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
Return Return
(boolean)
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; }
Expand full source code Collapse full source code View on GitHub