Skip to content

Instantly share code, notes, and snippets.

@jchristopher
Created March 26, 2020 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jchristopher/883d3a2fedc2cf81809cc10e6a1e32bf to your computer and use it in GitHub Desktop.
Save jchristopher/883d3a2fedc2cf81809cc10e6a1e32bf to your computer and use it in GitHub Desktop.
Restrict viewing Statistics to Administrators in SearchWP
<?php
// Restrict viewing Statistics to Administrators in SearchWP.
add_filter( 'searchwp\statistics\capability', function( $capability ) {
return 'manage_options';
} );
@TriOptCorp
Copy link

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.

@TriOptCorp
Copy link

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