Use PHP 7.4 featers and PHP 8 polyfills
This commit is contained in:
@ -35,10 +35,10 @@ class Limit_Customer_User_Role extends Limit {
|
||||
*/
|
||||
public static function default_state() {
|
||||
|
||||
return array(
|
||||
return [
|
||||
'enabled' => true,
|
||||
'limit' => 'default',
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -51,7 +51,7 @@ class Limit_Domain_Mapping extends Limit {
|
||||
* @param array $data The module data.
|
||||
* @return void
|
||||
*/
|
||||
public function setup($data) {
|
||||
public function setup($data): void {
|
||||
|
||||
parent::setup($data);
|
||||
|
||||
@ -99,9 +99,9 @@ class Limit_Domain_Mapping extends Limit {
|
||||
*/
|
||||
public function get_default_permissions($type) {
|
||||
|
||||
return array(
|
||||
return [
|
||||
'behavior' => 'available',
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -112,10 +112,10 @@ class Limit_Domain_Mapping extends Limit {
|
||||
*/
|
||||
public static function default_state() {
|
||||
|
||||
return array(
|
||||
return [
|
||||
'enabled' => true,
|
||||
'limit' => null,
|
||||
'mode' => 'default',
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ class Limit_Plugins extends Limit {
|
||||
|
||||
$plugin = (object) $this->{$value_to_check};
|
||||
|
||||
$types = array(
|
||||
$types = [
|
||||
'visible' => $plugin->visibility === 'visible',
|
||||
'hidden' => $plugin->visibility === 'hidden',
|
||||
'default' => $plugin->behavior === 'default',
|
||||
@ -52,7 +52,7 @@ class Limit_Plugins extends Limit {
|
||||
'force_inactive' => $plugin->behavior === 'force_inactive',
|
||||
'force_active_locked' => $plugin->behavior === 'force_active_locked',
|
||||
'force_inactive_locked' => $plugin->behavior === 'force_inactive_locked',
|
||||
);
|
||||
];
|
||||
|
||||
return wu_get_isset($types, $type, false);
|
||||
}
|
||||
@ -83,21 +83,21 @@ class Limit_Plugins extends Limit {
|
||||
*/
|
||||
public function get_by_type($behavior = null, $visibility = null) {
|
||||
|
||||
$search_params = array();
|
||||
$search_params = [];
|
||||
|
||||
if ($behavior) {
|
||||
$search_params[] = array('behavior', $behavior);
|
||||
$search_params[] = ['behavior', $behavior];
|
||||
}
|
||||
|
||||
if ($visibility) {
|
||||
$search_params[] = array('visibility', $visibility);
|
||||
$search_params[] = ['visibility', $visibility];
|
||||
}
|
||||
|
||||
$results = \Arrch\Arrch::find(
|
||||
(array) $this->get_limit(),
|
||||
array(
|
||||
[
|
||||
'where' => $search_params,
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
return $results;
|
||||
@ -113,10 +113,10 @@ class Limit_Plugins extends Limit {
|
||||
*/
|
||||
public function get_default_permissions($type) {
|
||||
|
||||
return array(
|
||||
return [
|
||||
'visibility' => 'visible',
|
||||
'behavior' => 'default',
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -129,7 +129,7 @@ class Limit_Plugins extends Limit {
|
||||
*/
|
||||
public function exists($plugin_name) {
|
||||
|
||||
$results = wu_get_isset($this->get_limit(), $plugin_name, array());
|
||||
$results = wu_get_isset($this->get_limit(), $plugin_name, []);
|
||||
|
||||
return wu_get_isset($results, 'visibility', 'not-set') !== 'not-set' || wu_get_isset($results, 'behavior', 'not-set') !== 'not-set';
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ class Limit_Post_Types extends Limit_Subtype {
|
||||
/*
|
||||
* Calculate post count based on all different status
|
||||
*/
|
||||
$post_count = $this->get_post_count($post_type);
|
||||
$post_count = static::get_post_count($post_type);
|
||||
|
||||
// Get the allowed quota
|
||||
$quota = $this->{$post_type}->number;
|
||||
@ -70,7 +70,7 @@ class Limit_Post_Types extends Limit_Subtype {
|
||||
|
||||
$post_count = wp_count_posts($post_type);
|
||||
|
||||
$statuses = $post_type === 'attachment' ? array('inherit') : array('publish', 'private');
|
||||
$statuses = $post_type === 'attachment' ? ['inherit'] : ['publish', 'private'];
|
||||
|
||||
/**
|
||||
* Allow plugin developers to change which post status should be counted
|
||||
|
@ -51,7 +51,7 @@ class Limit_Site_Templates extends Limit {
|
||||
* @param array $data The module data.
|
||||
* @return void
|
||||
*/
|
||||
public function setup($data) {
|
||||
public function setup($data): void {
|
||||
|
||||
parent::setup($data);
|
||||
|
||||
@ -86,11 +86,11 @@ class Limit_Site_Templates extends Limit {
|
||||
|
||||
$template = (object) $this->{$value_to_check};
|
||||
|
||||
$types = array(
|
||||
$types = [
|
||||
'available' => $template->behavior === 'available',
|
||||
'not_available' => $template->behavior === 'not_available',
|
||||
'pre_selected' => $template->behavior === 'pre_selected',
|
||||
);
|
||||
];
|
||||
|
||||
return wu_get_isset($types, $type, true);
|
||||
}
|
||||
@ -122,9 +122,9 @@ class Limit_Site_Templates extends Limit {
|
||||
*/
|
||||
public function get_default_permissions($type) {
|
||||
|
||||
return array(
|
||||
return [
|
||||
'behavior' => 'available',
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -139,7 +139,7 @@ class Limit_Site_Templates extends Limit {
|
||||
|
||||
$template_id = str_replace('site_', '', $template_id);
|
||||
|
||||
$results = wu_get_isset($this->get_limit(), $template_id, array());
|
||||
$results = wu_get_isset($this->get_limit(), $template_id, []);
|
||||
|
||||
return wu_get_isset($results, 'behavior', 'not-set') !== 'not-set';
|
||||
}
|
||||
@ -173,7 +173,7 @@ class Limit_Site_Templates extends Limit {
|
||||
|
||||
$limits = (array) $limits;
|
||||
|
||||
$available = array();
|
||||
$available = [];
|
||||
|
||||
foreach ($limits as $site_id => $site_settings) {
|
||||
$site_settings = (object) $site_settings;
|
||||
@ -221,7 +221,7 @@ class Limit_Site_Templates extends Limit {
|
||||
*/
|
||||
public function handle_limit() {
|
||||
|
||||
$module = wu_get_isset($_POST['modules'], $this->id, array());
|
||||
$module = wu_get_isset($_POST['modules'], $this->id, []);
|
||||
|
||||
return wu_get_isset($module, 'limit', $this->get_limit());
|
||||
}
|
||||
@ -236,7 +236,7 @@ class Limit_Site_Templates extends Limit {
|
||||
*/
|
||||
public function handle_others($module) {
|
||||
|
||||
$_module = wu_get_isset($_POST['modules'], $this->id, array());
|
||||
$_module = wu_get_isset($_POST['modules'], $this->id, []);
|
||||
|
||||
$module['mode'] = wu_get_isset($_module, 'mode', 'default');
|
||||
|
||||
@ -251,10 +251,10 @@ class Limit_Site_Templates extends Limit {
|
||||
*/
|
||||
public static function default_state() {
|
||||
|
||||
return array(
|
||||
return [
|
||||
'enabled' => true,
|
||||
'limit' => null,
|
||||
'mode' => 'default',
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -88,10 +88,10 @@ class Limit_Subtype extends Limit {
|
||||
*/
|
||||
public function get_default_permissions($type) {
|
||||
|
||||
return array(
|
||||
return [
|
||||
'enabled' => true,
|
||||
'number' => '', // unlimited
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -104,7 +104,7 @@ class Limit_Subtype extends Limit {
|
||||
*/
|
||||
public function exists($type) {
|
||||
|
||||
$results = wu_get_isset($this->get_limit(), $type, array());
|
||||
$results = wu_get_isset($this->get_limit(), $type, []);
|
||||
|
||||
return wu_get_isset($results, 'number', 'not-set') !== 'not-set';
|
||||
}
|
||||
@ -117,7 +117,7 @@ class Limit_Subtype extends Limit {
|
||||
*/
|
||||
public function handle_limit() {
|
||||
|
||||
$received = wu_get_isset($_POST['modules'][ $this->id ], 'limit', array());
|
||||
$received = wu_get_isset($_POST['modules'][ $this->id ], 'limit', []);
|
||||
|
||||
foreach ($received as $post_type => &$limitations) {
|
||||
$limitations['enabled'] = (bool) wu_get_isset($_POST['modules'][ $this->id ]['limit'][ $post_type ], 'enabled', false);
|
||||
|
@ -52,12 +52,12 @@ class Limit_Themes extends Limit {
|
||||
|
||||
$theme = (object) $this->{$value_to_check};
|
||||
|
||||
$types = array(
|
||||
$types = [
|
||||
'visible' => $theme->visibility === 'visible',
|
||||
'hidden' => $theme->visibility === 'hidden',
|
||||
'available' => $theme->behavior === 'available',
|
||||
'not_available' => $theme->behavior === 'not_available',
|
||||
);
|
||||
];
|
||||
|
||||
return wu_get_isset($types, $type, false);
|
||||
}
|
||||
@ -87,10 +87,10 @@ class Limit_Themes extends Limit {
|
||||
*/
|
||||
public function get_default_permissions($type) {
|
||||
|
||||
return array(
|
||||
return [
|
||||
'visibility' => 'visible',
|
||||
'behavior' => 'available',
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -103,7 +103,7 @@ class Limit_Themes extends Limit {
|
||||
*/
|
||||
public function exists($theme_name) {
|
||||
|
||||
$results = wu_get_isset($this->get_limit(), $theme_name, array());
|
||||
$results = wu_get_isset($this->get_limit(), $theme_name, []);
|
||||
|
||||
return wu_get_isset($results, 'visibility', 'not-set') !== 'not-set' || wu_get_isset($results, 'behavior', 'not-set') !== 'not-set';
|
||||
}
|
||||
@ -131,7 +131,7 @@ class Limit_Themes extends Limit {
|
||||
|
||||
$limits = $this->get_limit();
|
||||
|
||||
$available = array();
|
||||
$available = [];
|
||||
|
||||
foreach ($limits as $theme_slug => $theme_settings) {
|
||||
$theme_settings = (object) $theme_settings;
|
||||
|
@ -123,7 +123,7 @@ abstract class Limit implements \JsonSerializable {
|
||||
* @param array $data The module data.
|
||||
* @return void
|
||||
*/
|
||||
public function setup($data) {
|
||||
public function setup($data): void {
|
||||
|
||||
if ( ! is_array($data)) {
|
||||
$data = (array) $data;
|
||||
@ -147,10 +147,10 @@ abstract class Limit implements \JsonSerializable {
|
||||
|
||||
$data = wp_parse_args(
|
||||
$data,
|
||||
array(
|
||||
[
|
||||
'limit' => null,
|
||||
'enabled' => $this->enabled_default_value,
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
$this->limit = is_array($data['limit']) ? (object) $data['limit'] : $data['limit'];
|
||||
@ -299,7 +299,7 @@ abstract class Limit implements \JsonSerializable {
|
||||
*/
|
||||
public function handle_enabled() {
|
||||
|
||||
$module = wu_get_isset($_POST['modules'], $this->id, array());
|
||||
$module = wu_get_isset($_POST['modules'], $this->id, []);
|
||||
|
||||
return (bool) wu_get_isset($module, 'enabled', false);
|
||||
}
|
||||
@ -325,7 +325,7 @@ abstract class Limit implements \JsonSerializable {
|
||||
*/
|
||||
public function handle_limit() {
|
||||
|
||||
$module = wu_get_isset($_POST['modules'], $this->id, array());
|
||||
$module = wu_get_isset($_POST['modules'], $this->id, []);
|
||||
|
||||
return wu_get_isset($module, 'limit', null);
|
||||
}
|
||||
@ -338,9 +338,9 @@ abstract class Limit implements \JsonSerializable {
|
||||
*/
|
||||
public static function default_state() {
|
||||
|
||||
return array(
|
||||
return [
|
||||
'enabled' => false,
|
||||
'limit' => null,
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user