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

@ -25,7 +25,7 @@ class Billing_Address {
* @since 2.0.0
* @var array
*/
protected $attributes = array();
protected $attributes = [];
/**
* Initializes the object.
@ -34,7 +34,7 @@ class Billing_Address {
*
* @param array $data Array of key => values billing address fields.
*/
public function __construct($data = array()) {
public function __construct($data = []) {
$this->attributes($data);
}
@ -47,7 +47,7 @@ class Billing_Address {
* @param array $data Array of key => values billing address fields.
* @return void
*/
public function attributes($data) {
public function attributes($data): void {
$allowed_attributes = array_keys(self::fields());
@ -154,7 +154,7 @@ class Billing_Address {
*/
public function to_array($labels = false) {
$address_array = array();
$address_array = [];
$fields = self::fields();
@ -217,7 +217,7 @@ class Billing_Address {
*/
public static function fields($zip_only = false, $checkout_form = false) {
$fields = array();
$fields = [];
$countries = wu_get_countries_as_options();
@ -235,37 +235,37 @@ class Billing_Address {
}
}
$fields['company_name'] = array(
$fields['company_name'] = [
'type' => 'text',
'title' => __('Company Name', 'wp-ultimo'),
'default_placeholder' => __('E.g. Google (optional)', 'wp-ultimo'),
'wrapper_classes' => 'sm:wu-col-span-1',
);
];
$fields['billing_email'] = array(
$fields['billing_email'] = [
'type' => 'text',
'title' => __('Billing Email', 'wp-ultimo'),
'default_placeholder' => __('E.g. john@company.com', 'wp-ultimo'),
'wrapper_classes' => 'sm:wu-col-span-1',
'required' => true,
);
];
$fields['billing_address_line_1'] = array(
$fields['billing_address_line_1'] = [
'type' => 'text',
'title' => __('Address Line 1', 'wp-ultimo'),
'default_placeholder' => __('E.g. 555 1st Avenue', 'wp-ultimo'),
'wrapper_classes' => 'wu-col-span-2',
'required' => true,
);
];
$fields['billing_address_line_2'] = array(
$fields['billing_address_line_2'] = [
'type' => 'text',
'title' => __('Address Line 2', 'wp-ultimo'),
'default_placeholder' => __('E.g. Apartment 10a', 'wp-ultimo'),
'wrapper_classes' => 'wu-col-span-2',
);
];
$fields['billing_country'] = array(
$fields['billing_country'] = [
'type' => 'select',
'title' => __('Country', 'wp-ultimo'),
'default_placeholder' => __('E.g. US', 'wp-ultimo'),
@ -273,37 +273,37 @@ class Billing_Address {
'value' => ' ',
'options' => $countries,
'required' => true,
);
];
$fields['billing_state'] = array(
$fields['billing_state'] = [
'type' => 'text',
'title' => __('State / Province', 'wp-ultimo'),
'default_placeholder' => __('E.g. NY', 'wp-ultimo'),
'wrapper_classes' => 'sm:wu-col-span-1',
);
];
$fields['billing_city'] = array(
$fields['billing_city'] = [
'type' => 'text',
'title' => __('City / Town', 'wp-ultimo'),
'default_placeholder' => __('E.g. New York City', 'wp-ultimo'),
'wrapper_classes' => 'sm:wu-col-span-1',
);
];
$fields['billing_zip_code'] = array(
$fields['billing_zip_code'] = [
'type' => 'text',
'title' => __('ZIP / Postal Code', 'wp-ultimo'),
'default_placeholder' => __('E.g. 10009', 'wp-ultimo'),
'wrapper_classes' => 'sm:wu-col-span-1',
'required' => true,
);
];
$fields = wu_set_order_from_index($fields); // Adds missing order attributes
if ($zip_only) {
$fields = array(
$fields = [
'billing_zip_code' => $fields['billing_zip_code'],
'billing_country' => $fields['billing_country'],
);
];
}
/**
@ -331,18 +331,18 @@ class Billing_Address {
*/
public static function fields_for_rest($zip_only = false) {
$fields_for_rest = array();
$fields_for_rest = [];
foreach (self::fields($zip_only) as $field_key => $field) {
$options = wu_get_isset($field, 'options', false);
$enum = is_callable($options) ? call_user_func($options) : false;
$fields_for_rest[ $field_key ] = array(
$fields_for_rest[ $field_key ] = [
'description' => wu_get_isset($field, 'title', false) . '. ' . wu_get_isset($field, 'default_placeholder', false),
'type' => 'string',
'required' => wu_get_isset($field, 'required', false),
);
];
if ($enum) {
$fields_for_rest[ $field_key ]['enum'] = array_keys($enum);

View File

@ -32,7 +32,7 @@ class Limitations {
* @since 2.0.0
* @var array
*/
static $limitations_cache = array();
static $limitations_cache = [];
/**
* Version of the limitation schema.
@ -48,7 +48,7 @@ class Limitations {
* @since 2.0.0
* @var array
*/
protected $modules = array();
protected $modules = [];
/**
* The current limitation being merged in merge_recursive.
@ -65,7 +65,7 @@ class Limitations {
*
* @param array $modules_data Array of modules data.
*/
public function __construct($modules_data = array()) {
public function __construct($modules_data = []) {
$this->build_modules($modules_data);
}
@ -88,7 +88,7 @@ class Limitations {
$class_name = wu_get_isset($repo, $name, false);
if (class_exists($class_name)) {
$module = new $class_name(array());
$module = new $class_name([]);
$this->modules[ $name ] = $module;
@ -270,10 +270,10 @@ class Limitations {
$current_id = $this->current_merge_id;
$force_enabled_list = array(
$force_enabled_list = [
'plugins',
'themes',
);
];
$force_enabled = in_array($current_id, $force_enabled_list, true);
@ -283,9 +283,9 @@ class Limitations {
}
if ( ! wu_get_isset($array1, 'enabled', true)) {
$array1 = array(
$array1 = [
'enabled' => false,
);
];
}
if ( ! wu_get_isset($array2, 'enabled', true) && $should_sum) {
@ -325,32 +325,32 @@ class Limitations {
} elseif (isset($array1[ $key ]) && is_numeric($array1[ $key ]) && is_numeric($value) && $should_sum && ! $is_unlimited) {
$array1[ $key ] = ((int) $array1[ $key ]) + $value;
} elseif ($key === 'visibility' && isset($array1[ $key ]) && $should_sum) {
$key_priority = array(
$key_priority = [
'hidden' => 0,
'visible' => 1,
);
];
$array1[ $key ] = $key_priority[ $value ] > $key_priority[ $array1[ $key ] ] ? $value : $array1[ $key ];
} elseif ($key === 'behavior' && isset($array1[ $key ]) && $should_sum) {
$key_priority_list = array(
'plugins' => array(
$key_priority_list = [
'plugins' => [
'default' => 10,
'force_inactive_locked' => 20,
'force_inactive' => 30,
'force_active_locked' => 40,
'force_active' => 50,
),
'site' => array(
],
'site' => [
'not_available' => 10,
'available' => 20,
'pre_selected' => 30,
),
'themes' => array(
],
'themes' => [
'not_available' => 10,
'available' => 20,
'force_active' => 30,
),
);
],
];
$key_priority = apply_filters("wu_limitation_{$current_id}_priority", $key_priority_list[ $current_id ]);
@ -408,7 +408,7 @@ class Limitations {
global $wpdb;
$limitations = array();
$limitations = [];
$table_name = "{$wpdb->base_prefix}{$wu_prefix}{$slug}meta";
@ -437,7 +437,7 @@ class Limitations {
* @param int $id The id of the meta id.
* @return void
*/
public static function remove_limitations($slug, $id) {
public static function remove_limitations($slug, $id): void {
global $wpdb;
@ -487,7 +487,7 @@ class Limitations {
*/
public static function repository() {
$classes = array(
$classes = [
'post_types' => \WP_Ultimo\Limitations\Limit_Post_Types::class,
'plugins' => \WP_Ultimo\Limitations\Limit_Plugins::class,
'sites' => \WP_Ultimo\Limitations\Limit_Sites::class,
@ -498,7 +498,7 @@ class Limitations {
'site_templates' => \WP_Ultimo\Limitations\Limit_Site_Templates::class,
'domain_mapping' => \WP_Ultimo\Limitations\Limit_Domain_Mapping::class,
'customer_user_role' => \WP_Ultimo\Limitations\Limit_Customer_User_Role::class,
);
];
return apply_filters('wu_limit_classes', $classes);
}

View File

@ -25,7 +25,7 @@ class Note {
* @since 2.0.0
* @var array
*/
protected $attributes = array();
protected $attributes = [];
/**
* Initializes the object.
@ -34,7 +34,7 @@ class Note {
*
* @param array $data Array of key => values note fields.
*/
public function __construct($data = array()) {
public function __construct($data = []) {
$this->attributes($data);
}
@ -47,7 +47,7 @@ class Note {
* @param array $data Array of key => values note fields.
* @return void
*/
public function attributes($data) {
public function attributes($data): void {
$allowed_attributes = array_keys(self::fields());
@ -122,7 +122,7 @@ class Note {
*/
protected function validation_rules() {
return array();
return [];
}
/**
@ -154,7 +154,7 @@ class Note {
*/
public function to_array($labels = false) {
$address_array = array();
$address_array = [];
$fields = self::fields();
@ -190,22 +190,22 @@ class Note {
*/
public static function fields() {
$fields = array();
$fields = [];
$fields['text'] = array(
$fields['text'] = [
'type' => 'text',
'title' => __('Text', 'wp-ultimo'),
);
];
$fields['author_id'] = array(
$fields['author_id'] = [
'type' => 'number',
'title' => __('Author ID', 'wp-ultimo'),
);
];
$fields['note_id'] = array(
$fields['note_id'] = [
'type' => 'text',
'title' => __('Note ID', 'wp-ultimo'),
);
];
uasort($fields, 'wu_sort_by_order');