Make WordPress Core

Changeset 39338


Ignore:
Timestamp:
11/22/2016 11:40:22 AM (9 years ago)
Author:
peterwilsoncc
Message:

Themes: Prevent unneeded database updates in wp_get_custom_css_post().

When a custom header image was set but custom CSS was not, wp_get_custom_css_post() was generating an UPDATE query on every frontend request.

In theme options the header image meta data is stored as an object. In update_option() this hits an edge case as the resource IDs of the old and new values never match.

This changes the logic of wp_get_custom_css_post() to ensure set_theme_mod() is only called when the custom CSS has changed.

Props bradyvercher, helen.
Fixes #38866.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/theme.php

    r39276 r39338  
    16401640        'post_status'            => get_post_stati(),
    16411641        'name'                   => sanitize_title( $stylesheet ),
    1642         'number'                 => 1,
     1642        'posts_per_page'         => 1,
    16431643        'no_found_rows'          => true,
    16441644        'cache_results'          => true,
     
    16501650    if ( get_stylesheet() === $stylesheet ) {
    16511651        $post_id = get_theme_mod( 'custom_css_post_id' );
    1652         if ( ! $post_id || ! get_post( $post_id ) ) {
     1652
     1653        if ( $post_id > 0 && get_post( $post_id ) ) {
     1654            $post = get_post( $post_id );
     1655        } else {
    16531656            $query = new WP_Query( $custom_css_query_vars );
    16541657            $post = $query->post;
     
    16571660             * @todo This should get cleared if a custom_css post is added/removed.
    16581661             */
    1659             set_theme_mod( 'custom_css_post_id', $post ? $post->ID : -1 );
    1660         } elseif ( $post_id > 0 ) {
    1661             $post = get_post( $post_id );
     1662            if ( $post ) {
     1663                set_theme_mod( 'custom_css_post_id', $post->ID );
     1664            } elseif ( -1 !== $post_id ) {
     1665                set_theme_mod( 'custom_css_post_id', -1 );
     1666            }
    16621667        }
    16631668    } else {
Note: See TracChangeset for help on using the changeset viewer.