@@ -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,77 +11,77 @@ discard block |
||
11 | 11 | */ |
12 | 12 | class AUI_Component_Pagination { |
13 | 13 | |
14 | - /** |
|
15 | - * Build the component. |
|
16 | - * |
|
17 | - * @param array $args |
|
18 | - * |
|
19 | - * @return string The rendered component. |
|
20 | - */ |
|
21 | - public static function get( $args = array() ) { |
|
22 | - global $wp_query; |
|
23 | - |
|
24 | - $defaults = array( |
|
25 | - 'class' => '', |
|
26 | - 'mid_size' => 2, |
|
27 | - 'prev_text' => '<i class="fas fa-chevron-left"></i>', |
|
28 | - 'next_text' => '<i class="fas fa-chevron-right"></i>', |
|
29 | - 'screen_reader_text' => __( 'Posts navigation','aui' ), |
|
30 | - 'before_paging' => '', |
|
31 | - 'after_paging' => '', |
|
32 | - 'type' => 'array', |
|
33 | - 'total' => isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1, |
|
34 | - 'links' => array() // an array of links if using custom links, this includes the a tag. |
|
35 | - ); |
|
36 | - |
|
37 | - /** |
|
38 | - * Parse incoming $args into an array and merge it with $defaults |
|
39 | - */ |
|
40 | - $args = wp_parse_args( $args, $defaults ); |
|
41 | - |
|
42 | - $output = ''; |
|
43 | - |
|
44 | - // Don't print empty markup if there's only one page. |
|
45 | - if ( $args['total'] > 1 ) { |
|
46 | - |
|
47 | - // Set up paginated links. |
|
48 | - $links = !empty( $args['links'] ) ? $args['links'] : paginate_links( $args ); |
|
49 | - |
|
50 | - $class = !empty($args['class']) ? $args['class'] : ''; |
|
51 | - |
|
52 | - // make the output bootstrap ready |
|
53 | - $links_html = "<ul class='pagination m-0 p-0 $class'>"; |
|
54 | - if ( ! empty( $links ) ) { |
|
55 | - foreach ( $links as $link ) { |
|
56 | - $active = strpos( $link, 'current' ) !== false ? 'active' : ''; |
|
57 | - $links_html .= "<li class='page-item $active'>"; |
|
58 | - $links_html .= str_replace( "page-numbers", "page-link", $link ); |
|
59 | - $links_html .= "</li>"; |
|
60 | - } |
|
61 | - } |
|
62 | - $links_html .= "</ul>"; |
|
63 | - |
|
64 | - if ( $links ) { |
|
65 | - $output .= '<section class="px-0 py-2 w-100">'; |
|
66 | - $output .= _navigation_markup( $links_html, 'aui-pagination', $args['screen_reader_text'] ); |
|
67 | - $output .= '</section>'; |
|
68 | - } |
|
69 | - |
|
70 | - $output = str_replace( "screen-reader-text", "screen-reader-text sr-only", $output ); |
|
71 | - $output = str_replace( "nav-links", "aui-nav-links", $output ); |
|
72 | - } |
|
73 | - |
|
74 | - if ( $output ) { |
|
75 | - if ( ! empty( $args['before_paging'] ) ) { |
|
76 | - $output = $args['before_paging'] . $output; |
|
77 | - } |
|
78 | - |
|
79 | - if ( ! empty( $args['after_paging'] ) ) { |
|
80 | - $output = $output . $args['after_paging']; |
|
81 | - } |
|
82 | - } |
|
83 | - |
|
84 | - return $output; |
|
85 | - } |
|
14 | + /** |
|
15 | + * Build the component. |
|
16 | + * |
|
17 | + * @param array $args |
|
18 | + * |
|
19 | + * @return string The rendered component. |
|
20 | + */ |
|
21 | + public static function get( $args = array() ) { |
|
22 | + global $wp_query; |
|
23 | + |
|
24 | + $defaults = array( |
|
25 | + 'class' => '', |
|
26 | + 'mid_size' => 2, |
|
27 | + 'prev_text' => '<i class="fas fa-chevron-left"></i>', |
|
28 | + 'next_text' => '<i class="fas fa-chevron-right"></i>', |
|
29 | + 'screen_reader_text' => __( 'Posts navigation','aui' ), |
|
30 | + 'before_paging' => '', |
|
31 | + 'after_paging' => '', |
|
32 | + 'type' => 'array', |
|
33 | + 'total' => isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1, |
|
34 | + 'links' => array() // an array of links if using custom links, this includes the a tag. |
|
35 | + ); |
|
36 | + |
|
37 | + /** |
|
38 | + * Parse incoming $args into an array and merge it with $defaults |
|
39 | + */ |
|
40 | + $args = wp_parse_args( $args, $defaults ); |
|
41 | + |
|
42 | + $output = ''; |
|
43 | + |
|
44 | + // Don't print empty markup if there's only one page. |
|
45 | + if ( $args['total'] > 1 ) { |
|
46 | + |
|
47 | + // Set up paginated links. |
|
48 | + $links = !empty( $args['links'] ) ? $args['links'] : paginate_links( $args ); |
|
49 | + |
|
50 | + $class = !empty($args['class']) ? $args['class'] : ''; |
|
51 | + |
|
52 | + // make the output bootstrap ready |
|
53 | + $links_html = "<ul class='pagination m-0 p-0 $class'>"; |
|
54 | + if ( ! empty( $links ) ) { |
|
55 | + foreach ( $links as $link ) { |
|
56 | + $active = strpos( $link, 'current' ) !== false ? 'active' : ''; |
|
57 | + $links_html .= "<li class='page-item $active'>"; |
|
58 | + $links_html .= str_replace( "page-numbers", "page-link", $link ); |
|
59 | + $links_html .= "</li>"; |
|
60 | + } |
|
61 | + } |
|
62 | + $links_html .= "</ul>"; |
|
63 | + |
|
64 | + if ( $links ) { |
|
65 | + $output .= '<section class="px-0 py-2 w-100">'; |
|
66 | + $output .= _navigation_markup( $links_html, 'aui-pagination', $args['screen_reader_text'] ); |
|
67 | + $output .= '</section>'; |
|
68 | + } |
|
69 | + |
|
70 | + $output = str_replace( "screen-reader-text", "screen-reader-text sr-only", $output ); |
|
71 | + $output = str_replace( "nav-links", "aui-nav-links", $output ); |
|
72 | + } |
|
73 | + |
|
74 | + if ( $output ) { |
|
75 | + if ( ! empty( $args['before_paging'] ) ) { |
|
76 | + $output = $args['before_paging'] . $output; |
|
77 | + } |
|
78 | + |
|
79 | + if ( ! empty( $args['after_paging'] ) ) { |
|
80 | + $output = $output . $args['after_paging']; |
|
81 | + } |
|
82 | + } |
|
83 | + |
|
84 | + return $output; |
|
85 | + } |
|
86 | 86 | |
87 | 87 | } |
88 | 88 | \ No newline at end of file |
@@ -232,26 +232,26 @@ discard block |
||
232 | 232 | } |
233 | 233 | |
234 | 234 | function wpinv_get_chosen_gateway( $invoice_id = 0 ) { |
235 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
235 | + $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
236 | 236 | |
237 | 237 | $chosen = false; |
238 | 238 | if ( $invoice_id > 0 && $invoice = wpinv_get_invoice( $invoice_id ) ) { |
239 | 239 | $chosen = $invoice->get_gateway(); |
240 | 240 | } |
241 | 241 | |
242 | - $chosen = isset( $_REQUEST['payment-mode'] ) ? sanitize_text_field( $_REQUEST['payment-mode'] ) : $chosen; |
|
242 | + $chosen = isset( $_REQUEST['payment-mode'] ) ? sanitize_text_field( $_REQUEST['payment-mode'] ) : $chosen; |
|
243 | 243 | |
244 | - if ( false !== $chosen ) { |
|
245 | - $chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen ); |
|
246 | - } |
|
244 | + if ( false !== $chosen ) { |
|
245 | + $chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen ); |
|
246 | + } |
|
247 | 247 | |
248 | - if ( ! empty ( $chosen ) ) { |
|
249 | - $enabled_gateway = urldecode( $chosen ); |
|
250 | - } else if ( !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) { |
|
251 | - $enabled_gateway = 'manual'; |
|
252 | - } else { |
|
253 | - $enabled_gateway = wpinv_get_default_gateway(); |
|
254 | - } |
|
248 | + if ( ! empty ( $chosen ) ) { |
|
249 | + $enabled_gateway = urldecode( $chosen ); |
|
250 | + } else if ( !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) { |
|
251 | + $enabled_gateway = 'manual'; |
|
252 | + } else { |
|
253 | + $enabled_gateway = wpinv_get_default_gateway(); |
|
254 | + } |
|
255 | 255 | |
256 | 256 | if ( !wpinv_is_gateway_active( $enabled_gateway ) && !empty( $gateways ) ) { |
257 | 257 | if(wpinv_is_gateway_active( wpinv_get_default_gateway()) ){ |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | |
263 | 263 | } |
264 | 264 | |
265 | - return apply_filters( 'wpinv_chosen_gateway', $enabled_gateway ); |
|
265 | + return apply_filters( 'wpinv_chosen_gateway', $enabled_gateway ); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | function wpinv_record_gateway_error( $title = '', $message = '' ) { |
@@ -270,21 +270,21 @@ discard block |
||
270 | 270 | } |
271 | 271 | |
272 | 272 | function wpinv_count_sales_by_gateway( $gateway_id = 'paypal', $status = 'publish' ) { |
273 | - $ret = 0; |
|
274 | - $args = array( |
|
275 | - 'meta_key' => '_wpinv_gateway', |
|
276 | - 'meta_value' => $gateway_id, |
|
277 | - 'nopaging' => true, |
|
278 | - 'post_type' => 'wpi_invoice', |
|
279 | - 'post_status' => $status, |
|
280 | - 'fields' => 'ids' |
|
281 | - ); |
|
282 | - |
|
283 | - $payments = new WP_Query( $args ); |
|
284 | - |
|
285 | - if( $payments ) |
|
286 | - $ret = $payments->post_count; |
|
287 | - return $ret; |
|
273 | + $ret = 0; |
|
274 | + $args = array( |
|
275 | + 'meta_key' => '_wpinv_gateway', |
|
276 | + 'meta_value' => $gateway_id, |
|
277 | + 'nopaging' => true, |
|
278 | + 'post_type' => 'wpi_invoice', |
|
279 | + 'post_status' => $status, |
|
280 | + 'fields' => 'ids' |
|
281 | + ); |
|
282 | + |
|
283 | + $payments = new WP_Query( $args ); |
|
284 | + |
|
285 | + if( $payments ) |
|
286 | + $ret = $payments->post_count; |
|
287 | + return $ret; |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | function wpinv_settings_update_gateways( $input ) { |
@@ -13,94 +13,94 @@ discard block |
||
13 | 13 | class GetPaid_Paypal_Gateway extends GetPaid_Payment_Gateway { |
14 | 14 | |
15 | 15 | /** |
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | 20 | public $id = 'paypal'; |
21 | 21 | |
22 | 22 | /** |
23 | - * An array of features that this gateway supports. |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
23 | + * An array of features that this gateway supports. |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | 27 | protected $supports = array( 'subscription', 'sandbox' ); |
28 | 28 | |
29 | 29 | /** |
30 | - * Payment method order. |
|
31 | - * |
|
32 | - * @var int |
|
33 | - */ |
|
30 | + * Payment method order. |
|
31 | + * |
|
32 | + * @var int |
|
33 | + */ |
|
34 | 34 | public $order = 1; |
35 | 35 | |
36 | 36 | /** |
37 | - * Stores line items to send to PayPal. |
|
38 | - * |
|
39 | - * @var array |
|
40 | - */ |
|
37 | + * Stores line items to send to PayPal. |
|
38 | + * |
|
39 | + * @var array |
|
40 | + */ |
|
41 | 41 | protected $line_items = array(); |
42 | 42 | |
43 | 43 | /** |
44 | - * Endpoint for requests from PayPal. |
|
45 | - * |
|
46 | - * @var string |
|
47 | - */ |
|
48 | - protected $notify_url; |
|
49 | - |
|
50 | - /** |
|
51 | - * Endpoint for requests to PayPal. |
|
52 | - * |
|
53 | - * @var string |
|
54 | - */ |
|
44 | + * Endpoint for requests from PayPal. |
|
45 | + * |
|
46 | + * @var string |
|
47 | + */ |
|
48 | + protected $notify_url; |
|
49 | + |
|
50 | + /** |
|
51 | + * Endpoint for requests to PayPal. |
|
52 | + * |
|
53 | + * @var string |
|
54 | + */ |
|
55 | 55 | protected $endpoint; |
56 | 56 | |
57 | 57 | /** |
58 | - * Currencies this gateway is allowed for. |
|
59 | - * |
|
60 | - * @var array |
|
61 | - */ |
|
62 | - public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
58 | + * Currencies this gateway is allowed for. |
|
59 | + * |
|
60 | + * @var array |
|
61 | + */ |
|
62 | + public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
63 | 63 | |
64 | 64 | /** |
65 | - * URL to view a transaction. |
|
66 | - * |
|
67 | - * @var string |
|
68 | - */ |
|
65 | + * URL to view a transaction. |
|
66 | + * |
|
67 | + * @var string |
|
68 | + */ |
|
69 | 69 | public $view_transaction_url = 'https://www.{sandbox}paypal.com/activity/payment/%s'; |
70 | 70 | |
71 | 71 | /** |
72 | - * URL to view a subscription. |
|
73 | - * |
|
74 | - * @var string |
|
75 | - */ |
|
76 | - public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
72 | + * URL to view a subscription. |
|
73 | + * |
|
74 | + * @var string |
|
75 | + */ |
|
76 | + public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
77 | 77 | |
78 | 78 | /** |
79 | - * Class constructor. |
|
80 | - */ |
|
81 | - public function __construct() { |
|
79 | + * Class constructor. |
|
80 | + */ |
|
81 | + public function __construct() { |
|
82 | 82 | |
83 | 83 | $this->title = __( 'PayPal Standard', 'invoicing' ); |
84 | 84 | $this->method_title = __( 'PayPal Standard', 'invoicing' ); |
85 | 85 | $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' ); |
86 | 86 | $this->notify_url = wpinv_get_ipn_url( $this->id ); |
87 | 87 | |
88 | - add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
88 | + add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
89 | 89 | add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) ); |
90 | 90 | |
91 | 91 | parent::__construct(); |
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
95 | - * Process Payment. |
|
96 | - * |
|
97 | - * |
|
98 | - * @param WPInv_Invoice $invoice Invoice. |
|
99 | - * @param array $submission_data Posted checkout fields. |
|
100 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
101 | - * @return array |
|
102 | - */ |
|
103 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
95 | + * Process Payment. |
|
96 | + * |
|
97 | + * |
|
98 | + * @param WPInv_Invoice $invoice Invoice. |
|
99 | + * @param array $submission_data Posted checkout fields. |
|
100 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
101 | + * @return array |
|
102 | + */ |
|
103 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
104 | 104 | |
105 | 105 | // Get redirect url. |
106 | 106 | $paypal_redirect = $this->get_request_url( $invoice ); |
@@ -123,15 +123,15 @@ discard block |
||
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
126 | - * Get the PayPal request URL for an invoice. |
|
127 | - * |
|
128 | - * @param WPInv_Invoice $invoice Invoice object. |
|
129 | - * @return string |
|
130 | - */ |
|
131 | - public function get_request_url( $invoice ) { |
|
126 | + * Get the PayPal request URL for an invoice. |
|
127 | + * |
|
128 | + * @param WPInv_Invoice $invoice Invoice object. |
|
129 | + * @return string |
|
130 | + */ |
|
131 | + public function get_request_url( $invoice ) { |
|
132 | 132 | |
133 | 133 | // Endpoint for this request |
134 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
134 | + $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
135 | 135 | |
136 | 136 | // Retrieve paypal args. |
137 | 137 | $paypal_args = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' ); |
@@ -144,44 +144,44 @@ discard block |
||
144 | 144 | |
145 | 145 | return add_query_arg( $paypal_args, $this->endpoint ); |
146 | 146 | |
147 | - } |
|
147 | + } |
|
148 | 148 | |
149 | 149 | /** |
150 | - * Get PayPal Args for passing to PP. |
|
151 | - * |
|
152 | - * @param WPInv_Invoice $invoice Invoice object. |
|
153 | - * @return array |
|
154 | - */ |
|
155 | - protected function get_paypal_args( $invoice ) { |
|
150 | + * Get PayPal Args for passing to PP. |
|
151 | + * |
|
152 | + * @param WPInv_Invoice $invoice Invoice object. |
|
153 | + * @return array |
|
154 | + */ |
|
155 | + protected function get_paypal_args( $invoice ) { |
|
156 | 156 | |
157 | 157 | // Whether or not to send the line items as one item. |
158 | - $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', false, $invoice ); |
|
159 | - |
|
160 | - if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
161 | - $force_one_line_item = true; |
|
162 | - } |
|
163 | - |
|
164 | - $paypal_args = apply_filters( |
|
165 | - 'getpaid_paypal_args', |
|
166 | - array_merge( |
|
167 | - $this->get_transaction_args( $invoice ), |
|
168 | - $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
169 | - ), |
|
170 | - $invoice |
|
171 | - ); |
|
172 | - |
|
173 | - return $this->fix_request_length( $invoice, $paypal_args ); |
|
158 | + $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', false, $invoice ); |
|
159 | + |
|
160 | + if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
161 | + $force_one_line_item = true; |
|
162 | + } |
|
163 | + |
|
164 | + $paypal_args = apply_filters( |
|
165 | + 'getpaid_paypal_args', |
|
166 | + array_merge( |
|
167 | + $this->get_transaction_args( $invoice ), |
|
168 | + $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
169 | + ), |
|
170 | + $invoice |
|
171 | + ); |
|
172 | + |
|
173 | + return $this->fix_request_length( $invoice, $paypal_args ); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
177 | - * Get transaction args for paypal request. |
|
178 | - * |
|
179 | - * @param WPInv_Invoice $invoice Invoice object. |
|
180 | - * @return array |
|
181 | - */ |
|
182 | - protected function get_transaction_args( $invoice ) { |
|
183 | - |
|
184 | - return array( |
|
177 | + * Get transaction args for paypal request. |
|
178 | + * |
|
179 | + * @param WPInv_Invoice $invoice Invoice object. |
|
180 | + * @return array |
|
181 | + */ |
|
182 | + protected function get_transaction_args( $invoice ) { |
|
183 | + |
|
184 | + return array( |
|
185 | 185 | 'cmd' => '_cart', |
186 | 186 | 'business' => wpinv_get_option( 'paypal_email', false ), |
187 | 187 | 'no_shipping' => '1', |
@@ -206,16 +206,16 @@ discard block |
||
206 | 206 | } |
207 | 207 | |
208 | 208 | /** |
209 | - * Get line item args for paypal request. |
|
210 | - * |
|
211 | - * @param WPInv_Invoice $invoice Invoice object. |
|
212 | - * @param bool $force_one_line_item Create only one item for this invoice. |
|
213 | - * @return array |
|
214 | - */ |
|
215 | - protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
209 | + * Get line item args for paypal request. |
|
210 | + * |
|
211 | + * @param WPInv_Invoice $invoice Invoice object. |
|
212 | + * @param bool $force_one_line_item Create only one item for this invoice. |
|
213 | + * @return array |
|
214 | + */ |
|
215 | + protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
216 | 216 | |
217 | 217 | // Maybe send invoice as a single item. |
218 | - if ( $force_one_line_item ) { |
|
218 | + if ( $force_one_line_item ) { |
|
219 | 219 | return $this->get_line_item_args_single_item( $invoice ); |
220 | 220 | } |
221 | 221 | |
@@ -235,129 +235,129 @@ discard block |
||
235 | 235 | $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 ); |
236 | 236 | } |
237 | 237 | |
238 | - return array_merge( $line_item_args, $this->get_line_items() ); |
|
238 | + return array_merge( $line_item_args, $this->get_line_items() ); |
|
239 | 239 | |
240 | 240 | } |
241 | 241 | |
242 | 242 | /** |
243 | - * Get line item args for paypal request as a single line item. |
|
244 | - * |
|
245 | - * @param WPInv_Invoice $invoice Invoice object. |
|
246 | - * @return array |
|
247 | - */ |
|
248 | - protected function get_line_item_args_single_item( $invoice ) { |
|
249 | - $this->delete_line_items(); |
|
243 | + * Get line item args for paypal request as a single line item. |
|
244 | + * |
|
245 | + * @param WPInv_Invoice $invoice Invoice object. |
|
246 | + * @return array |
|
247 | + */ |
|
248 | + protected function get_line_item_args_single_item( $invoice ) { |
|
249 | + $this->delete_line_items(); |
|
250 | 250 | |
251 | 251 | $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
252 | - $this->add_line_item( $item_name, 1, wpinv_sanitize_amount( (float) $invoice->get_total(), 2 ), $invoice->get_id() ); |
|
252 | + $this->add_line_item( $item_name, 1, wpinv_sanitize_amount( (float) $invoice->get_total(), 2 ), $invoice->get_id() ); |
|
253 | 253 | |
254 | - return $this->get_line_items(); |
|
254 | + return $this->get_line_items(); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | /** |
258 | - * Return all line items. |
|
259 | - */ |
|
260 | - protected function get_line_items() { |
|
261 | - return $this->line_items; |
|
262 | - } |
|
258 | + * Return all line items. |
|
259 | + */ |
|
260 | + protected function get_line_items() { |
|
261 | + return $this->line_items; |
|
262 | + } |
|
263 | 263 | |
264 | 264 | /** |
265 | - * Remove all line items. |
|
266 | - */ |
|
267 | - protected function delete_line_items() { |
|
268 | - $this->line_items = array(); |
|
265 | + * Remove all line items. |
|
266 | + */ |
|
267 | + protected function delete_line_items() { |
|
268 | + $this->line_items = array(); |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | /** |
272 | - * Prepare line items to send to paypal. |
|
273 | - * |
|
274 | - * @param WPInv_Invoice $invoice Invoice object. |
|
275 | - */ |
|
276 | - protected function prepare_line_items( $invoice ) { |
|
277 | - $this->delete_line_items(); |
|
278 | - |
|
279 | - // Items. |
|
280 | - foreach ( $invoice->get_items() as $item ) { |
|
281 | - $amount = $invoice->get_template() == 'amount' ? $item->get_price() : $item->get_sub_total(); |
|
282 | - $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
|
283 | - $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
272 | + * Prepare line items to send to paypal. |
|
273 | + * |
|
274 | + * @param WPInv_Invoice $invoice Invoice object. |
|
275 | + */ |
|
276 | + protected function prepare_line_items( $invoice ) { |
|
277 | + $this->delete_line_items(); |
|
278 | + |
|
279 | + // Items. |
|
280 | + foreach ( $invoice->get_items() as $item ) { |
|
281 | + $amount = $invoice->get_template() == 'amount' ? $item->get_price() : $item->get_sub_total(); |
|
282 | + $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
|
283 | + $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | // Fees. |
287 | - foreach ( $invoice->get_fees() as $fee => $data ) { |
|
287 | + foreach ( $invoice->get_fees() as $fee => $data ) { |
|
288 | 288 | $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) ); |
289 | 289 | } |
290 | 290 | |
291 | 291 | } |
292 | 292 | |
293 | 293 | /** |
294 | - * Add PayPal Line Item. |
|
295 | - * |
|
296 | - * @param string $item_name Item name. |
|
297 | - * @param int $quantity Item quantity. |
|
298 | - * @param float $amount Amount. |
|
299 | - * @param string $item_number Item number. |
|
300 | - */ |
|
301 | - protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
302 | - $index = ( count( $this->line_items ) / 4 ) + 1; |
|
303 | - |
|
304 | - $item = apply_filters( |
|
305 | - 'getpaid_paypal_line_item', |
|
306 | - array( |
|
307 | - 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
308 | - 'quantity' => (int) $quantity, |
|
309 | - 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
310 | - 'item_number' => $item_number, |
|
311 | - ), |
|
312 | - $item_name, |
|
313 | - $quantity, |
|
314 | - $amount, |
|
315 | - $item_number |
|
316 | - ); |
|
317 | - |
|
318 | - $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
294 | + * Add PayPal Line Item. |
|
295 | + * |
|
296 | + * @param string $item_name Item name. |
|
297 | + * @param int $quantity Item quantity. |
|
298 | + * @param float $amount Amount. |
|
299 | + * @param string $item_number Item number. |
|
300 | + */ |
|
301 | + protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
302 | + $index = ( count( $this->line_items ) / 4 ) + 1; |
|
303 | + |
|
304 | + $item = apply_filters( |
|
305 | + 'getpaid_paypal_line_item', |
|
306 | + array( |
|
307 | + 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
308 | + 'quantity' => (int) $quantity, |
|
309 | + 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
310 | + 'item_number' => $item_number, |
|
311 | + ), |
|
312 | + $item_name, |
|
313 | + $quantity, |
|
314 | + $amount, |
|
315 | + $item_number |
|
316 | + ); |
|
317 | + |
|
318 | + $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
319 | 319 | $this->line_items[ 'quantity_' . $index ] = $item['quantity']; |
320 | 320 | |
321 | 321 | // The price or amount of the product, service, or contribution, not including shipping, handling, or tax. |
322 | - $this->line_items[ 'amount_' . $index ] = $item['amount']; |
|
323 | - $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
322 | + $this->line_items[ 'amount_' . $index ] = $item['amount']; |
|
323 | + $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | /** |
327 | - * If the default request with line items is too long, generate a new one with only one line item. |
|
328 | - * |
|
329 | - * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer. |
|
330 | - * |
|
331 | - * @param WPInv_Invoice $invoice Invoice to be sent to Paypal. |
|
332 | - * @param array $paypal_args Arguments sent to Paypal in the request. |
|
333 | - * @return array |
|
334 | - */ |
|
335 | - protected function fix_request_length( $invoice, $paypal_args ) { |
|
336 | - $max_paypal_length = 2083; |
|
337 | - $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
338 | - |
|
339 | - if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
340 | - return $paypal_args; |
|
341 | - } |
|
342 | - |
|
343 | - return apply_filters( |
|
344 | - 'getpaid_paypal_args', |
|
345 | - array_merge( |
|
346 | - $this->get_transaction_args( $invoice ), |
|
347 | - $this->get_line_item_args( $invoice, true ) |
|
348 | - ), |
|
349 | - $invoice |
|
350 | - ); |
|
327 | + * If the default request with line items is too long, generate a new one with only one line item. |
|
328 | + * |
|
329 | + * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer. |
|
330 | + * |
|
331 | + * @param WPInv_Invoice $invoice Invoice to be sent to Paypal. |
|
332 | + * @param array $paypal_args Arguments sent to Paypal in the request. |
|
333 | + * @return array |
|
334 | + */ |
|
335 | + protected function fix_request_length( $invoice, $paypal_args ) { |
|
336 | + $max_paypal_length = 2083; |
|
337 | + $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
338 | + |
|
339 | + if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
340 | + return $paypal_args; |
|
341 | + } |
|
342 | + |
|
343 | + return apply_filters( |
|
344 | + 'getpaid_paypal_args', |
|
345 | + array_merge( |
|
346 | + $this->get_transaction_args( $invoice ), |
|
347 | + $this->get_line_item_args( $invoice, true ) |
|
348 | + ), |
|
349 | + $invoice |
|
350 | + ); |
|
351 | 351 | |
352 | 352 | } |
353 | 353 | |
354 | 354 | /** |
355 | - * Processes recurring invoices. |
|
356 | - * |
|
357 | - * @param array $paypal_args PayPal args. |
|
358 | - * @param WPInv_Invoice $invoice Invoice object. |
|
359 | - */ |
|
360 | - public function process_subscription( $paypal_args, $invoice ) { |
|
355 | + * Processes recurring invoices. |
|
356 | + * |
|
357 | + * @param array $paypal_args PayPal args. |
|
358 | + * @param WPInv_Invoice $invoice Invoice object. |
|
359 | + */ |
|
360 | + public function process_subscription( $paypal_args, $invoice ) { |
|
361 | 361 | |
362 | 362 | // Make sure this is a subscription. |
363 | 363 | if ( ! $invoice->is_recurring() || ! $subscription = wpinv_get_subscription( $invoice ) ) { |
@@ -382,11 +382,11 @@ discard block |
||
382 | 382 | |
383 | 383 | $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount; |
384 | 384 | |
385 | - // Trial period length. |
|
386 | - $paypal_args['p1'] = $subscription_item->get_trial_interval(); |
|
385 | + // Trial period length. |
|
386 | + $paypal_args['p1'] = $subscription_item->get_trial_interval(); |
|
387 | 387 | |
388 | - // Trial period. |
|
389 | - $paypal_args['t1'] = $subscription_item->get_trial_period(); |
|
388 | + // Trial period. |
|
389 | + $paypal_args['t1'] = $subscription_item->get_trial_period(); |
|
390 | 390 | |
391 | 391 | } else if ( $initial_amount != $recurring_amount ) { |
392 | 392 | |
@@ -409,40 +409,40 @@ discard block |
||
409 | 409 | } |
410 | 410 | |
411 | 411 | // We have a recurring payment |
412 | - if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
412 | + if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
413 | 413 | |
414 | - // Subscription price |
|
415 | - $paypal_args['a3'] = $recurring_amount; |
|
414 | + // Subscription price |
|
415 | + $paypal_args['a3'] = $recurring_amount; |
|
416 | 416 | |
417 | - // Subscription duration |
|
418 | - $paypal_args['p3'] = $interval; |
|
417 | + // Subscription duration |
|
418 | + $paypal_args['p3'] = $interval; |
|
419 | 419 | |
420 | - // Subscription period |
|
421 | - $paypal_args['t3'] = $period; |
|
420 | + // Subscription period |
|
421 | + $paypal_args['t3'] = $period; |
|
422 | 422 | |
423 | 423 | } |
424 | 424 | |
425 | 425 | // Recurring payments |
426 | - if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
426 | + if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
427 | 427 | |
428 | - // Non-recurring payments |
|
429 | - $paypal_args['src'] = 0; |
|
428 | + // Non-recurring payments |
|
429 | + $paypal_args['src'] = 0; |
|
430 | 430 | |
431 | - } else { |
|
431 | + } else { |
|
432 | 432 | |
433 | - $paypal_args['src'] = 1; |
|
433 | + $paypal_args['src'] = 1; |
|
434 | 434 | |
435 | - if ( $bill_times > 0 ) { |
|
435 | + if ( $bill_times > 0 ) { |
|
436 | 436 | |
437 | - // An initial period is being used to charge a sign-up fee |
|
438 | - if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
439 | - $bill_times--; |
|
440 | - } |
|
437 | + // An initial period is being used to charge a sign-up fee |
|
438 | + if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
439 | + $bill_times--; |
|
440 | + } |
|
441 | 441 | |
442 | 442 | // Make sure it's not over the max of 52 |
443 | 443 | $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
444 | 444 | |
445 | - } |
|
445 | + } |
|
446 | 446 | } |
447 | 447 | |
448 | 448 | // Force return URL so that order description & instructions display |
@@ -458,19 +458,19 @@ discard block |
||
458 | 458 | } |
459 | 459 | |
460 | 460 | return apply_filters( |
461 | - 'getpaid_paypal_subscription_args', |
|
462 | - $paypal_args, |
|
463 | - $invoice |
|
461 | + 'getpaid_paypal_subscription_args', |
|
462 | + $paypal_args, |
|
463 | + $invoice |
|
464 | 464 | ); |
465 | 465 | |
466 | 466 | } |
467 | 467 | |
468 | 468 | /** |
469 | - * Processes ipns and marks payments as complete. |
|
470 | - * |
|
471 | - * @return void |
|
472 | - */ |
|
473 | - public function verify_ipn() { |
|
469 | + * Processes ipns and marks payments as complete. |
|
470 | + * |
|
471 | + * @return void |
|
472 | + */ |
|
473 | + public function verify_ipn() { |
|
474 | 474 | new GetPaid_Paypal_Gateway_IPN_Handler( $this ); |
475 | 475 | } |
476 | 476 | |
@@ -480,10 +480,10 @@ discard block |
||
480 | 480 | public function sandbox_notice() { |
481 | 481 | |
482 | 482 | return sprintf( |
483 | - __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ), |
|
484 | - '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
|
485 | - '</a>' |
|
486 | - ); |
|
483 | + __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ), |
|
484 | + '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
|
485 | + '</a>' |
|
486 | + ); |
|
487 | 487 | |
488 | 488 | } |
489 | 489 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
3 | - exit; |
|
3 | + exit; |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -10,55 +10,55 @@ discard block |
||
10 | 10 | class GetPaid_Payment_Form extends GetPaid_Data { |
11 | 11 | |
12 | 12 | /** |
13 | - * Which data store to load. |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
13 | + * Which data store to load. |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | 17 | protected $data_store_name = 'payment_form'; |
18 | 18 | |
19 | 19 | /** |
20 | - * This is the name of this object type. |
|
21 | - * |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - protected $object_type = 'payment_form'; |
|
20 | + * This is the name of this object type. |
|
21 | + * |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + protected $object_type = 'payment_form'; |
|
25 | 25 | |
26 | 26 | /** |
27 | - * Form Data array. This is the core form data exposed in APIs. |
|
28 | - * |
|
29 | - * @since 1.0.19 |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - protected $data = array( |
|
33 | - 'status' => 'draft', |
|
34 | - 'version' => '', |
|
35 | - 'date_created' => null, |
|
27 | + * Form Data array. This is the core form data exposed in APIs. |
|
28 | + * |
|
29 | + * @since 1.0.19 |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + protected $data = array( |
|
33 | + 'status' => 'draft', |
|
34 | + 'version' => '', |
|
35 | + 'date_created' => null, |
|
36 | 36 | 'date_modified' => null, |
37 | 37 | 'name' => '', |
38 | 38 | 'author' => 1, |
39 | 39 | 'elements' => null, |
40 | - 'items' => null, |
|
41 | - 'earned' => 0, |
|
42 | - 'refunded' => 0, |
|
43 | - 'cancelled' => 0, |
|
44 | - 'failed' => 0, |
|
45 | - ); |
|
46 | - |
|
47 | - /** |
|
48 | - * Stores meta in cache for future reads. |
|
49 | - * |
|
50 | - * A group must be set to to enable caching. |
|
51 | - * |
|
52 | - * @var string |
|
53 | - */ |
|
54 | - protected $cache_group = 'getpaid_forms'; |
|
55 | - |
|
56 | - /** |
|
57 | - * Stores a reference to the invoice if the form is for an invoice.. |
|
58 | - * |
|
59 | - * @var WPInv_Invoice |
|
60 | - */ |
|
61 | - public $invoice = 0; |
|
40 | + 'items' => null, |
|
41 | + 'earned' => 0, |
|
42 | + 'refunded' => 0, |
|
43 | + 'cancelled' => 0, |
|
44 | + 'failed' => 0, |
|
45 | + ); |
|
46 | + |
|
47 | + /** |
|
48 | + * Stores meta in cache for future reads. |
|
49 | + * |
|
50 | + * A group must be set to to enable caching. |
|
51 | + * |
|
52 | + * @var string |
|
53 | + */ |
|
54 | + protected $cache_group = 'getpaid_forms'; |
|
55 | + |
|
56 | + /** |
|
57 | + * Stores a reference to the invoice if the form is for an invoice.. |
|
58 | + * |
|
59 | + * @var WPInv_Invoice |
|
60 | + */ |
|
61 | + public $invoice = 0; |
|
62 | 62 | |
63 | 63 | /** |
64 | 64 | * Stores a reference to the original WP_Post object |
@@ -68,35 +68,35 @@ discard block |
||
68 | 68 | protected $post = null; |
69 | 69 | |
70 | 70 | /** |
71 | - * Get the form if ID is passed, otherwise the form is new and empty. |
|
72 | - * |
|
73 | - * @param int|object|GetPaid_Payment_Form|WP_Post $form Form to read. |
|
74 | - */ |
|
75 | - public function __construct( $form = 0 ) { |
|
76 | - parent::__construct( $form ); |
|
71 | + * Get the form if ID is passed, otherwise the form is new and empty. |
|
72 | + * |
|
73 | + * @param int|object|GetPaid_Payment_Form|WP_Post $form Form to read. |
|
74 | + */ |
|
75 | + public function __construct( $form = 0 ) { |
|
76 | + parent::__construct( $form ); |
|
77 | 77 | |
78 | - if ( is_numeric( $form ) && $form > 0 ) { |
|
79 | - $this->set_id( $form ); |
|
80 | - } elseif ( $form instanceof self ) { |
|
78 | + if ( is_numeric( $form ) && $form > 0 ) { |
|
79 | + $this->set_id( $form ); |
|
80 | + } elseif ( $form instanceof self ) { |
|
81 | 81 | |
82 | - $this->set_id( $form->get_id() ); |
|
83 | - $this->invoice = $form->invoice; |
|
82 | + $this->set_id( $form->get_id() ); |
|
83 | + $this->invoice = $form->invoice; |
|
84 | 84 | |
85 | - } elseif ( ! empty( $form->ID ) ) { |
|
86 | - $this->set_id( $form->ID ); |
|
87 | - } else { |
|
88 | - $this->set_object_read( true ); |
|
89 | - } |
|
85 | + } elseif ( ! empty( $form->ID ) ) { |
|
86 | + $this->set_id( $form->ID ); |
|
87 | + } else { |
|
88 | + $this->set_object_read( true ); |
|
89 | + } |
|
90 | 90 | |
91 | 91 | // Load the datastore. |
92 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
92 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
93 | 93 | |
94 | - if ( $this->get_id() > 0 ) { |
|
94 | + if ( $this->get_id() > 0 ) { |
|
95 | 95 | $this->post = get_post( $this->get_id() ); |
96 | - $this->data_store->read( $this ); |
|
96 | + $this->data_store->read( $this ); |
|
97 | 97 | } |
98 | 98 | |
99 | - } |
|
99 | + } |
|
100 | 100 | |
101 | 101 | /* |
102 | 102 | |-------------------------------------------------------------------------- |
@@ -114,358 +114,358 @@ discard block |
||
114 | 114 | */ |
115 | 115 | |
116 | 116 | /** |
117 | - * Get plugin version when the form was created. |
|
118 | - * |
|
119 | - * @since 1.0.19 |
|
120 | - * @param string $context View or edit context. |
|
121 | - * @return string |
|
122 | - */ |
|
123 | - public function get_version( $context = 'view' ) { |
|
124 | - return $this->get_prop( 'version', $context ); |
|
117 | + * Get plugin version when the form was created. |
|
118 | + * |
|
119 | + * @since 1.0.19 |
|
120 | + * @param string $context View or edit context. |
|
121 | + * @return string |
|
122 | + */ |
|
123 | + public function get_version( $context = 'view' ) { |
|
124 | + return $this->get_prop( 'version', $context ); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
128 | - * Get date when the form was created. |
|
129 | - * |
|
130 | - * @since 1.0.19 |
|
131 | - * @param string $context View or edit context. |
|
132 | - * @return string |
|
133 | - */ |
|
134 | - public function get_date_created( $context = 'view' ) { |
|
135 | - return $this->get_prop( 'date_created', $context ); |
|
128 | + * Get date when the form was created. |
|
129 | + * |
|
130 | + * @since 1.0.19 |
|
131 | + * @param string $context View or edit context. |
|
132 | + * @return string |
|
133 | + */ |
|
134 | + public function get_date_created( $context = 'view' ) { |
|
135 | + return $this->get_prop( 'date_created', $context ); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
139 | - * Get GMT date when the form was created. |
|
140 | - * |
|
141 | - * @since 1.0.19 |
|
142 | - * @param string $context View or edit context. |
|
143 | - * @return string |
|
144 | - */ |
|
145 | - public function get_date_created_gmt( $context = 'view' ) { |
|
139 | + * Get GMT date when the form was created. |
|
140 | + * |
|
141 | + * @since 1.0.19 |
|
142 | + * @param string $context View or edit context. |
|
143 | + * @return string |
|
144 | + */ |
|
145 | + public function get_date_created_gmt( $context = 'view' ) { |
|
146 | 146 | $date = $this->get_date_created( $context ); |
147 | 147 | |
148 | 148 | if ( $date ) { |
149 | 149 | $date = get_gmt_from_date( $date ); |
150 | 150 | } |
151 | - return $date; |
|
151 | + return $date; |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
155 | - * Get date when the form was last modified. |
|
156 | - * |
|
157 | - * @since 1.0.19 |
|
158 | - * @param string $context View or edit context. |
|
159 | - * @return string |
|
160 | - */ |
|
161 | - public function get_date_modified( $context = 'view' ) { |
|
162 | - return $this->get_prop( 'date_modified', $context ); |
|
155 | + * Get date when the form was last modified. |
|
156 | + * |
|
157 | + * @since 1.0.19 |
|
158 | + * @param string $context View or edit context. |
|
159 | + * @return string |
|
160 | + */ |
|
161 | + public function get_date_modified( $context = 'view' ) { |
|
162 | + return $this->get_prop( 'date_modified', $context ); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
166 | - * Get GMT date when the form was last modified. |
|
167 | - * |
|
168 | - * @since 1.0.19 |
|
169 | - * @param string $context View or edit context. |
|
170 | - * @return string |
|
171 | - */ |
|
172 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
166 | + * Get GMT date when the form was last modified. |
|
167 | + * |
|
168 | + * @since 1.0.19 |
|
169 | + * @param string $context View or edit context. |
|
170 | + * @return string |
|
171 | + */ |
|
172 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
173 | 173 | $date = $this->get_date_modified( $context ); |
174 | 174 | |
175 | 175 | if ( $date ) { |
176 | 176 | $date = get_gmt_from_date( $date ); |
177 | 177 | } |
178 | - return $date; |
|
178 | + return $date; |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
182 | - * Get the form name. |
|
183 | - * |
|
184 | - * @since 1.0.19 |
|
185 | - * @param string $context View or edit context. |
|
186 | - * @return string |
|
187 | - */ |
|
188 | - public function get_name( $context = 'view' ) { |
|
189 | - return $this->get_prop( 'name', $context ); |
|
182 | + * Get the form name. |
|
183 | + * |
|
184 | + * @since 1.0.19 |
|
185 | + * @param string $context View or edit context. |
|
186 | + * @return string |
|
187 | + */ |
|
188 | + public function get_name( $context = 'view' ) { |
|
189 | + return $this->get_prop( 'name', $context ); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
193 | - * Alias of self::get_name(). |
|
194 | - * |
|
195 | - * @since 1.0.19 |
|
196 | - * @param string $context View or edit context. |
|
197 | - * @return string |
|
198 | - */ |
|
199 | - public function get_title( $context = 'view' ) { |
|
200 | - return $this->get_name( $context ); |
|
201 | - } |
|
193 | + * Alias of self::get_name(). |
|
194 | + * |
|
195 | + * @since 1.0.19 |
|
196 | + * @param string $context View or edit context. |
|
197 | + * @return string |
|
198 | + */ |
|
199 | + public function get_title( $context = 'view' ) { |
|
200 | + return $this->get_name( $context ); |
|
201 | + } |
|
202 | 202 | |
203 | 203 | /** |
204 | - * Get the owner of the form. |
|
205 | - * |
|
206 | - * @since 1.0.19 |
|
207 | - * @param string $context View or edit context. |
|
208 | - * @return int |
|
209 | - */ |
|
210 | - public function get_author( $context = 'view' ) { |
|
211 | - return (int) $this->get_prop( 'author', $context ); |
|
204 | + * Get the owner of the form. |
|
205 | + * |
|
206 | + * @since 1.0.19 |
|
207 | + * @param string $context View or edit context. |
|
208 | + * @return int |
|
209 | + */ |
|
210 | + public function get_author( $context = 'view' ) { |
|
211 | + return (int) $this->get_prop( 'author', $context ); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
215 | - * Get the elements that make up the form. |
|
216 | - * |
|
217 | - * @since 1.0.19 |
|
218 | - * @param string $context View or edit context. |
|
219 | - * @return array |
|
220 | - */ |
|
221 | - public function get_elements( $context = 'view' ) { |
|
222 | - $elements = $this->get_prop( 'elements', $context ); |
|
215 | + * Get the elements that make up the form. |
|
216 | + * |
|
217 | + * @since 1.0.19 |
|
218 | + * @param string $context View or edit context. |
|
219 | + * @return array |
|
220 | + */ |
|
221 | + public function get_elements( $context = 'view' ) { |
|
222 | + $elements = $this->get_prop( 'elements', $context ); |
|
223 | 223 | |
224 | - if ( empty( $elements ) || ! is_array( $elements ) ) { |
|
224 | + if ( empty( $elements ) || ! is_array( $elements ) ) { |
|
225 | 225 | return wpinv_get_data( 'sample-payment-form' ); |
226 | - } |
|
226 | + } |
|
227 | 227 | |
228 | - // Ensure that all required elements exist. |
|
229 | - $_elements = array(); |
|
230 | - foreach ( $elements as $element ) { |
|
228 | + // Ensure that all required elements exist. |
|
229 | + $_elements = array(); |
|
230 | + foreach ( $elements as $element ) { |
|
231 | 231 | |
232 | - if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) { |
|
232 | + if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) { |
|
233 | 233 | |
234 | - $_elements[] = array( |
|
235 | - 'text' => __( 'Select Payment Method', 'invoicing' ), |
|
236 | - 'id' => 'gtscicd', |
|
237 | - 'name' => 'gtscicd', |
|
238 | - 'type' => 'gateway_select', |
|
239 | - 'premade' => true |
|
234 | + $_elements[] = array( |
|
235 | + 'text' => __( 'Select Payment Method', 'invoicing' ), |
|
236 | + 'id' => 'gtscicd', |
|
237 | + 'name' => 'gtscicd', |
|
238 | + 'type' => 'gateway_select', |
|
239 | + 'premade' => true |
|
240 | 240 | |
241 | - ); |
|
241 | + ); |
|
242 | 242 | |
243 | - } |
|
243 | + } |
|
244 | 244 | |
245 | - $_elements[] = $element; |
|
245 | + $_elements[] = $element; |
|
246 | 246 | |
247 | - } |
|
247 | + } |
|
248 | 248 | |
249 | 249 | return $_elements; |
250 | - } |
|
251 | - |
|
252 | - /** |
|
253 | - * Get the items sold via the form. |
|
254 | - * |
|
255 | - * @since 1.0.19 |
|
256 | - * @param string $context View or edit context. |
|
257 | - * @param string $return objects or arrays. |
|
258 | - * @return GetPaid_Form_Item[] |
|
259 | - */ |
|
260 | - public function get_items( $context = 'view', $return = 'objects' ) { |
|
261 | - $items = $this->get_prop( 'items', $context ); |
|
262 | - |
|
263 | - if ( empty( $items ) || ! is_array( $items ) ) { |
|
250 | + } |
|
251 | + |
|
252 | + /** |
|
253 | + * Get the items sold via the form. |
|
254 | + * |
|
255 | + * @since 1.0.19 |
|
256 | + * @param string $context View or edit context. |
|
257 | + * @param string $return objects or arrays. |
|
258 | + * @return GetPaid_Form_Item[] |
|
259 | + */ |
|
260 | + public function get_items( $context = 'view', $return = 'objects' ) { |
|
261 | + $items = $this->get_prop( 'items', $context ); |
|
262 | + |
|
263 | + if ( empty( $items ) || ! is_array( $items ) ) { |
|
264 | 264 | $items = wpinv_get_data( 'sample-payment-form-items' ); |
265 | - } |
|
265 | + } |
|
266 | + |
|
267 | + // Convert the items. |
|
268 | + $prepared = array(); |
|
266 | 269 | |
267 | - // Convert the items. |
|
268 | - $prepared = array(); |
|
270 | + foreach ( $items as $key => $value ) { |
|
269 | 271 | |
270 | - foreach ( $items as $key => $value ) { |
|
272 | + // Form items. |
|
273 | + if ( $value instanceof GetPaid_Form_Item ) { |
|
271 | 274 | |
272 | - // Form items. |
|
273 | - if ( $value instanceof GetPaid_Form_Item ) { |
|
275 | + if ( $value->can_purchase() ) { |
|
276 | + $prepared[] = $value; |
|
277 | + } |
|
274 | 278 | |
275 | - if ( $value->can_purchase() ) { |
|
276 | - $prepared[] = $value; |
|
277 | - } |
|
279 | + continue; |
|
278 | 280 | |
279 | - continue; |
|
281 | + } |
|
280 | 282 | |
281 | - } |
|
283 | + // $item_id => $quantity (buy buttons) |
|
284 | + if ( is_numeric( $key ) && is_numeric( $value ) ) { |
|
285 | + $item = new GetPaid_Form_Item( $key ); |
|
282 | 286 | |
283 | - // $item_id => $quantity (buy buttons) |
|
284 | - if ( is_numeric( $key ) && is_numeric( $value ) ) { |
|
285 | - $item = new GetPaid_Form_Item( $key ); |
|
287 | + if ( $item->can_purchase() ) { |
|
286 | 288 | |
287 | - if ( $item->can_purchase() ) { |
|
289 | + $value = (int) $value; |
|
290 | + $item->set_quantity( $value ); |
|
291 | + if ( 0 == $value ) { |
|
292 | + $item->set_quantity( 1 ); |
|
293 | + $item->set_allow_quantities( true ); |
|
294 | + } |
|
288 | 295 | |
289 | - $value = (int) $value; |
|
290 | - $item->set_quantity( $value ); |
|
291 | - if ( 0 == $value ) { |
|
292 | - $item->set_quantity( 1 ); |
|
293 | - $item->set_allow_quantities( true ); |
|
294 | - } |
|
296 | + $prepared[] = $item; |
|
297 | + } |
|
295 | 298 | |
296 | - $prepared[] = $item; |
|
297 | - } |
|
299 | + continue; |
|
300 | + } |
|
298 | 301 | |
299 | - continue; |
|
300 | - } |
|
302 | + // Items saved via payment forms editor. |
|
303 | + if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
301 | 304 | |
302 | - // Items saved via payment forms editor. |
|
303 | - if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
305 | + $item = new GetPaid_Form_Item( $value['id'] ); |
|
304 | 306 | |
305 | - $item = new GetPaid_Form_Item( $value['id'] ); |
|
307 | + if ( ! $item->can_purchase() ) { |
|
308 | + continue; |
|
309 | + } |
|
306 | 310 | |
307 | - if ( ! $item->can_purchase() ) { |
|
308 | - continue; |
|
309 | - } |
|
311 | + // Sub-total (Cart items). |
|
312 | + if ( isset( $value['subtotal'] ) ) { |
|
313 | + $item->set_price( $value['subtotal'] ); |
|
314 | + } |
|
310 | 315 | |
311 | - // Sub-total (Cart items). |
|
312 | - if ( isset( $value['subtotal'] ) ) { |
|
313 | - $item->set_price( $value['subtotal'] ); |
|
314 | - } |
|
316 | + if ( isset( $value['quantity'] ) ) { |
|
317 | + $item->set_quantity( $value['quantity'] ); |
|
318 | + } |
|
315 | 319 | |
316 | - if ( isset( $value['quantity'] ) ) { |
|
317 | - $item->set_quantity( $value['quantity'] ); |
|
318 | - } |
|
320 | + if ( isset( $value['allow_quantities'] ) ) { |
|
321 | + $item->set_allow_quantities( $value['allow_quantities'] ); |
|
322 | + } |
|
319 | 323 | |
320 | - if ( isset( $value['allow_quantities'] ) ) { |
|
321 | - $item->set_allow_quantities( $value['allow_quantities'] ); |
|
322 | - } |
|
324 | + if ( isset( $value['required'] ) ) { |
|
325 | + $item->set_is_required( $value['required'] ); |
|
326 | + } |
|
323 | 327 | |
324 | - if ( isset( $value['required'] ) ) { |
|
325 | - $item->set_is_required( $value['required'] ); |
|
326 | - } |
|
328 | + if ( isset( $value['description'] ) ) { |
|
329 | + $item->set_custom_description( $value['description'] ); |
|
330 | + } |
|
327 | 331 | |
328 | - if ( isset( $value['description'] ) ) { |
|
329 | - $item->set_custom_description( $value['description'] ); |
|
330 | - } |
|
332 | + $prepared[] = $item; |
|
333 | + continue; |
|
331 | 334 | |
332 | - $prepared[] = $item; |
|
333 | - continue; |
|
335 | + } |
|
336 | + |
|
337 | + // $item_id => array( 'price' => 10 ) (item variations) |
|
338 | + if ( is_numeric( $key ) && is_array( $value ) ) { |
|
339 | + $item = new GetPaid_Form_Item( $key ); |
|
340 | + |
|
341 | + if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) { |
|
342 | + $item->set_price( $value['price'] ); |
|
343 | + } |
|
344 | + |
|
345 | + if ( $item->can_purchase() ) { |
|
346 | + $prepared[] = $item; |
|
347 | + } |
|
348 | + |
|
349 | + continue; |
|
350 | + } |
|
351 | + |
|
352 | + } |
|
353 | + |
|
354 | + if ( 'objects' == $return && 'view' == $context ) { |
|
355 | + return $prepared; |
|
356 | + } |
|
357 | + |
|
358 | + $items = array(); |
|
359 | + foreach ( $prepared as $item ) { |
|
360 | + $items[] = $item->prepare_data_for_use(); |
|
361 | + } |
|
362 | + |
|
363 | + return $items; |
|
364 | + } |
|
365 | + |
|
366 | + /** |
|
367 | + * Get a single item belonging to the form. |
|
368 | + * |
|
369 | + * @since 1.0.19 |
|
370 | + * @param int $item_id The item id to return. |
|
371 | + * @return GetPaid_Form_Item|bool |
|
372 | + */ |
|
373 | + public function get_item( $item_id ) { |
|
374 | + |
|
375 | + if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
376 | + return false; |
|
377 | + } |
|
378 | + |
|
379 | + foreach( $this->get_items() as $item ) { |
|
380 | + if ( $item->get_id() == (int) $item_id ) { |
|
381 | + return $item; |
|
382 | + } |
|
383 | + } |
|
384 | + |
|
385 | + return false; |
|
386 | + |
|
387 | + } |
|
388 | + |
|
389 | + /** |
|
390 | + * Gets a single element. |
|
391 | + * |
|
392 | + * @since 1.0.19 |
|
393 | + * @param string $element_type The element type to return. |
|
394 | + * @return array|bool |
|
395 | + */ |
|
396 | + public function get_element_type( $element_type ) { |
|
397 | + |
|
398 | + if ( empty( $element_type ) || ! is_scalar( $element_type ) ) { |
|
399 | + return false; |
|
400 | + } |
|
401 | + |
|
402 | + foreach ( $this->get_prop( 'elements' ) as $element ) { |
|
403 | + |
|
404 | + if ( $element['type'] == $element_type ) { |
|
405 | + return $element; |
|
406 | + } |
|
407 | + |
|
408 | + } |
|
409 | + |
|
410 | + return false; |
|
411 | + |
|
412 | + } |
|
413 | + |
|
414 | + /** |
|
415 | + * Get the total amount earned via this form. |
|
416 | + * |
|
417 | + * @since 1.0.19 |
|
418 | + * @param string $context View or edit context. |
|
419 | + * @return array |
|
420 | + */ |
|
421 | + public function get_earned( $context = 'view' ) { |
|
422 | + return $this->get_prop( 'earned', $context ); |
|
423 | + } |
|
424 | + |
|
425 | + /** |
|
426 | + * Get the total amount refunded via this form. |
|
427 | + * |
|
428 | + * @since 1.0.19 |
|
429 | + * @param string $context View or edit context. |
|
430 | + * @return array |
|
431 | + */ |
|
432 | + public function get_refunded( $context = 'view' ) { |
|
433 | + return $this->get_prop( 'refunded', $context ); |
|
434 | + } |
|
334 | 435 | |
335 | - } |
|
436 | + /** |
|
437 | + * Get the total amount cancelled via this form. |
|
438 | + * |
|
439 | + * @since 1.0.19 |
|
440 | + * @param string $context View or edit context. |
|
441 | + * @return array |
|
442 | + */ |
|
443 | + public function get_cancelled( $context = 'view' ) { |
|
444 | + return $this->get_prop( 'cancelled', $context ); |
|
445 | + } |
|
336 | 446 | |
337 | - // $item_id => array( 'price' => 10 ) (item variations) |
|
338 | - if ( is_numeric( $key ) && is_array( $value ) ) { |
|
339 | - $item = new GetPaid_Form_Item( $key ); |
|
447 | + /** |
|
448 | + * Get the total amount failed via this form. |
|
449 | + * |
|
450 | + * @since 1.0.19 |
|
451 | + * @param string $context View or edit context. |
|
452 | + * @return array |
|
453 | + */ |
|
454 | + public function get_failed( $context = 'view' ) { |
|
455 | + return $this->get_prop( 'failed', $context ); |
|
456 | + } |
|
340 | 457 | |
341 | - if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) { |
|
342 | - $item->set_price( $value['price'] ); |
|
343 | - } |
|
344 | - |
|
345 | - if ( $item->can_purchase() ) { |
|
346 | - $prepared[] = $item; |
|
347 | - } |
|
348 | - |
|
349 | - continue; |
|
350 | - } |
|
351 | - |
|
352 | - } |
|
353 | - |
|
354 | - if ( 'objects' == $return && 'view' == $context ) { |
|
355 | - return $prepared; |
|
356 | - } |
|
357 | - |
|
358 | - $items = array(); |
|
359 | - foreach ( $prepared as $item ) { |
|
360 | - $items[] = $item->prepare_data_for_use(); |
|
361 | - } |
|
362 | - |
|
363 | - return $items; |
|
364 | - } |
|
365 | - |
|
366 | - /** |
|
367 | - * Get a single item belonging to the form. |
|
368 | - * |
|
369 | - * @since 1.0.19 |
|
370 | - * @param int $item_id The item id to return. |
|
371 | - * @return GetPaid_Form_Item|bool |
|
372 | - */ |
|
373 | - public function get_item( $item_id ) { |
|
374 | - |
|
375 | - if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
376 | - return false; |
|
377 | - } |
|
378 | - |
|
379 | - foreach( $this->get_items() as $item ) { |
|
380 | - if ( $item->get_id() == (int) $item_id ) { |
|
381 | - return $item; |
|
382 | - } |
|
383 | - } |
|
384 | - |
|
385 | - return false; |
|
386 | - |
|
387 | - } |
|
388 | - |
|
389 | - /** |
|
390 | - * Gets a single element. |
|
391 | - * |
|
392 | - * @since 1.0.19 |
|
393 | - * @param string $element_type The element type to return. |
|
394 | - * @return array|bool |
|
395 | - */ |
|
396 | - public function get_element_type( $element_type ) { |
|
397 | - |
|
398 | - if ( empty( $element_type ) || ! is_scalar( $element_type ) ) { |
|
399 | - return false; |
|
400 | - } |
|
401 | - |
|
402 | - foreach ( $this->get_prop( 'elements' ) as $element ) { |
|
403 | - |
|
404 | - if ( $element['type'] == $element_type ) { |
|
405 | - return $element; |
|
406 | - } |
|
407 | - |
|
408 | - } |
|
409 | - |
|
410 | - return false; |
|
411 | - |
|
412 | - } |
|
413 | - |
|
414 | - /** |
|
415 | - * Get the total amount earned via this form. |
|
416 | - * |
|
417 | - * @since 1.0.19 |
|
418 | - * @param string $context View or edit context. |
|
419 | - * @return array |
|
420 | - */ |
|
421 | - public function get_earned( $context = 'view' ) { |
|
422 | - return $this->get_prop( 'earned', $context ); |
|
423 | - } |
|
424 | - |
|
425 | - /** |
|
426 | - * Get the total amount refunded via this form. |
|
427 | - * |
|
428 | - * @since 1.0.19 |
|
429 | - * @param string $context View or edit context. |
|
430 | - * @return array |
|
431 | - */ |
|
432 | - public function get_refunded( $context = 'view' ) { |
|
433 | - return $this->get_prop( 'refunded', $context ); |
|
434 | - } |
|
435 | - |
|
436 | - /** |
|
437 | - * Get the total amount cancelled via this form. |
|
438 | - * |
|
439 | - * @since 1.0.19 |
|
440 | - * @param string $context View or edit context. |
|
441 | - * @return array |
|
442 | - */ |
|
443 | - public function get_cancelled( $context = 'view' ) { |
|
444 | - return $this->get_prop( 'cancelled', $context ); |
|
445 | - } |
|
446 | - |
|
447 | - /** |
|
448 | - * Get the total amount failed via this form. |
|
449 | - * |
|
450 | - * @since 1.0.19 |
|
451 | - * @param string $context View or edit context. |
|
452 | - * @return array |
|
453 | - */ |
|
454 | - public function get_failed( $context = 'view' ) { |
|
455 | - return $this->get_prop( 'failed', $context ); |
|
456 | - } |
|
457 | - |
|
458 | - /** |
|
459 | - * Get the currency. |
|
460 | - * |
|
461 | - * @since 1.0.19 |
|
462 | - * @param string $context View or edit context. |
|
463 | - * @return string |
|
464 | - */ |
|
465 | - public function get_currency() { |
|
466 | - $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
467 | - return apply_filters( 'getpaid-payment-form-currency', $currency, $this ); |
|
468 | - } |
|
458 | + /** |
|
459 | + * Get the currency. |
|
460 | + * |
|
461 | + * @since 1.0.19 |
|
462 | + * @param string $context View or edit context. |
|
463 | + * @return string |
|
464 | + */ |
|
465 | + public function get_currency() { |
|
466 | + $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
467 | + return apply_filters( 'getpaid-payment-form-currency', $currency, $this ); |
|
468 | + } |
|
469 | 469 | |
470 | 470 | /* |
471 | 471 | |-------------------------------------------------------------------------- |
@@ -478,22 +478,22 @@ discard block |
||
478 | 478 | */ |
479 | 479 | |
480 | 480 | /** |
481 | - * Set plugin version when the item was created. |
|
482 | - * |
|
483 | - * @since 1.0.19 |
|
484 | - */ |
|
485 | - public function set_version( $value ) { |
|
486 | - $this->set_prop( 'version', $value ); |
|
481 | + * Set plugin version when the item was created. |
|
482 | + * |
|
483 | + * @since 1.0.19 |
|
484 | + */ |
|
485 | + public function set_version( $value ) { |
|
486 | + $this->set_prop( 'version', $value ); |
|
487 | 487 | } |
488 | 488 | |
489 | 489 | /** |
490 | - * Set date when the item was created. |
|
491 | - * |
|
492 | - * @since 1.0.19 |
|
493 | - * @param string $value Value to set. |
|
490 | + * Set date when the item was created. |
|
491 | + * |
|
492 | + * @since 1.0.19 |
|
493 | + * @param string $value Value to set. |
|
494 | 494 | * @return bool Whether or not the date was set. |
495 | - */ |
|
496 | - public function set_date_created( $value ) { |
|
495 | + */ |
|
496 | + public function set_date_created( $value ) { |
|
497 | 497 | $date = strtotime( $value ); |
498 | 498 | |
499 | 499 | if ( $date ) { |
@@ -506,13 +506,13 @@ discard block |
||
506 | 506 | } |
507 | 507 | |
508 | 508 | /** |
509 | - * Set date when the item was last modified. |
|
510 | - * |
|
511 | - * @since 1.0.19 |
|
512 | - * @param string $value Value to set. |
|
509 | + * Set date when the item was last modified. |
|
510 | + * |
|
511 | + * @since 1.0.19 |
|
512 | + * @param string $value Value to set. |
|
513 | 513 | * @return bool Whether or not the date was set. |
514 | - */ |
|
515 | - public function set_date_modified( $value ) { |
|
514 | + */ |
|
515 | + public function set_date_modified( $value ) { |
|
516 | 516 | $date = strtotime( $value ); |
517 | 517 | |
518 | 518 | if ( $date ) { |
@@ -525,118 +525,118 @@ discard block |
||
525 | 525 | } |
526 | 526 | |
527 | 527 | /** |
528 | - * Set the item name. |
|
529 | - * |
|
530 | - * @since 1.0.19 |
|
531 | - * @param string $value New name. |
|
532 | - */ |
|
533 | - public function set_name( $value ) { |
|
534 | - $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
535 | - } |
|
536 | - |
|
537 | - /** |
|
538 | - * Alias of self::set_name(). |
|
539 | - * |
|
540 | - * @since 1.0.19 |
|
541 | - * @param string $value New name. |
|
542 | - */ |
|
543 | - public function set_title( $value ) { |
|
544 | - $this->set_name( $value ); |
|
545 | - } |
|
546 | - |
|
547 | - /** |
|
548 | - * Set the owner of the item. |
|
549 | - * |
|
550 | - * @since 1.0.19 |
|
551 | - * @param int $value New author. |
|
552 | - */ |
|
553 | - public function set_author( $value ) { |
|
554 | - $this->set_prop( 'author', (int) $value ); |
|
555 | - } |
|
556 | - |
|
557 | - /** |
|
558 | - * Set the form elements. |
|
559 | - * |
|
560 | - * @since 1.0.19 |
|
561 | - * @param array $value Form elements. |
|
562 | - */ |
|
563 | - public function set_elements( $value ) { |
|
564 | - if ( is_array( $value ) ) { |
|
565 | - $this->set_prop( 'elements', $value ); |
|
566 | - } |
|
567 | - } |
|
568 | - |
|
569 | - /** |
|
570 | - * Set the form items. |
|
571 | - * |
|
572 | - * @since 1.0.19 |
|
573 | - * @param array $value Form elements. |
|
574 | - */ |
|
575 | - public function set_items( $value ) { |
|
576 | - if ( is_array( $value ) ) { |
|
577 | - $this->set_prop( 'items', $value ); |
|
578 | - } |
|
579 | - } |
|
580 | - |
|
581 | - /** |
|
582 | - * Set the total amount earned via this form. |
|
583 | - * |
|
584 | - * @since 1.0.19 |
|
585 | - * @param float $value Amount earned. |
|
586 | - */ |
|
587 | - public function set_earned( $value ) { |
|
588 | - $value = max( (float) $value, 0 ); |
|
589 | - $this->set_prop( 'earned', $value ); |
|
590 | - } |
|
591 | - |
|
592 | - /** |
|
593 | - * Set the total amount refunded via this form. |
|
594 | - * |
|
595 | - * @since 1.0.19 |
|
596 | - * @param float $value Amount refunded. |
|
597 | - */ |
|
598 | - public function set_refunded( $value ) { |
|
599 | - $value = max( (float) $value, 0 ); |
|
600 | - $this->set_prop( 'refunded', $value ); |
|
601 | - } |
|
602 | - |
|
603 | - /** |
|
604 | - * Set the total amount cancelled via this form. |
|
605 | - * |
|
606 | - * @since 1.0.19 |
|
607 | - * @param float $value Amount cancelled. |
|
608 | - */ |
|
609 | - public function set_cancelled( $value ) { |
|
610 | - $value = max( (float) $value, 0 ); |
|
611 | - $this->set_prop( 'cancelled', $value ); |
|
612 | - } |
|
613 | - |
|
614 | - /** |
|
615 | - * Set the total amount failed via this form. |
|
616 | - * |
|
617 | - * @since 1.0.19 |
|
618 | - * @param float $value Amount cancelled. |
|
619 | - */ |
|
620 | - public function set_failed( $value ) { |
|
621 | - $value = max( (float) $value, 0 ); |
|
622 | - $this->set_prop( 'failed', $value ); |
|
623 | - } |
|
528 | + * Set the item name. |
|
529 | + * |
|
530 | + * @since 1.0.19 |
|
531 | + * @param string $value New name. |
|
532 | + */ |
|
533 | + public function set_name( $value ) { |
|
534 | + $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
535 | + } |
|
536 | + |
|
537 | + /** |
|
538 | + * Alias of self::set_name(). |
|
539 | + * |
|
540 | + * @since 1.0.19 |
|
541 | + * @param string $value New name. |
|
542 | + */ |
|
543 | + public function set_title( $value ) { |
|
544 | + $this->set_name( $value ); |
|
545 | + } |
|
546 | + |
|
547 | + /** |
|
548 | + * Set the owner of the item. |
|
549 | + * |
|
550 | + * @since 1.0.19 |
|
551 | + * @param int $value New author. |
|
552 | + */ |
|
553 | + public function set_author( $value ) { |
|
554 | + $this->set_prop( 'author', (int) $value ); |
|
555 | + } |
|
556 | + |
|
557 | + /** |
|
558 | + * Set the form elements. |
|
559 | + * |
|
560 | + * @since 1.0.19 |
|
561 | + * @param array $value Form elements. |
|
562 | + */ |
|
563 | + public function set_elements( $value ) { |
|
564 | + if ( is_array( $value ) ) { |
|
565 | + $this->set_prop( 'elements', $value ); |
|
566 | + } |
|
567 | + } |
|
568 | + |
|
569 | + /** |
|
570 | + * Set the form items. |
|
571 | + * |
|
572 | + * @since 1.0.19 |
|
573 | + * @param array $value Form elements. |
|
574 | + */ |
|
575 | + public function set_items( $value ) { |
|
576 | + if ( is_array( $value ) ) { |
|
577 | + $this->set_prop( 'items', $value ); |
|
578 | + } |
|
579 | + } |
|
580 | + |
|
581 | + /** |
|
582 | + * Set the total amount earned via this form. |
|
583 | + * |
|
584 | + * @since 1.0.19 |
|
585 | + * @param float $value Amount earned. |
|
586 | + */ |
|
587 | + public function set_earned( $value ) { |
|
588 | + $value = max( (float) $value, 0 ); |
|
589 | + $this->set_prop( 'earned', $value ); |
|
590 | + } |
|
591 | + |
|
592 | + /** |
|
593 | + * Set the total amount refunded via this form. |
|
594 | + * |
|
595 | + * @since 1.0.19 |
|
596 | + * @param float $value Amount refunded. |
|
597 | + */ |
|
598 | + public function set_refunded( $value ) { |
|
599 | + $value = max( (float) $value, 0 ); |
|
600 | + $this->set_prop( 'refunded', $value ); |
|
601 | + } |
|
602 | + |
|
603 | + /** |
|
604 | + * Set the total amount cancelled via this form. |
|
605 | + * |
|
606 | + * @since 1.0.19 |
|
607 | + * @param float $value Amount cancelled. |
|
608 | + */ |
|
609 | + public function set_cancelled( $value ) { |
|
610 | + $value = max( (float) $value, 0 ); |
|
611 | + $this->set_prop( 'cancelled', $value ); |
|
612 | + } |
|
613 | + |
|
614 | + /** |
|
615 | + * Set the total amount failed via this form. |
|
616 | + * |
|
617 | + * @since 1.0.19 |
|
618 | + * @param float $value Amount cancelled. |
|
619 | + */ |
|
620 | + public function set_failed( $value ) { |
|
621 | + $value = max( (float) $value, 0 ); |
|
622 | + $this->set_prop( 'failed', $value ); |
|
623 | + } |
|
624 | 624 | |
625 | 625 | /** |
626 | 626 | * Create an item. For backwards compatibilty. |
627 | 627 | * |
628 | 628 | * @deprecated |
629 | - * @return int item id |
|
629 | + * @return int item id |
|
630 | 630 | */ |
631 | 631 | public function create( $data = array() ) { |
632 | 632 | |
633 | - // Set the properties. |
|
634 | - if ( is_array( $data ) ) { |
|
635 | - $this->set_props( $data ); |
|
636 | - } |
|
633 | + // Set the properties. |
|
634 | + if ( is_array( $data ) ) { |
|
635 | + $this->set_props( $data ); |
|
636 | + } |
|
637 | 637 | |
638 | - // Save the item. |
|
639 | - return $this->save(); |
|
638 | + // Save the item. |
|
639 | + return $this->save(); |
|
640 | 640 | |
641 | 641 | } |
642 | 642 | |
@@ -644,7 +644,7 @@ discard block |
||
644 | 644 | * Updates an item. For backwards compatibilty. |
645 | 645 | * |
646 | 646 | * @deprecated |
647 | - * @return int item id |
|
647 | + * @return int item id |
|
648 | 648 | */ |
649 | 649 | public function update( $data = array() ) { |
650 | 650 | return $this->create( $data ); |
@@ -660,22 +660,22 @@ discard block |
||
660 | 660 | */ |
661 | 661 | |
662 | 662 | /** |
663 | - * Checks whether this is the default payment form. |
|
664 | - * |
|
665 | - * @since 1.0.19 |
|
666 | - * @return bool |
|
667 | - */ |
|
663 | + * Checks whether this is the default payment form. |
|
664 | + * |
|
665 | + * @since 1.0.19 |
|
666 | + * @return bool |
|
667 | + */ |
|
668 | 668 | public function is_default() { |
669 | 669 | $is_default = $this->get_id() == wpinv_get_default_payment_form(); |
670 | 670 | return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this ); |
671 | - } |
|
671 | + } |
|
672 | 672 | |
673 | 673 | /** |
674 | - * Checks whether the form is active. |
|
675 | - * |
|
676 | - * @since 1.0.19 |
|
677 | - * @return bool |
|
678 | - */ |
|
674 | + * Checks whether the form is active. |
|
675 | + * |
|
676 | + * @since 1.0.19 |
|
677 | + * @return bool |
|
678 | + */ |
|
679 | 679 | public function is_active() { |
680 | 680 | $is_active = 0 !== (int) $this->get_id(); |
681 | 681 | |
@@ -684,76 +684,76 @@ discard block |
||
684 | 684 | } |
685 | 685 | |
686 | 686 | return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this ); |
687 | - } |
|
688 | - |
|
689 | - /** |
|
690 | - * Checks whether the form has a given item. |
|
691 | - * |
|
692 | - * @since 1.0.19 |
|
693 | - * @return bool |
|
694 | - */ |
|
687 | + } |
|
688 | + |
|
689 | + /** |
|
690 | + * Checks whether the form has a given item. |
|
691 | + * |
|
692 | + * @since 1.0.19 |
|
693 | + * @return bool |
|
694 | + */ |
|
695 | 695 | public function has_item( $item_id ) { |
696 | 696 | return false !== $this->get_item( $item_id ); |
697 | - } |
|
698 | - |
|
699 | - /** |
|
700 | - * Checks whether the form has a given element. |
|
701 | - * |
|
702 | - * @since 1.0.19 |
|
703 | - * @return bool |
|
704 | - */ |
|
697 | + } |
|
698 | + |
|
699 | + /** |
|
700 | + * Checks whether the form has a given element. |
|
701 | + * |
|
702 | + * @since 1.0.19 |
|
703 | + * @return bool |
|
704 | + */ |
|
705 | 705 | public function has_element_type( $element_type ) { |
706 | 706 | return false !== $this->get_element_type( $element_type ); |
707 | - } |
|
708 | - |
|
709 | - /** |
|
710 | - * Checks whether this form is recurring or not. |
|
711 | - * |
|
712 | - * @since 1.0.19 |
|
713 | - * @return bool |
|
714 | - */ |
|
707 | + } |
|
708 | + |
|
709 | + /** |
|
710 | + * Checks whether this form is recurring or not. |
|
711 | + * |
|
712 | + * @since 1.0.19 |
|
713 | + * @return bool |
|
714 | + */ |
|
715 | 715 | public function is_recurring() { |
716 | 716 | |
717 | - if ( ! empty( $this->invoice ) ) { |
|
718 | - return $this->invoice->is_recurring(); |
|
719 | - } |
|
717 | + if ( ! empty( $this->invoice ) ) { |
|
718 | + return $this->invoice->is_recurring(); |
|
719 | + } |
|
720 | 720 | |
721 | - foreach ( $this->get_items() as $item ) { |
|
721 | + foreach ( $this->get_items() as $item ) { |
|
722 | 722 | |
723 | - if ( $item->is_recurring() ) { |
|
724 | - return true; |
|
725 | - } |
|
723 | + if ( $item->is_recurring() ) { |
|
724 | + return true; |
|
725 | + } |
|
726 | 726 | |
727 | - } |
|
727 | + } |
|
728 | 728 | |
729 | 729 | return false; |
730 | - } |
|
730 | + } |
|
731 | 731 | |
732 | - /** |
|
733 | - * Retrieves the form's html. |
|
734 | - * |
|
735 | - * @since 1.0.19 |
|
736 | - */ |
|
732 | + /** |
|
733 | + * Retrieves the form's html. |
|
734 | + * |
|
735 | + * @since 1.0.19 |
|
736 | + */ |
|
737 | 737 | public function get_html( $extra_markup = '' ) { |
738 | 738 | |
739 | - // Return the HTML. |
|
740 | - return wpinv_get_template_html( |
|
741 | - 'payment-forms/form.php', |
|
742 | - array( |
|
743 | - 'form' => $this, |
|
744 | - 'extra_markup' => $extra_markup, |
|
745 | - ) |
|
746 | - ); |
|
747 | - |
|
748 | - } |
|
749 | - |
|
750 | - /** |
|
751 | - * Displays the payment form. |
|
752 | - * |
|
753 | - * @since 1.0.19 |
|
754 | - */ |
|
739 | + // Return the HTML. |
|
740 | + return wpinv_get_template_html( |
|
741 | + 'payment-forms/form.php', |
|
742 | + array( |
|
743 | + 'form' => $this, |
|
744 | + 'extra_markup' => $extra_markup, |
|
745 | + ) |
|
746 | + ); |
|
747 | + |
|
748 | + } |
|
749 | + |
|
750 | + /** |
|
751 | + * Displays the payment form. |
|
752 | + * |
|
753 | + * @since 1.0.19 |
|
754 | + */ |
|
755 | 755 | public function display( $extra_markup = '' ) { |
756 | - echo $this->get_html( $extra_markup ); |
|
756 | + echo $this->get_html( $extra_markup ); |
|
757 | 757 | } |
758 | 758 | |
759 | 759 | } |
@@ -12,79 +12,79 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Payment_Form_Submission_Items { |
14 | 14 | |
15 | - /** |
|
16 | - * Submission items. |
|
17 | - * @var GetPaid_Form_Item[] |
|
18 | - */ |
|
19 | - public $items = array(); |
|
20 | - |
|
21 | 15 | /** |
22 | - * Class constructor |
|
23 | - * |
|
24 | - * @param GetPaid_Payment_Form_Submission $submission |
|
25 | - */ |
|
26 | - public function __construct( $submission ) { |
|
27 | - |
|
28 | - $data = $submission->get_data(); |
|
29 | - $payment_form = $submission->get_payment_form(); |
|
30 | - |
|
31 | - // Prepare the selected items. |
|
32 | - $selected_items = array(); |
|
33 | - if ( ! empty( $data['getpaid-items'] ) ) { |
|
34 | - $selected_items = wpinv_clean( $data['getpaid-items'] ); |
|
35 | - } |
|
36 | - |
|
37 | - // For default forms, ensure that an item has been set. |
|
38 | - if ( $payment_form->is_default() && ! $submission->has_invoice() && isset( $data['getpaid-form-items'] ) ) { |
|
39 | - $form_items = wpinv_clean( $data['getpaid-form-items'] ); |
|
40 | - $payment_form->set_items( getpaid_convert_items_to_array( $form_items ) ); |
|
41 | - } |
|
16 | + * Submission items. |
|
17 | + * @var GetPaid_Form_Item[] |
|
18 | + */ |
|
19 | + public $items = array(); |
|
42 | 20 | |
43 | - // Process each individual item. |
|
44 | - foreach ( $payment_form->get_items() as $item ) { |
|
45 | - $this->process_item( $item, $selected_items ); |
|
46 | - } |
|
47 | - |
|
48 | - } |
|
21 | + /** |
|
22 | + * Class constructor |
|
23 | + * |
|
24 | + * @param GetPaid_Payment_Form_Submission $submission |
|
25 | + */ |
|
26 | + public function __construct( $submission ) { |
|
27 | + |
|
28 | + $data = $submission->get_data(); |
|
29 | + $payment_form = $submission->get_payment_form(); |
|
30 | + |
|
31 | + // Prepare the selected items. |
|
32 | + $selected_items = array(); |
|
33 | + if ( ! empty( $data['getpaid-items'] ) ) { |
|
34 | + $selected_items = wpinv_clean( $data['getpaid-items'] ); |
|
35 | + } |
|
36 | + |
|
37 | + // For default forms, ensure that an item has been set. |
|
38 | + if ( $payment_form->is_default() && ! $submission->has_invoice() && isset( $data['getpaid-form-items'] ) ) { |
|
39 | + $form_items = wpinv_clean( $data['getpaid-form-items'] ); |
|
40 | + $payment_form->set_items( getpaid_convert_items_to_array( $form_items ) ); |
|
41 | + } |
|
42 | + |
|
43 | + // Process each individual item. |
|
44 | + foreach ( $payment_form->get_items() as $item ) { |
|
45 | + $this->process_item( $item, $selected_items ); |
|
46 | + } |
|
47 | + |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * Process a single item. |
|
52 | - * |
|
53 | - * @param GetPaid_Form_Item $item |
|
54 | - * @param array $selected_items |
|
55 | - */ |
|
56 | - public function process_item( $item, $selected_items ) { |
|
50 | + /** |
|
51 | + * Process a single item. |
|
52 | + * |
|
53 | + * @param GetPaid_Form_Item $item |
|
54 | + * @param array $selected_items |
|
55 | + */ |
|
56 | + public function process_item( $item, $selected_items ) { |
|
57 | 57 | |
58 | - // Abort if this is an optional item and it has not been selected. |
|
59 | - if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) { |
|
60 | - return; |
|
61 | - } |
|
58 | + // Abort if this is an optional item and it has not been selected. |
|
59 | + if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) { |
|
60 | + return; |
|
61 | + } |
|
62 | 62 | |
63 | - // (maybe) let customers change the quantities and prices. |
|
64 | - if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
63 | + // (maybe) let customers change the quantities and prices. |
|
64 | + if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
65 | 65 | |
66 | - // Maybe change the quantities. |
|
67 | - if ( $item->allows_quantities() ) { |
|
68 | - $item->set_quantity( (int) $selected_items[ $item->get_id() ]['quantity'] ); |
|
69 | - } |
|
66 | + // Maybe change the quantities. |
|
67 | + if ( $item->allows_quantities() ) { |
|
68 | + $item->set_quantity( (int) $selected_items[ $item->get_id() ]['quantity'] ); |
|
69 | + } |
|
70 | 70 | |
71 | - // Maybe change the price. |
|
72 | - if ( $item->user_can_set_their_price() ) { |
|
73 | - $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] ); |
|
71 | + // Maybe change the price. |
|
72 | + if ( $item->user_can_set_their_price() ) { |
|
73 | + $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] ); |
|
74 | 74 | |
75 | - if ( $item->get_minimum_price() > $price ) { |
|
76 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), wpinv_sanitize_amount( $item->get_minimum_price() ) ) ); |
|
77 | - } |
|
75 | + if ( $item->get_minimum_price() > $price ) { |
|
76 | + throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), wpinv_sanitize_amount( $item->get_minimum_price() ) ) ); |
|
77 | + } |
|
78 | 78 | |
79 | - $item->set_price( $price ); |
|
79 | + $item->set_price( $price ); |
|
80 | 80 | |
81 | - } |
|
81 | + } |
|
82 | 82 | |
83 | - } |
|
83 | + } |
|
84 | 84 | |
85 | - // Save the item. |
|
86 | - $this->items[] = $item; |
|
85 | + // Save the item. |
|
86 | + $this->items[] = $item; |
|
87 | 87 | |
88 | - } |
|
88 | + } |
|
89 | 89 | |
90 | 90 | } |
@@ -31,16 +31,16 @@ discard block |
||
31 | 31 | } |
32 | 32 | |
33 | 33 | function wpinv_can_checkout() { |
34 | - $can_checkout = true; // Always true for now |
|
34 | + $can_checkout = true; // Always true for now |
|
35 | 35 | |
36 | - return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout ); |
|
36 | + return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout ); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | function wpinv_get_success_page_uri() { |
40 | - $page_id = wpinv_get_option( 'success_page', 0 ); |
|
41 | - $page_id = absint( $page_id ); |
|
40 | + $page_id = wpinv_get_option( 'success_page', 0 ); |
|
41 | + $page_id = absint( $page_id ); |
|
42 | 42 | |
43 | - return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) ); |
|
43 | + return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) ); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
@@ -51,22 +51,22 @@ discard block |
||
51 | 51 | */ |
52 | 52 | function wpinv_get_history_page_uri( $post_type = 'wpi_invoice' ) { |
53 | 53 | $post_type = sanitize_key( str_replace( 'wpi_', '', $post_type ) ); |
54 | - $page_id = wpinv_get_option( "{$post_type}_history_page", 0 ); |
|
55 | - $page_id = absint( $page_id ); |
|
56 | - return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ), $post_type ); |
|
54 | + $page_id = wpinv_get_option( "{$post_type}_history_page", 0 ); |
|
55 | + $page_id = absint( $page_id ); |
|
56 | + return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ), $post_type ); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | function wpinv_is_success_page() { |
60 | - $is_success_page = wpinv_get_option( 'success_page', false ); |
|
61 | - $is_success_page = ! empty( $is_success_page ) ? is_page( $is_success_page ) : false; |
|
60 | + $is_success_page = wpinv_get_option( 'success_page', false ); |
|
61 | + $is_success_page = ! empty( $is_success_page ) ? is_page( $is_success_page ) : false; |
|
62 | 62 | |
63 | - return apply_filters( 'wpinv_is_success_page', $is_success_page ); |
|
63 | + return apply_filters( 'wpinv_is_success_page', $is_success_page ); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | function wpinv_is_invoice_history_page() { |
67 | - $ret = wpinv_get_option( 'invoice_history_page', false ); |
|
68 | - $ret = $ret ? is_page( $ret ) : false; |
|
69 | - return apply_filters( 'wpinv_is_invoice_history_page', $ret ); |
|
67 | + $ret = wpinv_get_option( 'invoice_history_page', false ); |
|
68 | + $ret = $ret ? is_page( $ret ) : false; |
|
69 | + return apply_filters( 'wpinv_is_invoice_history_page', $ret ); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | function wpinv_is_subscriptions_history_page() { |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | } |
90 | 90 | |
91 | 91 | function wpinv_send_to_failed_page( $args = null ) { |
92 | - $redirect = wpinv_get_failed_transaction_uri(); |
|
92 | + $redirect = wpinv_get_failed_transaction_uri(); |
|
93 | 93 | |
94 | 94 | if ( !empty( $args ) ) { |
95 | 95 | // Check for backward compatibility |
@@ -109,55 +109,55 @@ discard block |
||
109 | 109 | } |
110 | 110 | |
111 | 111 | function wpinv_get_checkout_uri( $args = array() ) { |
112 | - $uri = wpinv_get_option( 'checkout_page', false ); |
|
113 | - $uri = isset( $uri ) ? get_permalink( $uri ) : NULL; |
|
112 | + $uri = wpinv_get_option( 'checkout_page', false ); |
|
113 | + $uri = isset( $uri ) ? get_permalink( $uri ) : NULL; |
|
114 | 114 | |
115 | - if ( !empty( $args ) ) { |
|
116 | - // Check for backward compatibility |
|
117 | - if ( is_string( $args ) ) |
|
118 | - $args = str_replace( '?', '', $args ); |
|
115 | + if ( !empty( $args ) ) { |
|
116 | + // Check for backward compatibility |
|
117 | + if ( is_string( $args ) ) |
|
118 | + $args = str_replace( '?', '', $args ); |
|
119 | 119 | |
120 | - $args = wp_parse_args( $args ); |
|
120 | + $args = wp_parse_args( $args ); |
|
121 | 121 | |
122 | - $uri = add_query_arg( $args, $uri ); |
|
123 | - } |
|
122 | + $uri = add_query_arg( $args, $uri ); |
|
123 | + } |
|
124 | 124 | |
125 | - $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
125 | + $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
126 | 126 | |
127 | - $ajax_url = admin_url( 'admin-ajax.php', $scheme ); |
|
127 | + $ajax_url = admin_url( 'admin-ajax.php', $scheme ); |
|
128 | 128 | |
129 | - if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) { |
|
130 | - $uri = preg_replace( '/^http:/', 'https:', $uri ); |
|
131 | - } |
|
129 | + if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) { |
|
130 | + $uri = preg_replace( '/^http:/', 'https:', $uri ); |
|
131 | + } |
|
132 | 132 | |
133 | - return apply_filters( 'wpinv_get_checkout_uri', $uri ); |
|
133 | + return apply_filters( 'wpinv_get_checkout_uri', $uri ); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | function wpinv_get_success_page_url( $query_string = null ) { |
137 | - $success_page = wpinv_get_option( 'success_page', 0 ); |
|
138 | - $success_page = get_permalink( $success_page ); |
|
137 | + $success_page = wpinv_get_option( 'success_page', 0 ); |
|
138 | + $success_page = get_permalink( $success_page ); |
|
139 | 139 | |
140 | - if ( $query_string ) |
|
141 | - $success_page .= $query_string; |
|
140 | + if ( $query_string ) |
|
141 | + $success_page .= $query_string; |
|
142 | 142 | |
143 | - return apply_filters( 'wpinv_success_page_url', $success_page ); |
|
143 | + return apply_filters( 'wpinv_success_page_url', $success_page ); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | function wpinv_get_failed_transaction_uri( $extras = false ) { |
147 | - $uri = wpinv_get_option( 'failure_page', '' ); |
|
148 | - $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url(); |
|
147 | + $uri = wpinv_get_option( 'failure_page', '' ); |
|
148 | + $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url(); |
|
149 | 149 | |
150 | - if ( $extras ) |
|
151 | - $uri .= $extras; |
|
150 | + if ( $extras ) |
|
151 | + $uri .= $extras; |
|
152 | 152 | |
153 | - return apply_filters( 'wpinv_get_failed_transaction_uri', $uri ); |
|
153 | + return apply_filters( 'wpinv_get_failed_transaction_uri', $uri ); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | function wpinv_is_failed_transaction_page() { |
157 | - $ret = wpinv_get_option( 'failure_page', false ); |
|
158 | - $ret = isset( $ret ) ? is_page( $ret ) : false; |
|
157 | + $ret = wpinv_get_option( 'failure_page', false ); |
|
158 | + $ret = isset( $ret ) ? is_page( $ret ) : false; |
|
159 | 159 | |
160 | - return apply_filters( 'wpinv_is_failure_page', $ret ); |
|
160 | + return apply_filters( 'wpinv_is_failure_page', $ret ); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | function wpinv_transaction_query( $type = 'start' ) { |
@@ -232,36 +232,36 @@ discard block |
||
232 | 232 | $require_billing_details = apply_filters( 'wpinv_checkout_required_billing_details', wpinv_use_taxes() ); |
233 | 233 | |
234 | 234 | if ( $require_billing_details ) { |
235 | - if ( (bool)wpinv_get_option( 'fname_mandatory' ) ) { |
|
236 | - $required_fields['first_name'] = array( |
|
237 | - 'error_id' => 'invalid_first_name', |
|
238 | - 'error_message' => __( 'Please enter your first name', 'invoicing' ) |
|
239 | - ); |
|
240 | - } |
|
241 | - if ( (bool)wpinv_get_option( 'address_mandatory' ) ) { |
|
242 | - $required_fields['address'] = array( |
|
243 | - 'error_id' => 'invalid_address', |
|
244 | - 'error_message' => __( 'Please enter your address', 'invoicing' ) |
|
245 | - ); |
|
246 | - } |
|
247 | - if ( (bool)wpinv_get_option( 'city_mandatory' ) ) { |
|
248 | - $required_fields['city'] = array( |
|
249 | - 'error_id' => 'invalid_city', |
|
250 | - 'error_message' => __( 'Please enter your billing city', 'invoicing' ) |
|
251 | - ); |
|
252 | - } |
|
253 | - if ( (bool)wpinv_get_option( 'state_mandatory' ) ) { |
|
254 | - $required_fields['state'] = array( |
|
255 | - 'error_id' => 'invalid_state', |
|
256 | - 'error_message' => __( 'Please enter billing state / province', 'invoicing' ) |
|
257 | - ); |
|
258 | - } |
|
259 | - if ( (bool)wpinv_get_option( 'country_mandatory' ) ) { |
|
260 | - $required_fields['country'] = array( |
|
261 | - 'error_id' => 'invalid_country', |
|
262 | - 'error_message' => __( 'Please select your billing country', 'invoicing' ) |
|
263 | - ); |
|
264 | - } |
|
235 | + if ( (bool)wpinv_get_option( 'fname_mandatory' ) ) { |
|
236 | + $required_fields['first_name'] = array( |
|
237 | + 'error_id' => 'invalid_first_name', |
|
238 | + 'error_message' => __( 'Please enter your first name', 'invoicing' ) |
|
239 | + ); |
|
240 | + } |
|
241 | + if ( (bool)wpinv_get_option( 'address_mandatory' ) ) { |
|
242 | + $required_fields['address'] = array( |
|
243 | + 'error_id' => 'invalid_address', |
|
244 | + 'error_message' => __( 'Please enter your address', 'invoicing' ) |
|
245 | + ); |
|
246 | + } |
|
247 | + if ( (bool)wpinv_get_option( 'city_mandatory' ) ) { |
|
248 | + $required_fields['city'] = array( |
|
249 | + 'error_id' => 'invalid_city', |
|
250 | + 'error_message' => __( 'Please enter your billing city', 'invoicing' ) |
|
251 | + ); |
|
252 | + } |
|
253 | + if ( (bool)wpinv_get_option( 'state_mandatory' ) ) { |
|
254 | + $required_fields['state'] = array( |
|
255 | + 'error_id' => 'invalid_state', |
|
256 | + 'error_message' => __( 'Please enter billing state / province', 'invoicing' ) |
|
257 | + ); |
|
258 | + } |
|
259 | + if ( (bool)wpinv_get_option( 'country_mandatory' ) ) { |
|
260 | + $required_fields['country'] = array( |
|
261 | + 'error_id' => 'invalid_country', |
|
262 | + 'error_message' => __( 'Please select your billing country', 'invoicing' ) |
|
263 | + ); |
|
264 | + } |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | return apply_filters( 'wpinv_checkout_required_fields', $required_fields ); |
@@ -15,136 +15,136 @@ |
||
15 | 15 | class WPInv_REST_Invoice_Controller extends GetPaid_REST_Posts_Controller { |
16 | 16 | |
17 | 17 | /** |
18 | - * Post type. |
|
19 | - * |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - protected $post_type = 'wpi_invoice'; |
|
23 | - |
|
24 | - /** |
|
25 | - * The base of this controller's route. |
|
26 | - * |
|
27 | - * @since 1.0.13 |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - protected $rest_base = 'invoices'; |
|
31 | - |
|
32 | - /** Contains this controller's class name. |
|
33 | - * |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - public $crud_class = 'WPInv_Invoice'; |
|
18 | + * Post type. |
|
19 | + * |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + protected $post_type = 'wpi_invoice'; |
|
37 | 23 | |
38 | 24 | /** |
39 | - * Retrieves the query params for the invoices collection. |
|
40 | - * |
|
41 | - * @since 1.0.13 |
|
42 | - * |
|
43 | - * @return array Collection parameters. |
|
44 | - */ |
|
45 | - public function get_collection_params() { |
|
46 | - |
|
47 | - $params = array_merge( |
|
48 | - |
|
49 | - parent::get_collection_params(), |
|
50 | - |
|
51 | - array( |
|
52 | - |
|
53 | - |
|
54 | - 'customers' => array( |
|
55 | - 'description' => __( 'Limit result set to invoices for specific user ids.', 'invoicing' ), |
|
56 | - 'type' => 'array', |
|
57 | - 'items' => array( |
|
58 | - 'type' => 'integer', |
|
59 | - ), |
|
60 | - 'default' => array(), |
|
61 | - 'sanitize_callback' => 'wp_parse_id_list', |
|
62 | - ), |
|
63 | - |
|
64 | - 'exclude_customers' => array( |
|
65 | - 'description' => __( 'Exclude invoices to specific users.', 'invoicing' ), |
|
66 | - 'type' => 'array', |
|
67 | - 'items' => array( |
|
68 | - 'type' => 'integer', |
|
69 | - ), |
|
70 | - 'default' => array(), |
|
71 | - 'sanitize_callback' => 'wp_parse_id_list', |
|
72 | - ), |
|
73 | - |
|
74 | - 'parent' => array( |
|
75 | - 'description' => __( 'Limit result set to those of particular parent IDs.', 'invoicing' ), |
|
76 | - 'type' => 'array', |
|
77 | - 'items' => array( |
|
78 | - 'type' => 'integer', |
|
79 | - ), |
|
80 | - 'sanitize_callback' => 'wp_parse_id_list', |
|
81 | - 'default' => array(), |
|
82 | - ), |
|
83 | - |
|
84 | - 'parent_exclude' => array( |
|
85 | - 'description' => __( 'Limit result set to all items except those of a particular parent ID.', 'invoicing' ), |
|
86 | - 'type' => 'array', |
|
87 | - 'items' => array( |
|
88 | - 'type' => 'integer', |
|
89 | - ), |
|
90 | - 'sanitize_callback' => 'wp_parse_id_list', |
|
91 | - 'default' => array(), |
|
92 | - ), |
|
93 | - |
|
94 | - ) |
|
95 | - |
|
96 | - ); |
|
97 | - |
|
98 | - // Filter collection parameters for the invoices controller. |
|
99 | - return apply_filters( 'getpaid_rest_invoices_collection_params', $params, $this ); |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Determine the allowed query_vars for a get_items() response and |
|
104 | - * prepare for WP_Query. |
|
105 | - * |
|
106 | - * @param array $prepared_args Prepared arguments. |
|
107 | - * @param WP_REST_Request $request Request object. |
|
108 | - * @return array $query_args |
|
109 | - */ |
|
110 | - protected function prepare_items_query( $prepared_args = array(), $request = null ) { |
|
111 | - |
|
112 | - $query_args = parent::prepare_items_query( $prepared_args ); |
|
113 | - |
|
114 | - // Retrieve invoices for specific customers. |
|
115 | - if ( ! empty( $request['customers'] ) ) { |
|
116 | - $query_args['author__in'] = $request['customers']; |
|
117 | - } |
|
118 | - |
|
119 | - // Skip invoices for specific customers. |
|
120 | - if ( ! empty( $request['exclude_customers'] ) ) { |
|
121 | - $query_args['author__not_in'] = $request['exclude_customers']; |
|
122 | - } |
|
123 | - |
|
124 | - return apply_filters( 'getpaid_rest_invoices_prepare_items_query', $query_args, $request, $this ); |
|
125 | - |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * Retrieves a valid list of post statuses. |
|
130 | - * |
|
131 | - * @since 1.0.15 |
|
132 | - * |
|
133 | - * @return array A list of registered item statuses. |
|
134 | - */ |
|
135 | - public function get_post_statuses() { |
|
136 | - return array_keys( wpinv_get_invoice_statuses( true, false, $this->post_type ) ); |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * Saves a single invoice. |
|
141 | - * |
|
142 | - * @param WPInv_Invoice $invoice Invoice to save. |
|
143 | - * @return WP_Error|WPInv_Invoice |
|
144 | - */ |
|
145 | - protected function save_object( $invoice ) { |
|
146 | - $invoice->recalculate_total(); |
|
147 | - return parent::save_object( $invoice ); |
|
148 | - } |
|
25 | + * The base of this controller's route. |
|
26 | + * |
|
27 | + * @since 1.0.13 |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + protected $rest_base = 'invoices'; |
|
31 | + |
|
32 | + /** Contains this controller's class name. |
|
33 | + * |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + public $crud_class = 'WPInv_Invoice'; |
|
37 | + |
|
38 | + /** |
|
39 | + * Retrieves the query params for the invoices collection. |
|
40 | + * |
|
41 | + * @since 1.0.13 |
|
42 | + * |
|
43 | + * @return array Collection parameters. |
|
44 | + */ |
|
45 | + public function get_collection_params() { |
|
46 | + |
|
47 | + $params = array_merge( |
|
48 | + |
|
49 | + parent::get_collection_params(), |
|
50 | + |
|
51 | + array( |
|
52 | + |
|
53 | + |
|
54 | + 'customers' => array( |
|
55 | + 'description' => __( 'Limit result set to invoices for specific user ids.', 'invoicing' ), |
|
56 | + 'type' => 'array', |
|
57 | + 'items' => array( |
|
58 | + 'type' => 'integer', |
|
59 | + ), |
|
60 | + 'default' => array(), |
|
61 | + 'sanitize_callback' => 'wp_parse_id_list', |
|
62 | + ), |
|
63 | + |
|
64 | + 'exclude_customers' => array( |
|
65 | + 'description' => __( 'Exclude invoices to specific users.', 'invoicing' ), |
|
66 | + 'type' => 'array', |
|
67 | + 'items' => array( |
|
68 | + 'type' => 'integer', |
|
69 | + ), |
|
70 | + 'default' => array(), |
|
71 | + 'sanitize_callback' => 'wp_parse_id_list', |
|
72 | + ), |
|
73 | + |
|
74 | + 'parent' => array( |
|
75 | + 'description' => __( 'Limit result set to those of particular parent IDs.', 'invoicing' ), |
|
76 | + 'type' => 'array', |
|
77 | + 'items' => array( |
|
78 | + 'type' => 'integer', |
|
79 | + ), |
|
80 | + 'sanitize_callback' => 'wp_parse_id_list', |
|
81 | + 'default' => array(), |
|
82 | + ), |
|
83 | + |
|
84 | + 'parent_exclude' => array( |
|
85 | + 'description' => __( 'Limit result set to all items except those of a particular parent ID.', 'invoicing' ), |
|
86 | + 'type' => 'array', |
|
87 | + 'items' => array( |
|
88 | + 'type' => 'integer', |
|
89 | + ), |
|
90 | + 'sanitize_callback' => 'wp_parse_id_list', |
|
91 | + 'default' => array(), |
|
92 | + ), |
|
93 | + |
|
94 | + ) |
|
95 | + |
|
96 | + ); |
|
97 | + |
|
98 | + // Filter collection parameters for the invoices controller. |
|
99 | + return apply_filters( 'getpaid_rest_invoices_collection_params', $params, $this ); |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Determine the allowed query_vars for a get_items() response and |
|
104 | + * prepare for WP_Query. |
|
105 | + * |
|
106 | + * @param array $prepared_args Prepared arguments. |
|
107 | + * @param WP_REST_Request $request Request object. |
|
108 | + * @return array $query_args |
|
109 | + */ |
|
110 | + protected function prepare_items_query( $prepared_args = array(), $request = null ) { |
|
111 | + |
|
112 | + $query_args = parent::prepare_items_query( $prepared_args ); |
|
113 | + |
|
114 | + // Retrieve invoices for specific customers. |
|
115 | + if ( ! empty( $request['customers'] ) ) { |
|
116 | + $query_args['author__in'] = $request['customers']; |
|
117 | + } |
|
118 | + |
|
119 | + // Skip invoices for specific customers. |
|
120 | + if ( ! empty( $request['exclude_customers'] ) ) { |
|
121 | + $query_args['author__not_in'] = $request['exclude_customers']; |
|
122 | + } |
|
123 | + |
|
124 | + return apply_filters( 'getpaid_rest_invoices_prepare_items_query', $query_args, $request, $this ); |
|
125 | + |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Retrieves a valid list of post statuses. |
|
130 | + * |
|
131 | + * @since 1.0.15 |
|
132 | + * |
|
133 | + * @return array A list of registered item statuses. |
|
134 | + */ |
|
135 | + public function get_post_statuses() { |
|
136 | + return array_keys( wpinv_get_invoice_statuses( true, false, $this->post_type ) ); |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * Saves a single invoice. |
|
141 | + * |
|
142 | + * @param WPInv_Invoice $invoice Invoice to save. |
|
143 | + * @return WP_Error|WPInv_Invoice |
|
144 | + */ |
|
145 | + protected function save_object( $invoice ) { |
|
146 | + $invoice->recalculate_total(); |
|
147 | + return parent::save_object( $invoice ); |
|
148 | + } |
|
149 | 149 | |
150 | 150 | } |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
141 | 141 | */ |
142 | 142 | function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
143 | - return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path ); |
|
143 | + return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path ); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | * @return string |
159 | 159 | */ |
160 | 160 | function wpinv_get_theme_template_dir_name() { |
161 | - return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
161 | + return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -175,122 +175,122 @@ discard block |
||
175 | 175 | } |
176 | 176 | |
177 | 177 | function wpinv_get_template_part( $slug, $name = null, $load = true ) { |
178 | - do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
178 | + do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
179 | 179 | |
180 | - // Setup possible parts |
|
181 | - $templates = array(); |
|
182 | - if ( isset( $name ) ) |
|
183 | - $templates[] = $slug . '-' . $name . '.php'; |
|
184 | - $templates[] = $slug . '.php'; |
|
180 | + // Setup possible parts |
|
181 | + $templates = array(); |
|
182 | + if ( isset( $name ) ) |
|
183 | + $templates[] = $slug . '-' . $name . '.php'; |
|
184 | + $templates[] = $slug . '.php'; |
|
185 | 185 | |
186 | - // Allow template parts to be filtered |
|
187 | - $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
186 | + // Allow template parts to be filtered |
|
187 | + $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
188 | 188 | |
189 | - // Return the part that is found |
|
190 | - return wpinv_locate_tmpl( $templates, $load, false ); |
|
189 | + // Return the part that is found |
|
190 | + return wpinv_locate_tmpl( $templates, $load, false ); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) { |
194 | - // No file found yet |
|
195 | - $located = false; |
|
194 | + // No file found yet |
|
195 | + $located = false; |
|
196 | 196 | |
197 | - // Try to find a template file |
|
198 | - foreach ( (array)$template_names as $template_name ) { |
|
197 | + // Try to find a template file |
|
198 | + foreach ( (array)$template_names as $template_name ) { |
|
199 | 199 | |
200 | - // Continue if template is empty |
|
201 | - if ( empty( $template_name ) ) |
|
202 | - continue; |
|
200 | + // Continue if template is empty |
|
201 | + if ( empty( $template_name ) ) |
|
202 | + continue; |
|
203 | 203 | |
204 | - // Trim off any slashes from the template name |
|
205 | - $template_name = ltrim( $template_name, '/' ); |
|
204 | + // Trim off any slashes from the template name |
|
205 | + $template_name = ltrim( $template_name, '/' ); |
|
206 | 206 | |
207 | - // try locating this template file by looping through the template paths |
|
208 | - foreach( wpinv_get_theme_template_paths() as $template_path ) { |
|
207 | + // try locating this template file by looping through the template paths |
|
208 | + foreach( wpinv_get_theme_template_paths() as $template_path ) { |
|
209 | 209 | |
210 | - if( file_exists( $template_path . $template_name ) ) { |
|
211 | - $located = $template_path . $template_name; |
|
212 | - break; |
|
213 | - } |
|
214 | - } |
|
210 | + if( file_exists( $template_path . $template_name ) ) { |
|
211 | + $located = $template_path . $template_name; |
|
212 | + break; |
|
213 | + } |
|
214 | + } |
|
215 | 215 | |
216 | - if( !empty( $located ) ) { |
|
217 | - break; |
|
218 | - } |
|
219 | - } |
|
216 | + if( !empty( $located ) ) { |
|
217 | + break; |
|
218 | + } |
|
219 | + } |
|
220 | 220 | |
221 | - if ( ( true == $load ) && ! empty( $located ) ) |
|
222 | - load_template( $located, $require_once ); |
|
221 | + if ( ( true == $load ) && ! empty( $located ) ) |
|
222 | + load_template( $located, $require_once ); |
|
223 | 223 | |
224 | - return $located; |
|
224 | + return $located; |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | function wpinv_get_theme_template_paths() { |
228 | - $template_dir = wpinv_get_theme_template_dir_name(); |
|
228 | + $template_dir = wpinv_get_theme_template_dir_name(); |
|
229 | 229 | |
230 | - $file_paths = array( |
|
231 | - 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
232 | - 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
233 | - 100 => wpinv_get_templates_dir() |
|
234 | - ); |
|
230 | + $file_paths = array( |
|
231 | + 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
232 | + 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
233 | + 100 => wpinv_get_templates_dir() |
|
234 | + ); |
|
235 | 235 | |
236 | - $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
236 | + $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
237 | 237 | |
238 | - // sort the file paths based on priority |
|
239 | - ksort( $file_paths, SORT_NUMERIC ); |
|
238 | + // sort the file paths based on priority |
|
239 | + ksort( $file_paths, SORT_NUMERIC ); |
|
240 | 240 | |
241 | - return array_map( 'trailingslashit', $file_paths ); |
|
241 | + return array_map( 'trailingslashit', $file_paths ); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | function wpinv_checkout_meta_tags() { |
245 | 245 | |
246 | - $pages = array(); |
|
247 | - $pages[] = wpinv_get_option( 'success_page' ); |
|
248 | - $pages[] = wpinv_get_option( 'failure_page' ); |
|
249 | - $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
250 | - $pages[] = wpinv_get_option( 'invoice_subscription_page' ); |
|
246 | + $pages = array(); |
|
247 | + $pages[] = wpinv_get_option( 'success_page' ); |
|
248 | + $pages[] = wpinv_get_option( 'failure_page' ); |
|
249 | + $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
250 | + $pages[] = wpinv_get_option( 'invoice_subscription_page' ); |
|
251 | 251 | |
252 | - if( !wpinv_is_checkout() && !is_page( $pages ) ) { |
|
253 | - return; |
|
254 | - } |
|
252 | + if( !wpinv_is_checkout() && !is_page( $pages ) ) { |
|
253 | + return; |
|
254 | + } |
|
255 | 255 | |
256 | - echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
|
256 | + echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
|
257 | 257 | } |
258 | 258 | add_action( 'wp_head', 'wpinv_checkout_meta_tags' ); |
259 | 259 | |
260 | 260 | function wpinv_add_body_classes( $class ) { |
261 | - $classes = (array)$class; |
|
261 | + $classes = (array)$class; |
|
262 | 262 | |
263 | - if( wpinv_is_checkout() ) { |
|
264 | - $classes[] = 'wpinv-checkout'; |
|
265 | - $classes[] = 'wpinv-page'; |
|
266 | - } |
|
263 | + if( wpinv_is_checkout() ) { |
|
264 | + $classes[] = 'wpinv-checkout'; |
|
265 | + $classes[] = 'wpinv-page'; |
|
266 | + } |
|
267 | 267 | |
268 | - if( wpinv_is_success_page() ) { |
|
269 | - $classes[] = 'wpinv-success'; |
|
270 | - $classes[] = 'wpinv-page'; |
|
271 | - } |
|
268 | + if( wpinv_is_success_page() ) { |
|
269 | + $classes[] = 'wpinv-success'; |
|
270 | + $classes[] = 'wpinv-page'; |
|
271 | + } |
|
272 | 272 | |
273 | - if( wpinv_is_failed_transaction_page() ) { |
|
274 | - $classes[] = 'wpinv-failed-transaction'; |
|
275 | - $classes[] = 'wpinv-page'; |
|
276 | - } |
|
273 | + if( wpinv_is_failed_transaction_page() ) { |
|
274 | + $classes[] = 'wpinv-failed-transaction'; |
|
275 | + $classes[] = 'wpinv-page'; |
|
276 | + } |
|
277 | 277 | |
278 | - if( wpinv_is_invoice_history_page() ) { |
|
279 | - $classes[] = 'wpinv-history'; |
|
280 | - $classes[] = 'wpinv-page'; |
|
281 | - } |
|
278 | + if( wpinv_is_invoice_history_page() ) { |
|
279 | + $classes[] = 'wpinv-history'; |
|
280 | + $classes[] = 'wpinv-page'; |
|
281 | + } |
|
282 | 282 | |
283 | - if( wpinv_is_subscriptions_history_page() ) { |
|
284 | - $classes[] = 'wpinv-subscription'; |
|
285 | - $classes[] = 'wpinv-page'; |
|
286 | - } |
|
283 | + if( wpinv_is_subscriptions_history_page() ) { |
|
284 | + $classes[] = 'wpinv-subscription'; |
|
285 | + $classes[] = 'wpinv-page'; |
|
286 | + } |
|
287 | 287 | |
288 | - if( wpinv_is_test_mode() ) { |
|
289 | - $classes[] = 'wpinv-test-mode'; |
|
290 | - $classes[] = 'wpinv-page'; |
|
291 | - } |
|
288 | + if( wpinv_is_test_mode() ) { |
|
289 | + $classes[] = 'wpinv-test-mode'; |
|
290 | + $classes[] = 'wpinv-page'; |
|
291 | + } |
|
292 | 292 | |
293 | - return array_unique( $classes ); |
|
293 | + return array_unique( $classes ); |
|
294 | 294 | } |
295 | 295 | add_filter( 'body_class', 'wpinv_add_body_classes' ); |
296 | 296 | |
@@ -859,21 +859,21 @@ discard block |
||
859 | 859 | |
860 | 860 | $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format ); |
861 | 861 | |
862 | - // Remove unavailable tags. |
|
862 | + // Remove unavailable tags. |
|
863 | 863 | $formatted_address = preg_replace( "/\{\{\w+\}\}/", '', $formatted_address ); |
864 | 864 | |
865 | 865 | // Clean up white space. |
866 | - $formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) ); |
|
866 | + $formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) ); |
|
867 | 867 | $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address ); |
868 | 868 | |
869 | 869 | // Break newlines apart and remove empty lines/trim commas and white space. |
870 | - $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) ); |
|
870 | + $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) ); |
|
871 | 871 | |
872 | 872 | // Add html breaks. |
873 | - $formatted_address = implode( $separator, $formatted_address ); |
|
873 | + $formatted_address = implode( $separator, $formatted_address ); |
|
874 | 874 | |
875 | - // We're done! |
|
876 | - return $formatted_address; |
|
875 | + // We're done! |
|
876 | + return $formatted_address; |
|
877 | 877 | |
878 | 878 | } |
879 | 879 | |
@@ -1075,7 +1075,7 @@ discard block |
||
1075 | 1075 | } |
1076 | 1076 | |
1077 | 1077 | function wpinv_empty_cart_message() { |
1078 | - return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1078 | + return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1079 | 1079 | } |
1080 | 1080 | |
1081 | 1081 | /** |
@@ -1343,10 +1343,10 @@ discard block |
||
1343 | 1343 | |
1344 | 1344 | if ( 0 == count( $form->get_items() ) ) { |
1345 | 1345 | echo aui()->alert( |
1346 | - array( |
|
1347 | - 'type' => 'warning', |
|
1348 | - 'content' => __( 'No published items found', 'invoicing' ), |
|
1349 | - ) |
|
1346 | + array( |
|
1347 | + 'type' => 'warning', |
|
1348 | + 'content' => __( 'No published items found', 'invoicing' ), |
|
1349 | + ) |
|
1350 | 1350 | ); |
1351 | 1351 | return; |
1352 | 1352 | } |
@@ -1364,21 +1364,21 @@ discard block |
||
1364 | 1364 | $invoice = wpinv_get_invoice( $invoice_id ); |
1365 | 1365 | |
1366 | 1366 | if ( empty( $invoice ) ) { |
1367 | - echo aui()->alert( |
|
1368 | - array( |
|
1369 | - 'type' => 'warning', |
|
1370 | - 'content' => __( 'Invoice not found', 'invoicing' ), |
|
1371 | - ) |
|
1367 | + echo aui()->alert( |
|
1368 | + array( |
|
1369 | + 'type' => 'warning', |
|
1370 | + 'content' => __( 'Invoice not found', 'invoicing' ), |
|
1371 | + ) |
|
1372 | 1372 | ); |
1373 | 1373 | return; |
1374 | 1374 | } |
1375 | 1375 | |
1376 | 1376 | if ( $invoice->is_paid() ) { |
1377 | - echo aui()->alert( |
|
1378 | - array( |
|
1379 | - 'type' => 'warning', |
|
1380 | - 'content' => __( 'Invoice has already been paid', 'invoicing' ), |
|
1381 | - ) |
|
1377 | + echo aui()->alert( |
|
1378 | + array( |
|
1379 | + 'type' => 'warning', |
|
1380 | + 'content' => __( 'Invoice has already been paid', 'invoicing' ), |
|
1381 | + ) |
|
1382 | 1382 | ); |
1383 | 1383 | return; |
1384 | 1384 | } |
@@ -1440,7 +1440,7 @@ discard block |
||
1440 | 1440 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-form='$form'>$label</button>"; |
1441 | 1441 | } |
1442 | 1442 | |
1443 | - if ( ! empty( $items ) ) { |
|
1443 | + if ( ! empty( $items ) ) { |
|
1444 | 1444 | $items = esc_attr( $items ); |
1445 | 1445 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-item='$items'>$label</button>"; |
1446 | 1446 | } |
@@ -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,1012 +11,1012 @@ 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 | - 'label' => '', |
|
33 | - 'label_after'=> false, |
|
34 | - 'label_class'=> '', |
|
35 | - 'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
36 | - 'help_text' => '', |
|
37 | - 'validation_text' => '', |
|
38 | - 'validation_pattern' => '', |
|
39 | - 'no_wrap' => false, |
|
40 | - 'input_group_right' => '', |
|
41 | - 'input_group_left' => '', |
|
42 | - 'input_group_right_inside' => false, // forces the input group inside the input |
|
43 | - 'input_group_left_inside' => false, // forces the input group inside the input |
|
44 | - 'step' => '', |
|
45 | - 'switch' => false, // to show checkbox as a switch |
|
46 | - 'checked' => false, // set a checkbox or radio as selected |
|
47 | - 'password_toggle' => true, // toggle view/hide password |
|
48 | - 'element_require' => '', // [%element_id%] == "1" |
|
49 | - 'extra_attributes' => array() // an array of extra attributes |
|
50 | - ); |
|
51 | - |
|
52 | - /** |
|
53 | - * Parse incoming $args into an array and merge it with $defaults |
|
54 | - */ |
|
55 | - $args = wp_parse_args( $args, $defaults ); |
|
56 | - $output = ''; |
|
57 | - if ( ! empty( $args['type'] ) ) { |
|
58 | - // hidden label option needs to be empty |
|
59 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
60 | - |
|
61 | - $type = sanitize_html_class( $args['type'] ); |
|
62 | - |
|
63 | - $help_text = ''; |
|
64 | - $label = ''; |
|
65 | - $label_after = $args['label_after']; |
|
66 | - $label_args = array( |
|
67 | - 'title'=> $args['label'], |
|
68 | - 'for'=> $args['id'], |
|
69 | - 'class' => $args['label_class']." ", |
|
70 | - 'label_type' => $args['label_type'] |
|
71 | - ); |
|
72 | - |
|
73 | - // floating labels need label after |
|
74 | - if( $args['label_type'] == 'floating' && $type != 'checkbox' ){ |
|
75 | - $label_after = true; |
|
76 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
77 | - } |
|
78 | - |
|
79 | - // Some special sauce for files |
|
80 | - if($type=='file' ){ |
|
81 | - $label_after = true; // if type file we need the label after |
|
82 | - $args['class'] .= ' custom-file-input '; |
|
83 | - }elseif($type=='checkbox'){ |
|
84 | - $label_after = true; // if type file we need the label after |
|
85 | - $args['class'] .= ' custom-control-input '; |
|
86 | - }elseif($type=='datepicker' || $type=='timepicker'){ |
|
87 | - $type = 'text'; |
|
88 | - //$args['class'] .= ' aui-flatpickr bg-initial '; |
|
89 | - $args['class'] .= ' bg-initial '; |
|
90 | - |
|
91 | - $args['extra_attributes']['data-aui-init'] = 'flatpickr'; |
|
92 | - // enqueue the script |
|
93 | - $aui_settings = AyeCode_UI_Settings::instance(); |
|
94 | - $aui_settings->enqueue_flatpickr(); |
|
95 | - } |
|
96 | - |
|
97 | - |
|
98 | - // open/type |
|
99 | - $output .= '<input type="' . $type . '" '; |
|
100 | - |
|
101 | - // name |
|
102 | - if(!empty($args['name'])){ |
|
103 | - $output .= ' name="'.esc_attr($args['name']).'" '; |
|
104 | - } |
|
105 | - |
|
106 | - // id |
|
107 | - if(!empty($args['id'])){ |
|
108 | - $output .= ' id="'.sanitize_html_class($args['id']).'" '; |
|
109 | - } |
|
110 | - |
|
111 | - // placeholder |
|
112 | - if(isset($args['placeholder']) && '' != $args['placeholder'] ){ |
|
113 | - $output .= ' placeholder="'.esc_attr($args['placeholder']).'" '; |
|
114 | - } |
|
115 | - |
|
116 | - // title |
|
117 | - if(!empty($args['title'])){ |
|
118 | - $output .= ' title="'.esc_attr($args['title']).'" '; |
|
119 | - } |
|
120 | - |
|
121 | - // value |
|
122 | - if(!empty($args['value'])){ |
|
123 | - $output .= ' value="'.sanitize_text_field($args['value']).'" '; |
|
124 | - } |
|
125 | - |
|
126 | - // checked, for radio and checkboxes |
|
127 | - if( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ){ |
|
128 | - $output .= ' checked '; |
|
129 | - } |
|
130 | - |
|
131 | - // validation text |
|
132 | - if(!empty($args['validation_text'])){ |
|
133 | - $output .= ' oninvalid="setCustomValidity(\''.esc_attr($args['validation_text']).'\')" '; |
|
134 | - $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
135 | - } |
|
136 | - |
|
137 | - // validation_pattern |
|
138 | - if(!empty($args['validation_pattern'])){ |
|
139 | - $output .= ' pattern="'.$args['validation_pattern'].'" '; |
|
140 | - } |
|
141 | - |
|
142 | - // step (for numbers) |
|
143 | - if(!empty($args['step'])){ |
|
144 | - $output .= ' step="'.$args['step'].'" '; |
|
145 | - } |
|
146 | - |
|
147 | - // required |
|
148 | - if(!empty($args['required'])){ |
|
149 | - $output .= ' required '; |
|
150 | - } |
|
151 | - |
|
152 | - // class |
|
153 | - $class = !empty($args['class']) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
154 | - $output .= ' class="form-control '.$class.'" '; |
|
155 | - |
|
156 | - // data-attributes |
|
157 | - $output .= AUI_Component_Helper::data_attributes($args); |
|
158 | - |
|
159 | - // extra attributes |
|
160 | - if(!empty($args['extra_attributes'])){ |
|
161 | - $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
162 | - } |
|
163 | - |
|
164 | - // close |
|
165 | - $output .= ' >'; |
|
166 | - |
|
167 | - |
|
168 | - // label |
|
169 | - if(!empty($args['label'])){ |
|
170 | - if($type == 'file'){$label_args['class'] .= 'custom-file-label';} |
|
171 | - elseif($type == 'checkbox'){$label_args['class'] .= 'custom-control-label';} |
|
172 | - $label = self::label( $label_args, $type ); |
|
173 | - } |
|
174 | - |
|
175 | - // help text |
|
176 | - if(!empty($args['help_text'])){ |
|
177 | - $help_text = AUI_Component_Helper::help_text($args['help_text']); |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - // set help text in the correct possition |
|
182 | - if($label_after){ |
|
183 | - $output .= $label . $help_text; |
|
184 | - } |
|
185 | - |
|
186 | - // some input types need a separate wrap |
|
187 | - if($type == 'file') { |
|
188 | - $output = self::wrap( array( |
|
189 | - 'content' => $output, |
|
190 | - 'class' => 'form-group custom-file' |
|
191 | - ) ); |
|
192 | - }elseif($type == 'checkbox'){ |
|
193 | - $wrap_class = $args['switch'] ? 'custom-switch' : 'custom-checkbox'; |
|
194 | - $output = self::wrap( array( |
|
195 | - 'content' => $output, |
|
196 | - 'class' => 'custom-control '.$wrap_class |
|
197 | - ) ); |
|
198 | - |
|
199 | - if($args['label_type']=='horizontal'){ |
|
200 | - $output = '<div class="col-sm-2 col-form-label"></div><div class="col-sm-10">' . $output . '</div>'; |
|
201 | - } |
|
202 | - }elseif($type == 'password' && $args['password_toggle'] && !$args['input_group_right']){ |
|
203 | - |
|
204 | - |
|
205 | - // allow password field to toggle view |
|
206 | - $args['input_group_right'] = '<span class="input-group-text c-pointer px-3" |
|
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 | + 'label' => '', |
|
33 | + 'label_after'=> false, |
|
34 | + 'label_class'=> '', |
|
35 | + 'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
36 | + 'help_text' => '', |
|
37 | + 'validation_text' => '', |
|
38 | + 'validation_pattern' => '', |
|
39 | + 'no_wrap' => false, |
|
40 | + 'input_group_right' => '', |
|
41 | + 'input_group_left' => '', |
|
42 | + 'input_group_right_inside' => false, // forces the input group inside the input |
|
43 | + 'input_group_left_inside' => false, // forces the input group inside the input |
|
44 | + 'step' => '', |
|
45 | + 'switch' => false, // to show checkbox as a switch |
|
46 | + 'checked' => false, // set a checkbox or radio as selected |
|
47 | + 'password_toggle' => true, // toggle view/hide password |
|
48 | + 'element_require' => '', // [%element_id%] == "1" |
|
49 | + 'extra_attributes' => array() // an array of extra attributes |
|
50 | + ); |
|
51 | + |
|
52 | + /** |
|
53 | + * Parse incoming $args into an array and merge it with $defaults |
|
54 | + */ |
|
55 | + $args = wp_parse_args( $args, $defaults ); |
|
56 | + $output = ''; |
|
57 | + if ( ! empty( $args['type'] ) ) { |
|
58 | + // hidden label option needs to be empty |
|
59 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
60 | + |
|
61 | + $type = sanitize_html_class( $args['type'] ); |
|
62 | + |
|
63 | + $help_text = ''; |
|
64 | + $label = ''; |
|
65 | + $label_after = $args['label_after']; |
|
66 | + $label_args = array( |
|
67 | + 'title'=> $args['label'], |
|
68 | + 'for'=> $args['id'], |
|
69 | + 'class' => $args['label_class']." ", |
|
70 | + 'label_type' => $args['label_type'] |
|
71 | + ); |
|
72 | + |
|
73 | + // floating labels need label after |
|
74 | + if( $args['label_type'] == 'floating' && $type != 'checkbox' ){ |
|
75 | + $label_after = true; |
|
76 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
77 | + } |
|
78 | + |
|
79 | + // Some special sauce for files |
|
80 | + if($type=='file' ){ |
|
81 | + $label_after = true; // if type file we need the label after |
|
82 | + $args['class'] .= ' custom-file-input '; |
|
83 | + }elseif($type=='checkbox'){ |
|
84 | + $label_after = true; // if type file we need the label after |
|
85 | + $args['class'] .= ' custom-control-input '; |
|
86 | + }elseif($type=='datepicker' || $type=='timepicker'){ |
|
87 | + $type = 'text'; |
|
88 | + //$args['class'] .= ' aui-flatpickr bg-initial '; |
|
89 | + $args['class'] .= ' bg-initial '; |
|
90 | + |
|
91 | + $args['extra_attributes']['data-aui-init'] = 'flatpickr'; |
|
92 | + // enqueue the script |
|
93 | + $aui_settings = AyeCode_UI_Settings::instance(); |
|
94 | + $aui_settings->enqueue_flatpickr(); |
|
95 | + } |
|
96 | + |
|
97 | + |
|
98 | + // open/type |
|
99 | + $output .= '<input type="' . $type . '" '; |
|
100 | + |
|
101 | + // name |
|
102 | + if(!empty($args['name'])){ |
|
103 | + $output .= ' name="'.esc_attr($args['name']).'" '; |
|
104 | + } |
|
105 | + |
|
106 | + // id |
|
107 | + if(!empty($args['id'])){ |
|
108 | + $output .= ' id="'.sanitize_html_class($args['id']).'" '; |
|
109 | + } |
|
110 | + |
|
111 | + // placeholder |
|
112 | + if(isset($args['placeholder']) && '' != $args['placeholder'] ){ |
|
113 | + $output .= ' placeholder="'.esc_attr($args['placeholder']).'" '; |
|
114 | + } |
|
115 | + |
|
116 | + // title |
|
117 | + if(!empty($args['title'])){ |
|
118 | + $output .= ' title="'.esc_attr($args['title']).'" '; |
|
119 | + } |
|
120 | + |
|
121 | + // value |
|
122 | + if(!empty($args['value'])){ |
|
123 | + $output .= ' value="'.sanitize_text_field($args['value']).'" '; |
|
124 | + } |
|
125 | + |
|
126 | + // checked, for radio and checkboxes |
|
127 | + if( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ){ |
|
128 | + $output .= ' checked '; |
|
129 | + } |
|
130 | + |
|
131 | + // validation text |
|
132 | + if(!empty($args['validation_text'])){ |
|
133 | + $output .= ' oninvalid="setCustomValidity(\''.esc_attr($args['validation_text']).'\')" '; |
|
134 | + $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
135 | + } |
|
136 | + |
|
137 | + // validation_pattern |
|
138 | + if(!empty($args['validation_pattern'])){ |
|
139 | + $output .= ' pattern="'.$args['validation_pattern'].'" '; |
|
140 | + } |
|
141 | + |
|
142 | + // step (for numbers) |
|
143 | + if(!empty($args['step'])){ |
|
144 | + $output .= ' step="'.$args['step'].'" '; |
|
145 | + } |
|
146 | + |
|
147 | + // required |
|
148 | + if(!empty($args['required'])){ |
|
149 | + $output .= ' required '; |
|
150 | + } |
|
151 | + |
|
152 | + // class |
|
153 | + $class = !empty($args['class']) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
154 | + $output .= ' class="form-control '.$class.'" '; |
|
155 | + |
|
156 | + // data-attributes |
|
157 | + $output .= AUI_Component_Helper::data_attributes($args); |
|
158 | + |
|
159 | + // extra attributes |
|
160 | + if(!empty($args['extra_attributes'])){ |
|
161 | + $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
162 | + } |
|
163 | + |
|
164 | + // close |
|
165 | + $output .= ' >'; |
|
166 | + |
|
167 | + |
|
168 | + // label |
|
169 | + if(!empty($args['label'])){ |
|
170 | + if($type == 'file'){$label_args['class'] .= 'custom-file-label';} |
|
171 | + elseif($type == 'checkbox'){$label_args['class'] .= 'custom-control-label';} |
|
172 | + $label = self::label( $label_args, $type ); |
|
173 | + } |
|
174 | + |
|
175 | + // help text |
|
176 | + if(!empty($args['help_text'])){ |
|
177 | + $help_text = AUI_Component_Helper::help_text($args['help_text']); |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + // set help text in the correct possition |
|
182 | + if($label_after){ |
|
183 | + $output .= $label . $help_text; |
|
184 | + } |
|
185 | + |
|
186 | + // some input types need a separate wrap |
|
187 | + if($type == 'file') { |
|
188 | + $output = self::wrap( array( |
|
189 | + 'content' => $output, |
|
190 | + 'class' => 'form-group custom-file' |
|
191 | + ) ); |
|
192 | + }elseif($type == 'checkbox'){ |
|
193 | + $wrap_class = $args['switch'] ? 'custom-switch' : 'custom-checkbox'; |
|
194 | + $output = self::wrap( array( |
|
195 | + 'content' => $output, |
|
196 | + 'class' => 'custom-control '.$wrap_class |
|
197 | + ) ); |
|
198 | + |
|
199 | + if($args['label_type']=='horizontal'){ |
|
200 | + $output = '<div class="col-sm-2 col-form-label"></div><div class="col-sm-10">' . $output . '</div>'; |
|
201 | + } |
|
202 | + }elseif($type == 'password' && $args['password_toggle'] && !$args['input_group_right']){ |
|
203 | + |
|
204 | + |
|
205 | + // allow password field to toggle view |
|
206 | + $args['input_group_right'] = '<span class="input-group-text c-pointer px-3" |
|
207 | 207 | onclick="var $el = jQuery(this).find(\'i\');$el.toggleClass(\'fa-eye fa-eye-slash\'); |
208 | 208 | var $eli = jQuery(this).parent().parent().find(\'input\'); |
209 | 209 | if($el.hasClass(\'fa-eye\')) |
210 | 210 | {$eli.attr(\'type\',\'text\');} |
211 | 211 | else{$eli.attr(\'type\',\'password\');}" |
212 | 212 | ><i class="far fa-fw fa-eye-slash"></i></span>'; |
213 | - } |
|
214 | - |
|
215 | - // input group wraps |
|
216 | - if($args['input_group_left'] || $args['input_group_right']){ |
|
217 | - $w100 = strpos($args['class'], 'w-100') !== false ? ' w-100' : ''; |
|
218 | - if($args['input_group_left']){ |
|
219 | - $output = self::wrap( array( |
|
220 | - 'content' => $output, |
|
221 | - 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative'.$w100 : 'input-group', |
|
222 | - 'input_group_left' => $args['input_group_left'], |
|
223 | - 'input_group_left_inside' => $args['input_group_left_inside'] |
|
224 | - ) ); |
|
225 | - } |
|
226 | - if($args['input_group_right']){ |
|
227 | - $output = self::wrap( array( |
|
228 | - 'content' => $output, |
|
229 | - 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative'.$w100 : 'input-group', |
|
230 | - 'input_group_right' => $args['input_group_right'], |
|
231 | - 'input_group_right_inside' => $args['input_group_right_inside'] |
|
232 | - ) ); |
|
233 | - } |
|
234 | - |
|
235 | - } |
|
236 | - |
|
237 | - if(!$label_after){ |
|
238 | - $output .= $help_text; |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - if($args['label_type']=='horizontal' && $type != 'checkbox'){ |
|
243 | - $output = self::wrap( array( |
|
244 | - 'content' => $output, |
|
245 | - 'class' => 'col-sm-10', |
|
246 | - ) ); |
|
247 | - } |
|
248 | - |
|
249 | - if(!$label_after){ |
|
250 | - $output = $label . $output; |
|
251 | - } |
|
252 | - |
|
253 | - // wrap |
|
254 | - if(!$args['no_wrap']){ |
|
255 | - |
|
256 | - $form_group_class = $args['label_type']=='floating' && $type != 'checkbox' ? 'form-label-group' : 'form-group'; |
|
257 | - $wrap_class = $args['label_type']=='horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
258 | - $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
259 | - $output = self::wrap(array( |
|
260 | - 'content' => $output, |
|
261 | - 'class' => $wrap_class, |
|
262 | - 'element_require' => $args['element_require'], |
|
263 | - 'argument_id' => $args['id'] |
|
264 | - )); |
|
265 | - } |
|
266 | - |
|
267 | - |
|
268 | - |
|
269 | - } |
|
270 | - |
|
271 | - return $output; |
|
272 | - } |
|
273 | - |
|
274 | - /** |
|
275 | - * Build the component. |
|
276 | - * |
|
277 | - * @param array $args |
|
278 | - * |
|
279 | - * @return string The rendered component. |
|
280 | - */ |
|
281 | - public static function textarea($args = array()){ |
|
282 | - $defaults = array( |
|
283 | - 'name' => '', |
|
284 | - 'class' => '', |
|
285 | - 'wrap_class' => '', |
|
286 | - 'id' => '', |
|
287 | - 'placeholder'=> '', |
|
288 | - 'title' => '', |
|
289 | - 'value' => '', |
|
290 | - 'required' => false, |
|
291 | - 'label' => '', |
|
292 | - 'label_after'=> false, |
|
293 | - 'label_class' => '', |
|
294 | - 'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
295 | - 'help_text' => '', |
|
296 | - 'validation_text' => '', |
|
297 | - 'validation_pattern' => '', |
|
298 | - 'no_wrap' => false, |
|
299 | - 'rows' => '', |
|
300 | - 'wysiwyg' => false, |
|
301 | - 'element_require' => '', // [%element_id%] == "1" |
|
302 | - ); |
|
303 | - |
|
304 | - /** |
|
305 | - * Parse incoming $args into an array and merge it with $defaults |
|
306 | - */ |
|
307 | - $args = wp_parse_args( $args, $defaults ); |
|
308 | - $output = ''; |
|
309 | - |
|
310 | - // hidden label option needs to be empty |
|
311 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
312 | - |
|
313 | - // floating labels don't work with wysiwyg so set it as top |
|
314 | - if($args['label_type'] == 'floating' && !empty($args['wysiwyg'])){ |
|
315 | - $args['label_type'] = 'top'; |
|
316 | - } |
|
317 | - |
|
318 | - $label_after = $args['label_after']; |
|
319 | - |
|
320 | - // floating labels need label after |
|
321 | - if( $args['label_type'] == 'floating' && empty($args['wysiwyg']) ){ |
|
322 | - $label_after = true; |
|
323 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
324 | - } |
|
325 | - |
|
326 | - // label |
|
327 | - if(!empty($args['label']) && is_array($args['label'])){ |
|
328 | - }elseif(!empty($args['label']) && !$label_after){ |
|
329 | - $label_args = array( |
|
330 | - 'title'=> $args['label'], |
|
331 | - 'for'=> $args['id'], |
|
332 | - 'class' => $args['label_class']." ", |
|
333 | - 'label_type' => $args['label_type'] |
|
334 | - ); |
|
335 | - $output .= self::label( $label_args ); |
|
336 | - } |
|
337 | - |
|
338 | - // maybe horizontal label |
|
339 | - if($args['label_type']=='horizontal'){ |
|
340 | - $output .= '<div class="col-sm-10">'; |
|
341 | - } |
|
342 | - |
|
343 | - if(!empty($args['wysiwyg'])){ |
|
344 | - ob_start(); |
|
345 | - $content = $args['value']; |
|
346 | - $editor_id = !empty($args['id']) ? sanitize_html_class($args['id']) : 'wp_editor'; |
|
347 | - $settings = array( |
|
348 | - 'textarea_rows' => !empty(absint($args['rows'])) ? absint($args['rows']) : 4, |
|
349 | - 'quicktags' => false, |
|
350 | - 'media_buttons' => false, |
|
351 | - 'editor_class' => 'form-control', |
|
352 | - 'textarea_name' => !empty($args['name']) ? sanitize_html_class($args['name']) : sanitize_html_class($args['id']), |
|
353 | - 'teeny' => true, |
|
354 | - ); |
|
355 | - |
|
356 | - // maybe set settings if array |
|
357 | - if(is_array($args['wysiwyg'])){ |
|
358 | - $settings = wp_parse_args( $args['wysiwyg'], $settings ); |
|
359 | - } |
|
360 | - |
|
361 | - wp_editor( $content, $editor_id, $settings ); |
|
362 | - $output .= ob_get_clean(); |
|
363 | - }else{ |
|
364 | - |
|
365 | - // open |
|
366 | - $output .= '<textarea '; |
|
367 | - |
|
368 | - // name |
|
369 | - if(!empty($args['name'])){ |
|
370 | - $output .= ' name="'.sanitize_html_class($args['name']).'" '; |
|
371 | - } |
|
372 | - |
|
373 | - // id |
|
374 | - if(!empty($args['id'])){ |
|
375 | - $output .= ' id="'.sanitize_html_class($args['id']).'" '; |
|
376 | - } |
|
377 | - |
|
378 | - // placeholder |
|
379 | - if(isset($args['placeholder']) && '' != $args['placeholder']){ |
|
380 | - $output .= ' placeholder="'.esc_attr($args['placeholder']).'" '; |
|
381 | - } |
|
382 | - |
|
383 | - // title |
|
384 | - if(!empty($args['title'])){ |
|
385 | - $output .= ' title="'.esc_attr($args['title']).'" '; |
|
386 | - } |
|
387 | - |
|
388 | - // validation text |
|
389 | - if(!empty($args['validation_text'])){ |
|
390 | - $output .= ' oninvalid="setCustomValidity(\''.esc_attr($args['validation_text']).'\')" '; |
|
391 | - $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
392 | - } |
|
393 | - |
|
394 | - // validation_pattern |
|
395 | - if(!empty($args['validation_pattern'])){ |
|
396 | - $output .= ' pattern="'.$args['validation_pattern'].'" '; |
|
397 | - } |
|
398 | - |
|
399 | - // required |
|
400 | - if(!empty($args['required'])){ |
|
401 | - $output .= ' required '; |
|
402 | - } |
|
403 | - |
|
404 | - // rows |
|
405 | - if(!empty($args['rows'])){ |
|
406 | - $output .= ' rows="'.absint($args['rows']).'" '; |
|
407 | - } |
|
408 | - |
|
409 | - |
|
410 | - // class |
|
411 | - $class = !empty($args['class']) ? $args['class'] : ''; |
|
412 | - $output .= ' class="form-control '.$class.'" '; |
|
413 | - |
|
414 | - |
|
415 | - // close tag |
|
416 | - $output .= ' >'; |
|
417 | - |
|
418 | - // value |
|
419 | - if(!empty($args['value'])){ |
|
420 | - $output .= sanitize_textarea_field($args['value']); |
|
421 | - } |
|
422 | - |
|
423 | - // closing tag |
|
424 | - $output .= '</textarea>'; |
|
425 | - |
|
426 | - } |
|
427 | - |
|
428 | - if(!empty($args['label']) && $label_after){ |
|
429 | - $label_args = array( |
|
430 | - 'title'=> $args['label'], |
|
431 | - 'for'=> $args['id'], |
|
432 | - 'class' => $args['label_class']." ", |
|
433 | - 'label_type' => $args['label_type'] |
|
434 | - ); |
|
435 | - $output .= self::label( $label_args ); |
|
436 | - } |
|
437 | - |
|
438 | - // help text |
|
439 | - if(!empty($args['help_text'])){ |
|
440 | - $output .= AUI_Component_Helper::help_text($args['help_text']); |
|
441 | - } |
|
442 | - |
|
443 | - // maybe horizontal label |
|
444 | - if($args['label_type']=='horizontal'){ |
|
445 | - $output .= '</div>'; |
|
446 | - } |
|
447 | - |
|
448 | - |
|
449 | - // wrap |
|
450 | - if(!$args['no_wrap']){ |
|
451 | - $form_group_class = $args['label_type']=='floating' ? 'form-label-group' : 'form-group'; |
|
452 | - $wrap_class = $args['label_type']=='horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
453 | - $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
454 | - $output = self::wrap(array( |
|
455 | - 'content' => $output, |
|
456 | - 'class' => $wrap_class, |
|
457 | - 'element_require' => $args['element_require'], |
|
458 | - 'argument_id' => $args['id'] |
|
459 | - )); |
|
460 | - } |
|
461 | - |
|
462 | - |
|
463 | - return $output; |
|
464 | - } |
|
465 | - |
|
466 | - public static function label($args = array(), $type = ''){ |
|
467 | - //<label for="exampleInputEmail1">Email address</label> |
|
468 | - $defaults = array( |
|
469 | - 'title' => 'div', |
|
470 | - 'for' => '', |
|
471 | - 'class' => '', |
|
472 | - 'label_type' => '', // empty = hidden, top, horizontal |
|
473 | - ); |
|
474 | - |
|
475 | - /** |
|
476 | - * Parse incoming $args into an array and merge it with $defaults |
|
477 | - */ |
|
478 | - $args = wp_parse_args( $args, $defaults ); |
|
479 | - $output = ''; |
|
480 | - |
|
481 | - if($args['title']){ |
|
482 | - |
|
483 | - // maybe hide labels //@todo set a global option for visibility class |
|
484 | - if($type == 'file' || $type == 'checkbox' || $type == 'radio' || !empty($args['label_type']) ){ |
|
485 | - $class = $args['class']; |
|
486 | - }else{ |
|
487 | - $class = 'sr-only '.$args['class']; |
|
488 | - } |
|
489 | - |
|
490 | - // maybe horizontal |
|
491 | - if($args['label_type']=='horizontal' && $type != 'checkbox'){ |
|
492 | - $class .= ' col-sm-2 col-form-label'; |
|
493 | - } |
|
494 | - |
|
495 | - // open |
|
496 | - $output .= '<label '; |
|
497 | - |
|
498 | - // for |
|
499 | - if(!empty($args['for'])){ |
|
500 | - $output .= ' for="'.sanitize_text_field($args['for']).'" '; |
|
501 | - } |
|
502 | - |
|
503 | - // class |
|
504 | - $class = $class ? AUI_Component_Helper::esc_classes( $class ) : ''; |
|
505 | - $output .= ' class="'.$class.'" '; |
|
506 | - |
|
507 | - // close |
|
508 | - $output .= '>'; |
|
509 | - |
|
510 | - |
|
511 | - // title, don't escape fully as can contain html |
|
512 | - if(!empty($args['title'])){ |
|
513 | - $output .= wp_kses_post($args['title']); |
|
514 | - } |
|
515 | - |
|
516 | - // close wrap |
|
517 | - $output .= '</label>'; |
|
518 | - |
|
519 | - |
|
520 | - } |
|
521 | - |
|
522 | - |
|
523 | - return $output; |
|
524 | - } |
|
525 | - |
|
526 | - /** |
|
527 | - * Wrap some content in a HTML wrapper. |
|
528 | - * |
|
529 | - * @param array $args |
|
530 | - * |
|
531 | - * @return string |
|
532 | - */ |
|
533 | - public static function wrap($args = array()){ |
|
534 | - $defaults = array( |
|
535 | - 'type' => 'div', |
|
536 | - 'class' => 'form-group', |
|
537 | - 'content' => '', |
|
538 | - 'input_group_left' => '', |
|
539 | - 'input_group_right' => '', |
|
540 | - 'input_group_left_inside' => false, |
|
541 | - 'input_group_right_inside' => false, |
|
542 | - 'element_require' => '', |
|
543 | - 'argument_id' => '', |
|
544 | - ); |
|
545 | - |
|
546 | - /** |
|
547 | - * Parse incoming $args into an array and merge it with $defaults |
|
548 | - */ |
|
549 | - $args = wp_parse_args( $args, $defaults ); |
|
550 | - $output = ''; |
|
551 | - if($args['type']){ |
|
552 | - |
|
553 | - // open |
|
554 | - $output .= '<'.sanitize_html_class($args['type']); |
|
555 | - |
|
556 | - // element require |
|
557 | - if(!empty($args['element_require'])){ |
|
558 | - $output .= AUI_Component_Helper::element_require($args['element_require']); |
|
559 | - $args['class'] .= " aui-conditional-field"; |
|
560 | - } |
|
561 | - |
|
562 | - // argument_id |
|
563 | - if( !empty($args['argument_id']) ){ |
|
564 | - $output .= ' data-argument="'.esc_attr($args['argument_id']).'"'; |
|
565 | - } |
|
566 | - |
|
567 | - // class |
|
568 | - $class = !empty($args['class']) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
569 | - $output .= ' class="'.$class.'" '; |
|
570 | - |
|
571 | - // close wrap |
|
572 | - $output .= ' >'; |
|
573 | - |
|
574 | - |
|
575 | - // Input group left |
|
576 | - if(!empty($args['input_group_left'])){ |
|
577 | - $position_class = !empty($args['input_group_left_inside']) ? 'position-absolute h-100' : ''; |
|
578 | - $input_group_left = strpos($args['input_group_left'], '<') !== false ? $args['input_group_left'] : '<span class="input-group-text">'.$args['input_group_left'].'</span>'; |
|
579 | - $output .= '<div class="input-group-prepend '.$position_class.'">'.$input_group_left.'</div>'; |
|
580 | - } |
|
581 | - |
|
582 | - // content |
|
583 | - $output .= $args['content']; |
|
584 | - |
|
585 | - // Input group right |
|
586 | - if(!empty($args['input_group_right'])){ |
|
587 | - $position_class = !empty($args['input_group_left_inside']) ? 'position-absolute h-100' : ''; |
|
588 | - $input_group_right = strpos($args['input_group_right'], '<') !== false ? $args['input_group_right'] : '<span class="input-group-text">'.$args['input_group_right'].'</span>'; |
|
589 | - $output .= '<div class="input-group-append '.$position_class.'">'.$input_group_right.'</div>'; |
|
590 | - } |
|
591 | - |
|
592 | - |
|
593 | - // close wrap |
|
594 | - $output .= '</'.sanitize_html_class($args['type']).'>'; |
|
595 | - |
|
596 | - |
|
597 | - }else{ |
|
598 | - $output = $args['content']; |
|
599 | - } |
|
600 | - |
|
601 | - return $output; |
|
602 | - } |
|
603 | - |
|
604 | - /** |
|
605 | - * Build the component. |
|
606 | - * |
|
607 | - * @param array $args |
|
608 | - * |
|
609 | - * @return string The rendered component. |
|
610 | - */ |
|
611 | - public static function select($args = array()){ |
|
612 | - $defaults = array( |
|
613 | - 'class' => '', |
|
614 | - 'wrap_class' => '', |
|
615 | - 'id' => '', |
|
616 | - 'title' => '', |
|
617 | - 'value' => '', // can be an array or a string |
|
618 | - 'required' => false, |
|
619 | - 'label' => '', |
|
620 | - 'label_after'=> false, |
|
621 | - 'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
622 | - 'label_class' => '', |
|
623 | - 'help_text' => '', |
|
624 | - 'placeholder'=> '', |
|
625 | - 'options' => array(), // array or string |
|
626 | - 'icon' => '', |
|
627 | - 'multiple' => false, |
|
628 | - 'select2' => false, |
|
629 | - 'no_wrap' => false, |
|
630 | - 'element_require' => '', // [%element_id%] == "1" |
|
631 | - 'extra_attributes' => array(), // an array of extra attributes |
|
632 | - ); |
|
633 | - |
|
634 | - /** |
|
635 | - * Parse incoming $args into an array and merge it with $defaults |
|
636 | - */ |
|
637 | - $args = wp_parse_args( $args, $defaults ); |
|
638 | - $output = ''; |
|
639 | - |
|
640 | - // for now lets hide floating labels |
|
641 | - if( $args['label_type'] == 'floating' ){$args['label_type'] = 'hidden';} |
|
642 | - |
|
643 | - // hidden label option needs to be empty |
|
644 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
645 | - |
|
646 | - |
|
647 | - $label_after = $args['label_after']; |
|
648 | - |
|
649 | - // floating labels need label after |
|
650 | - if( $args['label_type'] == 'floating' ){ |
|
651 | - $label_after = true; |
|
652 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
653 | - } |
|
654 | - |
|
655 | - // Maybe setup select2 |
|
656 | - $is_select2 = false; |
|
657 | - if(!empty($args['select2'])){ |
|
658 | - $args['class'] .= ' aui-select2'; |
|
659 | - $is_select2 = true; |
|
660 | - }elseif( strpos($args['class'], 'aui-select2') !== false){ |
|
661 | - $is_select2 = true; |
|
662 | - } |
|
663 | - |
|
664 | - // select2 tags |
|
665 | - if( !empty($args['select2']) && $args['select2'] === 'tags'){ // triple equals needed here for some reason |
|
666 | - $args['data-tags'] = 'true'; |
|
667 | - $args['data-token-separators'] = "[',']"; |
|
668 | - $args['multiple'] = true; |
|
669 | - } |
|
670 | - |
|
671 | - // select2 placeholder |
|
672 | - if($is_select2 && isset($args['placeholder']) && '' != $args['placeholder'] && empty($args['data-placeholder'])){ |
|
673 | - $args['data-placeholder'] = esc_attr($args['placeholder']); |
|
674 | - $args['data-allow-clear'] = isset($args['data-allow-clear']) ? (bool) $args['data-allow-clear'] : true; |
|
675 | - } |
|
676 | - |
|
677 | - // label |
|
678 | - if(!empty($args['label']) && is_array($args['label'])){ |
|
679 | - }elseif(!empty($args['label']) && !$label_after){ |
|
680 | - $label_args = array( |
|
681 | - 'title'=> $args['label'], |
|
682 | - 'for'=> $args['id'], |
|
683 | - 'class' => $args['label_class']." ", |
|
684 | - 'label_type' => $args['label_type'] |
|
685 | - ); |
|
686 | - $output .= self::label($label_args); |
|
687 | - } |
|
688 | - |
|
689 | - // maybe horizontal label |
|
690 | - if($args['label_type']=='horizontal'){ |
|
691 | - $output .= '<div class="col-sm-10">'; |
|
692 | - } |
|
693 | - |
|
694 | - // open/type |
|
695 | - $output .= '<select '; |
|
696 | - |
|
697 | - // style |
|
698 | - if($is_select2){ |
|
699 | - $output .= " style='width:100%;' "; |
|
700 | - } |
|
701 | - |
|
702 | - // element require |
|
703 | - if(!empty($args['element_require'])){ |
|
704 | - $output .= AUI_Component_Helper::element_require($args['element_require']); |
|
705 | - $args['class'] .= " aui-conditional-field"; |
|
706 | - } |
|
707 | - |
|
708 | - // class |
|
709 | - $class = !empty($args['class']) ? $args['class'] : ''; |
|
710 | - $output .= AUI_Component_Helper::class_attr('custom-select '.$class); |
|
711 | - |
|
712 | - // name |
|
713 | - if(!empty($args['name'])){ |
|
714 | - $output .= AUI_Component_Helper::name($args['name'],$args['multiple']); |
|
715 | - } |
|
716 | - |
|
717 | - // id |
|
718 | - if(!empty($args['id'])){ |
|
719 | - $output .= AUI_Component_Helper::id($args['id']); |
|
720 | - } |
|
721 | - |
|
722 | - // title |
|
723 | - if(!empty($args['title'])){ |
|
724 | - $output .= AUI_Component_Helper::title($args['title']); |
|
725 | - } |
|
726 | - |
|
727 | - // data-attributes |
|
728 | - $output .= AUI_Component_Helper::data_attributes($args); |
|
729 | - |
|
730 | - // aria-attributes |
|
731 | - $output .= AUI_Component_Helper::aria_attributes($args); |
|
732 | - |
|
733 | - // extra attributes |
|
734 | - if(!empty($args['extra_attributes'])){ |
|
735 | - $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
736 | - } |
|
737 | - |
|
738 | - // required |
|
739 | - if(!empty($args['required'])){ |
|
740 | - $output .= ' required '; |
|
741 | - } |
|
742 | - |
|
743 | - // multiple |
|
744 | - if(!empty($args['multiple'])){ |
|
745 | - $output .= ' multiple '; |
|
746 | - } |
|
747 | - |
|
748 | - // close opening tag |
|
749 | - $output .= ' >'; |
|
750 | - |
|
751 | - // placeholder |
|
752 | - if(isset($args['placeholder']) && '' != $args['placeholder'] && !$is_select2){ |
|
753 | - $output .= '<option value="" disabled selected hidden>'.esc_attr($args['placeholder']).'</option>'; |
|
754 | - }elseif($is_select2 && !empty($args['placeholder'])){ |
|
755 | - $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder |
|
756 | - } |
|
757 | - |
|
758 | - // Options |
|
759 | - if(!empty($args['options'])){ |
|
760 | - |
|
761 | - if(!is_array($args['options'])){ |
|
762 | - $output .= $args['options']; // not the preferred way but an option |
|
763 | - }else{ |
|
764 | - foreach($args['options'] as $val => $name){ |
|
765 | - $selected = ''; |
|
766 | - if(is_array($name)){ |
|
767 | - if (isset($name['optgroup']) && ($name['optgroup'] == 'start' || $name['optgroup'] == 'end')) { |
|
768 | - $option_label = isset($name['label']) ? $name['label'] : ''; |
|
769 | - |
|
770 | - $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr($option_label) . '">' : '</optgroup>'; |
|
771 | - } else { |
|
772 | - $option_label = isset($name['label']) ? $name['label'] : ''; |
|
773 | - $option_value = isset($name['value']) ? $name['value'] : ''; |
|
774 | - if(!empty($args['multiple']) && !empty($args['value']) && is_array($args['value']) ){ |
|
775 | - $selected = in_array($option_value, stripslashes_deep($args['value'])) ? "selected" : ""; |
|
776 | - } elseif(!empty($args['value'])) { |
|
777 | - $selected = selected($option_value,stripslashes_deep($args['value']), false); |
|
778 | - } |
|
779 | - |
|
780 | - $output .= '<option value="' . esc_attr($option_value) . '" ' . $selected . '>' . $option_label . '</option>'; |
|
781 | - } |
|
782 | - }else{ |
|
783 | - if(!empty($args['value'])){ |
|
784 | - if(is_array($args['value'])){ |
|
785 | - $selected = in_array($val,$args['value']) ? 'selected="selected"' : ''; |
|
786 | - } elseif(!empty($args['value'])) { |
|
787 | - $selected = selected( $args['value'], $val, false); |
|
788 | - } |
|
789 | - } |
|
790 | - $output .= '<option value="'.esc_attr($val).'" '.$selected.'>'.esc_attr($name).'</option>'; |
|
791 | - } |
|
792 | - } |
|
793 | - } |
|
794 | - |
|
795 | - } |
|
796 | - |
|
797 | - // closing tag |
|
798 | - $output .= '</select>'; |
|
799 | - |
|
800 | - if(!empty($args['label']) && $label_after){ |
|
801 | - $label_args = array( |
|
802 | - 'title'=> $args['label'], |
|
803 | - 'for'=> $args['id'], |
|
804 | - 'class' => $args['label_class']." ", |
|
805 | - 'label_type' => $args['label_type'] |
|
806 | - ); |
|
807 | - $output .= self::label($label_args); |
|
808 | - } |
|
809 | - |
|
810 | - // help text |
|
811 | - if(!empty($args['help_text'])){ |
|
812 | - $output .= AUI_Component_Helper::help_text($args['help_text']); |
|
813 | - } |
|
814 | - |
|
815 | - // maybe horizontal label |
|
816 | - if($args['label_type']=='horizontal'){ |
|
817 | - $output .= '</div>'; |
|
818 | - } |
|
819 | - |
|
820 | - |
|
821 | - // wrap |
|
822 | - if(!$args['no_wrap']){ |
|
823 | - $wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group'; |
|
824 | - $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
825 | - $output = self::wrap(array( |
|
826 | - 'content' => $output, |
|
827 | - 'class' => $wrap_class, |
|
828 | - 'element_require' => $args['element_require'], |
|
829 | - 'argument_id' => $args['id'] |
|
830 | - )); |
|
831 | - } |
|
832 | - |
|
833 | - |
|
834 | - return $output; |
|
835 | - } |
|
836 | - |
|
837 | - /** |
|
838 | - * Build the component. |
|
839 | - * |
|
840 | - * @param array $args |
|
841 | - * |
|
842 | - * @return string The rendered component. |
|
843 | - */ |
|
844 | - public static function radio($args = array()){ |
|
845 | - $defaults = array( |
|
846 | - 'class' => '', |
|
847 | - 'wrap_class' => '', |
|
848 | - 'id' => '', |
|
849 | - 'title' => '', |
|
850 | - 'horizontal' => false, // sets the lable horizontal |
|
851 | - 'value' => '', |
|
852 | - 'label' => '', |
|
853 | - 'label_class'=> '', |
|
854 | - 'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
855 | - 'inline' => true, |
|
856 | - 'required' => false, |
|
857 | - 'options' => array(), |
|
858 | - 'icon' => '', |
|
859 | - 'no_wrap' => false, |
|
860 | - 'element_require' => '', // [%element_id%] == "1" |
|
861 | - 'extra_attributes' => array() // an array of extra attributes |
|
862 | - ); |
|
863 | - |
|
864 | - /** |
|
865 | - * Parse incoming $args into an array and merge it with $defaults |
|
866 | - */ |
|
867 | - $args = wp_parse_args( $args, $defaults ); |
|
868 | - |
|
869 | - // for now lets use horizontal for floating |
|
870 | - if( $args['label_type'] == 'floating' ){$args['label_type'] = 'horizontal';} |
|
871 | - |
|
872 | - $label_args = array( |
|
873 | - 'title'=> $args['label'], |
|
874 | - 'class' => $args['label_class']." pt-0 ", |
|
875 | - 'label_type' => $args['label_type'] |
|
876 | - ); |
|
877 | - |
|
878 | - $output = ''; |
|
879 | - |
|
880 | - |
|
881 | - |
|
882 | - // label before |
|
883 | - if(!empty($args['label'])){ |
|
884 | - $output .= self::label( $label_args, 'radio' ); |
|
885 | - } |
|
886 | - |
|
887 | - // maybe horizontal label |
|
888 | - if($args['label_type']=='horizontal'){ |
|
889 | - $output .= '<div class="col-sm-10">'; |
|
890 | - } |
|
891 | - |
|
892 | - if(!empty($args['options'])){ |
|
893 | - $count = 0; |
|
894 | - foreach($args['options'] as $value => $label){ |
|
895 | - $option_args = $args; |
|
896 | - $option_args['value'] = $value; |
|
897 | - $option_args['label'] = $label; |
|
898 | - $option_args['checked'] = $value == $args['value'] ? true : false; |
|
899 | - $output .= self::radio_option($option_args,$count); |
|
900 | - $count++; |
|
901 | - } |
|
902 | - } |
|
903 | - |
|
904 | - // maybe horizontal label |
|
905 | - if($args['label_type']=='horizontal'){ |
|
906 | - $output .= '</div>'; |
|
907 | - } |
|
908 | - |
|
909 | - |
|
910 | - // wrap |
|
911 | - $wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group'; |
|
912 | - $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
913 | - $output = self::wrap(array( |
|
914 | - 'content' => $output, |
|
915 | - 'class' => $wrap_class, |
|
916 | - 'element_require' => $args['element_require'], |
|
917 | - 'argument_id' => $args['id'] |
|
918 | - )); |
|
919 | - |
|
920 | - |
|
921 | - return $output; |
|
922 | - } |
|
923 | - |
|
924 | - /** |
|
925 | - * Build the component. |
|
926 | - * |
|
927 | - * @param array $args |
|
928 | - * |
|
929 | - * @return string The rendered component. |
|
930 | - */ |
|
931 | - public static function radio_option($args = array(),$count = ''){ |
|
932 | - $defaults = array( |
|
933 | - 'class' => '', |
|
934 | - 'id' => '', |
|
935 | - 'title' => '', |
|
936 | - 'value' => '', |
|
937 | - 'required' => false, |
|
938 | - 'inline' => true, |
|
939 | - 'label' => '', |
|
940 | - 'options' => array(), |
|
941 | - 'icon' => '', |
|
942 | - 'no_wrap' => false, |
|
943 | - 'extra_attributes' => array() // an array of extra attributes |
|
944 | - ); |
|
945 | - |
|
946 | - /** |
|
947 | - * Parse incoming $args into an array and merge it with $defaults |
|
948 | - */ |
|
949 | - $args = wp_parse_args( $args, $defaults ); |
|
950 | - |
|
951 | - $output = ''; |
|
952 | - |
|
953 | - // open/type |
|
954 | - $output .= '<input type="radio"'; |
|
955 | - |
|
956 | - // class |
|
957 | - $output .= ' class="form-check-input" '; |
|
958 | - |
|
959 | - // name |
|
960 | - if(!empty($args['name'])){ |
|
961 | - $output .= AUI_Component_Helper::name($args['name']); |
|
962 | - } |
|
963 | - |
|
964 | - // id |
|
965 | - if(!empty($args['id'])){ |
|
966 | - $output .= AUI_Component_Helper::id($args['id'].$count); |
|
967 | - } |
|
968 | - |
|
969 | - // title |
|
970 | - if(!empty($args['title'])){ |
|
971 | - $output .= AUI_Component_Helper::title($args['title']); |
|
972 | - } |
|
973 | - |
|
974 | - // value |
|
975 | - if(isset($args['value'])){ |
|
976 | - $output .= ' value="'.sanitize_text_field($args['value']).'" '; |
|
977 | - } |
|
978 | - |
|
979 | - // checked, for radio and checkboxes |
|
980 | - if( $args['checked'] ){ |
|
981 | - $output .= ' checked '; |
|
982 | - } |
|
983 | - |
|
984 | - // data-attributes |
|
985 | - $output .= AUI_Component_Helper::data_attributes($args); |
|
986 | - |
|
987 | - // aria-attributes |
|
988 | - $output .= AUI_Component_Helper::aria_attributes($args); |
|
989 | - |
|
990 | - // extra attributes |
|
991 | - if(!empty($args['extra_attributes'])){ |
|
992 | - $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
993 | - } |
|
994 | - |
|
995 | - // required |
|
996 | - if(!empty($args['required'])){ |
|
997 | - $output .= ' required '; |
|
998 | - } |
|
999 | - |
|
1000 | - // close opening tag |
|
1001 | - $output .= ' >'; |
|
1002 | - |
|
1003 | - // label |
|
1004 | - if(!empty($args['label']) && is_array($args['label'])){ |
|
1005 | - }elseif(!empty($args['label'])){ |
|
1006 | - $output .= self::label(array('title'=>$args['label'],'for'=>$args['id'].$count,'class'=>'form-check-label'),'radio'); |
|
1007 | - } |
|
1008 | - |
|
1009 | - // wrap |
|
1010 | - if(!$args['no_wrap']){ |
|
1011 | - $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check'; |
|
1012 | - $output = self::wrap(array( |
|
1013 | - 'content' => $output, |
|
1014 | - 'class' => $wrap_class |
|
1015 | - )); |
|
1016 | - } |
|
1017 | - |
|
1018 | - |
|
1019 | - return $output; |
|
1020 | - } |
|
213 | + } |
|
214 | + |
|
215 | + // input group wraps |
|
216 | + if($args['input_group_left'] || $args['input_group_right']){ |
|
217 | + $w100 = strpos($args['class'], 'w-100') !== false ? ' w-100' : ''; |
|
218 | + if($args['input_group_left']){ |
|
219 | + $output = self::wrap( array( |
|
220 | + 'content' => $output, |
|
221 | + 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative'.$w100 : 'input-group', |
|
222 | + 'input_group_left' => $args['input_group_left'], |
|
223 | + 'input_group_left_inside' => $args['input_group_left_inside'] |
|
224 | + ) ); |
|
225 | + } |
|
226 | + if($args['input_group_right']){ |
|
227 | + $output = self::wrap( array( |
|
228 | + 'content' => $output, |
|
229 | + 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative'.$w100 : 'input-group', |
|
230 | + 'input_group_right' => $args['input_group_right'], |
|
231 | + 'input_group_right_inside' => $args['input_group_right_inside'] |
|
232 | + ) ); |
|
233 | + } |
|
234 | + |
|
235 | + } |
|
236 | + |
|
237 | + if(!$label_after){ |
|
238 | + $output .= $help_text; |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + if($args['label_type']=='horizontal' && $type != 'checkbox'){ |
|
243 | + $output = self::wrap( array( |
|
244 | + 'content' => $output, |
|
245 | + 'class' => 'col-sm-10', |
|
246 | + ) ); |
|
247 | + } |
|
248 | + |
|
249 | + if(!$label_after){ |
|
250 | + $output = $label . $output; |
|
251 | + } |
|
252 | + |
|
253 | + // wrap |
|
254 | + if(!$args['no_wrap']){ |
|
255 | + |
|
256 | + $form_group_class = $args['label_type']=='floating' && $type != 'checkbox' ? 'form-label-group' : 'form-group'; |
|
257 | + $wrap_class = $args['label_type']=='horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
258 | + $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
259 | + $output = self::wrap(array( |
|
260 | + 'content' => $output, |
|
261 | + 'class' => $wrap_class, |
|
262 | + 'element_require' => $args['element_require'], |
|
263 | + 'argument_id' => $args['id'] |
|
264 | + )); |
|
265 | + } |
|
266 | + |
|
267 | + |
|
268 | + |
|
269 | + } |
|
270 | + |
|
271 | + return $output; |
|
272 | + } |
|
273 | + |
|
274 | + /** |
|
275 | + * Build the component. |
|
276 | + * |
|
277 | + * @param array $args |
|
278 | + * |
|
279 | + * @return string The rendered component. |
|
280 | + */ |
|
281 | + public static function textarea($args = array()){ |
|
282 | + $defaults = array( |
|
283 | + 'name' => '', |
|
284 | + 'class' => '', |
|
285 | + 'wrap_class' => '', |
|
286 | + 'id' => '', |
|
287 | + 'placeholder'=> '', |
|
288 | + 'title' => '', |
|
289 | + 'value' => '', |
|
290 | + 'required' => false, |
|
291 | + 'label' => '', |
|
292 | + 'label_after'=> false, |
|
293 | + 'label_class' => '', |
|
294 | + 'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
295 | + 'help_text' => '', |
|
296 | + 'validation_text' => '', |
|
297 | + 'validation_pattern' => '', |
|
298 | + 'no_wrap' => false, |
|
299 | + 'rows' => '', |
|
300 | + 'wysiwyg' => false, |
|
301 | + 'element_require' => '', // [%element_id%] == "1" |
|
302 | + ); |
|
303 | + |
|
304 | + /** |
|
305 | + * Parse incoming $args into an array and merge it with $defaults |
|
306 | + */ |
|
307 | + $args = wp_parse_args( $args, $defaults ); |
|
308 | + $output = ''; |
|
309 | + |
|
310 | + // hidden label option needs to be empty |
|
311 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
312 | + |
|
313 | + // floating labels don't work with wysiwyg so set it as top |
|
314 | + if($args['label_type'] == 'floating' && !empty($args['wysiwyg'])){ |
|
315 | + $args['label_type'] = 'top'; |
|
316 | + } |
|
317 | + |
|
318 | + $label_after = $args['label_after']; |
|
319 | + |
|
320 | + // floating labels need label after |
|
321 | + if( $args['label_type'] == 'floating' && empty($args['wysiwyg']) ){ |
|
322 | + $label_after = true; |
|
323 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
324 | + } |
|
325 | + |
|
326 | + // label |
|
327 | + if(!empty($args['label']) && is_array($args['label'])){ |
|
328 | + }elseif(!empty($args['label']) && !$label_after){ |
|
329 | + $label_args = array( |
|
330 | + 'title'=> $args['label'], |
|
331 | + 'for'=> $args['id'], |
|
332 | + 'class' => $args['label_class']." ", |
|
333 | + 'label_type' => $args['label_type'] |
|
334 | + ); |
|
335 | + $output .= self::label( $label_args ); |
|
336 | + } |
|
337 | + |
|
338 | + // maybe horizontal label |
|
339 | + if($args['label_type']=='horizontal'){ |
|
340 | + $output .= '<div class="col-sm-10">'; |
|
341 | + } |
|
342 | + |
|
343 | + if(!empty($args['wysiwyg'])){ |
|
344 | + ob_start(); |
|
345 | + $content = $args['value']; |
|
346 | + $editor_id = !empty($args['id']) ? sanitize_html_class($args['id']) : 'wp_editor'; |
|
347 | + $settings = array( |
|
348 | + 'textarea_rows' => !empty(absint($args['rows'])) ? absint($args['rows']) : 4, |
|
349 | + 'quicktags' => false, |
|
350 | + 'media_buttons' => false, |
|
351 | + 'editor_class' => 'form-control', |
|
352 | + 'textarea_name' => !empty($args['name']) ? sanitize_html_class($args['name']) : sanitize_html_class($args['id']), |
|
353 | + 'teeny' => true, |
|
354 | + ); |
|
355 | + |
|
356 | + // maybe set settings if array |
|
357 | + if(is_array($args['wysiwyg'])){ |
|
358 | + $settings = wp_parse_args( $args['wysiwyg'], $settings ); |
|
359 | + } |
|
360 | + |
|
361 | + wp_editor( $content, $editor_id, $settings ); |
|
362 | + $output .= ob_get_clean(); |
|
363 | + }else{ |
|
364 | + |
|
365 | + // open |
|
366 | + $output .= '<textarea '; |
|
367 | + |
|
368 | + // name |
|
369 | + if(!empty($args['name'])){ |
|
370 | + $output .= ' name="'.sanitize_html_class($args['name']).'" '; |
|
371 | + } |
|
372 | + |
|
373 | + // id |
|
374 | + if(!empty($args['id'])){ |
|
375 | + $output .= ' id="'.sanitize_html_class($args['id']).'" '; |
|
376 | + } |
|
377 | + |
|
378 | + // placeholder |
|
379 | + if(isset($args['placeholder']) && '' != $args['placeholder']){ |
|
380 | + $output .= ' placeholder="'.esc_attr($args['placeholder']).'" '; |
|
381 | + } |
|
382 | + |
|
383 | + // title |
|
384 | + if(!empty($args['title'])){ |
|
385 | + $output .= ' title="'.esc_attr($args['title']).'" '; |
|
386 | + } |
|
387 | + |
|
388 | + // validation text |
|
389 | + if(!empty($args['validation_text'])){ |
|
390 | + $output .= ' oninvalid="setCustomValidity(\''.esc_attr($args['validation_text']).'\')" '; |
|
391 | + $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
392 | + } |
|
393 | + |
|
394 | + // validation_pattern |
|
395 | + if(!empty($args['validation_pattern'])){ |
|
396 | + $output .= ' pattern="'.$args['validation_pattern'].'" '; |
|
397 | + } |
|
398 | + |
|
399 | + // required |
|
400 | + if(!empty($args['required'])){ |
|
401 | + $output .= ' required '; |
|
402 | + } |
|
403 | + |
|
404 | + // rows |
|
405 | + if(!empty($args['rows'])){ |
|
406 | + $output .= ' rows="'.absint($args['rows']).'" '; |
|
407 | + } |
|
408 | + |
|
409 | + |
|
410 | + // class |
|
411 | + $class = !empty($args['class']) ? $args['class'] : ''; |
|
412 | + $output .= ' class="form-control '.$class.'" '; |
|
413 | + |
|
414 | + |
|
415 | + // close tag |
|
416 | + $output .= ' >'; |
|
417 | + |
|
418 | + // value |
|
419 | + if(!empty($args['value'])){ |
|
420 | + $output .= sanitize_textarea_field($args['value']); |
|
421 | + } |
|
422 | + |
|
423 | + // closing tag |
|
424 | + $output .= '</textarea>'; |
|
425 | + |
|
426 | + } |
|
427 | + |
|
428 | + if(!empty($args['label']) && $label_after){ |
|
429 | + $label_args = array( |
|
430 | + 'title'=> $args['label'], |
|
431 | + 'for'=> $args['id'], |
|
432 | + 'class' => $args['label_class']." ", |
|
433 | + 'label_type' => $args['label_type'] |
|
434 | + ); |
|
435 | + $output .= self::label( $label_args ); |
|
436 | + } |
|
437 | + |
|
438 | + // help text |
|
439 | + if(!empty($args['help_text'])){ |
|
440 | + $output .= AUI_Component_Helper::help_text($args['help_text']); |
|
441 | + } |
|
442 | + |
|
443 | + // maybe horizontal label |
|
444 | + if($args['label_type']=='horizontal'){ |
|
445 | + $output .= '</div>'; |
|
446 | + } |
|
447 | + |
|
448 | + |
|
449 | + // wrap |
|
450 | + if(!$args['no_wrap']){ |
|
451 | + $form_group_class = $args['label_type']=='floating' ? 'form-label-group' : 'form-group'; |
|
452 | + $wrap_class = $args['label_type']=='horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
453 | + $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
454 | + $output = self::wrap(array( |
|
455 | + 'content' => $output, |
|
456 | + 'class' => $wrap_class, |
|
457 | + 'element_require' => $args['element_require'], |
|
458 | + 'argument_id' => $args['id'] |
|
459 | + )); |
|
460 | + } |
|
461 | + |
|
462 | + |
|
463 | + return $output; |
|
464 | + } |
|
465 | + |
|
466 | + public static function label($args = array(), $type = ''){ |
|
467 | + //<label for="exampleInputEmail1">Email address</label> |
|
468 | + $defaults = array( |
|
469 | + 'title' => 'div', |
|
470 | + 'for' => '', |
|
471 | + 'class' => '', |
|
472 | + 'label_type' => '', // empty = hidden, top, horizontal |
|
473 | + ); |
|
474 | + |
|
475 | + /** |
|
476 | + * Parse incoming $args into an array and merge it with $defaults |
|
477 | + */ |
|
478 | + $args = wp_parse_args( $args, $defaults ); |
|
479 | + $output = ''; |
|
480 | + |
|
481 | + if($args['title']){ |
|
482 | + |
|
483 | + // maybe hide labels //@todo set a global option for visibility class |
|
484 | + if($type == 'file' || $type == 'checkbox' || $type == 'radio' || !empty($args['label_type']) ){ |
|
485 | + $class = $args['class']; |
|
486 | + }else{ |
|
487 | + $class = 'sr-only '.$args['class']; |
|
488 | + } |
|
489 | + |
|
490 | + // maybe horizontal |
|
491 | + if($args['label_type']=='horizontal' && $type != 'checkbox'){ |
|
492 | + $class .= ' col-sm-2 col-form-label'; |
|
493 | + } |
|
494 | + |
|
495 | + // open |
|
496 | + $output .= '<label '; |
|
497 | + |
|
498 | + // for |
|
499 | + if(!empty($args['for'])){ |
|
500 | + $output .= ' for="'.sanitize_text_field($args['for']).'" '; |
|
501 | + } |
|
502 | + |
|
503 | + // class |
|
504 | + $class = $class ? AUI_Component_Helper::esc_classes( $class ) : ''; |
|
505 | + $output .= ' class="'.$class.'" '; |
|
506 | + |
|
507 | + // close |
|
508 | + $output .= '>'; |
|
509 | + |
|
510 | + |
|
511 | + // title, don't escape fully as can contain html |
|
512 | + if(!empty($args['title'])){ |
|
513 | + $output .= wp_kses_post($args['title']); |
|
514 | + } |
|
515 | + |
|
516 | + // close wrap |
|
517 | + $output .= '</label>'; |
|
518 | + |
|
519 | + |
|
520 | + } |
|
521 | + |
|
522 | + |
|
523 | + return $output; |
|
524 | + } |
|
525 | + |
|
526 | + /** |
|
527 | + * Wrap some content in a HTML wrapper. |
|
528 | + * |
|
529 | + * @param array $args |
|
530 | + * |
|
531 | + * @return string |
|
532 | + */ |
|
533 | + public static function wrap($args = array()){ |
|
534 | + $defaults = array( |
|
535 | + 'type' => 'div', |
|
536 | + 'class' => 'form-group', |
|
537 | + 'content' => '', |
|
538 | + 'input_group_left' => '', |
|
539 | + 'input_group_right' => '', |
|
540 | + 'input_group_left_inside' => false, |
|
541 | + 'input_group_right_inside' => false, |
|
542 | + 'element_require' => '', |
|
543 | + 'argument_id' => '', |
|
544 | + ); |
|
545 | + |
|
546 | + /** |
|
547 | + * Parse incoming $args into an array and merge it with $defaults |
|
548 | + */ |
|
549 | + $args = wp_parse_args( $args, $defaults ); |
|
550 | + $output = ''; |
|
551 | + if($args['type']){ |
|
552 | + |
|
553 | + // open |
|
554 | + $output .= '<'.sanitize_html_class($args['type']); |
|
555 | + |
|
556 | + // element require |
|
557 | + if(!empty($args['element_require'])){ |
|
558 | + $output .= AUI_Component_Helper::element_require($args['element_require']); |
|
559 | + $args['class'] .= " aui-conditional-field"; |
|
560 | + } |
|
561 | + |
|
562 | + // argument_id |
|
563 | + if( !empty($args['argument_id']) ){ |
|
564 | + $output .= ' data-argument="'.esc_attr($args['argument_id']).'"'; |
|
565 | + } |
|
566 | + |
|
567 | + // class |
|
568 | + $class = !empty($args['class']) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
569 | + $output .= ' class="'.$class.'" '; |
|
570 | + |
|
571 | + // close wrap |
|
572 | + $output .= ' >'; |
|
573 | + |
|
574 | + |
|
575 | + // Input group left |
|
576 | + if(!empty($args['input_group_left'])){ |
|
577 | + $position_class = !empty($args['input_group_left_inside']) ? 'position-absolute h-100' : ''; |
|
578 | + $input_group_left = strpos($args['input_group_left'], '<') !== false ? $args['input_group_left'] : '<span class="input-group-text">'.$args['input_group_left'].'</span>'; |
|
579 | + $output .= '<div class="input-group-prepend '.$position_class.'">'.$input_group_left.'</div>'; |
|
580 | + } |
|
581 | + |
|
582 | + // content |
|
583 | + $output .= $args['content']; |
|
584 | + |
|
585 | + // Input group right |
|
586 | + if(!empty($args['input_group_right'])){ |
|
587 | + $position_class = !empty($args['input_group_left_inside']) ? 'position-absolute h-100' : ''; |
|
588 | + $input_group_right = strpos($args['input_group_right'], '<') !== false ? $args['input_group_right'] : '<span class="input-group-text">'.$args['input_group_right'].'</span>'; |
|
589 | + $output .= '<div class="input-group-append '.$position_class.'">'.$input_group_right.'</div>'; |
|
590 | + } |
|
591 | + |
|
592 | + |
|
593 | + // close wrap |
|
594 | + $output .= '</'.sanitize_html_class($args['type']).'>'; |
|
595 | + |
|
596 | + |
|
597 | + }else{ |
|
598 | + $output = $args['content']; |
|
599 | + } |
|
600 | + |
|
601 | + return $output; |
|
602 | + } |
|
603 | + |
|
604 | + /** |
|
605 | + * Build the component. |
|
606 | + * |
|
607 | + * @param array $args |
|
608 | + * |
|
609 | + * @return string The rendered component. |
|
610 | + */ |
|
611 | + public static function select($args = array()){ |
|
612 | + $defaults = array( |
|
613 | + 'class' => '', |
|
614 | + 'wrap_class' => '', |
|
615 | + 'id' => '', |
|
616 | + 'title' => '', |
|
617 | + 'value' => '', // can be an array or a string |
|
618 | + 'required' => false, |
|
619 | + 'label' => '', |
|
620 | + 'label_after'=> false, |
|
621 | + 'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
622 | + 'label_class' => '', |
|
623 | + 'help_text' => '', |
|
624 | + 'placeholder'=> '', |
|
625 | + 'options' => array(), // array or string |
|
626 | + 'icon' => '', |
|
627 | + 'multiple' => false, |
|
628 | + 'select2' => false, |
|
629 | + 'no_wrap' => false, |
|
630 | + 'element_require' => '', // [%element_id%] == "1" |
|
631 | + 'extra_attributes' => array(), // an array of extra attributes |
|
632 | + ); |
|
633 | + |
|
634 | + /** |
|
635 | + * Parse incoming $args into an array and merge it with $defaults |
|
636 | + */ |
|
637 | + $args = wp_parse_args( $args, $defaults ); |
|
638 | + $output = ''; |
|
639 | + |
|
640 | + // for now lets hide floating labels |
|
641 | + if( $args['label_type'] == 'floating' ){$args['label_type'] = 'hidden';} |
|
642 | + |
|
643 | + // hidden label option needs to be empty |
|
644 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
645 | + |
|
646 | + |
|
647 | + $label_after = $args['label_after']; |
|
648 | + |
|
649 | + // floating labels need label after |
|
650 | + if( $args['label_type'] == 'floating' ){ |
|
651 | + $label_after = true; |
|
652 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
653 | + } |
|
654 | + |
|
655 | + // Maybe setup select2 |
|
656 | + $is_select2 = false; |
|
657 | + if(!empty($args['select2'])){ |
|
658 | + $args['class'] .= ' aui-select2'; |
|
659 | + $is_select2 = true; |
|
660 | + }elseif( strpos($args['class'], 'aui-select2') !== false){ |
|
661 | + $is_select2 = true; |
|
662 | + } |
|
663 | + |
|
664 | + // select2 tags |
|
665 | + if( !empty($args['select2']) && $args['select2'] === 'tags'){ // triple equals needed here for some reason |
|
666 | + $args['data-tags'] = 'true'; |
|
667 | + $args['data-token-separators'] = "[',']"; |
|
668 | + $args['multiple'] = true; |
|
669 | + } |
|
670 | + |
|
671 | + // select2 placeholder |
|
672 | + if($is_select2 && isset($args['placeholder']) && '' != $args['placeholder'] && empty($args['data-placeholder'])){ |
|
673 | + $args['data-placeholder'] = esc_attr($args['placeholder']); |
|
674 | + $args['data-allow-clear'] = isset($args['data-allow-clear']) ? (bool) $args['data-allow-clear'] : true; |
|
675 | + } |
|
676 | + |
|
677 | + // label |
|
678 | + if(!empty($args['label']) && is_array($args['label'])){ |
|
679 | + }elseif(!empty($args['label']) && !$label_after){ |
|
680 | + $label_args = array( |
|
681 | + 'title'=> $args['label'], |
|
682 | + 'for'=> $args['id'], |
|
683 | + 'class' => $args['label_class']." ", |
|
684 | + 'label_type' => $args['label_type'] |
|
685 | + ); |
|
686 | + $output .= self::label($label_args); |
|
687 | + } |
|
688 | + |
|
689 | + // maybe horizontal label |
|
690 | + if($args['label_type']=='horizontal'){ |
|
691 | + $output .= '<div class="col-sm-10">'; |
|
692 | + } |
|
693 | + |
|
694 | + // open/type |
|
695 | + $output .= '<select '; |
|
696 | + |
|
697 | + // style |
|
698 | + if($is_select2){ |
|
699 | + $output .= " style='width:100%;' "; |
|
700 | + } |
|
701 | + |
|
702 | + // element require |
|
703 | + if(!empty($args['element_require'])){ |
|
704 | + $output .= AUI_Component_Helper::element_require($args['element_require']); |
|
705 | + $args['class'] .= " aui-conditional-field"; |
|
706 | + } |
|
707 | + |
|
708 | + // class |
|
709 | + $class = !empty($args['class']) ? $args['class'] : ''; |
|
710 | + $output .= AUI_Component_Helper::class_attr('custom-select '.$class); |
|
711 | + |
|
712 | + // name |
|
713 | + if(!empty($args['name'])){ |
|
714 | + $output .= AUI_Component_Helper::name($args['name'],$args['multiple']); |
|
715 | + } |
|
716 | + |
|
717 | + // id |
|
718 | + if(!empty($args['id'])){ |
|
719 | + $output .= AUI_Component_Helper::id($args['id']); |
|
720 | + } |
|
721 | + |
|
722 | + // title |
|
723 | + if(!empty($args['title'])){ |
|
724 | + $output .= AUI_Component_Helper::title($args['title']); |
|
725 | + } |
|
726 | + |
|
727 | + // data-attributes |
|
728 | + $output .= AUI_Component_Helper::data_attributes($args); |
|
729 | + |
|
730 | + // aria-attributes |
|
731 | + $output .= AUI_Component_Helper::aria_attributes($args); |
|
732 | + |
|
733 | + // extra attributes |
|
734 | + if(!empty($args['extra_attributes'])){ |
|
735 | + $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
736 | + } |
|
737 | + |
|
738 | + // required |
|
739 | + if(!empty($args['required'])){ |
|
740 | + $output .= ' required '; |
|
741 | + } |
|
742 | + |
|
743 | + // multiple |
|
744 | + if(!empty($args['multiple'])){ |
|
745 | + $output .= ' multiple '; |
|
746 | + } |
|
747 | + |
|
748 | + // close opening tag |
|
749 | + $output .= ' >'; |
|
750 | + |
|
751 | + // placeholder |
|
752 | + if(isset($args['placeholder']) && '' != $args['placeholder'] && !$is_select2){ |
|
753 | + $output .= '<option value="" disabled selected hidden>'.esc_attr($args['placeholder']).'</option>'; |
|
754 | + }elseif($is_select2 && !empty($args['placeholder'])){ |
|
755 | + $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder |
|
756 | + } |
|
757 | + |
|
758 | + // Options |
|
759 | + if(!empty($args['options'])){ |
|
760 | + |
|
761 | + if(!is_array($args['options'])){ |
|
762 | + $output .= $args['options']; // not the preferred way but an option |
|
763 | + }else{ |
|
764 | + foreach($args['options'] as $val => $name){ |
|
765 | + $selected = ''; |
|
766 | + if(is_array($name)){ |
|
767 | + if (isset($name['optgroup']) && ($name['optgroup'] == 'start' || $name['optgroup'] == 'end')) { |
|
768 | + $option_label = isset($name['label']) ? $name['label'] : ''; |
|
769 | + |
|
770 | + $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr($option_label) . '">' : '</optgroup>'; |
|
771 | + } else { |
|
772 | + $option_label = isset($name['label']) ? $name['label'] : ''; |
|
773 | + $option_value = isset($name['value']) ? $name['value'] : ''; |
|
774 | + if(!empty($args['multiple']) && !empty($args['value']) && is_array($args['value']) ){ |
|
775 | + $selected = in_array($option_value, stripslashes_deep($args['value'])) ? "selected" : ""; |
|
776 | + } elseif(!empty($args['value'])) { |
|
777 | + $selected = selected($option_value,stripslashes_deep($args['value']), false); |
|
778 | + } |
|
779 | + |
|
780 | + $output .= '<option value="' . esc_attr($option_value) . '" ' . $selected . '>' . $option_label . '</option>'; |
|
781 | + } |
|
782 | + }else{ |
|
783 | + if(!empty($args['value'])){ |
|
784 | + if(is_array($args['value'])){ |
|
785 | + $selected = in_array($val,$args['value']) ? 'selected="selected"' : ''; |
|
786 | + } elseif(!empty($args['value'])) { |
|
787 | + $selected = selected( $args['value'], $val, false); |
|
788 | + } |
|
789 | + } |
|
790 | + $output .= '<option value="'.esc_attr($val).'" '.$selected.'>'.esc_attr($name).'</option>'; |
|
791 | + } |
|
792 | + } |
|
793 | + } |
|
794 | + |
|
795 | + } |
|
796 | + |
|
797 | + // closing tag |
|
798 | + $output .= '</select>'; |
|
799 | + |
|
800 | + if(!empty($args['label']) && $label_after){ |
|
801 | + $label_args = array( |
|
802 | + 'title'=> $args['label'], |
|
803 | + 'for'=> $args['id'], |
|
804 | + 'class' => $args['label_class']." ", |
|
805 | + 'label_type' => $args['label_type'] |
|
806 | + ); |
|
807 | + $output .= self::label($label_args); |
|
808 | + } |
|
809 | + |
|
810 | + // help text |
|
811 | + if(!empty($args['help_text'])){ |
|
812 | + $output .= AUI_Component_Helper::help_text($args['help_text']); |
|
813 | + } |
|
814 | + |
|
815 | + // maybe horizontal label |
|
816 | + if($args['label_type']=='horizontal'){ |
|
817 | + $output .= '</div>'; |
|
818 | + } |
|
819 | + |
|
820 | + |
|
821 | + // wrap |
|
822 | + if(!$args['no_wrap']){ |
|
823 | + $wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group'; |
|
824 | + $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
825 | + $output = self::wrap(array( |
|
826 | + 'content' => $output, |
|
827 | + 'class' => $wrap_class, |
|
828 | + 'element_require' => $args['element_require'], |
|
829 | + 'argument_id' => $args['id'] |
|
830 | + )); |
|
831 | + } |
|
832 | + |
|
833 | + |
|
834 | + return $output; |
|
835 | + } |
|
836 | + |
|
837 | + /** |
|
838 | + * Build the component. |
|
839 | + * |
|
840 | + * @param array $args |
|
841 | + * |
|
842 | + * @return string The rendered component. |
|
843 | + */ |
|
844 | + public static function radio($args = array()){ |
|
845 | + $defaults = array( |
|
846 | + 'class' => '', |
|
847 | + 'wrap_class' => '', |
|
848 | + 'id' => '', |
|
849 | + 'title' => '', |
|
850 | + 'horizontal' => false, // sets the lable horizontal |
|
851 | + 'value' => '', |
|
852 | + 'label' => '', |
|
853 | + 'label_class'=> '', |
|
854 | + 'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
855 | + 'inline' => true, |
|
856 | + 'required' => false, |
|
857 | + 'options' => array(), |
|
858 | + 'icon' => '', |
|
859 | + 'no_wrap' => false, |
|
860 | + 'element_require' => '', // [%element_id%] == "1" |
|
861 | + 'extra_attributes' => array() // an array of extra attributes |
|
862 | + ); |
|
863 | + |
|
864 | + /** |
|
865 | + * Parse incoming $args into an array and merge it with $defaults |
|
866 | + */ |
|
867 | + $args = wp_parse_args( $args, $defaults ); |
|
868 | + |
|
869 | + // for now lets use horizontal for floating |
|
870 | + if( $args['label_type'] == 'floating' ){$args['label_type'] = 'horizontal';} |
|
871 | + |
|
872 | + $label_args = array( |
|
873 | + 'title'=> $args['label'], |
|
874 | + 'class' => $args['label_class']." pt-0 ", |
|
875 | + 'label_type' => $args['label_type'] |
|
876 | + ); |
|
877 | + |
|
878 | + $output = ''; |
|
879 | + |
|
880 | + |
|
881 | + |
|
882 | + // label before |
|
883 | + if(!empty($args['label'])){ |
|
884 | + $output .= self::label( $label_args, 'radio' ); |
|
885 | + } |
|
886 | + |
|
887 | + // maybe horizontal label |
|
888 | + if($args['label_type']=='horizontal'){ |
|
889 | + $output .= '<div class="col-sm-10">'; |
|
890 | + } |
|
891 | + |
|
892 | + if(!empty($args['options'])){ |
|
893 | + $count = 0; |
|
894 | + foreach($args['options'] as $value => $label){ |
|
895 | + $option_args = $args; |
|
896 | + $option_args['value'] = $value; |
|
897 | + $option_args['label'] = $label; |
|
898 | + $option_args['checked'] = $value == $args['value'] ? true : false; |
|
899 | + $output .= self::radio_option($option_args,$count); |
|
900 | + $count++; |
|
901 | + } |
|
902 | + } |
|
903 | + |
|
904 | + // maybe horizontal label |
|
905 | + if($args['label_type']=='horizontal'){ |
|
906 | + $output .= '</div>'; |
|
907 | + } |
|
908 | + |
|
909 | + |
|
910 | + // wrap |
|
911 | + $wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group'; |
|
912 | + $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
913 | + $output = self::wrap(array( |
|
914 | + 'content' => $output, |
|
915 | + 'class' => $wrap_class, |
|
916 | + 'element_require' => $args['element_require'], |
|
917 | + 'argument_id' => $args['id'] |
|
918 | + )); |
|
919 | + |
|
920 | + |
|
921 | + return $output; |
|
922 | + } |
|
923 | + |
|
924 | + /** |
|
925 | + * Build the component. |
|
926 | + * |
|
927 | + * @param array $args |
|
928 | + * |
|
929 | + * @return string The rendered component. |
|
930 | + */ |
|
931 | + public static function radio_option($args = array(),$count = ''){ |
|
932 | + $defaults = array( |
|
933 | + 'class' => '', |
|
934 | + 'id' => '', |
|
935 | + 'title' => '', |
|
936 | + 'value' => '', |
|
937 | + 'required' => false, |
|
938 | + 'inline' => true, |
|
939 | + 'label' => '', |
|
940 | + 'options' => array(), |
|
941 | + 'icon' => '', |
|
942 | + 'no_wrap' => false, |
|
943 | + 'extra_attributes' => array() // an array of extra attributes |
|
944 | + ); |
|
945 | + |
|
946 | + /** |
|
947 | + * Parse incoming $args into an array and merge it with $defaults |
|
948 | + */ |
|
949 | + $args = wp_parse_args( $args, $defaults ); |
|
950 | + |
|
951 | + $output = ''; |
|
952 | + |
|
953 | + // open/type |
|
954 | + $output .= '<input type="radio"'; |
|
955 | + |
|
956 | + // class |
|
957 | + $output .= ' class="form-check-input" '; |
|
958 | + |
|
959 | + // name |
|
960 | + if(!empty($args['name'])){ |
|
961 | + $output .= AUI_Component_Helper::name($args['name']); |
|
962 | + } |
|
963 | + |
|
964 | + // id |
|
965 | + if(!empty($args['id'])){ |
|
966 | + $output .= AUI_Component_Helper::id($args['id'].$count); |
|
967 | + } |
|
968 | + |
|
969 | + // title |
|
970 | + if(!empty($args['title'])){ |
|
971 | + $output .= AUI_Component_Helper::title($args['title']); |
|
972 | + } |
|
973 | + |
|
974 | + // value |
|
975 | + if(isset($args['value'])){ |
|
976 | + $output .= ' value="'.sanitize_text_field($args['value']).'" '; |
|
977 | + } |
|
978 | + |
|
979 | + // checked, for radio and checkboxes |
|
980 | + if( $args['checked'] ){ |
|
981 | + $output .= ' checked '; |
|
982 | + } |
|
983 | + |
|
984 | + // data-attributes |
|
985 | + $output .= AUI_Component_Helper::data_attributes($args); |
|
986 | + |
|
987 | + // aria-attributes |
|
988 | + $output .= AUI_Component_Helper::aria_attributes($args); |
|
989 | + |
|
990 | + // extra attributes |
|
991 | + if(!empty($args['extra_attributes'])){ |
|
992 | + $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
993 | + } |
|
994 | + |
|
995 | + // required |
|
996 | + if(!empty($args['required'])){ |
|
997 | + $output .= ' required '; |
|
998 | + } |
|
999 | + |
|
1000 | + // close opening tag |
|
1001 | + $output .= ' >'; |
|
1002 | + |
|
1003 | + // label |
|
1004 | + if(!empty($args['label']) && is_array($args['label'])){ |
|
1005 | + }elseif(!empty($args['label'])){ |
|
1006 | + $output .= self::label(array('title'=>$args['label'],'for'=>$args['id'].$count,'class'=>'form-check-label'),'radio'); |
|
1007 | + } |
|
1008 | + |
|
1009 | + // wrap |
|
1010 | + if(!$args['no_wrap']){ |
|
1011 | + $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check'; |
|
1012 | + $output = self::wrap(array( |
|
1013 | + 'content' => $output, |
|
1014 | + 'class' => $wrap_class |
|
1015 | + )); |
|
1016 | + } |
|
1017 | + |
|
1018 | + |
|
1019 | + return $output; |
|
1020 | + } |
|
1021 | 1021 | |
1022 | 1022 | } |
1023 | 1023 | \ No newline at end of file |