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

WordPress Trac noreply at wordpress.org
Thu Jan 5 11:40:50 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.2
Component:  Customize           |     Version:  4.7
 Severity:  normal              |  Resolution:
 Keywords:  needs-patch         |     Focuses:
--------------------------------+--------------------

Comment (by cdog):

 OK, this should be better documented. It works as designed.

 This should get you working:

 {{{
 add_theme_support( 'custom-background', array(
         'default-image'      => get_template_directory_uri() . '/img
 /islemag-background.jpg',
         'default-size'       => 'cover',
         'default-repeat'     => 'no-repeat',
         'default-attachment' => 'fixed',
 ) );
 }}}

 Anytime the ''Default'' preset is selected it will revert to your theme's
 default settings.

 Also make sure to remove any theme mods if already set (using wp-cli):

 {{{
 $ wp theme mod remove background_size background_position_x
 background_position_y background_repeat background_attachment
 }}}

 The ''Default'' preset is intended to be altered by themes. A theme can
 define its own defaults by overriding core defults. See '''wp-
 includes/theme.php''':

 {{{
 $defaults = array(
         'default-image'          => '',
         'default-preset'         => 'default',
         'default-position-x'     => 'left',
         'default-position-y'     => 'top',
         'default-size'           => 'auto',
         'default-repeat'         => 'repeat',
         'default-attachment'     => 'scroll',
         'default-color'          => '',
         …
 );
 }}}

 The other presents can't be altered (and shouldn't; doing so can cause
 unexpected results). The 'default-preset' should be set other than
 'default' only when you want to use an already defined preset exactly as
 it is. Doing so requires you to set all options according to the preset
 (maybe we can improve this). See '''wp-admin/js/customize-controls.js''':

 {{{
 values = { // position_x, position_y, size, repeat, attachment
         'default': defaultValues,
         'fill': [ 'left', 'top', 'cover', 'no-repeat', 'fixed' ],
         'fit': [ 'left', 'top', 'contain', 'no-repeat', 'fixed' ],
         'repeat': [ 'left', 'top', 'auto', 'repeat', 'scroll' ]
 };
 }}}

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


More information about the wp-trac mailing list