@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | * |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 8 | +if (!defined('ABSPATH')) { |
|
| 9 | 9 | exit; // Exit if accessed directly |
| 10 | 10 | } |
| 11 | 11 | |
@@ -19,27 +19,27 @@ discard block |
||
| 19 | 19 | * |
| 20 | 20 | * @param WP_Post $post |
| 21 | 21 | */ |
| 22 | - public static function output( $post ) { |
|
| 22 | + public static function output($post) { |
|
| 23 | 23 | |
| 24 | 24 | //Fetch the invoice. |
| 25 | - $invoice = new WPInv_Invoice( $post ); |
|
| 25 | + $invoice = new WPInv_Invoice($post); |
|
| 26 | 26 | |
| 27 | 27 | // Ensure that it is recurring. |
| 28 | - if ( ! $invoice->is_recurring() ) { |
|
| 28 | + if (!$invoice->is_recurring()) { |
|
| 29 | 29 | return; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | // Fetch the subscription. |
| 33 | - $subscription = wpinv_get_subscription( $invoice ); |
|
| 33 | + $subscription = wpinv_get_subscription($invoice); |
|
| 34 | 34 | |
| 35 | 35 | ?> |
| 36 | - <?php if ( empty( $subscription ) ): ?> |
|
| 36 | + <?php if (empty($subscription)): ?> |
|
| 37 | 37 | <p class="wpi-meta-row"> |
| 38 | 38 | <?php |
| 39 | 39 | echo |
| 40 | 40 | wp_sprintf( |
| 41 | - __( 'A new subscription will be created when the customer checks out and pays the invoice. %sView all subscriptions%s', 'invoicing' ), |
|
| 42 | - '<a href="' . admin_url( 'admin.php?page=wpinv-subscriptions' ).'">', |
|
| 41 | + __('A new subscription will be created when the customer checks out and pays the invoice. %sView all subscriptions%s', 'invoicing'), |
|
| 42 | + '<a href="' . admin_url('admin.php?page=wpinv-subscriptions') . '">', |
|
| 43 | 43 | '</a>' |
| 44 | 44 | ); |
| 45 | 45 | ?> |
@@ -48,30 +48,30 @@ discard block |
||
| 48 | 48 | return; // If no subscription. |
| 49 | 49 | endif; |
| 50 | 50 | |
| 51 | - $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $subscription->period, $subscription->frequency ); |
|
| 52 | - $billing = wpinv_price(wpinv_format_amount( $subscription->recurring_amount ), wpinv_get_invoice_currency_code( $subscription->parent_payment_id ) ) . ' / ' . $frequency; |
|
| 53 | - $initial = wpinv_price(wpinv_format_amount( $subscription->initial_amount ), wpinv_get_invoice_currency_code( $subscription->parent_payment_id ) ); |
|
| 54 | - $exipired = strtotime( $subscription->expiration, current_time( 'timestamp' ) ) < current_time( 'timestamp' ); |
|
| 51 | + $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($subscription->period, $subscription->frequency); |
|
| 52 | + $billing = wpinv_price(wpinv_format_amount($subscription->recurring_amount), wpinv_get_invoice_currency_code($subscription->parent_payment_id)) . ' / ' . $frequency; |
|
| 53 | + $initial = wpinv_price(wpinv_format_amount($subscription->initial_amount), wpinv_get_invoice_currency_code($subscription->parent_payment_id)); |
|
| 54 | + $exipired = strtotime($subscription->expiration, current_time('timestamp')) < current_time('timestamp'); |
|
| 55 | 55 | ?> |
| 56 | 56 | |
| 57 | - <p class="wpi-meta-row wpi-sub-label <?php echo 'status-' . esc_attr( $subscription->status ); ?>"> |
|
| 57 | + <p class="wpi-meta-row wpi-sub-label <?php echo 'status-' . esc_attr($subscription->status); ?>"> |
|
| 58 | 58 | <?php echo $invoice->is_renewal() ? _e('Renewal Invoice', 'invoicing') : _e('Recurring Invoice', 'invoicing'); ?> |
| 59 | 59 | </p> |
| 60 | 60 | |
| 61 | - <?php if ( ! empty( $subscription->id ) ) : ?> |
|
| 61 | + <?php if (!empty($subscription->id)) : ?> |
|
| 62 | 62 | <p class="wpi-meta-row wpi-sub-id"> |
| 63 | - <label><?php _e( 'Subscription ID:', 'invoicing' ); ?></label> |
|
| 64 | - <a href="<?php echo esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $subscription->id ) ); ?>" title="<?php esc_attr_e( 'View or edit subscription', 'invoicing' ); ?>" target="_blank"><?php echo $subscription->id; ?></a> |
|
| 63 | + <label><?php _e('Subscription ID:', 'invoicing'); ?></label> |
|
| 64 | + <a href="<?php echo esc_url(admin_url('admin.php?page=wpinv-subscriptions&id=' . $subscription->id)); ?>" title="<?php esc_attr_e('View or edit subscription', 'invoicing'); ?>" target="_blank"><?php echo $subscription->id; ?></a> |
|
| 65 | 65 | </p> |
| 66 | 66 | <?php endif; ?> |
| 67 | 67 | |
| 68 | 68 | <p class="wpi-meta-row wpi-bill-cycle"> |
| 69 | - <label><?php _e( 'Billing Cycle:', 'invoicing'); ?> </label> |
|
| 69 | + <label><?php _e('Billing Cycle:', 'invoicing'); ?> </label> |
|
| 70 | 70 | <?php |
| 71 | 71 | |
| 72 | - if ( $subscription->recurring_amount != $subscription->initial_amount ) { |
|
| 72 | + if ($subscription->recurring_amount != $subscription->initial_amount) { |
|
| 73 | 73 | printf( |
| 74 | - _x( '%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing' ), |
|
| 74 | + _x('%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing'), |
|
| 75 | 75 | $initial, |
| 76 | 76 | $billing |
| 77 | 77 | ); |
@@ -83,38 +83,38 @@ discard block |
||
| 83 | 83 | </p> |
| 84 | 84 | |
| 85 | 85 | <p class="wpi-meta-row wpi-billed-times"> |
| 86 | - <label><?php _e( 'Times Billed:', 'invoicing' ); ?></label> |
|
| 87 | - <?php echo $subscription->get_times_billed() . ' / ' . ( ( $subscription->bill_times == 0 ) ? __( 'Until Cancelled', 'invoicing' ) : $subscription->bill_times ); ?> |
|
| 86 | + <label><?php _e('Times Billed:', 'invoicing'); ?></label> |
|
| 87 | + <?php echo $subscription->get_times_billed() . ' / ' . (($subscription->bill_times == 0) ? __('Until Cancelled', 'invoicing') : $subscription->bill_times); ?> |
|
| 88 | 88 | </p> |
| 89 | 89 | |
| 90 | 90 | <p class="wpi-meta-row wpi-start-date"> |
| 91 | - <label><?php _e( 'Start Date:', 'invoicing' ); ?></label> |
|
| 92 | - <?php echo date_i18n( get_option( 'date_format' ), strtotime( $subscription->created, current_time( 'timestamp' ) ) ); ?> |
|
| 91 | + <label><?php _e('Start Date:', 'invoicing'); ?></label> |
|
| 92 | + <?php echo date_i18n(get_option('date_format'), strtotime($subscription->created, current_time('timestamp'))); ?> |
|
| 93 | 93 | </p> |
| 94 | 94 | |
| 95 | 95 | <p class="wpi-meta-row wpi-end-date"> |
| 96 | - <label><?php echo $exipired ? __( 'Expired On:', 'invoicing' ) : __( 'Renews On:', 'invoicing' ); ?></label> |
|
| 97 | - <?php echo date_i18n( get_option( 'date_format' ), strtotime( $subscription->expiration, current_time( 'timestamp' ) ) ); ?> |
|
| 96 | + <label><?php echo $exipired ? __('Expired On:', 'invoicing') : __('Renews On:', 'invoicing'); ?></label> |
|
| 97 | + <?php echo date_i18n(get_option('date_format'), strtotime($subscription->expiration, current_time('timestamp'))); ?> |
|
| 98 | 98 | </p> |
| 99 | 99 | |
| 100 | - <?php if ( $subscription->status ) { ?> |
|
| 100 | + <?php if ($subscription->status) { ?> |
|
| 101 | 101 | <p class="wpi-meta-row wpi-sub-status"> |
| 102 | - <label><?php _e( 'Subscription Status:', 'invoicing'); ?> </label><?php echo $subscription->get_status_label(); ?> |
|
| 102 | + <label><?php _e('Subscription Status:', 'invoicing'); ?> </label><?php echo $subscription->get_status_label(); ?> |
|
| 103 | 103 | </p> |
| 104 | 104 | <?php } ?> |
| 105 | 105 | |
| 106 | - <?php if ( $invoice->is_renewal() ) { ?> |
|
| 106 | + <?php if ($invoice->is_renewal()) { ?> |
|
| 107 | 107 | <p class="wpi-meta-row wpi-invoice-parent"> |
| 108 | - <label><?php _e( 'Parent Invoice:', 'invoicing'); ?></label> |
|
| 108 | + <label><?php _e('Parent Invoice:', 'invoicing'); ?></label> |
|
| 109 | 109 | <?php |
| 110 | 110 | $parent = $invoice->get_parent_payment(); |
| 111 | 111 | |
| 112 | - if ( $parent->get_id() ) { |
|
| 113 | - $parent_url = esc_url( get_edit_post_link( $parent->get_id() ) ); |
|
| 112 | + if ($parent->get_id()) { |
|
| 113 | + $parent_url = esc_url(get_edit_post_link($parent->get_id())); |
|
| 114 | 114 | $parent_id = $parent->get_number(); |
| 115 | 115 | echo "<a href='$parent_url'>$parent_id</a>"; |
| 116 | 116 | } else { |
| 117 | - echo '<del>' . __( 'Deleted', 'invoicing' ) . '</del>'; |
|
| 117 | + echo '<del>' . __('Deleted', 'invoicing') . '</del>'; |
|
| 118 | 118 | } |
| 119 | 119 | ?> |
| 120 | 120 | |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | */ |
| 9 | 9 | function wpinv_subscriptions_page() { |
| 10 | 10 | |
| 11 | - if ( ! empty( $_GET['id'] ) ) { |
|
| 11 | + if (!empty($_GET['id'])) { |
|
| 12 | 12 | |
| 13 | 13 | wpinv_recurring_subscription_details(); |
| 14 | 14 | |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | <div class="wrap"> |
| 20 | 20 | |
| 21 | 21 | <h1> |
| 22 | - <?php _e( 'Subscriptions', 'invoicing' ); ?> |
|
| 22 | + <?php _e('Subscriptions', 'invoicing'); ?> |
|
| 23 | 23 | </h1> |
| 24 | 24 | <?php |
| 25 | 25 | $subscribers_table = new WPInv_Subscription_Reports_Table(); |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | <input type="hidden" name="post_type" value="download" /> |
| 32 | 32 | <input type="hidden" name="page" value="wpinv-subscriptions" /> |
| 33 | 33 | <?php $subscribers_table->views(); ?> |
| 34 | - <?php $subscribers_table->search_box( __( 'Search', 'wpinvoicing' ), 'subscriptions' ); ?> |
|
| 34 | + <?php $subscribers_table->search_box(__('Search', 'wpinvoicing'), 'subscriptions'); ?> |
|
| 35 | 35 | <?php $subscribers_table->display(); ?> |
| 36 | 36 | |
| 37 | 37 | </form> |
@@ -49,34 +49,34 @@ discard block |
||
| 49 | 49 | |
| 50 | 50 | $render = true; |
| 51 | 51 | |
| 52 | - if ( ! current_user_can( 'manage_invoicing' ) ) { |
|
| 53 | - die( __( 'You are not permitted to view this data.', 'invoicing' ) ); |
|
| 52 | + if (!current_user_can('manage_invoicing')) { |
|
| 53 | + die(__('You are not permitted to view this data.', 'invoicing')); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - if ( ! isset( $_GET['id'] ) || ! is_numeric( $_GET['id'] ) ) { |
|
| 57 | - die( __( 'Invalid subscription ID Provided.', 'invoicing' ) ); |
|
| 56 | + if (!isset($_GET['id']) || !is_numeric($_GET['id'])) { |
|
| 57 | + die(__('Invalid subscription ID Provided.', 'invoicing')); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | $sub_id = (int) $_GET['id']; |
| 61 | - $sub = new WPInv_Subscription( $sub_id ); |
|
| 61 | + $sub = new WPInv_Subscription($sub_id); |
|
| 62 | 62 | |
| 63 | - if ( empty( $sub ) ) { |
|
| 64 | - die( __( 'Invalid subscription ID Provided.', 'invoicing' ) ); |
|
| 63 | + if (empty($sub)) { |
|
| 64 | + die(__('Invalid subscription ID Provided.', 'invoicing')); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | ?> |
| 68 | 68 | <div class="wrap"> |
| 69 | - <h2><?php _e( 'Subscription Details', 'invoicing' ); ?></h2> |
|
| 69 | + <h2><?php _e('Subscription Details', 'invoicing'); ?></h2> |
|
| 70 | 70 | |
| 71 | - <?php if ( $sub ) : ?> |
|
| 71 | + <?php if ($sub) : ?> |
|
| 72 | 72 | |
| 73 | 73 | <div id="wpinv-item-card-wrapper"> |
| 74 | 74 | |
| 75 | - <?php do_action( 'wpinv_subscription_card_top', $sub ); ?> |
|
| 75 | + <?php do_action('wpinv_subscription_card_top', $sub); ?> |
|
| 76 | 76 | |
| 77 | 77 | <div class="info-wrapper item-section"> |
| 78 | 78 | |
| 79 | - <form id="edit-item-info" method="post" action="<?php echo admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $sub->id ); ?>"> |
|
| 79 | + <form id="edit-item-info" method="post" action="<?php echo admin_url('admin.php?page=wpinv-subscriptions&id=' . $sub->id); ?>"> |
|
| 80 | 80 | |
| 81 | 81 | <div class="item-info"> |
| 82 | 82 | |
@@ -84,124 +84,124 @@ discard block |
||
| 84 | 84 | <tbody> |
| 85 | 85 | <tr> |
| 86 | 86 | <td class="row-title"> |
| 87 | - <label for="tablecell"><?php _e( 'Billing Cycle:', 'invoicing' ); ?></label> |
|
| 87 | + <label for="tablecell"><?php _e('Billing Cycle:', 'invoicing'); ?></label> |
|
| 88 | 88 | </td> |
| 89 | 89 | <td> |
| 90 | 90 | <?php |
| 91 | - $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $sub->period, $sub->frequency ); |
|
| 92 | - $billing = wpinv_price( wpinv_format_amount( $sub->recurring_amount ), wpinv_get_invoice_currency_code( $sub->parent_payment_id ) ) . ' / ' . $frequency; |
|
| 93 | - $initial = wpinv_price( wpinv_format_amount( $sub->initial_amount ), wpinv_get_invoice_currency_code( $sub->parent_payment_id ) ); |
|
| 94 | - printf( _x( '%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing' ), $initial, $billing ); |
|
| 91 | + $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($sub->period, $sub->frequency); |
|
| 92 | + $billing = wpinv_price(wpinv_format_amount($sub->recurring_amount), wpinv_get_invoice_currency_code($sub->parent_payment_id)) . ' / ' . $frequency; |
|
| 93 | + $initial = wpinv_price(wpinv_format_amount($sub->initial_amount), wpinv_get_invoice_currency_code($sub->parent_payment_id)); |
|
| 94 | + printf(_x('%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing'), $initial, $billing); |
|
| 95 | 95 | ?> |
| 96 | 96 | </td> |
| 97 | 97 | </tr> |
| 98 | 98 | <tr> |
| 99 | 99 | <td class="row-title"> |
| 100 | - <label for="tablecell"><?php _e( 'Times Billed:', 'invoicing' ); ?></label> |
|
| 100 | + <label for="tablecell"><?php _e('Times Billed:', 'invoicing'); ?></label> |
|
| 101 | 101 | </td> |
| 102 | - <td><?php echo $sub->get_times_billed() . ' / ' . ( ( $sub->bill_times == 0 ) ? __( 'Until Cancelled', 'invoicing' ) : $sub->bill_times ); ?></td> |
|
| 102 | + <td><?php echo $sub->get_times_billed() . ' / ' . (($sub->bill_times == 0) ? __('Until Cancelled', 'invoicing') : $sub->bill_times); ?></td> |
|
| 103 | 103 | </tr> |
| 104 | 104 | <tr> |
| 105 | 105 | <td class="row-title"> |
| 106 | - <label for="tablecell"><?php _e( 'Customer:', 'invoicing' ); ?></label> |
|
| 106 | + <label for="tablecell"><?php _e('Customer:', 'invoicing'); ?></label> |
|
| 107 | 107 | </td> |
| 108 | 108 | <td> |
| 109 | - <?php $subscriber = get_userdata( $sub->customer_id ); ?> |
|
| 110 | - <a href="<?php echo esc_url( get_edit_user_link( $sub->customer_id ) ); ?>" target="_blank"><?php echo ! empty( $subscriber->display_name ) ? $subscriber->display_name : $subscriber->user_email; ?></a> |
|
| 109 | + <?php $subscriber = get_userdata($sub->customer_id); ?> |
|
| 110 | + <a href="<?php echo esc_url(get_edit_user_link($sub->customer_id)); ?>" target="_blank"><?php echo !empty($subscriber->display_name) ? $subscriber->display_name : $subscriber->user_email; ?></a> |
|
| 111 | 111 | </td> |
| 112 | 112 | </tr> |
| 113 | 113 | <tr> |
| 114 | 114 | <td class="row-title"> |
| 115 | - <label for="tablecell"><?php _e( 'Initial Invoice:', 'invoicing' ); ?></label> |
|
| 115 | + <label for="tablecell"><?php _e('Initial Invoice:', 'invoicing'); ?></label> |
|
| 116 | 116 | </td> |
| 117 | 117 | <td> |
| 118 | - <a target="_blank" title="<?php _e( 'View invoice', 'invoicing' ); ?>" href="<?php echo esc_url( get_permalink( $sub->parent_payment_id ) ); ?>"><?php echo wpinv_get_invoice_number( $sub->parent_payment_id ); ?></a> <?php echo wp_sprintf( __( '( ID: %s )', 'invoicing' ), '<a title="' . esc_attr( __( 'View invoice details', 'invoicing' ) ) . '" href="' . get_edit_post_link( $sub->parent_payment_id ) . '" target="_blank">' . $sub->parent_payment_id . '</a>' ); ?></td> |
|
| 118 | + <a target="_blank" title="<?php _e('View invoice', 'invoicing'); ?>" href="<?php echo esc_url(get_permalink($sub->parent_payment_id)); ?>"><?php echo wpinv_get_invoice_number($sub->parent_payment_id); ?></a> <?php echo wp_sprintf(__('( ID: %s )', 'invoicing'), '<a title="' . esc_attr(__('View invoice details', 'invoicing')) . '" href="' . get_edit_post_link($sub->parent_payment_id) . '" target="_blank">' . $sub->parent_payment_id . '</a>'); ?></td> |
|
| 119 | 119 | </tr> |
| 120 | 120 | <tr> |
| 121 | 121 | <td class="row-title"> |
| 122 | - <label for="tablecell"><?php _e( 'Item:', 'invoicing' ); ?></label> |
|
| 122 | + <label for="tablecell"><?php _e('Item:', 'invoicing'); ?></label> |
|
| 123 | 123 | </td> |
| 124 | 124 | <td> |
| 125 | 125 | <?php |
| 126 | - echo wpinv_item_dropdown( array( |
|
| 126 | + echo wpinv_item_dropdown(array( |
|
| 127 | 127 | 'name' => 'product_id', |
| 128 | 128 | 'id' => 'wpinv_invoice_item', |
| 129 | 129 | 'with_packages' => false, |
| 130 | 130 | 'show_recurring' => true, |
| 131 | 131 | 'selected' => $sub->product_id, |
| 132 | 132 | 'class' => 'wpinv-sub-product-id wpi_select2', |
| 133 | - ) ); |
|
| 133 | + )); |
|
| 134 | 134 | |
| 135 | 135 | ?> |
| 136 | - <a href="<?php echo esc_url( add_query_arg( array( |
|
| 136 | + <a href="<?php echo esc_url(add_query_arg(array( |
|
| 137 | 137 | 'post' => $sub->product_id, |
| 138 | 138 | 'action' => 'edit' |
| 139 | - ), admin_url( 'post.php' ) ) ); ?>" target="_blank"><?php _e( 'View Item', 'invoicing' ) ; ?></a> |
|
| 139 | + ), admin_url('post.php'))); ?>" target="_blank"><?php _e('View Item', 'invoicing'); ?></a> |
|
| 140 | 140 | </td> |
| 141 | 141 | </tr> |
| 142 | 142 | <tr> |
| 143 | 143 | <td class="row-title"> |
| 144 | - <label for="tablecell"><?php _e( 'Payment Method:', 'invoicing' ); ?></label> |
|
| 144 | + <label for="tablecell"><?php _e('Payment Method:', 'invoicing'); ?></label> |
|
| 145 | 145 | </td> |
| 146 | - <td><?php echo wpinv_get_gateway_admin_label( wpinv_get_payment_gateway( $sub->parent_payment_id ) ); ?></td> |
|
| 146 | + <td><?php echo wpinv_get_gateway_admin_label(wpinv_get_payment_gateway($sub->parent_payment_id)); ?></td> |
|
| 147 | 147 | </tr> |
| 148 | 148 | <tr> |
| 149 | 149 | <td class="row-title"> |
| 150 | - <label for="tablecell"><?php _e( 'Profile ID:', 'invoicing' ); ?></label> |
|
| 150 | + <label for="tablecell"><?php _e('Profile ID:', 'invoicing'); ?></label> |
|
| 151 | 151 | </td> |
| 152 | 152 | <td> |
| 153 | 153 | <span class="wpinv-sub-profile-id"> |
| 154 | - <?php echo apply_filters( 'wpinv_subscription_profile_link_' . $sub->gateway, $sub->profile_id, $sub ); ?> |
|
| 154 | + <?php echo apply_filters('wpinv_subscription_profile_link_' . $sub->gateway, $sub->profile_id, $sub); ?> |
|
| 155 | 155 | </span> |
| 156 | - <input type="text" name="profile_id" class="hidden wpinv-sub-profile-id" value="<?php echo esc_attr( $sub->profile_id ); ?>" /> |
|
| 156 | + <input type="text" name="profile_id" class="hidden wpinv-sub-profile-id" value="<?php echo esc_attr($sub->profile_id); ?>" /> |
|
| 157 | 157 | <span> – </span> |
| 158 | - <a href="#" class="wpinv-edit-sub-profile-id"><?php _e( 'Edit', 'invoicing' ); ?></a> |
|
| 158 | + <a href="#" class="wpinv-edit-sub-profile-id"><?php _e('Edit', 'invoicing'); ?></a> |
|
| 159 | 159 | </td> |
| 160 | 160 | </tr> |
| 161 | 161 | <tr> |
| 162 | 162 | <td class="row-title"> |
| 163 | - <label for="tablecell"><?php _e( 'Transaction ID:', 'invoicing' ); ?></label> |
|
| 163 | + <label for="tablecell"><?php _e('Transaction ID:', 'invoicing'); ?></label> |
|
| 164 | 164 | </td> |
| 165 | 165 | <td> |
| 166 | - <span class="wpinv-sub-transaction-id"><?php echo apply_filters( 'wpinv_subscription_transaction_link_' . $sub->gateway, $sub->get_transaction_id(), $sub ); ?></span> |
|
| 167 | - <input type="text" name="transaction_id" class="hidden wpinv-sub-transaction-id" value="<?php echo esc_attr( $sub->get_transaction_id() ); ?>" /> |
|
| 166 | + <span class="wpinv-sub-transaction-id"><?php echo apply_filters('wpinv_subscription_transaction_link_' . $sub->gateway, $sub->get_transaction_id(), $sub); ?></span> |
|
| 167 | + <input type="text" name="transaction_id" class="hidden wpinv-sub-transaction-id" value="<?php echo esc_attr($sub->get_transaction_id()); ?>" /> |
|
| 168 | 168 | <span> – </span> |
| 169 | - <a href="#" class="wpinv-edit-sub-transaction-id"><?php _e( 'Edit', 'invoicing' ); ?></a> |
|
| 169 | + <a href="#" class="wpinv-edit-sub-transaction-id"><?php _e('Edit', 'invoicing'); ?></a> |
|
| 170 | 170 | </td> |
| 171 | 171 | </tr> |
| 172 | 172 | <tr> |
| 173 | 173 | <td class="row-title"> |
| 174 | - <label for="tablecell"><?php _e( 'Date Created:', 'invoicing' ); ?></label> |
|
| 174 | + <label for="tablecell"><?php _e('Date Created:', 'invoicing'); ?></label> |
|
| 175 | 175 | </td> |
| 176 | - <td><?php echo date_i18n( get_option( 'date_format' ), strtotime( $sub->created, current_time( 'timestamp' ) ) ); ?></td> |
|
| 176 | + <td><?php echo date_i18n(get_option('date_format'), strtotime($sub->created, current_time('timestamp'))); ?></td> |
|
| 177 | 177 | </tr> |
| 178 | 178 | <tr> |
| 179 | 179 | <td class="row-title"> |
| 180 | 180 | <label for="tablecell"> |
| 181 | - <?php if( 'trialling' == $sub->status ) : ?> |
|
| 182 | - <?php _e( 'Trialling Until:', 'invoicing' ); ?> |
|
| 181 | + <?php if ('trialling' == $sub->status) : ?> |
|
| 182 | + <?php _e('Trialling Until:', 'invoicing'); ?> |
|
| 183 | 183 | <?php else: ?> |
| 184 | - <?php _e( 'Expiration Date:', 'invoicing' ); ?> |
|
| 184 | + <?php _e('Expiration Date:', 'invoicing'); ?> |
|
| 185 | 185 | <?php endif; ?> |
| 186 | 186 | </label> |
| 187 | 187 | </td> |
| 188 | 188 | <td> |
| 189 | - <span class="wpinv-sub-expiration"><?php echo date_i18n( get_option( 'date_format' ), strtotime( $sub->expiration, current_time( 'timestamp' ) ) ); ?></span> |
|
| 189 | + <span class="wpinv-sub-expiration"><?php echo date_i18n(get_option('date_format'), strtotime($sub->expiration, current_time('timestamp'))); ?></span> |
|
| 190 | 190 | </td> |
| 191 | 191 | </tr> |
| 192 | 192 | <tr> |
| 193 | 193 | <td class="row-title"> |
| 194 | - <label for="tablecell"><?php _e( 'Subscription Status:', 'invoicing' ); ?></label> |
|
| 194 | + <label for="tablecell"><?php _e('Subscription Status:', 'invoicing'); ?></label> |
|
| 195 | 195 | </td> |
| 196 | 196 | <td> |
| 197 | 197 | <select name="status" class="wpi_select2"> |
| 198 | - <option value="pending"<?php selected( 'pending', $sub->status ); ?>><?php _e( 'Pending', 'invoicing' ); ?></option> |
|
| 199 | - <option value="active"<?php selected( 'active', $sub->status ); ?>><?php _e( 'Active', 'invoicing' ); ?></option> |
|
| 200 | - <option value="cancelled"<?php selected( 'cancelled', $sub->status ); ?>><?php _e( 'Cancelled', 'invoicing' ); ?></option> |
|
| 201 | - <option value="expired"<?php selected( 'expired', $sub->status ); ?>><?php _e( 'Expired', 'invoicing' ); ?></option> |
|
| 202 | - <option value="trialling"<?php selected( 'trialling', $sub->status ); ?>><?php _e( 'Trialling', 'invoicing' ); ?></option> |
|
| 203 | - <option value="failing"<?php selected( 'failing', $sub->status ); ?>><?php _e( 'Failing', 'invoicing' ); ?></option> |
|
| 204 | - <option value="completed"<?php selected( 'completed', $sub->status ); ?>><?php _e( 'Completed', 'invoicing' ); ?></option> |
|
| 198 | + <option value="pending"<?php selected('pending', $sub->status); ?>><?php _e('Pending', 'invoicing'); ?></option> |
|
| 199 | + <option value="active"<?php selected('active', $sub->status); ?>><?php _e('Active', 'invoicing'); ?></option> |
|
| 200 | + <option value="cancelled"<?php selected('cancelled', $sub->status); ?>><?php _e('Cancelled', 'invoicing'); ?></option> |
|
| 201 | + <option value="expired"<?php selected('expired', $sub->status); ?>><?php _e('Expired', 'invoicing'); ?></option> |
|
| 202 | + <option value="trialling"<?php selected('trialling', $sub->status); ?>><?php _e('Trialling', 'invoicing'); ?></option> |
|
| 203 | + <option value="failing"<?php selected('failing', $sub->status); ?>><?php _e('Failing', 'invoicing'); ?></option> |
|
| 204 | + <option value="completed"<?php selected('completed', $sub->status); ?>><?php _e('Completed', 'invoicing'); ?></option> |
|
| 205 | 205 | </select> |
| 206 | 206 | </td> |
| 207 | 207 | </tr> |
@@ -209,79 +209,79 @@ discard block |
||
| 209 | 209 | </table> |
| 210 | 210 | </div> |
| 211 | 211 | <div id="wpinv-sub-notices"> |
| 212 | - <div class="notice notice-info inline hidden" id="wpinv-sub-product-update-notice"><p><?php _e( 'Changing the product assigned will not automatically adjust any pricing.', 'invoicing' ); ?></p></div> |
|
| 213 | - <div class="notice notice-warning inline hidden" id="wpinv-sub-profile-id-update-notice"><p><?php _e( 'Changing the profile ID can result in renewals not being processed. Do this with caution.', 'invoicing' ); ?></p></div> |
|
| 212 | + <div class="notice notice-info inline hidden" id="wpinv-sub-product-update-notice"><p><?php _e('Changing the product assigned will not automatically adjust any pricing.', 'invoicing'); ?></p></div> |
|
| 213 | + <div class="notice notice-warning inline hidden" id="wpinv-sub-profile-id-update-notice"><p><?php _e('Changing the profile ID can result in renewals not being processed. Do this with caution.', 'invoicing'); ?></p></div> |
|
| 214 | 214 | </div> |
| 215 | 215 | <div id="item-edit-actions" class="edit-item" style="float:right; margin: 10px 0 0; display: block;"> |
| 216 | - <?php wp_nonce_field( 'wpinv-recurring-update', 'wpinv-recurring-update-nonce', false, true ); ?> |
|
| 217 | - <input type="submit" name="wpinv_update_subscription" id="wpinv_update_subscription" class="button button-primary" value="<?php _e( 'Update Subscription', 'invoicing' ); ?>"/> |
|
| 218 | - <input type="hidden" name="sub_id" value="<?php echo absint( $sub->id ); ?>" /> |
|
| 219 | - <?php if( $sub->can_cancel() ) : ?> |
|
| 220 | - <a class="button button-primary" href="<?php echo $sub->get_cancel_url(); ?>" ><?php _e( 'Cancel Subscription', 'invoicing' ); ?></a> |
|
| 216 | + <?php wp_nonce_field('wpinv-recurring-update', 'wpinv-recurring-update-nonce', false, true); ?> |
|
| 217 | + <input type="submit" name="wpinv_update_subscription" id="wpinv_update_subscription" class="button button-primary" value="<?php _e('Update Subscription', 'invoicing'); ?>"/> |
|
| 218 | + <input type="hidden" name="sub_id" value="<?php echo absint($sub->id); ?>" /> |
|
| 219 | + <?php if ($sub->can_cancel()) : ?> |
|
| 220 | + <a class="button button-primary" href="<?php echo $sub->get_cancel_url(); ?>" ><?php _e('Cancel Subscription', 'invoicing'); ?></a> |
|
| 221 | 221 | <?php endif; ?> |
| 222 | - <input type="submit" name="wpinv_delete_subscription" class="wpinv-delete-subscription button" value="<?php _e( 'Delete Subscription', 'invoicing' ); ?>"/> |
|
| 222 | + <input type="submit" name="wpinv_delete_subscription" class="wpinv-delete-subscription button" value="<?php _e('Delete Subscription', 'invoicing'); ?>"/> |
|
| 223 | 223 | </div> |
| 224 | 224 | |
| 225 | 225 | </form> |
| 226 | 226 | </div> |
| 227 | 227 | |
| 228 | - <?php do_action( 'wpinv_subscription_before_stats', $sub ); ?> |
|
| 228 | + <?php do_action('wpinv_subscription_before_stats', $sub); ?> |
|
| 229 | 229 | |
| 230 | - <?php do_action( 'wpinv_subscription_before_tables_wrapper', $sub ); ?> |
|
| 230 | + <?php do_action('wpinv_subscription_before_tables_wrapper', $sub); ?> |
|
| 231 | 231 | |
| 232 | 232 | <div id="item-tables-wrapper" class="item-section"> |
| 233 | 233 | |
| 234 | - <?php do_action( 'wpinv_subscription_before_tables', $sub ); ?> |
|
| 234 | + <?php do_action('wpinv_subscription_before_tables', $sub); ?> |
|
| 235 | 235 | |
| 236 | - <h3><?php _e( 'Renewal Payments:', 'invoicing' ); ?></h3> |
|
| 236 | + <h3><?php _e('Renewal Payments:', 'invoicing'); ?></h3> |
|
| 237 | 237 | <?php $payments = $sub->get_child_payments(); ?> |
| 238 | - <?php if ( 'manual' == $sub->gateway ) : ?> |
|
| 239 | - <p><strong><?php _e( 'Note:', 'invoicing' ); ?></strong> <?php _e( 'Subscriptions purchased with the Test Payment gateway will not renew automatically.', 'invoicing' ); ?></p> |
|
| 238 | + <?php if ('manual' == $sub->gateway) : ?> |
|
| 239 | + <p><strong><?php _e('Note:', 'invoicing'); ?></strong> <?php _e('Subscriptions purchased with the Test Payment gateway will not renew automatically.', 'invoicing'); ?></p> |
|
| 240 | 240 | <?php endif; ?> |
| 241 | 241 | <table class="wp-list-table widefat striped payments"> |
| 242 | 242 | <thead> |
| 243 | 243 | <tr> |
| 244 | - <th><?php _e( 'ID', 'invoicing' ); ?></th> |
|
| 245 | - <th><?php _e( 'Amount', 'invoicing' ); ?></th> |
|
| 246 | - <th><?php _e( 'Date', 'invoicing' ); ?></th> |
|
| 247 | - <th><?php _e( 'Status', 'invoicing' ); ?></th> |
|
| 248 | - <th><?php _e( 'Invoice', 'invoicing' ); ?></th> |
|
| 249 | - <th class="column-wpi_actions"><?php _e( 'Actions', 'invoicing' ); ?></th> |
|
| 244 | + <th><?php _e('ID', 'invoicing'); ?></th> |
|
| 245 | + <th><?php _e('Amount', 'invoicing'); ?></th> |
|
| 246 | + <th><?php _e('Date', 'invoicing'); ?></th> |
|
| 247 | + <th><?php _e('Status', 'invoicing'); ?></th> |
|
| 248 | + <th><?php _e('Invoice', 'invoicing'); ?></th> |
|
| 249 | + <th class="column-wpi_actions"><?php _e('Actions', 'invoicing'); ?></th> |
|
| 250 | 250 | </tr> |
| 251 | 251 | </thead> |
| 252 | 252 | <tbody> |
| 253 | - <?php if ( ! empty( $payments ) ) : ?> |
|
| 254 | - <?php foreach ( $payments as $payment ) : $invoice = wpinv_get_invoice( $payment->ID ); if ( empty( $invoice->ID ) ) continue; ?> |
|
| 253 | + <?php if (!empty($payments)) : ?> |
|
| 254 | + <?php foreach ($payments as $payment) : $invoice = wpinv_get_invoice($payment->ID); if (empty($invoice->ID)) continue; ?> |
|
| 255 | 255 | <tr> |
| 256 | 256 | <td><?php echo $payment->ID; ?></td> |
| 257 | - <td><?php echo $invoice->get_total( true ); ?></td> |
|
| 257 | + <td><?php echo $invoice->get_total(true); ?></td> |
|
| 258 | 258 | <td><?php echo $invoice->get_invoice_date(); ?></td> |
| 259 | - <td><?php echo $invoice->get_status( true ); ?></td> |
|
| 259 | + <td><?php echo $invoice->get_status(true); ?></td> |
|
| 260 | 260 | <td> |
| 261 | - <a target="_blank" title="<?php _e( 'View invoice', 'invoicing' ); ?>" href="<?php echo esc_url( get_permalink( $payment->ID ) ); ?>"><?php echo $invoice->get_number(); ?></a> |
|
| 262 | - <?php do_action( 'wpinv_subscription_payments_actions', $sub, $payment ); ?> |
|
| 261 | + <a target="_blank" title="<?php _e('View invoice', 'invoicing'); ?>" href="<?php echo esc_url(get_permalink($payment->ID)); ?>"><?php echo $invoice->get_number(); ?></a> |
|
| 262 | + <?php do_action('wpinv_subscription_payments_actions', $sub, $payment); ?> |
|
| 263 | 263 | </td> |
| 264 | 264 | <td class="column-wpi_actions"> |
| 265 | - <a title="<?php echo esc_attr( wp_sprintf( __( 'View details for invoice: %s', 'invoicing' ), $invoice->get_number() ) ); ?>" href="<?php echo get_edit_post_link( $payment->ID ); ?>"><?php _e( 'View Details', 'invoicing' ); ?> |
|
| 265 | + <a title="<?php echo esc_attr(wp_sprintf(__('View details for invoice: %s', 'invoicing'), $invoice->get_number())); ?>" href="<?php echo get_edit_post_link($payment->ID); ?>"><?php _e('View Details', 'invoicing'); ?> |
|
| 266 | 266 | </a> |
| 267 | - <?php do_action( 'wpinv_subscription_payments_actions', $sub, $payment ); ?> |
|
| 267 | + <?php do_action('wpinv_subscription_payments_actions', $sub, $payment); ?> |
|
| 268 | 268 | </td> |
| 269 | 269 | </tr> |
| 270 | 270 | <?php endforeach; ?> |
| 271 | 271 | <?php else: ?> |
| 272 | 272 | <tr> |
| 273 | - <td colspan="5"><?php _e( 'No Invoices Found.', 'invoicing' ); ?></td> |
|
| 273 | + <td colspan="5"><?php _e('No Invoices Found.', 'invoicing'); ?></td> |
|
| 274 | 274 | </tr> |
| 275 | 275 | <?php endif; ?> |
| 276 | 276 | </tbody> |
| 277 | 277 | <tfoot></tfoot> |
| 278 | 278 | </table> |
| 279 | 279 | |
| 280 | - <?php do_action( 'wpinv_subscription_after_tables', $sub ); ?> |
|
| 280 | + <?php do_action('wpinv_subscription_after_tables', $sub); ?> |
|
| 281 | 281 | |
| 282 | 282 | </div> |
| 283 | 283 | |
| 284 | - <?php do_action( 'wpinv_subscription_card_bottom', $sub ); ?> |
|
| 284 | + <?php do_action('wpinv_subscription_card_bottom', $sub); ?> |
|
| 285 | 285 | </div> |
| 286 | 286 | |
| 287 | 287 | <?php endif; ?> |
@@ -299,36 +299,36 @@ discard block |
||
| 299 | 299 | */ |
| 300 | 300 | function wpinv_recurring_process_subscription_update() { |
| 301 | 301 | |
| 302 | - if( empty( $_POST['sub_id'] ) ) { |
|
| 302 | + if (empty($_POST['sub_id'])) { |
|
| 303 | 303 | return; |
| 304 | 304 | } |
| 305 | 305 | |
| 306 | - if( empty( $_POST['wpinv_update_subscription'] ) ) { |
|
| 306 | + if (empty($_POST['wpinv_update_subscription'])) { |
|
| 307 | 307 | return; |
| 308 | 308 | } |
| 309 | 309 | |
| 310 | - if( ! current_user_can( 'manage_invoicing') ) { |
|
| 310 | + if (!current_user_can('manage_invoicing')) { |
|
| 311 | 311 | return; |
| 312 | 312 | } |
| 313 | 313 | |
| 314 | - if( ! wp_verify_nonce( $_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update' ) ) { |
|
| 315 | - wp_die( __( 'Nonce verification failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 314 | + if (!wp_verify_nonce($_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update')) { |
|
| 315 | + wp_die(__('Nonce verification failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
| 316 | 316 | } |
| 317 | 317 | |
| 318 | - $profile_id = sanitize_text_field( $_POST['profile_id'] ); |
|
| 319 | - $transaction_id = sanitize_text_field( $_POST['transaction_id'] ); |
|
| 320 | - $product_id = absint( $_POST['product_id'] ); |
|
| 321 | - $subscription = new WPInv_Subscription( absint( $_POST['sub_id'] ) ); |
|
| 322 | - $subscription->update( array( |
|
| 323 | - 'status' => sanitize_text_field( $_POST['status'] ), |
|
| 318 | + $profile_id = sanitize_text_field($_POST['profile_id']); |
|
| 319 | + $transaction_id = sanitize_text_field($_POST['transaction_id']); |
|
| 320 | + $product_id = absint($_POST['product_id']); |
|
| 321 | + $subscription = new WPInv_Subscription(absint($_POST['sub_id'])); |
|
| 322 | + $subscription->update(array( |
|
| 323 | + 'status' => sanitize_text_field($_POST['status']), |
|
| 324 | 324 | 'profile_id' => $profile_id, |
| 325 | 325 | 'product_id' => $product_id, |
| 326 | 326 | 'transaction_id' => $transaction_id, |
| 327 | - ) ); |
|
| 327 | + )); |
|
| 328 | 328 | |
| 329 | - $status = sanitize_text_field( $_POST['status'] ); |
|
| 329 | + $status = sanitize_text_field($_POST['status']); |
|
| 330 | 330 | |
| 331 | - switch( $status ) { |
|
| 331 | + switch ($status) { |
|
| 332 | 332 | |
| 333 | 333 | case 'cancelled' : |
| 334 | 334 | |
@@ -347,11 +347,11 @@ discard block |
||
| 347 | 347 | |
| 348 | 348 | } |
| 349 | 349 | |
| 350 | - wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=updated&id=' . $subscription->id ) ); |
|
| 350 | + wp_redirect(admin_url('admin.php?page=wpinv-subscriptions&wpinv-message=updated&id=' . $subscription->id)); |
|
| 351 | 351 | exit; |
| 352 | 352 | |
| 353 | 353 | } |
| 354 | -add_action( 'admin_init', 'wpinv_recurring_process_subscription_update', 1 ); |
|
| 354 | +add_action('admin_init', 'wpinv_recurring_process_subscription_update', 1); |
|
| 355 | 355 | |
| 356 | 356 | /** |
| 357 | 357 | * Handles subscription deletion |
@@ -362,30 +362,30 @@ discard block |
||
| 362 | 362 | */ |
| 363 | 363 | function wpinv_recurring_process_subscription_deletion() { |
| 364 | 364 | |
| 365 | - if( empty( $_POST['sub_id'] ) ) { |
|
| 365 | + if (empty($_POST['sub_id'])) { |
|
| 366 | 366 | return; |
| 367 | 367 | } |
| 368 | 368 | |
| 369 | - if( empty( $_POST['wpinv_delete_subscription'] ) ) { |
|
| 369 | + if (empty($_POST['wpinv_delete_subscription'])) { |
|
| 370 | 370 | return; |
| 371 | 371 | } |
| 372 | 372 | |
| 373 | - if( ! current_user_can( 'manage_invoicing') ) { |
|
| 373 | + if (!current_user_can('manage_invoicing')) { |
|
| 374 | 374 | return; |
| 375 | 375 | } |
| 376 | 376 | |
| 377 | - if( ! wp_verify_nonce( $_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update' ) ) { |
|
| 378 | - wp_die( __( 'Nonce verification failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 377 | + if (!wp_verify_nonce($_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update')) { |
|
| 378 | + wp_die(__('Nonce verification failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
| 379 | 379 | } |
| 380 | 380 | |
| 381 | - $subscription = new WPInv_Subscription( absint( $_POST['sub_id'] ) ); |
|
| 381 | + $subscription = new WPInv_Subscription(absint($_POST['sub_id'])); |
|
| 382 | 382 | |
| 383 | - delete_post_meta( $subscription->parent_payment_id, '_wpinv_subscription_payment' ); |
|
| 383 | + delete_post_meta($subscription->parent_payment_id, '_wpinv_subscription_payment'); |
|
| 384 | 384 | |
| 385 | 385 | $subscription->delete(); |
| 386 | 386 | |
| 387 | - wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=deleted' ) ); |
|
| 387 | + wp_redirect(admin_url('admin.php?page=wpinv-subscriptions&wpinv-message=deleted')); |
|
| 388 | 388 | exit; |
| 389 | 389 | |
| 390 | 390 | } |
| 391 | -add_action( 'admin_init', 'wpinv_recurring_process_subscription_deletion', 2 ); |
|
| 391 | +add_action('admin_init', 'wpinv_recurring_process_subscription_deletion', 2); |
|
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | // Load WP_List_Table if not loaded |
| 15 | 15 | if( ! class_exists( 'WP_List_Table' ) ) { |
| 16 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 16 | + require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | /** |
@@ -23,102 +23,102 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | class WPInv_Subscription_Reports_Table extends WP_List_Table { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Number of results to show per page |
|
| 28 | - * |
|
| 29 | - * @since 1.0.0 |
|
| 30 | - */ |
|
| 31 | - |
|
| 32 | - public $per_page = 20; |
|
| 33 | - public $total_count = 0; |
|
| 34 | - public $active_count = 0; |
|
| 35 | - public $pending_count = 0; |
|
| 36 | - public $expired_count = 0; |
|
| 37 | - public $completed_count = 0; |
|
| 38 | - public $trialling_count = 0; |
|
| 39 | - public $cancelled_count = 0; |
|
| 40 | - public $failing_count = 0; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Get things started |
|
| 44 | - * |
|
| 45 | - * @access private |
|
| 46 | - * @since 1.0.0 |
|
| 47 | - * @return void |
|
| 48 | - */ |
|
| 49 | - function __construct(){ |
|
| 50 | - global $status, $page; |
|
| 51 | - |
|
| 52 | - // Set parent defaults |
|
| 53 | - parent::__construct( array( |
|
| 54 | - 'singular' => 'subscription', |
|
| 55 | - 'plural' => 'subscriptions', |
|
| 56 | - 'ajax' => false |
|
| 57 | - ) ); |
|
| 58 | - |
|
| 59 | - $this->get_subscription_counts(); |
|
| 60 | - |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Retrieve the view types |
|
| 65 | - * |
|
| 66 | - * @access public |
|
| 67 | - * @since 1.0.0 |
|
| 68 | - * @return array $views All the views available |
|
| 69 | - */ |
|
| 70 | - public function get_views() { |
|
| 71 | - |
|
| 72 | - $current = isset( $_GET['status'] ) ? $_GET['status'] : ''; |
|
| 73 | - $total_count = ' <span class="count">(' . $this->total_count . ')</span>'; |
|
| 74 | - $active_count = ' <span class="count">(' . $this->active_count . ')</span>'; |
|
| 75 | - $pending_count = ' <span class="count">(' . $this->pending_count . ')</span>'; |
|
| 76 | - $expired_count = ' <span class="count">(' . $this->expired_count . ')</span>'; |
|
| 77 | - $completed_count = ' <span class="count">(' . $this->completed_count . ')</span>'; |
|
| 78 | - $trialling_count = ' <span class="count">(' . $this->trialling_count . ')</span>'; |
|
| 79 | - $cancelled_count = ' <span class="count">(' . $this->cancelled_count . ')</span>'; |
|
| 80 | - $failing_count = ' <span class="count">(' . $this->failing_count . ')</span>'; |
|
| 81 | - |
|
| 82 | - $views = array( |
|
| 83 | - 'all' => sprintf( '<a href="%s"%s>%s</a>', remove_query_arg( array( 'status', 'paged' ) ), $current === 'all' || $current == '' ? ' class="current"' : '', __('All','invoicing' ) . $total_count ), |
|
| 84 | - 'active' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'active', 'paged' => FALSE ) ), $current === 'active' ? ' class="current"' : '', __('Active','invoicing' ) . $active_count ), |
|
| 85 | - 'pending' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'pending', 'paged' => FALSE ) ), $current === 'pending' ? ' class="current"' : '', __('Pending','invoicing' ) . $pending_count ), |
|
| 86 | - 'expired' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'expired', 'paged' => FALSE ) ), $current === 'expired' ? ' class="current"' : '', __('Expired','invoicing' ) . $expired_count ), |
|
| 87 | - 'completed' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'completed', 'paged' => FALSE ) ), $current === 'completed' ? ' class="current"' : '', __('Completed','invoicing' ) . $completed_count ), |
|
| 88 | - 'trialling' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'trialling', 'paged' => FALSE ) ), $current === 'trialling' ? ' class="current"' : '', __('Trialling','invoicing' ) . $trialling_count ), |
|
| 89 | - 'cancelled' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'cancelled', 'paged' => FALSE ) ), $current === 'cancelled' ? ' class="current"' : '', __('Cancelled','invoicing' ) . $cancelled_count ), |
|
| 90 | - 'failing' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'failing', 'paged' => FALSE ) ), $current === 'failing' ? ' class="current"' : '', __('Failing','invoicing' ) . $failing_count ), |
|
| 91 | - ); |
|
| 92 | - |
|
| 93 | - return apply_filters( 'wpinv_recurring_subscriptions_table_views', $views ); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Show the search field |
|
| 98 | - * |
|
| 99 | - * @since 2.5 |
|
| 100 | - * @access public |
|
| 101 | - * |
|
| 102 | - * @param string $text Label for the search box |
|
| 103 | - * @param string $input_id ID of the search box |
|
| 104 | - * |
|
| 105 | - * @return void |
|
| 106 | - */ |
|
| 107 | - public function search_box( $text, $input_id ) { |
|
| 108 | - |
|
| 109 | - if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) { |
|
| 110 | - return; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - $input_id = $input_id . '-search-input'; |
|
| 114 | - |
|
| 115 | - if ( ! empty( $_REQUEST['orderby'] ) ) { |
|
| 116 | - echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />'; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - if ( ! empty( $_REQUEST['order'] ) ) { |
|
| 120 | - echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />'; |
|
| 121 | - } |
|
| 26 | + /** |
|
| 27 | + * Number of results to show per page |
|
| 28 | + * |
|
| 29 | + * @since 1.0.0 |
|
| 30 | + */ |
|
| 31 | + |
|
| 32 | + public $per_page = 20; |
|
| 33 | + public $total_count = 0; |
|
| 34 | + public $active_count = 0; |
|
| 35 | + public $pending_count = 0; |
|
| 36 | + public $expired_count = 0; |
|
| 37 | + public $completed_count = 0; |
|
| 38 | + public $trialling_count = 0; |
|
| 39 | + public $cancelled_count = 0; |
|
| 40 | + public $failing_count = 0; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Get things started |
|
| 44 | + * |
|
| 45 | + * @access private |
|
| 46 | + * @since 1.0.0 |
|
| 47 | + * @return void |
|
| 48 | + */ |
|
| 49 | + function __construct(){ |
|
| 50 | + global $status, $page; |
|
| 51 | + |
|
| 52 | + // Set parent defaults |
|
| 53 | + parent::__construct( array( |
|
| 54 | + 'singular' => 'subscription', |
|
| 55 | + 'plural' => 'subscriptions', |
|
| 56 | + 'ajax' => false |
|
| 57 | + ) ); |
|
| 58 | + |
|
| 59 | + $this->get_subscription_counts(); |
|
| 60 | + |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Retrieve the view types |
|
| 65 | + * |
|
| 66 | + * @access public |
|
| 67 | + * @since 1.0.0 |
|
| 68 | + * @return array $views All the views available |
|
| 69 | + */ |
|
| 70 | + public function get_views() { |
|
| 71 | + |
|
| 72 | + $current = isset( $_GET['status'] ) ? $_GET['status'] : ''; |
|
| 73 | + $total_count = ' <span class="count">(' . $this->total_count . ')</span>'; |
|
| 74 | + $active_count = ' <span class="count">(' . $this->active_count . ')</span>'; |
|
| 75 | + $pending_count = ' <span class="count">(' . $this->pending_count . ')</span>'; |
|
| 76 | + $expired_count = ' <span class="count">(' . $this->expired_count . ')</span>'; |
|
| 77 | + $completed_count = ' <span class="count">(' . $this->completed_count . ')</span>'; |
|
| 78 | + $trialling_count = ' <span class="count">(' . $this->trialling_count . ')</span>'; |
|
| 79 | + $cancelled_count = ' <span class="count">(' . $this->cancelled_count . ')</span>'; |
|
| 80 | + $failing_count = ' <span class="count">(' . $this->failing_count . ')</span>'; |
|
| 81 | + |
|
| 82 | + $views = array( |
|
| 83 | + 'all' => sprintf( '<a href="%s"%s>%s</a>', remove_query_arg( array( 'status', 'paged' ) ), $current === 'all' || $current == '' ? ' class="current"' : '', __('All','invoicing' ) . $total_count ), |
|
| 84 | + 'active' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'active', 'paged' => FALSE ) ), $current === 'active' ? ' class="current"' : '', __('Active','invoicing' ) . $active_count ), |
|
| 85 | + 'pending' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'pending', 'paged' => FALSE ) ), $current === 'pending' ? ' class="current"' : '', __('Pending','invoicing' ) . $pending_count ), |
|
| 86 | + 'expired' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'expired', 'paged' => FALSE ) ), $current === 'expired' ? ' class="current"' : '', __('Expired','invoicing' ) . $expired_count ), |
|
| 87 | + 'completed' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'completed', 'paged' => FALSE ) ), $current === 'completed' ? ' class="current"' : '', __('Completed','invoicing' ) . $completed_count ), |
|
| 88 | + 'trialling' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'trialling', 'paged' => FALSE ) ), $current === 'trialling' ? ' class="current"' : '', __('Trialling','invoicing' ) . $trialling_count ), |
|
| 89 | + 'cancelled' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'cancelled', 'paged' => FALSE ) ), $current === 'cancelled' ? ' class="current"' : '', __('Cancelled','invoicing' ) . $cancelled_count ), |
|
| 90 | + 'failing' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'failing', 'paged' => FALSE ) ), $current === 'failing' ? ' class="current"' : '', __('Failing','invoicing' ) . $failing_count ), |
|
| 91 | + ); |
|
| 92 | + |
|
| 93 | + return apply_filters( 'wpinv_recurring_subscriptions_table_views', $views ); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Show the search field |
|
| 98 | + * |
|
| 99 | + * @since 2.5 |
|
| 100 | + * @access public |
|
| 101 | + * |
|
| 102 | + * @param string $text Label for the search box |
|
| 103 | + * @param string $input_id ID of the search box |
|
| 104 | + * |
|
| 105 | + * @return void |
|
| 106 | + */ |
|
| 107 | + public function search_box( $text, $input_id ) { |
|
| 108 | + |
|
| 109 | + if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) { |
|
| 110 | + return; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + $input_id = $input_id . '-search-input'; |
|
| 114 | + |
|
| 115 | + if ( ! empty( $_REQUEST['orderby'] ) ) { |
|
| 116 | + echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />'; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + if ( ! empty( $_REQUEST['order'] ) ) { |
|
| 120 | + echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />'; |
|
| 121 | + } |
|
| 122 | 122 | ?> |
| 123 | 123 | <p class="search-box"> |
| 124 | 124 | <?php do_action( 'wpinv_recurring_subscription_search_box' ); ?> |
@@ -127,18 +127,18 @@ discard block |
||
| 127 | 127 | <?php submit_button( $text, 'button', false, false, array('ID' => 'search-submit') ); ?><br/> |
| 128 | 128 | </p> |
| 129 | 129 | <?php |
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * Render most columns |
|
| 134 | - * |
|
| 135 | - * @access private |
|
| 136 | - * @since 1.0.0 |
|
| 137 | - * @return string |
|
| 138 | - */ |
|
| 139 | - function column_default( $item, $column_name ) { |
|
| 140 | - return $item->$column_name; |
|
| 141 | - } |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * Render most columns |
|
| 134 | + * |
|
| 135 | + * @access private |
|
| 136 | + * @since 1.0.0 |
|
| 137 | + * @return string |
|
| 138 | + */ |
|
| 139 | + function column_default( $item, $column_name ) { |
|
| 140 | + return $item->$column_name; |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | 143 | /** |
| 144 | 144 | * Subscription id column |
@@ -151,244 +151,244 @@ discard block |
||
| 151 | 151 | return '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $item->id ) ) . '" target="_blank">' . $item->id . '</a>'; |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - /** |
|
| 155 | - * Customer column |
|
| 156 | - * |
|
| 157 | - * @access private |
|
| 158 | - * @since 1.0.0 |
|
| 159 | - * @return string |
|
| 160 | - */ |
|
| 161 | - function column_customer_id( $item ) { |
|
| 162 | - $subscriber = get_userdata( $item->customer_id ); |
|
| 163 | - $customer = ! empty( $subscriber->display_name ) ? $subscriber->display_name : $subscriber->user_email; |
|
| 164 | - |
|
| 165 | - return '<a href="' . esc_url( get_edit_user_link( $item->customer_id ) ) . '" target="_blank">' . $customer . '</a>'; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Status column |
|
| 170 | - * |
|
| 171 | - * @access private |
|
| 172 | - * @since 1.0.0 |
|
| 173 | - * @return string |
|
| 174 | - */ |
|
| 175 | - function column_status( $item ) { |
|
| 176 | - return $item->get_status_label(); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * Period column |
|
| 181 | - * |
|
| 182 | - * @access private |
|
| 183 | - * @since 1.0.0 |
|
| 184 | - * @return string |
|
| 185 | - */ |
|
| 186 | - function column_period( $item ) { |
|
| 187 | - |
|
| 188 | - $period = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->period,$item->frequency ); |
|
| 189 | - |
|
| 190 | - return wpinv_price( wpinv_format_amount( $item->recurring_amount ), wpinv_get_invoice_currency_code( $item->parent_payment_id ) ) . ' / ' . $period; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * Billing Times column |
|
| 195 | - * |
|
| 196 | - * @access private |
|
| 197 | - * @since 1.0.0 |
|
| 198 | - * @return string |
|
| 199 | - */ |
|
| 200 | - function column_bill_times( $item ) { |
|
| 201 | - return $item->get_times_billed() . ' / ' . ( ( $item->bill_times == 0 ) ? __( 'Until Cancelled', 'invoicing' ) : $item->bill_times ); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * Initial Amount column |
|
| 206 | - * |
|
| 207 | - * @access private |
|
| 208 | - * @since 1.0.0 |
|
| 209 | - * @return string |
|
| 210 | - */ |
|
| 211 | - function column_initial_amount( $item ) { |
|
| 212 | - return wpinv_price( wpinv_format_amount( $item->initial_amount ), wpinv_get_invoice_currency_code( $item->parent_payment_id ) ); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * Renewal date column |
|
| 217 | - * |
|
| 218 | - * @access private |
|
| 219 | - * @since 1.0.0 |
|
| 220 | - * @return string |
|
| 221 | - */ |
|
| 222 | - function column_renewal_date( $item ) { |
|
| 223 | - return $renewal_date = ! empty( $item->expiration ) ? date_i18n( get_option( 'date_format' ), strtotime( $item->expiration ) ) : __( 'N/A', 'invoicing' ); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * Payment column |
|
| 228 | - * |
|
| 229 | - * @access private |
|
| 230 | - * @since 1.0.0 |
|
| 231 | - * @return string |
|
| 232 | - */ |
|
| 233 | - function column_parent_payment_id( $item ) { |
|
| 234 | - return '<a href="' . get_edit_post_link( $item->parent_payment_id ) . '" target="_blank">' . wpinv_get_invoice_number( $item->parent_payment_id ) . '</a>'; |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - /** |
|
| 238 | - * Product ID column |
|
| 239 | - * |
|
| 240 | - * @access private |
|
| 241 | - * @since 1.0.0 |
|
| 242 | - * @return string |
|
| 243 | - */ |
|
| 244 | - function column_product_id( $item ) { |
|
| 245 | - return '<a href="' . esc_url( admin_url( 'post.php?action=edit&post=' . $item->product_id ) ) . '" target="_blank">' . get_the_title( $item->product_id ) . '</a>'; |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * Render the edit column |
|
| 250 | - * |
|
| 251 | - * @access private |
|
| 252 | - * @since 2.0 |
|
| 253 | - * @return string |
|
| 254 | - */ |
|
| 255 | - function column_actions( $item ) { |
|
| 256 | - return '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $item->id ) ) . '" title="' . esc_attr( __( 'View or edit subscription', 'invoicing' ) ) . '" target="_blank">' . __( 'View', 'invoicing' ) . '</a>'; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - |
|
| 260 | - /** |
|
| 261 | - * Retrieve the table columns |
|
| 262 | - * |
|
| 263 | - * @access private |
|
| 264 | - * @since 1.0.0 |
|
| 265 | - * @return array |
|
| 266 | - */ |
|
| 267 | - |
|
| 268 | - function get_columns(){ |
|
| 269 | - $columns = array( |
|
| 270 | - 'sub_id' => __( 'ID', 'invoicing' ), |
|
| 271 | - 'customer_id' => __( 'Customer', 'invoicing' ), |
|
| 272 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 273 | - 'period' => __( 'Billing Cycle', 'invoicing' ), |
|
| 274 | - 'initial_amount' => __( 'Initial Amount', 'invoicing' ), |
|
| 275 | - 'bill_times' => __( 'Times Billed', 'invoicing' ), |
|
| 276 | - 'renewal_date' => __( 'Renewal Date', 'invoicing' ), |
|
| 277 | - 'parent_payment_id' => __( 'Invoice', 'invoicing' ), |
|
| 278 | - 'product_id' => __( 'Item', 'invoicing' ), |
|
| 279 | - 'actions' => __( 'Actions', 'invoicing' ), |
|
| 280 | - ); |
|
| 281 | - |
|
| 282 | - return apply_filters( 'wpinv_report_subscription_columns', $columns ); |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * Retrieve the current page number |
|
| 287 | - * |
|
| 288 | - * @access private |
|
| 289 | - * @since 1.0.0 |
|
| 290 | - * @return int |
|
| 291 | - */ |
|
| 292 | - function get_paged() { |
|
| 293 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * Retrieve the subscription counts |
|
| 298 | - * |
|
| 299 | - * @access public |
|
| 300 | - * @since 1.4 |
|
| 301 | - * @return void |
|
| 302 | - */ |
|
| 303 | - public function get_subscription_counts() { |
|
| 304 | - |
|
| 305 | - global $wp_query; |
|
| 306 | - |
|
| 307 | - $db = new WPInv_Subscriptions_DB; |
|
| 308 | - |
|
| 309 | - $search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : ''; |
|
| 310 | - |
|
| 311 | - $this->total_count = $db->count(); |
|
| 312 | - $this->active_count = $db->count( array( 'status' => 'active', 'search' => $search ) ); |
|
| 313 | - $this->pending_count = $db->count( array( 'status' => 'pending', 'search' => $search ) ); |
|
| 314 | - $this->expired_count = $db->count( array( 'status' => 'expired', 'search' => $search ) ); |
|
| 315 | - $this->trialling_count = $db->count( array( 'status' => 'trialling', 'search' => $search ) ); |
|
| 316 | - $this->cancelled_count = $db->count( array( 'status' => 'cancelled', 'search' => $search ) ); |
|
| 317 | - $this->completed_count = $db->count( array( 'status' => 'completed', 'search' => $search ) ); |
|
| 318 | - $this->failing_count = $db->count( array( 'status' => 'failing', 'search' => $search ) ); |
|
| 319 | - |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - /** |
|
| 323 | - * Setup the final data for the table |
|
| 324 | - * |
|
| 325 | - * @access private |
|
| 326 | - * @since 1.0.0 |
|
| 327 | - * @uses $this->_column_headers |
|
| 328 | - * @uses $this->items |
|
| 329 | - * @uses $this->get_columns() |
|
| 330 | - * @uses $this->get_sortable_columns() |
|
| 331 | - * @uses $this->get_pagenum() |
|
| 332 | - * @uses $this->set_pagination_args() |
|
| 333 | - * @return array |
|
| 334 | - */ |
|
| 335 | - function prepare_items() { |
|
| 336 | - |
|
| 337 | - $columns = $this->get_columns(); |
|
| 338 | - $hidden = array(); // No hidden columns |
|
| 339 | - $status = isset( $_GET['status'] ) ? $_GET['status'] : 'any'; |
|
| 340 | - $sortable = $this->get_sortable_columns(); |
|
| 341 | - |
|
| 342 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
| 343 | - |
|
| 344 | - $current_page = $this->get_pagenum(); |
|
| 345 | - |
|
| 346 | - $db = new WPInv_Subscriptions_DB; |
|
| 347 | - $search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : ''; |
|
| 348 | - $args = array( |
|
| 349 | - 'number' => $this->per_page, |
|
| 350 | - 'offset' => $this->per_page * ( $this->get_paged() - 1 ), |
|
| 351 | - 'search' => $search |
|
| 352 | - ); |
|
| 353 | - |
|
| 354 | - if ( 'any' !== $status ) { |
|
| 355 | - $args['status'] = $status; |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - $this->items = $db->get_subscriptions( $args ); |
|
| 359 | - |
|
| 360 | - switch ( $status ) { |
|
| 361 | - case 'active': |
|
| 362 | - $total_items = $this->active_count; |
|
| 363 | - break; |
|
| 364 | - case 'pending': |
|
| 365 | - $total_items = $this->pending_count; |
|
| 366 | - break; |
|
| 367 | - case 'expired': |
|
| 368 | - $total_items = $this->expired_count; |
|
| 369 | - break; |
|
| 370 | - case 'cancelled': |
|
| 371 | - $total_items = $this->cancelled_count; |
|
| 372 | - break; |
|
| 373 | - case 'failing': |
|
| 374 | - $total_items = $this->failing_count; |
|
| 375 | - break; |
|
| 376 | - case 'trialling': |
|
| 377 | - $total_items = $this->trialling_count; |
|
| 378 | - break; |
|
| 379 | - case 'completed': |
|
| 380 | - $total_items = $this->completed_count; |
|
| 381 | - break; |
|
| 382 | - case 'any': |
|
| 383 | - default: |
|
| 384 | - $total_items = $this->total_count; |
|
| 385 | - break; |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - $this->set_pagination_args( array( |
|
| 389 | - 'total_items' => $total_items, |
|
| 390 | - 'per_page' => $this->per_page, |
|
| 391 | - 'total_pages' => ceil( $total_items / $this->per_page ) |
|
| 392 | - ) ); |
|
| 393 | - } |
|
| 154 | + /** |
|
| 155 | + * Customer column |
|
| 156 | + * |
|
| 157 | + * @access private |
|
| 158 | + * @since 1.0.0 |
|
| 159 | + * @return string |
|
| 160 | + */ |
|
| 161 | + function column_customer_id( $item ) { |
|
| 162 | + $subscriber = get_userdata( $item->customer_id ); |
|
| 163 | + $customer = ! empty( $subscriber->display_name ) ? $subscriber->display_name : $subscriber->user_email; |
|
| 164 | + |
|
| 165 | + return '<a href="' . esc_url( get_edit_user_link( $item->customer_id ) ) . '" target="_blank">' . $customer . '</a>'; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Status column |
|
| 170 | + * |
|
| 171 | + * @access private |
|
| 172 | + * @since 1.0.0 |
|
| 173 | + * @return string |
|
| 174 | + */ |
|
| 175 | + function column_status( $item ) { |
|
| 176 | + return $item->get_status_label(); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * Period column |
|
| 181 | + * |
|
| 182 | + * @access private |
|
| 183 | + * @since 1.0.0 |
|
| 184 | + * @return string |
|
| 185 | + */ |
|
| 186 | + function column_period( $item ) { |
|
| 187 | + |
|
| 188 | + $period = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->period,$item->frequency ); |
|
| 189 | + |
|
| 190 | + return wpinv_price( wpinv_format_amount( $item->recurring_amount ), wpinv_get_invoice_currency_code( $item->parent_payment_id ) ) . ' / ' . $period; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * Billing Times column |
|
| 195 | + * |
|
| 196 | + * @access private |
|
| 197 | + * @since 1.0.0 |
|
| 198 | + * @return string |
|
| 199 | + */ |
|
| 200 | + function column_bill_times( $item ) { |
|
| 201 | + return $item->get_times_billed() . ' / ' . ( ( $item->bill_times == 0 ) ? __( 'Until Cancelled', 'invoicing' ) : $item->bill_times ); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * Initial Amount column |
|
| 206 | + * |
|
| 207 | + * @access private |
|
| 208 | + * @since 1.0.0 |
|
| 209 | + * @return string |
|
| 210 | + */ |
|
| 211 | + function column_initial_amount( $item ) { |
|
| 212 | + return wpinv_price( wpinv_format_amount( $item->initial_amount ), wpinv_get_invoice_currency_code( $item->parent_payment_id ) ); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * Renewal date column |
|
| 217 | + * |
|
| 218 | + * @access private |
|
| 219 | + * @since 1.0.0 |
|
| 220 | + * @return string |
|
| 221 | + */ |
|
| 222 | + function column_renewal_date( $item ) { |
|
| 223 | + return $renewal_date = ! empty( $item->expiration ) ? date_i18n( get_option( 'date_format' ), strtotime( $item->expiration ) ) : __( 'N/A', 'invoicing' ); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * Payment column |
|
| 228 | + * |
|
| 229 | + * @access private |
|
| 230 | + * @since 1.0.0 |
|
| 231 | + * @return string |
|
| 232 | + */ |
|
| 233 | + function column_parent_payment_id( $item ) { |
|
| 234 | + return '<a href="' . get_edit_post_link( $item->parent_payment_id ) . '" target="_blank">' . wpinv_get_invoice_number( $item->parent_payment_id ) . '</a>'; |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * Product ID column |
|
| 239 | + * |
|
| 240 | + * @access private |
|
| 241 | + * @since 1.0.0 |
|
| 242 | + * @return string |
|
| 243 | + */ |
|
| 244 | + function column_product_id( $item ) { |
|
| 245 | + return '<a href="' . esc_url( admin_url( 'post.php?action=edit&post=' . $item->product_id ) ) . '" target="_blank">' . get_the_title( $item->product_id ) . '</a>'; |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * Render the edit column |
|
| 250 | + * |
|
| 251 | + * @access private |
|
| 252 | + * @since 2.0 |
|
| 253 | + * @return string |
|
| 254 | + */ |
|
| 255 | + function column_actions( $item ) { |
|
| 256 | + return '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $item->id ) ) . '" title="' . esc_attr( __( 'View or edit subscription', 'invoicing' ) ) . '" target="_blank">' . __( 'View', 'invoicing' ) . '</a>'; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + |
|
| 260 | + /** |
|
| 261 | + * Retrieve the table columns |
|
| 262 | + * |
|
| 263 | + * @access private |
|
| 264 | + * @since 1.0.0 |
|
| 265 | + * @return array |
|
| 266 | + */ |
|
| 267 | + |
|
| 268 | + function get_columns(){ |
|
| 269 | + $columns = array( |
|
| 270 | + 'sub_id' => __( 'ID', 'invoicing' ), |
|
| 271 | + 'customer_id' => __( 'Customer', 'invoicing' ), |
|
| 272 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 273 | + 'period' => __( 'Billing Cycle', 'invoicing' ), |
|
| 274 | + 'initial_amount' => __( 'Initial Amount', 'invoicing' ), |
|
| 275 | + 'bill_times' => __( 'Times Billed', 'invoicing' ), |
|
| 276 | + 'renewal_date' => __( 'Renewal Date', 'invoicing' ), |
|
| 277 | + 'parent_payment_id' => __( 'Invoice', 'invoicing' ), |
|
| 278 | + 'product_id' => __( 'Item', 'invoicing' ), |
|
| 279 | + 'actions' => __( 'Actions', 'invoicing' ), |
|
| 280 | + ); |
|
| 281 | + |
|
| 282 | + return apply_filters( 'wpinv_report_subscription_columns', $columns ); |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * Retrieve the current page number |
|
| 287 | + * |
|
| 288 | + * @access private |
|
| 289 | + * @since 1.0.0 |
|
| 290 | + * @return int |
|
| 291 | + */ |
|
| 292 | + function get_paged() { |
|
| 293 | + return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * Retrieve the subscription counts |
|
| 298 | + * |
|
| 299 | + * @access public |
|
| 300 | + * @since 1.4 |
|
| 301 | + * @return void |
|
| 302 | + */ |
|
| 303 | + public function get_subscription_counts() { |
|
| 304 | + |
|
| 305 | + global $wp_query; |
|
| 306 | + |
|
| 307 | + $db = new WPInv_Subscriptions_DB; |
|
| 308 | + |
|
| 309 | + $search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : ''; |
|
| 310 | + |
|
| 311 | + $this->total_count = $db->count(); |
|
| 312 | + $this->active_count = $db->count( array( 'status' => 'active', 'search' => $search ) ); |
|
| 313 | + $this->pending_count = $db->count( array( 'status' => 'pending', 'search' => $search ) ); |
|
| 314 | + $this->expired_count = $db->count( array( 'status' => 'expired', 'search' => $search ) ); |
|
| 315 | + $this->trialling_count = $db->count( array( 'status' => 'trialling', 'search' => $search ) ); |
|
| 316 | + $this->cancelled_count = $db->count( array( 'status' => 'cancelled', 'search' => $search ) ); |
|
| 317 | + $this->completed_count = $db->count( array( 'status' => 'completed', 'search' => $search ) ); |
|
| 318 | + $this->failing_count = $db->count( array( 'status' => 'failing', 'search' => $search ) ); |
|
| 319 | + |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + /** |
|
| 323 | + * Setup the final data for the table |
|
| 324 | + * |
|
| 325 | + * @access private |
|
| 326 | + * @since 1.0.0 |
|
| 327 | + * @uses $this->_column_headers |
|
| 328 | + * @uses $this->items |
|
| 329 | + * @uses $this->get_columns() |
|
| 330 | + * @uses $this->get_sortable_columns() |
|
| 331 | + * @uses $this->get_pagenum() |
|
| 332 | + * @uses $this->set_pagination_args() |
|
| 333 | + * @return array |
|
| 334 | + */ |
|
| 335 | + function prepare_items() { |
|
| 336 | + |
|
| 337 | + $columns = $this->get_columns(); |
|
| 338 | + $hidden = array(); // No hidden columns |
|
| 339 | + $status = isset( $_GET['status'] ) ? $_GET['status'] : 'any'; |
|
| 340 | + $sortable = $this->get_sortable_columns(); |
|
| 341 | + |
|
| 342 | + $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
| 343 | + |
|
| 344 | + $current_page = $this->get_pagenum(); |
|
| 345 | + |
|
| 346 | + $db = new WPInv_Subscriptions_DB; |
|
| 347 | + $search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : ''; |
|
| 348 | + $args = array( |
|
| 349 | + 'number' => $this->per_page, |
|
| 350 | + 'offset' => $this->per_page * ( $this->get_paged() - 1 ), |
|
| 351 | + 'search' => $search |
|
| 352 | + ); |
|
| 353 | + |
|
| 354 | + if ( 'any' !== $status ) { |
|
| 355 | + $args['status'] = $status; |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + $this->items = $db->get_subscriptions( $args ); |
|
| 359 | + |
|
| 360 | + switch ( $status ) { |
|
| 361 | + case 'active': |
|
| 362 | + $total_items = $this->active_count; |
|
| 363 | + break; |
|
| 364 | + case 'pending': |
|
| 365 | + $total_items = $this->pending_count; |
|
| 366 | + break; |
|
| 367 | + case 'expired': |
|
| 368 | + $total_items = $this->expired_count; |
|
| 369 | + break; |
|
| 370 | + case 'cancelled': |
|
| 371 | + $total_items = $this->cancelled_count; |
|
| 372 | + break; |
|
| 373 | + case 'failing': |
|
| 374 | + $total_items = $this->failing_count; |
|
| 375 | + break; |
|
| 376 | + case 'trialling': |
|
| 377 | + $total_items = $this->trialling_count; |
|
| 378 | + break; |
|
| 379 | + case 'completed': |
|
| 380 | + $total_items = $this->completed_count; |
|
| 381 | + break; |
|
| 382 | + case 'any': |
|
| 383 | + default: |
|
| 384 | + $total_items = $this->total_count; |
|
| 385 | + break; |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + $this->set_pagination_args( array( |
|
| 389 | + 'total_items' => $total_items, |
|
| 390 | + 'per_page' => $this->per_page, |
|
| 391 | + 'total_pages' => ceil( $total_items / $this->per_page ) |
|
| 392 | + ) ); |
|
| 393 | + } |
|
| 394 | 394 | } |
@@ -8,11 +8,11 @@ discard block |
||
| 8 | 8 | |
| 9 | 9 | |
| 10 | 10 | // Exit if accessed directly |
| 11 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 11 | +if (!defined('ABSPATH')) exit; |
|
| 12 | 12 | |
| 13 | 13 | |
| 14 | 14 | // Load WP_List_Table if not loaded |
| 15 | -if( ! class_exists( 'WP_List_Table' ) ) { |
|
| 15 | +if (!class_exists('WP_List_Table')) { |
|
| 16 | 16 | require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
| 17 | 17 | } |
| 18 | 18 | |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | public $pending_count = 0; |
| 36 | 36 | public $expired_count = 0; |
| 37 | 37 | public $completed_count = 0; |
| 38 | - public $trialling_count = 0; |
|
| 38 | + public $trialling_count = 0; |
|
| 39 | 39 | public $cancelled_count = 0; |
| 40 | 40 | public $failing_count = 0; |
| 41 | 41 | |
@@ -46,15 +46,15 @@ discard block |
||
| 46 | 46 | * @since 1.0.0 |
| 47 | 47 | * @return void |
| 48 | 48 | */ |
| 49 | - function __construct(){ |
|
| 49 | + function __construct() { |
|
| 50 | 50 | global $status, $page; |
| 51 | 51 | |
| 52 | 52 | // Set parent defaults |
| 53 | - parent::__construct( array( |
|
| 53 | + parent::__construct(array( |
|
| 54 | 54 | 'singular' => 'subscription', |
| 55 | 55 | 'plural' => 'subscriptions', |
| 56 | 56 | 'ajax' => false |
| 57 | - ) ); |
|
| 57 | + )); |
|
| 58 | 58 | |
| 59 | 59 | $this->get_subscription_counts(); |
| 60 | 60 | |
@@ -69,28 +69,28 @@ discard block |
||
| 69 | 69 | */ |
| 70 | 70 | public function get_views() { |
| 71 | 71 | |
| 72 | - $current = isset( $_GET['status'] ) ? $_GET['status'] : ''; |
|
| 73 | - $total_count = ' <span class="count">(' . $this->total_count . ')</span>'; |
|
| 72 | + $current = isset($_GET['status']) ? $_GET['status'] : ''; |
|
| 73 | + $total_count = ' <span class="count">(' . $this->total_count . ')</span>'; |
|
| 74 | 74 | $active_count = ' <span class="count">(' . $this->active_count . ')</span>'; |
| 75 | 75 | $pending_count = ' <span class="count">(' . $this->pending_count . ')</span>'; |
| 76 | - $expired_count = ' <span class="count">(' . $this->expired_count . ')</span>'; |
|
| 76 | + $expired_count = ' <span class="count">(' . $this->expired_count . ')</span>'; |
|
| 77 | 77 | $completed_count = ' <span class="count">(' . $this->completed_count . ')</span>'; |
| 78 | - $trialling_count = ' <span class="count">(' . $this->trialling_count . ')</span>'; |
|
| 79 | - $cancelled_count = ' <span class="count">(' . $this->cancelled_count . ')</span>'; |
|
| 80 | - $failing_count = ' <span class="count">(' . $this->failing_count . ')</span>'; |
|
| 78 | + $trialling_count = ' <span class="count">(' . $this->trialling_count . ')</span>'; |
|
| 79 | + $cancelled_count = ' <span class="count">(' . $this->cancelled_count . ')</span>'; |
|
| 80 | + $failing_count = ' <span class="count">(' . $this->failing_count . ')</span>'; |
|
| 81 | 81 | |
| 82 | 82 | $views = array( |
| 83 | - 'all' => sprintf( '<a href="%s"%s>%s</a>', remove_query_arg( array( 'status', 'paged' ) ), $current === 'all' || $current == '' ? ' class="current"' : '', __('All','invoicing' ) . $total_count ), |
|
| 84 | - 'active' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'active', 'paged' => FALSE ) ), $current === 'active' ? ' class="current"' : '', __('Active','invoicing' ) . $active_count ), |
|
| 85 | - 'pending' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'pending', 'paged' => FALSE ) ), $current === 'pending' ? ' class="current"' : '', __('Pending','invoicing' ) . $pending_count ), |
|
| 86 | - 'expired' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'expired', 'paged' => FALSE ) ), $current === 'expired' ? ' class="current"' : '', __('Expired','invoicing' ) . $expired_count ), |
|
| 87 | - 'completed' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'completed', 'paged' => FALSE ) ), $current === 'completed' ? ' class="current"' : '', __('Completed','invoicing' ) . $completed_count ), |
|
| 88 | - 'trialling' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'trialling', 'paged' => FALSE ) ), $current === 'trialling' ? ' class="current"' : '', __('Trialling','invoicing' ) . $trialling_count ), |
|
| 89 | - 'cancelled' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'cancelled', 'paged' => FALSE ) ), $current === 'cancelled' ? ' class="current"' : '', __('Cancelled','invoicing' ) . $cancelled_count ), |
|
| 90 | - 'failing' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'failing', 'paged' => FALSE ) ), $current === 'failing' ? ' class="current"' : '', __('Failing','invoicing' ) . $failing_count ), |
|
| 83 | + 'all' => sprintf('<a href="%s"%s>%s</a>', remove_query_arg(array('status', 'paged')), $current === 'all' || $current == '' ? ' class="current"' : '', __('All', 'invoicing') . $total_count), |
|
| 84 | + 'active' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'active', 'paged' => FALSE)), $current === 'active' ? ' class="current"' : '', __('Active', 'invoicing') . $active_count), |
|
| 85 | + 'pending' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'pending', 'paged' => FALSE)), $current === 'pending' ? ' class="current"' : '', __('Pending', 'invoicing') . $pending_count), |
|
| 86 | + 'expired' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'expired', 'paged' => FALSE)), $current === 'expired' ? ' class="current"' : '', __('Expired', 'invoicing') . $expired_count), |
|
| 87 | + 'completed' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'completed', 'paged' => FALSE)), $current === 'completed' ? ' class="current"' : '', __('Completed', 'invoicing') . $completed_count), |
|
| 88 | + 'trialling' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'trialling', 'paged' => FALSE)), $current === 'trialling' ? ' class="current"' : '', __('Trialling', 'invoicing') . $trialling_count), |
|
| 89 | + 'cancelled' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'cancelled', 'paged' => FALSE)), $current === 'cancelled' ? ' class="current"' : '', __('Cancelled', 'invoicing') . $cancelled_count), |
|
| 90 | + 'failing' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'failing', 'paged' => FALSE)), $current === 'failing' ? ' class="current"' : '', __('Failing', 'invoicing') . $failing_count), |
|
| 91 | 91 | ); |
| 92 | 92 | |
| 93 | - return apply_filters( 'wpinv_recurring_subscriptions_table_views', $views ); |
|
| 93 | + return apply_filters('wpinv_recurring_subscriptions_table_views', $views); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
@@ -104,27 +104,27 @@ discard block |
||
| 104 | 104 | * |
| 105 | 105 | * @return void |
| 106 | 106 | */ |
| 107 | - public function search_box( $text, $input_id ) { |
|
| 107 | + public function search_box($text, $input_id) { |
|
| 108 | 108 | |
| 109 | - if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) { |
|
| 109 | + if (empty($_REQUEST['s']) && !$this->has_items()) { |
|
| 110 | 110 | return; |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | $input_id = $input_id . '-search-input'; |
| 114 | 114 | |
| 115 | - if ( ! empty( $_REQUEST['orderby'] ) ) { |
|
| 116 | - echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />'; |
|
| 115 | + if (!empty($_REQUEST['orderby'])) { |
|
| 116 | + echo '<input type="hidden" name="orderby" value="' . esc_attr($_REQUEST['orderby']) . '" />'; |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - if ( ! empty( $_REQUEST['order'] ) ) { |
|
| 120 | - echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />'; |
|
| 119 | + if (!empty($_REQUEST['order'])) { |
|
| 120 | + echo '<input type="hidden" name="order" value="' . esc_attr($_REQUEST['order']) . '" />'; |
|
| 121 | 121 | } |
| 122 | 122 | ?> |
| 123 | 123 | <p class="search-box"> |
| 124 | - <?php do_action( 'wpinv_recurring_subscription_search_box' ); ?> |
|
| 124 | + <?php do_action('wpinv_recurring_subscription_search_box'); ?> |
|
| 125 | 125 | <label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label> |
| 126 | 126 | <input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>" /> |
| 127 | - <?php submit_button( $text, 'button', false, false, array('ID' => 'search-submit') ); ?><br/> |
|
| 127 | + <?php submit_button($text, 'button', false, false, array('ID' => 'search-submit')); ?><br/> |
|
| 128 | 128 | </p> |
| 129 | 129 | <?php |
| 130 | 130 | } |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | * @since 1.0.0 |
| 137 | 137 | * @return string |
| 138 | 138 | */ |
| 139 | - function column_default( $item, $column_name ) { |
|
| 139 | + function column_default($item, $column_name) { |
|
| 140 | 140 | return $item->$column_name; |
| 141 | 141 | } |
| 142 | 142 | |
@@ -147,8 +147,8 @@ discard block |
||
| 147 | 147 | * @since 1.0.0 |
| 148 | 148 | * @return string |
| 149 | 149 | */ |
| 150 | - function column_sub_id( $item ) { |
|
| 151 | - return '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $item->id ) ) . '" target="_blank">' . $item->id . '</a>'; |
|
| 150 | + function column_sub_id($item) { |
|
| 151 | + return '<a href="' . esc_url(admin_url('admin.php?page=wpinv-subscriptions&id=' . $item->id)) . '" target="_blank">' . $item->id . '</a>'; |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
@@ -158,11 +158,11 @@ discard block |
||
| 158 | 158 | * @since 1.0.0 |
| 159 | 159 | * @return string |
| 160 | 160 | */ |
| 161 | - function column_customer_id( $item ) { |
|
| 162 | - $subscriber = get_userdata( $item->customer_id ); |
|
| 163 | - $customer = ! empty( $subscriber->display_name ) ? $subscriber->display_name : $subscriber->user_email; |
|
| 161 | + function column_customer_id($item) { |
|
| 162 | + $subscriber = get_userdata($item->customer_id); |
|
| 163 | + $customer = !empty($subscriber->display_name) ? $subscriber->display_name : $subscriber->user_email; |
|
| 164 | 164 | |
| 165 | - return '<a href="' . esc_url( get_edit_user_link( $item->customer_id ) ) . '" target="_blank">' . $customer . '</a>'; |
|
| 165 | + return '<a href="' . esc_url(get_edit_user_link($item->customer_id)) . '" target="_blank">' . $customer . '</a>'; |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | /** |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | * @since 1.0.0 |
| 173 | 173 | * @return string |
| 174 | 174 | */ |
| 175 | - function column_status( $item ) { |
|
| 175 | + function column_status($item) { |
|
| 176 | 176 | return $item->get_status_label(); |
| 177 | 177 | } |
| 178 | 178 | |
@@ -183,11 +183,11 @@ discard block |
||
| 183 | 183 | * @since 1.0.0 |
| 184 | 184 | * @return string |
| 185 | 185 | */ |
| 186 | - function column_period( $item ) { |
|
| 186 | + function column_period($item) { |
|
| 187 | 187 | |
| 188 | - $period = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->period,$item->frequency ); |
|
| 188 | + $period = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($item->period, $item->frequency); |
|
| 189 | 189 | |
| 190 | - return wpinv_price( wpinv_format_amount( $item->recurring_amount ), wpinv_get_invoice_currency_code( $item->parent_payment_id ) ) . ' / ' . $period; |
|
| 190 | + return wpinv_price(wpinv_format_amount($item->recurring_amount), wpinv_get_invoice_currency_code($item->parent_payment_id)) . ' / ' . $period; |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | /** |
@@ -197,8 +197,8 @@ discard block |
||
| 197 | 197 | * @since 1.0.0 |
| 198 | 198 | * @return string |
| 199 | 199 | */ |
| 200 | - function column_bill_times( $item ) { |
|
| 201 | - return $item->get_times_billed() . ' / ' . ( ( $item->bill_times == 0 ) ? __( 'Until Cancelled', 'invoicing' ) : $item->bill_times ); |
|
| 200 | + function column_bill_times($item) { |
|
| 201 | + return $item->get_times_billed() . ' / ' . (($item->bill_times == 0) ? __('Until Cancelled', 'invoicing') : $item->bill_times); |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | /** |
@@ -208,8 +208,8 @@ discard block |
||
| 208 | 208 | * @since 1.0.0 |
| 209 | 209 | * @return string |
| 210 | 210 | */ |
| 211 | - function column_initial_amount( $item ) { |
|
| 212 | - return wpinv_price( wpinv_format_amount( $item->initial_amount ), wpinv_get_invoice_currency_code( $item->parent_payment_id ) ); |
|
| 211 | + function column_initial_amount($item) { |
|
| 212 | + return wpinv_price(wpinv_format_amount($item->initial_amount), wpinv_get_invoice_currency_code($item->parent_payment_id)); |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | /** |
@@ -219,8 +219,8 @@ discard block |
||
| 219 | 219 | * @since 1.0.0 |
| 220 | 220 | * @return string |
| 221 | 221 | */ |
| 222 | - function column_renewal_date( $item ) { |
|
| 223 | - return $renewal_date = ! empty( $item->expiration ) ? date_i18n( get_option( 'date_format' ), strtotime( $item->expiration ) ) : __( 'N/A', 'invoicing' ); |
|
| 222 | + function column_renewal_date($item) { |
|
| 223 | + return $renewal_date = !empty($item->expiration) ? date_i18n(get_option('date_format'), strtotime($item->expiration)) : __('N/A', 'invoicing'); |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | /** |
@@ -230,8 +230,8 @@ discard block |
||
| 230 | 230 | * @since 1.0.0 |
| 231 | 231 | * @return string |
| 232 | 232 | */ |
| 233 | - function column_parent_payment_id( $item ) { |
|
| 234 | - return '<a href="' . get_edit_post_link( $item->parent_payment_id ) . '" target="_blank">' . wpinv_get_invoice_number( $item->parent_payment_id ) . '</a>'; |
|
| 233 | + function column_parent_payment_id($item) { |
|
| 234 | + return '<a href="' . get_edit_post_link($item->parent_payment_id) . '" target="_blank">' . wpinv_get_invoice_number($item->parent_payment_id) . '</a>'; |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** |
@@ -241,8 +241,8 @@ discard block |
||
| 241 | 241 | * @since 1.0.0 |
| 242 | 242 | * @return string |
| 243 | 243 | */ |
| 244 | - function column_product_id( $item ) { |
|
| 245 | - return '<a href="' . esc_url( admin_url( 'post.php?action=edit&post=' . $item->product_id ) ) . '" target="_blank">' . get_the_title( $item->product_id ) . '</a>'; |
|
| 244 | + function column_product_id($item) { |
|
| 245 | + return '<a href="' . esc_url(admin_url('post.php?action=edit&post=' . $item->product_id)) . '" target="_blank">' . get_the_title($item->product_id) . '</a>'; |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | /** |
@@ -252,8 +252,8 @@ discard block |
||
| 252 | 252 | * @since 2.0 |
| 253 | 253 | * @return string |
| 254 | 254 | */ |
| 255 | - function column_actions( $item ) { |
|
| 256 | - return '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $item->id ) ) . '" title="' . esc_attr( __( 'View or edit subscription', 'invoicing' ) ) . '" target="_blank">' . __( 'View', 'invoicing' ) . '</a>'; |
|
| 255 | + function column_actions($item) { |
|
| 256 | + return '<a href="' . esc_url(admin_url('admin.php?page=wpinv-subscriptions&id=' . $item->id)) . '" title="' . esc_attr(__('View or edit subscription', 'invoicing')) . '" target="_blank">' . __('View', 'invoicing') . '</a>'; |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | |
@@ -265,21 +265,21 @@ discard block |
||
| 265 | 265 | * @return array |
| 266 | 266 | */ |
| 267 | 267 | |
| 268 | - function get_columns(){ |
|
| 268 | + function get_columns() { |
|
| 269 | 269 | $columns = array( |
| 270 | - 'sub_id' => __( 'ID', 'invoicing' ), |
|
| 271 | - 'customer_id' => __( 'Customer', 'invoicing' ), |
|
| 272 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 273 | - 'period' => __( 'Billing Cycle', 'invoicing' ), |
|
| 274 | - 'initial_amount' => __( 'Initial Amount', 'invoicing' ), |
|
| 275 | - 'bill_times' => __( 'Times Billed', 'invoicing' ), |
|
| 276 | - 'renewal_date' => __( 'Renewal Date', 'invoicing' ), |
|
| 277 | - 'parent_payment_id' => __( 'Invoice', 'invoicing' ), |
|
| 278 | - 'product_id' => __( 'Item', 'invoicing' ), |
|
| 279 | - 'actions' => __( 'Actions', 'invoicing' ), |
|
| 270 | + 'sub_id' => __('ID', 'invoicing'), |
|
| 271 | + 'customer_id' => __('Customer', 'invoicing'), |
|
| 272 | + 'status' => __('Status', 'invoicing'), |
|
| 273 | + 'period' => __('Billing Cycle', 'invoicing'), |
|
| 274 | + 'initial_amount' => __('Initial Amount', 'invoicing'), |
|
| 275 | + 'bill_times' => __('Times Billed', 'invoicing'), |
|
| 276 | + 'renewal_date' => __('Renewal Date', 'invoicing'), |
|
| 277 | + 'parent_payment_id' => __('Invoice', 'invoicing'), |
|
| 278 | + 'product_id' => __('Item', 'invoicing'), |
|
| 279 | + 'actions' => __('Actions', 'invoicing'), |
|
| 280 | 280 | ); |
| 281 | 281 | |
| 282 | - return apply_filters( 'wpinv_report_subscription_columns', $columns ); |
|
| 282 | + return apply_filters('wpinv_report_subscription_columns', $columns); |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | /** |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | * @return int |
| 291 | 291 | */ |
| 292 | 292 | function get_paged() { |
| 293 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
| 293 | + return isset($_GET['paged']) ? absint($_GET['paged']) : 1; |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | /** |
@@ -306,16 +306,16 @@ discard block |
||
| 306 | 306 | |
| 307 | 307 | $db = new WPInv_Subscriptions_DB; |
| 308 | 308 | |
| 309 | - $search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : ''; |
|
| 309 | + $search = !empty($_GET['s']) ? sanitize_text_field($_GET['s']) : ''; |
|
| 310 | 310 | |
| 311 | 311 | $this->total_count = $db->count(); |
| 312 | - $this->active_count = $db->count( array( 'status' => 'active', 'search' => $search ) ); |
|
| 313 | - $this->pending_count = $db->count( array( 'status' => 'pending', 'search' => $search ) ); |
|
| 314 | - $this->expired_count = $db->count( array( 'status' => 'expired', 'search' => $search ) ); |
|
| 315 | - $this->trialling_count = $db->count( array( 'status' => 'trialling', 'search' => $search ) ); |
|
| 316 | - $this->cancelled_count = $db->count( array( 'status' => 'cancelled', 'search' => $search ) ); |
|
| 317 | - $this->completed_count = $db->count( array( 'status' => 'completed', 'search' => $search ) ); |
|
| 318 | - $this->failing_count = $db->count( array( 'status' => 'failing', 'search' => $search ) ); |
|
| 312 | + $this->active_count = $db->count(array('status' => 'active', 'search' => $search)); |
|
| 313 | + $this->pending_count = $db->count(array('status' => 'pending', 'search' => $search)); |
|
| 314 | + $this->expired_count = $db->count(array('status' => 'expired', 'search' => $search)); |
|
| 315 | + $this->trialling_count = $db->count(array('status' => 'trialling', 'search' => $search)); |
|
| 316 | + $this->cancelled_count = $db->count(array('status' => 'cancelled', 'search' => $search)); |
|
| 317 | + $this->completed_count = $db->count(array('status' => 'completed', 'search' => $search)); |
|
| 318 | + $this->failing_count = $db->count(array('status' => 'failing', 'search' => $search)); |
|
| 319 | 319 | |
| 320 | 320 | } |
| 321 | 321 | |
@@ -336,28 +336,28 @@ discard block |
||
| 336 | 336 | |
| 337 | 337 | $columns = $this->get_columns(); |
| 338 | 338 | $hidden = array(); // No hidden columns |
| 339 | - $status = isset( $_GET['status'] ) ? $_GET['status'] : 'any'; |
|
| 339 | + $status = isset($_GET['status']) ? $_GET['status'] : 'any'; |
|
| 340 | 340 | $sortable = $this->get_sortable_columns(); |
| 341 | 341 | |
| 342 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
| 342 | + $this->_column_headers = array($columns, $hidden, $sortable); |
|
| 343 | 343 | |
| 344 | 344 | $current_page = $this->get_pagenum(); |
| 345 | 345 | |
| 346 | 346 | $db = new WPInv_Subscriptions_DB; |
| 347 | - $search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : ''; |
|
| 347 | + $search = !empty($_GET['s']) ? sanitize_text_field($_GET['s']) : ''; |
|
| 348 | 348 | $args = array( |
| 349 | 349 | 'number' => $this->per_page, |
| 350 | - 'offset' => $this->per_page * ( $this->get_paged() - 1 ), |
|
| 350 | + 'offset' => $this->per_page * ($this->get_paged() - 1), |
|
| 351 | 351 | 'search' => $search |
| 352 | 352 | ); |
| 353 | 353 | |
| 354 | - if ( 'any' !== $status ) { |
|
| 354 | + if ('any' !== $status) { |
|
| 355 | 355 | $args['status'] = $status; |
| 356 | 356 | } |
| 357 | 357 | |
| 358 | - $this->items = $db->get_subscriptions( $args ); |
|
| 358 | + $this->items = $db->get_subscriptions($args); |
|
| 359 | 359 | |
| 360 | - switch ( $status ) { |
|
| 360 | + switch ($status) { |
|
| 361 | 361 | case 'active': |
| 362 | 362 | $total_items = $this->active_count; |
| 363 | 363 | break; |
@@ -385,10 +385,10 @@ discard block |
||
| 385 | 385 | break; |
| 386 | 386 | } |
| 387 | 387 | |
| 388 | - $this->set_pagination_args( array( |
|
| 388 | + $this->set_pagination_args(array( |
|
| 389 | 389 | 'total_items' => $total_items, |
| 390 | 390 | 'per_page' => $this->per_page, |
| 391 | - 'total_pages' => ceil( $total_items / $this->per_page ) |
|
| 392 | - ) ); |
|
| 391 | + 'total_pages' => ceil($total_items / $this->per_page) |
|
| 392 | + )); |
|
| 393 | 393 | } |
| 394 | 394 | } |
@@ -2,7 +2,7 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | // Exit if accessed directly |
| 4 | 4 | if ( ! defined( 'ABSPATH' ) ) { |
| 5 | - exit; |
|
| 5 | + exit; |
|
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | |
@@ -13,187 +13,187 @@ discard block |
||
| 13 | 13 | */ |
| 14 | 14 | class WPInv_Subscription { |
| 15 | 15 | |
| 16 | - private $subs_db; |
|
| 16 | + private $subs_db; |
|
| 17 | + |
|
| 18 | + public $id = 0; |
|
| 19 | + public $customer_id = 0; |
|
| 20 | + public $period = ''; |
|
| 21 | + public $initial_amount = ''; |
|
| 22 | + public $recurring_amount = ''; |
|
| 23 | + public $bill_times = 0; |
|
| 24 | + public $transaction_id = ''; |
|
| 25 | + public $parent_payment_id = 0; |
|
| 26 | + public $product_id = 0; |
|
| 27 | + public $created = '0000-00-00 00:00:00'; |
|
| 28 | + public $expiration = '0000-00-00 00:00:00'; |
|
| 29 | + public $trial_period = ''; |
|
| 30 | + public $status = 'pending'; |
|
| 31 | + public $profile_id = ''; |
|
| 32 | + public $gateway = ''; |
|
| 33 | + public $customer; |
|
| 17 | 34 | |
| 18 | - public $id = 0; |
|
| 19 | - public $customer_id = 0; |
|
| 20 | - public $period = ''; |
|
| 21 | - public $initial_amount = ''; |
|
| 22 | - public $recurring_amount = ''; |
|
| 23 | - public $bill_times = 0; |
|
| 24 | - public $transaction_id = ''; |
|
| 25 | - public $parent_payment_id = 0; |
|
| 26 | - public $product_id = 0; |
|
| 27 | - public $created = '0000-00-00 00:00:00'; |
|
| 28 | - public $expiration = '0000-00-00 00:00:00'; |
|
| 29 | - public $trial_period = ''; |
|
| 30 | - public $status = 'pending'; |
|
| 31 | - public $profile_id = ''; |
|
| 32 | - public $gateway = ''; |
|
| 33 | - public $customer; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * Get us started |
|
| 37 | - * |
|
| 38 | - * @since 1.0.0 |
|
| 39 | - * @return void |
|
| 40 | - */ |
|
| 41 | - function __construct( $_id_or_object = 0, $_by_profile_id = false ) { |
|
| 35 | + /** |
|
| 36 | + * Get us started |
|
| 37 | + * |
|
| 38 | + * @since 1.0.0 |
|
| 39 | + * @return void |
|
| 40 | + */ |
|
| 41 | + function __construct( $_id_or_object = 0, $_by_profile_id = false ) { |
|
| 42 | 42 | |
| 43 | - $this->subs_db = new WPInv_Subscriptions_DB; |
|
| 43 | + $this->subs_db = new WPInv_Subscriptions_DB; |
|
| 44 | 44 | |
| 45 | - if( $_by_profile_id ) { |
|
| 45 | + if( $_by_profile_id ) { |
|
| 46 | 46 | |
| 47 | - $_sub = $this->subs_db->get_by( 'profile_id', $_id_or_object ); |
|
| 47 | + $_sub = $this->subs_db->get_by( 'profile_id', $_id_or_object ); |
|
| 48 | 48 | |
| 49 | - if( empty( $_sub ) ) { |
|
| 50 | - return false; |
|
| 51 | - } |
|
| 49 | + if( empty( $_sub ) ) { |
|
| 50 | + return false; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - $_id_or_object = $_sub; |
|
| 53 | + $_id_or_object = $_sub; |
|
| 54 | 54 | |
| 55 | - } |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - return $this->setup_subscription( $_id_or_object ); |
|
| 58 | - } |
|
| 57 | + return $this->setup_subscription( $_id_or_object ); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Setup the subscription object |
|
| 62 | - * |
|
| 63 | - * @since 1.0.0 |
|
| 64 | - * @return void |
|
| 65 | - */ |
|
| 66 | - private function setup_subscription( $id_or_object = 0 ) { |
|
| 60 | + /** |
|
| 61 | + * Setup the subscription object |
|
| 62 | + * |
|
| 63 | + * @since 1.0.0 |
|
| 64 | + * @return void |
|
| 65 | + */ |
|
| 66 | + private function setup_subscription( $id_or_object = 0 ) { |
|
| 67 | 67 | |
| 68 | - if( empty( $id_or_object ) ) { |
|
| 69 | - return false; |
|
| 70 | - } |
|
| 68 | + if( empty( $id_or_object ) ) { |
|
| 69 | + return false; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - if( is_numeric( $id_or_object ) ) { |
|
| 72 | + if( is_numeric( $id_or_object ) ) { |
|
| 73 | 73 | |
| 74 | - $sub = $this->subs_db->get( $id_or_object ); |
|
| 74 | + $sub = $this->subs_db->get( $id_or_object ); |
|
| 75 | 75 | |
| 76 | - } elseif( is_object( $id_or_object ) ) { |
|
| 76 | + } elseif( is_object( $id_or_object ) ) { |
|
| 77 | 77 | |
| 78 | - $sub = $id_or_object; |
|
| 78 | + $sub = $id_or_object; |
|
| 79 | 79 | |
| 80 | - } |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - if( empty( $sub ) ) { |
|
| 83 | - return false; |
|
| 84 | - } |
|
| 82 | + if( empty( $sub ) ) { |
|
| 83 | + return false; |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - foreach( $sub as $key => $value ) { |
|
| 87 | - $this->$key = $value; |
|
| 88 | - } |
|
| 86 | + foreach( $sub as $key => $value ) { |
|
| 87 | + $this->$key = $value; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - $this->customer = get_userdata( $this->customer_id ); |
|
| 91 | - $this->gateway = wpinv_get_payment_gateway( $this->parent_payment_id ); |
|
| 90 | + $this->customer = get_userdata( $this->customer_id ); |
|
| 91 | + $this->gateway = wpinv_get_payment_gateway( $this->parent_payment_id ); |
|
| 92 | 92 | |
| 93 | - do_action( 'wpinv_recurring_setup_subscription', $this ); |
|
| 93 | + do_action( 'wpinv_recurring_setup_subscription', $this ); |
|
| 94 | 94 | |
| 95 | - return $this; |
|
| 96 | - } |
|
| 95 | + return $this; |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * Magic __get function to dispatch a call to retrieve a private property |
|
| 100 | - * |
|
| 101 | - * @since 1.0.0 |
|
| 102 | - */ |
|
| 103 | - public function __get( $key ) { |
|
| 98 | + /** |
|
| 99 | + * Magic __get function to dispatch a call to retrieve a private property |
|
| 100 | + * |
|
| 101 | + * @since 1.0.0 |
|
| 102 | + */ |
|
| 103 | + public function __get( $key ) { |
|
| 104 | 104 | |
| 105 | - if( method_exists( $this, 'get_' . $key ) ) { |
|
| 105 | + if( method_exists( $this, 'get_' . $key ) ) { |
|
| 106 | 106 | |
| 107 | - return call_user_func( array( $this, 'get_' . $key ) ); |
|
| 107 | + return call_user_func( array( $this, 'get_' . $key ) ); |
|
| 108 | 108 | |
| 109 | - } else { |
|
| 109 | + } else { |
|
| 110 | 110 | |
| 111 | - return new WP_Error( 'wpinv-subscription-invalid-property', sprintf( __( 'Can\'t get property %s', 'invoicing' ), $key ) ); |
|
| 111 | + return new WP_Error( 'wpinv-subscription-invalid-property', sprintf( __( 'Can\'t get property %s', 'invoicing' ), $key ) ); |
|
| 112 | 112 | |
| 113 | - } |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - } |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * Creates a subscription |
|
| 119 | - * |
|
| 120 | - * @since 1.0.0 |
|
| 121 | - * @param array $data Array of attributes for a subscription |
|
| 122 | - * @return mixed false if data isn't passed and class not instantiated for creation |
|
| 123 | - */ |
|
| 124 | - public function create( $data = array() ) { |
|
| 117 | + /** |
|
| 118 | + * Creates a subscription |
|
| 119 | + * |
|
| 120 | + * @since 1.0.0 |
|
| 121 | + * @param array $data Array of attributes for a subscription |
|
| 122 | + * @return mixed false if data isn't passed and class not instantiated for creation |
|
| 123 | + */ |
|
| 124 | + public function create( $data = array() ) { |
|
| 125 | 125 | |
| 126 | - if ( $this->id != 0 ) { |
|
| 127 | - return false; |
|
| 128 | - } |
|
| 126 | + if ( $this->id != 0 ) { |
|
| 127 | + return false; |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - $defaults = array( |
|
| 131 | - 'customer_id' => 0, |
|
| 132 | - 'frequency' => '', |
|
| 133 | - 'period' => '', |
|
| 134 | - 'initial_amount' => '', |
|
| 135 | - 'recurring_amount' => '', |
|
| 136 | - 'bill_times' => 0, |
|
| 137 | - 'parent_payment_id' => 0, |
|
| 138 | - 'product_id' => 0, |
|
| 139 | - 'created' => '', |
|
| 140 | - 'expiration' => '', |
|
| 141 | - 'status' => '', |
|
| 142 | - 'profile_id' => '', |
|
| 143 | - ); |
|
| 130 | + $defaults = array( |
|
| 131 | + 'customer_id' => 0, |
|
| 132 | + 'frequency' => '', |
|
| 133 | + 'period' => '', |
|
| 134 | + 'initial_amount' => '', |
|
| 135 | + 'recurring_amount' => '', |
|
| 136 | + 'bill_times' => 0, |
|
| 137 | + 'parent_payment_id' => 0, |
|
| 138 | + 'product_id' => 0, |
|
| 139 | + 'created' => '', |
|
| 140 | + 'expiration' => '', |
|
| 141 | + 'status' => '', |
|
| 142 | + 'profile_id' => '', |
|
| 143 | + ); |
|
| 144 | 144 | |
| 145 | - $args = wp_parse_args( $data, $defaults ); |
|
| 145 | + $args = wp_parse_args( $data, $defaults ); |
|
| 146 | 146 | |
| 147 | - if( $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) { |
|
| 147 | + if( $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) { |
|
| 148 | 148 | |
| 149 | - if( 'active' == $args['status'] || 'trialling' == $args['status'] ) { |
|
| 149 | + if( 'active' == $args['status'] || 'trialling' == $args['status'] ) { |
|
| 150 | 150 | |
| 151 | - // Force an active subscription to expired if expiration date is in the past |
|
| 152 | - $args['status'] = 'expired'; |
|
| 151 | + // Force an active subscription to expired if expiration date is in the past |
|
| 152 | + $args['status'] = 'expired'; |
|
| 153 | 153 | |
| 154 | - } |
|
| 155 | - } |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | 156 | |
| 157 | - do_action( 'wpinv_subscription_pre_create', $args ); |
|
| 157 | + do_action( 'wpinv_subscription_pre_create', $args ); |
|
| 158 | 158 | |
| 159 | - $id = $this->subs_db->insert( $args, 'subscription' ); |
|
| 159 | + $id = $this->subs_db->insert( $args, 'subscription' ); |
|
| 160 | 160 | |
| 161 | - do_action( 'wpinv_subscription_post_create', $id, $args ); |
|
| 161 | + do_action( 'wpinv_subscription_post_create', $id, $args ); |
|
| 162 | 162 | |
| 163 | - return $this->setup_subscription( $id ); |
|
| 163 | + return $this->setup_subscription( $id ); |
|
| 164 | 164 | |
| 165 | - } |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - /** |
|
| 168 | - * Updates a subscription |
|
| 169 | - * |
|
| 170 | - * @since 1.0.0 |
|
| 171 | - * @param array $args Array of fields to update |
|
| 172 | - * @return bool |
|
| 173 | - */ |
|
| 174 | - public function update( $args = array() ) { |
|
| 167 | + /** |
|
| 168 | + * Updates a subscription |
|
| 169 | + * |
|
| 170 | + * @since 1.0.0 |
|
| 171 | + * @param array $args Array of fields to update |
|
| 172 | + * @return bool |
|
| 173 | + */ |
|
| 174 | + public function update( $args = array() ) { |
|
| 175 | 175 | |
| 176 | - $ret = $this->subs_db->update( $this->id, $args ); |
|
| 176 | + $ret = $this->subs_db->update( $this->id, $args ); |
|
| 177 | 177 | |
| 178 | - do_action( 'wpinv_recurring_update_subscription', $this->id, $args, $this ); |
|
| 178 | + do_action( 'wpinv_recurring_update_subscription', $this->id, $args, $this ); |
|
| 179 | 179 | |
| 180 | - if ( $ret && isset( $args['profile_id'] ) ) { |
|
| 181 | - update_post_meta( $this->parent_payment_id, 'subscription_id', $args['profile_id'] ); |
|
| 182 | - } |
|
| 180 | + if ( $ret && isset( $args['profile_id'] ) ) { |
|
| 181 | + update_post_meta( $this->parent_payment_id, 'subscription_id', $args['profile_id'] ); |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - return $ret; |
|
| 184 | + return $ret; |
|
| 185 | 185 | |
| 186 | - } |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | - /** |
|
| 189 | - * Delete the subscription |
|
| 190 | - * |
|
| 191 | - * @since 1.0.0 |
|
| 192 | - * @return bool |
|
| 193 | - */ |
|
| 194 | - public function delete() { |
|
| 195 | - return $this->subs_db->delete( $this->id ); |
|
| 196 | - } |
|
| 188 | + /** |
|
| 189 | + * Delete the subscription |
|
| 190 | + * |
|
| 191 | + * @since 1.0.0 |
|
| 192 | + * @return bool |
|
| 193 | + */ |
|
| 194 | + public function delete() { |
|
| 195 | + return $this->subs_db->delete( $this->id ); |
|
| 196 | + } |
|
| 197 | 197 | |
| 198 | 198 | /** |
| 199 | 199 | * Retrieves the parent payment ID |
@@ -262,57 +262,57 @@ discard block |
||
| 262 | 262 | * |
| 263 | 263 | * @since 2.4 |
| 264 | 264 | * @param array $args Array of values for the payment, including amount and transaction ID |
| 265 | - * @param WPInv_Invoice $invoice |
|
| 265 | + * @param WPInv_Invoice $invoice |
|
| 266 | 266 | * @return bool |
| 267 | 267 | */ |
| 268 | 268 | public function add_payment( $args = array(), $invoice = false ) { |
| 269 | 269 | |
| 270 | - // Process each payment once. |
|
| 270 | + // Process each payment once. |
|
| 271 | 271 | if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) { |
| 272 | 272 | return false; |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | - // Are we creating a new invoice? |
|
| 276 | - if ( empty( $invoice ) ) { |
|
| 277 | - $invoice = $this->create_payment(); |
|
| 275 | + // Are we creating a new invoice? |
|
| 276 | + if ( empty( $invoice ) ) { |
|
| 277 | + $invoice = $this->create_payment(); |
|
| 278 | 278 | |
| 279 | - if ( empty( $invoice ) ) { |
|
| 280 | - return false; |
|
| 281 | - } |
|
| 279 | + if ( empty( $invoice ) ) { |
|
| 280 | + return false; |
|
| 281 | + } |
|
| 282 | 282 | |
| 283 | - $invoice->set_status( 'wpi-renewal' ); |
|
| 283 | + $invoice->set_status( 'wpi-renewal' ); |
|
| 284 | 284 | |
| 285 | - } |
|
| 285 | + } |
|
| 286 | 286 | |
| 287 | - // Maybe set a transaction id. |
|
| 288 | - if ( ! empty( $args['transaction_id'] ) ) { |
|
| 289 | - $invoice->set_transaction_id( $args['transaction_id'] ); |
|
| 290 | - } |
|
| 287 | + // Maybe set a transaction id. |
|
| 288 | + if ( ! empty( $args['transaction_id'] ) ) { |
|
| 289 | + $invoice->set_transaction_id( $args['transaction_id'] ); |
|
| 290 | + } |
|
| 291 | 291 | |
| 292 | - // Set the completed date. |
|
| 293 | - $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
| 292 | + // Set the completed date. |
|
| 293 | + $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
| 294 | 294 | |
| 295 | - // And the gateway. |
|
| 296 | - if ( ! empty( $args['gateway'] ) ) { |
|
| 297 | - $invoice->set_gateway( $args['gateway'] ); |
|
| 298 | - } |
|
| 295 | + // And the gateway. |
|
| 296 | + if ( ! empty( $args['gateway'] ) ) { |
|
| 297 | + $invoice->set_gateway( $args['gateway'] ); |
|
| 298 | + } |
|
| 299 | 299 | |
| 300 | - $invoice->save(); |
|
| 300 | + $invoice->save(); |
|
| 301 | 301 | |
| 302 | - if ( ! $invoice->get_id() ) { |
|
| 303 | - return 0; |
|
| 304 | - } |
|
| 302 | + if ( ! $invoice->get_id() ) { |
|
| 303 | + return 0; |
|
| 304 | + } |
|
| 305 | 305 | |
| 306 | - do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
| 307 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
| 306 | + do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
| 307 | + do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
| 308 | 308 | do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->parent_payment_id, $invoice->get_recurring_total(), $invoice->get_transaction_id() ); |
| 309 | 309 | |
| 310 | 310 | update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id ); |
| 311 | 311 | |
| 312 | 312 | return $invoice->get_id(); |
| 313 | - } |
|
| 313 | + } |
|
| 314 | 314 | |
| 315 | - /** |
|
| 315 | + /** |
|
| 316 | 316 | * Creates a new invoice and returns it. |
| 317 | 317 | * |
| 318 | 318 | * @since 1.0.19 |
@@ -321,196 +321,196 @@ discard block |
||
| 321 | 321 | */ |
| 322 | 322 | public function create_payment() { |
| 323 | 323 | |
| 324 | - // Do we have a parent invoice? |
|
| 324 | + // Do we have a parent invoice? |
|
| 325 | 325 | if ( ! $this->parent_payment_id ) { |
| 326 | 326 | return false; |
| 327 | 327 | } |
| 328 | 328 | |
| 329 | - // Ensure that the parent invoice is available. |
|
| 329 | + // Ensure that the parent invoice is available. |
|
| 330 | 330 | $parent_invoice = wpinv_get_invoice( $this->parent_payment_id ); |
| 331 | 331 | if ( empty( $parent_invoice ) ) { |
| 332 | 332 | return false; |
| 333 | 333 | } |
| 334 | 334 | |
| 335 | - // Duplicate the parent invoice. |
|
| 336 | - $invoice = new WPInv_Invoice(); |
|
| 337 | - $invoice->set_props( $parent_invoice->get_data() ); |
|
| 338 | - $invoice->set_id( 0 ); |
|
| 339 | - $invoice->set_parent_id( $parent_invoice->get_parent() ); |
|
| 340 | - $invoice->set_transaction_id( '' ); |
|
| 341 | - $invoice->set_key( $invoice->generate_key( 'renewal_' ) ); |
|
| 342 | - $invoice->set_number( '' ); |
|
| 343 | - $invoice->set_completed_date( '' ); |
|
| 344 | - $invoice->set_status( 'wpi-pending' ); |
|
| 345 | - $invoice->recalculate_total(); |
|
| 346 | - $invoice->save(); |
|
| 347 | - |
|
| 348 | - return $invoice->get_id() ? $invoice : false; |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - /** |
|
| 352 | - * Retrieves the transaction ID from the subscription |
|
| 353 | - * |
|
| 354 | - * @since 1.0.0 |
|
| 355 | - * @return bool |
|
| 356 | - */ |
|
| 357 | - public function get_transaction_id() { |
|
| 358 | - |
|
| 359 | - if( empty( $this->transaction_id ) ) { |
|
| 360 | - |
|
| 361 | - $txn_id = wpinv_get_payment_transaction_id( $this->parent_payment_id ); |
|
| 362 | - |
|
| 363 | - if( ! empty( $txn_id ) && (int) $this->parent_payment_id !== (int) $txn_id ) { |
|
| 364 | - $this->set_transaction_id( $txn_id ); |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - return $this->transaction_id; |
|
| 370 | - |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - /** |
|
| 374 | - * Stores the transaction ID for the subscription purchase |
|
| 375 | - * |
|
| 376 | - * @since 1.0.0.4 |
|
| 377 | - * @return bool |
|
| 378 | - */ |
|
| 379 | - public function set_transaction_id( $txn_id = '' ) { |
|
| 380 | - $this->update( array( 'transaction_id' => $txn_id ) ); |
|
| 381 | - $this->transaction_id = $txn_id; |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * Renews a subscription |
|
| 386 | - * |
|
| 387 | - * @since 1.0.0 |
|
| 388 | - * @return bool |
|
| 389 | - */ |
|
| 390 | - public function renew() { |
|
| 391 | - |
|
| 392 | - // Calculate new expiration |
|
| 393 | - $expires = $this->get_expiration_time(); |
|
| 394 | - $base_date = $expires > current_time( 'timestamp' ) ? $expires : current_time( 'timestamp' ); |
|
| 395 | - $frequency = isset( $this->frequency ) ? $this->frequency : 1; |
|
| 396 | - $new_expiration = strtotime( "+ {$frequency} {$this->period}", strtotime( $base_date ) ); |
|
| 397 | - $new_expiration = apply_filters( 'wpinv_subscription_renewal_expiration', date( 'Y-m-d H:i:s', $new_expiration ), $this->id, $this ); |
|
| 398 | - |
|
| 399 | - do_action( 'wpinv_subscription_pre_renew', $this->id, $new_expiration, $this ); |
|
| 400 | - |
|
| 401 | - $this->status = 'active'; |
|
| 402 | - $times_billed = $this->get_times_billed(); |
|
| 403 | - |
|
| 404 | - // Complete subscription if applicable |
|
| 405 | - if ( $this->bill_times > 0 && $times_billed >= $this->bill_times ) { |
|
| 406 | - $this->complete(); |
|
| 407 | - $this->status = 'completed'; |
|
| 408 | - return; |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - $args = array( |
|
| 412 | - 'expiration' => $new_expiration, |
|
| 413 | - 'status' => $this->status, |
|
| 414 | - ); |
|
| 335 | + // Duplicate the parent invoice. |
|
| 336 | + $invoice = new WPInv_Invoice(); |
|
| 337 | + $invoice->set_props( $parent_invoice->get_data() ); |
|
| 338 | + $invoice->set_id( 0 ); |
|
| 339 | + $invoice->set_parent_id( $parent_invoice->get_parent() ); |
|
| 340 | + $invoice->set_transaction_id( '' ); |
|
| 341 | + $invoice->set_key( $invoice->generate_key( 'renewal_' ) ); |
|
| 342 | + $invoice->set_number( '' ); |
|
| 343 | + $invoice->set_completed_date( '' ); |
|
| 344 | + $invoice->set_status( 'wpi-pending' ); |
|
| 345 | + $invoice->recalculate_total(); |
|
| 346 | + $invoice->save(); |
|
| 347 | + |
|
| 348 | + return $invoice->get_id() ? $invoice : false; |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + /** |
|
| 352 | + * Retrieves the transaction ID from the subscription |
|
| 353 | + * |
|
| 354 | + * @since 1.0.0 |
|
| 355 | + * @return bool |
|
| 356 | + */ |
|
| 357 | + public function get_transaction_id() { |
|
| 358 | + |
|
| 359 | + if( empty( $this->transaction_id ) ) { |
|
| 360 | + |
|
| 361 | + $txn_id = wpinv_get_payment_transaction_id( $this->parent_payment_id ); |
|
| 362 | + |
|
| 363 | + if( ! empty( $txn_id ) && (int) $this->parent_payment_id !== (int) $txn_id ) { |
|
| 364 | + $this->set_transaction_id( $txn_id ); |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + return $this->transaction_id; |
|
| 370 | + |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + /** |
|
| 374 | + * Stores the transaction ID for the subscription purchase |
|
| 375 | + * |
|
| 376 | + * @since 1.0.0.4 |
|
| 377 | + * @return bool |
|
| 378 | + */ |
|
| 379 | + public function set_transaction_id( $txn_id = '' ) { |
|
| 380 | + $this->update( array( 'transaction_id' => $txn_id ) ); |
|
| 381 | + $this->transaction_id = $txn_id; |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * Renews a subscription |
|
| 386 | + * |
|
| 387 | + * @since 1.0.0 |
|
| 388 | + * @return bool |
|
| 389 | + */ |
|
| 390 | + public function renew() { |
|
| 391 | + |
|
| 392 | + // Calculate new expiration |
|
| 393 | + $expires = $this->get_expiration_time(); |
|
| 394 | + $base_date = $expires > current_time( 'timestamp' ) ? $expires : current_time( 'timestamp' ); |
|
| 395 | + $frequency = isset( $this->frequency ) ? $this->frequency : 1; |
|
| 396 | + $new_expiration = strtotime( "+ {$frequency} {$this->period}", strtotime( $base_date ) ); |
|
| 397 | + $new_expiration = apply_filters( 'wpinv_subscription_renewal_expiration', date( 'Y-m-d H:i:s', $new_expiration ), $this->id, $this ); |
|
| 398 | + |
|
| 399 | + do_action( 'wpinv_subscription_pre_renew', $this->id, $new_expiration, $this ); |
|
| 400 | + |
|
| 401 | + $this->status = 'active'; |
|
| 402 | + $times_billed = $this->get_times_billed(); |
|
| 403 | + |
|
| 404 | + // Complete subscription if applicable |
|
| 405 | + if ( $this->bill_times > 0 && $times_billed >= $this->bill_times ) { |
|
| 406 | + $this->complete(); |
|
| 407 | + $this->status = 'completed'; |
|
| 408 | + return; |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + $args = array( |
|
| 412 | + 'expiration' => $new_expiration, |
|
| 413 | + 'status' => $this->status, |
|
| 414 | + ); |
|
| 415 | 415 | |
| 416 | 416 | $this->subs_db->update( $this->id, $args ); |
| 417 | 417 | |
| 418 | - $this->expiration = $new_expiration; |
|
| 418 | + $this->expiration = $new_expiration; |
|
| 419 | 419 | |
| 420 | - do_action( 'wpinv_subscription_post_renew', $this->id, $new_expiration, $this ); |
|
| 421 | - do_action( 'wpinv_recurring_set_subscription_status', $this->id, $this->status, $this ); |
|
| 420 | + do_action( 'wpinv_subscription_post_renew', $this->id, $new_expiration, $this ); |
|
| 421 | + do_action( 'wpinv_recurring_set_subscription_status', $this->id, $this->status, $this ); |
|
| 422 | 422 | |
| 423 | - } |
|
| 423 | + } |
|
| 424 | 424 | |
| 425 | - /** |
|
| 426 | - * Marks a subscription as completed |
|
| 427 | - * |
|
| 428 | - * Subscription is completed when the number of payments matches the billing_times field |
|
| 429 | - * |
|
| 430 | - * @since 1.0.0 |
|
| 431 | - * @return void |
|
| 432 | - */ |
|
| 433 | - public function complete() { |
|
| 425 | + /** |
|
| 426 | + * Marks a subscription as completed |
|
| 427 | + * |
|
| 428 | + * Subscription is completed when the number of payments matches the billing_times field |
|
| 429 | + * |
|
| 430 | + * @since 1.0.0 |
|
| 431 | + * @return void |
|
| 432 | + */ |
|
| 433 | + public function complete() { |
|
| 434 | 434 | |
| 435 | - // Only mark a subscription as complete if it's not already cancelled. |
|
| 436 | - if ( 'cancelled' === $this->status ) { |
|
| 437 | - return; |
|
| 438 | - } |
|
| 435 | + // Only mark a subscription as complete if it's not already cancelled. |
|
| 436 | + if ( 'cancelled' === $this->status ) { |
|
| 437 | + return; |
|
| 438 | + } |
|
| 439 | 439 | |
| 440 | - $args = array( |
|
| 441 | - 'status' => 'completed' |
|
| 442 | - ); |
|
| 440 | + $args = array( |
|
| 441 | + 'status' => 'completed' |
|
| 442 | + ); |
|
| 443 | 443 | |
| 444 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
| 444 | + if( $this->subs_db->update( $this->id, $args ) ) { |
|
| 445 | 445 | |
| 446 | - $this->status = 'completed'; |
|
| 446 | + $this->status = 'completed'; |
|
| 447 | 447 | |
| 448 | - do_action( 'wpinv_subscription_completed', $this->id, $this ); |
|
| 448 | + do_action( 'wpinv_subscription_completed', $this->id, $this ); |
|
| 449 | 449 | |
| 450 | - } |
|
| 450 | + } |
|
| 451 | 451 | |
| 452 | - } |
|
| 452 | + } |
|
| 453 | 453 | |
| 454 | - /** |
|
| 455 | - * Marks a subscription as expired |
|
| 456 | - * |
|
| 457 | - * Subscription is completed when the billing times is reached |
|
| 458 | - * |
|
| 459 | - * @since 1.0.0 |
|
| 460 | - * @param $check_expiration bool True if expiration date should be checked with merchant processor before expiring |
|
| 461 | - * @return void |
|
| 462 | - */ |
|
| 463 | - public function expire( $check_expiration = false ) { |
|
| 454 | + /** |
|
| 455 | + * Marks a subscription as expired |
|
| 456 | + * |
|
| 457 | + * Subscription is completed when the billing times is reached |
|
| 458 | + * |
|
| 459 | + * @since 1.0.0 |
|
| 460 | + * @param $check_expiration bool True if expiration date should be checked with merchant processor before expiring |
|
| 461 | + * @return void |
|
| 462 | + */ |
|
| 463 | + public function expire( $check_expiration = false ) { |
|
| 464 | 464 | |
| 465 | - $expiration = $this->expiration; |
|
| 465 | + $expiration = $this->expiration; |
|
| 466 | 466 | |
| 467 | - if( $check_expiration ) { |
|
| 467 | + if( $check_expiration ) { |
|
| 468 | 468 | |
| 469 | - // check_expiration() updates $this->expiration so compare to $expiration above |
|
| 469 | + // check_expiration() updates $this->expiration so compare to $expiration above |
|
| 470 | 470 | |
| 471 | - if( $expiration < $this->get_expiration() && current_time( 'timestamp' ) < $this->get_expiration_time() ) { |
|
| 471 | + if( $expiration < $this->get_expiration() && current_time( 'timestamp' ) < $this->get_expiration_time() ) { |
|
| 472 | 472 | |
| 473 | - return false; // Do not mark as expired since real expiration date is in the future |
|
| 474 | - } |
|
| 473 | + return false; // Do not mark as expired since real expiration date is in the future |
|
| 474 | + } |
|
| 475 | 475 | |
| 476 | - } |
|
| 476 | + } |
|
| 477 | 477 | |
| 478 | - $args = array( |
|
| 479 | - 'status' => 'expired' |
|
| 480 | - ); |
|
| 478 | + $args = array( |
|
| 479 | + 'status' => 'expired' |
|
| 480 | + ); |
|
| 481 | 481 | |
| 482 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
| 482 | + if( $this->subs_db->update( $this->id, $args ) ) { |
|
| 483 | 483 | |
| 484 | - $this->status = 'expired'; |
|
| 484 | + $this->status = 'expired'; |
|
| 485 | 485 | |
| 486 | - do_action( 'wpinv_subscription_expired', $this->id, $this ); |
|
| 486 | + do_action( 'wpinv_subscription_expired', $this->id, $this ); |
|
| 487 | 487 | |
| 488 | - } |
|
| 488 | + } |
|
| 489 | 489 | |
| 490 | - } |
|
| 490 | + } |
|
| 491 | 491 | |
| 492 | - /** |
|
| 493 | - * Marks a subscription as failing |
|
| 494 | - * |
|
| 495 | - * @since 2.4.2 |
|
| 496 | - * @return void |
|
| 497 | - */ |
|
| 498 | - public function failing() { |
|
| 492 | + /** |
|
| 493 | + * Marks a subscription as failing |
|
| 494 | + * |
|
| 495 | + * @since 2.4.2 |
|
| 496 | + * @return void |
|
| 497 | + */ |
|
| 498 | + public function failing() { |
|
| 499 | 499 | |
| 500 | - $args = array( |
|
| 501 | - 'status' => 'failing' |
|
| 502 | - ); |
|
| 500 | + $args = array( |
|
| 501 | + 'status' => 'failing' |
|
| 502 | + ); |
|
| 503 | 503 | |
| 504 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
| 504 | + if( $this->subs_db->update( $this->id, $args ) ) { |
|
| 505 | 505 | |
| 506 | - $this->status = 'failing'; |
|
| 506 | + $this->status = 'failing'; |
|
| 507 | 507 | |
| 508 | - do_action( 'wpinv_subscription_failing', $this->id, $this ); |
|
| 509 | - do_action( 'wpinv_recurring_payment_failed', $this ); |
|
| 508 | + do_action( 'wpinv_subscription_failing', $this->id, $this ); |
|
| 509 | + do_action( 'wpinv_recurring_payment_failed', $this ); |
|
| 510 | 510 | |
| 511 | - } |
|
| 511 | + } |
|
| 512 | 512 | |
| 513 | - } |
|
| 513 | + } |
|
| 514 | 514 | |
| 515 | 515 | /** |
| 516 | 516 | * Marks a subscription as cancelled |
@@ -544,22 +544,22 @@ discard block |
||
| 544 | 544 | } |
| 545 | 545 | } |
| 546 | 546 | |
| 547 | - /** |
|
| 548 | - * Determines if subscription can be cancelled |
|
| 549 | - * |
|
| 550 | - * This method is filtered by payment gateways in order to return true on subscriptions |
|
| 551 | - * that can be cancelled with a profile ID through the merchant processor |
|
| 552 | - * |
|
| 553 | - * @since 1.0.0 |
|
| 554 | - * @return bool |
|
| 555 | - */ |
|
| 556 | - public function can_cancel() { |
|
| 547 | + /** |
|
| 548 | + * Determines if subscription can be cancelled |
|
| 549 | + * |
|
| 550 | + * This method is filtered by payment gateways in order to return true on subscriptions |
|
| 551 | + * that can be cancelled with a profile ID through the merchant processor |
|
| 552 | + * |
|
| 553 | + * @since 1.0.0 |
|
| 554 | + * @return bool |
|
| 555 | + */ |
|
| 556 | + public function can_cancel() { |
|
| 557 | 557 | $ret = false; |
| 558 | - if( $this->gateway === 'manual' || in_array( $this->status, $this->get_cancellable_statuses() ) ) { |
|
| 558 | + if( $this->gateway === 'manual' || in_array( $this->status, $this->get_cancellable_statuses() ) ) { |
|
| 559 | 559 | $ret = true; |
| 560 | 560 | } |
| 561 | - return apply_filters( 'wpinv_subscription_can_cancel', $ret, $this ); |
|
| 562 | - } |
|
| 561 | + return apply_filters( 'wpinv_subscription_can_cancel', $ret, $this ); |
|
| 562 | + } |
|
| 563 | 563 | |
| 564 | 564 | /** |
| 565 | 565 | * Returns an array of subscription statuses that can be cancelled |
@@ -572,197 +572,197 @@ discard block |
||
| 572 | 572 | return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) ); |
| 573 | 573 | } |
| 574 | 574 | |
| 575 | - /** |
|
| 576 | - * Retrieves the URL to cancel subscription |
|
| 577 | - * |
|
| 578 | - * @since 1.0.0 |
|
| 579 | - * @return string |
|
| 580 | - */ |
|
| 581 | - public function get_cancel_url() { |
|
| 575 | + /** |
|
| 576 | + * Retrieves the URL to cancel subscription |
|
| 577 | + * |
|
| 578 | + * @since 1.0.0 |
|
| 579 | + * @return string |
|
| 580 | + */ |
|
| 581 | + public function get_cancel_url() { |
|
| 582 | 582 | |
| 583 | - $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'cancel_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-cancel' ); |
|
| 583 | + $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'cancel_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-cancel' ); |
|
| 584 | 584 | |
| 585 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
| 586 | - } |
|
| 585 | + return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
| 586 | + } |
|
| 587 | 587 | |
| 588 | - /** |
|
| 589 | - * Determines if subscription can be manually renewed |
|
| 590 | - * |
|
| 591 | - * This method is filtered by payment gateways in order to return true on subscriptions |
|
| 592 | - * that can be renewed manually |
|
| 593 | - * |
|
| 594 | - * @since 2.5 |
|
| 595 | - * @return bool |
|
| 596 | - */ |
|
| 597 | - public function can_renew() { |
|
| 588 | + /** |
|
| 589 | + * Determines if subscription can be manually renewed |
|
| 590 | + * |
|
| 591 | + * This method is filtered by payment gateways in order to return true on subscriptions |
|
| 592 | + * that can be renewed manually |
|
| 593 | + * |
|
| 594 | + * @since 2.5 |
|
| 595 | + * @return bool |
|
| 596 | + */ |
|
| 597 | + public function can_renew() { |
|
| 598 | 598 | |
| 599 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - /** |
|
| 603 | - * Retrieves the URL to renew a subscription |
|
| 604 | - * |
|
| 605 | - * @since 2.5 |
|
| 606 | - * @return string |
|
| 607 | - */ |
|
| 608 | - public function get_renew_url() { |
|
| 609 | - |
|
| 610 | - $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'renew_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-renew' ); |
|
| 611 | - |
|
| 612 | - return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
| 613 | - } |
|
| 614 | - |
|
| 615 | - /** |
|
| 616 | - * Determines if subscription can have their payment method updated |
|
| 617 | - * |
|
| 618 | - * @since 1.0.0 |
|
| 619 | - * @return bool |
|
| 620 | - */ |
|
| 621 | - public function can_update() { |
|
| 622 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - /** |
|
| 626 | - * Retrieves the URL to update subscription |
|
| 627 | - * |
|
| 628 | - * @since 1.0.0 |
|
| 629 | - * @return void |
|
| 630 | - */ |
|
| 631 | - public function get_update_url() { |
|
| 632 | - |
|
| 633 | - $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->id ) ); |
|
| 634 | - |
|
| 635 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - /** |
|
| 639 | - * Determines if subscription is active |
|
| 640 | - * |
|
| 641 | - * @since 1.0.0 |
|
| 642 | - * @return void |
|
| 643 | - */ |
|
| 644 | - public function is_active() { |
|
| 645 | - |
|
| 646 | - $ret = false; |
|
| 647 | - |
|
| 648 | - if( ! $this->is_expired() && ( $this->status == 'active' || $this->status == 'cancelled' || $this->status == 'trialling' ) ) { |
|
| 649 | - $ret = true; |
|
| 650 | - } |
|
| 651 | - |
|
| 652 | - return apply_filters( 'wpinv_subscription_is_active', $ret, $this->id, $this ); |
|
| 653 | - |
|
| 654 | - } |
|
| 655 | - |
|
| 656 | - /** |
|
| 657 | - * Determines if subscription is expired |
|
| 658 | - * |
|
| 659 | - * @since 1.0.0 |
|
| 660 | - * @return void |
|
| 661 | - */ |
|
| 662 | - public function is_expired() { |
|
| 663 | - |
|
| 664 | - $ret = false; |
|
| 665 | - |
|
| 666 | - if ( $this->status == 'expired' ) { |
|
| 667 | - |
|
| 668 | - $ret = true; |
|
| 669 | - |
|
| 670 | - } elseif( 'active' === $this->status || 'cancelled' === $this->status || $this->status == 'trialling' ) { |
|
| 671 | - |
|
| 672 | - $ret = false; |
|
| 673 | - $expiration = $this->get_expiration_time(); |
|
| 674 | - |
|
| 675 | - if( $expiration && strtotime( 'NOW', current_time( 'timestamp' ) ) > $expiration ) { |
|
| 676 | - $ret = true; |
|
| 677 | - |
|
| 678 | - if ( 'active' === $this->status || $this->status == 'trialling' ) { |
|
| 679 | - $this->expire(); |
|
| 680 | - } |
|
| 681 | - } |
|
| 682 | - |
|
| 683 | - } |
|
| 684 | - |
|
| 685 | - return apply_filters( 'wpinv_subscription_is_expired', $ret, $this->id, $this ); |
|
| 686 | - |
|
| 687 | - } |
|
| 688 | - |
|
| 689 | - /** |
|
| 690 | - * Retrieves the expiration date |
|
| 691 | - * |
|
| 692 | - * @since 1.0.0 |
|
| 693 | - * @return string |
|
| 694 | - */ |
|
| 695 | - public function get_expiration() { |
|
| 696 | - return $this->expiration; |
|
| 697 | - } |
|
| 698 | - |
|
| 699 | - /** |
|
| 700 | - * Retrieves the expiration date in a timestamp |
|
| 701 | - * |
|
| 702 | - * @since 1.0.0 |
|
| 703 | - * @return int |
|
| 704 | - */ |
|
| 705 | - public function get_expiration_time() { |
|
| 706 | - return strtotime( $this->expiration, current_time( 'timestamp' ) ); |
|
| 707 | - } |
|
| 708 | - |
|
| 709 | - /** |
|
| 710 | - * Retrieves the subscription status |
|
| 711 | - * |
|
| 712 | - * @since 1.0.0 |
|
| 713 | - * @return int |
|
| 714 | - */ |
|
| 715 | - public function get_status() { |
|
| 716 | - |
|
| 717 | - // Monitor for page load delays on pages with large subscription lists (IE: Subscriptions table in admin) |
|
| 718 | - $this->is_expired(); |
|
| 719 | - return $this->status; |
|
| 720 | - } |
|
| 721 | - |
|
| 722 | - /** |
|
| 723 | - * Retrieves the subscription status label |
|
| 724 | - * |
|
| 725 | - * @since 1.0.0 |
|
| 726 | - * @return int |
|
| 727 | - */ |
|
| 728 | - public function get_status_label() { |
|
| 599 | + return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
| 600 | + } |
|
| 729 | 601 | |
| 730 | - switch( $this->get_status() ) { |
|
| 731 | - case 'active' : |
|
| 732 | - $status = __( 'Active', 'invoicing' ); |
|
| 733 | - break; |
|
| 602 | + /** |
|
| 603 | + * Retrieves the URL to renew a subscription |
|
| 604 | + * |
|
| 605 | + * @since 2.5 |
|
| 606 | + * @return string |
|
| 607 | + */ |
|
| 608 | + public function get_renew_url() { |
|
| 734 | 609 | |
| 735 | - case 'cancelled' : |
|
| 736 | - $status = __( 'Cancelled', 'invoicing' ); |
|
| 737 | - break; |
|
| 738 | - |
|
| 739 | - case 'expired' : |
|
| 740 | - $status = __( 'Expired', 'invoicing' ); |
|
| 741 | - break; |
|
| 610 | + $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'renew_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-renew' ); |
|
| 742 | 611 | |
| 743 | - case 'pending' : |
|
| 744 | - $status = __( 'Pending', 'invoicing' ); |
|
| 745 | - break; |
|
| 612 | + return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
| 613 | + } |
|
| 614 | + |
|
| 615 | + /** |
|
| 616 | + * Determines if subscription can have their payment method updated |
|
| 617 | + * |
|
| 618 | + * @since 1.0.0 |
|
| 619 | + * @return bool |
|
| 620 | + */ |
|
| 621 | + public function can_update() { |
|
| 622 | + return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
| 623 | + } |
|
| 746 | 624 | |
| 747 | - case 'failing' : |
|
| 748 | - $status = __( 'Failing', 'invoicing' ); |
|
| 749 | - break; |
|
| 625 | + /** |
|
| 626 | + * Retrieves the URL to update subscription |
|
| 627 | + * |
|
| 628 | + * @since 1.0.0 |
|
| 629 | + * @return void |
|
| 630 | + */ |
|
| 631 | + public function get_update_url() { |
|
| 632 | + |
|
| 633 | + $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->id ) ); |
|
| 634 | + |
|
| 635 | + return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + /** |
|
| 639 | + * Determines if subscription is active |
|
| 640 | + * |
|
| 641 | + * @since 1.0.0 |
|
| 642 | + * @return void |
|
| 643 | + */ |
|
| 644 | + public function is_active() { |
|
| 645 | + |
|
| 646 | + $ret = false; |
|
| 647 | + |
|
| 648 | + if( ! $this->is_expired() && ( $this->status == 'active' || $this->status == 'cancelled' || $this->status == 'trialling' ) ) { |
|
| 649 | + $ret = true; |
|
| 650 | + } |
|
| 651 | + |
|
| 652 | + return apply_filters( 'wpinv_subscription_is_active', $ret, $this->id, $this ); |
|
| 653 | + |
|
| 654 | + } |
|
| 655 | + |
|
| 656 | + /** |
|
| 657 | + * Determines if subscription is expired |
|
| 658 | + * |
|
| 659 | + * @since 1.0.0 |
|
| 660 | + * @return void |
|
| 661 | + */ |
|
| 662 | + public function is_expired() { |
|
| 663 | + |
|
| 664 | + $ret = false; |
|
| 665 | + |
|
| 666 | + if ( $this->status == 'expired' ) { |
|
| 667 | + |
|
| 668 | + $ret = true; |
|
| 669 | + |
|
| 670 | + } elseif( 'active' === $this->status || 'cancelled' === $this->status || $this->status == 'trialling' ) { |
|
| 671 | + |
|
| 672 | + $ret = false; |
|
| 673 | + $expiration = $this->get_expiration_time(); |
|
| 674 | + |
|
| 675 | + if( $expiration && strtotime( 'NOW', current_time( 'timestamp' ) ) > $expiration ) { |
|
| 676 | + $ret = true; |
|
| 677 | + |
|
| 678 | + if ( 'active' === $this->status || $this->status == 'trialling' ) { |
|
| 679 | + $this->expire(); |
|
| 680 | + } |
|
| 681 | + } |
|
| 682 | + |
|
| 683 | + } |
|
| 750 | 684 | |
| 751 | - case 'trialling' : |
|
| 752 | - $status = __( 'Trialling', 'invoicing' ); |
|
| 753 | - break; |
|
| 754 | - |
|
| 755 | - case 'completed' : |
|
| 756 | - $status = __( 'Completed', 'invoicing' ); |
|
| 757 | - break; |
|
| 758 | - |
|
| 759 | - default: |
|
| 760 | - $status = ucfirst( $this->get_status() ); |
|
| 761 | - break; |
|
| 762 | - } |
|
| 685 | + return apply_filters( 'wpinv_subscription_is_expired', $ret, $this->id, $this ); |
|
| 763 | 686 | |
| 764 | - return $status; |
|
| 765 | - } |
|
| 687 | + } |
|
| 688 | + |
|
| 689 | + /** |
|
| 690 | + * Retrieves the expiration date |
|
| 691 | + * |
|
| 692 | + * @since 1.0.0 |
|
| 693 | + * @return string |
|
| 694 | + */ |
|
| 695 | + public function get_expiration() { |
|
| 696 | + return $this->expiration; |
|
| 697 | + } |
|
| 698 | + |
|
| 699 | + /** |
|
| 700 | + * Retrieves the expiration date in a timestamp |
|
| 701 | + * |
|
| 702 | + * @since 1.0.0 |
|
| 703 | + * @return int |
|
| 704 | + */ |
|
| 705 | + public function get_expiration_time() { |
|
| 706 | + return strtotime( $this->expiration, current_time( 'timestamp' ) ); |
|
| 707 | + } |
|
| 708 | + |
|
| 709 | + /** |
|
| 710 | + * Retrieves the subscription status |
|
| 711 | + * |
|
| 712 | + * @since 1.0.0 |
|
| 713 | + * @return int |
|
| 714 | + */ |
|
| 715 | + public function get_status() { |
|
| 716 | + |
|
| 717 | + // Monitor for page load delays on pages with large subscription lists (IE: Subscriptions table in admin) |
|
| 718 | + $this->is_expired(); |
|
| 719 | + return $this->status; |
|
| 720 | + } |
|
| 721 | + |
|
| 722 | + /** |
|
| 723 | + * Retrieves the subscription status label |
|
| 724 | + * |
|
| 725 | + * @since 1.0.0 |
|
| 726 | + * @return int |
|
| 727 | + */ |
|
| 728 | + public function get_status_label() { |
|
| 729 | + |
|
| 730 | + switch( $this->get_status() ) { |
|
| 731 | + case 'active' : |
|
| 732 | + $status = __( 'Active', 'invoicing' ); |
|
| 733 | + break; |
|
| 734 | + |
|
| 735 | + case 'cancelled' : |
|
| 736 | + $status = __( 'Cancelled', 'invoicing' ); |
|
| 737 | + break; |
|
| 738 | + |
|
| 739 | + case 'expired' : |
|
| 740 | + $status = __( 'Expired', 'invoicing' ); |
|
| 741 | + break; |
|
| 742 | + |
|
| 743 | + case 'pending' : |
|
| 744 | + $status = __( 'Pending', 'invoicing' ); |
|
| 745 | + break; |
|
| 746 | + |
|
| 747 | + case 'failing' : |
|
| 748 | + $status = __( 'Failing', 'invoicing' ); |
|
| 749 | + break; |
|
| 750 | + |
|
| 751 | + case 'trialling' : |
|
| 752 | + $status = __( 'Trialling', 'invoicing' ); |
|
| 753 | + break; |
|
| 754 | + |
|
| 755 | + case 'completed' : |
|
| 756 | + $status = __( 'Completed', 'invoicing' ); |
|
| 757 | + break; |
|
| 758 | + |
|
| 759 | + default: |
|
| 760 | + $status = ucfirst( $this->get_status() ); |
|
| 761 | + break; |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + return $status; |
|
| 765 | + } |
|
| 766 | 766 | |
| 767 | 767 | /** |
| 768 | 768 | * Retrieves the subscription status label |
@@ -827,7 +827,7 @@ discard block |
||
| 827 | 827 | * @return bool |
| 828 | 828 | */ |
| 829 | 829 | public function payment_exists( $txn_id = '' ) { |
| 830 | - $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
| 830 | + $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
| 831 | 831 | return ! empty( $invoice_id ); |
| 832 | 832 | } |
| 833 | 833 | |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | // Exit if accessed directly |
| 4 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 4 | +if (!defined('ABSPATH')) { |
|
| 5 | 5 | exit; |
| 6 | 6 | } |
| 7 | 7 | |
@@ -38,15 +38,15 @@ discard block |
||
| 38 | 38 | * @since 1.0.0 |
| 39 | 39 | * @return void |
| 40 | 40 | */ |
| 41 | - function __construct( $_id_or_object = 0, $_by_profile_id = false ) { |
|
| 41 | + function __construct($_id_or_object = 0, $_by_profile_id = false) { |
|
| 42 | 42 | |
| 43 | 43 | $this->subs_db = new WPInv_Subscriptions_DB; |
| 44 | 44 | |
| 45 | - if( $_by_profile_id ) { |
|
| 45 | + if ($_by_profile_id) { |
|
| 46 | 46 | |
| 47 | - $_sub = $this->subs_db->get_by( 'profile_id', $_id_or_object ); |
|
| 47 | + $_sub = $this->subs_db->get_by('profile_id', $_id_or_object); |
|
| 48 | 48 | |
| 49 | - if( empty( $_sub ) ) { |
|
| 49 | + if (empty($_sub)) { |
|
| 50 | 50 | return false; |
| 51 | 51 | } |
| 52 | 52 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - return $this->setup_subscription( $_id_or_object ); |
|
| 57 | + return $this->setup_subscription($_id_or_object); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
@@ -63,34 +63,34 @@ discard block |
||
| 63 | 63 | * @since 1.0.0 |
| 64 | 64 | * @return void |
| 65 | 65 | */ |
| 66 | - private function setup_subscription( $id_or_object = 0 ) { |
|
| 66 | + private function setup_subscription($id_or_object = 0) { |
|
| 67 | 67 | |
| 68 | - if( empty( $id_or_object ) ) { |
|
| 68 | + if (empty($id_or_object)) { |
|
| 69 | 69 | return false; |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - if( is_numeric( $id_or_object ) ) { |
|
| 72 | + if (is_numeric($id_or_object)) { |
|
| 73 | 73 | |
| 74 | - $sub = $this->subs_db->get( $id_or_object ); |
|
| 74 | + $sub = $this->subs_db->get($id_or_object); |
|
| 75 | 75 | |
| 76 | - } elseif( is_object( $id_or_object ) ) { |
|
| 76 | + } elseif (is_object($id_or_object)) { |
|
| 77 | 77 | |
| 78 | 78 | $sub = $id_or_object; |
| 79 | 79 | |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - if( empty( $sub ) ) { |
|
| 82 | + if (empty($sub)) { |
|
| 83 | 83 | return false; |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - foreach( $sub as $key => $value ) { |
|
| 86 | + foreach ($sub as $key => $value) { |
|
| 87 | 87 | $this->$key = $value; |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - $this->customer = get_userdata( $this->customer_id ); |
|
| 91 | - $this->gateway = wpinv_get_payment_gateway( $this->parent_payment_id ); |
|
| 90 | + $this->customer = get_userdata($this->customer_id); |
|
| 91 | + $this->gateway = wpinv_get_payment_gateway($this->parent_payment_id); |
|
| 92 | 92 | |
| 93 | - do_action( 'wpinv_recurring_setup_subscription', $this ); |
|
| 93 | + do_action('wpinv_recurring_setup_subscription', $this); |
|
| 94 | 94 | |
| 95 | 95 | return $this; |
| 96 | 96 | } |
@@ -100,15 +100,15 @@ discard block |
||
| 100 | 100 | * |
| 101 | 101 | * @since 1.0.0 |
| 102 | 102 | */ |
| 103 | - public function __get( $key ) { |
|
| 103 | + public function __get($key) { |
|
| 104 | 104 | |
| 105 | - if( method_exists( $this, 'get_' . $key ) ) { |
|
| 105 | + if (method_exists($this, 'get_' . $key)) { |
|
| 106 | 106 | |
| 107 | - return call_user_func( array( $this, 'get_' . $key ) ); |
|
| 107 | + return call_user_func(array($this, 'get_' . $key)); |
|
| 108 | 108 | |
| 109 | 109 | } else { |
| 110 | 110 | |
| 111 | - return new WP_Error( 'wpinv-subscription-invalid-property', sprintf( __( 'Can\'t get property %s', 'invoicing' ), $key ) ); |
|
| 111 | + return new WP_Error('wpinv-subscription-invalid-property', sprintf(__('Can\'t get property %s', 'invoicing'), $key)); |
|
| 112 | 112 | |
| 113 | 113 | } |
| 114 | 114 | |
@@ -121,9 +121,9 @@ discard block |
||
| 121 | 121 | * @param array $data Array of attributes for a subscription |
| 122 | 122 | * @return mixed false if data isn't passed and class not instantiated for creation |
| 123 | 123 | */ |
| 124 | - public function create( $data = array() ) { |
|
| 124 | + public function create($data = array()) { |
|
| 125 | 125 | |
| 126 | - if ( $this->id != 0 ) { |
|
| 126 | + if ($this->id != 0) { |
|
| 127 | 127 | return false; |
| 128 | 128 | } |
| 129 | 129 | |
@@ -142,11 +142,11 @@ discard block |
||
| 142 | 142 | 'profile_id' => '', |
| 143 | 143 | ); |
| 144 | 144 | |
| 145 | - $args = wp_parse_args( $data, $defaults ); |
|
| 145 | + $args = wp_parse_args($data, $defaults); |
|
| 146 | 146 | |
| 147 | - if( $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) { |
|
| 147 | + if ($args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) { |
|
| 148 | 148 | |
| 149 | - if( 'active' == $args['status'] || 'trialling' == $args['status'] ) { |
|
| 149 | + if ('active' == $args['status'] || 'trialling' == $args['status']) { |
|
| 150 | 150 | |
| 151 | 151 | // Force an active subscription to expired if expiration date is in the past |
| 152 | 152 | $args['status'] = 'expired'; |
@@ -154,13 +154,13 @@ discard block |
||
| 154 | 154 | } |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - do_action( 'wpinv_subscription_pre_create', $args ); |
|
| 157 | + do_action('wpinv_subscription_pre_create', $args); |
|
| 158 | 158 | |
| 159 | - $id = $this->subs_db->insert( $args, 'subscription' ); |
|
| 159 | + $id = $this->subs_db->insert($args, 'subscription'); |
|
| 160 | 160 | |
| 161 | - do_action( 'wpinv_subscription_post_create', $id, $args ); |
|
| 161 | + do_action('wpinv_subscription_post_create', $id, $args); |
|
| 162 | 162 | |
| 163 | - return $this->setup_subscription( $id ); |
|
| 163 | + return $this->setup_subscription($id); |
|
| 164 | 164 | |
| 165 | 165 | } |
| 166 | 166 | |
@@ -171,14 +171,14 @@ discard block |
||
| 171 | 171 | * @param array $args Array of fields to update |
| 172 | 172 | * @return bool |
| 173 | 173 | */ |
| 174 | - public function update( $args = array() ) { |
|
| 174 | + public function update($args = array()) { |
|
| 175 | 175 | |
| 176 | - $ret = $this->subs_db->update( $this->id, $args ); |
|
| 176 | + $ret = $this->subs_db->update($this->id, $args); |
|
| 177 | 177 | |
| 178 | - do_action( 'wpinv_recurring_update_subscription', $this->id, $args, $this ); |
|
| 178 | + do_action('wpinv_recurring_update_subscription', $this->id, $args, $this); |
|
| 179 | 179 | |
| 180 | - if ( $ret && isset( $args['profile_id'] ) ) { |
|
| 181 | - update_post_meta( $this->parent_payment_id, 'subscription_id', $args['profile_id'] ); |
|
| 180 | + if ($ret && isset($args['profile_id'])) { |
|
| 181 | + update_post_meta($this->parent_payment_id, 'subscription_id', $args['profile_id']); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | return $ret; |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | * @return bool |
| 193 | 193 | */ |
| 194 | 194 | public function delete() { |
| 195 | - return $this->subs_db->delete( $this->id ); |
|
| 195 | + return $this->subs_db->delete($this->id); |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | /** |
@@ -212,14 +212,14 @@ discard block |
||
| 212 | 212 | * @return array |
| 213 | 213 | */ |
| 214 | 214 | public function get_child_payments() { |
| 215 | - $payments = get_posts( array( |
|
| 215 | + $payments = get_posts(array( |
|
| 216 | 216 | 'post_parent' => (int) $this->parent_payment_id, |
| 217 | 217 | 'posts_per_page' => '999', |
| 218 | - 'post_status' => array( 'publish', 'wpi-processing', 'wpi-renewal' ), |
|
| 218 | + 'post_status' => array('publish', 'wpi-processing', 'wpi-renewal'), |
|
| 219 | 219 | 'orderby' => 'ID', |
| 220 | 220 | 'order' => 'DESC', |
| 221 | 221 | 'post_type' => 'wpi_invoice' |
| 222 | - ) ); |
|
| 222 | + )); |
|
| 223 | 223 | |
| 224 | 224 | return $payments; |
| 225 | 225 | } |
@@ -232,9 +232,9 @@ discard block |
||
| 232 | 232 | */ |
| 233 | 233 | public function get_total_payments() { |
| 234 | 234 | $child_payments = $this->get_child_payments(); |
| 235 | - $total_payments = !empty( $child_payments ) ? count( $child_payments ) : 0; |
|
| 235 | + $total_payments = !empty($child_payments) ? count($child_payments) : 0; |
|
| 236 | 236 | |
| 237 | - if ( 'pending' != $this->status ) { |
|
| 237 | + if ('pending' != $this->status) { |
|
| 238 | 238 | $total_payments++; |
| 239 | 239 | } |
| 240 | 240 | |
@@ -248,9 +248,9 @@ discard block |
||
| 248 | 248 | * @return int |
| 249 | 249 | */ |
| 250 | 250 | public function get_times_billed() { |
| 251 | - $times_billed = (int)$this->get_total_payments(); |
|
| 251 | + $times_billed = (int) $this->get_total_payments(); |
|
| 252 | 252 | |
| 253 | - if ( ! empty( $this->trial_period ) && $times_billed > 0 ) { |
|
| 253 | + if (!empty($this->trial_period) && $times_billed > 0) { |
|
| 254 | 254 | $times_billed--; |
| 255 | 255 | } |
| 256 | 256 | |
@@ -265,49 +265,49 @@ discard block |
||
| 265 | 265 | * @param WPInv_Invoice $invoice |
| 266 | 266 | * @return bool |
| 267 | 267 | */ |
| 268 | - public function add_payment( $args = array(), $invoice = false ) { |
|
| 268 | + public function add_payment($args = array(), $invoice = false) { |
|
| 269 | 269 | |
| 270 | 270 | // Process each payment once. |
| 271 | - if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) { |
|
| 271 | + if (!empty($args['transaction_id']) && $this->payment_exists($args['transaction_id'])) { |
|
| 272 | 272 | return false; |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | // Are we creating a new invoice? |
| 276 | - if ( empty( $invoice ) ) { |
|
| 276 | + if (empty($invoice)) { |
|
| 277 | 277 | $invoice = $this->create_payment(); |
| 278 | 278 | |
| 279 | - if ( empty( $invoice ) ) { |
|
| 279 | + if (empty($invoice)) { |
|
| 280 | 280 | return false; |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | - $invoice->set_status( 'wpi-renewal' ); |
|
| 283 | + $invoice->set_status('wpi-renewal'); |
|
| 284 | 284 | |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | // Maybe set a transaction id. |
| 288 | - if ( ! empty( $args['transaction_id'] ) ) { |
|
| 289 | - $invoice->set_transaction_id( $args['transaction_id'] ); |
|
| 288 | + if (!empty($args['transaction_id'])) { |
|
| 289 | + $invoice->set_transaction_id($args['transaction_id']); |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | // Set the completed date. |
| 293 | - $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
| 293 | + $invoice->set_completed_date(current_time('mysql')); |
|
| 294 | 294 | |
| 295 | 295 | // And the gateway. |
| 296 | - if ( ! empty( $args['gateway'] ) ) { |
|
| 297 | - $invoice->set_gateway( $args['gateway'] ); |
|
| 296 | + if (!empty($args['gateway'])) { |
|
| 297 | + $invoice->set_gateway($args['gateway']); |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | $invoice->save(); |
| 301 | 301 | |
| 302 | - if ( ! $invoice->get_id() ) { |
|
| 302 | + if (!$invoice->get_id()) { |
|
| 303 | 303 | return 0; |
| 304 | 304 | } |
| 305 | 305 | |
| 306 | - do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
| 307 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
| 308 | - do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->parent_payment_id, $invoice->get_recurring_total(), $invoice->get_transaction_id() ); |
|
| 306 | + do_action('getpaid_after_create_subscription_renewal_invoice', $invoice, $this); |
|
| 307 | + do_action('wpinv_recurring_add_subscription_payment', $invoice, $this); |
|
| 308 | + do_action('wpinv_recurring_record_payment', $invoice->get_id(), $this->parent_payment_id, $invoice->get_recurring_total(), $invoice->get_transaction_id()); |
|
| 309 | 309 | |
| 310 | - update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id ); |
|
| 310 | + update_post_meta($invoice->get_id(), '_wpinv_subscription_id', $this->id); |
|
| 311 | 311 | |
| 312 | 312 | return $invoice->get_id(); |
| 313 | 313 | } |
@@ -322,26 +322,26 @@ discard block |
||
| 322 | 322 | public function create_payment() { |
| 323 | 323 | |
| 324 | 324 | // Do we have a parent invoice? |
| 325 | - if ( ! $this->parent_payment_id ) { |
|
| 325 | + if (!$this->parent_payment_id) { |
|
| 326 | 326 | return false; |
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | // Ensure that the parent invoice is available. |
| 330 | - $parent_invoice = wpinv_get_invoice( $this->parent_payment_id ); |
|
| 331 | - if ( empty( $parent_invoice ) ) { |
|
| 330 | + $parent_invoice = wpinv_get_invoice($this->parent_payment_id); |
|
| 331 | + if (empty($parent_invoice)) { |
|
| 332 | 332 | return false; |
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | // Duplicate the parent invoice. |
| 336 | 336 | $invoice = new WPInv_Invoice(); |
| 337 | - $invoice->set_props( $parent_invoice->get_data() ); |
|
| 338 | - $invoice->set_id( 0 ); |
|
| 339 | - $invoice->set_parent_id( $parent_invoice->get_parent() ); |
|
| 340 | - $invoice->set_transaction_id( '' ); |
|
| 341 | - $invoice->set_key( $invoice->generate_key( 'renewal_' ) ); |
|
| 342 | - $invoice->set_number( '' ); |
|
| 343 | - $invoice->set_completed_date( '' ); |
|
| 344 | - $invoice->set_status( 'wpi-pending' ); |
|
| 337 | + $invoice->set_props($parent_invoice->get_data()); |
|
| 338 | + $invoice->set_id(0); |
|
| 339 | + $invoice->set_parent_id($parent_invoice->get_parent()); |
|
| 340 | + $invoice->set_transaction_id(''); |
|
| 341 | + $invoice->set_key($invoice->generate_key('renewal_')); |
|
| 342 | + $invoice->set_number(''); |
|
| 343 | + $invoice->set_completed_date(''); |
|
| 344 | + $invoice->set_status('wpi-pending'); |
|
| 345 | 345 | $invoice->recalculate_total(); |
| 346 | 346 | $invoice->save(); |
| 347 | 347 | |
@@ -356,12 +356,12 @@ discard block |
||
| 356 | 356 | */ |
| 357 | 357 | public function get_transaction_id() { |
| 358 | 358 | |
| 359 | - if( empty( $this->transaction_id ) ) { |
|
| 359 | + if (empty($this->transaction_id)) { |
|
| 360 | 360 | |
| 361 | - $txn_id = wpinv_get_payment_transaction_id( $this->parent_payment_id ); |
|
| 361 | + $txn_id = wpinv_get_payment_transaction_id($this->parent_payment_id); |
|
| 362 | 362 | |
| 363 | - if( ! empty( $txn_id ) && (int) $this->parent_payment_id !== (int) $txn_id ) { |
|
| 364 | - $this->set_transaction_id( $txn_id ); |
|
| 363 | + if (!empty($txn_id) && (int) $this->parent_payment_id !== (int) $txn_id) { |
|
| 364 | + $this->set_transaction_id($txn_id); |
|
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | } |
@@ -376,8 +376,8 @@ discard block |
||
| 376 | 376 | * @since 1.0.0.4 |
| 377 | 377 | * @return bool |
| 378 | 378 | */ |
| 379 | - public function set_transaction_id( $txn_id = '' ) { |
|
| 380 | - $this->update( array( 'transaction_id' => $txn_id ) ); |
|
| 379 | + public function set_transaction_id($txn_id = '') { |
|
| 380 | + $this->update(array('transaction_id' => $txn_id)); |
|
| 381 | 381 | $this->transaction_id = $txn_id; |
| 382 | 382 | } |
| 383 | 383 | |
@@ -391,18 +391,18 @@ discard block |
||
| 391 | 391 | |
| 392 | 392 | // Calculate new expiration |
| 393 | 393 | $expires = $this->get_expiration_time(); |
| 394 | - $base_date = $expires > current_time( 'timestamp' ) ? $expires : current_time( 'timestamp' ); |
|
| 395 | - $frequency = isset( $this->frequency ) ? $this->frequency : 1; |
|
| 396 | - $new_expiration = strtotime( "+ {$frequency} {$this->period}", strtotime( $base_date ) ); |
|
| 397 | - $new_expiration = apply_filters( 'wpinv_subscription_renewal_expiration', date( 'Y-m-d H:i:s', $new_expiration ), $this->id, $this ); |
|
| 394 | + $base_date = $expires > current_time('timestamp') ? $expires : current_time('timestamp'); |
|
| 395 | + $frequency = isset($this->frequency) ? $this->frequency : 1; |
|
| 396 | + $new_expiration = strtotime("+ {$frequency} {$this->period}", strtotime($base_date)); |
|
| 397 | + $new_expiration = apply_filters('wpinv_subscription_renewal_expiration', date('Y-m-d H:i:s', $new_expiration), $this->id, $this); |
|
| 398 | 398 | |
| 399 | - do_action( 'wpinv_subscription_pre_renew', $this->id, $new_expiration, $this ); |
|
| 399 | + do_action('wpinv_subscription_pre_renew', $this->id, $new_expiration, $this); |
|
| 400 | 400 | |
| 401 | 401 | $this->status = 'active'; |
| 402 | 402 | $times_billed = $this->get_times_billed(); |
| 403 | 403 | |
| 404 | 404 | // Complete subscription if applicable |
| 405 | - if ( $this->bill_times > 0 && $times_billed >= $this->bill_times ) { |
|
| 405 | + if ($this->bill_times > 0 && $times_billed >= $this->bill_times) { |
|
| 406 | 406 | $this->complete(); |
| 407 | 407 | $this->status = 'completed'; |
| 408 | 408 | return; |
@@ -413,12 +413,12 @@ discard block |
||
| 413 | 413 | 'status' => $this->status, |
| 414 | 414 | ); |
| 415 | 415 | |
| 416 | - $this->subs_db->update( $this->id, $args ); |
|
| 416 | + $this->subs_db->update($this->id, $args); |
|
| 417 | 417 | |
| 418 | 418 | $this->expiration = $new_expiration; |
| 419 | 419 | |
| 420 | - do_action( 'wpinv_subscription_post_renew', $this->id, $new_expiration, $this ); |
|
| 421 | - do_action( 'wpinv_recurring_set_subscription_status', $this->id, $this->status, $this ); |
|
| 420 | + do_action('wpinv_subscription_post_renew', $this->id, $new_expiration, $this); |
|
| 421 | + do_action('wpinv_recurring_set_subscription_status', $this->id, $this->status, $this); |
|
| 422 | 422 | |
| 423 | 423 | } |
| 424 | 424 | |
@@ -433,7 +433,7 @@ discard block |
||
| 433 | 433 | public function complete() { |
| 434 | 434 | |
| 435 | 435 | // Only mark a subscription as complete if it's not already cancelled. |
| 436 | - if ( 'cancelled' === $this->status ) { |
|
| 436 | + if ('cancelled' === $this->status) { |
|
| 437 | 437 | return; |
| 438 | 438 | } |
| 439 | 439 | |
@@ -441,11 +441,11 @@ discard block |
||
| 441 | 441 | 'status' => 'completed' |
| 442 | 442 | ); |
| 443 | 443 | |
| 444 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
| 444 | + if ($this->subs_db->update($this->id, $args)) { |
|
| 445 | 445 | |
| 446 | 446 | $this->status = 'completed'; |
| 447 | 447 | |
| 448 | - do_action( 'wpinv_subscription_completed', $this->id, $this ); |
|
| 448 | + do_action('wpinv_subscription_completed', $this->id, $this); |
|
| 449 | 449 | |
| 450 | 450 | } |
| 451 | 451 | |
@@ -460,15 +460,15 @@ discard block |
||
| 460 | 460 | * @param $check_expiration bool True if expiration date should be checked with merchant processor before expiring |
| 461 | 461 | * @return void |
| 462 | 462 | */ |
| 463 | - public function expire( $check_expiration = false ) { |
|
| 463 | + public function expire($check_expiration = false) { |
|
| 464 | 464 | |
| 465 | 465 | $expiration = $this->expiration; |
| 466 | 466 | |
| 467 | - if( $check_expiration ) { |
|
| 467 | + if ($check_expiration) { |
|
| 468 | 468 | |
| 469 | 469 | // check_expiration() updates $this->expiration so compare to $expiration above |
| 470 | 470 | |
| 471 | - if( $expiration < $this->get_expiration() && current_time( 'timestamp' ) < $this->get_expiration_time() ) { |
|
| 471 | + if ($expiration < $this->get_expiration() && current_time('timestamp') < $this->get_expiration_time()) { |
|
| 472 | 472 | |
| 473 | 473 | return false; // Do not mark as expired since real expiration date is in the future |
| 474 | 474 | } |
@@ -479,11 +479,11 @@ discard block |
||
| 479 | 479 | 'status' => 'expired' |
| 480 | 480 | ); |
| 481 | 481 | |
| 482 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
| 482 | + if ($this->subs_db->update($this->id, $args)) { |
|
| 483 | 483 | |
| 484 | 484 | $this->status = 'expired'; |
| 485 | 485 | |
| 486 | - do_action( 'wpinv_subscription_expired', $this->id, $this ); |
|
| 486 | + do_action('wpinv_subscription_expired', $this->id, $this); |
|
| 487 | 487 | |
| 488 | 488 | } |
| 489 | 489 | |
@@ -501,12 +501,12 @@ discard block |
||
| 501 | 501 | 'status' => 'failing' |
| 502 | 502 | ); |
| 503 | 503 | |
| 504 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
| 504 | + if ($this->subs_db->update($this->id, $args)) { |
|
| 505 | 505 | |
| 506 | 506 | $this->status = 'failing'; |
| 507 | 507 | |
| 508 | - do_action( 'wpinv_subscription_failing', $this->id, $this ); |
|
| 509 | - do_action( 'wpinv_recurring_payment_failed', $this ); |
|
| 508 | + do_action('wpinv_subscription_failing', $this->id, $this); |
|
| 509 | + do_action('wpinv_recurring_payment_failed', $this); |
|
| 510 | 510 | |
| 511 | 511 | } |
| 512 | 512 | |
@@ -519,7 +519,7 @@ discard block |
||
| 519 | 519 | * @return void |
| 520 | 520 | */ |
| 521 | 521 | public function cancel() { |
| 522 | - if ( 'cancelled' === $this->status ) { |
|
| 522 | + if ('cancelled' === $this->status) { |
|
| 523 | 523 | return; // Already cancelled |
| 524 | 524 | } |
| 525 | 525 | |
@@ -527,20 +527,20 @@ discard block |
||
| 527 | 527 | 'status' => 'cancelled' |
| 528 | 528 | ); |
| 529 | 529 | |
| 530 | - if ( $this->subs_db->update( $this->id, $args ) ) { |
|
| 531 | - if ( is_user_logged_in() ) { |
|
| 532 | - $userdata = get_userdata( get_current_user_id() ); |
|
| 530 | + if ($this->subs_db->update($this->id, $args)) { |
|
| 531 | + if (is_user_logged_in()) { |
|
| 532 | + $userdata = get_userdata(get_current_user_id()); |
|
| 533 | 533 | $user = $userdata->display_name; |
| 534 | 534 | } else { |
| 535 | - $user = __( 'gateway', 'invoicing' ); |
|
| 535 | + $user = __('gateway', 'invoicing'); |
|
| 536 | 536 | } |
| 537 | 537 | |
| 538 | - $note = sprintf( __( 'Subscription has been cancelled by %s', 'invoicing' ), $user ); |
|
| 539 | - wpinv_insert_payment_note( $this->parent_payment_id, $note, '', '', true ); |
|
| 538 | + $note = sprintf(__('Subscription has been cancelled by %s', 'invoicing'), $user); |
|
| 539 | + wpinv_insert_payment_note($this->parent_payment_id, $note, '', '', true); |
|
| 540 | 540 | |
| 541 | 541 | $this->status = 'cancelled'; |
| 542 | 542 | |
| 543 | - do_action( 'wpinv_subscription_cancelled', $this->id, $this ); |
|
| 543 | + do_action('wpinv_subscription_cancelled', $this->id, $this); |
|
| 544 | 544 | } |
| 545 | 545 | } |
| 546 | 546 | |
@@ -555,10 +555,10 @@ discard block |
||
| 555 | 555 | */ |
| 556 | 556 | public function can_cancel() { |
| 557 | 557 | $ret = false; |
| 558 | - if( $this->gateway === 'manual' || in_array( $this->status, $this->get_cancellable_statuses() ) ) { |
|
| 558 | + if ($this->gateway === 'manual' || in_array($this->status, $this->get_cancellable_statuses())) { |
|
| 559 | 559 | $ret = true; |
| 560 | 560 | } |
| 561 | - return apply_filters( 'wpinv_subscription_can_cancel', $ret, $this ); |
|
| 561 | + return apply_filters('wpinv_subscription_can_cancel', $ret, $this); |
|
| 562 | 562 | } |
| 563 | 563 | |
| 564 | 564 | /** |
@@ -569,7 +569,7 @@ discard block |
||
| 569 | 569 | * @return array |
| 570 | 570 | */ |
| 571 | 571 | public function get_cancellable_statuses() { |
| 572 | - return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) ); |
|
| 572 | + return apply_filters('wpinv_recurring_cancellable_statuses', array('active', 'trialling', 'failing')); |
|
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | /** |
@@ -580,9 +580,9 @@ discard block |
||
| 580 | 580 | */ |
| 581 | 581 | public function get_cancel_url() { |
| 582 | 582 | |
| 583 | - $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'cancel_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-cancel' ); |
|
| 583 | + $url = wp_nonce_url(add_query_arg(array('wpinv_action' => 'cancel_subscription', 'sub_id' => $this->id)), 'wpinv-recurring-cancel'); |
|
| 584 | 584 | |
| 585 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
| 585 | + return apply_filters('wpinv_subscription_cancel_url', $url, $this); |
|
| 586 | 586 | } |
| 587 | 587 | |
| 588 | 588 | /** |
@@ -596,7 +596,7 @@ discard block |
||
| 596 | 596 | */ |
| 597 | 597 | public function can_renew() { |
| 598 | 598 | |
| 599 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
| 599 | + return apply_filters('wpinv_subscription_can_renew', true, $this); |
|
| 600 | 600 | } |
| 601 | 601 | |
| 602 | 602 | /** |
@@ -607,9 +607,9 @@ discard block |
||
| 607 | 607 | */ |
| 608 | 608 | public function get_renew_url() { |
| 609 | 609 | |
| 610 | - $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'renew_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-renew' ); |
|
| 610 | + $url = wp_nonce_url(add_query_arg(array('wpinv_action' => 'renew_subscription', 'sub_id' => $this->id)), 'wpinv-recurring-renew'); |
|
| 611 | 611 | |
| 612 | - return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
| 612 | + return apply_filters('wpinv_subscription_renew_url', $url, $this); |
|
| 613 | 613 | } |
| 614 | 614 | |
| 615 | 615 | /** |
@@ -619,7 +619,7 @@ discard block |
||
| 619 | 619 | * @return bool |
| 620 | 620 | */ |
| 621 | 621 | public function can_update() { |
| 622 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
| 622 | + return apply_filters('wpinv_subscription_can_update', false, $this); |
|
| 623 | 623 | } |
| 624 | 624 | |
| 625 | 625 | /** |
@@ -630,9 +630,9 @@ discard block |
||
| 630 | 630 | */ |
| 631 | 631 | public function get_update_url() { |
| 632 | 632 | |
| 633 | - $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->id ) ); |
|
| 633 | + $url = add_query_arg(array('action' => 'update', 'subscription_id' => $this->id)); |
|
| 634 | 634 | |
| 635 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
| 635 | + return apply_filters('wpinv_subscription_update_url', $url, $this); |
|
| 636 | 636 | } |
| 637 | 637 | |
| 638 | 638 | /** |
@@ -645,11 +645,11 @@ discard block |
||
| 645 | 645 | |
| 646 | 646 | $ret = false; |
| 647 | 647 | |
| 648 | - if( ! $this->is_expired() && ( $this->status == 'active' || $this->status == 'cancelled' || $this->status == 'trialling' ) ) { |
|
| 648 | + if (!$this->is_expired() && ($this->status == 'active' || $this->status == 'cancelled' || $this->status == 'trialling')) { |
|
| 649 | 649 | $ret = true; |
| 650 | 650 | } |
| 651 | 651 | |
| 652 | - return apply_filters( 'wpinv_subscription_is_active', $ret, $this->id, $this ); |
|
| 652 | + return apply_filters('wpinv_subscription_is_active', $ret, $this->id, $this); |
|
| 653 | 653 | |
| 654 | 654 | } |
| 655 | 655 | |
@@ -663,26 +663,26 @@ discard block |
||
| 663 | 663 | |
| 664 | 664 | $ret = false; |
| 665 | 665 | |
| 666 | - if ( $this->status == 'expired' ) { |
|
| 666 | + if ($this->status == 'expired') { |
|
| 667 | 667 | |
| 668 | 668 | $ret = true; |
| 669 | 669 | |
| 670 | - } elseif( 'active' === $this->status || 'cancelled' === $this->status || $this->status == 'trialling' ) { |
|
| 670 | + } elseif ('active' === $this->status || 'cancelled' === $this->status || $this->status == 'trialling') { |
|
| 671 | 671 | |
| 672 | 672 | $ret = false; |
| 673 | 673 | $expiration = $this->get_expiration_time(); |
| 674 | 674 | |
| 675 | - if( $expiration && strtotime( 'NOW', current_time( 'timestamp' ) ) > $expiration ) { |
|
| 675 | + if ($expiration && strtotime('NOW', current_time('timestamp')) > $expiration) { |
|
| 676 | 676 | $ret = true; |
| 677 | 677 | |
| 678 | - if ( 'active' === $this->status || $this->status == 'trialling' ) { |
|
| 678 | + if ('active' === $this->status || $this->status == 'trialling') { |
|
| 679 | 679 | $this->expire(); |
| 680 | 680 | } |
| 681 | 681 | } |
| 682 | 682 | |
| 683 | 683 | } |
| 684 | 684 | |
| 685 | - return apply_filters( 'wpinv_subscription_is_expired', $ret, $this->id, $this ); |
|
| 685 | + return apply_filters('wpinv_subscription_is_expired', $ret, $this->id, $this); |
|
| 686 | 686 | |
| 687 | 687 | } |
| 688 | 688 | |
@@ -703,7 +703,7 @@ discard block |
||
| 703 | 703 | * @return int |
| 704 | 704 | */ |
| 705 | 705 | public function get_expiration_time() { |
| 706 | - return strtotime( $this->expiration, current_time( 'timestamp' ) ); |
|
| 706 | + return strtotime($this->expiration, current_time('timestamp')); |
|
| 707 | 707 | } |
| 708 | 708 | |
| 709 | 709 | /** |
@@ -727,37 +727,37 @@ discard block |
||
| 727 | 727 | */ |
| 728 | 728 | public function get_status_label() { |
| 729 | 729 | |
| 730 | - switch( $this->get_status() ) { |
|
| 730 | + switch ($this->get_status()) { |
|
| 731 | 731 | case 'active' : |
| 732 | - $status = __( 'Active', 'invoicing' ); |
|
| 732 | + $status = __('Active', 'invoicing'); |
|
| 733 | 733 | break; |
| 734 | 734 | |
| 735 | 735 | case 'cancelled' : |
| 736 | - $status = __( 'Cancelled', 'invoicing' ); |
|
| 736 | + $status = __('Cancelled', 'invoicing'); |
|
| 737 | 737 | break; |
| 738 | 738 | |
| 739 | 739 | case 'expired' : |
| 740 | - $status = __( 'Expired', 'invoicing' ); |
|
| 740 | + $status = __('Expired', 'invoicing'); |
|
| 741 | 741 | break; |
| 742 | 742 | |
| 743 | 743 | case 'pending' : |
| 744 | - $status = __( 'Pending', 'invoicing' ); |
|
| 744 | + $status = __('Pending', 'invoicing'); |
|
| 745 | 745 | break; |
| 746 | 746 | |
| 747 | 747 | case 'failing' : |
| 748 | - $status = __( 'Failing', 'invoicing' ); |
|
| 748 | + $status = __('Failing', 'invoicing'); |
|
| 749 | 749 | break; |
| 750 | 750 | |
| 751 | 751 | case 'trialling' : |
| 752 | - $status = __( 'Trialling', 'invoicing' ); |
|
| 752 | + $status = __('Trialling', 'invoicing'); |
|
| 753 | 753 | break; |
| 754 | 754 | |
| 755 | 755 | case 'completed' : |
| 756 | - $status = __( 'Completed', 'invoicing' ); |
|
| 756 | + $status = __('Completed', 'invoicing'); |
|
| 757 | 757 | break; |
| 758 | 758 | |
| 759 | 759 | default: |
| 760 | - $status = ucfirst( $this->get_status() ); |
|
| 760 | + $status = ucfirst($this->get_status()); |
|
| 761 | 761 | break; |
| 762 | 762 | } |
| 763 | 763 | |
@@ -772,51 +772,51 @@ discard block |
||
| 772 | 772 | */ |
| 773 | 773 | public function get_status_label_html() { |
| 774 | 774 | |
| 775 | - switch( $get_status = $this->get_status() ) { |
|
| 775 | + switch ($get_status = $this->get_status()) { |
|
| 776 | 776 | case 'active' : |
| 777 | - $status = __( 'Active', 'invoicing' ); |
|
| 777 | + $status = __('Active', 'invoicing'); |
|
| 778 | 778 | $class = 'label-info'; |
| 779 | 779 | break; |
| 780 | 780 | |
| 781 | 781 | case 'cancelled' : |
| 782 | - $status = __( 'Cancelled', 'invoicing' ); |
|
| 782 | + $status = __('Cancelled', 'invoicing'); |
|
| 783 | 783 | $class = 'label-danger'; |
| 784 | 784 | break; |
| 785 | 785 | |
| 786 | 786 | case 'expired' : |
| 787 | - $status = __( 'Expired', 'invoicing' ); |
|
| 787 | + $status = __('Expired', 'invoicing'); |
|
| 788 | 788 | $class = 'label-default'; |
| 789 | 789 | break; |
| 790 | 790 | |
| 791 | 791 | case 'pending' : |
| 792 | - $status = __( 'Pending', 'invoicing' ); |
|
| 792 | + $status = __('Pending', 'invoicing'); |
|
| 793 | 793 | $class = 'label-primary'; |
| 794 | 794 | break; |
| 795 | 795 | |
| 796 | 796 | case 'failing' : |
| 797 | - $status = __( 'Failing', 'invoicing' ); |
|
| 797 | + $status = __('Failing', 'invoicing'); |
|
| 798 | 798 | $class = 'label-danger'; |
| 799 | 799 | break; |
| 800 | 800 | |
| 801 | 801 | case 'trialling' : |
| 802 | - $status = __( 'Trialling', 'invoicing' ); |
|
| 802 | + $status = __('Trialling', 'invoicing'); |
|
| 803 | 803 | $class = 'label-info'; |
| 804 | 804 | break; |
| 805 | 805 | |
| 806 | 806 | case 'completed' : |
| 807 | - $status = __( 'Completed', 'invoicing' ); |
|
| 807 | + $status = __('Completed', 'invoicing'); |
|
| 808 | 808 | $class = 'label-success'; |
| 809 | 809 | break; |
| 810 | 810 | |
| 811 | 811 | default: |
| 812 | - $status = ucfirst( $this->get_status() ); |
|
| 812 | + $status = ucfirst($this->get_status()); |
|
| 813 | 813 | $class = 'label-default'; |
| 814 | 814 | break; |
| 815 | 815 | } |
| 816 | 816 | |
| 817 | 817 | $label = '<span class="sub-status label label-sub-' . $get_status . ' ' . $class . '">' . $status . '</span>'; |
| 818 | 818 | |
| 819 | - return apply_filters( 'wpinv_subscription_status_label_html', $label, $get_status, $status ); |
|
| 819 | + return apply_filters('wpinv_subscription_status_label_html', $label, $get_status, $status); |
|
| 820 | 820 | } |
| 821 | 821 | |
| 822 | 822 | /** |
@@ -826,9 +826,9 @@ discard block |
||
| 826 | 826 | * @param string $txn_id The transaction ID from the merchant processor |
| 827 | 827 | * @return bool |
| 828 | 828 | */ |
| 829 | - public function payment_exists( $txn_id = '' ) { |
|
| 830 | - $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
| 831 | - return ! empty( $invoice_id ); |
|
| 829 | + public function payment_exists($txn_id = '') { |
|
| 830 | + $invoice_id = WPInv_Invoice::get_invoice_id_by_field($txn_id, 'transaction_id'); |
|
| 831 | + return !empty($invoice_id); |
|
| 832 | 832 | } |
| 833 | 833 | |
| 834 | 834 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -defined( 'ABSPATH' ) || exit; |
|
| 7 | +defined('ABSPATH') || exit; |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Manual Payment Gateway class. |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * |
| 25 | 25 | * @var array |
| 26 | 26 | */ |
| 27 | - protected $supports = array( 'subscription' ); |
|
| 27 | + protected $supports = array('subscription'); |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * Payment method order. |
@@ -39,10 +39,10 @@ discard block |
||
| 39 | 39 | public function __construct() { |
| 40 | 40 | parent::__construct(); |
| 41 | 41 | |
| 42 | - $this->title = __( 'Manual Payment', 'invoicing' ); |
|
| 43 | - $this->method_title = __( 'Manual Payment', 'invoicing' ); |
|
| 42 | + $this->title = __('Manual Payment', 'invoicing'); |
|
| 43 | + $this->method_title = __('Manual Payment', 'invoicing'); |
|
| 44 | 44 | |
| 45 | - add_action( 'wpinv_renew_manual_subscription_profile', array( $this, 'renew_manual_subscription_profile' ) ); |
|
| 45 | + add_action('wpinv_renew_manual_subscription_profile', array($this, 'renew_manual_subscription_profile')); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -54,16 +54,16 @@ discard block |
||
| 54 | 54 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
| 55 | 55 | * @return array |
| 56 | 56 | */ |
| 57 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 57 | + public function process_payment($invoice, $submission_data, $submission) { |
|
| 58 | 58 | |
| 59 | 59 | // Mark it as paid. |
| 60 | 60 | $invoice->mark_paid(); |
| 61 | 61 | |
| 62 | 62 | // (Maybe) set recurring hooks. |
| 63 | - $this->start_manual_subscription_profile( $invoice ); |
|
| 63 | + $this->start_manual_subscription_profile($invoice); |
|
| 64 | 64 | |
| 65 | 65 | // Send to the success page. |
| 66 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
| 66 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
| 67 | 67 | |
| 68 | 68 | } |
| 69 | 69 | |
@@ -73,19 +73,19 @@ discard block |
||
| 73 | 73 | * |
| 74 | 74 | * @param WPInv_Invoice $invoice Invoice. |
| 75 | 75 | */ |
| 76 | - public function start_manual_subscription_profile( $invoice ) { |
|
| 76 | + public function start_manual_subscription_profile($invoice) { |
|
| 77 | 77 | |
| 78 | 78 | // Retrieve the subscription. |
| 79 | - $subscription = wpinv_get_subscription( $invoice ); |
|
| 80 | - if ( empty( $subscription ) ) { |
|
| 79 | + $subscription = wpinv_get_subscription($invoice); |
|
| 80 | + if (empty($subscription)) { |
|
| 81 | 81 | return; |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | // Schedule an action to run when the subscription expires. |
| 85 | 85 | $action_id = as_schedule_single_action( |
| 86 | - strtotime( $subscription->expiration ), |
|
| 86 | + strtotime($subscription->expiration), |
|
| 87 | 87 | 'wpinv_renew_manual_subscription_profile', |
| 88 | - array( $invoice->get_id() ), |
|
| 88 | + array($invoice->get_id()), |
|
| 89 | 89 | 'invoicing' |
| 90 | 90 | ); |
| 91 | 91 | |
@@ -105,16 +105,16 @@ discard block |
||
| 105 | 105 | * |
| 106 | 106 | * @param int $invoice_id Invoice. |
| 107 | 107 | */ |
| 108 | - public function renew_manual_subscription_profile( $invoice_id ) { |
|
| 108 | + public function renew_manual_subscription_profile($invoice_id) { |
|
| 109 | 109 | |
| 110 | 110 | // Retrieve the subscription. |
| 111 | - $subscription = wpinv_get_subscription( $invoice_id ); |
|
| 112 | - if ( empty( $subscription ) ) { |
|
| 111 | + $subscription = wpinv_get_subscription($invoice_id); |
|
| 112 | + if (empty($subscription)) { |
|
| 113 | 113 | return; |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | // Abort if it is canceled or complete. |
| 117 | - if ( $subscription->status == 'completed' || $subscription->status == 'cancelled' ) { |
|
| 117 | + if ($subscription->status == 'completed' || $subscription->status == 'cancelled') { |
|
| 118 | 118 | return; |
| 119 | 119 | } |
| 120 | 120 | |
@@ -122,34 +122,34 @@ discard block |
||
| 122 | 122 | $times_billed = $subscription->get_times_billed(); |
| 123 | 123 | $max_bills = $subscription->bill_times; |
| 124 | 124 | |
| 125 | - if ( empty( $max_bills ) || $max_bills > $times_billed ) { |
|
| 125 | + if (empty($max_bills) || $max_bills > $times_billed) { |
|
| 126 | 126 | |
| 127 | 127 | // Retrieve the invoice. |
| 128 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 128 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 129 | 129 | |
| 130 | 130 | // Renew the subscription. |
| 131 | - $subscription->add_payment( array( |
|
| 131 | + $subscription->add_payment(array( |
|
| 132 | 132 | 'amount' => $subscription->recurring_amount, |
| 133 | 133 | 'transaction_id' => $invoice->generate_key(), |
| 134 | 134 | 'gateway' => $this->id |
| 135 | - ) ); |
|
| 135 | + )); |
|
| 136 | 136 | |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | // Renew/Complete the subscription. |
| 140 | 140 | $subscription->renew(); |
| 141 | 141 | |
| 142 | - if ( 'completed' != $subscription->status ) { |
|
| 142 | + if ('completed' != $subscription->status) { |
|
| 143 | 143 | |
| 144 | 144 | // Schedule an action to run when the subscription expires. |
| 145 | 145 | $action_id = as_schedule_single_action( |
| 146 | - strtotime( $subscription->expiration ), |
|
| 146 | + strtotime($subscription->expiration), |
|
| 147 | 147 | 'wpinv_renew_manual_subscription_profile', |
| 148 | - array( $invoice_id ), |
|
| 148 | + array($invoice_id), |
|
| 149 | 149 | 'invoicing' |
| 150 | 150 | ); |
| 151 | 151 | |
| 152 | - $subscription->update( array( 'profile_id' => $action_id, ) ); |
|
| 152 | + $subscription->update(array('profile_id' => $action_id,)); |
|
| 153 | 153 | |
| 154 | 154 | } |
| 155 | 155 | |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -defined( 'ABSPATH' ) || exit; |
|
| 7 | +defined('ABSPATH') || exit; |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Paypal Payment Gateway class. |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * |
| 25 | 25 | * @var array |
| 26 | 26 | */ |
| 27 | - protected $supports = array( 'subscription', 'sandbox' ); |
|
| 27 | + protected $supports = array('subscription', 'sandbox'); |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * Payment method order. |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | * |
| 60 | 60 | * @var array |
| 61 | 61 | */ |
| 62 | - public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
| 62 | + public $currencies = array('AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR'); |
|
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | 65 | * URL to view a transaction. |
@@ -80,13 +80,13 @@ discard block |
||
| 80 | 80 | */ |
| 81 | 81 | public function __construct() { |
| 82 | 82 | |
| 83 | - $this->title = __( 'PayPal Standard', 'invoicing' ); |
|
| 84 | - $this->method_title = __( 'PayPal Standard', 'invoicing' ); |
|
| 85 | - $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' ); |
|
| 86 | - $this->notify_url = wpinv_get_ipn_url( $this->id ); |
|
| 83 | + $this->title = __('PayPal Standard', 'invoicing'); |
|
| 84 | + $this->method_title = __('PayPal Standard', 'invoicing'); |
|
| 85 | + $this->checkout_button_text = __('Proceed to PayPal', 'invoicing'); |
|
| 86 | + $this->notify_url = wpinv_get_ipn_url($this->id); |
|
| 87 | 87 | |
| 88 | - add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
| 89 | - add_filter( 'wpinv_gateway_description', array( $this, 'sandbox_notice' ), 10, 2 ); |
|
| 88 | + add_filter('getpaid_paypal_args', array($this, 'process_subscription'), 10, 2); |
|
| 89 | + add_filter('wpinv_gateway_description', array($this, 'sandbox_notice'), 10, 2); |
|
| 90 | 90 | |
| 91 | 91 | parent::__construct(); |
| 92 | 92 | } |
@@ -100,16 +100,16 @@ discard block |
||
| 100 | 100 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
| 101 | 101 | * @return array |
| 102 | 102 | */ |
| 103 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 103 | + public function process_payment($invoice, $submission_data, $submission) { |
|
| 104 | 104 | |
| 105 | 105 | // Get redirect url. |
| 106 | - $paypal_redirect = $this->get_request_url( $invoice ); |
|
| 106 | + $paypal_redirect = $this->get_request_url($invoice); |
|
| 107 | 107 | |
| 108 | 108 | // Add a note about the request url. |
| 109 | 109 | $invoice->add_note( |
| 110 | 110 | sprintf( |
| 111 | - __( 'Redirecting to PayPal: %s', 'invoicing' ), |
|
| 112 | - esc_url( $paypal_redirect ) |
|
| 111 | + __('Redirecting to PayPal: %s', 'invoicing'), |
|
| 112 | + esc_url($paypal_redirect) |
|
| 113 | 113 | ), |
| 114 | 114 | false, |
| 115 | 115 | false, |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | ); |
| 118 | 118 | |
| 119 | 119 | // Redirect to PayPal |
| 120 | - wp_redirect( $paypal_redirect ); |
|
| 120 | + wp_redirect($paypal_redirect); |
|
| 121 | 121 | exit; |
| 122 | 122 | |
| 123 | 123 | } |
@@ -128,21 +128,21 @@ discard block |
||
| 128 | 128 | * @param WPInv_Invoice $invoice Invoice object. |
| 129 | 129 | * @return string |
| 130 | 130 | */ |
| 131 | - public function get_request_url( $invoice ) { |
|
| 131 | + public function get_request_url($invoice) { |
|
| 132 | 132 | |
| 133 | 133 | // Endpoint for this request |
| 134 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
| 134 | + $this->endpoint = $this->is_sandbox($invoice) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
| 135 | 135 | |
| 136 | 136 | // Retrieve paypal args. |
| 137 | - $paypal_args = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' ); |
|
| 137 | + $paypal_args = map_deep($this->get_paypal_args($invoice), 'urlencode'); |
|
| 138 | 138 | |
| 139 | - if ( $invoice->is_recurring() ) { |
|
| 139 | + if ($invoice->is_recurring()) { |
|
| 140 | 140 | $paypal_args['bn'] = 'GetPaid_Subscribe_WPS_US'; |
| 141 | 141 | } else { |
| 142 | 142 | $paypal_args['bn'] = 'GetPaid_ShoppingCart_WPS_US'; |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - return add_query_arg( $paypal_args, $this->endpoint ); |
|
| 145 | + return add_query_arg($paypal_args, $this->endpoint); |
|
| 146 | 146 | |
| 147 | 147 | } |
| 148 | 148 | |
@@ -152,25 +152,25 @@ discard block |
||
| 152 | 152 | * @param WPInv_Invoice $invoice Invoice object. |
| 153 | 153 | * @return array |
| 154 | 154 | */ |
| 155 | - protected function get_paypal_args( $invoice ) { |
|
| 155 | + protected function get_paypal_args($invoice) { |
|
| 156 | 156 | |
| 157 | 157 | // Whether or not to send the line items as one item. |
| 158 | - $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', false, $invoice ); |
|
| 158 | + $force_one_line_item = apply_filters('getpaid_paypal_force_one_line_item', false, $invoice); |
|
| 159 | 159 | |
| 160 | - if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
| 160 | + if ($invoice->is_recurring() || (wpinv_use_taxes() && wpinv_prices_include_tax())) { |
|
| 161 | 161 | $force_one_line_item = true; |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | $paypal_args = apply_filters( |
| 165 | 165 | 'getpaid_paypal_args', |
| 166 | 166 | array_merge( |
| 167 | - $this->get_transaction_args( $invoice ), |
|
| 168 | - $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
| 167 | + $this->get_transaction_args($invoice), |
|
| 168 | + $this->get_line_item_args($invoice, $force_one_line_item) |
|
| 169 | 169 | ), |
| 170 | 170 | $invoice |
| 171 | 171 | ); |
| 172 | 172 | |
| 173 | - return $this->fix_request_length( $invoice, $paypal_args ); |
|
| 173 | + return $this->fix_request_length($invoice, $paypal_args); |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | /** |
@@ -179,11 +179,11 @@ discard block |
||
| 179 | 179 | * @param WPInv_Invoice $invoice Invoice object. |
| 180 | 180 | * @return array |
| 181 | 181 | */ |
| 182 | - protected function get_transaction_args( $invoice ) { |
|
| 182 | + protected function get_transaction_args($invoice) { |
|
| 183 | 183 | |
| 184 | 184 | return array( |
| 185 | 185 | 'cmd' => '_cart', |
| 186 | - 'business' => wpinv_get_option( 'paypal_email', false ), |
|
| 186 | + 'business' => wpinv_get_option('paypal_email', false), |
|
| 187 | 187 | 'no_shipping' => '1', |
| 188 | 188 | 'shipping' => '0', |
| 189 | 189 | 'no_note' => '1', |
@@ -191,16 +191,16 @@ discard block |
||
| 191 | 191 | 'rm' => is_ssl() ? 2 : 1, |
| 192 | 192 | 'upload' => 1, |
| 193 | 193 | 'currency_code' => $invoice->get_currency(), // https://developer.paypal.com/docs/nvp-soap-api/currency-codes/#paypal |
| 194 | - 'return' => esc_url_raw( $this->get_return_url( $invoice ) ), |
|
| 195 | - 'cancel_return' => esc_url_raw( $invoice->get_checkout_payment_url() ), |
|
| 196 | - 'notify_url' => getpaid_limit_length( $this->notify_url, 255 ), |
|
| 197 | - 'invoice' => getpaid_limit_length( $invoice->get_number(), 127 ), |
|
| 194 | + 'return' => esc_url_raw($this->get_return_url($invoice)), |
|
| 195 | + 'cancel_return' => esc_url_raw($invoice->get_checkout_payment_url()), |
|
| 196 | + 'notify_url' => getpaid_limit_length($this->notify_url, 255), |
|
| 197 | + 'invoice' => getpaid_limit_length($invoice->get_number(), 127), |
|
| 198 | 198 | 'custom' => $invoice->get_id(), |
| 199 | - 'first_name' => getpaid_limit_length( $invoice->get_first_name(), 32 ), |
|
| 200 | - 'last_name' => getpaid_limit_length( $invoice->get_last_name(), 64 ), |
|
| 201 | - 'country' => getpaid_limit_length( $invoice->get_country(), 2 ), |
|
| 202 | - 'email' => getpaid_limit_length( $invoice->get_email(), 127 ), |
|
| 203 | - 'cbt' => get_bloginfo( 'name' ) |
|
| 199 | + 'first_name' => getpaid_limit_length($invoice->get_first_name(), 32), |
|
| 200 | + 'last_name' => getpaid_limit_length($invoice->get_last_name(), 64), |
|
| 201 | + 'country' => getpaid_limit_length($invoice->get_country(), 2), |
|
| 202 | + 'email' => getpaid_limit_length($invoice->get_email(), 127), |
|
| 203 | + 'cbt' => get_bloginfo('name') |
|
| 204 | 204 | ); |
| 205 | 205 | |
| 206 | 206 | } |
@@ -212,30 +212,30 @@ discard block |
||
| 212 | 212 | * @param bool $force_one_line_item Create only one item for this invoice. |
| 213 | 213 | * @return array |
| 214 | 214 | */ |
| 215 | - protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
| 215 | + protected function get_line_item_args($invoice, $force_one_line_item = false) { |
|
| 216 | 216 | |
| 217 | 217 | // Maybe send invoice as a single item. |
| 218 | - if ( $force_one_line_item ) { |
|
| 219 | - return $this->get_line_item_args_single_item( $invoice ); |
|
| 218 | + if ($force_one_line_item) { |
|
| 219 | + return $this->get_line_item_args_single_item($invoice); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | // Send each line item individually. |
| 223 | 223 | $line_item_args = array(); |
| 224 | 224 | |
| 225 | 225 | // Prepare line items. |
| 226 | - $this->prepare_line_items( $invoice ); |
|
| 226 | + $this->prepare_line_items($invoice); |
|
| 227 | 227 | |
| 228 | 228 | // Add taxes to the cart |
| 229 | - if ( wpinv_use_taxes() && $invoice->is_taxable() ) { |
|
| 230 | - $line_item_args['tax_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_tax(), 2 ); |
|
| 229 | + if (wpinv_use_taxes() && $invoice->is_taxable()) { |
|
| 230 | + $line_item_args['tax_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_tax(), 2); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | // Add discount. |
| 234 | - if ( $invoice->get_total_discount() > 0 ) { |
|
| 235 | - $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 ); |
|
| 234 | + if ($invoice->get_total_discount() > 0) { |
|
| 235 | + $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_discount(), 2); |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | - return array_merge( $line_item_args, $this->get_line_items() ); |
|
| 238 | + return array_merge($line_item_args, $this->get_line_items()); |
|
| 239 | 239 | |
| 240 | 240 | } |
| 241 | 241 | |
@@ -245,11 +245,11 @@ discard block |
||
| 245 | 245 | * @param WPInv_Invoice $invoice Invoice object. |
| 246 | 246 | * @return array |
| 247 | 247 | */ |
| 248 | - protected function get_line_item_args_single_item( $invoice ) { |
|
| 248 | + protected function get_line_item_args_single_item($invoice) { |
|
| 249 | 249 | $this->delete_line_items(); |
| 250 | 250 | |
| 251 | - $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
|
| 252 | - $this->add_line_item( $item_name, 1, wpinv_sanitize_amount( (float) $invoice->get_total(), 2 ), $invoice->get_id() ); |
|
| 251 | + $item_name = sprintf(__('Invoice #%s', 'invoicing'), $invoice->get_number()); |
|
| 252 | + $this->add_line_item($item_name, 1, wpinv_sanitize_amount((float) $invoice->get_total(), 2), $invoice->get_id()); |
|
| 253 | 253 | |
| 254 | 254 | return $this->get_line_items(); |
| 255 | 255 | } |
@@ -273,19 +273,19 @@ discard block |
||
| 273 | 273 | * |
| 274 | 274 | * @param WPInv_Invoice $invoice Invoice object. |
| 275 | 275 | */ |
| 276 | - protected function prepare_line_items( $invoice ) { |
|
| 276 | + protected function prepare_line_items($invoice) { |
|
| 277 | 277 | $this->delete_line_items(); |
| 278 | 278 | |
| 279 | 279 | // Items. |
| 280 | - foreach ( $invoice->get_items() as $item ) { |
|
| 280 | + foreach ($invoice->get_items() as $item) { |
|
| 281 | 281 | $amount = $invoice->get_template() == 'amount' ? $item->get_price() : $item->get_sub_total(); |
| 282 | 282 | $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
| 283 | - $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
| 283 | + $this->add_line_item($item->get_raw_name(), $quantity, $amount, $item->get_id()); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | // Fees. |
| 287 | - foreach ( $invoice->get_fees() as $fee => $data ) { |
|
| 288 | - $this->add_line_item( $fee, 1, $data['amount'] ); |
|
| 287 | + foreach ($invoice->get_fees() as $fee => $data) { |
|
| 288 | + $this->add_line_item($fee, 1, $data['amount']); |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | } |
@@ -298,15 +298,15 @@ discard block |
||
| 298 | 298 | * @param float $amount Amount. |
| 299 | 299 | * @param string $item_number Item number. |
| 300 | 300 | */ |
| 301 | - protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
| 302 | - $index = ( count( $this->line_items ) / 4 ) + 1; |
|
| 301 | + protected function add_line_item($item_name, $quantity = 1, $amount = 0.0, $item_number = '') { |
|
| 302 | + $index = (count($this->line_items) / 4) + 1; |
|
| 303 | 303 | |
| 304 | 304 | $item = apply_filters( |
| 305 | 305 | 'getpaid_paypal_line_item', |
| 306 | 306 | array( |
| 307 | - 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
| 307 | + 'item_name' => html_entity_decode(getpaid_limit_length($item_name ? wp_strip_all_tags($item_name) : __('Item', 'invoicing'), 127), ENT_NOQUOTES, 'UTF-8'), |
|
| 308 | 308 | 'quantity' => (int) $quantity, |
| 309 | - 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
| 309 | + 'amount' => wpinv_sanitize_amount((float) $amount, 2), |
|
| 310 | 310 | 'item_number' => $item_number, |
| 311 | 311 | ), |
| 312 | 312 | $item_name, |
@@ -315,12 +315,12 @@ discard block |
||
| 315 | 315 | $item_number |
| 316 | 316 | ); |
| 317 | 317 | |
| 318 | - $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
| 319 | - $this->line_items[ 'quantity_' . $index ] = $item['quantity']; |
|
| 318 | + $this->line_items['item_name_' . $index] = getpaid_limit_length($item['item_name'], 127); |
|
| 319 | + $this->line_items['quantity_' . $index] = $item['quantity']; |
|
| 320 | 320 | |
| 321 | 321 | // The price or amount of the product, service, or contribution, not including shipping, handling, or tax. |
| 322 | - $this->line_items[ 'amount_' . $index ] = $item['amount']; |
|
| 323 | - $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
| 322 | + $this->line_items['amount_' . $index] = $item['amount']; |
|
| 323 | + $this->line_items['item_number_' . $index] = getpaid_limit_length($item['item_number'], 127); |
|
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | /** |
@@ -332,19 +332,19 @@ discard block |
||
| 332 | 332 | * @param array $paypal_args Arguments sent to Paypal in the request. |
| 333 | 333 | * @return array |
| 334 | 334 | */ |
| 335 | - protected function fix_request_length( $invoice, $paypal_args ) { |
|
| 335 | + protected function fix_request_length($invoice, $paypal_args) { |
|
| 336 | 336 | $max_paypal_length = 2083; |
| 337 | - $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
| 337 | + $query_candidate = http_build_query($paypal_args, '', '&'); |
|
| 338 | 338 | |
| 339 | - if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
| 339 | + if (strlen($this->endpoint . $query_candidate) <= $max_paypal_length) { |
|
| 340 | 340 | return $paypal_args; |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | return apply_filters( |
| 344 | 344 | 'getpaid_paypal_args', |
| 345 | 345 | array_merge( |
| 346 | - $this->get_transaction_args( $invoice ), |
|
| 347 | - $this->get_line_item_args( $invoice, true ) |
|
| 346 | + $this->get_transaction_args($invoice), |
|
| 347 | + $this->get_line_item_args($invoice, true) |
|
| 348 | 348 | ), |
| 349 | 349 | $invoice |
| 350 | 350 | ); |
@@ -357,10 +357,10 @@ discard block |
||
| 357 | 357 | * @param array $paypal_args PayPal args. |
| 358 | 358 | * @param WPInv_Invoice $invoice Invoice object. |
| 359 | 359 | */ |
| 360 | - public function process_subscription( $paypal_args, $invoice ) { |
|
| 360 | + public function process_subscription($paypal_args, $invoice) { |
|
| 361 | 361 | |
| 362 | 362 | // Make sure this is a subscription. |
| 363 | - if ( ! $invoice->is_recurring() || ! $subscription = wpinv_get_subscription( $invoice ) ) { |
|
| 363 | + if (!$invoice->is_recurring() || !$subscription = wpinv_get_subscription($invoice)) { |
|
| 364 | 364 | return $paypal_args; |
| 365 | 365 | } |
| 366 | 366 | |
@@ -368,17 +368,17 @@ discard block |
||
| 368 | 368 | $paypal_args['cmd'] = '_xclick-subscriptions'; |
| 369 | 369 | |
| 370 | 370 | // Subscription name. |
| 371 | - $paypal_args['item_name'] = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
|
| 371 | + $paypal_args['item_name'] = sprintf(__('Invoice #%s', 'invoicing'), $invoice->get_number()); |
|
| 372 | 372 | |
| 373 | 373 | // Get subscription args. |
| 374 | - $period = strtoupper( substr( $subscription->period, 0, 1) ); |
|
| 374 | + $period = strtoupper(substr($subscription->period, 0, 1)); |
|
| 375 | 375 | $interval = (int) $subscription->frequency; |
| 376 | 376 | $bill_times = (int) $subscription->bill_times; |
| 377 | - $initial_amount = (float) wpinv_sanitize_amount( $invoice->get_initial_total(), 2 ); |
|
| 378 | - $recurring_amount = (float) wpinv_sanitize_amount( $invoice->get_recurring_total(), 2 ); |
|
| 379 | - $subscription_item = $invoice->get_recurring( true ); |
|
| 377 | + $initial_amount = (float) wpinv_sanitize_amount($invoice->get_initial_total(), 2); |
|
| 378 | + $recurring_amount = (float) wpinv_sanitize_amount($invoice->get_recurring_total(), 2); |
|
| 379 | + $subscription_item = $invoice->get_recurring(true); |
|
| 380 | 380 | |
| 381 | - if ( $subscription_item->has_free_trial() ) { |
|
| 381 | + if ($subscription_item->has_free_trial()) { |
|
| 382 | 382 | |
| 383 | 383 | $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount; |
| 384 | 384 | |
@@ -388,28 +388,28 @@ discard block |
||
| 388 | 388 | // Trial period. |
| 389 | 389 | $paypal_args['t1'] = $subscription_item->get_trial_period(); |
| 390 | 390 | |
| 391 | - } else if ( $initial_amount != $recurring_amount ) { |
|
| 391 | + } else if ($initial_amount != $recurring_amount) { |
|
| 392 | 392 | |
| 393 | 393 | // No trial period, but initial amount includes a sign-up fee and/or other items, so charge it as a separate period. |
| 394 | 394 | |
| 395 | - if ( 1 == $bill_times ) { |
|
| 395 | + if (1 == $bill_times) { |
|
| 396 | 396 | $param_number = 3; |
| 397 | 397 | } else { |
| 398 | 398 | $param_number = 1; |
| 399 | 399 | } |
| 400 | 400 | |
| 401 | - $paypal_args[ 'a' . $param_number ] = $initial_amount ? 0 : $initial_amount; |
|
| 401 | + $paypal_args['a' . $param_number] = $initial_amount ? 0 : $initial_amount; |
|
| 402 | 402 | |
| 403 | 403 | // Sign Up interval |
| 404 | - $paypal_args[ 'p' . $param_number ] = $interval; |
|
| 404 | + $paypal_args['p' . $param_number] = $interval; |
|
| 405 | 405 | |
| 406 | 406 | // Sign Up unit of duration |
| 407 | - $paypal_args[ 't' . $param_number ] = $period; |
|
| 407 | + $paypal_args['t' . $param_number] = $period; |
|
| 408 | 408 | |
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | // We have a recurring payment |
| 412 | - if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
| 412 | + if (!isset($param_number) || 1 == $param_number) { |
|
| 413 | 413 | |
| 414 | 414 | // Subscription price |
| 415 | 415 | $paypal_args['a3'] = $recurring_amount; |
@@ -423,7 +423,7 @@ discard block |
||
| 423 | 423 | } |
| 424 | 424 | |
| 425 | 425 | // Recurring payments |
| 426 | - if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
| 426 | + if (1 == $bill_times || ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial() && 2 == $bill_times)) { |
|
| 427 | 427 | |
| 428 | 428 | // Non-recurring payments |
| 429 | 429 | $paypal_args['src'] = 0; |
@@ -432,15 +432,15 @@ discard block |
||
| 432 | 432 | |
| 433 | 433 | $paypal_args['src'] = 1; |
| 434 | 434 | |
| 435 | - if ( $bill_times > 0 ) { |
|
| 435 | + if ($bill_times > 0) { |
|
| 436 | 436 | |
| 437 | 437 | // An initial period is being used to charge a sign-up fee |
| 438 | - if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
| 438 | + if ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial()) { |
|
| 439 | 439 | $bill_times--; |
| 440 | 440 | } |
| 441 | 441 | |
| 442 | 442 | // Make sure it's not over the max of 52 |
| 443 | - $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
|
| 443 | + $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52); |
|
| 444 | 444 | |
| 445 | 445 | } |
| 446 | 446 | } |
@@ -449,10 +449,10 @@ discard block |
||
| 449 | 449 | $paypal_args['rm'] = 2; |
| 450 | 450 | |
| 451 | 451 | // Get rid of redudant items. |
| 452 | - foreach ( array( 'item_name_1', 'quantity_1', 'amount_1', 'item_number_1' ) as $arg ) { |
|
| 452 | + foreach (array('item_name_1', 'quantity_1', 'amount_1', 'item_number_1') as $arg) { |
|
| 453 | 453 | |
| 454 | - if ( isset( $paypal_args[ $arg ] ) ) { |
|
| 455 | - unset( $paypal_args[ $arg ] ); |
|
| 454 | + if (isset($paypal_args[$arg])) { |
|
| 455 | + unset($paypal_args[$arg]); |
|
| 456 | 456 | } |
| 457 | 457 | |
| 458 | 458 | } |
@@ -473,25 +473,25 @@ discard block |
||
| 473 | 473 | public function verify_ipn() { |
| 474 | 474 | |
| 475 | 475 | // Validate the IPN. |
| 476 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
| 477 | - wp_die( 'PayPal IPN Request Failure', 'PayPal IPN', array( 'response' => 500 ) ); |
|
| 476 | + if (empty($_POST) || !$this->validate_ipn()) { |
|
| 477 | + wp_die('PayPal IPN Request Failure', 'PayPal IPN', array('response' => 500)); |
|
| 478 | 478 | } |
| 479 | 479 | |
| 480 | 480 | // Process the IPN. |
| 481 | - $posted = wp_unslash( $_POST ); |
|
| 482 | - $invoice = wpinv_get_invoice( $posted['custom'] ); |
|
| 481 | + $posted = wp_unslash($_POST); |
|
| 482 | + $invoice = wpinv_get_invoice($posted['custom']); |
|
| 483 | 483 | |
| 484 | - if ( $invoice && $this->id == $invoice->get_gateway() ) { |
|
| 484 | + if ($invoice && $this->id == $invoice->get_gateway()) { |
|
| 485 | 485 | |
| 486 | - $posted['payment_status'] = strtolower( $posted['payment_status'] ); |
|
| 486 | + $posted['payment_status'] = strtolower($posted['payment_status']); |
|
| 487 | 487 | |
| 488 | - wpinv_error_log( 'Found invoice #' . $invoice->get_number() ); |
|
| 489 | - wpinv_error_log( 'Payment status:' . $posted['payment_status'] ); |
|
| 488 | + wpinv_error_log('Found invoice #' . $invoice->get_number()); |
|
| 489 | + wpinv_error_log('Payment status:' . $posted['payment_status']); |
|
| 490 | 490 | |
| 491 | - if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
| 492 | - call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
| 491 | + if (method_exists($this, 'ipn_txn_' . $posted['txn_type'])) { |
|
| 492 | + call_user_func(array($this, 'ipn_txn_' . $posted['txn_type']), $invoice, $posted); |
|
| 493 | 493 | } else { |
| 494 | - wpinv_error_log( 'Aborting, Invalid type:' . $posted['txn_type'] ); |
|
| 494 | + wpinv_error_log('Aborting, Invalid type:' . $posted['txn_type']); |
|
| 495 | 495 | } |
| 496 | 496 | |
| 497 | 497 | } |
@@ -505,10 +505,10 @@ discard block |
||
| 505 | 505 | */ |
| 506 | 506 | public function validate_ipn() { |
| 507 | 507 | |
| 508 | - wpinv_error_log( 'Validating PayPal IPN response' ); |
|
| 508 | + wpinv_error_log('Validating PayPal IPN response'); |
|
| 509 | 509 | |
| 510 | 510 | // Get received values from post data. |
| 511 | - $validate_ipn = wp_unslash( $_POST ); |
|
| 511 | + $validate_ipn = wp_unslash($_POST); |
|
| 512 | 512 | $validate_ipn['cmd'] = '_notify-validate'; |
| 513 | 513 | |
| 514 | 514 | // Send back post vars to paypal. |
@@ -522,18 +522,18 @@ discard block |
||
| 522 | 522 | ); |
| 523 | 523 | |
| 524 | 524 | // Post back to get a response. |
| 525 | - $response = wp_safe_remote_post( $this->is_sandbox() ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
| 525 | + $response = wp_safe_remote_post($this->is_sandbox() ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params); |
|
| 526 | 526 | |
| 527 | 527 | // Check to see if the request was valid. |
| 528 | - if ( ! is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
| 529 | - wpinv_error_log( $response['body'], 'Received valid response from PayPal IPN' ); |
|
| 528 | + if (!is_wp_error($response) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 && strstr($response['body'], 'VERIFIED')) { |
|
| 529 | + wpinv_error_log($response['body'], 'Received valid response from PayPal IPN'); |
|
| 530 | 530 | return true; |
| 531 | 531 | } |
| 532 | 532 | |
| 533 | - if ( is_wp_error( $response ) ) { |
|
| 534 | - wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
| 533 | + if (is_wp_error($response)) { |
|
| 534 | + wpinv_error_log($response->get_error_message(), 'Received invalid response from PayPal IPN'); |
|
| 535 | 535 | } else { |
| 536 | - wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
| 536 | + wpinv_error_log($response['body'], 'Received invalid response from PayPal IPN'); |
|
| 537 | 537 | } |
| 538 | 538 | |
| 539 | 539 | return false; |
@@ -546,12 +546,12 @@ discard block |
||
| 546 | 546 | * @param WPInv_Invoice $invoice Invoice object. |
| 547 | 547 | * @param string $currency currency to validate. |
| 548 | 548 | */ |
| 549 | - protected function validate_ipn_currency( $invoice, $currency ) { |
|
| 550 | - if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
| 551 | - wpinv_record_gateway_error( 'IPN Error', "Currencies do not match: {$currency} instead of {$invoice->get_currency()}" ); |
|
| 549 | + protected function validate_ipn_currency($invoice, $currency) { |
|
| 550 | + if (strtolower($invoice->get_currency()) !== strtolower($currency)) { |
|
| 551 | + wpinv_record_gateway_error('IPN Error', "Currencies do not match: {$currency} instead of {$invoice->get_currency()}"); |
|
| 552 | 552 | |
| 553 | 553 | /* translators: %s: currency code. */ |
| 554 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
| 554 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal currencies do not match (code %s).', 'invoicing'), $currency)); |
|
| 555 | 555 | exit; |
| 556 | 556 | } |
| 557 | 557 | } |
@@ -562,12 +562,12 @@ discard block |
||
| 562 | 562 | * @param WPInv_Invoice $invoice Invoice object. |
| 563 | 563 | * @param float $amount amount to validate. |
| 564 | 564 | */ |
| 565 | - protected function validate_ipn_amount( $invoice, $amount ) { |
|
| 566 | - if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
| 567 | - wpinv_record_gateway_error( 'IPN Error', "Amounts do not match: {$amount} instead of {$invoice->get_total()}" ); |
|
| 565 | + protected function validate_ipn_amount($invoice, $amount) { |
|
| 566 | + if (number_format($invoice->get_total(), 2, '.', '') !== number_format($amount, 2, '.', '')) { |
|
| 567 | + wpinv_record_gateway_error('IPN Error', "Amounts do not match: {$amount} instead of {$invoice->get_total()}"); |
|
| 568 | 568 | |
| 569 | 569 | /* translators: %s: Amount. */ |
| 570 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
| 570 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal amounts do not match (gross %s).', 'invoicing'), $amount)); |
|
| 571 | 571 | exit; |
| 572 | 572 | } |
| 573 | 573 | } |
@@ -578,14 +578,14 @@ discard block |
||
| 578 | 578 | * @param WPInv_Invoice $invoice Invoice object. |
| 579 | 579 | * @param string $receiver_email Email to validate. |
| 580 | 580 | */ |
| 581 | - protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
| 582 | - $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
| 581 | + protected function validate_ipn_receiver_email($invoice, $receiver_email) { |
|
| 582 | + $paypal_email = wpinv_get_option('paypal_email'); |
|
| 583 | 583 | |
| 584 | - if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
| 585 | - wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
| 584 | + if (strcasecmp(trim($receiver_email), trim($paypal_email)) !== 0) { |
|
| 585 | + wpinv_record_gateway_error('IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}"); |
|
| 586 | 586 | |
| 587 | 587 | /* translators: %s: email address . */ |
| 588 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
| 588 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal IPN response from a different email address (%s).', 'invoicing'), $receiver_email)); |
|
| 589 | 589 | exit; |
| 590 | 590 | } |
| 591 | 591 | |
@@ -597,57 +597,57 @@ discard block |
||
| 597 | 597 | * @param WPInv_Invoice $invoice Invoice object. |
| 598 | 598 | * @param array $posted Posted data. |
| 599 | 599 | */ |
| 600 | - protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
| 600 | + protected function ipn_txn_web_accept($invoice, $posted) { |
|
| 601 | 601 | |
| 602 | 602 | // Collect payment details |
| 603 | - $payment_status = strtolower( $posted['payment_status'] ); |
|
| 604 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
| 603 | + $payment_status = strtolower($posted['payment_status']); |
|
| 604 | + $business_email = isset($posted['business']) && is_email($posted['business']) ? trim($posted['business']) : trim($posted['receiver_email']); |
|
| 605 | 605 | |
| 606 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
| 607 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
| 606 | + $this->validate_ipn_receiver_email($invoice, $business_email); |
|
| 607 | + $this->validate_ipn_currency($invoice, $posted['mc_currency']); |
|
| 608 | 608 | |
| 609 | 609 | // Update the transaction id. |
| 610 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
| 611 | - $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
| 610 | + if (!empty($posted['txn_id'])) { |
|
| 611 | + $invoice->set_transaction_id(wpinv_clean($posted['txn_id'])); |
|
| 612 | 612 | $invoice->save(); |
| 613 | 613 | } |
| 614 | 614 | |
| 615 | 615 | // Process a refund. |
| 616 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
| 616 | + if ($payment_status == 'refunded' || $payment_status == 'reversed') { |
|
| 617 | 617 | |
| 618 | - update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
| 618 | + update_post_meta($invoice->get_id(), 'refunded_remotely', 1); |
|
| 619 | 619 | |
| 620 | - if ( ! $invoice->is_refunded() ) { |
|
| 621 | - $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
| 620 | + if (!$invoice->is_refunded()) { |
|
| 621 | + $invoice->update_status('wpi-refunded', $posted['reason_code']); |
|
| 622 | 622 | } |
| 623 | 623 | |
| 624 | 624 | exit; |
| 625 | 625 | } |
| 626 | 626 | |
| 627 | 627 | // Process payments. |
| 628 | - if ( $payment_status == 'completed' ) { |
|
| 628 | + if ($payment_status == 'completed') { |
|
| 629 | 629 | |
| 630 | - if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
| 631 | - wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already complete.' ); |
|
| 630 | + if ($invoice->is_paid() && 'wpi_processing' != $invoice->get_status()) { |
|
| 631 | + wpinv_error_log('Aborting, Invoice #' . $invoice->get_number() . ' is already complete.'); |
|
| 632 | 632 | exit; |
| 633 | 633 | } |
| 634 | 634 | |
| 635 | - $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
| 635 | + $this->validate_ipn_amount($invoice, $posted['mc_gross']); |
|
| 636 | 636 | |
| 637 | - if ( 'completed' === $payment_status || 'pending' === $payment_status ) { |
|
| 637 | + if ('completed' === $payment_status || 'pending' === $payment_status) { |
|
| 638 | 638 | |
| 639 | 639 | $note = ''; |
| 640 | 640 | |
| 641 | - if ( ! empty( $posted['mc_fee'] ) ) { |
|
| 642 | - $note = sprintf( __( 'PayPal Transaction Fee %s', 'invoicing' ), wpinv_clean( $posted['mc_fee'] ) ); |
|
| 641 | + if (!empty($posted['mc_fee'])) { |
|
| 642 | + $note = sprintf(__('PayPal Transaction Fee %s', 'invoicing'), wpinv_clean($posted['mc_fee'])); |
|
| 643 | 643 | } |
| 644 | 644 | |
| 645 | - $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? wpinv_clean( $posted['txn_id'] ) : '' ), $note ); |
|
| 645 | + $invoice->mark_paid((!empty($posted['txn_id']) ? wpinv_clean($posted['txn_id']) : ''), $note); |
|
| 646 | 646 | |
| 647 | 647 | } else { |
| 648 | 648 | |
| 649 | 649 | /* translators: %s: pending reason. */ |
| 650 | - $invoice->update_status( 'wpi_processing', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
| 650 | + $invoice->update_status('wpi_processing', sprintf(__('Payment pending (%s).', 'invoicing'), $posted['pending_reason'])); |
|
| 651 | 651 | |
| 652 | 652 | } |
| 653 | 653 | |
@@ -658,7 +658,7 @@ discard block |
||
| 658 | 658 | // Process failures. |
| 659 | 659 | |
| 660 | 660 | /* translators: %s: payment status. */ |
| 661 | - $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), wpinv_clean( $posted['payment_status'] ) ) ); |
|
| 661 | + $invoice->update_status('wpi-failed', sprintf(__('Payment %s via IPN.', 'invoicing'), wpinv_clean($posted['payment_status']))); |
|
| 662 | 662 | |
| 663 | 663 | } |
| 664 | 664 | |
@@ -668,8 +668,8 @@ discard block |
||
| 668 | 668 | * @param WPInv_Invoice $invoice Invoice object. |
| 669 | 669 | * @param array $posted Posted data. |
| 670 | 670 | */ |
| 671 | - protected function ipn_txn_cart( $invoice, $posted ) { |
|
| 672 | - $this->ipn_txn_web_accept( $invoice, $posted ); |
|
| 671 | + protected function ipn_txn_cart($invoice, $posted) { |
|
| 672 | + $this->ipn_txn_web_accept($invoice, $posted); |
|
| 673 | 673 | } |
| 674 | 674 | |
| 675 | 675 | /** |
@@ -678,39 +678,39 @@ discard block |
||
| 678 | 678 | * @param WPInv_Invoice $invoice Invoice object. |
| 679 | 679 | * @param array $posted Posted data. |
| 680 | 680 | */ |
| 681 | - protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
| 681 | + protected function ipn_txn_subscr_signup($invoice, $posted) { |
|
| 682 | 682 | |
| 683 | 683 | // Make sure the invoice has a subscription. |
| 684 | - $subscription = wpinv_get_subscription( $invoice ); |
|
| 684 | + $subscription = wpinv_get_subscription($invoice); |
|
| 685 | 685 | |
| 686 | - if ( empty( $subscription ) ) { |
|
| 687 | - wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
| 686 | + if (empty($subscription)) { |
|
| 687 | + wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found'); |
|
| 688 | 688 | } |
| 689 | 689 | |
| 690 | 690 | // Update the subscription ids. |
| 691 | 691 | $subscription->update( |
| 692 | 692 | array( |
| 693 | - 'profile_id' => sanitize_text_field( $posted['subscr_id'] ), |
|
| 693 | + 'profile_id' => sanitize_text_field($posted['subscr_id']), |
|
| 694 | 694 | ) |
| 695 | 695 | ); |
| 696 | 696 | |
| 697 | 697 | // Set the transaction id. |
| 698 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
| 699 | - $invoice->set_transaction_id( $posted['txn_id'] ); |
|
| 698 | + if (!empty($posted['txn_id'])) { |
|
| 699 | + $invoice->set_transaction_id($posted['txn_id']); |
|
| 700 | 700 | } |
| 701 | 701 | |
| 702 | 702 | // Update the payment status. |
| 703 | 703 | $invoice->mark_paid(); |
| 704 | 704 | |
| 705 | - $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
| 705 | + $invoice->add_note(sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true); |
|
| 706 | 706 | |
| 707 | 707 | // Update the subscription duration. |
| 708 | - $duration = strtotime( $subscription->expiration ) - strtotime( $subscription->created ); |
|
| 708 | + $duration = strtotime($subscription->expiration) - strtotime($subscription->created); |
|
| 709 | 709 | $subscription->update( |
| 710 | 710 | array( |
| 711 | 711 | 'status' => 'trialling' == $subscription->status ? 'trialling' : 'active', |
| 712 | - 'created' => current_time( 'mysql' ), |
|
| 713 | - 'expiration' => date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ), |
|
| 712 | + 'created' => current_time('mysql'), |
|
| 713 | + 'expiration' => date('Y-m-d H:i:s', (current_time('timestamp') + $duration)), |
|
| 714 | 714 | ) |
| 715 | 715 | ); |
| 716 | 716 | |
@@ -722,25 +722,25 @@ discard block |
||
| 722 | 722 | * @param WPInv_Invoice $invoice Invoice object. |
| 723 | 723 | * @param array $posted Posted data. |
| 724 | 724 | */ |
| 725 | - protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
| 725 | + protected function ipn_txn_subscr_payment($invoice, $posted) { |
|
| 726 | 726 | |
| 727 | 727 | // Make sure the invoice has a subscription. |
| 728 | - $subscription = wpinv_get_subscription( $invoice ); |
|
| 728 | + $subscription = wpinv_get_subscription($invoice); |
|
| 729 | 729 | |
| 730 | - if ( empty( $subscription ) ) { |
|
| 731 | - wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
| 730 | + if (empty($subscription)) { |
|
| 731 | + wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found'); |
|
| 732 | 732 | } |
| 733 | 733 | |
| 734 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
| 734 | + $this->validate_ipn_currency($invoice, $posted['mc_currency']); |
|
| 735 | 735 | |
| 736 | 736 | // Abort if the payment is already recorded. |
| 737 | - if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
| 737 | + if (wpinv_get_id_by_transaction_id($posted['txn_id'])) { |
|
| 738 | 738 | return; |
| 739 | 739 | } |
| 740 | 740 | |
| 741 | 741 | // Abort if this is the first payment. |
| 742 | - if ( date( 'Ynd', $subscription->created ) == date( 'Ynd', strtotime( $posted['payment_date'] ) ) ) { |
|
| 743 | - $invoice->set_transaction_id( $posted['txn_id'] ); |
|
| 742 | + if (date('Ynd', $subscription->created) == date('Ynd', strtotime($posted['payment_date']))) { |
|
| 743 | + $invoice->set_transaction_id($posted['txn_id']); |
|
| 744 | 744 | $invoice->save(); |
| 745 | 745 | return; |
| 746 | 746 | } |
@@ -751,14 +751,14 @@ discard block |
||
| 751 | 751 | 'gateway' => $this->id, |
| 752 | 752 | ); |
| 753 | 753 | |
| 754 | - $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
| 754 | + $invoice = wpinv_get_invoice($subscription->add_payment($args)); |
|
| 755 | 755 | |
| 756 | - if ( empty( $invoice ) ) { |
|
| 756 | + if (empty($invoice)) { |
|
| 757 | 757 | return; |
| 758 | 758 | } |
| 759 | 759 | |
| 760 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
| 761 | - $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
| 760 | + $invoice->add_note(wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $posted['txn_id']), false, false, true); |
|
| 761 | + $invoice->add_note(wp_sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true); |
|
| 762 | 762 | |
| 763 | 763 | $subscription->renew(); |
| 764 | 764 | |
@@ -770,9 +770,9 @@ discard block |
||
| 770 | 770 | * @param WPInv_Invoice $invoice Invoice object. |
| 771 | 771 | * @param array $posted Posted data. |
| 772 | 772 | */ |
| 773 | - protected function ipn_txn_subscr_cancel( $invoice, $posted ) { |
|
| 773 | + protected function ipn_txn_subscr_cancel($invoice, $posted) { |
|
| 774 | 774 | |
| 775 | - if ( $subscription = wpinv_get_subscription( $invoice ) ) { |
|
| 775 | + if ($subscription = wpinv_get_subscription($invoice)) { |
|
| 776 | 776 | $subscription->cancel(); |
| 777 | 777 | } |
| 778 | 778 | |
@@ -784,9 +784,9 @@ discard block |
||
| 784 | 784 | * @param WPInv_Invoice $invoice Invoice object. |
| 785 | 785 | * @param array $posted Posted data. |
| 786 | 786 | */ |
| 787 | - protected function ipn_txn_subscr_eot( $invoice, $posted ) { |
|
| 787 | + protected function ipn_txn_subscr_eot($invoice, $posted) { |
|
| 788 | 788 | |
| 789 | - if ( $subscription = wpinv_get_subscription( $invoice ) ) { |
|
| 789 | + if ($subscription = wpinv_get_subscription($invoice)) { |
|
| 790 | 790 | $subscription->complete(); |
| 791 | 791 | } |
| 792 | 792 | |
@@ -798,9 +798,9 @@ discard block |
||
| 798 | 798 | * @param WPInv_Invoice $invoice Invoice object. |
| 799 | 799 | * @param array $posted Posted data. |
| 800 | 800 | */ |
| 801 | - protected function ipn_txn_subscr_failed( $invoice, $posted ) { |
|
| 801 | + protected function ipn_txn_subscr_failed($invoice, $posted) { |
|
| 802 | 802 | |
| 803 | - if ( $subscription = wpinv_get_subscription( $invoice ) ) { |
|
| 803 | + if ($subscription = wpinv_get_subscription($invoice)) { |
|
| 804 | 804 | $subscription->failing(); |
| 805 | 805 | } |
| 806 | 806 | |
@@ -809,10 +809,10 @@ discard block |
||
| 809 | 809 | /** |
| 810 | 810 | * Displays a notice on the checkout page if sandbox is enabled. |
| 811 | 811 | */ |
| 812 | - public function sandbox_notice( $description, $gateway ) { |
|
| 813 | - if ( 'paypal' == $gateway && wpinv_is_test_mode( 'paypal' ) ) { |
|
| 812 | + public function sandbox_notice($description, $gateway) { |
|
| 813 | + if ('paypal' == $gateway && wpinv_is_test_mode('paypal')) { |
|
| 814 | 814 | $description .= '<br>' . sprintf( |
| 815 | - __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ), |
|
| 815 | + __('SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing'), |
|
| 816 | 816 | '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
| 817 | 817 | '</a>' |
| 818 | 818 | ); |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * @package Invoicing |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -defined( 'ABSPATH' ) || exit; |
|
| 9 | +defined('ABSPATH') || exit; |
|
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * Retrieves an item by it's ID. |
@@ -14,9 +14,9 @@ discard block |
||
| 14 | 14 | * @param int the item ID to retrieve. |
| 15 | 15 | * @return WPInv_Item|false |
| 16 | 16 | */ |
| 17 | -function wpinv_get_item_by_id( $id ) { |
|
| 18 | - $item = wpinv_get_item( $id ); |
|
| 19 | - return empty( $item ) || $id != $item->get_id() ? false : $item; |
|
| 17 | +function wpinv_get_item_by_id($id) { |
|
| 18 | + $item = wpinv_get_item($id); |
|
| 19 | + return empty($item) || $id != $item->get_id() ? false : $item; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -24,14 +24,14 @@ discard block |
||
| 24 | 24 | * |
| 25 | 25 | * @return WPInv_Item|false |
| 26 | 26 | */ |
| 27 | -function wpinv_get_item_by( $field = '', $value = '', $type = '' ) { |
|
| 27 | +function wpinv_get_item_by($field = '', $value = '', $type = '') { |
|
| 28 | 28 | |
| 29 | - if ( 'id' == strtolower( $field ) ) { |
|
| 30 | - return wpinv_get_item_by_id( $field ); |
|
| 29 | + if ('id' == strtolower($field)) { |
|
| 30 | + return wpinv_get_item_by_id($field); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - $id = WPInv_Item::get_item_id_by_field( $value, strtolower( $field ), $type ); |
|
| 34 | - return $id ? wpinv_get_item( $id ) : false; |
|
| 33 | + $id = WPInv_Item::get_item_id_by_field($value, strtolower($field), $type); |
|
| 34 | + return $id ? wpinv_get_item($id) : false; |
|
| 35 | 35 | |
| 36 | 36 | } |
| 37 | 37 | |
@@ -41,22 +41,22 @@ discard block |
||
| 41 | 41 | * @param int|WPInv_Item the item to retrieve. |
| 42 | 42 | * @return WPInv_Item|false |
| 43 | 43 | */ |
| 44 | -function wpinv_get_item( $item = 0 ) { |
|
| 44 | +function wpinv_get_item($item = 0) { |
|
| 45 | 45 | |
| 46 | - if ( empty( $item ) ) { |
|
| 46 | + if (empty($item)) { |
|
| 47 | 47 | return false; |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - $item = new WPInv_Item( $item ); |
|
| 50 | + $item = new WPInv_Item($item); |
|
| 51 | 51 | return $item->get_id() ? $item : false; |
| 52 | 52 | |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | -function wpinv_get_all_items( $args = array() ) { |
|
| 55 | +function wpinv_get_all_items($args = array()) { |
|
| 56 | 56 | |
| 57 | - $args = wp_parse_args( $args, array( |
|
| 58 | - 'status' => array( 'publish' ), |
|
| 59 | - 'limit' => get_option( 'posts_per_page' ), |
|
| 57 | + $args = wp_parse_args($args, array( |
|
| 58 | + 'status' => array('publish'), |
|
| 59 | + 'limit' => get_option('posts_per_page'), |
|
| 60 | 60 | 'page' => 1, |
| 61 | 61 | 'exclude' => array(), |
| 62 | 62 | 'orderby' => 'date', |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | 'meta_query' => array(), |
| 66 | 66 | 'return' => 'objects', |
| 67 | 67 | 'paginate' => false, |
| 68 | - ) ); |
|
| 68 | + )); |
|
| 69 | 69 | |
| 70 | 70 | $wp_query_args = array( |
| 71 | 71 | 'post_type' => 'wpi_item', |
@@ -75,26 +75,26 @@ discard block |
||
| 75 | 75 | 'fields' => 'ids', |
| 76 | 76 | 'orderby' => $args['orderby'], |
| 77 | 77 | 'order' => $args['order'], |
| 78 | - 'paged' => absint( $args['page'] ), |
|
| 78 | + 'paged' => absint($args['page']), |
|
| 79 | 79 | ); |
| 80 | 80 | |
| 81 | - if ( ! empty( $args['exclude'] ) ) { |
|
| 82 | - $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] ); |
|
| 81 | + if (!empty($args['exclude'])) { |
|
| 82 | + $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - if ( ! $args['paginate' ] ) { |
|
| 85 | + if (!$args['paginate']) { |
|
| 86 | 86 | $wp_query_args['no_found_rows'] = true; |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - if ( ! empty( $args['search'] ) ) { |
|
| 89 | + if (!empty($args['search'])) { |
|
| 90 | 90 | $wp_query_args['s'] = $args['search']; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - if ( ! empty( $args['type'] ) && $args['type'] !== wpinv_item_types() ) { |
|
| 94 | - $types = wpinv_parse_list( $args['type'] ); |
|
| 93 | + if (!empty($args['type']) && $args['type'] !== wpinv_item_types()) { |
|
| 94 | + $types = wpinv_parse_list($args['type']); |
|
| 95 | 95 | $wp_query_args['meta_query'][] = array( |
| 96 | 96 | 'key' => '_wpinv_type', |
| 97 | - 'value' => implode( ',', $types ), |
|
| 97 | + 'value' => implode(',', $types), |
|
| 98 | 98 | 'compare' => 'IN', |
| 99 | 99 | ); |
| 100 | 100 | } |
@@ -102,17 +102,17 @@ discard block |
||
| 102 | 102 | $wp_query_args = apply_filters('wpinv_get_items_args', $wp_query_args, $args); |
| 103 | 103 | |
| 104 | 104 | // Get results. |
| 105 | - $items = new WP_Query( $wp_query_args ); |
|
| 105 | + $items = new WP_Query($wp_query_args); |
|
| 106 | 106 | |
| 107 | - if ( 'objects' === $args['return'] ) { |
|
| 108 | - $return = array_map( 'wpinv_get_item_by_id', $items->posts ); |
|
| 109 | - } elseif ( 'self' === $args['return'] ) { |
|
| 107 | + if ('objects' === $args['return']) { |
|
| 108 | + $return = array_map('wpinv_get_item_by_id', $items->posts); |
|
| 109 | + } elseif ('self' === $args['return']) { |
|
| 110 | 110 | return $items; |
| 111 | 111 | } else { |
| 112 | 112 | $return = $items->posts; |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - if ( $args['paginate' ] ) { |
|
| 115 | + if ($args['paginate']) { |
|
| 116 | 116 | return (object) array( |
| 117 | 117 | 'items' => $return, |
| 118 | 118 | 'total' => $items->found_posts, |
@@ -124,12 +124,12 @@ discard block |
||
| 124 | 124 | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | -function wpinv_is_free_item( $item_id = 0 ) { |
|
| 128 | - if( empty( $item_id ) ) { |
|
| 127 | +function wpinv_is_free_item($item_id = 0) { |
|
| 128 | + if (empty($item_id)) { |
|
| 129 | 129 | return false; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - $item = new WPInv_Item( $item_id ); |
|
| 132 | + $item = new WPInv_Item($item_id); |
|
| 133 | 133 | |
| 134 | 134 | return $item->is_free(); |
| 135 | 135 | } |
@@ -139,128 +139,128 @@ discard block |
||
| 139 | 139 | * |
| 140 | 140 | * @param WP_Post|WPInv_Item|Int $item The item to check for. |
| 141 | 141 | */ |
| 142 | -function wpinv_item_is_editable( $item = 0 ) { |
|
| 142 | +function wpinv_item_is_editable($item = 0) { |
|
| 143 | 143 | |
| 144 | 144 | // Fetch the item. |
| 145 | - $item = new WPInv_Item( $item ); |
|
| 145 | + $item = new WPInv_Item($item); |
|
| 146 | 146 | |
| 147 | 147 | // Check if it is editable. |
| 148 | 148 | return $item->is_editable(); |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | -function wpinv_get_item_price( $item_id = 0 ) { |
|
| 152 | - if( empty( $item_id ) ) { |
|
| 151 | +function wpinv_get_item_price($item_id = 0) { |
|
| 152 | + if (empty($item_id)) { |
|
| 153 | 153 | return false; |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - $item = new WPInv_Item( $item_id ); |
|
| 156 | + $item = new WPInv_Item($item_id); |
|
| 157 | 157 | |
| 158 | 158 | return $item->get_price(); |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | -function wpinv_is_recurring_item( $item_id = 0 ) { |
|
| 162 | - if( empty( $item_id ) ) { |
|
| 161 | +function wpinv_is_recurring_item($item_id = 0) { |
|
| 162 | + if (empty($item_id)) { |
|
| 163 | 163 | return false; |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | - $item = new WPInv_Item( $item_id ); |
|
| 166 | + $item = new WPInv_Item($item_id); |
|
| 167 | 167 | |
| 168 | 168 | return $item->is_recurring(); |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | -function wpinv_item_price( $item_id = 0 ) { |
|
| 172 | - if( empty( $item_id ) ) { |
|
| 171 | +function wpinv_item_price($item_id = 0) { |
|
| 172 | + if (empty($item_id)) { |
|
| 173 | 173 | return false; |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - $price = wpinv_get_item_price( $item_id ); |
|
| 177 | - $price = wpinv_price( wpinv_format_amount( $price ) ); |
|
| 176 | + $price = wpinv_get_item_price($item_id); |
|
| 177 | + $price = wpinv_price(wpinv_format_amount($price)); |
|
| 178 | 178 | |
| 179 | - return apply_filters( 'wpinv_item_price', $price, $item_id ); |
|
| 179 | + return apply_filters('wpinv_item_price', $price, $item_id); |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | -function wpinv_item_show_price( $item_id = 0, $echo = true ) { |
|
| 183 | - if ( empty( $item_id ) ) { |
|
| 182 | +function wpinv_item_show_price($item_id = 0, $echo = true) { |
|
| 183 | + if (empty($item_id)) { |
|
| 184 | 184 | $item_id = get_the_ID(); |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | - $price = wpinv_item_price( $item_id ); |
|
| 187 | + $price = wpinv_item_price($item_id); |
|
| 188 | 188 | |
| 189 | - $price = apply_filters( 'wpinv_item_price', wpinv_sanitize_amount( $price ), $item_id ); |
|
| 189 | + $price = apply_filters('wpinv_item_price', wpinv_sanitize_amount($price), $item_id); |
|
| 190 | 190 | $formatted_price = '<span class="wpinv_price" id="wpinv_item_' . $item_id . '">' . $price . '</span>'; |
| 191 | - $formatted_price = apply_filters( 'wpinv_item_price_after_html', $formatted_price, $item_id, $price ); |
|
| 191 | + $formatted_price = apply_filters('wpinv_item_price_after_html', $formatted_price, $item_id, $price); |
|
| 192 | 192 | |
| 193 | - if ( $echo ) { |
|
| 193 | + if ($echo) { |
|
| 194 | 194 | echo $formatted_price; |
| 195 | 195 | } else { |
| 196 | 196 | return $formatted_price; |
| 197 | 197 | } |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | -function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) { |
|
| 201 | - if ( is_null( $amount_override ) ) { |
|
| 202 | - $original_price = get_post_meta( $item_id, '_wpinv_price', true ); |
|
| 200 | +function wpinv_get_item_final_price($item_id = 0, $amount_override = null) { |
|
| 201 | + if (is_null($amount_override)) { |
|
| 202 | + $original_price = get_post_meta($item_id, '_wpinv_price', true); |
|
| 203 | 203 | } else { |
| 204 | 204 | $original_price = $amount_override; |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | $price = $original_price; |
| 208 | 208 | |
| 209 | - return apply_filters( 'wpinv_get_item_final_price', $price, $item_id ); |
|
| 209 | + return apply_filters('wpinv_get_item_final_price', $price, $item_id); |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | -function wpinv_item_custom_singular_name( $item_id ) { |
|
| 213 | - if( empty( $item_id ) ) { |
|
| 212 | +function wpinv_item_custom_singular_name($item_id) { |
|
| 213 | + if (empty($item_id)) { |
|
| 214 | 214 | return false; |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | - $item = new WPInv_Item( $item_id ); |
|
| 217 | + $item = new WPInv_Item($item_id); |
|
| 218 | 218 | |
| 219 | 219 | return $item->get_custom_singular_name(); |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | function wpinv_get_item_types() { |
| 223 | 223 | $item_types = array( |
| 224 | - 'custom' => __( 'Standard', 'invoicing' ), |
|
| 225 | - 'fee' => __( 'Fee', 'invoicing' ), |
|
| 224 | + 'custom' => __('Standard', 'invoicing'), |
|
| 225 | + 'fee' => __('Fee', 'invoicing'), |
|
| 226 | 226 | ); |
| 227 | - return apply_filters( 'wpinv_get_item_types', $item_types ); |
|
| 227 | + return apply_filters('wpinv_get_item_types', $item_types); |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | function wpinv_item_types() { |
| 231 | 231 | $item_types = wpinv_get_item_types(); |
| 232 | 232 | |
| 233 | - return ( !empty( $item_types ) ? array_keys( $item_types ) : array() ); |
|
| 233 | + return (!empty($item_types) ? array_keys($item_types) : array()); |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | -function wpinv_get_item_type( $item_id ) { |
|
| 237 | - if( empty( $item_id ) ) { |
|
| 236 | +function wpinv_get_item_type($item_id) { |
|
| 237 | + if (empty($item_id)) { |
|
| 238 | 238 | return false; |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | - $item = new WPInv_Item( $item_id ); |
|
| 241 | + $item = new WPInv_Item($item_id); |
|
| 242 | 242 | |
| 243 | 243 | return $item->get_type(); |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | -function wpinv_item_type( $item_id ) { |
|
| 246 | +function wpinv_item_type($item_id) { |
|
| 247 | 247 | $item_types = wpinv_get_item_types(); |
| 248 | 248 | |
| 249 | - $item_type = wpinv_get_item_type( $item_id ); |
|
| 249 | + $item_type = wpinv_get_item_type($item_id); |
|
| 250 | 250 | |
| 251 | - if ( empty( $item_type ) ) { |
|
| 251 | + if (empty($item_type)) { |
|
| 252 | 252 | $item_type = '-'; |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | - $item_type = isset( $item_types[$item_type] ) ? $item_types[$item_type] : __( $item_type, 'invoicing' ); |
|
| 255 | + $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing'); |
|
| 256 | 256 | |
| 257 | - return apply_filters( 'wpinv_item_type', $item_type, $item_id ); |
|
| 257 | + return apply_filters('wpinv_item_type', $item_type, $item_id); |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | -function wpinv_record_item_in_log( $item_id = 0, $file_id, $user_info, $ip, $invoice_id ) { |
|
| 260 | +function wpinv_record_item_in_log($item_id = 0, $file_id, $user_info, $ip, $invoice_id) { |
|
| 261 | 261 | global $wpinv_logs; |
| 262 | 262 | |
| 263 | - if ( empty( $wpinv_logs ) ) { |
|
| 263 | + if (empty($wpinv_logs)) { |
|
| 264 | 264 | return false; |
| 265 | 265 | } |
| 266 | 266 | |
@@ -269,278 +269,278 @@ discard block |
||
| 269 | 269 | 'log_type' => 'wpi_item' |
| 270 | 270 | ); |
| 271 | 271 | |
| 272 | - $user_id = isset( $user_info['user_id'] ) ? $user_info['user_id'] : (int) -1; |
|
| 272 | + $user_id = isset($user_info['user_id']) ? $user_info['user_id'] : (int) -1; |
|
| 273 | 273 | |
| 274 | 274 | $log_meta = array( |
| 275 | 275 | 'user_info' => $user_info, |
| 276 | 276 | 'user_id' => $user_id, |
| 277 | - 'file_id' => (int)$file_id, |
|
| 277 | + 'file_id' => (int) $file_id, |
|
| 278 | 278 | 'ip' => $ip, |
| 279 | 279 | 'invoice_id'=> $invoice_id, |
| 280 | 280 | ); |
| 281 | 281 | |
| 282 | - $wpinv_logs->insert_log( $log_data, $log_meta ); |
|
| 282 | + $wpinv_logs->insert_log($log_data, $log_meta); |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | -function wpinv_remove_item_logs_on_delete( $item_id = 0 ) { |
|
| 286 | - if ( 'wpi_item' !== get_post_type( $item_id ) ) |
|
| 285 | +function wpinv_remove_item_logs_on_delete($item_id = 0) { |
|
| 286 | + if ('wpi_item' !== get_post_type($item_id)) |
|
| 287 | 287 | return; |
| 288 | 288 | |
| 289 | 289 | global $wpinv_logs; |
| 290 | 290 | |
| 291 | - if ( empty( $wpinv_logs ) ) { |
|
| 291 | + if (empty($wpinv_logs)) { |
|
| 292 | 292 | return false; |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | // Remove all log entries related to this item |
| 296 | - $wpinv_logs->delete_logs( $item_id ); |
|
| 296 | + $wpinv_logs->delete_logs($item_id); |
|
| 297 | 297 | } |
| 298 | -add_action( 'delete_post', 'wpinv_remove_item_logs_on_delete' ); |
|
| 298 | +add_action('delete_post', 'wpinv_remove_item_logs_on_delete'); |
|
| 299 | 299 | |
| 300 | -function wpinv_get_random_item( $post_ids = true ) { |
|
| 301 | - wpinv_get_random_items( 1, $post_ids ); |
|
| 300 | +function wpinv_get_random_item($post_ids = true) { |
|
| 301 | + wpinv_get_random_items(1, $post_ids); |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | -function wpinv_get_random_items( $num = 3, $post_ids = true ) { |
|
| 305 | - if ( $post_ids ) { |
|
| 306 | - $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids' ); |
|
| 304 | +function wpinv_get_random_items($num = 3, $post_ids = true) { |
|
| 305 | + if ($post_ids) { |
|
| 306 | + $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids'); |
|
| 307 | 307 | } else { |
| 308 | - $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num ); |
|
| 308 | + $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num); |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | - $args = apply_filters( 'wpinv_get_random_items', $args ); |
|
| 311 | + $args = apply_filters('wpinv_get_random_items', $args); |
|
| 312 | 312 | |
| 313 | - return get_posts( $args ); |
|
| 313 | + return get_posts($args); |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | -function wpinv_get_item_token( $url = '' ) { |
|
| 316 | +function wpinv_get_item_token($url = '') { |
|
| 317 | 317 | $args = array(); |
| 318 | - $hash = apply_filters( 'wpinv_get_url_token_algorithm', 'sha256' ); |
|
| 319 | - $secret = apply_filters( 'wpinv_get_url_token_secret', hash( $hash, wp_salt() ) ); |
|
| 318 | + $hash = apply_filters('wpinv_get_url_token_algorithm', 'sha256'); |
|
| 319 | + $secret = apply_filters('wpinv_get_url_token_secret', hash($hash, wp_salt())); |
|
| 320 | 320 | |
| 321 | - $parts = parse_url( $url ); |
|
| 321 | + $parts = parse_url($url); |
|
| 322 | 322 | $options = array(); |
| 323 | 323 | |
| 324 | - if ( isset( $parts['query'] ) ) { |
|
| 325 | - wp_parse_str( $parts['query'], $query_args ); |
|
| 324 | + if (isset($parts['query'])) { |
|
| 325 | + wp_parse_str($parts['query'], $query_args); |
|
| 326 | 326 | |
| 327 | - if ( ! empty( $query_args['o'] ) ) { |
|
| 328 | - $options = explode( ':', rawurldecode( $query_args['o'] ) ); |
|
| 327 | + if (!empty($query_args['o'])) { |
|
| 328 | + $options = explode(':', rawurldecode($query_args['o'])); |
|
| 329 | 329 | |
| 330 | - if ( in_array( 'ip', $options ) ) { |
|
| 330 | + if (in_array('ip', $options)) { |
|
| 331 | 331 | $args['ip'] = wpinv_get_ip(); |
| 332 | 332 | } |
| 333 | 333 | |
| 334 | - if ( in_array( 'ua', $options ) ) { |
|
| 334 | + if (in_array('ua', $options)) { |
|
| 335 | 335 | $ua = wpinv_get_user_agent(); |
| 336 | - $args['user_agent'] = rawurlencode( $ua ); |
|
| 336 | + $args['user_agent'] = rawurlencode($ua); |
|
| 337 | 337 | } |
| 338 | 338 | } |
| 339 | 339 | } |
| 340 | 340 | |
| 341 | - $args = apply_filters( 'wpinv_get_url_token_args', $args, $url, $options ); |
|
| 341 | + $args = apply_filters('wpinv_get_url_token_args', $args, $url, $options); |
|
| 342 | 342 | |
| 343 | 343 | $args['secret'] = $secret; |
| 344 | 344 | $args['token'] = false; |
| 345 | 345 | |
| 346 | - $url = add_query_arg( $args, $url ); |
|
| 347 | - $parts = parse_url( $url ); |
|
| 346 | + $url = add_query_arg($args, $url); |
|
| 347 | + $parts = parse_url($url); |
|
| 348 | 348 | |
| 349 | - if ( ! isset( $parts['path'] ) ) { |
|
| 349 | + if (!isset($parts['path'])) { |
|
| 350 | 350 | $parts['path'] = ''; |
| 351 | 351 | } |
| 352 | 352 | |
| 353 | - $token = md5( $parts['path'] . '?' . $parts['query'] ); |
|
| 353 | + $token = md5($parts['path'] . '?' . $parts['query']); |
|
| 354 | 354 | |
| 355 | 355 | return $token; |
| 356 | 356 | } |
| 357 | 357 | |
| 358 | -function wpinv_validate_url_token( $url = '' ) { |
|
| 358 | +function wpinv_validate_url_token($url = '') { |
|
| 359 | 359 | $ret = false; |
| 360 | - $parts = parse_url( $url ); |
|
| 360 | + $parts = parse_url($url); |
|
| 361 | 361 | |
| 362 | - if ( isset( $parts['query'] ) ) { |
|
| 363 | - wp_parse_str( $parts['query'], $query_args ); |
|
| 362 | + if (isset($parts['query'])) { |
|
| 363 | + wp_parse_str($parts['query'], $query_args); |
|
| 364 | 364 | |
| 365 | - $allowed = apply_filters( 'wpinv_url_token_allowed_params', array( |
|
| 365 | + $allowed = apply_filters('wpinv_url_token_allowed_params', array( |
|
| 366 | 366 | 'item', |
| 367 | 367 | 'ttl', |
| 368 | 368 | 'token' |
| 369 | - ) ); |
|
| 369 | + )); |
|
| 370 | 370 | |
| 371 | 371 | $remove = array(); |
| 372 | 372 | |
| 373 | - foreach( $query_args as $key => $value ) { |
|
| 374 | - if( false === in_array( $key, $allowed ) ) { |
|
| 373 | + foreach ($query_args as $key => $value) { |
|
| 374 | + if (false === in_array($key, $allowed)) { |
|
| 375 | 375 | $remove[] = $key; |
| 376 | 376 | } |
| 377 | 377 | } |
| 378 | 378 | |
| 379 | - if( ! empty( $remove ) ) { |
|
| 380 | - $url = remove_query_arg( $remove, $url ); |
|
| 379 | + if (!empty($remove)) { |
|
| 380 | + $url = remove_query_arg($remove, $url); |
|
| 381 | 381 | } |
| 382 | 382 | |
| 383 | - if ( isset( $query_args['ttl'] ) && current_time( 'timestamp' ) > $query_args['ttl'] ) { |
|
| 384 | - wp_die( apply_filters( 'wpinv_item_link_expired_text', __( 'Sorry but your item link has expired.', 'invoicing' ) ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 383 | + if (isset($query_args['ttl']) && current_time('timestamp') > $query_args['ttl']) { |
|
| 384 | + wp_die(apply_filters('wpinv_item_link_expired_text', __('Sorry but your item link has expired.', 'invoicing')), __('Error', 'invoicing'), array('response' => 403)); |
|
| 385 | 385 | } |
| 386 | 386 | |
| 387 | - if ( isset( $query_args['token'] ) && $query_args['token'] == wpinv_get_item_token( $url ) ) { |
|
| 387 | + if (isset($query_args['token']) && $query_args['token'] == wpinv_get_item_token($url)) { |
|
| 388 | 388 | $ret = true; |
| 389 | 389 | } |
| 390 | 390 | |
| 391 | 391 | } |
| 392 | 392 | |
| 393 | - return apply_filters( 'wpinv_validate_url_token', $ret, $url, $query_args ); |
|
| 393 | + return apply_filters('wpinv_validate_url_token', $ret, $url, $query_args); |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | -function wpinv_item_in_cart( $item_id = 0, $options = array() ) { |
|
| 396 | +function wpinv_item_in_cart($item_id = 0, $options = array()) { |
|
| 397 | 397 | $cart_items = wpinv_get_cart_contents(); |
| 398 | 398 | |
| 399 | 399 | $ret = false; |
| 400 | 400 | |
| 401 | - if ( is_array( $cart_items ) ) { |
|
| 402 | - foreach ( $cart_items as $item ) { |
|
| 403 | - if ( $item['id'] == $item_id ) { |
|
| 401 | + if (is_array($cart_items)) { |
|
| 402 | + foreach ($cart_items as $item) { |
|
| 403 | + if ($item['id'] == $item_id) { |
|
| 404 | 404 | $ret = true; |
| 405 | 405 | break; |
| 406 | 406 | } |
| 407 | 407 | } |
| 408 | 408 | } |
| 409 | 409 | |
| 410 | - return (bool) apply_filters( 'wpinv_item_in_cart', $ret, $item_id, $options ); |
|
| 410 | + return (bool) apply_filters('wpinv_item_in_cart', $ret, $item_id, $options); |
|
| 411 | 411 | } |
| 412 | 412 | |
| 413 | -function wpinv_get_cart_item_tax( $item_id = 0, $subtotal = '', $options = array() ) { |
|
| 413 | +function wpinv_get_cart_item_tax($item_id = 0, $subtotal = '', $options = array()) { |
|
| 414 | 414 | $tax = 0; |
| 415 | - if ( ! wpinv_item_is_tax_exclusive( $item_id ) ) { |
|
| 416 | - $country = !empty( $_POST['country'] ) ? $_POST['country'] : false; |
|
| 417 | - $state = isset( $_POST['state'] ) ? $_POST['state'] : ''; |
|
| 415 | + if (!wpinv_item_is_tax_exclusive($item_id)) { |
|
| 416 | + $country = !empty($_POST['country']) ? $_POST['country'] : false; |
|
| 417 | + $state = isset($_POST['state']) ? $_POST['state'] : ''; |
|
| 418 | 418 | |
| 419 | - $tax = wpinv_calculate_tax( $subtotal, $country, $state, $item_id ); |
|
| 419 | + $tax = wpinv_calculate_tax($subtotal, $country, $state, $item_id); |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | - return apply_filters( 'wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options ); |
|
| 422 | + return apply_filters('wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options); |
|
| 423 | 423 | } |
| 424 | 424 | |
| 425 | -function wpinv_cart_item_price( $item, $currency = '' ) { |
|
| 425 | +function wpinv_cart_item_price($item, $currency = '') { |
|
| 426 | 426 | |
| 427 | - if( empty( $currency ) ) { |
|
| 427 | + if (empty($currency)) { |
|
| 428 | 428 | $currency = wpinv_get_currency(); |
| 429 | 429 | } |
| 430 | 430 | |
| 431 | - $item_id = isset( $item['id'] ) ? $item['id'] : 0; |
|
| 432 | - $price = isset( $item['item_price'] ) ? wpinv_round_amount( $item['item_price'] ) : 0; |
|
| 433 | - $tax = wpinv_price( wpinv_format_amount( $item['tax'] ) ); |
|
| 431 | + $item_id = isset($item['id']) ? $item['id'] : 0; |
|
| 432 | + $price = isset($item['item_price']) ? wpinv_round_amount($item['item_price']) : 0; |
|
| 433 | + $tax = wpinv_price(wpinv_format_amount($item['tax'])); |
|
| 434 | 434 | |
| 435 | - if ( !wpinv_is_free_item( $item_id ) && !wpinv_item_is_tax_exclusive( $item_id ) ) { |
|
| 436 | - if ( wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax() ) { |
|
| 435 | + if (!wpinv_is_free_item($item_id) && !wpinv_item_is_tax_exclusive($item_id)) { |
|
| 436 | + if (wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax()) { |
|
| 437 | 437 | $price += $tax; |
| 438 | 438 | } |
| 439 | 439 | |
| 440 | - if( !wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax() ) { |
|
| 440 | + if (!wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax()) { |
|
| 441 | 441 | $price -= $tax; |
| 442 | 442 | } |
| 443 | 443 | } |
| 444 | 444 | |
| 445 | - $price = wpinv_price( wpinv_format_amount( $price ), $currency ); |
|
| 445 | + $price = wpinv_price(wpinv_format_amount($price), $currency); |
|
| 446 | 446 | |
| 447 | - return apply_filters( 'wpinv_cart_item_price_label', $price, $item ); |
|
| 447 | + return apply_filters('wpinv_cart_item_price_label', $price, $item); |
|
| 448 | 448 | } |
| 449 | 449 | |
| 450 | -function wpinv_cart_item_subtotal( $item, $currency = '' ) { |
|
| 450 | +function wpinv_cart_item_subtotal($item, $currency = '') { |
|
| 451 | 451 | |
| 452 | - if( empty( $currency ) ) { |
|
| 452 | + if (empty($currency)) { |
|
| 453 | 453 | $currency = wpinv_get_currency(); |
| 454 | 454 | } |
| 455 | 455 | |
| 456 | - $subtotal = isset( $item['subtotal'] ) ? $item['subtotal'] : 0; |
|
| 457 | - $subtotal = wpinv_price( wpinv_format_amount( $subtotal ), $currency ); |
|
| 456 | + $subtotal = isset($item['subtotal']) ? $item['subtotal'] : 0; |
|
| 457 | + $subtotal = wpinv_price(wpinv_format_amount($subtotal), $currency); |
|
| 458 | 458 | |
| 459 | - return apply_filters( 'wpinv_cart_item_subtotal_label', $subtotal, $item ); |
|
| 459 | + return apply_filters('wpinv_cart_item_subtotal_label', $subtotal, $item); |
|
| 460 | 460 | } |
| 461 | 461 | |
| 462 | -function wpinv_cart_item_tax( $item, $currency = '' ) { |
|
| 462 | +function wpinv_cart_item_tax($item, $currency = '') { |
|
| 463 | 463 | $tax = ''; |
| 464 | 464 | $tax_rate = ''; |
| 465 | 465 | |
| 466 | - if( empty( $currency ) ) { |
|
| 466 | + if (empty($currency)) { |
|
| 467 | 467 | $currency = wpinv_get_currency(); |
| 468 | 468 | } |
| 469 | 469 | |
| 470 | - if ( isset( $item['tax'] ) && $item['tax'] > 0 && $item['subtotal'] > 0 ) { |
|
| 471 | - $tax = wpinv_price( wpinv_format_amount( $item['tax'] ), $currency ); |
|
| 472 | - $tax_rate = !empty( $item['vat_rate'] ) ? $item['vat_rate'] : ( $item['tax'] / $item['subtotal'] ) * 100; |
|
| 473 | - $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : ''; |
|
| 470 | + if (isset($item['tax']) && $item['tax'] > 0 && $item['subtotal'] > 0) { |
|
| 471 | + $tax = wpinv_price(wpinv_format_amount($item['tax']), $currency); |
|
| 472 | + $tax_rate = !empty($item['vat_rate']) ? $item['vat_rate'] : ($item['tax'] / $item['subtotal']) * 100; |
|
| 473 | + $tax_rate = $tax_rate > 0 ? (float) wpinv_round_amount($tax_rate, 4) : ''; |
|
| 474 | 474 | $tax_rate = $tax_rate != '' ? ' <small class="tax-rate normal small">(' . $tax_rate . '%)</small>' : ''; |
| 475 | 475 | } |
| 476 | 476 | |
| 477 | - $tax = $tax . $tax_rate; |
|
| 477 | + $tax = $tax . $tax_rate; |
|
| 478 | 478 | |
| 479 | - if ( $tax === '' ) { |
|
| 479 | + if ($tax === '') { |
|
| 480 | 480 | $tax = 0; // Zero tax |
| 481 | 481 | } |
| 482 | 482 | |
| 483 | - return apply_filters( 'wpinv_cart_item_tax_label', $tax, $item ); |
|
| 483 | + return apply_filters('wpinv_cart_item_tax_label', $tax, $item); |
|
| 484 | 484 | } |
| 485 | 485 | |
| 486 | -function wpinv_get_cart_item_price( $item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false ) { |
|
| 486 | +function wpinv_get_cart_item_price($item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false) { |
|
| 487 | 487 | $price = 0; |
| 488 | 488 | |
| 489 | 489 | // Set custom price |
| 490 | - if ( isset( $cart_item['custom_price'] ) && $cart_item['custom_price'] !== '' ) { |
|
| 490 | + if (isset($cart_item['custom_price']) && $cart_item['custom_price'] !== '') { |
|
| 491 | 491 | $price = $cart_item['custom_price']; |
| 492 | 492 | } else { |
| 493 | - $variable_prices = wpinv_has_variable_prices( $item_id ); |
|
| 493 | + $variable_prices = wpinv_has_variable_prices($item_id); |
|
| 494 | 494 | |
| 495 | - if ( $variable_prices ) { |
|
| 496 | - $prices = wpinv_get_variable_prices( $item_id ); |
|
| 495 | + if ($variable_prices) { |
|
| 496 | + $prices = wpinv_get_variable_prices($item_id); |
|
| 497 | 497 | |
| 498 | - if ( $prices ) { |
|
| 499 | - if( ! empty( $options ) ) { |
|
| 500 | - $price = isset( $prices[ $options['price_id'] ] ) ? $prices[ $options['price_id'] ]['amount'] : false; |
|
| 498 | + if ($prices) { |
|
| 499 | + if (!empty($options)) { |
|
| 500 | + $price = isset($prices[$options['price_id']]) ? $prices[$options['price_id']]['amount'] : false; |
|
| 501 | 501 | } else { |
| 502 | 502 | $price = false; |
| 503 | 503 | } |
| 504 | 504 | } |
| 505 | 505 | } |
| 506 | 506 | |
| 507 | - if( ! $variable_prices || false === $price ) { |
|
| 508 | - if($cart_item['item_price'] > 0){ |
|
| 507 | + if (!$variable_prices || false === $price) { |
|
| 508 | + if ($cart_item['item_price'] > 0) { |
|
| 509 | 509 | $price = $cart_item['item_price']; |
| 510 | 510 | } else { |
| 511 | 511 | // Get the standard Item price if not using variable prices |
| 512 | - $price = wpinv_get_item_price( $item_id ); |
|
| 512 | + $price = wpinv_get_item_price($item_id); |
|
| 513 | 513 | } |
| 514 | 514 | } |
| 515 | 515 | } |
| 516 | 516 | |
| 517 | - if ( $remove_tax_from_inclusive && wpinv_prices_include_tax() ) { |
|
| 518 | - $price -= wpinv_get_cart_item_tax( $item_id, $price, $options ); |
|
| 517 | + if ($remove_tax_from_inclusive && wpinv_prices_include_tax()) { |
|
| 518 | + $price -= wpinv_get_cart_item_tax($item_id, $price, $options); |
|
| 519 | 519 | } |
| 520 | 520 | |
| 521 | - return apply_filters( 'wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive ); |
|
| 521 | + return apply_filters('wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive); |
|
| 522 | 522 | } |
| 523 | 523 | |
| 524 | -function wpinv_get_cart_item_price_id( $item = array() ) { |
|
| 525 | - if( isset( $item['item_number'] ) ) { |
|
| 526 | - $price_id = isset( $item['item_number']['options']['price_id'] ) ? $item['item_number']['options']['price_id'] : null; |
|
| 524 | +function wpinv_get_cart_item_price_id($item = array()) { |
|
| 525 | + if (isset($item['item_number'])) { |
|
| 526 | + $price_id = isset($item['item_number']['options']['price_id']) ? $item['item_number']['options']['price_id'] : null; |
|
| 527 | 527 | } else { |
| 528 | - $price_id = isset( $item['options']['price_id'] ) ? $item['options']['price_id'] : null; |
|
| 528 | + $price_id = isset($item['options']['price_id']) ? $item['options']['price_id'] : null; |
|
| 529 | 529 | } |
| 530 | 530 | return $price_id; |
| 531 | 531 | } |
| 532 | 532 | |
| 533 | -function wpinv_get_cart_item_price_name( $item = array() ) { |
|
| 534 | - $price_id = (int)wpinv_get_cart_item_price_id( $item ); |
|
| 535 | - $prices = wpinv_get_variable_prices( $item['id'] ); |
|
| 536 | - $name = ! empty( $prices[ $price_id ] ) ? $prices[ $price_id ]['name'] : ''; |
|
| 537 | - return apply_filters( 'wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item ); |
|
| 533 | +function wpinv_get_cart_item_price_name($item = array()) { |
|
| 534 | + $price_id = (int) wpinv_get_cart_item_price_id($item); |
|
| 535 | + $prices = wpinv_get_variable_prices($item['id']); |
|
| 536 | + $name = !empty($prices[$price_id]) ? $prices[$price_id]['name'] : ''; |
|
| 537 | + return apply_filters('wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item); |
|
| 538 | 538 | } |
| 539 | 539 | |
| 540 | -function wpinv_get_cart_item_name( $item = array() ) { |
|
| 541 | - $item_title = !empty( $item['name'] ) ? $item['name'] : get_the_title( $item['id'] ); |
|
| 540 | +function wpinv_get_cart_item_name($item = array()) { |
|
| 541 | + $item_title = !empty($item['name']) ? $item['name'] : get_the_title($item['id']); |
|
| 542 | 542 | |
| 543 | - if ( empty( $item_title ) ) { |
|
| 543 | + if (empty($item_title)) { |
|
| 544 | 544 | $item_title = $item['id']; |
| 545 | 545 | } |
| 546 | 546 | |
@@ -550,23 +550,23 @@ discard block |
||
| 550 | 550 | } |
| 551 | 551 | */ |
| 552 | 552 | |
| 553 | - return apply_filters( 'wpinv_get_cart_item_name', $item_title, $item['id'], $item ); |
|
| 553 | + return apply_filters('wpinv_get_cart_item_name', $item_title, $item['id'], $item); |
|
| 554 | 554 | } |
| 555 | 555 | |
| 556 | -function wpinv_has_variable_prices( $item_id = 0 ) { |
|
| 556 | +function wpinv_has_variable_prices($item_id = 0) { |
|
| 557 | 557 | return false; |
| 558 | 558 | } |
| 559 | 559 | |
| 560 | -function wpinv_get_item_position_in_cart( $item_id = 0, $options = array() ) { |
|
| 560 | +function wpinv_get_item_position_in_cart($item_id = 0, $options = array()) { |
|
| 561 | 561 | $cart_items = wpinv_get_cart_contents(); |
| 562 | 562 | |
| 563 | - if ( !is_array( $cart_items ) ) { |
|
| 563 | + if (!is_array($cart_items)) { |
|
| 564 | 564 | return false; // Empty cart |
| 565 | 565 | } else { |
| 566 | - foreach ( $cart_items as $position => $item ) { |
|
| 567 | - if ( $item['id'] == $item_id ) { |
|
| 568 | - if ( isset( $options['price_id'] ) && isset( $item['options']['price_id'] ) ) { |
|
| 569 | - if ( (int) $options['price_id'] == (int) $item['options']['price_id'] ) { |
|
| 566 | + foreach ($cart_items as $position => $item) { |
|
| 567 | + if ($item['id'] == $item_id) { |
|
| 568 | + if (isset($options['price_id']) && isset($item['options']['price_id'])) { |
|
| 569 | + if ((int) $options['price_id'] == (int) $item['options']['price_id']) { |
|
| 570 | 570 | return $position; |
| 571 | 571 | } |
| 572 | 572 | } else { |
@@ -579,80 +579,80 @@ discard block |
||
| 579 | 579 | return false; // Not found |
| 580 | 580 | } |
| 581 | 581 | |
| 582 | -function wpinv_get_cart_item_quantity( $item ) { |
|
| 583 | - if ( wpinv_item_quantities_enabled() ) { |
|
| 584 | - $quantity = !empty( $item['quantity'] ) && (int)$item['quantity'] > 0 ? absint( $item['quantity'] ) : 1; |
|
| 582 | +function wpinv_get_cart_item_quantity($item) { |
|
| 583 | + if (wpinv_item_quantities_enabled()) { |
|
| 584 | + $quantity = !empty($item['quantity']) && (int) $item['quantity'] > 0 ? absint($item['quantity']) : 1; |
|
| 585 | 585 | } else { |
| 586 | 586 | $quantity = 1; |
| 587 | 587 | } |
| 588 | 588 | |
| 589 | - if ( $quantity < 1 ) { |
|
| 589 | + if ($quantity < 1) { |
|
| 590 | 590 | $quantity = 1; |
| 591 | 591 | } |
| 592 | 592 | |
| 593 | - return apply_filters( 'wpinv_get_cart_item_quantity', $quantity, $item ); |
|
| 593 | + return apply_filters('wpinv_get_cart_item_quantity', $quantity, $item); |
|
| 594 | 594 | } |
| 595 | 595 | |
| 596 | -function wpinv_get_item_suffix( $item, $html = true ) { |
|
| 597 | - if ( empty( $item ) ) { |
|
| 596 | +function wpinv_get_item_suffix($item, $html = true) { |
|
| 597 | + if (empty($item)) { |
|
| 598 | 598 | return NULL; |
| 599 | 599 | } |
| 600 | 600 | |
| 601 | - if ( is_int( $item ) ) { |
|
| 602 | - $item = new WPInv_Item( $item ); |
|
| 601 | + if (is_int($item)) { |
|
| 602 | + $item = new WPInv_Item($item); |
|
| 603 | 603 | } |
| 604 | 604 | |
| 605 | - if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) { |
|
| 605 | + if (!(is_object($item) && is_a($item, 'WPInv_Item'))) { |
|
| 606 | 606 | return NULL; |
| 607 | 607 | } |
| 608 | 608 | |
| 609 | - $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : ''; |
|
| 609 | + $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : ''; |
|
| 610 | 610 | |
| 611 | - if ( !$html && $suffix ) { |
|
| 612 | - $suffix = strip_tags( $suffix ); |
|
| 611 | + if (!$html && $suffix) { |
|
| 612 | + $suffix = strip_tags($suffix); |
|
| 613 | 613 | } |
| 614 | 614 | |
| 615 | - return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html ); |
|
| 615 | + return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html); |
|
| 616 | 616 | } |
| 617 | 617 | |
| 618 | -function wpinv_remove_item( $item = 0, $force_delete = false ) { |
|
| 619 | - if ( empty( $item ) ) { |
|
| 618 | +function wpinv_remove_item($item = 0, $force_delete = false) { |
|
| 619 | + if (empty($item)) { |
|
| 620 | 620 | return NULL; |
| 621 | 621 | } |
| 622 | 622 | |
| 623 | - if ( is_int( $item ) ) { |
|
| 624 | - $item = new WPInv_Item( $item ); |
|
| 623 | + if (is_int($item)) { |
|
| 624 | + $item = new WPInv_Item($item); |
|
| 625 | 625 | } |
| 626 | 626 | |
| 627 | - if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) { |
|
| 627 | + if (!(is_object($item) && is_a($item, 'WPInv_Item'))) { |
|
| 628 | 628 | return NULL; |
| 629 | 629 | } |
| 630 | 630 | |
| 631 | - do_action( 'wpinv_pre_delete_item', $item ); |
|
| 631 | + do_action('wpinv_pre_delete_item', $item); |
|
| 632 | 632 | |
| 633 | - wp_delete_post( $item->ID, $force_delete ); |
|
| 633 | + wp_delete_post($item->ID, $force_delete); |
|
| 634 | 634 | |
| 635 | - do_action( 'wpinv_post_delete_item', $item ); |
|
| 635 | + do_action('wpinv_post_delete_item', $item); |
|
| 636 | 636 | } |
| 637 | 637 | |
| 638 | -function wpinv_can_delete_item( $post_id ) { |
|
| 638 | +function wpinv_can_delete_item($post_id) { |
|
| 639 | 639 | $return = wpinv_current_user_can_manage_invoicing() ? true : false; |
| 640 | 640 | |
| 641 | - if ( $return && wpinv_item_in_use( $post_id ) ) { |
|
| 641 | + if ($return && wpinv_item_in_use($post_id)) { |
|
| 642 | 642 | $return = false; // Don't delete item already use in invoices. |
| 643 | 643 | } |
| 644 | 644 | |
| 645 | - return apply_filters( 'wpinv_can_delete_item', $return, $post_id ); |
|
| 645 | + return apply_filters('wpinv_can_delete_item', $return, $post_id); |
|
| 646 | 646 | } |
| 647 | 647 | |
| 648 | 648 | function wpinv_admin_action_delete() { |
| 649 | 649 | $screen = get_current_screen(); |
| 650 | 650 | |
| 651 | - if ( !empty( $screen->post_type ) && $screen->post_type == 'wpi_item' && !empty( $_REQUEST['post'] ) && is_array( $_REQUEST['post'] ) ) { |
|
| 651 | + if (!empty($screen->post_type) && $screen->post_type == 'wpi_item' && !empty($_REQUEST['post']) && is_array($_REQUEST['post'])) { |
|
| 652 | 652 | $post_ids = array(); |
| 653 | 653 | |
| 654 | - foreach ( $_REQUEST['post'] as $post_id ) { |
|
| 655 | - if ( !wpinv_can_delete_item( $post_id ) ) { |
|
| 654 | + foreach ($_REQUEST['post'] as $post_id) { |
|
| 655 | + if (!wpinv_can_delete_item($post_id)) { |
|
| 656 | 656 | continue; |
| 657 | 657 | } |
| 658 | 658 | |
@@ -662,39 +662,39 @@ discard block |
||
| 662 | 662 | $_REQUEST['post'] = $post_ids; |
| 663 | 663 | } |
| 664 | 664 | } |
| 665 | -add_action( 'admin_action_trash', 'wpinv_admin_action_delete', -10 ); |
|
| 666 | -add_action( 'admin_action_delete', 'wpinv_admin_action_delete', -10 ); |
|
| 665 | +add_action('admin_action_trash', 'wpinv_admin_action_delete', -10); |
|
| 666 | +add_action('admin_action_delete', 'wpinv_admin_action_delete', -10); |
|
| 667 | 667 | |
| 668 | -function wpinv_check_delete_item( $check, $post, $force_delete ) { |
|
| 669 | - if ( $post->post_type == 'wpi_item' ) { |
|
| 670 | - if ( $force_delete && !wpinv_can_delete_item( $post->ID ) ) { |
|
| 668 | +function wpinv_check_delete_item($check, $post, $force_delete) { |
|
| 669 | + if ($post->post_type == 'wpi_item') { |
|
| 670 | + if ($force_delete && !wpinv_can_delete_item($post->ID)) { |
|
| 671 | 671 | return true; |
| 672 | 672 | } |
| 673 | 673 | } |
| 674 | 674 | |
| 675 | 675 | return $check; |
| 676 | 676 | } |
| 677 | -add_filter( 'pre_delete_post', 'wpinv_check_delete_item', 10, 3 ); |
|
| 677 | +add_filter('pre_delete_post', 'wpinv_check_delete_item', 10, 3); |
|
| 678 | 678 | |
| 679 | -function wpinv_item_in_use( $item_id ) { |
|
| 679 | +function wpinv_item_in_use($item_id) { |
|
| 680 | 680 | global $wpdb, $wpi_items_in_use; |
| 681 | 681 | |
| 682 | - if ( !$item_id > 0 ) { |
|
| 682 | + if (!$item_id > 0) { |
|
| 683 | 683 | return false; |
| 684 | 684 | } |
| 685 | 685 | |
| 686 | - if ( !empty( $wpi_items_in_use ) ) { |
|
| 687 | - if ( isset( $wpi_items_in_use[$item_id] ) ) { |
|
| 686 | + if (!empty($wpi_items_in_use)) { |
|
| 687 | + if (isset($wpi_items_in_use[$item_id])) { |
|
| 688 | 688 | return $wpi_items_in_use[$item_id]; |
| 689 | 689 | } |
| 690 | 690 | } else { |
| 691 | 691 | $wpi_items_in_use = array(); |
| 692 | 692 | } |
| 693 | 693 | |
| 694 | - $statuses = array_keys( wpinv_get_invoice_statuses( true, true ) ); |
|
| 694 | + $statuses = array_keys(wpinv_get_invoice_statuses(true, true)); |
|
| 695 | 695 | |
| 696 | - $query = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode( "','", $statuses ) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )"; |
|
| 697 | - $in_use = $wpdb->get_var( $query ) > 0 ? true : false; |
|
| 696 | + $query = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode("','", $statuses) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int) $item_id . "', pm.meta_value )"; |
|
| 697 | + $in_use = $wpdb->get_var($query) > 0 ? true : false; |
|
| 698 | 698 | |
| 699 | 699 | $wpi_items_in_use[$item_id] = $in_use; |
| 700 | 700 | |
@@ -737,45 +737,45 @@ discard block |
||
| 737 | 737 | * @param bool $wp_error whether or not to return a WP_Error on failure. |
| 738 | 738 | * @return bool|WP_Error|WPInv_Item |
| 739 | 739 | */ |
| 740 | -function wpinv_create_item( $args = array(), $wp_error = false ) { |
|
| 740 | +function wpinv_create_item($args = array(), $wp_error = false) { |
|
| 741 | 741 | |
| 742 | 742 | // Prepare the item. |
| 743 | - if ( ! empty( $args['custom_id'] ) && empty( $args['ID'] ) ) { |
|
| 744 | - $type = empty( $args['type'] ) ? 'custom' : $args['type']; |
|
| 745 | - $item = wpinv_get_item_by( 'custom_id', $args['custom_id'], $type ); |
|
| 743 | + if (!empty($args['custom_id']) && empty($args['ID'])) { |
|
| 744 | + $type = empty($args['type']) ? 'custom' : $args['type']; |
|
| 745 | + $item = wpinv_get_item_by('custom_id', $args['custom_id'], $type); |
|
| 746 | 746 | |
| 747 | - if ( ! empty( $item ) ) { |
|
| 747 | + if (!empty($item)) { |
|
| 748 | 748 | $args['ID'] = $item->get_id(); |
| 749 | 749 | } |
| 750 | 750 | |
| 751 | 751 | } |
| 752 | 752 | |
| 753 | 753 | // Do we have an item? |
| 754 | - if ( ! empty( $args['ID'] ) ) { |
|
| 755 | - $item = new WPInv_Item( $args['ID'] ); |
|
| 754 | + if (!empty($args['ID'])) { |
|
| 755 | + $item = new WPInv_Item($args['ID']); |
|
| 756 | 756 | } else { |
| 757 | 757 | $item = new WPInv_Item(); |
| 758 | 758 | } |
| 759 | 759 | |
| 760 | 760 | // Do we have an error? |
| 761 | - if ( ! empty( $item->last_error ) ) { |
|
| 762 | - return $wp_error ? new WP_Error( 'invalid_item', $item->last_error ) : false; |
|
| 761 | + if (!empty($item->last_error)) { |
|
| 762 | + return $wp_error ? new WP_Error('invalid_item', $item->last_error) : false; |
|
| 763 | 763 | } |
| 764 | 764 | |
| 765 | 765 | // Update item props. |
| 766 | - $item->set_props( $args ); |
|
| 766 | + $item->set_props($args); |
|
| 767 | 767 | |
| 768 | 768 | // Save the item. |
| 769 | 769 | $item->save(); |
| 770 | 770 | |
| 771 | 771 | // Do we have an error? |
| 772 | - if ( ! empty( $item->last_error ) ) { |
|
| 773 | - return $wp_error ? new WP_Error( 'not_saved', $item->last_error ) : false; |
|
| 772 | + if (!empty($item->last_error)) { |
|
| 773 | + return $wp_error ? new WP_Error('not_saved', $item->last_error) : false; |
|
| 774 | 774 | } |
| 775 | 775 | |
| 776 | 776 | // Was the item saved? |
| 777 | - if ( ! $item->get_id() ) { |
|
| 778 | - return $wp_error ? new WP_Error( 'not_saved', __( 'An error occured while saving the item', 'invoicing' ) ) : false; |
|
| 777 | + if (!$item->get_id()) { |
|
| 778 | + return $wp_error ? new WP_Error('not_saved', __('An error occured while saving the item', 'invoicing')) : false; |
|
| 779 | 779 | } |
| 780 | 780 | |
| 781 | 781 | return $item; |
@@ -787,14 +787,14 @@ discard block |
||
| 787 | 787 | * |
| 788 | 788 | * @see wpinv_create_item() |
| 789 | 789 | */ |
| 790 | -function wpinv_update_item( $args = array(), $wp_error = false ) { |
|
| 791 | - return wpinv_create_item( $args, $wp_error ); |
|
| 790 | +function wpinv_update_item($args = array(), $wp_error = false) { |
|
| 791 | + return wpinv_create_item($args, $wp_error); |
|
| 792 | 792 | } |
| 793 | 793 | |
| 794 | 794 | /** |
| 795 | 795 | * Sanitizes a recurring period |
| 796 | 796 | */ |
| 797 | -function getpaid_sanitize_recurring_period( $period, $full = false ) { |
|
| 797 | +function getpaid_sanitize_recurring_period($period, $full = false) { |
|
| 798 | 798 | |
| 799 | 799 | $periods = array( |
| 800 | 800 | 'D' => 'day', |
@@ -803,11 +803,11 @@ discard block |
||
| 803 | 803 | 'Y' => 'year', |
| 804 | 804 | ); |
| 805 | 805 | |
| 806 | - if ( ! isset( $periods[ $period ] ) ) { |
|
| 806 | + if (!isset($periods[$period])) { |
|
| 807 | 807 | $period = 'D'; |
| 808 | 808 | } |
| 809 | 809 | |
| 810 | - return $full ? $periods[ $period ] : $period; |
|
| 810 | + return $full ? $periods[$period] : $period; |
|
| 811 | 811 | |
| 812 | 812 | } |
| 813 | 813 | |
@@ -816,51 +816,51 @@ discard block |
||
| 816 | 816 | * |
| 817 | 817 | * @param WPInv_Item $item |
| 818 | 818 | */ |
| 819 | -function getpaid_item_recurring_price_help_text( $item, $currency = '' ) { |
|
| 819 | +function getpaid_item_recurring_price_help_text($item, $currency = '') { |
|
| 820 | 820 | |
| 821 | 821 | // Abort if it is not recurring. |
| 822 | - if ( ! $item->is_recurring() ) { |
|
| 822 | + if (!$item->is_recurring()) { |
|
| 823 | 823 | return ''; |
| 824 | 824 | } |
| 825 | 825 | |
| 826 | - $initial_price = wpinv_price( wpinv_sanitize_amount( $item->get_initial_price() ), $currency ); |
|
| 827 | - $recurring_price = wpinv_price( wpinv_sanitize_amount( $item->get_recurring_price() ), $currency ); |
|
| 828 | - $period = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->get_recurring_period(), $item->get_recurring_interval() ); |
|
| 829 | - $period = str_replace( '1 ', '', strtolower( $period ) ); |
|
| 826 | + $initial_price = wpinv_price(wpinv_sanitize_amount($item->get_initial_price()), $currency); |
|
| 827 | + $recurring_price = wpinv_price(wpinv_sanitize_amount($item->get_recurring_price()), $currency); |
|
| 828 | + $period = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($item->get_recurring_period(), $item->get_recurring_interval()); |
|
| 829 | + $period = str_replace('1 ', '', strtolower($period)); |
|
| 830 | 830 | |
| 831 | 831 | // For free trial items. |
| 832 | - if ( $item->has_free_trial() ) { |
|
| 833 | - $trial_period = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->get_trial_period(), $item->get_trial_interval() ); |
|
| 832 | + if ($item->has_free_trial()) { |
|
| 833 | + $trial_period = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($item->get_trial_period(), $item->get_trial_interval()); |
|
| 834 | 834 | |
| 835 | - if ( 0 == $item->get_initial_price() ) { |
|
| 835 | + if (0 == $item->get_initial_price()) { |
|
| 836 | 836 | return sprintf( |
| 837 | - __( 'Free for %s then %s every %s', 'invoicing' ), |
|
| 838 | - strtolower( $trial_period ), |
|
| 837 | + __('Free for %s then %s every %s', 'invoicing'), |
|
| 838 | + strtolower($trial_period), |
|
| 839 | 839 | $recurring_price, |
| 840 | 840 | $period |
| 841 | 841 | ); |
| 842 | 842 | } |
| 843 | 843 | |
| 844 | 844 | return sprintf( |
| 845 | - __( '%s for %s then %s every %s', 'invoicing' ), |
|
| 845 | + __('%s for %s then %s every %s', 'invoicing'), |
|
| 846 | 846 | $initial_price, |
| 847 | - strtolower( $trial_period ), |
|
| 847 | + strtolower($trial_period), |
|
| 848 | 848 | $recurring_price, |
| 849 | 849 | $period |
| 850 | 850 | ); |
| 851 | 851 | |
| 852 | 852 | } |
| 853 | 853 | |
| 854 | - if ( $initial_price == $recurring_price ) { |
|
| 854 | + if ($initial_price == $recurring_price) { |
|
| 855 | 855 | return sprintf( |
| 856 | - __( '%s every %s', 'invoicing' ), |
|
| 856 | + __('%s every %s', 'invoicing'), |
|
| 857 | 857 | $recurring_price, |
| 858 | 858 | $period |
| 859 | 859 | ); |
| 860 | 860 | } |
| 861 | 861 | |
| 862 | 862 | return sprintf( |
| 863 | - __( '%s for %s then %s every %s', 'invoicing' ), |
|
| 863 | + __('%s for %s then %s every %s', 'invoicing'), |
|
| 864 | 864 | $initial_price, |
| 865 | 865 | $period, |
| 866 | 866 | $recurring_price, |
@@ -283,8 +283,9 @@ |
||
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | function wpinv_remove_item_logs_on_delete( $item_id = 0 ) { |
| 286 | - if ( 'wpi_item' !== get_post_type( $item_id ) ) |
|
| 287 | - return; |
|
| 286 | + if ( 'wpi_item' !== get_post_type( $item_id ) ) { |
|
| 287 | + return; |
|
| 288 | + } |
|
| 288 | 289 | |
| 289 | 290 | global $wpinv_logs; |
| 290 | 291 | |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | - exit; |
|
| 3 | + exit; |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -10,30 +10,30 @@ discard block |
||
| 10 | 10 | class WPInv_Item extends GetPaid_Data { |
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | - * Which data store to load. |
|
| 14 | - * |
|
| 15 | - * @var string |
|
| 16 | - */ |
|
| 13 | + * Which data store to load. |
|
| 14 | + * |
|
| 15 | + * @var string |
|
| 16 | + */ |
|
| 17 | 17 | protected $data_store_name = 'item'; |
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | - * This is the name of this object type. |
|
| 21 | - * |
|
| 22 | - * @var string |
|
| 23 | - */ |
|
| 24 | - protected $object_type = 'item'; |
|
| 20 | + * This is the name of this object type. |
|
| 21 | + * |
|
| 22 | + * @var string |
|
| 23 | + */ |
|
| 24 | + protected $object_type = 'item'; |
|
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | - * Item Data array. This is the core item data exposed in APIs. |
|
| 28 | - * |
|
| 29 | - * @since 1.0.19 |
|
| 30 | - * @var array |
|
| 31 | - */ |
|
| 32 | - protected $data = array( |
|
| 33 | - 'parent_id' => 0, |
|
| 34 | - 'status' => 'draft', |
|
| 35 | - 'version' => '', |
|
| 36 | - 'date_created' => null, |
|
| 27 | + * Item Data array. This is the core item data exposed in APIs. |
|
| 28 | + * |
|
| 29 | + * @since 1.0.19 |
|
| 30 | + * @var array |
|
| 31 | + */ |
|
| 32 | + protected $data = array( |
|
| 33 | + 'parent_id' => 0, |
|
| 34 | + 'status' => 'draft', |
|
| 35 | + 'version' => '', |
|
| 36 | + 'date_created' => null, |
|
| 37 | 37 | 'date_modified' => null, |
| 38 | 38 | 'name' => '', |
| 39 | 39 | 'description' => '', |
@@ -58,13 +58,13 @@ discard block |
||
| 58 | 58 | ); |
| 59 | 59 | |
| 60 | 60 | /** |
| 61 | - * Stores meta in cache for future reads. |
|
| 62 | - * |
|
| 63 | - * A group must be set to to enable caching. |
|
| 64 | - * |
|
| 65 | - * @var string |
|
| 66 | - */ |
|
| 67 | - protected $cache_group = 'getpaid_items'; |
|
| 61 | + * Stores meta in cache for future reads. |
|
| 62 | + * |
|
| 63 | + * A group must be set to to enable caching. |
|
| 64 | + * |
|
| 65 | + * @var string |
|
| 66 | + */ |
|
| 67 | + protected $cache_group = 'getpaid_items'; |
|
| 68 | 68 | |
| 69 | 69 | /** |
| 70 | 70 | * Stores a reference to the original WP_Post object |
@@ -74,37 +74,37 @@ discard block |
||
| 74 | 74 | protected $post = null; |
| 75 | 75 | |
| 76 | 76 | /** |
| 77 | - * Get the item if ID is passed, otherwise the item is new and empty. |
|
| 78 | - * |
|
| 79 | - * @param int|object|WPInv_Item|WP_Post $item Item to read. |
|
| 80 | - */ |
|
| 81 | - public function __construct( $item = 0 ) { |
|
| 82 | - parent::__construct( $item ); |
|
| 83 | - |
|
| 84 | - if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) { |
|
| 85 | - $this->set_id( $item ); |
|
| 86 | - } elseif ( $item instanceof self ) { |
|
| 87 | - $this->set_id( $item->get_id() ); |
|
| 88 | - } elseif ( ! empty( $item->ID ) ) { |
|
| 89 | - $this->set_id( $item->ID ); |
|
| 90 | - } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) { |
|
| 91 | - $this->set_id( $item_id ); |
|
| 92 | - } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) { |
|
| 93 | - $this->set_id( $item_id ); |
|
| 94 | - } else { |
|
| 95 | - $this->set_object_read( true ); |
|
| 96 | - } |
|
| 77 | + * Get the item if ID is passed, otherwise the item is new and empty. |
|
| 78 | + * |
|
| 79 | + * @param int|object|WPInv_Item|WP_Post $item Item to read. |
|
| 80 | + */ |
|
| 81 | + public function __construct( $item = 0 ) { |
|
| 82 | + parent::__construct( $item ); |
|
| 83 | + |
|
| 84 | + if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) { |
|
| 85 | + $this->set_id( $item ); |
|
| 86 | + } elseif ( $item instanceof self ) { |
|
| 87 | + $this->set_id( $item->get_id() ); |
|
| 88 | + } elseif ( ! empty( $item->ID ) ) { |
|
| 89 | + $this->set_id( $item->ID ); |
|
| 90 | + } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) { |
|
| 91 | + $this->set_id( $item_id ); |
|
| 92 | + } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) { |
|
| 93 | + $this->set_id( $item_id ); |
|
| 94 | + } else { |
|
| 95 | + $this->set_object_read( true ); |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | 98 | // Load the datastore. |
| 99 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 99 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 100 | 100 | |
| 101 | - if ( $this->get_id() > 0 ) { |
|
| 101 | + if ( $this->get_id() > 0 ) { |
|
| 102 | 102 | $this->post = get_post( $this->get_id() ); |
| 103 | 103 | $this->ID = $this->get_id(); |
| 104 | - $this->data_store->read( $this ); |
|
| 104 | + $this->data_store->read( $this ); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - } |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | 109 | /* |
| 110 | 110 | |-------------------------------------------------------------------------- |
@@ -122,379 +122,379 @@ discard block |
||
| 122 | 122 | */ |
| 123 | 123 | |
| 124 | 124 | /** |
| 125 | - * Get parent item ID. |
|
| 126 | - * |
|
| 127 | - * @since 1.0.19 |
|
| 128 | - * @param string $context View or edit context. |
|
| 129 | - * @return int |
|
| 130 | - */ |
|
| 131 | - public function get_parent_id( $context = 'view' ) { |
|
| 132 | - return (int) $this->get_prop( 'parent_id', $context ); |
|
| 125 | + * Get parent item ID. |
|
| 126 | + * |
|
| 127 | + * @since 1.0.19 |
|
| 128 | + * @param string $context View or edit context. |
|
| 129 | + * @return int |
|
| 130 | + */ |
|
| 131 | + public function get_parent_id( $context = 'view' ) { |
|
| 132 | + return (int) $this->get_prop( 'parent_id', $context ); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /** |
| 136 | - * Get item status. |
|
| 137 | - * |
|
| 138 | - * @since 1.0.19 |
|
| 139 | - * @param string $context View or edit context. |
|
| 140 | - * @return string |
|
| 141 | - */ |
|
| 142 | - public function get_status( $context = 'view' ) { |
|
| 143 | - return $this->get_prop( 'status', $context ); |
|
| 136 | + * Get item status. |
|
| 137 | + * |
|
| 138 | + * @since 1.0.19 |
|
| 139 | + * @param string $context View or edit context. |
|
| 140 | + * @return string |
|
| 141 | + */ |
|
| 142 | + public function get_status( $context = 'view' ) { |
|
| 143 | + return $this->get_prop( 'status', $context ); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
| 147 | - * Get plugin version when the item was created. |
|
| 148 | - * |
|
| 149 | - * @since 1.0.19 |
|
| 150 | - * @param string $context View or edit context. |
|
| 151 | - * @return string |
|
| 152 | - */ |
|
| 153 | - public function get_version( $context = 'view' ) { |
|
| 154 | - return $this->get_prop( 'version', $context ); |
|
| 147 | + * Get plugin version when the item was created. |
|
| 148 | + * |
|
| 149 | + * @since 1.0.19 |
|
| 150 | + * @param string $context View or edit context. |
|
| 151 | + * @return string |
|
| 152 | + */ |
|
| 153 | + public function get_version( $context = 'view' ) { |
|
| 154 | + return $this->get_prop( 'version', $context ); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
| 158 | - * Get date when the item was created. |
|
| 159 | - * |
|
| 160 | - * @since 1.0.19 |
|
| 161 | - * @param string $context View or edit context. |
|
| 162 | - * @return string |
|
| 163 | - */ |
|
| 164 | - public function get_date_created( $context = 'view' ) { |
|
| 165 | - return $this->get_prop( 'date_created', $context ); |
|
| 158 | + * Get date when the item was created. |
|
| 159 | + * |
|
| 160 | + * @since 1.0.19 |
|
| 161 | + * @param string $context View or edit context. |
|
| 162 | + * @return string |
|
| 163 | + */ |
|
| 164 | + public function get_date_created( $context = 'view' ) { |
|
| 165 | + return $this->get_prop( 'date_created', $context ); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | /** |
| 169 | - * Get GMT date when the item was created. |
|
| 170 | - * |
|
| 171 | - * @since 1.0.19 |
|
| 172 | - * @param string $context View or edit context. |
|
| 173 | - * @return string |
|
| 174 | - */ |
|
| 175 | - public function get_date_created_gmt( $context = 'view' ) { |
|
| 169 | + * Get GMT date when the item was created. |
|
| 170 | + * |
|
| 171 | + * @since 1.0.19 |
|
| 172 | + * @param string $context View or edit context. |
|
| 173 | + * @return string |
|
| 174 | + */ |
|
| 175 | + public function get_date_created_gmt( $context = 'view' ) { |
|
| 176 | 176 | $date = $this->get_date_created( $context ); |
| 177 | 177 | |
| 178 | 178 | if ( $date ) { |
| 179 | 179 | $date = get_gmt_from_date( $date ); |
| 180 | 180 | } |
| 181 | - return $date; |
|
| 181 | + return $date; |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /** |
| 185 | - * Get date when the item was last modified. |
|
| 186 | - * |
|
| 187 | - * @since 1.0.19 |
|
| 188 | - * @param string $context View or edit context. |
|
| 189 | - * @return string |
|
| 190 | - */ |
|
| 191 | - public function get_date_modified( $context = 'view' ) { |
|
| 192 | - return $this->get_prop( 'date_modified', $context ); |
|
| 185 | + * Get date when the item was last modified. |
|
| 186 | + * |
|
| 187 | + * @since 1.0.19 |
|
| 188 | + * @param string $context View or edit context. |
|
| 189 | + * @return string |
|
| 190 | + */ |
|
| 191 | + public function get_date_modified( $context = 'view' ) { |
|
| 192 | + return $this->get_prop( 'date_modified', $context ); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
| 196 | - * Get GMT date when the item was last modified. |
|
| 197 | - * |
|
| 198 | - * @since 1.0.19 |
|
| 199 | - * @param string $context View or edit context. |
|
| 200 | - * @return string |
|
| 201 | - */ |
|
| 202 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
| 196 | + * Get GMT date when the item was last modified. |
|
| 197 | + * |
|
| 198 | + * @since 1.0.19 |
|
| 199 | + * @param string $context View or edit context. |
|
| 200 | + * @return string |
|
| 201 | + */ |
|
| 202 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
| 203 | 203 | $date = $this->get_date_modified( $context ); |
| 204 | 204 | |
| 205 | 205 | if ( $date ) { |
| 206 | 206 | $date = get_gmt_from_date( $date ); |
| 207 | 207 | } |
| 208 | - return $date; |
|
| 208 | + return $date; |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | /** |
| 212 | - * Get the item name. |
|
| 213 | - * |
|
| 214 | - * @since 1.0.19 |
|
| 215 | - * @param string $context View or edit context. |
|
| 216 | - * @return string |
|
| 217 | - */ |
|
| 218 | - public function get_name( $context = 'view' ) { |
|
| 219 | - return $this->get_prop( 'name', $context ); |
|
| 212 | + * Get the item name. |
|
| 213 | + * |
|
| 214 | + * @since 1.0.19 |
|
| 215 | + * @param string $context View or edit context. |
|
| 216 | + * @return string |
|
| 217 | + */ |
|
| 218 | + public function get_name( $context = 'view' ) { |
|
| 219 | + return $this->get_prop( 'name', $context ); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
| 223 | - * Alias of self::get_name(). |
|
| 224 | - * |
|
| 225 | - * @since 1.0.19 |
|
| 226 | - * @param string $context View or edit context. |
|
| 227 | - * @return string |
|
| 228 | - */ |
|
| 229 | - public function get_title( $context = 'view' ) { |
|
| 230 | - return $this->get_name( $context ); |
|
| 223 | + * Alias of self::get_name(). |
|
| 224 | + * |
|
| 225 | + * @since 1.0.19 |
|
| 226 | + * @param string $context View or edit context. |
|
| 227 | + * @return string |
|
| 228 | + */ |
|
| 229 | + public function get_title( $context = 'view' ) { |
|
| 230 | + return $this->get_name( $context ); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | /** |
| 234 | - * Get the item description. |
|
| 235 | - * |
|
| 236 | - * @since 1.0.19 |
|
| 237 | - * @param string $context View or edit context. |
|
| 238 | - * @return string |
|
| 239 | - */ |
|
| 240 | - public function get_description( $context = 'view' ) { |
|
| 241 | - return $this->get_prop( 'description', $context ); |
|
| 234 | + * Get the item description. |
|
| 235 | + * |
|
| 236 | + * @since 1.0.19 |
|
| 237 | + * @param string $context View or edit context. |
|
| 238 | + * @return string |
|
| 239 | + */ |
|
| 240 | + public function get_description( $context = 'view' ) { |
|
| 241 | + return $this->get_prop( 'description', $context ); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | /** |
| 245 | - * Alias of self::get_description(). |
|
| 246 | - * |
|
| 247 | - * @since 1.0.19 |
|
| 248 | - * @param string $context View or edit context. |
|
| 249 | - * @return string |
|
| 250 | - */ |
|
| 251 | - public function get_excerpt( $context = 'view' ) { |
|
| 252 | - return $this->get_description( $context ); |
|
| 245 | + * Alias of self::get_description(). |
|
| 246 | + * |
|
| 247 | + * @since 1.0.19 |
|
| 248 | + * @param string $context View or edit context. |
|
| 249 | + * @return string |
|
| 250 | + */ |
|
| 251 | + public function get_excerpt( $context = 'view' ) { |
|
| 252 | + return $this->get_description( $context ); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | /** |
| 256 | - * Alias of self::get_description(). |
|
| 257 | - * |
|
| 258 | - * @since 1.0.19 |
|
| 259 | - * @param string $context View or edit context. |
|
| 260 | - * @return string |
|
| 261 | - */ |
|
| 262 | - public function get_summary( $context = 'view' ) { |
|
| 263 | - return $this->get_description( $context ); |
|
| 256 | + * Alias of self::get_description(). |
|
| 257 | + * |
|
| 258 | + * @since 1.0.19 |
|
| 259 | + * @param string $context View or edit context. |
|
| 260 | + * @return string |
|
| 261 | + */ |
|
| 262 | + public function get_summary( $context = 'view' ) { |
|
| 263 | + return $this->get_description( $context ); |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | /** |
| 267 | - * Get the owner of the item. |
|
| 268 | - * |
|
| 269 | - * @since 1.0.19 |
|
| 270 | - * @param string $context View or edit context. |
|
| 271 | - * @return string |
|
| 272 | - */ |
|
| 273 | - public function get_author( $context = 'view' ) { |
|
| 274 | - return (int) $this->get_prop( 'author', $context ); |
|
| 267 | + * Get the owner of the item. |
|
| 268 | + * |
|
| 269 | + * @since 1.0.19 |
|
| 270 | + * @param string $context View or edit context. |
|
| 271 | + * @return string |
|
| 272 | + */ |
|
| 273 | + public function get_author( $context = 'view' ) { |
|
| 274 | + return (int) $this->get_prop( 'author', $context ); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | /** |
| 278 | - * Get the price of the item. |
|
| 279 | - * |
|
| 280 | - * @since 1.0.19 |
|
| 281 | - * @param string $context View or edit context. |
|
| 282 | - * @return float |
|
| 283 | - */ |
|
| 284 | - public function get_price( $context = 'view' ) { |
|
| 278 | + * Get the price of the item. |
|
| 279 | + * |
|
| 280 | + * @since 1.0.19 |
|
| 281 | + * @param string $context View or edit context. |
|
| 282 | + * @return float |
|
| 283 | + */ |
|
| 284 | + public function get_price( $context = 'view' ) { |
|
| 285 | 285 | return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) ); |
| 286 | - } |
|
| 286 | + } |
|
| 287 | 287 | |
| 288 | - /** |
|
| 289 | - * Get the inital price of the item. |
|
| 290 | - * |
|
| 291 | - * @since 1.0.19 |
|
| 292 | - * @param string $context View or edit context. |
|
| 293 | - * @return float |
|
| 294 | - */ |
|
| 295 | - public function get_initial_price( $context = 'view' ) { |
|
| 288 | + /** |
|
| 289 | + * Get the inital price of the item. |
|
| 290 | + * |
|
| 291 | + * @since 1.0.19 |
|
| 292 | + * @param string $context View or edit context. |
|
| 293 | + * @return float |
|
| 294 | + */ |
|
| 295 | + public function get_initial_price( $context = 'view' ) { |
|
| 296 | 296 | |
| 297 | - $price = (float) $this->get_price( $context ); |
|
| 297 | + $price = (float) $this->get_price( $context ); |
|
| 298 | 298 | |
| 299 | - if ( $this->has_free_trial() ) { |
|
| 300 | - $price = 0; |
|
| 301 | - } |
|
| 299 | + if ( $this->has_free_trial() ) { |
|
| 300 | + $price = 0; |
|
| 301 | + } |
|
| 302 | 302 | |
| 303 | 303 | return wpinv_sanitize_amount( apply_filters( 'wpinv_get_initial_item_price', $price, $this ) ); |
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | /** |
| 307 | - * Returns a formated price. |
|
| 308 | - * |
|
| 309 | - * @since 1.0.19 |
|
| 310 | - * @param string $context View or edit context. |
|
| 311 | - * @return string |
|
| 312 | - */ |
|
| 307 | + * Returns a formated price. |
|
| 308 | + * |
|
| 309 | + * @since 1.0.19 |
|
| 310 | + * @param string $context View or edit context. |
|
| 311 | + * @return string |
|
| 312 | + */ |
|
| 313 | 313 | public function get_the_price() { |
| 314 | 314 | return wpinv_price( wpinv_format_amount( $this->get_price() ) ); |
| 315 | - } |
|
| 316 | - |
|
| 317 | - /** |
|
| 318 | - * Returns the formated initial price. |
|
| 319 | - * |
|
| 320 | - * @since 1.0.19 |
|
| 321 | - * @param string $context View or edit context. |
|
| 322 | - * @return string |
|
| 323 | - */ |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + /** |
|
| 318 | + * Returns the formated initial price. |
|
| 319 | + * |
|
| 320 | + * @since 1.0.19 |
|
| 321 | + * @param string $context View or edit context. |
|
| 322 | + * @return string |
|
| 323 | + */ |
|
| 324 | 324 | public function get_the_initial_price() { |
| 325 | 325 | return wpinv_price( wpinv_format_amount( $this->get_initial_price() ) ); |
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | /** |
| 329 | - * Get the VAT rule of the item. |
|
| 330 | - * |
|
| 331 | - * @since 1.0.19 |
|
| 332 | - * @param string $context View or edit context. |
|
| 333 | - * @return string |
|
| 334 | - */ |
|
| 335 | - public function get_vat_rule( $context = 'view' ) { |
|
| 329 | + * Get the VAT rule of the item. |
|
| 330 | + * |
|
| 331 | + * @since 1.0.19 |
|
| 332 | + * @param string $context View or edit context. |
|
| 333 | + * @return string |
|
| 334 | + */ |
|
| 335 | + public function get_vat_rule( $context = 'view' ) { |
|
| 336 | 336 | return $this->get_prop( 'vat_rule', $context ); |
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | /** |
| 340 | - * Get the VAT class of the item. |
|
| 341 | - * |
|
| 342 | - * @since 1.0.19 |
|
| 343 | - * @param string $context View or edit context. |
|
| 344 | - * @return string |
|
| 345 | - */ |
|
| 346 | - public function get_vat_class( $context = 'view' ) { |
|
| 340 | + * Get the VAT class of the item. |
|
| 341 | + * |
|
| 342 | + * @since 1.0.19 |
|
| 343 | + * @param string $context View or edit context. |
|
| 344 | + * @return string |
|
| 345 | + */ |
|
| 346 | + public function get_vat_class( $context = 'view' ) { |
|
| 347 | 347 | return $this->get_prop( 'vat_class', $context ); |
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | /** |
| 351 | - * Get the type of the item. |
|
| 352 | - * |
|
| 353 | - * @since 1.0.19 |
|
| 354 | - * @param string $context View or edit context. |
|
| 355 | - * @return string |
|
| 356 | - */ |
|
| 357 | - public function get_type( $context = 'view' ) { |
|
| 351 | + * Get the type of the item. |
|
| 352 | + * |
|
| 353 | + * @since 1.0.19 |
|
| 354 | + * @param string $context View or edit context. |
|
| 355 | + * @return string |
|
| 356 | + */ |
|
| 357 | + public function get_type( $context = 'view' ) { |
|
| 358 | 358 | return $this->get_prop( 'type', $context ); |
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | /** |
| 362 | - * Get the custom id of the item. |
|
| 363 | - * |
|
| 364 | - * @since 1.0.19 |
|
| 365 | - * @param string $context View or edit context. |
|
| 366 | - * @return string |
|
| 367 | - */ |
|
| 368 | - public function get_custom_id( $context = 'view' ) { |
|
| 362 | + * Get the custom id of the item. |
|
| 363 | + * |
|
| 364 | + * @since 1.0.19 |
|
| 365 | + * @param string $context View or edit context. |
|
| 366 | + * @return string |
|
| 367 | + */ |
|
| 368 | + public function get_custom_id( $context = 'view' ) { |
|
| 369 | 369 | return $this->get_prop( 'custom_id', $context ); |
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | /** |
| 373 | - * Get the custom name of the item. |
|
| 374 | - * |
|
| 375 | - * @since 1.0.19 |
|
| 376 | - * @param string $context View or edit context. |
|
| 377 | - * @return string |
|
| 378 | - */ |
|
| 379 | - public function get_custom_name( $context = 'view' ) { |
|
| 373 | + * Get the custom name of the item. |
|
| 374 | + * |
|
| 375 | + * @since 1.0.19 |
|
| 376 | + * @param string $context View or edit context. |
|
| 377 | + * @return string |
|
| 378 | + */ |
|
| 379 | + public function get_custom_name( $context = 'view' ) { |
|
| 380 | 380 | return $this->get_prop( 'custom_name', $context ); |
| 381 | 381 | } |
| 382 | 382 | |
| 383 | 383 | /** |
| 384 | - * Get the custom singular name of the item. |
|
| 385 | - * |
|
| 386 | - * @since 1.0.19 |
|
| 387 | - * @param string $context View or edit context. |
|
| 388 | - * @return string |
|
| 389 | - */ |
|
| 390 | - public function get_custom_singular_name( $context = 'view' ) { |
|
| 384 | + * Get the custom singular name of the item. |
|
| 385 | + * |
|
| 386 | + * @since 1.0.19 |
|
| 387 | + * @param string $context View or edit context. |
|
| 388 | + * @return string |
|
| 389 | + */ |
|
| 390 | + public function get_custom_singular_name( $context = 'view' ) { |
|
| 391 | 391 | return $this->get_prop( 'custom_singular_name', $context ); |
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | /** |
| 395 | - * Checks if an item is editable.. |
|
| 396 | - * |
|
| 397 | - * @since 1.0.19 |
|
| 398 | - * @param string $context View or edit context. |
|
| 399 | - * @return int |
|
| 400 | - */ |
|
| 401 | - public function get_is_editable( $context = 'view' ) { |
|
| 395 | + * Checks if an item is editable.. |
|
| 396 | + * |
|
| 397 | + * @since 1.0.19 |
|
| 398 | + * @param string $context View or edit context. |
|
| 399 | + * @return int |
|
| 400 | + */ |
|
| 401 | + public function get_is_editable( $context = 'view' ) { |
|
| 402 | 402 | return (int) $this->get_prop( 'is_editable', $context ); |
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | /** |
| 406 | - * Alias of self::get_is_editable(). |
|
| 407 | - * |
|
| 408 | - * @since 1.0.19 |
|
| 409 | - * @param string $context View or edit context. |
|
| 410 | - * @return int |
|
| 411 | - */ |
|
| 412 | - public function get_editable( $context = 'view' ) { |
|
| 413 | - return $this->get_is_editable( $context ); |
|
| 406 | + * Alias of self::get_is_editable(). |
|
| 407 | + * |
|
| 408 | + * @since 1.0.19 |
|
| 409 | + * @param string $context View or edit context. |
|
| 410 | + * @return int |
|
| 411 | + */ |
|
| 412 | + public function get_editable( $context = 'view' ) { |
|
| 413 | + return $this->get_is_editable( $context ); |
|
| 414 | 414 | } |
| 415 | 415 | |
| 416 | 416 | /** |
| 417 | - * Checks if dynamic pricing is enabled. |
|
| 418 | - * |
|
| 419 | - * @since 1.0.19 |
|
| 420 | - * @param string $context View or edit context. |
|
| 421 | - * @return int |
|
| 422 | - */ |
|
| 423 | - public function get_is_dynamic_pricing( $context = 'view' ) { |
|
| 417 | + * Checks if dynamic pricing is enabled. |
|
| 418 | + * |
|
| 419 | + * @since 1.0.19 |
|
| 420 | + * @param string $context View or edit context. |
|
| 421 | + * @return int |
|
| 422 | + */ |
|
| 423 | + public function get_is_dynamic_pricing( $context = 'view' ) { |
|
| 424 | 424 | return (int) $this->get_prop( 'is_dynamic_pricing', $context ); |
| 425 | 425 | } |
| 426 | 426 | |
| 427 | 427 | /** |
| 428 | - * Returns the minimum price if dynamic pricing is enabled. |
|
| 429 | - * |
|
| 430 | - * @since 1.0.19 |
|
| 431 | - * @param string $context View or edit context. |
|
| 432 | - * @return float |
|
| 433 | - */ |
|
| 434 | - public function get_minimum_price( $context = 'view' ) { |
|
| 428 | + * Returns the minimum price if dynamic pricing is enabled. |
|
| 429 | + * |
|
| 430 | + * @since 1.0.19 |
|
| 431 | + * @param string $context View or edit context. |
|
| 432 | + * @return float |
|
| 433 | + */ |
|
| 434 | + public function get_minimum_price( $context = 'view' ) { |
|
| 435 | 435 | return wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) ); |
| 436 | 436 | } |
| 437 | 437 | |
| 438 | 438 | /** |
| 439 | - * Checks if this is a recurring item. |
|
| 440 | - * |
|
| 441 | - * @since 1.0.19 |
|
| 442 | - * @param string $context View or edit context. |
|
| 443 | - * @return int |
|
| 444 | - */ |
|
| 445 | - public function get_is_recurring( $context = 'view' ) { |
|
| 439 | + * Checks if this is a recurring item. |
|
| 440 | + * |
|
| 441 | + * @since 1.0.19 |
|
| 442 | + * @param string $context View or edit context. |
|
| 443 | + * @return int |
|
| 444 | + */ |
|
| 445 | + public function get_is_recurring( $context = 'view' ) { |
|
| 446 | 446 | return (int) $this->get_prop( 'is_recurring', $context ); |
| 447 | - } |
|
| 447 | + } |
|
| 448 | 448 | |
| 449 | - /** |
|
| 450 | - * Get the recurring price of the item. |
|
| 451 | - * |
|
| 452 | - * @since 1.0.19 |
|
| 453 | - * @param string $context View or edit context. |
|
| 454 | - * @return float |
|
| 455 | - */ |
|
| 456 | - public function get_recurring_price( $context = 'view' ) { |
|
| 457 | - $price = $this->get_price( $context ); |
|
| 449 | + /** |
|
| 450 | + * Get the recurring price of the item. |
|
| 451 | + * |
|
| 452 | + * @since 1.0.19 |
|
| 453 | + * @param string $context View or edit context. |
|
| 454 | + * @return float |
|
| 455 | + */ |
|
| 456 | + public function get_recurring_price( $context = 'view' ) { |
|
| 457 | + $price = $this->get_price( $context ); |
|
| 458 | 458 | return wpinv_sanitize_amount( apply_filters( 'wpinv_get_recurring_item_price', $price, $this->ID ) ); |
| 459 | - } |
|
| 460 | - |
|
| 461 | - /** |
|
| 462 | - * Get the first renewal date (in timestamps) of the item. |
|
| 463 | - * |
|
| 464 | - * @since 1.0.19 |
|
| 465 | - * @return int |
|
| 466 | - */ |
|
| 467 | - public function get_first_renewal_date() { |
|
| 468 | - |
|
| 469 | - $periods = array( |
|
| 470 | - 'D' => 'days', |
|
| 471 | - 'W' => 'weeks', |
|
| 472 | - 'M' => 'months', |
|
| 473 | - 'Y' => 'years', |
|
| 474 | - ); |
|
| 475 | - |
|
| 476 | - $period = $this->get_recurring_period(); |
|
| 477 | - $interval = $this->get_recurring_interval(); |
|
| 478 | - |
|
| 479 | - if ( $this->has_free_trial() ) { |
|
| 480 | - $period = $this->get_trial_period(); |
|
| 481 | - $interval = $this->get_trial_interval(); |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - $period = $periods[ $period ]; |
|
| 485 | - $interval = empty( $interval ) ? 1 : $interval; |
|
| 486 | - $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) ); |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + /** |
|
| 462 | + * Get the first renewal date (in timestamps) of the item. |
|
| 463 | + * |
|
| 464 | + * @since 1.0.19 |
|
| 465 | + * @return int |
|
| 466 | + */ |
|
| 467 | + public function get_first_renewal_date() { |
|
| 468 | + |
|
| 469 | + $periods = array( |
|
| 470 | + 'D' => 'days', |
|
| 471 | + 'W' => 'weeks', |
|
| 472 | + 'M' => 'months', |
|
| 473 | + 'Y' => 'years', |
|
| 474 | + ); |
|
| 475 | + |
|
| 476 | + $period = $this->get_recurring_period(); |
|
| 477 | + $interval = $this->get_recurring_interval(); |
|
| 478 | + |
|
| 479 | + if ( $this->has_free_trial() ) { |
|
| 480 | + $period = $this->get_trial_period(); |
|
| 481 | + $interval = $this->get_trial_interval(); |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + $period = $periods[ $period ]; |
|
| 485 | + $interval = empty( $interval ) ? 1 : $interval; |
|
| 486 | + $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) ); |
|
| 487 | 487 | return apply_filters( 'wpinv_get_first_renewal_date', $next_renewal, $this ); |
| 488 | 488 | } |
| 489 | 489 | |
| 490 | 490 | /** |
| 491 | - * Get the recurring period. |
|
| 492 | - * |
|
| 493 | - * @since 1.0.19 |
|
| 494 | - * @param bool $full Return abbreviation or in full. |
|
| 495 | - * @return string |
|
| 496 | - */ |
|
| 497 | - public function get_recurring_period( $full = false ) { |
|
| 491 | + * Get the recurring period. |
|
| 492 | + * |
|
| 493 | + * @since 1.0.19 |
|
| 494 | + * @param bool $full Return abbreviation or in full. |
|
| 495 | + * @return string |
|
| 496 | + */ |
|
| 497 | + public function get_recurring_period( $full = false ) { |
|
| 498 | 498 | $period = $this->get_prop( 'recurring_period', 'view' ); |
| 499 | 499 | |
| 500 | 500 | if ( $full && ! is_bool( $full ) ) { |
@@ -505,63 +505,63 @@ discard block |
||
| 505 | 505 | } |
| 506 | 506 | |
| 507 | 507 | /** |
| 508 | - * Get the recurring interval. |
|
| 509 | - * |
|
| 510 | - * @since 1.0.19 |
|
| 511 | - * @param string $context View or edit context. |
|
| 512 | - * @return int |
|
| 513 | - */ |
|
| 514 | - public function get_recurring_interval( $context = 'view' ) { |
|
| 515 | - $interval = absint( $this->get_prop( 'recurring_interval', $context ) ); |
|
| 508 | + * Get the recurring interval. |
|
| 509 | + * |
|
| 510 | + * @since 1.0.19 |
|
| 511 | + * @param string $context View or edit context. |
|
| 512 | + * @return int |
|
| 513 | + */ |
|
| 514 | + public function get_recurring_interval( $context = 'view' ) { |
|
| 515 | + $interval = absint( $this->get_prop( 'recurring_interval', $context ) ); |
|
| 516 | 516 | |
| 517 | - if ( $interval < 1 ) { |
|
| 518 | - $interval = 1; |
|
| 519 | - } |
|
| 517 | + if ( $interval < 1 ) { |
|
| 518 | + $interval = 1; |
|
| 519 | + } |
|
| 520 | 520 | |
| 521 | 521 | return $interval; |
| 522 | 522 | } |
| 523 | 523 | |
| 524 | 524 | /** |
| 525 | - * Get the recurring limit. |
|
| 526 | - * |
|
| 527 | - * @since 1.0.19 |
|
| 528 | - * @param string $context View or edit context. |
|
| 529 | - * @return int |
|
| 530 | - */ |
|
| 531 | - public function get_recurring_limit( $context = 'view' ) { |
|
| 525 | + * Get the recurring limit. |
|
| 526 | + * |
|
| 527 | + * @since 1.0.19 |
|
| 528 | + * @param string $context View or edit context. |
|
| 529 | + * @return int |
|
| 530 | + */ |
|
| 531 | + public function get_recurring_limit( $context = 'view' ) { |
|
| 532 | 532 | return (int) $this->get_prop( 'recurring_limit', $context ); |
| 533 | 533 | } |
| 534 | 534 | |
| 535 | 535 | /** |
| 536 | - * Checks if we have a free trial. |
|
| 537 | - * |
|
| 538 | - * @since 1.0.19 |
|
| 539 | - * @param string $context View or edit context. |
|
| 540 | - * @return int |
|
| 541 | - */ |
|
| 542 | - public function get_is_free_trial( $context = 'view' ) { |
|
| 536 | + * Checks if we have a free trial. |
|
| 537 | + * |
|
| 538 | + * @since 1.0.19 |
|
| 539 | + * @param string $context View or edit context. |
|
| 540 | + * @return int |
|
| 541 | + */ |
|
| 542 | + public function get_is_free_trial( $context = 'view' ) { |
|
| 543 | 543 | return (int) $this->get_prop( 'is_free_trial', $context ); |
| 544 | 544 | } |
| 545 | 545 | |
| 546 | 546 | /** |
| 547 | - * Alias for self::get_is_free_trial(). |
|
| 548 | - * |
|
| 549 | - * @since 1.0.19 |
|
| 550 | - * @param string $context View or edit context. |
|
| 551 | - * @return int |
|
| 552 | - */ |
|
| 553 | - public function get_free_trial( $context = 'view' ) { |
|
| 547 | + * Alias for self::get_is_free_trial(). |
|
| 548 | + * |
|
| 549 | + * @since 1.0.19 |
|
| 550 | + * @param string $context View or edit context. |
|
| 551 | + * @return int |
|
| 552 | + */ |
|
| 553 | + public function get_free_trial( $context = 'view' ) { |
|
| 554 | 554 | return $this->get_is_free_trial( $context ); |
| 555 | 555 | } |
| 556 | 556 | |
| 557 | 557 | /** |
| 558 | - * Get the trial period. |
|
| 559 | - * |
|
| 560 | - * @since 1.0.19 |
|
| 561 | - * @param bool $full Return abbreviation or in full. |
|
| 562 | - * @return string |
|
| 563 | - */ |
|
| 564 | - public function get_trial_period( $full = false ) { |
|
| 558 | + * Get the trial period. |
|
| 559 | + * |
|
| 560 | + * @since 1.0.19 |
|
| 561 | + * @param bool $full Return abbreviation or in full. |
|
| 562 | + * @return string |
|
| 563 | + */ |
|
| 564 | + public function get_trial_period( $full = false ) { |
|
| 565 | 565 | $period = $this->get_prop( 'trial_period', 'view' ); |
| 566 | 566 | |
| 567 | 567 | if ( $full && ! is_bool( $full ) ) { |
@@ -572,104 +572,104 @@ discard block |
||
| 572 | 572 | } |
| 573 | 573 | |
| 574 | 574 | /** |
| 575 | - * Get the trial interval. |
|
| 576 | - * |
|
| 577 | - * @since 1.0.19 |
|
| 578 | - * @param string $context View or edit context. |
|
| 579 | - * @return int |
|
| 580 | - */ |
|
| 581 | - public function get_trial_interval( $context = 'view' ) { |
|
| 575 | + * Get the trial interval. |
|
| 576 | + * |
|
| 577 | + * @since 1.0.19 |
|
| 578 | + * @param string $context View or edit context. |
|
| 579 | + * @return int |
|
| 580 | + */ |
|
| 581 | + public function get_trial_interval( $context = 'view' ) { |
|
| 582 | 582 | return (int) $this->get_prop( 'trial_interval', $context ); |
| 583 | - } |
|
| 583 | + } |
|
| 584 | 584 | |
| 585 | - /** |
|
| 586 | - * Get the item's edit url. |
|
| 587 | - * |
|
| 588 | - * @since 1.0.19 |
|
| 589 | - * @return string |
|
| 590 | - */ |
|
| 591 | - public function get_edit_url() { |
|
| 585 | + /** |
|
| 586 | + * Get the item's edit url. |
|
| 587 | + * |
|
| 588 | + * @since 1.0.19 |
|
| 589 | + * @return string |
|
| 590 | + */ |
|
| 591 | + public function get_edit_url() { |
|
| 592 | 592 | return get_edit_post_link( $this->get_id() ); |
| 593 | - } |
|
| 594 | - |
|
| 595 | - /** |
|
| 596 | - * Given an item's name/custom id, it returns its id. |
|
| 597 | - * |
|
| 598 | - * |
|
| 599 | - * @static |
|
| 600 | - * @param string $value The item name or custom id. |
|
| 601 | - * @param string $field Either name or custom_id. |
|
| 602 | - * @param string $type in case you need to search for a given type. |
|
| 603 | - * @since 1.0.15 |
|
| 604 | - * @return int |
|
| 605 | - */ |
|
| 606 | - public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) { |
|
| 607 | - |
|
| 608 | - // Trim the value. |
|
| 609 | - $value = trim( $value ); |
|
| 610 | - |
|
| 611 | - if ( empty( $value ) ) { |
|
| 612 | - return 0; |
|
| 613 | - } |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + /** |
|
| 596 | + * Given an item's name/custom id, it returns its id. |
|
| 597 | + * |
|
| 598 | + * |
|
| 599 | + * @static |
|
| 600 | + * @param string $value The item name or custom id. |
|
| 601 | + * @param string $field Either name or custom_id. |
|
| 602 | + * @param string $type in case you need to search for a given type. |
|
| 603 | + * @since 1.0.15 |
|
| 604 | + * @return int |
|
| 605 | + */ |
|
| 606 | + public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) { |
|
| 607 | + |
|
| 608 | + // Trim the value. |
|
| 609 | + $value = trim( $value ); |
|
| 610 | + |
|
| 611 | + if ( empty( $value ) ) { |
|
| 612 | + return 0; |
|
| 613 | + } |
|
| 614 | 614 | |
| 615 | 615 | // Valid fields. |
| 616 | 616 | $fields = array( 'custom_id', 'name', 'slug' ); |
| 617 | 617 | |
| 618 | - // Ensure a field has been passed. |
|
| 619 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 620 | - return 0; |
|
| 621 | - } |
|
| 622 | - |
|
| 623 | - if ( $field == 'name' ) { |
|
| 624 | - $field = 'slug'; |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - // Maybe retrieve from the cache. |
|
| 628 | - $item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
| 629 | - if ( ! empty( $item_id ) ) { |
|
| 630 | - return $item_id; |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - // Fetch from the db. |
|
| 634 | - if ( $field =='slug' ) { |
|
| 635 | - $items = get_posts( |
|
| 636 | - array( |
|
| 637 | - 'post_type' => 'wpi_item', |
|
| 638 | - 'name' => $value, |
|
| 639 | - 'posts_per_page' => 1, |
|
| 640 | - 'post_status' => 'any', |
|
| 641 | - ) |
|
| 642 | - ); |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - if ( $field =='custom_id' ) { |
|
| 646 | - $items = get_posts( |
|
| 647 | - array( |
|
| 648 | - 'post_type' => 'wpi_item', |
|
| 649 | - 'posts_per_page' => 1, |
|
| 650 | - 'post_status' => 'any', |
|
| 651 | - 'meta_query' => array( |
|
| 652 | - array( |
|
| 653 | - 'key' => '_wpinv_type', |
|
| 654 | - 'value' => $type, |
|
| 655 | - ), |
|
| 656 | - array( |
|
| 657 | - 'key' => '_wpinv_custom_id', |
|
| 658 | - 'value' => $type, |
|
| 659 | - ) |
|
| 660 | - ) |
|
| 661 | - ) |
|
| 662 | - ); |
|
| 663 | - } |
|
| 664 | - |
|
| 665 | - if ( empty( $items ) ) { |
|
| 666 | - return 0; |
|
| 667 | - } |
|
| 668 | - |
|
| 669 | - // Update the cache with our data |
|
| 670 | - wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
| 671 | - |
|
| 672 | - return $items[0]->ID; |
|
| 618 | + // Ensure a field has been passed. |
|
| 619 | + if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 620 | + return 0; |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + if ( $field == 'name' ) { |
|
| 624 | + $field = 'slug'; |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + // Maybe retrieve from the cache. |
|
| 628 | + $item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
| 629 | + if ( ! empty( $item_id ) ) { |
|
| 630 | + return $item_id; |
|
| 631 | + } |
|
| 632 | + |
|
| 633 | + // Fetch from the db. |
|
| 634 | + if ( $field =='slug' ) { |
|
| 635 | + $items = get_posts( |
|
| 636 | + array( |
|
| 637 | + 'post_type' => 'wpi_item', |
|
| 638 | + 'name' => $value, |
|
| 639 | + 'posts_per_page' => 1, |
|
| 640 | + 'post_status' => 'any', |
|
| 641 | + ) |
|
| 642 | + ); |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + if ( $field =='custom_id' ) { |
|
| 646 | + $items = get_posts( |
|
| 647 | + array( |
|
| 648 | + 'post_type' => 'wpi_item', |
|
| 649 | + 'posts_per_page' => 1, |
|
| 650 | + 'post_status' => 'any', |
|
| 651 | + 'meta_query' => array( |
|
| 652 | + array( |
|
| 653 | + 'key' => '_wpinv_type', |
|
| 654 | + 'value' => $type, |
|
| 655 | + ), |
|
| 656 | + array( |
|
| 657 | + 'key' => '_wpinv_custom_id', |
|
| 658 | + 'value' => $type, |
|
| 659 | + ) |
|
| 660 | + ) |
|
| 661 | + ) |
|
| 662 | + ); |
|
| 663 | + } |
|
| 664 | + |
|
| 665 | + if ( empty( $items ) ) { |
|
| 666 | + return 0; |
|
| 667 | + } |
|
| 668 | + |
|
| 669 | + // Update the cache with our data |
|
| 670 | + wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
| 671 | + |
|
| 672 | + return $items[0]->ID; |
|
| 673 | 673 | } |
| 674 | 674 | |
| 675 | 675 | /** |
@@ -702,52 +702,52 @@ discard block |
||
| 702 | 702 | */ |
| 703 | 703 | |
| 704 | 704 | /** |
| 705 | - * Set parent order ID. |
|
| 706 | - * |
|
| 707 | - * @since 1.0.19 |
|
| 708 | - */ |
|
| 709 | - public function set_parent_id( $value ) { |
|
| 710 | - if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) { |
|
| 711 | - return; |
|
| 712 | - } |
|
| 713 | - $this->set_prop( 'parent_id', absint( $value ) ); |
|
| 714 | - } |
|
| 715 | - |
|
| 716 | - /** |
|
| 717 | - * Sets item status. |
|
| 718 | - * |
|
| 719 | - * @since 1.0.19 |
|
| 720 | - * @param string $status New status. |
|
| 721 | - * @return array details of change. |
|
| 722 | - */ |
|
| 723 | - public function set_status( $status ) { |
|
| 705 | + * Set parent order ID. |
|
| 706 | + * |
|
| 707 | + * @since 1.0.19 |
|
| 708 | + */ |
|
| 709 | + public function set_parent_id( $value ) { |
|
| 710 | + if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) { |
|
| 711 | + return; |
|
| 712 | + } |
|
| 713 | + $this->set_prop( 'parent_id', absint( $value ) ); |
|
| 714 | + } |
|
| 715 | + |
|
| 716 | + /** |
|
| 717 | + * Sets item status. |
|
| 718 | + * |
|
| 719 | + * @since 1.0.19 |
|
| 720 | + * @param string $status New status. |
|
| 721 | + * @return array details of change. |
|
| 722 | + */ |
|
| 723 | + public function set_status( $status ) { |
|
| 724 | 724 | $old_status = $this->get_status(); |
| 725 | 725 | |
| 726 | 726 | $this->set_prop( 'status', $status ); |
| 727 | 727 | |
| 728 | - return array( |
|
| 729 | - 'from' => $old_status, |
|
| 730 | - 'to' => $status, |
|
| 731 | - ); |
|
| 728 | + return array( |
|
| 729 | + 'from' => $old_status, |
|
| 730 | + 'to' => $status, |
|
| 731 | + ); |
|
| 732 | 732 | } |
| 733 | 733 | |
| 734 | 734 | /** |
| 735 | - * Set plugin version when the item was created. |
|
| 736 | - * |
|
| 737 | - * @since 1.0.19 |
|
| 738 | - */ |
|
| 739 | - public function set_version( $value ) { |
|
| 740 | - $this->set_prop( 'version', $value ); |
|
| 735 | + * Set plugin version when the item was created. |
|
| 736 | + * |
|
| 737 | + * @since 1.0.19 |
|
| 738 | + */ |
|
| 739 | + public function set_version( $value ) { |
|
| 740 | + $this->set_prop( 'version', $value ); |
|
| 741 | 741 | } |
| 742 | 742 | |
| 743 | 743 | /** |
| 744 | - * Set date when the item was created. |
|
| 745 | - * |
|
| 746 | - * @since 1.0.19 |
|
| 747 | - * @param string $value Value to set. |
|
| 744 | + * Set date when the item was created. |
|
| 745 | + * |
|
| 746 | + * @since 1.0.19 |
|
| 747 | + * @param string $value Value to set. |
|
| 748 | 748 | * @return bool Whether or not the date was set. |
| 749 | - */ |
|
| 750 | - public function set_date_created( $value ) { |
|
| 749 | + */ |
|
| 750 | + public function set_date_created( $value ) { |
|
| 751 | 751 | $date = strtotime( $value ); |
| 752 | 752 | |
| 753 | 753 | if ( $date ) { |
@@ -760,13 +760,13 @@ discard block |
||
| 760 | 760 | } |
| 761 | 761 | |
| 762 | 762 | /** |
| 763 | - * Set date when the item was last modified. |
|
| 764 | - * |
|
| 765 | - * @since 1.0.19 |
|
| 766 | - * @param string $value Value to set. |
|
| 763 | + * Set date when the item was last modified. |
|
| 764 | + * |
|
| 765 | + * @since 1.0.19 |
|
| 766 | + * @param string $value Value to set. |
|
| 767 | 767 | * @return bool Whether or not the date was set. |
| 768 | - */ |
|
| 769 | - public function set_date_modified( $value ) { |
|
| 768 | + */ |
|
| 769 | + public function set_date_modified( $value ) { |
|
| 770 | 770 | $date = strtotime( $value ); |
| 771 | 771 | |
| 772 | 772 | if ( $date ) { |
@@ -779,105 +779,105 @@ discard block |
||
| 779 | 779 | } |
| 780 | 780 | |
| 781 | 781 | /** |
| 782 | - * Set the item name. |
|
| 783 | - * |
|
| 784 | - * @since 1.0.19 |
|
| 785 | - * @param string $value New name. |
|
| 786 | - */ |
|
| 787 | - public function set_name( $value ) { |
|
| 782 | + * Set the item name. |
|
| 783 | + * |
|
| 784 | + * @since 1.0.19 |
|
| 785 | + * @param string $value New name. |
|
| 786 | + */ |
|
| 787 | + public function set_name( $value ) { |
|
| 788 | 788 | $name = sanitize_text_field( $value ); |
| 789 | - $this->set_prop( 'name', $name ); |
|
| 789 | + $this->set_prop( 'name', $name ); |
|
| 790 | 790 | } |
| 791 | 791 | |
| 792 | 792 | /** |
| 793 | - * Alias of self::set_name(). |
|
| 794 | - * |
|
| 795 | - * @since 1.0.19 |
|
| 796 | - * @param string $value New name. |
|
| 797 | - */ |
|
| 798 | - public function set_title( $value ) { |
|
| 799 | - $this->set_name( $value ); |
|
| 793 | + * Alias of self::set_name(). |
|
| 794 | + * |
|
| 795 | + * @since 1.0.19 |
|
| 796 | + * @param string $value New name. |
|
| 797 | + */ |
|
| 798 | + public function set_title( $value ) { |
|
| 799 | + $this->set_name( $value ); |
|
| 800 | 800 | } |
| 801 | 801 | |
| 802 | 802 | /** |
| 803 | - * Set the item description. |
|
| 804 | - * |
|
| 805 | - * @since 1.0.19 |
|
| 806 | - * @param string $value New description. |
|
| 807 | - */ |
|
| 808 | - public function set_description( $value ) { |
|
| 803 | + * Set the item description. |
|
| 804 | + * |
|
| 805 | + * @since 1.0.19 |
|
| 806 | + * @param string $value New description. |
|
| 807 | + */ |
|
| 808 | + public function set_description( $value ) { |
|
| 809 | 809 | $description = wp_kses_post( $value ); |
| 810 | - return $this->set_prop( 'description', $description ); |
|
| 810 | + return $this->set_prop( 'description', $description ); |
|
| 811 | 811 | } |
| 812 | 812 | |
| 813 | 813 | /** |
| 814 | - * Alias of self::set_description(). |
|
| 815 | - * |
|
| 816 | - * @since 1.0.19 |
|
| 817 | - * @param string $value New description. |
|
| 818 | - */ |
|
| 819 | - public function set_excerpt( $value ) { |
|
| 820 | - $this->set_description( $value ); |
|
| 814 | + * Alias of self::set_description(). |
|
| 815 | + * |
|
| 816 | + * @since 1.0.19 |
|
| 817 | + * @param string $value New description. |
|
| 818 | + */ |
|
| 819 | + public function set_excerpt( $value ) { |
|
| 820 | + $this->set_description( $value ); |
|
| 821 | 821 | } |
| 822 | 822 | |
| 823 | 823 | /** |
| 824 | - * Alias of self::set_description(). |
|
| 825 | - * |
|
| 826 | - * @since 1.0.19 |
|
| 827 | - * @param string $value New description. |
|
| 828 | - */ |
|
| 829 | - public function set_summary( $value ) { |
|
| 830 | - $this->set_description( $value ); |
|
| 824 | + * Alias of self::set_description(). |
|
| 825 | + * |
|
| 826 | + * @since 1.0.19 |
|
| 827 | + * @param string $value New description. |
|
| 828 | + */ |
|
| 829 | + public function set_summary( $value ) { |
|
| 830 | + $this->set_description( $value ); |
|
| 831 | 831 | } |
| 832 | 832 | |
| 833 | 833 | /** |
| 834 | - * Set the owner of the item. |
|
| 835 | - * |
|
| 836 | - * @since 1.0.19 |
|
| 837 | - * @param int $value New author. |
|
| 838 | - */ |
|
| 839 | - public function set_author( $value ) { |
|
| 840 | - $this->set_prop( 'author', (int) $value ); |
|
| 834 | + * Set the owner of the item. |
|
| 835 | + * |
|
| 836 | + * @since 1.0.19 |
|
| 837 | + * @param int $value New author. |
|
| 838 | + */ |
|
| 839 | + public function set_author( $value ) { |
|
| 840 | + $this->set_prop( 'author', (int) $value ); |
|
| 841 | 841 | } |
| 842 | 842 | |
| 843 | 843 | /** |
| 844 | - * Set the price of the item. |
|
| 845 | - * |
|
| 846 | - * @since 1.0.19 |
|
| 847 | - * @param float $value New price. |
|
| 848 | - */ |
|
| 849 | - public function set_price( $value ) { |
|
| 844 | + * Set the price of the item. |
|
| 845 | + * |
|
| 846 | + * @since 1.0.19 |
|
| 847 | + * @param float $value New price. |
|
| 848 | + */ |
|
| 849 | + public function set_price( $value ) { |
|
| 850 | 850 | $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) ); |
| 851 | 851 | } |
| 852 | 852 | |
| 853 | 853 | /** |
| 854 | - * Set the VAT rule of the item. |
|
| 855 | - * |
|
| 856 | - * @since 1.0.19 |
|
| 857 | - * @param string $value new rule. |
|
| 858 | - */ |
|
| 859 | - public function set_vat_rule( $value ) { |
|
| 854 | + * Set the VAT rule of the item. |
|
| 855 | + * |
|
| 856 | + * @since 1.0.19 |
|
| 857 | + * @param string $value new rule. |
|
| 858 | + */ |
|
| 859 | + public function set_vat_rule( $value ) { |
|
| 860 | 860 | $this->set_prop( 'vat_rule', $value ); |
| 861 | 861 | } |
| 862 | 862 | |
| 863 | 863 | /** |
| 864 | - * Set the VAT class of the item. |
|
| 865 | - * |
|
| 866 | - * @since 1.0.19 |
|
| 867 | - * @param string $value new class. |
|
| 868 | - */ |
|
| 869 | - public function set_vat_class( $value ) { |
|
| 864 | + * Set the VAT class of the item. |
|
| 865 | + * |
|
| 866 | + * @since 1.0.19 |
|
| 867 | + * @param string $value new class. |
|
| 868 | + */ |
|
| 869 | + public function set_vat_class( $value ) { |
|
| 870 | 870 | $this->set_prop( 'vat_class', $value ); |
| 871 | 871 | } |
| 872 | 872 | |
| 873 | 873 | /** |
| 874 | - * Set the type of the item. |
|
| 875 | - * |
|
| 876 | - * @since 1.0.19 |
|
| 877 | - * @param string $value new item type. |
|
| 878 | - * @return string |
|
| 879 | - */ |
|
| 880 | - public function set_type( $value ) { |
|
| 874 | + * Set the type of the item. |
|
| 875 | + * |
|
| 876 | + * @since 1.0.19 |
|
| 877 | + * @param string $value new item type. |
|
| 878 | + * @return string |
|
| 879 | + */ |
|
| 880 | + public function set_type( $value ) { |
|
| 881 | 881 | |
| 882 | 882 | if ( empty( $value ) ) { |
| 883 | 883 | $value = 'custom'; |
@@ -887,134 +887,134 @@ discard block |
||
| 887 | 887 | } |
| 888 | 888 | |
| 889 | 889 | /** |
| 890 | - * Set the custom id of the item. |
|
| 891 | - * |
|
| 892 | - * @since 1.0.19 |
|
| 893 | - * @param string $value new custom id. |
|
| 894 | - */ |
|
| 895 | - public function set_custom_id( $value ) { |
|
| 890 | + * Set the custom id of the item. |
|
| 891 | + * |
|
| 892 | + * @since 1.0.19 |
|
| 893 | + * @param string $value new custom id. |
|
| 894 | + */ |
|
| 895 | + public function set_custom_id( $value ) { |
|
| 896 | 896 | $this->set_prop( 'custom_id', $value ); |
| 897 | 897 | } |
| 898 | 898 | |
| 899 | 899 | /** |
| 900 | - * Set the custom name of the item. |
|
| 901 | - * |
|
| 902 | - * @since 1.0.19 |
|
| 903 | - * @param string $value new custom name. |
|
| 904 | - */ |
|
| 905 | - public function set_custom_name( $value ) { |
|
| 900 | + * Set the custom name of the item. |
|
| 901 | + * |
|
| 902 | + * @since 1.0.19 |
|
| 903 | + * @param string $value new custom name. |
|
| 904 | + */ |
|
| 905 | + public function set_custom_name( $value ) { |
|
| 906 | 906 | $this->set_prop( 'custom_name', $value ); |
| 907 | 907 | } |
| 908 | 908 | |
| 909 | 909 | /** |
| 910 | - * Set the custom singular name of the item. |
|
| 911 | - * |
|
| 912 | - * @since 1.0.19 |
|
| 913 | - * @param string $value new custom singular name. |
|
| 914 | - */ |
|
| 915 | - public function set_custom_singular_name( $value ) { |
|
| 910 | + * Set the custom singular name of the item. |
|
| 911 | + * |
|
| 912 | + * @since 1.0.19 |
|
| 913 | + * @param string $value new custom singular name. |
|
| 914 | + */ |
|
| 915 | + public function set_custom_singular_name( $value ) { |
|
| 916 | 916 | $this->set_prop( 'custom_singular_name', $value ); |
| 917 | 917 | } |
| 918 | 918 | |
| 919 | 919 | /** |
| 920 | - * Sets if an item is editable.. |
|
| 921 | - * |
|
| 922 | - * @since 1.0.19 |
|
| 923 | - * @param int|bool $value whether or not the item is editable. |
|
| 924 | - */ |
|
| 925 | - public function set_is_editable( $value ) { |
|
| 926 | - if ( is_numeric( $value ) ) { |
|
| 927 | - $this->set_prop( 'is_editable', (int) $value ); |
|
| 928 | - } |
|
| 920 | + * Sets if an item is editable.. |
|
| 921 | + * |
|
| 922 | + * @since 1.0.19 |
|
| 923 | + * @param int|bool $value whether or not the item is editable. |
|
| 924 | + */ |
|
| 925 | + public function set_is_editable( $value ) { |
|
| 926 | + if ( is_numeric( $value ) ) { |
|
| 927 | + $this->set_prop( 'is_editable', (int) $value ); |
|
| 928 | + } |
|
| 929 | 929 | } |
| 930 | 930 | |
| 931 | 931 | /** |
| 932 | - * Sets if dynamic pricing is enabled. |
|
| 933 | - * |
|
| 934 | - * @since 1.0.19 |
|
| 935 | - * @param int|bool $value whether or not dynamic pricing is allowed. |
|
| 936 | - */ |
|
| 937 | - public function set_is_dynamic_pricing( $value ) { |
|
| 932 | + * Sets if dynamic pricing is enabled. |
|
| 933 | + * |
|
| 934 | + * @since 1.0.19 |
|
| 935 | + * @param int|bool $value whether or not dynamic pricing is allowed. |
|
| 936 | + */ |
|
| 937 | + public function set_is_dynamic_pricing( $value ) { |
|
| 938 | 938 | $this->set_prop( 'is_dynamic_pricing', (int) $value ); |
| 939 | 939 | } |
| 940 | 940 | |
| 941 | 941 | /** |
| 942 | - * Sets the minimum price if dynamic pricing is enabled. |
|
| 943 | - * |
|
| 944 | - * @since 1.0.19 |
|
| 945 | - * @param float $value minimum price. |
|
| 946 | - */ |
|
| 947 | - public function set_minimum_price( $value ) { |
|
| 942 | + * Sets the minimum price if dynamic pricing is enabled. |
|
| 943 | + * |
|
| 944 | + * @since 1.0.19 |
|
| 945 | + * @param float $value minimum price. |
|
| 946 | + */ |
|
| 947 | + public function set_minimum_price( $value ) { |
|
| 948 | 948 | $this->set_prop( 'minimum_price', (float) wpinv_sanitize_amount( $value ) ); |
| 949 | 949 | } |
| 950 | 950 | |
| 951 | 951 | /** |
| 952 | - * Sets if this is a recurring item. |
|
| 953 | - * |
|
| 954 | - * @since 1.0.19 |
|
| 955 | - * @param int|bool $value whether or not dynamic pricing is allowed. |
|
| 956 | - */ |
|
| 957 | - public function set_is_recurring( $value ) { |
|
| 952 | + * Sets if this is a recurring item. |
|
| 953 | + * |
|
| 954 | + * @since 1.0.19 |
|
| 955 | + * @param int|bool $value whether or not dynamic pricing is allowed. |
|
| 956 | + */ |
|
| 957 | + public function set_is_recurring( $value ) { |
|
| 958 | 958 | $this->set_prop( 'is_recurring', (int) $value ); |
| 959 | 959 | } |
| 960 | 960 | |
| 961 | 961 | /** |
| 962 | - * Set the recurring period. |
|
| 963 | - * |
|
| 964 | - * @since 1.0.19 |
|
| 965 | - * @param string $value new period. |
|
| 966 | - */ |
|
| 967 | - public function set_recurring_period( $value ) { |
|
| 962 | + * Set the recurring period. |
|
| 963 | + * |
|
| 964 | + * @since 1.0.19 |
|
| 965 | + * @param string $value new period. |
|
| 966 | + */ |
|
| 967 | + public function set_recurring_period( $value ) { |
|
| 968 | 968 | $this->set_prop( 'recurring_period', $value ); |
| 969 | 969 | } |
| 970 | 970 | |
| 971 | 971 | /** |
| 972 | - * Set the recurring interval. |
|
| 973 | - * |
|
| 974 | - * @since 1.0.19 |
|
| 975 | - * @param int $value recurring interval. |
|
| 976 | - */ |
|
| 977 | - public function set_recurring_interval( $value ) { |
|
| 972 | + * Set the recurring interval. |
|
| 973 | + * |
|
| 974 | + * @since 1.0.19 |
|
| 975 | + * @param int $value recurring interval. |
|
| 976 | + */ |
|
| 977 | + public function set_recurring_interval( $value ) { |
|
| 978 | 978 | return $this->set_prop( 'recurring_interval', (int) $value ); |
| 979 | 979 | } |
| 980 | 980 | |
| 981 | 981 | /** |
| 982 | - * Get the recurring limit. |
|
| 983 | - * @since 1.0.19 |
|
| 984 | - * @param int $value The recurring limit. |
|
| 985 | - * @return int |
|
| 986 | - */ |
|
| 987 | - public function set_recurring_limit( $value ) { |
|
| 982 | + * Get the recurring limit. |
|
| 983 | + * @since 1.0.19 |
|
| 984 | + * @param int $value The recurring limit. |
|
| 985 | + * @return int |
|
| 986 | + */ |
|
| 987 | + public function set_recurring_limit( $value ) { |
|
| 988 | 988 | $this->set_prop( 'recurring_limit', (int) $value ); |
| 989 | 989 | } |
| 990 | 990 | |
| 991 | 991 | /** |
| 992 | - * Checks if we have a free trial. |
|
| 993 | - * |
|
| 994 | - * @since 1.0.19 |
|
| 995 | - * @param int|bool $value whether or not it has a free trial. |
|
| 996 | - */ |
|
| 997 | - public function set_is_free_trial( $value ) { |
|
| 992 | + * Checks if we have a free trial. |
|
| 993 | + * |
|
| 994 | + * @since 1.0.19 |
|
| 995 | + * @param int|bool $value whether or not it has a free trial. |
|
| 996 | + */ |
|
| 997 | + public function set_is_free_trial( $value ) { |
|
| 998 | 998 | $this->set_prop( 'is_free_trial', (int) $value ); |
| 999 | 999 | } |
| 1000 | 1000 | |
| 1001 | 1001 | /** |
| 1002 | - * Set the trial period. |
|
| 1003 | - * |
|
| 1004 | - * @since 1.0.19 |
|
| 1005 | - * @param string $value trial period. |
|
| 1006 | - */ |
|
| 1007 | - public function set_trial_period( $value ) { |
|
| 1002 | + * Set the trial period. |
|
| 1003 | + * |
|
| 1004 | + * @since 1.0.19 |
|
| 1005 | + * @param string $value trial period. |
|
| 1006 | + */ |
|
| 1007 | + public function set_trial_period( $value ) { |
|
| 1008 | 1008 | $this->set_prop( 'trial_period', $value ); |
| 1009 | 1009 | } |
| 1010 | 1010 | |
| 1011 | 1011 | /** |
| 1012 | - * Set the trial interval. |
|
| 1013 | - * |
|
| 1014 | - * @since 1.0.19 |
|
| 1015 | - * @param int $value trial interval. |
|
| 1016 | - */ |
|
| 1017 | - public function set_trial_interval( $value ) { |
|
| 1012 | + * Set the trial interval. |
|
| 1013 | + * |
|
| 1014 | + * @since 1.0.19 |
|
| 1015 | + * @param int $value trial interval. |
|
| 1016 | + */ |
|
| 1017 | + public function set_trial_interval( $value ) { |
|
| 1018 | 1018 | $this->set_prop( 'trial_interval', $value ); |
| 1019 | 1019 | } |
| 1020 | 1020 | |
@@ -1022,17 +1022,17 @@ discard block |
||
| 1022 | 1022 | * Create an item. For backwards compatibilty. |
| 1023 | 1023 | * |
| 1024 | 1024 | * @deprecated |
| 1025 | - * @return int item id |
|
| 1025 | + * @return int item id |
|
| 1026 | 1026 | */ |
| 1027 | 1027 | public function create( $data = array() ) { |
| 1028 | 1028 | |
| 1029 | - // Set the properties. |
|
| 1030 | - if ( is_array( $data ) ) { |
|
| 1031 | - $this->set_props( $data ); |
|
| 1032 | - } |
|
| 1029 | + // Set the properties. |
|
| 1030 | + if ( is_array( $data ) ) { |
|
| 1031 | + $this->set_props( $data ); |
|
| 1032 | + } |
|
| 1033 | 1033 | |
| 1034 | - // Save the item. |
|
| 1035 | - return $this->save(); |
|
| 1034 | + // Save the item. |
|
| 1035 | + return $this->save(); |
|
| 1036 | 1036 | |
| 1037 | 1037 | } |
| 1038 | 1038 | |
@@ -1040,7 +1040,7 @@ discard block |
||
| 1040 | 1040 | * Updates an item. For backwards compatibilty. |
| 1041 | 1041 | * |
| 1042 | 1042 | * @deprecated |
| 1043 | - * @return int item id |
|
| 1043 | + * @return int item id |
|
| 1044 | 1044 | */ |
| 1045 | 1045 | public function update( $data = array() ) { |
| 1046 | 1046 | return $this->create( $data ); |
@@ -1056,84 +1056,84 @@ discard block |
||
| 1056 | 1056 | */ |
| 1057 | 1057 | |
| 1058 | 1058 | /** |
| 1059 | - * Checks whether the item has enabled dynamic pricing. |
|
| 1060 | - * |
|
| 1061 | - * @since 1.0.19 |
|
| 1062 | - * @return bool |
|
| 1063 | - */ |
|
| 1064 | - public function user_can_set_their_price() { |
|
| 1059 | + * Checks whether the item has enabled dynamic pricing. |
|
| 1060 | + * |
|
| 1061 | + * @since 1.0.19 |
|
| 1062 | + * @return bool |
|
| 1063 | + */ |
|
| 1064 | + public function user_can_set_their_price() { |
|
| 1065 | 1065 | return (bool) $this->get_is_dynamic_pricing(); |
| 1066 | - } |
|
| 1066 | + } |
|
| 1067 | 1067 | |
| 1068 | - /** |
|
| 1069 | - * Checks whether the item is recurring. |
|
| 1070 | - * |
|
| 1071 | - * @since 1.0.19 |
|
| 1072 | - * @return bool |
|
| 1073 | - */ |
|
| 1074 | - public function is_recurring() { |
|
| 1068 | + /** |
|
| 1069 | + * Checks whether the item is recurring. |
|
| 1070 | + * |
|
| 1071 | + * @since 1.0.19 |
|
| 1072 | + * @return bool |
|
| 1073 | + */ |
|
| 1074 | + public function is_recurring() { |
|
| 1075 | 1075 | return (bool) $this->get_is_recurring(); |
| 1076 | 1076 | } |
| 1077 | 1077 | |
| 1078 | 1078 | /** |
| 1079 | - * Checks whether the item has a free trial. |
|
| 1080 | - * |
|
| 1081 | - * @since 1.0.19 |
|
| 1082 | - * @return bool |
|
| 1083 | - */ |
|
| 1079 | + * Checks whether the item has a free trial. |
|
| 1080 | + * |
|
| 1081 | + * @since 1.0.19 |
|
| 1082 | + * @return bool |
|
| 1083 | + */ |
|
| 1084 | 1084 | public function has_free_trial() { |
| 1085 | 1085 | $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false; |
| 1086 | 1086 | return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this ); |
| 1087 | 1087 | } |
| 1088 | 1088 | |
| 1089 | 1089 | /** |
| 1090 | - * Checks whether the item is free. |
|
| 1091 | - * |
|
| 1092 | - * @since 1.0.19 |
|
| 1093 | - * @return bool |
|
| 1094 | - */ |
|
| 1090 | + * Checks whether the item is free. |
|
| 1091 | + * |
|
| 1092 | + * @since 1.0.19 |
|
| 1093 | + * @return bool |
|
| 1094 | + */ |
|
| 1095 | 1095 | public function is_free() { |
| 1096 | 1096 | $is_free = $this->get_price() == 0; |
| 1097 | 1097 | return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this ); |
| 1098 | 1098 | } |
| 1099 | 1099 | |
| 1100 | 1100 | /** |
| 1101 | - * Checks the item status against a passed in status. |
|
| 1102 | - * |
|
| 1103 | - * @param array|string $status Status to check. |
|
| 1104 | - * @return bool |
|
| 1105 | - */ |
|
| 1106 | - public function has_status( $status ) { |
|
| 1107 | - $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status; |
|
| 1108 | - return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status ); |
|
| 1101 | + * Checks the item status against a passed in status. |
|
| 1102 | + * |
|
| 1103 | + * @param array|string $status Status to check. |
|
| 1104 | + * @return bool |
|
| 1105 | + */ |
|
| 1106 | + public function has_status( $status ) { |
|
| 1107 | + $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status; |
|
| 1108 | + return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status ); |
|
| 1109 | 1109 | } |
| 1110 | 1110 | |
| 1111 | 1111 | /** |
| 1112 | - * Checks the item type against a passed in types. |
|
| 1113 | - * |
|
| 1114 | - * @param array|string $type Type to check. |
|
| 1115 | - * @return bool |
|
| 1116 | - */ |
|
| 1117 | - public function is_type( $type ) { |
|
| 1118 | - $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type; |
|
| 1119 | - return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type ); |
|
| 1120 | - } |
|
| 1112 | + * Checks the item type against a passed in types. |
|
| 1113 | + * |
|
| 1114 | + * @param array|string $type Type to check. |
|
| 1115 | + * @return bool |
|
| 1116 | + */ |
|
| 1117 | + public function is_type( $type ) { |
|
| 1118 | + $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type; |
|
| 1119 | + return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type ); |
|
| 1120 | + } |
|
| 1121 | 1121 | |
| 1122 | 1122 | /** |
| 1123 | - * Checks whether the item is editable. |
|
| 1124 | - * |
|
| 1125 | - * @since 1.0.19 |
|
| 1126 | - * @return bool |
|
| 1127 | - */ |
|
| 1123 | + * Checks whether the item is editable. |
|
| 1124 | + * |
|
| 1125 | + * @since 1.0.19 |
|
| 1126 | + * @return bool |
|
| 1127 | + */ |
|
| 1128 | 1128 | public function is_editable() { |
| 1129 | 1129 | $is_editable = $this->get_is_editable(); |
| 1130 | 1130 | return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this ); |
| 1131 | - } |
|
| 1131 | + } |
|
| 1132 | 1132 | |
| 1133 | - /** |
|
| 1134 | - * Returns an array of cart fees. |
|
| 1135 | - */ |
|
| 1136 | - public function get_fees( $type = 'fee', $item_id = 0 ) { |
|
| 1133 | + /** |
|
| 1134 | + * Returns an array of cart fees. |
|
| 1135 | + */ |
|
| 1136 | + public function get_fees( $type = 'fee', $item_id = 0 ) { |
|
| 1137 | 1137 | global $wpi_session; |
| 1138 | 1138 | |
| 1139 | 1139 | $fees = $wpi_session->get( 'wpi_cart_fees' ); |
@@ -1177,11 +1177,11 @@ discard block |
||
| 1177 | 1177 | } |
| 1178 | 1178 | |
| 1179 | 1179 | /** |
| 1180 | - * Checks whether the item is purchasable. |
|
| 1181 | - * |
|
| 1182 | - * @since 1.0.19 |
|
| 1183 | - * @return bool |
|
| 1184 | - */ |
|
| 1180 | + * Checks whether the item is purchasable. |
|
| 1181 | + * |
|
| 1182 | + * @since 1.0.19 |
|
| 1183 | + * @return bool |
|
| 1184 | + */ |
|
| 1185 | 1185 | public function can_purchase() { |
| 1186 | 1186 | $can_purchase = null !== $this->get_id(); |
| 1187 | 1187 | |
@@ -1193,11 +1193,11 @@ discard block |
||
| 1193 | 1193 | } |
| 1194 | 1194 | |
| 1195 | 1195 | /** |
| 1196 | - * Checks whether the item supports dynamic pricing. |
|
| 1197 | - * |
|
| 1198 | - * @since 1.0.19 |
|
| 1199 | - * @return bool |
|
| 1200 | - */ |
|
| 1196 | + * Checks whether the item supports dynamic pricing. |
|
| 1197 | + * |
|
| 1198 | + * @since 1.0.19 |
|
| 1199 | + * @return bool |
|
| 1200 | + */ |
|
| 1201 | 1201 | public function supports_dynamic_pricing() { |
| 1202 | 1202 | return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this ); |
| 1203 | 1203 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if (!defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -78,30 +78,30 @@ discard block |
||
| 78 | 78 | * |
| 79 | 79 | * @param int|object|WPInv_Item|WP_Post $item Item to read. |
| 80 | 80 | */ |
| 81 | - public function __construct( $item = 0 ) { |
|
| 82 | - parent::__construct( $item ); |
|
| 83 | - |
|
| 84 | - if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) { |
|
| 85 | - $this->set_id( $item ); |
|
| 86 | - } elseif ( $item instanceof self ) { |
|
| 87 | - $this->set_id( $item->get_id() ); |
|
| 88 | - } elseif ( ! empty( $item->ID ) ) { |
|
| 89 | - $this->set_id( $item->ID ); |
|
| 90 | - } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) { |
|
| 91 | - $this->set_id( $item_id ); |
|
| 92 | - } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) { |
|
| 93 | - $this->set_id( $item_id ); |
|
| 81 | + public function __construct($item = 0) { |
|
| 82 | + parent::__construct($item); |
|
| 83 | + |
|
| 84 | + if (!empty($item) && is_numeric($item) && 'wpi_item' == get_post_type($item)) { |
|
| 85 | + $this->set_id($item); |
|
| 86 | + } elseif ($item instanceof self) { |
|
| 87 | + $this->set_id($item->get_id()); |
|
| 88 | + } elseif (!empty($item->ID)) { |
|
| 89 | + $this->set_id($item->ID); |
|
| 90 | + } elseif (is_scalar($item) && $item_id = self::get_item_id_by_field($item, 'custom_id')) { |
|
| 91 | + $this->set_id($item_id); |
|
| 92 | + } elseif (is_scalar($item) && $item_id = self::get_item_id_by_field($item, 'name')) { |
|
| 93 | + $this->set_id($item_id); |
|
| 94 | 94 | } else { |
| 95 | - $this->set_object_read( true ); |
|
| 95 | + $this->set_object_read(true); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | // Load the datastore. |
| 99 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 99 | + $this->data_store = GetPaid_Data_Store::load($this->data_store_name); |
|
| 100 | 100 | |
| 101 | - if ( $this->get_id() > 0 ) { |
|
| 102 | - $this->post = get_post( $this->get_id() ); |
|
| 101 | + if ($this->get_id() > 0) { |
|
| 102 | + $this->post = get_post($this->get_id()); |
|
| 103 | 103 | $this->ID = $this->get_id(); |
| 104 | - $this->data_store->read( $this ); |
|
| 104 | + $this->data_store->read($this); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | } |
@@ -128,8 +128,8 @@ discard block |
||
| 128 | 128 | * @param string $context View or edit context. |
| 129 | 129 | * @return int |
| 130 | 130 | */ |
| 131 | - public function get_parent_id( $context = 'view' ) { |
|
| 132 | - return (int) $this->get_prop( 'parent_id', $context ); |
|
| 131 | + public function get_parent_id($context = 'view') { |
|
| 132 | + return (int) $this->get_prop('parent_id', $context); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /** |
@@ -139,8 +139,8 @@ discard block |
||
| 139 | 139 | * @param string $context View or edit context. |
| 140 | 140 | * @return string |
| 141 | 141 | */ |
| 142 | - public function get_status( $context = 'view' ) { |
|
| 143 | - return $this->get_prop( 'status', $context ); |
|
| 142 | + public function get_status($context = 'view') { |
|
| 143 | + return $this->get_prop('status', $context); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
@@ -150,8 +150,8 @@ discard block |
||
| 150 | 150 | * @param string $context View or edit context. |
| 151 | 151 | * @return string |
| 152 | 152 | */ |
| 153 | - public function get_version( $context = 'view' ) { |
|
| 154 | - return $this->get_prop( 'version', $context ); |
|
| 153 | + public function get_version($context = 'view') { |
|
| 154 | + return $this->get_prop('version', $context); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
@@ -161,8 +161,8 @@ discard block |
||
| 161 | 161 | * @param string $context View or edit context. |
| 162 | 162 | * @return string |
| 163 | 163 | */ |
| 164 | - public function get_date_created( $context = 'view' ) { |
|
| 165 | - return $this->get_prop( 'date_created', $context ); |
|
| 164 | + public function get_date_created($context = 'view') { |
|
| 165 | + return $this->get_prop('date_created', $context); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | /** |
@@ -172,11 +172,11 @@ discard block |
||
| 172 | 172 | * @param string $context View or edit context. |
| 173 | 173 | * @return string |
| 174 | 174 | */ |
| 175 | - public function get_date_created_gmt( $context = 'view' ) { |
|
| 176 | - $date = $this->get_date_created( $context ); |
|
| 175 | + public function get_date_created_gmt($context = 'view') { |
|
| 176 | + $date = $this->get_date_created($context); |
|
| 177 | 177 | |
| 178 | - if ( $date ) { |
|
| 179 | - $date = get_gmt_from_date( $date ); |
|
| 178 | + if ($date) { |
|
| 179 | + $date = get_gmt_from_date($date); |
|
| 180 | 180 | } |
| 181 | 181 | return $date; |
| 182 | 182 | } |
@@ -188,8 +188,8 @@ discard block |
||
| 188 | 188 | * @param string $context View or edit context. |
| 189 | 189 | * @return string |
| 190 | 190 | */ |
| 191 | - public function get_date_modified( $context = 'view' ) { |
|
| 192 | - return $this->get_prop( 'date_modified', $context ); |
|
| 191 | + public function get_date_modified($context = 'view') { |
|
| 192 | + return $this->get_prop('date_modified', $context); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
@@ -199,11 +199,11 @@ discard block |
||
| 199 | 199 | * @param string $context View or edit context. |
| 200 | 200 | * @return string |
| 201 | 201 | */ |
| 202 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
| 203 | - $date = $this->get_date_modified( $context ); |
|
| 202 | + public function get_date_modified_gmt($context = 'view') { |
|
| 203 | + $date = $this->get_date_modified($context); |
|
| 204 | 204 | |
| 205 | - if ( $date ) { |
|
| 206 | - $date = get_gmt_from_date( $date ); |
|
| 205 | + if ($date) { |
|
| 206 | + $date = get_gmt_from_date($date); |
|
| 207 | 207 | } |
| 208 | 208 | return $date; |
| 209 | 209 | } |
@@ -215,8 +215,8 @@ discard block |
||
| 215 | 215 | * @param string $context View or edit context. |
| 216 | 216 | * @return string |
| 217 | 217 | */ |
| 218 | - public function get_name( $context = 'view' ) { |
|
| 219 | - return $this->get_prop( 'name', $context ); |
|
| 218 | + public function get_name($context = 'view') { |
|
| 219 | + return $this->get_prop('name', $context); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
@@ -226,8 +226,8 @@ discard block |
||
| 226 | 226 | * @param string $context View or edit context. |
| 227 | 227 | * @return string |
| 228 | 228 | */ |
| 229 | - public function get_title( $context = 'view' ) { |
|
| 230 | - return $this->get_name( $context ); |
|
| 229 | + public function get_title($context = 'view') { |
|
| 230 | + return $this->get_name($context); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | /** |
@@ -237,8 +237,8 @@ discard block |
||
| 237 | 237 | * @param string $context View or edit context. |
| 238 | 238 | * @return string |
| 239 | 239 | */ |
| 240 | - public function get_description( $context = 'view' ) { |
|
| 241 | - return $this->get_prop( 'description', $context ); |
|
| 240 | + public function get_description($context = 'view') { |
|
| 241 | + return $this->get_prop('description', $context); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | /** |
@@ -248,8 +248,8 @@ discard block |
||
| 248 | 248 | * @param string $context View or edit context. |
| 249 | 249 | * @return string |
| 250 | 250 | */ |
| 251 | - public function get_excerpt( $context = 'view' ) { |
|
| 252 | - return $this->get_description( $context ); |
|
| 251 | + public function get_excerpt($context = 'view') { |
|
| 252 | + return $this->get_description($context); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | /** |
@@ -259,8 +259,8 @@ discard block |
||
| 259 | 259 | * @param string $context View or edit context. |
| 260 | 260 | * @return string |
| 261 | 261 | */ |
| 262 | - public function get_summary( $context = 'view' ) { |
|
| 263 | - return $this->get_description( $context ); |
|
| 262 | + public function get_summary($context = 'view') { |
|
| 263 | + return $this->get_description($context); |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | /** |
@@ -270,8 +270,8 @@ discard block |
||
| 270 | 270 | * @param string $context View or edit context. |
| 271 | 271 | * @return string |
| 272 | 272 | */ |
| 273 | - public function get_author( $context = 'view' ) { |
|
| 274 | - return (int) $this->get_prop( 'author', $context ); |
|
| 273 | + public function get_author($context = 'view') { |
|
| 274 | + return (int) $this->get_prop('author', $context); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | /** |
@@ -281,8 +281,8 @@ discard block |
||
| 281 | 281 | * @param string $context View or edit context. |
| 282 | 282 | * @return float |
| 283 | 283 | */ |
| 284 | - public function get_price( $context = 'view' ) { |
|
| 285 | - return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) ); |
|
| 284 | + public function get_price($context = 'view') { |
|
| 285 | + return wpinv_sanitize_amount($this->get_prop('price', $context)); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | /** |
@@ -292,15 +292,15 @@ discard block |
||
| 292 | 292 | * @param string $context View or edit context. |
| 293 | 293 | * @return float |
| 294 | 294 | */ |
| 295 | - public function get_initial_price( $context = 'view' ) { |
|
| 295 | + public function get_initial_price($context = 'view') { |
|
| 296 | 296 | |
| 297 | - $price = (float) $this->get_price( $context ); |
|
| 297 | + $price = (float) $this->get_price($context); |
|
| 298 | 298 | |
| 299 | - if ( $this->has_free_trial() ) { |
|
| 299 | + if ($this->has_free_trial()) { |
|
| 300 | 300 | $price = 0; |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | - return wpinv_sanitize_amount( apply_filters( 'wpinv_get_initial_item_price', $price, $this ) ); |
|
| 303 | + return wpinv_sanitize_amount(apply_filters('wpinv_get_initial_item_price', $price, $this)); |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | /** |
@@ -311,7 +311,7 @@ discard block |
||
| 311 | 311 | * @return string |
| 312 | 312 | */ |
| 313 | 313 | public function get_the_price() { |
| 314 | - return wpinv_price( wpinv_format_amount( $this->get_price() ) ); |
|
| 314 | + return wpinv_price(wpinv_format_amount($this->get_price())); |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | /** |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | * @return string |
| 323 | 323 | */ |
| 324 | 324 | public function get_the_initial_price() { |
| 325 | - return wpinv_price( wpinv_format_amount( $this->get_initial_price() ) ); |
|
| 325 | + return wpinv_price(wpinv_format_amount($this->get_initial_price())); |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | /** |
@@ -332,8 +332,8 @@ discard block |
||
| 332 | 332 | * @param string $context View or edit context. |
| 333 | 333 | * @return string |
| 334 | 334 | */ |
| 335 | - public function get_vat_rule( $context = 'view' ) { |
|
| 336 | - return $this->get_prop( 'vat_rule', $context ); |
|
| 335 | + public function get_vat_rule($context = 'view') { |
|
| 336 | + return $this->get_prop('vat_rule', $context); |
|
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | /** |
@@ -343,8 +343,8 @@ discard block |
||
| 343 | 343 | * @param string $context View or edit context. |
| 344 | 344 | * @return string |
| 345 | 345 | */ |
| 346 | - public function get_vat_class( $context = 'view' ) { |
|
| 347 | - return $this->get_prop( 'vat_class', $context ); |
|
| 346 | + public function get_vat_class($context = 'view') { |
|
| 347 | + return $this->get_prop('vat_class', $context); |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | /** |
@@ -354,8 +354,8 @@ discard block |
||
| 354 | 354 | * @param string $context View or edit context. |
| 355 | 355 | * @return string |
| 356 | 356 | */ |
| 357 | - public function get_type( $context = 'view' ) { |
|
| 358 | - return $this->get_prop( 'type', $context ); |
|
| 357 | + public function get_type($context = 'view') { |
|
| 358 | + return $this->get_prop('type', $context); |
|
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | /** |
@@ -365,8 +365,8 @@ discard block |
||
| 365 | 365 | * @param string $context View or edit context. |
| 366 | 366 | * @return string |
| 367 | 367 | */ |
| 368 | - public function get_custom_id( $context = 'view' ) { |
|
| 369 | - return $this->get_prop( 'custom_id', $context ); |
|
| 368 | + public function get_custom_id($context = 'view') { |
|
| 369 | + return $this->get_prop('custom_id', $context); |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | /** |
@@ -376,8 +376,8 @@ discard block |
||
| 376 | 376 | * @param string $context View or edit context. |
| 377 | 377 | * @return string |
| 378 | 378 | */ |
| 379 | - public function get_custom_name( $context = 'view' ) { |
|
| 380 | - return $this->get_prop( 'custom_name', $context ); |
|
| 379 | + public function get_custom_name($context = 'view') { |
|
| 380 | + return $this->get_prop('custom_name', $context); |
|
| 381 | 381 | } |
| 382 | 382 | |
| 383 | 383 | /** |
@@ -387,8 +387,8 @@ discard block |
||
| 387 | 387 | * @param string $context View or edit context. |
| 388 | 388 | * @return string |
| 389 | 389 | */ |
| 390 | - public function get_custom_singular_name( $context = 'view' ) { |
|
| 391 | - return $this->get_prop( 'custom_singular_name', $context ); |
|
| 390 | + public function get_custom_singular_name($context = 'view') { |
|
| 391 | + return $this->get_prop('custom_singular_name', $context); |
|
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | /** |
@@ -398,8 +398,8 @@ discard block |
||
| 398 | 398 | * @param string $context View or edit context. |
| 399 | 399 | * @return int |
| 400 | 400 | */ |
| 401 | - public function get_is_editable( $context = 'view' ) { |
|
| 402 | - return (int) $this->get_prop( 'is_editable', $context ); |
|
| 401 | + public function get_is_editable($context = 'view') { |
|
| 402 | + return (int) $this->get_prop('is_editable', $context); |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | /** |
@@ -409,8 +409,8 @@ discard block |
||
| 409 | 409 | * @param string $context View or edit context. |
| 410 | 410 | * @return int |
| 411 | 411 | */ |
| 412 | - public function get_editable( $context = 'view' ) { |
|
| 413 | - return $this->get_is_editable( $context ); |
|
| 412 | + public function get_editable($context = 'view') { |
|
| 413 | + return $this->get_is_editable($context); |
|
| 414 | 414 | } |
| 415 | 415 | |
| 416 | 416 | /** |
@@ -420,8 +420,8 @@ discard block |
||
| 420 | 420 | * @param string $context View or edit context. |
| 421 | 421 | * @return int |
| 422 | 422 | */ |
| 423 | - public function get_is_dynamic_pricing( $context = 'view' ) { |
|
| 424 | - return (int) $this->get_prop( 'is_dynamic_pricing', $context ); |
|
| 423 | + public function get_is_dynamic_pricing($context = 'view') { |
|
| 424 | + return (int) $this->get_prop('is_dynamic_pricing', $context); |
|
| 425 | 425 | } |
| 426 | 426 | |
| 427 | 427 | /** |
@@ -431,8 +431,8 @@ discard block |
||
| 431 | 431 | * @param string $context View or edit context. |
| 432 | 432 | * @return float |
| 433 | 433 | */ |
| 434 | - public function get_minimum_price( $context = 'view' ) { |
|
| 435 | - return wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) ); |
|
| 434 | + public function get_minimum_price($context = 'view') { |
|
| 435 | + return wpinv_sanitize_amount($this->get_prop('minimum_price', $context)); |
|
| 436 | 436 | } |
| 437 | 437 | |
| 438 | 438 | /** |
@@ -442,8 +442,8 @@ discard block |
||
| 442 | 442 | * @param string $context View or edit context. |
| 443 | 443 | * @return int |
| 444 | 444 | */ |
| 445 | - public function get_is_recurring( $context = 'view' ) { |
|
| 446 | - return (int) $this->get_prop( 'is_recurring', $context ); |
|
| 445 | + public function get_is_recurring($context = 'view') { |
|
| 446 | + return (int) $this->get_prop('is_recurring', $context); |
|
| 447 | 447 | } |
| 448 | 448 | |
| 449 | 449 | /** |
@@ -453,9 +453,9 @@ discard block |
||
| 453 | 453 | * @param string $context View or edit context. |
| 454 | 454 | * @return float |
| 455 | 455 | */ |
| 456 | - public function get_recurring_price( $context = 'view' ) { |
|
| 457 | - $price = $this->get_price( $context ); |
|
| 458 | - return wpinv_sanitize_amount( apply_filters( 'wpinv_get_recurring_item_price', $price, $this->ID ) ); |
|
| 456 | + public function get_recurring_price($context = 'view') { |
|
| 457 | + $price = $this->get_price($context); |
|
| 458 | + return wpinv_sanitize_amount(apply_filters('wpinv_get_recurring_item_price', $price, $this->ID)); |
|
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | /** |
@@ -476,15 +476,15 @@ discard block |
||
| 476 | 476 | $period = $this->get_recurring_period(); |
| 477 | 477 | $interval = $this->get_recurring_interval(); |
| 478 | 478 | |
| 479 | - if ( $this->has_free_trial() ) { |
|
| 479 | + if ($this->has_free_trial()) { |
|
| 480 | 480 | $period = $this->get_trial_period(); |
| 481 | 481 | $interval = $this->get_trial_interval(); |
| 482 | 482 | } |
| 483 | 483 | |
| 484 | - $period = $periods[ $period ]; |
|
| 485 | - $interval = empty( $interval ) ? 1 : $interval; |
|
| 486 | - $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) ); |
|
| 487 | - return apply_filters( 'wpinv_get_first_renewal_date', $next_renewal, $this ); |
|
| 484 | + $period = $periods[$period]; |
|
| 485 | + $interval = empty($interval) ? 1 : $interval; |
|
| 486 | + $next_renewal = strtotime("+$interval $period", current_time('timestamp')); |
|
| 487 | + return apply_filters('wpinv_get_first_renewal_date', $next_renewal, $this); |
|
| 488 | 488 | } |
| 489 | 489 | |
| 490 | 490 | /** |
@@ -494,14 +494,14 @@ discard block |
||
| 494 | 494 | * @param bool $full Return abbreviation or in full. |
| 495 | 495 | * @return string |
| 496 | 496 | */ |
| 497 | - public function get_recurring_period( $full = false ) { |
|
| 498 | - $period = $this->get_prop( 'recurring_period', 'view' ); |
|
| 497 | + public function get_recurring_period($full = false) { |
|
| 498 | + $period = $this->get_prop('recurring_period', 'view'); |
|
| 499 | 499 | |
| 500 | - if ( $full && ! is_bool( $full ) ) { |
|
| 500 | + if ($full && !is_bool($full)) { |
|
| 501 | 501 | $full = false; |
| 502 | 502 | } |
| 503 | 503 | |
| 504 | - return getpaid_sanitize_recurring_period( $period, $full ); |
|
| 504 | + return getpaid_sanitize_recurring_period($period, $full); |
|
| 505 | 505 | } |
| 506 | 506 | |
| 507 | 507 | /** |
@@ -511,10 +511,10 @@ discard block |
||
| 511 | 511 | * @param string $context View or edit context. |
| 512 | 512 | * @return int |
| 513 | 513 | */ |
| 514 | - public function get_recurring_interval( $context = 'view' ) { |
|
| 515 | - $interval = absint( $this->get_prop( 'recurring_interval', $context ) ); |
|
| 514 | + public function get_recurring_interval($context = 'view') { |
|
| 515 | + $interval = absint($this->get_prop('recurring_interval', $context)); |
|
| 516 | 516 | |
| 517 | - if ( $interval < 1 ) { |
|
| 517 | + if ($interval < 1) { |
|
| 518 | 518 | $interval = 1; |
| 519 | 519 | } |
| 520 | 520 | |
@@ -528,8 +528,8 @@ discard block |
||
| 528 | 528 | * @param string $context View or edit context. |
| 529 | 529 | * @return int |
| 530 | 530 | */ |
| 531 | - public function get_recurring_limit( $context = 'view' ) { |
|
| 532 | - return (int) $this->get_prop( 'recurring_limit', $context ); |
|
| 531 | + public function get_recurring_limit($context = 'view') { |
|
| 532 | + return (int) $this->get_prop('recurring_limit', $context); |
|
| 533 | 533 | } |
| 534 | 534 | |
| 535 | 535 | /** |
@@ -539,8 +539,8 @@ discard block |
||
| 539 | 539 | * @param string $context View or edit context. |
| 540 | 540 | * @return int |
| 541 | 541 | */ |
| 542 | - public function get_is_free_trial( $context = 'view' ) { |
|
| 543 | - return (int) $this->get_prop( 'is_free_trial', $context ); |
|
| 542 | + public function get_is_free_trial($context = 'view') { |
|
| 543 | + return (int) $this->get_prop('is_free_trial', $context); |
|
| 544 | 544 | } |
| 545 | 545 | |
| 546 | 546 | /** |
@@ -550,8 +550,8 @@ discard block |
||
| 550 | 550 | * @param string $context View or edit context. |
| 551 | 551 | * @return int |
| 552 | 552 | */ |
| 553 | - public function get_free_trial( $context = 'view' ) { |
|
| 554 | - return $this->get_is_free_trial( $context ); |
|
| 553 | + public function get_free_trial($context = 'view') { |
|
| 554 | + return $this->get_is_free_trial($context); |
|
| 555 | 555 | } |
| 556 | 556 | |
| 557 | 557 | /** |
@@ -561,14 +561,14 @@ discard block |
||
| 561 | 561 | * @param bool $full Return abbreviation or in full. |
| 562 | 562 | * @return string |
| 563 | 563 | */ |
| 564 | - public function get_trial_period( $full = false ) { |
|
| 565 | - $period = $this->get_prop( 'trial_period', 'view' ); |
|
| 564 | + public function get_trial_period($full = false) { |
|
| 565 | + $period = $this->get_prop('trial_period', 'view'); |
|
| 566 | 566 | |
| 567 | - if ( $full && ! is_bool( $full ) ) { |
|
| 567 | + if ($full && !is_bool($full)) { |
|
| 568 | 568 | $full = false; |
| 569 | 569 | } |
| 570 | 570 | |
| 571 | - return getpaid_sanitize_recurring_period( $period, $full ); |
|
| 571 | + return getpaid_sanitize_recurring_period($period, $full); |
|
| 572 | 572 | } |
| 573 | 573 | |
| 574 | 574 | /** |
@@ -578,8 +578,8 @@ discard block |
||
| 578 | 578 | * @param string $context View or edit context. |
| 579 | 579 | * @return int |
| 580 | 580 | */ |
| 581 | - public function get_trial_interval( $context = 'view' ) { |
|
| 582 | - return (int) $this->get_prop( 'trial_interval', $context ); |
|
| 581 | + public function get_trial_interval($context = 'view') { |
|
| 582 | + return (int) $this->get_prop('trial_interval', $context); |
|
| 583 | 583 | } |
| 584 | 584 | |
| 585 | 585 | /** |
@@ -589,7 +589,7 @@ discard block |
||
| 589 | 589 | * @return string |
| 590 | 590 | */ |
| 591 | 591 | public function get_edit_url() { |
| 592 | - return get_edit_post_link( $this->get_id() ); |
|
| 592 | + return get_edit_post_link($this->get_id()); |
|
| 593 | 593 | } |
| 594 | 594 | |
| 595 | 595 | /** |
@@ -603,35 +603,35 @@ discard block |
||
| 603 | 603 | * @since 1.0.15 |
| 604 | 604 | * @return int |
| 605 | 605 | */ |
| 606 | - public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) { |
|
| 606 | + public static function get_item_id_by_field($value, $field = 'custom_id', $type = '') { |
|
| 607 | 607 | |
| 608 | 608 | // Trim the value. |
| 609 | - $value = trim( $value ); |
|
| 609 | + $value = trim($value); |
|
| 610 | 610 | |
| 611 | - if ( empty( $value ) ) { |
|
| 611 | + if (empty($value)) { |
|
| 612 | 612 | return 0; |
| 613 | 613 | } |
| 614 | 614 | |
| 615 | 615 | // Valid fields. |
| 616 | - $fields = array( 'custom_id', 'name', 'slug' ); |
|
| 616 | + $fields = array('custom_id', 'name', 'slug'); |
|
| 617 | 617 | |
| 618 | 618 | // Ensure a field has been passed. |
| 619 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 619 | + if (empty($field) || !in_array($field, $fields)) { |
|
| 620 | 620 | return 0; |
| 621 | 621 | } |
| 622 | 622 | |
| 623 | - if ( $field == 'name' ) { |
|
| 623 | + if ($field == 'name') { |
|
| 624 | 624 | $field = 'slug'; |
| 625 | 625 | } |
| 626 | 626 | |
| 627 | 627 | // Maybe retrieve from the cache. |
| 628 | - $item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
| 629 | - if ( ! empty( $item_id ) ) { |
|
| 628 | + $item_id = wp_cache_get($value, "getpaid_{$type}_item_{$field}s_to_item_ids"); |
|
| 629 | + if (!empty($item_id)) { |
|
| 630 | 630 | return $item_id; |
| 631 | 631 | } |
| 632 | 632 | |
| 633 | 633 | // Fetch from the db. |
| 634 | - if ( $field =='slug' ) { |
|
| 634 | + if ($field == 'slug') { |
|
| 635 | 635 | $items = get_posts( |
| 636 | 636 | array( |
| 637 | 637 | 'post_type' => 'wpi_item', |
@@ -642,7 +642,7 @@ discard block |
||
| 642 | 642 | ); |
| 643 | 643 | } |
| 644 | 644 | |
| 645 | - if ( $field =='custom_id' ) { |
|
| 645 | + if ($field == 'custom_id') { |
|
| 646 | 646 | $items = get_posts( |
| 647 | 647 | array( |
| 648 | 648 | 'post_type' => 'wpi_item', |
@@ -662,12 +662,12 @@ discard block |
||
| 662 | 662 | ); |
| 663 | 663 | } |
| 664 | 664 | |
| 665 | - if ( empty( $items ) ) { |
|
| 665 | + if (empty($items)) { |
|
| 666 | 666 | return 0; |
| 667 | 667 | } |
| 668 | 668 | |
| 669 | 669 | // Update the cache with our data |
| 670 | - wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
| 670 | + wp_cache_set($value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids"); |
|
| 671 | 671 | |
| 672 | 672 | return $items[0]->ID; |
| 673 | 673 | } |
@@ -675,19 +675,19 @@ discard block |
||
| 675 | 675 | /** |
| 676 | 676 | * Margic method for retrieving a property. |
| 677 | 677 | */ |
| 678 | - public function __get( $key ) { |
|
| 678 | + public function __get($key) { |
|
| 679 | 679 | |
| 680 | 680 | // Check if we have a helper method for that. |
| 681 | - if ( method_exists( $this, 'get_' . $key ) ) { |
|
| 682 | - return call_user_func( array( $this, 'get_' . $key ) ); |
|
| 681 | + if (method_exists($this, 'get_' . $key)) { |
|
| 682 | + return call_user_func(array($this, 'get_' . $key)); |
|
| 683 | 683 | } |
| 684 | 684 | |
| 685 | 685 | // Check if the key is in the associated $post object. |
| 686 | - if ( ! empty( $this->post ) && isset( $this->post->$key ) ) { |
|
| 686 | + if (!empty($this->post) && isset($this->post->$key)) { |
|
| 687 | 687 | return $this->post->$key; |
| 688 | 688 | } |
| 689 | 689 | |
| 690 | - return $this->get_prop( $key ); |
|
| 690 | + return $this->get_prop($key); |
|
| 691 | 691 | |
| 692 | 692 | } |
| 693 | 693 | |
@@ -706,11 +706,11 @@ discard block |
||
| 706 | 706 | * |
| 707 | 707 | * @since 1.0.19 |
| 708 | 708 | */ |
| 709 | - public function set_parent_id( $value ) { |
|
| 710 | - if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) { |
|
| 709 | + public function set_parent_id($value) { |
|
| 710 | + if ($value && ($value === $this->get_id() || !get_post($value))) { |
|
| 711 | 711 | return; |
| 712 | 712 | } |
| 713 | - $this->set_prop( 'parent_id', absint( $value ) ); |
|
| 713 | + $this->set_prop('parent_id', absint($value)); |
|
| 714 | 714 | } |
| 715 | 715 | |
| 716 | 716 | /** |
@@ -720,10 +720,10 @@ discard block |
||
| 720 | 720 | * @param string $status New status. |
| 721 | 721 | * @return array details of change. |
| 722 | 722 | */ |
| 723 | - public function set_status( $status ) { |
|
| 723 | + public function set_status($status) { |
|
| 724 | 724 | $old_status = $this->get_status(); |
| 725 | 725 | |
| 726 | - $this->set_prop( 'status', $status ); |
|
| 726 | + $this->set_prop('status', $status); |
|
| 727 | 727 | |
| 728 | 728 | return array( |
| 729 | 729 | 'from' => $old_status, |
@@ -736,8 +736,8 @@ discard block |
||
| 736 | 736 | * |
| 737 | 737 | * @since 1.0.19 |
| 738 | 738 | */ |
| 739 | - public function set_version( $value ) { |
|
| 740 | - $this->set_prop( 'version', $value ); |
|
| 739 | + public function set_version($value) { |
|
| 740 | + $this->set_prop('version', $value); |
|
| 741 | 741 | } |
| 742 | 742 | |
| 743 | 743 | /** |
@@ -747,11 +747,11 @@ discard block |
||
| 747 | 747 | * @param string $value Value to set. |
| 748 | 748 | * @return bool Whether or not the date was set. |
| 749 | 749 | */ |
| 750 | - public function set_date_created( $value ) { |
|
| 751 | - $date = strtotime( $value ); |
|
| 750 | + public function set_date_created($value) { |
|
| 751 | + $date = strtotime($value); |
|
| 752 | 752 | |
| 753 | - if ( $date ) { |
|
| 754 | - $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) ); |
|
| 753 | + if ($date) { |
|
| 754 | + $this->set_prop('date_created', date('Y-m-d H:i:s', $date)); |
|
| 755 | 755 | return true; |
| 756 | 756 | } |
| 757 | 757 | |
@@ -766,11 +766,11 @@ discard block |
||
| 766 | 766 | * @param string $value Value to set. |
| 767 | 767 | * @return bool Whether or not the date was set. |
| 768 | 768 | */ |
| 769 | - public function set_date_modified( $value ) { |
|
| 770 | - $date = strtotime( $value ); |
|
| 769 | + public function set_date_modified($value) { |
|
| 770 | + $date = strtotime($value); |
|
| 771 | 771 | |
| 772 | - if ( $date ) { |
|
| 773 | - $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) ); |
|
| 772 | + if ($date) { |
|
| 773 | + $this->set_prop('date_modified', date('Y-m-d H:i:s', $date)); |
|
| 774 | 774 | return true; |
| 775 | 775 | } |
| 776 | 776 | |
@@ -784,9 +784,9 @@ discard block |
||
| 784 | 784 | * @since 1.0.19 |
| 785 | 785 | * @param string $value New name. |
| 786 | 786 | */ |
| 787 | - public function set_name( $value ) { |
|
| 788 | - $name = sanitize_text_field( $value ); |
|
| 789 | - $this->set_prop( 'name', $name ); |
|
| 787 | + public function set_name($value) { |
|
| 788 | + $name = sanitize_text_field($value); |
|
| 789 | + $this->set_prop('name', $name); |
|
| 790 | 790 | } |
| 791 | 791 | |
| 792 | 792 | /** |
@@ -795,8 +795,8 @@ discard block |
||
| 795 | 795 | * @since 1.0.19 |
| 796 | 796 | * @param string $value New name. |
| 797 | 797 | */ |
| 798 | - public function set_title( $value ) { |
|
| 799 | - $this->set_name( $value ); |
|
| 798 | + public function set_title($value) { |
|
| 799 | + $this->set_name($value); |
|
| 800 | 800 | } |
| 801 | 801 | |
| 802 | 802 | /** |
@@ -805,9 +805,9 @@ discard block |
||
| 805 | 805 | * @since 1.0.19 |
| 806 | 806 | * @param string $value New description. |
| 807 | 807 | */ |
| 808 | - public function set_description( $value ) { |
|
| 809 | - $description = wp_kses_post( $value ); |
|
| 810 | - return $this->set_prop( 'description', $description ); |
|
| 808 | + public function set_description($value) { |
|
| 809 | + $description = wp_kses_post($value); |
|
| 810 | + return $this->set_prop('description', $description); |
|
| 811 | 811 | } |
| 812 | 812 | |
| 813 | 813 | /** |
@@ -816,8 +816,8 @@ discard block |
||
| 816 | 816 | * @since 1.0.19 |
| 817 | 817 | * @param string $value New description. |
| 818 | 818 | */ |
| 819 | - public function set_excerpt( $value ) { |
|
| 820 | - $this->set_description( $value ); |
|
| 819 | + public function set_excerpt($value) { |
|
| 820 | + $this->set_description($value); |
|
| 821 | 821 | } |
| 822 | 822 | |
| 823 | 823 | /** |
@@ -826,8 +826,8 @@ discard block |
||
| 826 | 826 | * @since 1.0.19 |
| 827 | 827 | * @param string $value New description. |
| 828 | 828 | */ |
| 829 | - public function set_summary( $value ) { |
|
| 830 | - $this->set_description( $value ); |
|
| 829 | + public function set_summary($value) { |
|
| 830 | + $this->set_description($value); |
|
| 831 | 831 | } |
| 832 | 832 | |
| 833 | 833 | /** |
@@ -836,8 +836,8 @@ discard block |
||
| 836 | 836 | * @since 1.0.19 |
| 837 | 837 | * @param int $value New author. |
| 838 | 838 | */ |
| 839 | - public function set_author( $value ) { |
|
| 840 | - $this->set_prop( 'author', (int) $value ); |
|
| 839 | + public function set_author($value) { |
|
| 840 | + $this->set_prop('author', (int) $value); |
|
| 841 | 841 | } |
| 842 | 842 | |
| 843 | 843 | /** |
@@ -846,8 +846,8 @@ discard block |
||
| 846 | 846 | * @since 1.0.19 |
| 847 | 847 | * @param float $value New price. |
| 848 | 848 | */ |
| 849 | - public function set_price( $value ) { |
|
| 850 | - $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) ); |
|
| 849 | + public function set_price($value) { |
|
| 850 | + $this->set_prop('price', (float) wpinv_sanitize_amount($value)); |
|
| 851 | 851 | } |
| 852 | 852 | |
| 853 | 853 | /** |
@@ -856,8 +856,8 @@ discard block |
||
| 856 | 856 | * @since 1.0.19 |
| 857 | 857 | * @param string $value new rule. |
| 858 | 858 | */ |
| 859 | - public function set_vat_rule( $value ) { |
|
| 860 | - $this->set_prop( 'vat_rule', $value ); |
|
| 859 | + public function set_vat_rule($value) { |
|
| 860 | + $this->set_prop('vat_rule', $value); |
|
| 861 | 861 | } |
| 862 | 862 | |
| 863 | 863 | /** |
@@ -866,8 +866,8 @@ discard block |
||
| 866 | 866 | * @since 1.0.19 |
| 867 | 867 | * @param string $value new class. |
| 868 | 868 | */ |
| 869 | - public function set_vat_class( $value ) { |
|
| 870 | - $this->set_prop( 'vat_class', $value ); |
|
| 869 | + public function set_vat_class($value) { |
|
| 870 | + $this->set_prop('vat_class', $value); |
|
| 871 | 871 | } |
| 872 | 872 | |
| 873 | 873 | /** |
@@ -877,13 +877,13 @@ discard block |
||
| 877 | 877 | * @param string $value new item type. |
| 878 | 878 | * @return string |
| 879 | 879 | */ |
| 880 | - public function set_type( $value ) { |
|
| 880 | + public function set_type($value) { |
|
| 881 | 881 | |
| 882 | - if ( empty( $value ) ) { |
|
| 882 | + if (empty($value)) { |
|
| 883 | 883 | $value = 'custom'; |
| 884 | 884 | } |
| 885 | 885 | |
| 886 | - $this->set_prop( 'type', $value ); |
|
| 886 | + $this->set_prop('type', $value); |
|
| 887 | 887 | } |
| 888 | 888 | |
| 889 | 889 | /** |
@@ -892,8 +892,8 @@ discard block |
||
| 892 | 892 | * @since 1.0.19 |
| 893 | 893 | * @param string $value new custom id. |
| 894 | 894 | */ |
| 895 | - public function set_custom_id( $value ) { |
|
| 896 | - $this->set_prop( 'custom_id', $value ); |
|
| 895 | + public function set_custom_id($value) { |
|
| 896 | + $this->set_prop('custom_id', $value); |
|
| 897 | 897 | } |
| 898 | 898 | |
| 899 | 899 | /** |
@@ -902,8 +902,8 @@ discard block |
||
| 902 | 902 | * @since 1.0.19 |
| 903 | 903 | * @param string $value new custom name. |
| 904 | 904 | */ |
| 905 | - public function set_custom_name( $value ) { |
|
| 906 | - $this->set_prop( 'custom_name', $value ); |
|
| 905 | + public function set_custom_name($value) { |
|
| 906 | + $this->set_prop('custom_name', $value); |
|
| 907 | 907 | } |
| 908 | 908 | |
| 909 | 909 | /** |
@@ -912,8 +912,8 @@ discard block |
||
| 912 | 912 | * @since 1.0.19 |
| 913 | 913 | * @param string $value new custom singular name. |
| 914 | 914 | */ |
| 915 | - public function set_custom_singular_name( $value ) { |
|
| 916 | - $this->set_prop( 'custom_singular_name', $value ); |
|
| 915 | + public function set_custom_singular_name($value) { |
|
| 916 | + $this->set_prop('custom_singular_name', $value); |
|
| 917 | 917 | } |
| 918 | 918 | |
| 919 | 919 | /** |
@@ -922,9 +922,9 @@ discard block |
||
| 922 | 922 | * @since 1.0.19 |
| 923 | 923 | * @param int|bool $value whether or not the item is editable. |
| 924 | 924 | */ |
| 925 | - public function set_is_editable( $value ) { |
|
| 926 | - if ( is_numeric( $value ) ) { |
|
| 927 | - $this->set_prop( 'is_editable', (int) $value ); |
|
| 925 | + public function set_is_editable($value) { |
|
| 926 | + if (is_numeric($value)) { |
|
| 927 | + $this->set_prop('is_editable', (int) $value); |
|
| 928 | 928 | } |
| 929 | 929 | } |
| 930 | 930 | |
@@ -934,8 +934,8 @@ discard block |
||
| 934 | 934 | * @since 1.0.19 |
| 935 | 935 | * @param int|bool $value whether or not dynamic pricing is allowed. |
| 936 | 936 | */ |
| 937 | - public function set_is_dynamic_pricing( $value ) { |
|
| 938 | - $this->set_prop( 'is_dynamic_pricing', (int) $value ); |
|
| 937 | + public function set_is_dynamic_pricing($value) { |
|
| 938 | + $this->set_prop('is_dynamic_pricing', (int) $value); |
|
| 939 | 939 | } |
| 940 | 940 | |
| 941 | 941 | /** |
@@ -944,8 +944,8 @@ discard block |
||
| 944 | 944 | * @since 1.0.19 |
| 945 | 945 | * @param float $value minimum price. |
| 946 | 946 | */ |
| 947 | - public function set_minimum_price( $value ) { |
|
| 948 | - $this->set_prop( 'minimum_price', (float) wpinv_sanitize_amount( $value ) ); |
|
| 947 | + public function set_minimum_price($value) { |
|
| 948 | + $this->set_prop('minimum_price', (float) wpinv_sanitize_amount($value)); |
|
| 949 | 949 | } |
| 950 | 950 | |
| 951 | 951 | /** |
@@ -954,8 +954,8 @@ discard block |
||
| 954 | 954 | * @since 1.0.19 |
| 955 | 955 | * @param int|bool $value whether or not dynamic pricing is allowed. |
| 956 | 956 | */ |
| 957 | - public function set_is_recurring( $value ) { |
|
| 958 | - $this->set_prop( 'is_recurring', (int) $value ); |
|
| 957 | + public function set_is_recurring($value) { |
|
| 958 | + $this->set_prop('is_recurring', (int) $value); |
|
| 959 | 959 | } |
| 960 | 960 | |
| 961 | 961 | /** |
@@ -964,8 +964,8 @@ discard block |
||
| 964 | 964 | * @since 1.0.19 |
| 965 | 965 | * @param string $value new period. |
| 966 | 966 | */ |
| 967 | - public function set_recurring_period( $value ) { |
|
| 968 | - $this->set_prop( 'recurring_period', $value ); |
|
| 967 | + public function set_recurring_period($value) { |
|
| 968 | + $this->set_prop('recurring_period', $value); |
|
| 969 | 969 | } |
| 970 | 970 | |
| 971 | 971 | /** |
@@ -974,8 +974,8 @@ discard block |
||
| 974 | 974 | * @since 1.0.19 |
| 975 | 975 | * @param int $value recurring interval. |
| 976 | 976 | */ |
| 977 | - public function set_recurring_interval( $value ) { |
|
| 978 | - return $this->set_prop( 'recurring_interval', (int) $value ); |
|
| 977 | + public function set_recurring_interval($value) { |
|
| 978 | + return $this->set_prop('recurring_interval', (int) $value); |
|
| 979 | 979 | } |
| 980 | 980 | |
| 981 | 981 | /** |
@@ -984,8 +984,8 @@ discard block |
||
| 984 | 984 | * @param int $value The recurring limit. |
| 985 | 985 | * @return int |
| 986 | 986 | */ |
| 987 | - public function set_recurring_limit( $value ) { |
|
| 988 | - $this->set_prop( 'recurring_limit', (int) $value ); |
|
| 987 | + public function set_recurring_limit($value) { |
|
| 988 | + $this->set_prop('recurring_limit', (int) $value); |
|
| 989 | 989 | } |
| 990 | 990 | |
| 991 | 991 | /** |
@@ -994,8 +994,8 @@ discard block |
||
| 994 | 994 | * @since 1.0.19 |
| 995 | 995 | * @param int|bool $value whether or not it has a free trial. |
| 996 | 996 | */ |
| 997 | - public function set_is_free_trial( $value ) { |
|
| 998 | - $this->set_prop( 'is_free_trial', (int) $value ); |
|
| 997 | + public function set_is_free_trial($value) { |
|
| 998 | + $this->set_prop('is_free_trial', (int) $value); |
|
| 999 | 999 | } |
| 1000 | 1000 | |
| 1001 | 1001 | /** |
@@ -1004,8 +1004,8 @@ discard block |
||
| 1004 | 1004 | * @since 1.0.19 |
| 1005 | 1005 | * @param string $value trial period. |
| 1006 | 1006 | */ |
| 1007 | - public function set_trial_period( $value ) { |
|
| 1008 | - $this->set_prop( 'trial_period', $value ); |
|
| 1007 | + public function set_trial_period($value) { |
|
| 1008 | + $this->set_prop('trial_period', $value); |
|
| 1009 | 1009 | } |
| 1010 | 1010 | |
| 1011 | 1011 | /** |
@@ -1014,8 +1014,8 @@ discard block |
||
| 1014 | 1014 | * @since 1.0.19 |
| 1015 | 1015 | * @param int $value trial interval. |
| 1016 | 1016 | */ |
| 1017 | - public function set_trial_interval( $value ) { |
|
| 1018 | - $this->set_prop( 'trial_interval', $value ); |
|
| 1017 | + public function set_trial_interval($value) { |
|
| 1018 | + $this->set_prop('trial_interval', $value); |
|
| 1019 | 1019 | } |
| 1020 | 1020 | |
| 1021 | 1021 | /** |
@@ -1024,11 +1024,11 @@ discard block |
||
| 1024 | 1024 | * @deprecated |
| 1025 | 1025 | * @return int item id |
| 1026 | 1026 | */ |
| 1027 | - public function create( $data = array() ) { |
|
| 1027 | + public function create($data = array()) { |
|
| 1028 | 1028 | |
| 1029 | 1029 | // Set the properties. |
| 1030 | - if ( is_array( $data ) ) { |
|
| 1031 | - $this->set_props( $data ); |
|
| 1030 | + if (is_array($data)) { |
|
| 1031 | + $this->set_props($data); |
|
| 1032 | 1032 | } |
| 1033 | 1033 | |
| 1034 | 1034 | // Save the item. |
@@ -1042,8 +1042,8 @@ discard block |
||
| 1042 | 1042 | * @deprecated |
| 1043 | 1043 | * @return int item id |
| 1044 | 1044 | */ |
| 1045 | - public function update( $data = array() ) { |
|
| 1046 | - return $this->create( $data ); |
|
| 1045 | + public function update($data = array()) { |
|
| 1046 | + return $this->create($data); |
|
| 1047 | 1047 | } |
| 1048 | 1048 | |
| 1049 | 1049 | /* |
@@ -1083,7 +1083,7 @@ discard block |
||
| 1083 | 1083 | */ |
| 1084 | 1084 | public function has_free_trial() { |
| 1085 | 1085 | $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false; |
| 1086 | - return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this ); |
|
| 1086 | + return (bool) apply_filters('wpinv_item_has_free_trial', $has_trial, $this->ID, $this); |
|
| 1087 | 1087 | } |
| 1088 | 1088 | |
| 1089 | 1089 | /** |
@@ -1093,8 +1093,8 @@ discard block |
||
| 1093 | 1093 | * @return bool |
| 1094 | 1094 | */ |
| 1095 | 1095 | public function is_free() { |
| 1096 | - $is_free = $this->get_price() == 0; |
|
| 1097 | - return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this ); |
|
| 1096 | + $is_free = $this->get_price() == 0; |
|
| 1097 | + return (bool) apply_filters('wpinv_is_free_item', $is_free, $this->ID, $this); |
|
| 1098 | 1098 | } |
| 1099 | 1099 | |
| 1100 | 1100 | /** |
@@ -1103,9 +1103,9 @@ discard block |
||
| 1103 | 1103 | * @param array|string $status Status to check. |
| 1104 | 1104 | * @return bool |
| 1105 | 1105 | */ |
| 1106 | - public function has_status( $status ) { |
|
| 1107 | - $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status; |
|
| 1108 | - return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status ); |
|
| 1106 | + public function has_status($status) { |
|
| 1107 | + $has_status = (is_array($status) && in_array($this->get_status(), $status, true)) || $this->get_status() === $status; |
|
| 1108 | + return (bool) apply_filters('getpaid_item_has_status', $has_status, $this, $status); |
|
| 1109 | 1109 | } |
| 1110 | 1110 | |
| 1111 | 1111 | /** |
@@ -1114,9 +1114,9 @@ discard block |
||
| 1114 | 1114 | * @param array|string $type Type to check. |
| 1115 | 1115 | * @return bool |
| 1116 | 1116 | */ |
| 1117 | - public function is_type( $type ) { |
|
| 1118 | - $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type; |
|
| 1119 | - return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type ); |
|
| 1117 | + public function is_type($type) { |
|
| 1118 | + $is_type = (is_array($type) && in_array($this->get_type(), $type, true)) || $this->get_type() === $type; |
|
| 1119 | + return (bool) apply_filters('getpaid_item_is_type', $is_type, $this, $type); |
|
| 1120 | 1120 | } |
| 1121 | 1121 | |
| 1122 | 1122 | /** |
@@ -1127,53 +1127,53 @@ discard block |
||
| 1127 | 1127 | */ |
| 1128 | 1128 | public function is_editable() { |
| 1129 | 1129 | $is_editable = $this->get_is_editable(); |
| 1130 | - return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this ); |
|
| 1130 | + return (bool) apply_filters('wpinv_item_is_editable', $is_editable, $this->ID, $this); |
|
| 1131 | 1131 | } |
| 1132 | 1132 | |
| 1133 | 1133 | /** |
| 1134 | 1134 | * Returns an array of cart fees. |
| 1135 | 1135 | */ |
| 1136 | - public function get_fees( $type = 'fee', $item_id = 0 ) { |
|
| 1136 | + public function get_fees($type = 'fee', $item_id = 0) { |
|
| 1137 | 1137 | global $wpi_session; |
| 1138 | 1138 | |
| 1139 | - $fees = $wpi_session->get( 'wpi_cart_fees' ); |
|
| 1139 | + $fees = $wpi_session->get('wpi_cart_fees'); |
|
| 1140 | 1140 | |
| 1141 | - if ( ! wpinv_get_cart_contents() ) { |
|
| 1141 | + if (!wpinv_get_cart_contents()) { |
|
| 1142 | 1142 | // We can only get item type fees when the cart is empty |
| 1143 | 1143 | $type = 'custom'; |
| 1144 | 1144 | } |
| 1145 | 1145 | |
| 1146 | - if ( ! empty( $fees ) && ! empty( $type ) && 'all' !== $type ) { |
|
| 1147 | - foreach( $fees as $key => $fee ) { |
|
| 1148 | - if( ! empty( $fee['type'] ) && $type != $fee['type'] ) { |
|
| 1149 | - unset( $fees[ $key ] ); |
|
| 1146 | + if (!empty($fees) && !empty($type) && 'all' !== $type) { |
|
| 1147 | + foreach ($fees as $key => $fee) { |
|
| 1148 | + if (!empty($fee['type']) && $type != $fee['type']) { |
|
| 1149 | + unset($fees[$key]); |
|
| 1150 | 1150 | } |
| 1151 | 1151 | } |
| 1152 | 1152 | } |
| 1153 | 1153 | |
| 1154 | - if ( ! empty( $fees ) && ! empty( $item_id ) ) { |
|
| 1154 | + if (!empty($fees) && !empty($item_id)) { |
|
| 1155 | 1155 | // Remove fees that don't belong to the specified Item |
| 1156 | - foreach ( $fees as $key => $fee ) { |
|
| 1157 | - if ( (int) $item_id !== (int)$fee['custom_id'] ) { |
|
| 1158 | - unset( $fees[ $key ] ); |
|
| 1156 | + foreach ($fees as $key => $fee) { |
|
| 1157 | + if ((int) $item_id !== (int) $fee['custom_id']) { |
|
| 1158 | + unset($fees[$key]); |
|
| 1159 | 1159 | } |
| 1160 | 1160 | } |
| 1161 | 1161 | } |
| 1162 | 1162 | |
| 1163 | - if ( ! empty( $fees ) ) { |
|
| 1163 | + if (!empty($fees)) { |
|
| 1164 | 1164 | // Remove fees that belong to a specific item but are not in the cart |
| 1165 | - foreach( $fees as $key => $fee ) { |
|
| 1166 | - if( empty( $fee['custom_id'] ) ) { |
|
| 1165 | + foreach ($fees as $key => $fee) { |
|
| 1166 | + if (empty($fee['custom_id'])) { |
|
| 1167 | 1167 | continue; |
| 1168 | 1168 | } |
| 1169 | 1169 | |
| 1170 | - if ( !wpinv_item_in_cart( $fee['custom_id'] ) ) { |
|
| 1171 | - unset( $fees[ $key ] ); |
|
| 1170 | + if (!wpinv_item_in_cart($fee['custom_id'])) { |
|
| 1171 | + unset($fees[$key]); |
|
| 1172 | 1172 | } |
| 1173 | 1173 | } |
| 1174 | 1174 | } |
| 1175 | 1175 | |
| 1176 | - return ! empty( $fees ) ? $fees : array(); |
|
| 1176 | + return !empty($fees) ? $fees : array(); |
|
| 1177 | 1177 | } |
| 1178 | 1178 | |
| 1179 | 1179 | /** |
@@ -1185,11 +1185,11 @@ discard block |
||
| 1185 | 1185 | public function can_purchase() { |
| 1186 | 1186 | $can_purchase = null !== $this->get_id(); |
| 1187 | 1187 | |
| 1188 | - if ( ! current_user_can( 'edit_post', $this->ID ) && $this->post_status != 'publish' ) { |
|
| 1188 | + if (!current_user_can('edit_post', $this->ID) && $this->post_status != 'publish') { |
|
| 1189 | 1189 | $can_purchase = false; |
| 1190 | 1190 | } |
| 1191 | 1191 | |
| 1192 | - return (bool) apply_filters( 'wpinv_can_purchase_item', $can_purchase, $this ); |
|
| 1192 | + return (bool) apply_filters('wpinv_can_purchase_item', $can_purchase, $this); |
|
| 1193 | 1193 | } |
| 1194 | 1194 | |
| 1195 | 1195 | /** |
@@ -1199,6 +1199,6 @@ discard block |
||
| 1199 | 1199 | * @return bool |
| 1200 | 1200 | */ |
| 1201 | 1201 | public function supports_dynamic_pricing() { |
| 1202 | - return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this ); |
|
| 1202 | + return (bool) apply_filters('wpinv_item_supports_dynamic_pricing', true, $this); |
|
| 1203 | 1203 | } |
| 1204 | 1204 | } |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | * Personal data exporters. |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | -defined( 'ABSPATH' ) || exit; |
|
| 6 | +defined('ABSPATH') || exit; |
|
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | 9 | * WPInv_Privacy_Exporters Class. |
@@ -17,38 +17,38 @@ discard block |
||
| 17 | 17 | * @param int $page Page. |
| 18 | 18 | * @return array An array of invoice data in name value pairs |
| 19 | 19 | */ |
| 20 | - public static function customer_invoice_data_exporter( $email_address, $page ) { |
|
| 20 | + public static function customer_invoice_data_exporter($email_address, $page) { |
|
| 21 | 21 | $done = false; |
| 22 | 22 | $page = (int) $page; |
| 23 | 23 | $data_to_export = array(); |
| 24 | 24 | |
| 25 | - $user = get_user_by( 'email', $email_address ); |
|
| 26 | - if ( ! $user instanceof WP_User ) { |
|
| 25 | + $user = get_user_by('email', $email_address); |
|
| 26 | + if (!$user instanceof WP_User) { |
|
| 27 | 27 | return array( |
| 28 | 28 | 'data' => $data_to_export, |
| 29 | 29 | 'done' => true, |
| 30 | 30 | ); |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - $args = array( |
|
| 33 | + $args = array( |
|
| 34 | 34 | 'limit' => 30, |
| 35 | 35 | 'page' => $page, |
| 36 | 36 | 'user' => $user->ID, |
| 37 | 37 | ); |
| 38 | 38 | |
| 39 | - $invoices = wpinv_get_invoices( $args ); |
|
| 39 | + $invoices = wpinv_get_invoices($args); |
|
| 40 | 40 | |
| 41 | - if ( 0 < count( $invoices ) ) { |
|
| 42 | - foreach ( $invoices as $invoice ) { |
|
| 41 | + if (0 < count($invoices)) { |
|
| 42 | + foreach ($invoices as $invoice) { |
|
| 43 | 43 | $data_to_export[] = array( |
| 44 | 44 | 'group_id' => 'customer_invoices', |
| 45 | - 'group_label' => __( 'Invoicing Data', 'invoicing' ), |
|
| 46 | - 'group_description' => __( 'Customer invoicing data.', 'invoicing' ), |
|
| 45 | + 'group_label' => __('Invoicing Data', 'invoicing'), |
|
| 46 | + 'group_description' => __('Customer invoicing data.', 'invoicing'), |
|
| 47 | 47 | 'item_id' => "wpinv-{$invoice->ID}", |
| 48 | - 'data' => self::get_customer_invoice_data( $invoice ), |
|
| 48 | + 'data' => self::get_customer_invoice_data($invoice), |
|
| 49 | 49 | ); |
| 50 | 50 | } |
| 51 | - $done = 30 > count( $invoices ); |
|
| 51 | + $done = 30 > count($invoices); |
|
| 52 | 52 | } else { |
| 53 | 53 | $done = true; |
| 54 | 54 | } |
@@ -66,59 +66,59 @@ discard block |
||
| 66 | 66 | * @param WPInv_Invoice $invoice invoice object. |
| 67 | 67 | * @return array |
| 68 | 68 | */ |
| 69 | - public static function get_customer_invoice_data( $invoice ) { |
|
| 69 | + public static function get_customer_invoice_data($invoice) { |
|
| 70 | 70 | $personal_data = array(); |
| 71 | 71 | |
| 72 | 72 | $props_to_export = array( |
| 73 | - 'number' => __( 'Invoice Number', 'invoicing' ), |
|
| 74 | - 'created_date' => __( 'Invoice Date', 'invoicing' ), |
|
| 75 | - 'status' => __( 'Invoice Status', 'invoicing' ), |
|
| 76 | - 'total' => __( 'Invoice Total', 'invoicing' ), |
|
| 77 | - 'items' => __( 'Invoice Items', 'invoicing' ), |
|
| 78 | - 'first_name' => __( 'First Name', 'invoicing' ), |
|
| 79 | - 'last_name' => __( 'Last Name', 'invoicing' ), |
|
| 80 | - 'email' => __( 'Email Address', 'invoicing' ), |
|
| 81 | - '_wpinv_company' => __( 'Company', 'invoicing' ), |
|
| 82 | - 'phone' => __( 'Phone Number', 'invoicing' ), |
|
| 83 | - 'address' => __( 'Address', 'invoicing' ), |
|
| 84 | - '_wpinv_city' => __( 'City', 'invoicing' ), |
|
| 85 | - '_wpinv_country' => __( 'Country', 'invoicing' ), |
|
| 86 | - '_wpinv_state' => __( 'State', 'invoicing' ), |
|
| 87 | - '_wpinv_zip' => __( 'Zip Code', 'invoicing' ), |
|
| 73 | + 'number' => __('Invoice Number', 'invoicing'), |
|
| 74 | + 'created_date' => __('Invoice Date', 'invoicing'), |
|
| 75 | + 'status' => __('Invoice Status', 'invoicing'), |
|
| 76 | + 'total' => __('Invoice Total', 'invoicing'), |
|
| 77 | + 'items' => __('Invoice Items', 'invoicing'), |
|
| 78 | + 'first_name' => __('First Name', 'invoicing'), |
|
| 79 | + 'last_name' => __('Last Name', 'invoicing'), |
|
| 80 | + 'email' => __('Email Address', 'invoicing'), |
|
| 81 | + '_wpinv_company' => __('Company', 'invoicing'), |
|
| 82 | + 'phone' => __('Phone Number', 'invoicing'), |
|
| 83 | + 'address' => __('Address', 'invoicing'), |
|
| 84 | + '_wpinv_city' => __('City', 'invoicing'), |
|
| 85 | + '_wpinv_country' => __('Country', 'invoicing'), |
|
| 86 | + '_wpinv_state' => __('State', 'invoicing'), |
|
| 87 | + '_wpinv_zip' => __('Zip Code', 'invoicing'), |
|
| 88 | 88 | ); |
| 89 | 89 | |
| 90 | - $subscription = wpinv_get_subscription( $invoice ); |
|
| 90 | + $subscription = wpinv_get_subscription($invoice); |
|
| 91 | 91 | $period = $initial_amt = $bill_times = $billed = $renewal_date = ''; |
| 92 | 92 | |
| 93 | - if ( $invoice->is_recurring() && !empty( $subscription ) ) { |
|
| 94 | - $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $subscription->period,$subscription->frequency ); |
|
| 95 | - $period = wpinv_price( wpinv_format_amount( $subscription->recurring_amount ), wpinv_get_invoice_currency_code( $subscription->parent_payment_id ) ) . ' / ' . $frequency; |
|
| 96 | - $initial_amt = wpinv_price( wpinv_format_amount( $subscription->initial_amount ), wpinv_get_invoice_currency_code( $subscription->parent_payment_id ) ); |
|
| 97 | - $bill_times = $subscription->get_times_billed() . ' / ' . ( ( $subscription->bill_times == 0 ) ? __( 'Until Cancelled', 'invoicing' ) : $subscription->bill_times ); |
|
| 98 | - $renewal_date = ! empty( $subscription->expiration ) ? date_i18n( get_option( 'date_format' ), strtotime( $subscription->expiration ) ) : __( 'N/A', 'invoicing' ); |
|
| 99 | - |
|
| 100 | - $props_to_export['period'] = __( 'Billing Cycle', 'invoicing' ); |
|
| 101 | - $props_to_export['initial_amount'] = __( 'Initial Amount', 'invoicing' ); |
|
| 102 | - $props_to_export['bill_times'] = __( 'Times Billed', 'invoicing' ); |
|
| 103 | - $props_to_export['renewal_date'] = __( 'Renewal Date', 'invoicing' ); |
|
| 93 | + if ($invoice->is_recurring() && !empty($subscription)) { |
|
| 94 | + $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($subscription->period, $subscription->frequency); |
|
| 95 | + $period = wpinv_price(wpinv_format_amount($subscription->recurring_amount), wpinv_get_invoice_currency_code($subscription->parent_payment_id)) . ' / ' . $frequency; |
|
| 96 | + $initial_amt = wpinv_price(wpinv_format_amount($subscription->initial_amount), wpinv_get_invoice_currency_code($subscription->parent_payment_id)); |
|
| 97 | + $bill_times = $subscription->get_times_billed() . ' / ' . (($subscription->bill_times == 0) ? __('Until Cancelled', 'invoicing') : $subscription->bill_times); |
|
| 98 | + $renewal_date = !empty($subscription->expiration) ? date_i18n(get_option('date_format'), strtotime($subscription->expiration)) : __('N/A', 'invoicing'); |
|
| 99 | + |
|
| 100 | + $props_to_export['period'] = __('Billing Cycle', 'invoicing'); |
|
| 101 | + $props_to_export['initial_amount'] = __('Initial Amount', 'invoicing'); |
|
| 102 | + $props_to_export['bill_times'] = __('Times Billed', 'invoicing'); |
|
| 103 | + $props_to_export['renewal_date'] = __('Renewal Date', 'invoicing'); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - $props_to_export['ip'] = __( 'IP Address', 'invoicing' ); |
|
| 107 | - $props_to_export['view_url'] = __( 'Invoice Link', 'invoicing' ); |
|
| 106 | + $props_to_export['ip'] = __('IP Address', 'invoicing'); |
|
| 107 | + $props_to_export['view_url'] = __('Invoice Link', 'invoicing'); |
|
| 108 | 108 | |
| 109 | - $props_to_export = apply_filters( 'wpinv_privacy_export_invoice_personal_data_props', $props_to_export, $invoice, $subscription); |
|
| 109 | + $props_to_export = apply_filters('wpinv_privacy_export_invoice_personal_data_props', $props_to_export, $invoice, $subscription); |
|
| 110 | 110 | |
| 111 | - foreach ( $props_to_export as $prop => $name ) { |
|
| 111 | + foreach ($props_to_export as $prop => $name) { |
|
| 112 | 112 | $value = ''; |
| 113 | 113 | |
| 114 | - switch ( $prop ) { |
|
| 114 | + switch ($prop) { |
|
| 115 | 115 | case 'items': |
| 116 | 116 | $item_names = array(); |
| 117 | - foreach ( $invoice->get_cart_details() as $key => $cart_item ) { |
|
| 118 | - $item_quantity = $cart_item['quantity'] > 0 ? absint( $cart_item['quantity'] ) : 1; |
|
| 117 | + foreach ($invoice->get_cart_details() as $key => $cart_item) { |
|
| 118 | + $item_quantity = $cart_item['quantity'] > 0 ? absint($cart_item['quantity']) : 1; |
|
| 119 | 119 | $item_names[] = $cart_item['name'] . ' x ' . $item_quantity; |
| 120 | 120 | } |
| 121 | - $value = implode( ', ', $item_names ); |
|
| 121 | + $value = implode(', ', $item_names); |
|
| 122 | 122 | break; |
| 123 | 123 | case 'status': |
| 124 | 124 | $value = $invoice->get_status(true); |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | $value = $renewal_date; |
| 140 | 140 | break; |
| 141 | 141 | default: |
| 142 | - if ( is_callable( array( $invoice, 'get_' . $prop ) ) ) { |
|
| 142 | + if (is_callable(array($invoice, 'get_' . $prop))) { |
|
| 143 | 143 | $value = $invoice->{"get_$prop"}(); |
| 144 | 144 | } else { |
| 145 | 145 | $value = $invoice->get_meta($prop); |
@@ -147,9 +147,9 @@ discard block |
||
| 147 | 147 | break; |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - $value = apply_filters( 'wpi_privacy_export_invoice_personal_data_prop', $value, $prop, $invoice ); |
|
| 150 | + $value = apply_filters('wpi_privacy_export_invoice_personal_data_prop', $value, $prop, $invoice); |
|
| 151 | 151 | |
| 152 | - if ( $value ) { |
|
| 152 | + if ($value) { |
|
| 153 | 153 | $personal_data[] = array( |
| 154 | 154 | 'name' => $name, |
| 155 | 155 | 'value' => $value, |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - $personal_data = apply_filters( 'wpinv_privacy_export_invoice_personal_data', $personal_data, $invoice ); |
|
| 161 | + $personal_data = apply_filters('wpinv_privacy_export_invoice_personal_data', $personal_data, $invoice); |
|
| 162 | 162 | |
| 163 | 163 | return $personal_data; |
| 164 | 164 | |