LLMS_Student::get_enrollment_status( int $product_id, bool $use_cache = true )

Get the current enrollment status of a student for a particular product


Description Description


Parameters Parameters

$product_id

(int) (Required) WP Post ID of a Course, Lesson, or Membership

$use_cache

(bool) (Optional) If true, returns cached data if available, if false will run a db query

Default value: true


Top ↑

Return Return

(false|string)


Top ↑

Source Source

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

	public function get_enrollment_status( $product_id, $use_cache = true ) {

		$status = false;

		$product_type = get_post_type( $product_id );

		// only check the following post types
		if ( ! in_array( $product_type, array( 'course', 'lesson', 'llms_membership' ) ) ) {
			return apply_filters( 'llms_get_enrollment_status', $status, $this->get_id(), $product_id );
		}

		// get course ID if we're looking at a lesson
		if ( 'lesson' === $product_type ) {

			$lesson = new LLMS_Lesson( $product_id );
			$product_id = $lesson->get_parent_course();

		}

		if ( $use_cache ) {
			$status = $this->cache_get( sprintf( 'enrollment_status_%d', $product_id ) );
		}

		// status will be:
		//    + false if there was nothing in the cache -- run a query!
		//    + a string if there was a status          -- don't run query
		//    + null if there's no status               -- don't run query
		if ( false === $status ) {

			global $wpdb;

			// get the most recent recorded status
			$status = $wpdb->get_var( $wpdb->prepare(
				"SELECT meta_value FROM {$wpdb->prefix}lifterlms_user_postmeta WHERE meta_key = '_status' AND user_id = %d AND post_id = %d ORDER BY updated_date DESC LIMIT 1",
				array( $this->get_id(), $product_id )
			) );

			// null will be stored if the student has no status
			$this->cache_set( sprintf( 'enrollment_status_%d', $product_id ), $status );

		}

		$status = ( $status ) ? $status : false;

		return apply_filters( 'llms_get_enrollment_status', $status, $this->get_id(), $product_id );

	}

Top ↑

Changelog Changelog

Changelog
Version Description
3.0.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

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





Permalink: