GC_Customize_Widgets::sanitize_widget_js_instance()
最后更新于:2021-11-27 12:24:23
GC_Customize_Widgets::sanitize_widget_js_instance( array$value, string$id_base=null)Converts a widget instance into JSON-representable format.
参数
- $value
-
(array) (Required) Widget instance to convert to JSON.
- $id_base
-
(string) (Optional) Base of the ID of the widget being sanitized.
Default value: null
响应
(array) JSON-converted widget instance.
源文件
文件: gc-includes/class-gc-customize-widgets.php
public function sanitize_widget_js_instance( $value, $id_base = null ) {
global $gc_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 && gc_use_widgets_block_editor() ) {
$widget_object = $gc_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;
}