Menu Adam R Brown

WP hooks navigation: Home/browseActions indexFilters index

Source View: rest_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
547            *
548            * The dynamic portion of the hook name, `$this->post_type`, refers to the post type slug.
549            *
550            * @since 4.7.0
551            *
552            * @param WP_Post         $post     Inserted or updated post object.
553            * @param WP_REST_Request $request  Request object.
554            * @param bool            $creating True when creating a post, false when updating.
555            */
556           do_action( "rest_insert_{$this->post_type}", $post, $request, true );
557
558           $schema = $this->get_item_schema();
559
560           if ( ! empty( $schema['properties']['sticky'] ) ) {
561                if ( ! empty( $request['sticky'] ) ) {
562                     stick_post( $post_id );
563                } else {
564                     unstick_post( $post_id );
565                }
 
Line Code
673                } else {
674                     $post_id->add_data( array( 'status' => 400 ) );
675                }
676                return $post_id;
677           }
678
679           $post = get_post( $post_id );
680
681           /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php */
682           do_action( "rest_insert_{$this->post_type}", $post, $request, false );
683
684           $schema = $this->get_item_schema();
685
686           if ( ! empty( $schema['properties']['format'] ) && ! empty( $request['format'] ) ) {
687                set_post_format( $post, $request['format'] );
688           }
689
690           if ( ! empty( $schema['properties']['featured_media'] ) && isset( $request['featured_media'] ) ) {
691                $this->handle_featured_media( $request['featured_media'], $post_id );