Skip to content

Instantly share code, notes, and snippets.

@yuriinalivaiko
Last active July 10, 2022 11:08
Show Gist options
  • Save yuriinalivaiko/4140df34bf283fbbefed80dbcf5a65a5 to your computer and use it in GitHub Desktop.
Save yuriinalivaiko/4140df34bf283fbbefed80dbcf5a65a5 to your computer and use it in GitHub Desktop.
This code snippet prevents members from being able to see themselves in the member directory.
<?php
/**
* Prevent members from being able to see themselves in the member directory.
* Add this code to the file functions.php in the active theme directory.
*/
function um_pre_users_query_notme( $directory ) {
if ( is_user_logged_in() ) {
$directory->where_clauses[] = 'u.ID != ' . get_current_user_id();
}
}
add_action( 'um_pre_users_query', 'um_pre_users_query_notme', 20 );
function um_prepare_user_query_args_notme( $query_args ) {
if ( is_user_logged_in() ) {
$query_args['exclude'] = get_current_user_id();
}
return $query_args;
}
add_filter( 'um_prepare_user_query_args', 'um_prepare_user_query_args_notme', 20 );
@yuriinalivaiko
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment