Menu Adam R Brown

WP hooks navigation: Home/browseActions indexFilters index

Source View: rest_insert_user

To save our bandwidth, we show only a snippet of code around each occurence of the hook. View complete file in SVN (without highlighting).

Understanding Source Code

The best way to understand what a hook does is to look at where it occurs in the source code.

Remember, this hook may occur in more than one file. Moreover, the hook's context may change from version to version.

Source View

This hook occurs 2 times in this file.

Line Code
537           /**
538            * Fires immediately after a user is created or updated via the REST API.
539            *
540            * @since 4.7.0
541            *
542            * @param WP_User         $user     Inserted or updated user object.
543            * @param WP_REST_Request $request  Request object.
544            * @param bool            $creating True when creating a user, false when updating.
545            */
546           do_action( 'rest_insert_user', $user, $request, true );
547
548           if ( ! empty( $request['roles'] ) && ! empty( $schema['properties']['roles'] ) ) {
549                array_map( array( $user, 'add_role' ), $request['roles'] );
550           }
551
552           if ( ! empty( $schema['properties']['meta'] ) && isset( $request['meta'] ) ) {
553                $meta_update = $this->meta->update_value( $request['meta'], $user_id );
554
555                if ( is_wp_error( $meta_update ) ) {
 
Line Code
671           $user_id = wp_update_user( wp_slash( (array) $user ) );
672
673           if ( is_wp_error( $user_id ) ) {
674                return $user_id;
675           }
676
677           $user = get_user_by( 'id', $user_id );
678
679           /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php */
680           do_action( 'rest_insert_user', $user, $request, false );
681
682           if ( ! empty( $request['roles'] ) ) {
683                array_map( array( $user, 'add_role' ), $request['roles'] );
684           }
685
686           $schema = $this->get_item_schema();
687
688           if ( ! empty( $schema['properties']['meta'] ) && isset( $request['meta'] ) ) {
689                $meta_update = $this->meta->update_value( $request['meta'], $id );