Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
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
2 changes: 1 addition & 1 deletion assets/css/admin/subscriptions.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/css/forms-list.min.css

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions assets/js/components/subscriptions/SectionInputField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ const showField = computed(() => {
});

const modifySubscription = (event) => {

switch (field.value.db_type) {
case 'meta_serialized':
subscriptionStore.modifyCurrentSubscription( field.value.db_key, event.target.value, field.value.serialize_key );
Expand All @@ -107,7 +108,6 @@ const modifySubscription = (event) => {

default:
subscriptionStore.setMetaValue( field.value.db_key, event.target.value );

}
};

Expand Down Expand Up @@ -268,7 +268,9 @@ onMounted(() => {
:placeholder="field.placeholder ? field.placeholder : ''"
@input="[modifySubscription($event), processInput($event)]"
@keydown="processNumber"
min="-1"
:min="field.min"
:step="field.step"
:default="field.default"
:class="subscriptionStore.errors[fieldId] ? '!wpuf-border-red-500' : '!wpuf-border-gray-300'"
class="placeholder:wpuf-text-gray-400 wpuf-w-full wpuf-rounded-md wpuf-bg-white wpuf-py-1 wpuf-pl-3 wpuf-pr-10 wpuf-text-left wpuf-shadow-sm focus:!wpuf-border-primaryHover focus:wpuf-outline-none focus:wpuf-ring-1 focus:wpuf-ring-primaryHover sm:wpuf-text-sm">
<textarea
Expand Down
2 changes: 1 addition & 1 deletion assets/js/subscriptions-old.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@
} else {
$('.wpuf_subscription_expiration_field').hide();
}
}
},

};

Expand Down
2 changes: 1 addition & 1 deletion assets/js/subscriptions.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/js/subscriptions.min.js.map

Large diffs are not rendered by default.

35 changes: 20 additions & 15 deletions class/subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct() {

add_action( 'register_form', [ $this, 'register_form' ] );
add_action( 'wpuf_add_post_form_top', [ $this, 'register_form' ] );
add_filter( 'wpuf_user_register_redirect', [ $this, 'subs_redirect_pram' ], 10, 5 );
add_filter( 'wpuf_user_register_redirect', [ $this, 'subs_redirect_pram' ], 10, 2 );

add_filter( 'template_redirect', [ $this, 'user_subscription_cancel' ] );

Expand All @@ -59,10 +59,12 @@ public static function subscriber_cancel( $user_id, $pack_id ) {
'SELECT transaction_id FROM ' . $wpdb->prefix . 'wpuf_transaction
WHERE user_id = %d AND pack_id = %d LIMIT 1', $user_id, $pack_id
);
$result = $wpdb->get_row( $wpdb->prepare(
'SELECT transaction_id FROM ' . $wpdb->prefix . 'wpuf_transaction
$result = $wpdb->get_row(
$wpdb->prepare(
'SELECT transaction_id FROM ' . $wpdb->prefix . 'wpuf_transaction
WHERE user_id = %d AND pack_id = %d LIMIT 1', $user_id, $pack_id
) );
)
);

$transaction_id = $result ? $result->transaction_id : 0;

Expand Down Expand Up @@ -129,7 +131,7 @@ public static function init() {
*
* @return array
*/
public function subs_redirect_pram( $response, $user_id, $userdata, $form_id, $form_settings ) {
public function subs_redirect_pram( $response, $user_id ) {
if ( ! isset( $_POST['_wpnonce'] ) || ! isset( $_POST['action'] ) || ! wp_verify_nonce( sanitize_key( $_POST['_wpnonce'] ), 'wpuf_form_add' ) ) {
return;
}
Expand Down Expand Up @@ -740,11 +742,13 @@ public static function post_by_orderid( $order_id ) {
WHERE p.ID = m.post_id AND p.post_status <> 'publish' AND m.meta_key = '_wpuf_order_id' AND m.meta_value = %s", $order_id
);

return $wpdb->get_row( $wpdb->prepare(
"SELECT p.ID, p.post_status
return $wpdb->get_row(
$wpdb->prepare(
"SELECT p.ID, p.post_status
FROM $wpdb->posts p, $wpdb->postmeta m
WHERE p.ID = m.post_id AND p.post_status <> 'publish' AND m.meta_key = '_wpuf_order_id' AND m.meta_value = %s", $order_id
) );
)
);
}

/**
Expand Down Expand Up @@ -860,11 +864,12 @@ public function subscription_packs( $atts = null ) {
$payment_gateway = $wpdb->get_var( $wpdb->prepare( "SELECT payment_type FROM {$wpdb->prefix}wpuf_transaction WHERE user_id = %s AND status = 'completed' ORDER BY created DESC", $user_id ) );

$payment_gateway = strtolower( $payment_gateway );
$payment_gateway = $payment_gateway ? strtolower( $payment_gateway ) : '';
?>

<?php echo wp_kses_post( __( '<p><i>You have a subscription pack activated. </i></p>', 'wp-user-frontend' ) ); ?>
<?php /* translators: %s: pack title */ ?>
<?php echo sprintf( wp_kses_post( __( '<p><i>Pack name: %s </i></p>', 'wp-user-frontend' ) ), esc_html( get_the_title( $current_pack['pack_id'] ) ) ); ?>
<?php printf( wp_kses_post( __( '<p><i>Pack name: %s </i></p>', 'wp-user-frontend' ) ), esc_html( get_the_title( $current_pack['pack_id'] ) ) ); ?>

<?php echo '<p><i>' . esc_html__( 'To cancel the pack, press the following cancel button', 'wp-user-frontend' ) . '</i></p>'; ?>

Expand Down Expand Up @@ -1076,7 +1081,7 @@ public function subscription_pack_users( $pack_id = '', $status = '' ) {
$sql .= $pack_id ? ' WHERE subscribtion_id = ' . $pack_id : '';
$sql .= $status ? ' AND subscribtion_status = ' . $status : '';

$rows = $wpdb->get_results( $wpdb->prepare( "SELECT user_id FROM {$wpdb->prefix}wpuf_subscribers WHERE subscribtion_id = %s AND subscribtion_status = %s", $pack_id ? $pack_id : '', $status ? $status : '') );
$rows = $wpdb->get_results( $wpdb->prepare( "SELECT user_id FROM {$wpdb->prefix}wpuf_subscribers WHERE subscribtion_id = %s AND subscribtion_status = %s", $pack_id ? $pack_id : '', $status ? $status : '' ) );

if ( empty( $rows ) ) {
return $rows;
Expand Down Expand Up @@ -1123,7 +1128,7 @@ public function force_pack_permission( $perm, $id, $form_settings ) {
if ( is_user_logged_in() ) {
if ( wpuf_get_user()->post_locked() ) {
return 'no';
} else {
} elseif ( ! wpuf_get_user()->post_locked() ) {

// if post locking not enabled
if ( ! $form->is_charging_enabled() ) {
Expand All @@ -1140,7 +1145,7 @@ public function force_pack_permission( $perm, $id, $form_settings ) {
} elseif ( $current_user->subscription()->has_post_count( $form_settings['post_type'] ) ) {
return 'yes';
}
} else {
} elseif ( $fallback_enabled ) {
//fallback cost disabled
if ( ! $current_user->subscription()->current_pack_id() ) {
return 'no';
Expand Down Expand Up @@ -1358,9 +1363,9 @@ public function cancel_non_recurring_subscription() {
$current_time = current_time( 'mysql' );
$non_recurrent = array_filter(
$all_subscription, function ( $pack ) use ( $current_time ) {
$pack = maybe_unserialize( $pack->meta_value );
return ! empty( $pack['recurring'] ) && $pack['recurring'] === 'no' && $current_time >= $pack['expire'];
}
$pack = maybe_unserialize( $pack->meta_value );
return ! empty( $pack['recurring'] ) && $pack['recurring'] === 'no' && $current_time >= $pack['expire'];
}
);

$remove_feature_item_by_author = [];
Expand Down
14 changes: 0 additions & 14 deletions includes/Admin/Admin_Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -1480,20 +1480,6 @@ public function get_fields() {
),
'default' => '-1',
],
'number_of_global_styles' => [
'id' => 'number-of-global-styles',
'name' => 'number-of-global-styles',
'db_key' => '_post_type_name',
'db_type' => 'meta_serialized',
'serialize_key' => 'wp_global_styles',
'type' => 'input-number',
'label' => __( 'Maximum Number of Global Styles', 'wp-user-frontend' ),
'tooltip' => __(
'Set maximum number of global styles that users can use within the subscription period. Enter -1 for unlimited',
'wp-user-frontend'
),
'default' => '-1',
],
'number_of_menus' => [
'id' => 'number-of-menus',
'name' => 'number-of-menus',
Expand Down
45 changes: 26 additions & 19 deletions includes/Admin/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct() {

add_action( 'register_form', [ $this, 'register_form' ] );
add_action( 'wpuf_add_post_form_top', [ $this, 'register_form' ] );
add_filter( 'wpuf_user_register_redirect', [ $this, 'subs_redirect_pram' ], 10, 5 );
add_filter( 'wpuf_user_register_redirect', [ $this, 'subs_redirect_pram' ], 10, 2 );

add_filter( 'template_redirect', [ $this, 'user_subscription_cancel' ] );

Expand All @@ -63,10 +63,12 @@ public static function subscriber_cancel( $user_id, $pack_id ) {
'SELECT transaction_id FROM ' . $wpdb->prefix . 'wpuf_transaction
WHERE user_id = %d AND pack_id = %d LIMIT 1', $user_id, $pack_id
);
$result = $wpdb->get_row( $wpdb->prepare(
'SELECT transaction_id FROM ' . $wpdb->prefix . 'wpuf_transaction
$result = $wpdb->get_row(
$wpdb->prepare(
'SELECT transaction_id FROM ' . $wpdb->prefix . 'wpuf_transaction
WHERE user_id = %d AND pack_id = %d LIMIT 1', $user_id, $pack_id
) );
)
);

$transaction_id = $result ? $result->transaction_id : 'Free';

Expand Down Expand Up @@ -127,7 +129,7 @@ public function user_subscription_cancel() {
*
* @return array
*/
public function subs_redirect_pram( $response, $user_id, $userdata, $form_id, $form_settings ) {
public function subs_redirect_pram( $response, $user_id ) {
if ( ! isset( $_POST['_wpnonce'] ) || ! isset( $_POST['action'] ) || ! wp_verify_nonce( sanitize_key( $_POST['_wpnonce'] ), 'wpuf_form_add' ) ) {
return;
}
Expand Down Expand Up @@ -172,6 +174,11 @@ public function subs_redirect_pram( $response, $user_id, $userdata, $form_id, $f
* @return void
*/
public function register_form() {
// Check if the nonce is valid
if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_GET['_wpnonce'] ) ), 'wpuf_register_form' ) ) {
return;
}

$type = isset( $_GET['type'] ) ? sanitize_text_field( wp_unslash( $_GET['type'] ) ) : '';
$pack_id = isset( $_GET['pack_id'] ) ? intval( wp_unslash( $_GET['pack_id'] ) ) : 0;

Expand Down Expand Up @@ -391,9 +398,9 @@ public function save_form_meta( $subscription_id, $post ) {

$post_data = wp_unslash( $_POST );

// if ( ! isset( $post_data['billing_amount'] ) ) {
// return;
// }
// if ( ! isset( $post_data['billing_amount'] ) ) {
// return;
// }

$expiration_time = '';
$enable_post_expir = '';
Expand Down Expand Up @@ -755,11 +762,13 @@ public static function post_by_orderid( $order_id ) {
WHERE p.ID = m.post_id AND p.post_status <> 'publish' AND m.meta_key = '_wpuf_order_id' AND m.meta_value = %s", $order_id
);

return $wpdb->get_row( $wpdb->prepare(
"SELECT p.ID, p.post_status
return $wpdb->get_row(
$wpdb->prepare(
"SELECT p.ID, p.post_status
FROM $wpdb->posts p, $wpdb->postmeta m
WHERE p.ID = m.post_id AND p.post_status <> 'publish' AND m.meta_key = '_wpuf_order_id' AND m.meta_value = %s", $order_id
) );
)
);
}

/**
Expand Down Expand Up @@ -874,18 +883,18 @@ public function subscription_packs( $atts = null ) {
! empty( $current_pack['pack_id'] ) &&
isset( $current_pack['status'] ) &&
$current_pack['status'] === 'completed'
) {
) {
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 = %s AND status = 'completed' ORDER BY created DESC", $user_id ) );

$payment_gateway = strtolower( $payment_gateway );
$payment_gateway = $payment_gateway ? strtolower( $payment_gateway ) : '';
?>

<?php echo wp_kses_post( __( '<p><i>You have a subscription pack activated. </i></p>', 'wp-user-frontend' ) ); ?>
<?php /* translators: %s: pack title */ ?>
<?php echo sprintf( wp_kses_post( __( '<p><i>Pack name: %s </i></p>', 'wp-user-frontend' ) ), esc_html( get_the_title( $current_pack['pack_id'] ) ) ); ?>
<?php printf( wp_kses_post( __( '<p><i>Pack name: %s </i></p>', 'wp-user-frontend' ) ), esc_html( get_the_title( $current_pack['pack_id'] ) ) ); ?>

<?php echo '<p><i>' . esc_html__( 'To cancel the pack, press the following cancel button', 'wp-user-frontend' ) . '</i></p>'; ?>

Expand Down Expand Up @@ -978,15 +987,14 @@ public function pack_details( $pack, $details_meta, $current_pack_id = '', $coup

$recurring_des = sprintf( __( 'Every', 'wp-user-frontend' ) . ' %s %s', $cycle_number, self::get_cycle_label( $pack->meta_value['cycle_period'], $pack->meta_value['billing_cycle_number'] ), $pack->meta_value['_trial_duration_type'] );


if ( wpuf_is_checkbox_or_toggle_on( $pack->meta_value['enable_billing_limit'] ) && ! 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'] ) : '';
}

$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' );
/* translators: %s: trial days */
Expand Down Expand Up @@ -1179,8 +1187,7 @@ public function force_pack_permission( $perm, $id, $form_settings ) {
if ( is_user_logged_in() ) {
if ( wpuf_get_user()->post_locked() ) {
return 'no';
} else {

} elseif ( ! wpuf_get_user()->post_locked() ) {
// if post locking not enabled
if ( ! $form->is_charging_enabled() ) {
return 'yes';
Expand All @@ -1196,7 +1203,7 @@ public function force_pack_permission( $perm, $id, $form_settings ) {
} elseif ( $current_user->subscription()->has_post_count( $form_settings['post_type'] ) ) {
return 'yes';
}
} else {
} elseif ( $fallback_enabled ) {
//fallback cost disabled
if ( ! $current_user->subscription()->current_pack_id() ) {
return 'no';
Expand Down
5 changes: 0 additions & 5 deletions includes/Frontend/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@
return $content;
}

$pay_page = intval( wpuf_get_option( 'payment_page', 'wpuf_payment' ) );

Check warning on line 76 in includes/Frontend/Payment.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Equals sign not aligned correctly; expected 1 space but found 7 spaces

$billing_amount = 0;
$action = isset( $_REQUEST['action'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ) : '';

Check warning on line 79 in includes/Frontend/Payment.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Processing form data without nonce verification.

Check warning on line 79 in includes/Frontend/Payment.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Processing form data without nonce verification.
$get_type = isset( $_REQUEST['type'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['type'] ) ) : '';
$type = ( $get_type === 'post' ) ? 'post' : 'pack';
if ( ! is_user_logged_in() && $action === 'wpuf_pay' && $type !== 'post' ) {
Expand Down Expand Up @@ -204,11 +204,6 @@
$billing_amount = apply_filters( 'wpuf_payment_amount',
$pack->meta_value['billing_amount'] );
?>

<div id="wpuf_type"
style="display: none"><?php echo 'pack'; ?></div>
<div id="wpuf_id"
style="display: none"><?php echo esc_attr( $pack_id ); ?></div>
<div><?php esc_html_e( 'Selected Pack',
'wp-user-frontend' ); ?>:
<strong><?php echo esc_attr( $pack->post_title ); ?></strong>
Expand Down
Loading
Loading