Change User Role For WP Rocket Settings

By default, WP Rocket’s settings are available to users that have the Administrator user role; if you are on multisite, this means individual site administrators as well as Super Admins for the network.

If you want to modify the default set of required user capabilities for WP Rocket, you can do so with the following snippets. Preferably you would use a custom MU plugin, but you can also add code to your theme’s functions.php instead.

Grant Site Editors Access to WP Rocket’s Settings

You can lower the barrier to access WP Rocket’s settings and enable site editors to control its options by following these steps:

Custom MU Plugin

Follow the general instructions in this article:
How to Make a Custom (MU) Plugin

1
Create a folder named mu-plugins in your wp-content folder.
In case a mu-plugins folder already exists, don’t create a new one, just use the existing one.
2
Using a basic text editor create a new file and put the following code in it:
<?php
defined( 'ABSPATH' ) or die( 'Cheatin&#8217; uh?' );
/**
 * Plugin Name: WP Rocket | Settings Access for Site Editors 
 * Description: Allows site editors to access and modify WP Rocket’s settings.
 * Author:      WP Rocket Support Team
 * Author URI:  http://wp-rocket.me/
 * License:     GNU General Public License v3 or later
 * License URI: http://www.gnu.org/licenses/gpl-3.0.html
 */

/**
 * Set minimum user capability for WP Rocket.
 * @param  string $capability WordPress user capability
 * @return string             WordPress user capability
 */
function rocket_for_editor( $capability ) {

	if ( current_user_can( 'editor' ) ) {
		return 'editor';
	}

	return $capability;
}
add_filter( 'rocket_capacity', 'rocket_for_editor' );
// only required before 2.8.9:
add_filter( 'rocket_capability', 'rocket_for_editor' );
	
3
Save the file as wp-rocket-userrole.php
4
Upload this file to the mu-plugins folder created in step 1.
5
Finally, make sure to deactivate and re-activate WP Rocket.

From your Theme

Place the below snippet in the functions.php of your child theme or custom theme.

/**
 * Set minimum user capability for WP Rocket.
 * @param  string $capability WordPress user capability
 * @return string             WordPress user capability
 */
function rocket_for_editor( $capability ) {
	if ( current_user_can( 'editor' ) ) {
		return 'editor';
	}
	return $capability;
}
add_filter( 'rocket_capacity', 'rocket_for_editor' );
// only required before 2.8.9:
add_filter( 'rocket_capability', 'rocket_for_editor' );

Multisite: Restrict Settings to Super Admins Only

In a Multisite environment you can use the following code in your MU plugin or functions.php in order to restrict settings access to Super Admins for WP Rocket.
/**
 * Restrict settings access to Super Admins.
 * @param  string $capability WordPress user capability
 * @return string             WordPress user capability
 */
function rocket_for_super_admin( $capability ) {
	if ( ! current_user_can( 'manage_network' ) ) {
		return 'manage_network';
	}
	return $capability;
}
add_filter( 'rocket_capacity', 'rocket_for_super_admin' );
// only required before 2.8.9:
add_filter( 'rocket_capability', 'rocket_for_super_admin' );