The autocomplete_users_for_site_admins WordPress PHP filter allows you to control whether non-super admin users in a Multisite environment have access to the user auto-complete feature.
Usage
add_filter( 'autocomplete_users_for_site_admins', 'your_custom_function' ); function your_custom_function( $enable ) { // your custom code here return $enable; }
Parameters
$enable
(bool): Whether to enable auto-complete for non-super admins. Default isfalse
.
More information
See WordPress Developer Resources: autocomplete_users_for_site_admins
Examples
Enable auto-complete for all site admins
Enable the auto-complete feature for all site admins, not just super admins.
add_filter( 'autocomplete_users_for_site_admins', 'enable_autocomplete_for_site_admins' ); function enable_autocomplete_for_site_admins( $enable ) { return true; }
Enable auto-complete based on user role
Enable auto-complete for users with the ‘editor’ role.
add_filter( 'autocomplete_users_for_site_admins', 'enable_autocomplete_for_editors' ); function enable_autocomplete_for_editors( $enable ) { if ( current_user_can( 'editor' ) ) { return true; } return $enable; }
Enable auto-complete based on user ID
Enable auto-complete for a specific user by their ID.
add_filter( 'autocomplete_users_for_site_admins', 'enable_autocomplete_for_specific_user' ); function enable_autocomplete_for_specific_user( $enable ) { $user_id = get_current_user_id(); if ( $user_id == 123 ) { return true; } return $enable; }
Disable auto-complete for all users
Disable the auto-complete feature for all users, including super admins.
add_filter( 'autocomplete_users_for_site_admins', 'disable_autocomplete_for_all_users' ); function disable_autocomplete_for_all_users( $enable ) { return false; }
Enable auto-complete based on a custom capability
Enable auto-complete for users with a custom capability ‘manage_custom_posts’.
add_filter( 'autocomplete_users_for_site_admins', 'enable_autocomplete_for_custom_capability' ); function enable_autocomplete_for_custom_capability( $enable ) { if ( current_user_can( 'manage_custom_posts' ) ) { return true; } return $enable; }