Ticket #21785: 21785-move-query-logic.diff
File 21785-move-query-logic.diff, 7.9 KB (added by , 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 07c5dd8..aad5472 100644
a b class Custom_Image_Header { 248 248 function process_default_headers() { 249 249 global $_wp_default_headers; 250 250 251 static $has_processed_headers = false; 252 253 if ( $has_processed_headers ) { 254 return; 255 } 256 251 257 if ( !empty($this->headers) ) 252 258 return; 253 259 … … class Custom_Image_Header { 262 268 $this->default_headers[$header]['thumbnail_url'] = sprintf( $this->default_headers[$header]['thumbnail_url'], $template_directory_uri, $stylesheet_directory_uri ); 263 269 } 264 270 271 $has_processed_headers = true; 265 272 } 266 273 267 274 /** … … wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?> 1228 1235 $key = '_wp_attachment_custom_header_last_used_' . get_stylesheet(); 1229 1236 update_post_meta( $attachment_id, $key, time() ); 1230 1237 } 1238 1239 public function get_default_header_images() { 1240 $this->process_default_headers(); 1241 1242 // Get *the* default image if there is one 1243 $default = get_theme_support( 'custom-header', 'default-image' ); 1244 1245 if ( ! $default ) { // If not, 1246 return $this->default_headers; // easy peasy. 1247 } 1248 1249 $default = sprintf( $default, 1250 get_template_directory_uri(), 1251 get_stylesheet_directory_uri() ); 1252 1253 $header_images = array(); 1254 $already_has_default = false; 1255 1256 // Get the whole set of default images 1257 $default_header_images = $this->default_headers; 1258 foreach ( $default_header_images as $k => $h ) { 1259 if ( $h['url'] == $default ) { 1260 $already_has_default = true; 1261 break; 1262 } 1263 } 1264 1265 // If *the one true image* isn't included in the default set, add it in 1266 // first position 1267 if ( ! $already_has_default ) { 1268 $header_images['default'] = array( 1269 'url' => $default, 1270 'thumbnail_url' => $default, 1271 'description' => 'Default' 1272 ); 1273 } 1274 1275 // The rest of the set comes after 1276 $header_images = array_merge( $header_images, $default_header_images ); 1277 1278 return $header_images; 1279 } 1280 1281 public function get_uploaded_header_images() { 1282 $key = '_wp_attachment_custom_header_last_used_' . get_stylesheet(); 1283 $header_images = array(); 1284 1285 $headers_not_dated = get_posts( array( 1286 'post_type' => 'attachment', 1287 'meta_key' => '_wp_attachment_is_custom_header', 1288 'meta_value' => get_option('stylesheet'), 1289 'orderby' => 'none', 1290 '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 ) 1303 ) ); 1304 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 ) ); 1319 1320 $limit = apply_filters( 'custom_header_uploaded_limit', 15 ); 1321 $headers = array_merge( $headers_dated, $headers_not_dated ); 1322 $headers = array_slice( $headers, 0, $limit ); 1323 1324 foreach ( (array) $headers as $header ) { 1325 $url = esc_url_raw( $header->guid ); 1326 $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 ); 1330 1331 $h = array( 1332 'attachment_id' => $header->ID, 1333 'url' => $url, 1334 'thumbnail_url' => $url, 1335 'timestamp' => $timestamp ? $timestamp : 0, 1336 ); 1337 1338 if ( isset( $header_data['width'] ) ) { 1339 $h['width'] = $header_data['width']; 1340 } 1341 if ( isset( $header_data['height'] ) ) { 1342 $h['height'] = $header_data['height']; 1343 } 1344 1345 $header_images[] = $h; 1346 } 1347 1348 return $header_images; 1349 } 1231 1350 } -
src/wp-includes/class-wp-customize-control.php
diff --git a/src/wp-includes/class-wp-customize-control.php b/src/wp-includes/class-wp-customize-control.php index 896bdd9..e1d3187 100644
a b final class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control 761 761 parent::enqueue(); 762 762 } 763 763 764 public function get_default_header_images() {765 global $custom_image_header;766 767 // Get *the* default image if there is one768 $default = get_theme_support( 'custom-header', 'default-image' );769 770 if ( ! $default ) { // If not,771 return $custom_image_header->default_headers; // easy peasy.772 }773 774 $default = sprintf( $default,775 get_template_directory_uri(),776 get_stylesheet_directory_uri() );777 778 $header_images = array();779 $already_has_default = false;780 781 // Get the whole set of default images782 $default_header_images = $custom_image_header->default_headers;783 foreach ( $default_header_images as $k => $h ) {784 if ( $h['url'] == $default ) {785 $already_has_default = true;786 break;787 }788 }789 790 // If *the one true image* isn't included in the default set, add it in791 // first position792 if ( ! $already_has_default ) {793 $header_images['default'] = array(794 'url' => $default,795 'thumbnail_url' => $default,796 'description' => 'Default'797 );798 }799 800 // The rest of the set comes after801 $header_images = array_merge( $header_images, $default_header_images );802 803 return $header_images;804 }805 806 public function get_uploaded_header_images() {807 $key = '_wp_attachment_custom_header_last_used_' . get_stylesheet();808 $header_images = array();809 810 $headers_not_dated = get_posts( array(811 'post_type' => 'attachment',812 'meta_key' => '_wp_attachment_is_custom_header',813 'meta_value' => get_option('stylesheet'),814 'orderby' => 'none',815 'nopaging' => true,816 'meta_query' => array(817 array(818 'key' => '_wp_attachment_is_custom_header',819 'value' => get_option( 'stylesheet' ),820 'compare' => 'LIKE'821 ),822 array(823 'key' => $key,824 'value' => 'this string must not be empty',825 'compare' => 'NOT EXISTS'826 ),827 )828 ) );829 830 $headers_dated = get_posts( array(831 'post_type' => 'attachment',832 'meta_key' => $key,833 'orderby' => 'meta_value_num',834 'order' => 'DESC',835 'nopaging' => true,836 'meta_query' => array(837 array(838 'key' => '_wp_attachment_is_custom_header',839 'value' => get_option( 'stylesheet' ),840 'compare' => 'LIKE'841 ),842 ),843 ) );844 845 $limit = apply_filters( 'custom_header_uploaded_limit', 15 );846 $headers = array_merge( $headers_dated, $headers_not_dated );847 $headers = array_slice( $headers, 0, $limit );848 849 foreach ( (array) $headers as $header ) {850 $url = esc_url_raw( $header->guid );851 $header_data = wp_get_attachment_metadata( $header->ID );852 $timestamp = get_post_meta( $header->ID,853 '_wp_attachment_custom_header_last_used_' . get_stylesheet(),854 true );855 856 $h = array(857 'attachment_id' => $header->ID,858 'url' => $url,859 'thumbnail_url' => $url,860 'timestamp' => $timestamp ? $timestamp : 0,861 );862 863 if ( isset( $header_data['width'] ) ) {864 $h['width'] = $header_data['width'];865 }866 if ( isset( $header_data['height'] ) ) {867 $h['height'] = $header_data['height'];868 }869 870 $header_images[] = $h;871 }872 873 return $header_images;874 }875 876 764 public function prepare_control() { 877 765 global $custom_image_header; 878 766 if ( empty( $custom_image_header ) ) { … … final class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control 881 769 882 770 // Process default headers and uploaded headers. 883 771 $custom_image_header->process_default_headers(); 884 $this->default_headers = $ this->get_default_header_images();885 $this->uploaded_headers = $ this->get_uploaded_header_images();772 $this->default_headers = $custom_image_header->get_default_header_images(); 773 $this->uploaded_headers = $custom_image_header->get_uploaded_header_images(); 886 774 } 887 775 888 776 function print_header_image_template() {