jetpack
Last commit date
3rd-party
2 years ago
_inc
2 years ago
css
2 years ago
extensions
2 years ago
images
2 years ago
jetpack_vendor
14 hours ago
json-endpoints
2 years ago
modules
1 year ago
sal
2 years ago
src
3 years ago
vendor
2 years ago
views
3 years ago
CHANGELOG.md
2 years ago
LICENSE.txt
5 years ago
SECURITY.md
2 years ago
class-jetpack-connection-status.php
2 years ago
class-jetpack-connection-widget.php
2 years ago
class-jetpack-gallery-settings.php
3 years ago
class-jetpack-pre-connection-jitms.php
4 years ago
class-jetpack-recommendations-banner.php
2 years ago
class-jetpack-stats-dashboard-widget.php
2 years ago
class-jetpack-wizard-banner.php
5 years ago
class-jetpack-xmlrpc-methods.php
2 years ago
class.frame-nonce-preview.php
4 years ago
class.jetpack-admin.php
2 years ago
class.jetpack-affiliate.php
2 years ago
class.jetpack-autoupdate.php
2 years ago
class.jetpack-bbpress-json-api.compat.php
2 years ago
class.jetpack-boost-modules.php
3 years ago
class.jetpack-cli.php
2 years ago
class.jetpack-client-server.php
4 years ago
class.jetpack-connection-banner.php
2 years ago
class.jetpack-data.php
2 years ago
class.jetpack-gutenberg.php
2 years ago
class.jetpack-heartbeat.php
2 years ago
class.jetpack-idc.php
5 years ago
class.jetpack-modules-list-table.php
2 years ago
class.jetpack-network-sites-list-table.php
3 years ago
class.jetpack-network.php
3 years ago
class.jetpack-plan.php
3 years ago
class.jetpack-post-images.php
2 years ago
class.jetpack-twitter-cards.php
2 years ago
class.jetpack-user-agent.php
2 years ago
class.jetpack.php
2 years ago
class.json-api-endpoints.php
2 years ago
class.json-api.php
2 years ago
class.photon.php
3 years ago
composer.json
2 years ago
enhanced-open-graph.php
3 years ago
functions.compat.php
2 years ago
functions.cookies.php
2 years ago
functions.global.php
2 years ago
functions.is-mobile.php
2 years ago
functions.opengraph.php
2 years ago
functions.photon.php
2 years ago
jetpack.php
14 hours ago
json-api-config.php
3 years ago
json-endpoints.php
2 years ago
load-jetpack.php
3 years ago
locales.php
4 years ago
readme.txt
14 hours ago
uninstall.php
2 years ago
wpml-config.xml
4 years ago
class.jetpack-connection-banner.php
394 lines
| 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | /** |
| 3 | * Jetpack connection banner. |
| 4 | * DEPRECATED |
| 5 | * |
| 6 | * @package automattic/jetpack |
| 7 | */ |
| 8 | |
| 9 | use Automattic\Jetpack\Assets; |
| 10 | use Automattic\Jetpack\Assets\Logo; |
| 11 | use Automattic\Jetpack\Licensing; |
| 12 | |
| 13 | /** |
| 14 | * Jetpack connection banner. |
| 15 | * DEPRECATED - this banner has been removed as of version 13.0 |
| 16 | */ |
| 17 | class Jetpack_Connection_Banner { |
| 18 | /** |
| 19 | * Static instance. |
| 20 | * |
| 21 | * @var Jetpack_Connection_Banner |
| 22 | */ |
| 23 | private static $instance = null; |
| 24 | |
| 25 | /** |
| 26 | * Initialize and fetch the static instance. |
| 27 | * |
| 28 | * @return self |
| 29 | */ |
| 30 | public static function init() { |
| 31 | if ( self::$instance === null ) { |
| 32 | self::$instance = new Jetpack_Connection_Banner(); |
| 33 | } |
| 34 | |
| 35 | return self::$instance; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Jetpack_Connection_Banner constructor. |
| 40 | * |
| 41 | * Since we call the Jetpack_Connection_Banner:init() method from the `Jetpack` class, and after |
| 42 | * the admin_init action fires, we know that the admin is initialized at this point. |
| 43 | */ |
| 44 | private function __construct() { |
| 45 | add_action( 'current_screen', array( $this, 'maybe_initialize_hooks' ) ); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * The banner is forcibly displayed. |
| 50 | * |
| 51 | * @return bool |
| 52 | */ |
| 53 | public static function force_display() { |
| 54 | /** |
| 55 | * This is an experiment for partners to test. Allow customization of the behavior of pre-connection banners. |
| 56 | * |
| 57 | * @since 8.6.0 |
| 58 | * |
| 59 | * @param bool $always_show_prompt Should this prompt always appear? Default to false. |
| 60 | */ |
| 61 | return apply_filters( 'jetpack_pre_connection_prompt_helpers', false ); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Can the banner be displayed for the given screen? |
| 66 | * |
| 67 | * @param \WP_Screen $current_screen Current WordPress screen. |
| 68 | * |
| 69 | * @return bool |
| 70 | */ |
| 71 | public static function can_be_displayed( $current_screen ) { |
| 72 | $has_connected_owner = Jetpack::connection()->has_connected_owner(); |
| 73 | $is_connected = Jetpack::is_connection_ready(); |
| 74 | $has_licenses = ! empty( Licensing::instance()->stored_licenses() ); |
| 75 | |
| 76 | // Don't show the connect notice if the site has a connected owner. |
| 77 | if ( $has_connected_owner ) { |
| 78 | return false; |
| 79 | } |
| 80 | |
| 81 | // Don't show the connect notice if a site connection is established and there are no stored licenses. |
| 82 | // Stored licenses indicate that a purchased product may not be provisioned yet hence we need to keep |
| 83 | // showing the notice to nudge the user to connect in order to have their product(s) provisioned. |
| 84 | if ( $is_connected && ! $has_licenses ) { |
| 85 | return false; |
| 86 | } |
| 87 | |
| 88 | // Kill if banner has been dismissed and the pre-connection helpers filter is not set. |
| 89 | if ( |
| 90 | Jetpack_Options::get_option( 'dismissed_connection_banner' ) && |
| 91 | ! self::force_display() |
| 92 | ) { |
| 93 | return false; |
| 94 | } |
| 95 | |
| 96 | // Don't show the connect notice anywhere but the plugins.php after activating. |
| 97 | if ( 'plugins' !== $current_screen->base && 'dashboard' !== $current_screen->base ) { |
| 98 | return false; |
| 99 | } |
| 100 | |
| 101 | if ( ! current_user_can( 'jetpack_connect' ) ) { |
| 102 | return false; |
| 103 | } |
| 104 | |
| 105 | return true; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Given a string for the the banner was added, and an int that represents the slide to |
| 110 | * a URL for, this function returns a connection URL with a from parameter that will |
| 111 | * support split testing. |
| 112 | * |
| 113 | * @since 7.2 Event key format is now banner-connect-banner-72-dashboard or connect-banner-72-plugins. |
| 114 | * The param $slide_num was removed since we removed all slides but the first one. |
| 115 | * @since 4.4.0 |
| 116 | * |
| 117 | * @param string $jp_version_banner_added A short version of when the banner was added. Ex. 44. |
| 118 | * @return string |
| 119 | */ |
| 120 | public function build_connect_url_for_slide( $jp_version_banner_added ) { |
| 121 | global $current_screen; |
| 122 | $url = Jetpack::init()->build_connect_url( |
| 123 | true, |
| 124 | false, |
| 125 | sprintf( 'connect-banner-%s-%s', $jp_version_banner_added, $current_screen->base ) |
| 126 | ); |
| 127 | return add_query_arg( 'auth_approved', 'true', $url ); |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Will initialize hooks to display the new (as of 4.4) connection banner if the current user can |
| 132 | * connect Jetpack, if Jetpack has not been deactivated, and if the current page is the plugins or dashboard page. |
| 133 | * |
| 134 | * @since 4.4.0 |
| 135 | * @since 4.5.0 Made the new (as of 4.4) connection banner display to everyone by default. |
| 136 | * @since 5.3.0 Running another split test between 4.4 banner and a new one in 5.3. |
| 137 | * @since 7.2 B test was removed. |
| 138 | * @since 9.7 Moved the connection condition checking to this method to fulfill Licensing requirements. |
| 139 | * |
| 140 | * @param \WP_Screen $current_screen Current WordPress screen. |
| 141 | */ |
| 142 | public function maybe_initialize_hooks( $current_screen ) { |
| 143 | if ( ! self::can_be_displayed( $current_screen ) ) { |
| 144 | return; |
| 145 | } |
| 146 | |
| 147 | if ( ! empty( Licensing::instance()->stored_licenses() ) ) { |
| 148 | add_action( 'admin_notices', array( $this, 'render_license_aware_banner' ) ); |
| 149 | } else { |
| 150 | add_action( 'admin_notices', array( $this, 'render_banner' ) ); |
| 151 | } |
| 152 | |
| 153 | add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_banner_scripts' ) ); |
| 154 | add_action( 'admin_print_styles', array( $this, 'admin_banner_styles' ) ); |
| 155 | |
| 156 | if ( Jetpack::state( 'network_nag' ) ) { |
| 157 | add_action( 'network_admin_notices', array( $this, 'network_connect_notice' ) ); |
| 158 | } |
| 159 | |
| 160 | // Only fires immediately after plugin activation. |
| 161 | if ( get_transient( 'activated_jetpack' ) ) { |
| 162 | if ( |
| 163 | ! \Jetpack_Options::get_option( 'has_seen_wc_connection_modal', false ) |
| 164 | && in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', Jetpack::get_active_plugins() ), true ) |
| 165 | ) { |
| 166 | wp_safe_redirect( Jetpack::admin_url( 'page=jetpack#/woo-setup' ) ); |
| 167 | } else { |
| 168 | add_action( 'admin_enqueue_scripts', array( Jetpack::init(), 'activate_dialog' ) ); |
| 169 | } |
| 170 | delete_transient( 'activated_jetpack' ); |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Include the needed styles |
| 176 | */ |
| 177 | public function admin_banner_styles() { |
| 178 | wp_enqueue_style( |
| 179 | 'jetpack-connection-banner', |
| 180 | Assets::get_file_url_for_environment( |
| 181 | 'css/jetpack-connection-banner.min.css', |
| 182 | 'css/jetpack-connection-banner.css' |
| 183 | ), |
| 184 | array(), |
| 185 | JETPACK__VERSION |
| 186 | ); |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * Enqueues JavaScript for new connection banner. |
| 191 | * |
| 192 | * @since 4.4.0 |
| 193 | */ |
| 194 | public static function enqueue_banner_scripts() { |
| 195 | wp_enqueue_script( |
| 196 | 'jetpack-connection-banner-js', |
| 197 | Assets::get_file_url_for_environment( |
| 198 | '_inc/build/jetpack-connection-banner.min.js', |
| 199 | '_inc/jetpack-connection-banner.js' |
| 200 | ), |
| 201 | array( 'jquery' ), |
| 202 | JETPACK__VERSION, |
| 203 | true |
| 204 | ); |
| 205 | |
| 206 | wp_localize_script( |
| 207 | 'jetpack-connection-banner-js', |
| 208 | 'jp_banner', |
| 209 | array( |
| 210 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 211 | 'connectionBannerNonce' => wp_create_nonce( 'jp-connection-banner-nonce' ), |
| 212 | ) |
| 213 | ); |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * Enqueues JavaScript and CSS for the connection button. |
| 218 | * |
| 219 | * @since 7.7 |
| 220 | */ |
| 221 | public static function enqueue_connect_button_scripts() { |
| 222 | wp_enqueue_script( |
| 223 | 'jetpack-connect-button', |
| 224 | Assets::get_file_url_for_environment( |
| 225 | '_inc/build/connect-button.min.js', |
| 226 | '_inc/connect-button.js' |
| 227 | ), |
| 228 | array( 'jquery' ), |
| 229 | JETPACK__VERSION, |
| 230 | true |
| 231 | ); |
| 232 | |
| 233 | wp_enqueue_style( |
| 234 | 'jetpack-connect-button', |
| 235 | Assets::get_file_url_for_environment( |
| 236 | 'css/jetpack-connect.min.css', |
| 237 | 'css/jetpack-connect.css' |
| 238 | ), |
| 239 | array(), |
| 240 | JETPACK__VERSION |
| 241 | ); |
| 242 | |
| 243 | $tracking = new Automattic\Jetpack\Tracking(); |
| 244 | $identity = $tracking->tracks_get_identity( get_current_user_id() ); |
| 245 | |
| 246 | wp_localize_script( |
| 247 | 'jetpack-connect-button', |
| 248 | 'jpConnect', |
| 249 | array( |
| 250 | 'buttonTextRegistering' => __( 'Loading...', 'jetpack' ), |
| 251 | 'connectUrl' => Jetpack::admin_url( 'page=jetpack#/setup' ), |
| 252 | 'identity' => $identity, |
| 253 | 'preFetchScript' => plugins_url( '_inc/build/admin.js', JETPACK__PLUGIN_FILE ) . '?ver=' . JETPACK__VERSION, |
| 254 | ) |
| 255 | ); |
| 256 | } |
| 257 | |
| 258 | /** |
| 259 | * Renders the new connection banner as of 4.4.0. |
| 260 | * |
| 261 | * @since 4.4.0 |
| 262 | * @since 7.2 Copy and visual elements reduced to show the new focus of Jetpack on Security and Performance. |
| 263 | * @since 11.1 Adjusted the banner to Emerald style |
| 264 | */ |
| 265 | public function render_banner() { |
| 266 | $jetpack_logo = new Logo(); |
| 267 | ?> |
| 268 | <div class="jp-connection-banner"> |
| 269 | <div class="jp-connection-banner__container-top-text"> |
| 270 | <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><rect x="0" fill="none" width="24" height="24"/><g><path d="M12 2C6.477 2 2 6.477 2 12s4.477 10 10 10 10-4.477 10-10S17.523 2 12 2zm1 15h-2v-2h2v2zm0-4h-2l-.5-6h3l-.5 6z"/></g></svg> |
| 271 | <span> |
| 272 | <?php esc_html_e( 'You’re almost done. Set up Jetpack to enable powerful security and performance tools for WordPress.', 'jetpack' ); ?> |
| 273 | </span> |
| 274 | </div> |
| 275 | <?php |
| 276 | if ( ! static::force_display() ) : |
| 277 | ?> |
| 278 | <span |
| 279 | class="notice-dismiss jp-connection-banner__dismiss" |
| 280 | title="<?php esc_attr_e( 'Dismiss this notice', 'jetpack' ); ?>"> |
| 281 | </span> |
| 282 | |
| 283 | <?php |
| 284 | endif; |
| 285 | ?> |
| 286 | <div class="jp-connection-banner__inner"> |
| 287 | <div class="jp-connection-banner__content"> |
| 288 | <div class="jp-connection-banner__logo"> |
| 289 | <?php echo $jetpack_logo->get_jp_emblem_larger(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> |
| 290 | </div> |
| 291 | <h2 class="jp-connection-banner__title"><?php esc_html_e( 'Simplify your site security and performance with Jetpack', 'jetpack' ); ?></h2> |
| 292 | <div class="jp-connection-banner__columns"> |
| 293 | <div class="jp-connection-banner__text"><?php esc_html_e( 'Jetpack provides easy-to-use, comprehensive WordPress site security and backups, so you can focus on running your business.', 'jetpack' ); ?></div> |
| 294 | <div class="jp-connection-banner__text"><?php esc_html_e( 'Jetpack’s performance features make your site lightning-fast, while also improving your SEO and giving your visitors a better experience.', 'jetpack' ); ?></div> |
| 295 | </div> |
| 296 | <div class="jp-connection-banner__footer"> |
| 297 | <div class="jp-connection-banner__text jp-connection-banner__text--caption"><?php jetpack_render_tos_blurb(); ?></div> |
| 298 | <a id="jp-connect-button--alt" href="<?php echo esc_url( $this->build_connect_url_for_slide( '111' ) ); ?>" class="jp-banner-cta-button"> |
| 299 | <?php esc_html_e( 'Set up Jetpack', 'jetpack' ); ?> |
| 300 | </a> |
| 301 | </div> |
| 302 | </div> |
| 303 | <div class="jp-connection-banner__image-container"> |
| 304 | <img class="jp-connection-banner__image-background" src="<?php echo esc_url( plugins_url( 'images/jetpack-connection-banner-background.svg', JETPACK__PLUGIN_FILE ) ); ?>" /> |
| 305 | <picture> |
| 306 | <source |
| 307 | type="image/webp" |
| 308 | srcset="<?php echo esc_url( plugins_url( 'images/jetpack-connection-image.webp', JETPACK__PLUGIN_FILE ) ); ?> 1x, <?php echo esc_url( plugins_url( 'images/jetpack-connection-image-2x.webp', JETPACK__PLUGIN_FILE ) ); ?> 2x"> |
| 309 | <img |
| 310 | class="jp-connection-banner__image" |
| 311 | srcset="<?php echo esc_url( plugins_url( 'images/jetpack-connection-image.png', JETPACK__PLUGIN_FILE ) ); ?> 1x, <?php echo esc_url( plugins_url( 'images/jetpack-connection-image-2x.png', JETPACK__PLUGIN_FILE ) ); ?> 2x" |
| 312 | src="<?php echo esc_url( plugins_url( 'images/jetpack-connection-image.png', JETPACK__PLUGIN_FILE ) ); ?>" |
| 313 | alt=""> |
| 314 | </picture> |
| 315 | </div> |
| 316 | </div> |
| 317 | </div> |
| 318 | <?php |
| 319 | } |
| 320 | |
| 321 | /** |
| 322 | * Renders the license-away version of the connection banner. |
| 323 | * |
| 324 | * @since 9.0.0 |
| 325 | * @since 11.1 Adjusted the banner to Emerald style |
| 326 | */ |
| 327 | public function render_license_aware_banner() { |
| 328 | $jetpack_logo = new Logo(); |
| 329 | ?> |
| 330 | <div class="jp-connection-banner"> |
| 331 | <div class="jp-connection-banner__inner"> |
| 332 | <div class="jp-connection-banner__content"> |
| 333 | <div class="jp-connection-banner__logo"> |
| 334 | <?php echo $jetpack_logo->get_jp_emblem_larger(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> |
| 335 | </div> |
| 336 | <h2 class="jp-connection-banner__title jp-connection-banner__title--warning"> |
| 337 | <svg height="38" width="38" viewBox="0 0 24 24" class="jp-connection-banner__warning-icon"> |
| 338 | <g> |
| 339 | <rect x="8" y="6" width="8" height="12" style="fill:#000000" /> |
| 340 | <path d="M12 2C6.477 2 2 6.477 2 12s4.477 10 10 10 10-4.477 10-10S17.523 2 12 2zm1 15h-2v-2h2v2zm0-4h-2l-.5-6h3l-.5 6z" style="fill:#eec74f"></path> |
| 341 | </g> |
| 342 | </svg> |
| 343 | <?php esc_html_e( 'Finish setting up Jetpack', 'jetpack' ); ?> |
| 344 | </h2> |
| 345 | <div class="jp-connection-banner__text"><?php esc_html_e( "Thanks for purchasing a Jetpack subscription.\nThere’s just one more step to complete the installation.", 'jetpack' ); ?></div> |
| 346 | <div class="jp-connection-banner__footer"> |
| 347 | <div class="jp-connection-banner__text jp-connection-banner__text--caption"><?php jetpack_render_tos_blurb(); ?></div> |
| 348 | <a id="jp-connect-button--alt" href="<?php echo esc_url( $this->build_connect_url_for_slide( '111' ) ); ?>" class="jp-banner-cta-button"> |
| 349 | <?php esc_html_e( 'Set up Jetpack', 'jetpack' ); ?> |
| 350 | </a> |
| 351 | </div> |
| 352 | </div> |
| 353 | <div class="jp-connection-banner__image-container"> |
| 354 | <img class="jp-connection-banner__image-background" src="<?php echo esc_url( plugins_url( 'images/jetpack-connection-banner-background.svg', JETPACK__PLUGIN_FILE ) ); ?>" /> |
| 355 | <picture> |
| 356 | <source |
| 357 | type="image/webp" |
| 358 | srcset="<?php echo esc_url( plugins_url( 'images/jetpack-connection-image.webp', JETPACK__PLUGIN_FILE ) ); ?> 1x, <?php echo esc_url( plugins_url( 'images/jetpack-connection-image-2x.webp', JETPACK__PLUGIN_FILE ) ); ?> 2x"> |
| 359 | <img |
| 360 | class="jp-connection-banner__image" |
| 361 | srcset="<?php echo esc_url( plugins_url( 'images/jetpack-connection-image.png', JETPACK__PLUGIN_FILE ) ); ?> 1x, <?php echo esc_url( plugins_url( 'images/jetpack-connection-image-2x.png', JETPACK__PLUGIN_FILE ) ); ?> 2x" |
| 362 | src="<?php echo esc_url( plugins_url( 'images/jetpack-connection-image.png', JETPACK__PLUGIN_FILE ) ); ?>" |
| 363 | alt=""> |
| 364 | </picture> |
| 365 | </div> |
| 366 | </div> |
| 367 | </div> |
| 368 | <?php |
| 369 | } |
| 370 | |
| 371 | /** |
| 372 | * Renders the legacy network connection banner. |
| 373 | */ |
| 374 | public function network_connect_notice() { |
| 375 | ?> |
| 376 | <div id="message" class="updated jetpack-message"> |
| 377 | <div class="squeezer"> |
| 378 | <h2> |
| 379 | <?php |
| 380 | echo wp_kses( |
| 381 | __( |
| 382 | '<strong>Jetpack is activated!</strong> Each site on your network must be connected individually by an admin on that site.', |
| 383 | 'jetpack' |
| 384 | ), |
| 385 | array( 'strong' => array() ) |
| 386 | ); |
| 387 | ?> |
| 388 | </h2> |
| 389 | </div> |
| 390 | </div> |
| 391 | <?php |
| 392 | } |
| 393 | } |
| 394 |