| @@ -43,8 +43,18 @@ | ||
| 43 | 43 | const ASSET_URL = NOTIFICATIONX_ASSETS . 'admin/'; |
| 44 | 44 | const ASSET_PATH = NOTIFICATIONX_ASSETS_PATH . 'admin/'; |
| 45 | 45 | const VIEWS_PATH = NOTIFICATIONX_INCLUDES . 'Admin/views/'; |
| 46 | 46 | |
| 47 | + /** | |
| 48 | + * Oldest NotificationX Pro that ships its own copy of the Pro features the | |
| 49 | + * free plugin is removing (Flashing Tab, Cart Peek, Inline). Older Pro keeps | |
| 50 | + * working with this release, but loses those features once the free copies | |
| 51 | + * are deleted. See docs/api/frontend-js-hooks.md. | |
| 52 | + * | |
| 53 | + * @since 3.3.3 | |
| 54 | + */ | |
| 55 | + const MIN_PRO_VERSION = '3.2.3'; | |
| 56 | + | |
| 47 | 57 | private $insights = null; |
| 48 | 58 | |
| 49 | 59 | /** |
| 50 | 60 | * @var CacheBank |
| @@ -93,8 +103,12 @@ | ||
| 93 | 103 | } |
| 94 | 104 | } |
| 95 | 105 | add_action('admin_init', [$this, 'admin_init']); |
| 96 | 106 | add_action('admin_menu', [$this, 'menu'], 10); |
| 107 | + // all_admin_notices, not admin_notices: hide_others_plugin_admin_notice() | |
| 108 | + // clears admin_notices on NotificationX screens, and this notice must | |
| 109 | + // show there too. | |
| 110 | + add_action('all_admin_notices', [$this, 'pro_version_notice']); | |
| 97 | 111 | Dashboard::get_instance(); |
| 98 | 112 | SetupWizard::get_instance(); |
| 99 | 113 | PostType::get_instance(); |
| 100 | 114 | Settings::get_instance()->init(); |
| @@ -204,8 +218,52 @@ | ||
| 204 | 218 | // Remove OLD notice from 1.0.0 (if other WPDeveloper plugin has notice) |
| 205 | 219 | NoticeRemover::get_instance( '1.0.0' ); |
| 206 | 220 | } |
| 207 | 221 | |
| 222 | + | |
| 223 | + /** | |
| 224 | + * Whether the active NotificationX Pro is older than MIN_PRO_VERSION. | |
| 225 | + * | |
| 226 | + * @since 3.3.3 | |
| 227 | + * @param string|null $pro_version Pro version; defaults to NOTIFICATIONX_PRO_VERSION. | |
| 228 | + * @return bool False when Pro is not active or its version is unknown. | |
| 229 | + */ | |
| 230 | + public static function pro_needs_update( $pro_version = null ) { | |
| 231 | + if ( null === $pro_version ) { | |
| 232 | + if ( ! NotificationX::is_pro() || ! defined( 'NOTIFICATIONX_PRO_VERSION' ) ) { | |
| 233 | + return false; | |
| 234 | + } | |
| 235 | + $pro_version = NOTIFICATIONX_PRO_VERSION; | |
| 236 | + } | |
| 237 | + if ( ! is_string( $pro_version ) || '' === $pro_version ) { | |
| 238 | + return false; | |
| 239 | + } | |
| 240 | + return version_compare( $pro_version, self::MIN_PRO_VERSION, '<' ); | |
| 241 | + } | |
| 242 | + | |
| 243 | + /** | |
| 244 | + * Non-dismissible notice asking to update an outdated NotificationX Pro. | |
| 245 | + * | |
| 246 | + * @since 3.3.3 | |
| 247 | + * @return void | |
| 248 | + */ | |
| 249 | + public function pro_version_notice() { | |
| 250 | + if ( ! current_user_can( 'update_plugins' ) || ! self::pro_needs_update() ) { | |
| 251 | + return; | |
| 252 | + } | |
| 253 | + $message = sprintf( | |
| 254 | + /* translators: 1: installed NotificationX Pro version, 2: required NotificationX Pro version. */ | |
| 255 | + __( 'You are using NotificationX Pro %1$s. Please update NotificationX Pro to version %2$s or later. Upcoming NotificationX releases move Flashing Tab, Cart Peek and Inline notifications fully into NotificationX Pro, and older Pro versions will stop showing them.', 'notificationx' ), | |
| 256 | + '<strong>' . esc_html( NOTIFICATIONX_PRO_VERSION ) . '</strong>', | |
| 257 | + '<strong>' . esc_html( self::MIN_PRO_VERSION ) . '</strong>' | |
| 258 | + ); | |
| 259 | + printf( | |
| 260 | + '<div class="notice notice-warning nx-pro-version-notice"><p>%1$s <a href="%2$s">%3$s</a></p></div>', | |
| 261 | + wp_kses_post( $message ), | |
| 262 | + esc_url( self_admin_url( 'plugins.php?plugin_status=upgrade' ) ), | |
| 263 | + esc_html__( 'Go to plugin updates', 'notificationx' ) | |
| 264 | + ); | |
| 265 | + } | |
| 208 | 266 | |
| 209 | 267 | public function hide_others_plugin_admin_notice() |
| 210 | 268 | { |
| 211 | 269 | $current_screen = get_current_screen(); |