should_exclude($post);
if ($exclusion_reason) {
return new WP_Error('excluded', $exclusion_reason);
}
// Get the permalink
$url = get_permalink($post_id);
if (!$url) {
return new WP_Error('no_permalink', __('Could not get permalink for post', 'wp-to-html'));
}
// Fetch the rendered page
$response = wp_remote_get($url, array(
'timeout' => 30,
'sslverify' => false,
'cookies' => array(), // No cookies to get the logged-out version
));
if (is_wp_error($response)) {
return $response;
}
$html = wp_remote_retrieve_body($response);
$status_code = wp_remote_retrieve_response_code($response);
if ($status_code !== 200) {
return new WP_Error('bad_response', sprintf(__('Received HTTP %d response', 'wp-to-html'), $status_code));
}
if (empty($html)) {
return new WP_Error('empty_response', __('Received empty response', 'wp-to-html'));
}
// Get the cache path for this URL
$cache_path = $this->get_cache_path($url);
// Create directory if it doesn't exist
$cache_dir = dirname($cache_path);
if (!file_exists($cache_dir)) {
wp_mkdir_p($cache_dir);
}
// Bundle CSS and JS assets if enabled
$assets = WP_To_HTML_Assets::get_instance();
$html = $assets->bundle_assets($html, $post_id, $url);
// Add cache generation comment to HTML
$timestamp = current_time('mysql');
$cache_comment = "\n";
$html = preg_replace('/<\/html>/i', $cache_comment . "\n