]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-admin/custom-background.php
WordPress 4.7-scripts
[autoinstalls/wordpress.git] / wp-admin / custom-background.php
index fc320f9f416045cd8c090ce71df0226fb9d04bdb..bea4084c3058d7ce79f6e0bcce6a98ff4383d774 100644 (file)
@@ -18,7 +18,7 @@ class Custom_Background {
        /**
         * Callback for administration header.
         *
        /**
         * Callback for administration header.
         *
-        * @var callback
+        * @var callable
         * @since 3.0.0
         */
        public $admin_header_callback;
         * @since 3.0.0
         */
        public $admin_header_callback;
@@ -26,12 +26,16 @@ class Custom_Background {
        /**
         * Callback for header div.
         *
        /**
         * Callback for header div.
         *
-        * @var callback
+        * @var callable
         * @since 3.0.0
         */
        public $admin_image_div_callback;
 
        /**
         * @since 3.0.0
         */
        public $admin_image_div_callback;
 
        /**
+        * Used to trigger a success message when settings updated and set to true.
+        *
+        * @since 3.0.0
+        * @access private
         * @var bool
         */
        private $updated;
         * @var bool
         */
        private $updated;
@@ -40,8 +44,8 @@ class Custom_Background {
         * Constructor - Register administration header callback.
         *
         * @since 3.0.0
         * Constructor - Register administration header callback.
         *
         * @since 3.0.0
-        * @param callback $admin_header_callback
-        * @param callback $admin_image_div_callback Optional custom image div output callback.
+        * @param callable $admin_header_callback
+        * @param callable $admin_image_div_callback Optional custom image div output callback.
         */
        public function __construct($admin_header_callback = '', $admin_image_div_callback = '') {
                $this->admin_header_callback = $admin_header_callback;
         */
        public function __construct($admin_header_callback = '', $admin_image_div_callback = '') {
                $this->admin_header_callback = $admin_header_callback;
@@ -93,8 +97,8 @@ class Custom_Background {
 
                get_current_screen()->set_help_sidebar(
                        '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
 
                get_current_screen()->set_help_sidebar(
                        '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
-                       '<p>' . __( '<a href="https://codex.wordpress.org/Appearance_Background_Screen" target="_blank">Documentation on Custom Background</a>' ) . '</p>' .
-                       '<p>' . __( '<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>'
+                       '<p>' . __( '<a href="https://codex.wordpress.org/Appearance_Background_Screen">Documentation on Custom Background</a>' ) . '</p>' .
+                       '<p>' . __( '<a href="https://wordpress.org/support/">Support Forums</a>' ) . '</p>'
                );
 
                wp_enqueue_media();
                );
 
                wp_enqueue_media();
@@ -108,7 +112,6 @@ class Custom_Background {
         * @since 3.0.0
         */
        public function take_action() {
         * @since 3.0.0
         */
        public function take_action() {
-
                if ( empty($_POST) )
                        return;
 
                if ( empty($_POST) )
                        return;
 
@@ -130,31 +133,73 @@ class Custom_Background {
                        return;
                }
 
                        return;
                }
 
-               if ( isset($_POST['background-repeat']) ) {
-                       check_admin_referer('custom-background');
-                       if ( in_array($_POST['background-repeat'], array('repeat', 'no-repeat', 'repeat-x', 'repeat-y')) )
-                               $repeat = $_POST['background-repeat'];
-                       else
-                               $repeat = 'repeat';
-                       set_theme_mod('background_repeat', $repeat);
+               if ( isset( $_POST['background-preset'] ) ) {
+                       check_admin_referer( 'custom-background' );
+
+                       if ( in_array( $_POST['background-preset'], array( 'default', 'fill', 'fit', 'repeat', 'custom' ), true ) ) {
+                               $preset = $_POST['background-preset'];
+                       } else {
+                               $preset = 'default';
+                       }
+
+                       set_theme_mod( 'background_preset', $preset );
                }
 
                }
 
-               if ( isset($_POST['background-position-x']) ) {
-                       check_admin_referer('custom-background');
-                       if ( in_array($_POST['background-position-x'], array('center', 'right', 'left')) )
-                               $position = $_POST['background-position-x'];
-                       else
-                               $position = 'left';
-                       set_theme_mod('background_position_x', $position);
+               if ( isset( $_POST['background-position'] ) ) {
+                       check_admin_referer( 'custom-background' );
+
+                       $position = explode( ' ', $_POST['background-position'] );
+
+                       if ( in_array( $position[0], array( 'left', 'center', 'right' ), true ) ) {
+                               $position_x = $position[0];
+                       } else {
+                               $position_x = 'left';
+                       }
+
+                       if ( in_array( $position[1], array( 'top', 'center', 'bottom' ), true ) ) {
+                               $position_y = $position[1];
+                       } else {
+                               $position_y = 'top';
+                       }
+
+                       set_theme_mod( 'background_position_x', $position_x );
+                       set_theme_mod( 'background_position_y', $position_y );
                }
 
                }
 
-               if ( isset($_POST['background-attachment']) ) {
-                       check_admin_referer('custom-background');
-                       if ( in_array($_POST['background-attachment'], array('fixed', 'scroll')) )
-                               $attachment = $_POST['background-attachment'];
-                       else
-                               $attachment = 'fixed';
-                       set_theme_mod('background_attachment', $attachment);
+               if ( isset( $_POST['background-size'] ) ) {
+                       check_admin_referer( 'custom-background' );
+
+                       if ( in_array( $_POST['background-size'], array( 'auto', 'contain', 'cover' ), true ) ) {
+                               $size = $_POST['background-size'];
+                       } else {
+                               $size = 'auto';
+                       }
+
+                       set_theme_mod( 'background_size', $size );
+               }
+
+               if ( isset( $_POST['background-repeat'] ) ) {
+                       check_admin_referer( 'custom-background' );
+
+                       $repeat = $_POST['background-repeat'];
+
+                       if ( 'no-repeat' !== $repeat ) {
+                               $repeat = 'repeat';
+                       }
+
+                       set_theme_mod( 'background_repeat', $repeat );
+               }
+
+               if ( isset( $_POST['background-attachment'] ) ) {
+                       check_admin_referer( 'custom-background' );
+
+                       $attachment = $_POST['background-attachment'];
+
+                       if ( 'fixed' !== $attachment ) {
+                               $attachment = 'scroll';
+                       }
+
+                       set_theme_mod( 'background_attachment', $attachment );
                }
 
                if ( isset($_POST['background-color']) ) {
                }
 
                if ( isset($_POST['background-color']) ) {
@@ -177,7 +222,7 @@ class Custom_Background {
        public function admin_page() {
 ?>
 <div class="wrap" id="custom-background">
        public function admin_page() {
 ?>
 <div class="wrap" id="custom-background">
-<h2><?php _e( 'Custom Background' ); ?></h2>
+<h1><?php _e( 'Custom Background' ); ?></h1>
 
 <?php if ( current_user_can( 'customize' ) ) { ?>
 <div class="notice notice-info hide-if-no-customize">
 
 <?php if ( current_user_can( 'customize' ) ) { ?>
 <div class="notice notice-info hide-if-no-customize">
@@ -216,11 +261,18 @@ class Custom_Background {
                $background_image_thumb = get_background_image();
                if ( $background_image_thumb ) {
                        $background_image_thumb = esc_url( set_url_scheme( get_theme_mod( 'background_image_thumb', str_replace( '%', '%%', $background_image_thumb ) ) ) );
                $background_image_thumb = get_background_image();
                if ( $background_image_thumb ) {
                        $background_image_thumb = esc_url( set_url_scheme( get_theme_mod( 'background_image_thumb', str_replace( '%', '%%', $background_image_thumb ) ) ) );
+                       $background_position_x = get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) );
+                       $background_position_y = get_theme_mod( 'background_position_y', get_theme_support( 'custom-background', 'default-position-y' ) );
+                       $background_size = get_theme_mod( 'background_size', get_theme_support( 'custom-background', 'default-size' ) );
+                       $background_repeat = get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'default-repeat' ) );
+                       $background_attachment = get_theme_mod( 'background_attachment', get_theme_support( 'custom-background', 'default-attachment' ) );
 
                        // Background-image URL must be single quote, see below.
 
                        // Background-image URL must be single quote, see below.
-                       $background_styles .= ' background-image: url(\'' . $background_image_thumb . '\');'
-                               . ' background-repeat: ' . get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'default-repeat' ) ) . ';'
-                               . ' background-position: top ' . get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) );
+                       $background_styles .= " background-image: url('$background_image_thumb');"
+                               . " background-size: $background_size;"
+                               . " background-position: $background_position_x $background_position_y;"
+                               . " background-repeat: $background_repeat;"
+                               . " background-attachment: $background_attachment;";
                }
        ?>
        <div id="custom-background-image" style="<?php echo $background_styles; ?>"><?php // must be double quote, see above ?>
                }
        ?>
        <div id="custom-background-image" style="<?php echo $background_styles; ?>"><?php // must be double quote, see above ?>
@@ -239,7 +291,7 @@ class Custom_Background {
 <td>
 <form method="post">
 <?php wp_nonce_field('custom-background-remove', '_wpnonce-custom-background-remove'); ?>
 <td>
 <form method="post">
 <?php wp_nonce_field('custom-background-remove', '_wpnonce-custom-background-remove'); ?>
-<?php submit_button( __( 'Remove Background Image' ), 'button', 'remove-background', false ); ?><br/>
+<?php submit_button( __( 'Remove Background Image' ), '', 'remove-background', false ); ?><br/>
 <?php _e('This will remove the background image. You will not be able to restore any customizations.') ?>
 </form>
 </td>
 <?php _e('This will remove the background image. You will not be able to restore any customizations.') ?>
 </form>
 </td>
@@ -253,13 +305,14 @@ class Custom_Background {
 <td>
 <form method="post">
 <?php wp_nonce_field('custom-background-reset', '_wpnonce-custom-background-reset'); ?>
 <td>
 <form method="post">
 <?php wp_nonce_field('custom-background-reset', '_wpnonce-custom-background-reset'); ?>
-<?php submit_button( __( 'Restore Original Image' ), 'button', 'reset-background', false ); ?><br/>
+<?php submit_button( __( 'Restore Original Image' ), '', 'reset-background', false ); ?><br/>
 <?php _e('This will restore the original background image. You will not be able to restore any customizations.') ?>
 </form>
 </td>
 </tr>
 <?php endif; ?>
 
 <?php _e('This will restore the original background image. You will not be able to restore any customizations.') ?>
 </form>
 </td>
 </tr>
 <?php endif; ?>
 
+<?php if ( current_user_can( 'upload_files' ) ): ?>
 <tr>
 <th scope="row"><?php _e('Select Image'); ?></th>
 <td><form enctype="multipart/form-data" id="upload-form" class="wp-upload-form" method="post">
 <tr>
 <th scope="row"><?php _e('Select Image'); ?></th>
 <td><form enctype="multipart/form-data" id="upload-form" class="wp-upload-form" method="post">
@@ -268,7 +321,7 @@ class Custom_Background {
                <input type="file" id="upload" name="import" />
                <input type="hidden" name="action" value="save" />
                <?php wp_nonce_field( 'custom-background-upload', '_wpnonce-custom-background-upload' ); ?>
                <input type="file" id="upload" name="import" />
                <input type="hidden" name="action" value="save" />
                <?php wp_nonce_field( 'custom-background-upload', '_wpnonce-custom-background-upload' ); ?>
-               <?php submit_button( __( 'Upload' ), 'button', 'submit', false ); ?>
+               <?php submit_button( __( 'Upload' ), '', 'submit', false ); ?>
        </p>
        <p>
                <label for="choose-from-library-link"><?php _e( 'Or choose an image from your media library:' ); ?></label><br />
        </p>
        <p>
                <label for="choose-from-library-link"><?php _e( 'Or choose an image from your media library:' ); ?></label><br />
@@ -279,53 +332,85 @@ class Custom_Background {
        </form>
 </td>
 </tr>
        </form>
 </td>
 </tr>
+<?php endif; ?>
 </tbody>
 </table>
 
 </tbody>
 </table>
 
-<h3><?php _e('Display Options') ?></h3>
+<h3><?php _e( 'Display Options' ); ?></h3>
 <form method="post">
 <table class="form-table">
 <tbody>
 <?php if ( get_background_image() ) : ?>
 <form method="post">
 <table class="form-table">
 <tbody>
 <?php if ( get_background_image() ) : ?>
+<input name="background-preset" type="hidden" value="custom">
+
+<?php
+$background_position = sprintf(
+       '%s %s',
+       get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) ),
+       get_theme_mod( 'background_position_y', get_theme_support( 'custom-background', 'default-position-y' ) )
+);
+
+$background_position_options = array(
+       array(
+               'left top'   => array( 'label' => __( 'Top Left' ), 'icon' => 'dashicons dashicons-arrow-left-alt' ),
+               'center top' => array( 'label' => __( 'Top' ), 'icon' => 'dashicons dashicons-arrow-up-alt' ),
+               'right top'  => array( 'label' => __( 'Top Right' ), 'icon' => 'dashicons dashicons-arrow-right-alt' ),
+       ),
+       array(
+               'left center'   => array( 'label' => __( 'Left' ), 'icon' => 'dashicons dashicons-arrow-left-alt' ),
+               'center center' => array( 'label' => __( 'Center' ), 'icon' => 'background-position-center-icon' ),
+               'right center'  => array( 'label' => __( 'Right' ), 'icon' => 'dashicons dashicons-arrow-right-alt' ),
+       ),
+       array(
+               'left bottom'   => array( 'label' => __( 'Bottom Left' ), 'icon' => 'dashicons dashicons-arrow-left-alt' ),
+               'center bottom' => array( 'label' => __( 'Bottom' ), 'icon' => 'dashicons dashicons-arrow-down-alt' ),
+               'right bottom'  => array( 'label' => __( 'Bottom Right' ), 'icon' => 'dashicons dashicons-arrow-right-alt' ),
+       ),
+);
+?>
+<tr>
+<th scope="row"><?php _e( 'Image Position' ); ?></th>
+<td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Image Position' ); ?></span></legend>
+<div class="background-position-control">
+<?php foreach ( $background_position_options as $group ) : ?>
+       <div class="button-group">
+       <?php foreach ( $group as $value => $input ) : ?>
+               <label>
+                       <input class="screen-reader-text" name="background-position" type="radio" value="<?php echo esc_attr( $value ); ?>"<?php checked( $value, $background_position ); ?>>
+                       <span class="button display-options position"><span class="<?php echo esc_attr( $input['icon'] ); ?>" aria-hidden="true"></span></span>
+                       <span class="screen-reader-text"><?php echo $input['label']; ?></span>
+               </label>
+       <?php endforeach; ?>
+       </div>
+<?php endforeach; ?>
+</div>
+</fieldset></td>
+</tr>
+
 <tr>
 <tr>
-<th scope="row"><?php _e( 'Position' ); ?></th>
-<td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Position' ); ?></span></legend>
-<label>
-<input name="background-position-x" type="radio" value="left"<?php checked( 'left', get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) ) ); ?> />
-<?php _e('Left') ?>
-</label>
-<label>
-<input name="background-position-x" type="radio" value="center"<?php checked( 'center', get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) ) ); ?> />
-<?php _e('Center') ?>
-</label>
-<label>
-<input name="background-position-x" type="radio" value="right"<?php checked( 'right', get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) ) ); ?> />
-<?php _e('Right') ?>
-</label>
+<th scope="row"><label for="background-size"><?php _e( 'Image Size' ); ?></label></th>
+<td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Image Size' ); ?></span></legend>
+<select id="background-size" name="background-size">
+<option value="auto"<?php selected( 'auto', get_theme_mod( 'background_size', get_theme_support( 'custom-background', 'default-size' ) ) ); ?>><?php _ex( 'Original', 'Original Size' ); ?></option>
+<option value="contain"<?php selected( 'contain', get_theme_mod( 'background_size', get_theme_support( 'custom-background', 'default-size' ) ) ); ?>><?php _e( 'Fit to Screen' ); ?></option>
+<option value="cover"<?php selected( 'cover', get_theme_mod( 'background_size', get_theme_support( 'custom-background', 'default-size' ) ) ); ?>><?php _e( 'Fill Screen' ); ?></option>
+</select>
 </fieldset></td>
 </tr>
 
 <tr>
 </fieldset></td>
 </tr>
 
 <tr>
-<th scope="row"><?php _e( 'Repeat' ); ?></th>
-<td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Repeat' ); ?></span></legend>
-<label><input type="radio" name="background-repeat" value="no-repeat"<?php checked( 'no-repeat', get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'default-repeat' ) ) ); ?> /> <?php _e('No Repeat'); ?></label>
-       <label><input type="radio" name="background-repeat" value="repeat"<?php checked( 'repeat', get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'default-repeat' ) ) ); ?> /> <?php _e('Tile'); ?></label>
-       <label><input type="radio" name="background-repeat" value="repeat-x"<?php checked( 'repeat-x', get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'default-repeat' ) ) ); ?> /> <?php _e('Tile Horizontally'); ?></label>
-       <label><input type="radio" name="background-repeat" value="repeat-y"<?php checked( 'repeat-y', get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'default-repeat' ) ) ); ?> /> <?php _e('Tile Vertically'); ?></label>
+<th scope="row"><?php _ex( 'Repeat', 'Background Repeat' ); ?></th>
+<td><fieldset><legend class="screen-reader-text"><span><?php _ex( 'Repeat', 'Background Repeat' ); ?></span></legend>
+<input name="background-repeat" type="hidden" value="no-repeat">
+<label><input type="checkbox" name="background-repeat" value="repeat"<?php checked( 'repeat', get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'default-repeat' ) ) ); ?>> <?php _e( 'Repeat Background Image' ); ?></label>
 </fieldset></td>
 </tr>
 
 <tr>
 </fieldset></td>
 </tr>
 
 <tr>
-<th scope="row"><?php _ex( 'Attachment', 'Background Attachment' ); ?></th>
-<td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Attachment' ); ?></span></legend>
-<label>
-<input name="background-attachment" type="radio" value="scroll" <?php checked( 'scroll', get_theme_mod( 'background_attachment', get_theme_support( 'custom-background', 'default-attachment' ) ) ); ?> />
-<?php _e( 'Scroll' ); ?>
-</label>
-<label>
-<input name="background-attachment" type="radio" value="fixed" <?php checked( 'fixed', get_theme_mod( 'background_attachment', get_theme_support( 'custom-background', 'default-attachment' ) ) ); ?> />
-<?php _e( 'Fixed' ); ?>
-</label>
+<th scope="row"><?php _ex( 'Scroll', 'Background Scroll' ); ?></th>
+<td><fieldset><legend class="screen-reader-text"><span><?php _ex( 'Scroll', 'Background Scroll' ); ?></span></legend>
+<input name="background-attachment" type="hidden" value="fixed">
+<label><input name="background-attachment" type="checkbox" value="scroll" <?php checked( 'scroll', get_theme_mod( 'background_attachment', get_theme_support( 'custom-background', 'default-attachment' ) ) ); ?>> <?php _e( 'Scroll with Page' ); ?></label>
 </fieldset></td>
 </tr>
 <?php endif; // get_background_image() ?>
 </fieldset></td>
 </tr>
 <?php endif; // get_background_image() ?>
@@ -337,7 +422,7 @@ $default_color = '';
 if ( current_theme_supports( 'custom-background', 'default-color' ) )
        $default_color = ' data-default-color="#' . esc_attr( get_theme_support( 'custom-background', 'default-color' ) ) . '"';
 ?>
 if ( current_theme_supports( 'custom-background', 'default-color' ) )
        $default_color = ' data-default-color="#' . esc_attr( get_theme_support( 'custom-background', 'default-color' ) ) . '"';
 ?>
-<input type="text" name="background-color" id="background-color" value="#<?php echo esc_attr( get_background_color() ); ?>"<?php echo $default_color ?> />
+<input type="text" name="background-color" id="background-color" value="#<?php echo esc_attr( get_background_color() ); ?>"<?php echo $default_color ?>>
 </fieldset></td>
 </tr>
 </tbody>
 </fieldset></td>
 </tr>
 </tbody>
@@ -357,7 +442,6 @@ if ( current_theme_supports( 'custom-background', 'default-color' ) )
         * @since 3.0.0
         */
        public function handle_upload() {
         * @since 3.0.0
         */
        public function handle_upload() {
-
                if ( empty($_FILES) )
                        return;
 
                if ( empty($_FILES) )
                        return;
 
@@ -406,7 +490,7 @@ if ( current_theme_supports( 'custom-background', 'default-color' ) )
        }
 
        /**
        }
 
        /**
-        * AJAX handler for adding custom background context to an attachment.
+        * Ajax handler for adding custom background context to an attachment.
         *
         * Triggered when the user adds a new background image from the
         * Media Manager.
         *
         * Triggered when the user adds a new background image from the
         * Media Manager.
@@ -434,6 +518,9 @@ if ( current_theme_supports( 'custom-background', 'default-color' ) )
         *
         * @since 3.4.0
         * @deprecated 3.5.0
         *
         * @since 3.4.0
         * @deprecated 3.5.0
+        *
+        * @param array $form_fields
+        * @return array $form_fields
         */
        public function attachment_fields_to_edit( $form_fields ) {
                return $form_fields;
         */
        public function attachment_fields_to_edit( $form_fields ) {
                return $form_fields;
@@ -443,6 +530,9 @@ if ( current_theme_supports( 'custom-background', 'default-color' ) )
         *
         * @since 3.4.0
         * @deprecated 3.5.0
         *
         * @since 3.4.0
         * @deprecated 3.5.0
+        *
+        * @param array $tabs
+        * @return array $tabs
         */
        public function filter_upload_tabs( $tabs ) {
                return $tabs;
         */
        public function filter_upload_tabs( $tabs ) {
                return $tabs;