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 / includes / class-wp-optimize-notices.php

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

394 lines 17.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('WPO_PLUGIN_MAIN_PATH')) die('No direct access allowed');
4
5 if (!class_exists('Updraft_Notices_1_2')) require_once(WPO_PLUGIN_MAIN_PATH.'/vendor/team-updraft/common-libs/src/updraft-notices/updraft-notices.php');
6
7 class WP_Optimize_Notices extends Updraft_Notices_1_2 {
8
9 protected static $_instance = null;
10
11 private $initialized = false;
12
13 protected $self_affiliate_id = 216;
14
15 protected $notices_content = array();
16
17 /**
18 * Creates and returns the only notice instance
19 *
20 * @return object WP_Optimize_Notices instance
21 */
22 public static function instance() {
23 if (empty(self::$_instance)) {
24 self::$_instance = new self();
25 }
26 return self::$_instance;
27 }
28
29 /**
30 * This method gets any parent notices and adds its own notices to the notice array
31 *
32 * @return Array returns an array of notices
33 */
34 protected function populate_notices_content() {
35
36 $parent_notice_content = parent::populate_notices_content();
37
38 $child_notice_content = array(
39 'updraftplus' => array(
40 'prefix' => '',
41 'title' => __('Make sure you backup before you optimize your database', 'wp-optimize'),
42 'text' => __("UpdraftPlus is the world's most trusted backup plugin from the owners of WP-Optimize", 'wp-optimize'),
43 'image' => 'notices/updraft_logo.png',
44 'button_link' => 'https://wordpress.org/plugins/updraftplus/',
45 'button_meta' => 'updraftplus',
46 'dismiss_time' => 'dismiss_page_notice_until',
47 'supported_positions' => $this->dashboard_top_or_report,
48 'validity_function' => 'is_updraftplus_installed',
49 ),
50 'updraftcentral' => array(
51 'prefix' => '',
52 'title' => __('Save Time and Money. Manage multiple WordPress sites from one location.', 'wp-optimize'),
53 'text' => __('UpdraftCentral is a highly efficient way to take backup, update and manage multiple WP sites from one location.', 'wp-optimize'),
54 'image' => 'notices/updraft_logo.png',
55 'button_link' => 'https://updraftcentral.com',
56 'button_meta' => 'updraftcentral',
57 'dismiss_time' => 'dismiss_page_notice_until',
58 'supported_positions' => $this->dashboard_top_or_report,
59 'validity_function' => 'is_updraftcentral_installed',
60 ),
61 'rate_plugin' => array(
62 'text' => __("Hey - We noticed WP-Optimize has kept your site running fast for a while. If you like us, please consider leaving a positive review to spread the word. Or if you have any issues or questions please leave us a support message", 'wp-optimize') . ' <a href="https://wordpress.org/support/plugin/wp-optimize/" target="_blank">' . __('here', 'wp-optimize') . '.</a><br>' . __('Thank you so much!', 'wp-optimize') . ' - <b>WP-Optimize</b><br>',
63 'image' => 'notices/ud_smile.png',
64 'button_link' => 'https://wordpress.org/support/plugin/wp-optimize/reviews/?rate=5#new-post',
65 'button_meta' => 'review',
66 'dismiss_time' => 'dismiss_review_notice',
67 'supported_positions' => $this->dashboard_top,
68 'validity_function' => 'show_rate_notice'
69 ),
70 'translation_needed' => array(
71 'prefix' => '',
72 'title' => 'Can you translate? Want to improve WP-Optimize for speakers of your language?',
73 'text' => $this->url_start(true, 'translate.wordpress.org/projects/wp-plugins/wp-optimize')."Please go here for instructions - it is easy.".$this->url_end(true, 'translate.wordpress.org/projects/wp-plugins/wp-optimize'),
74 'text_plain' => $this->url_start(false, 'translate.wordpress.org/projects/wp-plugins/wp-optimize')."Please go here for instructions - it is easy.".$this->url_end(false, 'translate.wordpress.org/projects/wp-plugins/wp-optimize'),
75 'image' => 'notices/wp_optimize_logo.png',
76 'button_link' => false,
77 'dismiss_time' => false,
78 'supported_positions' => $this->anywhere,
79 'validity_function' => 'translation_needed',
80 ),
81 'wpo-premium' => array(
82 'prefix' => '',
83 'title' => __("Perform optimizations while your visitors sleep", "wp-optimize"),
84 'text' => __("WP-Optimize Premium features an advanced scheduling system that allows you to run optimizations at the quietest time of day (or night).", "wp-optimize"),
85 'image' => 'notices/wp_optimize_logo.png',
86 'button_link' => 'https://getwpo.com',
87 'button_meta' => 'wpo-premium',
88 'dismiss_time' => 'dismiss_notice',
89 'supported_positions' => $this->anywhere,
90 'validity_function' => 'is_wpo_premium_installed',
91 ),
92 'wpo-premium-multisite' => array(
93 'prefix' => '',
94 'title' => __("Manage a multisite installation? Need extra control?", "wp-optimize"),
95 'text' => __("WP-Optimize Premium's multisite feature includes a locking system that restricts optimization commands to users with the right permissions.", "wp-optimize"),
96 'image' => 'notices/wp_optimize_logo.png',
97 'button_link' => 'https://getwpo.com',
98 'button_meta' => 'wpo-premium',
99 'dismiss_time' => 'dismiss_notice',
100 'supported_positions' => $this->anywhere,
101 'validity_function' => 'is_wpo_premium_installed',
102 ),
103 'wpo-premium2' => array(
104 'prefix' => '',
105 'title' => __("WP-Optimize Premium offers unparalleled choice and flexibility", "wp-optimize"),
106 'text' => __("Upgrade today to combine over a dozen optimization options.", "wp-optimize"),
107 'image' => 'notices/wp_optimize_logo.png',
108 'button_link' => 'https://getwpo.com',
109 'button_meta' => 'wpo-premium',
110 'dismiss_time' => 'dismiss_notice',
111 'supported_positions' => $this->anywhere,
112 'validity_function' => 'is_wpo_premium_installed',
113 ),
114 'wpo-premium3' => array(
115 'prefix' => '',
116 'title' => __("Remove unwanted images for better site performance.", "wp-optimize"),
117 'text' => __("WP-Optimize Premium comes with a feature to easily remove orphaned images, or images that exceed a certain size from your website.", "wp-optimize"),
118 'image' => 'notices/wp_optimize_logo.png',
119 'button_link' => 'https://getwpo.com',
120 'button_meta' => 'wpo-premium',
121 'dismiss_time' => 'dismiss_notice',
122 'supported_positions' => $this->anywhere,
123 'validity_function' => 'is_wpo_premium_installed',
124 ),
125 'wpo-power-tweaks' => array(
126 'prefix' => '',
127 'title' => __("Power tweaks for advanced users and better site performance.", "wp-optimize"),
128 'text' => __("WP-Optimize Premium comes with the power tweaks that will enable you to improve performance by targeting specific weak points, either in WordPress Core, or in popular plugins.", "wp-optimize"),
129 'image' => 'notices/wp_optimize_logo.png',
130 'button_link' => 'https://getwpo.com/faqs/#Power-tweaks-2-',
131 'button_meta' => 'wpo-premium',
132 'dismiss_time' => 'dismiss_notice',
133 'supported_positions' => $this->anywhere,
134 'validity_function' => 'is_wpo_premium_installed',
135 ),
136 'subscriben' => array(
137 'prefix' => '',
138 'title' => 'Subscriben ' .__('by', 'wp-optimize'). ' UpdraftPlus',
139 'text' => __("The WordPress subscription extension for WooCommerce store owners.", "wp-optimize"),
140 'image' => 'notices/subscriben.png',
141 'button_link' => 'https://subscribenplugin.com',
142 'button_meta' => 'read_more',
143 'dismiss_time' => 'dismiss_notice',
144 'supported_positions' => $this->anywhere,
145 ),
146
147 // The sale adverts content starts here
148 'blackfriday' => array(
149 'prefix' => '',
150 'title' => __('Black Friday - 20% off WP-Optimize Premium until November 30th', 'wp-optimize'),
151 'text' => __('To benefit, use this discount code:', 'wp-optimize').' ',
152 'image' => 'notices/black_friday.png',
153 'button_link' => 'https://getwpo.com',
154 'button_meta' => 'wp-optimize',
155 'dismiss_time' => 'dismiss_season',
156 'discount_code' => 'blackfridaysale2022',
157 'valid_from' => '2022-11-20 00:00:00',
158 'valid_to' => '2022-11-30 23:59:59',
159 'supported_positions' => $this->dashboard_top_or_report,
160 'validity_function' => 'is_wpo_premium_installed',
161 ),
162 'newyear' => array(
163 'prefix' => '',
164 'title' => __('Happy New Year - 20% off WP-Optimize Premium until January 14th', 'wp-optimize'),
165 'text' => __('To benefit, use this discount code:', 'wp-optimize').' ',
166 'image' => 'notices/new_year.png',
167 'button_link' => 'https://getwpo.com',
168 'button_meta' => 'wp-optimize',
169 'dismiss_time' => 'dismiss_season',
170 'discount_code' => 'newyearsale2023',
171 'valid_from' => '2022-12-26 00:00:00',
172 'valid_to' => '2023-01-14 23:59:59',
173 'supported_positions' => $this->dashboard_top_or_report,
174 'validity_function' => 'is_wpo_premium_installed',
175 ),
176 'spring' => array(
177 'prefix' => '',
178 'title' => __('Spring sale - 20% off WP-Optimize Premium until May 31st', 'wp-optimize'),
179 'text' => __('To benefit, use this discount code:', 'wp-optimize').' ',
180 'image' => 'notices/spring.png',
181 'button_link' => 'https://getwpo.com',
182 'button_meta' => 'wp-optimize',
183 'dismiss_time' => 'dismiss_season',
184 'discount_code' => 'springsale2022',
185 'valid_from' => '2022-05-01 00:00:00',
186 'valid_to' => '2022-05-31 23:59:59',
187 'supported_positions' => $this->dashboard_top_or_report,
188 'validity_function' => 'is_wpo_premium_installed',
189 ),
190 'summer' => array(
191 'prefix' => '',
192 'title' => __('Summer sale - 20% off WP-Optimize Premium until July 31st', 'wp-optimize'),
193 'text' => __('To benefit, use this discount code:', 'wp-optimize').' ',
194 'image' => 'notices/summer.png',
195 'button_link' => 'https://getwpo.com',
196 'button_meta' => 'wp-optimize',
197 'dismiss_time' => 'dismiss_season',
198 'discount_code' => 'summersale2022',
199 'valid_from' => '2022-07-01 00:00:00',
200 'valid_to' => '2022-07-31 23:59:59',
201 'supported_positions' => $this->dashboard_top_or_report,
202 'validity_function' => 'is_wpo_premium_installed',
203 ),
204 'collection' => array(
205 'prefix' => '',
206 'title' => __('The Updraft Plugin Collection Sale', 'wp-optimize'),
207 'text' => __('Get 20% off any of our plugins. But hurry - offer ends 30th September, use this discount code:', 'wp-optimize').' ',
208 'image' => 'notices/wp_optimize_logo.png',
209 'button_link' => 'https://teamupdraft.com',
210 'campaign' => 'collection',
211 'button_meta' => 'collection',
212 'dismiss_time' => 'dismiss_season',
213 'discount_code' => 'WPO2022',
214 'valid_from' => '2022-09-01 00:00:00',
215 'valid_to' => '2022-09-30 23:59:59',
216 'supported_positions' => $this->dashboard_top_or_report,
217 )
218 );
219
220 return array_merge($parent_notice_content, $child_notice_content);
221 }
222
223 /**
224 * Call this method to setup the notices
225 */
226 public function notices_init() {
227 if ($this->initialized) return;
228 $this->initialized = true;
229 $this->notices_content = (defined('WP_OPTIMIZE_NOADS_B') && WP_OPTIMIZE_NOADS_B) ? array() : $this->populate_notices_content();
230 }
231
232 /**
233 * This method will call the parent is_plugin_installed and pass in the product updraftplus to check if that plugin is installed if it is then we shouldn't display the notice
234 *
235 * @param string $product the plugin slug
236 * @param boolean $also_require_active a bool to indicate if the plugin should also be active
237 * @return boolean a bool to indicate if the notice should be displayed or not
238 */
239 protected function is_updraftplus_installed($product = 'updraftplus', $also_require_active = false) {
240 return parent::is_plugin_installed($product, $also_require_active);
241 }
242
243 /**
244 * This method will call the parent is_plugin_installed and pass in the product updraftcentral to check if that plugin is installed if it is then we shouldn't display the notice
245 *
246 * @param string $product the plugin slug
247 * @param boolean $also_require_active a bool to indicate if the plugin should also be active
248 * @return boolean a bool to indicate if the notice should be displayed or not
249 */
250 protected function is_updraftcentral_installed($product = 'updraftcentral', $also_require_active = false) {
251 return parent::is_plugin_installed($product, $also_require_active);
252 }
253
254 /**
255 * This method will call the is premium function in the WPO object to check if this install is premium and if it is we won't display the notice
256 *
257 * @return boolean a bool to indicate if we should display the notice or not
258 */
259 protected function is_wpo_premium_installed() {
260 if (WP_Optimize::is_premium()) {
261 return false;
262 }
263
264 return true;
265 }
266
267 /**
268 * This method will check to see if a number of different backup plugins are installed and if they are we won't display the notice
269 *
270 * @param String $product the plugin slug
271 * @param boolean $also_require_active a bool to indicate if the plugin should be active or not
272 * @return boolean a bool to indicate if the notice should be displayed or not
273 */
274 public function is_backup_plugin_installed($product = null, $also_require_active = false) {
275 $backup_plugins = array('updraftplus' => 'UpdraftPlus', 'backwpup' => 'BackWPup', 'backupwordpress' => 'BackupWordPress', 'vaultpress' => 'VaultPress', 'wp-db-backup' => 'WP-DB-Backup', 'backupbuddy' => 'BackupBuddy');
276
277 foreach ($backup_plugins as $slug => $title) {
278 if (!parent::is_plugin_installed($slug, $also_require_active)) {
279 return $title;
280 }
281 }
282
283 return apply_filters('wp_optimize_is_backup_plugin_installed', false);
284 }
285
286 /**
287 * This function will check if we should display the rate notice or not
288 *
289 * @return boolean - to indicate if we should show the notice or not
290 */
291 protected function show_rate_notice() {
292
293 $options = WP_Optimize()->get_options();
294 $installed = $options->get_option('installed-for', 0);
295 $installed_for = time() - $installed;
296
297 if ($installed && $installed_for > 28*86400) {
298 return true;
299 }
300
301 return false;
302 }
303
304 /**
305 * This method calls the parent verson and will work out if the user is using a non english language and if so returns true so that they can see the translation advert.
306 *
307 * @param String $plugin_base_dir the plugin base directory
308 * @param String $product_name the name of the plugin
309 * @return Boolean returns true if the user is using a non english language and could translate otherwise false
310 */
311 protected function translation_needed($plugin_base_dir = null, $product_name = null) {// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
312 return parent::translation_needed(WPO_PLUGIN_MAIN_PATH, 'wp-optimize');
313 }
314
315 /**
316 * This method is used to generate the correct URL output for the start of the URL
317 *
318 * @param Boolean $html_allowed a boolean value to indicate if HTML can be used or not
319 * @param String $url the url to use
320 * @param Boolean $https a boolean value to indicate if https should be used or not
321 * @param String $website_home a string to be displayed
322 * @return String returns a string of the completed url
323 */
324 protected function url_start($html_allowed, $url, $https = false, $website_home = 'getwpo.com') {
325 return parent::url_start($html_allowed, $url, $https, $website_home);
326 }
327
328 /**
329 * This method checks to see if the notices dismiss_time parameter has been dismissed
330 *
331 * @param String $dismiss_time a string containing the dimiss time ID
332 * @return Boolean returns true if the notice has been dismissed and shouldn't be shown otherwise display it
333 */
334 protected function check_notice_dismissed($dismiss_time) {
335
336 $time_now = (defined('WP_OPTIMIZE_NOTICES_FORCE_TIME') ? WP_OPTIMIZE_NOTICES_FORCE_TIME : time());
337
338 $options = WP_Optimize()->get_options();
339
340 $notice_dismiss = ($time_now < $options->get_option($dismiss_time, 0));
341
342 return $notice_dismiss;
343 }
344
345 /**
346 * Check notice data for seasonal info and return true if we should display this notice.
347 *
348 * @param array $notice_data
349 * @return bool
350 */
351 protected function skip_seasonal_notices($notice_data) {
352 $time_now = defined('WPO_NOTICES_FORCE_TIME') ? WPO_NOTICES_FORCE_TIME : time();
353 // Do not show seasonal notices in Premium version.
354 if (false === WP_Optimize::is_premium()) {
355 $valid_from = strtotime($notice_data['valid_from']);
356 $valid_to = strtotime($notice_data['valid_to']);
357 $dismiss = $this->check_notice_dismissed($notice_data['dismiss_time']);
358 if (($time_now >= $valid_from && $time_now <= $valid_to) && !$dismiss) {
359 // return true so that we return this notice to be displayed
360 return true;
361 }
362 }
363
364 return false;
365 }
366
367 /**
368 * This method will create the chosen notice and the template to use and depending on the parameters either echo it to the page or return it
369 *
370 * @param Array $advert_information an array with the notice information in
371 * @param Boolean $return_instead_of_echo a bool value to indicate if the notice should be printed to page or returned
372 * @param String $position a string to indicate what template should be used
373 * @return String a notice to display
374 */
375 protected function render_specified_notice($advert_information, $return_instead_of_echo = false, $position = 'top') {
376
377 if ('bottom' == $position) {
378 $template_file = 'bottom-notice.php';
379 } elseif ('report' == $position) {
380 $template_file = 'report.php';
381 } elseif ('report-plain' == $position) {
382 $template_file = 'report-plain.php';
383 } else {
384 $template_file = 'horizontal-notice.php';
385 }
386
387 $extract_variables = array_merge($advert_information, array('wp_optimize_notices' => $this));
388
389 return WP_Optimize()->include_template('notices/'.$template_file, $return_instead_of_echo, $extract_variables);
390 }
391 }
392
393 $GLOBALS['wp_optimize_notices'] = WP_Optimize_Notices::instance();
394