LLMS_Engagement_Handler::check_post( int $post_id, string $post_type = null )

Validates a post id submitted to an engagement handler callback function.


Description Description

This ensures the following is true:

  • The post must exist
  • It must be published
  • Optionally, it must match the specified post type.

Top ↑

Parameters Parameters

$post_id

(int) (Required) WP_Post ID.

$post_type

(string) (Optional) The expected post type.

Default value: null


Top ↑

Return Return

(WP_Error|boolean) Returns true if all checks pass, otherwise returns a WP_Error.


Top ↑

Source Source

File: includes/class-llms-engagement-handler.php

	public static function check_post( $post_id, $post_type = null ) {

		$post = get_post( $post_id );
		if ( ! $post ) {
			// Translators: %d = the WP_Post ID.
			return new WP_Error( 'llms-engagement-post--not-found', sprintf( __( 'Post "%d" not found.', 'lifterlms' ), $post_id ), compact( 'post_id' ) );
		}

		if ( 'publish' !== $post->post_status ) {
			// Translators: %d = the WP_Post ID.
			return new WP_Error( 'llms-engagement-post--status', sprintf( __( 'Post "%d" is not published.', 'lifterlms' ), $post_id ), compact( 'post' ) );
		}

		if ( $post_type && $post_type !== $post->post_type ) {
			// Translators: %d = the WP_Post ID.
			return new WP_Error( 'llms-engagement-post--type', sprintf( __( 'Post "%d" is not the expected post type.', 'lifterlms' ), $post_id ), compact( 'post' ) );
		}

		return true;

	}


Top ↑

Changelog Changelog

Changelog
Version Description
6.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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