get_page_cache()->is_enabled() || !current_user_can(WP_Optimize()->capability_required())) return $actions; if ('publish' !== $post->post_status) return $actions; $post_id = $post->ID; $url = get_permalink($post_id); $path = WPO_Page_Cache::get_full_path_from_url($url); if (WPO_Page_Cache::is_cache_empty($path)) { $text = __('Preload cache', 'wp-optimize'); $actions['wpo_preload_cache'] = $this->get_preload_link($post_id, $text); } return $actions; } /** * Preload post/page of given ID * * @param int $post_id * @return bool */ public function single_page_cache_preload($post_id) { $url = get_permalink($post_id); if (!defined('WPO_CACHE_FILES_DIR') || empty($url)) return false; $preloader = WP_Optimize_Page_Cache_Preloader::instance(); $preloader->preload_desktop($url); $preloader->preload_mobile($url); $preloader->preload_amp($url); $path = WPO_Page_Cache::get_full_path_from_url($url); return !WPO_Page_Cache::is_cache_empty($path); } /** * Gets preload link html * * @param int $post_id Post ID * @param string $text Anchor text of the link * * @return string */ private function get_preload_link($post_id, $text) { return sprintf('%2$s', esc_attr($post_id), esc_html($text)); } } endif;