@@ -7,26 +7,26 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | -$label = empty( $label ) ? '' : wp_kses_post( $label ); |
|
13 | -$label_class = sanitize_key( preg_replace( '/[^A-Za-z0-9_-]/', '-', $label ) ); |
|
12 | +$label = empty($label) ? '' : wp_kses_post($label); |
|
13 | +$label_class = sanitize_key(preg_replace('/[^A-Za-z0-9_-]/', '-', $label)); |
|
14 | 14 | |
15 | -if ( ! empty( $required ) ) { |
|
15 | +if (!empty($required)) { |
|
16 | 16 | $label .= "<span class='text-danger'> *</span>"; |
17 | 17 | } |
18 | 18 | |
19 | 19 | aui()->radio( |
20 | 20 | array( |
21 | - 'name' => esc_attr( $id ), |
|
22 | - 'id' => esc_attr( $element_id ), |
|
23 | - 'required' => ! empty( $required ), |
|
21 | + 'name' => esc_attr($id), |
|
22 | + 'id' => esc_attr($element_id), |
|
23 | + 'required' => !empty($required), |
|
24 | 24 | 'label' => $label, |
25 | 25 | 'label_type' => 'vertical', |
26 | 26 | 'class' => 'w-auto', |
27 | 27 | 'inline' => false, |
28 | - 'options' => empty( $options ) ? array() : array_combine( $options, $options ), |
|
29 | - 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
28 | + 'options' => empty($options) ? array() : array_combine($options, $options), |
|
29 | + 'help_text' => empty($description) ? '' : wp_kses_post($description), |
|
30 | 30 | 'class' => $label_class, |
31 | 31 | 'value' => $query_value, |
32 | 32 | ), |
@@ -7,25 +7,25 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | -$label = empty( $label ) ? '' : wp_kses_post( $label ); |
|
13 | -$label_class = sanitize_key( preg_replace( '/[^A-Za-z0-9_-]/', '-', $label ) ); |
|
12 | +$label = empty($label) ? '' : wp_kses_post($label); |
|
13 | +$label_class = sanitize_key(preg_replace('/[^A-Za-z0-9_-]/', '-', $label)); |
|
14 | 14 | |
15 | -if ( ! empty( $required ) ) { |
|
15 | +if (!empty($required)) { |
|
16 | 16 | $label .= "<span class='text-danger'> *</span>"; |
17 | 17 | } |
18 | 18 | |
19 | 19 | aui()->input( |
20 | 20 | array( |
21 | - 'name' => esc_attr( $id ), |
|
22 | - 'id' => esc_attr( $element_id ), |
|
23 | - 'placeholder' => empty( $placeholder ) ? '' : esc_attr( $placeholder ), |
|
24 | - 'required' => ! empty( $required ), |
|
21 | + 'name' => esc_attr($id), |
|
22 | + 'id' => esc_attr($element_id), |
|
23 | + 'placeholder' => empty($placeholder) ? '' : esc_attr($placeholder), |
|
24 | + 'required' => !empty($required), |
|
25 | 25 | 'label' => $label, |
26 | 26 | 'label_type' => 'vertical', |
27 | - 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
28 | - 'class' => esc_attr( $label_class ), |
|
27 | + 'help_text' => empty($description) ? '' : wp_kses_post($description), |
|
28 | + 'class' => esc_attr($label_class), |
|
29 | 29 | 'value' => $query_value, |
30 | 30 | ), |
31 | 31 | true |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
11 | - exit; // Exit if accessed directly |
|
11 | + exit; // Exit if accessed directly |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | /** |
@@ -17,10 +17,10 @@ discard block |
||
17 | 17 | class GetPaid_Meta_Box_Invoice_Payment_Meta { |
18 | 18 | |
19 | 19 | /** |
20 | - * Output the metabox. |
|
21 | - * |
|
22 | - * @param WP_Post $post |
|
23 | - */ |
|
20 | + * Output the metabox. |
|
21 | + * |
|
22 | + * @param WP_Post $post |
|
23 | + */ |
|
24 | 24 | public static function output( $post ) { |
25 | 25 | |
26 | 26 | // Prepare the invoice. |
@@ -42,167 +42,167 @@ discard block |
||
42 | 42 | |
43 | 43 | if ( $invoice->is_draft() ) { |
44 | 44 | |
45 | - // Set gateway. |
|
46 | - aui()->select( |
|
47 | - array( |
|
48 | - 'id' => 'wpinv_gateway', |
|
49 | - 'name' => 'wpinv_gateway', |
|
50 | - 'label' => __( 'Gateway:', 'invoicing' ), |
|
51 | - 'label_type' => 'vertical', |
|
52 | - 'placeholder' => __( 'Select Gateway', 'invoicing' ), |
|
53 | - 'value' => wpinv_get_default_gateway(), |
|
54 | - 'select2' => true, |
|
55 | - 'data-allow-clear' => 'false', |
|
56 | - 'options' => wp_list_pluck( wpinv_get_enabled_payment_gateways( true ), 'admin_label' ), |
|
57 | - ), |
|
58 | - true |
|
59 | - ); |
|
45 | + // Set gateway. |
|
46 | + aui()->select( |
|
47 | + array( |
|
48 | + 'id' => 'wpinv_gateway', |
|
49 | + 'name' => 'wpinv_gateway', |
|
50 | + 'label' => __( 'Gateway:', 'invoicing' ), |
|
51 | + 'label_type' => 'vertical', |
|
52 | + 'placeholder' => __( 'Select Gateway', 'invoicing' ), |
|
53 | + 'value' => wpinv_get_default_gateway(), |
|
54 | + 'select2' => true, |
|
55 | + 'data-allow-clear' => 'false', |
|
56 | + 'options' => wp_list_pluck( wpinv_get_enabled_payment_gateways( true ), 'admin_label' ), |
|
57 | + ), |
|
58 | + true |
|
59 | + ); |
|
60 | 60 | |
61 | 61 | } else { |
62 | 62 | |
63 | - // Invoice key. |
|
64 | - aui()->input( |
|
65 | - array( |
|
66 | - 'type' => 'text', |
|
67 | - 'id' => 'wpinv_key', |
|
68 | - 'name' => 'wpinv_key', |
|
69 | - 'label' => sprintf( |
|
70 | - // translators: %s: Invoice type. |
|
71 | - __( '%s Key:', 'invoicing' ), |
|
72 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
73 | - ), |
|
74 | - 'label_type' => 'vertical', |
|
75 | - 'class' => 'form-control-sm', |
|
76 | - 'value' => $invoice->get_key( 'edit' ), |
|
77 | - 'extra_attributes' => array( |
|
78 | - 'onclick' => 'this.select();', |
|
79 | - 'readonly' => 'true', |
|
80 | - ), |
|
81 | - ), |
|
82 | - true |
|
83 | - ); |
|
84 | - |
|
85 | - // View URL. |
|
86 | - aui()->input( |
|
87 | - array( |
|
88 | - 'type' => 'text', |
|
89 | - 'id' => 'wpinv_view_url', |
|
90 | - 'name' => 'wpinv_view_url', |
|
91 | - 'label' => sprintf( |
|
92 | - // translators: %s: Invoice type. |
|
93 | - __( '%s URL:', 'invoicing' ), |
|
94 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
95 | - ) . ' <a href="' . esc_url_raw( $invoice->get_view_url() ) . '" title="' . __( 'View invoice', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-fw"></i></a>', |
|
96 | - 'label_type' => 'vertical', |
|
97 | - 'class' => 'form-control-sm', |
|
98 | - 'value' => $invoice->get_view_url(), |
|
99 | - 'extra_attributes' => array( |
|
100 | - 'onclick' => 'this.select();', |
|
101 | - 'readonly' => 'true', |
|
102 | - ), |
|
103 | - ), |
|
104 | - true |
|
105 | - ); |
|
106 | - |
|
107 | - // If the invoice is paid... |
|
108 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
109 | - |
|
110 | - // Gateway. |
|
111 | - aui()->input( |
|
112 | - array( |
|
113 | - 'type' => 'text', |
|
114 | - 'id' => 'wpinv_gateway', |
|
115 | - 'name' => '', |
|
116 | - 'label' => __( 'Gateway:', 'invoicing' ), |
|
117 | - 'label_type' => 'vertical', |
|
118 | - 'class' => 'form-control-sm', |
|
119 | - 'value' => wpinv_get_gateway_admin_label( $invoice->get_gateway( 'edit' ) ), |
|
120 | - 'extra_attributes' => array( |
|
121 | - 'onclick' => 'this.select();', |
|
122 | - 'readonly' => 'true', |
|
123 | - ), |
|
124 | - ), |
|
125 | - true |
|
126 | - ); |
|
127 | - |
|
128 | - // Transaction ID. |
|
129 | - $transaction_url = $invoice->get_transaction_url(); |
|
130 | - aui()->input( |
|
131 | - array( |
|
132 | - 'type' => 'text', |
|
133 | - 'id' => 'wpinv_transaction_id', |
|
134 | - 'name' => 'wpinv_transaction_id', |
|
135 | - 'label' => __( 'Transaction ID:', 'invoicing' ) . ( $transaction_url ? ' <a href="' . esc_url( $transaction_url ) . '" title="' . __( 'View details', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-fw"></i></a>' : '' ), |
|
136 | - 'label_type' => 'vertical', |
|
137 | - 'class' => 'form-control-sm', |
|
138 | - 'value' => $invoice->get_transaction_id( 'edit' ), |
|
139 | - 'help_text' => apply_filters( 'wpinv_invoice_transaction_link_' . $invoice->get_gateway( 'edit' ), '', $invoice->get_transaction_id(), $invoice ), |
|
140 | - 'extra_attributes' => array( |
|
141 | - 'onclick' => 'this.select();', |
|
142 | - 'readonly' => 'true', |
|
143 | - ), |
|
144 | - ), |
|
145 | - true |
|
146 | - ); |
|
147 | - |
|
148 | - // Currency. |
|
149 | - aui()->input( |
|
150 | - array( |
|
151 | - 'type' => 'text', |
|
152 | - 'id' => 'wpinv_currency', |
|
153 | - 'name' => 'wpinv_currency', |
|
154 | - 'label' => __( 'Currency:', 'invoicing' ), |
|
155 | - 'label_type' => 'vertical', |
|
156 | - 'class' => 'form-control-sm', |
|
157 | - 'value' => $invoice->get_currency( 'edit' ), |
|
158 | - 'extra_attributes' => array( |
|
159 | - 'onclick' => 'this.select();', |
|
160 | - 'readonly' => 'true', |
|
161 | - ), |
|
162 | - ), |
|
163 | - true |
|
164 | - ); |
|
165 | - |
|
166 | - } else { |
|
167 | - |
|
168 | - if ( 'wpi_invoice' === $invoice->get_post_type() ) { |
|
169 | - |
|
170 | - // Payment URL. |
|
171 | - aui()->input( |
|
172 | - array( |
|
173 | - 'type' => 'text', |
|
174 | - 'id' => 'wpinv_payment_url', |
|
175 | - 'name' => 'wpinv_payment_url', |
|
176 | - 'label' => __( 'Payment URL:', 'invoicing' ), |
|
177 | - 'label_type' => 'vertical', |
|
178 | - 'class' => 'form-control-sm', |
|
179 | - 'value' => $invoice->get_checkout_payment_url(), |
|
180 | - 'extra_attributes' => array( |
|
181 | - 'onclick' => 'this.select();', |
|
182 | - 'readonly' => 'true', |
|
183 | - ), |
|
184 | - ), |
|
185 | - true |
|
186 | - ); |
|
187 | - |
|
188 | - // Set gateway. |
|
189 | - aui()->select( |
|
190 | - array( |
|
191 | - 'id' => 'wpinv_gateway', |
|
192 | - 'name' => 'wpinv_gateway', |
|
193 | - 'label' => __( 'Gateway:', 'invoicing' ), |
|
194 | - 'label_type' => 'vertical', |
|
195 | - 'placeholder' => __( 'Select Gateway', 'invoicing' ), |
|
196 | - 'value' => $invoice->get_gateway( 'edit' ), |
|
197 | - 'select2' => true, |
|
198 | - 'data-allow-clear' => 'false', |
|
199 | - 'options' => wp_list_pluck( wpinv_get_enabled_payment_gateways( true ), 'admin_label' ), |
|
200 | - ), |
|
201 | - true |
|
202 | - ); |
|
203 | - |
|
204 | - } |
|
205 | - } |
|
63 | + // Invoice key. |
|
64 | + aui()->input( |
|
65 | + array( |
|
66 | + 'type' => 'text', |
|
67 | + 'id' => 'wpinv_key', |
|
68 | + 'name' => 'wpinv_key', |
|
69 | + 'label' => sprintf( |
|
70 | + // translators: %s: Invoice type. |
|
71 | + __( '%s Key:', 'invoicing' ), |
|
72 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
73 | + ), |
|
74 | + 'label_type' => 'vertical', |
|
75 | + 'class' => 'form-control-sm', |
|
76 | + 'value' => $invoice->get_key( 'edit' ), |
|
77 | + 'extra_attributes' => array( |
|
78 | + 'onclick' => 'this.select();', |
|
79 | + 'readonly' => 'true', |
|
80 | + ), |
|
81 | + ), |
|
82 | + true |
|
83 | + ); |
|
84 | + |
|
85 | + // View URL. |
|
86 | + aui()->input( |
|
87 | + array( |
|
88 | + 'type' => 'text', |
|
89 | + 'id' => 'wpinv_view_url', |
|
90 | + 'name' => 'wpinv_view_url', |
|
91 | + 'label' => sprintf( |
|
92 | + // translators: %s: Invoice type. |
|
93 | + __( '%s URL:', 'invoicing' ), |
|
94 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
95 | + ) . ' <a href="' . esc_url_raw( $invoice->get_view_url() ) . '" title="' . __( 'View invoice', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-fw"></i></a>', |
|
96 | + 'label_type' => 'vertical', |
|
97 | + 'class' => 'form-control-sm', |
|
98 | + 'value' => $invoice->get_view_url(), |
|
99 | + 'extra_attributes' => array( |
|
100 | + 'onclick' => 'this.select();', |
|
101 | + 'readonly' => 'true', |
|
102 | + ), |
|
103 | + ), |
|
104 | + true |
|
105 | + ); |
|
106 | + |
|
107 | + // If the invoice is paid... |
|
108 | + if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
109 | + |
|
110 | + // Gateway. |
|
111 | + aui()->input( |
|
112 | + array( |
|
113 | + 'type' => 'text', |
|
114 | + 'id' => 'wpinv_gateway', |
|
115 | + 'name' => '', |
|
116 | + 'label' => __( 'Gateway:', 'invoicing' ), |
|
117 | + 'label_type' => 'vertical', |
|
118 | + 'class' => 'form-control-sm', |
|
119 | + 'value' => wpinv_get_gateway_admin_label( $invoice->get_gateway( 'edit' ) ), |
|
120 | + 'extra_attributes' => array( |
|
121 | + 'onclick' => 'this.select();', |
|
122 | + 'readonly' => 'true', |
|
123 | + ), |
|
124 | + ), |
|
125 | + true |
|
126 | + ); |
|
127 | + |
|
128 | + // Transaction ID. |
|
129 | + $transaction_url = $invoice->get_transaction_url(); |
|
130 | + aui()->input( |
|
131 | + array( |
|
132 | + 'type' => 'text', |
|
133 | + 'id' => 'wpinv_transaction_id', |
|
134 | + 'name' => 'wpinv_transaction_id', |
|
135 | + 'label' => __( 'Transaction ID:', 'invoicing' ) . ( $transaction_url ? ' <a href="' . esc_url( $transaction_url ) . '" title="' . __( 'View details', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-fw"></i></a>' : '' ), |
|
136 | + 'label_type' => 'vertical', |
|
137 | + 'class' => 'form-control-sm', |
|
138 | + 'value' => $invoice->get_transaction_id( 'edit' ), |
|
139 | + 'help_text' => apply_filters( 'wpinv_invoice_transaction_link_' . $invoice->get_gateway( 'edit' ), '', $invoice->get_transaction_id(), $invoice ), |
|
140 | + 'extra_attributes' => array( |
|
141 | + 'onclick' => 'this.select();', |
|
142 | + 'readonly' => 'true', |
|
143 | + ), |
|
144 | + ), |
|
145 | + true |
|
146 | + ); |
|
147 | + |
|
148 | + // Currency. |
|
149 | + aui()->input( |
|
150 | + array( |
|
151 | + 'type' => 'text', |
|
152 | + 'id' => 'wpinv_currency', |
|
153 | + 'name' => 'wpinv_currency', |
|
154 | + 'label' => __( 'Currency:', 'invoicing' ), |
|
155 | + 'label_type' => 'vertical', |
|
156 | + 'class' => 'form-control-sm', |
|
157 | + 'value' => $invoice->get_currency( 'edit' ), |
|
158 | + 'extra_attributes' => array( |
|
159 | + 'onclick' => 'this.select();', |
|
160 | + 'readonly' => 'true', |
|
161 | + ), |
|
162 | + ), |
|
163 | + true |
|
164 | + ); |
|
165 | + |
|
166 | + } else { |
|
167 | + |
|
168 | + if ( 'wpi_invoice' === $invoice->get_post_type() ) { |
|
169 | + |
|
170 | + // Payment URL. |
|
171 | + aui()->input( |
|
172 | + array( |
|
173 | + 'type' => 'text', |
|
174 | + 'id' => 'wpinv_payment_url', |
|
175 | + 'name' => 'wpinv_payment_url', |
|
176 | + 'label' => __( 'Payment URL:', 'invoicing' ), |
|
177 | + 'label_type' => 'vertical', |
|
178 | + 'class' => 'form-control-sm', |
|
179 | + 'value' => $invoice->get_checkout_payment_url(), |
|
180 | + 'extra_attributes' => array( |
|
181 | + 'onclick' => 'this.select();', |
|
182 | + 'readonly' => 'true', |
|
183 | + ), |
|
184 | + ), |
|
185 | + true |
|
186 | + ); |
|
187 | + |
|
188 | + // Set gateway. |
|
189 | + aui()->select( |
|
190 | + array( |
|
191 | + 'id' => 'wpinv_gateway', |
|
192 | + 'name' => 'wpinv_gateway', |
|
193 | + 'label' => __( 'Gateway:', 'invoicing' ), |
|
194 | + 'label_type' => 'vertical', |
|
195 | + 'placeholder' => __( 'Select Gateway', 'invoicing' ), |
|
196 | + 'value' => $invoice->get_gateway( 'edit' ), |
|
197 | + 'select2' => true, |
|
198 | + 'data-allow-clear' => 'false', |
|
199 | + 'options' => wp_list_pluck( wpinv_get_enabled_payment_gateways( true ), 'admin_label' ), |
|
200 | + ), |
|
201 | + true |
|
202 | + ); |
|
203 | + |
|
204 | + } |
|
205 | + } |
|
206 | 206 | } |
207 | 207 | ?> |
208 | 208 | </div> |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * |
8 | 8 | */ |
9 | 9 | |
10 | -if ( ! defined( 'ABSPATH' ) ) { |
|
10 | +if (!defined('ABSPATH')) { |
|
11 | 11 | exit; // Exit if accessed directly |
12 | 12 | } |
13 | 13 | |
@@ -21,10 +21,10 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @param WP_Post $post |
23 | 23 | */ |
24 | - public static function output( $post ) { |
|
24 | + public static function output($post) { |
|
25 | 25 | |
26 | 26 | // Prepare the invoice. |
27 | - $invoice = new WPInv_Invoice( $post ); |
|
27 | + $invoice = new WPInv_Invoice($post); |
|
28 | 28 | |
29 | 29 | ?> |
30 | 30 | |
@@ -40,20 +40,20 @@ discard block |
||
40 | 40 | |
41 | 41 | <?php |
42 | 42 | |
43 | - if ( $invoice->is_draft() ) { |
|
43 | + if ($invoice->is_draft()) { |
|
44 | 44 | |
45 | 45 | // Set gateway. |
46 | 46 | aui()->select( |
47 | 47 | array( |
48 | 48 | 'id' => 'wpinv_gateway', |
49 | 49 | 'name' => 'wpinv_gateway', |
50 | - 'label' => __( 'Gateway:', 'invoicing' ), |
|
50 | + 'label' => __('Gateway:', 'invoicing'), |
|
51 | 51 | 'label_type' => 'vertical', |
52 | - 'placeholder' => __( 'Select Gateway', 'invoicing' ), |
|
52 | + 'placeholder' => __('Select Gateway', 'invoicing'), |
|
53 | 53 | 'value' => wpinv_get_default_gateway(), |
54 | 54 | 'select2' => true, |
55 | 55 | 'data-allow-clear' => 'false', |
56 | - 'options' => wp_list_pluck( wpinv_get_enabled_payment_gateways( true ), 'admin_label' ), |
|
56 | + 'options' => wp_list_pluck(wpinv_get_enabled_payment_gateways(true), 'admin_label'), |
|
57 | 57 | ), |
58 | 58 | true |
59 | 59 | ); |
@@ -68,12 +68,12 @@ discard block |
||
68 | 68 | 'name' => 'wpinv_key', |
69 | 69 | 'label' => sprintf( |
70 | 70 | // translators: %s: Invoice type. |
71 | - __( '%s Key:', 'invoicing' ), |
|
72 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
71 | + __('%s Key:', 'invoicing'), |
|
72 | + ucfirst($invoice->get_invoice_quote_type()) |
|
73 | 73 | ), |
74 | 74 | 'label_type' => 'vertical', |
75 | 75 | 'class' => 'form-control-sm', |
76 | - 'value' => $invoice->get_key( 'edit' ), |
|
76 | + 'value' => $invoice->get_key('edit'), |
|
77 | 77 | 'extra_attributes' => array( |
78 | 78 | 'onclick' => 'this.select();', |
79 | 79 | 'readonly' => 'true', |
@@ -90,9 +90,9 @@ discard block |
||
90 | 90 | 'name' => 'wpinv_view_url', |
91 | 91 | 'label' => sprintf( |
92 | 92 | // translators: %s: Invoice type. |
93 | - __( '%s URL:', 'invoicing' ), |
|
94 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
95 | - ) . ' <a href="' . esc_url_raw( $invoice->get_view_url() ) . '" title="' . __( 'View invoice', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-fw"></i></a>', |
|
93 | + __('%s URL:', 'invoicing'), |
|
94 | + ucfirst($invoice->get_invoice_quote_type()) |
|
95 | + ) . ' <a href="' . esc_url_raw($invoice->get_view_url()) . '" title="' . __('View invoice', 'invoicing') . '" target="_blank"><i class="fas fa-external-link-alt fa-fw"></i></a>', |
|
96 | 96 | 'label_type' => 'vertical', |
97 | 97 | 'class' => 'form-control-sm', |
98 | 98 | 'value' => $invoice->get_view_url(), |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | ); |
106 | 106 | |
107 | 107 | // If the invoice is paid... |
108 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
108 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
109 | 109 | |
110 | 110 | // Gateway. |
111 | 111 | aui()->input( |
@@ -113,10 +113,10 @@ discard block |
||
113 | 113 | 'type' => 'text', |
114 | 114 | 'id' => 'wpinv_gateway', |
115 | 115 | 'name' => '', |
116 | - 'label' => __( 'Gateway:', 'invoicing' ), |
|
116 | + 'label' => __('Gateway:', 'invoicing'), |
|
117 | 117 | 'label_type' => 'vertical', |
118 | 118 | 'class' => 'form-control-sm', |
119 | - 'value' => wpinv_get_gateway_admin_label( $invoice->get_gateway( 'edit' ) ), |
|
119 | + 'value' => wpinv_get_gateway_admin_label($invoice->get_gateway('edit')), |
|
120 | 120 | 'extra_attributes' => array( |
121 | 121 | 'onclick' => 'this.select();', |
122 | 122 | 'readonly' => 'true', |
@@ -132,11 +132,11 @@ discard block |
||
132 | 132 | 'type' => 'text', |
133 | 133 | 'id' => 'wpinv_transaction_id', |
134 | 134 | 'name' => 'wpinv_transaction_id', |
135 | - 'label' => __( 'Transaction ID:', 'invoicing' ) . ( $transaction_url ? ' <a href="' . esc_url( $transaction_url ) . '" title="' . __( 'View details', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-fw"></i></a>' : '' ), |
|
135 | + 'label' => __('Transaction ID:', 'invoicing') . ($transaction_url ? ' <a href="' . esc_url($transaction_url) . '" title="' . __('View details', 'invoicing') . '" target="_blank"><i class="fas fa-external-link-alt fa-fw"></i></a>' : ''), |
|
136 | 136 | 'label_type' => 'vertical', |
137 | 137 | 'class' => 'form-control-sm', |
138 | - 'value' => $invoice->get_transaction_id( 'edit' ), |
|
139 | - 'help_text' => apply_filters( 'wpinv_invoice_transaction_link_' . $invoice->get_gateway( 'edit' ), '', $invoice->get_transaction_id(), $invoice ), |
|
138 | + 'value' => $invoice->get_transaction_id('edit'), |
|
139 | + 'help_text' => apply_filters('wpinv_invoice_transaction_link_' . $invoice->get_gateway('edit'), '', $invoice->get_transaction_id(), $invoice), |
|
140 | 140 | 'extra_attributes' => array( |
141 | 141 | 'onclick' => 'this.select();', |
142 | 142 | 'readonly' => 'true', |
@@ -151,10 +151,10 @@ discard block |
||
151 | 151 | 'type' => 'text', |
152 | 152 | 'id' => 'wpinv_currency', |
153 | 153 | 'name' => 'wpinv_currency', |
154 | - 'label' => __( 'Currency:', 'invoicing' ), |
|
154 | + 'label' => __('Currency:', 'invoicing'), |
|
155 | 155 | 'label_type' => 'vertical', |
156 | 156 | 'class' => 'form-control-sm', |
157 | - 'value' => $invoice->get_currency( 'edit' ), |
|
157 | + 'value' => $invoice->get_currency('edit'), |
|
158 | 158 | 'extra_attributes' => array( |
159 | 159 | 'onclick' => 'this.select();', |
160 | 160 | 'readonly' => 'true', |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | |
166 | 166 | } else { |
167 | 167 | |
168 | - if ( 'wpi_invoice' === $invoice->get_post_type() ) { |
|
168 | + if ('wpi_invoice' === $invoice->get_post_type()) { |
|
169 | 169 | |
170 | 170 | // Payment URL. |
171 | 171 | aui()->input( |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | 'type' => 'text', |
174 | 174 | 'id' => 'wpinv_payment_url', |
175 | 175 | 'name' => 'wpinv_payment_url', |
176 | - 'label' => __( 'Payment URL:', 'invoicing' ), |
|
176 | + 'label' => __('Payment URL:', 'invoicing'), |
|
177 | 177 | 'label_type' => 'vertical', |
178 | 178 | 'class' => 'form-control-sm', |
179 | 179 | 'value' => $invoice->get_checkout_payment_url(), |
@@ -190,13 +190,13 @@ discard block |
||
190 | 190 | array( |
191 | 191 | 'id' => 'wpinv_gateway', |
192 | 192 | 'name' => 'wpinv_gateway', |
193 | - 'label' => __( 'Gateway:', 'invoicing' ), |
|
193 | + 'label' => __('Gateway:', 'invoicing'), |
|
194 | 194 | 'label_type' => 'vertical', |
195 | - 'placeholder' => __( 'Select Gateway', 'invoicing' ), |
|
196 | - 'value' => $invoice->get_gateway( 'edit' ), |
|
195 | + 'placeholder' => __('Select Gateway', 'invoicing'), |
|
196 | + 'value' => $invoice->get_gateway('edit'), |
|
197 | 197 | 'select2' => true, |
198 | 198 | 'data-allow-clear' => 'false', |
199 | - 'options' => wp_list_pluck( wpinv_get_enabled_payment_gateways( true ), 'admin_label' ), |
|
199 | + 'options' => wp_list_pluck(wpinv_get_enabled_payment_gateways(true), 'admin_label'), |
|
200 | 200 | ), |
201 | 201 | true |
202 | 202 | ); |
@@ -14,143 +14,143 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class WPInv_Subscriptions_Widget extends WP_Super_Duper { |
16 | 16 | |
17 | - /** |
|
18 | - * Register the widget with WordPress. |
|
19 | - * |
|
20 | - */ |
|
21 | - public function __construct() { |
|
22 | - |
|
23 | - $options = array( |
|
24 | - 'textdomain' => 'invoicing', |
|
25 | - 'block-icon' => 'controls-repeat', |
|
26 | - 'block-category' => 'widgets', |
|
27 | - 'block-keywords' => "['invoicing','subscriptions', 'getpaid']", |
|
28 | - 'class_name' => __CLASS__, |
|
29 | - 'base_id' => 'wpinv_subscriptions', |
|
30 | - 'name' => __( 'GetPaid > Subscriptions', 'invoicing' ), |
|
31 | - 'widget_ops' => array( |
|
32 | - 'classname' => 'getpaid-subscriptions bsui', |
|
33 | - 'description' => esc_html__( "Displays the current user's subscriptions.", 'invoicing' ), |
|
34 | - ), |
|
35 | - 'arguments' => array( |
|
36 | - 'title' => array( |
|
37 | - 'title' => __( 'Widget title', 'invoicing' ), |
|
38 | - 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
39 | - 'type' => 'text', |
|
40 | - 'desc_tip' => true, |
|
41 | - 'default' => '', |
|
42 | - 'advanced' => false, |
|
43 | - ), |
|
44 | - ), |
|
45 | - |
|
46 | - ); |
|
47 | - |
|
48 | - parent::__construct( $options ); |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * Retrieves current user's subscriptions. |
|
53 | - * |
|
54 | - * @return GetPaid_Subscriptions_Query |
|
55 | - */ |
|
56 | - public function get_subscriptions() { |
|
57 | - |
|
58 | - // Prepare license args. |
|
59 | - $args = array( |
|
60 | - 'customer_in' => get_current_user_id(), |
|
61 | - 'paged' => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1, |
|
62 | - ); |
|
63 | - |
|
64 | - return new GetPaid_Subscriptions_Query( $args ); |
|
65 | - |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * The Super block output function. |
|
70 | - * |
|
71 | - * @param array $args |
|
72 | - * @param array $widget_args |
|
73 | - * @param string $content |
|
74 | - * |
|
75 | - * @return mixed|string|bool |
|
76 | - */ |
|
77 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
78 | - |
|
79 | - // Ensure that the user is logged in. |
|
80 | - if ( ! is_user_logged_in() ) { |
|
81 | - |
|
82 | - return aui()->alert( |
|
83 | - array( |
|
84 | - 'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ), |
|
85 | - 'type' => 'error', |
|
86 | - ) |
|
87 | - ); |
|
88 | - |
|
89 | - } |
|
90 | - |
|
91 | - // Are we displaying a single subscription? |
|
92 | - if ( isset( $_GET['subscription'] ) ) { |
|
93 | - return $this->display_single_subscription( intval( $_GET['subscription'] ) ); |
|
94 | - } |
|
95 | - |
|
96 | - // Retrieve the user's subscriptions. |
|
97 | - $subscriptions = $this->get_subscriptions(); |
|
98 | - |
|
99 | - // Start the output buffer. |
|
100 | - ob_start(); |
|
101 | - |
|
102 | - // Backwards compatibility. |
|
103 | - do_action( 'wpinv_before_user_subscriptions' ); |
|
104 | - |
|
105 | - // Display errors and notices. |
|
106 | - wpinv_print_errors(); |
|
107 | - |
|
108 | - do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions ); |
|
109 | - |
|
110 | - // Print the table header. |
|
111 | - $this->print_table_header(); |
|
112 | - |
|
113 | - // Print table body. |
|
114 | - $this->print_table_body( $subscriptions->get_results() ); |
|
115 | - |
|
116 | - // Print table footer. |
|
117 | - $this->print_table_footer(); |
|
118 | - |
|
119 | - // Print the navigation. |
|
120 | - $this->print_navigation( $subscriptions->get_total() ); |
|
121 | - |
|
122 | - // Backwards compatibility. |
|
123 | - do_action( 'wpinv_after_user_subscriptions' ); |
|
124 | - |
|
125 | - // Return the output. |
|
126 | - return ob_get_clean(); |
|
127 | - |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * Retrieves the subscription columns. |
|
132 | - * |
|
133 | - * @return array |
|
134 | - */ |
|
135 | - public function get_subscriptions_table_columns() { |
|
17 | + /** |
|
18 | + * Register the widget with WordPress. |
|
19 | + * |
|
20 | + */ |
|
21 | + public function __construct() { |
|
22 | + |
|
23 | + $options = array( |
|
24 | + 'textdomain' => 'invoicing', |
|
25 | + 'block-icon' => 'controls-repeat', |
|
26 | + 'block-category' => 'widgets', |
|
27 | + 'block-keywords' => "['invoicing','subscriptions', 'getpaid']", |
|
28 | + 'class_name' => __CLASS__, |
|
29 | + 'base_id' => 'wpinv_subscriptions', |
|
30 | + 'name' => __( 'GetPaid > Subscriptions', 'invoicing' ), |
|
31 | + 'widget_ops' => array( |
|
32 | + 'classname' => 'getpaid-subscriptions bsui', |
|
33 | + 'description' => esc_html__( "Displays the current user's subscriptions.", 'invoicing' ), |
|
34 | + ), |
|
35 | + 'arguments' => array( |
|
36 | + 'title' => array( |
|
37 | + 'title' => __( 'Widget title', 'invoicing' ), |
|
38 | + 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
39 | + 'type' => 'text', |
|
40 | + 'desc_tip' => true, |
|
41 | + 'default' => '', |
|
42 | + 'advanced' => false, |
|
43 | + ), |
|
44 | + ), |
|
45 | + |
|
46 | + ); |
|
47 | + |
|
48 | + parent::__construct( $options ); |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * Retrieves current user's subscriptions. |
|
53 | + * |
|
54 | + * @return GetPaid_Subscriptions_Query |
|
55 | + */ |
|
56 | + public function get_subscriptions() { |
|
57 | + |
|
58 | + // Prepare license args. |
|
59 | + $args = array( |
|
60 | + 'customer_in' => get_current_user_id(), |
|
61 | + 'paged' => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1, |
|
62 | + ); |
|
63 | + |
|
64 | + return new GetPaid_Subscriptions_Query( $args ); |
|
65 | + |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * The Super block output function. |
|
70 | + * |
|
71 | + * @param array $args |
|
72 | + * @param array $widget_args |
|
73 | + * @param string $content |
|
74 | + * |
|
75 | + * @return mixed|string|bool |
|
76 | + */ |
|
77 | + public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
78 | + |
|
79 | + // Ensure that the user is logged in. |
|
80 | + if ( ! is_user_logged_in() ) { |
|
81 | + |
|
82 | + return aui()->alert( |
|
83 | + array( |
|
84 | + 'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ), |
|
85 | + 'type' => 'error', |
|
86 | + ) |
|
87 | + ); |
|
88 | + |
|
89 | + } |
|
90 | + |
|
91 | + // Are we displaying a single subscription? |
|
92 | + if ( isset( $_GET['subscription'] ) ) { |
|
93 | + return $this->display_single_subscription( intval( $_GET['subscription'] ) ); |
|
94 | + } |
|
95 | + |
|
96 | + // Retrieve the user's subscriptions. |
|
97 | + $subscriptions = $this->get_subscriptions(); |
|
98 | + |
|
99 | + // Start the output buffer. |
|
100 | + ob_start(); |
|
101 | + |
|
102 | + // Backwards compatibility. |
|
103 | + do_action( 'wpinv_before_user_subscriptions' ); |
|
104 | + |
|
105 | + // Display errors and notices. |
|
106 | + wpinv_print_errors(); |
|
107 | + |
|
108 | + do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions ); |
|
109 | + |
|
110 | + // Print the table header. |
|
111 | + $this->print_table_header(); |
|
112 | + |
|
113 | + // Print table body. |
|
114 | + $this->print_table_body( $subscriptions->get_results() ); |
|
115 | + |
|
116 | + // Print table footer. |
|
117 | + $this->print_table_footer(); |
|
118 | + |
|
119 | + // Print the navigation. |
|
120 | + $this->print_navigation( $subscriptions->get_total() ); |
|
121 | + |
|
122 | + // Backwards compatibility. |
|
123 | + do_action( 'wpinv_after_user_subscriptions' ); |
|
124 | + |
|
125 | + // Return the output. |
|
126 | + return ob_get_clean(); |
|
127 | + |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * Retrieves the subscription columns. |
|
132 | + * |
|
133 | + * @return array |
|
134 | + */ |
|
135 | + public function get_subscriptions_table_columns() { |
|
136 | 136 | |
137 | - $columns = array( |
|
138 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
139 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
140 | - 'renewal-date' => __( 'Next payment', 'invoicing' ), |
|
141 | - 'status' => __( 'Status', 'invoicing' ), |
|
142 | - ); |
|
137 | + $columns = array( |
|
138 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
139 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
140 | + 'renewal-date' => __( 'Next payment', 'invoicing' ), |
|
141 | + 'status' => __( 'Status', 'invoicing' ), |
|
142 | + ); |
|
143 | 143 | |
144 | - return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns ); |
|
145 | - } |
|
144 | + return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns ); |
|
145 | + } |
|
146 | 146 | |
147 | - /** |
|
148 | - * Displays the table header. |
|
149 | - * |
|
150 | - */ |
|
151 | - public function print_table_header() { |
|
147 | + /** |
|
148 | + * Displays the table header. |
|
149 | + * |
|
150 | + */ |
|
151 | + public function print_table_header() { |
|
152 | 152 | |
153 | - ?> |
|
153 | + ?> |
|
154 | 154 | |
155 | 155 | <table class="table table-bordered table-striped"> |
156 | 156 | |
@@ -166,122 +166,122 @@ discard block |
||
166 | 166 | |
167 | 167 | <?php |
168 | 168 | |
169 | - } |
|
169 | + } |
|
170 | 170 | |
171 | - /** |
|
172 | - * Displays the table body. |
|
173 | - * |
|
174 | - * @param WPInv_Subscription[] $subscriptions |
|
175 | - */ |
|
176 | - public function print_table_body( $subscriptions ) { |
|
171 | + /** |
|
172 | + * Displays the table body. |
|
173 | + * |
|
174 | + * @param WPInv_Subscription[] $subscriptions |
|
175 | + */ |
|
176 | + public function print_table_body( $subscriptions ) { |
|
177 | 177 | |
178 | - if ( empty( $subscriptions ) ) { |
|
179 | - $this->print_table_body_no_subscriptions(); |
|
180 | - } else { |
|
181 | - $this->print_table_body_subscriptions( $subscriptions ); |
|
182 | - } |
|
178 | + if ( empty( $subscriptions ) ) { |
|
179 | + $this->print_table_body_no_subscriptions(); |
|
180 | + } else { |
|
181 | + $this->print_table_body_subscriptions( $subscriptions ); |
|
182 | + } |
|
183 | 183 | |
184 | - } |
|
184 | + } |
|
185 | 185 | |
186 | - /** |
|
187 | - * Displays the table body if no subscriptions were found. |
|
188 | - * |
|
189 | - */ |
|
190 | - public function print_table_body_no_subscriptions() { |
|
186 | + /** |
|
187 | + * Displays the table body if no subscriptions were found. |
|
188 | + * |
|
189 | + */ |
|
190 | + public function print_table_body_no_subscriptions() { |
|
191 | 191 | |
192 | - ?> |
|
192 | + ?> |
|
193 | 193 | <tbody> |
194 | 194 | |
195 | 195 | <tr> |
196 | 196 | <td colspan="<?php echo count( $this->get_subscriptions_table_columns() ); ?>"> |
197 | 197 | |
198 | 198 | <?php |
199 | - aui()->alert( |
|
200 | - array( |
|
201 | - 'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ), |
|
202 | - 'type' => 'warning', |
|
203 | - ), |
|
199 | + aui()->alert( |
|
200 | + array( |
|
201 | + 'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ), |
|
202 | + 'type' => 'warning', |
|
203 | + ), |
|
204 | 204 | true |
205 | - ); |
|
206 | - ?> |
|
205 | + ); |
|
206 | + ?> |
|
207 | 207 | |
208 | 208 | </td> |
209 | 209 | </tr> |
210 | 210 | |
211 | 211 | </tbody> |
212 | 212 | <?php |
213 | - } |
|
213 | + } |
|
214 | 214 | |
215 | - /** |
|
216 | - * Displays the table body if subscriptions were found. |
|
217 | - * |
|
218 | - * @param WPInv_Subscription[] $subscriptions |
|
219 | - */ |
|
220 | - public function print_table_body_subscriptions( $subscriptions ) { |
|
215 | + /** |
|
216 | + * Displays the table body if subscriptions were found. |
|
217 | + * |
|
218 | + * @param WPInv_Subscription[] $subscriptions |
|
219 | + */ |
|
220 | + public function print_table_body_subscriptions( $subscriptions ) { |
|
221 | 221 | |
222 | - ?> |
|
222 | + ?> |
|
223 | 223 | <tbody> |
224 | 224 | |
225 | 225 | <?php foreach ( $subscriptions as $subscription ) : ?> |
226 | 226 | <tr class="getpaid-subscriptions-table-row subscription-<?php echo (int) $subscription->get_id(); ?>"> |
227 | 227 | <?php |
228 | - wpinv_get_template( |
|
229 | - 'subscriptions/subscriptions-table-row.php', |
|
230 | - array( |
|
231 | - 'subscription' => $subscription, |
|
232 | - 'widget' => $this, |
|
233 | - ) |
|
234 | - ); |
|
235 | - ?> |
|
228 | + wpinv_get_template( |
|
229 | + 'subscriptions/subscriptions-table-row.php', |
|
230 | + array( |
|
231 | + 'subscription' => $subscription, |
|
232 | + 'widget' => $this, |
|
233 | + ) |
|
234 | + ); |
|
235 | + ?> |
|
236 | 236 | </tr> |
237 | 237 | <?php endforeach; ?> |
238 | 238 | |
239 | 239 | </tbody> |
240 | 240 | <?php |
241 | - } |
|
242 | - |
|
243 | - /** |
|
244 | - * Adds row actions to a column |
|
245 | - * |
|
246 | - * @param string $content column content |
|
247 | - * @param WPInv_Subscription $subscription |
|
248 | - * @since 1.0.0 |
|
249 | - * @return string |
|
250 | - */ |
|
251 | - public function add_row_actions( $content, $subscription ) { |
|
252 | - |
|
253 | - // Prepare row actions. |
|
254 | - $actions = array(); |
|
255 | - |
|
256 | - // View subscription action. |
|
257 | - $view_url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
258 | - $view_url = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), $view_url ) ); |
|
259 | - $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>'; |
|
260 | - |
|
261 | - // Filter the actions. |
|
262 | - $actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription ); |
|
263 | - |
|
264 | - $sanitized = array(); |
|
265 | - foreach ( $actions as $key => $action ) { |
|
266 | - $key = sanitize_html_class( $key ); |
|
267 | - $action = wp_kses_post( $action ); |
|
268 | - $sanitized[] = "<span class='$key'>$action</span>"; |
|
269 | - } |
|
270 | - |
|
271 | - $row_actions = "<small class='form-text getpaid-subscription-item-actions'>"; |
|
272 | - $row_actions .= implode( ' | ', $sanitized ); |
|
273 | - $row_actions .= '</small>'; |
|
274 | - |
|
275 | - return $content . $row_actions; |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * Displays the table footer. |
|
280 | - * |
|
281 | - */ |
|
282 | - public function print_table_footer() { |
|
283 | - |
|
284 | - ?> |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * Adds row actions to a column |
|
245 | + * |
|
246 | + * @param string $content column content |
|
247 | + * @param WPInv_Subscription $subscription |
|
248 | + * @since 1.0.0 |
|
249 | + * @return string |
|
250 | + */ |
|
251 | + public function add_row_actions( $content, $subscription ) { |
|
252 | + |
|
253 | + // Prepare row actions. |
|
254 | + $actions = array(); |
|
255 | + |
|
256 | + // View subscription action. |
|
257 | + $view_url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
258 | + $view_url = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), $view_url ) ); |
|
259 | + $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>'; |
|
260 | + |
|
261 | + // Filter the actions. |
|
262 | + $actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription ); |
|
263 | + |
|
264 | + $sanitized = array(); |
|
265 | + foreach ( $actions as $key => $action ) { |
|
266 | + $key = sanitize_html_class( $key ); |
|
267 | + $action = wp_kses_post( $action ); |
|
268 | + $sanitized[] = "<span class='$key'>$action</span>"; |
|
269 | + } |
|
270 | + |
|
271 | + $row_actions = "<small class='form-text getpaid-subscription-item-actions'>"; |
|
272 | + $row_actions .= implode( ' | ', $sanitized ); |
|
273 | + $row_actions .= '</small>'; |
|
274 | + |
|
275 | + return $content . $row_actions; |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * Displays the table footer. |
|
280 | + * |
|
281 | + */ |
|
282 | + public function print_table_footer() { |
|
283 | + |
|
284 | + ?> |
|
285 | 285 | |
286 | 286 | <tfoot> |
287 | 287 | <tr> |
@@ -296,145 +296,145 @@ discard block |
||
296 | 296 | </table> |
297 | 297 | <?php |
298 | 298 | |
299 | - } |
|
299 | + } |
|
300 | 300 | |
301 | - /** |
|
302 | - * Displays the navigation. |
|
303 | - * |
|
304 | - * @param int $total |
|
305 | - */ |
|
306 | - public function print_navigation( $total ) { |
|
301 | + /** |
|
302 | + * Displays the navigation. |
|
303 | + * |
|
304 | + * @param int $total |
|
305 | + */ |
|
306 | + public function print_navigation( $total ) { |
|
307 | 307 | |
308 | - if ( $total < 1 ) { |
|
308 | + if ( $total < 1 ) { |
|
309 | 309 | |
310 | - // Out-of-bounds, run the query again without LIMIT for total count. |
|
311 | - $args = array( |
|
312 | - 'customer_in' => get_current_user_id(), |
|
313 | - 'fields' => 'id', |
|
314 | - ); |
|
310 | + // Out-of-bounds, run the query again without LIMIT for total count. |
|
311 | + $args = array( |
|
312 | + 'customer_in' => get_current_user_id(), |
|
313 | + 'fields' => 'id', |
|
314 | + ); |
|
315 | 315 | |
316 | - $count_query = new GetPaid_Subscriptions_Query( $args ); |
|
317 | - $total = $count_query->get_total(); |
|
318 | - } |
|
316 | + $count_query = new GetPaid_Subscriptions_Query( $args ); |
|
317 | + $total = $count_query->get_total(); |
|
318 | + } |
|
319 | 319 | |
320 | - // Abort if we do not have pages. |
|
321 | - if ( 2 > $total ) { |
|
322 | - return; |
|
323 | - } |
|
320 | + // Abort if we do not have pages. |
|
321 | + if ( 2 > $total ) { |
|
322 | + return; |
|
323 | + } |
|
324 | 324 | |
325 | - ?> |
|
325 | + ?> |
|
326 | 326 | |
327 | 327 | <div class="getpaid-subscriptions-pagination"> |
328 | 328 | <?php |
329 | - $big = 999999; |
|
330 | - |
|
331 | - echo wp_kses_post( |
|
332 | - getpaid_paginate_links( |
|
333 | - array( |
|
334 | - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
335 | - 'format' => '?paged=%#%', |
|
336 | - 'total' => (int) ceil( $total / 10 ), |
|
337 | - ) |
|
338 | - ) |
|
339 | - ); |
|
340 | - ?> |
|
329 | + $big = 999999; |
|
330 | + |
|
331 | + echo wp_kses_post( |
|
332 | + getpaid_paginate_links( |
|
333 | + array( |
|
334 | + 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
335 | + 'format' => '?paged=%#%', |
|
336 | + 'total' => (int) ceil( $total / 10 ), |
|
337 | + ) |
|
338 | + ) |
|
339 | + ); |
|
340 | + ?> |
|
341 | 341 | </div> |
342 | 342 | |
343 | 343 | <?php |
344 | - } |
|
345 | - |
|
346 | - /** |
|
347 | - * Returns a single subscription's columns. |
|
348 | - * |
|
349 | - * @param WPInv_Subscription $subscription |
|
350 | - * |
|
351 | - * @return array |
|
352 | - */ |
|
353 | - public function get_single_subscription_columns( $subscription ) { |
|
354 | - |
|
355 | - // Prepare subscription detail columns. |
|
356 | - $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_invoice_id(), $subscription->get_id() ); |
|
357 | - $items_count = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] ); |
|
358 | - $fields = apply_filters( |
|
359 | - 'getpaid_single_subscription_details_fields', |
|
360 | - array( |
|
361 | - 'status' => __( 'Status', 'invoicing' ), |
|
362 | - 'initial_amount' => __( 'Initial amount', 'invoicing' ), |
|
363 | - 'recurring_amount' => __( 'Recurring amount', 'invoicing' ), |
|
364 | - 'start_date' => __( 'Start date', 'invoicing' ), |
|
365 | - 'expiry_date' => __( 'Next payment', 'invoicing' ), |
|
366 | - 'payments' => __( 'Payments', 'invoicing' ), |
|
367 | - 'item' => _n( 'Item', 'Items', $items_count, 'invoicing' ), |
|
368 | - ), |
|
369 | - $subscription, |
|
370 | - $items_count |
|
371 | - ); |
|
372 | - |
|
373 | - if ( isset( $fields['expiry_date'] ) ) { |
|
374 | - |
|
375 | - if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) { |
|
376 | - $fields['expiry_date'] = __( 'End date', 'invoicing' ); |
|
377 | - } |
|
378 | - |
|
379 | - if ( 'pending' === $subscription->get_status() ) { |
|
380 | - unset( $fields['expiry_date'] ); |
|
381 | - } |
|
382 | - } |
|
383 | - |
|
384 | - if ( isset( $fields['start_date'] ) && 'pending' === $subscription->get_status() ) { |
|
385 | - unset( $fields['start_date'] ); |
|
386 | - } |
|
387 | - |
|
388 | - if ( $subscription->get_initial_amount() === $subscription->get_recurring_amount() ) { |
|
389 | - unset( $fields['initial_amount'] ); |
|
390 | - } |
|
391 | - |
|
392 | - return $fields; |
|
393 | - } |
|
394 | - |
|
395 | - /** |
|
396 | - * Displays a single subscription. |
|
397 | - * |
|
398 | - * @param string $subscription |
|
399 | - * |
|
400 | - * @return string |
|
401 | - */ |
|
402 | - public function display_single_subscription( $subscription ) { |
|
403 | - |
|
404 | - // Fetch the subscription. |
|
405 | - $subscription = new WPInv_Subscription( (int) $subscription ); |
|
406 | - |
|
407 | - if ( ! $subscription->exists() ) { |
|
408 | - |
|
409 | - return aui()->alert( |
|
410 | - array( |
|
411 | - 'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ), |
|
412 | - 'type' => 'error', |
|
413 | - ) |
|
414 | - ); |
|
415 | - |
|
416 | - } |
|
417 | - |
|
418 | - // Ensure that the user owns this subscription key. |
|
419 | - if ( get_current_user_id() != $subscription->get_customer_id() && ! wpinv_current_user_can_manage_invoicing() ) { |
|
420 | - |
|
421 | - return aui()->alert( |
|
422 | - array( |
|
423 | - 'content' => wp_kses_post( __( 'You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing' ) ), |
|
424 | - 'type' => 'error', |
|
425 | - ) |
|
426 | - ); |
|
427 | - |
|
428 | - } |
|
429 | - |
|
430 | - return wpinv_get_template_html( |
|
431 | - 'subscriptions/subscription-details.php', |
|
432 | - array( |
|
433 | - 'subscription' => $subscription, |
|
434 | - 'widget' => $this, |
|
435 | - ) |
|
436 | - ); |
|
437 | - |
|
438 | - } |
|
344 | + } |
|
345 | + |
|
346 | + /** |
|
347 | + * Returns a single subscription's columns. |
|
348 | + * |
|
349 | + * @param WPInv_Subscription $subscription |
|
350 | + * |
|
351 | + * @return array |
|
352 | + */ |
|
353 | + public function get_single_subscription_columns( $subscription ) { |
|
354 | + |
|
355 | + // Prepare subscription detail columns. |
|
356 | + $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_invoice_id(), $subscription->get_id() ); |
|
357 | + $items_count = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] ); |
|
358 | + $fields = apply_filters( |
|
359 | + 'getpaid_single_subscription_details_fields', |
|
360 | + array( |
|
361 | + 'status' => __( 'Status', 'invoicing' ), |
|
362 | + 'initial_amount' => __( 'Initial amount', 'invoicing' ), |
|
363 | + 'recurring_amount' => __( 'Recurring amount', 'invoicing' ), |
|
364 | + 'start_date' => __( 'Start date', 'invoicing' ), |
|
365 | + 'expiry_date' => __( 'Next payment', 'invoicing' ), |
|
366 | + 'payments' => __( 'Payments', 'invoicing' ), |
|
367 | + 'item' => _n( 'Item', 'Items', $items_count, 'invoicing' ), |
|
368 | + ), |
|
369 | + $subscription, |
|
370 | + $items_count |
|
371 | + ); |
|
372 | + |
|
373 | + if ( isset( $fields['expiry_date'] ) ) { |
|
374 | + |
|
375 | + if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) { |
|
376 | + $fields['expiry_date'] = __( 'End date', 'invoicing' ); |
|
377 | + } |
|
378 | + |
|
379 | + if ( 'pending' === $subscription->get_status() ) { |
|
380 | + unset( $fields['expiry_date'] ); |
|
381 | + } |
|
382 | + } |
|
383 | + |
|
384 | + if ( isset( $fields['start_date'] ) && 'pending' === $subscription->get_status() ) { |
|
385 | + unset( $fields['start_date'] ); |
|
386 | + } |
|
387 | + |
|
388 | + if ( $subscription->get_initial_amount() === $subscription->get_recurring_amount() ) { |
|
389 | + unset( $fields['initial_amount'] ); |
|
390 | + } |
|
391 | + |
|
392 | + return $fields; |
|
393 | + } |
|
394 | + |
|
395 | + /** |
|
396 | + * Displays a single subscription. |
|
397 | + * |
|
398 | + * @param string $subscription |
|
399 | + * |
|
400 | + * @return string |
|
401 | + */ |
|
402 | + public function display_single_subscription( $subscription ) { |
|
403 | + |
|
404 | + // Fetch the subscription. |
|
405 | + $subscription = new WPInv_Subscription( (int) $subscription ); |
|
406 | + |
|
407 | + if ( ! $subscription->exists() ) { |
|
408 | + |
|
409 | + return aui()->alert( |
|
410 | + array( |
|
411 | + 'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ), |
|
412 | + 'type' => 'error', |
|
413 | + ) |
|
414 | + ); |
|
415 | + |
|
416 | + } |
|
417 | + |
|
418 | + // Ensure that the user owns this subscription key. |
|
419 | + if ( get_current_user_id() != $subscription->get_customer_id() && ! wpinv_current_user_can_manage_invoicing() ) { |
|
420 | + |
|
421 | + return aui()->alert( |
|
422 | + array( |
|
423 | + 'content' => wp_kses_post( __( 'You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing' ) ), |
|
424 | + 'type' => 'error', |
|
425 | + ) |
|
426 | + ); |
|
427 | + |
|
428 | + } |
|
429 | + |
|
430 | + return wpinv_get_template_html( |
|
431 | + 'subscriptions/subscription-details.php', |
|
432 | + array( |
|
433 | + 'subscription' => $subscription, |
|
434 | + 'widget' => $this, |
|
435 | + ) |
|
436 | + ); |
|
437 | + |
|
438 | + } |
|
439 | 439 | |
440 | 440 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * @version 1.0.0 |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * Contains the subscriptions widget. |
@@ -27,15 +27,15 @@ discard block |
||
27 | 27 | 'block-keywords' => "['invoicing','subscriptions', 'getpaid']", |
28 | 28 | 'class_name' => __CLASS__, |
29 | 29 | 'base_id' => 'wpinv_subscriptions', |
30 | - 'name' => __( 'GetPaid > Subscriptions', 'invoicing' ), |
|
30 | + 'name' => __('GetPaid > Subscriptions', 'invoicing'), |
|
31 | 31 | 'widget_ops' => array( |
32 | 32 | 'classname' => 'getpaid-subscriptions bsui', |
33 | - 'description' => esc_html__( "Displays the current user's subscriptions.", 'invoicing' ), |
|
33 | + 'description' => esc_html__("Displays the current user's subscriptions.", 'invoicing'), |
|
34 | 34 | ), |
35 | 35 | 'arguments' => array( |
36 | 36 | 'title' => array( |
37 | - 'title' => __( 'Widget title', 'invoicing' ), |
|
38 | - 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
37 | + 'title' => __('Widget title', 'invoicing'), |
|
38 | + 'desc' => __('Enter widget title.', 'invoicing'), |
|
39 | 39 | 'type' => 'text', |
40 | 40 | 'desc_tip' => true, |
41 | 41 | 'default' => '', |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | |
46 | 46 | ); |
47 | 47 | |
48 | - parent::__construct( $options ); |
|
48 | + parent::__construct($options); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
@@ -56,12 +56,12 @@ discard block |
||
56 | 56 | public function get_subscriptions() { |
57 | 57 | |
58 | 58 | // Prepare license args. |
59 | - $args = array( |
|
59 | + $args = array( |
|
60 | 60 | 'customer_in' => get_current_user_id(), |
61 | - 'paged' => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1, |
|
61 | + 'paged' => (get_query_var('paged')) ? absint(get_query_var('paged')) : 1, |
|
62 | 62 | ); |
63 | 63 | |
64 | - return new GetPaid_Subscriptions_Query( $args ); |
|
64 | + return new GetPaid_Subscriptions_Query($args); |
|
65 | 65 | |
66 | 66 | } |
67 | 67 | |
@@ -74,14 +74,14 @@ discard block |
||
74 | 74 | * |
75 | 75 | * @return mixed|string|bool |
76 | 76 | */ |
77 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
77 | + public function output($args = array(), $widget_args = array(), $content = '') { |
|
78 | 78 | |
79 | 79 | // Ensure that the user is logged in. |
80 | - if ( ! is_user_logged_in() ) { |
|
80 | + if (!is_user_logged_in()) { |
|
81 | 81 | |
82 | 82 | return aui()->alert( |
83 | 83 | array( |
84 | - 'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ), |
|
84 | + 'content' => wp_kses_post(__('You need to log-in or create an account to view this section.', 'invoicing')), |
|
85 | 85 | 'type' => 'error', |
86 | 86 | ) |
87 | 87 | ); |
@@ -89,8 +89,8 @@ discard block |
||
89 | 89 | } |
90 | 90 | |
91 | 91 | // Are we displaying a single subscription? |
92 | - if ( isset( $_GET['subscription'] ) ) { |
|
93 | - return $this->display_single_subscription( intval( $_GET['subscription'] ) ); |
|
92 | + if (isset($_GET['subscription'])) { |
|
93 | + return $this->display_single_subscription(intval($_GET['subscription'])); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | // Retrieve the user's subscriptions. |
@@ -100,27 +100,27 @@ discard block |
||
100 | 100 | ob_start(); |
101 | 101 | |
102 | 102 | // Backwards compatibility. |
103 | - do_action( 'wpinv_before_user_subscriptions' ); |
|
103 | + do_action('wpinv_before_user_subscriptions'); |
|
104 | 104 | |
105 | 105 | // Display errors and notices. |
106 | 106 | wpinv_print_errors(); |
107 | 107 | |
108 | - do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions ); |
|
108 | + do_action('getpaid_license_manager_before_subscriptions', $subscriptions); |
|
109 | 109 | |
110 | 110 | // Print the table header. |
111 | 111 | $this->print_table_header(); |
112 | 112 | |
113 | 113 | // Print table body. |
114 | - $this->print_table_body( $subscriptions->get_results() ); |
|
114 | + $this->print_table_body($subscriptions->get_results()); |
|
115 | 115 | |
116 | 116 | // Print table footer. |
117 | 117 | $this->print_table_footer(); |
118 | 118 | |
119 | 119 | // Print the navigation. |
120 | - $this->print_navigation( $subscriptions->get_total() ); |
|
120 | + $this->print_navigation($subscriptions->get_total()); |
|
121 | 121 | |
122 | 122 | // Backwards compatibility. |
123 | - do_action( 'wpinv_after_user_subscriptions' ); |
|
123 | + do_action('wpinv_after_user_subscriptions'); |
|
124 | 124 | |
125 | 125 | // Return the output. |
126 | 126 | return ob_get_clean(); |
@@ -135,13 +135,13 @@ discard block |
||
135 | 135 | public function get_subscriptions_table_columns() { |
136 | 136 | |
137 | 137 | $columns = array( |
138 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
139 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
140 | - 'renewal-date' => __( 'Next payment', 'invoicing' ), |
|
141 | - 'status' => __( 'Status', 'invoicing' ), |
|
138 | + 'subscription' => __('Subscription', 'invoicing'), |
|
139 | + 'amount' => __('Amount', 'invoicing'), |
|
140 | + 'renewal-date' => __('Next payment', 'invoicing'), |
|
141 | + 'status' => __('Status', 'invoicing'), |
|
142 | 142 | ); |
143 | 143 | |
144 | - return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns ); |
|
144 | + return apply_filters('getpaid_frontend_subscriptions_table_columns', $columns); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | /** |
@@ -156,9 +156,9 @@ discard block |
||
156 | 156 | |
157 | 157 | <thead> |
158 | 158 | <tr> |
159 | - <?php foreach ( $this->get_subscriptions_table_columns() as $key => $label ) : ?> |
|
160 | - <th scope="col" class="font-weight-bold getpaid-subscriptions-table-<?php echo esc_attr( $key ); ?>"> |
|
161 | - <?php echo esc_html( $label ); ?> |
|
159 | + <?php foreach ($this->get_subscriptions_table_columns() as $key => $label) : ?> |
|
160 | + <th scope="col" class="font-weight-bold getpaid-subscriptions-table-<?php echo esc_attr($key); ?>"> |
|
161 | + <?php echo esc_html($label); ?> |
|
162 | 162 | </th> |
163 | 163 | <?php endforeach; ?> |
164 | 164 | </tr> |
@@ -173,12 +173,12 @@ discard block |
||
173 | 173 | * |
174 | 174 | * @param WPInv_Subscription[] $subscriptions |
175 | 175 | */ |
176 | - public function print_table_body( $subscriptions ) { |
|
176 | + public function print_table_body($subscriptions) { |
|
177 | 177 | |
178 | - if ( empty( $subscriptions ) ) { |
|
178 | + if (empty($subscriptions)) { |
|
179 | 179 | $this->print_table_body_no_subscriptions(); |
180 | 180 | } else { |
181 | - $this->print_table_body_subscriptions( $subscriptions ); |
|
181 | + $this->print_table_body_subscriptions($subscriptions); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | } |
@@ -193,12 +193,12 @@ discard block |
||
193 | 193 | <tbody> |
194 | 194 | |
195 | 195 | <tr> |
196 | - <td colspan="<?php echo count( $this->get_subscriptions_table_columns() ); ?>"> |
|
196 | + <td colspan="<?php echo count($this->get_subscriptions_table_columns()); ?>"> |
|
197 | 197 | |
198 | 198 | <?php |
199 | 199 | aui()->alert( |
200 | 200 | array( |
201 | - 'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ), |
|
201 | + 'content' => wp_kses_post(__('No subscriptions found.', 'invoicing')), |
|
202 | 202 | 'type' => 'warning', |
203 | 203 | ), |
204 | 204 | true |
@@ -217,12 +217,12 @@ discard block |
||
217 | 217 | * |
218 | 218 | * @param WPInv_Subscription[] $subscriptions |
219 | 219 | */ |
220 | - public function print_table_body_subscriptions( $subscriptions ) { |
|
220 | + public function print_table_body_subscriptions($subscriptions) { |
|
221 | 221 | |
222 | 222 | ?> |
223 | 223 | <tbody> |
224 | 224 | |
225 | - <?php foreach ( $subscriptions as $subscription ) : ?> |
|
225 | + <?php foreach ($subscriptions as $subscription) : ?> |
|
226 | 226 | <tr class="getpaid-subscriptions-table-row subscription-<?php echo (int) $subscription->get_id(); ?>"> |
227 | 227 | <?php |
228 | 228 | wpinv_get_template( |
@@ -248,28 +248,28 @@ discard block |
||
248 | 248 | * @since 1.0.0 |
249 | 249 | * @return string |
250 | 250 | */ |
251 | - public function add_row_actions( $content, $subscription ) { |
|
251 | + public function add_row_actions($content, $subscription) { |
|
252 | 252 | |
253 | 253 | // Prepare row actions. |
254 | 254 | $actions = array(); |
255 | 255 | |
256 | 256 | // View subscription action. |
257 | - $view_url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
258 | - $view_url = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), $view_url ) ); |
|
259 | - $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>'; |
|
257 | + $view_url = getpaid_get_tab_url('gp-subscriptions', get_permalink((int) wpinv_get_option('invoice_subscription_page'))); |
|
258 | + $view_url = esc_url(add_query_arg('subscription', (int) $subscription->get_id(), $view_url)); |
|
259 | + $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __('Manage Subscription', 'invoicing') . '</a>'; |
|
260 | 260 | |
261 | 261 | // Filter the actions. |
262 | - $actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription ); |
|
262 | + $actions = apply_filters('getpaid_subscriptions_table_subscription_actions', $actions, $subscription); |
|
263 | 263 | |
264 | - $sanitized = array(); |
|
265 | - foreach ( $actions as $key => $action ) { |
|
266 | - $key = sanitize_html_class( $key ); |
|
267 | - $action = wp_kses_post( $action ); |
|
264 | + $sanitized = array(); |
|
265 | + foreach ($actions as $key => $action) { |
|
266 | + $key = sanitize_html_class($key); |
|
267 | + $action = wp_kses_post($action); |
|
268 | 268 | $sanitized[] = "<span class='$key'>$action</span>"; |
269 | 269 | } |
270 | 270 | |
271 | 271 | $row_actions = "<small class='form-text getpaid-subscription-item-actions'>"; |
272 | - $row_actions .= implode( ' | ', $sanitized ); |
|
272 | + $row_actions .= implode(' | ', $sanitized); |
|
273 | 273 | $row_actions .= '</small>'; |
274 | 274 | |
275 | 275 | return $content . $row_actions; |
@@ -285,9 +285,9 @@ discard block |
||
285 | 285 | |
286 | 286 | <tfoot> |
287 | 287 | <tr> |
288 | - <?php foreach ( $this->get_subscriptions_table_columns() as $key => $label ) : ?> |
|
289 | - <th class="font-weight-bold getpaid-subscriptions-<?php echo esc_attr( $key ); ?>"> |
|
290 | - <?php echo esc_html( $label ); ?> |
|
288 | + <?php foreach ($this->get_subscriptions_table_columns() as $key => $label) : ?> |
|
289 | + <th class="font-weight-bold getpaid-subscriptions-<?php echo esc_attr($key); ?>"> |
|
290 | + <?php echo esc_html($label); ?> |
|
291 | 291 | </th> |
292 | 292 | <?php endforeach; ?> |
293 | 293 | </tr> |
@@ -303,22 +303,22 @@ discard block |
||
303 | 303 | * |
304 | 304 | * @param int $total |
305 | 305 | */ |
306 | - public function print_navigation( $total ) { |
|
306 | + public function print_navigation($total) { |
|
307 | 307 | |
308 | - if ( $total < 1 ) { |
|
308 | + if ($total < 1) { |
|
309 | 309 | |
310 | 310 | // Out-of-bounds, run the query again without LIMIT for total count. |
311 | - $args = array( |
|
311 | + $args = array( |
|
312 | 312 | 'customer_in' => get_current_user_id(), |
313 | 313 | 'fields' => 'id', |
314 | 314 | ); |
315 | 315 | |
316 | - $count_query = new GetPaid_Subscriptions_Query( $args ); |
|
316 | + $count_query = new GetPaid_Subscriptions_Query($args); |
|
317 | 317 | $total = $count_query->get_total(); |
318 | 318 | } |
319 | 319 | |
320 | 320 | // Abort if we do not have pages. |
321 | - if ( 2 > $total ) { |
|
321 | + if (2 > $total) { |
|
322 | 322 | return; |
323 | 323 | } |
324 | 324 | |
@@ -331,9 +331,9 @@ discard block |
||
331 | 331 | echo wp_kses_post( |
332 | 332 | getpaid_paginate_links( |
333 | 333 | array( |
334 | - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
334 | + 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
335 | 335 | 'format' => '?paged=%#%', |
336 | - 'total' => (int) ceil( $total / 10 ), |
|
336 | + 'total' => (int) ceil($total / 10), |
|
337 | 337 | ) |
338 | 338 | ) |
339 | 339 | ); |
@@ -350,43 +350,43 @@ discard block |
||
350 | 350 | * |
351 | 351 | * @return array |
352 | 352 | */ |
353 | - public function get_single_subscription_columns( $subscription ) { |
|
353 | + public function get_single_subscription_columns($subscription) { |
|
354 | 354 | |
355 | 355 | // Prepare subscription detail columns. |
356 | - $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_invoice_id(), $subscription->get_id() ); |
|
357 | - $items_count = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] ); |
|
356 | + $subscription_group = getpaid_get_invoice_subscription_group($subscription->get_parent_invoice_id(), $subscription->get_id()); |
|
357 | + $items_count = empty($subscription_group) ? 1 : count($subscription_group['items']); |
|
358 | 358 | $fields = apply_filters( |
359 | 359 | 'getpaid_single_subscription_details_fields', |
360 | 360 | array( |
361 | - 'status' => __( 'Status', 'invoicing' ), |
|
362 | - 'initial_amount' => __( 'Initial amount', 'invoicing' ), |
|
363 | - 'recurring_amount' => __( 'Recurring amount', 'invoicing' ), |
|
364 | - 'start_date' => __( 'Start date', 'invoicing' ), |
|
365 | - 'expiry_date' => __( 'Next payment', 'invoicing' ), |
|
366 | - 'payments' => __( 'Payments', 'invoicing' ), |
|
367 | - 'item' => _n( 'Item', 'Items', $items_count, 'invoicing' ), |
|
361 | + 'status' => __('Status', 'invoicing'), |
|
362 | + 'initial_amount' => __('Initial amount', 'invoicing'), |
|
363 | + 'recurring_amount' => __('Recurring amount', 'invoicing'), |
|
364 | + 'start_date' => __('Start date', 'invoicing'), |
|
365 | + 'expiry_date' => __('Next payment', 'invoicing'), |
|
366 | + 'payments' => __('Payments', 'invoicing'), |
|
367 | + 'item' => _n('Item', 'Items', $items_count, 'invoicing'), |
|
368 | 368 | ), |
369 | 369 | $subscription, |
370 | 370 | $items_count |
371 | 371 | ); |
372 | 372 | |
373 | - if ( isset( $fields['expiry_date'] ) ) { |
|
373 | + if (isset($fields['expiry_date'])) { |
|
374 | 374 | |
375 | - if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) { |
|
376 | - $fields['expiry_date'] = __( 'End date', 'invoicing' ); |
|
375 | + if (!$subscription->is_active() || $subscription->is_last_renewal()) { |
|
376 | + $fields['expiry_date'] = __('End date', 'invoicing'); |
|
377 | 377 | } |
378 | 378 | |
379 | - if ( 'pending' === $subscription->get_status() ) { |
|
380 | - unset( $fields['expiry_date'] ); |
|
379 | + if ('pending' === $subscription->get_status()) { |
|
380 | + unset($fields['expiry_date']); |
|
381 | 381 | } |
382 | 382 | } |
383 | 383 | |
384 | - if ( isset( $fields['start_date'] ) && 'pending' === $subscription->get_status() ) { |
|
385 | - unset( $fields['start_date'] ); |
|
384 | + if (isset($fields['start_date']) && 'pending' === $subscription->get_status()) { |
|
385 | + unset($fields['start_date']); |
|
386 | 386 | } |
387 | 387 | |
388 | - if ( $subscription->get_initial_amount() === $subscription->get_recurring_amount() ) { |
|
389 | - unset( $fields['initial_amount'] ); |
|
388 | + if ($subscription->get_initial_amount() === $subscription->get_recurring_amount()) { |
|
389 | + unset($fields['initial_amount']); |
|
390 | 390 | } |
391 | 391 | |
392 | 392 | return $fields; |
@@ -399,16 +399,16 @@ discard block |
||
399 | 399 | * |
400 | 400 | * @return string |
401 | 401 | */ |
402 | - public function display_single_subscription( $subscription ) { |
|
402 | + public function display_single_subscription($subscription) { |
|
403 | 403 | |
404 | 404 | // Fetch the subscription. |
405 | - $subscription = new WPInv_Subscription( (int) $subscription ); |
|
405 | + $subscription = new WPInv_Subscription((int) $subscription); |
|
406 | 406 | |
407 | - if ( ! $subscription->exists() ) { |
|
407 | + if (!$subscription->exists()) { |
|
408 | 408 | |
409 | 409 | return aui()->alert( |
410 | 410 | array( |
411 | - 'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ), |
|
411 | + 'content' => wp_kses_post(__('Subscription not found.', 'invoicing')), |
|
412 | 412 | 'type' => 'error', |
413 | 413 | ) |
414 | 414 | ); |
@@ -416,11 +416,11 @@ discard block |
||
416 | 416 | } |
417 | 417 | |
418 | 418 | // Ensure that the user owns this subscription key. |
419 | - if ( get_current_user_id() != $subscription->get_customer_id() && ! wpinv_current_user_can_manage_invoicing() ) { |
|
419 | + if (get_current_user_id() != $subscription->get_customer_id() && !wpinv_current_user_can_manage_invoicing()) { |
|
420 | 420 | |
421 | 421 | return aui()->alert( |
422 | 422 | array( |
423 | - 'content' => wp_kses_post( __( 'You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing' ) ), |
|
423 | + 'content' => wp_kses_post(__('You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing')), |
|
424 | 424 | 'type' => 'error', |
425 | 425 | ) |
426 | 426 | ); |
@@ -13,17 +13,17 @@ discard block |
||
13 | 13 | class GetPaid_Notification_Email_Sender { |
14 | 14 | |
15 | 15 | /** |
16 | - * Whether or not we should inline CSS into the email. |
|
17 | - */ |
|
18 | - public $inline_css = true; |
|
16 | + * Whether or not we should inline CSS into the email. |
|
17 | + */ |
|
18 | + public $inline_css = true; |
|
19 | 19 | |
20 | 20 | /** |
21 | - * The wp_mail() data. |
|
22 | - */ |
|
21 | + * The wp_mail() data. |
|
22 | + */ |
|
23 | 23 | public $wp_mail_data = null; |
24 | 24 | |
25 | 25 | /** |
26 | - * Sends a new email. |
|
26 | + * Sends a new email. |
|
27 | 27 | * |
28 | 28 | * @param string|array $to The recipients email or an array of recipient emails. |
29 | 29 | * @param string $subject The email's subject. |
@@ -31,49 +31,49 @@ discard block |
||
31 | 31 | * @param array $attachments The email attachments. |
32 | 32 | * |
33 | 33 | * @return bool |
34 | - */ |
|
35 | - public function send( $to, $subject, $email, $attachments = array() ) { |
|
34 | + */ |
|
35 | + public function send( $to, $subject, $email, $attachments = array() ) { |
|
36 | 36 | |
37 | - /* |
|
37 | + /* |
|
38 | 38 | * Allow to filter data on per-email basis. |
39 | 39 | */ |
40 | - $data = apply_filters( |
|
41 | - 'getpaid_email_data', |
|
42 | - array( |
|
43 | - 'to' => array_filter( array_unique( wpinv_parse_list( $to ) ) ), |
|
44 | - 'subject' => htmlspecialchars_decode( wp_strip_all_tags( $subject ), ENT_QUOTES ), |
|
45 | - 'email' => apply_filters( 'wpinv_mail_content', $email ), |
|
46 | - 'headers' => $this->get_headers(), |
|
47 | - 'attachments' => $attachments, |
|
48 | - ), |
|
49 | - $this |
|
50 | - ); |
|
40 | + $data = apply_filters( |
|
41 | + 'getpaid_email_data', |
|
42 | + array( |
|
43 | + 'to' => array_filter( array_unique( wpinv_parse_list( $to ) ) ), |
|
44 | + 'subject' => htmlspecialchars_decode( wp_strip_all_tags( $subject ), ENT_QUOTES ), |
|
45 | + 'email' => apply_filters( 'wpinv_mail_content', $email ), |
|
46 | + 'headers' => $this->get_headers(), |
|
47 | + 'attachments' => $attachments, |
|
48 | + ), |
|
49 | + $this |
|
50 | + ); |
|
51 | 51 | |
52 | 52 | // Remove slashes. |
53 | 53 | $data = (array) wp_unslash( $data ); |
54 | 54 | |
55 | 55 | // Cache it. |
56 | - $this->wp_mail_data = $data; |
|
56 | + $this->wp_mail_data = $data; |
|
57 | 57 | |
58 | - // Attach our own hooks. |
|
59 | - $this->before_sending(); |
|
58 | + // Attach our own hooks. |
|
59 | + $this->before_sending(); |
|
60 | 60 | |
61 | 61 | $result = false; |
62 | 62 | |
63 | 63 | foreach ( $this->wp_mail_data['to'] as $to ) { |
64 | - $result = $this->_send( $to, $data ); |
|
64 | + $result = $this->_send( $to, $data ); |
|
65 | 65 | } |
66 | 66 | |
67 | - // Remove our hooks. |
|
68 | - $this->after_sending(); |
|
67 | + // Remove our hooks. |
|
68 | + $this->after_sending(); |
|
69 | 69 | |
70 | - $this->wp_mail_data = null; |
|
70 | + $this->wp_mail_data = null; |
|
71 | 71 | |
72 | - return $result; |
|
73 | - } |
|
72 | + return $result; |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Does the actual sending. |
|
75 | + /** |
|
76 | + * Does the actual sending. |
|
77 | 77 | * |
78 | 78 | * @param string $to The recipient's email. |
79 | 79 | * @param array $data The email's data. |
@@ -81,81 +81,81 @@ discard block |
||
81 | 81 | * @param array $attachments The email attachments. |
82 | 82 | * |
83 | 83 | * @return bool |
84 | - */ |
|
85 | - protected function _send( $to, $data ) { |
|
86 | - |
|
87 | - // Prepare the sending function. |
|
88 | - $sending_function = apply_filters( 'getpaid_email_email_sending_function', 'wp_mail' ); |
|
89 | - |
|
90 | - // Send the actual email. |
|
91 | - $result = call_user_func( |
|
92 | - $sending_function, |
|
93 | - $to, |
|
94 | - html_entity_decode( $data['subject'], ENT_QUOTES, get_bloginfo( 'charset' ) ), |
|
95 | - $data['email'], |
|
96 | - $data['headers'], |
|
97 | - $data['attachments'] |
|
98 | - ); |
|
99 | - |
|
100 | - if ( ! $result ) { |
|
101 | - $log_message = wp_sprintf( __( "\nTime: %1\$s\nTo: %2\$s\nSubject: %3\$s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), $to, $data['subject'] ); |
|
102 | - wpinv_error_log( $log_message, __( 'Email from Invoicing plugin failed to send', 'invoicing' ), __FILE__, __LINE__ ); |
|
103 | - } |
|
104 | - |
|
105 | - return $result; |
|
106 | - } |
|
84 | + */ |
|
85 | + protected function _send( $to, $data ) { |
|
86 | + |
|
87 | + // Prepare the sending function. |
|
88 | + $sending_function = apply_filters( 'getpaid_email_email_sending_function', 'wp_mail' ); |
|
89 | + |
|
90 | + // Send the actual email. |
|
91 | + $result = call_user_func( |
|
92 | + $sending_function, |
|
93 | + $to, |
|
94 | + html_entity_decode( $data['subject'], ENT_QUOTES, get_bloginfo( 'charset' ) ), |
|
95 | + $data['email'], |
|
96 | + $data['headers'], |
|
97 | + $data['attachments'] |
|
98 | + ); |
|
99 | + |
|
100 | + if ( ! $result ) { |
|
101 | + $log_message = wp_sprintf( __( "\nTime: %1\$s\nTo: %2\$s\nSubject: %3\$s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), $to, $data['subject'] ); |
|
102 | + wpinv_error_log( $log_message, __( 'Email from Invoicing plugin failed to send', 'invoicing' ), __FILE__, __LINE__ ); |
|
103 | + } |
|
104 | + |
|
105 | + return $result; |
|
106 | + } |
|
107 | 107 | |
108 | 108 | /** |
109 | - * Retrieves email headers. |
|
110 | - */ |
|
111 | - public function get_headers() { |
|
109 | + * Retrieves email headers. |
|
110 | + */ |
|
111 | + public function get_headers() { |
|
112 | 112 | |
113 | - $name = $this->get_from_name(); |
|
114 | - $reply_to = $this->get_reply_to(); |
|
115 | - $headers = array( "Reply-To:$name <$reply_to>" ); |
|
113 | + $name = $this->get_from_name(); |
|
114 | + $reply_to = $this->get_reply_to(); |
|
115 | + $headers = array( "Reply-To:$name <$reply_to>" ); |
|
116 | 116 | |
117 | - return apply_filters( 'getpaid_email_headers', $headers, $this ); |
|
117 | + return apply_filters( 'getpaid_email_headers', $headers, $this ); |
|
118 | 118 | |
119 | - } |
|
119 | + } |
|
120 | 120 | |
121 | 121 | /** |
122 | - * Fires before an email is sent |
|
123 | - * |
|
124 | - * @since 1.0.0 |
|
125 | - */ |
|
126 | - public function before_sending() { |
|
122 | + * Fires before an email is sent |
|
123 | + * |
|
124 | + * @since 1.0.0 |
|
125 | + */ |
|
126 | + public function before_sending() { |
|
127 | 127 | |
128 | 128 | do_action( 'getpaid_before_send_email', $this ); |
129 | - add_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
130 | - add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
131 | - add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
132 | - add_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 ); |
|
129 | + add_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
130 | + add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
131 | + add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
132 | + add_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 ); |
|
133 | 133 | |
134 | - } |
|
134 | + } |
|
135 | 135 | |
136 | 136 | /** |
137 | - * Returns the from name. |
|
138 | - */ |
|
139 | - public function get_from_name() { |
|
137 | + * Returns the from name. |
|
138 | + */ |
|
139 | + public function get_from_name() { |
|
140 | 140 | |
141 | 141 | $from_name = wpinv_get_option( 'email_from_name', get_bloginfo( 'name' ) ); |
142 | 142 | |
143 | - if ( empty( $from_name ) ) { |
|
144 | - $from_name = get_bloginfo( 'name' ); |
|
143 | + if ( empty( $from_name ) ) { |
|
144 | + $from_name = get_bloginfo( 'name' ); |
|
145 | 145 | } |
146 | 146 | |
147 | - return wp_specialchars_decode( $from_name, ENT_QUOTES ); |
|
147 | + return wp_specialchars_decode( $from_name, ENT_QUOTES ); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
151 | - * Returns the from email. |
|
152 | - */ |
|
153 | - public function get_from_address() { |
|
151 | + * Returns the from email. |
|
152 | + */ |
|
153 | + public function get_from_address() { |
|
154 | 154 | |
155 | 155 | $from_address = wpinv_get_option( 'email_from', $this->default_from_address() ); |
156 | 156 | |
157 | - if ( ! is_email( $from_address ) ) { |
|
158 | - $from_address = $this->default_from_address(); |
|
157 | + if ( ! is_email( $from_address ) ) { |
|
158 | + $from_address = $this->default_from_address(); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | return $from_address; |
@@ -163,75 +163,75 @@ discard block |
||
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
166 | - * The default emails from address. |
|
167 | - * |
|
168 | - * Defaults to wordpress@$sitename |
|
169 | - * Some hosts will block outgoing mail from this address if it doesn't exist, |
|
170 | - * but there's no easy alternative. Defaulting to admin_email might appear to be |
|
171 | - * another option, but some hosts may refuse to relay mail from an unknown domain. |
|
172 | - * |
|
173 | - */ |
|
174 | - public function default_from_address() { |
|
175 | - |
|
176 | - // Get the site domain and get rid of www. |
|
177 | - $sitename = strtolower( $_SERVER['SERVER_NAME'] ); |
|
178 | - if ( substr( $sitename, 0, 4 ) == 'www.' ) { |
|
179 | - $sitename = substr( $sitename, 4 ); |
|
180 | - } |
|
181 | - |
|
182 | - $from_email = 'wordpress@' . $sitename; |
|
183 | - |
|
184 | - return apply_filters( 'getpaid_default_from_address', $from_email ); |
|
166 | + * The default emails from address. |
|
167 | + * |
|
168 | + * Defaults to wordpress@$sitename |
|
169 | + * Some hosts will block outgoing mail from this address if it doesn't exist, |
|
170 | + * but there's no easy alternative. Defaulting to admin_email might appear to be |
|
171 | + * another option, but some hosts may refuse to relay mail from an unknown domain. |
|
172 | + * |
|
173 | + */ |
|
174 | + public function default_from_address() { |
|
175 | + |
|
176 | + // Get the site domain and get rid of www. |
|
177 | + $sitename = strtolower( $_SERVER['SERVER_NAME'] ); |
|
178 | + if ( substr( $sitename, 0, 4 ) == 'www.' ) { |
|
179 | + $sitename = substr( $sitename, 4 ); |
|
180 | + } |
|
181 | + |
|
182 | + $from_email = 'wordpress@' . $sitename; |
|
183 | + |
|
184 | + return apply_filters( 'getpaid_default_from_address', $from_email ); |
|
185 | 185 | |
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
189 | - * Get the email reply-to. |
|
190 | - * |
|
191 | - * |
|
192 | - * @return string The email reply-to address. |
|
193 | - */ |
|
194 | - public function get_reply_to() { |
|
189 | + * Get the email reply-to. |
|
190 | + * |
|
191 | + * |
|
192 | + * @return string The email reply-to address. |
|
193 | + */ |
|
194 | + public function get_reply_to() { |
|
195 | 195 | |
196 | - $reply_to = current( wpinv_parse_list( wpinv_get_admin_email() ) ); |
|
196 | + $reply_to = current( wpinv_parse_list( wpinv_get_admin_email() ) ); |
|
197 | 197 | |
198 | - if ( ! is_email( $reply_to ) ) { |
|
199 | - $reply_to = get_option( 'admin_email' ); |
|
200 | - } |
|
198 | + if ( ! is_email( $reply_to ) ) { |
|
199 | + $reply_to = get_option( 'admin_email' ); |
|
200 | + } |
|
201 | 201 | |
202 | - return $reply_to; |
|
202 | + return $reply_to; |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | /** |
206 | - * Get the email content type. |
|
207 | - * |
|
208 | - */ |
|
209 | - public function get_content_type() { |
|
210 | - return apply_filters( 'getpaid_email_content_type', 'text/html', $this ); |
|
206 | + * Get the email content type. |
|
207 | + * |
|
208 | + */ |
|
209 | + public function get_content_type() { |
|
210 | + return apply_filters( 'getpaid_email_content_type', 'text/html', $this ); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | /** |
214 | - * Ensures that our email messages are not messed up by template plugins. |
|
215 | - * |
|
216 | - * @return array wp_mail_data. |
|
217 | - */ |
|
218 | - public function ensure_email_content( $args ) { |
|
219 | - $args['message'] = $this->wp_mail_data['email']; |
|
220 | - return $args; |
|
214 | + * Ensures that our email messages are not messed up by template plugins. |
|
215 | + * |
|
216 | + * @return array wp_mail_data. |
|
217 | + */ |
|
218 | + public function ensure_email_content( $args ) { |
|
219 | + $args['message'] = $this->wp_mail_data['email']; |
|
220 | + return $args; |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | /** |
224 | - * A little house keeping after an email is sent. |
|
225 | - * |
|
226 | - */ |
|
227 | - public function after_sending() { |
|
224 | + * A little house keeping after an email is sent. |
|
225 | + * |
|
226 | + */ |
|
227 | + public function after_sending() { |
|
228 | 228 | |
229 | 229 | do_action( 'getpaid_after_send_email', $this->wp_mail_data ); |
230 | - remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
231 | - remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
232 | - remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
233 | - remove_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 ); |
|
230 | + remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
231 | + remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
232 | + remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
233 | + remove_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 ); |
|
234 | 234 | |
235 | - } |
|
235 | + } |
|
236 | 236 | |
237 | 237 | } |
@@ -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 function is responsible for sending emails. |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | * |
33 | 33 | * @return bool |
34 | 34 | */ |
35 | - public function send( $to, $subject, $email, $attachments = array() ) { |
|
35 | + public function send($to, $subject, $email, $attachments = array()) { |
|
36 | 36 | |
37 | 37 | /* |
38 | 38 | * Allow to filter data on per-email basis. |
@@ -40,9 +40,9 @@ discard block |
||
40 | 40 | $data = apply_filters( |
41 | 41 | 'getpaid_email_data', |
42 | 42 | array( |
43 | - 'to' => array_filter( array_unique( wpinv_parse_list( $to ) ) ), |
|
44 | - 'subject' => htmlspecialchars_decode( wp_strip_all_tags( $subject ), ENT_QUOTES ), |
|
45 | - 'email' => apply_filters( 'wpinv_mail_content', $email ), |
|
43 | + 'to' => array_filter(array_unique(wpinv_parse_list($to))), |
|
44 | + 'subject' => htmlspecialchars_decode(wp_strip_all_tags($subject), ENT_QUOTES), |
|
45 | + 'email' => apply_filters('wpinv_mail_content', $email), |
|
46 | 46 | 'headers' => $this->get_headers(), |
47 | 47 | 'attachments' => $attachments, |
48 | 48 | ), |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | ); |
51 | 51 | |
52 | 52 | // Remove slashes. |
53 | - $data = (array) wp_unslash( $data ); |
|
53 | + $data = (array) wp_unslash($data); |
|
54 | 54 | |
55 | 55 | // Cache it. |
56 | 56 | $this->wp_mail_data = $data; |
@@ -60,8 +60,8 @@ discard block |
||
60 | 60 | |
61 | 61 | $result = false; |
62 | 62 | |
63 | - foreach ( $this->wp_mail_data['to'] as $to ) { |
|
64 | - $result = $this->_send( $to, $data ); |
|
63 | + foreach ($this->wp_mail_data['to'] as $to) { |
|
64 | + $result = $this->_send($to, $data); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | // Remove our hooks. |
@@ -82,24 +82,24 @@ discard block |
||
82 | 82 | * |
83 | 83 | * @return bool |
84 | 84 | */ |
85 | - protected function _send( $to, $data ) { |
|
85 | + protected function _send($to, $data) { |
|
86 | 86 | |
87 | 87 | // Prepare the sending function. |
88 | - $sending_function = apply_filters( 'getpaid_email_email_sending_function', 'wp_mail' ); |
|
88 | + $sending_function = apply_filters('getpaid_email_email_sending_function', 'wp_mail'); |
|
89 | 89 | |
90 | 90 | // Send the actual email. |
91 | 91 | $result = call_user_func( |
92 | 92 | $sending_function, |
93 | 93 | $to, |
94 | - html_entity_decode( $data['subject'], ENT_QUOTES, get_bloginfo( 'charset' ) ), |
|
94 | + html_entity_decode($data['subject'], ENT_QUOTES, get_bloginfo('charset')), |
|
95 | 95 | $data['email'], |
96 | 96 | $data['headers'], |
97 | 97 | $data['attachments'] |
98 | 98 | ); |
99 | 99 | |
100 | - if ( ! $result ) { |
|
101 | - $log_message = wp_sprintf( __( "\nTime: %1\$s\nTo: %2\$s\nSubject: %3\$s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), $to, $data['subject'] ); |
|
102 | - wpinv_error_log( $log_message, __( 'Email from Invoicing plugin failed to send', 'invoicing' ), __FILE__, __LINE__ ); |
|
100 | + if (!$result) { |
|
101 | + $log_message = wp_sprintf(__("\nTime: %1\$s\nTo: %2\$s\nSubject: %3\$s\n", 'invoicing'), date_i18n('F j Y H:i:s', current_time('timestamp')), $to, $data['subject']); |
|
102 | + wpinv_error_log($log_message, __('Email from Invoicing plugin failed to send', 'invoicing'), __FILE__, __LINE__); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | return $result; |
@@ -112,9 +112,9 @@ discard block |
||
112 | 112 | |
113 | 113 | $name = $this->get_from_name(); |
114 | 114 | $reply_to = $this->get_reply_to(); |
115 | - $headers = array( "Reply-To:$name <$reply_to>" ); |
|
115 | + $headers = array("Reply-To:$name <$reply_to>"); |
|
116 | 116 | |
117 | - return apply_filters( 'getpaid_email_headers', $headers, $this ); |
|
117 | + return apply_filters('getpaid_email_headers', $headers, $this); |
|
118 | 118 | |
119 | 119 | } |
120 | 120 | |
@@ -125,11 +125,11 @@ discard block |
||
125 | 125 | */ |
126 | 126 | public function before_sending() { |
127 | 127 | |
128 | - do_action( 'getpaid_before_send_email', $this ); |
|
129 | - add_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
130 | - add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
131 | - add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
132 | - add_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 ); |
|
128 | + do_action('getpaid_before_send_email', $this); |
|
129 | + add_filter('wp_mail_from', array($this, 'get_from_address'), 1000); |
|
130 | + add_filter('wp_mail_from_name', array($this, 'get_from_name'), 1000); |
|
131 | + add_filter('wp_mail_content_type', array($this, 'get_content_type'), 1000); |
|
132 | + add_filter('wp_mail', array($this, 'ensure_email_content'), 1000); |
|
133 | 133 | |
134 | 134 | } |
135 | 135 | |
@@ -138,13 +138,13 @@ discard block |
||
138 | 138 | */ |
139 | 139 | public function get_from_name() { |
140 | 140 | |
141 | - $from_name = wpinv_get_option( 'email_from_name', get_bloginfo( 'name' ) ); |
|
141 | + $from_name = wpinv_get_option('email_from_name', get_bloginfo('name')); |
|
142 | 142 | |
143 | - if ( empty( $from_name ) ) { |
|
144 | - $from_name = get_bloginfo( 'name' ); |
|
143 | + if (empty($from_name)) { |
|
144 | + $from_name = get_bloginfo('name'); |
|
145 | 145 | } |
146 | 146 | |
147 | - return wp_specialchars_decode( $from_name, ENT_QUOTES ); |
|
147 | + return wp_specialchars_decode($from_name, ENT_QUOTES); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
@@ -152,9 +152,9 @@ discard block |
||
152 | 152 | */ |
153 | 153 | public function get_from_address() { |
154 | 154 | |
155 | - $from_address = wpinv_get_option( 'email_from', $this->default_from_address() ); |
|
155 | + $from_address = wpinv_get_option('email_from', $this->default_from_address()); |
|
156 | 156 | |
157 | - if ( ! is_email( $from_address ) ) { |
|
157 | + if (!is_email($from_address)) { |
|
158 | 158 | $from_address = $this->default_from_address(); |
159 | 159 | } |
160 | 160 | |
@@ -174,14 +174,14 @@ discard block |
||
174 | 174 | public function default_from_address() { |
175 | 175 | |
176 | 176 | // Get the site domain and get rid of www. |
177 | - $sitename = strtolower( $_SERVER['SERVER_NAME'] ); |
|
178 | - if ( substr( $sitename, 0, 4 ) == 'www.' ) { |
|
179 | - $sitename = substr( $sitename, 4 ); |
|
177 | + $sitename = strtolower($_SERVER['SERVER_NAME']); |
|
178 | + if (substr($sitename, 0, 4) == 'www.') { |
|
179 | + $sitename = substr($sitename, 4); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | $from_email = 'wordpress@' . $sitename; |
183 | 183 | |
184 | - return apply_filters( 'getpaid_default_from_address', $from_email ); |
|
184 | + return apply_filters('getpaid_default_from_address', $from_email); |
|
185 | 185 | |
186 | 186 | } |
187 | 187 | |
@@ -193,10 +193,10 @@ discard block |
||
193 | 193 | */ |
194 | 194 | public function get_reply_to() { |
195 | 195 | |
196 | - $reply_to = current( wpinv_parse_list( wpinv_get_admin_email() ) ); |
|
196 | + $reply_to = current(wpinv_parse_list(wpinv_get_admin_email())); |
|
197 | 197 | |
198 | - if ( ! is_email( $reply_to ) ) { |
|
199 | - $reply_to = get_option( 'admin_email' ); |
|
198 | + if (!is_email($reply_to)) { |
|
199 | + $reply_to = get_option('admin_email'); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | return $reply_to; |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | * |
208 | 208 | */ |
209 | 209 | public function get_content_type() { |
210 | - return apply_filters( 'getpaid_email_content_type', 'text/html', $this ); |
|
210 | + return apply_filters('getpaid_email_content_type', 'text/html', $this); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | /** |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | * |
216 | 216 | * @return array wp_mail_data. |
217 | 217 | */ |
218 | - public function ensure_email_content( $args ) { |
|
218 | + public function ensure_email_content($args) { |
|
219 | 219 | $args['message'] = $this->wp_mail_data['email']; |
220 | 220 | return $args; |
221 | 221 | } |
@@ -226,11 +226,11 @@ discard block |
||
226 | 226 | */ |
227 | 227 | public function after_sending() { |
228 | 228 | |
229 | - do_action( 'getpaid_after_send_email', $this->wp_mail_data ); |
|
230 | - remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
231 | - remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
232 | - remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
233 | - remove_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 ); |
|
229 | + do_action('getpaid_after_send_email', $this->wp_mail_data); |
|
230 | + remove_filter('wp_mail_from', array($this, 'get_from_address'), 1000); |
|
231 | + remove_filter('wp_mail_from_name', array($this, 'get_from_name'), 1000); |
|
232 | + remove_filter('wp_mail_content_type', array($this, 'get_content_type'), 1000); |
|
233 | + remove_filter('wp_mail', array($this, 'ensure_email_content'), 1000); |
|
234 | 234 | |
235 | 235 | } |
236 | 236 |
@@ -17,45 +17,45 @@ discard block |
||
17 | 17 | */ |
18 | 18 | class BP_GetPaid_Component extends BP_Component { |
19 | 19 | |
20 | - /** |
|
21 | - * Start the component setup process. |
|
22 | - * |
|
23 | - * @since 2.1.5 |
|
24 | - */ |
|
25 | - public function __construct() { |
|
26 | - parent::start( |
|
27 | - 'getpaid', |
|
28 | - 'GetPaid', |
|
29 | - buddypress()->plugin_dir, |
|
30 | - array( |
|
31 | - 'adminbar_myaccount_order' => 30, |
|
32 | - ) |
|
33 | - ); |
|
34 | - } |
|
20 | + /** |
|
21 | + * Start the component setup process. |
|
22 | + * |
|
23 | + * @since 2.1.5 |
|
24 | + */ |
|
25 | + public function __construct() { |
|
26 | + parent::start( |
|
27 | + 'getpaid', |
|
28 | + 'GetPaid', |
|
29 | + buddypress()->plugin_dir, |
|
30 | + array( |
|
31 | + 'adminbar_myaccount_order' => 30, |
|
32 | + ) |
|
33 | + ); |
|
34 | + } |
|
35 | 35 | |
36 | 36 | /** |
37 | - * Set up component global variables. |
|
38 | - * |
|
39 | - * @since 2.1.5 |
|
40 | - * |
|
41 | - * |
|
42 | - * @param array $args { |
|
43 | - * All values are optional. |
|
44 | - * @type string $slug The component slug. Used to construct certain URLs, such as 'friends' in |
|
45 | - * http://example.com/members/joe/friends/. Default: the value of $this->id. |
|
46 | - * @type string $root_slug The component root slug. Note that this value is generally unused if the |
|
47 | - * component has a root directory (the slug will be overridden by the |
|
48 | - * post_name of the directory page). Default: the slug of the directory page |
|
49 | - * if one is found, otherwise an empty string. |
|
50 | - * @type bool $has_directory Set to true if the component requires an associated WordPress page. |
|
51 | - * @type callable $notification_callback Optional. The callable function that formats the component's notifications. |
|
52 | - * @type string $search_term Optional. The placeholder text in the component directory search box. Eg, |
|
53 | - * 'Search Groups...'. |
|
54 | - * @type array $global_tables Optional. An array of database table names. |
|
55 | - * @type array $meta_tables Optional. An array of metadata table names. |
|
56 | - * } |
|
57 | - */ |
|
58 | - public function setup_globals( $args = array() ) { |
|
37 | + * Set up component global variables. |
|
38 | + * |
|
39 | + * @since 2.1.5 |
|
40 | + * |
|
41 | + * |
|
42 | + * @param array $args { |
|
43 | + * All values are optional. |
|
44 | + * @type string $slug The component slug. Used to construct certain URLs, such as 'friends' in |
|
45 | + * http://example.com/members/joe/friends/. Default: the value of $this->id. |
|
46 | + * @type string $root_slug The component root slug. Note that this value is generally unused if the |
|
47 | + * component has a root directory (the slug will be overridden by the |
|
48 | + * post_name of the directory page). Default: the slug of the directory page |
|
49 | + * if one is found, otherwise an empty string. |
|
50 | + * @type bool $has_directory Set to true if the component requires an associated WordPress page. |
|
51 | + * @type callable $notification_callback Optional. The callable function that formats the component's notifications. |
|
52 | + * @type string $search_term Optional. The placeholder text in the component directory search box. Eg, |
|
53 | + * 'Search Groups...'. |
|
54 | + * @type array $global_tables Optional. An array of database table names. |
|
55 | + * @type array $meta_tables Optional. An array of metadata table names. |
|
56 | + * } |
|
57 | + */ |
|
58 | + public function setup_globals( $args = array() ) { |
|
59 | 59 | parent::setup_globals( |
60 | 60 | array( |
61 | 61 | 'id' => 'getpaid', |
@@ -64,21 +64,21 @@ discard block |
||
64 | 64 | 'has_directory' => false, |
65 | 65 | ) |
66 | 66 | ); |
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * Set up component navigation. |
|
71 | - * |
|
72 | - * @since 2.1.5 |
|
73 | - * |
|
74 | - * @see BP_Component::setup_nav() for a description of arguments. |
|
75 | - * |
|
76 | - * @param array $main_nav Optional. See BP_Component::setup_nav() for description. |
|
77 | - * @param array $sub_nav Optional. See BP_Component::setup_nav() for description. |
|
78 | - */ |
|
79 | - public function setup_nav( $main_nav = array(), $sub_nav = array() ) { |
|
80 | - |
|
81 | - // Abort if the integration is inactive. |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * Set up component navigation. |
|
71 | + * |
|
72 | + * @since 2.1.5 |
|
73 | + * |
|
74 | + * @see BP_Component::setup_nav() for a description of arguments. |
|
75 | + * |
|
76 | + * @param array $main_nav Optional. See BP_Component::setup_nav() for description. |
|
77 | + * @param array $sub_nav Optional. See BP_Component::setup_nav() for description. |
|
78 | + */ |
|
79 | + public function setup_nav( $main_nav = array(), $sub_nav = array() ) { |
|
80 | + |
|
81 | + // Abort if the integration is inactive. |
|
82 | 82 | if ( ! getpaid_is_buddypress_integration_active() || ! is_user_logged_in() ) { |
83 | 83 | return; |
84 | 84 | } |
@@ -88,25 +88,25 @@ discard block |
||
88 | 88 | return; |
89 | 89 | } |
90 | 90 | |
91 | - // Determine user to use. |
|
92 | - $user_domain = bp_loggedin_user_domain(); |
|
93 | - $slug = 'getpaid'; |
|
94 | - $payments_link = trailingslashit( $user_domain . $slug ); |
|
95 | - |
|
96 | - // Add 'Payments' to the main navigation. |
|
97 | - $main_nav = array( |
|
98 | - 'name' => _x( 'Billing', 'BuddyPress profile payments screen nav', 'invoicing' ), |
|
99 | - 'slug' => $slug, |
|
100 | - 'position' => apply_filters( 'wpinv_bp_nav_position', wpinv_get_option( 'wpinv_menu_position', 91 ), $slug ), |
|
101 | - 'screen_function' => array( $this, 'display_current_tab' ), |
|
102 | - 'default_subnav_slug' => apply_filters( 'getpaid_default_tab', 'gp-edit-address' ), |
|
91 | + // Determine user to use. |
|
92 | + $user_domain = bp_loggedin_user_domain(); |
|
93 | + $slug = 'getpaid'; |
|
94 | + $payments_link = trailingslashit( $user_domain . $slug ); |
|
95 | + |
|
96 | + // Add 'Payments' to the main navigation. |
|
97 | + $main_nav = array( |
|
98 | + 'name' => _x( 'Billing', 'BuddyPress profile payments screen nav', 'invoicing' ), |
|
99 | + 'slug' => $slug, |
|
100 | + 'position' => apply_filters( 'wpinv_bp_nav_position', wpinv_get_option( 'wpinv_menu_position', 91 ), $slug ), |
|
101 | + 'screen_function' => array( $this, 'display_current_tab' ), |
|
102 | + 'default_subnav_slug' => apply_filters( 'getpaid_default_tab', 'gp-edit-address' ), |
|
103 | 103 | 'show_for_displayed_user' => false, |
104 | - 'item_css_id' => $this->id, |
|
105 | - 'parent_url' => $user_domain, |
|
106 | - 'parent_slug' => buddypress()->slug, |
|
107 | - ); |
|
104 | + 'item_css_id' => $this->id, |
|
105 | + 'parent_url' => $user_domain, |
|
106 | + 'parent_slug' => buddypress()->slug, |
|
107 | + ); |
|
108 | 108 | |
109 | - // Add the subnav items to the payments nav item if we are using a theme that supports this. |
|
109 | + // Add the subnav items to the payments nav item if we are using a theme that supports this. |
|
110 | 110 | foreach ( getpaid_get_user_content_tabs() as $_slug => $tab ) { |
111 | 111 | |
112 | 112 | $sub_nav[] = array( |
@@ -116,8 +116,8 @@ discard block |
||
116 | 116 | 'parent_slug' => $slug, |
117 | 117 | 'position' => 10, |
118 | 118 | 'screen_function' => function() use ( $tab ) { |
119 | - $GLOBALS['getpaid_bp_current_tab'] = $tab; |
|
120 | - $this->display_current_tab(); |
|
119 | + $GLOBALS['getpaid_bp_current_tab'] = $tab; |
|
120 | + $this->display_current_tab(); |
|
121 | 121 | }, |
122 | 122 | 'show_for_displayed_user' => false, |
123 | 123 | 'item_css_id' => "getpaid-bp-$_slug", |
@@ -125,27 +125,27 @@ discard block |
||
125 | 125 | |
126 | 126 | } |
127 | 127 | |
128 | - parent::setup_nav( $main_nav, $sub_nav ); |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Set up the component entries in the WordPress Admin Bar. |
|
133 | - * |
|
134 | - * @since 2.1.5 |
|
135 | - * |
|
136 | - * @see BP_Component::setup_nav() for a description of the $wp_admin_nav |
|
137 | - * parameter array. |
|
138 | - * |
|
139 | - * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a |
|
140 | - * description. |
|
141 | - */ |
|
142 | - public function setup_admin_bar( $wp_admin_nav = array() ) { |
|
128 | + parent::setup_nav( $main_nav, $sub_nav ); |
|
129 | + } |
|
143 | 130 | |
144 | - // Menus for logged in user. |
|
145 | - if ( is_user_logged_in() ) { |
|
146 | - |
|
147 | - // Setup the logged in user variables. |
|
148 | - $payments_link = trailingslashit( bp_loggedin_user_domain() . 'getpaid/' ); |
|
131 | + /** |
|
132 | + * Set up the component entries in the WordPress Admin Bar. |
|
133 | + * |
|
134 | + * @since 2.1.5 |
|
135 | + * |
|
136 | + * @see BP_Component::setup_nav() for a description of the $wp_admin_nav |
|
137 | + * parameter array. |
|
138 | + * |
|
139 | + * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a |
|
140 | + * description. |
|
141 | + */ |
|
142 | + public function setup_admin_bar( $wp_admin_nav = array() ) { |
|
143 | + |
|
144 | + // Menus for logged in user. |
|
145 | + if ( is_user_logged_in() ) { |
|
146 | + |
|
147 | + // Setup the logged in user variables. |
|
148 | + $payments_link = trailingslashit( bp_loggedin_user_domain() . 'getpaid/' ); |
|
149 | 149 | |
150 | 150 | // Add the "Payments" sub menu. |
151 | 151 | $wp_admin_nav[] = array( |
@@ -168,48 +168,48 @@ discard block |
||
168 | 168 | } |
169 | 169 | } |
170 | 170 | |
171 | - parent::setup_admin_bar( $wp_admin_nav ); |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * Retrieves the current tab. |
|
176 | - * |
|
177 | - * @since 2.1.5 |
|
178 | - */ |
|
179 | - public function get_current_tab() { |
|
180 | - global $getpaid_bp_current_tab; |
|
181 | - |
|
182 | - if ( empty( $getpaid_bp_current_tab ) ) { |
|
183 | - return array( |
|
184 | - 'label' => __( 'Invoices', 'invoicing' ), |
|
185 | - 'content' => '[wpinv_history]', |
|
186 | - 'icon' => 'fas fa-file-invoice', |
|
187 | - ); |
|
188 | - } |
|
189 | - |
|
190 | - return $getpaid_bp_current_tab; |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * Displays the current tab. |
|
195 | - * |
|
196 | - * @since 2.1.5 |
|
197 | - */ |
|
198 | - public function display_current_tab() { |
|
199 | - |
|
200 | - add_action( 'bp_template_content', array( $this, 'handle_display_current_tab' ) ); |
|
201 | - $template = apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ); |
|
171 | + parent::setup_admin_bar( $wp_admin_nav ); |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * Retrieves the current tab. |
|
176 | + * |
|
177 | + * @since 2.1.5 |
|
178 | + */ |
|
179 | + public function get_current_tab() { |
|
180 | + global $getpaid_bp_current_tab; |
|
181 | + |
|
182 | + if ( empty( $getpaid_bp_current_tab ) ) { |
|
183 | + return array( |
|
184 | + 'label' => __( 'Invoices', 'invoicing' ), |
|
185 | + 'content' => '[wpinv_history]', |
|
186 | + 'icon' => 'fas fa-file-invoice', |
|
187 | + ); |
|
188 | + } |
|
189 | + |
|
190 | + return $getpaid_bp_current_tab; |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * Displays the current tab. |
|
195 | + * |
|
196 | + * @since 2.1.5 |
|
197 | + */ |
|
198 | + public function display_current_tab() { |
|
199 | + |
|
200 | + add_action( 'bp_template_content', array( $this, 'handle_display_current_tab' ) ); |
|
201 | + $template = apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ); |
|
202 | 202 | |
203 | 203 | bp_core_load_template( apply_filters( 'wpinv_bp_core_template_plugin', $template ) ); |
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * Handles the actual display of the current tab. |
|
208 | - * |
|
209 | - * @since 2.1.5 |
|
210 | - */ |
|
211 | - public function handle_display_current_tab() { |
|
212 | - echo getpaid_prepare_user_content_tab( $this->get_current_tab() ); |
|
213 | - } |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * Handles the actual display of the current tab. |
|
208 | + * |
|
209 | + * @since 2.1.5 |
|
210 | + */ |
|
211 | + public function handle_display_current_tab() { |
|
212 | + echo getpaid_prepare_user_content_tab( $this->get_current_tab() ); |
|
213 | + } |
|
214 | 214 | |
215 | 215 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | // Exit if accessed directly. |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * Main GetPaid Class. |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * @type array $meta_tables Optional. An array of metadata table names. |
56 | 56 | * } |
57 | 57 | */ |
58 | - public function setup_globals( $args = array() ) { |
|
58 | + public function setup_globals($args = array()) { |
|
59 | 59 | parent::setup_globals( |
60 | 60 | array( |
61 | 61 | 'id' => 'getpaid', |
@@ -76,30 +76,30 @@ discard block |
||
76 | 76 | * @param array $main_nav Optional. See BP_Component::setup_nav() for description. |
77 | 77 | * @param array $sub_nav Optional. See BP_Component::setup_nav() for description. |
78 | 78 | */ |
79 | - public function setup_nav( $main_nav = array(), $sub_nav = array() ) { |
|
79 | + public function setup_nav($main_nav = array(), $sub_nav = array()) { |
|
80 | 80 | |
81 | 81 | // Abort if the integration is inactive. |
82 | - if ( ! getpaid_is_buddypress_integration_active() || ! is_user_logged_in() ) { |
|
82 | + if (!getpaid_is_buddypress_integration_active() || !is_user_logged_in()) { |
|
83 | 83 | return; |
84 | 84 | } |
85 | 85 | |
86 | 86 | // Or a user is not viewing their profile. |
87 | - if ( bp_displayed_user_id() !== bp_loggedin_user_id() ) { |
|
87 | + if (bp_displayed_user_id() !== bp_loggedin_user_id()) { |
|
88 | 88 | return; |
89 | 89 | } |
90 | 90 | |
91 | 91 | // Determine user to use. |
92 | 92 | $user_domain = bp_loggedin_user_domain(); |
93 | 93 | $slug = 'getpaid'; |
94 | - $payments_link = trailingslashit( $user_domain . $slug ); |
|
94 | + $payments_link = trailingslashit($user_domain . $slug); |
|
95 | 95 | |
96 | 96 | // Add 'Payments' to the main navigation. |
97 | 97 | $main_nav = array( |
98 | - 'name' => _x( 'Billing', 'BuddyPress profile payments screen nav', 'invoicing' ), |
|
98 | + 'name' => _x('Billing', 'BuddyPress profile payments screen nav', 'invoicing'), |
|
99 | 99 | 'slug' => $slug, |
100 | - 'position' => apply_filters( 'wpinv_bp_nav_position', wpinv_get_option( 'wpinv_menu_position', 91 ), $slug ), |
|
101 | - 'screen_function' => array( $this, 'display_current_tab' ), |
|
102 | - 'default_subnav_slug' => apply_filters( 'getpaid_default_tab', 'gp-edit-address' ), |
|
100 | + 'position' => apply_filters('wpinv_bp_nav_position', wpinv_get_option('wpinv_menu_position', 91), $slug), |
|
101 | + 'screen_function' => array($this, 'display_current_tab'), |
|
102 | + 'default_subnav_slug' => apply_filters('getpaid_default_tab', 'gp-edit-address'), |
|
103 | 103 | 'show_for_displayed_user' => false, |
104 | 104 | 'item_css_id' => $this->id, |
105 | 105 | 'parent_url' => $user_domain, |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | ); |
108 | 108 | |
109 | 109 | // Add the subnav items to the payments nav item if we are using a theme that supports this. |
110 | - foreach ( getpaid_get_user_content_tabs() as $_slug => $tab ) { |
|
110 | + foreach (getpaid_get_user_content_tabs() as $_slug => $tab) { |
|
111 | 111 | |
112 | 112 | $sub_nav[] = array( |
113 | 113 | 'name' => $tab['label'], |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | 'parent_url' => $payments_link, |
116 | 116 | 'parent_slug' => $slug, |
117 | 117 | 'position' => 10, |
118 | - 'screen_function' => function() use ( $tab ) { |
|
118 | + 'screen_function' => function() use ($tab) { |
|
119 | 119 | $GLOBALS['getpaid_bp_current_tab'] = $tab; |
120 | 120 | $this->display_current_tab(); |
121 | 121 | }, |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | |
126 | 126 | } |
127 | 127 | |
128 | - parent::setup_nav( $main_nav, $sub_nav ); |
|
128 | + parent::setup_nav($main_nav, $sub_nav); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -139,36 +139,36 @@ discard block |
||
139 | 139 | * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a |
140 | 140 | * description. |
141 | 141 | */ |
142 | - public function setup_admin_bar( $wp_admin_nav = array() ) { |
|
142 | + public function setup_admin_bar($wp_admin_nav = array()) { |
|
143 | 143 | |
144 | 144 | // Menus for logged in user. |
145 | - if ( is_user_logged_in() ) { |
|
145 | + if (is_user_logged_in()) { |
|
146 | 146 | |
147 | 147 | // Setup the logged in user variables. |
148 | - $payments_link = trailingslashit( bp_loggedin_user_domain() . 'getpaid/' ); |
|
148 | + $payments_link = trailingslashit(bp_loggedin_user_domain() . 'getpaid/'); |
|
149 | 149 | |
150 | 150 | // Add the "Payments" sub menu. |
151 | 151 | $wp_admin_nav[] = array( |
152 | 152 | 'parent' => buddypress()->my_account_menu_id, |
153 | 153 | 'id' => 'my-account-getpaid', |
154 | - 'title' => _x( 'Billing', 'BuddyPress my account payments sub nav', 'invoicing' ), |
|
155 | - 'href' => $payments_link . apply_filters( 'getpaid_default_tab', 'gp-edit-address' ), |
|
154 | + 'title' => _x('Billing', 'BuddyPress my account payments sub nav', 'invoicing'), |
|
155 | + 'href' => $payments_link . apply_filters('getpaid_default_tab', 'gp-edit-address'), |
|
156 | 156 | ); |
157 | 157 | |
158 | - foreach ( getpaid_get_user_content_tabs() as $slug => $tab ) { |
|
158 | + foreach (getpaid_get_user_content_tabs() as $slug => $tab) { |
|
159 | 159 | |
160 | 160 | $wp_admin_nav[] = array( |
161 | 161 | 'parent' => 'my-account-getpaid', |
162 | 162 | 'id' => 'my-account-getpaid' . $slug, |
163 | 163 | 'title' => $tab['label'], |
164 | - 'href' => trailingslashit( $payments_link . $slug ), |
|
164 | + 'href' => trailingslashit($payments_link . $slug), |
|
165 | 165 | 'position' => 20, |
166 | 166 | ); |
167 | 167 | |
168 | 168 | } |
169 | 169 | } |
170 | 170 | |
171 | - parent::setup_admin_bar( $wp_admin_nav ); |
|
171 | + parent::setup_admin_bar($wp_admin_nav); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
@@ -179,9 +179,9 @@ discard block |
||
179 | 179 | public function get_current_tab() { |
180 | 180 | global $getpaid_bp_current_tab; |
181 | 181 | |
182 | - if ( empty( $getpaid_bp_current_tab ) ) { |
|
182 | + if (empty($getpaid_bp_current_tab)) { |
|
183 | 183 | return array( |
184 | - 'label' => __( 'Invoices', 'invoicing' ), |
|
184 | + 'label' => __('Invoices', 'invoicing'), |
|
185 | 185 | 'content' => '[wpinv_history]', |
186 | 186 | 'icon' => 'fas fa-file-invoice', |
187 | 187 | ); |
@@ -197,10 +197,10 @@ discard block |
||
197 | 197 | */ |
198 | 198 | public function display_current_tab() { |
199 | 199 | |
200 | - add_action( 'bp_template_content', array( $this, 'handle_display_current_tab' ) ); |
|
201 | - $template = apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ); |
|
200 | + add_action('bp_template_content', array($this, 'handle_display_current_tab')); |
|
201 | + $template = apply_filters('bp_core_template_plugin', 'members/single/plugins'); |
|
202 | 202 | |
203 | - bp_core_load_template( apply_filters( 'wpinv_bp_core_template_plugin', $template ) ); |
|
203 | + bp_core_load_template(apply_filters('wpinv_bp_core_template_plugin', $template)); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | * @since 2.1.5 |
210 | 210 | */ |
211 | 211 | public function handle_display_current_tab() { |
212 | - echo getpaid_prepare_user_content_tab( $this->get_current_tab() ); |
|
212 | + echo getpaid_prepare_user_content_tab($this->get_current_tab()); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | } |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | if ( $args['size'] == 'lg' || $args['size'] == 'large' ) { |
96 | 96 | $size = 'lg'; |
97 | 97 | $args['class'] .= ' form-control-lg'; |
98 | - }elseif ( $args['size'] == 'sm' || $args['size'] == 'small' ) { |
|
98 | + } elseif ( $args['size'] == 'sm' || $args['size'] == 'small' ) { |
|
99 | 99 | $size = 'sm'; |
100 | 100 | $args['class'] .= ' form-control-sm'; |
101 | 101 | } |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | $help_text = ''; |
237 | 237 | //$label_args['class'] .= ' d-inline '; |
238 | 238 | $args['wrap_class'] .= ' align-items-center '; |
239 | - }else{ |
|
239 | + } else{ |
|
240 | 240 | |
241 | 241 | } |
242 | 242 |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if ( ! defined( 'ABSPATH' ) ) { |
4 | - exit; // Exit if accessed directly |
|
4 | + exit; // Exit if accessed directly |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -11,1233 +11,1233 @@ discard block |
||
11 | 11 | */ |
12 | 12 | class AUI_Component_Input { |
13 | 13 | |
14 | - /** |
|
15 | - * Build the component. |
|
16 | - * |
|
17 | - * @param array $args |
|
18 | - * |
|
19 | - * @return string The rendered component. |
|
20 | - */ |
|
21 | - public static function input( $args = array() ) { |
|
22 | - $defaults = array( |
|
23 | - 'type' => 'text', |
|
24 | - 'name' => '', |
|
25 | - 'class' => '', |
|
26 | - 'wrap_class' => '', |
|
27 | - 'id' => '', |
|
28 | - 'placeholder' => '', |
|
29 | - 'title' => '', |
|
30 | - 'value' => '', |
|
31 | - 'required' => false, |
|
32 | - 'size' => '', // sm, lg, small, large |
|
33 | - 'clear_icon' => '', // true will show a clear icon, can't be used with input_group_right |
|
34 | - 'label' => '', |
|
35 | - 'label_after' => false, |
|
36 | - 'label_class' => '', |
|
37 | - 'label_col' => '2', |
|
38 | - 'label_type' => '', // top, horizontal, empty = hidden |
|
39 | - 'label_force_left' => false, // used to force checkbox label left when using horizontal |
|
40 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
41 | - 'help_text' => '', |
|
42 | - 'validation_text' => '', |
|
43 | - 'validation_pattern' => '', |
|
44 | - 'no_wrap' => false, |
|
45 | - 'input_group_right' => '', |
|
46 | - 'input_group_left' => '', |
|
47 | - 'input_group_right_inside' => false, |
|
48 | - // forces the input group inside the input |
|
49 | - 'input_group_left_inside' => false, |
|
50 | - // forces the input group inside the input |
|
51 | - 'step' => '', |
|
52 | - 'switch' => false, |
|
53 | - // to show checkbox as a switch |
|
54 | - 'checked' => false, |
|
55 | - // set a checkbox or radio as selected |
|
56 | - 'password_toggle' => true, |
|
57 | - // toggle view/hide password |
|
58 | - 'element_require' => '', |
|
59 | - // [%element_id%] == "1" |
|
60 | - 'extra_attributes' => array(), |
|
61 | - // an array of extra attributes |
|
62 | - 'wrap_attributes' => array() |
|
63 | - ); |
|
64 | - |
|
65 | - /** |
|
66 | - * Parse incoming $args into an array and merge it with $defaults |
|
67 | - */ |
|
68 | - $args = wp_parse_args( $args, $defaults ); |
|
69 | - $output = ''; |
|
70 | - if ( ! empty( $args['type'] ) ) { |
|
71 | - // hidden label option needs to be empty |
|
72 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
73 | - |
|
74 | - $type = sanitize_html_class( $args['type'] ); |
|
75 | - |
|
76 | - $help_text = ''; |
|
77 | - $label = ''; |
|
78 | - $label_after = $args['label_after']; |
|
79 | - $label_args = array( |
|
80 | - 'title' => $args['label'], |
|
81 | - 'for' => $args['id'], |
|
82 | - 'class' => $args['label_class'] . " ", |
|
83 | - 'label_type' => $args['label_type'], |
|
84 | - 'label_col' => $args['label_col'] |
|
85 | - ); |
|
86 | - |
|
87 | - // floating labels need label after |
|
88 | - if ( $args['label_type'] == 'floating' && $type != 'checkbox' ) { |
|
89 | - $label_after = true; |
|
90 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
91 | - } |
|
92 | - |
|
93 | - // size |
|
94 | - $size = ''; |
|
95 | - if ( $args['size'] == 'lg' || $args['size'] == 'large' ) { |
|
96 | - $size = 'lg'; |
|
97 | - $args['class'] .= ' form-control-lg'; |
|
98 | - }elseif ( $args['size'] == 'sm' || $args['size'] == 'small' ) { |
|
99 | - $size = 'sm'; |
|
100 | - $args['class'] .= ' form-control-sm'; |
|
101 | - } |
|
102 | - |
|
103 | - // clear function |
|
104 | - $clear_function = 'jQuery(this).parent().parent().find(\'input\').val(\'\');'; |
|
105 | - |
|
106 | - // Some special sauce for files |
|
107 | - if ( $type == 'file' ) { |
|
108 | - $label_after = true; // if type file we need the label after |
|
109 | - $args['class'] .= ' custom-file-input '; |
|
110 | - } elseif ( $type == 'checkbox' ) { |
|
111 | - $label_after = true; // if type file we need the label after |
|
112 | - $args['class'] .= ' custom-control-input '; |
|
113 | - } elseif ( $type == 'datepicker' || $type == 'timepicker' ) { |
|
114 | - $type = 'text'; |
|
115 | - $args['class'] .= ' bg-initial '; // @todo not sure why we have this? |
|
116 | - $clear_function .= "jQuery(this).parent().parent().find('input[name=\'" . esc_attr( $args['name'] ) . "\']').trigger('change');"; |
|
117 | - |
|
118 | - $args['extra_attributes']['data-aui-init'] = 'flatpickr'; |
|
119 | - |
|
120 | - // set a way to clear field if empty |
|
121 | - if ( $args['input_group_right'] === '' && $args['clear_icon'] !== false ) { |
|
122 | - $args['input_group_right_inside'] = true; |
|
123 | - $args['clear_icon'] = true; |
|
124 | - } |
|
125 | - |
|
126 | - // enqueue the script |
|
127 | - $aui_settings = AyeCode_UI_Settings::instance(); |
|
128 | - $aui_settings->enqueue_flatpickr(); |
|
129 | - } elseif ( $type == 'iconpicker' ) { |
|
130 | - $type = 'text'; |
|
131 | - //$args['class'] .= ' aui-flatpickr bg-initial '; |
|
14 | + /** |
|
15 | + * Build the component. |
|
16 | + * |
|
17 | + * @param array $args |
|
18 | + * |
|
19 | + * @return string The rendered component. |
|
20 | + */ |
|
21 | + public static function input( $args = array() ) { |
|
22 | + $defaults = array( |
|
23 | + 'type' => 'text', |
|
24 | + 'name' => '', |
|
25 | + 'class' => '', |
|
26 | + 'wrap_class' => '', |
|
27 | + 'id' => '', |
|
28 | + 'placeholder' => '', |
|
29 | + 'title' => '', |
|
30 | + 'value' => '', |
|
31 | + 'required' => false, |
|
32 | + 'size' => '', // sm, lg, small, large |
|
33 | + 'clear_icon' => '', // true will show a clear icon, can't be used with input_group_right |
|
34 | + 'label' => '', |
|
35 | + 'label_after' => false, |
|
36 | + 'label_class' => '', |
|
37 | + 'label_col' => '2', |
|
38 | + 'label_type' => '', // top, horizontal, empty = hidden |
|
39 | + 'label_force_left' => false, // used to force checkbox label left when using horizontal |
|
40 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
41 | + 'help_text' => '', |
|
42 | + 'validation_text' => '', |
|
43 | + 'validation_pattern' => '', |
|
44 | + 'no_wrap' => false, |
|
45 | + 'input_group_right' => '', |
|
46 | + 'input_group_left' => '', |
|
47 | + 'input_group_right_inside' => false, |
|
48 | + // forces the input group inside the input |
|
49 | + 'input_group_left_inside' => false, |
|
50 | + // forces the input group inside the input |
|
51 | + 'step' => '', |
|
52 | + 'switch' => false, |
|
53 | + // to show checkbox as a switch |
|
54 | + 'checked' => false, |
|
55 | + // set a checkbox or radio as selected |
|
56 | + 'password_toggle' => true, |
|
57 | + // toggle view/hide password |
|
58 | + 'element_require' => '', |
|
59 | + // [%element_id%] == "1" |
|
60 | + 'extra_attributes' => array(), |
|
61 | + // an array of extra attributes |
|
62 | + 'wrap_attributes' => array() |
|
63 | + ); |
|
64 | + |
|
65 | + /** |
|
66 | + * Parse incoming $args into an array and merge it with $defaults |
|
67 | + */ |
|
68 | + $args = wp_parse_args( $args, $defaults ); |
|
69 | + $output = ''; |
|
70 | + if ( ! empty( $args['type'] ) ) { |
|
71 | + // hidden label option needs to be empty |
|
72 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
73 | + |
|
74 | + $type = sanitize_html_class( $args['type'] ); |
|
75 | + |
|
76 | + $help_text = ''; |
|
77 | + $label = ''; |
|
78 | + $label_after = $args['label_after']; |
|
79 | + $label_args = array( |
|
80 | + 'title' => $args['label'], |
|
81 | + 'for' => $args['id'], |
|
82 | + 'class' => $args['label_class'] . " ", |
|
83 | + 'label_type' => $args['label_type'], |
|
84 | + 'label_col' => $args['label_col'] |
|
85 | + ); |
|
86 | + |
|
87 | + // floating labels need label after |
|
88 | + if ( $args['label_type'] == 'floating' && $type != 'checkbox' ) { |
|
89 | + $label_after = true; |
|
90 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
91 | + } |
|
92 | + |
|
93 | + // size |
|
94 | + $size = ''; |
|
95 | + if ( $args['size'] == 'lg' || $args['size'] == 'large' ) { |
|
96 | + $size = 'lg'; |
|
97 | + $args['class'] .= ' form-control-lg'; |
|
98 | + }elseif ( $args['size'] == 'sm' || $args['size'] == 'small' ) { |
|
99 | + $size = 'sm'; |
|
100 | + $args['class'] .= ' form-control-sm'; |
|
101 | + } |
|
102 | + |
|
103 | + // clear function |
|
104 | + $clear_function = 'jQuery(this).parent().parent().find(\'input\').val(\'\');'; |
|
105 | + |
|
106 | + // Some special sauce for files |
|
107 | + if ( $type == 'file' ) { |
|
108 | + $label_after = true; // if type file we need the label after |
|
109 | + $args['class'] .= ' custom-file-input '; |
|
110 | + } elseif ( $type == 'checkbox' ) { |
|
111 | + $label_after = true; // if type file we need the label after |
|
112 | + $args['class'] .= ' custom-control-input '; |
|
113 | + } elseif ( $type == 'datepicker' || $type == 'timepicker' ) { |
|
114 | + $type = 'text'; |
|
115 | + $args['class'] .= ' bg-initial '; // @todo not sure why we have this? |
|
116 | + $clear_function .= "jQuery(this).parent().parent().find('input[name=\'" . esc_attr( $args['name'] ) . "\']').trigger('change');"; |
|
117 | + |
|
118 | + $args['extra_attributes']['data-aui-init'] = 'flatpickr'; |
|
119 | + |
|
120 | + // set a way to clear field if empty |
|
121 | + if ( $args['input_group_right'] === '' && $args['clear_icon'] !== false ) { |
|
122 | + $args['input_group_right_inside'] = true; |
|
123 | + $args['clear_icon'] = true; |
|
124 | + } |
|
125 | + |
|
126 | + // enqueue the script |
|
127 | + $aui_settings = AyeCode_UI_Settings::instance(); |
|
128 | + $aui_settings->enqueue_flatpickr(); |
|
129 | + } elseif ( $type == 'iconpicker' ) { |
|
130 | + $type = 'text'; |
|
131 | + //$args['class'] .= ' aui-flatpickr bg-initial '; |
|
132 | 132 | // $args['class'] .= ' bg-initial '; |
133 | 133 | |
134 | - $args['extra_attributes']['data-aui-init'] = 'iconpicker'; |
|
135 | - $args['extra_attributes']['data-placement'] = 'bottomRight'; |
|
134 | + $args['extra_attributes']['data-aui-init'] = 'iconpicker'; |
|
135 | + $args['extra_attributes']['data-placement'] = 'bottomRight'; |
|
136 | 136 | |
137 | - $args['input_group_right'] = '<span class="input-group-addon input-group-text c-pointer"></span>'; |
|
137 | + $args['input_group_right'] = '<span class="input-group-addon input-group-text c-pointer"></span>'; |
|
138 | 138 | // $args['input_group_right_inside'] = true; |
139 | - // enqueue the script |
|
140 | - $aui_settings = AyeCode_UI_Settings::instance(); |
|
141 | - $aui_settings->enqueue_iconpicker(); |
|
142 | - } |
|
143 | - |
|
144 | - if ( $type == 'checkbox' && !empty($args['name'] ) && strpos($args['name'], '[') === false ) { |
|
145 | - $output .= '<input type="hidden" name="' . esc_attr( $args['name'] ) . '" value="0" />'; |
|
146 | - } |
|
147 | - |
|
148 | - // allow clear icon |
|
149 | - if ( $args['input_group_right'] === '' && $args['clear_icon'] ) { |
|
150 | - $font_size = $size == 'sm' ? '1.3' : ( $size == 'lg' ? '1.65' : '1.5' ); |
|
151 | - $args['input_group_right_inside'] = true; |
|
152 | - $args['input_group_right'] = '<span class="input-group-text aui-clear-input c-pointer bg-initial border-0 px-2 d-none" onclick="' . $clear_function . '"><span style="font-size: '.$font_size.'rem" aria-hidden="true" class="close">×</span></span>'; |
|
153 | - } |
|
154 | - |
|
155 | - // open/type |
|
156 | - $output .= '<input type="' . $type . '" '; |
|
157 | - |
|
158 | - // name |
|
159 | - if ( ! empty( $args['name'] ) ) { |
|
160 | - $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
161 | - } |
|
162 | - |
|
163 | - // id |
|
164 | - if ( ! empty( $args['id'] ) ) { |
|
165 | - $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
166 | - } |
|
167 | - |
|
168 | - // placeholder |
|
169 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
170 | - $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
171 | - } |
|
172 | - |
|
173 | - // title |
|
174 | - if ( ! empty( $args['title'] ) ) { |
|
175 | - $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
176 | - } |
|
177 | - |
|
178 | - // value |
|
179 | - if ( ! empty( $args['value'] ) ) { |
|
180 | - $output .= AUI_Component_Helper::value( $args['value'] ); |
|
181 | - } |
|
182 | - |
|
183 | - // checked, for radio and checkboxes |
|
184 | - if ( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ) { |
|
185 | - $output .= ' checked '; |
|
186 | - } |
|
187 | - |
|
188 | - // validation text |
|
189 | - if ( ! empty( $args['validation_text'] ) ) { |
|
190 | - $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" '; |
|
191 | - $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
192 | - } |
|
193 | - |
|
194 | - // validation_pattern |
|
195 | - if ( ! empty( $args['validation_pattern'] ) ) { |
|
196 | - $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
197 | - } |
|
198 | - |
|
199 | - // step (for numbers) |
|
200 | - if ( ! empty( $args['step'] ) ) { |
|
201 | - $output .= ' step="' . $args['step'] . '" '; |
|
202 | - } |
|
203 | - |
|
204 | - // required |
|
205 | - if ( ! empty( $args['required'] ) ) { |
|
206 | - $output .= ' required '; |
|
207 | - } |
|
208 | - |
|
209 | - // class |
|
210 | - $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
211 | - $output .= ' class="form-control ' . $class . '" '; |
|
212 | - |
|
213 | - // data-attributes |
|
214 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
215 | - |
|
216 | - // extra attributes |
|
217 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
218 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
219 | - } |
|
220 | - |
|
221 | - // close |
|
222 | - $output .= ' >'; |
|
223 | - |
|
224 | - // help text |
|
225 | - if ( ! empty( $args['help_text'] ) ) { |
|
226 | - $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
227 | - } |
|
228 | - |
|
229 | - // label |
|
230 | - if ( ! empty( $args['label'] ) ) { |
|
231 | - $label_base_class = ''; |
|
232 | - if ( $type == 'file' ) { |
|
233 | - $label_base_class = ' custom-file-label'; |
|
234 | - } elseif ( $type == 'checkbox' ) { |
|
235 | - if ( ! empty( $args['label_force_left'] ) ) { |
|
236 | - $label_args['title'] = wp_kses_post( $args['help_text'] ); |
|
237 | - $help_text = ''; |
|
238 | - //$label_args['class'] .= ' d-inline '; |
|
239 | - $args['wrap_class'] .= ' align-items-center '; |
|
240 | - }else{ |
|
241 | - |
|
242 | - } |
|
243 | - |
|
244 | - $label_base_class = ' custom-control-label'; |
|
245 | - } |
|
246 | - $label_args['class'] .= $label_base_class; |
|
247 | - $temp_label_args = $label_args; |
|
248 | - if(! empty( $args['label_force_left'] )){$temp_label_args['class'] = $label_base_class." text-muted";} |
|
249 | - $label = self::label( $temp_label_args, $type ); |
|
250 | - } |
|
251 | - |
|
252 | - |
|
253 | - |
|
254 | - |
|
255 | - // set help text in the correct position |
|
256 | - if ( $label_after ) { |
|
257 | - $output .= $label . $help_text; |
|
258 | - } |
|
259 | - |
|
260 | - // some input types need a separate wrap |
|
261 | - if ( $type == 'file' ) { |
|
262 | - $output = self::wrap( array( |
|
263 | - 'content' => $output, |
|
264 | - 'class' => 'form-group custom-file' |
|
265 | - ) ); |
|
266 | - } elseif ( $type == 'checkbox' ) { |
|
267 | - |
|
268 | - $label_args['title'] = $args['label']; |
|
269 | - $label_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ); |
|
270 | - $label = !empty( $args['label_force_left'] ) ? self::label( $label_args, 'cb' ) : '<div class="' . $label_col . ' col-form-label"></div>'; |
|
271 | - $switch_size_class = $args['switch'] && !is_bool( $args['switch'] ) ? ' custom-switch-'.esc_attr( $args['switch'] ) : ''; |
|
272 | - $wrap_class = $args['switch'] ? 'custom-switch'.$switch_size_class : 'custom-checkbox'; |
|
273 | - if ( ! empty( $args['label_force_left'] ) ) { |
|
274 | - $wrap_class .= ' d-flex align-content-center'; |
|
275 | - $label = str_replace("custom-control-label","", self::label( $label_args, 'cb' ) ); |
|
276 | - } |
|
277 | - $output = self::wrap( array( |
|
278 | - 'content' => $output, |
|
279 | - 'class' => 'custom-control ' . $wrap_class |
|
280 | - ) ); |
|
281 | - |
|
282 | - if ( $args['label_type'] == 'horizontal' ) { |
|
283 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
284 | - $output = $label . '<div class="' . $input_col . '">' . $output . '</div>'; |
|
285 | - } |
|
286 | - } elseif ( $type == 'password' && $args['password_toggle'] && ! $args['input_group_right'] ) { |
|
287 | - |
|
288 | - |
|
289 | - // allow password field to toggle view |
|
290 | - $args['input_group_right'] = '<span class="input-group-text c-pointer px-3" |
|
139 | + // enqueue the script |
|
140 | + $aui_settings = AyeCode_UI_Settings::instance(); |
|
141 | + $aui_settings->enqueue_iconpicker(); |
|
142 | + } |
|
143 | + |
|
144 | + if ( $type == 'checkbox' && !empty($args['name'] ) && strpos($args['name'], '[') === false ) { |
|
145 | + $output .= '<input type="hidden" name="' . esc_attr( $args['name'] ) . '" value="0" />'; |
|
146 | + } |
|
147 | + |
|
148 | + // allow clear icon |
|
149 | + if ( $args['input_group_right'] === '' && $args['clear_icon'] ) { |
|
150 | + $font_size = $size == 'sm' ? '1.3' : ( $size == 'lg' ? '1.65' : '1.5' ); |
|
151 | + $args['input_group_right_inside'] = true; |
|
152 | + $args['input_group_right'] = '<span class="input-group-text aui-clear-input c-pointer bg-initial border-0 px-2 d-none" onclick="' . $clear_function . '"><span style="font-size: '.$font_size.'rem" aria-hidden="true" class="close">×</span></span>'; |
|
153 | + } |
|
154 | + |
|
155 | + // open/type |
|
156 | + $output .= '<input type="' . $type . '" '; |
|
157 | + |
|
158 | + // name |
|
159 | + if ( ! empty( $args['name'] ) ) { |
|
160 | + $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
161 | + } |
|
162 | + |
|
163 | + // id |
|
164 | + if ( ! empty( $args['id'] ) ) { |
|
165 | + $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
166 | + } |
|
167 | + |
|
168 | + // placeholder |
|
169 | + if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
170 | + $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
171 | + } |
|
172 | + |
|
173 | + // title |
|
174 | + if ( ! empty( $args['title'] ) ) { |
|
175 | + $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
176 | + } |
|
177 | + |
|
178 | + // value |
|
179 | + if ( ! empty( $args['value'] ) ) { |
|
180 | + $output .= AUI_Component_Helper::value( $args['value'] ); |
|
181 | + } |
|
182 | + |
|
183 | + // checked, for radio and checkboxes |
|
184 | + if ( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ) { |
|
185 | + $output .= ' checked '; |
|
186 | + } |
|
187 | + |
|
188 | + // validation text |
|
189 | + if ( ! empty( $args['validation_text'] ) ) { |
|
190 | + $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" '; |
|
191 | + $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
192 | + } |
|
193 | + |
|
194 | + // validation_pattern |
|
195 | + if ( ! empty( $args['validation_pattern'] ) ) { |
|
196 | + $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
197 | + } |
|
198 | + |
|
199 | + // step (for numbers) |
|
200 | + if ( ! empty( $args['step'] ) ) { |
|
201 | + $output .= ' step="' . $args['step'] . '" '; |
|
202 | + } |
|
203 | + |
|
204 | + // required |
|
205 | + if ( ! empty( $args['required'] ) ) { |
|
206 | + $output .= ' required '; |
|
207 | + } |
|
208 | + |
|
209 | + // class |
|
210 | + $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
211 | + $output .= ' class="form-control ' . $class . '" '; |
|
212 | + |
|
213 | + // data-attributes |
|
214 | + $output .= AUI_Component_Helper::data_attributes( $args ); |
|
215 | + |
|
216 | + // extra attributes |
|
217 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
218 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
219 | + } |
|
220 | + |
|
221 | + // close |
|
222 | + $output .= ' >'; |
|
223 | + |
|
224 | + // help text |
|
225 | + if ( ! empty( $args['help_text'] ) ) { |
|
226 | + $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
227 | + } |
|
228 | + |
|
229 | + // label |
|
230 | + if ( ! empty( $args['label'] ) ) { |
|
231 | + $label_base_class = ''; |
|
232 | + if ( $type == 'file' ) { |
|
233 | + $label_base_class = ' custom-file-label'; |
|
234 | + } elseif ( $type == 'checkbox' ) { |
|
235 | + if ( ! empty( $args['label_force_left'] ) ) { |
|
236 | + $label_args['title'] = wp_kses_post( $args['help_text'] ); |
|
237 | + $help_text = ''; |
|
238 | + //$label_args['class'] .= ' d-inline '; |
|
239 | + $args['wrap_class'] .= ' align-items-center '; |
|
240 | + }else{ |
|
241 | + |
|
242 | + } |
|
243 | + |
|
244 | + $label_base_class = ' custom-control-label'; |
|
245 | + } |
|
246 | + $label_args['class'] .= $label_base_class; |
|
247 | + $temp_label_args = $label_args; |
|
248 | + if(! empty( $args['label_force_left'] )){$temp_label_args['class'] = $label_base_class." text-muted";} |
|
249 | + $label = self::label( $temp_label_args, $type ); |
|
250 | + } |
|
251 | + |
|
252 | + |
|
253 | + |
|
254 | + |
|
255 | + // set help text in the correct position |
|
256 | + if ( $label_after ) { |
|
257 | + $output .= $label . $help_text; |
|
258 | + } |
|
259 | + |
|
260 | + // some input types need a separate wrap |
|
261 | + if ( $type == 'file' ) { |
|
262 | + $output = self::wrap( array( |
|
263 | + 'content' => $output, |
|
264 | + 'class' => 'form-group custom-file' |
|
265 | + ) ); |
|
266 | + } elseif ( $type == 'checkbox' ) { |
|
267 | + |
|
268 | + $label_args['title'] = $args['label']; |
|
269 | + $label_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ); |
|
270 | + $label = !empty( $args['label_force_left'] ) ? self::label( $label_args, 'cb' ) : '<div class="' . $label_col . ' col-form-label"></div>'; |
|
271 | + $switch_size_class = $args['switch'] && !is_bool( $args['switch'] ) ? ' custom-switch-'.esc_attr( $args['switch'] ) : ''; |
|
272 | + $wrap_class = $args['switch'] ? 'custom-switch'.$switch_size_class : 'custom-checkbox'; |
|
273 | + if ( ! empty( $args['label_force_left'] ) ) { |
|
274 | + $wrap_class .= ' d-flex align-content-center'; |
|
275 | + $label = str_replace("custom-control-label","", self::label( $label_args, 'cb' ) ); |
|
276 | + } |
|
277 | + $output = self::wrap( array( |
|
278 | + 'content' => $output, |
|
279 | + 'class' => 'custom-control ' . $wrap_class |
|
280 | + ) ); |
|
281 | + |
|
282 | + if ( $args['label_type'] == 'horizontal' ) { |
|
283 | + $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
284 | + $output = $label . '<div class="' . $input_col . '">' . $output . '</div>'; |
|
285 | + } |
|
286 | + } elseif ( $type == 'password' && $args['password_toggle'] && ! $args['input_group_right'] ) { |
|
287 | + |
|
288 | + |
|
289 | + // allow password field to toggle view |
|
290 | + $args['input_group_right'] = '<span class="input-group-text c-pointer px-3" |
|
291 | 291 | onclick="var $el = jQuery(this).find(\'i\');$el.toggleClass(\'fa-eye fa-eye-slash\'); |
292 | 292 | var $eli = jQuery(this).parent().parent().find(\'input\'); |
293 | 293 | if($el.hasClass(\'fa-eye\')) |
294 | 294 | {$eli.attr(\'type\',\'text\');} |
295 | 295 | else{$eli.attr(\'type\',\'password\');}" |
296 | 296 | ><i class="far fa-fw fa-eye-slash"></i></span>'; |
297 | - } |
|
298 | - |
|
299 | - // input group wraps |
|
300 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
301 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
302 | - $group_size = $size == 'lg' ? ' input-group-lg' : ''; |
|
303 | - $group_size = !$group_size && $size == 'sm' ? ' input-group-sm' : $group_size; |
|
304 | - |
|
305 | - if ( $args['input_group_left'] ) { |
|
306 | - $output = self::wrap( array( |
|
307 | - 'content' => $output, |
|
308 | - 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
|
309 | - 'input_group_left' => $args['input_group_left'], |
|
310 | - 'input_group_left_inside' => $args['input_group_left_inside'] |
|
311 | - ) ); |
|
312 | - } |
|
313 | - if ( $args['input_group_right'] ) { |
|
314 | - $output = self::wrap( array( |
|
315 | - 'content' => $output, |
|
316 | - 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
|
317 | - 'input_group_right' => $args['input_group_right'], |
|
318 | - 'input_group_right_inside' => $args['input_group_right_inside'] |
|
319 | - ) ); |
|
320 | - } |
|
321 | - |
|
322 | - } |
|
323 | - |
|
324 | - if ( ! $label_after ) { |
|
325 | - $output .= $help_text; |
|
326 | - } |
|
327 | - |
|
328 | - |
|
329 | - if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
330 | - $output = self::wrap( array( |
|
331 | - 'content' => $output, |
|
332 | - 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
333 | - ) ); |
|
334 | - } |
|
335 | - |
|
336 | - if ( ! $label_after ) { |
|
337 | - $output = $label . $output; |
|
338 | - } |
|
339 | - |
|
340 | - // wrap |
|
341 | - if ( ! $args['no_wrap'] ) { |
|
342 | - $form_group_class = $args['label_type'] == 'floating' && $type != 'checkbox' ? 'form-label-group' : 'form-group'; |
|
343 | - $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
344 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
345 | - $output = self::wrap( array( |
|
346 | - 'content' => $output, |
|
347 | - 'class' => $wrap_class, |
|
348 | - 'element_require' => $args['element_require'], |
|
349 | - 'argument_id' => $args['id'], |
|
350 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
351 | - ) ); |
|
352 | - } |
|
353 | - } |
|
354 | - |
|
355 | - return $output; |
|
356 | - } |
|
357 | - |
|
358 | - public static function label( $args = array(), $type = '' ) { |
|
359 | - //<label for="exampleInputEmail1">Email address</label> |
|
360 | - $defaults = array( |
|
361 | - 'title' => 'div', |
|
362 | - 'for' => '', |
|
363 | - 'class' => '', |
|
364 | - 'label_type' => '', // empty = hidden, top, horizontal |
|
365 | - 'label_col' => '', |
|
366 | - ); |
|
367 | - |
|
368 | - /** |
|
369 | - * Parse incoming $args into an array and merge it with $defaults |
|
370 | - */ |
|
371 | - $args = wp_parse_args( $args, $defaults ); |
|
372 | - $output = ''; |
|
373 | - |
|
374 | - if ( $args['title'] ) { |
|
375 | - |
|
376 | - // maybe hide labels //@todo set a global option for visibility class |
|
377 | - if ( $type == 'file' || $type == 'checkbox' || $type == 'radio' || ! empty( $args['label_type'] ) ) { |
|
378 | - $class = $args['class']; |
|
379 | - } else { |
|
380 | - $class = 'sr-only ' . $args['class']; |
|
381 | - } |
|
382 | - |
|
383 | - // maybe horizontal |
|
384 | - if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
385 | - $class .= ' ' . AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ) . ' col-form-label'; |
|
386 | - } |
|
387 | - |
|
388 | - // open |
|
389 | - $output .= '<label '; |
|
390 | - |
|
391 | - // for |
|
392 | - if ( ! empty( $args['for'] ) ) { |
|
393 | - $output .= ' for="' . esc_attr( $args['for'] ) . '" '; |
|
394 | - } |
|
395 | - |
|
396 | - // class |
|
397 | - $class = $class ? AUI_Component_Helper::esc_classes( $class ) : ''; |
|
398 | - $output .= ' class="' . $class . '" '; |
|
399 | - |
|
400 | - // close |
|
401 | - $output .= '>'; |
|
402 | - |
|
403 | - |
|
404 | - // title, don't escape fully as can contain html |
|
405 | - if ( ! empty( $args['title'] ) ) { |
|
406 | - $output .= wp_kses_post( $args['title'] ); |
|
407 | - } |
|
408 | - |
|
409 | - // close wrap |
|
410 | - $output .= '</label>'; |
|
411 | - |
|
412 | - |
|
413 | - } |
|
414 | - |
|
415 | - |
|
416 | - return $output; |
|
417 | - } |
|
418 | - |
|
419 | - /** |
|
420 | - * Wrap some content in a HTML wrapper. |
|
421 | - * |
|
422 | - * @param array $args |
|
423 | - * |
|
424 | - * @return string |
|
425 | - */ |
|
426 | - public static function wrap( $args = array() ) { |
|
427 | - $defaults = array( |
|
428 | - 'type' => 'div', |
|
429 | - 'class' => 'form-group', |
|
430 | - 'content' => '', |
|
431 | - 'input_group_left' => '', |
|
432 | - 'input_group_right' => '', |
|
433 | - 'input_group_left_inside' => false, |
|
434 | - 'input_group_right_inside' => false, |
|
435 | - 'element_require' => '', |
|
436 | - 'argument_id' => '', |
|
437 | - 'wrap_attributes' => array() |
|
438 | - ); |
|
439 | - |
|
440 | - /** |
|
441 | - * Parse incoming $args into an array and merge it with $defaults |
|
442 | - */ |
|
443 | - $args = wp_parse_args( $args, $defaults ); |
|
444 | - $output = ''; |
|
445 | - if ( $args['type'] ) { |
|
446 | - |
|
447 | - // open |
|
448 | - $output .= '<' . sanitize_html_class( $args['type'] ); |
|
449 | - |
|
450 | - // element require |
|
451 | - if ( ! empty( $args['element_require'] ) ) { |
|
452 | - $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
453 | - $args['class'] .= " aui-conditional-field"; |
|
454 | - } |
|
455 | - |
|
456 | - // argument_id |
|
457 | - if ( ! empty( $args['argument_id'] ) ) { |
|
458 | - $output .= ' data-argument="' . esc_attr( $args['argument_id'] ) . '"'; |
|
459 | - } |
|
460 | - |
|
461 | - // class |
|
462 | - $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
463 | - $output .= ' class="' . $class . '" '; |
|
464 | - |
|
465 | - // Attributes |
|
466 | - if ( ! empty( $args['wrap_attributes'] ) ) { |
|
467 | - $output .= AUI_Component_Helper::extra_attributes( $args['wrap_attributes'] ); |
|
468 | - } |
|
469 | - |
|
470 | - // close wrap |
|
471 | - $output .= ' >'; |
|
472 | - |
|
473 | - |
|
474 | - // Input group left |
|
475 | - if ( ! empty( $args['input_group_left'] ) ) { |
|
476 | - $position_class = ! empty( $args['input_group_left_inside'] ) ? 'position-absolute h-100' : ''; |
|
477 | - $input_group_left = strpos( $args['input_group_left'], '<' ) !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>'; |
|
478 | - $output .= '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>'; |
|
479 | - } |
|
480 | - |
|
481 | - // content |
|
482 | - $output .= $args['content']; |
|
483 | - |
|
484 | - // Input group right |
|
485 | - if ( ! empty( $args['input_group_right'] ) ) { |
|
486 | - $position_class = ! empty( $args['input_group_right_inside'] ) ? 'position-absolute h-100' : ''; |
|
487 | - $input_group_right = strpos( $args['input_group_right'], '<' ) !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>'; |
|
488 | - $output .= '<div class="input-group-append ' . $position_class . '" style="top:0;right:0;">' . $input_group_right . '</div>'; |
|
489 | - } |
|
490 | - |
|
491 | - |
|
492 | - // close wrap |
|
493 | - $output .= '</' . sanitize_html_class( $args['type'] ) . '>'; |
|
494 | - |
|
495 | - |
|
496 | - } else { |
|
497 | - $output = $args['content']; |
|
498 | - } |
|
499 | - |
|
500 | - return $output; |
|
501 | - } |
|
502 | - |
|
503 | - /** |
|
504 | - * Build the component. |
|
505 | - * |
|
506 | - * @param array $args |
|
507 | - * |
|
508 | - * @return string The rendered component. |
|
509 | - */ |
|
510 | - public static function textarea( $args = array() ) { |
|
511 | - $defaults = array( |
|
512 | - 'name' => '', |
|
513 | - 'class' => '', |
|
514 | - 'wrap_class' => '', |
|
515 | - 'id' => '', |
|
516 | - 'placeholder' => '', |
|
517 | - 'title' => '', |
|
518 | - 'value' => '', |
|
519 | - 'required' => false, |
|
520 | - 'label' => '', |
|
521 | - 'label_after' => false, |
|
522 | - 'label_class' => '', |
|
523 | - 'label_type' => '', |
|
524 | - 'label_col' => '', |
|
525 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
526 | - 'input_group_right' => '', |
|
527 | - 'input_group_left' => '', |
|
528 | - 'input_group_right_inside' => false, |
|
529 | - 'help_text' => '', |
|
530 | - 'validation_text' => '', |
|
531 | - 'validation_pattern' => '', |
|
532 | - 'no_wrap' => false, |
|
533 | - 'rows' => '', |
|
534 | - 'wysiwyg' => false, |
|
535 | - 'allow_tags' => false, |
|
536 | - // Allow HTML tags |
|
537 | - 'element_require' => '', |
|
538 | - // [%element_id%] == "1" |
|
539 | - 'extra_attributes' => array(), |
|
540 | - // an array of extra attributes |
|
541 | - 'wrap_attributes' => array(), |
|
542 | - ); |
|
543 | - |
|
544 | - /** |
|
545 | - * Parse incoming $args into an array and merge it with $defaults |
|
546 | - */ |
|
547 | - $args = wp_parse_args( $args, $defaults ); |
|
548 | - $output = ''; |
|
549 | - |
|
550 | - // hidden label option needs to be empty |
|
551 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
552 | - |
|
553 | - // floating labels don't work with wysiwyg so set it as top |
|
554 | - if ( $args['label_type'] == 'floating' && ! empty( $args['wysiwyg'] ) ) { |
|
555 | - $args['label_type'] = 'top'; |
|
556 | - } |
|
557 | - |
|
558 | - $label_after = $args['label_after']; |
|
559 | - |
|
560 | - // floating labels need label after |
|
561 | - if ( $args['label_type'] == 'floating' && empty( $args['wysiwyg'] ) ) { |
|
562 | - $label_after = true; |
|
563 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
564 | - } |
|
565 | - |
|
566 | - // label |
|
567 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
568 | - } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
569 | - $label_args = array( |
|
570 | - 'title' => $args['label'], |
|
571 | - 'for' => $args['id'], |
|
572 | - 'class' => $args['label_class'] . " ", |
|
573 | - 'label_type' => $args['label_type'], |
|
574 | - 'label_col' => $args['label_col'] |
|
575 | - ); |
|
576 | - $output .= self::label( $label_args ); |
|
577 | - } |
|
578 | - |
|
579 | - // maybe horizontal label |
|
580 | - if ( $args['label_type'] == 'horizontal' ) { |
|
581 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
582 | - $output .= '<div class="' . $input_col . '">'; |
|
583 | - } |
|
584 | - |
|
585 | - if ( ! empty( $args['wysiwyg'] ) ) { |
|
586 | - ob_start(); |
|
587 | - $content = $args['value']; |
|
588 | - $editor_id = ! empty( $args['id'] ) ? sanitize_html_class( $args['id'] ) : 'wp_editor'; |
|
589 | - $settings = array( |
|
590 | - 'textarea_rows' => ! empty( absint( $args['rows'] ) ) ? absint( $args['rows'] ) : 4, |
|
591 | - 'quicktags' => false, |
|
592 | - 'media_buttons' => false, |
|
593 | - 'editor_class' => 'form-control', |
|
594 | - 'textarea_name' => ! empty( $args['name'] ) ? sanitize_html_class( $args['name'] ) : sanitize_html_class( $args['id'] ), |
|
595 | - 'teeny' => true, |
|
596 | - ); |
|
597 | - |
|
598 | - // maybe set settings if array |
|
599 | - if ( is_array( $args['wysiwyg'] ) ) { |
|
600 | - $settings = wp_parse_args( $args['wysiwyg'], $settings ); |
|
601 | - } |
|
602 | - |
|
603 | - wp_editor( $content, $editor_id, $settings ); |
|
604 | - $output .= ob_get_clean(); |
|
605 | - } else { |
|
606 | - |
|
607 | - // open |
|
608 | - $output .= '<textarea '; |
|
609 | - |
|
610 | - // name |
|
611 | - if ( ! empty( $args['name'] ) ) { |
|
612 | - $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
613 | - } |
|
614 | - |
|
615 | - // id |
|
616 | - if ( ! empty( $args['id'] ) ) { |
|
617 | - $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
618 | - } |
|
619 | - |
|
620 | - // placeholder |
|
621 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
622 | - $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
623 | - } |
|
624 | - |
|
625 | - // title |
|
626 | - if ( ! empty( $args['title'] ) ) { |
|
627 | - $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
628 | - } |
|
629 | - |
|
630 | - // validation text |
|
631 | - if ( ! empty( $args['validation_text'] ) ) { |
|
632 | - $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" '; |
|
633 | - $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
634 | - } |
|
635 | - |
|
636 | - // validation_pattern |
|
637 | - if ( ! empty( $args['validation_pattern'] ) ) { |
|
638 | - $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
639 | - } |
|
640 | - |
|
641 | - // required |
|
642 | - if ( ! empty( $args['required'] ) ) { |
|
643 | - $output .= ' required '; |
|
644 | - } |
|
645 | - |
|
646 | - // rows |
|
647 | - if ( ! empty( $args['rows'] ) ) { |
|
648 | - $output .= ' rows="' . absint( $args['rows'] ) . '" '; |
|
649 | - } |
|
650 | - |
|
651 | - |
|
652 | - // class |
|
653 | - $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
654 | - $output .= ' class="form-control ' . $class . '" '; |
|
655 | - |
|
656 | - // extra attributes |
|
657 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
658 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
659 | - } |
|
660 | - |
|
661 | - // close tag |
|
662 | - $output .= ' >'; |
|
663 | - |
|
664 | - // value |
|
665 | - if ( ! empty( $args['value'] ) ) { |
|
666 | - if ( ! empty( $args['allow_tags'] ) ) { |
|
667 | - $output .= AUI_Component_Helper::sanitize_html_field( $args['value'], $args ); // Sanitize HTML. |
|
668 | - } else { |
|
669 | - $output .= AUI_Component_Helper::sanitize_textarea_field( $args['value'] ); |
|
670 | - } |
|
671 | - } |
|
672 | - |
|
673 | - // closing tag |
|
674 | - $output .= '</textarea>'; |
|
675 | - |
|
676 | - |
|
677 | - // input group wraps |
|
678 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
679 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
680 | - if ( $args['input_group_left'] ) { |
|
681 | - $output = self::wrap( array( |
|
682 | - 'content' => $output, |
|
683 | - 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
684 | - 'input_group_left' => $args['input_group_left'], |
|
685 | - 'input_group_left_inside' => $args['input_group_left_inside'] |
|
686 | - ) ); |
|
687 | - } |
|
688 | - if ( $args['input_group_right'] ) { |
|
689 | - $output = self::wrap( array( |
|
690 | - 'content' => $output, |
|
691 | - 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
692 | - 'input_group_right' => $args['input_group_right'], |
|
693 | - 'input_group_right_inside' => $args['input_group_right_inside'] |
|
694 | - ) ); |
|
695 | - } |
|
696 | - |
|
697 | - } |
|
698 | - |
|
699 | - |
|
700 | - } |
|
701 | - |
|
702 | - if ( ! empty( $args['label'] ) && $label_after ) { |
|
703 | - $label_args = array( |
|
704 | - 'title' => $args['label'], |
|
705 | - 'for' => $args['id'], |
|
706 | - 'class' => $args['label_class'] . " ", |
|
707 | - 'label_type' => $args['label_type'], |
|
708 | - 'label_col' => $args['label_col'] |
|
709 | - ); |
|
710 | - $output .= self::label( $label_args ); |
|
711 | - } |
|
712 | - |
|
713 | - // help text |
|
714 | - if ( ! empty( $args['help_text'] ) ) { |
|
715 | - $output .= AUI_Component_Helper::help_text( $args['help_text'] ); |
|
716 | - } |
|
717 | - |
|
718 | - // maybe horizontal label |
|
719 | - if ( $args['label_type'] == 'horizontal' ) { |
|
720 | - $output .= '</div>'; |
|
721 | - } |
|
722 | - |
|
723 | - |
|
724 | - // wrap |
|
725 | - if ( ! $args['no_wrap'] ) { |
|
726 | - $form_group_class = $args['label_type'] == 'floating' ? 'form-label-group' : 'form-group'; |
|
727 | - $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
728 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
729 | - $output = self::wrap( array( |
|
730 | - 'content' => $output, |
|
731 | - 'class' => $wrap_class, |
|
732 | - 'element_require' => $args['element_require'], |
|
733 | - 'argument_id' => $args['id'], |
|
734 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
735 | - ) ); |
|
736 | - } |
|
737 | - |
|
738 | - |
|
739 | - return $output; |
|
740 | - } |
|
741 | - |
|
742 | - /** |
|
743 | - * Build the component. |
|
744 | - * |
|
745 | - * @param array $args |
|
746 | - * |
|
747 | - * @return string The rendered component. |
|
748 | - */ |
|
749 | - public static function select( $args = array() ) { |
|
750 | - $defaults = array( |
|
751 | - 'class' => '', |
|
752 | - 'wrap_class' => '', |
|
753 | - 'id' => '', |
|
754 | - 'title' => '', |
|
755 | - 'value' => '', |
|
756 | - // can be an array or a string |
|
757 | - 'required' => false, |
|
758 | - 'label' => '', |
|
759 | - 'label_after' => false, |
|
760 | - 'label_type' => '', |
|
761 | - 'label_col' => '', |
|
762 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
763 | - 'label_class' => '', |
|
764 | - 'help_text' => '', |
|
765 | - 'placeholder' => '', |
|
766 | - 'options' => array(), |
|
767 | - // array or string |
|
768 | - 'icon' => '', |
|
769 | - 'multiple' => false, |
|
770 | - 'select2' => false, |
|
771 | - 'no_wrap' => false, |
|
772 | - 'input_group_right' => '', |
|
773 | - 'input_group_left' => '', |
|
774 | - 'input_group_right_inside' => false, // forces the input group inside the input |
|
775 | - 'input_group_left_inside' => false, // forces the input group inside the input |
|
776 | - 'element_require' => '', |
|
777 | - // [%element_id%] == "1" |
|
778 | - 'extra_attributes' => array(), |
|
779 | - // an array of extra attributes |
|
780 | - 'wrap_attributes' => array(), |
|
781 | - ); |
|
782 | - |
|
783 | - /** |
|
784 | - * Parse incoming $args into an array and merge it with $defaults |
|
785 | - */ |
|
786 | - $args = wp_parse_args( $args, $defaults ); |
|
787 | - $output = ''; |
|
788 | - |
|
789 | - // for now lets hide floating labels |
|
790 | - if ( $args['label_type'] == 'floating' ) { |
|
791 | - $args['label_type'] = 'hidden'; |
|
792 | - } |
|
793 | - |
|
794 | - // hidden label option needs to be empty |
|
795 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
796 | - |
|
797 | - |
|
798 | - $label_after = $args['label_after']; |
|
799 | - |
|
800 | - // floating labels need label after |
|
801 | - if ( $args['label_type'] == 'floating' ) { |
|
802 | - $label_after = true; |
|
803 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
804 | - } |
|
805 | - |
|
806 | - // Maybe setup select2 |
|
807 | - $is_select2 = false; |
|
808 | - if ( ! empty( $args['select2'] ) ) { |
|
809 | - $args['class'] .= ' aui-select2'; |
|
810 | - $is_select2 = true; |
|
811 | - } elseif ( strpos( $args['class'], 'aui-select2' ) !== false ) { |
|
812 | - $is_select2 = true; |
|
813 | - } |
|
814 | - |
|
815 | - // select2 tags |
|
816 | - if ( ! empty( $args['select2'] ) && $args['select2'] === 'tags' ) { // triple equals needed here for some reason |
|
817 | - $args['data-tags'] = 'true'; |
|
818 | - $args['data-token-separators'] = "[',']"; |
|
819 | - $args['multiple'] = true; |
|
820 | - } |
|
821 | - |
|
822 | - // select2 placeholder |
|
823 | - if ( $is_select2 && isset( $args['placeholder'] ) && '' != $args['placeholder'] && empty( $args['data-placeholder'] ) ) { |
|
824 | - $args['data-placeholder'] = esc_attr( $args['placeholder'] ); |
|
825 | - $args['data-allow-clear'] = isset( $args['data-allow-clear'] ) ? (bool) $args['data-allow-clear'] : true; |
|
826 | - } |
|
827 | - |
|
828 | - // Set hidden input to save empty value for multiselect. |
|
829 | - if ( ! empty( $args['multiple'] ) && ! empty( $args['name'] ) ) { |
|
830 | - $output .= '<input type="hidden" ' . AUI_Component_Helper::name( $args['name'] ) . ' value="" data-ignore-rule/>'; |
|
831 | - } |
|
832 | - |
|
833 | - // open/type |
|
834 | - $output .= '<select '; |
|
835 | - |
|
836 | - // style |
|
837 | - if ( $is_select2 && !($args['input_group_left'] || $args['input_group_right'])) { |
|
838 | - $output .= " style='width:100%;' "; |
|
839 | - } |
|
840 | - |
|
841 | - // element require |
|
842 | - if ( ! empty( $args['element_require'] ) ) { |
|
843 | - $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
844 | - $args['class'] .= " aui-conditional-field"; |
|
845 | - } |
|
846 | - |
|
847 | - // class |
|
848 | - $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
849 | - $output .= AUI_Component_Helper::class_attr( 'custom-select ' . $class ); |
|
850 | - |
|
851 | - // name |
|
852 | - if ( ! empty( $args['name'] ) ) { |
|
853 | - $output .= AUI_Component_Helper::name( $args['name'], $args['multiple'] ); |
|
854 | - } |
|
855 | - |
|
856 | - // id |
|
857 | - if ( ! empty( $args['id'] ) ) { |
|
858 | - $output .= AUI_Component_Helper::id( $args['id'] ); |
|
859 | - } |
|
860 | - |
|
861 | - // title |
|
862 | - if ( ! empty( $args['title'] ) ) { |
|
863 | - $output .= AUI_Component_Helper::title( $args['title'] ); |
|
864 | - } |
|
865 | - |
|
866 | - // data-attributes |
|
867 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
868 | - |
|
869 | - // aria-attributes |
|
870 | - $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
871 | - |
|
872 | - // extra attributes |
|
873 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
874 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
875 | - } |
|
876 | - |
|
877 | - // required |
|
878 | - if ( ! empty( $args['required'] ) ) { |
|
879 | - $output .= ' required '; |
|
880 | - } |
|
881 | - |
|
882 | - // multiple |
|
883 | - if ( ! empty( $args['multiple'] ) ) { |
|
884 | - $output .= ' multiple '; |
|
885 | - } |
|
886 | - |
|
887 | - // close opening tag |
|
888 | - $output .= ' >'; |
|
889 | - |
|
890 | - // placeholder |
|
891 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] && ! $is_select2 ) { |
|
892 | - $output .= '<option value="" disabled selected hidden>' . esc_attr( $args['placeholder'] ) . '</option>'; |
|
893 | - } elseif ( $is_select2 && ! empty( $args['placeholder'] ) ) { |
|
894 | - $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder |
|
895 | - } |
|
896 | - |
|
897 | - // Options |
|
898 | - if ( ! empty( $args['options'] ) ) { |
|
899 | - |
|
900 | - if ( ! is_array( $args['options'] ) ) { |
|
901 | - $output .= $args['options']; // not the preferred way but an option |
|
902 | - } else { |
|
903 | - foreach ( $args['options'] as $val => $name ) { |
|
904 | - $selected = ''; |
|
905 | - if ( is_array( $name ) ) { |
|
906 | - if ( isset( $name['optgroup'] ) && ( $name['optgroup'] == 'start' || $name['optgroup'] == 'end' ) ) { |
|
907 | - $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
908 | - |
|
909 | - $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>'; |
|
910 | - } else { |
|
911 | - $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
912 | - $option_value = isset( $name['value'] ) ? $name['value'] : ''; |
|
913 | - $extra_attributes = !empty($name['extra_attributes']) ? AUI_Component_Helper::extra_attributes( $name['extra_attributes'] ) : ''; |
|
914 | - if ( ! empty( $args['multiple'] ) && ! empty( $args['value'] ) && is_array( $args['value'] ) ) { |
|
915 | - $selected = in_array( $option_value, stripslashes_deep( $args['value'] ) ) ? "selected" : ""; |
|
916 | - } elseif ( ! empty( $args['value'] ) ) { |
|
917 | - $selected = selected( $option_value, stripslashes_deep( $args['value'] ), false ); |
|
918 | - } elseif ( empty( $args['value'] ) && $args['value'] === $option_value ) { |
|
919 | - $selected = selected( $option_value, $args['value'], false ); |
|
920 | - } |
|
921 | - |
|
922 | - $output .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . ' '.$extra_attributes .'>' . $option_label . '</option>'; |
|
923 | - } |
|
924 | - } else { |
|
925 | - if ( ! empty( $args['value'] ) ) { |
|
926 | - if ( is_array( $args['value'] ) ) { |
|
927 | - $selected = in_array( $val, $args['value'] ) ? 'selected="selected"' : ''; |
|
928 | - } elseif ( ! empty( $args['value'] ) ) { |
|
929 | - $selected = selected( $args['value'], $val, false ); |
|
930 | - } |
|
931 | - } elseif ( $args['value'] === $val ) { |
|
932 | - $selected = selected( $args['value'], $val, false ); |
|
933 | - } |
|
934 | - $output .= '<option value="' . esc_attr( $val ) . '" ' . $selected . '>' . esc_attr( $name ) . '</option>'; |
|
935 | - } |
|
936 | - } |
|
937 | - } |
|
938 | - |
|
939 | - } |
|
940 | - |
|
941 | - // closing tag |
|
942 | - $output .= '</select>'; |
|
943 | - |
|
944 | - $label = ''; |
|
945 | - $help_text = ''; |
|
946 | - // label |
|
947 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
948 | - } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
949 | - $label_args = array( |
|
950 | - 'title' => $args['label'], |
|
951 | - 'for' => $args['id'], |
|
952 | - 'class' => $args['label_class'] . " ", |
|
953 | - 'label_type' => $args['label_type'], |
|
954 | - 'label_col' => $args['label_col'] |
|
955 | - ); |
|
956 | - $label = self::label( $label_args ); |
|
957 | - } |
|
958 | - |
|
959 | - // help text |
|
960 | - if ( ! empty( $args['help_text'] ) ) { |
|
961 | - $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
962 | - } |
|
963 | - |
|
964 | - // input group wraps |
|
965 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
966 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
967 | - if ( $args['input_group_left'] ) { |
|
968 | - $output = self::wrap( array( |
|
969 | - 'content' => $output, |
|
970 | - 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
971 | - 'input_group_left' => $args['input_group_left'], |
|
972 | - 'input_group_left_inside' => $args['input_group_left_inside'] |
|
973 | - ) ); |
|
974 | - } |
|
975 | - if ( $args['input_group_right'] ) { |
|
976 | - $output = self::wrap( array( |
|
977 | - 'content' => $output, |
|
978 | - 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
979 | - 'input_group_right' => $args['input_group_right'], |
|
980 | - 'input_group_right_inside' => $args['input_group_right_inside'] |
|
981 | - ) ); |
|
982 | - } |
|
983 | - |
|
984 | - } |
|
985 | - |
|
986 | - if ( ! $label_after ) { |
|
987 | - $output .= $help_text; |
|
988 | - } |
|
989 | - |
|
990 | - |
|
991 | - if ( $args['label_type'] == 'horizontal' ) { |
|
992 | - $output = self::wrap( array( |
|
993 | - 'content' => $output, |
|
994 | - 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
995 | - ) ); |
|
996 | - } |
|
997 | - |
|
998 | - if ( ! $label_after ) { |
|
999 | - $output = $label . $output; |
|
1000 | - } |
|
1001 | - |
|
1002 | - // maybe horizontal label |
|
297 | + } |
|
298 | + |
|
299 | + // input group wraps |
|
300 | + if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
301 | + $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
302 | + $group_size = $size == 'lg' ? ' input-group-lg' : ''; |
|
303 | + $group_size = !$group_size && $size == 'sm' ? ' input-group-sm' : $group_size; |
|
304 | + |
|
305 | + if ( $args['input_group_left'] ) { |
|
306 | + $output = self::wrap( array( |
|
307 | + 'content' => $output, |
|
308 | + 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
|
309 | + 'input_group_left' => $args['input_group_left'], |
|
310 | + 'input_group_left_inside' => $args['input_group_left_inside'] |
|
311 | + ) ); |
|
312 | + } |
|
313 | + if ( $args['input_group_right'] ) { |
|
314 | + $output = self::wrap( array( |
|
315 | + 'content' => $output, |
|
316 | + 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
|
317 | + 'input_group_right' => $args['input_group_right'], |
|
318 | + 'input_group_right_inside' => $args['input_group_right_inside'] |
|
319 | + ) ); |
|
320 | + } |
|
321 | + |
|
322 | + } |
|
323 | + |
|
324 | + if ( ! $label_after ) { |
|
325 | + $output .= $help_text; |
|
326 | + } |
|
327 | + |
|
328 | + |
|
329 | + if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
330 | + $output = self::wrap( array( |
|
331 | + 'content' => $output, |
|
332 | + 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
333 | + ) ); |
|
334 | + } |
|
335 | + |
|
336 | + if ( ! $label_after ) { |
|
337 | + $output = $label . $output; |
|
338 | + } |
|
339 | + |
|
340 | + // wrap |
|
341 | + if ( ! $args['no_wrap'] ) { |
|
342 | + $form_group_class = $args['label_type'] == 'floating' && $type != 'checkbox' ? 'form-label-group' : 'form-group'; |
|
343 | + $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
344 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
345 | + $output = self::wrap( array( |
|
346 | + 'content' => $output, |
|
347 | + 'class' => $wrap_class, |
|
348 | + 'element_require' => $args['element_require'], |
|
349 | + 'argument_id' => $args['id'], |
|
350 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
351 | + ) ); |
|
352 | + } |
|
353 | + } |
|
354 | + |
|
355 | + return $output; |
|
356 | + } |
|
357 | + |
|
358 | + public static function label( $args = array(), $type = '' ) { |
|
359 | + //<label for="exampleInputEmail1">Email address</label> |
|
360 | + $defaults = array( |
|
361 | + 'title' => 'div', |
|
362 | + 'for' => '', |
|
363 | + 'class' => '', |
|
364 | + 'label_type' => '', // empty = hidden, top, horizontal |
|
365 | + 'label_col' => '', |
|
366 | + ); |
|
367 | + |
|
368 | + /** |
|
369 | + * Parse incoming $args into an array and merge it with $defaults |
|
370 | + */ |
|
371 | + $args = wp_parse_args( $args, $defaults ); |
|
372 | + $output = ''; |
|
373 | + |
|
374 | + if ( $args['title'] ) { |
|
375 | + |
|
376 | + // maybe hide labels //@todo set a global option for visibility class |
|
377 | + if ( $type == 'file' || $type == 'checkbox' || $type == 'radio' || ! empty( $args['label_type'] ) ) { |
|
378 | + $class = $args['class']; |
|
379 | + } else { |
|
380 | + $class = 'sr-only ' . $args['class']; |
|
381 | + } |
|
382 | + |
|
383 | + // maybe horizontal |
|
384 | + if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
385 | + $class .= ' ' . AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ) . ' col-form-label'; |
|
386 | + } |
|
387 | + |
|
388 | + // open |
|
389 | + $output .= '<label '; |
|
390 | + |
|
391 | + // for |
|
392 | + if ( ! empty( $args['for'] ) ) { |
|
393 | + $output .= ' for="' . esc_attr( $args['for'] ) . '" '; |
|
394 | + } |
|
395 | + |
|
396 | + // class |
|
397 | + $class = $class ? AUI_Component_Helper::esc_classes( $class ) : ''; |
|
398 | + $output .= ' class="' . $class . '" '; |
|
399 | + |
|
400 | + // close |
|
401 | + $output .= '>'; |
|
402 | + |
|
403 | + |
|
404 | + // title, don't escape fully as can contain html |
|
405 | + if ( ! empty( $args['title'] ) ) { |
|
406 | + $output .= wp_kses_post( $args['title'] ); |
|
407 | + } |
|
408 | + |
|
409 | + // close wrap |
|
410 | + $output .= '</label>'; |
|
411 | + |
|
412 | + |
|
413 | + } |
|
414 | + |
|
415 | + |
|
416 | + return $output; |
|
417 | + } |
|
418 | + |
|
419 | + /** |
|
420 | + * Wrap some content in a HTML wrapper. |
|
421 | + * |
|
422 | + * @param array $args |
|
423 | + * |
|
424 | + * @return string |
|
425 | + */ |
|
426 | + public static function wrap( $args = array() ) { |
|
427 | + $defaults = array( |
|
428 | + 'type' => 'div', |
|
429 | + 'class' => 'form-group', |
|
430 | + 'content' => '', |
|
431 | + 'input_group_left' => '', |
|
432 | + 'input_group_right' => '', |
|
433 | + 'input_group_left_inside' => false, |
|
434 | + 'input_group_right_inside' => false, |
|
435 | + 'element_require' => '', |
|
436 | + 'argument_id' => '', |
|
437 | + 'wrap_attributes' => array() |
|
438 | + ); |
|
439 | + |
|
440 | + /** |
|
441 | + * Parse incoming $args into an array and merge it with $defaults |
|
442 | + */ |
|
443 | + $args = wp_parse_args( $args, $defaults ); |
|
444 | + $output = ''; |
|
445 | + if ( $args['type'] ) { |
|
446 | + |
|
447 | + // open |
|
448 | + $output .= '<' . sanitize_html_class( $args['type'] ); |
|
449 | + |
|
450 | + // element require |
|
451 | + if ( ! empty( $args['element_require'] ) ) { |
|
452 | + $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
453 | + $args['class'] .= " aui-conditional-field"; |
|
454 | + } |
|
455 | + |
|
456 | + // argument_id |
|
457 | + if ( ! empty( $args['argument_id'] ) ) { |
|
458 | + $output .= ' data-argument="' . esc_attr( $args['argument_id'] ) . '"'; |
|
459 | + } |
|
460 | + |
|
461 | + // class |
|
462 | + $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
463 | + $output .= ' class="' . $class . '" '; |
|
464 | + |
|
465 | + // Attributes |
|
466 | + if ( ! empty( $args['wrap_attributes'] ) ) { |
|
467 | + $output .= AUI_Component_Helper::extra_attributes( $args['wrap_attributes'] ); |
|
468 | + } |
|
469 | + |
|
470 | + // close wrap |
|
471 | + $output .= ' >'; |
|
472 | + |
|
473 | + |
|
474 | + // Input group left |
|
475 | + if ( ! empty( $args['input_group_left'] ) ) { |
|
476 | + $position_class = ! empty( $args['input_group_left_inside'] ) ? 'position-absolute h-100' : ''; |
|
477 | + $input_group_left = strpos( $args['input_group_left'], '<' ) !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>'; |
|
478 | + $output .= '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>'; |
|
479 | + } |
|
480 | + |
|
481 | + // content |
|
482 | + $output .= $args['content']; |
|
483 | + |
|
484 | + // Input group right |
|
485 | + if ( ! empty( $args['input_group_right'] ) ) { |
|
486 | + $position_class = ! empty( $args['input_group_right_inside'] ) ? 'position-absolute h-100' : ''; |
|
487 | + $input_group_right = strpos( $args['input_group_right'], '<' ) !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>'; |
|
488 | + $output .= '<div class="input-group-append ' . $position_class . '" style="top:0;right:0;">' . $input_group_right . '</div>'; |
|
489 | + } |
|
490 | + |
|
491 | + |
|
492 | + // close wrap |
|
493 | + $output .= '</' . sanitize_html_class( $args['type'] ) . '>'; |
|
494 | + |
|
495 | + |
|
496 | + } else { |
|
497 | + $output = $args['content']; |
|
498 | + } |
|
499 | + |
|
500 | + return $output; |
|
501 | + } |
|
502 | + |
|
503 | + /** |
|
504 | + * Build the component. |
|
505 | + * |
|
506 | + * @param array $args |
|
507 | + * |
|
508 | + * @return string The rendered component. |
|
509 | + */ |
|
510 | + public static function textarea( $args = array() ) { |
|
511 | + $defaults = array( |
|
512 | + 'name' => '', |
|
513 | + 'class' => '', |
|
514 | + 'wrap_class' => '', |
|
515 | + 'id' => '', |
|
516 | + 'placeholder' => '', |
|
517 | + 'title' => '', |
|
518 | + 'value' => '', |
|
519 | + 'required' => false, |
|
520 | + 'label' => '', |
|
521 | + 'label_after' => false, |
|
522 | + 'label_class' => '', |
|
523 | + 'label_type' => '', |
|
524 | + 'label_col' => '', |
|
525 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
526 | + 'input_group_right' => '', |
|
527 | + 'input_group_left' => '', |
|
528 | + 'input_group_right_inside' => false, |
|
529 | + 'help_text' => '', |
|
530 | + 'validation_text' => '', |
|
531 | + 'validation_pattern' => '', |
|
532 | + 'no_wrap' => false, |
|
533 | + 'rows' => '', |
|
534 | + 'wysiwyg' => false, |
|
535 | + 'allow_tags' => false, |
|
536 | + // Allow HTML tags |
|
537 | + 'element_require' => '', |
|
538 | + // [%element_id%] == "1" |
|
539 | + 'extra_attributes' => array(), |
|
540 | + // an array of extra attributes |
|
541 | + 'wrap_attributes' => array(), |
|
542 | + ); |
|
543 | + |
|
544 | + /** |
|
545 | + * Parse incoming $args into an array and merge it with $defaults |
|
546 | + */ |
|
547 | + $args = wp_parse_args( $args, $defaults ); |
|
548 | + $output = ''; |
|
549 | + |
|
550 | + // hidden label option needs to be empty |
|
551 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
552 | + |
|
553 | + // floating labels don't work with wysiwyg so set it as top |
|
554 | + if ( $args['label_type'] == 'floating' && ! empty( $args['wysiwyg'] ) ) { |
|
555 | + $args['label_type'] = 'top'; |
|
556 | + } |
|
557 | + |
|
558 | + $label_after = $args['label_after']; |
|
559 | + |
|
560 | + // floating labels need label after |
|
561 | + if ( $args['label_type'] == 'floating' && empty( $args['wysiwyg'] ) ) { |
|
562 | + $label_after = true; |
|
563 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
564 | + } |
|
565 | + |
|
566 | + // label |
|
567 | + if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
568 | + } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
569 | + $label_args = array( |
|
570 | + 'title' => $args['label'], |
|
571 | + 'for' => $args['id'], |
|
572 | + 'class' => $args['label_class'] . " ", |
|
573 | + 'label_type' => $args['label_type'], |
|
574 | + 'label_col' => $args['label_col'] |
|
575 | + ); |
|
576 | + $output .= self::label( $label_args ); |
|
577 | + } |
|
578 | + |
|
579 | + // maybe horizontal label |
|
580 | + if ( $args['label_type'] == 'horizontal' ) { |
|
581 | + $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
582 | + $output .= '<div class="' . $input_col . '">'; |
|
583 | + } |
|
584 | + |
|
585 | + if ( ! empty( $args['wysiwyg'] ) ) { |
|
586 | + ob_start(); |
|
587 | + $content = $args['value']; |
|
588 | + $editor_id = ! empty( $args['id'] ) ? sanitize_html_class( $args['id'] ) : 'wp_editor'; |
|
589 | + $settings = array( |
|
590 | + 'textarea_rows' => ! empty( absint( $args['rows'] ) ) ? absint( $args['rows'] ) : 4, |
|
591 | + 'quicktags' => false, |
|
592 | + 'media_buttons' => false, |
|
593 | + 'editor_class' => 'form-control', |
|
594 | + 'textarea_name' => ! empty( $args['name'] ) ? sanitize_html_class( $args['name'] ) : sanitize_html_class( $args['id'] ), |
|
595 | + 'teeny' => true, |
|
596 | + ); |
|
597 | + |
|
598 | + // maybe set settings if array |
|
599 | + if ( is_array( $args['wysiwyg'] ) ) { |
|
600 | + $settings = wp_parse_args( $args['wysiwyg'], $settings ); |
|
601 | + } |
|
602 | + |
|
603 | + wp_editor( $content, $editor_id, $settings ); |
|
604 | + $output .= ob_get_clean(); |
|
605 | + } else { |
|
606 | + |
|
607 | + // open |
|
608 | + $output .= '<textarea '; |
|
609 | + |
|
610 | + // name |
|
611 | + if ( ! empty( $args['name'] ) ) { |
|
612 | + $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
613 | + } |
|
614 | + |
|
615 | + // id |
|
616 | + if ( ! empty( $args['id'] ) ) { |
|
617 | + $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
618 | + } |
|
619 | + |
|
620 | + // placeholder |
|
621 | + if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
622 | + $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
623 | + } |
|
624 | + |
|
625 | + // title |
|
626 | + if ( ! empty( $args['title'] ) ) { |
|
627 | + $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
628 | + } |
|
629 | + |
|
630 | + // validation text |
|
631 | + if ( ! empty( $args['validation_text'] ) ) { |
|
632 | + $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" '; |
|
633 | + $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
634 | + } |
|
635 | + |
|
636 | + // validation_pattern |
|
637 | + if ( ! empty( $args['validation_pattern'] ) ) { |
|
638 | + $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
639 | + } |
|
640 | + |
|
641 | + // required |
|
642 | + if ( ! empty( $args['required'] ) ) { |
|
643 | + $output .= ' required '; |
|
644 | + } |
|
645 | + |
|
646 | + // rows |
|
647 | + if ( ! empty( $args['rows'] ) ) { |
|
648 | + $output .= ' rows="' . absint( $args['rows'] ) . '" '; |
|
649 | + } |
|
650 | + |
|
651 | + |
|
652 | + // class |
|
653 | + $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
654 | + $output .= ' class="form-control ' . $class . '" '; |
|
655 | + |
|
656 | + // extra attributes |
|
657 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
658 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
659 | + } |
|
660 | + |
|
661 | + // close tag |
|
662 | + $output .= ' >'; |
|
663 | + |
|
664 | + // value |
|
665 | + if ( ! empty( $args['value'] ) ) { |
|
666 | + if ( ! empty( $args['allow_tags'] ) ) { |
|
667 | + $output .= AUI_Component_Helper::sanitize_html_field( $args['value'], $args ); // Sanitize HTML. |
|
668 | + } else { |
|
669 | + $output .= AUI_Component_Helper::sanitize_textarea_field( $args['value'] ); |
|
670 | + } |
|
671 | + } |
|
672 | + |
|
673 | + // closing tag |
|
674 | + $output .= '</textarea>'; |
|
675 | + |
|
676 | + |
|
677 | + // input group wraps |
|
678 | + if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
679 | + $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
680 | + if ( $args['input_group_left'] ) { |
|
681 | + $output = self::wrap( array( |
|
682 | + 'content' => $output, |
|
683 | + 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
684 | + 'input_group_left' => $args['input_group_left'], |
|
685 | + 'input_group_left_inside' => $args['input_group_left_inside'] |
|
686 | + ) ); |
|
687 | + } |
|
688 | + if ( $args['input_group_right'] ) { |
|
689 | + $output = self::wrap( array( |
|
690 | + 'content' => $output, |
|
691 | + 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
692 | + 'input_group_right' => $args['input_group_right'], |
|
693 | + 'input_group_right_inside' => $args['input_group_right_inside'] |
|
694 | + ) ); |
|
695 | + } |
|
696 | + |
|
697 | + } |
|
698 | + |
|
699 | + |
|
700 | + } |
|
701 | + |
|
702 | + if ( ! empty( $args['label'] ) && $label_after ) { |
|
703 | + $label_args = array( |
|
704 | + 'title' => $args['label'], |
|
705 | + 'for' => $args['id'], |
|
706 | + 'class' => $args['label_class'] . " ", |
|
707 | + 'label_type' => $args['label_type'], |
|
708 | + 'label_col' => $args['label_col'] |
|
709 | + ); |
|
710 | + $output .= self::label( $label_args ); |
|
711 | + } |
|
712 | + |
|
713 | + // help text |
|
714 | + if ( ! empty( $args['help_text'] ) ) { |
|
715 | + $output .= AUI_Component_Helper::help_text( $args['help_text'] ); |
|
716 | + } |
|
717 | + |
|
718 | + // maybe horizontal label |
|
719 | + if ( $args['label_type'] == 'horizontal' ) { |
|
720 | + $output .= '</div>'; |
|
721 | + } |
|
722 | + |
|
723 | + |
|
724 | + // wrap |
|
725 | + if ( ! $args['no_wrap'] ) { |
|
726 | + $form_group_class = $args['label_type'] == 'floating' ? 'form-label-group' : 'form-group'; |
|
727 | + $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
728 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
729 | + $output = self::wrap( array( |
|
730 | + 'content' => $output, |
|
731 | + 'class' => $wrap_class, |
|
732 | + 'element_require' => $args['element_require'], |
|
733 | + 'argument_id' => $args['id'], |
|
734 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
735 | + ) ); |
|
736 | + } |
|
737 | + |
|
738 | + |
|
739 | + return $output; |
|
740 | + } |
|
741 | + |
|
742 | + /** |
|
743 | + * Build the component. |
|
744 | + * |
|
745 | + * @param array $args |
|
746 | + * |
|
747 | + * @return string The rendered component. |
|
748 | + */ |
|
749 | + public static function select( $args = array() ) { |
|
750 | + $defaults = array( |
|
751 | + 'class' => '', |
|
752 | + 'wrap_class' => '', |
|
753 | + 'id' => '', |
|
754 | + 'title' => '', |
|
755 | + 'value' => '', |
|
756 | + // can be an array or a string |
|
757 | + 'required' => false, |
|
758 | + 'label' => '', |
|
759 | + 'label_after' => false, |
|
760 | + 'label_type' => '', |
|
761 | + 'label_col' => '', |
|
762 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
763 | + 'label_class' => '', |
|
764 | + 'help_text' => '', |
|
765 | + 'placeholder' => '', |
|
766 | + 'options' => array(), |
|
767 | + // array or string |
|
768 | + 'icon' => '', |
|
769 | + 'multiple' => false, |
|
770 | + 'select2' => false, |
|
771 | + 'no_wrap' => false, |
|
772 | + 'input_group_right' => '', |
|
773 | + 'input_group_left' => '', |
|
774 | + 'input_group_right_inside' => false, // forces the input group inside the input |
|
775 | + 'input_group_left_inside' => false, // forces the input group inside the input |
|
776 | + 'element_require' => '', |
|
777 | + // [%element_id%] == "1" |
|
778 | + 'extra_attributes' => array(), |
|
779 | + // an array of extra attributes |
|
780 | + 'wrap_attributes' => array(), |
|
781 | + ); |
|
782 | + |
|
783 | + /** |
|
784 | + * Parse incoming $args into an array and merge it with $defaults |
|
785 | + */ |
|
786 | + $args = wp_parse_args( $args, $defaults ); |
|
787 | + $output = ''; |
|
788 | + |
|
789 | + // for now lets hide floating labels |
|
790 | + if ( $args['label_type'] == 'floating' ) { |
|
791 | + $args['label_type'] = 'hidden'; |
|
792 | + } |
|
793 | + |
|
794 | + // hidden label option needs to be empty |
|
795 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
796 | + |
|
797 | + |
|
798 | + $label_after = $args['label_after']; |
|
799 | + |
|
800 | + // floating labels need label after |
|
801 | + if ( $args['label_type'] == 'floating' ) { |
|
802 | + $label_after = true; |
|
803 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
804 | + } |
|
805 | + |
|
806 | + // Maybe setup select2 |
|
807 | + $is_select2 = false; |
|
808 | + if ( ! empty( $args['select2'] ) ) { |
|
809 | + $args['class'] .= ' aui-select2'; |
|
810 | + $is_select2 = true; |
|
811 | + } elseif ( strpos( $args['class'], 'aui-select2' ) !== false ) { |
|
812 | + $is_select2 = true; |
|
813 | + } |
|
814 | + |
|
815 | + // select2 tags |
|
816 | + if ( ! empty( $args['select2'] ) && $args['select2'] === 'tags' ) { // triple equals needed here for some reason |
|
817 | + $args['data-tags'] = 'true'; |
|
818 | + $args['data-token-separators'] = "[',']"; |
|
819 | + $args['multiple'] = true; |
|
820 | + } |
|
821 | + |
|
822 | + // select2 placeholder |
|
823 | + if ( $is_select2 && isset( $args['placeholder'] ) && '' != $args['placeholder'] && empty( $args['data-placeholder'] ) ) { |
|
824 | + $args['data-placeholder'] = esc_attr( $args['placeholder'] ); |
|
825 | + $args['data-allow-clear'] = isset( $args['data-allow-clear'] ) ? (bool) $args['data-allow-clear'] : true; |
|
826 | + } |
|
827 | + |
|
828 | + // Set hidden input to save empty value for multiselect. |
|
829 | + if ( ! empty( $args['multiple'] ) && ! empty( $args['name'] ) ) { |
|
830 | + $output .= '<input type="hidden" ' . AUI_Component_Helper::name( $args['name'] ) . ' value="" data-ignore-rule/>'; |
|
831 | + } |
|
832 | + |
|
833 | + // open/type |
|
834 | + $output .= '<select '; |
|
835 | + |
|
836 | + // style |
|
837 | + if ( $is_select2 && !($args['input_group_left'] || $args['input_group_right'])) { |
|
838 | + $output .= " style='width:100%;' "; |
|
839 | + } |
|
840 | + |
|
841 | + // element require |
|
842 | + if ( ! empty( $args['element_require'] ) ) { |
|
843 | + $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
844 | + $args['class'] .= " aui-conditional-field"; |
|
845 | + } |
|
846 | + |
|
847 | + // class |
|
848 | + $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
849 | + $output .= AUI_Component_Helper::class_attr( 'custom-select ' . $class ); |
|
850 | + |
|
851 | + // name |
|
852 | + if ( ! empty( $args['name'] ) ) { |
|
853 | + $output .= AUI_Component_Helper::name( $args['name'], $args['multiple'] ); |
|
854 | + } |
|
855 | + |
|
856 | + // id |
|
857 | + if ( ! empty( $args['id'] ) ) { |
|
858 | + $output .= AUI_Component_Helper::id( $args['id'] ); |
|
859 | + } |
|
860 | + |
|
861 | + // title |
|
862 | + if ( ! empty( $args['title'] ) ) { |
|
863 | + $output .= AUI_Component_Helper::title( $args['title'] ); |
|
864 | + } |
|
865 | + |
|
866 | + // data-attributes |
|
867 | + $output .= AUI_Component_Helper::data_attributes( $args ); |
|
868 | + |
|
869 | + // aria-attributes |
|
870 | + $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
871 | + |
|
872 | + // extra attributes |
|
873 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
874 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
875 | + } |
|
876 | + |
|
877 | + // required |
|
878 | + if ( ! empty( $args['required'] ) ) { |
|
879 | + $output .= ' required '; |
|
880 | + } |
|
881 | + |
|
882 | + // multiple |
|
883 | + if ( ! empty( $args['multiple'] ) ) { |
|
884 | + $output .= ' multiple '; |
|
885 | + } |
|
886 | + |
|
887 | + // close opening tag |
|
888 | + $output .= ' >'; |
|
889 | + |
|
890 | + // placeholder |
|
891 | + if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] && ! $is_select2 ) { |
|
892 | + $output .= '<option value="" disabled selected hidden>' . esc_attr( $args['placeholder'] ) . '</option>'; |
|
893 | + } elseif ( $is_select2 && ! empty( $args['placeholder'] ) ) { |
|
894 | + $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder |
|
895 | + } |
|
896 | + |
|
897 | + // Options |
|
898 | + if ( ! empty( $args['options'] ) ) { |
|
899 | + |
|
900 | + if ( ! is_array( $args['options'] ) ) { |
|
901 | + $output .= $args['options']; // not the preferred way but an option |
|
902 | + } else { |
|
903 | + foreach ( $args['options'] as $val => $name ) { |
|
904 | + $selected = ''; |
|
905 | + if ( is_array( $name ) ) { |
|
906 | + if ( isset( $name['optgroup'] ) && ( $name['optgroup'] == 'start' || $name['optgroup'] == 'end' ) ) { |
|
907 | + $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
908 | + |
|
909 | + $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>'; |
|
910 | + } else { |
|
911 | + $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
912 | + $option_value = isset( $name['value'] ) ? $name['value'] : ''; |
|
913 | + $extra_attributes = !empty($name['extra_attributes']) ? AUI_Component_Helper::extra_attributes( $name['extra_attributes'] ) : ''; |
|
914 | + if ( ! empty( $args['multiple'] ) && ! empty( $args['value'] ) && is_array( $args['value'] ) ) { |
|
915 | + $selected = in_array( $option_value, stripslashes_deep( $args['value'] ) ) ? "selected" : ""; |
|
916 | + } elseif ( ! empty( $args['value'] ) ) { |
|
917 | + $selected = selected( $option_value, stripslashes_deep( $args['value'] ), false ); |
|
918 | + } elseif ( empty( $args['value'] ) && $args['value'] === $option_value ) { |
|
919 | + $selected = selected( $option_value, $args['value'], false ); |
|
920 | + } |
|
921 | + |
|
922 | + $output .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . ' '.$extra_attributes .'>' . $option_label . '</option>'; |
|
923 | + } |
|
924 | + } else { |
|
925 | + if ( ! empty( $args['value'] ) ) { |
|
926 | + if ( is_array( $args['value'] ) ) { |
|
927 | + $selected = in_array( $val, $args['value'] ) ? 'selected="selected"' : ''; |
|
928 | + } elseif ( ! empty( $args['value'] ) ) { |
|
929 | + $selected = selected( $args['value'], $val, false ); |
|
930 | + } |
|
931 | + } elseif ( $args['value'] === $val ) { |
|
932 | + $selected = selected( $args['value'], $val, false ); |
|
933 | + } |
|
934 | + $output .= '<option value="' . esc_attr( $val ) . '" ' . $selected . '>' . esc_attr( $name ) . '</option>'; |
|
935 | + } |
|
936 | + } |
|
937 | + } |
|
938 | + |
|
939 | + } |
|
940 | + |
|
941 | + // closing tag |
|
942 | + $output .= '</select>'; |
|
943 | + |
|
944 | + $label = ''; |
|
945 | + $help_text = ''; |
|
946 | + // label |
|
947 | + if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
948 | + } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
949 | + $label_args = array( |
|
950 | + 'title' => $args['label'], |
|
951 | + 'for' => $args['id'], |
|
952 | + 'class' => $args['label_class'] . " ", |
|
953 | + 'label_type' => $args['label_type'], |
|
954 | + 'label_col' => $args['label_col'] |
|
955 | + ); |
|
956 | + $label = self::label( $label_args ); |
|
957 | + } |
|
958 | + |
|
959 | + // help text |
|
960 | + if ( ! empty( $args['help_text'] ) ) { |
|
961 | + $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
962 | + } |
|
963 | + |
|
964 | + // input group wraps |
|
965 | + if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
966 | + $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
967 | + if ( $args['input_group_left'] ) { |
|
968 | + $output = self::wrap( array( |
|
969 | + 'content' => $output, |
|
970 | + 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
971 | + 'input_group_left' => $args['input_group_left'], |
|
972 | + 'input_group_left_inside' => $args['input_group_left_inside'] |
|
973 | + ) ); |
|
974 | + } |
|
975 | + if ( $args['input_group_right'] ) { |
|
976 | + $output = self::wrap( array( |
|
977 | + 'content' => $output, |
|
978 | + 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
979 | + 'input_group_right' => $args['input_group_right'], |
|
980 | + 'input_group_right_inside' => $args['input_group_right_inside'] |
|
981 | + ) ); |
|
982 | + } |
|
983 | + |
|
984 | + } |
|
985 | + |
|
986 | + if ( ! $label_after ) { |
|
987 | + $output .= $help_text; |
|
988 | + } |
|
989 | + |
|
990 | + |
|
991 | + if ( $args['label_type'] == 'horizontal' ) { |
|
992 | + $output = self::wrap( array( |
|
993 | + 'content' => $output, |
|
994 | + 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
995 | + ) ); |
|
996 | + } |
|
997 | + |
|
998 | + if ( ! $label_after ) { |
|
999 | + $output = $label . $output; |
|
1000 | + } |
|
1001 | + |
|
1002 | + // maybe horizontal label |
|
1003 | 1003 | // if ( $args['label_type'] == 'horizontal' ) { |
1004 | 1004 | // $output .= '</div>'; |
1005 | 1005 | // } |
1006 | 1006 | |
1007 | 1007 | |
1008 | - // wrap |
|
1009 | - if ( ! $args['no_wrap'] ) { |
|
1010 | - $wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group'; |
|
1011 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1012 | - $output = self::wrap( array( |
|
1013 | - 'content' => $output, |
|
1014 | - 'class' => $wrap_class, |
|
1015 | - 'element_require' => $args['element_require'], |
|
1016 | - 'argument_id' => $args['id'], |
|
1017 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
1018 | - ) ); |
|
1019 | - } |
|
1020 | - |
|
1021 | - |
|
1022 | - return $output; |
|
1023 | - } |
|
1024 | - |
|
1025 | - /** |
|
1026 | - * Build the component. |
|
1027 | - * |
|
1028 | - * @param array $args |
|
1029 | - * |
|
1030 | - * @return string The rendered component. |
|
1031 | - */ |
|
1032 | - public static function radio( $args = array() ) { |
|
1033 | - $defaults = array( |
|
1034 | - 'class' => '', |
|
1035 | - 'wrap_class' => '', |
|
1036 | - 'id' => '', |
|
1037 | - 'title' => '', |
|
1038 | - 'horizontal' => false, |
|
1039 | - // sets the lable horizontal |
|
1040 | - 'value' => '', |
|
1041 | - 'label' => '', |
|
1042 | - 'label_class' => '', |
|
1043 | - 'label_type' => '', |
|
1044 | - 'label_col' => '', |
|
1045 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
1046 | - 'help_text' => '', |
|
1047 | - 'inline' => true, |
|
1048 | - 'required' => false, |
|
1049 | - 'options' => array(), |
|
1050 | - 'icon' => '', |
|
1051 | - 'no_wrap' => false, |
|
1052 | - 'element_require' => '', |
|
1053 | - // [%element_id%] == "1" |
|
1054 | - 'extra_attributes' => array(), |
|
1055 | - // an array of extra attributes |
|
1056 | - 'wrap_attributes' => array() |
|
1057 | - ); |
|
1058 | - |
|
1059 | - /** |
|
1060 | - * Parse incoming $args into an array and merge it with $defaults |
|
1061 | - */ |
|
1062 | - $args = wp_parse_args( $args, $defaults ); |
|
1063 | - |
|
1064 | - // for now lets use horizontal for floating |
|
1065 | - if ( $args['label_type'] == 'floating' ) { |
|
1066 | - $args['label_type'] = 'horizontal'; |
|
1067 | - } |
|
1068 | - |
|
1069 | - $label_args = array( |
|
1070 | - 'title' => $args['label'], |
|
1071 | - 'class' => $args['label_class'] . " pt-0 ", |
|
1072 | - 'label_type' => $args['label_type'], |
|
1073 | - 'label_col' => $args['label_col'] |
|
1074 | - ); |
|
1075 | - |
|
1076 | - $output = ''; |
|
1077 | - |
|
1078 | - |
|
1079 | - // label before |
|
1080 | - if ( ! empty( $args['label'] ) ) { |
|
1081 | - $output .= self::label( $label_args, 'radio' ); |
|
1082 | - } |
|
1083 | - |
|
1084 | - // maybe horizontal label |
|
1085 | - if ( $args['label_type'] == 'horizontal' ) { |
|
1086 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
1087 | - $output .= '<div class="' . $input_col . '">'; |
|
1088 | - } |
|
1089 | - |
|
1090 | - if ( ! empty( $args['options'] ) ) { |
|
1091 | - $count = 0; |
|
1092 | - foreach ( $args['options'] as $value => $label ) { |
|
1093 | - $option_args = $args; |
|
1094 | - $option_args['value'] = $value; |
|
1095 | - $option_args['label'] = $label; |
|
1096 | - $option_args['checked'] = $value == $args['value'] ? true : false; |
|
1097 | - $output .= self::radio_option( $option_args, $count ); |
|
1098 | - $count ++; |
|
1099 | - } |
|
1100 | - } |
|
1101 | - |
|
1102 | - // help text |
|
1103 | - $help_text = ! empty( $args['help_text'] ) ? AUI_Component_Helper::help_text( $args['help_text'] ) : ''; |
|
1104 | - $output .= $help_text; |
|
1105 | - |
|
1106 | - // maybe horizontal label |
|
1107 | - if ( $args['label_type'] == 'horizontal' ) { |
|
1108 | - $output .= '</div>'; |
|
1109 | - } |
|
1110 | - |
|
1111 | - // wrap |
|
1112 | - $wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group'; |
|
1113 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1114 | - $output = self::wrap( array( |
|
1115 | - 'content' => $output, |
|
1116 | - 'class' => $wrap_class, |
|
1117 | - 'element_require' => $args['element_require'], |
|
1118 | - 'argument_id' => $args['id'], |
|
1119 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
1120 | - ) ); |
|
1121 | - |
|
1122 | - |
|
1123 | - return $output; |
|
1124 | - } |
|
1125 | - |
|
1126 | - /** |
|
1127 | - * Build the component. |
|
1128 | - * |
|
1129 | - * @param array $args |
|
1130 | - * |
|
1131 | - * @return string The rendered component. |
|
1132 | - */ |
|
1133 | - public static function radio_option( $args = array(), $count = '' ) { |
|
1134 | - $defaults = array( |
|
1135 | - 'class' => '', |
|
1136 | - 'id' => '', |
|
1137 | - 'title' => '', |
|
1138 | - 'value' => '', |
|
1139 | - 'required' => false, |
|
1140 | - 'inline' => true, |
|
1141 | - 'label' => '', |
|
1142 | - 'options' => array(), |
|
1143 | - 'icon' => '', |
|
1144 | - 'no_wrap' => false, |
|
1145 | - 'extra_attributes' => array() // an array of extra attributes |
|
1146 | - ); |
|
1147 | - |
|
1148 | - /** |
|
1149 | - * Parse incoming $args into an array and merge it with $defaults |
|
1150 | - */ |
|
1151 | - $args = wp_parse_args( $args, $defaults ); |
|
1152 | - |
|
1153 | - $output = ''; |
|
1154 | - |
|
1155 | - // open/type |
|
1156 | - $output .= '<input type="radio"'; |
|
1157 | - |
|
1158 | - // class |
|
1159 | - $output .= ' class="form-check-input" '; |
|
1160 | - |
|
1161 | - // name |
|
1162 | - if ( ! empty( $args['name'] ) ) { |
|
1163 | - $output .= AUI_Component_Helper::name( $args['name'] ); |
|
1164 | - } |
|
1165 | - |
|
1166 | - // id |
|
1167 | - if ( ! empty( $args['id'] ) ) { |
|
1168 | - $output .= AUI_Component_Helper::id( $args['id'] . $count ); |
|
1169 | - } |
|
1170 | - |
|
1171 | - // title |
|
1172 | - if ( ! empty( $args['title'] ) ) { |
|
1173 | - $output .= AUI_Component_Helper::title( $args['title'] ); |
|
1174 | - } |
|
1175 | - |
|
1176 | - // value |
|
1177 | - if ( isset( $args['value'] ) ) { |
|
1178 | - $output .= AUI_Component_Helper::value( $args['value'] ); |
|
1179 | - } |
|
1180 | - |
|
1181 | - // checked, for radio and checkboxes |
|
1182 | - if ( $args['checked'] ) { |
|
1183 | - $output .= ' checked '; |
|
1184 | - } |
|
1185 | - |
|
1186 | - // data-attributes |
|
1187 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
1188 | - |
|
1189 | - // aria-attributes |
|
1190 | - $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
1191 | - |
|
1192 | - // extra attributes |
|
1193 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
1194 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
1195 | - } |
|
1196 | - |
|
1197 | - // required |
|
1198 | - if ( ! empty( $args['required'] ) ) { |
|
1199 | - $output .= ' required '; |
|
1200 | - } |
|
1201 | - |
|
1202 | - // close opening tag |
|
1203 | - $output .= ' >'; |
|
1204 | - |
|
1205 | - // label |
|
1206 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
1207 | - } elseif ( ! empty( $args['label'] ) ) { |
|
1208 | - $output .= self::label( array( |
|
1209 | - 'title' => $args['label'], |
|
1210 | - 'for' => $args['id'] . $count, |
|
1211 | - 'class' => 'form-check-label' |
|
1212 | - ), 'radio' ); |
|
1213 | - } |
|
1214 | - |
|
1215 | - // wrap |
|
1216 | - if ( ! $args['no_wrap'] ) { |
|
1217 | - $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check'; |
|
1218 | - |
|
1219 | - // Unique wrap class |
|
1220 | - $uniq_class = 'fwrap'; |
|
1221 | - if ( ! empty( $args['name'] ) ) { |
|
1222 | - $uniq_class .= '-' . $args['name']; |
|
1223 | - } else if ( ! empty( $args['id'] ) ) { |
|
1224 | - $uniq_class .= '-' . $args['id']; |
|
1225 | - } |
|
1226 | - |
|
1227 | - if ( isset( $args['value'] ) || $args['value'] !== "" ) { |
|
1228 | - $uniq_class .= '-' . $args['value']; |
|
1229 | - } else { |
|
1230 | - $uniq_class .= '-' . $count; |
|
1231 | - } |
|
1232 | - $wrap_class .= ' ' . sanitize_html_class( $uniq_class ); |
|
1233 | - |
|
1234 | - $output = self::wrap( array( |
|
1235 | - 'content' => $output, |
|
1236 | - 'class' => $wrap_class |
|
1237 | - ) ); |
|
1238 | - } |
|
1239 | - |
|
1240 | - return $output; |
|
1241 | - } |
|
1008 | + // wrap |
|
1009 | + if ( ! $args['no_wrap'] ) { |
|
1010 | + $wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group'; |
|
1011 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1012 | + $output = self::wrap( array( |
|
1013 | + 'content' => $output, |
|
1014 | + 'class' => $wrap_class, |
|
1015 | + 'element_require' => $args['element_require'], |
|
1016 | + 'argument_id' => $args['id'], |
|
1017 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
1018 | + ) ); |
|
1019 | + } |
|
1020 | + |
|
1021 | + |
|
1022 | + return $output; |
|
1023 | + } |
|
1024 | + |
|
1025 | + /** |
|
1026 | + * Build the component. |
|
1027 | + * |
|
1028 | + * @param array $args |
|
1029 | + * |
|
1030 | + * @return string The rendered component. |
|
1031 | + */ |
|
1032 | + public static function radio( $args = array() ) { |
|
1033 | + $defaults = array( |
|
1034 | + 'class' => '', |
|
1035 | + 'wrap_class' => '', |
|
1036 | + 'id' => '', |
|
1037 | + 'title' => '', |
|
1038 | + 'horizontal' => false, |
|
1039 | + // sets the lable horizontal |
|
1040 | + 'value' => '', |
|
1041 | + 'label' => '', |
|
1042 | + 'label_class' => '', |
|
1043 | + 'label_type' => '', |
|
1044 | + 'label_col' => '', |
|
1045 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
1046 | + 'help_text' => '', |
|
1047 | + 'inline' => true, |
|
1048 | + 'required' => false, |
|
1049 | + 'options' => array(), |
|
1050 | + 'icon' => '', |
|
1051 | + 'no_wrap' => false, |
|
1052 | + 'element_require' => '', |
|
1053 | + // [%element_id%] == "1" |
|
1054 | + 'extra_attributes' => array(), |
|
1055 | + // an array of extra attributes |
|
1056 | + 'wrap_attributes' => array() |
|
1057 | + ); |
|
1058 | + |
|
1059 | + /** |
|
1060 | + * Parse incoming $args into an array and merge it with $defaults |
|
1061 | + */ |
|
1062 | + $args = wp_parse_args( $args, $defaults ); |
|
1063 | + |
|
1064 | + // for now lets use horizontal for floating |
|
1065 | + if ( $args['label_type'] == 'floating' ) { |
|
1066 | + $args['label_type'] = 'horizontal'; |
|
1067 | + } |
|
1068 | + |
|
1069 | + $label_args = array( |
|
1070 | + 'title' => $args['label'], |
|
1071 | + 'class' => $args['label_class'] . " pt-0 ", |
|
1072 | + 'label_type' => $args['label_type'], |
|
1073 | + 'label_col' => $args['label_col'] |
|
1074 | + ); |
|
1075 | + |
|
1076 | + $output = ''; |
|
1077 | + |
|
1078 | + |
|
1079 | + // label before |
|
1080 | + if ( ! empty( $args['label'] ) ) { |
|
1081 | + $output .= self::label( $label_args, 'radio' ); |
|
1082 | + } |
|
1083 | + |
|
1084 | + // maybe horizontal label |
|
1085 | + if ( $args['label_type'] == 'horizontal' ) { |
|
1086 | + $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
1087 | + $output .= '<div class="' . $input_col . '">'; |
|
1088 | + } |
|
1089 | + |
|
1090 | + if ( ! empty( $args['options'] ) ) { |
|
1091 | + $count = 0; |
|
1092 | + foreach ( $args['options'] as $value => $label ) { |
|
1093 | + $option_args = $args; |
|
1094 | + $option_args['value'] = $value; |
|
1095 | + $option_args['label'] = $label; |
|
1096 | + $option_args['checked'] = $value == $args['value'] ? true : false; |
|
1097 | + $output .= self::radio_option( $option_args, $count ); |
|
1098 | + $count ++; |
|
1099 | + } |
|
1100 | + } |
|
1101 | + |
|
1102 | + // help text |
|
1103 | + $help_text = ! empty( $args['help_text'] ) ? AUI_Component_Helper::help_text( $args['help_text'] ) : ''; |
|
1104 | + $output .= $help_text; |
|
1105 | + |
|
1106 | + // maybe horizontal label |
|
1107 | + if ( $args['label_type'] == 'horizontal' ) { |
|
1108 | + $output .= '</div>'; |
|
1109 | + } |
|
1110 | + |
|
1111 | + // wrap |
|
1112 | + $wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group'; |
|
1113 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1114 | + $output = self::wrap( array( |
|
1115 | + 'content' => $output, |
|
1116 | + 'class' => $wrap_class, |
|
1117 | + 'element_require' => $args['element_require'], |
|
1118 | + 'argument_id' => $args['id'], |
|
1119 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
1120 | + ) ); |
|
1121 | + |
|
1122 | + |
|
1123 | + return $output; |
|
1124 | + } |
|
1125 | + |
|
1126 | + /** |
|
1127 | + * Build the component. |
|
1128 | + * |
|
1129 | + * @param array $args |
|
1130 | + * |
|
1131 | + * @return string The rendered component. |
|
1132 | + */ |
|
1133 | + public static function radio_option( $args = array(), $count = '' ) { |
|
1134 | + $defaults = array( |
|
1135 | + 'class' => '', |
|
1136 | + 'id' => '', |
|
1137 | + 'title' => '', |
|
1138 | + 'value' => '', |
|
1139 | + 'required' => false, |
|
1140 | + 'inline' => true, |
|
1141 | + 'label' => '', |
|
1142 | + 'options' => array(), |
|
1143 | + 'icon' => '', |
|
1144 | + 'no_wrap' => false, |
|
1145 | + 'extra_attributes' => array() // an array of extra attributes |
|
1146 | + ); |
|
1147 | + |
|
1148 | + /** |
|
1149 | + * Parse incoming $args into an array and merge it with $defaults |
|
1150 | + */ |
|
1151 | + $args = wp_parse_args( $args, $defaults ); |
|
1152 | + |
|
1153 | + $output = ''; |
|
1154 | + |
|
1155 | + // open/type |
|
1156 | + $output .= '<input type="radio"'; |
|
1157 | + |
|
1158 | + // class |
|
1159 | + $output .= ' class="form-check-input" '; |
|
1160 | + |
|
1161 | + // name |
|
1162 | + if ( ! empty( $args['name'] ) ) { |
|
1163 | + $output .= AUI_Component_Helper::name( $args['name'] ); |
|
1164 | + } |
|
1165 | + |
|
1166 | + // id |
|
1167 | + if ( ! empty( $args['id'] ) ) { |
|
1168 | + $output .= AUI_Component_Helper::id( $args['id'] . $count ); |
|
1169 | + } |
|
1170 | + |
|
1171 | + // title |
|
1172 | + if ( ! empty( $args['title'] ) ) { |
|
1173 | + $output .= AUI_Component_Helper::title( $args['title'] ); |
|
1174 | + } |
|
1175 | + |
|
1176 | + // value |
|
1177 | + if ( isset( $args['value'] ) ) { |
|
1178 | + $output .= AUI_Component_Helper::value( $args['value'] ); |
|
1179 | + } |
|
1180 | + |
|
1181 | + // checked, for radio and checkboxes |
|
1182 | + if ( $args['checked'] ) { |
|
1183 | + $output .= ' checked '; |
|
1184 | + } |
|
1185 | + |
|
1186 | + // data-attributes |
|
1187 | + $output .= AUI_Component_Helper::data_attributes( $args ); |
|
1188 | + |
|
1189 | + // aria-attributes |
|
1190 | + $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
1191 | + |
|
1192 | + // extra attributes |
|
1193 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
1194 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
1195 | + } |
|
1196 | + |
|
1197 | + // required |
|
1198 | + if ( ! empty( $args['required'] ) ) { |
|
1199 | + $output .= ' required '; |
|
1200 | + } |
|
1201 | + |
|
1202 | + // close opening tag |
|
1203 | + $output .= ' >'; |
|
1204 | + |
|
1205 | + // label |
|
1206 | + if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
1207 | + } elseif ( ! empty( $args['label'] ) ) { |
|
1208 | + $output .= self::label( array( |
|
1209 | + 'title' => $args['label'], |
|
1210 | + 'for' => $args['id'] . $count, |
|
1211 | + 'class' => 'form-check-label' |
|
1212 | + ), 'radio' ); |
|
1213 | + } |
|
1214 | + |
|
1215 | + // wrap |
|
1216 | + if ( ! $args['no_wrap'] ) { |
|
1217 | + $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check'; |
|
1218 | + |
|
1219 | + // Unique wrap class |
|
1220 | + $uniq_class = 'fwrap'; |
|
1221 | + if ( ! empty( $args['name'] ) ) { |
|
1222 | + $uniq_class .= '-' . $args['name']; |
|
1223 | + } else if ( ! empty( $args['id'] ) ) { |
|
1224 | + $uniq_class .= '-' . $args['id']; |
|
1225 | + } |
|
1226 | + |
|
1227 | + if ( isset( $args['value'] ) || $args['value'] !== "" ) { |
|
1228 | + $uniq_class .= '-' . $args['value']; |
|
1229 | + } else { |
|
1230 | + $uniq_class .= '-' . $count; |
|
1231 | + } |
|
1232 | + $wrap_class .= ' ' . sanitize_html_class( $uniq_class ); |
|
1233 | + |
|
1234 | + $output = self::wrap( array( |
|
1235 | + 'content' => $output, |
|
1236 | + 'class' => $wrap_class |
|
1237 | + ) ); |
|
1238 | + } |
|
1239 | + |
|
1240 | + return $output; |
|
1241 | + } |
|
1242 | 1242 | |
1243 | 1243 | } |
1244 | 1244 | \ No newline at end of file |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( ! defined( 'ABSPATH' ) ) { |
|
3 | +if (!defined('ABSPATH')) { |
|
4 | 4 | exit; // Exit if accessed directly |
5 | 5 | } |
6 | 6 | |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | * |
19 | 19 | * @return string The rendered component. |
20 | 20 | */ |
21 | - public static function input( $args = array() ) { |
|
21 | + public static function input($args = array()) { |
|
22 | 22 | $defaults = array( |
23 | 23 | 'type' => 'text', |
24 | 24 | 'name' => '', |
@@ -65,13 +65,13 @@ discard block |
||
65 | 65 | /** |
66 | 66 | * Parse incoming $args into an array and merge it with $defaults |
67 | 67 | */ |
68 | - $args = wp_parse_args( $args, $defaults ); |
|
68 | + $args = wp_parse_args($args, $defaults); |
|
69 | 69 | $output = ''; |
70 | - if ( ! empty( $args['type'] ) ) { |
|
70 | + if (!empty($args['type'])) { |
|
71 | 71 | // hidden label option needs to be empty |
72 | 72 | $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
73 | 73 | |
74 | - $type = sanitize_html_class( $args['type'] ); |
|
74 | + $type = sanitize_html_class($args['type']); |
|
75 | 75 | |
76 | 76 | $help_text = ''; |
77 | 77 | $label = ''; |
@@ -85,17 +85,17 @@ discard block |
||
85 | 85 | ); |
86 | 86 | |
87 | 87 | // floating labels need label after |
88 | - if ( $args['label_type'] == 'floating' && $type != 'checkbox' ) { |
|
88 | + if ($args['label_type'] == 'floating' && $type != 'checkbox') { |
|
89 | 89 | $label_after = true; |
90 | 90 | $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
91 | 91 | } |
92 | 92 | |
93 | 93 | // size |
94 | 94 | $size = ''; |
95 | - if ( $args['size'] == 'lg' || $args['size'] == 'large' ) { |
|
95 | + if ($args['size'] == 'lg' || $args['size'] == 'large') { |
|
96 | 96 | $size = 'lg'; |
97 | 97 | $args['class'] .= ' form-control-lg'; |
98 | - }elseif ( $args['size'] == 'sm' || $args['size'] == 'small' ) { |
|
98 | + }elseif ($args['size'] == 'sm' || $args['size'] == 'small') { |
|
99 | 99 | $size = 'sm'; |
100 | 100 | $args['class'] .= ' form-control-sm'; |
101 | 101 | } |
@@ -104,21 +104,21 @@ discard block |
||
104 | 104 | $clear_function = 'jQuery(this).parent().parent().find(\'input\').val(\'\');'; |
105 | 105 | |
106 | 106 | // Some special sauce for files |
107 | - if ( $type == 'file' ) { |
|
107 | + if ($type == 'file') { |
|
108 | 108 | $label_after = true; // if type file we need the label after |
109 | 109 | $args['class'] .= ' custom-file-input '; |
110 | - } elseif ( $type == 'checkbox' ) { |
|
110 | + } elseif ($type == 'checkbox') { |
|
111 | 111 | $label_after = true; // if type file we need the label after |
112 | 112 | $args['class'] .= ' custom-control-input '; |
113 | - } elseif ( $type == 'datepicker' || $type == 'timepicker' ) { |
|
113 | + } elseif ($type == 'datepicker' || $type == 'timepicker') { |
|
114 | 114 | $type = 'text'; |
115 | 115 | $args['class'] .= ' bg-initial '; // @todo not sure why we have this? |
116 | - $clear_function .= "jQuery(this).parent().parent().find('input[name=\'" . esc_attr( $args['name'] ) . "\']').trigger('change');"; |
|
116 | + $clear_function .= "jQuery(this).parent().parent().find('input[name=\'" . esc_attr($args['name']) . "\']').trigger('change');"; |
|
117 | 117 | |
118 | 118 | $args['extra_attributes']['data-aui-init'] = 'flatpickr'; |
119 | 119 | |
120 | 120 | // set a way to clear field if empty |
121 | - if ( $args['input_group_right'] === '' && $args['clear_icon'] !== false ) { |
|
121 | + if ($args['input_group_right'] === '' && $args['clear_icon'] !== false) { |
|
122 | 122 | $args['input_group_right_inside'] = true; |
123 | 123 | $args['clear_icon'] = true; |
124 | 124 | } |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | // enqueue the script |
127 | 127 | $aui_settings = AyeCode_UI_Settings::instance(); |
128 | 128 | $aui_settings->enqueue_flatpickr(); |
129 | - } elseif ( $type == 'iconpicker' ) { |
|
129 | + } elseif ($type == 'iconpicker') { |
|
130 | 130 | $type = 'text'; |
131 | 131 | //$args['class'] .= ' aui-flatpickr bg-initial '; |
132 | 132 | // $args['class'] .= ' bg-initial '; |
@@ -141,103 +141,103 @@ discard block |
||
141 | 141 | $aui_settings->enqueue_iconpicker(); |
142 | 142 | } |
143 | 143 | |
144 | - if ( $type == 'checkbox' && !empty($args['name'] ) && strpos($args['name'], '[') === false ) { |
|
145 | - $output .= '<input type="hidden" name="' . esc_attr( $args['name'] ) . '" value="0" />'; |
|
144 | + if ($type == 'checkbox' && !empty($args['name']) && strpos($args['name'], '[') === false) { |
|
145 | + $output .= '<input type="hidden" name="' . esc_attr($args['name']) . '" value="0" />'; |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | // allow clear icon |
149 | - if ( $args['input_group_right'] === '' && $args['clear_icon'] ) { |
|
150 | - $font_size = $size == 'sm' ? '1.3' : ( $size == 'lg' ? '1.65' : '1.5' ); |
|
149 | + if ($args['input_group_right'] === '' && $args['clear_icon']) { |
|
150 | + $font_size = $size == 'sm' ? '1.3' : ($size == 'lg' ? '1.65' : '1.5'); |
|
151 | 151 | $args['input_group_right_inside'] = true; |
152 | - $args['input_group_right'] = '<span class="input-group-text aui-clear-input c-pointer bg-initial border-0 px-2 d-none" onclick="' . $clear_function . '"><span style="font-size: '.$font_size.'rem" aria-hidden="true" class="close">×</span></span>'; |
|
152 | + $args['input_group_right'] = '<span class="input-group-text aui-clear-input c-pointer bg-initial border-0 px-2 d-none" onclick="' . $clear_function . '"><span style="font-size: ' . $font_size . 'rem" aria-hidden="true" class="close">×</span></span>'; |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | // open/type |
156 | 156 | $output .= '<input type="' . $type . '" '; |
157 | 157 | |
158 | 158 | // name |
159 | - if ( ! empty( $args['name'] ) ) { |
|
160 | - $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
159 | + if (!empty($args['name'])) { |
|
160 | + $output .= ' name="' . esc_attr($args['name']) . '" '; |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | // id |
164 | - if ( ! empty( $args['id'] ) ) { |
|
165 | - $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
164 | + if (!empty($args['id'])) { |
|
165 | + $output .= ' id="' . sanitize_html_class($args['id']) . '" '; |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | // placeholder |
169 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
170 | - $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
169 | + if (isset($args['placeholder']) && '' != $args['placeholder']) { |
|
170 | + $output .= ' placeholder="' . esc_attr($args['placeholder']) . '" '; |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | // title |
174 | - if ( ! empty( $args['title'] ) ) { |
|
175 | - $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
174 | + if (!empty($args['title'])) { |
|
175 | + $output .= ' title="' . esc_attr($args['title']) . '" '; |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | // value |
179 | - if ( ! empty( $args['value'] ) ) { |
|
180 | - $output .= AUI_Component_Helper::value( $args['value'] ); |
|
179 | + if (!empty($args['value'])) { |
|
180 | + $output .= AUI_Component_Helper::value($args['value']); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | // checked, for radio and checkboxes |
184 | - if ( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ) { |
|
184 | + if (($type == 'checkbox' || $type == 'radio') && $args['checked']) { |
|
185 | 185 | $output .= ' checked '; |
186 | 186 | } |
187 | 187 | |
188 | 188 | // validation text |
189 | - if ( ! empty( $args['validation_text'] ) ) { |
|
190 | - $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" '; |
|
189 | + if (!empty($args['validation_text'])) { |
|
190 | + $output .= ' oninvalid="setCustomValidity(\'' . esc_attr($args['validation_text']) . '\')" '; |
|
191 | 191 | $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
192 | 192 | } |
193 | 193 | |
194 | 194 | // validation_pattern |
195 | - if ( ! empty( $args['validation_pattern'] ) ) { |
|
196 | - $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
195 | + if (!empty($args['validation_pattern'])) { |
|
196 | + $output .= ' pattern="' . esc_attr($args['validation_pattern']) . '" '; |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | // step (for numbers) |
200 | - if ( ! empty( $args['step'] ) ) { |
|
200 | + if (!empty($args['step'])) { |
|
201 | 201 | $output .= ' step="' . $args['step'] . '" '; |
202 | 202 | } |
203 | 203 | |
204 | 204 | // required |
205 | - if ( ! empty( $args['required'] ) ) { |
|
205 | + if (!empty($args['required'])) { |
|
206 | 206 | $output .= ' required '; |
207 | 207 | } |
208 | 208 | |
209 | 209 | // class |
210 | - $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
210 | + $class = !empty($args['class']) ? AUI_Component_Helper::esc_classes($args['class']) : ''; |
|
211 | 211 | $output .= ' class="form-control ' . $class . '" '; |
212 | 212 | |
213 | 213 | // data-attributes |
214 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
214 | + $output .= AUI_Component_Helper::data_attributes($args); |
|
215 | 215 | |
216 | 216 | // extra attributes |
217 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
218 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
217 | + if (!empty($args['extra_attributes'])) { |
|
218 | + $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | // close |
222 | 222 | $output .= ' >'; |
223 | 223 | |
224 | 224 | // help text |
225 | - if ( ! empty( $args['help_text'] ) ) { |
|
226 | - $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
225 | + if (!empty($args['help_text'])) { |
|
226 | + $help_text = AUI_Component_Helper::help_text($args['help_text']); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | // label |
230 | - if ( ! empty( $args['label'] ) ) { |
|
230 | + if (!empty($args['label'])) { |
|
231 | 231 | $label_base_class = ''; |
232 | - if ( $type == 'file' ) { |
|
232 | + if ($type == 'file') { |
|
233 | 233 | $label_base_class = ' custom-file-label'; |
234 | - } elseif ( $type == 'checkbox' ) { |
|
235 | - if ( ! empty( $args['label_force_left'] ) ) { |
|
236 | - $label_args['title'] = wp_kses_post( $args['help_text'] ); |
|
234 | + } elseif ($type == 'checkbox') { |
|
235 | + if (!empty($args['label_force_left'])) { |
|
236 | + $label_args['title'] = wp_kses_post($args['help_text']); |
|
237 | 237 | $help_text = ''; |
238 | 238 | //$label_args['class'] .= ' d-inline '; |
239 | 239 | $args['wrap_class'] .= ' align-items-center '; |
240 | - }else{ |
|
240 | + } else { |
|
241 | 241 | |
242 | 242 | } |
243 | 243 | |
@@ -245,45 +245,45 @@ discard block |
||
245 | 245 | } |
246 | 246 | $label_args['class'] .= $label_base_class; |
247 | 247 | $temp_label_args = $label_args; |
248 | - if(! empty( $args['label_force_left'] )){$temp_label_args['class'] = $label_base_class." text-muted";} |
|
249 | - $label = self::label( $temp_label_args, $type ); |
|
248 | + if (!empty($args['label_force_left'])) {$temp_label_args['class'] = $label_base_class . " text-muted"; } |
|
249 | + $label = self::label($temp_label_args, $type); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | |
253 | 253 | |
254 | 254 | |
255 | 255 | // set help text in the correct position |
256 | - if ( $label_after ) { |
|
256 | + if ($label_after) { |
|
257 | 257 | $output .= $label . $help_text; |
258 | 258 | } |
259 | 259 | |
260 | 260 | // some input types need a separate wrap |
261 | - if ( $type == 'file' ) { |
|
262 | - $output = self::wrap( array( |
|
261 | + if ($type == 'file') { |
|
262 | + $output = self::wrap(array( |
|
263 | 263 | 'content' => $output, |
264 | 264 | 'class' => 'form-group custom-file' |
265 | - ) ); |
|
266 | - } elseif ( $type == 'checkbox' ) { |
|
265 | + )); |
|
266 | + } elseif ($type == 'checkbox') { |
|
267 | 267 | |
268 | 268 | $label_args['title'] = $args['label']; |
269 | - $label_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ); |
|
270 | - $label = !empty( $args['label_force_left'] ) ? self::label( $label_args, 'cb' ) : '<div class="' . $label_col . ' col-form-label"></div>'; |
|
271 | - $switch_size_class = $args['switch'] && !is_bool( $args['switch'] ) ? ' custom-switch-'.esc_attr( $args['switch'] ) : ''; |
|
272 | - $wrap_class = $args['switch'] ? 'custom-switch'.$switch_size_class : 'custom-checkbox'; |
|
273 | - if ( ! empty( $args['label_force_left'] ) ) { |
|
269 | + $label_col = AUI_Component_Helper::get_column_class($args['label_col'], 'label'); |
|
270 | + $label = !empty($args['label_force_left']) ? self::label($label_args, 'cb') : '<div class="' . $label_col . ' col-form-label"></div>'; |
|
271 | + $switch_size_class = $args['switch'] && !is_bool($args['switch']) ? ' custom-switch-' . esc_attr($args['switch']) : ''; |
|
272 | + $wrap_class = $args['switch'] ? 'custom-switch' . $switch_size_class : 'custom-checkbox'; |
|
273 | + if (!empty($args['label_force_left'])) { |
|
274 | 274 | $wrap_class .= ' d-flex align-content-center'; |
275 | - $label = str_replace("custom-control-label","", self::label( $label_args, 'cb' ) ); |
|
275 | + $label = str_replace("custom-control-label", "", self::label($label_args, 'cb')); |
|
276 | 276 | } |
277 | - $output = self::wrap( array( |
|
277 | + $output = self::wrap(array( |
|
278 | 278 | 'content' => $output, |
279 | 279 | 'class' => 'custom-control ' . $wrap_class |
280 | - ) ); |
|
280 | + )); |
|
281 | 281 | |
282 | - if ( $args['label_type'] == 'horizontal' ) { |
|
283 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
282 | + if ($args['label_type'] == 'horizontal') { |
|
283 | + $input_col = AUI_Component_Helper::get_column_class($args['label_col'], 'input'); |
|
284 | 284 | $output = $label . '<div class="' . $input_col . '">' . $output . '</div>'; |
285 | 285 | } |
286 | - } elseif ( $type == 'password' && $args['password_toggle'] && ! $args['input_group_right'] ) { |
|
286 | + } elseif ($type == 'password' && $args['password_toggle'] && !$args['input_group_right']) { |
|
287 | 287 | |
288 | 288 | |
289 | 289 | // allow password field to toggle view |
@@ -297,65 +297,65 @@ discard block |
||
297 | 297 | } |
298 | 298 | |
299 | 299 | // input group wraps |
300 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
301 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
300 | + if ($args['input_group_left'] || $args['input_group_right']) { |
|
301 | + $w100 = strpos($args['class'], 'w-100') !== false ? ' w-100' : ''; |
|
302 | 302 | $group_size = $size == 'lg' ? ' input-group-lg' : ''; |
303 | 303 | $group_size = !$group_size && $size == 'sm' ? ' input-group-sm' : $group_size; |
304 | 304 | |
305 | - if ( $args['input_group_left'] ) { |
|
306 | - $output = self::wrap( array( |
|
305 | + if ($args['input_group_left']) { |
|
306 | + $output = self::wrap(array( |
|
307 | 307 | 'content' => $output, |
308 | 308 | 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
309 | 309 | 'input_group_left' => $args['input_group_left'], |
310 | 310 | 'input_group_left_inside' => $args['input_group_left_inside'] |
311 | - ) ); |
|
311 | + )); |
|
312 | 312 | } |
313 | - if ( $args['input_group_right'] ) { |
|
314 | - $output = self::wrap( array( |
|
313 | + if ($args['input_group_right']) { |
|
314 | + $output = self::wrap(array( |
|
315 | 315 | 'content' => $output, |
316 | 316 | 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
317 | 317 | 'input_group_right' => $args['input_group_right'], |
318 | 318 | 'input_group_right_inside' => $args['input_group_right_inside'] |
319 | - ) ); |
|
319 | + )); |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | } |
323 | 323 | |
324 | - if ( ! $label_after ) { |
|
324 | + if (!$label_after) { |
|
325 | 325 | $output .= $help_text; |
326 | 326 | } |
327 | 327 | |
328 | 328 | |
329 | - if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
330 | - $output = self::wrap( array( |
|
329 | + if ($args['label_type'] == 'horizontal' && $type != 'checkbox') { |
|
330 | + $output = self::wrap(array( |
|
331 | 331 | 'content' => $output, |
332 | - 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
333 | - ) ); |
|
332 | + 'class' => AUI_Component_Helper::get_column_class($args['label_col'], 'input') |
|
333 | + )); |
|
334 | 334 | } |
335 | 335 | |
336 | - if ( ! $label_after ) { |
|
336 | + if (!$label_after) { |
|
337 | 337 | $output = $label . $output; |
338 | 338 | } |
339 | 339 | |
340 | 340 | // wrap |
341 | - if ( ! $args['no_wrap'] ) { |
|
341 | + if (!$args['no_wrap']) { |
|
342 | 342 | $form_group_class = $args['label_type'] == 'floating' && $type != 'checkbox' ? 'form-label-group' : 'form-group'; |
343 | 343 | $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
344 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
345 | - $output = self::wrap( array( |
|
344 | + $wrap_class = !empty($args['wrap_class']) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
345 | + $output = self::wrap(array( |
|
346 | 346 | 'content' => $output, |
347 | 347 | 'class' => $wrap_class, |
348 | 348 | 'element_require' => $args['element_require'], |
349 | 349 | 'argument_id' => $args['id'], |
350 | 350 | 'wrap_attributes' => $args['wrap_attributes'], |
351 | - ) ); |
|
351 | + )); |
|
352 | 352 | } |
353 | 353 | } |
354 | 354 | |
355 | 355 | return $output; |
356 | 356 | } |
357 | 357 | |
358 | - public static function label( $args = array(), $type = '' ) { |
|
358 | + public static function label($args = array(), $type = '') { |
|
359 | 359 | //<label for="exampleInputEmail1">Email address</label> |
360 | 360 | $defaults = array( |
361 | 361 | 'title' => 'div', |
@@ -368,33 +368,33 @@ discard block |
||
368 | 368 | /** |
369 | 369 | * Parse incoming $args into an array and merge it with $defaults |
370 | 370 | */ |
371 | - $args = wp_parse_args( $args, $defaults ); |
|
371 | + $args = wp_parse_args($args, $defaults); |
|
372 | 372 | $output = ''; |
373 | 373 | |
374 | - if ( $args['title'] ) { |
|
374 | + if ($args['title']) { |
|
375 | 375 | |
376 | 376 | // maybe hide labels //@todo set a global option for visibility class |
377 | - if ( $type == 'file' || $type == 'checkbox' || $type == 'radio' || ! empty( $args['label_type'] ) ) { |
|
377 | + if ($type == 'file' || $type == 'checkbox' || $type == 'radio' || !empty($args['label_type'])) { |
|
378 | 378 | $class = $args['class']; |
379 | 379 | } else { |
380 | 380 | $class = 'sr-only ' . $args['class']; |
381 | 381 | } |
382 | 382 | |
383 | 383 | // maybe horizontal |
384 | - if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
385 | - $class .= ' ' . AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ) . ' col-form-label'; |
|
384 | + if ($args['label_type'] == 'horizontal' && $type != 'checkbox') { |
|
385 | + $class .= ' ' . AUI_Component_Helper::get_column_class($args['label_col'], 'label') . ' col-form-label'; |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | // open |
389 | 389 | $output .= '<label '; |
390 | 390 | |
391 | 391 | // for |
392 | - if ( ! empty( $args['for'] ) ) { |
|
393 | - $output .= ' for="' . esc_attr( $args['for'] ) . '" '; |
|
392 | + if (!empty($args['for'])) { |
|
393 | + $output .= ' for="' . esc_attr($args['for']) . '" '; |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | // class |
397 | - $class = $class ? AUI_Component_Helper::esc_classes( $class ) : ''; |
|
397 | + $class = $class ? AUI_Component_Helper::esc_classes($class) : ''; |
|
398 | 398 | $output .= ' class="' . $class . '" '; |
399 | 399 | |
400 | 400 | // close |
@@ -402,8 +402,8 @@ discard block |
||
402 | 402 | |
403 | 403 | |
404 | 404 | // title, don't escape fully as can contain html |
405 | - if ( ! empty( $args['title'] ) ) { |
|
406 | - $output .= wp_kses_post( $args['title'] ); |
|
405 | + if (!empty($args['title'])) { |
|
406 | + $output .= wp_kses_post($args['title']); |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | // close wrap |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | * |
424 | 424 | * @return string |
425 | 425 | */ |
426 | - public static function wrap( $args = array() ) { |
|
426 | + public static function wrap($args = array()) { |
|
427 | 427 | $defaults = array( |
428 | 428 | 'type' => 'div', |
429 | 429 | 'class' => 'form-group', |
@@ -440,31 +440,31 @@ discard block |
||
440 | 440 | /** |
441 | 441 | * Parse incoming $args into an array and merge it with $defaults |
442 | 442 | */ |
443 | - $args = wp_parse_args( $args, $defaults ); |
|
443 | + $args = wp_parse_args($args, $defaults); |
|
444 | 444 | $output = ''; |
445 | - if ( $args['type'] ) { |
|
445 | + if ($args['type']) { |
|
446 | 446 | |
447 | 447 | // open |
448 | - $output .= '<' . sanitize_html_class( $args['type'] ); |
|
448 | + $output .= '<' . sanitize_html_class($args['type']); |
|
449 | 449 | |
450 | 450 | // element require |
451 | - if ( ! empty( $args['element_require'] ) ) { |
|
452 | - $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
451 | + if (!empty($args['element_require'])) { |
|
452 | + $output .= AUI_Component_Helper::element_require($args['element_require']); |
|
453 | 453 | $args['class'] .= " aui-conditional-field"; |
454 | 454 | } |
455 | 455 | |
456 | 456 | // argument_id |
457 | - if ( ! empty( $args['argument_id'] ) ) { |
|
458 | - $output .= ' data-argument="' . esc_attr( $args['argument_id'] ) . '"'; |
|
457 | + if (!empty($args['argument_id'])) { |
|
458 | + $output .= ' data-argument="' . esc_attr($args['argument_id']) . '"'; |
|
459 | 459 | } |
460 | 460 | |
461 | 461 | // class |
462 | - $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
462 | + $class = !empty($args['class']) ? AUI_Component_Helper::esc_classes($args['class']) : ''; |
|
463 | 463 | $output .= ' class="' . $class . '" '; |
464 | 464 | |
465 | 465 | // Attributes |
466 | - if ( ! empty( $args['wrap_attributes'] ) ) { |
|
467 | - $output .= AUI_Component_Helper::extra_attributes( $args['wrap_attributes'] ); |
|
466 | + if (!empty($args['wrap_attributes'])) { |
|
467 | + $output .= AUI_Component_Helper::extra_attributes($args['wrap_attributes']); |
|
468 | 468 | } |
469 | 469 | |
470 | 470 | // close wrap |
@@ -472,9 +472,9 @@ discard block |
||
472 | 472 | |
473 | 473 | |
474 | 474 | // Input group left |
475 | - if ( ! empty( $args['input_group_left'] ) ) { |
|
476 | - $position_class = ! empty( $args['input_group_left_inside'] ) ? 'position-absolute h-100' : ''; |
|
477 | - $input_group_left = strpos( $args['input_group_left'], '<' ) !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>'; |
|
475 | + if (!empty($args['input_group_left'])) { |
|
476 | + $position_class = !empty($args['input_group_left_inside']) ? 'position-absolute h-100' : ''; |
|
477 | + $input_group_left = strpos($args['input_group_left'], '<') !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>'; |
|
478 | 478 | $output .= '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>'; |
479 | 479 | } |
480 | 480 | |
@@ -482,15 +482,15 @@ discard block |
||
482 | 482 | $output .= $args['content']; |
483 | 483 | |
484 | 484 | // Input group right |
485 | - if ( ! empty( $args['input_group_right'] ) ) { |
|
486 | - $position_class = ! empty( $args['input_group_right_inside'] ) ? 'position-absolute h-100' : ''; |
|
487 | - $input_group_right = strpos( $args['input_group_right'], '<' ) !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>'; |
|
485 | + if (!empty($args['input_group_right'])) { |
|
486 | + $position_class = !empty($args['input_group_right_inside']) ? 'position-absolute h-100' : ''; |
|
487 | + $input_group_right = strpos($args['input_group_right'], '<') !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>'; |
|
488 | 488 | $output .= '<div class="input-group-append ' . $position_class . '" style="top:0;right:0;">' . $input_group_right . '</div>'; |
489 | 489 | } |
490 | 490 | |
491 | 491 | |
492 | 492 | // close wrap |
493 | - $output .= '</' . sanitize_html_class( $args['type'] ) . '>'; |
|
493 | + $output .= '</' . sanitize_html_class($args['type']) . '>'; |
|
494 | 494 | |
495 | 495 | |
496 | 496 | } else { |
@@ -507,7 +507,7 @@ discard block |
||
507 | 507 | * |
508 | 508 | * @return string The rendered component. |
509 | 509 | */ |
510 | - public static function textarea( $args = array() ) { |
|
510 | + public static function textarea($args = array()) { |
|
511 | 511 | $defaults = array( |
512 | 512 | 'name' => '', |
513 | 513 | 'class' => '', |
@@ -544,28 +544,28 @@ discard block |
||
544 | 544 | /** |
545 | 545 | * Parse incoming $args into an array and merge it with $defaults |
546 | 546 | */ |
547 | - $args = wp_parse_args( $args, $defaults ); |
|
547 | + $args = wp_parse_args($args, $defaults); |
|
548 | 548 | $output = ''; |
549 | 549 | |
550 | 550 | // hidden label option needs to be empty |
551 | 551 | $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
552 | 552 | |
553 | 553 | // floating labels don't work with wysiwyg so set it as top |
554 | - if ( $args['label_type'] == 'floating' && ! empty( $args['wysiwyg'] ) ) { |
|
554 | + if ($args['label_type'] == 'floating' && !empty($args['wysiwyg'])) { |
|
555 | 555 | $args['label_type'] = 'top'; |
556 | 556 | } |
557 | 557 | |
558 | 558 | $label_after = $args['label_after']; |
559 | 559 | |
560 | 560 | // floating labels need label after |
561 | - if ( $args['label_type'] == 'floating' && empty( $args['wysiwyg'] ) ) { |
|
561 | + if ($args['label_type'] == 'floating' && empty($args['wysiwyg'])) { |
|
562 | 562 | $label_after = true; |
563 | 563 | $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
564 | 564 | } |
565 | 565 | |
566 | 566 | // label |
567 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
568 | - } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
567 | + if (!empty($args['label']) && is_array($args['label'])) { |
|
568 | + } elseif (!empty($args['label']) && !$label_after) { |
|
569 | 569 | $label_args = array( |
570 | 570 | 'title' => $args['label'], |
571 | 571 | 'for' => $args['id'], |
@@ -573,34 +573,34 @@ discard block |
||
573 | 573 | 'label_type' => $args['label_type'], |
574 | 574 | 'label_col' => $args['label_col'] |
575 | 575 | ); |
576 | - $output .= self::label( $label_args ); |
|
576 | + $output .= self::label($label_args); |
|
577 | 577 | } |
578 | 578 | |
579 | 579 | // maybe horizontal label |
580 | - if ( $args['label_type'] == 'horizontal' ) { |
|
581 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
580 | + if ($args['label_type'] == 'horizontal') { |
|
581 | + $input_col = AUI_Component_Helper::get_column_class($args['label_col'], 'input'); |
|
582 | 582 | $output .= '<div class="' . $input_col . '">'; |
583 | 583 | } |
584 | 584 | |
585 | - if ( ! empty( $args['wysiwyg'] ) ) { |
|
585 | + if (!empty($args['wysiwyg'])) { |
|
586 | 586 | ob_start(); |
587 | 587 | $content = $args['value']; |
588 | - $editor_id = ! empty( $args['id'] ) ? sanitize_html_class( $args['id'] ) : 'wp_editor'; |
|
588 | + $editor_id = !empty($args['id']) ? sanitize_html_class($args['id']) : 'wp_editor'; |
|
589 | 589 | $settings = array( |
590 | - 'textarea_rows' => ! empty( absint( $args['rows'] ) ) ? absint( $args['rows'] ) : 4, |
|
590 | + 'textarea_rows' => !empty(absint($args['rows'])) ? absint($args['rows']) : 4, |
|
591 | 591 | 'quicktags' => false, |
592 | 592 | 'media_buttons' => false, |
593 | 593 | 'editor_class' => 'form-control', |
594 | - 'textarea_name' => ! empty( $args['name'] ) ? sanitize_html_class( $args['name'] ) : sanitize_html_class( $args['id'] ), |
|
594 | + 'textarea_name' => !empty($args['name']) ? sanitize_html_class($args['name']) : sanitize_html_class($args['id']), |
|
595 | 595 | 'teeny' => true, |
596 | 596 | ); |
597 | 597 | |
598 | 598 | // maybe set settings if array |
599 | - if ( is_array( $args['wysiwyg'] ) ) { |
|
600 | - $settings = wp_parse_args( $args['wysiwyg'], $settings ); |
|
599 | + if (is_array($args['wysiwyg'])) { |
|
600 | + $settings = wp_parse_args($args['wysiwyg'], $settings); |
|
601 | 601 | } |
602 | 602 | |
603 | - wp_editor( $content, $editor_id, $settings ); |
|
603 | + wp_editor($content, $editor_id, $settings); |
|
604 | 604 | $output .= ob_get_clean(); |
605 | 605 | } else { |
606 | 606 | |
@@ -608,65 +608,65 @@ discard block |
||
608 | 608 | $output .= '<textarea '; |
609 | 609 | |
610 | 610 | // name |
611 | - if ( ! empty( $args['name'] ) ) { |
|
612 | - $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
611 | + if (!empty($args['name'])) { |
|
612 | + $output .= ' name="' . esc_attr($args['name']) . '" '; |
|
613 | 613 | } |
614 | 614 | |
615 | 615 | // id |
616 | - if ( ! empty( $args['id'] ) ) { |
|
617 | - $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
616 | + if (!empty($args['id'])) { |
|
617 | + $output .= ' id="' . sanitize_html_class($args['id']) . '" '; |
|
618 | 618 | } |
619 | 619 | |
620 | 620 | // placeholder |
621 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
622 | - $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
621 | + if (isset($args['placeholder']) && '' != $args['placeholder']) { |
|
622 | + $output .= ' placeholder="' . esc_attr($args['placeholder']) . '" '; |
|
623 | 623 | } |
624 | 624 | |
625 | 625 | // title |
626 | - if ( ! empty( $args['title'] ) ) { |
|
627 | - $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
626 | + if (!empty($args['title'])) { |
|
627 | + $output .= ' title="' . esc_attr($args['title']) . '" '; |
|
628 | 628 | } |
629 | 629 | |
630 | 630 | // validation text |
631 | - if ( ! empty( $args['validation_text'] ) ) { |
|
632 | - $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" '; |
|
631 | + if (!empty($args['validation_text'])) { |
|
632 | + $output .= ' oninvalid="setCustomValidity(\'' . esc_attr($args['validation_text']) . '\')" '; |
|
633 | 633 | $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
634 | 634 | } |
635 | 635 | |
636 | 636 | // validation_pattern |
637 | - if ( ! empty( $args['validation_pattern'] ) ) { |
|
638 | - $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
637 | + if (!empty($args['validation_pattern'])) { |
|
638 | + $output .= ' pattern="' . esc_attr($args['validation_pattern']) . '" '; |
|
639 | 639 | } |
640 | 640 | |
641 | 641 | // required |
642 | - if ( ! empty( $args['required'] ) ) { |
|
642 | + if (!empty($args['required'])) { |
|
643 | 643 | $output .= ' required '; |
644 | 644 | } |
645 | 645 | |
646 | 646 | // rows |
647 | - if ( ! empty( $args['rows'] ) ) { |
|
648 | - $output .= ' rows="' . absint( $args['rows'] ) . '" '; |
|
647 | + if (!empty($args['rows'])) { |
|
648 | + $output .= ' rows="' . absint($args['rows']) . '" '; |
|
649 | 649 | } |
650 | 650 | |
651 | 651 | |
652 | 652 | // class |
653 | - $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
653 | + $class = !empty($args['class']) ? $args['class'] : ''; |
|
654 | 654 | $output .= ' class="form-control ' . $class . '" '; |
655 | 655 | |
656 | 656 | // extra attributes |
657 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
658 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
657 | + if (!empty($args['extra_attributes'])) { |
|
658 | + $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
659 | 659 | } |
660 | 660 | |
661 | 661 | // close tag |
662 | 662 | $output .= ' >'; |
663 | 663 | |
664 | 664 | // value |
665 | - if ( ! empty( $args['value'] ) ) { |
|
666 | - if ( ! empty( $args['allow_tags'] ) ) { |
|
667 | - $output .= AUI_Component_Helper::sanitize_html_field( $args['value'], $args ); // Sanitize HTML. |
|
665 | + if (!empty($args['value'])) { |
|
666 | + if (!empty($args['allow_tags'])) { |
|
667 | + $output .= AUI_Component_Helper::sanitize_html_field($args['value'], $args); // Sanitize HTML. |
|
668 | 668 | } else { |
669 | - $output .= AUI_Component_Helper::sanitize_textarea_field( $args['value'] ); |
|
669 | + $output .= AUI_Component_Helper::sanitize_textarea_field($args['value']); |
|
670 | 670 | } |
671 | 671 | } |
672 | 672 | |
@@ -675,23 +675,23 @@ discard block |
||
675 | 675 | |
676 | 676 | |
677 | 677 | // input group wraps |
678 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
679 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
680 | - if ( $args['input_group_left'] ) { |
|
681 | - $output = self::wrap( array( |
|
678 | + if ($args['input_group_left'] || $args['input_group_right']) { |
|
679 | + $w100 = strpos($args['class'], 'w-100') !== false ? ' w-100' : ''; |
|
680 | + if ($args['input_group_left']) { |
|
681 | + $output = self::wrap(array( |
|
682 | 682 | 'content' => $output, |
683 | 683 | 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
684 | 684 | 'input_group_left' => $args['input_group_left'], |
685 | 685 | 'input_group_left_inside' => $args['input_group_left_inside'] |
686 | - ) ); |
|
686 | + )); |
|
687 | 687 | } |
688 | - if ( $args['input_group_right'] ) { |
|
689 | - $output = self::wrap( array( |
|
688 | + if ($args['input_group_right']) { |
|
689 | + $output = self::wrap(array( |
|
690 | 690 | 'content' => $output, |
691 | 691 | 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
692 | 692 | 'input_group_right' => $args['input_group_right'], |
693 | 693 | 'input_group_right_inside' => $args['input_group_right_inside'] |
694 | - ) ); |
|
694 | + )); |
|
695 | 695 | } |
696 | 696 | |
697 | 697 | } |
@@ -699,7 +699,7 @@ discard block |
||
699 | 699 | |
700 | 700 | } |
701 | 701 | |
702 | - if ( ! empty( $args['label'] ) && $label_after ) { |
|
702 | + if (!empty($args['label']) && $label_after) { |
|
703 | 703 | $label_args = array( |
704 | 704 | 'title' => $args['label'], |
705 | 705 | 'for' => $args['id'], |
@@ -707,32 +707,32 @@ discard block |
||
707 | 707 | 'label_type' => $args['label_type'], |
708 | 708 | 'label_col' => $args['label_col'] |
709 | 709 | ); |
710 | - $output .= self::label( $label_args ); |
|
710 | + $output .= self::label($label_args); |
|
711 | 711 | } |
712 | 712 | |
713 | 713 | // help text |
714 | - if ( ! empty( $args['help_text'] ) ) { |
|
715 | - $output .= AUI_Component_Helper::help_text( $args['help_text'] ); |
|
714 | + if (!empty($args['help_text'])) { |
|
715 | + $output .= AUI_Component_Helper::help_text($args['help_text']); |
|
716 | 716 | } |
717 | 717 | |
718 | 718 | // maybe horizontal label |
719 | - if ( $args['label_type'] == 'horizontal' ) { |
|
719 | + if ($args['label_type'] == 'horizontal') { |
|
720 | 720 | $output .= '</div>'; |
721 | 721 | } |
722 | 722 | |
723 | 723 | |
724 | 724 | // wrap |
725 | - if ( ! $args['no_wrap'] ) { |
|
725 | + if (!$args['no_wrap']) { |
|
726 | 726 | $form_group_class = $args['label_type'] == 'floating' ? 'form-label-group' : 'form-group'; |
727 | 727 | $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
728 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
729 | - $output = self::wrap( array( |
|
728 | + $wrap_class = !empty($args['wrap_class']) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
729 | + $output = self::wrap(array( |
|
730 | 730 | 'content' => $output, |
731 | 731 | 'class' => $wrap_class, |
732 | 732 | 'element_require' => $args['element_require'], |
733 | 733 | 'argument_id' => $args['id'], |
734 | 734 | 'wrap_attributes' => $args['wrap_attributes'], |
735 | - ) ); |
|
735 | + )); |
|
736 | 736 | } |
737 | 737 | |
738 | 738 | |
@@ -746,7 +746,7 @@ discard block |
||
746 | 746 | * |
747 | 747 | * @return string The rendered component. |
748 | 748 | */ |
749 | - public static function select( $args = array() ) { |
|
749 | + public static function select($args = array()) { |
|
750 | 750 | $defaults = array( |
751 | 751 | 'class' => '', |
752 | 752 | 'wrap_class' => '', |
@@ -783,11 +783,11 @@ discard block |
||
783 | 783 | /** |
784 | 784 | * Parse incoming $args into an array and merge it with $defaults |
785 | 785 | */ |
786 | - $args = wp_parse_args( $args, $defaults ); |
|
786 | + $args = wp_parse_args($args, $defaults); |
|
787 | 787 | $output = ''; |
788 | 788 | |
789 | 789 | // for now lets hide floating labels |
790 | - if ( $args['label_type'] == 'floating' ) { |
|
790 | + if ($args['label_type'] == 'floating') { |
|
791 | 791 | $args['label_type'] = 'hidden'; |
792 | 792 | } |
793 | 793 | |
@@ -798,89 +798,89 @@ discard block |
||
798 | 798 | $label_after = $args['label_after']; |
799 | 799 | |
800 | 800 | // floating labels need label after |
801 | - if ( $args['label_type'] == 'floating' ) { |
|
801 | + if ($args['label_type'] == 'floating') { |
|
802 | 802 | $label_after = true; |
803 | 803 | $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
804 | 804 | } |
805 | 805 | |
806 | 806 | // Maybe setup select2 |
807 | 807 | $is_select2 = false; |
808 | - if ( ! empty( $args['select2'] ) ) { |
|
808 | + if (!empty($args['select2'])) { |
|
809 | 809 | $args['class'] .= ' aui-select2'; |
810 | 810 | $is_select2 = true; |
811 | - } elseif ( strpos( $args['class'], 'aui-select2' ) !== false ) { |
|
811 | + } elseif (strpos($args['class'], 'aui-select2') !== false) { |
|
812 | 812 | $is_select2 = true; |
813 | 813 | } |
814 | 814 | |
815 | 815 | // select2 tags |
816 | - if ( ! empty( $args['select2'] ) && $args['select2'] === 'tags' ) { // triple equals needed here for some reason |
|
816 | + if (!empty($args['select2']) && $args['select2'] === 'tags') { // triple equals needed here for some reason |
|
817 | 817 | $args['data-tags'] = 'true'; |
818 | 818 | $args['data-token-separators'] = "[',']"; |
819 | 819 | $args['multiple'] = true; |
820 | 820 | } |
821 | 821 | |
822 | 822 | // select2 placeholder |
823 | - if ( $is_select2 && isset( $args['placeholder'] ) && '' != $args['placeholder'] && empty( $args['data-placeholder'] ) ) { |
|
824 | - $args['data-placeholder'] = esc_attr( $args['placeholder'] ); |
|
825 | - $args['data-allow-clear'] = isset( $args['data-allow-clear'] ) ? (bool) $args['data-allow-clear'] : true; |
|
823 | + if ($is_select2 && isset($args['placeholder']) && '' != $args['placeholder'] && empty($args['data-placeholder'])) { |
|
824 | + $args['data-placeholder'] = esc_attr($args['placeholder']); |
|
825 | + $args['data-allow-clear'] = isset($args['data-allow-clear']) ? (bool) $args['data-allow-clear'] : true; |
|
826 | 826 | } |
827 | 827 | |
828 | 828 | // Set hidden input to save empty value for multiselect. |
829 | - if ( ! empty( $args['multiple'] ) && ! empty( $args['name'] ) ) { |
|
830 | - $output .= '<input type="hidden" ' . AUI_Component_Helper::name( $args['name'] ) . ' value="" data-ignore-rule/>'; |
|
829 | + if (!empty($args['multiple']) && !empty($args['name'])) { |
|
830 | + $output .= '<input type="hidden" ' . AUI_Component_Helper::name($args['name']) . ' value="" data-ignore-rule/>'; |
|
831 | 831 | } |
832 | 832 | |
833 | 833 | // open/type |
834 | 834 | $output .= '<select '; |
835 | 835 | |
836 | 836 | // style |
837 | - if ( $is_select2 && !($args['input_group_left'] || $args['input_group_right'])) { |
|
837 | + if ($is_select2 && !($args['input_group_left'] || $args['input_group_right'])) { |
|
838 | 838 | $output .= " style='width:100%;' "; |
839 | 839 | } |
840 | 840 | |
841 | 841 | // element require |
842 | - if ( ! empty( $args['element_require'] ) ) { |
|
843 | - $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
842 | + if (!empty($args['element_require'])) { |
|
843 | + $output .= AUI_Component_Helper::element_require($args['element_require']); |
|
844 | 844 | $args['class'] .= " aui-conditional-field"; |
845 | 845 | } |
846 | 846 | |
847 | 847 | // class |
848 | - $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
849 | - $output .= AUI_Component_Helper::class_attr( 'custom-select ' . $class ); |
|
848 | + $class = !empty($args['class']) ? $args['class'] : ''; |
|
849 | + $output .= AUI_Component_Helper::class_attr('custom-select ' . $class); |
|
850 | 850 | |
851 | 851 | // name |
852 | - if ( ! empty( $args['name'] ) ) { |
|
853 | - $output .= AUI_Component_Helper::name( $args['name'], $args['multiple'] ); |
|
852 | + if (!empty($args['name'])) { |
|
853 | + $output .= AUI_Component_Helper::name($args['name'], $args['multiple']); |
|
854 | 854 | } |
855 | 855 | |
856 | 856 | // id |
857 | - if ( ! empty( $args['id'] ) ) { |
|
858 | - $output .= AUI_Component_Helper::id( $args['id'] ); |
|
857 | + if (!empty($args['id'])) { |
|
858 | + $output .= AUI_Component_Helper::id($args['id']); |
|
859 | 859 | } |
860 | 860 | |
861 | 861 | // title |
862 | - if ( ! empty( $args['title'] ) ) { |
|
863 | - $output .= AUI_Component_Helper::title( $args['title'] ); |
|
862 | + if (!empty($args['title'])) { |
|
863 | + $output .= AUI_Component_Helper::title($args['title']); |
|
864 | 864 | } |
865 | 865 | |
866 | 866 | // data-attributes |
867 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
867 | + $output .= AUI_Component_Helper::data_attributes($args); |
|
868 | 868 | |
869 | 869 | // aria-attributes |
870 | - $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
870 | + $output .= AUI_Component_Helper::aria_attributes($args); |
|
871 | 871 | |
872 | 872 | // extra attributes |
873 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
874 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
873 | + if (!empty($args['extra_attributes'])) { |
|
874 | + $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
875 | 875 | } |
876 | 876 | |
877 | 877 | // required |
878 | - if ( ! empty( $args['required'] ) ) { |
|
878 | + if (!empty($args['required'])) { |
|
879 | 879 | $output .= ' required '; |
880 | 880 | } |
881 | 881 | |
882 | 882 | // multiple |
883 | - if ( ! empty( $args['multiple'] ) ) { |
|
883 | + if (!empty($args['multiple'])) { |
|
884 | 884 | $output .= ' multiple '; |
885 | 885 | } |
886 | 886 | |
@@ -888,50 +888,50 @@ discard block |
||
888 | 888 | $output .= ' >'; |
889 | 889 | |
890 | 890 | // placeholder |
891 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] && ! $is_select2 ) { |
|
892 | - $output .= '<option value="" disabled selected hidden>' . esc_attr( $args['placeholder'] ) . '</option>'; |
|
893 | - } elseif ( $is_select2 && ! empty( $args['placeholder'] ) ) { |
|
891 | + if (isset($args['placeholder']) && '' != $args['placeholder'] && !$is_select2) { |
|
892 | + $output .= '<option value="" disabled selected hidden>' . esc_attr($args['placeholder']) . '</option>'; |
|
893 | + } elseif ($is_select2 && !empty($args['placeholder'])) { |
|
894 | 894 | $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder |
895 | 895 | } |
896 | 896 | |
897 | 897 | // Options |
898 | - if ( ! empty( $args['options'] ) ) { |
|
898 | + if (!empty($args['options'])) { |
|
899 | 899 | |
900 | - if ( ! is_array( $args['options'] ) ) { |
|
900 | + if (!is_array($args['options'])) { |
|
901 | 901 | $output .= $args['options']; // not the preferred way but an option |
902 | 902 | } else { |
903 | - foreach ( $args['options'] as $val => $name ) { |
|
903 | + foreach ($args['options'] as $val => $name) { |
|
904 | 904 | $selected = ''; |
905 | - if ( is_array( $name ) ) { |
|
906 | - if ( isset( $name['optgroup'] ) && ( $name['optgroup'] == 'start' || $name['optgroup'] == 'end' ) ) { |
|
907 | - $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
905 | + if (is_array($name)) { |
|
906 | + if (isset($name['optgroup']) && ($name['optgroup'] == 'start' || $name['optgroup'] == 'end')) { |
|
907 | + $option_label = isset($name['label']) ? $name['label'] : ''; |
|
908 | 908 | |
909 | - $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>'; |
|
909 | + $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr($option_label) . '">' : '</optgroup>'; |
|
910 | 910 | } else { |
911 | - $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
912 | - $option_value = isset( $name['value'] ) ? $name['value'] : ''; |
|
913 | - $extra_attributes = !empty($name['extra_attributes']) ? AUI_Component_Helper::extra_attributes( $name['extra_attributes'] ) : ''; |
|
914 | - if ( ! empty( $args['multiple'] ) && ! empty( $args['value'] ) && is_array( $args['value'] ) ) { |
|
915 | - $selected = in_array( $option_value, stripslashes_deep( $args['value'] ) ) ? "selected" : ""; |
|
916 | - } elseif ( ! empty( $args['value'] ) ) { |
|
917 | - $selected = selected( $option_value, stripslashes_deep( $args['value'] ), false ); |
|
918 | - } elseif ( empty( $args['value'] ) && $args['value'] === $option_value ) { |
|
919 | - $selected = selected( $option_value, $args['value'], false ); |
|
911 | + $option_label = isset($name['label']) ? $name['label'] : ''; |
|
912 | + $option_value = isset($name['value']) ? $name['value'] : ''; |
|
913 | + $extra_attributes = !empty($name['extra_attributes']) ? AUI_Component_Helper::extra_attributes($name['extra_attributes']) : ''; |
|
914 | + if (!empty($args['multiple']) && !empty($args['value']) && is_array($args['value'])) { |
|
915 | + $selected = in_array($option_value, stripslashes_deep($args['value'])) ? "selected" : ""; |
|
916 | + } elseif (!empty($args['value'])) { |
|
917 | + $selected = selected($option_value, stripslashes_deep($args['value']), false); |
|
918 | + } elseif (empty($args['value']) && $args['value'] === $option_value) { |
|
919 | + $selected = selected($option_value, $args['value'], false); |
|
920 | 920 | } |
921 | 921 | |
922 | - $output .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . ' '.$extra_attributes .'>' . $option_label . '</option>'; |
|
922 | + $output .= '<option value="' . esc_attr($option_value) . '" ' . $selected . ' ' . $extra_attributes . '>' . $option_label . '</option>'; |
|
923 | 923 | } |
924 | 924 | } else { |
925 | - if ( ! empty( $args['value'] ) ) { |
|
926 | - if ( is_array( $args['value'] ) ) { |
|
927 | - $selected = in_array( $val, $args['value'] ) ? 'selected="selected"' : ''; |
|
928 | - } elseif ( ! empty( $args['value'] ) ) { |
|
929 | - $selected = selected( $args['value'], $val, false ); |
|
925 | + if (!empty($args['value'])) { |
|
926 | + if (is_array($args['value'])) { |
|
927 | + $selected = in_array($val, $args['value']) ? 'selected="selected"' : ''; |
|
928 | + } elseif (!empty($args['value'])) { |
|
929 | + $selected = selected($args['value'], $val, false); |
|
930 | 930 | } |
931 | - } elseif ( $args['value'] === $val ) { |
|
932 | - $selected = selected( $args['value'], $val, false ); |
|
931 | + } elseif ($args['value'] === $val) { |
|
932 | + $selected = selected($args['value'], $val, false); |
|
933 | 933 | } |
934 | - $output .= '<option value="' . esc_attr( $val ) . '" ' . $selected . '>' . esc_attr( $name ) . '</option>'; |
|
934 | + $output .= '<option value="' . esc_attr($val) . '" ' . $selected . '>' . esc_attr($name) . '</option>'; |
|
935 | 935 | } |
936 | 936 | } |
937 | 937 | } |
@@ -944,8 +944,8 @@ discard block |
||
944 | 944 | $label = ''; |
945 | 945 | $help_text = ''; |
946 | 946 | // label |
947 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
948 | - } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
947 | + if (!empty($args['label']) && is_array($args['label'])) { |
|
948 | + } elseif (!empty($args['label']) && !$label_after) { |
|
949 | 949 | $label_args = array( |
950 | 950 | 'title' => $args['label'], |
951 | 951 | 'for' => $args['id'], |
@@ -953,49 +953,49 @@ discard block |
||
953 | 953 | 'label_type' => $args['label_type'], |
954 | 954 | 'label_col' => $args['label_col'] |
955 | 955 | ); |
956 | - $label = self::label( $label_args ); |
|
956 | + $label = self::label($label_args); |
|
957 | 957 | } |
958 | 958 | |
959 | 959 | // help text |
960 | - if ( ! empty( $args['help_text'] ) ) { |
|
961 | - $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
960 | + if (!empty($args['help_text'])) { |
|
961 | + $help_text = AUI_Component_Helper::help_text($args['help_text']); |
|
962 | 962 | } |
963 | 963 | |
964 | 964 | // input group wraps |
965 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
966 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
967 | - if ( $args['input_group_left'] ) { |
|
968 | - $output = self::wrap( array( |
|
965 | + if ($args['input_group_left'] || $args['input_group_right']) { |
|
966 | + $w100 = strpos($args['class'], 'w-100') !== false ? ' w-100' : ''; |
|
967 | + if ($args['input_group_left']) { |
|
968 | + $output = self::wrap(array( |
|
969 | 969 | 'content' => $output, |
970 | 970 | 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
971 | 971 | 'input_group_left' => $args['input_group_left'], |
972 | 972 | 'input_group_left_inside' => $args['input_group_left_inside'] |
973 | - ) ); |
|
973 | + )); |
|
974 | 974 | } |
975 | - if ( $args['input_group_right'] ) { |
|
976 | - $output = self::wrap( array( |
|
975 | + if ($args['input_group_right']) { |
|
976 | + $output = self::wrap(array( |
|
977 | 977 | 'content' => $output, |
978 | 978 | 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
979 | 979 | 'input_group_right' => $args['input_group_right'], |
980 | 980 | 'input_group_right_inside' => $args['input_group_right_inside'] |
981 | - ) ); |
|
981 | + )); |
|
982 | 982 | } |
983 | 983 | |
984 | 984 | } |
985 | 985 | |
986 | - if ( ! $label_after ) { |
|
986 | + if (!$label_after) { |
|
987 | 987 | $output .= $help_text; |
988 | 988 | } |
989 | 989 | |
990 | 990 | |
991 | - if ( $args['label_type'] == 'horizontal' ) { |
|
992 | - $output = self::wrap( array( |
|
991 | + if ($args['label_type'] == 'horizontal') { |
|
992 | + $output = self::wrap(array( |
|
993 | 993 | 'content' => $output, |
994 | - 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
995 | - ) ); |
|
994 | + 'class' => AUI_Component_Helper::get_column_class($args['label_col'], 'input') |
|
995 | + )); |
|
996 | 996 | } |
997 | 997 | |
998 | - if ( ! $label_after ) { |
|
998 | + if (!$label_after) { |
|
999 | 999 | $output = $label . $output; |
1000 | 1000 | } |
1001 | 1001 | |
@@ -1006,16 +1006,16 @@ discard block |
||
1006 | 1006 | |
1007 | 1007 | |
1008 | 1008 | // wrap |
1009 | - if ( ! $args['no_wrap'] ) { |
|
1009 | + if (!$args['no_wrap']) { |
|
1010 | 1010 | $wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group'; |
1011 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1012 | - $output = self::wrap( array( |
|
1011 | + $wrap_class = !empty($args['wrap_class']) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1012 | + $output = self::wrap(array( |
|
1013 | 1013 | 'content' => $output, |
1014 | 1014 | 'class' => $wrap_class, |
1015 | 1015 | 'element_require' => $args['element_require'], |
1016 | 1016 | 'argument_id' => $args['id'], |
1017 | 1017 | 'wrap_attributes' => $args['wrap_attributes'], |
1018 | - ) ); |
|
1018 | + )); |
|
1019 | 1019 | } |
1020 | 1020 | |
1021 | 1021 | |
@@ -1029,7 +1029,7 @@ discard block |
||
1029 | 1029 | * |
1030 | 1030 | * @return string The rendered component. |
1031 | 1031 | */ |
1032 | - public static function radio( $args = array() ) { |
|
1032 | + public static function radio($args = array()) { |
|
1033 | 1033 | $defaults = array( |
1034 | 1034 | 'class' => '', |
1035 | 1035 | 'wrap_class' => '', |
@@ -1059,10 +1059,10 @@ discard block |
||
1059 | 1059 | /** |
1060 | 1060 | * Parse incoming $args into an array and merge it with $defaults |
1061 | 1061 | */ |
1062 | - $args = wp_parse_args( $args, $defaults ); |
|
1062 | + $args = wp_parse_args($args, $defaults); |
|
1063 | 1063 | |
1064 | 1064 | // for now lets use horizontal for floating |
1065 | - if ( $args['label_type'] == 'floating' ) { |
|
1065 | + if ($args['label_type'] == 'floating') { |
|
1066 | 1066 | $args['label_type'] = 'horizontal'; |
1067 | 1067 | } |
1068 | 1068 | |
@@ -1077,47 +1077,47 @@ discard block |
||
1077 | 1077 | |
1078 | 1078 | |
1079 | 1079 | // label before |
1080 | - if ( ! empty( $args['label'] ) ) { |
|
1081 | - $output .= self::label( $label_args, 'radio' ); |
|
1080 | + if (!empty($args['label'])) { |
|
1081 | + $output .= self::label($label_args, 'radio'); |
|
1082 | 1082 | } |
1083 | 1083 | |
1084 | 1084 | // maybe horizontal label |
1085 | - if ( $args['label_type'] == 'horizontal' ) { |
|
1086 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
1085 | + if ($args['label_type'] == 'horizontal') { |
|
1086 | + $input_col = AUI_Component_Helper::get_column_class($args['label_col'], 'input'); |
|
1087 | 1087 | $output .= '<div class="' . $input_col . '">'; |
1088 | 1088 | } |
1089 | 1089 | |
1090 | - if ( ! empty( $args['options'] ) ) { |
|
1090 | + if (!empty($args['options'])) { |
|
1091 | 1091 | $count = 0; |
1092 | - foreach ( $args['options'] as $value => $label ) { |
|
1092 | + foreach ($args['options'] as $value => $label) { |
|
1093 | 1093 | $option_args = $args; |
1094 | 1094 | $option_args['value'] = $value; |
1095 | 1095 | $option_args['label'] = $label; |
1096 | 1096 | $option_args['checked'] = $value == $args['value'] ? true : false; |
1097 | - $output .= self::radio_option( $option_args, $count ); |
|
1098 | - $count ++; |
|
1097 | + $output .= self::radio_option($option_args, $count); |
|
1098 | + $count++; |
|
1099 | 1099 | } |
1100 | 1100 | } |
1101 | 1101 | |
1102 | 1102 | // help text |
1103 | - $help_text = ! empty( $args['help_text'] ) ? AUI_Component_Helper::help_text( $args['help_text'] ) : ''; |
|
1103 | + $help_text = !empty($args['help_text']) ? AUI_Component_Helper::help_text($args['help_text']) : ''; |
|
1104 | 1104 | $output .= $help_text; |
1105 | 1105 | |
1106 | 1106 | // maybe horizontal label |
1107 | - if ( $args['label_type'] == 'horizontal' ) { |
|
1107 | + if ($args['label_type'] == 'horizontal') { |
|
1108 | 1108 | $output .= '</div>'; |
1109 | 1109 | } |
1110 | 1110 | |
1111 | 1111 | // wrap |
1112 | 1112 | $wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group'; |
1113 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1114 | - $output = self::wrap( array( |
|
1113 | + $wrap_class = !empty($args['wrap_class']) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1114 | + $output = self::wrap(array( |
|
1115 | 1115 | 'content' => $output, |
1116 | 1116 | 'class' => $wrap_class, |
1117 | 1117 | 'element_require' => $args['element_require'], |
1118 | 1118 | 'argument_id' => $args['id'], |
1119 | 1119 | 'wrap_attributes' => $args['wrap_attributes'], |
1120 | - ) ); |
|
1120 | + )); |
|
1121 | 1121 | |
1122 | 1122 | |
1123 | 1123 | return $output; |
@@ -1130,7 +1130,7 @@ discard block |
||
1130 | 1130 | * |
1131 | 1131 | * @return string The rendered component. |
1132 | 1132 | */ |
1133 | - public static function radio_option( $args = array(), $count = '' ) { |
|
1133 | + public static function radio_option($args = array(), $count = '') { |
|
1134 | 1134 | $defaults = array( |
1135 | 1135 | 'class' => '', |
1136 | 1136 | 'id' => '', |
@@ -1148,7 +1148,7 @@ discard block |
||
1148 | 1148 | /** |
1149 | 1149 | * Parse incoming $args into an array and merge it with $defaults |
1150 | 1150 | */ |
1151 | - $args = wp_parse_args( $args, $defaults ); |
|
1151 | + $args = wp_parse_args($args, $defaults); |
|
1152 | 1152 | |
1153 | 1153 | $output = ''; |
1154 | 1154 | |
@@ -1159,43 +1159,43 @@ discard block |
||
1159 | 1159 | $output .= ' class="form-check-input" '; |
1160 | 1160 | |
1161 | 1161 | // name |
1162 | - if ( ! empty( $args['name'] ) ) { |
|
1163 | - $output .= AUI_Component_Helper::name( $args['name'] ); |
|
1162 | + if (!empty($args['name'])) { |
|
1163 | + $output .= AUI_Component_Helper::name($args['name']); |
|
1164 | 1164 | } |
1165 | 1165 | |
1166 | 1166 | // id |
1167 | - if ( ! empty( $args['id'] ) ) { |
|
1168 | - $output .= AUI_Component_Helper::id( $args['id'] . $count ); |
|
1167 | + if (!empty($args['id'])) { |
|
1168 | + $output .= AUI_Component_Helper::id($args['id'] . $count); |
|
1169 | 1169 | } |
1170 | 1170 | |
1171 | 1171 | // title |
1172 | - if ( ! empty( $args['title'] ) ) { |
|
1173 | - $output .= AUI_Component_Helper::title( $args['title'] ); |
|
1172 | + if (!empty($args['title'])) { |
|
1173 | + $output .= AUI_Component_Helper::title($args['title']); |
|
1174 | 1174 | } |
1175 | 1175 | |
1176 | 1176 | // value |
1177 | - if ( isset( $args['value'] ) ) { |
|
1178 | - $output .= AUI_Component_Helper::value( $args['value'] ); |
|
1177 | + if (isset($args['value'])) { |
|
1178 | + $output .= AUI_Component_Helper::value($args['value']); |
|
1179 | 1179 | } |
1180 | 1180 | |
1181 | 1181 | // checked, for radio and checkboxes |
1182 | - if ( $args['checked'] ) { |
|
1182 | + if ($args['checked']) { |
|
1183 | 1183 | $output .= ' checked '; |
1184 | 1184 | } |
1185 | 1185 | |
1186 | 1186 | // data-attributes |
1187 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
1187 | + $output .= AUI_Component_Helper::data_attributes($args); |
|
1188 | 1188 | |
1189 | 1189 | // aria-attributes |
1190 | - $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
1190 | + $output .= AUI_Component_Helper::aria_attributes($args); |
|
1191 | 1191 | |
1192 | 1192 | // extra attributes |
1193 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
1194 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
1193 | + if (!empty($args['extra_attributes'])) { |
|
1194 | + $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
1195 | 1195 | } |
1196 | 1196 | |
1197 | 1197 | // required |
1198 | - if ( ! empty( $args['required'] ) ) { |
|
1198 | + if (!empty($args['required'])) { |
|
1199 | 1199 | $output .= ' required '; |
1200 | 1200 | } |
1201 | 1201 | |
@@ -1203,38 +1203,38 @@ discard block |
||
1203 | 1203 | $output .= ' >'; |
1204 | 1204 | |
1205 | 1205 | // label |
1206 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
1207 | - } elseif ( ! empty( $args['label'] ) ) { |
|
1208 | - $output .= self::label( array( |
|
1206 | + if (!empty($args['label']) && is_array($args['label'])) { |
|
1207 | + } elseif (!empty($args['label'])) { |
|
1208 | + $output .= self::label(array( |
|
1209 | 1209 | 'title' => $args['label'], |
1210 | 1210 | 'for' => $args['id'] . $count, |
1211 | 1211 | 'class' => 'form-check-label' |
1212 | - ), 'radio' ); |
|
1212 | + ), 'radio'); |
|
1213 | 1213 | } |
1214 | 1214 | |
1215 | 1215 | // wrap |
1216 | - if ( ! $args['no_wrap'] ) { |
|
1216 | + if (!$args['no_wrap']) { |
|
1217 | 1217 | $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check'; |
1218 | 1218 | |
1219 | 1219 | // Unique wrap class |
1220 | 1220 | $uniq_class = 'fwrap'; |
1221 | - if ( ! empty( $args['name'] ) ) { |
|
1221 | + if (!empty($args['name'])) { |
|
1222 | 1222 | $uniq_class .= '-' . $args['name']; |
1223 | - } else if ( ! empty( $args['id'] ) ) { |
|
1223 | + } else if (!empty($args['id'])) { |
|
1224 | 1224 | $uniq_class .= '-' . $args['id']; |
1225 | 1225 | } |
1226 | 1226 | |
1227 | - if ( isset( $args['value'] ) || $args['value'] !== "" ) { |
|
1227 | + if (isset($args['value']) || $args['value'] !== "") { |
|
1228 | 1228 | $uniq_class .= '-' . $args['value']; |
1229 | 1229 | } else { |
1230 | 1230 | $uniq_class .= '-' . $count; |
1231 | 1231 | } |
1232 | - $wrap_class .= ' ' . sanitize_html_class( $uniq_class ); |
|
1232 | + $wrap_class .= ' ' . sanitize_html_class($uniq_class); |
|
1233 | 1233 | |
1234 | - $output = self::wrap( array( |
|
1234 | + $output = self::wrap(array( |
|
1235 | 1235 | 'content' => $output, |
1236 | 1236 | 'class' => $wrap_class |
1237 | - ) ); |
|
1237 | + )); |
|
1238 | 1238 | } |
1239 | 1239 | |
1240 | 1240 | return $output; |
@@ -16,202 +16,202 @@ |
||
16 | 16 | |
17 | 17 | // If this file is called directly, abort. |
18 | 18 | if ( ! defined( 'WPINC' ) ) { |
19 | - die; |
|
19 | + die; |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | class AyeCode_UI_Plugin { |
23 | 23 | |
24 | - /** |
|
25 | - * AUI Plugin constructor. |
|
26 | - * |
|
27 | - * @since 1.0.0 |
|
28 | - */ |
|
29 | - public function __construct() { |
|
30 | - |
|
31 | - // load AUI |
|
32 | - require_once( dirname( __FILE__ ) . '/ayecode-ui-loader.php' ); |
|
33 | - |
|
34 | - // Maybe show example page |
|
35 | - add_action( 'template_redirect', array( $this,'maybe_show_examples' ) ); |
|
36 | - } |
|
37 | - |
|
38 | - public function maybe_show_examples(){ |
|
39 | - if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){ |
|
40 | - echo "<head>"; |
|
41 | - wp_head(); |
|
42 | - echo "</head>"; |
|
43 | - echo "<body class='bsui'>"; |
|
44 | - echo $this->get_examples(); |
|
45 | - wp_footer(); |
|
46 | - echo "</body>"; |
|
47 | - exit; |
|
48 | - } |
|
49 | - } |
|
50 | - |
|
51 | - public function get_examples(){ |
|
52 | - $output = ''; |
|
53 | - |
|
54 | - |
|
55 | - // open form |
|
56 | - $output .= "<form class='p-5 m-5 border rounded'>"; |
|
57 | - |
|
58 | - $output .= aui()->input( |
|
59 | - array( |
|
60 | - 'type' => 'datepicker', |
|
61 | - 'id' => 'wpinv_discount_start', |
|
62 | - 'size' => 'sm', |
|
63 | - 'name' => 'wpinv_discount_start', |
|
64 | - 'label' => __( 'Start Date', 'invoicing' ), |
|
65 | - 'placeholder' => 'YYYY-MM-DD 00:00', |
|
66 | - 'value' => '', |
|
67 | - 'extra_attributes' => array( |
|
68 | - 'data-enable-time' => 'true', |
|
69 | - 'data-time_24hr' => 'true', |
|
70 | - 'data-allow-input' => 'true', |
|
71 | - ), |
|
72 | - ), |
|
73 | - ); |
|
74 | - |
|
75 | - $output .= aui()->input( |
|
76 | - array( |
|
77 | - 'type' => 'datepicker', |
|
78 | - 'id' => 'wpinv_discount_start', |
|
79 | - //'size' => 'smx', |
|
80 | - 'name' => 'wpinv_discount_start', |
|
81 | - 'label' => __( 'Start Date', 'invoicing' ), |
|
82 | - 'placeholder' => 'YYYY-MM-DD 00:00', |
|
83 | - 'value' => '', |
|
84 | - 'extra_attributes' => array( |
|
85 | - 'data-enable-time' => 'true', |
|
86 | - 'data-time_24hr' => 'true', |
|
87 | - 'data-allow-input' => 'true', |
|
88 | - ), |
|
89 | - ), |
|
90 | - ); |
|
91 | - $output .= aui()->input( |
|
92 | - array( |
|
93 | - 'type' => 'datepicker', |
|
94 | - 'id' => 'wpinv_discount_start', |
|
95 | - 'size' => 'lg', |
|
96 | - 'name' => 'wpinv_discount_start', |
|
97 | - 'label' => __( 'Start Date', 'invoicing' ), |
|
98 | - 'placeholder' => 'YYYY-MM-DD 00:00', |
|
99 | - 'value' => '', |
|
100 | - 'extra_attributes' => array( |
|
101 | - 'data-enable-time' => 'true', |
|
102 | - 'data-time_24hr' => 'true', |
|
103 | - //'data-allow-input' => 'true', |
|
104 | - ), |
|
105 | - ) |
|
106 | - ); |
|
107 | - |
|
108 | - |
|
109 | - // input example |
|
110 | - $output .= aui()->input(array( |
|
111 | - 'type' => 'text', |
|
112 | - 'id' => 'text-example', |
|
113 | - 'size' => 'sm', |
|
114 | - //'clear_icon' => true, |
|
115 | - 'name' => 'text-example', |
|
116 | - 'placeholder' => 'text placeholder', |
|
117 | - 'title' => 'Text input example', |
|
118 | - 'value' => '', |
|
119 | - 'required' => false, |
|
120 | - 'help_text' => 'help text', |
|
121 | - 'label' => 'Text input example label', |
|
122 | - 'label_type' => 'top' |
|
123 | - )); |
|
124 | - |
|
125 | - $output .= aui()->input(array( |
|
126 | - 'type' => 'search', |
|
127 | - 'id' => 'text-example', |
|
128 | - 'size' => 'sm', |
|
129 | - //'clear_icon' => true, |
|
130 | - 'name' => 'text-example', |
|
131 | - 'placeholder' => 'text placeholder', |
|
132 | - 'title' => 'Text input example', |
|
133 | - 'value' => '', |
|
134 | - 'required' => false, |
|
135 | - 'help_text' => 'help text', |
|
136 | - 'label' => 'Text input example label', |
|
137 | - 'label_type' => 'top' |
|
138 | - )); |
|
139 | - |
|
140 | - // input example |
|
141 | - $output .= aui()->input(array( |
|
142 | - 'type' => 'url', |
|
143 | - 'id' => 'text-example2', |
|
144 | - 'name' => 'text-example', |
|
145 | - 'placeholder' => 'url placeholder', |
|
146 | - 'title' => 'Text input example', |
|
147 | - 'value' => '', |
|
148 | - 'required' => false, |
|
149 | - 'help_text' => 'help text', |
|
150 | - 'label' => 'Text input example label' |
|
151 | - )); |
|
152 | - |
|
153 | - // checkbox example |
|
154 | - $output .= aui()->input(array( |
|
155 | - 'type' => 'checkbox', |
|
156 | - 'id' => 'checkbox-example', |
|
157 | - 'name' => 'checkbox-example', |
|
158 | - 'placeholder' => 'checkbox-example', |
|
159 | - 'title' => 'Checkbox example', |
|
160 | - 'value' => '1', |
|
161 | - 'checked' => true, |
|
162 | - 'required' => false, |
|
163 | - 'help_text' => 'help text', |
|
164 | - 'label' => 'Checkbox checked' |
|
165 | - )); |
|
166 | - |
|
167 | - // checkbox example |
|
168 | - $output .= aui()->input(array( |
|
169 | - 'type' => 'checkbox', |
|
170 | - 'id' => 'checkbox-example2', |
|
171 | - 'name' => 'checkbox-example2', |
|
172 | - 'placeholder' => 'checkbox-example', |
|
173 | - 'title' => 'Checkbox example', |
|
174 | - 'value' => '1', |
|
175 | - 'checked' => false, |
|
176 | - 'required' => false, |
|
177 | - 'help_text' => 'help text', |
|
178 | - 'label' => 'Checkbox un-checked' |
|
179 | - )); |
|
180 | - |
|
181 | - // switch example |
|
182 | - $output .= aui()->input(array( |
|
183 | - 'type' => 'checkbox', |
|
184 | - 'id' => 'switch-example', |
|
185 | - 'name' => 'switch-example', |
|
186 | - 'placeholder' => 'checkbox-example', |
|
187 | - 'title' => 'Switch example', |
|
188 | - 'value' => '1', |
|
189 | - 'checked' => true, |
|
190 | - 'switch' => true, |
|
191 | - 'required' => false, |
|
192 | - 'help_text' => 'help text', |
|
193 | - 'label' => 'Switch on' |
|
194 | - )); |
|
195 | - |
|
196 | - // switch example |
|
197 | - $output .= aui()->input(array( |
|
198 | - 'type' => 'checkbox', |
|
199 | - 'id' => 'switch-example2', |
|
200 | - 'name' => 'switch-example2', |
|
201 | - 'placeholder' => 'checkbox-example', |
|
202 | - 'title' => 'Switch example', |
|
203 | - 'value' => '1', |
|
204 | - 'checked' => false, |
|
205 | - 'switch' => true, |
|
206 | - 'required' => false, |
|
207 | - 'help_text' => 'help text', |
|
208 | - 'label' => 'Switch off' |
|
209 | - )); |
|
210 | - |
|
211 | - // close form |
|
212 | - $output .= "</form>"; |
|
213 | - |
|
214 | - return $output; |
|
215 | - } |
|
24 | + /** |
|
25 | + * AUI Plugin constructor. |
|
26 | + * |
|
27 | + * @since 1.0.0 |
|
28 | + */ |
|
29 | + public function __construct() { |
|
30 | + |
|
31 | + // load AUI |
|
32 | + require_once( dirname( __FILE__ ) . '/ayecode-ui-loader.php' ); |
|
33 | + |
|
34 | + // Maybe show example page |
|
35 | + add_action( 'template_redirect', array( $this,'maybe_show_examples' ) ); |
|
36 | + } |
|
37 | + |
|
38 | + public function maybe_show_examples(){ |
|
39 | + if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){ |
|
40 | + echo "<head>"; |
|
41 | + wp_head(); |
|
42 | + echo "</head>"; |
|
43 | + echo "<body class='bsui'>"; |
|
44 | + echo $this->get_examples(); |
|
45 | + wp_footer(); |
|
46 | + echo "</body>"; |
|
47 | + exit; |
|
48 | + } |
|
49 | + } |
|
50 | + |
|
51 | + public function get_examples(){ |
|
52 | + $output = ''; |
|
53 | + |
|
54 | + |
|
55 | + // open form |
|
56 | + $output .= "<form class='p-5 m-5 border rounded'>"; |
|
57 | + |
|
58 | + $output .= aui()->input( |
|
59 | + array( |
|
60 | + 'type' => 'datepicker', |
|
61 | + 'id' => 'wpinv_discount_start', |
|
62 | + 'size' => 'sm', |
|
63 | + 'name' => 'wpinv_discount_start', |
|
64 | + 'label' => __( 'Start Date', 'invoicing' ), |
|
65 | + 'placeholder' => 'YYYY-MM-DD 00:00', |
|
66 | + 'value' => '', |
|
67 | + 'extra_attributes' => array( |
|
68 | + 'data-enable-time' => 'true', |
|
69 | + 'data-time_24hr' => 'true', |
|
70 | + 'data-allow-input' => 'true', |
|
71 | + ), |
|
72 | + ), |
|
73 | + ); |
|
74 | + |
|
75 | + $output .= aui()->input( |
|
76 | + array( |
|
77 | + 'type' => 'datepicker', |
|
78 | + 'id' => 'wpinv_discount_start', |
|
79 | + //'size' => 'smx', |
|
80 | + 'name' => 'wpinv_discount_start', |
|
81 | + 'label' => __( 'Start Date', 'invoicing' ), |
|
82 | + 'placeholder' => 'YYYY-MM-DD 00:00', |
|
83 | + 'value' => '', |
|
84 | + 'extra_attributes' => array( |
|
85 | + 'data-enable-time' => 'true', |
|
86 | + 'data-time_24hr' => 'true', |
|
87 | + 'data-allow-input' => 'true', |
|
88 | + ), |
|
89 | + ), |
|
90 | + ); |
|
91 | + $output .= aui()->input( |
|
92 | + array( |
|
93 | + 'type' => 'datepicker', |
|
94 | + 'id' => 'wpinv_discount_start', |
|
95 | + 'size' => 'lg', |
|
96 | + 'name' => 'wpinv_discount_start', |
|
97 | + 'label' => __( 'Start Date', 'invoicing' ), |
|
98 | + 'placeholder' => 'YYYY-MM-DD 00:00', |
|
99 | + 'value' => '', |
|
100 | + 'extra_attributes' => array( |
|
101 | + 'data-enable-time' => 'true', |
|
102 | + 'data-time_24hr' => 'true', |
|
103 | + //'data-allow-input' => 'true', |
|
104 | + ), |
|
105 | + ) |
|
106 | + ); |
|
107 | + |
|
108 | + |
|
109 | + // input example |
|
110 | + $output .= aui()->input(array( |
|
111 | + 'type' => 'text', |
|
112 | + 'id' => 'text-example', |
|
113 | + 'size' => 'sm', |
|
114 | + //'clear_icon' => true, |
|
115 | + 'name' => 'text-example', |
|
116 | + 'placeholder' => 'text placeholder', |
|
117 | + 'title' => 'Text input example', |
|
118 | + 'value' => '', |
|
119 | + 'required' => false, |
|
120 | + 'help_text' => 'help text', |
|
121 | + 'label' => 'Text input example label', |
|
122 | + 'label_type' => 'top' |
|
123 | + )); |
|
124 | + |
|
125 | + $output .= aui()->input(array( |
|
126 | + 'type' => 'search', |
|
127 | + 'id' => 'text-example', |
|
128 | + 'size' => 'sm', |
|
129 | + //'clear_icon' => true, |
|
130 | + 'name' => 'text-example', |
|
131 | + 'placeholder' => 'text placeholder', |
|
132 | + 'title' => 'Text input example', |
|
133 | + 'value' => '', |
|
134 | + 'required' => false, |
|
135 | + 'help_text' => 'help text', |
|
136 | + 'label' => 'Text input example label', |
|
137 | + 'label_type' => 'top' |
|
138 | + )); |
|
139 | + |
|
140 | + // input example |
|
141 | + $output .= aui()->input(array( |
|
142 | + 'type' => 'url', |
|
143 | + 'id' => 'text-example2', |
|
144 | + 'name' => 'text-example', |
|
145 | + 'placeholder' => 'url placeholder', |
|
146 | + 'title' => 'Text input example', |
|
147 | + 'value' => '', |
|
148 | + 'required' => false, |
|
149 | + 'help_text' => 'help text', |
|
150 | + 'label' => 'Text input example label' |
|
151 | + )); |
|
152 | + |
|
153 | + // checkbox example |
|
154 | + $output .= aui()->input(array( |
|
155 | + 'type' => 'checkbox', |
|
156 | + 'id' => 'checkbox-example', |
|
157 | + 'name' => 'checkbox-example', |
|
158 | + 'placeholder' => 'checkbox-example', |
|
159 | + 'title' => 'Checkbox example', |
|
160 | + 'value' => '1', |
|
161 | + 'checked' => true, |
|
162 | + 'required' => false, |
|
163 | + 'help_text' => 'help text', |
|
164 | + 'label' => 'Checkbox checked' |
|
165 | + )); |
|
166 | + |
|
167 | + // checkbox example |
|
168 | + $output .= aui()->input(array( |
|
169 | + 'type' => 'checkbox', |
|
170 | + 'id' => 'checkbox-example2', |
|
171 | + 'name' => 'checkbox-example2', |
|
172 | + 'placeholder' => 'checkbox-example', |
|
173 | + 'title' => 'Checkbox example', |
|
174 | + 'value' => '1', |
|
175 | + 'checked' => false, |
|
176 | + 'required' => false, |
|
177 | + 'help_text' => 'help text', |
|
178 | + 'label' => 'Checkbox un-checked' |
|
179 | + )); |
|
180 | + |
|
181 | + // switch example |
|
182 | + $output .= aui()->input(array( |
|
183 | + 'type' => 'checkbox', |
|
184 | + 'id' => 'switch-example', |
|
185 | + 'name' => 'switch-example', |
|
186 | + 'placeholder' => 'checkbox-example', |
|
187 | + 'title' => 'Switch example', |
|
188 | + 'value' => '1', |
|
189 | + 'checked' => true, |
|
190 | + 'switch' => true, |
|
191 | + 'required' => false, |
|
192 | + 'help_text' => 'help text', |
|
193 | + 'label' => 'Switch on' |
|
194 | + )); |
|
195 | + |
|
196 | + // switch example |
|
197 | + $output .= aui()->input(array( |
|
198 | + 'type' => 'checkbox', |
|
199 | + 'id' => 'switch-example2', |
|
200 | + 'name' => 'switch-example2', |
|
201 | + 'placeholder' => 'checkbox-example', |
|
202 | + 'title' => 'Switch example', |
|
203 | + 'value' => '1', |
|
204 | + 'checked' => false, |
|
205 | + 'switch' => true, |
|
206 | + 'required' => false, |
|
207 | + 'help_text' => 'help text', |
|
208 | + 'label' => 'Switch off' |
|
209 | + )); |
|
210 | + |
|
211 | + // close form |
|
212 | + $output .= "</form>"; |
|
213 | + |
|
214 | + return $output; |
|
215 | + } |
|
216 | 216 | } |
217 | 217 | new AyeCode_UI_Plugin(); |
218 | 218 | \ No newline at end of file |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | */ |
16 | 16 | |
17 | 17 | // If this file is called directly, abort. |
18 | -if ( ! defined( 'WPINC' ) ) { |
|
18 | +if (!defined('WPINC')) { |
|
19 | 19 | die; |
20 | 20 | } |
21 | 21 | |
@@ -29,14 +29,14 @@ discard block |
||
29 | 29 | public function __construct() { |
30 | 30 | |
31 | 31 | // load AUI |
32 | - require_once( dirname( __FILE__ ) . '/ayecode-ui-loader.php' ); |
|
32 | + require_once(dirname(__FILE__) . '/ayecode-ui-loader.php'); |
|
33 | 33 | |
34 | 34 | // Maybe show example page |
35 | - add_action( 'template_redirect', array( $this,'maybe_show_examples' ) ); |
|
35 | + add_action('template_redirect', array($this, 'maybe_show_examples')); |
|
36 | 36 | } |
37 | 37 | |
38 | - public function maybe_show_examples(){ |
|
39 | - if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){ |
|
38 | + public function maybe_show_examples() { |
|
39 | + if (current_user_can('manage_options') && isset($_REQUEST['preview-aui'])) { |
|
40 | 40 | echo "<head>"; |
41 | 41 | wp_head(); |
42 | 42 | echo "</head>"; |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | } |
49 | 49 | } |
50 | 50 | |
51 | - public function get_examples(){ |
|
51 | + public function get_examples() { |
|
52 | 52 | $output = ''; |
53 | 53 | |
54 | 54 | |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | 'id' => 'wpinv_discount_start', |
62 | 62 | 'size' => 'sm', |
63 | 63 | 'name' => 'wpinv_discount_start', |
64 | - 'label' => __( 'Start Date', 'invoicing' ), |
|
64 | + 'label' => __('Start Date', 'invoicing'), |
|
65 | 65 | 'placeholder' => 'YYYY-MM-DD 00:00', |
66 | 66 | 'value' => '', |
67 | 67 | 'extra_attributes' => array( |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | 'id' => 'wpinv_discount_start', |
79 | 79 | //'size' => 'smx', |
80 | 80 | 'name' => 'wpinv_discount_start', |
81 | - 'label' => __( 'Start Date', 'invoicing' ), |
|
81 | + 'label' => __('Start Date', 'invoicing'), |
|
82 | 82 | 'placeholder' => 'YYYY-MM-DD 00:00', |
83 | 83 | 'value' => '', |
84 | 84 | 'extra_attributes' => array( |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | 'id' => 'wpinv_discount_start', |
95 | 95 | 'size' => 'lg', |
96 | 96 | 'name' => 'wpinv_discount_start', |
97 | - 'label' => __( 'Start Date', 'invoicing' ), |
|
97 | + 'label' => __('Start Date', 'invoicing'), |
|
98 | 98 | 'placeholder' => 'YYYY-MM-DD 00:00', |
99 | 99 | 'value' => '', |
100 | 100 | 'extra_attributes' => array( |
@@ -12,473 +12,473 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Paypal_Gateway_IPN_Handler { |
14 | 14 | |
15 | - /** |
|
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
20 | - protected $id = 'paypal'; |
|
21 | - |
|
22 | - /** |
|
23 | - * Payment method object. |
|
24 | - * |
|
25 | - * @var GetPaid_Paypal_Gateway |
|
26 | - */ |
|
27 | - protected $gateway; |
|
28 | - |
|
29 | - /** |
|
30 | - * Class constructor. |
|
31 | - * |
|
32 | - * @param GetPaid_Paypal_Gateway $gateway |
|
33 | - */ |
|
34 | - public function __construct( $gateway ) { |
|
35 | - $this->gateway = $gateway; |
|
36 | - $this->verify_ipn(); |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * Processes ipns and marks payments as complete. |
|
41 | - * |
|
42 | - * @return void |
|
43 | - */ |
|
44 | - public function verify_ipn() { |
|
45 | - |
|
46 | - wpinv_error_log( 'GetPaid PayPal IPN Handler', false ); |
|
47 | - |
|
48 | - // Validate the IPN. |
|
49 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
50 | - wp_die( 'PayPal IPN Request Failure', 500 ); |
|
51 | - } |
|
52 | - |
|
53 | - // Process the IPN. |
|
54 | - $posted = wp_unslash( $_POST ); |
|
55 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
56 | - |
|
57 | - // Abort if it was not paid by our gateway. |
|
58 | - if ( $this->id != $invoice->get_gateway() ) { |
|
59 | - wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false ); |
|
60 | - wp_die( 'Invoice not paid via PayPal', 200 ); |
|
61 | - } |
|
62 | - |
|
63 | - $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : ''; |
|
64 | - $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
65 | - |
|
66 | - wpinv_error_log( 'Payment status:' . $posted['payment_status'], false ); |
|
67 | - wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false ); |
|
68 | - |
|
69 | - if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
70 | - call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
71 | - wpinv_error_log( 'Done processing IPN', false ); |
|
72 | - wp_die( 'Processed', 200 ); |
|
73 | - } |
|
74 | - |
|
75 | - wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false ); |
|
76 | - wp_die( 'Unsupported IPN type', 200 ); |
|
77 | - |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Retrieves IPN Invoice. |
|
82 | - * |
|
83 | - * @param array $posted |
|
84 | - * @return WPInv_Invoice |
|
85 | - */ |
|
86 | - protected function get_ipn_invoice( $posted ) { |
|
87 | - |
|
88 | - wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false ); |
|
89 | - |
|
90 | - if ( ! empty( $posted['custom'] ) ) { |
|
91 | - $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
92 | - |
|
93 | - if ( $invoice->exists() ) { |
|
94 | - wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false ); |
|
95 | - return $invoice; |
|
96 | - } |
|
97 | - } |
|
98 | - |
|
99 | - wpinv_error_log( 'Could not retrieve the associated invoice.', false ); |
|
100 | - wp_die( 'Could not retrieve the associated invoice.', 200 ); |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Check PayPal IPN validity. |
|
105 | - */ |
|
106 | - protected function validate_ipn() { |
|
107 | - |
|
108 | - wpinv_error_log( 'Validating PayPal IPN response', false ); |
|
109 | - |
|
110 | - // Retrieve the associated invoice. |
|
111 | - $posted = wp_unslash( $_POST ); |
|
112 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
113 | - |
|
114 | - if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
115 | - wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false ); |
|
116 | - } |
|
117 | - |
|
118 | - // Validate the IPN. |
|
119 | - $posted['cmd'] = '_notify-validate'; |
|
120 | - |
|
121 | - // Send back post vars to paypal. |
|
122 | - $params = array( |
|
123 | - 'body' => $posted, |
|
124 | - 'timeout' => 60, |
|
125 | - 'httpversion' => '1.1', |
|
126 | - 'compress' => false, |
|
127 | - 'decompress' => false, |
|
128 | - 'user-agent' => 'GetPaid/' . WPINV_VERSION, |
|
129 | - ); |
|
130 | - |
|
131 | - // Post back to get a response. |
|
132 | - $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
133 | - |
|
134 | - // Check to see if the request was valid. |
|
135 | - if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
136 | - wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false ); |
|
137 | - return true; |
|
138 | - } |
|
139 | - |
|
140 | - if ( is_wp_error( $response ) ) { |
|
141 | - wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
142 | - return false; |
|
143 | - } |
|
144 | - |
|
145 | - wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
146 | - return false; |
|
147 | - |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Check currency from IPN matches the invoice. |
|
152 | - * |
|
153 | - * @param WPInv_Invoice $invoice Invoice object. |
|
154 | - * @param string $currency currency to validate. |
|
155 | - */ |
|
156 | - protected function validate_ipn_currency( $invoice, $currency ) { |
|
15 | + /** |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | + protected $id = 'paypal'; |
|
21 | + |
|
22 | + /** |
|
23 | + * Payment method object. |
|
24 | + * |
|
25 | + * @var GetPaid_Paypal_Gateway |
|
26 | + */ |
|
27 | + protected $gateway; |
|
28 | + |
|
29 | + /** |
|
30 | + * Class constructor. |
|
31 | + * |
|
32 | + * @param GetPaid_Paypal_Gateway $gateway |
|
33 | + */ |
|
34 | + public function __construct( $gateway ) { |
|
35 | + $this->gateway = $gateway; |
|
36 | + $this->verify_ipn(); |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * Processes ipns and marks payments as complete. |
|
41 | + * |
|
42 | + * @return void |
|
43 | + */ |
|
44 | + public function verify_ipn() { |
|
45 | + |
|
46 | + wpinv_error_log( 'GetPaid PayPal IPN Handler', false ); |
|
47 | + |
|
48 | + // Validate the IPN. |
|
49 | + if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
50 | + wp_die( 'PayPal IPN Request Failure', 500 ); |
|
51 | + } |
|
52 | + |
|
53 | + // Process the IPN. |
|
54 | + $posted = wp_unslash( $_POST ); |
|
55 | + $invoice = $this->get_ipn_invoice( $posted ); |
|
56 | + |
|
57 | + // Abort if it was not paid by our gateway. |
|
58 | + if ( $this->id != $invoice->get_gateway() ) { |
|
59 | + wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false ); |
|
60 | + wp_die( 'Invoice not paid via PayPal', 200 ); |
|
61 | + } |
|
62 | + |
|
63 | + $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : ''; |
|
64 | + $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
65 | + |
|
66 | + wpinv_error_log( 'Payment status:' . $posted['payment_status'], false ); |
|
67 | + wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false ); |
|
68 | + |
|
69 | + if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
70 | + call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
71 | + wpinv_error_log( 'Done processing IPN', false ); |
|
72 | + wp_die( 'Processed', 200 ); |
|
73 | + } |
|
74 | + |
|
75 | + wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false ); |
|
76 | + wp_die( 'Unsupported IPN type', 200 ); |
|
77 | + |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Retrieves IPN Invoice. |
|
82 | + * |
|
83 | + * @param array $posted |
|
84 | + * @return WPInv_Invoice |
|
85 | + */ |
|
86 | + protected function get_ipn_invoice( $posted ) { |
|
87 | + |
|
88 | + wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false ); |
|
89 | + |
|
90 | + if ( ! empty( $posted['custom'] ) ) { |
|
91 | + $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
92 | + |
|
93 | + if ( $invoice->exists() ) { |
|
94 | + wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false ); |
|
95 | + return $invoice; |
|
96 | + } |
|
97 | + } |
|
98 | + |
|
99 | + wpinv_error_log( 'Could not retrieve the associated invoice.', false ); |
|
100 | + wp_die( 'Could not retrieve the associated invoice.', 200 ); |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Check PayPal IPN validity. |
|
105 | + */ |
|
106 | + protected function validate_ipn() { |
|
107 | + |
|
108 | + wpinv_error_log( 'Validating PayPal IPN response', false ); |
|
109 | + |
|
110 | + // Retrieve the associated invoice. |
|
111 | + $posted = wp_unslash( $_POST ); |
|
112 | + $invoice = $this->get_ipn_invoice( $posted ); |
|
113 | + |
|
114 | + if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
115 | + wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false ); |
|
116 | + } |
|
117 | + |
|
118 | + // Validate the IPN. |
|
119 | + $posted['cmd'] = '_notify-validate'; |
|
120 | + |
|
121 | + // Send back post vars to paypal. |
|
122 | + $params = array( |
|
123 | + 'body' => $posted, |
|
124 | + 'timeout' => 60, |
|
125 | + 'httpversion' => '1.1', |
|
126 | + 'compress' => false, |
|
127 | + 'decompress' => false, |
|
128 | + 'user-agent' => 'GetPaid/' . WPINV_VERSION, |
|
129 | + ); |
|
130 | + |
|
131 | + // Post back to get a response. |
|
132 | + $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
133 | + |
|
134 | + // Check to see if the request was valid. |
|
135 | + if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
136 | + wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false ); |
|
137 | + return true; |
|
138 | + } |
|
139 | + |
|
140 | + if ( is_wp_error( $response ) ) { |
|
141 | + wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
142 | + return false; |
|
143 | + } |
|
144 | + |
|
145 | + wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
146 | + return false; |
|
147 | + |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * Check currency from IPN matches the invoice. |
|
152 | + * |
|
153 | + * @param WPInv_Invoice $invoice Invoice object. |
|
154 | + * @param string $currency currency to validate. |
|
155 | + */ |
|
156 | + protected function validate_ipn_currency( $invoice, $currency ) { |
|
157 | 157 | |
158 | - if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
158 | + if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
159 | 159 | |
160 | - /* translators: %s: currency code. */ |
|
161 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
160 | + /* translators: %s: currency code. */ |
|
161 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
162 | 162 | |
163 | - wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
164 | - } |
|
163 | + wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
164 | + } |
|
165 | 165 | |
166 | - wpinv_error_log( $currency, 'Validated IPN Currency', false ); |
|
167 | - } |
|
166 | + wpinv_error_log( $currency, 'Validated IPN Currency', false ); |
|
167 | + } |
|
168 | 168 | |
169 | - /** |
|
170 | - * Check payment amount from IPN matches the invoice. |
|
171 | - * |
|
172 | - * @param WPInv_Invoice $invoice Invoice object. |
|
173 | - * @param float $amount amount to validate. |
|
174 | - */ |
|
175 | - protected function validate_ipn_amount( $invoice, $amount ) { |
|
176 | - if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
169 | + /** |
|
170 | + * Check payment amount from IPN matches the invoice. |
|
171 | + * |
|
172 | + * @param WPInv_Invoice $invoice Invoice object. |
|
173 | + * @param float $amount amount to validate. |
|
174 | + */ |
|
175 | + protected function validate_ipn_amount( $invoice, $amount ) { |
|
176 | + if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
177 | 177 | |
178 | - /* translators: %s: Amount. */ |
|
179 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
178 | + /* translators: %s: Amount. */ |
|
179 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
180 | 180 | |
181 | - wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
182 | - } |
|
181 | + wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
182 | + } |
|
183 | 183 | |
184 | - wpinv_error_log( $amount, 'Validated IPN Amount', false ); |
|
185 | - } |
|
184 | + wpinv_error_log( $amount, 'Validated IPN Amount', false ); |
|
185 | + } |
|
186 | 186 | |
187 | - /** |
|
188 | - * Verify receiver email from PayPal. |
|
189 | - * |
|
190 | - * @param WPInv_Invoice $invoice Invoice object. |
|
191 | - * @param string $receiver_email Email to validate. |
|
192 | - */ |
|
193 | - protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
194 | - $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
187 | + /** |
|
188 | + * Verify receiver email from PayPal. |
|
189 | + * |
|
190 | + * @param WPInv_Invoice $invoice Invoice object. |
|
191 | + * @param string $receiver_email Email to validate. |
|
192 | + */ |
|
193 | + protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
194 | + $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
195 | 195 | |
196 | - if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
197 | - wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
196 | + if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
197 | + wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
198 | 198 | |
199 | - /* translators: %s: email address . */ |
|
200 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
199 | + /* translators: %s: email address . */ |
|
200 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
201 | 201 | |
202 | - return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
203 | - } |
|
202 | + return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
203 | + } |
|
204 | 204 | |
205 | - wpinv_error_log( 'Validated PayPal Email', false ); |
|
206 | - } |
|
205 | + wpinv_error_log( 'Validated PayPal Email', false ); |
|
206 | + } |
|
207 | 207 | |
208 | - /** |
|
209 | - * Handles one time payments. |
|
210 | - * |
|
211 | - * @param WPInv_Invoice $invoice Invoice object. |
|
212 | - * @param array $posted Posted data. |
|
213 | - */ |
|
214 | - protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
208 | + /** |
|
209 | + * Handles one time payments. |
|
210 | + * |
|
211 | + * @param WPInv_Invoice $invoice Invoice object. |
|
212 | + * @param array $posted Posted data. |
|
213 | + */ |
|
214 | + protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
215 | 215 | |
216 | - // Collect payment details |
|
217 | - $payment_status = strtolower( $posted['payment_status'] ); |
|
218 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
216 | + // Collect payment details |
|
217 | + $payment_status = strtolower( $posted['payment_status'] ); |
|
218 | + $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
219 | 219 | |
220 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
221 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
220 | + $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
221 | + $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
222 | 222 | |
223 | - // Update the transaction id. |
|
224 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
225 | - $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
226 | - $invoice->save(); |
|
227 | - } |
|
223 | + // Update the transaction id. |
|
224 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
225 | + $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
226 | + $invoice->save(); |
|
227 | + } |
|
228 | 228 | |
229 | - $invoice->add_system_note( __( 'Processing invoice IPN', 'invoicing' ) ); |
|
229 | + $invoice->add_system_note( __( 'Processing invoice IPN', 'invoicing' ) ); |
|
230 | 230 | |
231 | - // Process a refund. |
|
232 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
231 | + // Process a refund. |
|
232 | + if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
233 | 233 | |
234 | - update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
234 | + update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
235 | 235 | |
236 | - if ( ! $invoice->is_refunded() ) { |
|
237 | - $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
238 | - } |
|
236 | + if ( ! $invoice->is_refunded() ) { |
|
237 | + $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
238 | + } |
|
239 | 239 | |
240 | - return wpinv_error_log( $posted['reason_code'], false ); |
|
241 | - } |
|
240 | + return wpinv_error_log( $posted['reason_code'], false ); |
|
241 | + } |
|
242 | 242 | |
243 | - // Process payments. |
|
244 | - if ( $payment_status == 'completed' ) { |
|
243 | + // Process payments. |
|
244 | + if ( $payment_status == 'completed' ) { |
|
245 | 245 | |
246 | - if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
247 | - return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false ); |
|
248 | - } |
|
246 | + if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
247 | + return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false ); |
|
248 | + } |
|
249 | 249 | |
250 | - $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
250 | + $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
251 | 251 | |
252 | - $note = ''; |
|
252 | + $note = ''; |
|
253 | 253 | |
254 | - if ( ! empty( $posted['mc_fee'] ) ) { |
|
255 | - $note = sprintf( __( 'PayPal Transaction Fee %s.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
256 | - } |
|
254 | + if ( ! empty( $posted['mc_fee'] ) ) { |
|
255 | + $note = sprintf( __( 'PayPal Transaction Fee %s.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
256 | + } |
|
257 | 257 | |
258 | - if ( ! empty( $posted['payer_status'] ) ) { |
|
259 | - $note = ' ' . sprintf( __( 'Buyer status %s.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
260 | - } |
|
258 | + if ( ! empty( $posted['payer_status'] ) ) { |
|
259 | + $note = ' ' . sprintf( __( 'Buyer status %s.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
260 | + } |
|
261 | 261 | |
262 | - $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
263 | - return wpinv_error_log( 'Invoice marked as paid.', false ); |
|
262 | + $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
263 | + return wpinv_error_log( 'Invoice marked as paid.', false ); |
|
264 | 264 | |
265 | - } |
|
265 | + } |
|
266 | 266 | |
267 | - // Pending payments. |
|
268 | - if ( $payment_status == 'pending' ) { |
|
267 | + // Pending payments. |
|
268 | + if ( $payment_status == 'pending' ) { |
|
269 | 269 | |
270 | - /* translators: %s: pending reason. */ |
|
271 | - $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
270 | + /* translators: %s: pending reason. */ |
|
271 | + $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
272 | 272 | |
273 | - return wpinv_error_log( 'Invoice marked as "payment held".', false ); |
|
274 | - } |
|
273 | + return wpinv_error_log( 'Invoice marked as "payment held".', false ); |
|
274 | + } |
|
275 | 275 | |
276 | - /* translators: %s: payment status. */ |
|
277 | - $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
276 | + /* translators: %s: payment status. */ |
|
277 | + $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
278 | 278 | |
279 | - } |
|
279 | + } |
|
280 | 280 | |
281 | - /** |
|
282 | - * Handles one time payments. |
|
283 | - * |
|
284 | - * @param WPInv_Invoice $invoice Invoice object. |
|
285 | - * @param array $posted Posted data. |
|
286 | - */ |
|
287 | - protected function ipn_txn_cart( $invoice, $posted ) { |
|
288 | - $this->ipn_txn_web_accept( $invoice, $posted ); |
|
289 | - } |
|
281 | + /** |
|
282 | + * Handles one time payments. |
|
283 | + * |
|
284 | + * @param WPInv_Invoice $invoice Invoice object. |
|
285 | + * @param array $posted Posted data. |
|
286 | + */ |
|
287 | + protected function ipn_txn_cart( $invoice, $posted ) { |
|
288 | + $this->ipn_txn_web_accept( $invoice, $posted ); |
|
289 | + } |
|
290 | 290 | |
291 | - /** |
|
292 | - * Handles subscription sign ups. |
|
293 | - * |
|
294 | - * @param WPInv_Invoice $invoice Invoice object. |
|
295 | - * @param array $posted Posted data. |
|
296 | - */ |
|
297 | - protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
291 | + /** |
|
292 | + * Handles subscription sign ups. |
|
293 | + * |
|
294 | + * @param WPInv_Invoice $invoice Invoice object. |
|
295 | + * @param array $posted Posted data. |
|
296 | + */ |
|
297 | + protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
298 | 298 | |
299 | - wpinv_error_log( 'Processing subscription signup', false ); |
|
299 | + wpinv_error_log( 'Processing subscription signup', false ); |
|
300 | 300 | |
301 | - // Make sure the invoice has a subscription. |
|
302 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
301 | + // Make sure the invoice has a subscription. |
|
302 | + $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
303 | 303 | |
304 | - if ( empty( $subscription ) ) { |
|
305 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
306 | - } |
|
304 | + if ( empty( $subscription ) ) { |
|
305 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
306 | + } |
|
307 | 307 | |
308 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
308 | + wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
309 | 309 | |
310 | - // Validate the IPN. |
|
311 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
312 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
313 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
310 | + // Validate the IPN. |
|
311 | + $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
312 | + $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
313 | + $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
314 | 314 | |
315 | - // Activate the subscription. |
|
316 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
317 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
318 | - $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
319 | - $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
320 | - $subscription->activate(); |
|
315 | + // Activate the subscription. |
|
316 | + $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
317 | + $subscription->set_date_created( current_time( 'mysql' ) ); |
|
318 | + $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
319 | + $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
320 | + $subscription->activate(); |
|
321 | 321 | |
322 | - // Set the transaction id. |
|
323 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
324 | - $invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true ); |
|
325 | - $invoice->set_transaction_id( $posted['txn_id'] ); |
|
326 | - } |
|
322 | + // Set the transaction id. |
|
323 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
324 | + $invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true ); |
|
325 | + $invoice->set_transaction_id( $posted['txn_id'] ); |
|
326 | + } |
|
327 | 327 | |
328 | - // Update the payment status. |
|
329 | - $invoice->mark_paid(); |
|
328 | + // Update the payment status. |
|
329 | + $invoice->mark_paid(); |
|
330 | 330 | |
331 | - $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true ); |
|
331 | + $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true ); |
|
332 | 332 | |
333 | - wpinv_error_log( 'Subscription started.', false ); |
|
334 | - } |
|
333 | + wpinv_error_log( 'Subscription started.', false ); |
|
334 | + } |
|
335 | 335 | |
336 | - /** |
|
337 | - * Handles subscription renewals. |
|
338 | - * |
|
339 | - * @param WPInv_Invoice $invoice Invoice object. |
|
340 | - * @param array $posted Posted data. |
|
341 | - */ |
|
342 | - protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
336 | + /** |
|
337 | + * Handles subscription renewals. |
|
338 | + * |
|
339 | + * @param WPInv_Invoice $invoice Invoice object. |
|
340 | + * @param array $posted Posted data. |
|
341 | + */ |
|
342 | + protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
343 | 343 | |
344 | - // Make sure the invoice has a subscription. |
|
345 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
344 | + // Make sure the invoice has a subscription. |
|
345 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
346 | 346 | |
347 | - if ( empty( $subscription ) ) { |
|
348 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
349 | - } |
|
347 | + if ( empty( $subscription ) ) { |
|
348 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
349 | + } |
|
350 | 350 | |
351 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
351 | + wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
352 | 352 | |
353 | - // PayPal sends a subscr_payment for the first payment too. |
|
354 | - $date_completed = getpaid_format_date( $invoice->get_date_completed() ); |
|
355 | - $date_created = getpaid_format_date( $invoice->get_date_created() ); |
|
356 | - $today_date = getpaid_format_date( current_time( 'mysql' ) ); |
|
357 | - $payment_date = getpaid_format_date( $posted['payment_date'] ); |
|
358 | - $subscribe_date = getpaid_format_date( $subscription->get_date_created() ); |
|
359 | - $dates = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) ); |
|
353 | + // PayPal sends a subscr_payment for the first payment too. |
|
354 | + $date_completed = getpaid_format_date( $invoice->get_date_completed() ); |
|
355 | + $date_created = getpaid_format_date( $invoice->get_date_created() ); |
|
356 | + $today_date = getpaid_format_date( current_time( 'mysql' ) ); |
|
357 | + $payment_date = getpaid_format_date( $posted['payment_date'] ); |
|
358 | + $subscribe_date = getpaid_format_date( $subscription->get_date_created() ); |
|
359 | + $dates = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) ); |
|
360 | 360 | |
361 | - foreach ( $dates as $date ) { |
|
361 | + foreach ( $dates as $date ) { |
|
362 | 362 | |
363 | - if ( $date !== $today_date && $date !== $payment_date ) { |
|
364 | - continue; |
|
365 | - } |
|
363 | + if ( $date !== $today_date && $date !== $payment_date ) { |
|
364 | + continue; |
|
365 | + } |
|
366 | 366 | |
367 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
368 | - $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
369 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), sanitize_text_field( $posted['txn_id'] ) ), false, false, true ); |
|
370 | - } |
|
367 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
368 | + $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
369 | + $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), sanitize_text_field( $posted['txn_id'] ) ), false, false, true ); |
|
370 | + } |
|
371 | 371 | |
372 | - return $invoice->mark_paid(); |
|
373 | - |
|
374 | - } |
|
372 | + return $invoice->mark_paid(); |
|
373 | + |
|
374 | + } |
|
375 | 375 | |
376 | - wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false ); |
|
377 | - |
|
378 | - // Abort if the payment is already recorded. |
|
379 | - if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
380 | - return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed', false ); |
|
381 | - } |
|
382 | - |
|
383 | - $args = array( |
|
384 | - 'transaction_id' => $posted['txn_id'], |
|
385 | - 'gateway' => $this->id, |
|
386 | - ); |
|
387 | - |
|
388 | - $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
376 | + wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false ); |
|
377 | + |
|
378 | + // Abort if the payment is already recorded. |
|
379 | + if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
380 | + return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed', false ); |
|
381 | + } |
|
382 | + |
|
383 | + $args = array( |
|
384 | + 'transaction_id' => $posted['txn_id'], |
|
385 | + 'gateway' => $this->id, |
|
386 | + ); |
|
387 | + |
|
388 | + $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
389 | 389 | |
390 | - if ( empty( $invoice ) ) { |
|
391 | - return; |
|
392 | - } |
|
390 | + if ( empty( $invoice ) ) { |
|
391 | + return; |
|
392 | + } |
|
393 | 393 | |
394 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true ); |
|
395 | - $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true ); |
|
394 | + $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true ); |
|
395 | + $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true ); |
|
396 | 396 | |
397 | - $subscription->renew(); |
|
398 | - wpinv_error_log( 'Subscription renewed.', false ); |
|
397 | + $subscription->renew(); |
|
398 | + wpinv_error_log( 'Subscription renewed.', false ); |
|
399 | 399 | |
400 | - } |
|
400 | + } |
|
401 | 401 | |
402 | - /** |
|
403 | - * Handles subscription cancelations. |
|
404 | - * |
|
405 | - * @param WPInv_Invoice $invoice Invoice object. |
|
406 | - */ |
|
407 | - protected function ipn_txn_subscr_cancel( $invoice ) { |
|
402 | + /** |
|
403 | + * Handles subscription cancelations. |
|
404 | + * |
|
405 | + * @param WPInv_Invoice $invoice Invoice object. |
|
406 | + */ |
|
407 | + protected function ipn_txn_subscr_cancel( $invoice ) { |
|
408 | 408 | |
409 | - // Make sure the invoice has a subscription. |
|
410 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
411 | - |
|
412 | - if ( empty( $subscription ) ) { |
|
413 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
414 | - } |
|
415 | - |
|
416 | - wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false ); |
|
417 | - $subscription->cancel(); |
|
418 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
409 | + // Make sure the invoice has a subscription. |
|
410 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
411 | + |
|
412 | + if ( empty( $subscription ) ) { |
|
413 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
414 | + } |
|
415 | + |
|
416 | + wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false ); |
|
417 | + $subscription->cancel(); |
|
418 | + wpinv_error_log( 'Subscription cancelled.', false ); |
|
419 | 419 | |
420 | - } |
|
420 | + } |
|
421 | 421 | |
422 | - /** |
|
423 | - * Handles subscription completions. |
|
424 | - * |
|
425 | - * @param WPInv_Invoice $invoice Invoice object. |
|
426 | - * @param array $posted Posted data. |
|
427 | - */ |
|
428 | - protected function ipn_txn_subscr_eot( $invoice ) { |
|
422 | + /** |
|
423 | + * Handles subscription completions. |
|
424 | + * |
|
425 | + * @param WPInv_Invoice $invoice Invoice object. |
|
426 | + * @param array $posted Posted data. |
|
427 | + */ |
|
428 | + protected function ipn_txn_subscr_eot( $invoice ) { |
|
429 | 429 | |
430 | - // Make sure the invoice has a subscription. |
|
431 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
430 | + // Make sure the invoice has a subscription. |
|
431 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
432 | 432 | |
433 | - if ( empty( $subscription ) ) { |
|
434 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
435 | - } |
|
433 | + if ( empty( $subscription ) ) { |
|
434 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
435 | + } |
|
436 | 436 | |
437 | - wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false ); |
|
438 | - $subscription->complete(); |
|
439 | - wpinv_error_log( 'Subscription completed.', false ); |
|
437 | + wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false ); |
|
438 | + $subscription->complete(); |
|
439 | + wpinv_error_log( 'Subscription completed.', false ); |
|
440 | 440 | |
441 | - } |
|
441 | + } |
|
442 | 442 | |
443 | - /** |
|
444 | - * Handles subscription fails. |
|
445 | - * |
|
446 | - * @param WPInv_Invoice $invoice Invoice object. |
|
447 | - * @param array $posted Posted data. |
|
448 | - */ |
|
449 | - protected function ipn_txn_subscr_failed( $invoice ) { |
|
443 | + /** |
|
444 | + * Handles subscription fails. |
|
445 | + * |
|
446 | + * @param WPInv_Invoice $invoice Invoice object. |
|
447 | + * @param array $posted Posted data. |
|
448 | + */ |
|
449 | + protected function ipn_txn_subscr_failed( $invoice ) { |
|
450 | 450 | |
451 | - // Make sure the invoice has a subscription. |
|
452 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
451 | + // Make sure the invoice has a subscription. |
|
452 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
453 | 453 | |
454 | - if ( empty( $subscription ) ) { |
|
455 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
456 | - } |
|
454 | + if ( empty( $subscription ) ) { |
|
455 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
456 | + } |
|
457 | 457 | |
458 | - wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false ); |
|
459 | - $subscription->failing(); |
|
460 | - wpinv_error_log( 'Subscription marked as failing.', false ); |
|
458 | + wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false ); |
|
459 | + $subscription->failing(); |
|
460 | + wpinv_error_log( 'Subscription marked as failing.', false ); |
|
461 | 461 | |
462 | - } |
|
462 | + } |
|
463 | 463 | |
464 | - /** |
|
465 | - * Handles subscription suspensions. |
|
466 | - * |
|
467 | - * @param WPInv_Invoice $invoice Invoice object. |
|
468 | - * @param array $posted Posted data. |
|
469 | - */ |
|
470 | - protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) { |
|
464 | + /** |
|
465 | + * Handles subscription suspensions. |
|
466 | + * |
|
467 | + * @param WPInv_Invoice $invoice Invoice object. |
|
468 | + * @param array $posted Posted data. |
|
469 | + */ |
|
470 | + protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) { |
|
471 | 471 | |
472 | - // Make sure the invoice has a subscription. |
|
473 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
472 | + // Make sure the invoice has a subscription. |
|
473 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
474 | 474 | |
475 | - if ( empty( $subscription ) ) { |
|
476 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
477 | - } |
|
478 | - |
|
479 | - wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false ); |
|
480 | - $subscription->cancel(); |
|
481 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
482 | - } |
|
475 | + if ( empty( $subscription ) ) { |
|
476 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
477 | + } |
|
478 | + |
|
479 | + wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false ); |
|
480 | + $subscription->cancel(); |
|
481 | + wpinv_error_log( 'Subscription cancelled.', false ); |
|
482 | + } |
|
483 | 483 | |
484 | 484 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Paypal Payment Gateway IPN handler class. |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | * |
32 | 32 | * @param GetPaid_Paypal_Gateway $gateway |
33 | 33 | */ |
34 | - public function __construct( $gateway ) { |
|
34 | + public function __construct($gateway) { |
|
35 | 35 | $this->gateway = $gateway; |
36 | 36 | $this->verify_ipn(); |
37 | 37 | } |
@@ -43,37 +43,37 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function verify_ipn() { |
45 | 45 | |
46 | - wpinv_error_log( 'GetPaid PayPal IPN Handler', false ); |
|
46 | + wpinv_error_log('GetPaid PayPal IPN Handler', false); |
|
47 | 47 | |
48 | 48 | // Validate the IPN. |
49 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
50 | - wp_die( 'PayPal IPN Request Failure', 500 ); |
|
49 | + if (empty($_POST) || !$this->validate_ipn()) { |
|
50 | + wp_die('PayPal IPN Request Failure', 500); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | // Process the IPN. |
54 | - $posted = wp_unslash( $_POST ); |
|
55 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
54 | + $posted = wp_unslash($_POST); |
|
55 | + $invoice = $this->get_ipn_invoice($posted); |
|
56 | 56 | |
57 | 57 | // Abort if it was not paid by our gateway. |
58 | - if ( $this->id != $invoice->get_gateway() ) { |
|
59 | - wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false ); |
|
60 | - wp_die( 'Invoice not paid via PayPal', 200 ); |
|
58 | + if ($this->id != $invoice->get_gateway()) { |
|
59 | + wpinv_error_log('Aborting, Invoice was not paid via PayPal', false); |
|
60 | + wp_die('Invoice not paid via PayPal', 200); |
|
61 | 61 | } |
62 | 62 | |
63 | - $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : ''; |
|
64 | - $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
63 | + $posted['payment_status'] = isset($posted['payment_status']) ? sanitize_key(strtolower($posted['payment_status'])) : ''; |
|
64 | + $posted['txn_type'] = sanitize_key(strtolower($posted['txn_type'])); |
|
65 | 65 | |
66 | - wpinv_error_log( 'Payment status:' . $posted['payment_status'], false ); |
|
67 | - wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false ); |
|
66 | + wpinv_error_log('Payment status:' . $posted['payment_status'], false); |
|
67 | + wpinv_error_log('IPN Type:' . $posted['txn_type'], false); |
|
68 | 68 | |
69 | - if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
70 | - call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
71 | - wpinv_error_log( 'Done processing IPN', false ); |
|
72 | - wp_die( 'Processed', 200 ); |
|
69 | + if (method_exists($this, 'ipn_txn_' . $posted['txn_type'])) { |
|
70 | + call_user_func(array($this, 'ipn_txn_' . $posted['txn_type']), $invoice, $posted); |
|
71 | + wpinv_error_log('Done processing IPN', false); |
|
72 | + wp_die('Processed', 200); |
|
73 | 73 | } |
74 | 74 | |
75 | - wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false ); |
|
76 | - wp_die( 'Unsupported IPN type', 200 ); |
|
75 | + wpinv_error_log('Aborting, Unsupported IPN type:' . $posted['txn_type'], false); |
|
76 | + wp_die('Unsupported IPN type', 200); |
|
77 | 77 | |
78 | 78 | } |
79 | 79 | |
@@ -83,21 +83,21 @@ discard block |
||
83 | 83 | * @param array $posted |
84 | 84 | * @return WPInv_Invoice |
85 | 85 | */ |
86 | - protected function get_ipn_invoice( $posted ) { |
|
86 | + protected function get_ipn_invoice($posted) { |
|
87 | 87 | |
88 | - wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false ); |
|
88 | + wpinv_error_log('Retrieving PayPal IPN Response Invoice', false); |
|
89 | 89 | |
90 | - if ( ! empty( $posted['custom'] ) ) { |
|
91 | - $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
90 | + if (!empty($posted['custom'])) { |
|
91 | + $invoice = new WPInv_Invoice($posted['custom']); |
|
92 | 92 | |
93 | - if ( $invoice->exists() ) { |
|
94 | - wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false ); |
|
93 | + if ($invoice->exists()) { |
|
94 | + wpinv_error_log('Found invoice #' . $invoice->get_number(), false); |
|
95 | 95 | return $invoice; |
96 | 96 | } |
97 | 97 | } |
98 | 98 | |
99 | - wpinv_error_log( 'Could not retrieve the associated invoice.', false ); |
|
100 | - wp_die( 'Could not retrieve the associated invoice.', 200 ); |
|
99 | + wpinv_error_log('Could not retrieve the associated invoice.', false); |
|
100 | + wp_die('Could not retrieve the associated invoice.', 200); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -105,14 +105,14 @@ discard block |
||
105 | 105 | */ |
106 | 106 | protected function validate_ipn() { |
107 | 107 | |
108 | - wpinv_error_log( 'Validating PayPal IPN response', false ); |
|
108 | + wpinv_error_log('Validating PayPal IPN response', false); |
|
109 | 109 | |
110 | 110 | // Retrieve the associated invoice. |
111 | - $posted = wp_unslash( $_POST ); |
|
112 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
111 | + $posted = wp_unslash($_POST); |
|
112 | + $invoice = $this->get_ipn_invoice($posted); |
|
113 | 113 | |
114 | - if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
115 | - wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false ); |
|
114 | + if ($this->gateway->is_sandbox($invoice)) { |
|
115 | + wpinv_error_log($posted, 'Invoice was processed in sandbox hence logging the posted data', false); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | // Validate the IPN. |
@@ -129,20 +129,20 @@ discard block |
||
129 | 129 | ); |
130 | 130 | |
131 | 131 | // Post back to get a response. |
132 | - $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
132 | + $response = wp_safe_remote_post($this->gateway->is_sandbox($invoice) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params); |
|
133 | 133 | |
134 | 134 | // Check to see if the request was valid. |
135 | - if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
136 | - wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false ); |
|
135 | + if (!is_wp_error($response) && $response['response']['code'] < 300 && strstr($response['body'], 'VERIFIED')) { |
|
136 | + wpinv_error_log('Received valid response from PayPal IPN: ' . $response['body'], false); |
|
137 | 137 | return true; |
138 | 138 | } |
139 | 139 | |
140 | - if ( is_wp_error( $response ) ) { |
|
141 | - wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
140 | + if (is_wp_error($response)) { |
|
141 | + wpinv_error_log($response->get_error_message(), 'Received invalid response from PayPal IPN'); |
|
142 | 142 | return false; |
143 | 143 | } |
144 | 144 | |
145 | - wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
145 | + wpinv_error_log($response['body'], 'Received invalid response from PayPal IPN'); |
|
146 | 146 | return false; |
147 | 147 | |
148 | 148 | } |
@@ -153,17 +153,17 @@ discard block |
||
153 | 153 | * @param WPInv_Invoice $invoice Invoice object. |
154 | 154 | * @param string $currency currency to validate. |
155 | 155 | */ |
156 | - protected function validate_ipn_currency( $invoice, $currency ) { |
|
156 | + protected function validate_ipn_currency($invoice, $currency) { |
|
157 | 157 | |
158 | - if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
158 | + if (strtolower($invoice->get_currency()) !== strtolower($currency)) { |
|
159 | 159 | |
160 | 160 | /* translators: %s: currency code. */ |
161 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
161 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal currencies do not match (code %s).', 'invoicing'), $currency)); |
|
162 | 162 | |
163 | - wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
163 | + wpinv_error_log("Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true); |
|
164 | 164 | } |
165 | 165 | |
166 | - wpinv_error_log( $currency, 'Validated IPN Currency', false ); |
|
166 | + wpinv_error_log($currency, 'Validated IPN Currency', false); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
@@ -172,16 +172,16 @@ discard block |
||
172 | 172 | * @param WPInv_Invoice $invoice Invoice object. |
173 | 173 | * @param float $amount amount to validate. |
174 | 174 | */ |
175 | - protected function validate_ipn_amount( $invoice, $amount ) { |
|
176 | - if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
175 | + protected function validate_ipn_amount($invoice, $amount) { |
|
176 | + if (number_format($invoice->get_total(), 2, '.', '') !== number_format($amount, 2, '.', '')) { |
|
177 | 177 | |
178 | 178 | /* translators: %s: Amount. */ |
179 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
179 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal amounts do not match (gross %s).', 'invoicing'), $amount)); |
|
180 | 180 | |
181 | - wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
181 | + wpinv_error_log("Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true); |
|
182 | 182 | } |
183 | 183 | |
184 | - wpinv_error_log( $amount, 'Validated IPN Amount', false ); |
|
184 | + wpinv_error_log($amount, 'Validated IPN Amount', false); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | /** |
@@ -190,19 +190,19 @@ discard block |
||
190 | 190 | * @param WPInv_Invoice $invoice Invoice object. |
191 | 191 | * @param string $receiver_email Email to validate. |
192 | 192 | */ |
193 | - protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
194 | - $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
193 | + protected function validate_ipn_receiver_email($invoice, $receiver_email) { |
|
194 | + $paypal_email = wpinv_get_option('paypal_email'); |
|
195 | 195 | |
196 | - if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
197 | - wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
196 | + if (strcasecmp(trim($receiver_email), trim($paypal_email)) !== 0) { |
|
197 | + wpinv_record_gateway_error('IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}"); |
|
198 | 198 | |
199 | 199 | /* translators: %s: email address . */ |
200 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
200 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal IPN response from a different email address (%s).', 'invoicing'), $receiver_email)); |
|
201 | 201 | |
202 | - return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
202 | + return wpinv_error_log("IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true); |
|
203 | 203 | } |
204 | 204 | |
205 | - wpinv_error_log( 'Validated PayPal Email', false ); |
|
205 | + wpinv_error_log('Validated PayPal Email', false); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | /** |
@@ -211,70 +211,70 @@ discard block |
||
211 | 211 | * @param WPInv_Invoice $invoice Invoice object. |
212 | 212 | * @param array $posted Posted data. |
213 | 213 | */ |
214 | - protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
214 | + protected function ipn_txn_web_accept($invoice, $posted) { |
|
215 | 215 | |
216 | 216 | // Collect payment details |
217 | - $payment_status = strtolower( $posted['payment_status'] ); |
|
218 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
217 | + $payment_status = strtolower($posted['payment_status']); |
|
218 | + $business_email = isset($posted['business']) && is_email($posted['business']) ? trim($posted['business']) : trim($posted['receiver_email']); |
|
219 | 219 | |
220 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
221 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
220 | + $this->validate_ipn_receiver_email($invoice, $business_email); |
|
221 | + $this->validate_ipn_currency($invoice, $posted['mc_currency']); |
|
222 | 222 | |
223 | 223 | // Update the transaction id. |
224 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
225 | - $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
224 | + if (!empty($posted['txn_id'])) { |
|
225 | + $invoice->set_transaction_id(wpinv_clean($posted['txn_id'])); |
|
226 | 226 | $invoice->save(); |
227 | 227 | } |
228 | 228 | |
229 | - $invoice->add_system_note( __( 'Processing invoice IPN', 'invoicing' ) ); |
|
229 | + $invoice->add_system_note(__('Processing invoice IPN', 'invoicing')); |
|
230 | 230 | |
231 | 231 | // Process a refund. |
232 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
232 | + if ($payment_status == 'refunded' || $payment_status == 'reversed') { |
|
233 | 233 | |
234 | - update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
234 | + update_post_meta($invoice->get_id(), 'refunded_remotely', 1); |
|
235 | 235 | |
236 | - if ( ! $invoice->is_refunded() ) { |
|
237 | - $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
236 | + if (!$invoice->is_refunded()) { |
|
237 | + $invoice->update_status('wpi-refunded', $posted['reason_code']); |
|
238 | 238 | } |
239 | 239 | |
240 | - return wpinv_error_log( $posted['reason_code'], false ); |
|
240 | + return wpinv_error_log($posted['reason_code'], false); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | // Process payments. |
244 | - if ( $payment_status == 'completed' ) { |
|
244 | + if ($payment_status == 'completed') { |
|
245 | 245 | |
246 | - if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
247 | - return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false ); |
|
246 | + if ($invoice->is_paid() && 'wpi_processing' != $invoice->get_status()) { |
|
247 | + return wpinv_error_log('Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false); |
|
248 | 248 | } |
249 | 249 | |
250 | - $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
250 | + $this->validate_ipn_amount($invoice, $posted['mc_gross']); |
|
251 | 251 | |
252 | 252 | $note = ''; |
253 | 253 | |
254 | - if ( ! empty( $posted['mc_fee'] ) ) { |
|
255 | - $note = sprintf( __( 'PayPal Transaction Fee %s.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
254 | + if (!empty($posted['mc_fee'])) { |
|
255 | + $note = sprintf(__('PayPal Transaction Fee %s.', 'invoicing'), sanitize_text_field($posted['mc_fee'])); |
|
256 | 256 | } |
257 | 257 | |
258 | - if ( ! empty( $posted['payer_status'] ) ) { |
|
259 | - $note = ' ' . sprintf( __( 'Buyer status %s.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
258 | + if (!empty($posted['payer_status'])) { |
|
259 | + $note = ' ' . sprintf(__('Buyer status %s.', 'invoicing'), sanitize_text_field($posted['payer_status'])); |
|
260 | 260 | } |
261 | 261 | |
262 | - $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
263 | - return wpinv_error_log( 'Invoice marked as paid.', false ); |
|
262 | + $invoice->mark_paid((!empty($posted['txn_id']) ? sanitize_text_field($posted['txn_id']) : ''), trim($note)); |
|
263 | + return wpinv_error_log('Invoice marked as paid.', false); |
|
264 | 264 | |
265 | 265 | } |
266 | 266 | |
267 | 267 | // Pending payments. |
268 | - if ( $payment_status == 'pending' ) { |
|
268 | + if ($payment_status == 'pending') { |
|
269 | 269 | |
270 | 270 | /* translators: %s: pending reason. */ |
271 | - $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
271 | + $invoice->update_status('wpi-onhold', sprintf(__('Payment pending (%s).', 'invoicing'), $posted['pending_reason'])); |
|
272 | 272 | |
273 | - return wpinv_error_log( 'Invoice marked as "payment held".', false ); |
|
273 | + return wpinv_error_log('Invoice marked as "payment held".', false); |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | /* translators: %s: payment status. */ |
277 | - $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
277 | + $invoice->update_status('wpi-failed', sprintf(__('Payment %s via IPN.', 'invoicing'), sanitize_text_field($posted['payment_status']))); |
|
278 | 278 | |
279 | 279 | } |
280 | 280 | |
@@ -284,8 +284,8 @@ discard block |
||
284 | 284 | * @param WPInv_Invoice $invoice Invoice object. |
285 | 285 | * @param array $posted Posted data. |
286 | 286 | */ |
287 | - protected function ipn_txn_cart( $invoice, $posted ) { |
|
288 | - $this->ipn_txn_web_accept( $invoice, $posted ); |
|
287 | + protected function ipn_txn_cart($invoice, $posted) { |
|
288 | + $this->ipn_txn_web_accept($invoice, $posted); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | /** |
@@ -294,43 +294,43 @@ discard block |
||
294 | 294 | * @param WPInv_Invoice $invoice Invoice object. |
295 | 295 | * @param array $posted Posted data. |
296 | 296 | */ |
297 | - protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
297 | + protected function ipn_txn_subscr_signup($invoice, $posted) { |
|
298 | 298 | |
299 | - wpinv_error_log( 'Processing subscription signup', false ); |
|
299 | + wpinv_error_log('Processing subscription signup', false); |
|
300 | 300 | |
301 | 301 | // Make sure the invoice has a subscription. |
302 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
302 | + $subscription = getpaid_get_invoice_subscription($invoice); |
|
303 | 303 | |
304 | - if ( empty( $subscription ) ) { |
|
305 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
304 | + if (empty($subscription)) { |
|
305 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
306 | 306 | } |
307 | 307 | |
308 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
308 | + wpinv_error_log('Found subscription #' . $subscription->get_id(), false); |
|
309 | 309 | |
310 | 310 | // Validate the IPN. |
311 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
312 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
313 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
311 | + $business_email = isset($posted['business']) && is_email($posted['business']) ? trim($posted['business']) : trim($posted['receiver_email']); |
|
312 | + $this->validate_ipn_receiver_email($invoice, $business_email); |
|
313 | + $this->validate_ipn_currency($invoice, $posted['mc_currency']); |
|
314 | 314 | |
315 | 315 | // Activate the subscription. |
316 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
317 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
318 | - $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
319 | - $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
316 | + $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created()); |
|
317 | + $subscription->set_date_created(current_time('mysql')); |
|
318 | + $subscription->set_expiration(date('Y-m-d H:i:s', (current_time('timestamp') + $duration))); |
|
319 | + $subscription->set_profile_id(sanitize_text_field($posted['subscr_id'])); |
|
320 | 320 | $subscription->activate(); |
321 | 321 | |
322 | 322 | // Set the transaction id. |
323 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
324 | - $invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true ); |
|
325 | - $invoice->set_transaction_id( $posted['txn_id'] ); |
|
323 | + if (!empty($posted['txn_id'])) { |
|
324 | + $invoice->add_note(sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $posted['txn_id']), false, false, true); |
|
325 | + $invoice->set_transaction_id($posted['txn_id']); |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | // Update the payment status. |
329 | 329 | $invoice->mark_paid(); |
330 | 330 | |
331 | - $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true ); |
|
331 | + $invoice->add_note(sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true); |
|
332 | 332 | |
333 | - wpinv_error_log( 'Subscription started.', false ); |
|
333 | + wpinv_error_log('Subscription started.', false); |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | /** |
@@ -339,45 +339,45 @@ discard block |
||
339 | 339 | * @param WPInv_Invoice $invoice Invoice object. |
340 | 340 | * @param array $posted Posted data. |
341 | 341 | */ |
342 | - protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
342 | + protected function ipn_txn_subscr_payment($invoice, $posted) { |
|
343 | 343 | |
344 | 344 | // Make sure the invoice has a subscription. |
345 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
345 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
346 | 346 | |
347 | - if ( empty( $subscription ) ) { |
|
348 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
347 | + if (empty($subscription)) { |
|
348 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
349 | 349 | } |
350 | 350 | |
351 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
351 | + wpinv_error_log('Found subscription #' . $subscription->get_id(), false); |
|
352 | 352 | |
353 | 353 | // PayPal sends a subscr_payment for the first payment too. |
354 | - $date_completed = getpaid_format_date( $invoice->get_date_completed() ); |
|
355 | - $date_created = getpaid_format_date( $invoice->get_date_created() ); |
|
356 | - $today_date = getpaid_format_date( current_time( 'mysql' ) ); |
|
357 | - $payment_date = getpaid_format_date( $posted['payment_date'] ); |
|
358 | - $subscribe_date = getpaid_format_date( $subscription->get_date_created() ); |
|
359 | - $dates = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) ); |
|
354 | + $date_completed = getpaid_format_date($invoice->get_date_completed()); |
|
355 | + $date_created = getpaid_format_date($invoice->get_date_created()); |
|
356 | + $today_date = getpaid_format_date(current_time('mysql')); |
|
357 | + $payment_date = getpaid_format_date($posted['payment_date']); |
|
358 | + $subscribe_date = getpaid_format_date($subscription->get_date_created()); |
|
359 | + $dates = array_filter(compact('date_completed', 'date_created', 'subscribe_date')); |
|
360 | 360 | |
361 | - foreach ( $dates as $date ) { |
|
361 | + foreach ($dates as $date) { |
|
362 | 362 | |
363 | - if ( $date !== $today_date && $date !== $payment_date ) { |
|
363 | + if ($date !== $today_date && $date !== $payment_date) { |
|
364 | 364 | continue; |
365 | 365 | } |
366 | 366 | |
367 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
368 | - $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
369 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), sanitize_text_field( $posted['txn_id'] ) ), false, false, true ); |
|
367 | + if (!empty($posted['txn_id'])) { |
|
368 | + $invoice->set_transaction_id(sanitize_text_field($posted['txn_id'])); |
|
369 | + $invoice->add_note(wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), sanitize_text_field($posted['txn_id'])), false, false, true); |
|
370 | 370 | } |
371 | 371 | |
372 | 372 | return $invoice->mark_paid(); |
373 | 373 | |
374 | 374 | } |
375 | 375 | |
376 | - wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false ); |
|
376 | + wpinv_error_log('Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false); |
|
377 | 377 | |
378 | 378 | // Abort if the payment is already recorded. |
379 | - if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
380 | - return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed', false ); |
|
379 | + if (wpinv_get_id_by_transaction_id($posted['txn_id'])) { |
|
380 | + return wpinv_error_log('Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed', false); |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | $args = array( |
@@ -385,17 +385,17 @@ discard block |
||
385 | 385 | 'gateway' => $this->id, |
386 | 386 | ); |
387 | 387 | |
388 | - $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
388 | + $invoice = wpinv_get_invoice($subscription->add_payment($args)); |
|
389 | 389 | |
390 | - if ( empty( $invoice ) ) { |
|
390 | + if (empty($invoice)) { |
|
391 | 391 | return; |
392 | 392 | } |
393 | 393 | |
394 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true ); |
|
395 | - $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true ); |
|
394 | + $invoice->add_note(wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $posted['txn_id']), false, false, true); |
|
395 | + $invoice->add_note(wp_sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true); |
|
396 | 396 | |
397 | 397 | $subscription->renew(); |
398 | - wpinv_error_log( 'Subscription renewed.', false ); |
|
398 | + wpinv_error_log('Subscription renewed.', false); |
|
399 | 399 | |
400 | 400 | } |
401 | 401 | |
@@ -404,18 +404,18 @@ discard block |
||
404 | 404 | * |
405 | 405 | * @param WPInv_Invoice $invoice Invoice object. |
406 | 406 | */ |
407 | - protected function ipn_txn_subscr_cancel( $invoice ) { |
|
407 | + protected function ipn_txn_subscr_cancel($invoice) { |
|
408 | 408 | |
409 | 409 | // Make sure the invoice has a subscription. |
410 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
410 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
411 | 411 | |
412 | - if ( empty( $subscription ) ) { |
|
413 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
412 | + if (empty($subscription)) { |
|
413 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
414 | 414 | } |
415 | 415 | |
416 | - wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false ); |
|
416 | + wpinv_error_log('Processing subscription cancellation for the invoice ' . $invoice->get_id(), false); |
|
417 | 417 | $subscription->cancel(); |
418 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
418 | + wpinv_error_log('Subscription cancelled.', false); |
|
419 | 419 | |
420 | 420 | } |
421 | 421 | |
@@ -425,18 +425,18 @@ discard block |
||
425 | 425 | * @param WPInv_Invoice $invoice Invoice object. |
426 | 426 | * @param array $posted Posted data. |
427 | 427 | */ |
428 | - protected function ipn_txn_subscr_eot( $invoice ) { |
|
428 | + protected function ipn_txn_subscr_eot($invoice) { |
|
429 | 429 | |
430 | 430 | // Make sure the invoice has a subscription. |
431 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
431 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
432 | 432 | |
433 | - if ( empty( $subscription ) ) { |
|
434 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
433 | + if (empty($subscription)) { |
|
434 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
435 | 435 | } |
436 | 436 | |
437 | - wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false ); |
|
437 | + wpinv_error_log('Processing subscription end of life for the invoice ' . $invoice->get_id(), false); |
|
438 | 438 | $subscription->complete(); |
439 | - wpinv_error_log( 'Subscription completed.', false ); |
|
439 | + wpinv_error_log('Subscription completed.', false); |
|
440 | 440 | |
441 | 441 | } |
442 | 442 | |
@@ -446,18 +446,18 @@ discard block |
||
446 | 446 | * @param WPInv_Invoice $invoice Invoice object. |
447 | 447 | * @param array $posted Posted data. |
448 | 448 | */ |
449 | - protected function ipn_txn_subscr_failed( $invoice ) { |
|
449 | + protected function ipn_txn_subscr_failed($invoice) { |
|
450 | 450 | |
451 | 451 | // Make sure the invoice has a subscription. |
452 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
452 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
453 | 453 | |
454 | - if ( empty( $subscription ) ) { |
|
455 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
454 | + if (empty($subscription)) { |
|
455 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
456 | 456 | } |
457 | 457 | |
458 | - wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false ); |
|
458 | + wpinv_error_log('Processing subscription payment failure for the invoice ' . $invoice->get_id(), false); |
|
459 | 459 | $subscription->failing(); |
460 | - wpinv_error_log( 'Subscription marked as failing.', false ); |
|
460 | + wpinv_error_log('Subscription marked as failing.', false); |
|
461 | 461 | |
462 | 462 | } |
463 | 463 | |
@@ -467,18 +467,18 @@ discard block |
||
467 | 467 | * @param WPInv_Invoice $invoice Invoice object. |
468 | 468 | * @param array $posted Posted data. |
469 | 469 | */ |
470 | - protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) { |
|
470 | + protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment($invoice) { |
|
471 | 471 | |
472 | 472 | // Make sure the invoice has a subscription. |
473 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
473 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
474 | 474 | |
475 | - if ( empty( $subscription ) ) { |
|
476 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
475 | + if (empty($subscription)) { |
|
476 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
477 | 477 | } |
478 | 478 | |
479 | - wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false ); |
|
479 | + wpinv_error_log('Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false); |
|
480 | 480 | $subscription->cancel(); |
481 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
481 | + wpinv_error_log('Subscription cancelled.', false); |
|
482 | 482 | } |
483 | 483 | |
484 | 484 | } |