buddydev

Untitled

Sep 23rd, 2025
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.06 KB | None | 0 0
  1.  
  2. /**
  3.  * Returns all users with a specific level.
  4.  *
  5.  * @param string $level_name Paid Membershp Pro level name.
  6.  *
  7.  * @return array
  8.  */
  9. function mpp_custom_get_pmpro_users_with_level_name( string $level_name ): array {
  10.     global $wpdb;
  11.  
  12.     // make sure pmpro is enabled.
  13.     if ( ! function_exists( 'pmpro_getAllLevels' ) ) {
  14.         return array();
  15.     }
  16.  
  17.     $user_ids = $wpdb->get_col(
  18.         $wpdb->prepare(
  19.             "SELECT mu.user_id FROM {$wpdb->pmpro_membership_levels} AS l
  20.             JOIN {$wpdb->pmpro_memberships_users} AS mu ON (l.id = mu.membership_id)
  21.                                     WHERE mu.status = 'active' AND l.name=%s", $level_name
  22.         ) );
  23.  
  24.     return array_map( 'absint', $user_ids );
  25. }
  26.  
  27. /**
  28.  * Exclude users with the specific level from directory.
  29.  */
  30. add_filter( 'mpp_main_gallery_query_args', function ( $args ) {
  31.  
  32.     // not the directory page.
  33.     if ( ! empty( $args['component'] ) ) {
  34.         return $args;
  35.     }
  36.  
  37.     // CHANGE this line.
  38.     $level_name            = "Basic";
  39.     $args['exclude_users'] = mpp_custom_get_pmpro_users_with_level_name( $level_name );
  40.  
  41.     return $args;
  42. } );
Advertisement
Add Comment
Please, Sign In to add comment