updated plugin Jetpack Protect version 5.0.0

This commit is contained in:
2026-06-03 21:29:05 +00:00
committed by Gitium
parent 0490bb3940
commit af21e84842
399 changed files with 17749 additions and 5470 deletions

View File

@ -25,7 +25,7 @@ class CookieState {
*/
public function state( $key = null, $value = null, $restate = false ) {
static $state = array();
static $path, $domain;
static $path, $domain; // this initializes values to null
if ( ! isset( $path ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
$admin_url = ( new Paths() )->admin_url();
@ -34,9 +34,6 @@ class CookieState {
if ( is_array( $bits ) ) {
$path = ( isset( $bits['path'] ) ) ? dirname( $bits['path'] ) : null;
$domain = ( isset( $bits['host'] ) ) ? $bits['host'] : null;
} else {
$path = null;
$domain = null;
}
}
@ -49,6 +46,7 @@ class CookieState {
if ( strlen( $v ) ) {
$state[ $k ] = $v;
}
// @phan-suppress-next-line PhanTypeMismatchArgumentInternal -- Setting cookie to false is valid and documented for deletion.
setcookie( "jetpackState[$k]", false, 0, $path, $domain, is_ssl(), true );
}
}

View File

@ -40,7 +40,9 @@ class Errors {
} else {
// Restore the original values for error reporting and output.
@ini_set( 'display_errors', $display_errors );
@error_reporting( $error_reporting );
if ( $error_reporting !== null ) {
@error_reporting( $error_reporting );
}
if ( class_exists( 'Jetpack' ) ) {
remove_action( 'shutdown', array( 'Jetpack', 'catch_errors_on_shutdown' ), 0 );
}

View File

@ -78,6 +78,34 @@ class Host {
return $this->is_wpcom_simple() || $this->is_woa_site();
}
/**
* Determine if this is a P2 site.
* This covers both P2 and P2020 themes.
*
* @return bool
*/
public function is_p2_site() {
$site_id = $this->get_wpcom_site_id();
if ( ! $site_id ) {
return false;
}
return str_contains( get_stylesheet(), 'pub/p2' ) || ( function_exists( '\WPForTeams\is_wpforteams_site' ) && \WPForTeams\is_wpforteams_site( $site_id ) );
}
/**
* Get the current site's WordPress.com ID.
*
* @return mixed The site's WordPress.com ID.
*/
public function get_wpcom_site_id() {
if ( $this->is_wpcom_simple() ) {
return get_current_blog_id();
} elseif ( class_exists( 'Jetpack' ) && \Jetpack::is_connection_ready() ) {
return \Jetpack_Options::get_option( 'id' );
}
return false;
}
/**
* Add all wordpress.com environments to the safe redirect allowed list.
*
@ -135,123 +163,15 @@ class Host {
return '';
}
/**
* Returns an array of nameservers for the current site.
*
* @param string $domain The domain of the site to check.
* @return array
*/
public function get_nameserver_dns_records( $domain ) {
if ( ! function_exists( 'dns_get_record' ) ) {
return array();
}
$dns_records = dns_get_record( $domain, DNS_NS ); // Fetches the DNS records of type NS (Name Server)
if ( false === $dns_records ) {
return array();
}
$nameservers = array();
foreach ( $dns_records as $record ) {
if ( isset( $record['target'] ) ) {
$nameservers[] = $record['target']; // Adds the nameserver to the array
}
}
return $nameservers; // Returns an array of nameserver names
}
/**
* Given a DNS entry, will return a hosting provider if one can be determined. Otherwise, will return 'unknown'.
* Sourced from: fbhepr%2Skers%2Sjcpbz%2Sjc%2Qpbagrag%2Syvo%2Subfgvat%2Qcebivqre%2Sanzrfreiref.cuc-og
*
* @param string $domain The domain of the site to check.
* @return string The hosting provider of 'unknown'.
*/
public function get_hosting_provider_by_nameserver( $domain ) {
$known_nameservers = array(
'bluehost' => array(
'.bluehost.com',
),
'dreamhost' => array(
'.dreamhost.com',
),
'mediatemple' => array(
'.mediatemple.net',
),
'xserver' => array(
'.xserver.jp',
),
'namecheap' => array(
'.namecheaphosting.com',
),
'hostmonster' => array(
'.hostmonster.com',
),
'justhost' => array(
'.justhost.com',
),
'digitalocean' => array(
'.digitalocean.com',
),
'one' => array(
'.one.com',
),
'hostpapa' => array(
'.hostpapa.com',
),
'siteground' => array(
'.sgcloud.net',
'.sgedu.site',
'.sgsrv1.com',
'.sgvps.net',
'.siteground.biz',
'.siteground.net',
'.siteground.eu',
),
'inmotion' => array(
'.inmotionhosting.com',
),
'ionos' => array(
'.ui-dns.org',
'.ui-dns.de',
'.ui-dns.biz',
'.ui-dns.com',
),
);
$dns_records = $this->get_nameserver_dns_records( $domain );
$dns_records = array_map( 'strtolower', $dns_records );
foreach ( $known_nameservers as $host => $ns_patterns ) {
foreach ( $ns_patterns as $ns_pattern ) {
foreach ( $dns_records as $record ) {
if ( false !== strpos( $record, $ns_pattern ) ) {
return $host;
}
}
}
}
return 'unknown';
}
/**
* Returns a guess of the hosting provider for the current site based on various checks.
*
* @since 5.0.4 Added $guess parameter.
*
* @param bool $guess Whether to guess the hosting provider.
* @since 6.0.0 Removed $guess parameter.
*
* @return string
*/
public function get_known_host_guess( $guess = true ) {
$host = Cache::get( 'host_guess' );
if ( null !== $host ) {
return $host;
}
public function get_known_host_guess() {
// First, let's check if we can recognize provider manually:
switch ( true ) {
case $this->is_woa_site():
@ -275,14 +195,6 @@ class Host {
break;
}
// Second, let's check if we can recognize provider by nameservers.
// Only do this if we're asked to guess.
$domain = isset( $_SERVER['SERVER_NAME'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_NAME'] ) ) : '';
if ( $provider === 'unknown' && ! empty( $domain ) && $guess ) {
$provider = $this->get_hosting_provider_by_nameserver( $domain );
}
Cache::set( 'host_guess', $provider );
return $provider;
}

View File

@ -468,7 +468,7 @@ class Modules {
ob_start();
$module_path = $this->get_path( $module );
if ( file_exists( $module_path ) ) {
require $this->get_path( $module ); // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.NotAbsolutePath
require_once $this->get_path( $module ); // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.NotAbsolutePath
}
$active[] = $module;

View File

@ -0,0 +1,112 @@
<?php
/**
* Get information about the current request.
*
* @package automattic/jetpack-status
*/
namespace Automattic\Jetpack\Status;
use Automattic\Jetpack\Constants;
/**
* Get information about the current request.
*/
class Request {
/**
* Determine whether the current request is for accessing the frontend.
* Also update Vary headers to indicate that the response may vary by Accept header.
*
* @since 6.0.3 Added $send_vary_headers argument.
*
* @param bool $send_vary_headers Whether to send Vary headers.
*
* @return bool True if it's a frontend request, false otherwise.
*/
public static function is_frontend( $send_vary_headers = true ) {
$is_frontend = true;
$is_varying_request = true;
if (
is_admin()
|| wp_doing_ajax()
|| wp_is_jsonp_request()
|| is_feed()
|| Constants::is_true( 'REST_REQUEST' )
|| Constants::is_true( 'REST_API_REQUEST' )
|| Constants::is_true( 'WP_CLI' )
|| Constants::is_true( 'WPCOM_CLI_SCRIPT' ) // Special case for CLI scripts on WP.com that aren't using WP CLI.
) {
$is_frontend = false;
$is_varying_request = false;
} elseif (
wp_is_json_request()
|| wp_is_xml_request()
) {
$is_frontend = false;
}
/*
* Check existing headers for the request.
* If there is no existing Vary Accept header, add one.
*/
if ( $send_vary_headers && $is_varying_request && ! headers_sent() ) {
$headers = headers_list();
$vary_header_parts = self::get_vary_headers( $headers );
header( 'Vary: ' . implode( ', ', $vary_header_parts ) );
}
/**
* Filter whether the current request is for accessing the frontend.
*
* @since jetpack-9.0.0
* @since 6.0.3 Added $send_vary_headers argument.
*
* @param bool $is_frontend Whether the current request is for accessing the frontend.
* @param bool $send_vary_headers Whether to send Vary headers.
*/
return (bool) apply_filters( 'jetpack_is_frontend', $is_frontend, $send_vary_headers );
}
/**
* Go through headers and get a list of Vary headers to add,
* including Vary on Accept and Content-Type if necessary.
*
* @since jetpack-12.2
*
* @param array $headers The headers to be sent.
*
* @return array $vary_header_parts Vary Headers to be sent.
*/
public static function get_vary_headers( $headers = array() ) {
$vary_header_parts = array( 'accept', 'content-type' );
foreach ( $headers as $header ) {
// Check for a Vary header.
if ( ! str_starts_with( strtolower( $header ), 'vary:' ) ) {
continue;
}
// If the header is a wildcard, we'll return that.
if ( str_contains( $header, '*' ) ) {
$vary_header_parts = array( '*' );
break;
}
// Remove the Vary: part of the header.
$header = preg_replace( '/^vary\:\s?/i', '', $header );
// Remove spaces from the header.
$header = str_replace( ' ', '', $header );
// Break the header into parts.
$header_parts = explode( ',', strtolower( $header ) );
// Build an array with the Accept header and what was already there.
$vary_header_parts = array_values( array_unique( array_merge( $vary_header_parts, $header_parts ) ) );
}
return $vary_header_parts;
}
}

View File

@ -53,6 +53,10 @@ class Status {
*/
$offline_mode = (bool) apply_filters( 'jetpack_offline_mode', $offline_mode );
if ( ! $offline_mode ) {
$offline_mode = (bool) get_option( 'jetpack_offline_mode' );
}
Cache::set( 'is_offline_mode', $offline_mode );
return $offline_mode;
}
@ -142,6 +146,7 @@ class Status {
'#\.docksal\.site$#i', // Docksal.
'#\.dev\.cc$#i', // ServerPress.
'#\.lndo\.site$#i', // Lando.
'#\.ddev\.site$#i', // DDEV.
'#^https?://127\.0\.0\.1$#',
);
@ -375,7 +380,7 @@ class Status {
public function is_coming_soon() {
$ret = Cache::get( 'is_coming_soon' );
if ( null === $ret ) {
$is_coming_soon = (bool) ( function_exists( 'site_is_coming_soon' ) && \site_is_coming_soon() )
$is_coming_soon = ( function_exists( 'site_is_coming_soon' ) && \site_is_coming_soon() )
|| get_option( 'wpcom_public_coming_soon' );
/**