Make WordPress Core

Ticket #34047: 34047.patch

File 34047.patch, 3.0 KB (added by dlh, 10 years ago)
  • src/wp-includes/default-filters.php

     
    201201add_filter( 'xmlrpc_pingback_error',    'xmlrpc_pingback_error'               );
    202202add_filter( 'title_save_pre',           'trim'                                );
    203203add_filter( 'get_comment_metadata',     'wp_lazyload_comment_meta',     10, 2 );
    204 add_filter( 'get_term_metadata',        'wp_lazyload_term_meta',        10, 2 );
     204add_filter( 'get_term_metadata',        'wp_lazyload_term_meta',        99, 2 );
    205205
    206206add_filter( 'http_request_host_is_external', 'allowed_http_request_hosts', 10, 2 );
    207207
  • src/wp-includes/taxonomy-functions.php

     
    15811581 * As a rule, term queries (`get_terms()` and `wp_get_object_terms()`) prime the metadata cache for matched terms by
    15821582 * default. However, this can cause a slight performance penalty, especially when that metadata is not actually used.
    15831583 * In the context of a `WP_Query` loop, we're able to avoid this potential penalty. `update_object_term_cache()`,
    1584  * called from `update_post_caches()`, does not 'update_term_meta_cache'. Instead, the first time `get_term_meta()` is
    1585  * called from within a `WP_Query` loop, the current function detects the fact, and then primes the metadata cache for
    1586  * all terms attached to all posts in the loop, with a single database query.
     1584 * called from `update_post_caches()`, does not `update_termmeta_cache()`. Instead, the first time `get_term_meta()` is
     1585 * called from within a `WP_Query` loop, the current function detects the fact, and then primes the metadata cache.
    15871586 *
    15881587 * @since 4.4.0
    15891588 *
    1590  * @param null $check   The `$check` param passed from the 'pre_term_metadata' hook.
     1589 * @param mixed $check   The `$check` param passed from the 'get_term_metadata' hook.
    15911590 * @param int  $term_id ID of the term whose metadata is being cached.
    1592  * @return null In order not to short-circuit `get_metadata()`.
     1591 * @return mixed The original value of `$check`.
    15931592 */
    15941593function wp_lazyload_term_meta( $check, $term_id ) {
    15951594        global $wp_query;
    15961595
     1596        // Skip if the call to `get_metadata()` will be short-circuited.
     1597        if ( null === $check ) {
     1598                prime_term_meta_cache( $wp_query );
     1599        }
     1600
     1601        return $check;
     1602}
     1603
     1604/**
     1605 * Prime the metadata cache for all terms attached to all posts in a WP_Query.
     1606 *
     1607 * @since 4.4.0
     1608 *
     1609 * @param WP_Query $wp_query Query object.
     1610 */
     1611function prime_term_meta_cache( $wp_query ) {
    15971612        if ( $wp_query instanceof WP_Query && ! empty( $wp_query->posts ) && $wp_query->get( 'update_post_term_cache' ) ) {
    15981613                // We can only lazyload if the entire post object is present.
    15991614                $posts = array();
     
    16281643                        update_termmeta_cache( array_keys( $term_ids ) );
    16291644                }
    16301645        }
    1631 
    1632         return $check;
    16331646}
    16341647
    16351648/**