AutoPurge.php
4 months ago
BeaverBuilder.php
4 months ago
CPTOptimization.php
4 months ago
CacheWarmup.php
3 months ago
CartCache.php
4 months ago
Components.php
4 months ago
EditorClearCache.php
4 months ago
GeneratePreview.php
7 months ago
HTMLCompression.php
3 months ago
Logger.php
4 months ago
OptimizationLevel.php
3 months ago
Optimizations.php
4 months ago
PurgeCache.php
4 months ago
Shortcodes.php
4 months ago
StockRefresh.php
4 months ago
Subscription.php
4 months ago
SystemReport.php
4 months ago
TestMode.php
4 months ago
AutoPurge.php
56 lines
| 1 | <?php |
| 2 | |
| 3 | namespace NitroPack\WordPress\Settings; |
| 4 | use Nitropack\WordPress\NitroPack; |
| 5 | |
| 6 | /** |
| 7 | * Auto Purge NitroPack cache on post/page save |
| 8 | */ |
| 9 | class AutoPurge { |
| 10 | /** @var string */ |
| 11 | public $option_name; |
| 12 | public function __construct() { |
| 13 | add_action( 'wp_ajax_nitropack_set_auto_cache_purge_ajax', [ $this, 'nitropack_set_auto_cache_purge_ajax' ] ); |
| 14 | $this->option_name = 'nitropack-autoCachePurge'; |
| 15 | } |
| 16 | |
| 17 | /** |
| 18 | * AJAX handler when toggling the setting in the Dashboard |
| 19 | * @return void |
| 20 | */ |
| 21 | public function nitropack_set_auto_cache_purge_ajax() { |
| 22 | nitropack_verify_ajax_nonce( $_REQUEST ); |
| 23 | $option = (int) ! empty( $_POST["autoCachePurgeStatus"] ); |
| 24 | $updated = update_option( $this->option_name, $option ); |
| 25 | if ( $updated ) { |
| 26 | NitroPack::getInstance()->getLogger()->notice( 'Auto cache purge is ' . ( $option === 1 ? 'enabled' : 'disabled' ) ); |
| 27 | nitropack_json_and_exit( [ "type" => "success", "message" => nitropack_admin_toast_msgs( 'success' ), 'autoCachePurgeStatus' => $option ] ); |
| 28 | } else { |
| 29 | NitroPack::getInstance()->getLogger()->error( 'Auto cache purge cannot be ' . ( $option === 1 ? 'enabled' : 'disabled' ) ); |
| 30 | nitropack_json_and_exit( [ |
| 31 | "type" => "error", |
| 32 | "message" => nitropack_admin_toast_msgs( 'error' ) |
| 33 | ] ); |
| 34 | } |
| 35 | } |
| 36 | /** |
| 37 | * Renders the Auto Purge option in the Dashboard |
| 38 | * @return void |
| 39 | */ |
| 40 | public function render() { |
| 41 | $autoCachePurge = get_option( $this->option_name, 1 ); |
| 42 | ?> |
| 43 | <div class="nitro-option" id="purge-cache-widget"> |
| 44 | <div class="nitro-option-main"> |
| 45 | <div class="text-box"> |
| 46 | <h6><?php esc_html_e( 'Purge cache', 'nitropack' ); ?></h6> |
| 47 | <p><?php esc_html_e( 'Purge affected cache when content is updated or published', 'nitropack' ); ?> |
| 48 | </p> |
| 49 | </div> |
| 50 | <?php $components = new Components(); |
| 51 | $components->render_toggle( 'auto-purge-status', $autoCachePurge ); ?> |
| 52 | </div> |
| 53 | </div> |
| 54 | <?php |
| 55 | } |
| 56 | } |