PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backup, Restore, Migration & Clone / 4.9.2
WP STAGING – WordPress Backup, Restore, Migration & Clone v4.9.2
4.9.2 4.9.1 4.9.0 4.8.1 trunk 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.10.0 3.2.0 3.3.1 3.3.2 3.3.3 3.4.1 3.4.3 3.5.0 3.6.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 4.0.0 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.8.0
wp-staging / Framework / Notices / WpVersionCompatNotice.php
wp-staging / Framework / Notices Last commit date
BackupPluginsNotice.php 1 year ago BooleanNotice.php 2 years ago CliIntegrationNotice.php 1 day ago DisabledItemsNotice.php 2 years ago DismissNotice.php 1 day ago NextGenEngineNotice.php 1 day ago Notices.php 1 day ago NoticesHandler.php 11 months ago ObjectCacheNotice.php 11 months ago OutdatedWpStagingNotice.php 1 year ago WarningsNotice.php 2 years ago WpVersionCompatNotice.php 3 months ago
WpVersionCompatNotice.php
124 lines
1 <?php
2
3 namespace WPStaging\Framework\Notices;
4
5 use WPStaging\Core\WPStaging;
6 use WPStaging\Framework\Language\Language;
7 use WPStaging\Framework\Security\Auth;
8
9 /**
10 * Displays a dismissible compatibility status banner when WP STAGING has not yet
11 * been validated for the currently installed WordPress version.
12 *
13 * Dismissal is stored in wp_options. The stored value is the plugin version at the
14 * time of dismissal, so the notice automatically reappears after a plugin update.
15 */
16 class WpVersionCompatNotice
17 {
18 /**
19 * Option key for storing the dismissed plugin version.
20 *
21 * @var string
22 */
23 const OPTION_KEY = 'wpstg_compat_notice_dismissed';
24
25 /**
26 * @var Auth
27 */
28 private $auth;
29
30 /**
31 * @param Auth $auth
32 */
33 public function __construct(Auth $auth)
34 {
35 $this->auth = $auth;
36 }
37
38 /**
39 * Conditionally render the compatibility notice inside the plugin UI.
40 *
41 * @return void
42 */
43 public function maybeShow()
44 {
45 if (!current_user_can('manage_options')) {
46 return;
47 }
48
49 $wpVersion = get_bloginfo('version');
50 $pluginVersion = WPStaging::getVersion();
51
52 if (!$this->shouldShowNotice($wpVersion, $pluginVersion)) {
53 return;
54 }
55
56 $wpMajorMinor = $this->getWpMajorMinor($wpVersion);
57
58 $changelogUrl = WPStaging::isPro()
59 ? 'https://wp-staging.com/wp-staging-pro-changelog/'
60 : 'https://wp-staging.com/changelog/';
61 $supportUrl = Language::localizeSupportUrl('https://wp-staging.com/support/');
62 $systemInfoUrl = admin_url('admin.php?page=wpstg-tools');
63
64 $notice = WPSTG_VIEWS_DIR . 'notices/wp-version-compat-notice.php';
65 if (!file_exists($notice)) {
66 return;
67 }
68
69 include $notice;
70 }
71
72 /**
73 * AJAX handler to persist dismissal.
74 *
75 * Stores the current plugin version so the notice reappears after a plugin update.
76 *
77 * @return void
78 */
79 public function ajaxDismissCompatNotice()
80 {
81 if (!$this->auth->isAuthenticatedRequest('', 'manage_options')) {
82 wp_send_json_error();
83 }
84
85 update_option(self::OPTION_KEY, WPStaging::getVersion(), false);
86 wp_send_json_success();
87 }
88
89 /**
90 * Determine whether the notice should be shown.
91 *
92 * @param string $wpVersion
93 * @param string $pluginVersion
94 * @return bool
95 */
96 private function shouldShowNotice($wpVersion, $pluginVersion)
97 {
98 $compatible = WPStaging::getInstance()->get('WPSTG_COMPATIBLE');
99
100 if (version_compare($compatible, $wpVersion, '>=')) {
101 return false;
102 }
103
104 $dismissedForVersion = get_option(self::OPTION_KEY, '');
105
106 return $dismissedForVersion !== $pluginVersion;
107 }
108
109 /**
110 * Extract the major.minor portion from a WordPress version string.
111 *
112 * @param string $version e.g. "6.6.1" or "7.0-alpha-61697"
113 * @return string e.g. "6.6" or "7.0"
114 */
115 private function getWpMajorMinor($version)
116 {
117 if (preg_match('/^(\d+\.\d+)/', $version, $m)) {
118 return $m[1];
119 }
120
121 return $version;
122 }
123 }
124