CourseCurriculum


Source

File: classes/CourseCurriculum.php

class CourseCurriculum {

	public static function instance() {
		static $instance = null;

		// Only run these methods if they haven't been run previously
		if ( null === $instance ) {
			$instance = new self();
		}

		// Always return the instance
		return $instance;
	}

	public function __construct() {

		add_filter( 'dozent_is_curriculum_locked', [ $this, 'is_curriculum_locked' ], 10, 3 );

	}

	public function is_curriculum_locked( $content, $curriculum, $course_id ) {
		if ( ! empty( $content ) ) {
			return $content;
		}

		$course = dozent_get_course( $course_id );

		if ( $course->is_public() && ( $curriculum->post_type === 'dozent_lecture' ) ) {
			return $content;
		}

		$locked_message = '';

		if ( ! is_user_logged_in() ) {
			$locked_message = __( 'You must log in before access the course', 'dozent' );

			return dozent_curriculum_locked_content( $curriculum, $locked_message, false );
		}

		/**
		 * User is now logged in
		 */

		if ( ! $course->has_permission() ) {

			$locked_message = sprintf( __( 'You have no permission to view this contents. Go to %s to gain access.', 'dozent' ), '<a href=" ' . $course->permalink() . ' "> course page </a>' );

			return dozent_curriculum_locked_content( $curriculum, $locked_message, false );
		}

		return $content;
	}

}

Methods