Created
March 26, 2020 17:21
-
-
Save jchristopher/883d3a2fedc2cf81809cc10e6a1e32bf to your computer and use it in GitHub Desktop.
Restrict viewing Statistics to Administrators in SearchWP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Restrict viewing Statistics to Administrators in SearchWP. | |
add_filter( 'searchwp\statistics\capability', function( $capability ) { | |
return 'manage_options'; | |
} ); |
I think I have an idea of how to do this. Using the User Role Editor plugin, I could create a new capability, called, for example: "view_searchwp_stats". I could then assign that capability to whatever roles I want. I would then add the above code to the SearchWP customizations plugin and then I should test with a user to ensure everything is working correctly.
I suppose my only concern there is that this may not be "granular" enough. Once the user can see the stats tab, they would also have "edit" rights to same, correct? Looking to give them "read only" rights, if possible.
Thanks.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
So this would automatically restrict the Statistics view to administrators? What if we wanted to have a specific role created and assigned to users to that the would have read-only access to the statistics? Please provide more details. Thank you.