Ticket #39461: 39461.diff
File 39461.diff, 11.9 KB (added by , 8 years ago) |
---|
-
wp-admin/custom-background.php
139 139 if ( in_array( $_POST['background-preset'], array( 'default', 'fill', 'fit', 'repeat', 'custom' ), true ) ) { 140 140 $preset = $_POST['background-preset']; 141 141 } else { 142 $preset = ' default';142 $preset = 'custom'; 143 143 } 144 144 145 145 set_theme_mod( 'background_preset', $preset ); … … 261 261 $background_image_thumb = get_background_image(); 262 262 if ( $background_image_thumb ) { 263 263 $background_image_thumb = esc_url( set_url_scheme( get_theme_mod( 'background_image_thumb', str_replace( '%', '%%', $background_image_thumb ) ) ) ); 264 $background_preset = get_theme_mod( 'background_preset', get_theme_support( 'custom-background', 'default-preset' ) ); 264 265 $background_position_x = get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) ); 265 266 $background_position_y = get_theme_mod( 'background_position_y', get_theme_support( 'custom-background', 'default-position-y' ) ); 266 $background_size = get_theme_mod( 'background_size', get_theme_support( 'custom-background', 'default-size') );267 $background_repeat = get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'default-repeat') );268 $background_attachment = get_theme_mod( 'background_attachment', get_theme_support( 'custom-background', 'default-attachment') );267 $background_size = get_theme_mod( 'background_size', _sanitize_custom_background_prop( 'size', $background_preset ) ); 268 $background_repeat = get_theme_mod( 'background_repeat', _sanitize_custom_background_prop( 'repeat', $background_preset ) ); 269 $background_attachment = get_theme_mod( 'background_attachment', _sanitize_custom_background_prop( 'attachment', $background_preset ) ); 269 270 270 271 // Background-image URL must be single quote, see below. 271 272 $background_styles .= " background-image: url('$background_image_thumb');" -
wp-admin/js/customize-controls.js
5183 5183 // Initialize the connection with the parent frame. 5184 5184 parent.send( 'ready' ); 5185 5185 5186 // Control visibility for default controls5187 $.each({5188 'background_image': {5189 controls: [ 'background_preset', 'background_position', 'background_size', 'background_repeat', 'background_attachment' ],5190 callback: function( to ) { return !! to; }5191 },5192 'show_on_front': {5193 controls: [ 'page_on_front', 'page_for_posts' ],5194 callback: function( to ) { return 'page' === to; }5195 },5196 'header_textcolor': {5197 controls: [ 'header_textcolor' ],5198 callback: function( to ) { return 'blank' !== to; }5199 }5200 }, function( settingId, o ) {5201 api( settingId, function( setting ) {5202 $.each( o.controls, function( i, controlId ) {5203 api.control( controlId, function( control ) {5204 var visibility = function( to ) {5205 control.container.toggle( o.callback( to ) );5206 };5207 5208 visibility( setting.get() );5209 setting.bind( visibility );5210 });5211 });5212 });5213 });5214 5215 5186 api.control( 'background_preset', function( control ) { 5216 var visibility, defaultValues, values, toggleVisibility,updateSettings, preset;5187 var visibility, defaultValues, values, updateSettings, preset; 5217 5188 5218 5189 visibility = { // position, size, repeat, attachment 5219 5190 'default': [ false, false, false, false ], … … 5233 5204 5234 5205 values = { // position_x, position_y, size, repeat, attachment 5235 5206 'default': defaultValues, 5236 'fill': [ 'left', 'top', 'cover', 'no-repeat', 'fixed' ],5237 'fit': [ 'left', 'top', 'contain', 'no-repeat', 'fixed' ],5238 'repeat': [ 'left', 'top', 'auto', 'repeat', 'scroll']5207 'fill': [ defaultValues[0], defaultValues[1], 'cover', 'no-repeat', 'fixed' ], 5208 'fit': [ defaultValues[0], defaultValues[1], 'contain', defaultValues[3], 'fixed' ], 5209 'repeat': [ defaultValues[0], defaultValues[1], 'auto', 'repeat', defaultValues[4] ] 5239 5210 }; 5240 5211 5241 // @todo These should actually toggle the active state, but without the preview overriding the state in data.activeControls.5242 toggleVisibility = function( preset ) {5243 _.each( [ 'background_position', 'background_size', 'background_repeat', 'background_attachment' ], function( controlId, i ) {5244 var control = api.control( controlId );5245 if ( control ) {5246 control.container.toggle( visibility[ preset ][ i ] );5247 }5248 } );5249 };5250 5251 5212 updateSettings = function( preset ) { 5252 5213 _.each( [ 'background_position_x', 'background_position_y', 'background_size', 'background_repeat', 'background_attachment' ], function( settingId, i ) { 5253 5214 var setting = api( settingId ); … … 5258 5219 }; 5259 5220 5260 5221 preset = control.setting.get(); 5261 toggleVisibility( preset );5262 5222 5223 control.toggleControls = function( preset ) { 5224 api( 'background_image', function( setting ) { 5225 var to = setting.get(); 5226 5227 _.each( [ 'background_position', 'background_size', 'background_repeat', 'background_attachment' ], function( controlId, i ) { 5228 var control = api.control( controlId ); 5229 5230 if ( control ) { 5231 control.container.toggle( !! to ? visibility[ preset ][ i ] : false ); 5232 } 5233 }); 5234 }); 5235 }; 5236 5237 control.toggleControls( preset ); 5238 5263 5239 control.setting.bind( 'change', function( preset ) { 5264 toggleVisibility( preset ); 5240 control.toggleControls( preset ); 5241 5265 5242 if ( 'custom' !== preset ) { 5266 5243 updateSettings( preset ); 5267 5244 } … … 5405 5382 } ); 5406 5383 } ); 5407 5384 5385 // Control visibility for default controls 5386 $.each({ 5387 'background_image': { 5388 controls: [ 'background_preset' ], 5389 callback: function( to ) { return !! to; } 5390 }, 5391 'show_on_front': { 5392 controls: [ 'page_on_front', 'page_for_posts' ], 5393 callback: function( to ) { return 'page' === to; } 5394 }, 5395 'header_textcolor': { 5396 controls: [ 'header_textcolor' ], 5397 callback: function( to ) { return 'blank' !== to; } 5398 } 5399 }, function( settingId, o ) { 5400 api( settingId, function( setting ) { 5401 $.each( o.controls, function( i, controlId ) { 5402 api.control( controlId, function( control ) { 5403 var visibility = function( to ) { 5404 if ( 'background_preset' === controlId ) { 5405 control.toggleControls( control.setting.get() ); 5406 } 5407 5408 control.container.toggle( o.callback( to ) ); 5409 }; 5410 5411 visibility( setting.get() ); 5412 5413 setting.bind( visibility ); 5414 }); 5415 }); 5416 }); 5417 }); 5418 5408 5419 // Update the setting validities. 5409 5420 api.previewer.bind( 'selective-refresh-setting-validities', function handleSelectiveRefreshedSettingValidities( settingValidities ) { 5410 5421 api._handleSettingValidities( { -
wp-includes/class-wp-customize-manager.php
4063 4063 4064 4064 $this->add_control( new WP_Customize_Background_Image_Control( $this ) ); 4065 4065 4066 $background_preset = get_theme_support( 'custom-background', 'default-preset' ); 4067 4066 4068 $this->add_setting( 'background_preset', array( 4067 'default' => get_theme_support( 'custom-background', 'default-preset' ),4069 'default' => $background_preset, 4068 4070 'theme_supports' => 'custom-background', 4069 4071 'sanitize_callback' => array( $this, '_sanitize_background_setting' ), 4070 4072 ) ); … … 4104 4106 ) ) ); 4105 4107 4106 4108 $this->add_setting( 'background_size', array( 4107 'default' => get_theme_support( 'custom-background', 'default-size'),4109 'default' => _sanitize_custom_background_prop( 'size', $background_preset ), 4108 4110 'theme_supports' => 'custom-background', 4109 4111 'sanitize_callback' => array( $this, '_sanitize_background_setting' ), 4110 4112 ) ); … … 4121 4123 ) ); 4122 4124 4123 4125 $this->add_setting( 'background_repeat', array( 4124 'default' => get_theme_support( 'custom-background', 'default-repeat'),4126 'default' => _sanitize_custom_background_prop( 'repeat', $background_preset ), 4125 4127 'sanitize_callback' => array( $this, '_sanitize_background_setting' ), 4126 4128 'theme_supports' => 'custom-background', 4127 4129 ) ); … … 4133 4135 ) ); 4134 4136 4135 4137 $this->add_setting( 'background_attachment', array( 4136 'default' => get_theme_support( 'custom-background', 'default-attachment'),4138 'default' => _sanitize_custom_background_prop( 'attachment', $background_preset ), 4137 4139 'sanitize_callback' => array( $this, '_sanitize_background_setting' ), 4138 4140 'theme_supports' => 'custom-background', 4139 4141 ) ); -
wp-includes/theme.php
1537 1537 } 1538 1538 1539 1539 /** 1540 * Sanitize background preset property value. 1541 * 1542 * @since 4.8.0 1543 * @access protected 1544 * 1545 * @param string $prop A background property name (expects size, repeat or attachment). 1546 * @param string $preset Optional. A preset name (expects default, fill, fit, repeat or custom). Defaults to the default preset. 1547 * @return string|bool The sanitized background property value or false if the specified preset doesn't exist. 1548 */ 1549 function _sanitize_custom_background_prop( $prop, $preset = 'default' ) { 1550 if ( 'size' === $prop ) { 1551 if ( 'fill' === $preset ) { 1552 return 'cover'; 1553 } elseif ( 'fit' === $preset ) { 1554 return 'contain'; 1555 } elseif ( 'repeat' === $preset ) { 1556 return 'auto'; 1557 } else { 1558 return get_theme_support( 'custom-background', 'default-size' ); 1559 } 1560 } elseif ( 'repeat' === $prop ) { 1561 if ( 'fill' === $preset ) { 1562 return 'no-repeat'; 1563 } elseif ( 'repeat' === $preset ) { 1564 return 'repeat'; 1565 } else { 1566 return get_theme_support( 'custom-background', 'default-repeat' ); 1567 } 1568 } elseif ( 'attachment' === $prop ) { 1569 if ( 'fill' === $preset || 'fit' === $preset ) { 1570 $attachment = 'fixed'; 1571 } else { 1572 $attachment = get_theme_support( 'custom-background', 'default-attachment' ); 1573 } 1574 } 1575 1576 return false; 1577 } 1578 1579 /** 1540 1580 * Default custom background callback. 1541 1581 * 1542 1582 * @since 3.0.0 … … 1566 1606 if ( $background ) { 1567 1607 $image = ' background-image: url("' . esc_url_raw( $background ) . '");'; 1568 1608 1609 // Background Preset. 1610 $preset = get_theme_mod( 'background_preset', get_theme_support( 'custom-background', 'default-preset' ) ); 1611 1569 1612 // Background Position. 1570 1613 $position_x = get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) ); 1571 1614 $position_y = get_theme_mod( 'background_position_y', get_theme_support( 'custom-background', 'default-position-y' ) ); … … 1581 1624 $position = " background-position: $position_x $position_y;"; 1582 1625 1583 1626 // Background Size. 1584 $size = get_theme_mod( 'background_size', get_theme_support( 'custom-background', 'default-size') );1627 $size = get_theme_mod( 'background_size', _sanitize_custom_background_prop( 'size', $preset ) ); 1585 1628 1586 1629 if ( ! in_array( $size, array( 'auto', 'contain', 'cover' ), true ) ) { 1587 1630 $size = 'auto'; … … 1590 1633 $size = " background-size: $size;"; 1591 1634 1592 1635 // Background Repeat. 1593 $repeat = get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'default-repeat') );1636 $repeat = get_theme_mod( 'background_repeat', _sanitize_custom_background_prop( 'repeat', $preset ) ); 1594 1637 1595 1638 if ( ! in_array( $repeat, array( 'repeat-x', 'repeat-y', 'repeat', 'no-repeat' ), true ) ) { 1596 1639 $repeat = 'repeat'; … … 1599 1642 $repeat = " background-repeat: $repeat;"; 1600 1643 1601 1644 // Background Scroll. 1602 $attachment = get_theme_mod( 'background_attachment', get_theme_support( 'custom-background', 'default-attachment') );1645 $attachment = get_theme_mod( 'background_attachment', _sanitize_custom_background_prop( 'attachment', $preset ) ); 1603 1646 1604 1647 if ( 'fixed' !== $attachment ) { 1605 1648 $attachment = 'scroll';