WordPress at Your Fingertips
function is not described

WP_Customize_Widgets::sanitize_widget_js_instance() public WP 3.9.0

Converts a widget instance into JSON-representable format.

{} It's a method of the class: WP_Customize_Widgets{}

No Hooks.

Return

Array. JSON-converted widget instance.

Usage

$WP_Customize_Widgets = new WP_Customize_Widgets();
$WP_Customize_Widgets->sanitize_widget_js_instance( $value, $id_base );
$value(array) (required)
Widget instance to convert to JSON.
$id_base(string)
Base of the ID of the widget being sanitized.
Default: null

Notes

  • Global. WP_Widget_Factory. $wp_widget_factory

Changelog

Since 3.9.0 Introduced.
Since 5.8.0 Added the $id_base parameter.

Code of WP_Customize_Widgets::sanitize_widget_js_instance() WP 5.8

<?php
public function sanitize_widget_js_instance( $value, $id_base = null ) {
	global $wp_widget_factory;

	if ( empty( $value['is_widget_customizer_js_value'] ) ) {
		$serialized = serialize( $value );

		$js_value = array(
			'encoded_serialized_instance'   => base64_encode( $serialized ),
			'title'                         => empty( $value['title'] ) ? '' : $value['title'],
			'is_widget_customizer_js_value' => true,
			'instance_hash_key'             => $this->get_instance_hash_key( $serialized ),
		);

		if ( $id_base && wp_use_widgets_block_editor() ) {
			$widget_object = $wp_widget_factory->get_widget_object( $id_base );
			if ( ! empty( $widget_object->widget_options['show_instance_in_rest'] ) ) {
				$js_value['raw_instance'] = (object) $value;
			}
		}

		return $js_value;
	}

	return $value;
}