WordPress Hooks Explorer

Listing all hooks extracted WordPress Core


Details about rest_insert_

Back to home

Files

Filename Hook Type Line Number PHP Doc
wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php do_action 709 /**
* Fires after a single post is created or updated via the REST API.
*
* The dynamic portion of the hook name, `$this->post_type`, refers to the post type slug.
*
* Possible hook names include:
*
* - `rest_insert_post`
* - `rest_insert_page`
* - `rest_insert_attachment`
*
* @since 4.7.0
*
* @param WP_Post $post Inserted or updated post object.
* @param WP_REST_Request $request Request object.
* @param bool $creating True when creating a post, false when updating.
*/
wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php do_action 891 /**
* Updates a single post.
*
* @since 4.7.0
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
*/
public function update_item( $request ) {
$valid_check = $this->get_post( $request['id'] );
if ( is_wp_error( $valid_check ) ) {
return $valid_check;
}

$post_before = get_post( $request['id'] );
$post = $this->prepare_item_for_database( $request );

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

if ( ! empty( $post->post_status ) ) {
$post_status = $post->post_status;
} else {
$post_status = $post_before->post_status;
}

/*
* `wp_unique_post_slug()` returns the same
* slug for 'draft' or 'pending' posts.
*
* To ensure that a unique slug is generated,
* pass the post data with the 'publish' status.
*/
wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php do_action 559 /**
* Fires after a single term is created or updated via the REST API.
*
* The dynamic portion of the hook name, `$this->taxonomy`, refers to the taxonomy slug.
*
* Possible hook names include:
*
* - `rest_insert_category`
* - `rest_insert_post_tag`
*
* @since 4.7.0
*
* @param WP_Term $term Inserted or updated term object.
* @param WP_REST_Request $request Request object.
* @param bool $creating True when creating a term, false when updating.
*/
wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php do_action 679 /**
* Updates a single term from a taxonomy.
*
* @since 4.7.0
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
*/
wp-includes/rest-api/endpoints/class-wp-rest-menus-controller.php do_action 240 /**
* Creates a single term in a taxonomy.
*
* @since 5.9.0
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
*/
public function create_item( $request ) {
if ( isset( $request['parent'] ) ) {
if ( ! is_taxonomy_hierarchical( $this->taxonomy ) ) {
return new WP_Error( 'rest_taxonomy_not_hierarchical', __( 'Cannot set parent term, taxonomy is not hierarchical.' ), array( 'status' => 400 ) );
}

$parent = wp_get_nav_menu_object( (int) $request['parent'] );

if ( ! $parent ) {
return new WP_Error( 'rest_term_invalid', __( 'Parent term does not exist.' ), array( 'status' => 400 ) );
}
}

$prepared_term = $this->prepare_item_for_database( $request );

$term = wp_update_nav_menu_object( 0, wp_slash( (array) $prepared_term ) );

if ( is_wp_error( $term ) ) {
/*
* If we're going to inform the client that the term already exists,
* give them the identifier for future use.
*/
wp-includes/rest-api/endpoints/class-wp-rest-menus-controller.php do_action 324 /**
* Updates a single term from a taxonomy.
*
* @since 5.9.0
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
*/

Hook Parameters

Parameter Type Name Description
WP_Post $post Inserted or updated post object.
WP_REST_Request $request Request object.
bool $creating True when creating a post, false when updating.
WP_Post $post Inserted or updated post object.
WP_REST_Request $request Request object.
bool $creating True when creating a post, false when updating.
WP_Term $term Inserted or updated term object.
WP_REST_Request $request Request object.
bool $creating True when creating a term, false when updating.
WP_Term $term Inserted or updated term object.
WP_REST_Request $request Request object.
bool $creating True when creating a term, false when updating.