'error', 'msg' => 'Invalid page url.']); exit; } // Download the HTML $response = wp_remote_get($html_url, ['timeout' => 60, 'redirection' => 0]); $response_code = wp_remote_retrieve_response_code($response); // Check for errors if (is_wp_error($response) || $response_code !== 200) { $berq_log->info("Failed to download cache: $page_url"); echo json_encode(['status' => 'error', 'msg' => 'Could not download html cache']); exit; } $html = wp_remote_retrieve_body($response); // Allow other plugins to modify cache html $html = apply_filters('berqwp_cache_buffer', $html); if (empty($license_key_hash) || empty($license_key) || $license_key_hash !== md5($license_key)) { echo json_encode(['status' => 'error', 'msg' => 'Request authentication failed']); http_response_code(403); exit; } if (empty($html)) { $berq_log->info("Empty html cache: $page_url"); echo json_encode(['status' => 'error', 'msg' => 'Empty html cache']); exit; } $cache = new Cache(null, bwp_get_cache_dir()); $cache->store_cache($page_url, $html); do_action('berqwp_stored_page_cache', $page_slug); $berq_log->info("Stored cache for $page_url"); // Cache is stored which means connection is stable // Delete connection test error transient $check_connection = bwp_check_connection(); if ($check_connection['status'] == 'error') { delete_transient('berqwp_connection_status'); } echo json_encode(['status' => 'success']); exit; } }