diff --git a/wp-includes/capabilities.php b/wp-includes/capabilities.php index 43a12e836..ec5b5020e 100644 --- a/wp-includes/capabilities.php +++ b/wp-includes/capabilities.php @@ -776,8 +776,7 @@ function map_meta_cap( $cap, $user_id ) { if ( 'publish' == $post->post_status ) { $caps[] = 'delete_published_posts'; } elseif ( 'trash' == $post->post_status ) { - $trash_meta = get_option('wp_trash_meta'); - if (is_array($trash_meta) && isset($trash_meta['posts'][$post->ID]['status']) && $trash_meta['posts'][$post->ID]['status'] == 'publish') + if ('publish' == get_post_meta($post->ID, '_wp_trash_meta_status', true) ) $caps[] = 'delete_published_posts'; } else { // If the post is draft... @@ -805,8 +804,7 @@ function map_meta_cap( $cap, $user_id ) { if ( $page->post_status == 'publish' ) { $caps[] = 'delete_published_pages'; } elseif ( 'trash' == $page->post_status ) { - $trash_meta = get_option('wp_trash_meta'); - if (is_array($trash_meta) && isset($trash_meta['posts'][$page->ID]['status']) && $trash_meta['posts'][$page->ID]['status'] == 'publish') + if ('publish' == get_post_meta($page->ID, '_wp_trash_meta_status', true) ) $caps[] = 'delete_published_pages'; } else { // If the page is draft... @@ -840,8 +838,7 @@ function map_meta_cap( $cap, $user_id ) { if ( 'publish' == $post->post_status ) { $caps[] = 'edit_published_posts'; } elseif ( 'trash' == $post->post_status ) { - $trash_meta = get_option('wp_trash_meta'); - if ( is_array($trash_meta) && isset($trash_meta['posts'][$post->ID]['status']) && $trash_meta['posts'][$post->ID]['status'] == 'publish' ) + if ('publish' == get_post_meta($post->ID, '_wp_trash_meta_status', true) ) $caps[] = 'edit_published_posts'; } else { // If the post is draft... @@ -869,8 +866,7 @@ function map_meta_cap( $cap, $user_id ) { if ( 'publish' == $page->post_status ) { $caps[] = 'edit_published_pages'; } elseif ( 'trash' == $page->post_status ) { - $trash_meta = get_option('wp_trash_meta'); - if ( is_array($trash_meta) && isset($trash_meta['posts'][$page->ID]['status']) && $trash_meta['posts'][$page->ID]['status'] == 'publish' ) + if ('publish' == get_post_meta($page->ID, '_wp_trash_meta_status', true) ) $caps[] = 'edit_published_pages'; } else { // If the page is draft... diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 3a8528ca1..b04e1edcb 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -3346,24 +3346,29 @@ function _cleanup_header_comment($str) { * @return void */ function wp_scheduled_delete() { + global $wpdb; + + $delete_timestamp = time() - (60*60*24*EMPTY_TRASH_DAYS); + + $posts_to_delete = $wpdb->get_results($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_trash_meta_time' AND meta_value < '%d'", $delete_timestamp), ARRAY_A); + + foreach ( (array) $posts_to_delete as $post ) { + wp_delete_post($post['post_id']); + } + + //Trashed Comments + //TODO Come up with a better store for the comment trash meta. $trash_meta = get_option('wp_trash_meta'); if ( !is_array($trash_meta) ) return; - $delete_timestamp = time() - (60*60*24*EMPTY_TRASH_DAYS); - foreach ( (array) $trash_meta['comments'] as $id => $meta ) { if ( $meta['time'] < $delete_timestamp ) { wp_delete_comment($id); unset($trash_meta['comments'][$id]); } } - foreach ( (array) $trash_meta['posts'] as $id => $meta ) { - if ( $meta['time'] < $delete_timestamp ) { - wp_delete_post($id); - unset($trash_meta['posts'][$id]); - } - } update_option('wp_trash_meta', $trash_meta); } +?> \ No newline at end of file diff --git a/wp-includes/post.php b/wp-includes/post.php index 0f282dd8f..602ad5d71 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -1149,11 +1149,8 @@ function wp_delete_post($postid = 0) { do_action('delete_post', $postid); - $trash_meta = get_option('wp_trash_meta'); - if ( is_array($trash_meta) && isset($trash_meta['posts'][$postid]) ) { - unset($trash_meta['posts'][$postid]); - update_option('wp_trash_meta', $trash_meta); - } + delete_post_meta($postid,'_wp_trash_meta_status'); + delete_post_meta($postid,'_wp_trash_meta_time'); /** @todo delete for pluggable post taxonomies too */ wp_delete_object_term_relationships($postid, array('category', 'post_tag')); @@ -1224,26 +1221,22 @@ function wp_delete_post($postid = 0) { * @param int $postid Post ID. * @return mixed False on failure */ -function wp_trash_post($postid = 0) { +function wp_trash_post($post_id = 0) { if ( EMPTY_TRASH_DAYS == 0 ) - return wp_delete_post($postid); + return wp_delete_post($post_id); - if ( !$post = wp_get_single_post($postid, ARRAY_A) ) + if ( !$post = wp_get_single_post($post_id, ARRAY_A) ) return $post; - do_action('trash_post', $postid); + do_action('trash_post', $post_id); - $trash_meta = get_option('wp_trash_meta'); - if ( !is_array($trash_meta) ) - $trash_meta = array(); - $trash_meta['posts'][$postid]['status'] = $post['post_status']; - $trash_meta['posts'][$postid]['time'] = time(); - update_option('wp_trash_meta', $trash_meta); + add_post_meta($post_id,'_wp_trash_meta_status', $post['post_status']); + add_post_meta($post_id,'_wp_trash_meta_time', time()); $post['post_status'] = 'trash'; wp_insert_post($post); - do_action('trashed_post', $postid); + do_action('trashed_post', $post_id); return $post; } @@ -1258,24 +1251,20 @@ function wp_trash_post($postid = 0) { * @param int $postid Post ID. * @return mixed False on failure */ -function wp_untrash_post($postid = 0) { - if ( !$post = wp_get_single_post($postid, ARRAY_A) ) +function wp_untrash_post($post_id = 0) { + if ( !$post = wp_get_single_post($post_id, ARRAY_A) ) return $post; - do_action('untrash_post', $postid); + do_action('untrash_post', $post_id); - $post['post_status'] = ($post->post_type == 'attachment') ? 'inherit' : 'draft'; + $post['post_status'] = ('attachment' == $post['post_type'] ) ? 'inherit' : 'draft'; - $trash_meta = get_option('wp_trash_meta'); - if ( is_array($trash_meta) && isset($trash_meta['posts'][$postid]) ) { - $post['post_status'] = $trash_meta['posts'][$postid]['status']; - unset($trash_meta['posts'][$postid]); - update_option('wp_trash_meta', $trash_meta); - } + delete_post_meta($post_id,'_wp_trash_meta_status'); + delete_post_meta($post_id,'_wp_trash_meta_time'); wp_insert_post($post); - do_action('untrashed_post', $postid); + do_action('untrashed_post', $post_id); return $post; } @@ -2666,11 +2655,9 @@ function wp_delete_attachment($postid) { if ( 'trash' != $post->post_status ) return wp_trash_post($postid); - $trash_meta = get_option('wp_trash_meta'); - if ( is_array($trash_meta) && isset($trash_meta['posts'][$postid]) ) { - unset($trash_meta['posts'][$postid]); - update_option('wp_trash_meta', $trash_meta); - } + delete_post_meta($post_id,'_wp_trash_meta_status'); + delete_post_meta($post_id,'_wp_trash_meta_time'); + $meta = wp_get_attachment_metadata( $postid ); $file = get_attached_file( $postid );