PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.9
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.9
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-install-or-update-notice.php

class-wp-optimize-install-or-update-notice.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 3.2.9, at includes/class-wp-optimize-install-or-update-notice.php

115 lines 2.8 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 * Install or update notice
6 * Manages the notice shown when the user activates or updates WPO
7 *
8 * The class is included during `admin_init`
9 */
10 class WP_Optimize_Install_Or_Update_Notice {
11
12 /**
13 * Notice Version.
14 * If we need to later show a similar notice with a different content,
15 * We can reuse this by changing the version number and updating the content in the template file.
16 *
17 * @var string
18 */
19 private $version = '1.1';
20
21 public function __construct() {
22 $this->options = WP_Optimize()->get_options();
23
24 if ($this->show_current_notice()) {
25 add_action('wpo_admin_after_header', array($this, 'output_notice'), 20);
26 }
27
28 }
29
30 /**
31 * Determines if the current notice was shown
32 *
33 * @return boolean
34 */
35 public function show_current_notice() {
36 // Check the option
37 $latest_saved_notice = $this->options->get_option('install-or-update-notice-version', false);
38 if ($latest_saved_notice && version_compare($latest_saved_notice, $this->version, '>=')) {
39 return false;
40 }
41
42 $notice_show_time = $this->options->get_option('install-or-update-notice-show-time', false);
43
44 // If notice has been showing for more than 14days, automatically dismiss it.
45 if ($notice_show_time && (time() - $notice_show_time) > (14 * 86400)) {
46 $this->dismiss();
47 return false;
48 }
49
50 if (!$notice_show_time) {
51 // Save the first time the notice was shown
52 $this->options->update_option('install-or-update-notice-show-time', time());
53 }
54 return true;
55 }
56
57 /**
58 * Outputs the notice
59 *
60 * @return void
61 */
62 public function output_notice() {
63 WP_Optimize()->include_template('notices/install-or-update-notice.php', false, array(
64 'is_new_install' => $this->is_new_install(),
65 'is_premium' => WP_Optimize::is_premium(),
66 'is_updraftplus_installed' => $this->is_updraftplus_installed()
67 ));
68 }
69
70 /**
71 * Attempts to find out if WPO was newly installed or updated
72 *
73 * @return boolean
74 */
75 private function is_new_install() {
76 if ($this->options->get_option('newly-activated', false)) {
77 return true;
78 }
79
80 return false;
81 }
82
83 /**
84 * Dismiss the notice
85 *
86 * @return boolean
87 */
88 public function dismiss() {
89
90 if ($this->is_new_install()) {
91 $this->options->delete_option('newly-activated');
92 }
93
94 if (!$this->options->update_option('install-or-update-notice-version', $this->version)) {
95 return false;
96 }
97
98 // Delete Notice show time option, to allow re-creating next time we need to show it.
99 $this->options->delete_option('install-or-update-notice-show-time');
100
101 return true;
102 }
103
104 /**
105 * Check if updraftplus is installed.
106 *
107 * @return bool
108 */
109 private function is_updraftplus_installed() {
110 $status = WP_Optimize()->get_db_info()->get_plugin_status('updraftplus');
111
112 return $status['installed'];
113 }
114 }
115