LLMS_Instructor::is_instructor( int $post_id = null )

Determine if the user is an instructor on a post


Parameters Parameters

$post_id

(int) (Optional) WP Post ID of a course or membership

Default value: null


Top ↑

Return Return

(boolean)


Top ↑

Source Source

File: includes/models/model.llms.instructor.php

	public function is_instructor( $post_id = null ) {

		$ret = false;

		// Use current post if no post is set.
		if ( ! $post_id ) {
			global $post;
			if ( ! $post ) {
				return apply_filters( 'llms_instructor_is_instructor', $ret, $post_id, $this );
			}
			$post_id = $post->ID;
		}

		$check_id = false;

		switch ( get_post_type( $post_id ) ) {

			case 'course':
				$check_id = $post_id;
				break;

			case 'llms_membership':
				$check_id = $post_id;
				break;

			case 'llms_question':
				$question = llms_get_post( $post_id );
				$check_id = array();
				foreach ( $question->get_quizzes() as $qid ) {
					$course = llms_get_post_parent_course( $qid );
					if ( $course ) {
						$check_id[] = $course->get( 'id' );
					}
				}
				break;

			default:
				$course = llms_get_post_parent_course( $post_id );
				if ( $course ) {
					$check_id = $course->get( 'id' );
				}
		}

		if ( $check_id ) {

			$check_ids = ! is_array( $check_id ) ? array( $check_id ) : $check_id;

			$query = $this->get_posts(
				array(
					'post__in'       => $check_ids,
					'posts_per_page' => 1,
				),
				'query'
			);

			$ret = $query->have_posts();

		}

		return apply_filters( 'llms_instructor_is_instructor', $ret, $post_id, $check_id, $this );

	}


Top ↑

Changelog Changelog

Changelog
Version Description
3.13.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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