Uncanny Toolkit for LearnDash Shortcodes

Below, you’ll find a detailed guide on how to add the Uncanny Toolkit for LearnDash Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Uncanny Toolkit for LearnDash Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the Uncanny Toolkit for LearnDash Plugin and the shortcodes it provides:

Plugin Icon
Uncanny Toolkit for LearnDash

"Uncanny Toolkit for LearnDash is a powerful plugin that enhances your e-learning platform with robust features. It simplifies course creation, student management, and overall LearnDash usability."

★★★★☆ (102) Active Installs: 30000+ Tested with: 6.2.3 PHP Version: 7.0
Included Shortcodes:
  • [uo_breadcrumbs]
  • [uo_login]
  • [uo-learndash-resume]
  • [uo_learndash_resume_link]
  • [uo_course_resume]
  • [uo_login_link]
  • [uo_loginout]
  • [uo_logout]
  • [uo_register]
  • [uo-learndash-certificates]
  • [uo-show]

Uncanny Toolkit for LearnDash [uo_breadcrumbs] Shortcode

The Uncanny LearnDash Toolkit shortcode ‘uo_breadcrumbs’ is used to create navigational breadcrumbs on your LearnDash site. It provides a trail for users to follow back to the starting point of their navigation. It’s highly customizable, allowing you to define variables like the dashboard link, text, and separator. The code also includes conditions for various post types and archive pages, ensuring accurate breadcrumb trails.

Shortcode: [uo_breadcrumbs]

Examples and Usage

Basic example – Displaying the breadcrumb navigation on your site using the ‘uo_breadcrumbs’ shortcode.

[uo_breadcrumbs]

PHP Function Code

In case you have difficulties debugging what causing issues with [uo_breadcrumbs] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'uo_breadcrumbs', array( __CLASS__, 'uo_breadcrumbs' ) );

Shortcode PHP function:

function uo_breadcrumbs() {
		global $wp_query;
		//$wp_query = new WP_Query();
		$learn_dash_labels = new \LearnDash_Custom_Label();
		$course_label      = $learn_dash_labels::get_label( 'courses' );
		// Define main variables
		$trail   = array();
		$trail[] = self::uo_build_anchor_links( get_bloginfo( 'url' ), esc_html__( 'Home', 'uncanny-learndash-toolkit' ), 'get-blog-info-url' );
		//$dashboard_link      = get_post_type_archive_link( 'sfwd-courses' );
		$dashboard_link      = '';
		$dashboard_text      = 'Dashboard';
		$dashboard_separator = '»';

		$get_dashboard_text       = self::get_settings_value( 'uncanny-breadcrumbs-dashboard-text', __CLASS__ );
		$get_dashboard_link       = self::get_settings_value( 'uncanny-breadcrumbs-dashboard-link', __CLASS__ );
		$get_dashboard_separator  = self::get_settings_value( 'uncanny-breadcrumbs-dashboard-separator', __CLASS__ );
		$get_include_current_page = self::get_settings_value( 'uncanny-breadcrumbs-include-current-page', __CLASS__ );
		$course_archive_link      = self::uo_build_anchor_links( get_post_type_archive_link( 'sfwd-courses' ), esc_html__( $course_label, 'uncanny-learndash-toolkit' ), 'course-archive-link' );
		//$course_archive_link     = self::uo_build_anchor_links( get_post_type_archive_link( 'sfwd-courses' ), esc_html__( 'Courses', 'uncanny-learndash-toolkit' ) );

		if ( strlen( trim( $get_dashboard_text ) ) ) {
			$dashboard_text = $get_dashboard_text;
		}

		if ( strlen( trim( $get_dashboard_link ) ) && '0' !== $get_dashboard_link ) {
			$dashboard_link = get_permalink( $get_dashboard_link );
			$dashboard_link = self::uo_build_anchor_links( $dashboard_link, $dashboard_text, 'dashboard-link-no-get-dashboard-link' );
		}

		if ( strlen( trim( $get_dashboard_separator ) ) ) {
			$dashboard_separator = $get_dashboard_separator;
		}
		$lesson_id = false;

		// If it's on home page
		if ( is_front_page() ) {
			$trail = array(); //Removing Single Home link from Homepage.
		} elseif ( is_singular() ) {
			// Get singular vars (page, post, attachments)
			$post      = $wp_query->get_queried_object();
			$post_id   = absint( $wp_query->get_queried_object_id() );
			$post_type = $post->post_type;

			if ( 'post' === $post_type ) {
				$maybe_tax = self::uo_post_taxonomy( $post_id );

				if ( false !== $maybe_tax ) {
					$trail[] = $maybe_tax;
				}
				$trail[] = get_the_title( $post_id );

			} elseif ( 'page' === $post_type ) {
				// If Woocommerce is installed and being viewed, add shop page to cart, checkout pages
				if ( class_exists( 'Woocommerce' ) ) {

					if ( is_cart() || is_checkout() ) {
						// Get shop page
						if ( function_exists( 'wc_get_page_id' ) ) {
							$shop_id    = wc_get_page_id( 'shop' );
							$shop_title = get_the_title( $shop_id );
							if ( function_exists( 'wpml_object_id' ) ) {
								$shop_title = get_the_title( wpml_object_id( $shop_id, 'page' ) );
							}
							// Shop page
							if ( $shop_id && $shop_title ) {
								$trail[] = self::uo_build_anchor_links( get_permalink( $shop_id ), $shop_title, 'woo-shop-page' );
							}
						}
					}
					if ( $get_include_current_page === 'on' ) {
						$trail[] = '<span class="uo-current_page">' . get_the_title( $post_id ) . '</span>';
					}
				} else {
					// Regular pages. See if the page has any ancestors. Add in the trail if ancestors are found
					$ancestors = get_ancestors( $post_id, 'page' );
					if ( ! empty ( $ancestors ) ) {
						$ancestors = array_reverse( $ancestors );
						foreach ( $ancestors as $page ) {
							$trail[] = self::uo_build_anchor_links( get_permalink( $page ), get_the_title( $page ), 'regular-page-ancestors' );
						}
					}
					if ( $get_include_current_page === 'on' ) {
						$trail[] = '<span class="uo-current_page">' . get_the_title( $post_id ) . '</span>';
					}
				}
			} elseif ( 'sfwd-courses' === $post_type ) {
				// See if Single Course is being displayed.
				if ( strlen( trim( $get_dashboard_link ) ) && '0' !== $get_dashboard_link ) {
					$trail[] = $dashboard_link;
				} else {
					$trail[] = $course_archive_link;
				}
				if ( $get_include_current_page === 'on' ) {
					$trail[] = '<span class="uo-current_page">' . get_the_title( $post_id ) . '</span>';
				}
			} elseif ( 'sfwd-lessons' === $post_type ) {
				// See if Single Lesson is being displayed.
				$course_id = learndash_get_course_id( $post_id );  // Getting Parent Course ID
				if ( strlen( trim( $get_dashboard_link ) ) && '0' !== $get_dashboard_link ) {
					$trail[] = $dashboard_link;
				} else {
					$trail[] = $course_archive_link;
				}
				$trail[] = self::uo_build_anchor_links( get_permalink( $course_id ), get_the_title( $course_id ), 'lessons-course-link' ); // Getting Lesson's Course Link

				if ( $get_include_current_page === 'on' ) {
					$trail[] = '<span class="uo-current_page">' . get_the_title( $post_id ) . '</span>';
				}
			} elseif ( 'sfwd-topic' === $post_type ) {
				// See if single Topic is being displayed
				$course_id = learndash_get_course_id( $post_id ); // Getting Parent Course ID
				$lesson_id = learndash_get_lesson_id( $post_id, $course_id ); // Getting Parent Lesson ID
				if ( strlen( trim( $get_dashboard_link ) ) && '0' !== $get_dashboard_link ) {
					$trail[] = $dashboard_link;
				} else {
					$trail[] = $course_archive_link;
				}
				$trail[] = self::uo_build_anchor_links( get_permalink( $course_id ), get_the_title( $course_id ), 'topics-course-link' ); // Getting Lesson's Course Link
				$trail[] = self::uo_build_anchor_links( get_permalink( $lesson_id ), get_the_title( $lesson_id ), 'topics-lesson-link' ); // Getting Topics's Lesson Link
				if ( $get_include_current_page === 'on' ) {
					$trail[] = '<span class="uo-current_page">' . get_the_title( $post_id ) . '</span>';
				}
			} elseif ( 'sfwd-quiz' === $post_type ) {
				// See if quiz is being displayed
				$course_id = learndash_get_course_id( $post_id ); // Getting Parent Course ID
				if ( strlen( trim( $get_dashboard_link ) ) && '0' !== $get_dashboard_link ) {
					$trail[] = $dashboard_link;
				} else {
					$trail[] = $course_archive_link;
				}

				$topic_id = learndash_get_lesson_id( $post_id, $course_id ); // Getting Parent Topic/Lesson ID

				if ( 'sfwd-topic' === get_post_type( $topic_id ) ) {
					$lesson_id = learndash_get_lesson_id( $topic_id, $course_id ); // Getting Parent Lesson ID
				} else {
					// detect topic id & grab lesson id
					$parent_ids = learndash_course_get_all_parent_step_ids( $course_id, $post_id );
					if ( ! empty( $parent_ids ) ) {
						foreach ( $parent_ids as $parent_id ) {
							if ( get_post_type( $parent_id ) === learndash_get_post_type_slug( 'topic' ) ) {
								$topic_id = $parent_id;
								$lesson_id = learndash_get_lesson_id( $topic_id, $course_id ); // Getting Parent Lesson ID
								break;
							}
						}
					}
				}

				$trail[] = self::uo_build_anchor_links( get_permalink( $course_id ), get_the_title( $course_id ), 'quizs-course-link' ); // Getting Lesson's Course Link
				//If $lesson_id is false, the quiz is associated with a lesson and course but not a topic.
				if ( $lesson_id ) {
					$trail[] = self::uo_build_anchor_links( get_permalink( $lesson_id ), get_the_title( $lesson_id ), 'quizs-lesson-link' ); // Getting Topics's Lesson Link
				}
				//If $topic_id is false, the quiz is associated with a course but not associated with any lessons or topics.
				if ( $topic_id ) {
					$trail[] = self::uo_build_anchor_links( get_permalink( $topic_id ), get_the_title( $topic_id ), 'quizs-topic-link' );
				}
				if ( $get_include_current_page === 'on' ) {
					$trail[] = '<span class="uo-current_page">' . get_the_title( $post_id ) . '</span>';
				}

			} else {
				// Add shop page to single product
				if ( 'product' === $post_type ) {
					// Get shop page
					if ( class_exists( 'Woocommerce' ) && function_exists( 'wc_get_page_id' ) ) {
						$shop_id    = wc_get_page_id( 'shop' );
						$shop_title = get_the_title( $shop_id );
						if ( function_exists( 'wpml_object_id' ) ) {
							$shop_title = get_the_title( wpml_object_id( $shop_id, 'page' ) );
						}

						// Shop page
						if ( $shop_id && $shop_title ) {
							$trail[] = self::uo_build_anchor_links( get_permalink( $shop_id ), $shop_title, 'products-woo-shop-page' );
						}
					}
				}

				// Getting terms of the post.
				if ( self::lms_get_taxonomy( $post_id, $post_type ) ) {
					$trail[] = self::lms_get_taxonomy( $post_id, $post_type );
				}
				if ( $get_include_current_page === 'on' ) {
					$trail[] = '<span class="uo-current_page">' . get_the_title( $post_id ) . '</span>';
				}
			}
		}
		// If it's an Archive
		if ( is_archive() ) {
			//Ignore if Courses & Products
			if ( ! is_post_type_archive( 'sfwd-courses' ) && ! is_post_type_archive( 'product' ) ) {
				if ( is_category() || is_tax() ) {
					$trail[] = single_cat_title( '', false ); // If its Blog Category
				}
				if ( is_day() ) {
					$trail[] = get_the_date(); // If its Single Day Archive
				}
				if ( is_month() ) {
					$trail[] = get_the_date( __( 'F Y', 'uncanny-learndash-toolkit' ) ) . esc_html__( ' Archives', 'uncanny-learndash-toolkit' ); // If Mothly Archives
				}
				if ( is_year() ) {
					$trail[] = get_the_date( __( 'Y', 'uncanny-learndash-toolkit' ) ) . esc_html__( ' Archives', 'uncanny-learndash-toolkit' ); // If its Yearly Archives
				}
				if ( is_author() ) {
					$trail[] = get_the_author(); // If its Author's Archives
				}
			} elseif ( is_post_type_archive( 'sfwd-courses' ) ) {
				$trail[] = esc_html__( $course_label, 'uncanny-learndash-toolkit' );
			} elseif ( is_post_type_archive( 'product' ) ) {
				$trail[] = esc_html__( 'Shop', 'uncanny-learndash-toolkit' );
			}
		}

		if ( is_search() ) {
			$trail[] = esc_html__( 'Search', 'uncanny-learndash-toolkit' );
			$trail[] = get_search_query();
		}

		// Build breadcrumbs
		$classes = 'sfwd-breadcrumbs clr';

		if ( array_key_exists( 'the_content', $GLOBALS['wp_filter'] ) ) {
			$classes .= ' lms-breadcrumbs ';
		}

		// Open breadcrumbs
		$breadcrumb = '<nav aria-label="' . esc_html__( 'Breadcrumb', 'uncanny-learndash-toolkit' ) . '" class="' . esc_attr( $classes ) . '"><div class="breadcrumb-trail">';

		// Separator HTML
		$separator = '<span class="sep"> ' . stripslashes( $dashboard_separator ) . ' </span>';

		// Join all trail items into a string
		$breadcrumb .= implode( $separator, $trail );

		// Close breadcrumbs
		$breadcrumb .= '</div></nav>';

		return $breadcrumb;
	}

Code file location:

uncanny-learndash-toolkit/uncanny-learndash-toolkit/src/classes/breadcrumbs.php

Uncanny Toolkit for LearnDash [uo_login] Shortcode

The Uncanny LearnDash Toolkit shortcode ‘uo_login’ is used to create a custom login form. It checks if a user is logged in, and displays a logout link or login form accordingly. The shortcode accepts various attributes like ‘username-label’, ‘password-label’, ‘rememberme-label’, etc. to customize the login form. It also supports reCAPTCHA for added security.

Shortcode: [uo_login]

Parameters

Here is a list of all possible uo_login shortcode parameters and attributes:

  • username-label – label for the username field in the form
  • password-label – label for the password field in the form
  • rememberme-label – label for the remember me checkbox
  • placeholder – defines whether placeholders should be used or not
  • redirect – URL where user is redirected after successful login
  • login-button-label – text displayed on the login button

Examples and Usage

Basic example – Display a login form on your page or post using the ‘uo_login’ shortcode.

[uo_login /]

Advanced examples

Display a login form with custom labels for the username and password fields.

[uo_login username-label="Enter your username" password-label="Enter your password" /]

Display a login form with a custom label for the remember me checkbox, and a custom label for the login button.

[uo_login rememberme-label="Remember my login details" login-button-label="Sign In" /]

Display a login form with a custom redirect URL. After successful login, the user will be redirected to the specified URL.

[uo_login redirect="https://yourwebsite.com/welcome" /]

Combine multiple parameters to customize the login form as per your needs.

[uo_login username-label="Enter your username" password-label="Enter your password" rememberme-label="Remember my login details" login-button-label="Sign In" redirect="https://yourwebsite.com/welcome" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [uo_login] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'uo_login', array( __CLASS__, 'uo_login_form' ) );

Shortcode PHP function:

function uo_login_form( $atts, $content = null ) {

		$hide_logged_in_ui = self::get_settings_value( 'hide_logged_in_ui', __CLASS__ );

		if ( is_user_logged_in() && 'on' === $hide_logged_in_ui ) {
			return '';
		}

		if ( is_user_logged_in() ) {

			if ( ! empty( $content ) ) {
				return do_shortcode( $content );
			}

			$logged_in_message = self::get_settings_value( 'uo_frontend_login_logged_in_message', __CLASS__, '%placeholder%', self::get_class_settings( '', true ) );

			$logout_link_text = self::get_settings_value( 'uo_frontend_logout_text', __CLASS__, '%placeholder%', self::get_class_settings( '', true ) );

			$logout_link = '<a href="' . wp_logout_url() . '" title="' . $logout_link_text . '">' . $logout_link_text . '</a>';

			return $logged_in_message . ' ' . $logout_link;
		}

		$username_label = ( isset( $atts['username-label'] ) ) ?
			$atts['username-label'] :
			self::get_settings_value( 'uo_login_username_label_login', __CLASS__, '%placeholder%', self::get_class_settings( '', true ) );

		$password_label = ( isset( $atts['password-label'] ) ) ?
			$atts['password-label'] :
			self::get_settings_value( 'uo_frontend_login_password_label', __CLASS__, '%placeholder%', self::get_class_settings( '', true ) );

		$rememberme_label = ( isset( $atts['rememberme-label'] ) ) ?
			$atts['rememberme-label'] :
			self::get_settings_value( 'uo_frontend_login_rememberme_label', __CLASS__, '%placeholder%', self::get_class_settings( '', true ) );

		$placeholder = ( isset( $atts['placeholder'] ) ? $atts['placeholder'] : 'yes' );
		$redirect    = ( isset( $atts['redirect'] ) ? $atts['redirect'] : home_url() );

		$submit_label = ( isset( $atts['login-button-label'] ) ) ?
			$atts['login-button-label'] :
			self::get_settings_value( 'uo_frontend_login_button_label', __CLASS__, '%placeholder%', self::get_class_settings( '', true ) );

		$recaptcha_key         = self::get_catpcha_key();
		$recaptcha_secrete_key = self::get_captcha_secret();

		if ( '' !== trim( $recaptcha_key ) && '' !== trim( $recaptcha_secrete_key ) ) {
			self::add_recaptcha_box();
		}

		if ( 'no' !== $placeholder ) {
			?>
			<script type='text/javascript'>
				jQuery(document).ready(function () {
					jQuery('#user_login').attr('placeholder', '<?php echo $username_label; ?>')
					jQuery('#user_pass').attr('placeholder', '<?php echo $password_label; ?>')
				})
			</script>
			<?php
			$username_label = '';
			$password_label = '';
		}

		// Override if redirect_to already set in login request.
		if ( isset( $_REQUEST['redirect_to'] ) && ! empty( $_REQUEST['redirect_to'] ) ) {
			$redirect = $_REQUEST['redirect_to'];
		}
		//Add an additional query variable for login redirect module. It'll override [uo_login redirect]
		if ( ! empty( $redirect ) ) {
			$redirect = strpos( $redirect, '?' ) ? $redirect . '&uo_redirect=1' : $redirect . '?uo_redirect';
		}

		$base_login_form_args = self::fetch_login_form_args();

		$login_form_args = array(
			'echo'           => false,
			'redirect'       => $redirect,
			'form_id'        => 'loginform',
			'label_username' => $username_label,
			'label_password' => $password_label,
			'label_remember' => $rememberme_label,
			'label_log_in'   => $submit_label,
			'id_username'    => 'user_login',
			'id_password'    => 'user_pass',
			'id_remember'    => 'rememberme',
			'id_submit'      => 'wp-submit',
			'remember'       => isset( $base_login_form_args['remember'] ) ? $base_login_form_args['remember'] : true,
			'value_username' => null,
			'value_remember' => true,
		);

		$login_form_args = apply_filters( 'uo_frontend_login_args', $login_form_args );

		return wp_login_form( $login_form_args );
	}

Code file location:

uncanny-learndash-toolkit/uncanny-learndash-toolkit/src/classes/frontend-login-plus.php

Uncanny Toolkit for LearnDash [uo-learndash-resume] Shortcode

The UO-LearnDash-Resume shortcode is a part of the Uncanny LearnDash Toolkit plugin. It allows users to resume their learning from where they left off. The PHP function ‘learndash_resume’ calls the ‘resume_function’, which enables the resume feature.

Shortcode: [uo-learndash-resume]

Examples and Usage

Basic example – The basic usage of the ‘uo-learndash-resume’ shortcode allows you to display the Learndash resume button on your website. This shortcode doesn’t require any parameters.

[uo-learndash-resume /]

PHP Function Code

In case you have difficulties debugging what causing issues with [uo-learndash-resume] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'uo-learndash-resume', array( __CLASS__, 'learndash_resume' ) );

Shortcode PHP function:

function learndash_resume() {
		return self::resume_function();
	}

Code file location:

uncanny-learndash-toolkit/uncanny-learndash-toolkit/src/classes/learn-dash-resume.php

Uncanny Toolkit for LearnDash [uo_learndash_resume_link] Shortcode

The Uncanny-Learndash-Toolkit plugin shortcode, ‘uo_learndash_resume_link’, allows users to resume their course from where they left off. It accepts ‘url_only’ as an attribute, which when set to ‘no’, displays the entire link. Otherwise, it only shows the URL.

Shortcode: [uo_learndash_resume_link]

Parameters

Here is a list of all possible uo_learndash_resume_link shortcode parameters and attributes:

  • url_only – Determines whether to return just the URL or the complete link

Examples and Usage

Basic example – The shortcode ‘uo_learndash_resume_link’ is used to resume the learning process in a LearnDash course. The ‘url_only’ attribute can be set to ‘no’ or ‘yes’. If it is set to ‘no’, the shortcode will return the full HTML for the resume link. If it is set to ‘yes’, the shortcode will return only the URL for the resume link.

[uo_learndash_resume_link url_only="no"]

Advanced examples

Using the shortcode to return only the URL for the resume link.

[uo_learndash_resume_link url_only="yes"]

Using the shortcode without any attribute. By default, ‘url_only’ is set to ‘no’, so this will return the full HTML for the resume link.

[uo_learndash_resume_link]

PHP Function Code

In case you have difficulties debugging what causing issues with [uo_learndash_resume_link] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'uo_learndash_resume_link', array( __CLASS__, 'learndash_resume_link' ) );

Shortcode PHP function:

function learndash_resume_link( $atts ) {
		$atts = shortcode_atts( array(
			'url_only' => 'no',
		), $atts, 'uo_learndash_resume_link' );

		return self::resume_function( true, $atts['url_only'] );
	}

Code file location:

uncanny-learndash-toolkit/uncanny-learndash-toolkit/src/classes/learn-dash-resume.php

Uncanny Toolkit for LearnDash [uo_course_resume] Shortcode

The Uncanny LearnDash Toolkit’s shortcode, ‘uo_course_resume’, allows users to resume their course from where they left off. It fetches the last known step of the user in the course and provides a resume link.

Shortcode: [uo_course_resume]

Parameters

Here is a list of all possible uo_course_resume shortcode parameters and attributes:

  • course_id – The unique identifier of the course
  • show_name – Option to display the course name, default is ‘yes’

Examples and Usage

Basic example – Display the resume button for a specific course by providing the course ID.

[uo_course_resume course_id=123 /]

Advanced examples

Display the resume button for a specific course and hide the course name on the button by setting ‘show_name’ attribute to ‘no’.

[uo_course_resume course_id=123 show_name=no /]

Display the resume button without specifying a course ID. The button will be linked to the last known course that the user accessed. The course name will be displayed on the button.

[uo_course_resume /]

Display the resume button for a specific course and show the course name on the button by setting ‘show_name’ attribute to ‘yes’.

[uo_course_resume course_id=123 show_name=yes /]

PHP Function Code

In case you have difficulties debugging what causing issues with [uo_course_resume] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'uo_course_resume', array( __CLASS__, 'uo_course_resume' ) );

Shortcode PHP function:

function uo_course_resume( $atts ) {
		$atts = shortcode_atts( array(
			'course_id' => '',
			'show_name' => 'yes',
		), $atts, 'uo_course_resume' );

		if ( is_user_logged_in() ) {
			if ( ! empty( $atts['course_id'] ) ) {
				$user           = wp_get_current_user();
				$step_course_id = $atts['course_id'];
				$course         = get_post( $step_course_id );

				if ( isset( $course ) && 'sfwd-courses' === $course->post_type ) {
					$last_know_step = get_user_meta( $user->ID, 'learndash_last_known_course_' . $step_course_id, true );

					// User has not hit a LD module yet
					if ( empty( $last_know_step ) ) {

						return '';
					}

					//$step_course_id = 0;
					// Sanity Check
					if ( absint( $last_know_step ) ) {
						$step_id = $last_know_step;
					} else {
						return '';
					}


					$last_know_post_object = get_post( $step_id );

					// Make sure the post exists and that the user hit a page that was a post
					// if $last_know_page_id returns '' then get post will return current pages post object
					// so we need to make sure first that the $last_know_page_id is returning something and
					// that the something is a valid post
					if ( null !== $last_know_post_object ) {

						$post_type        = $last_know_post_object->post_type; // getting post_type of last page.
						$label            = get_post_type_object( $post_type ); // getting Labels of the post type.
						$title            = $last_know_post_object->post_title;
						$resume_link_text = __( 'RESUME', 'uncanny-learndash-toolkit' );

						// Resume Link Text
						$link_text = self::get_settings_value( 'learn-dash-resume-button-text', __CLASS__ );
						$show_name = self::get_settings_value( 'learn-dash-resume-show-name', __CLASS__ );

						if ( strlen( trim( $link_text ) ) ) {
							$resume_link_text = __( $link_text, 'uncanny-learndash-toolkit' );
						} else {
							$resume_link_text = __( 'Resume', 'uncanny-learndash-toolkit' );
						}

						$resume_link_text = apply_filters( 'learndash_resume_link_text', $resume_link_text );

						$css_classes = apply_filters( 'learndash_resume_css_classes', 'learndash-resume-button' );

						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' ),
									$label->labels->singular_name,
									$title
								)
							),
							esc_attr( $css_classes ),
							esc_attr( $resume_link_text )
						);

						if ( $show_name === 'on' && 'yes' === $atts['show_name'] ) {
							printf(
								'<div class="resume-item-name">%s</div>',
								$title
							);
						}

						$resume_link = ob_get_contents();
						ob_end_clean();

						return $resume_link;
					}
				}
			}
		}

		return '';
	}

Code file location:

uncanny-learndash-toolkit/uncanny-learndash-toolkit/src/classes/learn-dash-resume.php

Uncanny Toolkit for LearnDash [uo_login_link] Shortcode

The Uncanny-Learndash-Toolkit shortcode, ‘uo_login_link’, is designed to create a login link. It uses the PHP function ‘login_link’ to generate a hyperlink for users to log in. This shortcode supports customization such as editing HTML tags and redirecting to a specific URL after login. It defaults to the current page if no URL is specified. The link text can be customized, defaulting to ‘Log In’.

Shortcode: [uo_login_link]

Parameters

Here is a list of all possible uo_login_link shortcode parameters and attributes:

  • edit_tag – Defines HTML attributes for the login link
  • redirect – Specifies the URL to redirect to after login

Examples and Usage

Basic example – The shortcode “uo_login_link” can be used to create a simple login link. By default, it redirects to the current page after the user logs in.

[uo_login_link]

Advanced examples

Adding a custom text to the login link can be done by simply inserting the text within the shortcode. This replaces the default “Log In” text.

[uo_login_link]Click here to Login[/uo_login_link]

The “uo_login_link” shortcode also accepts parameters. The “edit_tag” parameter can be used to add additional HTML attributes to the link, while the “redirect” parameter can be used to specify a custom redirection URL after the user logs in.

[uo_login_link edit_tag="class='custom-class' id='custom-id'" redirect="https://www.example.com/dashboard/"]Login[/uo_login_link]

Please note that the “redirect” parameter accepts absolute URLs only. Also, be careful with the “edit_tag” parameter as it directly affects the HTML output of the login link. Always ensure to use valid HTML attributes.

PHP Function Code

In case you have difficulties debugging what causing issues with [uo_login_link] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'uo_login_link', array( __CLASS__, 'login_link' ) );

Shortcode PHP function:

function login_link( $atts, $content = null ) {
		$atts = shortcode_atts( array(
			"edit_tag" => "",
			"redirect" => esc_url( $_SERVER['REQUEST_URI'] )
		), $atts, 'login' );

		$edit_tag = esc_html( strip_tags( $atts['edit_tag'] ) );
		$href     = wp_login_url( /*$atts['redirect']*/ );
		$content  = $content != '' ? $content : __( 'Log In', 'uncanny-learndash-toolkit' );

		return '<a href="' . esc_url( $href ) . '"' . $atts['edit_tag'] . '>' . $content . '</a>';
	}

Code file location:

uncanny-learndash-toolkit/uncanny-learndash-toolkit/src/classes/login-logout-menu.php

Uncanny Toolkit for LearnDash [uo_loginout] Shortcode

The Uncanny-LearnDash-Toolkit shortcode, ‘uo_loginout’, dynamically generates a login/logout link. It uses the ‘loginout_link’ function to customize the link text and redirect page. The function takes in the ‘edit_tag’ and ‘redirect’ parameters, defaulting to the current page URL. It also allows custom ‘log_in_text’ and ‘log_out_text’. The link displayed depends on the user’s login status. If a user is logged in, the logout link is shown and vice versa.

Shortcode: [uo_loginout]

Parameters

Here is a list of all possible uo_loginout shortcode parameters and attributes:

  • edit_tag – Allows addition of custom attributes to the login/logout link
  • redirect – Determines the URL where users will be redirected after logging in or out
  • log_in_text – Sets the text of the login link
  • log_out_text – Sets the text of the logout link

Examples and Usage

Basic example – The shortcode is used to display a login or logout link based on the user’s status. If the user is logged in, it will show a logout link, otherwise, it will show a login link.

[uo_loginout /]

Advanced examples

Using the shortcode with custom login and logout text. The ‘log_in_text’ and ‘log_out_text’ attributes are used to specify the text displayed for the login and logout links, respectively.

[uo_loginout log_in_text="Enter" log_out_text="Exit" /]

Using the shortcode with a redirect URL. The ‘redirect’ attribute is used to specify the URL where the user will be redirected after clicking the login or logout link.

[uo_loginout redirect="https://yourwebsite.com/welcome/" /]

Using the shortcode with all the available attributes. This example uses custom login and logout text, a redirect URL, and an ‘edit_tag’ which allows you to add additional HTML tags to the link.

[uo_loginout edit_tag="class='my-class'" redirect="https://yourwebsite.com/welcome/" log_in_text="Enter" log_out_text="Exit" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [uo_loginout] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'uo_loginout', array( __CLASS__, 'loginout_link' ) );

Shortcode PHP function:

function loginout_link( $atts, $content = null ) {
		$atts = shortcode_atts( array(
			"edit_tag" => "",
			"redirect" => esc_url( $_SERVER['REQUEST_URI'] ),
			"log_in_text"  => esc_html__( 'Log In', 'uncanny-learndash-toolkit' ),
			"log_out_text" => esc_html__( 'Logout', 'uncanny-learndash-toolkit' )
		), $atts, 'loginout' );

		$edit_tag = strip_tags( $atts['edit_tag'] );
		$href     = is_user_logged_in() ? wp_logout_url( /*$atts['redirect']*/ ) : wp_login_url( /*$atts['redirect']*/ );
		if ( $content && strstr( $content, '|' ) != '' ) { // the "|" char is used to split titles
			$content = explode( '|', $content );
			$content = is_user_logged_in() ? $content[1] : $content[0];
		} else {
			$content = is_user_logged_in() ? $atts[ 'log_out_text' ] : $atts[ 'log_in_text' ];
		}

		return '<a href="' . esc_url( $href ) . '"' . $atts['edit_tag'] . '>' . $content . '</a>';
	}

Code file location:

uncanny-learndash-toolkit/uncanny-learndash-toolkit/src/classes/login-logout-menu.php

Uncanny Toolkit for LearnDash [uo_logout] Shortcode

The Uncanny-LearnDash-Toolkit shortcode ‘uo_logout’ is designed to create a logout link for users. It uses a built-in WordPress function, wp_logout_url(), to generate the URL for logging out. The shortcode accepts two optional attributes: “edit_tag” and “redirect”. The “edit_tag” attribute allows you to add custom HTML tags to the logout link. Meanwhile, the “redirect” attribute lets you specify a URL to redirect users to after they log out. Shortcode: [uo_logout edit_tag=”class=’my-class’” redirect=”https://mywebsite.com/”] If no content is provided, the link text defaults to ‘Logout’. However, you can customize this by adding content inside the shortcode. Shortcode: [uo_logout]Click here to log out[/uo_logout]

Shortcode: [uo_logout]

Parameters

Here is a list of all possible uo_logout shortcode parameters and attributes:

  • edit_tag – Allows you to add extra HTML elements to the logout link
  • redirect – Define the URL where users will be redirected after logging out

Examples and Usage

Basic example – The shortcode will display a logout link. By default, it will redirect to the current page after logging out.

[uo_logout /]

Advanced examples

Adding a custom redirect URL after logout. In this example, the user will be redirected to the home page after logging out.

[uo_logout redirect="https://www.yourwebsite.com" /]

Adding custom text to the logout link. The custom text will be displayed instead of the default “Logout” text.

[uo_logout]Click here to logout[/uo_logout]

Combining both custom redirect and custom text. The user will be redirected to a custom URL after logging out and the logout link will display a custom text.

[uo_logout redirect="https://www.yourwebsite.com"]Click here to logout[/uo_logout]

PHP Function Code

In case you have difficulties debugging what causing issues with [uo_logout] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'uo_logout', array( __CLASS__, 'logout_link' ) );

Shortcode PHP function:

function logout_link( $atts, $content = null ) {
		$atts = shortcode_atts( array(
			"edit_tag" => "",
			"redirect" => esc_url( $_SERVER['REQUEST_URI'] )
		), $atts, 'logout' );

		$href     = wp_logout_url( /*$atts['redirect']*/ );
		$edit_tag = esc_html( strip_tags( $atts['edit_tag'] ) );
		$content  = $content != '' ? $content : __( 'Logout', 'uncanny-learndash-toolkit' );

		return '<a href="' . esc_url( $href ) . '"' . $atts['edit_tag'] . '>' . $content . '</a>';
	}

Code file location:

uncanny-learndash-toolkit/uncanny-learndash-toolkit/src/classes/login-logout-menu.php

Uncanny Toolkit for LearnDash [uo_register] Shortcode

The Uncanny LearnDash Toolkit shortcode, ‘uo_register’, is designed to generate a registration link. If a user is logged in, it returns an empty string. If the user isn’t logged in, it generates a site-specific URL that leads to the registration page. The link text defaults to ‘Register’ unless specified otherwise in the content attribute.

Shortcode: [uo_register]

Examples and Usage

Basic example – The basic usage of the shortcode ‘uo_register’ creates a registration link for the website. When the user is not logged in, it displays the text ‘Register’ which is clickable and redirects to the registration page.

[uo_register /]

PHP Function Code

In case you have difficulties debugging what causing issues with [uo_register] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'uo_register', array( __CLASS__, 'register_link' ) );

Shortcode PHP function:

function register_link( $atts, $content = null ) {
		if ( is_user_logged_in() ) {
			return '';
		}
		$href    = site_url( 'wp-login.php?action=register', 'login' );
		$content = $content != '' ? $content : __( 'Register', 'uncanny-learndash-toolkit' );
		$link    = '<a href="' . $href . '">' . $content . '</a>';

		return $link;
	}

Code file location:

uncanny-learndash-toolkit/uncanny-learndash-toolkit/src/classes/login-logout-menu.php

Uncanny Toolkit for LearnDash [uo-learndash-certificates] Shortcode

The ‘uo-learndash-certificates’ shortcode from the Uncanny-Learndash-Toolkit plugin is designed to display a list of certificates earned by a logged-in user. It allows you to customize the display using various attributes. You can define the class, title, and ‘no-cert-message’. It also gives you the option to show or hide certificates from courses, quizzes, and groups. The shortcode generates a list of certificates, providing a link to each certificate, and displays a custom message if no certificates have been earned.

Shortcode: [uo-learndash-certificates]

Parameters

Here is a list of all possible uo-learndash-certificates shortcode parameters and attributes:

  • class – defines the CSS class for the certificate list container
  • title – sets the title for the certificate list
  • no-cert-message – sets the message displayed when there are no certificates
  • course_certificates – controls the display of course certificates (‘show’ or ‘hide’)
  • quiz_certificates – controls the display of quiz certificates (‘show’ or ‘hide’)
  • group_certificates – controls the display of group certificates (‘show’ or ‘hide’)

Examples and Usage

Basic example – Displaying the list of certificates for the logged-in user without any customizations. This is the simplest way to use the shortcode, and it will display the list of certificates in a default format.

[uo-learndash-certificates /]

Advanced examples

Displaying the list of certificates with a custom CSS class. By specifying the ‘class’ attribute, you can apply your own styles to the certificate list.

[uo-learndash-certificates class="my-custom-class" /]

Displaying the list of certificates with a custom title. The ‘title’ attribute allows you to specify a custom heading for the certificate list.

[uo-learndash-certificates title="My Certificates" /]

Displaying the list of certificates with a custom message when no certificates are available. The ‘no-cert-message’ attribute allows you to customize the message that is displayed when the user has not yet earned any certificates.

[uo-learndash-certificates no-cert-message="You haven't earned any certificates yet." /]

Controlling which types of certificates are displayed. The ‘course_certificates’, ‘quiz_certificates’, and ‘group_certificates’ attributes allow you to control whether course, quiz, and group certificates are displayed, respectively. You can set each of these attributes to either ‘show’ or ‘hide’.

[uo-learndash-certificates course_certificates="hide" quiz_certificates="show" group_certificates="show" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [uo-learndash-certificates] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'uo-learndash-certificates', array( __CLASS__, 'learndash_certificates' ) );

Shortcode PHP function:

function learndash_certificates( $atts ) {

		if ( ! is_user_logged_in() ) {
			return '';
		}

		if ( isset( $atts['class'] ) ) {
			$class = $atts['class'];
		} else {
			$class = 'certificate-list-container';
		}

		if ( isset( $atts['title'] ) ) {
			$title = $atts['title'];
		} else {
			$title = '';
		}

		if ( isset( $atts['no-cert-message'] ) ) {
			$no_cert_message = $atts['no-cert-message'];
		} else {
			$no_cert_message = esc_html__( 'Complete courses to earn certificates', 'uncanny-learndash-toolkit' );
		}

		$course_certificates = 'show';
		if ( isset( $atts['course_certificates'] ) ) {
			if ( in_array( $atts['course_certificates'], array('show','hide'), true ) ) {
				$course_certificates = $atts['course_certificates'];
			}
		}

		$quiz_certificates = 'show';
		if ( isset( $atts['quiz_certificates'] ) ) {
			if ( in_array( $atts['quiz_certificates'], array('show','hide'), true ) ) {
				$quiz_certificates = $atts['quiz_certificates'];
			}
		}

		$group_certificates = 'show';
		if ( isset( $atts['group_certificates'] ) ) {
			if ( in_array( $atts['group_certificates'], array('show','hide'), true ) ) {
				$group_certificates = $atts['group_certificates'];
			}
		}

		$show_cert_title  = self::get_settings_value( 'uncanny-showcertificate-show-cert-title', __CLASS__ );
		$certificate_list = '';
		$courses = array();
		$quiz_attempts = array();

		/* GET Certificates For Courses*/
		if( 'show' === $course_certificates ){
			$args = array(
				'post_type'      => 'sfwd-courses',
				'posts_per_page' => - 1,
				'post_status'    => 'publish',
				'orderby'        => 'title',
				'order'          => 'ASC',
			);

			$courses = get_posts( $args );

			foreach ( $courses as $course ) {

				$certificate_id     = learndash_get_setting( $course->ID, 'certificate' );
				$certificate_object = get_post( $certificate_id );

				if ( ! empty( $certificate_object ) ) {
					if ( 'on' === $show_cert_title ) {
						$certificate_title = $certificate_object->post_title;
					} else {
						$certificate_title = $course->post_title;
					}

					$certificate_link = learndash_get_course_certificate_link( $course->ID );

					if ( $certificate_link && '' !== $certificate_link ) {
						$link             = apply_filters( 'uo_show_course_certificate_link', sprintf( '<a target="_blank" href="%s">%s</a>', $certificate_link, $certificate_title ), wp_get_current_user(), $course );
						$certificate_list .= $link . '<br>';
					}
				}
			}
		}

		/* GET Certificates for Quizzes*/
		if( 'show' === $quiz_certificates ){
			$quiz_attempts = self::quiz_attempts();

			if ( ! empty( $quiz_attempts ) ) {

				$quiz_attempts = array_reverse( $quiz_attempts );

				foreach ( $quiz_attempts as $k => $quiz_attempt ) {

					if ( isset( $quiz_attempt['certificate'] ) ) {
						$certificate_link    = $quiz_attempt['certificate']['certificateLink'];
						$quiz_title_fallback = ( isset( $quiz_attempt['quiz_title'] ) ) ? $quiz_attempt['quiz_title'] : '';
						$quiz_title          = ! empty( $quiz_attempt['post']->post_title ) ? $quiz_attempt['post']->post_title : $quiz_title_fallback;

						if ( ! empty( $certificate_link ) ) {

							if( isset($quiz_attempt['time']) ){
								$certificate_link = add_query_arg( array( 'time' => $quiz_attempt['time'] ), $certificate_link );
							}

							$meta               = get_post_meta( $quiz_attempt['post']->ID, '_sfwd-quiz', true );
							$certificate_id     = $meta['sfwd-quiz_certificate'];
							$certificate_object = get_post( $certificate_id );
							if ( 'on' === $show_cert_title ) {
								$certificate_title = $certificate_object->post_title;
							} else {
								$certificate_title = $quiz_title;
							}
							$link             = apply_filters( 'uo_show_quiz_certificate_link', sprintf( '<a target="_blank" href="%s">%s</a>', esc_url( $certificate_link ), $certificate_title ), wp_get_current_user(), $quiz_attempt );
							$certificate_list .= $link . '<br>';
						}
					}
				}
			}
		}

		/* GET Certificates for Groups*/
		if( 'show' === $group_certificates ){

			$args = array(
				'post_type'      => 'groups',
				'posts_per_page' => 9999,
				'post_status'    => 'publish',
				'orderby'        => 'title',
				'order'          => 'ASC',
			);

			$groups = get_posts( $args );

			foreach ( $groups as $group ) {

				$certificate_id     = learndash_get_setting( $group->ID, 'certificate' );
				$certificate_object = get_post( $certificate_id );

				if ( ! empty( $certificate_object ) ) {
					if ( 'on' === $show_cert_title ) {
						$certificate_title = $certificate_object->post_title;
					} else {
						$certificate_title = $group->post_title;
					}

					$certificate_link = learndash_get_group_certificate_link( $group->ID );

					if ( $certificate_link && '' !== $certificate_link ) {
						$link             = apply_filters( 'uo_show_group_certificate_link', sprintf( '<a target="_blank" href="%s">%s</a>', $certificate_link, $certificate_title ), wp_get_current_user(), $group );
						$certificate_list .= $link . '<br>';
					}
				}
			}
		}

		$certificate_list = apply_filters_deprecated( 'certificate_list_shortcode', array( $certificate_list ), '3.6.2', 'uo_certificate_list_shortcode' );
		$certificate_list = apply_filters( 'uo_certificate_list_shortcode', $certificate_list, $courses, $quiz_attempts );

		if ( '' === $certificate_list ) {
			$certificate_list = $no_cert_message;
		}

		$shortcode_html = '';
		if( 'show' === $course_certificates ||  'show' === $quiz_certificates ||  'show' === $group_certificates ){
			ob_start();
			?>
			<div class="<?php echo esc_attr( $class ); ?>">
				<div class="cert-list-title"><?php echo $title; ?></div>
				<div class="certificate-list"><?php echo $certificate_list; ?></div>
			</div>

			<?php

			$shortcode_html = ob_get_clean();
		}

		return $shortcode_html;

	}

Code file location:

uncanny-learndash-toolkit/uncanny-learndash-toolkit/src/classes/show-certificates-shortcode.php

Uncanny Toolkit for LearnDash [uo-show] Shortcode

The Uncanny-Learndash-Toolkit shortcode, ‘uo-show’, is designed to manage content visibility based on user status. This shortcode checks if a user is logged in or not. If the ‘for’ attribute equals ‘loggedin’, the enclosed content will only display for logged-in users. Conversely, if set to ‘loggedout’, the content will only show for logged-out users. Thus, it helps customize user experience.

Shortcode: [uo-show]

Parameters

Here is a list of all possible uo-show shortcode parameters and attributes:

  • for='loggedin' – Display content only to logged-in users.
  • for='loggedout' – Display content only to logged-out users.

Examples and Usage

Basic example – The shortcode is used to display content only to logged-in users.

[uo-show for="loggedin"]Welcome, logged in user![/uo-show]

Advanced examples

The shortcode can be used to display different content to logged-in and logged-out users. Here, we have two instances of the shortcode. The first one displays a welcome message to logged-in users, while the second one displays a different message to logged-out users.

[uo-show for="loggedin"]Welcome, logged in user![/uo-show]
[uo-show for="loggedout"]Please log in to see more content.[/uo-show]

In another advanced scenario, the shortcode can be used to nest other shortcodes. This allows you to control the visibility of other shortcodes based on the user’s login status. In this example, a contact form shortcode is nested within the ‘uo-show’ shortcode, making the contact form only visible to logged-in users.

[uo-show for="loggedin"][contact-form-7 id="1234" title="Contact form 1"][/uo-show]

PHP Function Code

In case you have difficulties debugging what causing issues with [uo-show] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'uo-show', array( __CLASS__, 'uo_show' ) );

Shortcode PHP function:

function uo_show( $atts, $content = null ) {

		//check tha the user is logged in
		if ( 'loggedin' === $atts['for'] ) {
			if ( is_user_logged_in() ) {
				//user is logged in so show the content
				return do_shortcode( $content );
			} else {
				return '';
			}
		}

		if ( 'loggedout' === $atts['for'] ) {
			if ( ! is_user_logged_in() ) {
				return do_shortcode( $content );
			} else {
				return '';
			}
		}

		return do_shortcode( $content );
	}

Code file location:

uncanny-learndash-toolkit/uncanny-learndash-toolkit/src/classes/show-hide-content.php

Conclusion

Now that you’ve learned how to embed the Uncanny Toolkit for LearnDash Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *