diff --git a/js/customize-posts.js b/js/customize-posts.js index 119b272..09268f9 100644 --- a/js/customize-posts.js +++ b/js/customize-posts.js @@ -308,6 +308,7 @@ request = wp.ajax.post( 'customize-posts-fetch-settings', { 'customize-posts-nonce': api.settings.nonce['customize-posts'], 'wp_customize': 'on', + 'customized': api.previewer.query().customized, 'post_ids': newPostIds } ); diff --git a/php/class-wp-customize-posts.php b/php/class-wp-customize-posts.php index 8c18e7b..582bb1b 100644 --- a/php/class-wp-customize-posts.php +++ b/php/class-wp-customize-posts.php @@ -1322,25 +1322,32 @@ public function ajax_fetch_settings() { wp_send_json_error( 'bad_post_ids' ); } + $this->manager->add_dynamic_settings( array_keys( $this->manager->unsanitized_post_values() ) ); + $setting_params = array(); $settings = $this->get_settings( $post_ids ); foreach ( $settings as $setting ) { if ( $setting->check_capabilities() ) { + $setting->preview(); $setting_params[ $setting->id ] = $this->get_setting_params( $setting ); } } // Return with a failure if any of the requested posts. foreach ( $post_ids as $post_id ) { - $post = get_post( $post_id ); - if ( empty( $post ) ) { - status_header( 404 ); - wp_send_json_error( 'requested_post_absent' ); + if ( $post_id < 0 ) { + $post_type = 'nav_menu_item'; + } else { + $post_type = get_post_type( $post_id ); + if ( empty( $post_type ) ) { + status_header( 404 ); + wp_send_json_error( 'requested_post_absent' ); + } } - if ( 'nav_menu_item' === $post->post_type ) { - $setting_id = sprintf( 'nav_menu_item[%d]', $post->ID ); + if ( 'nav_menu_item' === $post_type ) { + $setting_id = sprintf( 'nav_menu_item[%d]', $post_id ); } else { - $setting_id = WP_Customize_Post_Setting::get_post_setting_id( $post ); + $setting_id = WP_Customize_Post_Setting::get_post_setting_id( get_post( $post_id ) ); } if ( ! isset( $setting_params[ $setting_id ] ) ) { status_header( 404 );