-
Notifications
You must be signed in to change notification settings - Fork 138
fix(notifications): add unenrollment notification trigger #3185
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
Open
faisalahammad
wants to merge
3
commits into
gocodebox:dev
Choose a base branch
from
faisalahammad:fix/3141-unenrollment-notification
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| significance: minor | ||
| type: added | ||
| entry: "Added unenrollment notification trigger (popup and email) for courses and memberships, disabled by default." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
includes/notifications/controllers/class.llms.notification.controller.unenrollment.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| <?php | ||
| /** | ||
| * Notification Controller: Unenrollment | ||
| * | ||
| * @package LifterLMS/Notifications/Controllers/Classes | ||
| * | ||
| * @since [version] | ||
| * @version [version] | ||
| */ | ||
|
|
||
| defined( 'ABSPATH' ) || exit; | ||
|
|
||
| /** | ||
| * Notification Controller: Unenrollment | ||
| * | ||
| * @since [version] | ||
| */ | ||
| class LLMS_Notification_Controller_Unenrollment extends LLMS_Abstract_Notification_Controller { | ||
|
|
||
| /** | ||
| * Trigger Identifier | ||
| * | ||
| * @var string | ||
| */ | ||
| public $id = 'unenrollment'; | ||
|
|
||
| /** | ||
| * Number of accepted arguments passed to the callback function | ||
| * | ||
| * The unenrollment action fires with 4 args: $user_id, $product_id, $trigger, $new_status. | ||
| * | ||
| * @var int | ||
| */ | ||
| protected $action_accepted_args = 4; | ||
|
|
||
| /** | ||
| * Action hooks used to trigger sending of the notification | ||
| * | ||
| * `llms_user_removed_from_membership_level` was deprecated in 3.37.9 and removed in | ||
| * 6.0.0; `llms_user_removed_from_membership` is the current hook. | ||
| * | ||
| * @var array | ||
| */ | ||
| protected $action_hooks = array( | ||
| 'llms_user_removed_from_course', | ||
| 'llms_user_removed_from_membership', | ||
| ); | ||
|
|
||
| /** | ||
| * Callback function, called after a user is unenrolled from a course or membership | ||
| * | ||
| * @param int $user_id WP User ID of the unenrolled user. | ||
| * @param int $post_id WP Post ID of the course or membership. | ||
| * @param string $trigger Enrollment trigger that caused the unenrollment. | ||
| * @param string $new_status New enrollment status applied to the user. | ||
| * @return void | ||
| * @since [version] | ||
| */ | ||
| public function action_callback( $user_id = null, $post_id = null, $trigger = null, $new_status = null ) { | ||
|
|
||
| $this->user_id = $user_id; | ||
| $this->post_id = $post_id; | ||
| $this->course = llms_get_post( $post_id ); | ||
|
|
||
| $this->send(); | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Takes a subscriber type (student, author, etc) and retrieves a User ID | ||
| * | ||
| * @param string $subscriber Subscriber type string. | ||
| * @return int|false | ||
| * @since [version] | ||
| */ | ||
| protected function get_subscriber( $subscriber ) { | ||
|
|
||
| switch ( $subscriber ) { | ||
|
|
||
| case 'author': | ||
| $uid = $this->course->get( 'author' ); | ||
| break; | ||
|
|
||
| case 'student': | ||
| $uid = $this->user_id; | ||
| break; | ||
|
|
||
| default: | ||
| $uid = false; | ||
|
|
||
| } | ||
|
|
||
| return $uid; | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Get the translatable title for the notification | ||
| * used on settings screens | ||
| * | ||
| * @return string | ||
| * @since [version] | ||
| */ | ||
| public function get_title() { | ||
| return __( 'Unenrollment', 'lifterlms' ); | ||
| } | ||
|
|
||
| /** | ||
| * Setup the subscriber options for the notification | ||
| * | ||
| * All subscribers default to disabled ('no') per the feature request: | ||
| * site administrators must opt in to receive unenrollment notifications. | ||
| * | ||
| * @param string $type Notification type id. | ||
| * @return array | ||
| * @since [version] | ||
| */ | ||
| protected function set_subscriber_options( $type ) { | ||
|
|
||
| $options = array(); | ||
|
|
||
| switch ( $type ) { | ||
|
|
||
| case 'basic': | ||
| $options[] = $this->get_subscriber_option_array( 'student', 'no' ); | ||
| $options[] = $this->get_subscriber_option_array( 'author', 'no' ); | ||
| break; | ||
|
|
||
| case 'email': | ||
| $options[] = $this->get_subscriber_option_array( 'student', 'no' ); | ||
| $options[] = $this->get_subscriber_option_array( 'author', 'no' ); | ||
| $options[] = $this->get_subscriber_option_array( 'custom', 'no' ); | ||
| break; | ||
|
|
||
| } | ||
|
|
||
| return $options; | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| return LLMS_Notification_Controller_Unenrollment::instance(); |
143 changes: 143 additions & 0 deletions
143
includes/notifications/views/class.llms.notification.view.unenrollment.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| <?php | ||
| /** | ||
| * Notification View: Course/Membership Unenrollment | ||
| * | ||
| * @package LifterLMS/Notifications/Views/Classes | ||
| * | ||
| * @since [version] | ||
| * @version [version] | ||
| */ | ||
|
|
||
| defined( 'ABSPATH' ) || exit; | ||
|
|
||
| /** | ||
| * Notification View: Course/Membership Unenrollment | ||
| * | ||
| * @since [version] | ||
| */ | ||
| class LLMS_Notification_View_Unenrollment extends LLMS_Abstract_Notification_View { | ||
|
|
||
| /** | ||
| * Settings for basic notifications | ||
| * | ||
| * @var array | ||
| */ | ||
| protected $basic_options = array( | ||
| /** | ||
| * Time in milliseconds to show a notification | ||
| * before automatically dismissing it | ||
| */ | ||
| 'auto_dismiss' => 10000, | ||
| /** | ||
| * Enables manual dismissal of notifications | ||
| */ | ||
| 'dismissible' => true, | ||
| ); | ||
|
|
||
| /** | ||
| * Notification Trigger ID | ||
| * | ||
| * @var string | ||
| */ | ||
| public $trigger_id = 'unenrollment'; | ||
|
|
||
| /** | ||
| * Setup body content for output | ||
| * | ||
| * @return string | ||
| * @since [version] | ||
| */ | ||
| protected function set_body() { | ||
| if ( 'email' === $this->notification->get( 'type' ) ) { | ||
| return sprintf( __( 'You have been unenrolled from %s.', 'lifterlms' ), '{{TITLE}}' ); | ||
| } | ||
| return sprintf( __( '%1$s has been unenrolled from %2$s.', 'lifterlms' ), '{{STUDENT_NAME}}', '{{TITLE}}' ); | ||
| } | ||
|
|
||
| /** | ||
| * Setup footer content for output | ||
| * | ||
| * @return string | ||
| * @since [version] | ||
| */ | ||
| protected function set_footer() { | ||
| return ''; | ||
| } | ||
|
|
||
| /** | ||
| * Setup notification icon for output | ||
| * | ||
| * @return string | ||
| * @since [version] | ||
| */ | ||
| protected function set_icon() { | ||
| return $this->get_icon_default( 'negative' ); | ||
| } | ||
|
|
||
| /** | ||
| * Setup merge codes that can be used with the notification | ||
| * | ||
| * @return array | ||
| * @since [version] | ||
| */ | ||
| protected function set_merge_codes() { | ||
| return array( | ||
| '{{TITLE}}' => __( 'Title', 'lifterlms' ), | ||
| '{{TYPE}}' => __( 'Type (Course or Membership)', 'lifterlms' ), | ||
| '{{STUDENT_NAME}}' => __( 'Student Name', 'lifterlms' ), | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Replace merge codes with actual values | ||
| * | ||
| * @param string $code The merge code to get merged data for. | ||
| * @return string | ||
| * @since [version] | ||
| */ | ||
| protected function set_merge_data( $code ) { | ||
|
|
||
| switch ( $code ) { | ||
|
|
||
| case '{{TITLE}}': | ||
| $code = $this->post->get( 'title' ); | ||
| break; | ||
|
|
||
| case '{{TYPE}}': | ||
| $code = $this->post->get_post_type_label(); | ||
| break; | ||
|
|
||
| case '{{STUDENT_NAME}}': | ||
| $code = $this->is_for_self() ? __( 'you', 'lifterlms' ) : $this->user->get_name(); | ||
| break; | ||
|
|
||
| } | ||
|
|
||
| return $code; | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Setup notification subject for output | ||
| * | ||
| * @return string | ||
| * @since [version] | ||
| */ | ||
| protected function set_subject() { | ||
| if ( $this->is_for_self() ) { | ||
| return sprintf( __( 'You have been unenrolled from %s', 'lifterlms' ), '{{TITLE}}' ); | ||
| } | ||
| return sprintf( __( '%1$s unenrolled from %2$s', 'lifterlms' ), '{{STUDENT_NAME}}', '{{TITLE}}' ); | ||
|
faisalahammad marked this conversation as resolved.
|
||
| } | ||
|
|
||
| /** | ||
| * Setup notification title for output | ||
| * | ||
| * @return string | ||
| * @since [version] | ||
| */ | ||
| protected function set_title() { | ||
| return sprintf( __( '%1$s unenrollment', 'lifterlms' ), '{{TYPE}}' ); | ||
| } | ||
|
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.