Use PHP 7.4 featers and PHP 8 polyfills

This commit is contained in:
David Stone
2025-02-08 13:57:32 -07:00
parent 8bea6067cd
commit b41dc2b2eb
550 changed files with 15270 additions and 14627 deletions

View File

@ -26,11 +26,11 @@ class Helper {
*
* @var array
*/
static $providers = array(
static $providers = [
'https://ipv4.canihazip.com/s',
'https://ipv4.icanhazip.com/',
'https://api.ipify.org/',
);
];
/**
* Static-only class.
@ -72,7 +72,7 @@ class Helper {
*/
public static function get_local_network_ip() {
return isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : false;
return $_SERVER['SERVER_ADDR'] ?? false;
}
/**
@ -104,9 +104,9 @@ class Helper {
foreach ( self::$providers as $provider_url ) {
$response = wp_remote_get(
$provider_url,
array(
[
'timeout' => 5,
)
]
);
if ( ! is_wp_error($response) ) {
@ -154,16 +154,16 @@ class Helper {
}
// Add 'https://' if not already present to use SSL context properly.
$domain = strpos($domain, 'https://') === 0 ? $domain : 'https://' . $domain;
$domain = str_starts_with($domain, 'https://') ? $domain : 'https://' . $domain;
try {
// Create SSL context to fetch the certificate.
$context = stream_context_create(
array(
'ssl' => array(
[
'ssl' => [
'capture_peer_cert' => true,
),
)
],
]
);
// Open a stream to the domain over SSL.
@ -212,7 +212,7 @@ class Helper {
$is_valid = true;
} else {
foreach ($alt_names_array as $alt_name) {
if ( strpos($alt_name, '*.') === 0 && str_ends_with($host, substr($alt_name, 1))) {
if ( str_starts_with($alt_name, '*.') && str_ends_with($host, substr($alt_name, 1))) {
$is_valid = true;
break;
}

View File

@ -29,9 +29,9 @@ class Primary_Domain {
* @since 2.0.0
* @return void
*/
public function init() {
public function init(): void {
add_action('wu_domain_mapping_load', array($this, 'add_hooks'), -20);
add_action('wu_domain_mapping_load', [$this, 'add_hooks'], -20);
}
/**
@ -40,13 +40,13 @@ class Primary_Domain {
* @since 2.0.0
* @return void
*/
public function add_hooks() {
public function add_hooks(): void {
add_action('template_redirect', array($this, 'redirect_to_primary_domain'));
add_action('template_redirect', [$this, 'redirect_to_primary_domain']);
add_action('admin_init', array($this, 'maybe_redirect_to_mapped_or_network_domain'));
add_action('admin_init', [$this, 'maybe_redirect_to_mapped_or_network_domain']);
add_action('login_init', array($this, 'maybe_redirect_to_mapped_or_network_domain'));
add_action('login_init', [$this, 'maybe_redirect_to_mapped_or_network_domain']);
}
/**
@ -55,7 +55,7 @@ class Primary_Domain {
* @since 2.0.0
* @return void
*/
public function redirect_to_primary_domain() {
public function redirect_to_primary_domain(): void {
$should_redirect = true;
@ -85,12 +85,12 @@ class Primary_Domain {
}
$domains = wu_get_domains(
array(
[
'blog_id' => get_current_blog_id(),
'primary_domain' => 1,
'active' => 1,
'domain__not_in' => array($_SERVER['HTTP_HOST']),
)
'domain__not_in' => [$_SERVER['HTTP_HOST']],
]
);
if (empty($domains)) {
@ -116,7 +116,7 @@ class Primary_Domain {
* @since 2.0.0
* @return void
*/
public function maybe_redirect_to_mapped_or_network_domain() {
public function maybe_redirect_to_mapped_or_network_domain(): void {
if ($_SERVER['REQUEST_METHOD'] !== 'GET' || wp_doing_ajax()) {
return;
@ -151,7 +151,7 @@ class Primary_Domain {
$mapped_url_to_compare = $mapped_url['host'];
$query_args = array();
$query_args = [];
if (wu_get_isset($current_url, 'query')) {
wp_parse_str($current_url['query'], $query_args);