On this page
WP_Customize_Nav_Menus::sanitize_nav_menus_created_posts( array $value ): array
Sanitizes post IDs for posts created for nav menu items to be published.
Parameters
$valuearray Required-
Post IDs.
Return
array Post IDs.
Source
File: wp-includes/class-wp-customize-nav-menus.php. View all references
public function sanitize_nav_menus_created_posts( $value ) {
$post_ids = array();
foreach ( wp_parse_id_list( $value ) as $post_id ) {
if ( empty( $post_id ) ) {
continue;
}
$post = get_post( $post_id );
if ( 'auto-draft' !== $post->post_status && 'draft' !== $post->post_status ) {
continue;
}
$post_type_obj = get_post_type_object( $post->post_type );
if ( ! $post_type_obj ) {
continue;
}
if ( ! current_user_can( $post_type_obj->cap->publish_posts ) || ! current_user_can( 'edit_post', $post_id ) ) {
continue;
}
$post_ids[] = $post->ID;
}
return $post_ids;
}
Related
Uses
| Uses | Description |
|---|---|
| wp_parse_id_list() wp-includes/functions.php | Cleans up an array, comma- or space-separated list of IDs. |
| current_user_can() wp-includes/capabilities.php | Returns whether the current user has the specified capability. |
| get_post() wp-includes/post.php | Retrieves post data given a post ID or post object. |
| get_post_type_object() wp-includes/post.php | Retrieves a post type object by name. |
Changelog
| Version | Description |
|---|---|
| 4.7.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_customize_nav_menus/sanitize_nav_menus_created_posts