wp/wp-admin/includes/class-custom-background.php
changeset 18 be944660c56a
parent 16 a86126ab1dd4
child 19 3d72ae0968f4
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
   115 			return;
   115 			return;
   116 		}
   116 		}
   117 
   117 
   118 		if ( isset( $_POST['reset-background'] ) ) {
   118 		if ( isset( $_POST['reset-background'] ) ) {
   119 			check_admin_referer( 'custom-background-reset', '_wpnonce-custom-background-reset' );
   119 			check_admin_referer( 'custom-background-reset', '_wpnonce-custom-background-reset' );
       
   120 
   120 			remove_theme_mod( 'background_image' );
   121 			remove_theme_mod( 'background_image' );
   121 			remove_theme_mod( 'background_image_thumb' );
   122 			remove_theme_mod( 'background_image_thumb' );
       
   123 
   122 			$this->updated = true;
   124 			$this->updated = true;
   123 			return;
   125 			return;
   124 		}
   126 		}
   125 
   127 
   126 		if ( isset( $_POST['remove-background'] ) ) {
   128 		if ( isset( $_POST['remove-background'] ) ) {
   127 			// @todo Uploaded files are not removed here.
   129 			// @todo Uploaded files are not removed here.
   128 			check_admin_referer( 'custom-background-remove', '_wpnonce-custom-background-remove' );
   130 			check_admin_referer( 'custom-background-remove', '_wpnonce-custom-background-remove' );
       
   131 
   129 			set_theme_mod( 'background_image', '' );
   132 			set_theme_mod( 'background_image', '' );
   130 			set_theme_mod( 'background_image_thumb', '' );
   133 			set_theme_mod( 'background_image_thumb', '' );
       
   134 
   131 			$this->updated = true;
   135 			$this->updated = true;
   132 			wp_safe_redirect( $_POST['_wp_http_referer'] );
   136 			wp_safe_redirect( $_POST['_wp_http_referer'] );
   133 			return;
   137 			return;
   134 		}
   138 		}
   135 
   139 
   202 			set_theme_mod( 'background_attachment', $attachment );
   206 			set_theme_mod( 'background_attachment', $attachment );
   203 		}
   207 		}
   204 
   208 
   205 		if ( isset( $_POST['background-color'] ) ) {
   209 		if ( isset( $_POST['background-color'] ) ) {
   206 			check_admin_referer( 'custom-background' );
   210 			check_admin_referer( 'custom-background' );
       
   211 
   207 			$color = preg_replace( '/[^0-9a-fA-F]/', '', $_POST['background-color'] );
   212 			$color = preg_replace( '/[^0-9a-fA-F]/', '', $_POST['background-color'] );
   208 			if ( strlen( $color ) == 6 || strlen( $color ) == 3 ) {
   213 
       
   214 			if ( strlen( $color ) === 6 || strlen( $color ) === 3 ) {
   209 				set_theme_mod( 'background_color', $color );
   215 				set_theme_mod( 'background_color', $color );
   210 			} else {
   216 			} else {
   211 				set_theme_mod( 'background_color', '' );
   217 				set_theme_mod( 'background_color', '' );
   212 			}
   218 			}
   213 		}
   219 		}
   306 </td>
   312 </td>
   307 </tr>
   313 </tr>
   308 		<?php endif; ?>
   314 		<?php endif; ?>
   309 
   315 
   310 		<?php $default_image = get_theme_support( 'custom-background', 'default-image' ); ?>
   316 		<?php $default_image = get_theme_support( 'custom-background', 'default-image' ); ?>
   311 		<?php if ( $default_image && get_background_image() != $default_image ) : ?>
   317 		<?php if ( $default_image && get_background_image() !== $default_image ) : ?>
   312 <tr>
   318 <tr>
   313 <th scope="row"><?php _e( 'Restore Original Image' ); ?></th>
   319 <th scope="row"><?php _e( 'Restore Original Image' ); ?></th>
   314 <td>
   320 <td>
   315 <form method="post">
   321 <form method="post">
   316 			<?php wp_nonce_field( 'custom-background-reset', '_wpnonce-custom-background-reset' ); ?>
   322 			<?php wp_nonce_field( 'custom-background-reset', '_wpnonce-custom-background-reset' ); ?>
   410 <div class="background-position-control">
   416 <div class="background-position-control">
   411 			<?php foreach ( $background_position_options as $group ) : ?>
   417 			<?php foreach ( $background_position_options as $group ) : ?>
   412 	<div class="button-group">
   418 	<div class="button-group">
   413 				<?php foreach ( $group as $value => $input ) : ?>
   419 				<?php foreach ( $group as $value => $input ) : ?>
   414 		<label>
   420 		<label>
   415 			<input class="screen-reader-text" name="background-position" type="radio" value="<?php echo esc_attr( $value ); ?>"<?php checked( $value, $background_position ); ?>>
   421 			<input class="ui-helper-hidden-accessible" name="background-position" type="radio" value="<?php echo esc_attr( $value ); ?>"<?php checked( $value, $background_position ); ?>>
   416 			<span class="button display-options position"><span class="<?php echo esc_attr( $input['icon'] ); ?>" aria-hidden="true"></span></span>
   422 			<span class="button display-options position"><span class="<?php echo esc_attr( $input['icon'] ); ?>" aria-hidden="true"></span></span>
   417 			<span class="screen-reader-text"><?php echo $input['label']; ?></span>
   423 			<span class="screen-reader-text"><?php echo $input['label']; ?></span>
   418 		</label>
   424 		</label>
   419 	<?php endforeach; ?>
   425 	<?php endforeach; ?>
   420 	</div>
   426 	</div>
   482 		if ( empty( $_FILES ) ) {
   488 		if ( empty( $_FILES ) ) {
   483 			return;
   489 			return;
   484 		}
   490 		}
   485 
   491 
   486 		check_admin_referer( 'custom-background-upload', '_wpnonce-custom-background-upload' );
   492 		check_admin_referer( 'custom-background-upload', '_wpnonce-custom-background-upload' );
       
   493 
   487 		$overrides = array( 'test_form' => false );
   494 		$overrides = array( 'test_form' => false );
   488 
   495 
   489 		$uploaded_file = $_FILES['import'];
   496 		$uploaded_file = $_FILES['import'];
   490 		$wp_filetype   = wp_check_filetype_and_ext( $uploaded_file['tmp_name'], $uploaded_file['name'] );
   497 		$wp_filetype   = wp_check_filetype_and_ext( $uploaded_file['tmp_name'], $uploaded_file['name'] );
   491 		if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) ) {
   498 		if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) ) {
   579 	/**
   586 	/**
   580 	 * @since 3.4.0
   587 	 * @since 3.4.0
   581 	 * @deprecated 3.5.0
   588 	 * @deprecated 3.5.0
   582 	 */
   589 	 */
   583 	public function wp_set_background_image() {
   590 	public function wp_set_background_image() {
       
   591 		check_ajax_referer( 'custom-background' );
       
   592 
   584 		if ( ! current_user_can( 'edit_theme_options' ) || ! isset( $_POST['attachment_id'] ) ) {
   593 		if ( ! current_user_can( 'edit_theme_options' ) || ! isset( $_POST['attachment_id'] ) ) {
   585 			exit;
   594 			exit;
   586 		}
   595 		}
   587 
   596 
   588 		$attachment_id = absint( $_POST['attachment_id'] );
   597 		$attachment_id = absint( $_POST['attachment_id'] );