PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.1
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.1
16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 All 504 releases
← All changes | functions.global.php +104 -94 13.6.216.3-a.1 View file →
@@ -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,9 +32,9 @@
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 38 if ( ! str_starts_with( $version, 'jetpack-' ) ) {
38 39 return;
39 40 }
@@ -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 );
@@ -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 }
@@ -427,8 +430,9 @@
427 430 * Go through headers and get a list of Vary headers to add,
428 431 * including a Vary Accept header if necessary.
429 432 *
430 433 * @since 12.2
434 + * @deprecated 14.8
431 435 *
432 436 * @param array $headers The headers to be sent.
433 437 *
434 438 * @return array $vary_header_parts Vary Headers to be sent.
@@ -433,36 +437,11 @@
433 437 *
434 438 * @return array $vary_header_parts Vary Headers to be sent.
435 439 */
436 440 function jetpack_get_vary_headers( $headers = array() ) {
437 - $vary_header_parts = array( 'accept', 'content-type' );
441 + _deprecated_function( __FUNCTION__, '14.8', 'Automattic\Jetpack\Status\Request::get_vary_headers' );
438 442
439 - foreach ( $headers as $header ) {
440 - // Check for a Vary header.
441 - if ( ! str_starts_with( strtolower( $header ), 'vary:' ) ) {
442 - continue;
443 - }
444 -
445 - // If the header is a wildcard, we'll return that.
446 - if ( str_contains( $header, '*' ) ) {
447 - $vary_header_parts = array( '*' );
448 - break;
449 - }
450 -
451 - // Remove the Vary: part of the header.
452 - $header = preg_replace( '/^vary\:\s?/i', '', $header );
453 -
454 - // Remove spaces from the header.
455 - $header = str_replace( ' ', '', $header );
456 -
457 - // Break the header into parts.
458 - $header_parts = explode( ',', strtolower( $header ) );
459 -
460 - // Build an array with the Accept header and what was already there.
461 - $vary_header_parts = array_values( array_unique( array_merge( $vary_header_parts, $header_parts ) ) );
462 - }
463 -
464 - return $vary_header_parts;
443 + return ( new Request() )->get_vary_headers( $headers );
465 444 }
466 445
467 446 /**
468 447 * Determine whether the current request is for accessing the frontend.
@@ -467,83 +446,114 @@
467 446 /**
468 447 * Determine whether the current request is for accessing the frontend.
469 448 * Also update Vary headers to indicate that the response may vary by Accept header.
470 449 *
450 + * @deprecated 14.8
451 + *
471 452 * @return bool True if it's a frontend request, false otherwise.
472 453 */
473 454 function jetpack_is_frontend() {
474 - $is_frontend = true;
475 - $is_varying_request = true;
455 + _deprecated_function( __FUNCTION__, '14.8', 'Automattic\Jetpack\Status\Request::is_frontend' );
476 456
477 - if (
478 - is_admin()
479 - || wp_doing_ajax()
480 - || wp_is_jsonp_request()
481 - || is_feed()
482 - || ( defined( 'REST_REQUEST' ) && REST_REQUEST )
483 - || ( defined( 'REST_API_REQUEST' ) && REST_API_REQUEST )
484 - || ( defined( 'WP_CLI' ) && WP_CLI )
485 - ) {
486 - $is_frontend = false;
487 - $is_varying_request = false;
488 - } elseif (
489 - wp_is_json_request()
490 - || wp_is_xml_request()
491 - ) {
492 - $is_frontend = false;
493 - }
457 + return Request::is_frontend();
458 +}
494 459
495 - /*
496 - * Check existing headers for the request.
497 - * 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
498 471 */
499 - if ( $is_varying_request && ! headers_sent() ) {
500 - $headers = headers_list();
501 - $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 + );
502 486
503 - 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 );
504 497 }
498 +}
505 499
500 +if ( ! function_exists( 'jetpack_is_internal_testing_environment' ) ) {
506 501 /**
507 - * Filter whether the current request is for accessing the frontend.
502 + * Check if the site is an A8C-internal testing environment.
508 503 *
509 - * @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.
510 508 *
511 - * @param bool $is_frontend Whether the current request is for accessing the frontend.
512 - */
513 - return (bool) apply_filters( 'jetpack_is_frontend', $is_frontend );
514 -}
515 -
516 -/**
517 - * Build a list of Mastodon instance hosts.
518 - * That list can be extended via a filter.
519 - *
520 - * @since 11.8
521 - *
522 - * @return array
523 - */
524 -function jetpack_mastodon_get_instance_list() {
525 - $mastodon_instance_list = array(
526 - // Regex pattern to match any .tld for the mastodon host name.
527 - '#https?:\/\/(www\.)?mastodon\.(\w+)(\.\w+)?#',
528 - // Regex pattern to match any .tld for the mstdn host name.
529 - '#https?:\/\/(www\.)?mstdn\.(\w+)(\.\w+)?#',
530 - 'counter.social',
531 - 'fosstodon.org',
532 - 'gc2.jp',
533 - 'hachyderm.io',
534 - 'infosec.exchange',
535 - 'mas.to',
536 - 'pawoo.net',
537 - );
538 -
539 - /**
540 - * 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.
541 512 *
542 - * @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.
543 517 *
544 - * @module widgets, theme-tools
518 + * @since 15.8
545 519 *
546 - * @param array $mastodon_instance_list Array of Mastodon instances.
520 + * @return bool
547 521 */
548 - 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 + }
549 559 }