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
798 798 } 799 799 800 800 /** 801 * Removes comment IDand maybe updates post comment count.801 * Trashes the comment and maybe updates post comment count. 802 802 * 803 803 * 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. 805 806 * 806 807 * @since 2.0.0 807 808 * @uses $wpdb … … 810 811 * @uses wp_transition_comment_status() Passes new and old comment status along with $comment object 811 812 * 812 813 * @param int $comment_id Comment ID 814 * @param bool $force_delete Whether to bypass trash and force deletion 813 815 * @return bool False if delete comment query failure, true on success. 814 816 */ 815 function wp_delete_comment( $comment_id) {817 function wp_delete_comment( $comment_id, $force_delete = false ) { 816 818 global $wpdb; 817 819 if (!$comment = get_comment($comment_id)) 818 820 return false; 819 821 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 } 822 832 823 833 do_action('delete_comment', $comment_id); 824 834 … … 850 860 * Moves a comment to the Trash 851 861 * 852 862 * @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() 855 864 * 856 865 * @param int $comment_id Comment ID. 857 866 * @return mixed False on failure 858 867 */ 859 868 function 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); 876 870 } 877 871 878 872 /** -
post.php
1155 1155 } 1156 1156 1157 1157 /** 1158 * Removes a post, attachment, or page.1158 * Trashes a post or page or maybe deletes it. 1159 1159 * 1160 1160 * When the post and page goes, everything that is tied to it is deleted also. 1161 1161 * 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. 1162 1164 * 1163 1165 * @since 1.0.0 1164 1166 * @uses do_action() on 'delete_post' before deletion unless post type is 'attachment'. … … 1175 1177 if ( !$post = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d", $postid)) ) 1176 1178 return $post; 1177 1179 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 1181 1180 if ( $post->post_type == 'attachment' ) 1182 1181 return wp_delete_attachment( $postid, $force_delete ); 1183 1182 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 1184 1195 do_action('delete_post', $postid); 1185 1196 1186 1197 delete_post_meta($postid,'_wp_trash_meta_status'); … … 1262 1273 * Moves a post or page to the Trash 1263 1274 * 1264 1275 * @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() 1267 1277 * 1268 1278 * @param int $postid Post ID. 1269 1279 * @return mixed False on failure 1270 1280 */ 1271 1281 function 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); 1294 1283 } 1295 1284 1296 1285 /** … … 2816 2805 } 2817 2806 2818 2807 /** 2819 * Delete anattachment.2808 * Move an attachment to trash or maybe delete the attachment. 2820 2809 * 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 2822 2814 * meta fields, taxonomy, comments, etc associated with the attachment (except 2823 2815 * the main post). 2824 2816 * 2825 2817 * @since 2.0.0 2826 2818 * @uses $wpdb 2827 2819 * @uses do_action() Calls 'delete_attachment' hook on Attachment ID. 2820 * @uses MEDIA_TRASH 2828 2821 * 2829 2822 * @param int $postid Attachment ID. 2830 2823 * @param bool $force_delete Whether to bypass trash and force deletion … … 2839 2832 if ( 'attachment' != $post->post_type ) 2840 2833 return false; 2841 2834 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 } 2844 2846 2845 2847 delete_post_meta($post_id, '_wp_trash_meta_status'); 2846 2848 delete_post_meta($post_id, '_wp_trash_meta_time');
