Make WordPress Core

Changes between Initial Version and Version 1 of Ticket #45484, comment 4


Ignore:
Timestamp:
03/22/2019 04:00:27 AM (6 years ago)
Author:
timph
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #45484, comment 4

    initial v1  
    3030}}}
    3131
    32 The patch does the follow steps for theme_mods and options:
    33 1. serialize with **maybe_serialize()**
    34 2. checks for post symbol matches on strings for theme_mod/option values.
    35 3. replaces these strings with post ID ints
    36 4. unserialize with **maybe_unserialize()** so values can be properly used.
     32If you're not using a **fresh_site** install, you will need to manually force that state, you can add this to the same **functions.php** file:
     33
     34{{{
     35update_option( 'fresh_site', 1  );
     36}}}
     37
     38Now go into the customizer, and you will get PHP warning for not being able to preg_match on the values passed as they are arrays, like these:
     39
     40
     41{{{
     42[22-Mar-2019 03:25:50 UTC] PHP Warning:  preg_match() expects parameter 2 to be string, array given in /srv/www/wordpress-default/public_html/wp-includes/class-wp-customize-manager.php on line 1526
     43[22-Mar-2019 03:25:50 UTC] PHP Warning:  preg_match() expects parameter 2 to be string, array given in /srv/www/wordpress-default/public_html/wp-includes/class-wp-customize-manager.php on line 1544
     44}}}
     45
     46Now apply patch, and follow the same steps.  You should no longer receive PHP warnings.
     47
     48From the browser console, you can verify the correct value is set in the array for the theme_mod using the customizer js api:
     49
     50{{{
     51wp.customize( 'testing' )();
     52}}}
     53
     54The code for options vs theme_mods is pretty much identical, so it could probably be consolidated if necessary.
     55
     56----
     57
     58The patch does the following steps for theme_mods and options:
     59
     601. serialize value with **maybe_serialize()**
     612. check for post symbol matches on strings.
     623. replace these strings with post ID ints.
     634. unserialize value with **maybe_unserialize()** so values can be properly used.