[wp-trac] [WordPress Trac] #35168: 4.4 Customizer - serialized options can no longer be created

WordPress Trac noreply at wordpress.org
Sat Dec 19 21:56:36 UTC 2015


#35168: 4.4 Customizer - serialized options can no longer be created
--------------------------+------------------------------
 Reporter:  Looimaster    |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Customize     |     Version:  4.4
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------------------

Old description:

> When I do this:
> {{{
> function test_customize_register() {
> $wp_customize->add_setting( 'my_theme_name_options[my_option_name]',
> array(
>         'default' => '',
>         'type' => 'option',
>         'transport' => 'postMessage',
> ) );
>
> $wp_customize->add_control( new WP_Customize_Control( $wp_customize,
> 'my_theme_name_options[my_option_name]', array(
>         'label' => __( 'My label', 'theme-name' ),
>         'section' => 'my_section_name',
>         'type' => 'textarea',
> ) ) );
> }
> add_action( 'customize_register', 'test_customize_register' );
> }}}
> it doesn't CREATE `my_theme_name_options[my_option_name]` in `wp_options`
> database table (not correct).
>
> However, if `my_option_name` already exists in `my_theme_name_options` in
> `wp_options` database table then it is UPDATED (correct).
>
> When I do it as `theme_mod` it works:
>
> {{{
>
> $wp_customize->add_setting( 'my_option_name', array(
>         'default' => '',
>         'type' => 'theme_mod',
>         'transport' => 'postMessage',
> ) );
>
> $wp_customize->add_control( new WP_Customize_Control( $wp_customize,
> 'my_option_name', array(
>         'label' => __( 'My label', 'theme-name' ),
>         'section' => 'my_section_name',
>         'type' => 'textarea',
> ) ) );
> }}}
>

> What I tried:
> * Made sure there are no PHP/JS errors, the file is almost as simple as
> this.
> * Enabled WP_DEBUG and logs and there were no PHP errors.
> * Clicking "Save & Publish" indicates as if saving was successful but
> upon page refresh option is not created.
> * PHPMyAdmin doesn't show that database option is updated.
> * When I update this database option by other means (e.g. from admin
> page) it works.
> * Re-installed WordPress 4.4 in Dashboard > Updates.
> * Switched `textarea` to default field.
> * Created more fields and shortened
> `my_theme_name_options[my_option_name]` to `my_opts[opt_name]` but it
> didn't help.
> * Finally, created non-serialized `option` called `my_option_name` and it
> works (such option is CREATED and can be UPDATED).
>
> Conclusion: Serialized database entries are not created. They can be
> updated though if they were created outside Customizer.

New description:

 When I do this:

 {{{#!php
 <?php
 function test_customize_register() {
 $wp_customize->add_setting( 'my_theme_name_options[my_option_name]',
 array(
         'default' => '',
         'type' => 'option',
         'transport' => 'postMessage',
 ) );

 $wp_customize->add_control( new WP_Customize_Control( $wp_customize,
 'my_theme_name_options[my_option_name]', array(
         'label' => __( 'My label', 'theme-name' ),
         'section' => 'my_section_name',
         'type' => 'textarea',
 ) ) );
 }
 add_action( 'customize_register', 'test_customize_register' );
 }}}
 it doesn't CREATE `my_theme_name_options[my_option_name]` in `wp_options`
 database table (not correct).

 However, if `my_option_name` already exists in `my_theme_name_options` in
 `wp_options` database table then it is UPDATED (correct).

 When I do it as `theme_mod` it works:

 {{{#!php
 <?php
 $wp_customize->add_setting( 'my_option_name', array(
         'default' => '',
         'type' => 'theme_mod',
         'transport' => 'postMessage',
 ) );

 $wp_customize->add_control( new WP_Customize_Control( $wp_customize,
 'my_option_name', array(
         'label' => __( 'My label', 'theme-name' ),
         'section' => 'my_section_name',
         'type' => 'textarea',
 ) ) );
 }}}


 What I tried:
 * Made sure there are no PHP/JS errors, the file is almost as simple as
 this.
 * Enabled WP_DEBUG and logs and there were no PHP errors.
 * Clicking "Save & Publish" indicates as if saving was successful but upon
 page refresh option is not created.
 * PHPMyAdmin doesn't show that database option is updated.
 * When I update this database option by other means (e.g. from admin page)
 it works.
 * Re-installed WordPress 4.4 in Dashboard > Updates.
 * Switched `textarea` to default field.
 * Created more fields and shortened
 `my_theme_name_options[my_option_name]` to `my_opts[opt_name]` but it
 didn't help.
 * Finally, created non-serialized `option` called `my_option_name` and it
 works (such option is CREATED and can be UPDATED).

 Conclusion: Serialized database entries are not created. They can be
 updated though if they were created outside Customizer.

--

Comment (by westonruter):

 @Looimaster From your first example with options, I can see that
 `$wp_customize` would is undefined since it isn't being passed in to the
 function, and it isn't being declared as `global`. Is that just a typo in
 the description?

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


More information about the wp-trac mailing list