diff --git a/wp-includes/post.php b/wp-includes/post.php index 3ecadddd9d..932163190c 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -3460,15 +3460,15 @@ function wp_post_mime_type_where( $post_mime_types, $table_alias = '' ) { * @see wp_delete_attachment() * @see wp_trash_post() * - * @param int $postid Optional. Post ID. Default 0. + * @param int $post_id Optional. Post ID. Default 0. * @param bool $force_delete Optional. Whether to bypass Trash and force deletion. * Default false. * @return WP_Post|false|null Post data on success, false or null on failure. */ -function wp_delete_post( $postid = 0, $force_delete = false ) { +function wp_delete_post( $post_id = 0, $force_delete = false ) { global $wpdb; - $post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID = %d", $postid ) ); + $post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID = %d", $post_id ) ); if ( ! $post ) { return $post; @@ -3476,12 +3476,15 @@ function wp_delete_post( $postid = 0, $force_delete = false ) { $post = get_post( $post ); - if ( ! $force_delete && ( 'post' === $post->post_type || 'page' === $post->post_type ) && 'trash' !== get_post_status( $postid ) && EMPTY_TRASH_DAYS ) { - return wp_trash_post( $postid ); + 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( $postid, $force_delete ); + return wp_delete_attachment( $post_id, $force_delete ); } /** @@ -3506,30 +3509,39 @@ function wp_delete_post( $postid = 0, $force_delete = false ) { * * @see wp_delete_post() * - * @param int $postid Post ID. - * @param WP_Post $post Post object. + * @param int $post_id Post ID. + * @param WP_Post $post Post object. */ - do_action( 'before_delete_post', $postid, $post ); + do_action( 'before_delete_post', $post_id, $post ); - delete_post_meta( $postid, '_wp_trash_meta_status' ); - delete_post_meta( $postid, '_wp_trash_meta_time' ); + delete_post_meta( $post_id, '_wp_trash_meta_status' ); + delete_post_meta( $post_id, '_wp_trash_meta_time' ); - wp_delete_object_term_relationships( $postid, get_object_taxonomies( $post->post_type ) ); + 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' => $postid ); + $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", $postid, $post->post_type ); - $children = $wpdb->get_results( $children_query ); + $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( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'revision'", $postid ) ); + $revision_ids = $wpdb->get_col( + $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'revision'", $post_id ) + ); + // Use wp_delete_post (via wp_delete_post_revision) again. Ensures any meta/misplaced data gets cleaned up. foreach ( $revision_ids as $revision_id ) { wp_delete_post_revision( $revision_id ); @@ -3540,14 +3552,20 @@ function wp_delete_post( $postid = 0, $force_delete = false ) { wp_defer_comment_counting( true ); - $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d ORDER BY comment_ID DESC", $postid ) ); + $comment_ids = $wpdb->get_col( + $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d ORDER BY comment_ID DESC", $post_id ) + ); + foreach ( $comment_ids as $comment_id ) { wp_delete_comment( $comment_id, true ); } wp_defer_comment_counting( false ); - $post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $postid ) ); + $post_meta_ids = $wpdb->get_col( + $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $post_id ) + ); + foreach ( $post_meta_ids as $mid ) { delete_metadata_by_mid( 'post', $mid ); } @@ -3571,12 +3589,12 @@ function wp_delete_post( $postid = 0, $force_delete = false ) { * @since 1.2.0 * @since 5.5.0 Added the `$post` parameter. * - * @param int $postid Post ID. - * @param WP_Post $post Post object. + * @param int $post_id Post ID. + * @param WP_Post $post Post object. */ - do_action( 'delete_post', $postid, $post ); + do_action( 'delete_post', $post_id, $post ); - $result = $wpdb->delete( $wpdb->posts, array( 'ID' => $postid ) ); + $result = $wpdb->delete( $wpdb->posts, array( 'ID' => $post_id ) ); if ( ! $result ) { return false; } @@ -3600,10 +3618,10 @@ function wp_delete_post( $postid = 0, $force_delete = false ) { * @since 2.2.0 * @since 5.5.0 Added the `$post` parameter. * - * @param int $postid Post ID. - * @param WP_Post $post Post object. + * @param int $post_id Post ID. + * @param WP_Post $post Post object. */ - do_action( 'deleted_post', $postid, $post ); + do_action( 'deleted_post', $post_id, $post ); clean_post_cache( $post ); @@ -3613,7 +3631,7 @@ function wp_delete_post( $postid = 0, $force_delete = false ) { } } - wp_clear_scheduled_hook( 'publish_future_post', array( $postid ) ); + wp_clear_scheduled_hook( 'publish_future_post', array( $post_id ) ); /** * Fires after a post is deleted, at the conclusion of wp_delete_post(). @@ -3623,10 +3641,10 @@ function wp_delete_post( $postid = 0, $force_delete = false ) { * * @see wp_delete_post() * - * @param int $postid Post ID. - * @param WP_Post $post Post object. + * @param int $post_id Post ID. + * @param WP_Post $post Post object. */ - do_action( 'after_delete_post', $postid, $post ); + do_action( 'after_delete_post', $post_id, $post ); return $post; } diff --git a/wp-includes/version.php b/wp-includes/version.php index 5958757bb6..41f231c81c 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.6-alpha-57854'; +$wp_version = '6.6-alpha-57857'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.