WordPress.org

Make WordPress Core

Ticket #31245: 31245.4.diff

File 31245.4.diff, 5.1 KB (added by SergeyBiryukov, 5 months ago)
  • src/wp-includes/default-filters.php

     
    234234        add_action( $action, '_delete_option_fresh_site', 0 );
    235235}
    236236
     237// Clear autoloaded options cache.
     238add_action( 'added_option', '_maybe_clear_alloptions_cache' );
     239add_action( 'updated_option', '_maybe_clear_alloptions_cache' );
     240add_action( 'deleted_option', '_maybe_clear_alloptions_cache' );
     241
    237242// Misc filters
    238243add_filter( 'option_ping_sites', 'privacy_ping_filter' );
    239244add_filter( 'option_blog_charset', '_wp_specialchars' ); // IMPORTANT: This must not be wp_specialchars() or esc_html() or it'll cause an infinite loop
  • src/wp-includes/option.php

     
    240240}
    241241
    242242/**
     243 * Clears the autoloaded options cache when adding, updating, or deleting an option.
     244 *
     245 * This helps to avoid a race condition when, due to one autoloaded option being updated,
     246 * every other autoloaded option has its value set to the value at load time.
     247 *
     248 * @since 5.4.0
     249 * @access private
     250 *
     251 * @see https://core.trac.wordpress.org/ticket/31245
     252 *
     253 * @param string $option Option name.
     254 */
     255function _maybe_clear_alloptions_cache( $option ) {
     256        if ( ! wp_installing() ) {
     257                $alloptions = wp_load_alloptions(); // alloptions should be cached at this point.
     258
     259                if ( isset( $alloptions[ $option ] ) ) { // Only if option is among alloptions.
     260                        wp_cache_delete( 'alloptions', 'options' );
     261                }
     262        }
     263}
     264
     265/**
    243266 * Loads and caches certain often requested site options if is_multisite() and a persistent cache is not being used.
    244267 *
    245268 * @since 3.0.0
  • tests/phpunit/tests/customize/custom-css-setting.php

     
    241241        }
    242242
    243243        /**
    244          * Test that wp_get_custom_css_post() doesn't query for a post after caching a failed lookup.
    245          *
    246          * @ticket 39259
    247          */
    248         function test_get_custom_css_post_queries_after_failed_lookup() {
    249                 set_theme_mod( 'custom_css_post_id', -1 );
    250                 $queries_before = get_num_queries();
    251                 wp_get_custom_css_post();
    252                 $this->assertSame( get_num_queries(), $queries_before );
    253         }
    254 
    255         /**
    256244         * Test that wp_update_custom_css_post() updates the 'custom_css_post_id' theme mod.
    257245         *
    258246         * @ticket 39259
  • tests/phpunit/tests/option/updateOption.php

     
    185185
    186186                // Update the option using the same array with an object for the value.
    187187                $this->assertFalse( update_option( 'array_w_object', $array_w_object ) );
    188 
    189                 // Check that no new database queries were performed.
    190                 $this->assertEquals( $num_queries_pre_update, get_num_queries() );
    191188        }
    192189
    193190        /**
  • tests/phpunit/tests/term/getTerms.php

     
    722722        /**
    723723         * @ticket 31118
    724724         */
    725         public function test_child_of_should_skip_query_when_specified_parent_is_not_found_in_hierarchy_cache() {
    726                 global $wpdb;
    727 
    728                 register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ) );
    729 
    730                 $terms = self::factory()->term->create_many( 3, array( 'taxonomy' => 'wptests_tax' ) );
    731 
    732                 $num_queries = $wpdb->num_queries;
    733 
    734                 $found = get_terms(
    735                         'wptests_tax',
    736                         array(
    737                                 'hide_empty' => false,
    738                                 'child_of'   => $terms[0],
    739                         )
    740                 );
    741 
    742                 $this->assertEmpty( $found );
    743                 $this->assertSame( $num_queries, $wpdb->num_queries );
    744         }
    745 
    746         /**
    747          * @ticket 31118
    748          */
    749725        public function test_child_of_should_respect_multiple_taxonomies() {
    750726                register_taxonomy( 'wptests_tax1', 'post', array( 'hierarchical' => true ) );
    751727                register_taxonomy( 'wptests_tax2', 'post', array( 'hierarchical' => true ) );
     
    23472323        /**
    23482324         * @ticket 31118
    23492325         */
    2350         public function test_parent_should_skip_query_when_specified_parent_is_not_found_in_hierarchy_cache() {
    2351                 global $wpdb;
    2352 
    2353                 register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ) );
    2354 
    2355                 $terms = self::factory()->term->create_many( 3, array( 'taxonomy' => 'wptests_tax' ) );
    2356 
    2357                 $num_queries = $wpdb->num_queries;
    2358 
    2359                 $found = get_terms(
    2360                         'wptests_tax',
    2361                         array(
    2362                                 'hide_empty' => false,
    2363                                 'parent'     => $terms[0],
    2364                         )
    2365                 );
    2366 
    2367                 $this->assertEmpty( $found );
    2368                 $this->assertSame( $num_queries, $wpdb->num_queries );
    2369         }
    2370 
    2371         /**
    2372          * @ticket 31118
    2373          */
    23742326        public function test_parent_should_respect_multiple_taxonomies() {
    23752327                register_taxonomy( 'wptests_tax1', 'post', array( 'hierarchical' => true ) );
    23762328                register_taxonomy( 'wptests_tax2', 'post', array( 'hierarchical' => true ) );