CacheWarmup.php
7 months ago
Components.php
1 year ago
GeneratePreview.php
7 months ago
Logger.php
7 months ago
OptimizationLevel.php
7 months ago
Shortcodes.php
1 year ago
TestMode.php
10 months ago
CacheWarmup.php
71 lines
| 1 | <?php |
| 2 | |
| 3 | namespace NitroPack\WordPress\Settings; |
| 4 | |
| 5 | class CacheWarmup { |
| 6 | private static $instance = NULL; |
| 7 | public function __construct() { |
| 8 | add_action( 'wp_ajax_nitropack_skip_cache_warmup', array( $this, 'nitropack_skip_cache_warmup' ) ); |
| 9 | |
| 10 | } |
| 11 | public static function getInstance() { |
| 12 | if ( null === self::$instance ) { |
| 13 | self::$instance = new self(); |
| 14 | } |
| 15 | return self::$instance; |
| 16 | } |
| 17 | |
| 18 | /* Dismiss cache warmup notice in the final third step when Onboarding */ |
| 19 | public function nitropack_skip_cache_warmup() { |
| 20 | nitropack_verify_ajax_nonce( $_REQUEST ); |
| 21 | |
| 22 | $nitropack_notices = get_option( 'nitropack-dismissed-notices', array() ); |
| 23 | $nitropack_notices['skip_cache_warmup'] = 1; |
| 24 | update_option( 'nitropack-dismissed-notices', $nitropack_notices ); |
| 25 | |
| 26 | nitropack_json_and_exit( array( |
| 27 | "type" => "success", |
| 28 | "message" => nitropack_admin_toast_msgs( 'success', esc_html__( 'Cache warmup skipped.', 'nitropack' ) ) |
| 29 | ) ); |
| 30 | } |
| 31 | |
| 32 | /* Render cache warmup setting widget */ |
| 33 | public function render() { |
| 34 | $nitro = get_nitropack_sdk(); |
| 35 | $cache_warmup_stats = $nitro->getApi()->getWarmupStats(); |
| 36 | ?> |
| 37 | <div class="nitro-option" id="cache-warmup-widget"> |
| 38 | <div class="nitro-option-main"> |
| 39 | <div class="text-box" id="warmup-status-slider"> |
| 40 | |
| 41 | <?php $sitemap = get_option( 'nitropack-warmup-sitemap', false ); |
| 42 | $toolTipDisplayState = $sitemap ? '' : 'hidden'; ?> |
| 43 | |
| 44 | <h6><?php esc_html_e( 'Cache warmup', 'nitropack' ); ?> <span |
| 45 | class="badge badge-primary ml-2"><?php esc_html_e( 'Recommended', 'nitropack' ); ?></span> |
| 46 | <span class="tooltip-icon <?php echo $toolTipDisplayState; ?>" data-tooltip-target="tooltip-sitemap"> |
| 47 | <img src="<?php echo plugin_dir_url( NITROPACK_FILE ) . 'view/images/info.svg'; ?>"> |
| 48 | </span> |
| 49 | </h6> |
| 50 | <div id="tooltip-sitemap" role="tooltip" class="tooltip-container hidden"> |
| 51 | <?php echo $sitemap; ?> |
| 52 | <div class="tooltip-arrow" data-popper-arrow></div> |
| 53 | </div> |
| 54 | <p><?php esc_html_e( 'Automatically pre-caches your website\'s page content', 'nitropack' ); ?>. |
| 55 | <a href="https://support.nitropack.io/en/articles/8390320-cache-warmup" class="text-blue" |
| 56 | target="_blank"><?php esc_html_e( 'Learn more', 'nitropack' ); ?></a> |
| 57 | </p> |
| 58 | </div> |
| 59 | <label class="inline-flex items-center cursor-pointer ml-auto"> |
| 60 | <input id="warmup-status" type="checkbox" class="sr-only peer" <?php echo $cache_warmup_stats['status'] === 1 ? "checked" : ""; ?>> |
| 61 | <div class="toggle"></div> |
| 62 | </label> |
| 63 | </div> |
| 64 | <div class="msg-container hidden" id="loading-warmup-status"> |
| 65 | <img src="<?php echo plugin_dir_url( NITROPACK_FILE ) . 'view/images/loading.svg'; ?>" alt="loading" class="icon"> |
| 66 | <span class="msg"><?php esc_html_e( 'Loading cache warmup status', 'nitropack' ); ?></span> |
| 67 | </div> |
| 68 | </div> |
| 69 | <?php } |
| 70 | } |
| 71 |