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
2 months ago
Subscription.php
4 months ago
SystemReport.php
4 months ago
TestMode.php
4 months ago
EditorClearCache.php
61 lines
| 1 | <?php |
| 2 | namespace NitroPack\WordPress\Settings; |
| 3 | use NitroPack\WordPress\NitroPack; |
| 4 | |
| 5 | /** |
| 6 | * Allows editor role to purge or invalidate page cache in meta boxes. |
| 7 | */ |
| 8 | class EditorClearCache { |
| 9 | |
| 10 | /** @var string */ |
| 11 | public $option_name; |
| 12 | |
| 13 | public function __construct() { |
| 14 | add_action( 'wp_ajax_nitropack_set_can_editor_clear_cache', [ $this, 'nitropack_set_can_editor_clear_cache' ] ); |
| 15 | $this->option_name = 'nitropack-canEditorClearCache'; |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * AJAX handler when toggle the setting in Dashboard |
| 20 | * @return void |
| 21 | */ |
| 22 | public function nitropack_set_can_editor_clear_cache() { |
| 23 | nitropack_verify_ajax_nonce( $_REQUEST ); |
| 24 | $option = (int) ! empty( $_POST["data"]["canEditorClearCache"] ); |
| 25 | $updated = update_option( $this->option_name, $option ); |
| 26 | if ( $updated ) { |
| 27 | NitroPack::getInstance()->getLogger()->notice( 'Allow Editors to purge cache is ' . ( $option === 1 ? 'enabled' : 'disabled' ) ); |
| 28 | nitropack_json_and_exit( array( "type" => "success", "message" => nitropack_admin_toast_msgs( 'success' ), "allowedEditors" => $option ) ); |
| 29 | } else { |
| 30 | NitroPack::getInstance()->getLogger()->error( 'Allow Editors to purge cache cannot be ' . ( $option === 1 ? 'enabled' : 'disabled' ) ); |
| 31 | nitropack_json_and_exit( array( |
| 32 | "type" => "error", |
| 33 | "message" => nitropack_admin_toast_msgs( 'error' ) |
| 34 | ) ); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Renders the Editor Purge option in the Dashboard |
| 40 | * @return void |
| 41 | */ |
| 42 | public function render() { |
| 43 | $canEditorClearCache = get_option( $this->option_name, 1 ); |
| 44 | ?> |
| 45 | <div class="nitro-option" id="can-editor-clear-cache-widget"> |
| 46 | <div class="nitro-option-main"> |
| 47 | <div class="text-box"> |
| 48 | <h6> |
| 49 | <?php esc_html_e( 'Allow Editors to purge cache', 'nitropack' ); ?> |
| 50 | </h6> |
| 51 | <p> |
| 52 | <?php esc_html_e( 'Give Editors the right to purge cache when content is updated.', 'nitropack' ); ?> |
| 53 | </p> |
| 54 | </div> |
| 55 | <?php $components = new Components(); |
| 56 | $components->render_toggle( 'can-editor-clear-cache', $canEditorClearCache ); ?> |
| 57 | </div> |
| 58 | </div> |
| 59 | <?php |
| 60 | } |
| 61 | } |