[wp-trac] [WordPress Trac] #36633: Customizer Doesn't Save Defaults in The Database for a Theme

WordPress Trac noreply at wordpress.org
Mon Apr 25 04:24:48 UTC 2016


#36633: Customizer Doesn't Save Defaults in The Database for a Theme
--------------------------------+------------------------------
 Reporter:  mrahmadawais        |       Owner:
     Type:  enhancement         |      Status:  reopened
 Priority:  normal              |   Milestone:  Awaiting Review
Component:  Customize           |     Version:  trunk
 Severity:  normal              |  Resolution:
 Keywords:  dev-feedback close  |     Focuses:
--------------------------------+------------------------------

Comment (by mrahmadawais):

 Replying to [comment:5 westonruter]:
 > @mrahmadawais thanks for explaining. Yes, I can see how this would be
 confusing. If this were to be fixed, the approach I'd
 > .....

 Yup! The default array makes a lot of sense. That way if I really want to
 initialize the options, I can otherwise it simplifies things.

 P.S. This is what I am doing at the moment with the defaults array.

 {{{#!php
 <?php
 /**
  * Initialize Customizer settings with defaults.
  *
  * @since 1.0.0
  */
 if ( ! function_exists( 'vr_customizer_init_defaults' ) ) {
         add_action( 'customize_register', 'vr_customizer_init_defaults' );
         function vr_customizer_init_defaults( $wp_customize ) {
                 // Just in case.
                 global $wp_customize;

                 // Be safe.
                 if ( ! isset( $wp_customize ) ) {
                         return;
                 }

                 $vr_settings_array = array(
                         'vr_hide_call',
                         'vr_hide_fb',
                         'vr_fb_url',
                         'vr_hide_twt',
                         'vr_twt_url',
                         'vr_hide_gplus',
                         'vr_gplus_url',
                         'vr_hide_skp',
                         'vr_skp_url',
                         'vr_hide_li',
                         'vr_li_url',
                         'vr_hide_ytube',
                         'vr_ytube_url',
                         'vr_hide_insta',
                         'vr_insta_url',
                         'vr_hide_vim',
                         'vr_vim_url'
                 );

                 foreach ( $vr_settings_array as $id ) {
                         $setting = $wp_customize->get_setting( $id );

                         $value = get_theme_mod( $id );
                         if ( ! isset( $value ) || false == $value ) {
                                 set_theme_mod( $setting->id,
 $setting->default );
                         }
                 } // foreach ended.
         } // vr_customizer_init_defaults() ended.
 } // function_exists() ended.
 }}}

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


More information about the wp-trac mailing list