Tag Info

Hot answers tagged

9

You can use wp_delete_post. To get all posts with the "trash" status: $trash = get_posts('post_status=trash&numberposts=-1'); Then: foreach($trash as $post) wp_delete_post($post->ID, $bypass_trash = true);


6

You can do the following: Set EMPTY_TRASH_DAYS to a very high number. E.g.: define( 'EMPTY_TRASH_DAYS', 1000000 ); Or remove the wp_schedule_delete action: function my_remove_schedule_delete() { remove_action( 'wp_scheduled_delete', 'wp_scheduled_delete' ); } add_action( 'init', 'my_remove_schedule_delete' );


5

There are multiple actions. Listed in order of appearance with their parameters: untrash_post - (int) $post_id // before restoring transition_post_status - (string) $new_status, 'trash', (object) $post trash_to_{$new_status} - (object) $post // useful to address a special trash to status action untrash_post_comments - (int) $post_id // before associated ...


3

From your comment above, I believe you're running into issues with the _wpnonce piece of the puzzle. Looking at the code in /wp-admin/post.php, it appears that the untrash instruction is checking for a valid WordPress nonce, and not getting one. This might do the trick: <?php function wpse_95348_undelete_post( $post_id ) { // no post? if( ...


3

Use wp_trash_post instead, and keep in mind {post_status}_{post_type} so originally it should have been trash_empresa not trash_post, try wp_trash_empresa too


3

In vanilla WordPress the only difference is that trashed comments get deleted automatically after (customizable) time span. Adding plugins to the picture - it might make difference to what/how specific plugin learns from incoming spam.


3

Just use get_delete_post_link( $post_ID ) - it'll return the absolute URL with nonce and all! Just to be clear, this will get the link to trash posts (if trash supported). If you want to skip trash & get the perma-delete link, pass a second argument of true*. http://codex.wordpress.org/Function_Reference/get_delete_post_link Update: Having checked the ...


2

When deleting a user, WordPress displays a warning that unless you attribute the user's posts to a new user, it's posts will be deleted and you cannot undo those deletions. That means the only way to restore the posts and media is to restore a backup of the WordPress instance or database which you hopefully have.


2

With the filter we prevent the Trash link from being printed. And with the action, redirect back to the post listing page if the user tries to access the URL directly (/wp-admin/edit.php?post_status=trash&post_type=post). add_filter( 'views_edit-post', 'wpse_74488_remove_trash_link' ); add_action( 'admin_head-edit.php', 'wpse_74488_block_trash_access' ...


2

Well, this is partly true and partly false. When you trash a post, everything that is tied to it is also trashed. This means, if you untrash the post, the comments etc. are untrashed as well. However, comments and other stuff is not handled as if they were trashed directly (i.e., on the Comments page in your WordPress Admin). If you directly trash a ...


2

Unless there's a very good (usually performance, or, of course, inability of core functions to do what you need) reason to use raw SQL requests to fetch posts and other data in WordPress, you shouldn't construct your own SQL queries. Instead, you can use WP_Query. In your case, you could fetch the posts like this: $query = new WP_Query( array( ...


1

You're using a raw SQL query to do a post query, this is bad, because: There are already APIs that do this It is no longer inheriting the default parameters It doesn't go through the caching system so it can be slower Intead, use WP_Query. The reason you're getting trashed posts is because you're not specifying what post status you want. By default ...


1

The Core "trash post" links in the "Quick Edit" section on edit.php and in the "advanced" form in the "Publish" meta box work over GET not POST. Unless you have altered the form(s) somehow, there is no POST data. All you have is the post ID. To save data when a post is deleted, you won't be able to use the default "delete/trash" functionality. You will ...


1

Where did you see trash_comment? It is no original WordPress core function, though. Maybe some part of a plugin/theme? So in short: use wp_trash_comment - if you must. There is, however, an action called trash_comment. Maybe this is what got you confused...?


1

You could build an action for delete_comment, where you loop through the childcomments and delete them. I use two different functions here, one that trashes the childcomments (hooked into trash_comment), and one that deletes them directly. Please make sure which funtion you use, or if you want to use both. The safe version would be to move the ...


1

Hook into load-{screen_id} and check if the $_GET['trashed'] variable is 1 or above. add_action('load-edit.php','wpse_trashed_redirect'); function wpse_trashed_redirect(){ $screen = get_current_screen(); if('edit-page' == $screen->id){ if( isset($_GET['trashed']) && intval($_GET['trashed']) >0){ $redirect = ...


1

You could use get_post_status(): function is_trash( $post_id = 0 ) { 0 == $post_id and $post_id = get_the_ID(); return 'trash' === get_post_status( $post_id ); } Side note: To get a list of all registered post status objects use get_post_stati() – yes, that's wrong.


1

There are two hooks you should be considering-- wp_trash_post and trashed_post. Based on your statement that you want this to work "when a post is placed into the trash" I'd suggest the latter is the better hook, since it runs after the post is successfully placed in the trash. I hate to suggest this as an answer but I do think it explains why your function ...


1

This is done filtering the *_row_actions. For the Comments screen (/wp-admin/edit-comments.php) this is the hook: add_filter( 'comment_row_actions', 'comments_row_wpse_92313', 15, 2 ); function comments_row_wpse_92313( $actions, $comment ) { if( !current_user_can( 'delete_plugins' ) ) unset( $actions['quickedit'], $actions['edit'], ...


1

For any future readers it seems the hook has now changed from 'trash_post' to 'wp_trash_post' trac ticket explaining the name change



Only top voted, non community-wiki answers of a minimum length are eligible