Home / Admin / Unrestricted Admin Access
Duplicate Snippet

Embed Snippet on Your Site

Unrestricted Admin Access

When a site is managed by multiple admins, limit unnecessary exposure of critical responsibilities.

Code Preview
php
<?php
// Unrestricted Admin Access / Kiri Vadivelu / 2026
add_action( 'admin_init', 'restrict_admin_menu' );
function restrict_admin_menu() {
    
	// 1. Define the array of unrestricted users (by email)
    $unrestricted_users = array( '[email protected]', '[email protected]' );
    // 2. Get the current user's email
    $current_user = wp_get_current_user();
    $current_email = $current_user->user_email;
    // 3. Check if the current user is NOT in the whitelist
    if ( ! in_array( $current_email, $unrestricted_users ) ) {
        
        // 4. Remove menus for everyone else
        remove_menu_page( 'plugins.php' );        // Plugins
        remove_menu_page( 'themes.php' );         // Appearance
        remove_menu_page( 'users.php' );          // Users
        remove_menu_page( 'tools.php' );          // Tools
        remove_menu_page( 'options-general.php' ); // Settings
    }
}   

Comments

Add a Comment