Use PHP 7.4 featers and PHP 8 polyfills
This commit is contained in:
@ -78,7 +78,7 @@ class Arr {
|
||||
public static function filter($array, $closure) {
|
||||
|
||||
if ($closure) {
|
||||
$result = array();
|
||||
$result = [];
|
||||
|
||||
foreach ($array as $key => $value) {
|
||||
if (call_user_func($closure, $value, $key)) {
|
||||
@ -145,7 +145,7 @@ class Arr {
|
||||
$key = array_shift($keys);
|
||||
|
||||
if ( ! isset($array[ $key ]) || ! is_array($array[ $key ])) {
|
||||
$array[ $key ] = array();
|
||||
$array[ $key ] = [];
|
||||
}
|
||||
|
||||
$array =& $array[ $key ];
|
||||
|
@ -60,9 +60,9 @@ class Screenshot {
|
||||
|
||||
$response = wp_remote_get(
|
||||
$url,
|
||||
array(
|
||||
[
|
||||
'timeout' => 50,
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
if (wp_remote_retrieve_response_code($response) !== 200) {
|
||||
@ -80,7 +80,7 @@ class Screenshot {
|
||||
/*
|
||||
* Check if the results contain a PNG header.
|
||||
*/
|
||||
if (strncmp($response['body'], "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a", strlen("\x89\x50\x4e\x47\x0d\x0a\x1a\x0a")) !== 0) {
|
||||
if (! str_starts_with($response['body'], "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a")) {
|
||||
wu_log_add('screenshot-generator', $log_prefix . __('Result is not a PNG file.', 'wp-ultimo'), LogLevel::ERROR);
|
||||
|
||||
return false;
|
||||
@ -100,13 +100,13 @@ class Screenshot {
|
||||
$attachment_title = sanitize_file_name(pathinfo($file_name, PATHINFO_FILENAME));
|
||||
$wp_upload_dir = wp_upload_dir();
|
||||
|
||||
$post_info = array(
|
||||
$post_info = [
|
||||
'guid' => $wp_upload_dir['url'] . '/' . $file_name,
|
||||
'post_mime_type' => $file_type['type'],
|
||||
'post_title' => $attachment_title,
|
||||
'post_content' => '',
|
||||
'post_status' => 'inherit',
|
||||
);
|
||||
];
|
||||
|
||||
// Create the attachment
|
||||
$attach_id = wp_insert_attachment($post_info, $file_path);
|
||||
|
@ -29,20 +29,20 @@ class Sender {
|
||||
* @param array $args The args passed.
|
||||
* @return array
|
||||
*/
|
||||
public static function parse_args($args = array()) {
|
||||
public static function parse_args($args = []) {
|
||||
|
||||
$default_args = array(
|
||||
'from' => array(
|
||||
$default_args = [
|
||||
'from' => [
|
||||
'name' => wu_get_setting('from_name'),
|
||||
'email' => wu_get_setting('from_email'),
|
||||
),
|
||||
],
|
||||
'content' => '',
|
||||
'subject' => '',
|
||||
'bcc' => array(),
|
||||
'payload' => array(),
|
||||
'attachments' => array(),
|
||||
'bcc' => [],
|
||||
'payload' => [],
|
||||
'attachments' => [],
|
||||
'style' => wu_get_setting('email_template_type', 'html'),
|
||||
);
|
||||
];
|
||||
|
||||
$args = wp_parse_args($args, $default_args);
|
||||
|
||||
@ -59,13 +59,13 @@ class Sender {
|
||||
* @param array $args With content, subject and other arguments, has shortcodes, mail type.
|
||||
* @return array With the send response.
|
||||
*/
|
||||
public static function send_mail($from = array(), $to = array(), $args = array()) {
|
||||
public static function send_mail($from = [], $to = [], $args = []) {
|
||||
|
||||
if ( ! $from) {
|
||||
$from = array(
|
||||
$from = [
|
||||
'email' => wu_get_setting('from_email'),
|
||||
'name' => wu_get_setting('from_name'),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
$args = self::parse_args($args);
|
||||
@ -73,7 +73,7 @@ class Sender {
|
||||
/*
|
||||
* First, replace shortcodes.
|
||||
*/
|
||||
$payload = wu_get_isset($args, 'payload', array());
|
||||
$payload = wu_get_isset($args, 'payload', []);
|
||||
|
||||
$subject = self::process_shortcodes(wu_get_isset($args, 'subject', ''), $payload);
|
||||
|
||||
@ -82,7 +82,7 @@ class Sender {
|
||||
/*
|
||||
* Content type and template
|
||||
*/
|
||||
$headers = array();
|
||||
$headers = [];
|
||||
|
||||
if (wu_get_isset($args, 'style', 'html') === 'html') {
|
||||
$headers[] = 'Content-Type: text/html; charset=UTF-8';
|
||||
@ -95,7 +95,7 @@ class Sender {
|
||||
|
||||
$template = wu_get_template_contents(
|
||||
'broadcast/emails/base',
|
||||
array(
|
||||
[
|
||||
'site_name' => get_network_option(null, 'site_name'),
|
||||
'site_url' => get_site_url(wu_get_main_site_id()),
|
||||
'logo_url' => wu_get_network_logo(),
|
||||
@ -103,7 +103,7 @@ class Sender {
|
||||
'subject' => $subject,
|
||||
'content' => $content,
|
||||
'template_settings' => $template_settings,
|
||||
)
|
||||
]
|
||||
);
|
||||
} else {
|
||||
$headers[] = 'Content-Type: text/html; charset=UTF-8';
|
||||
@ -151,9 +151,9 @@ class Sender {
|
||||
$to = $main_to;
|
||||
}
|
||||
} else {
|
||||
$to = array(
|
||||
$to = [
|
||||
wu_format_email_string(wu_get_isset($to[0], 'email'), wu_get_isset($to[0], 'name')),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/*
|
||||
@ -192,13 +192,13 @@ class Sender {
|
||||
* @param array $payload Payload with the values to render in the content.
|
||||
* @return string
|
||||
*/
|
||||
public static function process_shortcodes($content, $payload = array()) {
|
||||
public static function process_shortcodes($content, $payload = []) {
|
||||
|
||||
if (empty($payload)) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
$match = array();
|
||||
$match = [];
|
||||
|
||||
preg_match_all('/{{(.*?)}}/', $content, $match);
|
||||
|
||||
|
@ -46,7 +46,7 @@ class Site_Duplicator {
|
||||
* @param array $args List of duplication parameters, check Site_Duplicator::process_duplication for reference.
|
||||
* @return int|\WP_Error ID of the newly created site or error.
|
||||
*/
|
||||
public static function duplicate_site($from_site_id, $title, $args = array()) {
|
||||
public static function duplicate_site($from_site_id, $title, $args = []) {
|
||||
|
||||
$args['from_site_id'] = $from_site_id;
|
||||
$args['title'] = $title;
|
||||
@ -81,7 +81,7 @@ class Site_Duplicator {
|
||||
* @param array $args List of duplication parameters, check Site_Duplicator::process_duplication for reference.
|
||||
* @return int|false ID of the created site.
|
||||
*/
|
||||
public static function override_site($from_site_id, $to_site_id, $args = array()) {
|
||||
public static function override_site($from_site_id, $to_site_id, $args = []) {
|
||||
|
||||
$to_site = wu_get_site($to_site_id);
|
||||
|
||||
@ -93,14 +93,14 @@ class Site_Duplicator {
|
||||
|
||||
$args = wp_parse_args(
|
||||
$args,
|
||||
array(
|
||||
[
|
||||
'email' => $to_site_customer->get_email_address(),
|
||||
'title' => $to_site->get_title(),
|
||||
'path' => $to_site->get_path(),
|
||||
'from_site_id' => $from_site_id,
|
||||
'to_site_id' => $to_site_id,
|
||||
'meta' => $to_site->meta,
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
$duplicate_site_id = self::process_duplication($args);
|
||||
@ -164,7 +164,7 @@ class Site_Duplicator {
|
||||
|
||||
$args = wp_parse_args(
|
||||
$args,
|
||||
array(
|
||||
[
|
||||
'email' => '', // Required arguments.
|
||||
'title' => '', // Required arguments.
|
||||
'path' => '/', // Required arguments.
|
||||
@ -175,9 +175,9 @@ class Site_Duplicator {
|
||||
'domain' => $current_site->domain,
|
||||
'copy_files' => wu_get_setting('copy_media', true),
|
||||
'network_id' => get_current_network_id(),
|
||||
'meta' => array(),
|
||||
'meta' => [],
|
||||
'user_id' => 0,
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
// Checks
|
||||
@ -198,7 +198,7 @@ class Site_Duplicator {
|
||||
}
|
||||
|
||||
if ( ! $args->to_site_id) {
|
||||
$meta = array_merge($args->meta, array('public' => $args->public));
|
||||
$meta = array_merge($args->meta, ['public' => $args->public]);
|
||||
|
||||
$args->to_site_id = wpmu_create_blog($args->domain, $args->path, $args->title, $user_id, $meta, $args->network_id);
|
||||
|
||||
@ -244,9 +244,9 @@ class Site_Duplicator {
|
||||
*/
|
||||
do_action(
|
||||
'wu_duplicate_site',
|
||||
array(
|
||||
[
|
||||
'site_id' => $args->to_site_id,
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
return $args->to_site_id;
|
||||
|
@ -68,7 +68,7 @@ class Validator {
|
||||
|
||||
$validation_error_messages = apply_filters(
|
||||
'wu_validator_error_messages',
|
||||
array(
|
||||
[
|
||||
'required' => $field_required_message,
|
||||
'required_without' => $field_required_message,
|
||||
'required_with' => $field_required_message,
|
||||
@ -84,17 +84,17 @@ class Validator {
|
||||
'lowercase' => sprintf(__('The %s must be lowercase', 'wp-ultimo'), ':attribute'),
|
||||
// translators: %s is the field identifier
|
||||
'integer' => sprintf(__('The %s must be integer', 'wp-ultimo'), ':attribute'),
|
||||
),
|
||||
],
|
||||
$this
|
||||
);
|
||||
|
||||
$this->validator = new Validator_Helper($validation_error_messages);
|
||||
|
||||
$this->validator->setTranslations(
|
||||
array(
|
||||
[
|
||||
'and' => __('and', 'wp-ultimo'),
|
||||
'or' => __('or', 'wp-ultimo'),
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
$this->validator->addValidator('unique', new Unique());
|
||||
@ -121,7 +121,7 @@ class Validator {
|
||||
* @param array $aliases List of aliases to be used with the validator.
|
||||
* @return \WP_Ultimo\Helpers\Validator
|
||||
*/
|
||||
public function validate($data, $rules = array(), $aliases = array()) {
|
||||
public function validate($data, $rules = [], $aliases = []) {
|
||||
|
||||
$this->errors = new \WP_Error();
|
||||
|
||||
|
@ -59,7 +59,7 @@ class WP_Config {
|
||||
|
||||
return file_put_contents($config_path, implode('', $config), LOCK_EX);
|
||||
} else {
|
||||
list($value, $line) = $line;
|
||||
[$value, $line] = $line;
|
||||
|
||||
if ($value !== true) {
|
||||
$config[ $line ] = $content . PHP_EOL;
|
||||
@ -84,7 +84,7 @@ class WP_Config {
|
||||
public function inject_contents($content_array, $line, $value) {
|
||||
|
||||
if ( ! is_array($value)) {
|
||||
$value = array($value);
|
||||
$value = [$value];
|
||||
}
|
||||
|
||||
array_splice($content_array, $line, 0, $value);
|
||||
@ -142,12 +142,12 @@ class WP_Config {
|
||||
*/
|
||||
$patterns = apply_filters(
|
||||
'wu_wp_config_reference_hook_line_patterns',
|
||||
array(
|
||||
[
|
||||
'/^\$table_prefix\s*=\s*[\'|\"]' . $wpdb->prefix . '[\'|\"]/' => 0,
|
||||
'/^( ){0,}\$table_prefix\s*=.*[\'|\"]' . $wpdb->prefix . '[\'|\"]/' => 0,
|
||||
'/(\/\* That\'s all, stop editing! Happy publishing\. \*\/)/' => -2,
|
||||
'/<\?php/' => 0,
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
$line = 1;
|
||||
@ -219,7 +219,7 @@ class WP_Config {
|
||||
|
||||
foreach ($config as $k => $line) {
|
||||
if (preg_match($pattern, (string) $line, $matches)) {
|
||||
return array(trim($matches[1]), $k);
|
||||
return [trim($matches[1]), $k];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ class Checkout_Steps extends Rule {
|
||||
* @since 2.0.0
|
||||
* @var array
|
||||
*/
|
||||
protected $fillableParams = array(); // phpcs:ignore
|
||||
protected $fillableParams = []; // phpcs:ignore
|
||||
/**
|
||||
* Performs the actual check.
|
||||
*
|
||||
@ -90,11 +90,11 @@ class Checkout_Steps extends Rule {
|
||||
*/
|
||||
$submittable_field_types = apply_filters(
|
||||
'wu_checkout_step_validation_submittable_field_types',
|
||||
array(
|
||||
[
|
||||
'submit_button',
|
||||
'pricing_table',
|
||||
'template_selection',
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
/**
|
||||
@ -103,11 +103,11 @@ class Checkout_Steps extends Rule {
|
||||
foreach ($value as $step) {
|
||||
$found_submittable_field_types = \Arrch\Arrch::find(
|
||||
$step['fields'],
|
||||
array(
|
||||
'where' => array(
|
||||
array('type', $submittable_field_types),
|
||||
),
|
||||
)
|
||||
[
|
||||
'where' => [
|
||||
['type', $submittable_field_types],
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
if (empty($found_submittable_field_types)) {
|
||||
|
@ -27,7 +27,7 @@ class City extends Rule {
|
||||
* @since 2.0.4
|
||||
* @var array
|
||||
*/
|
||||
protected $fillableParams = array('country', 'state');
|
||||
protected $fillableParams = ['country', 'state'];
|
||||
/**
|
||||
* Performs the actual check.
|
||||
*
|
||||
@ -35,7 +35,7 @@ class City extends Rule {
|
||||
*
|
||||
* @param mixed $city The city value detected.
|
||||
*/
|
||||
public function check($city) : bool {
|
||||
public function check($city): bool {
|
||||
|
||||
$check = true;
|
||||
|
||||
|
@ -27,7 +27,7 @@ class Country extends Rule {
|
||||
* @since 2.0.4
|
||||
* @var array
|
||||
*/
|
||||
protected $fillableParams = array(); // phpcs:ignore
|
||||
protected $fillableParams = []; // phpcs:ignore
|
||||
/**
|
||||
* Performs the actual check.
|
||||
*
|
||||
|
@ -35,7 +35,7 @@ class Domain extends Rule {
|
||||
* @since 2.0.0
|
||||
* @var array
|
||||
*/
|
||||
protected $fillableParams = array(); // phpcs:ignore
|
||||
protected $fillableParams = []; // phpcs:ignore
|
||||
/**
|
||||
* Performs the actual check.
|
||||
*
|
||||
|
@ -35,7 +35,7 @@ class Exists extends Rule {
|
||||
* @since 2.0.0
|
||||
* @var array
|
||||
*/
|
||||
protected $fillableParams = array('model', 'column', 'except'); // phpcs:ignore
|
||||
protected $fillableParams = ['model', 'column', 'except']; // phpcs:ignore
|
||||
|
||||
/**
|
||||
* Performs the actual check.
|
||||
@ -47,10 +47,10 @@ class Exists extends Rule {
|
||||
public function check($value): bool {
|
||||
|
||||
$this->requireParameters(
|
||||
array(
|
||||
[
|
||||
'model',
|
||||
'column',
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
$column = $this->parameter('column');
|
||||
|
@ -35,7 +35,7 @@ class Price_Variations extends Rule {
|
||||
* @since 2.0.0
|
||||
* @var array
|
||||
*/
|
||||
protected $fillableParams = array('duration', 'duration_unit'); // phpcs:ignore
|
||||
protected $fillableParams = ['duration', 'duration_unit']; // phpcs:ignore
|
||||
/**
|
||||
* Performs the actual check.
|
||||
*
|
||||
@ -75,12 +75,12 @@ class Price_Variations extends Rule {
|
||||
*/
|
||||
$unit = wu_get_isset($price_variation, 'duration_unit', false);
|
||||
|
||||
$allowed_units = array(
|
||||
$allowed_units = [
|
||||
'day',
|
||||
'week',
|
||||
'month',
|
||||
'year',
|
||||
);
|
||||
];
|
||||
|
||||
if (!in_array($unit, $allowed_units, true)) {
|
||||
|
||||
|
@ -35,7 +35,7 @@ class Products extends Rule {
|
||||
* @since 2.0.4
|
||||
* @var array
|
||||
*/
|
||||
protected $fillableParams = array(); // phpcs:ignore
|
||||
protected $fillableParams = []; // phpcs:ignore
|
||||
/**
|
||||
* Performs the actual check.
|
||||
*
|
||||
@ -49,7 +49,7 @@ class Products extends Rule {
|
||||
|
||||
$product_objects = array_map('wu_get_product', $products);
|
||||
|
||||
list($plan, $additional_products) = wu_segregate_products($product_objects);
|
||||
[$plan, $additional_products] = wu_segregate_products($product_objects);
|
||||
|
||||
if ($plan) {
|
||||
return true;
|
||||
|
@ -37,7 +37,7 @@ class Site_Template extends Rule {
|
||||
* @since 2.0.4
|
||||
* @var array
|
||||
*/
|
||||
protected $fillableParams = array(); // phpcs:ignore
|
||||
protected $fillableParams = []; // phpcs:ignore
|
||||
/**
|
||||
* Performs the actual check.
|
||||
*
|
||||
@ -81,7 +81,7 @@ class Site_Template extends Rule {
|
||||
|
||||
$allowed_templates = false;
|
||||
|
||||
$product_ids_or_slugs = Checkout::get_instance()->request_or_session('products', array());
|
||||
$product_ids_or_slugs = Checkout::get_instance()->request_or_session('products', []);
|
||||
|
||||
$product_ids_or_slugs = array_unique($product_ids_or_slugs);
|
||||
|
||||
@ -90,9 +90,9 @@ class Site_Template extends Rule {
|
||||
|
||||
$limits = new \WP_Ultimo\Objects\Limitations();
|
||||
|
||||
list($plan, $additional_products) = wu_segregate_products($products);
|
||||
[$plan, $additional_products] = wu_segregate_products($products);
|
||||
|
||||
$products = array_merge(array($plan), $additional_products);
|
||||
$products = array_merge([$plan], $additional_products);
|
||||
|
||||
foreach ($products as $product) {
|
||||
$limits = $limits->merge($product->get_limitations());
|
||||
|
@ -27,7 +27,7 @@ class State extends Rule {
|
||||
* @since 2.0.4
|
||||
* @var array
|
||||
*/
|
||||
protected $fillableParams = array('country'); // phpcs:ignore
|
||||
protected $fillableParams = ['country']; // phpcs:ignore
|
||||
/**
|
||||
* Performs the actual check.
|
||||
*
|
||||
|
@ -35,7 +35,7 @@ class Unique_Site extends Rule {
|
||||
* @since 2.0.0
|
||||
* @var array
|
||||
*/
|
||||
protected $fillableParams = array('self_id'); // phpcs:ignore
|
||||
protected $fillableParams = ['self_id']; // phpcs:ignore
|
||||
/**
|
||||
* Performs the actual check.
|
||||
*
|
||||
@ -45,7 +45,7 @@ class Unique_Site extends Rule {
|
||||
*/
|
||||
public function check($value) : bool { // phpcs:ignore
|
||||
|
||||
$this->requireParameters(array());
|
||||
$this->requireParameters([]);
|
||||
|
||||
$self_id = $this->parameter('self_id');
|
||||
|
||||
|
@ -35,7 +35,7 @@ class Unique extends Rule {
|
||||
* @since 2.0.0
|
||||
* @var array
|
||||
*/
|
||||
protected $fillableParams = array('model', 'column', 'self_id'); // phpcs:ignore
|
||||
protected $fillableParams = ['model', 'column', 'self_id']; // phpcs:ignore
|
||||
|
||||
/**
|
||||
* Performs the actual check.
|
||||
@ -47,10 +47,10 @@ class Unique extends Rule {
|
||||
public function check($value): bool {
|
||||
|
||||
$this->requireParameters(
|
||||
array(
|
||||
[
|
||||
'model',
|
||||
'column',
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
$column = $this->parameter('column');
|
||||
@ -62,17 +62,17 @@ class Unique extends Rule {
|
||||
$callback = 'get_user_by';
|
||||
break;
|
||||
default:
|
||||
$callback = array($model, 'get_by');
|
||||
$callback = [$model, 'get_by'];
|
||||
break;
|
||||
}
|
||||
|
||||
// do query
|
||||
$existing = call_user_func($callback, $column, $value);
|
||||
|
||||
$user_models = array(
|
||||
$user_models = [
|
||||
'\WP_User',
|
||||
'\WP_Ultimo\Models\Customer',
|
||||
);
|
||||
\WP_Ultimo\Models\Customer::class,
|
||||
];
|
||||
|
||||
/*
|
||||
* Customize the error message for the customer.
|
||||
|
Reference in New Issue
Block a user