Menu Adam R Brown

WP hooks navigation: Home/browseActions indexFilters index

Source View: rest_after_insert_attachment

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
193           /**
194            * Fires after a single attachment is completely created or updated via the REST API.
195            *
196            * @since 5.0.0
197            *
198            * @param WP_Post         $attachment Inserted or updated attachment object.
199            * @param WP_REST_Request $request    Request object.
200            * @param bool            $creating   True when creating an attachment, false when updating.
201            */
202           do_action( 'rest_after_insert_attachment', $attachment, $request, true );
203
204           $response = $this->prepare_item_for_response( $attachment, $request );
205           $response = rest_ensure_response( $response );
206           $response->set_status( 201 );
207           $response->header( 'Location', rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $id ) ) );
208
209           return $response;
210      }
211
 
Line Code
240           $fields_update = $this->update_additional_fields_for_object( $attachment, $request );
241
242           if ( is_wp_error( $fields_update ) ) {
243                return $fields_update;
244           }
245
246           $request->set_param( 'context', 'edit' );
247
248           /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php */
249           do_action( 'rest_after_insert_attachment', $attachment, $request, false );
250
251           $response = $this->prepare_item_for_response( $attachment, $request );
252           $response = rest_ensure_response( $response );
253
254           return $response;
255      }
256
257      /**
258       * Prepares a single attachment for create or update.