Changeset 27849
- Timestamp:
- 03/29/2014 10:52:17 AM (11 years ago)
- Location:
- trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/custom-header.php
r27497 r27849 41 41 * @access private 42 42 */ 43 var $default_headers = array();43 var $default_headers; 44 44 45 45 /** … … 255 255 return; 256 256 257 if ( is_array( $this->default_headers ) ) { 258 return; 259 } 260 257 261 $this->default_headers = $_wp_default_headers; 258 262 $template_directory_uri = get_template_directory_uri(); … … 262 266 $this->default_headers[$header]['thumbnail_url'] = sprintf( $this->default_headers[$header]['thumbnail_url'], $template_directory_uri, $stylesheet_directory_uri ); 263 267 } 264 265 268 } 266 269 … … 1229 1232 update_post_meta( $attachment_id, $key, time() ); 1230 1233 } 1234 1235 public function get_default_header_images() { 1236 $this->process_default_headers(); 1237 1238 // Get the default image if there is one. 1239 $default = get_theme_support( 'custom-header', 'default-image' ); 1240 1241 if ( ! $default ) { // If not, 1242 return $this->default_headers; // easy peasy. 1243 } 1244 1245 $default = sprintf( $default, get_template_directory_uri(), get_stylesheet_directory_uri() ); 1246 $already_has_default = false; 1247 1248 foreach ( $this->default_headers as $k => $h ) { 1249 if ( $h['url'] === $default ) { 1250 $already_has_default = true; 1251 break; 1252 } 1253 } 1254 1255 if ( $already_has_default ) { 1256 return $this->default_headers; 1257 } 1258 1259 // If the one true image isn't included in the default set, prepend it. 1260 $header_images = array(); 1261 $header_images['default'] = array( 1262 'url' => $default, 1263 'thumbnail_url' => $default, 1264 'description' => 'Default' 1265 ); 1266 1267 // The rest of the set comes after. 1268 $header_images = array_merge( $header_images, $this->default_headers ); 1269 return $header_images; 1270 } 1271 1272 public function get_uploaded_header_images() { 1273 $header_images = get_uploaded_header_images(); 1274 $timestamp_key = '_wp_attachment_custom_header_last_used_' . get_stylesheet(); 1275 1276 foreach ( $header_images as &$header_image ) { 1277 $header_image['timestamp'] = get_post_meta( $header_image['attachment_id'], $timestamp_key, true ); 1278 } 1279 1280 return $header_images; 1281 } 1231 1282 } -
trunk/src/wp-includes/class-wp-customize-control.php
r27816 r27849 756 756 } 757 757 758 public function get_default_header_images() {759 global $custom_image_header;760 761 // Get *the* default image if there is one762 $default = get_theme_support( 'custom-header', 'default-image' );763 764 if ( ! $default ) { // If not,765 return $custom_image_header->default_headers; // easy peasy.766 }767 768 $default = sprintf( $default,769 get_template_directory_uri(),770 get_stylesheet_directory_uri() );771 772 $header_images = array();773 $already_has_default = false;774 775 // Get the whole set of default images776 $default_header_images = $custom_image_header->default_headers;777 foreach ( $default_header_images as $k => $h ) {778 if ( $h['url'] == $default ) {779 $already_has_default = true;780 break;781 }782 }783 784 // If *the one true image* isn't included in the default set, add it in785 // first position786 if ( ! $already_has_default ) {787 $header_images['default'] = array(788 'url' => $default,789 'thumbnail_url' => $default,790 'description' => 'Default'791 );792 }793 794 // The rest of the set comes after795 $header_images = array_merge( $header_images, $default_header_images );796 797 return $header_images;798 }799 800 public function get_uploaded_header_images() {801 $key = '_wp_attachment_custom_header_last_used_' . get_stylesheet();802 $header_images = array();803 804 $headers_not_dated = get_posts( array(805 'post_type' => 'attachment',806 'meta_key' => '_wp_attachment_is_custom_header',807 'meta_value' => get_option('stylesheet'),808 'orderby' => 'none',809 'nopaging' => true,810 'meta_query' => array(811 array(812 'key' => '_wp_attachment_is_custom_header',813 'value' => get_option( 'stylesheet' ),814 'compare' => 'LIKE'815 ),816 array(817 'key' => $key,818 'value' => 'this string must not be empty',819 'compare' => 'NOT EXISTS'820 ),821 )822 ) );823 824 $headers_dated = get_posts( array(825 'post_type' => 'attachment',826 'meta_key' => $key,827 'orderby' => 'meta_value_num',828 'order' => 'DESC',829 'nopaging' => true,830 'meta_query' => array(831 array(832 'key' => '_wp_attachment_is_custom_header',833 'value' => get_option( 'stylesheet' ),834 'compare' => 'LIKE'835 ),836 ),837 ) );838 839 $limit = apply_filters( 'custom_header_uploaded_limit', 15 );840 $headers = array_merge( $headers_dated, $headers_not_dated );841 $headers = array_slice( $headers, 0, $limit );842 843 foreach ( (array) $headers as $header ) {844 $url = esc_url_raw( $header->guid );845 $header_data = wp_get_attachment_metadata( $header->ID );846 $timestamp = get_post_meta( $header->ID,847 '_wp_attachment_custom_header_last_used_' . get_stylesheet(),848 true );849 850 $h = array(851 'attachment_id' => $header->ID,852 'url' => $url,853 'thumbnail_url' => $url,854 'timestamp' => $timestamp ? $timestamp : 0,855 );856 857 if ( isset( $header_data['width'] ) ) {858 $h['width'] = $header_data['width'];859 }860 if ( isset( $header_data['height'] ) ) {861 $h['height'] = $header_data['height'];862 }863 864 $header_images[] = $h;865 }866 867 return $header_images;868 }869 870 758 public function prepare_control() { 871 759 global $custom_image_header; … … 876 764 // Process default headers and uploaded headers. 877 765 $custom_image_header->process_default_headers(); 878 $this->default_headers = $ this->get_default_header_images();879 $this->uploaded_headers = $ this->get_uploaded_header_images();766 $this->default_headers = $custom_image_header->get_default_header_images(); 767 $this->uploaded_headers = $custom_image_header->get_uploaded_header_images(); 880 768 } 881 769
Note: See TracChangeset
for help on using the changeset viewer.