| @@ -15,8 +15,10 @@ | ||
| 15 | 15 | use NotificationX\Core\Dashboard; |
| 16 | 16 | use NotificationX\Core\Database; |
| 17 | 17 | use NotificationX\Core\PostType; |
| 18 | 18 | use NotificationX\Core\SetupWizard; |
| 19 | +use NotificationX\Core\UsageTracker; | |
| 20 | +use NotificationX\Core\Maintenance; | |
| 19 | 21 | use NotificationX\Core\Upgrader; |
| 20 | 22 | use NotificationX\GetInstance; |
| 21 | 23 | use NotificationX\Extensions\ExtensionFactory; |
| 22 | 24 | |
| @@ -41,8 +43,18 @@ | ||
| 41 | 43 | const ASSET_URL = NOTIFICATIONX_ASSETS . 'admin/'; |
| 42 | 44 | const ASSET_PATH = NOTIFICATIONX_ASSETS_PATH . 'admin/'; |
| 43 | 45 | const VIEWS_PATH = NOTIFICATIONX_INCLUDES . 'Admin/views/'; |
| 44 | 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 | + | |
| 45 | 57 | private $insights = null; |
| 46 | 58 | |
| 47 | 59 | /** |
| 48 | 60 | * @var CacheBank |
| @@ -63,8 +75,10 @@ | ||
| 63 | 75 | RatingEmail::get_instance(); |
| 64 | 76 | ImportExport::get_instance(); |
| 65 | 77 | XSS::get_instance(); |
| 66 | 78 | InfoTooltipManager::get_instance(); |
| 79 | + UsageTracker::get_instance(); | |
| 80 | + Maintenance::get_instance(); | |
| 67 | 81 | add_action('init', [$this, 'init'], 5); |
| 68 | 82 | add_filter('nx_rest_miscellaneous', [$this, 'handle_miscellaneous_actions'], 10, 2); |
| 69 | 83 | add_filter('nx_builder_configs', [$this, 'add_popup_status_to_context'], 10, 1); |
| 70 | 84 | } |
| @@ -75,10 +89,14 @@ | ||
| 75 | 89 | * |
| 76 | 90 | * @return void |
| 77 | 91 | */ |
| 78 | 92 | public function init(){ |
| 93 | + // Usage insights/tracking must initialize regardless of Pro being | |
| 94 | + // active: Pro ships no insights of its own, so gating this behind | |
| 95 | + // !is_pro() left the put_do_weekly_action cron with no listener and | |
| 96 | + // disabled tracking (incl. the UsageTracker payload) on every Pro site. | |
| 97 | + $this->plugin_usage_insights(); | |
| 79 | 98 | if( ! NotificationX::is_pro() ){ |
| 80 | - $this->plugin_usage_insights(); | |
| 81 | 99 | $this->admin_notices(); |
| 82 | 100 | $is_embedpress_milestone_showing = get_option('is_embedpress_milestone_showing', false); |
| 83 | 101 | if (!$is_embedpress_milestone_showing) { |
| 84 | 102 | MilestoneNotification::get_instance(); |
| @@ -85,8 +103,12 @@ | ||
| 85 | 103 | } |
| 86 | 104 | } |
| 87 | 105 | add_action('admin_init', [$this, 'admin_init']); |
| 88 | 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']); | |
| 89 | 111 | Dashboard::get_instance(); |
| 90 | 112 | SetupWizard::get_instance(); |
| 91 | 113 | PostType::get_instance(); |
| 92 | 114 | Settings::get_instance()->init(); |
| @@ -197,8 +219,52 @@ | ||
| 197 | 219 | NoticeRemover::get_instance( '1.0.0' ); |
| 198 | 220 | } |
| 199 | 221 | |
| 200 | 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 | + } | |
| 266 | + | |
| 201 | 267 | public function hide_others_plugin_admin_notice() |
| 202 | 268 | { |
| 203 | 269 | $current_screen = get_current_screen(); |
| 204 | 270 | $hide_on = ['toplevel_page_nx-admin', 'notificationx_page_nx-dashboard', 'notificationx_page_nx-edit','notificationx_page_nx-settings','notificationx_page_nx-analytics','notificationx_page_nx-builder', 'notificationx_page_nx-feedback-entries']; |
| @@ -411,8 +477,11 @@ | ||
| 411 | 477 | self::$cache_bank->calculate_deposits( $notices ); |
| 412 | 478 | } |
| 413 | 479 | |
| 414 | 480 | public function plugin_usage_insights(){ |
| 481 | + if ( null !== $this->insights ) { | |
| 482 | + return $this->insights; | |
| 483 | + } | |
| 415 | 484 | $this->insights = PluginInsights::get_instance( NOTIFICATIONX_FILE, [ |
| 416 | 485 | 'opt_in' => true, |
| 417 | 486 | 'goodbye_form' => true, |
| 418 | 487 | 'item_id' => '6ba8d30bc0beaddb2540' |
| @@ -424,8 +493,10 @@ | ||
| 424 | 493 | discount coupon. This data lets us make sure this plugin always stays compatible with the most |
| 425 | 494 | popular plugins and themes. No spam, I promise.', 'notificationx' ), |
| 426 | 495 | )); |
| 427 | 496 | $this->insights->init(); |
| 497 | + | |
| 498 | + return $this->insights; | |
| 428 | 499 | } |
| 429 | 500 | |
| 430 | 501 | /** |
| 431 | 502 | * Handle miscellaneous REST API actions |