Filter uncanny-learndash-toolkit

uo_resume_button_permalink

Filters the permalink for the resume button, allowing modification of the URL before it's displayed.

add_filter( 'uo_resume_button_permalink', $callback, 10, 1 );

Description

Allows modification of the resume button's permalink. Developers can alter the URL used for the "Resume" button, which points to a specific lesson or topic. This filter receives the current permalink, the step ID, and the course ID.


Usage

add_filter( 'uo_resume_button_permalink', 'your_function_name', 10, 1 );

Return Value

The filtered value.


Examples

/**
 * Filters the permalink for the "Resume" button to potentially redirect to a different URL.
 *
 * This example demonstrates how to modify the resume button's permalink.
 * For instance, you might want to redirect users to a specific landing page
 * or a custom lesson if certain conditions are met.
 *
 * @param string $permalink       The original permalink of the resume button.
 * @param int    $step_id         The ID of the current step (lesson/topic/quiz).
 * @param int    $step_course_id  The ID of the course the step belongs to.
 *
 * @return string The modified permalink.
 */
add_filter(
	'uo_resume_button_permalink',
	function ( $permalink, $step_id, $step_course_id ) {
		// Example: If the step is a specific quiz and the user is an administrator,
		// redirect them to a custom quiz review page instead of the original quiz.
		if ( get_post_type( $step_id ) === 'quiz' && current_user_can( 'manage_options' ) ) {
			// Replace 'your_custom_quiz_review_page_slug' with the actual slug of your custom page.
			$custom_review_page_url = home_url( '/your_custom_quiz_review_page_slug/?quiz_id=' . $step_id );
			return esc_url( $custom_review_page_url );
		}

		// Example: If the step is a topic and the user has completed the course,
		// redirect them to the course completion page.
		if ( get_post_type( $step_id ) === 'topic' && learndash_is_course_completed( $step_course_id, get_current_user_id() ) ) {
			// Assuming you have a way to get the course completion page URL.
			// This is a placeholder; you'd likely use get_post_meta() or a dedicated function.
			$course_completion_page_url = get_post_meta( $step_course_id, 'course_completion_redirect', true );
			if ( ! empty( $course_completion_page_url ) ) {
				return esc_url( $course_completion_page_url );
			}
		}

		// If no special conditions are met, return the original permalink.
		return $permalink;
	},
	10, // Priority
	3  // Accepted arguments
);

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/learn-dash-resume.php:248
src/classes/learn-dash-resume.php:404

ob_start();

						if ( function_exists( 'learndash_get_step_permalink' ) ) {
							$permalink = learndash_get_step_permalink( $step_id, $step_course_id );
						} else {
							$permalink = get_permalink( $step_id );
						}
						$permalink = apply_filters( 'uo_resume_button_permalink', $permalink, $step_id, $step_course_id );

						printf(
							'<a href="%s" title="%s" class="%s"><input type="submit" value="%s" class=""></a>',
							$permalink,
							esc_attr(
								sprintf(
									esc_html_x( 'Resume %s: %s', 'LMS shortcode Resume link title "Resume post_type_name: Post_title ', 'uncanny-learndash-toolkit' ),


Scroll to Top