Created
October 28, 2025 12:58
-
-
Save lukapaunovic/f83762216101c99e6298f6d7a859b407 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| Plugin Name: Disable WP Rocket SaaS Deletion | |
| Description: Prevent WP Rocket from deleting SaaS-generated assets. | |
| Author: Luka | |
| */ | |
| # Remove Notices | |
| add_filter( 'rocket_dismiss_notice', '__return_true' ); | |
| # Do not automatically delete RUCSS | |
| add_filter( 'rocket_saas_deletion_enabled', '__return_false' ); | |
| // 1) Skini glavni WP Rocket admin bar hook | |
| add_action( 'init', function() { | |
| // WP Rocket registruje meni ovim: | |
| // add_action( 'admin_bar_menu', 'rocket_admin_bar', PHP_INT_MAX - 10 ); | |
| if ( function_exists( 'rocket_admin_bar' ) ) { | |
| remove_action( 'admin_bar_menu', 'rocket_admin_bar', PHP_INT_MAX - 10 ); | |
| } | |
| }, 20 ); | |
| // 2) Preduhitri SaaS/URL stavke (ako dođu iz njihovih klasa) – samo skloni čvorove | |
| add_action( 'admin_bar_menu', function( $bar ) { | |
| if ( ! is_object( $bar ) || ! method_exists( $bar, 'get_nodes' ) ) { | |
| return; | |
| } | |
| $nodes = $bar->get_nodes(); | |
| if ( empty( $nodes ) ) return; | |
| foreach ( $nodes as $id => $node ) { | |
| // Glavni parent | |
| if ( $id === 'wp-rocket' ) { | |
| $bar->remove_node( $id ); | |
| continue; | |
| } | |
| // Uobičajeni Rocket id-jevi i sve stavke pod 'wp-rocket' | |
| $parent = isset( $node->parent ) ? $node->parent : ''; | |
| if ( $parent === 'wp-rocket' || strpos( $id, 'rocket' ) === 0 ) { | |
| $bar->remove_node( $id ); | |
| } | |
| } | |
| }, PHP_INT_MAX ); | |
| // 1) Označi ga kao dismiss-ovan za sve admine (sprečava prikaz iz samog izvora) | |
| add_action('admin_init', function () { | |
| if ( ! current_user_can('manage_options') ) { return; } | |
| $uid = get_current_user_id(); | |
| $boxes = (array) get_user_meta($uid, 'rocket_boxes', true); | |
| if ( ! in_array('rocket_warning_plugin_modification', $boxes, true) ) { | |
| $boxes[] = 'rocket_warning_plugin_modification'; | |
| update_user_meta($uid, 'rocket_boxes', $boxes); | |
| } | |
| }, 1); | |
| // 2) Skinuti hook ako ga je WP Rocket već zakačio | |
| add_action('admin_init', function () { | |
| if ( function_exists('rocket_warning_plugin_modification') ) { | |
| for ($p=0; $p<=100; $p++) { | |
| remove_action('admin_notices', 'rocket_warning_plugin_modification', $p); | |
| remove_action('all_admin_notices', 'rocket_warning_plugin_modification', $p); | |
| } | |
| } | |
| }, 2); | |
| // 3) Poslednja linija odbrane: ako ipak prođe kroz njihov renderer, anuliraj baš taj notice | |
| add_filter('rocket_notice_args', function($args) { | |
| if ( is_array($args) && !empty($args['message']) ) { | |
| // poruka je i18n, pa gađamo po akciji clear_cache + ključnoj frazi | |
| $msg = wp_strip_all_tags($args['message']); | |
| if ( (isset($args['action']) && $args['action'] === 'clear_cache') | |
| || stripos($msg, 'One or more plugins have been enabled or disabled') !== false ) { | |
| // vrati null da zadrži originalne $defaults i praktično ne ispiše ništa | |
| return ['message' => '']; | |
| } | |
| } | |
| return $args; | |
| }, 999); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment