GC_Customize_Widgets::gc_ajax_update_widget()
最后更新于:2021-11-27 12:58:50
GC_Customize_Widgets::gc_ajax_update_widget()Updates widget settings asynchronously.
源文件
文件: gc-includes/class-gc-customize-widgets.php
public function gc_ajax_update_widget() {
if ( ! is_user_logged_in() ) {
gc_die( 0 );
}
check_ajax_referer( 'update-widget', 'nonce' );
if ( ! current_user_can( 'edit_theme_options' ) ) {
gc_die( -1 );
}
if ( empty( $_POST['widget-id'] ) ) {
gc_send_json_error( 'missing_widget-id' );
}
/** This action is documented in gc-admin/includes/ajax-actions.php */
do_action( 'load-widgets.php' ); // phpcs:ignore GeChiUI.NamingConventions.ValidHookName.UseUnderscores
/** This action is documented in gc-admin/includes/ajax-actions.php */
do_action( 'widgets.php' ); // phpcs:ignore GeChiUI.NamingConventions.ValidHookName.UseUnderscores
/** This action is documented in gc-admin/widgets.php */
do_action( 'sidebar_admin_setup' );
$widget_id = $this->get_post_value( 'widget-id' );
$parsed_id = $this->parse_widget_id( $widget_id );
$id_base = $parsed_id['id_base'];
$is_updating_widget_template = (
isset( $_POST[ 'widget-' . $id_base ] )
&&
is_array( $_POST[ 'widget-' . $id_base ] )
&&
preg_match( '/__i__|%i%/', key( $_POST[ 'widget-' . $id_base ] ) )
);
if ( $is_updating_widget_template ) {
gc_send_json_error( 'template_widget_not_updatable' );
}
$updated_widget = $this->call_widget_update( $widget_id ); // => {instance,form}
if ( is_gc_error( $updated_widget ) ) {
gc_send_json_error( $updated_widget->get_error_code() );
}
$form = $updated_widget['form'];
$instance = $this->sanitize_widget_js_instance( $updated_widget['instance'], $id_base );
gc_send_json_success( compact( 'form', 'instance' ) );
}