Make WordPress Core

Changeset 35299


Ignore:
Timestamp:
10/20/2015 06:22:41 PM (9 years ago)
Author:
obenland
Message:

Site Icon: Get site icon ID only when needed.

Cuts down on unnecessary queries, especially in environments that rely on
post meta a lot. Reverts [32997].

Props ap.koponen, swissspidy.
Fixes #34368.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-site-icon.php

    r35271 r35299  
    230230     */
    231231    public function get_post_metadata( $value, $post_id, $meta_key, $single ) {
    232         $site_icon_id = get_option( 'site_icon' );
    233 
    234         if ( $post_id == $site_icon_id && '_wp_attachment_backup_sizes' == $meta_key && $single ) {
    235             add_filter( 'intermediate_image_sizes', array( $this, 'intermediate_image_sizes' ) );
     232        if ( $single && '_wp_attachment_backup_sizes' === $meta_key ) {
     233            $site_icon_id = get_option( 'site_icon' );
     234
     235            if ( $post_id == $site_icon_id ) {
     236                add_filter( 'intermediate_image_sizes', array( $this, 'intermediate_image_sizes' ) );
     237            }
    236238        }
    237239
  • trunk/tests/phpunit/tests/image/site_icon.php

    r33335 r35299  
    128128    }
    129129
     130    /**
     131     * @ticket 34368
     132     */
     133    function test_get_post_metadata() {
     134        $attachment_id = $this->_insert_attachment();
     135        update_option( 'site_icon', $attachment_id );
     136
     137        $this->wp_site_icon->get_post_metadata( '', $attachment_id, '_some_post_meta', true );
     138        $this->assertFalse( has_filter( 'intermediate_image_sizes', array( $this->wp_site_icon, 'intermediate_image_sizes' ) ) );
     139
     140        $this->wp_site_icon->get_post_metadata( '', $attachment_id, '_wp_attachment_backup_sizes', true );
     141        $this->assertSame( 10,  has_filter( 'intermediate_image_sizes', array( $this->wp_site_icon, 'intermediate_image_sizes' ) ) );
     142
     143        wp_delete_attachment( $attachment_id, true );
     144    }
     145
    130146    function _custom_test_sizes( $sizes ) {
    131147        $sizes[] = 321;
  • trunk/tests/phpunit/tests/post/getPostClass.php

    r35242 r35299  
    121121        $found = get_post_class( '', $this->post_id );
    122122
    123         // The 'site_icon' option check adds a query during unit tests. See {@see WP_Site_Icon::get_post_metadata()}.
    124         $expected_num_queries = $num_queries + 1;
    125 
    126         $this->assertSame( $expected_num_queries, $wpdb->num_queries );
     123        $this->assertSame( $num_queries, $wpdb->num_queries );
    127124    }
    128125}
Note: See TracChangeset for help on using the changeset viewer.