Make WordPress Core


Ignore:
Timestamp:
10/15/2019 04:41:51 PM (5 years ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-customize-manager.php

    r46225 r46548  
    15181518        // Options.
    15191519        foreach ( $options as $name => $value ) {
    1520             if ( preg_match( '/^{{(?P<symbol>.+)}}$/', $value, $matches ) ) {
     1520
     1521            // Serialize the value to check for post symbols.
     1522            $value = maybe_serialize( $value );
     1523
     1524            if ( is_serialized( $value ) ) {
     1525                if ( preg_match( '/s:\d+:"{{(?P<symbol>.+)}}"/', $value, $matches ) ) {
     1526                    if ( isset( $posts[ $matches['symbol'] ] ) ) {
     1527                        $symbol_match = $posts[ $matches['symbol'] ]['ID'];
     1528                    } elseif ( isset( $attachment_ids[ $matches['symbol'] ] ) ) {
     1529                        $symbol_match = $attachment_ids[ $matches['symbol'] ];
     1530                    }
     1531
     1532                    // If we have any symbol matches, update the values.
     1533                    if ( isset( $symbol_match ) ) {
     1534                        // Replace found string matches with post IDs.
     1535                        $value = str_replace( $matches[0], "i:{$symbol_match}", $value );
     1536                    } else {
     1537                        continue;
     1538                    }
     1539                }
     1540            } elseif ( preg_match( '/^{{(?P<symbol>.+)}}$/', $value, $matches ) ) {
    15211541                if ( isset( $posts[ $matches['symbol'] ] ) ) {
    15221542                    $value = $posts[ $matches['symbol'] ]['ID'];
     
    15281548            }
    15291549
     1550            // Unserialize values after checking for post symbols, so they can be properly referenced.
     1551            $value = maybe_unserialize( $value );
     1552
    15301553            if ( empty( $changeset_data[ $name ] ) || ! empty( $changeset_data[ $name ]['starter_content'] ) ) {
    15311554                $this->set_post_value( $name, $value );
     
    15361559        // Theme mods.
    15371560        foreach ( $theme_mods as $name => $value ) {
    1538             if ( preg_match( '/^{{(?P<symbol>.+)}}$/', $value, $matches ) ) {
     1561
     1562            // Serialize the value to check for post symbols.
     1563            $value = maybe_serialize( $value );
     1564
     1565            // Check if value was serialized.
     1566            if ( is_serialized( $value ) ) {
     1567                if ( preg_match( '/s:\d+:"{{(?P<symbol>.+)}}"/', $value, $matches ) ) {
     1568                    if ( isset( $posts[ $matches['symbol'] ] ) ) {
     1569                        $symbol_match = $posts[ $matches['symbol'] ]['ID'];
     1570                    } elseif ( isset( $attachment_ids[ $matches['symbol'] ] ) ) {
     1571                        $symbol_match = $attachment_ids[ $matches['symbol'] ];
     1572                    }
     1573
     1574                    // If we have any symbol matches, update the values.
     1575                    if ( isset( $symbol_match ) ) {
     1576                        // Replace found string matches with post IDs.
     1577                        $value = str_replace( $matches[0], "i:{$symbol_match}", $value );
     1578                    } else {
     1579                        continue;
     1580                    }
     1581                }
     1582            } elseif ( preg_match( '/^{{(?P<symbol>.+)}}$/', $value, $matches ) ) {
    15391583                if ( isset( $posts[ $matches['symbol'] ] ) ) {
    15401584                    $value = $posts[ $matches['symbol'] ]['ID'];
     
    15451589                }
    15461590            }
     1591
     1592            // Unserialize values after checking for post symbols, so they can be properly referenced.
     1593            $value = maybe_unserialize( $value );
    15471594
    15481595            // Handle header image as special case since setting has a legacy format.
Note: See TracChangeset for help on using the changeset viewer.