@@ -7,64 +7,64 @@ discard block |
||
| 7 | 7 | * @version 1.0.19 |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -defined( 'ABSPATH' ) || exit; |
|
| 10 | +defined('ABSPATH') || exit; |
|
| 11 | 11 | |
| 12 | 12 | // Fetch the invoice. |
| 13 | -$invoice = new WPInv_Invoice( $invoice ); |
|
| 13 | +$invoice = new WPInv_Invoice($invoice); |
|
| 14 | 14 | |
| 15 | 15 | // @deprecated |
| 16 | -do_action( 'wpinv_success_content_before', $invoice ); |
|
| 17 | -do_action( 'wpinv_before_receipt', $invoice ); |
|
| 16 | +do_action('wpinv_success_content_before', $invoice); |
|
| 17 | +do_action('wpinv_before_receipt', $invoice); |
|
| 18 | 18 | |
| 19 | 19 | wpinv_print_errors(); |
| 20 | 20 | |
| 21 | 21 | // Prepare header text. |
| 22 | -if ( $invoice->is_paid() ) { |
|
| 22 | +if ($invoice->is_paid()) { |
|
| 23 | 23 | |
| 24 | 24 | $alert = aui()->alert( |
| 25 | 25 | array( |
| 26 | 26 | 'type' => 'success', |
| 27 | - 'content' => __( 'Thank you for your payment!', 'invoicing' ), |
|
| 27 | + 'content' => __('Thank you for your payment!', 'invoicing'), |
|
| 28 | 28 | ) |
| 29 | 29 | ); |
| 30 | 30 | |
| 31 | -} else if ( $invoice->is_refunded() ) { |
|
| 31 | +} else if ($invoice->is_refunded()) { |
|
| 32 | 32 | |
| 33 | 33 | $alert = aui()->alert( |
| 34 | 34 | array( |
| 35 | 35 | 'type' => 'info', |
| 36 | - 'content' => __( 'This invoice was refunded.', 'invoicing' ), |
|
| 36 | + 'content' => __('This invoice was refunded.', 'invoicing'), |
|
| 37 | 37 | ) |
| 38 | 38 | ); |
| 39 | 39 | |
| 40 | -} else if ( $invoice->is_held() ) { |
|
| 40 | +} else if ($invoice->is_held()) { |
|
| 41 | 41 | |
| 42 | 42 | $alert = aui()->alert( |
| 43 | 43 | array( |
| 44 | 44 | 'type' => 'info', |
| 45 | - 'content' => __( 'This invoice will be processed as soon we verify your payment.', 'invoicing' ), |
|
| 45 | + 'content' => __('This invoice will be processed as soon we verify your payment.', 'invoicing'), |
|
| 46 | 46 | ) |
| 47 | 47 | ); |
| 48 | 48 | |
| 49 | -} else if ( $invoice->needs_payment() ) { |
|
| 49 | +} else if ($invoice->needs_payment()) { |
|
| 50 | 50 | |
| 51 | - if ( ! empty( $_GET['token'] ) ) { |
|
| 51 | + if (!empty($_GET['token'])) { |
|
| 52 | 52 | |
| 53 | 53 | $alert = aui()->alert( |
| 54 | 54 | array( |
| 55 | 55 | 'type' => 'info', |
| 56 | - 'content' => __( "Sometimes it takes a few minutes for us to verify your payment. We'll notify you as soon as we've verified the payment.", 'invoicing' ), |
|
| 56 | + 'content' => __("Sometimes it takes a few minutes for us to verify your payment. We'll notify you as soon as we've verified the payment.", 'invoicing'), |
|
| 57 | 57 | ) |
| 58 | 58 | ); |
| 59 | 59 | |
| 60 | - } else if ( $invoice->is_due() ) { |
|
| 60 | + } else if ($invoice->is_due()) { |
|
| 61 | 61 | |
| 62 | 62 | $alert = aui()->alert( |
| 63 | 63 | array( |
| 64 | 64 | 'type' => 'danger', |
| 65 | 65 | 'content' => sprintf( |
| 66 | - __( 'This invoice was due on %.', 'invoicing' ), |
|
| 67 | - getpaid_format_date_value( $invoice->get_due_date() ) |
|
| 66 | + __('This invoice was due on %.', 'invoicing'), |
|
| 67 | + getpaid_format_date_value($invoice->get_due_date()) |
|
| 68 | 68 | ), |
| 69 | 69 | ) |
| 70 | 70 | ); |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | $alert = aui()->alert( |
| 75 | 75 | array( |
| 76 | 76 | 'type' => 'warning', |
| 77 | - 'content' => __( 'This invoice needs payment.', 'invoicing' ), |
|
| 77 | + 'content' => __('This invoice needs payment.', 'invoicing'), |
|
| 78 | 78 | ) |
| 79 | 79 | ); |
| 80 | 80 | |
@@ -89,19 +89,19 @@ discard block |
||
| 89 | 89 | |
| 90 | 90 | 'pay' => array( |
| 91 | 91 | 'url' => $invoice->get_checkout_payment_url(), |
| 92 | - 'name' => __( 'Pay For Invoice', 'invoicing' ), |
|
| 92 | + 'name' => __('Pay For Invoice', 'invoicing'), |
|
| 93 | 93 | 'class' => 'btn-success', |
| 94 | 94 | ), |
| 95 | 95 | |
| 96 | 96 | 'view' => array( |
| 97 | 97 | 'url' => $invoice->get_view_url(), |
| 98 | - 'name' => __( 'View Invoice', 'invoicing' ), |
|
| 98 | + 'name' => __('View Invoice', 'invoicing'), |
|
| 99 | 99 | 'class' => 'btn-primary', |
| 100 | 100 | ), |
| 101 | 101 | |
| 102 | 102 | 'history' => array( |
| 103 | 103 | 'url' => wpinv_get_history_page_uri(), |
| 104 | - 'name' => __( 'Invoice History', 'invoicing' ), |
|
| 104 | + 'name' => __('Invoice History', 'invoicing'), |
|
| 105 | 105 | 'class' => 'btn-warning', |
| 106 | 106 | ), |
| 107 | 107 | |
@@ -110,12 +110,12 @@ discard block |
||
| 110 | 110 | |
| 111 | 111 | ); |
| 112 | 112 | |
| 113 | -if ( ( ! $invoice->needs_payment() || $invoice->is_held() ) && isset( $actions['pay'] ) ) { |
|
| 114 | - unset( $actions['pay'] ); |
|
| 113 | +if ((!$invoice->needs_payment() || $invoice->is_held()) && isset($actions['pay'])) { |
|
| 114 | + unset($actions['pay']); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | -if ( ! is_user_logged_in() && isset( $actions['history'] ) ) { |
|
| 118 | - unset( $actions['history'] ); |
|
| 117 | +if (!is_user_logged_in() && isset($actions['history'])) { |
|
| 118 | + unset($actions['history']); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | ?> |
@@ -124,19 +124,19 @@ discard block |
||
| 124 | 124 | |
| 125 | 125 | <?php |
| 126 | 126 | |
| 127 | - do_action( 'wpinv_receipt_start', $invoice ); |
|
| 127 | + do_action('wpinv_receipt_start', $invoice); |
|
| 128 | 128 | |
| 129 | - if ( ! empty( $actions ) ) { |
|
| 129 | + if (!empty($actions)) { |
|
| 130 | 130 | |
| 131 | 131 | echo '<div class="wpinv-receipt-actions text-right mt-1 mb-4">'; |
| 132 | 132 | |
| 133 | - foreach ( $actions as $key => $action ) { |
|
| 133 | + foreach ($actions as $key => $action) { |
|
| 134 | 134 | |
| 135 | - $key = sanitize_html_class( $key ); |
|
| 136 | - $class = empty( $action['class'] ) ? 'btn-dark' : sanitize_html_class( $action['class'] ); |
|
| 137 | - $url = empty( $action['url'] ) ? '#' : esc_url( $action['url'] ); |
|
| 138 | - $attrs = empty( $action['attrs'] ) ? '' : $action['attrs']; |
|
| 139 | - $anchor = sanitize_text_field( $action['name'] ); |
|
| 135 | + $key = sanitize_html_class($key); |
|
| 136 | + $class = empty($action['class']) ? 'btn-dark' : sanitize_html_class($action['class']); |
|
| 137 | + $url = empty($action['url']) ? '#' : esc_url($action['url']); |
|
| 138 | + $attrs = empty($action['attrs']) ? '' : $action['attrs']; |
|
| 139 | + $anchor = sanitize_text_field($action['name']); |
|
| 140 | 140 | |
| 141 | 141 | echo "<a href='$url' class='btn btn-sm ml-1 $class $key' $attrs>$anchor</a>"; |
| 142 | 142 | } |
@@ -152,21 +152,21 @@ discard block |
||
| 152 | 152 | <div class="wpinv-receipt-details"> |
| 153 | 153 | |
| 154 | 154 | <h4 class="wpinv-details-t mb-3 mt-3"> |
| 155 | - <?php echo apply_filters( 'wpinv_receipt_details_title', __( 'Invoice Details', 'invoicing' ), $invoice ); ?> |
|
| 155 | + <?php echo apply_filters('wpinv_receipt_details_title', __('Invoice Details', 'invoicing'), $invoice); ?> |
|
| 156 | 156 | </h4> |
| 157 | 157 | |
| 158 | - <?php getpaid_invoice_meta( $invoice ); ?> |
|
| 158 | + <?php getpaid_invoice_meta($invoice); ?> |
|
| 159 | 159 | |
| 160 | 160 | </div> |
| 161 | 161 | |
| 162 | - <?php echo getpaid_display_invoice_subscriptions( $invoice ); ?> |
|
| 162 | + <?php echo getpaid_display_invoice_subscriptions($invoice); ?> |
|
| 163 | 163 | |
| 164 | - <?php do_action( 'wpinv_receipt_end', $invoice ); ?> |
|
| 164 | + <?php do_action('wpinv_receipt_end', $invoice); ?> |
|
| 165 | 165 | |
| 166 | 166 | </div> |
| 167 | 167 | |
| 168 | 168 | <?php |
| 169 | 169 | |
| 170 | 170 | // @deprecated |
| 171 | -do_action( 'wpinv_success_content_after', $invoice ); |
|
| 172 | -do_action( 'wpinv_after_receipt', $invoice ); |
|
| 171 | +do_action('wpinv_success_content_after', $invoice); |
|
| 172 | +do_action('wpinv_after_receipt', $invoice); |
|
@@ -4,8 +4,8 @@ discard block |
||
| 4 | 4 | <?php |
| 5 | 5 | echo |
| 6 | 6 | wp_sprintf( |
| 7 | - __( 'Your payment is processing. This page will reload automatically in 10 seconds. If it does not, click <a href="%s">here</a>.', 'invoicing' ), |
|
| 8 | - esc_url_raw( remove_query_arg( 'payment-confirm' ) ) |
|
| 7 | + __('Your payment is processing. This page will reload automatically in 10 seconds. If it does not, click <a href="%s">here</a>.', 'invoicing'), |
|
| 8 | + esc_url_raw(remove_query_arg('payment-confirm')) |
|
| 9 | 9 | ); |
| 10 | 10 | ?> |
| 11 | 11 | <i class="fa fa-spin fa-refresh"></i> |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | <script type="text/javascript"> |
| 15 | 15 | setTimeout( |
| 16 | 16 | function(){ |
| 17 | - window.location.href = '<?php echo esc_url_raw( remove_query_arg( 'payment-confirm' ) ) ;?>'; |
|
| 17 | + window.location.href = '<?php echo esc_url_raw(remove_query_arg('payment-confirm')); ?>'; |
|
| 18 | 18 | }, |
| 19 | 19 | 10000 |
| 20 | 20 | ); |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | */ |
| 51 | 51 | function getpaid_get_invoice_subscription_group( $invoice_id, $subscription_id ) { |
| 52 | 52 | $subscription_groups = getpaid_get_invoice_subscription_groups( $invoice_id ); |
| 53 | - $matching_group = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) ); |
|
| 53 | + $matching_group = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) ); |
|
| 54 | 54 | return reset( $matching_group ); |
| 55 | 55 | } |
| 56 | 56 | |
@@ -62,8 +62,8 @@ discard block |
||
| 62 | 62 | * @return WPInv_Subscription|false |
| 63 | 63 | */ |
| 64 | 64 | function getpaid_get_subscription( $subscription ) { |
| 65 | - $subscription = new WPInv_Subscription( $subscription ); |
|
| 66 | - return $subscription->exists() ? $subscription : false; |
|
| 65 | + $subscription = new WPInv_Subscription( $subscription ); |
|
| 66 | + return $subscription->exists() ? $subscription : false; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -77,28 +77,28 @@ discard block |
||
| 77 | 77 | */ |
| 78 | 78 | function getpaid_get_subscriptions( $args = array(), $return = 'results' ) { |
| 79 | 79 | |
| 80 | - // Do not retrieve all fields if we just want the count. |
|
| 81 | - if ( 'count' == $return ) { |
|
| 82 | - $args['fields'] = 'id'; |
|
| 83 | - $args['number'] = 1; |
|
| 84 | - } |
|
| 80 | + // Do not retrieve all fields if we just want the count. |
|
| 81 | + if ( 'count' == $return ) { |
|
| 82 | + $args['fields'] = 'id'; |
|
| 83 | + $args['number'] = 1; |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - // Do not count all matches if we just want the results. |
|
| 87 | - if ( 'results' == $return ) { |
|
| 88 | - $args['count_total'] = false; |
|
| 89 | - } |
|
| 86 | + // Do not count all matches if we just want the results. |
|
| 87 | + if ( 'results' == $return ) { |
|
| 88 | + $args['count_total'] = false; |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - $query = new GetPaid_Subscriptions_Query( $args ); |
|
| 91 | + $query = new GetPaid_Subscriptions_Query( $args ); |
|
| 92 | 92 | |
| 93 | - if ( 'results' == $return ) { |
|
| 94 | - return $query->get_results(); |
|
| 95 | - } |
|
| 93 | + if ( 'results' == $return ) { |
|
| 94 | + return $query->get_results(); |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - if ( 'count' == $return ) { |
|
| 98 | - return $query->get_total(); |
|
| 99 | - } |
|
| 97 | + if ( 'count' == $return ) { |
|
| 98 | + return $query->get_total(); |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - return $query; |
|
| 101 | + return $query; |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | /** |
@@ -108,18 +108,18 @@ discard block |
||
| 108 | 108 | */ |
| 109 | 109 | function getpaid_get_subscription_statuses() { |
| 110 | 110 | |
| 111 | - return apply_filters( |
|
| 112 | - 'getpaid_get_subscription_statuses', |
|
| 113 | - array( |
|
| 114 | - 'pending' => __( 'Pending', 'invoicing' ), |
|
| 115 | - 'trialling' => __( 'Trialing', 'invoicing' ), |
|
| 116 | - 'active' => __( 'Active', 'invoicing' ), |
|
| 117 | - 'failing' => __( 'Failing', 'invoicing' ), |
|
| 118 | - 'expired' => __( 'Expired', 'invoicing' ), |
|
| 119 | - 'completed' => __( 'Complete', 'invoicing' ), |
|
| 120 | - 'cancelled' => __( 'Cancelled', 'invoicing' ), |
|
| 121 | - ) |
|
| 122 | - ); |
|
| 111 | + return apply_filters( |
|
| 112 | + 'getpaid_get_subscription_statuses', |
|
| 113 | + array( |
|
| 114 | + 'pending' => __( 'Pending', 'invoicing' ), |
|
| 115 | + 'trialling' => __( 'Trialing', 'invoicing' ), |
|
| 116 | + 'active' => __( 'Active', 'invoicing' ), |
|
| 117 | + 'failing' => __( 'Failing', 'invoicing' ), |
|
| 118 | + 'expired' => __( 'Expired', 'invoicing' ), |
|
| 119 | + 'completed' => __( 'Complete', 'invoicing' ), |
|
| 120 | + 'cancelled' => __( 'Cancelled', 'invoicing' ), |
|
| 121 | + ) |
|
| 122 | + ); |
|
| 123 | 123 | |
| 124 | 124 | } |
| 125 | 125 | |
@@ -129,8 +129,8 @@ discard block |
||
| 129 | 129 | * @return string |
| 130 | 130 | */ |
| 131 | 131 | function getpaid_get_subscription_status_label( $status ) { |
| 132 | - $statuses = getpaid_get_subscription_statuses(); |
|
| 133 | - return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) ); |
|
| 132 | + $statuses = getpaid_get_subscription_statuses(); |
|
| 133 | + return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) ); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
@@ -140,18 +140,18 @@ discard block |
||
| 140 | 140 | */ |
| 141 | 141 | function getpaid_get_subscription_status_classes() { |
| 142 | 142 | |
| 143 | - return apply_filters( |
|
| 144 | - 'getpaid_get_subscription_status_classes', |
|
| 145 | - array( |
|
| 146 | - 'pending' => 'badge-dark', |
|
| 147 | - 'trialling' => 'badge-info', |
|
| 148 | - 'active' => 'badge-success', |
|
| 149 | - 'failing' => 'badge-warning', |
|
| 150 | - 'expired' => 'badge-danger', |
|
| 151 | - 'completed' => 'badge-primary', |
|
| 152 | - 'cancelled' => 'badge-secondary', |
|
| 153 | - ) |
|
| 154 | - ); |
|
| 143 | + return apply_filters( |
|
| 144 | + 'getpaid_get_subscription_status_classes', |
|
| 145 | + array( |
|
| 146 | + 'pending' => 'badge-dark', |
|
| 147 | + 'trialling' => 'badge-info', |
|
| 148 | + 'active' => 'badge-success', |
|
| 149 | + 'failing' => 'badge-warning', |
|
| 150 | + 'expired' => 'badge-danger', |
|
| 151 | + 'completed' => 'badge-primary', |
|
| 152 | + 'cancelled' => 'badge-secondary', |
|
| 153 | + ) |
|
| 154 | + ); |
|
| 155 | 155 | |
| 156 | 156 | } |
| 157 | 157 | |
@@ -162,15 +162,15 @@ discard block |
||
| 162 | 162 | */ |
| 163 | 163 | function getpaid_get_subscription_status_counts( $args = array() ) { |
| 164 | 164 | |
| 165 | - $statuses = array_keys( getpaid_get_subscription_statuses() ); |
|
| 166 | - $counts = array(); |
|
| 165 | + $statuses = array_keys( getpaid_get_subscription_statuses() ); |
|
| 166 | + $counts = array(); |
|
| 167 | 167 | |
| 168 | - foreach ( $statuses as $status ) { |
|
| 169 | - $_args = wp_parse_args( "status=$status", $args ); |
|
| 170 | - $counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' ); |
|
| 171 | - } |
|
| 168 | + foreach ( $statuses as $status ) { |
|
| 169 | + $_args = wp_parse_args( "status=$status", $args ); |
|
| 170 | + $counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' ); |
|
| 171 | + } |
|
| 172 | 172 | |
| 173 | - return $counts; |
|
| 173 | + return $counts; |
|
| 174 | 174 | |
| 175 | 175 | } |
| 176 | 176 | |
@@ -181,32 +181,32 @@ discard block |
||
| 181 | 181 | */ |
| 182 | 182 | function getpaid_get_subscription_periods() { |
| 183 | 183 | |
| 184 | - return apply_filters( |
|
| 185 | - 'getpaid_get_subscription_periods', |
|
| 186 | - array( |
|
| 184 | + return apply_filters( |
|
| 185 | + 'getpaid_get_subscription_periods', |
|
| 186 | + array( |
|
| 187 | 187 | |
| 188 | - 'day' => array( |
|
| 189 | - 'singular' => __( '%s day', 'invoicing' ), |
|
| 190 | - 'plural' => __( '%d days', 'invoicing' ), |
|
| 191 | - ), |
|
| 188 | + 'day' => array( |
|
| 189 | + 'singular' => __( '%s day', 'invoicing' ), |
|
| 190 | + 'plural' => __( '%d days', 'invoicing' ), |
|
| 191 | + ), |
|
| 192 | 192 | |
| 193 | - 'week' => array( |
|
| 194 | - 'singular' => __( '%s week', 'invoicing' ), |
|
| 195 | - 'plural' => __( '%d weeks', 'invoicing' ), |
|
| 196 | - ), |
|
| 193 | + 'week' => array( |
|
| 194 | + 'singular' => __( '%s week', 'invoicing' ), |
|
| 195 | + 'plural' => __( '%d weeks', 'invoicing' ), |
|
| 196 | + ), |
|
| 197 | 197 | |
| 198 | - 'month' => array( |
|
| 199 | - 'singular' => __( '%s month', 'invoicing' ), |
|
| 200 | - 'plural' => __( '%d months', 'invoicing' ), |
|
| 201 | - ), |
|
| 198 | + 'month' => array( |
|
| 199 | + 'singular' => __( '%s month', 'invoicing' ), |
|
| 200 | + 'plural' => __( '%d months', 'invoicing' ), |
|
| 201 | + ), |
|
| 202 | 202 | |
| 203 | - 'year' => array( |
|
| 204 | - 'singular' => __( '%s year', 'invoicing' ), |
|
| 205 | - 'plural' => __( '%d years', 'invoicing' ), |
|
| 206 | - ), |
|
| 203 | + 'year' => array( |
|
| 204 | + 'singular' => __( '%s year', 'invoicing' ), |
|
| 205 | + 'plural' => __( '%d years', 'invoicing' ), |
|
| 206 | + ), |
|
| 207 | 207 | |
| 208 | - ) |
|
| 209 | - ); |
|
| 208 | + ) |
|
| 209 | + ); |
|
| 210 | 210 | |
| 211 | 211 | } |
| 212 | 212 | |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | * @return int |
| 218 | 218 | */ |
| 219 | 219 | function getpaid_get_subscription_trial_period_interval( $trial_period ) { |
| 220 | - return (int) preg_replace( '/[^0-9]/', '', $trial_period ); |
|
| 220 | + return (int) preg_replace( '/[^0-9]/', '', $trial_period ); |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | /** |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | * @return string |
| 228 | 228 | */ |
| 229 | 229 | function getpaid_get_subscription_trial_period_period( $trial_period ) { |
| 230 | - return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) ); |
|
| 230 | + return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) ); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | /** |
@@ -238,8 +238,8 @@ discard block |
||
| 238 | 238 | * @return string |
| 239 | 239 | */ |
| 240 | 240 | function getpaid_get_subscription_period_label( $period, $interval = 1, $singular_prefix = '1' ) { |
| 241 | - $label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label( $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix ); |
|
| 242 | - return strtolower( sanitize_text_field( $label ) ); |
|
| 241 | + $label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label( $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix ); |
|
| 242 | + return strtolower( sanitize_text_field( $label ) ); |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | /** |
@@ -250,22 +250,22 @@ discard block |
||
| 250 | 250 | */ |
| 251 | 251 | function getpaid_get_singular_subscription_period_label( $period, $singular_prefix = '1' ) { |
| 252 | 252 | |
| 253 | - $periods = getpaid_get_subscription_periods(); |
|
| 254 | - $period = strtolower( $period ); |
|
| 253 | + $periods = getpaid_get_subscription_periods(); |
|
| 254 | + $period = strtolower( $period ); |
|
| 255 | 255 | |
| 256 | - if ( isset( $periods[ $period ] ) ) { |
|
| 257 | - return sprintf( $periods[ $period ]['singular'], $singular_prefix ); |
|
| 258 | - } |
|
| 256 | + if ( isset( $periods[ $period ] ) ) { |
|
| 257 | + return sprintf( $periods[ $period ]['singular'], $singular_prefix ); |
|
| 258 | + } |
|
| 259 | 259 | |
| 260 | - // Backwards compatibility. |
|
| 261 | - foreach ( $periods as $key => $data ) { |
|
| 262 | - if ( strpos( $key, $period ) === 0 ) { |
|
| 263 | - return sprintf( $data['singular'], $singular_prefix ); |
|
| 264 | - } |
|
| 265 | - } |
|
| 260 | + // Backwards compatibility. |
|
| 261 | + foreach ( $periods as $key => $data ) { |
|
| 262 | + if ( strpos( $key, $period ) === 0 ) { |
|
| 263 | + return sprintf( $data['singular'], $singular_prefix ); |
|
| 264 | + } |
|
| 265 | + } |
|
| 266 | 266 | |
| 267 | - // Invalid string. |
|
| 268 | - return ''; |
|
| 267 | + // Invalid string. |
|
| 268 | + return ''; |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | /** |
@@ -277,22 +277,22 @@ discard block |
||
| 277 | 277 | */ |
| 278 | 278 | function getpaid_get_plural_subscription_period_label( $period, $interval ) { |
| 279 | 279 | |
| 280 | - $periods = getpaid_get_subscription_periods(); |
|
| 281 | - $period = strtolower( $period ); |
|
| 280 | + $periods = getpaid_get_subscription_periods(); |
|
| 281 | + $period = strtolower( $period ); |
|
| 282 | 282 | |
| 283 | - if ( isset( $periods[ $period ] ) ) { |
|
| 284 | - return sprintf( $periods[ $period ]['plural'], $interval ); |
|
| 285 | - } |
|
| 283 | + if ( isset( $periods[ $period ] ) ) { |
|
| 284 | + return sprintf( $periods[ $period ]['plural'], $interval ); |
|
| 285 | + } |
|
| 286 | 286 | |
| 287 | - // Backwards compatibility. |
|
| 288 | - foreach ( $periods as $key => $data ) { |
|
| 289 | - if ( strpos( $key, $period ) === 0 ) { |
|
| 290 | - return sprintf( $data['plural'], $interval ); |
|
| 291 | - } |
|
| 292 | - } |
|
| 287 | + // Backwards compatibility. |
|
| 288 | + foreach ( $periods as $key => $data ) { |
|
| 289 | + if ( strpos( $key, $period ) === 0 ) { |
|
| 290 | + return sprintf( $data['plural'], $interval ); |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | 293 | |
| 294 | - // Invalid string. |
|
| 295 | - return ''; |
|
| 294 | + // Invalid string. |
|
| 295 | + return ''; |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | 298 | /** |
@@ -303,101 +303,101 @@ discard block |
||
| 303 | 303 | */ |
| 304 | 304 | function getpaid_get_formatted_subscription_amount( $subscription ) { |
| 305 | 305 | |
| 306 | - $initial = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
| 307 | - $recurring = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
| 308 | - $period = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
| 309 | - $bill_times = $subscription->get_bill_times(); |
|
| 306 | + $initial = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
| 307 | + $recurring = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
| 308 | + $period = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
| 309 | + $bill_times = $subscription->get_bill_times(); |
|
| 310 | 310 | |
| 311 | - if ( ! empty( $bill_times ) ) { |
|
| 312 | - $bill_times = $subscription->get_frequency() * $bill_times; |
|
| 313 | - $bill_times = getpaid_get_subscription_period_label( $subscription->get_period(), $bill_times ); |
|
| 314 | - } |
|
| 311 | + if ( ! empty( $bill_times ) ) { |
|
| 312 | + $bill_times = $subscription->get_frequency() * $bill_times; |
|
| 313 | + $bill_times = getpaid_get_subscription_period_label( $subscription->get_period(), $bill_times ); |
|
| 314 | + } |
|
| 315 | 315 | |
| 316 | - // Trial periods. |
|
| 317 | - if ( $subscription->has_trial_period() ) { |
|
| 316 | + // Trial periods. |
|
| 317 | + if ( $subscription->has_trial_period() ) { |
|
| 318 | 318 | |
| 319 | - $trial_period = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() ); |
|
| 320 | - $trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() ); |
|
| 319 | + $trial_period = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() ); |
|
| 320 | + $trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() ); |
|
| 321 | 321 | |
| 322 | - if ( empty( $bill_times ) ) { |
|
| 322 | + if ( empty( $bill_times ) ) { |
|
| 323 | 323 | |
| 324 | - return sprintf( |
|
| 324 | + return sprintf( |
|
| 325 | 325 | |
| 326 | - // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period |
|
| 327 | - _x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ), |
|
| 328 | - $initial, |
|
| 329 | - getpaid_get_subscription_period_label( $trial_period, $trial_interval ), |
|
| 330 | - $recurring, |
|
| 331 | - $period |
|
| 326 | + // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period |
|
| 327 | + _x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ), |
|
| 328 | + $initial, |
|
| 329 | + getpaid_get_subscription_period_label( $trial_period, $trial_interval ), |
|
| 330 | + $recurring, |
|
| 331 | + $period |
|
| 332 | 332 | |
| 333 | - ); |
|
| 333 | + ); |
|
| 334 | 334 | |
| 335 | - } |
|
| 335 | + } |
|
| 336 | 336 | |
| 337 | - return sprintf( |
|
| 337 | + return sprintf( |
|
| 338 | 338 | |
| 339 | - // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period, $5: is the bill times |
|
| 340 | - _x( '%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing' ), |
|
| 341 | - $initial, |
|
| 342 | - getpaid_get_subscription_period_label( $trial_period, $trial_interval ), |
|
| 343 | - $recurring, |
|
| 344 | - $period, |
|
| 345 | - $bill_times |
|
| 346 | - ); |
|
| 339 | + // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period, $5: is the bill times |
|
| 340 | + _x( '%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing' ), |
|
| 341 | + $initial, |
|
| 342 | + getpaid_get_subscription_period_label( $trial_period, $trial_interval ), |
|
| 343 | + $recurring, |
|
| 344 | + $period, |
|
| 345 | + $bill_times |
|
| 346 | + ); |
|
| 347 | 347 | |
| 348 | - } |
|
| 348 | + } |
|
| 349 | 349 | |
| 350 | - if ( $initial != $recurring ) { |
|
| 350 | + if ( $initial != $recurring ) { |
|
| 351 | 351 | |
| 352 | - if ( empty( $bill_times ) ) { |
|
| 352 | + if ( empty( $bill_times ) ) { |
|
| 353 | 353 | |
| 354 | - return sprintf( |
|
| 354 | + return sprintf( |
|
| 355 | 355 | |
| 356 | - // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period |
|
| 357 | - _x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ), |
|
| 358 | - $initial, |
|
| 359 | - $recurring, |
|
| 360 | - $period |
|
| 356 | + // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period |
|
| 357 | + _x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ), |
|
| 358 | + $initial, |
|
| 359 | + $recurring, |
|
| 360 | + $period |
|
| 361 | 361 | |
| 362 | - ); |
|
| 362 | + ); |
|
| 363 | 363 | |
| 364 | - } |
|
| 364 | + } |
|
| 365 | 365 | |
| 366 | - return sprintf( |
|
| 366 | + return sprintf( |
|
| 367 | 367 | |
| 368 | - // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period, $4: is the bill times |
|
| 369 | - _x( 'Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing' ), |
|
| 370 | - $initial, |
|
| 371 | - $recurring, |
|
| 372 | - $period, |
|
| 373 | - $bill_times |
|
| 368 | + // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period, $4: is the bill times |
|
| 369 | + _x( 'Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing' ), |
|
| 370 | + $initial, |
|
| 371 | + $recurring, |
|
| 372 | + $period, |
|
| 373 | + $bill_times |
|
| 374 | 374 | |
| 375 | - ); |
|
| 375 | + ); |
|
| 376 | 376 | |
| 377 | - } |
|
| 377 | + } |
|
| 378 | 378 | |
| 379 | - if ( empty( $bill_times ) ) { |
|
| 379 | + if ( empty( $bill_times ) ) { |
|
| 380 | 380 | |
| 381 | - return sprintf( |
|
| 381 | + return sprintf( |
|
| 382 | 382 | |
| 383 | - // translators: $1: is the recurring amount, $2: is the recurring period |
|
| 384 | - _x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ), |
|
| 385 | - $initial, |
|
| 386 | - $period |
|
| 383 | + // translators: $1: is the recurring amount, $2: is the recurring period |
|
| 384 | + _x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ), |
|
| 385 | + $initial, |
|
| 386 | + $period |
|
| 387 | 387 | |
| 388 | - ); |
|
| 388 | + ); |
|
| 389 | 389 | |
| 390 | - } |
|
| 390 | + } |
|
| 391 | 391 | |
| 392 | - return sprintf( |
|
| 392 | + return sprintf( |
|
| 393 | 393 | |
| 394 | - // translators: $1: is the bill times, $2: is the recurring amount, $3: is the recurring period |
|
| 395 | - _x( '%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ), |
|
| 396 | - $bill_times, |
|
| 397 | - $initial, |
|
| 398 | - $period |
|
| 394 | + // translators: $1: is the bill times, $2: is the recurring amount, $3: is the recurring period |
|
| 395 | + _x( '%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ), |
|
| 396 | + $bill_times, |
|
| 397 | + $initial, |
|
| 398 | + $period |
|
| 399 | 399 | |
| 400 | - ); |
|
| 400 | + ); |
|
| 401 | 401 | |
| 402 | 402 | } |
| 403 | 403 | |
@@ -408,7 +408,7 @@ discard block |
||
| 408 | 408 | * @return WPInv_Subscription|false |
| 409 | 409 | */ |
| 410 | 410 | function getpaid_get_invoice_subscription( $invoice ) { |
| 411 | - return getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 411 | + return getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | /** |
@@ -417,10 +417,10 @@ discard block |
||
| 417 | 417 | * @param WPInv_Invoice $invoice |
| 418 | 418 | */ |
| 419 | 419 | function getpaid_activate_invoice_subscription( $invoice ) { |
| 420 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
| 421 | - if ( is_a( $subscription, 'WPInv_Subscription' ) ) { |
|
| 422 | - $subscription->activate(); |
|
| 423 | - } |
|
| 420 | + $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
| 421 | + if ( is_a( $subscription, 'WPInv_Subscription' ) ) { |
|
| 422 | + $subscription->activate(); |
|
| 423 | + } |
|
| 424 | 424 | } |
| 425 | 425 | |
| 426 | 426 | /** |
@@ -429,7 +429,7 @@ discard block |
||
| 429 | 429 | * @return WPInv_Subscriptions |
| 430 | 430 | */ |
| 431 | 431 | function getpaid_subscriptions() { |
| 432 | - return getpaid()->get( 'subscriptions' ); |
|
| 432 | + return getpaid()->get( 'subscriptions' ); |
|
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | /** |
@@ -448,15 +448,15 @@ discard block |
||
| 448 | 448 | return false; |
| 449 | 449 | } |
| 450 | 450 | |
| 451 | - // Fetch the invoice subscription. |
|
| 452 | - $subscription = getpaid_get_subscriptions( |
|
| 453 | - array( |
|
| 454 | - 'invoice_in' => $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id(), |
|
| 455 | - 'number' => 1, |
|
| 456 | - ) |
|
| 457 | - ); |
|
| 451 | + // Fetch the invoice subscription. |
|
| 452 | + $subscription = getpaid_get_subscriptions( |
|
| 453 | + array( |
|
| 454 | + 'invoice_in' => $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id(), |
|
| 455 | + 'number' => 1, |
|
| 456 | + ) |
|
| 457 | + ); |
|
| 458 | 458 | |
| 459 | - return empty( $subscription ) ? false : $subscription[0]; |
|
| 459 | + return empty( $subscription ) ? false : $subscription[0]; |
|
| 460 | 460 | |
| 461 | 461 | } |
| 462 | 462 | |
@@ -473,48 +473,48 @@ discard block |
||
| 473 | 473 | */ |
| 474 | 474 | function getpaid_get_recurring_item_key( $cart_item ) { |
| 475 | 475 | |
| 476 | - $cart_key = 'renews_'; |
|
| 477 | - $interval = $cart_item->get_recurring_interval(); |
|
| 478 | - $period = $cart_item->get_recurring_period( true ); |
|
| 479 | - $length = $cart_item->get_recurring_limit() * $interval; |
|
| 480 | - $trial_period = $cart_item->get_trial_period( true ); |
|
| 481 | - $trial_length = $cart_item->get_trial_interval(); |
|
| 482 | - |
|
| 483 | - // First start with the billing interval and period |
|
| 484 | - switch ( $interval ) { |
|
| 485 | - case 1 : |
|
| 486 | - if ( 'day' == $period ) { |
|
| 487 | - $cart_key .= 'daily'; |
|
| 488 | - } else { |
|
| 489 | - $cart_key .= sprintf( '%sly', $period ); |
|
| 490 | - } |
|
| 491 | - break; |
|
| 492 | - case 2 : |
|
| 493 | - $cart_key .= sprintf( 'every_2nd_%s', $period ); |
|
| 494 | - break; |
|
| 495 | - case 3 : |
|
| 496 | - $cart_key .= sprintf( 'every_3rd_%s', $period ); |
|
| 497 | - break; |
|
| 498 | - default: |
|
| 499 | - $cart_key .= sprintf( 'every_%dth_%s', $interval, $period ); |
|
| 500 | - break; |
|
| 501 | - } |
|
| 502 | - |
|
| 503 | - // Maybe add the optional maximum billing periods... |
|
| 504 | - if ( $length > 0 ) { |
|
| 505 | - $cart_key .= '_for_'; |
|
| 506 | - $cart_key .= sprintf( '%d_%s', $length, $period ); |
|
| 507 | - if ( $length > 1 ) { |
|
| 508 | - $cart_key .= 's'; |
|
| 509 | - } |
|
| 510 | - } |
|
| 511 | - |
|
| 512 | - // And an optional free trial. |
|
| 513 | - if ( $cart_item->has_free_trial() ) { |
|
| 514 | - $cart_key .= sprintf( '_after_a_%d_%s_trial', $trial_length, $trial_period ); |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - return apply_filters( 'getpaid_get_recurring_item_key', $cart_key, $cart_item ); |
|
| 476 | + $cart_key = 'renews_'; |
|
| 477 | + $interval = $cart_item->get_recurring_interval(); |
|
| 478 | + $period = $cart_item->get_recurring_period( true ); |
|
| 479 | + $length = $cart_item->get_recurring_limit() * $interval; |
|
| 480 | + $trial_period = $cart_item->get_trial_period( true ); |
|
| 481 | + $trial_length = $cart_item->get_trial_interval(); |
|
| 482 | + |
|
| 483 | + // First start with the billing interval and period |
|
| 484 | + switch ( $interval ) { |
|
| 485 | + case 1 : |
|
| 486 | + if ( 'day' == $period ) { |
|
| 487 | + $cart_key .= 'daily'; |
|
| 488 | + } else { |
|
| 489 | + $cart_key .= sprintf( '%sly', $period ); |
|
| 490 | + } |
|
| 491 | + break; |
|
| 492 | + case 2 : |
|
| 493 | + $cart_key .= sprintf( 'every_2nd_%s', $period ); |
|
| 494 | + break; |
|
| 495 | + case 3 : |
|
| 496 | + $cart_key .= sprintf( 'every_3rd_%s', $period ); |
|
| 497 | + break; |
|
| 498 | + default: |
|
| 499 | + $cart_key .= sprintf( 'every_%dth_%s', $interval, $period ); |
|
| 500 | + break; |
|
| 501 | + } |
|
| 502 | + |
|
| 503 | + // Maybe add the optional maximum billing periods... |
|
| 504 | + if ( $length > 0 ) { |
|
| 505 | + $cart_key .= '_for_'; |
|
| 506 | + $cart_key .= sprintf( '%d_%s', $length, $period ); |
|
| 507 | + if ( $length > 1 ) { |
|
| 508 | + $cart_key .= 's'; |
|
| 509 | + } |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + // And an optional free trial. |
|
| 513 | + if ( $cart_item->has_free_trial() ) { |
|
| 514 | + $cart_key .= sprintf( '_after_a_%d_%s_trial', $trial_length, $trial_period ); |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + return apply_filters( 'getpaid_get_recurring_item_key', $cart_key, $cart_item ); |
|
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | /** |
@@ -525,17 +525,17 @@ discard block |
||
| 525 | 525 | */ |
| 526 | 526 | function getpaid_get_subscription_groups( $invoice ) { |
| 527 | 527 | |
| 528 | - // Generate subscription groups. |
|
| 529 | - $subscription_groups = array(); |
|
| 530 | - foreach ( $invoice->get_items() as $item ) { |
|
| 528 | + // Generate subscription groups. |
|
| 529 | + $subscription_groups = array(); |
|
| 530 | + foreach ( $invoice->get_items() as $item ) { |
|
| 531 | 531 | |
| 532 | - if ( $item->is_recurring() ) { |
|
| 533 | - $subscription_groups[ getpaid_get_recurring_item_key( $item ) ][] = $item; |
|
| 534 | - } |
|
| 532 | + if ( $item->is_recurring() ) { |
|
| 533 | + $subscription_groups[ getpaid_get_recurring_item_key( $item ) ][] = $item; |
|
| 534 | + } |
|
| 535 | 535 | |
| 536 | - } |
|
| 536 | + } |
|
| 537 | 537 | |
| 538 | - return $subscription_groups; |
|
| 538 | + return $subscription_groups; |
|
| 539 | 539 | } |
| 540 | 540 | |
| 541 | 541 | /** |
@@ -549,57 +549,57 @@ discard block |
||
| 549 | 549 | */ |
| 550 | 550 | function getpaid_calculate_subscription_totals( $invoice ) { |
| 551 | 551 | |
| 552 | - // Generate subscription groups. |
|
| 553 | - $subscription_groups = getpaid_get_subscription_groups( $invoice ); |
|
| 552 | + // Generate subscription groups. |
|
| 553 | + $subscription_groups = getpaid_get_subscription_groups( $invoice ); |
|
| 554 | 554 | |
| 555 | - // Now let's calculate the totals for each group of subscriptions |
|
| 556 | - $subscription_totals = array(); |
|
| 555 | + // Now let's calculate the totals for each group of subscriptions |
|
| 556 | + $subscription_totals = array(); |
|
| 557 | 557 | |
| 558 | - foreach ( $subscription_groups as $subscription_key => $items ) { |
|
| 558 | + foreach ( $subscription_groups as $subscription_key => $items ) { |
|
| 559 | 559 | |
| 560 | - if ( empty( $subscription_totals[ $subscription_key ] ) ) { |
|
| 560 | + if ( empty( $subscription_totals[ $subscription_key ] ) ) { |
|
| 561 | 561 | |
| 562 | - $subscription_totals[ $subscription_key ] = array( |
|
| 563 | - 'initial_total' => 0, |
|
| 564 | - 'recurring_total' => 0, |
|
| 565 | - 'items' => array(), |
|
| 566 | - 'trialling' => false, |
|
| 567 | - ); |
|
| 562 | + $subscription_totals[ $subscription_key ] = array( |
|
| 563 | + 'initial_total' => 0, |
|
| 564 | + 'recurring_total' => 0, |
|
| 565 | + 'items' => array(), |
|
| 566 | + 'trialling' => false, |
|
| 567 | + ); |
|
| 568 | 568 | |
| 569 | - } |
|
| 569 | + } |
|
| 570 | 570 | |
| 571 | - /** |
|
| 572 | - * Get the totals of the group. |
|
| 573 | - * @var GetPaid_Form_Item $item |
|
| 574 | - */ |
|
| 575 | - foreach ( $items as $item ) { |
|
| 571 | + /** |
|
| 572 | + * Get the totals of the group. |
|
| 573 | + * @var GetPaid_Form_Item $item |
|
| 574 | + */ |
|
| 575 | + foreach ( $items as $item ) { |
|
| 576 | 576 | |
| 577 | - $subscription_totals[ $subscription_key ]['items'][$item->get_id()] = $item->prepare_data_for_saving(); |
|
| 578 | - $subscription_totals[ $subscription_key ]['item_id'] = $item->get_id(); |
|
| 579 | - $subscription_totals[ $subscription_key ]['period'] = $item->get_recurring_period( true ); |
|
| 580 | - $subscription_totals[ $subscription_key ]['interval'] = $item->get_recurring_interval(); |
|
| 581 | - $subscription_totals[ $subscription_key ]['initial_total'] += $item->get_sub_total(); |
|
| 582 | - $subscription_totals[ $subscription_key ]['recurring_total'] += $item->get_recurring_sub_total(); |
|
| 583 | - $subscription_totals[ $subscription_key ]['recurring_limit'] = $item->get_recurring_limit(); |
|
| 577 | + $subscription_totals[ $subscription_key ]['items'][$item->get_id()] = $item->prepare_data_for_saving(); |
|
| 578 | + $subscription_totals[ $subscription_key ]['item_id'] = $item->get_id(); |
|
| 579 | + $subscription_totals[ $subscription_key ]['period'] = $item->get_recurring_period( true ); |
|
| 580 | + $subscription_totals[ $subscription_key ]['interval'] = $item->get_recurring_interval(); |
|
| 581 | + $subscription_totals[ $subscription_key ]['initial_total'] += $item->get_sub_total(); |
|
| 582 | + $subscription_totals[ $subscription_key ]['recurring_total'] += $item->get_recurring_sub_total(); |
|
| 583 | + $subscription_totals[ $subscription_key ]['recurring_limit'] = $item->get_recurring_limit(); |
|
| 584 | 584 | |
| 585 | - // Calculate the next renewal date. |
|
| 586 | - $period = $item->get_recurring_period( true ); |
|
| 587 | - $interval = $item->get_recurring_interval(); |
|
| 585 | + // Calculate the next renewal date. |
|
| 586 | + $period = $item->get_recurring_period( true ); |
|
| 587 | + $interval = $item->get_recurring_interval(); |
|
| 588 | 588 | |
| 589 | - // If the subscription item has a trial period... |
|
| 590 | - if ( $item->has_free_trial() ) { |
|
| 591 | - $period = $item->get_trial_period( true ); |
|
| 592 | - $interval = $item->get_trial_interval(); |
|
| 593 | - $subscription_totals[ $subscription_key ]['trialling'] = $interval . ' ' . $period; |
|
| 594 | - } |
|
| 589 | + // If the subscription item has a trial period... |
|
| 590 | + if ( $item->has_free_trial() ) { |
|
| 591 | + $period = $item->get_trial_period( true ); |
|
| 592 | + $interval = $item->get_trial_interval(); |
|
| 593 | + $subscription_totals[ $subscription_key ]['trialling'] = $interval . ' ' . $period; |
|
| 594 | + } |
|
| 595 | 595 | |
| 596 | - $subscription_totals[ $subscription_key ]['renews_on'] = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", current_time( 'timestamp' ) ) ); |
|
| 596 | + $subscription_totals[ $subscription_key ]['renews_on'] = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", current_time( 'timestamp' ) ) ); |
|
| 597 | 597 | |
| 598 | - } |
|
| 598 | + } |
|
| 599 | 599 | |
| 600 | - } |
|
| 600 | + } |
|
| 601 | 601 | |
| 602 | - return apply_filters( 'getpaid_calculate_subscription_totals', $subscription_totals, $invoice ); |
|
| 602 | + return apply_filters( 'getpaid_calculate_subscription_totals', $subscription_totals, $invoice ); |
|
| 603 | 603 | } |
| 604 | 604 | |
| 605 | 605 | /** |
@@ -610,17 +610,17 @@ discard block |
||
| 610 | 610 | */ |
| 611 | 611 | function getpaid_should_group_subscriptions( $invoice ) { |
| 612 | 612 | |
| 613 | - $recurring_items = 0; |
|
| 613 | + $recurring_items = 0; |
|
| 614 | 614 | |
| 615 | - foreach ( $invoice->get_items() as $item ) { |
|
| 615 | + foreach ( $invoice->get_items() as $item ) { |
|
| 616 | 616 | |
| 617 | - if ( $item->is_recurring() ) { |
|
| 618 | - $recurring_items ++; |
|
| 619 | - } |
|
| 617 | + if ( $item->is_recurring() ) { |
|
| 618 | + $recurring_items ++; |
|
| 619 | + } |
|
| 620 | 620 | |
| 621 | - } |
|
| 621 | + } |
|
| 622 | 622 | |
| 623 | - return apply_filters( 'getpaid_should_group_subscriptions', $recurring_items > 1, $invoice ); |
|
| 623 | + return apply_filters( 'getpaid_should_group_subscriptions', $recurring_items > 1, $invoice ); |
|
| 624 | 624 | } |
| 625 | 625 | |
| 626 | 626 | /** |
@@ -630,14 +630,14 @@ discard block |
||
| 630 | 630 | * @return int |
| 631 | 631 | */ |
| 632 | 632 | function getpaid_count_subscription_invoices( $parent_invoice_id ) { |
| 633 | - global $wpdb; |
|
| 634 | - |
|
| 635 | - return (int) $wpdb->get_var( |
|
| 636 | - $wpdb->prepare( |
|
| 637 | - "SELECT COUNT(ID) FROM $wpdb->posts WHERE ( post_parent=%d OR ID=%d ) AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )", |
|
| 638 | - $parent_invoice_id, |
|
| 639 | - $parent_invoice_id |
|
| 640 | - ) |
|
| 641 | - ); |
|
| 633 | + global $wpdb; |
|
| 634 | + |
|
| 635 | + return (int) $wpdb->get_var( |
|
| 636 | + $wpdb->prepare( |
|
| 637 | + "SELECT COUNT(ID) FROM $wpdb->posts WHERE ( post_parent=%d OR ID=%d ) AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )", |
|
| 638 | + $parent_invoice_id, |
|
| 639 | + $parent_invoice_id |
|
| 640 | + ) |
|
| 641 | + ); |
|
| 642 | 642 | |
| 643 | 643 | } |
@@ -13,18 +13,18 @@ discard block |
||
| 13 | 13 | * @return WPInv_Subscription[]|WPInv_Subscription|false |
| 14 | 14 | * @since 2.3.0 |
| 15 | 15 | */ |
| 16 | -function getpaid_get_invoice_subscriptions( $invoice ) { |
|
| 16 | +function getpaid_get_invoice_subscriptions($invoice) { |
|
| 17 | 17 | |
| 18 | 18 | // Retrieve subscription groups. |
| 19 | - $subscription_ids = wp_list_pluck( getpaid_get_invoice_subscription_groups( $invoice->get_id() ), 'subscription_id' ); |
|
| 19 | + $subscription_ids = wp_list_pluck(getpaid_get_invoice_subscription_groups($invoice->get_id()), 'subscription_id'); |
|
| 20 | 20 | |
| 21 | 21 | // No subscription groups, normal subscription. |
| 22 | - if ( empty( $subscription_ids ) ) { |
|
| 23 | - return getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 22 | + if (empty($subscription_ids)) { |
|
| 23 | + return getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | // Subscription groups. |
| 27 | - return array_filter( array_map( 'getpaid_get_subscription', $subscription_ids ) ); |
|
| 27 | + return array_filter(array_map('getpaid_get_subscription', $subscription_ids)); |
|
| 28 | 28 | |
| 29 | 29 | } |
| 30 | 30 | |
@@ -35,9 +35,9 @@ discard block |
||
| 35 | 35 | * @return array |
| 36 | 36 | * @since 2.3.0 |
| 37 | 37 | */ |
| 38 | -function getpaid_get_invoice_subscription_groups( $invoice_id ) { |
|
| 39 | - $subscription_groups = get_post_meta( $invoice_id, 'getpaid_subscription_groups', true ); |
|
| 40 | - return empty( $subscription_groups ) ? array() : $subscription_groups; |
|
| 38 | +function getpaid_get_invoice_subscription_groups($invoice_id) { |
|
| 39 | + $subscription_groups = get_post_meta($invoice_id, 'getpaid_subscription_groups', true); |
|
| 40 | + return empty($subscription_groups) ? array() : $subscription_groups; |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -48,10 +48,10 @@ discard block |
||
| 48 | 48 | * @return array|false |
| 49 | 49 | * @since 2.3.0 |
| 50 | 50 | */ |
| 51 | -function getpaid_get_invoice_subscription_group( $invoice_id, $subscription_id ) { |
|
| 52 | - $subscription_groups = getpaid_get_invoice_subscription_groups( $invoice_id ); |
|
| 53 | - $matching_group = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) ); |
|
| 54 | - return reset( $matching_group ); |
|
| 51 | +function getpaid_get_invoice_subscription_group($invoice_id, $subscription_id) { |
|
| 52 | + $subscription_groups = getpaid_get_invoice_subscription_groups($invoice_id); |
|
| 53 | + $matching_group = wp_list_filter($subscription_groups, compact('subscription_id')); |
|
| 54 | + return reset($matching_group); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
@@ -61,8 +61,8 @@ discard block |
||
| 61 | 61 | * @since 2.3.0 |
| 62 | 62 | * @return WPInv_Subscription|false |
| 63 | 63 | */ |
| 64 | -function getpaid_get_subscription( $subscription ) { |
|
| 65 | - $subscription = new WPInv_Subscription( $subscription ); |
|
| 64 | +function getpaid_get_subscription($subscription) { |
|
| 65 | + $subscription = new WPInv_Subscription($subscription); |
|
| 66 | 66 | return $subscription->exists() ? $subscription : false; |
| 67 | 67 | } |
| 68 | 68 | |
@@ -75,26 +75,26 @@ discard block |
||
| 75 | 75 | * |
| 76 | 76 | * @return int|array|WPInv_Subscription[]|GetPaid_Subscriptions_Query |
| 77 | 77 | */ |
| 78 | -function getpaid_get_subscriptions( $args = array(), $return = 'results' ) { |
|
| 78 | +function getpaid_get_subscriptions($args = array(), $return = 'results') { |
|
| 79 | 79 | |
| 80 | 80 | // Do not retrieve all fields if we just want the count. |
| 81 | - if ( 'count' == $return ) { |
|
| 81 | + if ('count' == $return) { |
|
| 82 | 82 | $args['fields'] = 'id'; |
| 83 | 83 | $args['number'] = 1; |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | // Do not count all matches if we just want the results. |
| 87 | - if ( 'results' == $return ) { |
|
| 87 | + if ('results' == $return) { |
|
| 88 | 88 | $args['count_total'] = false; |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - $query = new GetPaid_Subscriptions_Query( $args ); |
|
| 91 | + $query = new GetPaid_Subscriptions_Query($args); |
|
| 92 | 92 | |
| 93 | - if ( 'results' == $return ) { |
|
| 93 | + if ('results' == $return) { |
|
| 94 | 94 | return $query->get_results(); |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - if ( 'count' == $return ) { |
|
| 97 | + if ('count' == $return) { |
|
| 98 | 98 | return $query->get_total(); |
| 99 | 99 | } |
| 100 | 100 | |
@@ -111,13 +111,13 @@ discard block |
||
| 111 | 111 | return apply_filters( |
| 112 | 112 | 'getpaid_get_subscription_statuses', |
| 113 | 113 | array( |
| 114 | - 'pending' => __( 'Pending', 'invoicing' ), |
|
| 115 | - 'trialling' => __( 'Trialing', 'invoicing' ), |
|
| 116 | - 'active' => __( 'Active', 'invoicing' ), |
|
| 117 | - 'failing' => __( 'Failing', 'invoicing' ), |
|
| 118 | - 'expired' => __( 'Expired', 'invoicing' ), |
|
| 119 | - 'completed' => __( 'Complete', 'invoicing' ), |
|
| 120 | - 'cancelled' => __( 'Cancelled', 'invoicing' ), |
|
| 114 | + 'pending' => __('Pending', 'invoicing'), |
|
| 115 | + 'trialling' => __('Trialing', 'invoicing'), |
|
| 116 | + 'active' => __('Active', 'invoicing'), |
|
| 117 | + 'failing' => __('Failing', 'invoicing'), |
|
| 118 | + 'expired' => __('Expired', 'invoicing'), |
|
| 119 | + 'completed' => __('Complete', 'invoicing'), |
|
| 120 | + 'cancelled' => __('Cancelled', 'invoicing'), |
|
| 121 | 121 | ) |
| 122 | 122 | ); |
| 123 | 123 | |
@@ -128,9 +128,9 @@ discard block |
||
| 128 | 128 | * |
| 129 | 129 | * @return string |
| 130 | 130 | */ |
| 131 | -function getpaid_get_subscription_status_label( $status ) { |
|
| 131 | +function getpaid_get_subscription_status_label($status) { |
|
| 132 | 132 | $statuses = getpaid_get_subscription_statuses(); |
| 133 | - return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) ); |
|
| 133 | + return isset($statuses[$status]) ? $statuses[$status] : ucfirst(sanitize_text_field($status)); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
@@ -160,14 +160,14 @@ discard block |
||
| 160 | 160 | * |
| 161 | 161 | * @return array |
| 162 | 162 | */ |
| 163 | -function getpaid_get_subscription_status_counts( $args = array() ) { |
|
| 163 | +function getpaid_get_subscription_status_counts($args = array()) { |
|
| 164 | 164 | |
| 165 | - $statuses = array_keys( getpaid_get_subscription_statuses() ); |
|
| 165 | + $statuses = array_keys(getpaid_get_subscription_statuses()); |
|
| 166 | 166 | $counts = array(); |
| 167 | 167 | |
| 168 | - foreach ( $statuses as $status ) { |
|
| 169 | - $_args = wp_parse_args( "status=$status", $args ); |
|
| 170 | - $counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' ); |
|
| 168 | + foreach ($statuses as $status) { |
|
| 169 | + $_args = wp_parse_args("status=$status", $args); |
|
| 170 | + $counts[$status] = getpaid_get_subscriptions($_args, 'count'); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | return $counts; |
@@ -186,23 +186,23 @@ discard block |
||
| 186 | 186 | array( |
| 187 | 187 | |
| 188 | 188 | 'day' => array( |
| 189 | - 'singular' => __( '%s day', 'invoicing' ), |
|
| 190 | - 'plural' => __( '%d days', 'invoicing' ), |
|
| 189 | + 'singular' => __('%s day', 'invoicing'), |
|
| 190 | + 'plural' => __('%d days', 'invoicing'), |
|
| 191 | 191 | ), |
| 192 | 192 | |
| 193 | 193 | 'week' => array( |
| 194 | - 'singular' => __( '%s week', 'invoicing' ), |
|
| 195 | - 'plural' => __( '%d weeks', 'invoicing' ), |
|
| 194 | + 'singular' => __('%s week', 'invoicing'), |
|
| 195 | + 'plural' => __('%d weeks', 'invoicing'), |
|
| 196 | 196 | ), |
| 197 | 197 | |
| 198 | 198 | 'month' => array( |
| 199 | - 'singular' => __( '%s month', 'invoicing' ), |
|
| 200 | - 'plural' => __( '%d months', 'invoicing' ), |
|
| 199 | + 'singular' => __('%s month', 'invoicing'), |
|
| 200 | + 'plural' => __('%d months', 'invoicing'), |
|
| 201 | 201 | ), |
| 202 | 202 | |
| 203 | 203 | 'year' => array( |
| 204 | - 'singular' => __( '%s year', 'invoicing' ), |
|
| 205 | - 'plural' => __( '%d years', 'invoicing' ), |
|
| 204 | + 'singular' => __('%s year', 'invoicing'), |
|
| 205 | + 'plural' => __('%d years', 'invoicing'), |
|
| 206 | 206 | ), |
| 207 | 207 | |
| 208 | 208 | ) |
@@ -216,8 +216,8 @@ discard block |
||
| 216 | 216 | * @param string $trial_period |
| 217 | 217 | * @return int |
| 218 | 218 | */ |
| 219 | -function getpaid_get_subscription_trial_period_interval( $trial_period ) { |
|
| 220 | - return (int) preg_replace( '/[^0-9]/', '', $trial_period ); |
|
| 219 | +function getpaid_get_subscription_trial_period_interval($trial_period) { |
|
| 220 | + return (int) preg_replace('/[^0-9]/', '', $trial_period); |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | /** |
@@ -226,8 +226,8 @@ discard block |
||
| 226 | 226 | * @param string $trial_period |
| 227 | 227 | * @return string |
| 228 | 228 | */ |
| 229 | -function getpaid_get_subscription_trial_period_period( $trial_period ) { |
|
| 230 | - return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) ); |
|
| 229 | +function getpaid_get_subscription_trial_period_period($trial_period) { |
|
| 230 | + return preg_replace('/[^a-z]/', '', strtolower($trial_period)); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | /** |
@@ -237,9 +237,9 @@ discard block |
||
| 237 | 237 | * @param int $interval |
| 238 | 238 | * @return string |
| 239 | 239 | */ |
| 240 | -function getpaid_get_subscription_period_label( $period, $interval = 1, $singular_prefix = '1' ) { |
|
| 241 | - $label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label( $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix ); |
|
| 242 | - return strtolower( sanitize_text_field( $label ) ); |
|
| 240 | +function getpaid_get_subscription_period_label($period, $interval = 1, $singular_prefix = '1') { |
|
| 241 | + $label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label($period, $interval) : getpaid_get_singular_subscription_period_label($period, $singular_prefix); |
|
| 242 | + return strtolower(sanitize_text_field($label)); |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | /** |
@@ -248,19 +248,19 @@ discard block |
||
| 248 | 248 | * @param string $period |
| 249 | 249 | * @return string |
| 250 | 250 | */ |
| 251 | -function getpaid_get_singular_subscription_period_label( $period, $singular_prefix = '1' ) { |
|
| 251 | +function getpaid_get_singular_subscription_period_label($period, $singular_prefix = '1') { |
|
| 252 | 252 | |
| 253 | 253 | $periods = getpaid_get_subscription_periods(); |
| 254 | - $period = strtolower( $period ); |
|
| 254 | + $period = strtolower($period); |
|
| 255 | 255 | |
| 256 | - if ( isset( $periods[ $period ] ) ) { |
|
| 257 | - return sprintf( $periods[ $period ]['singular'], $singular_prefix ); |
|
| 256 | + if (isset($periods[$period])) { |
|
| 257 | + return sprintf($periods[$period]['singular'], $singular_prefix); |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | // Backwards compatibility. |
| 261 | - foreach ( $periods as $key => $data ) { |
|
| 262 | - if ( strpos( $key, $period ) === 0 ) { |
|
| 263 | - return sprintf( $data['singular'], $singular_prefix ); |
|
| 261 | + foreach ($periods as $key => $data) { |
|
| 262 | + if (strpos($key, $period) === 0) { |
|
| 263 | + return sprintf($data['singular'], $singular_prefix); |
|
| 264 | 264 | } |
| 265 | 265 | } |
| 266 | 266 | |
@@ -275,19 +275,19 @@ discard block |
||
| 275 | 275 | * @param int $interval |
| 276 | 276 | * @return string |
| 277 | 277 | */ |
| 278 | -function getpaid_get_plural_subscription_period_label( $period, $interval ) { |
|
| 278 | +function getpaid_get_plural_subscription_period_label($period, $interval) { |
|
| 279 | 279 | |
| 280 | 280 | $periods = getpaid_get_subscription_periods(); |
| 281 | - $period = strtolower( $period ); |
|
| 281 | + $period = strtolower($period); |
|
| 282 | 282 | |
| 283 | - if ( isset( $periods[ $period ] ) ) { |
|
| 284 | - return sprintf( $periods[ $period ]['plural'], $interval ); |
|
| 283 | + if (isset($periods[$period])) { |
|
| 284 | + return sprintf($periods[$period]['plural'], $interval); |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | // Backwards compatibility. |
| 288 | - foreach ( $periods as $key => $data ) { |
|
| 289 | - if ( strpos( $key, $period ) === 0 ) { |
|
| 290 | - return sprintf( $data['plural'], $interval ); |
|
| 288 | + foreach ($periods as $key => $data) { |
|
| 289 | + if (strpos($key, $period) === 0) { |
|
| 290 | + return sprintf($data['plural'], $interval); |
|
| 291 | 291 | } |
| 292 | 292 | } |
| 293 | 293 | |
@@ -301,32 +301,32 @@ discard block |
||
| 301 | 301 | * @param WPInv_Subscription $subscription |
| 302 | 302 | * @return string |
| 303 | 303 | */ |
| 304 | -function getpaid_get_formatted_subscription_amount( $subscription ) { |
|
| 304 | +function getpaid_get_formatted_subscription_amount($subscription) { |
|
| 305 | 305 | |
| 306 | - $initial = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
| 307 | - $recurring = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
| 308 | - $period = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
| 306 | + $initial = wpinv_price($subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency()); |
|
| 307 | + $recurring = wpinv_price($subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency()); |
|
| 308 | + $period = getpaid_get_subscription_period_label($subscription->get_period(), $subscription->get_frequency(), ''); |
|
| 309 | 309 | $bill_times = $subscription->get_bill_times(); |
| 310 | 310 | |
| 311 | - if ( ! empty( $bill_times ) ) { |
|
| 311 | + if (!empty($bill_times)) { |
|
| 312 | 312 | $bill_times = $subscription->get_frequency() * $bill_times; |
| 313 | - $bill_times = getpaid_get_subscription_period_label( $subscription->get_period(), $bill_times ); |
|
| 313 | + $bill_times = getpaid_get_subscription_period_label($subscription->get_period(), $bill_times); |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | // Trial periods. |
| 317 | - if ( $subscription->has_trial_period() ) { |
|
| 317 | + if ($subscription->has_trial_period()) { |
|
| 318 | 318 | |
| 319 | - $trial_period = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() ); |
|
| 320 | - $trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() ); |
|
| 319 | + $trial_period = getpaid_get_subscription_trial_period_period($subscription->get_trial_period()); |
|
| 320 | + $trial_interval = getpaid_get_subscription_trial_period_interval($subscription->get_trial_period()); |
|
| 321 | 321 | |
| 322 | - if ( empty( $bill_times ) ) { |
|
| 322 | + if (empty($bill_times)) { |
|
| 323 | 323 | |
| 324 | 324 | return sprintf( |
| 325 | 325 | |
| 326 | 326 | // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period |
| 327 | - _x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ), |
|
| 327 | + _x('%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing'), |
|
| 328 | 328 | $initial, |
| 329 | - getpaid_get_subscription_period_label( $trial_period, $trial_interval ), |
|
| 329 | + getpaid_get_subscription_period_label($trial_period, $trial_interval), |
|
| 330 | 330 | $recurring, |
| 331 | 331 | $period |
| 332 | 332 | |
@@ -337,9 +337,9 @@ discard block |
||
| 337 | 337 | return sprintf( |
| 338 | 338 | |
| 339 | 339 | // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period, $5: is the bill times |
| 340 | - _x( '%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing' ), |
|
| 340 | + _x('%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing'), |
|
| 341 | 341 | $initial, |
| 342 | - getpaid_get_subscription_period_label( $trial_period, $trial_interval ), |
|
| 342 | + getpaid_get_subscription_period_label($trial_period, $trial_interval), |
|
| 343 | 343 | $recurring, |
| 344 | 344 | $period, |
| 345 | 345 | $bill_times |
@@ -347,14 +347,14 @@ discard block |
||
| 347 | 347 | |
| 348 | 348 | } |
| 349 | 349 | |
| 350 | - if ( $initial != $recurring ) { |
|
| 350 | + if ($initial != $recurring) { |
|
| 351 | 351 | |
| 352 | - if ( empty( $bill_times ) ) { |
|
| 352 | + if (empty($bill_times)) { |
|
| 353 | 353 | |
| 354 | 354 | return sprintf( |
| 355 | 355 | |
| 356 | 356 | // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period |
| 357 | - _x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ), |
|
| 357 | + _x('Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing'), |
|
| 358 | 358 | $initial, |
| 359 | 359 | $recurring, |
| 360 | 360 | $period |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | return sprintf( |
| 367 | 367 | |
| 368 | 368 | // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period, $4: is the bill times |
| 369 | - _x( 'Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing' ), |
|
| 369 | + _x('Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing'), |
|
| 370 | 370 | $initial, |
| 371 | 371 | $recurring, |
| 372 | 372 | $period, |
@@ -376,12 +376,12 @@ discard block |
||
| 376 | 376 | |
| 377 | 377 | } |
| 378 | 378 | |
| 379 | - if ( empty( $bill_times ) ) { |
|
| 379 | + if (empty($bill_times)) { |
|
| 380 | 380 | |
| 381 | 381 | return sprintf( |
| 382 | 382 | |
| 383 | 383 | // translators: $1: is the recurring amount, $2: is the recurring period |
| 384 | - _x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ), |
|
| 384 | + _x('%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing'), |
|
| 385 | 385 | $initial, |
| 386 | 386 | $period |
| 387 | 387 | |
@@ -392,7 +392,7 @@ discard block |
||
| 392 | 392 | return sprintf( |
| 393 | 393 | |
| 394 | 394 | // translators: $1: is the bill times, $2: is the recurring amount, $3: is the recurring period |
| 395 | - _x( '%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ), |
|
| 395 | + _x('%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing'), |
|
| 396 | 396 | $bill_times, |
| 397 | 397 | $initial, |
| 398 | 398 | $period |
@@ -407,8 +407,8 @@ discard block |
||
| 407 | 407 | * @param WPInv_Invoice $invoice |
| 408 | 408 | * @return WPInv_Subscription|false |
| 409 | 409 | */ |
| 410 | -function getpaid_get_invoice_subscription( $invoice ) { |
|
| 411 | - return getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 410 | +function getpaid_get_invoice_subscription($invoice) { |
|
| 411 | + return getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | /** |
@@ -416,9 +416,9 @@ discard block |
||
| 416 | 416 | * |
| 417 | 417 | * @param WPInv_Invoice $invoice |
| 418 | 418 | */ |
| 419 | -function getpaid_activate_invoice_subscription( $invoice ) { |
|
| 420 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
| 421 | - if ( is_a( $subscription, 'WPInv_Subscription' ) ) { |
|
| 419 | +function getpaid_activate_invoice_subscription($invoice) { |
|
| 420 | + $subscription = getpaid_get_invoice_subscription($invoice); |
|
| 421 | + if (is_a($subscription, 'WPInv_Subscription')) { |
|
| 422 | 422 | $subscription->activate(); |
| 423 | 423 | } |
| 424 | 424 | } |
@@ -429,7 +429,7 @@ discard block |
||
| 429 | 429 | * @return WPInv_Subscriptions |
| 430 | 430 | */ |
| 431 | 431 | function getpaid_subscriptions() { |
| 432 | - return getpaid()->get( 'subscriptions' ); |
|
| 432 | + return getpaid()->get('subscriptions'); |
|
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | /** |
@@ -438,13 +438,13 @@ discard block |
||
| 438 | 438 | * @since 2.3.0 |
| 439 | 439 | * @return WPInv_Subscription|bool |
| 440 | 440 | */ |
| 441 | -function wpinv_get_invoice_subscription( $invoice ) { |
|
| 441 | +function wpinv_get_invoice_subscription($invoice) { |
|
| 442 | 442 | |
| 443 | 443 | // Retrieve the invoice. |
| 444 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 444 | + $invoice = new WPInv_Invoice($invoice); |
|
| 445 | 445 | |
| 446 | 446 | // Ensure it is a recurring invoice. |
| 447 | - if ( ! $invoice->is_recurring() ) { |
|
| 447 | + if (!$invoice->is_recurring()) { |
|
| 448 | 448 | return false; |
| 449 | 449 | } |
| 450 | 450 | |
@@ -456,7 +456,7 @@ discard block |
||
| 456 | 456 | ) |
| 457 | 457 | ); |
| 458 | 458 | |
| 459 | - return empty( $subscription ) ? false : $subscription[0]; |
|
| 459 | + return empty($subscription) ? false : $subscription[0]; |
|
| 460 | 460 | |
| 461 | 461 | } |
| 462 | 462 | |
@@ -471,50 +471,50 @@ discard block |
||
| 471 | 471 | * @param GetPaid_Form_Item|WPInv_Item $cart_item |
| 472 | 472 | * @return string |
| 473 | 473 | */ |
| 474 | -function getpaid_get_recurring_item_key( $cart_item ) { |
|
| 474 | +function getpaid_get_recurring_item_key($cart_item) { |
|
| 475 | 475 | |
| 476 | 476 | $cart_key = 'renews_'; |
| 477 | 477 | $interval = $cart_item->get_recurring_interval(); |
| 478 | - $period = $cart_item->get_recurring_period( true ); |
|
| 478 | + $period = $cart_item->get_recurring_period(true); |
|
| 479 | 479 | $length = $cart_item->get_recurring_limit() * $interval; |
| 480 | - $trial_period = $cart_item->get_trial_period( true ); |
|
| 480 | + $trial_period = $cart_item->get_trial_period(true); |
|
| 481 | 481 | $trial_length = $cart_item->get_trial_interval(); |
| 482 | 482 | |
| 483 | 483 | // First start with the billing interval and period |
| 484 | - switch ( $interval ) { |
|
| 484 | + switch ($interval) { |
|
| 485 | 485 | case 1 : |
| 486 | - if ( 'day' == $period ) { |
|
| 486 | + if ('day' == $period) { |
|
| 487 | 487 | $cart_key .= 'daily'; |
| 488 | 488 | } else { |
| 489 | - $cart_key .= sprintf( '%sly', $period ); |
|
| 489 | + $cart_key .= sprintf('%sly', $period); |
|
| 490 | 490 | } |
| 491 | 491 | break; |
| 492 | 492 | case 2 : |
| 493 | - $cart_key .= sprintf( 'every_2nd_%s', $period ); |
|
| 493 | + $cart_key .= sprintf('every_2nd_%s', $period); |
|
| 494 | 494 | break; |
| 495 | 495 | case 3 : |
| 496 | - $cart_key .= sprintf( 'every_3rd_%s', $period ); |
|
| 496 | + $cart_key .= sprintf('every_3rd_%s', $period); |
|
| 497 | 497 | break; |
| 498 | 498 | default: |
| 499 | - $cart_key .= sprintf( 'every_%dth_%s', $interval, $period ); |
|
| 499 | + $cart_key .= sprintf('every_%dth_%s', $interval, $period); |
|
| 500 | 500 | break; |
| 501 | 501 | } |
| 502 | 502 | |
| 503 | 503 | // Maybe add the optional maximum billing periods... |
| 504 | - if ( $length > 0 ) { |
|
| 504 | + if ($length > 0) { |
|
| 505 | 505 | $cart_key .= '_for_'; |
| 506 | - $cart_key .= sprintf( '%d_%s', $length, $period ); |
|
| 507 | - if ( $length > 1 ) { |
|
| 506 | + $cart_key .= sprintf('%d_%s', $length, $period); |
|
| 507 | + if ($length > 1) { |
|
| 508 | 508 | $cart_key .= 's'; |
| 509 | 509 | } |
| 510 | 510 | } |
| 511 | 511 | |
| 512 | 512 | // And an optional free trial. |
| 513 | - if ( $cart_item->has_free_trial() ) { |
|
| 514 | - $cart_key .= sprintf( '_after_a_%d_%s_trial', $trial_length, $trial_period ); |
|
| 513 | + if ($cart_item->has_free_trial()) { |
|
| 514 | + $cart_key .= sprintf('_after_a_%d_%s_trial', $trial_length, $trial_period); |
|
| 515 | 515 | } |
| 516 | 516 | |
| 517 | - return apply_filters( 'getpaid_get_recurring_item_key', $cart_key, $cart_item ); |
|
| 517 | + return apply_filters('getpaid_get_recurring_item_key', $cart_key, $cart_item); |
|
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | /** |
@@ -523,14 +523,14 @@ discard block |
||
| 523 | 523 | * @param WPInv_Invoice|GetPaid_Payment_Form_Submission|GetPaid_Payment_Form $invoice |
| 524 | 524 | * @return array |
| 525 | 525 | */ |
| 526 | -function getpaid_get_subscription_groups( $invoice ) { |
|
| 526 | +function getpaid_get_subscription_groups($invoice) { |
|
| 527 | 527 | |
| 528 | 528 | // Generate subscription groups. |
| 529 | 529 | $subscription_groups = array(); |
| 530 | - foreach ( $invoice->get_items() as $item ) { |
|
| 530 | + foreach ($invoice->get_items() as $item) { |
|
| 531 | 531 | |
| 532 | - if ( $item->is_recurring() ) { |
|
| 533 | - $subscription_groups[ getpaid_get_recurring_item_key( $item ) ][] = $item; |
|
| 532 | + if ($item->is_recurring()) { |
|
| 533 | + $subscription_groups[getpaid_get_recurring_item_key($item)][] = $item; |
|
| 534 | 534 | } |
| 535 | 535 | |
| 536 | 536 | } |
@@ -547,19 +547,19 @@ discard block |
||
| 547 | 547 | * @param WPInv_Invoice|GetPaid_Payment_Form_Submission|GetPaid_Payment_Form $invoice |
| 548 | 548 | * @return array |
| 549 | 549 | */ |
| 550 | -function getpaid_calculate_subscription_totals( $invoice ) { |
|
| 550 | +function getpaid_calculate_subscription_totals($invoice) { |
|
| 551 | 551 | |
| 552 | 552 | // Generate subscription groups. |
| 553 | - $subscription_groups = getpaid_get_subscription_groups( $invoice ); |
|
| 553 | + $subscription_groups = getpaid_get_subscription_groups($invoice); |
|
| 554 | 554 | |
| 555 | 555 | // Now let's calculate the totals for each group of subscriptions |
| 556 | 556 | $subscription_totals = array(); |
| 557 | 557 | |
| 558 | - foreach ( $subscription_groups as $subscription_key => $items ) { |
|
| 558 | + foreach ($subscription_groups as $subscription_key => $items) { |
|
| 559 | 559 | |
| 560 | - if ( empty( $subscription_totals[ $subscription_key ] ) ) { |
|
| 560 | + if (empty($subscription_totals[$subscription_key])) { |
|
| 561 | 561 | |
| 562 | - $subscription_totals[ $subscription_key ] = array( |
|
| 562 | + $subscription_totals[$subscription_key] = array( |
|
| 563 | 563 | 'initial_total' => 0, |
| 564 | 564 | 'recurring_total' => 0, |
| 565 | 565 | 'items' => array(), |
@@ -572,34 +572,34 @@ discard block |
||
| 572 | 572 | * Get the totals of the group. |
| 573 | 573 | * @var GetPaid_Form_Item $item |
| 574 | 574 | */ |
| 575 | - foreach ( $items as $item ) { |
|
| 575 | + foreach ($items as $item) { |
|
| 576 | 576 | |
| 577 | - $subscription_totals[ $subscription_key ]['items'][$item->get_id()] = $item->prepare_data_for_saving(); |
|
| 578 | - $subscription_totals[ $subscription_key ]['item_id'] = $item->get_id(); |
|
| 579 | - $subscription_totals[ $subscription_key ]['period'] = $item->get_recurring_period( true ); |
|
| 580 | - $subscription_totals[ $subscription_key ]['interval'] = $item->get_recurring_interval(); |
|
| 581 | - $subscription_totals[ $subscription_key ]['initial_total'] += $item->get_sub_total(); |
|
| 582 | - $subscription_totals[ $subscription_key ]['recurring_total'] += $item->get_recurring_sub_total(); |
|
| 583 | - $subscription_totals[ $subscription_key ]['recurring_limit'] = $item->get_recurring_limit(); |
|
| 577 | + $subscription_totals[$subscription_key]['items'][$item->get_id()] = $item->prepare_data_for_saving(); |
|
| 578 | + $subscription_totals[$subscription_key]['item_id'] = $item->get_id(); |
|
| 579 | + $subscription_totals[$subscription_key]['period'] = $item->get_recurring_period(true); |
|
| 580 | + $subscription_totals[$subscription_key]['interval'] = $item->get_recurring_interval(); |
|
| 581 | + $subscription_totals[$subscription_key]['initial_total'] += $item->get_sub_total(); |
|
| 582 | + $subscription_totals[$subscription_key]['recurring_total'] += $item->get_recurring_sub_total(); |
|
| 583 | + $subscription_totals[$subscription_key]['recurring_limit'] = $item->get_recurring_limit(); |
|
| 584 | 584 | |
| 585 | 585 | // Calculate the next renewal date. |
| 586 | - $period = $item->get_recurring_period( true ); |
|
| 586 | + $period = $item->get_recurring_period(true); |
|
| 587 | 587 | $interval = $item->get_recurring_interval(); |
| 588 | 588 | |
| 589 | 589 | // If the subscription item has a trial period... |
| 590 | - if ( $item->has_free_trial() ) { |
|
| 591 | - $period = $item->get_trial_period( true ); |
|
| 590 | + if ($item->has_free_trial()) { |
|
| 591 | + $period = $item->get_trial_period(true); |
|
| 592 | 592 | $interval = $item->get_trial_interval(); |
| 593 | - $subscription_totals[ $subscription_key ]['trialling'] = $interval . ' ' . $period; |
|
| 593 | + $subscription_totals[$subscription_key]['trialling'] = $interval . ' ' . $period; |
|
| 594 | 594 | } |
| 595 | 595 | |
| 596 | - $subscription_totals[ $subscription_key ]['renews_on'] = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", current_time( 'timestamp' ) ) ); |
|
| 596 | + $subscription_totals[$subscription_key]['renews_on'] = date('Y-m-d H:i:s', strtotime("+$interval $period", current_time('timestamp'))); |
|
| 597 | 597 | |
| 598 | 598 | } |
| 599 | 599 | |
| 600 | 600 | } |
| 601 | 601 | |
| 602 | - return apply_filters( 'getpaid_calculate_subscription_totals', $subscription_totals, $invoice ); |
|
| 602 | + return apply_filters('getpaid_calculate_subscription_totals', $subscription_totals, $invoice); |
|
| 603 | 603 | } |
| 604 | 604 | |
| 605 | 605 | /** |
@@ -608,19 +608,19 @@ discard block |
||
| 608 | 608 | * @param WPInv_Invoice|GetPaid_Payment_Form_Submission|GetPaid_Payment_Form $invoice |
| 609 | 609 | * @return array |
| 610 | 610 | */ |
| 611 | -function getpaid_should_group_subscriptions( $invoice ) { |
|
| 611 | +function getpaid_should_group_subscriptions($invoice) { |
|
| 612 | 612 | |
| 613 | 613 | $recurring_items = 0; |
| 614 | 614 | |
| 615 | - foreach ( $invoice->get_items() as $item ) { |
|
| 615 | + foreach ($invoice->get_items() as $item) { |
|
| 616 | 616 | |
| 617 | - if ( $item->is_recurring() ) { |
|
| 618 | - $recurring_items ++; |
|
| 617 | + if ($item->is_recurring()) { |
|
| 618 | + $recurring_items++; |
|
| 619 | 619 | } |
| 620 | 620 | |
| 621 | 621 | } |
| 622 | 622 | |
| 623 | - return apply_filters( 'getpaid_should_group_subscriptions', $recurring_items > 1, $invoice ); |
|
| 623 | + return apply_filters('getpaid_should_group_subscriptions', $recurring_items > 1, $invoice); |
|
| 624 | 624 | } |
| 625 | 625 | |
| 626 | 626 | /** |
@@ -629,7 +629,7 @@ discard block |
||
| 629 | 629 | * @param int $parent_invoice_id |
| 630 | 630 | * @return int |
| 631 | 631 | */ |
| 632 | -function getpaid_count_subscription_invoices( $parent_invoice_id ) { |
|
| 632 | +function getpaid_count_subscription_invoices($parent_invoice_id) { |
|
| 633 | 633 | global $wpdb; |
| 634 | 634 | |
| 635 | 635 | return (int) $wpdb->get_var( |
@@ -12,276 +12,276 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Metaboxes { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Only save metaboxes once. |
|
| 17 | - * |
|
| 18 | - * @var boolean |
|
| 19 | - */ |
|
| 20 | - private static $saved_meta_boxes = false; |
|
| 21 | - |
|
| 22 | 15 | /** |
| 23 | - * Hook in methods. |
|
| 24 | - */ |
|
| 25 | - public static function init() { |
|
| 26 | - |
|
| 27 | - // Register metaboxes. |
|
| 28 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 ); |
|
| 29 | - |
|
| 30 | - // Remove metaboxes. |
|
| 31 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 ); |
|
| 32 | - |
|
| 33 | - // Rename metaboxes. |
|
| 34 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 ); |
|
| 35 | - |
|
| 36 | - // Save metaboxes. |
|
| 37 | - add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 ); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Register core metaboxes. |
|
| 42 | - */ |
|
| 43 | - public static function add_meta_boxes( $post_type, $post ) { |
|
| 16 | + * Only save metaboxes once. |
|
| 17 | + * |
|
| 18 | + * @var boolean |
|
| 19 | + */ |
|
| 20 | + private static $saved_meta_boxes = false; |
|
| 44 | 21 | |
| 45 | - // For invoices... |
|
| 46 | - self::add_invoice_meta_boxes( $post_type, $post ); |
|
| 47 | - |
|
| 48 | - // For payment forms. |
|
| 49 | - self::add_payment_form_meta_boxes( $post_type ); |
|
| 50 | - |
|
| 51 | - // For invoice items. |
|
| 52 | - self::add_item_meta_boxes( $post_type ); |
|
| 53 | - |
|
| 54 | - // For invoice discounts. |
|
| 55 | - if ( $post_type == 'wpi_discount' ) { |
|
| 56 | - add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' ); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - } |
|
| 22 | + /** |
|
| 23 | + * Hook in methods. |
|
| 24 | + */ |
|
| 25 | + public static function init() { |
|
| 60 | 26 | |
| 61 | - /** |
|
| 62 | - * Register core metaboxes. |
|
| 63 | - */ |
|
| 64 | - protected static function add_payment_form_meta_boxes( $post_type ) { |
|
| 27 | + // Register metaboxes. |
|
| 28 | + add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 ); |
|
| 65 | 29 | |
| 66 | - // For payment forms. |
|
| 67 | - if ( $post_type == 'wpi_payment_form' ) { |
|
| 30 | + // Remove metaboxes. |
|
| 31 | + add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 ); |
|
| 68 | 32 | |
| 69 | - // Design payment form. |
|
| 70 | - add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
|
| 33 | + // Rename metaboxes. |
|
| 34 | + add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 ); |
|
| 71 | 35 | |
| 72 | - // Payment form information. |
|
| 73 | - add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' ); |
|
| 36 | + // Save metaboxes. |
|
| 37 | + add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 ); |
|
| 38 | + } |
|
| 74 | 39 | |
| 75 | - } |
|
| 40 | + /** |
|
| 41 | + * Register core metaboxes. |
|
| 42 | + */ |
|
| 43 | + public static function add_meta_boxes( $post_type, $post ) { |
|
| 76 | 44 | |
| 77 | - } |
|
| 45 | + // For invoices... |
|
| 46 | + self::add_invoice_meta_boxes( $post_type, $post ); |
|
| 78 | 47 | |
| 79 | - /** |
|
| 80 | - * Register core metaboxes. |
|
| 81 | - */ |
|
| 82 | - protected static function add_item_meta_boxes( $post_type ) { |
|
| 48 | + // For payment forms. |
|
| 49 | + self::add_payment_form_meta_boxes( $post_type ); |
|
| 83 | 50 | |
| 84 | - if ( $post_type == 'wpi_item' ) { |
|
| 51 | + // For invoice items. |
|
| 52 | + self::add_item_meta_boxes( $post_type ); |
|
| 85 | 53 | |
| 86 | - // Item details. |
|
| 87 | - add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' ); |
|
| 54 | + // For invoice discounts. |
|
| 55 | + if ( $post_type == 'wpi_discount' ) { |
|
| 56 | + add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' ); |
|
| 57 | + } |
|
| 88 | 58 | |
| 89 | - // If taxes are enabled, register the tax metabox. |
|
| 90 | - if ( wpinv_use_taxes() ) { |
|
| 91 | - add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' ); |
|
| 92 | - } |
|
| 59 | + } |
|
| 93 | 60 | |
| 94 | - // Item info. |
|
| 95 | - add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' ); |
|
| 61 | + /** |
|
| 62 | + * Register core metaboxes. |
|
| 63 | + */ |
|
| 64 | + protected static function add_payment_form_meta_boxes( $post_type ) { |
|
| 96 | 65 | |
| 97 | - } |
|
| 66 | + // For payment forms. |
|
| 67 | + if ( $post_type == 'wpi_payment_form' ) { |
|
| 98 | 68 | |
| 99 | - } |
|
| 69 | + // Design payment form. |
|
| 70 | + add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
|
| 100 | 71 | |
| 101 | - /** |
|
| 102 | - * Register invoice metaboxes. |
|
| 103 | - */ |
|
| 104 | - protected static function add_invoice_meta_boxes( $post_type, $post ) { |
|
| 72 | + // Payment form information. |
|
| 73 | + add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' ); |
|
| 105 | 74 | |
| 106 | - // For invoices... |
|
| 107 | - if ( getpaid_is_invoice_post_type( $post_type ) ) { |
|
| 108 | - $invoice = new WPInv_Invoice( $post ); |
|
| 75 | + } |
|
| 109 | 76 | |
| 110 | - // Resend invoice. |
|
| 111 | - if ( ! $invoice->is_draft() ) { |
|
| 77 | + } |
|
| 112 | 78 | |
| 113 | - add_meta_box( |
|
| 114 | - 'wpinv-mb-resend-invoice', |
|
| 115 | - sprintf( |
|
| 116 | - __( 'Resend %s', 'invoicing' ), |
|
| 117 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 118 | - ), |
|
| 119 | - 'GetPaid_Meta_Box_Resend_Invoice::output', |
|
| 120 | - $post_type, |
|
| 121 | - 'side', |
|
| 122 | - 'low' |
|
| 123 | - ); |
|
| 79 | + /** |
|
| 80 | + * Register core metaboxes. |
|
| 81 | + */ |
|
| 82 | + protected static function add_item_meta_boxes( $post_type ) { |
|
| 124 | 83 | |
| 125 | - } |
|
| 84 | + if ( $post_type == 'wpi_item' ) { |
|
| 126 | 85 | |
| 127 | - // Subscriptions. |
|
| 128 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
| 129 | - if ( ! empty( $subscriptions ) ) { |
|
| 86 | + // Item details. |
|
| 87 | + add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' ); |
|
| 130 | 88 | |
| 131 | - if ( is_array( $subscriptions ) ) { |
|
| 132 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' ); |
|
| 133 | - } else { |
|
| 134 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' ); |
|
| 135 | - } |
|
| 89 | + // If taxes are enabled, register the tax metabox. |
|
| 90 | + if ( wpinv_use_taxes() ) { |
|
| 91 | + add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' ); |
|
| 92 | + } |
|
| 136 | 93 | |
| 137 | - if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) { |
|
| 138 | - add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' ); |
|
| 139 | - } |
|
| 94 | + // Item info. |
|
| 95 | + add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' ); |
|
| 140 | 96 | |
| 141 | - } |
|
| 97 | + } |
|
| 142 | 98 | |
| 143 | - // Invoice details. |
|
| 144 | - add_meta_box( |
|
| 145 | - 'wpinv-details', |
|
| 146 | - sprintf( |
|
| 147 | - __( '%s Details', 'invoicing' ), |
|
| 148 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 149 | - ), |
|
| 150 | - 'GetPaid_Meta_Box_Invoice_Details::output', |
|
| 151 | - $post_type, |
|
| 152 | - 'side' |
|
| 153 | - ); |
|
| 154 | - |
|
| 155 | - // Payment details. |
|
| 156 | - if ( ! $invoice->is_draft() ) { |
|
| 157 | - add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' ); |
|
| 158 | - } |
|
| 99 | + } |
|
| 159 | 100 | |
| 160 | - // Billing details. |
|
| 161 | - add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' ); |
|
| 101 | + /** |
|
| 102 | + * Register invoice metaboxes. |
|
| 103 | + */ |
|
| 104 | + protected static function add_invoice_meta_boxes( $post_type, $post ) { |
|
| 105 | + |
|
| 106 | + // For invoices... |
|
| 107 | + if ( getpaid_is_invoice_post_type( $post_type ) ) { |
|
| 108 | + $invoice = new WPInv_Invoice( $post ); |
|
| 109 | + |
|
| 110 | + // Resend invoice. |
|
| 111 | + if ( ! $invoice->is_draft() ) { |
|
| 112 | + |
|
| 113 | + add_meta_box( |
|
| 114 | + 'wpinv-mb-resend-invoice', |
|
| 115 | + sprintf( |
|
| 116 | + __( 'Resend %s', 'invoicing' ), |
|
| 117 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 118 | + ), |
|
| 119 | + 'GetPaid_Meta_Box_Resend_Invoice::output', |
|
| 120 | + $post_type, |
|
| 121 | + 'side', |
|
| 122 | + 'low' |
|
| 123 | + ); |
|
| 124 | + |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + // Subscriptions. |
|
| 128 | + $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
| 129 | + if ( ! empty( $subscriptions ) ) { |
|
| 130 | + |
|
| 131 | + if ( is_array( $subscriptions ) ) { |
|
| 132 | + add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' ); |
|
| 133 | + } else { |
|
| 134 | + add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' ); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) { |
|
| 138 | + add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' ); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + // Invoice details. |
|
| 144 | + add_meta_box( |
|
| 145 | + 'wpinv-details', |
|
| 146 | + sprintf( |
|
| 147 | + __( '%s Details', 'invoicing' ), |
|
| 148 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 149 | + ), |
|
| 150 | + 'GetPaid_Meta_Box_Invoice_Details::output', |
|
| 151 | + $post_type, |
|
| 152 | + 'side' |
|
| 153 | + ); |
|
| 154 | + |
|
| 155 | + // Payment details. |
|
| 156 | + if ( ! $invoice->is_draft() ) { |
|
| 157 | + add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' ); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + // Billing details. |
|
| 161 | + add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' ); |
|
| 162 | 162 | |
| 163 | - // Invoice items. |
|
| 164 | - add_meta_box( |
|
| 165 | - 'wpinv-items', |
|
| 166 | - sprintf( |
|
| 167 | - __( '%s Items', 'invoicing' ), |
|
| 168 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 169 | - ), |
|
| 170 | - 'GetPaid_Meta_Box_Invoice_Items::output', |
|
| 171 | - $post_type, |
|
| 172 | - 'normal', |
|
| 173 | - 'high' |
|
| 174 | - ); |
|
| 163 | + // Invoice items. |
|
| 164 | + add_meta_box( |
|
| 165 | + 'wpinv-items', |
|
| 166 | + sprintf( |
|
| 167 | + __( '%s Items', 'invoicing' ), |
|
| 168 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 169 | + ), |
|
| 170 | + 'GetPaid_Meta_Box_Invoice_Items::output', |
|
| 171 | + $post_type, |
|
| 172 | + 'normal', |
|
| 173 | + 'high' |
|
| 174 | + ); |
|
| 175 | 175 | |
| 176 | - // Invoice notes. |
|
| 177 | - add_meta_box( |
|
| 178 | - 'wpinv-notes', |
|
| 179 | - sprintf( |
|
| 180 | - __( '%s Notes', 'invoicing' ), |
|
| 181 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 182 | - ), |
|
| 183 | - 'WPInv_Meta_Box_Notes::output', |
|
| 184 | - $post_type, |
|
| 185 | - 'side', |
|
| 186 | - 'low' |
|
| 187 | - ); |
|
| 188 | - |
|
| 189 | - // Shipping Address. |
|
| 190 | - if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) { |
|
| 191 | - add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' ); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - // Payment form information. |
|
| 195 | - if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) { |
|
| 196 | - add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' ); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * Remove some metaboxes. |
|
| 205 | - */ |
|
| 206 | - public static function remove_meta_boxes() { |
|
| 207 | - remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' ); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * Rename other metaboxes. |
|
| 212 | - */ |
|
| 213 | - public static function rename_meta_boxes() { |
|
| 176 | + // Invoice notes. |
|
| 177 | + add_meta_box( |
|
| 178 | + 'wpinv-notes', |
|
| 179 | + sprintf( |
|
| 180 | + __( '%s Notes', 'invoicing' ), |
|
| 181 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 182 | + ), |
|
| 183 | + 'WPInv_Meta_Box_Notes::output', |
|
| 184 | + $post_type, |
|
| 185 | + 'side', |
|
| 186 | + 'low' |
|
| 187 | + ); |
|
| 188 | + |
|
| 189 | + // Shipping Address. |
|
| 190 | + if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) { |
|
| 191 | + add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' ); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + // Payment form information. |
|
| 195 | + if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) { |
|
| 196 | + add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' ); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * Remove some metaboxes. |
|
| 205 | + */ |
|
| 206 | + public static function remove_meta_boxes() { |
|
| 207 | + remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' ); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * Rename other metaboxes. |
|
| 212 | + */ |
|
| 213 | + public static function rename_meta_boxes() { |
|
| 214 | 214 | |
| 215 | - } |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * Check if we're saving, then trigger an action based on the post type. |
|
| 219 | - * |
|
| 220 | - * @param int $post_id Post ID. |
|
| 221 | - * @param object $post Post object. |
|
| 222 | - */ |
|
| 223 | - public static function save_meta_boxes( $post_id, $post ) { |
|
| 224 | - $post_id = absint( $post_id ); |
|
| 225 | - $data = wp_unslash( $_POST ); |
|
| 226 | - |
|
| 227 | - // Do not save for ajax requests. |
|
| 228 | - if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
| 229 | - return; |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - // $post_id and $post are required |
|
| 233 | - if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { |
|
| 234 | - return; |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - // Dont' save meta boxes for revisions or autosaves. |
|
| 238 | - if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
| 239 | - return; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - // Check the nonce. |
|
| 243 | - if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) { |
|
| 244 | - return; |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - // Check the post being saved == the $post_id to prevent triggering this call for other save_post events. |
|
| 248 | - if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) { |
|
| 249 | - return; |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - // Check user has permission to edit. |
|
| 253 | - if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
| 254 | - return; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
| 258 | - |
|
| 259 | - // We need this save event to run once to avoid potential endless loops. |
|
| 260 | - self::$saved_meta_boxes = true; |
|
| 261 | - |
|
| 262 | - return GetPaid_Meta_Box_Invoice_Address::save( $post_id ); |
|
| 263 | - |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - // Ensure this is our post type. |
|
| 267 | - $post_types_map = array( |
|
| 268 | - 'wpi_item' => 'GetPaid_Meta_Box_Item_Details', |
|
| 269 | - 'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form', |
|
| 270 | - 'wpi_discount' => 'GetPaid_Meta_Box_Discount_Details', |
|
| 271 | - ); |
|
| 272 | - |
|
| 273 | - // Is this our post type? |
|
| 274 | - if ( ! isset( $post_types_map[ $post->post_type ] ) ) { |
|
| 275 | - return; |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - // We need this save event to run once to avoid potential endless loops. |
|
| 279 | - self::$saved_meta_boxes = true; |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * Check if we're saving, then trigger an action based on the post type. |
|
| 219 | + * |
|
| 220 | + * @param int $post_id Post ID. |
|
| 221 | + * @param object $post Post object. |
|
| 222 | + */ |
|
| 223 | + public static function save_meta_boxes( $post_id, $post ) { |
|
| 224 | + $post_id = absint( $post_id ); |
|
| 225 | + $data = wp_unslash( $_POST ); |
|
| 226 | + |
|
| 227 | + // Do not save for ajax requests. |
|
| 228 | + if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
| 229 | + return; |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + // $post_id and $post are required |
|
| 233 | + if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { |
|
| 234 | + return; |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + // Dont' save meta boxes for revisions or autosaves. |
|
| 238 | + if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
| 239 | + return; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + // Check the nonce. |
|
| 243 | + if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) { |
|
| 244 | + return; |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + // Check the post being saved == the $post_id to prevent triggering this call for other save_post events. |
|
| 248 | + if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) { |
|
| 249 | + return; |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + // Check user has permission to edit. |
|
| 253 | + if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
| 254 | + return; |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
| 258 | + |
|
| 259 | + // We need this save event to run once to avoid potential endless loops. |
|
| 260 | + self::$saved_meta_boxes = true; |
|
| 261 | + |
|
| 262 | + return GetPaid_Meta_Box_Invoice_Address::save( $post_id ); |
|
| 263 | + |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + // Ensure this is our post type. |
|
| 267 | + $post_types_map = array( |
|
| 268 | + 'wpi_item' => 'GetPaid_Meta_Box_Item_Details', |
|
| 269 | + 'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form', |
|
| 270 | + 'wpi_discount' => 'GetPaid_Meta_Box_Discount_Details', |
|
| 271 | + ); |
|
| 272 | + |
|
| 273 | + // Is this our post type? |
|
| 274 | + if ( ! isset( $post_types_map[ $post->post_type ] ) ) { |
|
| 275 | + return; |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + // We need this save event to run once to avoid potential endless loops. |
|
| 279 | + self::$saved_meta_boxes = true; |
|
| 280 | 280 | |
| 281 | - // Save the post. |
|
| 282 | - $class = $post_types_map[ $post->post_type ]; |
|
| 283 | - $class::save( $post_id, $_POST, $post ); |
|
| 281 | + // Save the post. |
|
| 282 | + $class = $post_types_map[ $post->post_type ]; |
|
| 283 | + $class::save( $post_id, $_POST, $post ); |
|
| 284 | 284 | |
| 285 | - } |
|
| 285 | + } |
|
| 286 | 286 | |
| 287 | 287 | } |
@@ -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 | * Metaboxes Admin Class |
@@ -25,35 +25,35 @@ discard block |
||
| 25 | 25 | public static function init() { |
| 26 | 26 | |
| 27 | 27 | // Register metaboxes. |
| 28 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 ); |
|
| 28 | + add_action('add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2); |
|
| 29 | 29 | |
| 30 | 30 | // Remove metaboxes. |
| 31 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 ); |
|
| 31 | + add_action('add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30); |
|
| 32 | 32 | |
| 33 | 33 | // Rename metaboxes. |
| 34 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 ); |
|
| 34 | + add_action('add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45); |
|
| 35 | 35 | |
| 36 | 36 | // Save metaboxes. |
| 37 | - add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 ); |
|
| 37 | + add_action('save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** |
| 41 | 41 | * Register core metaboxes. |
| 42 | 42 | */ |
| 43 | - public static function add_meta_boxes( $post_type, $post ) { |
|
| 43 | + public static function add_meta_boxes($post_type, $post) { |
|
| 44 | 44 | |
| 45 | 45 | // For invoices... |
| 46 | - self::add_invoice_meta_boxes( $post_type, $post ); |
|
| 46 | + self::add_invoice_meta_boxes($post_type, $post); |
|
| 47 | 47 | |
| 48 | 48 | // For payment forms. |
| 49 | - self::add_payment_form_meta_boxes( $post_type ); |
|
| 49 | + self::add_payment_form_meta_boxes($post_type); |
|
| 50 | 50 | |
| 51 | 51 | // For invoice items. |
| 52 | - self::add_item_meta_boxes( $post_type ); |
|
| 52 | + self::add_item_meta_boxes($post_type); |
|
| 53 | 53 | |
| 54 | 54 | // For invoice discounts. |
| 55 | - if ( $post_type == 'wpi_discount' ) { |
|
| 56 | - add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' ); |
|
| 55 | + if ($post_type == 'wpi_discount') { |
|
| 56 | + add_meta_box('wpinv_discount_details', __('Discount Details', 'invoicing'), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high'); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | } |
@@ -61,16 +61,16 @@ discard block |
||
| 61 | 61 | /** |
| 62 | 62 | * Register core metaboxes. |
| 63 | 63 | */ |
| 64 | - protected static function add_payment_form_meta_boxes( $post_type ) { |
|
| 64 | + protected static function add_payment_form_meta_boxes($post_type) { |
|
| 65 | 65 | |
| 66 | 66 | // For payment forms. |
| 67 | - if ( $post_type == 'wpi_payment_form' ) { |
|
| 67 | + if ($post_type == 'wpi_payment_form') { |
|
| 68 | 68 | |
| 69 | 69 | // Design payment form. |
| 70 | - add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
|
| 70 | + add_meta_box('wpinv-payment-form-design', __('Payment Form', 'invoicing'), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal'); |
|
| 71 | 71 | |
| 72 | 72 | // Payment form information. |
| 73 | - add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' ); |
|
| 73 | + add_meta_box('wpinv-payment-form-info', __('Details', 'invoicing'), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side'); |
|
| 74 | 74 | |
| 75 | 75 | } |
| 76 | 76 | |
@@ -79,20 +79,20 @@ discard block |
||
| 79 | 79 | /** |
| 80 | 80 | * Register core metaboxes. |
| 81 | 81 | */ |
| 82 | - protected static function add_item_meta_boxes( $post_type ) { |
|
| 82 | + protected static function add_item_meta_boxes($post_type) { |
|
| 83 | 83 | |
| 84 | - if ( $post_type == 'wpi_item' ) { |
|
| 84 | + if ($post_type == 'wpi_item') { |
|
| 85 | 85 | |
| 86 | 86 | // Item details. |
| 87 | - add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' ); |
|
| 87 | + add_meta_box('wpinv_item_details', __('Item Details', 'invoicing'), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high'); |
|
| 88 | 88 | |
| 89 | 89 | // If taxes are enabled, register the tax metabox. |
| 90 | - if ( wpinv_use_taxes() ) { |
|
| 91 | - add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' ); |
|
| 90 | + if (wpinv_use_taxes()) { |
|
| 91 | + add_meta_box('wpinv_item_vat', __('Tax', 'invoicing'), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high'); |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | // Item info. |
| 95 | - add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' ); |
|
| 95 | + add_meta_box('wpinv_field_item_info', __('Item info', 'invoicing'), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core'); |
|
| 96 | 96 | |
| 97 | 97 | } |
| 98 | 98 | |
@@ -101,20 +101,20 @@ discard block |
||
| 101 | 101 | /** |
| 102 | 102 | * Register invoice metaboxes. |
| 103 | 103 | */ |
| 104 | - protected static function add_invoice_meta_boxes( $post_type, $post ) { |
|
| 104 | + protected static function add_invoice_meta_boxes($post_type, $post) { |
|
| 105 | 105 | |
| 106 | 106 | // For invoices... |
| 107 | - if ( getpaid_is_invoice_post_type( $post_type ) ) { |
|
| 108 | - $invoice = new WPInv_Invoice( $post ); |
|
| 107 | + if (getpaid_is_invoice_post_type($post_type)) { |
|
| 108 | + $invoice = new WPInv_Invoice($post); |
|
| 109 | 109 | |
| 110 | 110 | // Resend invoice. |
| 111 | - if ( ! $invoice->is_draft() ) { |
|
| 111 | + if (!$invoice->is_draft()) { |
|
| 112 | 112 | |
| 113 | 113 | add_meta_box( |
| 114 | 114 | 'wpinv-mb-resend-invoice', |
| 115 | 115 | sprintf( |
| 116 | - __( 'Resend %s', 'invoicing' ), |
|
| 117 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 116 | + __('Resend %s', 'invoicing'), |
|
| 117 | + ucfirst($invoice->get_invoice_quote_type()) |
|
| 118 | 118 | ), |
| 119 | 119 | 'GetPaid_Meta_Box_Resend_Invoice::output', |
| 120 | 120 | $post_type, |
@@ -125,17 +125,17 @@ discard block |
||
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | // Subscriptions. |
| 128 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
| 129 | - if ( ! empty( $subscriptions ) ) { |
|
| 128 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
| 129 | + if (!empty($subscriptions)) { |
|
| 130 | 130 | |
| 131 | - if ( is_array( $subscriptions ) ) { |
|
| 132 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' ); |
|
| 131 | + if (is_array($subscriptions)) { |
|
| 132 | + add_meta_box('wpinv-mb-subscriptions', __('Related Subscriptions', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced'); |
|
| 133 | 133 | } else { |
| 134 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' ); |
|
| 134 | + add_meta_box('wpinv-mb-subscriptions', __('Subscription Details', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced'); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) { |
|
| 138 | - add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' ); |
|
| 137 | + if (getpaid_count_subscription_invoices($invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id()) > 1) { |
|
| 138 | + add_meta_box('wpinv-mb-subscription-invoices', __('Related Payments', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced'); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | } |
@@ -144,8 +144,8 @@ discard block |
||
| 144 | 144 | add_meta_box( |
| 145 | 145 | 'wpinv-details', |
| 146 | 146 | sprintf( |
| 147 | - __( '%s Details', 'invoicing' ), |
|
| 148 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 147 | + __('%s Details', 'invoicing'), |
|
| 148 | + ucfirst($invoice->get_invoice_quote_type()) |
|
| 149 | 149 | ), |
| 150 | 150 | 'GetPaid_Meta_Box_Invoice_Details::output', |
| 151 | 151 | $post_type, |
@@ -153,19 +153,19 @@ discard block |
||
| 153 | 153 | ); |
| 154 | 154 | |
| 155 | 155 | // Payment details. |
| 156 | - if ( ! $invoice->is_draft() ) { |
|
| 157 | - add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' ); |
|
| 156 | + if (!$invoice->is_draft()) { |
|
| 157 | + add_meta_box('wpinv-payment-meta', __('Payment Meta', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default'); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | // Billing details. |
| 161 | - add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' ); |
|
| 161 | + add_meta_box('wpinv-address', __('Billing Details', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high'); |
|
| 162 | 162 | |
| 163 | 163 | // Invoice items. |
| 164 | 164 | add_meta_box( |
| 165 | 165 | 'wpinv-items', |
| 166 | 166 | sprintf( |
| 167 | - __( '%s Items', 'invoicing' ), |
|
| 168 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 167 | + __('%s Items', 'invoicing'), |
|
| 168 | + ucfirst($invoice->get_invoice_quote_type()) |
|
| 169 | 169 | ), |
| 170 | 170 | 'GetPaid_Meta_Box_Invoice_Items::output', |
| 171 | 171 | $post_type, |
@@ -177,8 +177,8 @@ discard block |
||
| 177 | 177 | add_meta_box( |
| 178 | 178 | 'wpinv-notes', |
| 179 | 179 | sprintf( |
| 180 | - __( '%s Notes', 'invoicing' ), |
|
| 181 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 180 | + __('%s Notes', 'invoicing'), |
|
| 181 | + ucfirst($invoice->get_invoice_quote_type()) |
|
| 182 | 182 | ), |
| 183 | 183 | 'WPInv_Meta_Box_Notes::output', |
| 184 | 184 | $post_type, |
@@ -187,13 +187,13 @@ discard block |
||
| 187 | 187 | ); |
| 188 | 188 | |
| 189 | 189 | // Shipping Address. |
| 190 | - if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) { |
|
| 191 | - add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' ); |
|
| 190 | + if (get_post_meta($invoice->get_id(), 'shipping_address', true)) { |
|
| 191 | + add_meta_box('wpinv-invoice-shipping-details', __('Shipping Address', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high'); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | // Payment form information. |
| 195 | - if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) { |
|
| 196 | - add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' ); |
|
| 195 | + if (get_post_meta($invoice->get_id(), 'payment_form_data', true)) { |
|
| 196 | + add_meta_box('wpinv-invoice-payment-form-details', __('Payment Form Details', 'invoicing'), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high'); |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | } |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | * Remove some metaboxes. |
| 205 | 205 | */ |
| 206 | 206 | public static function remove_meta_boxes() { |
| 207 | - remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' ); |
|
| 207 | + remove_meta_box('wpseo_meta', 'wpi_invoice', 'normal'); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | /** |
@@ -220,46 +220,46 @@ discard block |
||
| 220 | 220 | * @param int $post_id Post ID. |
| 221 | 221 | * @param object $post Post object. |
| 222 | 222 | */ |
| 223 | - public static function save_meta_boxes( $post_id, $post ) { |
|
| 224 | - $post_id = absint( $post_id ); |
|
| 225 | - $data = wp_unslash( $_POST ); |
|
| 223 | + public static function save_meta_boxes($post_id, $post) { |
|
| 224 | + $post_id = absint($post_id); |
|
| 225 | + $data = wp_unslash($_POST); |
|
| 226 | 226 | |
| 227 | 227 | // Do not save for ajax requests. |
| 228 | - if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
| 228 | + if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) { |
|
| 229 | 229 | return; |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | // $post_id and $post are required |
| 233 | - if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { |
|
| 233 | + if (empty($post_id) || empty($post) || self::$saved_meta_boxes) { |
|
| 234 | 234 | return; |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | // Dont' save meta boxes for revisions or autosaves. |
| 238 | - if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
| 238 | + if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) { |
|
| 239 | 239 | return; |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | // Check the nonce. |
| 243 | - if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) { |
|
| 243 | + if (empty($data['getpaid_meta_nonce']) || !wp_verify_nonce($data['getpaid_meta_nonce'], 'getpaid_meta_nonce')) { |
|
| 244 | 244 | return; |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | // Check the post being saved == the $post_id to prevent triggering this call for other save_post events. |
| 248 | - if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) { |
|
| 248 | + if (empty($data['post_ID']) || absint($data['post_ID']) !== $post_id) { |
|
| 249 | 249 | return; |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | // Check user has permission to edit. |
| 253 | - if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
| 253 | + if (!current_user_can('edit_post', $post_id)) { |
|
| 254 | 254 | return; |
| 255 | 255 | } |
| 256 | 256 | |
| 257 | - if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
| 257 | + if (getpaid_is_invoice_post_type($post->post_type)) { |
|
| 258 | 258 | |
| 259 | 259 | // We need this save event to run once to avoid potential endless loops. |
| 260 | 260 | self::$saved_meta_boxes = true; |
| 261 | 261 | |
| 262 | - return GetPaid_Meta_Box_Invoice_Address::save( $post_id ); |
|
| 262 | + return GetPaid_Meta_Box_Invoice_Address::save($post_id); |
|
| 263 | 263 | |
| 264 | 264 | } |
| 265 | 265 | |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | ); |
| 272 | 272 | |
| 273 | 273 | // Is this our post type? |
| 274 | - if ( ! isset( $post_types_map[ $post->post_type ] ) ) { |
|
| 274 | + if (!isset($post_types_map[$post->post_type])) { |
|
| 275 | 275 | return; |
| 276 | 276 | } |
| 277 | 277 | |
@@ -279,8 +279,8 @@ discard block |
||
| 279 | 279 | self::$saved_meta_boxes = true; |
| 280 | 280 | |
| 281 | 281 | // Save the post. |
| 282 | - $class = $post_types_map[ $post->post_type ]; |
|
| 283 | - $class::save( $post_id, $_POST, $post ); |
|
| 282 | + $class = $post_types_map[$post->post_type]; |
|
| 283 | + $class::save($post_id, $_POST, $post); |
|
| 284 | 284 | |
| 285 | 285 | } |
| 286 | 286 | |
@@ -4,99 +4,99 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -defined( 'ABSPATH' ) || exit; |
|
| 7 | +defined('ABSPATH') || exit; |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Displays an invoice. |
| 11 | 11 | * |
| 12 | 12 | * @param WPInv_Invoice $invoice. |
| 13 | 13 | */ |
| 14 | -function getpaid_invoice( $invoice ) { |
|
| 15 | - if ( ! empty( $invoice ) ) { |
|
| 16 | - wpinv_get_template( 'invoice/invoice.php', compact( 'invoice' ) ); |
|
| 14 | +function getpaid_invoice($invoice) { |
|
| 15 | + if (!empty($invoice)) { |
|
| 16 | + wpinv_get_template('invoice/invoice.php', compact('invoice')); |
|
| 17 | 17 | } |
| 18 | 18 | } |
| 19 | -add_action( 'getpaid_invoice', 'getpaid_invoice', 10 ); |
|
| 19 | +add_action('getpaid_invoice', 'getpaid_invoice', 10); |
|
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | 22 | * Displays the invoice footer. |
| 23 | 23 | */ |
| 24 | -function getpaid_invoice_footer( $invoice ) { |
|
| 25 | - if ( ! empty( $invoice ) ) { |
|
| 26 | - wpinv_get_template( 'invoice/footer.php', compact( 'invoice' ) ); |
|
| 24 | +function getpaid_invoice_footer($invoice) { |
|
| 25 | + if (!empty($invoice)) { |
|
| 26 | + wpinv_get_template('invoice/footer.php', compact('invoice')); |
|
| 27 | 27 | } |
| 28 | 28 | } |
| 29 | -add_action( 'getpaid_invoice_footer', 'getpaid_invoice_footer', 10 ); |
|
| 29 | +add_action('getpaid_invoice_footer', 'getpaid_invoice_footer', 10); |
|
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | 32 | * Displays the invoice top bar. |
| 33 | 33 | */ |
| 34 | -function getpaid_invoice_header( $invoice ) { |
|
| 35 | - if ( ! empty( $invoice ) ) { |
|
| 36 | - wpinv_get_template( 'invoice/header.php', compact( 'invoice' ) ); |
|
| 34 | +function getpaid_invoice_header($invoice) { |
|
| 35 | + if (!empty($invoice)) { |
|
| 36 | + wpinv_get_template('invoice/header.php', compact('invoice')); |
|
| 37 | 37 | } |
| 38 | 38 | } |
| 39 | -add_action( 'getpaid_invoice_header', 'getpaid_invoice_header', 10 ); |
|
| 39 | +add_action('getpaid_invoice_header', 'getpaid_invoice_header', 10); |
|
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | 42 | * Displays actions on the left side of the header. |
| 43 | 43 | */ |
| 44 | -function getpaid_invoice_header_left_actions( $invoice ) { |
|
| 45 | - if ( ! empty( $invoice ) ) { |
|
| 46 | - wpinv_get_template( 'invoice/header-left-actions.php', compact( 'invoice' ) ); |
|
| 44 | +function getpaid_invoice_header_left_actions($invoice) { |
|
| 45 | + if (!empty($invoice)) { |
|
| 46 | + wpinv_get_template('invoice/header-left-actions.php', compact('invoice')); |
|
| 47 | 47 | } |
| 48 | 48 | } |
| 49 | -add_action( 'getpaid_invoice_header_left', 'getpaid_invoice_header_left_actions', 10 ); |
|
| 49 | +add_action('getpaid_invoice_header_left', 'getpaid_invoice_header_left_actions', 10); |
|
| 50 | 50 | |
| 51 | 51 | /** |
| 52 | 52 | * Displays actions on the right side of the invoice top bar. |
| 53 | 53 | */ |
| 54 | -function getpaid_invoice_header_right_actions( $invoice ) { |
|
| 55 | - if ( ! empty( $invoice ) ) { |
|
| 56 | - wpinv_get_template( 'invoice/header-right-actions.php', compact( 'invoice' ) ); |
|
| 54 | +function getpaid_invoice_header_right_actions($invoice) { |
|
| 55 | + if (!empty($invoice)) { |
|
| 56 | + wpinv_get_template('invoice/header-right-actions.php', compact('invoice')); |
|
| 57 | 57 | } |
| 58 | 58 | } |
| 59 | -add_action( 'getpaid_invoice_header_right', 'getpaid_invoice_header_right_actions', 10 ); |
|
| 59 | +add_action('getpaid_invoice_header_right', 'getpaid_invoice_header_right_actions', 10); |
|
| 60 | 60 | |
| 61 | 61 | /** |
| 62 | 62 | * Displays the invoice title, logo etc. |
| 63 | 63 | */ |
| 64 | -function getpaid_invoice_details_top( $invoice ) { |
|
| 65 | - if ( ! empty( $invoice ) ) { |
|
| 66 | - wpinv_get_template( 'invoice/details-top.php', compact( 'invoice' ) ); |
|
| 64 | +function getpaid_invoice_details_top($invoice) { |
|
| 65 | + if (!empty($invoice)) { |
|
| 66 | + wpinv_get_template('invoice/details-top.php', compact('invoice')); |
|
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | -add_action( 'getpaid_invoice_details', 'getpaid_invoice_details_top', 10 ); |
|
| 69 | +add_action('getpaid_invoice_details', 'getpaid_invoice_details_top', 10); |
|
| 70 | 70 | |
| 71 | 71 | /** |
| 72 | 72 | * Displays the company logo. |
| 73 | 73 | */ |
| 74 | -function getpaid_invoice_logo( $invoice ) { |
|
| 75 | - if ( ! empty( $invoice ) ) { |
|
| 76 | - wpinv_get_template( 'invoice/invoice-logo.php', compact( 'invoice' ) ); |
|
| 74 | +function getpaid_invoice_logo($invoice) { |
|
| 75 | + if (!empty($invoice)) { |
|
| 76 | + wpinv_get_template('invoice/invoice-logo.php', compact('invoice')); |
|
| 77 | 77 | } |
| 78 | 78 | } |
| 79 | -add_action( 'getpaid_invoice_details_top_left', 'getpaid_invoice_logo' ); |
|
| 79 | +add_action('getpaid_invoice_details_top_left', 'getpaid_invoice_logo'); |
|
| 80 | 80 | |
| 81 | 81 | /** |
| 82 | 82 | * Displays the type of invoice. |
| 83 | 83 | */ |
| 84 | -function getpaid_invoice_type( $invoice ) { |
|
| 85 | - if ( ! empty( $invoice ) ) { |
|
| 86 | - wpinv_get_template( 'invoice/invoice-type.php', compact( 'invoice' ) ); |
|
| 84 | +function getpaid_invoice_type($invoice) { |
|
| 85 | + if (!empty($invoice)) { |
|
| 86 | + wpinv_get_template('invoice/invoice-type.php', compact('invoice')); |
|
| 87 | 87 | } |
| 88 | 88 | } |
| 89 | -add_action( 'getpaid_invoice_details_top_right', 'getpaid_invoice_type' ); |
|
| 89 | +add_action('getpaid_invoice_details_top_right', 'getpaid_invoice_type'); |
|
| 90 | 90 | |
| 91 | 91 | /** |
| 92 | 92 | * Displays the invoice details. |
| 93 | 93 | */ |
| 94 | -function getpaid_invoice_details_main( $invoice ) { |
|
| 95 | - if ( ! empty( $invoice ) ) { |
|
| 96 | - wpinv_get_template( 'invoice/details.php', compact( 'invoice' ) ); |
|
| 94 | +function getpaid_invoice_details_main($invoice) { |
|
| 95 | + if (!empty($invoice)) { |
|
| 96 | + wpinv_get_template('invoice/details.php', compact('invoice')); |
|
| 97 | 97 | } |
| 98 | 98 | } |
| 99 | -add_action( 'getpaid_invoice_details', 'getpaid_invoice_details_main', 50 ); |
|
| 99 | +add_action('getpaid_invoice_details', 'getpaid_invoice_details_main', 50); |
|
| 100 | 100 | |
| 101 | 101 | /** |
| 102 | 102 | * Returns a path to the templates directory. |
@@ -125,8 +125,8 @@ discard block |
||
| 125 | 125 | * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'. |
| 126 | 126 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
| 127 | 127 | */ |
| 128 | -function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
| 129 | - getpaid_template()->display_template( $template_name, $args, $template_path, $default_path ); |
|
| 128 | +function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
| 129 | + getpaid_template()->display_template($template_name, $args, $template_path, $default_path); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | /** |
@@ -139,8 +139,8 @@ discard block |
||
| 139 | 139 | * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'. |
| 140 | 140 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
| 141 | 141 | */ |
| 142 | -function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
| 143 | - return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path ); |
|
| 142 | +function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
| 143 | + return getpaid_template()->get_template($template_name, $args, $template_path, $default_path); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | * @return string |
| 150 | 150 | */ |
| 151 | 151 | function wpinv_template_path() { |
| 152 | - return apply_filters( 'wpinv_template_path', wpinv_get_theme_template_dir_name() ); |
|
| 152 | + return apply_filters('wpinv_template_path', wpinv_get_theme_template_dir_name()); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | /** |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | * @return string |
| 159 | 159 | */ |
| 160 | 160 | function wpinv_get_theme_template_dir_name() { |
| 161 | - return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
| 161 | + return trailingslashit(apply_filters('wpinv_templates_dir', 'invoicing')); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | /** |
@@ -170,56 +170,56 @@ discard block |
||
| 170 | 170 | * @param string $template_path The template path relative to the theme's root dir. Defaults to 'invoicing'. |
| 171 | 171 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
| 172 | 172 | */ |
| 173 | -function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) { |
|
| 174 | - return getpaid_template()->locate_template( $template_name, $template_path, $default_path ); |
|
| 173 | +function wpinv_locate_template($template_name, $template_path = '', $default_path = '') { |
|
| 174 | + return getpaid_template()->locate_template($template_name, $template_path, $default_path); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | -function wpinv_get_template_part( $slug, $name = null, $load = true ) { |
|
| 178 | - do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
| 177 | +function wpinv_get_template_part($slug, $name = null, $load = true) { |
|
| 178 | + do_action('get_template_part_' . $slug, $slug, $name); |
|
| 179 | 179 | |
| 180 | 180 | // Setup possible parts |
| 181 | 181 | $templates = array(); |
| 182 | - if ( isset( $name ) ) |
|
| 182 | + if (isset($name)) |
|
| 183 | 183 | $templates[] = $slug . '-' . $name . '.php'; |
| 184 | 184 | $templates[] = $slug . '.php'; |
| 185 | 185 | |
| 186 | 186 | // Allow template parts to be filtered |
| 187 | - $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
| 187 | + $templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name); |
|
| 188 | 188 | |
| 189 | 189 | // Return the part that is found |
| 190 | - return wpinv_locate_tmpl( $templates, $load, false ); |
|
| 190 | + return wpinv_locate_tmpl($templates, $load, false); |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | -function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) { |
|
| 193 | +function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) { |
|
| 194 | 194 | // No file found yet |
| 195 | 195 | $located = false; |
| 196 | 196 | |
| 197 | 197 | // Try to find a template file |
| 198 | - foreach ( (array)$template_names as $template_name ) { |
|
| 198 | + foreach ((array) $template_names as $template_name) { |
|
| 199 | 199 | |
| 200 | 200 | // Continue if template is empty |
| 201 | - if ( empty( $template_name ) ) |
|
| 201 | + if (empty($template_name)) |
|
| 202 | 202 | continue; |
| 203 | 203 | |
| 204 | 204 | // Trim off any slashes from the template name |
| 205 | - $template_name = ltrim( $template_name, '/' ); |
|
| 205 | + $template_name = ltrim($template_name, '/'); |
|
| 206 | 206 | |
| 207 | 207 | // try locating this template file by looping through the template paths |
| 208 | - foreach( wpinv_get_theme_template_paths() as $template_path ) { |
|
| 208 | + foreach (wpinv_get_theme_template_paths() as $template_path) { |
|
| 209 | 209 | |
| 210 | - if( file_exists( $template_path . $template_name ) ) { |
|
| 210 | + if (file_exists($template_path . $template_name)) { |
|
| 211 | 211 | $located = $template_path . $template_name; |
| 212 | 212 | break; |
| 213 | 213 | } |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | - if( !empty( $located ) ) { |
|
| 216 | + if (!empty($located)) { |
|
| 217 | 217 | break; |
| 218 | 218 | } |
| 219 | 219 | } |
| 220 | 220 | |
| 221 | - if ( ( true == $load ) && ! empty( $located ) ) |
|
| 222 | - load_template( $located, $require_once ); |
|
| 221 | + if ((true == $load) && !empty($located)) |
|
| 222 | + load_template($located, $require_once); |
|
| 223 | 223 | |
| 224 | 224 | return $located; |
| 225 | 225 | } |
@@ -228,127 +228,127 @@ discard block |
||
| 228 | 228 | $template_dir = wpinv_get_theme_template_dir_name(); |
| 229 | 229 | |
| 230 | 230 | $file_paths = array( |
| 231 | - 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
| 232 | - 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
| 231 | + 1 => trailingslashit(get_stylesheet_directory()) . $template_dir, |
|
| 232 | + 10 => trailingslashit(get_template_directory()) . $template_dir, |
|
| 233 | 233 | 100 => wpinv_get_templates_dir() |
| 234 | 234 | ); |
| 235 | 235 | |
| 236 | - $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
| 236 | + $file_paths = apply_filters('wpinv_template_paths', $file_paths); |
|
| 237 | 237 | |
| 238 | 238 | // sort the file paths based on priority |
| 239 | - ksort( $file_paths, SORT_NUMERIC ); |
|
| 239 | + ksort($file_paths, SORT_NUMERIC); |
|
| 240 | 240 | |
| 241 | - return array_map( 'trailingslashit', $file_paths ); |
|
| 241 | + return array_map('trailingslashit', $file_paths); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | function wpinv_checkout_meta_tags() { |
| 245 | 245 | |
| 246 | 246 | $pages = array(); |
| 247 | - $pages[] = wpinv_get_option( 'success_page' ); |
|
| 248 | - $pages[] = wpinv_get_option( 'failure_page' ); |
|
| 249 | - $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
| 250 | - $pages[] = wpinv_get_option( 'invoice_subscription_page' ); |
|
| 247 | + $pages[] = wpinv_get_option('success_page'); |
|
| 248 | + $pages[] = wpinv_get_option('failure_page'); |
|
| 249 | + $pages[] = wpinv_get_option('invoice_history_page'); |
|
| 250 | + $pages[] = wpinv_get_option('invoice_subscription_page'); |
|
| 251 | 251 | |
| 252 | - if( !wpinv_is_checkout() && !is_page( $pages ) ) { |
|
| 252 | + if (!wpinv_is_checkout() && !is_page($pages)) { |
|
| 253 | 253 | return; |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
| 257 | 257 | } |
| 258 | -add_action( 'wp_head', 'wpinv_checkout_meta_tags' ); |
|
| 258 | +add_action('wp_head', 'wpinv_checkout_meta_tags'); |
|
| 259 | 259 | |
| 260 | -function wpinv_add_body_classes( $class ) { |
|
| 261 | - $classes = (array)$class; |
|
| 260 | +function wpinv_add_body_classes($class) { |
|
| 261 | + $classes = (array) $class; |
|
| 262 | 262 | |
| 263 | - if( wpinv_is_checkout() ) { |
|
| 263 | + if (wpinv_is_checkout()) { |
|
| 264 | 264 | $classes[] = 'wpinv-checkout'; |
| 265 | 265 | $classes[] = 'wpinv-page'; |
| 266 | 266 | } |
| 267 | 267 | |
| 268 | - if( wpinv_is_success_page() ) { |
|
| 268 | + if (wpinv_is_success_page()) { |
|
| 269 | 269 | $classes[] = 'wpinv-success'; |
| 270 | 270 | $classes[] = 'wpinv-page'; |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | - if( wpinv_is_failed_transaction_page() ) { |
|
| 273 | + if (wpinv_is_failed_transaction_page()) { |
|
| 274 | 274 | $classes[] = 'wpinv-failed-transaction'; |
| 275 | 275 | $classes[] = 'wpinv-page'; |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | - if( wpinv_is_invoice_history_page() ) { |
|
| 278 | + if (wpinv_is_invoice_history_page()) { |
|
| 279 | 279 | $classes[] = 'wpinv-history'; |
| 280 | 280 | $classes[] = 'wpinv-page'; |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | - if( wpinv_is_subscriptions_history_page() ) { |
|
| 283 | + if (wpinv_is_subscriptions_history_page()) { |
|
| 284 | 284 | $classes[] = 'wpinv-subscription'; |
| 285 | 285 | $classes[] = 'wpinv-page'; |
| 286 | 286 | } |
| 287 | 287 | |
| 288 | - if( wpinv_is_test_mode() ) { |
|
| 288 | + if (wpinv_is_test_mode()) { |
|
| 289 | 289 | $classes[] = 'wpinv-test-mode'; |
| 290 | 290 | $classes[] = 'wpinv-page'; |
| 291 | 291 | } |
| 292 | 292 | |
| 293 | - return array_unique( $classes ); |
|
| 293 | + return array_unique($classes); |
|
| 294 | 294 | } |
| 295 | -add_filter( 'body_class', 'wpinv_add_body_classes' ); |
|
| 295 | +add_filter('body_class', 'wpinv_add_body_classes'); |
|
| 296 | 296 | |
| 297 | -function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) { |
|
| 298 | - $current = date( 'Y' ); |
|
| 299 | - $start_year = $current - absint( $years_before ); |
|
| 300 | - $end_year = $current + absint( $years_after ); |
|
| 301 | - $selected = empty( $selected ) ? date( 'Y' ) : $selected; |
|
| 297 | +function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) { |
|
| 298 | + $current = date('Y'); |
|
| 299 | + $start_year = $current - absint($years_before); |
|
| 300 | + $end_year = $current + absint($years_after); |
|
| 301 | + $selected = empty($selected) ? date('Y') : $selected; |
|
| 302 | 302 | $options = array(); |
| 303 | 303 | |
| 304 | - while ( $start_year <= $end_year ) { |
|
| 305 | - $options[ absint( $start_year ) ] = $start_year; |
|
| 304 | + while ($start_year <= $end_year) { |
|
| 305 | + $options[absint($start_year)] = $start_year; |
|
| 306 | 306 | $start_year++; |
| 307 | 307 | } |
| 308 | 308 | |
| 309 | - $output = wpinv_html_select( array( |
|
| 309 | + $output = wpinv_html_select(array( |
|
| 310 | 310 | 'name' => $name, |
| 311 | 311 | 'selected' => $selected, |
| 312 | 312 | 'options' => $options, |
| 313 | 313 | 'show_option_all' => false, |
| 314 | 314 | 'show_option_none' => false |
| 315 | - ) ); |
|
| 315 | + )); |
|
| 316 | 316 | |
| 317 | 317 | return $output; |
| 318 | 318 | } |
| 319 | 319 | |
| 320 | -function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) { |
|
| 320 | +function wpinv_html_month_dropdown($name = 'month', $selected = 0) { |
|
| 321 | 321 | |
| 322 | 322 | $options = array( |
| 323 | - '1' => __( 'January', 'invoicing' ), |
|
| 324 | - '2' => __( 'February', 'invoicing' ), |
|
| 325 | - '3' => __( 'March', 'invoicing' ), |
|
| 326 | - '4' => __( 'April', 'invoicing' ), |
|
| 327 | - '5' => __( 'May', 'invoicing' ), |
|
| 328 | - '6' => __( 'June', 'invoicing' ), |
|
| 329 | - '7' => __( 'July', 'invoicing' ), |
|
| 330 | - '8' => __( 'August', 'invoicing' ), |
|
| 331 | - '9' => __( 'September', 'invoicing' ), |
|
| 332 | - '10' => __( 'October', 'invoicing' ), |
|
| 333 | - '11' => __( 'November', 'invoicing' ), |
|
| 334 | - '12' => __( 'December', 'invoicing' ), |
|
| 323 | + '1' => __('January', 'invoicing'), |
|
| 324 | + '2' => __('February', 'invoicing'), |
|
| 325 | + '3' => __('March', 'invoicing'), |
|
| 326 | + '4' => __('April', 'invoicing'), |
|
| 327 | + '5' => __('May', 'invoicing'), |
|
| 328 | + '6' => __('June', 'invoicing'), |
|
| 329 | + '7' => __('July', 'invoicing'), |
|
| 330 | + '8' => __('August', 'invoicing'), |
|
| 331 | + '9' => __('September', 'invoicing'), |
|
| 332 | + '10' => __('October', 'invoicing'), |
|
| 333 | + '11' => __('November', 'invoicing'), |
|
| 334 | + '12' => __('December', 'invoicing'), |
|
| 335 | 335 | ); |
| 336 | 336 | |
| 337 | 337 | // If no month is selected, default to the current month |
| 338 | - $selected = empty( $selected ) ? date( 'n' ) : $selected; |
|
| 338 | + $selected = empty($selected) ? date('n') : $selected; |
|
| 339 | 339 | |
| 340 | - $output = wpinv_html_select( array( |
|
| 340 | + $output = wpinv_html_select(array( |
|
| 341 | 341 | 'name' => $name, |
| 342 | 342 | 'selected' => $selected, |
| 343 | 343 | 'options' => $options, |
| 344 | 344 | 'show_option_all' => false, |
| 345 | 345 | 'show_option_none' => false |
| 346 | - ) ); |
|
| 346 | + )); |
|
| 347 | 347 | |
| 348 | 348 | return $output; |
| 349 | 349 | } |
| 350 | 350 | |
| 351 | -function wpinv_html_select( $args = array() ) { |
|
| 351 | +function wpinv_html_select($args = array()) { |
|
| 352 | 352 | $defaults = array( |
| 353 | 353 | 'options' => array(), |
| 354 | 354 | 'name' => null, |
@@ -357,8 +357,8 @@ discard block |
||
| 357 | 357 | 'selected' => 0, |
| 358 | 358 | 'placeholder' => null, |
| 359 | 359 | 'multiple' => false, |
| 360 | - 'show_option_all' => _x( 'All', 'all dropdown items', 'invoicing' ), |
|
| 361 | - 'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ), |
|
| 360 | + 'show_option_all' => _x('All', 'all dropdown items', 'invoicing'), |
|
| 361 | + 'show_option_none' => _x('None', 'no dropdown items', 'invoicing'), |
|
| 362 | 362 | 'data' => array(), |
| 363 | 363 | 'onchange' => null, |
| 364 | 364 | 'required' => false, |
@@ -366,74 +366,74 @@ discard block |
||
| 366 | 366 | 'readonly' => false, |
| 367 | 367 | ); |
| 368 | 368 | |
| 369 | - $args = wp_parse_args( $args, $defaults ); |
|
| 369 | + $args = wp_parse_args($args, $defaults); |
|
| 370 | 370 | |
| 371 | 371 | $data_elements = ''; |
| 372 | - foreach ( $args['data'] as $key => $value ) { |
|
| 373 | - $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"'; |
|
| 372 | + foreach ($args['data'] as $key => $value) { |
|
| 373 | + $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"'; |
|
| 374 | 374 | } |
| 375 | 375 | |
| 376 | - if( $args['multiple'] ) { |
|
| 376 | + if ($args['multiple']) { |
|
| 377 | 377 | $multiple = ' MULTIPLE'; |
| 378 | 378 | } else { |
| 379 | 379 | $multiple = ''; |
| 380 | 380 | } |
| 381 | 381 | |
| 382 | - if( $args['placeholder'] ) { |
|
| 382 | + if ($args['placeholder']) { |
|
| 383 | 383 | $placeholder = $args['placeholder']; |
| 384 | 384 | } else { |
| 385 | 385 | $placeholder = ''; |
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | $options = ''; |
| 389 | - if( !empty( $args['onchange'] ) ) { |
|
| 390 | - $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"'; |
|
| 389 | + if (!empty($args['onchange'])) { |
|
| 390 | + $options .= ' onchange="' . esc_attr($args['onchange']) . '"'; |
|
| 391 | 391 | } |
| 392 | 392 | |
| 393 | - if( !empty( $args['required'] ) ) { |
|
| 393 | + if (!empty($args['required'])) { |
|
| 394 | 394 | $options .= ' required="required"'; |
| 395 | 395 | } |
| 396 | 396 | |
| 397 | - if( !empty( $args['disabled'] ) ) { |
|
| 397 | + if (!empty($args['disabled'])) { |
|
| 398 | 398 | $options .= ' disabled'; |
| 399 | 399 | } |
| 400 | 400 | |
| 401 | - if( !empty( $args['readonly'] ) ) { |
|
| 401 | + if (!empty($args['readonly'])) { |
|
| 402 | 402 | $options .= ' readonly'; |
| 403 | 403 | } |
| 404 | 404 | |
| 405 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
| 406 | - $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>'; |
|
| 405 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
| 406 | + $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>'; |
|
| 407 | 407 | |
| 408 | - if ( $args['show_option_all'] ) { |
|
| 409 | - if( $args['multiple'] ) { |
|
| 410 | - $selected = selected( true, in_array( 0, $args['selected'] ), false ); |
|
| 408 | + if ($args['show_option_all']) { |
|
| 409 | + if ($args['multiple']) { |
|
| 410 | + $selected = selected(true, in_array(0, $args['selected']), false); |
|
| 411 | 411 | } else { |
| 412 | - $selected = selected( $args['selected'], 0, false ); |
|
| 412 | + $selected = selected($args['selected'], 0, false); |
|
| 413 | 413 | } |
| 414 | - $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>'; |
|
| 414 | + $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>'; |
|
| 415 | 415 | } |
| 416 | 416 | |
| 417 | - if ( !empty( $args['options'] ) ) { |
|
| 417 | + if (!empty($args['options'])) { |
|
| 418 | 418 | |
| 419 | - if ( $args['show_option_none'] ) { |
|
| 420 | - if( $args['multiple'] ) { |
|
| 421 | - $selected = selected( true, in_array( "", $args['selected'] ), false ); |
|
| 419 | + if ($args['show_option_none']) { |
|
| 420 | + if ($args['multiple']) { |
|
| 421 | + $selected = selected(true, in_array("", $args['selected']), false); |
|
| 422 | 422 | } else { |
| 423 | - $selected = selected( $args['selected'] === "", true, false ); |
|
| 423 | + $selected = selected($args['selected'] === "", true, false); |
|
| 424 | 424 | } |
| 425 | - $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>'; |
|
| 425 | + $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>'; |
|
| 426 | 426 | } |
| 427 | 427 | |
| 428 | - foreach( $args['options'] as $key => $option ) { |
|
| 428 | + foreach ($args['options'] as $key => $option) { |
|
| 429 | 429 | |
| 430 | - if( $args['multiple'] && is_array( $args['selected'] ) ) { |
|
| 431 | - $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false ); |
|
| 430 | + if ($args['multiple'] && is_array($args['selected'])) { |
|
| 431 | + $selected = selected(true, (bool) in_array($key, $args['selected']), false); |
|
| 432 | 432 | } else { |
| 433 | - $selected = selected( $args['selected'], $key, false ); |
|
| 433 | + $selected = selected($args['selected'], $key, false); |
|
| 434 | 434 | } |
| 435 | 435 | |
| 436 | - $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>'; |
|
| 436 | + $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>'; |
|
| 437 | 437 | } |
| 438 | 438 | } |
| 439 | 439 | |
@@ -442,7 +442,7 @@ discard block |
||
| 442 | 442 | return $output; |
| 443 | 443 | } |
| 444 | 444 | |
| 445 | -function wpinv_item_dropdown( $args = array() ) { |
|
| 445 | +function wpinv_item_dropdown($args = array()) { |
|
| 446 | 446 | $defaults = array( |
| 447 | 447 | 'name' => 'wpi_item', |
| 448 | 448 | 'id' => 'wpi_item', |
@@ -450,14 +450,14 @@ discard block |
||
| 450 | 450 | 'multiple' => false, |
| 451 | 451 | 'selected' => 0, |
| 452 | 452 | 'number' => 100, |
| 453 | - 'placeholder' => __( 'Choose a item', 'invoicing' ), |
|
| 454 | - 'data' => array( 'search-type' => 'item' ), |
|
| 453 | + 'placeholder' => __('Choose a item', 'invoicing'), |
|
| 454 | + 'data' => array('search-type' => 'item'), |
|
| 455 | 455 | 'show_option_all' => false, |
| 456 | 456 | 'show_option_none' => false, |
| 457 | 457 | 'show_recurring' => false, |
| 458 | 458 | ); |
| 459 | 459 | |
| 460 | - $args = wp_parse_args( $args, $defaults ); |
|
| 460 | + $args = wp_parse_args($args, $defaults); |
|
| 461 | 461 | |
| 462 | 462 | $item_args = array( |
| 463 | 463 | 'post_type' => 'wpi_item', |
@@ -466,44 +466,44 @@ discard block |
||
| 466 | 466 | 'posts_per_page' => $args['number'] |
| 467 | 467 | ); |
| 468 | 468 | |
| 469 | - $item_args = apply_filters( 'wpinv_item_dropdown_query_args', $item_args, $args, $defaults ); |
|
| 469 | + $item_args = apply_filters('wpinv_item_dropdown_query_args', $item_args, $args, $defaults); |
|
| 470 | 470 | |
| 471 | - $items = get_posts( $item_args ); |
|
| 471 | + $items = get_posts($item_args); |
|
| 472 | 472 | $options = array(); |
| 473 | - if ( $items ) { |
|
| 474 | - foreach ( $items as $item ) { |
|
| 475 | - $title = esc_html( $item->post_title ); |
|
| 473 | + if ($items) { |
|
| 474 | + foreach ($items as $item) { |
|
| 475 | + $title = esc_html($item->post_title); |
|
| 476 | 476 | |
| 477 | - if ( !empty( $args['show_recurring'] ) ) { |
|
| 478 | - $title .= wpinv_get_item_suffix( $item->ID, false ); |
|
| 477 | + if (!empty($args['show_recurring'])) { |
|
| 478 | + $title .= wpinv_get_item_suffix($item->ID, false); |
|
| 479 | 479 | } |
| 480 | 480 | |
| 481 | - $options[ absint( $item->ID ) ] = $title; |
|
| 481 | + $options[absint($item->ID)] = $title; |
|
| 482 | 482 | } |
| 483 | 483 | } |
| 484 | 484 | |
| 485 | 485 | // This ensures that any selected items are included in the drop down |
| 486 | - if( is_array( $args['selected'] ) ) { |
|
| 487 | - foreach( $args['selected'] as $item ) { |
|
| 488 | - if( ! in_array( $item, $options ) ) { |
|
| 489 | - $title = get_the_title( $item ); |
|
| 490 | - if ( !empty( $args['show_recurring'] ) ) { |
|
| 491 | - $title .= wpinv_get_item_suffix( $item, false ); |
|
| 486 | + if (is_array($args['selected'])) { |
|
| 487 | + foreach ($args['selected'] as $item) { |
|
| 488 | + if (!in_array($item, $options)) { |
|
| 489 | + $title = get_the_title($item); |
|
| 490 | + if (!empty($args['show_recurring'])) { |
|
| 491 | + $title .= wpinv_get_item_suffix($item, false); |
|
| 492 | 492 | } |
| 493 | 493 | $options[$item] = $title; |
| 494 | 494 | } |
| 495 | 495 | } |
| 496 | - } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) { |
|
| 497 | - if ( ! in_array( $args['selected'], $options ) ) { |
|
| 498 | - $title = get_the_title( $args['selected'] ); |
|
| 499 | - if ( !empty( $args['show_recurring'] ) ) { |
|
| 500 | - $title .= wpinv_get_item_suffix( $args['selected'], false ); |
|
| 496 | + } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) { |
|
| 497 | + if (!in_array($args['selected'], $options)) { |
|
| 498 | + $title = get_the_title($args['selected']); |
|
| 499 | + if (!empty($args['show_recurring'])) { |
|
| 500 | + $title .= wpinv_get_item_suffix($args['selected'], false); |
|
| 501 | 501 | } |
| 502 | - $options[$args['selected']] = get_the_title( $args['selected'] ); |
|
| 502 | + $options[$args['selected']] = get_the_title($args['selected']); |
|
| 503 | 503 | } |
| 504 | 504 | } |
| 505 | 505 | |
| 506 | - $output = wpinv_html_select( array( |
|
| 506 | + $output = wpinv_html_select(array( |
|
| 507 | 507 | 'name' => $args['name'], |
| 508 | 508 | 'selected' => $args['selected'], |
| 509 | 509 | 'id' => $args['id'], |
@@ -514,7 +514,7 @@ discard block |
||
| 514 | 514 | 'show_option_all' => $args['show_option_all'], |
| 515 | 515 | 'show_option_none' => $args['show_option_none'], |
| 516 | 516 | 'data' => $args['data'], |
| 517 | - ) ); |
|
| 517 | + )); |
|
| 518 | 518 | |
| 519 | 519 | return $output; |
| 520 | 520 | } |
@@ -534,16 +534,16 @@ discard block |
||
| 534 | 534 | ); |
| 535 | 535 | |
| 536 | 536 | $options = array(); |
| 537 | - if ( $items ) { |
|
| 538 | - foreach ( $items as $item ) { |
|
| 539 | - $options[ $item->ID ] = esc_html( $item->post_title ) . wpinv_get_item_suffix( $item->ID, false ); |
|
| 537 | + if ($items) { |
|
| 538 | + foreach ($items as $item) { |
|
| 539 | + $options[$item->ID] = esc_html($item->post_title) . wpinv_get_item_suffix($item->ID, false); |
|
| 540 | 540 | } |
| 541 | 541 | } |
| 542 | 542 | |
| 543 | 543 | return $options; |
| 544 | 544 | } |
| 545 | 545 | |
| 546 | -function wpinv_html_checkbox( $args = array() ) { |
|
| 546 | +function wpinv_html_checkbox($args = array()) { |
|
| 547 | 547 | $defaults = array( |
| 548 | 548 | 'name' => null, |
| 549 | 549 | 'current' => null, |
@@ -554,17 +554,17 @@ discard block |
||
| 554 | 554 | ) |
| 555 | 555 | ); |
| 556 | 556 | |
| 557 | - $args = wp_parse_args( $args, $defaults ); |
|
| 557 | + $args = wp_parse_args($args, $defaults); |
|
| 558 | 558 | |
| 559 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
| 559 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
| 560 | 560 | $options = ''; |
| 561 | - if ( ! empty( $args['options']['disabled'] ) ) { |
|
| 561 | + if (!empty($args['options']['disabled'])) { |
|
| 562 | 562 | $options .= ' disabled="disabled"'; |
| 563 | - } elseif ( ! empty( $args['options']['readonly'] ) ) { |
|
| 563 | + } elseif (!empty($args['options']['readonly'])) { |
|
| 564 | 564 | $options .= ' readonly'; |
| 565 | 565 | } |
| 566 | 566 | |
| 567 | - $output = '<input type="checkbox"' . $options . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $class . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />'; |
|
| 567 | + $output = '<input type="checkbox"' . $options . ' name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . $class . ' ' . esc_attr($args['name']) . '" ' . checked(1, $args['current'], false) . ' />'; |
|
| 568 | 568 | |
| 569 | 569 | return $output; |
| 570 | 570 | } |
@@ -572,9 +572,9 @@ discard block |
||
| 572 | 572 | /** |
| 573 | 573 | * Displays a hidden field. |
| 574 | 574 | */ |
| 575 | -function getpaid_hidden_field( $name, $value ) { |
|
| 576 | - $name = sanitize_text_field( $name ); |
|
| 577 | - $value = esc_attr( $value ); |
|
| 575 | +function getpaid_hidden_field($name, $value) { |
|
| 576 | + $name = sanitize_text_field($name); |
|
| 577 | + $value = esc_attr($value); |
|
| 578 | 578 | |
| 579 | 579 | echo "<input type='hidden' name='$name' value='$value' />"; |
| 580 | 580 | } |
@@ -582,31 +582,31 @@ discard block |
||
| 582 | 582 | /** |
| 583 | 583 | * Displays a submit field. |
| 584 | 584 | */ |
| 585 | -function getpaid_submit_field( $value, $name = 'submit', $class = 'btn-primary' ) { |
|
| 586 | - $name = sanitize_text_field( $name ); |
|
| 587 | - $value = esc_attr( $value ); |
|
| 588 | - $class = esc_attr( $class ); |
|
| 585 | +function getpaid_submit_field($value, $name = 'submit', $class = 'btn-primary') { |
|
| 586 | + $name = sanitize_text_field($name); |
|
| 587 | + $value = esc_attr($value); |
|
| 588 | + $class = esc_attr($class); |
|
| 589 | 589 | |
| 590 | 590 | echo "<input type='submit' name='$name' value='$value' class='btn $class' />"; |
| 591 | 591 | } |
| 592 | 592 | |
| 593 | -function wpinv_html_text( $args = array() ) { |
|
| 593 | +function wpinv_html_text($args = array()) { |
|
| 594 | 594 | // Backwards compatibility |
| 595 | - if ( func_num_args() > 1 ) { |
|
| 595 | + if (func_num_args() > 1) { |
|
| 596 | 596 | $args = func_get_args(); |
| 597 | 597 | |
| 598 | 598 | $name = $args[0]; |
| 599 | - $value = isset( $args[1] ) ? $args[1] : ''; |
|
| 600 | - $label = isset( $args[2] ) ? $args[2] : ''; |
|
| 601 | - $desc = isset( $args[3] ) ? $args[3] : ''; |
|
| 599 | + $value = isset($args[1]) ? $args[1] : ''; |
|
| 600 | + $label = isset($args[2]) ? $args[2] : ''; |
|
| 601 | + $desc = isset($args[3]) ? $args[3] : ''; |
|
| 602 | 602 | } |
| 603 | 603 | |
| 604 | 604 | $defaults = array( |
| 605 | 605 | 'id' => '', |
| 606 | - 'name' => isset( $name ) ? $name : 'text', |
|
| 607 | - 'value' => isset( $value ) ? $value : null, |
|
| 608 | - 'label' => isset( $label ) ? $label : null, |
|
| 609 | - 'desc' => isset( $desc ) ? $desc : null, |
|
| 606 | + 'name' => isset($name) ? $name : 'text', |
|
| 607 | + 'value' => isset($value) ? $value : null, |
|
| 608 | + 'label' => isset($label) ? $label : null, |
|
| 609 | + 'desc' => isset($desc) ? $desc : null, |
|
| 610 | 610 | 'placeholder' => '', |
| 611 | 611 | 'class' => 'regular-text', |
| 612 | 612 | 'disabled' => false, |
@@ -616,41 +616,41 @@ discard block |
||
| 616 | 616 | 'data' => false |
| 617 | 617 | ); |
| 618 | 618 | |
| 619 | - $args = wp_parse_args( $args, $defaults ); |
|
| 619 | + $args = wp_parse_args($args, $defaults); |
|
| 620 | 620 | |
| 621 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
| 621 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
| 622 | 622 | $options = ''; |
| 623 | - if( $args['required'] ) { |
|
| 623 | + if ($args['required']) { |
|
| 624 | 624 | $options .= ' required="required"'; |
| 625 | 625 | } |
| 626 | - if( $args['readonly'] ) { |
|
| 626 | + if ($args['readonly']) { |
|
| 627 | 627 | $options .= ' readonly'; |
| 628 | 628 | } |
| 629 | - if( $args['readonly'] ) { |
|
| 629 | + if ($args['readonly']) { |
|
| 630 | 630 | $options .= ' readonly'; |
| 631 | 631 | } |
| 632 | 632 | |
| 633 | 633 | $data = ''; |
| 634 | - if ( !empty( $args['data'] ) ) { |
|
| 635 | - foreach ( $args['data'] as $key => $value ) { |
|
| 636 | - $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" '; |
|
| 634 | + if (!empty($args['data'])) { |
|
| 635 | + foreach ($args['data'] as $key => $value) { |
|
| 636 | + $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" '; |
|
| 637 | 637 | } |
| 638 | 638 | } |
| 639 | 639 | |
| 640 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
| 641 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
| 642 | - if ( ! empty( $args['desc'] ) ) { |
|
| 643 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
| 640 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
| 641 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>'; |
|
| 642 | + if (!empty($args['desc'])) { |
|
| 643 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
| 644 | 644 | } |
| 645 | 645 | |
| 646 | - $output .= '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" autocomplete="' . esc_attr( $args['autocomplete'] ) . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $class . '" ' . $data . ' ' . trim( $options ) . '/>'; |
|
| 646 | + $output .= '<input type="text" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" autocomplete="' . esc_attr($args['autocomplete']) . '" value="' . esc_attr($args['value']) . '" placeholder="' . esc_attr($args['placeholder']) . '" class="' . $class . '" ' . $data . ' ' . trim($options) . '/>'; |
|
| 647 | 647 | |
| 648 | 648 | $output .= '</span>'; |
| 649 | 649 | |
| 650 | 650 | return $output; |
| 651 | 651 | } |
| 652 | 652 | |
| 653 | -function wpinv_html_textarea( $args = array() ) { |
|
| 653 | +function wpinv_html_textarea($args = array()) { |
|
| 654 | 654 | $defaults = array( |
| 655 | 655 | 'name' => 'textarea', |
| 656 | 656 | 'value' => null, |
@@ -661,31 +661,31 @@ discard block |
||
| 661 | 661 | 'placeholder' => '', |
| 662 | 662 | ); |
| 663 | 663 | |
| 664 | - $args = wp_parse_args( $args, $defaults ); |
|
| 664 | + $args = wp_parse_args($args, $defaults); |
|
| 665 | 665 | |
| 666 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
| 666 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
| 667 | 667 | $disabled = ''; |
| 668 | - if( $args['disabled'] ) { |
|
| 668 | + if ($args['disabled']) { |
|
| 669 | 669 | $disabled = ' disabled="disabled"'; |
| 670 | 670 | } |
| 671 | 671 | |
| 672 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
| 673 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
| 674 | - $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>'; |
|
| 672 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
| 673 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>'; |
|
| 674 | + $output .= '<textarea name="' . esc_attr($args['name']) . '" placeholder="' . esc_attr($args['placeholder']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>'; |
|
| 675 | 675 | |
| 676 | - if ( ! empty( $args['desc'] ) ) { |
|
| 677 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
| 676 | + if (!empty($args['desc'])) { |
|
| 677 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
| 678 | 678 | } |
| 679 | 679 | $output .= '</span>'; |
| 680 | 680 | |
| 681 | 681 | return $output; |
| 682 | 682 | } |
| 683 | 683 | |
| 684 | -function wpinv_html_ajax_user_search( $args = array() ) { |
|
| 684 | +function wpinv_html_ajax_user_search($args = array()) { |
|
| 685 | 685 | $defaults = array( |
| 686 | 686 | 'name' => 'user_id', |
| 687 | 687 | 'value' => null, |
| 688 | - 'placeholder' => __( 'Enter username', 'invoicing' ), |
|
| 688 | + 'placeholder' => __('Enter username', 'invoicing'), |
|
| 689 | 689 | 'label' => null, |
| 690 | 690 | 'desc' => null, |
| 691 | 691 | 'class' => '', |
@@ -694,13 +694,13 @@ discard block |
||
| 694 | 694 | 'data' => false |
| 695 | 695 | ); |
| 696 | 696 | |
| 697 | - $args = wp_parse_args( $args, $defaults ); |
|
| 697 | + $args = wp_parse_args($args, $defaults); |
|
| 698 | 698 | |
| 699 | 699 | $args['class'] = 'wpinv-ajax-user-search ' . $args['class']; |
| 700 | 700 | |
| 701 | 701 | $output = '<span class="wpinv_user_search_wrap">'; |
| 702 | - $output .= wpinv_html_text( $args ); |
|
| 703 | - $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __( 'Cancel', 'invoicing' ) . '" aria-label="' . __( 'Cancel', 'invoicing' ) . '" href="#">x</a><span></span></span>'; |
|
| 702 | + $output .= wpinv_html_text($args); |
|
| 703 | + $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __('Cancel', 'invoicing') . '" aria-label="' . __('Cancel', 'invoicing') . '" href="#">x</a><span></span></span>'; |
|
| 704 | 704 | $output .= '</span>'; |
| 705 | 705 | |
| 706 | 706 | return $output; |
@@ -711,20 +711,20 @@ discard block |
||
| 711 | 711 | * |
| 712 | 712 | * @param string $template the template that is currently being used. |
| 713 | 713 | */ |
| 714 | -function wpinv_template( $template ) { |
|
| 714 | +function wpinv_template($template) { |
|
| 715 | 715 | global $post; |
| 716 | 716 | |
| 717 | - if ( ! is_admin() && ( is_single() || is_404() ) && ! empty( $post->ID ) && getpaid_is_invoice_post_type( get_post_type( $post->ID ) ) ) { |
|
| 717 | + if (!is_admin() && (is_single() || is_404()) && !empty($post->ID) && getpaid_is_invoice_post_type(get_post_type($post->ID))) { |
|
| 718 | 718 | |
| 719 | 719 | // If the user can view this invoice, display it. |
| 720 | - if ( wpinv_user_can_view_invoice( $post->ID ) ) { |
|
| 720 | + if (wpinv_user_can_view_invoice($post->ID)) { |
|
| 721 | 721 | |
| 722 | - return wpinv_get_template_part( 'wpinv-invoice-print', false, false ); |
|
| 722 | + return wpinv_get_template_part('wpinv-invoice-print', false, false); |
|
| 723 | 723 | |
| 724 | 724 | // Else display an error message. |
| 725 | 725 | } else { |
| 726 | 726 | |
| 727 | - return wpinv_get_template_part( 'wpinv-invalid-access', false, false ); |
|
| 727 | + return wpinv_get_template_part('wpinv-invalid-access', false, false); |
|
| 728 | 728 | |
| 729 | 729 | } |
| 730 | 730 | |
@@ -732,24 +732,24 @@ discard block |
||
| 732 | 732 | |
| 733 | 733 | return $template; |
| 734 | 734 | } |
| 735 | -add_filter( 'template_include', 'wpinv_template', 10, 1 ); |
|
| 735 | +add_filter('template_include', 'wpinv_template', 10, 1); |
|
| 736 | 736 | |
| 737 | 737 | function wpinv_get_business_address() { |
| 738 | 738 | $business_address = wpinv_store_address(); |
| 739 | - $business_address = !empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : ''; |
|
| 739 | + $business_address = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : ''; |
|
| 740 | 740 | |
| 741 | 741 | $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : ''; |
| 742 | 742 | |
| 743 | - return apply_filters( 'wpinv_get_business_address', $business_address ); |
|
| 743 | + return apply_filters('wpinv_get_business_address', $business_address); |
|
| 744 | 744 | } |
| 745 | 745 | |
| 746 | 746 | /** |
| 747 | 747 | * Displays the company address. |
| 748 | 748 | */ |
| 749 | 749 | function wpinv_display_from_address() { |
| 750 | - wpinv_get_template( 'invoice/company-address.php' ); |
|
| 750 | + wpinv_get_template('invoice/company-address.php'); |
|
| 751 | 751 | } |
| 752 | -add_action( 'getpaid_invoice_details_left', 'wpinv_display_from_address', 10 ); |
|
| 752 | +add_action('getpaid_invoice_details_left', 'wpinv_display_from_address', 10); |
|
| 753 | 753 | |
| 754 | 754 | /** |
| 755 | 755 | * Generates a watermark text for an invoice. |
@@ -757,9 +757,9 @@ discard block |
||
| 757 | 757 | * @param WPInv_Invoice $invoice |
| 758 | 758 | * @return string |
| 759 | 759 | */ |
| 760 | -function wpinv_watermark( $invoice ) { |
|
| 761 | - $watermark = wpinv_get_watermark( $invoice ); |
|
| 762 | - return apply_filters( 'wpinv_get_watermark', $watermark, $invoice ); |
|
| 760 | +function wpinv_watermark($invoice) { |
|
| 761 | + $watermark = wpinv_get_watermark($invoice); |
|
| 762 | + return apply_filters('wpinv_get_watermark', $watermark, $invoice); |
|
| 763 | 763 | } |
| 764 | 764 | |
| 765 | 765 | /** |
@@ -768,37 +768,37 @@ discard block |
||
| 768 | 768 | * @param WPInv_Invoice $invoice |
| 769 | 769 | * @return string |
| 770 | 770 | */ |
| 771 | -function wpinv_get_watermark( $invoice ) { |
|
| 771 | +function wpinv_get_watermark($invoice) { |
|
| 772 | 772 | return $invoice->get_status_nicename(); |
| 773 | 773 | } |
| 774 | 774 | |
| 775 | 775 | /** |
| 776 | 776 | * @deprecated |
| 777 | 777 | */ |
| 778 | -function wpinv_display_invoice_details( $invoice ) { |
|
| 779 | - return getpaid_invoice_meta( $invoice ); |
|
| 778 | +function wpinv_display_invoice_details($invoice) { |
|
| 779 | + return getpaid_invoice_meta($invoice); |
|
| 780 | 780 | } |
| 781 | 781 | |
| 782 | 782 | /** |
| 783 | 783 | * Displays invoice meta. |
| 784 | 784 | */ |
| 785 | -function getpaid_invoice_meta( $invoice ) { |
|
| 785 | +function getpaid_invoice_meta($invoice) { |
|
| 786 | 786 | |
| 787 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 787 | + $invoice = new WPInv_Invoice($invoice); |
|
| 788 | 788 | |
| 789 | 789 | // Ensure that we have an invoice. |
| 790 | - if ( 0 == $invoice->get_id() ) { |
|
| 790 | + if (0 == $invoice->get_id()) { |
|
| 791 | 791 | return; |
| 792 | 792 | } |
| 793 | 793 | |
| 794 | 794 | // Get the invoice meta. |
| 795 | - $meta = getpaid_get_invoice_meta( $invoice ); |
|
| 795 | + $meta = getpaid_get_invoice_meta($invoice); |
|
| 796 | 796 | |
| 797 | 797 | // Display the meta. |
| 798 | - wpinv_get_template( 'invoice/invoice-meta.php', compact( 'invoice', 'meta' ) ); |
|
| 798 | + wpinv_get_template('invoice/invoice-meta.php', compact('invoice', 'meta')); |
|
| 799 | 799 | |
| 800 | 800 | } |
| 801 | -add_action( 'getpaid_invoice_details_right', 'getpaid_invoice_meta', 10 ); |
|
| 801 | +add_action('getpaid_invoice_details_right', 'getpaid_invoice_meta', 10); |
|
| 802 | 802 | |
| 803 | 803 | /** |
| 804 | 804 | * Retrieves the address markup to use on Invoices. |
@@ -810,29 +810,29 @@ discard block |
||
| 810 | 810 | * @param string $separator How to separate address lines. |
| 811 | 811 | * @return string |
| 812 | 812 | */ |
| 813 | -function wpinv_get_invoice_address_markup( $billing_details, $separator = '<br/>' ) { |
|
| 813 | +function wpinv_get_invoice_address_markup($billing_details, $separator = '<br/>') { |
|
| 814 | 814 | |
| 815 | 815 | // Retrieve the address markup... |
| 816 | - $country= empty( $billing_details['country'] ) ? '' : $billing_details['country']; |
|
| 817 | - $format = wpinv_get_full_address_format( $country ); |
|
| 816 | + $country = empty($billing_details['country']) ? '' : $billing_details['country']; |
|
| 817 | + $format = wpinv_get_full_address_format($country); |
|
| 818 | 818 | |
| 819 | 819 | // ... and the replacements. |
| 820 | - $replacements = wpinv_get_invoice_address_replacements( $billing_details ); |
|
| 820 | + $replacements = wpinv_get_invoice_address_replacements($billing_details); |
|
| 821 | 821 | |
| 822 | - $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format ); |
|
| 822 | + $formatted_address = str_ireplace(array_keys($replacements), $replacements, $format); |
|
| 823 | 823 | |
| 824 | 824 | // Remove unavailable tags. |
| 825 | - $formatted_address = preg_replace( "/\{\{\w+\}\}/", '', $formatted_address ); |
|
| 825 | + $formatted_address = preg_replace("/\{\{\w+\}\}/", '', $formatted_address); |
|
| 826 | 826 | |
| 827 | 827 | // Clean up white space. |
| 828 | - $formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) ); |
|
| 829 | - $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address ); |
|
| 828 | + $formatted_address = preg_replace('/ +/', ' ', trim($formatted_address)); |
|
| 829 | + $formatted_address = preg_replace('/\n\n+/', "\n", $formatted_address); |
|
| 830 | 830 | |
| 831 | 831 | // Break newlines apart and remove empty lines/trim commas and white space. |
| 832 | - $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) ); |
|
| 832 | + $formatted_address = array_filter(array_map('wpinv_trim_formatted_address_line', explode("\n", $formatted_address))); |
|
| 833 | 833 | |
| 834 | 834 | // Add html breaks. |
| 835 | - $formatted_address = implode( $separator, $formatted_address ); |
|
| 835 | + $formatted_address = implode($separator, $formatted_address); |
|
| 836 | 836 | |
| 837 | 837 | // We're done! |
| 838 | 838 | return $formatted_address; |
@@ -844,118 +844,118 @@ discard block |
||
| 844 | 844 | * |
| 845 | 845 | * @param WPInv_Invoice $invoice |
| 846 | 846 | */ |
| 847 | -function wpinv_display_to_address( $invoice = 0 ) { |
|
| 848 | - if ( ! empty( $invoice ) ) { |
|
| 849 | - wpinv_get_template( 'invoice/billing-address.php', compact( 'invoice' ) ); |
|
| 847 | +function wpinv_display_to_address($invoice = 0) { |
|
| 848 | + if (!empty($invoice)) { |
|
| 849 | + wpinv_get_template('invoice/billing-address.php', compact('invoice')); |
|
| 850 | 850 | } |
| 851 | 851 | } |
| 852 | -add_action( 'getpaid_invoice_details_left', 'wpinv_display_to_address', 40 ); |
|
| 852 | +add_action('getpaid_invoice_details_left', 'wpinv_display_to_address', 40); |
|
| 853 | 853 | |
| 854 | 854 | |
| 855 | 855 | /** |
| 856 | 856 | * Displays invoice line items. |
| 857 | 857 | */ |
| 858 | -function wpinv_display_line_items( $invoice_id = 0 ) { |
|
| 858 | +function wpinv_display_line_items($invoice_id = 0) { |
|
| 859 | 859 | |
| 860 | 860 | // Prepare the invoice. |
| 861 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 861 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 862 | 862 | |
| 863 | 863 | // Abort if there is no invoice. |
| 864 | - if ( 0 == $invoice->get_id() ) { |
|
| 864 | + if (0 == $invoice->get_id()) { |
|
| 865 | 865 | return; |
| 866 | 866 | } |
| 867 | 867 | |
| 868 | 868 | // Line item columns. |
| 869 | - $columns = getpaid_invoice_item_columns( $invoice ); |
|
| 870 | - $columns = apply_filters( 'getpaid_invoice_line_items_table_columns', $columns, $invoice ); |
|
| 869 | + $columns = getpaid_invoice_item_columns($invoice); |
|
| 870 | + $columns = apply_filters('getpaid_invoice_line_items_table_columns', $columns, $invoice); |
|
| 871 | 871 | |
| 872 | - wpinv_get_template( 'invoice/line-items.php', compact( 'invoice', 'columns' ) ); |
|
| 872 | + wpinv_get_template('invoice/line-items.php', compact('invoice', 'columns')); |
|
| 873 | 873 | } |
| 874 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_line_items', 10 ); |
|
| 874 | +add_action('getpaid_invoice_line_items', 'wpinv_display_line_items', 10); |
|
| 875 | 875 | |
| 876 | 876 | /** |
| 877 | 877 | * Displays invoice subscriptions. |
| 878 | 878 | * |
| 879 | 879 | * @param WPInv_Invoice $invoice |
| 880 | 880 | */ |
| 881 | -function getpaid_display_invoice_subscriptions( $invoice ) { |
|
| 881 | +function getpaid_display_invoice_subscriptions($invoice) { |
|
| 882 | 882 | |
| 883 | 883 | // Subscriptions. |
| 884 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
| 884 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
| 885 | 885 | |
| 886 | - if ( empty( $subscriptions ) || ! $invoice->is_recurring() ) { |
|
| 886 | + if (empty($subscriptions) || !$invoice->is_recurring()) { |
|
| 887 | 887 | return; |
| 888 | 888 | } |
| 889 | 889 | |
| 890 | - $main_subscription = getpaid_get_invoice_subscription( $invoice ); |
|
| 890 | + $main_subscription = getpaid_get_invoice_subscription($invoice); |
|
| 891 | 891 | |
| 892 | 892 | // Display related subscriptions. |
| 893 | - if ( is_array( $subscriptions ) ) { |
|
| 894 | - printf( '<h2 class="mt-5 mb-1 h4">%s</h2>', esc_html__( 'Related Subscriptions', 'invoicing' ) ); |
|
| 895 | - getpaid_admin_subscription_related_subscriptions_metabox( $main_subscription, false ); |
|
| 893 | + if (is_array($subscriptions)) { |
|
| 894 | + printf('<h2 class="mt-5 mb-1 h4">%s</h2>', esc_html__('Related Subscriptions', 'invoicing')); |
|
| 895 | + getpaid_admin_subscription_related_subscriptions_metabox($main_subscription, false); |
|
| 896 | 896 | } |
| 897 | 897 | |
| 898 | - if ( $main_subscription->get_total_payments() > 1 ) { |
|
| 899 | - printf( '<h2 class="mt-5 mb-1 h4">%s</h2>', esc_html__( 'Related Invoices', 'invoicing' ) ); |
|
| 900 | - getpaid_admin_subscription_invoice_details_metabox( $main_subscription, false ); |
|
| 898 | + if ($main_subscription->get_total_payments() > 1) { |
|
| 899 | + printf('<h2 class="mt-5 mb-1 h4">%s</h2>', esc_html__('Related Invoices', 'invoicing')); |
|
| 900 | + getpaid_admin_subscription_invoice_details_metabox($main_subscription, false); |
|
| 901 | 901 | } |
| 902 | 902 | |
| 903 | 903 | } |
| 904 | -add_action( 'getpaid_invoice_line_items', 'getpaid_display_invoice_subscriptions', 15 ); |
|
| 904 | +add_action('getpaid_invoice_line_items', 'getpaid_display_invoice_subscriptions', 15); |
|
| 905 | 905 | |
| 906 | 906 | /** |
| 907 | 907 | * Displays invoice notices on invoices. |
| 908 | 908 | */ |
| 909 | 909 | function wpinv_display_invoice_notice() { |
| 910 | 910 | |
| 911 | - $label = wpinv_get_option( 'vat_invoice_notice_label' ); |
|
| 912 | - $notice = wpinv_get_option( 'vat_invoice_notice' ); |
|
| 911 | + $label = wpinv_get_option('vat_invoice_notice_label'); |
|
| 912 | + $notice = wpinv_get_option('vat_invoice_notice'); |
|
| 913 | 913 | |
| 914 | - if ( empty( $label ) && empty( $notice ) ) { |
|
| 914 | + if (empty($label) && empty($notice)) { |
|
| 915 | 915 | return; |
| 916 | 916 | } |
| 917 | 917 | |
| 918 | 918 | echo '<div class="mt-4 mb-4 wpinv-vat-notice">'; |
| 919 | 919 | |
| 920 | - if ( ! empty( $label ) ) { |
|
| 921 | - $label = sanitize_text_field( $label ); |
|
| 920 | + if (!empty($label)) { |
|
| 921 | + $label = sanitize_text_field($label); |
|
| 922 | 922 | echo "<h5>$label</h5>"; |
| 923 | 923 | } |
| 924 | 924 | |
| 925 | - if ( ! empty( $notice ) ) { |
|
| 926 | - echo '<small class="form-text text-muted">' . wpautop( wptexturize( $notice ) ) . '</small>'; |
|
| 925 | + if (!empty($notice)) { |
|
| 926 | + echo '<small class="form-text text-muted">' . wpautop(wptexturize($notice)) . '</small>'; |
|
| 927 | 927 | } |
| 928 | 928 | |
| 929 | 929 | echo '</div>'; |
| 930 | 930 | } |
| 931 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100 ); |
|
| 931 | +add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100); |
|
| 932 | 932 | |
| 933 | 933 | /** |
| 934 | 934 | * @param WPInv_Invoice $invoice |
| 935 | 935 | */ |
| 936 | -function wpinv_display_invoice_notes( $invoice ) { |
|
| 936 | +function wpinv_display_invoice_notes($invoice) { |
|
| 937 | 937 | |
| 938 | 938 | // Retrieve the notes. |
| 939 | - $notes = wpinv_get_invoice_notes( $invoice->get_id(), 'customer' ); |
|
| 939 | + $notes = wpinv_get_invoice_notes($invoice->get_id(), 'customer'); |
|
| 940 | 940 | |
| 941 | 941 | // Abort if we have non. |
| 942 | - if ( empty( $notes ) ) { |
|
| 942 | + if (empty($notes)) { |
|
| 943 | 943 | return; |
| 944 | 944 | } |
| 945 | 945 | |
| 946 | 946 | // Echo the note. |
| 947 | 947 | echo '<div class="getpaid-invoice-notes-wrapper position-relative my-4">'; |
| 948 | - echo '<h2 class="getpaid-invoice-notes-title mb-1 p-0 h4">' . __( 'Notes', 'invoicing' ) .'</h2>'; |
|
| 948 | + echo '<h2 class="getpaid-invoice-notes-title mb-1 p-0 h4">' . __('Notes', 'invoicing') . '</h2>'; |
|
| 949 | 949 | echo '<ul class="getpaid-invoice-notes text-break overflow-auto list-unstyled p-0 m-0">'; |
| 950 | 950 | |
| 951 | - foreach( $notes as $note ) { |
|
| 952 | - wpinv_get_invoice_note_line_item( $note ); |
|
| 951 | + foreach ($notes as $note) { |
|
| 952 | + wpinv_get_invoice_note_line_item($note); |
|
| 953 | 953 | } |
| 954 | 954 | |
| 955 | 955 | echo '</ul>'; |
| 956 | 956 | echo '</div>'; |
| 957 | 957 | } |
| 958 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60 ); |
|
| 958 | +add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60); |
|
| 959 | 959 | |
| 960 | 960 | /** |
| 961 | 961 | * Loads scripts on our invoice templates. |
@@ -963,31 +963,31 @@ discard block |
||
| 963 | 963 | function wpinv_display_style() { |
| 964 | 964 | |
| 965 | 965 | // Make sure that all scripts have been loaded. |
| 966 | - if ( ! did_action( 'wp_enqueue_scripts' ) ) { |
|
| 967 | - do_action( 'wp_enqueue_scripts' ); |
|
| 966 | + if (!did_action('wp_enqueue_scripts')) { |
|
| 967 | + do_action('wp_enqueue_scripts'); |
|
| 968 | 968 | } |
| 969 | 969 | |
| 970 | 970 | // Register the invoices style. |
| 971 | - wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice.css' ) ); |
|
| 971 | + wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime(WPINV_PLUGIN_DIR . 'assets/css/invoice.css')); |
|
| 972 | 972 | |
| 973 | 973 | // Load required styles |
| 974 | - wp_print_styles( 'wpinv-single-style' ); |
|
| 975 | - wp_print_styles( 'ayecode-ui' ); |
|
| 974 | + wp_print_styles('wpinv-single-style'); |
|
| 975 | + wp_print_styles('ayecode-ui'); |
|
| 976 | 976 | |
| 977 | 977 | // Maybe load custom css. |
| 978 | - $custom_css = wpinv_get_option( 'template_custom_css' ); |
|
| 978 | + $custom_css = wpinv_get_option('template_custom_css'); |
|
| 979 | 979 | |
| 980 | - if ( isset( $custom_css ) && ! empty( $custom_css ) ) { |
|
| 981 | - $custom_css = wp_kses( $custom_css, array( '\'', '\"' ) ); |
|
| 982 | - $custom_css = str_replace( '>', '>', $custom_css ); |
|
| 980 | + if (isset($custom_css) && !empty($custom_css)) { |
|
| 981 | + $custom_css = wp_kses($custom_css, array('\'', '\"')); |
|
| 982 | + $custom_css = str_replace('>', '>', $custom_css); |
|
| 983 | 983 | echo '<style type="text/css">'; |
| 984 | 984 | echo $custom_css; |
| 985 | 985 | echo '</style>'; |
| 986 | 986 | } |
| 987 | 987 | |
| 988 | 988 | } |
| 989 | -add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' ); |
|
| 990 | -add_action( 'wpinv_invalid_invoice_head', 'wpinv_display_style' ); |
|
| 989 | +add_action('wpinv_invoice_print_head', 'wpinv_display_style'); |
|
| 990 | +add_action('wpinv_invalid_invoice_head', 'wpinv_display_style'); |
|
| 991 | 991 | |
| 992 | 992 | |
| 993 | 993 | /** |
@@ -999,41 +999,41 @@ discard block |
||
| 999 | 999 | // Retrieve the current invoice. |
| 1000 | 1000 | $invoice_id = getpaid_get_current_invoice_id(); |
| 1001 | 1001 | |
| 1002 | - if ( empty( $invoice_id ) ) { |
|
| 1002 | + if (empty($invoice_id)) { |
|
| 1003 | 1003 | |
| 1004 | 1004 | return aui()->alert( |
| 1005 | 1005 | array( |
| 1006 | 1006 | 'type' => 'warning', |
| 1007 | - 'content' => __( 'Invalid invoice', 'invoicing' ), |
|
| 1007 | + 'content' => __('Invalid invoice', 'invoicing'), |
|
| 1008 | 1008 | ) |
| 1009 | 1009 | ); |
| 1010 | 1010 | |
| 1011 | 1011 | } |
| 1012 | 1012 | |
| 1013 | 1013 | // Can the user view this invoice? |
| 1014 | - if ( ! wpinv_user_can_view_invoice( $invoice_id ) ) { |
|
| 1014 | + if (!wpinv_user_can_view_invoice($invoice_id)) { |
|
| 1015 | 1015 | |
| 1016 | 1016 | return aui()->alert( |
| 1017 | 1017 | array( |
| 1018 | 1018 | 'type' => 'warning', |
| 1019 | - 'content' => __( 'You are not allowed to view this invoice', 'invoicing' ), |
|
| 1019 | + 'content' => __('You are not allowed to view this invoice', 'invoicing'), |
|
| 1020 | 1020 | ) |
| 1021 | 1021 | ); |
| 1022 | 1022 | |
| 1023 | 1023 | } |
| 1024 | 1024 | |
| 1025 | 1025 | // Ensure that it is not yet paid for. |
| 1026 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 1026 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 1027 | 1027 | |
| 1028 | 1028 | // Maybe mark it as viewed. |
| 1029 | - getpaid_maybe_mark_invoice_as_viewed( $invoice ); |
|
| 1029 | + getpaid_maybe_mark_invoice_as_viewed($invoice); |
|
| 1030 | 1030 | |
| 1031 | - if ( $invoice->is_paid() ) { |
|
| 1031 | + if ($invoice->is_paid()) { |
|
| 1032 | 1032 | |
| 1033 | 1033 | return aui()->alert( |
| 1034 | 1034 | array( |
| 1035 | 1035 | 'type' => 'success', |
| 1036 | - 'content' => __( 'This invoice has already been paid.', 'invoicing' ), |
|
| 1036 | + 'content' => __('This invoice has already been paid.', 'invoicing'), |
|
| 1037 | 1037 | ) |
| 1038 | 1038 | ); |
| 1039 | 1039 | |
@@ -1043,15 +1043,15 @@ discard block |
||
| 1043 | 1043 | $wpi_checkout_id = $invoice_id; |
| 1044 | 1044 | |
| 1045 | 1045 | // Retrieve appropriate payment form. |
| 1046 | - $payment_form = new GetPaid_Payment_Form( $invoice->get_meta( 'force_payment_form' ) ); |
|
| 1047 | - $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
| 1046 | + $payment_form = new GetPaid_Payment_Form($invoice->get_meta('force_payment_form')); |
|
| 1047 | + $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
| 1048 | 1048 | |
| 1049 | - if ( ! $payment_form->exists() ) { |
|
| 1049 | + if (!$payment_form->exists()) { |
|
| 1050 | 1050 | |
| 1051 | 1051 | return aui()->alert( |
| 1052 | 1052 | array( |
| 1053 | 1053 | 'type' => 'warning', |
| 1054 | - 'content' => __( 'Error loading the payment form', 'invoicing' ), |
|
| 1054 | + 'content' => __('Error loading the payment form', 'invoicing'), |
|
| 1055 | 1055 | ) |
| 1056 | 1056 | ); |
| 1057 | 1057 | |
@@ -1060,29 +1060,29 @@ discard block |
||
| 1060 | 1060 | // Set the invoice. |
| 1061 | 1061 | $payment_form->invoice = $invoice; |
| 1062 | 1062 | |
| 1063 | - if ( ! $payment_form->is_default() ) { |
|
| 1063 | + if (!$payment_form->is_default()) { |
|
| 1064 | 1064 | |
| 1065 | 1065 | $items = array(); |
| 1066 | 1066 | $item_ids = array(); |
| 1067 | 1067 | |
| 1068 | - foreach ( $invoice->get_items() as $item ) { |
|
| 1069 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 1068 | + foreach ($invoice->get_items() as $item) { |
|
| 1069 | + if (!in_array($item->get_id(), $item_ids)) { |
|
| 1070 | 1070 | $item_ids[] = $item->get_id(); |
| 1071 | 1071 | $items[] = $item; |
| 1072 | 1072 | } |
| 1073 | 1073 | } |
| 1074 | 1074 | |
| 1075 | - foreach ( $payment_form->get_items() as $item ) { |
|
| 1076 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 1075 | + foreach ($payment_form->get_items() as $item) { |
|
| 1076 | + if (!in_array($item->get_id(), $item_ids)) { |
|
| 1077 | 1077 | $item_ids[] = $item->get_id(); |
| 1078 | 1078 | $items[] = $item; |
| 1079 | 1079 | } |
| 1080 | 1080 | } |
| 1081 | 1081 | |
| 1082 | - $payment_form->set_items( $items ); |
|
| 1082 | + $payment_form->set_items($items); |
|
| 1083 | 1083 | |
| 1084 | 1084 | } else { |
| 1085 | - $payment_form->set_items( $invoice->get_items() ); |
|
| 1085 | + $payment_form->set_items($invoice->get_items()); |
|
| 1086 | 1086 | } |
| 1087 | 1087 | |
| 1088 | 1088 | // Generate the html. |
@@ -1091,7 +1091,7 @@ discard block |
||
| 1091 | 1091 | } |
| 1092 | 1092 | |
| 1093 | 1093 | function wpinv_empty_cart_message() { |
| 1094 | - return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
| 1094 | + return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>'); |
|
| 1095 | 1095 | } |
| 1096 | 1096 | |
| 1097 | 1097 | /** |
@@ -1108,76 +1108,76 @@ discard block |
||
| 1108 | 1108 | ) |
| 1109 | 1109 | ); |
| 1110 | 1110 | } |
| 1111 | -add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' ); |
|
| 1111 | +add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart'); |
|
| 1112 | 1112 | |
| 1113 | 1113 | /** |
| 1114 | 1114 | * Filters the receipt page. |
| 1115 | 1115 | */ |
| 1116 | -function wpinv_filter_success_page_content( $content ) { |
|
| 1116 | +function wpinv_filter_success_page_content($content) { |
|
| 1117 | 1117 | |
| 1118 | 1118 | // Maybe abort early. |
| 1119 | - if ( is_admin() || ! is_singular() || ! in_the_loop() || ! is_main_query() || is_preview() ) { |
|
| 1119 | + if (is_admin() || !is_singular() || !in_the_loop() || !is_main_query() || is_preview()) { |
|
| 1120 | 1120 | return $content; |
| 1121 | 1121 | } |
| 1122 | 1122 | |
| 1123 | 1123 | // Ensure this is our page. |
| 1124 | - if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) { |
|
| 1124 | + if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) { |
|
| 1125 | 1125 | |
| 1126 | - $gateway = sanitize_text_field( $_GET['payment-confirm'] ); |
|
| 1127 | - return apply_filters( "wpinv_payment_confirm_$gateway", $content ); |
|
| 1126 | + $gateway = sanitize_text_field($_GET['payment-confirm']); |
|
| 1127 | + return apply_filters("wpinv_payment_confirm_$gateway", $content); |
|
| 1128 | 1128 | |
| 1129 | 1129 | } |
| 1130 | 1130 | |
| 1131 | 1131 | return $content; |
| 1132 | 1132 | } |
| 1133 | -add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 ); |
|
| 1133 | +add_filter('the_content', 'wpinv_filter_success_page_content', 99999); |
|
| 1134 | 1134 | |
| 1135 | -function wpinv_invoice_link( $invoice_id ) { |
|
| 1136 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 1135 | +function wpinv_invoice_link($invoice_id) { |
|
| 1136 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 1137 | 1137 | |
| 1138 | - if ( empty( $invoice ) ) { |
|
| 1138 | + if (empty($invoice)) { |
|
| 1139 | 1139 | return NULL; |
| 1140 | 1140 | } |
| 1141 | 1141 | |
| 1142 | - $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>'; |
|
| 1142 | + $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>'; |
|
| 1143 | 1143 | |
| 1144 | - return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice ); |
|
| 1144 | + return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice); |
|
| 1145 | 1145 | } |
| 1146 | 1146 | |
| 1147 | -function wpinv_get_invoice_note_line_item( $note, $echo = true ) { |
|
| 1148 | - if ( empty( $note ) ) { |
|
| 1147 | +function wpinv_get_invoice_note_line_item($note, $echo = true) { |
|
| 1148 | + if (empty($note)) { |
|
| 1149 | 1149 | return NULL; |
| 1150 | 1150 | } |
| 1151 | 1151 | |
| 1152 | - if ( is_int( $note ) ) { |
|
| 1153 | - $note = get_comment( $note ); |
|
| 1152 | + if (is_int($note)) { |
|
| 1153 | + $note = get_comment($note); |
|
| 1154 | 1154 | } |
| 1155 | 1155 | |
| 1156 | - if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) { |
|
| 1156 | + if (!(is_object($note) && is_a($note, 'WP_Comment'))) { |
|
| 1157 | 1157 | return NULL; |
| 1158 | 1158 | } |
| 1159 | 1159 | |
| 1160 | - $note_classes = array( 'note' ); |
|
| 1161 | - $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : ''; |
|
| 1160 | + $note_classes = array('note'); |
|
| 1161 | + $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : ''; |
|
| 1162 | 1162 | $note_classes[] = $note->comment_author === 'System' ? 'system-note' : ''; |
| 1163 | - $note_classes = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note ); |
|
| 1164 | - $note_classes = !empty( $note_classes ) ? implode( ' ', $note_classes ) : ''; |
|
| 1163 | + $note_classes = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note); |
|
| 1164 | + $note_classes = !empty($note_classes) ? implode(' ', $note_classes) : ''; |
|
| 1165 | 1165 | |
| 1166 | 1166 | ob_start(); |
| 1167 | 1167 | ?> |
| 1168 | - <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?> mb-2"> |
|
| 1168 | + <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?> mb-2"> |
|
| 1169 | 1169 | <div class="note_content"> |
| 1170 | 1170 | |
| 1171 | - <?php echo wptexturize( wp_kses_post( $note->comment_content ) ); ?> |
|
| 1171 | + <?php echo wptexturize(wp_kses_post($note->comment_content)); ?> |
|
| 1172 | 1172 | |
| 1173 | - <?php if ( ! is_admin() ) : ?> |
|
| 1173 | + <?php if (!is_admin()) : ?> |
|
| 1174 | 1174 | <em class="small form-text text-muted mt-0"> |
| 1175 | 1175 | <?php |
| 1176 | 1176 | printf( |
| 1177 | - __( '%1$s - %2$s at %3$s', 'invoicing' ), |
|
| 1177 | + __('%1$s - %2$s at %3$s', 'invoicing'), |
|
| 1178 | 1178 | $note->comment_author, |
| 1179 | - getpaid_format_date_value( $note->comment_date ), |
|
| 1180 | - date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) |
|
| 1179 | + getpaid_format_date_value($note->comment_date), |
|
| 1180 | + date_i18n(get_option('time_format'), strtotime($note->comment_date)) |
|
| 1181 | 1181 | ); |
| 1182 | 1182 | ?> |
| 1183 | 1183 | </em> |
@@ -1185,21 +1185,21 @@ discard block |
||
| 1185 | 1185 | |
| 1186 | 1186 | </div> |
| 1187 | 1187 | |
| 1188 | - <?php if ( is_admin() ) : ?> |
|
| 1188 | + <?php if (is_admin()) : ?> |
|
| 1189 | 1189 | |
| 1190 | 1190 | <p class="meta px-4 py-2"> |
| 1191 | - <abbr class="exact-date" title="<?php echo esc_attr( $note->comment_date ); ?>"> |
|
| 1191 | + <abbr class="exact-date" title="<?php echo esc_attr($note->comment_date); ?>"> |
|
| 1192 | 1192 | <?php |
| 1193 | 1193 | printf( |
| 1194 | - __( '%1$s - %2$s at %3$s', 'invoicing' ), |
|
| 1194 | + __('%1$s - %2$s at %3$s', 'invoicing'), |
|
| 1195 | 1195 | $note->comment_author, |
| 1196 | - getpaid_format_date_value( $note->comment_date ), |
|
| 1197 | - date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) |
|
| 1196 | + getpaid_format_date_value($note->comment_date), |
|
| 1197 | + date_i18n(get_option('time_format'), strtotime($note->comment_date)) |
|
| 1198 | 1198 | ); |
| 1199 | 1199 | ?> |
| 1200 | 1200 | </abbr> |
| 1201 | - <?php if ( $note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing() ) { ?> |
|
| 1202 | - <a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a> |
|
| 1201 | + <?php if ($note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing()) { ?> |
|
| 1202 | + <a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a> |
|
| 1203 | 1203 | <?php } ?> |
| 1204 | 1204 | </p> |
| 1205 | 1205 | |
@@ -1208,9 +1208,9 @@ discard block |
||
| 1208 | 1208 | </li> |
| 1209 | 1209 | <?php |
| 1210 | 1210 | $note_content = ob_get_clean(); |
| 1211 | - $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo ); |
|
| 1211 | + $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo); |
|
| 1212 | 1212 | |
| 1213 | - if ( $echo ) { |
|
| 1213 | + if ($echo) { |
|
| 1214 | 1214 | echo $note_content; |
| 1215 | 1215 | } else { |
| 1216 | 1216 | return $note_content; |
@@ -1224,21 +1224,21 @@ discard block |
||
| 1224 | 1224 | * @return string |
| 1225 | 1225 | */ |
| 1226 | 1226 | function wpinv_get_policy_text() { |
| 1227 | - $privacy_page_id = get_option( 'wp_page_for_privacy_policy', 0 ); |
|
| 1227 | + $privacy_page_id = get_option('wp_page_for_privacy_policy', 0); |
|
| 1228 | 1228 | |
| 1229 | - $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf( __( 'Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing' ), '[wpinv_privacy_policy]' )); |
|
| 1229 | + $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf(__('Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing'), '[wpinv_privacy_policy]')); |
|
| 1230 | 1230 | |
| 1231 | - if(!$privacy_page_id){ |
|
| 1232 | - $privacy_page_id = wpinv_get_option( 'privacy_page', 0 ); |
|
| 1231 | + if (!$privacy_page_id) { |
|
| 1232 | + $privacy_page_id = wpinv_get_option('privacy_page', 0); |
|
| 1233 | 1233 | } |
| 1234 | 1234 | |
| 1235 | - $privacy_link = $privacy_page_id ? '<a href="' . esc_url( get_permalink( $privacy_page_id ) ) . '" class="wpinv-privacy-policy-link" target="_blank">' . __( 'privacy policy', 'invoicing' ) . '</a>' : __( 'privacy policy', 'invoicing' ); |
|
| 1235 | + $privacy_link = $privacy_page_id ? '<a href="' . esc_url(get_permalink($privacy_page_id)) . '" class="wpinv-privacy-policy-link" target="_blank">' . __('privacy policy', 'invoicing') . '</a>' : __('privacy policy', 'invoicing'); |
|
| 1236 | 1236 | |
| 1237 | 1237 | $find_replace = array( |
| 1238 | 1238 | '[wpinv_privacy_policy]' => $privacy_link, |
| 1239 | 1239 | ); |
| 1240 | 1240 | |
| 1241 | - $privacy_text = str_replace( array_keys( $find_replace ), array_values( $find_replace ), $text ); |
|
| 1241 | + $privacy_text = str_replace(array_keys($find_replace), array_values($find_replace), $text); |
|
| 1242 | 1242 | |
| 1243 | 1243 | return wp_kses_post(wpautop($privacy_text)); |
| 1244 | 1244 | } |
@@ -1246,21 +1246,21 @@ discard block |
||
| 1246 | 1246 | function wpinv_oxygen_fix_conflict() { |
| 1247 | 1247 | global $ct_ignore_post_types; |
| 1248 | 1248 | |
| 1249 | - if ( ! is_array( $ct_ignore_post_types ) ) { |
|
| 1249 | + if (!is_array($ct_ignore_post_types)) { |
|
| 1250 | 1250 | $ct_ignore_post_types = array(); |
| 1251 | 1251 | } |
| 1252 | 1252 | |
| 1253 | - $post_types = array( 'wpi_discount', 'wpi_invoice', 'wpi_item', 'wpi_payment_form' ); |
|
| 1253 | + $post_types = array('wpi_discount', 'wpi_invoice', 'wpi_item', 'wpi_payment_form'); |
|
| 1254 | 1254 | |
| 1255 | - foreach ( $post_types as $post_type ) { |
|
| 1255 | + foreach ($post_types as $post_type) { |
|
| 1256 | 1256 | $ct_ignore_post_types[] = $post_type; |
| 1257 | 1257 | |
| 1258 | 1258 | // Ignore post type |
| 1259 | - add_filter( 'pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999 ); |
|
| 1259 | + add_filter('pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999); |
|
| 1260 | 1260 | } |
| 1261 | 1261 | |
| 1262 | - remove_filter( 'template_include', 'wpinv_template', 10, 1 ); |
|
| 1263 | - add_filter( 'template_include', 'wpinv_template', 999, 1 ); |
|
| 1262 | + remove_filter('template_include', 'wpinv_template', 10, 1); |
|
| 1263 | + add_filter('template_include', 'wpinv_template', 999, 1); |
|
| 1264 | 1264 | } |
| 1265 | 1265 | |
| 1266 | 1266 | /** |
@@ -1268,10 +1268,10 @@ discard block |
||
| 1268 | 1268 | * |
| 1269 | 1269 | * @param GetPaid_Payment_Form $form |
| 1270 | 1270 | */ |
| 1271 | -function getpaid_display_payment_form( $form ) { |
|
| 1271 | +function getpaid_display_payment_form($form) { |
|
| 1272 | 1272 | |
| 1273 | - if ( is_numeric( $form ) ) { |
|
| 1274 | - $form = new GetPaid_Payment_Form( $form ); |
|
| 1273 | + if (is_numeric($form)) { |
|
| 1274 | + $form = new GetPaid_Payment_Form($form); |
|
| 1275 | 1275 | } |
| 1276 | 1276 | |
| 1277 | 1277 | $form->display(); |
@@ -1281,55 +1281,55 @@ discard block |
||
| 1281 | 1281 | /** |
| 1282 | 1282 | * Helper function to display a item payment form on the frontend. |
| 1283 | 1283 | */ |
| 1284 | -function getpaid_display_item_payment_form( $items ) { |
|
| 1284 | +function getpaid_display_item_payment_form($items) { |
|
| 1285 | 1285 | |
| 1286 | - $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
| 1287 | - $form->set_items( $items ); |
|
| 1286 | + $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
| 1287 | + $form->set_items($items); |
|
| 1288 | 1288 | |
| 1289 | - if ( 0 == count( $form->get_items() ) ) { |
|
| 1289 | + if (0 == count($form->get_items())) { |
|
| 1290 | 1290 | echo aui()->alert( |
| 1291 | 1291 | array( |
| 1292 | 1292 | 'type' => 'warning', |
| 1293 | - 'content' => __( 'No published items found', 'invoicing' ), |
|
| 1293 | + 'content' => __('No published items found', 'invoicing'), |
|
| 1294 | 1294 | ) |
| 1295 | 1295 | ); |
| 1296 | 1296 | return; |
| 1297 | 1297 | } |
| 1298 | 1298 | |
| 1299 | - $form_items = esc_attr( getpaid_convert_items_to_string( $items ) ); |
|
| 1299 | + $form_items = esc_attr(getpaid_convert_items_to_string($items)); |
|
| 1300 | 1300 | $form_items = "<input type='hidden' name='getpaid-form-items' value='$form_items' />"; |
| 1301 | - $form->display( $form_items ); |
|
| 1301 | + $form->display($form_items); |
|
| 1302 | 1302 | } |
| 1303 | 1303 | |
| 1304 | 1304 | /** |
| 1305 | 1305 | * Helper function to display an invoice payment form on the frontend. |
| 1306 | 1306 | */ |
| 1307 | -function getpaid_display_invoice_payment_form( $invoice_id ) { |
|
| 1307 | +function getpaid_display_invoice_payment_form($invoice_id) { |
|
| 1308 | 1308 | |
| 1309 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 1309 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 1310 | 1310 | |
| 1311 | - if ( empty( $invoice ) ) { |
|
| 1311 | + if (empty($invoice)) { |
|
| 1312 | 1312 | echo aui()->alert( |
| 1313 | 1313 | array( |
| 1314 | 1314 | 'type' => 'warning', |
| 1315 | - 'content' => __( 'Invoice not found', 'invoicing' ), |
|
| 1315 | + 'content' => __('Invoice not found', 'invoicing'), |
|
| 1316 | 1316 | ) |
| 1317 | 1317 | ); |
| 1318 | 1318 | return; |
| 1319 | 1319 | } |
| 1320 | 1320 | |
| 1321 | - if ( $invoice->is_paid() ) { |
|
| 1321 | + if ($invoice->is_paid()) { |
|
| 1322 | 1322 | echo aui()->alert( |
| 1323 | 1323 | array( |
| 1324 | 1324 | 'type' => 'warning', |
| 1325 | - 'content' => __( 'Invoice has already been paid', 'invoicing' ), |
|
| 1325 | + 'content' => __('Invoice has already been paid', 'invoicing'), |
|
| 1326 | 1326 | ) |
| 1327 | 1327 | ); |
| 1328 | 1328 | return; |
| 1329 | 1329 | } |
| 1330 | 1330 | |
| 1331 | - $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
| 1332 | - $form->set_items( $invoice->get_items() ); |
|
| 1331 | + $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
| 1332 | + $form->set_items($invoice->get_items()); |
|
| 1333 | 1333 | |
| 1334 | 1334 | $form->display(); |
| 1335 | 1335 | } |
@@ -1337,23 +1337,23 @@ discard block |
||
| 1337 | 1337 | /** |
| 1338 | 1338 | * Helper function to convert item string to array. |
| 1339 | 1339 | */ |
| 1340 | -function getpaid_convert_items_to_array( $items ) { |
|
| 1341 | - $items = array_filter( array_map( 'trim', explode( ',', $items ) ) ); |
|
| 1340 | +function getpaid_convert_items_to_array($items) { |
|
| 1341 | + $items = array_filter(array_map('trim', explode(',', $items))); |
|
| 1342 | 1342 | $prepared = array(); |
| 1343 | 1343 | |
| 1344 | - foreach ( $items as $item ) { |
|
| 1345 | - $data = array_map( 'trim', explode( '|', $item ) ); |
|
| 1344 | + foreach ($items as $item) { |
|
| 1345 | + $data = array_map('trim', explode('|', $item)); |
|
| 1346 | 1346 | |
| 1347 | - if ( empty( $data[0] ) || ! is_numeric( $data[0] ) ) { |
|
| 1347 | + if (empty($data[0]) || !is_numeric($data[0])) { |
|
| 1348 | 1348 | continue; |
| 1349 | 1349 | } |
| 1350 | 1350 | |
| 1351 | 1351 | $quantity = 1; |
| 1352 | - if ( isset( $data[1] ) && is_numeric( $data[1] ) ) { |
|
| 1352 | + if (isset($data[1]) && is_numeric($data[1])) { |
|
| 1353 | 1353 | $quantity = (float) $data[1]; |
| 1354 | 1354 | } |
| 1355 | 1355 | |
| 1356 | - $prepared[ $data[0] ] = $quantity; |
|
| 1356 | + $prepared[$data[0]] = $quantity; |
|
| 1357 | 1357 | |
| 1358 | 1358 | } |
| 1359 | 1359 | |
@@ -1363,13 +1363,13 @@ discard block |
||
| 1363 | 1363 | /** |
| 1364 | 1364 | * Helper function to convert item array to string. |
| 1365 | 1365 | */ |
| 1366 | -function getpaid_convert_items_to_string( $items ) { |
|
| 1366 | +function getpaid_convert_items_to_string($items) { |
|
| 1367 | 1367 | $prepared = array(); |
| 1368 | 1368 | |
| 1369 | - foreach ( $items as $item => $quantity ) { |
|
| 1369 | + foreach ($items as $item => $quantity) { |
|
| 1370 | 1370 | $prepared[] = "$item|$quantity"; |
| 1371 | 1371 | } |
| 1372 | - return implode( ',', $prepared ); |
|
| 1372 | + return implode(',', $prepared); |
|
| 1373 | 1373 | } |
| 1374 | 1374 | |
| 1375 | 1375 | /** |
@@ -1377,21 +1377,21 @@ discard block |
||
| 1377 | 1377 | * |
| 1378 | 1378 | * Provide a label and one of $form, $items or $invoice. |
| 1379 | 1379 | */ |
| 1380 | -function getpaid_get_payment_button( $label, $form = null, $items = null, $invoice = null ) { |
|
| 1381 | - $label = sanitize_text_field( $label ); |
|
| 1380 | +function getpaid_get_payment_button($label, $form = null, $items = null, $invoice = null) { |
|
| 1381 | + $label = sanitize_text_field($label); |
|
| 1382 | 1382 | |
| 1383 | - if ( ! empty( $form ) ) { |
|
| 1384 | - $form = esc_attr( $form ); |
|
| 1383 | + if (!empty($form)) { |
|
| 1384 | + $form = esc_attr($form); |
|
| 1385 | 1385 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-form='$form'>$label</button>"; |
| 1386 | 1386 | } |
| 1387 | 1387 | |
| 1388 | - if ( ! empty( $items ) ) { |
|
| 1389 | - $items = esc_attr( $items ); |
|
| 1388 | + if (!empty($items)) { |
|
| 1389 | + $items = esc_attr($items); |
|
| 1390 | 1390 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-item='$items'>$label</button>"; |
| 1391 | 1391 | } |
| 1392 | 1392 | |
| 1393 | - if ( ! empty( $invoice ) ) { |
|
| 1394 | - $invoice = esc_attr( $invoice ); |
|
| 1393 | + if (!empty($invoice)) { |
|
| 1394 | + $invoice = esc_attr($invoice); |
|
| 1395 | 1395 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-invoice='$invoice'>$label</button>"; |
| 1396 | 1396 | } |
| 1397 | 1397 | |
@@ -1402,17 +1402,17 @@ discard block |
||
| 1402 | 1402 | * |
| 1403 | 1403 | * @param WPInv_Invoice $invoice |
| 1404 | 1404 | */ |
| 1405 | -function getpaid_the_invoice_description( $invoice ) { |
|
| 1405 | +function getpaid_the_invoice_description($invoice) { |
|
| 1406 | 1406 | $description = $invoice->get_description(); |
| 1407 | 1407 | |
| 1408 | - if ( empty( $description ) ) { |
|
| 1408 | + if (empty($description)) { |
|
| 1409 | 1409 | return; |
| 1410 | 1410 | } |
| 1411 | 1411 | |
| 1412 | - $description = wp_kses_post( $description ); |
|
| 1412 | + $description = wp_kses_post($description); |
|
| 1413 | 1413 | echo "<small class='getpaid-invoice-description text-dark p-2 form-text' style='margin-bottom: 20px; border-left: 2px solid #2196F3;'><em>$description</em></small>"; |
| 1414 | 1414 | } |
| 1415 | -add_action( 'getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100 ); |
|
| 1415 | +add_action('getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100); |
|
| 1416 | 1416 | |
| 1417 | 1417 | /** |
| 1418 | 1418 | * Render element on a form. |
@@ -1420,60 +1420,60 @@ discard block |
||
| 1420 | 1420 | * @param array $element |
| 1421 | 1421 | * @param GetPaid_Payment_Form $form |
| 1422 | 1422 | */ |
| 1423 | -function getpaid_payment_form_element( $element, $form ) { |
|
| 1423 | +function getpaid_payment_form_element($element, $form) { |
|
| 1424 | 1424 | |
| 1425 | 1425 | // Set up the args. |
| 1426 | - $element_type = trim( $element['type'] ); |
|
| 1426 | + $element_type = trim($element['type']); |
|
| 1427 | 1427 | $element['form'] = $form; |
| 1428 | - extract( $element ); |
|
| 1428 | + extract($element); |
|
| 1429 | 1429 | |
| 1430 | 1430 | // Try to locate the appropriate template. |
| 1431 | - $located = wpinv_locate_template( "payment-forms/elements/$element_type.php" ); |
|
| 1431 | + $located = wpinv_locate_template("payment-forms/elements/$element_type.php"); |
|
| 1432 | 1432 | |
| 1433 | 1433 | // Abort if this is not our element. |
| 1434 | - if ( empty( $located ) || ! file_exists( $located ) ) { |
|
| 1434 | + if (empty($located) || !file_exists($located)) { |
|
| 1435 | 1435 | return; |
| 1436 | 1436 | } |
| 1437 | 1437 | |
| 1438 | 1438 | // Generate the class and id of the element. |
| 1439 | - $wrapper_class = 'getpaid-payment-form-element-' . trim( esc_attr( $element_type ) ); |
|
| 1440 | - $id = isset( $id ) ? $id : uniqid( 'gp' ); |
|
| 1439 | + $wrapper_class = 'getpaid-payment-form-element-' . trim(esc_attr($element_type)); |
|
| 1440 | + $id = isset($id) ? $id : uniqid('gp'); |
|
| 1441 | 1441 | |
| 1442 | 1442 | // Echo the opening wrapper. |
| 1443 | 1443 | echo "<div class='getpaid-payment-form-element $wrapper_class'>"; |
| 1444 | 1444 | |
| 1445 | 1445 | // Fires before displaying a given element type's content. |
| 1446 | - do_action( "getpaid_before_payment_form_{$element_type}_element", $element, $form ); |
|
| 1446 | + do_action("getpaid_before_payment_form_{$element_type}_element", $element, $form); |
|
| 1447 | 1447 | |
| 1448 | 1448 | // Include the template for the element. |
| 1449 | 1449 | include $located; |
| 1450 | 1450 | |
| 1451 | 1451 | // Fires after displaying a given element type's content. |
| 1452 | - do_action( "getpaid_payment_form_{$element_type}_element", $element, $form ); |
|
| 1452 | + do_action("getpaid_payment_form_{$element_type}_element", $element, $form); |
|
| 1453 | 1453 | |
| 1454 | 1454 | // Echo the closing wrapper. |
| 1455 | 1455 | echo '</div>'; |
| 1456 | 1456 | } |
| 1457 | -add_action( 'getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2 ); |
|
| 1457 | +add_action('getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2); |
|
| 1458 | 1458 | |
| 1459 | 1459 | /** |
| 1460 | 1460 | * Render an element's edit page. |
| 1461 | 1461 | * |
| 1462 | 1462 | * @param WP_Post $post |
| 1463 | 1463 | */ |
| 1464 | -function getpaid_payment_form_edit_element_template( $post ) { |
|
| 1464 | +function getpaid_payment_form_edit_element_template($post) { |
|
| 1465 | 1465 | |
| 1466 | 1466 | // Retrieve all elements. |
| 1467 | - $all_elements = wp_list_pluck( wpinv_get_data( 'payment-form-elements' ), 'type' ); |
|
| 1467 | + $all_elements = wp_list_pluck(wpinv_get_data('payment-form-elements'), 'type'); |
|
| 1468 | 1468 | |
| 1469 | - foreach ( $all_elements as $element ) { |
|
| 1469 | + foreach ($all_elements as $element) { |
|
| 1470 | 1470 | |
| 1471 | 1471 | // Try to locate the appropriate template. |
| 1472 | - $element = sanitize_key( $element ); |
|
| 1473 | - $located = wpinv_locate_template( "payment-forms-admin/edit/$element.php" ); |
|
| 1472 | + $element = sanitize_key($element); |
|
| 1473 | + $located = wpinv_locate_template("payment-forms-admin/edit/$element.php"); |
|
| 1474 | 1474 | |
| 1475 | 1475 | // Continue if this is not our element. |
| 1476 | - if ( empty( $located ) || ! file_exists( $located ) ) { |
|
| 1476 | + if (empty($located) || !file_exists($located)) { |
|
| 1477 | 1477 | continue; |
| 1478 | 1478 | } |
| 1479 | 1479 | |
@@ -1484,7 +1484,7 @@ discard block |
||
| 1484 | 1484 | } |
| 1485 | 1485 | |
| 1486 | 1486 | } |
| 1487 | -add_action( 'getpaid_payment_form_edit_element_template', 'getpaid_payment_form_edit_element_template' ); |
|
| 1487 | +add_action('getpaid_payment_form_edit_element_template', 'getpaid_payment_form_edit_element_template'); |
|
| 1488 | 1488 | |
| 1489 | 1489 | /** |
| 1490 | 1490 | * Render an element's preview. |
@@ -1493,16 +1493,16 @@ discard block |
||
| 1493 | 1493 | function getpaid_payment_form_render_element_preview_template() { |
| 1494 | 1494 | |
| 1495 | 1495 | // Retrieve all elements. |
| 1496 | - $all_elements = wp_list_pluck( wpinv_get_data( 'payment-form-elements' ), 'type' ); |
|
| 1496 | + $all_elements = wp_list_pluck(wpinv_get_data('payment-form-elements'), 'type'); |
|
| 1497 | 1497 | |
| 1498 | - foreach ( $all_elements as $element ) { |
|
| 1498 | + foreach ($all_elements as $element) { |
|
| 1499 | 1499 | |
| 1500 | 1500 | // Try to locate the appropriate template. |
| 1501 | - $element = sanitize_key( $element ); |
|
| 1502 | - $located = wpinv_locate_template( "payment-forms-admin/previews/$element.php" ); |
|
| 1501 | + $element = sanitize_key($element); |
|
| 1502 | + $located = wpinv_locate_template("payment-forms-admin/previews/$element.php"); |
|
| 1503 | 1503 | |
| 1504 | 1504 | // Continue if this is not our element. |
| 1505 | - if ( empty( $located ) || ! file_exists( $located ) ) { |
|
| 1505 | + if (empty($located) || !file_exists($located)) { |
|
| 1506 | 1506 | continue; |
| 1507 | 1507 | } |
| 1508 | 1508 | |
@@ -1513,7 +1513,7 @@ discard block |
||
| 1513 | 1513 | } |
| 1514 | 1514 | |
| 1515 | 1515 | } |
| 1516 | -add_action( 'wpinv_payment_form_render_element_template', 'getpaid_payment_form_render_element_preview_template' ); |
|
| 1516 | +add_action('wpinv_payment_form_render_element_template', 'getpaid_payment_form_render_element_preview_template'); |
|
| 1517 | 1517 | |
| 1518 | 1518 | /** |
| 1519 | 1519 | * Shows a list of gateways that support recurring payments. |
@@ -1521,17 +1521,17 @@ discard block |
||
| 1521 | 1521 | function wpinv_get_recurring_gateways_text() { |
| 1522 | 1522 | $gateways = array(); |
| 1523 | 1523 | |
| 1524 | - foreach ( wpinv_get_payment_gateways() as $key => $gateway ) { |
|
| 1525 | - if ( wpinv_gateway_support_subscription( $key ) ) { |
|
| 1526 | - $gateways[] = sanitize_text_field( $gateway['admin_label'] ); |
|
| 1524 | + foreach (wpinv_get_payment_gateways() as $key => $gateway) { |
|
| 1525 | + if (wpinv_gateway_support_subscription($key)) { |
|
| 1526 | + $gateways[] = sanitize_text_field($gateway['admin_label']); |
|
| 1527 | 1527 | } |
| 1528 | 1528 | } |
| 1529 | 1529 | |
| 1530 | - if ( empty( $gateways ) ) { |
|
| 1531 | - return "<span class='form-text text-danger'>" . __( 'No active gateways support subscription payments.', 'invoicing' ) ."</span>"; |
|
| 1530 | + if (empty($gateways)) { |
|
| 1531 | + return "<span class='form-text text-danger'>" . __('No active gateways support subscription payments.', 'invoicing') . "</span>"; |
|
| 1532 | 1532 | } |
| 1533 | 1533 | |
| 1534 | - return "<span class='form-text text-muted'>" . wp_sprintf( __( 'Subscription payments only supported by: %s', 'invoicing' ), implode( ', ', $gateways ) ) ."</span>"; |
|
| 1534 | + return "<span class='form-text text-muted'>" . wp_sprintf(__('Subscription payments only supported by: %s', 'invoicing'), implode(', ', $gateways)) . "</span>"; |
|
| 1535 | 1535 | |
| 1536 | 1536 | } |
| 1537 | 1537 | |
@@ -1541,7 +1541,7 @@ discard block |
||
| 1541 | 1541 | * @return GetPaid_Template |
| 1542 | 1542 | */ |
| 1543 | 1543 | function getpaid_template() { |
| 1544 | - return getpaid()->get( 'template' ); |
|
| 1544 | + return getpaid()->get('template'); |
|
| 1545 | 1545 | } |
| 1546 | 1546 | |
| 1547 | 1547 | /** |
@@ -1550,8 +1550,8 @@ discard block |
||
| 1550 | 1550 | * @param array args |
| 1551 | 1551 | * @return string |
| 1552 | 1552 | */ |
| 1553 | -function getpaid_paginate_links( $args ) { |
|
| 1554 | - return str_replace( 'page-link dots', 'page-link text-dark', aui()->pagination( $args ) ); |
|
| 1553 | +function getpaid_paginate_links($args) { |
|
| 1554 | + return str_replace('page-link dots', 'page-link text-dark', aui()->pagination($args)); |
|
| 1555 | 1555 | } |
| 1556 | 1556 | |
| 1557 | 1557 | /** |
@@ -1561,21 +1561,21 @@ discard block |
||
| 1561 | 1561 | * @param string state |
| 1562 | 1562 | * @return string |
| 1563 | 1563 | */ |
| 1564 | -function getpaid_get_states_select_markup( $country, $state, $placeholder, $label, $help_text, $required = false, $wrapper_class = 'col-12', $field_name = 'wpinv_state' ) { |
|
| 1564 | +function getpaid_get_states_select_markup($country, $state, $placeholder, $label, $help_text, $required = false, $wrapper_class = 'col-12', $field_name = 'wpinv_state') { |
|
| 1565 | 1565 | |
| 1566 | - $states = wpinv_get_country_states( $country ); |
|
| 1567 | - $uniqid = uniqid( '_' ); |
|
| 1566 | + $states = wpinv_get_country_states($country); |
|
| 1567 | + $uniqid = uniqid('_'); |
|
| 1568 | 1568 | |
| 1569 | - if ( ! empty( $states ) ) { |
|
| 1569 | + if (!empty($states)) { |
|
| 1570 | 1570 | |
| 1571 | - return aui()->select( array( |
|
| 1571 | + return aui()->select(array( |
|
| 1572 | 1572 | 'options' => $states, |
| 1573 | - 'name' => esc_attr( $field_name ), |
|
| 1574 | - 'id' => sanitize_html_class( $field_name ) . $uniqid, |
|
| 1575 | - 'value' => sanitize_text_field( $state ), |
|
| 1573 | + 'name' => esc_attr($field_name), |
|
| 1574 | + 'id' => sanitize_html_class($field_name) . $uniqid, |
|
| 1575 | + 'value' => sanitize_text_field($state), |
|
| 1576 | 1576 | 'placeholder' => $placeholder, |
| 1577 | 1577 | 'required' => $required, |
| 1578 | - 'label' => wp_kses_post( $label ), |
|
| 1578 | + 'label' => wp_kses_post($label), |
|
| 1579 | 1579 | 'label_type' => 'vertical', |
| 1580 | 1580 | 'help_text' => $help_text, |
| 1581 | 1581 | 'class' => 'getpaid-address-field wpinv_state', |
@@ -1590,14 +1590,14 @@ discard block |
||
| 1590 | 1590 | |
| 1591 | 1591 | return aui()->input( |
| 1592 | 1592 | array( |
| 1593 | - 'name' => esc_attr( $field_name ), |
|
| 1594 | - 'id' => sanitize_html_class( $field_name ) . $uniqid, |
|
| 1593 | + 'name' => esc_attr($field_name), |
|
| 1594 | + 'id' => sanitize_html_class($field_name) . $uniqid, |
|
| 1595 | 1595 | 'placeholder' => $placeholder, |
| 1596 | 1596 | 'required' => $required, |
| 1597 | - 'label' => wp_kses_post( $label ), |
|
| 1597 | + 'label' => wp_kses_post($label), |
|
| 1598 | 1598 | 'label_type' => 'vertical', |
| 1599 | 1599 | 'help_text' => $help_text, |
| 1600 | - 'value' => sanitize_text_field( $state ), |
|
| 1600 | + 'value' => sanitize_text_field($state), |
|
| 1601 | 1601 | 'class' => 'getpaid-address-field wpinv_state', |
| 1602 | 1602 | 'wrap_class' => "$wrapper_class getpaid-address-field-wrapper__state", |
| 1603 | 1603 | 'label_class' => 'getpaid-address-field-label getpaid-address-field-label__state', |
@@ -1615,16 +1615,16 @@ discard block |
||
| 1615 | 1615 | * @param array $element |
| 1616 | 1616 | * @return string |
| 1617 | 1617 | */ |
| 1618 | -function getpaid_get_form_element_grid_class( $element ) { |
|
| 1618 | +function getpaid_get_form_element_grid_class($element) { |
|
| 1619 | 1619 | |
| 1620 | 1620 | $class = "col-12"; |
| 1621 | - $width = empty( $element['grid_width'] ) ? 'full' : $element['grid_width']; |
|
| 1621 | + $width = empty($element['grid_width']) ? 'full' : $element['grid_width']; |
|
| 1622 | 1622 | |
| 1623 | - if ( $width == 'half' ) { |
|
| 1623 | + if ($width == 'half') { |
|
| 1624 | 1624 | $class = "col-12 col-md-6"; |
| 1625 | 1625 | } |
| 1626 | 1626 | |
| 1627 | - if ( $width == 'third' ) { |
|
| 1627 | + if ($width == 'third') { |
|
| 1628 | 1628 | $class = "col-12 col-md-4"; |
| 1629 | 1629 | } |
| 1630 | 1630 | |
@@ -15,125 +15,125 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | class WPInv_Subscription extends GetPaid_Data { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Which data store to load. |
|
| 20 | - * |
|
| 21 | - * @var string |
|
| 22 | - */ |
|
| 23 | - protected $data_store_name = 'subscription'; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * This is the name of this object type. |
|
| 27 | - * |
|
| 28 | - * @var string |
|
| 29 | - */ |
|
| 30 | - protected $object_type = 'subscription'; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Item Data array. This is the core item data exposed in APIs. |
|
| 34 | - * |
|
| 35 | - * @since 1.0.19 |
|
| 36 | - * @var array |
|
| 37 | - */ |
|
| 38 | - protected $data = array( |
|
| 39 | - 'customer_id' => 0, |
|
| 40 | - 'frequency' => 1, |
|
| 41 | - 'period' => 'D', |
|
| 42 | - 'initial_amount' => null, |
|
| 43 | - 'recurring_amount' => null, |
|
| 44 | - 'bill_times' => 0, |
|
| 45 | - 'transaction_id' => '', |
|
| 46 | - 'parent_payment_id' => null, |
|
| 47 | - 'product_id' => 0, |
|
| 48 | - 'created' => '0000-00-00 00:00:00', |
|
| 49 | - 'expiration' => '0000-00-00 00:00:00', |
|
| 50 | - 'trial_period' => '', |
|
| 51 | - 'status' => 'pending', |
|
| 52 | - 'profile_id' => '', |
|
| 53 | - 'gateway' => '', |
|
| 54 | - 'customer' => '', |
|
| 55 | - ); |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Stores the status transition information. |
|
| 59 | - * |
|
| 60 | - * @since 1.0.19 |
|
| 61 | - * @var bool |
|
| 62 | - */ |
|
| 63 | - protected $status_transition = false; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Get the subscription if ID is passed, otherwise the subscription is new and empty. |
|
| 67 | - * |
|
| 68 | - * @param int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read. |
|
| 69 | - * @param bool $deprecated |
|
| 70 | - */ |
|
| 71 | - function __construct( $subscription = 0, $deprecated = false ) { |
|
| 72 | - |
|
| 73 | - parent::__construct( $subscription ); |
|
| 74 | - |
|
| 75 | - if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) { |
|
| 76 | - $this->set_id( $subscription ); |
|
| 77 | - } elseif ( $subscription instanceof self ) { |
|
| 78 | - $this->set_id( $subscription->get_id() ); |
|
| 79 | - } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) { |
|
| 80 | - $this->set_id( $subscription_id ); |
|
| 81 | - } elseif ( ! empty( $subscription->id ) ) { |
|
| 82 | - $this->set_id( $subscription->id ); |
|
| 83 | - } else { |
|
| 84 | - $this->set_object_read( true ); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - // Load the datastore. |
|
| 88 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 89 | - |
|
| 90 | - if ( $this->get_id() > 0 ) { |
|
| 91 | - $this->data_store->read( $this ); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Given an invoice id, profile id, transaction id, it returns the subscription's id. |
|
| 98 | - * |
|
| 99 | - * |
|
| 100 | - * @static |
|
| 101 | - * @param string $value |
|
| 102 | - * @param string $field Either invoice_id, transaction_id or profile_id. |
|
| 103 | - * @since 1.0.19 |
|
| 104 | - * @return int |
|
| 105 | - */ |
|
| 106 | - public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) { |
|
| 18 | + /** |
|
| 19 | + * Which data store to load. |
|
| 20 | + * |
|
| 21 | + * @var string |
|
| 22 | + */ |
|
| 23 | + protected $data_store_name = 'subscription'; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * This is the name of this object type. |
|
| 27 | + * |
|
| 28 | + * @var string |
|
| 29 | + */ |
|
| 30 | + protected $object_type = 'subscription'; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Item Data array. This is the core item data exposed in APIs. |
|
| 34 | + * |
|
| 35 | + * @since 1.0.19 |
|
| 36 | + * @var array |
|
| 37 | + */ |
|
| 38 | + protected $data = array( |
|
| 39 | + 'customer_id' => 0, |
|
| 40 | + 'frequency' => 1, |
|
| 41 | + 'period' => 'D', |
|
| 42 | + 'initial_amount' => null, |
|
| 43 | + 'recurring_amount' => null, |
|
| 44 | + 'bill_times' => 0, |
|
| 45 | + 'transaction_id' => '', |
|
| 46 | + 'parent_payment_id' => null, |
|
| 47 | + 'product_id' => 0, |
|
| 48 | + 'created' => '0000-00-00 00:00:00', |
|
| 49 | + 'expiration' => '0000-00-00 00:00:00', |
|
| 50 | + 'trial_period' => '', |
|
| 51 | + 'status' => 'pending', |
|
| 52 | + 'profile_id' => '', |
|
| 53 | + 'gateway' => '', |
|
| 54 | + 'customer' => '', |
|
| 55 | + ); |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Stores the status transition information. |
|
| 59 | + * |
|
| 60 | + * @since 1.0.19 |
|
| 61 | + * @var bool |
|
| 62 | + */ |
|
| 63 | + protected $status_transition = false; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Get the subscription if ID is passed, otherwise the subscription is new and empty. |
|
| 67 | + * |
|
| 68 | + * @param int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read. |
|
| 69 | + * @param bool $deprecated |
|
| 70 | + */ |
|
| 71 | + function __construct( $subscription = 0, $deprecated = false ) { |
|
| 72 | + |
|
| 73 | + parent::__construct( $subscription ); |
|
| 74 | + |
|
| 75 | + if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) { |
|
| 76 | + $this->set_id( $subscription ); |
|
| 77 | + } elseif ( $subscription instanceof self ) { |
|
| 78 | + $this->set_id( $subscription->get_id() ); |
|
| 79 | + } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) { |
|
| 80 | + $this->set_id( $subscription_id ); |
|
| 81 | + } elseif ( ! empty( $subscription->id ) ) { |
|
| 82 | + $this->set_id( $subscription->id ); |
|
| 83 | + } else { |
|
| 84 | + $this->set_object_read( true ); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + // Load the datastore. |
|
| 88 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 89 | + |
|
| 90 | + if ( $this->get_id() > 0 ) { |
|
| 91 | + $this->data_store->read( $this ); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Given an invoice id, profile id, transaction id, it returns the subscription's id. |
|
| 98 | + * |
|
| 99 | + * |
|
| 100 | + * @static |
|
| 101 | + * @param string $value |
|
| 102 | + * @param string $field Either invoice_id, transaction_id or profile_id. |
|
| 103 | + * @since 1.0.19 |
|
| 104 | + * @return int |
|
| 105 | + */ |
|
| 106 | + public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) { |
|
| 107 | 107 | global $wpdb; |
| 108 | 108 | |
| 109 | - // Trim the value. |
|
| 110 | - $value = trim( $value ); |
|
| 109 | + // Trim the value. |
|
| 110 | + $value = trim( $value ); |
|
| 111 | 111 | |
| 112 | - if ( empty( $value ) ) { |
|
| 113 | - return 0; |
|
| 114 | - } |
|
| 112 | + if ( empty( $value ) ) { |
|
| 113 | + return 0; |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - if ( 'invoice_id' == $field ) { |
|
| 117 | - $field = 'parent_payment_id'; |
|
| 118 | - } |
|
| 116 | + if ( 'invoice_id' == $field ) { |
|
| 117 | + $field = 'parent_payment_id'; |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | 120 | // Valid fields. |
| 121 | 121 | $fields = array( |
| 122 | - 'parent_payment_id', |
|
| 123 | - 'transaction_id', |
|
| 124 | - 'profile_id' |
|
| 125 | - ); |
|
| 126 | - |
|
| 127 | - // Ensure a field has been passed. |
|
| 128 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 129 | - return 0; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - // Maybe retrieve from the cache. |
|
| 133 | - $subscription_id = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
| 134 | - if ( ! empty( $subscription_id ) ) { |
|
| 135 | - return $subscription_id; |
|
| 136 | - } |
|
| 122 | + 'parent_payment_id', |
|
| 123 | + 'transaction_id', |
|
| 124 | + 'profile_id' |
|
| 125 | + ); |
|
| 126 | + |
|
| 127 | + // Ensure a field has been passed. |
|
| 128 | + if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 129 | + return 0; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + // Maybe retrieve from the cache. |
|
| 133 | + $subscription_id = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
| 134 | + if ( ! empty( $subscription_id ) ) { |
|
| 135 | + return $subscription_id; |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | 138 | // Fetch from the db. |
| 139 | 139 | $table = $wpdb->prefix . 'wpinv_subscriptions'; |
@@ -141,34 +141,34 @@ discard block |
||
| 141 | 141 | $wpdb->prepare( "SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value ) |
| 142 | 142 | ); |
| 143 | 143 | |
| 144 | - if ( empty( $subscription_id ) ) { |
|
| 145 | - return 0; |
|
| 146 | - } |
|
| 144 | + if ( empty( $subscription_id ) ) { |
|
| 145 | + return 0; |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | - // Update the cache with our data. |
|
| 149 | - wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
| 148 | + // Update the cache with our data. |
|
| 149 | + wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
| 150 | 150 | |
| 151 | - return $subscription_id; |
|
| 152 | - } |
|
| 151 | + return $subscription_id; |
|
| 152 | + } |
|
| 153 | 153 | |
| 154 | - /** |
|
| 154 | + /** |
|
| 155 | 155 | * Clears the subscription's cache. |
| 156 | 156 | */ |
| 157 | 157 | public function clear_cache() { |
| 158 | - wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' ); |
|
| 159 | - wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' ); |
|
| 160 | - wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' ); |
|
| 161 | - wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' ); |
|
| 162 | - } |
|
| 158 | + wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' ); |
|
| 159 | + wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' ); |
|
| 160 | + wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' ); |
|
| 161 | + wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' ); |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | - /** |
|
| 164 | + /** |
|
| 165 | 165 | * Checks if a subscription key is set. |
| 166 | 166 | */ |
| 167 | 167 | public function _isset( $key ) { |
| 168 | 168 | return isset( $this->data[$key] ) || method_exists( $this, "get_$key" ); |
| 169 | - } |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - /* |
|
| 171 | + /* |
|
| 172 | 172 | |-------------------------------------------------------------------------- |
| 173 | 173 | | CRUD methods |
| 174 | 174 | |-------------------------------------------------------------------------- |
@@ -177,545 +177,545 @@ discard block |
||
| 177 | 177 | | |
| 178 | 178 | */ |
| 179 | 179 | |
| 180 | - /* |
|
| 181 | - |-------------------------------------------------------------------------- |
|
| 182 | - | Getters |
|
| 183 | - |-------------------------------------------------------------------------- |
|
| 184 | - */ |
|
| 180 | + /* |
|
| 181 | + |-------------------------------------------------------------------------- |
|
| 182 | + | Getters |
|
| 183 | + |-------------------------------------------------------------------------- |
|
| 184 | + */ |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * Get customer id. |
|
| 188 | + * |
|
| 189 | + * @since 1.0.19 |
|
| 190 | + * @param string $context View or edit context. |
|
| 191 | + * @return int |
|
| 192 | + */ |
|
| 193 | + public function get_customer_id( $context = 'view' ) { |
|
| 194 | + return (int) $this->get_prop( 'customer_id', $context ); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * Get customer information. |
|
| 199 | + * |
|
| 200 | + * @since 1.0.19 |
|
| 201 | + * @param string $context View or edit context. |
|
| 202 | + * @return WP_User|false WP_User object on success, false on failure. |
|
| 203 | + */ |
|
| 204 | + public function get_customer( $context = 'view' ) { |
|
| 205 | + return get_userdata( $this->get_customer_id( $context ) ); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * Get parent invoice id. |
|
| 210 | + * |
|
| 211 | + * @since 1.0.19 |
|
| 212 | + * @param string $context View or edit context. |
|
| 213 | + * @return int |
|
| 214 | + */ |
|
| 215 | + public function get_parent_invoice_id( $context = 'view' ) { |
|
| 216 | + return (int) $this->get_prop( 'parent_payment_id', $context ); |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * Alias for self::get_parent_invoice_id(). |
|
| 221 | + * |
|
| 222 | + * @since 1.0.19 |
|
| 223 | + * @param string $context View or edit context. |
|
| 224 | + * @return int |
|
| 225 | + */ |
|
| 226 | + public function get_parent_payment_id( $context = 'view' ) { |
|
| 227 | + return $this->get_parent_invoice_id( $context ); |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * Alias for self::get_parent_invoice_id(). |
|
| 232 | + * |
|
| 233 | + * @since 1.0.0 |
|
| 234 | + * @return int |
|
| 235 | + */ |
|
| 236 | + public function get_original_payment_id( $context = 'view' ) { |
|
| 237 | + return $this->get_parent_invoice_id( $context ); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * Get parent invoice. |
|
| 242 | + * |
|
| 243 | + * @since 1.0.19 |
|
| 244 | + * @param string $context View or edit context. |
|
| 245 | + * @return WPInv_Invoice |
|
| 246 | + */ |
|
| 247 | + public function get_parent_invoice( $context = 'view' ) { |
|
| 248 | + return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) ); |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * Alias for self::get_parent_invoice(). |
|
| 253 | + * |
|
| 254 | + * @since 1.0.19 |
|
| 255 | + * @param string $context View or edit context. |
|
| 256 | + * @return WPInv_Invoice |
|
| 257 | + */ |
|
| 258 | + public function get_parent_payment( $context = 'view' ) { |
|
| 259 | + return $this->get_parent_invoice( $context ); |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * Get subscription's product id. |
|
| 264 | + * |
|
| 265 | + * @since 1.0.19 |
|
| 266 | + * @param string $context View or edit context. |
|
| 267 | + * @return int |
|
| 268 | + */ |
|
| 269 | + public function get_product_id( $context = 'view' ) { |
|
| 270 | + return (int) $this->get_prop( 'product_id', $context ); |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + /** |
|
| 274 | + * Get the subscription product. |
|
| 275 | + * |
|
| 276 | + * @since 1.0.19 |
|
| 277 | + * @param string $context View or edit context. |
|
| 278 | + * @return WPInv_Item |
|
| 279 | + */ |
|
| 280 | + public function get_product( $context = 'view' ) { |
|
| 281 | + return new WPInv_Item( $this->get_product_id( $context ) ); |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + /** |
|
| 285 | + * Get parent invoice's gateway. |
|
| 286 | + * |
|
| 287 | + * Here for backwards compatibility. |
|
| 288 | + * |
|
| 289 | + * @since 1.0.19 |
|
| 290 | + * @param string $context View or edit context. |
|
| 291 | + * @return string |
|
| 292 | + */ |
|
| 293 | + public function get_gateway( $context = 'view' ) { |
|
| 294 | + return $this->get_parent_invoice( $context )->get_gateway(); |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + /** |
|
| 298 | + * Get the period of a renewal. |
|
| 299 | + * |
|
| 300 | + * @since 1.0.19 |
|
| 301 | + * @param string $context View or edit context. |
|
| 302 | + * @return string |
|
| 303 | + */ |
|
| 304 | + public function get_period( $context = 'view' ) { |
|
| 305 | + return $this->get_prop( 'period', $context ); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * Get number of periods each renewal is valid for. |
|
| 310 | + * |
|
| 311 | + * @since 1.0.19 |
|
| 312 | + * @param string $context View or edit context. |
|
| 313 | + * @return int |
|
| 314 | + */ |
|
| 315 | + public function get_frequency( $context = 'view' ) { |
|
| 316 | + return (int) $this->get_prop( 'frequency', $context ); |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * Get the initial amount for the subscription. |
|
| 321 | + * |
|
| 322 | + * @since 1.0.19 |
|
| 323 | + * @param string $context View or edit context. |
|
| 324 | + * @return float |
|
| 325 | + */ |
|
| 326 | + public function get_initial_amount( $context = 'view' ) { |
|
| 327 | + return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) ); |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * Get the recurring amount for the subscription. |
|
| 332 | + * |
|
| 333 | + * @since 1.0.19 |
|
| 334 | + * @param string $context View or edit context. |
|
| 335 | + * @return float |
|
| 336 | + */ |
|
| 337 | + public function get_recurring_amount( $context = 'view' ) { |
|
| 338 | + return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) ); |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + /** |
|
| 342 | + * Get number of times that this subscription can be renewed. |
|
| 343 | + * |
|
| 344 | + * @since 1.0.19 |
|
| 345 | + * @param string $context View or edit context. |
|
| 346 | + * @return int |
|
| 347 | + */ |
|
| 348 | + public function get_bill_times( $context = 'view' ) { |
|
| 349 | + return (int) $this->get_prop( 'bill_times', $context ); |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * Get transaction id of this subscription's parent invoice. |
|
| 354 | + * |
|
| 355 | + * @since 1.0.19 |
|
| 356 | + * @param string $context View or edit context. |
|
| 357 | + * @return string |
|
| 358 | + */ |
|
| 359 | + public function get_transaction_id( $context = 'view' ) { |
|
| 360 | + return $this->get_prop( 'transaction_id', $context ); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + /** |
|
| 364 | + * Get the date that the subscription was created. |
|
| 365 | + * |
|
| 366 | + * @since 1.0.19 |
|
| 367 | + * @param string $context View or edit context. |
|
| 368 | + * @return string |
|
| 369 | + */ |
|
| 370 | + public function get_created( $context = 'view' ) { |
|
| 371 | + return $this->get_prop( 'created', $context ); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + /** |
|
| 375 | + * Alias for self::get_created(). |
|
| 376 | + * |
|
| 377 | + * @since 1.0.19 |
|
| 378 | + * @param string $context View or edit context. |
|
| 379 | + * @return string |
|
| 380 | + */ |
|
| 381 | + public function get_date_created( $context = 'view' ) { |
|
| 382 | + return $this->get_created( $context ); |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * Retrieves the creation date in a timestamp |
|
| 387 | + * |
|
| 388 | + * @since 1.0.0 |
|
| 389 | + * @return int |
|
| 390 | + */ |
|
| 391 | + public function get_time_created() { |
|
| 392 | + $created = $this->get_date_created(); |
|
| 393 | + return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) ); |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + /** |
|
| 397 | + * Get GMT date when the subscription was created. |
|
| 398 | + * |
|
| 399 | + * @since 1.0.19 |
|
| 400 | + * @param string $context View or edit context. |
|
| 401 | + * @return string |
|
| 402 | + */ |
|
| 403 | + public function get_date_created_gmt( $context = 'view' ) { |
|
| 404 | + $date = $this->get_date_created( $context ); |
|
| 405 | + |
|
| 406 | + if ( $date ) { |
|
| 407 | + $date = get_gmt_from_date( $date ); |
|
| 408 | + } |
|
| 409 | + return $date; |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + /** |
|
| 413 | + * Get the date that the subscription will renew. |
|
| 414 | + * |
|
| 415 | + * @since 1.0.19 |
|
| 416 | + * @param string $context View or edit context. |
|
| 417 | + * @return string |
|
| 418 | + */ |
|
| 419 | + public function get_next_renewal_date( $context = 'view' ) { |
|
| 420 | + return $this->get_prop( 'expiration', $context ); |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + /** |
|
| 424 | + * Alias for self::get_next_renewal_date(). |
|
| 425 | + * |
|
| 426 | + * @since 1.0.19 |
|
| 427 | + * @param string $context View or edit context. |
|
| 428 | + * @return string |
|
| 429 | + */ |
|
| 430 | + public function get_expiration( $context = 'view' ) { |
|
| 431 | + return $this->get_next_renewal_date( $context ); |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * Retrieves the expiration date in a timestamp |
|
| 436 | + * |
|
| 437 | + * @since 1.0.0 |
|
| 438 | + * @return int |
|
| 439 | + */ |
|
| 440 | + public function get_expiration_time() { |
|
| 441 | + $expiration = $this->get_expiration(); |
|
| 442 | + |
|
| 443 | + if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
| 444 | + return current_time( 'timestamp' ); |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + $expiration = strtotime( $expiration, current_time( 'timestamp' ) ); |
|
| 448 | + return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration; |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * Get GMT date when the subscription will renew. |
|
| 453 | + * |
|
| 454 | + * @since 1.0.19 |
|
| 455 | + * @param string $context View or edit context. |
|
| 456 | + * @return string |
|
| 457 | + */ |
|
| 458 | + public function get_next_renewal_date_gmt( $context = 'view' ) { |
|
| 459 | + $date = $this->get_next_renewal_date( $context ); |
|
| 460 | + |
|
| 461 | + if ( $date ) { |
|
| 462 | + $date = get_gmt_from_date( $date ); |
|
| 463 | + } |
|
| 464 | + return $date; |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + /** |
|
| 468 | + * Get the subscription's trial period. |
|
| 469 | + * |
|
| 470 | + * @since 1.0.19 |
|
| 471 | + * @param string $context View or edit context. |
|
| 472 | + * @return string |
|
| 473 | + */ |
|
| 474 | + public function get_trial_period( $context = 'view' ) { |
|
| 475 | + return $this->get_prop( 'trial_period', $context ); |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + /** |
|
| 479 | + * Get the subscription's status. |
|
| 480 | + * |
|
| 481 | + * @since 1.0.19 |
|
| 482 | + * @param string $context View or edit context. |
|
| 483 | + * @return string |
|
| 484 | + */ |
|
| 485 | + public function get_status( $context = 'view' ) { |
|
| 486 | + return $this->get_prop( 'status', $context ); |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + /** |
|
| 490 | + * Get the subscription's profile id. |
|
| 491 | + * |
|
| 492 | + * @since 1.0.19 |
|
| 493 | + * @param string $context View or edit context. |
|
| 494 | + * @return string |
|
| 495 | + */ |
|
| 496 | + public function get_profile_id( $context = 'view' ) { |
|
| 497 | + return $this->get_prop( 'profile_id', $context ); |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + /* |
|
| 501 | + |-------------------------------------------------------------------------- |
|
| 502 | + | Setters |
|
| 503 | + |-------------------------------------------------------------------------- |
|
| 504 | + */ |
|
| 505 | + |
|
| 506 | + /** |
|
| 507 | + * Set customer id. |
|
| 508 | + * |
|
| 509 | + * @since 1.0.19 |
|
| 510 | + * @param int $value The customer's id. |
|
| 511 | + */ |
|
| 512 | + public function set_customer_id( $value ) { |
|
| 513 | + $this->set_prop( 'customer_id', (int) $value ); |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + /** |
|
| 517 | + * Set parent invoice id. |
|
| 518 | + * |
|
| 519 | + * @since 1.0.19 |
|
| 520 | + * @param int $value The parent invoice id. |
|
| 521 | + */ |
|
| 522 | + public function set_parent_invoice_id( $value ) { |
|
| 523 | + $this->set_prop( 'parent_payment_id', (int) $value ); |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + /** |
|
| 527 | + * Alias for self::set_parent_invoice_id(). |
|
| 528 | + * |
|
| 529 | + * @since 1.0.19 |
|
| 530 | + * @param int $value The parent invoice id. |
|
| 531 | + */ |
|
| 532 | + public function set_parent_payment_id( $value ) { |
|
| 533 | + $this->set_parent_invoice_id( $value ); |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + /** |
|
| 537 | + * Alias for self::set_parent_invoice_id(). |
|
| 538 | + * |
|
| 539 | + * @since 1.0.19 |
|
| 540 | + * @param int $value The parent invoice id. |
|
| 541 | + */ |
|
| 542 | + public function set_original_payment_id( $value ) { |
|
| 543 | + $this->set_parent_invoice_id( $value ); |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + /** |
|
| 547 | + * Set subscription's product id. |
|
| 548 | + * |
|
| 549 | + * @since 1.0.19 |
|
| 550 | + * @param int $value The subscription product id. |
|
| 551 | + */ |
|
| 552 | + public function set_product_id( $value ) { |
|
| 553 | + $this->set_prop( 'product_id', (int) $value ); |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + /** |
|
| 557 | + * Set the period of a renewal. |
|
| 558 | + * |
|
| 559 | + * @since 1.0.19 |
|
| 560 | + * @param string $value The renewal period. |
|
| 561 | + */ |
|
| 562 | + public function set_period( $value ) { |
|
| 563 | + $this->set_prop( 'period', $value ); |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + /** |
|
| 567 | + * Set number of periods each renewal is valid for. |
|
| 568 | + * |
|
| 569 | + * @since 1.0.19 |
|
| 570 | + * @param int $value The subscription frequency. |
|
| 571 | + */ |
|
| 572 | + public function set_frequency( $value ) { |
|
| 573 | + $value = empty( $value ) ? 1 : (int) $value; |
|
| 574 | + $this->set_prop( 'frequency', absint( $value ) ); |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + /** |
|
| 578 | + * Set the initial amount for the subscription. |
|
| 579 | + * |
|
| 580 | + * @since 1.0.19 |
|
| 581 | + * @param float $value The initial subcription amount. |
|
| 582 | + */ |
|
| 583 | + public function set_initial_amount( $value ) { |
|
| 584 | + $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) ); |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + /** |
|
| 588 | + * Set the recurring amount for the subscription. |
|
| 589 | + * |
|
| 590 | + * @since 1.0.19 |
|
| 591 | + * @param float $value The recurring subcription amount. |
|
| 592 | + */ |
|
| 593 | + public function set_recurring_amount( $value ) { |
|
| 594 | + $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) ); |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + /** |
|
| 598 | + * Set number of times that this subscription can be renewed. |
|
| 599 | + * |
|
| 600 | + * @since 1.0.19 |
|
| 601 | + * @param int $value Bill times. |
|
| 602 | + */ |
|
| 603 | + public function set_bill_times( $value ) { |
|
| 604 | + $this->set_prop( 'bill_times', (int) $value ); |
|
| 605 | + } |
|
| 606 | + |
|
| 607 | + /** |
|
| 608 | + * Get transaction id of this subscription's parent invoice. |
|
| 609 | + * |
|
| 610 | + * @since 1.0.19 |
|
| 611 | + * @param string $value Bill times. |
|
| 612 | + */ |
|
| 613 | + public function set_transaction_id( $value ) { |
|
| 614 | + $this->set_prop( 'transaction_id', sanitize_text_field( $value ) ); |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + /** |
|
| 618 | + * Set date when this subscription started. |
|
| 619 | + * |
|
| 620 | + * @since 1.0.19 |
|
| 621 | + * @param string $value strtotime compliant date. |
|
| 622 | + */ |
|
| 623 | + public function set_created( $value ) { |
|
| 624 | + $date = strtotime( $value ); |
|
| 625 | + |
|
| 626 | + if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
| 627 | + $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) ); |
|
| 628 | + return; |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + $this->set_prop( 'created', '' ); |
|
| 185 | 632 | |
| 186 | - /** |
|
| 187 | - * Get customer id. |
|
| 188 | - * |
|
| 189 | - * @since 1.0.19 |
|
| 190 | - * @param string $context View or edit context. |
|
| 191 | - * @return int |
|
| 192 | - */ |
|
| 193 | - public function get_customer_id( $context = 'view' ) { |
|
| 194 | - return (int) $this->get_prop( 'customer_id', $context ); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * Get customer information. |
|
| 199 | - * |
|
| 200 | - * @since 1.0.19 |
|
| 201 | - * @param string $context View or edit context. |
|
| 202 | - * @return WP_User|false WP_User object on success, false on failure. |
|
| 203 | - */ |
|
| 204 | - public function get_customer( $context = 'view' ) { |
|
| 205 | - return get_userdata( $this->get_customer_id( $context ) ); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * Get parent invoice id. |
|
| 210 | - * |
|
| 211 | - * @since 1.0.19 |
|
| 212 | - * @param string $context View or edit context. |
|
| 213 | - * @return int |
|
| 214 | - */ |
|
| 215 | - public function get_parent_invoice_id( $context = 'view' ) { |
|
| 216 | - return (int) $this->get_prop( 'parent_payment_id', $context ); |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * Alias for self::get_parent_invoice_id(). |
|
| 221 | - * |
|
| 222 | - * @since 1.0.19 |
|
| 223 | - * @param string $context View or edit context. |
|
| 224 | - * @return int |
|
| 225 | - */ |
|
| 226 | - public function get_parent_payment_id( $context = 'view' ) { |
|
| 227 | - return $this->get_parent_invoice_id( $context ); |
|
| 228 | - } |
|
| 633 | + } |
|
| 229 | 634 | |
| 230 | - /** |
|
| 231 | - * Alias for self::get_parent_invoice_id(). |
|
| 635 | + /** |
|
| 636 | + * Alias for self::set_created(). |
|
| 232 | 637 | * |
| 233 | - * @since 1.0.0 |
|
| 234 | - * @return int |
|
| 638 | + * @since 1.0.19 |
|
| 639 | + * @param string $value strtotime compliant date. |
|
| 235 | 640 | */ |
| 236 | - public function get_original_payment_id( $context = 'view' ) { |
|
| 237 | - return $this->get_parent_invoice_id( $context ); |
|
| 641 | + public function set_date_created( $value ) { |
|
| 642 | + $this->set_created( $value ); |
|
| 238 | 643 | } |
| 239 | 644 | |
| 240 | - /** |
|
| 241 | - * Get parent invoice. |
|
| 242 | - * |
|
| 243 | - * @since 1.0.19 |
|
| 244 | - * @param string $context View or edit context. |
|
| 245 | - * @return WPInv_Invoice |
|
| 246 | - */ |
|
| 247 | - public function get_parent_invoice( $context = 'view' ) { |
|
| 248 | - return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) ); |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * Alias for self::get_parent_invoice(). |
|
| 253 | - * |
|
| 254 | - * @since 1.0.19 |
|
| 255 | - * @param string $context View or edit context. |
|
| 256 | - * @return WPInv_Invoice |
|
| 257 | - */ |
|
| 258 | - public function get_parent_payment( $context = 'view' ) { |
|
| 259 | - return $this->get_parent_invoice( $context ); |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * Get subscription's product id. |
|
| 264 | - * |
|
| 265 | - * @since 1.0.19 |
|
| 266 | - * @param string $context View or edit context. |
|
| 267 | - * @return int |
|
| 268 | - */ |
|
| 269 | - public function get_product_id( $context = 'view' ) { |
|
| 270 | - return (int) $this->get_prop( 'product_id', $context ); |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - /** |
|
| 274 | - * Get the subscription product. |
|
| 275 | - * |
|
| 276 | - * @since 1.0.19 |
|
| 277 | - * @param string $context View or edit context. |
|
| 278 | - * @return WPInv_Item |
|
| 279 | - */ |
|
| 280 | - public function get_product( $context = 'view' ) { |
|
| 281 | - return new WPInv_Item( $this->get_product_id( $context ) ); |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - /** |
|
| 285 | - * Get parent invoice's gateway. |
|
| 286 | - * |
|
| 287 | - * Here for backwards compatibility. |
|
| 288 | - * |
|
| 289 | - * @since 1.0.19 |
|
| 290 | - * @param string $context View or edit context. |
|
| 291 | - * @return string |
|
| 292 | - */ |
|
| 293 | - public function get_gateway( $context = 'view' ) { |
|
| 294 | - return $this->get_parent_invoice( $context )->get_gateway(); |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - /** |
|
| 298 | - * Get the period of a renewal. |
|
| 299 | - * |
|
| 300 | - * @since 1.0.19 |
|
| 301 | - * @param string $context View or edit context. |
|
| 302 | - * @return string |
|
| 303 | - */ |
|
| 304 | - public function get_period( $context = 'view' ) { |
|
| 305 | - return $this->get_prop( 'period', $context ); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * Get number of periods each renewal is valid for. |
|
| 310 | - * |
|
| 311 | - * @since 1.0.19 |
|
| 312 | - * @param string $context View or edit context. |
|
| 313 | - * @return int |
|
| 314 | - */ |
|
| 315 | - public function get_frequency( $context = 'view' ) { |
|
| 316 | - return (int) $this->get_prop( 'frequency', $context ); |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * Get the initial amount for the subscription. |
|
| 321 | - * |
|
| 322 | - * @since 1.0.19 |
|
| 323 | - * @param string $context View or edit context. |
|
| 324 | - * @return float |
|
| 325 | - */ |
|
| 326 | - public function get_initial_amount( $context = 'view' ) { |
|
| 327 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) ); |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * Get the recurring amount for the subscription. |
|
| 332 | - * |
|
| 333 | - * @since 1.0.19 |
|
| 334 | - * @param string $context View or edit context. |
|
| 335 | - * @return float |
|
| 336 | - */ |
|
| 337 | - public function get_recurring_amount( $context = 'view' ) { |
|
| 338 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) ); |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - /** |
|
| 342 | - * Get number of times that this subscription can be renewed. |
|
| 343 | - * |
|
| 344 | - * @since 1.0.19 |
|
| 345 | - * @param string $context View or edit context. |
|
| 346 | - * @return int |
|
| 347 | - */ |
|
| 348 | - public function get_bill_times( $context = 'view' ) { |
|
| 349 | - return (int) $this->get_prop( 'bill_times', $context ); |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * Get transaction id of this subscription's parent invoice. |
|
| 354 | - * |
|
| 355 | - * @since 1.0.19 |
|
| 356 | - * @param string $context View or edit context. |
|
| 357 | - * @return string |
|
| 358 | - */ |
|
| 359 | - public function get_transaction_id( $context = 'view' ) { |
|
| 360 | - return $this->get_prop( 'transaction_id', $context ); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - /** |
|
| 364 | - * Get the date that the subscription was created. |
|
| 365 | - * |
|
| 366 | - * @since 1.0.19 |
|
| 367 | - * @param string $context View or edit context. |
|
| 368 | - * @return string |
|
| 369 | - */ |
|
| 370 | - public function get_created( $context = 'view' ) { |
|
| 371 | - return $this->get_prop( 'created', $context ); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - /** |
|
| 375 | - * Alias for self::get_created(). |
|
| 376 | - * |
|
| 377 | - * @since 1.0.19 |
|
| 378 | - * @param string $context View or edit context. |
|
| 379 | - * @return string |
|
| 380 | - */ |
|
| 381 | - public function get_date_created( $context = 'view' ) { |
|
| 382 | - return $this->get_created( $context ); |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * Retrieves the creation date in a timestamp |
|
| 387 | - * |
|
| 388 | - * @since 1.0.0 |
|
| 389 | - * @return int |
|
| 390 | - */ |
|
| 391 | - public function get_time_created() { |
|
| 392 | - $created = $this->get_date_created(); |
|
| 393 | - return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) ); |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - /** |
|
| 397 | - * Get GMT date when the subscription was created. |
|
| 398 | - * |
|
| 399 | - * @since 1.0.19 |
|
| 400 | - * @param string $context View or edit context. |
|
| 401 | - * @return string |
|
| 402 | - */ |
|
| 403 | - public function get_date_created_gmt( $context = 'view' ) { |
|
| 404 | - $date = $this->get_date_created( $context ); |
|
| 645 | + /** |
|
| 646 | + * Set the date that the subscription will renew. |
|
| 647 | + * |
|
| 648 | + * @since 1.0.19 |
|
| 649 | + * @param string $value strtotime compliant date. |
|
| 650 | + */ |
|
| 651 | + public function set_next_renewal_date( $value ) { |
|
| 652 | + $date = strtotime( $value ); |
|
| 405 | 653 | |
| 406 | - if ( $date ) { |
|
| 407 | - $date = get_gmt_from_date( $date ); |
|
| 654 | + if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
| 655 | + $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) ); |
|
| 656 | + return; |
|
| 408 | 657 | } |
| 409 | - return $date; |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - /** |
|
| 413 | - * Get the date that the subscription will renew. |
|
| 414 | - * |
|
| 415 | - * @since 1.0.19 |
|
| 416 | - * @param string $context View or edit context. |
|
| 417 | - * @return string |
|
| 418 | - */ |
|
| 419 | - public function get_next_renewal_date( $context = 'view' ) { |
|
| 420 | - return $this->get_prop( 'expiration', $context ); |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - /** |
|
| 424 | - * Alias for self::get_next_renewal_date(). |
|
| 425 | - * |
|
| 426 | - * @since 1.0.19 |
|
| 427 | - * @param string $context View or edit context. |
|
| 428 | - * @return string |
|
| 429 | - */ |
|
| 430 | - public function get_expiration( $context = 'view' ) { |
|
| 431 | - return $this->get_next_renewal_date( $context ); |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * Retrieves the expiration date in a timestamp |
|
| 436 | - * |
|
| 437 | - * @since 1.0.0 |
|
| 438 | - * @return int |
|
| 439 | - */ |
|
| 440 | - public function get_expiration_time() { |
|
| 441 | - $expiration = $this->get_expiration(); |
|
| 442 | - |
|
| 443 | - if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
| 444 | - return current_time( 'timestamp' ); |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - $expiration = strtotime( $expiration, current_time( 'timestamp' ) ); |
|
| 448 | - return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration; |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * Get GMT date when the subscription will renew. |
|
| 453 | - * |
|
| 454 | - * @since 1.0.19 |
|
| 455 | - * @param string $context View or edit context. |
|
| 456 | - * @return string |
|
| 457 | - */ |
|
| 458 | - public function get_next_renewal_date_gmt( $context = 'view' ) { |
|
| 459 | - $date = $this->get_next_renewal_date( $context ); |
|
| 460 | 658 | |
| 461 | - if ( $date ) { |
|
| 462 | - $date = get_gmt_from_date( $date ); |
|
| 463 | - } |
|
| 464 | - return $date; |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - /** |
|
| 468 | - * Get the subscription's trial period. |
|
| 469 | - * |
|
| 470 | - * @since 1.0.19 |
|
| 471 | - * @param string $context View or edit context. |
|
| 472 | - * @return string |
|
| 473 | - */ |
|
| 474 | - public function get_trial_period( $context = 'view' ) { |
|
| 475 | - return $this->get_prop( 'trial_period', $context ); |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - /** |
|
| 479 | - * Get the subscription's status. |
|
| 480 | - * |
|
| 481 | - * @since 1.0.19 |
|
| 482 | - * @param string $context View or edit context. |
|
| 483 | - * @return string |
|
| 484 | - */ |
|
| 485 | - public function get_status( $context = 'view' ) { |
|
| 486 | - return $this->get_prop( 'status', $context ); |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - /** |
|
| 490 | - * Get the subscription's profile id. |
|
| 491 | - * |
|
| 492 | - * @since 1.0.19 |
|
| 493 | - * @param string $context View or edit context. |
|
| 494 | - * @return string |
|
| 495 | - */ |
|
| 496 | - public function get_profile_id( $context = 'view' ) { |
|
| 497 | - return $this->get_prop( 'profile_id', $context ); |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - /* |
|
| 501 | - |-------------------------------------------------------------------------- |
|
| 502 | - | Setters |
|
| 503 | - |-------------------------------------------------------------------------- |
|
| 504 | - */ |
|
| 659 | + $this->set_prop( 'expiration', '' ); |
|
| 505 | 660 | |
| 506 | - /** |
|
| 507 | - * Set customer id. |
|
| 508 | - * |
|
| 509 | - * @since 1.0.19 |
|
| 510 | - * @param int $value The customer's id. |
|
| 511 | - */ |
|
| 512 | - public function set_customer_id( $value ) { |
|
| 513 | - $this->set_prop( 'customer_id', (int) $value ); |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - /** |
|
| 517 | - * Set parent invoice id. |
|
| 518 | - * |
|
| 519 | - * @since 1.0.19 |
|
| 520 | - * @param int $value The parent invoice id. |
|
| 521 | - */ |
|
| 522 | - public function set_parent_invoice_id( $value ) { |
|
| 523 | - $this->set_prop( 'parent_payment_id', (int) $value ); |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - /** |
|
| 527 | - * Alias for self::set_parent_invoice_id(). |
|
| 528 | - * |
|
| 529 | - * @since 1.0.19 |
|
| 530 | - * @param int $value The parent invoice id. |
|
| 531 | - */ |
|
| 532 | - public function set_parent_payment_id( $value ) { |
|
| 533 | - $this->set_parent_invoice_id( $value ); |
|
| 534 | - } |
|
| 661 | + } |
|
| 535 | 662 | |
| 536 | - /** |
|
| 537 | - * Alias for self::set_parent_invoice_id(). |
|
| 663 | + /** |
|
| 664 | + * Alias for self::set_next_renewal_date(). |
|
| 538 | 665 | * |
| 539 | 666 | * @since 1.0.19 |
| 540 | - * @param int $value The parent invoice id. |
|
| 667 | + * @param string $value strtotime compliant date. |
|
| 541 | 668 | */ |
| 542 | - public function set_original_payment_id( $value ) { |
|
| 543 | - $this->set_parent_invoice_id( $value ); |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - /** |
|
| 547 | - * Set subscription's product id. |
|
| 548 | - * |
|
| 549 | - * @since 1.0.19 |
|
| 550 | - * @param int $value The subscription product id. |
|
| 551 | - */ |
|
| 552 | - public function set_product_id( $value ) { |
|
| 553 | - $this->set_prop( 'product_id', (int) $value ); |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - /** |
|
| 557 | - * Set the period of a renewal. |
|
| 558 | - * |
|
| 559 | - * @since 1.0.19 |
|
| 560 | - * @param string $value The renewal period. |
|
| 561 | - */ |
|
| 562 | - public function set_period( $value ) { |
|
| 563 | - $this->set_prop( 'period', $value ); |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - /** |
|
| 567 | - * Set number of periods each renewal is valid for. |
|
| 568 | - * |
|
| 569 | - * @since 1.0.19 |
|
| 570 | - * @param int $value The subscription frequency. |
|
| 571 | - */ |
|
| 572 | - public function set_frequency( $value ) { |
|
| 573 | - $value = empty( $value ) ? 1 : (int) $value; |
|
| 574 | - $this->set_prop( 'frequency', absint( $value ) ); |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - /** |
|
| 578 | - * Set the initial amount for the subscription. |
|
| 579 | - * |
|
| 580 | - * @since 1.0.19 |
|
| 581 | - * @param float $value The initial subcription amount. |
|
| 582 | - */ |
|
| 583 | - public function set_initial_amount( $value ) { |
|
| 584 | - $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) ); |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - /** |
|
| 588 | - * Set the recurring amount for the subscription. |
|
| 589 | - * |
|
| 590 | - * @since 1.0.19 |
|
| 591 | - * @param float $value The recurring subcription amount. |
|
| 592 | - */ |
|
| 593 | - public function set_recurring_amount( $value ) { |
|
| 594 | - $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) ); |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - /** |
|
| 598 | - * Set number of times that this subscription can be renewed. |
|
| 599 | - * |
|
| 600 | - * @since 1.0.19 |
|
| 601 | - * @param int $value Bill times. |
|
| 602 | - */ |
|
| 603 | - public function set_bill_times( $value ) { |
|
| 604 | - $this->set_prop( 'bill_times', (int) $value ); |
|
| 605 | - } |
|
| 606 | - |
|
| 607 | - /** |
|
| 608 | - * Get transaction id of this subscription's parent invoice. |
|
| 609 | - * |
|
| 610 | - * @since 1.0.19 |
|
| 611 | - * @param string $value Bill times. |
|
| 612 | - */ |
|
| 613 | - public function set_transaction_id( $value ) { |
|
| 614 | - $this->set_prop( 'transaction_id', sanitize_text_field( $value ) ); |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - /** |
|
| 618 | - * Set date when this subscription started. |
|
| 619 | - * |
|
| 620 | - * @since 1.0.19 |
|
| 621 | - * @param string $value strtotime compliant date. |
|
| 622 | - */ |
|
| 623 | - public function set_created( $value ) { |
|
| 624 | - $date = strtotime( $value ); |
|
| 669 | + public function set_expiration( $value ) { |
|
| 670 | + $this->set_next_renewal_date( $value ); |
|
| 671 | + } |
|
| 625 | 672 | |
| 626 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
| 627 | - $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) ); |
|
| 673 | + /** |
|
| 674 | + * Set the subscription's trial period. |
|
| 675 | + * |
|
| 676 | + * @since 1.0.19 |
|
| 677 | + * @param string $value trial period e.g 1 year. |
|
| 678 | + */ |
|
| 679 | + public function set_trial_period( $value ) { |
|
| 680 | + $this->set_prop( 'trial_period', $value ); |
|
| 681 | + } |
|
| 682 | + |
|
| 683 | + /** |
|
| 684 | + * Set the subscription's status. |
|
| 685 | + * |
|
| 686 | + * @since 1.0.19 |
|
| 687 | + * @param string $new_status New subscription status. |
|
| 688 | + */ |
|
| 689 | + public function set_status( $new_status ) { |
|
| 690 | + |
|
| 691 | + // Abort if this is not a valid status; |
|
| 692 | + if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) { |
|
| 628 | 693 | return; |
| 629 | 694 | } |
| 630 | 695 | |
| 631 | - $this->set_prop( 'created', '' ); |
|
| 696 | + $old_status = $this->get_status(); |
|
| 697 | + $this->set_prop( 'status', $new_status ); |
|
| 632 | 698 | |
| 633 | - } |
|
| 699 | + if ( true === $this->object_read && $old_status !== $new_status ) { |
|
| 700 | + $this->status_transition = array( |
|
| 701 | + 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
| 702 | + 'to' => $new_status, |
|
| 703 | + ); |
|
| 704 | + } |
|
| 634 | 705 | |
| 635 | - /** |
|
| 636 | - * Alias for self::set_created(). |
|
| 637 | - * |
|
| 638 | - * @since 1.0.19 |
|
| 639 | - * @param string $value strtotime compliant date. |
|
| 640 | - */ |
|
| 641 | - public function set_date_created( $value ) { |
|
| 642 | - $this->set_created( $value ); |
|
| 643 | 706 | } |
| 644 | 707 | |
| 645 | - /** |
|
| 646 | - * Set the date that the subscription will renew. |
|
| 647 | - * |
|
| 648 | - * @since 1.0.19 |
|
| 649 | - * @param string $value strtotime compliant date. |
|
| 650 | - */ |
|
| 651 | - public function set_next_renewal_date( $value ) { |
|
| 652 | - $date = strtotime( $value ); |
|
| 708 | + /** |
|
| 709 | + * Set the subscription's (remote) profile id. |
|
| 710 | + * |
|
| 711 | + * @since 1.0.19 |
|
| 712 | + * @param string $value the remote profile id. |
|
| 713 | + */ |
|
| 714 | + public function set_profile_id( $value ) { |
|
| 715 | + $this->set_prop( 'profile_id', sanitize_text_field( $value ) ); |
|
| 716 | + } |
|
| 653 | 717 | |
| 654 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
| 655 | - $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) ); |
|
| 656 | - return; |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - $this->set_prop( 'expiration', '' ); |
|
| 660 | - |
|
| 661 | - } |
|
| 662 | - |
|
| 663 | - /** |
|
| 664 | - * Alias for self::set_next_renewal_date(). |
|
| 665 | - * |
|
| 666 | - * @since 1.0.19 |
|
| 667 | - * @param string $value strtotime compliant date. |
|
| 668 | - */ |
|
| 669 | - public function set_expiration( $value ) { |
|
| 670 | - $this->set_next_renewal_date( $value ); |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - /** |
|
| 674 | - * Set the subscription's trial period. |
|
| 675 | - * |
|
| 676 | - * @since 1.0.19 |
|
| 677 | - * @param string $value trial period e.g 1 year. |
|
| 678 | - */ |
|
| 679 | - public function set_trial_period( $value ) { |
|
| 680 | - $this->set_prop( 'trial_period', $value ); |
|
| 681 | - } |
|
| 682 | - |
|
| 683 | - /** |
|
| 684 | - * Set the subscription's status. |
|
| 685 | - * |
|
| 686 | - * @since 1.0.19 |
|
| 687 | - * @param string $new_status New subscription status. |
|
| 688 | - */ |
|
| 689 | - public function set_status( $new_status ) { |
|
| 690 | - |
|
| 691 | - // Abort if this is not a valid status; |
|
| 692 | - if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) { |
|
| 693 | - return; |
|
| 694 | - } |
|
| 695 | - |
|
| 696 | - $old_status = $this->get_status(); |
|
| 697 | - $this->set_prop( 'status', $new_status ); |
|
| 698 | - |
|
| 699 | - if ( true === $this->object_read && $old_status !== $new_status ) { |
|
| 700 | - $this->status_transition = array( |
|
| 701 | - 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
| 702 | - 'to' => $new_status, |
|
| 703 | - ); |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - } |
|
| 707 | - |
|
| 708 | - /** |
|
| 709 | - * Set the subscription's (remote) profile id. |
|
| 710 | - * |
|
| 711 | - * @since 1.0.19 |
|
| 712 | - * @param string $value the remote profile id. |
|
| 713 | - */ |
|
| 714 | - public function set_profile_id( $value ) { |
|
| 715 | - $this->set_prop( 'profile_id', sanitize_text_field( $value ) ); |
|
| 716 | - } |
|
| 717 | - |
|
| 718 | - /* |
|
| 718 | + /* |
|
| 719 | 719 | |-------------------------------------------------------------------------- |
| 720 | 720 | | Boolean methods |
| 721 | 721 | |-------------------------------------------------------------------------- |
@@ -724,55 +724,55 @@ discard block |
||
| 724 | 724 | | |
| 725 | 725 | */ |
| 726 | 726 | |
| 727 | - /** |
|
| 727 | + /** |
|
| 728 | 728 | * Checks if the subscription has a given status. |
| 729 | - * |
|
| 730 | - * @param string|array String or array of strings to check for. |
|
| 731 | - * @return bool |
|
| 729 | + * |
|
| 730 | + * @param string|array String or array of strings to check for. |
|
| 731 | + * @return bool |
|
| 732 | 732 | */ |
| 733 | 733 | public function has_status( $status ) { |
| 734 | 734 | return in_array( $this->get_status(), wpinv_clean( wpinv_parse_list( $status ) ) ); |
| 735 | - } |
|
| 735 | + } |
|
| 736 | 736 | |
| 737 | - /** |
|
| 737 | + /** |
|
| 738 | 738 | * Checks if the subscription has a trial period. |
| 739 | - * |
|
| 740 | - * @return bool |
|
| 739 | + * |
|
| 740 | + * @return bool |
|
| 741 | 741 | */ |
| 742 | 742 | public function has_trial_period() { |
| 743 | - $period = $this->get_trial_period(); |
|
| 743 | + $period = $this->get_trial_period(); |
|
| 744 | 744 | return ! empty( $period ); |
| 745 | - } |
|
| 746 | - |
|
| 747 | - /** |
|
| 748 | - * Is the subscription active? |
|
| 749 | - * |
|
| 750 | - * @return bool |
|
| 751 | - */ |
|
| 752 | - public function is_active() { |
|
| 753 | - return $this->has_status( 'active trialling' ) && ! $this->is_expired(); |
|
| 754 | - } |
|
| 755 | - |
|
| 756 | - /** |
|
| 757 | - * Is the subscription expired? |
|
| 758 | - * |
|
| 759 | - * @return bool |
|
| 760 | - */ |
|
| 761 | - public function is_expired() { |
|
| 762 | - return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) ); |
|
| 763 | - } |
|
| 764 | - |
|
| 765 | - /** |
|
| 766 | - * Is this the last renewals? |
|
| 767 | - * |
|
| 768 | - * @return bool |
|
| 769 | - */ |
|
| 770 | - public function is_last_renewal() { |
|
| 771 | - $max_bills = $this->get_bill_times(); |
|
| 772 | - return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed(); |
|
| 773 | - } |
|
| 774 | - |
|
| 775 | - /* |
|
| 745 | + } |
|
| 746 | + |
|
| 747 | + /** |
|
| 748 | + * Is the subscription active? |
|
| 749 | + * |
|
| 750 | + * @return bool |
|
| 751 | + */ |
|
| 752 | + public function is_active() { |
|
| 753 | + return $this->has_status( 'active trialling' ) && ! $this->is_expired(); |
|
| 754 | + } |
|
| 755 | + |
|
| 756 | + /** |
|
| 757 | + * Is the subscription expired? |
|
| 758 | + * |
|
| 759 | + * @return bool |
|
| 760 | + */ |
|
| 761 | + public function is_expired() { |
|
| 762 | + return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) ); |
|
| 763 | + } |
|
| 764 | + |
|
| 765 | + /** |
|
| 766 | + * Is this the last renewals? |
|
| 767 | + * |
|
| 768 | + * @return bool |
|
| 769 | + */ |
|
| 770 | + public function is_last_renewal() { |
|
| 771 | + $max_bills = $this->get_bill_times(); |
|
| 772 | + return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed(); |
|
| 773 | + } |
|
| 774 | + |
|
| 775 | + /* |
|
| 776 | 776 | |-------------------------------------------------------------------------- |
| 777 | 777 | | Additional methods |
| 778 | 778 | |-------------------------------------------------------------------------- |
@@ -781,27 +781,27 @@ discard block |
||
| 781 | 781 | | |
| 782 | 782 | */ |
| 783 | 783 | |
| 784 | - /** |
|
| 785 | - * Backwards compatibilty. |
|
| 786 | - */ |
|
| 787 | - public function create( $data = array() ) { |
|
| 784 | + /** |
|
| 785 | + * Backwards compatibilty. |
|
| 786 | + */ |
|
| 787 | + public function create( $data = array() ) { |
|
| 788 | 788 | |
| 789 | - // Set the properties. |
|
| 790 | - if ( is_array( $data ) ) { |
|
| 791 | - $this->set_props( $data ); |
|
| 792 | - } |
|
| 789 | + // Set the properties. |
|
| 790 | + if ( is_array( $data ) ) { |
|
| 791 | + $this->set_props( $data ); |
|
| 792 | + } |
|
| 793 | 793 | |
| 794 | - // Save the item. |
|
| 795 | - return $this->save(); |
|
| 794 | + // Save the item. |
|
| 795 | + return $this->save(); |
|
| 796 | 796 | |
| 797 | - } |
|
| 797 | + } |
|
| 798 | 798 | |
| 799 | - /** |
|
| 800 | - * Backwards compatibilty. |
|
| 801 | - */ |
|
| 802 | - public function update( $args = array() ) { |
|
| 803 | - return $this->create( $args ); |
|
| 804 | - } |
|
| 799 | + /** |
|
| 800 | + * Backwards compatibilty. |
|
| 801 | + */ |
|
| 802 | + public function update( $args = array() ) { |
|
| 803 | + return $this->create( $args ); |
|
| 804 | + } |
|
| 805 | 805 | |
| 806 | 806 | /** |
| 807 | 807 | * Retrieve renewal payments for a subscription |
@@ -811,22 +811,22 @@ discard block |
||
| 811 | 811 | */ |
| 812 | 812 | public function get_child_payments( $hide_pending = true ) { |
| 813 | 813 | |
| 814 | - $statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' ); |
|
| 814 | + $statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' ); |
|
| 815 | 815 | |
| 816 | - if ( ! $hide_pending ) { |
|
| 817 | - $statuses = array_keys( wpinv_get_invoice_statuses() ); |
|
| 818 | - } |
|
| 816 | + if ( ! $hide_pending ) { |
|
| 817 | + $statuses = array_keys( wpinv_get_invoice_statuses() ); |
|
| 818 | + } |
|
| 819 | 819 | |
| 820 | 820 | return get_posts( |
| 821 | - array( |
|
| 822 | - 'post_parent' => $this->get_parent_payment_id(), |
|
| 823 | - 'numberposts' => -1, |
|
| 824 | - 'post_status' => $statuses, |
|
| 825 | - 'orderby' => 'ID', |
|
| 826 | - 'order' => 'ASC', |
|
| 827 | - 'post_type' => 'wpi_invoice' |
|
| 828 | - ) |
|
| 829 | - ); |
|
| 821 | + array( |
|
| 822 | + 'post_parent' => $this->get_parent_payment_id(), |
|
| 823 | + 'numberposts' => -1, |
|
| 824 | + 'post_status' => $statuses, |
|
| 825 | + 'orderby' => 'ID', |
|
| 826 | + 'order' => 'ASC', |
|
| 827 | + 'post_type' => 'wpi_invoice' |
|
| 828 | + ) |
|
| 829 | + ); |
|
| 830 | 830 | } |
| 831 | 831 | |
| 832 | 832 | /** |
@@ -836,7 +836,7 @@ discard block |
||
| 836 | 836 | * @return int |
| 837 | 837 | */ |
| 838 | 838 | public function get_total_payments() { |
| 839 | - return getpaid_count_subscription_invoices( $this->get_parent_invoice_id() ); |
|
| 839 | + return getpaid_count_subscription_invoices( $this->get_parent_invoice_id() ); |
|
| 840 | 840 | } |
| 841 | 841 | |
| 842 | 842 | /** |
@@ -860,57 +860,57 @@ discard block |
||
| 860 | 860 | * |
| 861 | 861 | * @since 2.4 |
| 862 | 862 | * @param array $args Array of values for the payment, including amount and transaction ID |
| 863 | - * @param WPInv_Invoice $invoice If adding an existing invoice. |
|
| 863 | + * @param WPInv_Invoice $invoice If adding an existing invoice. |
|
| 864 | 864 | * @return bool |
| 865 | 865 | */ |
| 866 | 866 | public function add_payment( $args = array(), $invoice = false ) { |
| 867 | 867 | |
| 868 | - // Process each payment once. |
|
| 868 | + // Process each payment once. |
|
| 869 | 869 | if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) { |
| 870 | 870 | return false; |
| 871 | 871 | } |
| 872 | 872 | |
| 873 | - // Are we creating a new invoice? |
|
| 874 | - if ( empty( $invoice ) ) { |
|
| 875 | - $invoice = $this->create_payment(); |
|
| 873 | + // Are we creating a new invoice? |
|
| 874 | + if ( empty( $invoice ) ) { |
|
| 875 | + $invoice = $this->create_payment(); |
|
| 876 | 876 | |
| 877 | - if ( empty( $invoice ) ) { |
|
| 878 | - return false; |
|
| 879 | - } |
|
| 877 | + if ( empty( $invoice ) ) { |
|
| 878 | + return false; |
|
| 879 | + } |
|
| 880 | 880 | |
| 881 | - } |
|
| 881 | + } |
|
| 882 | 882 | |
| 883 | - $invoice->set_status( 'wpi-renewal' ); |
|
| 883 | + $invoice->set_status( 'wpi-renewal' ); |
|
| 884 | 884 | |
| 885 | - // Maybe set a transaction id. |
|
| 886 | - if ( ! empty( $args['transaction_id'] ) ) { |
|
| 887 | - $invoice->set_transaction_id( $args['transaction_id'] ); |
|
| 888 | - } |
|
| 885 | + // Maybe set a transaction id. |
|
| 886 | + if ( ! empty( $args['transaction_id'] ) ) { |
|
| 887 | + $invoice->set_transaction_id( $args['transaction_id'] ); |
|
| 888 | + } |
|
| 889 | 889 | |
| 890 | - // Set the completed date. |
|
| 891 | - $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
| 890 | + // Set the completed date. |
|
| 891 | + $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
| 892 | 892 | |
| 893 | - // And the gateway. |
|
| 894 | - if ( ! empty( $args['gateway'] ) ) { |
|
| 895 | - $invoice->set_gateway( $args['gateway'] ); |
|
| 896 | - } |
|
| 893 | + // And the gateway. |
|
| 894 | + if ( ! empty( $args['gateway'] ) ) { |
|
| 895 | + $invoice->set_gateway( $args['gateway'] ); |
|
| 896 | + } |
|
| 897 | 897 | |
| 898 | - $invoice->save(); |
|
| 898 | + $invoice->save(); |
|
| 899 | 899 | |
| 900 | - if ( ! $invoice->exists() ) { |
|
| 901 | - return false; |
|
| 902 | - } |
|
| 900 | + if ( ! $invoice->exists() ) { |
|
| 901 | + return false; |
|
| 902 | + } |
|
| 903 | 903 | |
| 904 | - do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
| 905 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
| 904 | + do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
| 905 | + do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
| 906 | 906 | do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() ); |
| 907 | 907 | |
| 908 | 908 | update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id ); |
| 909 | 909 | |
| 910 | 910 | return $invoice->get_id(); |
| 911 | - } |
|
| 911 | + } |
|
| 912 | 912 | |
| 913 | - /** |
|
| 913 | + /** |
|
| 914 | 914 | * Creates a new invoice and returns it. |
| 915 | 915 | * |
| 916 | 916 | * @since 1.0.19 |
@@ -918,124 +918,124 @@ discard block |
||
| 918 | 918 | */ |
| 919 | 919 | public function create_payment() { |
| 920 | 920 | |
| 921 | - $parent_invoice = $this->get_parent_payment(); |
|
| 922 | - |
|
| 923 | - if ( ! $parent_invoice->exists() ) { |
|
| 924 | - return false; |
|
| 925 | - } |
|
| 926 | - |
|
| 927 | - // Duplicate the parent invoice. |
|
| 928 | - $invoice = getpaid_duplicate_invoice( $parent_invoice ); |
|
| 929 | - $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
| 930 | - $invoice->set_subscription_id( $this->get_id() ); |
|
| 931 | - $invoice->set_remote_subscription_id( $this->get_profile_id() ); |
|
| 932 | - |
|
| 933 | - // Set invoice items. |
|
| 934 | - $subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() ); |
|
| 935 | - $allowed_items = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] ); |
|
| 936 | - $invoice_items = array(); |
|
| 937 | - |
|
| 938 | - foreach ( $invoice->get_items() as $item ) { |
|
| 939 | - if ( in_array( $item->get_id(), $allowed_items ) ) { |
|
| 940 | - $invoice_items[] = $item; |
|
| 941 | - } |
|
| 942 | - } |
|
| 943 | - |
|
| 944 | - $invoice->set_items( $invoice_items ); |
|
| 945 | - |
|
| 946 | - if ( ! empty( $subscription_group['fees'] ) ) { |
|
| 947 | - $invoice->set_fees( $subscription_group['fees'] ); |
|
| 948 | - } |
|
| 949 | - |
|
| 950 | - // Maybe recalculate discount (Pre-GetPaid Fix). |
|
| 951 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
| 952 | - if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) { |
|
| 953 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
| 954 | - } |
|
| 955 | - |
|
| 956 | - $invoice->recalculate_total(); |
|
| 957 | - $invoice->set_status( 'wpi-pending' ); |
|
| 958 | - $invoice->save(); |
|
| 959 | - |
|
| 960 | - return $invoice->exists() ? $invoice : false; |
|
| 961 | - } |
|
| 962 | - |
|
| 963 | - /** |
|
| 964 | - * Renews or completes a subscription |
|
| 965 | - * |
|
| 966 | - * @since 1.0.0 |
|
| 967 | - * @return int The subscription's id |
|
| 968 | - */ |
|
| 969 | - public function renew() { |
|
| 970 | - |
|
| 971 | - // Complete subscription if applicable |
|
| 972 | - if ( $this->is_last_renewal() ) { |
|
| 973 | - return $this->complete(); |
|
| 974 | - } |
|
| 975 | - |
|
| 976 | - // Calculate new expiration |
|
| 977 | - $frequency = $this->get_frequency(); |
|
| 978 | - $period = $this->get_period(); |
|
| 979 | - $new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() ); |
|
| 980 | - |
|
| 981 | - $this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) ); |
|
| 982 | - $this->set_status( 'active' ); |
|
| 983 | - $this->save(); |
|
| 984 | - |
|
| 985 | - do_action( 'getpaid_subscription_renewed', $this ); |
|
| 986 | - |
|
| 987 | - return $this->get_id(); |
|
| 988 | - } |
|
| 989 | - |
|
| 990 | - /** |
|
| 991 | - * Marks a subscription as completed |
|
| 992 | - * |
|
| 993 | - * Subscription is completed when the number of payments matches the billing_times field |
|
| 994 | - * |
|
| 995 | - * @since 1.0.0 |
|
| 996 | - * @return int|bool Subscription id or false if the subscription is cancelled. |
|
| 997 | - */ |
|
| 998 | - public function complete() { |
|
| 999 | - |
|
| 1000 | - // Only mark a subscription as complete if it's not already cancelled. |
|
| 1001 | - if ( $this->has_status( 'cancelled' ) ) { |
|
| 1002 | - return false; |
|
| 1003 | - } |
|
| 1004 | - |
|
| 1005 | - $this->set_status( 'completed' ); |
|
| 1006 | - return $this->save(); |
|
| 1007 | - |
|
| 1008 | - } |
|
| 1009 | - |
|
| 1010 | - /** |
|
| 1011 | - * Marks a subscription as expired |
|
| 1012 | - * |
|
| 1013 | - * @since 1.0.0 |
|
| 1014 | - * @param bool $check_expiration |
|
| 1015 | - * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
|
| 1016 | - */ |
|
| 1017 | - public function expire( $check_expiration = false ) { |
|
| 1018 | - |
|
| 1019 | - if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
| 1020 | - // Do not mark as expired since real expiration date is in the future |
|
| 1021 | - return false; |
|
| 1022 | - } |
|
| 1023 | - |
|
| 1024 | - $this->set_status( 'expired' ); |
|
| 1025 | - return $this->save(); |
|
| 1026 | - |
|
| 1027 | - } |
|
| 1028 | - |
|
| 1029 | - /** |
|
| 1030 | - * Marks a subscription as failing |
|
| 1031 | - * |
|
| 1032 | - * @since 2.4.2 |
|
| 1033 | - * @return int Subscription id. |
|
| 1034 | - */ |
|
| 1035 | - public function failing() { |
|
| 1036 | - $this->set_status( 'failing' ); |
|
| 1037 | - return $this->save(); |
|
| 1038 | - } |
|
| 921 | + $parent_invoice = $this->get_parent_payment(); |
|
| 922 | + |
|
| 923 | + if ( ! $parent_invoice->exists() ) { |
|
| 924 | + return false; |
|
| 925 | + } |
|
| 926 | + |
|
| 927 | + // Duplicate the parent invoice. |
|
| 928 | + $invoice = getpaid_duplicate_invoice( $parent_invoice ); |
|
| 929 | + $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
| 930 | + $invoice->set_subscription_id( $this->get_id() ); |
|
| 931 | + $invoice->set_remote_subscription_id( $this->get_profile_id() ); |
|
| 932 | + |
|
| 933 | + // Set invoice items. |
|
| 934 | + $subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() ); |
|
| 935 | + $allowed_items = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] ); |
|
| 936 | + $invoice_items = array(); |
|
| 937 | + |
|
| 938 | + foreach ( $invoice->get_items() as $item ) { |
|
| 939 | + if ( in_array( $item->get_id(), $allowed_items ) ) { |
|
| 940 | + $invoice_items[] = $item; |
|
| 941 | + } |
|
| 942 | + } |
|
| 943 | + |
|
| 944 | + $invoice->set_items( $invoice_items ); |
|
| 945 | + |
|
| 946 | + if ( ! empty( $subscription_group['fees'] ) ) { |
|
| 947 | + $invoice->set_fees( $subscription_group['fees'] ); |
|
| 948 | + } |
|
| 949 | + |
|
| 950 | + // Maybe recalculate discount (Pre-GetPaid Fix). |
|
| 951 | + $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
| 952 | + if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) { |
|
| 953 | + $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
| 954 | + } |
|
| 955 | + |
|
| 956 | + $invoice->recalculate_total(); |
|
| 957 | + $invoice->set_status( 'wpi-pending' ); |
|
| 958 | + $invoice->save(); |
|
| 959 | + |
|
| 960 | + return $invoice->exists() ? $invoice : false; |
|
| 961 | + } |
|
| 962 | + |
|
| 963 | + /** |
|
| 964 | + * Renews or completes a subscription |
|
| 965 | + * |
|
| 966 | + * @since 1.0.0 |
|
| 967 | + * @return int The subscription's id |
|
| 968 | + */ |
|
| 969 | + public function renew() { |
|
| 970 | + |
|
| 971 | + // Complete subscription if applicable |
|
| 972 | + if ( $this->is_last_renewal() ) { |
|
| 973 | + return $this->complete(); |
|
| 974 | + } |
|
| 975 | + |
|
| 976 | + // Calculate new expiration |
|
| 977 | + $frequency = $this->get_frequency(); |
|
| 978 | + $period = $this->get_period(); |
|
| 979 | + $new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() ); |
|
| 980 | + |
|
| 981 | + $this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) ); |
|
| 982 | + $this->set_status( 'active' ); |
|
| 983 | + $this->save(); |
|
| 984 | + |
|
| 985 | + do_action( 'getpaid_subscription_renewed', $this ); |
|
| 986 | + |
|
| 987 | + return $this->get_id(); |
|
| 988 | + } |
|
| 989 | + |
|
| 990 | + /** |
|
| 991 | + * Marks a subscription as completed |
|
| 992 | + * |
|
| 993 | + * Subscription is completed when the number of payments matches the billing_times field |
|
| 994 | + * |
|
| 995 | + * @since 1.0.0 |
|
| 996 | + * @return int|bool Subscription id or false if the subscription is cancelled. |
|
| 997 | + */ |
|
| 998 | + public function complete() { |
|
| 999 | + |
|
| 1000 | + // Only mark a subscription as complete if it's not already cancelled. |
|
| 1001 | + if ( $this->has_status( 'cancelled' ) ) { |
|
| 1002 | + return false; |
|
| 1003 | + } |
|
| 1004 | + |
|
| 1005 | + $this->set_status( 'completed' ); |
|
| 1006 | + return $this->save(); |
|
| 1007 | + |
|
| 1008 | + } |
|
| 1009 | + |
|
| 1010 | + /** |
|
| 1011 | + * Marks a subscription as expired |
|
| 1012 | + * |
|
| 1013 | + * @since 1.0.0 |
|
| 1014 | + * @param bool $check_expiration |
|
| 1015 | + * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
|
| 1016 | + */ |
|
| 1017 | + public function expire( $check_expiration = false ) { |
|
| 1018 | + |
|
| 1019 | + if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
| 1020 | + // Do not mark as expired since real expiration date is in the future |
|
| 1021 | + return false; |
|
| 1022 | + } |
|
| 1023 | + |
|
| 1024 | + $this->set_status( 'expired' ); |
|
| 1025 | + return $this->save(); |
|
| 1026 | + |
|
| 1027 | + } |
|
| 1028 | + |
|
| 1029 | + /** |
|
| 1030 | + * Marks a subscription as failing |
|
| 1031 | + * |
|
| 1032 | + * @since 2.4.2 |
|
| 1033 | + * @return int Subscription id. |
|
| 1034 | + */ |
|
| 1035 | + public function failing() { |
|
| 1036 | + $this->set_status( 'failing' ); |
|
| 1037 | + return $this->save(); |
|
| 1038 | + } |
|
| 1039 | 1039 | |
| 1040 | 1040 | /** |
| 1041 | 1041 | * Marks a subscription as cancelled |
@@ -1044,19 +1044,19 @@ discard block |
||
| 1044 | 1044 | * @return int Subscription id. |
| 1045 | 1045 | */ |
| 1046 | 1046 | public function cancel() { |
| 1047 | - $this->set_status( 'cancelled' ); |
|
| 1048 | - return $this->save(); |
|
| 1047 | + $this->set_status( 'cancelled' ); |
|
| 1048 | + return $this->save(); |
|
| 1049 | 1049 | } |
| 1050 | 1050 | |
| 1051 | - /** |
|
| 1052 | - * Determines if a subscription can be cancelled both locally and with a payment processor. |
|
| 1053 | - * |
|
| 1054 | - * @since 1.0.0 |
|
| 1055 | - * @return bool |
|
| 1056 | - */ |
|
| 1057 | - public function can_cancel() { |
|
| 1058 | - return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
| 1059 | - } |
|
| 1051 | + /** |
|
| 1052 | + * Determines if a subscription can be cancelled both locally and with a payment processor. |
|
| 1053 | + * |
|
| 1054 | + * @since 1.0.0 |
|
| 1055 | + * @return bool |
|
| 1056 | + */ |
|
| 1057 | + public function can_cancel() { |
|
| 1058 | + return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
| 1059 | + } |
|
| 1060 | 1060 | |
| 1061 | 1061 | /** |
| 1062 | 1062 | * Returns an array of subscription statuses that can be cancelled |
@@ -1069,96 +1069,96 @@ discard block |
||
| 1069 | 1069 | return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) ); |
| 1070 | 1070 | } |
| 1071 | 1071 | |
| 1072 | - /** |
|
| 1073 | - * Retrieves the URL to cancel subscription |
|
| 1074 | - * |
|
| 1075 | - * @since 1.0.0 |
|
| 1076 | - * @return string |
|
| 1077 | - */ |
|
| 1078 | - public function get_cancel_url() { |
|
| 1079 | - $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() ); |
|
| 1080 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
| 1081 | - } |
|
| 1082 | - |
|
| 1083 | - /** |
|
| 1084 | - * Retrieves the URL to view a subscription |
|
| 1085 | - * |
|
| 1086 | - * @since 1.0.19 |
|
| 1087 | - * @return string |
|
| 1088 | - */ |
|
| 1089 | - public function get_view_url() { |
|
| 1090 | - |
|
| 1091 | - $url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
| 1092 | - $url = add_query_arg( 'subscription', $this->get_id(), $url ); |
|
| 1093 | - |
|
| 1094 | - return apply_filters( 'getpaid_get_subscription_view_url', $url, $this ); |
|
| 1095 | - } |
|
| 1096 | - |
|
| 1097 | - /** |
|
| 1098 | - * Determines if subscription can be manually renewed |
|
| 1099 | - * |
|
| 1100 | - * This method is filtered by payment gateways in order to return true on subscriptions |
|
| 1101 | - * that can be renewed manually |
|
| 1102 | - * |
|
| 1103 | - * @since 2.5 |
|
| 1104 | - * @return bool |
|
| 1105 | - */ |
|
| 1106 | - public function can_renew() { |
|
| 1107 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
| 1108 | - } |
|
| 1109 | - |
|
| 1110 | - /** |
|
| 1111 | - * Retrieves the URL to renew a subscription |
|
| 1112 | - * |
|
| 1113 | - * @since 2.5 |
|
| 1114 | - * @return string |
|
| 1115 | - */ |
|
| 1116 | - public function get_renew_url() { |
|
| 1117 | - $url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'getpaid-nonce' ); |
|
| 1118 | - return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
| 1119 | - } |
|
| 1120 | - |
|
| 1121 | - /** |
|
| 1122 | - * Determines if subscription can have their payment method updated |
|
| 1123 | - * |
|
| 1124 | - * @since 1.0.0 |
|
| 1125 | - * @return bool |
|
| 1126 | - */ |
|
| 1127 | - public function can_update() { |
|
| 1128 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
| 1129 | - } |
|
| 1130 | - |
|
| 1131 | - /** |
|
| 1132 | - * Retrieves the URL to update subscription |
|
| 1133 | - * |
|
| 1134 | - * @since 1.0.0 |
|
| 1135 | - * @return string |
|
| 1136 | - */ |
|
| 1137 | - public function get_update_url() { |
|
| 1138 | - $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) ); |
|
| 1139 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
| 1140 | - } |
|
| 1141 | - |
|
| 1142 | - /** |
|
| 1143 | - * Retrieves the subscription status label |
|
| 1144 | - * |
|
| 1145 | - * @since 1.0.0 |
|
| 1146 | - * @return string |
|
| 1147 | - */ |
|
| 1148 | - public function get_status_label() { |
|
| 1149 | - return getpaid_get_subscription_status_label( $this->get_status() ); |
|
| 1150 | - } |
|
| 1151 | - |
|
| 1152 | - /** |
|
| 1153 | - * Retrieves the subscription status class |
|
| 1154 | - * |
|
| 1155 | - * @since 1.0.19 |
|
| 1156 | - * @return string |
|
| 1157 | - */ |
|
| 1158 | - public function get_status_class() { |
|
| 1159 | - $statuses = getpaid_get_subscription_status_classes(); |
|
| 1160 | - return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark'; |
|
| 1161 | - } |
|
| 1072 | + /** |
|
| 1073 | + * Retrieves the URL to cancel subscription |
|
| 1074 | + * |
|
| 1075 | + * @since 1.0.0 |
|
| 1076 | + * @return string |
|
| 1077 | + */ |
|
| 1078 | + public function get_cancel_url() { |
|
| 1079 | + $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() ); |
|
| 1080 | + return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
| 1081 | + } |
|
| 1082 | + |
|
| 1083 | + /** |
|
| 1084 | + * Retrieves the URL to view a subscription |
|
| 1085 | + * |
|
| 1086 | + * @since 1.0.19 |
|
| 1087 | + * @return string |
|
| 1088 | + */ |
|
| 1089 | + public function get_view_url() { |
|
| 1090 | + |
|
| 1091 | + $url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
| 1092 | + $url = add_query_arg( 'subscription', $this->get_id(), $url ); |
|
| 1093 | + |
|
| 1094 | + return apply_filters( 'getpaid_get_subscription_view_url', $url, $this ); |
|
| 1095 | + } |
|
| 1096 | + |
|
| 1097 | + /** |
|
| 1098 | + * Determines if subscription can be manually renewed |
|
| 1099 | + * |
|
| 1100 | + * This method is filtered by payment gateways in order to return true on subscriptions |
|
| 1101 | + * that can be renewed manually |
|
| 1102 | + * |
|
| 1103 | + * @since 2.5 |
|
| 1104 | + * @return bool |
|
| 1105 | + */ |
|
| 1106 | + public function can_renew() { |
|
| 1107 | + return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
| 1108 | + } |
|
| 1109 | + |
|
| 1110 | + /** |
|
| 1111 | + * Retrieves the URL to renew a subscription |
|
| 1112 | + * |
|
| 1113 | + * @since 2.5 |
|
| 1114 | + * @return string |
|
| 1115 | + */ |
|
| 1116 | + public function get_renew_url() { |
|
| 1117 | + $url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'getpaid-nonce' ); |
|
| 1118 | + return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
| 1119 | + } |
|
| 1120 | + |
|
| 1121 | + /** |
|
| 1122 | + * Determines if subscription can have their payment method updated |
|
| 1123 | + * |
|
| 1124 | + * @since 1.0.0 |
|
| 1125 | + * @return bool |
|
| 1126 | + */ |
|
| 1127 | + public function can_update() { |
|
| 1128 | + return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
| 1129 | + } |
|
| 1130 | + |
|
| 1131 | + /** |
|
| 1132 | + * Retrieves the URL to update subscription |
|
| 1133 | + * |
|
| 1134 | + * @since 1.0.0 |
|
| 1135 | + * @return string |
|
| 1136 | + */ |
|
| 1137 | + public function get_update_url() { |
|
| 1138 | + $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) ); |
|
| 1139 | + return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
| 1140 | + } |
|
| 1141 | + |
|
| 1142 | + /** |
|
| 1143 | + * Retrieves the subscription status label |
|
| 1144 | + * |
|
| 1145 | + * @since 1.0.0 |
|
| 1146 | + * @return string |
|
| 1147 | + */ |
|
| 1148 | + public function get_status_label() { |
|
| 1149 | + return getpaid_get_subscription_status_label( $this->get_status() ); |
|
| 1150 | + } |
|
| 1151 | + |
|
| 1152 | + /** |
|
| 1153 | + * Retrieves the subscription status class |
|
| 1154 | + * |
|
| 1155 | + * @since 1.0.19 |
|
| 1156 | + * @return string |
|
| 1157 | + */ |
|
| 1158 | + public function get_status_class() { |
|
| 1159 | + $statuses = getpaid_get_subscription_status_classes(); |
|
| 1160 | + return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark'; |
|
| 1161 | + } |
|
| 1162 | 1162 | |
| 1163 | 1163 | /** |
| 1164 | 1164 | * Retrieves the subscription status label |
@@ -1168,11 +1168,11 @@ discard block |
||
| 1168 | 1168 | */ |
| 1169 | 1169 | public function get_status_label_html() { |
| 1170 | 1170 | |
| 1171 | - $status_label = sanitize_text_field( $this->get_status_label() ); |
|
| 1172 | - $class = esc_attr( $this->get_status_class() ); |
|
| 1173 | - $status = sanitize_html_class( $this->get_status() ); |
|
| 1171 | + $status_label = sanitize_text_field( $this->get_status_label() ); |
|
| 1172 | + $class = esc_attr( $this->get_status_class() ); |
|
| 1173 | + $status = sanitize_html_class( $this->get_status() ); |
|
| 1174 | 1174 | |
| 1175 | - return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
|
| 1175 | + return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
|
| 1176 | 1176 | } |
| 1177 | 1177 | |
| 1178 | 1178 | /** |
@@ -1183,75 +1183,75 @@ discard block |
||
| 1183 | 1183 | * @return bool |
| 1184 | 1184 | */ |
| 1185 | 1185 | public function payment_exists( $txn_id = '' ) { |
| 1186 | - $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
| 1186 | + $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
| 1187 | 1187 | return ! empty( $invoice_id ); |
| 1188 | - } |
|
| 1189 | - |
|
| 1190 | - /** |
|
| 1191 | - * Handle the status transition. |
|
| 1192 | - */ |
|
| 1193 | - protected function status_transition() { |
|
| 1194 | - $status_transition = $this->status_transition; |
|
| 1195 | - |
|
| 1196 | - // Reset status transition variable. |
|
| 1197 | - $this->status_transition = false; |
|
| 1198 | - |
|
| 1199 | - if ( $status_transition ) { |
|
| 1200 | - try { |
|
| 1201 | - |
|
| 1202 | - // Fire a hook for the status change. |
|
| 1203 | - do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
| 1204 | - do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
| 1205 | - |
|
| 1206 | - if ( ! empty( $status_transition['from'] ) ) { |
|
| 1207 | - |
|
| 1208 | - /* translators: 1: old subscription status 2: new subscription status */ |
|
| 1209 | - $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
| 1210 | - |
|
| 1211 | - // Note the transition occurred. |
|
| 1212 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1213 | - |
|
| 1214 | - // Fire another hook. |
|
| 1215 | - do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
| 1216 | - do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
| 1217 | - |
|
| 1218 | - } else { |
|
| 1219 | - /* translators: %s: new invoice status */ |
|
| 1220 | - $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
| 1221 | - |
|
| 1222 | - // Note the transition occurred. |
|
| 1223 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1224 | - |
|
| 1225 | - } |
|
| 1226 | - } catch ( Exception $e ) { |
|
| 1227 | - $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
| 1228 | - } |
|
| 1229 | - } |
|
| 1230 | - |
|
| 1231 | - } |
|
| 1232 | - |
|
| 1233 | - /** |
|
| 1234 | - * Save data to the database. |
|
| 1235 | - * |
|
| 1236 | - * @since 1.0.19 |
|
| 1237 | - * @return int subscription ID |
|
| 1238 | - */ |
|
| 1239 | - public function save() { |
|
| 1240 | - parent::save(); |
|
| 1241 | - $this->status_transition(); |
|
| 1242 | - return $this->get_id(); |
|
| 1243 | - } |
|
| 1244 | - |
|
| 1245 | - /** |
|
| 1246 | - * Activates a subscription. |
|
| 1247 | - * |
|
| 1248 | - * @since 1.0.19 |
|
| 1249 | - * @return int subscription ID |
|
| 1250 | - */ |
|
| 1251 | - public function activate() { |
|
| 1252 | - $status = 'trialling' == $this->get_status() ? 'trialling' : 'active'; |
|
| 1253 | - $this->set_status( $status ); |
|
| 1254 | - return $this->save(); |
|
| 1255 | - } |
|
| 1188 | + } |
|
| 1189 | + |
|
| 1190 | + /** |
|
| 1191 | + * Handle the status transition. |
|
| 1192 | + */ |
|
| 1193 | + protected function status_transition() { |
|
| 1194 | + $status_transition = $this->status_transition; |
|
| 1195 | + |
|
| 1196 | + // Reset status transition variable. |
|
| 1197 | + $this->status_transition = false; |
|
| 1198 | + |
|
| 1199 | + if ( $status_transition ) { |
|
| 1200 | + try { |
|
| 1201 | + |
|
| 1202 | + // Fire a hook for the status change. |
|
| 1203 | + do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
| 1204 | + do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
| 1205 | + |
|
| 1206 | + if ( ! empty( $status_transition['from'] ) ) { |
|
| 1207 | + |
|
| 1208 | + /* translators: 1: old subscription status 2: new subscription status */ |
|
| 1209 | + $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
| 1210 | + |
|
| 1211 | + // Note the transition occurred. |
|
| 1212 | + $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1213 | + |
|
| 1214 | + // Fire another hook. |
|
| 1215 | + do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
| 1216 | + do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
| 1217 | + |
|
| 1218 | + } else { |
|
| 1219 | + /* translators: %s: new invoice status */ |
|
| 1220 | + $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
| 1221 | + |
|
| 1222 | + // Note the transition occurred. |
|
| 1223 | + $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1224 | + |
|
| 1225 | + } |
|
| 1226 | + } catch ( Exception $e ) { |
|
| 1227 | + $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
| 1228 | + } |
|
| 1229 | + } |
|
| 1230 | + |
|
| 1231 | + } |
|
| 1232 | + |
|
| 1233 | + /** |
|
| 1234 | + * Save data to the database. |
|
| 1235 | + * |
|
| 1236 | + * @since 1.0.19 |
|
| 1237 | + * @return int subscription ID |
|
| 1238 | + */ |
|
| 1239 | + public function save() { |
|
| 1240 | + parent::save(); |
|
| 1241 | + $this->status_transition(); |
|
| 1242 | + return $this->get_id(); |
|
| 1243 | + } |
|
| 1244 | + |
|
| 1245 | + /** |
|
| 1246 | + * Activates a subscription. |
|
| 1247 | + * |
|
| 1248 | + * @since 1.0.19 |
|
| 1249 | + * @return int subscription ID |
|
| 1250 | + */ |
|
| 1251 | + public function activate() { |
|
| 1252 | + $status = 'trialling' == $this->get_status() ? 'trialling' : 'active'; |
|
| 1253 | + $this->set_status( $status ); |
|
| 1254 | + return $this->save(); |
|
| 1255 | + } |
|
| 1256 | 1256 | |
| 1257 | 1257 | } |
@@ -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 | * The Subscription Class |
@@ -68,27 +68,27 @@ discard block |
||
| 68 | 68 | * @param int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read. |
| 69 | 69 | * @param bool $deprecated |
| 70 | 70 | */ |
| 71 | - function __construct( $subscription = 0, $deprecated = false ) { |
|
| 71 | + function __construct($subscription = 0, $deprecated = false) { |
|
| 72 | 72 | |
| 73 | - parent::__construct( $subscription ); |
|
| 73 | + parent::__construct($subscription); |
|
| 74 | 74 | |
| 75 | - if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) { |
|
| 76 | - $this->set_id( $subscription ); |
|
| 77 | - } elseif ( $subscription instanceof self ) { |
|
| 78 | - $this->set_id( $subscription->get_id() ); |
|
| 79 | - } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) { |
|
| 80 | - $this->set_id( $subscription_id ); |
|
| 81 | - } elseif ( ! empty( $subscription->id ) ) { |
|
| 82 | - $this->set_id( $subscription->id ); |
|
| 75 | + if (!$deprecated && !empty($subscription) && is_numeric($subscription)) { |
|
| 76 | + $this->set_id($subscription); |
|
| 77 | + } elseif ($subscription instanceof self) { |
|
| 78 | + $this->set_id($subscription->get_id()); |
|
| 79 | + } elseif ($deprecated && $subscription_id = self::get_subscription_id_by_field($subscription, 'profile_id')) { |
|
| 80 | + $this->set_id($subscription_id); |
|
| 81 | + } elseif (!empty($subscription->id)) { |
|
| 82 | + $this->set_id($subscription->id); |
|
| 83 | 83 | } else { |
| 84 | - $this->set_object_read( true ); |
|
| 84 | + $this->set_object_read(true); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | // Load the datastore. |
| 88 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 88 | + $this->data_store = GetPaid_Data_Store::load($this->data_store_name); |
|
| 89 | 89 | |
| 90 | - if ( $this->get_id() > 0 ) { |
|
| 91 | - $this->data_store->read( $this ); |
|
| 90 | + if ($this->get_id() > 0) { |
|
| 91 | + $this->data_store->read($this); |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | } |
@@ -103,17 +103,17 @@ discard block |
||
| 103 | 103 | * @since 1.0.19 |
| 104 | 104 | * @return int |
| 105 | 105 | */ |
| 106 | - public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) { |
|
| 106 | + public static function get_subscription_id_by_field($value, $field = 'profile_id') { |
|
| 107 | 107 | global $wpdb; |
| 108 | 108 | |
| 109 | 109 | // Trim the value. |
| 110 | - $value = trim( $value ); |
|
| 110 | + $value = trim($value); |
|
| 111 | 111 | |
| 112 | - if ( empty( $value ) ) { |
|
| 112 | + if (empty($value)) { |
|
| 113 | 113 | return 0; |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | - if ( 'invoice_id' == $field ) { |
|
| 116 | + if ('invoice_id' == $field) { |
|
| 117 | 117 | $field = 'parent_payment_id'; |
| 118 | 118 | } |
| 119 | 119 | |
@@ -125,28 +125,28 @@ discard block |
||
| 125 | 125 | ); |
| 126 | 126 | |
| 127 | 127 | // Ensure a field has been passed. |
| 128 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 128 | + if (empty($field) || !in_array($field, $fields)) { |
|
| 129 | 129 | return 0; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | // Maybe retrieve from the cache. |
| 133 | - $subscription_id = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
| 134 | - if ( ! empty( $subscription_id ) ) { |
|
| 133 | + $subscription_id = wp_cache_get($value, "getpaid_subscription_{$field}s_to_subscription_ids"); |
|
| 134 | + if (!empty($subscription_id)) { |
|
| 135 | 135 | return $subscription_id; |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | // Fetch from the db. |
| 139 | 139 | $table = $wpdb->prefix . 'wpinv_subscriptions'; |
| 140 | 140 | $subscription_id = (int) $wpdb->get_var( |
| 141 | - $wpdb->prepare( "SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value ) |
|
| 141 | + $wpdb->prepare("SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value) |
|
| 142 | 142 | ); |
| 143 | 143 | |
| 144 | - if ( empty( $subscription_id ) ) { |
|
| 144 | + if (empty($subscription_id)) { |
|
| 145 | 145 | return 0; |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | // Update the cache with our data. |
| 149 | - wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
| 149 | + wp_cache_set($value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids"); |
|
| 150 | 150 | |
| 151 | 151 | return $subscription_id; |
| 152 | 152 | } |
@@ -155,17 +155,17 @@ discard block |
||
| 155 | 155 | * Clears the subscription's cache. |
| 156 | 156 | */ |
| 157 | 157 | public function clear_cache() { |
| 158 | - wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' ); |
|
| 159 | - wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' ); |
|
| 160 | - wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' ); |
|
| 161 | - wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' ); |
|
| 158 | + wp_cache_delete($this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids'); |
|
| 159 | + wp_cache_delete($this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids'); |
|
| 160 | + wp_cache_delete($this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids'); |
|
| 161 | + wp_cache_delete($this->get_id(), 'getpaid_subscriptions'); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | /** |
| 165 | 165 | * Checks if a subscription key is set. |
| 166 | 166 | */ |
| 167 | - public function _isset( $key ) { |
|
| 168 | - return isset( $this->data[$key] ) || method_exists( $this, "get_$key" ); |
|
| 167 | + public function _isset($key) { |
|
| 168 | + return isset($this->data[$key]) || method_exists($this, "get_$key"); |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | /* |
@@ -190,8 +190,8 @@ discard block |
||
| 190 | 190 | * @param string $context View or edit context. |
| 191 | 191 | * @return int |
| 192 | 192 | */ |
| 193 | - public function get_customer_id( $context = 'view' ) { |
|
| 194 | - return (int) $this->get_prop( 'customer_id', $context ); |
|
| 193 | + public function get_customer_id($context = 'view') { |
|
| 194 | + return (int) $this->get_prop('customer_id', $context); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
@@ -201,8 +201,8 @@ discard block |
||
| 201 | 201 | * @param string $context View or edit context. |
| 202 | 202 | * @return WP_User|false WP_User object on success, false on failure. |
| 203 | 203 | */ |
| 204 | - public function get_customer( $context = 'view' ) { |
|
| 205 | - return get_userdata( $this->get_customer_id( $context ) ); |
|
| 204 | + public function get_customer($context = 'view') { |
|
| 205 | + return get_userdata($this->get_customer_id($context)); |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | /** |
@@ -212,8 +212,8 @@ discard block |
||
| 212 | 212 | * @param string $context View or edit context. |
| 213 | 213 | * @return int |
| 214 | 214 | */ |
| 215 | - public function get_parent_invoice_id( $context = 'view' ) { |
|
| 216 | - return (int) $this->get_prop( 'parent_payment_id', $context ); |
|
| 215 | + public function get_parent_invoice_id($context = 'view') { |
|
| 216 | + return (int) $this->get_prop('parent_payment_id', $context); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | /** |
@@ -223,8 +223,8 @@ discard block |
||
| 223 | 223 | * @param string $context View or edit context. |
| 224 | 224 | * @return int |
| 225 | 225 | */ |
| 226 | - public function get_parent_payment_id( $context = 'view' ) { |
|
| 227 | - return $this->get_parent_invoice_id( $context ); |
|
| 226 | + public function get_parent_payment_id($context = 'view') { |
|
| 227 | + return $this->get_parent_invoice_id($context); |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | /** |
@@ -233,8 +233,8 @@ discard block |
||
| 233 | 233 | * @since 1.0.0 |
| 234 | 234 | * @return int |
| 235 | 235 | */ |
| 236 | - public function get_original_payment_id( $context = 'view' ) { |
|
| 237 | - return $this->get_parent_invoice_id( $context ); |
|
| 236 | + public function get_original_payment_id($context = 'view') { |
|
| 237 | + return $this->get_parent_invoice_id($context); |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | /** |
@@ -244,8 +244,8 @@ discard block |
||
| 244 | 244 | * @param string $context View or edit context. |
| 245 | 245 | * @return WPInv_Invoice |
| 246 | 246 | */ |
| 247 | - public function get_parent_invoice( $context = 'view' ) { |
|
| 248 | - return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) ); |
|
| 247 | + public function get_parent_invoice($context = 'view') { |
|
| 248 | + return new WPInv_Invoice($this->get_parent_invoice_id($context)); |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | /** |
@@ -255,8 +255,8 @@ discard block |
||
| 255 | 255 | * @param string $context View or edit context. |
| 256 | 256 | * @return WPInv_Invoice |
| 257 | 257 | */ |
| 258 | - public function get_parent_payment( $context = 'view' ) { |
|
| 259 | - return $this->get_parent_invoice( $context ); |
|
| 258 | + public function get_parent_payment($context = 'view') { |
|
| 259 | + return $this->get_parent_invoice($context); |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | /** |
@@ -266,8 +266,8 @@ discard block |
||
| 266 | 266 | * @param string $context View or edit context. |
| 267 | 267 | * @return int |
| 268 | 268 | */ |
| 269 | - public function get_product_id( $context = 'view' ) { |
|
| 270 | - return (int) $this->get_prop( 'product_id', $context ); |
|
| 269 | + public function get_product_id($context = 'view') { |
|
| 270 | + return (int) $this->get_prop('product_id', $context); |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | /** |
@@ -277,8 +277,8 @@ discard block |
||
| 277 | 277 | * @param string $context View or edit context. |
| 278 | 278 | * @return WPInv_Item |
| 279 | 279 | */ |
| 280 | - public function get_product( $context = 'view' ) { |
|
| 281 | - return new WPInv_Item( $this->get_product_id( $context ) ); |
|
| 280 | + public function get_product($context = 'view') { |
|
| 281 | + return new WPInv_Item($this->get_product_id($context)); |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | /** |
@@ -290,8 +290,8 @@ discard block |
||
| 290 | 290 | * @param string $context View or edit context. |
| 291 | 291 | * @return string |
| 292 | 292 | */ |
| 293 | - public function get_gateway( $context = 'view' ) { |
|
| 294 | - return $this->get_parent_invoice( $context )->get_gateway(); |
|
| 293 | + public function get_gateway($context = 'view') { |
|
| 294 | + return $this->get_parent_invoice($context)->get_gateway(); |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | /** |
@@ -301,8 +301,8 @@ discard block |
||
| 301 | 301 | * @param string $context View or edit context. |
| 302 | 302 | * @return string |
| 303 | 303 | */ |
| 304 | - public function get_period( $context = 'view' ) { |
|
| 305 | - return $this->get_prop( 'period', $context ); |
|
| 304 | + public function get_period($context = 'view') { |
|
| 305 | + return $this->get_prop('period', $context); |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | /** |
@@ -312,8 +312,8 @@ discard block |
||
| 312 | 312 | * @param string $context View or edit context. |
| 313 | 313 | * @return int |
| 314 | 314 | */ |
| 315 | - public function get_frequency( $context = 'view' ) { |
|
| 316 | - return (int) $this->get_prop( 'frequency', $context ); |
|
| 315 | + public function get_frequency($context = 'view') { |
|
| 316 | + return (int) $this->get_prop('frequency', $context); |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | /** |
@@ -323,8 +323,8 @@ discard block |
||
| 323 | 323 | * @param string $context View or edit context. |
| 324 | 324 | * @return float |
| 325 | 325 | */ |
| 326 | - public function get_initial_amount( $context = 'view' ) { |
|
| 327 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) ); |
|
| 326 | + public function get_initial_amount($context = 'view') { |
|
| 327 | + return (float) wpinv_sanitize_amount($this->get_prop('initial_amount', $context)); |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | /** |
@@ -334,8 +334,8 @@ discard block |
||
| 334 | 334 | * @param string $context View or edit context. |
| 335 | 335 | * @return float |
| 336 | 336 | */ |
| 337 | - public function get_recurring_amount( $context = 'view' ) { |
|
| 338 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) ); |
|
| 337 | + public function get_recurring_amount($context = 'view') { |
|
| 338 | + return (float) wpinv_sanitize_amount($this->get_prop('recurring_amount', $context)); |
|
| 339 | 339 | } |
| 340 | 340 | |
| 341 | 341 | /** |
@@ -345,8 +345,8 @@ discard block |
||
| 345 | 345 | * @param string $context View or edit context. |
| 346 | 346 | * @return int |
| 347 | 347 | */ |
| 348 | - public function get_bill_times( $context = 'view' ) { |
|
| 349 | - return (int) $this->get_prop( 'bill_times', $context ); |
|
| 348 | + public function get_bill_times($context = 'view') { |
|
| 349 | + return (int) $this->get_prop('bill_times', $context); |
|
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | /** |
@@ -356,8 +356,8 @@ discard block |
||
| 356 | 356 | * @param string $context View or edit context. |
| 357 | 357 | * @return string |
| 358 | 358 | */ |
| 359 | - public function get_transaction_id( $context = 'view' ) { |
|
| 360 | - return $this->get_prop( 'transaction_id', $context ); |
|
| 359 | + public function get_transaction_id($context = 'view') { |
|
| 360 | + return $this->get_prop('transaction_id', $context); |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | /** |
@@ -367,8 +367,8 @@ discard block |
||
| 367 | 367 | * @param string $context View or edit context. |
| 368 | 368 | * @return string |
| 369 | 369 | */ |
| 370 | - public function get_created( $context = 'view' ) { |
|
| 371 | - return $this->get_prop( 'created', $context ); |
|
| 370 | + public function get_created($context = 'view') { |
|
| 371 | + return $this->get_prop('created', $context); |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | /** |
@@ -378,8 +378,8 @@ discard block |
||
| 378 | 378 | * @param string $context View or edit context. |
| 379 | 379 | * @return string |
| 380 | 380 | */ |
| 381 | - public function get_date_created( $context = 'view' ) { |
|
| 382 | - return $this->get_created( $context ); |
|
| 381 | + public function get_date_created($context = 'view') { |
|
| 382 | + return $this->get_created($context); |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | /** |
@@ -390,7 +390,7 @@ discard block |
||
| 390 | 390 | */ |
| 391 | 391 | public function get_time_created() { |
| 392 | 392 | $created = $this->get_date_created(); |
| 393 | - return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) ); |
|
| 393 | + return empty($created) ? current_time('timestamp') : strtotime($created, current_time('timestamp')); |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | /** |
@@ -400,11 +400,11 @@ discard block |
||
| 400 | 400 | * @param string $context View or edit context. |
| 401 | 401 | * @return string |
| 402 | 402 | */ |
| 403 | - public function get_date_created_gmt( $context = 'view' ) { |
|
| 404 | - $date = $this->get_date_created( $context ); |
|
| 403 | + public function get_date_created_gmt($context = 'view') { |
|
| 404 | + $date = $this->get_date_created($context); |
|
| 405 | 405 | |
| 406 | - if ( $date ) { |
|
| 407 | - $date = get_gmt_from_date( $date ); |
|
| 406 | + if ($date) { |
|
| 407 | + $date = get_gmt_from_date($date); |
|
| 408 | 408 | } |
| 409 | 409 | return $date; |
| 410 | 410 | } |
@@ -416,8 +416,8 @@ discard block |
||
| 416 | 416 | * @param string $context View or edit context. |
| 417 | 417 | * @return string |
| 418 | 418 | */ |
| 419 | - public function get_next_renewal_date( $context = 'view' ) { |
|
| 420 | - return $this->get_prop( 'expiration', $context ); |
|
| 419 | + public function get_next_renewal_date($context = 'view') { |
|
| 420 | + return $this->get_prop('expiration', $context); |
|
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | /** |
@@ -427,8 +427,8 @@ discard block |
||
| 427 | 427 | * @param string $context View or edit context. |
| 428 | 428 | * @return string |
| 429 | 429 | */ |
| 430 | - public function get_expiration( $context = 'view' ) { |
|
| 431 | - return $this->get_next_renewal_date( $context ); |
|
| 430 | + public function get_expiration($context = 'view') { |
|
| 431 | + return $this->get_next_renewal_date($context); |
|
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | /** |
@@ -440,12 +440,12 @@ discard block |
||
| 440 | 440 | public function get_expiration_time() { |
| 441 | 441 | $expiration = $this->get_expiration(); |
| 442 | 442 | |
| 443 | - if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
| 444 | - return current_time( 'timestamp' ); |
|
| 443 | + if (empty($expiration) || '0000-00-00 00:00:00' == $expiration) { |
|
| 444 | + return current_time('timestamp'); |
|
| 445 | 445 | } |
| 446 | 446 | |
| 447 | - $expiration = strtotime( $expiration, current_time( 'timestamp' ) ); |
|
| 448 | - return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration; |
|
| 447 | + $expiration = strtotime($expiration, current_time('timestamp')); |
|
| 448 | + return $expiration < current_time('timestamp') ? current_time('timestamp') : $expiration; |
|
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | /** |
@@ -455,11 +455,11 @@ discard block |
||
| 455 | 455 | * @param string $context View or edit context. |
| 456 | 456 | * @return string |
| 457 | 457 | */ |
| 458 | - public function get_next_renewal_date_gmt( $context = 'view' ) { |
|
| 459 | - $date = $this->get_next_renewal_date( $context ); |
|
| 458 | + public function get_next_renewal_date_gmt($context = 'view') { |
|
| 459 | + $date = $this->get_next_renewal_date($context); |
|
| 460 | 460 | |
| 461 | - if ( $date ) { |
|
| 462 | - $date = get_gmt_from_date( $date ); |
|
| 461 | + if ($date) { |
|
| 462 | + $date = get_gmt_from_date($date); |
|
| 463 | 463 | } |
| 464 | 464 | return $date; |
| 465 | 465 | } |
@@ -471,8 +471,8 @@ discard block |
||
| 471 | 471 | * @param string $context View or edit context. |
| 472 | 472 | * @return string |
| 473 | 473 | */ |
| 474 | - public function get_trial_period( $context = 'view' ) { |
|
| 475 | - return $this->get_prop( 'trial_period', $context ); |
|
| 474 | + public function get_trial_period($context = 'view') { |
|
| 475 | + return $this->get_prop('trial_period', $context); |
|
| 476 | 476 | } |
| 477 | 477 | |
| 478 | 478 | /** |
@@ -482,8 +482,8 @@ discard block |
||
| 482 | 482 | * @param string $context View or edit context. |
| 483 | 483 | * @return string |
| 484 | 484 | */ |
| 485 | - public function get_status( $context = 'view' ) { |
|
| 486 | - return $this->get_prop( 'status', $context ); |
|
| 485 | + public function get_status($context = 'view') { |
|
| 486 | + return $this->get_prop('status', $context); |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | /** |
@@ -493,8 +493,8 @@ discard block |
||
| 493 | 493 | * @param string $context View or edit context. |
| 494 | 494 | * @return string |
| 495 | 495 | */ |
| 496 | - public function get_profile_id( $context = 'view' ) { |
|
| 497 | - return $this->get_prop( 'profile_id', $context ); |
|
| 496 | + public function get_profile_id($context = 'view') { |
|
| 497 | + return $this->get_prop('profile_id', $context); |
|
| 498 | 498 | } |
| 499 | 499 | |
| 500 | 500 | /* |
@@ -509,8 +509,8 @@ discard block |
||
| 509 | 509 | * @since 1.0.19 |
| 510 | 510 | * @param int $value The customer's id. |
| 511 | 511 | */ |
| 512 | - public function set_customer_id( $value ) { |
|
| 513 | - $this->set_prop( 'customer_id', (int) $value ); |
|
| 512 | + public function set_customer_id($value) { |
|
| 513 | + $this->set_prop('customer_id', (int) $value); |
|
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | /** |
@@ -519,8 +519,8 @@ discard block |
||
| 519 | 519 | * @since 1.0.19 |
| 520 | 520 | * @param int $value The parent invoice id. |
| 521 | 521 | */ |
| 522 | - public function set_parent_invoice_id( $value ) { |
|
| 523 | - $this->set_prop( 'parent_payment_id', (int) $value ); |
|
| 522 | + public function set_parent_invoice_id($value) { |
|
| 523 | + $this->set_prop('parent_payment_id', (int) $value); |
|
| 524 | 524 | } |
| 525 | 525 | |
| 526 | 526 | /** |
@@ -529,8 +529,8 @@ discard block |
||
| 529 | 529 | * @since 1.0.19 |
| 530 | 530 | * @param int $value The parent invoice id. |
| 531 | 531 | */ |
| 532 | - public function set_parent_payment_id( $value ) { |
|
| 533 | - $this->set_parent_invoice_id( $value ); |
|
| 532 | + public function set_parent_payment_id($value) { |
|
| 533 | + $this->set_parent_invoice_id($value); |
|
| 534 | 534 | } |
| 535 | 535 | |
| 536 | 536 | /** |
@@ -539,8 +539,8 @@ discard block |
||
| 539 | 539 | * @since 1.0.19 |
| 540 | 540 | * @param int $value The parent invoice id. |
| 541 | 541 | */ |
| 542 | - public function set_original_payment_id( $value ) { |
|
| 543 | - $this->set_parent_invoice_id( $value ); |
|
| 542 | + public function set_original_payment_id($value) { |
|
| 543 | + $this->set_parent_invoice_id($value); |
|
| 544 | 544 | } |
| 545 | 545 | |
| 546 | 546 | /** |
@@ -549,8 +549,8 @@ discard block |
||
| 549 | 549 | * @since 1.0.19 |
| 550 | 550 | * @param int $value The subscription product id. |
| 551 | 551 | */ |
| 552 | - public function set_product_id( $value ) { |
|
| 553 | - $this->set_prop( 'product_id', (int) $value ); |
|
| 552 | + public function set_product_id($value) { |
|
| 553 | + $this->set_prop('product_id', (int) $value); |
|
| 554 | 554 | } |
| 555 | 555 | |
| 556 | 556 | /** |
@@ -559,8 +559,8 @@ discard block |
||
| 559 | 559 | * @since 1.0.19 |
| 560 | 560 | * @param string $value The renewal period. |
| 561 | 561 | */ |
| 562 | - public function set_period( $value ) { |
|
| 563 | - $this->set_prop( 'period', $value ); |
|
| 562 | + public function set_period($value) { |
|
| 563 | + $this->set_prop('period', $value); |
|
| 564 | 564 | } |
| 565 | 565 | |
| 566 | 566 | /** |
@@ -569,9 +569,9 @@ discard block |
||
| 569 | 569 | * @since 1.0.19 |
| 570 | 570 | * @param int $value The subscription frequency. |
| 571 | 571 | */ |
| 572 | - public function set_frequency( $value ) { |
|
| 573 | - $value = empty( $value ) ? 1 : (int) $value; |
|
| 574 | - $this->set_prop( 'frequency', absint( $value ) ); |
|
| 572 | + public function set_frequency($value) { |
|
| 573 | + $value = empty($value) ? 1 : (int) $value; |
|
| 574 | + $this->set_prop('frequency', absint($value)); |
|
| 575 | 575 | } |
| 576 | 576 | |
| 577 | 577 | /** |
@@ -580,8 +580,8 @@ discard block |
||
| 580 | 580 | * @since 1.0.19 |
| 581 | 581 | * @param float $value The initial subcription amount. |
| 582 | 582 | */ |
| 583 | - public function set_initial_amount( $value ) { |
|
| 584 | - $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) ); |
|
| 583 | + public function set_initial_amount($value) { |
|
| 584 | + $this->set_prop('initial_amount', wpinv_sanitize_amount($value)); |
|
| 585 | 585 | } |
| 586 | 586 | |
| 587 | 587 | /** |
@@ -590,8 +590,8 @@ discard block |
||
| 590 | 590 | * @since 1.0.19 |
| 591 | 591 | * @param float $value The recurring subcription amount. |
| 592 | 592 | */ |
| 593 | - public function set_recurring_amount( $value ) { |
|
| 594 | - $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) ); |
|
| 593 | + public function set_recurring_amount($value) { |
|
| 594 | + $this->set_prop('recurring_amount', wpinv_sanitize_amount($value)); |
|
| 595 | 595 | } |
| 596 | 596 | |
| 597 | 597 | /** |
@@ -600,8 +600,8 @@ discard block |
||
| 600 | 600 | * @since 1.0.19 |
| 601 | 601 | * @param int $value Bill times. |
| 602 | 602 | */ |
| 603 | - public function set_bill_times( $value ) { |
|
| 604 | - $this->set_prop( 'bill_times', (int) $value ); |
|
| 603 | + public function set_bill_times($value) { |
|
| 604 | + $this->set_prop('bill_times', (int) $value); |
|
| 605 | 605 | } |
| 606 | 606 | |
| 607 | 607 | /** |
@@ -610,8 +610,8 @@ discard block |
||
| 610 | 610 | * @since 1.0.19 |
| 611 | 611 | * @param string $value Bill times. |
| 612 | 612 | */ |
| 613 | - public function set_transaction_id( $value ) { |
|
| 614 | - $this->set_prop( 'transaction_id', sanitize_text_field( $value ) ); |
|
| 613 | + public function set_transaction_id($value) { |
|
| 614 | + $this->set_prop('transaction_id', sanitize_text_field($value)); |
|
| 615 | 615 | } |
| 616 | 616 | |
| 617 | 617 | /** |
@@ -620,15 +620,15 @@ discard block |
||
| 620 | 620 | * @since 1.0.19 |
| 621 | 621 | * @param string $value strtotime compliant date. |
| 622 | 622 | */ |
| 623 | - public function set_created( $value ) { |
|
| 624 | - $date = strtotime( $value ); |
|
| 623 | + public function set_created($value) { |
|
| 624 | + $date = strtotime($value); |
|
| 625 | 625 | |
| 626 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
| 627 | - $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) ); |
|
| 626 | + if ($date && $value !== '0000-00-00 00:00:00') { |
|
| 627 | + $this->set_prop('created', date('Y-m-d H:i:s', $date)); |
|
| 628 | 628 | return; |
| 629 | 629 | } |
| 630 | 630 | |
| 631 | - $this->set_prop( 'created', '' ); |
|
| 631 | + $this->set_prop('created', ''); |
|
| 632 | 632 | |
| 633 | 633 | } |
| 634 | 634 | |
@@ -638,8 +638,8 @@ discard block |
||
| 638 | 638 | * @since 1.0.19 |
| 639 | 639 | * @param string $value strtotime compliant date. |
| 640 | 640 | */ |
| 641 | - public function set_date_created( $value ) { |
|
| 642 | - $this->set_created( $value ); |
|
| 641 | + public function set_date_created($value) { |
|
| 642 | + $this->set_created($value); |
|
| 643 | 643 | } |
| 644 | 644 | |
| 645 | 645 | /** |
@@ -648,15 +648,15 @@ discard block |
||
| 648 | 648 | * @since 1.0.19 |
| 649 | 649 | * @param string $value strtotime compliant date. |
| 650 | 650 | */ |
| 651 | - public function set_next_renewal_date( $value ) { |
|
| 652 | - $date = strtotime( $value ); |
|
| 651 | + public function set_next_renewal_date($value) { |
|
| 652 | + $date = strtotime($value); |
|
| 653 | 653 | |
| 654 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
| 655 | - $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) ); |
|
| 654 | + if ($date && $value !== '0000-00-00 00:00:00') { |
|
| 655 | + $this->set_prop('expiration', date('Y-m-d H:i:s', $date)); |
|
| 656 | 656 | return; |
| 657 | 657 | } |
| 658 | 658 | |
| 659 | - $this->set_prop( 'expiration', '' ); |
|
| 659 | + $this->set_prop('expiration', ''); |
|
| 660 | 660 | |
| 661 | 661 | } |
| 662 | 662 | |
@@ -666,8 +666,8 @@ discard block |
||
| 666 | 666 | * @since 1.0.19 |
| 667 | 667 | * @param string $value strtotime compliant date. |
| 668 | 668 | */ |
| 669 | - public function set_expiration( $value ) { |
|
| 670 | - $this->set_next_renewal_date( $value ); |
|
| 669 | + public function set_expiration($value) { |
|
| 670 | + $this->set_next_renewal_date($value); |
|
| 671 | 671 | } |
| 672 | 672 | |
| 673 | 673 | /** |
@@ -676,8 +676,8 @@ discard block |
||
| 676 | 676 | * @since 1.0.19 |
| 677 | 677 | * @param string $value trial period e.g 1 year. |
| 678 | 678 | */ |
| 679 | - public function set_trial_period( $value ) { |
|
| 680 | - $this->set_prop( 'trial_period', $value ); |
|
| 679 | + public function set_trial_period($value) { |
|
| 680 | + $this->set_prop('trial_period', $value); |
|
| 681 | 681 | } |
| 682 | 682 | |
| 683 | 683 | /** |
@@ -686,19 +686,19 @@ discard block |
||
| 686 | 686 | * @since 1.0.19 |
| 687 | 687 | * @param string $new_status New subscription status. |
| 688 | 688 | */ |
| 689 | - public function set_status( $new_status ) { |
|
| 689 | + public function set_status($new_status) { |
|
| 690 | 690 | |
| 691 | 691 | // Abort if this is not a valid status; |
| 692 | - if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) { |
|
| 692 | + if (!array_key_exists($new_status, getpaid_get_subscription_statuses())) { |
|
| 693 | 693 | return; |
| 694 | 694 | } |
| 695 | 695 | |
| 696 | 696 | $old_status = $this->get_status(); |
| 697 | - $this->set_prop( 'status', $new_status ); |
|
| 697 | + $this->set_prop('status', $new_status); |
|
| 698 | 698 | |
| 699 | - if ( true === $this->object_read && $old_status !== $new_status ) { |
|
| 699 | + if (true === $this->object_read && $old_status !== $new_status) { |
|
| 700 | 700 | $this->status_transition = array( |
| 701 | - 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
| 701 | + 'from' => !empty($this->status_transition['from']) ? $this->status_transition['from'] : $old_status, |
|
| 702 | 702 | 'to' => $new_status, |
| 703 | 703 | ); |
| 704 | 704 | } |
@@ -711,8 +711,8 @@ discard block |
||
| 711 | 711 | * @since 1.0.19 |
| 712 | 712 | * @param string $value the remote profile id. |
| 713 | 713 | */ |
| 714 | - public function set_profile_id( $value ) { |
|
| 715 | - $this->set_prop( 'profile_id', sanitize_text_field( $value ) ); |
|
| 714 | + public function set_profile_id($value) { |
|
| 715 | + $this->set_prop('profile_id', sanitize_text_field($value)); |
|
| 716 | 716 | } |
| 717 | 717 | |
| 718 | 718 | /* |
@@ -730,8 +730,8 @@ discard block |
||
| 730 | 730 | * @param string|array String or array of strings to check for. |
| 731 | 731 | * @return bool |
| 732 | 732 | */ |
| 733 | - public function has_status( $status ) { |
|
| 734 | - return in_array( $this->get_status(), wpinv_clean( wpinv_parse_list( $status ) ) ); |
|
| 733 | + public function has_status($status) { |
|
| 734 | + return in_array($this->get_status(), wpinv_clean(wpinv_parse_list($status))); |
|
| 735 | 735 | } |
| 736 | 736 | |
| 737 | 737 | /** |
@@ -741,7 +741,7 @@ discard block |
||
| 741 | 741 | */ |
| 742 | 742 | public function has_trial_period() { |
| 743 | 743 | $period = $this->get_trial_period(); |
| 744 | - return ! empty( $period ); |
|
| 744 | + return !empty($period); |
|
| 745 | 745 | } |
| 746 | 746 | |
| 747 | 747 | /** |
@@ -750,7 +750,7 @@ discard block |
||
| 750 | 750 | * @return bool |
| 751 | 751 | */ |
| 752 | 752 | public function is_active() { |
| 753 | - return $this->has_status( 'active trialling' ) && ! $this->is_expired(); |
|
| 753 | + return $this->has_status('active trialling') && !$this->is_expired(); |
|
| 754 | 754 | } |
| 755 | 755 | |
| 756 | 756 | /** |
@@ -759,7 +759,7 @@ discard block |
||
| 759 | 759 | * @return bool |
| 760 | 760 | */ |
| 761 | 761 | public function is_expired() { |
| 762 | - return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) ); |
|
| 762 | + return $this->has_status('expired') || ($this->has_status('active cancelled trialling') && $this->get_expiration_time() < current_time('mysql')); |
|
| 763 | 763 | } |
| 764 | 764 | |
| 765 | 765 | /** |
@@ -769,7 +769,7 @@ discard block |
||
| 769 | 769 | */ |
| 770 | 770 | public function is_last_renewal() { |
| 771 | 771 | $max_bills = $this->get_bill_times(); |
| 772 | - return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed(); |
|
| 772 | + return !empty($max_bills) && $max_bills <= $this->get_times_billed(); |
|
| 773 | 773 | } |
| 774 | 774 | |
| 775 | 775 | /* |
@@ -784,11 +784,11 @@ discard block |
||
| 784 | 784 | /** |
| 785 | 785 | * Backwards compatibilty. |
| 786 | 786 | */ |
| 787 | - public function create( $data = array() ) { |
|
| 787 | + public function create($data = array()) { |
|
| 788 | 788 | |
| 789 | 789 | // Set the properties. |
| 790 | - if ( is_array( $data ) ) { |
|
| 791 | - $this->set_props( $data ); |
|
| 790 | + if (is_array($data)) { |
|
| 791 | + $this->set_props($data); |
|
| 792 | 792 | } |
| 793 | 793 | |
| 794 | 794 | // Save the item. |
@@ -799,8 +799,8 @@ discard block |
||
| 799 | 799 | /** |
| 800 | 800 | * Backwards compatibilty. |
| 801 | 801 | */ |
| 802 | - public function update( $args = array() ) { |
|
| 803 | - return $this->create( $args ); |
|
| 802 | + public function update($args = array()) { |
|
| 803 | + return $this->create($args); |
|
| 804 | 804 | } |
| 805 | 805 | |
| 806 | 806 | /** |
@@ -809,12 +809,12 @@ discard block |
||
| 809 | 809 | * @since 1.0.0 |
| 810 | 810 | * @return WP_Post[] |
| 811 | 811 | */ |
| 812 | - public function get_child_payments( $hide_pending = true ) { |
|
| 812 | + public function get_child_payments($hide_pending = true) { |
|
| 813 | 813 | |
| 814 | - $statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' ); |
|
| 814 | + $statuses = array('publish', 'wpi-processing', 'wpi-renewal'); |
|
| 815 | 815 | |
| 816 | - if ( ! $hide_pending ) { |
|
| 817 | - $statuses = array_keys( wpinv_get_invoice_statuses() ); |
|
| 816 | + if (!$hide_pending) { |
|
| 817 | + $statuses = array_keys(wpinv_get_invoice_statuses()); |
|
| 818 | 818 | } |
| 819 | 819 | |
| 820 | 820 | return get_posts( |
@@ -836,7 +836,7 @@ discard block |
||
| 836 | 836 | * @return int |
| 837 | 837 | */ |
| 838 | 838 | public function get_total_payments() { |
| 839 | - return getpaid_count_subscription_invoices( $this->get_parent_invoice_id() ); |
|
| 839 | + return getpaid_count_subscription_invoices($this->get_parent_invoice_id()); |
|
| 840 | 840 | } |
| 841 | 841 | |
| 842 | 842 | /** |
@@ -848,7 +848,7 @@ discard block |
||
| 848 | 848 | public function get_times_billed() { |
| 849 | 849 | $times_billed = $this->get_total_payments(); |
| 850 | 850 | |
| 851 | - if ( (float) $this->get_initial_amount() == 0 && $times_billed > 0 ) { |
|
| 851 | + if ((float) $this->get_initial_amount() == 0 && $times_billed > 0) { |
|
| 852 | 852 | $times_billed--; |
| 853 | 853 | } |
| 854 | 854 | |
@@ -863,49 +863,49 @@ discard block |
||
| 863 | 863 | * @param WPInv_Invoice $invoice If adding an existing invoice. |
| 864 | 864 | * @return bool |
| 865 | 865 | */ |
| 866 | - public function add_payment( $args = array(), $invoice = false ) { |
|
| 866 | + public function add_payment($args = array(), $invoice = false) { |
|
| 867 | 867 | |
| 868 | 868 | // Process each payment once. |
| 869 | - if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) { |
|
| 869 | + if (!empty($args['transaction_id']) && $this->payment_exists($args['transaction_id'])) { |
|
| 870 | 870 | return false; |
| 871 | 871 | } |
| 872 | 872 | |
| 873 | 873 | // Are we creating a new invoice? |
| 874 | - if ( empty( $invoice ) ) { |
|
| 874 | + if (empty($invoice)) { |
|
| 875 | 875 | $invoice = $this->create_payment(); |
| 876 | 876 | |
| 877 | - if ( empty( $invoice ) ) { |
|
| 877 | + if (empty($invoice)) { |
|
| 878 | 878 | return false; |
| 879 | 879 | } |
| 880 | 880 | |
| 881 | 881 | } |
| 882 | 882 | |
| 883 | - $invoice->set_status( 'wpi-renewal' ); |
|
| 883 | + $invoice->set_status('wpi-renewal'); |
|
| 884 | 884 | |
| 885 | 885 | // Maybe set a transaction id. |
| 886 | - if ( ! empty( $args['transaction_id'] ) ) { |
|
| 887 | - $invoice->set_transaction_id( $args['transaction_id'] ); |
|
| 886 | + if (!empty($args['transaction_id'])) { |
|
| 887 | + $invoice->set_transaction_id($args['transaction_id']); |
|
| 888 | 888 | } |
| 889 | 889 | |
| 890 | 890 | // Set the completed date. |
| 891 | - $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
| 891 | + $invoice->set_completed_date(current_time('mysql')); |
|
| 892 | 892 | |
| 893 | 893 | // And the gateway. |
| 894 | - if ( ! empty( $args['gateway'] ) ) { |
|
| 895 | - $invoice->set_gateway( $args['gateway'] ); |
|
| 894 | + if (!empty($args['gateway'])) { |
|
| 895 | + $invoice->set_gateway($args['gateway']); |
|
| 896 | 896 | } |
| 897 | 897 | |
| 898 | 898 | $invoice->save(); |
| 899 | 899 | |
| 900 | - if ( ! $invoice->exists() ) { |
|
| 900 | + if (!$invoice->exists()) { |
|
| 901 | 901 | return false; |
| 902 | 902 | } |
| 903 | 903 | |
| 904 | - do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
| 905 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
| 906 | - do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() ); |
|
| 904 | + do_action('getpaid_after_create_subscription_renewal_invoice', $invoice, $this); |
|
| 905 | + do_action('wpinv_recurring_add_subscription_payment', $invoice, $this); |
|
| 906 | + do_action('wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id()); |
|
| 907 | 907 | |
| 908 | - update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id ); |
|
| 908 | + update_post_meta($invoice->get_id(), '_wpinv_subscription_id', $this->id); |
|
| 909 | 909 | |
| 910 | 910 | return $invoice->get_id(); |
| 911 | 911 | } |
@@ -920,41 +920,41 @@ discard block |
||
| 920 | 920 | |
| 921 | 921 | $parent_invoice = $this->get_parent_payment(); |
| 922 | 922 | |
| 923 | - if ( ! $parent_invoice->exists() ) { |
|
| 923 | + if (!$parent_invoice->exists()) { |
|
| 924 | 924 | return false; |
| 925 | 925 | } |
| 926 | 926 | |
| 927 | 927 | // Duplicate the parent invoice. |
| 928 | - $invoice = getpaid_duplicate_invoice( $parent_invoice ); |
|
| 929 | - $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
| 930 | - $invoice->set_subscription_id( $this->get_id() ); |
|
| 931 | - $invoice->set_remote_subscription_id( $this->get_profile_id() ); |
|
| 928 | + $invoice = getpaid_duplicate_invoice($parent_invoice); |
|
| 929 | + $invoice->set_parent_id($parent_invoice->get_id()); |
|
| 930 | + $invoice->set_subscription_id($this->get_id()); |
|
| 931 | + $invoice->set_remote_subscription_id($this->get_profile_id()); |
|
| 932 | 932 | |
| 933 | 933 | // Set invoice items. |
| 934 | - $subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() ); |
|
| 935 | - $allowed_items = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] ); |
|
| 934 | + $subscription_group = getpaid_get_invoice_subscription_group($parent_invoice->get_id(), $this->get_id()); |
|
| 935 | + $allowed_items = empty($subscription_group) ? array($this->get_product_id()) : array_keys($subscription_group['items']); |
|
| 936 | 936 | $invoice_items = array(); |
| 937 | 937 | |
| 938 | - foreach ( $invoice->get_items() as $item ) { |
|
| 939 | - if ( in_array( $item->get_id(), $allowed_items ) ) { |
|
| 938 | + foreach ($invoice->get_items() as $item) { |
|
| 939 | + if (in_array($item->get_id(), $allowed_items)) { |
|
| 940 | 940 | $invoice_items[] = $item; |
| 941 | 941 | } |
| 942 | 942 | } |
| 943 | 943 | |
| 944 | - $invoice->set_items( $invoice_items ); |
|
| 944 | + $invoice->set_items($invoice_items); |
|
| 945 | 945 | |
| 946 | - if ( ! empty( $subscription_group['fees'] ) ) { |
|
| 947 | - $invoice->set_fees( $subscription_group['fees'] ); |
|
| 946 | + if (!empty($subscription_group['fees'])) { |
|
| 947 | + $invoice->set_fees($subscription_group['fees']); |
|
| 948 | 948 | } |
| 949 | 949 | |
| 950 | 950 | // Maybe recalculate discount (Pre-GetPaid Fix). |
| 951 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
| 952 | - if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) { |
|
| 953 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
| 951 | + $discount = new WPInv_Discount($invoice->get_discount_code()); |
|
| 952 | + if ($discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount()) { |
|
| 953 | + $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount)); |
|
| 954 | 954 | } |
| 955 | 955 | |
| 956 | 956 | $invoice->recalculate_total(); |
| 957 | - $invoice->set_status( 'wpi-pending' ); |
|
| 957 | + $invoice->set_status('wpi-pending'); |
|
| 958 | 958 | $invoice->save(); |
| 959 | 959 | |
| 960 | 960 | return $invoice->exists() ? $invoice : false; |
@@ -969,20 +969,20 @@ discard block |
||
| 969 | 969 | public function renew() { |
| 970 | 970 | |
| 971 | 971 | // Complete subscription if applicable |
| 972 | - if ( $this->is_last_renewal() ) { |
|
| 972 | + if ($this->is_last_renewal()) { |
|
| 973 | 973 | return $this->complete(); |
| 974 | 974 | } |
| 975 | 975 | |
| 976 | 976 | // Calculate new expiration |
| 977 | 977 | $frequency = $this->get_frequency(); |
| 978 | 978 | $period = $this->get_period(); |
| 979 | - $new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() ); |
|
| 979 | + $new_expiration = strtotime("+ $frequency $period", $this->get_expiration_time()); |
|
| 980 | 980 | |
| 981 | - $this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) ); |
|
| 982 | - $this->set_status( 'active' ); |
|
| 981 | + $this->set_expiration(date('Y-m-d H:i:s', $new_expiration)); |
|
| 982 | + $this->set_status('active'); |
|
| 983 | 983 | $this->save(); |
| 984 | 984 | |
| 985 | - do_action( 'getpaid_subscription_renewed', $this ); |
|
| 985 | + do_action('getpaid_subscription_renewed', $this); |
|
| 986 | 986 | |
| 987 | 987 | return $this->get_id(); |
| 988 | 988 | } |
@@ -998,11 +998,11 @@ discard block |
||
| 998 | 998 | public function complete() { |
| 999 | 999 | |
| 1000 | 1000 | // Only mark a subscription as complete if it's not already cancelled. |
| 1001 | - if ( $this->has_status( 'cancelled' ) ) { |
|
| 1001 | + if ($this->has_status('cancelled')) { |
|
| 1002 | 1002 | return false; |
| 1003 | 1003 | } |
| 1004 | 1004 | |
| 1005 | - $this->set_status( 'completed' ); |
|
| 1005 | + $this->set_status('completed'); |
|
| 1006 | 1006 | return $this->save(); |
| 1007 | 1007 | |
| 1008 | 1008 | } |
@@ -1014,14 +1014,14 @@ discard block |
||
| 1014 | 1014 | * @param bool $check_expiration |
| 1015 | 1015 | * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
| 1016 | 1016 | */ |
| 1017 | - public function expire( $check_expiration = false ) { |
|
| 1017 | + public function expire($check_expiration = false) { |
|
| 1018 | 1018 | |
| 1019 | - if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
| 1019 | + if ($check_expiration && $this->get_expiration_time() > current_time('timestamp')) { |
|
| 1020 | 1020 | // Do not mark as expired since real expiration date is in the future |
| 1021 | 1021 | return false; |
| 1022 | 1022 | } |
| 1023 | 1023 | |
| 1024 | - $this->set_status( 'expired' ); |
|
| 1024 | + $this->set_status('expired'); |
|
| 1025 | 1025 | return $this->save(); |
| 1026 | 1026 | |
| 1027 | 1027 | } |
@@ -1033,7 +1033,7 @@ discard block |
||
| 1033 | 1033 | * @return int Subscription id. |
| 1034 | 1034 | */ |
| 1035 | 1035 | public function failing() { |
| 1036 | - $this->set_status( 'failing' ); |
|
| 1036 | + $this->set_status('failing'); |
|
| 1037 | 1037 | return $this->save(); |
| 1038 | 1038 | } |
| 1039 | 1039 | |
@@ -1044,7 +1044,7 @@ discard block |
||
| 1044 | 1044 | * @return int Subscription id. |
| 1045 | 1045 | */ |
| 1046 | 1046 | public function cancel() { |
| 1047 | - $this->set_status( 'cancelled' ); |
|
| 1047 | + $this->set_status('cancelled'); |
|
| 1048 | 1048 | return $this->save(); |
| 1049 | 1049 | } |
| 1050 | 1050 | |
@@ -1055,7 +1055,7 @@ discard block |
||
| 1055 | 1055 | * @return bool |
| 1056 | 1056 | */ |
| 1057 | 1057 | public function can_cancel() { |
| 1058 | - return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
| 1058 | + return apply_filters('wpinv_subscription_can_cancel', $this->has_status($this->get_cancellable_statuses()), $this); |
|
| 1059 | 1059 | } |
| 1060 | 1060 | |
| 1061 | 1061 | /** |
@@ -1066,7 +1066,7 @@ discard block |
||
| 1066 | 1066 | * @return array |
| 1067 | 1067 | */ |
| 1068 | 1068 | public function get_cancellable_statuses() { |
| 1069 | - return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) ); |
|
| 1069 | + return apply_filters('wpinv_recurring_cancellable_statuses', array('active', 'trialling', 'failing')); |
|
| 1070 | 1070 | } |
| 1071 | 1071 | |
| 1072 | 1072 | /** |
@@ -1076,8 +1076,8 @@ discard block |
||
| 1076 | 1076 | * @return string |
| 1077 | 1077 | */ |
| 1078 | 1078 | public function get_cancel_url() { |
| 1079 | - $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() ); |
|
| 1080 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
| 1079 | + $url = getpaid_get_authenticated_action_url('subscription_cancel', $this->get_view_url()); |
|
| 1080 | + return apply_filters('wpinv_subscription_cancel_url', $url, $this); |
|
| 1081 | 1081 | } |
| 1082 | 1082 | |
| 1083 | 1083 | /** |
@@ -1088,10 +1088,10 @@ discard block |
||
| 1088 | 1088 | */ |
| 1089 | 1089 | public function get_view_url() { |
| 1090 | 1090 | |
| 1091 | - $url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
| 1092 | - $url = add_query_arg( 'subscription', $this->get_id(), $url ); |
|
| 1091 | + $url = getpaid_get_tab_url('gp-subscriptions', get_permalink((int) wpinv_get_option('invoice_subscription_page'))); |
|
| 1092 | + $url = add_query_arg('subscription', $this->get_id(), $url); |
|
| 1093 | 1093 | |
| 1094 | - return apply_filters( 'getpaid_get_subscription_view_url', $url, $this ); |
|
| 1094 | + return apply_filters('getpaid_get_subscription_view_url', $url, $this); |
|
| 1095 | 1095 | } |
| 1096 | 1096 | |
| 1097 | 1097 | /** |
@@ -1104,7 +1104,7 @@ discard block |
||
| 1104 | 1104 | * @return bool |
| 1105 | 1105 | */ |
| 1106 | 1106 | public function can_renew() { |
| 1107 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
| 1107 | + return apply_filters('wpinv_subscription_can_renew', true, $this); |
|
| 1108 | 1108 | } |
| 1109 | 1109 | |
| 1110 | 1110 | /** |
@@ -1114,8 +1114,8 @@ discard block |
||
| 1114 | 1114 | * @return string |
| 1115 | 1115 | */ |
| 1116 | 1116 | public function get_renew_url() { |
| 1117 | - $url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'getpaid-nonce' ); |
|
| 1118 | - return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
| 1117 | + $url = wp_nonce_url(add_query_arg(array('getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id)), 'getpaid-nonce'); |
|
| 1118 | + return apply_filters('wpinv_subscription_renew_url', $url, $this); |
|
| 1119 | 1119 | } |
| 1120 | 1120 | |
| 1121 | 1121 | /** |
@@ -1125,7 +1125,7 @@ discard block |
||
| 1125 | 1125 | * @return bool |
| 1126 | 1126 | */ |
| 1127 | 1127 | public function can_update() { |
| 1128 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
| 1128 | + return apply_filters('wpinv_subscription_can_update', false, $this); |
|
| 1129 | 1129 | } |
| 1130 | 1130 | |
| 1131 | 1131 | /** |
@@ -1135,8 +1135,8 @@ discard block |
||
| 1135 | 1135 | * @return string |
| 1136 | 1136 | */ |
| 1137 | 1137 | public function get_update_url() { |
| 1138 | - $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) ); |
|
| 1139 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
| 1138 | + $url = add_query_arg(array('action' => 'update', 'subscription_id' => $this->get_id())); |
|
| 1139 | + return apply_filters('wpinv_subscription_update_url', $url, $this); |
|
| 1140 | 1140 | } |
| 1141 | 1141 | |
| 1142 | 1142 | /** |
@@ -1146,7 +1146,7 @@ discard block |
||
| 1146 | 1146 | * @return string |
| 1147 | 1147 | */ |
| 1148 | 1148 | public function get_status_label() { |
| 1149 | - return getpaid_get_subscription_status_label( $this->get_status() ); |
|
| 1149 | + return getpaid_get_subscription_status_label($this->get_status()); |
|
| 1150 | 1150 | } |
| 1151 | 1151 | |
| 1152 | 1152 | /** |
@@ -1157,7 +1157,7 @@ discard block |
||
| 1157 | 1157 | */ |
| 1158 | 1158 | public function get_status_class() { |
| 1159 | 1159 | $statuses = getpaid_get_subscription_status_classes(); |
| 1160 | - return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark'; |
|
| 1160 | + return isset($statuses[$this->get_status()]) ? $statuses[$this->get_status()] : 'badge-dark'; |
|
| 1161 | 1161 | } |
| 1162 | 1162 | |
| 1163 | 1163 | /** |
@@ -1168,9 +1168,9 @@ discard block |
||
| 1168 | 1168 | */ |
| 1169 | 1169 | public function get_status_label_html() { |
| 1170 | 1170 | |
| 1171 | - $status_label = sanitize_text_field( $this->get_status_label() ); |
|
| 1172 | - $class = esc_attr( $this->get_status_class() ); |
|
| 1173 | - $status = sanitize_html_class( $this->get_status() ); |
|
| 1171 | + $status_label = sanitize_text_field($this->get_status_label()); |
|
| 1172 | + $class = esc_attr($this->get_status_class()); |
|
| 1173 | + $status = sanitize_html_class($this->get_status()); |
|
| 1174 | 1174 | |
| 1175 | 1175 | return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
| 1176 | 1176 | } |
@@ -1182,9 +1182,9 @@ discard block |
||
| 1182 | 1182 | * @param string $txn_id The transaction ID from the merchant processor |
| 1183 | 1183 | * @return bool |
| 1184 | 1184 | */ |
| 1185 | - public function payment_exists( $txn_id = '' ) { |
|
| 1186 | - $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
| 1187 | - return ! empty( $invoice_id ); |
|
| 1185 | + public function payment_exists($txn_id = '') { |
|
| 1186 | + $invoice_id = WPInv_Invoice::get_invoice_id_by_field($txn_id, 'transaction_id'); |
|
| 1187 | + return !empty($invoice_id); |
|
| 1188 | 1188 | } |
| 1189 | 1189 | |
| 1190 | 1190 | /** |
@@ -1196,35 +1196,35 @@ discard block |
||
| 1196 | 1196 | // Reset status transition variable. |
| 1197 | 1197 | $this->status_transition = false; |
| 1198 | 1198 | |
| 1199 | - if ( $status_transition ) { |
|
| 1199 | + if ($status_transition) { |
|
| 1200 | 1200 | try { |
| 1201 | 1201 | |
| 1202 | 1202 | // Fire a hook for the status change. |
| 1203 | - do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
| 1204 | - do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
| 1203 | + do_action('wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition); |
|
| 1204 | + do_action('getpaid_subscription_' . $status_transition['to'], $this, $status_transition); |
|
| 1205 | 1205 | |
| 1206 | - if ( ! empty( $status_transition['from'] ) ) { |
|
| 1206 | + if (!empty($status_transition['from'])) { |
|
| 1207 | 1207 | |
| 1208 | 1208 | /* translators: 1: old subscription status 2: new subscription status */ |
| 1209 | - $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
| 1209 | + $transition_note = sprintf(__('Subscription status changed from %1$s to %2$s.', 'invoicing'), getpaid_get_subscription_status_label($status_transition['from']), getpaid_get_subscription_status_label($status_transition['to'])); |
|
| 1210 | 1210 | |
| 1211 | 1211 | // Note the transition occurred. |
| 1212 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1212 | + $this->get_parent_payment()->add_note($transition_note, false, false, true); |
|
| 1213 | 1213 | |
| 1214 | 1214 | // Fire another hook. |
| 1215 | - do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
| 1216 | - do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
| 1215 | + do_action('getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this); |
|
| 1216 | + do_action('getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to']); |
|
| 1217 | 1217 | |
| 1218 | 1218 | } else { |
| 1219 | 1219 | /* translators: %s: new invoice status */ |
| 1220 | - $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
| 1220 | + $transition_note = sprintf(__('Subscription status set to %s.', 'invoicing'), getpaid_get_subscription_status_label($status_transition['to'])); |
|
| 1221 | 1221 | |
| 1222 | 1222 | // Note the transition occurred. |
| 1223 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1223 | + $this->get_parent_payment()->add_note($transition_note, false, false, true); |
|
| 1224 | 1224 | |
| 1225 | 1225 | } |
| 1226 | - } catch ( Exception $e ) { |
|
| 1227 | - $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
| 1226 | + } catch (Exception $e) { |
|
| 1227 | + $this->get_parent_payment()->add_note(__('Error during subscription status transition.', 'invoicing') . ' ' . $e->getMessage()); |
|
| 1228 | 1228 | } |
| 1229 | 1229 | } |
| 1230 | 1230 | |
@@ -1250,7 +1250,7 @@ discard block |
||
| 1250 | 1250 | */ |
| 1251 | 1251 | public function activate() { |
| 1252 | 1252 | $status = 'trialling' == $this->get_status() ? 'trialling' : 'active'; |
| 1253 | - $this->set_status( $status ); |
|
| 1253 | + $this->set_status($status); |
|
| 1254 | 1254 | return $this->save(); |
| 1255 | 1255 | } |
| 1256 | 1256 | |