[wp-trac] [WordPress Trac] #39461: default-preset option for custom background cannot be set by default

WordPress Trac noreply at wordpress.org
Wed Feb 8 11:29:09 UTC 2017


#39461: default-preset option for custom background cannot be set by default
--------------------------------+--------------------
 Reporter:  cristian-ungureanu  |       Owner:
     Type:  defect (bug)        |      Status:  new
 Priority:  normal              |   Milestone:  4.7.3
Component:  Customize           |     Version:  4.7
 Severity:  normal              |  Resolution:
 Keywords:  has-patch           |     Focuses:
--------------------------------+--------------------
Changes (by cdog):

 * keywords:  needs-patch => has-patch


Comment:

 Sorry for delay, got busy lately. The good news is that I just got 2
 tickets to WordCamp Europe! See you there :)

 Now on the patch. [attachment:39561.diff] (misspelled it, can someone
 rename it?) provides a solution for what we discussed and addresses a
 display issue when loading the customizer. Specifically some controls can
 toggle the display of other controls. Choosing a background image was
 either showing or hiding all background settings overriding the selected
 preset related controls (for example, the Default preset shouldn't display
 any controls; choosing an image was showing them).

 Next, I'll provide some working examples for a better understanding of the
 changes and how this can be used. The workflow from the interface remains
 the same.

 '''Example 1.''' Choosing a default preset (this could be `default`,
 `fill`, `fit`, `repeat` or `custom`)

 {{{
 add_theme_support( 'custom-background', array(
         'default-image'  => get_template_directory_uri() .
 '/img/autumn.jpg',
         'default-preset' => 'fill'
 ));
 }}}

 Specifying a value for `default-preset` will set the active preset and
 inherit all properties of the preset.

 '''Example 2.''' Overriding default settings for presets

 {{{
 add_theme_support( 'custom-background', array(
         'default-image'      => get_template_directory_uri() .
 '/img/autumn.jpg',
         'default-position-x' => 'center',
         'default-position-y' => 'center'
 ));
 }}}

 This will apply for all presets. Prior to the patch this was affecting the
 Default preset only. Switching a preset from one to another will revert to
 these values instead of core defaults.

 {{{
 add_theme_support( 'custom-background', array(
         'default-image'  => get_template_directory_uri() .
 '/img/autumn.jpg',
         'default-preset' => 'fit'
         'default-repeat' => 'no-repeat'
 ));
 }}}

 Because the Fit to Screen preset allows you to toggle the Repeat
 Background Image option from the interface now you can do the same from
 your theme.

 {{{
 add_theme_support( 'custom-background', array(
         'default-image'      => get_template_directory_uri() .
 '/img/autumn.jpg',
         'default-preset'     => 'fit'
         'default-attachment' => 'fixed'
 ));
 }}}

 The `default-attachment` property will be ignored in this case. It will
 affect only the presets that allow this change (like Default, Repeat and
 Custom). All values are sanitized to drop any invalid settings.

 '''Example 3.''' Owning the Default preset from a theme (revert to your
 own defaults instead of core defaults)

 {{{
 add_theme_support( 'custom-background', array(
         'default-image'      => get_template_directory_uri() .
 '/img/autumn.jpg',
         'default-preset'     => 'default',
         'default-position-x' => 'center',
         'default-position-y' => 'center',
         'default-size'       => 'cover',
         'default-repeat'     => 'no-repeat',
         'default-attachment' => 'fixed'
 ));
 }}}

 Doing this you will have your own Default preset.

 @celloexpressions hope this helps. I aimed for greater flexibility and to
 fix existing issues. Any feedback is welcome. Thanks!

--
Ticket URL: <https://core.trac.wordpress.org/ticket/39461#comment:9>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list