is_free = Opt_In_Utils::_is_free(); add_action( 'current_screen', array( $this, 'load_plugins_page_notices' ) ); $cap = is_multisite() ? 'manage_network_plugins' : 'update_plugins'; $this->user_can_update_plugins = current_user_can( $cap ); add_action( 'wp_ajax_hustle_dismiss_notification', array( $this, 'dismiss_notification' ) ); } /** * Enqueues the notices to be shown within the plugin's pages. * * @since 4.2.0 */ public function add_in_hustle_notices() { // Show upgrade notice only if this is free, and Hustle Pro is not already installed. if ( $this->is_free && ! file_exists( WP_PLUGIN_DIR . '/hustle/opt-in.php' ) ) { add_action( 'admin_notices', array( $this, 'show_pro_available_notice' ) ); } if ( Hustle_Migration::check_tracking_needs_migration() ) { add_action( 'admin_notices', array( $this, 'show_migrate_tracking_notice' ) ); } if ( Hustle_Migration::did_hustle_exist() ) { add_action( 'admin_notices', array( $this, 'show_review_css_after_migration_notice' ) ); } if ( Hustle_Migration::is_migrated( 'hustle_40_migrated' ) ) { add_action( 'admin_notices', array( $this, 'show_visibility_behavior_update' ) ); } add_action( 'admin_notices', array( $this, 'show_sendgrid_update_notice' ) ); add_action( 'admin_notices', array( $this, 'show_provider_migration_notice' ) ); } /** * Print the notice * * @since 4.2.0 * * @param string $message Notice's message. Must be already escaped. * @param boolean|string $name Notice's name. * @param string $type Notice's type error|success|info|warning. * @param boolean $is_dismissible Whether the notice is dismissible. */ private function show_notice( $message, $name = false, $type = 'info', $is_dismissible = false ) { $notices_types = array( 'info', 'success', 'error', 'warning' ); $class = 'notice'; $class .= in_array( $type, $notices_types, true ) ? ' notice-' . $type : ''; $nonce = false; if ( $is_dismissible ) { $class .= ' is-dismissible'; if ( $name ) { $class .= ' hustle-dismissible-admin-notice'; $nonce = wp_create_nonce( 'hustle_dismiss_notification' ); } } ?>
get_provider_migration_content( $provider, $username, $provider_data['name'] ); ?>
' . esc_html__( 'Congratulations! You have activated Hustle Pro! We have automatically deactivated the free version.', 'hustle' ) . '
'; $this->show_notice( $message, false, 'success', true ); delete_site_option( 'hustle_free_deactivated' ); } // For Free. if ( get_site_option( 'hustle_free_activated' ) ) { $message = '' . esc_html__( 'You already have Hustle Pro activated. If you really wish to go back to the free version of Hustle, please deactivate the Pro version first', 'hustle' ) . '
'; $this->show_notice( $message, false, 'error', true ); delete_site_option( 'hustle_free_activated' ); } } /** * Displays an admin notice when the user is an active member and doesn't have Hustle Pro installed * Shown in hustle pages. Per user notification. * * @since 3.0.6 */ public function show_pro_available_notice() { // The notice was already dismissed. if ( self::was_notification_dismissed( 'hustle_pro_is_available' ) ) { return; } // Show the notice only to users who can do something about this and who are members. if ( ! $this->user_can_update_plugins || ! Opt_In_Utils::is_hustle_included_in_membership() ) { return; } $link = lib3()->html->element( array( 'type' => 'html_link', 'value' => esc_html__( 'Upgrade' ), 'url' => esc_url( lib3()->get_link( 'hustle', 'install_plugin', '' ) ), 'class' => 'button-primary', ), true ); $profile = get_option( 'wdp_un_profile_data', '' ); $name = ! empty( $profile ) ? $profile['profile']['name'] : __( 'Hey', 'hustle' ); $message = ''; /* translators: user's name */ $message .= sprintf( esc_html__( '%s, it appears you have an active WPMU DEV membership but haven\'t upgraded Hustle to the pro version. You won\'t lose an any settings upgrading, go for it!', 'hustle' ), $name ); $message .= '
'; $message .= '' . $link . '
'; // used id hustle-notice-pro-is-available before. $this->show_notice( $message, 'hustle_pro_is_available', 'info', true ); } /** * Display the notice to migrate tracking and subscriptions data. * Shown in hustle pages. Per user notification. * * @since 4.0.0 */ public function show_migrate_tracking_notice() { if ( ! self::is_show_migrate_tracking_notice() ) { return; } $migrate_url = add_query_arg( array( 'page' => Hustle_Data::ADMIN_PAGE, 'show-migrate' => 'true', ), 'admin.php' ); $current_user = wp_get_current_user(); $username = ! empty( $current_user->user_firstname ) ? $current_user->user_firstname : $current_user->user_login; $message = ''; /* translators: user's name */ $message .= sprintf( esc_html__( 'Hey %s, nice work on updating the Hustle! However, you need to migrate the data of your existing modules such as tracking data and email list manually.', 'hustle' ), esc_html( $username ) ); $message .= '
'; $message .= '' . esc_html__( 'Migrate Data', 'hustle' ) . '' . esc_html__( 'Dismiss', 'hustle' ) . '
'; $this->show_notice( $message, 'tracking-migration-notice', 'warning', false ); } /** * Display a notice for reviewing the modules' custom css after migration. * Shown in hustle pages. Per user notification. * * @since 4.0.0 */ public function show_review_css_after_migration_notice() { if ( self::was_notification_dismissed( '40_custom_style_review' ) ) { return; } $current_user = wp_get_current_user(); $username = ! empty( $current_user->user_firstname ) ? $current_user->user_firstname : $current_user->user_login; $message = ''; $message .= sprintf( /* translators: user's name */ esc_html__( "Hey %s, we have improved Hustle’s front-end code in this update, which included modifying some CSS classes. Any custom CSS you were using may have been affected. We recommend reviewing the modules (which were using custom CSS) to ensure they don't need any adjustments.", 'hustle' ), esc_html( $username ) ); $message .= '
'; $this->show_notice( $message, '40_custom_style_review', 'warning', true ); } /** * Display a notice for updating Marketing Campaings via Sendgrid. * Shown in hustle pages. Per user notification. * * @since 4.0.4 */ public function show_sendgrid_update_notice() { // Check if the notification is already dismissed. if ( self::was_notification_dismissed( 'hustle_sendgrid_update_showed' ) ) { return; } // Check if there is no Sendgrid intagration. if ( ! $this->is_provider_integrated( 'sendgrid' ) ) { self::add_dismissed_notification( 'hustle_sendgrid_update_showed' ); return; } $integrations_url = add_query_arg( array( 'page' => Hustle_Data::INTEGRATIONS_PAGE ), 'admin.php' ); $current_user = wp_get_current_user(); $username = ! empty( $current_user->user_firstname ) ? $current_user->user_firstname : $current_user->user_login; $message = ''; $message .= sprintf( /* translators: 1. user's name, 2. opening 'a' tag to sendgrid link, 3. closing 'a' tag, 4. opening 'b' tag, 5. closing 'b' tag */ esc_html__( 'Hey %1$s, we have updated our %4$sSendGrid%5$s integration to support the %2$snew Marketing Campaigns%3$s. You need to review your existing SendGrid integration(s) and select the Marketing Campaigns version (new or legacy) you are using to avoid failed API calls.', 'hustle' ), esc_html( $username ), '', '', '', '' ); $message .= '
'; $message .= '' . esc_html__( 'Review Integrations', 'hustle' ) . '
'; $this->show_notice( $message, 'hustle_sendgrid_update_showed', 'warning', true ); } /** * Shows the provider's migration notice. * Shown in hustle pages. Per user notification. * * @since 4.2.0 */ public function show_provider_migration_notice() { $aweber_instances = get_option( 'hustle_provider_aweber_settings' ); if ( ! empty( $aweber_instances ) ) { foreach ( $aweber_instances as $key => $instance ) { if ( ! array_key_exists( 'access_oauth2_token', $instance ) || empty( $instance['access_oauth2_token'] ) ) { $provider_data = array( 'name' => $instance['name'], 'id' => $key, ); $this->get_provider_migration_notice_html( 'aweber', $provider_data ); } } } } /** * Display a notice for reviewing visibility conditions after updating. * Shown in hustle pages. Per user notification. * * @since 4.1.0 */ public function show_visibility_behavior_update() { if ( self::was_notification_dismissed( '41_visibility_behavior_update' ) ) { return; } if ( $this->is_fresh_install() ) { return; } $url_params = array( 'page' => Hustle_Data::ADMIN_PAGE, 'review-conditions' => 'true', ); $url = add_query_arg( $url_params, 'admin.php' ); $link = lib3()->html->element( array( 'type' => 'html_link', 'value' => esc_html__( 'Check conditions', 'hustle' ), 'url' => esc_url_raw( $url ), 'class' => 'button-primary', ), true ); $version = $this->is_free ? '7.1' : '4.1'; ob_start(); ?>
show_notice( $message, '41_visibility_behavior_update', 'warning', true ); } /** * ************************** * NOTICES * ************************** */ /** * Check is $provider integrated or not * * @since 4.0.4 * @param string $provider Provider slug. * @return bool */ private function is_provider_integrated( $provider ) { $providers = Hustle_Provider_Utils::get_registered_addons_grouped_by_connected(); $connected = wp_list_pluck( $providers['connected'], 'slug' ); return in_array( $provider, $connected, true ); } /** * Checks whether the current install is a fresh one. * It returns false if there was a version installed before. * * @since 4.3.0 * * @return boolean */ private function is_fresh_install() { return ! get_site_option( 'hustle_previous_version', false ); } }