Customize: Ensure that WP_Customize_Manager::import_theme_starter_content() properly handles starter content with (nested) arrays as values.

Previously, searching for symbol references to replace with post or attachment IDs in array values resulted in a PHP warning.

Props timph, JarretC, SergeyBiryukov.
Fixes #45484.
Built from https://develop.svn.wordpress.org/trunk@46548


git-svn-id: http://core.svn.wordpress.org/trunk@46345 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2019-10-15 16:43:01 +00:00
parent 52dee3c19b
commit 71e8fedf6c
2 changed files with 50 additions and 3 deletions

View File

@ -1517,7 +1517,27 @@ final class WP_Customize_Manager {
// Options.
foreach ( $options as $name => $value ) {
if ( preg_match( '/^{{(?P<symbol>.+)}}$/', $value, $matches ) ) {
// Serialize the value to check for post symbols.
$value = maybe_serialize( $value );
if ( is_serialized( $value ) ) {
if ( preg_match( '/s:\d+:"{{(?P<symbol>.+)}}"/', $value, $matches ) ) {
if ( isset( $posts[ $matches['symbol'] ] ) ) {
$symbol_match = $posts[ $matches['symbol'] ]['ID'];
} elseif ( isset( $attachment_ids[ $matches['symbol'] ] ) ) {
$symbol_match = $attachment_ids[ $matches['symbol'] ];
}
// If we have any symbol matches, update the values.
if ( isset( $symbol_match ) ) {
// Replace found string matches with post IDs.
$value = str_replace( $matches[0], "i:{$symbol_match}", $value );
} else {
continue;
}
}
} elseif ( preg_match( '/^{{(?P<symbol>.+)}}$/', $value, $matches ) ) {
if ( isset( $posts[ $matches['symbol'] ] ) ) {
$value = $posts[ $matches['symbol'] ]['ID'];
} elseif ( isset( $attachment_ids[ $matches['symbol'] ] ) ) {
@ -1527,6 +1547,9 @@ final class WP_Customize_Manager {
}
}
// Unserialize values after checking for post symbols, so they can be properly referenced.
$value = maybe_unserialize( $value );
if ( empty( $changeset_data[ $name ] ) || ! empty( $changeset_data[ $name ]['starter_content'] ) ) {
$this->set_post_value( $name, $value );
$this->pending_starter_content_settings_ids[] = $name;
@ -1535,7 +1558,28 @@ final class WP_Customize_Manager {
// Theme mods.
foreach ( $theme_mods as $name => $value ) {
if ( preg_match( '/^{{(?P<symbol>.+)}}$/', $value, $matches ) ) {
// Serialize the value to check for post symbols.
$value = maybe_serialize( $value );
// Check if value was serialized.
if ( is_serialized( $value ) ) {
if ( preg_match( '/s:\d+:"{{(?P<symbol>.+)}}"/', $value, $matches ) ) {
if ( isset( $posts[ $matches['symbol'] ] ) ) {
$symbol_match = $posts[ $matches['symbol'] ]['ID'];
} elseif ( isset( $attachment_ids[ $matches['symbol'] ] ) ) {
$symbol_match = $attachment_ids[ $matches['symbol'] ];
}
// If we have any symbol matches, update the values.
if ( isset( $symbol_match ) ) {
// Replace found string matches with post IDs.
$value = str_replace( $matches[0], "i:{$symbol_match}", $value );
} else {
continue;
}
}
} elseif ( preg_match( '/^{{(?P<symbol>.+)}}$/', $value, $matches ) ) {
if ( isset( $posts[ $matches['symbol'] ] ) ) {
$value = $posts[ $matches['symbol'] ]['ID'];
} elseif ( isset( $attachment_ids[ $matches['symbol'] ] ) ) {
@ -1545,6 +1589,9 @@ final class WP_Customize_Manager {
}
}
// Unserialize values after checking for post symbols, so they can be properly referenced.
$value = maybe_unserialize( $value );
// Handle header image as special case since setting has a legacy format.
if ( 'header_image' === $name ) {
$name = 'header_image_data';

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.3-beta3-46547';
$wp_version = '5.3-beta3-46548';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.