'; } echo '

' . esc_html__('These settings enable you to manage the object cache.', 'pressable_cache_management') . '

'; // Check if the site uses Cloudflare $response = wp_remote_get( get_site_url(), array( 'timeout' => 120 ) ); $headers = wp_remote_retrieve_headers( $response ); if ( isset( $headers['server'] ) && stripos( $headers['server'], 'cloudflare' ) !== false ) { //Cloudflare is present in the website header. // Check Batcache status $site_url = get_site_url(); $response = wp_remote_get( $site_url, array( 'timeout' => 120 ) ); if ( is_wp_error( $response ) || strpos( $response['body'], 'batcache' ) === false ) { echo '

Batcache Status: Broken 🔴

'; echo '

Disable Cloudflare proxy and caching and try again 🟠


'; } else { echo '

Batcache Status: OK 🟢

'; } } else { //Cloudflare is not present in the website header. // Check for Batcache $site_url = get_site_url(); $response = wp_remote_get( $site_url, array( 'timeout' => 120 ) ); if ( is_wp_error( $response ) || strpos( $response['body'], 'batcache' ) === false ) { echo '

Batcache Status: Broken 🔴


'; } else { echo '

Batcache Status: OK 🟢

'; } } } // RESTORED: This function is required by admin/settings-validate.php but was accidentally removed during cleanup. function pressable_cache_management_options_radio_button() { return array( 'enable' => esc_html__('Enable CDN (Recommended)', 'pressable_cache_management') , 'disable' => esc_html__('Disable CDN', 'pressable_cache_management') ); } // Removed redundant code related to CDN and old API flags $pcm_con_auth = 'pressable_api_admin_notice__status'; // If the option already exists, update it to "OK" if ( get_option( $pcm_con_auth ) !== false ) { update_option( $pcm_con_auth, 'OK' ); } else { add_option( $pcm_con_auth, 'OK' ); } function pressable_cache_management_callback_section_edge_cache() { echo '

' . esc_html__('These settings enable you to manage Edge Cache settings.', 'pressable_cache_management') . '

'; } // callback: Hide Pressable branding tab page description function pressable_cache_management_callback_section_branding() { echo '

' . esc_html__('This setting allows you to show or hide the plugin branding.', 'pressable_cache_management') . '

'; } /** ******************************** * Object Cache * * Management Tab * ******************************** * */ // Flush object cache button function pressable_cache_management_callback_field_button($args) { $options = get_option('pressable_cache_management_options'); $id = isset($args['id']) ? $args['id'] : ''; $label = isset($args['label']) ? $args['label'] : ''; echo ''; echo '
'; echo '
'; //Display time stamp when object cache was last flushed echo 'Last flushed at: ' . wp_kses_post( get_option('flush-obj-cache-time-stamp') ); } // Extend batcache checkbox function pressable_cache_management_callback_field_extend_cache_checkbox($args) { $options = get_option('pressable_cache_management_options'); $id = isset($args['id']) ? $args['id'] : ''; $label = isset($args['label']) ? $args['label'] : ''; $checked = isset($options[$id]) ? checked($options[$id], 1, false) : ''; echo '
'; echo ''; // echo '
'; echo ''; } // Flush site cache on Theme/Plugin update checkbox function pressable_cache_management_callback_field_plugin_theme_update_checkbox($args) { $options = get_option('pressable_cache_management_options'); $id = isset($args['id']) ? $args['id'] : ''; $label = isset($args['label']) ? $args['label'] : ''; $checked = isset($options[$id]) ? checked($options[$id], 1, false) : ''; echo '
'; echo ''; echo ''; echo '
'; echo '
'; //Display time stamp when object cache was last flushed when theme plugin echo 'Last flushed at: ' . wp_kses_post( get_option('flush-cache-theme-plugin-time-stamp') ); } // Flush site object cache on page & post update checkbox function pressable_cache_management_callback_field_page_edit_checkbox($args) { $options = get_option('pressable_cache_management_options'); $id = isset($args['id']) ? $args['id'] : ''; $label = isset($args['label']) ? $args['label'] : ''; $checked = isset($options[$id]) ? checked($options[$id], 1, false) : ''; echo '
'; echo ''; // echo '
'; echo ''; echo '
'; echo '
'; //Display time stamp when object cache was last flushed when page or post was updated echo 'Last flushed at: ' . wp_kses_post( get_option('flush-cache-page-edit-time-stamp') ); } // Flush site object cache when page, post and posttypes are updated checkbox function pressable_cache_management_callback_field_page_post_delete_checkbox($args) { $options = get_option('pressable_cache_management_options'); $id = isset($args['id']) ? $args['id'] : ''; $label = isset($args['label']) ? $args['label'] : ''; $checked = isset($options[$id]) ? checked($options[$id], 1, false) : ''; echo '
'; echo ''; // echo '
'; echo ''; echo '
'; echo '
'; //Display time stamp when object cache was last flushed when page or post was deleted echo 'Last flushed at: ' . wp_kses_post( get_option('flush-cache-on-page-post-delete-time-stamp') ); } // Flush cache when comment is deleted checkbox function pressable_cache_management_callback_field_comment_delete_checkbox($args) { $options = get_option('pressable_cache_management_options'); $id = isset($args['id']) ? $args['id'] : ''; $label = isset($args['label']) ? $args['label'] : ''; $checked = isset($options[$id]) ? checked($options[$id], 1, false) : ''; echo '
'; echo ''; // echo '
'; echo ''; echo '
'; echo '
'; //Display time stamp when object cache was last flushed when comment was deleted echo 'Last flushed at: ' . wp_kses_post( get_option('flush-cache-on-comment-delete-time-stamp') ); } //Flush cache for a single page function pressable_cache_management_callback_field_flush_batcache_particular_page_checbox($args) { $options = get_option('pressable_cache_management_options'); $id = isset($args['id']) ? $args['id'] : ''; $label = isset($args['label']) ? $args['label'] : ''; $checked = isset($options[$id]) ? checked($options[$id], 1, false) : ''; echo '
'; echo ''; // echo '
'; echo ''; echo '
'; echo '
'; //Display time stamp when object cache was last flushed echo 'Last flushed at: ' . wp_kses_post( get_option('flush-object-cache-for-single-page-time-stamp') ); echo '
'; echo 'Page URL: ' . esc_html( get_option('single-page-url-flushed') ); } //Flush cache for WooCommerce product single page function pressable_cache_management_callback_field_flush_batcache_woo_product_page_checbox($args) { $options = get_option('pressable_cache_management_options'); $id = isset($args['id']) ? $args['id'] : ''; $label = isset($args['label']) ? $args['label'] : ''; $checked = isset($options[$id]) ? checked($options[$id], 1, false) : ''; echo '
'; echo ''; // echo '
'; echo ''; echo '
'; // echo 'Last purged Edge at: ' . (get_option('single-page-edge-cache-purge-time-stamp')) . ''; // echo '
'; } //Callback: text field to exempt individual page from batcache function pressable_cache_management_callback_field_exempt_batcache_text($args) { $options = get_option('pressable_cache_management_options'); $id = isset($args['id']) ? $args['id'] : ''; $label = isset($args['label']) ? $args['label'] : ''; $value = isset($options[$id]) ? sanitize_text_field($options[$id]) : ''; echo '
'; echo ''; } /* /** ******************************** * Edge Cache * * Management Tab * ******************************** **/ // Radio button options to turn on/off Edge Cache function pressable_cache_management_options_radio_edge_cache_button() { return array( 'enable' => esc_html__('Enable Edge Cache', 'pressable_cache_management') , ); } // AJAX handler function to check Edge Cache status on demand function pcm_ajax_check_edge_cache_status() { if (!current_user_can('manage_options')) { wp_send_json_error(['message' => 'Unauthorized'], 403); return; } // --- Transient cache: avoid hitting the Pressable API on every page load --- // Cache TTL: 5 minutes for enabled/disabled, 60 seconds for DDoS/unknown so // we recover quickly without hammering the API. $cache_key = 'pcm_ec_status_cache'; $cached = get_transient( $cache_key ); if ( $cached !== false ) { // Serve from cache — no API call needed wp_send_json_success([ 'enabled' => $cached['is_enabled'], 'status_text' => $cached['status_text'], 'status_flag' => $cached['status_flag'], 'from_cache' => true, 'html_controls_enable_disable' => pressable_cache_management_generate_enable_disable_content( $cached['is_enabled'] ), ]); return; } if ( ! class_exists('Edge_Cache_Plugin') ) { wp_send_json_error([ 'message' => 'Edge Cache dependency is not available.', 'html_controls_enable_disable' => '

' . esc_html__('Error: Edge Cache dependency is missing.', 'pressable_cache_management') . '

', ]); return; } $edge_cache = Edge_Cache_Plugin::get_instance(); $server_status = $edge_cache->get_ec_status(); // live API call $is_enabled = false; $status_text = 'Unknown'; $status_flag = 'Error'; $ttl = 60; // short TTL for unknown/error states if ( $server_status === Edge_Cache_Plugin::EC_ENABLED ) { $is_enabled = true; $status_text = 'Enabled'; $status_flag = 'Success'; $ttl = 300; // 5 minutes — stable state } elseif ( $server_status === Edge_Cache_Plugin::EC_DISABLED ) { $is_enabled = false; $status_text = 'Disabled'; $status_flag = 'Success'; $ttl = 300; // 5 minutes — stable state } elseif ( $server_status === Edge_Cache_Plugin::EC_DDOS ) { $status_text = 'Defensive Mode (DDoS)'; $status_flag = 'Warning'; $ttl = 60; // re-check sooner during DDoS mode } // Store in transient so subsequent page loads skip the API call set_transient( $cache_key, [ 'is_enabled' => $is_enabled, 'status_text' => $status_text, 'status_flag' => $status_flag, ], $ttl ); // Keep wp_options in sync for server-side badge rendering update_option('edge-cache-status', $status_flag); update_option('edge-cache-enabled', $is_enabled ? 'enabled' : 'disabled'); wp_send_json_success([ 'enabled' => $is_enabled, 'status_text' => $status_text, 'status_flag' => $status_flag, 'from_cache' => false, 'html_controls_enable_disable' => pressable_cache_management_generate_enable_disable_content( $is_enabled ), ]); } add_action('wp_ajax_pcm_check_edge_cache_status', 'pcm_ajax_check_edge_cache_status'); /** * Clear the edge cache status transient whenever the state changes * (enable, disable, purge) so the next request gets a fresh live value. */ function pcm_clear_ec_status_cache() { delete_transient( 'pcm_ec_status_cache' ); } add_action( 'pcm_after_edge_cache_enable', 'pcm_clear_ec_status_cache' ); add_action( 'pcm_after_edge_cache_disable', 'pcm_clear_ec_status_cache' ); add_action( 'pcm_after_edge_cache_purge', 'pcm_clear_ec_status_cache' ); add_action( 'pcm_after_defensive_mode_change','pcm_clear_ec_status_cache' ); /** * Helper function to generate only the Enable/Disable button form HTML. * * @param bool $is_enabled Whether the Edge Cache is currently enabled. * @return string The HTML containing only the Enable/Disable control. */ function pressable_cache_management_generate_enable_disable_content($is_enabled) { ob_start(); //Button form/label if ($is_enabled) { $id = 'disable_edge_cache_nonce'; $value = __('Disable Edge Cache', 'pressable_cache_management'); $submit_class = 'purgecacahe'; echo ''; echo '
'; echo ''; echo ''; echo ''; echo ''; echo '
'; } else { $id = 'enable_edge_cache_nonce'; $value = __('Enable Edge Cache', 'pressable_cache_management'); $submit_class = 'purgecacahe'; echo ''; echo '
'; echo ''; echo ''; echo ''; echo ''; echo '
'; } return ob_get_clean(); } // Renders the placeholder div and the synchronization script. function pressable_cache_management_callback_field_extend_edge_cache_radio_button($args) { // Renders the single placeholder div and the synchronization script. ?>
'; echo '
'; echo ''; echo '
'; echo '
'; // Display timestamp when object cache was last flushed echo '' . esc_html__( 'Last purged at:', 'pressable_cache_management' ) . ' ' . esc_html( get_option('edge-cache-purge-time-stamp') ); echo '
'; echo '
'; echo '' . esc_html__( 'Single URL last purged at:', 'pressable_cache_management' ) . ' ' . esc_html( get_option('single-page-edge-cache-purge-time-stamp') ); echo '
'; echo '' . esc_html__( 'Single URL:', 'pressable_cache_management' ) . ' ' . esc_html( get_option('edge-cache-single-page-url-purged') ); echo '
'; echo '
'; echo '

' . __('Purging cache will temporarily slow down your site for all visitors while the cache rebuilds.', 'pressable_cache_management'). '

'; } /** ******************************** * Remove Pressable * * Branding Tab * ******************************** * */ // Radio button options function pressable_cache_management_options_remove_branding_radio_button() { return array( 'enable' => esc_html__('Show Pressable Branding', 'pressable_cache_management') , 'disable' => esc_html__('Hide Pressable Branding', 'pressable_cache_management') ); } function pressable_cache_management_callback_field_extend_remove_branding_radio_button($args) { $options = get_option('remove_pressable_branding_tab_options'); $id = isset($args['id']) ? $args['id'] : ''; $label = isset($args['label']) ? $args['label'] : ''; $selected_option = isset($options[$id]) ? sanitize_text_field($options[$id]) : ''; $radio_options = pressable_cache_management_options_remove_branding_radio_button(); foreach ($radio_options as $value => $label) { $checked = checked($selected_option === $value, true, false); echo ''; echo ''; } }