.....
global $untrashed_posts;
$untrashed_posts = array();
function wpse_handle_untrash($new_status, $old_status, $post)
{
global $untrashed_posts;
// if the post was in the trash, but now is not
if( $old_status == 'trash' )
{
// if you want, you can do something only for a certain post type
if($post->post_type == 'my_post_type')
{
array_push($untrashed_posts, $post->ID );
}
}
}
add_action('transition_post_status', 'wpse_handle_untrash', 10, 3 );
.....
function my_redirect_post_location( $location, $post_id )
{
global $untrashed_posts;
if ( ... )
{
$location = add_query_arg(....);
}
if ( $untrashed_posts ) // If i have untrashed posts.
{
$location = add_query_arg( 'ids', $untrashed_posts[0], $location );
}
return $location;
}
add_filter( 'redirect_post_location', 'my_redirect_post_location' , 10, 2 );
........
// Create me own admin notice for fail save post!
function my_admin_notices( $post_id )
{
global $untrashed_posts;
switch ( $_GET['message'] )
{
case 1:
....
}
if ( isset( $_GET['trashed'] ) ) // If he sends my posts in the trash.
{
if ( isset( $_GET['ids'] ) )
{
my_print_notice( 'Trashed posts is : ', $_GET['ids'] );
}
}
if ( isset( $_GET['untrashed'] ) ) // If he restore my posts
{
if ( isset( $_GET['ids'] ) )
{
my_print_notice( 'Untrashed posts is : ', $_GET['ids'] );
}
}
}
add_action( 'admin_notices', 'my_admin_notices' );
Comments