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

332 lines 15.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 if (!class_exists('Updraft_Notices_1_3')) 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_3 {
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 // translators: %1$s are bold html tags to make some of the text bold, %2$s are closing tags
38 $sale_description = sprintf(__('Make your site even %1$s faster with Premium %2$s.', 'wp-optimize'), '<b>', '</b>') . ' ';
39 // translators: %1$s are bold html tags to make some of the text bold, %2$s are closing tags
40 $sale_description .= sprintf(__('Identify orphaned images, load pages faster and get %1$s premium support %2$s.', 'wp-optimize'), '<b>', '</b>') . ' ';
41 $sale_description .= __('Get advanced options, like the ability to optimize your site using WP-CLI.', 'wp-optimize') . ' ';
42 // translators: %1$s are bold html tags to make some of the text bold, %2$s are closing tags
43 $sale_description .= sprintf(__('Premium is %1$s compatible with WordPress multisite, WooCommerce and other add-ons %2$s, including multilingual and multi-currency WordPress plugins.', 'wp-optimize'), '<b>', '</b>');
44 $sale_description .= '<br>';
45
46 $bf_checkout_html = '<b><a href="https://teamupdraft.com/plugin-black-friday/?utm_source=udp-plugin&utm_medium=referral&utm_campaign=bf25-udp-plugin-banner&utm_content=bf-sale&utm_creative_format=advert" target="_blank">'.__('Save 20% with code blackfridaysale2025', 'wp-optimize').'</a></b>';
47
48 $child_notice_content = array(
49 'updraftplus' => array(
50 'prefix' => '',
51 'title' => __('Make sure you backup before you optimize your database', 'wp-optimize'),
52 'text' => __("UpdraftPlus is the world's most trusted backup plugin, from the owners of WP-Optimize.", 'wp-optimize'),
53 'image' => 'notices/updraft_logo.png',
54 'button_link' => 'https://wordpress.org/plugins/updraftplus/',
55 'button_meta' => 'updraftplus',
56 'dismiss_time' => 'dismiss_page_notice_until',
57 'supported_positions' => $this->dashboard_top_or_report,
58 'validity_function' => 'is_updraftplus_installed',
59 ),
60 'updraftcentral' => array(
61 'prefix' => '',
62 'title' => __('Save time and money.', 'wp-optimize') . ' ' . __('Manage multiple sites from one location.', 'wp-optimize'),
63 'text' => __('Back up, update and manage multiple WordPress websites centrally.', 'wp-optimize'),
64 'image' => 'notices/updraft_central_logo.png',
65 'button_link' => 'https://teamupdraft.com/updraftcentral/?utm_source=wpo-plugin&utm_medium=referral&utm_campaign=paac&utm_content=updraftcentral&utm_creative_format=advert',
66 'button_meta' => 'updraftcentral',
67 'dismiss_time' => 'dismiss_page_notice_until',
68 'supported_positions' => $this->dashboard_top_or_report,
69 'validity_function' => 'is_updraftcentral_installed',
70 ),
71 'rate_plugin' => array(
72 // translators: %1$s is an anchor tag to WP-Optimize support forum, %2$s is closing tags
73 'text' => __("We noticed WP-Optimize has kept your site running fast for a while.", 'wp-optimize') . ' ' . __('If you like us, please consider leaving us a positive review.', 'wp-optimize') . ' ' . sprintf(__('If you have any issues or questions please contact %1$s support. %2$s', 'wp-optimize'), '<a href="https://wordpress.org/support/plugin/wp-optimize/" target="_blank">', '</a><br>') . __('Thank you so much!', 'wp-optimize'),
74 'image' => 'notices/wp_optimize_logo.png',
75 'button_link' => 'https://wordpress.org/support/plugin/wp-optimize/reviews/?rate=5#new-post',
76 'button_meta' => 'review',
77 'dismiss_time' => 'dismiss_review_notice',
78 'supported_positions' => $this->dashboard_top,
79 'validity_function' => 'show_rate_notice'
80 ),
81 'translation_needed' => array(
82 'prefix' => '',
83 'title' => 'Can you translate?',
84 'text' => __("Want to improve WP-Optimize for speakers of your language? Go here for instructions", 'wp-optimize'),
85 'image' => 'notices/wp_optimize_logo.png',
86 'button_link' => 'https://teamupdraft.com/translate-for-us?utm_source=wpo-plugin&utm_medium=referral&utm_campaign=paac&utm_content=translate&utm_creative_format=advert',
87 'button_meta' => 'translate',
88 'dismiss_time' => false,
89 'supported_positions' => $this->anywhere,
90 'validity_function' => 'translation_needed',
91 ),
92 'wpo-premium' => array(
93 'prefix' => '',
94 'title' => __("Perform optimizations while your visitors sleep", "wp-optimize"),
95 'text' => __("Schedule optimizations for set times e.g. overnight when server resources are high.", "wp-optimize"),
96 'image' => 'notices/wp_optimize_logo.png',
97 'button_link' => 'https://teamupdraft.com/wp-optimize/features?utm_source=wpo-plugin&utm_medium=referral&utm_campaign=paac&utm_content=while-they-sleep&utm_creative_format=advert',
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-premium-multisite' => array(
104 'prefix' => '',
105 'title' => __("Manage a multisite installation?", "wp-optimize"),
106 'text' => __("Optimize any site (or combination of sites) on the multisite network.", "wp-optimize") . ' ' . __("Give the right permissions to the right users.", "wp-optimize"),
107 'image' => 'notices/wp_optimize_logo.png',
108 'button_link' => 'https://teamupdraft.com/wp-optimize/features?utm_source=wpo-plugin&utm_medium=referral&utm_campaign=paac&utm_content=multisite&utm_creative_format=advert',
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://teamupdraft.com/wp-optimize/features?utm_source=wpo-plugin&utm_medium=referral&utm_campaign=paac&utm_content=unwanted-images&utm_creative_format=advert',
120 'button_meta' => 'wpo-premium',
121 'dismiss_time' => 'dismiss_notice',
122 'supported_positions' => $this->anywhere,
123 'validity_function' => 'is_wpo_premium_installed',
124 ),
125 'aios' => array(
126 'prefix' => '',
127 'title' => __('Secure your site', 'wp-optimize'),
128 // translators: %1$s is the name of plugin and %2$s is the name of the team
129 'text' => sprintf(__('The %1$s plugin from %2$s.', 'wp-optimize'), '"All-In-One" Security', 'TeamUpdraft'),
130 'image' => 'notices/aios_logo.png',
131 'button_link' => 'https://teamupdraft.com/all-in-one-security/?utm_source=wpo-plugin&utm_medium=referral&utm_campaign=paac&utm_content=aios&utm_creative_format=advert',
132 'button_meta' => 'aios',
133 'dismiss_time' => 'dismiss_notice',
134 'supported_positions' => $this->anywhere,
135 ),
136
137 // The sale adverts content starts here
138 'blackfriday' => array(
139 'prefix' => '',
140 'title' => __('20% off - Black Friday Sale', 'wp-optimize'),
141 // translators: %s is a link to pricing/check out page
142 'text' => $sale_description . '<br>' . sprintf(__('%s at checkout.', 'wp-optimize'), $bf_checkout_html) . ' <b>' . __('Hurry, offer ends 2 December.', 'wp-optimize') . '</b>',
143 'image' => 'notices/wpo_sale_icon.png',
144 'button_link' => 'https://teamupdraft.com/plugin-black-friday/?utm_source=udp-plugin&utm_medium=referral&utm_campaign=bf25-udp-plugin-banner&utm_content=bf-sale&utm_creative_format=advert',
145 'button_meta' => 'no-button',
146 'dismiss_time' => 'dismiss_season',
147 // 'discount_code' => 'blackfridaysale2022',
148 'valid_from' => '2025-11-14 00:00:00',
149 'valid_to' => '2025-12-02 23:59:59',
150 'supported_positions' => $this->dashboard_top_or_report,
151 'validity_function' => 'is_wpo_premium_installed',
152 ),
153 );
154
155 return array_merge($parent_notice_content, $child_notice_content);
156 }
157
158 /**
159 * Call this method to set up the notices
160 */
161 public function notices_init() {
162 if ($this->initialized) return;
163 $this->initialized = true;
164 $this->notices_content = (defined('WP_OPTIMIZE_NOADS_B') && WP_OPTIMIZE_NOADS_B) ? array() : $this->populate_notices_content();
165 }
166
167 /**
168 * 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
169 *
170 * @param string $product the plugin slug
171 * @param boolean $also_require_active a bool to indicate if the plugin should also be active
172 * @return boolean a bool to indicate if the notice should be displayed or not
173 */
174 protected function is_updraftplus_installed($product = 'updraftplus', $also_require_active = false) {
175 return parent::is_plugin_installed($product, $also_require_active);
176 }
177
178 /**
179 * 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
180 *
181 * @param string $product the plugin slug
182 * @param boolean $also_require_active a bool to indicate if the plugin should also be active
183 * @return boolean a bool to indicate if the notice should be displayed or not
184 */
185 protected function is_updraftcentral_installed($product = 'updraftcentral', $also_require_active = false) {
186 return parent::is_plugin_installed($product, $also_require_active);
187 }
188
189 /**
190 * This method will call the is premium function in the WPO object to check if this installation is premium and if it is we won't display the notice
191 *
192 * @return boolean a bool to indicate if we should display the notice or not
193 */
194 protected function is_wpo_premium_installed() {
195 if (WP_Optimize::is_premium()) {
196 return false;
197 }
198
199 return true;
200 }
201
202 /**
203 * 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
204 *
205 * @param ?string $product the plugin slug
206 * @param boolean $also_require_active a bool to indicate if the plugin should be active or not
207 * @return boolean a bool to indicate if the notice should be displayed or not
208 */
209 public function is_backup_plugin_installed(?string $product = null, bool $also_require_active = false): bool {
210 $backup_plugins = array('updraftplus' => 'UpdraftPlus', 'backwpup' => 'BackWPup', 'backupwordpress' => 'BackupWordPress', 'vaultpress' => 'VaultPress', 'wp-db-backup' => 'WP-DB-Backup', 'backupbuddy' => 'BackupBuddy');
211
212 foreach ($backup_plugins as $slug => $title) {
213 if (!parent::is_plugin_installed($slug, $also_require_active)) {
214 return $title;
215 }
216 }
217
218 return apply_filters('wp_optimize_is_backup_plugin_installed', false);
219 }
220
221 /**
222 * This function will check if we should display the rate notice or not
223 *
224 * @return boolean - to indicate if we should show the notice or not
225 */
226 protected function show_rate_notice() {
227
228 $options = WP_Optimize()->get_options();
229 $installed = $options->get_option('installed-for', 0);
230 $installed_for = time() - $installed;
231
232 if ($installed && $installed_for > 28*86400) {
233 return true;
234 }
235
236 return false;
237 }
238
239 /**
240 * 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.
241 *
242 * @param ?string $plugin_base_dir the plugin base directory
243 * @param ?string $product_name the name of the plugin
244 * @return boolean returns true if the user is using a non english language and could translate otherwise false
245 */
246 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
247 return parent::translation_needed(WPO_PLUGIN_MAIN_PATH, 'wp-optimize');
248 }
249
250 /**
251 * This method is used to generate the correct URL output for the start of the URL
252 *
253 * @param boolean $html_allowed a boolean value to indicate if HTML can be used or not
254 * @param string $url the url to use
255 * @param boolean $https a boolean value to indicate if https should be used or not
256 * @param string $website_home a string to be displayed
257 * @return string returns a string of the completed url
258 */
259 protected function url_start($html_allowed, $url, $https = false, $website_home = 'teamupdraft.com/wp-optimize/') {
260 return parent::url_start($html_allowed, $url, $https, $website_home);
261 }
262
263 /**
264 * This method checks to see if the notices dismiss_time parameter has been dismissed
265 *
266 * @param string $dismiss_time a string containing the dismiss time ID
267 * @return boolean returns true if the notice has been dismissed and shouldn't be shown otherwise display it
268 */
269 protected function check_notice_dismissed($dismiss_time) {
270
271 $time_now = (defined('WP_OPTIMIZE_NOTICES_FORCE_TIME') ? WP_OPTIMIZE_NOTICES_FORCE_TIME : time());
272
273 $options = WP_Optimize()->get_options();
274
275 $notice_dismiss = ($time_now < $options->get_option($dismiss_time, 0));
276
277 return $notice_dismiss;
278 }
279
280 /**
281 * Check notice data for seasonal info and return true if we should display this notice.
282 *
283 * @param array $notice_data
284 * @return bool
285 */
286 protected function skip_seasonal_notices($notice_data) {
287 $time_now = defined('WPO_NOTICES_FORCE_TIME') ? WPO_NOTICES_FORCE_TIME : time();
288 // Do not show seasonal notices in Premium version.
289 if (false === WP_Optimize::is_premium()) {
290 $valid_from = strtotime($notice_data['valid_from']);
291 $valid_to = strtotime($notice_data['valid_to']);
292 $dismiss = $this->check_notice_dismissed($notice_data['dismiss_time']);
293 if (($time_now >= $valid_from && $time_now <= $valid_to) && !$dismiss) {
294 // return true so that we return this notice to be displayed
295 return true;
296 }
297 }
298
299 return false;
300 }
301
302 /**
303 * 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
304 *
305 * @param array $advert_information an array with the notice information in
306 * @param boolean $return_instead_of_echo a bool value to indicate if the notice should be printed to page or returned
307 * @param string $position a string to indicate what template should be used
308 * @return ?string a notice to display
309 */
310 protected function render_specified_notice($advert_information, $return_instead_of_echo = false, $position = 'top') {
311
312 if ('bottom' === $position) {
313 $template_file = 'bottom-notice.php';
314 } elseif ('report' === $position) {
315 $template_file = 'report.php';
316 } elseif ('report-plain' === $position) {
317 $template_file = 'report-plain.php';
318 } else {
319 $template_file = 'horizontal-notice.php';
320 }
321
322 $extract_variables = array_merge($advert_information, array('wp_optimize_notices' => $this));
323
324 return WP_Optimize()->include_template('notices/'.$template_file, $return_instead_of_echo, $extract_variables);
325 }
326
327 protected function widget_enqueue() {
328 }
329 }
330
331 $GLOBALS['wp_optimize_notices'] = WP_Optimize_Notices::instance();
332