Filter uncanny-learndash-groups

uo-dashboard-template-3-0

Filters the template used for Uncanny Dashboard's template structure, allowing for customization of the core dashboard layout.

add_filter( 'uo-dashboard-template-3-0', $callback, 10, 1 );

Description

Allows developers to filter the path or content of the core "Dashboard Template 3.0" file for frontend user dashboards. This filter is applied before the template is rendered, enabling customization or complete replacement of the default template structure.


Usage

add_filter( 'uo-dashboard-template-3-0', 'your_function_name', 10, 1 );

Return Value

The filtered value.


Examples

<?php
/**
 * Example of how to use the 'uo-dashboard-template-3-0' filter to conditionally
 * modify the dashboard template path.
 *
 * This example checks if the user has completed any courses and, if so,
 * returns a different template path to display a "congratulations" message.
 * Otherwise, it returns the original template path.
 *
 * @param string $template_path The default template path provided by the Uncanny Toolkit.
 * @return string The modified or original template path.
 */
add_filter( 'uo-dashboard-template-3-0', 'my_custom_uo_dashboard_template', 10, 1 );

function my_custom_uo_dashboard_template( $template_path ) {

    // Get the current logged-in user ID.
    $user_id = get_current_user_id();

    // If no user is logged in, return the original template path.
    if ( ! $user_id ) {
        return $template_path;
    }

    // Simulate checking if the user has completed any courses.
    // In a real scenario, you'd likely use a WordPress function or plugin API.
    // For demonstration, let's assume a function `my_has_user_completed_any_courses()` exists.
    // Replace this with actual logic to check course completion.
    $has_completed_courses = false; // Default to false
    // Example: if ( my_has_user_completed_any_courses( $user_id ) ) { $has_completed_courses = true; }

    // For this example, let's just randomly decide if they completed courses to show variety.
    if ( rand(0, 1) === 1 ) {
        $has_completed_courses = true;
    }


    if ( $has_completed_courses ) {
        // If the user has completed courses, return a path to a custom template.
        // This custom template could display a congratulatory message or a summary of achievements.
        // Ensure this template file exists in your theme's directory.
        $custom_template_path = get_stylesheet_directory() . '/my-templates/frontend-dashboard/dashboard-template-3_0-congratulations.php';

        // Check if our custom template file exists. If not, fall back to the original.
        if ( file_exists( $custom_template_path ) ) {
            return $custom_template_path;
        } else {
            // If the custom template isn't found, return the original path.
            return $template_path;
        }
    } else {
        // If the user hasn't completed courses (or we haven't determined they have),
        // return the original template path.
        return $template_path;
    }
}

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

src/classes/reports/learndash-progress-report.php:902

}

		//Check to see if the file is in template to override default template.
		$file_path = get_stylesheet_directory() . '/uncanny-learndash-groups/templates/frontend-course-management/dashboard-template-3_0.php';

		if ( ! file_exists( $file_path ) ) {
			//$file_path = apply_filters( 'uo-dashboard-template-3-0', self::get_template( 'frontend-dashboard/dashboard-template-3_0.php', dirname( dirname( __FILE__ ) ) . '/src' ) );
			$file_path = apply_filters( 'uo-dashboard-template-3-0', Utilities::get_template( 'frontend-course-management/dashboard-template-3_0.php' ), UNCANNY_GROUPS_PLUGIN . '/src/templates/frontend-course-management' );
		}

		$level = ob_get_level();
		ob_start();

		LD_QuizPro::showModalWindow();


Scroll to Top