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. * * This method should not be called if the site is connected to WordPress.com or if the site is in development mode. * * @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. * * @param $current_screen */ function maybe_initialize_hooks( $current_screen ) { // Kill if banner has been dismissed if ( Jetpack_Options::get_option( 'dismissed_connection_banner' ) ) { return; } // Don't show the connect notice anywhere but the plugins.php after activating if ( 'plugins' !== $current_screen->base && 'dashboard' !== $current_screen->base ) { return; } if ( ! current_user_can( 'jetpack_connect' ) ) { return; } 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, // we're falling back to the original flow on Safari desktop and mobile. if ( $is_safari ) { $force_variation = 'original'; } elseif ( Constants::is_true( 'JETPACK_SHOULD_USE_CONNECTION_IFRAME' ) ) { $force_variation = 'in_place'; } elseif ( Constants::is_defined( 'JETPACK_SHOULD_USE_CONNECTION_IFRAME' ) ) { $force_variation = 'original'; } else { $force_variation = null; } $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' => Jetpack::admin_url( 'page=jetpack#/plans-prompt' ), '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 */ function render_banner() { ?>