Introduction
By default, BuddyBoss does not provide an option to restrict access to the WordPress admin area. You can limit admin access so that only administrators can view the WP Admin pages by adding a custom function to your active theme. This guide explains how you can restrict users to the WordPress admin page.
Custom Workaround
Before proceeding, make sure you have a complete site backup.
- In your WordPress admin dashboard, go to Appearance > Theme Editor.
- Under Select theme to edit, choose your active theme (preferably BuddyBoss Child Theme), then click Select.
- From the Theme Files list, click Theme Functions (functions.php).
- Paste the following code just before the closing PHP tag (?>):
function bb_restrict_admin_only() {
if ( ! current_user_can( 'manage_options' ) && ( ! wp_doing_ajax() ) ) {
wp_safe_redirect( site_url() );
exit;
}
}
add_action( 'admin_init', 'bb_restrict_admin_only', 1 );- Click Update File to save your changes.
Troubleshooting and FAQs
Q: Non-admin users can still access the admin area, what should I check?
A: Make sure the code is added to the active theme’s functions.php and clear any caches.
Q: Will this block AJAX requests or background processes?
A: No, AJAX requests are excluded to prevent issues with site functionality.
Q: Will this affect administrators?
A: No, users with the manage_options capability will still have full access.
Q: Can I redirect users to a different page instead of the homepage?
A: Yes, replace site_url() with the URL of your choice.
Q: Who can I contact for further assistance?
A: Check the BuddyBoss Support Policy or consult a developer.