wphooks.info - rest_after_insert_attachment

rest_after_insert_attachment

(trunk - 5.1-alpha-44286)

*** New in trunk ***

The hook occurs in the following 2 files

wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php:
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
		/**
		 * Fires after a single attachment is completely created or updated via the REST API.
		 *
		 * @since 5.0.0
		 *
		 * @param WP_Post         $attachment Inserted or updated attachment object.
		 * @param WP_REST_Request $request    Request object.
		 * @param bool            $creating   True when creating an attachment, false when updating.
		 */
		do_action( 'rest_after_insert_attachment', $attachment, $request, true );

		$response = $this->prepare_item_for_response( $attachment, $request );
		$response = rest_ensure_response( $response );
		$response->set_status( 201 );
		$response->header( 'Location', rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $id ) ) );

		return $response;
	}
wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php:
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
		$fields_update = $this->update_additional_fields_for_object( $attachment, $request );

		if ( is_wp_error( $fields_update ) ) {
			return $fields_update;
		}

		$request->set_param( 'context', 'edit' );

		/** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php */
		do_action( 'rest_after_insert_attachment', $attachment, $request, false );

		$response = $this->prepare_item_for_response( $attachment, $request );
		$response = rest_ensure_response( $response );

		return $response;
	}

	/**
	 * Prepares a single attachment for create or update.