If you are using Independent Analytics on a large number of sites and don’t want to manually configure which user roles have access to the analytics, you can do so programmatically instead.
Independent Analytics uses the WordPress capabilities system and restricts access based on these three permissions:
iawp_read_only_authored_access – view stats for own content onlyiawp_read_only_access – view all statsiawp_full_access – view all stats and edit the settings
As an example, here’s how you could give editors access to view the analytics, but not edit the settings:
function iawp_grant_editor_access() {
$role = get_role( 'editor' );
if ( $role && ! $role->has_cap( 'iawp_read_only_access' ) ) {
$role->add_cap( 'iawp_read_only_access' );
}
}
add_action( 'admin_init', 'iawp_grant_editor_access' );
