BackupPluginsNotice.php
1 day ago
BooleanNotice.php
1 day ago
CliIntegrationNotice.php
1 day ago
DisabledItemsNotice.php
1 day ago
DismissNotice.php
1 day ago
NextGenEngineNotice.php
1 day ago
Notices.php
1 day ago
NoticesHandler.php
1 day ago
ObjectCacheNotice.php
1 day ago
OutdatedWpStagingNotice.php
1 day ago
WarningsNotice.php
1 day ago
WpVersionCompatNotice.php
1 day 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 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | class WpVersionCompatNotice |
| 17 | { |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | const OPTION_KEY = 'wpstg_compat_notice_dismissed'; |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | private $auth; |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | public function __construct(Auth $auth) |
| 34 | { |
| 35 | $this->auth = $auth; |
| 36 | } |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 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 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 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 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 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 | |
| 111 | |
| 112 | |
| 113 | |
| 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 |