Ticket #20871: 20871.3.diff
| File 20871.3.diff, 12.3 KB (added by , 14 years ago) |
|---|
-
wp-admin/custom-background.php
383 383 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); 384 384 update_post_meta( $id, '_wp_attachment_is_custom_background', get_option('stylesheet' ) ); 385 385 386 set_theme_mod('background_image', esc_url ($url));386 set_theme_mod('background_image', esc_url_raw($url)); 387 387 388 388 $thumbnail = wp_get_attachment_image_src( $id, 'thumbnail' ); 389 set_theme_mod('background_image_thumb', esc_url ( $thumbnail[0] ) );389 set_theme_mod('background_image_thumb', esc_url_raw( $thumbnail[0] ) ); 390 390 391 391 do_action('wp_create_file_in_uploads', $file, $id); // For replication 392 392 $this->updated = true; … … 425 425 update_post_meta( $attachment_id, '_wp_attachment_is_custom_background', get_option('stylesheet' ) ); 426 426 $url = wp_get_attachment_image_src( $attachment_id, $size ); 427 427 $thumbnail = wp_get_attachment_image_src( $attachment_id, 'thumbnail' ); 428 set_theme_mod( 'background_image', esc_url ( $url[0] ) );429 set_theme_mod( 'background_image_thumb', esc_url ( $thumbnail[0] ) );428 set_theme_mod( 'background_image', esc_url_raw( $url[0] ) ); 429 set_theme_mod( 'background_image_thumb', esc_url_raw( $thumbnail[0] ) ); 430 430 exit; 431 431 } 432 432 } -
wp-admin/custom-header.php
211 211 212 212 if ( isset( $_POST['resetheader'] ) ) { 213 213 check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' ); 214 $this->process_default_headers(); 215 $default = get_theme_support( 'custom-header', 'default-image' ); 216 $default = sprintf( $default, get_template_directory_uri(), get_stylesheet_directory_uri() ); 217 foreach ( $this->default_headers as $header => $details ) { 218 if ( $details['url'] == $default ) { 219 $default_data = $details; 220 break; 221 } 222 } 223 set_theme_mod( 'header_image', $default ); 224 if ( empty( $default_data['width'] ) ) 225 $default_data['width'] = get_theme_support( 'custom-header', 'width' ); 226 if ( empty( $default_data['height'] ) ) 227 $default_data['height'] = get_theme_support( 'custom-header', 'height' ); 228 set_theme_mod( 'header_image_data', (object) $default_data ); 214 $this->reset_header_image(); 229 215 return; 230 216 } 231 217 … … 237 223 238 224 if ( isset( $_POST['removeheader'] ) ) { 239 225 check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' ); 240 set_theme_mod( 'header_image', 'remove-header');226 $this->remove_header_image(); 241 227 return; 242 228 } 243 229 … … 256 242 257 243 if ( isset( $_POST['default-header'] ) ) { 258 244 check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' ); 259 if ( 'random-default-image' == $_POST['default-header'] ) { 260 set_theme_mod( 'header_image', 'random-default-image' ); 261 } elseif ( 'random-uploaded-image' == $_POST['default-header'] ) { 262 set_theme_mod( 'header_image', 'random-uploaded-image' ); 263 } else { 264 $this->process_default_headers(); 265 $uploaded = get_uploaded_header_images(); 266 if ( isset( $uploaded[$_POST['default-header']] ) ) { 267 set_theme_mod( 'header_image', esc_url( $uploaded[$_POST['default-header']]['url'] ) ); 268 set_theme_mod( 'header_image_data', (object) $uploaded[$_POST['default-header']] ); 269 } elseif ( isset( $this->default_headers[$_POST['default-header']] ) ) { 270 set_theme_mod( 'header_image', esc_url( $this->default_headers[$_POST['default-header']]['url'] ) ); 271 if ( empty( $this->default_headers[$_POST['default-header']]['width'] ) ) 272 $this->default_headers[$_POST['default-header']]['width'] = get_theme_support( 'custom-header', 'width' ); 273 if ( empty( $this->default_headers[$_POST['default-header']]['height'] ) ) 274 $this->default_headers[$_POST['default-header']]['height'] = get_theme_support( 'custom-header', 'height' ); 275 set_theme_mod( 'header_image_data', (object) $this->default_headers[$_POST['default-header']] ); 276 } 277 } 245 $this->choose_existing_header_image( $_POST['default-header'] ); 246 return; 278 247 } 279 248 } 280 249 … … 718 687 wp_die( __( 'Cheatin’ uh?' ) ); 719 688 720 689 if ( empty( $_POST ) && isset( $_GET['file'] ) ) { 721 $ id = absint( $_GET['file'] );722 $file = get_attached_file( $ id, true );723 $url = wp_get_attachment_image_src( $ id, 'full');690 $attachment_id = absint( $_GET['file'] ); 691 $file = get_attached_file( $attachment_id, true ); 692 $url = wp_get_attachment_image_src( $attachment_id, 'full'); 724 693 $url = $url[0]; 725 694 } elseif ( isset( $_POST ) ) { 726 695 extract($this->step_2_manage_upload()); … … 729 698 if ( file_exists( $file ) ) { 730 699 list( $width, $height, $type, $attr ) = getimagesize( $file ); 731 700 } else { 732 $data = wp_get_attachment_metadata( $ id );701 $data = wp_get_attachment_metadata( $attachment_id ); 733 702 $height = $data[ 'height' ]; 734 703 $width = $data[ 'width' ]; 735 704 unset( $data ); … … 750 719 { 751 720 // Add the meta-data 752 721 if ( file_exists( $file ) ) 753 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); 754 update_post_meta( $id, '_wp_attachment_is_custom_header', get_option('stylesheet' ) ); 722 wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $file ) ); 755 723 756 set_theme_mod('header_image', esc_url($url)); 757 do_action('wp_create_file_in_uploads', $file, $id); // For replication 724 $this->select_new_header_image( compact( 'url', 'attachment_id', 'width', 'height' ) ); 725 726 do_action('wp_create_file_in_uploads', $file, $attachment_id); // For replication 758 727 return $this->finished(); 759 728 } elseif ( $width > $max_width ) { 760 729 $oitar = $width / $max_width; 761 $image = wp_crop_image($ id, 0, 0, $width, $height, $max_width, $height / $oitar, false, str_replace(basename($file), 'midsize-'.basename($file), $file));730 $image = wp_crop_image($attachment_id, 0, 0, $width, $height, $max_width, $height / $oitar, false, str_replace(basename($file), 'midsize-'.basename($file), $file)); 762 731 if ( ! $image || is_wp_error( $image ) ) 763 732 wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) ); 764 733 765 $image = apply_filters('wp_create_file_in_uploads', $image, $ id); // For replication734 $image = apply_filters('wp_create_file_in_uploads', $image, $attachment_id); // For replication 766 735 767 736 $url = str_replace(basename($url), basename($image), $url); 768 737 $width = $width / $oitar; … … 788 757 <input type="hidden" name="y1" id="y1" value="0"/> 789 758 <input type="hidden" name="width" id="width" value="<?php echo esc_attr( $width ); ?>"/> 790 759 <input type="hidden" name="height" id="height" value="<?php echo esc_attr( $height ); ?>"/> 791 <input type="hidden" name="attachment_id" id="attachment_id" value="<?php echo esc_attr( $ id ); ?>" />760 <input type="hidden" name="attachment_id" id="attachment_id" value="<?php echo esc_attr( $attachment_id ); ?>" /> 792 761 <input type="hidden" name="oitar" id="oitar" value="<?php echo esc_attr( $oitar ); ?>" /> 793 762 <?php if ( empty( $_POST ) && isset( $_GET['file'] ) ) { ?> 794 763 <input type="hidden" name="create-new-attachment" value="true" /> … … 835 804 ); 836 805 837 806 // Save the data 838 $ id = wp_insert_attachment( $object, $file );839 return compact( ' id', 'file', 'filename', 'url', 'type' );807 $attachment_id = wp_insert_attachment( $object, $file ); 808 return compact( 'attachment_id', 'file', 'filename', 'url', 'type' ); 840 809 } 841 810 842 811 /** … … 918 887 // Update the attachment 919 888 $attachment_id = wp_insert_attachment( $object, $cropped ); 920 889 wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $cropped ) ); 921 update_post_meta( $attachment_id, '_wp_attachment_is_custom_header', get_option( 'stylesheet' ) );922 890 923 set_theme_mod('header_image', $url); 891 $width = $dst_width; 892 $height = $dst_height; 893 $this->select_new_header_image( compact( 'url', 'attachment_id', 'width', 'height' ) ); 924 894 925 $header_data = new stdClass();926 $header_data->attachment_id = $attachment_id;927 $header_data->url = $url;928 $header_data->thumbnail_url = $url;929 $header_data->width = $dst_width;930 $header_data->height = $dst_height;931 932 set_theme_mod( 'header_image_data', $header_data );933 934 895 // cleanup 935 896 $medium = str_replace( basename( $original ), 'midsize-' . basename( $original ), $original ); 936 897 if ( file_exists( $medium ) ) … … 997 958 return array( 'library' => __('Media Library') ); 998 959 } 999 960 961 /** 962 * Remove a header image. 963 * 964 * @since 3.4.0 965 */ 966 final public function remove_header_image() { 967 set_theme_mod( 'header_image', 'remove-header' ); 968 remove_theme_mod( 'header_image_data' ); 969 } 970 971 /** 972 * Reset a header image to the default image for the theme. 973 * 974 * This method does not do anything if the theme does not have a default header image. 975 * 976 * @since 3.4.0 977 */ 978 final public function reset_header_image() { 979 $this->process_default_headers(); 980 $default = get_theme_support( 'custom-header', 'default-image' ); 981 982 if ( ! $default ) 983 return; 984 985 $default = sprintf( $default, get_template_directory_uri(), get_stylesheet_directory_uri() ); 986 987 foreach ( $this->default_headers as $header => $details ) { 988 if ( $details['url'] == $default ) { 989 $default_data = $details; 990 break; 991 } 992 } 993 994 if ( empty( $default_data['width'] ) ) 995 $default_data['width'] = get_theme_support( 'custom-header', 'width' ); 996 if ( empty( $default_data['height'] ) ) 997 $default_data['height'] = get_theme_support( 'custom-header', 'height' ); 998 set_theme_mod( 'header_image', $default ); 999 set_theme_mod( 'header_image_data', (object) $default_data ); 1000 } 1001 1002 /** 1003 * Choose a header image, selected from existing uploaded and default headers. 1004 * 1005 * @param string $choice Which header image to select. Allows for values of 'random-default-image', 1006 * for randomly cycling among the default images; 'random-uploaded-image', for randomly cycling 1007 * among the uploaded images; the key of a default image registered for that theme; and 1008 * the key of an image uploaded for that theme (the basename of the URL). 1009 */ 1010 final public function choose_existing_header_image( $choice ) { 1011 if ( 'random-default-image' == $choice ) { 1012 set_theme_mod( 'header_image', 'random-default-image' ); 1013 remove_theme_mod( 'header_image_data' ); 1014 return; 1015 } 1016 1017 if ( 'random-uploaded-image' == $choice ) { 1018 set_theme_mod( 'header_image', 'random-uploaded-image' ); 1019 remove_theme_mod( 'header_image_data' ); 1020 return; 1021 } 1022 1023 $this->process_default_headers(); 1024 if ( isset( $this->default_headers[ $choice ] ) ) { 1025 if ( empty( $this->default_headers[ $choice ]['width'] ) ) 1026 $this->default_headers[ $choice ]['width'] = get_theme_support( 'custom-header', 'width' ); 1027 if ( empty( $this->default_headers[ $choice ]['height'] ) ) 1028 $this->default_headers[ $choice ]['height'] = get_theme_support( 'custom-header', 'height' ); 1029 set_theme_mod( 'header_image', esc_url_raw( $this->default_headers[ $choice ]['url'] ) ); 1030 set_theme_mod( 'header_image_data', (object) $this->default_headers[ $choice ] ); 1031 return; 1032 } 1033 1034 $uploaded = get_uploaded_header_images(); 1035 if ( isset( $uploaded[ $choice ] ) ) { 1036 set_theme_mod( 'header_image', esc_url_raw( $uploaded[ $choice ]['url'] ) ); 1037 set_theme_mod( 'header_image_data', (object) $uploaded[ $choice ] ); 1038 return; 1039 } 1040 } 1041 1042 /** 1043 * Select a header image, either newly uploaded or from the media library. 1044 * 1045 * @since 3.4.0 1046 * 1047 * @param array $args An array of arguments: attachment_id, url, width, height. All are required. 1048 */ 1049 final public function select_new_header_image( $args ) { 1050 extract( $args ); 1051 1052 $url = esc_url_raw( $url ); 1053 1054 $header_data = new stdClass(); 1055 $header_data->attachment_id = $attachment_id; 1056 $header_data->url = $url; 1057 $header_data->thumbnail_url = $url; 1058 $header_data->width = $width; 1059 $header_data->height = $height; 1060 1061 update_post_meta( $attachment_id, '_wp_attachment_is_custom_header', get_stylesheet() ); 1062 set_theme_mod( 'header_image', $url ); 1063 set_theme_mod( 'header_image_data', $header_data ); 1064 } 1000 1065 }