1. Customize
  2. Transfers
  3. Exclude recipients by role

Exclude recipients by role

Note: Now, Transfers add-on includes a setting that lets you setup the allowed roles.
You can find more information in the add-on documentation.

The following snippet shows how to exclude recipients by role on any transfer form recipients autocomplete.

For more information about roles and capabilities, check the Roles and Capabilities on WordPress official docs, specially this section.

function my_prefix_filter_transfers_exclude_recipients_by_role( $query_vars, $user_id, $search ) {

    global $wpdb;

    $roles = array( 'administrator', 'editor' ); // Set the role(s) you want to exclude users

    $cap_meta_key = $wpdb->get_blog_prefix() . 'capabilities';

    $query_vars['join'][] = "LEFT JOIN {$wpdb->usermeta} AS umrole ON ( umrole.user_id = u.ID AND umrole.meta_key = '$cap_meta_key' )";

    foreach( $roles as $role ) {
        $query_vars['where'][] = "umrole.meta_value NOT LIKE '%\"{$role}\"%'";

    return $query_vars;

add_filter( 'gamipress_transfers_users_autocomplete_pre_query_vars', 'my_prefix_filter_transfers_exclude_recipients_by_role', 10, 3 );

How can we help?