widget_update_callback
Filter HookDescription
An RPC-style endpoint which can be used by clients to turn user input in a widget admin form into an encoded instance object. Accepts: - id: A widget type ID. - instance: A widget's encoded instance object. Optional. - form_data: Form data from submitting a widget's admin form. Optional. Returns: - instance: The encoded instance object after updating the widget with the given form data. - form: The widget's admin form after updating the widget with the given form data. / public function encode_form_data( $request ) { global $wp_widget_factory; $id = $request['id']; $widget_object = $wp_widget_factory->get_widget_object( $id ); if ( ! $widget_object ) { return new WP_Error( 'rest_invalid_widget', __( 'Cannot preview a widget that does not extend WP_Widget.' ), array( 'status' => 400 ) ); } /* Set the widget's number so that the id attributes in the HTML that we return are predictable.Hook Information
File Location |
wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php
View on GitHub
|
Hook Type | Filter |
Line Number | 513 |
Hook Parameters
Type | Name | Description |
---|---|---|
WP_REST_Request
|
$request
|
Full details about the request. |
Usage Examples
Basic Usage
<?php
// Hook into widget_update_callback
add_filter('widget_update_callback', 'my_custom_filter', 10, 1);
function my_custom_filter($request) {
// Your custom filtering logic here
return $request;
}
Source Code Context
wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php:513
- How this hook is used in WordPress core
<?php
508 $old_instance = $instance;
509
510 $instance = $widget_object->update( $new_instance, $old_instance );
511
512 /** This filter is documented in wp-includes/class-wp-widget.php */
513 $instance = apply_filters(
514 'widget_update_callback',
515 $instance,
516 $new_instance,
517 $old_instance,
518 $widget_object
PHP Documentation
<?php
/**
* An RPC-style endpoint which can be used by clients to turn user input in
* a widget admin form into an encoded instance object.
*
* Accepts:
*
* - id: A widget type ID.
* - instance: A widget's encoded instance object. Optional.
* - form_data: Form data from submitting a widget's admin form. Optional.
*
* Returns:
* - instance: The encoded instance object after updating the widget with
* the given form data.
* - form: The widget's admin form after updating the widget with the
* given form data.
*
* @since 5.8.0
*
* @global WP_Widget_Factory $wp_widget_factory
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
*/
public function encode_form_data( $request ) {
global $wp_widget_factory;
$id = $request['id'];
$widget_object = $wp_widget_factory->get_widget_object( $id );
if ( ! $widget_object ) {
return new WP_Error(
'rest_invalid_widget',
__( 'Cannot preview a widget that does not extend WP_Widget.' ),
array( 'status' => 400 )
);
}
/*
* Set the widget's number so that the id attributes in the HTML that we
* return are predictable.
*/
Quick Info
- Hook Type: Filter
- Parameters: 1
- File: wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php
Related Hooks
Related hooks will be displayed here in future updates.