WP Rocket Helper Plugin
A WordPress helper plugin to remove two hooks in the 'wp-rocket' plugin.
by Robert A Gadon · github.com/rgadon107/rocket-helper · website
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/rgadon107/rocket-helper/archive/refs/heads/development.zip'Rocket-Helper' Plugin
A WordPress helper plugin intended to target and remove 2 admin notices in the WP Rocket plugin that display when either the .htaccess or advanced-cache.php files are not writable.
Targeting the admin notices
There is one procedural function and one class method each that manage the respective admin notices.
- function
rocket_warning_htaccess_permissions()in/wp-rocket/inc/admin/ui/notices.phpon line 377. - function
rocket_warning_advanced_cache_permissions()in/wp-rocket/inc/deprecated/3.6.phpon line 111.
Removing function rocket_warning_htaccess_permissions()
The function rocket_warning_htaccess_permissions() was relatively easy to disable. It’s registered to the action event admin_notices. The event is located in the file /wp-admin/admin-header.php on line #281. I removed the admin notice by registering a custom callback to the admin_init hook which fires as an admin screen or script is being initialized.
I validated the removal of rocket_warning_htaccess_permissions() by calling the global variable $wp_filter inside the custom callback and inspecting $wp_filter[‘admin_notices’] before and after the function was removed. The call to $wp_filter was removed prior to committing the plugin code to Git.
Removing rocket_warning_advanced_cache_permissions().
This was a more challenging function to disable. In WP Rocket version 3.6, this function was deprecated, and replaced by \WP_Rocket\Engine\Cache\AdvancedCache::notice_permissions(). That method is not currently accessible via the instantiation of a new object.
In the case of hosting by WP Engine ( /wp-rocket/inc/3rd-party/hosting/wpengine.php ), the admin notice previously generated by rocket_warning_advanced_cache_permissions() is removed on the admin_init hook. An anonymous function registered to admin_init instatiates an object assigned to the variable $subscriber. Then the target function registered to the admin_notices hook is removed.
Plugin structure
This plugin is based on a starter plugin boilerplate originally committed by Tonya Mork to the Github repo for KnowTheCode.io.