Changeset 11749 for trunk/wp-includes/post.php
- Timestamp:
- 07/30/2009 01:39:34 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/post.php
r11734 r11749 999 999 $count = $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A ); 1000 1000 1001 $stats = array( 'publish' => 0, 'private' => 0, 'draft' => 0, 'pending' => 0, 'future' => 0 );1001 $stats = array( 'publish' => 0, 'private' => 0, 'draft' => 0, 'pending' => 0, 'future' => 0, 'trash' => 0 ); 1002 1002 foreach( (array) $count as $row_num => $row ) { 1003 1003 $stats[$row['post_status']] = $row['num_posts']; … … 1028 1028 1029 1029 $and = wp_post_mime_type_where( $mime_type ); 1030 $count = $wpdb->get_results( "SELECT post_mime_type, COUNT( * ) AS num_posts FROM $wpdb->posts WHERE post_type = 'attachment' $and GROUP BY post_mime_type", ARRAY_A );1030 $count = $wpdb->get_results( "SELECT post_mime_type, COUNT( * ) AS num_posts FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' $and GROUP BY post_mime_type", ARRAY_A ); 1031 1031 1032 1032 $stats = array( ); … … 1034 1034 $stats[$row['post_mime_type']] = $row['num_posts']; 1035 1035 } 1036 $stats['trash'] = $wpdb->get_var( "SELECT COUNT( * ) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status = 'trash' $and"); 1036 1037 1037 1038 return (object) $stats; … … 1141 1142 return $post; 1142 1143 1143 if ( 'attachment' == $post->post_type ) 1144 if ( ($post->post_type == 'post' || $post->post_type == 'page') && get_post_status($postid) != 'trash' && EMPTY_TRASH_DAYS > 0 ) 1145 return wp_trash_post($postid); 1146 1147 if ( $post->post_type == 'attachment' ) 1144 1148 return wp_delete_attachment($postid); 1145 1149 1146 1150 do_action('delete_post', $postid); 1151 1152 $trash_meta = get_option('wp_trash_meta'); 1153 if ( is_array($trash_meta) && isset($trash_meta['posts'][$postid]) ) { 1154 unset($trash_meta['posts'][$postid]); 1155 update_option('wp_trash_meta', $trash_meta); 1156 } 1147 1157 1148 1158 /** @todo delete for pluggable post taxonomies too */ … … 1201 1211 1202 1212 do_action('deleted_post', $postid); 1213 1214 return $post; 1215 } 1216 1217 /** 1218 * Moves a post or page to the Trash 1219 * 1220 * @since 2.9.0 1221 * @uses do_action() on 'trash_post' before trashing 1222 * @uses do_action() on 'trashed_post' after trashing 1223 * 1224 * @param int $postid Post ID. 1225 * @return mixed False on failure 1226 */ 1227 function wp_trash_post($postid = 0) { 1228 if ( EMPTY_TRASH_DAYS == 0 ) 1229 return wp_delete_post($postid); 1230 1231 if ( !$post = wp_get_single_post($postid, ARRAY_A) ) 1232 return $post; 1233 1234 do_action('trash_post', $postid); 1235 1236 $trash_meta = get_option('wp_trash_meta'); 1237 if ( !is_array($trash_meta) ) 1238 $trash_meta = array(); 1239 $trash_meta['posts'][$postid]['status'] = $post['post_status']; 1240 $trash_meta['posts'][$postid]['time'] = time(); 1241 update_option('wp_trash_meta', $trash_meta); 1242 1243 $post['post_status'] = 'trash'; 1244 wp_insert_post($post); 1245 1246 do_action('trashed_post', $postid); 1247 1248 return $post; 1249 } 1250 1251 /** 1252 * Removes a post or page from the Trash 1253 * 1254 * @since 2.9.0 1255 * @uses do_action() on 'untrash_post' before undeletion 1256 * @uses do_action() on 'untrashed_post' after undeletion 1257 * 1258 * @param int $postid Post ID. 1259 * @return mixed False on failure 1260 */ 1261 function wp_untrash_post($postid = 0) { 1262 if (!$post = wp_get_single_post($postid, ARRAY_A)) 1263 return $post; 1264 1265 do_action('untrash_post', $postid); 1266 1267 $post['post_status'] = 'draft'; 1268 1269 $trash_meta = get_option('wp_trash_meta'); 1270 if (is_array($trash_meta) && isset($trash_meta['posts'][$postid])) { 1271 $post['post_status'] = $trash_meta['posts'][$postid]['status']; 1272 unset($trash_meta['posts'][$postid]); 1273 update_option('wp_trash_meta', $trash_meta); 1274 } 1275 1276 wp_insert_post($post); 1277 1278 do_action('untrashed_post', $postid); 1203 1279 1204 1280 return $post; … … 2587 2663 if ( 'attachment' != $post->post_type ) 2588 2664 return false; 2665 2666 if ( 'trash' != $post->post_status ) 2667 return wp_trash_post($postid); 2668 2669 $trash_meta = get_option('wp_trash_meta'); 2670 if ( is_array($trash_meta) && isset($trash_meta['posts'][$postid]) ) { 2671 unset($trash_meta['posts'][$postid]); 2672 update_option('wp_trash_meta', $trash_meta); 2673 } 2589 2674 2590 2675 $meta = wp_get_attachment_metadata( $postid );
Note: See TracChangeset
for help on using the changeset viewer.