Customize: Prevent `_delete_option_fresh_site()` from hitting DB if `fresh_site` flag already cleared.

Amends [38991].
Props dlh, westonruter.
Fixes #41039.


git-svn-id: https://develop.svn.wordpress.org/trunk@41244 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Weston Ruter 2017-08-13 00:56:24 +00:00
parent 7bff33a6eb
commit b4a8af7e35
2 changed files with 27 additions and 3 deletions

View File

@ -3303,7 +3303,7 @@ function _config_wp_siteurl( $url = '' ) {
* @access private * @access private
*/ */
function _delete_option_fresh_site() { function _delete_option_fresh_site() {
update_option( 'fresh_site', 0 ); update_option( 'fresh_site', '0' );
} }
/** /**

View File

@ -170,17 +170,41 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase {
$this->assertInstanceOf( 'WPDieException', $exception ); $this->assertInstanceOf( 'WPDieException', $exception );
$this->assertContains( 'Invalid changeset UUID', $exception->getMessage() ); $this->assertContains( 'Invalid changeset UUID', $exception->getMessage() );
update_option( 'fresh_site', 0 ); update_option( 'fresh_site', '0' );
$wp_customize = new WP_Customize_Manager(); $wp_customize = new WP_Customize_Manager();
$wp_customize->setup_theme(); $wp_customize->setup_theme();
$this->assertFalse( has_action( 'after_setup_theme', array( $wp_customize, 'import_theme_starter_content' ) ) ); $this->assertFalse( has_action( 'after_setup_theme', array( $wp_customize, 'import_theme_starter_content' ) ) );
// Make sure that starter content import gets queued on a fresh site. // Make sure that starter content import gets queued on a fresh site.
update_option( 'fresh_site', 1 ); update_option( 'fresh_site', '1' );
$wp_customize->setup_theme(); $wp_customize->setup_theme();
$this->assertEquals( 100, has_action( 'after_setup_theme', array( $wp_customize, 'import_theme_starter_content' ) ) ); $this->assertEquals( 100, has_action( 'after_setup_theme', array( $wp_customize, 'import_theme_starter_content' ) ) );
} }
/**
* Test that clearing a fresh site is a no-op if the site is already fresh.
*
* @see _delete_option_fresh_site()
* @ticket 41039
*/
function test_fresh_site_flag_clearing() {
global $wp_customize, $wpdb;
// Make sure fresh site flag is cleared when publishing a changeset.
update_option( 'fresh_site', '1' );
do_action( 'customize_save_after', $wp_customize );
$this->assertEquals( '0', get_option( 'fresh_site' ) );
// Simulate a new, uncached request.
wp_cache_delete( 'alloptions', 'options' );
wp_load_alloptions();
// Make sure no DB write is done when publishing and a site is already non-fresh.
$query_count = $wpdb->num_queries;
do_action( 'customize_save_after', $wp_customize );
$this->assertSame( $query_count, $wpdb->num_queries );
}
/** /**
* Test WP_Customize_Manager::setup_theme() for frontend. * Test WP_Customize_Manager::setup_theme() for frontend.
* *