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

@ -126,8 +126,7 @@ class Domain extends Base_Model {
'secure' => 'default:0',
'primary_domain' => 'default:0',
);
} // end validation_rules;
}
/**
* Returns the domain address mapped.
@ -138,8 +137,7 @@ class Domain extends Base_Model {
public function get_domain() {
return $this->domain;
} // end get_domain;
}
/**
* Sets the domain of this model object;
@ -152,8 +150,7 @@ class Domain extends Base_Model {
public function set_domain($domain) {
$this->domain = strtolower($domain);
} // end set_domain;
}
/**
* Gets the URL with schema and all.
*
@ -166,8 +163,7 @@ class Domain extends Base_Model {
$schema = $this->is_secure() ? 'https://' : 'http://';
return sprintf('%s%s/%s', $schema, $this->get_domain(), $path);
} // end get_url;
}
/**
* Get the ID of the corresponding site.
@ -179,8 +175,7 @@ class Domain extends Base_Model {
public function get_blog_id() {
return (int) $this->blog_id;
} // end get_blog_id;
}
/**
* Sets the blog_id of this model object;
@ -193,8 +188,7 @@ class Domain extends Base_Model {
public function set_blog_id($blog_id) {
$this->blog_id = $blog_id;
} // end set_blog_id;
}
/**
* Get the ID of the corresponding site.
@ -205,15 +199,14 @@ class Domain extends Base_Model {
public function get_site_id() {
return $this->get_blog_id();
} // end get_site_id;
/**
* Get the site object for this particular mapping.
*
* @since 2.0.0
* @return \WP_Site|\WP_Ultimo\Models\Site|false
*/
public function get_site() {
}
/**
* Get the site object for this particular mapping.
*
* @since 2.0.0
* @return \WP_Site|\WP_Ultimo\Models\Site|false
*/
public function get_site() {
/**
* In a domain mapping environment, the user is not yet logged in.
@ -222,15 +215,12 @@ class Domain extends Base_Model {
*
* To bypass this limitation, we use the default WordPress function on those cases.
*/
if (!function_exists('current_user_can')) {
if ( ! function_exists('current_user_can')) {
return \WP_Site::get_instance($this->get_blog_id());
} // end if;
}
return wu_get_site($this->get_blog_id());
} // end get_site;
}
/**
* Check if this particular mapping is active.
@ -241,14 +231,11 @@ class Domain extends Base_Model {
public function is_active() {
if ($this->has_inactive_stage()) {
return false;
} // end if;
}
return (bool) $this->active;
} // end is_active;
}
/**
* Sets the active state of this model object;
@ -261,8 +248,7 @@ class Domain extends Base_Model {
public function set_active($active) {
$this->active = $active;
} // end set_active;
}
/**
* Check if this is a primary domain.
@ -273,8 +259,7 @@ class Domain extends Base_Model {
public function is_primary_domain() {
return (bool) $this->primary_domain;
} // end is_primary_domain;
}
/**
* Sets the primary_domain state of this model object;
@ -287,8 +272,7 @@ class Domain extends Base_Model {
public function set_primary_domain($primary_domain) {
$this->primary_domain = $primary_domain;
} // end set_primary_domain;
}
/**
* Check if we should use this domain securely (via HTTPS).
@ -299,8 +283,7 @@ class Domain extends Base_Model {
public function is_secure() {
return (bool) $this->secure;
} // end is_secure;
}
/**
* Sets the secure state of this model object;
@ -313,8 +296,7 @@ class Domain extends Base_Model {
public function set_secure($secure) {
$this->secure = $secure;
} // end set_secure;
}
/**
* Get the stage in which this domain is in at the moment.
@ -327,8 +309,7 @@ class Domain extends Base_Model {
public function get_stage() {
return $this->stage;
} // end get_stage;
}
/**
* Sets the stage of this model object;
@ -341,8 +322,7 @@ class Domain extends Base_Model {
public function set_stage($stage) {
$this->stage = $stage;
} // end set_stage;
}
/**
* Check if this domain is on a inactive stage.
*
@ -351,8 +331,7 @@ class Domain extends Base_Model {
public function has_inactive_stage(): bool {
return in_array($this->get_stage(), self::INACTIVE_STAGES, true);
} // end has_inactive_stage;
}
/**
* Returns the Label for a given stage level.
@ -365,8 +344,7 @@ class Domain extends Base_Model {
$type = new Domain_Stage($this->get_stage());
return $type->get_label();
} // end get_stage_label;
}
/**
* Gets the classes for a given stage level.
@ -379,8 +357,7 @@ class Domain extends Base_Model {
$type = new Domain_Stage($this->get_stage());
return $type->get_classes();
} // end get_stage_class;
}
/**
* Get date when this was created.
@ -391,8 +368,7 @@ class Domain extends Base_Model {
public function get_date_created() {
return $this->date_created;
} // end get_date_created;
}
/**
* Set date when this was created.
@ -404,8 +380,7 @@ class Domain extends Base_Model {
public function set_date_created($date_created) {
$this->date_created = $date_created;
} // end set_date_created;
}
/**
* Check if the domain is correctly set-up in terms of DNS resolution.
@ -426,16 +401,12 @@ class Domain extends Base_Model {
$domains_and_ips = array_column($results, 'data');
if (in_array($current_site->domain, $domains_and_ips, true)) {
return true;
} // end if;
}
if (in_array($network_ip_address, $domains_and_ips, true)) {
return true;
} // end if;
}
$result = false;
@ -451,8 +422,7 @@ class Domain extends Base_Model {
$result = apply_filters('wu_domain_has_correct_dns', $result, $this, $domains_and_ips);
return $result;
} // end has_correct_dns;
}
/**
* Checks if the current domain has a valid SSL certificate that covers it.
@ -463,8 +433,7 @@ class Domain extends Base_Model {
public function has_valid_ssl_certificate() {
return Helper::has_valid_ssl_certificate($this->get_domain());
} // end has_valid_ssl_certificate;
}
/**
* Save (create or update) the model on the database.
@ -485,11 +454,8 @@ class Domain extends Base_Model {
$results = parent::save();
if (is_wp_error($results) === false) {
if ($new_domain) {
if (has_action('mercator.mapping.created')) {
$deprecated_args = array(
$this,
);
@ -503,13 +469,8 @@ class Domain extends Base_Model {
* @return void.
*/
do_action_deprecated('mercator.mapping.created', $deprecated_args, '2.0.0', 'wu_domain_post_save');
} // end if;
} else {
if (has_action('mercator.mapping.updated')) {
}
} elseif (has_action('mercator.mapping.updated')) {
$deprecated_args = array(
$this,
$before_changes,
@ -524,10 +485,7 @@ class Domain extends Base_Model {
* @return void.
*/
do_action_deprecated('mercator.mapping.updated', $deprecated_args, '2.0.0', 'wu_domain_post_save');
} // end if;
} // end if;
}
/*
* Resets cache.
@ -536,24 +494,21 @@ class Domain extends Base_Model {
* after a change is made.
*/
wp_cache_flush();
} // end if;
}
return $results;
} // end save;
/**
* Delete the model from the database.
*
* @since 2.0.0
* @return \WP_Error|bool
*/
public function delete() {
}
/**
* Delete the model from the database.
*
* @since 2.0.0
* @return \WP_Error|bool
*/
public function delete() {
$results = parent::delete();
if (is_wp_error($results) === false && has_action('mercator.mapping.deleted')) {
$deprecated_args = array(
$this,
);
@ -566,8 +521,7 @@ class Domain extends Base_Model {
* @return void.
*/
do_action_deprecated('mercator.mapping.deleted', $deprecated_args, '2.0.0', 'wu_domain_post_delete');
} // end if;
}
/*
* Delete log file.
@ -577,8 +531,7 @@ class Domain extends Base_Model {
wu_log_add("domain-{$this->get_domain()}", __('Domain deleted and logs cleared...', 'wp-ultimo'));
return $results;
} // end delete;
}
/**
* Get mapping by site ID
@ -594,16 +547,12 @@ class Domain extends Base_Model {
// Allow passing a site object in
if (is_object($site) && isset($site->blog_id)) {
$site = $site->blog_id;
}
} // end if;
if (!is_numeric($site)) {
if ( ! is_numeric($site)) {
return new \WP_Error('wu_domain_mapping_invalid_id');
} // end if;
}
$site = absint($site);
@ -611,16 +560,12 @@ class Domain extends Base_Model {
$mappings = wp_cache_get('id:' . $site, 'domain_mapping');
if ($mappings === 'none') {
return false;
}
} // end if;
if (!empty($mappings)) {
if ( ! empty($mappings)) {
return static::to_instances($mappings);
} // end if;
}
// Cache missed, fetch from DB
// Suppress errors in case the table doesn't exist
@ -632,19 +577,16 @@ class Domain extends Base_Model {
$wpdb->suppress_errors($suppress);
if (!$mappings) {
if ( ! $mappings) {
wp_cache_set('id:' . $site, 'none', 'domain_mapping');
return false;
} // end if;
}
wp_cache_set('id:' . $site, $mappings, 'domain_mapping');
return static::to_instances($mappings);
} // end get_by_site;
}
/**
* Gets mappings by domain names
@ -666,28 +608,21 @@ class Domain extends Base_Model {
$not_exists = 0;
foreach ($domains as $domain) {
$data = wp_cache_get('domain:' . $domain, 'domain_mappings');
if (!empty($data) && $data !== 'notexists') {
if ( ! empty($data) && $data !== 'notexists') {
return new static($data);
} elseif ($data === 'notexists') {
$not_exists++;
} // end if;
} // end foreach;
++$not_exists;
}
}
if ($not_exists === count($domains)) {
// Every domain we checked was found in the cache, but doesn't exist
// so skip the query
return null;
} // end if;
}
$placeholders = array_fill(0, count($domains), '%s');
@ -709,19 +644,14 @@ class Domain extends Base_Model {
// Cache that it doesn't exist
foreach ($domains as $domain) {
wp_cache_set('domain:' . $domain, 'notexists', 'domain_mappings');
} // end foreach;
}
return null;
} // end if;
}
wp_cache_set('domain:' . $mapping->domain, $mapping, 'domain_mappings');
return new static($mapping);
} // end get_by_domain;
} // end class Domain;
}
}