' . 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 '' . 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 ''; } else { $id = 'enable_edge_cache_nonce'; $value = __('Enable Edge Cache', 'pressable_cache_management'); $submit_class = 'purgecacahe'; 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. ?>' . __('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 ''; } }