]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-admin/custom-header.php
WordPress 3.8.1-scripts
[autoinstalls/wordpress.git] / wp-admin / custom-header.php
index fc9d4f126f10894ea7e8b1edd341857a50138cb9..7f222f7cb7e80cd3aca6c710b61bf61b2ba61b94 100644 (file)
@@ -84,21 +84,15 @@ class Custom_Image_Header {
                if ( ! current_user_can('edit_theme_options') )
                        return;
 
-               $this->page = $page = add_theme_page(__('Header'), __('Header'), 'edit_theme_options', 'custom-header', array(&$this, 'admin_page'));
+               $this->page = $page = add_theme_page(__('Header'), __('Header'), 'edit_theme_options', 'custom-header', array($this, 'admin_page'));
 
-               add_action("admin_print_scripts-$page", array(&$this, 'js_includes'));
-               add_action("admin_print_styles-$page", array(&$this, 'css_includes'));
-               add_action("admin_head-$page", array(&$this, 'help') );
-               add_action("admin_head-$page", array(&$this, 'take_action'), 50);
-               add_action("admin_head-$page", array(&$this, 'js'), 50);
+               add_action("admin_print_scripts-$page", array($this, 'js_includes'));
+               add_action("admin_print_styles-$page", array($this, 'css_includes'));
+               add_action("admin_head-$page", array($this, 'help') );
+               add_action("admin_head-$page", array($this, 'take_action'), 50);
+               add_action("admin_head-$page", array($this, 'js'), 50);
                if ( $this->admin_header_callback )
                        add_action("admin_head-$page", $this->admin_header_callback, 51);
-
-               if ( isset( $_REQUEST['context'] ) && $_REQUEST['context'] == 'custom-header' ) {
-                       add_filter( 'attachment_fields_to_edit', array( $this, 'attachment_fields_to_edit' ), 10, 2 );
-                       add_filter( 'media_upload_tabs', array( $this, 'filter_upload_tabs' ) );
-                       add_filter( 'media_upload_mime_type_links', '__return_empty_array' );
-               }
        }
 
        /**
@@ -130,8 +124,8 @@ class Custom_Image_Header {
                        'title'   => __('Header Text'),
                        'content' =>
                                '<p>' . sprintf( __( 'For most themes, the header text is your Site Title and Tagline, as defined in the <a href="%1$s">General Settings</a> section.' ), admin_url( 'options-general.php' ) ) . '<p>' .
-                               '<p>' . __( 'In the Header Text section of this page, you can choose whether to display this text or hide it. You can also choose a color for the text by typing in a legitimate HTML hex value (eg: &#8220;#ff0000&#8221; for red) or by clicking &#8220;Select a Color&#8221; and dialing in a color using the color picker.') . '</p>' .
-                               '<p>' . __( 'Don&#8217;t forget to Save Changes when you&#8217;re done!') . '</p>'
+                               '<p>' . __( 'In the Header Text section of this page, you can choose whether to display this text or hide it. You can also choose a color for the text by clicking the Select Color button and either typing in a legitimate HTML hex value, e.g. &#8220;#ff0000&#8221; for red, or by choosing a color using the color picker.' ) . '</p>' .
+                               '<p>' . __( 'Don&#8217;t forget to click &#8220;Save Changes&#8221; when you&#8217;re done!') . '</p>'
                ) );
 
                get_current_screen()->set_help_sidebar(
@@ -171,11 +165,10 @@ class Custom_Image_Header {
                $step = $this->step();
 
                if ( ( 1 == $step || 3 == $step ) ) {
-                       add_thickbox();
-                       wp_enqueue_script( 'media-upload' );
+                       wp_enqueue_media();
                        wp_enqueue_script( 'custom-header' );
                        if ( current_theme_supports( 'custom-header', 'header-text' ) )
-                               wp_enqueue_script('farbtastic');
+                               wp_enqueue_script( 'wp-color-picker' );
                } elseif ( 2 == $step ) {
                        wp_enqueue_script('imgareaselect');
                }
@@ -190,7 +183,7 @@ class Custom_Image_Header {
                $step = $this->step();
 
                if ( ( 1 == $step || 3 == $step ) && current_theme_supports( 'custom-header', 'header-text' ) )
-                       wp_enqueue_style('farbtastic');
+                       wp_enqueue_style( 'wp-color-picker' );
                elseif ( 2 == $step )
                        wp_enqueue_style('imgareaselect');
        }
@@ -215,12 +208,6 @@ class Custom_Image_Header {
                        return;
                }
 
-               if ( isset( $_POST['resettext'] ) ) {
-                       check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
-                       remove_theme_mod('header_textcolor');
-                       return;
-               }
-
                if ( isset( $_POST['removeheader'] ) ) {
                        check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
                        $this->remove_header_image();
@@ -332,7 +319,6 @@ class Custom_Image_Header {
        function js_1() { ?>
 <script type="text/javascript">
 /* <![CDATA[ */
-var farbtastic;
 (function($){
        var default_color = '#<?php echo get_theme_support( 'custom-header', 'default-text-color' ); ?>',
                header_text_fields;
@@ -341,7 +327,6 @@ var farbtastic;
                $('#name').css('color', color);
                $('#desc').css('color', color);
                $('#text-color').val(color);
-               farbtastic.setColor(color);
        }
 
        function toggle_text() {
@@ -360,45 +345,20 @@ var farbtastic;
        }
 
        $(document).ready(function() {
+               var text_color = $('#text-color');
                header_text_fields = $('.displaying-header-text');
-               $('#pickcolor').click(function(e) {
-                       e.preventDefault();
-                       $('#color-picker').show();
+               text_color.wpColorPicker({
+                       change: function( event, ui ) {
+                               pickColor( text_color.wpColorPicker('color') );
+                       },
+                       clear: function() {
+                               pickColor( '' );
+                       }
                });
-
                $('#display-header-text').click( toggle_text );
-
-               $('#defaultcolor').click(function() {
-                       pickColor(default_color);
-                       $('#text-color').val(default_color);
-               });
-
-               $('#text-color').keyup(function() {
-                       var _hex = $('#text-color').val();
-                       var hex = _hex;
-                       if ( hex[0] != '#' )
-                               hex = '#' + hex;
-                       hex = hex.replace(/[^#a-fA-F0-9]+/, '');
-                       if ( hex != _hex )
-                               $('#text-color').val(hex);
-                       if ( hex.length == 4 || hex.length == 7 )
-                               pickColor( hex );
-               });
-
-               $(document).mousedown(function(){
-                       $('#color-picker').each( function() {
-                               var display = $(this).css('display');
-                               if (display == 'block')
-                                       $(this).fadeOut(2);
-                       });
-               });
-
-               farbtastic = $.farbtastic('#color-picker', function(color) { pickColor(color); });
-               <?php if ( display_header_text() ) { ?>
-               pickColor('#<?php echo get_header_textcolor(); ?>');
-               <?php } else { ?>
+               <?php if ( ! display_header_text() ) : ?>
                toggle_text();
-               <?php } ?>
+               <?php endif; ?>
        });
 })(jQuery);
 /* ]]> */
@@ -490,7 +450,6 @@ var farbtastic;
 ?>
 
 <div class="wrap">
-<?php screen_icon(); ?>
 <h2><?php _e('Custom Header'); ?></h2>
 
 <?php if ( ! empty( $this->updated ) ) { ?>
@@ -504,14 +463,21 @@ var farbtastic;
 <table class="form-table">
 <tbody>
 
+<?php if ( get_custom_header() || display_header_text() ) : ?>
 <tr valign="top">
 <th scope="row"><?php _e( 'Preview' ); ?></th>
 <td>
        <?php if ( $this->admin_image_div_callback ) {
          call_user_func( $this->admin_image_div_callback );
        } else {
+               $custom_header = get_custom_header();
+               $header_image_style = 'background-image:url(' . esc_url( get_header_image() ) . ');';
+               if ( $custom_header->width )
+                       $header_image_style .= 'max-width:' . $custom_header->width . 'px;';
+               if ( $custom_header->height )
+                       $header_image_style .= 'height:' . $custom_header->height . 'px;';
        ?>
-       <div id="headimg" style="background-image:url(<?php esc_url ( header_image() ) ?>);max-width:<?php echo get_custom_header()->width; ?>px;height:<?php echo get_custom_header()->height; ?>px;">
+       <div id="headimg" style="<?php echo $header_image_style; ?>">
                <?php
                if ( display_header_text() )
                        $style = ' style="color:#' . get_header_textcolor() . ';"';
@@ -524,11 +490,13 @@ var farbtastic;
        <?php } ?>
 </td>
 </tr>
+<?php endif; ?>
+
 <?php if ( current_theme_supports( 'custom-header', 'uploads' ) ) : ?>
 <tr valign="top">
 <th scope="row"><?php _e( 'Select Image' ); ?></th>
 <td>
-       <p><?php _e( 'You can upload a custom header image to be shown at the top of your site instead of the default one. On the next screen you will be able to crop the image.' ); ?><br />
+       <p><?php _e( 'You can select an image to be shown at the top of your site by uploading from your computer or choosing from your media library. After selecting an image you will be able to crop it.' ); ?><br />
        <?php
        if ( ! current_theme_supports( 'custom-header', 'flex-height' ) && ! current_theme_supports( 'custom-header', 'flex-width' ) ) {
                printf( __( 'Images of exactly <strong>%1$d &times; %2$d pixels</strong> will be used as-is.' ) . '<br />', get_theme_support( 'custom-header', 'width' ), get_theme_support( 'custom-header', 'height' ) );
@@ -546,7 +514,7 @@ var farbtastic;
                        printf( __( 'Suggested height is <strong>%1$d pixels</strong>.' ) . ' ', get_theme_support( 'custom-header', 'height' ) );
        }
        ?></p>
-       <form enctype="multipart/form-data" id="upload-form" method="post" action="<?php echo esc_attr( add_query_arg( 'step', 2 ) ) ?>">
+       <form enctype="multipart/form-data" id="upload-form" class="wp-upload-form" method="post" action="<?php echo esc_url( add_query_arg( 'step', 2 ) ) ?>">
        <p>
                <label for="upload"><?php _e( 'Choose an image from your computer:' ); ?></label><br />
                <input type="file" id="upload" name="import" />
@@ -555,13 +523,18 @@ var farbtastic;
                <?php submit_button( __( 'Upload' ), 'button', 'submit', false ); ?>
        </p>
        <?php
-               $image_library_url = get_upload_iframe_src( 'image', null, 'library' );
-               $image_library_url = remove_query_arg( 'TB_iframe', $image_library_url );
-               $image_library_url = add_query_arg( array( 'context' => 'custom-header', 'TB_iframe' => 1 ), $image_library_url );
+               $modal_update_href = esc_url( add_query_arg( array(
+                       'page' => 'custom-header',
+                       'step' => 2,
+                       '_wpnonce-custom-header-upload' => wp_create_nonce('custom-header-upload'),
+               ), admin_url('themes.php') ) );
        ?>
        <p>
                <label for="choose-from-library-link"><?php _e( 'Or choose an image from your media library:' ); ?></label><br />
-               <a id="choose-from-library-link" class="button thickbox" href="<?php echo esc_url( $image_library_url ); ?>"><?php _e( 'Choose Image' ); ?></a>
+               <a id="choose-from-library-link" class="button"
+                       data-update-link="<?php echo esc_attr( $modal_update_href ); ?>"
+                       data-choose="<?php esc_attr_e( 'Choose a Custom Header' ); ?>"
+                       data-update="<?php esc_attr_e( 'Set as header' ); ?>"><?php _e( 'Choose Image' ); ?></a>
        </p>
        </form>
 </td>
@@ -570,7 +543,7 @@ var farbtastic;
 </tbody>
 </table>
 
-<form method="post" action="<?php echo esc_attr( add_query_arg( 'step', 1 ) ) ?>">
+<form method="post" action="<?php echo esc_url( add_query_arg( 'step', 1 ) ) ?>">
 <table class="form-table">
 <tbody>
        <?php if ( get_uploaded_header_images() ) : ?>
@@ -641,31 +614,29 @@ var farbtastic;
 <th scope="row"><?php _e( 'Text Color' ); ?></th>
 <td>
        <p>
-<?php if ( display_header_text() ) : ?>
-               <input type="text" name="text-color" id="text-color" value="#<?php echo esc_attr( get_header_textcolor() ); ?>" />
-<?php else : ?>
-               <input type="text" name="text-color" id="text-color" value="#<?php echo esc_attr( get_theme_support( 'custom-header', 'default-text-color' ) ); ?>" />
-<?php endif; ?>
-               <a href="#" class="hide-if-no-js" id="pickcolor"><?php _e( 'Select a Color' ); ?></a>
+<?php
+$header_textcolor = display_header_text() ? get_header_textcolor() : get_theme_support( 'custom-header', 'default-text-color' );
+$default_color = '';
+if ( current_theme_supports( 'custom-header', 'default-text-color' ) ) {
+       $default_color = '#' . get_theme_support( 'custom-header', 'default-text-color' );
+       $default_color_attr = ' data-default-color="' . esc_attr( $default_color ) . '"';
+       echo '<input type="text" name="text-color" id="text-color" value="#' . esc_attr( $header_textcolor ) . '"' . $default_color_attr . ' />';
+       if ( $default_color )
+               echo ' <span class="description hide-if-js">' . sprintf( _x( 'Default: %s', 'color' ), $default_color ) . '</span>';
+}
+?>
        </p>
-       <div id="color-picker" style="z-index: 100; background:#eee; border:1px solid #ccc; position:absolute; display:none;"></div>
-</td>
-</tr>
-
-       <?php if ( current_theme_supports( 'custom-header', 'default-text-color' ) && get_theme_mod( 'header_textcolor' ) ) { ?>
-<tr valign="top">
-<th scope="row"><?php _e('Reset Text Color'); ?></th>
-<td>
-       <p><?php _e( 'This will restore the original header text. You will not be able to restore any customizations.' ) ?></p>
-       <?php submit_button( __( 'Restore Original Header Text' ), 'button', 'resettext', false ); ?>
 </td>
 </tr>
-       <?php } ?>
-
 </tbody>
 </table>
 <?php endif;
 
+/**
+ * Fires just before the submit button in the custom header options form.
+ *
+ * @since 3.1.0
+ */
 do_action( 'custom_header_options' );
 
 wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?>
@@ -699,8 +670,8 @@ wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?>
                        list( $width, $height, $type, $attr ) = getimagesize( $file );
                } else {
                        $data = wp_get_attachment_metadata( $attachment_id );
-                       $height = $data[ 'height' ];
-                       $width = $data[ 'width' ];
+                       $height = isset( $data[ 'height' ] ) ? $data[ 'height' ] : 0;
+                       $width = isset( $data[ 'width' ] ) ? $data[ 'width' ] : 0;
                        unset( $data );
                }
 
@@ -723,7 +694,16 @@ wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?>
 
                        $this->set_header_image( compact( 'url', 'attachment_id', 'width', 'height' ) );
 
-                       do_action('wp_create_file_in_uploads', $file, $attachment_id); // For replication
+                       /**
+                        * Fires after the header image is set or an error is returned.
+                        *
+                        * @since 2.1.0
+                        *
+                        * @param string $file          Path to the file.
+                        * @param int    $attachment_id Attachment ID.
+                        */
+                       do_action( 'wp_create_file_in_uploads', $file, $attachment_id ); // For replication
+
                        return $this->finished();
                } elseif ( $width > $max_width ) {
                        $oitar = $width / $max_width;
@@ -731,7 +711,8 @@ wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?>
                        if ( ! $image || is_wp_error( $image ) )
                                wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) );
 
-                       $image = apply_filters('wp_create_file_in_uploads', $image, $attachment_id); // For replication
+                       /** This filter is documented in wp-admin/custom-header.php */
+                       $image = apply_filters( 'wp_create_file_in_uploads', $image, $attachment_id ); // For replication
 
                        $url = str_replace(basename($url), basename($image), $url);
                        $width = $width / $oitar;
@@ -742,10 +723,9 @@ wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?>
                ?>
 
 <div class="wrap">
-<?php screen_icon(); ?>
 <h2><?php _e( 'Crop Header Image' ); ?></h2>
 
-<form method="post" action="<?php echo esc_attr(add_query_arg('step', 3)); ?>">
+<form method="post" action="<?php echo esc_url(add_query_arg('step', 3)); ?>">
        <p class="hide-if-no-js"><?php _e('Choose the part of the image you want to use as your header.'); ?></p>
        <p class="hide-if-js"><strong><?php _e( 'You need Javascript to choose a part of the image.'); ?></strong></p>
 
@@ -767,7 +747,7 @@ wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?>
        <p class="submit">
        <?php submit_button( __( 'Crop and Publish' ), 'primary', 'submit', false ); ?>
        <?php
-       if ( isset( $oitar ) && 1 == $oitar )
+       if ( isset( $oitar ) && 1 == $oitar && ( current_theme_supports( 'custom-header', 'flex-height' ) || current_theme_supports( 'custom-header', 'flex-width' ) ) )
                submit_button( __( 'Skip Cropping, Publish Image as Is' ), 'secondary', 'skip-cropping', false );
        ?>
        </p>
@@ -784,7 +764,13 @@ wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?>
         */
        function step_2_manage_upload() {
                $overrides = array('test_form' => false);
-               $file = wp_handle_upload($_FILES['import'], $overrides);
+
+               $uploaded_file = $_FILES['import'];
+               $wp_filetype = wp_check_filetype_and_ext( $uploaded_file['tmp_name'], $uploaded_file['name'], false );
+               if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) )
+                       wp_die( __( 'The uploaded file is not a valid image. Please try again.' ) );
+
+               $file = wp_handle_upload($uploaded_file, $overrides);
 
                if ( isset($file['error']) )
                        wp_die( $file['error'],  __( 'Image Upload Error' ) );
@@ -819,6 +805,9 @@ wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?>
                if ( ! current_theme_supports( 'custom-header', 'uploads' ) )
                        wp_die( __( 'Cheatin&#8217; uh?' ) );
 
+               if ( ! empty( $_POST['skip-cropping'] ) && ! ( current_theme_supports( 'custom-header', 'flex-height' ) || current_theme_supports( 'custom-header', 'flex-width' ) ) )
+                       wp_die( __( 'Cheatin&#8217; uh?' ) );
+
                if ( $_POST['oitar'] > 1 ) {
                        $_POST['x1'] = $_POST['x1'] * $_POST['oitar'];
                        $_POST['y1'] = $_POST['y1'] * $_POST['oitar'];
@@ -863,7 +852,8 @@ wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?>
                if ( ! $cropped || is_wp_error( $cropped ) )
                        wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) );
 
-               $cropped = apply_filters('wp_create_file_in_uploads', $cropped, $attachment_id); // For replication
+               /** This filter is documented in wp-admin/custom-header.php */
+               $cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication
 
                $parent = get_post($attachment_id);
                $parent_url = $parent->guid;
@@ -894,10 +884,21 @@ wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?>
 
                // cleanup
                $medium = str_replace( basename( $original ), 'midsize-' . basename( $original ), $original );
-               if ( file_exists( $medium ) )
+               if ( file_exists( $medium ) ) {
+                       /**
+                        * Filter the path of the file to delete.
+                        *
+                        * @since 2.1.0
+                        *
+                        * @param string $medium Path to the file to delete.
+                        */
                        @unlink( apply_filters( 'wp_delete_file', $medium ) );
-               if ( empty( $_POST['create-new-attachment'] ) && empty( $_POST['skip-cropping'] ) )
+               }
+
+               if ( empty( $_POST['create-new-attachment'] ) && empty( $_POST['skip-cropping'] ) ) {
+                       /** This filter is documented in wp-admin/custom-header.php */
                        @unlink( apply_filters( 'wp_delete_file', $original ) );
+               }
 
                return $this->finished();
        }
@@ -930,32 +931,21 @@ wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?>
        }
 
        /**
-        * Replace default attachment actions with "Set as header" link.
+        * Unused since 3.5.0.
         *
         * @since 3.4.0
         */
-       function attachment_fields_to_edit( $form_fields, $post ) {
-               $form_fields = array();
-               $href = esc_url(add_query_arg(array(
-                       'page' => 'custom-header',
-                       'step' => 2,
-                       '_wpnonce-custom-header-upload' => wp_create_nonce('custom-header-upload'),
-                       'file' => $post->ID
-               ), admin_url('themes.php')));
-
-               $form_fields['buttons'] = array( 'tr' => '<tr class="submit"><td></td><td><a data-location="' . $href . '" class="wp-set-header">' . __( 'Set as header' ) . '</a></td></tr>' );
-               $form_fields['context'] = array( 'input' => 'hidden', 'value' => 'custom-header' );
-
+       function attachment_fields_to_edit( $form_fields ) {
                return $form_fields;
        }
 
        /**
-        * Leave only "Media Library" tab in the uploader window.
+        * Unused since 3.5.0.
         *
         * @since 3.4.0
         */
-       function filter_upload_tabs() {
-               return array( 'library' => __('Media Library') );
+       function filter_upload_tabs( $tabs ) {
+               return $tabs;
        }
 
        /**
@@ -1039,6 +1029,7 @@ wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?>
 
                $default = sprintf( $default, get_template_directory_uri(), get_stylesheet_directory_uri() );
 
+               $default_data = array();
                foreach ( $this->default_headers as $header => $details ) {
                        if ( $details['url'] == $default ) {
                                $default_data = $details;