@@ -14,93 +14,93 @@ discard block |
||
14 | 14 | class GetPaid_Admin { |
15 | 15 | |
16 | 16 | /** |
17 | - * Local path to this plugins admin directory |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - public $admin_path; |
|
22 | - |
|
23 | - /** |
|
24 | - * Web path to this plugins admin directory |
|
25 | - * |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - public $admin_url; |
|
29 | - |
|
30 | - /** |
|
31 | - * Reports components. |
|
32 | - * |
|
33 | - * @var GetPaid_Reports |
|
34 | - */ |
|
17 | + * Local path to this plugins admin directory |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + public $admin_path; |
|
22 | + |
|
23 | + /** |
|
24 | + * Web path to this plugins admin directory |
|
25 | + * |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + public $admin_url; |
|
29 | + |
|
30 | + /** |
|
31 | + * Reports components. |
|
32 | + * |
|
33 | + * @var GetPaid_Reports |
|
34 | + */ |
|
35 | 35 | public $reports; |
36 | 36 | |
37 | 37 | /** |
38 | - * Class constructor. |
|
39 | - */ |
|
40 | - public function __construct() { |
|
38 | + * Class constructor. |
|
39 | + */ |
|
40 | + public function __construct() { |
|
41 | 41 | |
42 | 42 | $this->admin_path = plugin_dir_path( __FILE__ ); |
43 | - $this->admin_url = plugins_url( '/', __FILE__ ); |
|
44 | - $this->reports = new GetPaid_Reports(); |
|
43 | + $this->admin_url = plugins_url( '/', __FILE__ ); |
|
44 | + $this->reports = new GetPaid_Reports(); |
|
45 | 45 | |
46 | 46 | if ( is_admin() ) { |
47 | - $this->init_admin_hooks(); |
|
47 | + $this->init_admin_hooks(); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
53 | - * Init action and filter hooks |
|
54 | - * |
|
55 | - */ |
|
56 | - private function init_admin_hooks() { |
|
53 | + * Init action and filter hooks |
|
54 | + * |
|
55 | + */ |
|
56 | + private function init_admin_hooks() { |
|
57 | 57 | add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ), 9 ); |
58 | 58 | add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
59 | 59 | add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) ); |
60 | 60 | add_action( 'admin_init', array( $this, 'activation_redirect' ) ); |
61 | 61 | add_action( 'admin_init', array( $this, 'maybe_do_admin_action' ) ); |
62 | - add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
63 | - add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) ); |
|
64 | - add_action( 'getpaid_authenticated_admin_action_duplicate_form', array( $this, 'duplicate_payment_form' ) ); |
|
65 | - add_action( 'getpaid_authenticated_admin_action_reset_form_stats', array( $this, 'reset_form_stats' ) ); |
|
66 | - add_action( 'getpaid_authenticated_admin_action_duplicate_invoice', array( $this, 'duplicate_invoice' ) ); |
|
67 | - add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
68 | - add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
62 | + add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
63 | + add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) ); |
|
64 | + add_action( 'getpaid_authenticated_admin_action_duplicate_form', array( $this, 'duplicate_payment_form' ) ); |
|
65 | + add_action( 'getpaid_authenticated_admin_action_reset_form_stats', array( $this, 'reset_form_stats' ) ); |
|
66 | + add_action( 'getpaid_authenticated_admin_action_duplicate_invoice', array( $this, 'duplicate_invoice' ) ); |
|
67 | + add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
68 | + add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
69 | 69 | add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) ); |
70 | - add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
71 | - add_action( 'getpaid_authenticated_admin_action_refresh_permalinks', array( $this, 'admin_refresh_permalinks' ) ); |
|
72 | - add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
73 | - add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
74 | - add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) ); |
|
75 | - add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) ); |
|
76 | - add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) ); |
|
77 | - add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) ); |
|
78 | - add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
79 | - do_action( 'getpaid_init_admin_hooks', $this ); |
|
80 | - |
|
81 | - // Setup/welcome |
|
82 | - if ( ! empty( $_GET['page'] ) ) { |
|
83 | - switch ( sanitize_text_field( $_GET['page'] ) ) { |
|
84 | - case 'gp-setup': |
|
85 | - include_once dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php'; |
|
86 | - break; |
|
87 | - } |
|
88 | - } |
|
89 | - |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Register admin scripts |
|
94 | - * |
|
95 | - */ |
|
96 | - public function enqeue_scripts() { |
|
70 | + add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
71 | + add_action( 'getpaid_authenticated_admin_action_refresh_permalinks', array( $this, 'admin_refresh_permalinks' ) ); |
|
72 | + add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
73 | + add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
74 | + add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) ); |
|
75 | + add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) ); |
|
76 | + add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) ); |
|
77 | + add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) ); |
|
78 | + add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
79 | + do_action( 'getpaid_init_admin_hooks', $this ); |
|
80 | + |
|
81 | + // Setup/welcome |
|
82 | + if ( ! empty( $_GET['page'] ) ) { |
|
83 | + switch ( sanitize_text_field( $_GET['page'] ) ) { |
|
84 | + case 'gp-setup': |
|
85 | + include_once dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php'; |
|
86 | + break; |
|
87 | + } |
|
88 | + } |
|
89 | + |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Register admin scripts |
|
94 | + * |
|
95 | + */ |
|
96 | + public function enqeue_scripts() { |
|
97 | 97 | global $current_screen, $pagenow; |
98 | 98 | |
99 | - $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
100 | - $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
99 | + $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
100 | + $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
101 | 101 | |
102 | 102 | if ( ! empty( $current_screen->post_type ) ) { |
103 | - $page = $current_screen->post_type; |
|
103 | + $page = $current_screen->post_type; |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | // General styles. |
@@ -121,53 +121,53 @@ discard block |
||
121 | 121 | } |
122 | 122 | |
123 | 123 | // Payment form scripts. |
124 | - if ( 'wpi_payment_form' == $page && $editing ) { |
|
124 | + if ( 'wpi_payment_form' == $page && $editing ) { |
|
125 | 125 | $this->load_payment_form_scripts(); |
126 | 126 | } |
127 | 127 | |
128 | - if ( $page == 'wpinv-subscriptions' ) { |
|
129 | - wp_enqueue_script( 'postbox' ); |
|
130 | - } |
|
128 | + if ( $page == 'wpinv-subscriptions' ) { |
|
129 | + wp_enqueue_script( 'postbox' ); |
|
130 | + } |
|
131 | 131 | |
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
135 | - * Returns admin js translations. |
|
136 | - * |
|
137 | - */ |
|
138 | - protected function get_admin_i18() { |
|
135 | + * Returns admin js translations. |
|
136 | + * |
|
137 | + */ |
|
138 | + protected function get_admin_i18() { |
|
139 | 139 | global $post; |
140 | 140 | |
141 | - $date_range = array( |
|
142 | - 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days', |
|
143 | - ); |
|
141 | + $date_range = array( |
|
142 | + 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days', |
|
143 | + ); |
|
144 | 144 | |
145 | - if ( $date_range['period'] == 'custom' ) { |
|
145 | + if ( $date_range['period'] == 'custom' ) { |
|
146 | 146 | |
147 | - if ( isset( $_GET['from'] ) ) { |
|
148 | - $date_range['after'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
149 | - } |
|
147 | + if ( isset( $_GET['from'] ) ) { |
|
148 | + $date_range['after'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
149 | + } |
|
150 | 150 | |
151 | - if ( isset( $_GET['to'] ) ) { |
|
152 | - $date_range['before'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
153 | - } |
|
151 | + if ( isset( $_GET['to'] ) ) { |
|
152 | + $date_range['before'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
153 | + } |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | $i18n = array( |
157 | 157 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
158 | 158 | 'post_ID' => isset( $post->ID ) ? $post->ID : '', |
159 | - 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
160 | - 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
161 | - 'rest_root' => esc_url_raw( rest_url() ), |
|
162 | - 'date_range' => $date_range, |
|
159 | + 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
160 | + 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
161 | + 'rest_root' => esc_url_raw( rest_url() ), |
|
162 | + 'date_range' => $date_range, |
|
163 | 163 | 'add_invoice_note_nonce' => wp_create_nonce( 'add-invoice-note' ), |
164 | 164 | 'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ), |
165 | 165 | 'invoice_item_nonce' => wp_create_nonce( 'invoice-item' ), |
166 | 166 | 'billing_details_nonce' => wp_create_nonce( 'get-billing-details' ), |
167 | 167 | 'tax' => wpinv_tax_amount(), |
168 | 168 | 'discount' => 0, |
169 | - 'currency_symbol' => wpinv_currency_symbol(), |
|
170 | - 'currency' => wpinv_get_currency(), |
|
169 | + 'currency_symbol' => wpinv_currency_symbol(), |
|
170 | + 'currency' => wpinv_get_currency(), |
|
171 | 171 | 'currency_pos' => wpinv_currency_position(), |
172 | 172 | 'thousand_sep' => wpinv_thousands_separator(), |
173 | 173 | 'decimal_sep' => wpinv_decimal_separator(), |
@@ -187,118 +187,118 @@ discard block |
||
187 | 187 | 'item_description' => __( 'Item Description', 'invoicing' ), |
188 | 188 | 'invoice_description' => __( 'Invoice Description', 'invoicing' ), |
189 | 189 | 'discount_description' => __( 'Discount Description', 'invoicing' ), |
190 | - 'searching' => __( 'Searching', 'invoicing' ), |
|
191 | - 'loading' => __( 'Loading...', 'invoicing' ), |
|
192 | - 'search_customers' => __( 'Enter customer name or email', 'invoicing' ), |
|
193 | - 'search_items' => __( 'Enter item name', 'invoicing' ), |
|
194 | - 'graphs' => array_merge( array( 'refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax' ), array_keys( wpinv_get_report_graphs() ) ), |
|
190 | + 'searching' => __( 'Searching', 'invoicing' ), |
|
191 | + 'loading' => __( 'Loading...', 'invoicing' ), |
|
192 | + 'search_customers' => __( 'Enter customer name or email', 'invoicing' ), |
|
193 | + 'search_items' => __( 'Enter item name', 'invoicing' ), |
|
194 | + 'graphs' => array_merge( array( 'refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax' ), array_keys( wpinv_get_report_graphs() ) ), |
|
195 | 195 | ); |
196 | 196 | |
197 | - if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
197 | + if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
198 | 198 | |
199 | - $invoice = new WPInv_Invoice( $post ); |
|
200 | - $i18n['save_invoice'] = sprintf( |
|
201 | - __( 'Save %s', 'invoicing' ), |
|
202 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
203 | - ); |
|
199 | + $invoice = new WPInv_Invoice( $post ); |
|
200 | + $i18n['save_invoice'] = sprintf( |
|
201 | + __( 'Save %s', 'invoicing' ), |
|
202 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
203 | + ); |
|
204 | 204 | |
205 | - $i18n['invoice_description'] = sprintf( |
|
206 | - __( '%s Description', 'invoicing' ), |
|
207 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
208 | - ); |
|
205 | + $i18n['invoice_description'] = sprintf( |
|
206 | + __( '%s Description', 'invoicing' ), |
|
207 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
208 | + ); |
|
209 | 209 | |
210 | - } |
|
211 | - return $i18n; |
|
212 | - } |
|
210 | + } |
|
211 | + return $i18n; |
|
212 | + } |
|
213 | 213 | |
214 | - /** |
|
215 | - * Change the admin footer text on GetPaid admin pages. |
|
216 | - * |
|
217 | - * @since 2.0.0 |
|
218 | - * @param string $footer_text |
|
219 | - * @return string |
|
220 | - */ |
|
221 | - public function admin_footer_text( $footer_text ) { |
|
222 | - global $current_screen; |
|
214 | + /** |
|
215 | + * Change the admin footer text on GetPaid admin pages. |
|
216 | + * |
|
217 | + * @since 2.0.0 |
|
218 | + * @param string $footer_text |
|
219 | + * @return string |
|
220 | + */ |
|
221 | + public function admin_footer_text( $footer_text ) { |
|
222 | + global $current_screen; |
|
223 | 223 | |
224 | - $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
224 | + $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
225 | 225 | |
226 | 226 | if ( ! empty( $current_screen->post_type ) ) { |
227 | - $page = $current_screen->post_type; |
|
227 | + $page = $current_screen->post_type; |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | // General styles. |
231 | 231 | if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) { |
232 | 232 | |
233 | - // Change the footer text |
|
234 | - if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
233 | + // Change the footer text |
|
234 | + if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
235 | 235 | |
236 | - $rating_url = esc_url( |
|
237 | - wp_nonce_url( |
|
238 | - admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
239 | - 'getpaid-nonce', |
|
240 | - 'getpaid-nonce' |
|
236 | + $rating_url = esc_url( |
|
237 | + wp_nonce_url( |
|
238 | + admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
239 | + 'getpaid-nonce', |
|
240 | + 'getpaid-nonce' |
|
241 | 241 | ) |
242 | - ); |
|
242 | + ); |
|
243 | 243 | |
244 | - $footer_text = sprintf( |
|
245 | - /* translators: %s: five stars */ |
|
246 | - __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
247 | - "<a href='$rating_url'>★★★★★</a>" |
|
248 | - ); |
|
244 | + $footer_text = sprintf( |
|
245 | + /* translators: %s: five stars */ |
|
246 | + __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
247 | + "<a href='$rating_url'>★★★★★</a>" |
|
248 | + ); |
|
249 | 249 | |
250 | - } else { |
|
250 | + } else { |
|
251 | 251 | |
252 | - $footer_text = sprintf( |
|
253 | - /* translators: %s: GetPaid */ |
|
254 | - __( 'Thank you for using %s!', 'invoicing' ), |
|
255 | - "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
|
256 | - ); |
|
252 | + $footer_text = sprintf( |
|
253 | + /* translators: %s: GetPaid */ |
|
254 | + __( 'Thank you for using %s!', 'invoicing' ), |
|
255 | + "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
|
256 | + ); |
|
257 | 257 | |
258 | - } |
|
258 | + } |
|
259 | 259 | } |
260 | 260 | |
261 | - return $footer_text; |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * Redirects to wp.org to rate the plugin. |
|
266 | - * |
|
267 | - * @since 2.0.0 |
|
268 | - */ |
|
269 | - public function redirect_to_wordpress_rating_page() { |
|
270 | - update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
271 | - wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
272 | - exit; |
|
273 | - } |
|
274 | - |
|
275 | - /** |
|
276 | - * Loads payment form js. |
|
277 | - * |
|
278 | - */ |
|
279 | - protected function load_payment_form_scripts() { |
|
261 | + return $footer_text; |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * Redirects to wp.org to rate the plugin. |
|
266 | + * |
|
267 | + * @since 2.0.0 |
|
268 | + */ |
|
269 | + public function redirect_to_wordpress_rating_page() { |
|
270 | + update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
271 | + wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
272 | + exit; |
|
273 | + } |
|
274 | + |
|
275 | + /** |
|
276 | + * Loads payment form js. |
|
277 | + * |
|
278 | + */ |
|
279 | + protected function load_payment_form_scripts() { |
|
280 | 280 | global $post; |
281 | 281 | |
282 | 282 | wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.min.js', array(), WPINV_VERSION ); |
283 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
284 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
283 | + wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
284 | + wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
285 | 285 | |
286 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
287 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable', 'wp-hooks' ), $version ); |
|
286 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
287 | + wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable', 'wp-hooks' ), $version ); |
|
288 | 288 | |
289 | - wp_localize_script( |
|
289 | + wp_localize_script( |
|
290 | 290 | 'wpinv-admin-payment-form-script', |
291 | 291 | 'wpinvPaymentFormAdmin', |
292 | 292 | array( |
293 | - 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
294 | - 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
295 | - 'currency' => wpinv_currency_symbol(), |
|
296 | - 'position' => wpinv_currency_position(), |
|
297 | - 'decimals' => (int) wpinv_decimals(), |
|
298 | - 'thousands_sep' => wpinv_thousands_separator(), |
|
299 | - 'decimals_sep' => wpinv_decimal_separator(), |
|
300 | - 'form_items' => gepaid_get_form_items( $post->ID ), |
|
301 | - 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
293 | + 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
294 | + 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
295 | + 'currency' => wpinv_currency_symbol(), |
|
296 | + 'position' => wpinv_currency_position(), |
|
297 | + 'decimals' => (int) wpinv_decimals(), |
|
298 | + 'thousands_sep' => wpinv_thousands_separator(), |
|
299 | + 'decimals_sep' => wpinv_decimal_separator(), |
|
300 | + 'form_items' => gepaid_get_form_items( $post->ID ), |
|
301 | + 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
302 | 302 | ) |
303 | 303 | ); |
304 | 304 | |
@@ -307,19 +307,19 @@ discard block |
||
307 | 307 | } |
308 | 308 | |
309 | 309 | /** |
310 | - * Add our classes to admin pages. |
|
310 | + * Add our classes to admin pages. |
|
311 | 311 | * |
312 | 312 | * @param string $classes |
313 | 313 | * @return string |
314 | - * |
|
315 | - */ |
|
314 | + * |
|
315 | + */ |
|
316 | 316 | public function admin_body_class( $classes ) { |
317 | - global $pagenow, $post, $current_screen; |
|
317 | + global $pagenow, $post, $current_screen; |
|
318 | 318 | |
319 | 319 | $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
320 | 320 | |
321 | 321 | if ( ! empty( $current_screen->post_type ) ) { |
322 | - $page = $current_screen->post_type; |
|
322 | + $page = $current_screen->post_type; |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | if ( false !== stripos( $page, 'wpi' ) ) { |
@@ -328,70 +328,70 @@ discard block |
||
328 | 328 | |
329 | 329 | if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) { |
330 | 330 | $classes .= ' wpinv-cpt wpinv'; |
331 | - } |
|
331 | + } |
|
332 | 332 | |
333 | - if ( getpaid_is_invoice_post_type( $page ) ) { |
|
333 | + if ( getpaid_is_invoice_post_type( $page ) ) { |
|
334 | 334 | $classes .= ' getpaid-is-invoice-cpt'; |
335 | 335 | } |
336 | 336 | |
337 | - return $classes; |
|
337 | + return $classes; |
|
338 | 338 | } |
339 | 339 | |
340 | 340 | /** |
341 | - * Maybe show the AyeCode Connect Notice. |
|
342 | - */ |
|
343 | - public function init_ayecode_connect_helper() { |
|
341 | + * Maybe show the AyeCode Connect Notice. |
|
342 | + */ |
|
343 | + public function init_ayecode_connect_helper() { |
|
344 | 344 | |
345 | - // Register with the deactivation survey class. |
|
346 | - AyeCode_Deactivation_Survey::instance( |
|
345 | + // Register with the deactivation survey class. |
|
346 | + AyeCode_Deactivation_Survey::instance( |
|
347 | 347 | array( |
348 | - 'slug' => 'invoicing', |
|
349 | - 'version' => WPINV_VERSION, |
|
350 | - 'support_url' => 'https://wpgetpaid.com/support/', |
|
351 | - 'documentation_url' => 'https://docs.wpgetpaid.com/', |
|
352 | - 'activated' => (int) get_option( 'gepaid_installed_on' ), |
|
348 | + 'slug' => 'invoicing', |
|
349 | + 'version' => WPINV_VERSION, |
|
350 | + 'support_url' => 'https://wpgetpaid.com/support/', |
|
351 | + 'documentation_url' => 'https://docs.wpgetpaid.com/', |
|
352 | + 'activated' => (int) get_option( 'gepaid_installed_on' ), |
|
353 | 353 | ) |
354 | 354 | ); |
355 | 355 | |
356 | 356 | new AyeCode_Connect_Helper( |
357 | 357 | array( |
358 | - 'connect_title' => __( 'WP Invoicing - an AyeCode product!', 'invoicing' ), |
|
359 | - 'connect_external' => __( 'Please confirm you wish to connect your site?', 'invoicing' ), |
|
360 | - 'connect' => sprintf( __( '<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %1$slearn more%2$s', 'invoicing' ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", '</a>' ), |
|
361 | - 'connect_button' => __( 'Connect Site', 'invoicing' ), |
|
362 | - 'connecting_button' => __( 'Connecting...', 'invoicing' ), |
|
363 | - 'error_localhost' => __( 'This service will only work with a live domain, not a localhost.', 'invoicing' ), |
|
364 | - 'error' => __( 'Something went wrong, please refresh and try again.', 'invoicing' ), |
|
358 | + 'connect_title' => __( 'WP Invoicing - an AyeCode product!', 'invoicing' ), |
|
359 | + 'connect_external' => __( 'Please confirm you wish to connect your site?', 'invoicing' ), |
|
360 | + 'connect' => sprintf( __( '<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %1$slearn more%2$s', 'invoicing' ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", '</a>' ), |
|
361 | + 'connect_button' => __( 'Connect Site', 'invoicing' ), |
|
362 | + 'connecting_button' => __( 'Connecting...', 'invoicing' ), |
|
363 | + 'error_localhost' => __( 'This service will only work with a live domain, not a localhost.', 'invoicing' ), |
|
364 | + 'error' => __( 'Something went wrong, please refresh and try again.', 'invoicing' ), |
|
365 | 365 | ), |
366 | 366 | array( 'wpi-addons' ) |
367 | 367 | ); |
368 | 368 | |
369 | 369 | } |
370 | 370 | |
371 | - /** |
|
372 | - * Redirect users to settings on activation. |
|
373 | - * |
|
374 | - * @return void |
|
375 | - */ |
|
376 | - public function activation_redirect() { |
|
371 | + /** |
|
372 | + * Redirect users to settings on activation. |
|
373 | + * |
|
374 | + * @return void |
|
375 | + */ |
|
376 | + public function activation_redirect() { |
|
377 | 377 | |
378 | - $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
378 | + $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
379 | 379 | |
380 | - if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
381 | - return; |
|
382 | - } |
|
380 | + if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
381 | + return; |
|
382 | + } |
|
383 | 383 | |
384 | - // Bail if activating from network, or bulk |
|
385 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
386 | - return; |
|
387 | - } |
|
384 | + // Bail if activating from network, or bulk |
|
385 | + if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
386 | + return; |
|
387 | + } |
|
388 | 388 | |
389 | - update_option( 'wpinv_redirected_to_settings', 1 ); |
|
389 | + update_option( 'wpinv_redirected_to_settings', 1 ); |
|
390 | 390 | |
391 | 391 | wp_safe_redirect( admin_url( 'index.php?page=gp-setup' ) ); |
392 | 392 | exit; |
393 | 393 | |
394 | - } |
|
394 | + } |
|
395 | 395 | |
396 | 396 | /** |
397 | 397 | * Fires an admin action after verifying that a user can fire them. |
@@ -405,564 +405,564 @@ discard block |
||
405 | 405 | |
406 | 406 | } |
407 | 407 | |
408 | - /** |
|
408 | + /** |
|
409 | 409 | * Duplicate invoice. |
410 | - * |
|
411 | - * @param array $args |
|
410 | + * |
|
411 | + * @param array $args |
|
412 | 412 | */ |
413 | 413 | public function duplicate_invoice( $args ) { |
414 | 414 | |
415 | - if ( empty( $args['invoice_id'] ) ) { |
|
416 | - return; |
|
417 | - } |
|
415 | + if ( empty( $args['invoice_id'] ) ) { |
|
416 | + return; |
|
417 | + } |
|
418 | 418 | |
419 | - $invoice = new WPInv_Invoice( (int) $args['invoice_id'] ); |
|
419 | + $invoice = new WPInv_Invoice( (int) $args['invoice_id'] ); |
|
420 | 420 | |
421 | - if ( ! $invoice->exists() ) { |
|
422 | - return; |
|
423 | - } |
|
421 | + if ( ! $invoice->exists() ) { |
|
422 | + return; |
|
423 | + } |
|
424 | 424 | |
425 | - $new_invoice = getpaid_duplicate_invoice( $invoice ); |
|
426 | - $new_invoice->save(); |
|
425 | + $new_invoice = getpaid_duplicate_invoice( $invoice ); |
|
426 | + $new_invoice->save(); |
|
427 | 427 | |
428 | - if ( $new_invoice->exists() ) { |
|
428 | + if ( $new_invoice->exists() ) { |
|
429 | 429 | |
430 | - getpaid_admin()->show_success( __( 'Invoice duplicated successfully.', 'invoicing' ) ); |
|
430 | + getpaid_admin()->show_success( __( 'Invoice duplicated successfully.', 'invoicing' ) ); |
|
431 | 431 | |
432 | - wp_safe_redirect( |
|
433 | - add_query_arg( |
|
434 | - array( |
|
435 | - 'action' => 'edit', |
|
436 | - 'post' => $new_invoice->get_id(), |
|
437 | - ), |
|
438 | - admin_url( 'post.php' ) |
|
439 | - ) |
|
440 | - ); |
|
441 | - exit; |
|
432 | + wp_safe_redirect( |
|
433 | + add_query_arg( |
|
434 | + array( |
|
435 | + 'action' => 'edit', |
|
436 | + 'post' => $new_invoice->get_id(), |
|
437 | + ), |
|
438 | + admin_url( 'post.php' ) |
|
439 | + ) |
|
440 | + ); |
|
441 | + exit; |
|
442 | 442 | |
443 | - } |
|
443 | + } |
|
444 | 444 | |
445 | - getpaid_admin()->show_error( __( 'There was an error duplicating this invoice. Please try again.', 'invoicing' ) ); |
|
445 | + getpaid_admin()->show_error( __( 'There was an error duplicating this invoice. Please try again.', 'invoicing' ) ); |
|
446 | 446 | |
447 | - } |
|
447 | + } |
|
448 | 448 | |
449 | - /** |
|
449 | + /** |
|
450 | 450 | * Sends a payment reminder to a customer. |
451 | - * |
|
452 | - * @param array $args |
|
451 | + * |
|
452 | + * @param array $args |
|
453 | 453 | */ |
454 | 454 | public function duplicate_payment_form( $args ) { |
455 | 455 | |
456 | - if ( empty( $args['form_id'] ) ) { |
|
457 | - return; |
|
458 | - } |
|
459 | - |
|
460 | - $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
456 | + if ( empty( $args['form_id'] ) ) { |
|
457 | + return; |
|
458 | + } |
|
461 | 459 | |
462 | - if ( ! $form->exists() ) { |
|
463 | - return; |
|
464 | - } |
|
460 | + $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
465 | 461 | |
466 | - $new_form = new GetPaid_Payment_Form(); |
|
467 | - $new_form->set_author( $form->get_author( 'edit' ) ); |
|
468 | - $new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) ); |
|
469 | - $new_form->set_elements( $form->get_elements( 'edit' ) ); |
|
470 | - $new_form->set_items( $form->get_items( 'edit' ) ); |
|
471 | - $new_form->save(); |
|
462 | + if ( ! $form->exists() ) { |
|
463 | + return; |
|
464 | + } |
|
472 | 465 | |
473 | - if ( $new_form->exists() ) { |
|
474 | - $this->show_success( __( 'Form duplicated successfully', 'invoicing' ) ); |
|
475 | - $url = get_edit_post_link( $new_form->get_id(), 'edit' ); |
|
476 | - } else { |
|
477 | - $this->show_error( __( 'Unable to duplicate form', 'invoicing' ) ); |
|
478 | - $url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ); |
|
479 | - } |
|
466 | + $new_form = new GetPaid_Payment_Form(); |
|
467 | + $new_form->set_author( $form->get_author( 'edit' ) ); |
|
468 | + $new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) ); |
|
469 | + $new_form->set_elements( $form->get_elements( 'edit' ) ); |
|
470 | + $new_form->set_items( $form->get_items( 'edit' ) ); |
|
471 | + $new_form->save(); |
|
472 | + |
|
473 | + if ( $new_form->exists() ) { |
|
474 | + $this->show_success( __( 'Form duplicated successfully', 'invoicing' ) ); |
|
475 | + $url = get_edit_post_link( $new_form->get_id(), 'edit' ); |
|
476 | + } else { |
|
477 | + $this->show_error( __( 'Unable to duplicate form', 'invoicing' ) ); |
|
478 | + $url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ); |
|
479 | + } |
|
480 | 480 | |
481 | - wp_redirect( $url ); |
|
482 | - exit; |
|
483 | - } |
|
481 | + wp_redirect( $url ); |
|
482 | + exit; |
|
483 | + } |
|
484 | 484 | |
485 | - /** |
|
485 | + /** |
|
486 | 486 | * Resets form stats. |
487 | - * |
|
488 | - * @param array $args |
|
487 | + * |
|
488 | + * @param array $args |
|
489 | 489 | */ |
490 | 490 | public function reset_form_stats( $args ) { |
491 | 491 | |
492 | - if ( empty( $args['form_id'] ) ) { |
|
493 | - return; |
|
494 | - } |
|
492 | + if ( empty( $args['form_id'] ) ) { |
|
493 | + return; |
|
494 | + } |
|
495 | 495 | |
496 | - $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
496 | + $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
497 | 497 | |
498 | - if ( ! $form->exists() ) { |
|
499 | - return; |
|
500 | - } |
|
498 | + if ( ! $form->exists() ) { |
|
499 | + return; |
|
500 | + } |
|
501 | 501 | |
502 | - $form->set_earned( 0 ); |
|
503 | - $form->set_refunded( 0 ); |
|
504 | - $form->set_cancelled( 0 ); |
|
505 | - $form->set_failed( 0 ); |
|
506 | - $form->save(); |
|
502 | + $form->set_earned( 0 ); |
|
503 | + $form->set_refunded( 0 ); |
|
504 | + $form->set_cancelled( 0 ); |
|
505 | + $form->set_failed( 0 ); |
|
506 | + $form->save(); |
|
507 | 507 | |
508 | - $this->show_success( __( 'Form stats reset successfully', 'invoicing' ) ); |
|
508 | + $this->show_success( __( 'Form stats reset successfully', 'invoicing' ) ); |
|
509 | 509 | |
510 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ) ); |
|
511 | - exit; |
|
512 | - } |
|
510 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ) ); |
|
511 | + exit; |
|
512 | + } |
|
513 | 513 | |
514 | - /** |
|
514 | + /** |
|
515 | 515 | * Sends a payment reminder to a customer. |
516 | - * |
|
517 | - * @param array $args |
|
516 | + * |
|
517 | + * @param array $args |
|
518 | 518 | */ |
519 | 519 | public function send_customer_invoice( $args ) { |
520 | - getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true ); |
|
521 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
522 | - exit; |
|
523 | - } |
|
520 | + getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true ); |
|
521 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
522 | + exit; |
|
523 | + } |
|
524 | 524 | |
525 | - /** |
|
525 | + /** |
|
526 | 526 | * Sends a payment reminder to a customer. |
527 | - * |
|
528 | - * @param array $args |
|
527 | + * |
|
528 | + * @param array $args |
|
529 | 529 | */ |
530 | 530 | public function send_customer_payment_reminder( $args ) { |
531 | - $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
531 | + $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
532 | 532 | |
533 | - if ( $sent ) { |
|
534 | - $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
535 | - } else { |
|
536 | - $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
537 | - } |
|
533 | + if ( $sent ) { |
|
534 | + $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
535 | + } else { |
|
536 | + $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
537 | + } |
|
538 | 538 | |
539 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
540 | - exit; |
|
541 | - } |
|
539 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
540 | + exit; |
|
541 | + } |
|
542 | 542 | |
543 | - /** |
|
543 | + /** |
|
544 | 544 | * Resets tax rates. |
545 | - * |
|
545 | + * |
|
546 | 546 | */ |
547 | 547 | public function admin_reset_tax_rates() { |
548 | 548 | |
549 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
550 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
551 | - exit; |
|
549 | + update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
550 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
551 | + exit; |
|
552 | 552 | |
553 | - } |
|
553 | + } |
|
554 | 554 | |
555 | - /** |
|
555 | + /** |
|
556 | 556 | * Resets admin pages. |
557 | - * |
|
557 | + * |
|
558 | 558 | */ |
559 | 559 | public function admin_create_missing_pages() { |
560 | - $installer = new GetPaid_Installer(); |
|
561 | - $installer->create_pages(); |
|
562 | - $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
563 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
564 | - exit; |
|
565 | - } |
|
566 | - |
|
567 | - /** |
|
568 | - * Refreshes the permalinks. |
|
569 | - */ |
|
570 | - public function admin_refresh_permalinks() { |
|
571 | - flush_rewrite_rules(); |
|
572 | - $this->show_success( __( 'Permalinks refreshed.', 'invoicing' ) ); |
|
573 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
574 | - exit; |
|
575 | - } |
|
576 | - |
|
577 | - /** |
|
560 | + $installer = new GetPaid_Installer(); |
|
561 | + $installer->create_pages(); |
|
562 | + $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
563 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
564 | + exit; |
|
565 | + } |
|
566 | + |
|
567 | + /** |
|
568 | + * Refreshes the permalinks. |
|
569 | + */ |
|
570 | + public function admin_refresh_permalinks() { |
|
571 | + flush_rewrite_rules(); |
|
572 | + $this->show_success( __( 'Permalinks refreshed.', 'invoicing' ) ); |
|
573 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
574 | + exit; |
|
575 | + } |
|
576 | + |
|
577 | + /** |
|
578 | 578 | * Creates an missing admin tables. |
579 | - * |
|
579 | + * |
|
580 | 580 | */ |
581 | 581 | public function admin_create_missing_tables() { |
582 | - global $wpdb; |
|
583 | - $installer = new GetPaid_Installer(); |
|
582 | + global $wpdb; |
|
583 | + $installer = new GetPaid_Installer(); |
|
584 | 584 | |
585 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) { |
|
586 | - $installer->create_subscriptions_table(); |
|
585 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) { |
|
586 | + $installer->create_subscriptions_table(); |
|
587 | 587 | |
588 | - if ( $wpdb->last_error !== '' ) { |
|
589 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
590 | - } |
|
591 | - } |
|
588 | + if ( $wpdb->last_error !== '' ) { |
|
589 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
590 | + } |
|
591 | + } |
|
592 | 592 | |
593 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) { |
|
594 | - $installer->create_invoices_table(); |
|
593 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) { |
|
594 | + $installer->create_invoices_table(); |
|
595 | 595 | |
596 | - if ( '' !== $wpdb->last_error ) { |
|
597 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
598 | - } |
|
599 | - } |
|
596 | + if ( '' !== $wpdb->last_error ) { |
|
597 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
598 | + } |
|
599 | + } |
|
600 | 600 | |
601 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) { |
|
602 | - $installer->create_invoice_items_table(); |
|
601 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) { |
|
602 | + $installer->create_invoice_items_table(); |
|
603 | 603 | |
604 | - if ( '' !== $wpdb->last_error ) { |
|
605 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
606 | - } |
|
607 | - } |
|
604 | + if ( '' !== $wpdb->last_error ) { |
|
605 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
606 | + } |
|
607 | + } |
|
608 | 608 | |
609 | - if ( ! $this->has_notices() ) { |
|
610 | - $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
611 | - } |
|
609 | + if ( ! $this->has_notices() ) { |
|
610 | + $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
611 | + } |
|
612 | 612 | |
613 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
614 | - exit; |
|
615 | - } |
|
613 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
614 | + exit; |
|
615 | + } |
|
616 | 616 | |
617 | - /** |
|
617 | + /** |
|
618 | 618 | * Migrates old invoices to the new database tables. |
619 | - * |
|
619 | + * |
|
620 | 620 | */ |
621 | 621 | public function admin_migrate_old_invoices() { |
622 | 622 | |
623 | - // Migrate the invoices. |
|
624 | - $installer = new GetPaid_Installer(); |
|
625 | - $installer->migrate_old_invoices(); |
|
623 | + // Migrate the invoices. |
|
624 | + $installer = new GetPaid_Installer(); |
|
625 | + $installer->migrate_old_invoices(); |
|
626 | 626 | |
627 | - // Show an admin message. |
|
628 | - $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
627 | + // Show an admin message. |
|
628 | + $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
629 | 629 | |
630 | - // Redirect the admin. |
|
631 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
632 | - exit; |
|
630 | + // Redirect the admin. |
|
631 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
632 | + exit; |
|
633 | 633 | |
634 | - } |
|
634 | + } |
|
635 | 635 | |
636 | - /** |
|
636 | + /** |
|
637 | 637 | * Download customers. |
638 | - * |
|
638 | + * |
|
639 | 639 | */ |
640 | 640 | public function admin_download_customers() { |
641 | - global $wpdb; |
|
642 | - |
|
643 | - $output = fopen( 'php://output', 'w' ); |
|
644 | - |
|
645 | - if ( false === $output ) { |
|
646 | - wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
647 | - } |
|
641 | + global $wpdb; |
|
648 | 642 | |
649 | - header( 'Content-Type:text/csv' ); |
|
650 | - header( 'Content-Disposition:attachment;filename=customers.csv' ); |
|
643 | + $output = fopen( 'php://output', 'w' ); |
|
651 | 644 | |
652 | - $post_types = ''; |
|
645 | + if ( false === $output ) { |
|
646 | + wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
647 | + } |
|
653 | 648 | |
654 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
655 | - $post_types .= $wpdb->prepare( 'post_type=%s OR ', $post_type ); |
|
656 | - } |
|
649 | + header( 'Content-Type:text/csv' ); |
|
650 | + header( 'Content-Disposition:attachment;filename=customers.csv' ); |
|
657 | 651 | |
658 | - $post_types = rtrim( $post_types, ' OR' ); |
|
652 | + $post_types = ''; |
|
659 | 653 | |
660 | - $customers = $wpdb->get_col( "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types" ); |
|
654 | + foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
655 | + $post_types .= $wpdb->prepare( 'post_type=%s OR ', $post_type ); |
|
656 | + } |
|
661 | 657 | |
662 | - $columns = array( |
|
663 | - 'name' => __( 'Name', 'invoicing' ), |
|
664 | - 'email' => __( 'Email', 'invoicing' ), |
|
665 | - 'country' => __( 'Country', 'invoicing' ), |
|
666 | - 'state' => __( 'State', 'invoicing' ), |
|
667 | - 'city' => __( 'City', 'invoicing' ), |
|
668 | - 'zip' => __( 'ZIP', 'invoicing' ), |
|
669 | - 'address' => __( 'Address', 'invoicing' ), |
|
670 | - 'phone' => __( 'Phone', 'invoicing' ), |
|
671 | - 'company' => __( 'Company', 'invoicing' ), |
|
672 | - 'company_id' => __( 'Company ID', 'invoicing' ), |
|
673 | - 'invoices' => __( 'Invoices', 'invoicing' ), |
|
674 | - 'total_raw' => __( 'Total Spend', 'invoicing' ), |
|
675 | - 'signup' => __( 'Date created', 'invoicing' ), |
|
676 | - ); |
|
658 | + $post_types = rtrim( $post_types, ' OR' ); |
|
659 | + |
|
660 | + $customers = $wpdb->get_col( "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types" ); |
|
661 | + |
|
662 | + $columns = array( |
|
663 | + 'name' => __( 'Name', 'invoicing' ), |
|
664 | + 'email' => __( 'Email', 'invoicing' ), |
|
665 | + 'country' => __( 'Country', 'invoicing' ), |
|
666 | + 'state' => __( 'State', 'invoicing' ), |
|
667 | + 'city' => __( 'City', 'invoicing' ), |
|
668 | + 'zip' => __( 'ZIP', 'invoicing' ), |
|
669 | + 'address' => __( 'Address', 'invoicing' ), |
|
670 | + 'phone' => __( 'Phone', 'invoicing' ), |
|
671 | + 'company' => __( 'Company', 'invoicing' ), |
|
672 | + 'company_id' => __( 'Company ID', 'invoicing' ), |
|
673 | + 'invoices' => __( 'Invoices', 'invoicing' ), |
|
674 | + 'total_raw' => __( 'Total Spend', 'invoicing' ), |
|
675 | + 'signup' => __( 'Date created', 'invoicing' ), |
|
676 | + ); |
|
677 | 677 | |
678 | - // Output the csv column headers. |
|
679 | - fputcsv( $output, array_values( $columns ) ); |
|
678 | + // Output the csv column headers. |
|
679 | + fputcsv( $output, array_values( $columns ) ); |
|
680 | 680 | |
681 | - // Loop through |
|
682 | - $table = new WPInv_Customers_Table(); |
|
683 | - foreach ( $customers as $customer_id ) { |
|
681 | + // Loop through |
|
682 | + $table = new WPInv_Customers_Table(); |
|
683 | + foreach ( $customers as $customer_id ) { |
|
684 | 684 | |
685 | - $user = get_user_by( 'id', $customer_id ); |
|
686 | - $row = array(); |
|
687 | - if ( empty( $user ) ) { |
|
688 | - continue; |
|
689 | - } |
|
685 | + $user = get_user_by( 'id', $customer_id ); |
|
686 | + $row = array(); |
|
687 | + if ( empty( $user ) ) { |
|
688 | + continue; |
|
689 | + } |
|
690 | 690 | |
691 | - foreach ( array_keys( $columns ) as $column ) { |
|
691 | + foreach ( array_keys( $columns ) as $column ) { |
|
692 | 692 | |
693 | - $method = 'column_' . $column; |
|
693 | + $method = 'column_' . $column; |
|
694 | 694 | |
695 | - if ( 'name' == $column ) { |
|
696 | - $value = esc_html( $user->display_name ); |
|
697 | - } elseif ( 'email' == $column ) { |
|
698 | - $value = sanitize_email( $user->user_email ); |
|
699 | - } elseif ( is_callable( array( $table, $method ) ) ) { |
|
700 | - $value = wp_strip_all_tags( $table->$method( $user ) ); |
|
701 | - } |
|
695 | + if ( 'name' == $column ) { |
|
696 | + $value = esc_html( $user->display_name ); |
|
697 | + } elseif ( 'email' == $column ) { |
|
698 | + $value = sanitize_email( $user->user_email ); |
|
699 | + } elseif ( is_callable( array( $table, $method ) ) ) { |
|
700 | + $value = wp_strip_all_tags( $table->$method( $user ) ); |
|
701 | + } |
|
702 | 702 | |
703 | - if ( empty( $value ) ) { |
|
704 | - $value = esc_html( get_user_meta( $user->ID, '_wpinv_' . $column, true ) ); |
|
705 | - } |
|
703 | + if ( empty( $value ) ) { |
|
704 | + $value = esc_html( get_user_meta( $user->ID, '_wpinv_' . $column, true ) ); |
|
705 | + } |
|
706 | 706 | |
707 | - $row[] = $value; |
|
707 | + $row[] = $value; |
|
708 | 708 | |
709 | - } |
|
709 | + } |
|
710 | 710 | |
711 | - fputcsv( $output, $row ); |
|
712 | - } |
|
711 | + fputcsv( $output, $row ); |
|
712 | + } |
|
713 | 713 | |
714 | - fclose( $output ); |
|
715 | - exit; |
|
714 | + fclose( $output ); |
|
715 | + exit; |
|
716 | 716 | |
717 | - } |
|
717 | + } |
|
718 | 718 | |
719 | - /** |
|
719 | + /** |
|
720 | 720 | * Installs a plugin. |
721 | - * |
|
722 | - * @param array $data |
|
721 | + * |
|
722 | + * @param array $data |
|
723 | 723 | */ |
724 | 724 | public function admin_install_plugin( $data ) { |
725 | 725 | |
726 | - if ( ! empty( $data['plugins'] ) ) { |
|
727 | - include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
728 | - wp_cache_flush(); |
|
726 | + if ( ! empty( $data['plugins'] ) ) { |
|
727 | + include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
728 | + wp_cache_flush(); |
|
729 | 729 | |
730 | - foreach ( $data['plugins'] as $slug => $file ) { |
|
731 | - $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' ); |
|
732 | - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
733 | - $installed = $upgrader->install( $plugin_zip ); |
|
730 | + foreach ( $data['plugins'] as $slug => $file ) { |
|
731 | + $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' ); |
|
732 | + $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
733 | + $installed = $upgrader->install( $plugin_zip ); |
|
734 | 734 | |
735 | - if ( ! is_wp_error( $installed ) && $installed ) { |
|
736 | - activate_plugin( $file, '', false, true ); |
|
737 | - } else { |
|
738 | - wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false ); |
|
739 | - } |
|
735 | + if ( ! is_wp_error( $installed ) && $installed ) { |
|
736 | + activate_plugin( $file, '', false, true ); |
|
737 | + } else { |
|
738 | + wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false ); |
|
739 | + } |
|
740 | 740 | } |
741 | 741 | } |
742 | 742 | |
743 | - $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' ); |
|
744 | - wp_safe_redirect( $redirect ); |
|
745 | - exit; |
|
743 | + $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' ); |
|
744 | + wp_safe_redirect( $redirect ); |
|
745 | + exit; |
|
746 | 746 | |
747 | - } |
|
747 | + } |
|
748 | 748 | |
749 | - /** |
|
749 | + /** |
|
750 | 750 | * Connects a gateway. |
751 | - * |
|
752 | - * @param array $data |
|
751 | + * |
|
752 | + * @param array $data |
|
753 | 753 | */ |
754 | 754 | public function admin_connect_gateway( $data ) { |
755 | 755 | |
756 | - if ( ! empty( $data['plugin'] ) ) { |
|
756 | + if ( ! empty( $data['plugin'] ) ) { |
|
757 | 757 | |
758 | - $gateway = sanitize_key( $data['plugin'] ); |
|
759 | - $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
758 | + $gateway = sanitize_key( $data['plugin'] ); |
|
759 | + $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
760 | 760 | |
761 | - if ( ! empty( $connect_url ) ) { |
|
762 | - wp_redirect( $connect_url ); |
|
763 | - exit; |
|
764 | - } |
|
761 | + if ( ! empty( $connect_url ) ) { |
|
762 | + wp_redirect( $connect_url ); |
|
763 | + exit; |
|
764 | + } |
|
765 | 765 | |
766 | - if ( 'stripe' == $data['plugin'] ) { |
|
767 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
768 | - include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
769 | - wp_cache_flush(); |
|
766 | + if ( 'stripe' == $data['plugin'] ) { |
|
767 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
768 | + include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
769 | + wp_cache_flush(); |
|
770 | 770 | |
771 | - if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) { |
|
772 | - $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' ); |
|
773 | - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
774 | - $upgrader->install( $plugin_zip ); |
|
775 | - } |
|
771 | + if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) { |
|
772 | + $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' ); |
|
773 | + $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
774 | + $upgrader->install( $plugin_zip ); |
|
775 | + } |
|
776 | 776 | |
777 | - activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true ); |
|
778 | - } |
|
777 | + activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true ); |
|
778 | + } |
|
779 | 779 | |
780 | - $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
781 | - if ( ! empty( $connect_url ) ) { |
|
782 | - wp_redirect( $connect_url ); |
|
783 | - exit; |
|
784 | - } |
|
780 | + $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
781 | + if ( ! empty( $connect_url ) ) { |
|
782 | + wp_redirect( $connect_url ); |
|
783 | + exit; |
|
784 | + } |
|
785 | 785 | } |
786 | 786 | |
787 | - $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' ); |
|
788 | - wp_safe_redirect( $redirect ); |
|
789 | - exit; |
|
787 | + $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' ); |
|
788 | + wp_safe_redirect( $redirect ); |
|
789 | + exit; |
|
790 | 790 | |
791 | - } |
|
791 | + } |
|
792 | 792 | |
793 | - /** |
|
793 | + /** |
|
794 | 794 | * Recalculates discounts. |
795 | - * |
|
795 | + * |
|
796 | 796 | */ |
797 | 797 | public function admin_recalculate_discounts() { |
798 | - global $wpdb; |
|
798 | + global $wpdb; |
|
799 | 799 | |
800 | - // Fetch all invoices that have discount codes. |
|
801 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
802 | - $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" ); |
|
800 | + // Fetch all invoices that have discount codes. |
|
801 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
802 | + $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" ); |
|
803 | 803 | |
804 | - foreach ( $invoices as $invoice ) { |
|
804 | + foreach ( $invoices as $invoice ) { |
|
805 | 805 | |
806 | - $invoice = new WPInv_Invoice( $invoice ); |
|
806 | + $invoice = new WPInv_Invoice( $invoice ); |
|
807 | 807 | |
808 | - if ( ! $invoice->exists() ) { |
|
809 | - continue; |
|
810 | - } |
|
808 | + if ( ! $invoice->exists() ) { |
|
809 | + continue; |
|
810 | + } |
|
811 | 811 | |
812 | - // Abort if the discount does not exist or does not apply here. |
|
813 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
814 | - if ( ! $discount->exists() ) { |
|
815 | - continue; |
|
816 | - } |
|
812 | + // Abort if the discount does not exist or does not apply here. |
|
813 | + $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
814 | + if ( ! $discount->exists() ) { |
|
815 | + continue; |
|
816 | + } |
|
817 | 817 | |
818 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
819 | - $invoice->recalculate_total(); |
|
818 | + $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
819 | + $invoice->recalculate_total(); |
|
820 | 820 | |
821 | - if ( $invoice->get_total_discount() > 0 ) { |
|
822 | - $invoice->save(); |
|
823 | - } |
|
821 | + if ( $invoice->get_total_discount() > 0 ) { |
|
822 | + $invoice->save(); |
|
823 | + } |
|
824 | 824 | } |
825 | 825 | |
826 | - // Show an admin message. |
|
827 | - $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) ); |
|
826 | + // Show an admin message. |
|
827 | + $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) ); |
|
828 | 828 | |
829 | - // Redirect the admin. |
|
830 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
831 | - exit; |
|
829 | + // Redirect the admin. |
|
830 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
831 | + exit; |
|
832 | 832 | |
833 | - } |
|
833 | + } |
|
834 | 834 | |
835 | 835 | /** |
836 | - * Returns an array of admin notices. |
|
837 | - * |
|
838 | - * @since 1.0.19 |
|
836 | + * Returns an array of admin notices. |
|
837 | + * |
|
838 | + * @since 1.0.19 |
|
839 | 839 | * @return array |
840 | - */ |
|
841 | - public function get_notices() { |
|
842 | - $notices = get_option( 'wpinv_admin_notices' ); |
|
840 | + */ |
|
841 | + public function get_notices() { |
|
842 | + $notices = get_option( 'wpinv_admin_notices' ); |
|
843 | 843 | return is_array( $notices ) ? $notices : array(); |
844 | - } |
|
844 | + } |
|
845 | 845 | |
846 | - /** |
|
847 | - * Checks if we have any admin notices. |
|
848 | - * |
|
849 | - * @since 2.0.4 |
|
846 | + /** |
|
847 | + * Checks if we have any admin notices. |
|
848 | + * |
|
849 | + * @since 2.0.4 |
|
850 | 850 | * @return array |
851 | - */ |
|
852 | - public function has_notices() { |
|
853 | - return count( $this->get_notices() ) > 0; |
|
854 | - } |
|
855 | - |
|
856 | - /** |
|
857 | - * Clears all admin notices |
|
858 | - * |
|
859 | - * @access public |
|
860 | - * @since 1.0.19 |
|
861 | - */ |
|
862 | - public function clear_notices() { |
|
863 | - delete_option( 'wpinv_admin_notices' ); |
|
864 | - } |
|
865 | - |
|
866 | - /** |
|
867 | - * Saves a new admin notice |
|
868 | - * |
|
869 | - * @access public |
|
870 | - * @since 1.0.19 |
|
871 | - */ |
|
872 | - public function save_notice( $type, $message ) { |
|
873 | - $notices = $this->get_notices(); |
|
874 | - |
|
875 | - if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ] ) ) { |
|
876 | - $notices[ $type ] = array(); |
|
877 | - } |
|
878 | - |
|
879 | - $notices[ $type ][] = $message; |
|
880 | - |
|
881 | - update_option( 'wpinv_admin_notices', $notices ); |
|
882 | - } |
|
883 | - |
|
884 | - /** |
|
885 | - * Displays a success notice |
|
886 | - * |
|
887 | - * @param string $msg The message to qeue. |
|
888 | - * @access public |
|
889 | - * @since 1.0.19 |
|
890 | - */ |
|
891 | - public function show_success( $msg ) { |
|
892 | - $this->save_notice( 'success', $msg ); |
|
893 | - } |
|
894 | - |
|
895 | - /** |
|
896 | - * Displays a error notice |
|
897 | - * |
|
898 | - * @access public |
|
899 | - * @param string $msg The message to qeue. |
|
900 | - * @since 1.0.19 |
|
901 | - */ |
|
902 | - public function show_error( $msg ) { |
|
903 | - $this->save_notice( 'error', $msg ); |
|
904 | - } |
|
905 | - |
|
906 | - /** |
|
907 | - * Displays a warning notice |
|
908 | - * |
|
909 | - * @access public |
|
910 | - * @param string $msg The message to qeue. |
|
911 | - * @since 1.0.19 |
|
912 | - */ |
|
913 | - public function show_warning( $msg ) { |
|
914 | - $this->save_notice( 'warning', $msg ); |
|
915 | - } |
|
916 | - |
|
917 | - /** |
|
918 | - * Displays a info notice |
|
919 | - * |
|
920 | - * @access public |
|
921 | - * @param string $msg The message to qeue. |
|
922 | - * @since 1.0.19 |
|
923 | - */ |
|
924 | - public function show_info( $msg ) { |
|
925 | - $this->save_notice( 'info', $msg ); |
|
926 | - } |
|
927 | - |
|
928 | - /** |
|
929 | - * Show notices |
|
930 | - * |
|
931 | - * @access public |
|
932 | - * @since 1.0.19 |
|
933 | - */ |
|
934 | - public function show_notices() { |
|
851 | + */ |
|
852 | + public function has_notices() { |
|
853 | + return count( $this->get_notices() ) > 0; |
|
854 | + } |
|
855 | + |
|
856 | + /** |
|
857 | + * Clears all admin notices |
|
858 | + * |
|
859 | + * @access public |
|
860 | + * @since 1.0.19 |
|
861 | + */ |
|
862 | + public function clear_notices() { |
|
863 | + delete_option( 'wpinv_admin_notices' ); |
|
864 | + } |
|
865 | + |
|
866 | + /** |
|
867 | + * Saves a new admin notice |
|
868 | + * |
|
869 | + * @access public |
|
870 | + * @since 1.0.19 |
|
871 | + */ |
|
872 | + public function save_notice( $type, $message ) { |
|
873 | + $notices = $this->get_notices(); |
|
874 | + |
|
875 | + if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ] ) ) { |
|
876 | + $notices[ $type ] = array(); |
|
877 | + } |
|
878 | + |
|
879 | + $notices[ $type ][] = $message; |
|
880 | + |
|
881 | + update_option( 'wpinv_admin_notices', $notices ); |
|
882 | + } |
|
883 | + |
|
884 | + /** |
|
885 | + * Displays a success notice |
|
886 | + * |
|
887 | + * @param string $msg The message to qeue. |
|
888 | + * @access public |
|
889 | + * @since 1.0.19 |
|
890 | + */ |
|
891 | + public function show_success( $msg ) { |
|
892 | + $this->save_notice( 'success', $msg ); |
|
893 | + } |
|
894 | + |
|
895 | + /** |
|
896 | + * Displays a error notice |
|
897 | + * |
|
898 | + * @access public |
|
899 | + * @param string $msg The message to qeue. |
|
900 | + * @since 1.0.19 |
|
901 | + */ |
|
902 | + public function show_error( $msg ) { |
|
903 | + $this->save_notice( 'error', $msg ); |
|
904 | + } |
|
905 | + |
|
906 | + /** |
|
907 | + * Displays a warning notice |
|
908 | + * |
|
909 | + * @access public |
|
910 | + * @param string $msg The message to qeue. |
|
911 | + * @since 1.0.19 |
|
912 | + */ |
|
913 | + public function show_warning( $msg ) { |
|
914 | + $this->save_notice( 'warning', $msg ); |
|
915 | + } |
|
916 | + |
|
917 | + /** |
|
918 | + * Displays a info notice |
|
919 | + * |
|
920 | + * @access public |
|
921 | + * @param string $msg The message to qeue. |
|
922 | + * @since 1.0.19 |
|
923 | + */ |
|
924 | + public function show_info( $msg ) { |
|
925 | + $this->save_notice( 'info', $msg ); |
|
926 | + } |
|
927 | + |
|
928 | + /** |
|
929 | + * Show notices |
|
930 | + * |
|
931 | + * @access public |
|
932 | + * @since 1.0.19 |
|
933 | + */ |
|
934 | + public function show_notices() { |
|
935 | 935 | |
936 | 936 | $notices = $this->get_notices(); |
937 | 937 | $this->clear_notices(); |
938 | 938 | |
939 | - foreach ( $notices as $type => $messages ) { |
|
939 | + foreach ( $notices as $type => $messages ) { |
|
940 | 940 | |
941 | - if ( ! is_array( $messages ) ) { |
|
942 | - continue; |
|
943 | - } |
|
941 | + if ( ! is_array( $messages ) ) { |
|
942 | + continue; |
|
943 | + } |
|
944 | 944 | |
945 | 945 | $type = esc_attr( $type ); |
946 | - foreach ( $messages as $message ) { |
|
947 | - echo wp_kses_post( "<div class='notice notice-$type is-dismissible'><p>$message</p></div>" ); |
|
946 | + foreach ( $messages as $message ) { |
|
947 | + echo wp_kses_post( "<div class='notice notice-$type is-dismissible'><p>$message</p></div>" ); |
|
948 | 948 | } |
949 | 949 | } |
950 | 950 | |
951 | - foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
952 | - |
|
953 | - if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
954 | - $url = wp_nonce_url( |
|
955 | - add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
956 | - 'getpaid-nonce', |
|
957 | - 'getpaid-nonce' |
|
958 | - ); |
|
959 | - $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
960 | - $message2 = __( 'Generate Pages', 'invoicing' ); |
|
961 | - echo wp_kses_post( "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>" ); |
|
962 | - break; |
|
963 | - } |
|
951 | + foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
952 | + |
|
953 | + if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
954 | + $url = wp_nonce_url( |
|
955 | + add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
956 | + 'getpaid-nonce', |
|
957 | + 'getpaid-nonce' |
|
958 | + ); |
|
959 | + $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
960 | + $message2 = __( 'Generate Pages', 'invoicing' ); |
|
961 | + echo wp_kses_post( "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>" ); |
|
962 | + break; |
|
963 | + } |
|
964 | 964 | } |
965 | 965 | |
966 | - } |
|
966 | + } |
|
967 | 967 | |
968 | 968 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
11 | - exit; // Exit if accessed directly |
|
11 | + exit; // Exit if accessed directly |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | /** |
@@ -16,84 +16,84 @@ discard block |
||
16 | 16 | */ |
17 | 17 | class GetPaid_Meta_Box_Invoice_Address { |
18 | 18 | |
19 | - /** |
|
20 | - * Output the metabox. |
|
21 | - * |
|
22 | - * @param WP_Post $post |
|
23 | - */ |
|
24 | - public static function output( $post ) { |
|
25 | - |
|
26 | - // Prepare the invoice. |
|
27 | - $invoice = new WPInv_Invoice( $post ); |
|
28 | - $customer = $invoice->exists() ? $invoice->get_user_id( 'edit' ) : get_current_user_id(); |
|
29 | - $customer = new WP_User( $customer ); |
|
30 | - $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email ); |
|
31 | - wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' ); |
|
32 | - |
|
33 | - // Address fields. |
|
34 | - $address_fields = array( |
|
35 | - 'first_name' => array( |
|
36 | - 'label' => __( 'First Name', 'invoicing' ), |
|
37 | - 'type' => 'text', |
|
38 | - ), |
|
39 | - 'last_name' => array( |
|
40 | - 'label' => __( 'Last Name', 'invoicing' ), |
|
41 | - 'type' => 'text', |
|
42 | - ), |
|
43 | - 'company' => array( |
|
44 | - 'label' => __( 'Company', 'invoicing' ), |
|
45 | - 'type' => 'text', |
|
46 | - 'class' => 'getpaid-recalculate-prices-on-change', |
|
47 | - ), |
|
48 | - 'vat_number' => array( |
|
49 | - 'label' => __( 'VAT Number', 'invoicing' ), |
|
50 | - 'type' => 'text', |
|
51 | - ), |
|
52 | - 'address' => array( |
|
53 | - 'label' => __( 'Address', 'invoicing' ), |
|
54 | - 'type' => 'text', |
|
55 | - ), |
|
56 | - 'city' => array( |
|
57 | - 'label' => __( 'City', 'invoicing' ), |
|
58 | - 'type' => 'text', |
|
59 | - ), |
|
60 | - 'country' => array( |
|
61 | - 'label' => __( 'Country', 'invoicing' ), |
|
62 | - 'type' => 'select', |
|
63 | - 'class' => 'getpaid-recalculate-prices-on-change', |
|
64 | - 'options' => wpinv_get_country_list(), |
|
65 | - 'placeholder' => __( 'Choose a country', 'invoicing' ), |
|
66 | - ), |
|
67 | - 'state' => array( |
|
68 | - 'label' => __( 'State', 'invoicing' ), |
|
69 | - 'type' => 'text', |
|
70 | - 'class' => 'getpaid-recalculate-prices-on-change', |
|
71 | - ), |
|
72 | - 'zip' => array( |
|
73 | - 'label' => __( 'Zip', 'invoicing' ), |
|
74 | - 'type' => 'text', |
|
75 | - ), |
|
76 | - 'phone' => array( |
|
77 | - 'label' => __( 'Phone', 'invoicing' ), |
|
78 | - 'type' => 'text', |
|
79 | - ), |
|
80 | - ); |
|
81 | - |
|
82 | - $states = wpinv_get_country_states( $invoice->get_country( 'edit' ) ); |
|
83 | - |
|
84 | - if ( ! empty( $states ) ) { |
|
85 | - $address_fields['state']['type'] = 'select'; |
|
86 | - $address_fields['state']['options'] = $states; |
|
87 | - $address_fields['state']['placeholder'] = __( 'Choose a state', 'invoicing' ); |
|
88 | - } |
|
89 | - |
|
90 | - // Maybe remove the VAT field. |
|
91 | - if ( ! wpinv_use_taxes() ) { |
|
92 | - unset( $address_fields['vat_number'] ); |
|
93 | - } |
|
94 | - |
|
95 | - $address_fields = apply_filters( 'getpaid_admin_edit_invoice_address_fields', $address_fields, $invoice ); |
|
96 | - ?> |
|
19 | + /** |
|
20 | + * Output the metabox. |
|
21 | + * |
|
22 | + * @param WP_Post $post |
|
23 | + */ |
|
24 | + public static function output( $post ) { |
|
25 | + |
|
26 | + // Prepare the invoice. |
|
27 | + $invoice = new WPInv_Invoice( $post ); |
|
28 | + $customer = $invoice->exists() ? $invoice->get_user_id( 'edit' ) : get_current_user_id(); |
|
29 | + $customer = new WP_User( $customer ); |
|
30 | + $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email ); |
|
31 | + wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' ); |
|
32 | + |
|
33 | + // Address fields. |
|
34 | + $address_fields = array( |
|
35 | + 'first_name' => array( |
|
36 | + 'label' => __( 'First Name', 'invoicing' ), |
|
37 | + 'type' => 'text', |
|
38 | + ), |
|
39 | + 'last_name' => array( |
|
40 | + 'label' => __( 'Last Name', 'invoicing' ), |
|
41 | + 'type' => 'text', |
|
42 | + ), |
|
43 | + 'company' => array( |
|
44 | + 'label' => __( 'Company', 'invoicing' ), |
|
45 | + 'type' => 'text', |
|
46 | + 'class' => 'getpaid-recalculate-prices-on-change', |
|
47 | + ), |
|
48 | + 'vat_number' => array( |
|
49 | + 'label' => __( 'VAT Number', 'invoicing' ), |
|
50 | + 'type' => 'text', |
|
51 | + ), |
|
52 | + 'address' => array( |
|
53 | + 'label' => __( 'Address', 'invoicing' ), |
|
54 | + 'type' => 'text', |
|
55 | + ), |
|
56 | + 'city' => array( |
|
57 | + 'label' => __( 'City', 'invoicing' ), |
|
58 | + 'type' => 'text', |
|
59 | + ), |
|
60 | + 'country' => array( |
|
61 | + 'label' => __( 'Country', 'invoicing' ), |
|
62 | + 'type' => 'select', |
|
63 | + 'class' => 'getpaid-recalculate-prices-on-change', |
|
64 | + 'options' => wpinv_get_country_list(), |
|
65 | + 'placeholder' => __( 'Choose a country', 'invoicing' ), |
|
66 | + ), |
|
67 | + 'state' => array( |
|
68 | + 'label' => __( 'State', 'invoicing' ), |
|
69 | + 'type' => 'text', |
|
70 | + 'class' => 'getpaid-recalculate-prices-on-change', |
|
71 | + ), |
|
72 | + 'zip' => array( |
|
73 | + 'label' => __( 'Zip', 'invoicing' ), |
|
74 | + 'type' => 'text', |
|
75 | + ), |
|
76 | + 'phone' => array( |
|
77 | + 'label' => __( 'Phone', 'invoicing' ), |
|
78 | + 'type' => 'text', |
|
79 | + ), |
|
80 | + ); |
|
81 | + |
|
82 | + $states = wpinv_get_country_states( $invoice->get_country( 'edit' ) ); |
|
83 | + |
|
84 | + if ( ! empty( $states ) ) { |
|
85 | + $address_fields['state']['type'] = 'select'; |
|
86 | + $address_fields['state']['options'] = $states; |
|
87 | + $address_fields['state']['placeholder'] = __( 'Choose a state', 'invoicing' ); |
|
88 | + } |
|
89 | + |
|
90 | + // Maybe remove the VAT field. |
|
91 | + if ( ! wpinv_use_taxes() ) { |
|
92 | + unset( $address_fields['vat_number'] ); |
|
93 | + } |
|
94 | + |
|
95 | + $address_fields = apply_filters( 'getpaid_admin_edit_invoice_address_fields', $address_fields, $invoice ); |
|
96 | + ?> |
|
97 | 97 | |
98 | 98 | <style> |
99 | 99 | #wpinv-address label { |
@@ -118,19 +118,19 @@ discard block |
||
118 | 118 | <div id="getpaid-invoice-email-wrapper" class="d-none"> |
119 | 119 | <input type="hidden" id="getpaid-invoice-create-new-user" name="wpinv_new_user" value="" /> |
120 | 120 | <?php |
121 | - aui()->input( |
|
122 | - array( |
|
123 | - 'type' => 'text', |
|
124 | - 'id' => 'getpaid-invoice-new-user-email', |
|
125 | - 'name' => 'wpinv_email', |
|
126 | - 'label' => __( 'Email', 'invoicing' ) . '<span class="required">*</span>', |
|
127 | - 'label_type' => 'vertical', |
|
128 | - 'placeholder' => '[email protected]', |
|
129 | - 'class' => 'form-control-sm', |
|
130 | - ), |
|
131 | - true |
|
132 | - ); |
|
133 | - ?> |
|
121 | + aui()->input( |
|
122 | + array( |
|
123 | + 'type' => 'text', |
|
124 | + 'id' => 'getpaid-invoice-new-user-email', |
|
125 | + 'name' => 'wpinv_email', |
|
126 | + 'label' => __( 'Email', 'invoicing' ) . '<span class="required">*</span>', |
|
127 | + 'label_type' => 'vertical', |
|
128 | + 'placeholder' => '[email protected]', |
|
129 | + 'class' => 'form-control-sm', |
|
130 | + ), |
|
131 | + true |
|
132 | + ); |
|
133 | + ?> |
|
134 | 134 | </div> |
135 | 135 | </div> |
136 | 136 | <div class="col-12 col-sm-6 form-group mb-3 mt-sm-4"> |
@@ -154,39 +154,39 @@ discard block |
||
154 | 154 | <div class="col-12 col-sm-6 getpaid-invoice-address-field__<?php echo esc_attr( $key ); ?>--wrapper"> |
155 | 155 | <?php |
156 | 156 | |
157 | - if ( 'select' === $field['type'] ) { |
|
158 | - aui()->select( |
|
159 | - array( |
|
160 | - 'id' => 'wpinv_' . $key, |
|
161 | - 'name' => 'wpinv_' . $key, |
|
162 | - 'label' => $field['label'], |
|
163 | - 'label_type' => 'vertical', |
|
164 | - 'placeholder' => isset( $field['placeholder'] ) ? $field['placeholder'] : '', |
|
165 | - 'class' => 'form-control-sm ' . ( isset( $field['class'] ) ? $field['class'] : '' ), |
|
166 | - 'value' => $invoice->get( $key, 'edit' ), |
|
167 | - 'options' => $field['options'], |
|
168 | - 'data-allow-clear' => 'false', |
|
169 | - 'select2' => true, |
|
170 | - ), |
|
171 | - true |
|
172 | - ); |
|
173 | - } else { |
|
174 | - aui()->input( |
|
175 | - array( |
|
176 | - 'type' => $field['type'], |
|
177 | - 'id' => 'wpinv_' . $key, |
|
178 | - 'name' => 'wpinv_' . $key, |
|
179 | - 'label' => $field['label'], |
|
180 | - 'label_type' => 'vertical', |
|
181 | - 'placeholder' => isset( $field['placeholder'] ) ? $field['placeholder'] : '', |
|
182 | - 'class' => 'form-control-sm ' . ( isset( $field['class'] ) ? $field['class'] : '' ), |
|
183 | - 'value' => $invoice->get( $key, 'edit' ), |
|
184 | - ), |
|
185 | - true |
|
186 | - ); |
|
187 | - } |
|
188 | - |
|
189 | - ?> |
|
157 | + if ( 'select' === $field['type'] ) { |
|
158 | + aui()->select( |
|
159 | + array( |
|
160 | + 'id' => 'wpinv_' . $key, |
|
161 | + 'name' => 'wpinv_' . $key, |
|
162 | + 'label' => $field['label'], |
|
163 | + 'label_type' => 'vertical', |
|
164 | + 'placeholder' => isset( $field['placeholder'] ) ? $field['placeholder'] : '', |
|
165 | + 'class' => 'form-control-sm ' . ( isset( $field['class'] ) ? $field['class'] : '' ), |
|
166 | + 'value' => $invoice->get( $key, 'edit' ), |
|
167 | + 'options' => $field['options'], |
|
168 | + 'data-allow-clear' => 'false', |
|
169 | + 'select2' => true, |
|
170 | + ), |
|
171 | + true |
|
172 | + ); |
|
173 | + } else { |
|
174 | + aui()->input( |
|
175 | + array( |
|
176 | + 'type' => $field['type'], |
|
177 | + 'id' => 'wpinv_' . $key, |
|
178 | + 'name' => 'wpinv_' . $key, |
|
179 | + 'label' => $field['label'], |
|
180 | + 'label_type' => 'vertical', |
|
181 | + 'placeholder' => isset( $field['placeholder'] ) ? $field['placeholder'] : '', |
|
182 | + 'class' => 'form-control-sm ' . ( isset( $field['class'] ) ? $field['class'] : '' ), |
|
183 | + 'value' => $invoice->get( $key, 'edit' ), |
|
184 | + ), |
|
185 | + true |
|
186 | + ); |
|
187 | + } |
|
188 | + |
|
189 | + ?> |
|
190 | 190 | </div> |
191 | 191 | <?php endforeach; ?> |
192 | 192 | </div> |
@@ -197,48 +197,48 @@ discard block |
||
197 | 197 | <div class="row"> |
198 | 198 | <div class="col-12 col-sm-6"> |
199 | 199 | <?php |
200 | - aui()->select( |
|
201 | - array( |
|
202 | - 'id' => 'wpinv_template', |
|
203 | - 'name' => 'wpinv_template', |
|
204 | - 'label' => __( 'Template', 'invoicing' ), |
|
205 | - 'label_type' => 'vertical', |
|
206 | - 'placeholder' => __( 'Choose a template', 'invoicing' ), |
|
207 | - 'class' => 'form-control-sm', |
|
208 | - 'value' => $invoice->get_template( 'edit' ), |
|
209 | - 'options' => array( |
|
210 | - 'quantity' => __( 'Quantity', 'invoicing' ), |
|
211 | - 'hours' => __( 'Hours', 'invoicing' ), |
|
212 | - ), |
|
213 | - 'data-allow-clear' => 'false', |
|
214 | - 'select2' => true, |
|
215 | - ), |
|
216 | - true |
|
217 | - ); |
|
218 | - ?> |
|
200 | + aui()->select( |
|
201 | + array( |
|
202 | + 'id' => 'wpinv_template', |
|
203 | + 'name' => 'wpinv_template', |
|
204 | + 'label' => __( 'Template', 'invoicing' ), |
|
205 | + 'label_type' => 'vertical', |
|
206 | + 'placeholder' => __( 'Choose a template', 'invoicing' ), |
|
207 | + 'class' => 'form-control-sm', |
|
208 | + 'value' => $invoice->get_template( 'edit' ), |
|
209 | + 'options' => array( |
|
210 | + 'quantity' => __( 'Quantity', 'invoicing' ), |
|
211 | + 'hours' => __( 'Hours', 'invoicing' ), |
|
212 | + ), |
|
213 | + 'data-allow-clear' => 'false', |
|
214 | + 'select2' => true, |
|
215 | + ), |
|
216 | + true |
|
217 | + ); |
|
218 | + ?> |
|
219 | 219 | </div> |
220 | 220 | <div class="col-12 col-sm-6"> |
221 | 221 | <?php |
222 | 222 | |
223 | - // Set currency. |
|
224 | - aui()->select( |
|
225 | - array( |
|
226 | - 'id' => 'wpinv_currency', |
|
227 | - 'name' => 'wpinv_currency', |
|
228 | - 'label' => __( 'Currency', 'invoicing' ), |
|
229 | - 'label_type' => 'vertical', |
|
230 | - 'placeholder' => __( 'Select Invoice Currency', 'invoicing' ), |
|
231 | - 'class' => 'form-control-sm getpaid-recalculate-prices-on-change', |
|
232 | - 'value' => $invoice->get_currency( 'edit' ), |
|
233 | - 'required' => false, |
|
234 | - 'data-allow-clear' => 'false', |
|
235 | - 'select2' => true, |
|
236 | - 'options' => wpinv_get_currencies(), |
|
237 | - ), |
|
238 | - true |
|
239 | - ); |
|
240 | - |
|
241 | - ?> |
|
223 | + // Set currency. |
|
224 | + aui()->select( |
|
225 | + array( |
|
226 | + 'id' => 'wpinv_currency', |
|
227 | + 'name' => 'wpinv_currency', |
|
228 | + 'label' => __( 'Currency', 'invoicing' ), |
|
229 | + 'label_type' => 'vertical', |
|
230 | + 'placeholder' => __( 'Select Invoice Currency', 'invoicing' ), |
|
231 | + 'class' => 'form-control-sm getpaid-recalculate-prices-on-change', |
|
232 | + 'value' => $invoice->get_currency( 'edit' ), |
|
233 | + 'required' => false, |
|
234 | + 'data-allow-clear' => 'false', |
|
235 | + 'select2' => true, |
|
236 | + 'options' => wpinv_get_currencies(), |
|
237 | + ), |
|
238 | + true |
|
239 | + ); |
|
240 | + |
|
241 | + ?> |
|
242 | 242 | </div> |
243 | 243 | </div> |
244 | 244 | |
@@ -248,123 +248,123 @@ discard block |
||
248 | 248 | <div class="row"> |
249 | 249 | <div class="col-12 col-sm-6"> |
250 | 250 | <?php |
251 | - aui()->input( |
|
252 | - array( |
|
253 | - 'type' => 'text', |
|
254 | - 'id' => 'wpinv_company_id', |
|
255 | - 'name' => 'wpinv_company_id', |
|
256 | - 'label' => __( 'Company ID', 'invoicing' ), |
|
257 | - 'label_type' => 'vertical', |
|
258 | - 'placeholder' => '', |
|
259 | - 'class' => 'form-control-sm', |
|
260 | - 'value' => $invoice->get_company_id( 'edit' ), |
|
261 | - ), |
|
262 | - true |
|
263 | - ); |
|
264 | - ?> |
|
251 | + aui()->input( |
|
252 | + array( |
|
253 | + 'type' => 'text', |
|
254 | + 'id' => 'wpinv_company_id', |
|
255 | + 'name' => 'wpinv_company_id', |
|
256 | + 'label' => __( 'Company ID', 'invoicing' ), |
|
257 | + 'label_type' => 'vertical', |
|
258 | + 'placeholder' => '', |
|
259 | + 'class' => 'form-control-sm', |
|
260 | + 'value' => $invoice->get_company_id( 'edit' ), |
|
261 | + ), |
|
262 | + true |
|
263 | + ); |
|
264 | + ?> |
|
265 | 265 | </div> |
266 | 266 | </div> |
267 | 267 | |
268 | 268 | <?php do_action( 'getpaid_after_metabox_invoice_address', $invoice ); ?> |
269 | 269 | </div> |
270 | 270 | <?php |
271 | - } |
|
272 | - |
|
273 | - /** |
|
274 | - * Save meta box data. |
|
275 | - * |
|
276 | - * @param int $post_id |
|
277 | - * @param array $posted the posted data. |
|
278 | - */ |
|
279 | - public static function save( $post_id, $posted ) { |
|
280 | - |
|
281 | - // Prepare the invoice. |
|
282 | - $invoice = new WPInv_Invoice( $post_id ); |
|
283 | - |
|
284 | - // Load new data. |
|
285 | - $invoice->set_props( |
|
286 | - array( |
|
287 | - 'template' => isset( $posted['wpinv_template'] ) ? wpinv_clean( $posted['wpinv_template'] ) : null, |
|
288 | - 'email_cc' => isset( $posted['wpinv_cc'] ) ? wpinv_clean( $posted['wpinv_cc'] ) : null, |
|
289 | - 'disable_taxes' => ! empty( $posted['disable_taxes'] ), |
|
290 | - 'currency' => isset( $posted['wpinv_currency'] ) ? wpinv_clean( $posted['wpinv_currency'] ) : null, |
|
291 | - 'gateway' => ( $invoice->needs_payment() && isset( $posted['wpinv_gateway'] ) ) ? wpinv_clean( $posted['wpinv_gateway'] ) : null, |
|
292 | - 'address' => isset( $posted['wpinv_address'] ) ? wpinv_clean( $posted['wpinv_address'] ) : null, |
|
293 | - 'vat_number' => isset( $posted['wpinv_vat_number'] ) ? wpinv_clean( $posted['wpinv_vat_number'] ) : null, |
|
294 | - 'company' => isset( $posted['wpinv_company'] ) ? wpinv_clean( $posted['wpinv_company'] ) : null, |
|
295 | - 'company_id' => isset( $posted['wpinv_company_id'] ) ? wpinv_clean( $posted['wpinv_company_id'] ) : null, |
|
296 | - 'zip' => isset( $posted['wpinv_zip'] ) ? wpinv_clean( $posted['wpinv_zip'] ) : null, |
|
297 | - 'state' => isset( $posted['wpinv_state'] ) ? wpinv_clean( $posted['wpinv_state'] ) : null, |
|
298 | - 'city' => isset( $posted['wpinv_city'] ) ? wpinv_clean( $posted['wpinv_city'] ) : null, |
|
299 | - 'country' => isset( $posted['wpinv_country'] ) ? wpinv_clean( $posted['wpinv_country'] ) : null, |
|
300 | - 'phone' => isset( $posted['wpinv_phone'] ) ? wpinv_clean( $posted['wpinv_phone'] ) : null, |
|
301 | - 'first_name' => isset( $posted['wpinv_first_name'] ) ? wpinv_clean( $posted['wpinv_first_name'] ) : null, |
|
302 | - 'last_name' => isset( $posted['wpinv_last_name'] ) ? wpinv_clean( $posted['wpinv_last_name'] ) : null, |
|
303 | - 'author' => isset( $posted['post_author_override'] ) ? wpinv_clean( $posted['post_author_override'] ) : null, |
|
304 | - 'date_created' => isset( $posted['date_created'] ) ? wpinv_clean( $posted['date_created'] ) : null, |
|
305 | - 'date_completed' => isset( $posted['wpinv_date_completed'] ) ? wpinv_clean( $posted['wpinv_date_completed'] ) : null, |
|
306 | - 'due_date' => isset( $posted['wpinv_due_date'] ) ? wpinv_clean( $posted['wpinv_due_date'] ) : null, |
|
307 | - 'number' => isset( $posted['wpinv_number'] ) ? wpinv_clean( $posted['wpinv_number'] ) : null, |
|
308 | - 'status' => isset( $posted['wpinv_status'] ) ? wpinv_clean( $posted['wpinv_status'] ) : null, |
|
309 | - ) |
|
310 | - ); |
|
311 | - |
|
312 | - // Discount code. |
|
313 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
314 | - |
|
315 | - if ( isset( $posted['wpinv_discount_code'] ) ) { |
|
316 | - $invoice->set_discount_code( wpinv_clean( $posted['wpinv_discount_code'] ) ); |
|
317 | - } |
|
318 | - |
|
319 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
320 | - if ( $discount->exists() ) { |
|
321 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
322 | - } else { |
|
323 | - $invoice->remove_discount( 'discount_code' ); |
|
324 | - } |
|
325 | - |
|
326 | - // Recalculate totals. |
|
327 | - $invoice->recalculate_total(); |
|
328 | - |
|
329 | - } |
|
330 | - |
|
331 | - // If we're creating a new user... |
|
332 | - if ( ! empty( $posted['wpinv_new_user'] ) && is_email( stripslashes( $posted['wpinv_email'] ) ) ) { |
|
333 | - |
|
334 | - // Attempt to create the user. |
|
335 | - $user = wpinv_create_user( sanitize_email( stripslashes( $posted['wpinv_email'] ) ), $invoice->get_first_name() . $invoice->get_last_name() ); |
|
336 | - |
|
337 | - // If successful, update the invoice author. |
|
338 | - if ( is_numeric( $user ) ) { |
|
339 | - $invoice->set_author( $user ); |
|
340 | - } else { |
|
341 | - wpinv_error_log( $user->get_error_message(), __( 'Invoice add new user', 'invoicing' ), __FILE__, __LINE__ ); |
|
342 | - } |
|
343 | - } |
|
344 | - |
|
345 | - // Do not send new invoice notifications. |
|
346 | - $GLOBALS['wpinv_skip_invoice_notification'] = true; |
|
347 | - |
|
348 | - // Save the invoice. |
|
349 | - $invoice->save(); |
|
350 | - |
|
351 | - // Save the user address. |
|
352 | - getpaid_save_invoice_user_address( $invoice ); |
|
353 | - |
|
354 | - // Undo do not send new invoice notifications. |
|
355 | - $GLOBALS['wpinv_skip_invoice_notification'] = false; |
|
356 | - |
|
357 | - // (Maybe) send new user notification. |
|
358 | - $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
359 | - if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ) ) ) { |
|
360 | - wp_send_new_user_notifications( $user, 'user' ); |
|
361 | - } |
|
362 | - |
|
363 | - if ( ! empty( $posted['send_to_customer'] ) && ! $invoice->is_draft() ) { |
|
364 | - getpaid()->get( 'invoice_emails' )->user_invoice( $invoice, true ); |
|
365 | - } |
|
366 | - |
|
367 | - // Fires after an invoice is saved. |
|
368 | - do_action( 'wpinv_invoice_metabox_saved', $invoice ); |
|
369 | - } |
|
271 | + } |
|
272 | + |
|
273 | + /** |
|
274 | + * Save meta box data. |
|
275 | + * |
|
276 | + * @param int $post_id |
|
277 | + * @param array $posted the posted data. |
|
278 | + */ |
|
279 | + public static function save( $post_id, $posted ) { |
|
280 | + |
|
281 | + // Prepare the invoice. |
|
282 | + $invoice = new WPInv_Invoice( $post_id ); |
|
283 | + |
|
284 | + // Load new data. |
|
285 | + $invoice->set_props( |
|
286 | + array( |
|
287 | + 'template' => isset( $posted['wpinv_template'] ) ? wpinv_clean( $posted['wpinv_template'] ) : null, |
|
288 | + 'email_cc' => isset( $posted['wpinv_cc'] ) ? wpinv_clean( $posted['wpinv_cc'] ) : null, |
|
289 | + 'disable_taxes' => ! empty( $posted['disable_taxes'] ), |
|
290 | + 'currency' => isset( $posted['wpinv_currency'] ) ? wpinv_clean( $posted['wpinv_currency'] ) : null, |
|
291 | + 'gateway' => ( $invoice->needs_payment() && isset( $posted['wpinv_gateway'] ) ) ? wpinv_clean( $posted['wpinv_gateway'] ) : null, |
|
292 | + 'address' => isset( $posted['wpinv_address'] ) ? wpinv_clean( $posted['wpinv_address'] ) : null, |
|
293 | + 'vat_number' => isset( $posted['wpinv_vat_number'] ) ? wpinv_clean( $posted['wpinv_vat_number'] ) : null, |
|
294 | + 'company' => isset( $posted['wpinv_company'] ) ? wpinv_clean( $posted['wpinv_company'] ) : null, |
|
295 | + 'company_id' => isset( $posted['wpinv_company_id'] ) ? wpinv_clean( $posted['wpinv_company_id'] ) : null, |
|
296 | + 'zip' => isset( $posted['wpinv_zip'] ) ? wpinv_clean( $posted['wpinv_zip'] ) : null, |
|
297 | + 'state' => isset( $posted['wpinv_state'] ) ? wpinv_clean( $posted['wpinv_state'] ) : null, |
|
298 | + 'city' => isset( $posted['wpinv_city'] ) ? wpinv_clean( $posted['wpinv_city'] ) : null, |
|
299 | + 'country' => isset( $posted['wpinv_country'] ) ? wpinv_clean( $posted['wpinv_country'] ) : null, |
|
300 | + 'phone' => isset( $posted['wpinv_phone'] ) ? wpinv_clean( $posted['wpinv_phone'] ) : null, |
|
301 | + 'first_name' => isset( $posted['wpinv_first_name'] ) ? wpinv_clean( $posted['wpinv_first_name'] ) : null, |
|
302 | + 'last_name' => isset( $posted['wpinv_last_name'] ) ? wpinv_clean( $posted['wpinv_last_name'] ) : null, |
|
303 | + 'author' => isset( $posted['post_author_override'] ) ? wpinv_clean( $posted['post_author_override'] ) : null, |
|
304 | + 'date_created' => isset( $posted['date_created'] ) ? wpinv_clean( $posted['date_created'] ) : null, |
|
305 | + 'date_completed' => isset( $posted['wpinv_date_completed'] ) ? wpinv_clean( $posted['wpinv_date_completed'] ) : null, |
|
306 | + 'due_date' => isset( $posted['wpinv_due_date'] ) ? wpinv_clean( $posted['wpinv_due_date'] ) : null, |
|
307 | + 'number' => isset( $posted['wpinv_number'] ) ? wpinv_clean( $posted['wpinv_number'] ) : null, |
|
308 | + 'status' => isset( $posted['wpinv_status'] ) ? wpinv_clean( $posted['wpinv_status'] ) : null, |
|
309 | + ) |
|
310 | + ); |
|
311 | + |
|
312 | + // Discount code. |
|
313 | + if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
314 | + |
|
315 | + if ( isset( $posted['wpinv_discount_code'] ) ) { |
|
316 | + $invoice->set_discount_code( wpinv_clean( $posted['wpinv_discount_code'] ) ); |
|
317 | + } |
|
318 | + |
|
319 | + $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
320 | + if ( $discount->exists() ) { |
|
321 | + $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
322 | + } else { |
|
323 | + $invoice->remove_discount( 'discount_code' ); |
|
324 | + } |
|
325 | + |
|
326 | + // Recalculate totals. |
|
327 | + $invoice->recalculate_total(); |
|
328 | + |
|
329 | + } |
|
330 | + |
|
331 | + // If we're creating a new user... |
|
332 | + if ( ! empty( $posted['wpinv_new_user'] ) && is_email( stripslashes( $posted['wpinv_email'] ) ) ) { |
|
333 | + |
|
334 | + // Attempt to create the user. |
|
335 | + $user = wpinv_create_user( sanitize_email( stripslashes( $posted['wpinv_email'] ) ), $invoice->get_first_name() . $invoice->get_last_name() ); |
|
336 | + |
|
337 | + // If successful, update the invoice author. |
|
338 | + if ( is_numeric( $user ) ) { |
|
339 | + $invoice->set_author( $user ); |
|
340 | + } else { |
|
341 | + wpinv_error_log( $user->get_error_message(), __( 'Invoice add new user', 'invoicing' ), __FILE__, __LINE__ ); |
|
342 | + } |
|
343 | + } |
|
344 | + |
|
345 | + // Do not send new invoice notifications. |
|
346 | + $GLOBALS['wpinv_skip_invoice_notification'] = true; |
|
347 | + |
|
348 | + // Save the invoice. |
|
349 | + $invoice->save(); |
|
350 | + |
|
351 | + // Save the user address. |
|
352 | + getpaid_save_invoice_user_address( $invoice ); |
|
353 | + |
|
354 | + // Undo do not send new invoice notifications. |
|
355 | + $GLOBALS['wpinv_skip_invoice_notification'] = false; |
|
356 | + |
|
357 | + // (Maybe) send new user notification. |
|
358 | + $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
359 | + if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ) ) ) { |
|
360 | + wp_send_new_user_notifications( $user, 'user' ); |
|
361 | + } |
|
362 | + |
|
363 | + if ( ! empty( $posted['send_to_customer'] ) && ! $invoice->is_draft() ) { |
|
364 | + getpaid()->get( 'invoice_emails' )->user_invoice( $invoice, true ); |
|
365 | + } |
|
366 | + |
|
367 | + // Fires after an invoice is saved. |
|
368 | + do_action( 'wpinv_invoice_metabox_saved', $invoice ); |
|
369 | + } |
|
370 | 370 | } |
@@ -12,184 +12,184 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Checkout { |
14 | 14 | |
15 | - /** |
|
16 | - * @var GetPaid_Payment_Form_Submission |
|
17 | - */ |
|
18 | - protected $payment_form_submission; |
|
19 | - |
|
20 | - /** |
|
21 | - * Class constructor. |
|
22 | - * |
|
23 | - * @param GetPaid_Payment_Form_Submission $submission |
|
24 | - */ |
|
25 | - public function __construct( $submission ) { |
|
26 | - $this->payment_form_submission = $submission; |
|
27 | - } |
|
28 | - |
|
29 | - /** |
|
30 | - * Processes the checkout. |
|
31 | - * |
|
32 | - */ |
|
33 | - public function process_checkout() { |
|
34 | - |
|
35 | - // Validate the submission. |
|
36 | - $this->validate_submission(); |
|
37 | - |
|
38 | - // Prepare the invoice. |
|
39 | - $items = $this->get_submission_items(); |
|
40 | - $invoice = $this->get_submission_invoice(); |
|
41 | - $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
42 | - $prepared = $this->prepare_submission_data_for_saving(); |
|
43 | - |
|
44 | - $this->prepare_billing_info( $invoice ); |
|
45 | - |
|
46 | - $shipping = $this->prepare_shipping_info( $invoice ); |
|
47 | - |
|
48 | - // Save the invoice. |
|
49 | - $invoice->set_is_viewed( true ); |
|
50 | - $invoice->recalculate_total(); |
|
15 | + /** |
|
16 | + * @var GetPaid_Payment_Form_Submission |
|
17 | + */ |
|
18 | + protected $payment_form_submission; |
|
19 | + |
|
20 | + /** |
|
21 | + * Class constructor. |
|
22 | + * |
|
23 | + * @param GetPaid_Payment_Form_Submission $submission |
|
24 | + */ |
|
25 | + public function __construct( $submission ) { |
|
26 | + $this->payment_form_submission = $submission; |
|
27 | + } |
|
28 | + |
|
29 | + /** |
|
30 | + * Processes the checkout. |
|
31 | + * |
|
32 | + */ |
|
33 | + public function process_checkout() { |
|
34 | + |
|
35 | + // Validate the submission. |
|
36 | + $this->validate_submission(); |
|
37 | + |
|
38 | + // Prepare the invoice. |
|
39 | + $items = $this->get_submission_items(); |
|
40 | + $invoice = $this->get_submission_invoice(); |
|
41 | + $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
42 | + $prepared = $this->prepare_submission_data_for_saving(); |
|
43 | + |
|
44 | + $this->prepare_billing_info( $invoice ); |
|
45 | + |
|
46 | + $shipping = $this->prepare_shipping_info( $invoice ); |
|
47 | + |
|
48 | + // Save the invoice. |
|
49 | + $invoice->set_is_viewed( true ); |
|
50 | + $invoice->recalculate_total(); |
|
51 | 51 | $invoice->save(); |
52 | 52 | |
53 | - do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
53 | + do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
54 | 54 | |
55 | - // Send to the gateway. |
|
56 | - $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
57 | - } |
|
55 | + // Send to the gateway. |
|
56 | + $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * Validates the submission. |
|
61 | - * |
|
62 | - */ |
|
63 | - protected function validate_submission() { |
|
59 | + /** |
|
60 | + * Validates the submission. |
|
61 | + * |
|
62 | + */ |
|
63 | + protected function validate_submission() { |
|
64 | 64 | |
65 | - $submission = $this->payment_form_submission; |
|
66 | - $data = $submission->get_data(); |
|
65 | + $submission = $this->payment_form_submission; |
|
66 | + $data = $submission->get_data(); |
|
67 | 67 | |
68 | - // Do we have an error? |
|
68 | + // Do we have an error? |
|
69 | 69 | if ( ! empty( $submission->last_error ) ) { |
70 | - wp_send_json_error( $submission->last_error ); |
|
70 | + wp_send_json_error( $submission->last_error ); |
|
71 | 71 | } |
72 | 72 | |
73 | - // We need a billing email. |
|
73 | + // We need a billing email. |
|
74 | 74 | if ( ! $submission->has_billing_email() ) { |
75 | 75 | wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
76 | - } |
|
76 | + } |
|
77 | 77 | |
78 | - // Non-recurring gateways should not be allowed to process recurring invoices. |
|
79 | - if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
80 | - wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
81 | - } |
|
78 | + // Non-recurring gateways should not be allowed to process recurring invoices. |
|
79 | + if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
80 | + wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
81 | + } |
|
82 | 82 | |
83 | - // Ensure the gateway is active. |
|
84 | - if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
85 | - wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
86 | - } |
|
83 | + // Ensure the gateway is active. |
|
84 | + if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
85 | + wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
86 | + } |
|
87 | 87 | |
88 | - // Clear any existing errors. |
|
89 | - wpinv_clear_errors(); |
|
88 | + // Clear any existing errors. |
|
89 | + wpinv_clear_errors(); |
|
90 | 90 | |
91 | - // Allow themes and plugins to hook to errors |
|
92 | - do_action( 'getpaid_checkout_error_checks', $submission ); |
|
91 | + // Allow themes and plugins to hook to errors |
|
92 | + do_action( 'getpaid_checkout_error_checks', $submission ); |
|
93 | 93 | |
94 | - // Do we have any errors? |
|
94 | + // Do we have any errors? |
|
95 | 95 | if ( wpinv_get_errors() ) { |
96 | 96 | wp_send_json_error( getpaid_get_errors_html() ); |
97 | - } |
|
97 | + } |
|
98 | 98 | |
99 | - } |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Retrieves submission items. |
|
103 | - * |
|
104 | - * @return GetPaid_Form_Item[] |
|
105 | - */ |
|
106 | - protected function get_submission_items() { |
|
101 | + /** |
|
102 | + * Retrieves submission items. |
|
103 | + * |
|
104 | + * @return GetPaid_Form_Item[] |
|
105 | + */ |
|
106 | + protected function get_submission_items() { |
|
107 | 107 | |
108 | - $items = $this->payment_form_submission->get_items(); |
|
108 | + $items = $this->payment_form_submission->get_items(); |
|
109 | 109 | |
110 | 110 | // Ensure that we have items. |
111 | 111 | if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) { |
112 | 112 | wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) ); |
113 | - } |
|
114 | - |
|
115 | - return $items; |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * Retrieves submission invoice. |
|
120 | - * |
|
121 | - * @return WPInv_Invoice |
|
122 | - */ |
|
123 | - protected function get_submission_invoice() { |
|
124 | - $submission = $this->payment_form_submission; |
|
125 | - |
|
126 | - if ( ! $submission->has_invoice() ) { |
|
127 | - $invoice = new WPInv_Invoice(); |
|
128 | - $invoice->set_created_via( 'payment_form' ); |
|
129 | - return $invoice; |
|
130 | 113 | } |
131 | 114 | |
132 | - $invoice = $submission->get_invoice(); |
|
115 | + return $items; |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * Retrieves submission invoice. |
|
120 | + * |
|
121 | + * @return WPInv_Invoice |
|
122 | + */ |
|
123 | + protected function get_submission_invoice() { |
|
124 | + $submission = $this->payment_form_submission; |
|
133 | 125 | |
134 | - // Make sure that it is neither paid or refunded. |
|
135 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
136 | - wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
137 | - } |
|
126 | + if ( ! $submission->has_invoice() ) { |
|
127 | + $invoice = new WPInv_Invoice(); |
|
128 | + $invoice->set_created_via( 'payment_form' ); |
|
129 | + return $invoice; |
|
130 | + } |
|
138 | 131 | |
139 | - return $invoice; |
|
140 | - } |
|
132 | + $invoice = $submission->get_invoice(); |
|
141 | 133 | |
142 | - /** |
|
143 | - * Processes the submission invoice. |
|
144 | - * |
|
145 | - * @param WPInv_Invoice $invoice |
|
146 | - * @param GetPaid_Form_Item[] $items |
|
147 | - * @return WPInv_Invoice |
|
148 | - */ |
|
149 | - protected function process_submission_invoice( $invoice, $items ) { |
|
134 | + // Make sure that it is neither paid or refunded. |
|
135 | + if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
136 | + wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
137 | + } |
|
150 | 138 | |
151 | - $submission = $this->payment_form_submission; |
|
139 | + return $invoice; |
|
140 | + } |
|
152 | 141 | |
153 | - // Set-up the invoice details. |
|
154 | - $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
155 | - $invoice->set_user_id( $this->get_submission_customer() ); |
|
156 | - $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
142 | + /** |
|
143 | + * Processes the submission invoice. |
|
144 | + * |
|
145 | + * @param WPInv_Invoice $invoice |
|
146 | + * @param GetPaid_Form_Item[] $items |
|
147 | + * @return WPInv_Invoice |
|
148 | + */ |
|
149 | + protected function process_submission_invoice( $invoice, $items ) { |
|
150 | + |
|
151 | + $submission = $this->payment_form_submission; |
|
152 | + |
|
153 | + // Set-up the invoice details. |
|
154 | + $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
155 | + $invoice->set_user_id( $this->get_submission_customer() ); |
|
156 | + $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
157 | 157 | $invoice->set_items( $items ); |
158 | 158 | $invoice->set_fees( $submission->get_fees() ); |
159 | 159 | $invoice->set_taxes( $submission->get_taxes() ); |
160 | - $invoice->set_discounts( $submission->get_discounts() ); |
|
161 | - $invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) ); |
|
162 | - $invoice->set_currency( $submission->get_currency() ); |
|
160 | + $invoice->set_discounts( $submission->get_discounts() ); |
|
161 | + $invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) ); |
|
162 | + $invoice->set_currency( $submission->get_currency() ); |
|
163 | 163 | |
164 | - if ( $submission->has_shipping() ) { |
|
165 | - $invoice->set_shipping( $submission->get_shipping() ); |
|
166 | - } |
|
164 | + if ( $submission->has_shipping() ) { |
|
165 | + $invoice->set_shipping( $submission->get_shipping() ); |
|
166 | + } |
|
167 | 167 | |
168 | - $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
169 | - $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
168 | + $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
169 | + $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
170 | 170 | |
171 | - if ( $submission->has_discount_code() ) { |
|
171 | + if ( $submission->has_discount_code() ) { |
|
172 | 172 | $invoice->set_discount_code( $submission->get_discount_code() ); |
173 | - } |
|
174 | - |
|
175 | - getpaid_maybe_add_default_address( $invoice ); |
|
176 | - return $invoice; |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * Retrieves the submission's customer. |
|
181 | - * |
|
182 | - * @return int The customer id. |
|
183 | - */ |
|
184 | - protected function get_submission_customer() { |
|
185 | - $submission = $this->payment_form_submission; |
|
186 | - |
|
187 | - // If this is an existing invoice... |
|
188 | - if ( $submission->has_invoice() ) { |
|
189 | - return $submission->get_invoice()->get_user_id(); |
|
190 | - } |
|
191 | - |
|
192 | - // (Maybe) create the user. |
|
173 | + } |
|
174 | + |
|
175 | + getpaid_maybe_add_default_address( $invoice ); |
|
176 | + return $invoice; |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * Retrieves the submission's customer. |
|
181 | + * |
|
182 | + * @return int The customer id. |
|
183 | + */ |
|
184 | + protected function get_submission_customer() { |
|
185 | + $submission = $this->payment_form_submission; |
|
186 | + |
|
187 | + // If this is an existing invoice... |
|
188 | + if ( $submission->has_invoice() ) { |
|
189 | + return $submission->get_invoice()->get_user_id(); |
|
190 | + } |
|
191 | + |
|
192 | + // (Maybe) create the user. |
|
193 | 193 | $user = get_current_user_id(); |
194 | 194 | |
195 | 195 | if ( empty( $user ) ) { |
@@ -197,16 +197,16 @@ discard block |
||
197 | 197 | } |
198 | 198 | |
199 | 199 | if ( empty( $user ) ) { |
200 | - $name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) ); |
|
201 | - $name = implode( '', array_filter( $name ) ); |
|
200 | + $name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) ); |
|
201 | + $name = implode( '', array_filter( $name ) ); |
|
202 | 202 | $user = wpinv_create_user( $submission->get_billing_email(), $name ); |
203 | 203 | |
204 | - // (Maybe) send new user notification. |
|
205 | - $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
206 | - if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) { |
|
207 | - wp_send_new_user_notifications( $user, 'user' ); |
|
208 | - } |
|
209 | - } |
|
204 | + // (Maybe) send new user notification. |
|
205 | + $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
206 | + if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) { |
|
207 | + wp_send_new_user_notifications( $user, 'user' ); |
|
208 | + } |
|
209 | + } |
|
210 | 210 | |
211 | 211 | if ( is_wp_error( $user ) ) { |
212 | 212 | wp_send_json_error( $user->get_error_message() ); |
@@ -214,49 +214,49 @@ discard block |
||
214 | 214 | |
215 | 215 | if ( is_numeric( $user ) ) { |
216 | 216 | return $user; |
217 | - } |
|
217 | + } |
|
218 | 218 | |
219 | - return $user->ID; |
|
219 | + return $user->ID; |
|
220 | 220 | |
221 | - } |
|
221 | + } |
|
222 | 222 | |
223 | - /** |
|
223 | + /** |
|
224 | 224 | * Prepares submission data for saving to the database. |
225 | 225 | * |
226 | - * @return array |
|
226 | + * @return array |
|
227 | 227 | */ |
228 | 228 | public function prepare_submission_data_for_saving() { |
229 | 229 | |
230 | - $submission = $this->payment_form_submission; |
|
230 | + $submission = $this->payment_form_submission; |
|
231 | 231 | |
232 | - // Prepared submission details. |
|
232 | + // Prepared submission details. |
|
233 | 233 | $prepared = array( |
234 | - 'all' => array(), |
|
235 | - 'meta' => array(), |
|
236 | - ); |
|
234 | + 'all' => array(), |
|
235 | + 'meta' => array(), |
|
236 | + ); |
|
237 | 237 | |
238 | 238 | // Raw submission details. |
239 | - $data = $submission->get_data(); |
|
239 | + $data = $submission->get_data(); |
|
240 | 240 | |
241 | - // Loop through the submitted details. |
|
241 | + // Loop through the submitted details. |
|
242 | 242 | foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
243 | 243 | |
244 | - // Skip premade fields. |
|
244 | + // Skip premade fields. |
|
245 | 245 | if ( ! empty( $field['premade'] ) ) { |
246 | 246 | continue; |
247 | 247 | } |
248 | 248 | |
249 | - // Ensure address is provided. |
|
250 | - if ( 'address' === $field['type'] ) { |
|
249 | + // Ensure address is provided. |
|
250 | + if ( 'address' === $field['type'] ) { |
|
251 | 251 | $address_type = isset( $field['address_type'] ) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing'; |
252 | 252 | |
253 | - foreach ( $field['fields'] as $address_field ) { |
|
253 | + foreach ( $field['fields'] as $address_field ) { |
|
254 | 254 | |
255 | - if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
256 | - wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
257 | - } |
|
258 | - } |
|
259 | - } |
|
255 | + if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
256 | + wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
257 | + } |
|
258 | + } |
|
259 | + } |
|
260 | 260 | |
261 | 261 | // If it is required and not set, abort. |
262 | 262 | if ( ! $submission->is_required_field_set( $field ) ) { |
@@ -266,31 +266,31 @@ discard block |
||
266 | 266 | // Handle misc fields. |
267 | 267 | if ( isset( $data[ $field['id'] ] ) ) { |
268 | 268 | |
269 | - // Uploads. |
|
270 | - if ( 'file_upload' === $field['type'] ) { |
|
271 | - $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] ); |
|
269 | + // Uploads. |
|
270 | + if ( 'file_upload' === $field['type'] ) { |
|
271 | + $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] ); |
|
272 | 272 | |
273 | - if ( count( $data[ $field['id'] ] ) > $max_file_num ) { |
|
274 | - wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) ); |
|
275 | - } |
|
273 | + if ( count( $data[ $field['id'] ] ) > $max_file_num ) { |
|
274 | + wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) ); |
|
275 | + } |
|
276 | 276 | |
277 | - $value = array(); |
|
277 | + $value = array(); |
|
278 | 278 | |
279 | - foreach ( $data[ $field['id'] ] as $url => $name ) { |
|
280 | - $value[] = sprintf( |
|
281 | - '<a href="%s" target="_blank">%s</a>', |
|
282 | - esc_url_raw( $url ), |
|
283 | - esc_html( $name ) |
|
284 | - ); |
|
285 | - } |
|
279 | + foreach ( $data[ $field['id'] ] as $url => $name ) { |
|
280 | + $value[] = sprintf( |
|
281 | + '<a href="%s" target="_blank">%s</a>', |
|
282 | + esc_url_raw( $url ), |
|
283 | + esc_html( $name ) |
|
284 | + ); |
|
285 | + } |
|
286 | 286 | |
287 | - $value = implode( ' | ', $value ); |
|
287 | + $value = implode( ' | ', $value ); |
|
288 | 288 | |
289 | - } elseif ( 'checkbox' === $field['type'] ) { |
|
290 | - $value = ! empty( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' ); |
|
291 | - } else { |
|
292 | - $value = wp_kses_post( $data[ $field['id'] ] ); |
|
293 | - } |
|
289 | + } elseif ( 'checkbox' === $field['type'] ) { |
|
290 | + $value = ! empty( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' ); |
|
291 | + } else { |
|
292 | + $value = wp_kses_post( $data[ $field['id'] ] ); |
|
293 | + } |
|
294 | 294 | |
295 | 295 | $label = $field['id']; |
296 | 296 | |
@@ -298,192 +298,192 @@ discard block |
||
298 | 298 | $label = $field['label']; |
299 | 299 | } |
300 | 300 | |
301 | - if ( ! empty( $field['add_meta'] ) ) { |
|
302 | - $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
303 | - } |
|
304 | - $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
301 | + if ( ! empty( $field['add_meta'] ) ) { |
|
302 | + $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
303 | + } |
|
304 | + $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
305 | 305 | |
306 | 306 | } |
307 | - } |
|
307 | + } |
|
308 | 308 | |
309 | - return $prepared; |
|
309 | + return $prepared; |
|
310 | 310 | |
311 | - } |
|
311 | + } |
|
312 | 312 | |
313 | - /** |
|
313 | + /** |
|
314 | 314 | * Retrieves address details. |
315 | 315 | * |
316 | - * @return array |
|
317 | - * @param WPInv_Invoice $invoice |
|
318 | - * @param string $type |
|
316 | + * @return array |
|
317 | + * @param WPInv_Invoice $invoice |
|
318 | + * @param string $type |
|
319 | 319 | */ |
320 | 320 | public function prepare_address_details( $invoice, $type = 'billing' ) { |
321 | 321 | |
322 | - $data = $this->payment_form_submission->get_data(); |
|
323 | - $type = sanitize_key( $type ); |
|
324 | - $address = array(); |
|
325 | - $prepared = array(); |
|
322 | + $data = $this->payment_form_submission->get_data(); |
|
323 | + $type = sanitize_key( $type ); |
|
324 | + $address = array(); |
|
325 | + $prepared = array(); |
|
326 | 326 | |
327 | - if ( ! empty( $data[ $type ] ) ) { |
|
328 | - $address = $data[ $type ]; |
|
329 | - } |
|
327 | + if ( ! empty( $data[ $type ] ) ) { |
|
328 | + $address = $data[ $type ]; |
|
329 | + } |
|
330 | 330 | |
331 | - // Clean address details. |
|
332 | - foreach ( $address as $key => $value ) { |
|
333 | - $key = sanitize_key( $key ); |
|
334 | - $key = str_replace( 'wpinv_', '', $key ); |
|
335 | - $value = wpinv_clean( $value ); |
|
336 | - $prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
337 | - } |
|
331 | + // Clean address details. |
|
332 | + foreach ( $address as $key => $value ) { |
|
333 | + $key = sanitize_key( $key ); |
|
334 | + $key = str_replace( 'wpinv_', '', $key ); |
|
335 | + $value = wpinv_clean( $value ); |
|
336 | + $prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
337 | + } |
|
338 | 338 | |
339 | - // Filter address details. |
|
340 | - $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
339 | + // Filter address details. |
|
340 | + $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
341 | 341 | |
342 | - // Remove non-whitelisted values. |
|
343 | - return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
342 | + // Remove non-whitelisted values. |
|
343 | + return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
344 | 344 | |
345 | - } |
|
345 | + } |
|
346 | 346 | |
347 | - /** |
|
347 | + /** |
|
348 | 348 | * Prepares the billing details. |
349 | 349 | * |
350 | - * @return array |
|
351 | - * @param WPInv_Invoice $invoice |
|
350 | + * @return array |
|
351 | + * @param WPInv_Invoice $invoice |
|
352 | 352 | */ |
353 | 353 | protected function prepare_billing_info( &$invoice ) { |
354 | 354 | |
355 | - $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
355 | + $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
356 | 356 | |
357 | - // Update the invoice with the billing details. |
|
358 | - $invoice->set_props( $billing_address ); |
|
357 | + // Update the invoice with the billing details. |
|
358 | + $invoice->set_props( $billing_address ); |
|
359 | 359 | |
360 | - } |
|
360 | + } |
|
361 | 361 | |
362 | - /** |
|
362 | + /** |
|
363 | 363 | * Prepares the shipping details. |
364 | 364 | * |
365 | - * @return array |
|
366 | - * @param WPInv_Invoice $invoice |
|
365 | + * @return array |
|
366 | + * @param WPInv_Invoice $invoice |
|
367 | 367 | */ |
368 | 368 | protected function prepare_shipping_info( $invoice ) { |
369 | 369 | |
370 | - $data = $this->payment_form_submission->get_data(); |
|
370 | + $data = $this->payment_form_submission->get_data(); |
|
371 | 371 | |
372 | - if ( empty( $data['same-shipping-address'] ) ) { |
|
373 | - return $this->prepare_address_details( $invoice, 'shipping' ); |
|
374 | - } |
|
372 | + if ( empty( $data['same-shipping-address'] ) ) { |
|
373 | + return $this->prepare_address_details( $invoice, 'shipping' ); |
|
374 | + } |
|
375 | 375 | |
376 | - return $this->prepare_address_details( $invoice, 'billing' ); |
|
376 | + return $this->prepare_address_details( $invoice, 'billing' ); |
|
377 | 377 | |
378 | - } |
|
378 | + } |
|
379 | 379 | |
380 | - /** |
|
381 | - * Confirms the submission is valid and send users to the gateway. |
|
382 | - * |
|
383 | - * @param WPInv_Invoice $invoice |
|
384 | - * @param array $prepared_payment_form_data |
|
385 | - * @param array $shipping |
|
386 | - */ |
|
387 | - protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
380 | + /** |
|
381 | + * Confirms the submission is valid and send users to the gateway. |
|
382 | + * |
|
383 | + * @param WPInv_Invoice $invoice |
|
384 | + * @param array $prepared_payment_form_data |
|
385 | + * @param array $shipping |
|
386 | + */ |
|
387 | + protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
388 | 388 | |
389 | - // Ensure the invoice exists. |
|
389 | + // Ensure the invoice exists. |
|
390 | 390 | if ( ! $invoice->exists() ) { |
391 | 391 | wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) ); |
392 | 392 | } |
393 | 393 | |
394 | - // Save payment form data. |
|
395 | - $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
394 | + // Save payment form data. |
|
395 | + $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
396 | 396 | delete_post_meta( $invoice->get_id(), 'payment_form_data' ); |
397 | - delete_post_meta( $invoice->get_id(), 'additional_meta_data' ); |
|
398 | - if ( ! empty( $prepared_payment_form_data ) ) { |
|
397 | + delete_post_meta( $invoice->get_id(), 'additional_meta_data' ); |
|
398 | + if ( ! empty( $prepared_payment_form_data ) ) { |
|
399 | 399 | |
400 | - if ( ! empty( $prepared_payment_form_data['all'] ) ) { |
|
401 | - update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] ); |
|
402 | - } |
|
400 | + if ( ! empty( $prepared_payment_form_data['all'] ) ) { |
|
401 | + update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] ); |
|
402 | + } |
|
403 | 403 | |
404 | - if ( ! empty( $prepared_payment_form_data['meta'] ) ) { |
|
405 | - update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] ); |
|
406 | - } |
|
407 | - } |
|
404 | + if ( ! empty( $prepared_payment_form_data['meta'] ) ) { |
|
405 | + update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] ); |
|
406 | + } |
|
407 | + } |
|
408 | 408 | |
409 | - // Save payment form data. |
|
410 | - $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission ); |
|
409 | + // Save payment form data. |
|
410 | + $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission ); |
|
411 | 411 | if ( ! empty( $shipping ) ) { |
412 | 412 | update_post_meta( $invoice->get_id(), 'shipping_address', $shipping ); |
413 | - } |
|
413 | + } |
|
414 | 414 | |
415 | - // Backwards compatibility. |
|
415 | + // Backwards compatibility. |
|
416 | 416 | add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) ); |
417 | 417 | |
418 | - try { |
|
419 | - $this->process_payment( $invoice ); |
|
420 | - } catch ( Exception $e ) { |
|
421 | - wpinv_set_error( 'payment_error', $e->getMessage() ); |
|
422 | - } |
|
418 | + try { |
|
419 | + $this->process_payment( $invoice ); |
|
420 | + } catch ( Exception $e ) { |
|
421 | + wpinv_set_error( 'payment_error', $e->getMessage() ); |
|
422 | + } |
|
423 | 423 | |
424 | 424 | // If we are here, there was an error. |
425 | - wpinv_send_back_to_checkout( $invoice ); |
|
425 | + wpinv_send_back_to_checkout( $invoice ); |
|
426 | 426 | |
427 | - } |
|
427 | + } |
|
428 | 428 | |
429 | - /** |
|
430 | - * Processes the actual payment. |
|
431 | - * |
|
432 | - * @param WPInv_Invoice $invoice |
|
433 | - */ |
|
434 | - protected function process_payment( $invoice ) { |
|
429 | + /** |
|
430 | + * Processes the actual payment. |
|
431 | + * |
|
432 | + * @param WPInv_Invoice $invoice |
|
433 | + */ |
|
434 | + protected function process_payment( $invoice ) { |
|
435 | 435 | |
436 | - // Clear any checkout errors. |
|
437 | - wpinv_clear_errors(); |
|
436 | + // Clear any checkout errors. |
|
437 | + wpinv_clear_errors(); |
|
438 | 438 | |
439 | - // No need to send free invoices to the gateway. |
|
440 | - if ( $invoice->is_free() ) { |
|
441 | - $this->process_free_payment( $invoice ); |
|
442 | - } |
|
439 | + // No need to send free invoices to the gateway. |
|
440 | + if ( $invoice->is_free() ) { |
|
441 | + $this->process_free_payment( $invoice ); |
|
442 | + } |
|
443 | 443 | |
444 | - $submission = $this->payment_form_submission; |
|
444 | + $submission = $this->payment_form_submission; |
|
445 | 445 | |
446 | - // Fires before sending to the gateway. |
|
447 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
446 | + // Fires before sending to the gateway. |
|
447 | + do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
448 | 448 | |
449 | - // Allow the sumission data to be modified before it is sent to the gateway. |
|
450 | - $submission_data = $submission->get_data(); |
|
451 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
452 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
449 | + // Allow the sumission data to be modified before it is sent to the gateway. |
|
450 | + $submission_data = $submission->get_data(); |
|
451 | + $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
452 | + $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
453 | 453 | |
454 | - // Validate the currency. |
|
455 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
456 | - wpinv_set_error( 'invalid_currency' ); |
|
457 | - } |
|
454 | + // Validate the currency. |
|
455 | + if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
456 | + wpinv_set_error( 'invalid_currency' ); |
|
457 | + } |
|
458 | 458 | |
459 | - // Check to see if we have any errors. |
|
460 | - if ( wpinv_get_errors() ) { |
|
461 | - wpinv_send_back_to_checkout( $invoice ); |
|
462 | - } |
|
459 | + // Check to see if we have any errors. |
|
460 | + if ( wpinv_get_errors() ) { |
|
461 | + wpinv_send_back_to_checkout( $invoice ); |
|
462 | + } |
|
463 | 463 | |
464 | - // Send info to the gateway for payment processing |
|
465 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
464 | + // Send info to the gateway for payment processing |
|
465 | + do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
466 | 466 | |
467 | - // Backwards compatibility. |
|
468 | - wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
467 | + // Backwards compatibility. |
|
468 | + wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
469 | 469 | |
470 | - } |
|
470 | + } |
|
471 | 471 | |
472 | - /** |
|
473 | - * Marks the invoice as paid in case the checkout is free. |
|
474 | - * |
|
475 | - * @param WPInv_Invoice $invoice |
|
476 | - */ |
|
477 | - protected function process_free_payment( $invoice ) { |
|
472 | + /** |
|
473 | + * Marks the invoice as paid in case the checkout is free. |
|
474 | + * |
|
475 | + * @param WPInv_Invoice $invoice |
|
476 | + */ |
|
477 | + protected function process_free_payment( $invoice ) { |
|
478 | 478 | |
479 | - $invoice->set_gateway( 'none' ); |
|
480 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
481 | - $invoice->mark_paid(); |
|
482 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
479 | + $invoice->set_gateway( 'none' ); |
|
480 | + $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
481 | + $invoice->mark_paid(); |
|
482 | + wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
483 | 483 | |
484 | - } |
|
484 | + } |
|
485 | 485 | |
486 | - /** |
|
486 | + /** |
|
487 | 487 | * Sends a redrect response to payment details. |
488 | 488 | * |
489 | 489 | */ |
@@ -26,71 +26,71 @@ discard block |
||
26 | 26 | |
27 | 27 | <?php |
28 | 28 | |
29 | - // Fires before printing a line item column. |
|
30 | - do_action( "getpaid_form_cart_item_before_$key", $item, $form ); |
|
29 | + // Fires before printing a line item column. |
|
30 | + do_action( "getpaid_form_cart_item_before_$key", $item, $form ); |
|
31 | 31 | |
32 | - // Item name. |
|
33 | - if ( 'name' === $key ) { |
|
32 | + // Item name. |
|
33 | + if ( 'name' === $key ) { |
|
34 | 34 | |
35 | 35 | |
36 | - ob_start(); |
|
36 | + ob_start(); |
|
37 | 37 | |
38 | - // Add an optional description. |
|
39 | - $description = $item->get_description(); |
|
38 | + // Add an optional description. |
|
39 | + $description = $item->get_description(); |
|
40 | 40 | |
41 | - if ( ! empty( $description ) ) { |
|
42 | - echo "<small class='form-text text-muted pr-2 m-0'>" . wp_kses_post( $description ) . '</small>'; |
|
43 | - } |
|
41 | + if ( ! empty( $description ) ) { |
|
42 | + echo "<small class='form-text text-muted pr-2 m-0'>" . wp_kses_post( $description ) . '</small>'; |
|
43 | + } |
|
44 | 44 | |
45 | - // Price help text. |
|
46 | - $description = getpaid_item_recurring_price_help_text( $item, $currency ); |
|
47 | - if ( $description ) { |
|
48 | - echo "<small class='getpaid-form-item-price-desc form-text text-muted font-italic pr-2 m-0'>" . wp_kses_post( $description ) . '</small>'; |
|
49 | - } |
|
45 | + // Price help text. |
|
46 | + $description = getpaid_item_recurring_price_help_text( $item, $currency ); |
|
47 | + if ( $description ) { |
|
48 | + echo "<small class='getpaid-form-item-price-desc form-text text-muted font-italic pr-2 m-0'>" . wp_kses_post( $description ) . '</small>'; |
|
49 | + } |
|
50 | 50 | |
51 | - do_action( 'getpaid_payment_form_cart_item_description', $item, $form ); |
|
51 | + do_action( 'getpaid_payment_form_cart_item_description', $item, $form ); |
|
52 | 52 | |
53 | - if ( wpinv_current_user_can_manage_invoicing() ) { |
|
53 | + if ( wpinv_current_user_can_manage_invoicing() ) { |
|
54 | 54 | |
55 | - edit_post_link( |
|
56 | - __( 'Edit this item.', 'invoicing' ), |
|
57 | - '<small class="form-text text-muted">', |
|
58 | - '</small>', |
|
59 | - $item->get_id(), |
|
60 | - 'text-danger' |
|
61 | - ); |
|
55 | + edit_post_link( |
|
56 | + __( 'Edit this item.', 'invoicing' ), |
|
57 | + '<small class="form-text text-muted">', |
|
58 | + '</small>', |
|
59 | + $item->get_id(), |
|
60 | + 'text-danger' |
|
61 | + ); |
|
62 | 62 | |
63 | - } |
|
63 | + } |
|
64 | 64 | |
65 | - $description = ob_get_clean(); |
|
65 | + $description = ob_get_clean(); |
|
66 | 66 | |
67 | - // Display the name. |
|
68 | - $tootip = empty( $description ) ? '' : ' <i class="fas fa-xs fa-info gp-tooltip d-sm-none text-muted"></i>'; |
|
67 | + // Display the name. |
|
68 | + $tootip = empty( $description ) ? '' : ' <i class="fas fa-xs fa-info gp-tooltip d-sm-none text-muted"></i>'; |
|
69 | 69 | |
70 | - $has_featured_image = has_post_thumbnail( $item->get_id() ); |
|
70 | + $has_featured_image = has_post_thumbnail( $item->get_id() ); |
|
71 | 71 | |
72 | - if ( $has_featured_image ) { |
|
73 | - echo '<div class="d-flex align-items-center getpaid-form-item-has-featured-image">'; |
|
74 | - echo '<div class="getpaid-form-item-image-container mr-2">'; |
|
75 | - echo get_the_post_thumbnail( $item->get_id(), 'thumbnail', array( 'class' => 'getpaid-form-item-image mb-0' ) ); |
|
76 | - echo '</div>'; |
|
77 | - echo '<div class="getpaid-form-item-name-container">'; |
|
78 | - } |
|
72 | + if ( $has_featured_image ) { |
|
73 | + echo '<div class="d-flex align-items-center getpaid-form-item-has-featured-image">'; |
|
74 | + echo '<div class="getpaid-form-item-image-container mr-2">'; |
|
75 | + echo get_the_post_thumbnail( $item->get_id(), 'thumbnail', array( 'class' => 'getpaid-form-item-image mb-0' ) ); |
|
76 | + echo '</div>'; |
|
77 | + echo '<div class="getpaid-form-item-name-container">'; |
|
78 | + } |
|
79 | 79 | |
80 | - echo '<div class="mb-1 font-weight-bold">' . esc_html( $item->get_name() ) . wp_kses_post( $tootip ) . '</div>'; |
|
80 | + echo '<div class="mb-1 font-weight-bold">' . esc_html( $item->get_name() ) . wp_kses_post( $tootip ) . '</div>'; |
|
81 | 81 | |
82 | - if ( ! empty( $description ) ) { |
|
83 | - printf( '<span class="d-none d-sm-block getpaid-item-desc">%s</span>', wp_kses_post( $description ) ); |
|
84 | - } |
|
82 | + if ( ! empty( $description ) ) { |
|
83 | + printf( '<span class="d-none d-sm-block getpaid-item-desc">%s</span>', wp_kses_post( $description ) ); |
|
84 | + } |
|
85 | 85 | |
86 | - if ( $item->allows_quantities() ) { |
|
87 | - printf( |
|
88 | - '<small class="d-sm-none text-muted form-text">%s</small>', |
|
89 | - sprintf( |
|
90 | - // translators: %s is the item quantity. |
|
91 | - esc_html__( 'Qty %s', 'invoicing' ), |
|
92 | - sprintf( |
|
93 | - '<input |
|
86 | + if ( $item->allows_quantities() ) { |
|
87 | + printf( |
|
88 | + '<small class="d-sm-none text-muted form-text">%s</small>', |
|
89 | + sprintf( |
|
90 | + // translators: %s is the item quantity. |
|
91 | + esc_html__( 'Qty %s', 'invoicing' ), |
|
92 | + sprintf( |
|
93 | + '<input |
|
94 | 94 | type="number" |
95 | 95 | step="0.01" |
96 | 96 | style="width: 48px;" |
@@ -99,62 +99,62 @@ discard block |
||
99 | 99 | min="1" |
100 | 100 | max="%s" |
101 | 101 | >', |
102 | - (float) $item->get_quantity() == 0 ? 1 : (float) $item->get_quantity(), |
|
103 | - floatval( null !== $max_qty ? $max_qty : 1000000000000 ) |
|
104 | - ) |
|
105 | - ) |
|
106 | - ); |
|
107 | - } else { |
|
108 | - printf( |
|
109 | - '<small class="d-sm-none text-muted form-text">%s</small>', |
|
110 | - sprintf( |
|
111 | - // translators: %s is the item quantity. |
|
112 | - esc_html__( 'Qty %s', 'invoicing' ), |
|
113 | - (float) $item->get_quantity() |
|
114 | - ) |
|
115 | - ); |
|
116 | - } |
|
117 | - |
|
118 | - if ( $has_featured_image ) { |
|
119 | - echo '</div>'; |
|
120 | - echo '</div>'; |
|
121 | - } |
|
122 | - } |
|
123 | - |
|
124 | - // Item price. |
|
125 | - if ( 'price' === $key ) { |
|
126 | - |
|
127 | - // Set the currency position. |
|
128 | - $position = wpinv_currency_position(); |
|
129 | - |
|
130 | - if ( 'left_space' === $position ) { |
|
131 | - $position = 'left'; |
|
132 | - } |
|
133 | - |
|
134 | - if ( 'right_space' === $position ) { |
|
135 | - $position = 'right'; |
|
136 | - } |
|
137 | - |
|
138 | - if ( $item->user_can_set_their_price() ) { |
|
139 | - $price = max( (float) $item->get_price(), (float) $item->get_minimum_price() ); |
|
140 | - $minimum = (float) $item->get_minimum_price(); |
|
141 | - $validate_minimum = ''; |
|
142 | - $class = ''; |
|
143 | - $data_minimum = ''; |
|
144 | - |
|
145 | - if ( $minimum > 0 ) { |
|
146 | - $validate_minimum = sprintf( |
|
147 | - // translators: %s is the minimum price. |
|
148 | - esc_attr__( 'The minimum allowed amount is %s', 'invoicing' ), |
|
149 | - wp_strip_all_tags( wpinv_price( $minimum, $currency ) ) |
|
150 | - ); |
|
151 | - |
|
152 | - $class = 'getpaid-validate-minimum-amount'; |
|
153 | - |
|
154 | - $data_minimum = "data-minimum-amount='" . esc_attr( getpaid_unstandardize_amount( $minimum ) ) . "'"; |
|
155 | - } |
|
156 | - |
|
157 | - ?> |
|
102 | + (float) $item->get_quantity() == 0 ? 1 : (float) $item->get_quantity(), |
|
103 | + floatval( null !== $max_qty ? $max_qty : 1000000000000 ) |
|
104 | + ) |
|
105 | + ) |
|
106 | + ); |
|
107 | + } else { |
|
108 | + printf( |
|
109 | + '<small class="d-sm-none text-muted form-text">%s</small>', |
|
110 | + sprintf( |
|
111 | + // translators: %s is the item quantity. |
|
112 | + esc_html__( 'Qty %s', 'invoicing' ), |
|
113 | + (float) $item->get_quantity() |
|
114 | + ) |
|
115 | + ); |
|
116 | + } |
|
117 | + |
|
118 | + if ( $has_featured_image ) { |
|
119 | + echo '</div>'; |
|
120 | + echo '</div>'; |
|
121 | + } |
|
122 | + } |
|
123 | + |
|
124 | + // Item price. |
|
125 | + if ( 'price' === $key ) { |
|
126 | + |
|
127 | + // Set the currency position. |
|
128 | + $position = wpinv_currency_position(); |
|
129 | + |
|
130 | + if ( 'left_space' === $position ) { |
|
131 | + $position = 'left'; |
|
132 | + } |
|
133 | + |
|
134 | + if ( 'right_space' === $position ) { |
|
135 | + $position = 'right'; |
|
136 | + } |
|
137 | + |
|
138 | + if ( $item->user_can_set_their_price() ) { |
|
139 | + $price = max( (float) $item->get_price(), (float) $item->get_minimum_price() ); |
|
140 | + $minimum = (float) $item->get_minimum_price(); |
|
141 | + $validate_minimum = ''; |
|
142 | + $class = ''; |
|
143 | + $data_minimum = ''; |
|
144 | + |
|
145 | + if ( $minimum > 0 ) { |
|
146 | + $validate_minimum = sprintf( |
|
147 | + // translators: %s is the minimum price. |
|
148 | + esc_attr__( 'The minimum allowed amount is %s', 'invoicing' ), |
|
149 | + wp_strip_all_tags( wpinv_price( $minimum, $currency ) ) |
|
150 | + ); |
|
151 | + |
|
152 | + $class = 'getpaid-validate-minimum-amount'; |
|
153 | + |
|
154 | + $data_minimum = "data-minimum-amount='" . esc_attr( getpaid_unstandardize_amount( $minimum ) ) . "'"; |
|
155 | + } |
|
156 | + |
|
157 | + ?> |
|
158 | 158 | <div class="input-group input-group-sm"> |
159 | 159 | <?php if ( 'left' === $position ) : ?> |
160 | 160 | <?php if ( empty( $GLOBALS['aui_bs5'] ) ) : ?> |
@@ -195,46 +195,46 @@ discard block |
||
195 | 195 | |
196 | 196 | <?php |
197 | 197 | |
198 | - } else { |
|
199 | - ?> |
|
198 | + } else { |
|
199 | + ?> |
|
200 | 200 | <span class="getpaid-items-<?php echo (int) $item->get_id(); ?>-view-price"> |
201 | 201 | <?php echo wp_kses_post( wpinv_price( $item->get_price(), $currency ) ); ?> |
202 | 202 | </span> |
203 | 203 | <input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][price]' type='hidden' class='getpaid-item-price-input' value='<?php echo esc_attr( $item->get_price() ); ?>'> |
204 | 204 | <?php |
205 | - } |
|
205 | + } |
|
206 | 206 | |
207 | - printf( |
|
207 | + printf( |
|
208 | 208 | '<small class="d-sm-none text-muted form-text getpaid-mobile-item-subtotal">%s</small>', |
209 | - // translators: %s is the item subtotal. |
|
209 | + // translators: %s is the item subtotal. |
|
210 | 210 | sprintf( esc_html__( 'Subtotal: %s', 'invoicing' ), wp_kses_post( wpinv_price( $item->get_sub_total(), $currency ) ) ) |
211 | 211 | ); |
212 | - } |
|
212 | + } |
|
213 | 213 | |
214 | - // Item quantity. |
|
215 | - if ( 'quantity' === $key ) { |
|
214 | + // Item quantity. |
|
215 | + if ( 'quantity' === $key ) { |
|
216 | 216 | |
217 | - if ( $item->allows_quantities() ) { |
|
218 | - ?> |
|
217 | + if ( $item->allows_quantities() ) { |
|
218 | + ?> |
|
219 | 219 | <input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][quantity]' type="number" step="any" style='width: 64px; line-height: 1; min-height: 35px;' class='getpaid-item-quantity-input p-1 align-middle font-weight-normal shadow-none m-0 rounded-0 text-center border' value='<?php echo (float) $item->get_quantity() == 0 ? 1 : (float) $item->get_quantity(); ?>' min='1' <?php echo null !== $max_qty ? 'max="' . (float) $max_qty . '"' : ''; ?> required> |
220 | 220 | <?php |
221 | - } else { |
|
222 | - ?> |
|
221 | + } else { |
|
222 | + ?> |
|
223 | 223 | <span class="getpaid-items-<?php echo (int) $item->get_id(); ?>-view-quantity"> |
224 | 224 | <?php echo (float) $item->get_quantity(); ?> |
225 | 225 | </span> |
226 | 226 | <input type='hidden' name='getpaid-items[<?php echo (int) $item->get_id(); ?>][quantity]' class='getpaid-item-quantity-input' value='<?php echo (float) $item->get_quantity(); ?>'> |
227 | 227 | <?php |
228 | - } |
|
228 | + } |
|
229 | 229 | } |
230 | 230 | |
231 | - // Item sub total. |
|
232 | - if ( 'subtotal' === $key ) { |
|
233 | - echo wp_kses_post( wpinv_price( $item->get_sub_total(), $currency ) ); |
|
234 | - } |
|
231 | + // Item sub total. |
|
232 | + if ( 'subtotal' === $key ) { |
|
233 | + echo wp_kses_post( wpinv_price( $item->get_sub_total(), $currency ) ); |
|
234 | + } |
|
235 | 235 | |
236 | - do_action( "getpaid_payment_form_cart_item_$key", $item, $form ); |
|
237 | - ?> |
|
236 | + do_action( "getpaid_payment_form_cart_item_$key", $item, $form ); |
|
237 | + ?> |
|
238 | 238 | |
239 | 239 | </div> |
240 | 240 |
@@ -12,51 +12,51 @@ discard block |
||
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(); |
|
15 | + /** |
|
16 | + * Submission items. |
|
17 | + * @var GetPaid_Form_Item[] |
|
18 | + */ |
|
19 | + public $items = array(); |
|
20 | 20 | |
21 | 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 | - $invoice = $submission->get_invoice(); |
|
31 | - $force_prices = array(); |
|
32 | - |
|
33 | - // Prepare the selected items. |
|
34 | - $selected_items = array(); |
|
35 | - if ( ! empty( $data['getpaid-items'] ) ) { |
|
36 | - $selected_items = wpinv_clean( $data['getpaid-items'] ); |
|
37 | - |
|
38 | - if ( ! empty( $invoice ) && $submission->is_initial_fetch() ) { |
|
39 | - foreach ( $invoice->get_items() as $invoice_item ) { |
|
40 | - if ( isset( $selected_items[ $invoice_item->get_id() ] ) ) { |
|
41 | - $selected_items[ $invoice_item->get_id() ]['quantity'] = $invoice_item->get_quantity(); |
|
42 | - $selected_items[ $invoice_item->get_id() ]['price'] = $invoice_item->get_price(); |
|
43 | - |
|
44 | - $force_prices[ $invoice_item->get_id() ] = $invoice_item->get_price(); |
|
45 | - } |
|
46 | - } |
|
47 | - } |
|
48 | - } |
|
49 | - |
|
50 | - // (Maybe) set form items. |
|
51 | - if ( isset( $data['getpaid-form-items'] ) ) { |
|
52 | - |
|
53 | - // Confirm items key. |
|
54 | - $form_items = wpinv_clean( $data['getpaid-form-items'] ); |
|
55 | - if ( ! isset( $data['getpaid-form-items-key'] ) || md5( NONCE_KEY . AUTH_KEY . $form_items ) !== $data['getpaid-form-items-key'] ) { |
|
56 | - throw new Exception( __( 'We could not validate the form items. Please reload the page and try again.', 'invoicing' ) ); |
|
57 | - } |
|
58 | - |
|
59 | - $items = array(); |
|
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 | + $invoice = $submission->get_invoice(); |
|
31 | + $force_prices = array(); |
|
32 | + |
|
33 | + // Prepare the selected items. |
|
34 | + $selected_items = array(); |
|
35 | + if ( ! empty( $data['getpaid-items'] ) ) { |
|
36 | + $selected_items = wpinv_clean( $data['getpaid-items'] ); |
|
37 | + |
|
38 | + if ( ! empty( $invoice ) && $submission->is_initial_fetch() ) { |
|
39 | + foreach ( $invoice->get_items() as $invoice_item ) { |
|
40 | + if ( isset( $selected_items[ $invoice_item->get_id() ] ) ) { |
|
41 | + $selected_items[ $invoice_item->get_id() ]['quantity'] = $invoice_item->get_quantity(); |
|
42 | + $selected_items[ $invoice_item->get_id() ]['price'] = $invoice_item->get_price(); |
|
43 | + |
|
44 | + $force_prices[ $invoice_item->get_id() ] = $invoice_item->get_price(); |
|
45 | + } |
|
46 | + } |
|
47 | + } |
|
48 | + } |
|
49 | + |
|
50 | + // (Maybe) set form items. |
|
51 | + if ( isset( $data['getpaid-form-items'] ) ) { |
|
52 | + |
|
53 | + // Confirm items key. |
|
54 | + $form_items = wpinv_clean( $data['getpaid-form-items'] ); |
|
55 | + if ( ! isset( $data['getpaid-form-items-key'] ) || md5( NONCE_KEY . AUTH_KEY . $form_items ) !== $data['getpaid-form-items-key'] ) { |
|
56 | + throw new Exception( __( 'We could not validate the form items. Please reload the page and try again.', 'invoicing' ) ); |
|
57 | + } |
|
58 | + |
|
59 | + $items = array(); |
|
60 | 60 | $item_ids = array(); |
61 | 61 | |
62 | 62 | foreach ( getpaid_convert_items_to_array( $form_items ) as $item_id => $qty ) { |
@@ -69,10 +69,10 @@ discard block |
||
69 | 69 | $item->set_is_required( false ); |
70 | 70 | } |
71 | 71 | |
72 | - if ( ! $item->user_can_set_their_price() && isset( $force_prices[ $item_id ] ) ) { |
|
73 | - $item->set_is_dynamic_pricing( true ); |
|
74 | - $item->set_minimum_price( 0 ); |
|
75 | - } |
|
72 | + if ( ! $item->user_can_set_their_price() && isset( $force_prices[ $item_id ] ) ) { |
|
73 | + $item->set_is_dynamic_pricing( true ); |
|
74 | + $item->set_minimum_price( 0 ); |
|
75 | + } |
|
76 | 76 | |
77 | 77 | $item_ids[] = $item->get_id(); |
78 | 78 | $items[] = $item; |
@@ -87,61 +87,61 @@ discard block |
||
87 | 87 | $items[] = $item; |
88 | 88 | } |
89 | 89 | } |
90 | - } |
|
90 | + } |
|
91 | 91 | |
92 | 92 | $payment_form->set_items( $items ); |
93 | 93 | |
94 | - } |
|
95 | - |
|
96 | - // Process each individual item. |
|
97 | - foreach ( $payment_form->get_items() as $item ) { |
|
98 | - $this->process_item( $item, $selected_items, $submission ); |
|
99 | - } |
|
100 | - |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Process a single item. |
|
105 | - * |
|
106 | - * @param GetPaid_Form_Item $item |
|
107 | - * @param array $selected_items |
|
108 | - * @param GetPaid_Payment_Form_Submission $submission |
|
109 | - */ |
|
110 | - public function process_item( $item, $selected_items, $submission ) { |
|
94 | + } |
|
111 | 95 | |
112 | - // Abort if this is an optional item and it has not been selected. |
|
113 | - if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) { |
|
114 | - return; |
|
115 | - } |
|
96 | + // Process each individual item. |
|
97 | + foreach ( $payment_form->get_items() as $item ) { |
|
98 | + $this->process_item( $item, $selected_items, $submission ); |
|
99 | + } |
|
116 | 100 | |
117 | - // (maybe) let customers change the quantities and prices. |
|
118 | - if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
101 | + } |
|
119 | 102 | |
120 | - // Maybe change the quantities. |
|
121 | - if ( $item->allows_quantities() ) { |
|
122 | - $item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] ); |
|
123 | - } |
|
103 | + /** |
|
104 | + * Process a single item. |
|
105 | + * |
|
106 | + * @param GetPaid_Form_Item $item |
|
107 | + * @param array $selected_items |
|
108 | + * @param GetPaid_Payment_Form_Submission $submission |
|
109 | + */ |
|
110 | + public function process_item( $item, $selected_items, $submission ) { |
|
111 | + |
|
112 | + // Abort if this is an optional item and it has not been selected. |
|
113 | + if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) { |
|
114 | + return; |
|
115 | + } |
|
116 | + |
|
117 | + // (maybe) let customers change the quantities and prices. |
|
118 | + if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
119 | + |
|
120 | + // Maybe change the quantities. |
|
121 | + if ( $item->allows_quantities() ) { |
|
122 | + $item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] ); |
|
123 | + } |
|
124 | 124 | |
125 | - // Maybe change the price. |
|
126 | - if ( $item->user_can_set_their_price() ) { |
|
127 | - $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] ); |
|
125 | + // Maybe change the price. |
|
126 | + if ( $item->user_can_set_their_price() ) { |
|
127 | + $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] ); |
|
128 | 128 | |
129 | - if ( $item->get_minimum_price() > $price ) { |
|
130 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $item->get_minimum_price() ) ) ); |
|
131 | - } |
|
129 | + if ( $item->get_minimum_price() > $price ) { |
|
130 | + throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $item->get_minimum_price() ) ) ); |
|
131 | + } |
|
132 | 132 | |
133 | - $item->set_price( $price ); |
|
133 | + $item->set_price( $price ); |
|
134 | 134 | |
135 | - } |
|
136 | - } |
|
135 | + } |
|
136 | + } |
|
137 | 137 | |
138 | - if ( 0 == $item->get_quantity() ) { |
|
139 | - return; |
|
140 | - } |
|
138 | + if ( 0 == $item->get_quantity() ) { |
|
139 | + return; |
|
140 | + } |
|
141 | 141 | |
142 | - // Save the item. |
|
143 | - $this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item', $item, $submission ); |
|
142 | + // Save the item. |
|
143 | + $this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item', $item, $submission ); |
|
144 | 144 | |
145 | - } |
|
145 | + } |
|
146 | 146 | |
147 | 147 | } |
@@ -12,305 +12,305 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Payment_Form_Submission_Refresh_Prices { |
14 | 14 | |
15 | - /** |
|
16 | - * Contains the response for refreshing prices. |
|
17 | - * @var array |
|
18 | - */ |
|
19 | - public $response = array(); |
|
15 | + /** |
|
16 | + * Contains the response for refreshing prices. |
|
17 | + * @var array |
|
18 | + */ |
|
19 | + public $response = array(); |
|
20 | 20 | |
21 | 21 | /** |
22 | - * Class constructor |
|
23 | - * |
|
24 | - * @param GetPaid_Payment_Form_Submission $submission |
|
25 | - */ |
|
26 | - public function __construct( $submission ) { |
|
27 | - |
|
28 | - $this->response = array( |
|
29 | - 'submission_id' => $submission->id, |
|
22 | + * Class constructor |
|
23 | + * |
|
24 | + * @param GetPaid_Payment_Form_Submission $submission |
|
25 | + */ |
|
26 | + public function __construct( $submission ) { |
|
27 | + |
|
28 | + $this->response = array( |
|
29 | + 'submission_id' => $submission->id, |
|
30 | 30 | 'has_recurring' => $submission->has_recurring, |
31 | - 'has_subscription_group' => $submission->has_subscription_group(), |
|
32 | - 'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(), |
|
31 | + 'has_subscription_group' => $submission->has_subscription_group(), |
|
32 | + 'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(), |
|
33 | 33 | 'is_free' => ! $submission->should_collect_payment_details(), |
34 | - ); |
|
35 | - |
|
36 | - $payment_form = $submission->get_payment_form(); |
|
37 | - if ( ! empty( $payment_form->invoice ) ) { |
|
38 | - $this->response['invoice'] = $payment_form->invoice->get_id(); |
|
39 | - } |
|
40 | - |
|
41 | - $this->add_totals( $submission ); |
|
42 | - $this->add_texts( $submission ); |
|
43 | - $this->add_items( $submission ); |
|
44 | - $this->add_fees( $submission ); |
|
45 | - $this->add_discounts( $submission ); |
|
46 | - $this->add_taxes( $submission ); |
|
47 | - $this->add_gateways( $submission ); |
|
48 | - $this->add_data( $submission ); |
|
49 | - |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * Adds totals to a response for submission refresh prices. |
|
54 | - * |
|
55 | - * @param GetPaid_Payment_Form_Submission $submission |
|
56 | - */ |
|
57 | - public function add_totals( $submission ) { |
|
58 | - |
|
59 | - $this->response = array_merge( |
|
60 | - $this->response, |
|
61 | - array( |
|
62 | - |
|
63 | - 'totals' => array( |
|
64 | - 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
65 | - 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
66 | - 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
67 | - 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
68 | - 'total' => $submission->format_amount( $submission->get_total() ), |
|
69 | - 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
70 | - ), |
|
71 | - |
|
72 | - 'recurring' => array( |
|
73 | - 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
74 | - 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
75 | - 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
76 | - 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
77 | - 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
78 | - ), |
|
79 | - |
|
80 | - 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
81 | - 'currency' => $submission->get_currency(), |
|
82 | - |
|
83 | - ) |
|
84 | - ); |
|
85 | - |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Adds texts to a response for submission refresh prices. |
|
90 | - * |
|
91 | - * @param GetPaid_Payment_Form_Submission $submission |
|
92 | - */ |
|
93 | - public function add_texts( $submission ) { |
|
94 | - |
|
95 | - $payable = $submission->format_amount( $submission->get_total() ); |
|
96 | - $groups = getpaid_get_subscription_groups( $submission ); |
|
97 | - |
|
98 | - if ( $submission->has_recurring && 2 > count( $groups ) ) { |
|
99 | - |
|
100 | - $recurring = new WPInv_Item( $submission->has_recurring ); |
|
101 | - $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
102 | - $main_item = reset( $groups ); |
|
103 | - |
|
104 | - if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
105 | - $payable = "$payable / $period"; |
|
106 | - } elseif ( $main_item ) { |
|
107 | - |
|
108 | - $main_item = reset( $main_item ); |
|
109 | - |
|
110 | - // Calculate the next renewal date. |
|
111 | - $_period = $main_item->get_recurring_period( true ); |
|
112 | - $_interval = $main_item->get_recurring_interval(); |
|
113 | - |
|
114 | - // If the subscription item has a trial period... |
|
115 | - if ( $main_item->has_free_trial() ) { |
|
116 | - $_period = $main_item->get_trial_period( true ); |
|
117 | - $_interval = $main_item->get_trial_interval(); |
|
118 | - } |
|
119 | - |
|
120 | - $payable = sprintf( |
|
121 | - __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
122 | - $submission->format_amount( $submission->get_total() ), |
|
123 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
124 | - $period |
|
125 | - ); |
|
126 | - |
|
127 | - $payable .= sprintf( |
|
128 | - '<small class="text-muted form-text">%s</small>', |
|
129 | - sprintf( |
|
130 | - __( 'First renewal on %s', 'invoicing' ), |
|
131 | - getpaid_format_date( date( 'Y-m-d H:i:s', strtotime( "+$_interval $_period", current_time( 'timestamp' ) ) ) ) |
|
132 | - ) |
|
133 | - ); |
|
134 | - |
|
135 | - } else { |
|
136 | - $payable = sprintf( |
|
137 | - __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
138 | - $submission->format_amount( $submission->get_total() ), |
|
139 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
140 | - $period |
|
141 | - ); |
|
142 | - } |
|
143 | -} |
|
34 | + ); |
|
35 | + |
|
36 | + $payment_form = $submission->get_payment_form(); |
|
37 | + if ( ! empty( $payment_form->invoice ) ) { |
|
38 | + $this->response['invoice'] = $payment_form->invoice->get_id(); |
|
39 | + } |
|
40 | + |
|
41 | + $this->add_totals( $submission ); |
|
42 | + $this->add_texts( $submission ); |
|
43 | + $this->add_items( $submission ); |
|
44 | + $this->add_fees( $submission ); |
|
45 | + $this->add_discounts( $submission ); |
|
46 | + $this->add_taxes( $submission ); |
|
47 | + $this->add_gateways( $submission ); |
|
48 | + $this->add_data( $submission ); |
|
144 | 49 | |
145 | - $texts = array( |
|
146 | - '.getpaid-checkout-total-payable' => $payable, |
|
147 | - ); |
|
50 | + } |
|
148 | 51 | |
149 | - foreach ( $submission->get_items() as $item ) { |
|
150 | - $item_id = $item->get_id(); |
|
151 | - $initial_price = $submission->format_amount( $item->get_sub_total() - $item->item_discount ); |
|
152 | - $recurring_price = $submission->format_amount( $item->get_recurring_sub_total() - $item->recurring_item_discount ); |
|
153 | - $texts[ ".item-$item_id .getpaid-form-item-price-desc" ] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
154 | - $texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = sprintf( __( 'Subtotal: %s', 'invoicing' ), $submission->format_amount( $item->get_sub_total() ) ); |
|
52 | + /** |
|
53 | + * Adds totals to a response for submission refresh prices. |
|
54 | + * |
|
55 | + * @param GetPaid_Payment_Form_Submission $submission |
|
56 | + */ |
|
57 | + public function add_totals( $submission ) { |
|
58 | + |
|
59 | + $this->response = array_merge( |
|
60 | + $this->response, |
|
61 | + array( |
|
62 | + |
|
63 | + 'totals' => array( |
|
64 | + 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
65 | + 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
66 | + 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
67 | + 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
68 | + 'total' => $submission->format_amount( $submission->get_total() ), |
|
69 | + 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
70 | + ), |
|
71 | + |
|
72 | + 'recurring' => array( |
|
73 | + 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
74 | + 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
75 | + 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
76 | + 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
77 | + 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
78 | + ), |
|
79 | + |
|
80 | + 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
81 | + 'currency' => $submission->get_currency(), |
|
82 | + |
|
83 | + ) |
|
84 | + ); |
|
85 | + |
|
86 | + } |
|
155 | 87 | |
156 | - if ( $item->get_quantity() == 1 ) { |
|
157 | - $texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = ''; |
|
158 | - } |
|
88 | + /** |
|
89 | + * Adds texts to a response for submission refresh prices. |
|
90 | + * |
|
91 | + * @param GetPaid_Payment_Form_Submission $submission |
|
92 | + */ |
|
93 | + public function add_texts( $submission ) { |
|
94 | + |
|
95 | + $payable = $submission->format_amount( $submission->get_total() ); |
|
96 | + $groups = getpaid_get_subscription_groups( $submission ); |
|
97 | + |
|
98 | + if ( $submission->has_recurring && 2 > count( $groups ) ) { |
|
99 | + |
|
100 | + $recurring = new WPInv_Item( $submission->has_recurring ); |
|
101 | + $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
102 | + $main_item = reset( $groups ); |
|
103 | + |
|
104 | + if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
105 | + $payable = "$payable / $period"; |
|
106 | + } elseif ( $main_item ) { |
|
107 | + |
|
108 | + $main_item = reset( $main_item ); |
|
109 | + |
|
110 | + // Calculate the next renewal date. |
|
111 | + $_period = $main_item->get_recurring_period( true ); |
|
112 | + $_interval = $main_item->get_recurring_interval(); |
|
113 | + |
|
114 | + // If the subscription item has a trial period... |
|
115 | + if ( $main_item->has_free_trial() ) { |
|
116 | + $_period = $main_item->get_trial_period( true ); |
|
117 | + $_interval = $main_item->get_trial_interval(); |
|
118 | + } |
|
119 | + |
|
120 | + $payable = sprintf( |
|
121 | + __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
122 | + $submission->format_amount( $submission->get_total() ), |
|
123 | + $submission->format_amount( $submission->get_recurring_total() ), |
|
124 | + $period |
|
125 | + ); |
|
126 | + |
|
127 | + $payable .= sprintf( |
|
128 | + '<small class="text-muted form-text">%s</small>', |
|
129 | + sprintf( |
|
130 | + __( 'First renewal on %s', 'invoicing' ), |
|
131 | + getpaid_format_date( date( 'Y-m-d H:i:s', strtotime( "+$_interval $_period", current_time( 'timestamp' ) ) ) ) |
|
132 | + ) |
|
133 | + ); |
|
134 | + |
|
135 | + } else { |
|
136 | + $payable = sprintf( |
|
137 | + __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
138 | + $submission->format_amount( $submission->get_total() ), |
|
139 | + $submission->format_amount( $submission->get_recurring_total() ), |
|
140 | + $period |
|
141 | + ); |
|
142 | + } |
|
159 | 143 | } |
160 | 144 | |
161 | - $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
145 | + $texts = array( |
|
146 | + '.getpaid-checkout-total-payable' => $payable, |
|
147 | + ); |
|
162 | 148 | |
163 | - } |
|
149 | + foreach ( $submission->get_items() as $item ) { |
|
150 | + $item_id = $item->get_id(); |
|
151 | + $initial_price = $submission->format_amount( $item->get_sub_total() - $item->item_discount ); |
|
152 | + $recurring_price = $submission->format_amount( $item->get_recurring_sub_total() - $item->recurring_item_discount ); |
|
153 | + $texts[ ".item-$item_id .getpaid-form-item-price-desc" ] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
154 | + $texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = sprintf( __( 'Subtotal: %s', 'invoicing' ), $submission->format_amount( $item->get_sub_total() ) ); |
|
155 | + |
|
156 | + if ( $item->get_quantity() == 1 ) { |
|
157 | + $texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = ''; |
|
158 | + } |
|
159 | +} |
|
164 | 160 | |
165 | - /** |
|
166 | - * Adds items to a response for submission refresh prices. |
|
167 | - * |
|
168 | - * @param GetPaid_Payment_Form_Submission $submission |
|
169 | - */ |
|
170 | - public function add_items( $submission ) { |
|
161 | + $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
171 | 162 | |
172 | - // Add items. |
|
173 | - $items = array(); |
|
174 | - $selected_items = array(); |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Adds items to a response for submission refresh prices. |
|
167 | + * |
|
168 | + * @param GetPaid_Payment_Form_Submission $submission |
|
169 | + */ |
|
170 | + public function add_items( $submission ) { |
|
171 | + |
|
172 | + // Add items. |
|
173 | + $items = array(); |
|
174 | + $selected_items = array(); |
|
175 | 175 | |
176 | 176 | foreach ( $submission->get_items() as $item ) { |
177 | - $item_id = $item->get_id(); |
|
178 | - $items[ "$item_id" ] = $submission->format_amount( $item->get_sub_total() ); |
|
179 | - |
|
180 | - $selected_items[ "$item_id" ] = array( |
|
181 | - 'quantity' => $item->get_quantity(), |
|
182 | - 'price' => $item->get_price(), |
|
183 | - 'price_fmt' => $submission->format_amount( $item->get_price() ), |
|
184 | - ); |
|
185 | - } |
|
186 | - |
|
187 | - $this->response = array_merge( |
|
188 | - $this->response, |
|
189 | - array( |
|
190 | - 'items' => $items, |
|
191 | - 'selected_items' => $selected_items, |
|
192 | - ) |
|
193 | - ); |
|
194 | - |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * Adds fees to a response for submission refresh prices. |
|
199 | - * |
|
200 | - * @param GetPaid_Payment_Form_Submission $submission |
|
201 | - */ |
|
202 | - public function add_fees( $submission ) { |
|
203 | - |
|
204 | - $fees = array(); |
|
177 | + $item_id = $item->get_id(); |
|
178 | + $items[ "$item_id" ] = $submission->format_amount( $item->get_sub_total() ); |
|
179 | + |
|
180 | + $selected_items[ "$item_id" ] = array( |
|
181 | + 'quantity' => $item->get_quantity(), |
|
182 | + 'price' => $item->get_price(), |
|
183 | + 'price_fmt' => $submission->format_amount( $item->get_price() ), |
|
184 | + ); |
|
185 | + } |
|
186 | + |
|
187 | + $this->response = array_merge( |
|
188 | + $this->response, |
|
189 | + array( |
|
190 | + 'items' => $items, |
|
191 | + 'selected_items' => $selected_items, |
|
192 | + ) |
|
193 | + ); |
|
194 | + |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * Adds fees to a response for submission refresh prices. |
|
199 | + * |
|
200 | + * @param GetPaid_Payment_Form_Submission $submission |
|
201 | + */ |
|
202 | + public function add_fees( $submission ) { |
|
203 | + |
|
204 | + $fees = array(); |
|
205 | 205 | |
206 | 206 | foreach ( $submission->get_fees() as $name => $data ) { |
207 | - $fees[ $name ] = $submission->format_amount( $data['initial_fee'] ); |
|
208 | - } |
|
207 | + $fees[ $name ] = $submission->format_amount( $data['initial_fee'] ); |
|
208 | + } |
|
209 | 209 | |
210 | - $this->response = array_merge( |
|
211 | - $this->response, |
|
212 | - array( 'fees' => $fees ) |
|
213 | - ); |
|
210 | + $this->response = array_merge( |
|
211 | + $this->response, |
|
212 | + array( 'fees' => $fees ) |
|
213 | + ); |
|
214 | 214 | |
215 | - } |
|
215 | + } |
|
216 | 216 | |
217 | - /** |
|
218 | - * Adds discounts to a response for submission refresh prices. |
|
219 | - * |
|
220 | - * @param GetPaid_Payment_Form_Submission $submission |
|
221 | - */ |
|
222 | - public function add_discounts( $submission ) { |
|
217 | + /** |
|
218 | + * Adds discounts to a response for submission refresh prices. |
|
219 | + * |
|
220 | + * @param GetPaid_Payment_Form_Submission $submission |
|
221 | + */ |
|
222 | + public function add_discounts( $submission ) { |
|
223 | 223 | |
224 | - $discounts = array(); |
|
224 | + $discounts = array(); |
|
225 | 225 | |
226 | 226 | foreach ( $submission->get_discounts() as $name => $data ) { |
227 | - $discounts[ $name ] = $submission->format_amount( $data['initial_discount'] ); |
|
228 | - } |
|
227 | + $discounts[ $name ] = $submission->format_amount( $data['initial_discount'] ); |
|
228 | + } |
|
229 | 229 | |
230 | - $this->response = array_merge( |
|
231 | - $this->response, |
|
232 | - array( 'discounts' => $discounts ) |
|
233 | - ); |
|
230 | + $this->response = array_merge( |
|
231 | + $this->response, |
|
232 | + array( 'discounts' => $discounts ) |
|
233 | + ); |
|
234 | 234 | |
235 | - } |
|
235 | + } |
|
236 | 236 | |
237 | - /** |
|
238 | - * Adds taxes to a response for submission refresh prices. |
|
239 | - * |
|
240 | - * @param GetPaid_Payment_Form_Submission $submission |
|
241 | - */ |
|
242 | - public function add_taxes( $submission ) { |
|
243 | - |
|
244 | - $taxes = array(); |
|
245 | - $markup = ''; |
|
237 | + /** |
|
238 | + * Adds taxes to a response for submission refresh prices. |
|
239 | + * |
|
240 | + * @param GetPaid_Payment_Form_Submission $submission |
|
241 | + */ |
|
242 | + public function add_taxes( $submission ) { |
|
243 | + |
|
244 | + $taxes = array(); |
|
245 | + $markup = ''; |
|
246 | 246 | foreach ( $submission->get_taxes() as $name => $data ) { |
247 | - $name = sanitize_text_field( $name ); |
|
248 | - $amount = $submission->format_amount( $data['initial_tax'] ); |
|
249 | - $taxes[ $name ] = $amount; |
|
250 | - $markup .= "<small class='form-text'>$name : $amount</small>"; |
|
251 | - } |
|
252 | - |
|
253 | - if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) { |
|
254 | - $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
|
255 | - } |
|
256 | - |
|
257 | - $this->response = array_merge( |
|
258 | - $this->response, |
|
259 | - array( 'taxes' => $taxes ) |
|
260 | - ); |
|
261 | - |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * Adds gateways to a response for submission refresh prices. |
|
266 | - * |
|
267 | - * @param GetPaid_Payment_Form_Submission $submission |
|
268 | - */ |
|
269 | - public function add_gateways( $submission ) { |
|
270 | - |
|
271 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
272 | - |
|
273 | - if ( $this->response['has_recurring'] ) { |
|
274 | - |
|
275 | - foreach ( $gateways as $i => $gateway ) { |
|
276 | - |
|
277 | - if ( |
|
278 | - ! getpaid_payment_gateway_supports( $gateway, 'subscription' ) |
|
279 | - || ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) ) |
|
280 | - || ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) { |
|
281 | - unset( $gateways[ $i ] ); |
|
282 | - } |
|
247 | + $name = sanitize_text_field( $name ); |
|
248 | + $amount = $submission->format_amount( $data['initial_tax'] ); |
|
249 | + $taxes[ $name ] = $amount; |
|
250 | + $markup .= "<small class='form-text'>$name : $amount</small>"; |
|
251 | + } |
|
252 | + |
|
253 | + if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) { |
|
254 | + $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
|
255 | + } |
|
256 | + |
|
257 | + $this->response = array_merge( |
|
258 | + $this->response, |
|
259 | + array( 'taxes' => $taxes ) |
|
260 | + ); |
|
261 | + |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * Adds gateways to a response for submission refresh prices. |
|
266 | + * |
|
267 | + * @param GetPaid_Payment_Form_Submission $submission |
|
268 | + */ |
|
269 | + public function add_gateways( $submission ) { |
|
270 | + |
|
271 | + $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
272 | + |
|
273 | + if ( $this->response['has_recurring'] ) { |
|
274 | + |
|
275 | + foreach ( $gateways as $i => $gateway ) { |
|
276 | + |
|
277 | + if ( |
|
278 | + ! getpaid_payment_gateway_supports( $gateway, 'subscription' ) |
|
279 | + || ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) ) |
|
280 | + || ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) { |
|
281 | + unset( $gateways[ $i ] ); |
|
282 | + } |
|
283 | 283 | } |
284 | 284 | } |
285 | 285 | |
286 | - $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
287 | - $this->response = array_merge( |
|
288 | - $this->response, |
|
289 | - array( 'gateways' => $gateways ) |
|
290 | - ); |
|
291 | - |
|
292 | - } |
|
293 | - |
|
294 | - /** |
|
295 | - * Adds data to a response for submission refresh prices. |
|
296 | - * |
|
297 | - * @param GetPaid_Payment_Form_Submission $submission |
|
298 | - */ |
|
299 | - public function add_data( $submission ) { |
|
300 | - |
|
301 | - $this->response = array_merge( |
|
302 | - $this->response, |
|
303 | - array( |
|
304 | - 'js_data' => apply_filters( |
|
305 | - 'getpaid_submission_js_data', |
|
306 | - array( |
|
307 | - 'is_recurring' => $this->response['has_recurring'], |
|
308 | - ), |
|
309 | - $submission |
|
310 | - ), |
|
311 | - ) |
|
312 | - ); |
|
313 | - |
|
314 | - } |
|
286 | + $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
287 | + $this->response = array_merge( |
|
288 | + $this->response, |
|
289 | + array( 'gateways' => $gateways ) |
|
290 | + ); |
|
291 | + |
|
292 | + } |
|
293 | + |
|
294 | + /** |
|
295 | + * Adds data to a response for submission refresh prices. |
|
296 | + * |
|
297 | + * @param GetPaid_Payment_Form_Submission $submission |
|
298 | + */ |
|
299 | + public function add_data( $submission ) { |
|
300 | + |
|
301 | + $this->response = array_merge( |
|
302 | + $this->response, |
|
303 | + array( |
|
304 | + 'js_data' => apply_filters( |
|
305 | + 'getpaid_submission_js_data', |
|
306 | + array( |
|
307 | + 'is_recurring' => $this->response['has_recurring'], |
|
308 | + ), |
|
309 | + $submission |
|
310 | + ), |
|
311 | + ) |
|
312 | + ); |
|
313 | + |
|
314 | + } |
|
315 | 315 | |
316 | 316 | } |
@@ -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,67 +10,67 @@ discard block |
||
10 | 10 | class GetPaid_Form_Item extends WPInv_Item { |
11 | 11 | |
12 | 12 | /** |
13 | - * Stores a custom description for the item. |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - protected $custom_description = null; |
|
18 | - |
|
19 | - /** |
|
20 | - * Stores the item quantity. |
|
21 | - * |
|
22 | - * @var float |
|
23 | - */ |
|
24 | - protected $quantity = 1; |
|
25 | - |
|
26 | - /** |
|
27 | - * Stores the item meta. |
|
28 | - * |
|
29 | - * @var array |
|
30 | - */ |
|
31 | - protected $meta = array(); |
|
32 | - |
|
33 | - /** |
|
34 | - * Is this item required? |
|
35 | - * |
|
36 | - * @var int |
|
37 | - */ |
|
38 | - protected $is_required = true; |
|
39 | - |
|
40 | - /** |
|
41 | - * Are quantities allowed? |
|
42 | - * |
|
43 | - * @var int |
|
44 | - */ |
|
45 | - protected $allow_quantities = false; |
|
46 | - |
|
47 | - /** |
|
48 | - * Associated invoice. |
|
49 | - * |
|
50 | - * @var int |
|
51 | - */ |
|
52 | - public $invoice_id = 0; |
|
53 | - |
|
54 | - /** |
|
55 | - * Item discount. |
|
56 | - * |
|
57 | - * @var float |
|
58 | - */ |
|
59 | - public $item_discount = 0; |
|
60 | - |
|
61 | - /** |
|
62 | - * Recurring item discount. |
|
63 | - * |
|
64 | - * @var float |
|
65 | - */ |
|
66 | - public $recurring_item_discount = 0; |
|
67 | - |
|
68 | - /** |
|
69 | - * Item tax. |
|
70 | - * |
|
71 | - * @var float |
|
72 | - */ |
|
73 | - public $item_tax = 0; |
|
13 | + * Stores a custom description for the item. |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + protected $custom_description = null; |
|
18 | + |
|
19 | + /** |
|
20 | + * Stores the item quantity. |
|
21 | + * |
|
22 | + * @var float |
|
23 | + */ |
|
24 | + protected $quantity = 1; |
|
25 | + |
|
26 | + /** |
|
27 | + * Stores the item meta. |
|
28 | + * |
|
29 | + * @var array |
|
30 | + */ |
|
31 | + protected $meta = array(); |
|
32 | + |
|
33 | + /** |
|
34 | + * Is this item required? |
|
35 | + * |
|
36 | + * @var int |
|
37 | + */ |
|
38 | + protected $is_required = true; |
|
39 | + |
|
40 | + /** |
|
41 | + * Are quantities allowed? |
|
42 | + * |
|
43 | + * @var int |
|
44 | + */ |
|
45 | + protected $allow_quantities = false; |
|
46 | + |
|
47 | + /** |
|
48 | + * Associated invoice. |
|
49 | + * |
|
50 | + * @var int |
|
51 | + */ |
|
52 | + public $invoice_id = 0; |
|
53 | + |
|
54 | + /** |
|
55 | + * Item discount. |
|
56 | + * |
|
57 | + * @var float |
|
58 | + */ |
|
59 | + public $item_discount = 0; |
|
60 | + |
|
61 | + /** |
|
62 | + * Recurring item discount. |
|
63 | + * |
|
64 | + * @var float |
|
65 | + */ |
|
66 | + public $recurring_item_discount = 0; |
|
67 | + |
|
68 | + /** |
|
69 | + * Item tax. |
|
70 | + * |
|
71 | + * @var float |
|
72 | + */ |
|
73 | + public $item_tax = 0; |
|
74 | 74 | |
75 | 75 | /* |
76 | 76 | |-------------------------------------------------------------------------- |
@@ -88,230 +88,230 @@ discard block |
||
88 | 88 | */ |
89 | 89 | |
90 | 90 | /** |
91 | - * Get the item name. |
|
92 | - * |
|
93 | - * @since 1.0.19 |
|
94 | - * @param string $context View or edit context. |
|
95 | - * @return string |
|
96 | - */ |
|
97 | - public function get_name( $context = 'view' ) { |
|
98 | - $name = parent::get_name( $context ); |
|
99 | - return $name . wpinv_get_item_suffix( $this ); |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Get the item name without a suffix. |
|
104 | - * |
|
105 | - * @since 1.0.19 |
|
106 | - * @param string $context View or edit context. |
|
107 | - * @return string |
|
108 | - */ |
|
109 | - public function get_raw_name( $context = 'view' ) { |
|
110 | - return parent::get_name( $context ); |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Get the item description. |
|
115 | - * |
|
116 | - * @since 1.0.19 |
|
117 | - * @param string $context View or edit context. |
|
118 | - * @return string |
|
119 | - */ |
|
120 | - public function get_description( $context = 'view' ) { |
|
121 | - |
|
122 | - if ( isset( $this->custom_description ) ) { |
|
123 | - return $this->custom_description; |
|
124 | - } |
|
125 | - |
|
126 | - return parent::get_description( $context ); |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * Returns the sub total. |
|
131 | - * |
|
132 | - * @since 1.0.19 |
|
133 | - * @param string $context View or edit context. |
|
134 | - * @return float |
|
135 | - */ |
|
136 | - public function get_sub_total( $context = 'view' ) { |
|
137 | - return $this->get_quantity( $context ) * $this->get_initial_price( $context ); |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * Returns the recurring sub total. |
|
142 | - * |
|
143 | - * @since 1.0.19 |
|
144 | - * @param string $context View or edit context. |
|
145 | - * @return float |
|
146 | - */ |
|
147 | - public function get_recurring_sub_total( $context = 'view' ) { |
|
148 | - |
|
149 | - if ( $this->is_recurring() ) { |
|
150 | - return $this->get_quantity( $context ) * $this->get_price( $context ); |
|
151 | - } |
|
152 | - |
|
153 | - return 0; |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * @deprecated |
|
158 | - */ |
|
159 | - public function get_qantity( $context = 'view' ) { |
|
160 | - return $this->get_quantity( $context ); |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Get the item quantity. |
|
165 | - * |
|
166 | - * @since 1.0.19 |
|
167 | - * @param string $context View or edit context. |
|
168 | - * @return float |
|
169 | - */ |
|
170 | - public function get_quantity( $context = 'view' ) { |
|
171 | - $quantity = (float) $this->quantity; |
|
172 | - |
|
173 | - if ( 'view' === $context ) { |
|
174 | - return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this ); |
|
175 | - } |
|
176 | - |
|
177 | - return $quantity; |
|
178 | - |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * Get the item meta data. |
|
183 | - * |
|
184 | - * @since 1.0.19 |
|
185 | - * @param string $context View or edit context. |
|
186 | - * @return meta |
|
187 | - */ |
|
188 | - public function get_item_meta( $context = 'view' ) { |
|
189 | - $meta = $this->meta; |
|
190 | - |
|
191 | - if ( 'view' === $context ) { |
|
192 | - return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this ); |
|
193 | - } |
|
194 | - |
|
195 | - return $meta; |
|
196 | - |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * Returns whether or not customers can update the item quantity. |
|
201 | - * |
|
202 | - * @since 1.0.19 |
|
203 | - * @param string $context View or edit context. |
|
204 | - * @return bool |
|
205 | - */ |
|
206 | - public function get_allow_quantities( $context = 'view' ) { |
|
207 | - $allow_quantities = (bool) $this->allow_quantities; |
|
208 | - |
|
209 | - if ( 'view' === $context ) { |
|
210 | - return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this ); |
|
211 | - } |
|
212 | - |
|
213 | - return $allow_quantities; |
|
214 | - |
|
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * Returns whether or not the item is required. |
|
219 | - * |
|
220 | - * @since 1.0.19 |
|
221 | - * @param string $context View or edit context. |
|
222 | - * @return bool |
|
223 | - */ |
|
224 | - public function get_is_required( $context = 'view' ) { |
|
225 | - $is_required = (bool) $this->is_required; |
|
226 | - |
|
227 | - if ( 'view' === $context ) { |
|
228 | - return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this ); |
|
229 | - } |
|
230 | - |
|
231 | - return $is_required; |
|
232 | - |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * Prepares form data for use. |
|
237 | - * |
|
238 | - * @since 1.0.19 |
|
239 | - * @return array |
|
240 | - */ |
|
241 | - public function prepare_data_for_use( $required = null ) { |
|
242 | - |
|
243 | - $required = is_null( $required ) ? $this->is_required() : $required; |
|
244 | - return array( |
|
245 | - 'title' => wp_strip_all_tags( $this->get_name() ), |
|
246 | - 'id' => $this->get_id(), |
|
247 | - 'price' => $this->get_price(), |
|
248 | - 'recurring' => $this->is_recurring(), |
|
249 | - 'description' => $this->get_description(), |
|
250 | - 'allow_quantities' => $this->allows_quantities(), |
|
251 | - 'required' => $required, |
|
252 | - ); |
|
253 | - |
|
254 | - } |
|
255 | - |
|
256 | - /** |
|
257 | - * Prepares form data for ajax use. |
|
258 | - * |
|
259 | - * @since 1.0.19 |
|
260 | - * @return array |
|
261 | - */ |
|
262 | - public function prepare_data_for_invoice_edit_ajax( $currency = '', $is_renewal = false ) { |
|
263 | - |
|
264 | - $description = getpaid_item_recurring_price_help_text( $this, $currency ); |
|
265 | - |
|
266 | - if ( $description ) { |
|
267 | - $description = "<div class='getpaid-subscription-help-text'>$description</div>"; |
|
268 | - } |
|
269 | - |
|
270 | - $price = ! $is_renewal ? $this->get_price() : $this->get_recurring_price(); |
|
271 | - $subtotal = ! $is_renewal ? $this->get_sub_total() : $this->get_recurring_sub_total(); |
|
272 | - return array( |
|
273 | - 'id' => $this->get_id(), |
|
274 | - 'texts' => array( |
|
275 | - 'item-name' => sanitize_text_field( $this->get_name() ), |
|
276 | - 'item-description' => wp_kses_post( $this->get_description() ) . $description, |
|
277 | - 'item-quantity' => floatval( $this->get_quantity() ), |
|
278 | - 'item-price' => wpinv_price( $price, $currency ), |
|
279 | - 'item-total' => wpinv_price( $subtotal, $currency ), |
|
280 | - ), |
|
281 | - 'inputs' => array( |
|
282 | - 'item-id' => $this->get_id(), |
|
283 | - 'item-name' => sanitize_text_field( $this->get_name() ), |
|
284 | - 'item-description' => wp_kses_post( $this->get_description() ), |
|
285 | - 'item-quantity' => floatval( $this->get_quantity() ), |
|
286 | - 'item-price' => $price, |
|
287 | - ), |
|
288 | - ); |
|
289 | - |
|
290 | - } |
|
291 | - |
|
292 | - /** |
|
293 | - * Prepares form data for saving (cart_details). |
|
294 | - * |
|
295 | - * @since 1.0.19 |
|
296 | - * @return array |
|
297 | - */ |
|
298 | - public function prepare_data_for_saving() { |
|
299 | - |
|
300 | - return array( |
|
301 | - 'post_id' => $this->invoice_id, |
|
302 | - 'item_id' => $this->get_id(), |
|
303 | - 'item_name' => sanitize_text_field( $this->get_raw_name( 'edit' ) ), |
|
304 | - 'item_description' => $this->get_description( 'edit' ), |
|
305 | - 'tax' => $this->item_tax, |
|
306 | - 'item_price' => $this->get_price( 'edit' ), |
|
307 | - 'quantity' => (float) $this->get_quantity( 'edit' ), |
|
308 | - 'discount' => $this->item_discount, |
|
309 | - 'subtotal' => $this->get_sub_total( 'edit' ), |
|
310 | - 'price' => $this->get_sub_total( 'edit' ) + $this->item_tax - $this->item_discount, |
|
311 | - 'meta' => $this->get_item_meta( 'edit' ), |
|
312 | - ); |
|
313 | - |
|
314 | - } |
|
91 | + * Get the item name. |
|
92 | + * |
|
93 | + * @since 1.0.19 |
|
94 | + * @param string $context View or edit context. |
|
95 | + * @return string |
|
96 | + */ |
|
97 | + public function get_name( $context = 'view' ) { |
|
98 | + $name = parent::get_name( $context ); |
|
99 | + return $name . wpinv_get_item_suffix( $this ); |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Get the item name without a suffix. |
|
104 | + * |
|
105 | + * @since 1.0.19 |
|
106 | + * @param string $context View or edit context. |
|
107 | + * @return string |
|
108 | + */ |
|
109 | + public function get_raw_name( $context = 'view' ) { |
|
110 | + return parent::get_name( $context ); |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Get the item description. |
|
115 | + * |
|
116 | + * @since 1.0.19 |
|
117 | + * @param string $context View or edit context. |
|
118 | + * @return string |
|
119 | + */ |
|
120 | + public function get_description( $context = 'view' ) { |
|
121 | + |
|
122 | + if ( isset( $this->custom_description ) ) { |
|
123 | + return $this->custom_description; |
|
124 | + } |
|
125 | + |
|
126 | + return parent::get_description( $context ); |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * Returns the sub total. |
|
131 | + * |
|
132 | + * @since 1.0.19 |
|
133 | + * @param string $context View or edit context. |
|
134 | + * @return float |
|
135 | + */ |
|
136 | + public function get_sub_total( $context = 'view' ) { |
|
137 | + return $this->get_quantity( $context ) * $this->get_initial_price( $context ); |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * Returns the recurring sub total. |
|
142 | + * |
|
143 | + * @since 1.0.19 |
|
144 | + * @param string $context View or edit context. |
|
145 | + * @return float |
|
146 | + */ |
|
147 | + public function get_recurring_sub_total( $context = 'view' ) { |
|
148 | + |
|
149 | + if ( $this->is_recurring() ) { |
|
150 | + return $this->get_quantity( $context ) * $this->get_price( $context ); |
|
151 | + } |
|
152 | + |
|
153 | + return 0; |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * @deprecated |
|
158 | + */ |
|
159 | + public function get_qantity( $context = 'view' ) { |
|
160 | + return $this->get_quantity( $context ); |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Get the item quantity. |
|
165 | + * |
|
166 | + * @since 1.0.19 |
|
167 | + * @param string $context View or edit context. |
|
168 | + * @return float |
|
169 | + */ |
|
170 | + public function get_quantity( $context = 'view' ) { |
|
171 | + $quantity = (float) $this->quantity; |
|
172 | + |
|
173 | + if ( 'view' === $context ) { |
|
174 | + return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this ); |
|
175 | + } |
|
176 | + |
|
177 | + return $quantity; |
|
178 | + |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * Get the item meta data. |
|
183 | + * |
|
184 | + * @since 1.0.19 |
|
185 | + * @param string $context View or edit context. |
|
186 | + * @return meta |
|
187 | + */ |
|
188 | + public function get_item_meta( $context = 'view' ) { |
|
189 | + $meta = $this->meta; |
|
190 | + |
|
191 | + if ( 'view' === $context ) { |
|
192 | + return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this ); |
|
193 | + } |
|
194 | + |
|
195 | + return $meta; |
|
196 | + |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * Returns whether or not customers can update the item quantity. |
|
201 | + * |
|
202 | + * @since 1.0.19 |
|
203 | + * @param string $context View or edit context. |
|
204 | + * @return bool |
|
205 | + */ |
|
206 | + public function get_allow_quantities( $context = 'view' ) { |
|
207 | + $allow_quantities = (bool) $this->allow_quantities; |
|
208 | + |
|
209 | + if ( 'view' === $context ) { |
|
210 | + return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this ); |
|
211 | + } |
|
212 | + |
|
213 | + return $allow_quantities; |
|
214 | + |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * Returns whether or not the item is required. |
|
219 | + * |
|
220 | + * @since 1.0.19 |
|
221 | + * @param string $context View or edit context. |
|
222 | + * @return bool |
|
223 | + */ |
|
224 | + public function get_is_required( $context = 'view' ) { |
|
225 | + $is_required = (bool) $this->is_required; |
|
226 | + |
|
227 | + if ( 'view' === $context ) { |
|
228 | + return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this ); |
|
229 | + } |
|
230 | + |
|
231 | + return $is_required; |
|
232 | + |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * Prepares form data for use. |
|
237 | + * |
|
238 | + * @since 1.0.19 |
|
239 | + * @return array |
|
240 | + */ |
|
241 | + public function prepare_data_for_use( $required = null ) { |
|
242 | + |
|
243 | + $required = is_null( $required ) ? $this->is_required() : $required; |
|
244 | + return array( |
|
245 | + 'title' => wp_strip_all_tags( $this->get_name() ), |
|
246 | + 'id' => $this->get_id(), |
|
247 | + 'price' => $this->get_price(), |
|
248 | + 'recurring' => $this->is_recurring(), |
|
249 | + 'description' => $this->get_description(), |
|
250 | + 'allow_quantities' => $this->allows_quantities(), |
|
251 | + 'required' => $required, |
|
252 | + ); |
|
253 | + |
|
254 | + } |
|
255 | + |
|
256 | + /** |
|
257 | + * Prepares form data for ajax use. |
|
258 | + * |
|
259 | + * @since 1.0.19 |
|
260 | + * @return array |
|
261 | + */ |
|
262 | + public function prepare_data_for_invoice_edit_ajax( $currency = '', $is_renewal = false ) { |
|
263 | + |
|
264 | + $description = getpaid_item_recurring_price_help_text( $this, $currency ); |
|
265 | + |
|
266 | + if ( $description ) { |
|
267 | + $description = "<div class='getpaid-subscription-help-text'>$description</div>"; |
|
268 | + } |
|
269 | + |
|
270 | + $price = ! $is_renewal ? $this->get_price() : $this->get_recurring_price(); |
|
271 | + $subtotal = ! $is_renewal ? $this->get_sub_total() : $this->get_recurring_sub_total(); |
|
272 | + return array( |
|
273 | + 'id' => $this->get_id(), |
|
274 | + 'texts' => array( |
|
275 | + 'item-name' => sanitize_text_field( $this->get_name() ), |
|
276 | + 'item-description' => wp_kses_post( $this->get_description() ) . $description, |
|
277 | + 'item-quantity' => floatval( $this->get_quantity() ), |
|
278 | + 'item-price' => wpinv_price( $price, $currency ), |
|
279 | + 'item-total' => wpinv_price( $subtotal, $currency ), |
|
280 | + ), |
|
281 | + 'inputs' => array( |
|
282 | + 'item-id' => $this->get_id(), |
|
283 | + 'item-name' => sanitize_text_field( $this->get_name() ), |
|
284 | + 'item-description' => wp_kses_post( $this->get_description() ), |
|
285 | + 'item-quantity' => floatval( $this->get_quantity() ), |
|
286 | + 'item-price' => $price, |
|
287 | + ), |
|
288 | + ); |
|
289 | + |
|
290 | + } |
|
291 | + |
|
292 | + /** |
|
293 | + * Prepares form data for saving (cart_details). |
|
294 | + * |
|
295 | + * @since 1.0.19 |
|
296 | + * @return array |
|
297 | + */ |
|
298 | + public function prepare_data_for_saving() { |
|
299 | + |
|
300 | + return array( |
|
301 | + 'post_id' => $this->invoice_id, |
|
302 | + 'item_id' => $this->get_id(), |
|
303 | + 'item_name' => sanitize_text_field( $this->get_raw_name( 'edit' ) ), |
|
304 | + 'item_description' => $this->get_description( 'edit' ), |
|
305 | + 'tax' => $this->item_tax, |
|
306 | + 'item_price' => $this->get_price( 'edit' ), |
|
307 | + 'quantity' => (float) $this->get_quantity( 'edit' ), |
|
308 | + 'discount' => $this->item_discount, |
|
309 | + 'subtotal' => $this->get_sub_total( 'edit' ), |
|
310 | + 'price' => $this->get_sub_total( 'edit' ) + $this->item_tax - $this->item_discount, |
|
311 | + 'meta' => $this->get_item_meta( 'edit' ), |
|
312 | + ); |
|
313 | + |
|
314 | + } |
|
315 | 315 | |
316 | 316 | /* |
317 | 317 | |-------------------------------------------------------------------------- |
@@ -323,70 +323,70 @@ discard block |
||
323 | 323 | | object. |
324 | 324 | */ |
325 | 325 | |
326 | - /** |
|
327 | - * Set the item qantity. |
|
328 | - * |
|
329 | - * @since 1.0.19 |
|
330 | - * @param float $quantity The item quantity. |
|
331 | - */ |
|
332 | - public function set_quantity( $quantity ) { |
|
333 | - |
|
334 | - if ( ! is_numeric( $quantity ) ) { |
|
335 | - $quantity = 1; |
|
336 | - } |
|
337 | - |
|
338 | - $this->quantity = (float) $quantity; |
|
339 | - |
|
340 | - } |
|
341 | - |
|
342 | - /** |
|
343 | - * Set the item meta data. |
|
344 | - * |
|
345 | - * @since 1.0.19 |
|
346 | - * @param array $meta The item meta data. |
|
347 | - */ |
|
348 | - public function set_item_meta( $meta ) { |
|
349 | - $this->meta = maybe_unserialize( $meta ); |
|
350 | - } |
|
351 | - |
|
352 | - /** |
|
353 | - * Set whether or not the quantities are allowed. |
|
354 | - * |
|
355 | - * @since 1.0.19 |
|
356 | - * @param bool $allow_quantities |
|
357 | - */ |
|
358 | - public function set_allow_quantities( $allow_quantities ) { |
|
359 | - $this->allow_quantities = (bool) $allow_quantities; |
|
360 | - } |
|
361 | - |
|
362 | - /** |
|
363 | - * Set whether or not the item is required. |
|
364 | - * |
|
365 | - * @since 1.0.19 |
|
366 | - * @param bool $is_required |
|
367 | - */ |
|
368 | - public function set_is_required( $is_required ) { |
|
369 | - $this->is_required = (bool) $is_required; |
|
370 | - } |
|
371 | - |
|
372 | - /** |
|
373 | - * Sets the custom item description. |
|
374 | - * |
|
375 | - * @since 1.0.19 |
|
376 | - * @param string $description |
|
377 | - */ |
|
378 | - public function set_custom_description( $description ) { |
|
379 | - $this->custom_description = $description; |
|
380 | - } |
|
326 | + /** |
|
327 | + * Set the item qantity. |
|
328 | + * |
|
329 | + * @since 1.0.19 |
|
330 | + * @param float $quantity The item quantity. |
|
331 | + */ |
|
332 | + public function set_quantity( $quantity ) { |
|
333 | + |
|
334 | + if ( ! is_numeric( $quantity ) ) { |
|
335 | + $quantity = 1; |
|
336 | + } |
|
337 | + |
|
338 | + $this->quantity = (float) $quantity; |
|
339 | + |
|
340 | + } |
|
341 | + |
|
342 | + /** |
|
343 | + * Set the item meta data. |
|
344 | + * |
|
345 | + * @since 1.0.19 |
|
346 | + * @param array $meta The item meta data. |
|
347 | + */ |
|
348 | + public function set_item_meta( $meta ) { |
|
349 | + $this->meta = maybe_unserialize( $meta ); |
|
350 | + } |
|
351 | + |
|
352 | + /** |
|
353 | + * Set whether or not the quantities are allowed. |
|
354 | + * |
|
355 | + * @since 1.0.19 |
|
356 | + * @param bool $allow_quantities |
|
357 | + */ |
|
358 | + public function set_allow_quantities( $allow_quantities ) { |
|
359 | + $this->allow_quantities = (bool) $allow_quantities; |
|
360 | + } |
|
361 | + |
|
362 | + /** |
|
363 | + * Set whether or not the item is required. |
|
364 | + * |
|
365 | + * @since 1.0.19 |
|
366 | + * @param bool $is_required |
|
367 | + */ |
|
368 | + public function set_is_required( $is_required ) { |
|
369 | + $this->is_required = (bool) $is_required; |
|
370 | + } |
|
371 | + |
|
372 | + /** |
|
373 | + * Sets the custom item description. |
|
374 | + * |
|
375 | + * @since 1.0.19 |
|
376 | + * @param string $description |
|
377 | + */ |
|
378 | + public function set_custom_description( $description ) { |
|
379 | + $this->custom_description = $description; |
|
380 | + } |
|
381 | 381 | |
382 | 382 | /** |
383 | 383 | * We do not want to save items to the database. |
384 | 384 | * |
385 | - * @return int item id |
|
385 | + * @return int item id |
|
386 | 386 | */ |
387 | 387 | public function save( $data = array() ) { |
388 | 388 | return $this->get_id(); |
389 | - } |
|
389 | + } |
|
390 | 390 | |
391 | 391 | /* |
392 | 392 | |-------------------------------------------------------------------------- |
@@ -398,23 +398,23 @@ discard block |
||
398 | 398 | */ |
399 | 399 | |
400 | 400 | /** |
401 | - * Checks whether the item has enabled dynamic pricing. |
|
402 | - * |
|
403 | - * @since 1.0.19 |
|
404 | - * @return bool |
|
405 | - */ |
|
406 | - public function is_required() { |
|
401 | + * Checks whether the item has enabled dynamic pricing. |
|
402 | + * |
|
403 | + * @since 1.0.19 |
|
404 | + * @return bool |
|
405 | + */ |
|
406 | + public function is_required() { |
|
407 | 407 | return (bool) $this->get_is_required(); |
408 | - } |
|
409 | - |
|
410 | - /** |
|
411 | - * Checks whether users can edit the quantities. |
|
412 | - * |
|
413 | - * @since 1.0.19 |
|
414 | - * @return bool |
|
415 | - */ |
|
416 | - public function allows_quantities() { |
|
408 | + } |
|
409 | + |
|
410 | + /** |
|
411 | + * Checks whether users can edit the quantities. |
|
412 | + * |
|
413 | + * @since 1.0.19 |
|
414 | + * @return bool |
|
415 | + */ |
|
416 | + public function allows_quantities() { |
|
417 | 417 | return (bool) $this->get_allow_quantities(); |
418 | - } |
|
418 | + } |
|
419 | 419 | |
420 | 420 | } |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * Bail if we are not in WP. |
14 | 14 | */ |
15 | 15 | if ( ! defined( 'ABSPATH' ) ) { |
16 | - exit; |
|
16 | + exit; |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
@@ -21,362 +21,362 @@ discard block |
||
21 | 21 | */ |
22 | 22 | if ( ! class_exists( 'WP_Font_Awesome_Settings' ) ) { |
23 | 23 | |
24 | - /** |
|
25 | - * A Class to be able to change settings for Font Awesome. |
|
26 | - * |
|
27 | - * Class WP_Font_Awesome_Settings |
|
28 | - * @since 1.0.10 Now able to pass wp.org theme check. |
|
29 | - * @since 1.0.11 Font Awesome Pro now supported. |
|
30 | - * @since 1.0.11 Font Awesome Kits now supported. |
|
31 | - * @since 1.0.13 RTL language support added. |
|
32 | - * @since 1.0.14 Warning added for v6 pro requires kit and will now not work if official FA plugin installed. |
|
33 | - * @since 1.0.15 Font Awesome will now load in the FSE if enable din the backend. |
|
34 | - * @since 1.1.0 Option added to load FontAwesome locally. |
|
35 | - * @since 1.1.1 Requires to re-save settings to load locally when option does not exists - FIXED. |
|
36 | - * @since 1.1.2 Bumped the latest version to 6.3.0 - CHANGED. |
|
37 | - * @ver 1.0.15 |
|
38 | - * @todo decide how to implement textdomain |
|
39 | - */ |
|
40 | - class WP_Font_Awesome_Settings { |
|
41 | - |
|
42 | - /** |
|
43 | - * Class version version. |
|
44 | - * |
|
45 | - * @var string |
|
46 | - */ |
|
47 | - public $version = '1.1.2'; |
|
48 | - |
|
49 | - /** |
|
50 | - * Class textdomain. |
|
51 | - * |
|
52 | - * @var string |
|
53 | - */ |
|
54 | - public $textdomain = 'font-awesome-settings'; |
|
55 | - |
|
56 | - /** |
|
57 | - * Latest version of Font Awesome at time of publish published. |
|
58 | - * |
|
59 | - * @var string |
|
60 | - */ |
|
61 | - public $latest = "6.3.0"; |
|
62 | - |
|
63 | - /** |
|
64 | - * The title. |
|
65 | - * |
|
66 | - * @var string |
|
67 | - */ |
|
68 | - public $name = 'Font Awesome'; |
|
69 | - |
|
70 | - /** |
|
71 | - * Holds the settings values. |
|
72 | - * |
|
73 | - * @var array |
|
74 | - */ |
|
75 | - private $settings; |
|
76 | - |
|
77 | - /** |
|
78 | - * WP_Font_Awesome_Settings instance. |
|
79 | - * |
|
80 | - * @access private |
|
81 | - * @since 1.0.0 |
|
82 | - * @var WP_Font_Awesome_Settings There can be only one! |
|
83 | - */ |
|
84 | - private static $instance = null; |
|
85 | - |
|
86 | - /** |
|
87 | - * Main WP_Font_Awesome_Settings Instance. |
|
88 | - * |
|
89 | - * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded. |
|
90 | - * |
|
91 | - * @since 1.0.0 |
|
92 | - * @static |
|
93 | - * @return WP_Font_Awesome_Settings - Main instance. |
|
94 | - */ |
|
95 | - public static function instance() { |
|
96 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
97 | - self::$instance = new WP_Font_Awesome_Settings; |
|
98 | - |
|
99 | - add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
100 | - |
|
101 | - if ( is_admin() ) { |
|
102 | - add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
103 | - add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
104 | - add_action( 'admin_notices', array( self::$instance, 'admin_notices' ) ); |
|
105 | - } |
|
106 | - |
|
107 | - do_action( 'wp_font_awesome_settings_loaded' ); |
|
108 | - } |
|
109 | - |
|
110 | - return self::$instance; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Initiate the settings and add the required action hooks. |
|
115 | - * |
|
116 | - * @since 1.0.8 Settings name wrong - FIXED |
|
117 | - */ |
|
118 | - public function init() { |
|
119 | - // Download fontawesome locally. |
|
120 | - add_action( 'add_option_wp-font-awesome-settings', array( $this, 'add_option_wp_font_awesome_settings' ), 10, 2 ); |
|
121 | - add_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 ); |
|
122 | - |
|
123 | - $this->settings = $this->get_settings(); |
|
124 | - |
|
125 | - // check if the official plugin is active and use that instead if so. |
|
126 | - if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
127 | - |
|
128 | - if ( $this->settings['type'] == 'CSS' ) { |
|
129 | - |
|
130 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
131 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
132 | - } |
|
133 | - |
|
134 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
135 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
136 | - add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_styles' ), 10, 2 ); |
|
137 | - } |
|
138 | - |
|
139 | - } else { |
|
140 | - |
|
141 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
142 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
143 | - } |
|
144 | - |
|
145 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
146 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
147 | - add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_scripts' ), 10, 2 ); |
|
148 | - } |
|
149 | - } |
|
150 | - |
|
151 | - // remove font awesome if set to do so |
|
152 | - if ( $this->settings['dequeue'] == '1' ) { |
|
153 | - add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 ); |
|
154 | - } |
|
155 | - } |
|
156 | - |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * Add FA to the FSE. |
|
161 | - * |
|
162 | - * @param $editor_settings |
|
163 | - * @param $block_editor_context |
|
164 | - * |
|
165 | - * @return array |
|
166 | - */ |
|
167 | - public function enqueue_editor_styles( $editor_settings, $block_editor_context ){ |
|
168 | - |
|
169 | - if ( ! empty( $editor_settings['__unstableResolvedAssets']['styles'] ) ) { |
|
170 | - $url = $this->get_url(); |
|
171 | - $editor_settings['__unstableResolvedAssets']['styles'] .= "<link rel='stylesheet' id='font-awesome-css' href='$url' media='all' />"; |
|
172 | - } |
|
173 | - |
|
174 | - return $editor_settings; |
|
175 | - } |
|
176 | - |
|
177 | - /** |
|
178 | - * Add FA to the FSE. |
|
179 | - * |
|
180 | - * @param $editor_settings |
|
181 | - * @param $block_editor_context |
|
182 | - * |
|
183 | - * @return array |
|
184 | - */ |
|
185 | - public function enqueue_editor_scripts( $editor_settings, $block_editor_context ){ |
|
186 | - |
|
187 | - $url = $this->get_url(); |
|
188 | - $editor_settings['__unstableResolvedAssets']['scripts'] .= "<script src='$url' id='font-awesome-js'></script>"; |
|
189 | - |
|
190 | - return $editor_settings; |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * Adds the Font Awesome styles. |
|
195 | - */ |
|
196 | - public function enqueue_style() { |
|
197 | - // build url |
|
198 | - $url = $this->get_url(); |
|
199 | - $version = ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) ? strip_tags( $this->settings['local_version'] ) : null; |
|
200 | - |
|
201 | - wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
202 | - wp_register_style( 'font-awesome', $url, array(), $version ); |
|
203 | - wp_enqueue_style( 'font-awesome' ); |
|
204 | - |
|
205 | - // RTL language support CSS. |
|
206 | - if ( is_rtl() ) { |
|
207 | - wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() ); |
|
208 | - } |
|
209 | - |
|
210 | - if ( $this->settings['shims'] ) { |
|
211 | - $url = $this->get_url( true ); |
|
212 | - wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
213 | - wp_register_style( 'font-awesome-shims', $url, array(), $version ); |
|
214 | - wp_enqueue_style( 'font-awesome-shims' ); |
|
215 | - } |
|
216 | - } |
|
217 | - |
|
218 | - /** |
|
219 | - * Adds the Font Awesome JS. |
|
220 | - */ |
|
221 | - public function enqueue_scripts() { |
|
222 | - // build url |
|
223 | - $url = $this->get_url(); |
|
224 | - |
|
225 | - $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script'; |
|
226 | - call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there |
|
227 | - wp_register_script( 'font-awesome', $url, array(), null ); |
|
228 | - wp_enqueue_script( 'font-awesome' ); |
|
229 | - |
|
230 | - if ( $this->settings['shims'] ) { |
|
231 | - $url = $this->get_url( true ); |
|
232 | - call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there |
|
233 | - wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
234 | - wp_enqueue_script( 'font-awesome-shims' ); |
|
235 | - } |
|
236 | - } |
|
237 | - |
|
238 | - /** |
|
239 | - * Get the url of the Font Awesome files. |
|
240 | - * |
|
241 | - * @param bool $shims If this is a shim file or not. |
|
242 | - * @param bool $local Load locally if allowed. |
|
243 | - * |
|
244 | - * @return string The url to the file. |
|
245 | - */ |
|
246 | - public function get_url( $shims = false, $local = true ) { |
|
247 | - $script = $shims ? 'v4-shims' : 'all'; |
|
248 | - $sub = $this->settings['pro'] ? 'pro' : 'use'; |
|
249 | - $type = $this->settings['type']; |
|
250 | - $version = $this->settings['version']; |
|
251 | - $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : ''; |
|
252 | - $url = ''; |
|
253 | - |
|
254 | - if ( $type == 'KIT' && $kit_url ) { |
|
255 | - if ( $shims ) { |
|
256 | - // if its a kit then we don't add shims here |
|
257 | - return ''; |
|
258 | - } |
|
259 | - $url .= $kit_url; // CDN |
|
260 | - $url .= "?wpfas=true"; // set our var so our version is not removed |
|
261 | - } else { |
|
262 | - $v = ''; |
|
263 | - // Check and load locally. |
|
264 | - if ( $local && $this->has_local() ) { |
|
265 | - $script .= ".min"; |
|
266 | - $v .= '&ver=' . strip_tags( $this->settings['local_version'] ); |
|
267 | - $url .= $this->get_fonts_url(); // Local fonts url. |
|
268 | - } else { |
|
269 | - $url .= "https://$sub.fontawesome.com/releases/"; // CDN |
|
270 | - $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
271 | - } |
|
272 | - $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
|
273 | - $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
|
274 | - $url .= "?wpfas=true" . $v; // set our var so our version is not removed |
|
275 | - } |
|
276 | - |
|
277 | - return $url; |
|
278 | - } |
|
279 | - |
|
280 | - /** |
|
281 | - * Try and remove any other versions of Font Awesome added by other plugins/themes. |
|
282 | - * |
|
283 | - * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version. |
|
284 | - * |
|
285 | - * @param $url |
|
286 | - * @param $original_url |
|
287 | - * @param $_context |
|
288 | - * |
|
289 | - * @return string The filtered url. |
|
290 | - */ |
|
291 | - public function remove_font_awesome( $url, $original_url, $_context ) { |
|
292 | - |
|
293 | - if ( $_context == 'display' |
|
294 | - && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) |
|
295 | - && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false ) |
|
296 | - ) {// it's a font-awesome-url (probably) |
|
297 | - |
|
298 | - if ( strstr( $url, "wpfas=true" ) !== false ) { |
|
299 | - if ( $this->settings['type'] == 'JS' ) { |
|
300 | - if ( $this->settings['js-pseudo'] ) { |
|
301 | - $url .= "' data-search-pseudo-elements defer='defer"; |
|
302 | - } else { |
|
303 | - $url .= "' defer='defer"; |
|
304 | - } |
|
305 | - } |
|
306 | - } else { |
|
307 | - $url = ''; // removing the url removes the file |
|
308 | - } |
|
309 | - |
|
310 | - } |
|
311 | - |
|
312 | - return $url; |
|
313 | - } |
|
314 | - |
|
315 | - /** |
|
316 | - * Register the database settings with WordPress. |
|
317 | - */ |
|
318 | - public function register_settings() { |
|
319 | - register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
320 | - } |
|
321 | - |
|
322 | - /** |
|
323 | - * Add the WordPress settings menu item. |
|
324 | - * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
325 | - */ |
|
326 | - public function menu_item() { |
|
327 | - $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
328 | - call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
329 | - $this, |
|
330 | - 'settings_page' |
|
331 | - ) ); |
|
332 | - } |
|
333 | - |
|
334 | - /** |
|
335 | - * Get the current Font Awesome output settings. |
|
336 | - * |
|
337 | - * @return array The array of settings. |
|
338 | - */ |
|
339 | - public function get_settings() { |
|
340 | - $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
341 | - |
|
342 | - $defaults = array( |
|
343 | - 'type' => 'CSS', // type to use, CSS or JS or KIT |
|
344 | - 'version' => '', // latest |
|
345 | - 'enqueue' => '', // front and backend |
|
346 | - 'shims' => '0', // default OFF now in 2020 |
|
347 | - 'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive) |
|
348 | - 'dequeue' => '0', // if we should try to remove other versions added by other plugins/themes |
|
349 | - 'pro' => '0', // if pro CDN url should be used |
|
350 | - 'local' => '0', // Store fonts locally. |
|
351 | - 'local_version' => '', // Local fonts version. |
|
352 | - 'kit-url' => '', // the kit url |
|
353 | - ); |
|
354 | - |
|
355 | - $settings = wp_parse_args( $db_settings, $defaults ); |
|
356 | - |
|
357 | - /** |
|
358 | - * Filter the Font Awesome settings. |
|
359 | - * |
|
360 | - * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
361 | - */ |
|
362 | - return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults ); |
|
363 | - } |
|
364 | - |
|
365 | - /** |
|
366 | - * The settings page html output. |
|
367 | - */ |
|
368 | - public function settings_page() { |
|
369 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
370 | - wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) ); |
|
371 | - } |
|
372 | - |
|
373 | - // a hidden way to force the update of the version number via api instead of waiting the 48 hours |
|
374 | - if ( isset( $_REQUEST['force-version-check'] ) ) { |
|
375 | - $this->get_latest_version( $force_api = true ); |
|
376 | - } |
|
377 | - |
|
378 | - if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
379 | - ?> |
|
24 | + /** |
|
25 | + * A Class to be able to change settings for Font Awesome. |
|
26 | + * |
|
27 | + * Class WP_Font_Awesome_Settings |
|
28 | + * @since 1.0.10 Now able to pass wp.org theme check. |
|
29 | + * @since 1.0.11 Font Awesome Pro now supported. |
|
30 | + * @since 1.0.11 Font Awesome Kits now supported. |
|
31 | + * @since 1.0.13 RTL language support added. |
|
32 | + * @since 1.0.14 Warning added for v6 pro requires kit and will now not work if official FA plugin installed. |
|
33 | + * @since 1.0.15 Font Awesome will now load in the FSE if enable din the backend. |
|
34 | + * @since 1.1.0 Option added to load FontAwesome locally. |
|
35 | + * @since 1.1.1 Requires to re-save settings to load locally when option does not exists - FIXED. |
|
36 | + * @since 1.1.2 Bumped the latest version to 6.3.0 - CHANGED. |
|
37 | + * @ver 1.0.15 |
|
38 | + * @todo decide how to implement textdomain |
|
39 | + */ |
|
40 | + class WP_Font_Awesome_Settings { |
|
41 | + |
|
42 | + /** |
|
43 | + * Class version version. |
|
44 | + * |
|
45 | + * @var string |
|
46 | + */ |
|
47 | + public $version = '1.1.2'; |
|
48 | + |
|
49 | + /** |
|
50 | + * Class textdomain. |
|
51 | + * |
|
52 | + * @var string |
|
53 | + */ |
|
54 | + public $textdomain = 'font-awesome-settings'; |
|
55 | + |
|
56 | + /** |
|
57 | + * Latest version of Font Awesome at time of publish published. |
|
58 | + * |
|
59 | + * @var string |
|
60 | + */ |
|
61 | + public $latest = "6.3.0"; |
|
62 | + |
|
63 | + /** |
|
64 | + * The title. |
|
65 | + * |
|
66 | + * @var string |
|
67 | + */ |
|
68 | + public $name = 'Font Awesome'; |
|
69 | + |
|
70 | + /** |
|
71 | + * Holds the settings values. |
|
72 | + * |
|
73 | + * @var array |
|
74 | + */ |
|
75 | + private $settings; |
|
76 | + |
|
77 | + /** |
|
78 | + * WP_Font_Awesome_Settings instance. |
|
79 | + * |
|
80 | + * @access private |
|
81 | + * @since 1.0.0 |
|
82 | + * @var WP_Font_Awesome_Settings There can be only one! |
|
83 | + */ |
|
84 | + private static $instance = null; |
|
85 | + |
|
86 | + /** |
|
87 | + * Main WP_Font_Awesome_Settings Instance. |
|
88 | + * |
|
89 | + * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded. |
|
90 | + * |
|
91 | + * @since 1.0.0 |
|
92 | + * @static |
|
93 | + * @return WP_Font_Awesome_Settings - Main instance. |
|
94 | + */ |
|
95 | + public static function instance() { |
|
96 | + if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
97 | + self::$instance = new WP_Font_Awesome_Settings; |
|
98 | + |
|
99 | + add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
100 | + |
|
101 | + if ( is_admin() ) { |
|
102 | + add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
103 | + add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
104 | + add_action( 'admin_notices', array( self::$instance, 'admin_notices' ) ); |
|
105 | + } |
|
106 | + |
|
107 | + do_action( 'wp_font_awesome_settings_loaded' ); |
|
108 | + } |
|
109 | + |
|
110 | + return self::$instance; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Initiate the settings and add the required action hooks. |
|
115 | + * |
|
116 | + * @since 1.0.8 Settings name wrong - FIXED |
|
117 | + */ |
|
118 | + public function init() { |
|
119 | + // Download fontawesome locally. |
|
120 | + add_action( 'add_option_wp-font-awesome-settings', array( $this, 'add_option_wp_font_awesome_settings' ), 10, 2 ); |
|
121 | + add_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 ); |
|
122 | + |
|
123 | + $this->settings = $this->get_settings(); |
|
124 | + |
|
125 | + // check if the official plugin is active and use that instead if so. |
|
126 | + if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
127 | + |
|
128 | + if ( $this->settings['type'] == 'CSS' ) { |
|
129 | + |
|
130 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
131 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
132 | + } |
|
133 | + |
|
134 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
135 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
136 | + add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_styles' ), 10, 2 ); |
|
137 | + } |
|
138 | + |
|
139 | + } else { |
|
140 | + |
|
141 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
142 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
143 | + } |
|
144 | + |
|
145 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
146 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
147 | + add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_scripts' ), 10, 2 ); |
|
148 | + } |
|
149 | + } |
|
150 | + |
|
151 | + // remove font awesome if set to do so |
|
152 | + if ( $this->settings['dequeue'] == '1' ) { |
|
153 | + add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 ); |
|
154 | + } |
|
155 | + } |
|
156 | + |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * Add FA to the FSE. |
|
161 | + * |
|
162 | + * @param $editor_settings |
|
163 | + * @param $block_editor_context |
|
164 | + * |
|
165 | + * @return array |
|
166 | + */ |
|
167 | + public function enqueue_editor_styles( $editor_settings, $block_editor_context ){ |
|
168 | + |
|
169 | + if ( ! empty( $editor_settings['__unstableResolvedAssets']['styles'] ) ) { |
|
170 | + $url = $this->get_url(); |
|
171 | + $editor_settings['__unstableResolvedAssets']['styles'] .= "<link rel='stylesheet' id='font-awesome-css' href='$url' media='all' />"; |
|
172 | + } |
|
173 | + |
|
174 | + return $editor_settings; |
|
175 | + } |
|
176 | + |
|
177 | + /** |
|
178 | + * Add FA to the FSE. |
|
179 | + * |
|
180 | + * @param $editor_settings |
|
181 | + * @param $block_editor_context |
|
182 | + * |
|
183 | + * @return array |
|
184 | + */ |
|
185 | + public function enqueue_editor_scripts( $editor_settings, $block_editor_context ){ |
|
186 | + |
|
187 | + $url = $this->get_url(); |
|
188 | + $editor_settings['__unstableResolvedAssets']['scripts'] .= "<script src='$url' id='font-awesome-js'></script>"; |
|
189 | + |
|
190 | + return $editor_settings; |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * Adds the Font Awesome styles. |
|
195 | + */ |
|
196 | + public function enqueue_style() { |
|
197 | + // build url |
|
198 | + $url = $this->get_url(); |
|
199 | + $version = ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) ? strip_tags( $this->settings['local_version'] ) : null; |
|
200 | + |
|
201 | + wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
202 | + wp_register_style( 'font-awesome', $url, array(), $version ); |
|
203 | + wp_enqueue_style( 'font-awesome' ); |
|
204 | + |
|
205 | + // RTL language support CSS. |
|
206 | + if ( is_rtl() ) { |
|
207 | + wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() ); |
|
208 | + } |
|
209 | + |
|
210 | + if ( $this->settings['shims'] ) { |
|
211 | + $url = $this->get_url( true ); |
|
212 | + wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
213 | + wp_register_style( 'font-awesome-shims', $url, array(), $version ); |
|
214 | + wp_enqueue_style( 'font-awesome-shims' ); |
|
215 | + } |
|
216 | + } |
|
217 | + |
|
218 | + /** |
|
219 | + * Adds the Font Awesome JS. |
|
220 | + */ |
|
221 | + public function enqueue_scripts() { |
|
222 | + // build url |
|
223 | + $url = $this->get_url(); |
|
224 | + |
|
225 | + $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script'; |
|
226 | + call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there |
|
227 | + wp_register_script( 'font-awesome', $url, array(), null ); |
|
228 | + wp_enqueue_script( 'font-awesome' ); |
|
229 | + |
|
230 | + if ( $this->settings['shims'] ) { |
|
231 | + $url = $this->get_url( true ); |
|
232 | + call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there |
|
233 | + wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
234 | + wp_enqueue_script( 'font-awesome-shims' ); |
|
235 | + } |
|
236 | + } |
|
237 | + |
|
238 | + /** |
|
239 | + * Get the url of the Font Awesome files. |
|
240 | + * |
|
241 | + * @param bool $shims If this is a shim file or not. |
|
242 | + * @param bool $local Load locally if allowed. |
|
243 | + * |
|
244 | + * @return string The url to the file. |
|
245 | + */ |
|
246 | + public function get_url( $shims = false, $local = true ) { |
|
247 | + $script = $shims ? 'v4-shims' : 'all'; |
|
248 | + $sub = $this->settings['pro'] ? 'pro' : 'use'; |
|
249 | + $type = $this->settings['type']; |
|
250 | + $version = $this->settings['version']; |
|
251 | + $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : ''; |
|
252 | + $url = ''; |
|
253 | + |
|
254 | + if ( $type == 'KIT' && $kit_url ) { |
|
255 | + if ( $shims ) { |
|
256 | + // if its a kit then we don't add shims here |
|
257 | + return ''; |
|
258 | + } |
|
259 | + $url .= $kit_url; // CDN |
|
260 | + $url .= "?wpfas=true"; // set our var so our version is not removed |
|
261 | + } else { |
|
262 | + $v = ''; |
|
263 | + // Check and load locally. |
|
264 | + if ( $local && $this->has_local() ) { |
|
265 | + $script .= ".min"; |
|
266 | + $v .= '&ver=' . strip_tags( $this->settings['local_version'] ); |
|
267 | + $url .= $this->get_fonts_url(); // Local fonts url. |
|
268 | + } else { |
|
269 | + $url .= "https://$sub.fontawesome.com/releases/"; // CDN |
|
270 | + $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
271 | + } |
|
272 | + $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
|
273 | + $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
|
274 | + $url .= "?wpfas=true" . $v; // set our var so our version is not removed |
|
275 | + } |
|
276 | + |
|
277 | + return $url; |
|
278 | + } |
|
279 | + |
|
280 | + /** |
|
281 | + * Try and remove any other versions of Font Awesome added by other plugins/themes. |
|
282 | + * |
|
283 | + * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version. |
|
284 | + * |
|
285 | + * @param $url |
|
286 | + * @param $original_url |
|
287 | + * @param $_context |
|
288 | + * |
|
289 | + * @return string The filtered url. |
|
290 | + */ |
|
291 | + public function remove_font_awesome( $url, $original_url, $_context ) { |
|
292 | + |
|
293 | + if ( $_context == 'display' |
|
294 | + && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) |
|
295 | + && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false ) |
|
296 | + ) {// it's a font-awesome-url (probably) |
|
297 | + |
|
298 | + if ( strstr( $url, "wpfas=true" ) !== false ) { |
|
299 | + if ( $this->settings['type'] == 'JS' ) { |
|
300 | + if ( $this->settings['js-pseudo'] ) { |
|
301 | + $url .= "' data-search-pseudo-elements defer='defer"; |
|
302 | + } else { |
|
303 | + $url .= "' defer='defer"; |
|
304 | + } |
|
305 | + } |
|
306 | + } else { |
|
307 | + $url = ''; // removing the url removes the file |
|
308 | + } |
|
309 | + |
|
310 | + } |
|
311 | + |
|
312 | + return $url; |
|
313 | + } |
|
314 | + |
|
315 | + /** |
|
316 | + * Register the database settings with WordPress. |
|
317 | + */ |
|
318 | + public function register_settings() { |
|
319 | + register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
320 | + } |
|
321 | + |
|
322 | + /** |
|
323 | + * Add the WordPress settings menu item. |
|
324 | + * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
325 | + */ |
|
326 | + public function menu_item() { |
|
327 | + $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
328 | + call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
329 | + $this, |
|
330 | + 'settings_page' |
|
331 | + ) ); |
|
332 | + } |
|
333 | + |
|
334 | + /** |
|
335 | + * Get the current Font Awesome output settings. |
|
336 | + * |
|
337 | + * @return array The array of settings. |
|
338 | + */ |
|
339 | + public function get_settings() { |
|
340 | + $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
341 | + |
|
342 | + $defaults = array( |
|
343 | + 'type' => 'CSS', // type to use, CSS or JS or KIT |
|
344 | + 'version' => '', // latest |
|
345 | + 'enqueue' => '', // front and backend |
|
346 | + 'shims' => '0', // default OFF now in 2020 |
|
347 | + 'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive) |
|
348 | + 'dequeue' => '0', // if we should try to remove other versions added by other plugins/themes |
|
349 | + 'pro' => '0', // if pro CDN url should be used |
|
350 | + 'local' => '0', // Store fonts locally. |
|
351 | + 'local_version' => '', // Local fonts version. |
|
352 | + 'kit-url' => '', // the kit url |
|
353 | + ); |
|
354 | + |
|
355 | + $settings = wp_parse_args( $db_settings, $defaults ); |
|
356 | + |
|
357 | + /** |
|
358 | + * Filter the Font Awesome settings. |
|
359 | + * |
|
360 | + * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
361 | + */ |
|
362 | + return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults ); |
|
363 | + } |
|
364 | + |
|
365 | + /** |
|
366 | + * The settings page html output. |
|
367 | + */ |
|
368 | + public function settings_page() { |
|
369 | + if ( ! current_user_can( 'manage_options' ) ) { |
|
370 | + wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) ); |
|
371 | + } |
|
372 | + |
|
373 | + // a hidden way to force the update of the version number via api instead of waiting the 48 hours |
|
374 | + if ( isset( $_REQUEST['force-version-check'] ) ) { |
|
375 | + $this->get_latest_version( $force_api = true ); |
|
376 | + } |
|
377 | + |
|
378 | + if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
379 | + ?> |
|
380 | 380 | <style> |
381 | 381 | .wpfas-kit-show { |
382 | 382 | display: none; |
@@ -402,16 +402,16 @@ discard block |
||
402 | 402 | <h1><?php echo $this->name; ?></h1> |
403 | 403 | <form method="post" action="options.php" class="fas-settings-form"> |
404 | 404 | <?php |
405 | - settings_fields( 'wp-font-awesome-settings' ); |
|
406 | - do_settings_sections( 'wp-font-awesome-settings' ); |
|
407 | - $table_class = ''; |
|
408 | - if ( $this->settings['type'] ) { |
|
409 | - $table_class .= 'wpfas-' . sanitize_html_class( strtolower( $this->settings['type'] ) ) . '-set'; |
|
410 | - } |
|
411 | - if ( ! empty( $this->settings['pro'] ) ) { |
|
412 | - $table_class .= ' wpfas-has-pro'; |
|
413 | - } |
|
414 | - ?> |
|
405 | + settings_fields( 'wp-font-awesome-settings' ); |
|
406 | + do_settings_sections( 'wp-font-awesome-settings' ); |
|
407 | + $table_class = ''; |
|
408 | + if ( $this->settings['type'] ) { |
|
409 | + $table_class .= 'wpfas-' . sanitize_html_class( strtolower( $this->settings['type'] ) ) . '-set'; |
|
410 | + } |
|
411 | + if ( ! empty( $this->settings['pro'] ) ) { |
|
412 | + $table_class .= ' wpfas-has-pro'; |
|
413 | + } |
|
414 | + ?> |
|
415 | 415 | <?php if ( $this->settings['type'] != 'KIT' && ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) ) { ?> |
416 | 416 | <?php if ( $this->has_local() ) { ?> |
417 | 417 | <div class="notice notice-info"><p><strong><?php _e( 'Font Awesome fonts are loading locally.', 'font-awesome-settings' ); ?></strong></p></div> |
@@ -436,12 +436,12 @@ discard block |
||
436 | 436 | <td> |
437 | 437 | <input class="regular-text" id="wpfas-kit-url" type="url" name="wp-font-awesome-settings[kit-url]" value="<?php echo esc_attr( $this->settings['kit-url'] ); ?>" placeholder="<?php echo 'https://kit.font';echo 'awesome.com/123abc.js'; // this won't pass theme check :(?>"/> |
438 | 438 | <span><?php |
439 | - echo sprintf( |
|
440 | - __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ), |
|
441 | - '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>', |
|
442 | - '</a>' |
|
443 | - ); |
|
444 | - ?></span> |
|
439 | + echo sprintf( |
|
440 | + __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ), |
|
441 | + '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>', |
|
442 | + '</a>' |
|
443 | + ); |
|
444 | + ?></span> |
|
445 | 445 | </td> |
446 | 446 | </tr> |
447 | 447 | |
@@ -482,14 +482,14 @@ discard block |
||
482 | 482 | <input type="hidden" name="wp-font-awesome-settings[pro]" value="0"/> |
483 | 483 | <input type="checkbox" name="wp-font-awesome-settings[pro]" value="1" <?php checked( $this->settings['pro'], '1' ); ?> id="wpfas-pro" onchange="if(jQuery(this).is(':checked')){jQuery('.wpfas-table-settings').addClass('wpfas-has-pro')}else{jQuery('.wpfas-table-settings').removeClass('wpfas-has-pro')}"/> |
484 | 484 | <span><?php |
485 | - echo wp_sprintf( |
|
486 | - __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings' ), |
|
487 | - '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/referral?a=c9b89e1418">', |
|
488 | - ' <i class="fas fa-external-link-alt"></i></a>', |
|
489 | - '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn">', |
|
490 | - ' <i class="fas fa-external-link-alt"></i></a>' |
|
491 | - ); |
|
492 | - ?></span> |
|
485 | + echo wp_sprintf( |
|
486 | + __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings' ), |
|
487 | + '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/referral?a=c9b89e1418">', |
|
488 | + ' <i class="fas fa-external-link-alt"></i></a>', |
|
489 | + '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn">', |
|
490 | + ' <i class="fas fa-external-link-alt"></i></a>' |
|
491 | + ); |
|
492 | + ?></span> |
|
493 | 493 | </td> |
494 | 494 | </tr> |
495 | 495 | |
@@ -543,8 +543,8 @@ discard block |
||
543 | 543 | </table> |
544 | 544 | <div class="fas-buttons"> |
545 | 545 | <?php |
546 | - submit_button(); |
|
547 | - ?> |
|
546 | + submit_button(); |
|
547 | + ?> |
|
548 | 548 | <p class="submit"><a href="https://fontawesome.com/referral?a=c9b89e1418" class="button button-secondary"><?php _e('Get 14,000+ more icons with Font Awesome Pro','font-awesome-settings'); ?> <i class="fas fa-external-link-alt"></i></a></p> |
549 | 549 | |
550 | 550 | </div> |
@@ -553,392 +553,392 @@ discard block |
||
553 | 553 | <div id="wpfas-version"><?php echo sprintf(__( 'Version: %s (affiliate links provided)', 'font-awesome-settings' ), $this->version ); ?></div> |
554 | 554 | </div> |
555 | 555 | <?php |
556 | - } |
|
557 | - } |
|
558 | - |
|
559 | - /** |
|
560 | - * Check a version number is valid and if so return it or else return an empty string. |
|
561 | - * |
|
562 | - * @param $version string The version number to check. |
|
563 | - * |
|
564 | - * @since 1.0.6 |
|
565 | - * |
|
566 | - * @return string Either a valid version number or an empty string. |
|
567 | - */ |
|
568 | - public function validate_version_number( $version ) { |
|
569 | - |
|
570 | - if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
|
571 | - // valid |
|
572 | - } else { |
|
573 | - $version = '';// not validated |
|
574 | - } |
|
575 | - |
|
576 | - return $version; |
|
577 | - } |
|
578 | - |
|
579 | - |
|
580 | - /** |
|
581 | - * Get the latest version of Font Awesome. |
|
582 | - * |
|
583 | - * We check for a cached version and if none we will check for a live version via API and then cache it for 48 hours. |
|
584 | - * |
|
585 | - * @since 1.0.7 |
|
586 | - * @return mixed|string The latest version number found. |
|
587 | - */ |
|
588 | - public function get_latest_version( $force_api = false ) { |
|
589 | - $latest_version = $this->latest; |
|
590 | - |
|
591 | - $cache = get_transient( 'wp-font-awesome-settings-version' ); |
|
592 | - |
|
593 | - if ( $cache === false || $force_api ) { // its not set |
|
594 | - $api_ver = $this->get_latest_version_from_api(); |
|
595 | - if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
|
596 | - $latest_version = $api_ver; |
|
597 | - set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
|
598 | - } |
|
599 | - } elseif ( $this->validate_version_number( $cache ) ) { |
|
600 | - if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
|
601 | - $latest_version = $cache; |
|
602 | - } |
|
603 | - } |
|
604 | - |
|
605 | - // Check and auto download fonts locally. |
|
606 | - if ( empty( $this->settings['pro'] ) && empty( $this->settings['version'] ) && $this->settings['type'] != 'KIT' && ! empty( $this->settings['local'] ) && ! empty( $this->settings['local_version'] ) && ! empty( $latest_version ) ) { |
|
607 | - if ( version_compare( $latest_version, $this->settings['local_version'], '>' ) && is_admin() && ! wp_doing_ajax() ) { |
|
608 | - $this->download_package( $latest_version ); |
|
609 | - } |
|
610 | - } |
|
611 | - |
|
612 | - return $latest_version; |
|
613 | - } |
|
614 | - |
|
615 | - /** |
|
616 | - * Get the latest Font Awesome version from the github API. |
|
617 | - * |
|
618 | - * @since 1.0.7 |
|
619 | - * @return string The latest version number or `0` on API fail. |
|
620 | - */ |
|
621 | - public function get_latest_version_from_api() { |
|
622 | - $version = "0"; |
|
623 | - $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" ); |
|
624 | - if ( ! is_wp_error( $response ) && is_array( $response ) ) { |
|
625 | - $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
626 | - if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) { |
|
627 | - $version = $api_response['tag_name']; |
|
628 | - } |
|
629 | - } |
|
630 | - |
|
631 | - return $version; |
|
632 | - } |
|
633 | - |
|
634 | - /** |
|
635 | - * Inline CSS for RTL language support. |
|
636 | - * |
|
637 | - * @since 1.0.13 |
|
638 | - * @return string Inline CSS. |
|
639 | - */ |
|
640 | - public function rtl_inline_css() { |
|
641 | - $inline_css = '[dir=rtl] .fa-address,[dir=rtl] .fa-address-card,[dir=rtl] .fa-adjust,[dir=rtl] .fa-alarm-clock,[dir=rtl] .fa-align-left,[dir=rtl] .fa-align-right,[dir=rtl] .fa-analytics,[dir=rtl] .fa-angle-double-left,[dir=rtl] .fa-angle-double-right,[dir=rtl] .fa-angle-left,[dir=rtl] .fa-angle-right,[dir=rtl] .fa-arrow-alt-circle-left,[dir=rtl] .fa-arrow-alt-circle-right,[dir=rtl] .fa-arrow-alt-from-left,[dir=rtl] .fa-arrow-alt-from-right,[dir=rtl] .fa-arrow-alt-left,[dir=rtl] .fa-arrow-alt-right,[dir=rtl] .fa-arrow-alt-square-left,[dir=rtl] .fa-arrow-alt-square-right,[dir=rtl] .fa-arrow-alt-to-left,[dir=rtl] .fa-arrow-alt-to-right,[dir=rtl] .fa-arrow-circle-left,[dir=rtl] .fa-arrow-circle-right,[dir=rtl] .fa-arrow-from-left,[dir=rtl] .fa-arrow-from-right,[dir=rtl] .fa-arrow-left,[dir=rtl] .fa-arrow-right,[dir=rtl] .fa-arrow-square-left,[dir=rtl] .fa-arrow-square-right,[dir=rtl] .fa-arrow-to-left,[dir=rtl] .fa-arrow-to-right,[dir=rtl] .fa-balance-scale-left,[dir=rtl] .fa-balance-scale-right,[dir=rtl] .fa-bed,[dir=rtl] .fa-bed-bunk,[dir=rtl] .fa-bed-empty,[dir=rtl] .fa-border-left,[dir=rtl] .fa-border-right,[dir=rtl] .fa-calendar-check,[dir=rtl] .fa-caret-circle-left,[dir=rtl] .fa-caret-circle-right,[dir=rtl] .fa-caret-left,[dir=rtl] .fa-caret-right,[dir=rtl] .fa-caret-square-left,[dir=rtl] .fa-caret-square-right,[dir=rtl] .fa-cart-arrow-down,[dir=rtl] .fa-cart-plus,[dir=rtl] .fa-chart-area,[dir=rtl] .fa-chart-bar,[dir=rtl] .fa-chart-line,[dir=rtl] .fa-chart-line-down,[dir=rtl] .fa-chart-network,[dir=rtl] .fa-chart-pie,[dir=rtl] .fa-chart-pie-alt,[dir=rtl] .fa-chart-scatter,[dir=rtl] .fa-check-circle,[dir=rtl] .fa-check-square,[dir=rtl] .fa-chevron-circle-left,[dir=rtl] .fa-chevron-circle-right,[dir=rtl] .fa-chevron-double-left,[dir=rtl] .fa-chevron-double-right,[dir=rtl] .fa-chevron-left,[dir=rtl] .fa-chevron-right,[dir=rtl] .fa-chevron-square-left,[dir=rtl] .fa-chevron-square-right,[dir=rtl] .fa-clock,[dir=rtl] .fa-file,[dir=rtl] .fa-file-alt,[dir=rtl] .fa-file-archive,[dir=rtl] .fa-file-audio,[dir=rtl] .fa-file-chart-line,[dir=rtl] .fa-file-chart-pie,[dir=rtl] .fa-file-code,[dir=rtl] .fa-file-excel,[dir=rtl] .fa-file-image,[dir=rtl] .fa-file-pdf,[dir=rtl] .fa-file-powerpoint,[dir=rtl] .fa-file-video,[dir=rtl] .fa-file-word,[dir=rtl] .fa-flag,[dir=rtl] .fa-folder,[dir=rtl] .fa-folder-open,[dir=rtl] .fa-hand-lizard,[dir=rtl] .fa-hand-point-down,[dir=rtl] .fa-hand-point-left,[dir=rtl] .fa-hand-point-right,[dir=rtl] .fa-hand-point-up,[dir=rtl] .fa-hand-scissors,[dir=rtl] .fa-image,[dir=rtl] .fa-long-arrow-alt-left,[dir=rtl] .fa-long-arrow-alt-right,[dir=rtl] .fa-long-arrow-left,[dir=rtl] .fa-long-arrow-right,[dir=rtl] .fa-luggage-cart,[dir=rtl] .fa-moon,[dir=rtl] .fa-pencil,[dir=rtl] .fa-pencil-alt,[dir=rtl] .fa-play-circle,[dir=rtl] .fa-project-diagram,[dir=rtl] .fa-quote-left,[dir=rtl] .fa-quote-right,[dir=rtl] .fa-shopping-cart,[dir=rtl] .fa-thumbs-down,[dir=rtl] .fa-thumbs-up,[dir=rtl] .fa-user-chart{filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1);transform:scale(-1,1)}[dir=rtl] .fa-spin{animation-direction:reverse}'; |
|
642 | - |
|
643 | - return $inline_css; |
|
644 | - } |
|
645 | - |
|
646 | - /** |
|
647 | - * Show any warnings as an admin notice. |
|
648 | - * |
|
649 | - * @return void |
|
650 | - */ |
|
651 | - public function admin_notices() { |
|
652 | - $settings = $this->settings; |
|
653 | - |
|
654 | - if ( defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
655 | - if ( ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] == 'wp-font-awesome-settings' ) { |
|
656 | - ?> |
|
556 | + } |
|
557 | + } |
|
558 | + |
|
559 | + /** |
|
560 | + * Check a version number is valid and if so return it or else return an empty string. |
|
561 | + * |
|
562 | + * @param $version string The version number to check. |
|
563 | + * |
|
564 | + * @since 1.0.6 |
|
565 | + * |
|
566 | + * @return string Either a valid version number or an empty string. |
|
567 | + */ |
|
568 | + public function validate_version_number( $version ) { |
|
569 | + |
|
570 | + if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
|
571 | + // valid |
|
572 | + } else { |
|
573 | + $version = '';// not validated |
|
574 | + } |
|
575 | + |
|
576 | + return $version; |
|
577 | + } |
|
578 | + |
|
579 | + |
|
580 | + /** |
|
581 | + * Get the latest version of Font Awesome. |
|
582 | + * |
|
583 | + * We check for a cached version and if none we will check for a live version via API and then cache it for 48 hours. |
|
584 | + * |
|
585 | + * @since 1.0.7 |
|
586 | + * @return mixed|string The latest version number found. |
|
587 | + */ |
|
588 | + public function get_latest_version( $force_api = false ) { |
|
589 | + $latest_version = $this->latest; |
|
590 | + |
|
591 | + $cache = get_transient( 'wp-font-awesome-settings-version' ); |
|
592 | + |
|
593 | + if ( $cache === false || $force_api ) { // its not set |
|
594 | + $api_ver = $this->get_latest_version_from_api(); |
|
595 | + if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
|
596 | + $latest_version = $api_ver; |
|
597 | + set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
|
598 | + } |
|
599 | + } elseif ( $this->validate_version_number( $cache ) ) { |
|
600 | + if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
|
601 | + $latest_version = $cache; |
|
602 | + } |
|
603 | + } |
|
604 | + |
|
605 | + // Check and auto download fonts locally. |
|
606 | + if ( empty( $this->settings['pro'] ) && empty( $this->settings['version'] ) && $this->settings['type'] != 'KIT' && ! empty( $this->settings['local'] ) && ! empty( $this->settings['local_version'] ) && ! empty( $latest_version ) ) { |
|
607 | + if ( version_compare( $latest_version, $this->settings['local_version'], '>' ) && is_admin() && ! wp_doing_ajax() ) { |
|
608 | + $this->download_package( $latest_version ); |
|
609 | + } |
|
610 | + } |
|
611 | + |
|
612 | + return $latest_version; |
|
613 | + } |
|
614 | + |
|
615 | + /** |
|
616 | + * Get the latest Font Awesome version from the github API. |
|
617 | + * |
|
618 | + * @since 1.0.7 |
|
619 | + * @return string The latest version number or `0` on API fail. |
|
620 | + */ |
|
621 | + public function get_latest_version_from_api() { |
|
622 | + $version = "0"; |
|
623 | + $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" ); |
|
624 | + if ( ! is_wp_error( $response ) && is_array( $response ) ) { |
|
625 | + $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
626 | + if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) { |
|
627 | + $version = $api_response['tag_name']; |
|
628 | + } |
|
629 | + } |
|
630 | + |
|
631 | + return $version; |
|
632 | + } |
|
633 | + |
|
634 | + /** |
|
635 | + * Inline CSS for RTL language support. |
|
636 | + * |
|
637 | + * @since 1.0.13 |
|
638 | + * @return string Inline CSS. |
|
639 | + */ |
|
640 | + public function rtl_inline_css() { |
|
641 | + $inline_css = '[dir=rtl] .fa-address,[dir=rtl] .fa-address-card,[dir=rtl] .fa-adjust,[dir=rtl] .fa-alarm-clock,[dir=rtl] .fa-align-left,[dir=rtl] .fa-align-right,[dir=rtl] .fa-analytics,[dir=rtl] .fa-angle-double-left,[dir=rtl] .fa-angle-double-right,[dir=rtl] .fa-angle-left,[dir=rtl] .fa-angle-right,[dir=rtl] .fa-arrow-alt-circle-left,[dir=rtl] .fa-arrow-alt-circle-right,[dir=rtl] .fa-arrow-alt-from-left,[dir=rtl] .fa-arrow-alt-from-right,[dir=rtl] .fa-arrow-alt-left,[dir=rtl] .fa-arrow-alt-right,[dir=rtl] .fa-arrow-alt-square-left,[dir=rtl] .fa-arrow-alt-square-right,[dir=rtl] .fa-arrow-alt-to-left,[dir=rtl] .fa-arrow-alt-to-right,[dir=rtl] .fa-arrow-circle-left,[dir=rtl] .fa-arrow-circle-right,[dir=rtl] .fa-arrow-from-left,[dir=rtl] .fa-arrow-from-right,[dir=rtl] .fa-arrow-left,[dir=rtl] .fa-arrow-right,[dir=rtl] .fa-arrow-square-left,[dir=rtl] .fa-arrow-square-right,[dir=rtl] .fa-arrow-to-left,[dir=rtl] .fa-arrow-to-right,[dir=rtl] .fa-balance-scale-left,[dir=rtl] .fa-balance-scale-right,[dir=rtl] .fa-bed,[dir=rtl] .fa-bed-bunk,[dir=rtl] .fa-bed-empty,[dir=rtl] .fa-border-left,[dir=rtl] .fa-border-right,[dir=rtl] .fa-calendar-check,[dir=rtl] .fa-caret-circle-left,[dir=rtl] .fa-caret-circle-right,[dir=rtl] .fa-caret-left,[dir=rtl] .fa-caret-right,[dir=rtl] .fa-caret-square-left,[dir=rtl] .fa-caret-square-right,[dir=rtl] .fa-cart-arrow-down,[dir=rtl] .fa-cart-plus,[dir=rtl] .fa-chart-area,[dir=rtl] .fa-chart-bar,[dir=rtl] .fa-chart-line,[dir=rtl] .fa-chart-line-down,[dir=rtl] .fa-chart-network,[dir=rtl] .fa-chart-pie,[dir=rtl] .fa-chart-pie-alt,[dir=rtl] .fa-chart-scatter,[dir=rtl] .fa-check-circle,[dir=rtl] .fa-check-square,[dir=rtl] .fa-chevron-circle-left,[dir=rtl] .fa-chevron-circle-right,[dir=rtl] .fa-chevron-double-left,[dir=rtl] .fa-chevron-double-right,[dir=rtl] .fa-chevron-left,[dir=rtl] .fa-chevron-right,[dir=rtl] .fa-chevron-square-left,[dir=rtl] .fa-chevron-square-right,[dir=rtl] .fa-clock,[dir=rtl] .fa-file,[dir=rtl] .fa-file-alt,[dir=rtl] .fa-file-archive,[dir=rtl] .fa-file-audio,[dir=rtl] .fa-file-chart-line,[dir=rtl] .fa-file-chart-pie,[dir=rtl] .fa-file-code,[dir=rtl] .fa-file-excel,[dir=rtl] .fa-file-image,[dir=rtl] .fa-file-pdf,[dir=rtl] .fa-file-powerpoint,[dir=rtl] .fa-file-video,[dir=rtl] .fa-file-word,[dir=rtl] .fa-flag,[dir=rtl] .fa-folder,[dir=rtl] .fa-folder-open,[dir=rtl] .fa-hand-lizard,[dir=rtl] .fa-hand-point-down,[dir=rtl] .fa-hand-point-left,[dir=rtl] .fa-hand-point-right,[dir=rtl] .fa-hand-point-up,[dir=rtl] .fa-hand-scissors,[dir=rtl] .fa-image,[dir=rtl] .fa-long-arrow-alt-left,[dir=rtl] .fa-long-arrow-alt-right,[dir=rtl] .fa-long-arrow-left,[dir=rtl] .fa-long-arrow-right,[dir=rtl] .fa-luggage-cart,[dir=rtl] .fa-moon,[dir=rtl] .fa-pencil,[dir=rtl] .fa-pencil-alt,[dir=rtl] .fa-play-circle,[dir=rtl] .fa-project-diagram,[dir=rtl] .fa-quote-left,[dir=rtl] .fa-quote-right,[dir=rtl] .fa-shopping-cart,[dir=rtl] .fa-thumbs-down,[dir=rtl] .fa-thumbs-up,[dir=rtl] .fa-user-chart{filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1);transform:scale(-1,1)}[dir=rtl] .fa-spin{animation-direction:reverse}'; |
|
642 | + |
|
643 | + return $inline_css; |
|
644 | + } |
|
645 | + |
|
646 | + /** |
|
647 | + * Show any warnings as an admin notice. |
|
648 | + * |
|
649 | + * @return void |
|
650 | + */ |
|
651 | + public function admin_notices() { |
|
652 | + $settings = $this->settings; |
|
653 | + |
|
654 | + if ( defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
655 | + if ( ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] == 'wp-font-awesome-settings' ) { |
|
656 | + ?> |
|
657 | 657 | <div class="notice notice-error is-dismissible"> |
658 | 658 | <p><?php _e( 'The Official Font Awesome Plugin is active, please adjust your settings there.', 'font-awesome-settings' ); ?></p> |
659 | 659 | </div> |
660 | 660 | <?php |
661 | - } |
|
662 | - } else { |
|
663 | - if ( ! empty( $settings ) ) { |
|
664 | - if ( $settings['type'] != 'KIT' && $settings['pro'] && ( $settings['version'] == '' || version_compare( $settings['version'], '6', '>=' ) ) ) { |
|
665 | - $link = admin_url('options-general.php?page=wp-font-awesome-settings'); |
|
666 | - ?> |
|
661 | + } |
|
662 | + } else { |
|
663 | + if ( ! empty( $settings ) ) { |
|
664 | + if ( $settings['type'] != 'KIT' && $settings['pro'] && ( $settings['version'] == '' || version_compare( $settings['version'], '6', '>=' ) ) ) { |
|
665 | + $link = admin_url('options-general.php?page=wp-font-awesome-settings'); |
|
666 | + ?> |
|
667 | 667 | <div class="notice notice-error is-dismissible"> |
668 | 668 | <p><?php echo sprintf( __( 'Font Awesome Pro v6 requires the use of a kit, please setup your kit in %ssettings.%s', 'font-awesome-settings' ),"<a href='". esc_url_raw( $link )."'>","</a>" ); ?></p> |
669 | 669 | </div> |
670 | 670 | <?php |
671 | - } |
|
672 | - } |
|
673 | - } |
|
674 | - } |
|
675 | - |
|
676 | - /** |
|
677 | - * Handle fontawesome add settings to download fontawesome to store locally. |
|
678 | - * |
|
679 | - * @since 1.1.1 |
|
680 | - * |
|
681 | - * @param string $option The option name. |
|
682 | - * @param mixed $value The option value. |
|
683 | - */ |
|
684 | - public function add_option_wp_font_awesome_settings( $option, $value ) { |
|
685 | - // Do nothing if WordPress is being installed. |
|
686 | - if ( wp_installing() ) { |
|
687 | - return; |
|
688 | - } |
|
689 | - |
|
690 | - if ( ! empty( $value['local'] ) && empty( $value['pro'] ) && ! ( ! empty( $value['type'] ) && $value['type'] == 'KIT' ) ) { |
|
691 | - $version = isset( $value['version'] ) && $value['version'] ? $value['version'] : $this->get_latest_version(); |
|
692 | - |
|
693 | - if ( ! empty( $version ) ) { |
|
694 | - $response = $this->download_package( $version, $value ); |
|
695 | - |
|
696 | - if ( is_wp_error( $response ) ) { |
|
697 | - add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'font-awesome-settings' ) . ' ' . $response->get_error_message(), 'error' ); |
|
698 | - } |
|
699 | - } |
|
700 | - } |
|
701 | - } |
|
702 | - |
|
703 | - /** |
|
704 | - * Handle fontawesome update settings to download fontawesome to store locally. |
|
705 | - * |
|
706 | - * @since 1.1.0 |
|
707 | - * |
|
708 | - * @param mixed $old_value The old option value. |
|
709 | - * @param mixed $value The new option value. |
|
710 | - */ |
|
711 | - public function update_option_wp_font_awesome_settings( $old_value, $new_value ) { |
|
712 | - // Do nothing if WordPress is being installed. |
|
713 | - if ( wp_installing() ) { |
|
714 | - return; |
|
715 | - } |
|
716 | - |
|
717 | - if ( ! empty( $new_value['local'] ) && empty( $new_value['pro'] ) && ! ( ! empty( $new_value['type'] ) && $new_value['type'] == 'KIT' ) ) { |
|
718 | - // Old values |
|
719 | - $old_version = isset( $old_value['version'] ) && $old_value['version'] ? $old_value['version'] : ( isset( $old_value['local_version'] ) ? $old_value['local_version'] : '' ); |
|
720 | - $old_local = isset( $old_value['local'] ) ? (int) $old_value['local'] : 0; |
|
721 | - |
|
722 | - // New values |
|
723 | - $new_version = isset( $new_value['version'] ) && $new_value['version'] ? $new_value['version'] : $this->get_latest_version(); |
|
724 | - |
|
725 | - if ( empty( $old_local ) || $old_version !== $new_version || ! file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) { |
|
726 | - $response = $this->download_package( $new_version, $new_value ); |
|
727 | - |
|
728 | - if ( is_wp_error( $response ) ) { |
|
729 | - add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'font-awesome-settings' ) . ' ' . $response->get_error_message(), 'error' ); |
|
730 | - } |
|
731 | - } |
|
732 | - } |
|
733 | - } |
|
734 | - |
|
735 | - /** |
|
736 | - * Get the fonts directory local path. |
|
737 | - * |
|
738 | - * @since 1.1.0 |
|
739 | - * |
|
740 | - * @param string Fonts directory local path. |
|
741 | - */ |
|
742 | - public function get_fonts_dir() { |
|
743 | - $upload_dir = wp_upload_dir( null, false ); |
|
744 | - |
|
745 | - return $upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'ayefonts' . DIRECTORY_SEPARATOR . 'fa' . DIRECTORY_SEPARATOR; |
|
746 | - } |
|
747 | - |
|
748 | - /** |
|
749 | - * Get the fonts directory local url. |
|
750 | - * |
|
751 | - * @since 1.1.0 |
|
752 | - * |
|
753 | - * @param string Fonts directory local url. |
|
754 | - */ |
|
755 | - public function get_fonts_url() { |
|
756 | - $upload_dir = wp_upload_dir( null, false ); |
|
757 | - |
|
758 | - return $upload_dir['baseurl'] . '/ayefonts/fa/'; |
|
759 | - } |
|
760 | - |
|
761 | - /** |
|
762 | - * Check whether load locally active. |
|
763 | - * |
|
764 | - * @since 1.1.0 |
|
765 | - * |
|
766 | - * @return bool True if active else false. |
|
767 | - */ |
|
768 | - public function has_local() { |
|
769 | - if ( ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) && file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) { |
|
770 | - return true; |
|
771 | - } |
|
772 | - |
|
773 | - return false; |
|
774 | - } |
|
775 | - |
|
776 | - /** |
|
777 | - * Get the WP Filesystem access. |
|
778 | - * |
|
779 | - * @since 1.1.0 |
|
780 | - * |
|
781 | - * @return object The WP Filesystem. |
|
782 | - */ |
|
783 | - public function get_wp_filesystem() { |
|
784 | - if ( ! function_exists( 'get_filesystem_method' ) ) { |
|
785 | - require_once( ABSPATH . "/wp-admin/includes/file.php" ); |
|
786 | - } |
|
787 | - |
|
788 | - $access_type = get_filesystem_method(); |
|
789 | - |
|
790 | - if ( $access_type === 'direct' ) { |
|
791 | - /* You can safely run request_filesystem_credentials() without any issues and don't need to worry about passing in a URL */ |
|
792 | - $creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() ); |
|
793 | - |
|
794 | - /* Initialize the API */ |
|
795 | - if ( ! WP_Filesystem( $creds ) ) { |
|
796 | - /* Any problems and we exit */ |
|
797 | - return false; |
|
798 | - } |
|
799 | - |
|
800 | - global $wp_filesystem; |
|
801 | - |
|
802 | - return $wp_filesystem; |
|
803 | - /* Do our file manipulations below */ |
|
804 | - } else if ( defined( 'FTP_USER' ) ) { |
|
805 | - $creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() ); |
|
806 | - |
|
807 | - /* Initialize the API */ |
|
808 | - if ( ! WP_Filesystem( $creds ) ) { |
|
809 | - /* Any problems and we exit */ |
|
810 | - return false; |
|
811 | - } |
|
812 | - |
|
813 | - global $wp_filesystem; |
|
814 | - |
|
815 | - return $wp_filesystem; |
|
816 | - } else { |
|
817 | - /* Don't have direct write access. Prompt user with our notice */ |
|
818 | - return false; |
|
819 | - } |
|
820 | - } |
|
821 | - |
|
822 | - /** |
|
823 | - * Download the fontawesome package file. |
|
824 | - * |
|
825 | - * @since 1.1.0 |
|
826 | - * |
|
827 | - * @param mixed $version The font awesome. |
|
828 | - * @param array $option Fontawesome settings. |
|
829 | - * @return WP_ERROR|bool Error on fail and true on success. |
|
830 | - */ |
|
831 | - public function download_package( $version, $option = array() ) { |
|
832 | - $filename = 'fontawesome-free-' . $version . '-web'; |
|
833 | - $url = 'https://use.fontawesome.com/releases/v' . $version . '/' . $filename . '.zip'; |
|
834 | - |
|
835 | - if ( ! function_exists( 'wp_handle_upload' ) ) { |
|
836 | - require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
837 | - } |
|
838 | - |
|
839 | - $download_file = download_url( esc_url_raw( $url ) ); |
|
840 | - |
|
841 | - if ( is_wp_error( $download_file ) ) { |
|
842 | - return new WP_Error( 'fontawesome_download_failed', __( $download_file->get_error_message(), 'font-awesome-settings' ) ); |
|
843 | - } else if ( empty( $download_file ) ) { |
|
844 | - return new WP_Error( 'fontawesome_download_failed', __( 'Something went wrong in downloading the font awesome to store locally.', 'font-awesome-settings' ) ); |
|
845 | - } |
|
846 | - |
|
847 | - $response = $this->extract_package( $download_file, $filename, true ); |
|
848 | - |
|
849 | - // Update local version. |
|
850 | - if ( is_wp_error( $response ) ) { |
|
851 | - return $response; |
|
852 | - } else if ( $response ) { |
|
853 | - if ( empty( $option ) ) { |
|
854 | - $option = get_option( 'wp-font-awesome-settings' ); |
|
855 | - } |
|
856 | - |
|
857 | - $option['local_version'] = $version; |
|
858 | - |
|
859 | - // Remove action to prevent looping. |
|
860 | - remove_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 ); |
|
861 | - |
|
862 | - update_option( 'wp-font-awesome-settings', $option ); |
|
863 | - |
|
864 | - return true; |
|
865 | - } |
|
866 | - |
|
867 | - return false; |
|
868 | - } |
|
869 | - |
|
870 | - /** |
|
871 | - * Extract the fontawesome package file. |
|
872 | - * |
|
873 | - * @since 1.1.0 |
|
874 | - * |
|
875 | - * @param string $package The package file path. |
|
876 | - * @param string $dirname Package file name. |
|
877 | - * @param bool $delete_package Delete temp file or not. |
|
878 | - * @return WP_Error|bool True on success WP_Error on fail. |
|
879 | - */ |
|
880 | - public function extract_package( $package, $dirname = '', $delete_package = false ) { |
|
881 | - global $wp_filesystem; |
|
882 | - |
|
883 | - $wp_filesystem = $this->get_wp_filesystem(); |
|
884 | - |
|
885 | - if ( empty( $wp_filesystem ) && isset( $wp_filesystem->errors ) && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) { |
|
886 | - return new WP_Error( 'fontawesome_filesystem_error', __( $wp_filesystem->errors->get_error_message(), 'font-awesome-settings' ) ); |
|
887 | - } else if ( empty( $wp_filesystem ) ) { |
|
888 | - return new WP_Error( 'fontawesome_filesystem_error', __( 'Failed to initialise WP_Filesystem while trying to download the Font Awesome package.', 'font-awesome-settings' ) ); |
|
889 | - } |
|
890 | - |
|
891 | - $fonts_dir = $this->get_fonts_dir(); |
|
892 | - $fonts_tmp_dir = dirname( $fonts_dir ) . DIRECTORY_SEPARATOR . 'fa-tmp' . DIRECTORY_SEPARATOR; |
|
893 | - |
|
894 | - if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) { |
|
895 | - $wp_filesystem->delete( $fonts_tmp_dir, true ); |
|
896 | - } |
|
897 | - |
|
898 | - // Unzip package to working directory. |
|
899 | - $result = unzip_file( $package, $fonts_tmp_dir ); |
|
900 | - |
|
901 | - if ( is_wp_error( $result ) ) { |
|
902 | - $wp_filesystem->delete( $fonts_tmp_dir, true ); |
|
903 | - |
|
904 | - if ( 'incompatible_archive' === $result->get_error_code() ) { |
|
905 | - return new WP_Error( 'fontawesome_incompatible_archive', __( $result->get_error_message(), 'font-awesome-settings' ) ); |
|
906 | - } |
|
907 | - |
|
908 | - return $result; |
|
909 | - } |
|
910 | - |
|
911 | - if ( $wp_filesystem->is_dir( $fonts_dir ) ) { |
|
912 | - $wp_filesystem->delete( $fonts_dir, true ); |
|
913 | - } |
|
914 | - |
|
915 | - $extract_dir = $fonts_tmp_dir; |
|
916 | - |
|
917 | - if ( $dirname && $wp_filesystem->is_dir( $extract_dir . $dirname . DIRECTORY_SEPARATOR ) ) { |
|
918 | - $extract_dir .= $dirname . DIRECTORY_SEPARATOR; |
|
919 | - } |
|
920 | - |
|
921 | - try { |
|
922 | - $return = $wp_filesystem->move( $extract_dir, $fonts_dir, true ); |
|
923 | - } catch ( Exception $e ) { |
|
924 | - $return = new WP_Error( 'fontawesome_move_package', __( 'Fail to move font awesome package!', 'font-awesome-settings' ) ); |
|
925 | - } |
|
926 | - |
|
927 | - if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) { |
|
928 | - $wp_filesystem->delete( $fonts_tmp_dir, true ); |
|
929 | - } |
|
930 | - |
|
931 | - // Once extracted, delete the package if required. |
|
932 | - if ( $delete_package ) { |
|
933 | - unlink( $package ); |
|
934 | - } |
|
935 | - |
|
936 | - return $return; |
|
937 | - } |
|
938 | - } |
|
939 | - |
|
940 | - /** |
|
941 | - * Run the class if found. |
|
942 | - */ |
|
943 | - WP_Font_Awesome_Settings::instance(); |
|
671 | + } |
|
672 | + } |
|
673 | + } |
|
674 | + } |
|
675 | + |
|
676 | + /** |
|
677 | + * Handle fontawesome add settings to download fontawesome to store locally. |
|
678 | + * |
|
679 | + * @since 1.1.1 |
|
680 | + * |
|
681 | + * @param string $option The option name. |
|
682 | + * @param mixed $value The option value. |
|
683 | + */ |
|
684 | + public function add_option_wp_font_awesome_settings( $option, $value ) { |
|
685 | + // Do nothing if WordPress is being installed. |
|
686 | + if ( wp_installing() ) { |
|
687 | + return; |
|
688 | + } |
|
689 | + |
|
690 | + if ( ! empty( $value['local'] ) && empty( $value['pro'] ) && ! ( ! empty( $value['type'] ) && $value['type'] == 'KIT' ) ) { |
|
691 | + $version = isset( $value['version'] ) && $value['version'] ? $value['version'] : $this->get_latest_version(); |
|
692 | + |
|
693 | + if ( ! empty( $version ) ) { |
|
694 | + $response = $this->download_package( $version, $value ); |
|
695 | + |
|
696 | + if ( is_wp_error( $response ) ) { |
|
697 | + add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'font-awesome-settings' ) . ' ' . $response->get_error_message(), 'error' ); |
|
698 | + } |
|
699 | + } |
|
700 | + } |
|
701 | + } |
|
702 | + |
|
703 | + /** |
|
704 | + * Handle fontawesome update settings to download fontawesome to store locally. |
|
705 | + * |
|
706 | + * @since 1.1.0 |
|
707 | + * |
|
708 | + * @param mixed $old_value The old option value. |
|
709 | + * @param mixed $value The new option value. |
|
710 | + */ |
|
711 | + public function update_option_wp_font_awesome_settings( $old_value, $new_value ) { |
|
712 | + // Do nothing if WordPress is being installed. |
|
713 | + if ( wp_installing() ) { |
|
714 | + return; |
|
715 | + } |
|
716 | + |
|
717 | + if ( ! empty( $new_value['local'] ) && empty( $new_value['pro'] ) && ! ( ! empty( $new_value['type'] ) && $new_value['type'] == 'KIT' ) ) { |
|
718 | + // Old values |
|
719 | + $old_version = isset( $old_value['version'] ) && $old_value['version'] ? $old_value['version'] : ( isset( $old_value['local_version'] ) ? $old_value['local_version'] : '' ); |
|
720 | + $old_local = isset( $old_value['local'] ) ? (int) $old_value['local'] : 0; |
|
721 | + |
|
722 | + // New values |
|
723 | + $new_version = isset( $new_value['version'] ) && $new_value['version'] ? $new_value['version'] : $this->get_latest_version(); |
|
724 | + |
|
725 | + if ( empty( $old_local ) || $old_version !== $new_version || ! file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) { |
|
726 | + $response = $this->download_package( $new_version, $new_value ); |
|
727 | + |
|
728 | + if ( is_wp_error( $response ) ) { |
|
729 | + add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'font-awesome-settings' ) . ' ' . $response->get_error_message(), 'error' ); |
|
730 | + } |
|
731 | + } |
|
732 | + } |
|
733 | + } |
|
734 | + |
|
735 | + /** |
|
736 | + * Get the fonts directory local path. |
|
737 | + * |
|
738 | + * @since 1.1.0 |
|
739 | + * |
|
740 | + * @param string Fonts directory local path. |
|
741 | + */ |
|
742 | + public function get_fonts_dir() { |
|
743 | + $upload_dir = wp_upload_dir( null, false ); |
|
744 | + |
|
745 | + return $upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'ayefonts' . DIRECTORY_SEPARATOR . 'fa' . DIRECTORY_SEPARATOR; |
|
746 | + } |
|
747 | + |
|
748 | + /** |
|
749 | + * Get the fonts directory local url. |
|
750 | + * |
|
751 | + * @since 1.1.0 |
|
752 | + * |
|
753 | + * @param string Fonts directory local url. |
|
754 | + */ |
|
755 | + public function get_fonts_url() { |
|
756 | + $upload_dir = wp_upload_dir( null, false ); |
|
757 | + |
|
758 | + return $upload_dir['baseurl'] . '/ayefonts/fa/'; |
|
759 | + } |
|
760 | + |
|
761 | + /** |
|
762 | + * Check whether load locally active. |
|
763 | + * |
|
764 | + * @since 1.1.0 |
|
765 | + * |
|
766 | + * @return bool True if active else false. |
|
767 | + */ |
|
768 | + public function has_local() { |
|
769 | + if ( ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) && file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) { |
|
770 | + return true; |
|
771 | + } |
|
772 | + |
|
773 | + return false; |
|
774 | + } |
|
775 | + |
|
776 | + /** |
|
777 | + * Get the WP Filesystem access. |
|
778 | + * |
|
779 | + * @since 1.1.0 |
|
780 | + * |
|
781 | + * @return object The WP Filesystem. |
|
782 | + */ |
|
783 | + public function get_wp_filesystem() { |
|
784 | + if ( ! function_exists( 'get_filesystem_method' ) ) { |
|
785 | + require_once( ABSPATH . "/wp-admin/includes/file.php" ); |
|
786 | + } |
|
787 | + |
|
788 | + $access_type = get_filesystem_method(); |
|
789 | + |
|
790 | + if ( $access_type === 'direct' ) { |
|
791 | + /* You can safely run request_filesystem_credentials() without any issues and don't need to worry about passing in a URL */ |
|
792 | + $creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() ); |
|
793 | + |
|
794 | + /* Initialize the API */ |
|
795 | + if ( ! WP_Filesystem( $creds ) ) { |
|
796 | + /* Any problems and we exit */ |
|
797 | + return false; |
|
798 | + } |
|
799 | + |
|
800 | + global $wp_filesystem; |
|
801 | + |
|
802 | + return $wp_filesystem; |
|
803 | + /* Do our file manipulations below */ |
|
804 | + } else if ( defined( 'FTP_USER' ) ) { |
|
805 | + $creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() ); |
|
806 | + |
|
807 | + /* Initialize the API */ |
|
808 | + if ( ! WP_Filesystem( $creds ) ) { |
|
809 | + /* Any problems and we exit */ |
|
810 | + return false; |
|
811 | + } |
|
812 | + |
|
813 | + global $wp_filesystem; |
|
814 | + |
|
815 | + return $wp_filesystem; |
|
816 | + } else { |
|
817 | + /* Don't have direct write access. Prompt user with our notice */ |
|
818 | + return false; |
|
819 | + } |
|
820 | + } |
|
821 | + |
|
822 | + /** |
|
823 | + * Download the fontawesome package file. |
|
824 | + * |
|
825 | + * @since 1.1.0 |
|
826 | + * |
|
827 | + * @param mixed $version The font awesome. |
|
828 | + * @param array $option Fontawesome settings. |
|
829 | + * @return WP_ERROR|bool Error on fail and true on success. |
|
830 | + */ |
|
831 | + public function download_package( $version, $option = array() ) { |
|
832 | + $filename = 'fontawesome-free-' . $version . '-web'; |
|
833 | + $url = 'https://use.fontawesome.com/releases/v' . $version . '/' . $filename . '.zip'; |
|
834 | + |
|
835 | + if ( ! function_exists( 'wp_handle_upload' ) ) { |
|
836 | + require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
837 | + } |
|
838 | + |
|
839 | + $download_file = download_url( esc_url_raw( $url ) ); |
|
840 | + |
|
841 | + if ( is_wp_error( $download_file ) ) { |
|
842 | + return new WP_Error( 'fontawesome_download_failed', __( $download_file->get_error_message(), 'font-awesome-settings' ) ); |
|
843 | + } else if ( empty( $download_file ) ) { |
|
844 | + return new WP_Error( 'fontawesome_download_failed', __( 'Something went wrong in downloading the font awesome to store locally.', 'font-awesome-settings' ) ); |
|
845 | + } |
|
846 | + |
|
847 | + $response = $this->extract_package( $download_file, $filename, true ); |
|
848 | + |
|
849 | + // Update local version. |
|
850 | + if ( is_wp_error( $response ) ) { |
|
851 | + return $response; |
|
852 | + } else if ( $response ) { |
|
853 | + if ( empty( $option ) ) { |
|
854 | + $option = get_option( 'wp-font-awesome-settings' ); |
|
855 | + } |
|
856 | + |
|
857 | + $option['local_version'] = $version; |
|
858 | + |
|
859 | + // Remove action to prevent looping. |
|
860 | + remove_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 ); |
|
861 | + |
|
862 | + update_option( 'wp-font-awesome-settings', $option ); |
|
863 | + |
|
864 | + return true; |
|
865 | + } |
|
866 | + |
|
867 | + return false; |
|
868 | + } |
|
869 | + |
|
870 | + /** |
|
871 | + * Extract the fontawesome package file. |
|
872 | + * |
|
873 | + * @since 1.1.0 |
|
874 | + * |
|
875 | + * @param string $package The package file path. |
|
876 | + * @param string $dirname Package file name. |
|
877 | + * @param bool $delete_package Delete temp file or not. |
|
878 | + * @return WP_Error|bool True on success WP_Error on fail. |
|
879 | + */ |
|
880 | + public function extract_package( $package, $dirname = '', $delete_package = false ) { |
|
881 | + global $wp_filesystem; |
|
882 | + |
|
883 | + $wp_filesystem = $this->get_wp_filesystem(); |
|
884 | + |
|
885 | + if ( empty( $wp_filesystem ) && isset( $wp_filesystem->errors ) && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) { |
|
886 | + return new WP_Error( 'fontawesome_filesystem_error', __( $wp_filesystem->errors->get_error_message(), 'font-awesome-settings' ) ); |
|
887 | + } else if ( empty( $wp_filesystem ) ) { |
|
888 | + return new WP_Error( 'fontawesome_filesystem_error', __( 'Failed to initialise WP_Filesystem while trying to download the Font Awesome package.', 'font-awesome-settings' ) ); |
|
889 | + } |
|
890 | + |
|
891 | + $fonts_dir = $this->get_fonts_dir(); |
|
892 | + $fonts_tmp_dir = dirname( $fonts_dir ) . DIRECTORY_SEPARATOR . 'fa-tmp' . DIRECTORY_SEPARATOR; |
|
893 | + |
|
894 | + if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) { |
|
895 | + $wp_filesystem->delete( $fonts_tmp_dir, true ); |
|
896 | + } |
|
897 | + |
|
898 | + // Unzip package to working directory. |
|
899 | + $result = unzip_file( $package, $fonts_tmp_dir ); |
|
900 | + |
|
901 | + if ( is_wp_error( $result ) ) { |
|
902 | + $wp_filesystem->delete( $fonts_tmp_dir, true ); |
|
903 | + |
|
904 | + if ( 'incompatible_archive' === $result->get_error_code() ) { |
|
905 | + return new WP_Error( 'fontawesome_incompatible_archive', __( $result->get_error_message(), 'font-awesome-settings' ) ); |
|
906 | + } |
|
907 | + |
|
908 | + return $result; |
|
909 | + } |
|
910 | + |
|
911 | + if ( $wp_filesystem->is_dir( $fonts_dir ) ) { |
|
912 | + $wp_filesystem->delete( $fonts_dir, true ); |
|
913 | + } |
|
914 | + |
|
915 | + $extract_dir = $fonts_tmp_dir; |
|
916 | + |
|
917 | + if ( $dirname && $wp_filesystem->is_dir( $extract_dir . $dirname . DIRECTORY_SEPARATOR ) ) { |
|
918 | + $extract_dir .= $dirname . DIRECTORY_SEPARATOR; |
|
919 | + } |
|
920 | + |
|
921 | + try { |
|
922 | + $return = $wp_filesystem->move( $extract_dir, $fonts_dir, true ); |
|
923 | + } catch ( Exception $e ) { |
|
924 | + $return = new WP_Error( 'fontawesome_move_package', __( 'Fail to move font awesome package!', 'font-awesome-settings' ) ); |
|
925 | + } |
|
926 | + |
|
927 | + if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) { |
|
928 | + $wp_filesystem->delete( $fonts_tmp_dir, true ); |
|
929 | + } |
|
930 | + |
|
931 | + // Once extracted, delete the package if required. |
|
932 | + if ( $delete_package ) { |
|
933 | + unlink( $package ); |
|
934 | + } |
|
935 | + |
|
936 | + return $return; |
|
937 | + } |
|
938 | + } |
|
939 | + |
|
940 | + /** |
|
941 | + * Run the class if found. |
|
942 | + */ |
|
943 | + WP_Font_Awesome_Settings::instance(); |
|
944 | 944 | } |
@@ -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,1283 +11,1283 @@ 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 | - global $aui_bs5; |
|
23 | - |
|
24 | - $defaults = array( |
|
25 | - 'type' => 'text', |
|
26 | - 'name' => '', |
|
27 | - 'class' => '', |
|
28 | - 'wrap_class' => '', |
|
29 | - 'id' => '', |
|
30 | - 'placeholder' => '', |
|
31 | - 'title' => '', |
|
32 | - 'value' => '', |
|
33 | - 'required' => false, |
|
34 | - 'size' => '', // sm, lg, small, large |
|
35 | - 'clear_icon' => '', // true will show a clear icon, can't be used with input_group_right |
|
36 | - 'with_hidden' => false, // Append hidden field for single checkbox. |
|
37 | - 'label' => '', |
|
38 | - 'label_after' => false, |
|
39 | - 'label_class' => '', |
|
40 | - 'label_col' => '2', |
|
41 | - 'label_type' => '', // top, horizontal, empty = hidden |
|
42 | - 'label_force_left' => false, // used to force checkbox label left when using horizontal |
|
43 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
44 | - 'help_text' => '', |
|
45 | - 'validation_text' => '', |
|
46 | - 'validation_pattern' => '', |
|
47 | - 'no_wrap' => false, |
|
48 | - 'input_group_right' => '', |
|
49 | - 'input_group_left' => '', |
|
50 | - 'input_group_right_inside' => false, |
|
51 | - // forces the input group inside the input |
|
52 | - 'input_group_left_inside' => false, |
|
53 | - // forces the input group inside the input |
|
54 | - 'form_group_class' => '', |
|
55 | - 'step' => '', |
|
56 | - 'switch' => false, |
|
57 | - // to show checkbox as a switch |
|
58 | - 'checked' => false, |
|
59 | - // set a checkbox or radio as selected |
|
60 | - 'password_toggle' => true, |
|
61 | - // toggle view/hide password |
|
62 | - 'element_require' => '', |
|
63 | - // [%element_id%] == "1" |
|
64 | - 'extra_attributes' => array(), |
|
65 | - // an array of extra attributes |
|
66 | - 'wrap_attributes' => array() |
|
67 | - ); |
|
68 | - |
|
69 | - /** |
|
70 | - * Parse incoming $args into an array and merge it with $defaults |
|
71 | - */ |
|
72 | - $args = wp_parse_args( $args, $defaults ); |
|
73 | - $output = ''; |
|
74 | - if ( ! empty( $args['type'] ) ) { |
|
75 | - // hidden label option needs to be empty |
|
76 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
77 | - |
|
78 | - $type = sanitize_html_class( $args['type'] ); |
|
79 | - |
|
80 | - $help_text = ''; |
|
81 | - $label = ''; |
|
82 | - $label_after = $args['label_after']; |
|
83 | - $label_args = array( |
|
84 | - 'title' => $args['label'], |
|
85 | - 'for' => $args['id'], |
|
86 | - 'class' => $args['label_class'] . " ", |
|
87 | - 'label_type' => $args['label_type'], |
|
88 | - 'label_col' => $args['label_col'] |
|
89 | - ); |
|
90 | - |
|
91 | - // floating labels need label after |
|
92 | - if ( $args['label_type'] == 'floating' && $type != 'checkbox' ) { |
|
93 | - $label_after = true; |
|
94 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
95 | - } |
|
96 | - |
|
97 | - // size |
|
98 | - $size = ''; |
|
99 | - if ( $args['size'] == 'lg' || $args['size'] == 'large' ) { |
|
100 | - $size = 'lg'; |
|
101 | - $args['class'] .= ' form-control-lg'; |
|
102 | - }elseif ( $args['size'] == 'sm' || $args['size'] == 'small' ) { |
|
103 | - $size = 'sm'; |
|
104 | - $args['class'] .= ' form-control-sm'; |
|
105 | - } |
|
106 | - |
|
107 | - // clear function |
|
108 | - $clear_function = 'jQuery(this).parent().parent().find(\'input\').val(\'\');'; |
|
109 | - |
|
110 | - // Some special sauce for files |
|
111 | - if ( $type == 'file' ) { |
|
112 | - $label_after = true; // if type file we need the label after |
|
113 | - $args['class'] .= ' custom-file-input '; |
|
114 | - } elseif ( $type == 'checkbox' ) { |
|
115 | - $label_after = true; // if type file we need the label after |
|
116 | - $args['class'] .= $aui_bs5 ? ' form-check-input' : ' custom-control-input '; |
|
117 | - } elseif ( $type == 'datepicker' || $type == 'timepicker' ) { |
|
118 | - $orig_type = $type; |
|
119 | - $type = 'text'; |
|
120 | - $args['class'] .= ' bg-initial '; // @todo not sure why we have this? |
|
121 | - $clear_function .= "jQuery(this).parent().parent().find('input[name=\'" . esc_attr( $args['name'] ) . "\']').trigger('change');"; |
|
122 | - |
|
123 | - $args['extra_attributes']['data-aui-init'] = 'flatpickr'; |
|
124 | - |
|
125 | - // Disable native datetime inputs. |
|
126 | - if ( ( $orig_type == 'timepicker' || ! empty( $args['extra_attributes']['data-enable-time'] ) ) && ! isset( $args['extra_attributes']['data-disable-mobile'] ) ) { |
|
127 | - $args['extra_attributes']['data-disable-mobile'] = 'true'; |
|
128 | - } |
|
129 | - |
|
130 | - // set a way to clear field if empty |
|
131 | - if ( $args['input_group_right'] === '' && $args['clear_icon'] !== false ) { |
|
132 | - $args['input_group_right_inside'] = true; |
|
133 | - $args['clear_icon'] = true; |
|
134 | - } |
|
135 | - |
|
136 | - // enqueue the script |
|
137 | - $aui_settings = AyeCode_UI_Settings::instance(); |
|
138 | - $aui_settings->enqueue_flatpickr(); |
|
139 | - } elseif ( $type == 'iconpicker' ) { |
|
140 | - $type = 'text'; |
|
141 | - //$args['class'] .= ' aui-flatpickr bg-initial '; |
|
14 | + /** |
|
15 | + * Build the component. |
|
16 | + * |
|
17 | + * @param array $args |
|
18 | + * |
|
19 | + * @return string The rendered component. |
|
20 | + */ |
|
21 | + public static function input( $args = array() ) { |
|
22 | + global $aui_bs5; |
|
23 | + |
|
24 | + $defaults = array( |
|
25 | + 'type' => 'text', |
|
26 | + 'name' => '', |
|
27 | + 'class' => '', |
|
28 | + 'wrap_class' => '', |
|
29 | + 'id' => '', |
|
30 | + 'placeholder' => '', |
|
31 | + 'title' => '', |
|
32 | + 'value' => '', |
|
33 | + 'required' => false, |
|
34 | + 'size' => '', // sm, lg, small, large |
|
35 | + 'clear_icon' => '', // true will show a clear icon, can't be used with input_group_right |
|
36 | + 'with_hidden' => false, // Append hidden field for single checkbox. |
|
37 | + 'label' => '', |
|
38 | + 'label_after' => false, |
|
39 | + 'label_class' => '', |
|
40 | + 'label_col' => '2', |
|
41 | + 'label_type' => '', // top, horizontal, empty = hidden |
|
42 | + 'label_force_left' => false, // used to force checkbox label left when using horizontal |
|
43 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
44 | + 'help_text' => '', |
|
45 | + 'validation_text' => '', |
|
46 | + 'validation_pattern' => '', |
|
47 | + 'no_wrap' => false, |
|
48 | + 'input_group_right' => '', |
|
49 | + 'input_group_left' => '', |
|
50 | + 'input_group_right_inside' => false, |
|
51 | + // forces the input group inside the input |
|
52 | + 'input_group_left_inside' => false, |
|
53 | + // forces the input group inside the input |
|
54 | + 'form_group_class' => '', |
|
55 | + 'step' => '', |
|
56 | + 'switch' => false, |
|
57 | + // to show checkbox as a switch |
|
58 | + 'checked' => false, |
|
59 | + // set a checkbox or radio as selected |
|
60 | + 'password_toggle' => true, |
|
61 | + // toggle view/hide password |
|
62 | + 'element_require' => '', |
|
63 | + // [%element_id%] == "1" |
|
64 | + 'extra_attributes' => array(), |
|
65 | + // an array of extra attributes |
|
66 | + 'wrap_attributes' => array() |
|
67 | + ); |
|
68 | + |
|
69 | + /** |
|
70 | + * Parse incoming $args into an array and merge it with $defaults |
|
71 | + */ |
|
72 | + $args = wp_parse_args( $args, $defaults ); |
|
73 | + $output = ''; |
|
74 | + if ( ! empty( $args['type'] ) ) { |
|
75 | + // hidden label option needs to be empty |
|
76 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
77 | + |
|
78 | + $type = sanitize_html_class( $args['type'] ); |
|
79 | + |
|
80 | + $help_text = ''; |
|
81 | + $label = ''; |
|
82 | + $label_after = $args['label_after']; |
|
83 | + $label_args = array( |
|
84 | + 'title' => $args['label'], |
|
85 | + 'for' => $args['id'], |
|
86 | + 'class' => $args['label_class'] . " ", |
|
87 | + 'label_type' => $args['label_type'], |
|
88 | + 'label_col' => $args['label_col'] |
|
89 | + ); |
|
90 | + |
|
91 | + // floating labels need label after |
|
92 | + if ( $args['label_type'] == 'floating' && $type != 'checkbox' ) { |
|
93 | + $label_after = true; |
|
94 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
95 | + } |
|
96 | + |
|
97 | + // size |
|
98 | + $size = ''; |
|
99 | + if ( $args['size'] == 'lg' || $args['size'] == 'large' ) { |
|
100 | + $size = 'lg'; |
|
101 | + $args['class'] .= ' form-control-lg'; |
|
102 | + }elseif ( $args['size'] == 'sm' || $args['size'] == 'small' ) { |
|
103 | + $size = 'sm'; |
|
104 | + $args['class'] .= ' form-control-sm'; |
|
105 | + } |
|
106 | + |
|
107 | + // clear function |
|
108 | + $clear_function = 'jQuery(this).parent().parent().find(\'input\').val(\'\');'; |
|
109 | + |
|
110 | + // Some special sauce for files |
|
111 | + if ( $type == 'file' ) { |
|
112 | + $label_after = true; // if type file we need the label after |
|
113 | + $args['class'] .= ' custom-file-input '; |
|
114 | + } elseif ( $type == 'checkbox' ) { |
|
115 | + $label_after = true; // if type file we need the label after |
|
116 | + $args['class'] .= $aui_bs5 ? ' form-check-input' : ' custom-control-input '; |
|
117 | + } elseif ( $type == 'datepicker' || $type == 'timepicker' ) { |
|
118 | + $orig_type = $type; |
|
119 | + $type = 'text'; |
|
120 | + $args['class'] .= ' bg-initial '; // @todo not sure why we have this? |
|
121 | + $clear_function .= "jQuery(this).parent().parent().find('input[name=\'" . esc_attr( $args['name'] ) . "\']').trigger('change');"; |
|
122 | + |
|
123 | + $args['extra_attributes']['data-aui-init'] = 'flatpickr'; |
|
124 | + |
|
125 | + // Disable native datetime inputs. |
|
126 | + if ( ( $orig_type == 'timepicker' || ! empty( $args['extra_attributes']['data-enable-time'] ) ) && ! isset( $args['extra_attributes']['data-disable-mobile'] ) ) { |
|
127 | + $args['extra_attributes']['data-disable-mobile'] = 'true'; |
|
128 | + } |
|
129 | + |
|
130 | + // set a way to clear field if empty |
|
131 | + if ( $args['input_group_right'] === '' && $args['clear_icon'] !== false ) { |
|
132 | + $args['input_group_right_inside'] = true; |
|
133 | + $args['clear_icon'] = true; |
|
134 | + } |
|
135 | + |
|
136 | + // enqueue the script |
|
137 | + $aui_settings = AyeCode_UI_Settings::instance(); |
|
138 | + $aui_settings->enqueue_flatpickr(); |
|
139 | + } elseif ( $type == 'iconpicker' ) { |
|
140 | + $type = 'text'; |
|
141 | + //$args['class'] .= ' aui-flatpickr bg-initial '; |
|
142 | 142 | // $args['class'] .= ' bg-initial '; |
143 | 143 | |
144 | - $args['extra_attributes']['data-aui-init'] = 'iconpicker'; |
|
145 | - $args['extra_attributes']['data-placement'] = 'bottomRight'; |
|
144 | + $args['extra_attributes']['data-aui-init'] = 'iconpicker'; |
|
145 | + $args['extra_attributes']['data-placement'] = 'bottomRight'; |
|
146 | 146 | |
147 | - $args['input_group_right'] = '<span class="input-group-addon input-group-text c-pointer"></span>'; |
|
147 | + $args['input_group_right'] = '<span class="input-group-addon input-group-text c-pointer"></span>'; |
|
148 | 148 | // $args['input_group_right_inside'] = true; |
149 | - // enqueue the script |
|
150 | - $aui_settings = AyeCode_UI_Settings::instance(); |
|
151 | - $aui_settings->enqueue_iconpicker(); |
|
152 | - } |
|
153 | - |
|
154 | - if ( $type == 'checkbox' && ( ( ! empty( $args['name'] ) && strpos( $args['name'], '[' ) === false ) || ! empty( $args['with_hidden'] ) ) ) { |
|
155 | - $output .= '<input type="hidden" name="' . esc_attr( $args['name'] ) . '" value="0" />'; |
|
156 | - } |
|
157 | - |
|
158 | - // allow clear icon |
|
159 | - if ( $args['input_group_right'] === '' && $args['clear_icon'] ) { |
|
160 | - $font_size = $size == 'sm' ? '1.3' : ( $size == 'lg' ? '1.65' : '1.5' ); |
|
161 | - $args['input_group_right_inside'] = true; |
|
162 | - $align_class = $aui_bs5 ? ' h-100 py-0' : ''; |
|
163 | - $args['input_group_right'] = '<span class="input-group-text aui-clear-input c-pointer bg-initial border-0 px-2 d-none ' . $align_class . '" onclick="' . $clear_function . '"><span style="font-size: ' . $font_size . 'rem" aria-hidden="true" class="' . ( $aui_bs5 ? 'btn-close' : 'close' ) . '">' . ( $aui_bs5 ? '' : '×' ) . '</span></span>'; |
|
164 | - } |
|
165 | - |
|
166 | - // open/type |
|
167 | - $output .= '<input type="' . $type . '" '; |
|
168 | - |
|
169 | - // name |
|
170 | - if ( ! empty( $args['name'] ) ) { |
|
171 | - $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
172 | - } |
|
173 | - |
|
174 | - // id |
|
175 | - if ( ! empty( $args['id'] ) ) { |
|
176 | - $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
177 | - } |
|
178 | - |
|
179 | - // placeholder |
|
180 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
181 | - $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
182 | - } |
|
183 | - |
|
184 | - // title |
|
185 | - if ( ! empty( $args['title'] ) ) { |
|
186 | - $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
187 | - } |
|
188 | - |
|
189 | - // value |
|
190 | - if ( ! empty( $args['value'] ) ) { |
|
191 | - $output .= AUI_Component_Helper::value( $args['value'] ); |
|
192 | - } |
|
193 | - |
|
194 | - // checked, for radio and checkboxes |
|
195 | - if ( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ) { |
|
196 | - $output .= ' checked '; |
|
197 | - } |
|
198 | - |
|
199 | - // validation text |
|
200 | - if ( ! empty( $args['validation_text'] ) ) { |
|
201 | - $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" '; |
|
202 | - $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
203 | - } |
|
204 | - |
|
205 | - // validation_pattern |
|
206 | - if ( ! empty( $args['validation_pattern'] ) ) { |
|
207 | - $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
208 | - } |
|
209 | - |
|
210 | - // step (for numbers) |
|
211 | - if ( ! empty( $args['step'] ) ) { |
|
212 | - $output .= ' step="' . $args['step'] . '" '; |
|
213 | - } |
|
214 | - |
|
215 | - // required |
|
216 | - if ( ! empty( $args['required'] ) ) { |
|
217 | - $output .= ' required '; |
|
218 | - } |
|
219 | - |
|
220 | - // class |
|
221 | - $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
222 | - $output .= $aui_bs5 && $type == 'checkbox' ? ' class="' . $class . '" ' : ' class="form-control ' . $class . '" '; |
|
223 | - |
|
224 | - // data-attributes |
|
225 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
226 | - |
|
227 | - // extra attributes |
|
228 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
229 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
230 | - } |
|
231 | - |
|
232 | - // close |
|
233 | - $output .= ' >'; |
|
234 | - |
|
235 | - // help text |
|
236 | - if ( ! empty( $args['help_text'] ) ) { |
|
237 | - $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
238 | - } |
|
239 | - |
|
240 | - // label |
|
241 | - if ( ! empty( $args['label'] ) ) { |
|
242 | - $label_base_class = ''; |
|
243 | - if ( $type == 'file' ) { |
|
244 | - $label_base_class = ' custom-file-label'; |
|
245 | - } elseif ( $type == 'checkbox' ) { |
|
246 | - if ( ! empty( $args['label_force_left'] ) ) { |
|
247 | - $label_args['title'] = wp_kses_post( $args['help_text'] ); |
|
248 | - $help_text = ''; |
|
249 | - //$label_args['class'] .= ' d-inline '; |
|
250 | - $args['wrap_class'] .= ' align-items-center '; |
|
251 | - }else{ |
|
252 | - |
|
253 | - } |
|
254 | - |
|
255 | - $label_base_class = $aui_bs5 ? ' form-check-label' : ' custom-control-label'; |
|
256 | - } |
|
257 | - $label_args['class'] .= $label_base_class; |
|
258 | - $temp_label_args = $label_args; |
|
259 | - if(! empty( $args['label_force_left'] )){$temp_label_args['class'] = $label_base_class." text-muted";} |
|
260 | - $label = self::label( $temp_label_args, $type ); |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - |
|
265 | - |
|
266 | - // set help text in the correct position |
|
267 | - if ( $label_after ) { |
|
268 | - $output .= $label . $help_text; |
|
269 | - } |
|
270 | - |
|
271 | - // some input types need a separate wrap |
|
272 | - if ( $type == 'file' ) { |
|
273 | - $output = self::wrap( array( |
|
274 | - 'content' => $output, |
|
275 | - 'class' => $aui_bs5 ? 'mb-3 custom-file' : 'form-group custom-file' |
|
276 | - ) ); |
|
277 | - } elseif ( $type == 'checkbox' ) { |
|
278 | - |
|
279 | - $label_args['title'] = $args['label']; |
|
280 | - $label_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ); |
|
281 | - $label = !empty( $args['label_force_left'] ) ? self::label( $label_args, 'cb' ) : '<div class="' . $label_col . ' col-form-label"></div>'; |
|
282 | - $switch_size_class = $args['switch'] && !is_bool( $args['switch'] ) ? ' custom-switch-'.esc_attr( $args['switch'] ) : ''; |
|
283 | - if ( $aui_bs5 ) { |
|
284 | - $wrap_class = $args['switch'] ? 'form-check form-switch' . $switch_size_class : 'form-check'; |
|
285 | - }else{ |
|
286 | - $wrap_class = $args['switch'] ? 'custom-switch' . $switch_size_class : 'custom-checkbox' ; |
|
287 | - } |
|
288 | - if ( ! empty( $args['label_force_left'] ) ) { |
|
289 | - $wrap_class .= $aui_bs5 ? '' : ' d-flex align-content-center'; |
|
290 | - $label = str_replace(array("form-check-label","custom-control-label"),"", self::label( $label_args, 'cb' ) ); |
|
291 | - } |
|
292 | - $output = self::wrap( array( |
|
293 | - 'content' => $output, |
|
294 | - 'class' => $aui_bs5 ? $wrap_class : 'custom-control ' . $wrap_class |
|
295 | - ) ); |
|
296 | - |
|
297 | - if ( $args['label_type'] == 'horizontal' ) { |
|
298 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
299 | - $output = $label . '<div class="' . $input_col . '">' . $output . '</div>'; |
|
300 | - } |
|
301 | - } elseif ( $type == 'password' && $args['password_toggle'] && ! $args['input_group_right'] ) { |
|
302 | - |
|
303 | - |
|
304 | - // allow password field to toggle view |
|
305 | - $args['input_group_right'] = '<span class="input-group-text c-pointer px-3" |
|
149 | + // enqueue the script |
|
150 | + $aui_settings = AyeCode_UI_Settings::instance(); |
|
151 | + $aui_settings->enqueue_iconpicker(); |
|
152 | + } |
|
153 | + |
|
154 | + if ( $type == 'checkbox' && ( ( ! empty( $args['name'] ) && strpos( $args['name'], '[' ) === false ) || ! empty( $args['with_hidden'] ) ) ) { |
|
155 | + $output .= '<input type="hidden" name="' . esc_attr( $args['name'] ) . '" value="0" />'; |
|
156 | + } |
|
157 | + |
|
158 | + // allow clear icon |
|
159 | + if ( $args['input_group_right'] === '' && $args['clear_icon'] ) { |
|
160 | + $font_size = $size == 'sm' ? '1.3' : ( $size == 'lg' ? '1.65' : '1.5' ); |
|
161 | + $args['input_group_right_inside'] = true; |
|
162 | + $align_class = $aui_bs5 ? ' h-100 py-0' : ''; |
|
163 | + $args['input_group_right'] = '<span class="input-group-text aui-clear-input c-pointer bg-initial border-0 px-2 d-none ' . $align_class . '" onclick="' . $clear_function . '"><span style="font-size: ' . $font_size . 'rem" aria-hidden="true" class="' . ( $aui_bs5 ? 'btn-close' : 'close' ) . '">' . ( $aui_bs5 ? '' : '×' ) . '</span></span>'; |
|
164 | + } |
|
165 | + |
|
166 | + // open/type |
|
167 | + $output .= '<input type="' . $type . '" '; |
|
168 | + |
|
169 | + // name |
|
170 | + if ( ! empty( $args['name'] ) ) { |
|
171 | + $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
172 | + } |
|
173 | + |
|
174 | + // id |
|
175 | + if ( ! empty( $args['id'] ) ) { |
|
176 | + $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
177 | + } |
|
178 | + |
|
179 | + // placeholder |
|
180 | + if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
181 | + $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
182 | + } |
|
183 | + |
|
184 | + // title |
|
185 | + if ( ! empty( $args['title'] ) ) { |
|
186 | + $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
187 | + } |
|
188 | + |
|
189 | + // value |
|
190 | + if ( ! empty( $args['value'] ) ) { |
|
191 | + $output .= AUI_Component_Helper::value( $args['value'] ); |
|
192 | + } |
|
193 | + |
|
194 | + // checked, for radio and checkboxes |
|
195 | + if ( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ) { |
|
196 | + $output .= ' checked '; |
|
197 | + } |
|
198 | + |
|
199 | + // validation text |
|
200 | + if ( ! empty( $args['validation_text'] ) ) { |
|
201 | + $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" '; |
|
202 | + $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
203 | + } |
|
204 | + |
|
205 | + // validation_pattern |
|
206 | + if ( ! empty( $args['validation_pattern'] ) ) { |
|
207 | + $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
208 | + } |
|
209 | + |
|
210 | + // step (for numbers) |
|
211 | + if ( ! empty( $args['step'] ) ) { |
|
212 | + $output .= ' step="' . $args['step'] . '" '; |
|
213 | + } |
|
214 | + |
|
215 | + // required |
|
216 | + if ( ! empty( $args['required'] ) ) { |
|
217 | + $output .= ' required '; |
|
218 | + } |
|
219 | + |
|
220 | + // class |
|
221 | + $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
222 | + $output .= $aui_bs5 && $type == 'checkbox' ? ' class="' . $class . '" ' : ' class="form-control ' . $class . '" '; |
|
223 | + |
|
224 | + // data-attributes |
|
225 | + $output .= AUI_Component_Helper::data_attributes( $args ); |
|
226 | + |
|
227 | + // extra attributes |
|
228 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
229 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
230 | + } |
|
231 | + |
|
232 | + // close |
|
233 | + $output .= ' >'; |
|
234 | + |
|
235 | + // help text |
|
236 | + if ( ! empty( $args['help_text'] ) ) { |
|
237 | + $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
238 | + } |
|
239 | + |
|
240 | + // label |
|
241 | + if ( ! empty( $args['label'] ) ) { |
|
242 | + $label_base_class = ''; |
|
243 | + if ( $type == 'file' ) { |
|
244 | + $label_base_class = ' custom-file-label'; |
|
245 | + } elseif ( $type == 'checkbox' ) { |
|
246 | + if ( ! empty( $args['label_force_left'] ) ) { |
|
247 | + $label_args['title'] = wp_kses_post( $args['help_text'] ); |
|
248 | + $help_text = ''; |
|
249 | + //$label_args['class'] .= ' d-inline '; |
|
250 | + $args['wrap_class'] .= ' align-items-center '; |
|
251 | + }else{ |
|
252 | + |
|
253 | + } |
|
254 | + |
|
255 | + $label_base_class = $aui_bs5 ? ' form-check-label' : ' custom-control-label'; |
|
256 | + } |
|
257 | + $label_args['class'] .= $label_base_class; |
|
258 | + $temp_label_args = $label_args; |
|
259 | + if(! empty( $args['label_force_left'] )){$temp_label_args['class'] = $label_base_class." text-muted";} |
|
260 | + $label = self::label( $temp_label_args, $type ); |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + |
|
265 | + |
|
266 | + // set help text in the correct position |
|
267 | + if ( $label_after ) { |
|
268 | + $output .= $label . $help_text; |
|
269 | + } |
|
270 | + |
|
271 | + // some input types need a separate wrap |
|
272 | + if ( $type == 'file' ) { |
|
273 | + $output = self::wrap( array( |
|
274 | + 'content' => $output, |
|
275 | + 'class' => $aui_bs5 ? 'mb-3 custom-file' : 'form-group custom-file' |
|
276 | + ) ); |
|
277 | + } elseif ( $type == 'checkbox' ) { |
|
278 | + |
|
279 | + $label_args['title'] = $args['label']; |
|
280 | + $label_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ); |
|
281 | + $label = !empty( $args['label_force_left'] ) ? self::label( $label_args, 'cb' ) : '<div class="' . $label_col . ' col-form-label"></div>'; |
|
282 | + $switch_size_class = $args['switch'] && !is_bool( $args['switch'] ) ? ' custom-switch-'.esc_attr( $args['switch'] ) : ''; |
|
283 | + if ( $aui_bs5 ) { |
|
284 | + $wrap_class = $args['switch'] ? 'form-check form-switch' . $switch_size_class : 'form-check'; |
|
285 | + }else{ |
|
286 | + $wrap_class = $args['switch'] ? 'custom-switch' . $switch_size_class : 'custom-checkbox' ; |
|
287 | + } |
|
288 | + if ( ! empty( $args['label_force_left'] ) ) { |
|
289 | + $wrap_class .= $aui_bs5 ? '' : ' d-flex align-content-center'; |
|
290 | + $label = str_replace(array("form-check-label","custom-control-label"),"", self::label( $label_args, 'cb' ) ); |
|
291 | + } |
|
292 | + $output = self::wrap( array( |
|
293 | + 'content' => $output, |
|
294 | + 'class' => $aui_bs5 ? $wrap_class : 'custom-control ' . $wrap_class |
|
295 | + ) ); |
|
296 | + |
|
297 | + if ( $args['label_type'] == 'horizontal' ) { |
|
298 | + $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
299 | + $output = $label . '<div class="' . $input_col . '">' . $output . '</div>'; |
|
300 | + } |
|
301 | + } elseif ( $type == 'password' && $args['password_toggle'] && ! $args['input_group_right'] ) { |
|
302 | + |
|
303 | + |
|
304 | + // allow password field to toggle view |
|
305 | + $args['input_group_right'] = '<span class="input-group-text c-pointer px-3" |
|
306 | 306 | onclick="var $el = jQuery(this).find(\'i\');$el.toggleClass(\'fa-eye fa-eye-slash\'); |
307 | 307 | var $eli = jQuery(this).parent().parent().find(\'input\'); |
308 | 308 | if($el.hasClass(\'fa-eye\')) |
309 | 309 | {$eli.attr(\'type\',\'text\');} |
310 | 310 | else{$eli.attr(\'type\',\'password\');}" |
311 | 311 | ><i class="far fa-fw fa-eye-slash"></i></span>'; |
312 | - } |
|
313 | - |
|
314 | - // input group wraps |
|
315 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
316 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
317 | - $group_size = $size == 'lg' ? ' input-group-lg' : ''; |
|
318 | - $group_size = !$group_size && $size == 'sm' ? ' input-group-sm' : $group_size; |
|
319 | - |
|
320 | - if ( $args['input_group_left'] ) { |
|
321 | - $output = self::wrap( array( |
|
322 | - 'content' => $output, |
|
323 | - 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
|
324 | - 'input_group_left' => $args['input_group_left'], |
|
325 | - 'input_group_left_inside' => $args['input_group_left_inside'] |
|
326 | - ) ); |
|
327 | - } |
|
328 | - if ( $args['input_group_right'] ) { |
|
329 | - $output = self::wrap( array( |
|
330 | - 'content' => $output, |
|
331 | - 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
|
332 | - 'input_group_right' => $args['input_group_right'], |
|
333 | - 'input_group_right_inside' => $args['input_group_right_inside'] |
|
334 | - ) ); |
|
335 | - } |
|
336 | - |
|
337 | - } |
|
338 | - |
|
339 | - if ( ! $label_after ) { |
|
340 | - $output .= $help_text; |
|
341 | - } |
|
342 | - |
|
343 | - |
|
344 | - if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
345 | - $output = self::wrap( array( |
|
346 | - 'content' => $output, |
|
347 | - 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
348 | - ) ); |
|
349 | - } |
|
350 | - |
|
351 | - if ( ! $label_after ) { |
|
352 | - $output = $label . $output; |
|
353 | - } |
|
354 | - |
|
355 | - // wrap |
|
356 | - if ( ! $args['no_wrap'] ) { |
|
357 | - if ( ! empty( $args['form_group_class'] ) ) { |
|
358 | - $fg_class = esc_attr( $args['form_group_class'] ); |
|
359 | - }else{ |
|
360 | - $fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
361 | - } |
|
362 | - $form_group_class = $args['label_type'] == 'floating' && $type != 'checkbox' ? 'form-label-group' : $fg_class; |
|
363 | - $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
364 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
365 | - $output = self::wrap( array( |
|
366 | - 'content' => $output, |
|
367 | - 'class' => $wrap_class, |
|
368 | - 'element_require' => $args['element_require'], |
|
369 | - 'argument_id' => $args['id'], |
|
370 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
371 | - ) ); |
|
372 | - } |
|
373 | - } |
|
374 | - |
|
375 | - return $output; |
|
376 | - } |
|
377 | - |
|
378 | - public static function label( $args = array(), $type = '' ) { |
|
379 | - global $aui_bs5; |
|
380 | - //<label for="exampleInputEmail1">Email address</label> |
|
381 | - $defaults = array( |
|
382 | - 'title' => 'div', |
|
383 | - 'for' => '', |
|
384 | - 'class' => '', |
|
385 | - 'label_type' => '', // empty = hidden, top, horizontal |
|
386 | - 'label_col' => '', |
|
387 | - ); |
|
388 | - |
|
389 | - /** |
|
390 | - * Parse incoming $args into an array and merge it with $defaults |
|
391 | - */ |
|
392 | - $args = wp_parse_args( $args, $defaults ); |
|
393 | - $output = ''; |
|
394 | - |
|
395 | - if ( $args['title'] ) { |
|
396 | - |
|
397 | - // maybe hide labels //@todo set a global option for visibility class |
|
398 | - if ( $type == 'file' || $type == 'checkbox' || $type == 'radio' || ! empty( $args['label_type'] ) ) { |
|
399 | - $class = $args['class']; |
|
400 | - } else { |
|
401 | - $class = 'sr-only ' . $args['class']; |
|
402 | - } |
|
403 | - |
|
404 | - // maybe horizontal |
|
405 | - if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
406 | - $class .= ' ' . AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ) . ' col-form-label '.$type; |
|
407 | - } |
|
408 | - |
|
409 | - if( $aui_bs5 ){ $class .= ' form-label'; } |
|
410 | - |
|
411 | - // open |
|
412 | - $output .= '<label '; |
|
413 | - |
|
414 | - // for |
|
415 | - if ( ! empty( $args['for'] ) ) { |
|
416 | - $output .= ' for="' . esc_attr( $args['for'] ) . '" '; |
|
417 | - } |
|
418 | - |
|
419 | - // class |
|
420 | - $class = $class ? AUI_Component_Helper::esc_classes( $class ) : ''; |
|
421 | - $output .= ' class="' . $class . '" '; |
|
422 | - |
|
423 | - // close |
|
424 | - $output .= '>'; |
|
425 | - |
|
426 | - |
|
427 | - // title, don't escape fully as can contain html |
|
428 | - if ( ! empty( $args['title'] ) ) { |
|
429 | - $output .= wp_kses_post( $args['title'] ); |
|
430 | - } |
|
431 | - |
|
432 | - // close wrap |
|
433 | - $output .= '</label>'; |
|
434 | - |
|
435 | - |
|
436 | - } |
|
437 | - |
|
438 | - |
|
439 | - return $output; |
|
440 | - } |
|
441 | - |
|
442 | - /** |
|
443 | - * Wrap some content in a HTML wrapper. |
|
444 | - * |
|
445 | - * @param array $args |
|
446 | - * |
|
447 | - * @return string |
|
448 | - */ |
|
449 | - public static function wrap( $args = array() ) { |
|
450 | - global $aui_bs5; |
|
451 | - $defaults = array( |
|
452 | - 'type' => 'div', |
|
453 | - 'class' => $aui_bs5 ? 'mb-3' : 'form-group', |
|
454 | - 'content' => '', |
|
455 | - 'input_group_left' => '', |
|
456 | - 'input_group_right' => '', |
|
457 | - 'input_group_left_inside' => false, |
|
458 | - 'input_group_right_inside' => false, |
|
459 | - 'element_require' => '', |
|
460 | - 'argument_id' => '', |
|
461 | - 'wrap_attributes' => array() |
|
462 | - ); |
|
463 | - |
|
464 | - /** |
|
465 | - * Parse incoming $args into an array and merge it with $defaults |
|
466 | - */ |
|
467 | - $args = wp_parse_args( $args, $defaults ); |
|
468 | - $output = ''; |
|
469 | - if ( $args['type'] ) { |
|
470 | - |
|
471 | - // open |
|
472 | - $output .= '<' . sanitize_html_class( $args['type'] ); |
|
473 | - |
|
474 | - // element require |
|
475 | - if ( ! empty( $args['element_require'] ) ) { |
|
476 | - $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
477 | - $args['class'] .= " aui-conditional-field"; |
|
478 | - } |
|
479 | - |
|
480 | - // argument_id |
|
481 | - if ( ! empty( $args['argument_id'] ) ) { |
|
482 | - $output .= ' data-argument="' . esc_attr( $args['argument_id'] ) . '"'; |
|
483 | - } |
|
484 | - |
|
485 | - // class |
|
486 | - $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
487 | - $output .= ' class="' . $class . '" '; |
|
488 | - |
|
489 | - // Attributes |
|
490 | - if ( ! empty( $args['wrap_attributes'] ) ) { |
|
491 | - $output .= AUI_Component_Helper::extra_attributes( $args['wrap_attributes'] ); |
|
492 | - } |
|
493 | - |
|
494 | - // close wrap |
|
495 | - $output .= ' >'; |
|
496 | - |
|
497 | - |
|
498 | - // Input group left |
|
499 | - if ( ! empty( $args['input_group_left'] ) ) { |
|
500 | - $position_class = ! empty( $args['input_group_left_inside'] ) ? 'position-absolute h-100' : ''; |
|
501 | - $input_group_left = strpos( $args['input_group_left'], '<' ) !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>'; |
|
502 | - $output .= $aui_bs5 ? $input_group_left : '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>'; |
|
312 | + } |
|
313 | + |
|
314 | + // input group wraps |
|
315 | + if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
316 | + $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
317 | + $group_size = $size == 'lg' ? ' input-group-lg' : ''; |
|
318 | + $group_size = !$group_size && $size == 'sm' ? ' input-group-sm' : $group_size; |
|
319 | + |
|
320 | + if ( $args['input_group_left'] ) { |
|
321 | + $output = self::wrap( array( |
|
322 | + 'content' => $output, |
|
323 | + 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
|
324 | + 'input_group_left' => $args['input_group_left'], |
|
325 | + 'input_group_left_inside' => $args['input_group_left_inside'] |
|
326 | + ) ); |
|
327 | + } |
|
328 | + if ( $args['input_group_right'] ) { |
|
329 | + $output = self::wrap( array( |
|
330 | + 'content' => $output, |
|
331 | + 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
|
332 | + 'input_group_right' => $args['input_group_right'], |
|
333 | + 'input_group_right_inside' => $args['input_group_right_inside'] |
|
334 | + ) ); |
|
335 | + } |
|
336 | + |
|
337 | + } |
|
338 | + |
|
339 | + if ( ! $label_after ) { |
|
340 | + $output .= $help_text; |
|
341 | + } |
|
342 | + |
|
343 | + |
|
344 | + if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
345 | + $output = self::wrap( array( |
|
346 | + 'content' => $output, |
|
347 | + 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
348 | + ) ); |
|
349 | + } |
|
350 | + |
|
351 | + if ( ! $label_after ) { |
|
352 | + $output = $label . $output; |
|
353 | + } |
|
354 | + |
|
355 | + // wrap |
|
356 | + if ( ! $args['no_wrap'] ) { |
|
357 | + if ( ! empty( $args['form_group_class'] ) ) { |
|
358 | + $fg_class = esc_attr( $args['form_group_class'] ); |
|
359 | + }else{ |
|
360 | + $fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
361 | + } |
|
362 | + $form_group_class = $args['label_type'] == 'floating' && $type != 'checkbox' ? 'form-label-group' : $fg_class; |
|
363 | + $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
364 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
365 | + $output = self::wrap( array( |
|
366 | + 'content' => $output, |
|
367 | + 'class' => $wrap_class, |
|
368 | + 'element_require' => $args['element_require'], |
|
369 | + 'argument_id' => $args['id'], |
|
370 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
371 | + ) ); |
|
372 | + } |
|
373 | + } |
|
374 | + |
|
375 | + return $output; |
|
376 | + } |
|
377 | + |
|
378 | + public static function label( $args = array(), $type = '' ) { |
|
379 | + global $aui_bs5; |
|
380 | + //<label for="exampleInputEmail1">Email address</label> |
|
381 | + $defaults = array( |
|
382 | + 'title' => 'div', |
|
383 | + 'for' => '', |
|
384 | + 'class' => '', |
|
385 | + 'label_type' => '', // empty = hidden, top, horizontal |
|
386 | + 'label_col' => '', |
|
387 | + ); |
|
388 | + |
|
389 | + /** |
|
390 | + * Parse incoming $args into an array and merge it with $defaults |
|
391 | + */ |
|
392 | + $args = wp_parse_args( $args, $defaults ); |
|
393 | + $output = ''; |
|
394 | + |
|
395 | + if ( $args['title'] ) { |
|
396 | + |
|
397 | + // maybe hide labels //@todo set a global option for visibility class |
|
398 | + if ( $type == 'file' || $type == 'checkbox' || $type == 'radio' || ! empty( $args['label_type'] ) ) { |
|
399 | + $class = $args['class']; |
|
400 | + } else { |
|
401 | + $class = 'sr-only ' . $args['class']; |
|
402 | + } |
|
403 | + |
|
404 | + // maybe horizontal |
|
405 | + if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
406 | + $class .= ' ' . AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ) . ' col-form-label '.$type; |
|
407 | + } |
|
408 | + |
|
409 | + if( $aui_bs5 ){ $class .= ' form-label'; } |
|
410 | + |
|
411 | + // open |
|
412 | + $output .= '<label '; |
|
413 | + |
|
414 | + // for |
|
415 | + if ( ! empty( $args['for'] ) ) { |
|
416 | + $output .= ' for="' . esc_attr( $args['for'] ) . '" '; |
|
417 | + } |
|
418 | + |
|
419 | + // class |
|
420 | + $class = $class ? AUI_Component_Helper::esc_classes( $class ) : ''; |
|
421 | + $output .= ' class="' . $class . '" '; |
|
422 | + |
|
423 | + // close |
|
424 | + $output .= '>'; |
|
425 | + |
|
426 | + |
|
427 | + // title, don't escape fully as can contain html |
|
428 | + if ( ! empty( $args['title'] ) ) { |
|
429 | + $output .= wp_kses_post( $args['title'] ); |
|
430 | + } |
|
431 | + |
|
432 | + // close wrap |
|
433 | + $output .= '</label>'; |
|
434 | + |
|
435 | + |
|
436 | + } |
|
437 | + |
|
438 | + |
|
439 | + return $output; |
|
440 | + } |
|
441 | + |
|
442 | + /** |
|
443 | + * Wrap some content in a HTML wrapper. |
|
444 | + * |
|
445 | + * @param array $args |
|
446 | + * |
|
447 | + * @return string |
|
448 | + */ |
|
449 | + public static function wrap( $args = array() ) { |
|
450 | + global $aui_bs5; |
|
451 | + $defaults = array( |
|
452 | + 'type' => 'div', |
|
453 | + 'class' => $aui_bs5 ? 'mb-3' : 'form-group', |
|
454 | + 'content' => '', |
|
455 | + 'input_group_left' => '', |
|
456 | + 'input_group_right' => '', |
|
457 | + 'input_group_left_inside' => false, |
|
458 | + 'input_group_right_inside' => false, |
|
459 | + 'element_require' => '', |
|
460 | + 'argument_id' => '', |
|
461 | + 'wrap_attributes' => array() |
|
462 | + ); |
|
463 | + |
|
464 | + /** |
|
465 | + * Parse incoming $args into an array and merge it with $defaults |
|
466 | + */ |
|
467 | + $args = wp_parse_args( $args, $defaults ); |
|
468 | + $output = ''; |
|
469 | + if ( $args['type'] ) { |
|
470 | + |
|
471 | + // open |
|
472 | + $output .= '<' . sanitize_html_class( $args['type'] ); |
|
473 | + |
|
474 | + // element require |
|
475 | + if ( ! empty( $args['element_require'] ) ) { |
|
476 | + $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
477 | + $args['class'] .= " aui-conditional-field"; |
|
478 | + } |
|
479 | + |
|
480 | + // argument_id |
|
481 | + if ( ! empty( $args['argument_id'] ) ) { |
|
482 | + $output .= ' data-argument="' . esc_attr( $args['argument_id'] ) . '"'; |
|
483 | + } |
|
484 | + |
|
485 | + // class |
|
486 | + $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
487 | + $output .= ' class="' . $class . '" '; |
|
488 | + |
|
489 | + // Attributes |
|
490 | + if ( ! empty( $args['wrap_attributes'] ) ) { |
|
491 | + $output .= AUI_Component_Helper::extra_attributes( $args['wrap_attributes'] ); |
|
492 | + } |
|
493 | + |
|
494 | + // close wrap |
|
495 | + $output .= ' >'; |
|
496 | + |
|
497 | + |
|
498 | + // Input group left |
|
499 | + if ( ! empty( $args['input_group_left'] ) ) { |
|
500 | + $position_class = ! empty( $args['input_group_left_inside'] ) ? 'position-absolute h-100' : ''; |
|
501 | + $input_group_left = strpos( $args['input_group_left'], '<' ) !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>'; |
|
502 | + $output .= $aui_bs5 ? $input_group_left : '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>'; |
|
503 | 503 | // $output .= '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>'; |
504 | - } |
|
504 | + } |
|
505 | 505 | |
506 | - // content |
|
507 | - $output .= $args['content']; |
|
506 | + // content |
|
507 | + $output .= $args['content']; |
|
508 | 508 | |
509 | - // Input group right |
|
510 | - if ( ! empty( $args['input_group_right'] ) ) { |
|
511 | - $position_class = ! empty( $args['input_group_right_inside'] ) ? 'position-absolute h-100' : ''; |
|
512 | - $input_group_right = strpos( $args['input_group_right'], '<' ) !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>'; |
|
513 | - $output .= $aui_bs5 ? str_replace( 'input-group-text','input-group-text top-0 end-0', $input_group_right ) : '<div class="input-group-append ' . $position_class . '" style="top:0;right:0;">' . $input_group_right . '</div>'; |
|
509 | + // Input group right |
|
510 | + if ( ! empty( $args['input_group_right'] ) ) { |
|
511 | + $position_class = ! empty( $args['input_group_right_inside'] ) ? 'position-absolute h-100' : ''; |
|
512 | + $input_group_right = strpos( $args['input_group_right'], '<' ) !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>'; |
|
513 | + $output .= $aui_bs5 ? str_replace( 'input-group-text','input-group-text top-0 end-0', $input_group_right ) : '<div class="input-group-append ' . $position_class . '" style="top:0;right:0;">' . $input_group_right . '</div>'; |
|
514 | 514 | // $output .= '<div class="input-group-append ' . $position_class . '" style="top:0;right:0;">' . $input_group_right . '</div>'; |
515 | - } |
|
516 | - |
|
517 | - |
|
518 | - // close wrap |
|
519 | - $output .= '</' . sanitize_html_class( $args['type'] ) . '>'; |
|
520 | - |
|
521 | - |
|
522 | - } else { |
|
523 | - $output = $args['content']; |
|
524 | - } |
|
525 | - |
|
526 | - return $output; |
|
527 | - } |
|
528 | - |
|
529 | - /** |
|
530 | - * Build the component. |
|
531 | - * |
|
532 | - * @param array $args |
|
533 | - * |
|
534 | - * @return string The rendered component. |
|
535 | - */ |
|
536 | - public static function textarea( $args = array() ) { |
|
537 | - global $aui_bs5; |
|
538 | - |
|
539 | - $defaults = array( |
|
540 | - 'name' => '', |
|
541 | - 'class' => '', |
|
542 | - 'wrap_class' => '', |
|
543 | - 'id' => '', |
|
544 | - 'placeholder' => '', |
|
545 | - 'title' => '', |
|
546 | - 'value' => '', |
|
547 | - 'required' => false, |
|
548 | - 'label' => '', |
|
549 | - 'label_after' => false, |
|
550 | - 'label_class' => '', |
|
551 | - 'label_type' => '', |
|
552 | - 'label_col' => '', |
|
553 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
554 | - 'input_group_right' => '', |
|
555 | - 'input_group_left' => '', |
|
556 | - 'input_group_right_inside' => false, |
|
557 | - 'form_group_class' => '', |
|
558 | - 'help_text' => '', |
|
559 | - 'validation_text' => '', |
|
560 | - 'validation_pattern' => '', |
|
561 | - 'no_wrap' => false, |
|
562 | - 'rows' => '', |
|
563 | - 'wysiwyg' => false, |
|
564 | - 'allow_tags' => false, |
|
565 | - // Allow HTML tags |
|
566 | - 'element_require' => '', |
|
567 | - // [%element_id%] == "1" |
|
568 | - 'extra_attributes' => array(), |
|
569 | - // an array of extra attributes |
|
570 | - 'wrap_attributes' => array(), |
|
571 | - ); |
|
572 | - |
|
573 | - /** |
|
574 | - * Parse incoming $args into an array and merge it with $defaults |
|
575 | - */ |
|
576 | - $args = wp_parse_args( $args, $defaults ); |
|
577 | - $output = ''; |
|
578 | - $label = ''; |
|
579 | - |
|
580 | - // hidden label option needs to be empty |
|
581 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
582 | - |
|
583 | - // floating labels don't work with wysiwyg so set it as top |
|
584 | - if ( $args['label_type'] == 'floating' && ! empty( $args['wysiwyg'] ) ) { |
|
585 | - $args['label_type'] = 'top'; |
|
586 | - } |
|
587 | - |
|
588 | - $label_after = $args['label_after']; |
|
589 | - |
|
590 | - // floating labels need label after |
|
591 | - if ( $args['label_type'] == 'floating' && empty( $args['wysiwyg'] ) ) { |
|
592 | - $label_after = true; |
|
593 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
594 | - } |
|
595 | - |
|
596 | - // label |
|
597 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
598 | - } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
599 | - $label_args = array( |
|
600 | - 'title' => $args['label'], |
|
601 | - 'for' => $args['id'], |
|
602 | - 'class' => $args['label_class'] . " ", |
|
603 | - 'label_type' => $args['label_type'], |
|
604 | - 'label_col' => $args['label_col'] |
|
605 | - ); |
|
606 | - $label .= self::label( $label_args ); |
|
607 | - } |
|
608 | - |
|
609 | - // maybe horizontal label |
|
610 | - if ( $args['label_type'] == 'horizontal' ) { |
|
611 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
612 | - $label .= '<div class="' . $input_col . '">'; |
|
613 | - } |
|
614 | - |
|
615 | - if ( ! empty( $args['wysiwyg'] ) ) { |
|
616 | - ob_start(); |
|
617 | - $content = $args['value']; |
|
618 | - $editor_id = ! empty( $args['id'] ) ? sanitize_html_class( $args['id'] ) : 'wp_editor'; |
|
619 | - $settings = array( |
|
620 | - 'textarea_rows' => ! empty( absint( $args['rows'] ) ) ? absint( $args['rows'] ) : 4, |
|
621 | - 'quicktags' => false, |
|
622 | - 'media_buttons' => false, |
|
623 | - 'editor_class' => 'form-control', |
|
624 | - 'textarea_name' => ! empty( $args['name'] ) ? sanitize_html_class( $args['name'] ) : sanitize_html_class( $args['id'] ), |
|
625 | - 'teeny' => true, |
|
626 | - ); |
|
627 | - |
|
628 | - // maybe set settings if array |
|
629 | - if ( is_array( $args['wysiwyg'] ) ) { |
|
630 | - $settings = wp_parse_args( $args['wysiwyg'], $settings ); |
|
631 | - } |
|
632 | - |
|
633 | - wp_editor( $content, $editor_id, $settings ); |
|
634 | - $output .= ob_get_clean(); |
|
635 | - } else { |
|
636 | - |
|
637 | - // open |
|
638 | - $output .= '<textarea '; |
|
639 | - |
|
640 | - // name |
|
641 | - if ( ! empty( $args['name'] ) ) { |
|
642 | - $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
643 | - } |
|
644 | - |
|
645 | - // id |
|
646 | - if ( ! empty( $args['id'] ) ) { |
|
647 | - $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
648 | - } |
|
649 | - |
|
650 | - // placeholder |
|
651 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
652 | - $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
653 | - } |
|
654 | - |
|
655 | - // title |
|
656 | - if ( ! empty( $args['title'] ) ) { |
|
657 | - $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
658 | - } |
|
659 | - |
|
660 | - // validation text |
|
661 | - if ( ! empty( $args['validation_text'] ) ) { |
|
662 | - $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" '; |
|
663 | - $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
664 | - } |
|
665 | - |
|
666 | - // validation_pattern |
|
667 | - if ( ! empty( $args['validation_pattern'] ) ) { |
|
668 | - $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
669 | - } |
|
670 | - |
|
671 | - // required |
|
672 | - if ( ! empty( $args['required'] ) ) { |
|
673 | - $output .= ' required '; |
|
674 | - } |
|
675 | - |
|
676 | - // rows |
|
677 | - if ( ! empty( $args['rows'] ) ) { |
|
678 | - $output .= ' rows="' . absint( $args['rows'] ) . '" '; |
|
679 | - } |
|
680 | - |
|
681 | - |
|
682 | - // class |
|
683 | - $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
684 | - $output .= ' class="form-control ' . $class . '" '; |
|
685 | - |
|
686 | - // extra attributes |
|
687 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
688 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
689 | - } |
|
690 | - |
|
691 | - // close tag |
|
692 | - $output .= ' >'; |
|
693 | - |
|
694 | - // value |
|
695 | - if ( ! empty( $args['value'] ) ) { |
|
696 | - if ( ! empty( $args['allow_tags'] ) ) { |
|
697 | - $output .= AUI_Component_Helper::sanitize_html_field( $args['value'], $args ); // Sanitize HTML. |
|
698 | - } else { |
|
699 | - $output .= AUI_Component_Helper::sanitize_textarea_field( $args['value'] ); |
|
700 | - } |
|
701 | - } |
|
702 | - |
|
703 | - // closing tag |
|
704 | - $output .= '</textarea>'; |
|
705 | - |
|
706 | - |
|
707 | - // input group wraps |
|
708 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
709 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
710 | - if ( $args['input_group_left'] ) { |
|
711 | - $output = self::wrap( array( |
|
712 | - 'content' => $output, |
|
713 | - 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
714 | - 'input_group_left' => $args['input_group_left'], |
|
715 | - 'input_group_left_inside' => $args['input_group_left_inside'] |
|
716 | - ) ); |
|
717 | - } |
|
718 | - if ( $args['input_group_right'] ) { |
|
719 | - $output = self::wrap( array( |
|
720 | - 'content' => $output, |
|
721 | - 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
722 | - 'input_group_right' => $args['input_group_right'], |
|
723 | - 'input_group_right_inside' => $args['input_group_right_inside'] |
|
724 | - ) ); |
|
725 | - } |
|
726 | - |
|
727 | - } |
|
728 | - |
|
729 | - |
|
730 | - } |
|
731 | - |
|
732 | - if ( ! empty( $args['label'] ) && $label_after ) { |
|
733 | - $label_args = array( |
|
734 | - 'title' => $args['label'], |
|
735 | - 'for' => $args['id'], |
|
736 | - 'class' => $args['label_class'] . " ", |
|
737 | - 'label_type' => $args['label_type'], |
|
738 | - 'label_col' => $args['label_col'] |
|
739 | - ); |
|
740 | - $output .= self::label( $label_args ); |
|
741 | - } |
|
742 | - |
|
743 | - // help text |
|
744 | - if ( ! empty( $args['help_text'] ) ) { |
|
745 | - $output .= AUI_Component_Helper::help_text( $args['help_text'] ); |
|
746 | - } |
|
747 | - |
|
748 | - if ( ! $label_after ) { |
|
749 | - $output = $label . $output; |
|
750 | - } |
|
751 | - |
|
752 | - // maybe horizontal label |
|
753 | - if ( $args['label_type'] == 'horizontal' ) { |
|
754 | - $output .= '</div>'; |
|
755 | - } |
|
756 | - |
|
757 | - |
|
758 | - // wrap |
|
759 | - if ( ! $args['no_wrap'] ) { |
|
760 | - if ( ! empty( $args['form_group_class'] ) ) { |
|
761 | - $fg_class = esc_attr( $args['form_group_class'] ); |
|
762 | - }else{ |
|
763 | - $fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
764 | - } |
|
765 | - $form_group_class = $args['label_type'] == 'floating' ? 'form-label-group' : $fg_class; |
|
766 | - $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
767 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
768 | - $output = self::wrap( array( |
|
769 | - 'content' => $output, |
|
770 | - 'class' => $wrap_class, |
|
771 | - 'element_require' => $args['element_require'], |
|
772 | - 'argument_id' => $args['id'], |
|
773 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
774 | - ) ); |
|
775 | - } |
|
776 | - |
|
777 | - |
|
778 | - return $output; |
|
779 | - } |
|
780 | - |
|
781 | - /** |
|
782 | - * Build the component. |
|
783 | - * |
|
784 | - * @param array $args |
|
785 | - * |
|
786 | - * @return string The rendered component. |
|
787 | - */ |
|
788 | - public static function select( $args = array() ) { |
|
789 | - global $aui_bs5; |
|
790 | - $defaults = array( |
|
791 | - 'class' => '', |
|
792 | - 'wrap_class' => '', |
|
793 | - 'id' => '', |
|
794 | - 'title' => '', |
|
795 | - 'value' => '', |
|
796 | - // can be an array or a string |
|
797 | - 'required' => false, |
|
798 | - 'label' => '', |
|
799 | - 'label_after' => false, |
|
800 | - 'label_type' => '', |
|
801 | - 'label_col' => '', |
|
802 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
803 | - 'label_class' => '', |
|
804 | - 'help_text' => '', |
|
805 | - 'placeholder' => '', |
|
806 | - 'options' => array(), |
|
807 | - // array or string |
|
808 | - 'icon' => '', |
|
809 | - 'multiple' => false, |
|
810 | - 'select2' => false, |
|
811 | - 'no_wrap' => false, |
|
812 | - 'input_group_right' => '', |
|
813 | - 'input_group_left' => '', |
|
814 | - 'input_group_right_inside' => false, // forces the input group inside the input |
|
815 | - 'input_group_left_inside' => false, // forces the input group inside the input |
|
816 | - 'form_group_class' => '', |
|
817 | - 'element_require' => '', |
|
818 | - // [%element_id%] == "1" |
|
819 | - 'extra_attributes' => array(), |
|
820 | - // an array of extra attributes |
|
821 | - 'wrap_attributes' => array(), |
|
822 | - ); |
|
823 | - |
|
824 | - /** |
|
825 | - * Parse incoming $args into an array and merge it with $defaults |
|
826 | - */ |
|
827 | - $args = wp_parse_args( $args, $defaults ); |
|
828 | - $output = ''; |
|
829 | - |
|
830 | - // for now lets hide floating labels |
|
831 | - if ( $args['label_type'] == 'floating' ) { |
|
832 | - $args['label_type'] = 'hidden'; |
|
833 | - } |
|
834 | - |
|
835 | - // hidden label option needs to be empty |
|
836 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
837 | - |
|
838 | - |
|
839 | - $label_after = $args['label_after']; |
|
840 | - |
|
841 | - // floating labels need label after |
|
842 | - if ( $args['label_type'] == 'floating' ) { |
|
843 | - $label_after = true; |
|
844 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
845 | - } |
|
846 | - |
|
847 | - // Maybe setup select2 |
|
848 | - $is_select2 = false; |
|
849 | - if ( ! empty( $args['select2'] ) ) { |
|
850 | - $args['class'] .= ' aui-select2'; |
|
851 | - $is_select2 = true; |
|
852 | - } elseif ( strpos( $args['class'], 'aui-select2' ) !== false ) { |
|
853 | - $is_select2 = true; |
|
854 | - } |
|
855 | - |
|
856 | - // select2 tags |
|
857 | - if ( ! empty( $args['select2'] ) && $args['select2'] === 'tags' ) { // triple equals needed here for some reason |
|
858 | - $args['data-tags'] = 'true'; |
|
859 | - $args['data-token-separators'] = "[',']"; |
|
860 | - $args['multiple'] = true; |
|
861 | - } |
|
862 | - |
|
863 | - // select2 placeholder |
|
864 | - if ( $is_select2 && isset( $args['placeholder'] ) && '' != $args['placeholder'] && empty( $args['data-placeholder'] ) ) { |
|
865 | - $args['data-placeholder'] = esc_attr( $args['placeholder'] ); |
|
866 | - $args['data-allow-clear'] = isset( $args['data-allow-clear'] ) ? (bool) $args['data-allow-clear'] : true; |
|
867 | - } |
|
868 | - |
|
869 | - // Set hidden input to save empty value for multiselect. |
|
870 | - if ( ! empty( $args['multiple'] ) && ! empty( $args['name'] ) ) { |
|
871 | - $output .= '<input type="hidden" ' . AUI_Component_Helper::name( $args['name'] ) . ' value="" data-ignore-rule/>'; |
|
872 | - } |
|
873 | - |
|
874 | - // open/type |
|
875 | - $output .= '<select '; |
|
876 | - |
|
877 | - // style |
|
878 | - if ( $is_select2 && !($args['input_group_left'] || $args['input_group_right'])) { |
|
879 | - $output .= " style='width:100%;' "; |
|
880 | - } |
|
881 | - |
|
882 | - // element require |
|
883 | - if ( ! empty( $args['element_require'] ) ) { |
|
884 | - $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
885 | - $args['class'] .= " aui-conditional-field"; |
|
886 | - } |
|
887 | - |
|
888 | - // class |
|
889 | - $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
890 | - $select_class = $aui_bs5 ? 'form-select ' : 'custom-select '; |
|
891 | - $output .= AUI_Component_Helper::class_attr( $select_class . $class ); |
|
892 | - |
|
893 | - // name |
|
894 | - if ( ! empty( $args['name'] ) ) { |
|
895 | - $output .= AUI_Component_Helper::name( $args['name'], $args['multiple'] ); |
|
896 | - } |
|
897 | - |
|
898 | - // id |
|
899 | - if ( ! empty( $args['id'] ) ) { |
|
900 | - $output .= AUI_Component_Helper::id( $args['id'] ); |
|
901 | - } |
|
902 | - |
|
903 | - // title |
|
904 | - if ( ! empty( $args['title'] ) ) { |
|
905 | - $output .= AUI_Component_Helper::title( $args['title'] ); |
|
906 | - } |
|
907 | - |
|
908 | - // data-attributes |
|
909 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
910 | - |
|
911 | - // aria-attributes |
|
912 | - $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
913 | - |
|
914 | - // extra attributes |
|
915 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
916 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
917 | - } |
|
918 | - |
|
919 | - // required |
|
920 | - if ( ! empty( $args['required'] ) ) { |
|
921 | - $output .= ' required '; |
|
922 | - } |
|
923 | - |
|
924 | - // multiple |
|
925 | - if ( ! empty( $args['multiple'] ) ) { |
|
926 | - $output .= ' multiple '; |
|
927 | - } |
|
928 | - |
|
929 | - // close opening tag |
|
930 | - $output .= ' >'; |
|
931 | - |
|
932 | - // placeholder |
|
933 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] && ! $is_select2 ) { |
|
934 | - $output .= '<option value="" disabled selected hidden>' . esc_attr( $args['placeholder'] ) . '</option>'; |
|
935 | - } elseif ( $is_select2 && ! empty( $args['placeholder'] ) ) { |
|
936 | - $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder |
|
937 | - } |
|
938 | - |
|
939 | - // Options |
|
940 | - if ( ! empty( $args['options'] ) ) { |
|
941 | - |
|
942 | - if ( ! is_array( $args['options'] ) ) { |
|
943 | - $output .= $args['options']; // not the preferred way but an option |
|
944 | - } else { |
|
945 | - foreach ( $args['options'] as $val => $name ) { |
|
946 | - $selected = ''; |
|
947 | - if ( is_array( $name ) ) { |
|
948 | - if ( isset( $name['optgroup'] ) && ( $name['optgroup'] == 'start' || $name['optgroup'] == 'end' ) ) { |
|
949 | - $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
950 | - |
|
951 | - $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>'; |
|
952 | - } else { |
|
953 | - $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
954 | - $option_value = isset( $name['value'] ) ? $name['value'] : ''; |
|
955 | - $extra_attributes = !empty($name['extra_attributes']) ? AUI_Component_Helper::extra_attributes( $name['extra_attributes'] ) : ''; |
|
956 | - if ( ! empty( $args['multiple'] ) && ! empty( $args['value'] ) && is_array( $args['value'] ) ) { |
|
957 | - $selected = in_array( $option_value, stripslashes_deep( $args['value'] ) ) ? "selected" : ""; |
|
958 | - } elseif ( ! empty( $args['value'] ) ) { |
|
959 | - $selected = selected( $option_value, stripslashes_deep( $args['value'] ), false ); |
|
960 | - } elseif ( empty( $args['value'] ) && $args['value'] === $option_value ) { |
|
961 | - $selected = selected( $option_value, $args['value'], false ); |
|
962 | - } |
|
963 | - |
|
964 | - $output .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . ' '.$extra_attributes .'>' . $option_label . '</option>'; |
|
965 | - } |
|
966 | - } else { |
|
967 | - if ( ! empty( $args['value'] ) ) { |
|
968 | - if ( is_array( $args['value'] ) ) { |
|
969 | - $selected = in_array( $val, $args['value'] ) ? 'selected="selected"' : ''; |
|
970 | - } elseif ( ! empty( $args['value'] ) ) { |
|
971 | - $selected = selected( $args['value'], $val, false ); |
|
972 | - } |
|
973 | - } elseif ( $args['value'] === $val ) { |
|
974 | - $selected = selected( $args['value'], $val, false ); |
|
975 | - } |
|
976 | - $output .= '<option value="' . esc_attr( $val ) . '" ' . $selected . '>' . esc_attr( $name ) . '</option>'; |
|
977 | - } |
|
978 | - } |
|
979 | - } |
|
980 | - |
|
981 | - } |
|
982 | - |
|
983 | - // closing tag |
|
984 | - $output .= '</select>'; |
|
985 | - |
|
986 | - $label = ''; |
|
987 | - $help_text = ''; |
|
988 | - // label |
|
989 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
990 | - } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
991 | - $label_args = array( |
|
992 | - 'title' => $args['label'], |
|
993 | - 'for' => $args['id'], |
|
994 | - 'class' => $args['label_class'] . " ", |
|
995 | - 'label_type' => $args['label_type'], |
|
996 | - 'label_col' => $args['label_col'] |
|
997 | - ); |
|
998 | - $label = self::label( $label_args ); |
|
999 | - } |
|
1000 | - |
|
1001 | - // help text |
|
1002 | - if ( ! empty( $args['help_text'] ) ) { |
|
1003 | - $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
1004 | - } |
|
1005 | - |
|
1006 | - // input group wraps |
|
1007 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
1008 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
1009 | - if ( $args['input_group_left'] ) { |
|
1010 | - $output = self::wrap( array( |
|
1011 | - 'content' => $output, |
|
1012 | - 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
1013 | - 'input_group_left' => $args['input_group_left'], |
|
1014 | - 'input_group_left_inside' => $args['input_group_left_inside'] |
|
1015 | - ) ); |
|
1016 | - } |
|
1017 | - if ( $args['input_group_right'] ) { |
|
1018 | - $output = self::wrap( array( |
|
1019 | - 'content' => $output, |
|
1020 | - 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
1021 | - 'input_group_right' => $args['input_group_right'], |
|
1022 | - 'input_group_right_inside' => $args['input_group_right_inside'] |
|
1023 | - ) ); |
|
1024 | - } |
|
1025 | - |
|
1026 | - } |
|
1027 | - |
|
1028 | - if ( ! $label_after ) { |
|
1029 | - $output .= $help_text; |
|
1030 | - } |
|
1031 | - |
|
1032 | - |
|
1033 | - if ( $args['label_type'] == 'horizontal' ) { |
|
1034 | - $output = self::wrap( array( |
|
1035 | - 'content' => $output, |
|
1036 | - 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
1037 | - ) ); |
|
1038 | - } |
|
1039 | - |
|
1040 | - if ( ! $label_after ) { |
|
1041 | - $output = $label . $output; |
|
1042 | - } |
|
1043 | - |
|
1044 | - // maybe horizontal label |
|
515 | + } |
|
516 | + |
|
517 | + |
|
518 | + // close wrap |
|
519 | + $output .= '</' . sanitize_html_class( $args['type'] ) . '>'; |
|
520 | + |
|
521 | + |
|
522 | + } else { |
|
523 | + $output = $args['content']; |
|
524 | + } |
|
525 | + |
|
526 | + return $output; |
|
527 | + } |
|
528 | + |
|
529 | + /** |
|
530 | + * Build the component. |
|
531 | + * |
|
532 | + * @param array $args |
|
533 | + * |
|
534 | + * @return string The rendered component. |
|
535 | + */ |
|
536 | + public static function textarea( $args = array() ) { |
|
537 | + global $aui_bs5; |
|
538 | + |
|
539 | + $defaults = array( |
|
540 | + 'name' => '', |
|
541 | + 'class' => '', |
|
542 | + 'wrap_class' => '', |
|
543 | + 'id' => '', |
|
544 | + 'placeholder' => '', |
|
545 | + 'title' => '', |
|
546 | + 'value' => '', |
|
547 | + 'required' => false, |
|
548 | + 'label' => '', |
|
549 | + 'label_after' => false, |
|
550 | + 'label_class' => '', |
|
551 | + 'label_type' => '', |
|
552 | + 'label_col' => '', |
|
553 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
554 | + 'input_group_right' => '', |
|
555 | + 'input_group_left' => '', |
|
556 | + 'input_group_right_inside' => false, |
|
557 | + 'form_group_class' => '', |
|
558 | + 'help_text' => '', |
|
559 | + 'validation_text' => '', |
|
560 | + 'validation_pattern' => '', |
|
561 | + 'no_wrap' => false, |
|
562 | + 'rows' => '', |
|
563 | + 'wysiwyg' => false, |
|
564 | + 'allow_tags' => false, |
|
565 | + // Allow HTML tags |
|
566 | + 'element_require' => '', |
|
567 | + // [%element_id%] == "1" |
|
568 | + 'extra_attributes' => array(), |
|
569 | + // an array of extra attributes |
|
570 | + 'wrap_attributes' => array(), |
|
571 | + ); |
|
572 | + |
|
573 | + /** |
|
574 | + * Parse incoming $args into an array and merge it with $defaults |
|
575 | + */ |
|
576 | + $args = wp_parse_args( $args, $defaults ); |
|
577 | + $output = ''; |
|
578 | + $label = ''; |
|
579 | + |
|
580 | + // hidden label option needs to be empty |
|
581 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
582 | + |
|
583 | + // floating labels don't work with wysiwyg so set it as top |
|
584 | + if ( $args['label_type'] == 'floating' && ! empty( $args['wysiwyg'] ) ) { |
|
585 | + $args['label_type'] = 'top'; |
|
586 | + } |
|
587 | + |
|
588 | + $label_after = $args['label_after']; |
|
589 | + |
|
590 | + // floating labels need label after |
|
591 | + if ( $args['label_type'] == 'floating' && empty( $args['wysiwyg'] ) ) { |
|
592 | + $label_after = true; |
|
593 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
594 | + } |
|
595 | + |
|
596 | + // label |
|
597 | + if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
598 | + } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
599 | + $label_args = array( |
|
600 | + 'title' => $args['label'], |
|
601 | + 'for' => $args['id'], |
|
602 | + 'class' => $args['label_class'] . " ", |
|
603 | + 'label_type' => $args['label_type'], |
|
604 | + 'label_col' => $args['label_col'] |
|
605 | + ); |
|
606 | + $label .= self::label( $label_args ); |
|
607 | + } |
|
608 | + |
|
609 | + // maybe horizontal label |
|
610 | + if ( $args['label_type'] == 'horizontal' ) { |
|
611 | + $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
612 | + $label .= '<div class="' . $input_col . '">'; |
|
613 | + } |
|
614 | + |
|
615 | + if ( ! empty( $args['wysiwyg'] ) ) { |
|
616 | + ob_start(); |
|
617 | + $content = $args['value']; |
|
618 | + $editor_id = ! empty( $args['id'] ) ? sanitize_html_class( $args['id'] ) : 'wp_editor'; |
|
619 | + $settings = array( |
|
620 | + 'textarea_rows' => ! empty( absint( $args['rows'] ) ) ? absint( $args['rows'] ) : 4, |
|
621 | + 'quicktags' => false, |
|
622 | + 'media_buttons' => false, |
|
623 | + 'editor_class' => 'form-control', |
|
624 | + 'textarea_name' => ! empty( $args['name'] ) ? sanitize_html_class( $args['name'] ) : sanitize_html_class( $args['id'] ), |
|
625 | + 'teeny' => true, |
|
626 | + ); |
|
627 | + |
|
628 | + // maybe set settings if array |
|
629 | + if ( is_array( $args['wysiwyg'] ) ) { |
|
630 | + $settings = wp_parse_args( $args['wysiwyg'], $settings ); |
|
631 | + } |
|
632 | + |
|
633 | + wp_editor( $content, $editor_id, $settings ); |
|
634 | + $output .= ob_get_clean(); |
|
635 | + } else { |
|
636 | + |
|
637 | + // open |
|
638 | + $output .= '<textarea '; |
|
639 | + |
|
640 | + // name |
|
641 | + if ( ! empty( $args['name'] ) ) { |
|
642 | + $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
643 | + } |
|
644 | + |
|
645 | + // id |
|
646 | + if ( ! empty( $args['id'] ) ) { |
|
647 | + $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
648 | + } |
|
649 | + |
|
650 | + // placeholder |
|
651 | + if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
652 | + $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
653 | + } |
|
654 | + |
|
655 | + // title |
|
656 | + if ( ! empty( $args['title'] ) ) { |
|
657 | + $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
658 | + } |
|
659 | + |
|
660 | + // validation text |
|
661 | + if ( ! empty( $args['validation_text'] ) ) { |
|
662 | + $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" '; |
|
663 | + $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
664 | + } |
|
665 | + |
|
666 | + // validation_pattern |
|
667 | + if ( ! empty( $args['validation_pattern'] ) ) { |
|
668 | + $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
669 | + } |
|
670 | + |
|
671 | + // required |
|
672 | + if ( ! empty( $args['required'] ) ) { |
|
673 | + $output .= ' required '; |
|
674 | + } |
|
675 | + |
|
676 | + // rows |
|
677 | + if ( ! empty( $args['rows'] ) ) { |
|
678 | + $output .= ' rows="' . absint( $args['rows'] ) . '" '; |
|
679 | + } |
|
680 | + |
|
681 | + |
|
682 | + // class |
|
683 | + $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
684 | + $output .= ' class="form-control ' . $class . '" '; |
|
685 | + |
|
686 | + // extra attributes |
|
687 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
688 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
689 | + } |
|
690 | + |
|
691 | + // close tag |
|
692 | + $output .= ' >'; |
|
693 | + |
|
694 | + // value |
|
695 | + if ( ! empty( $args['value'] ) ) { |
|
696 | + if ( ! empty( $args['allow_tags'] ) ) { |
|
697 | + $output .= AUI_Component_Helper::sanitize_html_field( $args['value'], $args ); // Sanitize HTML. |
|
698 | + } else { |
|
699 | + $output .= AUI_Component_Helper::sanitize_textarea_field( $args['value'] ); |
|
700 | + } |
|
701 | + } |
|
702 | + |
|
703 | + // closing tag |
|
704 | + $output .= '</textarea>'; |
|
705 | + |
|
706 | + |
|
707 | + // input group wraps |
|
708 | + if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
709 | + $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
710 | + if ( $args['input_group_left'] ) { |
|
711 | + $output = self::wrap( array( |
|
712 | + 'content' => $output, |
|
713 | + 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
714 | + 'input_group_left' => $args['input_group_left'], |
|
715 | + 'input_group_left_inside' => $args['input_group_left_inside'] |
|
716 | + ) ); |
|
717 | + } |
|
718 | + if ( $args['input_group_right'] ) { |
|
719 | + $output = self::wrap( array( |
|
720 | + 'content' => $output, |
|
721 | + 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
722 | + 'input_group_right' => $args['input_group_right'], |
|
723 | + 'input_group_right_inside' => $args['input_group_right_inside'] |
|
724 | + ) ); |
|
725 | + } |
|
726 | + |
|
727 | + } |
|
728 | + |
|
729 | + |
|
730 | + } |
|
731 | + |
|
732 | + if ( ! empty( $args['label'] ) && $label_after ) { |
|
733 | + $label_args = array( |
|
734 | + 'title' => $args['label'], |
|
735 | + 'for' => $args['id'], |
|
736 | + 'class' => $args['label_class'] . " ", |
|
737 | + 'label_type' => $args['label_type'], |
|
738 | + 'label_col' => $args['label_col'] |
|
739 | + ); |
|
740 | + $output .= self::label( $label_args ); |
|
741 | + } |
|
742 | + |
|
743 | + // help text |
|
744 | + if ( ! empty( $args['help_text'] ) ) { |
|
745 | + $output .= AUI_Component_Helper::help_text( $args['help_text'] ); |
|
746 | + } |
|
747 | + |
|
748 | + if ( ! $label_after ) { |
|
749 | + $output = $label . $output; |
|
750 | + } |
|
751 | + |
|
752 | + // maybe horizontal label |
|
753 | + if ( $args['label_type'] == 'horizontal' ) { |
|
754 | + $output .= '</div>'; |
|
755 | + } |
|
756 | + |
|
757 | + |
|
758 | + // wrap |
|
759 | + if ( ! $args['no_wrap'] ) { |
|
760 | + if ( ! empty( $args['form_group_class'] ) ) { |
|
761 | + $fg_class = esc_attr( $args['form_group_class'] ); |
|
762 | + }else{ |
|
763 | + $fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
764 | + } |
|
765 | + $form_group_class = $args['label_type'] == 'floating' ? 'form-label-group' : $fg_class; |
|
766 | + $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
767 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
768 | + $output = self::wrap( array( |
|
769 | + 'content' => $output, |
|
770 | + 'class' => $wrap_class, |
|
771 | + 'element_require' => $args['element_require'], |
|
772 | + 'argument_id' => $args['id'], |
|
773 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
774 | + ) ); |
|
775 | + } |
|
776 | + |
|
777 | + |
|
778 | + return $output; |
|
779 | + } |
|
780 | + |
|
781 | + /** |
|
782 | + * Build the component. |
|
783 | + * |
|
784 | + * @param array $args |
|
785 | + * |
|
786 | + * @return string The rendered component. |
|
787 | + */ |
|
788 | + public static function select( $args = array() ) { |
|
789 | + global $aui_bs5; |
|
790 | + $defaults = array( |
|
791 | + 'class' => '', |
|
792 | + 'wrap_class' => '', |
|
793 | + 'id' => '', |
|
794 | + 'title' => '', |
|
795 | + 'value' => '', |
|
796 | + // can be an array or a string |
|
797 | + 'required' => false, |
|
798 | + 'label' => '', |
|
799 | + 'label_after' => false, |
|
800 | + 'label_type' => '', |
|
801 | + 'label_col' => '', |
|
802 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
803 | + 'label_class' => '', |
|
804 | + 'help_text' => '', |
|
805 | + 'placeholder' => '', |
|
806 | + 'options' => array(), |
|
807 | + // array or string |
|
808 | + 'icon' => '', |
|
809 | + 'multiple' => false, |
|
810 | + 'select2' => false, |
|
811 | + 'no_wrap' => false, |
|
812 | + 'input_group_right' => '', |
|
813 | + 'input_group_left' => '', |
|
814 | + 'input_group_right_inside' => false, // forces the input group inside the input |
|
815 | + 'input_group_left_inside' => false, // forces the input group inside the input |
|
816 | + 'form_group_class' => '', |
|
817 | + 'element_require' => '', |
|
818 | + // [%element_id%] == "1" |
|
819 | + 'extra_attributes' => array(), |
|
820 | + // an array of extra attributes |
|
821 | + 'wrap_attributes' => array(), |
|
822 | + ); |
|
823 | + |
|
824 | + /** |
|
825 | + * Parse incoming $args into an array and merge it with $defaults |
|
826 | + */ |
|
827 | + $args = wp_parse_args( $args, $defaults ); |
|
828 | + $output = ''; |
|
829 | + |
|
830 | + // for now lets hide floating labels |
|
831 | + if ( $args['label_type'] == 'floating' ) { |
|
832 | + $args['label_type'] = 'hidden'; |
|
833 | + } |
|
834 | + |
|
835 | + // hidden label option needs to be empty |
|
836 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
837 | + |
|
838 | + |
|
839 | + $label_after = $args['label_after']; |
|
840 | + |
|
841 | + // floating labels need label after |
|
842 | + if ( $args['label_type'] == 'floating' ) { |
|
843 | + $label_after = true; |
|
844 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
845 | + } |
|
846 | + |
|
847 | + // Maybe setup select2 |
|
848 | + $is_select2 = false; |
|
849 | + if ( ! empty( $args['select2'] ) ) { |
|
850 | + $args['class'] .= ' aui-select2'; |
|
851 | + $is_select2 = true; |
|
852 | + } elseif ( strpos( $args['class'], 'aui-select2' ) !== false ) { |
|
853 | + $is_select2 = true; |
|
854 | + } |
|
855 | + |
|
856 | + // select2 tags |
|
857 | + if ( ! empty( $args['select2'] ) && $args['select2'] === 'tags' ) { // triple equals needed here for some reason |
|
858 | + $args['data-tags'] = 'true'; |
|
859 | + $args['data-token-separators'] = "[',']"; |
|
860 | + $args['multiple'] = true; |
|
861 | + } |
|
862 | + |
|
863 | + // select2 placeholder |
|
864 | + if ( $is_select2 && isset( $args['placeholder'] ) && '' != $args['placeholder'] && empty( $args['data-placeholder'] ) ) { |
|
865 | + $args['data-placeholder'] = esc_attr( $args['placeholder'] ); |
|
866 | + $args['data-allow-clear'] = isset( $args['data-allow-clear'] ) ? (bool) $args['data-allow-clear'] : true; |
|
867 | + } |
|
868 | + |
|
869 | + // Set hidden input to save empty value for multiselect. |
|
870 | + if ( ! empty( $args['multiple'] ) && ! empty( $args['name'] ) ) { |
|
871 | + $output .= '<input type="hidden" ' . AUI_Component_Helper::name( $args['name'] ) . ' value="" data-ignore-rule/>'; |
|
872 | + } |
|
873 | + |
|
874 | + // open/type |
|
875 | + $output .= '<select '; |
|
876 | + |
|
877 | + // style |
|
878 | + if ( $is_select2 && !($args['input_group_left'] || $args['input_group_right'])) { |
|
879 | + $output .= " style='width:100%;' "; |
|
880 | + } |
|
881 | + |
|
882 | + // element require |
|
883 | + if ( ! empty( $args['element_require'] ) ) { |
|
884 | + $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
885 | + $args['class'] .= " aui-conditional-field"; |
|
886 | + } |
|
887 | + |
|
888 | + // class |
|
889 | + $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
890 | + $select_class = $aui_bs5 ? 'form-select ' : 'custom-select '; |
|
891 | + $output .= AUI_Component_Helper::class_attr( $select_class . $class ); |
|
892 | + |
|
893 | + // name |
|
894 | + if ( ! empty( $args['name'] ) ) { |
|
895 | + $output .= AUI_Component_Helper::name( $args['name'], $args['multiple'] ); |
|
896 | + } |
|
897 | + |
|
898 | + // id |
|
899 | + if ( ! empty( $args['id'] ) ) { |
|
900 | + $output .= AUI_Component_Helper::id( $args['id'] ); |
|
901 | + } |
|
902 | + |
|
903 | + // title |
|
904 | + if ( ! empty( $args['title'] ) ) { |
|
905 | + $output .= AUI_Component_Helper::title( $args['title'] ); |
|
906 | + } |
|
907 | + |
|
908 | + // data-attributes |
|
909 | + $output .= AUI_Component_Helper::data_attributes( $args ); |
|
910 | + |
|
911 | + // aria-attributes |
|
912 | + $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
913 | + |
|
914 | + // extra attributes |
|
915 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
916 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
917 | + } |
|
918 | + |
|
919 | + // required |
|
920 | + if ( ! empty( $args['required'] ) ) { |
|
921 | + $output .= ' required '; |
|
922 | + } |
|
923 | + |
|
924 | + // multiple |
|
925 | + if ( ! empty( $args['multiple'] ) ) { |
|
926 | + $output .= ' multiple '; |
|
927 | + } |
|
928 | + |
|
929 | + // close opening tag |
|
930 | + $output .= ' >'; |
|
931 | + |
|
932 | + // placeholder |
|
933 | + if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] && ! $is_select2 ) { |
|
934 | + $output .= '<option value="" disabled selected hidden>' . esc_attr( $args['placeholder'] ) . '</option>'; |
|
935 | + } elseif ( $is_select2 && ! empty( $args['placeholder'] ) ) { |
|
936 | + $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder |
|
937 | + } |
|
938 | + |
|
939 | + // Options |
|
940 | + if ( ! empty( $args['options'] ) ) { |
|
941 | + |
|
942 | + if ( ! is_array( $args['options'] ) ) { |
|
943 | + $output .= $args['options']; // not the preferred way but an option |
|
944 | + } else { |
|
945 | + foreach ( $args['options'] as $val => $name ) { |
|
946 | + $selected = ''; |
|
947 | + if ( is_array( $name ) ) { |
|
948 | + if ( isset( $name['optgroup'] ) && ( $name['optgroup'] == 'start' || $name['optgroup'] == 'end' ) ) { |
|
949 | + $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
950 | + |
|
951 | + $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>'; |
|
952 | + } else { |
|
953 | + $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
954 | + $option_value = isset( $name['value'] ) ? $name['value'] : ''; |
|
955 | + $extra_attributes = !empty($name['extra_attributes']) ? AUI_Component_Helper::extra_attributes( $name['extra_attributes'] ) : ''; |
|
956 | + if ( ! empty( $args['multiple'] ) && ! empty( $args['value'] ) && is_array( $args['value'] ) ) { |
|
957 | + $selected = in_array( $option_value, stripslashes_deep( $args['value'] ) ) ? "selected" : ""; |
|
958 | + } elseif ( ! empty( $args['value'] ) ) { |
|
959 | + $selected = selected( $option_value, stripslashes_deep( $args['value'] ), false ); |
|
960 | + } elseif ( empty( $args['value'] ) && $args['value'] === $option_value ) { |
|
961 | + $selected = selected( $option_value, $args['value'], false ); |
|
962 | + } |
|
963 | + |
|
964 | + $output .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . ' '.$extra_attributes .'>' . $option_label . '</option>'; |
|
965 | + } |
|
966 | + } else { |
|
967 | + if ( ! empty( $args['value'] ) ) { |
|
968 | + if ( is_array( $args['value'] ) ) { |
|
969 | + $selected = in_array( $val, $args['value'] ) ? 'selected="selected"' : ''; |
|
970 | + } elseif ( ! empty( $args['value'] ) ) { |
|
971 | + $selected = selected( $args['value'], $val, false ); |
|
972 | + } |
|
973 | + } elseif ( $args['value'] === $val ) { |
|
974 | + $selected = selected( $args['value'], $val, false ); |
|
975 | + } |
|
976 | + $output .= '<option value="' . esc_attr( $val ) . '" ' . $selected . '>' . esc_attr( $name ) . '</option>'; |
|
977 | + } |
|
978 | + } |
|
979 | + } |
|
980 | + |
|
981 | + } |
|
982 | + |
|
983 | + // closing tag |
|
984 | + $output .= '</select>'; |
|
985 | + |
|
986 | + $label = ''; |
|
987 | + $help_text = ''; |
|
988 | + // label |
|
989 | + if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
990 | + } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
991 | + $label_args = array( |
|
992 | + 'title' => $args['label'], |
|
993 | + 'for' => $args['id'], |
|
994 | + 'class' => $args['label_class'] . " ", |
|
995 | + 'label_type' => $args['label_type'], |
|
996 | + 'label_col' => $args['label_col'] |
|
997 | + ); |
|
998 | + $label = self::label( $label_args ); |
|
999 | + } |
|
1000 | + |
|
1001 | + // help text |
|
1002 | + if ( ! empty( $args['help_text'] ) ) { |
|
1003 | + $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
1004 | + } |
|
1005 | + |
|
1006 | + // input group wraps |
|
1007 | + if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
1008 | + $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
1009 | + if ( $args['input_group_left'] ) { |
|
1010 | + $output = self::wrap( array( |
|
1011 | + 'content' => $output, |
|
1012 | + 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
1013 | + 'input_group_left' => $args['input_group_left'], |
|
1014 | + 'input_group_left_inside' => $args['input_group_left_inside'] |
|
1015 | + ) ); |
|
1016 | + } |
|
1017 | + if ( $args['input_group_right'] ) { |
|
1018 | + $output = self::wrap( array( |
|
1019 | + 'content' => $output, |
|
1020 | + 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
1021 | + 'input_group_right' => $args['input_group_right'], |
|
1022 | + 'input_group_right_inside' => $args['input_group_right_inside'] |
|
1023 | + ) ); |
|
1024 | + } |
|
1025 | + |
|
1026 | + } |
|
1027 | + |
|
1028 | + if ( ! $label_after ) { |
|
1029 | + $output .= $help_text; |
|
1030 | + } |
|
1031 | + |
|
1032 | + |
|
1033 | + if ( $args['label_type'] == 'horizontal' ) { |
|
1034 | + $output = self::wrap( array( |
|
1035 | + 'content' => $output, |
|
1036 | + 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
1037 | + ) ); |
|
1038 | + } |
|
1039 | + |
|
1040 | + if ( ! $label_after ) { |
|
1041 | + $output = $label . $output; |
|
1042 | + } |
|
1043 | + |
|
1044 | + // maybe horizontal label |
|
1045 | 1045 | // if ( $args['label_type'] == 'horizontal' ) { |
1046 | 1046 | // $output .= '</div>'; |
1047 | 1047 | // } |
1048 | 1048 | |
1049 | 1049 | |
1050 | - // wrap |
|
1051 | - if ( ! $args['no_wrap'] ) { |
|
1052 | - if ( ! empty( $args['form_group_class'] ) ) { |
|
1053 | - $fg_class = esc_attr( $args['form_group_class'] ); |
|
1054 | - }else{ |
|
1055 | - $fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
1056 | - } |
|
1057 | - $wrap_class = $args['label_type'] == 'horizontal' ? $fg_class . ' row' : $fg_class; |
|
1058 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1059 | - $output = self::wrap( array( |
|
1060 | - 'content' => $output, |
|
1061 | - 'class' => $wrap_class, |
|
1062 | - 'element_require' => $args['element_require'], |
|
1063 | - 'argument_id' => $args['id'], |
|
1064 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
1065 | - ) ); |
|
1066 | - } |
|
1067 | - |
|
1068 | - |
|
1069 | - return $output; |
|
1070 | - } |
|
1071 | - |
|
1072 | - /** |
|
1073 | - * Build the component. |
|
1074 | - * |
|
1075 | - * @param array $args |
|
1076 | - * |
|
1077 | - * @return string The rendered component. |
|
1078 | - */ |
|
1079 | - public static function radio( $args = array() ) { |
|
1080 | - global $aui_bs5; |
|
1081 | - |
|
1082 | - $defaults = array( |
|
1083 | - 'class' => '', |
|
1084 | - 'wrap_class' => '', |
|
1085 | - 'id' => '', |
|
1086 | - 'title' => '', |
|
1087 | - 'horizontal' => false, |
|
1088 | - // sets the lable horizontal |
|
1089 | - 'value' => '', |
|
1090 | - 'label' => '', |
|
1091 | - 'label_class' => '', |
|
1092 | - 'label_type' => '', |
|
1093 | - 'label_col' => '', |
|
1094 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
1095 | - 'help_text' => '', |
|
1096 | - 'inline' => true, |
|
1097 | - 'required' => false, |
|
1098 | - 'options' => array(), |
|
1099 | - 'icon' => '', |
|
1100 | - 'no_wrap' => false, |
|
1101 | - 'element_require' => '', |
|
1102 | - // [%element_id%] == "1" |
|
1103 | - 'extra_attributes' => array(), |
|
1104 | - // an array of extra attributes |
|
1105 | - 'wrap_attributes' => array() |
|
1106 | - ); |
|
1107 | - |
|
1108 | - /** |
|
1109 | - * Parse incoming $args into an array and merge it with $defaults |
|
1110 | - */ |
|
1111 | - $args = wp_parse_args( $args, $defaults ); |
|
1112 | - |
|
1113 | - // for now lets use horizontal for floating |
|
1114 | - if ( $args['label_type'] == 'floating' ) { |
|
1115 | - $args['label_type'] = 'horizontal'; |
|
1116 | - } |
|
1117 | - |
|
1118 | - $label_args = array( |
|
1119 | - 'title' => $args['label'], |
|
1120 | - 'class' => $args['label_class'] . " pt-0 ", |
|
1121 | - 'label_type' => $args['label_type'], |
|
1122 | - 'label_col' => $args['label_col'] |
|
1123 | - ); |
|
1124 | - |
|
1125 | - $output = ''; |
|
1126 | - |
|
1127 | - |
|
1128 | - // label before |
|
1129 | - if ( ! empty( $args['label'] ) ) { |
|
1130 | - $output .= self::label( $label_args, 'radio' ); |
|
1131 | - } |
|
1132 | - |
|
1133 | - // maybe horizontal label |
|
1134 | - if ( $args['label_type'] == 'horizontal' ) { |
|
1135 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
1136 | - $output .= '<div class="' . $input_col . '">'; |
|
1137 | - } |
|
1138 | - |
|
1139 | - if ( ! empty( $args['options'] ) ) { |
|
1140 | - $count = 0; |
|
1141 | - foreach ( $args['options'] as $value => $label ) { |
|
1142 | - $option_args = $args; |
|
1143 | - $option_args['value'] = $value; |
|
1144 | - $option_args['label'] = $label; |
|
1145 | - $option_args['checked'] = $value == $args['value'] ? true : false; |
|
1146 | - $output .= self::radio_option( $option_args, $count ); |
|
1147 | - $count ++; |
|
1148 | - } |
|
1149 | - } |
|
1150 | - |
|
1151 | - // help text |
|
1152 | - $help_text = ! empty( $args['help_text'] ) ? AUI_Component_Helper::help_text( $args['help_text'] ) : ''; |
|
1153 | - $output .= $help_text; |
|
1154 | - |
|
1155 | - // maybe horizontal label |
|
1156 | - if ( $args['label_type'] == 'horizontal' ) { |
|
1157 | - $output .= '</div>'; |
|
1158 | - } |
|
1159 | - |
|
1160 | - // wrap |
|
1161 | - $fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
1162 | - $wrap_class = $args['label_type'] == 'horizontal' ? $fg_class . ' row' : $fg_class; |
|
1163 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1164 | - $output = self::wrap( array( |
|
1165 | - 'content' => $output, |
|
1166 | - 'class' => $wrap_class, |
|
1167 | - 'element_require' => $args['element_require'], |
|
1168 | - 'argument_id' => $args['id'], |
|
1169 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
1170 | - ) ); |
|
1171 | - |
|
1172 | - |
|
1173 | - return $output; |
|
1174 | - } |
|
1175 | - |
|
1176 | - /** |
|
1177 | - * Build the component. |
|
1178 | - * |
|
1179 | - * @param array $args |
|
1180 | - * |
|
1181 | - * @return string The rendered component. |
|
1182 | - */ |
|
1183 | - public static function radio_option( $args = array(), $count = '' ) { |
|
1184 | - $defaults = array( |
|
1185 | - 'class' => '', |
|
1186 | - 'id' => '', |
|
1187 | - 'title' => '', |
|
1188 | - 'value' => '', |
|
1189 | - 'required' => false, |
|
1190 | - 'inline' => true, |
|
1191 | - 'label' => '', |
|
1192 | - 'options' => array(), |
|
1193 | - 'icon' => '', |
|
1194 | - 'no_wrap' => false, |
|
1195 | - 'extra_attributes' => array() // an array of extra attributes |
|
1196 | - ); |
|
1197 | - |
|
1198 | - /** |
|
1199 | - * Parse incoming $args into an array and merge it with $defaults |
|
1200 | - */ |
|
1201 | - $args = wp_parse_args( $args, $defaults ); |
|
1202 | - |
|
1203 | - $output = ''; |
|
1204 | - |
|
1205 | - // open/type |
|
1206 | - $output .= '<input type="radio"'; |
|
1207 | - |
|
1208 | - // class |
|
1209 | - $output .= ' class="form-check-input" '; |
|
1210 | - |
|
1211 | - // name |
|
1212 | - if ( ! empty( $args['name'] ) ) { |
|
1213 | - $output .= AUI_Component_Helper::name( $args['name'] ); |
|
1214 | - } |
|
1215 | - |
|
1216 | - // id |
|
1217 | - if ( ! empty( $args['id'] ) ) { |
|
1218 | - $output .= AUI_Component_Helper::id( $args['id'] . $count ); |
|
1219 | - } |
|
1220 | - |
|
1221 | - // title |
|
1222 | - if ( ! empty( $args['title'] ) ) { |
|
1223 | - $output .= AUI_Component_Helper::title( $args['title'] ); |
|
1224 | - } |
|
1225 | - |
|
1226 | - // value |
|
1227 | - if ( isset( $args['value'] ) ) { |
|
1228 | - $output .= AUI_Component_Helper::value( $args['value'] ); |
|
1229 | - } |
|
1230 | - |
|
1231 | - // checked, for radio and checkboxes |
|
1232 | - if ( $args['checked'] ) { |
|
1233 | - $output .= ' checked '; |
|
1234 | - } |
|
1235 | - |
|
1236 | - // data-attributes |
|
1237 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
1238 | - |
|
1239 | - // aria-attributes |
|
1240 | - $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
1241 | - |
|
1242 | - // extra attributes |
|
1243 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
1244 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
1245 | - } |
|
1246 | - |
|
1247 | - // required |
|
1248 | - if ( ! empty( $args['required'] ) ) { |
|
1249 | - $output .= ' required '; |
|
1250 | - } |
|
1251 | - |
|
1252 | - // close opening tag |
|
1253 | - $output .= ' >'; |
|
1254 | - |
|
1255 | - // label |
|
1256 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
1257 | - } elseif ( ! empty( $args['label'] ) ) { |
|
1258 | - $output .= self::label( array( |
|
1259 | - 'title' => $args['label'], |
|
1260 | - 'for' => $args['id'] . $count, |
|
1261 | - 'class' => 'form-check-label' |
|
1262 | - ), 'radio' ); |
|
1263 | - } |
|
1264 | - |
|
1265 | - // wrap |
|
1266 | - if ( ! $args['no_wrap'] ) { |
|
1267 | - $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check'; |
|
1268 | - |
|
1269 | - // Unique wrap class |
|
1270 | - $uniq_class = 'fwrap'; |
|
1271 | - if ( ! empty( $args['name'] ) ) { |
|
1272 | - $uniq_class .= '-' . $args['name']; |
|
1273 | - } else if ( ! empty( $args['id'] ) ) { |
|
1274 | - $uniq_class .= '-' . $args['id']; |
|
1275 | - } |
|
1276 | - |
|
1277 | - if ( isset( $args['value'] ) || $args['value'] !== "" ) { |
|
1278 | - $uniq_class .= '-' . $args['value']; |
|
1279 | - } else { |
|
1280 | - $uniq_class .= '-' . $count; |
|
1281 | - } |
|
1282 | - $wrap_class .= ' ' . sanitize_html_class( $uniq_class ); |
|
1283 | - |
|
1284 | - $output = self::wrap( array( |
|
1285 | - 'content' => $output, |
|
1286 | - 'class' => $wrap_class |
|
1287 | - ) ); |
|
1288 | - } |
|
1289 | - |
|
1290 | - return $output; |
|
1291 | - } |
|
1050 | + // wrap |
|
1051 | + if ( ! $args['no_wrap'] ) { |
|
1052 | + if ( ! empty( $args['form_group_class'] ) ) { |
|
1053 | + $fg_class = esc_attr( $args['form_group_class'] ); |
|
1054 | + }else{ |
|
1055 | + $fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
1056 | + } |
|
1057 | + $wrap_class = $args['label_type'] == 'horizontal' ? $fg_class . ' row' : $fg_class; |
|
1058 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1059 | + $output = self::wrap( array( |
|
1060 | + 'content' => $output, |
|
1061 | + 'class' => $wrap_class, |
|
1062 | + 'element_require' => $args['element_require'], |
|
1063 | + 'argument_id' => $args['id'], |
|
1064 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
1065 | + ) ); |
|
1066 | + } |
|
1067 | + |
|
1068 | + |
|
1069 | + return $output; |
|
1070 | + } |
|
1071 | + |
|
1072 | + /** |
|
1073 | + * Build the component. |
|
1074 | + * |
|
1075 | + * @param array $args |
|
1076 | + * |
|
1077 | + * @return string The rendered component. |
|
1078 | + */ |
|
1079 | + public static function radio( $args = array() ) { |
|
1080 | + global $aui_bs5; |
|
1081 | + |
|
1082 | + $defaults = array( |
|
1083 | + 'class' => '', |
|
1084 | + 'wrap_class' => '', |
|
1085 | + 'id' => '', |
|
1086 | + 'title' => '', |
|
1087 | + 'horizontal' => false, |
|
1088 | + // sets the lable horizontal |
|
1089 | + 'value' => '', |
|
1090 | + 'label' => '', |
|
1091 | + 'label_class' => '', |
|
1092 | + 'label_type' => '', |
|
1093 | + 'label_col' => '', |
|
1094 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
1095 | + 'help_text' => '', |
|
1096 | + 'inline' => true, |
|
1097 | + 'required' => false, |
|
1098 | + 'options' => array(), |
|
1099 | + 'icon' => '', |
|
1100 | + 'no_wrap' => false, |
|
1101 | + 'element_require' => '', |
|
1102 | + // [%element_id%] == "1" |
|
1103 | + 'extra_attributes' => array(), |
|
1104 | + // an array of extra attributes |
|
1105 | + 'wrap_attributes' => array() |
|
1106 | + ); |
|
1107 | + |
|
1108 | + /** |
|
1109 | + * Parse incoming $args into an array and merge it with $defaults |
|
1110 | + */ |
|
1111 | + $args = wp_parse_args( $args, $defaults ); |
|
1112 | + |
|
1113 | + // for now lets use horizontal for floating |
|
1114 | + if ( $args['label_type'] == 'floating' ) { |
|
1115 | + $args['label_type'] = 'horizontal'; |
|
1116 | + } |
|
1117 | + |
|
1118 | + $label_args = array( |
|
1119 | + 'title' => $args['label'], |
|
1120 | + 'class' => $args['label_class'] . " pt-0 ", |
|
1121 | + 'label_type' => $args['label_type'], |
|
1122 | + 'label_col' => $args['label_col'] |
|
1123 | + ); |
|
1124 | + |
|
1125 | + $output = ''; |
|
1126 | + |
|
1127 | + |
|
1128 | + // label before |
|
1129 | + if ( ! empty( $args['label'] ) ) { |
|
1130 | + $output .= self::label( $label_args, 'radio' ); |
|
1131 | + } |
|
1132 | + |
|
1133 | + // maybe horizontal label |
|
1134 | + if ( $args['label_type'] == 'horizontal' ) { |
|
1135 | + $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
1136 | + $output .= '<div class="' . $input_col . '">'; |
|
1137 | + } |
|
1138 | + |
|
1139 | + if ( ! empty( $args['options'] ) ) { |
|
1140 | + $count = 0; |
|
1141 | + foreach ( $args['options'] as $value => $label ) { |
|
1142 | + $option_args = $args; |
|
1143 | + $option_args['value'] = $value; |
|
1144 | + $option_args['label'] = $label; |
|
1145 | + $option_args['checked'] = $value == $args['value'] ? true : false; |
|
1146 | + $output .= self::radio_option( $option_args, $count ); |
|
1147 | + $count ++; |
|
1148 | + } |
|
1149 | + } |
|
1150 | + |
|
1151 | + // help text |
|
1152 | + $help_text = ! empty( $args['help_text'] ) ? AUI_Component_Helper::help_text( $args['help_text'] ) : ''; |
|
1153 | + $output .= $help_text; |
|
1154 | + |
|
1155 | + // maybe horizontal label |
|
1156 | + if ( $args['label_type'] == 'horizontal' ) { |
|
1157 | + $output .= '</div>'; |
|
1158 | + } |
|
1159 | + |
|
1160 | + // wrap |
|
1161 | + $fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
1162 | + $wrap_class = $args['label_type'] == 'horizontal' ? $fg_class . ' row' : $fg_class; |
|
1163 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1164 | + $output = self::wrap( array( |
|
1165 | + 'content' => $output, |
|
1166 | + 'class' => $wrap_class, |
|
1167 | + 'element_require' => $args['element_require'], |
|
1168 | + 'argument_id' => $args['id'], |
|
1169 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
1170 | + ) ); |
|
1171 | + |
|
1172 | + |
|
1173 | + return $output; |
|
1174 | + } |
|
1175 | + |
|
1176 | + /** |
|
1177 | + * Build the component. |
|
1178 | + * |
|
1179 | + * @param array $args |
|
1180 | + * |
|
1181 | + * @return string The rendered component. |
|
1182 | + */ |
|
1183 | + public static function radio_option( $args = array(), $count = '' ) { |
|
1184 | + $defaults = array( |
|
1185 | + 'class' => '', |
|
1186 | + 'id' => '', |
|
1187 | + 'title' => '', |
|
1188 | + 'value' => '', |
|
1189 | + 'required' => false, |
|
1190 | + 'inline' => true, |
|
1191 | + 'label' => '', |
|
1192 | + 'options' => array(), |
|
1193 | + 'icon' => '', |
|
1194 | + 'no_wrap' => false, |
|
1195 | + 'extra_attributes' => array() // an array of extra attributes |
|
1196 | + ); |
|
1197 | + |
|
1198 | + /** |
|
1199 | + * Parse incoming $args into an array and merge it with $defaults |
|
1200 | + */ |
|
1201 | + $args = wp_parse_args( $args, $defaults ); |
|
1202 | + |
|
1203 | + $output = ''; |
|
1204 | + |
|
1205 | + // open/type |
|
1206 | + $output .= '<input type="radio"'; |
|
1207 | + |
|
1208 | + // class |
|
1209 | + $output .= ' class="form-check-input" '; |
|
1210 | + |
|
1211 | + // name |
|
1212 | + if ( ! empty( $args['name'] ) ) { |
|
1213 | + $output .= AUI_Component_Helper::name( $args['name'] ); |
|
1214 | + } |
|
1215 | + |
|
1216 | + // id |
|
1217 | + if ( ! empty( $args['id'] ) ) { |
|
1218 | + $output .= AUI_Component_Helper::id( $args['id'] . $count ); |
|
1219 | + } |
|
1220 | + |
|
1221 | + // title |
|
1222 | + if ( ! empty( $args['title'] ) ) { |
|
1223 | + $output .= AUI_Component_Helper::title( $args['title'] ); |
|
1224 | + } |
|
1225 | + |
|
1226 | + // value |
|
1227 | + if ( isset( $args['value'] ) ) { |
|
1228 | + $output .= AUI_Component_Helper::value( $args['value'] ); |
|
1229 | + } |
|
1230 | + |
|
1231 | + // checked, for radio and checkboxes |
|
1232 | + if ( $args['checked'] ) { |
|
1233 | + $output .= ' checked '; |
|
1234 | + } |
|
1235 | + |
|
1236 | + // data-attributes |
|
1237 | + $output .= AUI_Component_Helper::data_attributes( $args ); |
|
1238 | + |
|
1239 | + // aria-attributes |
|
1240 | + $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
1241 | + |
|
1242 | + // extra attributes |
|
1243 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
1244 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
1245 | + } |
|
1246 | + |
|
1247 | + // required |
|
1248 | + if ( ! empty( $args['required'] ) ) { |
|
1249 | + $output .= ' required '; |
|
1250 | + } |
|
1251 | + |
|
1252 | + // close opening tag |
|
1253 | + $output .= ' >'; |
|
1254 | + |
|
1255 | + // label |
|
1256 | + if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
1257 | + } elseif ( ! empty( $args['label'] ) ) { |
|
1258 | + $output .= self::label( array( |
|
1259 | + 'title' => $args['label'], |
|
1260 | + 'for' => $args['id'] . $count, |
|
1261 | + 'class' => 'form-check-label' |
|
1262 | + ), 'radio' ); |
|
1263 | + } |
|
1264 | + |
|
1265 | + // wrap |
|
1266 | + if ( ! $args['no_wrap'] ) { |
|
1267 | + $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check'; |
|
1268 | + |
|
1269 | + // Unique wrap class |
|
1270 | + $uniq_class = 'fwrap'; |
|
1271 | + if ( ! empty( $args['name'] ) ) { |
|
1272 | + $uniq_class .= '-' . $args['name']; |
|
1273 | + } else if ( ! empty( $args['id'] ) ) { |
|
1274 | + $uniq_class .= '-' . $args['id']; |
|
1275 | + } |
|
1276 | + |
|
1277 | + if ( isset( $args['value'] ) || $args['value'] !== "" ) { |
|
1278 | + $uniq_class .= '-' . $args['value']; |
|
1279 | + } else { |
|
1280 | + $uniq_class .= '-' . $count; |
|
1281 | + } |
|
1282 | + $wrap_class .= ' ' . sanitize_html_class( $uniq_class ); |
|
1283 | + |
|
1284 | + $output = self::wrap( array( |
|
1285 | + 'content' => $output, |
|
1286 | + 'class' => $wrap_class |
|
1287 | + ) ); |
|
1288 | + } |
|
1289 | + |
|
1290 | + return $output; |
|
1291 | + } |
|
1292 | 1292 | |
1293 | 1293 | } |
1294 | 1294 | \ No newline at end of file |