PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.21
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.21
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.21, at includes/class-wp-optimize-notices.php

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