- Timestamp:
- 06/04/2021 12:44:41 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php
r51060 r51068 187 187 $sidebar_id = $request['sidebar']; 188 188 189 $widget_id = $this->save_widget( $request );189 $widget_id = $this->save_widget( $request, $sidebar_id ); 190 190 191 191 if ( is_wp_error( $widget_id ) ) { … … 249 249 $request->has_param( 'form_data' ) 250 250 ) { 251 $maybe_error = $this->save_widget( $request );251 $maybe_error = $this->save_widget( $request, $sidebar_id ); 252 252 if ( is_wp_error( $maybe_error ) ) { 253 253 return $maybe_error; … … 356 356 ); 357 357 } 358 359 /** 360 * Fires after a widget is deleted via the REST API. 361 * 362 * @since 5.8.0 363 * @param string $widget_id ID of the widget marked for deletion. 364 * @param string $sidebar_id ID of the sidebar the widget was deleted from. 365 * @param WP_REST_Response $response The response data. 366 * @param WP_REST_Request $request The request sent to the API. 367 */ 368 do_action( 'rest_delete_widget', $widget_id, $sidebar_id, $response, $request ); 358 369 359 370 return $response; … … 386 397 * @since 5.8.0 387 398 * 388 * @param WP_REST_Request $request Full details about the request. 399 * @param WP_REST_Request $request Full details about the request. 400 * @param string $sidebar_id ID of the sidebar the widget belongs to. 389 401 * 390 402 * @return string|WP_Error The saved widget ID. 391 403 */ 392 protected function save_widget( $request ) {404 protected function save_widget( $request, $sidebar_id ) { 393 405 global $wp_widget_factory, $wp_registered_widget_updates; 394 406 … … 402 414 $number = isset( $parsed_id['number'] ) ? $parsed_id['number'] : null; 403 415 $widget_object = $wp_widget_factory->get_widget_object( $id_base ); 416 $creating = false; 404 417 } elseif ( $request['id_base'] ) { 405 418 // Saving a new widget. … … 408 421 $number = $widget_object ? next_widget_id_number( $id_base ) : null; 409 422 $id = $widget_object ? $id_base . '-' . $number : $id_base; 423 $creating = true; 410 424 } else { 411 425 return new WP_Error( … … 503 517 } 504 518 519 /** 520 * Fires after a widget is created or updated via the REST API. 521 * 522 * @since 5.8.0 523 * @param string $id ID of the widget being saved. 524 * @param string $sidebar_id ID of the sidebar containing the widget being saved. 525 * @param WP_REST_Request $request Request object. 526 * @param bool $creating True when creating a widget, false when updating. 527 */ 528 do_action( 'rest_after_save_widget', $id, $sidebar_id, $request, $creating ); 529 505 530 return $id; 506 531 }
Note: See TracChangeset
for help on using the changeset viewer.