LLMS_Template_Loader::template_loader( string $template )

Check if content should be restricted and include overrides where appropriate


Description Description

Triggers actions based on content restrictions.


Top ↑

Parameters Parameters

$template

(string) (Required) The template to load.


Top ↑

Return Return

(string)


Top ↑

Source Source

File: includes/class.llms.template.loader.php

	 */
	public function template_loader( $template ) {

		$page_restricted = llms_page_restricted( get_the_ID() );
		$this->maybe_print_notices_on_sales_page_redirect();

		if ( $page_restricted['is_restricted'] ) {

			/**
			 * Generic action triggered when content is restricted.
			 *
			 * @since Unknown
			 *
			 * @see llms_content_restricted_by_{$page_restricted['reason']} A specific hook triggered by a specific restriction reason.
			 *
			 * @param array $page_restricted Restriction information from `llms_page_restricted()`.
			 */
			do_action( 'lifterlms_content_restricted', $page_restricted );

			/**
			 * Action triggered when content is restricted for the specified reason.
			 *
			 * The dynamic portion of this hook, `{$page_restricted['reason']}` refers to the restriction reason
			 * code generated by `llms_page_restricted()`.
			 *
			 * @since Unknown
			 *
			 * @see llms_content_restricted A generic hook triggered at the same time.
			 *
			 * @param array $page_restricted Restriction information from `llms_page_restricted()`.
			 */
			do_action( "llms_content_restricted_by_{$page_restricted['reason']}", $page_restricted );

			// Blog should bypass checks, except when sitewide restrictions are enabled.
			if ( is_home() && 'sitewide_membership' === $page_restricted['reason'] ) {

				// Prints notices on the blog page when there's not redirects setup.
				add_action( 'loop_start', 'llms_print_notices', 5 );

				return $template;

			}

			// Course and membership content restrictions are handled by conditional elements in the editor.
			if ( in_array( get_post_type(), array( 'course', 'llms_membership' ), true ) ) {
				return $template;
			}

			// Content is restricted.
			$template = 'single-no-access.php';

		} elseif ( is_post_type_archive( 'course' ) || is_page( llms_get_page_id( 'courses' ) ) ) {

			$template = 'archive-course.php';

		} elseif ( is_post_type_archive( 'llms_membership' ) || is_page( llms_get_page_id( 'memberships' ) ) ) {

			$template = 'archive-llms_membership.php';

		} elseif ( is_tax( array( 'course_cat', 'course_tag', 'course_difficulty', 'course_track', 'membership_tag', 'membership_cat' ) ) ) {

			global $wp_query;
			$obj      = $wp_query->get_queried_object();
			$template = 'taxonomy-' . $obj->taxonomy . '.php';

		} elseif ( is_singular( array( 'llms_certificate', 'llms_my_certificate' ) ) ) {

			$template = 'single-certificate.php';

		} else {

			return $template;

		}

		// We have reason to use a LifterLMS template, check if there's an override we should use from a theme / etc...
		$override      = llms_get_template_override( $template );
		$template_path = $override ? $override : LLMS()->plugin_path() . '/templates/';
		return $template_path . $template;



Top ↑

Changelog Changelog

Changelog
Version Description
4.10.1 Refactor to reduce code duplication and replace usage of llms_shop with courses for catalog check.
3.37.2 Make sure to print notices on sales page redirect.
3.16.11 Unknown.
1.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.