llms_is_focus_mode_enabled( int $post_id )

Determine if Focus Mode is enabled for a specific post (lesson, quiz, or other post types via filter).


Description Description

For lessons and quizzes, uses the parent course focus mode setting (or global setting).
Add-ons (e.g. LifterLMS Assignments) can use the filter to enable focus mode for their post types.


Top ↑

Parameters Parameters

$post_id

(int) (Required) The ID of the post (lesson, quiz, etc.).


Top ↑

Return Return

(bool)


Top ↑

Source Source

File: includes/functions/llms.functions.template.php

function llms_is_focus_mode_enabled( $post_id ) {
	$post = llms_get_post( $post_id );
	if ( ! $post ) {
		return false;
	}

	$result = false;
	$type   = $post->get( 'type' );

	if ( 'lesson' === $type || 'llms_quiz' === $type ) {
		$course = llms_get_post_parent_course( $post_id );
		if ( ! $course ) {
			return apply_filters( 'llms_is_focus_mode_enabled', false, $post_id );
		}

		$course_focus_mode = $course->get( 'focus_mode' );
		if ( 'enable' === $course_focus_mode ) {
			$result = true;
		} elseif ( 'disable' === $course_focus_mode ) {
			$result = false;
		} else {
			$result = 'yes' === get_option( 'lifterlms_enable_focus_mode', 'no' );
		}

		if ( $result && ! current_user_can( 'manage_lifterlms' ) ) {
			$student = llms_get_student();
			if ( ! $student || ! $student->is_enrolled( $course->get( 'id' ) ) ) {
				$result = false;
			}
		}
	}

	/**
	 * Filters whether focus mode is enabled for a given post.
	 *
	 * Used by add-ons (e.g. LifterLMS Assignments) to enable focus mode for their post types
	 * when focus mode is enabled globally and/or for the course.
	 *
	 * @since 10.0.0
	 *
	 * @param bool $result  Whether focus mode is enabled.
	 * @param int  $post_id The post ID.
	 */
	return apply_filters( 'llms_is_focus_mode_enabled', $result, $post_id );
}


Top ↑

Changelog Changelog

Changelog
Version Description
10.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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