WP_Customize_Nav_Menus::sanitize_nav_menus_created_posts() WordPress Method

The WP_Customize_Nav_Menus::sanitize_nav_menus_created_posts() method is used to sanitize nav menu items that have been created from posts. This is done by setting the correct post_status for each menu item, based on the current status of the post.

WP_Customize_Nav_Menus::sanitize_nav_menus_created_posts( array $value ) #

Sanitizes post IDs for posts created for nav menu items to be published.


Parameters

$value

(array)(Required)Post IDs.


Top ↑

Return

(array) Post IDs.


Top ↑

Source

File: wp-includes/class-wp-customize-nav-menus.php

	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;
	}


Top ↑

Changelog

Changelog
VersionDescription
4.7.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.