Guest User

Untitled

a guest
Sep 22nd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. function my_pre_get_posts($query) {
  2.  
  3. screen = get_current_screen();
  4.  
  5. current_user = wp_get_current_user();
  6.  
  7. $restricted_user_id = 10;
  8. $allowed_post_id = 1234;
  9.  
  10. $current_post_id = isset($_GET['post'])?(int)$_GET['post']:false;
  11.  
  12. if($current_user->ID !== $restricted_user_id) {
  13. return;
  14. }
  15. if(! $current_post_id) {
  16. return;
  17. }
  18. if($screen->id =='page'&& $current_post_id !== $allowed_post_id) {
  19. wp_redirect(admin_url());
  20. exit;
  21. }
  22.  
  23.  
  24. $restrictions_map = [10=>[123], 12311=>[152,186]];
  25.  
  26. if( array_key_exists($current_user->ID, $restrictions_map)) {
  27. $allowed_posts = $restrictions_map[$current_user->ID];
  28. if($screen->id == 'page' && ! in_array($current_user->ID, $allowed_posts)) {
  29. if(array_key_exists($current_user->ID, $restrictions_map)) {
  30. $allowed_posts = $restrictions_map[$current_user->ID];
  31. if($screen->id =='page' && ! in_array($current_user->ID, $allowed_posts)) {
  32. wp_redirect(admin_url());
  33. exit;
  34. }
  35. }
  36. }
  37.  
  38. }
  39.  
  40. add_action('pre_get_posts','my_pre_get_posts');
Add Comment
Please, Sign In to add comment