| @@ -12,13 +12,14 @@ | ||
| 12 | 12 | |
| 13 | 13 | use Automattic\Jetpack\Connection\Client; |
| 14 | 14 | use Automattic\Jetpack\Redirect; |
| 15 | 15 | use Automattic\Jetpack\Status\Host; |
| 16 | +use Automattic\Jetpack\Status\Request; | |
| 16 | 17 | use Automattic\Jetpack\Sync\Functions; |
| 17 | 18 | |
| 18 | 19 | // Disable direct access. |
| 19 | 20 | if ( ! defined( 'ABSPATH' ) ) { |
| 20 | - exit; | |
| 21 | + exit( 0 ); | |
| 21 | 22 | } |
| 22 | 23 | |
| 23 | 24 | require_once __DIR__ . '/functions.is-mobile.php'; |
| 24 | 25 | |
| @@ -31,11 +32,11 @@ | ||
| 31 | 32 | * @param string $function The function that was called. |
| 32 | 33 | * @param string $replacement Optional. The function that should have been called. Default null. |
| 33 | 34 | * @param string $version The version of Jetpack that deprecated the function. |
| 34 | 35 | */ |
| 35 | -function jetpack_deprecated_function( $function, $replacement, $version ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | |
| 36 | +function jetpack_deprecated_function( $function, $replacement, $version ) { | |
| 36 | 37 | // Bail early for non-Jetpack deprecations. |
| 37 | - if ( 0 !== strpos( $version, 'jetpack-' ) ) { | |
| 38 | + if ( ! str_starts_with( $version, 'jetpack-' ) ) { | |
| 38 | 39 | return; |
| 39 | 40 | } |
| 40 | 41 | |
| 41 | 42 | // Look for when a function will be removed based on when it was deprecated. |
| @@ -49,10 +50,12 @@ | ||
| 49 | 50 | && apply_filters( 'deprecated_function_trigger_error', true ) |
| 50 | 51 | ) { |
| 51 | 52 | error_log( // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log |
| 52 | 53 | sprintf( |
| 53 | - /* Translators: 1. Function name. 2. Jetpack version number. */ | |
| 54 | - __( 'The %1$s function will be removed from the Jetpack plugin in version %2$s.', 'jetpack' ), | |
| 54 | + doing_action( 'after_setup_theme' ) || did_action( 'after_setup_theme' ) ? | |
| 55 | + /* Translators: 1. Function name. 2. Jetpack version number. */ | |
| 56 | + __( 'The %1$s function will be removed from the Jetpack plugin in version %2$s.', 'jetpack' ) | |
| 57 | + : 'The %1$s function will be removed from the Jetpack plugin in version %2$s.', | |
| 55 | 58 | $function, |
| 56 | 59 | $removed_version |
| 57 | 60 | ) |
| 58 | 61 | ); |
| @@ -73,9 +76,9 @@ | ||
| 73 | 76 | * @param string $message A message regarding the change. |
| 74 | 77 | */ |
| 75 | 78 | function jetpack_deprecated_file( $file, $replacement, $version, $message ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
| 76 | 79 | // Bail early for non-Jetpack deprecations. |
| 77 | - if ( 0 !== strpos( $version, 'jetpack-' ) ) { | |
| 80 | + if ( ! str_starts_with( $version, 'jetpack-' ) ) { | |
| 78 | 81 | return; |
| 79 | 82 | } |
| 80 | 83 | |
| 81 | 84 | // Look for when a file will be removed based on when it was deprecated. |
| @@ -135,9 +138,9 @@ | ||
| 135 | 138 | |
| 136 | 139 | // We'll remove the function from the code 6 months later, thus 6 major versions later. |
| 137 | 140 | $removed_version = $deprecated_version + 0.6; |
| 138 | 141 | |
| 139 | - return (float) $removed_version; | |
| 142 | + return $removed_version; | |
| 140 | 143 | } |
| 141 | 144 | |
| 142 | 145 | return false; |
| 143 | 146 | } |
| @@ -250,10 +253,8 @@ | ||
| 250 | 253 | |
| 251 | 254 | /** |
| 252 | 255 | * Prints a TOS blurb used throughout the connection prompts. |
| 253 | 256 | * |
| 254 | - * Note: custom ToS messages are also defined in Jetpack_Pre_Connection_JITMs->get_raw_messages() | |
| 255 | - * | |
| 256 | 257 | * @since 5.3 |
| 257 | 258 | * |
| 258 | 259 | * @echo string |
| 259 | 260 | */ |
| @@ -260,9 +261,9 @@ | ||
| 260 | 261 | function jetpack_render_tos_blurb() { |
| 261 | 262 | printf( |
| 262 | 263 | wp_kses( |
| 263 | 264 | /* Translators: placeholders are links. */ |
| 264 | - __( 'By clicking the <strong>Set up Jetpack</strong> button, you agree to our <a href="%1$s" target="_blank" rel="noopener noreferrer">Terms of Service</a> and to <a href="%2$s" target="_blank" rel="noopener noreferrer">share details</a> with WordPress.com.', 'jetpack' ), | |
| 265 | + __( 'By clicking <strong>Set up Jetpack</strong>, you agree to our <a href="%1$s" target="_blank" rel="noopener noreferrer">Terms of Service</a> and to <a href="%2$s" target="_blank" rel="noopener noreferrer">sync your site‘s data</a> with us.', 'jetpack' ), | |
| 265 | 266 | array( |
| 266 | 267 | 'a' => array( |
| 267 | 268 | 'href' => array(), |
| 268 | 269 | 'target' => array(), |
| @@ -336,10 +337,10 @@ | ||
| 336 | 337 | * @since 6.1.0 |
| 337 | 338 | |
| 338 | 339 | * @deprecated Automattic\Jetpack\Sync\Functions::json_wrap |
| 339 | 340 | * |
| 340 | - * @param array|obj $any Source data to be cleaned up. | |
| 341 | - * @param array $seen_nodes Built array of nodes. | |
| 341 | + * @param mixed $any Source data to be cleaned up. | |
| 342 | + * @param array $seen_nodes Built array of nodes. | |
| 342 | 343 | * |
| 343 | 344 | * @return array |
| 344 | 345 | */ |
| 345 | 346 | function jetpack_json_wrap( &$any, $seen_nodes = array() ) { |
| @@ -429,8 +430,9 @@ | ||
| 429 | 430 | * Go through headers and get a list of Vary headers to add, |
| 430 | 431 | * including a Vary Accept header if necessary. |
| 431 | 432 | * |
| 432 | 433 | * @since 12.2 |
| 434 | + * @deprecated 14.8 | |
| 433 | 435 | * |
| 434 | 436 | * @param array $headers The headers to be sent. |
| 435 | 437 | * |
| 436 | 438 | * @return array $vary_header_parts Vary Headers to be sent. |
| @@ -435,36 +437,11 @@ | ||
| 435 | 437 | * |
| 436 | 438 | * @return array $vary_header_parts Vary Headers to be sent. |
| 437 | 439 | */ |
| 438 | 440 | function jetpack_get_vary_headers( $headers = array() ) { |
| 439 | - $vary_header_parts = array( 'accept', 'content-type' ); | |
| 441 | + _deprecated_function( __FUNCTION__, '14.8', 'Automattic\Jetpack\Status\Request::get_vary_headers' ); | |
| 440 | 442 | |
| 441 | - foreach ( $headers as $header ) { | |
| 442 | - // Check for a Vary header. | |
| 443 | - if ( 'vary:' !== substr( strtolower( $header ), 0, 5 ) ) { | |
| 444 | - continue; | |
| 445 | - } | |
| 446 | - | |
| 447 | - // If the header is a wildcard, we'll return that. | |
| 448 | - if ( false !== strpos( $header, '*' ) ) { | |
| 449 | - $vary_header_parts = array( '*' ); | |
| 450 | - break; | |
| 451 | - } | |
| 452 | - | |
| 453 | - // Remove the Vary: part of the header. | |
| 454 | - $header = preg_replace( '/^vary\:\s?/i', '', $header ); | |
| 455 | - | |
| 456 | - // Remove spaces from the header. | |
| 457 | - $header = str_replace( ' ', '', $header ); | |
| 458 | - | |
| 459 | - // Break the header into parts. | |
| 460 | - $header_parts = explode( ',', strtolower( $header ) ); | |
| 461 | - | |
| 462 | - // Build an array with the Accept header and what was already there. | |
| 463 | - $vary_header_parts = array_values( array_unique( array_merge( $vary_header_parts, $header_parts ) ) ); | |
| 464 | - } | |
| 465 | - | |
| 466 | - return $vary_header_parts; | |
| 443 | + return ( new Request() )->get_vary_headers( $headers ); | |
| 467 | 444 | } |
| 468 | 445 | |
| 469 | 446 | /** |
| 470 | 447 | * Determine whether the current request is for accessing the frontend. |
| @@ -469,83 +446,114 @@ | ||
| 469 | 446 | /** |
| 470 | 447 | * Determine whether the current request is for accessing the frontend. |
| 471 | 448 | * Also update Vary headers to indicate that the response may vary by Accept header. |
| 472 | 449 | * |
| 450 | + * @deprecated 14.8 | |
| 451 | + * | |
| 473 | 452 | * @return bool True if it's a frontend request, false otherwise. |
| 474 | 453 | */ |
| 475 | 454 | function jetpack_is_frontend() { |
| 476 | - $is_frontend = true; | |
| 477 | - $is_varying_request = true; | |
| 455 | + _deprecated_function( __FUNCTION__, '14.8', 'Automattic\Jetpack\Status\Request::is_frontend' ); | |
| 478 | 456 | |
| 479 | - if ( | |
| 480 | - is_admin() | |
| 481 | - || wp_doing_ajax() | |
| 482 | - || wp_is_jsonp_request() | |
| 483 | - || is_feed() | |
| 484 | - || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) | |
| 485 | - || ( defined( 'REST_API_REQUEST' ) && REST_API_REQUEST ) | |
| 486 | - || ( defined( 'WP_CLI' ) && WP_CLI ) | |
| 487 | - ) { | |
| 488 | - $is_frontend = false; | |
| 489 | - $is_varying_request = false; | |
| 490 | - } elseif ( | |
| 491 | - wp_is_json_request() | |
| 492 | - || wp_is_xml_request() | |
| 493 | - ) { | |
| 494 | - $is_frontend = false; | |
| 495 | - } | |
| 457 | + return Request::is_frontend(); | |
| 458 | +} | |
| 496 | 459 | |
| 497 | - /* | |
| 498 | - * Check existing headers for the request. | |
| 499 | - * If there is no existing Vary Accept header, add one. | |
| 460 | +if ( ! function_exists( 'jetpack_mastodon_get_instance_list' ) ) { | |
| 461 | + /** | |
| 462 | + * Build a list of Mastodon instance hosts. | |
| 463 | + * That list can be extended via a filter. | |
| 464 | + * | |
| 465 | + * @todo This function is now replicated in the Classic Theme Helper package and can be | |
| 466 | + * removed here once Social Links are moved out of Jetpack. | |
| 467 | + * | |
| 468 | + * @since 11.8 | |
| 469 | + * | |
| 470 | + * @return array | |
| 500 | 471 | */ |
| 501 | - if ( $is_varying_request && ! headers_sent() ) { | |
| 502 | - $headers = headers_list(); | |
| 503 | - $vary_header_parts = jetpack_get_vary_headers( $headers ); | |
| 472 | + function jetpack_mastodon_get_instance_list() { | |
| 473 | + $mastodon_instance_list = array( | |
| 474 | + // Regex pattern to match any .tld for the mastodon host name. | |
| 475 | + '#https?:\/\/(www\.)?mastodon\.(\w+)(\.\w+)?#', | |
| 476 | + // Regex pattern to match any .tld for the mstdn host name. | |
| 477 | + '#https?:\/\/(www\.)?mstdn\.(\w+)(\.\w+)?#', | |
| 478 | + 'counter.social', | |
| 479 | + 'fosstodon.org', | |
| 480 | + 'gc2.jp', | |
| 481 | + 'hachyderm.io', | |
| 482 | + 'infosec.exchange', | |
| 483 | + 'mas.to', | |
| 484 | + 'pawoo.net', | |
| 485 | + ); | |
| 504 | 486 | |
| 505 | - header( 'Vary: ' . implode( ', ', $vary_header_parts ) ); | |
| 487 | + /** | |
| 488 | + * Filter the list of Mastodon instances. | |
| 489 | + * | |
| 490 | + * @since 11.8 | |
| 491 | + * | |
| 492 | + * @module widgets, theme-tools | |
| 493 | + * | |
| 494 | + * @param array $mastodon_instance_list Array of Mastodon instances. | |
| 495 | + */ | |
| 496 | + return (array) apply_filters( 'jetpack_mastodon_instance_list', $mastodon_instance_list ); | |
| 506 | 497 | } |
| 498 | +} | |
| 507 | 499 | |
| 500 | +if ( ! function_exists( 'jetpack_is_internal_testing_environment' ) ) { | |
| 508 | 501 | /** |
| 509 | - * Filter whether the current request is for accessing the frontend. | |
| 502 | + * Check if the site is an A8C-internal testing environment. | |
| 510 | 503 | * |
| 511 | - * @since 9.0.0 | |
| 504 | + * Returns true for localhost, Jurassic Ninja/Tube sandboxes, A8C proxied | |
| 505 | + * requests, and known Atomic client IDs used for internal testing. Useful | |
| 506 | + * for tagging analytics events as test traffic so they can be filtered out | |
| 507 | + * of production reporting. | |
| 512 | 508 | * |
| 513 | - * @param bool $is_frontend Whether the current request is for accessing the frontend. | |
| 514 | - */ | |
| 515 | - return (bool) apply_filters( 'jetpack_is_frontend', $is_frontend ); | |
| 516 | -} | |
| 517 | - | |
| 518 | -/** | |
| 519 | - * Build a list of Mastodon instance hosts. | |
| 520 | - * That list can be extended via a filter. | |
| 521 | - * | |
| 522 | - * @since 11.8 | |
| 523 | - * | |
| 524 | - * @return array | |
| 525 | - */ | |
| 526 | -function jetpack_mastodon_get_instance_list() { | |
| 527 | - $mastodon_instance_list = array( | |
| 528 | - // Regex pattern to match any .tld for the mastodon host name. | |
| 529 | - '#https?:\/\/(www\.)?mastodon\.(\w+)(\.\w+)?#', | |
| 530 | - // Regex pattern to match any .tld for the mstdn host name. | |
| 531 | - '#https?:\/\/(www\.)?mstdn\.(\w+)(\.\w+)?#', | |
| 532 | - 'counter.social', | |
| 533 | - 'fosstodon.org', | |
| 534 | - 'gc2.jp', | |
| 535 | - 'hachyderm.io', | |
| 536 | - 'infosec.exchange', | |
| 537 | - 'mas.to', | |
| 538 | - 'pawoo.net', | |
| 539 | - ); | |
| 540 | - | |
| 541 | - /** | |
| 542 | - * Filter the list of Mastodon instances. | |
| 509 | + * Not to be confused with Jetpack's legacy "Development Mode", which is now | |
| 510 | + * Status::is_offline_mode() and controls whether Jetpack connects to | |
| 511 | + * WordPress.com. | |
| 543 | 512 | * |
| 544 | - * @since 11.8 | |
| 513 | + * Note: This intentionally duplicates the logic from | |
| 514 | + * Agents_Manager::is_dev_mode() in jetpack-agents-manager rather than calling | |
| 515 | + * it directly, because that package is only available on WordPress.com | |
| 516 | + * hosted sites, while Jetpack also runs on self-hosted sites. | |
| 545 | 517 | * |
| 546 | - * @module widgets, theme-tools | |
| 518 | + * @since 15.8 | |
| 547 | 519 | * |
| 548 | - * @param array $mastodon_instance_list Array of Mastodon instances. | |
| 520 | + * @return bool | |
| 549 | 521 | */ |
| 550 | - return (array) apply_filters( 'jetpack_mastodon_instance_list', $mastodon_instance_list ); | |
| 522 | + function jetpack_is_internal_testing_environment() { | |
| 523 | + // Known local environments. | |
| 524 | + $domain = (string) wp_parse_url( get_site_url(), PHP_URL_HOST ); | |
| 525 | + if ( | |
| 526 | + $domain === 'localhost' || | |
| 527 | + '.jurassic.tube' === stristr( $domain, '.jurassic.tube' ) || | |
| 528 | + '.jurassic.ninja' === stristr( $domain, '.jurassic.ninja' ) | |
| 529 | + ) { | |
| 530 | + return true; | |
| 531 | + } | |
| 532 | + | |
| 533 | + // Proxied A8C request via function. | |
| 534 | + if ( function_exists( 'wpcom_is_proxied_request' ) && wpcom_is_proxied_request() ) { | |
| 535 | + return true; | |
| 536 | + } | |
| 537 | + | |
| 538 | + // Proxied A8C request via server variable or constant. | |
| 539 | + if ( | |
| 540 | + ( isset( $_SERVER['A8C_PROXIED_REQUEST'] ) && (bool) sanitize_text_field( wp_unslash( $_SERVER['A8C_PROXIED_REQUEST'] ) ) ) || | |
| 541 | + ( defined( 'A8C_PROXIED_REQUEST' ) && A8C_PROXIED_REQUEST ) | |
| 542 | + ) { | |
| 543 | + return true; | |
| 544 | + } | |
| 545 | + | |
| 546 | + if ( defined( 'AT_PROXIED_REQUEST' ) && AT_PROXIED_REQUEST && defined( 'ATOMIC_CLIENT_ID' ) ) { | |
| 547 | + switch ( ATOMIC_CLIENT_ID ) { | |
| 548 | + case 1: | |
| 549 | + case 2: | |
| 550 | + case 3: | |
| 551 | + case 32: | |
| 552 | + case 118: | |
| 553 | + return true; | |
| 554 | + } | |
| 555 | + } | |
| 556 | + | |
| 557 | + return false; | |
| 558 | + } | |
| 551 | 559 | } |