LifterLMS Filters
Filters are one of two kinds of hooks made available in WordPress.
Before getting started with LifterLMS filters, you may want to familiarize yourself with how to utilize filters in WordPress and the WordPress core function add_filter().
Filters can be added to your theme’s or child theme’s functions.php file or to a site-specific plugin.
There are hundreds of filters available in LifterLMS. Head over to the LifterLMS Code Reference to find a full list of all the filters in LifterLMS.
Use this snippet to prevent students from being able to self-cancel their recurring subscriptions on the student dashboard.
// Don't copy this line! /** * llms_allow_subscription_cancellation.php * * @since 2017-07-12 */ /** * Prevents students from being able to self-cancel their recurring subscriptions on the student dashboard */ add_filter( 'llms_allow_subscription_cancellation', '__return_false' );
Added in LifterLMS 3.10.1
Disable Auto-Advance to the next lesson when a lesson is completed.
// Don't copy this line! /** * lifterlms_autoadvance.php * * @since 2017-07-13 */ // disable auto-advance on lesson completion add_filter( 'lifterlms_autoadvance', '__return_false' );
Customize the “Buy Now” text on the purchase button of the LifterLMS Checkout screen.
// Don't copy this line! /** * lifterlms_checkout_buy_button_text.php * * @since 2016-10-28 */ /** * Customize the text of the "Buy Now" button on the checkout screen * @param string $text default text of the button * @return string */ function my_llms_buy_button_text( $text ) { return __( 'PURCHASE!', 'my-text-domain' ); } add_filter( 'lifterlms_checkout_buy_button_text', 'my_llms_buy_button_text' );
Add a custom currency to LifterLMS currencies list.
Ensure that your payment gateway(s) support the currency!
// Don't copy this line! /** * lifterlms-add-custom-currency.php * * @since 2016-08-22 */ function llms_add_currency( $currencies ) { $code = 'ABC'; // currency code as per ISO currency code standards (http://www.iso.org/iso/home/standards/currency_codes.htm) $name = __( 'Currency Name', 'my-text-domain' ); // name to be displayed for the currency $currencies[$code] = $name; return $currencies; } add_filter( 'lifterlms_currencies', 'llms_add_currency' );
This filter allows you to modify the text of recurring payment pricing descriptions.
// Don't copy this line! /** * lifterlms_recurring_price_html.php * * @since 2016-08-08 */ /** * Update the display of recurring payment information * @param string $text HTML / Text to display the price * @param obj $product Instance of the LLMS_Product * @return string */ function llms_get_recurring_price_html( $text, $product ) { return sprintf( __( 'Recurring Price: %s', 'my-text-domain' ), $text ); } add_filter( 'lifterlms_recurring_price_html', 'llms_recurring_price_html', 10, 2 );
Redirect new student registrations to a custom URL upon successful registartion.
// Don't copy this line! /** * lifterlms_registration_redirect.php * * @since 2017-06-29 */ /** * Redirect to a custom page on your site during LifterLMS Registrations * @param string $url default URL * @return string */ function my_lifterlms_reg_redirect( $url ) { return untrailingslashit( get_site_url() ) . '/my-custom-redirct-page'; } add_filter( 'lifterlms_registration_redirect', 'my_lifterlms_reg_redirect' );
This filter allows you to modify the text of single payment pricing descriptions.
// Don't copy this line! /** * remove "single payment of" via LifterLMS filters * * @since 2016-08-08 */ /** * Programatically remove "Single Payment Of" from LifterLMS pricing screens * @param string $text HTML / Text to display the price * @param obj $product Instance of the LLMS_Product * @return string */ function llms_get_single_price_html( $text, $product ) { return str_replace( 'single payment of ', '', $text ); } add_filter( 'lifterlms_get_single_price_html', 'llms_get_single_price_html', 10, 2 );
Modify the number of columns used when displaying achievements on the student dashboard and elsewhere.
// Don't copy this line! /** * llms_achievement_loop_columns.php * * @since 2017-10-21 */ /** * Modify the number of columns used when looping achievements on the student dashboard * We have CSS in the core for anywhere from 1-5 columns * if you need more than 5 columns you'll want to add additional custom css to acommodate: * .lifterlms ul.llms-achievements-loop.loop-cols-6 li.llms-achievement-loop-item { width: 16.666%; } * @param int $cols number of columns (default is 4) * @return int */ function my_achievement_loop_columns( $cols ) { return 5; } add_filter( 'llms_achievement_loop_columns', 'my_achievement_loop_columns', 999, 1 );
Use this filter to customize the default number of courses displayed on each page when a student visits the “View All Courses” page on the student dashboard.
// Don't copy this line! /** * llms_dashboard_courses_per_page.php * * @since 2017-03-22 */ /** * Customize the number of courses displayed on each page of the "View Courses" endpoint on the LifterLMS Student Dashboard * @param int $count default number of courses (10) * @return int */ function my_custom_llms_dashboard_recent_courses_count( $count ) { return 25; } add_filter( 'llms_dashboard_courses_per_page', 'my_custom_llms_dashboard_recent_courses_count' );
Added in version 3.5.4
Use this filter to customize the CSS added to LifterLMS-generated emails
// Don't copy this line! /** * available for LifterLMS 3.8.0-alpha.1 & higher * * @since 2017-04-27 */ add_filter( 'llms_email_css', 'my_llms_email_branding' ); function my_llms_email_branding( $css ) { // these are all the defineable rules with their defaults // uncomment and customize whichever you wish to customize // not a dev? confused? I'll be adding branding options to LifterLMS Labs in conjunction with the public release of LifterLMS 3.8 // $css['background-color'] = '#f6f6f6'; // $css['border-radius'] = '3px'; // $css['button-background-color'] = '#2295ff'; // $css['button-font-color'] = '#ffffff'; // $css['divider-color'] = '#cecece'; // $css['font-color'] = '#222222'; // $css['font-family'] = 'sans-serif'; // $css['font-size'] = '15px'; // $css['font-size-small'] = '13px'; // $css['heading-background-color'] = '#2295ff'; // $css['heading-font-color'] = '#ffffff'; // $css['main-color'] = '#2295ff'; // $css['max-width'] = '580px'; return $css; }
Change the text displayed for free ($0.00) access plans.
// Don't copy this line! /** * change free text access plan text * * @since 2017-10-15 */ /* * Change the text displayed for free ($0.00) access plans * @param string $text the default text ("Free") * @return string */ function my_free_pricing_text( $text ) { return __( 'INCLUDED', 'my-text-domain' ); // change text to whatever you want here } add_filter( 'llms_get_free_access_plan_pricing_text', 'my_free_pricing_text' );
Change the maximum number of access plans which can be created for a single course / membership.
// Don't copy this line! /** * llms_get_product_access_plan_limit.php * * @since 2017-09-06 */ /** * Change the maximum number of access plans which can be created for a single course / membership * @param int $limit number of plans * @return int */ function my_llms_get_product_access_plan_limit( $limit ) { return 12; } add_filter( 'llms_get_product_access_plan_limit', 'my_llms_get_product_access_plan_limit' );
Use this filter to customize settings associated with LifterLMS Basic Notifications.
Currently the only settings is the heartbeat interval which is used to customize how frequently AJAX calls are made to check for new notifications.
/** * Filter to customize settings associated with LifterLMS Basic Notifications. * * https://lifterlms.com/docs/lifterlms-filters/#llms_notifications_settings * * You can add this recipe to your site by creating a custom plugin * or using the Code Snippets plugin available for free in the WordPress repository. * Read this companion documentation for step-by-step directions on either method. * https://lifterlms.com/docs/adding-custom-code/ */ function my_llms_notifications_settings( $settings ) { $settings['heartbeat_interval'] = 60000; return $settings; } add_filter( 'llms_notifications_settings', 'my_llms_notifications_settings', 10, 1 );
Added in LifterLMS 3.9.5
Add or modify recurring order failed payment retry rules.
// Don't copy this line! /** * Add a retry rule to the end of the default rules that waits 7 days and retries the recurring payment * * @since 2018-05-18 */ /** * Add a retry rule to the end of the default rules that waits 7 days and retries the recurring payment * @param array $rules existing rules * @return array */ function my_custom_retry_rules( $rules ) { $rules[] = array( 'delay' => WEEK_IN_SECONDS, 'status' => 'on-hold', 'notifications' => true, ); return $rules; } add_filter( 'llms_order_automatic_retry_rules', 'my_custom_retry_rules' );
// Don't copy this line! /** * llms_order_status_can_resubscribe_from.php * * @since 2018-06-21 */ /** * Customize which order statuses student can resubscribe from * @param array $statuses array of order statuses * default statuses: [ 'llms-pending-cancel', 'llms-pending', 'llms-on-hold' ] * @return array */ function my_llms_order_status_can_resubscribe_from( $statuses ) { unset( $statuses['llms-pending-cancel'] ); // this would make it so "Pending Cancellation" orders cannot be resubscribed from $statuses[] = 'llms-failed'; // this allows "Failed" orders to be resubscribed to return $statuses; } add_filter( 'llms_order_status_can_resubscribe_from', 'my_llms_order_status_can_resubscribe_from' );
Add additional pages to the list of pages shown to non-enrolled visitors when sitewide membership restrictions are in effect
// Don't copy this line! /** * lifterlms_sitewide_restriction_bypass_ids.php * * @since 2017-03-27 */ /** * Add additional pages to the list of pages shown to non-enrolled visitors when sitewide membership restrictions are in effect * @param array $ids WP Post IDs * @return array */ function my_lifterlms_sitewide_restriction_bypass_ids( $ids ) { // add the WP Post IDs of posts which can be accessed without being an enrolled member here $custom_ids = array( 123, 456, 789 ); return array_merge( $ids, $custom_ids ); } add_filter( 'lifterlms_sitewide_restriction_bypass_ids', 'my_lifterlms_sitewide_restriction_bypass_ids', 10, 1 );
Customize the default tab displayed when student’s visit the LifterLMS Student Dashboard.
// Don't copy this line! /** * llms_student_dashboard_default_tab.php * * @since 2017-03-22 */ /** * Customize the default tab displayed when a student visits the student dashboard */ function my_custom_student_dashboard_tab( $tab ) { return 'view-courses'; } add_filter( 'llms_student_dashboard_default_tab', 'my_custom_student_dashboard_tab' );
Use this filter to add, remove, or modify tabs on LifterLMS Student Dashboard.
This example removes tabs:
// Don't copy this line! /** * llms-remove-student-dashboard-tabs.php * * @since 2016-11-17 */ /** * Remove tabs from the LifterLMS Student dashboard * @param array $tabs registered tabs * @return array */ function my_remove_dashboard_tabs( $tabs ) { // unset( $tabs['view-courses'] ); // unset( $tabs['view-achievements'] ); // unset( $tabs['notifications'] ); // unset( $tabs['edit-account'] ); // unset( $tabs['redeem-voucher'] ); // unset( $tabs['orders'] ); // unset( $tabs['signout'] ); return $tabs; } add_filter( 'llms_get_student_dashboard_tabs', 'my_remove_dashboard_tabs' );
This example adds tabs:
// Don't copy this line! /** * llms-add-student-dashboard-tabs.php * * @since 2016-11-17 */ /** * Add custom dashboard tabs / urls to the dashboard navigation * @param array $tabs existing tabs * @return array */ function my_custom_dashboard_tabs( $tabs ) { // save the signout tab $signout = $tabs['signout']; // remove the signout tab unset( $tabs['signout'] ); /** * Add custom Tabs below */ // Basic Custom tab with URL (eg: link to a WordPress page) $tabs['my-tab'] = array( 'title' => __( 'My Tab Title', 'my-text-domain' ), 'url' => 'http://mydomain.com/path/to/url', ); // Advanced Custom tab with content displayed on the Dashboard as an endpoint // NOTE: you'll need to FLUSH PERMALINKS after adding a custom endpoint, if you don't the endpoint will 404! // how to flush permalinks: https://lifterlms.com/docs/how-to-flush-wordpress-rewrite-rules-or-permalinks/ $tabs['my-endpoint'] = array( 'content' => 'my_custom_endpoint_content', // this should be a callable function that outputs your content 'endpoint' => __( 'my-endpoint', 'my-text-domain' ), // endpoint slug (eg: http://mysite.com/my-courses/my-endpoint) 'nav_item' => true, // will add the endpoint to LifterLMS section on WP menu admin pages for use on WP nav menus 'title' => __( 'My Endpoint Title', 'my-text-domain' ), ); // restore the signout tab $tabs['signout'] = $signout; return $tabs; } add_filter( 'llms_get_student_dashboard_tabs', 'my_custom_dashboard_tabs', 10, 1 ); /** * Outputs HTML content for a custom endpoint * @return void */ function my_custom_endpoint_content() { echo '<p>This is my endpoint content</p>'; }
Customize the number of students displayed per page on the admin reporting table for “Students”.
Note that setting this number too high could result in PHP timeouts due to exhausted memory!
// Don't copy this line! /** * llms_gradebook_students_per_page.php * * @since 2016-12-30 */ /** * Customize the number of students per page on the admin reporting table * @param int $num default (20) * @return int */ function my_results_per_page( $num ) { return 50; } add_filter( 'llms_gradebook_students_per_page', 'my_results_per_page' );
Customize the number of courses per page on the admin reporting table for a student’s course list.
Note that setting this number too high could result in PHP timeouts due to exhausted memory!
// Don't copy this line! /** * llms_gradebook_student-courses_per_page.php * * @since 2016-12-30 */ /** * Customize the number of courses per page on the admin reporting table for a student's course list * @param int $num default (20) * @return int */ function my_results_per_page( $num ) { return 50; } add_filter( 'llms_gradebook_student-courses_per_page', 'my_results_per_page' );
This filter allows you to disable quick enrollment and free checkout for free access plans. For more information see Checkout for Free Access Plans.
// Don't copy this line! /** * llms_has_free_checkout.php * * @since 2017-02-02 */ add_filter( 'llms_has_free_checkout', '__return_false' );
Use this filter to redirect a student to a custom url upon marking a lesson complete.
// Don't copy this line! /** * llms_lesson_complete_redirect.php * * @since 2017-04-04 */ /** * Redirect to a custom URL upon marking a lesson complete * @param string $url default URL * @return string */ function my_llms_lesson_complete_redirect( $url ) { return 'http://mycustomurl.com'; } add_filter( 'llms_lesson_complete_redirect', 'my_llms_lesson_complete_redirect', 10, 1 );
LifterLMS automatically skips membership restrictions checks on certain LifterLMS core post types which, by default, cannot be restricted to a membership.
You can use this filter to add or remove custom post types to or from this list.
To remove:
// Don't copy this line! /** * remove-llms_is_post_restricted_by_membership_skip_post_types.php * * @since 2016-12-05 */ /** * Remove a post type from the list of post types LifterLMS will NOT check for membership restrictions * @param array $post_types array of post type names * @return array */ function my_allow_lessons_restrictions( $post_types ) { // the following post types are automatically bypassed // during membership restriction checks // course // lesson // llms_quiz // llms_membership // llms_question // llms_certificate // llms_my_certificate // this will remove lessons from the list so that lessons can be restricted $i = array_search( 'lesson', $post_types ); if ( false !== $i ) { unset( $post_types[ $i ] ); } return $post_types; } add_filter( 'llms_is_post_restricted_by_membership_skip_post_types', 'my_allow_lessons_restrictions' );
To add:
// Don't copy this line! /** * add-llms_is_post_restricted_by_membership_skip_post_types.php * * @since 2016-12-05 */ /** * Add a post type to the list of post types LifterLMS will NOT check for membership restrictions. * @param array $post_types array of post type names * @return array */ function my_allow_lessons_restrictions( $post_types ) { array_push( $post_types, 'my_custom_post_type' ); return $post_types; } add_filter( 'llms_is_post_restricted_by_membership_skip_post_types', 'my_allow_lessons_restrictions' );
Use this filter to hide the display of the Lesson short description on lesson preview tiles.
// Don't copy this line! /** * llms_show_preview_excerpt.php * * @since 2016-11-28 */ // disables lesson short description in the lesson preview tiles add_filter( 'llms_show_preview_excerpt', '__return_false' );
// Don't copy this line! /** * llms_show_preview_excerpt_ait.php * * @since 2016-11-28 */ /** * Display lesson excerpts on course syllabus but NOT on next / previous tiles on lesson pages */ function my_lesson_preview_function( $show ) { if ( is_course() ) { return true; } return false; } // disables lesson short description in the lesson preview tiles add_filter( 'llms_show_preview_excerpt', 'my_lesson_preview_function' );
These filters allow you to add, display, save, and validate custom user meta fields as they are displayed and edited on the WordPress Admin Panel User Profile Screen.
These filters are located in “includes/admin/class.llms.admin.user.custom.fields.php”.
lifterlms_get_user_custom_fields #
Use this filter to add custom fields to the user’s profile on the WordPress admin panel
Added in LifterLMS 2.7.0, last updated LifterLMS 2.7.0
// Don't copy this line! /** * lifterlms_get_user_custom_fields.php * * @since 2016-05-05 */ /** * Add a custom field to the user's profile on the WP admin panel * @param array $fields associatve array of field data * @return array */ function my_custom_user_fields( $fields ) { $fields['llms_custom_field_id'] = array( // array key *should* the value you want to store in the WP usermeta table 'description' => 'A short description of this field', 'label' => __( 'My Custom Field Label', 'my-text-domain' ), 'required' => false, // if you want this field to be required, switch to "true" 'type' => 'text', // accepts any valid HTML5 input type, note that we don't have support for textareas or select elements! ); return $fields; } add_filter( 'lifterlms_get_user_custom_fields', 'my_custom_user_fields', 10, 1 );
lifterlms_get_user_custom_field_value_{$field_id} #
Use this filter the customize the output of user field data when it is displayed on the admin panel.
Added in LifterLMS 2.7.0, last updated LifterLMS 2.7.0
// Don't copy this line! /** * lifterlms_get_user_custom_field_value_{$field_id).php * * @since 2016-05-05 */ /** * Override the default value of a custom field retrieved from the usermeta table * * note that this filter isn't necessary but *can* be used if you don't simply * want to retrieve the value of the field from the usermeta table * * @param mixed $value value from the usermeta table * @param obj $user Instance of WP_User for whom data is being retrieved * @param string $field_id id / name of the field * @return mixed */ function my_custom_field_value( $value, $user, $field_id ) { // do something with the field value, for example replace underscores with spaces because why not? $value = str_replace( '_', ' ', $value ); return $value; } add_filter( 'lifterlms_get_user_custom_field_value_my_custom_field_id', 'my_custom_field_value', 10, 3 ); // "my_custom_field_id" should be replaced with your field's id!
lifterlms_validate_custom_user_field_{$field_id} #
Use this filter to validate custom user field data before it is saved to the database and output error messages specific to your custom field.
Added in LifterLMS 2.7.0, last updated LifterLMS 2.7.0
// Don't copy this line! /** * lifterlms_validate_custom_user_field_{$field_id}.php * * @since 2016-05-05 */ /** * Run custom validation against the field * If filter function returns a truthy, validation will stop, fields will not be saved, * and an error message will be displayed on screen * * This should return false or a string which will be used as the error message * * If false is returned, the field has "passed" validation (eg no errors) * * @param mixed $error false or error message string * @param string $field_id field id or name * @param obj $user Instace of WP_User * @return mixed */ function my_custom_field_validation( $error, $field_id, $user ) { // for example, lets make sure the field is numeric if ( ! is_numeric( $_POST[$field_id] ) ) { $error = __( 'ERROR: The value of "My Custom Field" must be numeric!', 'my-text-doamin' ); } return $error; } add_filter( 'lifterlms_validate_custom_user_field_my_custom_field_id', 'my_custom_field_validation', 10, 3 );
lifterlms_save_custom_user_field_{$field_id} #
Use this filter to filter the user submitted before it is stored in the database (after validation).
Added in LifterLMS 2.7.0, last updated LifterLMS 2.7.0
// Don't copy this line! /** * lifterlms_save_custom_user_field_{$field_id}.php * * @since 2016-05-05 */ /** * Customize the value stored in the database before the field data is saved * * This runs after validation so no need to re-validate here * * @param mixed $value user submitted value * @param obj $user WP_User instance * @param string $field_id name / id of the field * @return mixed */ function my_custom_field_save( $value, $user, $field_id ) { // for example ensure remove protocal prefixes from the beginning of a web address field $value = str_replace( array( 'https://', 'http://' ), '', $value ); return $value; } add_filter( 'lifterlms_save_custom_user_field_my_custom_field_id', 'my_custom_field_save', 10, 3 );