has_connected_owner(); $is_connected = Jetpack::is_connection_ready(); $has_licenses = ! empty( Licensing::instance()->stored_licenses() ); // Don't show the connect notice if the site has a connected owner. if ( $has_connected_owner ) { return false; } // Don't show the connect notice if a site connection is established and there are no stored licenses. // Stored licenses indicate that a purchased product may not be provisioned yet hence we need to keep // showing the notice to nudge the user to connect in order to have their product(s) provisioned. if ( $is_connected && ! $has_licenses ) { return false; } // Kill if banner has been dismissed and the pre-connection helpers filter is not set. if ( Jetpack_Options::get_option( 'dismissed_connection_banner' ) && ! self::force_display() ) { return false; } // Don't show the connect notice anywhere but the plugins.php after activating. if ( 'plugins' !== $current_screen->base && 'dashboard' !== $current_screen->base ) { return false; } if ( ! current_user_can( 'jetpack_connect' ) ) { return false; } return true; } /** * Given a string for the the banner was added, and an int that represents the slide to * a URL for, this function returns a connection URL with a from parameter that will * support split testing. * * @since 7.2 Event key format is now banner-connect-banner-72-dashboard or connect-banner-72-plugins. * The param $slide_num was removed since we removed all slides but the first one. * @since 4.4.0 * * @param string $jp_version_banner_added A short version of when the banner was added. Ex. 44 * * @return string */ function build_connect_url_for_slide( $jp_version_banner_added ) { global $current_screen; $url = Jetpack::init()->build_connect_url( true, false, sprintf( 'connect-banner-%s-%s', $jp_version_banner_added, $current_screen->base ) ); return add_query_arg( 'auth_approved', 'true', $url ); } /** * Will initialize hooks to display the new (as of 4.4) connection banner if the current user can * connect Jetpack, if Jetpack has not been deactivated, and if the current page is the plugins page. * * @since 4.4.0 * @since 4.5.0 Made the new (as of 4.4) connection banner display to everyone by default. * @since 5.3.0 Running another split test between 4.4 banner and a new one in 5.3. * @since 7.2 B test was removed. * @since 9.7 Moved the connection condition checking to this method to fulfill Licensing requirements. * * @param $current_screen */ function maybe_initialize_hooks( $current_screen ) { if ( ! self::can_be_displayed( $current_screen ) ) { return; } if ( ! empty( Licensing::instance()->stored_licenses() ) ) { add_action( 'admin_notices', array( $this, 'render_license_aware_banner' ) ); } else { add_action( 'admin_notices', array( $this, 'render_banner' ) ); } add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_banner_scripts' ) ); add_action( 'admin_print_styles', array( Jetpack::init(), 'admin_banner_styles' ) ); if ( Jetpack::state( 'network_nag' ) ) { add_action( 'network_admin_notices', array( $this, 'network_connect_notice' ) ); } // Only fires immediately after plugin activation if ( get_transient( 'activated_jetpack' ) ) { add_action( 'admin_notices', array( $this, 'render_connect_prompt_full_screen' ) ); delete_transient( 'activated_jetpack' ); } } /** * Enqueues JavaScript for new connection banner. * * @since 4.4.0 */ public static function enqueue_banner_scripts() { wp_enqueue_script( 'jetpack-connection-banner-js', Assets::get_file_url_for_environment( '_inc/build/jetpack-connection-banner.min.js', '_inc/jetpack-connection-banner.js' ), array( 'jquery' ), JETPACK__VERSION, true ); wp_localize_script( 'jetpack-connection-banner-js', 'jp_banner', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'connectionBannerNonce' => wp_create_nonce( 'jp-connection-banner-nonce' ), ) ); } /** * Enqueues JavaScript and CSS for new connect-in-place flow. * * @since 7.7 */ public static function enqueue_connect_button_scripts() { global $is_safari; wp_enqueue_script( 'jetpack-connect-button', Assets::get_file_url_for_environment( '_inc/build/connect-button.min.js', '_inc/connect-button.js' ), array( 'jquery' ), JETPACK__VERSION, true ); wp_enqueue_style( 'jetpack-connect-button', Assets::get_file_url_for_environment( 'css/jetpack-connect.min.css', 'css/jetpack-connect.css' ) ); $jetpackApiUrl = wp_parse_url( Jetpack::connection()->api_url( '' ) ); // Due to the limitation in how 3rd party cookies are handled in Safari and Opera, // we're falling back to the original flow. if ( $is_safari || User_Agent_Info::is_opera_desktop() || Constants::is_true( 'JETPACK_SHOULD_NOT_USE_CONNECTION_IFRAME' ) ) { $force_variation = 'original'; } else { $force_variation = 'in_place'; } $tracking = new Automattic\Jetpack\Tracking(); $identity = $tracking->tracks_get_identity( get_current_user_id() ); wp_localize_script( 'jetpack-connect-button', 'jpConnect', array( 'apiBaseUrl' => esc_url_raw( rest_url( 'jetpack/v4' ) ), 'registrationNonce' => wp_create_nonce( 'jetpack-registration-nonce' ), 'apiNonce' => wp_create_nonce( 'wp_rest' ), 'apiSiteDataNonce' => wp_create_nonce( 'wp_rest' ), 'buttonTextRegistering' => __( 'Loading...', 'jetpack' ), 'jetpackApiDomain' => $jetpackApiUrl['scheme'] . '://' . $jetpackApiUrl['host'], 'forceVariation' => $force_variation, 'connectInPlaceUrl' => Jetpack::admin_url( 'page=jetpack#/setup' ), 'dashboardUrl' => Jetpack::admin_url( 'page=jetpack#/dashboard' ), 'plansPromptUrl' => Redirect::get_url( 'jetpack-connect-plans' ), 'identity' => $identity, 'preFetchScript' => plugins_url( '_inc/build/admin.js', JETPACK__PLUGIN_FILE ) . '?ver=' . JETPACK__VERSION, ) ); } /** * Renders the new connection banner as of 4.4.0. * * @since 7.2 Copy and visual elements reduced to show the new focus of Jetpack on Security and Performance. * @since 4.4.0 */ public function render_banner() { ?>