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 +127 -63 12.0.3 → 16.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.
@@ -119,9 +120,9 @@
119 120 * (let's only keep the first decimal, e.g. 8.8 and not 8.8.0)
120 121 */
121 122 preg_match( '#(([0-9]+\.([0-9]+))(?:\.[0-9]+)*)#', $version, $matches );
122 123
123 - if ( isset( $matches[2], $matches[3] ) ) {
124 + if ( isset( $matches[2] ) && isset( $matches[3] ) ) {
124 125 $deprecated_version = (float) $matches[2];
125 126 $deprecated_minor = (float) $matches[3];
126 127
127 128 /*
@@ -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() ) {
@@ -427,69 +426,134 @@
427 426 return in_array( $type, $supported_mime_types, true );
428 427 }
429 428
430 429 /**
430 + * Go through headers and get a list of Vary headers to add,
431 + * including a Vary Accept header if necessary.
432 + *
433 + * @since 12.2
434 + * @deprecated 14.8
435 + *
436 + * @param array $headers The headers to be sent.
437 + *
438 + * @return array $vary_header_parts Vary Headers to be sent.
439 + */
440 +function jetpack_get_vary_headers( $headers = array() ) {
441 + _deprecated_function( __FUNCTION__, '14.8', 'Automattic\Jetpack\Status\Request::get_vary_headers' );
442 +
443 + return ( new Request() )->get_vary_headers( $headers );
444 +}
445 +
446 +/**
431 447 * Determine whether the current request is for accessing the frontend.
448 + * Also update Vary headers to indicate that the response may vary by Accept header.
432 449 *
450 + * @deprecated 14.8
451 + *
433 452 * @return bool True if it's a frontend request, false otherwise.
434 453 */
435 454 function jetpack_is_frontend() {
436 - $is_frontend = true;
455 + _deprecated_function( __FUNCTION__, '14.8', 'Automattic\Jetpack\Status\Request::is_frontend' );
437 456
438 - if (
439 - is_admin() ||
440 - wp_doing_ajax() ||
441 - wp_is_json_request() ||
442 - wp_is_jsonp_request() ||
443 - wp_is_xml_request() ||
444 - is_feed() ||
445 - ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ||
446 - ( defined( 'REST_API_REQUEST' ) && REST_API_REQUEST ) ||
447 - ( defined( 'WP_CLI' ) && WP_CLI )
448 - ) {
449 - $is_frontend = false;
450 - }
457 + return Request::is_frontend();
458 +}
451 459
460 +if ( ! function_exists( 'jetpack_mastodon_get_instance_list' ) ) {
452 461 /**
453 - * Filter whether the current request is for accessing the frontend.
462 + * Build a list of Mastodon instance hosts.
463 + * That list can be extended via a filter.
454 464 *
455 - * @since 9.0.0
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.
456 467 *
457 - * @param bool $is_frontend Whether the current request is for accessing the frontend.
468 + * @since 11.8
469 + *
470 + * @return array
458 471 */
459 - return (bool) apply_filters( 'jetpack_is_frontend', $is_frontend );
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 + );
486 +
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 );
497 + }
460 498 }
461 499
462 -/**
463 - * Build a list of Mastodon instance hosts.
464 - * That list can be extended via a filter.
465 - *
466 - * @since 11.8
467 - *
468 - * @return array
469 - */
470 -function jetpack_mastodon_get_instance_list() {
471 - $mastodon_instance_list = array(
472 - // Regex pattern to match any .tld for the mastodon host name.
473 - '#https?:\/\/(www\.)?mastodon\.(\w+)(\.\w+)?#',
474 - // Regex pattern to match any .tld for the mstdn host name.
475 - '#https?:\/\/(www\.)?mstdn\.(\w+)(\.\w+)?#',
476 - 'counter.social',
477 - 'fosstodon.org',
478 - 'gc2.jp',
479 - 'hachyderm.io',
480 - 'infosec.exchange',
481 - 'mas.to',
482 - 'pawoo.net',
483 - );
484 -
500 +if ( ! function_exists( 'jetpack_is_internal_testing_environment' ) ) {
485 501 /**
486 - * Filter the list of Mastodon instances.
502 + * Check if the site is an A8C-internal testing environment.
487 503 *
488 - * @since 11.8
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.
489 508 *
490 - * @module widgets, theme-tools
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.
491 512 *
492 - * @param array $mastodon_instance_list Array of Mastodon instances.
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.
517 + *
518 + * @since 15.8
519 + *
520 + * @return bool
493 521 */
494 - 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 + }
495 559 }