Prevent members from being able to see themselves in the member directory

Welcome mkmcst community Forum Web programming WordPress Ultimate Member Code Examples Prevent members from being able to see themselves in the member directory

Viewing 0 reply threads
  • Author
    Posts
    • #2630
      michael mc
      Keymaster
      @michael
      <?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 );
      view raw
Viewing 0 reply threads
  • You must be logged in to reply to this topic.