PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.7
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.7
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-wp-optimize-minify-preloader.php

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

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