Menu Adam R Brown

WP hooks navigation: Home/browseActions indexFilters index

Source View: rest_after_insert_{$this->post_type}

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
361           $fields_update = $this->update_additional_fields_for_object( $template, $request );
362           if ( is_wp_error( $fields_update ) ) {
363                return $fields_update;
364           }
365
366           $request->set_param( 'context', 'edit' );
367
368           $post = get_post( $template->wp_id );
369           /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php */
370           do_action( "rest_after_insert_{$this->post_type}", $post, $request, false );
371
372           wp_after_insert_post( $post, $update, $post_before );
373
374           $response = $this->prepare_item_for_response( $template, $request );
375
376           return rest_ensure_response( $response );
377      }
378
379      /**
 
Line Code
421           $id            = $posts[0]->id;
422           $post          = get_post( $post_id );
423           $template      = get_block_template( $id, $this->post_type );
424           $fields_update = $this->update_additional_fields_for_object( $template, $request );
425           if ( is_wp_error( $fields_update ) ) {
426                return $fields_update;
427           }
428
429           /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php */
430           do_action( "rest_after_insert_{$this->post_type}", $post, $request, true );
431
432           wp_after_insert_post( $post, false, null );
433
434           $response = $this->prepare_item_for_response( $template, $request );
435           $response = rest_ensure_response( $response );
436
437           $response->set_status( 201 );
438           $response->header( 'Location', rest_url( sprintf( '%s/%s/%s', $this->namespace, $this->rest_base, $template->id ) ) );
439