Ticket #18959: multiple-header-images.2.diff
File multiple-header-images.2.diff, 7.6 KB (added by , 10 years ago) |
---|
-
.
-
wp-admin/custom-header.php
Property changes on: . ___________________________________________________________________ Added: svn:ignore ## -0,0 +1 ## +wp-config.php
278 278 set_theme_mod( 'header_textcolor', 'blank' ); 279 279 } 280 280 281 if ( isset ( $_POST['default-header'] ) ) {281 if ( isset ( $_POST['random-header'] ) ) { 282 282 check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' ); 283 $this->set_header_image( $_POST['random-header'] ); 284 return; 285 } elseif ( isset( $_POST['default-header'] ) && is_array( $_POST['default-header'] ) && count( $_POST['default-header'] ) ) { 286 check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' ); 283 287 $this->set_header_image( $_POST['default-header'] ); 284 288 return; 285 289 } … … 330 334 331 335 if ( 1 < count( $headers ) ) { 332 336 echo '<div class="random-header">'; 333 echo '<label><input name=" default-header" type="radio" value="random-' . $type . '-image"' . checked( is_random_header_image( $type ), true, false ) . ' />';337 echo '<label><input name="random-header" type="radio" value="random-' . $type . '-image"' . checked( is_random_header_image( $type ), true, false ) . ' />'; 334 338 echo __( '<strong>Random:</strong> Show a different image on each page.' ); 335 339 echo '</label>'; 336 340 echo '</div>'; … … 341 345 $header_thumbnail = $header['thumbnail_url']; 342 346 $header_url = $header['url']; 343 347 $header_desc = empty( $header['description'] ) ? '' : $header['description']; 348 if ( is_array( get_theme_mod( 'header_image' ) ) ) { 349 $checked = checked( in_array( $header_url, get_theme_mod( 'header_image' ) ), true, false ); 350 } else { 351 $checked = checked( $header_url, get_theme_mod( 'header_image' ), false ); 352 } 344 353 echo '<div class="default-header">'; 345 echo '<label><input name="default-header " type="radio" value="' . esc_attr( $header_key ) . '" ' . checked( $header_url, get_theme_mod( 'header_image' ), false ). ' />';354 echo '<label><input name="default-header[]" type="checkbox" value="' . esc_attr( $header_key ) . '" ' . $checked . ' />'; 346 355 $width = ''; 347 356 if ( !empty( $header['attachment_id'] ) ) 348 357 $width = ' width="230"'; … … 1008 1017 final public function set_header_image( $choice ) { 1009 1018 if ( is_array( $choice ) || is_object( $choice ) ) { 1010 1019 $choice = (array) $choice; 1011 if ( ! isset( $choice['attachment_id'] ) || ! isset( $choice['url'] ) ) 1012 return; 1020 if ( ! isset( $choice['attachment_id'] ) || ! isset( $choice['url'] ) ) { 1021 $header_image_data = $header_image = array(); 1022 $this->process_default_headers(); 1023 $uploaded = get_uploaded_header_images(); 1013 1024 1014 $choice['url'] = esc_url_raw( $choice['url'] ); 1025 foreach ( $choice as $image ) { 1026 if ( $uploaded && isset( $uploaded[ $image ] ) ) { 1027 $image = $uploaded[ $image ]; 1028 } elseif ( isset( $this->default_headers[ $image ] ) ) { 1029 $image = $this->default_headers[ $image ]; 1030 } elseif ( is_string( $image ) ) { 1031 $image = array( 'url' => $image ); 1032 } 1015 1033 1016 $header_image_data = (object) array( 1017 'attachment_id' => $choice['attachment_id'], 1018 'url' => $choice['url'], 1019 'thumbnail_url' => $choice['url'], 1020 'height' => $choice['height'], 1021 'width' => $choice['width'], 1022 ); 1034 $image['url'] = esc_url_raw( $image['url'] ); 1035 if( ! isset( $image['attachment_id'] ) || ! isset( $image['url'] ) ) { 1036 $header_image_data[] = $image; 1037 } else { 1038 $header_image_data[] = (object) array( 1039 'attachment_id' => $image['attachment_id'], 1040 'url' => $image['url'], 1041 'thumbnail_url' => $image['url'], 1042 'height' => $image['height'], 1043 'width' => $image['width'], 1044 ); 1023 1045 1024 update_post_meta( $choice['attachment_id'], '_wp_attachment_is_custom_header', get_stylesheet() ); 1025 set_theme_mod( 'header_image', $choice['url'] ); 1026 set_theme_mod( 'header_image_data', $header_image_data ); 1046 update_post_meta( $image['attachment_id'], '_wp_attachment_is_custom_header', get_stylesheet() ); 1047 } 1048 1049 $header_image[] = $image['url']; 1050 } 1051 1052 set_theme_mod( 'header_image', $header_image ); 1053 set_theme_mod( 'header_image_data', $header_image_data ); 1054 } else { 1055 $choice['url'] = esc_url_raw( $choice['url'] ); 1056 1057 $header_image_data = get_theme_mod( 'header_image_data' ); 1058 $header_image = get_theme_mod( 'header_image' ); 1059 1060 $header_image_data[] = (object) array( 1061 'attachment_id' => $choice['attachment_id'], 1062 'url' => $choice['url'], 1063 'thumbnail_url' => $choice['url'], 1064 'height' => $choice['height'], 1065 'width' => $choice['width'], 1066 ); 1067 $header_image[] = $choice['url']; 1068 1069 update_post_meta( $choice['attachment_id'], '_wp_attachment_is_custom_header', get_stylesheet() ); 1070 set_theme_mod( 'header_image', $header_image ); 1071 set_theme_mod( 'header_image_data', $header_image_data ); 1072 } 1027 1073 return; 1028 1074 } 1029 1075 … … 1036 1082 $uploaded = get_uploaded_header_images(); 1037 1083 if ( $uploaded && isset( $uploaded[ $choice ] ) ) { 1038 1084 $header_image_data = $uploaded[ $choice ]; 1039 1040 1085 } else { 1041 1086 $this->process_default_headers(); 1042 1087 if ( isset( $this->default_headers[ $choice ] ) ) … … 1045 1090 return; 1046 1091 } 1047 1092 1048 set_theme_mod( 'header_image', esc_url_raw( $header_image_data['url'] ));1093 set_theme_mod( 'header_image', $header_image ); 1049 1094 set_theme_mod( 'header_image_data', $header_image_data ); 1050 1095 } 1051 1096 -
wp-admin/js/custom-header.js
6 6 // Fetch available headers and apply jQuery.masonry 7 7 // once the images have loaded. 8 8 var $headers = $('.available-headers'); 9 var $random = $('.random-header input[type="radio"]'); 10 var $images = $('.available-headers input[type="checkbox"]'); 9 11 10 12 $headers.imagesLoaded( function() { 11 13 $headers.masonry({ … … 14 16 }); 15 17 }); 16 18 19 // Uncheck selected header images when random radio is selected 20 $random.on( 'click', function() { 21 $images.removeAttr('checked'); 22 }); 23 24 // Uncheck random radio when header images are selected 25 $images.on( 'click', function() { 26 if ( $images.is(':checked') ) $random.removeAttr('checked'); 27 }); 28 17 29 // Build the choose from library frame. 18 30 $('#choose-from-library-link').click( function( event ) { 19 31 var $el = $(this); -
wp-includes/theme.php
1040 1040 if ( 'remove-header' == $url ) 1041 1041 return false; 1042 1042 1043 if ( is_random_header_image() ) 1043 if ( is_random_header_image() ) { 1044 1044 $url = get_random_header_image(); 1045 } elseif ( is_array( $url ) ) { 1046 return esc_url_raw( set_url_scheme( get_random_header_image( $url ) ) ); 1047 } 1045 1048 1046 1049 return esc_url_raw( set_url_scheme( $url ) ); 1047 1050 } … … 1091 1094 * 1092 1095 * @since 3.2.0 1093 1096 * 1097 * @param array $paths Optional paths of header images to randomize from 1094 1098 * @return string Path to header image 1095 1099 */ 1096 1100 1097 function get_random_header_image() { 1101 function get_random_header_image( $paths = false ) { 1102 if( $paths ) { 1103 return $paths[ array_rand( $paths ) ]; 1104 } 1105 1098 1106 $random_image = _get_random_header_data(); 1099 1107 if ( empty( $random_image->url ) ) 1100 1108 return '';