Skip to content

Instantly share code, notes, and snippets.

@glueckpress
Last active March 5, 2019 21:19
Show Gist options
  • Save glueckpress/6a5ec40dc71e9775fcaa to your computer and use it in GitHub Desktop.
Save glueckpress/6a5ec40dc71e9775fcaa to your computer and use it in GitHub Desktop.
[WordPress] Multisite: Restrict WP Rocket settings access to superadmins.
<?php
/**
* Plugin Name: WP Rocket User Role
* Description: Restrict WP Rocket settings access to superadmins.
* Version: 2015.12
* Author: Caspar Hübinger
* Author URI: https://profiles.wordpress.org/glueckpress/
* Plugin URI: http://docs.wp-rocket.me/article/129-change-user-role-for-wp-rocket-settings
* License: GNU General Public License v3
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! function_exists( 'wprocket_userrole' ) && ! function_exists( 'wprocket_userrole__super_admin' ) ) {
/**
* Load plugin.
*/
function wprocket_userrole() {
add_filter( 'option_page_capability_wp_rocket', 'wprocket_userrole__super_admin' );
add_filter( 'rocket_capacity', 'wprocket_userrole__super_admin' );
}
add_action( 'plugins_loaded', 'wprocket_userrole' );
/**
* Set minimum capability to access WP Rocket settings.
*
* @param string $capability Minimum capability to access WP Rocket settings
* @return string Minimum capability to access WP Rocket settings
*/
function wprocket_userrole__super_admin( $capability ) {
if ( ! current_user_can( 'manage_network' ) ) {
return 'manage_network';
}
return $capability;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment