WordPress.org

Make WordPress Core

Changeset 41243


Ignore:
Timestamp:
08/12/2017 09:20:23 PM (2 years ago)
Author:
westonruter
Message:

Customize: Fix PHP warning raised when deleting a setting from changeset via passing null as params in WP_Customize_Manager::save_changeset_post().

Props dlh.
Fixes #41621.

Location:
trunk
Files:
2 edited

Legend:

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

    r41205 r41243  
    22792279        // Amend post values with any supplied data.
    22802280        foreach ( $args['data'] as $setting_id => $setting_params ) {
    2281             if ( array_key_exists( 'value', $setting_params ) ) {
     2281            if ( is_array( $setting_params ) && array_key_exists( 'value', $setting_params ) ) {
    22822282                $this->set_post_value( $setting_id, $setting_params['value'] ); // Add to post values so that they can be validated and sanitized.
    22832283            }
  • trunk/tests/phpunit/tests/customize/manager.php

    r41205 r41243  
    12471247
    12481248    /**
     1249     * Test passing `null` for a setting ID to remove it from the changeset.
     1250     *
     1251     * @ticket 41621
     1252     * @covers WP_Customize_Manager::save_changeset_post()
     1253     */
     1254    function test_remove_setting_from_changeset_post() {
     1255        $uuid = wp_generate_uuid4();
     1256
     1257        $manager = $this->create_test_manager( $uuid );
     1258        $manager->save_changeset_post( array(
     1259            'data' => array(
     1260                'scratchpad' => array(
     1261                    'value' => 'foo',
     1262                ),
     1263            ),
     1264        ) );
     1265
     1266        // Create a new manager so post values are unset.
     1267        $manager = $this->create_test_manager( $uuid );
     1268
     1269        $this->assertArrayHasKey( 'scratchpad', $manager->changeset_data() );
     1270
     1271        $manager->save_changeset_post( array(
     1272            'data' => array(
     1273                'scratchpad' => null,
     1274            ),
     1275        ) );
     1276
     1277        $this->assertArrayNotHasKey( 'scratchpad', $manager->changeset_data() );
     1278    }
     1279
     1280    /**
    12491281     * Test writing changesets and publishing with users who can unfiltered_html and those who cannot.
    12501282     *
Note: See TracChangeset for help on using the changeset viewer.