Changeset 43571 for trunk/src/wp-admin/custom-background.php
- Timestamp:
- 08/17/2018 01:50:26 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/custom-background.php
r42343 r43571 222 222 */ 223 223 public function admin_page() { 224 ?>224 ?> 225 225 <div class="wrap" id="custom-background"> 226 226 <h1><?php _e( 'Custom Background' ); ?></h1> 227 227 228 <?php if ( current_user_can( 'customize' ) ) { ?>228 <?php if ( current_user_can( 'customize' ) ) { ?> 229 229 <div class="notice notice-info hide-if-no-customize"> 230 230 <p> 231 <?php232 printf(233 __( 'You can now manage and live-preview Custom Backgrounds in the <a href="%1$s">Customizer</a>.' ),234 admin_url( 'customize.php?autofocus[control]=background_image' )235 );236 ?>231 <?php 232 printf( 233 __( 'You can now manage and live-preview Custom Backgrounds in the <a href="%1$s">Customizer</a>.' ), 234 admin_url( 'customize.php?autofocus[control]=background_image' ) 235 ); 236 ?> 237 237 </p> 238 238 </div> 239 <?php } ?>240 241 <?php if ( ! empty( $this->updated ) ) { ?>239 <?php } ?> 240 241 <?php if ( ! empty( $this->updated ) ) { ?> 242 242 <div id="message" class="updated"> 243 243 <p><?php printf( __( 'Background updated. <a href="%s">Visit your site</a> to see how it looks.' ), home_url( '/' ) ); ?></p> 244 244 </div> 245 <?php } ?>245 <?php } ?> 246 246 247 247 <h3><?php _e( 'Background Image' ); ?></h3> … … 252 252 <th scope="row"><?php _e( 'Preview' ); ?></th> 253 253 <td> 254 <?php255 if ( $this->admin_image_div_callback ) {256 call_user_func( $this->admin_image_div_callback );257 } else {258 $background_styles = '';259 if ( $bgcolor = get_background_color() ) {260 $background_styles .= 'background-color: #' . $bgcolor . ';';261 }262 263 $background_image_thumb = get_background_image();264 if ( $background_image_thumb ) {265 $background_image_thumb = esc_url( set_url_scheme( get_theme_mod( 'background_image_thumb', str_replace( '%', '%%', $background_image_thumb ) ) ) );266 $background_position_x = get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) );267 $background_position_y = get_theme_mod( 'background_position_y', get_theme_support( 'custom-background', 'default-position-y' ) );268 $background_size = get_theme_mod( 'background_size', get_theme_support( 'custom-background', 'default-size' ) );269 $background_repeat = get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'default-repeat' ) );270 $background_attachment = get_theme_mod( 'background_attachment', get_theme_support( 'custom-background', 'default-attachment' ) );271 272 // Background-image URL must be single quote, see below.273 $background_styles .= " background-image: url('$background_image_thumb');"254 <?php 255 if ( $this->admin_image_div_callback ) { 256 call_user_func( $this->admin_image_div_callback ); 257 } else { 258 $background_styles = ''; 259 if ( $bgcolor = get_background_color() ) { 260 $background_styles .= 'background-color: #' . $bgcolor . ';'; 261 } 262 263 $background_image_thumb = get_background_image(); 264 if ( $background_image_thumb ) { 265 $background_image_thumb = esc_url( set_url_scheme( get_theme_mod( 'background_image_thumb', str_replace( '%', '%%', $background_image_thumb ) ) ) ); 266 $background_position_x = get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) ); 267 $background_position_y = get_theme_mod( 'background_position_y', get_theme_support( 'custom-background', 'default-position-y' ) ); 268 $background_size = get_theme_mod( 'background_size', get_theme_support( 'custom-background', 'default-size' ) ); 269 $background_repeat = get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'default-repeat' ) ); 270 $background_attachment = get_theme_mod( 'background_attachment', get_theme_support( 'custom-background', 'default-attachment' ) ); 271 272 // Background-image URL must be single quote, see below. 273 $background_styles .= " background-image: url('$background_image_thumb');" 274 274 . " background-size: $background_size;" 275 275 . " background-position: $background_position_x $background_position_y;" 276 276 . " background-repeat: $background_repeat;" 277 277 . " background-attachment: $background_attachment;"; 278 }279 ?>278 } 279 ?> 280 280 <div id="custom-background-image" style="<?php echo $background_styles; ?>"><?php // must be double quote, see above ?> 281 <?php if ( $background_image_thumb ) { ?>281 <?php if ( $background_image_thumb ) { ?> 282 282 <img class="custom-background-image" src="<?php echo $background_image_thumb; ?>" style="visibility:hidden;" alt="" /><br /> 283 283 <img class="custom-background-image" src="<?php echo $background_image_thumb; ?>" style="visibility:hidden;" alt="" /> … … 288 288 </tr> 289 289 290 <?php if ( get_background_image() ) : ?>290 <?php if ( get_background_image() ) : ?> 291 291 <tr> 292 292 <th scope="row"><?php _e( 'Remove Image' ); ?></th> 293 293 <td> 294 294 <form method="post"> 295 <?php wp_nonce_field( 'custom-background-remove', '_wpnonce-custom-background-remove' ); ?>296 <?php submit_button( __( 'Remove Background Image' ), '', 'remove-background', false ); ?><br/>297 <?php _e( 'This will remove the background image. You will not be able to restore any customizations.' ); ?>295 <?php wp_nonce_field( 'custom-background-remove', '_wpnonce-custom-background-remove' ); ?> 296 <?php submit_button( __( 'Remove Background Image' ), '', 'remove-background', false ); ?><br/> 297 <?php _e( 'This will remove the background image. You will not be able to restore any customizations.' ); ?> 298 298 </form> 299 299 </td> 300 300 </tr> 301 <?php endif; ?>302 303 <?php $default_image = get_theme_support( 'custom-background', 'default-image' ); ?>304 <?php if ( $default_image && get_background_image() != $default_image ) : ?>301 <?php endif; ?> 302 303 <?php $default_image = get_theme_support( 'custom-background', 'default-image' ); ?> 304 <?php if ( $default_image && get_background_image() != $default_image ) : ?> 305 305 <tr> 306 306 <th scope="row"><?php _e( 'Restore Original Image' ); ?></th> 307 307 <td> 308 308 <form method="post"> 309 <?php wp_nonce_field( 'custom-background-reset', '_wpnonce-custom-background-reset' ); ?>310 <?php submit_button( __( 'Restore Original Image' ), '', 'reset-background', false ); ?><br/>311 <?php _e( 'This will restore the original background image. You will not be able to restore any customizations.' ); ?>309 <?php wp_nonce_field( 'custom-background-reset', '_wpnonce-custom-background-reset' ); ?> 310 <?php submit_button( __( 'Restore Original Image' ), '', 'reset-background', false ); ?><br/> 311 <?php _e( 'This will restore the original background image. You will not be able to restore any customizations.' ); ?> 312 312 </form> 313 313 </td> 314 314 </tr> 315 <?php endif; ?>316 317 <?php if ( current_user_can( 'upload_files' ) ) : ?>315 <?php endif; ?> 316 317 <?php if ( current_user_can( 'upload_files' ) ) : ?> 318 318 <tr> 319 319 <th scope="row"><?php _e( 'Select Image' ); ?></th> … … 323 323 <input type="file" id="upload" name="import" /> 324 324 <input type="hidden" name="action" value="save" /> 325 <?php wp_nonce_field( 'custom-background-upload', '_wpnonce-custom-background-upload' ); ?>326 <?php submit_button( __( 'Upload' ), '', 'submit', false ); ?>325 <?php wp_nonce_field( 'custom-background-upload', '_wpnonce-custom-background-upload' ); ?> 326 <?php submit_button( __( 'Upload' ), '', 'submit', false ); ?> 327 327 </p> 328 328 <p> … … 335 335 </td> 336 336 </tr> 337 <?php endif; ?>337 <?php endif; ?> 338 338 </tbody> 339 339 </table> … … 343 343 <table class="form-table"> 344 344 <tbody> 345 <?php if ( get_background_image() ) : ?>345 <?php if ( get_background_image() ) : ?> 346 346 <input name="background-preset" type="hidden" value="custom"> 347 347 348 <?php349 $background_position = sprintf(350 '%s %s',351 get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) ),352 get_theme_mod( 'background_position_y', get_theme_support( 'custom-background', 'default-position-y' ) )353 );354 355 $background_position_options = array(356 array(357 'left top' => array(358 'label' => __( 'Top Left' ),359 'icon' => 'dashicons dashicons-arrow-left-alt',360 ),361 'center top' => array(362 'label' => __( 'Top' ),363 'icon' => 'dashicons dashicons-arrow-up-alt',364 ),365 'right top' => array(366 'label' => __( 'Top Right' ),367 'icon' => 'dashicons dashicons-arrow-right-alt',368 ),369 ),370 array(371 'left center' => array(372 'label' => __( 'Left' ),373 'icon' => 'dashicons dashicons-arrow-left-alt',374 ),375 'center center' => array(376 'label' => __( 'Center' ),377 'icon' => 'background-position-center-icon',378 ),379 'right center' => array(380 'label' => __( 'Right' ),381 'icon' => 'dashicons dashicons-arrow-right-alt',382 ),383 ),384 array(385 'left bottom' => array(386 'label' => __( 'Bottom Left' ),387 'icon' => 'dashicons dashicons-arrow-left-alt',388 ),389 'center bottom' => array(390 'label' => __( 'Bottom' ),391 'icon' => 'dashicons dashicons-arrow-down-alt',392 ),393 'right bottom' => array(394 'label' => __( 'Bottom Right' ),395 'icon' => 'dashicons dashicons-arrow-right-alt',396 ),397 ),398 );399 ?>348 <?php 349 $background_position = sprintf( 350 '%s %s', 351 get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) ), 352 get_theme_mod( 'background_position_y', get_theme_support( 'custom-background', 'default-position-y' ) ) 353 ); 354 355 $background_position_options = array( 356 array( 357 'left top' => array( 358 'label' => __( 'Top Left' ), 359 'icon' => 'dashicons dashicons-arrow-left-alt', 360 ), 361 'center top' => array( 362 'label' => __( 'Top' ), 363 'icon' => 'dashicons dashicons-arrow-up-alt', 364 ), 365 'right top' => array( 366 'label' => __( 'Top Right' ), 367 'icon' => 'dashicons dashicons-arrow-right-alt', 368 ), 369 ), 370 array( 371 'left center' => array( 372 'label' => __( 'Left' ), 373 'icon' => 'dashicons dashicons-arrow-left-alt', 374 ), 375 'center center' => array( 376 'label' => __( 'Center' ), 377 'icon' => 'background-position-center-icon', 378 ), 379 'right center' => array( 380 'label' => __( 'Right' ), 381 'icon' => 'dashicons dashicons-arrow-right-alt', 382 ), 383 ), 384 array( 385 'left bottom' => array( 386 'label' => __( 'Bottom Left' ), 387 'icon' => 'dashicons dashicons-arrow-left-alt', 388 ), 389 'center bottom' => array( 390 'label' => __( 'Bottom' ), 391 'icon' => 'dashicons dashicons-arrow-down-alt', 392 ), 393 'right bottom' => array( 394 'label' => __( 'Bottom Right' ), 395 'icon' => 'dashicons dashicons-arrow-right-alt', 396 ), 397 ), 398 ); 399 ?> 400 400 <tr> 401 401 <th scope="row"><?php _e( 'Image Position' ); ?></th> 402 402 <td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Image Position' ); ?></span></legend> 403 403 <div class="background-position-control"> 404 <?php foreach ( $background_position_options as $group ) : ?>404 <?php foreach ( $background_position_options as $group ) : ?> 405 405 <div class="button-group"> 406 <?php foreach ( $group as $value => $input ) : ?>406 <?php foreach ( $group as $value => $input ) : ?> 407 407 <label> 408 408 <input class="screen-reader-text" name="background-position" type="radio" value="<?php echo esc_attr( $value ); ?>"<?php checked( $value, $background_position ); ?>> … … 447 447 <th scope="row"><?php _e( 'Background Color' ); ?></th> 448 448 <td><fieldset><legend class="screen-reader-text"><span><?php _e( 'Background Color' ); ?></span></legend> 449 <?php450 $default_color = '';451 if ( current_theme_supports( 'custom-background', 'default-color' ) ) {452 $default_color = ' data-default-color="#' . esc_attr( get_theme_support( 'custom-background', 'default-color' ) ) . '"';453 }454 ?>449 <?php 450 $default_color = ''; 451 if ( current_theme_supports( 'custom-background', 'default-color' ) ) { 452 $default_color = ' data-default-color="#' . esc_attr( get_theme_support( 'custom-background', 'default-color' ) ) . '"'; 453 } 454 ?> 455 455 <input type="text" name="background-color" id="background-color" value="#<?php echo esc_attr( get_background_color() ); ?>"<?php echo $default_color; ?>> 456 456 </fieldset></td> … … 459 459 </table> 460 460 461 <?php wp_nonce_field( 'custom-background' ); ?>462 <?php submit_button( null, 'primary', 'save-background-options' ); ?>461 <?php wp_nonce_field( 'custom-background' ); ?> 462 <?php submit_button( null, 'primary', 'save-background-options' ); ?> 463 463 </form> 464 464 465 465 </div> 466 <?php466 <?php 467 467 } 468 468 … … 582 582 $sizes = array_keys( 583 583 apply_filters( 584 'image_size_names_choose', array( 584 'image_size_names_choose', 585 array( 585 586 'thumbnail' => __( 'Thumbnail' ), 586 587 'medium' => __( 'Medium' ),
Note: See TracChangeset
for help on using the changeset viewer.