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

@ -36,44 +36,44 @@ trait WP_Ultimo_Plan_Deprecated {
$value = null;
switch ($key) {
case 'title':
$value = $this->get_name();
break;
case 'id':
case 'ID':
$value = $this->get_id();
break;
case 'free':
$value = $this->get_pricing_type() === 'free';
break;
case 'price_1':
case 'price_3':
case 'price_12':
$value = 20;
break;
case 'top_deal':
$value = $this->is_featured_plan();
break;
case 'feature_list':
$value = $this->get_feature_list();
break;
case 'quotas':
$value = array(
// 'sites' => 300,
'upload' => 1024 * 1024 * 1024,
'visits' => 300,
);
break;
case 'post':
$value = (object) array(
'ID' => $this->get_id(),
'post_title' => $this->get_name(),
);
break;
default:
$value = $this->get_meta('wpu_' . $key, false, true);
break;
} // end switch;
case 'title':
$value = $this->get_name();
break;
case 'id':
case 'ID':
$value = $this->get_id();
break;
case 'free':
$value = $this->get_pricing_type() === 'free';
break;
case 'price_1':
case 'price_3':
case 'price_12':
$value = 20;
break;
case 'top_deal':
$value = $this->is_featured_plan();
break;
case 'feature_list':
$value = $this->get_feature_list();
break;
case 'quotas':
$value = array(
// 'sites' => 300,
'upload' => 1024 * 1024 * 1024,
'visits' => 300,
);
break;
case 'post':
$value = (object) array(
'ID' => $this->get_id(),
'post_title' => $this->get_name(),
);
break;
default:
$value = $this->get_meta('wpu_' . $key, false, true);
break;
}
/**
* Let developers know that this is not going to be supported in the future.
@ -83,8 +83,7 @@ trait WP_Ultimo_Plan_Deprecated {
_doing_it_wrong($key, __('Product keys should not be accessed directly', 'wp-ultimo'), '2.0.0');
return $value;
} // end __get;
}
/**
* Get the featured status for this product.
@ -95,14 +94,11 @@ trait WP_Ultimo_Plan_Deprecated {
public function is_featured_plan() {
if ($this->featured_plan === null) {
$this->featured_plan = $this->get_meta('featured_plan', false);
} // end if;
}
return (bool) $this->featured_plan;
} // end is_featured_plan;
}
/**
* Set the featured status for this product.
@ -114,8 +110,7 @@ trait WP_Ultimo_Plan_Deprecated {
public function set_featured_plan($featured_plan) {
$this->meta['featured_plan'] = $featured_plan;
} // end set_featured_plan;
}
/**
* Deprecated: Checks if a given plan is a contact us plan.
@ -129,8 +124,7 @@ trait WP_Ultimo_Plan_Deprecated {
_deprecated_function(__METHOD__, '2.0.0', 'get_pricing_type');
return $this->get_pricing_type() === 'contact_us';
} // end is_contact_us;
}
/**
* Get the pricing table lines to be displayed on the pricing tables
@ -147,20 +141,14 @@ trait WP_Ultimo_Plan_Deprecated {
* @since 1.7.0
*/
if ($this->should_display_quota_on_pricing_tables('setup_fee', true)) {
if ($this->get_pricing_type() === 'contact_us') {
$pricing_table_lines['wu_product_contact_us'] = __('Contact Us to know more', 'wp-ultimo');
} else {
$pricing_table_lines['wu_product_setup_fee'] = $this->has_setup_fee()
? sprintf(__('Setup Fee: %s', 'wp-ultimo'), "<strong class='pricing-table-setupfee' data-value='" . $this->get_setup_fee() . "'>" . wu_format_currency($this->get_setup_fee()) . '</strong>')
: __('No Setup Fee', 'wp-ultimo');
} // end if;
} // end if;
}
}
/**
*
@ -181,28 +169,25 @@ trait WP_Ultimo_Plan_Deprecated {
if ($this->is_post_type_disabled($pt_slug)) {
// Translators: used as "No Posts" where a post type is disabled
$pricing_table_lines['wu_product_limit_post_type_' . $pt_slug] = sprintf(__('No %s', 'wp-ultimo'), $post_type->labels->name);
$pricing_table_lines[ 'wu_product_limit_post_type_' . $pt_slug ] = sprintf(__('No %s', 'wp-ultimo'), $post_type->labels->name);
continue;
} // end if;
}
/**
* Get the values
*
*
* @var integer|string
*/
$is_unlimited = (int) $this->get_limitations()->post_types->{$pt_slug}->number === 0 || !$this->get_limitations()->post_types->is_enabled();
$is_unlimited = (int) $this->get_limitations()->post_types->{$pt_slug}->number === 0 || ! $this->get_limitations()->post_types->is_enabled();
$value = $is_unlimited ? __('Unlimited', 'wp-ultimo') : $this->get_limitations()->post_types->{$pt_slug}->number;
// Add Line
$label = $value == 1 ? $post_type->labels->singular_name : $post_type->labels->name;
$pricing_table_lines['wu_product_limit_post_type_' . $pt_slug] = sprintf('%s %s', $value, $label);
} // end if;
} // end foreach;
$pricing_table_lines[ 'wu_product_limit_post_type_' . $pt_slug ] = sprintf('%s %s', $value, $label);
}
}
/**
*
@ -210,27 +195,23 @@ trait WP_Ultimo_Plan_Deprecated {
* Gets the Disk Space and Sites to be displayed on the pricing table options
*/
if (wu_get_setting('enable_multiple_sites') && $this->should_display_quota_on_pricing_tables('sites')) {
$is_unlimited = (int) $this->get_limitations()->sites->get_limit() === 0 || !$this->get_limitations()->sites->is_enabled();
$is_unlimited = (int) $this->get_limitations()->sites->get_limit() === 0 || ! $this->get_limitations()->sites->is_enabled();
$value = $is_unlimited ? __('Unlimited', 'wp-ultimo') : $this->get_limitations()->sites->get_limit();
// Add Line
$pricing_table_lines['wu_product_limit_sites'] = sprintf('<strong>%s %s</strong>', $value, _n('Site', 'Sites', $this->get_limitations()->sites->get_limit(), 'wp-ultimo'));
} // end if;
}
/**
* Display DiskSpace
*/
if ($this->should_display_quota_on_pricing_tables('upload')) {
$is_unlimited = (int) $this->get_limitations()->disk_space->get_limit() === 0 || !$this->get_limitations()->disk_space->is_enabled();
$is_unlimited = (int) $this->get_limitations()->disk_space->get_limit() === 0 || ! $this->get_limitations()->disk_space->is_enabled();
$disk_space = $is_unlimited ? __('Unlimited', 'wp-ultimo') : size_format(absint($this->get_limitations()->disk_space->get_limit()) * 1024 * 1024);
// Add Line
$pricing_table_lines['wu_product_limit_disk_space'] = !empty($disk_space) ? sprintf(__('%s <strong>Disk Space</strong>', 'wp-ultimo'), $disk_space) : false;
} // end if;
$pricing_table_lines['wu_product_limit_disk_space'] = ! empty($disk_space) ? sprintf(__('%s <strong>Disk Space</strong>', 'wp-ultimo'), $disk_space) : false;
}
/**
* Visits
@ -238,14 +219,12 @@ trait WP_Ultimo_Plan_Deprecated {
* @since 1.6.0
*/
if ($this->should_display_quota_on_pricing_tables('visits')) {
$is_unlimited = (int) $this->get_limitations()->visits->get_limit() === 0 || !$this->get_limitations()->visits->is_enabled();
$is_unlimited = (int) $this->get_limitations()->visits->get_limit() === 0 || ! $this->get_limitations()->visits->is_enabled();
$value = $is_unlimited ? __('Unlimited', 'wp-ultimo') : number_format($this->get_limitations()->visits->get_limit());
// Add Line
$pricing_table_lines['wu_product_limit_visits'] = sprintf('%s %s', $value, _n('Visit per month', 'Visits per month', $this->get_limitations()->visits->get_limit(), 'wp-ultimo'));
} // end if;
}
/**
* Display Trial, if some
@ -254,12 +233,10 @@ trait WP_Ultimo_Plan_Deprecated {
$trial_days_plan = $this->get_trial_duration();
if ($trial_days > 0 || $trial_days_plan) {
$trial_days = $trial_days_plan ? $trial_days_plan : $trial_days;
$pricing_table_lines['wu_product_trial'] = !$this->is_free() ? sprintf(__('%s day <strong>Free Trial</strong>', 'wp-ultimo'), $trial_days) : '-';
} // end if;
$pricing_table_lines['wu_product_trial'] = ! $this->is_free() ? sprintf(__('%s day <strong>Free Trial</strong>', 'wp-ultimo'), $trial_days) : '-';
}
/**
*
@ -271,23 +248,18 @@ trait WP_Ultimo_Plan_Deprecated {
$custom_features = explode('<br />', nl2br($this->get_feature_list()));
foreach ($custom_features as $key => $custom_feature) {
if (trim($custom_feature) == '') {
continue;
}
} // end if;
$pricing_table_lines['wu_product_feature_' . $key] = sprintf('%s', trim($custom_feature));
} // end foreach;
$pricing_table_lines[ 'wu_product_feature_' . $key ] = sprintf('%s', trim($custom_feature));
}
/**
* Return Lines, filterable
*/
return apply_filters("wu_get_pricing_table_lines_$this->id", $pricing_table_lines, $this);
} // end get_pricing_table_lines;
}
/**
* Deprecated: A quota to get.
@ -301,26 +273,17 @@ trait WP_Ultimo_Plan_Deprecated {
public function get_quota($quota_name) {
if ($quota_name === 'visits') {
$limit = (float) $this->get_limitations()->visits->get_limit();
} elseif ($quota_name === 'disk_space') {
$limit = (float) $this->get_limitations()->disk_space->get_limit();
} elseif ($quota_name === 'sites') {
$limit = (float) $this->get_limitations()->sites->get_limit();
} else {
$limit = (float) $this->get_limitations()->post_types->{$quota_name}->number;
} // end if;
}
return $limit;
} // end get_quota;
}
/**
* Returns wether or not we should display a given quota type in the Quotas and Limits widgets
@ -336,21 +299,16 @@ trait WP_Ultimo_Plan_Deprecated {
*/
$elements = array();
if (!$elements) {
if ( ! $elements) {
return true;
}
} // end if;
if (!isset( $elements[$quota_type] ) && $default) {
if ( ! isset($elements[ $quota_type ]) && $default) {
return true;
}
} // end if;
return isset( $elements[$quota_type] ) && $elements[$quota_type];
} // end should_display_quota_on_pricing_tables;
return isset($elements[ $quota_type ]) && $elements[ $quota_type ];
}
/**
* Checks if this plan allows unlimited extra users
@ -361,8 +319,7 @@ trait WP_Ultimo_Plan_Deprecated {
public function should_allow_unlimited_extra_users() {
return apply_filters('wu_plan_should_allow_unlimited_extra_users', (bool) $this->unlimited_extra_users, $this);
} // end should_allow_unlimited_extra_users;
}
/**
* Returns wether or not we should display a given quota type in the Quotas and Limits widgets
@ -373,9 +330,8 @@ trait WP_Ultimo_Plan_Deprecated {
*/
public function is_post_type_disabled($post_type) {
return !$this->get_limitations()->post_types->{$post_type}->enabled;
} // end is_post_type_disabled;
return ! $this->get_limitations()->post_types->{$post_type}->enabled;
}
/**
* Returns the post_type quotas
@ -387,14 +343,20 @@ trait WP_Ultimo_Plan_Deprecated {
$quotas = $this->quotas;
return array_filter($quotas, fn($quota_name) => !in_array($quota_name, array(
'sites',
'attachment',
'upload',
'users',
'visits',
), true), ARRAY_FILTER_USE_KEY);
} // end get_post_type_quotas;
} // end trait WP_Ultimo_Plan_Deprecated;
return array_filter(
$quotas,
fn($quota_name) => ! in_array(
$quota_name,
array(
'sites',
'attachment',
'upload',
'users',
'visits',
),
true
),
ARRAY_FILTER_USE_KEY
);
}
}