PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 2.2.11
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v2.2.11
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 3.8.0 All 110 releases
wp-optimize / includes / wp-optimize-notices.php

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

397 lines 17.3 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_0')) require_once(WPO_PLUGIN_MAIN_PATH.'/includes/updraft-notices.php');
6
7 class WP_Optimize_Notices extends Updraft_Notices_1_0 {
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 a 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 'prefix' => '',
63 'title' => __('Like WP-Optimize and can spare one minute?', 'wp-optimize'),
64 'text' => __('Please help WP-Optimize by giving a positive review at wordpress.org.', 'wp-optimize'),
65 'image' => 'notices/wp_optimize_logo.png',
66 'button_link' => 'https://wordpress.org/support/plugin/wp-optimize/reviews/?rate=5#new-post',
67 'button_meta' => 'review',
68 'dismiss_time' => 'dismiss_page_notice_until',
69 'supported_positions' => $this->anywhere,
70 ),
71 'translation_needed' => array(
72 'prefix' => '',
73 'title' => 'Can you translate? Want to improve WP-Optimize for speakers of your language?',
74 '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'),
75 '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'),
76 'image' => 'notices/wp_optimize_logo.png',
77 'button_link' => false,
78 'dismiss_time' => false,
79 'supported_positions' => $this->anywhere,
80 'validity_function' => 'translation_needed',
81 ),
82 'keyy' => array(
83 'prefix' => '',
84 'title' => 'Keyy: Instant and secure logon with a wave of your phone',
85 'text' => __("Find out more about our revolutionary new WordPress plugin.", "wp-optimize") . $this->url_end(true, 'getkeyy.com'),
86 'image' => 'notices/keyy_logo.png',
87 'dismiss_time' => 'dismiss_notice',
88 'supported_positions' => $this->anywhere,
89 'validity_function' => 'is_keyy_installed',
90 ),
91 'wpo-premium' => array(
92 'prefix' => '',
93 'title' => __("Perform optimizations while your visitors sleep", "wp-optimize"),
94 '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"),
95 'image' => 'notices/wp_optimize_logo.png',
96 'button_link' => 'https://getwpo.com',
97 'button_meta' => 'wpo-premium',
98 'dismiss_time' => 'dismiss_notice',
99 'supported_positions' => $this->anywhere,
100 'validity_function' => 'is_wpo_premium_installed',
101 ),
102 'wpo-premium-multisite' => array(
103 'prefix' => '',
104 'title' => __("Manage a multisite installation? Need extra control?", "wp-optimize"),
105 'text' => __("WP-Optimize Premium's multisite feature includes a locking system that restricts optimization commands to users with the right permissions.", "wp-optimize"),
106 'image' => 'notices/wp_optimize_logo.png',
107 'button_link' => 'https://getwpo.com',
108 'button_meta' => 'wpo-premium',
109 'dismiss_time' => 'dismiss_notice',
110 'supported_positions' => $this->anywhere,
111 'validity_function' => 'is_wpo_premium_installed',
112 ),
113 'wpo-premium2' => array(
114 'prefix' => '',
115 'title' => __("WP-Optimize Premium offers unparalleled choice and flexibility", "wp-optimize"),
116 'text' => __("Upgrade today to combine over a dozen optimization options.", "wp-optimize"),
117 'image' => 'notices/wp_optimize_logo.png',
118 'button_link' => 'https://getwpo.com',
119 'button_meta' => 'wpo-premium',
120 'dismiss_time' => 'dismiss_notice',
121 'supported_positions' => $this->anywhere,
122 'validity_function' => 'is_wpo_premium_installed',
123 ),
124 'wpo-premium3' => array(
125 'prefix' => '',
126 'title' => __("Remove unwanted images for better site performance.", "wp-optimize"),
127 '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"),
128 'image' => 'notices/wp_optimize_logo.png',
129 'button_link' => 'https://getwpo.com',
130 'button_meta' => 'wpo-premium',
131 'dismiss_time' => 'dismiss_notice',
132 'supported_positions' => $this->anywhere,
133 'validity_function' => 'is_wpo_premium_installed',
134 ),
135 'meta-slider' => array(
136 'prefix' => '',
137 'title' => __("MetaSlider: the world's #1 slider plugin from the makers of WP-Optimize", "wp-optimize"),
138 'text' => __("With MetaSlider, you can easily add style and flare with beautifully-designed sliders.", "wp-optimize"),
139 'button_link' => 'https://metaslider.com',
140 'button_meta' => 'metaslider',
141 'image' => 'notices/metaslider_logo.png',
142 'dismiss_time' => 'dismiss_notice',
143 'supported_positions' => $this->anywhere,
144 'validity_function' => 'is_metaslider_installed',
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' => 'blackfridaysale2018',
157 'valid_from' => '2018-11-20 00:00:00',
158 'valid_to' => '2018-11-30 23:59:59',
159 'supported_positions' => $this->dashboard_top_or_report,
160 ),
161 'christmas' => array(
162 'prefix' => '',
163 'title' => __('Christmas sale - 20% off WP-Optimize Premium until December 25th', 'wp-optimize'),
164 'text' => __('To benefit, use this discount code:', 'wp-optimize').' ',
165 'image' => 'notices/christmas.png',
166 'button_link' => 'https://getwpo.com',
167 'button_meta' => 'wp-optimize',
168 'dismiss_time' => 'dismiss_season',
169 'discount_code' => 'christmassale2018',
170 'valid_from' => '2018-12-01 00:00:00',
171 'valid_to' => '2018-12-25 23:59:59',
172 'supported_positions' => $this->dashboard_top_or_report,
173 ),
174 'newyear' => array(
175 'prefix' => '',
176 'title' => __('Happy New Year - 20% off WP-Optimize Premium until January 14th', 'wpo-premium'),
177 'text' => __('To benefit, use this discount code:', 'wpo-premium').' ',
178 'image' => 'notices/new_year.png',
179 'button_link' => 'https://getwpo.com',
180 'button_meta' => 'wp-optimize',
181 'dismiss_time' => 'dismiss_season',
182 'discount_code' => 'newyearsale2019',
183 'valid_from' => '2018-12-26 00:00:00',
184 'valid_to' => '2019-01-14 23:59:59',
185 'supported_positions' => $this->dashboard_top_or_report,
186 ),
187 'spring' => array(
188 'prefix' => '',
189 'title' => __('Spring sale - 20% off WP-Optimize Premium until April 30th', 'wpo-premium'),
190 'text' => __('To benefit, use this discount code:', 'wpo-premium').' ',
191 'image' => 'notices/spring.png',
192 'button_link' => 'https://getwpo.com',
193 'button_meta' => 'updraftplus',
194 'dismiss_time' => 'dismiss_season',
195 'discount_code' => 'springsale2018',
196 'valid_from' => '2019-04-01 00:00:00',
197 'valid_to' => '2019-04-30 23:59:59',
198 'supported_positions' => $this->dashboard_top_or_report,
199 ),
200 'summer' => array(
201 'prefix' => '',
202 'title' => __('Summer sale - 20% off WP-Optimize Premium until July 31st', 'wp-optimize'),
203 'text' => __('To benefit, use this discount code:', 'wp-optimize').' ',
204 'image' => 'notices/summer.png',
205 'button_link' => 'https://getwpo.com',
206 'button_meta' => 'wp-optimize',
207 'dismiss_time' => 'dismiss_season',
208 'discount_code' => 'summersale2018',
209 'valid_from' => '2019-07-01 00:00:00',
210 'valid_to' => '2019-07-31 23:59:59',
211 'supported_positions' => $this->dashboard_top_or_report,
212 )
213 );
214
215 return array_merge($parent_notice_content, $child_notice_content);
216 }
217
218 /**
219 * Call this method to setup the notices
220 */
221 public function notices_init() {
222 if ($this->initialized) return;
223 $this->initialized = true;
224 $this->notices_content = (defined('WP_OPTIMIZE_NOADS_B') && WP_OPTIMIZE_NOADS_B) ? array() : $this->populate_notices_content();
225 $our_version = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? WPO_VERSION.'.'.time() : WPO_VERSION;
226 $min_or_not = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min';
227 wp_enqueue_style('wp-optimize-notices-css', WPO_PLUGIN_URL.'/css/wp-optimize-notices'.$min_or_not.'.css', array(), $our_version);
228 }
229
230 /**
231 * 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
232 *
233 * @param string $product the plugin slug
234 * @param boolean $also_require_active a bool to indicate if the plugin should also be active
235 * @return boolean a bool to indicate if the notice should be displayed or not
236 */
237 protected function is_updraftplus_installed($product = 'updraftplus', $also_require_active = false) {
238 return parent::is_plugin_installed($product, $also_require_active);
239 }
240
241 /**
242 * 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
243 *
244 * @param string $product the plugin slug
245 * @param boolean $also_require_active a bool to indicate if the plugin should also be active
246 * @return boolean a bool to indicate if the notice should be displayed or not
247 */
248 protected function is_updraftcentral_installed($product = 'updraftcentral', $also_require_active = false) {
249 return parent::is_plugin_installed($product, $also_require_active);
250 }
251
252 /**
253 * This method will call the parent is_plugin_installed and pass in the product keyy to check if that plugin is installed if it is then we shouldn't display the notice
254 *
255 * @param string $product the plugin slug
256 * @param boolean $also_require_active a bool to indicate if the plugin should also be active
257 * @return boolean a bool to indicate if the notice should be displayed or not
258 */
259 protected function is_keyy_installed($product = 'keyy', $also_require_active = false) {
260 return parent::is_plugin_installed($product, $also_require_active);
261 }
262
263 /**
264 * 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
265 *
266 * @return boolean a bool to indicate if we should display the notice or not
267 */
268 protected function is_wpo_premium_installed() {
269 if (WP_Optimize()->is_premium()) {
270 return false;
271 }
272
273 return true;
274 }
275
276 /**
277 * 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
278 *
279 * @param String $product the plugin slug
280 * @param boolean $also_require_active a bool to indicate if the plugin should be active or not
281 * @return boolean a bool to indicate if the notice should be displayed or not
282 */
283 public function is_backup_plugin_installed($product = null, $also_require_active = false) {
284 $backup_plugins = array('updraftplus' => 'UpdraftPlus', 'backwpup' => 'BackWPup', 'backupwordpress' => 'BackupWordPress', 'vaultpress' => 'VaultPress', 'wp-db-backup' => 'WP-DB-Backup', 'backupbuddy' => 'BackupBuddy');
285
286 foreach ($backup_plugins as $slug => $title) {
287 if (!parent::is_plugin_installed($slug, $also_require_active)) {
288 return $title;
289 }
290 }
291
292 return apply_filters('wp_optimize_is_backup_plugin_installed', false);
293 }
294
295 /**
296 * This method will check to see if Meta Slider plugin is installed.
297 *
298 * @param String $product the plugin slug
299 * @param boolean $also_require_active a bool to indicate if the plugin should be active or not
300 * @return boolean a bool to indicate if the notice should be displayed or not
301 */
302 protected function is_metaslider_installed($product = 'ml-slider', $also_require_active = false) {
303 return parent::is_plugin_installed($product, $also_require_active);
304 }
305
306
307 /**
308 * 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.
309 *
310 * @param String $plugin_base_dir the plugin base directory
311 * @param String $product_name the name of the plugin
312 * @return Boolean returns true if the user is using a non english language and could translate otherwise false
313 */
314 protected function translation_needed($plugin_base_dir = null, $product_name = null) {
315 return parent::translation_needed(WPO_PLUGIN_MAIN_PATH, 'wp-optimize');
316 }
317
318 /**
319 * This method is used to generate the correct URL output for the start of the URL
320 *
321 * @param Boolean $html_allowed a boolean value to indicate if HTML can be used or not
322 * @param String $url the url to use
323 * @param Boolean $https a boolean value to indicate if https should be used or not
324 * @param String $website_home a string to be displayed
325 * @return String returns a string of the completed url
326 */
327 protected function url_start($html_allowed = false, $url, $https = false, $website_home = 'updraftplus.com/wp-optimize') {
328 return parent::url_start($html_allowed, $url, $https, $website_home);
329 }
330
331 /**
332 * This method checks to see if the notices dismiss_time parameter has been dismissed
333 *
334 * @param String $dismiss_time a string containing the dimiss time ID
335 * @return Boolean returns true if the notice has been dismissed and shouldn't be shown otherwise display it
336 */
337 protected function check_notice_dismissed($dismiss_time) {
338
339 $time_now = (defined('WP_OPTIMIZE_NOTICES_FORCE_TIME') ? WP_OPTIMIZE_NOTICES_FORCE_TIME : time());
340
341 $options = WP_Optimize()->get_options();
342
343 $notice_dismiss = ($time_now < $options->get_option($dismiss_time, 0));
344
345 return $notice_dismiss;
346 }
347
348 /**
349 * Check notice data for seasonal info and return true if we should display this notice.
350 *
351 * @param array $notice_data
352 * @return bool
353 */
354 protected function skip_seasonal_notices($notice_data) {
355 $time_now = defined('WPO_NOTICES_FORCE_TIME') ? WPO_NOTICES_FORCE_TIME : time();
356 // Do not show seasonal notices in Premium version.
357 if (false === WP_Optimize::is_premium()) {
358 $valid_from = strtotime($notice_data['valid_from']);
359 $valid_to = strtotime($notice_data['valid_to']);
360 $dismiss = $this->check_notice_dismissed($notice_data['dismiss_time']);
361 if (($time_now >= $valid_from && $time_now <= $valid_to) && !$dismiss) {
362 // return true so that we return this notice to be displayed
363 return true;
364 }
365 }
366
367 return false;
368 }
369
370 /**
371 * 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
372 *
373 * @param Array $advert_information an array with the notice information in
374 * @param Boolean $return_instead_of_echo a bool value to indicate if the notice should be printed to page or returned
375 * @param String $position a string to indicate what template should be used
376 * @return String a notice to display
377 */
378 protected function render_specified_notice($advert_information, $return_instead_of_echo = false, $position = 'top') {
379
380 if ('bottom' == $position) {
381 $template_file = 'bottom-notice.php';
382 } elseif ('report' == $position) {
383 $template_file = 'report.php';
384 } elseif ('report-plain' == $position) {
385 $template_file = 'report-plain.php';
386 } else {
387 $template_file = 'horizontal-notice.php';
388 }
389
390 $extract_variables = array_merge($advert_information, array('wp_optimize_notices' => $this));
391
392 return WP_Optimize()->include_template('notices/'.$template_file, $return_instead_of_echo, $extract_variables);
393 }
394 }
395
396 $GLOBALS['wp_optimize_notices'] = WP_Optimize_Notices::instance();
397