diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php index 8663196248..5b312b54f1 100644 --- a/wp-includes/default-filters.php +++ b/wp-includes/default-filters.php @@ -246,7 +246,18 @@ add_filter( 'wp_robots', 'wp_robots_noindex_search' ); add_filter( 'wp_robots', 'wp_robots_max_image_preview_large' ); // Mark site as no longer fresh. -foreach ( array( 'publish_post', 'publish_page', 'wp_ajax_save-widget', 'wp_ajax_widgets-order', 'customize_save_after' ) as $action ) { +foreach ( + array( + 'publish_post', + 'publish_page', + 'wp_ajax_save-widget', + 'wp_ajax_widgets-order', + 'customize_save_after', + 'rest_after_save_widget', + 'rest_delete_widget', + 'rest_save_sidebar', + ) as $action +) { add_action( $action, '_delete_option_fresh_site', 0 ); } diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-sidebars-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-sidebars-controller.php index 7011018a83..3c1a83f0db 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-sidebars-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-sidebars-controller.php @@ -209,6 +209,15 @@ class WP_REST_Sidebars_Controller extends WP_REST_Controller { $sidebar = $this->get_sidebar( $request['id'] ); + /** + * 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. + */ + do_action( 'rest_save_sidebar', $sidebar, $request ); + return $this->prepare_item_for_response( $sidebar, $request ); } diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php index 899317fc8b..35cd9b4f94 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php @@ -186,7 +186,7 @@ class WP_REST_Widgets_Controller extends WP_REST_Controller { public function create_item( $request ) { $sidebar_id = $request['sidebar']; - $widget_id = $this->save_widget( $request ); + $widget_id = $this->save_widget( $request, $sidebar_id ); if ( is_wp_error( $widget_id ) ) { return $widget_id; @@ -248,7 +248,7 @@ class WP_REST_Widgets_Controller extends WP_REST_Controller { $request->has_param( 'instance' ) || $request->has_param( 'form_data' ) ) { - $maybe_error = $this->save_widget( $request ); + $maybe_error = $this->save_widget( $request, $sidebar_id ); if ( is_wp_error( $maybe_error ) ) { return $maybe_error; } @@ -356,6 +356,17 @@ 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. + * @param WP_REST_Request $request The request sent to the API. + */ + do_action( 'rest_delete_widget', $widget_id, $sidebar_id, $response, $request ); + return $response; } @@ -385,11 +396,12 @@ class WP_REST_Widgets_Controller extends WP_REST_Controller { * * @since 5.8.0 * - * @param WP_REST_Request $request Full details about the request. + * @param WP_REST_Request $request Full details about the request. + * @param string $sidebar_id ID of the sidebar the widget belongs to. * * @return string|WP_Error The saved widget ID. */ - protected function save_widget( $request ) { + protected function save_widget( $request, $sidebar_id ) { global $wp_widget_factory, $wp_registered_widget_updates; require_once ABSPATH . 'wp-admin/includes/widgets.php'; // For next_widget_id_number(). @@ -401,12 +413,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; } 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; } else { return new WP_Error( 'rest_invalid_widget', @@ -502,6 +516,17 @@ class WP_REST_Widgets_Controller extends WP_REST_Controller { $widget_object->updated = false; } + /** + * 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. + */ + do_action( 'rest_after_save_widget', $id, $sidebar_id, $request, $creating ); + return $id; } diff --git a/wp-includes/version.php b/wp-includes/version.php index ad58e267a2..7b0f934718 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.8-alpha-51067'; +$wp_version = '5.8-alpha-51068'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.