PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.3
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.3
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / minify / class-wpo-minify-preloader.php

class-wpo-minify-preloader.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 3.2.3, at minify/class-wpo-minify-preloader.php

167 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('ABSPATH')) die('No direct access allowed');
4
5
6 if (!class_exists('WP_Optimize_Minify_Load_Url_Task')) require_once(dirname(__FILE__) . '/class-wpo-minify-load-url-task.php');
7
8 if (!class_exists('WP_Optimize_Preloader')) require_once(WPO_PLUGIN_MAIN_PATH . 'includes/class-wpo-preloader.php');
9
10 class WP_Optimize_Minify_Preloader extends WP_Optimize_Preloader {
11
12 protected $preload_type = 'minify';
13
14 protected $task_type = 'minify-load-url-task';
15
16 static protected $_instance = null;
17
18 /**
19 * WP_Optimize_Page_Cache_Preloader constructor.
20 */
21 public function __construct() {
22 parent::__construct();
23
24 add_filter('cron_schedules', array($this, 'cron_add_intervals'));
25 }
26
27 /**
28 * Check if minify is active.
29 *
30 * @return bool
31 */
32 public function is_option_active() {
33 if (!function_exists('wp_optimize_minify_config')) {
34 include_once WPO_PLUGIN_MAIN_PATH . '/minify/class-wp-optimize-minify-config.php';
35 }
36 return wp_optimize_minify_config()->get('enabled');
37 }
38
39 /**
40 * Add intervals to cron schedules.
41 *
42 * @param array $schedules
43 *
44 * @return array
45 */
46 public function cron_add_intervals($schedules) {
47 $interval = $this->get_continue_preload_cron_interval();
48 $schedules['wpo_minify_preload_continue_interval'] = array(
49 'interval' => $interval,
50 'display' => round($interval / 60, 1).' minutes'
51 );
52
53 return $schedules;
54 }
55
56 /**
57 * Create tasks (WP_Optimize_Load_Url_Task) for preload all urls from site.
58 *
59 * @param string $type The preload type (currently: scheduled, manual)
60 * @return void
61 */
62 public function create_tasks_for_preload_site_urls($type = 'manual') {
63 $urls = $this->get_site_urls();
64
65 if (!empty($urls)) {
66
67 $this->log(__('Minify: Creating tasks for preload site urls.', 'wp-optimize'));
68
69 foreach ($urls as $url) {
70 if (wpo_url_in_exceptions($url)) continue;
71
72 // this description is being used for internal purposes.
73 $description = 'Preload - '.$url;
74 $options = array('url' => $url, 'preload_type' => $type, 'anonymous_user_allowed' => (defined('DOING_CRON') && DOING_CRON) || (defined('WP_CLI') && WP_CLI));
75
76 WP_Optimize_Minify_Load_Url_Task::create_task($this->task_type, $description, $options, 'WP_Optimize_Minify_Load_Url_Task');
77 }
78
79 $this->log(__('Minify: Tasks for preload site urls created.', 'wp-optimize'));
80 }
81 }
82
83 /**
84 * Instance of WP_Optimize_Minify_Preloader.
85 *
86 * @return WP_Optimize_Minify_Preloader
87 */
88 public static function instance() {
89 if (empty(self::$_instance)) {
90 self::$_instance = new WP_Optimize_Minify_Preloader();
91 }
92
93 return self::$_instance;
94 }
95
96 /**
97 * Option disabled error message
98 *
99 * @return array
100 */
101 protected function get_option_disabled_error() {
102 return array(
103 'success' => false,
104 'error' => __('Minify is disabled.', 'wp-optimize')
105 );
106 }
107
108 /**
109 * Get preload already running error message
110 *
111 * @return array
112 */
113 protected function get_preload_already_running_error() {
114 return array(
115 'success' => false,
116 'error' => __('Probably minify preload is running already.', 'wp-optimize')
117 );
118 }
119
120 protected function get_preload_data() {
121 $cache_path = WP_Optimize_Minify_Cache_Functions::cache_path();
122 $cache_dir = $cache_path['cachedir'];
123 $minify_cache_data = array();
124 $minify_cache_data['size'] = esc_html(WP_Optimize_Minify_Cache_Functions::get_cachestats($cache_dir));
125 $minify_cache_data['total_size'] = esc_html(WP_Optimize_Minify_Cache_Functions::get_cachestats(WPO_CACHE_MIN_FILES_DIR));
126 return $minify_cache_data;
127 }
128
129 protected function get_preloading_message($minify_cache_data) {
130 return array(
131 'done' => false,
132 'message' => __('Loading URLs...', 'wp-optimize'),
133 'size' => WP_Optimize()->format_size($minify_cache_data['size']),
134 'total_size' => $minify_cache_data['total_size']
135 );
136 }
137
138 protected function get_last_preload_message($minify_cache_data, $last_preload_time_str) {
139 return array(
140 'done' => true,
141 'message' => sprintf(__('Last preload finished at %s', 'wp-optimize'), $last_preload_time_str),
142 'size' => WP_Optimize()->format_size($minify_cache_data['size']),
143 'total_size' => $minify_cache_data['total_size']
144 );
145 }
146
147 protected function get_preload_success_message($minify_cache_data) {
148 return array(
149 'done' => true,
150 'size' => WP_Optimize()->format_size($minify_cache_data['size']),
151 'total_size' => $minify_cache_data['total_size']
152 );
153 }
154
155 protected function get_preload_progress_message($minify_cache_data, $preloaded_message, $preload_resuming_in) {
156 return array(
157 'done' => false,
158 'message' => $preloaded_message,
159 'size' => WP_Optimize()->format_size($minify_cache_data['size']),
160 'total_size' => $minify_cache_data['total_size'],
161 'resume_in' => $preload_resuming_in
162 );
163 }
164 }
165
166 WP_Optimize_Minify_Preloader::instance();
167