[wp-trac] [WordPress Trac] #45484: starter content theme_mods/options throw php warning if not string

WordPress Trac noreply at wordpress.org
Fri Mar 22 03:40:28 UTC 2019


#45484: starter content theme_mods/options throw php warning if not string
-------------------------------------+------------------------------
 Reporter:  timph                    |       Owner:  (none)
     Type:  defect (bug)             |      Status:  new
 Priority:  normal                   |   Milestone:  Awaiting Review
Component:  Customize                |     Version:  4.7
 Severity:  normal                   |  Resolution:
 Keywords:  has-patch needs-testing  |     Focuses:
-------------------------------------+------------------------------
Changes (by timph):

 * keywords:  needs-patch => has-patch needs-testing


Comment:

 Patch can be tested by adding this code to twenty-nineteen's
 **functions.php**:

 {{{
 add_action( 'after_setup_theme', 'add_testing_theme_support' );
 add_action( 'customize_register', 'add_testing_customizer_settings' );

 function add_testing_theme_support() {
         add_theme_support( 'starter-content', [
                 'attachments' => [
                         'test' => [
                                 'post_title' => 'testing for post ID',
                                 'file' => 'screenshot.png',
                         ],
                 ],
                 'theme_mods' => [
                         'testing' => [ 1, '{{test}}', 3 ],
                 ],
                 'options' => [
                         'testing' => [ 1, 2, '{{test}}' ],
                 ],
         ] );
 }

 function add_testing_customizer_settings( $wp_customize ) {
         $wp_customize->add_setting( 'testing' , [
                 'default'     => 0,
                 'transport'   => 'postMessage',
         ] );
 }
 }}}

 The patch does the follow steps for theme_mods and options:
 1. serialize with **maybe_serialize()**
 2. checks for post symbol matches on strings for theme_mod/option values.
 3. replaces these strings with post ID ints
 4. unserialize with **maybe_unserialize()** so values can be properly
 used.

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


More information about the wp-trac mailing list