|
7 | 7 | <strong><?php esc_html_e( 'Package & billing details: ', 'wp-user-frontend' ); ?></strong> |
8 | 8 | <?php echo esc_html( $billing_amount . ' ' . $recurring_des ); ?> |
9 | 9 | </div> |
10 | | - <?php if ( is_wp_error( $user_sub ) ) { ?> |
| 10 | + <?php if ( is_wp_error( $user_sub ) ) { ?> |
11 | 11 | <div> |
12 | 12 | <strong><?php esc_html_e( 'Subscription Status: ', 'wp-user-frontend' ); ?></strong> |
13 | 13 | <?php esc_html_e( 'Subscription Expired!', 'wp-user-frontend' ); ?> |
14 | 14 | </div> |
15 | | - <?php } else { |
16 | | - if ( ! empty( $user_sub['total_feature_item'] ) && -1 === $user_sub['total_feature_item'] ) { ?> |
| 15 | + <?php |
| 16 | + } else { |
| 17 | + if ( ! empty( $user_sub['total_feature_item'] ) && -1 === $user_sub['total_feature_item'] ) { |
| 18 | + ?> |
17 | 19 | <div><strong><?php esc_html_e( 'Number of featured item: ', 'wp-user-frontend' ); ?></strong><?php echo esc_html( $user_sub['total_feature_item'] ); ?></div> |
18 | 20 | <?php } ?> |
19 | 21 | <div> |
|
31 | 33 | if ( ! $post_type_obj ) { |
32 | 34 | continue; |
33 | 35 | } |
34 | | - $post_count++; |
| 36 | + ++$post_count; |
35 | 37 | } |
36 | 38 | } |
37 | 39 | ?> |
|
49 | 51 | continue; |
50 | 52 | } |
51 | 53 | $value = ( $value == '-1' ) ? __( 'Unlimited', 'wp-user-frontend' ) : $value; |
52 | | - $hidden_class = ($i >= 3) ? 'wpuf-remaining-post-hidden' : ''; |
| 54 | + $hidden_class = ( $i >= 0 ) ? 'wpuf-remaining-post-hidden' : ''; |
53 | 55 | ?> |
54 | 56 | <div class="<?php echo esc_attr( $hidden_class ); ?>"><?php echo esc_html( $post_type_obj->labels->name ) . ': ' . esc_html( $value ); ?></div> |
55 | 57 | <?php |
56 | | - $i ++; |
| 58 | + ++$i; |
57 | 59 | } |
58 | 60 | } |
59 | 61 | echo $i ? '' : esc_attr( $i ); |
60 | 62 | ?> |
61 | 63 | </div> |
62 | | - <?php if ( $post_count > 3 ) : ?> |
| 64 | + <?php if ( $post_count > 0 ) : ?> |
63 | 65 | <button type="button" id="wpuf-remaining-posts-toggle" class="btn btn-link" style="padding:0;"><?php esc_html_e( 'Show More', 'wp-user-frontend' ); ?></button> |
64 | 66 | <script> |
65 | 67 | (function(){ |
|
80 | 82 | </div> |
81 | 83 | <?php |
82 | 84 | if ( $user_sub['recurring'] != 'yes' ) { |
83 | | - if ( !empty( $user_sub['expire'] ) ) { |
84 | | - $expiry_date = ( 'unlimited' === $user_sub['expire'] ) ? __( 'Unlimited', 'wp-user-frontend' ) : wpuf_get_date( wpuf_date2mysql( $user_sub['expire'] ) ); ?> |
| 85 | + if ( ! empty( $user_sub['expire'] ) ) { |
| 86 | + $expiry_date = ( 'unlimited' === $user_sub['expire'] ) ? __( 'Unlimited', 'wp-user-frontend' ) : wpuf_get_date( wpuf_date2mysql( $user_sub['expire'] ) ); |
| 87 | + ?> |
85 | 88 | <div class="wpuf-expire"> |
86 | 89 | <strong><?php echo esc_html__( 'Expire date:', 'wp-user-frontend' ); ?></strong> <?php echo esc_html( $expiry_date ); ?> |
87 | 90 | </div> |
|
105 | 108 | * @param array $user_sub User subscription data |
106 | 109 | * @return array Subscription data |
107 | 110 | */ |
108 | | - function get_subscription_data( $user_sub ) { |
109 | | - global $wpdb; |
110 | | - |
111 | | - $user_id = get_current_user_id(); |
112 | | - $pack_id = $user_sub['pack_id']; |
113 | | - $subscription = wpuf()->subscription->get_subscription( $pack_id ); |
114 | | - // Get payment gateway |
115 | | - $payment_gateway = $wpdb->get_var( $wpdb->prepare( |
| 111 | +function get_subscription_data( $user_sub ) { |
| 112 | + global $wpdb; |
| 113 | + |
| 114 | + $user_id = get_current_user_id(); |
| 115 | + $pack_id = $user_sub['pack_id']; |
| 116 | + $subscription = wpuf()->subscription->get_subscription( $pack_id ); |
| 117 | + // Get payment gateway |
| 118 | + $payment_gateway = $wpdb->get_var( |
| 119 | + $wpdb->prepare( |
116 | 120 | "SELECT payment_type |
117 | 121 | FROM {$wpdb->prefix}wpuf_transaction |
118 | 122 | WHERE user_id = %d |
119 | 123 | AND status = 'completed' |
120 | | - ORDER BY created DESC", |
121 | | - $user_id |
122 | | - ) ); |
123 | | - $payment_gateway = strtolower( $payment_gateway ); |
| 124 | + ORDER BY created DESC", |
| 125 | + $user_id |
| 126 | + ) |
| 127 | + ); |
| 128 | + $payment_gateway = strtolower( $payment_gateway ); |
124 | 129 |
|
125 | | - // Get last payment date |
126 | | - $last_payment_date = $wpdb->get_var( $wpdb->prepare( |
| 130 | + // Get last payment date |
| 131 | + $last_payment_date = $wpdb->get_var( |
| 132 | + $wpdb->prepare( |
127 | 133 | "SELECT created |
128 | 134 | FROM {$wpdb->prefix}wpuf_transaction |
129 | 135 | WHERE user_id = %d |
130 | 136 | AND status = 'completed' |
131 | 137 | ORDER BY created DESC |
132 | 138 | LIMIT 1", |
133 | 139 | $user_id |
134 | | - ) ); |
| 140 | + ) |
| 141 | + ); |
135 | 142 |
|
136 | | - // Get billing cycle details |
137 | | - $cycle_number = intval( $subscription->meta_value['billing_cycle_number'] ); |
138 | | - $cycle_period = $subscription->meta_value['cycle_period']; |
139 | | - |
140 | | - // Get trial details |
141 | | - $trial_status = $subscription->meta_value['trial_status']; |
142 | | - $trial_duration = $subscription->meta_value['trial_duration']; |
143 | | - $trial_duration_type = $subscription->meta_value['trial_duration_type']; |
| 143 | + // Get billing cycle details |
| 144 | + $cycle_number = intval( $subscription->meta_value['billing_cycle_number'] ); |
| 145 | + $cycle_period = $subscription->meta_value['cycle_period']; |
144 | 146 |
|
145 | | - return [ |
146 | | - 'payment_gateway' => $payment_gateway, |
147 | | - 'last_payment_date' => $last_payment_date, |
148 | | - 'cycle_number' => $cycle_number, |
149 | | - 'cycle_period' => $cycle_period, |
150 | | - 'trial_status' => $trial_status, |
151 | | - 'trial_duration' => $trial_duration, |
152 | | - 'trial_duration_type' => $trial_duration_type |
153 | | - ]; |
154 | | - } |
| 147 | + // Get trial details |
| 148 | + $trial_status = $subscription->meta_value['trial_status']; |
| 149 | + $trial_duration = $subscription->meta_value['trial_duration']; |
| 150 | + $trial_duration_type = $subscription->meta_value['trial_duration_type']; |
| 151 | + |
| 152 | + return [ |
| 153 | + 'payment_gateway' => $payment_gateway, |
| 154 | + 'last_payment_date' => $last_payment_date, |
| 155 | + 'cycle_number' => $cycle_number, |
| 156 | + 'cycle_period' => $cycle_period, |
| 157 | + 'trial_status' => $trial_status, |
| 158 | + 'trial_duration' => $trial_duration, |
| 159 | + 'trial_duration_type' => $trial_duration_type, |
| 160 | + ]; |
| 161 | +} |
155 | 162 |
|
156 | 163 | /** |
157 | 164 | * Display subscription details |
158 | 165 | * |
159 | 166 | * @param array $subscription_data Subscription data |
160 | 167 | * @return void |
161 | 168 | */ |
162 | | - function display_subscription_details( $subscription_data ) { |
163 | | - $trial_html = get_trial_expiration_html( $subscription_data ); |
164 | | - $billing_html = get_next_billing_html( $subscription_data ); |
165 | | - ?> |
| 169 | +function display_subscription_details( $subscription_data ) { |
| 170 | + $trial_html = get_trial_expiration_html( $subscription_data ); |
| 171 | + $billing_html = get_next_billing_html( $subscription_data ); |
| 172 | + ?> |
166 | 173 | <br> |
167 | | - <?php if ( $subscription_data['trial_status'] == 'on' ): ?> |
| 174 | + <?php if ( $subscription_data['trial_status'] == 'on' ) : ?> |
168 | 175 | <?php echo wp_kses_post( $trial_html ); ?> |
169 | | - <?php elseif ( $subscription_data['trial_status'] === 'off' ): ?> |
| 176 | + <?php elseif ( $subscription_data['trial_status'] === 'off' ) : ?> |
170 | 177 | <div class="wpuf-recurring-info"> |
171 | 178 | <?php echo wp_kses_post( $billing_html ); ?> |
172 | 179 | </div> |
173 | 180 | <?php endif; ?> |
174 | 181 |
|
175 | 182 | <p><i><?php esc_html_e( 'To cancel the pack, press the following cancel button.', 'wp-user-frontend' ); ?></i></p> |
176 | 183 | <form action="" method="post" style="text-align: center;"> |
177 | | - <?php wp_nonce_field( 'wpuf-sub-cancel' ); ?> |
| 184 | + <?php wp_nonce_field( 'wpuf-sub-cancel' ); ?> |
178 | 185 | <input type="hidden" name="gateway" value="<?php echo esc_attr( $subscription_data['payment_gateway'] ); ?>"> |
179 | 186 | <input type="submit" name="wpuf_cancel_subscription" class="btn btn-sm btn-danger" value="<?php esc_html_e( 'Cancel', 'wp-user-frontend' ); ?>"> |
180 | 187 | </form> |
181 | 188 | <?php |
182 | | - } |
| 189 | +} |
183 | 190 |
|
184 | 191 | /** |
185 | 192 | * Get trial expiration HTML |
186 | 193 | * |
187 | 194 | * @param array $subscription_data Subscription data |
188 | 195 | * @return string HTML for trial expiration |
189 | 196 | */ |
190 | | - function get_trial_expiration_html( $subscription_data ) { |
191 | | - if ( $subscription_data['trial_status'] !== 'on' ) { |
192 | | - return ''; |
193 | | - } |
| 197 | +function get_trial_expiration_html( $subscription_data ) { |
| 198 | + if ( $subscription_data['trial_status'] !== 'on' ) { |
| 199 | + return ''; |
| 200 | + } |
194 | 201 |
|
195 | | - $trial_expiration_date = date( |
196 | | - 'Y-m-d', |
197 | | - strtotime( |
198 | | - "+{$subscription_data['trial_duration']} {$subscription_data['trial_duration_type']}", |
199 | | - strtotime( $subscription_data['last_payment_date'] ) |
200 | | - ) |
201 | | - ); |
| 202 | + $trial_expiration_date = date( |
| 203 | + 'Y-m-d', |
| 204 | + strtotime( |
| 205 | + "+{$subscription_data['trial_duration']} {$subscription_data['trial_duration_type']}", |
| 206 | + strtotime( $subscription_data['last_payment_date'] ) |
| 207 | + ) |
| 208 | + ); |
202 | 209 |
|
203 | | - return sprintf( |
204 | | - '<div><strong>%s</strong> %s</div>', |
205 | | - esc_html__( 'Trial expiration date:', 'wp-user-frontend' ), |
206 | | - esc_html( $trial_expiration_date ) |
207 | | - ); |
208 | | - } |
| 210 | + return sprintf( |
| 211 | + '<div><strong>%s</strong> %s</div>', |
| 212 | + esc_html__( 'Trial expiration date:', 'wp-user-frontend' ), |
| 213 | + esc_html( $trial_expiration_date ) |
| 214 | + ); |
| 215 | +} |
209 | 216 |
|
210 | 217 | /** |
211 | 218 | * Get next billing HTML |
212 | 219 | * |
213 | 220 | * @param array $subscription_data Subscription data |
214 | 221 | * @return string HTML for next billing |
215 | 222 | */ |
216 | | - function get_next_billing_html( $subscription_data ) { |
217 | | - if ( ! $subscription_data['last_payment_date'] || |
218 | | - ! $subscription_data['cycle_number'] || |
219 | | - ! $subscription_data['cycle_period'] ) { |
220 | | - return sprintf( |
221 | | - '<div><strong>%s</strong> %s</div>', |
222 | | - esc_html__( 'Next billing date:', 'wp-user-frontend' ), |
223 | | - esc_html__( 'N/A', 'wp-user-frontend' ) |
224 | | - ); |
225 | | - } |
| 223 | +function get_next_billing_html( $subscription_data ) { |
| 224 | + if ( ! $subscription_data['last_payment_date'] || |
| 225 | + ! $subscription_data['cycle_number'] || |
| 226 | + ! $subscription_data['cycle_period'] ) { |
| 227 | + return sprintf( |
| 228 | + '<div><strong>%s</strong> %s</div>', |
| 229 | + esc_html__( 'Next billing date:', 'wp-user-frontend' ), |
| 230 | + esc_html__( 'N/A', 'wp-user-frontend' ) |
| 231 | + ); |
| 232 | + } |
226 | 233 |
|
227 | | - $next_billing_date = date( |
228 | | - 'Y-m-d', |
229 | | - strtotime( |
230 | | - "+{$subscription_data['cycle_number']} {$subscription_data['cycle_period']}", |
231 | | - strtotime( $subscription_data['last_payment_date'] ) |
232 | | - ) |
233 | | - ); |
234 | | - return sprintf( |
235 | | - '<div><strong>%s</strong> %s</div>', |
236 | | - esc_html__( 'Next billing date:', 'wp-user-frontend' ), |
237 | | - esc_html( $next_billing_date ) |
238 | | - ); |
239 | | - } |
| 234 | + $next_billing_date = date( |
| 235 | + 'Y-m-d', |
| 236 | + strtotime( |
| 237 | + "+{$subscription_data['cycle_number']} {$subscription_data['cycle_period']}", |
| 238 | + strtotime( $subscription_data['last_payment_date'] ) |
| 239 | + ) |
| 240 | + ); |
| 241 | + return sprintf( |
| 242 | + '<div><strong>%s</strong> %s</div>', |
| 243 | + esc_html__( 'Next billing date:', 'wp-user-frontend' ), |
| 244 | + esc_html( $next_billing_date ) |
| 245 | + ); |
| 246 | +} |
240 | 247 | ?> |
0 commit comments