# Only Named Administrators Can Manage Plugins, Themes and Users

> Limits installing, activating, editing and deleting plugins and themes, updating WordPress and managing users to the administrator accounts you list by user ID, even if other accounts have the administrator role.

- Type: PHP
- Runs: Run everywhere
- Category: [Security](https://wpide.com/library/category/security/)
- Tags: capabilities, administrators, hardening
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/sec-trusted-admins-only-manage-code/

## Code

```php
// User IDs allowed to manage code and users.
$wpide_trusted_admins = array( 1 );

add_filter( 'map_meta_cap', function ( $caps, $cap, $user_id ) use ( $wpide_trusted_admins ) {
    static $guarded = array( 'install_plugins', 'activate_plugins', 'deactivate_plugins', 'delete_plugins', 'update_plugins', 'edit_plugins', 'install_themes', 'switch_themes', 'delete_themes', 'update_themes', 'edit_themes', 'update_core', 'create_users', 'promote_users', 'delete_users', 'edit_users', 'remove_users' );

    if ( ! in_array( $cap, $guarded, true ) || in_array( (int) $user_id, array_map( 'intval', $wpide_trusted_admins ), true ) ) {
        return $caps;
    }

    static $any_trusted = null;
    if ( null === $any_trusted ) {
        $any_trusted = false;
        foreach ( $wpide_trusted_admins as $id ) {
            $trusted = get_userdata( (int) $id );
            if ( $trusted && in_array( 'administrator', (array) $trusted->roles, true ) ) {
                $any_trusted = true;
                break;
            }
        }
    }

    return $any_trusted ? array( 'do_not_allow' ) : $caps;
}, 20, 3 );
```

## Notes

Put your own user ID in the list first (find it in the address bar when editing your profile); if none of the listed IDs is an administrator, the snippet does nothing so you cannot lock yourself out.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Only Named Administrators Can Manage Plugins, Themes and Users" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
