@@ -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 |
@@ -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 | * Payment form submission taxes class |
@@ -29,22 +29,22 @@ discard block |
||
29 | 29 | * |
30 | 30 | * @param GetPaid_Payment_Form_Submission $submission |
31 | 31 | */ |
32 | - public function __construct( $submission ) { |
|
32 | + public function __construct($submission) { |
|
33 | 33 | |
34 | 34 | // Validate VAT number. |
35 | - $this->validate_vat( $submission ); |
|
35 | + $this->validate_vat($submission); |
|
36 | 36 | |
37 | - if ( $this->skip_taxes ) { |
|
37 | + if ($this->skip_taxes) { |
|
38 | 38 | return; |
39 | 39 | } |
40 | 40 | |
41 | - foreach ( $submission->get_items() as $item ) { |
|
42 | - $this->process_item_tax( $item, $submission ); |
|
41 | + foreach ($submission->get_items() as $item) { |
|
42 | + $this->process_item_tax($item, $submission); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | // Process any existing invoice taxes. |
46 | - if ( $submission->has_invoice() ) { |
|
47 | - $this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes ); |
|
46 | + if ($submission->has_invoice()) { |
|
47 | + $this->taxes = array_replace($submission->get_invoice()->get_taxes(), $this->taxes); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | } |
@@ -56,24 +56,24 @@ discard block |
||
56 | 56 | * @param GetPaid_Form_Item $item |
57 | 57 | * @param GetPaid_Payment_Form_Submission $submission |
58 | 58 | */ |
59 | - public function process_item_tax( $item, $submission ) { |
|
59 | + public function process_item_tax($item, $submission) { |
|
60 | 60 | |
61 | - $rates = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state ); |
|
62 | - $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
63 | - $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates ); |
|
64 | - $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates ); |
|
61 | + $rates = getpaid_get_item_tax_rates($item, $submission->country, $submission->state); |
|
62 | + $rates = getpaid_filter_item_tax_rates($item, $rates); |
|
63 | + $taxes = getpaid_calculate_item_taxes(getpaid_get_taxable_amount($item, false), $rates); |
|
64 | + $r_taxes = getpaid_calculate_item_taxes(getpaid_get_taxable_amount($item, true), $rates); |
|
65 | 65 | |
66 | - foreach ( $taxes as $name => $amount ) { |
|
67 | - $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
68 | - $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
66 | + foreach ($taxes as $name => $amount) { |
|
67 | + $recurring = isset($r_taxes[$name]) ? $r_taxes[$name] : 0; |
|
68 | + $tax = getpaid_prepare_item_tax($item, $name, $amount, $recurring); |
|
69 | 69 | |
70 | - if ( ! isset( $this->taxes[ $name ] ) ) { |
|
71 | - $this->taxes[ $name ] = $tax; |
|
70 | + if (!isset($this->taxes[$name])) { |
|
71 | + $this->taxes[$name] = $tax; |
|
72 | 72 | continue; |
73 | 73 | } |
74 | 74 | |
75 | - $this->taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
76 | - $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
75 | + $this->taxes[$name]['initial_tax'] += $tax['initial_tax']; |
|
76 | + $this->taxes[$name]['recurring_tax'] += $tax['recurring_tax']; |
|
77 | 77 | |
78 | 78 | } |
79 | 79 | |
@@ -86,11 +86,11 @@ discard block |
||
86 | 86 | * @since 1.0.19 |
87 | 87 | * @return bool |
88 | 88 | */ |
89 | - public function has_digital_item( $submission ) { |
|
89 | + public function has_digital_item($submission) { |
|
90 | 90 | |
91 | - foreach ( $submission->get_items() as $item ) { |
|
91 | + foreach ($submission->get_items() as $item) { |
|
92 | 92 | |
93 | - if ( 'digital' == $item->get_vat_rule() ) { |
|
93 | + if ('digital' == $item->get_vat_rule()) { |
|
94 | 94 | return true; |
95 | 95 | } |
96 | 96 | |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | * @return bool |
107 | 107 | */ |
108 | 108 | public static function is_eu_store() { |
109 | - return self::is_eu_country( wpinv_get_default_country() ); |
|
109 | + return self::is_eu_country(wpinv_get_default_country()); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
@@ -116,8 +116,8 @@ discard block |
||
116 | 116 | * @since 1.0.19 |
117 | 117 | * @return bool |
118 | 118 | */ |
119 | - public static function is_eu_country( $country ) { |
|
120 | - return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country ); |
|
119 | + public static function is_eu_country($country) { |
|
120 | + return getpaid_is_eu_state($country) || getpaid_is_gst_country($country); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -127,8 +127,8 @@ discard block |
||
127 | 127 | * @since 1.0.19 |
128 | 128 | * @return bool |
129 | 129 | */ |
130 | - public static function is_eu_transaction( $customer_country ) { |
|
131 | - return self::is_eu_country( $customer_country ) && self::is_eu_store(); |
|
130 | + public static function is_eu_transaction($customer_country) { |
|
131 | + return self::is_eu_country($customer_country) && self::is_eu_store(); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
@@ -138,12 +138,12 @@ discard block |
||
138 | 138 | * @since 1.0.19 |
139 | 139 | * @return string |
140 | 140 | */ |
141 | - public function get_vat_number( $submission ) { |
|
141 | + public function get_vat_number($submission) { |
|
142 | 142 | |
143 | 143 | // Retrieve from the posted number. |
144 | - $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' ); |
|
145 | - if ( ! is_null( $vat_number ) ) { |
|
146 | - return wpinv_clean( $vat_number ); |
|
144 | + $vat_number = $submission->get_field('wpinv_vat_number', 'billing'); |
|
145 | + if (!is_null($vat_number)) { |
|
146 | + return wpinv_clean($vat_number); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : ''; |
@@ -156,12 +156,12 @@ discard block |
||
156 | 156 | * @since 1.0.19 |
157 | 157 | * @return string |
158 | 158 | */ |
159 | - public function get_company( $submission ) { |
|
159 | + public function get_company($submission) { |
|
160 | 160 | |
161 | 161 | // Retrieve from the posted data. |
162 | - $company = $submission->get_field( 'wpinv_company', 'billing' ); |
|
163 | - if ( ! empty( $company ) ) { |
|
164 | - return wpinv_clean( $company ); |
|
162 | + $company = $submission->get_field('wpinv_company', 'billing'); |
|
163 | + if (!empty($company)) { |
|
164 | + return wpinv_clean($company); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | // Retrieve from the invoice. |
@@ -176,10 +176,10 @@ discard block |
||
176 | 176 | * @since 1.0.19 |
177 | 177 | * @return string |
178 | 178 | */ |
179 | - public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
179 | + public function requires_vat($ip_in_eu, $country_in_eu) { |
|
180 | 180 | |
181 | - $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
182 | - $prevent_b2c = ! empty( $prevent_b2c ); |
|
181 | + $prevent_b2c = wpinv_get_option('vat_prevent_b2c_purchase'); |
|
182 | + $prevent_b2c = !empty($prevent_b2c); |
|
183 | 183 | $is_eu = $ip_in_eu || $country_in_eu; |
184 | 184 | |
185 | 185 | return $prevent_b2c && $is_eu; |
@@ -191,45 +191,45 @@ discard block |
||
191 | 191 | * @param GetPaid_Payment_Form_Submission $submission |
192 | 192 | * @since 1.0.19 |
193 | 193 | */ |
194 | - public function validate_vat( $submission ) { |
|
194 | + public function validate_vat($submission) { |
|
195 | 195 | |
196 | - $in_eu = $this->is_eu_transaction( $submission->country ); |
|
196 | + $in_eu = $this->is_eu_transaction($submission->country); |
|
197 | 197 | |
198 | 198 | // Abort if we are not validating vat numbers. |
199 | - if ( ! $in_eu ) { |
|
199 | + if (!$in_eu) { |
|
200 | 200 | return; |
201 | 201 | } |
202 | 202 | |
203 | 203 | // Prepare variables. |
204 | - $vat_number = $this->get_vat_number( $submission ); |
|
204 | + $vat_number = $this->get_vat_number($submission); |
|
205 | 205 | $ip_country = getpaid_get_ip_country(); |
206 | - $is_eu = $this->is_eu_country( $submission->country ); |
|
207 | - $is_ip_eu = $this->is_eu_country( $ip_country ); |
|
206 | + $is_eu = $this->is_eu_country($submission->country); |
|
207 | + $is_ip_eu = $this->is_eu_country($ip_country); |
|
208 | 208 | |
209 | 209 | // Maybe abort early for initial fetches. |
210 | - if ( $submission->is_initial_fetch() && empty( $vat_number ) ) { |
|
210 | + if ($submission->is_initial_fetch() && empty($vat_number)) { |
|
211 | 211 | return; |
212 | 212 | } |
213 | 213 | |
214 | 214 | // If we're preventing business to consumer purchases, |
215 | - if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
215 | + if ($this->requires_vat($is_ip_eu, $is_eu) && empty($vat_number)) { |
|
216 | 216 | |
217 | 217 | // Ensure that a vat number has been specified. |
218 | 218 | throw new Exception( |
219 | - __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) |
|
219 | + __('Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing') |
|
220 | 220 | ); |
221 | 221 | |
222 | 222 | } |
223 | 223 | |
224 | - if ( empty( $vat_number ) ) { |
|
224 | + if (empty($vat_number)) { |
|
225 | 225 | return; |
226 | 226 | } |
227 | 227 | |
228 | - if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) { |
|
229 | - throw new Exception( __( 'Your VAT number is invalid', 'invoicing' ) ); |
|
228 | + if (wpinv_should_validate_vat_number() && !wpinv_validate_vat_number($vat_number, $submission->country)) { |
|
229 | + throw new Exception(__('Your VAT number is invalid', 'invoicing')); |
|
230 | 230 | } |
231 | 231 | |
232 | - if ( wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { |
|
232 | + if (wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option('vat_same_country_rule', 'vat_too')) { |
|
233 | 233 | return; |
234 | 234 | } |
235 | 235 |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * |
9 | 9 | */ |
10 | 10 | |
11 | -if ( ! defined( 'ABSPATH' ) ) { |
|
11 | +if (!defined('ABSPATH')) { |
|
12 | 12 | exit; |
13 | 13 | } |
14 | 14 | |
@@ -117,8 +117,8 @@ discard block |
||
117 | 117 | * |
118 | 118 | * @param int|object|array|string $read ID to load from the DB (optional) or already queried data. |
119 | 119 | */ |
120 | - public function __construct( $read = 0 ) { |
|
121 | - $this->data = array_merge( $this->data, $this->extra_data ); |
|
120 | + public function __construct($read = 0) { |
|
121 | + $this->data = array_merge($this->data, $this->extra_data); |
|
122 | 122 | $this->default_data = $this->data; |
123 | 123 | } |
124 | 124 | |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | * @return array |
129 | 129 | */ |
130 | 130 | public function __sleep() { |
131 | - return array( 'id' ); |
|
131 | + return array('id'); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
@@ -137,10 +137,10 @@ discard block |
||
137 | 137 | * If the object no longer exists, remove the ID. |
138 | 138 | */ |
139 | 139 | public function __wakeup() { |
140 | - $this->__construct( absint( $this->id ) ); |
|
140 | + $this->__construct(absint($this->id)); |
|
141 | 141 | |
142 | - if ( ! empty( $this->last_error ) ) { |
|
143 | - $this->set_id( 0 ); |
|
142 | + if (!empty($this->last_error)) { |
|
143 | + $this->set_id(0); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | } |
@@ -152,11 +152,11 @@ discard block |
||
152 | 152 | */ |
153 | 153 | public function __clone() { |
154 | 154 | $this->maybe_read_meta_data(); |
155 | - if ( ! empty( $this->meta_data ) ) { |
|
156 | - foreach ( $this->meta_data as $array_key => $meta ) { |
|
157 | - $this->meta_data[ $array_key ] = clone $meta; |
|
158 | - if ( ! empty( $meta->id ) ) { |
|
159 | - $this->meta_data[ $array_key ]->id = null; |
|
155 | + if (!empty($this->meta_data)) { |
|
156 | + foreach ($this->meta_data as $array_key => $meta) { |
|
157 | + $this->meta_data[$array_key] = clone $meta; |
|
158 | + if (!empty($meta->id)) { |
|
159 | + $this->meta_data[$array_key]->id = null; |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | } |
@@ -199,8 +199,8 @@ discard block |
||
199 | 199 | * @param string $context View or edit context. |
200 | 200 | * @return string |
201 | 201 | */ |
202 | - public function get_status( $context = 'view' ) { |
|
203 | - return $this->get_prop( 'status', $context ); |
|
202 | + public function get_status($context = 'view') { |
|
203 | + return $this->get_prop('status', $context); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
@@ -210,10 +210,10 @@ discard block |
||
210 | 210 | * @param bool $force_delete Should the data be deleted permanently. |
211 | 211 | * @return bool result |
212 | 212 | */ |
213 | - public function delete( $force_delete = false ) { |
|
214 | - if ( $this->data_store && $this->exists() ) { |
|
215 | - $this->data_store->delete( $this, array( 'force_delete' => $force_delete ) ); |
|
216 | - $this->set_id( 0 ); |
|
213 | + public function delete($force_delete = false) { |
|
214 | + if ($this->data_store && $this->exists()) { |
|
215 | + $this->data_store->delete($this, array('force_delete' => $force_delete)); |
|
216 | + $this->set_id(0); |
|
217 | 217 | return true; |
218 | 218 | } |
219 | 219 | return false; |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | * @return int |
227 | 227 | */ |
228 | 228 | public function save() { |
229 | - if ( ! $this->data_store ) { |
|
229 | + if (!$this->data_store) { |
|
230 | 230 | return $this->get_id(); |
231 | 231 | } |
232 | 232 | |
@@ -236,12 +236,12 @@ discard block |
||
236 | 236 | * @param GetPaid_Data $this The object being saved. |
237 | 237 | * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
238 | 238 | */ |
239 | - do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
239 | + do_action('getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store); |
|
240 | 240 | |
241 | - if ( $this->get_id() ) { |
|
242 | - $this->data_store->update( $this ); |
|
241 | + if ($this->get_id()) { |
|
242 | + $this->data_store->update($this); |
|
243 | 243 | } else { |
244 | - $this->data_store->create( $this ); |
|
244 | + $this->data_store->create($this); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | /** |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | * @param GetPaid_Data $this The object being saved. |
251 | 251 | * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
252 | 252 | */ |
253 | - do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
253 | + do_action('getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store); |
|
254 | 254 | |
255 | 255 | return $this->get_id(); |
256 | 256 | } |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | * @return string Data in JSON format. |
263 | 263 | */ |
264 | 264 | public function __toString() { |
265 | - return wp_json_encode( $this->get_data() ); |
|
265 | + return wp_json_encode($this->get_data()); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | /** |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | * @return array |
273 | 273 | */ |
274 | 274 | public function get_data() { |
275 | - return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) ); |
|
275 | + return array_merge(array('id' => $this->get_id()), $this->data, array('meta_data' => $this->get_meta_data())); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | /** |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | * @return array |
283 | 283 | */ |
284 | 284 | public function get_data_keys() { |
285 | - return array_keys( $this->data ); |
|
285 | + return array_keys($this->data); |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | /** |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | * @return array |
293 | 293 | */ |
294 | 294 | public function get_extra_data_keys() { |
295 | - return array_keys( $this->extra_data ); |
|
295 | + return array_keys($this->extra_data); |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | /** |
@@ -302,8 +302,8 @@ discard block |
||
302 | 302 | * @param mixed $meta Meta value to check. |
303 | 303 | * @return bool |
304 | 304 | */ |
305 | - protected function filter_null_meta( $meta ) { |
|
306 | - return ! is_null( $meta->value ); |
|
305 | + protected function filter_null_meta($meta) { |
|
306 | + return !is_null($meta->value); |
|
307 | 307 | } |
308 | 308 | |
309 | 309 | /** |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | */ |
315 | 315 | public function get_meta_data() { |
316 | 316 | $this->maybe_read_meta_data(); |
317 | - return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) ); |
|
317 | + return array_values(array_filter($this->meta_data, array($this, 'filter_null_meta'))); |
|
318 | 318 | } |
319 | 319 | |
320 | 320 | /** |
@@ -324,21 +324,21 @@ discard block |
||
324 | 324 | * @param string $key Key to check. |
325 | 325 | * @return bool true if it's an internal key, false otherwise |
326 | 326 | */ |
327 | - protected function is_internal_meta_key( $key ) { |
|
328 | - $internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true ); |
|
327 | + protected function is_internal_meta_key($key) { |
|
328 | + $internal_meta_key = !empty($key) && $this->data_store && in_array($key, $this->data_store->get_internal_meta_keys(), true); |
|
329 | 329 | |
330 | - if ( ! $internal_meta_key ) { |
|
330 | + if (!$internal_meta_key) { |
|
331 | 331 | return false; |
332 | 332 | } |
333 | 333 | |
334 | - $has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) ); |
|
334 | + $has_setter_or_getter = is_callable(array($this, 'set_' . $key)) || is_callable(array($this, 'get_' . $key)); |
|
335 | 335 | |
336 | - if ( ! $has_setter_or_getter ) { |
|
336 | + if (!$has_setter_or_getter) { |
|
337 | 337 | return false; |
338 | 338 | } |
339 | 339 | |
340 | 340 | /* translators: %s: $key Key to check */ |
341 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'invoicing' ), $key ), '1.0.19' ); |
|
341 | + getpaid_doing_it_wrong(__FUNCTION__, sprintf(__('Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'invoicing'), $key), '1.0.19'); |
|
342 | 342 | |
343 | 343 | return true; |
344 | 344 | } |
@@ -352,20 +352,20 @@ discard block |
||
352 | 352 | * @access public |
353 | 353 | * |
354 | 354 | */ |
355 | - public function __set( $key, $value ) { |
|
355 | + public function __set($key, $value) { |
|
356 | 356 | |
357 | - if ( 'id' == strtolower( $key ) ) { |
|
358 | - return $this->set_id( $value ); |
|
357 | + if ('id' == strtolower($key)) { |
|
358 | + return $this->set_id($value); |
|
359 | 359 | } |
360 | 360 | |
361 | - if ( method_exists( $this, "set_$key") ) { |
|
361 | + if (method_exists($this, "set_$key")) { |
|
362 | 362 | |
363 | 363 | /* translators: %s: $key Key to set */ |
364 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'invoicing' ), $key ), '1.0.19' ); |
|
364 | + getpaid_doing_it_wrong(__FUNCTION__, sprintf(__('Object data such as "%s" should not be accessed directly. Use getters and setters.', 'invoicing'), $key), '1.0.19'); |
|
365 | 365 | |
366 | - call_user_func( array( $this, "set_$key" ), $value ); |
|
366 | + call_user_func(array($this, "set_$key"), $value); |
|
367 | 367 | } else { |
368 | - $this->set_prop( $key, $value ); |
|
368 | + $this->set_prop($key, $value); |
|
369 | 369 | } |
370 | 370 | |
371 | 371 | } |
@@ -373,25 +373,25 @@ discard block |
||
373 | 373 | /** |
374 | 374 | * Margic method for retrieving a property. |
375 | 375 | */ |
376 | - public function __get( $key ) { |
|
376 | + public function __get($key) { |
|
377 | 377 | |
378 | 378 | // Check if we have a helper method for that. |
379 | - if ( method_exists( $this, 'get_' . $key ) ) { |
|
379 | + if (method_exists($this, 'get_' . $key)) { |
|
380 | 380 | |
381 | - if ( 'post_type' != $key ) { |
|
381 | + if ('post_type' != $key) { |
|
382 | 382 | /* translators: %s: $key Key to set */ |
383 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'invoicing' ), $key ), '1.0.19' ); |
|
383 | + getpaid_doing_it_wrong(__FUNCTION__, sprintf(__('Object data such as "%s" should not be accessed directly. Use getters and setters.', 'invoicing'), $key), '1.0.19'); |
|
384 | 384 | } |
385 | 385 | |
386 | - return call_user_func( array( $this, 'get_' . $key ) ); |
|
386 | + return call_user_func(array($this, 'get_' . $key)); |
|
387 | 387 | } |
388 | 388 | |
389 | 389 | // Check if the key is in the associated $post object. |
390 | - if ( ! empty( $this->post ) && isset( $this->post->$key ) ) { |
|
390 | + if (!empty($this->post) && isset($this->post->$key)) { |
|
391 | 391 | return $this->post->$key; |
392 | 392 | } |
393 | 393 | |
394 | - return $this->get_prop( $key ); |
|
394 | + return $this->get_prop($key); |
|
395 | 395 | |
396 | 396 | } |
397 | 397 | |
@@ -404,15 +404,15 @@ discard block |
||
404 | 404 | * @param string $context What the value is for. Valid values are view and edit. |
405 | 405 | * @return mixed |
406 | 406 | */ |
407 | - public function get_meta( $key = '', $single = true, $context = 'view' ) { |
|
407 | + public function get_meta($key = '', $single = true, $context = 'view') { |
|
408 | 408 | |
409 | 409 | // Check if this is an internal meta key. |
410 | - $_key = str_replace( '_wpinv', '', $key ); |
|
411 | - $_key = str_replace( 'wpinv', '', $_key ); |
|
412 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
410 | + $_key = str_replace('_wpinv', '', $key); |
|
411 | + $_key = str_replace('wpinv', '', $_key); |
|
412 | + if ($this->is_internal_meta_key($key)) { |
|
413 | 413 | $function = 'get_' . $_key; |
414 | 414 | |
415 | - if ( is_callable( array( $this, $function ) ) ) { |
|
415 | + if (is_callable(array($this, $function))) { |
|
416 | 416 | return $this->{$function}(); |
417 | 417 | } |
418 | 418 | } |
@@ -420,20 +420,20 @@ discard block |
||
420 | 420 | // Read the meta data if not yet read. |
421 | 421 | $this->maybe_read_meta_data(); |
422 | 422 | $meta_data = $this->get_meta_data(); |
423 | - $array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true ); |
|
423 | + $array_keys = array_keys(wp_list_pluck($meta_data, 'key'), $key, true); |
|
424 | 424 | $value = $single ? '' : array(); |
425 | 425 | |
426 | - if ( ! empty( $array_keys ) ) { |
|
426 | + if (!empty($array_keys)) { |
|
427 | 427 | // We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()). |
428 | - if ( $single ) { |
|
429 | - $value = $meta_data[ current( $array_keys ) ]->value; |
|
428 | + if ($single) { |
|
429 | + $value = $meta_data[current($array_keys)]->value; |
|
430 | 430 | } else { |
431 | - $value = array_intersect_key( $meta_data, array_flip( $array_keys ) ); |
|
431 | + $value = array_intersect_key($meta_data, array_flip($array_keys)); |
|
432 | 432 | } |
433 | 433 | } |
434 | 434 | |
435 | - if ( 'view' === $context ) { |
|
436 | - $value = apply_filters( $this->get_hook_prefix() . $key, $value, $this ); |
|
435 | + if ('view' === $context) { |
|
436 | + $value = apply_filters($this->get_hook_prefix() . $key, $value, $this); |
|
437 | 437 | } |
438 | 438 | |
439 | 439 | return $value; |
@@ -446,10 +446,10 @@ discard block |
||
446 | 446 | * @param string $key Meta Key. |
447 | 447 | * @return boolean |
448 | 448 | */ |
449 | - public function meta_exists( $key = '' ) { |
|
449 | + public function meta_exists($key = '') { |
|
450 | 450 | $this->maybe_read_meta_data(); |
451 | - $array_keys = wp_list_pluck( $this->get_meta_data(), 'key' ); |
|
452 | - return in_array( $key, $array_keys, true ); |
|
451 | + $array_keys = wp_list_pluck($this->get_meta_data(), 'key'); |
|
452 | + return in_array($key, $array_keys, true); |
|
453 | 453 | } |
454 | 454 | |
455 | 455 | /** |
@@ -458,12 +458,12 @@ discard block |
||
458 | 458 | * @since 1.0.19 |
459 | 459 | * @param array $data Key/Value pairs. |
460 | 460 | */ |
461 | - public function set_meta_data( $data ) { |
|
462 | - if ( ! empty( $data ) && is_array( $data ) ) { |
|
461 | + public function set_meta_data($data) { |
|
462 | + if (!empty($data) && is_array($data)) { |
|
463 | 463 | $this->maybe_read_meta_data(); |
464 | - foreach ( $data as $meta ) { |
|
464 | + foreach ($data as $meta) { |
|
465 | 465 | $meta = (array) $meta; |
466 | - if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) { |
|
466 | + if (isset($meta['key'], $meta['value'], $meta['id'])) { |
|
467 | 467 | $this->meta_data[] = new GetPaid_Meta_Data( |
468 | 468 | array( |
469 | 469 | 'id' => $meta['id'], |
@@ -485,18 +485,18 @@ discard block |
||
485 | 485 | * @param string|array $value Meta value. |
486 | 486 | * @param bool $unique Should this be a unique key?. |
487 | 487 | */ |
488 | - public function add_meta_data( $key, $value, $unique = false ) { |
|
489 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
488 | + public function add_meta_data($key, $value, $unique = false) { |
|
489 | + if ($this->is_internal_meta_key($key)) { |
|
490 | 490 | $function = 'set_' . $key; |
491 | 491 | |
492 | - if ( is_callable( array( $this, $function ) ) ) { |
|
493 | - return $this->{$function}( $value ); |
|
492 | + if (is_callable(array($this, $function))) { |
|
493 | + return $this->{$function}($value); |
|
494 | 494 | } |
495 | 495 | } |
496 | 496 | |
497 | 497 | $this->maybe_read_meta_data(); |
498 | - if ( $unique ) { |
|
499 | - $this->delete_meta_data( $key ); |
|
498 | + if ($unique) { |
|
499 | + $this->delete_meta_data($key); |
|
500 | 500 | } |
501 | 501 | $this->meta_data[] = new GetPaid_Meta_Data( |
502 | 502 | array( |
@@ -517,12 +517,12 @@ discard block |
||
517 | 517 | * @param string|array $value Meta value. |
518 | 518 | * @param int $meta_id Meta ID. |
519 | 519 | */ |
520 | - public function update_meta_data( $key, $value, $meta_id = 0 ) { |
|
521 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
520 | + public function update_meta_data($key, $value, $meta_id = 0) { |
|
521 | + if ($this->is_internal_meta_key($key)) { |
|
522 | 522 | $function = 'set_' . $key; |
523 | 523 | |
524 | - if ( is_callable( array( $this, $function ) ) ) { |
|
525 | - return $this->{$function}( $value ); |
|
524 | + if (is_callable(array($this, $function))) { |
|
525 | + return $this->{$function}($value); |
|
526 | 526 | } |
527 | 527 | } |
528 | 528 | |
@@ -530,33 +530,33 @@ discard block |
||
530 | 530 | |
531 | 531 | $array_key = false; |
532 | 532 | |
533 | - if ( $meta_id ) { |
|
534 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true ); |
|
535 | - $array_key = $array_keys ? current( $array_keys ) : false; |
|
533 | + if ($meta_id) { |
|
534 | + $array_keys = array_keys(wp_list_pluck($this->meta_data, 'id'), $meta_id, true); |
|
535 | + $array_key = $array_keys ? current($array_keys) : false; |
|
536 | 536 | } else { |
537 | 537 | // Find matches by key. |
538 | 538 | $matches = array(); |
539 | - foreach ( $this->meta_data as $meta_data_array_key => $meta ) { |
|
540 | - if ( $meta->key === $key ) { |
|
539 | + foreach ($this->meta_data as $meta_data_array_key => $meta) { |
|
540 | + if ($meta->key === $key) { |
|
541 | 541 | $matches[] = $meta_data_array_key; |
542 | 542 | } |
543 | 543 | } |
544 | 544 | |
545 | - if ( ! empty( $matches ) ) { |
|
545 | + if (!empty($matches)) { |
|
546 | 546 | // Set matches to null so only one key gets the new value. |
547 | - foreach ( $matches as $meta_data_array_key ) { |
|
548 | - $this->meta_data[ $meta_data_array_key ]->value = null; |
|
547 | + foreach ($matches as $meta_data_array_key) { |
|
548 | + $this->meta_data[$meta_data_array_key]->value = null; |
|
549 | 549 | } |
550 | - $array_key = current( $matches ); |
|
550 | + $array_key = current($matches); |
|
551 | 551 | } |
552 | 552 | } |
553 | 553 | |
554 | - if ( false !== $array_key ) { |
|
555 | - $meta = $this->meta_data[ $array_key ]; |
|
554 | + if (false !== $array_key) { |
|
555 | + $meta = $this->meta_data[$array_key]; |
|
556 | 556 | $meta->key = $key; |
557 | 557 | $meta->value = $value; |
558 | 558 | } else { |
559 | - $this->add_meta_data( $key, $value, true ); |
|
559 | + $this->add_meta_data($key, $value, true); |
|
560 | 560 | } |
561 | 561 | } |
562 | 562 | |
@@ -566,13 +566,13 @@ discard block |
||
566 | 566 | * @since 1.0.19 |
567 | 567 | * @param string $key Meta key. |
568 | 568 | */ |
569 | - public function delete_meta_data( $key ) { |
|
569 | + public function delete_meta_data($key) { |
|
570 | 570 | $this->maybe_read_meta_data(); |
571 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true ); |
|
571 | + $array_keys = array_keys(wp_list_pluck($this->meta_data, 'key'), $key, true); |
|
572 | 572 | |
573 | - if ( $array_keys ) { |
|
574 | - foreach ( $array_keys as $array_key ) { |
|
575 | - $this->meta_data[ $array_key ]->value = null; |
|
573 | + if ($array_keys) { |
|
574 | + foreach ($array_keys as $array_key) { |
|
575 | + $this->meta_data[$array_key]->value = null; |
|
576 | 576 | } |
577 | 577 | } |
578 | 578 | } |
@@ -583,13 +583,13 @@ discard block |
||
583 | 583 | * @since 1.0.19 |
584 | 584 | * @param int $mid Meta ID. |
585 | 585 | */ |
586 | - public function delete_meta_data_by_mid( $mid ) { |
|
586 | + public function delete_meta_data_by_mid($mid) { |
|
587 | 587 | $this->maybe_read_meta_data(); |
588 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true ); |
|
588 | + $array_keys = array_keys(wp_list_pluck($this->meta_data, 'id'), (int) $mid, true); |
|
589 | 589 | |
590 | - if ( $array_keys ) { |
|
591 | - foreach ( $array_keys as $array_key ) { |
|
592 | - $this->meta_data[ $array_key ]->value = null; |
|
590 | + if ($array_keys) { |
|
591 | + foreach ($array_keys as $array_key) { |
|
592 | + $this->meta_data[$array_key]->value = null; |
|
593 | 593 | } |
594 | 594 | } |
595 | 595 | } |
@@ -600,7 +600,7 @@ discard block |
||
600 | 600 | * @since 1.0.19 |
601 | 601 | */ |
602 | 602 | protected function maybe_read_meta_data() { |
603 | - if ( is_null( $this->meta_data ) ) { |
|
603 | + if (is_null($this->meta_data)) { |
|
604 | 604 | $this->read_meta_data(); |
605 | 605 | } |
606 | 606 | } |
@@ -612,42 +612,42 @@ discard block |
||
612 | 612 | * @since 1.0.19 |
613 | 613 | * @param bool $force_read True to force a new DB read (and update cache). |
614 | 614 | */ |
615 | - public function read_meta_data( $force_read = false ) { |
|
615 | + public function read_meta_data($force_read = false) { |
|
616 | 616 | |
617 | 617 | // Reset meta data. |
618 | 618 | $this->meta_data = array(); |
619 | 619 | |
620 | 620 | // Maybe abort early. |
621 | - if ( ! $this->get_id() || ! $this->data_store ) { |
|
621 | + if (!$this->get_id() || !$this->data_store) { |
|
622 | 622 | return; |
623 | 623 | } |
624 | 624 | |
625 | 625 | // Only read from cache if the cache key is set. |
626 | 626 | $cache_key = null; |
627 | - if ( ! $force_read && ! empty( $this->cache_group ) ) { |
|
628 | - $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id(); |
|
629 | - $raw_meta_data = wp_cache_get( $cache_key, $this->cache_group ); |
|
627 | + if (!$force_read && !empty($this->cache_group)) { |
|
628 | + $cache_key = GetPaid_Cache_Helper::get_cache_prefix($this->cache_group) . GetPaid_Cache_Helper::get_cache_prefix('object_' . $this->get_id()) . 'object_meta_' . $this->get_id(); |
|
629 | + $raw_meta_data = wp_cache_get($cache_key, $this->cache_group); |
|
630 | 630 | } |
631 | 631 | |
632 | 632 | // Should we force read? |
633 | - if ( empty( $raw_meta_data ) ) { |
|
634 | - $raw_meta_data = $this->data_store->read_meta( $this ); |
|
633 | + if (empty($raw_meta_data)) { |
|
634 | + $raw_meta_data = $this->data_store->read_meta($this); |
|
635 | 635 | |
636 | - if ( ! empty( $cache_key ) ) { |
|
637 | - wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group ); |
|
636 | + if (!empty($cache_key)) { |
|
637 | + wp_cache_set($cache_key, $raw_meta_data, $this->cache_group); |
|
638 | 638 | } |
639 | 639 | |
640 | 640 | } |
641 | 641 | |
642 | 642 | // Set meta data. |
643 | - if ( is_array( $raw_meta_data ) ) { |
|
643 | + if (is_array($raw_meta_data)) { |
|
644 | 644 | |
645 | - foreach ( $raw_meta_data as $meta ) { |
|
645 | + foreach ($raw_meta_data as $meta) { |
|
646 | 646 | $this->meta_data[] = new GetPaid_Meta_Data( |
647 | 647 | array( |
648 | 648 | 'id' => (int) $meta->meta_id, |
649 | 649 | 'key' => $meta->meta_key, |
650 | - 'value' => maybe_unserialize( $meta->meta_value ), |
|
650 | + 'value' => maybe_unserialize($meta->meta_value), |
|
651 | 651 | ) |
652 | 652 | ); |
653 | 653 | } |
@@ -662,28 +662,28 @@ discard block |
||
662 | 662 | * @since 1.0.19 |
663 | 663 | */ |
664 | 664 | public function save_meta_data() { |
665 | - if ( ! $this->data_store || is_null( $this->meta_data ) ) { |
|
665 | + if (!$this->data_store || is_null($this->meta_data)) { |
|
666 | 666 | return; |
667 | 667 | } |
668 | - foreach ( $this->meta_data as $array_key => $meta ) { |
|
669 | - if ( is_null( $meta->value ) ) { |
|
670 | - if ( ! empty( $meta->id ) ) { |
|
671 | - $this->data_store->delete_meta( $this, $meta ); |
|
672 | - unset( $this->meta_data[ $array_key ] ); |
|
668 | + foreach ($this->meta_data as $array_key => $meta) { |
|
669 | + if (is_null($meta->value)) { |
|
670 | + if (!empty($meta->id)) { |
|
671 | + $this->data_store->delete_meta($this, $meta); |
|
672 | + unset($this->meta_data[$array_key]); |
|
673 | 673 | } |
674 | - } elseif ( empty( $meta->id ) ) { |
|
675 | - $meta->id = $this->data_store->add_meta( $this, $meta ); |
|
674 | + } elseif (empty($meta->id)) { |
|
675 | + $meta->id = $this->data_store->add_meta($this, $meta); |
|
676 | 676 | $meta->apply_changes(); |
677 | 677 | } else { |
678 | - if ( $meta->get_changes() ) { |
|
679 | - $this->data_store->update_meta( $this, $meta ); |
|
678 | + if ($meta->get_changes()) { |
|
679 | + $this->data_store->update_meta($this, $meta); |
|
680 | 680 | $meta->apply_changes(); |
681 | 681 | } |
682 | 682 | } |
683 | 683 | } |
684 | - if ( ! empty( $this->cache_group ) ) { |
|
685 | - $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id(); |
|
686 | - wp_cache_delete( $cache_key, $this->cache_group ); |
|
684 | + if (!empty($this->cache_group)) { |
|
685 | + $cache_key = GetPaid_Cache_Helper::get_cache_prefix($this->cache_group) . GetPaid_Cache_Helper::get_cache_prefix('object_' . $this->get_id()) . 'object_meta_' . $this->get_id(); |
|
686 | + wp_cache_delete($cache_key, $this->cache_group); |
|
687 | 687 | } |
688 | 688 | } |
689 | 689 | |
@@ -693,8 +693,8 @@ discard block |
||
693 | 693 | * @since 1.0.19 |
694 | 694 | * @param int $id ID. |
695 | 695 | */ |
696 | - public function set_id( $id ) { |
|
697 | - $this->id = absint( $id ); |
|
696 | + public function set_id($id) { |
|
697 | + $this->id = absint($id); |
|
698 | 698 | } |
699 | 699 | |
700 | 700 | /** |
@@ -704,10 +704,10 @@ discard block |
||
704 | 704 | * @param string $status New status. |
705 | 705 | * @return array details of change. |
706 | 706 | */ |
707 | - public function set_status( $status ) { |
|
707 | + public function set_status($status) { |
|
708 | 708 | $old_status = $this->get_status(); |
709 | 709 | |
710 | - $this->set_prop( 'status', $status ); |
|
710 | + $this->set_prop('status', $status); |
|
711 | 711 | |
712 | 712 | return array( |
713 | 713 | 'from' => $old_status, |
@@ -723,7 +723,7 @@ discard block |
||
723 | 723 | public function set_defaults() { |
724 | 724 | $this->data = $this->default_data; |
725 | 725 | $this->changes = array(); |
726 | - $this->set_object_read( false ); |
|
726 | + $this->set_object_read(false); |
|
727 | 727 | } |
728 | 728 | |
729 | 729 | /** |
@@ -732,7 +732,7 @@ discard block |
||
732 | 732 | * @since 1.0.19 |
733 | 733 | * @param boolean $read Should read?. |
734 | 734 | */ |
735 | - public function set_object_read( $read = true ) { |
|
735 | + public function set_object_read($read = true) { |
|
736 | 736 | $this->object_read = (bool) $read; |
737 | 737 | } |
738 | 738 | |
@@ -757,32 +757,32 @@ discard block |
||
757 | 757 | * |
758 | 758 | * @return bool|WP_Error |
759 | 759 | */ |
760 | - public function set_props( $props, $context = 'set' ) { |
|
760 | + public function set_props($props, $context = 'set') { |
|
761 | 761 | $errors = false; |
762 | 762 | |
763 | - foreach ( $props as $prop => $value ) { |
|
763 | + foreach ($props as $prop => $value) { |
|
764 | 764 | try { |
765 | 765 | /** |
766 | 766 | * Checks if the prop being set is allowed, and the value is not null. |
767 | 767 | */ |
768 | - if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) { |
|
768 | + if (is_null($value) || in_array($prop, array('prop', 'date_prop', 'meta_data'), true)) { |
|
769 | 769 | continue; |
770 | 770 | } |
771 | 771 | $setter = "set_$prop"; |
772 | 772 | |
773 | - if ( is_callable( array( $this, $setter ) ) ) { |
|
774 | - $this->{$setter}( $value ); |
|
773 | + if (is_callable(array($this, $setter))) { |
|
774 | + $this->{$setter}($value); |
|
775 | 775 | } |
776 | - } catch ( Exception $e ) { |
|
777 | - if ( ! $errors ) { |
|
776 | + } catch (Exception $e) { |
|
777 | + if (!$errors) { |
|
778 | 778 | $errors = new WP_Error(); |
779 | 779 | } |
780 | - $errors->add( $e->getCode(), $e->getMessage() ); |
|
780 | + $errors->add($e->getCode(), $e->getMessage()); |
|
781 | 781 | $this->last_error = $e->getMessage(); |
782 | 782 | } |
783 | 783 | } |
784 | 784 | |
785 | - return $errors && count( $errors->get_error_codes() ) ? $errors : true; |
|
785 | + return $errors && count($errors->get_error_codes()) ? $errors : true; |
|
786 | 786 | } |
787 | 787 | |
788 | 788 | /** |
@@ -795,14 +795,14 @@ discard block |
||
795 | 795 | * @param string $prop Name of prop to set. |
796 | 796 | * @param mixed $value Value of the prop. |
797 | 797 | */ |
798 | - protected function set_prop( $prop, $value ) { |
|
799 | - if ( array_key_exists( $prop, $this->data ) ) { |
|
800 | - if ( true === $this->object_read ) { |
|
801 | - if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) { |
|
802 | - $this->changes[ $prop ] = $value; |
|
798 | + protected function set_prop($prop, $value) { |
|
799 | + if (array_key_exists($prop, $this->data)) { |
|
800 | + if (true === $this->object_read) { |
|
801 | + if ($value !== $this->data[$prop] || array_key_exists($prop, $this->changes)) { |
|
802 | + $this->changes[$prop] = $value; |
|
803 | 803 | } |
804 | 804 | } else { |
805 | - $this->data[ $prop ] = $value; |
|
805 | + $this->data[$prop] = $value; |
|
806 | 806 | } |
807 | 807 | } |
808 | 808 | } |
@@ -823,7 +823,7 @@ discard block |
||
823 | 823 | * @since 1.0.19 |
824 | 824 | */ |
825 | 825 | public function apply_changes() { |
826 | - $this->data = array_replace( $this->data, $this->changes ); |
|
826 | + $this->data = array_replace($this->data, $this->changes); |
|
827 | 827 | $this->changes = array(); |
828 | 828 | } |
829 | 829 | |
@@ -848,14 +848,14 @@ discard block |
||
848 | 848 | * @param string $context What the value is for. Valid values are view and edit. |
849 | 849 | * @return mixed |
850 | 850 | */ |
851 | - protected function get_prop( $prop, $context = 'view' ) { |
|
851 | + protected function get_prop($prop, $context = 'view') { |
|
852 | 852 | $value = null; |
853 | 853 | |
854 | - if ( array_key_exists( $prop, $this->data ) ) { |
|
855 | - $value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ]; |
|
854 | + if (array_key_exists($prop, $this->data)) { |
|
855 | + $value = array_key_exists($prop, $this->changes) ? $this->changes[$prop] : $this->data[$prop]; |
|
856 | 856 | |
857 | - if ( 'view' === $context ) { |
|
858 | - $value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this ); |
|
857 | + if ('view' === $context) { |
|
858 | + $value = apply_filters($this->get_hook_prefix() . $prop, $value, $this); |
|
859 | 859 | } |
860 | 860 | } |
861 | 861 | |
@@ -869,13 +869,13 @@ discard block |
||
869 | 869 | * @param string $prop Name of prop to set. |
870 | 870 | * @param string|integer $value Value of the prop. |
871 | 871 | */ |
872 | - protected function set_date_prop( $prop, $value ) { |
|
872 | + protected function set_date_prop($prop, $value) { |
|
873 | 873 | |
874 | - if ( empty( $value ) ) { |
|
875 | - $this->set_prop( $prop, null ); |
|
874 | + if (empty($value)) { |
|
875 | + $this->set_prop($prop, null); |
|
876 | 876 | return; |
877 | 877 | } |
878 | - $this->set_prop( $prop, $value ); |
|
878 | + $this->set_prop($prop, $value); |
|
879 | 879 | |
880 | 880 | } |
881 | 881 | |
@@ -886,7 +886,7 @@ discard block |
||
886 | 886 | * @param string $code Error code. |
887 | 887 | * @param string $message Error message. |
888 | 888 | */ |
889 | - protected function error( $code, $message ) { |
|
889 | + protected function error($code, $message) { |
|
890 | 890 | $this->last_error = $message; |
891 | 891 | } |
892 | 892 | |
@@ -898,7 +898,7 @@ discard block |
||
898 | 898 | */ |
899 | 899 | public function exists() { |
900 | 900 | $id = $this->get_id(); |
901 | - return ! empty( $id ); |
|
901 | + return !empty($id); |
|
902 | 902 | } |
903 | 903 | |
904 | 904 | } |
@@ -4,99 +4,99 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Displays an invoice. |
11 | 11 | * |
12 | 12 | * @param WPInv_Invoice $invoice. |
13 | 13 | */ |
14 | -function getpaid_invoice( $invoice ) { |
|
15 | - if ( ! empty( $invoice ) ) { |
|
16 | - wpinv_get_template( 'invoice/invoice.php', compact( 'invoice' ) ); |
|
14 | +function getpaid_invoice($invoice) { |
|
15 | + if (!empty($invoice)) { |
|
16 | + wpinv_get_template('invoice/invoice.php', compact('invoice')); |
|
17 | 17 | } |
18 | 18 | } |
19 | -add_action( 'getpaid_invoice', 'getpaid_invoice', 10 ); |
|
19 | +add_action('getpaid_invoice', 'getpaid_invoice', 10); |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * Displays the invoice footer. |
23 | 23 | */ |
24 | -function getpaid_invoice_footer( $invoice ) { |
|
25 | - if ( ! empty( $invoice ) ) { |
|
26 | - wpinv_get_template( 'invoice/footer.php', compact( 'invoice' ) ); |
|
24 | +function getpaid_invoice_footer($invoice) { |
|
25 | + if (!empty($invoice)) { |
|
26 | + wpinv_get_template('invoice/footer.php', compact('invoice')); |
|
27 | 27 | } |
28 | 28 | } |
29 | -add_action( 'getpaid_invoice_footer', 'getpaid_invoice_footer', 10 ); |
|
29 | +add_action('getpaid_invoice_footer', 'getpaid_invoice_footer', 10); |
|
30 | 30 | |
31 | 31 | /** |
32 | 32 | * Displays the invoice top bar. |
33 | 33 | */ |
34 | -function getpaid_invoice_header( $invoice ) { |
|
35 | - if ( ! empty( $invoice ) ) { |
|
36 | - wpinv_get_template( 'invoice/header.php', compact( 'invoice' ) ); |
|
34 | +function getpaid_invoice_header($invoice) { |
|
35 | + if (!empty($invoice)) { |
|
36 | + wpinv_get_template('invoice/header.php', compact('invoice')); |
|
37 | 37 | } |
38 | 38 | } |
39 | -add_action( 'getpaid_invoice_header', 'getpaid_invoice_header', 10 ); |
|
39 | +add_action('getpaid_invoice_header', 'getpaid_invoice_header', 10); |
|
40 | 40 | |
41 | 41 | /** |
42 | 42 | * Displays actions on the left side of the header. |
43 | 43 | */ |
44 | -function getpaid_invoice_header_left_actions( $invoice ) { |
|
45 | - if ( ! empty( $invoice ) ) { |
|
46 | - wpinv_get_template( 'invoice/header-left-actions.php', compact( 'invoice' ) ); |
|
44 | +function getpaid_invoice_header_left_actions($invoice) { |
|
45 | + if (!empty($invoice)) { |
|
46 | + wpinv_get_template('invoice/header-left-actions.php', compact('invoice')); |
|
47 | 47 | } |
48 | 48 | } |
49 | -add_action( 'getpaid_invoice_header_left', 'getpaid_invoice_header_left_actions', 10 ); |
|
49 | +add_action('getpaid_invoice_header_left', 'getpaid_invoice_header_left_actions', 10); |
|
50 | 50 | |
51 | 51 | /** |
52 | 52 | * Displays actions on the right side of the invoice top bar. |
53 | 53 | */ |
54 | -function getpaid_invoice_header_right_actions( $invoice ) { |
|
55 | - if ( ! empty( $invoice ) ) { |
|
56 | - wpinv_get_template( 'invoice/header-right-actions.php', compact( 'invoice' ) ); |
|
54 | +function getpaid_invoice_header_right_actions($invoice) { |
|
55 | + if (!empty($invoice)) { |
|
56 | + wpinv_get_template('invoice/header-right-actions.php', compact('invoice')); |
|
57 | 57 | } |
58 | 58 | } |
59 | -add_action( 'getpaid_invoice_header_right', 'getpaid_invoice_header_right_actions', 10 ); |
|
59 | +add_action('getpaid_invoice_header_right', 'getpaid_invoice_header_right_actions', 10); |
|
60 | 60 | |
61 | 61 | /** |
62 | 62 | * Displays the invoice title, logo etc. |
63 | 63 | */ |
64 | -function getpaid_invoice_details_top( $invoice ) { |
|
65 | - if ( ! empty( $invoice ) ) { |
|
66 | - wpinv_get_template( 'invoice/details-top.php', compact( 'invoice' ) ); |
|
64 | +function getpaid_invoice_details_top($invoice) { |
|
65 | + if (!empty($invoice)) { |
|
66 | + wpinv_get_template('invoice/details-top.php', compact('invoice')); |
|
67 | 67 | } |
68 | 68 | } |
69 | -add_action( 'getpaid_invoice_details', 'getpaid_invoice_details_top', 10 ); |
|
69 | +add_action('getpaid_invoice_details', 'getpaid_invoice_details_top', 10); |
|
70 | 70 | |
71 | 71 | /** |
72 | 72 | * Displays the company logo. |
73 | 73 | */ |
74 | -function getpaid_invoice_logo( $invoice ) { |
|
75 | - if ( ! empty( $invoice ) ) { |
|
76 | - wpinv_get_template( 'invoice/invoice-logo.php', compact( 'invoice' ) ); |
|
74 | +function getpaid_invoice_logo($invoice) { |
|
75 | + if (!empty($invoice)) { |
|
76 | + wpinv_get_template('invoice/invoice-logo.php', compact('invoice')); |
|
77 | 77 | } |
78 | 78 | } |
79 | -add_action( 'getpaid_invoice_details_top_left', 'getpaid_invoice_logo' ); |
|
79 | +add_action('getpaid_invoice_details_top_left', 'getpaid_invoice_logo'); |
|
80 | 80 | |
81 | 81 | /** |
82 | 82 | * Displays the type of invoice. |
83 | 83 | */ |
84 | -function getpaid_invoice_type( $invoice ) { |
|
85 | - if ( ! empty( $invoice ) ) { |
|
86 | - wpinv_get_template( 'invoice/invoice-type.php', compact( 'invoice' ) ); |
|
84 | +function getpaid_invoice_type($invoice) { |
|
85 | + if (!empty($invoice)) { |
|
86 | + wpinv_get_template('invoice/invoice-type.php', compact('invoice')); |
|
87 | 87 | } |
88 | 88 | } |
89 | -add_action( 'getpaid_invoice_details_top_right', 'getpaid_invoice_type' ); |
|
89 | +add_action('getpaid_invoice_details_top_right', 'getpaid_invoice_type'); |
|
90 | 90 | |
91 | 91 | /** |
92 | 92 | * Displays the invoice details. |
93 | 93 | */ |
94 | -function getpaid_invoice_details_main( $invoice ) { |
|
95 | - if ( ! empty( $invoice ) ) { |
|
96 | - wpinv_get_template( 'invoice/details.php', compact( 'invoice' ) ); |
|
94 | +function getpaid_invoice_details_main($invoice) { |
|
95 | + if (!empty($invoice)) { |
|
96 | + wpinv_get_template('invoice/details.php', compact('invoice')); |
|
97 | 97 | } |
98 | 98 | } |
99 | -add_action( 'getpaid_invoice_details', 'getpaid_invoice_details_main', 50 ); |
|
99 | +add_action('getpaid_invoice_details', 'getpaid_invoice_details_main', 50); |
|
100 | 100 | |
101 | 101 | /** |
102 | 102 | * Returns a path to the templates directory. |
@@ -125,8 +125,8 @@ discard block |
||
125 | 125 | * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'. |
126 | 126 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
127 | 127 | */ |
128 | -function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
129 | - getpaid_template()->display_template( $template_name, $args, $template_path, $default_path ); |
|
128 | +function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
129 | + getpaid_template()->display_template($template_name, $args, $template_path, $default_path); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -139,8 +139,8 @@ discard block |
||
139 | 139 | * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'. |
140 | 140 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
141 | 141 | */ |
142 | -function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
143 | - return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path ); |
|
142 | +function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
143 | + return getpaid_template()->get_template($template_name, $args, $template_path, $default_path); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * @return string |
150 | 150 | */ |
151 | 151 | function wpinv_template_path() { |
152 | - return apply_filters( 'wpinv_template_path', wpinv_get_theme_template_dir_name() ); |
|
152 | + return apply_filters('wpinv_template_path', wpinv_get_theme_template_dir_name()); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | * @return string |
159 | 159 | */ |
160 | 160 | function wpinv_get_theme_template_dir_name() { |
161 | - return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
161 | + return trailingslashit(apply_filters('wpinv_templates_dir', 'invoicing')); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -170,56 +170,56 @@ discard block |
||
170 | 170 | * @param string $template_path The template path relative to the theme's root dir. Defaults to 'invoicing'. |
171 | 171 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
172 | 172 | */ |
173 | -function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) { |
|
174 | - return getpaid_template()->locate_template( $template_name, $template_path, $default_path ); |
|
173 | +function wpinv_locate_template($template_name, $template_path = '', $default_path = '') { |
|
174 | + return getpaid_template()->locate_template($template_name, $template_path, $default_path); |
|
175 | 175 | } |
176 | 176 | |
177 | -function wpinv_get_template_part( $slug, $name = null, $load = true ) { |
|
178 | - do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
177 | +function wpinv_get_template_part($slug, $name = null, $load = true) { |
|
178 | + do_action('get_template_part_' . $slug, $slug, $name); |
|
179 | 179 | |
180 | 180 | // Setup possible parts |
181 | 181 | $templates = array(); |
182 | - if ( isset( $name ) ) |
|
182 | + if (isset($name)) |
|
183 | 183 | $templates[] = $slug . '-' . $name . '.php'; |
184 | 184 | $templates[] = $slug . '.php'; |
185 | 185 | |
186 | 186 | // Allow template parts to be filtered |
187 | - $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
187 | + $templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name); |
|
188 | 188 | |
189 | 189 | // Return the part that is found |
190 | - return wpinv_locate_tmpl( $templates, $load, false ); |
|
190 | + return wpinv_locate_tmpl($templates, $load, false); |
|
191 | 191 | } |
192 | 192 | |
193 | -function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) { |
|
193 | +function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) { |
|
194 | 194 | // No file found yet |
195 | 195 | $located = false; |
196 | 196 | |
197 | 197 | // Try to find a template file |
198 | - foreach ( (array)$template_names as $template_name ) { |
|
198 | + foreach ((array) $template_names as $template_name) { |
|
199 | 199 | |
200 | 200 | // Continue if template is empty |
201 | - if ( empty( $template_name ) ) |
|
201 | + if (empty($template_name)) |
|
202 | 202 | continue; |
203 | 203 | |
204 | 204 | // Trim off any slashes from the template name |
205 | - $template_name = ltrim( $template_name, '/' ); |
|
205 | + $template_name = ltrim($template_name, '/'); |
|
206 | 206 | |
207 | 207 | // try locating this template file by looping through the template paths |
208 | - foreach( wpinv_get_theme_template_paths() as $template_path ) { |
|
208 | + foreach (wpinv_get_theme_template_paths() as $template_path) { |
|
209 | 209 | |
210 | - if( file_exists( $template_path . $template_name ) ) { |
|
210 | + if (file_exists($template_path . $template_name)) { |
|
211 | 211 | $located = $template_path . $template_name; |
212 | 212 | break; |
213 | 213 | } |
214 | 214 | } |
215 | 215 | |
216 | - if( !empty( $located ) ) { |
|
216 | + if (!empty($located)) { |
|
217 | 217 | break; |
218 | 218 | } |
219 | 219 | } |
220 | 220 | |
221 | - if ( ( true == $load ) && ! empty( $located ) ) |
|
222 | - load_template( $located, $require_once ); |
|
221 | + if ((true == $load) && !empty($located)) |
|
222 | + load_template($located, $require_once); |
|
223 | 223 | |
224 | 224 | return $located; |
225 | 225 | } |
@@ -228,127 +228,127 @@ discard block |
||
228 | 228 | $template_dir = wpinv_get_theme_template_dir_name(); |
229 | 229 | |
230 | 230 | $file_paths = array( |
231 | - 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
232 | - 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
231 | + 1 => trailingslashit(get_stylesheet_directory()) . $template_dir, |
|
232 | + 10 => trailingslashit(get_template_directory()) . $template_dir, |
|
233 | 233 | 100 => wpinv_get_templates_dir() |
234 | 234 | ); |
235 | 235 | |
236 | - $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
236 | + $file_paths = apply_filters('wpinv_template_paths', $file_paths); |
|
237 | 237 | |
238 | 238 | // sort the file paths based on priority |
239 | - ksort( $file_paths, SORT_NUMERIC ); |
|
239 | + ksort($file_paths, SORT_NUMERIC); |
|
240 | 240 | |
241 | - return array_map( 'trailingslashit', $file_paths ); |
|
241 | + return array_map('trailingslashit', $file_paths); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | function wpinv_checkout_meta_tags() { |
245 | 245 | |
246 | 246 | $pages = array(); |
247 | - $pages[] = wpinv_get_option( 'success_page' ); |
|
248 | - $pages[] = wpinv_get_option( 'failure_page' ); |
|
249 | - $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
250 | - $pages[] = wpinv_get_option( 'invoice_subscription_page' ); |
|
247 | + $pages[] = wpinv_get_option('success_page'); |
|
248 | + $pages[] = wpinv_get_option('failure_page'); |
|
249 | + $pages[] = wpinv_get_option('invoice_history_page'); |
|
250 | + $pages[] = wpinv_get_option('invoice_subscription_page'); |
|
251 | 251 | |
252 | - if( !wpinv_is_checkout() && !is_page( $pages ) ) { |
|
252 | + if (!wpinv_is_checkout() && !is_page($pages)) { |
|
253 | 253 | return; |
254 | 254 | } |
255 | 255 | |
256 | 256 | echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
257 | 257 | } |
258 | -add_action( 'wp_head', 'wpinv_checkout_meta_tags' ); |
|
258 | +add_action('wp_head', 'wpinv_checkout_meta_tags'); |
|
259 | 259 | |
260 | -function wpinv_add_body_classes( $class ) { |
|
261 | - $classes = (array)$class; |
|
260 | +function wpinv_add_body_classes($class) { |
|
261 | + $classes = (array) $class; |
|
262 | 262 | |
263 | - if( wpinv_is_checkout() ) { |
|
263 | + if (wpinv_is_checkout()) { |
|
264 | 264 | $classes[] = 'wpinv-checkout'; |
265 | 265 | $classes[] = 'wpinv-page'; |
266 | 266 | } |
267 | 267 | |
268 | - if( wpinv_is_success_page() ) { |
|
268 | + if (wpinv_is_success_page()) { |
|
269 | 269 | $classes[] = 'wpinv-success'; |
270 | 270 | $classes[] = 'wpinv-page'; |
271 | 271 | } |
272 | 272 | |
273 | - if( wpinv_is_failed_transaction_page() ) { |
|
273 | + if (wpinv_is_failed_transaction_page()) { |
|
274 | 274 | $classes[] = 'wpinv-failed-transaction'; |
275 | 275 | $classes[] = 'wpinv-page'; |
276 | 276 | } |
277 | 277 | |
278 | - if( wpinv_is_invoice_history_page() ) { |
|
278 | + if (wpinv_is_invoice_history_page()) { |
|
279 | 279 | $classes[] = 'wpinv-history'; |
280 | 280 | $classes[] = 'wpinv-page'; |
281 | 281 | } |
282 | 282 | |
283 | - if( wpinv_is_subscriptions_history_page() ) { |
|
283 | + if (wpinv_is_subscriptions_history_page()) { |
|
284 | 284 | $classes[] = 'wpinv-subscription'; |
285 | 285 | $classes[] = 'wpinv-page'; |
286 | 286 | } |
287 | 287 | |
288 | - if( wpinv_is_test_mode() ) { |
|
288 | + if (wpinv_is_test_mode()) { |
|
289 | 289 | $classes[] = 'wpinv-test-mode'; |
290 | 290 | $classes[] = 'wpinv-page'; |
291 | 291 | } |
292 | 292 | |
293 | - return array_unique( $classes ); |
|
293 | + return array_unique($classes); |
|
294 | 294 | } |
295 | -add_filter( 'body_class', 'wpinv_add_body_classes' ); |
|
295 | +add_filter('body_class', 'wpinv_add_body_classes'); |
|
296 | 296 | |
297 | -function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) { |
|
298 | - $current = date( 'Y' ); |
|
299 | - $start_year = $current - absint( $years_before ); |
|
300 | - $end_year = $current + absint( $years_after ); |
|
301 | - $selected = empty( $selected ) ? date( 'Y' ) : $selected; |
|
297 | +function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) { |
|
298 | + $current = date('Y'); |
|
299 | + $start_year = $current - absint($years_before); |
|
300 | + $end_year = $current + absint($years_after); |
|
301 | + $selected = empty($selected) ? date('Y') : $selected; |
|
302 | 302 | $options = array(); |
303 | 303 | |
304 | - while ( $start_year <= $end_year ) { |
|
305 | - $options[ absint( $start_year ) ] = $start_year; |
|
304 | + while ($start_year <= $end_year) { |
|
305 | + $options[absint($start_year)] = $start_year; |
|
306 | 306 | $start_year++; |
307 | 307 | } |
308 | 308 | |
309 | - $output = wpinv_html_select( array( |
|
309 | + $output = wpinv_html_select(array( |
|
310 | 310 | 'name' => $name, |
311 | 311 | 'selected' => $selected, |
312 | 312 | 'options' => $options, |
313 | 313 | 'show_option_all' => false, |
314 | 314 | 'show_option_none' => false |
315 | - ) ); |
|
315 | + )); |
|
316 | 316 | |
317 | 317 | return $output; |
318 | 318 | } |
319 | 319 | |
320 | -function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) { |
|
320 | +function wpinv_html_month_dropdown($name = 'month', $selected = 0) { |
|
321 | 321 | |
322 | 322 | $options = array( |
323 | - '1' => __( 'January', 'invoicing' ), |
|
324 | - '2' => __( 'February', 'invoicing' ), |
|
325 | - '3' => __( 'March', 'invoicing' ), |
|
326 | - '4' => __( 'April', 'invoicing' ), |
|
327 | - '5' => __( 'May', 'invoicing' ), |
|
328 | - '6' => __( 'June', 'invoicing' ), |
|
329 | - '7' => __( 'July', 'invoicing' ), |
|
330 | - '8' => __( 'August', 'invoicing' ), |
|
331 | - '9' => __( 'September', 'invoicing' ), |
|
332 | - '10' => __( 'October', 'invoicing' ), |
|
333 | - '11' => __( 'November', 'invoicing' ), |
|
334 | - '12' => __( 'December', 'invoicing' ), |
|
323 | + '1' => __('January', 'invoicing'), |
|
324 | + '2' => __('February', 'invoicing'), |
|
325 | + '3' => __('March', 'invoicing'), |
|
326 | + '4' => __('April', 'invoicing'), |
|
327 | + '5' => __('May', 'invoicing'), |
|
328 | + '6' => __('June', 'invoicing'), |
|
329 | + '7' => __('July', 'invoicing'), |
|
330 | + '8' => __('August', 'invoicing'), |
|
331 | + '9' => __('September', 'invoicing'), |
|
332 | + '10' => __('October', 'invoicing'), |
|
333 | + '11' => __('November', 'invoicing'), |
|
334 | + '12' => __('December', 'invoicing'), |
|
335 | 335 | ); |
336 | 336 | |
337 | 337 | // If no month is selected, default to the current month |
338 | - $selected = empty( $selected ) ? date( 'n' ) : $selected; |
|
338 | + $selected = empty($selected) ? date('n') : $selected; |
|
339 | 339 | |
340 | - $output = wpinv_html_select( array( |
|
340 | + $output = wpinv_html_select(array( |
|
341 | 341 | 'name' => $name, |
342 | 342 | 'selected' => $selected, |
343 | 343 | 'options' => $options, |
344 | 344 | 'show_option_all' => false, |
345 | 345 | 'show_option_none' => false |
346 | - ) ); |
|
346 | + )); |
|
347 | 347 | |
348 | 348 | return $output; |
349 | 349 | } |
350 | 350 | |
351 | -function wpinv_html_select( $args = array() ) { |
|
351 | +function wpinv_html_select($args = array()) { |
|
352 | 352 | $defaults = array( |
353 | 353 | 'options' => array(), |
354 | 354 | 'name' => null, |
@@ -357,8 +357,8 @@ discard block |
||
357 | 357 | 'selected' => 0, |
358 | 358 | 'placeholder' => null, |
359 | 359 | 'multiple' => false, |
360 | - 'show_option_all' => _x( 'All', 'all dropdown items', 'invoicing' ), |
|
361 | - 'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ), |
|
360 | + 'show_option_all' => _x('All', 'all dropdown items', 'invoicing'), |
|
361 | + 'show_option_none' => _x('None', 'no dropdown items', 'invoicing'), |
|
362 | 362 | 'data' => array(), |
363 | 363 | 'onchange' => null, |
364 | 364 | 'required' => false, |
@@ -366,74 +366,74 @@ discard block |
||
366 | 366 | 'readonly' => false, |
367 | 367 | ); |
368 | 368 | |
369 | - $args = wp_parse_args( $args, $defaults ); |
|
369 | + $args = wp_parse_args($args, $defaults); |
|
370 | 370 | |
371 | 371 | $data_elements = ''; |
372 | - foreach ( $args['data'] as $key => $value ) { |
|
373 | - $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"'; |
|
372 | + foreach ($args['data'] as $key => $value) { |
|
373 | + $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"'; |
|
374 | 374 | } |
375 | 375 | |
376 | - if( $args['multiple'] ) { |
|
376 | + if ($args['multiple']) { |
|
377 | 377 | $multiple = ' MULTIPLE'; |
378 | 378 | } else { |
379 | 379 | $multiple = ''; |
380 | 380 | } |
381 | 381 | |
382 | - if( $args['placeholder'] ) { |
|
382 | + if ($args['placeholder']) { |
|
383 | 383 | $placeholder = $args['placeholder']; |
384 | 384 | } else { |
385 | 385 | $placeholder = ''; |
386 | 386 | } |
387 | 387 | |
388 | 388 | $options = ''; |
389 | - if( !empty( $args['onchange'] ) ) { |
|
390 | - $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"'; |
|
389 | + if (!empty($args['onchange'])) { |
|
390 | + $options .= ' onchange="' . esc_attr($args['onchange']) . '"'; |
|
391 | 391 | } |
392 | 392 | |
393 | - if( !empty( $args['required'] ) ) { |
|
393 | + if (!empty($args['required'])) { |
|
394 | 394 | $options .= ' required="required"'; |
395 | 395 | } |
396 | 396 | |
397 | - if( !empty( $args['disabled'] ) ) { |
|
397 | + if (!empty($args['disabled'])) { |
|
398 | 398 | $options .= ' disabled'; |
399 | 399 | } |
400 | 400 | |
401 | - if( !empty( $args['readonly'] ) ) { |
|
401 | + if (!empty($args['readonly'])) { |
|
402 | 402 | $options .= ' readonly'; |
403 | 403 | } |
404 | 404 | |
405 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
406 | - $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>'; |
|
405 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
406 | + $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>'; |
|
407 | 407 | |
408 | - if ( $args['show_option_all'] ) { |
|
409 | - if( $args['multiple'] ) { |
|
410 | - $selected = selected( true, in_array( 0, $args['selected'] ), false ); |
|
408 | + if ($args['show_option_all']) { |
|
409 | + if ($args['multiple']) { |
|
410 | + $selected = selected(true, in_array(0, $args['selected']), false); |
|
411 | 411 | } else { |
412 | - $selected = selected( $args['selected'], 0, false ); |
|
412 | + $selected = selected($args['selected'], 0, false); |
|
413 | 413 | } |
414 | - $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>'; |
|
414 | + $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>'; |
|
415 | 415 | } |
416 | 416 | |
417 | - if ( !empty( $args['options'] ) ) { |
|
417 | + if (!empty($args['options'])) { |
|
418 | 418 | |
419 | - if ( $args['show_option_none'] ) { |
|
420 | - if( $args['multiple'] ) { |
|
421 | - $selected = selected( true, in_array( "", $args['selected'] ), false ); |
|
419 | + if ($args['show_option_none']) { |
|
420 | + if ($args['multiple']) { |
|
421 | + $selected = selected(true, in_array("", $args['selected']), false); |
|
422 | 422 | } else { |
423 | - $selected = selected( $args['selected'] === "", true, false ); |
|
423 | + $selected = selected($args['selected'] === "", true, false); |
|
424 | 424 | } |
425 | - $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>'; |
|
425 | + $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>'; |
|
426 | 426 | } |
427 | 427 | |
428 | - foreach( $args['options'] as $key => $option ) { |
|
428 | + foreach ($args['options'] as $key => $option) { |
|
429 | 429 | |
430 | - if( $args['multiple'] && is_array( $args['selected'] ) ) { |
|
431 | - $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false ); |
|
430 | + if ($args['multiple'] && is_array($args['selected'])) { |
|
431 | + $selected = selected(true, (bool) in_array($key, $args['selected']), false); |
|
432 | 432 | } else { |
433 | - $selected = selected( $args['selected'], $key, false ); |
|
433 | + $selected = selected($args['selected'], $key, false); |
|
434 | 434 | } |
435 | 435 | |
436 | - $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>'; |
|
436 | + $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>'; |
|
437 | 437 | } |
438 | 438 | } |
439 | 439 | |
@@ -442,7 +442,7 @@ discard block |
||
442 | 442 | return $output; |
443 | 443 | } |
444 | 444 | |
445 | -function wpinv_item_dropdown( $args = array() ) { |
|
445 | +function wpinv_item_dropdown($args = array()) { |
|
446 | 446 | $defaults = array( |
447 | 447 | 'name' => 'wpi_item', |
448 | 448 | 'id' => 'wpi_item', |
@@ -450,14 +450,14 @@ discard block |
||
450 | 450 | 'multiple' => false, |
451 | 451 | 'selected' => 0, |
452 | 452 | 'number' => 100, |
453 | - 'placeholder' => __( 'Choose a item', 'invoicing' ), |
|
454 | - 'data' => array( 'search-type' => 'item' ), |
|
453 | + 'placeholder' => __('Choose a item', 'invoicing'), |
|
454 | + 'data' => array('search-type' => 'item'), |
|
455 | 455 | 'show_option_all' => false, |
456 | 456 | 'show_option_none' => false, |
457 | 457 | 'show_recurring' => false, |
458 | 458 | ); |
459 | 459 | |
460 | - $args = wp_parse_args( $args, $defaults ); |
|
460 | + $args = wp_parse_args($args, $defaults); |
|
461 | 461 | |
462 | 462 | $item_args = array( |
463 | 463 | 'post_type' => 'wpi_item', |
@@ -466,44 +466,44 @@ discard block |
||
466 | 466 | 'posts_per_page' => $args['number'] |
467 | 467 | ); |
468 | 468 | |
469 | - $item_args = apply_filters( 'wpinv_item_dropdown_query_args', $item_args, $args, $defaults ); |
|
469 | + $item_args = apply_filters('wpinv_item_dropdown_query_args', $item_args, $args, $defaults); |
|
470 | 470 | |
471 | - $items = get_posts( $item_args ); |
|
471 | + $items = get_posts($item_args); |
|
472 | 472 | $options = array(); |
473 | - if ( $items ) { |
|
474 | - foreach ( $items as $item ) { |
|
475 | - $title = esc_html( $item->post_title ); |
|
473 | + if ($items) { |
|
474 | + foreach ($items as $item) { |
|
475 | + $title = esc_html($item->post_title); |
|
476 | 476 | |
477 | - if ( !empty( $args['show_recurring'] ) ) { |
|
478 | - $title .= wpinv_get_item_suffix( $item->ID, false ); |
|
477 | + if (!empty($args['show_recurring'])) { |
|
478 | + $title .= wpinv_get_item_suffix($item->ID, false); |
|
479 | 479 | } |
480 | 480 | |
481 | - $options[ absint( $item->ID ) ] = $title; |
|
481 | + $options[absint($item->ID)] = $title; |
|
482 | 482 | } |
483 | 483 | } |
484 | 484 | |
485 | 485 | // This ensures that any selected items are included in the drop down |
486 | - if( is_array( $args['selected'] ) ) { |
|
487 | - foreach( $args['selected'] as $item ) { |
|
488 | - if( ! in_array( $item, $options ) ) { |
|
489 | - $title = get_the_title( $item ); |
|
490 | - if ( !empty( $args['show_recurring'] ) ) { |
|
491 | - $title .= wpinv_get_item_suffix( $item, false ); |
|
486 | + if (is_array($args['selected'])) { |
|
487 | + foreach ($args['selected'] as $item) { |
|
488 | + if (!in_array($item, $options)) { |
|
489 | + $title = get_the_title($item); |
|
490 | + if (!empty($args['show_recurring'])) { |
|
491 | + $title .= wpinv_get_item_suffix($item, false); |
|
492 | 492 | } |
493 | 493 | $options[$item] = $title; |
494 | 494 | } |
495 | 495 | } |
496 | - } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) { |
|
497 | - if ( ! in_array( $args['selected'], $options ) ) { |
|
498 | - $title = get_the_title( $args['selected'] ); |
|
499 | - if ( !empty( $args['show_recurring'] ) ) { |
|
500 | - $title .= wpinv_get_item_suffix( $args['selected'], false ); |
|
496 | + } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) { |
|
497 | + if (!in_array($args['selected'], $options)) { |
|
498 | + $title = get_the_title($args['selected']); |
|
499 | + if (!empty($args['show_recurring'])) { |
|
500 | + $title .= wpinv_get_item_suffix($args['selected'], false); |
|
501 | 501 | } |
502 | - $options[$args['selected']] = get_the_title( $args['selected'] ); |
|
502 | + $options[$args['selected']] = get_the_title($args['selected']); |
|
503 | 503 | } |
504 | 504 | } |
505 | 505 | |
506 | - $output = wpinv_html_select( array( |
|
506 | + $output = wpinv_html_select(array( |
|
507 | 507 | 'name' => $args['name'], |
508 | 508 | 'selected' => $args['selected'], |
509 | 509 | 'id' => $args['id'], |
@@ -514,7 +514,7 @@ discard block |
||
514 | 514 | 'show_option_all' => $args['show_option_all'], |
515 | 515 | 'show_option_none' => $args['show_option_none'], |
516 | 516 | 'data' => $args['data'], |
517 | - ) ); |
|
517 | + )); |
|
518 | 518 | |
519 | 519 | return $output; |
520 | 520 | } |
@@ -534,16 +534,16 @@ discard block |
||
534 | 534 | ); |
535 | 535 | |
536 | 536 | $options = array(); |
537 | - if ( $items ) { |
|
538 | - foreach ( $items as $item ) { |
|
539 | - $options[ $item->ID ] = esc_html( $item->post_title ) . wpinv_get_item_suffix( $item->ID, false ); |
|
537 | + if ($items) { |
|
538 | + foreach ($items as $item) { |
|
539 | + $options[$item->ID] = esc_html($item->post_title) . wpinv_get_item_suffix($item->ID, false); |
|
540 | 540 | } |
541 | 541 | } |
542 | 542 | |
543 | 543 | return $options; |
544 | 544 | } |
545 | 545 | |
546 | -function wpinv_html_checkbox( $args = array() ) { |
|
546 | +function wpinv_html_checkbox($args = array()) { |
|
547 | 547 | $defaults = array( |
548 | 548 | 'name' => null, |
549 | 549 | 'current' => null, |
@@ -554,17 +554,17 @@ discard block |
||
554 | 554 | ) |
555 | 555 | ); |
556 | 556 | |
557 | - $args = wp_parse_args( $args, $defaults ); |
|
557 | + $args = wp_parse_args($args, $defaults); |
|
558 | 558 | |
559 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
559 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
560 | 560 | $options = ''; |
561 | - if ( ! empty( $args['options']['disabled'] ) ) { |
|
561 | + if (!empty($args['options']['disabled'])) { |
|
562 | 562 | $options .= ' disabled="disabled"'; |
563 | - } elseif ( ! empty( $args['options']['readonly'] ) ) { |
|
563 | + } elseif (!empty($args['options']['readonly'])) { |
|
564 | 564 | $options .= ' readonly'; |
565 | 565 | } |
566 | 566 | |
567 | - $output = '<input type="checkbox"' . $options . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $class . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />'; |
|
567 | + $output = '<input type="checkbox"' . $options . ' name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . $class . ' ' . esc_attr($args['name']) . '" ' . checked(1, $args['current'], false) . ' />'; |
|
568 | 568 | |
569 | 569 | return $output; |
570 | 570 | } |
@@ -572,9 +572,9 @@ discard block |
||
572 | 572 | /** |
573 | 573 | * Displays a hidden field. |
574 | 574 | */ |
575 | -function getpaid_hidden_field( $name, $value ) { |
|
576 | - $name = sanitize_text_field( $name ); |
|
577 | - $value = esc_attr( $value ); |
|
575 | +function getpaid_hidden_field($name, $value) { |
|
576 | + $name = sanitize_text_field($name); |
|
577 | + $value = esc_attr($value); |
|
578 | 578 | |
579 | 579 | echo "<input type='hidden' name='$name' value='$value' />"; |
580 | 580 | } |
@@ -582,31 +582,31 @@ discard block |
||
582 | 582 | /** |
583 | 583 | * Displays a submit field. |
584 | 584 | */ |
585 | -function getpaid_submit_field( $value, $name = 'submit', $class = 'btn-primary' ) { |
|
586 | - $name = sanitize_text_field( $name ); |
|
587 | - $value = esc_attr( $value ); |
|
588 | - $class = esc_attr( $class ); |
|
585 | +function getpaid_submit_field($value, $name = 'submit', $class = 'btn-primary') { |
|
586 | + $name = sanitize_text_field($name); |
|
587 | + $value = esc_attr($value); |
|
588 | + $class = esc_attr($class); |
|
589 | 589 | |
590 | 590 | echo "<input type='submit' name='$name' value='$value' class='btn $class' />"; |
591 | 591 | } |
592 | 592 | |
593 | -function wpinv_html_text( $args = array() ) { |
|
593 | +function wpinv_html_text($args = array()) { |
|
594 | 594 | // Backwards compatibility |
595 | - if ( func_num_args() > 1 ) { |
|
595 | + if (func_num_args() > 1) { |
|
596 | 596 | $args = func_get_args(); |
597 | 597 | |
598 | 598 | $name = $args[0]; |
599 | - $value = isset( $args[1] ) ? $args[1] : ''; |
|
600 | - $label = isset( $args[2] ) ? $args[2] : ''; |
|
601 | - $desc = isset( $args[3] ) ? $args[3] : ''; |
|
599 | + $value = isset($args[1]) ? $args[1] : ''; |
|
600 | + $label = isset($args[2]) ? $args[2] : ''; |
|
601 | + $desc = isset($args[3]) ? $args[3] : ''; |
|
602 | 602 | } |
603 | 603 | |
604 | 604 | $defaults = array( |
605 | 605 | 'id' => '', |
606 | - 'name' => isset( $name ) ? $name : 'text', |
|
607 | - 'value' => isset( $value ) ? $value : null, |
|
608 | - 'label' => isset( $label ) ? $label : null, |
|
609 | - 'desc' => isset( $desc ) ? $desc : null, |
|
606 | + 'name' => isset($name) ? $name : 'text', |
|
607 | + 'value' => isset($value) ? $value : null, |
|
608 | + 'label' => isset($label) ? $label : null, |
|
609 | + 'desc' => isset($desc) ? $desc : null, |
|
610 | 610 | 'placeholder' => '', |
611 | 611 | 'class' => 'regular-text', |
612 | 612 | 'disabled' => false, |
@@ -616,41 +616,41 @@ discard block |
||
616 | 616 | 'data' => false |
617 | 617 | ); |
618 | 618 | |
619 | - $args = wp_parse_args( $args, $defaults ); |
|
619 | + $args = wp_parse_args($args, $defaults); |
|
620 | 620 | |
621 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
621 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
622 | 622 | $options = ''; |
623 | - if( $args['required'] ) { |
|
623 | + if ($args['required']) { |
|
624 | 624 | $options .= ' required="required"'; |
625 | 625 | } |
626 | - if( $args['readonly'] ) { |
|
626 | + if ($args['readonly']) { |
|
627 | 627 | $options .= ' readonly'; |
628 | 628 | } |
629 | - if( $args['readonly'] ) { |
|
629 | + if ($args['readonly']) { |
|
630 | 630 | $options .= ' readonly'; |
631 | 631 | } |
632 | 632 | |
633 | 633 | $data = ''; |
634 | - if ( !empty( $args['data'] ) ) { |
|
635 | - foreach ( $args['data'] as $key => $value ) { |
|
636 | - $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" '; |
|
634 | + if (!empty($args['data'])) { |
|
635 | + foreach ($args['data'] as $key => $value) { |
|
636 | + $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" '; |
|
637 | 637 | } |
638 | 638 | } |
639 | 639 | |
640 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
641 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
642 | - if ( ! empty( $args['desc'] ) ) { |
|
643 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
640 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
641 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>'; |
|
642 | + if (!empty($args['desc'])) { |
|
643 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
644 | 644 | } |
645 | 645 | |
646 | - $output .= '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" autocomplete="' . esc_attr( $args['autocomplete'] ) . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $class . '" ' . $data . ' ' . trim( $options ) . '/>'; |
|
646 | + $output .= '<input type="text" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" autocomplete="' . esc_attr($args['autocomplete']) . '" value="' . esc_attr($args['value']) . '" placeholder="' . esc_attr($args['placeholder']) . '" class="' . $class . '" ' . $data . ' ' . trim($options) . '/>'; |
|
647 | 647 | |
648 | 648 | $output .= '</span>'; |
649 | 649 | |
650 | 650 | return $output; |
651 | 651 | } |
652 | 652 | |
653 | -function wpinv_html_textarea( $args = array() ) { |
|
653 | +function wpinv_html_textarea($args = array()) { |
|
654 | 654 | $defaults = array( |
655 | 655 | 'name' => 'textarea', |
656 | 656 | 'value' => null, |
@@ -661,31 +661,31 @@ discard block |
||
661 | 661 | 'placeholder' => '', |
662 | 662 | ); |
663 | 663 | |
664 | - $args = wp_parse_args( $args, $defaults ); |
|
664 | + $args = wp_parse_args($args, $defaults); |
|
665 | 665 | |
666 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
666 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
667 | 667 | $disabled = ''; |
668 | - if( $args['disabled'] ) { |
|
668 | + if ($args['disabled']) { |
|
669 | 669 | $disabled = ' disabled="disabled"'; |
670 | 670 | } |
671 | 671 | |
672 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
673 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
674 | - $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>'; |
|
672 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
673 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>'; |
|
674 | + $output .= '<textarea name="' . esc_attr($args['name']) . '" placeholder="' . esc_attr($args['placeholder']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>'; |
|
675 | 675 | |
676 | - if ( ! empty( $args['desc'] ) ) { |
|
677 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
676 | + if (!empty($args['desc'])) { |
|
677 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
678 | 678 | } |
679 | 679 | $output .= '</span>'; |
680 | 680 | |
681 | 681 | return $output; |
682 | 682 | } |
683 | 683 | |
684 | -function wpinv_html_ajax_user_search( $args = array() ) { |
|
684 | +function wpinv_html_ajax_user_search($args = array()) { |
|
685 | 685 | $defaults = array( |
686 | 686 | 'name' => 'user_id', |
687 | 687 | 'value' => null, |
688 | - 'placeholder' => __( 'Enter username', 'invoicing' ), |
|
688 | + 'placeholder' => __('Enter username', 'invoicing'), |
|
689 | 689 | 'label' => null, |
690 | 690 | 'desc' => null, |
691 | 691 | 'class' => '', |
@@ -694,13 +694,13 @@ discard block |
||
694 | 694 | 'data' => false |
695 | 695 | ); |
696 | 696 | |
697 | - $args = wp_parse_args( $args, $defaults ); |
|
697 | + $args = wp_parse_args($args, $defaults); |
|
698 | 698 | |
699 | 699 | $args['class'] = 'wpinv-ajax-user-search ' . $args['class']; |
700 | 700 | |
701 | 701 | $output = '<span class="wpinv_user_search_wrap">'; |
702 | - $output .= wpinv_html_text( $args ); |
|
703 | - $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __( 'Cancel', 'invoicing' ) . '" aria-label="' . __( 'Cancel', 'invoicing' ) . '" href="#">x</a><span></span></span>'; |
|
702 | + $output .= wpinv_html_text($args); |
|
703 | + $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __('Cancel', 'invoicing') . '" aria-label="' . __('Cancel', 'invoicing') . '" href="#">x</a><span></span></span>'; |
|
704 | 704 | $output .= '</span>'; |
705 | 705 | |
706 | 706 | return $output; |
@@ -711,20 +711,20 @@ discard block |
||
711 | 711 | * |
712 | 712 | * @param string $template the template that is currently being used. |
713 | 713 | */ |
714 | -function wpinv_template( $template ) { |
|
714 | +function wpinv_template($template) { |
|
715 | 715 | global $post; |
716 | 716 | |
717 | - if ( ! is_admin() && ( is_single() || is_404() ) && ! empty( $post->ID ) && getpaid_is_invoice_post_type( get_post_type( $post->ID ) ) ) { |
|
717 | + if (!is_admin() && (is_single() || is_404()) && !empty($post->ID) && getpaid_is_invoice_post_type(get_post_type($post->ID))) { |
|
718 | 718 | |
719 | 719 | // If the user can view this invoice, display it. |
720 | - if ( wpinv_user_can_view_invoice( $post->ID ) ) { |
|
720 | + if (wpinv_user_can_view_invoice($post->ID)) { |
|
721 | 721 | |
722 | - return wpinv_get_template_part( 'wpinv-invoice-print', false, false ); |
|
722 | + return wpinv_get_template_part('wpinv-invoice-print', false, false); |
|
723 | 723 | |
724 | 724 | // Else display an error message. |
725 | 725 | } else { |
726 | 726 | |
727 | - return wpinv_get_template_part( 'wpinv-invalid-access', false, false ); |
|
727 | + return wpinv_get_template_part('wpinv-invalid-access', false, false); |
|
728 | 728 | |
729 | 729 | } |
730 | 730 | |
@@ -732,24 +732,24 @@ discard block |
||
732 | 732 | |
733 | 733 | return $template; |
734 | 734 | } |
735 | -add_filter( 'template_include', 'wpinv_template', 10, 1 ); |
|
735 | +add_filter('template_include', 'wpinv_template', 10, 1); |
|
736 | 736 | |
737 | 737 | function wpinv_get_business_address() { |
738 | 738 | $business_address = wpinv_store_address(); |
739 | - $business_address = !empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : ''; |
|
739 | + $business_address = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : ''; |
|
740 | 740 | |
741 | 741 | $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : ''; |
742 | 742 | |
743 | - return apply_filters( 'wpinv_get_business_address', $business_address ); |
|
743 | + return apply_filters('wpinv_get_business_address', $business_address); |
|
744 | 744 | } |
745 | 745 | |
746 | 746 | /** |
747 | 747 | * Displays the company address. |
748 | 748 | */ |
749 | 749 | function wpinv_display_from_address() { |
750 | - wpinv_get_template( 'invoice/company-address.php' ); |
|
750 | + wpinv_get_template('invoice/company-address.php'); |
|
751 | 751 | } |
752 | -add_action( 'getpaid_invoice_details_left', 'wpinv_display_from_address', 10 ); |
|
752 | +add_action('getpaid_invoice_details_left', 'wpinv_display_from_address', 10); |
|
753 | 753 | |
754 | 754 | /** |
755 | 755 | * Generates a watermark text for an invoice. |
@@ -757,9 +757,9 @@ discard block |
||
757 | 757 | * @param WPInv_Invoice $invoice |
758 | 758 | * @return string |
759 | 759 | */ |
760 | -function wpinv_watermark( $invoice ) { |
|
761 | - $watermark = wpinv_get_watermark( $invoice ); |
|
762 | - return apply_filters( 'wpinv_get_watermark', $watermark, $invoice ); |
|
760 | +function wpinv_watermark($invoice) { |
|
761 | + $watermark = wpinv_get_watermark($invoice); |
|
762 | + return apply_filters('wpinv_get_watermark', $watermark, $invoice); |
|
763 | 763 | } |
764 | 764 | |
765 | 765 | /** |
@@ -768,37 +768,37 @@ discard block |
||
768 | 768 | * @param WPInv_Invoice $invoice |
769 | 769 | * @return string |
770 | 770 | */ |
771 | -function wpinv_get_watermark( $invoice ) { |
|
771 | +function wpinv_get_watermark($invoice) { |
|
772 | 772 | return $invoice->get_status_nicename(); |
773 | 773 | } |
774 | 774 | |
775 | 775 | /** |
776 | 776 | * @deprecated |
777 | 777 | */ |
778 | -function wpinv_display_invoice_details( $invoice ) { |
|
779 | - return getpaid_invoice_meta( $invoice ); |
|
778 | +function wpinv_display_invoice_details($invoice) { |
|
779 | + return getpaid_invoice_meta($invoice); |
|
780 | 780 | } |
781 | 781 | |
782 | 782 | /** |
783 | 783 | * Displays invoice meta. |
784 | 784 | */ |
785 | -function getpaid_invoice_meta( $invoice ) { |
|
785 | +function getpaid_invoice_meta($invoice) { |
|
786 | 786 | |
787 | - $invoice = new WPInv_Invoice( $invoice ); |
|
787 | + $invoice = new WPInv_Invoice($invoice); |
|
788 | 788 | |
789 | 789 | // Ensure that we have an invoice. |
790 | - if ( 0 == $invoice->get_id() ) { |
|
790 | + if (0 == $invoice->get_id()) { |
|
791 | 791 | return; |
792 | 792 | } |
793 | 793 | |
794 | 794 | // Get the invoice meta. |
795 | - $meta = getpaid_get_invoice_meta( $invoice ); |
|
795 | + $meta = getpaid_get_invoice_meta($invoice); |
|
796 | 796 | |
797 | 797 | // Display the meta. |
798 | - wpinv_get_template( 'invoice/invoice-meta.php', compact( 'invoice', 'meta' ) ); |
|
798 | + wpinv_get_template('invoice/invoice-meta.php', compact('invoice', 'meta')); |
|
799 | 799 | |
800 | 800 | } |
801 | -add_action( 'getpaid_invoice_details_right', 'getpaid_invoice_meta', 10 ); |
|
801 | +add_action('getpaid_invoice_details_right', 'getpaid_invoice_meta', 10); |
|
802 | 802 | |
803 | 803 | /** |
804 | 804 | * Retrieves the address markup to use on Invoices. |
@@ -810,29 +810,29 @@ discard block |
||
810 | 810 | * @param string $separator How to separate address lines. |
811 | 811 | * @return string |
812 | 812 | */ |
813 | -function wpinv_get_invoice_address_markup( $billing_details, $separator = '<br/>' ) { |
|
813 | +function wpinv_get_invoice_address_markup($billing_details, $separator = '<br/>') { |
|
814 | 814 | |
815 | 815 | // Retrieve the address markup... |
816 | - $country= empty( $billing_details['country'] ) ? '' : $billing_details['country']; |
|
817 | - $format = wpinv_get_full_address_format( $country ); |
|
816 | + $country = empty($billing_details['country']) ? '' : $billing_details['country']; |
|
817 | + $format = wpinv_get_full_address_format($country); |
|
818 | 818 | |
819 | 819 | // ... and the replacements. |
820 | - $replacements = wpinv_get_invoice_address_replacements( $billing_details ); |
|
820 | + $replacements = wpinv_get_invoice_address_replacements($billing_details); |
|
821 | 821 | |
822 | - $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format ); |
|
822 | + $formatted_address = str_ireplace(array_keys($replacements), $replacements, $format); |
|
823 | 823 | |
824 | 824 | // Remove unavailable tags. |
825 | - $formatted_address = preg_replace( "/\{\{\w+\}\}/", '', $formatted_address ); |
|
825 | + $formatted_address = preg_replace("/\{\{\w+\}\}/", '', $formatted_address); |
|
826 | 826 | |
827 | 827 | // Clean up white space. |
828 | - $formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) ); |
|
829 | - $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address ); |
|
828 | + $formatted_address = preg_replace('/ +/', ' ', trim($formatted_address)); |
|
829 | + $formatted_address = preg_replace('/\n\n+/', "\n", $formatted_address); |
|
830 | 830 | |
831 | 831 | // Break newlines apart and remove empty lines/trim commas and white space. |
832 | - $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) ); |
|
832 | + $formatted_address = array_filter(array_map('wpinv_trim_formatted_address_line', explode("\n", $formatted_address))); |
|
833 | 833 | |
834 | 834 | // Add html breaks. |
835 | - $formatted_address = implode( $separator, $formatted_address ); |
|
835 | + $formatted_address = implode($separator, $formatted_address); |
|
836 | 836 | |
837 | 837 | // We're done! |
838 | 838 | return $formatted_address; |
@@ -844,88 +844,88 @@ discard block |
||
844 | 844 | * |
845 | 845 | * @param WPInv_Invoice $invoice |
846 | 846 | */ |
847 | -function wpinv_display_to_address( $invoice = 0 ) { |
|
848 | - if ( ! empty( $invoice ) ) { |
|
849 | - wpinv_get_template( 'invoice/billing-address.php', compact( 'invoice' ) ); |
|
847 | +function wpinv_display_to_address($invoice = 0) { |
|
848 | + if (!empty($invoice)) { |
|
849 | + wpinv_get_template('invoice/billing-address.php', compact('invoice')); |
|
850 | 850 | } |
851 | 851 | } |
852 | -add_action( 'getpaid_invoice_details_left', 'wpinv_display_to_address', 40 ); |
|
852 | +add_action('getpaid_invoice_details_left', 'wpinv_display_to_address', 40); |
|
853 | 853 | |
854 | 854 | |
855 | 855 | /** |
856 | 856 | * Displays invoice line items. |
857 | 857 | */ |
858 | -function wpinv_display_line_items( $invoice_id = 0 ) { |
|
858 | +function wpinv_display_line_items($invoice_id = 0) { |
|
859 | 859 | |
860 | 860 | // Prepare the invoice. |
861 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
861 | + $invoice = new WPInv_Invoice($invoice_id); |
|
862 | 862 | |
863 | 863 | // Abort if there is no invoice. |
864 | - if ( 0 == $invoice->get_id() ) { |
|
864 | + if (0 == $invoice->get_id()) { |
|
865 | 865 | return; |
866 | 866 | } |
867 | 867 | |
868 | 868 | // Line item columns. |
869 | - $columns = getpaid_invoice_item_columns( $invoice ); |
|
870 | - $columns = apply_filters( 'getpaid_invoice_line_items_table_columns', $columns, $invoice ); |
|
869 | + $columns = getpaid_invoice_item_columns($invoice); |
|
870 | + $columns = apply_filters('getpaid_invoice_line_items_table_columns', $columns, $invoice); |
|
871 | 871 | |
872 | - wpinv_get_template( 'invoice/line-items.php', compact( 'invoice', 'columns' ) ); |
|
872 | + wpinv_get_template('invoice/line-items.php', compact('invoice', 'columns')); |
|
873 | 873 | } |
874 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_line_items', 10 ); |
|
874 | +add_action('getpaid_invoice_line_items', 'wpinv_display_line_items', 10); |
|
875 | 875 | |
876 | 876 | /** |
877 | 877 | * Displays invoice notices on invoices. |
878 | 878 | */ |
879 | 879 | function wpinv_display_invoice_notice() { |
880 | 880 | |
881 | - $label = wpinv_get_option( 'vat_invoice_notice_label' ); |
|
882 | - $notice = wpinv_get_option( 'vat_invoice_notice' ); |
|
881 | + $label = wpinv_get_option('vat_invoice_notice_label'); |
|
882 | + $notice = wpinv_get_option('vat_invoice_notice'); |
|
883 | 883 | |
884 | - if ( empty( $label ) && empty( $notice ) ) { |
|
884 | + if (empty($label) && empty($notice)) { |
|
885 | 885 | return; |
886 | 886 | } |
887 | 887 | |
888 | 888 | echo '<div class="mt-4 mb-4 wpinv-vat-notice">'; |
889 | 889 | |
890 | - if ( ! empty( $label ) ) { |
|
891 | - $label = sanitize_text_field( $label ); |
|
890 | + if (!empty($label)) { |
|
891 | + $label = sanitize_text_field($label); |
|
892 | 892 | echo "<h5>$label</h5>"; |
893 | 893 | } |
894 | 894 | |
895 | - if ( ! empty( $notice ) ) { |
|
896 | - echo '<small class="form-text text-muted">' . wpautop( wptexturize( $notice ) ) . '</small>'; |
|
895 | + if (!empty($notice)) { |
|
896 | + echo '<small class="form-text text-muted">' . wpautop(wptexturize($notice)) . '</small>'; |
|
897 | 897 | } |
898 | 898 | |
899 | 899 | echo '</div>'; |
900 | 900 | } |
901 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100 ); |
|
901 | +add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100); |
|
902 | 902 | |
903 | 903 | /** |
904 | 904 | * @param WPInv_Invoice $invoice |
905 | 905 | */ |
906 | -function wpinv_display_invoice_notes( $invoice ) { |
|
906 | +function wpinv_display_invoice_notes($invoice) { |
|
907 | 907 | |
908 | 908 | // Retrieve the notes. |
909 | - $notes = wpinv_get_invoice_notes( $invoice->get_id(), 'customer' ); |
|
909 | + $notes = wpinv_get_invoice_notes($invoice->get_id(), 'customer'); |
|
910 | 910 | |
911 | 911 | // Abort if we have non. |
912 | - if ( empty( $notes ) ) { |
|
912 | + if (empty($notes)) { |
|
913 | 913 | return; |
914 | 914 | } |
915 | 915 | |
916 | 916 | // Echo the note. |
917 | 917 | echo '<div class="getpaid-invoice-notes-wrapper position-relative my-4">'; |
918 | - echo '<h2 class="getpaid-invoice-notes-title mb-1 p-0 h4">' . __( 'Notes', 'invoicing' ) .'</h2>'; |
|
918 | + echo '<h2 class="getpaid-invoice-notes-title mb-1 p-0 h4">' . __('Notes', 'invoicing') . '</h2>'; |
|
919 | 919 | echo '<ul class="getpaid-invoice-notes text-break overflow-auto list-unstyled p-0 m-0">'; |
920 | 920 | |
921 | - foreach( $notes as $note ) { |
|
922 | - wpinv_get_invoice_note_line_item( $note ); |
|
921 | + foreach ($notes as $note) { |
|
922 | + wpinv_get_invoice_note_line_item($note); |
|
923 | 923 | } |
924 | 924 | |
925 | 925 | echo '</ul>'; |
926 | 926 | echo '</div>'; |
927 | 927 | } |
928 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60 ); |
|
928 | +add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60); |
|
929 | 929 | |
930 | 930 | /** |
931 | 931 | * Loads scripts on our invoice templates. |
@@ -933,31 +933,31 @@ discard block |
||
933 | 933 | function wpinv_display_style() { |
934 | 934 | |
935 | 935 | // Make sure that all scripts have been loaded. |
936 | - if ( ! did_action( 'wp_enqueue_scripts' ) ) { |
|
937 | - do_action( 'wp_enqueue_scripts' ); |
|
936 | + if (!did_action('wp_enqueue_scripts')) { |
|
937 | + do_action('wp_enqueue_scripts'); |
|
938 | 938 | } |
939 | 939 | |
940 | 940 | // Register the invoices style. |
941 | - wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice.css' ) ); |
|
941 | + wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime(WPINV_PLUGIN_DIR . 'assets/css/invoice.css')); |
|
942 | 942 | |
943 | 943 | // Load required styles |
944 | - wp_print_styles( 'wpinv-single-style' ); |
|
945 | - wp_print_styles( 'ayecode-ui' ); |
|
944 | + wp_print_styles('wpinv-single-style'); |
|
945 | + wp_print_styles('ayecode-ui'); |
|
946 | 946 | |
947 | 947 | // Maybe load custom css. |
948 | - $custom_css = wpinv_get_option( 'template_custom_css' ); |
|
948 | + $custom_css = wpinv_get_option('template_custom_css'); |
|
949 | 949 | |
950 | - if ( isset( $custom_css ) && ! empty( $custom_css ) ) { |
|
951 | - $custom_css = wp_kses( $custom_css, array( '\'', '\"' ) ); |
|
952 | - $custom_css = str_replace( '>', '>', $custom_css ); |
|
950 | + if (isset($custom_css) && !empty($custom_css)) { |
|
951 | + $custom_css = wp_kses($custom_css, array('\'', '\"')); |
|
952 | + $custom_css = str_replace('>', '>', $custom_css); |
|
953 | 953 | echo '<style type="text/css">'; |
954 | 954 | echo $custom_css; |
955 | 955 | echo '</style>'; |
956 | 956 | } |
957 | 957 | |
958 | 958 | } |
959 | -add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' ); |
|
960 | -add_action( 'wpinv_invalid_invoice_head', 'wpinv_display_style' ); |
|
959 | +add_action('wpinv_invoice_print_head', 'wpinv_display_style'); |
|
960 | +add_action('wpinv_invalid_invoice_head', 'wpinv_display_style'); |
|
961 | 961 | |
962 | 962 | |
963 | 963 | /** |
@@ -969,41 +969,41 @@ discard block |
||
969 | 969 | // Retrieve the current invoice. |
970 | 970 | $invoice_id = getpaid_get_current_invoice_id(); |
971 | 971 | |
972 | - if ( empty( $invoice_id ) ) { |
|
972 | + if (empty($invoice_id)) { |
|
973 | 973 | |
974 | 974 | return aui()->alert( |
975 | 975 | array( |
976 | 976 | 'type' => 'warning', |
977 | - 'content' => __( 'Invalid invoice', 'invoicing' ), |
|
977 | + 'content' => __('Invalid invoice', 'invoicing'), |
|
978 | 978 | ) |
979 | 979 | ); |
980 | 980 | |
981 | 981 | } |
982 | 982 | |
983 | 983 | // Can the user view this invoice? |
984 | - if ( ! wpinv_user_can_view_invoice( $invoice_id ) ) { |
|
984 | + if (!wpinv_user_can_view_invoice($invoice_id)) { |
|
985 | 985 | |
986 | 986 | return aui()->alert( |
987 | 987 | array( |
988 | 988 | 'type' => 'warning', |
989 | - 'content' => __( 'You are not allowed to view this invoice', 'invoicing' ), |
|
989 | + 'content' => __('You are not allowed to view this invoice', 'invoicing'), |
|
990 | 990 | ) |
991 | 991 | ); |
992 | 992 | |
993 | 993 | } |
994 | 994 | |
995 | 995 | // Ensure that it is not yet paid for. |
996 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
996 | + $invoice = new WPInv_Invoice($invoice_id); |
|
997 | 997 | |
998 | 998 | // Maybe mark it as viewed. |
999 | - getpaid_maybe_mark_invoice_as_viewed( $invoice ); |
|
999 | + getpaid_maybe_mark_invoice_as_viewed($invoice); |
|
1000 | 1000 | |
1001 | - if ( $invoice->is_paid() ) { |
|
1001 | + if ($invoice->is_paid()) { |
|
1002 | 1002 | |
1003 | 1003 | return aui()->alert( |
1004 | 1004 | array( |
1005 | 1005 | 'type' => 'success', |
1006 | - 'content' => __( 'This invoice has already been paid.', 'invoicing' ), |
|
1006 | + 'content' => __('This invoice has already been paid.', 'invoicing'), |
|
1007 | 1007 | ) |
1008 | 1008 | ); |
1009 | 1009 | |
@@ -1013,15 +1013,15 @@ discard block |
||
1013 | 1013 | $wpi_checkout_id = $invoice_id; |
1014 | 1014 | |
1015 | 1015 | // Retrieve appropriate payment form. |
1016 | - $payment_form = new GetPaid_Payment_Form( $invoice->get_meta( 'force_payment_form' ) ); |
|
1017 | - $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
1016 | + $payment_form = new GetPaid_Payment_Form($invoice->get_meta('force_payment_form')); |
|
1017 | + $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
1018 | 1018 | |
1019 | - if ( ! $payment_form->exists() ) { |
|
1019 | + if (!$payment_form->exists()) { |
|
1020 | 1020 | |
1021 | 1021 | return aui()->alert( |
1022 | 1022 | array( |
1023 | 1023 | 'type' => 'warning', |
1024 | - 'content' => __( 'Error loading the payment form', 'invoicing' ), |
|
1024 | + 'content' => __('Error loading the payment form', 'invoicing'), |
|
1025 | 1025 | ) |
1026 | 1026 | ); |
1027 | 1027 | |
@@ -1030,29 +1030,29 @@ discard block |
||
1030 | 1030 | // Set the invoice. |
1031 | 1031 | $payment_form->invoice = $invoice; |
1032 | 1032 | |
1033 | - if ( ! $payment_form->is_default() ) { |
|
1033 | + if (!$payment_form->is_default()) { |
|
1034 | 1034 | |
1035 | 1035 | $items = array(); |
1036 | 1036 | $item_ids = array(); |
1037 | 1037 | |
1038 | - foreach ( $invoice->get_items() as $item ) { |
|
1039 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
1038 | + foreach ($invoice->get_items() as $item) { |
|
1039 | + if (!in_array($item->get_id(), $item_ids)) { |
|
1040 | 1040 | $item_ids[] = $item->get_id(); |
1041 | 1041 | $items[] = $item; |
1042 | 1042 | } |
1043 | 1043 | } |
1044 | 1044 | |
1045 | - foreach ( $payment_form->get_items() as $item ) { |
|
1046 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
1045 | + foreach ($payment_form->get_items() as $item) { |
|
1046 | + if (!in_array($item->get_id(), $item_ids)) { |
|
1047 | 1047 | $item_ids[] = $item->get_id(); |
1048 | 1048 | $items[] = $item; |
1049 | 1049 | } |
1050 | 1050 | } |
1051 | 1051 | |
1052 | - $payment_form->set_items( $items ); |
|
1052 | + $payment_form->set_items($items); |
|
1053 | 1053 | |
1054 | 1054 | } else { |
1055 | - $payment_form->set_items( $invoice->get_items() ); |
|
1055 | + $payment_form->set_items($invoice->get_items()); |
|
1056 | 1056 | } |
1057 | 1057 | |
1058 | 1058 | // Generate the html. |
@@ -1061,7 +1061,7 @@ discard block |
||
1061 | 1061 | } |
1062 | 1062 | |
1063 | 1063 | function wpinv_empty_cart_message() { |
1064 | - return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1064 | + return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>'); |
|
1065 | 1065 | } |
1066 | 1066 | |
1067 | 1067 | /** |
@@ -1078,71 +1078,71 @@ discard block |
||
1078 | 1078 | ) |
1079 | 1079 | ); |
1080 | 1080 | } |
1081 | -add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' ); |
|
1081 | +add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart'); |
|
1082 | 1082 | |
1083 | 1083 | /** |
1084 | 1084 | * Filters the receipt page. |
1085 | 1085 | */ |
1086 | -function wpinv_filter_success_page_content( $content ) { |
|
1086 | +function wpinv_filter_success_page_content($content) { |
|
1087 | 1087 | |
1088 | 1088 | // Ensure this is our page. |
1089 | - if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) { |
|
1089 | + if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) { |
|
1090 | 1090 | |
1091 | - $gateway = sanitize_text_field( $_GET['payment-confirm'] ); |
|
1092 | - return apply_filters( "wpinv_payment_confirm_$gateway", $content ); |
|
1091 | + $gateway = sanitize_text_field($_GET['payment-confirm']); |
|
1092 | + return apply_filters("wpinv_payment_confirm_$gateway", $content); |
|
1093 | 1093 | |
1094 | 1094 | } |
1095 | 1095 | |
1096 | 1096 | return $content; |
1097 | 1097 | } |
1098 | -add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 ); |
|
1098 | +add_filter('the_content', 'wpinv_filter_success_page_content', 99999); |
|
1099 | 1099 | |
1100 | -function wpinv_invoice_link( $invoice_id ) { |
|
1101 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1100 | +function wpinv_invoice_link($invoice_id) { |
|
1101 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1102 | 1102 | |
1103 | - if ( empty( $invoice ) ) { |
|
1103 | + if (empty($invoice)) { |
|
1104 | 1104 | return NULL; |
1105 | 1105 | } |
1106 | 1106 | |
1107 | - $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>'; |
|
1107 | + $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>'; |
|
1108 | 1108 | |
1109 | - return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice ); |
|
1109 | + return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice); |
|
1110 | 1110 | } |
1111 | 1111 | |
1112 | -function wpinv_get_invoice_note_line_item( $note, $echo = true ) { |
|
1113 | - if ( empty( $note ) ) { |
|
1112 | +function wpinv_get_invoice_note_line_item($note, $echo = true) { |
|
1113 | + if (empty($note)) { |
|
1114 | 1114 | return NULL; |
1115 | 1115 | } |
1116 | 1116 | |
1117 | - if ( is_int( $note ) ) { |
|
1118 | - $note = get_comment( $note ); |
|
1117 | + if (is_int($note)) { |
|
1118 | + $note = get_comment($note); |
|
1119 | 1119 | } |
1120 | 1120 | |
1121 | - if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) { |
|
1121 | + if (!(is_object($note) && is_a($note, 'WP_Comment'))) { |
|
1122 | 1122 | return NULL; |
1123 | 1123 | } |
1124 | 1124 | |
1125 | - $note_classes = array( 'note' ); |
|
1126 | - $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : ''; |
|
1125 | + $note_classes = array('note'); |
|
1126 | + $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : ''; |
|
1127 | 1127 | $note_classes[] = $note->comment_author === 'System' ? 'system-note' : ''; |
1128 | - $note_classes = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note ); |
|
1129 | - $note_classes = !empty( $note_classes ) ? implode( ' ', $note_classes ) : ''; |
|
1128 | + $note_classes = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note); |
|
1129 | + $note_classes = !empty($note_classes) ? implode(' ', $note_classes) : ''; |
|
1130 | 1130 | |
1131 | 1131 | ob_start(); |
1132 | 1132 | ?> |
1133 | - <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?> mb-2"> |
|
1133 | + <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?> mb-2"> |
|
1134 | 1134 | <div class="note_content"> |
1135 | 1135 | |
1136 | - <?php echo wptexturize( wp_kses_post( $note->comment_content ) ); ?> |
|
1136 | + <?php echo wptexturize(wp_kses_post($note->comment_content)); ?> |
|
1137 | 1137 | |
1138 | - <?php if ( ! is_admin() ) : ?> |
|
1138 | + <?php if (!is_admin()) : ?> |
|
1139 | 1139 | <em class="small form-text text-muted mt-0"> |
1140 | 1140 | <?php |
1141 | 1141 | printf( |
1142 | - __( '%1$s - %2$s at %3$s', 'invoicing' ), |
|
1142 | + __('%1$s - %2$s at %3$s', 'invoicing'), |
|
1143 | 1143 | $note->comment_author, |
1144 | - getpaid_format_date_value( $note->comment_date ), |
|
1145 | - date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) |
|
1144 | + getpaid_format_date_value($note->comment_date), |
|
1145 | + date_i18n(get_option('time_format'), strtotime($note->comment_date)) |
|
1146 | 1146 | ); |
1147 | 1147 | ?> |
1148 | 1148 | </em> |
@@ -1150,21 +1150,21 @@ discard block |
||
1150 | 1150 | |
1151 | 1151 | </div> |
1152 | 1152 | |
1153 | - <?php if ( is_admin() ) : ?> |
|
1153 | + <?php if (is_admin()) : ?> |
|
1154 | 1154 | |
1155 | 1155 | <p class="meta px-4 py-2"> |
1156 | - <abbr class="exact-date" title="<?php echo esc_attr( $note->comment_date ); ?>"> |
|
1156 | + <abbr class="exact-date" title="<?php echo esc_attr($note->comment_date); ?>"> |
|
1157 | 1157 | <?php |
1158 | 1158 | printf( |
1159 | - __( '%1$s - %2$s at %3$s', 'invoicing' ), |
|
1159 | + __('%1$s - %2$s at %3$s', 'invoicing'), |
|
1160 | 1160 | $note->comment_author, |
1161 | - getpaid_format_date_value( $note->comment_date ), |
|
1162 | - date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) |
|
1161 | + getpaid_format_date_value($note->comment_date), |
|
1162 | + date_i18n(get_option('time_format'), strtotime($note->comment_date)) |
|
1163 | 1163 | ); |
1164 | 1164 | ?> |
1165 | 1165 | </abbr> |
1166 | - <?php if ( $note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing() ) { ?> |
|
1167 | - <a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a> |
|
1166 | + <?php if ($note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing()) { ?> |
|
1167 | + <a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a> |
|
1168 | 1168 | <?php } ?> |
1169 | 1169 | </p> |
1170 | 1170 | |
@@ -1173,9 +1173,9 @@ discard block |
||
1173 | 1173 | </li> |
1174 | 1174 | <?php |
1175 | 1175 | $note_content = ob_get_clean(); |
1176 | - $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo ); |
|
1176 | + $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo); |
|
1177 | 1177 | |
1178 | - if ( $echo ) { |
|
1178 | + if ($echo) { |
|
1179 | 1179 | echo $note_content; |
1180 | 1180 | } else { |
1181 | 1181 | return $note_content; |
@@ -1189,21 +1189,21 @@ discard block |
||
1189 | 1189 | * @return string |
1190 | 1190 | */ |
1191 | 1191 | function wpinv_get_policy_text() { |
1192 | - $privacy_page_id = get_option( 'wp_page_for_privacy_policy', 0 ); |
|
1192 | + $privacy_page_id = get_option('wp_page_for_privacy_policy', 0); |
|
1193 | 1193 | |
1194 | - $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf( __( 'Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing' ), '[wpinv_privacy_policy]' )); |
|
1194 | + $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf(__('Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing'), '[wpinv_privacy_policy]')); |
|
1195 | 1195 | |
1196 | - if(!$privacy_page_id){ |
|
1197 | - $privacy_page_id = wpinv_get_option( 'privacy_page', 0 ); |
|
1196 | + if (!$privacy_page_id) { |
|
1197 | + $privacy_page_id = wpinv_get_option('privacy_page', 0); |
|
1198 | 1198 | } |
1199 | 1199 | |
1200 | - $privacy_link = $privacy_page_id ? '<a href="' . esc_url( get_permalink( $privacy_page_id ) ) . '" class="wpinv-privacy-policy-link" target="_blank">' . __( 'privacy policy', 'invoicing' ) . '</a>' : __( 'privacy policy', 'invoicing' ); |
|
1200 | + $privacy_link = $privacy_page_id ? '<a href="' . esc_url(get_permalink($privacy_page_id)) . '" class="wpinv-privacy-policy-link" target="_blank">' . __('privacy policy', 'invoicing') . '</a>' : __('privacy policy', 'invoicing'); |
|
1201 | 1201 | |
1202 | 1202 | $find_replace = array( |
1203 | 1203 | '[wpinv_privacy_policy]' => $privacy_link, |
1204 | 1204 | ); |
1205 | 1205 | |
1206 | - $privacy_text = str_replace( array_keys( $find_replace ), array_values( $find_replace ), $text ); |
|
1206 | + $privacy_text = str_replace(array_keys($find_replace), array_values($find_replace), $text); |
|
1207 | 1207 | |
1208 | 1208 | return wp_kses_post(wpautop($privacy_text)); |
1209 | 1209 | } |
@@ -1211,21 +1211,21 @@ discard block |
||
1211 | 1211 | function wpinv_oxygen_fix_conflict() { |
1212 | 1212 | global $ct_ignore_post_types; |
1213 | 1213 | |
1214 | - if ( ! is_array( $ct_ignore_post_types ) ) { |
|
1214 | + if (!is_array($ct_ignore_post_types)) { |
|
1215 | 1215 | $ct_ignore_post_types = array(); |
1216 | 1216 | } |
1217 | 1217 | |
1218 | - $post_types = array( 'wpi_discount', 'wpi_invoice', 'wpi_item', 'wpi_payment_form' ); |
|
1218 | + $post_types = array('wpi_discount', 'wpi_invoice', 'wpi_item', 'wpi_payment_form'); |
|
1219 | 1219 | |
1220 | - foreach ( $post_types as $post_type ) { |
|
1220 | + foreach ($post_types as $post_type) { |
|
1221 | 1221 | $ct_ignore_post_types[] = $post_type; |
1222 | 1222 | |
1223 | 1223 | // Ignore post type |
1224 | - add_filter( 'pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999 ); |
|
1224 | + add_filter('pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999); |
|
1225 | 1225 | } |
1226 | 1226 | |
1227 | - remove_filter( 'template_include', 'wpinv_template', 10, 1 ); |
|
1228 | - add_filter( 'template_include', 'wpinv_template', 999, 1 ); |
|
1227 | + remove_filter('template_include', 'wpinv_template', 10, 1); |
|
1228 | + add_filter('template_include', 'wpinv_template', 999, 1); |
|
1229 | 1229 | } |
1230 | 1230 | |
1231 | 1231 | /** |
@@ -1233,10 +1233,10 @@ discard block |
||
1233 | 1233 | * |
1234 | 1234 | * @param GetPaid_Payment_Form $form |
1235 | 1235 | */ |
1236 | -function getpaid_display_payment_form( $form ) { |
|
1236 | +function getpaid_display_payment_form($form) { |
|
1237 | 1237 | |
1238 | - if ( is_numeric( $form ) ) { |
|
1239 | - $form = new GetPaid_Payment_Form( $form ); |
|
1238 | + if (is_numeric($form)) { |
|
1239 | + $form = new GetPaid_Payment_Form($form); |
|
1240 | 1240 | } |
1241 | 1241 | |
1242 | 1242 | $form->display(); |
@@ -1246,55 +1246,55 @@ discard block |
||
1246 | 1246 | /** |
1247 | 1247 | * Helper function to display a item payment form on the frontend. |
1248 | 1248 | */ |
1249 | -function getpaid_display_item_payment_form( $items ) { |
|
1249 | +function getpaid_display_item_payment_form($items) { |
|
1250 | 1250 | |
1251 | - $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
1252 | - $form->set_items( $items ); |
|
1251 | + $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
1252 | + $form->set_items($items); |
|
1253 | 1253 | |
1254 | - if ( 0 == count( $form->get_items() ) ) { |
|
1254 | + if (0 == count($form->get_items())) { |
|
1255 | 1255 | echo aui()->alert( |
1256 | 1256 | array( |
1257 | 1257 | 'type' => 'warning', |
1258 | - 'content' => __( 'No published items found', 'invoicing' ), |
|
1258 | + 'content' => __('No published items found', 'invoicing'), |
|
1259 | 1259 | ) |
1260 | 1260 | ); |
1261 | 1261 | return; |
1262 | 1262 | } |
1263 | 1263 | |
1264 | - $form_items = esc_attr( getpaid_convert_items_to_string( $items ) ); |
|
1264 | + $form_items = esc_attr(getpaid_convert_items_to_string($items)); |
|
1265 | 1265 | $form_items = "<input type='hidden' name='getpaid-form-items' value='$form_items' />"; |
1266 | - $form->display( $form_items ); |
|
1266 | + $form->display($form_items); |
|
1267 | 1267 | } |
1268 | 1268 | |
1269 | 1269 | /** |
1270 | 1270 | * Helper function to display an invoice payment form on the frontend. |
1271 | 1271 | */ |
1272 | -function getpaid_display_invoice_payment_form( $invoice_id ) { |
|
1272 | +function getpaid_display_invoice_payment_form($invoice_id) { |
|
1273 | 1273 | |
1274 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1274 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1275 | 1275 | |
1276 | - if ( empty( $invoice ) ) { |
|
1276 | + if (empty($invoice)) { |
|
1277 | 1277 | echo aui()->alert( |
1278 | 1278 | array( |
1279 | 1279 | 'type' => 'warning', |
1280 | - 'content' => __( 'Invoice not found', 'invoicing' ), |
|
1280 | + 'content' => __('Invoice not found', 'invoicing'), |
|
1281 | 1281 | ) |
1282 | 1282 | ); |
1283 | 1283 | return; |
1284 | 1284 | } |
1285 | 1285 | |
1286 | - if ( $invoice->is_paid() ) { |
|
1286 | + if ($invoice->is_paid()) { |
|
1287 | 1287 | echo aui()->alert( |
1288 | 1288 | array( |
1289 | 1289 | 'type' => 'warning', |
1290 | - 'content' => __( 'Invoice has already been paid', 'invoicing' ), |
|
1290 | + 'content' => __('Invoice has already been paid', 'invoicing'), |
|
1291 | 1291 | ) |
1292 | 1292 | ); |
1293 | 1293 | return; |
1294 | 1294 | } |
1295 | 1295 | |
1296 | - $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
1297 | - $form->set_items( $invoice->get_items() ); |
|
1296 | + $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
1297 | + $form->set_items($invoice->get_items()); |
|
1298 | 1298 | |
1299 | 1299 | $form->display(); |
1300 | 1300 | } |
@@ -1302,23 +1302,23 @@ discard block |
||
1302 | 1302 | /** |
1303 | 1303 | * Helper function to convert item string to array. |
1304 | 1304 | */ |
1305 | -function getpaid_convert_items_to_array( $items ) { |
|
1306 | - $items = array_filter( array_map( 'trim', explode( ',', $items ) ) ); |
|
1305 | +function getpaid_convert_items_to_array($items) { |
|
1306 | + $items = array_filter(array_map('trim', explode(',', $items))); |
|
1307 | 1307 | $prepared = array(); |
1308 | 1308 | |
1309 | - foreach ( $items as $item ) { |
|
1310 | - $data = array_map( 'trim', explode( '|', $item ) ); |
|
1309 | + foreach ($items as $item) { |
|
1310 | + $data = array_map('trim', explode('|', $item)); |
|
1311 | 1311 | |
1312 | - if ( empty( $data[0] ) || ! is_numeric( $data[0] ) ) { |
|
1312 | + if (empty($data[0]) || !is_numeric($data[0])) { |
|
1313 | 1313 | continue; |
1314 | 1314 | } |
1315 | 1315 | |
1316 | 1316 | $quantity = 1; |
1317 | - if ( isset( $data[1] ) && is_numeric( $data[1] ) ) { |
|
1317 | + if (isset($data[1]) && is_numeric($data[1])) { |
|
1318 | 1318 | $quantity = (float) $data[1]; |
1319 | 1319 | } |
1320 | 1320 | |
1321 | - $prepared[ $data[0] ] = $quantity; |
|
1321 | + $prepared[$data[0]] = $quantity; |
|
1322 | 1322 | |
1323 | 1323 | } |
1324 | 1324 | |
@@ -1328,13 +1328,13 @@ discard block |
||
1328 | 1328 | /** |
1329 | 1329 | * Helper function to convert item array to string. |
1330 | 1330 | */ |
1331 | -function getpaid_convert_items_to_string( $items ) { |
|
1331 | +function getpaid_convert_items_to_string($items) { |
|
1332 | 1332 | $prepared = array(); |
1333 | 1333 | |
1334 | - foreach ( $items as $item => $quantity ) { |
|
1334 | + foreach ($items as $item => $quantity) { |
|
1335 | 1335 | $prepared[] = "$item|$quantity"; |
1336 | 1336 | } |
1337 | - return implode( ',', $prepared ); |
|
1337 | + return implode(',', $prepared); |
|
1338 | 1338 | } |
1339 | 1339 | |
1340 | 1340 | /** |
@@ -1342,21 +1342,21 @@ discard block |
||
1342 | 1342 | * |
1343 | 1343 | * Provide a label and one of $form, $items or $invoice. |
1344 | 1344 | */ |
1345 | -function getpaid_get_payment_button( $label, $form = null, $items = null, $invoice = null ) { |
|
1346 | - $label = sanitize_text_field( $label ); |
|
1345 | +function getpaid_get_payment_button($label, $form = null, $items = null, $invoice = null) { |
|
1346 | + $label = sanitize_text_field($label); |
|
1347 | 1347 | |
1348 | - if ( ! empty( $form ) ) { |
|
1349 | - $form = esc_attr( $form ); |
|
1348 | + if (!empty($form)) { |
|
1349 | + $form = esc_attr($form); |
|
1350 | 1350 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-form='$form'>$label</button>"; |
1351 | 1351 | } |
1352 | 1352 | |
1353 | - if ( ! empty( $items ) ) { |
|
1354 | - $items = esc_attr( $items ); |
|
1353 | + if (!empty($items)) { |
|
1354 | + $items = esc_attr($items); |
|
1355 | 1355 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-item='$items'>$label</button>"; |
1356 | 1356 | } |
1357 | 1357 | |
1358 | - if ( ! empty( $invoice ) ) { |
|
1359 | - $invoice = esc_attr( $invoice ); |
|
1358 | + if (!empty($invoice)) { |
|
1359 | + $invoice = esc_attr($invoice); |
|
1360 | 1360 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-invoice='$invoice'>$label</button>"; |
1361 | 1361 | } |
1362 | 1362 | |
@@ -1367,17 +1367,17 @@ discard block |
||
1367 | 1367 | * |
1368 | 1368 | * @param WPInv_Invoice $invoice |
1369 | 1369 | */ |
1370 | -function getpaid_the_invoice_description( $invoice ) { |
|
1370 | +function getpaid_the_invoice_description($invoice) { |
|
1371 | 1371 | $description = $invoice->get_description(); |
1372 | 1372 | |
1373 | - if ( empty( $description ) ) { |
|
1373 | + if (empty($description)) { |
|
1374 | 1374 | return; |
1375 | 1375 | } |
1376 | 1376 | |
1377 | - $description = wp_kses_post( $description ); |
|
1377 | + $description = wp_kses_post($description); |
|
1378 | 1378 | echo "<small class='getpaid-invoice-description text-dark p-2 form-text' style='margin-bottom: 20px; border-left: 2px solid #2196F3;'><em>$description</em></small>"; |
1379 | 1379 | } |
1380 | -add_action( 'getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100 ); |
|
1380 | +add_action('getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100); |
|
1381 | 1381 | |
1382 | 1382 | /** |
1383 | 1383 | * Render element on a form. |
@@ -1385,60 +1385,60 @@ discard block |
||
1385 | 1385 | * @param array $element |
1386 | 1386 | * @param GetPaid_Payment_Form $form |
1387 | 1387 | */ |
1388 | -function getpaid_payment_form_element( $element, $form ) { |
|
1388 | +function getpaid_payment_form_element($element, $form) { |
|
1389 | 1389 | |
1390 | 1390 | // Set up the args. |
1391 | - $element_type = trim( $element['type'] ); |
|
1391 | + $element_type = trim($element['type']); |
|
1392 | 1392 | $element['form'] = $form; |
1393 | - extract( $element ); |
|
1393 | + extract($element); |
|
1394 | 1394 | |
1395 | 1395 | // Try to locate the appropriate template. |
1396 | - $located = wpinv_locate_template( "payment-forms/elements/$element_type.php" ); |
|
1396 | + $located = wpinv_locate_template("payment-forms/elements/$element_type.php"); |
|
1397 | 1397 | |
1398 | 1398 | // Abort if this is not our element. |
1399 | - if ( empty( $located ) || ! file_exists( $located ) ) { |
|
1399 | + if (empty($located) || !file_exists($located)) { |
|
1400 | 1400 | return; |
1401 | 1401 | } |
1402 | 1402 | |
1403 | 1403 | // Generate the class and id of the element. |
1404 | - $wrapper_class = 'getpaid-payment-form-element-' . trim( esc_attr( $element_type ) ); |
|
1405 | - $id = isset( $id ) ? $id : uniqid( 'gp' ); |
|
1404 | + $wrapper_class = 'getpaid-payment-form-element-' . trim(esc_attr($element_type)); |
|
1405 | + $id = isset($id) ? $id : uniqid('gp'); |
|
1406 | 1406 | |
1407 | 1407 | // Echo the opening wrapper. |
1408 | 1408 | echo "<div class='getpaid-payment-form-element $wrapper_class'>"; |
1409 | 1409 | |
1410 | 1410 | // Fires before displaying a given element type's content. |
1411 | - do_action( "getpaid_before_payment_form_{$element_type}_element", $element, $form ); |
|
1411 | + do_action("getpaid_before_payment_form_{$element_type}_element", $element, $form); |
|
1412 | 1412 | |
1413 | 1413 | // Include the template for the element. |
1414 | 1414 | include $located; |
1415 | 1415 | |
1416 | 1416 | // Fires after displaying a given element type's content. |
1417 | - do_action( "getpaid_payment_form_{$element_type}_element", $element, $form ); |
|
1417 | + do_action("getpaid_payment_form_{$element_type}_element", $element, $form); |
|
1418 | 1418 | |
1419 | 1419 | // Echo the closing wrapper. |
1420 | 1420 | echo '</div>'; |
1421 | 1421 | } |
1422 | -add_action( 'getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2 ); |
|
1422 | +add_action('getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2); |
|
1423 | 1423 | |
1424 | 1424 | /** |
1425 | 1425 | * Render an element's edit page. |
1426 | 1426 | * |
1427 | 1427 | * @param WP_Post $post |
1428 | 1428 | */ |
1429 | -function getpaid_payment_form_edit_element_template( $post ) { |
|
1429 | +function getpaid_payment_form_edit_element_template($post) { |
|
1430 | 1430 | |
1431 | 1431 | // Retrieve all elements. |
1432 | - $all_elements = wp_list_pluck( wpinv_get_data( 'payment-form-elements' ), 'type' ); |
|
1432 | + $all_elements = wp_list_pluck(wpinv_get_data('payment-form-elements'), 'type'); |
|
1433 | 1433 | |
1434 | - foreach ( $all_elements as $element ) { |
|
1434 | + foreach ($all_elements as $element) { |
|
1435 | 1435 | |
1436 | 1436 | // Try to locate the appropriate template. |
1437 | - $element = sanitize_key( $element ); |
|
1438 | - $located = wpinv_locate_template( "payment-forms-admin/edit/$element.php" ); |
|
1437 | + $element = sanitize_key($element); |
|
1438 | + $located = wpinv_locate_template("payment-forms-admin/edit/$element.php"); |
|
1439 | 1439 | |
1440 | 1440 | // Continue if this is not our element. |
1441 | - if ( empty( $located ) || ! file_exists( $located ) ) { |
|
1441 | + if (empty($located) || !file_exists($located)) { |
|
1442 | 1442 | continue; |
1443 | 1443 | } |
1444 | 1444 | |
@@ -1449,7 +1449,7 @@ discard block |
||
1449 | 1449 | } |
1450 | 1450 | |
1451 | 1451 | } |
1452 | -add_action( 'getpaid_payment_form_edit_element_template', 'getpaid_payment_form_edit_element_template' ); |
|
1452 | +add_action('getpaid_payment_form_edit_element_template', 'getpaid_payment_form_edit_element_template'); |
|
1453 | 1453 | |
1454 | 1454 | /** |
1455 | 1455 | * Render an element's preview. |
@@ -1458,16 +1458,16 @@ discard block |
||
1458 | 1458 | function getpaid_payment_form_render_element_preview_template() { |
1459 | 1459 | |
1460 | 1460 | // Retrieve all elements. |
1461 | - $all_elements = wp_list_pluck( wpinv_get_data( 'payment-form-elements' ), 'type' ); |
|
1461 | + $all_elements = wp_list_pluck(wpinv_get_data('payment-form-elements'), 'type'); |
|
1462 | 1462 | |
1463 | - foreach ( $all_elements as $element ) { |
|
1463 | + foreach ($all_elements as $element) { |
|
1464 | 1464 | |
1465 | 1465 | // Try to locate the appropriate template. |
1466 | - $element = sanitize_key( $element ); |
|
1467 | - $located = wpinv_locate_template( "payment-forms-admin/previews/$element.php" ); |
|
1466 | + $element = sanitize_key($element); |
|
1467 | + $located = wpinv_locate_template("payment-forms-admin/previews/$element.php"); |
|
1468 | 1468 | |
1469 | 1469 | // Continue if this is not our element. |
1470 | - if ( empty( $located ) || ! file_exists( $located ) ) { |
|
1470 | + if (empty($located) || !file_exists($located)) { |
|
1471 | 1471 | continue; |
1472 | 1472 | } |
1473 | 1473 | |
@@ -1478,7 +1478,7 @@ discard block |
||
1478 | 1478 | } |
1479 | 1479 | |
1480 | 1480 | } |
1481 | -add_action( 'wpinv_payment_form_render_element_template', 'getpaid_payment_form_render_element_preview_template' ); |
|
1481 | +add_action('wpinv_payment_form_render_element_template', 'getpaid_payment_form_render_element_preview_template'); |
|
1482 | 1482 | |
1483 | 1483 | /** |
1484 | 1484 | * Shows a list of gateways that support recurring payments. |
@@ -1486,17 +1486,17 @@ discard block |
||
1486 | 1486 | function wpinv_get_recurring_gateways_text() { |
1487 | 1487 | $gateways = array(); |
1488 | 1488 | |
1489 | - foreach ( wpinv_get_payment_gateways() as $key => $gateway ) { |
|
1490 | - if ( wpinv_gateway_support_subscription( $key ) ) { |
|
1491 | - $gateways[] = sanitize_text_field( $gateway['admin_label'] ); |
|
1489 | + foreach (wpinv_get_payment_gateways() as $key => $gateway) { |
|
1490 | + if (wpinv_gateway_support_subscription($key)) { |
|
1491 | + $gateways[] = sanitize_text_field($gateway['admin_label']); |
|
1492 | 1492 | } |
1493 | 1493 | } |
1494 | 1494 | |
1495 | - if ( empty( $gateways ) ) { |
|
1496 | - return "<span class='form-text text-danger'>" . __( 'No active gateways support subscription payments.', 'invoicing' ) ."</span>"; |
|
1495 | + if (empty($gateways)) { |
|
1496 | + return "<span class='form-text text-danger'>" . __('No active gateways support subscription payments.', 'invoicing') . "</span>"; |
|
1497 | 1497 | } |
1498 | 1498 | |
1499 | - return "<span class='form-text text-muted'>" . wp_sprintf( __( 'Subscription payments only supported by: %s', 'invoicing' ), implode( ', ', $gateways ) ) ."</span>"; |
|
1499 | + return "<span class='form-text text-muted'>" . wp_sprintf(__('Subscription payments only supported by: %s', 'invoicing'), implode(', ', $gateways)) . "</span>"; |
|
1500 | 1500 | |
1501 | 1501 | } |
1502 | 1502 | |
@@ -1506,7 +1506,7 @@ discard block |
||
1506 | 1506 | * @return GetPaid_Template |
1507 | 1507 | */ |
1508 | 1508 | function getpaid_template() { |
1509 | - return getpaid()->get( 'template' ); |
|
1509 | + return getpaid()->get('template'); |
|
1510 | 1510 | } |
1511 | 1511 | |
1512 | 1512 | /** |
@@ -1515,8 +1515,8 @@ discard block |
||
1515 | 1515 | * @param array args |
1516 | 1516 | * @return string |
1517 | 1517 | */ |
1518 | -function getpaid_paginate_links( $args ) { |
|
1519 | - return str_replace( 'page-link dots', 'page-link text-dark', aui()->pagination( $args ) ); |
|
1518 | +function getpaid_paginate_links($args) { |
|
1519 | + return str_replace('page-link dots', 'page-link text-dark', aui()->pagination($args)); |
|
1520 | 1520 | } |
1521 | 1521 | |
1522 | 1522 | /** |
@@ -1526,21 +1526,21 @@ discard block |
||
1526 | 1526 | * @param string state |
1527 | 1527 | * @return string |
1528 | 1528 | */ |
1529 | -function getpaid_get_states_select_markup( $country, $state, $placeholder, $label, $help_text, $required = false, $wrapper_class = 'col-12', $field_name = 'wpinv_state' ) { |
|
1529 | +function getpaid_get_states_select_markup($country, $state, $placeholder, $label, $help_text, $required = false, $wrapper_class = 'col-12', $field_name = 'wpinv_state') { |
|
1530 | 1530 | |
1531 | - $states = wpinv_get_country_states( $country ); |
|
1532 | - $uniqid = uniqid( '_' ); |
|
1531 | + $states = wpinv_get_country_states($country); |
|
1532 | + $uniqid = uniqid('_'); |
|
1533 | 1533 | |
1534 | - if ( ! empty( $states ) ) { |
|
1534 | + if (!empty($states)) { |
|
1535 | 1535 | |
1536 | - return aui()->select( array( |
|
1536 | + return aui()->select(array( |
|
1537 | 1537 | 'options' => $states, |
1538 | - 'name' => esc_attr( $field_name ), |
|
1539 | - 'id' => sanitize_html_class( $field_name ) . $uniqid, |
|
1540 | - 'value' => sanitize_text_field( $state ), |
|
1538 | + 'name' => esc_attr($field_name), |
|
1539 | + 'id' => sanitize_html_class($field_name) . $uniqid, |
|
1540 | + 'value' => sanitize_text_field($state), |
|
1541 | 1541 | 'placeholder' => $placeholder, |
1542 | 1542 | 'required' => $required, |
1543 | - 'label' => wp_kses_post( $label ), |
|
1543 | + 'label' => wp_kses_post($label), |
|
1544 | 1544 | 'label_type' => 'vertical', |
1545 | 1545 | 'help_text' => $help_text, |
1546 | 1546 | 'class' => 'getpaid-address-field wpinv_state', |
@@ -1555,14 +1555,14 @@ discard block |
||
1555 | 1555 | |
1556 | 1556 | return aui()->input( |
1557 | 1557 | array( |
1558 | - 'name' => esc_attr( $field_name ), |
|
1559 | - 'id' => sanitize_html_class( $field_name ) . $uniqid, |
|
1558 | + 'name' => esc_attr($field_name), |
|
1559 | + 'id' => sanitize_html_class($field_name) . $uniqid, |
|
1560 | 1560 | 'placeholder' => $placeholder, |
1561 | 1561 | 'required' => $required, |
1562 | - 'label' => wp_kses_post( $label ), |
|
1562 | + 'label' => wp_kses_post($label), |
|
1563 | 1563 | 'label_type' => 'vertical', |
1564 | 1564 | 'help_text' => $help_text, |
1565 | - 'value' => sanitize_text_field( $state ), |
|
1565 | + 'value' => sanitize_text_field($state), |
|
1566 | 1566 | 'class' => 'getpaid-address-field wpinv_state', |
1567 | 1567 | 'wrap_class' => "$wrapper_class getpaid-address-field-wrapper__state", |
1568 | 1568 | 'label_class' => 'getpaid-address-field-label getpaid-address-field-label__state', |
@@ -1580,16 +1580,16 @@ discard block |
||
1580 | 1580 | * @param array $element |
1581 | 1581 | * @return string |
1582 | 1582 | */ |
1583 | -function getpaid_get_form_element_grid_class( $element ) { |
|
1583 | +function getpaid_get_form_element_grid_class($element) { |
|
1584 | 1584 | |
1585 | 1585 | $class = "col-12"; |
1586 | - $width = empty( $element['grid_width'] ) ? 'full' : $element['grid_width']; |
|
1586 | + $width = empty($element['grid_width']) ? 'full' : $element['grid_width']; |
|
1587 | 1587 | |
1588 | - if ( $width == 'half' ) { |
|
1588 | + if ($width == 'half') { |
|
1589 | 1589 | $class = "col-12 col-md-6"; |
1590 | 1590 | } |
1591 | 1591 | |
1592 | - if ( $width == 'third' ) { |
|
1592 | + if ($width == 'third') { |
|
1593 | 1593 | $class = "col-12 col-md-4"; |
1594 | 1594 | } |
1595 | 1595 |
@@ -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,35 +119,35 @@ 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 | $merge_tags = array( |
130 | - '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
131 | - '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
132 | - '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
133 | - '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
134 | - '{email}' => sanitize_email( $invoice->get_email() ), |
|
135 | - '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
136 | - '{invoice_currency}' => sanitize_text_field( $invoice->get_currency() ), |
|
137 | - '{invoice_total}' => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ), |
|
138 | - '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
139 | - '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ), |
|
140 | - '{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ), |
|
141 | - '{invoice_date}' => getpaid_format_date_value( $invoice->get_date_created() ), |
|
142 | - '{invoice_due_date}' => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ), |
|
143 | - '{invoice_quote}' => sanitize_text_field( strtolower( $invoice->get_label() ) ), |
|
144 | - '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_label() ) ), |
|
145 | - '{invoice_description}' => wp_kses_post( $invoice->get_description() ), |
|
146 | - '{subscription_name}' => wp_kses_post( $invoice->get_subscription_name() ), |
|
147 | - '{is_was}' => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
130 | + '{name}' => sanitize_text_field($invoice->get_user_full_name()), |
|
131 | + '{full_name}' => sanitize_text_field($invoice->get_user_full_name()), |
|
132 | + '{first_name}' => sanitize_text_field($invoice->get_first_name()), |
|
133 | + '{last_name}' => sanitize_text_field($invoice->get_last_name()), |
|
134 | + '{email}' => sanitize_email($invoice->get_email()), |
|
135 | + '{invoice_number}' => sanitize_text_field($invoice->get_number()), |
|
136 | + '{invoice_currency}' => sanitize_text_field($invoice->get_currency()), |
|
137 | + '{invoice_total}' => sanitize_text_field(wpinv_price($invoice->get_total(), $invoice->get_currency())), |
|
138 | + '{invoice_link}' => esc_url($invoice->get_view_url()), |
|
139 | + '{invoice_pay_link}' => esc_url($invoice->get_checkout_payment_url()), |
|
140 | + '{invoice_receipt_link}'=> esc_url($invoice->get_receipt_url()), |
|
141 | + '{invoice_date}' => getpaid_format_date_value($invoice->get_date_created()), |
|
142 | + '{invoice_due_date}' => getpaid_format_date_value($invoice->get_due_date(), __('on receipt', 'invoicing')), |
|
143 | + '{invoice_quote}' => sanitize_text_field(strtolower($invoice->get_label())), |
|
144 | + '{invoice_label}' => sanitize_text_field(ucfirst($invoice->get_label())), |
|
145 | + '{invoice_description}' => wp_kses_post($invoice->get_description()), |
|
146 | + '{subscription_name}' => wp_kses_post($invoice->get_subscription_name()), |
|
147 | + '{is_was}' => strtotime($invoice->get_due_date()) < current_time('timestamp') ? __('was', 'invoicing') : __('is', 'invoicing'), |
|
148 | 148 | ); |
149 | 149 | |
150 | - return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice ); |
|
150 | + return apply_filters('getpaid_invoice_email_merge_tags', $merge_tags, $invoice); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | /** |
@@ -159,11 +159,11 @@ discard block |
||
159 | 159 | * @param string|array $recipients |
160 | 160 | * @param array $extra_args Extra template args. |
161 | 161 | */ |
162 | - public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
162 | + public function send_email($invoice, $email, $type, $recipients, $extra_args = array()) { |
|
163 | 163 | |
164 | - do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
164 | + do_action('getpaid_before_send_invoice_notification', $type, $invoice, $email); |
|
165 | 165 | |
166 | - if ( apply_filters( 'getpaid_skip_invoice_email', false, $type, $invoice ) ) { |
|
166 | + if (apply_filters('getpaid_skip_invoice_email', false, $type, $invoice)) { |
|
167 | 167 | return; |
168 | 168 | } |
169 | 169 | |
@@ -171,29 +171,29 @@ discard block |
||
171 | 171 | $merge_tags = $email->get_merge_tags(); |
172 | 172 | |
173 | 173 | $result = $mailer->send( |
174 | - apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
175 | - $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
176 | - $email->get_content( $merge_tags, $extra_args ), |
|
174 | + apply_filters('getpaid_invoice_email_recipients', wpinv_parse_list($recipients), $email), |
|
175 | + $email->add_merge_tags($email->get_subject(), $merge_tags), |
|
176 | + $email->get_content($merge_tags, $extra_args), |
|
177 | 177 | $email->get_attachments() |
178 | 178 | ); |
179 | 179 | |
180 | 180 | // Maybe send a copy to the admin. |
181 | - if ( $email->include_admin_bcc() ) { |
|
181 | + if ($email->include_admin_bcc()) { |
|
182 | 182 | $mailer->send( |
183 | 183 | wpinv_get_admin_email(), |
184 | - $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
185 | - $email->get_content( $merge_tags ), |
|
184 | + $email->add_merge_tags($email->get_subject() . __(' - ADMIN BCC COPY', 'invoicing'), $merge_tags), |
|
185 | + $email->get_content($merge_tags), |
|
186 | 186 | $email->get_attachments() |
187 | 187 | ); |
188 | 188 | } |
189 | 189 | |
190 | - if ( $result ) { |
|
191 | - $invoice->add_note( sprintf( __( 'Successfully sent %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true ); |
|
190 | + if ($result) { |
|
191 | + $invoice->add_note(sprintf(__('Successfully sent %s notification email.', 'invoicing'), sanitize_key($type)), false, false, true); |
|
192 | 192 | } else { |
193 | - $invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true ); |
|
193 | + $invoice->add_note(sprintf(__('Failed sending %s notification email.', 'invoicing'), sanitize_key($type)), false, false, true); |
|
194 | 194 | } |
195 | 195 | |
196 | - do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
196 | + do_action('getpaid_after_send_invoice_notification', $type, $invoice, $email); |
|
197 | 197 | |
198 | 198 | return $result; |
199 | 199 | } |
@@ -204,14 +204,14 @@ discard block |
||
204 | 204 | * @param array $recipients |
205 | 205 | * @param GetPaid_Notification_Email $email |
206 | 206 | */ |
207 | - public function filter_email_recipients( $recipients, $email ) { |
|
207 | + public function filter_email_recipients($recipients, $email) { |
|
208 | 208 | |
209 | - if ( ! $email->is_admin_email() ) { |
|
209 | + if (!$email->is_admin_email()) { |
|
210 | 210 | $cc = $email->object->get_email_cc(); |
211 | 211 | |
212 | - if ( ! empty( $cc ) ) { |
|
213 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
214 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
212 | + if (!empty($cc)) { |
|
213 | + $cc = array_map('sanitize_email', wpinv_parse_list($cc)); |
|
214 | + $recipients = array_filter(array_unique(array_merge($recipients, $cc))); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | } |
@@ -225,17 +225,17 @@ discard block |
||
225 | 225 | * |
226 | 226 | * @param WPInv_Invoice $invoice |
227 | 227 | */ |
228 | - public function new_invoice( $invoice ) { |
|
228 | + public function new_invoice($invoice) { |
|
229 | 229 | |
230 | 230 | // Only send this email for invoices created via the admin page. |
231 | - if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
231 | + if (!$invoice->is_type('invoice') || $this->is_payment_form_invoice($invoice->get_id())) { |
|
232 | 232 | return; |
233 | 233 | } |
234 | 234 | |
235 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
235 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
236 | 236 | $recipient = wpinv_get_admin_email(); |
237 | 237 | |
238 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
238 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
239 | 239 | |
240 | 240 | } |
241 | 241 | |
@@ -244,12 +244,12 @@ discard block |
||
244 | 244 | * |
245 | 245 | * @param WPInv_Invoice $invoice |
246 | 246 | */ |
247 | - public function cancelled_invoice( $invoice ) { |
|
247 | + public function cancelled_invoice($invoice) { |
|
248 | 248 | |
249 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
249 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
250 | 250 | $recipient = wpinv_get_admin_email(); |
251 | 251 | |
252 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
252 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
253 | 253 | |
254 | 254 | } |
255 | 255 | |
@@ -258,12 +258,12 @@ discard block |
||
258 | 258 | * |
259 | 259 | * @param WPInv_Invoice $invoice |
260 | 260 | */ |
261 | - public function failed_invoice( $invoice ) { |
|
261 | + public function failed_invoice($invoice) { |
|
262 | 262 | |
263 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
263 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
264 | 264 | $recipient = wpinv_get_admin_email(); |
265 | 265 | |
266 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
266 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
267 | 267 | |
268 | 268 | } |
269 | 269 | |
@@ -272,12 +272,12 @@ discard block |
||
272 | 272 | * |
273 | 273 | * @param WPInv_Invoice $invoice |
274 | 274 | */ |
275 | - public function onhold_invoice( $invoice ) { |
|
275 | + public function onhold_invoice($invoice) { |
|
276 | 276 | |
277 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
277 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
278 | 278 | $recipient = $invoice->get_email(); |
279 | 279 | |
280 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
280 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
281 | 281 | |
282 | 282 | } |
283 | 283 | |
@@ -286,12 +286,12 @@ discard block |
||
286 | 286 | * |
287 | 287 | * @param WPInv_Invoice $invoice |
288 | 288 | */ |
289 | - public function processing_invoice( $invoice ) { |
|
289 | + public function processing_invoice($invoice) { |
|
290 | 290 | |
291 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
291 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
292 | 292 | $recipient = $invoice->get_email(); |
293 | 293 | |
294 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
294 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
295 | 295 | |
296 | 296 | } |
297 | 297 | |
@@ -300,17 +300,17 @@ discard block |
||
300 | 300 | * |
301 | 301 | * @param WPInv_Invoice $invoice |
302 | 302 | */ |
303 | - public function completed_invoice( $invoice ) { |
|
303 | + public function completed_invoice($invoice) { |
|
304 | 304 | |
305 | 305 | // (Maybe) abort if it is a renewal invoice. |
306 | - if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
306 | + if ($invoice->is_renewal() && !wpinv_get_option('email_completed_invoice_renewal_active', false)) { |
|
307 | 307 | return; |
308 | 308 | } |
309 | 309 | |
310 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
310 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
311 | 311 | $recipient = $invoice->get_email(); |
312 | 312 | |
313 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
313 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
314 | 314 | |
315 | 315 | } |
316 | 316 | |
@@ -319,12 +319,12 @@ discard block |
||
319 | 319 | * |
320 | 320 | * @param WPInv_Invoice $invoice |
321 | 321 | */ |
322 | - public function refunded_invoice( $invoice ) { |
|
322 | + public function refunded_invoice($invoice) { |
|
323 | 323 | |
324 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
324 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
325 | 325 | $recipient = $invoice->get_email(); |
326 | 326 | |
327 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
327 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
328 | 328 | |
329 | 329 | } |
330 | 330 | |
@@ -334,21 +334,21 @@ discard block |
||
334 | 334 | * @param WPInv_Invoice $invoice |
335 | 335 | * @param bool $force |
336 | 336 | */ |
337 | - public function user_invoice( $invoice, $force = false ) { |
|
337 | + public function user_invoice($invoice, $force = false) { |
|
338 | 338 | |
339 | - if ( ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) { |
|
339 | + if (!empty($GLOBALS['wpinv_skip_invoice_notification'])) { |
|
340 | 340 | return; |
341 | 341 | } |
342 | 342 | |
343 | 343 | // Only send this email for invoices created via the admin page. |
344 | - if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) { |
|
344 | + if (!$invoice->is_type('invoice') || (empty($force) && $this->is_payment_form_invoice($invoice->get_id()))) { |
|
345 | 345 | return; |
346 | 346 | } |
347 | 347 | |
348 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
348 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
349 | 349 | $recipient = $invoice->get_email(); |
350 | 350 | |
351 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
351 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
352 | 352 | |
353 | 353 | } |
354 | 354 | |
@@ -358,8 +358,8 @@ discard block |
||
358 | 358 | * @param int $invoice |
359 | 359 | * @return bool |
360 | 360 | */ |
361 | - public function is_payment_form_invoice( $invoice ) { |
|
362 | - return empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' == get_post_meta( $invoice, 'wpinv_created_via', true ) ); |
|
361 | + public function is_payment_form_invoice($invoice) { |
|
362 | + return empty($_GET['getpaid-admin-action']) && ('payment_form' == get_post_meta($invoice, 'wpinv_created_via', true) || 'geodirectory' == get_post_meta($invoice, 'wpinv_created_via', true)); |
|
363 | 363 | } |
364 | 364 | |
365 | 365 | /** |
@@ -368,12 +368,12 @@ discard block |
||
368 | 368 | * @param WPInv_Invoice $invoice |
369 | 369 | * @param string $note |
370 | 370 | */ |
371 | - public function user_note( $invoice, $note ) { |
|
371 | + public function user_note($invoice, $note) { |
|
372 | 372 | |
373 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
373 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
374 | 374 | $recipient = $invoice->get_email(); |
375 | 375 | |
376 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
376 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient, array('customer_note' => $note)); |
|
377 | 377 | |
378 | 378 | } |
379 | 379 | |
@@ -382,9 +382,9 @@ discard block |
||
382 | 382 | * |
383 | 383 | * @param WPInv_Invoice $invoice |
384 | 384 | */ |
385 | - public function force_send_overdue_notice( $invoice ) { |
|
386 | - $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
387 | - return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
385 | + public function force_send_overdue_notice($invoice) { |
|
386 | + $email = new GetPaid_Notification_Email('overdue', $invoice); |
|
387 | + return $this->send_email($invoice, $email, 'overdue', $invoice->get_email()); |
|
388 | 388 | } |
389 | 389 | |
390 | 390 | /** |
@@ -395,37 +395,37 @@ discard block |
||
395 | 395 | public function overdue() { |
396 | 396 | global $wpdb; |
397 | 397 | |
398 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
398 | + $email = new GetPaid_Notification_Email(__FUNCTION__); |
|
399 | 399 | |
400 | 400 | // Fetch reminder days. |
401 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
401 | + $reminder_days = array_unique(wp_parse_id_list($email->get_option('days'))); |
|
402 | 402 | |
403 | 403 | // Abort if non is set. |
404 | - if ( empty( $reminder_days ) ) { |
|
404 | + if (empty($reminder_days)) { |
|
405 | 405 | return; |
406 | 406 | } |
407 | 407 | |
408 | 408 | // Retrieve date query. |
409 | - $date_query = $this->get_date_query( $reminder_days ); |
|
409 | + $date_query = $this->get_date_query($reminder_days); |
|
410 | 410 | |
411 | 411 | // Invoices table. |
412 | 412 | $table = $wpdb->prefix . 'getpaid_invoices'; |
413 | 413 | |
414 | 414 | // Fetch invoices. |
415 | - $invoices = $wpdb->get_col( |
|
415 | + $invoices = $wpdb->get_col( |
|
416 | 416 | "SELECT posts.ID FROM $wpdb->posts as posts |
417 | 417 | LEFT JOIN $table as invoices ON invoices.post_id = posts.ID |
418 | 418 | WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query"); |
419 | 419 | |
420 | - foreach ( $invoices as $invoice ) { |
|
420 | + foreach ($invoices as $invoice) { |
|
421 | 421 | |
422 | 422 | // Only send this email for invoices created via the admin page. |
423 | - if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
424 | - $invoice = new WPInv_Invoice( $invoice ); |
|
423 | + if (!$this->is_payment_form_invoice($invoice)) { |
|
424 | + $invoice = new WPInv_Invoice($invoice); |
|
425 | 425 | $email->object = $invoice; |
426 | 426 | |
427 | - if ( $invoice->needs_payment() ) { |
|
428 | - $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
427 | + if ($invoice->needs_payment()) { |
|
428 | + $this->send_email($invoice, $email, __FUNCTION__, $invoice->get_email()); |
|
429 | 429 | } |
430 | 430 | |
431 | 431 | } |
@@ -440,14 +440,14 @@ discard block |
||
440 | 440 | * @param array $reminder_days |
441 | 441 | * @return string |
442 | 442 | */ |
443 | - public function get_date_query( $reminder_days ) { |
|
443 | + public function get_date_query($reminder_days) { |
|
444 | 444 | |
445 | 445 | $date_query = array( |
446 | 446 | 'relation' => 'OR' |
447 | 447 | ); |
448 | 448 | |
449 | - foreach ( $reminder_days as $days ) { |
|
450 | - $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
449 | + foreach ($reminder_days as $days) { |
|
450 | + $date = date_parse(date('Y-m-d', strtotime("-$days days", current_time('timestamp')))); |
|
451 | 451 | |
452 | 452 | $date_query[] = array( |
453 | 453 | 'year' => $date['year'], |
@@ -457,7 +457,7 @@ discard block |
||
457 | 457 | |
458 | 458 | } |
459 | 459 | |
460 | - $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
460 | + $date_query = new WP_Date_Query($date_query, 'invoices.due_date'); |
|
461 | 461 | |
462 | 462 | return $date_query->get_sql(); |
463 | 463 |
@@ -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 subscription notificaiton emails. |
@@ -45,21 +45,21 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public function init_hooks() { |
47 | 47 | |
48 | - add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 ); |
|
49 | - foreach ( $this->subscription_actions as $hook => $email_type ) { |
|
48 | + add_filter('getpaid_get_email_merge_tags', array($this, 'subscription_merge_tags'), 10, 2); |
|
49 | + foreach ($this->subscription_actions as $hook => $email_type) { |
|
50 | 50 | |
51 | - $email = new GetPaid_Notification_Email( $email_type ); |
|
51 | + $email = new GetPaid_Notification_Email($email_type); |
|
52 | 52 | |
53 | - if ( ! $email->is_active() ) { |
|
53 | + if (!$email->is_active()) { |
|
54 | 54 | continue; |
55 | 55 | } |
56 | 56 | |
57 | - if ( method_exists( $this, $email_type ) ) { |
|
58 | - add_action( $hook, array( $this, $email_type ), 100, 2 ); |
|
57 | + if (method_exists($this, $email_type)) { |
|
58 | + add_action($hook, array($this, $email_type), 100, 2); |
|
59 | 59 | continue; |
60 | 60 | } |
61 | 61 | |
62 | - do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook ); |
|
62 | + do_action('getpaid_subscription_notification_email_register_hook', $email_type, $hook); |
|
63 | 63 | |
64 | 64 | } |
65 | 65 | |
@@ -71,12 +71,12 @@ discard block |
||
71 | 71 | * @param array $merge_tags |
72 | 72 | * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
73 | 73 | */ |
74 | - public function subscription_merge_tags( $merge_tags, $object ) { |
|
74 | + public function subscription_merge_tags($merge_tags, $object) { |
|
75 | 75 | |
76 | - if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
76 | + if (is_a($object, 'WPInv_Subscription')) { |
|
77 | 77 | $merge_tags = array_merge( |
78 | 78 | $merge_tags, |
79 | - $this->get_subscription_merge_tags( $object ) |
|
79 | + $this->get_subscription_merge_tags($object) |
|
80 | 80 | ); |
81 | 81 | } |
82 | 82 | |
@@ -90,25 +90,25 @@ discard block |
||
90 | 90 | * @param WPInv_Subscription $subscription |
91 | 91 | * @return array |
92 | 92 | */ |
93 | - public function get_subscription_merge_tags( $subscription ) { |
|
93 | + public function get_subscription_merge_tags($subscription) { |
|
94 | 94 | |
95 | 95 | // Abort if it does not exist. |
96 | - if ( ! $subscription->get_id() ) { |
|
96 | + if (!$subscription->get_id()) { |
|
97 | 97 | return array(); |
98 | 98 | } |
99 | 99 | |
100 | - $invoice = $subscription->get_parent_invoice(); |
|
100 | + $invoice = $subscription->get_parent_invoice(); |
|
101 | 101 | return array( |
102 | - '{subscription_renewal_date}' => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ), |
|
103 | - '{subscription_created}' => getpaid_format_date_value( $subscription->get_date_created() ), |
|
104 | - '{subscription_status}' => sanitize_text_field( $subscription->get_status_label() ), |
|
105 | - '{subscription_profile_id}' => sanitize_text_field( $subscription->get_profile_id() ), |
|
106 | - '{subscription_id}' => absint( $subscription->get_id() ), |
|
107 | - '{subscription_recurring_amount}' => sanitize_text_field( wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ) ), |
|
108 | - '{subscription_initial_amount}' => sanitize_text_field( wpinv_price( $subscription->get_initial_amount(), $invoice->get_currency() ) ), |
|
109 | - '{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ), |
|
102 | + '{subscription_renewal_date}' => getpaid_format_date_value($subscription->get_next_renewal_date(), __('Never', 'invoicing')), |
|
103 | + '{subscription_created}' => getpaid_format_date_value($subscription->get_date_created()), |
|
104 | + '{subscription_status}' => sanitize_text_field($subscription->get_status_label()), |
|
105 | + '{subscription_profile_id}' => sanitize_text_field($subscription->get_profile_id()), |
|
106 | + '{subscription_id}' => absint($subscription->get_id()), |
|
107 | + '{subscription_recurring_amount}' => sanitize_text_field(wpinv_price($subscription->get_recurring_amount(), $invoice->get_currency())), |
|
108 | + '{subscription_initial_amount}' => sanitize_text_field(wpinv_price($subscription->get_initial_amount(), $invoice->get_currency())), |
|
109 | + '{subscription_recurring_period}' => getpaid_get_subscription_period_label($subscription->get_period(), $subscription->get_frequency(), ''), |
|
110 | 110 | '{subscription_bill_times}' => $subscription->get_bill_times(), |
111 | - '{subscription_url}' => esc_url( $subscription->get_view_url() ), |
|
111 | + '{subscription_url}' => esc_url($subscription->get_view_url()), |
|
112 | 112 | ); |
113 | 113 | |
114 | 114 | } |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | * @param WPInv_Invoice $invoice |
120 | 120 | * @return bool |
121 | 121 | */ |
122 | - public function should_send_notification( $invoice ) { |
|
122 | + public function should_send_notification($invoice) { |
|
123 | 123 | return 0 != $invoice->get_id(); |
124 | 124 | } |
125 | 125 | |
@@ -129,14 +129,14 @@ discard block |
||
129 | 129 | * @param WPInv_Invoice $invoice |
130 | 130 | * @return array |
131 | 131 | */ |
132 | - public function get_recipients( $invoice ) { |
|
133 | - $recipients = array( $invoice->get_email() ); |
|
132 | + public function get_recipients($invoice) { |
|
133 | + $recipients = array($invoice->get_email()); |
|
134 | 134 | |
135 | 135 | $cc = $invoice->get_email_cc(); |
136 | 136 | |
137 | - if ( ! empty( $cc ) ) { |
|
138 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
139 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
137 | + if (!empty($cc)) { |
|
138 | + $cc = array_map('sanitize_email', wpinv_parse_list($cc)); |
|
139 | + $recipients = array_filter(array_unique(array_merge($recipients, $cc))); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | return $recipients; |
@@ -150,51 +150,51 @@ discard block |
||
150 | 150 | * @param string $type |
151 | 151 | * @param array $extra_args Extra template args. |
152 | 152 | */ |
153 | - public function send_email( $subscription, $email, $type, $extra_args = array() ) { |
|
153 | + public function send_email($subscription, $email, $type, $extra_args = array()) { |
|
154 | 154 | |
155 | 155 | // Abort in case the parent invoice does not exist. |
156 | 156 | $invoice = $subscription->get_parent_invoice(); |
157 | - if ( ! $this->should_send_notification( $invoice ) ) { |
|
157 | + if (!$this->should_send_notification($invoice)) { |
|
158 | 158 | return; |
159 | 159 | } |
160 | 160 | |
161 | - if ( apply_filters( 'getpaid_skip_subscription_email', false, $type, $subscription ) ) { |
|
161 | + if (apply_filters('getpaid_skip_subscription_email', false, $type, $subscription)) { |
|
162 | 162 | return; |
163 | 163 | } |
164 | 164 | |
165 | - do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email ); |
|
165 | + do_action('getpaid_before_send_subscription_notification', $type, $subscription, $email); |
|
166 | 166 | |
167 | - $recipients = $this->get_recipients( $invoice ); |
|
167 | + $recipients = $this->get_recipients($invoice); |
|
168 | 168 | $mailer = new GetPaid_Notification_Email_Sender(); |
169 | 169 | $merge_tags = $email->get_merge_tags(); |
170 | - $content = $email->get_content( $merge_tags, $extra_args ); |
|
171 | - $subject = $email->add_merge_tags( $email->get_subject(), $merge_tags ); |
|
170 | + $content = $email->get_content($merge_tags, $extra_args); |
|
171 | + $subject = $email->add_merge_tags($email->get_subject(), $merge_tags); |
|
172 | 172 | $attachments = $email->get_attachments(); |
173 | 173 | |
174 | 174 | $result = $mailer->send( |
175 | - apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
175 | + apply_filters('getpaid_subscription_email_recipients', wpinv_parse_list($recipients), $email), |
|
176 | 176 | $subject, |
177 | 177 | $content, |
178 | 178 | $attachments |
179 | 179 | ); |
180 | 180 | |
181 | 181 | // Maybe send a copy to the admin. |
182 | - if ( $email->include_admin_bcc() ) { |
|
182 | + if ($email->include_admin_bcc()) { |
|
183 | 183 | $mailer->send( |
184 | 184 | wpinv_get_admin_email(), |
185 | - $subject . __( ' - ADMIN BCC COPY', 'invoicing' ), |
|
185 | + $subject . __(' - ADMIN BCC COPY', 'invoicing'), |
|
186 | 186 | $content, |
187 | 187 | $attachments |
188 | 188 | ); |
189 | 189 | } |
190 | 190 | |
191 | - if ( $result ) { |
|
192 | - $subscription->get_parent_invoice()->add_note( sprintf( __( 'Successfully sent %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true ); |
|
191 | + if ($result) { |
|
192 | + $subscription->get_parent_invoice()->add_note(sprintf(__('Successfully sent %s notification email.', 'invoicing'), sanitize_key($type)), false, false, true); |
|
193 | 193 | } else { |
194 | - $subscription->get_parent_invoice()->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true ); |
|
194 | + $subscription->get_parent_invoice()->add_note(sprintf(__('Failed sending %s notification email.', 'invoicing'), sanitize_key($type)), false, false, true); |
|
195 | 195 | } |
196 | 196 | |
197 | - do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email ); |
|
197 | + do_action('getpaid_after_send_subscription_notification', $type, $subscription, $email); |
|
198 | 198 | |
199 | 199 | } |
200 | 200 | |
@@ -203,10 +203,10 @@ discard block |
||
203 | 203 | * |
204 | 204 | * @param WPInv_Subscription $subscription |
205 | 205 | */ |
206 | - public function subscription_trial( $subscription ) { |
|
206 | + public function subscription_trial($subscription) { |
|
207 | 207 | |
208 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
209 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
208 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $subscription); |
|
209 | + $this->send_email($subscription, $email, __FUNCTION__); |
|
210 | 210 | |
211 | 211 | } |
212 | 212 | |
@@ -215,10 +215,10 @@ discard block |
||
215 | 215 | * |
216 | 216 | * @param WPInv_Subscription $subscription |
217 | 217 | */ |
218 | - public function subscription_cancelled( $subscription ) { |
|
218 | + public function subscription_cancelled($subscription) { |
|
219 | 219 | |
220 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
221 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
220 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $subscription); |
|
221 | + $this->send_email($subscription, $email, __FUNCTION__); |
|
222 | 222 | |
223 | 223 | } |
224 | 224 | |
@@ -227,10 +227,10 @@ discard block |
||
227 | 227 | * |
228 | 228 | * @param WPInv_Subscription $subscription |
229 | 229 | */ |
230 | - public function subscription_expired( $subscription ) { |
|
230 | + public function subscription_expired($subscription) { |
|
231 | 231 | |
232 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
233 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
232 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $subscription); |
|
233 | + $this->send_email($subscription, $email, __FUNCTION__); |
|
234 | 234 | |
235 | 235 | } |
236 | 236 | |
@@ -239,10 +239,10 @@ discard block |
||
239 | 239 | * |
240 | 240 | * @param WPInv_Subscription $subscription |
241 | 241 | */ |
242 | - public function subscription_complete( $subscription ) { |
|
242 | + public function subscription_complete($subscription) { |
|
243 | 243 | |
244 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
245 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
244 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $subscription); |
|
245 | + $this->send_email($subscription, $email, __FUNCTION__); |
|
246 | 246 | |
247 | 247 | } |
248 | 248 | |
@@ -252,18 +252,18 @@ discard block |
||
252 | 252 | */ |
253 | 253 | public function renewal_reminder() { |
254 | 254 | |
255 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
255 | + $email = new GetPaid_Notification_Email(__FUNCTION__); |
|
256 | 256 | |
257 | 257 | // Fetch reminder days. |
258 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
258 | + $reminder_days = array_unique(wp_parse_id_list($email->get_option('days'))); |
|
259 | 259 | |
260 | 260 | // Abort if non is set. |
261 | - if ( empty( $reminder_days ) ) { |
|
261 | + if (empty($reminder_days)) { |
|
262 | 262 | return; |
263 | 263 | } |
264 | 264 | |
265 | 265 | // Fetch matching subscriptions. |
266 | - $args = array( |
|
266 | + $args = array( |
|
267 | 267 | 'number' => -1, |
268 | 268 | 'count_total' => false, |
269 | 269 | 'status' => 'trialling active', |
@@ -272,8 +272,8 @@ discard block |
||
272 | 272 | ), |
273 | 273 | ); |
274 | 274 | |
275 | - foreach ( $reminder_days as $days ) { |
|
276 | - $date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) ); |
|
275 | + foreach ($reminder_days as $days) { |
|
276 | + $date = date_parse(date('Y-m-d', strtotime("+$days days", current_time('timestamp')))); |
|
277 | 277 | |
278 | 278 | $args['date_expires_query'][] = array( |
279 | 279 | 'year' => $date['year'], |
@@ -283,14 +283,14 @@ discard block |
||
283 | 283 | |
284 | 284 | } |
285 | 285 | |
286 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
286 | + $subscriptions = new GetPaid_Subscriptions_Query($args); |
|
287 | 287 | |
288 | - foreach ( $subscriptions as $subscription ) { |
|
288 | + foreach ($subscriptions as $subscription) { |
|
289 | 289 | |
290 | 290 | // Skip packages. |
291 | - if ( get_post_meta( $subscription->get_product_id(), '_wpinv_type', true ) != 'package' ) { |
|
291 | + if (get_post_meta($subscription->get_product_id(), '_wpinv_type', true) != 'package') { |
|
292 | 292 | $email->object = $subscription; |
293 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
293 | + $this->send_email($subscription, $email, __FUNCTION__); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Contains functions that display the subscriptions admin page. |
4 | 4 | */ |
5 | 5 | |
6 | -defined( 'ABSPATH' ) || exit; |
|
6 | +defined('ABSPATH') || exit; |
|
7 | 7 | |
8 | 8 | /** |
9 | 9 | * Render the Subscriptions page |
@@ -17,22 +17,22 @@ discard block |
||
17 | 17 | ?> |
18 | 18 | |
19 | 19 | <div class="wrap"> |
20 | - <h1><?php echo esc_html( get_admin_page_title() ); ?></h1> |
|
20 | + <h1><?php echo esc_html(get_admin_page_title()); ?></h1> |
|
21 | 21 | <div class="bsui"> |
22 | 22 | |
23 | 23 | <?php |
24 | 24 | |
25 | 25 | // Verify user permissions. |
26 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
26 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
27 | 27 | |
28 | 28 | echo aui()->alert( |
29 | 29 | array( |
30 | 30 | 'type' => 'danger', |
31 | - 'content' => __( 'You are not permitted to view this page.', 'invoicing' ), |
|
31 | + 'content' => __('You are not permitted to view this page.', 'invoicing'), |
|
32 | 32 | ) |
33 | 33 | ); |
34 | 34 | |
35 | - } else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) { |
|
35 | + } else if (!empty($_GET['id']) && is_numeric($_GET['id'])) { |
|
36 | 36 | |
37 | 37 | // Display a single subscription. |
38 | 38 | wpinv_recurring_subscription_details(); |
@@ -81,13 +81,13 @@ discard block |
||
81 | 81 | function wpinv_recurring_subscription_details() { |
82 | 82 | |
83 | 83 | // Fetch the subscription. |
84 | - $sub = new WPInv_Subscription( (int) $_GET['id'] ); |
|
85 | - if ( ! $sub->get_id() ) { |
|
84 | + $sub = new WPInv_Subscription((int) $_GET['id']); |
|
85 | + if (!$sub->get_id()) { |
|
86 | 86 | |
87 | 87 | echo aui()->alert( |
88 | 88 | array( |
89 | 89 | 'type' => 'danger', |
90 | - 'content' => __( 'Subscription not found.', 'invoicing' ), |
|
90 | + 'content' => __('Subscription not found.', 'invoicing'), |
|
91 | 91 | ) |
92 | 92 | ); |
93 | 93 | |
@@ -95,31 +95,31 @@ discard block |
||
95 | 95 | } |
96 | 96 | |
97 | 97 | // Use metaboxes to display the subscription details. |
98 | - add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal' ); |
|
99 | - add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' ); |
|
100 | - add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' ); |
|
101 | - do_action( 'getpaid_admin_single_subscription_register_metabox', $sub ); |
|
98 | + add_meta_box('getpaid_admin_subscription_details_metabox', __('Subscription Details', 'invoicing'), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal'); |
|
99 | + add_meta_box('getpaid_admin_subscription_update_metabox', __('Change Status', 'invoicing'), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side'); |
|
100 | + add_meta_box('getpaid_admin_subscription_invoice_details_metabox', __('Invoices', 'invoicing'), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced'); |
|
101 | + do_action('getpaid_admin_single_subscription_register_metabox', $sub); |
|
102 | 102 | |
103 | 103 | ?> |
104 | 104 | |
105 | - <form method="post" action="<?php echo admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $sub->get_id() ) ); ?>"> |
|
105 | + <form method="post" action="<?php echo admin_url('admin.php?page=wpinv-subscriptions&id=' . absint($sub->get_id())); ?>"> |
|
106 | 106 | |
107 | - <?php wp_nonce_field( 'getpaid-nonce', 'getpaid-nonce' ); ?> |
|
108 | - <?php wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); ?> |
|
109 | - <?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?> |
|
107 | + <?php wp_nonce_field('getpaid-nonce', 'getpaid-nonce'); ?> |
|
108 | + <?php wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); ?> |
|
109 | + <?php wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); ?> |
|
110 | 110 | <input type="hidden" name="getpaid-admin-action" value="update_single_subscription" /> |
111 | - <input type="hidden" name="subscription_id" value="<?php echo (int) $sub->get_id() ;?>" /> |
|
111 | + <input type="hidden" name="subscription_id" value="<?php echo (int) $sub->get_id(); ?>" /> |
|
112 | 112 | |
113 | 113 | <div id="poststuff"> |
114 | 114 | <div id="post-body" class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>"> |
115 | 115 | |
116 | 116 | <div id="postbox-container-1" class="postbox-container"> |
117 | - <?php do_meta_boxes( get_current_screen(), 'side', $sub ); ?> |
|
117 | + <?php do_meta_boxes(get_current_screen(), 'side', $sub); ?> |
|
118 | 118 | </div> |
119 | 119 | |
120 | 120 | <div id="postbox-container-2" class="postbox-container"> |
121 | - <?php do_meta_boxes( get_current_screen(), 'normal', $sub ); ?> |
|
122 | - <?php do_meta_boxes( get_current_screen(), 'advanced', $sub ); ?> |
|
121 | + <?php do_meta_boxes(get_current_screen(), 'normal', $sub); ?> |
|
122 | + <?php do_meta_boxes(get_current_screen(), 'advanced', $sub); ?> |
|
123 | 123 | </div> |
124 | 124 | |
125 | 125 | </div> |
@@ -138,40 +138,40 @@ discard block |
||
138 | 138 | * |
139 | 139 | * @param WPInv_Subscription $sub |
140 | 140 | */ |
141 | -function getpaid_admin_subscription_details_metabox( $sub ) { |
|
141 | +function getpaid_admin_subscription_details_metabox($sub) { |
|
142 | 142 | |
143 | 143 | // Prepare subscription detail columns. |
144 | 144 | $fields = apply_filters( |
145 | 145 | 'getpaid_subscription_admin_page_fields', |
146 | 146 | array( |
147 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
148 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
149 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
150 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
151 | - 'renews_on' => __( 'Next Payment', 'invoicing' ), |
|
152 | - 'renewals' => __( 'Payments', 'invoicing' ), |
|
153 | - 'item' => __( 'Item', 'invoicing' ), |
|
154 | - 'gateway' => __( 'Payment Method', 'invoicing' ), |
|
155 | - 'profile_id' => __( 'Profile ID', 'invoicing' ), |
|
156 | - 'status' => __( 'Status', 'invoicing' ), |
|
147 | + 'subscription' => __('Subscription', 'invoicing'), |
|
148 | + 'customer' => __('Customer', 'invoicing'), |
|
149 | + 'amount' => __('Amount', 'invoicing'), |
|
150 | + 'start_date' => __('Start Date', 'invoicing'), |
|
151 | + 'renews_on' => __('Next Payment', 'invoicing'), |
|
152 | + 'renewals' => __('Payments', 'invoicing'), |
|
153 | + 'item' => __('Item', 'invoicing'), |
|
154 | + 'gateway' => __('Payment Method', 'invoicing'), |
|
155 | + 'profile_id' => __('Profile ID', 'invoicing'), |
|
156 | + 'status' => __('Status', 'invoicing'), |
|
157 | 157 | ) |
158 | 158 | ); |
159 | 159 | |
160 | - if ( ! $sub->is_active() ) { |
|
160 | + if (!$sub->is_active()) { |
|
161 | 161 | |
162 | - if ( isset( $fields['renews_on'] ) ) { |
|
163 | - unset( $fields['renews_on'] ); |
|
162 | + if (isset($fields['renews_on'])) { |
|
163 | + unset($fields['renews_on']); |
|
164 | 164 | } |
165 | 165 | |
166 | - if ( isset( $fields['gateway'] ) ) { |
|
167 | - unset( $fields['gateway'] ); |
|
166 | + if (isset($fields['gateway'])) { |
|
167 | + unset($fields['gateway']); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | } |
171 | 171 | |
172 | 172 | $profile_id = $sub->get_profile_id(); |
173 | - if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) { |
|
174 | - unset( $fields['profile_id'] ); |
|
173 | + if (empty($profile_id) && isset($fields['profile_id'])) { |
|
174 | + unset($fields['profile_id']); |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | ?> |
@@ -179,16 +179,16 @@ discard block |
||
179 | 179 | <table class="table table-borderless" style="font-size: 14px;"> |
180 | 180 | <tbody> |
181 | 181 | |
182 | - <?php foreach ( $fields as $key => $label ) : ?> |
|
182 | + <?php foreach ($fields as $key => $label) : ?> |
|
183 | 183 | |
184 | - <tr class="getpaid-subscription-meta-<?php echo sanitize_html_class( $key ); ?>"> |
|
184 | + <tr class="getpaid-subscription-meta-<?php echo sanitize_html_class($key); ?>"> |
|
185 | 185 | |
186 | 186 | <th class="w-25" style="font-weight: 500;"> |
187 | - <?php echo sanitize_text_field( $label ); ?> |
|
187 | + <?php echo sanitize_text_field($label); ?> |
|
188 | 188 | </th> |
189 | 189 | |
190 | 190 | <td class="w-75 text-muted"> |
191 | - <?php do_action( 'getpaid_subscription_admin_display_' . sanitize_text_field( $key ), $sub ); ?> |
|
191 | + <?php do_action('getpaid_subscription_admin_display_' . sanitize_text_field($key), $sub); ?> |
|
192 | 192 | </td> |
193 | 193 | |
194 | 194 | </tr> |
@@ -206,131 +206,131 @@ discard block |
||
206 | 206 | * |
207 | 207 | * @param WPInv_Subscription $subscription |
208 | 208 | */ |
209 | -function getpaid_admin_subscription_metabox_display_customer( $subscription ) { |
|
209 | +function getpaid_admin_subscription_metabox_display_customer($subscription) { |
|
210 | 210 | |
211 | - $username = __( '(Missing User)', 'invoicing' ); |
|
211 | + $username = __('(Missing User)', 'invoicing'); |
|
212 | 212 | |
213 | - $user = get_userdata( $subscription->get_customer_id() ); |
|
214 | - if ( $user ) { |
|
213 | + $user = get_userdata($subscription->get_customer_id()); |
|
214 | + if ($user) { |
|
215 | 215 | |
216 | 216 | $username = sprintf( |
217 | 217 | '<a href="user-edit.php?user_id=%s">%s</a>', |
218 | - absint( $user->ID ), |
|
219 | - ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email ) |
|
218 | + absint($user->ID), |
|
219 | + !empty($user->display_name) ? sanitize_text_field($user->display_name) : sanitize_email($user->user_email) |
|
220 | 220 | ); |
221 | 221 | |
222 | 222 | } |
223 | 223 | |
224 | 224 | echo $username; |
225 | 225 | } |
226 | -add_action( 'getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer' ); |
|
226 | +add_action('getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer'); |
|
227 | 227 | |
228 | 228 | /** |
229 | 229 | * Displays the subscription amount. |
230 | 230 | * |
231 | 231 | * @param WPInv_Subscription $subscription |
232 | 232 | */ |
233 | -function getpaid_admin_subscription_metabox_display_amount( $subscription ) { |
|
234 | - $amount = sanitize_text_field( getpaid_get_formatted_subscription_amount( $subscription ) ); |
|
233 | +function getpaid_admin_subscription_metabox_display_amount($subscription) { |
|
234 | + $amount = sanitize_text_field(getpaid_get_formatted_subscription_amount($subscription)); |
|
235 | 235 | echo "<span>$amount</span>"; |
236 | 236 | } |
237 | -add_action( 'getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount' ); |
|
237 | +add_action('getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount'); |
|
238 | 238 | |
239 | 239 | /** |
240 | 240 | * Displays the subscription id. |
241 | 241 | * |
242 | 242 | * @param WPInv_Subscription $subscription |
243 | 243 | */ |
244 | -function getpaid_admin_subscription_metabox_display_id( $subscription ) { |
|
245 | - echo '#' . absint( $subscription->get_id() ); |
|
244 | +function getpaid_admin_subscription_metabox_display_id($subscription) { |
|
245 | + echo '#' . absint($subscription->get_id()); |
|
246 | 246 | } |
247 | -add_action( 'getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id' ); |
|
247 | +add_action('getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id'); |
|
248 | 248 | |
249 | 249 | /** |
250 | 250 | * Displays the subscription renewal date. |
251 | 251 | * |
252 | 252 | * @param WPInv_Subscription $subscription |
253 | 253 | */ |
254 | -function getpaid_admin_subscription_metabox_display_start_date( $subscription ) { |
|
255 | - echo getpaid_format_date_value( $subscription->get_date_created() ); |
|
254 | +function getpaid_admin_subscription_metabox_display_start_date($subscription) { |
|
255 | + echo getpaid_format_date_value($subscription->get_date_created()); |
|
256 | 256 | } |
257 | -add_action( 'getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date' ); |
|
257 | +add_action('getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date'); |
|
258 | 258 | |
259 | 259 | /** |
260 | 260 | * Displays the subscription renewal date. |
261 | 261 | * |
262 | 262 | * @param WPInv_Subscription $subscription |
263 | 263 | */ |
264 | -function getpaid_admin_subscription_metabox_display_renews_on( $subscription ) { |
|
265 | - echo getpaid_format_date_value( $subscription->get_expiration() ); |
|
264 | +function getpaid_admin_subscription_metabox_display_renews_on($subscription) { |
|
265 | + echo getpaid_format_date_value($subscription->get_expiration()); |
|
266 | 266 | } |
267 | -add_action( 'getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on' ); |
|
267 | +add_action('getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on'); |
|
268 | 268 | |
269 | 269 | /** |
270 | 270 | * Displays the subscription renewal count. |
271 | 271 | * |
272 | 272 | * @param WPInv_Subscription $subscription |
273 | 273 | */ |
274 | -function getpaid_admin_subscription_metabox_display_renewals( $subscription ) { |
|
274 | +function getpaid_admin_subscription_metabox_display_renewals($subscription) { |
|
275 | 275 | $max_bills = $subscription->get_bill_times(); |
276 | - echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
276 | + echo $subscription->get_times_billed() . ' / ' . (empty($max_bills) ? "∞" : $max_bills); |
|
277 | 277 | } |
278 | -add_action( 'getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals' ); |
|
278 | +add_action('getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals'); |
|
279 | 279 | /** |
280 | 280 | * Displays the subscription item. |
281 | 281 | * |
282 | 282 | * @param WPInv_Subscription $subscription |
283 | 283 | */ |
284 | -function getpaid_admin_subscription_metabox_display_item( $subscription ) { |
|
284 | +function getpaid_admin_subscription_metabox_display_item($subscription) { |
|
285 | 285 | |
286 | - $item = get_post( $subscription->get_product_id() ); |
|
286 | + $item = get_post($subscription->get_product_id()); |
|
287 | 287 | |
288 | - if ( ! empty( $item ) ) { |
|
289 | - $link = get_edit_post_link( $item ); |
|
290 | - $link = esc_url( $link ); |
|
291 | - $name = esc_html( get_the_title( $item ) ); |
|
288 | + if (!empty($item)) { |
|
289 | + $link = get_edit_post_link($item); |
|
290 | + $link = esc_url($link); |
|
291 | + $name = esc_html(get_the_title($item)); |
|
292 | 292 | echo "<a href='$link'>$name</a>"; |
293 | 293 | } else { |
294 | - echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() ); |
|
294 | + echo sprintf(__('Item #%s', 'invoicing'), $subscription->get_product_id()); |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | } |
298 | -add_action( 'getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item' ); |
|
298 | +add_action('getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item'); |
|
299 | 299 | |
300 | 300 | /** |
301 | 301 | * Displays the subscription gateway. |
302 | 302 | * |
303 | 303 | * @param WPInv_Subscription $subscription |
304 | 304 | */ |
305 | -function getpaid_admin_subscription_metabox_display_gateway( $subscription ) { |
|
305 | +function getpaid_admin_subscription_metabox_display_gateway($subscription) { |
|
306 | 306 | |
307 | 307 | $gateway = $subscription->get_gateway(); |
308 | 308 | |
309 | - if ( ! empty( $gateway ) ) { |
|
310 | - echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) ); |
|
309 | + if (!empty($gateway)) { |
|
310 | + echo sanitize_text_field(wpinv_get_gateway_admin_label($gateway)); |
|
311 | 311 | } else { |
312 | 312 | echo "—"; |
313 | 313 | } |
314 | 314 | |
315 | 315 | } |
316 | -add_action( 'getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway' ); |
|
316 | +add_action('getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway'); |
|
317 | 317 | |
318 | 318 | /** |
319 | 319 | * Displays the subscription status. |
320 | 320 | * |
321 | 321 | * @param WPInv_Subscription $subscription |
322 | 322 | */ |
323 | -function getpaid_admin_subscription_metabox_display_status( $subscription ) { |
|
323 | +function getpaid_admin_subscription_metabox_display_status($subscription) { |
|
324 | 324 | echo $subscription->get_status_label_html(); |
325 | 325 | } |
326 | -add_action( 'getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status' ); |
|
326 | +add_action('getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status'); |
|
327 | 327 | |
328 | 328 | /** |
329 | 329 | * Displays the subscription profile id. |
330 | 330 | * |
331 | 331 | * @param WPInv_Subscription $subscription |
332 | 332 | */ |
333 | -function getpaid_admin_subscription_metabox_display_profile_id( $subscription ) { |
|
333 | +function getpaid_admin_subscription_metabox_display_profile_id($subscription) { |
|
334 | 334 | |
335 | 335 | $profile_id = $subscription->get_profile_id(); |
336 | 336 | |
@@ -339,32 +339,32 @@ discard block |
||
339 | 339 | 'type' => 'text', |
340 | 340 | 'id' => 'wpinv_subscription_profile_id', |
341 | 341 | 'name' => 'wpinv_subscription_profile_id', |
342 | - 'label' => __( 'Profile Id', 'invoicing' ), |
|
342 | + 'label' => __('Profile Id', 'invoicing'), |
|
343 | 343 | 'label_type' => 'hidden', |
344 | - 'placeholder' => __( 'Profile Id', 'invoicing' ), |
|
345 | - 'value' => sanitize_text_field( $profile_id ), |
|
344 | + 'placeholder' => __('Profile Id', 'invoicing'), |
|
345 | + 'value' => sanitize_text_field($profile_id), |
|
346 | 346 | 'input_group_right' => '', |
347 | 347 | 'no_wrap' => true, |
348 | 348 | ) |
349 | 349 | ); |
350 | 350 | |
351 | - echo str_ireplace( 'form-control', 'regular-text', $input ); |
|
351 | + echo str_ireplace('form-control', 'regular-text', $input); |
|
352 | 352 | |
353 | - $url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $subscription ); |
|
354 | - if ( ! empty( $url ) ) { |
|
355 | - $url = esc_url_raw( $url ); |
|
356 | - echo ' <a href="' . $url . '" title="' . __( 'View in Gateway', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>'; |
|
353 | + $url = apply_filters('getpaid_remote_subscription_profile_url', '', $subscription); |
|
354 | + if (!empty($url)) { |
|
355 | + $url = esc_url_raw($url); |
|
356 | + echo ' <a href="' . $url . '" title="' . __('View in Gateway', 'invoicing') . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>'; |
|
357 | 357 | } |
358 | 358 | |
359 | 359 | } |
360 | -add_action( 'getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id' ); |
|
360 | +add_action('getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id'); |
|
361 | 361 | |
362 | 362 | /** |
363 | 363 | * Displays the subscriptions update metabox. |
364 | 364 | * |
365 | 365 | * @param WPInv_Subscription $subscription |
366 | 366 | */ |
367 | -function getpaid_admin_subscription_update_metabox( $subscription ) { |
|
367 | +function getpaid_admin_subscription_update_metabox($subscription) { |
|
368 | 368 | |
369 | 369 | ?> |
370 | 370 | <div class="mt-3"> |
@@ -377,10 +377,10 @@ discard block |
||
377 | 377 | 'id' => 'subscription_status_update_select', |
378 | 378 | 'required' => true, |
379 | 379 | 'no_wrap' => false, |
380 | - 'label' => __( 'Subscription Status', 'invoicing' ), |
|
381 | - 'help_text' => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ), |
|
380 | + 'label' => __('Subscription Status', 'invoicing'), |
|
381 | + 'help_text' => __('Updating the status will trigger related actions and hooks', 'invoicing'), |
|
382 | 382 | 'select2' => true, |
383 | - 'value' => $subscription->get_status( 'edit' ), |
|
383 | + 'value' => $subscription->get_status('edit'), |
|
384 | 384 | ) |
385 | 385 | ); |
386 | 386 | ?> |
@@ -388,13 +388,13 @@ discard block |
||
388 | 388 | <div class="mt-2 px-3 py-2 bg-light border-top" style="margin: -12px;"> |
389 | 389 | |
390 | 390 | <?php |
391 | - submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false ); |
|
391 | + submit_button(__('Update', 'invoicing'), 'primary', 'submit', false); |
|
392 | 392 | |
393 | - $url = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) ); |
|
394 | - $anchor = __( 'Renew Subscription', 'invoicing' ); |
|
395 | - $title = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' ); |
|
393 | + $url = esc_url(wp_nonce_url(add_query_arg('getpaid-admin-action', 'subscription_manual_renew'), 'getpaid-nonce', 'getpaid-nonce')); |
|
394 | + $anchor = __('Renew Subscription', 'invoicing'); |
|
395 | + $title = esc_attr__('Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing'); |
|
396 | 396 | |
397 | - if ( $subscription->is_active() ) { |
|
397 | + if ($subscription->is_active()) { |
|
398 | 398 | echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>"; |
399 | 399 | } |
400 | 400 | |
@@ -406,31 +406,31 @@ discard block |
||
406 | 406 | * |
407 | 407 | * @param WPInv_Subscription $subscription |
408 | 408 | */ |
409 | -function getpaid_admin_subscription_invoice_details_metabox( $subscription ) { |
|
409 | +function getpaid_admin_subscription_invoice_details_metabox($subscription) { |
|
410 | 410 | |
411 | 411 | $columns = apply_filters( |
412 | 412 | 'getpaid_subscription_related_invoices_columns', |
413 | 413 | array( |
414 | - 'invoice' => __( 'Invoice', 'invoicing' ), |
|
415 | - 'relationship' => __( 'Relationship', 'invoicing' ), |
|
416 | - 'date' => __( 'Date', 'invoicing' ), |
|
417 | - 'status' => __( 'Status', 'invoicing' ), |
|
418 | - 'total' => __( 'Total', 'invoicing' ), |
|
414 | + 'invoice' => __('Invoice', 'invoicing'), |
|
415 | + 'relationship' => __('Relationship', 'invoicing'), |
|
416 | + 'date' => __('Date', 'invoicing'), |
|
417 | + 'status' => __('Status', 'invoicing'), |
|
418 | + 'total' => __('Total', 'invoicing'), |
|
419 | 419 | ), |
420 | 420 | $subscription |
421 | 421 | ); |
422 | 422 | |
423 | 423 | // Prepare the invoices. |
424 | - $payments = $subscription->get_child_payments( ! is_admin() ); |
|
424 | + $payments = $subscription->get_child_payments(!is_admin()); |
|
425 | 425 | $parent = $subscription->get_parent_invoice(); |
426 | 426 | |
427 | - if ( $parent->get_id() ) { |
|
428 | - $payments = array_merge( array( $parent ), $payments ); |
|
427 | + if ($parent->get_id()) { |
|
428 | + $payments = array_merge(array($parent), $payments); |
|
429 | 429 | } |
430 | 430 | |
431 | 431 | $table_class = 'w-100 bg-white'; |
432 | 432 | |
433 | - if ( ! is_admin() ) { |
|
433 | + if (!is_admin()) { |
|
434 | 434 | $table_class = 'table table-bordered table-striped'; |
435 | 435 | } |
436 | 436 | |
@@ -442,9 +442,9 @@ discard block |
||
442 | 442 | <thead> |
443 | 443 | <tr> |
444 | 444 | <?php |
445 | - foreach ( $columns as $key => $label ) { |
|
446 | - $key = esc_attr( $key ); |
|
447 | - $label = sanitize_text_field( $label ); |
|
445 | + foreach ($columns as $key => $label) { |
|
446 | + $key = esc_attr($key); |
|
447 | + $label = sanitize_text_field($label); |
|
448 | 448 | |
449 | 449 | echo "<th class='subscription-invoice-field-$key bg-light p-2 text-left color-dark font-weight-bold'>$label</th>"; |
450 | 450 | } |
@@ -454,50 +454,50 @@ discard block |
||
454 | 454 | |
455 | 455 | <tbody> |
456 | 456 | |
457 | - <?php if ( empty( $payments ) ) : ?> |
|
457 | + <?php if (empty($payments)) : ?> |
|
458 | 458 | <tr> |
459 | 459 | <td colspan="<?php echo count($columns); ?>" class="p-2 text-left text-muted"> |
460 | - <?php _e( 'This subscription has no invoices.', 'invoicing' ); ?> |
|
460 | + <?php _e('This subscription has no invoices.', 'invoicing'); ?> |
|
461 | 461 | </td> |
462 | 462 | </tr> |
463 | 463 | <?php endif; ?> |
464 | 464 | |
465 | 465 | <?php |
466 | 466 | |
467 | - foreach( $payments as $payment ) : |
|
467 | + foreach ($payments as $payment) : |
|
468 | 468 | |
469 | 469 | // Ensure that we have an invoice. |
470 | - $payment = new WPInv_Invoice( $payment ); |
|
470 | + $payment = new WPInv_Invoice($payment); |
|
471 | 471 | |
472 | 472 | // Abort if the invoice is invalid. |
473 | - if ( ! $payment->get_id() ) { |
|
473 | + if (!$payment->get_id()) { |
|
474 | 474 | continue; |
475 | 475 | } |
476 | 476 | |
477 | 477 | echo '<tr>'; |
478 | 478 | |
479 | - foreach ( array_keys( $columns ) as $key ) { |
|
479 | + foreach (array_keys($columns) as $key) { |
|
480 | 480 | |
481 | 481 | echo '<td class="p-2 text-left">'; |
482 | 482 | |
483 | - switch( $key ) { |
|
483 | + switch ($key) { |
|
484 | 484 | |
485 | 485 | case 'total': |
486 | - echo '<strong>' . wpinv_price( $payment->get_total(), $payment->get_currency() ) . '</strong>'; |
|
486 | + echo '<strong>' . wpinv_price($payment->get_total(), $payment->get_currency()) . '</strong>'; |
|
487 | 487 | break; |
488 | 488 | |
489 | 489 | case 'relationship': |
490 | - echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' ); |
|
490 | + echo $payment->is_renewal() ? __('Renewal Invoice', 'invoicing') : __('Initial Invoice', 'invoicing'); |
|
491 | 491 | break; |
492 | 492 | |
493 | 493 | case 'date': |
494 | - echo getpaid_format_date_value( $payment->get_date_created() ); |
|
494 | + echo getpaid_format_date_value($payment->get_date_created()); |
|
495 | 495 | break; |
496 | 496 | |
497 | 497 | case 'status': |
498 | 498 | |
499 | 499 | $status = $payment->get_status_nicename(); |
500 | - if ( is_admin() ) { |
|
500 | + if (is_admin()) { |
|
501 | 501 | $status = $payment->get_status_label_html(); |
502 | 502 | } |
503 | 503 | |
@@ -505,13 +505,13 @@ discard block |
||
505 | 505 | break; |
506 | 506 | |
507 | 507 | case 'invoice': |
508 | - $link = esc_url( get_edit_post_link( $payment->get_id() ) ); |
|
508 | + $link = esc_url(get_edit_post_link($payment->get_id())); |
|
509 | 509 | |
510 | - if ( ! is_admin() ) { |
|
511 | - $link = esc_url( $payment->get_view_url() ); |
|
510 | + if (!is_admin()) { |
|
511 | + $link = esc_url($payment->get_view_url()); |
|
512 | 512 | } |
513 | 513 | |
514 | - $invoice = sanitize_text_field( $payment->get_number() ); |
|
514 | + $invoice = sanitize_text_field($payment->get_number()); |
|
515 | 515 | echo "<a href='$link'>$invoice</a>"; |
516 | 516 | break; |
517 | 517 | } |
@@ -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 | * Abstaract Payment Gateway class. |
@@ -139,55 +139,55 @@ discard block |
||
139 | 139 | public function __construct() { |
140 | 140 | |
141 | 141 | // Register gateway. |
142 | - add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
142 | + add_filter('wpinv_payment_gateways', array($this, 'register_gateway')); |
|
143 | 143 | |
144 | - $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
144 | + $this->enabled = wpinv_is_gateway_active($this->id); |
|
145 | 145 | |
146 | 146 | // Enable Subscriptions. |
147 | - if ( $this->supports( 'subscription' ) ) { |
|
148 | - add_filter( "wpinv_{$this->id}_support_subscription", '__return_true' ); |
|
147 | + if ($this->supports('subscription')) { |
|
148 | + add_filter("wpinv_{$this->id}_support_subscription", '__return_true'); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | // Enable sandbox. |
152 | - if ( $this->supports( 'sandbox' ) ) { |
|
153 | - add_filter( "wpinv_{$this->id}_supports_sandbox", '__return_true' ); |
|
152 | + if ($this->supports('sandbox')) { |
|
153 | + add_filter("wpinv_{$this->id}_supports_sandbox", '__return_true'); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | // Invoice addons. |
157 | - if ( $this->supports( 'addons' ) ) { |
|
158 | - add_filter( "getpaid_{$this->id}_supports_addons", '__return_true' ); |
|
159 | - add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 ); |
|
157 | + if ($this->supports('addons')) { |
|
158 | + add_filter("getpaid_{$this->id}_supports_addons", '__return_true'); |
|
159 | + add_action("getpaid_process_{$this->id}_invoice_addons", array($this, 'process_addons'), 10, 2); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | // Gateway settings. |
163 | - add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
163 | + add_filter("wpinv_gateway_settings_{$this->id}", array($this, 'admin_settings')); |
|
164 | 164 | |
165 | 165 | |
166 | 166 | // Gateway checkout fiellds. |
167 | - add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
167 | + add_action("wpinv_{$this->id}_cc_form", array($this, 'payment_fields'), 10, 2); |
|
168 | 168 | |
169 | 169 | // Process payment. |
170 | - add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
170 | + add_action("getpaid_gateway_{$this->id}", array($this, 'process_payment'), 10, 3); |
|
171 | 171 | |
172 | 172 | // Change the checkout button text. |
173 | - if ( ! empty( $this->checkout_button_text ) ) { |
|
174 | - add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
173 | + if (!empty($this->checkout_button_text)) { |
|
174 | + add_filter("getpaid_gateway_{$this->id}_checkout_button_label", array($this, 'rename_checkout_button')); |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | // Check if a gateway is valid for a given currency. |
178 | - add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
178 | + add_filter("getpaid_gateway_{$this->id}_is_valid_for_currency", array($this, 'validate_currency'), 10, 2); |
|
179 | 179 | |
180 | 180 | // Generate the transaction url. |
181 | - add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
181 | + add_filter("getpaid_gateway_{$this->id}_transaction_url", array($this, 'filter_transaction_url'), 10, 2); |
|
182 | 182 | |
183 | 183 | // Generate the subscription url. |
184 | - add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 ); |
|
184 | + add_filter('getpaid_remote_subscription_profile_url', array($this, 'generate_subscription_url'), 10, 2); |
|
185 | 185 | |
186 | 186 | // Confirm payments. |
187 | - add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
187 | + add_filter("wpinv_payment_confirm_{$this->id}", array($this, 'confirm_payment'), 10, 2); |
|
188 | 188 | |
189 | 189 | // Verify IPNs. |
190 | - add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
190 | + add_action("wpinv_verify_{$this->id}_ipn", array($this, 'verify_ipn')); |
|
191 | 191 | |
192 | 192 | } |
193 | 193 | |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | * @since 1.0.19 |
198 | 198 | * @return bool |
199 | 199 | */ |
200 | - public function is( $gateway ) { |
|
200 | + public function is($gateway) { |
|
201 | 201 | return $gateway == $this->id; |
202 | 202 | } |
203 | 203 | |
@@ -207,23 +207,23 @@ discard block |
||
207 | 207 | * @since 1.0.19 |
208 | 208 | * @return array |
209 | 209 | */ |
210 | - public function get_tokens( $sandbox = null ) { |
|
210 | + public function get_tokens($sandbox = null) { |
|
211 | 211 | |
212 | - if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
213 | - $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
212 | + if (is_user_logged_in() && $this->supports('tokens') && 0 == count($this->tokens)) { |
|
213 | + $tokens = get_user_meta(get_current_user_id(), "getpaid_{$this->id}_tokens", true); |
|
214 | 214 | |
215 | - if ( is_array( $tokens ) ) { |
|
215 | + if (is_array($tokens)) { |
|
216 | 216 | $this->tokens = $tokens; |
217 | 217 | } |
218 | 218 | |
219 | 219 | } |
220 | 220 | |
221 | - if ( ! is_bool( $sandbox ) ) { |
|
221 | + if (!is_bool($sandbox)) { |
|
222 | 222 | return $this->tokens; |
223 | 223 | } |
224 | 224 | |
225 | - $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
226 | - return wp_list_filter( $this->tokens, $args ); |
|
225 | + $args = array('type' => $sandbox ? 'sandbox' : 'live'); |
|
226 | + return wp_list_filter($this->tokens, $args); |
|
227 | 227 | |
228 | 228 | } |
229 | 229 | |
@@ -232,12 +232,12 @@ discard block |
||
232 | 232 | * |
233 | 233 | * @since 1.0.19 |
234 | 234 | */ |
235 | - public function save_token( $token ) { |
|
235 | + public function save_token($token) { |
|
236 | 236 | |
237 | 237 | $tokens = $this->get_tokens(); |
238 | 238 | $tokens[] = $token; |
239 | 239 | |
240 | - update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
240 | + update_user_meta(get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens); |
|
241 | 241 | |
242 | 242 | $this->tokens = $tokens; |
243 | 243 | |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | * @return string |
250 | 250 | */ |
251 | 251 | public function get_method_title() { |
252 | - return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
252 | + return apply_filters('getpaid_gateway_method_title', $this->method_title, $this); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | /** |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | * @return string |
259 | 259 | */ |
260 | 260 | public function get_method_description() { |
261 | - return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
261 | + return apply_filters('getpaid_gateway_method_description', $this->method_description, $this); |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | /** |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | * @param WPInv_Invoice $invoice Invoice object. |
268 | 268 | * @return string |
269 | 269 | */ |
270 | - public function get_return_url( $invoice ) { |
|
270 | + public function get_return_url($invoice) { |
|
271 | 271 | |
272 | 272 | // Payment success url |
273 | 273 | $return_url = add_query_arg( |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | wpinv_get_success_page_uri() |
280 | 280 | ); |
281 | 281 | |
282 | - return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
282 | + return apply_filters('getpaid_gateway_success_url', $return_url, $invoice, $this); |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | /** |
@@ -288,24 +288,24 @@ discard block |
||
288 | 288 | * @param string $content Success page content. |
289 | 289 | * @return string |
290 | 290 | */ |
291 | - public function confirm_payment( $content ) { |
|
291 | + public function confirm_payment($content) { |
|
292 | 292 | |
293 | 293 | // Retrieve the invoice. |
294 | 294 | $invoice_id = getpaid_get_current_invoice_id(); |
295 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
295 | + $invoice = wpinv_get_invoice($invoice_id); |
|
296 | 296 | |
297 | 297 | // Ensure that it exists and that it is pending payment. |
298 | - if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
298 | + if (empty($invoice_id) || !$invoice->needs_payment()) { |
|
299 | 299 | return $content; |
300 | 300 | } |
301 | 301 | |
302 | 302 | // Can the user view this invoice?? |
303 | - if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
303 | + if (!wpinv_user_can_view_invoice($invoice)) { |
|
304 | 304 | return $content; |
305 | 305 | } |
306 | 306 | |
307 | 307 | // Show payment processing indicator. |
308 | - return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
308 | + return wpinv_get_template_html('wpinv-payment-processing.php', compact('invoice')); |
|
309 | 309 | } |
310 | 310 | |
311 | 311 | /** |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | * @param GetPaid_Form_Item[] $items |
323 | 323 | * @return WPInv_Invoice |
324 | 324 | */ |
325 | - public function process_addons( $invoice, $items ) { |
|
325 | + public function process_addons($invoice, $items) { |
|
326 | 326 | |
327 | 327 | } |
328 | 328 | |
@@ -333,14 +333,14 @@ discard block |
||
333 | 333 | * @param WPInv_Invoice $invoice Invoice object. |
334 | 334 | * @return string transaction URL, or empty string. |
335 | 335 | */ |
336 | - public function filter_transaction_url( $transaction_url, $invoice ) { |
|
336 | + public function filter_transaction_url($transaction_url, $invoice) { |
|
337 | 337 | |
338 | - $transaction_id = $invoice->get_transaction_id(); |
|
338 | + $transaction_id = $invoice->get_transaction_id(); |
|
339 | 339 | |
340 | - if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
341 | - $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
342 | - $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
343 | - $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
340 | + if (!empty($this->view_transaction_url) && !empty($transaction_id)) { |
|
341 | + $transaction_url = sprintf($this->view_transaction_url, $transaction_id); |
|
342 | + $replace = $this->is_sandbox($invoice) ? 'sandbox' : ''; |
|
343 | + $transaction_url = str_replace('{sandbox}', $replace, $transaction_url); |
|
344 | 344 | } |
345 | 345 | |
346 | 346 | return $transaction_url; |
@@ -353,15 +353,15 @@ discard block |
||
353 | 353 | * @param WPInv_Subscription $subscription Subscription objectt. |
354 | 354 | * @return string subscription URL, or empty string. |
355 | 355 | */ |
356 | - public function generate_subscription_url( $subscription_url, $subscription ) { |
|
356 | + public function generate_subscription_url($subscription_url, $subscription) { |
|
357 | 357 | |
358 | - $profile_id = $subscription->get_profile_id(); |
|
358 | + $profile_id = $subscription->get_profile_id(); |
|
359 | 359 | |
360 | - if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
360 | + if ($this->id == $subscription->get_gateway() && !empty($this->view_subscription_url) && !empty($profile_id)) { |
|
361 | 361 | |
362 | - $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
363 | - $replace = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : ''; |
|
364 | - $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
362 | + $subscription_url = sprintf($this->view_subscription_url, $profile_id); |
|
363 | + $replace = $this->is_sandbox($subscription->get_parent_invoice()) ? 'sandbox' : ''; |
|
364 | + $subscription_url = str_replace('{sandbox}', $replace, $subscription_url); |
|
365 | 365 | |
366 | 366 | } |
367 | 367 | |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | * @return bool |
375 | 375 | */ |
376 | 376 | public function is_available() { |
377 | - return ! empty( $this->enabled ); |
|
377 | + return !empty($this->enabled); |
|
378 | 378 | } |
379 | 379 | |
380 | 380 | /** |
@@ -383,7 +383,7 @@ discard block |
||
383 | 383 | * @return string |
384 | 384 | */ |
385 | 385 | public function get_title() { |
386 | - return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
386 | + return apply_filters('getpaid_gateway_title', $this->title, $this); |
|
387 | 387 | } |
388 | 388 | |
389 | 389 | /** |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | * @return string |
393 | 393 | */ |
394 | 394 | public function get_description() { |
395 | - return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
395 | + return apply_filters('getpaid_gateway_description', $this->description, $this); |
|
396 | 396 | } |
397 | 397 | |
398 | 398 | /** |
@@ -404,9 +404,9 @@ discard block |
||
404 | 404 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
405 | 405 | * @return void |
406 | 406 | */ |
407 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
407 | + public function process_payment($invoice, $submission_data, $submission) { |
|
408 | 408 | // Process the payment then either redirect to the success page or the gateway. |
409 | - do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
409 | + do_action('getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission); |
|
410 | 410 | } |
411 | 411 | |
412 | 412 | /** |
@@ -420,8 +420,8 @@ discard block |
||
420 | 420 | * @param string $reason Refund reason. |
421 | 421 | * @return WP_Error|bool True or false based on success, or a WP_Error object. |
422 | 422 | */ |
423 | - public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
424 | - return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
423 | + public function process_refund($invoice, $amount = null, $reason = '') { |
|
424 | + return apply_filters('getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason); |
|
425 | 425 | } |
426 | 426 | |
427 | 427 | /** |
@@ -430,8 +430,8 @@ discard block |
||
430 | 430 | * @param int $invoice_id 0 or invoice id. |
431 | 431 | * @param GetPaid_Payment_Form $form Current payment form. |
432 | 432 | */ |
433 | - public function payment_fields( $invoice_id, $form ) { |
|
434 | - do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
433 | + public function payment_fields($invoice_id, $form) { |
|
434 | + do_action('getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form); |
|
435 | 435 | } |
436 | 436 | |
437 | 437 | /** |
@@ -439,7 +439,7 @@ discard block |
||
439 | 439 | * |
440 | 440 | * @param array $admin_settings |
441 | 441 | */ |
442 | - public function admin_settings( $admin_settings ) { |
|
442 | + public function admin_settings($admin_settings) { |
|
443 | 443 | return $admin_settings; |
444 | 444 | } |
445 | 445 | |
@@ -448,8 +448,8 @@ discard block |
||
448 | 448 | * |
449 | 449 | * @param string $option |
450 | 450 | */ |
451 | - public function get_option( $option, $default = false ) { |
|
452 | - return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
451 | + public function get_option($option, $default = false) { |
|
452 | + return wpinv_get_option($this->id . '_' . $option, $default); |
|
453 | 453 | } |
454 | 454 | |
455 | 455 | /** |
@@ -462,8 +462,8 @@ discard block |
||
462 | 462 | * @return bool True if the gateway supports the feature, false otherwise. |
463 | 463 | * @since 1.0.19 |
464 | 464 | */ |
465 | - public function supports( $feature ) { |
|
466 | - return apply_filters( 'getpaid_payment_gateway_supports', in_array( $feature, $this->supports ), $feature, $this ); |
|
465 | + public function supports($feature) { |
|
466 | + return apply_filters('getpaid_payment_gateway_supports', in_array($feature, $this->supports), $feature, $this); |
|
467 | 467 | } |
468 | 468 | |
469 | 469 | /** |
@@ -471,36 +471,36 @@ discard block |
||
471 | 471 | * |
472 | 472 | * @param bool $save whether or not to display the save button. |
473 | 473 | */ |
474 | - public function get_cc_form( $save = false ) { |
|
474 | + public function get_cc_form($save = false) { |
|
475 | 475 | |
476 | 476 | ob_start(); |
477 | 477 | |
478 | - $id_prefix = esc_attr( uniqid( $this->id ) ); |
|
478 | + $id_prefix = esc_attr(uniqid($this->id)); |
|
479 | 479 | |
480 | 480 | $months = array( |
481 | - '01' => __( 'January', 'invoicing' ), |
|
482 | - '02' => __( 'February', 'invoicing' ), |
|
483 | - '03' => __( 'March', 'invoicing' ), |
|
484 | - '04' => __( 'April', 'invoicing' ), |
|
485 | - '05' => __( 'May', 'invoicing' ), |
|
486 | - '06' => __( 'June', 'invoicing' ), |
|
487 | - '07' => __( 'July', 'invoicing' ), |
|
488 | - '08' => __( 'August', 'invoicing' ), |
|
489 | - '09' => __( 'September', 'invoicing' ), |
|
490 | - '10' => __( 'October', 'invoicing' ), |
|
491 | - '11' => __( 'November', 'invoicing' ), |
|
492 | - '12' => __( 'December', 'invoicing' ), |
|
481 | + '01' => __('January', 'invoicing'), |
|
482 | + '02' => __('February', 'invoicing'), |
|
483 | + '03' => __('March', 'invoicing'), |
|
484 | + '04' => __('April', 'invoicing'), |
|
485 | + '05' => __('May', 'invoicing'), |
|
486 | + '06' => __('June', 'invoicing'), |
|
487 | + '07' => __('July', 'invoicing'), |
|
488 | + '08' => __('August', 'invoicing'), |
|
489 | + '09' => __('September', 'invoicing'), |
|
490 | + '10' => __('October', 'invoicing'), |
|
491 | + '11' => __('November', 'invoicing'), |
|
492 | + '12' => __('December', 'invoicing'), |
|
493 | 493 | ); |
494 | 494 | |
495 | - $year = (int) date( 'Y', current_time( 'timestamp' ) ); |
|
495 | + $year = (int) date('Y', current_time('timestamp')); |
|
496 | 496 | $years = array(); |
497 | 497 | |
498 | - for ( $i = 0; $i <= 10; $i++ ) { |
|
499 | - $years[ $year + $i ] = $year + $i; |
|
498 | + for ($i = 0; $i <= 10; $i++) { |
|
499 | + $years[$year + $i] = $year + $i; |
|
500 | 500 | } |
501 | 501 | |
502 | 502 | ?> |
503 | - <div class="<?php echo esc_attr( $this->id );?>-cc-form getpaid-cc-form mt-1"> |
|
503 | + <div class="<?php echo esc_attr($this->id); ?>-cc-form getpaid-cc-form mt-1"> |
|
504 | 504 | |
505 | 505 | |
506 | 506 | <div class="getpaid-cc-card-inner"> |
@@ -509,14 +509,14 @@ discard block |
||
509 | 509 | <div class="col-12"> |
510 | 510 | |
511 | 511 | <div class="form-group"> |
512 | - <label for="<?php echo esc_attr( "$id_prefix-cc-number" ) ?>"><?php _e( 'Card number', 'invoicing' ); ?></label> |
|
512 | + <label for="<?php echo esc_attr("$id_prefix-cc-number") ?>"><?php _e('Card number', 'invoicing'); ?></label> |
|
513 | 513 | <div class="input-group input-group-sm"> |
514 | 514 | <div class="input-group-prepend "> |
515 | 515 | <span class="input-group-text"> |
516 | 516 | <i class="fa fa-credit-card"></i> |
517 | 517 | </span> |
518 | 518 | </div> |
519 | - <input type="text" name="<?php echo esc_attr( $this->id . '[cc_number]' ) ?>authorizenet[cc_number]" id="<?php echo esc_attr( "$id_prefix-cc-number" ) ?>" class="form-control form-control-sm" autocomplete="cc-number"> |
|
519 | + <input type="text" name="<?php echo esc_attr($this->id . '[cc_number]') ?>authorizenet[cc_number]" id="<?php echo esc_attr("$id_prefix-cc-number") ?>" class="form-control form-control-sm" autocomplete="cc-number"> |
|
520 | 520 | </div> |
521 | 521 | </div> |
522 | 522 | |
@@ -524,17 +524,17 @@ discard block |
||
524 | 524 | |
525 | 525 | <div class="col-12"> |
526 | 526 | <div class="form-group"> |
527 | - <label><?php _e( 'Expiration', 'invoicing' ); ?></label> |
|
527 | + <label><?php _e('Expiration', 'invoicing'); ?></label> |
|
528 | 528 | <div class="form-row"> |
529 | 529 | |
530 | 530 | <div class="col"> |
531 | - <select class="form-control form-control-sm" autocomplete="cc-exp-month" name="<?php echo esc_attr( $this->id );?>[cc_expire_month]"> |
|
532 | - <option disabled selected="selected"><?php _e( 'MM', 'invoicing' ); ?></option> |
|
531 | + <select class="form-control form-control-sm" autocomplete="cc-exp-month" name="<?php echo esc_attr($this->id); ?>[cc_expire_month]"> |
|
532 | + <option disabled selected="selected"><?php _e('MM', 'invoicing'); ?></option> |
|
533 | 533 | |
534 | 534 | <?php |
535 | - foreach ( $months as $key => $month ) { |
|
536 | - $key = esc_attr( $key ); |
|
537 | - $month = wpinv_clean( $month ); |
|
535 | + foreach ($months as $key => $month) { |
|
536 | + $key = esc_attr($key); |
|
537 | + $month = wpinv_clean($month); |
|
538 | 538 | echo "<option value='$key'>$month</option>" . PHP_EOL; |
539 | 539 | } |
540 | 540 | ?> |
@@ -543,13 +543,13 @@ discard block |
||
543 | 543 | </div> |
544 | 544 | |
545 | 545 | <div class="col"> |
546 | - <select class="form-control form-control-sm" autocomplete="cc-exp-year" name="<?php echo esc_attr( $this->id );?>[cc_expire_year]"> |
|
547 | - <option disabled selected="selected"><?php _e( 'YY', 'invoicing' ); ?></option> |
|
546 | + <select class="form-control form-control-sm" autocomplete="cc-exp-year" name="<?php echo esc_attr($this->id); ?>[cc_expire_year]"> |
|
547 | + <option disabled selected="selected"><?php _e('YY', 'invoicing'); ?></option> |
|
548 | 548 | |
549 | 549 | <?php |
550 | - foreach ( $years as $key => $year ) { |
|
551 | - $key = esc_attr( $key ); |
|
552 | - $year = wpinv_clean( $year ); |
|
550 | + foreach ($years as $key => $year) { |
|
551 | + $key = esc_attr($key); |
|
552 | + $year = wpinv_clean($year); |
|
553 | 553 | echo "<option value='$key'>$year</option>" . PHP_EOL; |
554 | 554 | } |
555 | 555 | ?> |
@@ -567,7 +567,7 @@ discard block |
||
567 | 567 | array( |
568 | 568 | 'name' => $this->id . '[cc_cvv2]', |
569 | 569 | 'id' => "$id_prefix-cc-cvv2", |
570 | - 'label' => __( 'CCV', 'invoicing' ), |
|
570 | + 'label' => __('CCV', 'invoicing'), |
|
571 | 571 | 'label_type' => 'vertical', |
572 | 572 | 'class' => 'form-control-sm', |
573 | 573 | 'extra_attributes' => array( |
@@ -582,7 +582,7 @@ discard block |
||
582 | 582 | |
583 | 583 | <?php |
584 | 584 | |
585 | - if ( $save ) { |
|
585 | + if ($save) { |
|
586 | 586 | echo $this->save_payment_method_checkbox(); |
587 | 587 | } |
588 | 588 | |
@@ -601,7 +601,7 @@ discard block |
||
601 | 601 | * |
602 | 602 | * @since 1.0.19 |
603 | 603 | */ |
604 | - public function new_payment_method_entry( $form ) { |
|
604 | + public function new_payment_method_entry($form) { |
|
605 | 605 | echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>"; |
606 | 606 | } |
607 | 607 | |
@@ -611,16 +611,16 @@ discard block |
||
611 | 611 | * @since 1.0.19 |
612 | 612 | */ |
613 | 613 | public function saved_payment_methods() { |
614 | - $html = '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
614 | + $html = '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr(count($this->get_tokens($this->is_sandbox()))) . '">'; |
|
615 | 615 | |
616 | - foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
617 | - $html .= $this->get_saved_payment_method_option_html( $token ); |
|
616 | + foreach ($this->get_tokens($this->is_sandbox()) as $token) { |
|
617 | + $html .= $this->get_saved_payment_method_option_html($token); |
|
618 | 618 | } |
619 | 619 | |
620 | 620 | $html .= $this->get_new_payment_method_option_html(); |
621 | 621 | $html .= '</ul>'; |
622 | 622 | |
623 | - echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this ); |
|
623 | + echo apply_filters('getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this); |
|
624 | 624 | } |
625 | 625 | |
626 | 626 | /** |
@@ -630,7 +630,7 @@ discard block |
||
630 | 630 | * @param array $token Payment Token. |
631 | 631 | * @return string Generated payment method HTML |
632 | 632 | */ |
633 | - public function get_saved_payment_method_option_html( $token ) { |
|
633 | + public function get_saved_payment_method_option_html($token) { |
|
634 | 634 | |
635 | 635 | return sprintf( |
636 | 636 | '<li class="getpaid-payment-method form-group"> |
@@ -639,10 +639,10 @@ discard block |
||
639 | 639 | <span>%3$s</span> |
640 | 640 | </label> |
641 | 641 | </li>', |
642 | - esc_attr( $this->id ), |
|
643 | - esc_attr( $token['id'] ), |
|
644 | - esc_html( $token['name'] ), |
|
645 | - checked( empty( $token['default'] ), false, false ) |
|
642 | + esc_attr($this->id), |
|
643 | + esc_attr($token['id']), |
|
644 | + esc_html($token['name']), |
|
645 | + checked(empty($token['default']), false, false) |
|
646 | 646 | ); |
647 | 647 | |
648 | 648 | } |
@@ -654,7 +654,7 @@ discard block |
||
654 | 654 | */ |
655 | 655 | public function get_new_payment_method_option_html() { |
656 | 656 | |
657 | - $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
657 | + $label = apply_filters('getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __('Use a new payment method', 'invoicing'), $this); |
|
658 | 658 | |
659 | 659 | return sprintf( |
660 | 660 | '<li class="getpaid-new-payment-method"> |
@@ -663,8 +663,8 @@ discard block |
||
663 | 663 | <span>%2$s</span> |
664 | 664 | </label> |
665 | 665 | </li>', |
666 | - esc_attr( $this->id ), |
|
667 | - esc_html( $label ) |
|
666 | + esc_attr($this->id), |
|
667 | + esc_html($label) |
|
668 | 668 | ); |
669 | 669 | |
670 | 670 | } |
@@ -679,10 +679,10 @@ discard block |
||
679 | 679 | return aui()->input( |
680 | 680 | array( |
681 | 681 | 'type' => 'checkbox', |
682 | - 'name' => esc_attr( "getpaid-$this->id-new-payment-method" ), |
|
683 | - 'id' => esc_attr( uniqid( $this->id ) ), |
|
682 | + 'name' => esc_attr("getpaid-$this->id-new-payment-method"), |
|
683 | + 'id' => esc_attr(uniqid($this->id)), |
|
684 | 684 | 'required' => false, |
685 | - 'label' => esc_html__( 'Save payment method', 'invoicing' ), |
|
685 | + 'label' => esc_html__('Save payment method', 'invoicing'), |
|
686 | 686 | 'value' => 'true', |
687 | 687 | 'checked' => true, |
688 | 688 | 'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1', |
@@ -696,9 +696,9 @@ discard block |
||
696 | 696 | * |
697 | 697 | * @return array |
698 | 698 | */ |
699 | - public function register_gateway( $gateways ) { |
|
699 | + public function register_gateway($gateways) { |
|
700 | 700 | |
701 | - $gateways[ $this->id ] = array( |
|
701 | + $gateways[$this->id] = array( |
|
702 | 702 | |
703 | 703 | 'admin_label' => $this->method_title, |
704 | 704 | 'checkout_label' => $this->title, |
@@ -716,13 +716,13 @@ discard block |
||
716 | 716 | * @param WPInv_Invoice|null $invoice Invoice object or null. |
717 | 717 | * @return bool |
718 | 718 | */ |
719 | - public function is_sandbox( $invoice = null ) { |
|
719 | + public function is_sandbox($invoice = null) { |
|
720 | 720 | |
721 | - if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
721 | + if (!empty($invoice) && !$invoice->needs_payment()) { |
|
722 | 722 | return $invoice->get_mode() == 'test'; |
723 | 723 | } |
724 | 724 | |
725 | - return wpinv_is_test_mode( $this->id ); |
|
725 | + return wpinv_is_test_mode($this->id); |
|
726 | 726 | |
727 | 727 | } |
728 | 728 | |
@@ -740,15 +740,15 @@ discard block |
||
740 | 740 | * |
741 | 741 | * @return bool |
742 | 742 | */ |
743 | - public function validate_currency( $validation, $currency ) { |
|
743 | + public function validate_currency($validation, $currency) { |
|
744 | 744 | |
745 | 745 | // Required currencies. |
746 | - if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
746 | + if (!empty($this->currencies) && !in_array($currency, $this->currencies)) { |
|
747 | 747 | return false; |
748 | 748 | } |
749 | 749 | |
750 | 750 | // Excluded currencies. |
751 | - if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
751 | + if (!empty($this->exclude_currencies) && in_array($currency, $this->exclude_currencies)) { |
|
752 | 752 | return false; |
753 | 753 | } |
754 | 754 | |
@@ -759,13 +759,13 @@ discard block |
||
759 | 759 | * Displays an error |
760 | 760 | * |
761 | 761 | */ |
762 | - public function show_error( $code, $message, $type ) { |
|
762 | + public function show_error($code, $message, $type) { |
|
763 | 763 | |
764 | - if ( is_admin() ) { |
|
765 | - getpaid_admin()->{"show_$type"}( $message ); |
|
764 | + if (is_admin()) { |
|
765 | + getpaid_admin()->{"show_$type"}($message); |
|
766 | 766 | } |
767 | 767 | |
768 | - wpinv_set_error( $code, $message, $type ); |
|
768 | + wpinv_set_error($code, $message, $type); |
|
769 | 769 | |
770 | 770 | } |
771 | 771 |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | /** |
9 | 9 | * Main Subscriptions class. |
10 | 10 | * |
@@ -14,31 +14,31 @@ discard block |
||
14 | 14 | /** |
15 | 15 | * Class constructor. |
16 | 16 | */ |
17 | - public function __construct(){ |
|
17 | + public function __construct() { |
|
18 | 18 | |
19 | 19 | // Fire gateway specific hooks when a subscription changes. |
20 | - add_action( 'getpaid_subscription_status_changed', array( $this, 'process_subscription_status_change' ), 10, 3 ); |
|
20 | + add_action('getpaid_subscription_status_changed', array($this, 'process_subscription_status_change'), 10, 3); |
|
21 | 21 | |
22 | 22 | // De-activate a subscription whenever the invoice changes payment statuses. |
23 | - add_action( 'getpaid_invoice_status_wpi-refunded', array( $this, 'maybe_deactivate_invoice_subscription' ), 20 ); |
|
24 | - add_action( 'getpaid_invoice_status_wpi-failed', array( $this, 'maybe_deactivate_invoice_subscription' ), 20 ); |
|
25 | - add_action( 'getpaid_invoice_status_wpi-cancelled', array( $this, 'maybe_deactivate_invoice_subscription' ), 20 ); |
|
26 | - add_action( 'getpaid_invoice_status_wpi-pending', array( $this, 'maybe_deactivate_invoice_subscription' ), 20 ); |
|
23 | + add_action('getpaid_invoice_status_wpi-refunded', array($this, 'maybe_deactivate_invoice_subscription'), 20); |
|
24 | + add_action('getpaid_invoice_status_wpi-failed', array($this, 'maybe_deactivate_invoice_subscription'), 20); |
|
25 | + add_action('getpaid_invoice_status_wpi-cancelled', array($this, 'maybe_deactivate_invoice_subscription'), 20); |
|
26 | + add_action('getpaid_invoice_status_wpi-pending', array($this, 'maybe_deactivate_invoice_subscription'), 20); |
|
27 | 27 | |
28 | 28 | // Handles subscription cancelations. |
29 | - add_action( 'getpaid_authenticated_action_subscription_cancel', array( $this, 'user_cancel_single_subscription' ) ); |
|
29 | + add_action('getpaid_authenticated_action_subscription_cancel', array($this, 'user_cancel_single_subscription')); |
|
30 | 30 | |
31 | 31 | // Create a subscription whenever an invoice is created, (and update it when it is updated). |
32 | - add_action( 'getpaid_new_invoice', array( $this, 'maybe_create_invoice_subscription' ) ); |
|
33 | - add_action( 'getpaid_update_invoice', array( $this, 'maybe_update_invoice_subscription' ) ); |
|
32 | + add_action('getpaid_new_invoice', array($this, 'maybe_create_invoice_subscription')); |
|
33 | + add_action('getpaid_update_invoice', array($this, 'maybe_update_invoice_subscription')); |
|
34 | 34 | |
35 | 35 | // Handles admin subscription update actions. |
36 | - add_action( 'getpaid_authenticated_admin_action_update_single_subscription', array( $this, 'admin_update_single_subscription' ) ); |
|
37 | - add_action( 'getpaid_authenticated_admin_action_subscription_manual_renew', array( $this, 'admin_renew_single_subscription' ) ); |
|
38 | - add_action( 'getpaid_authenticated_admin_action_subscription_manual_delete', array( $this, 'admin_delete_single_subscription' ) ); |
|
36 | + add_action('getpaid_authenticated_admin_action_update_single_subscription', array($this, 'admin_update_single_subscription')); |
|
37 | + add_action('getpaid_authenticated_admin_action_subscription_manual_renew', array($this, 'admin_renew_single_subscription')); |
|
38 | + add_action('getpaid_authenticated_admin_action_subscription_manual_delete', array($this, 'admin_delete_single_subscription')); |
|
39 | 39 | |
40 | 40 | // Filter invoice item row actions. |
41 | - add_action( 'getpaid-invoice-page-line-item-actions', array( $this, 'filter_invoice_line_item_actions' ), 10, 3 ); |
|
41 | + add_action('getpaid-invoice-page-line-item-actions', array($this, 'filter_invoice_line_item_actions'), 10, 3); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -47,19 +47,19 @@ discard block |
||
47 | 47 | * @param WPInv_Invoice $invoice |
48 | 48 | * @return WPInv_Subscription|bool |
49 | 49 | */ |
50 | - public function get_invoice_subscription( $invoice ) { |
|
50 | + public function get_invoice_subscription($invoice) { |
|
51 | 51 | $subscription_id = $invoice->get_subscription_id(); |
52 | 52 | |
53 | 53 | // Fallback to the parent invoice if the child invoice has no subscription id. |
54 | - if ( empty( $subscription_id && $invoice->is_renewal() ) ) { |
|
54 | + if (empty($subscription_id && $invoice->is_renewal())) { |
|
55 | 55 | $subscription_id = $invoice->get_parent_payment()->get_subscription_id(); |
56 | 56 | } |
57 | 57 | |
58 | 58 | // Fetch the subscription. |
59 | - $subscription = new WPInv_Subscription( $subscription_id ); |
|
59 | + $subscription = new WPInv_Subscription($subscription_id); |
|
60 | 60 | |
61 | 61 | // Return subscription or use a fallback for backwards compatibility. |
62 | - return $subscription->get_id() ? $subscription : wpinv_get_subscription( $invoice ); |
|
62 | + return $subscription->get_id() ? $subscription : wpinv_get_subscription($invoice); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -67,16 +67,16 @@ discard block |
||
67 | 67 | * |
68 | 68 | * @param WPInv_Invoice $invoice |
69 | 69 | */ |
70 | - public function maybe_deactivate_invoice_subscription( $invoice ) { |
|
70 | + public function maybe_deactivate_invoice_subscription($invoice) { |
|
71 | 71 | |
72 | - $subscription = $this->get_invoice_subscription( $invoice ); |
|
72 | + $subscription = $this->get_invoice_subscription($invoice); |
|
73 | 73 | |
74 | 74 | // Abort if the subscription is missing or not active. |
75 | - if ( empty( $subscription ) || ! $subscription->is_active() ) { |
|
75 | + if (empty($subscription) || !$subscription->is_active()) { |
|
76 | 76 | return; |
77 | 77 | } |
78 | 78 | |
79 | - $subscription->set_status( 'pending' ); |
|
79 | + $subscription->set_status('pending'); |
|
80 | 80 | $subscription->save(); |
81 | 81 | |
82 | 82 | } |
@@ -88,15 +88,15 @@ discard block |
||
88 | 88 | * @param string $from |
89 | 89 | * @param string $to |
90 | 90 | */ |
91 | - public function process_subscription_status_change( $subscription, $from, $to ) { |
|
91 | + public function process_subscription_status_change($subscription, $from, $to) { |
|
92 | 92 | |
93 | 93 | $gateway = $subscription->get_gateway(); |
94 | 94 | |
95 | - if ( ! empty( $gateway ) ) { |
|
96 | - $gateway = sanitize_key( $gateway ); |
|
97 | - $from = sanitize_key( $from ); |
|
98 | - $to = sanitize_key( $to ); |
|
99 | - do_action( "getpaid_{$gateway}_subscription_$to", $subscription, $from ); |
|
95 | + if (!empty($gateway)) { |
|
96 | + $gateway = sanitize_key($gateway); |
|
97 | + $from = sanitize_key($from); |
|
98 | + $to = sanitize_key($to); |
|
99 | + do_action("getpaid_{$gateway}_subscription_$to", $subscription, $from); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | } |
@@ -109,8 +109,8 @@ discard block |
||
109 | 109 | * @deprecated |
110 | 110 | * @return mixed|string|void |
111 | 111 | */ |
112 | - public static function wpinv_get_pretty_subscription_frequency( $period, $frequency_count = 1 ) { |
|
113 | - return getpaid_get_subscription_period_label( $period, $frequency_count ); |
|
112 | + public static function wpinv_get_pretty_subscription_frequency($period, $frequency_count = 1) { |
|
113 | + return getpaid_get_subscription_period_label($period, $frequency_count); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | /** |
@@ -120,34 +120,34 @@ discard block |
||
120 | 120 | * @since 1.0.0 |
121 | 121 | * @return void |
122 | 122 | */ |
123 | - public function user_cancel_single_subscription( $data ) { |
|
123 | + public function user_cancel_single_subscription($data) { |
|
124 | 124 | |
125 | 125 | // Ensure there is a subscription to cancel. |
126 | - if ( empty( $data['subscription'] ) ) { |
|
126 | + if (empty($data['subscription'])) { |
|
127 | 127 | return; |
128 | 128 | } |
129 | 129 | |
130 | - $subscription = new WPInv_Subscription( (int) $data['subscription'] ); |
|
130 | + $subscription = new WPInv_Subscription((int) $data['subscription']); |
|
131 | 131 | |
132 | 132 | // Ensure that it exists and that it belongs to the current user. |
133 | - if ( ! $subscription->get_id() || $subscription->get_customer_id() != get_current_user_id() ) { |
|
134 | - wpinv_set_error( 'invalid_subscription', __( 'You do not have permission to cancel this subscription', 'invoicing' ) ); |
|
133 | + if (!$subscription->get_id() || $subscription->get_customer_id() != get_current_user_id()) { |
|
134 | + wpinv_set_error('invalid_subscription', __('You do not have permission to cancel this subscription', 'invoicing')); |
|
135 | 135 | |
136 | 136 | // Can it be cancelled. |
137 | - } else if ( ! $subscription->can_cancel() ) { |
|
138 | - wpinv_set_error( 'cannot_cancel', __( 'This subscription cannot be cancelled as it is not active.', 'invoicing' ) ); |
|
137 | + } else if (!$subscription->can_cancel()) { |
|
138 | + wpinv_set_error('cannot_cancel', __('This subscription cannot be cancelled as it is not active.', 'invoicing')); |
|
139 | 139 | |
140 | 140 | |
141 | 141 | // Cancel it. |
142 | 142 | } else { |
143 | 143 | |
144 | 144 | $subscription->cancel(); |
145 | - wpinv_set_error( 'cancelled', __( 'This subscription has been cancelled.', 'invoicing' ), 'info' ); |
|
145 | + wpinv_set_error('cancelled', __('This subscription has been cancelled.', 'invoicing'), 'info'); |
|
146 | 146 | } |
147 | 147 | |
148 | - $redirect = remove_query_arg( array( 'getpaid-action', 'getpaid-nonce' ) ); |
|
148 | + $redirect = remove_query_arg(array('getpaid-action', 'getpaid-nonce')); |
|
149 | 149 | |
150 | - wp_safe_redirect( $redirect ); |
|
150 | + wp_safe_redirect($redirect); |
|
151 | 151 | exit; |
152 | 152 | |
153 | 153 | } |
@@ -159,15 +159,15 @@ discard block |
||
159 | 159 | * @param WPInv_Invoice $invoice |
160 | 160 | * @since 1.0.0 |
161 | 161 | */ |
162 | - public function maybe_create_invoice_subscription( $invoice ) { |
|
162 | + public function maybe_create_invoice_subscription($invoice) { |
|
163 | 163 | |
164 | 164 | // Abort if it is not recurring. |
165 | - if ( $invoice->is_free() || ! $invoice->is_recurring() || $invoice->is_renewal() ) { |
|
165 | + if ($invoice->is_free() || !$invoice->is_recurring() || $invoice->is_renewal()) { |
|
166 | 166 | return; |
167 | 167 | } |
168 | 168 | |
169 | 169 | $subscription = new WPInv_Subscription(); |
170 | - return $this->update_invoice_subscription( $subscription, $invoice ); |
|
170 | + return $this->update_invoice_subscription($subscription, $invoice); |
|
171 | 171 | |
172 | 172 | } |
173 | 173 | |
@@ -178,32 +178,32 @@ discard block |
||
178 | 178 | * @param WPInv_Invoice $invoice |
179 | 179 | * @since 1.0.19 |
180 | 180 | */ |
181 | - public function maybe_update_invoice_subscription( $invoice ) { |
|
181 | + public function maybe_update_invoice_subscription($invoice) { |
|
182 | 182 | |
183 | 183 | // Do not process renewals. |
184 | - if ( $invoice->is_renewal() ) { |
|
184 | + if ($invoice->is_renewal()) { |
|
185 | 185 | return; |
186 | 186 | } |
187 | 187 | |
188 | 188 | // Delete existing subscription if available and the invoice is not recurring. |
189 | - if ( ! $invoice->is_recurring() ) { |
|
190 | - $subscription = new WPInv_Subscription( $invoice->get_subscription_id() ); |
|
191 | - $subscription->delete( true ); |
|
189 | + if (!$invoice->is_recurring()) { |
|
190 | + $subscription = new WPInv_Subscription($invoice->get_subscription_id()); |
|
191 | + $subscription->delete(true); |
|
192 | 192 | return; |
193 | 193 | } |
194 | 194 | |
195 | 195 | // (Maybe) create a new subscription. |
196 | - $subscription = $this->get_invoice_subscription( $invoice ); |
|
197 | - if ( empty( $subscription ) ) { |
|
198 | - return $this->maybe_create_invoice_subscription( $invoice ); |
|
196 | + $subscription = $this->get_invoice_subscription($invoice); |
|
197 | + if (empty($subscription)) { |
|
198 | + return $this->maybe_create_invoice_subscription($invoice); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | // Abort if an invoice is paid and already has a subscription. |
202 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
202 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
203 | 203 | return; |
204 | 204 | } |
205 | 205 | |
206 | - return $this->update_invoice_subscription( $subscription, $invoice ); |
|
206 | + return $this->update_invoice_subscription($subscription, $invoice); |
|
207 | 207 | |
208 | 208 | } |
209 | 209 | |
@@ -215,57 +215,57 @@ discard block |
||
215 | 215 | * @param WPInv_Invoice $invoice |
216 | 216 | * @since 1.0.19 |
217 | 217 | */ |
218 | - public function update_invoice_subscription( $subscription, $invoice ) { |
|
218 | + public function update_invoice_subscription($subscription, $invoice) { |
|
219 | 219 | |
220 | 220 | // Delete the subscription if an invoice is free or nolonger recurring. |
221 | - if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_free() || ! $invoice->is_recurring() ) { |
|
221 | + if (!$invoice->is_type('invoice') || $invoice->is_free() || !$invoice->is_recurring()) { |
|
222 | 222 | return $subscription->delete(); |
223 | 223 | } |
224 | 224 | |
225 | - $subscription->set_customer_id( $invoice->get_customer_id() ); |
|
226 | - $subscription->set_parent_invoice_id( $invoice->get_id() ); |
|
227 | - $subscription->set_initial_amount( $invoice->get_initial_total() ); |
|
228 | - $subscription->set_recurring_amount( $invoice->get_recurring_total() ); |
|
229 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
230 | - $subscription->set_status( $invoice->is_paid() ? 'active' : 'pending' ); |
|
225 | + $subscription->set_customer_id($invoice->get_customer_id()); |
|
226 | + $subscription->set_parent_invoice_id($invoice->get_id()); |
|
227 | + $subscription->set_initial_amount($invoice->get_initial_total()); |
|
228 | + $subscription->set_recurring_amount($invoice->get_recurring_total()); |
|
229 | + $subscription->set_date_created(current_time('mysql')); |
|
230 | + $subscription->set_status($invoice->is_paid() ? 'active' : 'pending'); |
|
231 | 231 | |
232 | 232 | // Get the recurring item and abort if it does not exist. |
233 | - $subscription_item = $invoice->get_recurring( true ); |
|
234 | - if ( ! $subscription_item->get_id() ) { |
|
233 | + $subscription_item = $invoice->get_recurring(true); |
|
234 | + if (!$subscription_item->get_id()) { |
|
235 | 235 | $invoice->set_subscription_id(0); |
236 | 236 | $invoice->save(); |
237 | 237 | return $subscription->delete(); |
238 | 238 | } |
239 | 239 | |
240 | - $subscription->set_product_id( $subscription_item->get_id() ); |
|
241 | - $subscription->set_period( $subscription_item->get_recurring_period( true ) ); |
|
242 | - $subscription->set_frequency( $subscription_item->get_recurring_interval() ); |
|
243 | - $subscription->set_bill_times( $subscription_item->get_recurring_limit() ); |
|
240 | + $subscription->set_product_id($subscription_item->get_id()); |
|
241 | + $subscription->set_period($subscription_item->get_recurring_period(true)); |
|
242 | + $subscription->set_frequency($subscription_item->get_recurring_interval()); |
|
243 | + $subscription->set_bill_times($subscription_item->get_recurring_limit()); |
|
244 | 244 | |
245 | 245 | // Calculate the next renewal date. |
246 | - $period = $subscription_item->get_recurring_period( true ); |
|
246 | + $period = $subscription_item->get_recurring_period(true); |
|
247 | 247 | $interval = $subscription_item->get_recurring_interval(); |
248 | 248 | |
249 | 249 | // If the subscription item has a trial period... |
250 | - if ( $subscription_item->has_free_trial() ) { |
|
251 | - $period = $subscription_item->get_trial_period( true ); |
|
250 | + if ($subscription_item->has_free_trial()) { |
|
251 | + $period = $subscription_item->get_trial_period(true); |
|
252 | 252 | $interval = $subscription_item->get_trial_interval(); |
253 | - $subscription->set_trial_period( $interval . ' ' . $period ); |
|
254 | - $subscription->set_status( 'trialling' ); |
|
253 | + $subscription->set_trial_period($interval . ' ' . $period); |
|
254 | + $subscription->set_status('trialling'); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | // If initial amount is free, treat it as a free trial even if the subscription item does not have a free trial. |
258 | - if ( $invoice->has_free_trial() ) { |
|
259 | - $subscription->set_trial_period( $interval . ' ' . $period ); |
|
260 | - $subscription->set_status( 'trialling' ); |
|
258 | + if ($invoice->has_free_trial()) { |
|
259 | + $subscription->set_trial_period($interval . ' ' . $period); |
|
260 | + $subscription->set_status('trialling'); |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | // Calculate the next renewal date. |
264 | - $expiration = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", strtotime( $subscription->get_date_created() ) ) ); |
|
264 | + $expiration = date('Y-m-d H:i:s', strtotime("+$interval $period", strtotime($subscription->get_date_created()))); |
|
265 | 265 | |
266 | - $subscription->set_next_renewal_date( $expiration ); |
|
266 | + $subscription->set_next_renewal_date($expiration); |
|
267 | 267 | $subscription->save(); |
268 | - $invoice->set_subscription_id( $subscription->get_id() ); |
|
268 | + $invoice->set_subscription_id($subscription->get_id()); |
|
269 | 269 | return $subscription->get_id(); |
270 | 270 | |
271 | 271 | } |
@@ -276,27 +276,27 @@ discard block |
||
276 | 276 | * @param array $data |
277 | 277 | * @since 1.0.19 |
278 | 278 | */ |
279 | - public function admin_update_single_subscription( $args ) { |
|
279 | + public function admin_update_single_subscription($args) { |
|
280 | 280 | |
281 | 281 | // Ensure the subscription exists and that a status has been given. |
282 | - if ( empty( $args['subscription_id'] ) ) { |
|
282 | + if (empty($args['subscription_id'])) { |
|
283 | 283 | return; |
284 | 284 | } |
285 | 285 | |
286 | 286 | // Retrieve the subscriptions. |
287 | - $subscription = new WPInv_Subscription( $args['subscription_id'] ); |
|
287 | + $subscription = new WPInv_Subscription($args['subscription_id']); |
|
288 | 288 | |
289 | - if ( $subscription->get_id() ) { |
|
289 | + if ($subscription->get_id()) { |
|
290 | 290 | |
291 | 291 | $subscription->set_props( |
292 | 292 | array( |
293 | - 'status' => isset( $args['subscription_status'] ) ? $args['subscription_status'] : null, |
|
294 | - 'profile_id' => isset( $args['wpinv_subscription_profile_id'] ) ? $args['wpinv_subscription_profile_id'] : null, |
|
293 | + 'status' => isset($args['subscription_status']) ? $args['subscription_status'] : null, |
|
294 | + 'profile_id' => isset($args['wpinv_subscription_profile_id']) ? $args['wpinv_subscription_profile_id'] : null, |
|
295 | 295 | ) |
296 | 296 | ); |
297 | 297 | |
298 | 298 | $subscription->save(); |
299 | - getpaid_admin()->show_info( __( 'Subscription updated', 'invoicing' ) ); |
|
299 | + getpaid_admin()->show_info(__('Subscription updated', 'invoicing')); |
|
300 | 300 | |
301 | 301 | } |
302 | 302 | |
@@ -308,27 +308,27 @@ discard block |
||
308 | 308 | * @param array $data |
309 | 309 | * @since 1.0.19 |
310 | 310 | */ |
311 | - public function admin_renew_single_subscription( $args ) { |
|
311 | + public function admin_renew_single_subscription($args) { |
|
312 | 312 | |
313 | 313 | // Ensure the subscription exists and that a status has been given. |
314 | - if ( empty( $args['id'] ) ) { |
|
314 | + if (empty($args['id'])) { |
|
315 | 315 | return; |
316 | 316 | } |
317 | 317 | |
318 | 318 | // Retrieve the subscriptions. |
319 | - $subscription = new WPInv_Subscription( $args['id'] ); |
|
319 | + $subscription = new WPInv_Subscription($args['id']); |
|
320 | 320 | |
321 | - if ( $subscription->get_id() ) { |
|
321 | + if ($subscription->get_id()) { |
|
322 | 322 | |
323 | - do_action( 'getpaid_admin_renew_subscription', $subscription ); |
|
323 | + do_action('getpaid_admin_renew_subscription', $subscription); |
|
324 | 324 | |
325 | - $args = array( 'transaction_id', $subscription->get_parent_invoice()->generate_key( 'renewal_' ) ); |
|
325 | + $args = array('transaction_id', $subscription->get_parent_invoice()->generate_key('renewal_')); |
|
326 | 326 | |
327 | - if ( ! $subscription->add_payment( $args ) ) { |
|
328 | - getpaid_admin()->show_error( __( 'We are unable to renew this subscription as the parent invoice does not exist.', 'invoicing' ) ); |
|
327 | + if (!$subscription->add_payment($args)) { |
|
328 | + getpaid_admin()->show_error(__('We are unable to renew this subscription as the parent invoice does not exist.', 'invoicing')); |
|
329 | 329 | } else { |
330 | 330 | $subscription->renew(); |
331 | - getpaid_admin()->show_info( __( 'This subscription has been renewed and extended.', 'invoicing' ) ); |
|
331 | + getpaid_admin()->show_info(__('This subscription has been renewed and extended.', 'invoicing')); |
|
332 | 332 | } |
333 | 333 | |
334 | 334 | wp_safe_redirect( |
@@ -351,20 +351,20 @@ discard block |
||
351 | 351 | * @param array $data |
352 | 352 | * @since 1.0.19 |
353 | 353 | */ |
354 | - public function admin_delete_single_subscription( $args ) { |
|
354 | + public function admin_delete_single_subscription($args) { |
|
355 | 355 | |
356 | 356 | // Ensure the subscription exists and that a status has been given. |
357 | - if ( empty( $args['id'] ) ) { |
|
357 | + if (empty($args['id'])) { |
|
358 | 358 | return; |
359 | 359 | } |
360 | 360 | |
361 | 361 | // Retrieve the subscriptions. |
362 | - $subscription = new WPInv_Subscription( $args['id'] ); |
|
362 | + $subscription = new WPInv_Subscription($args['id']); |
|
363 | 363 | |
364 | - if ( $subscription->delete() ) { |
|
365 | - getpaid_admin()->show_info( __( 'This subscription has been deleted.', 'invoicing' ) ); |
|
364 | + if ($subscription->delete()) { |
|
365 | + getpaid_admin()->show_info(__('This subscription has been deleted.', 'invoicing')); |
|
366 | 366 | } else { |
367 | - getpaid_admin()->show_error( __( 'We are unable to delete this subscription. Please try again.', 'invoicing' ) ); |
|
367 | + getpaid_admin()->show_error(__('We are unable to delete this subscription. Please try again.', 'invoicing')); |
|
368 | 368 | } |
369 | 369 | |
370 | 370 | $redirected = wp_safe_redirect( |
@@ -377,7 +377,7 @@ discard block |
||
377 | 377 | ) |
378 | 378 | ); |
379 | 379 | |
380 | - if ( $redirected ) { |
|
380 | + if ($redirected) { |
|
381 | 381 | exit; |
382 | 382 | } |
383 | 383 | |
@@ -390,10 +390,10 @@ discard block |
||
390 | 390 | * @param WPInv_Item $item |
391 | 391 | * @param WPInv_Invoice $invoice |
392 | 392 | */ |
393 | - public function filter_invoice_line_item_actions( $actions, $item, $invoice ) { |
|
393 | + public function filter_invoice_line_item_actions($actions, $item, $invoice) { |
|
394 | 394 | |
395 | 395 | // Fetch item subscription. |
396 | - $args = array( |
|
396 | + $args = array( |
|
397 | 397 | 'invoice_in' => $invoice->is_parent() ? $invoice->get_id() : $invoice->get_parent_id(), |
398 | 398 | 'product_in' => $item->get_id(), |
399 | 399 | 'number' => 1, |
@@ -401,13 +401,13 @@ discard block |
||
401 | 401 | 'fields' => 'id', |
402 | 402 | ); |
403 | 403 | |
404 | - $subscription = new GetPaid_Subscriptions_Query( $args ); |
|
404 | + $subscription = new GetPaid_Subscriptions_Query($args); |
|
405 | 405 | $subscription = $subscription->get_results(); |
406 | 406 | |
407 | 407 | // In case we found a match... |
408 | - if ( ! empty( $subscription ) ) { |
|
409 | - $url = esc_url( add_query_arg( 'subscription', (int) $subscription[0], get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ) ); |
|
410 | - $actions['subscription'] = "<a href='$url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>'; |
|
408 | + if (!empty($subscription)) { |
|
409 | + $url = esc_url(add_query_arg('subscription', (int) $subscription[0], get_permalink((int) wpinv_get_option('invoice_subscription_page')))); |
|
410 | + $actions['subscription'] = "<a href='$url' class='text-decoration-none'>" . __('Manage Subscription', 'invoicing') . '</a>'; |
|
411 | 411 | } |
412 | 412 | |
413 | 413 | return $actions; |