wp/wp-admin/custom-background.php
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
equal deleted inserted replaced
4:346c88efed21 5:5e2f62d02dcd
    18 	/**
    18 	/**
    19 	 * Callback for administration header.
    19 	 * Callback for administration header.
    20 	 *
    20 	 *
    21 	 * @var callback
    21 	 * @var callback
    22 	 * @since 3.0.0
    22 	 * @since 3.0.0
    23 	 * @access private
    23 	 */
    24 	 */
    24 	public $admin_header_callback;
    25 	var $admin_header_callback;
       
    26 
    25 
    27 	/**
    26 	/**
    28 	 * Callback for header div.
    27 	 * Callback for header div.
    29 	 *
    28 	 *
    30 	 * @var callback
    29 	 * @var callback
    31 	 * @since 3.0.0
    30 	 * @since 3.0.0
    32 	 * @access private
    31 	 */
    33 	 */
    32 	public $admin_image_div_callback;
    34 	var $admin_image_div_callback;
    33 
    35 
    34 	/**
    36 	/**
    35 	 * @var bool
    37 	 * Holds the page menu hook.
    36 	 */
    38 	 *
    37 	private $updated;
    39 	 * @var string
       
    40 	 * @since 3.0.0
       
    41 	 * @access private
       
    42 	 */
       
    43 	var $page = '';
       
    44 
    38 
    45 	/**
    39 	/**
    46 	 * Constructor - Register administration header callback.
    40 	 * Constructor - Register administration header callback.
    47 	 *
    41 	 *
    48 	 * @since 3.0.0
    42 	 * @since 3.0.0
    49 	 * @param callback $admin_header_callback
    43 	 * @param callback $admin_header_callback
    50 	 * @param callback $admin_image_div_callback Optional custom image div output callback.
    44 	 * @param callback $admin_image_div_callback Optional custom image div output callback.
    51 	 * @return Custom_Background
    45 	 */
    52 	 */
    46 	public function __construct($admin_header_callback = '', $admin_image_div_callback = '') {
    53 	function __construct($admin_header_callback = '', $admin_image_div_callback = '') {
       
    54 		$this->admin_header_callback = $admin_header_callback;
    47 		$this->admin_header_callback = $admin_header_callback;
    55 		$this->admin_image_div_callback = $admin_image_div_callback;
    48 		$this->admin_image_div_callback = $admin_image_div_callback;
    56 
    49 
    57 		add_action( 'admin_menu', array( $this, 'init' ) );
    50 		add_action( 'admin_menu', array( $this, 'init' ) );
       
    51 
       
    52 		add_action( 'wp_ajax_custom-background-add', array( $this, 'ajax_background_add' ) );
       
    53 
       
    54 		// Unused since 3.5.0.
    58 		add_action( 'wp_ajax_set-background-image', array( $this, 'wp_set_background_image' ) );
    55 		add_action( 'wp_ajax_set-background-image', array( $this, 'wp_set_background_image' ) );
    59 	}
    56 	}
    60 
    57 
    61 	/**
    58 	/**
    62 	 * Set up the hooks for the Custom Background admin page.
    59 	 * Set up the hooks for the Custom Background admin page.
    63 	 *
    60 	 *
    64 	 * @since 3.0.0
    61 	 * @since 3.0.0
    65 	 */
    62 	 */
    66 	function init() {
    63 	public function init() {
    67 		if ( ! current_user_can('edit_theme_options') )
    64 		$page = add_theme_page( __( 'Background' ), __( 'Background' ), 'edit_theme_options', 'custom-background', array( $this, 'admin_page' ) );
       
    65 		if ( ! $page ) {
    68 			return;
    66 			return;
    69 
    67 		}
    70 		$this->page = $page = add_theme_page(__('Background'), __('Background'), 'edit_theme_options', 'custom-background', array($this, 'admin_page'));
    68 
    71 
    69 		add_action( "load-$page", array( $this, 'admin_load' ) );
    72 		add_action("load-$page", array($this, 'admin_load'));
    70 		add_action( "load-$page", array( $this, 'take_action' ), 49 );
    73 		add_action("load-$page", array($this, 'take_action'), 49);
    71 		add_action( "load-$page", array( $this, 'handle_upload' ), 49 );
    74 		add_action("load-$page", array($this, 'handle_upload'), 49);
    72 
    75 
    73 		if ( $this->admin_header_callback ) {
    76 		if ( $this->admin_header_callback )
    74 			add_action( "admin_head-$page", $this->admin_header_callback, 51 );
    77 			add_action("admin_head-$page", $this->admin_header_callback, 51);
    75 		}
    78 	}
    76 	}
    79 
    77 
    80 	/**
    78 	/**
    81 	 * Set up the enqueue for the CSS & JavaScript files.
    79 	 * Set up the enqueue for the CSS & JavaScript files.
    82 	 *
    80 	 *
    83 	 * @since 3.0.0
    81 	 * @since 3.0.0
    84 	 */
    82 	 */
    85 	function admin_load() {
    83 	public function admin_load() {
    86 		get_current_screen()->add_help_tab( array(
    84 		get_current_screen()->add_help_tab( array(
    87 			'id'      => 'overview',
    85 			'id'      => 'overview',
    88 			'title'   => __('Overview'),
    86 			'title'   => __('Overview'),
    89 			'content' =>
    87 			'content' =>
    90 				'<p>' . __( 'You can customize the look of your site without touching any of your theme&#8217;s code by using a custom background. Your background can be an image or a color.' ) . '</p>' .
    88 				'<p>' . __( 'You can customize the look of your site without touching any of your theme&#8217;s code by using a custom background. Your background can be an image or a color.' ) . '</p>' .
    93 				'<p>' . __( 'Don&#8217;t forget to click on the Save Changes button when you are finished.' ) . '</p>'
    91 				'<p>' . __( 'Don&#8217;t forget to click on the Save Changes button when you are finished.' ) . '</p>'
    94 		) );
    92 		) );
    95 
    93 
    96 		get_current_screen()->set_help_sidebar(
    94 		get_current_screen()->set_help_sidebar(
    97 			'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
    95 			'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
    98 			'<p>' . __( '<a href="http://codex.wordpress.org/Appearance_Background_Screen" target="_blank">Documentation on Custom Background</a>' ) . '</p>' .
    96 			'<p>' . __( '<a href="https://codex.wordpress.org/Appearance_Background_Screen" target="_blank">Documentation on Custom Background</a>' ) . '</p>' .
    99 			'<p>' . __( '<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>'
    97 			'<p>' . __( '<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>'
   100 		);
    98 		);
   101 
    99 
   102 		wp_enqueue_media();
   100 		wp_enqueue_media();
   103 		wp_enqueue_script('custom-background');
   101 		wp_enqueue_script('custom-background');
   104 		wp_enqueue_style('wp-color-picker');
   102 		wp_enqueue_style('wp-color-picker');
   107 	/**
   105 	/**
   108 	 * Execute custom background modification.
   106 	 * Execute custom background modification.
   109 	 *
   107 	 *
   110 	 * @since 3.0.0
   108 	 * @since 3.0.0
   111 	 */
   109 	 */
   112 	function take_action() {
   110 	public function take_action() {
   113 
   111 
   114 		if ( empty($_POST) )
   112 		if ( empty($_POST) )
   115 			return;
   113 			return;
   116 
   114 
   117 		if ( isset($_POST['reset-background']) ) {
   115 		if ( isset($_POST['reset-background']) ) {
   174 	/**
   172 	/**
   175 	 * Display the custom background page.
   173 	 * Display the custom background page.
   176 	 *
   174 	 *
   177 	 * @since 3.0.0
   175 	 * @since 3.0.0
   178 	 */
   176 	 */
   179 	function admin_page() {
   177 	public function admin_page() {
   180 ?>
   178 ?>
   181 <div class="wrap" id="custom-background">
   179 <div class="wrap" id="custom-background">
   182 <?php screen_icon(); ?>
   180 <h2><?php _e( 'Custom Background' ); ?></h2>
   183 <h2><?php _e('Custom Background'); ?></h2>
   181 
   184 <?php if ( !empty($this->updated) ) { ?>
   182 <?php if ( current_user_can( 'customize' ) ) { ?>
       
   183 <div class="notice notice-info hide-if-no-customize">
       
   184 	<p>
       
   185 		<?php
       
   186 		printf(
       
   187 			__( 'You can now manage and live-preview Custom Backgrounds in the <a href="%1$s">Customizer</a>.' ),
       
   188 			admin_url( 'customize.php?autofocus[control]=background_image' )
       
   189 		);
       
   190 		?>
       
   191 	</p>
       
   192 </div>
       
   193 <?php } ?>
       
   194 
       
   195 <?php if ( ! empty( $this->updated ) ) { ?>
   185 <div id="message" class="updated">
   196 <div id="message" class="updated">
   186 <p><?php printf( __( 'Background updated. <a href="%s">Visit your site</a> to see how it looks.' ), home_url( '/' ) ); ?></p>
   197 <p><?php printf( __( 'Background updated. <a href="%s">Visit your site</a> to see how it looks.' ), home_url( '/' ) ); ?></p>
   187 </div>
   198 </div>
   188 <?php }
   199 <?php } ?>
   189 
   200 
   190 	if ( $this->admin_image_div_callback ) {
   201 <h3><?php _e( 'Background Image' ); ?></h3>
   191 		call_user_func($this->admin_image_div_callback);
   202 
   192 	} else {
       
   193 ?>
       
   194 <h3><?php _e('Background Image'); ?></h3>
       
   195 <table class="form-table">
   203 <table class="form-table">
   196 <tbody>
   204 <tbody>
   197 <tr valign="top">
   205 <tr>
   198 <th scope="row"><?php _e('Preview'); ?></th>
   206 <th scope="row"><?php _e( 'Preview' ); ?></th>
   199 <td>
   207 <td>
   200 <?php
   208 	<?php
   201 $background_styles = '';
   209 	if ( $this->admin_image_div_callback ) {
   202 if ( $bgcolor = get_background_color() )
   210 		call_user_func( $this->admin_image_div_callback );
   203 	$background_styles .= 'background-color: #' . $bgcolor . ';';
   211 	} else {
   204 
   212 		$background_styles = '';
   205 if ( get_background_image() ) {
   213 		if ( $bgcolor = get_background_color() )
   206 	$background_image_thumb = esc_url( set_url_scheme( get_theme_mod( 'background_image_thumb', str_replace( '%', '%%', get_background_image() ) ) ) );
   214 			$background_styles .= 'background-color: #' . $bgcolor . ';';
   207 	// background-image URL must be single quote, see below
   215 
   208 	$background_styles .= ' background-image: url(\'' . $background_image_thumb . '\');'
   216 		$background_image_thumb = get_background_image();
   209 		. ' background-repeat: ' . get_theme_mod('background_repeat', 'repeat') . ';'
   217 		if ( $background_image_thumb ) {
   210 		. ' background-position: top ' . get_theme_mod('background_position_x', 'left');
   218 			$background_image_thumb = esc_url( set_url_scheme( get_theme_mod( 'background_image_thumb', str_replace( '%', '%%', $background_image_thumb ) ) ) );
   211 }
   219 
   212 ?>
   220 			// Background-image URL must be single quote, see below.
   213 <div id="custom-background-image" style="<?php echo $background_styles; ?>"><?php // must be double quote, see above ?>
   221 			$background_styles .= ' background-image: url(\'' . $background_image_thumb . '\');'
   214 <?php if ( get_background_image() ) { ?>
   222 				. ' background-repeat: ' . get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'default-repeat' ) ) . ';'
   215 <img class="custom-background-image" src="<?php echo $background_image_thumb; ?>" style="visibility:hidden;" alt="" /><br />
   223 				. ' background-position: top ' . get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) );
   216 <img class="custom-background-image" src="<?php echo $background_image_thumb; ?>" style="visibility:hidden;" alt="" />
   224 		}
   217 <?php } ?>
   225 	?>
   218 </div>
   226 	<div id="custom-background-image" style="<?php echo $background_styles; ?>"><?php // must be double quote, see above ?>
   219 <?php } ?>
   227 		<?php if ( $background_image_thumb ) { ?>
       
   228 		<img class="custom-background-image" src="<?php echo $background_image_thumb; ?>" style="visibility:hidden;" alt="" /><br />
       
   229 		<img class="custom-background-image" src="<?php echo $background_image_thumb; ?>" style="visibility:hidden;" alt="" />
       
   230 		<?php } ?>
       
   231 	</div>
       
   232 	<?php } ?>
   220 </td>
   233 </td>
   221 </tr>
   234 </tr>
       
   235 
   222 <?php if ( get_background_image() ) : ?>
   236 <?php if ( get_background_image() ) : ?>
   223 <tr valign="top">
   237 <tr>
   224 <th scope="row"><?php _e('Remove Image'); ?></th>
   238 <th scope="row"><?php _e('Remove Image'); ?></th>
   225 <td>
   239 <td>
   226 <form method="post" action="">
   240 <form method="post">
   227 <?php wp_nonce_field('custom-background-remove', '_wpnonce-custom-background-remove'); ?>
   241 <?php wp_nonce_field('custom-background-remove', '_wpnonce-custom-background-remove'); ?>
   228 <?php submit_button( __( 'Remove Background Image' ), 'button', 'remove-background', false ); ?><br/>
   242 <?php submit_button( __( 'Remove Background Image' ), 'button', 'remove-background', false ); ?><br/>
   229 <?php _e('This will remove the background image. You will not be able to restore any customizations.') ?>
   243 <?php _e('This will remove the background image. You will not be able to restore any customizations.') ?>
   230 </form>
   244 </form>
   231 </td>
   245 </td>
   232 </tr>
   246 </tr>
   233 <?php endif; ?>
   247 <?php endif; ?>
   234 
   248 
   235 <?php $default_image = get_theme_support( 'custom-background', 'default-image' ); ?>
   249 <?php $default_image = get_theme_support( 'custom-background', 'default-image' ); ?>
   236 <?php if ( $default_image && get_background_image() != $default_image ) : ?>
   250 <?php if ( $default_image && get_background_image() != $default_image ) : ?>
   237 <tr valign="top">
   251 <tr>
   238 <th scope="row"><?php _e('Restore Original Image'); ?></th>
   252 <th scope="row"><?php _e('Restore Original Image'); ?></th>
   239 <td>
   253 <td>
   240 <form method="post" action="">
   254 <form method="post">
   241 <?php wp_nonce_field('custom-background-reset', '_wpnonce-custom-background-reset'); ?>
   255 <?php wp_nonce_field('custom-background-reset', '_wpnonce-custom-background-reset'); ?>
   242 <?php submit_button( __( 'Restore Original Image' ), 'button', 'reset-background', false ); ?><br/>
   256 <?php submit_button( __( 'Restore Original Image' ), 'button', 'reset-background', false ); ?><br/>
   243 <?php _e('This will restore the original background image. You will not be able to restore any customizations.') ?>
   257 <?php _e('This will restore the original background image. You will not be able to restore any customizations.') ?>
   244 </form>
   258 </form>
   245 </td>
   259 </td>
   246 </tr>
   260 </tr>
   247 
       
   248 <?php endif; ?>
   261 <?php endif; ?>
   249 <tr valign="top">
   262 
       
   263 <tr>
   250 <th scope="row"><?php _e('Select Image'); ?></th>
   264 <th scope="row"><?php _e('Select Image'); ?></th>
   251 <td><form enctype="multipart/form-data" id="upload-form" class="wp-upload-form" method="post" action="">
   265 <td><form enctype="multipart/form-data" id="upload-form" class="wp-upload-form" method="post">
   252 	<p>
   266 	<p>
   253 		<label for="upload"><?php _e( 'Choose an image from your computer:' ); ?></label><br />
   267 		<label for="upload"><?php _e( 'Choose an image from your computer:' ); ?></label><br />
   254 		<input type="file" id="upload" name="import" />
   268 		<input type="file" id="upload" name="import" />
   255 		<input type="hidden" name="action" value="save" />
   269 		<input type="hidden" name="action" value="save" />
   256 		<?php wp_nonce_field( 'custom-background-upload', '_wpnonce-custom-background-upload' ); ?>
   270 		<?php wp_nonce_field( 'custom-background-upload', '_wpnonce-custom-background-upload' ); ?>
   257 		<?php submit_button( __( 'Upload' ), 'button', 'submit', false ); ?>
   271 		<?php submit_button( __( 'Upload' ), 'button', 'submit', false ); ?>
   258 	</p>
   272 	</p>
   259 	<p>
   273 	<p>
   260 		<label for="choose-from-library-link"><?php _e( 'Or choose an image from your media library:' ); ?></label><br />
   274 		<label for="choose-from-library-link"><?php _e( 'Or choose an image from your media library:' ); ?></label><br />
   261 		<a id="choose-from-library-link" class="button"
   275 		<button id="choose-from-library-link" class="button"
   262 			data-choose="<?php esc_attr_e( 'Choose a Background Image' ); ?>"
   276 			data-choose="<?php esc_attr_e( 'Choose a Background Image' ); ?>"
   263 			data-update="<?php esc_attr_e( 'Set as background' ); ?>"><?php _e( 'Choose Image' ); ?></a>
   277 			data-update="<?php esc_attr_e( 'Set as background' ); ?>"><?php _e( 'Choose Image' ); ?></button>
   264 	</p>
   278 	</p>
   265 	</form>
   279 	</form>
   266 </td>
   280 </td>
   267 </tr>
   281 </tr>
   268 </tbody>
   282 </tbody>
   269 </table>
   283 </table>
   270 
   284 
   271 <h3><?php _e('Display Options') ?></h3>
   285 <h3><?php _e('Display Options') ?></h3>
   272 <form method="post" action="">
   286 <form method="post">
   273 <table class="form-table">
   287 <table class="form-table">
   274 <tbody>
   288 <tbody>
   275 <?php if ( get_background_image() ) : ?>
   289 <?php if ( get_background_image() ) : ?>
   276 <tr valign="top">
   290 <tr>
   277 <th scope="row"><?php _e( 'Position' ); ?></th>
   291 <th scope="row"><?php _e( 'Position' ); ?></th>
   278 <td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Position' ); ?></span></legend>
   292 <td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Position' ); ?></span></legend>
   279 <label>
   293 <label>
   280 <input name="background-position-x" type="radio" value="left"<?php checked('left', get_theme_mod('background_position_x', 'left')); ?> />
   294 <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' ) ) ); ?> />
   281 <?php _e('Left') ?>
   295 <?php _e('Left') ?>
   282 </label>
   296 </label>
   283 <label>
   297 <label>
   284 <input name="background-position-x" type="radio" value="center"<?php checked('center', get_theme_mod('background_position_x', 'left')); ?> />
   298 <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' ) ) ); ?> />
   285 <?php _e('Center') ?>
   299 <?php _e('Center') ?>
   286 </label>
   300 </label>
   287 <label>
   301 <label>
   288 <input name="background-position-x" type="radio" value="right"<?php checked('right', get_theme_mod('background_position_x', 'left')); ?> />
   302 <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' ) ) ); ?> />
   289 <?php _e('Right') ?>
   303 <?php _e('Right') ?>
   290 </label>
   304 </label>
   291 </fieldset></td>
   305 </fieldset></td>
   292 </tr>
   306 </tr>
   293 
   307 
   294 <tr valign="top">
   308 <tr>
   295 <th scope="row"><?php _e( 'Repeat' ); ?></th>
   309 <th scope="row"><?php _e( 'Repeat' ); ?></th>
   296 <td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Repeat' ); ?></span></legend>
   310 <td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Repeat' ); ?></span></legend>
   297 <label><input type="radio" name="background-repeat" value="no-repeat"<?php checked('no-repeat', get_theme_mod('background_repeat', 'repeat')); ?> /> <?php _e('No Repeat'); ?></label>
   311 <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>
   298 	<label><input type="radio" name="background-repeat" value="repeat"<?php checked('repeat', get_theme_mod('background_repeat', 'repeat')); ?> /> <?php _e('Tile'); ?></label>
   312 	<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>
   299 	<label><input type="radio" name="background-repeat" value="repeat-x"<?php checked('repeat-x', get_theme_mod('background_repeat', 'repeat')); ?> /> <?php _e('Tile Horizontally'); ?></label>
   313 	<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>
   300 	<label><input type="radio" name="background-repeat" value="repeat-y"<?php checked('repeat-y', get_theme_mod('background_repeat', 'repeat')); ?> /> <?php _e('Tile Vertically'); ?></label>
   314 	<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>
   301 </fieldset></td>
   315 </fieldset></td>
   302 </tr>
   316 </tr>
   303 
   317 
   304 <tr valign="top">
   318 <tr>
   305 <th scope="row"><?php _ex( 'Attachment', 'Background Attachment' ); ?></th>
   319 <th scope="row"><?php _ex( 'Attachment', 'Background Attachment' ); ?></th>
   306 <td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Attachment' ); ?></span></legend>
   320 <td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Attachment' ); ?></span></legend>
   307 <label>
   321 <label>
   308 <input name="background-attachment" type="radio" value="scroll" <?php checked('scroll', get_theme_mod('background_attachment', 'scroll')); ?> />
   322 <input name="background-attachment" type="radio" value="scroll" <?php checked( 'scroll', get_theme_mod( 'background_attachment', get_theme_support( 'custom-background', 'default-attachment' ) ) ); ?> />
   309 <?php _e('Scroll') ?>
   323 <?php _e( 'Scroll' ); ?>
   310 </label>
   324 </label>
   311 <label>
   325 <label>
   312 <input name="background-attachment" type="radio" value="fixed" <?php checked('fixed', get_theme_mod('background_attachment', 'scroll')); ?> />
   326 <input name="background-attachment" type="radio" value="fixed" <?php checked( 'fixed', get_theme_mod( 'background_attachment', get_theme_support( 'custom-background', 'default-attachment' ) ) ); ?> />
   313 <?php _e('Fixed') ?>
   327 <?php _e( 'Fixed' ); ?>
   314 </label>
   328 </label>
   315 </fieldset></td>
   329 </fieldset></td>
   316 </tr>
   330 </tr>
   317 <?php endif; // get_background_image() ?>
   331 <?php endif; // get_background_image() ?>
   318 <tr valign="top">
   332 <tr>
   319 <th scope="row"><?php _e( 'Background Color' ); ?></th>
   333 <th scope="row"><?php _e( 'Background Color' ); ?></th>
   320 <td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Color' ); ?></span></legend>
   334 <td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Color' ); ?></span></legend>
   321 <?php
   335 <?php
   322 $default_color = '';
   336 $default_color = '';
   323 if ( current_theme_supports( 'custom-background', 'default-color' ) )
   337 if ( current_theme_supports( 'custom-background', 'default-color' ) )
   340 	/**
   354 	/**
   341 	 * Handle an Image upload for the background image.
   355 	 * Handle an Image upload for the background image.
   342 	 *
   356 	 *
   343 	 * @since 3.0.0
   357 	 * @since 3.0.0
   344 	 */
   358 	 */
   345 	function handle_upload() {
   359 	public function handle_upload() {
   346 
   360 
   347 		if ( empty($_FILES) )
   361 		if ( empty($_FILES) )
   348 			return;
   362 			return;
   349 
   363 
   350 		check_admin_referer('custom-background-upload', '_wpnonce-custom-background-upload');
   364 		check_admin_referer('custom-background-upload', '_wpnonce-custom-background-upload');
   351 		$overrides = array('test_form' => false);
   365 		$overrides = array('test_form' => false);
   352 
   366 
   353 		$uploaded_file = $_FILES['import'];
   367 		$uploaded_file = $_FILES['import'];
   354 		$wp_filetype = wp_check_filetype_and_ext( $uploaded_file['tmp_name'], $uploaded_file['name'], false );
   368 		$wp_filetype = wp_check_filetype_and_ext( $uploaded_file['tmp_name'], $uploaded_file['name'] );
   355 		if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) )
   369 		if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) )
   356 			wp_die( __( 'The uploaded file is not a valid image. Please try again.' ) );
   370 			wp_die( __( 'The uploaded file is not a valid image. Please try again.' ) );
   357 
   371 
   358 		$file = wp_handle_upload($uploaded_file, $overrides);
   372 		$file = wp_handle_upload($uploaded_file, $overrides);
   359 
   373 
   390 		do_action( 'wp_create_file_in_uploads', $file, $id ); // For replication
   404 		do_action( 'wp_create_file_in_uploads', $file, $id ); // For replication
   391 		$this->updated = true;
   405 		$this->updated = true;
   392 	}
   406 	}
   393 
   407 
   394 	/**
   408 	/**
   395 	 * Unused since 3.5.0.
   409 	 * AJAX handler for adding custom background context to an attachment.
       
   410 	 *
       
   411 	 * Triggered when the user adds a new background image from the
       
   412 	 * Media Manager.
       
   413 	 *
       
   414 	 * @since 4.1.0
       
   415 	 */
       
   416 	public function ajax_background_add() {
       
   417 		check_ajax_referer( 'background-add', 'nonce' );
       
   418 
       
   419 		if ( ! current_user_can( 'edit_theme_options' ) ) {
       
   420 			wp_send_json_error();
       
   421 		}
       
   422 
       
   423 		$attachment_id = absint( $_POST['attachment_id'] );
       
   424 		if ( $attachment_id < 1 ) {
       
   425 			wp_send_json_error();
       
   426 		}
       
   427 
       
   428 		update_post_meta( $attachment_id, '_wp_attachment_is_custom_background', get_stylesheet() );
       
   429 
       
   430 		wp_send_json_success();
       
   431 	}
       
   432 
       
   433 	/**
   396 	 *
   434 	 *
   397 	 * @since 3.4.0
   435 	 * @since 3.4.0
   398 	 */
   436 	 * @deprecated 3.5.0
   399 	function attachment_fields_to_edit( $form_fields ) {
   437 	 */
       
   438 	public function attachment_fields_to_edit( $form_fields ) {
   400 		return $form_fields;
   439 		return $form_fields;
   401 	}
   440 	}
   402 
   441 
   403 	/**
   442 	/**
   404 	 * Unused since 3.5.0.
       
   405 	 *
   443 	 *
   406 	 * @since 3.4.0
   444 	 * @since 3.4.0
   407 	 */
   445 	 * @deprecated 3.5.0
   408 	function filter_upload_tabs( $tabs ) {
   446 	 */
       
   447 	public function filter_upload_tabs( $tabs ) {
   409 		return $tabs;
   448 		return $tabs;
   410 	}
   449 	}
   411 
   450 
       
   451 	/**
       
   452 	 *
       
   453 	 * @since 3.4.0
       
   454 	 * @deprecated 3.5.0
       
   455 	 */
   412 	public function wp_set_background_image() {
   456 	public function wp_set_background_image() {
   413 		if ( ! current_user_can('edit_theme_options') || ! isset( $_POST['attachment_id'] ) ) exit;
   457 		if ( ! current_user_can('edit_theme_options') || ! isset( $_POST['attachment_id'] ) ) exit;
   414 		$attachment_id = absint($_POST['attachment_id']);
   458 		$attachment_id = absint($_POST['attachment_id']);
   415 		/** This filter is documented in wp-admin/includes/media.php */
   459 		/** This filter is documented in wp-admin/includes/media.php */
   416 		$sizes = array_keys(apply_filters( 'image_size_names_choose', array('thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large'), 'full' => __('Full Size')) ));
   460 		$sizes = array_keys(apply_filters( 'image_size_names_choose', array('thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large'), 'full' => __('Full Size')) ));