BuddyX

LearnDash Hooks Reference

Free & Pro

Developer documentation for customizing BuddyX Pro's LearnDash integration.


Filter Hooks

buddyx_ld_filter_course_author_url

Modify the instructor profile URL on course pages.

add_filter( 'buddyx_ld_filter_course_author_url', 'my_instructor_url', 10, 2 );

function my_instructor_url( $author_url, $instructor_id ) {
    // Link to BuddyPress profile instead
    if ( function_exists( 'bp_core_get_user_domain' ) ) {
        return bp_core_get_user_domain( $instructor_id );
    }
    return $author_url;
}

Parameters:

  • $author_url (string) - Default author posts URL with ?post_type=sfwd-courses
  • $instructor_id (int) - User ID of the instructor

Return: String - Modified URL


buddyx_ld_course_search_form_format

Control the search form HTML format.

add_filter( 'buddyx_ld_course_search_form_format', 'my_search_format' );

function my_search_format( $format ) {
    // Force XHTML format
    return 'xhtml';
}

Parameters:

  • $format (string) - 'html5' or 'xhtml'

Return: String - Format type


get_buddyx_ld_course_search_form

Customize the complete course search form output.

add_filter( 'get_buddyx_ld_course_search_form', 'my_search_form' );

function my_search_form( $form ) {
    // Add custom class to form
    $form = str_replace( 'class="buddyx_ld_course_search-form',
                         'class="my-custom-class buddyx_ld_course_search-form',
                         $form );
    return $form;
}

Parameters:

  • $form (string) - Complete search form HTML

Return: String - Modified form HTML


buddyx_learndash_lms_get_course_participants_per_page

Control how many participants show per AJAX load.

add_filter( 'buddyx_learndash_lms_get_course_participants_per_page', 'my_participants_count' );

function my_participants_count( $per_page ) {
    // Show 10 participants per page
    return 10;
}

Parameters:

  • $per_page (int) - Default is 5

Return: Integer - Number of participants per page


learndash_header_tab_menu

BuddyX Pro uses this LearnDash filter to add custom meta boxes.

add_filter( 'learndash_header_tab_menu', 'my_metaboxes', 15, 4 );

function my_metaboxes( $header_data_tabs, $menu_tab_key, $screen_post_type ) {
    // Add custom metabox to Settings tab
    foreach ( $header_data_tabs as $key => $data_tabs ) {
        if ( 'sfwd-courses-settings' === $data_tabs['id'] ) {
            $header_data_tabs[ $key ]['metaboxes'][] = 'my_custom_metabox';
        }
    }
    return $header_data_tabs;
}

Theme-registered metaboxes:

  • learndash_course_custom_features - Custom features panel

single_template

BuddyX Pro filters single templates for LearnDash groups.

add_filter( 'single_template', 'my_group_template', 15 );

function my_group_template( $template ) {
    if ( get_post_type() === 'groups' ) {
        // Use custom template
        $my_template = get_stylesheet_directory() . '/my-group-template.php';
        if ( file_exists( $my_template ) ) {
            return $my_template;
        }
    }
    return $template;
}

Action Hooks

buddyx_sub_header

BuddyX Pro replaces the sub header on LearnDash pages.

// Add content before the LearnDash course header
add_action( 'buddyx_sub_header', 'my_before_course_header', 5 );

function my_before_course_header() {
    if ( is_singular( 'sfwd-courses' ) ) {
        echo '<div class="course-announcement">Enrollment open!</div>';
    }
}

Theme modifications:

  • Removes default buddyx_sub_header on single courses/groups
  • Adds buddyx_learndash_single_course_header for courses
  • Adds buddyx_learndash_single_group_header for groups
  • Adds buddyx_learndash_instructor_header for instructor pages

learndash-focus-header-nav-after

BuddyX Pro adds elements after the Focus Mode header navigation.

add_action( 'learndash-focus-header-nav-after', 'my_focus_button', 15, 2 );

function my_focus_button( $course_id, $user_id ) {
    ?>
    <button class="my-focus-action">Custom Action</button>
    <?php
}

Theme additions at this hook:

  • Dark/Light mode toggle (priority 10)
  • Sidebar trigger button (priority 10)

pre_get_buddyx_ld_course_search_form

Fires before the course search form is generated.

add_action( 'pre_get_buddyx_ld_course_search_form', 'my_search_setup' );

function my_search_setup() {
    // Custom setup before search form renders
}

save_post

BuddyX Pro saves custom course meta on post save.

add_action( 'save_post', 'my_course_save', 15 );

function my_course_save( $post_id ) {
    if ( get_post_type( $post_id ) !== 'sfwd-courses' ) {
        return;
    }

    // Your custom save logic
}

Theme-saved meta:

  • buddyx_ld_ccf_enable - Custom features enabled
  • buddyx_ld_features - Array of feature icons/text
  • _course_image_id - Cover image attachment ID
  • _group_image_id - Group cover image attachment ID

Theme Functions

buddyx_learndash_single_course_header()

Renders the Udemy-style single course header.

// Replace with custom header
remove_action( 'buddyx_sub_header', 'buddyx_learndash_single_course_header' );
add_action( 'buddyx_sub_header', 'my_course_header' );

function my_course_header() {
    // Custom course header implementation
}

Output includes:

  • Breadcrumbs (if enabled)
  • Course title
  • Short description
  • Enrollment count
  • Instructor avatars/names
  • Last updated date

buddyx_learndash_single_group_header()

Renders the single group header.

// Customize group header
remove_action( 'buddyx_sub_header', 'buddyx_learndash_single_group_header' );
add_action( 'buddyx_sub_header', 'my_group_header' );

buddyx_learndash_instructor_header()

Renders the instructor profile header.

// Customize instructor header
remove_action( 'buddyx_sub_header', 'buddyx_learndash_instructor_header' );
add_action( 'buddyx_sub_header', 'my_instructor_header' );

get_buddyx_ld_course_search_form()

Generates the course search form with filters.

// Display in template
if ( function_exists( 'get_buddyx_ld_course_search_form' ) ) {
    get_buddyx_ld_course_search_form();
}

// Get form as string
$form = get_buddyx_ld_course_search_form( false );

Parameters:

  • $echo (bool) - Whether to echo or return (default: true)

Return: String|void - Form HTML when $echo is false


buddyx_learndash_ld_course_enrolled_users_list()

Get cached count of enrolled users.

$count = buddyx_learndash_ld_course_enrolled_users_list( $course_id );
echo $count . ' students enrolled';

// Force refresh cache
$count = buddyx_learndash_ld_course_enrolled_users_list( $course_id, true );

Parameters:

  • $course_id (int) - Course ID
  • $force_refresh (bool) - Bypass transient cache (default: false)

Return: Integer - Number of enrolled users


buddyx_learndash_fontawesome_icons()

Get array of available FontAwesome icons for course features.

$icons = buddyx_learndash_fontawesome_icons();
// Returns array of icon class names like 'fas fa-book', 'fab fa-youtube', etc.

Return: Array - List of FontAwesome icon class names


AJAX Endpoints

buddyx_learndash_lms_get_course_participants

AJAX handler for loading more course participants.

Request Parameters:

  • course (int) - Course ID
  • total (int) - Total number of users
  • page (int) - Current page number
  • nonce (string) - Security nonce

Response:

{
    "success": true,
    "data": {
        "html": "<li>...</li>",
        "show_more": "true",
        "page": 2
    }
}

Customizer Settings

Getting Customizer Values

// Category filter enabled
$cat_filter = get_theme_mod( 'ld_category_filter', buddyx_defaults( 'ld-category-filter' ) );

// Instructor filter enabled
$inst_filter = get_theme_mod( 'ld_instructors_filter', buddyx_defaults( 'ld-instructors-filter' ) );

// Course columns
$columns = get_theme_mod( 'ld_cousse_columns', 'default' );
// Values: 'ld_column_1', 'ld_column_2', 'ld_column_3', 'default' (4 columns)

// LearnDash sidebar layout
$sidebar = get_theme_mod( 'ld_sidebar_option', buddyx_defaults( 'ld-sidebar-option' ) );

Post Meta Reference

Course Meta

Meta Key Type Description
buddyx_ld_ccf_enable string 'yes' or empty
buddyx_ld_features array Icon/text pairs
_course_image_id int Cover image ID

Group Meta

Meta Key Type Description
_group_image_id int Cover image ID

CSS Classes

Course Header Classes

Class Element
.learndash-single-course-header Main header container
.course-cover-image When cover image is set
.learndash-single-course-header-inner-wrap Content wrapper
.course-header-short-description Description text
.learndash-course-info Enrollment info
.learndash-course-instructor Instructor section
.instructor-avatar Avatar container
.instructor-name Name links
.last-update-date Update date

Instructor Header Classes

Class Element
.buddyx-learndash-author-info Main container
.lm-course-author-info-tab Content wrapper
.lm-course-author-avatar Avatar container
.lm-author-bio Bio section
.lm-author-title Name heading
.lm-author-social Social links list
.lm-author-description Bio text

Focus Mode Classes

Class Element
.learndash-dark-mode Dark mode icon
.learndash-light-mode Light mode icon
.ld-focus-sidebar-trigger Sidebar toggle button

Template Overrides

Custom Search Form Template

Create buddyx_ld_course_searchform.php in your child theme to override the search form.

// child-theme/buddyx_ld_course_searchform.php
<form role="search" method="get" class="my-search-form" action="<?php echo esc_url( get_post_type_archive_link( 'sfwd-courses' ) ); ?>">
    <!-- Your custom form HTML -->
</form>

Custom Group Template

Create single-sfwd-groups.php in your child theme for custom group single template.


Related Documentation