Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Returns all users with a specific level.
- *
- * @param string $level_name Paid Membershp Pro level name.
- *
- * @return array
- */
- function mpp_custom_get_pmpro_users_with_level_name( string $level_name ): array {
- global $wpdb;
- // make sure pmpro is enabled.
- if ( ! function_exists( 'pmpro_getAllLevels' ) ) {
- return array();
- }
- $user_ids = $wpdb->get_col(
- $wpdb->prepare(
- "SELECT mu.user_id FROM {$wpdb->pmpro_membership_levels} AS l
- JOIN {$wpdb->pmpro_memberships_users} AS mu ON (l.id = mu.membership_id)
- WHERE mu.status = 'active' AND l.name=%s", $level_name
- ) );
- return array_map( 'absint', $user_ids );
- }
- /**
- * Exclude users with the specific level from directory.
- */
- add_filter( 'mpp_main_gallery_query_args', function ( $args ) {
- // not the directory page.
- if ( ! empty( $args['component'] ) ) {
- return $args;
- }
- // CHANGE this line.
- $level_name = "Basic";
- $args['exclude_users'] = mpp_custom_get_pmpro_users_with_level_name( $level_name );
- return $args;
- } );
Advertisement
Add Comment
Please, Sign In to add comment