Ticket #11470: 11470-trash-functions-become-wrappers.diff

File 11470-trash-functions-become-wrappers.diff, 6.7 KB (added by nacin, 3 years ago)
  • comment.php

     
    798798} 
    799799 
    800800/** 
    801  * Removes comment ID and maybe updates post comment count. 
     801 * Trashes the comment and maybe updates post comment count. 
    802802 * 
    803803 * The post comment count will be updated if the comment was approved and has a 
    804  * post ID available. 
     804 * post ID available. The comment will be deleted if it is already in spam or trash, 
     805 * if trash is disabled, or if $force_delete is true. 
    805806 * 
    806807 * @since 2.0.0 
    807808 * @uses $wpdb 
     
    810811 * @uses wp_transition_comment_status() Passes new and old comment status along with $comment object 
    811812 * 
    812813 * @param int $comment_id Comment ID 
     814 * @param bool $force_delete Whether to bypass trash and force deletion 
    813815 * @return bool False if delete comment query failure, true on success. 
    814816 */ 
    815 function wp_delete_comment($comment_id) { 
     817function wp_delete_comment( $comment_id, $force_delete = false ) { 
    816818        global $wpdb; 
    817819        if (!$comment = get_comment($comment_id)) 
    818820                return false; 
    819821 
    820         if (wp_get_comment_status($comment_id) != 'trash' && wp_get_comment_status($comment_id) != 'spam' && EMPTY_TRASH_DAYS > 0) 
    821                 return wp_trash_comment($comment_id); 
     822        if ( !$force_delete && EMPTY_TRASH_DAYS && !in_array( wp_get_comment_status($comment_id), array('trash', 'spam') ) ) { 
     823                do_action('trash_comment', $comment_id); 
     824                if ( wp_set_comment_status($comment_id, 'trash') ) { 
     825                        add_comment_meta($comment_id, '_wp_trash_meta_status', $comment->comment_approved); 
     826                        add_comment_meta($comment_id, '_wp_trash_meta_time', time() ); 
     827                        do_action('trashed_comment', $comment_id); 
     828                        return true; 
     829                } 
     830                return false; 
     831        } 
    822832 
    823833        do_action('delete_comment', $comment_id); 
    824834 
     
    850860 * Moves a comment to the Trash 
    851861 * 
    852862 * @since 2.9.0 
    853  * @uses do_action() on 'trash_comment' before trashing 
    854  * @uses do_action() on 'trashed_comment' after trashing 
     863 * @uses wp_delete_comment() 
    855864 * 
    856865 * @param int $comment_id Comment ID. 
    857866 * @return mixed False on failure 
    858867 */ 
    859868function wp_trash_comment($comment_id) { 
    860         if ( EMPTY_TRASH_DAYS == 0 ) 
    861                 return wp_delete_comment($comment_id); 
    862  
    863         if ( !$comment = get_comment($comment_id) ) 
    864                 return false; 
    865  
    866         do_action('trash_comment', $comment_id); 
    867  
    868         if ( wp_set_comment_status($comment_id, 'trash') ) { 
    869                 add_comment_meta($comment_id, '_wp_trash_meta_status', $comment->comment_approved); 
    870                 add_comment_meta($comment_id, '_wp_trash_meta_time', time() ); 
    871                 do_action('trashed_comment', $comment_id); 
    872                 return true; 
    873         } 
    874  
    875         return false; 
     869        return wp_delete_comment($comment_id); 
    876870} 
    877871 
    878872/** 
  • post.php

     
    11551155} 
    11561156 
    11571157/** 
    1158  * Removes a post, attachment, or page. 
     1158 * Trashes a post or page or maybe deletes it. 
    11591159 * 
    11601160 * When the post and page goes, everything that is tied to it is deleted also. 
    11611161 * This includes comments, post meta fields, and terms associated with the post. 
     1162 * Post or page is moved to trash instead of permanently deleted unless trash is 
     1163 * disabled, item is already in the trash, or $force_delete is true. 
    11621164 * 
    11631165 * @since 1.0.0 
    11641166 * @uses do_action() on 'delete_post' before deletion unless post type is 'attachment'. 
     
    11751177        if ( !$post = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d", $postid)) ) 
    11761178                return $post; 
    11771179 
    1178         if ( !$force_delete && ( $post->post_type == 'post' || $post->post_type == 'page') && get_post_status( $postid ) != 'trash' && EMPTY_TRASH_DAYS > 0 ) 
    1179                         return wp_trash_post($postid); 
    1180  
    11811180        if ( $post->post_type == 'attachment' ) 
    11821181                return wp_delete_attachment( $postid, $force_delete ); 
    11831182 
     1183        // Trash post if warranted. 
     1184        if ( !$force_delete && EMPTY_TRASH_DAYS && ( $post->post_type == 'post' || $post->post_type == 'page') && get_post_status( $postid ) != 'trash' ) { 
     1185                do_action('trash_post', $post_id); 
     1186                add_post_meta($post_id,'_wp_trash_meta_status', $post['post_status']); 
     1187                add_post_meta($post_id,'_wp_trash_meta_time', time()); 
     1188                $post['post_status'] = 'trash'; 
     1189                wp_insert_post($post); 
     1190                wp_trash_post_comments($post_id); 
     1191                do_action('trashed_post', $post_id); 
     1192                return $post; 
     1193        } 
     1194 
    11841195        do_action('delete_post', $postid); 
    11851196 
    11861197        delete_post_meta($postid,'_wp_trash_meta_status'); 
     
    12621273 * Moves a post or page to the Trash 
    12631274 * 
    12641275 * @since 2.9.0 
    1265  * @uses do_action() on 'trash_post' before trashing 
    1266  * @uses do_action() on 'trashed_post' after trashing 
     1276 * @uses wp_delete_post() 
    12671277 * 
    12681278 * @param int $postid Post ID. 
    12691279 * @return mixed False on failure 
    12701280 */ 
    12711281function wp_trash_post($post_id = 0) { 
    1272         if ( EMPTY_TRASH_DAYS == 0 ) 
    1273                 return wp_delete_post($post_id); 
    1274  
    1275         if ( !$post = wp_get_single_post($post_id, ARRAY_A) ) 
    1276                 return $post; 
    1277  
    1278         if ( $post['post_status'] == 'trash' ) 
    1279                 return false; 
    1280  
    1281         do_action('trash_post', $post_id); 
    1282  
    1283         add_post_meta($post_id,'_wp_trash_meta_status', $post['post_status']); 
    1284         add_post_meta($post_id,'_wp_trash_meta_time', time()); 
    1285  
    1286         $post['post_status'] = 'trash'; 
    1287         wp_insert_post($post); 
    1288  
    1289         wp_trash_post_comments($post_id); 
    1290  
    1291         do_action('trashed_post', $post_id); 
    1292  
    1293         return $post; 
     1282        return wp_delete_post($post_id); 
    12941283} 
    12951284 
    12961285/** 
     
    28162805} 
    28172806 
    28182807/** 
    2819  * Delete an attachment. 
     2808 * Move an attachment to trash or maybe delete the attachment. 
    28202809 * 
    2821  * Will remove the file also, when the attachment is removed. Removes all post 
     2810 * If trash for media is enabled, the attachment is moved to trash, unless 
     2811 * $force_delete is true or the attachment is already in the trash. 
     2812 * 
     2813 * Will remove the file also, when the attachment is deleted. Deletes all post 
    28222814 * meta fields, taxonomy, comments, etc associated with the attachment (except 
    28232815 * the main post). 
    28242816 * 
    28252817 * @since 2.0.0 
    28262818 * @uses $wpdb 
    28272819 * @uses do_action() Calls 'delete_attachment' hook on Attachment ID. 
     2820 * @uses MEDIA_TRASH 
    28282821 * 
    28292822 * @param int $postid Attachment ID. 
    28302823 * @param bool $force_delete Whether to bypass trash and force deletion 
     
    28392832        if ( 'attachment' != $post->post_type ) 
    28402833                return false; 
    28412834 
    2842         if ( !$force_delete && EMPTY_TRASH_DAYS && MEDIA_TRASH && 'trash' != $post->post_status ) 
    2843                 return wp_trash_post( $post_id ); 
     2835        // Trash post if warranted. 
     2836        if ( !$force_delete && EMPTY_TRASH_DAYS && MEDIA_TRASH && 'trash' != $post->post_status ) { 
     2837                do_action('trash_attachment', $post_id); 
     2838                add_post_meta($post_id,'_wp_trash_meta_status', $post['post_status']); 
     2839                add_post_meta($post_id,'_wp_trash_meta_time', time()); 
     2840                $post['post_status'] = 'trash'; 
     2841                wp_insert_post($post); 
     2842                wp_trash_post_comments($post_id); 
     2843                do_action('trashed_attachment', $post_id); 
     2844                return $post; 
     2845        } 
    28442846 
    28452847        delete_post_meta($post_id, '_wp_trash_meta_status'); 
    28462848        delete_post_meta($post_id, '_wp_trash_meta_time');