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; ?>

View File

@ -9,63 +9,59 @@
* Deal with different pricing options
*/
foreach ($products as $index => &$_product) {
$_product = wu_get_product($_product['id']);
$_product = wu_get_product($_product['id']);
$product_variation = $_product->get_as_variation($duration, $duration_unit);
$product_variation = $_product->get_as_variation($duration, $duration_unit);
if ($product_variation === false && !$force_different_durations) {
unset($products[$index]);
$_product = $product_variation;
} // end if;
if ($product_variation === false && ! $force_different_durations) {
unset($products[ $index ]);
$_product = $product_variation;
} // end if;
} // end foreach;
?>
<div class="">
<div class="wu-grid wu-grid-flow-row wu-gap-4 <?php echo $classes; ?>">
<div class="wu-grid wu-grid-flow-row wu-gap-4 <?php echo $classes; ?>">
<?php foreach ($products as $product) : ?>
<?php foreach ($products as $product) : ?>
<label
id="wu-product-<?php echo $product->get_id(); ?>"
class="wu-relative wu-block wu-rounded-lg wu-border wu-border-gray-300 wu-bg-white wu-border-solid wu-shadow-sm wu-px-6 wu-py-4 wu-cursor-pointer hover:wu-border-gray-400 sm:wu-flex sm:wu-justify-between focus-within:wu-ring-1 focus-within:wu-ring-offset-2 focus-within:wu-ring-indigo-500">
<label
id="wu-product-<?php echo $product->get_id(); ?>"
class="wu-relative wu-block wu-rounded-lg wu-border wu-border-gray-300 wu-bg-white wu-border-solid wu-shadow-sm wu-px-6 wu-py-4 wu-cursor-pointer hover:wu-border-gray-400 sm:wu-flex sm:wu-justify-between focus-within:wu-ring-1 focus-within:wu-ring-offset-2 focus-within:wu-ring-indigo-500">
<input v-if="<?php echo json_encode($product->get_pricing_type() !== 'contact_us'); ?>" v-on:click="$parent.add_plan(<?php echo $product->get_id(); ?>)" type="checkbox" name="products[]" value="<?php echo $product->get_id(); ?>" class="screen-reader-text wu-hidden">
<input v-if="<?php echo json_encode($product->get_pricing_type() !== 'contact_us'); ?>" v-on:click="$parent.add_plan(<?php echo $product->get_id(); ?>)" type="checkbox" name="products[]" value="<?php echo $product->get_id(); ?>" class="screen-reader-text wu-hidden">
<input v-else v-on:click="$parent.open_url('<?php echo esc_url($product->get_contact_us_link()); ?>', '_blank');" type="checkbox" name="products[]" value="<?php echo $product->get_id(); ?>" class="screen-reader-text wu-hidden">
<input v-else v-on:click="$parent.open_url('<?php echo esc_url($product->get_contact_us_link()); ?>', '_blank');" type="checkbox" name="products[]" value="<?php echo $product->get_id(); ?>" class="screen-reader-text wu-hidden">
<div class="wu-flex wu-items-center">
<div class="wu-text-sm">
<span id="server-size-0-label" class="wu-font-semibold wu-block wu-text-gray-900">
<?php echo $product->get_name(); ?>
</span>
<div id="server-size-0-description-0" class="wu-text-gray-600">
<p class="sm:wu-inline">
<?php echo $product->get_description(); ?>
</p>
</div>
</div>
</div>
<div id="server-size-0-description-1" class="wu-mt-2 wu-flex wu-text-md sm:wu-mt-0 sm:wu-block sm:wu-ml-4 sm:wu-text-right">
<div class="wu-font-semibold wu-text-gray-900"><?php echo $product->get_formatted_amount(); ?></div>
<div class="wu-ml-1 wu-text-sm wu-text-gray-500 sm:wu-ml-0"><?php echo $product->get_recurring_description(); ?></div>
</div>
<div class="wu-flex wu-items-center">
<div class="wu-text-sm">
<span id="server-size-0-label" class="wu-font-semibold wu-block wu-text-gray-900">
<?php echo $product->get_name(); ?>
</span>
<div id="server-size-0-description-0" class="wu-text-gray-600">
<p class="sm:wu-inline">
<?php echo $product->get_description(); ?>
</p>
</div>
</div>
</div>
<div id="server-size-0-description-1" class="wu-mt-2 wu-flex wu-text-md sm:wu-mt-0 sm:wu-block sm:wu-ml-4 sm:wu-text-right">
<div class="wu-font-semibold wu-text-gray-900"><?php echo $product->get_formatted_amount(); ?></div>
<div class="wu-ml-1 wu-text-sm wu-text-gray-500 sm:wu-ml-0"><?php echo $product->get_recurring_description(); ?></div>
</div>
<div
class="wu-absolute wu--inset-px wu-rounded-lg wu-border-solid wu-border-2 wu-pointer-events-none wu-top-0 wu-bottom-0 wu-right-0 wu-left-0"
:class="$parent.has_product(<?php echo $product->get_id(); ?>) || $parent.has_product('<?php echo $product->get_slug(); ?>') ? 'wu-border-blue-500' : 'wu-border-transparent'"
aria-hidden="true"
>
</div>
</label>
<div
class="wu-absolute wu--inset-px wu-rounded-lg wu-border-solid wu-border-2 wu-pointer-events-none wu-top-0 wu-bottom-0 wu-right-0 wu-left-0"
:class="$parent.has_product(<?php echo $product->get_id(); ?>) || $parent.has_product('<?php echo $product->get_slug(); ?>') ? 'wu-border-blue-500' : 'wu-border-transparent'"
aria-hidden="true"
>
</div>
</label>
<?php endforeach; ?>
<?php endforeach; ?>
</div>
</div>
</div>