plugin updates

This commit is contained in:
Tony Volpe
2024-09-17 10:43:54 -04:00
parent 44b413346f
commit b7c8882c8c
1359 changed files with 58219 additions and 11364 deletions

View File

@@ -25,7 +25,7 @@ class Cache {
*
* @param string $key Key to fetch.
* @param mixed $default Default value to return if the key is not set.
* @returns mixed Data.
* @return mixed Data.
*/
public static function get( $key, $default = null ) {
$blog_id = get_current_blog_id();

View File

@@ -14,25 +14,31 @@ namespace Automattic\Jetpack;
/**
* Erros class.
*
* @deprecated since 3.2.0
*/
class Errors {
/**
* Catches PHP errors. Must be used in conjunction with output buffering.
*
* @deprecated since 3.2.0
* @param bool $catch True to start catching, False to stop.
*
* @static
*/
public function catch_errors( $catch ) {
_deprecated_function( __METHOD__, '3.2.0' );
static $display_errors, $error_reporting;
if ( $catch ) {
// Force error reporting and output, store original values.
$display_errors = @ini_set( 'display_errors', 1 );
$error_reporting = @error_reporting( E_ALL );
if ( class_exists( 'Jetpack' ) ) {
add_action( 'shutdown', array( 'Jetpack', 'catch_errors_on_shutdown' ), 0 );
}
} else {
// Restore the original values for error reporting and output.
@ini_set( 'display_errors', $display_errors );
@error_reporting( $error_reporting );
if ( class_exists( 'Jetpack' ) ) {

View File

@@ -34,7 +34,7 @@ class Files {
// phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
while ( false !== $file = readdir( $dir ) ) {
if ( '.' === substr( $file, 0, 1 ) || '.php' !== substr( $file, -4 ) ) {
if ( str_starts_with( $file, '.' ) || ! str_ends_with( $file, '.php' ) ) {
continue;
}

View File

@@ -34,7 +34,7 @@ class Host {
*
* @since 1.9.0
*
* @return bool;
* @return bool
*/
public function is_atomic_platform() {
return Constants::is_true( 'ATOMIC_SITE_ID' ) && Constants::is_true( 'ATOMIC_CLIENT_ID' );
@@ -127,11 +127,169 @@ class Host {
*/
public function get_source_query() {
// phpcs:disable WordPress.Security.NonceVerification.Recommended
$allowed_sources = array( 'jetpack-manage' );
$allowed_sources = array( 'jetpack-manage', 'a8c-for-agencies' );
if ( isset( $_GET['source'] ) && in_array( $_GET['source'], $allowed_sources, true ) ) {
return sanitize_key( $_GET['source'] );
}
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)
$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.
*
* @return string
*/
public function get_known_host_guess() {
$host = Cache::get( 'host_guess' );
if ( null !== $host ) {
return $host;
}
// First, let's check if we can recognize provider manually:
switch ( true ) {
case $this->is_woa_site():
$provider = 'woa';
break;
case $this->is_atomic_platform():
$provider = 'atomic';
break;
case $this->is_newspack_site():
$provider = 'newspack';
break;
case $this->is_vip_site():
$provider = 'vip';
break;
case $this->is_wpcom_simple():
case $this->is_wpcom_platform():
$provider = 'wpcom';
break;
default:
$provider = 'unknown';
break;
}
// Second, let's check if we can recognize provider by nameservers:
$domain = isset( $_SERVER['SERVER_NAME'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_NAME'] ) ) : '';
if ( $provider === 'unknown' && ! empty( $domain ) ) {
$provider = $this->get_hosting_provider_by_nameserver( $domain );
}
Cache::set( 'host_guess', $provider );
return $provider;
}
/**
* Add public-api.wordpress.com to the safe redirect allowed list - only added when someone allows API access.
*
* @since 3.0.2 Ported from Jetpack to the Status package.
*
* To be used with a filter of allowed domains for a redirect.
*
* @param array $domains Allowed WP.com Environments.
*
* @return array
*/
public static function allow_wpcom_public_api_domain( $domains ) {
$domains[] = 'public-api.wordpress.com';
return $domains;
}
}

View File

@@ -22,10 +22,16 @@ class Modules {
* Check whether or not a Jetpack module is active.
*
* @param string $module The slug of a Jetpack module.
* @param bool $available_only Whether to only check among available modules.
*
* @return bool
*/
public function is_active( $module ) {
return in_array( $module, self::get_active(), true );
public function is_active( $module, $available_only = true ) {
if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
return true;
}
return in_array( $module, self::get_active( $available_only ), true );
}
/**
@@ -162,7 +168,7 @@ class Modules {
}
$key = md5( $file_name . maybe_serialize( $headers ) );
$refresh_cache = is_admin() && isset( $_GET['page'] ) && 'jetpack' === substr( $_GET['page'], 0, 7 ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput
$refresh_cache = is_admin() && isset( $_GET['page'] ) && is_string( $_GET['page'] ) && str_starts_with( $_GET['page'], 'jetpack' ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput
// If we don't need to refresh the cache, and already have the value, short-circuit!
if ( ! $refresh_cache && isset( $file_data_option[ $key ] ) ) {
@@ -180,8 +186,12 @@ class Modules {
/**
* Get a list of activated modules as an array of module slugs.
*
* @param bool $available_only Filter out the unavailable (deleted) modules.
*
* @return array
*/
public function get_active() {
public function get_active( $available_only = true ) {
$active = \Jetpack_Options::get_option( 'active_modules' );
if ( ! is_array( $active ) ) {
@@ -202,9 +212,11 @@ class Modules {
$active[] = 'protect';
}
// If it's not available, it shouldn't be active.
// We don't delete it from the options though, as it will be active again when a plugin gets reactivated.
$active = array_intersect( $active, $this->get_available() );
if ( $available_only ) {
// If it's not available, it shouldn't be active.
// We don't delete it from the options though, as it will be active again when a plugin gets reactivated.
$active = array_intersect( $active, $this->get_available() );
}
/**
* Allow filtering of the active modules.
@@ -450,10 +462,8 @@ class Modules {
}
// Check the file for fatal errors, a la wp-admin/plugins.php::activate.
$errors = new Errors();
$state->state( 'module', $module );
$state->state( 'error', 'module_activation_failed' ); // we'll override this later if the plugin can be included without fatal error.
$errors->catch_errors( true );
ob_start();
$module_path = $this->get_path( $module );
@@ -466,7 +476,6 @@ class Modules {
$state->state( 'error', false ); // the override.
ob_end_clean();
$errors->catch_errors( false );
} else { // Not a Jetpack plugin.
$active[] = $module;
$this->update_active( $active );
@@ -530,7 +539,7 @@ class Modules {
*
* @param array $modules Array of active modules to be saved in options.
*
* @return $success bool true for success, false for failure.
* @return bool $success true for success, false for failure.
*/
public function update_active( $modules ) {
$current_modules = \Jetpack_Options::get_option( 'active_modules', array() );

View File

@@ -25,4 +25,57 @@ class Paths {
$url = add_query_arg( $args, admin_url( 'admin.php' ) );
return $url;
}
/**
* Determine if the current request is activating a plugin from the plugins page.
*
* @param string $plugin Plugin file path to check.
* @return bool
*/
public function is_current_request_activating_plugin_from_plugins_screen( $plugin ) {
// Filter out common async request contexts
if (
wp_doing_ajax() ||
( defined( 'REST_REQUEST' ) && REST_REQUEST ) ||
( defined( 'REST_API_REQUEST' ) && REST_API_REQUEST ) ||
( defined( 'WP_CLI' ) && WP_CLI )
) {
return false;
}
if ( isset( $_SERVER['SCRIPT_NAME'] ) ) {
$request_file = esc_url_raw( wp_unslash( $_SERVER['SCRIPT_NAME'] ) );
} elseif ( isset( $_SERVER['REQUEST_URI'] ) ) {
list( $request_file ) = explode( '?', esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
} else {
return false;
}
// Not the plugins page
if ( strpos( $request_file, 'wp-admin/plugins.php' ) === false ) {
return false;
}
// Same method to get the action as used by plugins.php
$wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
$action = $wp_list_table->current_action();
// Not a singular activation
// This also means that if the plugin is activated as part of a group ( bulk activation ), this function will return false here.
if ( 'activate' !== $action ) {
return false;
}
// Check the nonce associated with the plugin activation
// We are not changing any data here, so this is not super necessary, it's just a best practice before using the form data from $_REQUEST.
check_admin_referer( 'activate-plugin_' . $plugin );
// Not the right plugin
$requested_plugin = isset( $_REQUEST['plugin'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['plugin'] ) ) : null;
if ( $requested_plugin !== $plugin ) {
return false;
}
return true;
}
}

View File

@@ -17,18 +17,6 @@ use WPCOM_Masterbar;
* Used to retrieve information about the current status of Jetpack and the site overall.
*/
class Status {
/**
* Is Jetpack in development (offline) mode?
*
* @deprecated 1.3.0 Use Status->is_offline_mode().
*
* @return bool Whether Jetpack's offline mode is active.
*/
public function is_development_mode() {
_deprecated_function( __FUNCTION__, '1.3.0', 'Automattic\Jetpack\Status->is_offline_mode' );
return $this->is_offline_mode();
}
/**
* Is Jetpack in offline mode?
*
@@ -54,20 +42,6 @@ class Status {
$offline_mode = true;
}
/**
* Filters Jetpack's offline mode.
*
* @see https://jetpack.com/support/development-mode/
* @todo Update documentation ^^.
*
* @since 1.1.1
* @since-jetpack 2.2.1
* @deprecated 1.3.0
*
* @param bool $offline_mode Is Jetpack's offline mode active.
*/
$offline_mode = (bool) apply_filters_deprecated( 'jetpack_development_mode', array( $offline_mode ), '1.3.0', 'jetpack_offline_mode' );
/**
* Filters Jetpack's offline mode.
*
@@ -84,21 +58,6 @@ class Status {
return $offline_mode;
}
/**
* Is Jetpack in "No User test mode"?
*
* This will make Jetpack act as if there were no connected users, but only a site connection (aka blog token)
*
* @since 1.6.0
* @deprecated 1.7.5 Since this version, Jetpack connection is considered active after registration, making no_user_testing_mode obsolete.
*
* @return bool Whether Jetpack's No User Testing Mode is active.
*/
public function is_no_user_testing_mode() {
_deprecated_function( __METHOD__, '1.7.5' );
return true;
}
/**
* Whether this is a system with a multiple networks.
* Implemented since there is no core is_multi_network function.
@@ -167,6 +126,7 @@ class Status {
$site_url = site_url();
// Check for localhost and sites using an IP only first.
// Note: str_contains() is not used here, as wp-includes/compat.php is not loaded in this file.
$is_local = $site_url && false === strpos( $site_url, '.' );
// Use Core's environment check, if available.
@@ -211,11 +171,12 @@ class Status {
/**
* If is a staging site.
*
* @todo Add IDC detection to a package.
* @deprecated since 3.3.0
*
* @return bool
*/
public function is_staging_site() {
_deprecated_function( __FUNCTION__, '3.3.0', 'in_safe_mode' );
$cached = Cache::get( 'is_staging_site' );
if ( null !== $cached ) {
return $cached;
@@ -301,6 +262,64 @@ class Status {
return $is_staging;
}
/**
* If the site is in safe mode.
*
* @since 3.3.0
*
* @return bool
*/
public function in_safe_mode() {
$cached = Cache::get( 'in_safe_mode' );
if ( null !== $cached ) {
return $cached;
}
$in_safe_mode = false;
if ( method_exists( 'Automattic\\Jetpack\\Identity_Crisis', 'validate_sync_error_idc_option' ) && \Automattic\Jetpack\Identity_Crisis::validate_sync_error_idc_option() ) {
$in_safe_mode = true;
}
/**
* Filters in_safe_mode check.
*
* @since 3.3.0
*
* @param bool $in_safe_mode If the current site is in safe mode.
*/
$in_safe_mode = apply_filters( 'jetpack_is_in_safe_mode', $in_safe_mode );
Cache::set( 'in_safe_mode', $in_safe_mode );
return $in_safe_mode;
}
/**
* If the site is a development/staging site.
* This is a new version of is_staging_site added to separate safe mode from the legacy staging mode.
* This method checks for core WP_ENVIRONMENT_TYPE setting
* Using the jetpack_is_development_site filter.
*
* @since 3.3.0
*
* @return bool
*/
public static function is_development_site() {
$cached = Cache::get( 'is_development_site' );
if ( null !== $cached ) {
return $cached;
}
$is_dev_site = ! in_array( wp_get_environment_type(), array( 'production', 'local' ), true );
/**
* Filters is_development_site check.
*
* @since 3.3.0
*
* @param bool $is_dev_site If the current site is a staging or dev site.
*/
$is_dev_site = apply_filters( 'jetpack_is_development_site', $is_dev_site );
Cache::set( 'is_development_site', $is_dev_site );
return $is_dev_site;
}
/**
* Whether the site is currently onboarding or not.
* A site is considered as being onboarded if it currently has an onboarding token.

View File

@@ -40,4 +40,17 @@ class Visitor {
return ! empty( $_SERVER['REMOTE_ADDR'] ) ? filter_var( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : '';
}
/**
* Simple gate check for a11n feature testing purposes using AT_PROXIED_REQUEST constant.
* IMPORTANT: Only use it for internal feature test purposes, not authorization.
*
* The goal of this function is to help us gate features by using a similar function name
* we find on simple sites: is_automattician().
*
* @return bool True if the current request is PROXIED, false otherwise.
*/
public function is_automattician_feature_flags_only() {
return ( defined( 'AT_PROXIED_REQUEST' ) && AT_PROXIED_REQUEST );
}
}