WP_Customize_Widgets::call_widget_update() – Finds and invokes the widget update and control callbacks.
You appear to be a bot. Output may be restricted
Description
Finds and invokes the widget update and control callbacks.
Requires that $_POST
be populated with the instance data.
Usage
$array|WP_Error = WP_Customize_Widgets::call_widget_update( $widget_id );
Parameters
- $widget_id
- ( string ) required – Widget ID.
Returns
array|WP_Error Array containing the updated widget information. A WP_Error object, otherwise.
Source
File name: wordpress/wp-includes/class-wp-customize-widgets.php
Lines:
1 to 100 of 113
public function call_widget_update( $widget_id ) { global $wp_registered_widget_updates, $wp_registered_widget_controls; $setting_id = $this->WP_Customize_Widgets::get_setting_id( $widget_id ); /* * Make sure that other setting changes have previewed since this widget * may depend on them (e.g. Menus being present for Navigation Menu widget). */ if ( ! did_action( 'customize_preview_init' ) ) { foreach ( $this->manager->settings() as $setting ) { if ( $setting->id !== $setting_id ) { $setting->preview(); } } } $this->WP_Customize_Widgets::start_capturing_option_updates(); $parsed_id = $this->WP_Customize_Widgets::parse_widget_id( $widget_id ); $option_name = 'widget_' . $parsed_id['id_base']; /* * If a previously-sanitized instance is provided, populate the input vars * with its values so that the widget update callback will read this instance */ $added_input_vars = array(); if ( ! empty( $_POST['sanitized_widget_setting'] ) ) { $sanitized_widget_setting = json_decode( $this->WP_Customize_Widgets::get_post_value( 'sanitized_widget_setting' ), true ); if ( false === $sanitized_widget_setting ) { $this->WP_Customize_Widgets::stop_capturing_option_updates(); return new WP_Error( 'widget_setting_malformed' ); } $instance = $this->WP_Customize_Widgets::sanitize_widget_instance( $sanitized_widget_setting, $parsed_id['id_base'] ); if ( is_null( $instance ) ) { $this->WP_Customize_Widgets::stop_capturing_option_updates(); return new WP_Error( 'widget_setting_unsanitized' ); } if ( ! is_null( $parsed_id['number'] ) ) { $value = array(); $value[ $parsed_id['number'] ] = $instance; $key = 'widget-' . $parsed_id['id_base']; $_REQUEST[ $key ] = wp_slash( $value ); $_POST[ $key ] = $_REQUEST[ $key ]; $added_input_vars[] = $key; } else { foreach ( $instance as $key => $value ) { $_REQUEST[ $key ] = wp_slash( $value ); $_POST[ $key ] = $_REQUEST[ $key ]; $added_input_vars[] = $key; } } } // Invoke the widget update callback. foreach ( (array) $wp_registered_widget_updates as $name => $control ) { if ( $name === $parsed_id['id_base'] && is_callable( $control['callback'] ) ) { ob_start(); call_user_func_array( $control['callback'], $control['params'] ); ob_end_clean(); break; } } // Clean up any input vars that were manually added. foreach ( $added_input_vars as $key ) { unset( $_POST[ $key ] ); unset( $_REQUEST[ $key ] ); } // Make sure the expected option was updated. if ( 0 !== $this->WP_Customize_Widgets::count_captured_options() ) { if ( $this->WP_Customize_Widgets::count_captured_options() > 1 ) { $this->WP_Customize_Widgets::stop_capturing_option_updates(); return new WP_Error( 'widget_setting_too_many_options' ); } $updated_option_name = key( $this->WP_Customize_Widgets::get_captured_options() ); if ( $updated_option_name !== $option_name ) { $this->WP_Customize_Widgets::stop_capturing_option_updates(); return new WP_Error( 'widget_setting_unexpected_option' ); } } // Obtain the widget instance. $option = $this->WP_Customize_Widgets::get_captured_option( $option_name ); if ( null !== $parsed_id['number'] ) { $instance = $option[ $parsed_id['number'] ]; } else { $instance = $option; } /* * Override the incoming $_POST['customized'] for a newly-created widget's * setting with the new $instance so that the preview filter currently * in place from WP_Customize_Setting::preview() will use this value * instead of the default widget instance value (an empty array). */ $this->manager->set_post_value( $setting_id, $this->WP_Customize_Widgets::sanitize_widget_js_instance( $instance, $parsed_id['id_base'] ) );