You can use fep_filter_rest_users_args filter hook to change where you want to search (for some examples https://www.shamimsplugins.com/support/search/fep_filter_rest_users_args/). Also you can use fep_filter_user_name to change what name you want to show.
This plugin is highly customizable. You can even use fep_filter_rest_users_response to query and response as you like. This will bypass plugin’s query fully.
You can add 2 approaches
Suppose current user id is 2 (you can get that using get_current_user_id()) and connected users of this user in 2,3 and 4 (get that from your member plugin or using query)
Approach 1. You show only connected users in auto suggestion and in directory.
add_filter( 'fep_filter_rest_users_args', function( $args, $for, $q, $x ) {
$args['meta_query'] = [
'include' => [2,3,4], //Get ids from member plugin
];
return $args;
}, 10, 4 );
Approach 2. restrict user from sending message to only connected users
add_filter( 'fep_current_user_can', function( $can, $cap, $id ){
if ( 'send_new_message_to' != $cap || ! $can ) {
return $can;
}
//Get ids from member plugin
if( in_array($id, [2,3,4] ) ){
return true;
}
return false;
}, 10, 3);
As i understand you want only doctor’s self patients will be shown to that doctor. Eg. your doctors roles are A, B and C. And patients of doctor A’s are patients_of_A. So your filter will look like
add_filter( 'fep_filter_rest_users_args', function( $args ){
if ( in_array( 'A', wp_get_current_user()->roles ) ) {
$args['role'] = 'patients_of_A';
}
return $args;
});
As i understand you do not need to filter messages.
Do you want such a way that an Editor role user only see other Editor role users? you can use fep_directory_arguments and fep_filter_rest_users_args
You can add following code in your theme’s (child theme’s if you are using) functions.php
add_filter( 'fep_filter_rest_users_args', function( $args ){
$args['date_query'][] = [
'after' => '2024-11-01 00:00:00',
];
return $args;
});
Please try following code
add_filter( 'fep_filter_rest_users_args', function( $args ){
$args['search_columns'][] = 'user_email';
return $args;
});
You need to change $args parameters only. Not full get_users function.
Eg.
add_filter( 'fep_filter_rest_users_args', function( $args ){
$args['search'] = 1449,
return $args;
});
Hi,
I want to populate custom users in To field , for this I am using this fep_filter_rest_users_args but not working
The code using in function.php is below :
add_action( ‘fep_filter_rest_users_args’, ‘populate_pm_users’ );
function populate_pm_users($args){
global $wpdb;
$args = get_users( array(
‘search’ => 1419,
‘search_columns’ => array(‘ID’),
) );
return $args;
}
Please suggest what arguments are wrong .
Thanks
You can use fep_filter_rest_users_args hook.
As $args is supplied to get_users function you can modify any parameters there. you can get supported parameters in https://developer.wordpress.org/reference/classes/wp_user_query/prepare_query/
You can add following code in your theme’s (child theme’s if you are using) functions.php. It will hide those users from autosuggestion who unchecked “Allow others to send me messages?” in their settings.
add_filter( 'fep_filter_rest_users_args', function( $args, $for, $q, $x ) {
$args['meta_query'] = [
'relation' => 'OR',
[
'key' => 'FEP_user_options',
'value' => 's:14:"allow_messages";s:1:"1";',
'compare' => 'LIKE',
],
[
'key' => 'FEP_user_options',
'compare' => 'NOT EXISTS',
]
];
return $args;
}, 10, 4 );
You can add following code in your theme’s (child theme’s if you are using) functions.php
add_filter( 'fep_filter_rest_users_args', function( $args ){
if ( in_array( 'mentor', wp_get_current_user()->roles ) ) {
$args['meta_query'][] = [
'key' => 'mentor',
'value' => get_current_user_id(),
];
}
return $args;
});
(untested)
Change mentor role and meta key in the code as you require.
Let me know.