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

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