How to add a column to the Trash page?

You can check the value of the post_status query variable and make sure that it’s set to trash: function wpse239286_trash_column( $columns ) { // Bail if we’re not looking at trash. $status = get_query_var( ‘post_status’ ); if ( ‘trash’ !== $status ) { return $columns; } return array_merge( $columns, array( ‘trash_column’ => __( ‘Trash Column’, … Read more

Can I differentiate between “Delete Post Permanently” and “Empty Trash” and do something for each accordingly?

So as leymannx pointed out in his comment, the “delete_post” hook actually handles both scenarios I was looking for, as it seems to know to run a “for each post deleted, do x” when “Empty Trash” is clicked and will also “do x” when “Delete Post Permanently” is clicked! My final code ended up looking … Read more

Dynamically create/remove terms in taxonomy when custom post type is published/trashed

Ok, I think I’ve figured out a viable solution. Kinda disappointed that there’s no way I’ve found thus far to hook directly into trash_{custom_post_type} like I was able to on the publish_{custom_post_type} hook. Here’s a solution for anyone else struggling with this issue. If anyone has any better suggestions, please feel free to share! /** … Read more

Add frontend “Restore” link

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( … Read more

Exclude trash from save_post

save_post gets fired, once the post is saved. We get the current post object as the second parameter. So we can check, if the current post status is trash: <?php add_action( ‘save_post’, function( $post_ID, $post, $update ) { if ( ‘trash’ === $post->post_status ) { return; } /** do your stuff **/ }, 10, 3 … Read more

Is there an action that is called when a post is restored from the trash?

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 comments are untrashed untrashed_post_comments – (int) $post_id // … Read more

Undelete post (untrash)?

There is not wp_undelete_post but you have other choices: wp_untrash_post(): when post is trashed, the previous status is stored in _wp_trash_meta_status meta field. wp_untrash_post() restore trashed posts to previous status whatever it was; for example, private, inherit, publish. I’ve not tested it but it should work with a custom post status as well. wp_publish_post(): if … Read more

How to change redirect after moving a page to trash?

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 = add_query_arg(array(‘page’=>’custom_page_oder’, ‘trashed’ => false, ‘ids’ => false )); wp_redirect($redirect); exit(); } } } This works – and I’m not aware of a better way of doing … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)