@@ -7,57 +7,57 @@ discard block |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | -if ( empty( $fields ) ) { |
|
12 | +if (empty($fields)) { |
|
13 | 13 | return; |
14 | 14 | } |
15 | 15 | |
16 | 16 | // A prefix for all ids (so that a form can be included in the same page multiple times). |
17 | -$uniqid = uniqid( '_' ); |
|
17 | +$uniqid = uniqid('_'); |
|
18 | 18 | |
19 | 19 | // Prepare the user's country. |
20 | -if ( ! empty( $form->invoice ) ) { |
|
20 | +if (!empty($form->invoice)) { |
|
21 | 21 | $country = $form->invoice->get_country(); |
22 | 22 | } |
23 | 23 | |
24 | -if ( empty( $country ) ) { |
|
25 | - $country = empty( $country ) ? getpaid_get_ip_country() : $country; |
|
26 | - $country = empty( $country ) ? wpinv_get_default_country() : $country; |
|
24 | +if (empty($country)) { |
|
25 | + $country = empty($country) ? getpaid_get_ip_country() : $country; |
|
26 | + $country = empty($country) ? wpinv_get_default_country() : $country; |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | // A prefix for all ids (so that a form can be included in the same page multiple times). |
30 | -$uniqid = uniqid( '_' ); |
|
30 | +$uniqid = uniqid('_'); |
|
31 | 31 | |
32 | -$address_type = empty( $address_type ) ? 'billing' : $address_type; |
|
32 | +$address_type = empty($address_type) ? 'billing' : $address_type; |
|
33 | 33 | |
34 | 34 | ?> |
35 | 35 | |
36 | -<?php if ( 'both' === $address_type ) : ?> |
|
36 | +<?php if ('both' === $address_type) : ?> |
|
37 | 37 | |
38 | 38 | <!-- Start Billing/Shipping Address Title --> |
39 | 39 | <h4 class="mb-3 getpaid-shipping-billing-address-title"> |
40 | - <?php esc_html_e( 'Billing / Shipping Address', 'invoicing' ); ?> |
|
40 | + <?php esc_html_e('Billing / Shipping Address', 'invoicing'); ?> |
|
41 | 41 | </h4> |
42 | 42 | <!-- End Billing Address Title --> |
43 | 43 | |
44 | 44 | <!-- Start Billing Address Title --> |
45 | 45 | <h4 class="mb-3 getpaid-billing-address-title"> |
46 | - <?php esc_html_e( 'Billing Address', 'invoicing' ); ?> |
|
46 | + <?php esc_html_e('Billing Address', 'invoicing'); ?> |
|
47 | 47 | </h4> |
48 | 48 | <!-- End Billing Address Title --> |
49 | 49 | |
50 | 50 | <?php endif; ?> |
51 | 51 | |
52 | 52 | |
53 | -<?php if ( 'both' === $address_type || 'billing' === $address_type ) : ?> |
|
53 | +<?php if ('both' === $address_type || 'billing' === $address_type) : ?> |
|
54 | 54 | |
55 | 55 | <!-- Start Billing Address --> |
56 | 56 | <div class="getpaid-billing-address-wrapper"> |
57 | 57 | <?php |
58 | 58 | $field_type = 'billing'; |
59 | - include plugin_dir_path( __FILE__ ) . 'address-fields.php'; |
|
60 | - do_action( 'getpaid_after_payment_form_billing_fields', $form ); |
|
59 | + include plugin_dir_path(__FILE__) . 'address-fields.php'; |
|
60 | + do_action('getpaid_after_payment_form_billing_fields', $form); |
|
61 | 61 | ?> |
62 | 62 | </div> |
63 | 63 | <!-- End Billing Address --> |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | <?php endif; ?> |
66 | 66 | |
67 | 67 | |
68 | -<?php if ( 'both' === $address_type ) : ?> |
|
68 | +<?php if ('both' === $address_type) : ?> |
|
69 | 69 | |
70 | 70 | |
71 | 71 | <?php |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | 'name' => 'same-shipping-address', |
77 | 77 | 'id' => "shipping-toggle$uniqid", |
78 | 78 | 'required' => false, |
79 | - 'label' => empty( $shipping_address_toggle ) ? esc_html__( 'Same billing & shipping address.', 'invoicing' ) : wp_kses_post( $shipping_address_toggle ), |
|
79 | + 'label' => empty($shipping_address_toggle) ? esc_html__('Same billing & shipping address.', 'invoicing') : wp_kses_post($shipping_address_toggle), |
|
80 | 80 | 'value' => 1, |
81 | 81 | 'checked' => true, |
82 | 82 | 'class' => 'w-auto', |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | |
90 | 90 | <!-- Start Shipping Address Title --> |
91 | 91 | <h4 class="mb-3 getpaid-shipping-address-title"> |
92 | - <?php esc_html_e( 'Shipping Address', 'invoicing' ); ?> |
|
92 | + <?php esc_html_e('Shipping Address', 'invoicing'); ?> |
|
93 | 93 | </h4> |
94 | 94 | <!-- End Shipping Address Title --> |
95 | 95 | |
@@ -98,14 +98,14 @@ discard block |
||
98 | 98 | |
99 | 99 | |
100 | 100 | |
101 | -<?php if ( 'both' === $address_type || 'shipping' === $address_type ) : ?> |
|
101 | +<?php if ('both' === $address_type || 'shipping' === $address_type) : ?> |
|
102 | 102 | |
103 | 103 | <!-- Start Shipping Address --> |
104 | 104 | <div class="getpaid-shipping-address-wrapper"> |
105 | 105 | <?php |
106 | 106 | $field_type = 'shipping'; |
107 | - include plugin_dir_path( __FILE__ ) . 'address-fields.php'; |
|
108 | - do_action( 'getpaid_after_payment_form_shipping_fields', $form ); |
|
107 | + include plugin_dir_path(__FILE__) . 'address-fields.php'; |
|
108 | + do_action('getpaid_after_payment_form_shipping_fields', $form); |
|
109 | 109 | ?> |
110 | 110 | </div> |
111 | 111 | <!-- End Shipping Address --> |
@@ -7,37 +7,37 @@ discard block |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | $value = $query_value; |
13 | 13 | $class = ''; |
14 | 14 | |
15 | -if ( ! empty( $form->invoice ) ) { |
|
16 | - $value = sanitize_email( $form->invoice->get_email() ); |
|
17 | -} elseif ( is_user_logged_in() ) { |
|
15 | +if (!empty($form->invoice)) { |
|
16 | + $value = sanitize_email($form->invoice->get_email()); |
|
17 | +} elseif (is_user_logged_in()) { |
|
18 | 18 | $user = wp_get_current_user(); |
19 | - $value = sanitize_email( $user->user_email ); |
|
19 | + $value = sanitize_email($user->user_email); |
|
20 | 20 | } |
21 | 21 | |
22 | -if ( ! empty( $value ) && ! empty( $hide_billing_email ) ) { |
|
22 | +if (!empty($value) && !empty($hide_billing_email)) { |
|
23 | 23 | $class = 'd-none'; |
24 | 24 | } |
25 | 25 | |
26 | -do_action( 'getpaid_before_payment_form_billing_email', $form ); |
|
26 | +do_action('getpaid_before_payment_form_billing_email', $form); |
|
27 | 27 | |
28 | -echo "<span class='" . esc_attr( $class ) . "'>"; |
|
28 | +echo "<span class='" . esc_attr($class) . "'>"; |
|
29 | 29 | |
30 | 30 | aui()->input( |
31 | 31 | array( |
32 | 32 | 'name' => 'billing_email', |
33 | - 'id' => esc_attr( $element_id ), |
|
34 | - 'placeholder' => empty( $placeholder ) ? '' : esc_attr( $placeholder ), |
|
35 | - 'required' => ! empty( $required ), |
|
36 | - 'label' => empty( $label ) ? '' : wp_kses_post( $label ) . '<span class="text-danger"> *</span>', |
|
33 | + 'id' => esc_attr($element_id), |
|
34 | + 'placeholder' => empty($placeholder) ? '' : esc_attr($placeholder), |
|
35 | + 'required' => !empty($required), |
|
36 | + 'label' => empty($label) ? '' : wp_kses_post($label) . '<span class="text-danger"> *</span>', |
|
37 | 37 | 'label_type' => 'vertical', |
38 | - 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
38 | + 'help_text' => empty($description) ? '' : wp_kses_post($description), |
|
39 | 39 | 'type' => 'email', |
40 | - 'value' => apply_filters ( 'getpaid_payment_form_billing_email_value', $value ), |
|
40 | + 'value' => apply_filters('getpaid_payment_form_billing_email_value', $value), |
|
41 | 41 | 'class' => 'wpinv_billing_email getpaid-refresh-on-change', |
42 | 42 | 'extra_attributes' => array( |
43 | 43 | 'autocomplete' => 'billing email', |
@@ -48,4 +48,4 @@ discard block |
||
48 | 48 | |
49 | 49 | echo '</span>'; |
50 | 50 | |
51 | -do_action( 'getpaid_after_payment_form_billing_email', $form ); |
|
51 | +do_action('getpaid_after_payment_form_billing_email', $form); |
@@ -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 | * Returns an array of discount type. |
@@ -17,8 +17,8 @@ discard block |
||
17 | 17 | return apply_filters( |
18 | 18 | 'wpinv_discount_types', |
19 | 19 | array( |
20 | - 'percent' => __( 'Percentage', 'invoicing' ), |
|
21 | - 'flat' => __( 'Flat Amount', 'invoicing' ), |
|
20 | + 'percent' => __('Percentage', 'invoicing'), |
|
21 | + 'flat' => __('Flat Amount', 'invoicing'), |
|
22 | 22 | ) |
23 | 23 | ); |
24 | 24 | } |
@@ -28,46 +28,46 @@ discard block |
||
28 | 28 | * |
29 | 29 | * @return string |
30 | 30 | */ |
31 | -function wpinv_get_discount_type_name( $type = '' ) { |
|
31 | +function wpinv_get_discount_type_name($type = '') { |
|
32 | 32 | $types = wpinv_get_discount_types(); |
33 | - return isset( $types[ $type ] ) ? $types[ $type ] : $type; |
|
33 | + return isset($types[$type]) ? $types[$type] : $type; |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
37 | 37 | * Deletes a discount via the admin page. |
38 | 38 | * |
39 | 39 | */ |
40 | -function wpinv_delete_discount( $data ) { |
|
40 | +function wpinv_delete_discount($data) { |
|
41 | 41 | |
42 | - $discount = new WPInv_Discount( absint( $data['discount'] ) ); |
|
43 | - $discount->delete( true ); |
|
42 | + $discount = new WPInv_Discount(absint($data['discount'])); |
|
43 | + $discount->delete(true); |
|
44 | 44 | |
45 | 45 | } |
46 | -add_action( 'getpaid_authenticated_admin_action_delete_discount', 'wpinv_delete_discount' ); |
|
46 | +add_action('getpaid_authenticated_admin_action_delete_discount', 'wpinv_delete_discount'); |
|
47 | 47 | |
48 | 48 | /** |
49 | 49 | * Deactivates a discount via the admin page. |
50 | 50 | */ |
51 | -function wpinv_activate_discount( $data ) { |
|
51 | +function wpinv_activate_discount($data) { |
|
52 | 52 | |
53 | - $discount = new WPInv_Discount( absint( $data['discount'] ) ); |
|
54 | - $discount->set_status( 'publish' ); |
|
53 | + $discount = new WPInv_Discount(absint($data['discount'])); |
|
54 | + $discount->set_status('publish'); |
|
55 | 55 | $discount->save(); |
56 | 56 | |
57 | 57 | } |
58 | -add_action( 'getpaid_authenticated_admin_action_activate_discount', 'wpinv_activate_discount' ); |
|
58 | +add_action('getpaid_authenticated_admin_action_activate_discount', 'wpinv_activate_discount'); |
|
59 | 59 | |
60 | 60 | /** |
61 | 61 | * Activates a discount via the admin page. |
62 | 62 | */ |
63 | -function wpinv_deactivate_discount( $data ) { |
|
63 | +function wpinv_deactivate_discount($data) { |
|
64 | 64 | |
65 | - $discount = new WPInv_Discount( absint( $data['discount'] ) ); |
|
66 | - $discount->set_status( 'pending' ); |
|
65 | + $discount = new WPInv_Discount(absint($data['discount'])); |
|
66 | + $discount->set_status('pending'); |
|
67 | 67 | $discount->save(); |
68 | 68 | |
69 | 69 | } |
70 | -add_action( 'getpaid_authenticated_admin_action_deactivate_discount', 'wpinv_deactivate_discount' ); |
|
70 | +add_action('getpaid_authenticated_admin_action_deactivate_discount', 'wpinv_deactivate_discount'); |
|
71 | 71 | |
72 | 72 | /** |
73 | 73 | * Fetches a discount object. |
@@ -76,8 +76,8 @@ discard block |
||
76 | 76 | * @since 1.0.15 |
77 | 77 | * @return WPInv_Discount |
78 | 78 | */ |
79 | -function wpinv_get_discount( $discount ) { |
|
80 | - return new WPInv_Discount( $discount ); |
|
79 | +function wpinv_get_discount($discount) { |
|
80 | + return new WPInv_Discount($discount); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -87,8 +87,8 @@ discard block |
||
87 | 87 | * @since 1.0.15 |
88 | 88 | * @return WPInv_Discount |
89 | 89 | */ |
90 | -function wpinv_get_discount_obj( $discount = 0 ) { |
|
91 | - return new WPInv_Discount( $discount ); |
|
90 | +function wpinv_get_discount_obj($discount = 0) { |
|
91 | + return new WPInv_Discount($discount); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
@@ -98,10 +98,10 @@ discard block |
||
98 | 98 | * @param string|int $value The field value |
99 | 99 | * @return bool|WPInv_Discount |
100 | 100 | */ |
101 | -function wpinv_get_discount_by( $deprecated = null, $value = '' ) { |
|
102 | - $discount = new WPInv_Discount( $value ); |
|
101 | +function wpinv_get_discount_by($deprecated = null, $value = '') { |
|
102 | + $discount = new WPInv_Discount($value); |
|
103 | 103 | |
104 | - if ( $discount->get_id() != 0 ) { |
|
104 | + if ($discount->get_id() != 0) { |
|
105 | 105 | return $discount; |
106 | 106 | } |
107 | 107 | |
@@ -116,9 +116,9 @@ discard block |
||
116 | 116 | function wpinv_get_discount_statuses() { |
117 | 117 | |
118 | 118 | return array( |
119 | - 'expired' => __( 'Expired', 'invoicing' ), |
|
120 | - 'publish' => __( 'Active', 'invoicing' ), |
|
121 | - 'inactive' => __( 'Inactive', 'invoicing' ), |
|
119 | + 'expired' => __('Expired', 'invoicing'), |
|
120 | + 'publish' => __('Active', 'invoicing'), |
|
121 | + 'inactive' => __('Inactive', 'invoicing'), |
|
122 | 122 | ); |
123 | 123 | |
124 | 124 | } |
@@ -126,9 +126,9 @@ discard block |
||
126 | 126 | /** |
127 | 127 | * Retrieves an invoice status label. |
128 | 128 | */ |
129 | -function wpinv_discount_status( $status ) { |
|
129 | +function wpinv_discount_status($status) { |
|
130 | 130 | $statuses = wpinv_get_discount_statuses(); |
131 | - return isset( $statuses[ $status ] ) ? $statuses[ $status ] : __( 'Inactive', 'invoicing' ); |
|
131 | + return isset($statuses[$status]) ? $statuses[$status] : __('Inactive', 'invoicing'); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
@@ -138,12 +138,12 @@ discard block |
||
138 | 138 | * @param int|array|string|WPInv_Discount $code discount data, object, ID or code. |
139 | 139 | * @return bool |
140 | 140 | */ |
141 | -function wpinv_discount_is_recurring( $discount = 0, $code = 0 ) { |
|
141 | +function wpinv_discount_is_recurring($discount = 0, $code = 0) { |
|
142 | 142 | |
143 | - if ( ! empty( $discount ) ) { |
|
144 | - $discount = wpinv_get_discount_obj( $discount ); |
|
143 | + if (!empty($discount)) { |
|
144 | + $discount = wpinv_get_discount_obj($discount); |
|
145 | 145 | } else { |
146 | - $discount = wpinv_get_discount_obj( $code ); |
|
146 | + $discount = wpinv_get_discount_obj($code); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | return $discount->get_is_recurring(); |
@@ -158,35 +158,35 @@ discard block |
||
158 | 158 | * @param WPInv_Discount $discount |
159 | 159 | * @return array |
160 | 160 | */ |
161 | -function getpaid_calculate_invoice_discount( $invoice, $discount ) { |
|
161 | +function getpaid_calculate_invoice_discount($invoice, $discount) { |
|
162 | 162 | |
163 | 163 | $initial_discount = 0; |
164 | 164 | $recurring_discount = 0; |
165 | 165 | |
166 | - foreach ( $invoice->get_items() as $item ) { |
|
166 | + foreach ($invoice->get_items() as $item) { |
|
167 | 167 | |
168 | 168 | // Abort if it is not valid for this item. |
169 | - if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) { |
|
169 | + if (!$discount->is_valid_for_items(array($item->get_id()))) { |
|
170 | 170 | continue; |
171 | 171 | } |
172 | 172 | |
173 | 173 | // Calculate the initial amount... |
174 | - $item_discount = $discount->get_discounted_amount( $item->get_sub_total() ); |
|
174 | + $item_discount = $discount->get_discounted_amount($item->get_sub_total()); |
|
175 | 175 | $recurring_item_discount = 0; |
176 | 176 | |
177 | 177 | // ... and maybe the recurring amount. |
178 | - if ( $item->is_recurring() && $discount->is_recurring() ) { |
|
179 | - $recurring_item_discount = $discount->get_discounted_amount( $item->get_recurring_sub_total() ); |
|
178 | + if ($item->is_recurring() && $discount->is_recurring()) { |
|
179 | + $recurring_item_discount = $discount->get_discounted_amount($item->get_recurring_sub_total()); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | // Discount should not exceed discounted amount. |
183 | - if ( ! $discount->is_type( 'percent' ) ) { |
|
183 | + if (!$discount->is_type('percent')) { |
|
184 | 184 | |
185 | - if ( ( $initial_discount + $item_discount ) > $discount->get_amount() ) { |
|
185 | + if (($initial_discount + $item_discount) > $discount->get_amount()) { |
|
186 | 186 | $item_discount = $discount->get_amount() - $initial_discount; |
187 | 187 | } |
188 | 188 | |
189 | - if ( ( $recurring_discount + $recurring_item_discount ) > $discount->get_amount() ) { |
|
189 | + if (($recurring_discount + $recurring_item_discount) > $discount->get_amount()) { |
|
190 | 190 | $recurring_item_discount = $discount->get_amount() - $recurring_discount; |
191 | 191 | } |
192 | 192 | } |
@@ -218,10 +218,10 @@ discard block |
||
218 | 218 | array( |
219 | 219 | 'post_type' => 'wpi_discount', |
220 | 220 | 'numberposts' => 1, |
221 | - 'fields' => array( 'ids' ), |
|
221 | + 'fields' => array('ids'), |
|
222 | 222 | ) |
223 | 223 | ); |
224 | 224 | |
225 | - return ! empty( $discounts ); |
|
225 | + return !empty($discounts); |
|
226 | 226 | |
227 | 227 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -72,28 +72,28 @@ discard block |
||
72 | 72 | * |
73 | 73 | * @param int|object|GetPaid_Payment_Form|WP_Post $form Form to read. |
74 | 74 | */ |
75 | - public function __construct( $form = 0 ) { |
|
76 | - parent::__construct( $form ); |
|
75 | + public function __construct($form = 0) { |
|
76 | + parent::__construct($form); |
|
77 | 77 | |
78 | - if ( is_numeric( $form ) && $form > 0 ) { |
|
79 | - $this->set_id( $form ); |
|
80 | - } elseif ( $form instanceof self ) { |
|
78 | + if (is_numeric($form) && $form > 0) { |
|
79 | + $this->set_id($form); |
|
80 | + } elseif ($form instanceof self) { |
|
81 | 81 | |
82 | - $this->set_id( $form->get_id() ); |
|
82 | + $this->set_id($form->get_id()); |
|
83 | 83 | $this->invoice = $form->invoice; |
84 | 84 | |
85 | - } elseif ( ! empty( $form->ID ) ) { |
|
86 | - $this->set_id( $form->ID ); |
|
85 | + } elseif (!empty($form->ID)) { |
|
86 | + $this->set_id($form->ID); |
|
87 | 87 | } else { |
88 | - $this->set_object_read( true ); |
|
88 | + $this->set_object_read(true); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | // Load the datastore. |
92 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
92 | + $this->data_store = GetPaid_Data_Store::load($this->data_store_name); |
|
93 | 93 | |
94 | - if ( $this->get_id() > 0 ) { |
|
95 | - $this->post = get_post( $this->get_id() ); |
|
96 | - $this->data_store->read( $this ); |
|
94 | + if ($this->get_id() > 0) { |
|
95 | + $this->post = get_post($this->get_id()); |
|
96 | + $this->data_store->read($this); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | } |
@@ -120,8 +120,8 @@ discard block |
||
120 | 120 | * @param string $context View or edit context. |
121 | 121 | * @return string |
122 | 122 | */ |
123 | - public function get_version( $context = 'view' ) { |
|
124 | - return $this->get_prop( 'version', $context ); |
|
123 | + public function get_version($context = 'view') { |
|
124 | + return $this->get_prop('version', $context); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -131,8 +131,8 @@ discard block |
||
131 | 131 | * @param string $context View or edit context. |
132 | 132 | * @return string |
133 | 133 | */ |
134 | - public function get_date_created( $context = 'view' ) { |
|
135 | - return $this->get_prop( 'date_created', $context ); |
|
134 | + public function get_date_created($context = 'view') { |
|
135 | + return $this->get_prop('date_created', $context); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
@@ -142,11 +142,11 @@ discard block |
||
142 | 142 | * @param string $context View or edit context. |
143 | 143 | * @return string |
144 | 144 | */ |
145 | - public function get_date_created_gmt( $context = 'view' ) { |
|
146 | - $date = $this->get_date_created( $context ); |
|
145 | + public function get_date_created_gmt($context = 'view') { |
|
146 | + $date = $this->get_date_created($context); |
|
147 | 147 | |
148 | - if ( $date ) { |
|
149 | - $date = get_gmt_from_date( $date ); |
|
148 | + if ($date) { |
|
149 | + $date = get_gmt_from_date($date); |
|
150 | 150 | } |
151 | 151 | return $date; |
152 | 152 | } |
@@ -158,8 +158,8 @@ discard block |
||
158 | 158 | * @param string $context View or edit context. |
159 | 159 | * @return string |
160 | 160 | */ |
161 | - public function get_date_modified( $context = 'view' ) { |
|
162 | - return $this->get_prop( 'date_modified', $context ); |
|
161 | + public function get_date_modified($context = 'view') { |
|
162 | + return $this->get_prop('date_modified', $context); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -169,11 +169,11 @@ discard block |
||
169 | 169 | * @param string $context View or edit context. |
170 | 170 | * @return string |
171 | 171 | */ |
172 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
173 | - $date = $this->get_date_modified( $context ); |
|
172 | + public function get_date_modified_gmt($context = 'view') { |
|
173 | + $date = $this->get_date_modified($context); |
|
174 | 174 | |
175 | - if ( $date ) { |
|
176 | - $date = get_gmt_from_date( $date ); |
|
175 | + if ($date) { |
|
176 | + $date = get_gmt_from_date($date); |
|
177 | 177 | } |
178 | 178 | return $date; |
179 | 179 | } |
@@ -185,8 +185,8 @@ discard block |
||
185 | 185 | * @param string $context View or edit context. |
186 | 186 | * @return string |
187 | 187 | */ |
188 | - public function get_name( $context = 'view' ) { |
|
189 | - return $this->get_prop( 'name', $context ); |
|
188 | + public function get_name($context = 'view') { |
|
189 | + return $this->get_prop('name', $context); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
@@ -196,8 +196,8 @@ discard block |
||
196 | 196 | * @param string $context View or edit context. |
197 | 197 | * @return string |
198 | 198 | */ |
199 | - public function get_title( $context = 'view' ) { |
|
200 | - return $this->get_name( $context ); |
|
199 | + public function get_title($context = 'view') { |
|
200 | + return $this->get_name($context); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | /** |
@@ -207,8 +207,8 @@ discard block |
||
207 | 207 | * @param string $context View or edit context. |
208 | 208 | * @return int |
209 | 209 | */ |
210 | - public function get_author( $context = 'view' ) { |
|
211 | - return (int) $this->get_prop( 'author', $context ); |
|
210 | + public function get_author($context = 'view') { |
|
211 | + return (int) $this->get_prop('author', $context); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
@@ -218,21 +218,21 @@ discard block |
||
218 | 218 | * @param string $context View or edit context. |
219 | 219 | * @return array |
220 | 220 | */ |
221 | - public function get_elements( $context = 'view' ) { |
|
222 | - $elements = $this->get_prop( 'elements', $context ); |
|
221 | + public function get_elements($context = 'view') { |
|
222 | + $elements = $this->get_prop('elements', $context); |
|
223 | 223 | |
224 | - if ( empty( $elements ) || ! is_array( $elements ) ) { |
|
225 | - return wpinv_get_data( 'sample-payment-form' ); |
|
224 | + if (empty($elements) || !is_array($elements)) { |
|
225 | + return wpinv_get_data('sample-payment-form'); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | // Ensure that all required elements exist. |
229 | 229 | $_elements = array(); |
230 | - foreach ( $elements as $element ) { |
|
230 | + foreach ($elements as $element) { |
|
231 | 231 | |
232 | - if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) { |
|
232 | + if ($element['type'] == 'pay_button' && !$this->has_element_type('gateway_select')) { |
|
233 | 233 | |
234 | 234 | $_elements[] = array( |
235 | - 'text' => __( 'Select Payment Method', 'invoicing' ), |
|
235 | + 'text' => __('Select Payment Method', 'invoicing'), |
|
236 | 236 | 'id' => 'gtscicd', |
237 | 237 | 'name' => 'gtscicd', |
238 | 238 | 'type' => 'gateway_select', |
@@ -257,22 +257,22 @@ discard block |
||
257 | 257 | * @param string $return objects or arrays. |
258 | 258 | * @return GetPaid_Form_Item[] |
259 | 259 | */ |
260 | - public function get_items( $context = 'view', $return = 'objects' ) { |
|
261 | - $items = $this->get_prop( 'items', $context ); |
|
260 | + public function get_items($context = 'view', $return = 'objects') { |
|
261 | + $items = $this->get_prop('items', $context); |
|
262 | 262 | |
263 | - if ( empty( $items ) || ! is_array( $items ) ) { |
|
264 | - $items = wpinv_get_data( 'sample-payment-form-items' ); |
|
263 | + if (empty($items) || !is_array($items)) { |
|
264 | + $items = wpinv_get_data('sample-payment-form-items'); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | // Convert the items. |
268 | 268 | $prepared = array(); |
269 | 269 | |
270 | - foreach ( $items as $key => $value ) { |
|
270 | + foreach ($items as $key => $value) { |
|
271 | 271 | |
272 | 272 | // Form items. |
273 | - if ( $value instanceof GetPaid_Form_Item ) { |
|
273 | + if ($value instanceof GetPaid_Form_Item) { |
|
274 | 274 | |
275 | - if ( $value->can_purchase() ) { |
|
275 | + if ($value->can_purchase()) { |
|
276 | 276 | $prepared[] = $value; |
277 | 277 | } |
278 | 278 | |
@@ -281,16 +281,16 @@ discard block |
||
281 | 281 | } |
282 | 282 | |
283 | 283 | // $item_id => $quantity (buy buttons) |
284 | - if ( is_numeric( $key ) && is_numeric( $value ) ) { |
|
285 | - $item = new GetPaid_Form_Item( $key ); |
|
284 | + if (is_numeric($key) && is_numeric($value)) { |
|
285 | + $item = new GetPaid_Form_Item($key); |
|
286 | 286 | |
287 | - if ( $item->can_purchase() ) { |
|
287 | + if ($item->can_purchase()) { |
|
288 | 288 | |
289 | 289 | $value = (float) $value; |
290 | - $item->set_quantity( $value ); |
|
291 | - if ( 0 == $value ) { |
|
292 | - $item->set_quantity( 1 ); |
|
293 | - $item->set_allow_quantities( true ); |
|
290 | + $item->set_quantity($value); |
|
291 | + if (0 == $value) { |
|
292 | + $item->set_quantity(1); |
|
293 | + $item->set_allow_quantities(true); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | $prepared[] = $item; |
@@ -300,33 +300,33 @@ discard block |
||
300 | 300 | } |
301 | 301 | |
302 | 302 | // Items saved via payment forms editor. |
303 | - if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
303 | + if (is_array($value) && isset($value['id'])) { |
|
304 | 304 | |
305 | - $item = new GetPaid_Form_Item( $value['id'] ); |
|
305 | + $item = new GetPaid_Form_Item($value['id']); |
|
306 | 306 | |
307 | - if ( ! $item->can_purchase() ) { |
|
307 | + if (!$item->can_purchase()) { |
|
308 | 308 | continue; |
309 | 309 | } |
310 | 310 | |
311 | 311 | // Sub-total (Cart items). |
312 | - if ( isset( $value['subtotal'] ) ) { |
|
313 | - $item->set_price( $value['subtotal'] ); |
|
312 | + if (isset($value['subtotal'])) { |
|
313 | + $item->set_price($value['subtotal']); |
|
314 | 314 | } |
315 | 315 | |
316 | - if ( isset( $value['quantity'] ) ) { |
|
317 | - $item->set_quantity( $value['quantity'] ); |
|
316 | + if (isset($value['quantity'])) { |
|
317 | + $item->set_quantity($value['quantity']); |
|
318 | 318 | } |
319 | 319 | |
320 | - if ( isset( $value['allow_quantities'] ) ) { |
|
321 | - $item->set_allow_quantities( $value['allow_quantities'] ); |
|
320 | + if (isset($value['allow_quantities'])) { |
|
321 | + $item->set_allow_quantities($value['allow_quantities']); |
|
322 | 322 | } |
323 | 323 | |
324 | - if ( isset( $value['required'] ) ) { |
|
325 | - $item->set_is_required( $value['required'] ); |
|
324 | + if (isset($value['required'])) { |
|
325 | + $item->set_is_required($value['required']); |
|
326 | 326 | } |
327 | 327 | |
328 | - if ( isset( $value['description'] ) ) { |
|
329 | - $item->set_custom_description( $value['description'] ); |
|
328 | + if (isset($value['description'])) { |
|
329 | + $item->set_custom_description($value['description']); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | $prepared[] = $item; |
@@ -335,14 +335,14 @@ discard block |
||
335 | 335 | } |
336 | 336 | |
337 | 337 | // $item_id => array( 'price' => 10 ) (item variations) |
338 | - if ( is_numeric( $key ) && is_array( $value ) ) { |
|
339 | - $item = new GetPaid_Form_Item( $key ); |
|
338 | + if (is_numeric($key) && is_array($value)) { |
|
339 | + $item = new GetPaid_Form_Item($key); |
|
340 | 340 | |
341 | - if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) { |
|
342 | - $item->set_price( $value['price'] ); |
|
341 | + if (isset($value['price']) && $item->user_can_set_their_price()) { |
|
342 | + $item->set_price($value['price']); |
|
343 | 343 | } |
344 | 344 | |
345 | - if ( $item->can_purchase() ) { |
|
345 | + if ($item->can_purchase()) { |
|
346 | 346 | $prepared[] = $item; |
347 | 347 | } |
348 | 348 | |
@@ -350,12 +350,12 @@ discard block |
||
350 | 350 | } |
351 | 351 | } |
352 | 352 | |
353 | - if ( 'objects' == $return && 'view' == $context ) { |
|
353 | + if ('objects' == $return && 'view' == $context) { |
|
354 | 354 | return $prepared; |
355 | 355 | } |
356 | 356 | |
357 | 357 | $items = array(); |
358 | - foreach ( $prepared as $item ) { |
|
358 | + foreach ($prepared as $item) { |
|
359 | 359 | $items[] = $item->prepare_data_for_use(); |
360 | 360 | } |
361 | 361 | |
@@ -369,14 +369,14 @@ discard block |
||
369 | 369 | * @param int $item_id The item id to return. |
370 | 370 | * @return GetPaid_Form_Item|bool |
371 | 371 | */ |
372 | - public function get_item( $item_id ) { |
|
372 | + public function get_item($item_id) { |
|
373 | 373 | |
374 | - if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
374 | + if (empty($item_id) || !is_numeric($item_id)) { |
|
375 | 375 | return false; |
376 | 376 | } |
377 | 377 | |
378 | - foreach ( $this->get_items() as $item ) { |
|
379 | - if ( $item->get_id() == (int) $item_id ) { |
|
378 | + foreach ($this->get_items() as $item) { |
|
379 | + if ($item->get_id() == (int) $item_id) { |
|
380 | 380 | return $item; |
381 | 381 | } |
382 | 382 | } |
@@ -392,15 +392,15 @@ discard block |
||
392 | 392 | * @param string $element_type The element type to return. |
393 | 393 | * @return array|bool |
394 | 394 | */ |
395 | - public function get_element_type( $element_type ) { |
|
395 | + public function get_element_type($element_type) { |
|
396 | 396 | |
397 | - if ( empty( $element_type ) || ! is_scalar( $element_type ) ) { |
|
397 | + if (empty($element_type) || !is_scalar($element_type)) { |
|
398 | 398 | return false; |
399 | 399 | } |
400 | 400 | |
401 | - foreach ( $this->get_prop( 'elements' ) as $element ) { |
|
401 | + foreach ($this->get_prop('elements') as $element) { |
|
402 | 402 | |
403 | - if ( $element['type'] === $element_type ) { |
|
403 | + if ($element['type'] === $element_type) { |
|
404 | 404 | return $element; |
405 | 405 | } |
406 | 406 | } |
@@ -416,8 +416,8 @@ discard block |
||
416 | 416 | * @param string $context View or edit context. |
417 | 417 | * @return float |
418 | 418 | */ |
419 | - public function get_earned( $context = 'view' ) { |
|
420 | - return $this->get_prop( 'earned', $context ); |
|
419 | + public function get_earned($context = 'view') { |
|
420 | + return $this->get_prop('earned', $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 float |
429 | 429 | */ |
430 | - public function get_refunded( $context = 'view' ) { |
|
431 | - return $this->get_prop( 'refunded', $context ); |
|
430 | + public function get_refunded($context = 'view') { |
|
431 | + return $this->get_prop('refunded', $context); |
|
432 | 432 | } |
433 | 433 | |
434 | 434 | /** |
@@ -438,8 +438,8 @@ discard block |
||
438 | 438 | * @param string $context View or edit context. |
439 | 439 | * @return float |
440 | 440 | */ |
441 | - public function get_cancelled( $context = 'view' ) { |
|
442 | - return $this->get_prop( 'cancelled', $context ); |
|
441 | + public function get_cancelled($context = 'view') { |
|
442 | + return $this->get_prop('cancelled', $context); |
|
443 | 443 | } |
444 | 444 | |
445 | 445 | /** |
@@ -449,8 +449,8 @@ discard block |
||
449 | 449 | * @param string $context View or edit context. |
450 | 450 | * @return float |
451 | 451 | */ |
452 | - public function get_failed( $context = 'view' ) { |
|
453 | - return $this->get_prop( 'failed', $context ); |
|
452 | + public function get_failed($context = 'view') { |
|
453 | + return $this->get_prop('failed', $context); |
|
454 | 454 | } |
455 | 455 | |
456 | 456 | /** |
@@ -461,8 +461,8 @@ discard block |
||
461 | 461 | * @return string |
462 | 462 | */ |
463 | 463 | public function get_currency() { |
464 | - $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
465 | - return apply_filters( 'getpaid-payment-form-currency', $currency, $this ); |
|
464 | + $currency = empty($this->invoice) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
465 | + return apply_filters('getpaid-payment-form-currency', $currency, $this); |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | /* |
@@ -480,8 +480,8 @@ discard block |
||
480 | 480 | * |
481 | 481 | * @since 1.0.19 |
482 | 482 | */ |
483 | - public function set_version( $value ) { |
|
484 | - $this->set_prop( 'version', $value ); |
|
483 | + public function set_version($value) { |
|
484 | + $this->set_prop('version', $value); |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | /** |
@@ -491,11 +491,11 @@ discard block |
||
491 | 491 | * @param string $value Value to set. |
492 | 492 | * @return bool Whether or not the date was set. |
493 | 493 | */ |
494 | - public function set_date_created( $value ) { |
|
495 | - $date = strtotime( $value ); |
|
494 | + public function set_date_created($value) { |
|
495 | + $date = strtotime($value); |
|
496 | 496 | |
497 | - if ( $date ) { |
|
498 | - $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) ); |
|
497 | + if ($date) { |
|
498 | + $this->set_prop('date_created', date('Y-m-d H:i:s', $date)); |
|
499 | 499 | return true; |
500 | 500 | } |
501 | 501 | |
@@ -510,11 +510,11 @@ discard block |
||
510 | 510 | * @param string $value Value to set. |
511 | 511 | * @return bool Whether or not the date was set. |
512 | 512 | */ |
513 | - public function set_date_modified( $value ) { |
|
514 | - $date = strtotime( $value ); |
|
513 | + public function set_date_modified($value) { |
|
514 | + $date = strtotime($value); |
|
515 | 515 | |
516 | - if ( $date ) { |
|
517 | - $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) ); |
|
516 | + if ($date) { |
|
517 | + $this->set_prop('date_modified', date('Y-m-d H:i:s', $date)); |
|
518 | 518 | return true; |
519 | 519 | } |
520 | 520 | |
@@ -528,8 +528,8 @@ discard block |
||
528 | 528 | * @since 1.0.19 |
529 | 529 | * @param string $value New name. |
530 | 530 | */ |
531 | - public function set_name( $value ) { |
|
532 | - $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
531 | + public function set_name($value) { |
|
532 | + $this->set_prop('name', sanitize_text_field($value)); |
|
533 | 533 | } |
534 | 534 | |
535 | 535 | /** |
@@ -538,8 +538,8 @@ discard block |
||
538 | 538 | * @since 1.0.19 |
539 | 539 | * @param string $value New name. |
540 | 540 | */ |
541 | - public function set_title( $value ) { |
|
542 | - $this->set_name( $value ); |
|
541 | + public function set_title($value) { |
|
542 | + $this->set_name($value); |
|
543 | 543 | } |
544 | 544 | |
545 | 545 | /** |
@@ -548,8 +548,8 @@ discard block |
||
548 | 548 | * @since 1.0.19 |
549 | 549 | * @param int $value New author. |
550 | 550 | */ |
551 | - public function set_author( $value ) { |
|
552 | - $this->set_prop( 'author', (int) $value ); |
|
551 | + public function set_author($value) { |
|
552 | + $this->set_prop('author', (int) $value); |
|
553 | 553 | } |
554 | 554 | |
555 | 555 | /** |
@@ -559,9 +559,9 @@ discard block |
||
559 | 559 | * @sinve 2.3.4 Array values sanitized. |
560 | 560 | * @param array $value Form elements. |
561 | 561 | */ |
562 | - public function set_elements( $value ) { |
|
563 | - if ( is_array( $value ) ) { |
|
564 | - $this->set_prop( 'elements', wp_kses_post_deep( $value ) ); |
|
562 | + public function set_elements($value) { |
|
563 | + if (is_array($value)) { |
|
564 | + $this->set_prop('elements', wp_kses_post_deep($value)); |
|
565 | 565 | } |
566 | 566 | } |
567 | 567 | |
@@ -572,36 +572,36 @@ discard block |
||
572 | 572 | * |
573 | 573 | * @return mixed |
574 | 574 | */ |
575 | - public function sanitize_array_values( $value ) { |
|
575 | + public function sanitize_array_values($value) { |
|
576 | 576 | |
577 | 577 | // sanitize |
578 | - if ( ! empty( $value ) ) { |
|
578 | + if (!empty($value)) { |
|
579 | 579 | |
580 | - foreach ( $value as $key => $val_arr ) { |
|
580 | + foreach ($value as $key => $val_arr) { |
|
581 | 581 | |
582 | - if ( is_array( $val_arr ) ) { |
|
582 | + if (is_array($val_arr)) { |
|
583 | 583 | // check if we have sub array items. |
584 | 584 | $sub_arr = array(); |
585 | - foreach ( $val_arr as $key2 => $val2 ) { |
|
586 | - if ( is_array( $val2 ) ) { |
|
587 | - $sub_arr[ $key2 ] = $this->sanitize_array_values( $val2 ); |
|
588 | - unset( $val_arr[ $key ][ $key2 ] ); |
|
585 | + foreach ($val_arr as $key2 => $val2) { |
|
586 | + if (is_array($val2)) { |
|
587 | + $sub_arr[$key2] = $this->sanitize_array_values($val2); |
|
588 | + unset($val_arr[$key][$key2]); |
|
589 | 589 | } |
590 | 590 | } |
591 | 591 | |
592 | 592 | // we allow some html in description so we sanitize it separately. |
593 | - $help_text = ! empty( $val_arr['description'] ) ? wp_kses_post( $val_arr['description'] ) : ''; |
|
593 | + $help_text = !empty($val_arr['description']) ? wp_kses_post($val_arr['description']) : ''; |
|
594 | 594 | |
595 | 595 | // sanitize array elements |
596 | - $value[ $key ] = array_map( 'sanitize_text_field', $val_arr ); |
|
596 | + $value[$key] = array_map('sanitize_text_field', $val_arr); |
|
597 | 597 | |
598 | 598 | // add back the description if set |
599 | - if ( isset( $val_arr['description'] ) ) { |
|
600 | -$value[ $key ]['description'] = $help_text;} |
|
599 | + if (isset($val_arr['description'])) { |
|
600 | +$value[$key]['description'] = $help_text; } |
|
601 | 601 | |
602 | 602 | // add back sub array items after its been sanitized. |
603 | - if ( ! empty( $sub_arr ) ) { |
|
604 | - $value[ $key ] = array_merge( $value[ $key ], $sub_arr ); |
|
603 | + if (!empty($sub_arr)) { |
|
604 | + $value[$key] = array_merge($value[$key], $sub_arr); |
|
605 | 605 | } |
606 | 606 | } |
607 | 607 | } |
@@ -616,9 +616,9 @@ discard block |
||
616 | 616 | * @since 1.0.19 |
617 | 617 | * @param array $value Form elements. |
618 | 618 | */ |
619 | - public function set_items( $value ) { |
|
620 | - if ( is_array( $value ) ) { |
|
621 | - $this->set_prop( 'items', $value ); |
|
619 | + public function set_items($value) { |
|
620 | + if (is_array($value)) { |
|
621 | + $this->set_prop('items', $value); |
|
622 | 622 | } |
623 | 623 | } |
624 | 624 | |
@@ -628,9 +628,9 @@ discard block |
||
628 | 628 | * @since 1.0.19 |
629 | 629 | * @param float $value Amount earned. |
630 | 630 | */ |
631 | - public function set_earned( $value ) { |
|
632 | - $value = max( (float) $value, 0 ); |
|
633 | - $this->set_prop( 'earned', $value ); |
|
631 | + public function set_earned($value) { |
|
632 | + $value = max((float) $value, 0); |
|
633 | + $this->set_prop('earned', $value); |
|
634 | 634 | } |
635 | 635 | |
636 | 636 | /** |
@@ -639,9 +639,9 @@ discard block |
||
639 | 639 | * @since 1.0.19 |
640 | 640 | * @param float $value Amount refunded. |
641 | 641 | */ |
642 | - public function set_refunded( $value ) { |
|
643 | - $value = max( (float) $value, 0 ); |
|
644 | - $this->set_prop( 'refunded', $value ); |
|
642 | + public function set_refunded($value) { |
|
643 | + $value = max((float) $value, 0); |
|
644 | + $this->set_prop('refunded', $value); |
|
645 | 645 | } |
646 | 646 | |
647 | 647 | /** |
@@ -650,9 +650,9 @@ discard block |
||
650 | 650 | * @since 1.0.19 |
651 | 651 | * @param float $value Amount cancelled. |
652 | 652 | */ |
653 | - public function set_cancelled( $value ) { |
|
654 | - $value = max( (float) $value, 0 ); |
|
655 | - $this->set_prop( 'cancelled', $value ); |
|
653 | + public function set_cancelled($value) { |
|
654 | + $value = max((float) $value, 0); |
|
655 | + $this->set_prop('cancelled', $value); |
|
656 | 656 | } |
657 | 657 | |
658 | 658 | /** |
@@ -661,9 +661,9 @@ discard block |
||
661 | 661 | * @since 1.0.19 |
662 | 662 | * @param float $value Amount cancelled. |
663 | 663 | */ |
664 | - public function set_failed( $value ) { |
|
665 | - $value = max( (float) $value, 0 ); |
|
666 | - $this->set_prop( 'failed', $value ); |
|
664 | + public function set_failed($value) { |
|
665 | + $value = max((float) $value, 0); |
|
666 | + $this->set_prop('failed', $value); |
|
667 | 667 | } |
668 | 668 | |
669 | 669 | /** |
@@ -672,11 +672,11 @@ discard block |
||
672 | 672 | * @deprecated |
673 | 673 | * @return int item id |
674 | 674 | */ |
675 | - public function create( $data = array() ) { |
|
675 | + public function create($data = array()) { |
|
676 | 676 | |
677 | 677 | // Set the properties. |
678 | - if ( is_array( $data ) ) { |
|
679 | - $this->set_props( $data ); |
|
678 | + if (is_array($data)) { |
|
679 | + $this->set_props($data); |
|
680 | 680 | } |
681 | 681 | |
682 | 682 | // Save the item. |
@@ -690,8 +690,8 @@ discard block |
||
690 | 690 | * @deprecated |
691 | 691 | * @return int item id |
692 | 692 | */ |
693 | - public function update( $data = array() ) { |
|
694 | - return $this->create( $data ); |
|
693 | + public function update($data = array()) { |
|
694 | + return $this->create($data); |
|
695 | 695 | } |
696 | 696 | |
697 | 697 | /* |
@@ -711,7 +711,7 @@ discard block |
||
711 | 711 | */ |
712 | 712 | public function is_default() { |
713 | 713 | $is_default = $this->get_id() == wpinv_get_default_payment_form(); |
714 | - return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this ); |
|
714 | + return (bool) apply_filters('wpinv_is_default_payment_form', $is_default, $this->get_id(), $this); |
|
715 | 715 | } |
716 | 716 | |
717 | 717 | /** |
@@ -723,11 +723,11 @@ discard block |
||
723 | 723 | public function is_active() { |
724 | 724 | $is_active = 0 !== (int) $this->get_id(); |
725 | 725 | |
726 | - if ( $is_active && ! current_user_can( 'edit_post', $this->get_id() ) && $this->get_status() != 'publish' ) { |
|
726 | + if ($is_active && !current_user_can('edit_post', $this->get_id()) && $this->get_status() != 'publish') { |
|
727 | 727 | $is_active = false; |
728 | 728 | } |
729 | 729 | |
730 | - return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this ); |
|
730 | + return (bool) apply_filters('wpinv_is_payment_form_active', $is_active, $this); |
|
731 | 731 | } |
732 | 732 | |
733 | 733 | /** |
@@ -736,8 +736,8 @@ discard block |
||
736 | 736 | * @since 1.0.19 |
737 | 737 | * @return bool |
738 | 738 | */ |
739 | - public function has_item( $item_id ) { |
|
740 | - return false !== $this->get_item( $item_id ); |
|
739 | + public function has_item($item_id) { |
|
740 | + return false !== $this->get_item($item_id); |
|
741 | 741 | } |
742 | 742 | |
743 | 743 | /** |
@@ -746,8 +746,8 @@ discard block |
||
746 | 746 | * @since 1.0.19 |
747 | 747 | * @return bool |
748 | 748 | */ |
749 | - public function has_element_type( $element_type ) { |
|
750 | - return false !== $this->get_element_type( $element_type ); |
|
749 | + public function has_element_type($element_type) { |
|
750 | + return false !== $this->get_element_type($element_type); |
|
751 | 751 | } |
752 | 752 | |
753 | 753 | /** |
@@ -758,13 +758,13 @@ discard block |
||
758 | 758 | */ |
759 | 759 | public function is_recurring() { |
760 | 760 | |
761 | - if ( ! empty( $this->invoice ) ) { |
|
761 | + if (!empty($this->invoice)) { |
|
762 | 762 | return $this->invoice->is_recurring(); |
763 | 763 | } |
764 | 764 | |
765 | - foreach ( $this->get_items() as $item ) { |
|
765 | + foreach ($this->get_items() as $item) { |
|
766 | 766 | |
767 | - if ( $item->is_recurring() ) { |
|
767 | + if ($item->is_recurring()) { |
|
768 | 768 | return true; |
769 | 769 | } |
770 | 770 | } |
@@ -777,7 +777,7 @@ discard block |
||
777 | 777 | * |
778 | 778 | * @since 1.0.19 |
779 | 779 | */ |
780 | - public function get_html( $extra_markup = '' ) { |
|
780 | + public function get_html($extra_markup = '') { |
|
781 | 781 | |
782 | 782 | // Return the HTML. |
783 | 783 | return wpinv_get_template_html( |
@@ -795,7 +795,7 @@ discard block |
||
795 | 795 | * |
796 | 796 | * @since 1.0.19 |
797 | 797 | */ |
798 | - public function display( $extra_markup = '' ) { |
|
798 | + public function display($extra_markup = '') { |
|
799 | 799 | wpinv_get_template( |
800 | 800 | 'payment-forms/form.php', |
801 | 801 | array( |
@@ -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 | * This class handles invoice notificaiton emails. |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | $this->invoice_actions = apply_filters( |
29 | 29 | 'getpaid_notification_email_invoice_triggers', |
30 | 30 | array( |
31 | - 'getpaid_new_invoice' => array( 'new_invoice', 'user_invoice' ), |
|
31 | + 'getpaid_new_invoice' => array('new_invoice', 'user_invoice'), |
|
32 | 32 | 'getpaid_invoice_status_wpi-cancelled' => 'cancelled_invoice', |
33 | 33 | 'getpaid_invoice_status_wpi-failed' => 'failed_invoice', |
34 | 34 | 'getpaid_invoice_status_wpi-onhold' => 'onhold_invoice', |
@@ -50,11 +50,11 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public function init_hooks() { |
52 | 52 | |
53 | - add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 ); |
|
54 | - add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 ); |
|
53 | + add_filter('getpaid_get_email_merge_tags', array($this, 'invoice_merge_tags'), 10, 2); |
|
54 | + add_filter('getpaid_invoice_email_recipients', array($this, 'filter_email_recipients'), 10, 2); |
|
55 | 55 | |
56 | - foreach ( $this->invoice_actions as $hook => $email_type ) { |
|
57 | - $this->init_email_type_hook( $hook, $email_type ); |
|
56 | + foreach ($this->invoice_actions as $hook => $email_type) { |
|
57 | + $this->init_email_type_hook($hook, $email_type); |
|
58 | 58 | } |
59 | 59 | } |
60 | 60 | |
@@ -64,25 +64,25 @@ discard block |
||
64 | 64 | * @param string $hook |
65 | 65 | * @param string|array $email_type |
66 | 66 | */ |
67 | - public function init_email_type_hook( $hook, $email_type ) { |
|
67 | + public function init_email_type_hook($hook, $email_type) { |
|
68 | 68 | |
69 | - $email_type = wpinv_parse_list( $email_type ); |
|
69 | + $email_type = wpinv_parse_list($email_type); |
|
70 | 70 | |
71 | - foreach ( $email_type as $type ) { |
|
71 | + foreach ($email_type as $type) { |
|
72 | 72 | |
73 | - $email = new GetPaid_Notification_Email( $type ); |
|
73 | + $email = new GetPaid_Notification_Email($type); |
|
74 | 74 | |
75 | 75 | // Abort if it is not active. |
76 | - if ( ! $email->is_active() ) { |
|
76 | + if (!$email->is_active()) { |
|
77 | 77 | continue; |
78 | 78 | } |
79 | 79 | |
80 | - if ( method_exists( $this, $type ) ) { |
|
81 | - add_action( $hook, array( $this, $type ), 100, 2 ); |
|
80 | + if (method_exists($this, $type)) { |
|
81 | + add_action($hook, array($this, $type), 100, 2); |
|
82 | 82 | continue; |
83 | 83 | } |
84 | 84 | |
85 | - do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook ); |
|
85 | + do_action('getpaid_invoice_init_email_type_hook', $type, $hook); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | } |
@@ -93,19 +93,19 @@ discard block |
||
93 | 93 | * @param array $merge_tags |
94 | 94 | * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
95 | 95 | */ |
96 | - public function invoice_merge_tags( $merge_tags, $object ) { |
|
96 | + public function invoice_merge_tags($merge_tags, $object) { |
|
97 | 97 | |
98 | - if ( is_a( $object, 'WPInv_Invoice' ) ) { |
|
98 | + if (is_a($object, 'WPInv_Invoice')) { |
|
99 | 99 | return array_merge( |
100 | 100 | $merge_tags, |
101 | - $this->get_invoice_merge_tags( $object ) |
|
101 | + $this->get_invoice_merge_tags($object) |
|
102 | 102 | ); |
103 | 103 | } |
104 | 104 | |
105 | - if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
105 | + if (is_a($object, 'WPInv_Subscription')) { |
|
106 | 106 | return array_merge( |
107 | 107 | $merge_tags, |
108 | - $this->get_invoice_merge_tags( $object->get_parent_payment() ) |
|
108 | + $this->get_invoice_merge_tags($object->get_parent_payment()) |
|
109 | 109 | ); |
110 | 110 | } |
111 | 111 | |
@@ -119,52 +119,52 @@ discard block |
||
119 | 119 | * @param WPInv_Invoice $invoice |
120 | 120 | * @return array |
121 | 121 | */ |
122 | - public function get_invoice_merge_tags( $invoice ) { |
|
122 | + public function get_invoice_merge_tags($invoice) { |
|
123 | 123 | |
124 | 124 | // Abort if it does not exist. |
125 | - if ( ! $invoice->get_id() ) { |
|
125 | + if (!$invoice->get_id()) { |
|
126 | 126 | return array(); |
127 | 127 | } |
128 | 128 | |
129 | 129 | $due_date = $invoice->get_due_date(); |
130 | - $due_date = empty( $due_date ) ? time() + MINUTE_IN_SECONDS : strtotime( $due_date ) + ( (int) get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); |
|
130 | + $due_date = empty($due_date) ? time() + MINUTE_IN_SECONDS : strtotime($due_date) + ((int) get_option('gmt_offset') * HOUR_IN_SECONDS); |
|
131 | 131 | $merge_tags = array( |
132 | - '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
133 | - '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
134 | - '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
135 | - '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
136 | - '{email}' => sanitize_email( $invoice->get_email() ), |
|
137 | - '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
138 | - '{invoice_currency}' => sanitize_text_field( $invoice->get_currency() ), |
|
139 | - '{invoice_total}' => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ), |
|
140 | - '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
141 | - '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ), |
|
142 | - '{invoice_receipt_link}' => esc_url( $invoice->get_receipt_url() ), |
|
143 | - '{invoice_date}' => getpaid_format_date_value( $invoice->get_date_created() ), |
|
144 | - '{invoice_due_date}' => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ), |
|
145 | - '{invoice_quote}' => sanitize_text_field( strtolower( $invoice->get_label() ) ), |
|
146 | - '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_label() ) ), |
|
147 | - '{invoice_description}' => wp_kses_post( $invoice->get_description() ), |
|
148 | - '{subscription_name}' => wp_kses_post( $invoice->get_subscription_name() ), |
|
149 | - '{is_was}' => $due_date < time() ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
132 | + '{name}' => sanitize_text_field($invoice->get_user_full_name()), |
|
133 | + '{full_name}' => sanitize_text_field($invoice->get_user_full_name()), |
|
134 | + '{first_name}' => sanitize_text_field($invoice->get_first_name()), |
|
135 | + '{last_name}' => sanitize_text_field($invoice->get_last_name()), |
|
136 | + '{email}' => sanitize_email($invoice->get_email()), |
|
137 | + '{invoice_number}' => sanitize_text_field($invoice->get_number()), |
|
138 | + '{invoice_currency}' => sanitize_text_field($invoice->get_currency()), |
|
139 | + '{invoice_total}' => sanitize_text_field(wpinv_price($invoice->get_total(), $invoice->get_currency())), |
|
140 | + '{invoice_link}' => esc_url($invoice->get_view_url()), |
|
141 | + '{invoice_pay_link}' => esc_url($invoice->get_checkout_payment_url()), |
|
142 | + '{invoice_receipt_link}' => esc_url($invoice->get_receipt_url()), |
|
143 | + '{invoice_date}' => getpaid_format_date_value($invoice->get_date_created()), |
|
144 | + '{invoice_due_date}' => getpaid_format_date_value($invoice->get_due_date(), __('on receipt', 'invoicing')), |
|
145 | + '{invoice_quote}' => sanitize_text_field(strtolower($invoice->get_label())), |
|
146 | + '{invoice_label}' => sanitize_text_field(ucfirst($invoice->get_label())), |
|
147 | + '{invoice_description}' => wp_kses_post($invoice->get_description()), |
|
148 | + '{subscription_name}' => wp_kses_post($invoice->get_subscription_name()), |
|
149 | + '{is_was}' => $due_date < time() ? __('was', 'invoicing') : __('is', 'invoicing'), |
|
150 | 150 | ); |
151 | 151 | |
152 | - $payment_form_data = $invoice->get_meta( 'payment_form_data', true ); |
|
152 | + $payment_form_data = $invoice->get_meta('payment_form_data', true); |
|
153 | 153 | |
154 | - if ( is_array( $payment_form_data ) ) { |
|
154 | + if (is_array($payment_form_data)) { |
|
155 | 155 | |
156 | - foreach ( $payment_form_data as $label => $value ) { |
|
156 | + foreach ($payment_form_data as $label => $value) { |
|
157 | 157 | |
158 | - $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) ); |
|
159 | - $value = is_array( $value ) ? implode( ', ', $value ) : $value; |
|
158 | + $label = preg_replace('/[^a-z0-9]+/', '_', strtolower($label)); |
|
159 | + $value = is_array($value) ? implode(', ', $value) : $value; |
|
160 | 160 | |
161 | - if ( is_scalar( $value ) ) { |
|
162 | - $merge_tags[ "{{$label}}" ] = wp_kses_post( $value ); |
|
161 | + if (is_scalar($value)) { |
|
162 | + $merge_tags["{{$label}}"] = wp_kses_post($value); |
|
163 | 163 | } |
164 | 164 | } |
165 | 165 | } |
166 | 166 | |
167 | - return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice ); |
|
167 | + return apply_filters('getpaid_invoice_email_merge_tags', $merge_tags, $invoice); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | /** |
@@ -176,12 +176,12 @@ discard block |
||
176 | 176 | * @param string|array $recipients |
177 | 177 | * @param array $extra_args Extra template args. |
178 | 178 | */ |
179 | - public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
179 | + public function send_email($invoice, $email, $type, $recipients, $extra_args = array()) { |
|
180 | 180 | |
181 | - do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
181 | + do_action('getpaid_before_send_invoice_notification', $type, $invoice, $email); |
|
182 | 182 | |
183 | - $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' ); |
|
184 | - if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) { |
|
183 | + $skip = $invoice->is_free() && wpinv_get_option('skip_email_free_invoice'); |
|
184 | + if (apply_filters('getpaid_skip_invoice_email', $skip, $type, $invoice)) { |
|
185 | 185 | return; |
186 | 186 | } |
187 | 187 | |
@@ -189,43 +189,43 @@ discard block |
||
189 | 189 | $merge_tags = $email->get_merge_tags(); |
190 | 190 | |
191 | 191 | $result = $mailer->send( |
192 | - apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
193 | - $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
194 | - $email->get_content( $merge_tags, $extra_args ), |
|
192 | + apply_filters('getpaid_invoice_email_recipients', wpinv_parse_list($recipients), $email), |
|
193 | + $email->add_merge_tags($email->get_subject(), $merge_tags), |
|
194 | + $email->get_content($merge_tags, $extra_args), |
|
195 | 195 | $email->get_attachments() |
196 | 196 | ); |
197 | 197 | |
198 | 198 | // Maybe send a copy to the admin. |
199 | - if ( $email->include_admin_bcc() ) { |
|
199 | + if ($email->include_admin_bcc()) { |
|
200 | 200 | $mailer->send( |
201 | 201 | wpinv_get_admin_email(), |
202 | - $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
203 | - $email->get_content( $merge_tags ), |
|
202 | + $email->add_merge_tags($email->get_subject() . __(' - ADMIN BCC COPY', 'invoicing'), $merge_tags), |
|
203 | + $email->get_content($merge_tags), |
|
204 | 204 | $email->get_attachments() |
205 | 205 | ); |
206 | 206 | } |
207 | 207 | |
208 | - if ( $result ) { |
|
208 | + if ($result) { |
|
209 | 209 | $invoice->add_system_note( |
210 | 210 | sprintf( |
211 | 211 | // translators: %1 is the email type, %2 is the invoice recipient. |
212 | - __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ), |
|
213 | - sanitize_key( $type ), |
|
214 | - $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
212 | + __('Successfully sent %1$s notification email to %2$s.', 'invoicing'), |
|
213 | + sanitize_key($type), |
|
214 | + $email->is_admin_email() ? __('admin', 'invoicing') : __('the customer', 'invoicing') |
|
215 | 215 | ) |
216 | 216 | ); |
217 | 217 | } else { |
218 | 218 | $invoice->add_system_note( |
219 | 219 | sprintf( |
220 | 220 | // translators: %1 is the email type, %2 is the invoice recipient. |
221 | - __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ), |
|
222 | - sanitize_key( $type ), |
|
223 | - $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
221 | + __('Failed sending %1$s notification email to %2$s.', 'invoicing'), |
|
222 | + sanitize_key($type), |
|
223 | + $email->is_admin_email() ? __('admin', 'invoicing') : __('the customer', 'invoicing') |
|
224 | 224 | ) |
225 | 225 | ); |
226 | 226 | } |
227 | 227 | |
228 | - do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
228 | + do_action('getpaid_after_send_invoice_notification', $type, $invoice, $email); |
|
229 | 229 | |
230 | 230 | return $result; |
231 | 231 | } |
@@ -236,20 +236,20 @@ discard block |
||
236 | 236 | * @param array $recipients |
237 | 237 | * @param GetPaid_Notification_Email $email |
238 | 238 | */ |
239 | - public function filter_email_recipients( $recipients, $email ) { |
|
239 | + public function filter_email_recipients($recipients, $email) { |
|
240 | 240 | |
241 | - if ( ! $email->is_admin_email() ) { |
|
241 | + if (!$email->is_admin_email()) { |
|
242 | 242 | $cc = $email->object->get_email_cc(); |
243 | - $cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true ); |
|
243 | + $cc_2 = get_user_meta($email->object->get_user_id(), '_wpinv_email_cc', true); |
|
244 | 244 | |
245 | - if ( ! empty( $cc ) ) { |
|
246 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
247 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
245 | + if (!empty($cc)) { |
|
246 | + $cc = array_map('sanitize_email', wpinv_parse_list($cc)); |
|
247 | + $recipients = array_filter(array_unique(array_merge($recipients, $cc))); |
|
248 | 248 | } |
249 | 249 | |
250 | - if ( ! empty( $cc_2 ) ) { |
|
251 | - $cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) ); |
|
252 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) ); |
|
250 | + if (!empty($cc_2)) { |
|
251 | + $cc_2 = array_map('sanitize_email', wpinv_parse_list($cc_2)); |
|
252 | + $recipients = array_filter(array_unique(array_merge($recipients, $cc_2))); |
|
253 | 253 | } |
254 | 254 | } |
255 | 255 | |
@@ -262,17 +262,17 @@ discard block |
||
262 | 262 | * |
263 | 263 | * @param WPInv_Invoice $invoice |
264 | 264 | */ |
265 | - public function new_invoice( $invoice ) { |
|
265 | + public function new_invoice($invoice) { |
|
266 | 266 | |
267 | 267 | // Only send this email for invoices created via the admin page. |
268 | - if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
268 | + if (!$invoice->is_type('invoice') || $invoice->is_paid() || $this->is_payment_form_invoice($invoice->get_id())) { |
|
269 | 269 | return; |
270 | 270 | } |
271 | 271 | |
272 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
272 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
273 | 273 | $recipient = wpinv_get_admin_email(); |
274 | 274 | |
275 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
275 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
276 | 276 | |
277 | 277 | } |
278 | 278 | |
@@ -281,12 +281,12 @@ discard block |
||
281 | 281 | * |
282 | 282 | * @param WPInv_Invoice $invoice |
283 | 283 | */ |
284 | - public function cancelled_invoice( $invoice ) { |
|
284 | + public function cancelled_invoice($invoice) { |
|
285 | 285 | |
286 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
286 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
287 | 287 | $recipient = $invoice->get_email(); |
288 | 288 | |
289 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
289 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | /** |
@@ -294,12 +294,12 @@ discard block |
||
294 | 294 | * |
295 | 295 | * @param WPInv_Invoice $invoice |
296 | 296 | */ |
297 | - public function failed_invoice( $invoice ) { |
|
297 | + public function failed_invoice($invoice) { |
|
298 | 298 | |
299 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
299 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
300 | 300 | $recipient = wpinv_get_admin_email(); |
301 | 301 | |
302 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
302 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
303 | 303 | |
304 | 304 | } |
305 | 305 | |
@@ -308,12 +308,12 @@ discard block |
||
308 | 308 | * |
309 | 309 | * @param WPInv_Invoice $invoice |
310 | 310 | */ |
311 | - public function onhold_invoice( $invoice ) { |
|
311 | + public function onhold_invoice($invoice) { |
|
312 | 312 | |
313 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
313 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
314 | 314 | $recipient = $invoice->get_email(); |
315 | 315 | |
316 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
316 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
317 | 317 | |
318 | 318 | } |
319 | 319 | |
@@ -322,12 +322,12 @@ discard block |
||
322 | 322 | * |
323 | 323 | * @param WPInv_Invoice $invoice |
324 | 324 | */ |
325 | - public function processing_invoice( $invoice ) { |
|
325 | + public function processing_invoice($invoice) { |
|
326 | 326 | |
327 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
327 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
328 | 328 | $recipient = $invoice->get_email(); |
329 | 329 | |
330 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
330 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
331 | 331 | |
332 | 332 | } |
333 | 333 | |
@@ -336,17 +336,17 @@ discard block |
||
336 | 336 | * |
337 | 337 | * @param WPInv_Invoice $invoice |
338 | 338 | */ |
339 | - public function completed_invoice( $invoice ) { |
|
339 | + public function completed_invoice($invoice) { |
|
340 | 340 | |
341 | 341 | // (Maybe) abort if it is a renewal invoice. |
342 | - if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
342 | + if ($invoice->is_renewal() && !wpinv_get_option('email_completed_invoice_renewal_active', false)) { |
|
343 | 343 | return; |
344 | 344 | } |
345 | 345 | |
346 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
346 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
347 | 347 | $recipient = $invoice->get_email(); |
348 | 348 | |
349 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
349 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
350 | 350 | |
351 | 351 | } |
352 | 352 | |
@@ -355,12 +355,12 @@ discard block |
||
355 | 355 | * |
356 | 356 | * @param WPInv_Invoice $invoice |
357 | 357 | */ |
358 | - public function refunded_invoice( $invoice ) { |
|
358 | + public function refunded_invoice($invoice) { |
|
359 | 359 | |
360 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
360 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
361 | 361 | $recipient = $invoice->get_email(); |
362 | 362 | |
363 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
363 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
364 | 364 | |
365 | 365 | } |
366 | 366 | |
@@ -370,21 +370,21 @@ discard block |
||
370 | 370 | * @param WPInv_Invoice $invoice |
371 | 371 | * @param bool $force |
372 | 372 | */ |
373 | - public function user_invoice( $invoice, $force = false ) { |
|
373 | + public function user_invoice($invoice, $force = false) { |
|
374 | 374 | |
375 | - if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) { |
|
375 | + if (!$force && !empty($GLOBALS['wpinv_skip_invoice_notification'])) { |
|
376 | 376 | return; |
377 | 377 | } |
378 | 378 | |
379 | 379 | // Only send this email for invoices created via the admin page. |
380 | - if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) { |
|
380 | + if (!$invoice->is_type('invoice') || (empty($force) && $invoice->is_paid()) || (empty($force) && $this->is_payment_form_invoice($invoice->get_id()))) { |
|
381 | 381 | return; |
382 | 382 | } |
383 | 383 | |
384 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
384 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
385 | 385 | $recipient = $invoice->get_email(); |
386 | 386 | |
387 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
387 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
388 | 388 | |
389 | 389 | } |
390 | 390 | |
@@ -394,11 +394,11 @@ discard block |
||
394 | 394 | * @param int $invoice |
395 | 395 | * @return bool |
396 | 396 | */ |
397 | - public function is_payment_form_invoice( $invoice ) { |
|
398 | - $created_via = get_post_meta( $invoice, 'wpinv_created_via', true ); |
|
397 | + public function is_payment_form_invoice($invoice) { |
|
398 | + $created_via = get_post_meta($invoice, 'wpinv_created_via', true); |
|
399 | 399 | $is_payment_form_invoice = 'payment_form' === $created_via || 'geodirectory' === $created_via; |
400 | - $is_payment_form_invoice = apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice ); |
|
401 | - return empty( $_GET['getpaid-admin-action'] ) && $is_payment_form_invoice; |
|
400 | + $is_payment_form_invoice = apply_filters('getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice); |
|
401 | + return empty($_GET['getpaid-admin-action']) && $is_payment_form_invoice; |
|
402 | 402 | } |
403 | 403 | |
404 | 404 | /** |
@@ -407,12 +407,12 @@ discard block |
||
407 | 407 | * @param WPInv_Invoice $invoice |
408 | 408 | * @param string $note |
409 | 409 | */ |
410 | - public function user_note( $invoice, $note ) { |
|
410 | + public function user_note($invoice, $note) { |
|
411 | 411 | |
412 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
412 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
413 | 413 | $recipient = $invoice->get_email(); |
414 | 414 | |
415 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
415 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient, array('customer_note' => $note)); |
|
416 | 416 | |
417 | 417 | } |
418 | 418 | |
@@ -421,9 +421,9 @@ discard block |
||
421 | 421 | * |
422 | 422 | * @param WPInv_Invoice $invoice |
423 | 423 | */ |
424 | - public function force_send_overdue_notice( $invoice ) { |
|
425 | - $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
426 | - return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
424 | + public function force_send_overdue_notice($invoice) { |
|
425 | + $email = new GetPaid_Notification_Email('overdue', $invoice); |
|
426 | + return $this->send_email($invoice, $email, 'overdue', $invoice->get_email()); |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | /** |
@@ -434,38 +434,38 @@ discard block |
||
434 | 434 | public function overdue() { |
435 | 435 | global $wpdb; |
436 | 436 | |
437 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
437 | + $email = new GetPaid_Notification_Email(__FUNCTION__); |
|
438 | 438 | |
439 | 439 | // Fetch reminder days. |
440 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
440 | + $reminder_days = array_unique(wp_parse_id_list($email->get_option('days'))); |
|
441 | 441 | |
442 | 442 | // Abort if non is set. |
443 | - if ( empty( $reminder_days ) ) { |
|
443 | + if (empty($reminder_days)) { |
|
444 | 444 | return; |
445 | 445 | } |
446 | 446 | |
447 | 447 | // Retrieve date query. |
448 | - $date_query = $this->get_date_query( $reminder_days ); |
|
448 | + $date_query = $this->get_date_query($reminder_days); |
|
449 | 449 | |
450 | 450 | // Invoices table. |
451 | 451 | $table = $wpdb->prefix . 'getpaid_invoices'; |
452 | 452 | |
453 | 453 | // Fetch invoices. |
454 | - $invoices = $wpdb->get_col( |
|
454 | + $invoices = $wpdb->get_col( |
|
455 | 455 | "SELECT posts.ID FROM $wpdb->posts as posts |
456 | 456 | LEFT JOIN $table as invoices ON invoices.post_id = posts.ID |
457 | 457 | WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query" |
458 | 458 | ); |
459 | 459 | |
460 | - foreach ( $invoices as $invoice ) { |
|
460 | + foreach ($invoices as $invoice) { |
|
461 | 461 | |
462 | 462 | // Only send this email for invoices created via the admin page. |
463 | - if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
464 | - $invoice = new WPInv_Invoice( $invoice ); |
|
463 | + if (!$this->is_payment_form_invoice($invoice)) { |
|
464 | + $invoice = new WPInv_Invoice($invoice); |
|
465 | 465 | $email->object = $invoice; |
466 | 466 | |
467 | - if ( $invoice->needs_payment() && ! $invoice->is_renewal() ) { |
|
468 | - $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
467 | + if ($invoice->needs_payment() && !$invoice->is_renewal()) { |
|
468 | + $this->send_email($invoice, $email, __FUNCTION__, $invoice->get_email()); |
|
469 | 469 | } |
470 | 470 | } |
471 | 471 | } |
@@ -478,14 +478,14 @@ discard block |
||
478 | 478 | * @param array $reminder_days |
479 | 479 | * @return string |
480 | 480 | */ |
481 | - public function get_date_query( $reminder_days ) { |
|
481 | + public function get_date_query($reminder_days) { |
|
482 | 482 | |
483 | 483 | $date_query = array( |
484 | 484 | 'relation' => 'OR', |
485 | 485 | ); |
486 | 486 | |
487 | - foreach ( $reminder_days as $days ) { |
|
488 | - $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
487 | + foreach ($reminder_days as $days) { |
|
488 | + $date = date_parse(date('Y-m-d', strtotime("-$days days", current_time('timestamp')))); |
|
489 | 489 | |
490 | 490 | $date_query[] = array( |
491 | 491 | 'year' => $date['year'], |
@@ -495,7 +495,7 @@ discard block |
||
495 | 495 | |
496 | 496 | } |
497 | 497 | |
498 | - $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
498 | + $date_query = new WP_Date_Query($date_query, 'invoices.due_date'); |
|
499 | 499 | |
500 | 500 | return $date_query->get_sql(); |
501 | 501 |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * GetPaid_Item_Data_Store class file. |
4 | 4 | * |
5 | 5 | */ |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
@@ -80,39 +80,39 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @param WPInv_Item $item Item object. |
82 | 82 | */ |
83 | - public function create( &$item ) { |
|
84 | - $item->set_version( WPINV_VERSION ); |
|
85 | - $item->set_date_created( current_time( 'mysql' ) ); |
|
83 | + public function create(&$item) { |
|
84 | + $item->set_version(WPINV_VERSION); |
|
85 | + $item->set_date_created(current_time('mysql')); |
|
86 | 86 | |
87 | 87 | // Create a new post. |
88 | 88 | $id = wp_insert_post( |
89 | 89 | apply_filters( |
90 | 90 | 'getpaid_new_item_data', |
91 | 91 | array( |
92 | - 'post_date' => $item->get_date_created( 'edit' ), |
|
92 | + 'post_date' => $item->get_date_created('edit'), |
|
93 | 93 | 'post_type' => 'wpi_item', |
94 | - 'post_status' => $this->get_post_status( $item ), |
|
94 | + 'post_status' => $this->get_post_status($item), |
|
95 | 95 | 'ping_status' => 'closed', |
96 | - 'post_author' => $item->get_author( 'edit' ), |
|
97 | - 'post_title' => $item->get_name( 'edit' ), |
|
96 | + 'post_author' => $item->get_author('edit'), |
|
97 | + 'post_title' => $item->get_name('edit'), |
|
98 | 98 | 'post_parent' => $item->get_parent_id(), |
99 | - 'post_excerpt' => $item->get_description( 'edit' ), |
|
99 | + 'post_excerpt' => $item->get_description('edit'), |
|
100 | 100 | ) |
101 | 101 | ), |
102 | 102 | true |
103 | 103 | ); |
104 | 104 | |
105 | - if ( $id && ! is_wp_error( $id ) ) { |
|
106 | - $item->set_id( $id ); |
|
107 | - $this->update_post_meta( $item ); |
|
105 | + if ($id && !is_wp_error($id)) { |
|
106 | + $item->set_id($id); |
|
107 | + $this->update_post_meta($item); |
|
108 | 108 | $item->save_meta_data(); |
109 | 109 | $item->apply_changes(); |
110 | - $this->clear_caches( $item ); |
|
111 | - do_action( 'getpaid_new_item', $item ); |
|
110 | + $this->clear_caches($item); |
|
111 | + do_action('getpaid_new_item', $item); |
|
112 | 112 | return true; |
113 | 113 | } |
114 | 114 | |
115 | - if ( is_wp_error( $id ) ) { |
|
115 | + if (is_wp_error($id)) { |
|
116 | 116 | $item->last_error = $id->get_error_message(); |
117 | 117 | } |
118 | 118 | |
@@ -125,14 +125,14 @@ discard block |
||
125 | 125 | * @param WPInv_Item $item Item object. |
126 | 126 | * |
127 | 127 | */ |
128 | - public function read( &$item ) { |
|
128 | + public function read(&$item) { |
|
129 | 129 | |
130 | 130 | $item->set_defaults(); |
131 | - $item_object = get_post( $item->get_id() ); |
|
131 | + $item_object = get_post($item->get_id()); |
|
132 | 132 | |
133 | - if ( ! $item->get_id() || ! $item_object || $item_object->post_type != 'wpi_item' ) { |
|
134 | - $item->last_error = __( 'Invalid item.', 'invoicing' ); |
|
135 | - $item->set_id( 0 ); |
|
133 | + if (!$item->get_id() || !$item_object || $item_object->post_type != 'wpi_item') { |
|
134 | + $item->last_error = __('Invalid item.', 'invoicing'); |
|
135 | + $item->set_id(0); |
|
136 | 136 | return false; |
137 | 137 | } |
138 | 138 | |
@@ -148,10 +148,10 @@ discard block |
||
148 | 148 | ) |
149 | 149 | ); |
150 | 150 | |
151 | - $this->read_object_data( $item, $item_object ); |
|
151 | + $this->read_object_data($item, $item_object); |
|
152 | 152 | $item->read_meta_data(); |
153 | - $item->set_object_read( true ); |
|
154 | - do_action( 'getpaid_read_item', $item ); |
|
153 | + $item->set_object_read(true); |
|
154 | + do_action('getpaid_read_item', $item); |
|
155 | 155 | |
156 | 156 | } |
157 | 157 | |
@@ -160,29 +160,29 @@ discard block |
||
160 | 160 | * |
161 | 161 | * @param WPInv_Item $item Item object. |
162 | 162 | */ |
163 | - public function update( &$item ) { |
|
163 | + public function update(&$item) { |
|
164 | 164 | $item->save_meta_data(); |
165 | - $item->set_version( WPINV_VERSION ); |
|
165 | + $item->set_version(WPINV_VERSION); |
|
166 | 166 | |
167 | - if ( null === $item->get_date_created( 'edit' ) ) { |
|
168 | - $item->set_date_created( current_time( 'mysql' ) ); |
|
167 | + if (null === $item->get_date_created('edit')) { |
|
168 | + $item->set_date_created(current_time('mysql')); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | // Grab the current status so we can compare. |
172 | - $previous_status = get_post_status( $item->get_id() ); |
|
172 | + $previous_status = get_post_status($item->get_id()); |
|
173 | 173 | |
174 | 174 | $changes = $item->get_changes(); |
175 | 175 | |
176 | 176 | // Only update the post when the post data changes. |
177 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'description', 'name', 'author' ), array_keys( $changes ) ) ) { |
|
177 | + if (array_intersect(array('date_created', 'date_modified', 'status', 'parent_id', 'description', 'name', 'author'), array_keys($changes))) { |
|
178 | 178 | $post_data = array( |
179 | - 'post_date' => $item->get_date_created( 'edit' ), |
|
180 | - 'post_status' => $item->get_status( 'edit' ), |
|
181 | - 'post_parent' => $item->get_parent_id( 'edit' ), |
|
182 | - 'post_excerpt' => $item->get_description( 'edit' ), |
|
183 | - 'post_modified' => $item->get_date_modified( 'edit' ), |
|
184 | - 'post_title' => $item->get_name( 'edit' ), |
|
185 | - 'post_author' => $item->get_author( 'edit' ), |
|
179 | + 'post_date' => $item->get_date_created('edit'), |
|
180 | + 'post_status' => $item->get_status('edit'), |
|
181 | + 'post_parent' => $item->get_parent_id('edit'), |
|
182 | + 'post_excerpt' => $item->get_description('edit'), |
|
183 | + 'post_modified' => $item->get_date_modified('edit'), |
|
184 | + 'post_title' => $item->get_name('edit'), |
|
185 | + 'post_author' => $item->get_author('edit'), |
|
186 | 186 | ); |
187 | 187 | |
188 | 188 | /** |
@@ -193,25 +193,25 @@ discard block |
||
193 | 193 | * This ensures hooks are fired by either WP itself (admin screen save), |
194 | 194 | * or an update purely from CRUD. |
195 | 195 | */ |
196 | - if ( doing_action( 'save_post' ) ) { |
|
197 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $item->get_id() ) ); |
|
198 | - clean_post_cache( $item->get_id() ); |
|
196 | + if (doing_action('save_post')) { |
|
197 | + $GLOBALS['wpdb']->update($GLOBALS['wpdb']->posts, $post_data, array('ID' => $item->get_id())); |
|
198 | + clean_post_cache($item->get_id()); |
|
199 | 199 | } else { |
200 | - wp_update_post( array_merge( array( 'ID' => $item->get_id() ), $post_data ) ); |
|
200 | + wp_update_post(array_merge(array('ID' => $item->get_id()), $post_data)); |
|
201 | 201 | } |
202 | - $item->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
202 | + $item->read_meta_data(true); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
203 | 203 | } |
204 | - $this->update_post_meta( $item ); |
|
204 | + $this->update_post_meta($item); |
|
205 | 205 | $item->apply_changes(); |
206 | - $this->clear_caches( $item ); |
|
206 | + $this->clear_caches($item); |
|
207 | 207 | |
208 | 208 | // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
209 | - $new_status = $item->get_status( 'edit' ); |
|
209 | + $new_status = $item->get_status('edit'); |
|
210 | 210 | |
211 | - if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
212 | - do_action( 'getpaid_new_item', $item ); |
|
211 | + if ($new_status !== $previous_status && in_array($previous_status, array('new', 'auto-draft', 'draft'), true)) { |
|
212 | + do_action('getpaid_new_item', $item); |
|
213 | 213 | } else { |
214 | - do_action( 'getpaid_update_item', $item ); |
|
214 | + do_action('getpaid_update_item', $item); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | } |
@@ -228,14 +228,14 @@ discard block |
||
228 | 228 | * @param WPInv_Item $item WPInv_Item object. |
229 | 229 | * @since 1.0.19 |
230 | 230 | */ |
231 | - protected function update_post_meta( &$item ) { |
|
231 | + protected function update_post_meta(&$item) { |
|
232 | 232 | |
233 | 233 | // Ensure that we have a custom id. |
234 | - if ( ! $item->get_custom_id() ) { |
|
235 | - $item->set_custom_id( $item->get_id() ); |
|
234 | + if (!$item->get_custom_id()) { |
|
235 | + $item->set_custom_id($item->get_id()); |
|
236 | 236 | } |
237 | 237 | |
238 | - parent::update_post_meta( $item ); |
|
238 | + parent::update_post_meta($item); |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -146,8 +146,8 @@ discard block |
||
146 | 146 | $this->state = wpinv_get_default_state(); |
147 | 147 | |
148 | 148 | // Do we have an actual submission? |
149 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
150 | - $this->load_data( wp_kses_post_deep( wp_unslash( $_POST ) ) ); |
|
149 | + if (isset($_POST['getpaid_payment_form_submission'])) { |
|
150 | + $this->load_data(wp_kses_post_deep(wp_unslash($_POST))); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | } |
@@ -157,16 +157,16 @@ discard block |
||
157 | 157 | * |
158 | 158 | * @param array $data |
159 | 159 | */ |
160 | - public function load_data( $data ) { |
|
160 | + public function load_data($data) { |
|
161 | 161 | |
162 | 162 | // Allow plugins to filter the data. |
163 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
163 | + $data = apply_filters('getpaid_submission_data', $data, $this); |
|
164 | 164 | |
165 | 165 | // Cache it... |
166 | 166 | $this->data = $data; |
167 | 167 | |
168 | 168 | // Then generate a unique id from the data. |
169 | - $this->id = md5( wp_json_encode( $data ) ); |
|
169 | + $this->id = md5(wp_json_encode($data)); |
|
170 | 170 | |
171 | 171 | // Finally, process the submission. |
172 | 172 | try { |
@@ -176,29 +176,29 @@ discard block |
||
176 | 176 | $processors = apply_filters( |
177 | 177 | 'getpaid_payment_form_submission_processors', |
178 | 178 | array( |
179 | - array( $this, 'process_payment_form' ), |
|
180 | - array( $this, 'process_invoice' ), |
|
181 | - array( $this, 'process_fees' ), |
|
182 | - array( $this, 'process_items' ), |
|
183 | - array( $this, 'process_discount' ), |
|
184 | - array( $this, 'process_taxes' ), |
|
179 | + array($this, 'process_payment_form'), |
|
180 | + array($this, 'process_invoice'), |
|
181 | + array($this, 'process_fees'), |
|
182 | + array($this, 'process_items'), |
|
183 | + array($this, 'process_discount'), |
|
184 | + array($this, 'process_taxes'), |
|
185 | 185 | ), |
186 | 186 | $this |
187 | 187 | ); |
188 | 188 | |
189 | - foreach ( $processors as $processor ) { |
|
190 | - call_user_func_array( $processor, array( &$this ) ); |
|
189 | + foreach ($processors as $processor) { |
|
190 | + call_user_func_array($processor, array(&$this)); |
|
191 | 191 | } |
192 | - } catch ( GetPaid_Payment_Exception $e ) { |
|
192 | + } catch (GetPaid_Payment_Exception $e) { |
|
193 | 193 | $this->last_error = $e->getMessage(); |
194 | 194 | $this->last_error_code = $e->getErrorCode(); |
195 | - } catch ( Exception $e ) { |
|
195 | + } catch (Exception $e) { |
|
196 | 196 | $this->last_error = $e->getMessage(); |
197 | 197 | $this->last_error_code = $e->getCode(); |
198 | 198 | } |
199 | 199 | |
200 | 200 | // Fired when we are done processing a submission. |
201 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
201 | + do_action_ref_array('getpaid_process_submission', array(&$this)); |
|
202 | 202 | |
203 | 203 | } |
204 | 204 | |
@@ -219,18 +219,18 @@ discard block |
||
219 | 219 | public function process_payment_form() { |
220 | 220 | |
221 | 221 | // Every submission needs an active payment form. |
222 | - if ( empty( $this->data['form_id'] ) ) { |
|
223 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
222 | + if (empty($this->data['form_id'])) { |
|
223 | + throw new Exception(__('Missing payment form', 'invoicing')); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | // Fetch the payment form. |
227 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
227 | + $this->payment_form = new GetPaid_Payment_Form($this->data['form_id']); |
|
228 | 228 | |
229 | - if ( ! $this->payment_form->is_active() ) { |
|
230 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
229 | + if (!$this->payment_form->is_active()) { |
|
230 | + throw new Exception(__('Payment form not active', 'invoicing')); |
|
231 | 231 | } |
232 | 232 | |
233 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
233 | + do_action_ref_array('getpaid_submissions_process_payment_form', array(&$this)); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | /** |
@@ -260,64 +260,64 @@ discard block |
||
260 | 260 | public function process_invoice() { |
261 | 261 | |
262 | 262 | // Abort if there is no invoice. |
263 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
263 | + if (empty($this->data['invoice_id'])) { |
|
264 | 264 | |
265 | 265 | // Check if we are resuming a payment. |
266 | - if ( empty( $this->data['maybe_use_invoice'] ) ) { |
|
266 | + if (empty($this->data['maybe_use_invoice'])) { |
|
267 | 267 | return; |
268 | 268 | } |
269 | 269 | |
270 | - $invoice = wpinv_get_invoice( $this->data['maybe_use_invoice'] ); |
|
271 | - if ( empty( $invoice ) || ! $invoice->has_status( 'draft, auto-draft, wpi-pending' ) ) { |
|
270 | + $invoice = wpinv_get_invoice($this->data['maybe_use_invoice']); |
|
271 | + if (empty($invoice) || !$invoice->has_status('draft, auto-draft, wpi-pending')) { |
|
272 | 272 | return; |
273 | 273 | } |
274 | 274 | } |
275 | 275 | |
276 | 276 | // If the submission is for an existing invoice, ensure that it exists |
277 | 277 | // and that it is not paid for. |
278 | - if ( empty( $invoice ) ) { |
|
279 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
278 | + if (empty($invoice)) { |
|
279 | + $invoice = wpinv_get_invoice($this->data['invoice_id']); |
|
280 | 280 | } |
281 | 281 | |
282 | - if ( empty( $invoice ) ) { |
|
283 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
282 | + if (empty($invoice)) { |
|
283 | + throw new Exception(__('Invalid invoice', 'invoicing')); |
|
284 | 284 | } |
285 | 285 | |
286 | - if ( $invoice->is_paid() ) { |
|
287 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
286 | + if ($invoice->is_paid()) { |
|
287 | + throw new Exception(__('This invoice is already paid for.', 'invoicing')); |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | $this->payment_form->invoice = $invoice; |
291 | - if ( ! $this->payment_form->is_default() ) { |
|
291 | + if (!$this->payment_form->is_default()) { |
|
292 | 292 | |
293 | 293 | $items = array(); |
294 | 294 | $item_ids = array(); |
295 | 295 | |
296 | - foreach ( $invoice->get_items() as $item ) { |
|
297 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
296 | + foreach ($invoice->get_items() as $item) { |
|
297 | + if (!in_array($item->get_id(), $item_ids)) { |
|
298 | 298 | $item_ids[] = $item->get_id(); |
299 | 299 | $items[] = $item; |
300 | 300 | } |
301 | 301 | } |
302 | 302 | |
303 | - foreach ( $this->payment_form->get_items() as $item ) { |
|
304 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
303 | + foreach ($this->payment_form->get_items() as $item) { |
|
304 | + if (!in_array($item->get_id(), $item_ids)) { |
|
305 | 305 | $item_ids[] = $item->get_id(); |
306 | 306 | $items[] = $item; |
307 | 307 | } |
308 | 308 | } |
309 | 309 | |
310 | - $this->payment_form->set_items( $items ); |
|
310 | + $this->payment_form->set_items($items); |
|
311 | 311 | |
312 | 312 | } else { |
313 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
313 | + $this->payment_form->set_items($invoice->get_items()); |
|
314 | 314 | } |
315 | 315 | |
316 | 316 | $this->country = $invoice->get_country(); |
317 | 317 | $this->state = $invoice->get_state(); |
318 | 318 | $this->invoice = $invoice; |
319 | 319 | |
320 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
320 | + do_action_ref_array('getpaid_submissions_process_invoice', array(&$this)); |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | /** |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | * @return bool |
338 | 338 | */ |
339 | 339 | public function has_invoice() { |
340 | - return ! empty( $this->invoice ); |
|
340 | + return !empty($this->invoice); |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | /* |
@@ -356,13 +356,13 @@ discard block |
||
356 | 356 | */ |
357 | 357 | public function process_items() { |
358 | 358 | |
359 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
359 | + $processor = new GetPaid_Payment_Form_Submission_Items($this); |
|
360 | 360 | |
361 | - foreach ( $processor->items as $item ) { |
|
362 | - $this->add_item( $item ); |
|
361 | + foreach ($processor->items as $item) { |
|
362 | + $this->add_item($item); |
|
363 | 363 | } |
364 | 364 | |
365 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
365 | + do_action_ref_array('getpaid_submissions_process_items', array(&$this)); |
|
366 | 366 | } |
367 | 367 | |
368 | 368 | /** |
@@ -371,20 +371,20 @@ discard block |
||
371 | 371 | * @since 1.0.19 |
372 | 372 | * @param GetPaid_Form_Item $item |
373 | 373 | */ |
374 | - public function add_item( $item ) { |
|
374 | + public function add_item($item) { |
|
375 | 375 | |
376 | 376 | // Make sure that it is available for purchase. |
377 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
377 | + if (!$item->can_purchase() || isset($this->items[$item->get_id()])) { |
|
378 | 378 | return; |
379 | 379 | } |
380 | 380 | |
381 | 381 | // Each submission can only contain one recurring item. |
382 | - if ( $item->is_recurring() ) { |
|
382 | + if ($item->is_recurring()) { |
|
383 | 383 | $this->has_recurring = $item->get_id(); |
384 | 384 | } |
385 | 385 | |
386 | 386 | // Update the items and totals. |
387 | - $this->items[ $item->get_id() ] = $item; |
|
387 | + $this->items[$item->get_id()] = $item; |
|
388 | 388 | $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
389 | 389 | $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
390 | 390 | |
@@ -398,17 +398,17 @@ discard block |
||
398 | 398 | * |
399 | 399 | * @since 1.0.19 |
400 | 400 | */ |
401 | - public function remove_item( $item_id ) { |
|
401 | + public function remove_item($item_id) { |
|
402 | 402 | |
403 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
404 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
405 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
403 | + if (isset($this->items[$item_id])) { |
|
404 | + $this->totals['subtotal']['initial'] -= $this->items[$item_id]->get_sub_total(); |
|
405 | + $this->totals['subtotal']['recurring'] -= $this->items[$item_id]->get_recurring_sub_total(); |
|
406 | 406 | |
407 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
407 | + if ($this->items[$item_id]->is_recurring()) { |
|
408 | 408 | $this->has_recurring = 0; |
409 | 409 | } |
410 | 410 | |
411 | - unset( $this->items[ $item_id ] ); |
|
411 | + unset($this->items[$item_id]); |
|
412 | 412 | } |
413 | 413 | |
414 | 414 | } |
@@ -420,7 +420,7 @@ discard block |
||
420 | 420 | */ |
421 | 421 | public function get_subtotal() { |
422 | 422 | |
423 | - if ( wpinv_prices_include_tax() ) { |
|
423 | + if (wpinv_prices_include_tax()) { |
|
424 | 424 | return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
425 | 425 | } |
426 | 426 | |
@@ -434,7 +434,7 @@ discard block |
||
434 | 434 | */ |
435 | 435 | public function get_recurring_subtotal() { |
436 | 436 | |
437 | - if ( wpinv_prices_include_tax() ) { |
|
437 | + if (wpinv_prices_include_tax()) { |
|
438 | 438 | return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
439 | 439 | } |
440 | 440 | |
@@ -458,7 +458,7 @@ discard block |
||
458 | 458 | * @return bool |
459 | 459 | */ |
460 | 460 | public function has_subscription_group() { |
461 | - return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
461 | + return $this->has_recurring && getpaid_should_group_subscriptions($this) && 1 == count(getpaid_get_subscription_groups($this)); |
|
462 | 462 | } |
463 | 463 | |
464 | 464 | /** |
@@ -468,7 +468,7 @@ discard block |
||
468 | 468 | * @return bool |
469 | 469 | */ |
470 | 470 | public function has_multiple_subscription_groups() { |
471 | - return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
471 | + return $this->has_recurring && 1 < count(getpaid_get_subscription_groups($this)); |
|
472 | 472 | } |
473 | 473 | |
474 | 474 | /* |
@@ -488,39 +488,39 @@ discard block |
||
488 | 488 | public function process_taxes() { |
489 | 489 | |
490 | 490 | // Abort if we're not using taxes. |
491 | - if ( ! $this->use_taxes() ) { |
|
491 | + if (!$this->use_taxes()) { |
|
492 | 492 | return; |
493 | 493 | } |
494 | 494 | |
495 | 495 | // If a custom country && state has been passed in, use it to calculate taxes. |
496 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
497 | - if ( ! empty( $country ) ) { |
|
496 | + $country = $this->get_field('wpinv_country', 'billing'); |
|
497 | + if (!empty($country)) { |
|
498 | 498 | $this->country = $country; |
499 | 499 | } |
500 | 500 | |
501 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
502 | - if ( ! empty( $state ) ) { |
|
501 | + $state = $this->get_field('wpinv_state', 'billing'); |
|
502 | + if (!empty($state)) { |
|
503 | 503 | $this->state = $state; |
504 | 504 | } |
505 | 505 | |
506 | 506 | // Confirm if the provided country and the ip country are similar. |
507 | - $address_confirmed = $this->get_field( 'confirm-address' ); |
|
508 | - if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
509 | - throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
507 | + $address_confirmed = $this->get_field('confirm-address'); |
|
508 | + if (isset($_POST['billing']['country']) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty($address_confirmed)) { |
|
509 | + throw new Exception(__('The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing')); |
|
510 | 510 | } |
511 | 511 | |
512 | 512 | // Abort if the country is not taxable. |
513 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
513 | + if (!wpinv_is_country_taxable($this->country)) { |
|
514 | 514 | return; |
515 | 515 | } |
516 | 516 | |
517 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
517 | + $processor = new GetPaid_Payment_Form_Submission_Taxes($this); |
|
518 | 518 | |
519 | - foreach ( $processor->taxes as $tax ) { |
|
520 | - $this->add_tax( $tax ); |
|
519 | + foreach ($processor->taxes as $tax) { |
|
520 | + $this->add_tax($tax); |
|
521 | 521 | } |
522 | 522 | |
523 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
523 | + do_action_ref_array('getpaid_submissions_process_taxes', array(&$this)); |
|
524 | 524 | } |
525 | 525 | |
526 | 526 | /** |
@@ -529,16 +529,16 @@ discard block |
||
529 | 529 | * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
530 | 530 | * @since 1.0.19 |
531 | 531 | */ |
532 | - public function add_tax( $tax ) { |
|
532 | + public function add_tax($tax) { |
|
533 | 533 | |
534 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
535 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
536 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
534 | + if (wpinv_round_tax_per_tax_rate()) { |
|
535 | + $tax['initial_tax'] = wpinv_round_amount($tax['initial_tax']); |
|
536 | + $tax['recurring_tax'] = wpinv_round_amount($tax['recurring_tax']); |
|
537 | 537 | } |
538 | 538 | |
539 | - $this->taxes[ $tax['name'] ] = $tax; |
|
540 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
541 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
539 | + $this->taxes[$tax['name']] = $tax; |
|
540 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount($tax['initial_tax']); |
|
541 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount($tax['recurring_tax']); |
|
542 | 542 | |
543 | 543 | } |
544 | 544 | |
@@ -547,12 +547,12 @@ discard block |
||
547 | 547 | * |
548 | 548 | * @since 1.0.19 |
549 | 549 | */ |
550 | - public function remove_tax( $tax_name ) { |
|
550 | + public function remove_tax($tax_name) { |
|
551 | 551 | |
552 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
553 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
554 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
555 | - unset( $this->taxes[ $tax_name ] ); |
|
552 | + if (isset($this->taxes[$tax_name])) { |
|
553 | + $this->totals['taxes']['initial'] -= $this->taxes[$tax_name]['initial_tax']; |
|
554 | + $this->totals['taxes']['recurring'] -= $this->taxes[$tax_name]['recurring_tax']; |
|
555 | + unset($this->taxes[$tax_name]); |
|
556 | 556 | } |
557 | 557 | |
558 | 558 | } |
@@ -566,11 +566,11 @@ discard block |
||
566 | 566 | |
567 | 567 | $use_taxes = wpinv_use_taxes(); |
568 | 568 | |
569 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
569 | + if ($this->has_invoice() && !$this->invoice->is_taxable()) { |
|
570 | 570 | $use_taxes = false; |
571 | 571 | } |
572 | 572 | |
573 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
573 | + return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this); |
|
574 | 574 | |
575 | 575 | } |
576 | 576 | |
@@ -619,13 +619,13 @@ discard block |
||
619 | 619 | |
620 | 620 | $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
621 | 621 | $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
622 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
622 | + $processor = new GetPaid_Payment_Form_Submission_Discount($this, $initial_total, $recurring_total); |
|
623 | 623 | |
624 | - foreach ( $processor->discounts as $discount ) { |
|
625 | - $this->add_discount( $discount ); |
|
624 | + foreach ($processor->discounts as $discount) { |
|
625 | + $this->add_discount($discount); |
|
626 | 626 | } |
627 | 627 | |
628 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
628 | + do_action_ref_array('getpaid_submissions_process_discounts', array(&$this)); |
|
629 | 629 | } |
630 | 630 | |
631 | 631 | /** |
@@ -634,10 +634,10 @@ discard block |
||
634 | 634 | * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
635 | 635 | * @since 1.0.19 |
636 | 636 | */ |
637 | - public function add_discount( $discount ) { |
|
638 | - $this->discounts[ $discount['name'] ] = $discount; |
|
639 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
640 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
637 | + public function add_discount($discount) { |
|
638 | + $this->discounts[$discount['name']] = $discount; |
|
639 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount($discount['initial_discount']); |
|
640 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount($discount['recurring_discount']); |
|
641 | 641 | } |
642 | 642 | |
643 | 643 | /** |
@@ -645,12 +645,12 @@ discard block |
||
645 | 645 | * |
646 | 646 | * @since 1.0.19 |
647 | 647 | */ |
648 | - public function remove_discount( $name ) { |
|
648 | + public function remove_discount($name) { |
|
649 | 649 | |
650 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
651 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
652 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
653 | - unset( $this->discounts[ $name ] ); |
|
650 | + if (isset($this->discounts[$name])) { |
|
651 | + $this->totals['discount']['initial'] -= $this->discounts[$name]['initial_discount']; |
|
652 | + $this->totals['discount']['recurring'] -= $this->discounts[$name]['recurring_discount']; |
|
653 | + unset($this->discounts[$name]); |
|
654 | 654 | } |
655 | 655 | |
656 | 656 | } |
@@ -662,7 +662,7 @@ discard block |
||
662 | 662 | * @return bool |
663 | 663 | */ |
664 | 664 | public function has_discount_code() { |
665 | - return ! empty( $this->discounts['discount_code'] ); |
|
665 | + return !empty($this->discounts['discount_code']); |
|
666 | 666 | } |
667 | 667 | |
668 | 668 | /** |
@@ -719,13 +719,13 @@ discard block |
||
719 | 719 | */ |
720 | 720 | public function process_fees() { |
721 | 721 | |
722 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
722 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees($this); |
|
723 | 723 | |
724 | - foreach ( $fees_processor->fees as $fee ) { |
|
725 | - $this->add_fee( $fee ); |
|
724 | + foreach ($fees_processor->fees as $fee) { |
|
725 | + $this->add_fee($fee); |
|
726 | 726 | } |
727 | 727 | |
728 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
728 | + do_action_ref_array('getpaid_submissions_process_fees', array(&$this)); |
|
729 | 729 | } |
730 | 730 | |
731 | 731 | /** |
@@ -734,17 +734,17 @@ discard block |
||
734 | 734 | * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
735 | 735 | * @since 1.0.19 |
736 | 736 | */ |
737 | - public function add_fee( $fee ) { |
|
737 | + public function add_fee($fee) { |
|
738 | 738 | |
739 | - if ( $fee['name'] == 'shipping' ) { |
|
740 | - $this->totals['shipping']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
741 | - $this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
739 | + if ($fee['name'] == 'shipping') { |
|
740 | + $this->totals['shipping']['initial'] += wpinv_sanitize_amount($fee['initial_fee']); |
|
741 | + $this->totals['shipping']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']); |
|
742 | 742 | return; |
743 | 743 | } |
744 | 744 | |
745 | - $this->fees[ $fee['name'] ] = $fee; |
|
746 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
747 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
745 | + $this->fees[$fee['name']] = $fee; |
|
746 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount($fee['initial_fee']); |
|
747 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']); |
|
748 | 748 | |
749 | 749 | } |
750 | 750 | |
@@ -753,15 +753,15 @@ discard block |
||
753 | 753 | * |
754 | 754 | * @since 1.0.19 |
755 | 755 | */ |
756 | - public function remove_fee( $name ) { |
|
756 | + public function remove_fee($name) { |
|
757 | 757 | |
758 | - if ( isset( $this->fees[ $name ] ) ) { |
|
759 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
760 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
761 | - unset( $this->fees[ $name ] ); |
|
758 | + if (isset($this->fees[$name])) { |
|
759 | + $this->totals['fees']['initial'] -= $this->fees[$name]['initial_fee']; |
|
760 | + $this->totals['fees']['recurring'] -= $this->fees[$name]['recurring_fee']; |
|
761 | + unset($this->fees[$name]); |
|
762 | 762 | } |
763 | 763 | |
764 | - if ( 'shipping' == $name ) { |
|
764 | + if ('shipping' == $name) { |
|
765 | 765 | $this->totals['shipping']['initial'] = 0; |
766 | 766 | $this->totals['shipping']['recurring'] = 0; |
767 | 767 | } |
@@ -802,7 +802,7 @@ discard block |
||
802 | 802 | * @since 1.0.19 |
803 | 803 | */ |
804 | 804 | public function has_fees() { |
805 | - return count( $this->fees ) !== 0; |
|
805 | + return count($this->fees) !== 0; |
|
806 | 806 | } |
807 | 807 | |
808 | 808 | /* |
@@ -838,7 +838,7 @@ discard block |
||
838 | 838 | * @since 1.0.19 |
839 | 839 | */ |
840 | 840 | public function has_shipping() { |
841 | - return apply_filters( 'getpaid_payment_form_has_shipping', false, $this ); |
|
841 | + return apply_filters('getpaid_payment_form_has_shipping', false, $this); |
|
842 | 842 | } |
843 | 843 | |
844 | 844 | /** |
@@ -848,7 +848,7 @@ discard block |
||
848 | 848 | * @since 1.0.19 |
849 | 849 | */ |
850 | 850 | public function is_initial_fetch() { |
851 | - return isset( $this->data['initial_state'] ) && empty( $this->data['initial_state'] ); |
|
851 | + return isset($this->data['initial_state']) && empty($this->data['initial_state']); |
|
852 | 852 | } |
853 | 853 | |
854 | 854 | /** |
@@ -858,7 +858,7 @@ discard block |
||
858 | 858 | */ |
859 | 859 | public function get_total() { |
860 | 860 | $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount(); |
861 | - return max( $total, 0 ); |
|
861 | + return max($total, 0); |
|
862 | 862 | } |
863 | 863 | |
864 | 864 | /** |
@@ -868,7 +868,7 @@ discard block |
||
868 | 868 | */ |
869 | 869 | public function get_recurring_total() { |
870 | 870 | $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount(); |
871 | - return max( $total, 0 ); |
|
871 | + return max($total, 0); |
|
872 | 872 | } |
873 | 873 | |
874 | 874 | /** |
@@ -880,12 +880,12 @@ discard block |
||
880 | 880 | $initial = $this->get_total(); |
881 | 881 | $recurring = $this->get_recurring_total(); |
882 | 882 | |
883 | - if ( $this->has_recurring == 0 ) { |
|
883 | + if ($this->has_recurring == 0) { |
|
884 | 884 | $recurring = 0; |
885 | 885 | } |
886 | 886 | |
887 | 887 | $collect = $initial > 0 || $recurring > 0; |
888 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
888 | + return apply_filters('getpaid_submission_should_collect_payment_details', $collect, $this); |
|
889 | 889 | } |
890 | 890 | |
891 | 891 | /** |
@@ -894,7 +894,7 @@ discard block |
||
894 | 894 | * @since 1.0.19 |
895 | 895 | */ |
896 | 896 | public function get_billing_email() { |
897 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
897 | + return apply_filters('getpaid_get_submission_billing_email', $this->get_field('billing_email'), $this); |
|
898 | 898 | } |
899 | 899 | |
900 | 900 | /** |
@@ -904,7 +904,7 @@ discard block |
||
904 | 904 | */ |
905 | 905 | public function has_billing_email() { |
906 | 906 | $billing_email = $this->get_billing_email(); |
907 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
907 | + return !empty($billing_email) && is_email($billing_email); |
|
908 | 908 | } |
909 | 909 | |
910 | 910 | /** |
@@ -934,8 +934,8 @@ discard block |
||
934 | 934 | * @since 1.0.19 |
935 | 935 | * @return mixed|null |
936 | 936 | */ |
937 | - public function get_field( $field, $sub_array_key = null ) { |
|
938 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
937 | + public function get_field($field, $sub_array_key = null) { |
|
938 | + return getpaid_get_array_field($this->data, $field, $sub_array_key); |
|
939 | 939 | } |
940 | 940 | |
941 | 941 | /** |
@@ -943,8 +943,8 @@ discard block |
||
943 | 943 | * |
944 | 944 | * @since 1.0.19 |
945 | 945 | */ |
946 | - public function is_required_field_set( $field ) { |
|
947 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
946 | + public function is_required_field_set($field) { |
|
947 | + return empty($field['required']) || !empty($this->data[$field['id']]); |
|
948 | 948 | } |
949 | 949 | |
950 | 950 | /** |
@@ -952,8 +952,8 @@ discard block |
||
952 | 952 | * |
953 | 953 | * @since 1.0.19 |
954 | 954 | */ |
955 | - public function format_amount( $amount ) { |
|
956 | - return wpinv_price( $amount, $this->get_currency() ); |
|
955 | + public function format_amount($amount) { |
|
956 | + return wpinv_price($amount, $this->get_currency()); |
|
957 | 957 | } |
958 | 958 | |
959 | 959 | } |
@@ -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 | * Are we supporting item quantities? |
@@ -20,35 +20,35 @@ discard block |
||
20 | 20 | */ |
21 | 21 | function wpinv_get_ip() { |
22 | 22 | |
23 | - if ( isset( $_SERVER['HTTP_X_REAL_IP'] ) ) { |
|
24 | - return sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_REAL_IP'] ) ); |
|
23 | + if (isset($_SERVER['HTTP_X_REAL_IP'])) { |
|
24 | + return sanitize_text_field(wp_unslash($_SERVER['HTTP_X_REAL_IP'])); |
|
25 | 25 | } |
26 | 26 | |
27 | - if ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { |
|
27 | + if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|
28 | 28 | // Proxy servers can send through this header like this: X-Forwarded-For: client1, proxy1, proxy2 |
29 | 29 | // Make sure we always only send through the first IP in the list which should always be the client IP. |
30 | - return (string) rest_is_ip_address( trim( current( preg_split( '/,/', sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) ) ) ) ); |
|
30 | + return (string) rest_is_ip_address(trim(current(preg_split('/,/', sanitize_text_field(wp_unslash($_SERVER['HTTP_X_FORWARDED_FOR'])))))); |
|
31 | 31 | } |
32 | 32 | |
33 | - if ( isset( $_SERVER['HTTP_CLIENT_IP'] ) ) { |
|
34 | - return sanitize_text_field( wp_unslash( $_SERVER['HTTP_CLIENT_IP'] ) ); |
|
33 | + if (isset($_SERVER['HTTP_CLIENT_IP'])) { |
|
34 | + return sanitize_text_field(wp_unslash($_SERVER['HTTP_CLIENT_IP'])); |
|
35 | 35 | } |
36 | 36 | |
37 | - if ( isset( $_SERVER['REMOTE_ADDR'] ) ) { |
|
38 | - return sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ); |
|
37 | + if (isset($_SERVER['REMOTE_ADDR'])) { |
|
38 | + return sanitize_text_field(wp_unslash($_SERVER['REMOTE_ADDR'])); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | return ''; |
42 | 42 | } |
43 | 43 | |
44 | 44 | function wpinv_get_user_agent() { |
45 | - if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
|
46 | - $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] ); |
|
45 | + if (!empty($_SERVER['HTTP_USER_AGENT'])) { |
|
46 | + $user_agent = sanitize_text_field($_SERVER['HTTP_USER_AGENT']); |
|
47 | 47 | } else { |
48 | 48 | $user_agent = ''; |
49 | 49 | } |
50 | 50 | |
51 | - return apply_filters( 'wpinv_get_user_agent', $user_agent ); |
|
51 | + return apply_filters('wpinv_get_user_agent', $user_agent); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
@@ -57,16 +57,16 @@ discard block |
||
57 | 57 | * @param string $amount The amount to sanitize. |
58 | 58 | * @return float |
59 | 59 | */ |
60 | -function getpaid_standardize_amount( $amount ) { |
|
60 | +function getpaid_standardize_amount($amount) { |
|
61 | 61 | |
62 | - $amount = str_replace( wpinv_thousands_separator(), '', $amount ); |
|
63 | - $amount = str_replace( wpinv_decimal_separator(), '.', $amount ); |
|
64 | - if ( is_numeric( $amount ) ) { |
|
65 | - return floatval( $amount ); |
|
62 | + $amount = str_replace(wpinv_thousands_separator(), '', $amount); |
|
63 | + $amount = str_replace(wpinv_decimal_separator(), '.', $amount); |
|
64 | + if (is_numeric($amount)) { |
|
65 | + return floatval($amount); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | // Cast the remaining to a float. |
69 | - return wpinv_round_amount( preg_replace( '/[^0-9\.\-]/', '', $amount ) ); |
|
69 | + return wpinv_round_amount(preg_replace('/[^0-9\.\-]/', '', $amount)); |
|
70 | 70 | |
71 | 71 | } |
72 | 72 | |
@@ -75,8 +75,8 @@ discard block |
||
75 | 75 | * |
76 | 76 | * @param string $amount The amount to sanitize. |
77 | 77 | */ |
78 | -function getpaid_unstandardize_amount( $amount ) { |
|
79 | - return str_replace( '.', wpinv_decimal_separator(), $amount ); |
|
78 | +function getpaid_unstandardize_amount($amount) { |
|
79 | + return str_replace('.', wpinv_decimal_separator(), $amount); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
@@ -84,24 +84,24 @@ discard block |
||
84 | 84 | * |
85 | 85 | * @param string $amount The amount to sanitize. |
86 | 86 | */ |
87 | -function wpinv_sanitize_amount( $amount ) { |
|
87 | +function wpinv_sanitize_amount($amount) { |
|
88 | 88 | |
89 | - if ( is_numeric( $amount ) ) { |
|
90 | - return floatval( $amount ); |
|
89 | + if (is_numeric($amount)) { |
|
90 | + return floatval($amount); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | // Separate the decimals and thousands. |
94 | - $amount = empty( $amount ) ? '0' : (string) $amount; |
|
95 | - $amount = explode( wpinv_decimal_separator(), $amount ); |
|
94 | + $amount = empty($amount) ? '0' : (string) $amount; |
|
95 | + $amount = explode(wpinv_decimal_separator(), $amount); |
|
96 | 96 | |
97 | 97 | // Remove thousands. |
98 | - $amount[0] = str_replace( wpinv_thousands_separator(), '', $amount[0] ); |
|
98 | + $amount[0] = str_replace(wpinv_thousands_separator(), '', $amount[0]); |
|
99 | 99 | |
100 | 100 | // Convert back to string. |
101 | - $amount = count( $amount ) > 1 ? "{$amount[0]}.{$amount[1]}" : $amount[0]; |
|
101 | + $amount = count($amount) > 1 ? "{$amount[0]}.{$amount[1]}" : $amount[0]; |
|
102 | 102 | |
103 | 103 | // Cast the remaining to a float. |
104 | - return (float) preg_replace( '/[^0-9\.\-]/', '', $amount ); |
|
104 | + return (float) preg_replace('/[^0-9\.\-]/', '', $amount); |
|
105 | 105 | |
106 | 106 | } |
107 | 107 | |
@@ -111,19 +111,19 @@ discard block |
||
111 | 111 | * @param float $amount |
112 | 112 | * @param float|string|int|null $decimals |
113 | 113 | */ |
114 | -function wpinv_round_amount( $amount, $decimals = null, $use_sprintf = false ) { |
|
114 | +function wpinv_round_amount($amount, $decimals = null, $use_sprintf = false) { |
|
115 | 115 | |
116 | - if ( $decimals === null ) { |
|
116 | + if ($decimals === null) { |
|
117 | 117 | $decimals = wpinv_decimals(); |
118 | 118 | } |
119 | 119 | |
120 | - if ( $use_sprintf ) { |
|
121 | - $amount = sprintf( "%.{$decimals}f", (float) $amount ); |
|
120 | + if ($use_sprintf) { |
|
121 | + $amount = sprintf("%.{$decimals}f", (float) $amount); |
|
122 | 122 | } else { |
123 | - $amount = round( (float) $amount, absint( $decimals ) ); |
|
123 | + $amount = round((float) $amount, absint($decimals)); |
|
124 | 124 | } |
125 | 125 | |
126 | - return apply_filters( 'wpinv_round_amount', $amount, $decimals ); |
|
126 | + return apply_filters('wpinv_round_amount', $amount, $decimals); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
@@ -135,32 +135,32 @@ discard block |
||
135 | 135 | * @param string|WPInv_Invoice $invoice The invoice object|post type|type |
136 | 136 | * @return array |
137 | 137 | */ |
138 | -function wpinv_get_invoice_statuses( $draft = false, $trashed = false, $invoice = false ) { |
|
138 | +function wpinv_get_invoice_statuses($draft = false, $trashed = false, $invoice = false) { |
|
139 | 139 | |
140 | 140 | $invoice_statuses = array( |
141 | - 'wpi-pending' => _x( 'Pending payment', 'Invoice status', 'invoicing' ), |
|
142 | - 'publish' => _x( 'Paid', 'Invoice status', 'invoicing' ), |
|
143 | - 'wpi-processing' => _x( 'Processing', 'Invoice status', 'invoicing' ), |
|
144 | - 'wpi-onhold' => _x( 'On hold', 'Invoice status', 'invoicing' ), |
|
145 | - 'wpi-cancelled' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
146 | - 'wpi-refunded' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
147 | - 'wpi-failed' => _x( 'Failed', 'Invoice status', 'invoicing' ), |
|
148 | - 'wpi-renewal' => _x( 'Renewal Payment', 'Invoice status', 'invoicing' ), |
|
141 | + 'wpi-pending' => _x('Pending payment', 'Invoice status', 'invoicing'), |
|
142 | + 'publish' => _x('Paid', 'Invoice status', 'invoicing'), |
|
143 | + 'wpi-processing' => _x('Processing', 'Invoice status', 'invoicing'), |
|
144 | + 'wpi-onhold' => _x('On hold', 'Invoice status', 'invoicing'), |
|
145 | + 'wpi-cancelled' => _x('Cancelled', 'Invoice status', 'invoicing'), |
|
146 | + 'wpi-refunded' => _x('Refunded', 'Invoice status', 'invoicing'), |
|
147 | + 'wpi-failed' => _x('Failed', 'Invoice status', 'invoicing'), |
|
148 | + 'wpi-renewal' => _x('Renewal Payment', 'Invoice status', 'invoicing'), |
|
149 | 149 | ); |
150 | 150 | |
151 | - if ( $draft ) { |
|
152 | - $invoice_statuses['draft'] = __( 'Draft', 'invoicing' ); |
|
151 | + if ($draft) { |
|
152 | + $invoice_statuses['draft'] = __('Draft', 'invoicing'); |
|
153 | 153 | } |
154 | 154 | |
155 | - if ( $trashed ) { |
|
156 | - $invoice_statuses['trash'] = __( 'Trash', 'invoicing' ); |
|
155 | + if ($trashed) { |
|
156 | + $invoice_statuses['trash'] = __('Trash', 'invoicing'); |
|
157 | 157 | } |
158 | 158 | |
159 | - if ( $invoice instanceof WPInv_Invoice ) { |
|
159 | + if ($invoice instanceof WPInv_Invoice) { |
|
160 | 160 | $invoice = $invoice->get_post_type(); |
161 | 161 | } |
162 | 162 | |
163 | - return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice ); |
|
163 | + return apply_filters('wpinv_statuses', $invoice_statuses, $invoice); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | /** |
@@ -169,11 +169,11 @@ discard block |
||
169 | 169 | * @param string $status The raw status |
170 | 170 | * @param string|WPInv_Invoice $invoice The invoice object|post type|type |
171 | 171 | */ |
172 | -function wpinv_status_nicename( $status, $invoice = false ) { |
|
173 | - $statuses = wpinv_get_invoice_statuses( true, true, $invoice ); |
|
174 | - $status = isset( $statuses[ $status ] ) ? $statuses[ $status ] : $status; |
|
172 | +function wpinv_status_nicename($status, $invoice = false) { |
|
173 | + $statuses = wpinv_get_invoice_statuses(true, true, $invoice); |
|
174 | + $status = isset($statuses[$status]) ? $statuses[$status] : $status; |
|
175 | 175 | |
176 | - return sanitize_text_field( $status ); |
|
176 | + return sanitize_text_field($status); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | /** |
@@ -181,13 +181,13 @@ discard block |
||
181 | 181 | * |
182 | 182 | * @param string $current |
183 | 183 | */ |
184 | -function wpinv_get_currency( $current = '' ) { |
|
184 | +function wpinv_get_currency($current = '') { |
|
185 | 185 | |
186 | - if ( empty( $current ) ) { |
|
187 | - $current = apply_filters( 'wpinv_currency', wpinv_get_option( 'currency', 'USD' ) ); |
|
186 | + if (empty($current)) { |
|
187 | + $current = apply_filters('wpinv_currency', wpinv_get_option('currency', 'USD')); |
|
188 | 188 | } |
189 | 189 | |
190 | - return trim( strtoupper( $current ) ); |
|
190 | + return trim(strtoupper($current)); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | /** |
@@ -195,25 +195,25 @@ discard block |
||
195 | 195 | * |
196 | 196 | * @param string|null $currency The currency code. Defaults to the default currency. |
197 | 197 | */ |
198 | -function wpinv_currency_symbol( $currency = null ) { |
|
198 | +function wpinv_currency_symbol($currency = null) { |
|
199 | 199 | |
200 | 200 | // Prepare the currency. |
201 | - $currency = empty( $currency ) ? wpinv_get_currency() : wpinv_clean( $currency ); |
|
201 | + $currency = empty($currency) ? wpinv_get_currency() : wpinv_clean($currency); |
|
202 | 202 | |
203 | 203 | // Fetch all symbols. |
204 | 204 | $symbols = wpinv_get_currency_symbols(); |
205 | 205 | |
206 | 206 | // Fetch this currencies symbol. |
207 | - $currency_symbol = isset( $symbols[ $currency ] ) ? $symbols[ $currency ] : $currency; |
|
207 | + $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : $currency; |
|
208 | 208 | |
209 | 209 | // Filter the symbol. |
210 | - return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency ); |
|
210 | + return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | function wpinv_currency_position() { |
214 | - $position = wpinv_get_option( 'currency_position', 'left' ); |
|
214 | + $position = wpinv_get_option('currency_position', 'left'); |
|
215 | 215 | |
216 | - return apply_filters( 'wpinv_currency_position', $position ); |
|
216 | + return apply_filters('wpinv_currency_position', $position); |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | /** |
@@ -221,13 +221,13 @@ discard block |
||
221 | 221 | * |
222 | 222 | * @param $string|null $current |
223 | 223 | */ |
224 | -function wpinv_thousands_separator( $current = null ) { |
|
224 | +function wpinv_thousands_separator($current = null) { |
|
225 | 225 | |
226 | - if ( null == $current ) { |
|
227 | - $current = wpinv_get_option( 'thousands_separator', ',' ); |
|
226 | + if (null == $current) { |
|
227 | + $current = wpinv_get_option('thousands_separator', ','); |
|
228 | 228 | } |
229 | 229 | |
230 | - return trim( $current ); |
|
230 | + return trim($current); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | /** |
@@ -235,13 +235,13 @@ discard block |
||
235 | 235 | * |
236 | 236 | * @param $string|null $current |
237 | 237 | */ |
238 | -function wpinv_decimal_separator( $current = null ) { |
|
238 | +function wpinv_decimal_separator($current = null) { |
|
239 | 239 | |
240 | - if ( null == $current ) { |
|
241 | - $current = wpinv_get_option( 'decimal_separator', '.' ); |
|
240 | + if (null == $current) { |
|
241 | + $current = wpinv_get_option('decimal_separator', '.'); |
|
242 | 242 | } |
243 | 243 | |
244 | - return trim( $current ); |
|
244 | + return trim($current); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | /** |
@@ -249,27 +249,27 @@ discard block |
||
249 | 249 | * |
250 | 250 | * @param $string|null $current |
251 | 251 | */ |
252 | -function wpinv_decimals( $current = null ) { |
|
252 | +function wpinv_decimals($current = null) { |
|
253 | 253 | |
254 | - if ( null == $current ) { |
|
255 | - $current = wpinv_get_option( 'decimals', 2 ); |
|
254 | + if (null == $current) { |
|
255 | + $current = wpinv_get_option('decimals', 2); |
|
256 | 256 | } |
257 | 257 | |
258 | - return absint( $current ); |
|
258 | + return absint($current); |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | /** |
262 | 262 | * Retrieves a list of all supported currencies. |
263 | 263 | */ |
264 | 264 | function wpinv_get_currencies() { |
265 | - return apply_filters( 'wpinv_currencies', wpinv_get_data( 'currencies' ) ); |
|
265 | + return apply_filters('wpinv_currencies', wpinv_get_data('currencies')); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | /** |
269 | 269 | * Retrieves a list of all currency symbols. |
270 | 270 | */ |
271 | 271 | function wpinv_get_currency_symbols() { |
272 | - return apply_filters( 'wpinv_currency_symbols', wpinv_get_data( 'currency-symbols' ) ); |
|
272 | + return apply_filters('wpinv_currency_symbols', wpinv_get_data('currency-symbols')); |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | /** |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | $currency_pos = wpinv_currency_position(); |
282 | 282 | $format = '%1$s%2$s'; |
283 | 283 | |
284 | - switch ( $currency_pos ) { |
|
284 | + switch ($currency_pos) { |
|
285 | 285 | case 'left': |
286 | 286 | $format = '%1$s%2$s'; |
287 | 287 | break; |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | break; |
297 | 297 | } |
298 | 298 | |
299 | - return apply_filters( 'getpaid_price_format', $format, $currency_pos ); |
|
299 | + return apply_filters('getpaid_price_format', $format, $currency_pos); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | /** |
@@ -306,8 +306,8 @@ discard block |
||
306 | 306 | * @param string $currency Currency. |
307 | 307 | * @return string |
308 | 308 | */ |
309 | -function wpinv_the_price( $amount = 0, $currency = '' ) { |
|
310 | - echo wp_kses_post( wpinv_price( $amount, $currency ) ); |
|
309 | +function wpinv_the_price($amount = 0, $currency = '') { |
|
310 | + echo wp_kses_post(wpinv_price($amount, $currency)); |
|
311 | 311 | } |
312 | 312 | |
313 | 313 | /** |
@@ -317,25 +317,25 @@ discard block |
||
317 | 317 | * @param string $currency Currency. |
318 | 318 | * @return string |
319 | 319 | */ |
320 | -function wpinv_price( $amount = 0, $currency = '' ) { |
|
320 | +function wpinv_price($amount = 0, $currency = '') { |
|
321 | 321 | |
322 | 322 | // Backwards compatibility. |
323 | - $amount = wpinv_sanitize_amount( $amount ); |
|
323 | + $amount = wpinv_sanitize_amount($amount); |
|
324 | 324 | |
325 | 325 | // Prepare variables. |
326 | - $currency = wpinv_get_currency( $currency ); |
|
326 | + $currency = wpinv_get_currency($currency); |
|
327 | 327 | $amount = (float) $amount; |
328 | 328 | $unformatted_amount = $amount; |
329 | 329 | $negative = $amount < 0; |
330 | - $amount = apply_filters( 'getpaid_raw_amount', floatval( $negative ? $amount * -1 : $amount ) ); |
|
331 | - $amount = wpinv_format_amount( $amount ); |
|
330 | + $amount = apply_filters('getpaid_raw_amount', floatval($negative ? $amount * -1 : $amount)); |
|
331 | + $amount = wpinv_format_amount($amount); |
|
332 | 332 | |
333 | 333 | // Format the amount. |
334 | 334 | $format = getpaid_get_price_format(); |
335 | - $formatted_amount = ( $negative ? '-' : '' ) . sprintf( $format, '<span class="getpaid-currency__symbol">' . wpinv_currency_symbol( $currency ) . '</span>', $amount ); |
|
335 | + $formatted_amount = ($negative ? '-' : '') . sprintf($format, '<span class="getpaid-currency__symbol">' . wpinv_currency_symbol($currency) . '</span>', $amount); |
|
336 | 336 | |
337 | 337 | // Filter the formatting. |
338 | - return apply_filters( 'wpinv_price', $formatted_amount, $amount, $currency, $unformatted_amount ); |
|
338 | + return apply_filters('wpinv_price', $formatted_amount, $amount, $currency, $unformatted_amount); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | /** |
@@ -346,25 +346,25 @@ discard block |
||
346 | 346 | * @param bool $calculate Whether or not to apply separators. |
347 | 347 | * @return string |
348 | 348 | */ |
349 | -function wpinv_format_amount( $amount, $decimals = null, $calculate = false ) { |
|
349 | +function wpinv_format_amount($amount, $decimals = null, $calculate = false) { |
|
350 | 350 | $thousands_sep = wpinv_thousands_separator(); |
351 | 351 | $decimal_sep = wpinv_decimal_separator(); |
352 | - $decimals = wpinv_decimals( $decimals ); |
|
353 | - $amount = wpinv_sanitize_amount( $amount ); |
|
352 | + $decimals = wpinv_decimals($decimals); |
|
353 | + $amount = wpinv_sanitize_amount($amount); |
|
354 | 354 | |
355 | - if ( $calculate ) { |
|
355 | + if ($calculate) { |
|
356 | 356 | return $amount; |
357 | 357 | } |
358 | 358 | |
359 | 359 | // Fomart the amount. |
360 | - return number_format( $amount, $decimals, $decimal_sep, $thousands_sep ); |
|
360 | + return number_format($amount, $decimals, $decimal_sep, $thousands_sep); |
|
361 | 361 | } |
362 | 362 | |
363 | -function wpinv_sanitize_key( $key ) { |
|
363 | +function wpinv_sanitize_key($key) { |
|
364 | 364 | $raw_key = $key; |
365 | - $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key ); |
|
365 | + $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key); |
|
366 | 366 | |
367 | - return apply_filters( 'wpinv_sanitize_key', $key, $raw_key ); |
|
367 | + return apply_filters('wpinv_sanitize_key', $key, $raw_key); |
|
368 | 368 | } |
369 | 369 | |
370 | 370 | /** |
@@ -372,8 +372,8 @@ discard block |
||
372 | 372 | * |
373 | 373 | * @param $str the file whose extension should be retrieved. |
374 | 374 | */ |
375 | -function wpinv_get_file_extension( $str ) { |
|
376 | - $filetype = wp_check_filetype( $str ); |
|
375 | +function wpinv_get_file_extension($str) { |
|
376 | + $filetype = wp_check_filetype($str); |
|
377 | 377 | return $filetype['ext']; |
378 | 378 | } |
379 | 379 | |
@@ -382,16 +382,16 @@ discard block |
||
382 | 382 | * |
383 | 383 | * @param string $string |
384 | 384 | */ |
385 | -function wpinv_string_is_image_url( $string ) { |
|
386 | - $extension = strtolower( wpinv_get_file_extension( $string ) ); |
|
387 | - return in_array( $extension, array( 'jpeg', 'jpg', 'png', 'gif', 'ico' ), true ); |
|
385 | +function wpinv_string_is_image_url($string) { |
|
386 | + $extension = strtolower(wpinv_get_file_extension($string)); |
|
387 | + return in_array($extension, array('jpeg', 'jpg', 'png', 'gif', 'ico'), true); |
|
388 | 388 | } |
389 | 389 | |
390 | 390 | /** |
391 | 391 | * Returns the current URL. |
392 | 392 | */ |
393 | 393 | function wpinv_get_current_page_url() { |
394 | - return esc_url( add_query_arg( array() ) ); |
|
394 | + return esc_url(add_query_arg(array())); |
|
395 | 395 | } |
396 | 396 | |
397 | 397 | /** |
@@ -401,46 +401,46 @@ discard block |
||
401 | 401 | * @param string $name Constant name. |
402 | 402 | * @param mixed $value Value. |
403 | 403 | */ |
404 | -function getpaid_maybe_define_constant( $name, $value ) { |
|
405 | - if ( ! defined( $name ) ) { |
|
406 | - define( $name, $value ); |
|
404 | +function getpaid_maybe_define_constant($name, $value) { |
|
405 | + if (!defined($name)) { |
|
406 | + define($name, $value); |
|
407 | 407 | } |
408 | 408 | } |
409 | 409 | |
410 | 410 | function wpinv_get_php_arg_separator_output() { |
411 | - return ini_get( 'arg_separator.output' ); |
|
411 | + return ini_get('arg_separator.output'); |
|
412 | 412 | } |
413 | 413 | |
414 | -function wpinv_rgb_from_hex( $color ) { |
|
415 | - $color = str_replace( '#', '', $color ); |
|
414 | +function wpinv_rgb_from_hex($color) { |
|
415 | + $color = str_replace('#', '', $color); |
|
416 | 416 | |
417 | 417 | // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF" |
418 | - $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color ); |
|
419 | - if ( empty( $color ) ) { |
|
418 | + $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color); |
|
419 | + if (empty($color)) { |
|
420 | 420 | return null; |
421 | 421 | } |
422 | 422 | |
423 | - $color = str_split( $color ); |
|
423 | + $color = str_split($color); |
|
424 | 424 | |
425 | 425 | $rgb = array(); |
426 | - $rgb['R'] = hexdec( $color[0] . $color[1] ); |
|
427 | - $rgb['G'] = hexdec( $color[2] . $color[3] ); |
|
428 | - $rgb['B'] = hexdec( $color[4] . $color[5] ); |
|
426 | + $rgb['R'] = hexdec($color[0] . $color[1]); |
|
427 | + $rgb['G'] = hexdec($color[2] . $color[3]); |
|
428 | + $rgb['B'] = hexdec($color[4] . $color[5]); |
|
429 | 429 | |
430 | 430 | return $rgb; |
431 | 431 | } |
432 | 432 | |
433 | -function wpinv_hex_darker( $color, $factor = 30 ) { |
|
434 | - $base = wpinv_rgb_from_hex( $color ); |
|
433 | +function wpinv_hex_darker($color, $factor = 30) { |
|
434 | + $base = wpinv_rgb_from_hex($color); |
|
435 | 435 | $color = '#'; |
436 | 436 | |
437 | - foreach ( $base as $k => $v ) { |
|
437 | + foreach ($base as $k => $v) { |
|
438 | 438 | $amount = $v / 100; |
439 | - $amount = round( $amount * $factor ); |
|
439 | + $amount = round($amount * $factor); |
|
440 | 440 | $new_decimal = $v - $amount; |
441 | 441 | |
442 | - $new_hex_component = dechex( $new_decimal ); |
|
443 | - if ( strlen( $new_hex_component ) < 2 ) { |
|
442 | + $new_hex_component = dechex($new_decimal); |
|
443 | + if (strlen($new_hex_component) < 2) { |
|
444 | 444 | $new_hex_component = '0' . $new_hex_component; |
445 | 445 | } |
446 | 446 | $color .= $new_hex_component; |
@@ -449,18 +449,18 @@ discard block |
||
449 | 449 | return $color; |
450 | 450 | } |
451 | 451 | |
452 | -function wpinv_hex_lighter( $color, $factor = 30 ) { |
|
453 | - $base = wpinv_rgb_from_hex( $color ); |
|
452 | +function wpinv_hex_lighter($color, $factor = 30) { |
|
453 | + $base = wpinv_rgb_from_hex($color); |
|
454 | 454 | $color = '#'; |
455 | 455 | |
456 | - foreach ( $base as $k => $v ) { |
|
456 | + foreach ($base as $k => $v) { |
|
457 | 457 | $amount = 255 - $v; |
458 | 458 | $amount = $amount / 100; |
459 | - $amount = round( $amount * $factor ); |
|
459 | + $amount = round($amount * $factor); |
|
460 | 460 | $new_decimal = $v + $amount; |
461 | 461 | |
462 | - $new_hex_component = dechex( $new_decimal ); |
|
463 | - if ( strlen( $new_hex_component ) < 2 ) { |
|
462 | + $new_hex_component = dechex($new_decimal); |
|
463 | + if (strlen($new_hex_component) < 2) { |
|
464 | 464 | $new_hex_component = '0' . $new_hex_component; |
465 | 465 | } |
466 | 466 | $color .= $new_hex_component; |
@@ -469,22 +469,22 @@ discard block |
||
469 | 469 | return $color; |
470 | 470 | } |
471 | 471 | |
472 | -function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) { |
|
473 | - $hex = str_replace( '#', '', $color ); |
|
472 | +function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') { |
|
473 | + $hex = str_replace('#', '', $color); |
|
474 | 474 | |
475 | - $c_r = hexdec( substr( $hex, 0, 2 ) ); |
|
476 | - $c_g = hexdec( substr( $hex, 2, 2 ) ); |
|
477 | - $c_b = hexdec( substr( $hex, 4, 2 ) ); |
|
475 | + $c_r = hexdec(substr($hex, 0, 2)); |
|
476 | + $c_g = hexdec(substr($hex, 2, 2)); |
|
477 | + $c_b = hexdec(substr($hex, 4, 2)); |
|
478 | 478 | |
479 | - $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000; |
|
479 | + $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000; |
|
480 | 480 | |
481 | 481 | return $brightness > 155 ? $dark : $light; |
482 | 482 | } |
483 | 483 | |
484 | -function wpinv_format_hex( $hex ) { |
|
485 | - $hex = trim( str_replace( '#', '', $hex ) ); |
|
484 | +function wpinv_format_hex($hex) { |
|
485 | + $hex = trim(str_replace('#', '', $hex)); |
|
486 | 486 | |
487 | - if ( strlen( $hex ) == 3 ) { |
|
487 | + if (strlen($hex) == 3) { |
|
488 | 488 | $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2]; |
489 | 489 | } |
490 | 490 | |
@@ -504,12 +504,12 @@ discard block |
||
504 | 504 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
505 | 505 | * @return string |
506 | 506 | */ |
507 | -function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) { |
|
508 | - if ( function_exists( 'mb_strimwidth' ) ) { |
|
509 | - return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding ); |
|
507 | +function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') { |
|
508 | + if (function_exists('mb_strimwidth')) { |
|
509 | + return mb_strimwidth($str, $start, $width, $trimmaker, $encoding); |
|
510 | 510 | } |
511 | 511 | |
512 | - return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker; |
|
512 | + return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker; |
|
513 | 513 | } |
514 | 514 | |
515 | 515 | /** |
@@ -521,28 +521,28 @@ discard block |
||
521 | 521 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
522 | 522 | * @return int Returns the number of characters in string. |
523 | 523 | */ |
524 | -function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) { |
|
525 | - if ( function_exists( 'mb_strlen' ) ) { |
|
526 | - return mb_strlen( $str, $encoding ); |
|
524 | +function wpinv_utf8_strlen($str, $encoding = 'UTF-8') { |
|
525 | + if (function_exists('mb_strlen')) { |
|
526 | + return mb_strlen($str, $encoding); |
|
527 | 527 | } |
528 | 528 | |
529 | - return strlen( $str ); |
|
529 | + return strlen($str); |
|
530 | 530 | } |
531 | 531 | |
532 | -function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) { |
|
533 | - if ( function_exists( 'mb_strtolower' ) ) { |
|
534 | - return mb_strtolower( $str, $encoding ); |
|
532 | +function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') { |
|
533 | + if (function_exists('mb_strtolower')) { |
|
534 | + return mb_strtolower($str, $encoding); |
|
535 | 535 | } |
536 | 536 | |
537 | - return strtolower( $str ); |
|
537 | + return strtolower($str); |
|
538 | 538 | } |
539 | 539 | |
540 | -function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) { |
|
541 | - if ( function_exists( 'mb_strtoupper' ) ) { |
|
542 | - return mb_strtoupper( $str, $encoding ); |
|
540 | +function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') { |
|
541 | + if (function_exists('mb_strtoupper')) { |
|
542 | + return mb_strtoupper($str, $encoding); |
|
543 | 543 | } |
544 | 544 | |
545 | - return strtoupper( $str ); |
|
545 | + return strtoupper($str); |
|
546 | 546 | } |
547 | 547 | |
548 | 548 | /** |
@@ -556,12 +556,12 @@ discard block |
||
556 | 556 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
557 | 557 | * @return int Returns the position of the first occurrence of search in the string. |
558 | 558 | */ |
559 | -function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) { |
|
560 | - if ( function_exists( 'mb_strpos' ) ) { |
|
561 | - return mb_strpos( $str, $find, $offset, $encoding ); |
|
559 | +function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') { |
|
560 | + if (function_exists('mb_strpos')) { |
|
561 | + return mb_strpos($str, $find, $offset, $encoding); |
|
562 | 562 | } |
563 | 563 | |
564 | - return strpos( $str, $find, $offset ); |
|
564 | + return strpos($str, $find, $offset); |
|
565 | 565 | } |
566 | 566 | |
567 | 567 | /** |
@@ -575,12 +575,12 @@ discard block |
||
575 | 575 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
576 | 576 | * @return int Returns the position of the last occurrence of search. |
577 | 577 | */ |
578 | -function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) { |
|
579 | - if ( function_exists( 'mb_strrpos' ) ) { |
|
580 | - return mb_strrpos( $str, $find, $offset, $encoding ); |
|
578 | +function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') { |
|
579 | + if (function_exists('mb_strrpos')) { |
|
580 | + return mb_strrpos($str, $find, $offset, $encoding); |
|
581 | 581 | } |
582 | 582 | |
583 | - return strrpos( $str, $find, $offset ); |
|
583 | + return strrpos($str, $find, $offset); |
|
584 | 584 | } |
585 | 585 | |
586 | 586 | /** |
@@ -595,16 +595,16 @@ discard block |
||
595 | 595 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
596 | 596 | * @return string |
597 | 597 | */ |
598 | -function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) { |
|
599 | - if ( function_exists( 'mb_substr' ) ) { |
|
600 | - if ( null === $length ) { |
|
601 | - return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding ); |
|
598 | +function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') { |
|
599 | + if (function_exists('mb_substr')) { |
|
600 | + if (null === $length) { |
|
601 | + return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding); |
|
602 | 602 | } else { |
603 | - return mb_substr( $str, $start, $length, $encoding ); |
|
603 | + return mb_substr($str, $start, $length, $encoding); |
|
604 | 604 | } |
605 | 605 | } |
606 | 606 | |
607 | - return substr( $str, $start, $length ); |
|
607 | + return substr($str, $start, $length); |
|
608 | 608 | } |
609 | 609 | |
610 | 610 | /** |
@@ -616,48 +616,48 @@ discard block |
||
616 | 616 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
617 | 617 | * @return string The width of string. |
618 | 618 | */ |
619 | -function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) { |
|
620 | - if ( function_exists( 'mb_strwidth' ) ) { |
|
621 | - return mb_strwidth( $str, $encoding ); |
|
619 | +function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') { |
|
620 | + if (function_exists('mb_strwidth')) { |
|
621 | + return mb_strwidth($str, $encoding); |
|
622 | 622 | } |
623 | 623 | |
624 | - return wpinv_utf8_strlen( $str, $encoding ); |
|
624 | + return wpinv_utf8_strlen($str, $encoding); |
|
625 | 625 | } |
626 | 626 | |
627 | -function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) { |
|
628 | - if ( function_exists( 'mb_strlen' ) ) { |
|
629 | - $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding ); |
|
627 | +function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') { |
|
628 | + if (function_exists('mb_strlen')) { |
|
629 | + $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding); |
|
630 | 630 | $str_end = ''; |
631 | 631 | |
632 | - if ( $lower_str_end ) { |
|
633 | - $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding ); |
|
632 | + if ($lower_str_end) { |
|
633 | + $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding); |
|
634 | 634 | } else { |
635 | - $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ); |
|
635 | + $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding); |
|
636 | 636 | } |
637 | 637 | |
638 | 638 | return $first_letter . $str_end; |
639 | 639 | } |
640 | 640 | |
641 | - return ucfirst( $str ); |
|
641 | + return ucfirst($str); |
|
642 | 642 | } |
643 | 643 | |
644 | -function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) { |
|
645 | - if ( function_exists( 'mb_convert_case' ) ) { |
|
646 | - return mb_convert_case( $str, MB_CASE_TITLE, $encoding ); |
|
644 | +function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') { |
|
645 | + if (function_exists('mb_convert_case')) { |
|
646 | + return mb_convert_case($str, MB_CASE_TITLE, $encoding); |
|
647 | 647 | } |
648 | 648 | |
649 | - return ucwords( $str ); |
|
649 | + return ucwords($str); |
|
650 | 650 | } |
651 | 651 | |
652 | -function wpinv_period_in_days( $period, $unit ) { |
|
653 | - $period = absint( $period ); |
|
652 | +function wpinv_period_in_days($period, $unit) { |
|
653 | + $period = absint($period); |
|
654 | 654 | |
655 | - if ( $period > 0 ) { |
|
656 | - if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) { |
|
655 | + if ($period > 0) { |
|
656 | + if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) { |
|
657 | 657 | $period = $period * 7; |
658 | - } elseif ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) { |
|
658 | + } elseif (in_array(strtolower($unit), array('m', 'month', 'months'))) { |
|
659 | 659 | $period = $period * 30; |
660 | - } elseif ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) { |
|
660 | + } elseif (in_array(strtolower($unit), array('y', 'year', 'years'))) { |
|
661 | 661 | $period = $period * 365; |
662 | 662 | } |
663 | 663 | } |
@@ -665,14 +665,14 @@ discard block |
||
665 | 665 | return $period; |
666 | 666 | } |
667 | 667 | |
668 | -function wpinv_cal_days_in_month( $calendar, $month, $year ) { |
|
669 | - if ( function_exists( 'cal_days_in_month' ) ) { |
|
670 | - return cal_days_in_month( $calendar, $month, $year ); |
|
668 | +function wpinv_cal_days_in_month($calendar, $month, $year) { |
|
669 | + if (function_exists('cal_days_in_month')) { |
|
670 | + return cal_days_in_month($calendar, $month, $year); |
|
671 | 671 | } |
672 | 672 | |
673 | 673 | // Fallback in case the calendar extension is not loaded in PHP |
674 | 674 | // Only supports Gregorian calendar |
675 | - return gmdate( 't', mktime( 0, 0, 0, $month, 1, $year ) ); |
|
675 | + return gmdate('t', mktime(0, 0, 0, $month, 1, $year)); |
|
676 | 676 | } |
677 | 677 | |
678 | 678 | /** |
@@ -683,27 +683,27 @@ discard block |
||
683 | 683 | * |
684 | 684 | * @return string |
685 | 685 | */ |
686 | -function wpi_help_tip( $tip, $allow_html = false, $is_vue = false, $echo = false ) { |
|
686 | +function wpi_help_tip($tip, $allow_html = false, $is_vue = false, $echo = false) { |
|
687 | 687 | |
688 | - if ( $allow_html ) { |
|
689 | - $tip = wpi_sanitize_tooltip( $tip ); |
|
688 | + if ($allow_html) { |
|
689 | + $tip = wpi_sanitize_tooltip($tip); |
|
690 | 690 | } else { |
691 | - $tip = strip_tags( $tip ); |
|
691 | + $tip = strip_tags($tip); |
|
692 | 692 | } |
693 | 693 | |
694 | - if ( $is_vue ) { |
|
694 | + if ($is_vue) { |
|
695 | 695 | |
696 | - if ( $echo ) { |
|
697 | - echo '<span class="dashicons dashicons-editor-help" title="' . esc_attr( $tip ) . '"></span>'; |
|
696 | + if ($echo) { |
|
697 | + echo '<span class="dashicons dashicons-editor-help" title="' . esc_attr($tip) . '"></span>'; |
|
698 | 698 | } else { |
699 | - return '<span class="dashicons dashicons-editor-help" title="' . esc_attr( $tip ) . '"></span>'; |
|
699 | + return '<span class="dashicons dashicons-editor-help" title="' . esc_attr($tip) . '"></span>'; |
|
700 | 700 | } |
701 | 701 | } |
702 | 702 | |
703 | - if ( $echo ) { |
|
704 | - echo '<span class="wpi-help-tip dashicons dashicons-editor-help" title="' . esc_attr( $tip ) . '"></span>'; |
|
703 | + if ($echo) { |
|
704 | + echo '<span class="wpi-help-tip dashicons dashicons-editor-help" title="' . esc_attr($tip) . '"></span>'; |
|
705 | 705 | } else { |
706 | - return '<span class="wpi-help-tip dashicons dashicons-editor-help" title="' . esc_attr( $tip ) . '"></span>'; |
|
706 | + return '<span class="wpi-help-tip dashicons dashicons-editor-help" title="' . esc_attr($tip) . '"></span>'; |
|
707 | 707 | } |
708 | 708 | } |
709 | 709 | |
@@ -715,9 +715,9 @@ discard block |
||
715 | 715 | * @param string $var |
716 | 716 | * @return string |
717 | 717 | */ |
718 | -function wpi_sanitize_tooltip( $var ) { |
|
718 | +function wpi_sanitize_tooltip($var) { |
|
719 | 719 | return wp_kses( |
720 | - html_entity_decode( $var ), |
|
720 | + html_entity_decode($var), |
|
721 | 721 | array( |
722 | 722 | 'br' => array(), |
723 | 723 | 'em' => array(), |
@@ -740,7 +740,7 @@ discard block |
||
740 | 740 | */ |
741 | 741 | function wpinv_get_screen_ids() { |
742 | 742 | |
743 | - $screen_id = sanitize_title( __( 'Invoicing', 'invoicing' ) ); |
|
743 | + $screen_id = sanitize_title(__('Invoicing', 'invoicing')); |
|
744 | 744 | |
745 | 745 | $screen_ids = array( |
746 | 746 | 'toplevel_page_' . $screen_id, |
@@ -762,7 +762,7 @@ discard block |
||
762 | 762 | 'gp-setup', // setup wizard |
763 | 763 | ); |
764 | 764 | |
765 | - return apply_filters( 'wpinv_screen_ids', $screen_ids ); |
|
765 | + return apply_filters('wpinv_screen_ids', $screen_ids); |
|
766 | 766 | } |
767 | 767 | |
768 | 768 | /** |
@@ -773,14 +773,14 @@ discard block |
||
773 | 773 | * @param array|string $list List of values. |
774 | 774 | * @return array Sanitized array of values. |
775 | 775 | */ |
776 | -function wpinv_parse_list( $list ) { |
|
776 | +function wpinv_parse_list($list) { |
|
777 | 777 | |
778 | - if ( empty( $list ) ) { |
|
778 | + if (empty($list)) { |
|
779 | 779 | $list = array(); |
780 | 780 | } |
781 | 781 | |
782 | - if ( ! is_array( $list ) ) { |
|
783 | - return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY ); |
|
782 | + if (!is_array($list)) { |
|
783 | + return preg_split('/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY); |
|
784 | 784 | } |
785 | 785 | |
786 | 786 | return $list; |
@@ -794,8 +794,8 @@ discard block |
||
794 | 794 | * @param string $key Type of data to fetch. |
795 | 795 | * @return mixed Fetched data. |
796 | 796 | */ |
797 | -function wpinv_get_data( $key ) { |
|
798 | - return apply_filters( "wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php" ); |
|
797 | +function wpinv_get_data($key) { |
|
798 | + return apply_filters("wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php"); |
|
799 | 799 | } |
800 | 800 | |
801 | 801 | /** |
@@ -807,10 +807,10 @@ discard block |
||
807 | 807 | * @param bool $first_empty Whether or not the first item in the list should be empty |
808 | 808 | * @return mixed Fetched data. |
809 | 809 | */ |
810 | -function wpinv_maybe_add_empty_option( $options, $first_empty ) { |
|
810 | +function wpinv_maybe_add_empty_option($options, $first_empty) { |
|
811 | 811 | |
812 | - if ( ! empty( $options ) && $first_empty ) { |
|
813 | - return array_merge( array( '' => '' ), $options ); |
|
812 | + if (!empty($options) && $first_empty) { |
|
813 | + return array_merge(array('' => ''), $options); |
|
814 | 814 | } |
815 | 815 | return $options; |
816 | 816 | |
@@ -822,21 +822,21 @@ discard block |
||
822 | 822 | * @param mixed $var Data to sanitize. |
823 | 823 | * @return string|array |
824 | 824 | */ |
825 | -function wpinv_clean( $var ) { |
|
825 | +function wpinv_clean($var) { |
|
826 | 826 | |
827 | - if ( is_array( $var ) ) { |
|
828 | - return array_map( 'wpinv_clean', $var ); |
|
827 | + if (is_array($var)) { |
|
828 | + return array_map('wpinv_clean', $var); |
|
829 | 829 | } |
830 | 830 | |
831 | - if ( is_object( $var ) ) { |
|
832 | - $object_vars = get_object_vars( $var ); |
|
833 | - foreach ( $object_vars as $property_name => $property_value ) { |
|
834 | - $var->$property_name = wpinv_clean( $property_value ); |
|
831 | + if (is_object($var)) { |
|
832 | + $object_vars = get_object_vars($var); |
|
833 | + foreach ($object_vars as $property_name => $property_value) { |
|
834 | + $var->$property_name = wpinv_clean($property_value); |
|
835 | 835 | } |
836 | 836 | return $var; |
837 | 837 | } |
838 | 838 | |
839 | - return is_string( $var ) ? sanitize_text_field( stripslashes( $var ) ) : $var; |
|
839 | + return is_string($var) ? sanitize_text_field(stripslashes($var)) : $var; |
|
840 | 840 | } |
841 | 841 | |
842 | 842 | /** |
@@ -845,43 +845,43 @@ discard block |
||
845 | 845 | * @param string $str Data to convert. |
846 | 846 | * @return string|array |
847 | 847 | */ |
848 | -function getpaid_convert_price_string_to_options( $str ) { |
|
848 | +function getpaid_convert_price_string_to_options($str) { |
|
849 | 849 | |
850 | - $raw_options = array_map( 'trim', explode( ',', $str ) ); |
|
851 | - $options = array(); |
|
850 | + $raw_options = array_map('trim', explode(',', $str)); |
|
851 | + $options = array(); |
|
852 | 852 | |
853 | - foreach ( $raw_options as $option ) { |
|
853 | + foreach ($raw_options as $option) { |
|
854 | 854 | |
855 | - if ( '' == $option ) { |
|
855 | + if ('' == $option) { |
|
856 | 856 | continue; |
857 | 857 | } |
858 | 858 | |
859 | - $option = array_map( 'trim', explode( '|', $option ) ); |
|
859 | + $option = array_map('trim', explode('|', $option)); |
|
860 | 860 | |
861 | 861 | $price = null; |
862 | 862 | $label = null; |
863 | 863 | |
864 | - if ( isset( $option[0] ) && '' != $option[0] ) { |
|
865 | - $label = $option[0]; |
|
864 | + if (isset($option[0]) && '' != $option[0]) { |
|
865 | + $label = $option[0]; |
|
866 | 866 | } |
867 | 867 | |
868 | - if ( isset( $option[1] ) && '' != $option[1] ) { |
|
868 | + if (isset($option[1]) && '' != $option[1]) { |
|
869 | 869 | $price = $option[1]; |
870 | 870 | } |
871 | 871 | |
872 | - if ( ! isset( $price ) ) { |
|
872 | + if (!isset($price)) { |
|
873 | 873 | $price = $label; |
874 | 874 | } |
875 | 875 | |
876 | - if ( ! isset( $price ) || ! is_numeric( $price ) ) { |
|
876 | + if (!isset($price) || !is_numeric($price)) { |
|
877 | 877 | continue; |
878 | 878 | } |
879 | 879 | |
880 | - if ( ! isset( $label ) ) { |
|
880 | + if (!isset($label)) { |
|
881 | 881 | $label = $price; |
882 | 882 | } |
883 | 883 | |
884 | - $options[ "$label|$price" ] = $label; |
|
884 | + $options["$label|$price"] = $label; |
|
885 | 885 | } |
886 | 886 | |
887 | 887 | return $options; |
@@ -890,14 +890,14 @@ discard block |
||
890 | 890 | /** |
891 | 891 | * Returns the help tip. |
892 | 892 | */ |
893 | -function getpaid_get_help_tip( $tip, $additional_classes = '', $echo = false ) { |
|
893 | +function getpaid_get_help_tip($tip, $additional_classes = '', $echo = false) { |
|
894 | 894 | $classes = 'wpi-help-tip dashicons dashicons-editor-help ' . $additional_classes; |
895 | - $tip = esc_attr( $tip ); |
|
895 | + $tip = esc_attr($tip); |
|
896 | 896 | |
897 | - if ( $echo ) { |
|
898 | - echo '<span class="' . esc_attr( $classes ) . '" data-tip="' . esc_attr( $tip ) . '"></span>'; |
|
897 | + if ($echo) { |
|
898 | + echo '<span class="' . esc_attr($classes) . '" data-tip="' . esc_attr($tip) . '"></span>'; |
|
899 | 899 | } else { |
900 | - return '<span class="' . esc_attr( $classes ) . '" data-tip="' . esc_attr( $tip ) . '"></span>'; |
|
900 | + return '<span class="' . esc_attr($classes) . '" data-tip="' . esc_attr($tip) . '"></span>'; |
|
901 | 901 | } |
902 | 902 | |
903 | 903 | } |
@@ -905,18 +905,18 @@ discard block |
||
905 | 905 | /** |
906 | 906 | * Formats a date |
907 | 907 | */ |
908 | -function getpaid_format_date( $date, $with_time = false ) { |
|
908 | +function getpaid_format_date($date, $with_time = false) { |
|
909 | 909 | |
910 | - if ( empty( $date ) || $date == '0000-00-00 00:00:00' ) { |
|
910 | + if (empty($date) || $date == '0000-00-00 00:00:00') { |
|
911 | 911 | return ''; |
912 | 912 | } |
913 | 913 | |
914 | 914 | $format = getpaid_date_format(); |
915 | 915 | |
916 | - if ( $with_time ) { |
|
916 | + if ($with_time) { |
|
917 | 917 | $format .= ' ' . getpaid_time_format(); |
918 | 918 | } |
919 | - return date_i18n( $format, strtotime( $date ) ); |
|
919 | + return date_i18n($format, strtotime($date)); |
|
920 | 920 | |
921 | 921 | } |
922 | 922 | |
@@ -925,9 +925,9 @@ discard block |
||
925 | 925 | * |
926 | 926 | * @return string |
927 | 927 | */ |
928 | -function getpaid_format_date_value( $date, $default = '—', $with_time = false ) { |
|
929 | - $date = getpaid_format_date( $date, $with_time ); |
|
930 | - return empty( $date ) ? $default : $date; |
|
928 | +function getpaid_format_date_value($date, $default = '—', $with_time = false) { |
|
929 | + $date = getpaid_format_date($date, $with_time); |
|
930 | + return empty($date) ? $default : $date; |
|
931 | 931 | } |
932 | 932 | |
933 | 933 | /** |
@@ -936,7 +936,7 @@ discard block |
||
936 | 936 | * @return string |
937 | 937 | */ |
938 | 938 | function getpaid_date_format() { |
939 | - return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) ); |
|
939 | + return apply_filters('getpaid_date_format', get_option('date_format')); |
|
940 | 940 | } |
941 | 941 | |
942 | 942 | /** |
@@ -945,7 +945,7 @@ discard block |
||
945 | 945 | * @return string |
946 | 946 | */ |
947 | 947 | function getpaid_time_format() { |
948 | - return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) ); |
|
948 | + return apply_filters('getpaid_time_format', get_option('time_format')); |
|
949 | 949 | } |
950 | 950 | |
951 | 951 | /** |
@@ -955,16 +955,16 @@ discard block |
||
955 | 955 | * @param integer $limit Limit size in characters. |
956 | 956 | * @return string |
957 | 957 | */ |
958 | -function getpaid_limit_length( $string, $limit ) { |
|
958 | +function getpaid_limit_length($string, $limit) { |
|
959 | 959 | $str_limit = $limit - 3; |
960 | 960 | |
961 | - if ( function_exists( 'mb_strimwidth' ) ) { |
|
962 | - if ( mb_strlen( $string ) > $limit ) { |
|
963 | - $string = mb_strimwidth( $string, 0, $str_limit ) . '...'; |
|
961 | + if (function_exists('mb_strimwidth')) { |
|
962 | + if (mb_strlen($string) > $limit) { |
|
963 | + $string = mb_strimwidth($string, 0, $str_limit) . '...'; |
|
964 | 964 | } |
965 | 965 | } else { |
966 | - if ( strlen( $string ) > $limit ) { |
|
967 | - $string = substr( $string, 0, $str_limit ) . '...'; |
|
966 | + if (strlen($string) > $limit) { |
|
967 | + $string = substr($string, 0, $str_limit) . '...'; |
|
968 | 968 | } |
969 | 969 | } |
970 | 970 | return $string; |
@@ -978,7 +978,7 @@ discard block |
||
978 | 978 | * @since 1.0.19 |
979 | 979 | */ |
980 | 980 | function getpaid_api() { |
981 | - return getpaid()->get( 'api' ); |
|
981 | + return getpaid()->get('api'); |
|
982 | 982 | } |
983 | 983 | |
984 | 984 | /** |
@@ -988,7 +988,7 @@ discard block |
||
988 | 988 | * @since 1.0.19 |
989 | 989 | */ |
990 | 990 | function getpaid_post_types() { |
991 | - return getpaid()->get( 'post_types' ); |
|
991 | + return getpaid()->get('post_types'); |
|
992 | 992 | } |
993 | 993 | |
994 | 994 | /** |
@@ -998,7 +998,7 @@ discard block |
||
998 | 998 | * @since 1.0.19 |
999 | 999 | */ |
1000 | 1000 | function getpaid_session() { |
1001 | - return getpaid()->get( 'session' ); |
|
1001 | + return getpaid()->get('session'); |
|
1002 | 1002 | } |
1003 | 1003 | |
1004 | 1004 | /** |
@@ -1008,7 +1008,7 @@ discard block |
||
1008 | 1008 | * @since 1.0.19 |
1009 | 1009 | */ |
1010 | 1010 | function getpaid_notes() { |
1011 | - return getpaid()->get( 'notes' ); |
|
1011 | + return getpaid()->get('notes'); |
|
1012 | 1012 | } |
1013 | 1013 | |
1014 | 1014 | /** |
@@ -1017,7 +1017,7 @@ discard block |
||
1017 | 1017 | * @return GetPaid_Admin |
1018 | 1018 | */ |
1019 | 1019 | function getpaid_admin() { |
1020 | - return getpaid()->get( 'admin' ); |
|
1020 | + return getpaid()->get('admin'); |
|
1021 | 1021 | } |
1022 | 1022 | |
1023 | 1023 | /** |
@@ -1027,8 +1027,8 @@ discard block |
||
1027 | 1027 | * @param string $base the base url |
1028 | 1028 | * @return string |
1029 | 1029 | */ |
1030 | -function getpaid_get_authenticated_action_url( $action, $base = false ) { |
|
1031 | - return wp_nonce_url( add_query_arg( 'getpaid-action', $action, $base ), 'getpaid-nonce', 'getpaid-nonce' ); |
|
1030 | +function getpaid_get_authenticated_action_url($action, $base = false) { |
|
1031 | + return wp_nonce_url(add_query_arg('getpaid-action', $action, $base), 'getpaid-nonce', 'getpaid-nonce'); |
|
1032 | 1032 | } |
1033 | 1033 | |
1034 | 1034 | /** |
@@ -1036,11 +1036,11 @@ discard block |
||
1036 | 1036 | * |
1037 | 1037 | * @return string |
1038 | 1038 | */ |
1039 | -function getpaid_get_post_type_label( $post_type, $plural = true ) { |
|
1039 | +function getpaid_get_post_type_label($post_type, $plural = true) { |
|
1040 | 1040 | |
1041 | - $post_type = get_post_type_object( $post_type ); |
|
1041 | + $post_type = get_post_type_object($post_type); |
|
1042 | 1042 | |
1043 | - if ( ! is_object( $post_type ) ) { |
|
1043 | + if (!is_object($post_type)) { |
|
1044 | 1044 | return null; |
1045 | 1045 | } |
1046 | 1046 | |
@@ -1053,18 +1053,18 @@ discard block |
||
1053 | 1053 | * |
1054 | 1054 | * @return mixed|null |
1055 | 1055 | */ |
1056 | -function getpaid_get_array_field( $array, $key, $secondary_key = null ) { |
|
1056 | +function getpaid_get_array_field($array, $key, $secondary_key = null) { |
|
1057 | 1057 | |
1058 | - if ( ! is_array( $array ) ) { |
|
1058 | + if (!is_array($array)) { |
|
1059 | 1059 | return null; |
1060 | 1060 | } |
1061 | 1061 | |
1062 | - if ( ! empty( $secondary_key ) ) { |
|
1063 | - $array = isset( $array[ $secondary_key ] ) ? $array[ $secondary_key ] : array(); |
|
1064 | - return getpaid_get_array_field( $array, $key ); |
|
1062 | + if (!empty($secondary_key)) { |
|
1063 | + $array = isset($array[$secondary_key]) ? $array[$secondary_key] : array(); |
|
1064 | + return getpaid_get_array_field($array, $key); |
|
1065 | 1065 | } |
1066 | 1066 | |
1067 | - return isset( $array[ $key ] ) ? $array[ $key ] : null; |
|
1067 | + return isset($array[$key]) ? $array[$key] : null; |
|
1068 | 1068 | |
1069 | 1069 | } |
1070 | 1070 | |
@@ -1073,12 +1073,12 @@ discard block |
||
1073 | 1073 | * |
1074 | 1074 | * @return array |
1075 | 1075 | */ |
1076 | -function getpaid_array_merge_if_empty( $args, $defaults ) { |
|
1076 | +function getpaid_array_merge_if_empty($args, $defaults) { |
|
1077 | 1077 | |
1078 | - foreach ( $defaults as $key => $value ) { |
|
1078 | + foreach ($defaults as $key => $value) { |
|
1079 | 1079 | |
1080 | - if ( empty( $args[ $key ] ) ) { |
|
1081 | - $args[ $key ] = $value; |
|
1080 | + if (empty($args[$key])) { |
|
1081 | + $args[$key] = $value; |
|
1082 | 1082 | } |
1083 | 1083 | } |
1084 | 1084 | |
@@ -1095,12 +1095,12 @@ discard block |
||
1095 | 1095 | |
1096 | 1096 | $types = get_allowed_mime_types(); |
1097 | 1097 | |
1098 | - if ( isset( $types['htm|html'] ) ) { |
|
1099 | - unset( $types['htm|html'] ); |
|
1098 | + if (isset($types['htm|html'])) { |
|
1099 | + unset($types['htm|html']); |
|
1100 | 1100 | } |
1101 | 1101 | |
1102 | - if ( isset( $types['js'] ) ) { |
|
1103 | - unset( $types['js'] ); |
|
1102 | + if (isset($types['js'])) { |
|
1103 | + unset($types['js']); |
|
1104 | 1104 | } |
1105 | 1105 | |
1106 | 1106 | return $types; |
@@ -1108,21 +1108,21 @@ discard block |
||
1108 | 1108 | } |
1109 | 1109 | |
1110 | 1110 | |
1111 | -function getpaid_user_delete_invoice( $data ) { |
|
1111 | +function getpaid_user_delete_invoice($data) { |
|
1112 | 1112 | |
1113 | 1113 | // Ensure there is an invoice to delete. |
1114 | - if ( empty( $data['invoice_id'] ) ) { |
|
1114 | + if (empty($data['invoice_id'])) { |
|
1115 | 1115 | return; |
1116 | 1116 | } |
1117 | 1117 | |
1118 | - $invoice = new WPInv_Invoice( (int) $data['invoice_id'] ); |
|
1118 | + $invoice = new WPInv_Invoice((int) $data['invoice_id']); |
|
1119 | 1119 | |
1120 | 1120 | // Ensure that it exists and that it belongs to the current user. |
1121 | - if ( ! $invoice->exists() || $invoice->get_customer_id() != get_current_user_id() ) { |
|
1121 | + if (!$invoice->exists() || $invoice->get_customer_id() != get_current_user_id()) { |
|
1122 | 1122 | $notice = 'perm_delete_invoice'; |
1123 | 1123 | |
1124 | 1124 | // Can it be deleted? |
1125 | - } elseif ( ! $invoice->needs_payment() ) { |
|
1125 | + } elseif (!$invoice->needs_payment()) { |
|
1126 | 1126 | $notice = 'cannot_delete_invoice'; |
1127 | 1127 | |
1128 | 1128 | // Delete it. |
@@ -1141,8 +1141,8 @@ discard block |
||
1141 | 1141 | ) |
1142 | 1142 | ); |
1143 | 1143 | |
1144 | - wp_safe_redirect( $redirect ); |
|
1144 | + wp_safe_redirect($redirect); |
|
1145 | 1145 | exit; |
1146 | 1146 | |
1147 | 1147 | } |
1148 | -add_action( 'getpaid_authenticated_action_delete_invoice', 'getpaid_user_delete_invoice' ); |
|
1148 | +add_action('getpaid_authenticated_action_delete_invoice', 'getpaid_user_delete_invoice'); |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | * @since 2.0.0 |
10 | 10 | */ |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * GetPaid REST reports controller class. |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * |
47 | 47 | * @see register_rest_route() |
48 | 48 | */ |
49 | - public function register_namespace_routes( $namespace ) { |
|
49 | + public function register_namespace_routes($namespace) { |
|
50 | 50 | |
51 | 51 | // Get sales report. |
52 | 52 | register_rest_route( |
@@ -55,11 +55,11 @@ discard block |
||
55 | 55 | array( |
56 | 56 | array( |
57 | 57 | 'methods' => WP_REST_Server::READABLE, |
58 | - 'callback' => array( $this, 'get_items' ), |
|
59 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
58 | + 'callback' => array($this, 'get_items'), |
|
59 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
60 | 60 | 'args' => $this->get_collection_params(), |
61 | 61 | ), |
62 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
62 | + 'schema' => array($this, 'get_public_item_schema'), |
|
63 | 63 | ) |
64 | 64 | ); |
65 | 65 | |
@@ -72,10 +72,10 @@ discard block |
||
72 | 72 | * @param WP_REST_Request $request Full data about the request. |
73 | 73 | * @return WP_Error|boolean |
74 | 74 | */ |
75 | - public function get_items_permissions_check( $request ) { |
|
75 | + public function get_items_permissions_check($request) { |
|
76 | 76 | |
77 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
78 | - return new WP_Error( 'rest_cannot_view', __( 'Sorry, you cannot list resources.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) ); |
|
77 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
78 | + return new WP_Error('rest_cannot_view', __('Sorry, you cannot list resources.', 'invoicing'), array('status' => rest_authorization_required_code())); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | return true; |
@@ -87,12 +87,12 @@ discard block |
||
87 | 87 | * @param WP_REST_Request $request |
88 | 88 | * @return array|WP_Error |
89 | 89 | */ |
90 | - public function get_items( $request ) { |
|
90 | + public function get_items($request) { |
|
91 | 91 | $data = array(); |
92 | - $item = $this->prepare_item_for_response( null, $request ); |
|
93 | - $data[] = $this->prepare_response_for_collection( $item ); |
|
92 | + $item = $this->prepare_item_for_response(null, $request); |
|
93 | + $data[] = $this->prepare_response_for_collection($item); |
|
94 | 94 | |
95 | - return rest_ensure_response( $data ); |
|
95 | + return rest_ensure_response($data); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
@@ -102,164 +102,164 @@ discard block |
||
102 | 102 | * @param WP_REST_Request $request Request object. |
103 | 103 | * @return WP_REST_Response $response Response data. |
104 | 104 | */ |
105 | - public function prepare_item_for_response( $_, $request ) { |
|
105 | + public function prepare_item_for_response($_, $request) { |
|
106 | 106 | |
107 | 107 | // Set report range. |
108 | - $this->report_range = $this->get_date_range( $request ); |
|
108 | + $this->report_range = $this->get_date_range($request); |
|
109 | 109 | |
110 | 110 | $report_data = $this->get_report_data(); |
111 | 111 | $period_totals = array(); |
112 | 112 | |
113 | 113 | // Setup period totals by ensuring each period in the interval has data. |
114 | - $start_date = strtotime( $this->report_range['after'] ); |
|
114 | + $start_date = strtotime($this->report_range['after']); |
|
115 | 115 | |
116 | - if ( 'month' === $this->groupby ) { |
|
117 | - $start_date = strtotime( gmdate( 'Y-m-01', $start_date ) ); |
|
116 | + if ('month' === $this->groupby) { |
|
117 | + $start_date = strtotime(gmdate('Y-m-01', $start_date)); |
|
118 | 118 | } |
119 | 119 | |
120 | - for ( $i = 0; $i < $this->interval; $i++ ) { |
|
120 | + for ($i = 0; $i < $this->interval; $i++) { |
|
121 | 121 | |
122 | - switch ( $this->groupby ) { |
|
122 | + switch ($this->groupby) { |
|
123 | 123 | case 'day': |
124 | - $time = gmdate( 'Y-m-d', strtotime( "+{$i} DAY", $start_date ) ); |
|
124 | + $time = gmdate('Y-m-d', strtotime("+{$i} DAY", $start_date)); |
|
125 | 125 | break; |
126 | 126 | default: |
127 | - $time = gmdate( 'Y-m', strtotime( "+{$i} MONTH", $start_date ) ); |
|
127 | + $time = gmdate('Y-m', strtotime("+{$i} MONTH", $start_date)); |
|
128 | 128 | break; |
129 | 129 | } |
130 | 130 | |
131 | 131 | // Set the defaults for each period. |
132 | - $period_totals[ $time ] = array( |
|
132 | + $period_totals[$time] = array( |
|
133 | 133 | 'invoices' => 0, |
134 | 134 | 'items' => 0, |
135 | 135 | 'refunded_items' => 0, |
136 | - 'refunded_tax' => wpinv_round_amount( 0.00 ), |
|
137 | - 'subtotal' => wpinv_round_amount( 0.00 ), |
|
138 | - 'refunded_subtotal' => wpinv_round_amount( 0.00 ), |
|
139 | - 'refunded_fees' => wpinv_round_amount( 0.00 ), |
|
140 | - 'discount' => wpinv_round_amount( 0.00 ), |
|
136 | + 'refunded_tax' => wpinv_round_amount(0.00), |
|
137 | + 'subtotal' => wpinv_round_amount(0.00), |
|
138 | + 'refunded_subtotal' => wpinv_round_amount(0.00), |
|
139 | + 'refunded_fees' => wpinv_round_amount(0.00), |
|
140 | + 'discount' => wpinv_round_amount(0.00), |
|
141 | 141 | ); |
142 | 142 | |
143 | - foreach ( array_keys( wpinv_get_report_graphs() ) as $key ) { |
|
144 | - if ( ! isset( $period_totals[ $time ][ $key ] ) ) { |
|
145 | - $period_totals[ $time ][ $key ] = wpinv_round_amount( 0.00 ); |
|
143 | + foreach (array_keys(wpinv_get_report_graphs()) as $key) { |
|
144 | + if (!isset($period_totals[$time][$key])) { |
|
145 | + $period_totals[$time][$key] = wpinv_round_amount(0.00); |
|
146 | 146 | } |
147 | 147 | } |
148 | 148 | } |
149 | 149 | |
150 | 150 | // add total sales, total invoice count, total tax for each period |
151 | - $date_format = ( 'day' === $this->groupby ) ? 'Y-m-d' : 'Y-m'; |
|
152 | - foreach ( $report_data->invoices as $invoice ) { |
|
153 | - $time = gmdate( $date_format, strtotime( $invoice->post_date ) ); |
|
151 | + $date_format = ('day' === $this->groupby) ? 'Y-m-d' : 'Y-m'; |
|
152 | + foreach ($report_data->invoices as $invoice) { |
|
153 | + $time = gmdate($date_format, strtotime($invoice->post_date)); |
|
154 | 154 | |
155 | - if ( ! isset( $period_totals[ $time ] ) ) { |
|
155 | + if (!isset($period_totals[$time])) { |
|
156 | 156 | continue; |
157 | 157 | } |
158 | 158 | |
159 | - $period_totals[ $time ]['sales'] = wpinv_round_amount( $invoice->total_sales ); |
|
160 | - $period_totals[ $time ]['tax'] = wpinv_round_amount( $invoice->total_tax ); |
|
161 | - $period_totals[ $time ]['subtotal'] = wpinv_round_amount( $invoice->subtotal ); |
|
162 | - $period_totals[ $time ]['fees'] = wpinv_round_amount( $invoice->total_fees ); |
|
159 | + $period_totals[$time]['sales'] = wpinv_round_amount($invoice->total_sales); |
|
160 | + $period_totals[$time]['tax'] = wpinv_round_amount($invoice->total_tax); |
|
161 | + $period_totals[$time]['subtotal'] = wpinv_round_amount($invoice->subtotal); |
|
162 | + $period_totals[$time]['fees'] = wpinv_round_amount($invoice->total_fees); |
|
163 | 163 | |
164 | 164 | } |
165 | 165 | |
166 | - foreach ( $report_data->refunds as $invoice ) { |
|
167 | - $time = gmdate( $date_format, strtotime( $invoice->post_date ) ); |
|
166 | + foreach ($report_data->refunds as $invoice) { |
|
167 | + $time = gmdate($date_format, strtotime($invoice->post_date)); |
|
168 | 168 | |
169 | - if ( ! isset( $period_totals[ $time ] ) ) { |
|
169 | + if (!isset($period_totals[$time])) { |
|
170 | 170 | continue; |
171 | 171 | } |
172 | 172 | |
173 | - $period_totals[ $time ]['refunds'] = wpinv_round_amount( $invoice->total_sales ); |
|
174 | - $period_totals[ $time ]['refunded_tax'] = wpinv_round_amount( $invoice->total_tax ); |
|
175 | - $period_totals[ $time ]['refunded_subtotal'] = wpinv_round_amount( $invoice->subtotal ); |
|
176 | - $period_totals[ $time ]['refunded_fees'] = wpinv_round_amount( $invoice->total_fees ); |
|
173 | + $period_totals[$time]['refunds'] = wpinv_round_amount($invoice->total_sales); |
|
174 | + $period_totals[$time]['refunded_tax'] = wpinv_round_amount($invoice->total_tax); |
|
175 | + $period_totals[$time]['refunded_subtotal'] = wpinv_round_amount($invoice->subtotal); |
|
176 | + $period_totals[$time]['refunded_fees'] = wpinv_round_amount($invoice->total_fees); |
|
177 | 177 | |
178 | 178 | } |
179 | 179 | |
180 | - foreach ( $report_data->invoice_counts as $invoice ) { |
|
181 | - $time = gmdate( $date_format, strtotime( $invoice->post_date ) ); |
|
180 | + foreach ($report_data->invoice_counts as $invoice) { |
|
181 | + $time = gmdate($date_format, strtotime($invoice->post_date)); |
|
182 | 182 | |
183 | - if ( isset( $period_totals[ $time ] ) ) { |
|
184 | - $period_totals[ $time ]['invoices'] = (int) $invoice->count; |
|
183 | + if (isset($period_totals[$time])) { |
|
184 | + $period_totals[$time]['invoices'] = (int) $invoice->count; |
|
185 | 185 | } |
186 | 186 | } |
187 | 187 | |
188 | 188 | // Add total invoice items for each period. |
189 | - foreach ( $report_data->invoice_items as $invoice_item ) { |
|
190 | - $time = ( 'day' === $this->groupby ) ? gmdate( 'Y-m-d', strtotime( $invoice_item->post_date ) ) : gmdate( 'Y-m', strtotime( $invoice_item->post_date ) ); |
|
189 | + foreach ($report_data->invoice_items as $invoice_item) { |
|
190 | + $time = ('day' === $this->groupby) ? gmdate('Y-m-d', strtotime($invoice_item->post_date)) : gmdate('Y-m', strtotime($invoice_item->post_date)); |
|
191 | 191 | |
192 | - if ( isset( $period_totals[ $time ] ) ) { |
|
193 | - $period_totals[ $time ]['items'] = (int) $invoice_item->invoice_item_count; |
|
192 | + if (isset($period_totals[$time])) { |
|
193 | + $period_totals[$time]['items'] = (int) $invoice_item->invoice_item_count; |
|
194 | 194 | } |
195 | 195 | } |
196 | 196 | |
197 | 197 | // Add total discount for each period. |
198 | - foreach ( $report_data->coupons as $discount ) { |
|
199 | - $time = ( 'day' === $this->groupby ) ? gmdate( 'Y-m-d', strtotime( $discount->post_date ) ) : gmdate( 'Y-m', strtotime( $discount->post_date ) ); |
|
198 | + foreach ($report_data->coupons as $discount) { |
|
199 | + $time = ('day' === $this->groupby) ? gmdate('Y-m-d', strtotime($discount->post_date)) : gmdate('Y-m', strtotime($discount->post_date)); |
|
200 | 200 | |
201 | - if ( isset( $period_totals[ $time ] ) ) { |
|
202 | - $period_totals[ $time ]['discount'] = wpinv_round_amount( $discount->discount_amount ); |
|
201 | + if (isset($period_totals[$time])) { |
|
202 | + $period_totals[$time]['discount'] = wpinv_round_amount($discount->discount_amount); |
|
203 | 203 | } |
204 | 204 | } |
205 | 205 | |
206 | 206 | // Extra fields. |
207 | - foreach ( array_keys( wpinv_get_report_graphs() ) as $key ) { |
|
207 | + foreach (array_keys(wpinv_get_report_graphs()) as $key) { |
|
208 | 208 | |
209 | 209 | // Abort unprepared. |
210 | - if ( ! isset( $report_data->$key ) ) { |
|
210 | + if (!isset($report_data->$key)) { |
|
211 | 211 | continue; |
212 | 212 | } |
213 | 213 | |
214 | 214 | // Abort defaults. |
215 | - if ( in_array( $key, array( 'sales', 'refunds', 'tax', 'fees', 'discount', 'invoices', 'items' ) ) ) { |
|
215 | + if (in_array($key, array('sales', 'refunds', 'tax', 'fees', 'discount', 'invoices', 'items'))) { |
|
216 | 216 | continue; |
217 | 217 | } |
218 | 218 | |
219 | 219 | // Set values. |
220 | - foreach ( $report_data->$key as $item ) { |
|
221 | - $time = ( 'day' === $this->groupby ) ? gmdate( 'Y-m-d', strtotime( $item->date ) ) : gmdate( 'Y-m', strtotime( $item->date ) ); |
|
220 | + foreach ($report_data->$key as $item) { |
|
221 | + $time = ('day' === $this->groupby) ? gmdate('Y-m-d', strtotime($item->date)) : gmdate('Y-m', strtotime($item->date)); |
|
222 | 222 | |
223 | - if ( isset( $period_totals[ $time ] ) ) { |
|
224 | - $period_totals[ $time ][ $key ] = wpinv_round_amount( $item->val ); |
|
223 | + if (isset($period_totals[$time])) { |
|
224 | + $period_totals[$time][$key] = wpinv_round_amount($item->val); |
|
225 | 225 | } |
226 | 226 | } |
227 | 227 | |
228 | - unset( $report_data->$key ); |
|
228 | + unset($report_data->$key); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | $report_data->totals = $period_totals; |
232 | 232 | $report_data->grouped_by = $this->groupby; |
233 | - $report_data->interval = max( $this->interval, 1 ); |
|
233 | + $report_data->interval = max($this->interval, 1); |
|
234 | 234 | $report_data->currency = wpinv_get_currency(); |
235 | 235 | $report_data->currency_symbol = wpinv_currency_symbol(); |
236 | 236 | $report_data->currency_position = wpinv_currency_position(); |
237 | 237 | $report_data->decimal_places = wpinv_decimals(); |
238 | 238 | $report_data->thousands_sep = wpinv_thousands_separator(); |
239 | 239 | $report_data->decimals_sep = wpinv_decimal_separator(); |
240 | - $report_data->start_date = gmdate( 'Y-m-d', strtotime( $this->report_range['after'] ) ); |
|
241 | - $report_data->end_date = gmdate( 'Y-m-d', strtotime( $this->report_range['before'] ) ); |
|
242 | - $report_data->start_date_locale = getpaid_format_date( gmdate( 'Y-m-d', strtotime( $this->report_range['after'] ) ) ); |
|
243 | - $report_data->end_date_locale = getpaid_format_date( gmdate( 'Y-m-d', strtotime( $this->report_range['before'] ) ) ); |
|
240 | + $report_data->start_date = gmdate('Y-m-d', strtotime($this->report_range['after'])); |
|
241 | + $report_data->end_date = gmdate('Y-m-d', strtotime($this->report_range['before'])); |
|
242 | + $report_data->start_date_locale = getpaid_format_date(gmdate('Y-m-d', strtotime($this->report_range['after']))); |
|
243 | + $report_data->end_date_locale = getpaid_format_date(gmdate('Y-m-d', strtotime($this->report_range['before']))); |
|
244 | 244 | $report_data->decimals_sep = wpinv_decimal_separator(); |
245 | 245 | |
246 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
246 | + $context = !empty($request['context']) ? $request['context'] : 'view'; |
|
247 | 247 | $data = $report_data; |
248 | - unset( $data->invoice_counts, $data->invoices, $data->coupons, $data->refunds, $data->invoice_items ); |
|
249 | - $data = $this->add_additional_fields_to_object( (array) $data, $request ); |
|
250 | - $data = $this->filter_response_by_context( $data, $context ); |
|
248 | + unset($data->invoice_counts, $data->invoices, $data->coupons, $data->refunds, $data->invoice_items); |
|
249 | + $data = $this->add_additional_fields_to_object((array) $data, $request); |
|
250 | + $data = $this->filter_response_by_context($data, $context); |
|
251 | 251 | |
252 | 252 | // Wrap the data in a response object. |
253 | - $response = rest_ensure_response( $data ); |
|
253 | + $response = rest_ensure_response($data); |
|
254 | 254 | $response->add_links( |
255 | 255 | array( |
256 | 256 | 'about' => array( |
257 | - 'href' => rest_url( sprintf( '%s/reports', $this->namespace ) ), |
|
257 | + 'href' => rest_url(sprintf('%s/reports', $this->namespace)), |
|
258 | 258 | ), |
259 | 259 | ) |
260 | 260 | ); |
261 | 261 | |
262 | - return apply_filters( 'getpaid_rest_prepare_report_sales', $response, $report_data, $request ); |
|
262 | + return apply_filters('getpaid_rest_prepare_report_sales', $response, $report_data, $request); |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | /** |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | * @return stdClass |
269 | 269 | */ |
270 | 270 | public function get_report_data() { |
271 | - if ( empty( $this->report_data ) ) { |
|
271 | + if (empty($this->report_data)) { |
|
272 | 272 | $this->query_report_data(); |
273 | 273 | } |
274 | 274 | return $this->report_data; |
@@ -291,31 +291,31 @@ discard block |
||
291 | 291 | ); |
292 | 292 | |
293 | 293 | // Calculated totals. |
294 | - $this->report_data->total_tax = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_tax' ) ) ); |
|
295 | - $this->report_data->total_sales = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_sales' ) ) ); |
|
296 | - $this->report_data->total_discount = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_discount' ) ) ); |
|
297 | - $this->report_data->total_fees = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'total_fees' ) ) ); |
|
298 | - $this->report_data->subtotal = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->invoices, 'subtotal' ) ) ); |
|
299 | - $this->report_data->net_sales = wpinv_round_amount( $this->report_data->total_sales - max( 0, $this->report_data->total_tax ) ); |
|
300 | - $this->report_data->total_refunded_tax = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_tax' ) ) ); |
|
301 | - $this->report_data->total_refunds = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_sales' ) ) ); |
|
302 | - $this->report_data->refunded_discount = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_discount' ) ) ); |
|
303 | - $this->report_data->refunded_fees = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'total_fees' ) ) ); |
|
304 | - $this->report_data->refunded_subtotal = wpinv_round_amount( array_sum( wp_list_pluck( $this->report_data->refunds, 'subtotal' ) ) ); |
|
305 | - $this->report_data->net_refunds = wpinv_round_amount( $this->report_data->total_refunds + max( 0, $this->report_data->total_refunded_tax ) ); |
|
294 | + $this->report_data->total_tax = wpinv_round_amount(array_sum(wp_list_pluck($this->report_data->invoices, 'total_tax'))); |
|
295 | + $this->report_data->total_sales = wpinv_round_amount(array_sum(wp_list_pluck($this->report_data->invoices, 'total_sales'))); |
|
296 | + $this->report_data->total_discount = wpinv_round_amount(array_sum(wp_list_pluck($this->report_data->invoices, 'total_discount'))); |
|
297 | + $this->report_data->total_fees = wpinv_round_amount(array_sum(wp_list_pluck($this->report_data->invoices, 'total_fees'))); |
|
298 | + $this->report_data->subtotal = wpinv_round_amount(array_sum(wp_list_pluck($this->report_data->invoices, 'subtotal'))); |
|
299 | + $this->report_data->net_sales = wpinv_round_amount($this->report_data->total_sales - max(0, $this->report_data->total_tax)); |
|
300 | + $this->report_data->total_refunded_tax = wpinv_round_amount(array_sum(wp_list_pluck($this->report_data->refunds, 'total_tax'))); |
|
301 | + $this->report_data->total_refunds = wpinv_round_amount(array_sum(wp_list_pluck($this->report_data->refunds, 'total_sales'))); |
|
302 | + $this->report_data->refunded_discount = wpinv_round_amount(array_sum(wp_list_pluck($this->report_data->refunds, 'total_discount'))); |
|
303 | + $this->report_data->refunded_fees = wpinv_round_amount(array_sum(wp_list_pluck($this->report_data->refunds, 'total_fees'))); |
|
304 | + $this->report_data->refunded_subtotal = wpinv_round_amount(array_sum(wp_list_pluck($this->report_data->refunds, 'subtotal'))); |
|
305 | + $this->report_data->net_refunds = wpinv_round_amount($this->report_data->total_refunds + max(0, $this->report_data->total_refunded_tax)); |
|
306 | 306 | |
307 | 307 | // Calculate average based on net. |
308 | - $this->report_data->average_sales = wpinv_round_amount( $this->report_data->net_sales / max( $this->interval, 1 ), 2 ); |
|
309 | - $this->report_data->average_total_sales = wpinv_round_amount( $this->report_data->total_sales / max( $this->interval, 1 ), 2 ); |
|
308 | + $this->report_data->average_sales = wpinv_round_amount($this->report_data->net_sales / max($this->interval, 1), 2); |
|
309 | + $this->report_data->average_total_sales = wpinv_round_amount($this->report_data->total_sales / max($this->interval, 1), 2); |
|
310 | 310 | |
311 | 311 | // Total invoices in this period, even if refunded. |
312 | - $this->report_data->total_invoices = absint( array_sum( wp_list_pluck( $this->report_data->invoice_counts, 'count' ) ) ); |
|
312 | + $this->report_data->total_invoices = absint(array_sum(wp_list_pluck($this->report_data->invoice_counts, 'count'))); |
|
313 | 313 | |
314 | 314 | // Items invoiced in this period, even if refunded. |
315 | - $this->report_data->total_items = absint( array_sum( wp_list_pluck( $this->report_data->invoice_items, 'invoice_item_count' ) ) ); |
|
315 | + $this->report_data->total_items = absint(array_sum(wp_list_pluck($this->report_data->invoice_items, 'invoice_item_count'))); |
|
316 | 316 | |
317 | 317 | // 3rd party filtering of report data |
318 | - $this->report_data = apply_filters( 'getpaid_rest_api_filter_report_data', $this->report_data, $this ); |
|
318 | + $this->report_data = apply_filters('getpaid_rest_api_filter_report_data', $this->report_data, $this); |
|
319 | 319 | } |
320 | 320 | |
321 | 321 | /** |
@@ -340,11 +340,11 @@ discard block |
||
340 | 340 | 'name' => 'post_date', |
341 | 341 | ), |
342 | 342 | ), |
343 | - 'group_by' => $this->get_group_by_sql( 'posts.post_date' ), |
|
343 | + 'group_by' => $this->get_group_by_sql('posts.post_date'), |
|
344 | 344 | 'order_by' => 'post_date ASC', |
345 | 345 | 'query_type' => 'get_results', |
346 | 346 | 'filter_range' => $this->report_range, |
347 | - 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded', 'wpi-renewal' ), |
|
347 | + 'invoice_status' => array('publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded', 'wpi-renewal'), |
|
348 | 348 | ) |
349 | 349 | ); |
350 | 350 | |
@@ -371,11 +371,11 @@ discard block |
||
371 | 371 | 'name' => 'post_date', |
372 | 372 | ), |
373 | 373 | ), |
374 | - 'group_by' => $this->get_group_by_sql( 'posts.post_date' ), |
|
374 | + 'group_by' => $this->get_group_by_sql('posts.post_date'), |
|
375 | 375 | 'order_by' => 'post_date ASC', |
376 | 376 | 'query_type' => 'get_results', |
377 | 377 | 'filter_range' => $this->report_range, |
378 | - 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded', 'wpi-renewal' ), |
|
378 | + 'invoice_status' => array('publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded', 'wpi-renewal'), |
|
379 | 379 | ) |
380 | 380 | ); |
381 | 381 | |
@@ -402,11 +402,11 @@ discard block |
||
402 | 402 | 'name' => 'post_date', |
403 | 403 | ), |
404 | 404 | ), |
405 | - 'group_by' => $this->get_group_by_sql( 'posts.post_date' ), |
|
405 | + 'group_by' => $this->get_group_by_sql('posts.post_date'), |
|
406 | 406 | 'order_by' => 'post_date ASC', |
407 | 407 | 'query_type' => 'get_results', |
408 | 408 | 'filter_range' => $this->report_range, |
409 | - 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded', 'wpi-renewal' ), |
|
409 | + 'invoice_status' => array('publish', 'wpi-processing', 'wpi-onhold', 'wpi-refunded', 'wpi-renewal'), |
|
410 | 410 | ) |
411 | 411 | ); |
412 | 412 | |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | ), |
431 | 431 | 'query_type' => 'get_var', |
432 | 432 | 'filter_range' => $this->report_range, |
433 | - 'invoice_status' => array( 'wpi-refunded' ), |
|
433 | + 'invoice_status' => array('wpi-refunded'), |
|
434 | 434 | ) |
435 | 435 | ); |
436 | 436 | |
@@ -477,11 +477,11 @@ discard block |
||
477 | 477 | 'name' => 'post_date', |
478 | 478 | ), |
479 | 479 | ), |
480 | - 'group_by' => $this->get_group_by_sql( 'posts.post_date' ), |
|
480 | + 'group_by' => $this->get_group_by_sql('posts.post_date'), |
|
481 | 481 | 'order_by' => 'post_date ASC', |
482 | 482 | 'query_type' => 'get_results', |
483 | 483 | 'filter_range' => $this->report_range, |
484 | - 'invoice_status' => array( 'publish', 'wpi-processing', 'wpi-onhold', 'wpi-renewal' ), |
|
484 | + 'invoice_status' => array('publish', 'wpi-processing', 'wpi-onhold', 'wpi-renewal'), |
|
485 | 485 | ) |
486 | 486 | ); |
487 | 487 | |
@@ -528,11 +528,11 @@ discard block |
||
528 | 528 | 'name' => 'post_date', |
529 | 529 | ), |
530 | 530 | ), |
531 | - 'group_by' => $this->get_group_by_sql( 'posts.post_date' ), |
|
531 | + 'group_by' => $this->get_group_by_sql('posts.post_date'), |
|
532 | 532 | 'order_by' => 'post_date ASC', |
533 | 533 | 'query_type' => 'get_results', |
534 | 534 | 'filter_range' => $this->report_range, |
535 | - 'invoice_status' => array( 'wpi-refunded' ), |
|
535 | + 'invoice_status' => array('wpi-refunded'), |
|
536 | 536 | ) |
537 | 537 | ); |
538 | 538 | |
@@ -551,154 +551,154 @@ discard block |
||
551 | 551 | 'type' => 'object', |
552 | 552 | 'properties' => array( |
553 | 553 | 'total_sales' => array( |
554 | - 'description' => __( 'Gross sales in the period.', 'invoicing' ), |
|
554 | + 'description' => __('Gross sales in the period.', 'invoicing'), |
|
555 | 555 | 'type' => 'string', |
556 | - 'context' => array( 'view' ), |
|
556 | + 'context' => array('view'), |
|
557 | 557 | 'readonly' => true, |
558 | 558 | ), |
559 | 559 | 'net_sales' => array( |
560 | - 'description' => __( 'Net sales in the period.', 'invoicing' ), |
|
560 | + 'description' => __('Net sales in the period.', 'invoicing'), |
|
561 | 561 | 'type' => 'string', |
562 | - 'context' => array( 'view' ), |
|
562 | + 'context' => array('view'), |
|
563 | 563 | 'readonly' => true, |
564 | 564 | ), |
565 | 565 | 'average_sales' => array( |
566 | - 'description' => __( 'Average net daily sales.', 'invoicing' ), |
|
566 | + 'description' => __('Average net daily sales.', 'invoicing'), |
|
567 | 567 | 'type' => 'string', |
568 | - 'context' => array( 'view' ), |
|
568 | + 'context' => array('view'), |
|
569 | 569 | 'readonly' => true, |
570 | 570 | ), |
571 | 571 | 'average_total_sales' => array( |
572 | - 'description' => __( 'Average gross daily sales.', 'invoicing' ), |
|
572 | + 'description' => __('Average gross daily sales.', 'invoicing'), |
|
573 | 573 | 'type' => 'string', |
574 | - 'context' => array( 'view' ), |
|
574 | + 'context' => array('view'), |
|
575 | 575 | 'readonly' => true, |
576 | 576 | ), |
577 | 577 | 'total_invoices' => array( |
578 | - 'description' => __( 'Number of paid invoices.', 'invoicing' ), |
|
578 | + 'description' => __('Number of paid invoices.', 'invoicing'), |
|
579 | 579 | 'type' => 'integer', |
580 | - 'context' => array( 'view' ), |
|
580 | + 'context' => array('view'), |
|
581 | 581 | 'readonly' => true, |
582 | 582 | ), |
583 | 583 | 'total_items' => array( |
584 | - 'description' => __( 'Number of items purchased.', 'invoicing' ), |
|
584 | + 'description' => __('Number of items purchased.', 'invoicing'), |
|
585 | 585 | 'type' => 'integer', |
586 | - 'context' => array( 'view' ), |
|
586 | + 'context' => array('view'), |
|
587 | 587 | 'readonly' => true, |
588 | 588 | ), |
589 | 589 | 'refunded_items' => array( |
590 | - 'description' => __( 'Number of items refunded.', 'invoicing' ), |
|
590 | + 'description' => __('Number of items refunded.', 'invoicing'), |
|
591 | 591 | 'type' => 'integer', |
592 | - 'context' => array( 'view' ), |
|
592 | + 'context' => array('view'), |
|
593 | 593 | 'readonly' => true, |
594 | 594 | ), |
595 | 595 | 'total_tax' => array( |
596 | - 'description' => __( 'Total charged for taxes.', 'invoicing' ), |
|
596 | + 'description' => __('Total charged for taxes.', 'invoicing'), |
|
597 | 597 | 'type' => 'string', |
598 | - 'context' => array( 'view' ), |
|
598 | + 'context' => array('view'), |
|
599 | 599 | 'readonly' => true, |
600 | 600 | ), |
601 | 601 | 'total_refunded_tax' => array( |
602 | - 'description' => __( 'Total refunded for taxes.', 'invoicing' ), |
|
602 | + 'description' => __('Total refunded for taxes.', 'invoicing'), |
|
603 | 603 | 'type' => 'string', |
604 | - 'context' => array( 'view' ), |
|
604 | + 'context' => array('view'), |
|
605 | 605 | 'readonly' => true, |
606 | 606 | ), |
607 | 607 | 'total_fees' => array( |
608 | - 'description' => __( 'Total fees charged.', 'invoicing' ), |
|
608 | + 'description' => __('Total fees charged.', 'invoicing'), |
|
609 | 609 | 'type' => 'string', |
610 | - 'context' => array( 'view' ), |
|
610 | + 'context' => array('view'), |
|
611 | 611 | 'readonly' => true, |
612 | 612 | ), |
613 | 613 | 'total_refunds' => array( |
614 | - 'description' => __( 'Total of refunded invoices.', 'invoicing' ), |
|
614 | + 'description' => __('Total of refunded invoices.', 'invoicing'), |
|
615 | 615 | 'type' => 'integer', |
616 | - 'context' => array( 'view' ), |
|
616 | + 'context' => array('view'), |
|
617 | 617 | 'readonly' => true, |
618 | 618 | ), |
619 | 619 | 'net_refunds' => array( |
620 | - 'description' => __( 'Net of refunded invoices.', 'invoicing' ), |
|
620 | + 'description' => __('Net of refunded invoices.', 'invoicing'), |
|
621 | 621 | 'type' => 'integer', |
622 | - 'context' => array( 'view' ), |
|
622 | + 'context' => array('view'), |
|
623 | 623 | 'readonly' => true, |
624 | 624 | ), |
625 | 625 | 'total_discount' => array( |
626 | - 'description' => __( 'Total of discounts used.', 'invoicing' ), |
|
626 | + 'description' => __('Total of discounts used.', 'invoicing'), |
|
627 | 627 | 'type' => 'integer', |
628 | - 'context' => array( 'view' ), |
|
628 | + 'context' => array('view'), |
|
629 | 629 | 'readonly' => true, |
630 | 630 | ), |
631 | 631 | 'totals' => array( |
632 | - 'description' => __( 'Totals.', 'invoicing' ), |
|
632 | + 'description' => __('Totals.', 'invoicing'), |
|
633 | 633 | 'type' => 'array', |
634 | 634 | 'items' => array( |
635 | 635 | 'type' => 'array', |
636 | 636 | ), |
637 | - 'context' => array( 'view' ), |
|
637 | + 'context' => array('view'), |
|
638 | 638 | 'readonly' => true, |
639 | 639 | ), |
640 | 640 | 'interval' => array( |
641 | - 'description' => __( 'Number of months/days in the report period.', 'invoicing' ), |
|
641 | + 'description' => __('Number of months/days in the report period.', 'invoicing'), |
|
642 | 642 | 'type' => 'integer', |
643 | - 'context' => array( 'view' ), |
|
643 | + 'context' => array('view'), |
|
644 | 644 | 'readonly' => true, |
645 | 645 | ), |
646 | 646 | 'previous_range' => array( |
647 | - 'description' => __( 'The previous report period.', 'invoicing' ), |
|
647 | + 'description' => __('The previous report period.', 'invoicing'), |
|
648 | 648 | 'type' => 'array', |
649 | 649 | 'items' => array( |
650 | 650 | 'type' => 'string', |
651 | 651 | ), |
652 | - 'context' => array( 'view' ), |
|
652 | + 'context' => array('view'), |
|
653 | 653 | 'readonly' => true, |
654 | 654 | ), |
655 | 655 | 'grouped_by' => array( |
656 | - 'description' => __( 'The period used to group the totals.', 'invoicing' ), |
|
656 | + 'description' => __('The period used to group the totals.', 'invoicing'), |
|
657 | 657 | 'type' => 'string', |
658 | - 'context' => array( 'view' ), |
|
659 | - 'enum' => array( 'day', 'month' ), |
|
658 | + 'context' => array('view'), |
|
659 | + 'enum' => array('day', 'month'), |
|
660 | 660 | 'readonly' => true, |
661 | 661 | ), |
662 | 662 | 'currency' => array( |
663 | - 'description' => __( 'The default store currency.', 'invoicing' ), |
|
663 | + 'description' => __('The default store currency.', 'invoicing'), |
|
664 | 664 | 'type' => 'string', |
665 | - 'context' => array( 'view' ), |
|
665 | + 'context' => array('view'), |
|
666 | 666 | 'readonly' => true, |
667 | 667 | ), |
668 | 668 | 'currency_symbol' => array( |
669 | - 'description' => __( 'The default store currency symbol.', 'invoicing' ), |
|
669 | + 'description' => __('The default store currency symbol.', 'invoicing'), |
|
670 | 670 | 'type' => 'string', |
671 | - 'context' => array( 'view' ), |
|
671 | + 'context' => array('view'), |
|
672 | 672 | 'readonly' => true, |
673 | 673 | ), |
674 | 674 | 'currency_position' => array( |
675 | - 'description' => __( 'The default store currency position.', 'invoicing' ), |
|
675 | + 'description' => __('The default store currency position.', 'invoicing'), |
|
676 | 676 | 'type' => 'string', |
677 | - 'context' => array( 'view' ), |
|
677 | + 'context' => array('view'), |
|
678 | 678 | 'readonly' => true, |
679 | 679 | ), |
680 | 680 | 'decimal_places' => array( |
681 | - 'description' => __( 'The default store decimal places.', 'invoicing' ), |
|
681 | + 'description' => __('The default store decimal places.', 'invoicing'), |
|
682 | 682 | 'type' => 'string', |
683 | - 'context' => array( 'view' ), |
|
683 | + 'context' => array('view'), |
|
684 | 684 | 'readonly' => true, |
685 | 685 | ), |
686 | 686 | 'thousands_sep' => array( |
687 | - 'description' => __( 'The default store thousands separator.', 'invoicing' ), |
|
687 | + 'description' => __('The default store thousands separator.', 'invoicing'), |
|
688 | 688 | 'type' => 'string', |
689 | - 'context' => array( 'view' ), |
|
689 | + 'context' => array('view'), |
|
690 | 690 | 'readonly' => true, |
691 | 691 | ), |
692 | 692 | 'decimals_sep' => array( |
693 | - 'description' => __( 'The default store decimals separator.', 'invoicing' ), |
|
693 | + 'description' => __('The default store decimals separator.', 'invoicing'), |
|
694 | 694 | 'type' => 'string', |
695 | - 'context' => array( 'view' ), |
|
695 | + 'context' => array('view'), |
|
696 | 696 | 'readonly' => true, |
697 | 697 | ), |
698 | 698 | ), |
699 | 699 | ); |
700 | 700 | |
701 | - return $this->add_additional_fields_schema( $schema ); |
|
701 | + return $this->add_additional_fields_schema($schema); |
|
702 | 702 | |
703 | 703 | } |
704 | 704 |