Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-inclu.../rest-api/endpoint...
File: class-wp-rest-widgets-controller.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* REST API: WP_REST_Widgets_Controller class
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage REST_API
[5] Fix | Delete
* @since 5.8.0
[6] Fix | Delete
*/
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Core class to access widgets via the REST API.
[10] Fix | Delete
*
[11] Fix | Delete
* @since 5.8.0
[12] Fix | Delete
*
[13] Fix | Delete
* @see WP_REST_Controller
[14] Fix | Delete
*/
[15] Fix | Delete
class WP_REST_Widgets_Controller extends WP_REST_Controller {
[16] Fix | Delete
[17] Fix | Delete
/**
[18] Fix | Delete
* Tracks whether {@see retrieve_widgets()} has been called in the current request.
[19] Fix | Delete
*
[20] Fix | Delete
* @since 5.9.0
[21] Fix | Delete
* @var bool
[22] Fix | Delete
*/
[23] Fix | Delete
protected $widgets_retrieved = false;
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* Whether the controller supports batching.
[27] Fix | Delete
*
[28] Fix | Delete
* @since 5.9.0
[29] Fix | Delete
* @var array
[30] Fix | Delete
*/
[31] Fix | Delete
protected $allow_batch = array( 'v1' => true );
[32] Fix | Delete
[33] Fix | Delete
/**
[34] Fix | Delete
* Widgets controller constructor.
[35] Fix | Delete
*
[36] Fix | Delete
* @since 5.8.0
[37] Fix | Delete
*/
[38] Fix | Delete
public function __construct() {
[39] Fix | Delete
$this->namespace = 'wp/v2';
[40] Fix | Delete
$this->rest_base = 'widgets';
[41] Fix | Delete
}
[42] Fix | Delete
[43] Fix | Delete
/**
[44] Fix | Delete
* Registers the widget routes for the controller.
[45] Fix | Delete
*
[46] Fix | Delete
* @since 5.8.0
[47] Fix | Delete
*/
[48] Fix | Delete
public function register_routes() {
[49] Fix | Delete
register_rest_route(
[50] Fix | Delete
$this->namespace,
[51] Fix | Delete
$this->rest_base,
[52] Fix | Delete
array(
[53] Fix | Delete
array(
[54] Fix | Delete
'methods' => WP_REST_Server::READABLE,
[55] Fix | Delete
'callback' => array( $this, 'get_items' ),
[56] Fix | Delete
'permission_callback' => array( $this, 'get_items_permissions_check' ),
[57] Fix | Delete
'args' => $this->get_collection_params(),
[58] Fix | Delete
),
[59] Fix | Delete
array(
[60] Fix | Delete
'methods' => WP_REST_Server::CREATABLE,
[61] Fix | Delete
'callback' => array( $this, 'create_item' ),
[62] Fix | Delete
'permission_callback' => array( $this, 'create_item_permissions_check' ),
[63] Fix | Delete
'args' => $this->get_endpoint_args_for_item_schema(),
[64] Fix | Delete
),
[65] Fix | Delete
'allow_batch' => $this->allow_batch,
[66] Fix | Delete
'schema' => array( $this, 'get_public_item_schema' ),
[67] Fix | Delete
)
[68] Fix | Delete
);
[69] Fix | Delete
[70] Fix | Delete
register_rest_route(
[71] Fix | Delete
$this->namespace,
[72] Fix | Delete
$this->rest_base . '/(?P<id>[\w\-]+)',
[73] Fix | Delete
array(
[74] Fix | Delete
array(
[75] Fix | Delete
'methods' => WP_REST_Server::READABLE,
[76] Fix | Delete
'callback' => array( $this, 'get_item' ),
[77] Fix | Delete
'permission_callback' => array( $this, 'get_item_permissions_check' ),
[78] Fix | Delete
'args' => array(
[79] Fix | Delete
'context' => $this->get_context_param( array( 'default' => 'view' ) ),
[80] Fix | Delete
),
[81] Fix | Delete
),
[82] Fix | Delete
array(
[83] Fix | Delete
'methods' => WP_REST_Server::EDITABLE,
[84] Fix | Delete
'callback' => array( $this, 'update_item' ),
[85] Fix | Delete
'permission_callback' => array( $this, 'update_item_permissions_check' ),
[86] Fix | Delete
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
[87] Fix | Delete
),
[88] Fix | Delete
array(
[89] Fix | Delete
'methods' => WP_REST_Server::DELETABLE,
[90] Fix | Delete
'callback' => array( $this, 'delete_item' ),
[91] Fix | Delete
'permission_callback' => array( $this, 'delete_item_permissions_check' ),
[92] Fix | Delete
'args' => array(
[93] Fix | Delete
'force' => array(
[94] Fix | Delete
'description' => __( 'Whether to force removal of the widget, or move it to the inactive sidebar.' ),
[95] Fix | Delete
'type' => 'boolean',
[96] Fix | Delete
),
[97] Fix | Delete
),
[98] Fix | Delete
),
[99] Fix | Delete
'allow_batch' => $this->allow_batch,
[100] Fix | Delete
'schema' => array( $this, 'get_public_item_schema' ),
[101] Fix | Delete
)
[102] Fix | Delete
);
[103] Fix | Delete
}
[104] Fix | Delete
[105] Fix | Delete
/**
[106] Fix | Delete
* Checks if a given request has access to get widgets.
[107] Fix | Delete
*
[108] Fix | Delete
* @since 5.8.0
[109] Fix | Delete
*
[110] Fix | Delete
* @param WP_REST_Request $request Full details about the request.
[111] Fix | Delete
* @return true|WP_Error True if the request has read access, WP_Error object otherwise.
[112] Fix | Delete
*/
[113] Fix | Delete
public function get_items_permissions_check( $request ) {
[114] Fix | Delete
$this->retrieve_widgets();
[115] Fix | Delete
if ( isset( $request['sidebar'] ) && $this->check_read_sidebar_permission( $request['sidebar'] ) ) {
[116] Fix | Delete
return true;
[117] Fix | Delete
}
[118] Fix | Delete
[119] Fix | Delete
foreach ( wp_get_sidebars_widgets() as $sidebar_id => $widget_ids ) {
[120] Fix | Delete
if ( $this->check_read_sidebar_permission( $sidebar_id ) ) {
[121] Fix | Delete
return true;
[122] Fix | Delete
}
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
return $this->permissions_check( $request );
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
/**
[129] Fix | Delete
* Retrieves a collection of widgets.
[130] Fix | Delete
*
[131] Fix | Delete
* @since 5.8.0
[132] Fix | Delete
*
[133] Fix | Delete
* @param WP_REST_Request $request Full details about the request.
[134] Fix | Delete
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
[135] Fix | Delete
*/
[136] Fix | Delete
public function get_items( $request ) {
[137] Fix | Delete
$this->retrieve_widgets();
[138] Fix | Delete
[139] Fix | Delete
$prepared = array();
[140] Fix | Delete
$permissions_check = $this->permissions_check( $request );
[141] Fix | Delete
[142] Fix | Delete
foreach ( wp_get_sidebars_widgets() as $sidebar_id => $widget_ids ) {
[143] Fix | Delete
if ( isset( $request['sidebar'] ) && $sidebar_id !== $request['sidebar'] ) {
[144] Fix | Delete
continue;
[145] Fix | Delete
}
[146] Fix | Delete
[147] Fix | Delete
if ( is_wp_error( $permissions_check ) && ! $this->check_read_sidebar_permission( $sidebar_id ) ) {
[148] Fix | Delete
continue;
[149] Fix | Delete
}
[150] Fix | Delete
[151] Fix | Delete
foreach ( $widget_ids as $widget_id ) {
[152] Fix | Delete
$response = $this->prepare_item_for_response( compact( 'sidebar_id', 'widget_id' ), $request );
[153] Fix | Delete
[154] Fix | Delete
if ( ! is_wp_error( $response ) ) {
[155] Fix | Delete
$prepared[] = $this->prepare_response_for_collection( $response );
[156] Fix | Delete
}
[157] Fix | Delete
}
[158] Fix | Delete
}
[159] Fix | Delete
[160] Fix | Delete
return new WP_REST_Response( $prepared );
[161] Fix | Delete
}
[162] Fix | Delete
[163] Fix | Delete
/**
[164] Fix | Delete
* Checks if a given request has access to get a widget.
[165] Fix | Delete
*
[166] Fix | Delete
* @since 5.8.0
[167] Fix | Delete
*
[168] Fix | Delete
* @param WP_REST_Request $request Full details about the request.
[169] Fix | Delete
* @return true|WP_Error True if the request has read access, WP_Error object otherwise.
[170] Fix | Delete
*/
[171] Fix | Delete
public function get_item_permissions_check( $request ) {
[172] Fix | Delete
$this->retrieve_widgets();
[173] Fix | Delete
[174] Fix | Delete
$widget_id = $request['id'];
[175] Fix | Delete
$sidebar_id = wp_find_widgets_sidebar( $widget_id );
[176] Fix | Delete
[177] Fix | Delete
if ( $sidebar_id && $this->check_read_sidebar_permission( $sidebar_id ) ) {
[178] Fix | Delete
return true;
[179] Fix | Delete
}
[180] Fix | Delete
[181] Fix | Delete
return $this->permissions_check( $request );
[182] Fix | Delete
}
[183] Fix | Delete
[184] Fix | Delete
/**
[185] Fix | Delete
* Checks if a sidebar can be read publicly.
[186] Fix | Delete
*
[187] Fix | Delete
* @since 5.9.0
[188] Fix | Delete
*
[189] Fix | Delete
* @param string $sidebar_id The sidebar ID.
[190] Fix | Delete
* @return bool Whether the sidebar can be read.
[191] Fix | Delete
*/
[192] Fix | Delete
protected function check_read_sidebar_permission( $sidebar_id ) {
[193] Fix | Delete
$sidebar = wp_get_sidebar( $sidebar_id );
[194] Fix | Delete
[195] Fix | Delete
return ! empty( $sidebar['show_in_rest'] );
[196] Fix | Delete
}
[197] Fix | Delete
[198] Fix | Delete
/**
[199] Fix | Delete
* Gets an individual widget.
[200] Fix | Delete
*
[201] Fix | Delete
* @since 5.8.0
[202] Fix | Delete
*
[203] Fix | Delete
* @param WP_REST_Request $request Full details about the request.
[204] Fix | Delete
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
[205] Fix | Delete
*/
[206] Fix | Delete
public function get_item( $request ) {
[207] Fix | Delete
$this->retrieve_widgets();
[208] Fix | Delete
[209] Fix | Delete
$widget_id = $request['id'];
[210] Fix | Delete
$sidebar_id = wp_find_widgets_sidebar( $widget_id );
[211] Fix | Delete
[212] Fix | Delete
if ( is_null( $sidebar_id ) ) {
[213] Fix | Delete
return new WP_Error(
[214] Fix | Delete
'rest_widget_not_found',
[215] Fix | Delete
__( 'No widget was found with that id.' ),
[216] Fix | Delete
array( 'status' => 404 )
[217] Fix | Delete
);
[218] Fix | Delete
}
[219] Fix | Delete
[220] Fix | Delete
return $this->prepare_item_for_response( compact( 'widget_id', 'sidebar_id' ), $request );
[221] Fix | Delete
}
[222] Fix | Delete
[223] Fix | Delete
/**
[224] Fix | Delete
* Checks if a given request has access to create widgets.
[225] Fix | Delete
*
[226] Fix | Delete
* @since 5.8.0
[227] Fix | Delete
*
[228] Fix | Delete
* @param WP_REST_Request $request Full details about the request.
[229] Fix | Delete
* @return true|WP_Error True if the request has read access, WP_Error object otherwise.
[230] Fix | Delete
*/
[231] Fix | Delete
public function create_item_permissions_check( $request ) {
[232] Fix | Delete
return $this->permissions_check( $request );
[233] Fix | Delete
}
[234] Fix | Delete
[235] Fix | Delete
/**
[236] Fix | Delete
* Creates a widget.
[237] Fix | Delete
*
[238] Fix | Delete
* @since 5.8.0
[239] Fix | Delete
*
[240] Fix | Delete
* @param WP_REST_Request $request Full details about the request.
[241] Fix | Delete
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
[242] Fix | Delete
*/
[243] Fix | Delete
public function create_item( $request ) {
[244] Fix | Delete
$sidebar_id = $request['sidebar'];
[245] Fix | Delete
[246] Fix | Delete
$widget_id = $this->save_widget( $request, $sidebar_id );
[247] Fix | Delete
[248] Fix | Delete
if ( is_wp_error( $widget_id ) ) {
[249] Fix | Delete
return $widget_id;
[250] Fix | Delete
}
[251] Fix | Delete
[252] Fix | Delete
wp_assign_widget_to_sidebar( $widget_id, $sidebar_id );
[253] Fix | Delete
[254] Fix | Delete
$request['context'] = 'edit';
[255] Fix | Delete
[256] Fix | Delete
$response = $this->prepare_item_for_response( compact( 'sidebar_id', 'widget_id' ), $request );
[257] Fix | Delete
[258] Fix | Delete
if ( is_wp_error( $response ) ) {
[259] Fix | Delete
return $response;
[260] Fix | Delete
}
[261] Fix | Delete
[262] Fix | Delete
$response->set_status( 201 );
[263] Fix | Delete
[264] Fix | Delete
return $response;
[265] Fix | Delete
}
[266] Fix | Delete
[267] Fix | Delete
/**
[268] Fix | Delete
* Checks if a given request has access to update widgets.
[269] Fix | Delete
*
[270] Fix | Delete
* @since 5.8.0
[271] Fix | Delete
*
[272] Fix | Delete
* @param WP_REST_Request $request Full details about the request.
[273] Fix | Delete
* @return true|WP_Error True if the request has read access, WP_Error object otherwise.
[274] Fix | Delete
*/
[275] Fix | Delete
public function update_item_permissions_check( $request ) {
[276] Fix | Delete
return $this->permissions_check( $request );
[277] Fix | Delete
}
[278] Fix | Delete
[279] Fix | Delete
/**
[280] Fix | Delete
* Updates an existing widget.
[281] Fix | Delete
*
[282] Fix | Delete
* @since 5.8.0
[283] Fix | Delete
*
[284] Fix | Delete
* @global WP_Widget_Factory $wp_widget_factory
[285] Fix | Delete
*
[286] Fix | Delete
* @param WP_REST_Request $request Full details about the request.
[287] Fix | Delete
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
[288] Fix | Delete
*/
[289] Fix | Delete
public function update_item( $request ) {
[290] Fix | Delete
global $wp_widget_factory;
[291] Fix | Delete
[292] Fix | Delete
/*
[293] Fix | Delete
* retrieve_widgets() contains logic to move "hidden" or "lost" widgets to the
[294] Fix | Delete
* wp_inactive_widgets sidebar based on the contents of the $sidebars_widgets global.
[295] Fix | Delete
*
[296] Fix | Delete
* When batch requests are processed, this global is not properly updated by previous
[297] Fix | Delete
* calls, resulting in widgets incorrectly being moved to the wp_inactive_widgets
[298] Fix | Delete
* sidebar.
[299] Fix | Delete
*
[300] Fix | Delete
* See https://core.trac.wordpress.org/ticket/53657.
[301] Fix | Delete
*/
[302] Fix | Delete
wp_get_sidebars_widgets();
[303] Fix | Delete
$this->retrieve_widgets();
[304] Fix | Delete
[305] Fix | Delete
$widget_id = $request['id'];
[306] Fix | Delete
$sidebar_id = wp_find_widgets_sidebar( $widget_id );
[307] Fix | Delete
[308] Fix | Delete
// Allow sidebar to be unset or missing when widget is not a WP_Widget.
[309] Fix | Delete
$parsed_id = wp_parse_widget_id( $widget_id );
[310] Fix | Delete
$widget_object = $wp_widget_factory->get_widget_object( $parsed_id['id_base'] );
[311] Fix | Delete
if ( is_null( $sidebar_id ) && $widget_object ) {
[312] Fix | Delete
return new WP_Error(
[313] Fix | Delete
'rest_widget_not_found',
[314] Fix | Delete
__( 'No widget was found with that id.' ),
[315] Fix | Delete
array( 'status' => 404 )
[316] Fix | Delete
);
[317] Fix | Delete
}
[318] Fix | Delete
[319] Fix | Delete
if (
[320] Fix | Delete
$request->has_param( 'instance' ) ||
[321] Fix | Delete
$request->has_param( 'form_data' )
[322] Fix | Delete
) {
[323] Fix | Delete
$maybe_error = $this->save_widget( $request, $sidebar_id );
[324] Fix | Delete
if ( is_wp_error( $maybe_error ) ) {
[325] Fix | Delete
return $maybe_error;
[326] Fix | Delete
}
[327] Fix | Delete
}
[328] Fix | Delete
[329] Fix | Delete
if ( $request->has_param( 'sidebar' ) ) {
[330] Fix | Delete
if ( $sidebar_id !== $request['sidebar'] ) {
[331] Fix | Delete
$sidebar_id = $request['sidebar'];
[332] Fix | Delete
wp_assign_widget_to_sidebar( $widget_id, $sidebar_id );
[333] Fix | Delete
}
[334] Fix | Delete
}
[335] Fix | Delete
[336] Fix | Delete
$request['context'] = 'edit';
[337] Fix | Delete
[338] Fix | Delete
return $this->prepare_item_for_response( compact( 'widget_id', 'sidebar_id' ), $request );
[339] Fix | Delete
}
[340] Fix | Delete
[341] Fix | Delete
/**
[342] Fix | Delete
* Checks if a given request has access to delete widgets.
[343] Fix | Delete
*
[344] Fix | Delete
* @since 5.8.0
[345] Fix | Delete
*
[346] Fix | Delete
* @param WP_REST_Request $request Full details about the request.
[347] Fix | Delete
* @return true|WP_Error True if the request has read access, WP_Error object otherwise.
[348] Fix | Delete
*/
[349] Fix | Delete
public function delete_item_permissions_check( $request ) {
[350] Fix | Delete
return $this->permissions_check( $request );
[351] Fix | Delete
}
[352] Fix | Delete
[353] Fix | Delete
/**
[354] Fix | Delete
* Deletes a widget.
[355] Fix | Delete
*
[356] Fix | Delete
* @since 5.8.0
[357] Fix | Delete
*
[358] Fix | Delete
* @global WP_Widget_Factory $wp_widget_factory
[359] Fix | Delete
* @global array $wp_registered_widget_updates The registered widget update functions.
[360] Fix | Delete
*
[361] Fix | Delete
* @param WP_REST_Request $request Full details about the request.
[362] Fix | Delete
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
[363] Fix | Delete
*/
[364] Fix | Delete
public function delete_item( $request ) {
[365] Fix | Delete
global $wp_widget_factory, $wp_registered_widget_updates;
[366] Fix | Delete
[367] Fix | Delete
/*
[368] Fix | Delete
* retrieve_widgets() contains logic to move "hidden" or "lost" widgets to the
[369] Fix | Delete
* wp_inactive_widgets sidebar based on the contents of the $sidebars_widgets global.
[370] Fix | Delete
*
[371] Fix | Delete
* When batch requests are processed, this global is not properly updated by previous
[372] Fix | Delete
* calls, resulting in widgets incorrectly being moved to the wp_inactive_widgets
[373] Fix | Delete
* sidebar.
[374] Fix | Delete
*
[375] Fix | Delete
* See https://core.trac.wordpress.org/ticket/53657.
[376] Fix | Delete
*/
[377] Fix | Delete
wp_get_sidebars_widgets();
[378] Fix | Delete
$this->retrieve_widgets();
[379] Fix | Delete
[380] Fix | Delete
$widget_id = $request['id'];
[381] Fix | Delete
$sidebar_id = wp_find_widgets_sidebar( $widget_id );
[382] Fix | Delete
[383] Fix | Delete
if ( is_null( $sidebar_id ) ) {
[384] Fix | Delete
return new WP_Error(
[385] Fix | Delete
'rest_widget_not_found',
[386] Fix | Delete
__( 'No widget was found with that id.' ),
[387] Fix | Delete
array( 'status' => 404 )
[388] Fix | Delete
);
[389] Fix | Delete
}
[390] Fix | Delete
[391] Fix | Delete
$request['context'] = 'edit';
[392] Fix | Delete
[393] Fix | Delete
if ( $request['force'] ) {
[394] Fix | Delete
$response = $this->prepare_item_for_response( compact( 'widget_id', 'sidebar_id' ), $request );
[395] Fix | Delete
[396] Fix | Delete
$parsed_id = wp_parse_widget_id( $widget_id );
[397] Fix | Delete
$id_base = $parsed_id['id_base'];
[398] Fix | Delete
[399] Fix | Delete
$original_post = $_POST;
[400] Fix | Delete
$original_request = $_REQUEST;
[401] Fix | Delete
[402] Fix | Delete
$_POST = array(
[403] Fix | Delete
'sidebar' => $sidebar_id,
[404] Fix | Delete
"widget-$id_base" => array(),
[405] Fix | Delete
'the-widget-id' => $widget_id,
[406] Fix | Delete
'delete_widget' => '1',
[407] Fix | Delete
);
[408] Fix | Delete
$_REQUEST = $_POST;
[409] Fix | Delete
[410] Fix | Delete
/** This action is documented in wp-admin/widgets-form.php */
[411] Fix | Delete
do_action( 'delete_widget', $widget_id, $sidebar_id, $id_base );
[412] Fix | Delete
[413] Fix | Delete
$callback = $wp_registered_widget_updates[ $id_base ]['callback'];
[414] Fix | Delete
$params = $wp_registered_widget_updates[ $id_base ]['params'];
[415] Fix | Delete
[416] Fix | Delete
if ( is_callable( $callback ) ) {
[417] Fix | Delete
ob_start();
[418] Fix | Delete
call_user_func_array( $callback, $params );
[419] Fix | Delete
ob_end_clean();
[420] Fix | Delete
}
[421] Fix | Delete
[422] Fix | Delete
$_POST = $original_post;
[423] Fix | Delete
$_REQUEST = $original_request;
[424] Fix | Delete
[425] Fix | Delete
$widget_object = $wp_widget_factory->get_widget_object( $id_base );
[426] Fix | Delete
[427] Fix | Delete
if ( $widget_object ) {
[428] Fix | Delete
/*
[429] Fix | Delete
* WP_Widget sets `updated = true` after an update to prevent more than one widget
[430] Fix | Delete
* from being saved per request. This isn't what we want in the REST API, though,
[431] Fix | Delete
* as we support batch requests.
[432] Fix | Delete
*/
[433] Fix | Delete
$widget_object->updated = false;
[434] Fix | Delete
}
[435] Fix | Delete
[436] Fix | Delete
wp_assign_widget_to_sidebar( $widget_id, '' );
[437] Fix | Delete
[438] Fix | Delete
$response->set_data(
[439] Fix | Delete
array(
[440] Fix | Delete
'deleted' => true,
[441] Fix | Delete
'previous' => $response->get_data(),
[442] Fix | Delete
)
[443] Fix | Delete
);
[444] Fix | Delete
} else {
[445] Fix | Delete
wp_assign_widget_to_sidebar( $widget_id, 'wp_inactive_widgets' );
[446] Fix | Delete
[447] Fix | Delete
$response = $this->prepare_item_for_response(
[448] Fix | Delete
array(
[449] Fix | Delete
'sidebar_id' => 'wp_inactive_widgets',
[450] Fix | Delete
'widget_id' => $widget_id,
[451] Fix | Delete
),
[452] Fix | Delete
$request
[453] Fix | Delete
);
[454] Fix | Delete
}
[455] Fix | Delete
[456] Fix | Delete
/**
[457] Fix | Delete
* Fires after a widget is deleted via the REST API.
[458] Fix | Delete
*
[459] Fix | Delete
* @since 5.8.0
[460] Fix | Delete
*
[461] Fix | Delete
* @param string $widget_id ID of the widget marked for deletion.
[462] Fix | Delete
* @param string $sidebar_id ID of the sidebar the widget was deleted from.
[463] Fix | Delete
* @param WP_REST_Response|WP_Error $response The response data, or WP_Error object on failure.
[464] Fix | Delete
* @param WP_REST_Request $request The request sent to the API.
[465] Fix | Delete
*/
[466] Fix | Delete
do_action( 'rest_delete_widget', $widget_id, $sidebar_id, $response, $request );
[467] Fix | Delete
[468] Fix | Delete
return $response;
[469] Fix | Delete
}
[470] Fix | Delete
[471] Fix | Delete
/**
[472] Fix | Delete
* Performs a permissions check for managing widgets.
[473] Fix | Delete
*
[474] Fix | Delete
* @since 5.8.0
[475] Fix | Delete
*
[476] Fix | Delete
* @param WP_REST_Request $request Full details about the request.
[477] Fix | Delete
* @return true|WP_Error
[478] Fix | Delete
*/
[479] Fix | Delete
protected function permissions_check( $request ) {
[480] Fix | Delete
if ( ! current_user_can( 'edit_theme_options' ) ) {
[481] Fix | Delete
return new WP_Error(
[482] Fix | Delete
'rest_cannot_manage_widgets',
[483] Fix | Delete
__( 'Sorry, you are not allowed to manage widgets on this site.' ),
[484] Fix | Delete
array(
[485] Fix | Delete
'status' => rest_authorization_required_code(),
[486] Fix | Delete
)
[487] Fix | Delete
);
[488] Fix | Delete
}
[489] Fix | Delete
[490] Fix | Delete
return true;
[491] Fix | Delete
}
[492] Fix | Delete
[493] Fix | Delete
/**
[494] Fix | Delete
* Looks for "lost" widgets once per request.
[495] Fix | Delete
*
[496] Fix | Delete
* @since 5.9.0
[497] Fix | Delete
*
[498] Fix | Delete
* @see retrieve_widgets()
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function