Ticket #39461: 39561.diff
File 39561.diff, 11.5 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
5136 5136 // Initialize the connection with the parent frame. 5137 5137 parent.send( 'ready' ); 5138 5138 5139 // Control visibility for default controls5140 $.each({5141 'background_image': {5142 controls: [ 'background_preset', 'background_position', 'background_size', 'background_repeat', 'background_attachment' ],5143 callback: function( to ) { return !! to; }5144 },5145 'show_on_front': {5146 controls: [ 'page_on_front', 'page_for_posts' ],5147 callback: function( to ) { return 'page' === to; }5148 },5149 'header_textcolor': {5150 controls: [ 'header_textcolor' ],5151 callback: function( to ) { return 'blank' !== to; }5152 }5153 }, function( settingId, o ) {5154 api( settingId, function( setting ) {5155 $.each( o.controls, function( i, controlId ) {5156 api.control( controlId, function( control ) {5157 var visibility = function( to ) {5158 control.container.toggle( o.callback( to ) );5159 };5160 5161 visibility( setting.get() );5162 setting.bind( visibility );5163 });5164 });5165 });5166 });5167 5168 5139 api.control( 'background_preset', function( control ) { 5169 var visibility, defaultValues, values, toggleVisibility,updateSettings, preset;5140 var visibility, defaultValues, values, updateSettings, preset; 5170 5141 5171 5142 visibility = { // position, size, repeat, attachment 5172 5143 'default': [ false, false, false, false ], … … 5186 5157 5187 5158 values = { // position_x, position_y, size, repeat, attachment 5188 5159 'default': defaultValues, 5189 'fill': [ 'left', 'top', 'cover', 'no-repeat', 'fixed' ],5190 'fit': [ 'left', 'top', 'contain', 'no-repeat', 'fixed' ],5191 'repeat': [ 'left', 'top', 'auto', 'repeat', 'scroll']5160 'fill': [ defaultValues[0], defaultValues[1], 'cover', 'no-repeat', 'fixed' ], 5161 'fit': [ defaultValues[0], defaultValues[1], 'contain', defaultValues[3], 'fixed' ], 5162 'repeat': [ defaultValues[0], defaultValues[1], 'auto', 'repeat', defaultValues[4] ] 5192 5163 }; 5193 5164 5194 // @todo These should actually toggle the active state, but without the preview overriding the state in data.activeControls.5195 toggleVisibility = function( preset ) {5196 _.each( [ 'background_position', 'background_size', 'background_repeat', 'background_attachment' ], function( controlId, i ) {5197 var control = api.control( controlId );5198 if ( control ) {5199 control.container.toggle( visibility[ preset ][ i ] );5200 }5201 } );5202 };5203 5204 5165 updateSettings = function( preset ) { 5205 5166 _.each( [ 'background_position_x', 'background_position_y', 'background_size', 'background_repeat', 'background_attachment' ], function( settingId, i ) { 5206 5167 var setting = api( settingId ); … … 5211 5172 }; 5212 5173 5213 5174 preset = control.setting.get(); 5214 toggleVisibility( preset );5215 5175 5176 control.toggleControls = function( preset ) { 5177 api( 'background_image', function( setting ) { 5178 var to = setting.get(); 5179 5180 _.each( [ 'background_position', 'background_size', 'background_repeat', 'background_attachment' ], function( controlId, i ) { 5181 var control = api.control( controlId ); 5182 5183 if ( control ) { 5184 control.container.toggle( !! to ? visibility[ preset ][ i ] : false ); 5185 } 5186 }); 5187 }); 5188 }; 5189 5190 control.toggleControls( preset ); 5191 5216 5192 control.setting.bind( 'change', function( preset ) { 5217 toggleVisibility( preset ); 5193 control.toggleControls( preset ); 5194 5218 5195 if ( 'custom' !== preset ) { 5219 5196 updateSettings( preset ); 5220 5197 } … … 5358 5335 } ); 5359 5336 } ); 5360 5337 5338 // Control visibility for default controls 5339 $.each({ 5340 'background_image': { 5341 controls: [ 'background_preset' ], 5342 callback: function( to ) { return !! to; } 5343 }, 5344 'show_on_front': { 5345 controls: [ 'page_on_front', 'page_for_posts' ], 5346 callback: function( to ) { return 'page' === to; } 5347 }, 5348 'header_textcolor': { 5349 controls: [ 'header_textcolor' ], 5350 callback: function( to ) { return 'blank' !== to; } 5351 } 5352 }, function( settingId, o ) { 5353 api( settingId, function( setting ) { 5354 $.each( o.controls, function( i, controlId ) { 5355 api.control( controlId, function( control ) { 5356 var visibility = function( to ) { 5357 if ( 'background_preset' === controlId ) { 5358 control.toggleControls( control.setting.get() ); 5359 } 5360 5361 control.container.toggle( o.callback( to ) ); 5362 }; 5363 5364 visibility( setting.get() ); 5365 5366 setting.bind( visibility ); 5367 }); 5368 }); 5369 }); 5370 }); 5371 5361 5372 // Update the setting validities. 5362 5373 api.previewer.bind( 'selective-refresh-setting-validities', function handleSelectiveRefreshedSettingValidities( settingValidities ) { 5363 5374 api._handleSettingValidities( { -
wp-includes/class-wp-customize-manager.php
3990 3990 3991 3991 $this->add_control( new WP_Customize_Background_Image_Control( $this ) ); 3992 3992 3993 $background_preset = get_theme_support( 'custom-background', 'default-preset' ); 3994 3993 3995 $this->add_setting( 'background_preset', array( 3994 'default' => get_theme_support( 'custom-background', 'default-preset' ),3996 'default' => $background_preset, 3995 3997 'theme_supports' => 'custom-background', 3996 3998 'sanitize_callback' => array( $this, '_sanitize_background_setting' ), 3997 3999 ) ); … … 4031 4033 ) ) ); 4032 4034 4033 4035 $this->add_setting( 'background_size', array( 4034 'default' => get_theme_support( 'custom-background', 'default-size'),4036 'default' => _sanitize_custom_background_prop( 'size', $background_preset ), 4035 4037 'theme_supports' => 'custom-background', 4036 4038 'sanitize_callback' => array( $this, '_sanitize_background_setting' ), 4037 4039 ) ); … … 4048 4050 ) ); 4049 4051 4050 4052 $this->add_setting( 'background_repeat', array( 4051 'default' => get_theme_support( 'custom-background', 'default-repeat'),4053 'default' => _sanitize_custom_background_prop( 'repeat', $background_preset ), 4052 4054 'sanitize_callback' => array( $this, '_sanitize_background_setting' ), 4053 4055 'theme_supports' => 'custom-background', 4054 4056 ) ); … … 4060 4062 ) ); 4061 4063 4062 4064 $this->add_setting( 'background_attachment', array( 4063 'default' => get_theme_support( 'custom-background', 'default-attachment'),4065 'default' => _sanitize_custom_background_prop( 'attachment', $background_preset ), 4064 4066 'sanitize_callback' => array( $this, '_sanitize_background_setting' ), 4065 4067 'theme_supports' => 'custom-background', 4066 4068 ) ); -
wp-includes/theme.php
1536 1536 echo get_background_color(); 1537 1537 } 1538 1538 1539 function _sanitize_custom_background_prop( $prop, $preset = 'default' ) { 1540 if ( 'size' === $prop ) { 1541 if ( 'fill' === $preset ) { 1542 return 'cover'; 1543 } elseif ( 'fit' === $preset ) { 1544 return 'contain'; 1545 } elseif ( 'repeat' === $preset ) { 1546 return 'auto'; 1547 } else { 1548 return get_theme_support( 'custom-background', 'default-size' ); 1549 } 1550 } elseif ( 'repeat' === $prop ) { 1551 if ( 'fill' === $preset ) { 1552 return 'no-repeat'; 1553 } elseif ( 'repeat' === $preset ) { 1554 return 'repeat'; 1555 } else { 1556 return get_theme_support( 'custom-background', 'default-repeat' ); 1557 } 1558 } elseif ( 'attachment' === $prop ) { 1559 if ( 'fill' === $preset || 'fit' === $preset ) { 1560 $attachment = 'fixed'; 1561 } else { 1562 $attachment = get_theme_support( 'custom-background', 'default-attachment' ); 1563 } 1564 } 1565 1566 return false; 1567 } 1568 1539 1569 /** 1540 1570 * Default custom background callback. 1541 1571 * … … 1566 1596 if ( $background ) { 1567 1597 $image = ' background-image: url("' . esc_url_raw( $background ) . '");'; 1568 1598 1599 // Background Preset. 1600 $preset = get_theme_mod( 'background_preset', get_theme_support( 'custom-background', 'default-preset' ) ); 1601 1569 1602 // Background Position. 1570 1603 $position_x = get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) ); 1571 1604 $position_y = get_theme_mod( 'background_position_y', get_theme_support( 'custom-background', 'default-position-y' ) ); … … 1581 1614 $position = " background-position: $position_x $position_y;"; 1582 1615 1583 1616 // Background Size. 1584 $size = get_theme_mod( 'background_size', get_theme_support( 'custom-background', 'default-size') );1617 $size = get_theme_mod( 'background_size', _sanitize_custom_background_prop( 'size', $preset ) ); 1585 1618 1586 1619 if ( ! in_array( $size, array( 'auto', 'contain', 'cover' ), true ) ) { 1587 1620 $size = 'auto'; … … 1590 1623 $size = " background-size: $size;"; 1591 1624 1592 1625 // Background Repeat. 1593 $repeat = get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'default-repeat') );1626 $repeat = get_theme_mod( 'background_repeat', _sanitize_custom_background_prop( 'repeat', $preset ) ); 1594 1627 1595 1628 if ( ! in_array( $repeat, array( 'repeat-x', 'repeat-y', 'repeat', 'no-repeat' ), true ) ) { 1596 1629 $repeat = 'repeat'; … … 1599 1632 $repeat = " background-repeat: $repeat;"; 1600 1633 1601 1634 // Background Scroll. 1602 $attachment = get_theme_mod( 'background_attachment', get_theme_support( 'custom-background', 'default-attachment') );1635 $attachment = get_theme_mod( 'background_attachment', _sanitize_custom_background_prop( 'attachment', $preset ) ); 1603 1636 1604 1637 if ( 'fixed' !== $attachment ) { 1605 1638 $attachment = 'scroll';