WordPress.org

Make WordPress Core

Changeset 11878


Ignore:
Timestamp:
08/25/2009 10:05:15 PM (9 years ago)
Author:
westi
Message:

Move the storage of the metadata for trashed posts into the post meta table rather than storing it in an option. See #4529.

Location:
trunk/wp-includes
Files:
3 edited

Legend:

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

    r11873 r11878  
    777777                $caps[] = 'delete_published_posts';
    778778            } elseif ( 'trash' == $post->post_status ) {
    779                 $trash_meta = get_option('wp_trash_meta');
    780                 if (is_array($trash_meta) && isset($trash_meta['posts'][$post->ID]['status']) && $trash_meta['posts'][$post->ID]['status'] == 'publish')
     779                if ('publish' == get_post_meta($post->ID, '_wp_trash_meta_status', true) )
    781780                    $caps[] = 'delete_published_posts';
    782781            } else {
     
    806805                $caps[] = 'delete_published_pages';
    807806            } elseif ( 'trash' == $page->post_status ) {
    808                 $trash_meta = get_option('wp_trash_meta');
    809                 if (is_array($trash_meta) && isset($trash_meta['posts'][$page->ID]['status']) && $trash_meta['posts'][$page->ID]['status'] == 'publish')
     807                if ('publish' == get_post_meta($page->ID, '_wp_trash_meta_status', true) )
    810808                    $caps[] = 'delete_published_pages';
    811809            } else {
     
    841839                $caps[] = 'edit_published_posts';
    842840            } elseif ( 'trash' == $post->post_status ) {
    843                 $trash_meta = get_option('wp_trash_meta');
    844                 if ( is_array($trash_meta) && isset($trash_meta['posts'][$post->ID]['status']) && $trash_meta['posts'][$post->ID]['status'] == 'publish' )
     841                if ('publish' == get_post_meta($post->ID, '_wp_trash_meta_status', true) )
    845842                    $caps[] = 'edit_published_posts';
    846843            } else {
     
    870867                $caps[] = 'edit_published_pages';
    871868            } elseif ( 'trash' == $page->post_status ) {
    872                 $trash_meta = get_option('wp_trash_meta');
    873                 if ( is_array($trash_meta) && isset($trash_meta['posts'][$page->ID]['status']) && $trash_meta['posts'][$page->ID]['status'] == 'publish' )
     869                if ('publish' == get_post_meta($page->ID, '_wp_trash_meta_status', true) )
    874870                    $caps[] = 'edit_published_pages';
    875871            } else {
  • trunk/wp-includes/functions.php

    r11750 r11878  
    33473347 */
    33483348function wp_scheduled_delete() {
     3349    global $wpdb;
     3350
     3351    $delete_timestamp = time() - (60*60*24*EMPTY_TRASH_DAYS);
     3352   
     3353    $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);
     3354   
     3355    foreach ( (array) $posts_to_delete as $post ) {
     3356        wp_delete_post($post['post_id']);
     3357    }
     3358
     3359    //Trashed Comments
     3360    //TODO Come up with a better store for the comment trash meta.
    33493361    $trash_meta = get_option('wp_trash_meta');
    33503362    if ( !is_array($trash_meta) )
    33513363        return;
    3352 
    3353     $delete_timestamp = time() - (60*60*24*EMPTY_TRASH_DAYS);
    33543364
    33553365    foreach ( (array) $trash_meta['comments'] as $id => $meta ) {
     
    33593369        }
    33603370    }
    3361     foreach ( (array) $trash_meta['posts'] as $id => $meta ) {
    3362         if ( $meta['time'] < $delete_timestamp ) {
    3363             wp_delete_post($id);
    3364             unset($trash_meta['posts'][$id]);
    3365         }
    3366     }
    33673371
    33683372    update_option('wp_trash_meta', $trash_meta);
    33693373}
     3374?>
  • trunk/wp-includes/post.php

    r11841 r11878  
    11501150    do_action('delete_post', $postid);
    11511151   
    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     }
     1152    delete_post_meta($postid,'_wp_trash_meta_status');
     1153    delete_post_meta($postid,'_wp_trash_meta_time');
    11571154
    11581155    /** @todo delete for pluggable post taxonomies too */
     
    12251222 * @return mixed False on failure
    12261223 */
    1227 function wp_trash_post($postid = 0) {
     1224function wp_trash_post($post_id = 0) {
    12281225    if ( EMPTY_TRASH_DAYS == 0 )
    1229         return wp_delete_post($postid);
    1230 
    1231     if ( !$post = wp_get_single_post($postid, ARRAY_A) )
     1226        return wp_delete_post($post_id);
     1227
     1228    if ( !$post = wp_get_single_post($post_id, ARRAY_A) )
    12321229        return $post;
    12331230
    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);
     1231    do_action('trash_post', $post_id);
     1232
     1233    add_post_meta($post_id,'_wp_trash_meta_status', $post['post_status']);
     1234    add_post_meta($post_id,'_wp_trash_meta_time', time());
    12421235
    12431236    $post['post_status'] = 'trash';
    12441237    wp_insert_post($post);
    12451238
    1246     do_action('trashed_post', $postid);
     1239    do_action('trashed_post', $post_id);
    12471240
    12481241    return $post;
     
    12591252 * @return mixed False on failure
    12601253 */
    1261 function wp_untrash_post($postid = 0) {
    1262     if ( !$post = wp_get_single_post($postid, ARRAY_A) )
     1254function wp_untrash_post($post_id = 0) {
     1255    if ( !$post = wp_get_single_post($post_id, ARRAY_A) )
    12631256        return $post;
    12641257
    1265     do_action('untrash_post', $postid);
    1266 
    1267     $post['post_status'] = ($post->post_type == 'attachment') ? 'inherit' : '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     }
     1258    do_action('untrash_post', $post_id);
     1259
     1260    $post['post_status'] = ('attachment' == $post['post_type'] ) ? 'inherit' : 'draft';
     1261
     1262    delete_post_meta($post_id,'_wp_trash_meta_status');
     1263    delete_post_meta($post_id,'_wp_trash_meta_time');
    12751264
    12761265    wp_insert_post($post);
    12771266
    1278     do_action('untrashed_post', $postid);
     1267    do_action('untrashed_post', $post_id);
    12791268
    12801269    return $post;
     
    26672656        return wp_trash_post($postid);
    26682657
    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     }
     2658    delete_post_meta($post_id,'_wp_trash_meta_status');
     2659    delete_post_meta($post_id,'_wp_trash_meta_time');
     2660       
    26742661
    26752662    $meta = wp_get_attachment_metadata( $postid );
Note: See TracChangeset for help on using the changeset viewer.