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
178           /**
179            * Fires after a single attachment is completely created or updated via the REST API.
180            *
181            * @since 5.0.0
182            *
183            * @param WP_Post         $attachment Inserted or updated attachment object.
184            * @param WP_REST_Request $request    Request object.
185            * @param bool            $creating   True when creating an attachment, false when updating.
186            */
187           do_action( 'rest_after_insert_attachment', $attachment, $request, true );
188
189           if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
190                // Set a custom header with the attachment_id.
191                // Used by the browser/client to resume creating image sub-sizes after a PHP fatal error.
192                header( 'X-WP-Upload-Attachment-ID: ' . $attachment_id );
193           }
194
195           // Include media and image functions to get access to wp_generate_attachment_metadata().
196           require_once ABSPATH . 'wp-admin/includes/media.php';
 
Line Code
332           $fields_update = $this->update_additional_fields_for_object( $attachment, $request );
333
334           if ( is_wp_error( $fields_update ) ) {
335                return $fields_update;
336           }
337
338           $request->set_param( 'context', 'edit' );
339
340           /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php */
341           do_action( 'rest_after_insert_attachment', $attachment, $request, false );
342
343           $response = $this->prepare_item_for_response( $attachment, $request );
344           $response = rest_ensure_response( $response );
345
346           return $response;
347      }
348
349      /**
350       * Performs post processing on an attachment.