LLMS_Beaver_Builder::is_node_visible( bool $visible, obj $node )

Determine if a node is visible based on llms enrollments status visibility settings.


Parameters Parameters

$visible

(bool) (Required) Default visibility.

$node

(obj) (Required) BB node object.


Top ↑

Return Return

(boolean)


Top ↑

Source Source

File: includes/class-llms-beaver-builder.php

	public function is_node_visible( $visible, $node ) {

		if ( isset( $node->settings ) && isset( $node->settings->visibility_display ) && false !== strpos( $node->settings->visibility_display, 'llms_' ) ) {

			$status = $node->settings->visibility_display;

			$uid  = get_current_user_id();
			$type = ! empty( $node->settings->llms_enrollment_type ) ? $node->settings->llms_enrollment_type : null;

			llms_log( $type );

			if ( ! $type || 'any' === $type ) {

				// No type means current course/membership.
				if ( ! $type ) {

					$current_id = get_the_ID();
					// Cascade up for lessons & quizzes.
					if ( in_array( get_post_type( $current_id ), array( 'lesson', 'llms_quiz' ), true ) ) {
						$course     = llms_get_post_parent_course( $current_id );
						$current_id = $course->get( 'id' );
					}

					// If the current id isn't a course or membership don't proceed.
					if ( ! in_array( get_post_type( $current_id ), array( 'course', 'llms_membership' ), true ) ) {
						return $visibility;
					}

					// Get the enrollment status.
					$enrollment_status = llms_is_user_enrolled( $uid, $current_id );
				} elseif ( 'any' === $type ) { // Check if they're enrolled/not enrolled in anything.
					$enrollment_status = $this->is_student_enrolled_in_one_thing( $uid );
				}

				if ( 'llms_enrolled' === $status ) {
					return $enrollment_status;
				} elseif ( 'llms_not_enrolled' === $status ) {
					return ( ! $enrollment_status );
				}
			} elseif ( 'specific' === $type ) { // Check if they're enrolled / not enrolled in the specific courses/memberships.

				$match = $node->settings->llms_enrollment_match ? $node->settings->llms_enrollment_match : 'any';
				$ids   = $this->get_related_posts_from_settings( $node->settings );

				if ( empty( $ids ) ) {
					return true;
				}

				if ( 'llms_enrolled' === $status ) {

					if ( ! $uid ) {
						return false;
					}

					return llms_is_user_enrolled( $uid, $ids, $match );

				} elseif ( 'llms_not_enrolled' === $status ) {

					if ( ! $uid ) {
						return true;
					}

					return ! llms_is_user_enrolled( $uid, $ids, $match );

				}
			}
		}

		return $visible;
	}


Top ↑

Changelog Changelog

Changelog
Version Description
1.7.0 Use in_array() strict comparisons.
1.5.3 Fixed visibility conditional logic for 'specific' enrollment type.
1.5.0 Unknown.
1.3.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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