llms_get_post( WP_Post|int $post, mixed $error = false )

Retrieve the LLMS Post Model for a give post by ID or WP_Post Object


Parameters Parameters

$post

(WP_Post|int) (Required) Instance of WP_Post or a WP Post ID.

$error

(mixed) (Optional) Determine what to return if the LLMS class isn't found. post = WP_Post falsy = false.

Default value: false


Top ↑

Return Return

(LLMS_Post_Model|WP_Post|null|false) LLMS_Post_Model extended object, null if WP get_post() fails, WP_Post if LLMS_Post_Model extended class isn't found and $error = 'post' false if LLMS_Post_Model extended class isn't found and $error != 'post'.


Top ↑

Source Source

File: includes/llms.functions.core.php

 */
function llms_get_post( $post, $error = false ) {

	$post = get_post( $post );
	if ( ! $post ) {
		return $post;
	}

	$class = '';

	// Check whether it's an llms post candidate: `post_type` starts with the 'llms_' prefix, or is one of the unprefixed ones.
	if ( 0 === strpos( $post->post_type, 'llms_' ) || in_array( $post->post_type, llms_get_unprefixed_post_types(), true ) ) {
		$post_type = explode( '_', str_replace( 'llms_', '', $post->post_type ) );
		$class     = 'LLMS';
		foreach ( $post_type as $part ) {
			$class .= '_' . ucfirst( $part );
		}
	}

	if ( $class && class_exists( $class ) ) {
		return new $class( $post );
	} elseif ( 'post' === $error ) {
		return $post;
	}

	return false;



Top ↑

Changelog Changelog

Changelog
Version Description
4.10.1 Made sure to only instantiate LifterLMS classes.
3.3.0
3.16.11 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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