Advertisement
Tassos

after untrash problem

Jul 11th, 2017
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.71 KB | None | 0 0
  1. .....
  2.  
  3. global $untrashed_posts;
  4. $untrashed_posts = array();
  5.  
  6. function wpse_handle_untrash($new_status, $old_status, $post)
  7. {
  8.     global $untrashed_posts;
  9.    
  10.     // if the post was in the trash, but now is not
  11.     if( $old_status == 'trash' )
  12.     {
  13.         // if you want, you can do something only for a certain post type
  14.         if($post->post_type == 'my_post_type')
  15.         {
  16.             array_push($untrashed_posts, $post->ID );
  17.         }
  18.     }
  19. }
  20.  
  21. add_action('transition_post_status', 'wpse_handle_untrash', 10, 3 );
  22.  
  23. .....
  24.  
  25.  
  26. function my_redirect_post_location( $location, $post_id )
  27. {
  28.     global $untrashed_posts;
  29.  
  30.     if ( ... )
  31.     {
  32.         $location = add_query_arg(....);
  33.     }
  34.    
  35.     if ( $untrashed_posts ) // If i have untrashed posts.
  36.     {
  37.         $location = add_query_arg( 'ids', $untrashed_posts[0], $location );
  38.     }
  39.    
  40.     return $location;
  41. }
  42.  
  43. add_filter( 'redirect_post_location', 'my_redirect_post_location' , 10, 2 );
  44.  
  45. ........
  46.  
  47. // Create me own admin notice for fail save post!
  48. function my_admin_notices( $post_id )
  49. {
  50.     global $untrashed_posts;
  51.  
  52.     switch ( $_GET['message'] )
  53.     {
  54.         case 1:
  55.         ....
  56.     }
  57.  
  58.     if ( isset( $_GET['trashed'] ) ) // If he sends my posts in the trash.
  59.     {
  60.         if ( isset( $_GET['ids'] ) )
  61.         {
  62.            my_print_notice( 'Trashed posts is : ', $_GET['ids'] );
  63.         }
  64.     }
  65.    
  66.     if ( isset( $_GET['untrashed'] ) ) // If he restore my posts
  67.     {
  68.         if ( isset( $_GET['ids'] ) )
  69.         {
  70.             my_print_notice( 'Untrashed posts is : ', $_GET['ids'] );
  71.         }
  72.     }
  73.        
  74. }
  75.  
  76. add_action( 'admin_notices', 'my_admin_notices' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement