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. git-svn-id: https://develop.svn.wordpress.org/trunk@41243 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
440c8692e3
commit
7bff33a6eb
@ -2278,7 +2278,7 @@ final class WP_Customize_Manager {
|
|||||||
|
|
||||||
// Amend post values with any supplied data.
|
// Amend post values with any supplied data.
|
||||||
foreach ( $args['data'] as $setting_id => $setting_params ) {
|
foreach ( $args['data'] as $setting_id => $setting_params ) {
|
||||||
if ( array_key_exists( 'value', $setting_params ) ) {
|
if ( is_array( $setting_params ) && array_key_exists( 'value', $setting_params ) ) {
|
||||||
$this->set_post_value( $setting_id, $setting_params['value'] ); // Add to post values so that they can be validated and sanitized.
|
$this->set_post_value( $setting_id, $setting_params['value'] ); // Add to post values so that they can be validated and sanitized.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1245,6 +1245,38 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase {
|
|||||||
$this->assertEquals( $other_admin_user_id, $data['scratchpad']['user_id'] );
|
$this->assertEquals( $other_admin_user_id, $data['scratchpad']['user_id'] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test passing `null` for a setting ID to remove it from the changeset.
|
||||||
|
*
|
||||||
|
* @ticket 41621
|
||||||
|
* @covers WP_Customize_Manager::save_changeset_post()
|
||||||
|
*/
|
||||||
|
function test_remove_setting_from_changeset_post() {
|
||||||
|
$uuid = wp_generate_uuid4();
|
||||||
|
|
||||||
|
$manager = $this->create_test_manager( $uuid );
|
||||||
|
$manager->save_changeset_post( array(
|
||||||
|
'data' => array(
|
||||||
|
'scratchpad' => array(
|
||||||
|
'value' => 'foo',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
) );
|
||||||
|
|
||||||
|
// Create a new manager so post values are unset.
|
||||||
|
$manager = $this->create_test_manager( $uuid );
|
||||||
|
|
||||||
|
$this->assertArrayHasKey( 'scratchpad', $manager->changeset_data() );
|
||||||
|
|
||||||
|
$manager->save_changeset_post( array(
|
||||||
|
'data' => array(
|
||||||
|
'scratchpad' => null,
|
||||||
|
),
|
||||||
|
) );
|
||||||
|
|
||||||
|
$this->assertArrayNotHasKey( 'scratchpad', $manager->changeset_data() );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test writing changesets and publishing with users who can unfiltered_html and those who cannot.
|
* Test writing changesets and publishing with users who can unfiltered_html and those who cannot.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user