Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request #299 from xwp/bugfix/previewed-fetched-settings
Browse files Browse the repository at this point in the history
Improve fetching of settings
  • Loading branch information
westonruter committed Sep 29, 2016
2 parents f082137 + 59696e3 commit 1d95e90
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions js/customize-posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
} );

Expand Down
21 changes: 14 additions & 7 deletions php/class-wp-customize-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down

0 comments on commit 1d95e90

Please sign in to comment.