REST API: Rename the $creating parameter of rest_after_save_widget action to $update.

This brings some consistency with similar actions for posts, e.g. `save_post` or `wp_insert_post`.

Follow-up to [51068], [51069].

See #53317.

git-svn-id: https://develop.svn.wordpress.org/trunk@51071 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2021-06-04 10:47:01 +00:00
parent 794a136dd2
commit e7ac82157e
2 changed files with 9 additions and 6 deletions

View File

@ -213,8 +213,9 @@ class WP_REST_Sidebars_Controller extends WP_REST_Controller {
* Fires after a sidebar is updated via the REST API.
*
* @since 5.8.0
* @param array $sidebar The updated sidebar.
* @param WP_REST_Request $request Request object.
*
* @param array $sidebar The updated sidebar.
* @param WP_REST_Request $request Request object.
*/
do_action( 'rest_save_sidebar', $sidebar, $request );

View File

@ -360,6 +360,7 @@ class WP_REST_Widgets_Controller extends WP_REST_Controller {
* Fires after a widget is deleted via the REST API.
*
* @since 5.8.0
*
* @param string $widget_id ID of the widget marked for deletion.
* @param string $sidebar_id ID of the sidebar the widget was deleted from.
* @param WP_REST_Response $response The response data.
@ -413,14 +414,14 @@ class WP_REST_Widgets_Controller extends WP_REST_Controller {
$id_base = $parsed_id['id_base'];
$number = isset( $parsed_id['number'] ) ? $parsed_id['number'] : null;
$widget_object = $wp_widget_factory->get_widget_object( $id_base );
$creating = false;
$update = true;
} elseif ( $request['id_base'] ) {
// Saving a new widget.
$id_base = $request['id_base'];
$widget_object = $wp_widget_factory->get_widget_object( $id_base );
$number = $widget_object ? next_widget_id_number( $id_base ) : null;
$id = $widget_object ? $id_base . '-' . $number : $id_base;
$creating = true;
$update = false;
} else {
return new WP_Error(
'rest_invalid_widget',
@ -520,12 +521,13 @@ class WP_REST_Widgets_Controller extends WP_REST_Controller {
* Fires after a widget is created or updated via the REST API.
*
* @since 5.8.0
*
* @param string $id ID of the widget being saved.
* @param string $sidebar_id ID of the sidebar containing the widget being saved.
* @param WP_REST_Request $request Request object.
* @param bool $creating True when creating a widget, false when updating.
* @param bool $update Whether this is an existing widget being updated.
*/
do_action( 'rest_after_save_widget', $id, $sidebar_id, $request, $creating );
do_action( 'rest_after_save_widget', $id, $sidebar_id, $request, $update );
return $id;
}