# Add a Site Manager Role (No Database Changes)

> Adds a "Site Manager" role with everything an editor can do plus managing users and menus, defined in code so nothing is written to the database.

- Type: PHP
- Runs: Run everywhere
- Category: [Users](https://wpide.com/library/category/users/)
- Tags: users, roles, client
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/site-manager-role/

## Code

```php
$wpide_add_site_manager = function ( $wp_roles ) {
    if ( isset( $wp_roles->roles['site_manager'] ) ) {
        return;
    }

    $editor = $wp_roles->get_role( 'editor' );
    $caps   = array_merge(
        $editor ? $editor->capabilities : array( 'read' => true ),
        array(
            'list_users'         => true,
            'create_users'       => true,
            'edit_users'         => true,
            'delete_users'       => true,
            'promote_users'      => true,
            'edit_theme_options' => true,
        )
    );

    $wp_roles->roles['site_manager']        = array( 'name' => 'Site Manager', 'capabilities' => $caps );
    $wp_roles->role_objects['site_manager'] = new WP_Role( 'site_manager', $caps );
    $wp_roles->role_names['site_manager']   = 'Site Manager';
};

add_action( 'wp_roles_init', $wpide_add_site_manager );

if ( did_action( 'wp_roles_init' ) ) {
    $wpide_add_site_manager( wp_roles() );
}

// Site managers cannot create administrators or change administrator accounts.
add_filter( 'editable_roles', function ( $roles ) {
    if ( ! current_user_can( 'manage_options' ) ) {
        unset( $roles['administrator'] );
    }

    return $roles;
} );

add_filter( 'map_meta_cap', function ( $caps, $cap, $user_id, $args ) {
    if ( in_array( $cap, array( 'edit_user', 'delete_user', 'remove_user', 'promote_user' ), true ) && ! empty( $args[0] ) && (int) $args[0] !== (int) $user_id && user_can( (int) $args[0], 'manage_options' ) && ! user_can( $user_id, 'manage_options' ) ) {
        $caps[] = 'do_not_allow';
    }

    return $caps;
}, 10, 4 );
```

## Notes

Users given this role lose their permissions while the snippet is inactive; reassign them before removing it.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Add a Site Manager Role (No Database Changes)" 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/
