WordPress.org

Make WordPress Core

Changeset 13995


Ignore:
Timestamp:
04/04/2010 12:20:19 PM (9 years ago)
Author:
nacin
Message:

Add $force_delete to wp_delete_comment(). see #12766, see #11470.

Location:
trunk/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/comment.php

    r13937 r13995  
    857857
    858858/**
    859  * Removes comment ID and maybe updates post comment count.
     859 * Trashes or deletes a comment.
     860 *
     861 * The comment is moved to trash instead of permanently deleted unless trash is
     862 * disabled, item is already in the trash, or $force_delete is true.
    860863 *
    861864 * The post comment count will be updated if the comment was approved and has a
     
    870873 *
    871874 * @param int $comment_id Comment ID
     875 * @param bool $force_delete Whether to bypass trash and force deletion. Default is false.
    872876 * @return bool False if delete comment query failure, true on success.
    873877 */
    874 function wp_delete_comment($comment_id) {
     878function wp_delete_comment($comment_id, $force_delete = false) {
    875879    global $wpdb;
    876880    if (!$comment = get_comment($comment_id))
    877881        return false;
    878882
    879     if (wp_get_comment_status($comment_id) != 'trash' && wp_get_comment_status($comment_id) != 'spam' && EMPTY_TRASH_DAYS > 0)
     883    if ( !$force_delete && EMPTY_TRASH_DAYS && !in_array( wp_get_comment_status($comment_id), array( 'trash', 'spam' ) ) )
    880884        return wp_trash_comment($comment_id);
    881885
     
    916920 * Moves a comment to the Trash
    917921 *
     922 * If trash is disabled, comment is permanently deleted.
     923 *
    918924 * @since 2.9.0
    919925 * @uses do_action() on 'trash_comment' before trashing
    920926 * @uses do_action() on 'trashed_comment' after trashing
     927 * @uses wp_delete_comment() if trash is disabled
    921928 *
    922929 * @param int $comment_id Comment ID.
     
    924931 */
    925932function wp_trash_comment($comment_id) {
    926     if ( EMPTY_TRASH_DAYS == 0 )
    927         return wp_delete_comment($comment_id);
     933    if ( !EMPTY_TRASH_DAYS )
     934        return wp_delete_comment($comment_id, true);
    928935
    929936    if ( !$comment = get_comment($comment_id) )
  • trunk/wp-includes/post.php

    r13985 r13995  
    15931593
    15941594/**
    1595  * Removes a post, attachment, or page.
    1596  *
    1597  * When the post and page goes, everything that is tied to it is deleted also.
     1595 * Trashes or deletes a post or page.
     1596 *
     1597 * When the post and page is permanently deleted, everything that is tied to it is deleted also.
    15981598 * This includes comments, post meta fields, and terms associated with the post.
     1599 *
     1600 * The post or page is moved to trash instead of permanently deleted unless trash is
     1601 * disabled, item is already in the trash, or $force_delete is true.
    15991602 *
    16001603 * @since 1.0.0
     
    16021605 * @uses do_action() on 'deleted_post' after deletion unless post type is 'attachment'.
    16031606 * @uses wp_delete_attachment() if post type is 'attachment'.
     1607 * @uses wp_trash_post() if item should be trashed.
    16041608 *
    16051609 * @param int $postid Post ID.
    1606  * @param bool $force_delete Whether to bypass trash and force deletion
     1610 * @param bool $force_delete Whether to bypass trash and force deletion. Defaults to false.
    16071611 * @return mixed False on failure
    16081612 */
     
    16131617        return $post;
    16141618
    1615     if ( !$force_delete && ( $post->post_type == 'post' || $post->post_type == 'page') && get_post_status( $postid ) != 'trash' && EMPTY_TRASH_DAYS > 0 )
     1619    if ( !$force_delete && ( $post->post_type == 'post' || $post->post_type == 'page') && get_post_status( $postid ) != 'trash' && EMPTY_TRASH_DAYS )
    16161620            return wp_trash_post($postid);
    16171621
     
    16991703 * Moves a post or page to the Trash
    17001704 *
     1705 * If trash is disabled, the post or page is permanently deleted.
     1706 *
    17011707 * @since 2.9.0
    17021708 * @uses do_action() on 'trash_post' before trashing
    17031709 * @uses do_action() on 'trashed_post' after trashing
     1710 * @uses wp_delete_post() if trash is disabled
    17041711 *
    17051712 * @param int $postid Post ID.
     
    17071714 */
    17081715function wp_trash_post($post_id = 0) {
    1709     if ( EMPTY_TRASH_DAYS == 0 )
    1710         return wp_delete_post($post_id);
     1716    if ( !EMPTY_TRASH_DAYS )
     1717        return wp_delete_post($post_id, true);
    17111718
    17121719    if ( !$post = wp_get_single_post($post_id, ARRAY_A) )
     
    32973304
    32983305/**
    3299  * Delete an attachment.
    3300  *
    3301  * Will remove the file also, when the attachment is removed. Removes all post
    3302  * meta fields, taxonomy, comments, etc associated with the attachment (except
    3303  * the main post).
     3306 * Trashes or deletes an attachment.
     3307 *
     3308 * When an attachment is permanently deleted, the file will also be removed.
     3309 * Deletion removes all post meta fields, taxonomy, comments, etc. associated
     3310 * with the attachment (except the main post).
     3311 *
     3312 * The attachment is moved to the trash instead of permanently deleted unless trash
     3313 * for media is disabled, item is already in the trash, or $force_delete is true.
    33043314 *
    33053315 * @since 2.0.0
     
    33083318 *
    33093319 * @param int $postid Attachment ID.
    3310  * @param bool $force_delete Whether to bypass trash and force deletion
     3320 * @param bool $force_delete Whether to bypass trash and force deletion. Defaults to false.
    33113321 * @return mixed False on failure. Post data on success.
    33123322 */
Note: See TracChangeset for help on using the changeset viewer.