Last active
September 5, 2019 08:49
-
-
Save actual-saurabh/9826484ca095e3f3c0430ca59ad853b3 to your computer and use it in GitHub Desktop.
Remove frontend notifications from LifterLMS
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
<?php // Do not copy this line | |
// Copy from under this line and paste into your child theme's functions.php | |
add_action( 'init', 'llms_turn_off_notifications', 10, 999 ); | |
add_action( 'wp_enqueue_scripts', 'llms_dequeue_notification_script', 10, 999 ); | |
if ( ! function_exists( 'llms_turn_off_notifications' ) ){ | |
function llms_turn_off_notifications(){ | |
// an array of all the notification ids in https://github.com/gocodebox/lifterlms/tree/master/includes/notifications/controllers | |
$notification_ids = array( | |
'achievement_earned', | |
'certificate_earned', | |
'course_complete', | |
'course_track_complete', | |
'enrollment', | |
'lesson_complete', | |
'section_complete', | |
'student_welcome', | |
'purchase_receipt', | |
'quiz_failed', | |
'quiz_passed', | |
'manual_payment_due', | |
'payment_retry', | |
); | |
// filter out basic notifications | |
foreach( $notification_ids as $notification ){ | |
add_filter( 'llms_notification_' . $notification . '_subscriber_options', 'llms_remove_basic_notifications', 10, 2 ); | |
} | |
} | |
} | |
if ( ! function_exists( 'llms_remove_basic_notifications' ) ){ | |
function llms_remove_basic_notifications( $subscriber_options, $type ){ | |
// only remove basic notifications, leaving emails in place | |
if ( $type != 'basic' ){ | |
return $subscriber_options; | |
} | |
return array(); | |
} | |
} | |
if ( ! function_exists( 'llms_dequeue_notification_script' ) ){ | |
function llms_dequeue_notification_script(){ | |
// dequeue the notifications script | |
wp_dequeue_script( 'llms-notifications' ); | |
} | |
} |
@RifleFish this does exactly that: https://gist.github.com/actual-saurabh/9826484ca095e3f3c0430ca59ad853b3#file-llms-remove-notifications-php-L38-L41
@actual-saurabh I know what you mean, but earning a certificate and completing a lesson notifications are both classified as 'Basic' notifications, which means that this script disables them both. However I want to keep the notifications for earning a certificate. Isn't there an option to disable notifications by name instead of delivery type?
@RifleFish you can remove the trigger ids that you wish to keep the notifications for, from the list in lines 12-26.
@actual-saurabh Great, thank you!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this! I have a question though, is there a way to only disable specific Basic notifications? I'd like my user to know that he/she earned a certificate, but I don't want to spam them with a notification every time they complete a lesson/quiz.