Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelogs/issue-3141.yml
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."
1 change: 1 addition & 0 deletions includes/notifications/class.llms.notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ private function load() {
'section_complete',
'student_welcome',
'subscription_cancelled',
'unenrollment',
'upcoming_payment_reminder',
);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
<?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]
* @version [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]
* @version [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]
* @version [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]
* @version [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();
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<?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]
* @version [version]
*/
protected function set_body() {
return sprintf( __( '%1$s has been unenrolled from %2$s.', 'lifterlms' ), '{{STUDENT_NAME}}', '{{TITLE}}' );
}

/**
* Setup footer content for output
*
* @return string
* @since [version]
* @version [version]
*/
protected function set_footer() {
return '';
}

/**
* Setup notification icon for output
*
* @return string
* @since [version]
* @version [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]
* @version [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]
* @version [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]
* @version [version]
*/
protected function set_subject() {
return sprintf( __( '%1$s unenrolled from %2$s', 'lifterlms' ), '{{STUDENT_NAME}}', '{{TITLE}}' );
}

/**
* Setup notification title for output
*
* @return string
* @since [version]
* @version [version]
*/
protected function set_title() {
return sprintf( __( '%1$s unenrollment', 'lifterlms' ), '{{TYPE}}' );
}

}
Loading