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 +111 -105 12.5.216.3-a.1 View file →
@@ -1,5 +1,5 @@
1 -<?php
1 +<?php // phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase
2 2 /**
3 3 * This file is meant to be the home for any generic & reusable functions
4 4 * that can be accessed anywhere within Jetpack.
5 5 *
@@ -12,15 +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.
20 - */
19 +// Disable direct access.
21 20 if ( ! defined( 'ABSPATH' ) ) {
22 - exit;
21 + exit( 0 );
23 22 }
24 23
25 24 require_once __DIR__ . '/functions.is-mobile.php';
26 25
@@ -33,11 +32,11 @@
33 32 * @param string $function The function that was called.
34 33 * @param string $replacement Optional. The function that should have been called. Default null.
35 34 * @param string $version The version of Jetpack that deprecated the function.
36 35 */
37 -function jetpack_deprecated_function( $function, $replacement, $version ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
36 +function jetpack_deprecated_function( $function, $replacement, $version ) {
38 37 // Bail early for non-Jetpack deprecations.
39 - if ( 0 !== strpos( $version, 'jetpack-' ) ) {
38 + if ( ! str_starts_with( $version, 'jetpack-' ) ) {
40 39 return;
41 40 }
42 41
43 42 // Look for when a function will be removed based on when it was deprecated.
@@ -51,10 +50,12 @@
51 50 && apply_filters( 'deprecated_function_trigger_error', true )
52 51 ) {
53 52 error_log( // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
54 53 sprintf(
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' ),
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.',
57 58 $function,
58 59 $removed_version
59 60 )
60 61 );
@@ -75,9 +76,9 @@
75 76 * @param string $message A message regarding the change.
76 77 */
77 78 function jetpack_deprecated_file( $file, $replacement, $version, $message ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
78 79 // Bail early for non-Jetpack deprecations.
79 - if ( 0 !== strpos( $version, 'jetpack-' ) ) {
80 + if ( ! str_starts_with( $version, 'jetpack-' ) ) {
80 81 return;
81 82 }
82 83
83 84 // Look for when a file will be removed based on when it was deprecated.
@@ -137,9 +138,9 @@
137 138
138 139 // We'll remove the function from the code 6 months later, thus 6 major versions later.
139 140 $removed_version = $deprecated_version + 0.6;
140 141
141 - return (float) $removed_version;
142 + return $removed_version;
142 143 }
143 144
144 145 return false;
145 146 }
@@ -252,10 +253,8 @@
252 253
253 254 /**
254 255 * Prints a TOS blurb used throughout the connection prompts.
255 256 *
256 - * Note: custom ToS messages are also defined in Jetpack_Pre_Connection_JITMs->get_raw_messages()
257 - *
258 257 * @since 5.3
259 258 *
260 259 * @echo string
261 260 */
@@ -262,9 +261,9 @@
262 261 function jetpack_render_tos_blurb() {
263 262 printf(
264 263 wp_kses(
265 264 /* Translators: placeholders are links. */
266 - __( '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' ),
267 266 array(
268 267 'a' => array(
269 268 'href' => array(),
270 269 'target' => array(),
@@ -338,10 +337,10 @@
338 337 * @since 6.1.0
339 338
340 339 * @deprecated Automattic\Jetpack\Sync\Functions::json_wrap
341 340 *
342 - * @param array|obj $any Source data to be cleaned up.
343 - * @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.
344 343 *
345 344 * @return array
346 345 */
347 346 function jetpack_json_wrap( &$any, $seen_nodes = array() ) {
@@ -431,8 +430,9 @@
431 430 * Go through headers and get a list of Vary headers to add,
432 431 * including a Vary Accept header if necessary.
433 432 *
434 433 * @since 12.2
434 + * @deprecated 14.8
435 435 *
436 436 * @param array $headers The headers to be sent.
437 437 *
438 438 * @return array $vary_header_parts Vary Headers to be sent.
@@ -437,36 +437,11 @@
437 437 *
438 438 * @return array $vary_header_parts Vary Headers to be sent.
439 439 */
440 440 function jetpack_get_vary_headers( $headers = array() ) {
441 - $vary_header_parts = array( 'accept', 'content-type' );
441 + _deprecated_function( __FUNCTION__, '14.8', 'Automattic\Jetpack\Status\Request::get_vary_headers' );
442 442
443 - foreach ( $headers as $header ) {
444 - // Check for a Vary header.
445 - if ( 'vary:' !== substr( strtolower( $header ), 0, 5 ) ) {
446 - continue;
447 - }
448 -
449 - // If the header is a wildcard, we'll return that.
450 - if ( false !== strpos( $header, '*' ) ) {
451 - $vary_header_parts = array( '*' );
452 - break;
453 - }
454 -
455 - // Remove the Vary: part of the header.
456 - $header = preg_replace( '/^vary\:\s?/i', '', $header );
457 -
458 - // Remove spaces from the header.
459 - $header = str_replace( ' ', '', $header );
460 -
461 - // Break the header into parts.
462 - $header_parts = explode( ',', strtolower( $header ) );
463 -
464 - // Build an array with the Accept header and what was already there.
465 - $vary_header_parts = array_values( array_unique( array_merge( $vary_header_parts, $header_parts ) ) );
466 - }
467 -
468 - return $vary_header_parts;
443 + return ( new Request() )->get_vary_headers( $headers );
469 444 }
470 445
471 446 /**
472 447 * Determine whether the current request is for accessing the frontend.
@@ -471,83 +446,114 @@
471 446 /**
472 447 * Determine whether the current request is for accessing the frontend.
473 448 * Also update Vary headers to indicate that the response may vary by Accept header.
474 449 *
450 + * @deprecated 14.8
451 + *
475 452 * @return bool True if it's a frontend request, false otherwise.
476 453 */
477 454 function jetpack_is_frontend() {
478 - $is_frontend = true;
479 - $is_varying_request = true;
455 + _deprecated_function( __FUNCTION__, '14.8', 'Automattic\Jetpack\Status\Request::is_frontend' );
480 456
481 - if (
482 - is_admin()
483 - || wp_doing_ajax()
484 - || wp_is_jsonp_request()
485 - || is_feed()
486 - || ( defined( 'REST_REQUEST' ) && REST_REQUEST )
487 - || ( defined( 'REST_API_REQUEST' ) && REST_API_REQUEST )
488 - || ( defined( 'WP_CLI' ) && WP_CLI )
489 - ) {
490 - $is_frontend = false;
491 - $is_varying_request = false;
492 - } elseif (
493 - wp_is_json_request()
494 - || wp_is_xml_request()
495 - ) {
496 - $is_frontend = false;
497 - }
457 + return Request::is_frontend();
458 +}
498 459
499 - /*
500 - * Check existing headers for the request.
501 - * 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
502 471 */
503 - if ( $is_varying_request && ! headers_sent() ) {
504 - $headers = headers_list();
505 - $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 + );
506 486
507 - 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 );
508 497 }
498 +}
509 499
500 +if ( ! function_exists( 'jetpack_is_internal_testing_environment' ) ) {
510 501 /**
511 - * Filter whether the current request is for accessing the frontend.
502 + * Check if the site is an A8C-internal testing environment.
512 503 *
513 - * @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.
514 508 *
515 - * @param bool $is_frontend Whether the current request is for accessing the frontend.
516 - */
517 - return (bool) apply_filters( 'jetpack_is_frontend', $is_frontend );
518 -}
519 -
520 -/**
521 - * Build a list of Mastodon instance hosts.
522 - * That list can be extended via a filter.
523 - *
524 - * @since 11.8
525 - *
526 - * @return array
527 - */
528 -function jetpack_mastodon_get_instance_list() {
529 - $mastodon_instance_list = array(
530 - // Regex pattern to match any .tld for the mastodon host name.
531 - '#https?:\/\/(www\.)?mastodon\.(\w+)(\.\w+)?#',
532 - // Regex pattern to match any .tld for the mstdn host name.
533 - '#https?:\/\/(www\.)?mstdn\.(\w+)(\.\w+)?#',
534 - 'counter.social',
535 - 'fosstodon.org',
536 - 'gc2.jp',
537 - 'hachyderm.io',
538 - 'infosec.exchange',
539 - 'mas.to',
540 - 'pawoo.net',
541 - );
542 -
543 - /**
544 - * 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.
545 512 *
546 - * @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.
547 517 *
548 - * @module widgets, theme-tools
518 + * @since 15.8
549 519 *
550 - * @param array $mastodon_instance_list Array of Mastodon instances.
520 + * @return bool
551 521 */
552 - 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 + }
553 559 }