Skip to content

Conversation

@sanketio
Copy link
Contributor

@sanketio sanketio commented Aug 5, 2025

Description of the Change

This PR adds a new feature to hide the WordPress admin bar on the frontend for specific user roles. This addresses the common need for previewing sites to low-access users by providing a cleaner, distraction-free experience.

Key Features:

  • Role-based admin bar hiding: Admins can select which user roles should have the admin bar hidden on the frontend
  • Frontend-only: Only affects the frontend, admin functionality remains unchanged
  • Network support: Works with both single-site and multisite installations
  • Clean interface: Simple checkbox interface for easy role selection

Implementation Details:

  • Uses WordPress's built-in show_admin_bar filter
  • Adds new setting field hide_admin_bar_roles to the plugin options
  • Implements proper sanitization and validation of user roles

Closes #354

How to test the Change

  1. Setup:

    • Install and activate the plugin
    • Go to Settings > Reading
    • Scroll to Restricted Site Access section
  2. Test Role Selection:

    • Check/uncheck different user roles
    • Save settings
    • Verify selected roles are saved correctly
  3. Test Admin Bar Hiding:

    • Log in as a user with a role that has admin bar hidden
    • Visit frontend pages
    • Verify admin bar is not visible
    • Check that no layout issues occur (no extra top margin)
  4. Test Admin Bar Visibility:

    • Log in as a user with a role that doesn't have admin bar hidden
    • Visit frontend pages
    • Verify admin bar is visible as normal
  5. Test Network Settings (Multisite):

    • If using multisite, test the feature in network settings
    • Verify it works across all sites in the network based on the selected "Mode"

Changelog Entry

Added - New feature to hide admin bar on frontend for specific user roles

Credits

Props @sanketio

Checklist:

@sanketio sanketio marked this pull request as draft August 5, 2025 12:00
@github-actions github-actions bot added the needs:code-review This requires code review. label Aug 5, 2025
@jeffpaul jeffpaul added this to the 7.6.0 milestone Aug 5, 2025
@github-actions github-actions bot removed the needs:code-review This requires code review. label Aug 5, 2025
@sanketio sanketio marked this pull request as ready for review August 6, 2025 14:37
@github-actions github-actions bot added the needs:code-review This requires code review. label Aug 6, 2025
Copy link
Collaborator

@dkotter dkotter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really good, thanks for all the work here. Left one minor comment on the label text but otherwise I saw only one issue.

If the plugin is network-activated, we have an option to either select settings that become the default for any newly created site (allowing someone to change those settings on a site-by-site basis) or enforce those settings across all sites (which means those settings can't be changed on a site-by-site basis).

It seems this new setting doesn't respect that. So if I network-activate the plugin and choose the enforce option, the option(s) I select for this new user role setting aren't enforced at the site-level and someone can still change that setting on a site level.

I didn't check the default option to see if that worked (requires creating a new site on the network) but I imagine that's probably not working either.

@sanketio
Copy link
Contributor Author

sanketio commented Aug 7, 2025

@dkotter Thank you for taking time in reviewing the feature and outlining the issue.

It seems this new setting doesn't respect that. So if I network-activate the plugin and choose the enforce option, the option(s) I select for this new user role setting aren't enforced at the site-level and someone can still change that setting on a site level.

Yes, you were right about this. I updated the code and it should work fine now.

I didn't check the default option to see if that worked (requires creating a new site on the network) but I imagine that's probably not working either.

I tested this before making any changes, and it was working fine. It was just that enforce mode was having an issue.

@dkotter
Copy link
Collaborator

dkotter commented Aug 7, 2025

Yes, you were right about this. I updated the code and it should work fine now.

This is working great now, thanks for the changes! I do see a notice showing twice though when settings are enforced, which seems a little weird:

Admin notice showing twice

@github-actions github-actions bot added the needs:refresh This requires a refreshed PR to resolve. label Aug 7, 2025
@github-actions github-actions bot removed the needs:refresh This requires a refreshed PR to resolve. label Aug 8, 2025
@sanketio
Copy link
Contributor Author

sanketio commented Aug 8, 2025

Thanks, @dkotter!

Those two notices are different: one is for site visibility, and the other one is for restricted site access plugin.

The first one is being added through blog_privacy_selector action, and we cannot combine these two as both are separate settings. I have explicitly added the second notice so that it shows only for the restricted site access in case we add more always-visible settings in the plugin.

@jeffpaul jeffpaul requested a review from dkotter September 8, 2025 20:06
@dkotter dkotter merged commit eaa6a48 into develop Oct 24, 2025
15 checks passed
@dkotter dkotter deleted the feature/354-hide-admin-bar branch October 24, 2025 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs:code-review This requires code review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a setting to RSA to hide the admin bar for subscriber users on the FE

3 participants