Solving WordPress Admin Permission Issues with WP-CLI
This article provides a guide to resolve WordPress admin permission issues, particularly when the Dashboard, Themes, or Plugins menus are inaccessible in wp-admin despite an Administrator role. It includes WP-CLI commands and steps to troubleshoot and fix issues, along with common WP-CLI commands for repetitive tasks.
Overview
WordPress admin permission issues often arise from corrupted user roles, plugin/theme conflicts, core file issues, or database problems. Symptoms include missing wp-admin menus (e.g., Dashboard, Themes, Plugins) or restricted access to admin features. WP-CLI is a powerful tool to diagnose and resolve these issues efficiently.
Prerequisites
- WP-CLI installed (
wp --infoto verify). - Access to the WordPress root directory.
- Sufficient server permissions (e.g., file and database access).
- Backup your site (
wp db exportandtar -czf backup.tar.gz wp-content) before making changes.
Troubleshooting Steps
1. Verify User Role and Capabilities
Ensure the user has the Administrator role and required capabilities (edit_dashboard, switch_themes, activate_plugins).
- Check User Role:
wp user get user@example.com --field=rolesOutput: Should return
administrator. If not, set the role:wp user set-role user@example.com administrator - Check Capabilities:
wp role list+---------------+---------------+ | name | role | +---------------+---------------+ | Administrator | administrator | | Editor | editor | | Author | author | | Contributor | contributor | | Subscriber | subscriber | | SEO Manager | wpseo_manager | | SEO Editor | wpseo_editor | +---------------+---------------+
wp cap list administratorOutput: Confirmedit_dashboard,switch_themes,install_themes,activate_plugins,install_pluginsare present. - Reset Administrator Role:
If capabilities are missing, reset the role:<?php // File: reset-admin.php require('wp-load.php'); remove_role('administrator'); $admin_caps = [ 'edit_dashboard' => true, 'switch_themes' => true, 'install_themes' => true, 'update_themes' => true, 'delete_themes' => true, 'edit_themes' => true, 'edit_theme_options' => true, 'activate_plugins' => true, 'install_plugins' => true, 'update_plugins' => true, 'delete_plugins' => true, 'edit_plugins' => true, 'manage_options' => true, 'update_core' => true, 'read' => true, 'edit_posts' => true, 'edit_others_posts' => true, 'publish_posts' => true, 'edit_pages' => true, 'publish_pages' => true, 'manage_categories' => true, 'moderate_comments' => true, 'upload_files' => true, 'edit_users' => true, 'create_users' => true, 'delete_users' => true, 'list_users' => true, ]; add_role('administrator', 'Administrator', $admin_caps); $user = get_user_by('email', 'user@example.com'); if ($user) $user->set_role('administrator'); echo "Admin role reset. Delete this file!";Run:
wp eval-file reset-admin.phpand delete the file.
2. Check for Plugin/Theme Conflicts
Plugins or themes may hide menu items or override capabilities.
- Deactivate All Plugins:
wp plugin deactivate --allLog in to
wp-admin. If menus appear, reactivate plugins individually:wp plugin activate akismet - Switch to Default Theme:
wp theme activate twentytwentyfiveIf not installed:
wp theme install twentytwentyfive --activate.
3. Verify Core Files
Corrupted core files (e.g., wp-admin/menu.php) can break menu rendering.
- Check Integrity:
wp core verify-checksumsIf errors, reinstall core:
wp core download --force --skip-content
4. Debug Admin Menu
Custom code may remove menu items via the admin_menu hook.
- Log Menu Items:
Createwp-content/mu-plugins/debug-menu.php:<?php add_action('admin_menu', function () { global $menu, $submenu; file_put_contents(WP_CONTENT_DIR . '/menu-debug.log', print_r($menu, true)); file_put_contents(WP_CONTENT_DIR . '/submenu-debug.log', print_r($submenu, true)); }, 999);Check
wp-content/menu-debug.logforindex.php(Dashboard),themes.php(Themes),plugins.php(Plugins). - Force Menu Items:
Createwp-content/mu-plugins/force-menu.php:<?php add_action('admin_menu', function () { add_menu_page('Dashboard', 'Dashboard', 'edit_dashboard', 'index.php', '', 'dashicons-dashboard', 0); add_menu_page('Themes', 'Themes', 'switch_themes', 'themes.php', '', 'dashicons-admin-appearance', 60); add_menu_page('Plugins', 'Plugins', 'activate_plugins', 'plugins.php', '', 'dashicons-admin-plugins', 65); }, 999);Delete after testing.
5. Check Database
Corrupted roles in the database can cause permission issues.
- Verify Roles:
wp option get wp_user_rolesIf incorrect, reset roles:
wp role reset --all - Repair Database:
wp db repair
6. Multisite (If Applicable)
For multisite, ensure super admin status:
wp super-admin add user@example.com
Check network admin menus (/wp-admin/network/).
7. Enable Debugging
Log errors to identify issues:
wp config set WP_DEBUG true --raw
wp config set WP_DEBUG_LOG true --raw
wp config set WP_DEBUG_DISPLAY false --raw
Check wp-content/debug.log for errors.
Common WP-CLI Commands for Repetitive Issues
- List Users:
wp user list --fields=user_email,roles - List Plugins:
wp plugin list --fields=name,status - Activate/Deactivate Plugin:
wp plugin activate akismet wp plugin deactivate akismet - Switch Theme:
wp theme activate twentytwentyfive - Update WordPress Core:
wp core update - Flush Cache:
wp cache flush - Check File Permissions:
find wp-admin -type d -exec chmod 755 {} \; find wp-admin -type f -exec chmod 644 {} \;
Additional Tips
- Backup Regularly: Use
wp db exportand archivewp-contentbefore changes. - Security Plugins: Check plugins like WP Rocket or Wordfence for restrictions:
wp plugin deactivate wp-rocket wordfence - File Permissions: Ensure
wp-adminandwp-contenthave correct permissions (755for directories,644for files).
