Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions class/subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ public function save_form_meta( $subscription_id, $post ) {
$cycle_period = ! empty( $post_data['cycle_period'] ) ? sanitize_text_field( wp_unslash( $post_data['cycle_period'] ) ) : '';
$billing_limit = ! empty( $post_data['billing_limit'] ) ? sanitize_text_field( wp_unslash( $post_data['billing_limit'] ) ) : '';
$trial_duration = ! empty( $post_data['trial_duration'] ) ? sanitize_text_field( wp_unslash( $post_data['trial_duration'] ) ) : '';
$trial_duration_type = ! empty( $post_data['trial_duration_type'] ) ? sanitize_text_field( wp_unslash( $post_data['trial_duration_type'] ) ) : '';
$trial_duration_type = ! empty( $post_data['_trial_duration_type'] ) ? sanitize_text_field( wp_unslash( $post_data['_trial_duration_type'] ) ) : '';

if ( isset( $post_data['post_expiration_settings'] ) ) {
if ( isset( $post_data['post_expiration_settings']['expiration_time_value'] ) && isset( $post_data['post_expiration_settings']['expiration_time_type'] ) ) {
Expand Down Expand Up @@ -955,7 +955,7 @@ public function pack_details( $pack, $details_meta, $current_pack_id = '', $coup
}

if ( $billing_amount && $pack->meta_value['recurring_pay'] === 'yes' ) {
$recurring_des = sprintf( __( 'Every', 'wp-user-frontend' ) . ' %s %s', $pack->meta_value['billing_cycle_number'], self::get_cycle_label( $pack->meta_value['cycle_period'], $pack->meta_value['billing_cycle_number'] ), $pack->meta_value['trial_duration_type'] );
$recurring_des = sprintf( __( 'Every', 'wp-user-frontend' ) . ' %s %s', $pack->meta_value['billing_cycle_number'], self::get_cycle_label( $pack->meta_value['cycle_period'], $pack->meta_value['billing_cycle_number'] ), $pack->meta_value['_trial_duration_type'] );
$recurring_des .= ! empty( $pack->meta_value['billing_limit'] ) ? sprintf( ', ' . __( 'for', 'wp-user-frontend' ) . ' %s ' . __( 'installments', 'wp-user-frontend' ), $pack->meta_value['billing_limit'] ) : '';
$recurring_des = '<div class="wpuf-pack-cycle wpuf-nullamount-hide">' . $recurring_des . '</div>';
}
Expand Down
8 changes: 4 additions & 4 deletions includes/Admin/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@ public function pack_details( $pack, $details_meta, $current_pack_id = '', $coup
}

if ( $billing_amount && wpuf_is_checkbox_or_toggle_on( $pack->meta_value['recurring_pay'] ) ) {
$recurring_des = sprintf( __( 'Every', 'wp-user-frontend' ) . ' %s %s', $pack->meta_value['billing_cycle_number'], self::get_cycle_label( $pack->meta_value['cycle_period'], $pack->meta_value['billing_cycle_number'] ), $pack->meta_value['trial_duration_type'] );
$recurring_des = sprintf( __( 'Every', 'wp-user-frontend' ) . ' %s %s', $pack->meta_value['billing_cycle_number'], self::get_cycle_label( $pack->meta_value['cycle_period'], $pack->meta_value['billing_cycle_number'] ), $pack->meta_value['_trial_duration_type'] );

if ( ! empty( $pack->meta_value['billing_limit'] ) && '-1' !== $pack->meta_value['billing_limit'] ) {
$recurring_des .= ! empty( $pack->meta_value['billing_limit'] ) ? sprintf( ', ' . __( 'for', 'wp-user-frontend' ) . ' %s ' . __( 'installments', 'wp-user-frontend' ), $pack->meta_value['billing_limit'] ) : '';
Expand All @@ -983,11 +983,11 @@ public function pack_details( $pack, $details_meta, $current_pack_id = '', $coup
$recurring_des = '<div class="wpuf-pack-cycle wpuf-nullamount-hide">' . $recurring_des . '</div>';
}

if ( $billing_amount && wpuf_is_checkbox_or_toggle_on( $pack->meta_value['recurring_pay'] ) && wpuf_is_checkbox_or_toggle_on( $pack->meta_value['trial_status'] ) ) {
if ( $billing_amount && wpuf_is_checkbox_or_toggle_on( $pack->meta_value['recurring_pay'] ) && wpuf_is_checkbox_or_toggle_on( $pack->meta_value['_trial_status'] ) ) {
//phpcs:ignore
$duration = _n( $pack->meta_value['trial_duration_type'], $pack->meta_value['trial_duration_type'] . 's', $pack->meta_value['trial_duration'], 'wp-user-frontend' );
$duration = _n( $pack->meta_value['_trial_duration_type'], $pack->meta_value['_trial_duration_type'] . 's', $pack->meta_value['_trial_duration'], 'wp-user-frontend' );
/* translators: %s: trial days */
$trial_des = sprintf( __( 'Trial available for first %1$s %2$s', 'wp-user-frontend' ), $pack->meta_value['trial_duration'], $duration );
$trial_des = sprintf( __( 'Trial available for first %1$s %2$s', 'wp-user-frontend' ), $pack->meta_value['_trial_duration'], $duration );
Comment on lines +989 to +993
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Standardized trial metadata handling

This change improves code consistency in two ways:

  1. Uses wpuf_is_checkbox_or_toggle_on() for both recurring payment and trial status checks
  2. Properly references underscored trial metadata keys (_trial_duration_type) which aligns with the metadata storage approach throughout the codebase

This standardization helps prevent potential bugs from inconsistent meta key references.

}

$label = wpuf_get_option( 'logged_in_label', 'wpuf_subscription_settings', false );
Expand Down
7 changes: 4 additions & 3 deletions includes/Frontend/Frontend_Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,16 @@ public function subscription_section( $sections, $current_section ) {
$recurring_des = '';
$billing_amount = ( intval( $pack->meta_value['billing_amount'] ) > 0 ) ? $details_meta['symbol'] . $pack->meta_value['billing_amount'] : __( 'Free',
'wp-user-frontend' );
if ( $pack->meta_value['recurring_pay'] === 'yes' ) {
if ( wpuf_is_checkbox_or_toggle_on( $pack->meta_value['recurring_pay'] ) ) {
error_log( print_r( $pack->meta_value, true ) );
/* translators: %s: billing cycle number, %s: billing cycle period */
$recurring_des = sprintf( __( 'For each', 'wp-user-frontend' ) . ' %s %s',
$pack->meta_value['billing_cycle_number'],
Subscription::get_cycle_label( $pack->meta_value['cycle_period'],
$pack->meta_value['billing_cycle_number'] ),
$pack->meta_value['trial_duration_type'] );
$pack->meta_value['_trial_duration_type'] );
/* translators: %s: number of installments */
$recurring_des .= ! empty( $pack->meta_value['billing_limit'] ) ? sprintf( __( ', for %s installments',
$recurring_des .= ! empty( $pack->meta_value['billing_limit'] ) && -1 === $pack->meta_value['billing_limit'] ? sprintf( __( ', for %s installments',
'wp-user-frontend' ),
$pack->meta_value['billing_limit'] ) : '';
}
Expand Down
4 changes: 2 additions & 2 deletions templates/dashboard/subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
<strong><?php esc_html_e( 'Package & billing details: ', 'wp-user-frontend' ); ?></strong>
<?php echo esc_html( $billing_amount . ' ' . $recurring_des ); ?>
</div>
<?php if ( is_wp_error( $user_sub ) ) { ?>

Check failure on line 10 in templates/dashboard/subscription.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Expected 1 space after opening PHP tag; 2 found
<div>
<strong><?php esc_html_e( 'Subscription Status: ', 'wp-user-frontend' ); ?></strong>
<?php esc_html_e( 'Subscription Expired!', 'wp-user-frontend' ); ?>
</div>
<?php } else {

Check failure on line 15 in templates/dashboard/subscription.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Opening PHP tag must be on a line by itself
if ( ! empty( $user_sub['total_feature_item'] ) ) { ?>
if ( ! empty( $user_sub['total_feature_item'] ) && -1 === $user_sub['total_feature_item'] ) { ?>

Check failure on line 16 in templates/dashboard/subscription.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Closing PHP tag must be on a line by itself

Check failure on line 16 in templates/dashboard/subscription.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Line indented incorrectly; expected 3 tabs, found 3 tabs and 1 spaces

Check warning on line 16 in templates/dashboard/subscription.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found precision alignment of 1 spaces.
<div><strong><?php esc_html_e( 'Number of featured item: ', 'wp-user-frontend' ); ?></strong><?php echo esc_html( $user_sub['total_feature_item'] ); ?></div>
<?php } ?>
<div>
Expand All @@ -24,7 +24,7 @@
foreach ( $user_sub['posts'] as $key => $value ) {
$value = intval( $value );

if ( $value === 0 ) {
if ( 0 === $value || -1 === $value ) {
continue;
}

Expand All @@ -33,19 +33,19 @@
if ( ! $post_type_obj ) {
continue;
}
$value = ( $value == '-1' ) ? __( 'Unlimited', 'wp-user-frontend' ) : $value; ?>

Check failure on line 36 in templates/dashboard/subscription.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Closing PHP tag must be on a line by itself

Check warning on line 36 in templates/dashboard/subscription.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Loose comparisons are not allowed. Expected: "==="; Found: "=="
<div><?php echo esc_html( $post_type_obj->labels->name ) . ': ' . esc_html( $value ); ?></div>
<?php
$i ++;

Check failure on line 39 in templates/dashboard/subscription.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Expected no spaces between $i and the increment operator; 1 found

Check warning on line 39 in templates/dashboard/subscription.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Stand-alone post-increment statement found. Use pre-increment instead: ++$i .
}
}
echo $i ? '' : esc_attr( $i );
?>
</div>
<?php
if ( $user_sub['recurring'] != 'yes' ) {

Check warning on line 46 in templates/dashboard/subscription.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Loose comparisons are not allowed. Expected: "!=="; Found: "!="
if ( !empty( $user_sub['expire'] ) ) {

Check failure on line 47 in templates/dashboard/subscription.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Expected 1 space after "!"; 0 found
$expiry_date = ( 'unlimited' === $user_sub['expire'] ) ? __( 'Unlimited', 'wp-user-frontend' ) : wpuf_get_date( wpuf_date2mysql( $user_sub['expire'] ) ); ?>

Check failure on line 48 in templates/dashboard/subscription.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Closing PHP tag must be on a line by itself

Check failure on line 48 in templates/dashboard/subscription.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Expected 1 space after "="; 2 found
<div class="wpuf-expire">
<strong><?php echo esc_html__( 'Expire date:', 'wp-user-frontend' ); ?></strong> <?php echo esc_html( $expiry_date ); ?>
</div>
Expand All @@ -53,13 +53,13 @@
}
}

if ( $user_sub['recurring'] == 'yes' ) {

Check warning on line 56 in templates/dashboard/subscription.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Loose comparisons are not allowed. Expected: "==="; Found: "=="
global $wpdb;

$user_id = get_current_user_id();
$payment_gateway = $wpdb->get_var( $wpdb->prepare( "SELECT payment_type FROM {$wpdb->prefix}wpuf_transaction WHERE user_id = %d AND status = 'completed' ORDER BY created DESC", $user_id ) );

$payment_gateway = strtolower( $payment_gateway ); ?>

Check failure on line 62 in templates/dashboard/subscription.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Closing PHP tag must be on a line by itself
<br>
<p><i><?php esc_html_e( 'To cancel the pack, press the following cancel button.', 'wp-user-frontend' ); ?></i></p>
<form action="" method="post" style="text-align: center;">
Expand Down
4 changes: 2 additions & 2 deletions templates/subscriptions/pack-details.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
*/
?>
<div class="wpuf-pricing-wrap">
<h3><?php echo wp_kses_post( $pack->post_title ); ?> </h3>
<h3><?php echo wp_kses_post( $pack->post_title ); ?></h3>
<div class="wpuf-sub-amount">

<?php if ( $billing_amount != '0.00' ) { ?>

Check warning on line 21 in templates/subscriptions/pack-details.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Loose comparisons are not allowed. Expected: "!=="; Found: "!="
<span class="wpuf-sub-cost"><?php echo esc_html( wpuf_format_price( $billing_amount ) ); ?></span>
<?php } else { ?>
<span class="wpuf-sub-cost"><?php esc_html_e( 'Free', 'wp-user-frontend' ); ?></span>
Expand All @@ -28,7 +28,7 @@

</div>
<?php
if ( $pack->meta_value['recurring_pay'] == 'yes' ) {
if ( wpuf_is_checkbox_or_toggle_on( $pack->meta_value['recurring_pay'] ) ) {
?>
<div class="wpuf-sub-body wpuf-nullamount-hide">
<div class="wpuf-sub-terms"><?php echo esc_html( $trial_des ); ?></div>
Expand All @@ -41,14 +41,14 @@
<?php echo wp_kses_post( wpautop( $pack->post_content ) ); ?>
</div>
<?php
$action = isset( $_GET['action'] ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : '';

Check warning on line 44 in templates/subscriptions/pack-details.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Processing form data without nonce verification.

Check warning on line 44 in templates/subscriptions/pack-details.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Processing form data without nonce verification.

if ( $action == 'wpuf_pay' || $coupon_status ) {

Check warning on line 46 in templates/subscriptions/pack-details.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Loose comparisons are not allowed. Expected: "==="; Found: "=="
return;
}
?>
<div class="wpuf-sub-button">
<a <?php echo ( esc_attr( $current_pack_status ) == 'completed' ) ? ' class = "wpuf-disabled-link" ' : ''; ?> href="<?php echo ( esc_attr( $current_pack_status ) == 'completed' ) ? 'javascript:' : esc_attr( add_query_arg( $query_args, esc_url( $query_url ) ) ); ?>" onclick="<?php echo esc_attr( $details_meta['onclick'] ); ?>">

Check warning on line 51 in templates/subscriptions/pack-details.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Loose comparisons are not allowed. Expected: "==="; Found: "=="
<?php echo esc_html( $button_name ); ?>
</a>
</div>
Loading