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' ); } } ?>
class="" >
user_firstname ) ? $current_user->user_firstname : $current_user->user_login; $migrate_url = add_query_arg( array( 'page' => Hustle_Data::INTEGRATIONS_PAGE, 'show_provider_migration' => $provider, 'integration_id' => isset( $provider_data['id'] ) ? $provider_data['id'] : '', ), 'admin.php' ); $provided_id = isset( $provider_data['id'] ) ? $provider . '_' . $provider_data['id'] : $provider; ?>
" data-name="" data-id="" style="display: none" >

get_provider_migration_content( $provider, $username, $provider_data['name'] ); ?>

id && 'plugins-network' !== $current_screen->id ) { return; } // Display admin notice about plugin deactivation. if ( is_multisite() ) { add_action( 'network_admin_notices', array( $this, 'hustle_activated_deactivated' ) ); } // We want to show this in the subsite's plugin page as well. add_action( 'admin_notices', array( $this, 'hustle_activated_deactivated' ) ); $this->add_in_hustle_row_messages(); } /** * Add notices in the plugin's row. * * @since 4.2.2 */ private function add_in_hustle_row_messages() { if ( $this->is_free ) { add_action( 'in_plugin_update_message-wordpress-popup/popover.php', array( $this, 'in_plugin_update_message' ), 10, 2 ); require_once Opt_In::$plugin_path . 'lib/free-dashboard/module.php'; // Register the current plugin. do_action( 'wdev-register-plugin', // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores plugin_basename( __FILE__ ), // 1. Plugin ID 'Hustle', // 2. Plugin Title '/plugins/wordpress-popup/', // 3. https://wordpress.org __( 'Sign Me Up', 'hustle' ), // 4. Email Button CTA 'f68d9fbc51' // 5. Mailchimp List id ); } else { add_action( 'load-plugins.php', function() { add_action( 'after_plugin_row_hustle/opt-in.php', array( $this, 'in_plugin_update_message' ), 10, 3 ); }, 22 // Must be called after Dashboard which is 21. ); // Load dashboard notice. global $wpmudev_notices; $wpmudev_notices[] = array( 'id' => 1107020, 'name' => 'Hustle', 'screens' => array( 'toplevel_page_hustle', 'optin-pro_page_inc_optin', ), ); require_once Opt_In::$plugin_path . 'lib/wpmudev-dashboard/wpmudev-dash-notification.php'; } } /** * Add notice to Hustle's row in the Plugins page * Alert the members they should check out their modules when upgrading to 4.1.0. * * @since 4.0.4 * * @param string $project_id Project ID. * @param array $plugin_data Plugin data. * @param string $project_name Project name. */ public function in_plugin_update_message( $project_id, $plugin_data, $project_name = '' ) { $plugin_data = (object) $plugin_data; $needed_version = $this->is_free ? '7.1' : '4.1'; if ( empty( $plugin_data->new_version ) || empty( $plugin_data->plugin ) || $needed_version !== $plugin_data->new_version ) { return; } $heads_up = __( 'Heads up!', 'hustle' ); /* translators: current version */ $title = sprintf( __( 'We’ve fixed visibility conditions in Hustle %1$s which may affect the visibility behavior of your pop-ups and other modules.', 'hustle' ), $plugin_data->new_version ); /* translators: current version */ $description = sprintf( __( 'Prior to Hustle %1$s, the visibility engine would require you to set rules for every post type your theme used, not just the ones you specified to make it appear on correct pages. We’ve updated this behavior to only display modules based on the post types explicitly defined in your conditions. For Example, if you add a “Pages” condition to show your module on 1 page only, you’d no longer have to add other post type conditions to hide your module on them. After updating, we recommend double-checking your Hustle modules’ visibility conditions are working as expected.', 'hustle' ), $plugin_data->new_version ); echo ""; } /** * ************************** * NOTICES * ************************** */ /** * Available notifications. * * In plugins.php page. * * @see Hustle_Notifications::hustle_activated_deactivated() * * In Hustle pages. * @see Hustle_Notifications::show_pro_available_notice() * @see Hustle_Notifications::show_migrate_tracking_notice() * @see Hustle_Notifications::show_review_css_after_migration_notice() * @see Hustle_Notifications::show_sendgrid_update_notice() * @see Hustle_Notifications::show_provider_migration_notice() * @see Hustle_Notifications::show_visibility_behavior_update() */ /** * Displays a notice on plugin activation and deactivaton. * This is shown when either free or pro is active, and the other version (free or pro) is activated. * * @since 2.1.4 * @since 4.2.0 Moved from Opt_In to this class. */ public function hustle_activated_deactivated() { // Show the notice only to users who can do something about this. if ( ! $this->user_can_update_plugins ) { return; } // For Pro. if ( get_site_option( 'hustle_free_deactivated' ) ) { $message = '

' . 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 ); } }