Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wp_mail still working for temporary users #6868

Merged
merged 6 commits into from
May 15, 2023

Conversation

fjorgemota
Copy link
Member

@fjorgemota fjorgemota commented May 9, 2023

Fix a situation that #6855 didn't cover: Blocking wp_mail when the e-mail isn't dispatched from the frontend of the site.

Proposed Changes

  • Block wp_mail calls related to temporary users even on non-frontend context;

Testing Instructions

The test for this is pretty simple, on WP-CLI, run the following commands, line by line:

remove_all_filters('wp_mail'); // To make sure that no other filter will change the data informed
wp_mail( 'user1@guest.senseilms', 'Test email', 'Hello, this is a test email.', [    'From: My Site Name <noreply@example.com>']); // Should return false on this branch, true on trunk
wp_mail( 'user1@preview.senseilms', 'Test email', 'Hello, this is a test email.', [    'From: My Site Name <noreply@example.com>']); // Should return false on this branch, true on trunk
wp_mail( 'user1@example.com', 'Test email', 'Hello, this is a test email.', [    'From: My Site Name <noreply@example.com>']); // Should return true in any scenario

Here's the code running on this branch:

image

This is the code running on the trunk branch:

image

Pre-Merge Checklist

  • PR title and description contain sufficient detail and accurately describe the changes
  • Acceptance criteria is met
  • Decisions are publicly documented
  • Adheres to coding standards (PHP, JavaScript, CSS, HTML)
  • All strings are translatable (without concatenation, handles plurals)
  • Follows our naming conventions (P6rkRX-4oA-p2)
  • Hooks (p6rkRX-1uS-p2) and functions are documented
  • New UIs are responsive and use a mobile-first approach
  • New UIs match the designs
  • Different user privileges (admin, teacher, subscriber) are tested as appropriate
  • Code is tested on the minimum supported PHP and WordPress versions
  • User interface changes have been tested on the latest versions of Chrome, Firefox and Safari
  • "Needs Documentation" label is added if this change requires updates to documentation
  • Known issues are created as new GitHub issues

@fjorgemota fjorgemota self-assigned this May 9, 2023
@codecov
Copy link

codecov bot commented May 9, 2023

Codecov Report

Merging #6868 (09fd44e) into trunk (224b1b0) will increase coverage by 0.00%.
The diff coverage is 74.52%.

Impacted file tree graph

@@            Coverage Diff            @@
##              trunk    #6868   +/-   ##
=========================================
  Coverage     46.87%   46.87%           
  Complexity    10189    10189           
=========================================
  Files           554      554           
  Lines         36748    36748           
  Branches        381      381           
=========================================
+ Hits          17226    17227    +1     
+ Misses        19216    19215    -1     
  Partials        306      306           
Impacted Files Coverage Δ
assets/blocks/quiz/quiz-block/quiz-edit.js 86.66% <ø> (ø)
assets/extensions/store.js 14.08% <ø> (ø)
includes/admin/class-sensei-extensions.php 0.00% <0.00%> (ø)
includes/blocks/course-theme/class-exit-course.php 47.05% <0.00%> (ø)
includes/blocks/course-theme/class-focus-mode.php 44.44% <0.00%> (ø)
includes/class-sensei-autoloader-bundle.php 0.00% <0.00%> (ø)
includes/class-sensei-autoloader.php 0.00% <0.00%> (ø)
includes/class-sensei-bootstrap.php 0.00% <0.00%> (ø)
includes/class-sensei-emails.php 0.00% <0.00%> (ø)
includes/class-sensei-grading-user-quiz.php 0.00% <ø> (ø)
... and 17 more

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3c91e32...09fd44e. Read the comment docs.

Comment on lines +38 to +39
add_filter( 'pre_wp_mail', [ Sensei_Guest_User::class, 'skip_wp_mail' ], 10, 2 );
add_filter( 'pre_wp_mail', [ Sensei_Preview_User::class, 'skip_wp_mail' ], 10, 2 );
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a huge fan of this change: basically, I'm adding the filters here for each class.

I thought about maybe creating a method in each class just to run that add_filter and call it here, but I think the result would be...quite similar, so that's why I left it this way.

This is also the main change that fixes the issue, so..yeah, there's that.

@fjorgemota fjorgemota marked this pull request as ready for review May 9, 2023 21:52
@fjorgemota fjorgemota requested a review from a team May 9, 2023 21:52
Copy link
Contributor

@renatho renatho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good and works as described!

@fjorgemota fjorgemota merged commit 0fa020d into trunk May 15, 2023
19 of 20 checks passed
@fjorgemota fjorgemota deleted the fix/wpmail-temporary-users branch May 15, 2023 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants