/** * Populate post values and $_POST['customized'] wth the snapshot's data. * * Plugins used to have to dynamically register settings by inspecting the * $_POST['customized'] var and manually re-parse and inspect to see if it * contains settings that wouldn't be registered otherwise. This ensures * that these plugins will continue to work. * * Note that this can't be called prior to the setup_theme action or else * magic quotes may end up getting added twice. * * @see Customize_Snapshot_Manager::should_import_and_preview_snapshot() */ public function import_snapshot_data() { /* * We don't merge the snapshot data with any existing existing unsanitized * post values since should_import_and_preview_snapshot returns false if * there is any existing data in the Customizer state. This is to prevent * clobbering existing values (or previewing non-snapshotted values on frontend). * Note that wp.customize.Snapshots.extendPreviewerQuery() will extend the * previewer data to include the current snapshot UUID. */ $snapshot_values = array_filter(wp_list_pluck($this->snapshot->data(), 'value'), function ($value) { return !is_null($value); }); // Populate input vars for back-compat. $_POST['customized'] = wp_slash(wp_json_encode($snapshot_values)); // @codingStandardsIgnoreStart $_REQUEST['customized'] = $_POST['customized']; // @codingStandardsIgnoreEnd foreach ($snapshot_values as $setting_id => $value) { $this->customize_manager->set_post_value($setting_id, $value); } }
/** * Test set with varying setting params. * * @see Customize_Snapshot::set() */ function test_set_with_varying_setting_params() { $manager = new Customize_Snapshot_Manager($this->plugin); $manager->init(); $snapshot = new Customize_Snapshot($manager, self::UUID); $result = $snapshot->set(array('foo' => array('value' => 'ok'))); $this->assertNull($result['errors']); $resultant_data = $snapshot->data(); $this->assertEquals('ok', $resultant_data['foo']['value']); // Check setting a param without a value, ensuring that foo still remains but snapshot is amended. $result = $snapshot->set(array('bar' => array('extra' => 'ok'))); $this->assertNull($result['errors']); $resultant_data = $snapshot->data(); $this->assertEquals('ok', $resultant_data['foo']['value']); $this->assertArrayHasKey('extra', $resultant_data['bar']); $this->assertNull($resultant_data['bar']['value']); }