mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-16 23:00:21 +00:00
REST API: Always fire the rest_insert_* actions after the related object is updated or inserted.
Brings consistency to the `rest_insert_*` actions. Also includes some shuffling and clean-up as well including: - Ensure we are passing the most current `$post` and `$user` objects to the `update_additional_fields_for_object()` callbacks. - Changes the function signature of `handle_status_param()` in the Comments controller to accept just the comment_id as the 2nd parameter, instead of a full WP_Comment object. Only the comment_id is needed in the method, this avoids having to include another `get_comment()` call. - Renames a variable in the `create_item()` method of the Posts controller from `$post` -> `$prepared_post` to be more explicit. - Minor fixes/clarifications to the rest_insert_* hook docs Props rachelbaker, joehoyle Fixes #38905. git-svn-id: https://develop.svn.wordpress.org/trunk@39348 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -461,6 +461,17 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
|
||||
|
||||
$user = get_user_by( 'id', $user_id );
|
||||
|
||||
/**
|
||||
* Fires immediately after a user is created or updated via the REST API.
|
||||
*
|
||||
* @since 4.7.0
|
||||
*
|
||||
* @param WP_User $user Inserted or updated user object.
|
||||
* @param WP_REST_Request $request Request object.
|
||||
* @param bool $creating True when creating a user, false when updating.
|
||||
*/
|
||||
do_action( 'rest_insert_user', $user, $request, true );
|
||||
|
||||
if ( ! empty( $request['roles'] ) && ! empty( $schema['properties']['roles'] ) ) {
|
||||
array_map( array( $user, 'add_role' ), $request['roles'] );
|
||||
}
|
||||
@@ -473,23 +484,13 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
|
||||
}
|
||||
}
|
||||
|
||||
$user = get_user_by( 'id', $user_id );
|
||||
$fields_update = $this->update_additional_fields_for_object( $user, $request );
|
||||
|
||||
if ( is_wp_error( $fields_update ) ) {
|
||||
return $fields_update;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fires immediately after a user is created or updated via the REST API.
|
||||
*
|
||||
* @since 4.7.0
|
||||
*
|
||||
* @param WP_User $user Data used to create the user.
|
||||
* @param WP_REST_Request $request Request object.
|
||||
* @param bool $creating True when creating user, false when updating user.
|
||||
*/
|
||||
do_action( 'rest_insert_user', $user, $request, true );
|
||||
|
||||
$request->set_param( 'context', 'edit' );
|
||||
|
||||
$response = $this->prepare_item_for_response( $user, $request );
|
||||
@@ -573,7 +574,10 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
|
||||
return $user_id;
|
||||
}
|
||||
|
||||
$user = get_user_by( 'id', $id );
|
||||
$user = get_user_by( 'id', $user_id );
|
||||
|
||||
/* This action is documented in lib/endpoints/class-wp-rest-users-controller.php */
|
||||
do_action( 'rest_insert_user', $user, $request, false );
|
||||
|
||||
if ( is_multisite() && ! is_user_member_of_blog( $id ) ) {
|
||||
add_user_to_blog( get_current_blog_id(), $id, '' );
|
||||
@@ -593,15 +597,13 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
|
||||
}
|
||||
}
|
||||
|
||||
$user = get_user_by( 'id', $user_id );
|
||||
$fields_update = $this->update_additional_fields_for_object( $user, $request );
|
||||
|
||||
if ( is_wp_error( $fields_update ) ) {
|
||||
return $fields_update;
|
||||
}
|
||||
|
||||
/* This action is documented in lib/endpoints/class-wp-rest-users-controller.php */
|
||||
do_action( 'rest_insert_user', $user, $request, false );
|
||||
|
||||
$request->set_param( 'context', 'edit' );
|
||||
|
||||
$response = $this->prepare_item_for_response( $user, $request );
|
||||
|
||||
Reference in New Issue
Block a user