mirror of
https://github.com/WordPress/WordPress.git
synced 2025-01-22 08:11:52 +01:00
Move the storage of the metadata for trashed posts into the post meta table rather than storing it in an option. See #4529.
git-svn-id: http://svn.automattic.com/wordpress/trunk@11878 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
3897050e45
commit
e8b550fd33
@ -776,8 +776,7 @@ function map_meta_cap( $cap, $user_id ) {
|
|||||||
if ( 'publish' == $post->post_status ) {
|
if ( 'publish' == $post->post_status ) {
|
||||||
$caps[] = 'delete_published_posts';
|
$caps[] = 'delete_published_posts';
|
||||||
} elseif ( 'trash' == $post->post_status ) {
|
} elseif ( 'trash' == $post->post_status ) {
|
||||||
$trash_meta = get_option('wp_trash_meta');
|
if ('publish' == get_post_meta($post->ID, '_wp_trash_meta_status', true) )
|
||||||
if (is_array($trash_meta) && isset($trash_meta['posts'][$post->ID]['status']) && $trash_meta['posts'][$post->ID]['status'] == 'publish')
|
|
||||||
$caps[] = 'delete_published_posts';
|
$caps[] = 'delete_published_posts';
|
||||||
} else {
|
} else {
|
||||||
// If the post is draft...
|
// If the post is draft...
|
||||||
@ -805,8 +804,7 @@ function map_meta_cap( $cap, $user_id ) {
|
|||||||
if ( $page->post_status == 'publish' ) {
|
if ( $page->post_status == 'publish' ) {
|
||||||
$caps[] = 'delete_published_pages';
|
$caps[] = 'delete_published_pages';
|
||||||
} elseif ( 'trash' == $page->post_status ) {
|
} elseif ( 'trash' == $page->post_status ) {
|
||||||
$trash_meta = get_option('wp_trash_meta');
|
if ('publish' == get_post_meta($page->ID, '_wp_trash_meta_status', true) )
|
||||||
if (is_array($trash_meta) && isset($trash_meta['posts'][$page->ID]['status']) && $trash_meta['posts'][$page->ID]['status'] == 'publish')
|
|
||||||
$caps[] = 'delete_published_pages';
|
$caps[] = 'delete_published_pages';
|
||||||
} else {
|
} else {
|
||||||
// If the page is draft...
|
// If the page is draft...
|
||||||
@ -840,8 +838,7 @@ function map_meta_cap( $cap, $user_id ) {
|
|||||||
if ( 'publish' == $post->post_status ) {
|
if ( 'publish' == $post->post_status ) {
|
||||||
$caps[] = 'edit_published_posts';
|
$caps[] = 'edit_published_posts';
|
||||||
} elseif ( 'trash' == $post->post_status ) {
|
} elseif ( 'trash' == $post->post_status ) {
|
||||||
$trash_meta = get_option('wp_trash_meta');
|
if ('publish' == get_post_meta($post->ID, '_wp_trash_meta_status', true) )
|
||||||
if ( is_array($trash_meta) && isset($trash_meta['posts'][$post->ID]['status']) && $trash_meta['posts'][$post->ID]['status'] == 'publish' )
|
|
||||||
$caps[] = 'edit_published_posts';
|
$caps[] = 'edit_published_posts';
|
||||||
} else {
|
} else {
|
||||||
// If the post is draft...
|
// If the post is draft...
|
||||||
@ -869,8 +866,7 @@ function map_meta_cap( $cap, $user_id ) {
|
|||||||
if ( 'publish' == $page->post_status ) {
|
if ( 'publish' == $page->post_status ) {
|
||||||
$caps[] = 'edit_published_pages';
|
$caps[] = 'edit_published_pages';
|
||||||
} elseif ( 'trash' == $page->post_status ) {
|
} elseif ( 'trash' == $page->post_status ) {
|
||||||
$trash_meta = get_option('wp_trash_meta');
|
if ('publish' == get_post_meta($page->ID, '_wp_trash_meta_status', true) )
|
||||||
if ( is_array($trash_meta) && isset($trash_meta['posts'][$page->ID]['status']) && $trash_meta['posts'][$page->ID]['status'] == 'publish' )
|
|
||||||
$caps[] = 'edit_published_pages';
|
$caps[] = 'edit_published_pages';
|
||||||
} else {
|
} else {
|
||||||
// If the page is draft...
|
// If the page is draft...
|
||||||
|
@ -3346,24 +3346,29 @@ function _cleanup_header_comment($str) {
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function wp_scheduled_delete() {
|
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');
|
$trash_meta = get_option('wp_trash_meta');
|
||||||
if ( !is_array($trash_meta) )
|
if ( !is_array($trash_meta) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
$delete_timestamp = time() - (60*60*24*EMPTY_TRASH_DAYS);
|
|
||||||
|
|
||||||
foreach ( (array) $trash_meta['comments'] as $id => $meta ) {
|
foreach ( (array) $trash_meta['comments'] as $id => $meta ) {
|
||||||
if ( $meta['time'] < $delete_timestamp ) {
|
if ( $meta['time'] < $delete_timestamp ) {
|
||||||
wp_delete_comment($id);
|
wp_delete_comment($id);
|
||||||
unset($trash_meta['comments'][$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);
|
update_option('wp_trash_meta', $trash_meta);
|
||||||
}
|
}
|
||||||
|
?>
|
@ -1149,11 +1149,8 @@ function wp_delete_post($postid = 0) {
|
|||||||
|
|
||||||
do_action('delete_post', $postid);
|
do_action('delete_post', $postid);
|
||||||
|
|
||||||
$trash_meta = get_option('wp_trash_meta');
|
delete_post_meta($postid,'_wp_trash_meta_status');
|
||||||
if ( is_array($trash_meta) && isset($trash_meta['posts'][$postid]) ) {
|
delete_post_meta($postid,'_wp_trash_meta_time');
|
||||||
unset($trash_meta['posts'][$postid]);
|
|
||||||
update_option('wp_trash_meta', $trash_meta);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @todo delete for pluggable post taxonomies too */
|
/** @todo delete for pluggable post taxonomies too */
|
||||||
wp_delete_object_term_relationships($postid, array('category', 'post_tag'));
|
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.
|
* @param int $postid Post ID.
|
||||||
* @return mixed False on failure
|
* @return mixed False on failure
|
||||||
*/
|
*/
|
||||||
function wp_trash_post($postid = 0) {
|
function wp_trash_post($post_id = 0) {
|
||||||
if ( EMPTY_TRASH_DAYS == 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;
|
return $post;
|
||||||
|
|
||||||
do_action('trash_post', $postid);
|
do_action('trash_post', $post_id);
|
||||||
|
|
||||||
$trash_meta = get_option('wp_trash_meta');
|
add_post_meta($post_id,'_wp_trash_meta_status', $post['post_status']);
|
||||||
if ( !is_array($trash_meta) )
|
add_post_meta($post_id,'_wp_trash_meta_time', time());
|
||||||
$trash_meta = array();
|
|
||||||
$trash_meta['posts'][$postid]['status'] = $post['post_status'];
|
|
||||||
$trash_meta['posts'][$postid]['time'] = time();
|
|
||||||
update_option('wp_trash_meta', $trash_meta);
|
|
||||||
|
|
||||||
$post['post_status'] = 'trash';
|
$post['post_status'] = 'trash';
|
||||||
wp_insert_post($post);
|
wp_insert_post($post);
|
||||||
|
|
||||||
do_action('trashed_post', $postid);
|
do_action('trashed_post', $post_id);
|
||||||
|
|
||||||
return $post;
|
return $post;
|
||||||
}
|
}
|
||||||
@ -1258,24 +1251,20 @@ function wp_trash_post($postid = 0) {
|
|||||||
* @param int $postid Post ID.
|
* @param int $postid Post ID.
|
||||||
* @return mixed False on failure
|
* @return mixed False on failure
|
||||||
*/
|
*/
|
||||||
function wp_untrash_post($postid = 0) {
|
function wp_untrash_post($post_id = 0) {
|
||||||
if ( !$post = wp_get_single_post($postid, ARRAY_A) )
|
if ( !$post = wp_get_single_post($post_id, ARRAY_A) )
|
||||||
return $post;
|
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');
|
delete_post_meta($post_id,'_wp_trash_meta_status');
|
||||||
if ( is_array($trash_meta) && isset($trash_meta['posts'][$postid]) ) {
|
delete_post_meta($post_id,'_wp_trash_meta_time');
|
||||||
$post['post_status'] = $trash_meta['posts'][$postid]['status'];
|
|
||||||
unset($trash_meta['posts'][$postid]);
|
|
||||||
update_option('wp_trash_meta', $trash_meta);
|
|
||||||
}
|
|
||||||
|
|
||||||
wp_insert_post($post);
|
wp_insert_post($post);
|
||||||
|
|
||||||
do_action('untrashed_post', $postid);
|
do_action('untrashed_post', $post_id);
|
||||||
|
|
||||||
return $post;
|
return $post;
|
||||||
}
|
}
|
||||||
@ -2666,11 +2655,9 @@ function wp_delete_attachment($postid) {
|
|||||||
if ( 'trash' != $post->post_status )
|
if ( 'trash' != $post->post_status )
|
||||||
return wp_trash_post($postid);
|
return wp_trash_post($postid);
|
||||||
|
|
||||||
$trash_meta = get_option('wp_trash_meta');
|
delete_post_meta($post_id,'_wp_trash_meta_status');
|
||||||
if ( is_array($trash_meta) && isset($trash_meta['posts'][$postid]) ) {
|
delete_post_meta($post_id,'_wp_trash_meta_time');
|
||||||
unset($trash_meta['posts'][$postid]);
|
|
||||||
update_option('wp_trash_meta', $trash_meta);
|
|
||||||
}
|
|
||||||
|
|
||||||
$meta = wp_get_attachment_metadata( $postid );
|
$meta = wp_get_attachment_metadata( $postid );
|
||||||
$file = get_attached_file( $postid );
|
$file = get_attached_file( $postid );
|
||||||
|
Loading…
Reference in New Issue
Block a user