Use new code style

This commit is contained in:
David Stone
2025-02-07 19:02:33 -07:00
parent 0181024ae1
commit 8433379d90
672 changed files with 37107 additions and 45249 deletions

View File

@ -37,10 +37,9 @@ class Limit_Customer_User_Role extends Limit {
return array(
'enabled' => true,
'limit' => 'default'
'limit' => 'default',
);
} // end default_state;
}
/**
* The check method is what gets called when allowed is called.
@ -58,8 +57,7 @@ class Limit_Customer_User_Role extends Limit {
public function check($value_to_check, $limit, $type = '') {
return true;
} // end check;
}
/**
* Gets the limit data.
@ -74,7 +72,5 @@ class Limit_Customer_User_Role extends Limit {
$default_value = wu_get_setting('default_role', 'administrator');
return empty($this->limit) || $this->limit === 'default' ? $default_value : $this->limit;
} // end get_limit;
} // end class Limit_Customer_User_Role;
}
}

View File

@ -43,7 +43,5 @@ class Limit_Disk_Space extends Limit {
public function check($value_to_check, $limit, $type = '') {
return true;
} // end check;
} // end class Limit_Disk_Space;
}
}

View File

@ -36,11 +36,11 @@ class Limit_Domain_Mapping extends Limit {
protected $mode = 'default';
/**
* Allows sub-type limits to set their own default value for enabled.
*
* @since 2.0.0
* @var bool
*/
* Allows sub-type limits to set their own default value for enabled.
*
* @since 2.0.0
* @var bool
*/
private bool $enabled_default_value = true;
/**
@ -56,8 +56,7 @@ class Limit_Domain_Mapping extends Limit {
parent::setup($data);
$this->mode = wu_get_isset($data, 'mode', 'default');
} // end setup;
}
/**
* Returns the mode. Can be one of three: default, assign_template and choose_available_templates.
@ -68,8 +67,7 @@ class Limit_Domain_Mapping extends Limit {
public function get_mode() {
return $this->mode;
} // end get_mode;
}
/**
* The check method is what gets called when allowed is called.
@ -89,8 +87,7 @@ class Limit_Domain_Mapping extends Limit {
$check = true;
return $check;
} // end check;
}
/**
* Returns default permissions.
@ -105,8 +102,7 @@ class Limit_Domain_Mapping extends Limit {
return array(
'behavior' => 'available',
);
} // end get_default_permissions;
}
/**
* Returns a default state.
@ -121,7 +117,5 @@ class Limit_Domain_Mapping extends Limit {
'limit' => null,
'mode' => 'default',
);
} // end default_state;
} // end class Limit_Domain_Mapping;
}
}

View File

@ -55,8 +55,7 @@ class Limit_Plugins extends Limit {
);
return wu_get_isset($types, $type, false);
} // end check;
}
/**
* Adds a magic getter for plugins.
@ -71,8 +70,7 @@ class Limit_Plugins extends Limit {
$plugin = (object) wu_get_isset($this->get_limit(), $plugin_name, $this->get_default_permissions($plugin_name));
return (object) wp_parse_args($plugin, $this->get_default_permissions($plugin_name));
} // end __get;
}
/**
* Returns a list of plugins by behavior and visibility.
@ -88,24 +86,22 @@ class Limit_Plugins extends Limit {
$search_params = array();
if ($behavior) {
$search_params[] = array('behavior', $behavior);
} // end if;
}
if ($visibility) {
$search_params[] = array('visibility', $visibility);
}
} // end if;
$results = \Arrch\Arrch::find((array) $this->get_limit(), array(
'where' => $search_params,
));
$results = \Arrch\Arrch::find(
(array) $this->get_limit(),
array(
'where' => $search_params,
)
);
return $results;
} // end get_by_type;
}
/**
* Returns default permissions.
@ -121,8 +117,7 @@ class Limit_Plugins extends Limit {
'visibility' => 'visible',
'behavior' => 'default',
);
} // end get_default_permissions;
}
/**
* Checks if a theme exists on the current module.
@ -137,8 +132,7 @@ class Limit_Plugins extends Limit {
$results = wu_get_isset($this->get_limit(), $plugin_name, array());
return wu_get_isset($results, 'visibility', 'not-set') !== 'not-set' || wu_get_isset($results, 'behavior', 'not-set') !== 'not-set';
} // end exists;
}
/**
* Checks if the module is enabled.
@ -151,7 +145,5 @@ class Limit_Plugins extends Limit {
public function is_enabled($type = '') {
return true;
} // end is_enabled;
} // end class Limit_Plugins;
}
}

View File

@ -54,8 +54,7 @@ class Limit_Post_Types extends Limit_Subtype {
* @param int User id
*/
return apply_filters('wu_limits_is_post_above_limit', $quota > 0 && $post_count >= $quota);
} // end is_post_above_limit;
}
/**
* Get the post count for this site.
@ -85,14 +84,10 @@ class Limit_Post_Types extends Limit_Subtype {
$post_statuses = apply_filters('wu_post_count_statuses', $statuses, $post_type);
foreach ($post_statuses as $post_status) {
if (isset($post_count->{$post_status})) {
$count += (int) $post_count->{$post_status};
} // end if;
} // end foreach;
}
}
/**
* Allow plugin developers to change the count total
@ -104,7 +99,5 @@ class Limit_Post_Types extends Limit_Subtype {
* @return int New total
*/
return apply_filters('wu_post_count', $count, $post_count, $post_type);
} // end get_post_count;
} // end class Limit_Post_Types;
}
}

View File

@ -36,11 +36,11 @@ class Limit_Site_Templates extends Limit {
protected $mode = 'default';
/**
* Allows sub-type limits to set their own default value for enabled.
*
* @since 2.0.0
* @var bool
*/
* Allows sub-type limits to set their own default value for enabled.
*
* @since 2.0.0
* @var bool
*/
private bool $enabled_default_value = true;
/**
@ -56,8 +56,7 @@ class Limit_Site_Templates extends Limit {
parent::setup($data);
$this->mode = wu_get_isset($data, 'mode', 'default');
} // end setup;
}
/**
* Returns the mode. Can be one of three: default, assign_template and choose_available_templates.
@ -68,8 +67,7 @@ class Limit_Site_Templates extends Limit {
public function get_mode() {
return $this->mode;
} // end get_mode;
}
/**
* The check method is what gets called when allowed is called.
@ -95,8 +93,7 @@ class Limit_Site_Templates extends Limit {
);
return wu_get_isset($types, $type, true);
} // end check;
}
/**
* Adds a magic getter for themes.
@ -113,8 +110,7 @@ class Limit_Site_Templates extends Limit {
$template = (object) wu_get_isset($this->get_limit(), $template_id, $this->get_default_permissions($template_id));
return (object) wp_parse_args($template, $this->get_default_permissions($template_id));
} // end __get;
}
/**
* Returns default permissions.
@ -129,8 +125,7 @@ class Limit_Site_Templates extends Limit {
return array(
'behavior' => 'available',
);
} // end get_default_permissions;
}
/**
* Checks if a theme exists on the current module.
@ -147,8 +142,7 @@ class Limit_Site_Templates extends Limit {
$results = wu_get_isset($this->get_limit(), $template_id, array());
return wu_get_isset($results, 'behavior', 'not-set') !== 'not-set';
} // end exists;
}
/**
* Get all themes.
@ -161,8 +155,7 @@ class Limit_Site_Templates extends Limit {
$templates = (array) $this->get_limit();
return array_keys($templates);
} // end get_all_templates;
}
/**
* Get available themes.
@ -174,31 +167,24 @@ class Limit_Site_Templates extends Limit {
$limits = $this->get_limit();
if (!$limits) {
if ( ! $limits) {
return false;
} // end if;
}
$limits = (array) $limits;
$available = array();
foreach ($limits as $site_id => $site_settings) {
$site_settings = (object) $site_settings;
if ($site_settings->behavior === 'available' || $site_settings->behavior === 'pre_selected' || $this->mode === 'default') {
$available[] = $site_id;
} // end if;
} // end foreach;
}
}
return $available;
} // end get_available_site_templates;
}
/**
* Get the forced active theme for the current limitations.
@ -212,27 +198,20 @@ class Limit_Site_Templates extends Limit {
$pre_selected_site_template = false;
if (!$limits) {
if ( ! $limits) {
return $pre_selected_site_template;
} // end if;
}
foreach ($limits as $site_id => $site_settings) {
$site_settings = (object) $site_settings;
if ($site_settings->behavior === 'pre_selected') {
$pre_selected_site_template = $site_id;
} // end if;
} // end foreach;
}
}
return $pre_selected_site_template;
} // end get_pre_selected_site_template;
}
/**
* Handles limits on post submission.
@ -245,8 +224,7 @@ class Limit_Site_Templates extends Limit {
$module = wu_get_isset($_POST['modules'], $this->id, array());
return wu_get_isset($module, 'limit', $this->get_limit());
} // end handle_limit;
}
/**
* Handles other elements when saving. Used for custom attributes.
@ -263,8 +241,7 @@ class Limit_Site_Templates extends Limit {
$module['mode'] = wu_get_isset($_module, 'mode', 'default');
return $module;
} // end handle_others;
}
/**
* Returns a default state.
@ -279,7 +256,5 @@ class Limit_Site_Templates extends Limit {
'limit' => null,
'mode' => 'default',
);
} // end default_state;
} // end class Limit_Site_Templates;
}
}

View File

@ -43,7 +43,5 @@ class Limit_Sites extends Limit {
public function check($value_to_check, $limit, $type = '') {
return true;
} // end check;
} // end class Limit_Sites;
}
}

View File

@ -36,11 +36,9 @@ class Limit_Subtype extends Limit {
/*
* If no type is passed, bail.
*/
if (!$type) {
if ( ! $type) {
return false;
} // end if;
}
/*
* Set default values for inexistent post types.
@ -51,24 +49,19 @@ class Limit_Subtype extends Limit {
/*
* Case post type disabled.
*/
if (!$post_type_limit->enabled) {
if ( ! $post_type_limit->enabled) {
return false;
} // end if;
}
/*
* Case unlimited posts
*/
if (absint($post_type_limit->number) === 0) {
return true;
} // end if;
}
return absint($value_to_check) < absint($post_type_limit->number);
} // end check;
}
/**
* Adds a magic getter for subtypes.
@ -83,8 +76,7 @@ class Limit_Subtype extends Limit {
$type = (object) wu_get_isset($this->get_limit(), $sub_type, $this->get_default_permissions($sub_type));
return (object) wp_parse_args($type, $this->get_default_permissions($sub_type));
} // end __get;
}
/**
* Returns default permissions.
@ -100,8 +92,7 @@ class Limit_Subtype extends Limit {
'enabled' => true,
'number' => '', // unlimited
);
} // end get_default_permissions;
}
/**
* Checks if a theme exists on the current module.
@ -116,8 +107,7 @@ class Limit_Subtype extends Limit {
$results = wu_get_isset($this->get_limit(), $type, array());
return wu_get_isset($results, 'number', 'not-set') !== 'not-set';
} // end exists;
}
/**
* Handles limits on post submission.
@ -127,16 +117,12 @@ 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', array());
foreach ($received as $post_type => &$limitations) {
$limitations['enabled'] = (bool) wu_get_isset($_POST['modules'][$this->id]['limit'][$post_type], 'enabled', false);
} // end foreach;
$limitations['enabled'] = (bool) wu_get_isset($_POST['modules'][ $this->id ]['limit'][ $post_type ], 'enabled', false);
}
return $received;
} // end handle_limit;
} // end class Limit_Subtype;
}
}

View File

@ -60,8 +60,7 @@ class Limit_Themes extends Limit {
);
return wu_get_isset($types, $type, false);
} // end check;
}
/**
* Adds a magic getter for themes.
@ -76,8 +75,7 @@ class Limit_Themes extends Limit {
$theme = (object) wu_get_isset($this->get_limit(), $theme_name, $this->get_default_permissions($theme_name));
return (object) wp_parse_args($theme, $this->get_default_permissions($theme_name));
} // end __get;
}
/**
* Returns default permissions.
@ -93,8 +91,7 @@ class Limit_Themes extends Limit {
'visibility' => 'visible',
'behavior' => 'available',
);
} // end get_default_permissions;
}
/**
* Checks if a theme exists on the current module.
@ -109,8 +106,7 @@ class Limit_Themes extends Limit {
$results = wu_get_isset($this->get_limit(), $theme_name, array());
return wu_get_isset($results, 'visibility', 'not-set') !== 'not-set' || wu_get_isset($results, 'behavior', 'not-set') !== 'not-set';
} // end exists;
}
/**
* Get all themes.
@ -123,8 +119,7 @@ class Limit_Themes extends Limit {
$themes = (array) $this->get_limit();
return array_keys($themes);
} // end get_all_themes;
}
/**
* Get available themes.
@ -139,20 +134,15 @@ class Limit_Themes extends Limit {
$available = array();
foreach ($limits as $theme_slug => $theme_settings) {
$theme_settings = (object) $theme_settings;
if ($theme_settings->behavior === 'available') {
$available[] = $theme_slug;
} // end if;
} // end foreach;
}
}
return $available;
} // end get_available_themes;
}
/**
* Get the forced active theme for the current limitations.
@ -167,34 +157,25 @@ class Limit_Themes extends Limit {
$limits = $this->get_limit();
if (empty($limits)) {
return $active_theme;
} // end if;
}
if ($this->forced_active_theme !== null) {
return $this->forced_active_theme;
} // end if;
}
foreach ($limits as $theme_slug => $theme_settings) {
$theme_settings = (object) $theme_settings;
if ($theme_settings->behavior === 'force_active') {
$active_theme = $theme_slug;
} // end if;
} // end foreach;
}
}
$this->forced_active_theme = $active_theme;
return $this->forced_active_theme;
} // end get_forced_active_theme;
}
/**
* Checks if the module is enabled.
@ -207,7 +188,5 @@ class Limit_Themes extends Limit {
public function is_enabled($type = '') {
return true;
} // end is_enabled;
} // end class Limit_Themes;
}
}

View File

@ -26,5 +26,4 @@ class Limit_Users extends Limit_Subtype {
* @var string
*/
protected $id = 'users';
} // end class Limit_Users;
}

View File

@ -43,7 +43,5 @@ class Limit_Visits extends Limit {
public function check($value_to_check, $limit, $type = '') {
return true;
} // end check;
} // end class Limit_Visits;
}
}

View File

@ -51,33 +51,33 @@ abstract class Limit implements \JsonSerializable {
protected $enabled;
/**
* Controls if this limit has its own limit.
*
* When the limit is inherited from other models,
* such as memberships or products.
*
* @since 2.0.0
* @var bool
*/
* Controls if this limit has its own limit.
*
* When the limit is inherited from other models,
* such as memberships or products.
*
* @since 2.0.0
* @var bool
*/
private bool $has_own_limit = true;
/**
* Controls if this limit has its own enabled status.
*
* When the enabled is inherited from other models,
* such as memberships or products.
*
* @since 2.0.0
* @var bool
*/
* Controls if this limit has its own enabled status.
*
* When the enabled is inherited from other models,
* such as memberships or products.
*
* @since 2.0.0
* @var bool
*/
private bool $has_own_enabled = true;
/**
* Allows sub-type limits to set their own default value for enabled.
*
* @since 2.0.0
* @var bool
*/
* Allows sub-type limits to set their own default value for enabled.
*
* @since 2.0.0
* @var bool
*/
private bool $enabled_default_value = true;
/**
@ -89,8 +89,7 @@ abstract class Limit implements \JsonSerializable {
public function __construct($data) {
$this->setup($data);
} // end __construct;
}
/**
* Prepare for serialization.
@ -101,8 +100,7 @@ abstract class Limit implements \JsonSerializable {
public function __serialize() { // phpcs:ignore
return serialize($this->to_array());
} // end __serialize;
}
/**
* Handles un-serialization.
@ -115,8 +113,7 @@ abstract class Limit implements \JsonSerializable {
public function __unserialize($data) { // phpcs:ignore
$this->setup(unserialize($data));
} // end __unserialize;
}
/**
* Sets up the module based on the module data.
@ -128,11 +125,9 @@ abstract class Limit implements \JsonSerializable {
*/
public function setup($data) {
if (!is_array($data)) {
if ( ! is_array($data)) {
$data = (array) $data;
} // end if;
}
$current_limit = wu_get_isset($data, 'limit', 'not-set');
@ -140,31 +135,29 @@ abstract class Limit implements \JsonSerializable {
* Sets the own limit flag, if necessary.
*/
if ($current_limit === 'not-set' || $current_limit === '') {
$this->has_own_limit = false;
} // end if;
}
/*
* Sets the own enabled flag, if necessary.
*/
if (wu_get_isset($data, 'enabled', 'not-set') === 'not-set') {
$this->has_own_enabled = false;
}
} // end if;
$data = wp_parse_args($data, array(
'limit' => null,
'enabled' => $this->enabled_default_value,
));
$data = wp_parse_args(
$data,
array(
'limit' => null,
'enabled' => $this->enabled_default_value,
)
);
$this->limit = is_array($data['limit']) ? (object) $data['limit'] : $data['limit'];
$this->enabled = (bool) $data['enabled'];
do_action("wu_{$this->id}_limit_setup", $data, $this);
} // end setup;
}
/**
* Returns the id of the module.
@ -175,8 +168,7 @@ abstract class Limit implements \JsonSerializable {
public function get_id() {
return $this->id;
} // end get_id;
}
/**
* Checks if a value is allowed under this limit.
@ -193,19 +185,16 @@ abstract class Limit implements \JsonSerializable {
* @param string $type The type parameter.
* @return bool
*/
public final function allowed($value_to_check, $type = '') {
final public function allowed($value_to_check, $type = '') {
$allowed = $this->is_enabled();
if ($allowed) {
$allowed = $this->check($value_to_check, $this->limit, $type);
} // end if;
}
return apply_filters("wu_limit_{$this->id}_{$type}_allowed", $allowed, $type, $this);
} // end allowed;
}
/**
* The check method is what gets called when allowed is called.
@ -233,8 +222,7 @@ abstract class Limit implements \JsonSerializable {
public function get_limit($type = '') {
return $this->limit;
} // end get_limit;
}
/**
* Checks if the module is enabled.
@ -247,8 +235,7 @@ abstract class Limit implements \JsonSerializable {
public function is_enabled($type = '') {
return $this->enabled;
} // end is_enabled;
}
/**
* Converts the limitations list to an array.
@ -268,8 +255,7 @@ abstract class Limit implements \JsonSerializable {
unset($array['enabled_default_value']);
return $array;
} // end to_array;
}
/**
* Prepares for serialization.
@ -281,8 +267,7 @@ abstract class Limit implements \JsonSerializable {
public function jsonSerialize() {
return json_encode($this->to_array());
} // end jsonSerialize;
}
/**
* Checks if this module has its own limit.
@ -293,8 +278,7 @@ abstract class Limit implements \JsonSerializable {
public function has_own_limit() {
return $this->has_own_limit;
} // end has_own_limit;
}
/**
* Checks if this module has its own enabled.
@ -305,8 +289,7 @@ abstract class Limit implements \JsonSerializable {
public function has_own_enabled() {
return $this->has_own_enabled;
} // end has_own_enabled;
}
/**
* Handles enabled status on post submission.
@ -319,8 +302,7 @@ abstract class Limit implements \JsonSerializable {
$module = wu_get_isset($_POST['modules'], $this->id, array());
return (bool) wu_get_isset($module, 'enabled', false);
} // end handle_enabled;
}
/**
* Handles other elements when saving. Used for custom attributes.
@ -333,8 +315,7 @@ abstract class Limit implements \JsonSerializable {
public function handle_others($module) {
return $module;
} // end handle_others;
}
/**
* Handles limits on post submission.
@ -347,8 +328,7 @@ abstract class Limit implements \JsonSerializable {
$module = wu_get_isset($_POST['modules'], $this->id, array());
return wu_get_isset($module, 'limit', null);
} // end handle_limit;
}
/**
* Returns a default state.
@ -362,7 +342,5 @@ abstract class Limit implements \JsonSerializable {
'enabled' => false,
'limit' => null,
);
} // end default_state;
} // end class Limit;
}
}