llms_rest_validate_post_types( int|int[] $ids, string|string[] $post_types, boolean $allow_empty = false )

Validate submitted array of integers is an array of real post types id, or empty.


Parameters Parameters

$ids

(int|int[]) (Required) A single or a list of post IDs.

$post_types

(string|string[]) (Required) A single or a list of post types to check against.

$allow_empty

(boolean) (Optional) Whether or not allowing empty lists.

Default value: false


Top ↑

Return Return

(boolean)


Top ↑

Source Source

File: libraries/lifterlms-rest/includes/server/llms-rest-server-functions.php

function llms_rest_validate_post_types( $ids, $post_types, $allow_empty = false ) {

	$ids = is_array( $ids ) ? $ids : array( $ids );
	$ids = array_filter( $ids );

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

	$valid      = true;
	$post_types = is_array( $post_types ) ? $post_types : array( $post_types );

	if ( ! empty( $ids ) ) {
		$real_post_types = array_filter(
			$ids,
			function( $id ) use ( $post_types ) {
				return ( is_numeric( $id ) && in_array( get_post_type( (int) $id ), $post_types, true ) );
			}
		);

		$valid = count( $real_post_types ) === count( $ids );
	}

	return $valid;

}


Top ↑

User Contributed Notes User Contributed Notes

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