wp-includes/post.php:3834Trashes or deletes a post or page.
$post_idintoptional0$force_deletebooloptionalfalseWP_Post|false|null7 hooks fire while wp_delete_post() runs, in this order:
Filters whether a post deletion should take place.
Fires before a post is deleted, at the start of wp_delete_post().
Fires immediately before a post is deleted from the database.
Fires immediately before a post is deleted from the database.
Fires immediately after a post is deleted from the database.
Fires immediately after a post is deleted from the database.
Fires after a post is deleted, at the conclusion of wp_delete_post().
function wp_delete_post( $post_id = 0, $force_delete = false ) { global $wpdb; $post_id = (int) $post_id; if ( $post_id <= 0 ) { _doing_it_wrong( __FUNCTION__, __( 'The post ID must be greater than 0.' ), '6.9.0' ); return false; } $post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID = %d", $post_id ) ); if ( ! $post ) { return $post; } $post = get_post( $post ); if ( ! $force_delete && ( 'post' === $post->post_type || 'page' === $post->post_type ) && 'trash' !== get_post_status( $post_id ) && EMPTY_TRASH_DAYS ) { return wp_trash_post( $post_id ); } if ( 'attachment' === $post->post_type ) { return wp_delete_attachment( $post_id, $force_delete ); } /** * Filters whether a post deletion should take place. * * @since 4.4.0 * * @param WP_Post|false|null $check Whether to go forward with deletion. Anything other than null will short-circuit deletion. * @param WP_Post $post Post object. * @param bool $force_delete Whether to bypass the Trash. */ $check = apply_filters( 'pre_delete_post', null, $post, $force_delete ); if ( null !== $check ) { return $check; } /** * Fires before a post is deleted, at the start of wp_delete_post(). * * @since 3.2.0 * @since 5.5.0 Added the `$post` parameter. * * @see wp_delete_post() * * @param int $post_id Post ID. * @param WP_Post $post Post object. */ do_action( 'before_delete_post', $post_id, $post ); delete_post_meta( $post_id, '_wp_trash_meta_status' ); delete_post_meta( $post_id, '_wp_trash_meta_time' ); wp_delete_object_term_relationships( $post_id, get_object_taxonomies( $post->post_type ) ); $parent_data = array( 'post_parent' => $post->post_parent ); $parent_where = array( 'post_parent' => $post_id ); if ( is_post_type_hierarchical( $post->post_type ) ) { // Point children of this page to its parent, also clean the cache of affected children. $children_query = $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_parent = %d AND post_type = %s", $post_id, $post->post_type ); $children = $wpdb->get_results( $children_query ); if ( $children ) { $wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => $post->post_type ) ); } } // Do raw query. wp_get_post_revisions() is filtered. $revision_ids = $wpdb->get_col(Introduced in 1.0.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
src/wp-includes/post.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.