Make WordPress Core

Changeset 57857


Ignore:
Timestamp:
03/19/2024 05:45:30 PM (4 weeks ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Rename the $postid parameter to $post_id in wp_delete_post().

This matches the parameter name in wp_trash_post() and all the other functions receiving post ID as a parameter.

See #60700.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post.php

    r57853 r57857  
    34613461 * @see wp_trash_post()
    34623462 *
    3463  * @param int  $postid       Optional. Post ID. Default 0.
     3463 * @param int  $post_id      Optional. Post ID. Default 0.
    34643464 * @param bool $force_delete Optional. Whether to bypass Trash and force deletion.
    34653465 *                           Default false.
    34663466 * @return WP_Post|false|null Post data on success, false or null on failure.
    34673467 */
    3468 function wp_delete_post( $postid = 0, $force_delete = false ) {
     3468function wp_delete_post( $post_id = 0, $force_delete = false ) {
    34693469    global $wpdb;
    34703470
    3471     $post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID = %d", $postid ) );
     3471    $post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID = %d", $post_id ) );
    34723472
    34733473    if ( ! $post ) {
     
    34773477    $post = get_post( $post );
    34783478
    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 );
    34813484    }
    34823485
    34833486    if ( 'attachment' === $post->post_type ) {
    3484         return wp_delete_attachment( $postid, $force_delete );
     3487        return wp_delete_attachment( $post_id, $force_delete );
    34853488    }
    34863489
     
    35073510     * @see wp_delete_post()
    35083511     *
    3509      * @param int     $postid Post ID.
    3510      * @param WP_Post $post   Post object.
     3512     * @param int     $post_id Post ID.
     3513     * @param WP_Post $post    Post object.
    35113514     */
    3512     do_action( 'before_delete_post', $postid, $post );
    3513 
    3514     delete_post_meta( $postid, '_wp_trash_meta_status' );
    3515     delete_post_meta( $postid, '_wp_trash_meta_time' );
    3516 
    3517     wp_delete_object_term_relationships( $postid, 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 ) );
    35183521
    35193522    $parent_data  = array( 'post_parent' => $post->post_parent );
    3520     $parent_where = array( 'post_parent' => $postid );
     3523    $parent_where = array( 'post_parent' => $post_id );
    35213524
    35223525    if ( is_post_type_hierarchical( $post->post_type ) ) {
    35233526        // 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
    35263535        if ( $children ) {
    35273536            $wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => $post->post_type ) );
     
    35303539
    35313540    // 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
    35333545    // Use wp_delete_post (via wp_delete_post_revision) again. Ensures any meta/misplaced data gets cleaned up.
    35343546    foreach ( $revision_ids as $revision_id ) {
     
    35413553    wp_defer_comment_counting( true );
    35423554
    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
    35443559    foreach ( $comment_ids as $comment_id ) {
    35453560        wp_delete_comment( $comment_id, true );
     
    35483563    wp_defer_comment_counting( false );
    35493564
    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
    35513569    foreach ( $post_meta_ids as $mid ) {
    35523570        delete_metadata_by_mid( 'post', $mid );
     
    35723590     * @since 5.5.0 Added the `$post` parameter.
    35733591     *
    3574      * @param int     $postid Post ID.
    3575      * @param WP_Post $post   Post object.
     3592     * @param int     $post_id Post ID.
     3593     * @param WP_Post $post    Post object.
    35763594     */
    3577     do_action( 'delete_post', $postid, $post );
    3578 
    3579     $result = $wpdb->delete( $wpdb->posts, array( 'ID' => $postid ) );
     3595    do_action( 'delete_post', $post_id, $post );
     3596
     3597    $result = $wpdb->delete( $wpdb->posts, array( 'ID' => $post_id ) );
    35803598    if ( ! $result ) {
    35813599        return false;
     
    36013619     * @since 5.5.0 Added the `$post` parameter.
    36023620     *
    3603      * @param int     $postid Post ID.
    3604      * @param WP_Post $post   Post object.
     3621     * @param int     $post_id Post ID.
     3622     * @param WP_Post $post    Post object.
    36053623     */
    3606     do_action( 'deleted_post', $postid, $post );
     3624    do_action( 'deleted_post', $post_id, $post );
    36073625
    36083626    clean_post_cache( $post );
     
    36143632    }
    36153633
    3616     wp_clear_scheduled_hook( 'publish_future_post', array( $postid ) );
     3634    wp_clear_scheduled_hook( 'publish_future_post', array( $post_id ) );
    36173635
    36183636    /**
     
    36243642     * @see wp_delete_post()
    36253643     *
    3626      * @param int     $postid Post ID.
    3627      * @param WP_Post $post   Post object.
     3644     * @param int     $post_id Post ID.
     3645     * @param WP_Post $post    Post object.
    36283646     */
    3629     do_action( 'after_delete_post', $postid, $post );
     3647    do_action( 'after_delete_post', $post_id, $post );
    36303648
    36313649    return $post;
Note: See TracChangeset for help on using the changeset viewer.