WP_Customize_Nav_Menus::save_nav_menus_created_posts() WordPress Method
The WP_Customize_Nav_Menus::save_nav_menus_created_posts() method is used to save navigation menus created posts. This method is called when the user clicks the "Save" button on the navigation menu editor screen.
WP_Customize_Nav_Menus::save_nav_menus_created_posts( WP_Customize_Setting $setting ) #
Publishes the auto-draft posts that were created for nav menu items.
Description
The post IDs will have been sanitized by already by WP_Customize_Nav_Menu_Items::sanitize_nav_menus_created_posts()
to remove any post IDs for which the user cannot publish or for which the post is not an auto-draft.
Parameters
- $setting
(WP_Customize_Setting)(Required)Customizer setting object.
Source
File: wp-includes/class-wp-customize-nav-menus.php
public function save_nav_menus_created_posts( $setting ) { $post_ids = $setting->post_value(); if ( ! empty( $post_ids ) ) { foreach ( $post_ids as $post_id ) { // Prevent overriding the status that a user may have prematurely updated the post to. $current_status = get_post_status( $post_id ); if ( 'auto-draft' !== $current_status && 'draft' !== $current_status ) { continue; } $target_status = 'attachment' === get_post_type( $post_id ) ? 'inherit' : 'publish'; $args = array( 'ID' => $post_id, 'post_status' => $target_status, ); $post_name = get_post_meta( $post_id, '_customize_draft_post_name', true ); if ( $post_name ) { $args['post_name'] = $post_name; } // Note that wp_publish_post() cannot be used because unique slugs need to be assigned. wp_update_post( wp_slash( $args ) ); delete_post_meta( $post_id, '_customize_draft_post_name' ); } } }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
4.7.0 | Introduced. |