Make WordPress Core

Ticket #21785: consolidated-query-logic-2.diff

File consolidated-query-logic-2.diff, 2.5 KB (added by mcsf, 11 years ago)
  • src/wp-admin/custom-header.php

    diff --git a/src/wp-admin/custom-header.php b/src/wp-admin/custom-header.php
    index aad5472..8a07aa7 100644
    a b wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?> 
    12781278                return $header_images;
    12791279        }
    12801280
     1281        private function cmp_headers($a, $b) {
     1282                $a_timestamp = absint( $a->_wp_attachment_custom_header_last_used );
     1283                $b_timestamp = absint( $b->_wp_attachment_custom_header_last_used );
     1284                if ( $a_timestamp == $b_timestamp ) {
     1285                        return 0;
     1286                }
     1287                return ( $a_timestamp > $b_timestamp ) ? -1 : 1;
     1288        }
     1289
    12811290        public function get_uploaded_header_images() {
    12821291                $key = '_wp_attachment_custom_header_last_used_' . get_stylesheet();
    1283                 $header_images = array();
    12841292
    1285                 $headers_not_dated = get_posts( array(
     1293                $headers_all = get_posts( array(
    12861294                        'post_type' => 'attachment',
    12871295                        'meta_key' => '_wp_attachment_is_custom_header',
    12881296                        'meta_value' => get_option('stylesheet'),
    12891297                        'orderby' => 'none',
    12901298                        'nopaging' => true,
    1291                         'meta_query' => array(
    1292                                 array(
    1293                                         'key' => '_wp_attachment_is_custom_header',
    1294                                         'value' => get_option( 'stylesheet' ),
    1295                                         'compare' => 'LIKE'
    1296                                 ),
    1297                                 array(
    1298                                         'key' => $key,
    1299                                         'value' => 'this string must not be empty',
    1300                                         'compare' => 'NOT EXISTS'
    1301                                 ),
    1302                         )
    13031299                ) );
    13041300
    1305                 $headers_dated = get_posts( array(
    1306                         'post_type' => 'attachment',
    1307                         'meta_key' => $key,
    1308                         'orderby' => 'meta_value_num',
    1309                         'order' => 'DESC',
    1310                         'nopaging' => true,
    1311                         'meta_query' => array(
    1312                                 array(
    1313                                         'key' => '_wp_attachment_is_custom_header',
    1314                                         'value' => get_option( 'stylesheet' ),
    1315                                         'compare' => 'LIKE'
    1316                                 ),
    1317                         ),
    1318                 ) );
     1301                $headers = array();
     1302                foreach ( $headers_all as $header ) {
     1303                        $header->_wp_attachment_custom_header_last_used = get_post_meta( $header->ID, $key, true );
     1304                        $headers[] = $header;
     1305                }
    13191306
     1307                usort( $headers, array( $this, 'cmp_headers' ) );
    13201308                $limit = apply_filters( 'custom_header_uploaded_limit', 15 );
    1321                 $headers = array_merge( $headers_dated, $headers_not_dated );
    13221309                $headers = array_slice( $headers, 0, $limit );
    13231310
     1311                $header_images = array();
    13241312                foreach ( (array) $headers as $header ) {
    13251313                        $url = esc_url_raw( $header->guid );
    13261314                        $header_data = wp_get_attachment_metadata( $header->ID );
    1327                         $timestamp = get_post_meta( $header->ID,
    1328                                 '_wp_attachment_custom_header_last_used_' . get_stylesheet(),
    1329                                 true );
     1315                        $timestamp = $header->_wp_attachment_custom_header_last_used;
    13301316
    13311317                        $h = array(
    13321318                                'attachment_id' => $header->ID,