Created
July 20, 2024 16:15
-
-
Save victormattosvm/9990a9112e307ce655e6434b05722c95 to your computer and use it in GitHub Desktop.
[GoInfinite] Automatically clear WAF cache after Elementor edits
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 | |
| function clear_waf_cache() { | |
| try { | |
| // Execute the shell command to clear WAF cache | |
| $output_str = shell_exec('cli8 waf cache clear'); | |
| // Check if shell_exec returned an output | |
| if ($output_str === null) { | |
| throw new Exception('shell_exec failed to execute the command.'); | |
| } | |
| // Get the string and transform it into array | |
| $output = json_decode($output_str, true); | |
| // Check if the output is valid and if the status is false | |
| if (!is_array($output) || $output['status'] === false) { | |
| throw new Exception('Error when trying to clear WAF cache'); | |
| } | |
| } catch (Exception $e) { | |
| error_log($e->getMessage()); | |
| } | |
| } | |
| add_action('elementor/editor/after_save', 'clear_waf_cache'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment