From ca12fb6710e5b10e9c625da2f37589b828f84b2c Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Thu, 9 Nov 2017 04:45:38 +0000 Subject: [PATCH] Customize: Fix reliability of just-in-time publishing for changesets that miss their schedule when visiting `customize.php`. When just doing `wp_publish_post()` for the changeset from `customize.php`, any option-based settings will fail to get saved because `WP_Customize_Manager` would have already been loaded with `settings_previewed`, resulting in `update_option()` calls being short-circuited. So an admin-ajax request to `customize_save` is used to work around this. Props westonruter, jeremyfelt, dlh for testing, LittleBigThing for testing. Amends [41626]. See #28721, #39221. Fixes #42457 for 4.9. Built from https://develop.svn.wordpress.org/branches/4.9@42139 git-svn-id: http://core.svn.wordpress.org/branches/4.9@41970 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/customize.php | 28 ++++++++++++++++++++++++++-- wp-includes/version.php | 2 +- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/wp-admin/customize.php b/wp-admin/customize.php index 7f9e5a9dc7..91c67d0016 100644 --- a/wp-admin/customize.php +++ b/wp-admin/customize.php @@ -42,10 +42,34 @@ if ( $wp_customize->changeset_post_id() ) { get_post_time( 'G', true, $changeset_post ) < time() ); if ( $missed_schedule ) { - wp_publish_post( $changeset_post->ID ); + /* + * Note that an Ajax request spawns here instead of just calling `wp_publish_post( $changeset_post->ID )`. + * + * Because WP_Customize_Manager is not instantiated for customize.php with the `settings_previewed=false` + * argument, settings cannot be reliably saved. Some logic short-circuits if the current value is the + * same as the value being saved. This is particularly true for options via `update_option()`. + * + * By opening an Ajax request, this is avoided and the changeset is published. See #39221. + */ + $nonces = $wp_customize->get_nonces(); + $request_args = array( + 'nonce' => $nonces['save'], + 'customize_changeset_uuid' => $wp_customize->changeset_uuid(), + 'wp_customize' => 'on', + 'customize_changeset_status' => 'publish', + ); + ob_start(); + ?> + + + ' . __( 'Your scheduled changes just published' ) . '' . - '

' . __( 'Customize New Changes' ) . '

', + '

' . __( 'Customize New Changes' ) . '

' . $script, 200 ); } diff --git a/wp-includes/version.php b/wp-includes/version.php index 8224747fb3..9897038c7c 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.9-RC2-42137'; +$wp_version = '4.9-RC2-42139'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.