Action hook 'delete_widget'

in WP Core File wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php at line 418

View Source

delete_widget

Action Hook
Description
Deletes a widget. / public function delete_item( $request ) { global $wp_widget_factory, $wp_registered_widget_updates; /* retrieve_widgets() contains logic to move "hidden" or "lost" widgets to the wp_inactive_widgets sidebar based on the contents of the $sidebars_widgets global. When batch requests are processed, this global is not properly updated by previous calls, resulting in widgets incorrectly being moved to the wp_inactive_widgets sidebar. See https://core.trac.wordpress.org/ticket/53657.

Hook Information

File Location wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php View on GitHub
Hook Type Action
Line Number 418

Hook Parameters

Type Name Description
WP_REST_Request $request Full details about the request.

Usage Examples

Basic Usage
<?php
// Hook into delete_widget
add_action('delete_widget', 'my_custom_function', 10, 1);

function my_custom_function($request) {
    // Your custom code here
}

Source Code Context

wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php:418 - How this hook is used in WordPress core
<?php
 413  				'delete_widget'   => '1',
 414  			);
 415  			$_REQUEST = $_POST;
 416  
 417  			/** This action is documented in wp-admin/widgets-form.php */
 418  			do_action( 'delete_widget', $widget_id, $sidebar_id, $id_base );
 419  
 420  			$callback = $wp_registered_widget_updates[ $id_base ]['callback'];
 421  			$params   = $wp_registered_widget_updates[ $id_base ]['params'];
 422  
 423  			if ( is_callable( $callback ) ) {

PHP Documentation

<?php
/**
	 * Deletes a widget.
	 *
	 * @since 5.8.0
	 *
	 * @global WP_Widget_Factory $wp_widget_factory
	 * @global array             $wp_registered_widget_updates The registered widget update functions.
	 *
	 * @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 delete_item( $request ) {
		global $wp_widget_factory, $wp_registered_widget_updates;

		/*
		 * retrieve_widgets() contains logic to move "hidden" or "lost" widgets to the
		 * wp_inactive_widgets sidebar based on the contents of the $sidebars_widgets global.
		 *
		 * When batch requests are processed, this global is not properly updated by previous
		 * calls, resulting in widgets incorrectly being moved to the wp_inactive_widgets
		 * sidebar.
		 *
		 * See https://core.trac.wordpress.org/ticket/53657.
		 */
Quick Info
  • Hook Type: Action
  • Parameters: 1
  • File: wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php
Related Hooks

Related hooks will be displayed here in future updates.