WP_Customize_Manager::preserve_insert_changeset_post_content()publicWP 5.4.1

Preserves the initial JSON post_content passed to save into the post.

This is needed to prevent KSES and other content_save_pre filters from corrupting JSON data.

Note that WP_Customize_Manager::validate_setting_values() have already run on the setting values being serialized as JSON into the post content so it is pre-sanitized.

Also, the sanitization logic is re-run through the respective WP_Customize_Setting::sanitize() method when being read out of the changeset, via WP_Customize_Manager::post_value(), and this sanitized value will also be sent into WP_Customize_Setting::update() for persisting to the DB.

Multiple users can collaborate on a single changeset, where one user may have the unfiltered_html capability but another may not. A user with unfiltered_html may add a script tag to some field which needs to be kept intact even when another user updates the changeset to modify another field when they do not have unfiltered_html.

Метод класса: WP_Customize_Manager{}

Хуков нет.

Возвращает

Массив. Filtered post data.

Использование

$WP_Customize_Manager = new WP_Customize_Manager();
$WP_Customize_Manager->preserve_insert_changeset_post_content( $data, $postarr, $unsanitized_postarr );
$data(массив) (обязательный)
An array of slashed and processed post data.
$postarr(массив) (обязательный)
An array of sanitized (and slashed) but otherwise unmodified post data.
$unsanitized_postarr(массив) (обязательный)
An array of slashed yet unsanitized and unprocessed post data as originally passed to wp_insert_post().

Список изменений

С версии 5.4.1 Введена.

Код WP_Customize_Manager::preserve_insert_changeset_post_content() WP 6.5.2

public function preserve_insert_changeset_post_content( $data, $postarr, $unsanitized_postarr ) {
	if (
		isset( $data['post_type'] ) &&
		isset( $unsanitized_postarr['post_content'] ) &&
		'customize_changeset' === $data['post_type'] ||
		(
			'revision' === $data['post_type'] &&
			! empty( $data['post_parent'] ) &&
			'customize_changeset' === get_post_type( $data['post_parent'] )
		)
	) {
		$data['post_content'] = $unsanitized_postarr['post_content'];
	}
	return $data;
}