Changeset 57857
- Timestamp:
- 03/19/2024 05:45:30 PM (6 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/post.php
r57853 r57857 3461 3461 * @see wp_trash_post() 3462 3462 * 3463 * @param int $post idOptional. Post ID. Default 0.3463 * @param int $post_id Optional. Post ID. Default 0. 3464 3464 * @param bool $force_delete Optional. Whether to bypass Trash and force deletion. 3465 3465 * Default false. 3466 3466 * @return WP_Post|false|null Post data on success, false or null on failure. 3467 3467 */ 3468 function wp_delete_post( $post id = 0, $force_delete = false ) {3468 function wp_delete_post( $post_id = 0, $force_delete = false ) { 3469 3469 global $wpdb; 3470 3470 3471 $post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID = %d", $post id ) );3471 $post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID = %d", $post_id ) ); 3472 3472 3473 3473 if ( ! $post ) { … … 3477 3477 $post = get_post( $post ); 3478 3478 3479 if ( ! $force_delete && ( 'post' === $post->post_type || 'page' === $post->post_type ) && 'trash' !== get_post_status( $postid ) && EMPTY_TRASH_DAYS ) { 3480 return wp_trash_post( $postid ); 3479 if ( ! $force_delete 3480 && ( 'post' === $post->post_type || 'page' === $post->post_type ) 3481 && 'trash' !== get_post_status( $post_id ) && EMPTY_TRASH_DAYS 3482 ) { 3483 return wp_trash_post( $post_id ); 3481 3484 } 3482 3485 3483 3486 if ( 'attachment' === $post->post_type ) { 3484 return wp_delete_attachment( $post id, $force_delete );3487 return wp_delete_attachment( $post_id, $force_delete ); 3485 3488 } 3486 3489 … … 3507 3510 * @see wp_delete_post() 3508 3511 * 3509 * @param int $post id Post ID.3510 * @param WP_Post $post Post object.3512 * @param int $post_id Post ID. 3513 * @param WP_Post $post Post object. 3511 3514 */ 3512 do_action( 'before_delete_post', $post id, $post );3513 3514 delete_post_meta( $post id, '_wp_trash_meta_status' );3515 delete_post_meta( $post id, '_wp_trash_meta_time' );3516 3517 wp_delete_object_term_relationships( $post id, get_object_taxonomies( $post->post_type ) );3515 do_action( 'before_delete_post', $post_id, $post ); 3516 3517 delete_post_meta( $post_id, '_wp_trash_meta_status' ); 3518 delete_post_meta( $post_id, '_wp_trash_meta_time' ); 3519 3520 wp_delete_object_term_relationships( $post_id, get_object_taxonomies( $post->post_type ) ); 3518 3521 3519 3522 $parent_data = array( 'post_parent' => $post->post_parent ); 3520 $parent_where = array( 'post_parent' => $post id );3523 $parent_where = array( 'post_parent' => $post_id ); 3521 3524 3522 3525 if ( is_post_type_hierarchical( $post->post_type ) ) { 3523 3526 // Point children of this page to its parent, also clean the cache of affected children. 3524 $children_query = $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_parent = %d AND post_type = %s", $postid, $post->post_type ); 3525 $children = $wpdb->get_results( $children_query ); 3527 $children_query = $wpdb->prepare( 3528 "SELECT * FROM $wpdb->posts WHERE post_parent = %d AND post_type = %s", 3529 $post_id, 3530 $post->post_type 3531 ); 3532 3533 $children = $wpdb->get_results( $children_query ); 3534 3526 3535 if ( $children ) { 3527 3536 $wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => $post->post_type ) ); … … 3530 3539 3531 3540 // Do raw query. wp_get_post_revisions() is filtered. 3532 $revision_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'revision'", $postid ) ); 3541 $revision_ids = $wpdb->get_col( 3542 $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'revision'", $post_id ) 3543 ); 3544 3533 3545 // Use wp_delete_post (via wp_delete_post_revision) again. Ensures any meta/misplaced data gets cleaned up. 3534 3546 foreach ( $revision_ids as $revision_id ) { … … 3541 3553 wp_defer_comment_counting( true ); 3542 3554 3543 $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d ORDER BY comment_ID DESC", $postid ) ); 3555 $comment_ids = $wpdb->get_col( 3556 $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d ORDER BY comment_ID DESC", $post_id ) 3557 ); 3558 3544 3559 foreach ( $comment_ids as $comment_id ) { 3545 3560 wp_delete_comment( $comment_id, true ); … … 3548 3563 wp_defer_comment_counting( false ); 3549 3564 3550 $post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $postid ) ); 3565 $post_meta_ids = $wpdb->get_col( 3566 $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $post_id ) 3567 ); 3568 3551 3569 foreach ( $post_meta_ids as $mid ) { 3552 3570 delete_metadata_by_mid( 'post', $mid ); … … 3572 3590 * @since 5.5.0 Added the `$post` parameter. 3573 3591 * 3574 * @param int $post id Post ID.3575 * @param WP_Post $post Post object.3592 * @param int $post_id Post ID. 3593 * @param WP_Post $post Post object. 3576 3594 */ 3577 do_action( 'delete_post', $post id, $post );3578 3579 $result = $wpdb->delete( $wpdb->posts, array( 'ID' => $post id ) );3595 do_action( 'delete_post', $post_id, $post ); 3596 3597 $result = $wpdb->delete( $wpdb->posts, array( 'ID' => $post_id ) ); 3580 3598 if ( ! $result ) { 3581 3599 return false; … … 3601 3619 * @since 5.5.0 Added the `$post` parameter. 3602 3620 * 3603 * @param int $post id Post ID.3604 * @param WP_Post $post Post object.3621 * @param int $post_id Post ID. 3622 * @param WP_Post $post Post object. 3605 3623 */ 3606 do_action( 'deleted_post', $post id, $post );3624 do_action( 'deleted_post', $post_id, $post ); 3607 3625 3608 3626 clean_post_cache( $post ); … … 3614 3632 } 3615 3633 3616 wp_clear_scheduled_hook( 'publish_future_post', array( $post id ) );3634 wp_clear_scheduled_hook( 'publish_future_post', array( $post_id ) ); 3617 3635 3618 3636 /** … … 3624 3642 * @see wp_delete_post() 3625 3643 * 3626 * @param int $post id Post ID.3627 * @param WP_Post $post Post object.3644 * @param int $post_id Post ID. 3645 * @param WP_Post $post Post object. 3628 3646 */ 3629 do_action( 'after_delete_post', $post id, $post );3647 do_action( 'after_delete_post', $post_id, $post ); 3630 3648 3631 3649 return $post;
Note: See TracChangeset
for help on using the changeset viewer.