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

Add setting in user profile page to Opt out of or Opt in to receiving individual emails #7586

Merged
merged 28 commits into from Apr 23, 2024

Conversation

Imran92
Copy link
Contributor

@Imran92 Imran92 commented Apr 10, 2024

Resolves #7497

Proposed Changes

Added a setting section in the User profile page in WpAdmin where the user can Opt out of (Or later Opt in to) individual emails they receive.

These were the considerations -

  • Any student/teacher/user can go to their own profile and uncheck any box beside an email to Opt-out
  • If any new email is introduced, by default, the users will subscribe to them, because our emails are Opt-out by nature
  • If the Admin keeps any email deactivated, the users/students will not see in in their profile, because they don’t need to opt out
  • Students will see only the Student emails in their profile page, because seeing Teacher emails don’t make sense for them
  • Pro emails will only be available in users’ Profile if Pro is installed, we don’t show the upsell emails there, because it doesn’t make sense for the users to opt-out of unavailable emails
  • An admin user (who has Cap for editing profiles of other users) can open a user’s profile from WpAdmin -> Users -> All Users -> (Click on any user) and opt them out/in to any email. In case that site has WP Admin disabled, or any user has asked the teacher/admin to stop getting a particular email, the Admin can just do it for that particular user (Can be handy in cases where users don’t have access to WpAdmin)

Note: We initially planned to add a link in the bottom of the emails with an URL to this page so that the users will know where to go to for unsubscribing. But @donnapep and I discussed later and decided not to do it here. Because in some sites, users are not given access to WP-Admin, putting this URL in the emails of those sites will not make sense.

Testing Instructions

  1. Make sure you are receiving Sensei emails for your Admin user
  2. Create a User with a student role, with another email you can check
  3. Create a Course with lessons and quizzes
  4. Enrol the student User to that Course
  5. Do some email generating activities (Enrolling in course should do, can also submit quiz by logging in as the student and the teacher user can grade the quiz)
  6. Make sure the student receives the emails
  7. Now after logging in as the student user, go to Wp Admin -> Profile
  8. Scroll down to Sensei Email section
  9. Make sure you are seeing emails that are only for Student users, no Teacher Email is appearing
  10. Opt out of one or more emails that you were receiving (uncheck and save)
  11. Now generate those emails again
  12. Make sure you haven't received any
  13. Now turn those emails on again
  14. Regenerate emails
  15. Make sure you are receiving them now
  16. Log in as the Admin user and go to Users -> Profile (your own Admin user's profile)
  17. Make sure you are seeing all active emails
  18. Opt out and in and check by email receiving as before
  19. As an admin user, go to Users -> WpAdmin -> Users -> All Users -> (Click on the student user) and opt the user out of any email
  20. Generate email for student user and make sure the logics work
  21. Deactivate Senesi-Pro and make sure Pro emails don't appear in profiles (Or activate and make sure they do)
  22. Unpublish one or more emails and make sure they don't appear in profiles any more
  23. Re-activate and make sure they are appearing again
  24. Login with users of different roles and make sure you see this setting in their profiles

New/Updated Hooks

  • sensei_send_emails - Updated hook by adding a new param to identify the email being sent.

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
  • Legacy courses (course without blocks) are tested
  • 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

@Imran92 Imran92 added the Hooks This change adds or modifies one or more hooks. label Apr 10, 2024
@Imran92 Imran92 added this to the 4.23.1 milestone Apr 10, 2024
@Imran92 Imran92 requested a review from a team April 10, 2024 15:03
@Imran92 Imran92 self-assigned this Apr 10, 2024
Copy link

Test the previous changes of this PR with WordPress Playground.

Copy link

Test the previous changes of this PR with WordPress Playground.

Copy link

Test the previous changes of this PR with WordPress Playground.

Copy link

Test the previous changes of this PR with WordPress Playground.

@donnapep
Copy link
Collaborator

I don't think we need the subject, and it's difficult to distinguish between student and teacher emails currently. Could we do something like this instead?

Screenshot 2024-04-11 at 8 24 58 AM

@m1r0

Copy link

Test the previous changes of this PR with WordPress Playground.

Copy link

Test the previous changes of this PR with WordPress Playground.

Copy link

Test the previous changes of this PR with WordPress Playground.

@donnapep donnapep modified the milestones: 4.23.1, 4.23.2 Apr 15, 2024
@m1r0 m1r0 requested review from a team and removed request for a team April 15, 2024 14:54
Copy link

Test the previous changes of this PR with WordPress Playground.

Copy link

codecov bot commented Apr 15, 2024

Codecov Report

Attention: Patch coverage is 91.91919% with 8 lines in your changes are missing coverage. Please review.

Project coverage is 51.84%. Comparing base (2ac96e8) to head (841c158).
Report is 45 commits behind head on trunk.

❗ Current head 841c158 differs from pull request most recent head 3c1eb87. Consider uploading reports for the commit 3c1eb87 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##              trunk    #7586      +/-   ##
============================================
+ Coverage     51.77%   51.84%   +0.07%     
- Complexity    11401    11436      +35     
============================================
  Files           650      652       +2     
  Lines         48549    48656     +107     
  Branches        470      470              
============================================
+ Hits          25135    25228      +93     
- Misses        23033    23047      +14     
  Partials        381      381              
Files Coverage Δ
...ncludes/internal/emails/class-email-list-table.php 84.42% <100.00%> (ø)
...ncludes/internal/emails/class-email-repository.php 96.66% <ø> (ø)
includes/internal/emails/class-email-sender.php 99.01% <100.00%> (ø)
...ludes/internal/emails/class-email-subscription.php 100.00% <100.00%> (ø)
includes/class-sensei-emails.php 0.00% <0.00%> (ø)
...udes/internal/emails/class-email-customization.php 57.69% <50.00%> (-0.65%) ⬇️
...ernal/emails/class-email-user-profile-settings.php 93.67% <93.67%> (ø)

... and 32 files 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 41752e5...3c1eb87. Read the comment docs.

merkushin
merkushin previously approved these changes Apr 23, 2024
Copy link
Member

@merkushin merkushin left a comment

Choose a reason for hiding this comment

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

Works well 👍

Left two suggestions. Optional, but...

Really enjoyed reading test in tests/unit-tests/internal/emails/test-class-email-subscription.php.

Comment on lines 116 to 149
<h3><?php esc_html_e( 'Sensei Email', 'sensei-lms' ); ?></h3>

<table class="form-table">
<?php
foreach ( $user_emails as $type => $emails ) {
?>
<tr>
<th scope="row">
<?php
switch ( $type ) {
case 'student':
esc_html_e( 'Student Emails', 'sensei-lms' );
break;
case 'teacher':
esc_html_e( 'Teacher Emails', 'sensei-lms' );
break;
default:
esc_html_e( 'Other Emails', 'sensei-lms' );
break;
}
?>
</th>
<td>
<?php
foreach ( $emails as $identifier => $email ) {
$this->render_email_subscription_setting( $user->ID, $identifier, $email );
}
?>
</td>
</tr>
<?php
}
?>
</table>
Copy link
Member

Choose a reason for hiding this comment

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

Could be extracted into a view file.

Copy link
Member

Choose a reason for hiding this comment

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

Extracted here: d4bbe81

Comment on lines 167 to 172
<fieldset>
<label for="<?php echo esc_attr( $this->get_field_id( $identifier ) ); ?>">
<input name="sensei-email-subscriptions[]" type="checkbox" value="<?php echo esc_attr( $identifier ); ?>" <?php checked( false, $is_unsubscribed ); ?> id="<?php echo esc_attr( $this->get_field_id( $identifier ) ); ?>">
<?php echo esc_html( $description ); ?>
</label>
</fieldset>
Copy link
Member

Choose a reason for hiding this comment

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

Same here: could be extracted into a view file.

Copy link
Member

Choose a reason for hiding this comment

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

Extracted here: d4bbe81

Copy link

Test the previous changes of this PR with WordPress Playground.

Copy link

Test the previous changes of this PR with WordPress Playground.

Copy link

Test the previous changes of this PR with WordPress Playground.

Copy link

Test the previous changes of this PR with WordPress Playground.

Copy link
Member

@merkushin merkushin left a comment

Choose a reason for hiding this comment

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

Restore my approval.

@Imran92 Imran92 merged commit c1e6f81 into trunk Apr 23, 2024
23 checks passed
@Imran92 Imran92 deleted the add/email-opt-in-out branch April 23, 2024 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Hooks This change adds or modifies one or more hooks.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable students and teachers to unsubscribe from emails
4 participants