mirror of
git://develop.git.wordpress.org/
synced 2025-01-17 21:08:44 +01:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@35299 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
8ec6153115
commit
e9579b3ed5
@ -229,11 +229,13 @@ class WP_Site_Icon {
|
|||||||
* @return array|null|string The attachment metadata value, array of values, or null.
|
* @return array|null|string The attachment metadata value, array of values, or null.
|
||||||
*/
|
*/
|
||||||
public function get_post_metadata( $value, $post_id, $meta_key, $single ) {
|
public function get_post_metadata( $value, $post_id, $meta_key, $single ) {
|
||||||
|
if ( $single && '_wp_attachment_backup_sizes' === $meta_key ) {
|
||||||
$site_icon_id = get_option( 'site_icon' );
|
$site_icon_id = get_option( 'site_icon' );
|
||||||
|
|
||||||
if ( $post_id == $site_icon_id && '_wp_attachment_backup_sizes' == $meta_key && $single ) {
|
if ( $post_id == $site_icon_id ) {
|
||||||
add_filter( 'intermediate_image_sizes', array( $this, 'intermediate_image_sizes' ) );
|
add_filter( 'intermediate_image_sizes', array( $this, 'intermediate_image_sizes' ) );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
@ -127,6 +127,22 @@ class Tests_WP_Site_Icon extends WP_UnitTestCase {
|
|||||||
$this->assertFalse( get_option( 'site_icon', false ) );
|
$this->assertFalse( get_option( 'site_icon', false ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ticket 34368
|
||||||
|
*/
|
||||||
|
function test_get_post_metadata() {
|
||||||
|
$attachment_id = $this->_insert_attachment();
|
||||||
|
update_option( 'site_icon', $attachment_id );
|
||||||
|
|
||||||
|
$this->wp_site_icon->get_post_metadata( '', $attachment_id, '_some_post_meta', true );
|
||||||
|
$this->assertFalse( has_filter( 'intermediate_image_sizes', array( $this->wp_site_icon, 'intermediate_image_sizes' ) ) );
|
||||||
|
|
||||||
|
$this->wp_site_icon->get_post_metadata( '', $attachment_id, '_wp_attachment_backup_sizes', true );
|
||||||
|
$this->assertSame( 10, has_filter( 'intermediate_image_sizes', array( $this->wp_site_icon, 'intermediate_image_sizes' ) ) );
|
||||||
|
|
||||||
|
wp_delete_attachment( $attachment_id, true );
|
||||||
|
}
|
||||||
|
|
||||||
function _custom_test_sizes( $sizes ) {
|
function _custom_test_sizes( $sizes ) {
|
||||||
$sizes[] = 321;
|
$sizes[] = 321;
|
||||||
|
|
||||||
|
@ -120,9 +120,6 @@ class Tests_Post_GetPostClass extends WP_UnitTestCase {
|
|||||||
|
|
||||||
$found = get_post_class( '', $this->post_id );
|
$found = get_post_class( '', $this->post_id );
|
||||||
|
|
||||||
// The 'site_icon' option check adds a query during unit tests. See {@see WP_Site_Icon::get_post_metadata()}.
|
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||||
$expected_num_queries = $num_queries + 1;
|
|
||||||
|
|
||||||
$this->assertSame( $expected_num_queries, $wpdb->num_queries );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user