Advertisement
bedas

wpv_query_filter

Aug 31st, 2015
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.92 KB | None | 0 0
  1. add_filter( 'wpv_filter_query_post_process', 'prefix_modify_empty_query', 10, 3 );
  2. function prefix_modify_empty_query( $query, $view_settings, $view_id )
  3. {
  4.     if (!empty($query->posts))
  5.     {
  6.         $valid_posts = array();
  7.         foreach ($query->posts as $post)
  8.         {
  9.             //check the author cap here
  10.             $cap_is_good = new_pp_speaker_cap_yes($post);
  11.  
  12.             if ($cap_id_good)
  13.                 $valid_posts[] = $post;
  14.         }
  15.  
  16.         if (!empty($valid_posts))
  17.         {
  18.             $query->posts = $valid_posts;
  19.             $query->post_count = $count($valid_posts);
  20.         }
  21.     }
  22.     return $query;
  23. }
  24.  
  25. function new_pp_speaker_cap_yes($post)
  26. {
  27.     require_once( ABSPATH . 'wp-includes/pluggable.php' );
  28.     $groups_user = new Groups_User(get_the_author_meta('ID', $post->post_author));
  29.     $author_can_speaker = $groups_user->can( 'pp_speaker' );
  30.  
  31.     if ( empty($author_can_speaker) ) {
  32.         $author_can_speaker = 0;
  33.     }
  34.     return $author_can_speaker ;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement