Skip to content

Instantly share code, notes, and snippets.

@actual-saurabh
Last active September 5, 2019 08:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save actual-saurabh/9826484ca095e3f3c0430ca59ad853b3 to your computer and use it in GitHub Desktop.
Save actual-saurabh/9826484ca095e3f3c0430ca59ad853b3 to your computer and use it in GitHub Desktop.
Remove frontend notifications from LifterLMS
<?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' );
}
}
@Mte90
Copy link

Mte90 commented Apr 23, 2018

It is missing a ; on line 40.

@actual-saurabh
Copy link
Author

@Mte90 thanks, fixed!

@lucs29
Copy link

lucs29 commented Sep 5, 2019

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.

@actual-saurabh
Copy link
Author

@lucs29
Copy link

lucs29 commented Sep 5, 2019

@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?

@actual-saurabh
Copy link
Author

@RifleFish you can remove the trigger ids that you wish to keep the notifications for, from the list in lines 12-26.

@lucs29
Copy link

lucs29 commented Sep 5, 2019

@actual-saurabh Great, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment