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

@ -15,31 +15,34 @@
$products_to_reduce = array_merge(array(false), $products);
$first_recurring_product = array_reduce($products_to_reduce, function($chosen_product, $product) {
$first_recurring_product = array_reduce(
$products_to_reduce,
function ($chosen_product, $product) {
if ($product && $product->is_recurring() && $chosen_product == false) {
if ($product && $product->is_recurring() && $chosen_product == false) {
$chosen_product = $product;
} // end if;
$chosen_product = $product;
return $chosen_product;
}
);
} // end if;
$legacy_mode = array_reduce(
$products_to_reduce,
function ($all_have_same_duration, $product) use ($first_recurring_product) {
return $chosen_product;
if ($product && $product->is_recurring()) {
$all_have_same_duration = $first_recurring_product->get_recurring_description() == $product->get_recurring_description();
} // end if;
});
return $all_have_same_duration;
}
);
$legacy_mode = array_reduce($products_to_reduce, function($all_have_same_duration, $product) use ($first_recurring_product) {
if ($product && $product->is_recurring()) {
$all_have_same_duration = $first_recurring_product->get_recurring_description() == $product->get_recurring_description();
} // end if;
return $all_have_same_duration;
});
wp_add_inline_script('wu-checkout', sprintf('
wp_add_inline_script(
'wu-checkout',
sprintf(
'
/**
* Force different durations.
@ -48,11 +51,18 @@ wp_add_inline_script('wu-checkout', sprintf('
window.wu_legacy_mode = %s;
', json_encode($force_different_durations), json_encode($legacy_mode)), 'after');
',
json_encode($force_different_durations),
json_encode($legacy_mode)
),
'after'
);
if ($first_recurring_product !== null) {
wp_add_inline_script('wu-checkout', sprintf("
wp_add_inline_script(
'wu-checkout',
sprintf(
"
/**
* Add durations if necessary.
@ -78,8 +88,12 @@ if ($first_recurring_product !== null) {
});
", json_encode($first_recurring_product->get_duration()), json_encode($first_recurring_product->get_duration_unit())), 'after');
",
json_encode($first_recurring_product->get_duration()),
json_encode($first_recurring_product->get_duration_unit())
),
'after'
);
}
?>
@ -93,281 +107,267 @@ if ($first_recurring_product !== null) {
<?php else : ?>
<div class="wu-content-plan">
<div class="wu-content-plan">
<div class="layer plans wu-overflow-hidden wu-flex">
<div class="layer plans wu-overflow-hidden wu-flex">
<?php foreach ($products as $product) : ?>
<?php foreach ($products as $product) : ?>
<div
id="plan-<?php echo esc_attr($product->get_id()); ?>"
class="<?php echo "wu-product-{$product->get_id()}"; ?> lift wu-plan plan-tier wu-flex-1 <?php echo esc_attr($product->is_featured_plan() ? 'callout' : ''); ?> wu-flex wu-flex-col wu-justify-between"
v-show="wu_force_different_durations || (duration && wu_legacy_mode) || (( (!duration) || duration == <?php echo $product->get_duration(); ?> && duration_unit == '<?php echo $product->get_duration_unit(); ?>' ) || <?php echo json_encode($product->get_pricing_type() !== 'paid'); ?>)"
>
<div
id="plan-<?php echo esc_attr($product->get_id()); ?>"
class="<?php echo "wu-product-{$product->get_id()}"; ?> lift wu-plan plan-tier wu-flex-1 <?php echo esc_attr($product->is_featured_plan() ? 'callout' : ''); ?> wu-flex wu-flex-col wu-justify-between"
v-show="wu_force_different_durations || (duration && wu_legacy_mode) || (( (!duration) || duration == <?php echo $product->get_duration(); ?> && duration_unit == '<?php echo $product->get_duration_unit(); ?>' ) || <?php echo json_encode($product->get_pricing_type() !== 'paid'); ?>)"
>
<div class="wu-relative">
<div class="wu-relative">
<?php if ($product->is_featured_plan()) : ?>
<?php if ($product->is_featured_plan()) : ?>
<h6>
<h6>
<?php
<?php
/**
* Featured tag.
*/
echo apply_filters('wu_featured_plan_label', __('Featured Plan', 'wp-ultimo'), $product);
/**
* Featured tag.
*/
echo apply_filters('wu_featured_plan_label', __('Featured Plan', 'wp-ultimo'), $product);
?>
?>
</h6>
</h6>
<?php endif; ?>
<?php endif; ?>
<h4 class="wp-ui-primary">
<h4 class="wp-ui-primary">
<?php echo $product->get_name(); ?>
<?php echo $product->get_name(); ?>
</h4>
</h4>
<?php
<?php
/**
* Case Free
*/
if ($product->get_pricing_type() === 'free') :
/**
* Case Free
*/
if ($product->get_pricing_type() === 'free') :
?>
?>
<!-- Price -->
<h5>
<!-- Price -->
<h5>
<span class="plan-price">
<span class="plan-price">
<?php _e('Free!', 'wp-ultimo'); ?>
<?php _e('Free!', 'wp-ultimo'); ?>
</span>
</span>
</h5>
</h5>
<?php
<?php
/**
* Case Free
*/
elseif ($product->get_pricing_type() === 'contact_us') :
/**
* Case Free
*/
elseif ($product->get_pricing_type() === 'contact_us') :
?>
?>
<!-- Price -->
<h5>
<!-- Price -->
<h5>
<span class="plan-price">
<span class="plan-price">
<?php echo apply_filters('wu_plan_contact_us_price_line', __('--', 'wp-ultimo')); ?>
<?php echo apply_filters('wu_plan_contact_us_price_line', __('--', 'wp-ultimo')); ?>
</span>
</span>
</h5>
</h5>
<?php else : ?>
<?php else : ?>
<!-- Price -->
<h5>
<!-- Price -->
<h5>
<?php
<?php
/**
* Price display.
*/
/**
* Price display.
*/
$symbol_left = in_array(wu_get_setting('currency_position', '%s%v'), array('%s%v', '%s %v'));
$symbol_left = in_array(wu_get_setting('currency_position', '%s%v'), array('%s%v', '%s %v'));
?>
?>
<?php if ($symbol_left) : ?>
<?php if ($symbol_left) : ?>
<sup class="superscript">
<sup class="superscript">
<?php echo wu_get_currency_symbol($product->get_currency()); ?>
<?php echo wu_get_currency_symbol($product->get_currency()); ?>
</sup>
</sup>
<?php endif; ?>
<?php endif; ?>
<span class="plan-price" v-if="wu_force_different_durations || (duration == <?php echo $product->get_duration(); ?> && duration_unit == '<?php echo $product->get_duration_unit(); ?>')">
<span class="plan-price" v-if="wu_force_different_durations || (duration == <?php echo $product->get_duration(); ?> && duration_unit == '<?php echo $product->get_duration_unit(); ?>')">
<?php
<?php
$n = $product->get_amount();
$n = $product->get_amount();
echo str_replace(wu_get_currency_symbol(), '', wu_format_currency($n));
echo str_replace(wu_get_currency_symbol(), '', wu_format_currency($n));
?>
?>
</span>
</span>
<?php foreach (array(3, 12) as $freq) :
<?php
foreach (array(3, 12) as $freq) :
$price_variation = $product->get_price_variation($freq, 'month');
$price_variation = $product->get_price_variation($freq, 'month');
if ( ! $price_variation) {
continue;
} // end if;
if (!$price_variation) {
?>
continue;
<span class="plan-price" v-cloak v-if="duration == <?php echo $price_variation['duration']; ?> && duration_unit == '<?php echo $price_variation['duration_unit']; ?>'">
} // end if;
<?php
?>
$n = $price_variation ? $price_variation['monthly_amount'] : false;
<span class="plan-price" v-cloak v-if="duration == <?php echo $price_variation['duration']; ?> && duration_unit == '<?php echo $price_variation['duration_unit']; ?>'">
if ($n) {
echo str_replace(wu_get_currency_symbol(), '', wu_format_currency($n));
} else {
echo '--';
} // end if;
<?php
?>
$n = $price_variation ? $price_variation['monthly_amount'] : false;
if ($n) {
echo str_replace(wu_get_currency_symbol(), '', wu_format_currency($n));
} else {
echo '--';
} // end if;
?>
</span>
<?php endforeach;?>
<sub v-if="1 == <?php echo $product->get_duration(); ?> && 'month' == '<?php echo $product->get_duration_unit(); ?>'">
<?php
/**
* Period Unit.
*/
$symbol = $product->is_recurring() ? __('/mo', 'wp-ultimo') : '';
echo (!$symbol_left ? wu_get_currency_symbol() : '').' '.$symbol;
?>
</sub>
<sub v-else>
<?php
/**
* Period Unit.
*/
$symbol = $product->is_recurring() ? $product->get_recurring_description() : '';
echo (!$symbol_left ? wu_get_currency_symbol() : '').' '.$symbol;
?>
</sub>
</h5>
<!-- end Price -->
<?php endif; ?>
<p class="early-adopter-price">
<?php echo $product->get_description(); ?>
</p>
</div>
<br>
<!-- Feature List Begins -->
<ul>
<?php
/**
*
* Display quarterly and Annually plans, to be hidden.
*/
$prices_total = array(
3 => __('every 3 months', 'wp-ultimo'),
12 => __('yearly', 'wp-ultimo'),
);
foreach ($prices_total as $freq => $string) {
$price_variation = $product->get_price_variation($freq, 'month');
if (!$price_variation || $product->get_pricing_type() == 'free' || $product->get_pricing_type() == 'contact_us') {
echo "<li v-cloak v-show='duration == ".$freq."' class='total-price total-price-$freq'>-</li>";
} else {
$text = sprintf(__('%1$s, billed %2$s', 'wp-ultimo'), wu_format_currency($price_variation['amount']), $string);
$extra_check_for_annual = '';
if ($freq === 12) {
$extra_check_for_annual = ' || (duration == "1" && duration_unit == "year")';
} // end if;
echo "<li v-cloak v-show='duration == ".$freq.$extra_check_for_annual."' class='total-price total-price-$freq'>$text</li>";
} // end if;
} // end foreach;
?>
<?php foreach ($product->get_pricing_table_lines() as $key => $line) : ?>
<li class="<?php echo str_replace('_', '-', $key); ?>"><?php echo $line; ?></li>
<?php endforeach; ?>
<li class="wu-cta">
<button
v-if="<?php echo json_encode($product->get_pricing_type() !== 'contact_us'); ?>"
v-on:click="add_plan(<?php echo $product->get_id(); ?>)"
type="button"
name="products[]"
value="<?php echo $product->get_id(); ?>"
class="button button-primary button-next"
>
<?php _e('Select Plan', 'wp-ultimo'); ?>
</button>
<button
v-else
v-on:click="open_url('<?php echo esc_url($product->get_contact_us_link()); ?>', '_blank');" type="button"
name="products[]"
value="<?php echo $product->get_id(); ?>"
class="button button-primary button-next"
>
<?php _e('Select Plan', 'wp-ultimo'); ?>
</button>
</li>
</ul>
<!-- Feature List Ends -->
</div>
</span>
<?php endforeach; ?>
</div>
</div>
<sub v-if="1 == <?php echo $product->get_duration(); ?> && 'month' == '<?php echo $product->get_duration_unit(); ?>'">
<?php
/**
* Period Unit.
*/
$symbol = $product->is_recurring() ? __('/mo', 'wp-ultimo') : '';
echo (! $symbol_left ? wu_get_currency_symbol() : '') . ' ' . $symbol;
?>
</sub>
<sub v-else>
<?php
/**
* Period Unit.
*/
$symbol = $product->is_recurring() ? $product->get_recurring_description() : '';
echo (! $symbol_left ? wu_get_currency_symbol() : '') . ' ' . $symbol;
?>
</sub>
</h5>
<!-- end Price -->
<?php endif; ?>
<p class="early-adopter-price">
<?php echo $product->get_description(); ?>
</p>
</div>
<br>
<!-- Feature List Begins -->
<ul>
<?php
/**
*
* Display quarterly and Annually plans, to be hidden.
*/
$prices_total = array(
3 => __('every 3 months', 'wp-ultimo'),
12 => __('yearly', 'wp-ultimo'),
);
foreach ($prices_total as $freq => $string) {
$price_variation = $product->get_price_variation($freq, 'month');
if ( ! $price_variation || $product->get_pricing_type() == 'free' || $product->get_pricing_type() == 'contact_us') {
echo "<li v-cloak v-show='duration == " . $freq . "' class='total-price total-price-$freq'>-</li>";
} else {
$text = sprintf(__('%1$s, billed %2$s', 'wp-ultimo'), wu_format_currency($price_variation['amount']), $string);
$extra_check_for_annual = '';
if ($freq === 12) {
$extra_check_for_annual = ' || (duration == "1" && duration_unit == "year")';
} // end if;
echo "<li v-cloak v-show='duration == " . $freq . $extra_check_for_annual . "' class='total-price total-price-$freq'>$text</li>";
} // end if;
} // end foreach;
?>
<?php foreach ($product->get_pricing_table_lines() as $key => $line) : ?>
<li class="<?php echo str_replace('_', '-', $key); ?>"><?php echo $line; ?></li>
<?php endforeach; ?>
<li class="wu-cta">
<button
v-if="<?php echo json_encode($product->get_pricing_type() !== 'contact_us'); ?>"
v-on:click="add_plan(<?php echo $product->get_id(); ?>)"
type="button"
name="products[]"
value="<?php echo $product->get_id(); ?>"
class="button button-primary button-next"
>
<?php _e('Select Plan', 'wp-ultimo'); ?>
</button>
<button
v-else
v-on:click="open_url('<?php echo esc_url($product->get_contact_us_link()); ?>', '_blank');" type="button"
name="products[]"
value="<?php echo $product->get_id(); ?>"
class="button button-primary button-next"
>
<?php _e('Select Plan', 'wp-ultimo'); ?>
</button>
</li>
</ul>
<!-- Feature List Ends -->
</div>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>