Tutor Shortcodes

Below, you’ll find a detailed guide on how to add the Tutor 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 Tutor Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the Tutor Plugin and the shortcodes it provides:

Plugin Icon
Tutor LMS – eLearning and online course solution

"Tutor LMS is a comprehensive eLearning and online course solution for WordPress. This powerful plugin transforms your site into an educational hub, making learning accessible and engaging."

★★★★✩ (502) Active Installs: 70000+ Tested with: 6.3.2 PHP Version: 7.1
Included Shortcodes:
  • [tutor_student_registration_form]
  • [tutor_dashboard]
  • [tutor_instructor_registration_form]
  • [tutor_course]
  • [tutor_instructor_list]

Tutor [tutor_student_registration_form] Shortcode

The Tutor Student Registration Form shortcode is an integral part of the Tutor plugin. It facilitates the student registration process. This shortcode checks if a user is logged in. If they are, it loads the logged-in dashboard. If not, it presents the registration form. This ensures a smooth user experience.

Shortcode: [tutor_student_registration_form]

Examples and Usage

Basic example – A simple usage of the shortcode to display the student registration form.

[tutor_student_registration_form /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'tutor_student_registration_form', array( $this, 'student_registration_form' ) );

Shortcode PHP function:

function student_registration_form() {
		ob_start();
		if ( is_user_logged_in() ) {
			tutor_load_template( 'dashboard.logged-in' );
		} else {
			tutor_load_template( 'dashboard.registration' );
		}
		return apply_filters( 'tutor/student/register', ob_get_clean() );
	}

Code file location:

tutor/tutor/classes/Shortcode.php

Tutor [tutor_dashboard] Shortcode

The ‘tutor_dashboard’ shortcode is a functional piece of code in the Tutor plugin. It checks if a user is logged in and displays the dashboard. If not, it shows a login form. The PHP function ‘tutor_dashboard’ is triggered by this shortcode. It uses global $wp_query and ob_start() to buffer the output. If the user is logged in, it loads the dashboard template. If not, it displays a login form with a sign-in button.

Shortcode: [tutor_dashboard]

Examples and Usage

Basic example – The given shortcode is used to display the Tutor LMS user dashboard. If a user is logged in, it will display the dashboard. If not, it will show a login form.

[tutor_dashboard /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'tutor_dashboard', array( $this, 'tutor_dashboard' ) );

Shortcode PHP function:

function tutor_dashboard() {
		global $wp_query;

		ob_start();
		if ( is_user_logged_in() ) {
			/**
			 * Added isset() Condition to avoid infinite loop since v.1.5.4
			 * This has cause error by others plugin, Such AS SEO
			 */

			if ( ! isset( $wp_query->query_vars['tutor_dashboard_page'] ) ) {
				tutor_load_template( 'dashboard', array( 'is_shortcode' => true ) );
			}
		} else {
			/**
			 * If user not logged in show login form instead of
			 * popup sign-in button
			 *
			 * @since 2.1.3
			 */
			$login_url = tutor_utils()->get_option( 'enable_tutor_native_login', null, true, true ) ? '' : wp_login_url( tutor()->current_url );
			echo sprintf( __( 'Please %1$sSign-In%2$s to view this page', 'tutor' ), '<a data-login_url="' . esc_url( $login_url ) . '" href="#" class="tutor-open-login-modal">', '</a>' );//phpcs:ignore
		}
		return apply_filters( 'tutor_dashboard/index', ob_get_clean() );
	}

Code file location:

tutor/tutor/classes/Shortcode.php

Tutor [tutor_instructor_registration_form] Shortcode

The ‘Tutor Instructor Registration Form’ shortcode is used to display a registration form for instructors. It checks if a user is logged in and accordingly loads the appropriate template.

Shortcode: [tutor_instructor_registration_form]

Examples and Usage

Basic example – A shortcode that enables the instructor registration form on the page.

[tutor_instructor_registration_form /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'tutor_instructor_registration_form', array( $this, 'instructor_registration_form' ) );

Shortcode PHP function:

function instructor_registration_form() {
		ob_start();
		if ( is_user_logged_in() ) {
			tutor_load_template( 'dashboard.instructor.logged-in' );
		} else {
			tutor_load_template( 'dashboard.instructor.registration' );
		}
		return apply_filters( 'tutor_dashboard/student/index', ob_get_clean() );
	}

Code file location:

tutor/tutor/classes/Shortcode.php

Tutor [tutor_course] Shortcode

The Tutor Course shortcode allows you to display a list of courses on your WordPress site. It fetches courses based on parameters like ID, category, order, and count.

Shortcode: [tutor_course]

Parameters

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

  • post_type – Determines the type of post to display, default is course type.
  • post_status – Only shows posts that are published.
  • id – Allows to display specific course(s) by their ID(s).
  • exclude_ids – Skips specific course(s) by their ID(s).
  • category – Filters courses by specific category IDs or names.
  • orderby – Determines the sorting order of the courses, default is by ID.
  • order – Sets the direction of the sorting, default is descending.
  • count – Sets the number of courses displayed per page.
  • paged – Determines the page number for pagination.
  • course_filter – Enables the course filter option.
  • column_per_row – Sets the number of course columns per row.
  • show_pagination – Displays pagination if set to ‘on’.

Examples and Usage

Basic example – Displaying a course using its ID

[tutor_course id=1 /]

Using the shortcode to display a course by referencing its ID. The course will load by ID.

Advanced examples

Displaying a course excluding certain IDs

[tutor_course id=1 exclude_ids="2,3" /]

Using the shortcode to display a course by referencing its ID and excluding certain course IDs. The course will load by ID, and the courses with IDs 2 and 3 will not be displayed.

Displaying a course in a specific category by category ID

[tutor_course id=1 category="5" /]

Using the shortcode to display a course by referencing its ID and specifying a category ID. The course will load by ID, and only if it belongs to the category with ID 5.

Displaying a course in a specific category by category name

[tutor_course id=1 category="Mathematics" /]

Using the shortcode to display a course by referencing its ID and specifying a category name. The course will load by ID, and only if it belongs to the category named “Mathematics”.

PHP Function Code

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

Shortcode line:

add_shortcode( 'tutor_course', array( $this, 'tutor_course' ) );

Shortcode PHP function:

function tutor_course( $atts ) {
		$a = shortcode_atts(
			array(
				'post_type'   => apply_filters( 'tutor_course_archive_post_types', array( tutor()->course_post_type ) ),
				'post_status' => 'publish',

				'id'          => '',
				'exclude_ids' => '',
				'category'    => '',

				'orderby'     => 'ID',
				'order'       => 'DESC',
				'count'       => tutils()->get_option( 'courses_per_page', 12 ),
				'paged'       => get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1,
			),
			$atts
		);

		if ( ! empty( $a['id'] ) ) {
			$ids           = (array) explode( ',', $a['id'] );
			$a['post__in'] = $ids;
		}

		if ( ! empty( $a['exclude_ids'] ) ) {
			$exclude_ids       = (array) explode( ',', $a['exclude_ids'] );
			$a['post__not_in'] = $exclude_ids;
		}
		if ( ! empty( $a['category'] ) ) {
			$category = (array) explode( ',', $a['category'] );

			$a['tax_query'] = array();

			$category_ids = array_filter(
				$category,
				function( $id ) {
					return is_numeric( $id );
				}
			);

			$category_names = array_filter(
				$category,
				function( $id ) {
					return ! is_numeric( $id );
				}
			);

			if ( ! empty( $category_ids ) ) {
				$a['tax_query'] = array(
					array(
						'taxonomy' => 'course-category',
						'field'    => 'term_id',
						'terms'    => $category_ids,
						'operator' => 'IN',
					),
				);
			}

			if ( ! empty( $category_names ) ) {
				$a['tax_query'] = array(
					array(
						'taxonomy' => 'course-category',
						'field'    => 'name',
						'terms'    => $category_names,
						'operator' => 'IN',
					),
				);
			}
		}
		$a['posts_per_page'] = (int) $a['count'];

		wp_reset_query();
		$the_query = new \WP_Query( $a );

		/**
		 * Pagination & course filter handle from query param on page load (without ajax)
		 *
		 * @since 2.4.0
		 */
		$get = Input::has( 'course_filter' ) ? Input::sanitize_array( $_GET ) : array();
		if ( Input::has( 'course_filter' ) ) {
			$filter    = ( new \Tutor\Course_Filter( false ) )->load_listing( $get, true );
			$the_query = new \WP_Query( $filter );
		}

		// Load the renderer now.
		ob_start();

		if ( $the_query->have_posts() ) {
			tutor_load_template(
				'archive-course-init',
				array(
					'course_filter'     => isset( $atts['course_filter'] ) && 'on' === $atts['course_filter'],
					'supported_filters' => tutor_utils()->get_option( 'supported_course_filters', array() ),
					'loop_content_only' => false,
					'column_per_row'    => isset( $atts['column_per_row'] ) ? $atts['column_per_row'] : null,
					'course_per_page'   => $a['posts_per_page'],
					'show_pagination'   => isset( $atts['show_pagination'] ) && 'on' === $atts['show_pagination'],
					'the_query'         => $the_query,
					'current_page'      => isset( $get['current_page'] ) ? (int) $get['current_page'] : 1,
				)
			);
		} else {
			tutor_utils()->tutor_empty_state( tutor_utils()->not_found_text() );
		}

		$output = ob_get_clean();
		wp_reset_postdata();
		return $output;
	}

Code file location:

tutor/tutor/classes/Shortcode.php

Tutor [tutor_instructor_list] Shortcode

The Tutor Instructor List shortcode is designed to generate a list of instructors. It also provides an option to filter the list based on specific criteria. The shortcode fetches instructor data from the database and prepares it for display. If the ‘filter’ attribute is enabled, it further fetches course categories, allowing users to filter instructors by course category. The output is then returned as content.

Shortcode: [tutor_instructor_list]

Parameters

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

  • filter – enables or disables the instructor list filter
  • instructor-page – sets the current page of the instructor list

Examples and Usage

Basic example – A basic usage of the shortcode to display a list of instructors without any filtering.

[tutor_instructor_list /]

Advanced examples

Using the shortcode to display a list of instructors with a filter. The filter can be turned on or off by setting the ‘filter’ attribute to ‘on’ or ‘off’ respectively.

[tutor_instructor_list filter="on" /]

Using the shortcode to display a filtered list of instructors on a specific page. The ‘instructor-page’ attribute can be used to specify the page number.

[tutor_instructor_list filter="on" instructor-page="2" /]

Using the shortcode to display a list of instructors without any filter on a specific page. The ‘instructor-page’ attribute can be used to specify the page number.

[tutor_instructor_list filter="off" instructor-page="3" /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'tutor_instructor_list', array( $this, 'tutor_instructor_list' ) );

Shortcode PHP function:

function tutor_instructor_list( $atts ) {
		global $wpdb;
		! is_array( $atts ) ? $atts = array() : 0;

		$current_page = (int) tutor_utils()->array_get( 'instructor-page', $_GET, 1 );
		$current_page = Input::get( 'instructor-page', 1, Input::TYPE_INT );
		$current_page = $current_page >= 1 ? $current_page : 1;

		$show_filter         = isset( $atts['filter'] ) ? 'on' === $atts['filter'] : tutor_utils()->get_option( 'instructor_list_show_filter', false );
		$atts['show_filter'] = $show_filter;

		// Get instructor list to sow.
		$payload                = $this->prepare_instructor_list( $current_page, $atts );
		$payload['show_filter'] = $show_filter;

		ob_start();
		tutor_load_template( 'shortcode.tutor-instructor', $payload );
		$content = ob_get_clean();

		if ( $show_filter ) {
			$limit           = 8;
			$course_taxonomy = 'course-category';
			$course_cats     = $wpdb->get_results(
				$wpdb->prepare(
					"SELECT
						* 
					FROM {$wpdb->terms} AS term
					
					INNER JOIN {$wpdb->term_taxonomy} AS taxonomy
						ON taxonomy.term_id = term.term_id AND taxonomy.taxonomy = %s

					ORDER BY term.term_id DESC
					LIMIT %d
					",
					$course_taxonomy,
					$limit
				)
			);

			$all_cats = $wpdb->get_var(
				$wpdb->prepare(
					"SELECT
						COUNT(*) as total 
					FROM {$wpdb->terms} AS term
						INNER JOIN {$wpdb->term_taxonomy} AS taxonomy
							ON taxonomy.term_id = term.term_id AND taxonomy.taxonomy = %s
					ORDER BY term.term_id DESC
					",
					$course_taxonomy
				)
			);

			$attributes = $payload;
			unset( $attributes['instructors'] );

			$payload = array(
				'show_filter' => $show_filter,
				'content'     => $content,
				'categories'  => $course_cats,
				'all_cats'    => $all_cats,
				'attributes'  => array_merge( $atts, $attributes ),
			);

			ob_start();

			tutor_load_template( 'shortcode.instructor-filter', $payload );

			$content = ob_get_clean();
		}

		return $content;
	}

Code file location:

tutor/tutor/classes/Shortcode.php

Conclusion

Now that you’ve learned how to embed the Tutor 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 *