Advertisement
verygoodplugins

Untitled

Aug 2nd, 2023
1,073
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.08 KB | None | 0 0
  1. function custom_filter_wpf_user_can_access($posts, $query) {
  2.     // Check if we are on the main query and the user is logged in
  3.     if (is_main_query() && is_user_logged_in()) {
  4.         // Array to hold accessible and inaccessible posts
  5.         $accessible_posts = array();
  6.         $inaccessible_posts = array();
  7.  
  8.         // Loop through each post and check if the user can access it
  9.         foreach ($posts as $post) {
  10.             // Check if the user can access the post
  11.             if (wpf_user_can_access($post->ID)) {
  12.                 // If accessible, add it to the accessible_posts array
  13.                 $accessible_posts[] = $post;
  14.             } else {
  15.                 // If inaccessible, add it to the inaccessible_posts array
  16.                 $inaccessible_posts[] = $post;
  17.             }
  18.         }
  19.  
  20.         // Concatenate the accessible_posts and inaccessible_posts arrays to reorder the $posts array
  21.         $posts = array_merge($accessible_posts, $inaccessible_posts);
  22.     }
  23.  
  24.     return $posts;
  25. }
  26. add_filter('the_posts', 'custom_filter_wpf_user_can_access', 10, 2);
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement