@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | // Load WP_List_Table if not loaded |
11 | 11 | if ( ! class_exists( 'WP_List_Table' ) ) { |
12 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
12 | + require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
13 | 13 | } |
14 | 14 | |
15 | 15 | /** |
@@ -21,354 +21,354 @@ discard block |
||
21 | 21 | */ |
22 | 22 | class WPInv_Customers_Table extends WP_List_Table { |
23 | 23 | |
24 | - /** |
|
25 | - * @var int Number of items per page |
|
26 | - * @since 1.0.19 |
|
27 | - */ |
|
28 | - public $per_page = 10; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var int Number of items |
|
32 | - * @since 1.0.19 |
|
33 | - */ |
|
34 | - public $total = 0; |
|
35 | - |
|
36 | - /** |
|
37 | - * Get things started |
|
38 | - * |
|
39 | - * @since 1.0.19 |
|
40 | - * @see WP_List_Table::__construct() |
|
41 | - */ |
|
42 | - public function __construct() { |
|
43 | - |
|
44 | - // Set parent defaults |
|
45 | - parent::__construct( array( |
|
46 | - 'singular' => 'id', |
|
47 | - 'plural' => 'ids', |
|
48 | - 'ajax' => false, |
|
49 | - ) ); |
|
50 | - |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * Gets the name of the primary column. |
|
55 | - * |
|
56 | - * @since 1.0.19 |
|
57 | - * @access protected |
|
58 | - * |
|
59 | - * @return string Name of the primary column. |
|
60 | - */ |
|
61 | - protected function get_primary_column_name() { |
|
62 | - return 'name'; |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * This function renders most of the columns in the list table. |
|
67 | - * |
|
68 | - * @since 1.0.19 |
|
69 | - * |
|
70 | - * @param WP_User $item |
|
71 | - * @param string $column_name The name of the column |
|
72 | - * |
|
73 | - * @return string Column Name |
|
74 | - */ |
|
75 | - public function column_default( $item, $column_name ) { |
|
76 | - $value = sanitize_text_field( get_user_meta( $item->ID, '_wpinv_' . $column_name, true ) ); |
|
77 | - return apply_filters( 'wpinv_customers_table_column' . $column_name, $value, $item ); |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Displays the country column. |
|
82 | - * |
|
83 | - * @since 1.0.19 |
|
84 | - * |
|
85 | - * @param WP_User $user |
|
86 | - * |
|
87 | - * @return string Column Name |
|
88 | - */ |
|
89 | - public function column_country( $user ) { |
|
90 | - $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
91 | - if ( $country ) { |
|
92 | - $country = wpinv_country_name( $country ); |
|
93 | - } |
|
94 | - return sanitize_text_field( $country ); |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Displays the state column. |
|
99 | - * |
|
100 | - * @since 1.0.19 |
|
101 | - * |
|
102 | - * @param WP_User $user |
|
103 | - * |
|
104 | - * @return string Column Name |
|
105 | - */ |
|
106 | - public function column_state( $user ) { |
|
107 | - $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
108 | - $state = $user->_wpinv_state; |
|
109 | - if ( $state ) { |
|
110 | - $state = wpinv_state_name( $state, $country ); |
|
111 | - } |
|
112 | - |
|
113 | - return sanitize_text_field( $state ); |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Displays the signup column. |
|
118 | - * |
|
119 | - * @since 1.0.19 |
|
120 | - * |
|
121 | - * @param WP_User $user |
|
122 | - * |
|
123 | - * @return string Column Name |
|
124 | - */ |
|
125 | - public function column_signup( $user ) { |
|
126 | - return getpaid_format_date_value( $user->user_registered ); |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * Displays the total spent column. |
|
131 | - * |
|
132 | - * @since 1.0.19 |
|
133 | - * |
|
134 | - * @param WP_User $user |
|
135 | - * |
|
136 | - * @return string Column Name |
|
137 | - */ |
|
138 | - public function column_total( $user ) { |
|
139 | - |
|
140 | - $args = array( |
|
141 | - 'data' => array( |
|
142 | - |
|
143 | - 'total' => array( |
|
144 | - 'type' => 'invoice_data', |
|
145 | - 'function' => 'SUM', |
|
146 | - 'name' => 'total_sales', |
|
147 | - ) |
|
148 | - |
|
149 | - ), |
|
150 | - 'where' => array( |
|
151 | - |
|
152 | - 'author' => array( |
|
153 | - 'type' => 'post_data', |
|
154 | - 'value' => absint( $user->ID ), |
|
155 | - 'key' => 'posts.post_author', |
|
156 | - 'operator' => '=', |
|
157 | - ), |
|
158 | - |
|
159 | - ), |
|
160 | - 'query_type' => 'get_var', |
|
161 | - 'invoice_status' => array( 'wpi-renewal', 'wpi-processing', 'publish' ), |
|
162 | - ); |
|
163 | - |
|
164 | - return wpinv_price( (float) GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
165 | - |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Displays the total spent column. |
|
170 | - * |
|
171 | - * @since 1.0.19 |
|
172 | - * |
|
173 | - * @param WP_User $user |
|
174 | - * |
|
175 | - * @return string Column Name |
|
176 | - */ |
|
177 | - public function column_invoices( $user ) { |
|
178 | - |
|
179 | - $args = array( |
|
180 | - 'data' => array( |
|
181 | - |
|
182 | - 'ID' => array( |
|
183 | - 'type' => 'post_data', |
|
184 | - 'function' => 'COUNT', |
|
185 | - 'name' => 'count', |
|
186 | - 'distinct' => true, |
|
187 | - ), |
|
188 | - |
|
189 | - ), |
|
190 | - 'where' => array( |
|
191 | - |
|
192 | - 'author' => array( |
|
193 | - 'type' => 'post_data', |
|
194 | - 'value' => absint( $user->ID ), |
|
195 | - 'key' => 'posts.post_author', |
|
196 | - 'operator' => '=', |
|
197 | - ), |
|
198 | - |
|
199 | - ), |
|
200 | - 'query_type' => 'get_var', |
|
201 | - 'invoice_status' => array_keys( wpinv_get_invoice_statuses() ), |
|
202 | - ); |
|
203 | - |
|
204 | - return absint( GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
205 | - |
|
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * Generates content for a single row of the table |
|
210 | - * @since 1.0.19 |
|
211 | - * |
|
212 | - * @param int $item The user id. |
|
213 | - */ |
|
214 | - public function single_row( $item ) { |
|
215 | - $item = get_user_by( 'id', $item ); |
|
216 | - |
|
217 | - if ( empty( $item ) ) { |
|
218 | - return; |
|
219 | - } |
|
220 | - |
|
221 | - echo '<tr>'; |
|
222 | - $this->single_row_columns( $item ); |
|
223 | - echo '</tr>'; |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * Displays the customers name |
|
228 | - * |
|
229 | - * @param WP_User $customer customer. |
|
230 | - * @return string |
|
231 | - */ |
|
232 | - public function column_name( $customer ) { |
|
233 | - |
|
234 | - // Customer view URL. |
|
235 | - $view_url = esc_url( add_query_arg( 'user_id', $customer->ID, admin_url( 'user-edit.php' ) ) ); |
|
236 | - $row_actions = $this->row_actions( |
|
237 | - array( |
|
238 | - 'view' => '<a href="' . $view_url . '#getpaid-fieldset-billing">' . __( 'Edit Details', 'invoicing' ) . '</a>', |
|
239 | - ) |
|
240 | - ); |
|
241 | - |
|
242 | - // Get user's address. |
|
243 | - $address = wpinv_get_user_address( $customer->ID ); |
|
244 | - |
|
245 | - // Customer email address. |
|
246 | - $email = sanitize_email( $customer->user_email ); |
|
247 | - |
|
248 | - // Customer's avatar. |
|
249 | - $avatar = esc_url( get_avatar_url( $email ) ); |
|
250 | - $avatar = "<img src='$avatar' height='32' width='32'/>"; |
|
251 | - |
|
252 | - // Customer's name. |
|
253 | - $name = sanitize_text_field( "{$address['first_name']} {$address['last_name']}" ); |
|
254 | - |
|
255 | - if ( ! empty( $name ) ) { |
|
256 | - $name = "<div style='overflow: hidden;height: 18px;'>$name</div>"; |
|
257 | - } |
|
258 | - |
|
259 | - $email = "<div class='row-title'><a href='$view_url'>$email</a></div>"; |
|
260 | - |
|
261 | - return "<div style='display: flex;'><div>$avatar</div><div style='margin-left: 10px;'>$name<strong>$email</strong>$row_actions</div></div>"; |
|
262 | - |
|
263 | - } |
|
264 | - |
|
265 | - /** |
|
266 | - * Retrieve the table columns |
|
267 | - * |
|
268 | - * @since 1.0.19 |
|
269 | - * @return array $columns Array of all the list table columns |
|
270 | - */ |
|
271 | - public function get_columns() { |
|
272 | - |
|
273 | - $columns = array( |
|
274 | - 'name' => __( 'Name', 'invoicing' ), |
|
275 | - 'country' => __( 'Country', 'invoicing' ), |
|
276 | - 'state' => __( 'State', 'invoicing' ), |
|
277 | - 'city' => __( 'City', 'invoicing' ), |
|
278 | - 'zip' => __( 'ZIP', 'invoicing' ), |
|
279 | - 'address' => __( 'Address', 'invoicing' ), |
|
280 | - 'phone' => __( 'Phone', 'invoicing' ), |
|
281 | - 'company' => __( 'Company', 'invoicing' ), |
|
282 | - 'invoices' => __( 'Invoices', 'invoicing' ), |
|
283 | - 'total' => __( 'Total Spend', 'invoicing' ), |
|
284 | - 'signup' => __( 'Date created', 'invoicing' ), |
|
285 | - ); |
|
286 | - return apply_filters( 'wpinv_customers_table_columns', $columns ); |
|
287 | - |
|
288 | - } |
|
289 | - |
|
290 | - /** |
|
291 | - * Retrieve the current page number |
|
292 | - * |
|
293 | - * @since 1.0.19 |
|
294 | - * @return int Current page number |
|
295 | - */ |
|
296 | - public function get_paged() { |
|
297 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
298 | - } |
|
299 | - |
|
300 | - /** |
|
301 | - * Returns bulk actions. |
|
302 | - * |
|
303 | - * @since 1.0.19 |
|
304 | - * @return void |
|
305 | - */ |
|
306 | - public function bulk_actions( $which = '' ) { |
|
307 | - return array(); |
|
308 | - } |
|
309 | - |
|
310 | - /** |
|
311 | - * Prepares the display query |
|
312 | - */ |
|
313 | - public function prepare_query() { |
|
314 | - global $wpdb; |
|
315 | - |
|
316 | - $post_types = ''; |
|
317 | - |
|
318 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
319 | - $post_types .= $wpdb->prepare( "post_type=%s OR ", $post_type ); |
|
320 | - } |
|
321 | - |
|
322 | - $post_types = rtrim( $post_types, ' OR' ); |
|
323 | - |
|
324 | - // Maybe search. |
|
325 | - if ( ! empty( $_POST['s'] ) ) { |
|
326 | - $users = get_users( |
|
327 | - array( |
|
328 | - 'search' => sanitize_text_field( urldecode( $_POST['s'] ) ), |
|
329 | - 'search_columns' => array( 'user_login', 'user_email', 'display_name' ), |
|
330 | - 'fields' => 'ID', |
|
331 | - ) |
|
332 | - ); |
|
333 | - |
|
334 | - $users = implode( ', ', $users ); |
|
335 | - $post_types = "($post_types) AND ( post_author IN ( $users ) )"; |
|
336 | - } |
|
337 | - |
|
338 | - // Users with invoices. |
|
339 | - $customers = $wpdb->get_col( |
|
340 | - $wpdb->prepare( |
|
341 | - "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types LIMIT %d,%d", |
|
342 | - $this->get_paged() * 10 - 10, |
|
343 | - $this->per_page |
|
344 | - ) |
|
345 | - ); |
|
346 | - |
|
347 | - $this->items = $customers; |
|
348 | - $this->total = (int) $wpdb->get_var( "SELECT COUNT( DISTINCT( post_author ) ) FROM $wpdb->posts WHERE $post_types" ); |
|
349 | - |
|
350 | - } |
|
351 | - |
|
352 | - /** |
|
353 | - * Setup the final data for the table |
|
354 | - * |
|
355 | - * @since 1.0.19 |
|
356 | - * @return void |
|
357 | - */ |
|
358 | - public function prepare_items() { |
|
359 | - $columns = $this->get_columns(); |
|
360 | - $hidden = array(); // No hidden columns |
|
361 | - $sortable = $this->get_sortable_columns(); |
|
362 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
363 | - $this->prepare_query(); |
|
364 | - |
|
365 | - $this->set_pagination_args( |
|
366 | - array( |
|
367 | - 'total_items' => $this->total, |
|
368 | - 'per_page' => $this->per_page, |
|
369 | - 'total_pages' => ceil( $this->total / $this->per_page ) |
|
370 | - ) |
|
371 | - ); |
|
372 | - |
|
373 | - } |
|
24 | + /** |
|
25 | + * @var int Number of items per page |
|
26 | + * @since 1.0.19 |
|
27 | + */ |
|
28 | + public $per_page = 10; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var int Number of items |
|
32 | + * @since 1.0.19 |
|
33 | + */ |
|
34 | + public $total = 0; |
|
35 | + |
|
36 | + /** |
|
37 | + * Get things started |
|
38 | + * |
|
39 | + * @since 1.0.19 |
|
40 | + * @see WP_List_Table::__construct() |
|
41 | + */ |
|
42 | + public function __construct() { |
|
43 | + |
|
44 | + // Set parent defaults |
|
45 | + parent::__construct( array( |
|
46 | + 'singular' => 'id', |
|
47 | + 'plural' => 'ids', |
|
48 | + 'ajax' => false, |
|
49 | + ) ); |
|
50 | + |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * Gets the name of the primary column. |
|
55 | + * |
|
56 | + * @since 1.0.19 |
|
57 | + * @access protected |
|
58 | + * |
|
59 | + * @return string Name of the primary column. |
|
60 | + */ |
|
61 | + protected function get_primary_column_name() { |
|
62 | + return 'name'; |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * This function renders most of the columns in the list table. |
|
67 | + * |
|
68 | + * @since 1.0.19 |
|
69 | + * |
|
70 | + * @param WP_User $item |
|
71 | + * @param string $column_name The name of the column |
|
72 | + * |
|
73 | + * @return string Column Name |
|
74 | + */ |
|
75 | + public function column_default( $item, $column_name ) { |
|
76 | + $value = sanitize_text_field( get_user_meta( $item->ID, '_wpinv_' . $column_name, true ) ); |
|
77 | + return apply_filters( 'wpinv_customers_table_column' . $column_name, $value, $item ); |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Displays the country column. |
|
82 | + * |
|
83 | + * @since 1.0.19 |
|
84 | + * |
|
85 | + * @param WP_User $user |
|
86 | + * |
|
87 | + * @return string Column Name |
|
88 | + */ |
|
89 | + public function column_country( $user ) { |
|
90 | + $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
91 | + if ( $country ) { |
|
92 | + $country = wpinv_country_name( $country ); |
|
93 | + } |
|
94 | + return sanitize_text_field( $country ); |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Displays the state column. |
|
99 | + * |
|
100 | + * @since 1.0.19 |
|
101 | + * |
|
102 | + * @param WP_User $user |
|
103 | + * |
|
104 | + * @return string Column Name |
|
105 | + */ |
|
106 | + public function column_state( $user ) { |
|
107 | + $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
108 | + $state = $user->_wpinv_state; |
|
109 | + if ( $state ) { |
|
110 | + $state = wpinv_state_name( $state, $country ); |
|
111 | + } |
|
112 | + |
|
113 | + return sanitize_text_field( $state ); |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Displays the signup column. |
|
118 | + * |
|
119 | + * @since 1.0.19 |
|
120 | + * |
|
121 | + * @param WP_User $user |
|
122 | + * |
|
123 | + * @return string Column Name |
|
124 | + */ |
|
125 | + public function column_signup( $user ) { |
|
126 | + return getpaid_format_date_value( $user->user_registered ); |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * Displays the total spent column. |
|
131 | + * |
|
132 | + * @since 1.0.19 |
|
133 | + * |
|
134 | + * @param WP_User $user |
|
135 | + * |
|
136 | + * @return string Column Name |
|
137 | + */ |
|
138 | + public function column_total( $user ) { |
|
139 | + |
|
140 | + $args = array( |
|
141 | + 'data' => array( |
|
142 | + |
|
143 | + 'total' => array( |
|
144 | + 'type' => 'invoice_data', |
|
145 | + 'function' => 'SUM', |
|
146 | + 'name' => 'total_sales', |
|
147 | + ) |
|
148 | + |
|
149 | + ), |
|
150 | + 'where' => array( |
|
151 | + |
|
152 | + 'author' => array( |
|
153 | + 'type' => 'post_data', |
|
154 | + 'value' => absint( $user->ID ), |
|
155 | + 'key' => 'posts.post_author', |
|
156 | + 'operator' => '=', |
|
157 | + ), |
|
158 | + |
|
159 | + ), |
|
160 | + 'query_type' => 'get_var', |
|
161 | + 'invoice_status' => array( 'wpi-renewal', 'wpi-processing', 'publish' ), |
|
162 | + ); |
|
163 | + |
|
164 | + return wpinv_price( (float) GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
165 | + |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Displays the total spent column. |
|
170 | + * |
|
171 | + * @since 1.0.19 |
|
172 | + * |
|
173 | + * @param WP_User $user |
|
174 | + * |
|
175 | + * @return string Column Name |
|
176 | + */ |
|
177 | + public function column_invoices( $user ) { |
|
178 | + |
|
179 | + $args = array( |
|
180 | + 'data' => array( |
|
181 | + |
|
182 | + 'ID' => array( |
|
183 | + 'type' => 'post_data', |
|
184 | + 'function' => 'COUNT', |
|
185 | + 'name' => 'count', |
|
186 | + 'distinct' => true, |
|
187 | + ), |
|
188 | + |
|
189 | + ), |
|
190 | + 'where' => array( |
|
191 | + |
|
192 | + 'author' => array( |
|
193 | + 'type' => 'post_data', |
|
194 | + 'value' => absint( $user->ID ), |
|
195 | + 'key' => 'posts.post_author', |
|
196 | + 'operator' => '=', |
|
197 | + ), |
|
198 | + |
|
199 | + ), |
|
200 | + 'query_type' => 'get_var', |
|
201 | + 'invoice_status' => array_keys( wpinv_get_invoice_statuses() ), |
|
202 | + ); |
|
203 | + |
|
204 | + return absint( GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
205 | + |
|
206 | + } |
|
207 | + |
|
208 | + /** |
|
209 | + * Generates content for a single row of the table |
|
210 | + * @since 1.0.19 |
|
211 | + * |
|
212 | + * @param int $item The user id. |
|
213 | + */ |
|
214 | + public function single_row( $item ) { |
|
215 | + $item = get_user_by( 'id', $item ); |
|
216 | + |
|
217 | + if ( empty( $item ) ) { |
|
218 | + return; |
|
219 | + } |
|
220 | + |
|
221 | + echo '<tr>'; |
|
222 | + $this->single_row_columns( $item ); |
|
223 | + echo '</tr>'; |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * Displays the customers name |
|
228 | + * |
|
229 | + * @param WP_User $customer customer. |
|
230 | + * @return string |
|
231 | + */ |
|
232 | + public function column_name( $customer ) { |
|
233 | + |
|
234 | + // Customer view URL. |
|
235 | + $view_url = esc_url( add_query_arg( 'user_id', $customer->ID, admin_url( 'user-edit.php' ) ) ); |
|
236 | + $row_actions = $this->row_actions( |
|
237 | + array( |
|
238 | + 'view' => '<a href="' . $view_url . '#getpaid-fieldset-billing">' . __( 'Edit Details', 'invoicing' ) . '</a>', |
|
239 | + ) |
|
240 | + ); |
|
241 | + |
|
242 | + // Get user's address. |
|
243 | + $address = wpinv_get_user_address( $customer->ID ); |
|
244 | + |
|
245 | + // Customer email address. |
|
246 | + $email = sanitize_email( $customer->user_email ); |
|
247 | + |
|
248 | + // Customer's avatar. |
|
249 | + $avatar = esc_url( get_avatar_url( $email ) ); |
|
250 | + $avatar = "<img src='$avatar' height='32' width='32'/>"; |
|
251 | + |
|
252 | + // Customer's name. |
|
253 | + $name = sanitize_text_field( "{$address['first_name']} {$address['last_name']}" ); |
|
254 | + |
|
255 | + if ( ! empty( $name ) ) { |
|
256 | + $name = "<div style='overflow: hidden;height: 18px;'>$name</div>"; |
|
257 | + } |
|
258 | + |
|
259 | + $email = "<div class='row-title'><a href='$view_url'>$email</a></div>"; |
|
260 | + |
|
261 | + return "<div style='display: flex;'><div>$avatar</div><div style='margin-left: 10px;'>$name<strong>$email</strong>$row_actions</div></div>"; |
|
262 | + |
|
263 | + } |
|
264 | + |
|
265 | + /** |
|
266 | + * Retrieve the table columns |
|
267 | + * |
|
268 | + * @since 1.0.19 |
|
269 | + * @return array $columns Array of all the list table columns |
|
270 | + */ |
|
271 | + public function get_columns() { |
|
272 | + |
|
273 | + $columns = array( |
|
274 | + 'name' => __( 'Name', 'invoicing' ), |
|
275 | + 'country' => __( 'Country', 'invoicing' ), |
|
276 | + 'state' => __( 'State', 'invoicing' ), |
|
277 | + 'city' => __( 'City', 'invoicing' ), |
|
278 | + 'zip' => __( 'ZIP', 'invoicing' ), |
|
279 | + 'address' => __( 'Address', 'invoicing' ), |
|
280 | + 'phone' => __( 'Phone', 'invoicing' ), |
|
281 | + 'company' => __( 'Company', 'invoicing' ), |
|
282 | + 'invoices' => __( 'Invoices', 'invoicing' ), |
|
283 | + 'total' => __( 'Total Spend', 'invoicing' ), |
|
284 | + 'signup' => __( 'Date created', 'invoicing' ), |
|
285 | + ); |
|
286 | + return apply_filters( 'wpinv_customers_table_columns', $columns ); |
|
287 | + |
|
288 | + } |
|
289 | + |
|
290 | + /** |
|
291 | + * Retrieve the current page number |
|
292 | + * |
|
293 | + * @since 1.0.19 |
|
294 | + * @return int Current page number |
|
295 | + */ |
|
296 | + public function get_paged() { |
|
297 | + return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
298 | + } |
|
299 | + |
|
300 | + /** |
|
301 | + * Returns bulk actions. |
|
302 | + * |
|
303 | + * @since 1.0.19 |
|
304 | + * @return void |
|
305 | + */ |
|
306 | + public function bulk_actions( $which = '' ) { |
|
307 | + return array(); |
|
308 | + } |
|
309 | + |
|
310 | + /** |
|
311 | + * Prepares the display query |
|
312 | + */ |
|
313 | + public function prepare_query() { |
|
314 | + global $wpdb; |
|
315 | + |
|
316 | + $post_types = ''; |
|
317 | + |
|
318 | + foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
319 | + $post_types .= $wpdb->prepare( "post_type=%s OR ", $post_type ); |
|
320 | + } |
|
321 | + |
|
322 | + $post_types = rtrim( $post_types, ' OR' ); |
|
323 | + |
|
324 | + // Maybe search. |
|
325 | + if ( ! empty( $_POST['s'] ) ) { |
|
326 | + $users = get_users( |
|
327 | + array( |
|
328 | + 'search' => sanitize_text_field( urldecode( $_POST['s'] ) ), |
|
329 | + 'search_columns' => array( 'user_login', 'user_email', 'display_name' ), |
|
330 | + 'fields' => 'ID', |
|
331 | + ) |
|
332 | + ); |
|
333 | + |
|
334 | + $users = implode( ', ', $users ); |
|
335 | + $post_types = "($post_types) AND ( post_author IN ( $users ) )"; |
|
336 | + } |
|
337 | + |
|
338 | + // Users with invoices. |
|
339 | + $customers = $wpdb->get_col( |
|
340 | + $wpdb->prepare( |
|
341 | + "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types LIMIT %d,%d", |
|
342 | + $this->get_paged() * 10 - 10, |
|
343 | + $this->per_page |
|
344 | + ) |
|
345 | + ); |
|
346 | + |
|
347 | + $this->items = $customers; |
|
348 | + $this->total = (int) $wpdb->get_var( "SELECT COUNT( DISTINCT( post_author ) ) FROM $wpdb->posts WHERE $post_types" ); |
|
349 | + |
|
350 | + } |
|
351 | + |
|
352 | + /** |
|
353 | + * Setup the final data for the table |
|
354 | + * |
|
355 | + * @since 1.0.19 |
|
356 | + * @return void |
|
357 | + */ |
|
358 | + public function prepare_items() { |
|
359 | + $columns = $this->get_columns(); |
|
360 | + $hidden = array(); // No hidden columns |
|
361 | + $sortable = $this->get_sortable_columns(); |
|
362 | + $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
363 | + $this->prepare_query(); |
|
364 | + |
|
365 | + $this->set_pagination_args( |
|
366 | + array( |
|
367 | + 'total_items' => $this->total, |
|
368 | + 'per_page' => $this->per_page, |
|
369 | + 'total_pages' => ceil( $this->total / $this->per_page ) |
|
370 | + ) |
|
371 | + ); |
|
372 | + |
|
373 | + } |
|
374 | 374 | } |
@@ -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,187 +10,187 @@ discard block |
||
10 | 10 | class GetPaid_Payment_Form_Submission { |
11 | 11 | |
12 | 12 | /** |
13 | - * Submission ID |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - public $id = null; |
|
18 | - |
|
19 | - /** |
|
20 | - * The raw submission data. |
|
21 | - * |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $data = null; |
|
25 | - |
|
26 | - /** |
|
27 | - * Submission totals |
|
28 | - * |
|
29 | - * @var array |
|
30 | - */ |
|
31 | - protected $totals = array( |
|
32 | - |
|
33 | - 'subtotal' => array( |
|
34 | - 'initial' => 0, |
|
35 | - 'recurring' => 0, |
|
36 | - ), |
|
37 | - |
|
38 | - 'discount' => array( |
|
39 | - 'initial' => 0, |
|
40 | - 'recurring' => 0, |
|
41 | - ), |
|
42 | - |
|
43 | - 'fees' => array( |
|
44 | - 'initial' => 0, |
|
45 | - 'recurring' => 0, |
|
46 | - ), |
|
47 | - |
|
48 | - 'taxes' => array( |
|
49 | - 'initial' => 0, |
|
50 | - 'recurring' => 0, |
|
51 | - ), |
|
52 | - |
|
53 | - ); |
|
54 | - |
|
55 | - /** |
|
56 | - * Sets the associated payment form. |
|
57 | - * |
|
58 | - * @var GetPaid_Payment_Form |
|
59 | - */ |
|
13 | + * Submission ID |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + public $id = null; |
|
18 | + |
|
19 | + /** |
|
20 | + * The raw submission data. |
|
21 | + * |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $data = null; |
|
25 | + |
|
26 | + /** |
|
27 | + * Submission totals |
|
28 | + * |
|
29 | + * @var array |
|
30 | + */ |
|
31 | + protected $totals = array( |
|
32 | + |
|
33 | + 'subtotal' => array( |
|
34 | + 'initial' => 0, |
|
35 | + 'recurring' => 0, |
|
36 | + ), |
|
37 | + |
|
38 | + 'discount' => array( |
|
39 | + 'initial' => 0, |
|
40 | + 'recurring' => 0, |
|
41 | + ), |
|
42 | + |
|
43 | + 'fees' => array( |
|
44 | + 'initial' => 0, |
|
45 | + 'recurring' => 0, |
|
46 | + ), |
|
47 | + |
|
48 | + 'taxes' => array( |
|
49 | + 'initial' => 0, |
|
50 | + 'recurring' => 0, |
|
51 | + ), |
|
52 | + |
|
53 | + ); |
|
54 | + |
|
55 | + /** |
|
56 | + * Sets the associated payment form. |
|
57 | + * |
|
58 | + * @var GetPaid_Payment_Form |
|
59 | + */ |
|
60 | 60 | protected $payment_form = null; |
61 | 61 | |
62 | 62 | /** |
63 | - * The country for the submission. |
|
64 | - * |
|
65 | - * @var string |
|
66 | - */ |
|
67 | - public $country = null; |
|
68 | - |
|
69 | - /** |
|
70 | - * The state for the submission. |
|
71 | - * |
|
72 | - * @since 1.0.19 |
|
73 | - * @var string |
|
74 | - */ |
|
75 | - public $state = null; |
|
76 | - |
|
77 | - /** |
|
78 | - * The invoice associated with the submission. |
|
79 | - * |
|
80 | - * @var WPInv_Invoice |
|
81 | - */ |
|
82 | - protected $invoice = null; |
|
83 | - |
|
84 | - /** |
|
85 | - * The recurring item for the submission. |
|
86 | - * |
|
87 | - * @var int |
|
88 | - */ |
|
89 | - public $has_recurring = 0; |
|
90 | - |
|
91 | - /** |
|
92 | - * An array of fees for the submission. |
|
93 | - * |
|
94 | - * @var array |
|
95 | - */ |
|
96 | - protected $fees = array(); |
|
97 | - |
|
98 | - /** |
|
99 | - * An array of discounts for the submission. |
|
100 | - * |
|
101 | - * @var array |
|
102 | - */ |
|
103 | - protected $discounts = array(); |
|
104 | - |
|
105 | - /** |
|
106 | - * An array of taxes for the submission. |
|
107 | - * |
|
108 | - * @var array |
|
109 | - */ |
|
110 | - protected $taxes = array(); |
|
111 | - |
|
112 | - /** |
|
113 | - * An array of items for the submission. |
|
114 | - * |
|
115 | - * @var GetPaid_Form_Item[] |
|
116 | - */ |
|
117 | - protected $items = array(); |
|
118 | - |
|
119 | - /** |
|
120 | - * The last error. |
|
121 | - * |
|
122 | - * @var string |
|
123 | - */ |
|
124 | - public $last_error = null; |
|
125 | - |
|
126 | - /** |
|
127 | - * Class constructor. |
|
128 | - * |
|
129 | - */ |
|
130 | - public function __construct() { |
|
131 | - |
|
132 | - // Set the state and country to the default state and country. |
|
133 | - $this->country = wpinv_default_billing_country(); |
|
134 | - $this->state = wpinv_get_default_state(); |
|
135 | - |
|
136 | - // Do we have an actual submission? |
|
137 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
138 | - $this->load_data( $_POST ); |
|
139 | - } |
|
140 | - |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Loads submission data. |
|
145 | - * |
|
146 | - * @param array $data |
|
147 | - */ |
|
148 | - public function load_data( $data ) { |
|
149 | - |
|
150 | - // Remove slashes from the submitted data... |
|
151 | - $data = wp_unslash( $data ); |
|
152 | - |
|
153 | - // Allow plugins to filter the data. |
|
154 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
155 | - |
|
156 | - // Cache it... |
|
157 | - $this->data = $data; |
|
158 | - |
|
159 | - // Then generate a unique id from the data. |
|
160 | - $this->id = md5( wp_json_encode( $data ) ); |
|
161 | - |
|
162 | - // Finally, process the submission. |
|
163 | - try { |
|
164 | - |
|
165 | - // Each process is passed an instance of the class (with reference) |
|
166 | - // and should throw an Exception whenever it encounters one. |
|
167 | - $processors = apply_filters( |
|
168 | - 'getpaid_payment_form_submission_processors', |
|
169 | - array( |
|
170 | - array( $this, 'process_payment_form' ), |
|
171 | - array( $this, 'process_invoice' ), |
|
172 | - array( $this, 'process_fees' ), |
|
173 | - array( $this, 'process_items' ), |
|
174 | - array( $this, 'process_discount' ), |
|
175 | - array( $this, 'process_taxes' ), |
|
176 | - ), |
|
177 | - $this |
|
178 | - ); |
|
179 | - |
|
180 | - foreach ( $processors as $processor ) { |
|
181 | - call_user_func_array( $processor, array( &$this ) ); |
|
182 | - } |
|
183 | - |
|
184 | - } catch ( Exception $e ) { |
|
185 | - $this->last_error = $e->getMessage(); |
|
186 | - } |
|
187 | - |
|
188 | - // Fired when we are done processing a submission. |
|
189 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
190 | - |
|
191 | - } |
|
192 | - |
|
193 | - /* |
|
63 | + * The country for the submission. |
|
64 | + * |
|
65 | + * @var string |
|
66 | + */ |
|
67 | + public $country = null; |
|
68 | + |
|
69 | + /** |
|
70 | + * The state for the submission. |
|
71 | + * |
|
72 | + * @since 1.0.19 |
|
73 | + * @var string |
|
74 | + */ |
|
75 | + public $state = null; |
|
76 | + |
|
77 | + /** |
|
78 | + * The invoice associated with the submission. |
|
79 | + * |
|
80 | + * @var WPInv_Invoice |
|
81 | + */ |
|
82 | + protected $invoice = null; |
|
83 | + |
|
84 | + /** |
|
85 | + * The recurring item for the submission. |
|
86 | + * |
|
87 | + * @var int |
|
88 | + */ |
|
89 | + public $has_recurring = 0; |
|
90 | + |
|
91 | + /** |
|
92 | + * An array of fees for the submission. |
|
93 | + * |
|
94 | + * @var array |
|
95 | + */ |
|
96 | + protected $fees = array(); |
|
97 | + |
|
98 | + /** |
|
99 | + * An array of discounts for the submission. |
|
100 | + * |
|
101 | + * @var array |
|
102 | + */ |
|
103 | + protected $discounts = array(); |
|
104 | + |
|
105 | + /** |
|
106 | + * An array of taxes for the submission. |
|
107 | + * |
|
108 | + * @var array |
|
109 | + */ |
|
110 | + protected $taxes = array(); |
|
111 | + |
|
112 | + /** |
|
113 | + * An array of items for the submission. |
|
114 | + * |
|
115 | + * @var GetPaid_Form_Item[] |
|
116 | + */ |
|
117 | + protected $items = array(); |
|
118 | + |
|
119 | + /** |
|
120 | + * The last error. |
|
121 | + * |
|
122 | + * @var string |
|
123 | + */ |
|
124 | + public $last_error = null; |
|
125 | + |
|
126 | + /** |
|
127 | + * Class constructor. |
|
128 | + * |
|
129 | + */ |
|
130 | + public function __construct() { |
|
131 | + |
|
132 | + // Set the state and country to the default state and country. |
|
133 | + $this->country = wpinv_default_billing_country(); |
|
134 | + $this->state = wpinv_get_default_state(); |
|
135 | + |
|
136 | + // Do we have an actual submission? |
|
137 | + if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
138 | + $this->load_data( $_POST ); |
|
139 | + } |
|
140 | + |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Loads submission data. |
|
145 | + * |
|
146 | + * @param array $data |
|
147 | + */ |
|
148 | + public function load_data( $data ) { |
|
149 | + |
|
150 | + // Remove slashes from the submitted data... |
|
151 | + $data = wp_unslash( $data ); |
|
152 | + |
|
153 | + // Allow plugins to filter the data. |
|
154 | + $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
155 | + |
|
156 | + // Cache it... |
|
157 | + $this->data = $data; |
|
158 | + |
|
159 | + // Then generate a unique id from the data. |
|
160 | + $this->id = md5( wp_json_encode( $data ) ); |
|
161 | + |
|
162 | + // Finally, process the submission. |
|
163 | + try { |
|
164 | + |
|
165 | + // Each process is passed an instance of the class (with reference) |
|
166 | + // and should throw an Exception whenever it encounters one. |
|
167 | + $processors = apply_filters( |
|
168 | + 'getpaid_payment_form_submission_processors', |
|
169 | + array( |
|
170 | + array( $this, 'process_payment_form' ), |
|
171 | + array( $this, 'process_invoice' ), |
|
172 | + array( $this, 'process_fees' ), |
|
173 | + array( $this, 'process_items' ), |
|
174 | + array( $this, 'process_discount' ), |
|
175 | + array( $this, 'process_taxes' ), |
|
176 | + ), |
|
177 | + $this |
|
178 | + ); |
|
179 | + |
|
180 | + foreach ( $processors as $processor ) { |
|
181 | + call_user_func_array( $processor, array( &$this ) ); |
|
182 | + } |
|
183 | + |
|
184 | + } catch ( Exception $e ) { |
|
185 | + $this->last_error = $e->getMessage(); |
|
186 | + } |
|
187 | + |
|
188 | + // Fired when we are done processing a submission. |
|
189 | + do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
190 | + |
|
191 | + } |
|
192 | + |
|
193 | + /* |
|
194 | 194 | |-------------------------------------------------------------------------- |
195 | 195 | | Payment Forms. |
196 | 196 | |-------------------------------------------------------------------------- |
@@ -199,39 +199,39 @@ discard block |
||
199 | 199 | | submission has an active payment form etc. |
200 | 200 | */ |
201 | 201 | |
202 | - /** |
|
203 | - * Prepares the submission's payment form. |
|
204 | - * |
|
205 | - * @since 1.0.19 |
|
206 | - */ |
|
207 | - public function process_payment_form() { |
|
202 | + /** |
|
203 | + * Prepares the submission's payment form. |
|
204 | + * |
|
205 | + * @since 1.0.19 |
|
206 | + */ |
|
207 | + public function process_payment_form() { |
|
208 | 208 | |
209 | - // Every submission needs an active payment form. |
|
210 | - if ( empty( $this->data['form_id'] ) ) { |
|
211 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
212 | - } |
|
209 | + // Every submission needs an active payment form. |
|
210 | + if ( empty( $this->data['form_id'] ) ) { |
|
211 | + throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
212 | + } |
|
213 | 213 | |
214 | - // Fetch the payment form. |
|
215 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
214 | + // Fetch the payment form. |
|
215 | + $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
216 | 216 | |
217 | - if ( ! $this->payment_form->is_active() ) { |
|
218 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
219 | - } |
|
217 | + if ( ! $this->payment_form->is_active() ) { |
|
218 | + throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
219 | + } |
|
220 | 220 | |
221 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
222 | - } |
|
221 | + do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
222 | + } |
|
223 | 223 | |
224 | 224 | /** |
225 | - * Returns the payment form. |
|
226 | - * |
|
227 | - * @since 1.0.19 |
|
228 | - * @return GetPaid_Payment_Form |
|
229 | - */ |
|
230 | - public function get_payment_form() { |
|
231 | - return $this->payment_form; |
|
232 | - } |
|
225 | + * Returns the payment form. |
|
226 | + * |
|
227 | + * @since 1.0.19 |
|
228 | + * @return GetPaid_Payment_Form |
|
229 | + */ |
|
230 | + public function get_payment_form() { |
|
231 | + return $this->payment_form; |
|
232 | + } |
|
233 | 233 | |
234 | - /* |
|
234 | + /* |
|
235 | 235 | |-------------------------------------------------------------------------- |
236 | 236 | | Invoices. |
237 | 237 | |-------------------------------------------------------------------------- |
@@ -240,61 +240,61 @@ discard block |
||
240 | 240 | | might be for an existing invoice. |
241 | 241 | */ |
242 | 242 | |
243 | - /** |
|
244 | - * Prepares the submission's invoice. |
|
245 | - * |
|
246 | - * @since 1.0.19 |
|
247 | - */ |
|
248 | - public function process_invoice() { |
|
243 | + /** |
|
244 | + * Prepares the submission's invoice. |
|
245 | + * |
|
246 | + * @since 1.0.19 |
|
247 | + */ |
|
248 | + public function process_invoice() { |
|
249 | 249 | |
250 | - // Abort if there is no invoice. |
|
251 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
252 | - return; |
|
253 | - } |
|
250 | + // Abort if there is no invoice. |
|
251 | + if ( empty( $this->data['invoice_id'] ) ) { |
|
252 | + return; |
|
253 | + } |
|
254 | 254 | |
255 | - // If the submission is for an existing invoice, ensure that it exists |
|
256 | - // and that it is not paid for. |
|
257 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
255 | + // If the submission is for an existing invoice, ensure that it exists |
|
256 | + // and that it is not paid for. |
|
257 | + $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
258 | 258 | |
259 | 259 | if ( empty( $invoice ) ) { |
260 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
261 | - } |
|
262 | - |
|
263 | - if ( $invoice->is_paid() ) { |
|
264 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
265 | - } |
|
266 | - |
|
267 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
268 | - $this->payment_form->invoice = $invoice; |
|
269 | - |
|
270 | - $this->country = $invoice->get_country(); |
|
271 | - $this->state = $invoice->get_state(); |
|
272 | - $this->invoice = $invoice; |
|
273 | - |
|
274 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
275 | - } |
|
276 | - |
|
277 | - /** |
|
278 | - * Returns the associated invoice. |
|
279 | - * |
|
280 | - * @since 1.0.19 |
|
281 | - * @return WPInv_Invoice |
|
282 | - */ |
|
283 | - public function get_invoice() { |
|
284 | - return $this->invoice; |
|
285 | - } |
|
286 | - |
|
287 | - /** |
|
288 | - * Checks whether there is an invoice associated with this submission. |
|
289 | - * |
|
290 | - * @since 1.0.19 |
|
291 | - * @return bool |
|
292 | - */ |
|
293 | - public function has_invoice() { |
|
294 | - return ! empty( $this->invoice ); |
|
295 | - } |
|
296 | - |
|
297 | - /* |
|
260 | + throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
261 | + } |
|
262 | + |
|
263 | + if ( $invoice->is_paid() ) { |
|
264 | + throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
265 | + } |
|
266 | + |
|
267 | + $this->payment_form->set_items( $invoice->get_items() ); |
|
268 | + $this->payment_form->invoice = $invoice; |
|
269 | + |
|
270 | + $this->country = $invoice->get_country(); |
|
271 | + $this->state = $invoice->get_state(); |
|
272 | + $this->invoice = $invoice; |
|
273 | + |
|
274 | + do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
275 | + } |
|
276 | + |
|
277 | + /** |
|
278 | + * Returns the associated invoice. |
|
279 | + * |
|
280 | + * @since 1.0.19 |
|
281 | + * @return WPInv_Invoice |
|
282 | + */ |
|
283 | + public function get_invoice() { |
|
284 | + return $this->invoice; |
|
285 | + } |
|
286 | + |
|
287 | + /** |
|
288 | + * Checks whether there is an invoice associated with this submission. |
|
289 | + * |
|
290 | + * @since 1.0.19 |
|
291 | + * @return bool |
|
292 | + */ |
|
293 | + public function has_invoice() { |
|
294 | + return ! empty( $this->invoice ); |
|
295 | + } |
|
296 | + |
|
297 | + /* |
|
298 | 298 | |-------------------------------------------------------------------------- |
299 | 299 | | Items. |
300 | 300 | |-------------------------------------------------------------------------- |
@@ -303,115 +303,115 @@ discard block |
||
303 | 303 | | recurring item. But can have an unlimited number of non-recurring items. |
304 | 304 | */ |
305 | 305 | |
306 | - /** |
|
307 | - * Prepares the submission's items. |
|
308 | - * |
|
309 | - * @since 1.0.19 |
|
310 | - */ |
|
311 | - public function process_items() { |
|
312 | - |
|
313 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
314 | - |
|
315 | - foreach ( $processor->items as $item ) { |
|
316 | - $this->add_item( $item ); |
|
317 | - } |
|
318 | - |
|
319 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
320 | - } |
|
321 | - |
|
322 | - /** |
|
323 | - * Adds an item to the submission. |
|
324 | - * |
|
325 | - * @since 1.0.19 |
|
326 | - * @param GetPaid_Form_Item $item |
|
327 | - */ |
|
328 | - public function add_item( $item ) { |
|
329 | - |
|
330 | - // Make sure that it is available for purchase. |
|
331 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
332 | - return; |
|
333 | - } |
|
334 | - |
|
335 | - // Each submission can only contain one recurring item. |
|
336 | - if ( $item->is_recurring() ) { |
|
337 | - |
|
338 | - if ( $this->has_recurring != 0 ) { |
|
339 | - throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) ); |
|
340 | - } |
|
341 | - |
|
342 | - $this->has_recurring = $item->get_id(); |
|
343 | - |
|
344 | - } |
|
345 | - |
|
346 | - // Update the items and totals. |
|
347 | - $this->items[ $item->get_id() ] = $item; |
|
348 | - $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
349 | - $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
350 | - |
|
351 | - } |
|
352 | - |
|
353 | - /** |
|
354 | - * Removes a specific item. |
|
355 | - * |
|
356 | - * You should not call this method after the discounts and taxes |
|
357 | - * have been calculated. |
|
358 | - * |
|
359 | - * @since 1.0.19 |
|
360 | - */ |
|
361 | - public function remove_item( $item_id ) { |
|
362 | - |
|
363 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
364 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
365 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
366 | - |
|
367 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
368 | - $this->has_recurring = 0; |
|
369 | - } |
|
370 | - |
|
371 | - unset( $this->items[ $item_id ] ); |
|
372 | - } |
|
373 | - |
|
374 | - } |
|
375 | - |
|
376 | - /** |
|
377 | - * Returns the subtotal. |
|
378 | - * |
|
379 | - * @since 1.0.19 |
|
380 | - */ |
|
381 | - public function get_subtotal() { |
|
382 | - |
|
383 | - if ( wpinv_prices_include_tax() ) { |
|
384 | - return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
385 | - } |
|
386 | - |
|
387 | - return $this->totals['subtotal']['initial']; |
|
388 | - } |
|
389 | - |
|
390 | - /** |
|
391 | - * Returns the recurring subtotal. |
|
392 | - * |
|
393 | - * @since 1.0.19 |
|
394 | - */ |
|
395 | - public function get_recurring_subtotal() { |
|
396 | - |
|
397 | - if ( wpinv_prices_include_tax() ) { |
|
398 | - return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
399 | - } |
|
400 | - |
|
401 | - return $this->totals['subtotal']['recurring']; |
|
402 | - } |
|
403 | - |
|
404 | - /** |
|
405 | - * Returns all items. |
|
406 | - * |
|
407 | - * @since 1.0.19 |
|
408 | - * @return GetPaid_Form_Item[] |
|
409 | - */ |
|
410 | - public function get_items() { |
|
411 | - return $this->items; |
|
412 | - } |
|
413 | - |
|
414 | - /* |
|
306 | + /** |
|
307 | + * Prepares the submission's items. |
|
308 | + * |
|
309 | + * @since 1.0.19 |
|
310 | + */ |
|
311 | + public function process_items() { |
|
312 | + |
|
313 | + $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
314 | + |
|
315 | + foreach ( $processor->items as $item ) { |
|
316 | + $this->add_item( $item ); |
|
317 | + } |
|
318 | + |
|
319 | + do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
320 | + } |
|
321 | + |
|
322 | + /** |
|
323 | + * Adds an item to the submission. |
|
324 | + * |
|
325 | + * @since 1.0.19 |
|
326 | + * @param GetPaid_Form_Item $item |
|
327 | + */ |
|
328 | + public function add_item( $item ) { |
|
329 | + |
|
330 | + // Make sure that it is available for purchase. |
|
331 | + if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
332 | + return; |
|
333 | + } |
|
334 | + |
|
335 | + // Each submission can only contain one recurring item. |
|
336 | + if ( $item->is_recurring() ) { |
|
337 | + |
|
338 | + if ( $this->has_recurring != 0 ) { |
|
339 | + throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) ); |
|
340 | + } |
|
341 | + |
|
342 | + $this->has_recurring = $item->get_id(); |
|
343 | + |
|
344 | + } |
|
345 | + |
|
346 | + // Update the items and totals. |
|
347 | + $this->items[ $item->get_id() ] = $item; |
|
348 | + $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
349 | + $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
350 | + |
|
351 | + } |
|
352 | + |
|
353 | + /** |
|
354 | + * Removes a specific item. |
|
355 | + * |
|
356 | + * You should not call this method after the discounts and taxes |
|
357 | + * have been calculated. |
|
358 | + * |
|
359 | + * @since 1.0.19 |
|
360 | + */ |
|
361 | + public function remove_item( $item_id ) { |
|
362 | + |
|
363 | + if ( isset( $this->items[ $item_id ] ) ) { |
|
364 | + $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
365 | + $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
366 | + |
|
367 | + if ( $this->items[ $item_id ]->is_recurring() ) { |
|
368 | + $this->has_recurring = 0; |
|
369 | + } |
|
370 | + |
|
371 | + unset( $this->items[ $item_id ] ); |
|
372 | + } |
|
373 | + |
|
374 | + } |
|
375 | + |
|
376 | + /** |
|
377 | + * Returns the subtotal. |
|
378 | + * |
|
379 | + * @since 1.0.19 |
|
380 | + */ |
|
381 | + public function get_subtotal() { |
|
382 | + |
|
383 | + if ( wpinv_prices_include_tax() ) { |
|
384 | + return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
385 | + } |
|
386 | + |
|
387 | + return $this->totals['subtotal']['initial']; |
|
388 | + } |
|
389 | + |
|
390 | + /** |
|
391 | + * Returns the recurring subtotal. |
|
392 | + * |
|
393 | + * @since 1.0.19 |
|
394 | + */ |
|
395 | + public function get_recurring_subtotal() { |
|
396 | + |
|
397 | + if ( wpinv_prices_include_tax() ) { |
|
398 | + return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
399 | + } |
|
400 | + |
|
401 | + return $this->totals['subtotal']['recurring']; |
|
402 | + } |
|
403 | + |
|
404 | + /** |
|
405 | + * Returns all items. |
|
406 | + * |
|
407 | + * @since 1.0.19 |
|
408 | + * @return GetPaid_Form_Item[] |
|
409 | + */ |
|
410 | + public function get_items() { |
|
411 | + return $this->items; |
|
412 | + } |
|
413 | + |
|
414 | + /* |
|
415 | 415 | |-------------------------------------------------------------------------- |
416 | 416 | | Taxes |
417 | 417 | |-------------------------------------------------------------------------- |
@@ -420,128 +420,128 @@ discard block |
||
420 | 420 | | or only one-time. |
421 | 421 | */ |
422 | 422 | |
423 | - /** |
|
424 | - * Prepares the submission's taxes. |
|
425 | - * |
|
426 | - * @since 1.0.19 |
|
427 | - */ |
|
428 | - public function process_taxes() { |
|
429 | - |
|
430 | - // Abort if we're not using taxes. |
|
431 | - if ( ! $this->use_taxes() ) { |
|
432 | - return; |
|
433 | - } |
|
434 | - |
|
435 | - // If a custom country && state has been passed in, use it to calculate taxes. |
|
436 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
437 | - if ( ! empty( $country ) ) { |
|
438 | - $this->country = $country; |
|
439 | - } |
|
440 | - |
|
441 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
442 | - if ( ! empty( $state ) ) { |
|
443 | - $this->state = $state; |
|
444 | - } |
|
445 | - |
|
446 | - // Confirm if the provided country and the ip country are similar. |
|
447 | - $address_confirmed = $this->get_field( 'confirm-address' ); |
|
448 | - if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
449 | - throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
450 | - } |
|
451 | - |
|
452 | - // Abort if the country is not taxable. |
|
453 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
454 | - return; |
|
455 | - } |
|
456 | - |
|
457 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
458 | - |
|
459 | - foreach ( $processor->taxes as $tax ) { |
|
460 | - $this->add_tax( $tax ); |
|
461 | - } |
|
462 | - |
|
463 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
464 | - } |
|
465 | - |
|
466 | - /** |
|
467 | - * Adds a tax to the submission. |
|
468 | - * |
|
469 | - * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
470 | - * @since 1.0.19 |
|
471 | - */ |
|
472 | - public function add_tax( $tax ) { |
|
473 | - |
|
474 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
475 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
476 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
477 | - } |
|
478 | - |
|
479 | - $this->taxes[ $tax['name'] ] = $tax; |
|
480 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
481 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
482 | - |
|
483 | - } |
|
484 | - |
|
485 | - /** |
|
486 | - * Removes a specific tax. |
|
487 | - * |
|
488 | - * @since 1.0.19 |
|
489 | - */ |
|
490 | - public function remove_tax( $tax_name ) { |
|
491 | - |
|
492 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
493 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
494 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
495 | - unset( $this->taxes[ $tax_name ] ); |
|
496 | - } |
|
497 | - |
|
498 | - } |
|
499 | - |
|
500 | - /** |
|
501 | - * Whether or not we'll use taxes for the submission. |
|
502 | - * |
|
503 | - * @since 1.0.19 |
|
504 | - */ |
|
505 | - public function use_taxes() { |
|
506 | - |
|
507 | - $use_taxes = wpinv_use_taxes(); |
|
508 | - |
|
509 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
510 | - $use_taxes = false; |
|
511 | - } |
|
512 | - |
|
513 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
514 | - |
|
515 | - } |
|
516 | - |
|
517 | - /** |
|
518 | - * Returns the tax. |
|
519 | - * |
|
520 | - * @since 1.0.19 |
|
521 | - */ |
|
522 | - public function get_tax() { |
|
523 | - return $this->totals['taxes']['initial']; |
|
524 | - } |
|
525 | - |
|
526 | - /** |
|
527 | - * Returns the recurring tax. |
|
528 | - * |
|
529 | - * @since 1.0.19 |
|
530 | - */ |
|
531 | - public function get_recurring_tax() { |
|
532 | - return $this->totals['taxes']['recurring']; |
|
533 | - } |
|
534 | - |
|
535 | - /** |
|
536 | - * Returns all taxes. |
|
537 | - * |
|
538 | - * @since 1.0.19 |
|
539 | - */ |
|
540 | - public function get_taxes() { |
|
541 | - return $this->taxes; |
|
542 | - } |
|
543 | - |
|
544 | - /* |
|
423 | + /** |
|
424 | + * Prepares the submission's taxes. |
|
425 | + * |
|
426 | + * @since 1.0.19 |
|
427 | + */ |
|
428 | + public function process_taxes() { |
|
429 | + |
|
430 | + // Abort if we're not using taxes. |
|
431 | + if ( ! $this->use_taxes() ) { |
|
432 | + return; |
|
433 | + } |
|
434 | + |
|
435 | + // If a custom country && state has been passed in, use it to calculate taxes. |
|
436 | + $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
437 | + if ( ! empty( $country ) ) { |
|
438 | + $this->country = $country; |
|
439 | + } |
|
440 | + |
|
441 | + $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
442 | + if ( ! empty( $state ) ) { |
|
443 | + $this->state = $state; |
|
444 | + } |
|
445 | + |
|
446 | + // Confirm if the provided country and the ip country are similar. |
|
447 | + $address_confirmed = $this->get_field( 'confirm-address' ); |
|
448 | + if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
449 | + throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
450 | + } |
|
451 | + |
|
452 | + // Abort if the country is not taxable. |
|
453 | + if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
454 | + return; |
|
455 | + } |
|
456 | + |
|
457 | + $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
458 | + |
|
459 | + foreach ( $processor->taxes as $tax ) { |
|
460 | + $this->add_tax( $tax ); |
|
461 | + } |
|
462 | + |
|
463 | + do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
464 | + } |
|
465 | + |
|
466 | + /** |
|
467 | + * Adds a tax to the submission. |
|
468 | + * |
|
469 | + * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
470 | + * @since 1.0.19 |
|
471 | + */ |
|
472 | + public function add_tax( $tax ) { |
|
473 | + |
|
474 | + if ( wpinv_round_tax_per_tax_rate() ) { |
|
475 | + $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
476 | + $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
477 | + } |
|
478 | + |
|
479 | + $this->taxes[ $tax['name'] ] = $tax; |
|
480 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
481 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
482 | + |
|
483 | + } |
|
484 | + |
|
485 | + /** |
|
486 | + * Removes a specific tax. |
|
487 | + * |
|
488 | + * @since 1.0.19 |
|
489 | + */ |
|
490 | + public function remove_tax( $tax_name ) { |
|
491 | + |
|
492 | + if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
493 | + $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
494 | + $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
495 | + unset( $this->taxes[ $tax_name ] ); |
|
496 | + } |
|
497 | + |
|
498 | + } |
|
499 | + |
|
500 | + /** |
|
501 | + * Whether or not we'll use taxes for the submission. |
|
502 | + * |
|
503 | + * @since 1.0.19 |
|
504 | + */ |
|
505 | + public function use_taxes() { |
|
506 | + |
|
507 | + $use_taxes = wpinv_use_taxes(); |
|
508 | + |
|
509 | + if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
510 | + $use_taxes = false; |
|
511 | + } |
|
512 | + |
|
513 | + return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
514 | + |
|
515 | + } |
|
516 | + |
|
517 | + /** |
|
518 | + * Returns the tax. |
|
519 | + * |
|
520 | + * @since 1.0.19 |
|
521 | + */ |
|
522 | + public function get_tax() { |
|
523 | + return $this->totals['taxes']['initial']; |
|
524 | + } |
|
525 | + |
|
526 | + /** |
|
527 | + * Returns the recurring tax. |
|
528 | + * |
|
529 | + * @since 1.0.19 |
|
530 | + */ |
|
531 | + public function get_recurring_tax() { |
|
532 | + return $this->totals['taxes']['recurring']; |
|
533 | + } |
|
534 | + |
|
535 | + /** |
|
536 | + * Returns all taxes. |
|
537 | + * |
|
538 | + * @since 1.0.19 |
|
539 | + */ |
|
540 | + public function get_taxes() { |
|
541 | + return $this->taxes; |
|
542 | + } |
|
543 | + |
|
544 | + /* |
|
545 | 545 | |-------------------------------------------------------------------------- |
546 | 546 | | Discounts |
547 | 547 | |-------------------------------------------------------------------------- |
@@ -550,99 +550,99 @@ discard block |
||
550 | 550 | | or only one-time. They also do not have to come from a discount code. |
551 | 551 | */ |
552 | 552 | |
553 | - /** |
|
554 | - * Prepares the submission's discount. |
|
555 | - * |
|
556 | - * @since 1.0.19 |
|
557 | - */ |
|
558 | - public function process_discount() { |
|
559 | - |
|
560 | - $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
561 | - $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
562 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
563 | - |
|
564 | - foreach ( $processor->discounts as $discount ) { |
|
565 | - $this->add_discount( $discount ); |
|
566 | - } |
|
567 | - |
|
568 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
569 | - } |
|
570 | - |
|
571 | - /** |
|
572 | - * Adds a discount to the submission. |
|
573 | - * |
|
574 | - * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
575 | - * @since 1.0.19 |
|
576 | - */ |
|
577 | - public function add_discount( $discount ) { |
|
578 | - $this->discounts[ $discount['name'] ] = $discount; |
|
579 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
580 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
581 | - } |
|
582 | - |
|
583 | - /** |
|
584 | - * Removes a discount from the submission. |
|
585 | - * |
|
586 | - * @since 1.0.19 |
|
587 | - */ |
|
588 | - public function remove_discount( $name ) { |
|
589 | - |
|
590 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
591 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
592 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
593 | - unset( $this->discounts[ $name ] ); |
|
594 | - } |
|
595 | - |
|
596 | - } |
|
597 | - |
|
598 | - /** |
|
599 | - * Checks whether there is a discount code associated with this submission. |
|
600 | - * |
|
601 | - * @since 1.0.19 |
|
602 | - * @return bool |
|
603 | - */ |
|
604 | - public function has_discount_code() { |
|
605 | - return ! empty( $this->discounts['discount_code'] ); |
|
606 | - } |
|
607 | - |
|
608 | - /** |
|
609 | - * Returns the discount code. |
|
610 | - * |
|
611 | - * @since 1.0.19 |
|
612 | - * @return string |
|
613 | - */ |
|
614 | - public function get_discount_code() { |
|
615 | - return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
616 | - } |
|
617 | - |
|
618 | - /** |
|
619 | - * Returns the discount. |
|
620 | - * |
|
621 | - * @since 1.0.19 |
|
622 | - */ |
|
623 | - public function get_discount() { |
|
624 | - return $this->totals['discount']['initial']; |
|
625 | - } |
|
626 | - |
|
627 | - /** |
|
628 | - * Returns the recurring discount. |
|
629 | - * |
|
630 | - * @since 1.0.19 |
|
631 | - */ |
|
632 | - public function get_recurring_discount() { |
|
633 | - return $this->totals['discount']['recurring']; |
|
634 | - } |
|
635 | - |
|
636 | - /** |
|
637 | - * Returns all discounts. |
|
638 | - * |
|
639 | - * @since 1.0.19 |
|
640 | - */ |
|
641 | - public function get_discounts() { |
|
642 | - return $this->discounts; |
|
643 | - } |
|
644 | - |
|
645 | - /* |
|
553 | + /** |
|
554 | + * Prepares the submission's discount. |
|
555 | + * |
|
556 | + * @since 1.0.19 |
|
557 | + */ |
|
558 | + public function process_discount() { |
|
559 | + |
|
560 | + $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
561 | + $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
562 | + $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
563 | + |
|
564 | + foreach ( $processor->discounts as $discount ) { |
|
565 | + $this->add_discount( $discount ); |
|
566 | + } |
|
567 | + |
|
568 | + do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
569 | + } |
|
570 | + |
|
571 | + /** |
|
572 | + * Adds a discount to the submission. |
|
573 | + * |
|
574 | + * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
575 | + * @since 1.0.19 |
|
576 | + */ |
|
577 | + public function add_discount( $discount ) { |
|
578 | + $this->discounts[ $discount['name'] ] = $discount; |
|
579 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
580 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
581 | + } |
|
582 | + |
|
583 | + /** |
|
584 | + * Removes a discount from the submission. |
|
585 | + * |
|
586 | + * @since 1.0.19 |
|
587 | + */ |
|
588 | + public function remove_discount( $name ) { |
|
589 | + |
|
590 | + if ( isset( $this->discounts[ $name ] ) ) { |
|
591 | + $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
592 | + $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
593 | + unset( $this->discounts[ $name ] ); |
|
594 | + } |
|
595 | + |
|
596 | + } |
|
597 | + |
|
598 | + /** |
|
599 | + * Checks whether there is a discount code associated with this submission. |
|
600 | + * |
|
601 | + * @since 1.0.19 |
|
602 | + * @return bool |
|
603 | + */ |
|
604 | + public function has_discount_code() { |
|
605 | + return ! empty( $this->discounts['discount_code'] ); |
|
606 | + } |
|
607 | + |
|
608 | + /** |
|
609 | + * Returns the discount code. |
|
610 | + * |
|
611 | + * @since 1.0.19 |
|
612 | + * @return string |
|
613 | + */ |
|
614 | + public function get_discount_code() { |
|
615 | + return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
616 | + } |
|
617 | + |
|
618 | + /** |
|
619 | + * Returns the discount. |
|
620 | + * |
|
621 | + * @since 1.0.19 |
|
622 | + */ |
|
623 | + public function get_discount() { |
|
624 | + return $this->totals['discount']['initial']; |
|
625 | + } |
|
626 | + |
|
627 | + /** |
|
628 | + * Returns the recurring discount. |
|
629 | + * |
|
630 | + * @since 1.0.19 |
|
631 | + */ |
|
632 | + public function get_recurring_discount() { |
|
633 | + return $this->totals['discount']['recurring']; |
|
634 | + } |
|
635 | + |
|
636 | + /** |
|
637 | + * Returns all discounts. |
|
638 | + * |
|
639 | + * @since 1.0.19 |
|
640 | + */ |
|
641 | + public function get_discounts() { |
|
642 | + return $this->discounts; |
|
643 | + } |
|
644 | + |
|
645 | + /* |
|
646 | 646 | |-------------------------------------------------------------------------- |
647 | 647 | | Fees |
648 | 648 | |-------------------------------------------------------------------------- |
@@ -652,89 +652,89 @@ discard block |
||
652 | 652 | | fees. |
653 | 653 | */ |
654 | 654 | |
655 | - /** |
|
656 | - * Prepares the submission's fees. |
|
657 | - * |
|
658 | - * @since 1.0.19 |
|
659 | - */ |
|
660 | - public function process_fees() { |
|
661 | - |
|
662 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
663 | - |
|
664 | - foreach ( $fees_processor->fees as $fee ) { |
|
665 | - $this->add_fee( $fee ); |
|
666 | - } |
|
667 | - |
|
668 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
669 | - } |
|
670 | - |
|
671 | - /** |
|
672 | - * Adds a fee to the submission. |
|
673 | - * |
|
674 | - * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
675 | - * @since 1.0.19 |
|
676 | - */ |
|
677 | - public function add_fee( $fee ) { |
|
678 | - |
|
679 | - $this->fees[ $fee['name'] ] = $fee; |
|
680 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
681 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
682 | - |
|
683 | - } |
|
684 | - |
|
685 | - /** |
|
686 | - * Removes a fee from the submission. |
|
687 | - * |
|
688 | - * @since 1.0.19 |
|
689 | - */ |
|
690 | - public function remove_fee( $name ) { |
|
691 | - |
|
692 | - if ( isset( $this->fees[ $name ] ) ) { |
|
693 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
694 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
695 | - unset( $this->fees[ $name ] ); |
|
696 | - } |
|
697 | - |
|
698 | - } |
|
699 | - |
|
700 | - /** |
|
701 | - * Returns the fees. |
|
702 | - * |
|
703 | - * @since 1.0.19 |
|
704 | - */ |
|
705 | - public function get_fee() { |
|
706 | - return $this->totals['fees']['initial']; |
|
707 | - } |
|
708 | - |
|
709 | - /** |
|
710 | - * Returns the recurring fees. |
|
711 | - * |
|
712 | - * @since 1.0.19 |
|
713 | - */ |
|
714 | - public function get_recurring_fee() { |
|
715 | - return $this->totals['fees']['recurring']; |
|
716 | - } |
|
717 | - |
|
718 | - /** |
|
719 | - * Returns all fees. |
|
720 | - * |
|
721 | - * @since 1.0.19 |
|
722 | - */ |
|
723 | - public function get_fees() { |
|
724 | - return $this->fees; |
|
725 | - } |
|
726 | - |
|
727 | - /** |
|
728 | - * Checks if there are any fees for the form. |
|
729 | - * |
|
730 | - * @return bool |
|
731 | - * @since 1.0.19 |
|
732 | - */ |
|
733 | - public function has_fees() { |
|
734 | - return count( $this->fees ) !== 0; |
|
735 | - } |
|
736 | - |
|
737 | - /* |
|
655 | + /** |
|
656 | + * Prepares the submission's fees. |
|
657 | + * |
|
658 | + * @since 1.0.19 |
|
659 | + */ |
|
660 | + public function process_fees() { |
|
661 | + |
|
662 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
663 | + |
|
664 | + foreach ( $fees_processor->fees as $fee ) { |
|
665 | + $this->add_fee( $fee ); |
|
666 | + } |
|
667 | + |
|
668 | + do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
669 | + } |
|
670 | + |
|
671 | + /** |
|
672 | + * Adds a fee to the submission. |
|
673 | + * |
|
674 | + * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
675 | + * @since 1.0.19 |
|
676 | + */ |
|
677 | + public function add_fee( $fee ) { |
|
678 | + |
|
679 | + $this->fees[ $fee['name'] ] = $fee; |
|
680 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
681 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
682 | + |
|
683 | + } |
|
684 | + |
|
685 | + /** |
|
686 | + * Removes a fee from the submission. |
|
687 | + * |
|
688 | + * @since 1.0.19 |
|
689 | + */ |
|
690 | + public function remove_fee( $name ) { |
|
691 | + |
|
692 | + if ( isset( $this->fees[ $name ] ) ) { |
|
693 | + $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
694 | + $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
695 | + unset( $this->fees[ $name ] ); |
|
696 | + } |
|
697 | + |
|
698 | + } |
|
699 | + |
|
700 | + /** |
|
701 | + * Returns the fees. |
|
702 | + * |
|
703 | + * @since 1.0.19 |
|
704 | + */ |
|
705 | + public function get_fee() { |
|
706 | + return $this->totals['fees']['initial']; |
|
707 | + } |
|
708 | + |
|
709 | + /** |
|
710 | + * Returns the recurring fees. |
|
711 | + * |
|
712 | + * @since 1.0.19 |
|
713 | + */ |
|
714 | + public function get_recurring_fee() { |
|
715 | + return $this->totals['fees']['recurring']; |
|
716 | + } |
|
717 | + |
|
718 | + /** |
|
719 | + * Returns all fees. |
|
720 | + * |
|
721 | + * @since 1.0.19 |
|
722 | + */ |
|
723 | + public function get_fees() { |
|
724 | + return $this->fees; |
|
725 | + } |
|
726 | + |
|
727 | + /** |
|
728 | + * Checks if there are any fees for the form. |
|
729 | + * |
|
730 | + * @return bool |
|
731 | + * @since 1.0.19 |
|
732 | + */ |
|
733 | + public function has_fees() { |
|
734 | + return count( $this->fees ) !== 0; |
|
735 | + } |
|
736 | + |
|
737 | + /* |
|
738 | 738 | |-------------------------------------------------------------------------- |
739 | 739 | | MISC |
740 | 740 | |-------------------------------------------------------------------------- |
@@ -742,119 +742,119 @@ discard block |
||
742 | 742 | | Extra submission functions. |
743 | 743 | */ |
744 | 744 | |
745 | - /** |
|
746 | - * Checks if this is the initial fetch. |
|
747 | - * |
|
748 | - * @return bool |
|
749 | - * @since 1.0.19 |
|
750 | - */ |
|
751 | - public function is_initial_fetch() { |
|
752 | - return empty( $this->data['initial_state'] ); |
|
753 | - } |
|
754 | - |
|
755 | - /** |
|
756 | - * Returns the total amount to collect for this submission. |
|
757 | - * |
|
758 | - * @since 1.0.19 |
|
759 | - */ |
|
760 | - public function get_total() { |
|
761 | - $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
|
762 | - return max( $total, 0 ); |
|
763 | - } |
|
764 | - |
|
765 | - /** |
|
766 | - * Returns the recurring total amount to collect for this submission. |
|
767 | - * |
|
768 | - * @since 1.0.19 |
|
769 | - */ |
|
770 | - public function get_recurring_total() { |
|
771 | - $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
|
772 | - return max( $total, 0 ); |
|
773 | - } |
|
774 | - |
|
775 | - /** |
|
776 | - * Whether payment details should be collected for this submission. |
|
777 | - * |
|
778 | - * @since 1.0.19 |
|
779 | - */ |
|
780 | - public function should_collect_payment_details() { |
|
781 | - $initial = $this->get_total(); |
|
782 | - $recurring = $this->get_recurring_total(); |
|
783 | - |
|
784 | - if ( $this->has_recurring == 0 ) { |
|
785 | - $recurring = 0; |
|
786 | - } |
|
787 | - |
|
788 | - $collect = $initial > 0 || $recurring > 0; |
|
789 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
790 | - } |
|
791 | - |
|
792 | - /** |
|
793 | - * Returns the billing email of the user. |
|
794 | - * |
|
795 | - * @since 1.0.19 |
|
796 | - */ |
|
797 | - public function get_billing_email() { |
|
798 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
799 | - } |
|
800 | - |
|
801 | - /** |
|
802 | - * Checks if the submitter has a billing email. |
|
803 | - * |
|
804 | - * @since 1.0.19 |
|
805 | - */ |
|
806 | - public function has_billing_email() { |
|
807 | - $billing_email = $this->get_billing_email(); |
|
808 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
809 | - } |
|
810 | - |
|
811 | - /** |
|
812 | - * Returns the appropriate currency for the submission. |
|
813 | - * |
|
814 | - * @since 1.0.19 |
|
815 | - * @return string |
|
816 | - */ |
|
817 | - public function get_currency() { |
|
818 | - return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
819 | - } |
|
820 | - |
|
821 | - /** |
|
822 | - * Returns the raw submission data. |
|
823 | - * |
|
824 | - * @since 1.0.19 |
|
825 | - * @return array |
|
826 | - */ |
|
827 | - public function get_data() { |
|
828 | - return $this->data; |
|
829 | - } |
|
830 | - |
|
831 | - /** |
|
832 | - * Returns a field from the submission data |
|
833 | - * |
|
834 | - * @param string $field |
|
835 | - * @since 1.0.19 |
|
836 | - * @return mixed|null |
|
837 | - */ |
|
838 | - public function get_field( $field, $sub_array_key = null ) { |
|
839 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
840 | - } |
|
841 | - |
|
842 | - /** |
|
843 | - * Checks if a required field is set. |
|
844 | - * |
|
845 | - * @since 1.0.19 |
|
846 | - */ |
|
847 | - public function is_required_field_set( $field ) { |
|
848 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
849 | - } |
|
850 | - |
|
851 | - /** |
|
852 | - * Formats an amount |
|
853 | - * |
|
854 | - * @since 1.0.19 |
|
855 | - */ |
|
856 | - public function format_amount( $amount ) { |
|
857 | - return wpinv_price( $amount, $this->get_currency() ); |
|
858 | - } |
|
745 | + /** |
|
746 | + * Checks if this is the initial fetch. |
|
747 | + * |
|
748 | + * @return bool |
|
749 | + * @since 1.0.19 |
|
750 | + */ |
|
751 | + public function is_initial_fetch() { |
|
752 | + return empty( $this->data['initial_state'] ); |
|
753 | + } |
|
754 | + |
|
755 | + /** |
|
756 | + * Returns the total amount to collect for this submission. |
|
757 | + * |
|
758 | + * @since 1.0.19 |
|
759 | + */ |
|
760 | + public function get_total() { |
|
761 | + $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
|
762 | + return max( $total, 0 ); |
|
763 | + } |
|
764 | + |
|
765 | + /** |
|
766 | + * Returns the recurring total amount to collect for this submission. |
|
767 | + * |
|
768 | + * @since 1.0.19 |
|
769 | + */ |
|
770 | + public function get_recurring_total() { |
|
771 | + $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
|
772 | + return max( $total, 0 ); |
|
773 | + } |
|
774 | + |
|
775 | + /** |
|
776 | + * Whether payment details should be collected for this submission. |
|
777 | + * |
|
778 | + * @since 1.0.19 |
|
779 | + */ |
|
780 | + public function should_collect_payment_details() { |
|
781 | + $initial = $this->get_total(); |
|
782 | + $recurring = $this->get_recurring_total(); |
|
783 | + |
|
784 | + if ( $this->has_recurring == 0 ) { |
|
785 | + $recurring = 0; |
|
786 | + } |
|
787 | + |
|
788 | + $collect = $initial > 0 || $recurring > 0; |
|
789 | + return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
790 | + } |
|
791 | + |
|
792 | + /** |
|
793 | + * Returns the billing email of the user. |
|
794 | + * |
|
795 | + * @since 1.0.19 |
|
796 | + */ |
|
797 | + public function get_billing_email() { |
|
798 | + return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
799 | + } |
|
800 | + |
|
801 | + /** |
|
802 | + * Checks if the submitter has a billing email. |
|
803 | + * |
|
804 | + * @since 1.0.19 |
|
805 | + */ |
|
806 | + public function has_billing_email() { |
|
807 | + $billing_email = $this->get_billing_email(); |
|
808 | + return ! empty( $billing_email ) && is_email( $billing_email ); |
|
809 | + } |
|
810 | + |
|
811 | + /** |
|
812 | + * Returns the appropriate currency for the submission. |
|
813 | + * |
|
814 | + * @since 1.0.19 |
|
815 | + * @return string |
|
816 | + */ |
|
817 | + public function get_currency() { |
|
818 | + return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
819 | + } |
|
820 | + |
|
821 | + /** |
|
822 | + * Returns the raw submission data. |
|
823 | + * |
|
824 | + * @since 1.0.19 |
|
825 | + * @return array |
|
826 | + */ |
|
827 | + public function get_data() { |
|
828 | + return $this->data; |
|
829 | + } |
|
830 | + |
|
831 | + /** |
|
832 | + * Returns a field from the submission data |
|
833 | + * |
|
834 | + * @param string $field |
|
835 | + * @since 1.0.19 |
|
836 | + * @return mixed|null |
|
837 | + */ |
|
838 | + public function get_field( $field, $sub_array_key = null ) { |
|
839 | + return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
840 | + } |
|
841 | + |
|
842 | + /** |
|
843 | + * Checks if a required field is set. |
|
844 | + * |
|
845 | + * @since 1.0.19 |
|
846 | + */ |
|
847 | + public function is_required_field_set( $field ) { |
|
848 | + return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
849 | + } |
|
850 | + |
|
851 | + /** |
|
852 | + * Formats an amount |
|
853 | + * |
|
854 | + * @since 1.0.19 |
|
855 | + */ |
|
856 | + public function format_amount( $amount ) { |
|
857 | + return wpinv_price( $amount, $this->get_currency() ); |
|
858 | + } |
|
859 | 859 | |
860 | 860 | } |
@@ -13,30 +13,30 @@ discard block |
||
13 | 13 | class GetPaid_Bank_Transfer_Gateway extends GetPaid_Payment_Gateway { |
14 | 14 | |
15 | 15 | /** |
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | 20 | public $id = 'bank_transfer'; |
21 | 21 | |
22 | - /** |
|
23 | - * An array of features that this gateway supports. |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
27 | - protected $supports = array( 'addons' ); |
|
22 | + /** |
|
23 | + * An array of features that this gateway supports. |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | + protected $supports = array( 'addons' ); |
|
28 | 28 | |
29 | 29 | /** |
30 | - * Payment method order. |
|
31 | - * |
|
32 | - * @var int |
|
33 | - */ |
|
34 | - public $order = 8; |
|
30 | + * Payment method order. |
|
31 | + * |
|
32 | + * @var int |
|
33 | + */ |
|
34 | + public $order = 8; |
|
35 | 35 | |
36 | 36 | /** |
37 | - * Class constructor. |
|
38 | - */ |
|
39 | - public function __construct() { |
|
37 | + * Class constructor. |
|
38 | + */ |
|
39 | + public function __construct() { |
|
40 | 40 | parent::__construct(); |
41 | 41 | |
42 | 42 | $this->title = __( 'Direct bank transfer', 'invoicing' ); |
@@ -44,23 +44,23 @@ discard block |
||
44 | 44 | $this->checkout_button_text = __( 'Proceed', 'invoicing' ); |
45 | 45 | $this->instructions = apply_filters( 'wpinv_bank_instructions', $this->get_option( 'info' ) ); |
46 | 46 | |
47 | - add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) ); |
|
48 | - add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 ); |
|
49 | - add_action( 'wpinv_pdf_content_billing', array( $this, 'thankyou_page' ), 11 ); |
|
50 | - add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 ); |
|
47 | + add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) ); |
|
48 | + add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 ); |
|
49 | + add_action( 'wpinv_pdf_content_billing', array( $this, 'thankyou_page' ), 11 ); |
|
50 | + add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 ); |
|
51 | 51 | |
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
55 | - * Process Payment. |
|
56 | - * |
|
57 | - * |
|
58 | - * @param WPInv_Invoice $invoice Invoice. |
|
59 | - * @param array $submission_data Posted checkout fields. |
|
60 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
61 | - * @return array |
|
62 | - */ |
|
63 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
55 | + * Process Payment. |
|
56 | + * |
|
57 | + * |
|
58 | + * @param WPInv_Invoice $invoice Invoice. |
|
59 | + * @param array $submission_data Posted checkout fields. |
|
60 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
61 | + * @return array |
|
62 | + */ |
|
63 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
64 | 64 | |
65 | 65 | // Add a transaction id. |
66 | 66 | $invoice->set_transaction_id( $invoice->generate_key('trans_') ); |
@@ -81,66 +81,66 @@ discard block |
||
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
84 | - * Output for the order received page. |
|
85 | - * |
|
86 | - * @param WPInv_Invoice $invoice Invoice. |
|
87 | - */ |
|
88 | - public function thankyou_page( $invoice ) { |
|
84 | + * Output for the order received page. |
|
85 | + * |
|
86 | + * @param WPInv_Invoice $invoice Invoice. |
|
87 | + */ |
|
88 | + public function thankyou_page( $invoice ) { |
|
89 | 89 | |
90 | 90 | if ( 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
91 | 91 | |
92 | - echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL; |
|
92 | + echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL; |
|
93 | 93 | |
94 | 94 | if ( ! empty( $this->instructions ) ) { |
95 | 95 | echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) ); |
96 | - } |
|
96 | + } |
|
97 | 97 | |
98 | - $this->bank_details( $invoice ); |
|
98 | + $this->bank_details( $invoice ); |
|
99 | 99 | |
100 | - echo '</div>'; |
|
100 | + echo '</div>'; |
|
101 | 101 | |
102 | 102 | } |
103 | 103 | |
104 | - } |
|
104 | + } |
|
105 | 105 | |
106 | 106 | /** |
107 | - * Add content to the WPI emails. |
|
108 | - * |
|
109 | - * @param WPInv_Invoice $invoice Invoice. |
|
110 | - * @param string $email_type Email format: plain text or HTML. |
|
111 | - * @param bool $sent_to_admin Sent to admin. |
|
112 | - */ |
|
113 | - public function email_instructions( $invoice, $email_type, $sent_to_admin ) { |
|
107 | + * Add content to the WPI emails. |
|
108 | + * |
|
109 | + * @param WPInv_Invoice $invoice Invoice. |
|
110 | + * @param string $email_type Email format: plain text or HTML. |
|
111 | + * @param bool $sent_to_admin Sent to admin. |
|
112 | + */ |
|
113 | + public function email_instructions( $invoice, $email_type, $sent_to_admin ) { |
|
114 | 114 | |
115 | - if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
|
115 | + if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
|
116 | 116 | |
117 | - echo '<div class="wpi-email-row getpaid-bank-transfer-details">'; |
|
117 | + echo '<div class="wpi-email-row getpaid-bank-transfer-details">'; |
|
118 | 118 | |
119 | - if ( $this->instructions ) { |
|
120 | - echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL ); |
|
119 | + if ( $this->instructions ) { |
|
120 | + echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL ); |
|
121 | 121 | } |
122 | 122 | |
123 | - $this->bank_details( $invoice ); |
|
123 | + $this->bank_details( $invoice ); |
|
124 | 124 | |
125 | - echo '</div>'; |
|
125 | + echo '</div>'; |
|
126 | 126 | |
127 | - } |
|
127 | + } |
|
128 | 128 | |
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
132 | - * Get bank details and place into a list format. |
|
133 | - * |
|
134 | - * @param WPInv_Invoice $invoice Invoice. |
|
135 | - */ |
|
136 | - protected function bank_details( $invoice ) { |
|
132 | + * Get bank details and place into a list format. |
|
133 | + * |
|
134 | + * @param WPInv_Invoice $invoice Invoice. |
|
135 | + */ |
|
136 | + protected function bank_details( $invoice ) { |
|
137 | 137 | |
138 | - // Get the invoice country and country $locale. |
|
139 | - $country = $invoice->get_country(); |
|
140 | - $locale = $this->get_country_locale(); |
|
138 | + // Get the invoice country and country $locale. |
|
139 | + $country = $invoice->get_country(); |
|
140 | + $locale = $this->get_country_locale(); |
|
141 | 141 | |
142 | - // Get sortcode label in the $locale array and use appropriate one. |
|
143 | - $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
142 | + // Get sortcode label in the $locale array and use appropriate one. |
|
143 | + $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
144 | 144 | |
145 | 145 | $bank_fields = array( |
146 | 146 | 'ac_name' => __( 'Account Name', 'invoicing' ), |
@@ -169,144 +169,144 @@ discard block |
||
169 | 169 | return; |
170 | 170 | } |
171 | 171 | |
172 | - echo '<h3 class="getpaid-bank-transfer-title"> ' . apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ) ) . '</h3>' . PHP_EOL; |
|
172 | + echo '<h3 class="getpaid-bank-transfer-title"> ' . apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ) ) . '</h3>' . PHP_EOL; |
|
173 | 173 | |
174 | - echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL; |
|
174 | + echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL; |
|
175 | 175 | |
176 | - foreach ( $bank_info as $key => $data ) { |
|
176 | + foreach ( $bank_info as $key => $data ) { |
|
177 | 177 | |
178 | - $key = sanitize_html_class( $key ); |
|
179 | - $label = wp_kses_post( $data['label'] ); |
|
180 | - $value = wp_kses_post( wptexturize( $data['value'] ) ); |
|
178 | + $key = sanitize_html_class( $key ); |
|
179 | + $label = wp_kses_post( $data['label'] ); |
|
180 | + $value = wp_kses_post( wptexturize( $data['value'] ) ); |
|
181 | 181 | |
182 | - echo "<tr class='getpaid-bank-transfer-$key'><th class='font-weight-bold'>$label</th><td class='w-75'>$value</td></tr>" . PHP_EOL; |
|
183 | - } |
|
182 | + echo "<tr class='getpaid-bank-transfer-$key'><th class='font-weight-bold'>$label</th><td class='w-75'>$value</td></tr>" . PHP_EOL; |
|
183 | + } |
|
184 | 184 | |
185 | - echo '</table>'; |
|
185 | + echo '</table>'; |
|
186 | 186 | |
187 | 187 | } |
188 | 188 | |
189 | 189 | /** |
190 | - * Get country locale if localized. |
|
191 | - * |
|
192 | - * @return array |
|
193 | - */ |
|
194 | - public function get_country_locale() { |
|
195 | - |
|
196 | - if ( empty( $this->locale ) ) { |
|
197 | - |
|
198 | - // Locale information to be used - only those that are not 'Sort Code'. |
|
199 | - $this->locale = apply_filters( |
|
200 | - 'getpaid_get_bank_transfer_locale', |
|
201 | - array( |
|
202 | - 'AU' => array( |
|
203 | - 'sortcode' => array( |
|
204 | - 'label' => __( 'BSB', 'invoicing' ), |
|
205 | - ), |
|
206 | - ), |
|
207 | - 'CA' => array( |
|
208 | - 'sortcode' => array( |
|
209 | - 'label' => __( 'Bank transit number', 'invoicing' ), |
|
210 | - ), |
|
211 | - ), |
|
212 | - 'IN' => array( |
|
213 | - 'sortcode' => array( |
|
214 | - 'label' => __( 'IFSC', 'invoicing' ), |
|
215 | - ), |
|
216 | - ), |
|
217 | - 'IT' => array( |
|
218 | - 'sortcode' => array( |
|
219 | - 'label' => __( 'Branch sort', 'invoicing' ), |
|
220 | - ), |
|
221 | - ), |
|
222 | - 'NZ' => array( |
|
223 | - 'sortcode' => array( |
|
224 | - 'label' => __( 'Bank code', 'invoicing' ), |
|
225 | - ), |
|
226 | - ), |
|
227 | - 'SE' => array( |
|
228 | - 'sortcode' => array( |
|
229 | - 'label' => __( 'Bank code', 'invoicing' ), |
|
230 | - ), |
|
231 | - ), |
|
232 | - 'US' => array( |
|
233 | - 'sortcode' => array( |
|
234 | - 'label' => __( 'Routing number', 'invoicing' ), |
|
235 | - ), |
|
236 | - ), |
|
237 | - 'ZA' => array( |
|
238 | - 'sortcode' => array( |
|
239 | - 'label' => __( 'Branch code', 'invoicing' ), |
|
240 | - ), |
|
241 | - ), |
|
242 | - ) |
|
243 | - ); |
|
244 | - |
|
245 | - } |
|
246 | - |
|
247 | - return $this->locale; |
|
248 | - |
|
249 | - } |
|
250 | - |
|
251 | - /** |
|
252 | - * Filters the gateway settings. |
|
253 | - * |
|
254 | - * @param array $admin_settings |
|
255 | - */ |
|
256 | - public function admin_settings( $admin_settings ) { |
|
190 | + * Get country locale if localized. |
|
191 | + * |
|
192 | + * @return array |
|
193 | + */ |
|
194 | + public function get_country_locale() { |
|
195 | + |
|
196 | + if ( empty( $this->locale ) ) { |
|
197 | + |
|
198 | + // Locale information to be used - only those that are not 'Sort Code'. |
|
199 | + $this->locale = apply_filters( |
|
200 | + 'getpaid_get_bank_transfer_locale', |
|
201 | + array( |
|
202 | + 'AU' => array( |
|
203 | + 'sortcode' => array( |
|
204 | + 'label' => __( 'BSB', 'invoicing' ), |
|
205 | + ), |
|
206 | + ), |
|
207 | + 'CA' => array( |
|
208 | + 'sortcode' => array( |
|
209 | + 'label' => __( 'Bank transit number', 'invoicing' ), |
|
210 | + ), |
|
211 | + ), |
|
212 | + 'IN' => array( |
|
213 | + 'sortcode' => array( |
|
214 | + 'label' => __( 'IFSC', 'invoicing' ), |
|
215 | + ), |
|
216 | + ), |
|
217 | + 'IT' => array( |
|
218 | + 'sortcode' => array( |
|
219 | + 'label' => __( 'Branch sort', 'invoicing' ), |
|
220 | + ), |
|
221 | + ), |
|
222 | + 'NZ' => array( |
|
223 | + 'sortcode' => array( |
|
224 | + 'label' => __( 'Bank code', 'invoicing' ), |
|
225 | + ), |
|
226 | + ), |
|
227 | + 'SE' => array( |
|
228 | + 'sortcode' => array( |
|
229 | + 'label' => __( 'Bank code', 'invoicing' ), |
|
230 | + ), |
|
231 | + ), |
|
232 | + 'US' => array( |
|
233 | + 'sortcode' => array( |
|
234 | + 'label' => __( 'Routing number', 'invoicing' ), |
|
235 | + ), |
|
236 | + ), |
|
237 | + 'ZA' => array( |
|
238 | + 'sortcode' => array( |
|
239 | + 'label' => __( 'Branch code', 'invoicing' ), |
|
240 | + ), |
|
241 | + ), |
|
242 | + ) |
|
243 | + ); |
|
244 | + |
|
245 | + } |
|
246 | + |
|
247 | + return $this->locale; |
|
248 | + |
|
249 | + } |
|
250 | + |
|
251 | + /** |
|
252 | + * Filters the gateway settings. |
|
253 | + * |
|
254 | + * @param array $admin_settings |
|
255 | + */ |
|
256 | + public function admin_settings( $admin_settings ) { |
|
257 | 257 | |
258 | 258 | $admin_settings['bank_transfer_desc']['std'] = __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' ); |
259 | - $admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' ); |
|
259 | + $admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' ); |
|
260 | 260 | |
261 | - $locale = $this->get_country_locale(); |
|
261 | + $locale = $this->get_country_locale(); |
|
262 | 262 | |
263 | - // Get sortcode label in the $locale array and use appropriate one. |
|
264 | - $country = wpinv_default_billing_country(); |
|
265 | - $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
263 | + // Get sortcode label in the $locale array and use appropriate one. |
|
264 | + $country = wpinv_default_billing_country(); |
|
265 | + $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
266 | 266 | |
267 | - $admin_settings['bank_transfer_ac_name'] = array( |
|
267 | + $admin_settings['bank_transfer_ac_name'] = array( |
|
268 | 268 | 'type' => 'text', |
269 | 269 | 'id' => 'bank_transfer_ac_name', |
270 | 270 | 'name' => __( 'Account Name', 'invoicing' ), |
271 | - ); |
|
271 | + ); |
|
272 | 272 | |
273 | - $admin_settings['bank_transfer_ac_no'] = array( |
|
273 | + $admin_settings['bank_transfer_ac_no'] = array( |
|
274 | 274 | 'type' => 'text', |
275 | 275 | 'id' => 'bank_transfer_ac_no', |
276 | 276 | 'name' => __( 'Account Number', 'invoicing' ), |
277 | - ); |
|
277 | + ); |
|
278 | 278 | |
279 | - $admin_settings['bank_transfer_bank_name'] = array( |
|
279 | + $admin_settings['bank_transfer_bank_name'] = array( |
|
280 | 280 | 'type' => 'text', |
281 | 281 | 'id' => 'bank_transfer_bank_name', |
282 | 282 | 'name' => __( 'Bank Name', 'invoicing' ), |
283 | - ); |
|
283 | + ); |
|
284 | 284 | |
285 | - $admin_settings['bank_transfer_ifsc'] = array( |
|
285 | + $admin_settings['bank_transfer_ifsc'] = array( |
|
286 | 286 | 'type' => 'text', |
287 | 287 | 'id' => 'bank_transfer_ifsc', |
288 | 288 | 'name' => __( 'IFSC Code', 'invoicing' ), |
289 | - ); |
|
289 | + ); |
|
290 | 290 | |
291 | - $admin_settings['bank_transfer_iban'] = array( |
|
291 | + $admin_settings['bank_transfer_iban'] = array( |
|
292 | 292 | 'type' => 'text', |
293 | 293 | 'id' => 'bank_transfer_iban', |
294 | 294 | 'name' => __( 'IBAN', 'invoicing' ), |
295 | - ); |
|
295 | + ); |
|
296 | 296 | |
297 | - $admin_settings['bank_transfer_bic'] = array( |
|
297 | + $admin_settings['bank_transfer_bic'] = array( |
|
298 | 298 | 'type' => 'text', |
299 | 299 | 'id' => 'bank_transfer_bic', |
300 | 300 | 'name' => __( 'BIC/Swift Code', 'invoicing' ), |
301 | - ); |
|
301 | + ); |
|
302 | 302 | |
303 | - $admin_settings['bank_transfer_sort_code'] = array( |
|
304 | - 'type' => 'text', |
|
305 | - 'id' => 'bank_transfer_sort_code', |
|
306 | - 'name' => $sortcode, |
|
307 | - ); |
|
303 | + $admin_settings['bank_transfer_sort_code'] = array( |
|
304 | + 'type' => 'text', |
|
305 | + 'id' => 'bank_transfer_sort_code', |
|
306 | + 'name' => $sortcode, |
|
307 | + ); |
|
308 | 308 | |
309 | - $admin_settings['bank_transfer_info'] = array( |
|
309 | + $admin_settings['bank_transfer_info'] = array( |
|
310 | 310 | 'id' => 'bank_transfer_info', |
311 | 311 | 'name' => __( 'Instructions', 'invoicing' ), |
312 | 312 | 'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ), |
@@ -316,17 +316,17 @@ discard block |
||
316 | 316 | 'rows' => 5 |
317 | 317 | ); |
318 | 318 | |
319 | - return $admin_settings; |
|
320 | - } |
|
319 | + return $admin_settings; |
|
320 | + } |
|
321 | 321 | |
322 | - /** |
|
323 | - * Processes invoice addons. |
|
324 | - * |
|
325 | - * @param WPInv_Invoice $invoice |
|
326 | - * @param GetPaid_Form_Item[] $items |
|
327 | - * @return WPInv_Invoice |
|
328 | - */ |
|
329 | - public function process_addons( $invoice, $items ) { |
|
322 | + /** |
|
323 | + * Processes invoice addons. |
|
324 | + * |
|
325 | + * @param WPInv_Invoice $invoice |
|
326 | + * @param GetPaid_Form_Item[] $items |
|
327 | + * @return WPInv_Invoice |
|
328 | + */ |
|
329 | + public function process_addons( $invoice, $items ) { |
|
330 | 330 | |
331 | 331 | foreach ( $items as $item ) { |
332 | 332 | $invoice->add_item( $item ); |
@@ -334,6 +334,6 @@ discard block |
||
334 | 334 | |
335 | 335 | $invoice->recalculate_total(); |
336 | 336 | $invoice->save(); |
337 | - } |
|
337 | + } |
|
338 | 338 | |
339 | 339 | } |
@@ -12,229 +12,229 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Payment_Form_Submission_Taxes { |
14 | 14 | |
15 | - /** |
|
16 | - * Submission taxes. |
|
17 | - * @var array |
|
18 | - */ |
|
19 | - public $taxes = array(); |
|
20 | - |
|
21 | - /** |
|
22 | - * Whether or not we should skip the taxes. |
|
23 | - * @var bool |
|
24 | - */ |
|
25 | - protected $skip_taxes = false; |
|
15 | + /** |
|
16 | + * Submission taxes. |
|
17 | + * @var array |
|
18 | + */ |
|
19 | + public $taxes = array(); |
|
20 | + |
|
21 | + /** |
|
22 | + * Whether or not we should skip the taxes. |
|
23 | + * @var bool |
|
24 | + */ |
|
25 | + protected $skip_taxes = false; |
|
26 | + |
|
27 | + /** |
|
28 | + * Class constructor |
|
29 | + * |
|
30 | + * @param GetPaid_Payment_Form_Submission $submission |
|
31 | + */ |
|
32 | + public function __construct( $submission ) { |
|
33 | + |
|
34 | + // Validate VAT number. |
|
35 | + $this->validate_vat( $submission ); |
|
36 | + |
|
37 | + if ( $this->skip_taxes ) { |
|
38 | + return; |
|
39 | + } |
|
40 | + |
|
41 | + foreach ( $submission->get_items() as $item ) { |
|
42 | + $this->process_item_tax( $item, $submission ); |
|
43 | + } |
|
44 | + |
|
45 | + // Process any existing invoice taxes. |
|
46 | + if ( $submission->has_invoice() ) { |
|
47 | + $this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes ); |
|
48 | + } |
|
49 | + |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * Maybe process tax. |
|
54 | + * |
|
55 | + * @since 1.0.19 |
|
56 | + * @param GetPaid_Form_Item $item |
|
57 | + * @param GetPaid_Payment_Form_Submission $submission |
|
58 | + */ |
|
59 | + public function process_item_tax( $item, $submission ) { |
|
60 | + |
|
61 | + $rates = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state ); |
|
62 | + $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
63 | + $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ), $rates ); |
|
64 | + $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ), $rates ); |
|
65 | + |
|
66 | + foreach ( $taxes as $name => $amount ) { |
|
67 | + $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
68 | + $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
69 | + |
|
70 | + if ( ! isset( $this->taxes[ $name ] ) ) { |
|
71 | + $this->taxes[ $name ] = $tax; |
|
72 | + continue; |
|
73 | + } |
|
74 | + |
|
75 | + $this->taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
76 | + $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
77 | + |
|
78 | + } |
|
79 | + |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * Checks if the submission has a digital item. |
|
84 | + * |
|
85 | + * @param GetPaid_Payment_Form_Submission $submission |
|
86 | + * @since 1.0.19 |
|
87 | + * @return bool |
|
88 | + */ |
|
89 | + public function has_digital_item( $submission ) { |
|
90 | + |
|
91 | + foreach ( $submission->get_items() as $item ) { |
|
92 | + |
|
93 | + if ( 'digital' == $item->get_vat_rule() ) { |
|
94 | + return true; |
|
95 | + } |
|
96 | + |
|
97 | + } |
|
98 | + |
|
99 | + return false; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Checks if this is an eu store. |
|
104 | + * |
|
105 | + * @since 1.0.19 |
|
106 | + * @return bool |
|
107 | + */ |
|
108 | + public static function is_eu_store() { |
|
109 | + return self::is_eu_country( wpinv_get_default_country() ); |
|
110 | + } |
|
26 | 111 | |
27 | 112 | /** |
28 | - * Class constructor |
|
29 | - * |
|
30 | - * @param GetPaid_Payment_Form_Submission $submission |
|
31 | - */ |
|
32 | - public function __construct( $submission ) { |
|
33 | - |
|
34 | - // Validate VAT number. |
|
35 | - $this->validate_vat( $submission ); |
|
36 | - |
|
37 | - if ( $this->skip_taxes ) { |
|
38 | - return; |
|
39 | - } |
|
40 | - |
|
41 | - foreach ( $submission->get_items() as $item ) { |
|
42 | - $this->process_item_tax( $item, $submission ); |
|
43 | - } |
|
44 | - |
|
45 | - // Process any existing invoice taxes. |
|
46 | - if ( $submission->has_invoice() ) { |
|
47 | - $this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes ); |
|
48 | - } |
|
49 | - |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * Maybe process tax. |
|
54 | - * |
|
55 | - * @since 1.0.19 |
|
56 | - * @param GetPaid_Form_Item $item |
|
57 | - * @param GetPaid_Payment_Form_Submission $submission |
|
58 | - */ |
|
59 | - public function process_item_tax( $item, $submission ) { |
|
60 | - |
|
61 | - $rates = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state ); |
|
62 | - $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
63 | - $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ), $rates ); |
|
64 | - $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ), $rates ); |
|
65 | - |
|
66 | - foreach ( $taxes as $name => $amount ) { |
|
67 | - $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
68 | - $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
69 | - |
|
70 | - if ( ! isset( $this->taxes[ $name ] ) ) { |
|
71 | - $this->taxes[ $name ] = $tax; |
|
72 | - continue; |
|
73 | - } |
|
74 | - |
|
75 | - $this->taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
76 | - $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
77 | - |
|
78 | - } |
|
79 | - |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * Checks if the submission has a digital item. |
|
84 | - * |
|
85 | - * @param GetPaid_Payment_Form_Submission $submission |
|
86 | - * @since 1.0.19 |
|
87 | - * @return bool |
|
88 | - */ |
|
89 | - public function has_digital_item( $submission ) { |
|
90 | - |
|
91 | - foreach ( $submission->get_items() as $item ) { |
|
92 | - |
|
93 | - if ( 'digital' == $item->get_vat_rule() ) { |
|
94 | - return true; |
|
95 | - } |
|
96 | - |
|
97 | - } |
|
98 | - |
|
99 | - return false; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Checks if this is an eu store. |
|
104 | - * |
|
105 | - * @since 1.0.19 |
|
106 | - * @return bool |
|
107 | - */ |
|
108 | - public static function is_eu_store() { |
|
109 | - return self::is_eu_country( wpinv_get_default_country() ); |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * Checks if this is an eu country. |
|
114 | - * |
|
115 | - * @param string $country |
|
116 | - * @since 1.0.19 |
|
117 | - * @return bool |
|
118 | - */ |
|
119 | - public static function is_eu_country( $country ) { |
|
120 | - return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country ); |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Checks if this is an eu purchase. |
|
125 | - * |
|
126 | - * @param string $customer_country |
|
127 | - * @since 1.0.19 |
|
128 | - * @return bool |
|
129 | - */ |
|
130 | - public static function is_eu_transaction( $customer_country ) { |
|
131 | - return self::is_eu_country( $customer_country ) && self::is_eu_store(); |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Retrieves the vat number. |
|
136 | - * |
|
137 | - * @param GetPaid_Payment_Form_Submission $submission |
|
138 | - * @since 1.0.19 |
|
139 | - * @return string |
|
140 | - */ |
|
141 | - public function get_vat_number( $submission ) { |
|
142 | - |
|
143 | - // Retrieve from the posted number. |
|
144 | - $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' ); |
|
145 | - if ( ! empty( $vat_number ) ) { |
|
146 | - return wpinv_clean( $vat_number ); |
|
147 | - } |
|
148 | - |
|
149 | - // Retrieve from the invoice. |
|
150 | - return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : ''; |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * Retrieves the company. |
|
155 | - * |
|
156 | - * @param GetPaid_Payment_Form_Submission $submission |
|
157 | - * @since 1.0.19 |
|
158 | - * @return string |
|
159 | - */ |
|
160 | - public function get_company( $submission ) { |
|
161 | - |
|
162 | - // Retrieve from the posted data. |
|
163 | - $company = $submission->get_field( 'wpinv_company', 'billing' ); |
|
164 | - if ( ! empty( $company ) ) { |
|
165 | - return wpinv_clean( $company ); |
|
166 | - } |
|
167 | - |
|
168 | - // Retrieve from the invoice. |
|
169 | - return $submission->has_invoice() ? $submission->get_invoice()->get_company() : ''; |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * Checks if we require a VAT number. |
|
174 | - * |
|
175 | - * @param bool $ip_in_eu Whether the customer IP is from the EU |
|
176 | - * @param bool $country_in_eu Whether the customer country is from the EU |
|
177 | - * @since 1.0.19 |
|
178 | - * @return string |
|
179 | - */ |
|
180 | - public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
181 | - |
|
182 | - $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
183 | - $prevent_b2c = ! empty( $prevent_b2c ); |
|
184 | - $is_eu = $ip_in_eu || $country_in_eu; |
|
185 | - |
|
186 | - return $prevent_b2c && $is_eu; |
|
187 | - } |
|
188 | - |
|
189 | - /** |
|
190 | - * Validate VAT data. |
|
191 | - * |
|
192 | - * @param GetPaid_Payment_Form_Submission $submission |
|
193 | - * @since 1.0.19 |
|
194 | - */ |
|
195 | - public function validate_vat( $submission ) { |
|
196 | - |
|
197 | - $in_eu = $this->is_eu_transaction( $submission->country ); |
|
198 | - |
|
199 | - // Abort if we are not validating vat numbers. |
|
200 | - if ( ! $in_eu ) { |
|
113 | + * Checks if this is an eu country. |
|
114 | + * |
|
115 | + * @param string $country |
|
116 | + * @since 1.0.19 |
|
117 | + * @return bool |
|
118 | + */ |
|
119 | + public static function is_eu_country( $country ) { |
|
120 | + return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country ); |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Checks if this is an eu purchase. |
|
125 | + * |
|
126 | + * @param string $customer_country |
|
127 | + * @since 1.0.19 |
|
128 | + * @return bool |
|
129 | + */ |
|
130 | + public static function is_eu_transaction( $customer_country ) { |
|
131 | + return self::is_eu_country( $customer_country ) && self::is_eu_store(); |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Retrieves the vat number. |
|
136 | + * |
|
137 | + * @param GetPaid_Payment_Form_Submission $submission |
|
138 | + * @since 1.0.19 |
|
139 | + * @return string |
|
140 | + */ |
|
141 | + public function get_vat_number( $submission ) { |
|
142 | + |
|
143 | + // Retrieve from the posted number. |
|
144 | + $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' ); |
|
145 | + if ( ! empty( $vat_number ) ) { |
|
146 | + return wpinv_clean( $vat_number ); |
|
147 | + } |
|
148 | + |
|
149 | + // Retrieve from the invoice. |
|
150 | + return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : ''; |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * Retrieves the company. |
|
155 | + * |
|
156 | + * @param GetPaid_Payment_Form_Submission $submission |
|
157 | + * @since 1.0.19 |
|
158 | + * @return string |
|
159 | + */ |
|
160 | + public function get_company( $submission ) { |
|
161 | + |
|
162 | + // Retrieve from the posted data. |
|
163 | + $company = $submission->get_field( 'wpinv_company', 'billing' ); |
|
164 | + if ( ! empty( $company ) ) { |
|
165 | + return wpinv_clean( $company ); |
|
166 | + } |
|
167 | + |
|
168 | + // Retrieve from the invoice. |
|
169 | + return $submission->has_invoice() ? $submission->get_invoice()->get_company() : ''; |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * Checks if we require a VAT number. |
|
174 | + * |
|
175 | + * @param bool $ip_in_eu Whether the customer IP is from the EU |
|
176 | + * @param bool $country_in_eu Whether the customer country is from the EU |
|
177 | + * @since 1.0.19 |
|
178 | + * @return string |
|
179 | + */ |
|
180 | + public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
181 | + |
|
182 | + $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
183 | + $prevent_b2c = ! empty( $prevent_b2c ); |
|
184 | + $is_eu = $ip_in_eu || $country_in_eu; |
|
185 | + |
|
186 | + return $prevent_b2c && $is_eu; |
|
187 | + } |
|
188 | + |
|
189 | + /** |
|
190 | + * Validate VAT data. |
|
191 | + * |
|
192 | + * @param GetPaid_Payment_Form_Submission $submission |
|
193 | + * @since 1.0.19 |
|
194 | + */ |
|
195 | + public function validate_vat( $submission ) { |
|
196 | + |
|
197 | + $in_eu = $this->is_eu_transaction( $submission->country ); |
|
198 | + |
|
199 | + // Abort if we are not validating vat numbers. |
|
200 | + if ( ! $in_eu ) { |
|
201 | 201 | return; |
202 | - } |
|
202 | + } |
|
203 | 203 | |
204 | - // Prepare variables. |
|
205 | - $vat_number = $this->get_vat_number( $submission ); |
|
206 | - $ip_country = getpaid_get_ip_country(); |
|
204 | + // Prepare variables. |
|
205 | + $vat_number = $this->get_vat_number( $submission ); |
|
206 | + $ip_country = getpaid_get_ip_country(); |
|
207 | 207 | $is_eu = $this->is_eu_country( $submission->country ); |
208 | 208 | $is_ip_eu = $this->is_eu_country( $ip_country ); |
209 | 209 | |
210 | - // Maybe abort early for initial fetches. |
|
211 | - if ( $submission->is_initial_fetch() && empty( $vat_number ) ) { |
|
212 | - return; |
|
213 | - } |
|
210 | + // Maybe abort early for initial fetches. |
|
211 | + if ( $submission->is_initial_fetch() && empty( $vat_number ) ) { |
|
212 | + return; |
|
213 | + } |
|
214 | 214 | |
215 | - // If we're preventing business to consumer purchases, |
|
216 | - if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
215 | + // If we're preventing business to consumer purchases, |
|
216 | + if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
217 | 217 | |
218 | - // Ensure that a vat number has been specified. |
|
219 | - throw new Exception( |
|
220 | - __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) |
|
221 | - ); |
|
218 | + // Ensure that a vat number has been specified. |
|
219 | + throw new Exception( |
|
220 | + __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) |
|
221 | + ); |
|
222 | 222 | |
223 | - } |
|
223 | + } |
|
224 | 224 | |
225 | - if ( empty( $vat_number ) ) { |
|
226 | - return; |
|
227 | - } |
|
225 | + if ( empty( $vat_number ) ) { |
|
226 | + return; |
|
227 | + } |
|
228 | 228 | |
229 | - if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) { |
|
230 | - throw new Exception( __( 'Your VAT number is invalid', 'invoicing' ) ); |
|
231 | - } |
|
229 | + if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) { |
|
230 | + throw new Exception( __( 'Your VAT number is invalid', 'invoicing' ) ); |
|
231 | + } |
|
232 | 232 | |
233 | - if ( wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { |
|
234 | - return; |
|
235 | - } |
|
233 | + if ( wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { |
|
234 | + return; |
|
235 | + } |
|
236 | 236 | |
237 | - $this->skip_taxes = true; |
|
238 | - } |
|
237 | + $this->skip_taxes = true; |
|
238 | + } |
|
239 | 239 | |
240 | 240 | } |
@@ -24,64 +24,64 @@ discard block |
||
24 | 24 | |
25 | 25 | <?php |
26 | 26 | |
27 | - // Fires before printing a line item column. |
|
28 | - do_action( "getpaid_form_cart_item_before_$key", $item, $form ); |
|
27 | + // Fires before printing a line item column. |
|
28 | + do_action( "getpaid_form_cart_item_before_$key", $item, $form ); |
|
29 | 29 | |
30 | - // Item name. |
|
31 | - if ( 'name' == $key ) { |
|
30 | + // Item name. |
|
31 | + if ( 'name' == $key ) { |
|
32 | 32 | |
33 | - // Display the name. |
|
34 | - echo '<div class="mb-1">' . sanitize_text_field( $item->get_name() ) . '</div>'; |
|
33 | + // Display the name. |
|
34 | + echo '<div class="mb-1">' . sanitize_text_field( $item->get_name() ) . '</div>'; |
|
35 | 35 | |
36 | - // And an optional description. |
|
36 | + // And an optional description. |
|
37 | 37 | $description = $item->get_description(); |
38 | 38 | |
39 | 39 | if ( ! empty( $description ) ) { |
40 | 40 | $description = wp_kses_post( $description ); |
41 | 41 | echo "<small class='form-text text-muted pr-2 m-0'>$description</small>"; |
42 | - } |
|
42 | + } |
|
43 | 43 | |
44 | - // Price help text. |
|
44 | + // Price help text. |
|
45 | 45 | $description = getpaid_item_recurring_price_help_text( $item, $currency ); |
46 | 46 | if ( $description ) { |
47 | 47 | echo "<small class='getpaid-form-item-price-desc form-text text-muted pr-2 m-0'>$description</small>"; |
48 | - } |
|
48 | + } |
|
49 | 49 | |
50 | - } |
|
50 | + } |
|
51 | 51 | |
52 | - // Item price. |
|
53 | - if ( 'price' == $key ) { |
|
52 | + // Item price. |
|
53 | + if ( 'price' == $key ) { |
|
54 | 54 | |
55 | - // Set the currency position. |
|
56 | - $position = wpinv_currency_position(); |
|
55 | + // Set the currency position. |
|
56 | + $position = wpinv_currency_position(); |
|
57 | 57 | |
58 | - if ( $position == 'left_space' ) { |
|
59 | - $position = 'left'; |
|
60 | - } |
|
58 | + if ( $position == 'left_space' ) { |
|
59 | + $position = 'left'; |
|
60 | + } |
|
61 | 61 | |
62 | - if ( $position == 'right_space' ) { |
|
63 | - $position = 'right'; |
|
64 | - } |
|
62 | + if ( $position == 'right_space' ) { |
|
63 | + $position = 'right'; |
|
64 | + } |
|
65 | 65 | |
66 | - if ( $item->user_can_set_their_price() ) { |
|
67 | - $price = max( (float) $item->get_price(), (float) $item->get_minimum_price() ); |
|
68 | - $minimum = (float) $item->get_minimum_price(); |
|
69 | - $validate_minimum = ''; |
|
70 | - $class = ''; |
|
71 | - $data_minimum = ''; |
|
66 | + if ( $item->user_can_set_their_price() ) { |
|
67 | + $price = max( (float) $item->get_price(), (float) $item->get_minimum_price() ); |
|
68 | + $minimum = (float) $item->get_minimum_price(); |
|
69 | + $validate_minimum = ''; |
|
70 | + $class = ''; |
|
71 | + $data_minimum = ''; |
|
72 | 72 | |
73 | - if ( $minimum > 0 ) { |
|
74 | - $validate_minimum = sprintf( |
|
75 | - esc_attr__( 'The minimum allowed amount is %s', 'invoicing' ), |
|
76 | - sanitize_text_field( wpinv_price( $minimum, $currency ) ) |
|
77 | - ); |
|
73 | + if ( $minimum > 0 ) { |
|
74 | + $validate_minimum = sprintf( |
|
75 | + esc_attr__( 'The minimum allowed amount is %s', 'invoicing' ), |
|
76 | + sanitize_text_field( wpinv_price( $minimum, $currency ) ) |
|
77 | + ); |
|
78 | 78 | |
79 | - $class = 'getpaid-validate-minimum-amount'; |
|
79 | + $class = 'getpaid-validate-minimum-amount'; |
|
80 | 80 | |
81 | - $data_minimum = "data-minimum-amount='$minimum'"; |
|
82 | - } |
|
81 | + $data_minimum = "data-minimum-amount='$minimum'"; |
|
82 | + } |
|
83 | 83 | |
84 | - ?> |
|
84 | + ?> |
|
85 | 85 | <div class="input-group input-group-sm"> |
86 | 86 | <?php if( 'left' == $position ) : ?> |
87 | 87 | <div class="input-group-prepend"> |
@@ -105,37 +105,37 @@ discard block |
||
105 | 105 | </div> |
106 | 106 | |
107 | 107 | <?php |
108 | - } else { |
|
109 | - echo wpinv_price( $item->get_price(), $currency ); |
|
110 | - ?> |
|
108 | + } else { |
|
109 | + echo wpinv_price( $item->get_price(), $currency ); |
|
110 | + ?> |
|
111 | 111 | <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() ); ?>'> |
112 | 112 | <?php |
113 | - } |
|
114 | - } |
|
113 | + } |
|
114 | + } |
|
115 | 115 | |
116 | - // Item quantity. |
|
117 | - if ( 'quantity' == $key ) { |
|
116 | + // Item quantity. |
|
117 | + if ( 'quantity' == $key ) { |
|
118 | 118 | |
119 | - if ( $item->allows_quantities() ) { |
|
120 | - ?> |
|
119 | + if ( $item->allows_quantities() ) { |
|
120 | + ?> |
|
121 | 121 | <input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][quantity]' type='text' 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(); ?>' min='1' required> |
122 | 122 | <?php |
123 | - } else { |
|
124 | - echo (float) $item->get_quantity(); |
|
125 | - echo ' '; |
|
126 | - ?> |
|
123 | + } else { |
|
124 | + echo (float) $item->get_quantity(); |
|
125 | + echo ' '; |
|
126 | + ?> |
|
127 | 127 | <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(); ?>'> |
128 | 128 | <?php |
129 | - } |
|
130 | - } |
|
129 | + } |
|
130 | + } |
|
131 | 131 | |
132 | - // Item sub total. |
|
133 | - if ( 'subtotal' == $key ) { |
|
134 | - echo wpinv_price( $item->get_sub_total(), $currency ); |
|
135 | - } |
|
132 | + // Item sub total. |
|
133 | + if ( 'subtotal' == $key ) { |
|
134 | + echo wpinv_price( $item->get_sub_total(), $currency ); |
|
135 | + } |
|
136 | 136 | |
137 | - do_action( "getpaid_payment_form_cart_item_$key", $item, $form ); |
|
138 | - ?> |
|
137 | + do_action( "getpaid_payment_form_cart_item_$key", $item, $form ); |
|
138 | + ?> |
|
139 | 139 | |
140 | 140 | </div> |
141 | 141 |
@@ -7,40 +7,40 @@ |
||
7 | 7 | * Bail if we are not in WP. |
8 | 8 | */ |
9 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
10 | - exit; |
|
10 | + exit; |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | /** |
14 | 14 | * Set the version only if its the current newest while loading. |
15 | 15 | */ |
16 | 16 | add_action('after_setup_theme', function () { |
17 | - global $ayecode_ui_version,$ayecode_ui_file_key; |
|
18 | - $this_version = "0.1.43"; |
|
19 | - if(version_compare($this_version , $ayecode_ui_version, '>')){ |
|
20 | - $ayecode_ui_version = $this_version ; |
|
21 | - $ayecode_ui_file_key = wp_hash( __FILE__ ); |
|
22 | - } |
|
17 | + global $ayecode_ui_version,$ayecode_ui_file_key; |
|
18 | + $this_version = "0.1.43"; |
|
19 | + if(version_compare($this_version , $ayecode_ui_version, '>')){ |
|
20 | + $ayecode_ui_version = $this_version ; |
|
21 | + $ayecode_ui_file_key = wp_hash( __FILE__ ); |
|
22 | + } |
|
23 | 23 | },0); |
24 | 24 | |
25 | 25 | /** |
26 | 26 | * Load this version of WP Bootstrap Settings only if the file hash is the current one. |
27 | 27 | */ |
28 | 28 | add_action('after_setup_theme', function () { |
29 | - global $ayecode_ui_file_key; |
|
30 | - if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){ |
|
31 | - include_once( dirname( __FILE__ ) . '/includes/class-aui.php' ); |
|
32 | - include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' ); |
|
33 | - } |
|
29 | + global $ayecode_ui_file_key; |
|
30 | + if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){ |
|
31 | + include_once( dirname( __FILE__ ) . '/includes/class-aui.php' ); |
|
32 | + include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' ); |
|
33 | + } |
|
34 | 34 | },1); |
35 | 35 | |
36 | 36 | /** |
37 | 37 | * Add the function that calls the class. |
38 | 38 | */ |
39 | 39 | if(!function_exists('aui')){ |
40 | - function aui(){ |
|
41 | - if(!class_exists("AUI",false)){ |
|
42 | - return false; |
|
43 | - } |
|
44 | - return AUI::instance(); |
|
45 | - } |
|
40 | + function aui(){ |
|
41 | + if(!class_exists("AUI",false)){ |
|
42 | + return false; |
|
43 | + } |
|
44 | + return AUI::instance(); |
|
45 | + } |
|
46 | 46 | } |
47 | 47 | \ No newline at end of file |
@@ -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,235 +21,235 @@ discard block |
||
21 | 21 | */ |
22 | 22 | if ( ! class_exists( 'AyeCode_UI_Settings' ) ) { |
23 | 23 | |
24 | - /** |
|
25 | - * A Class to be able to change settings for Font Awesome. |
|
26 | - * |
|
27 | - * Class AyeCode_UI_Settings |
|
28 | - * @ver 1.0.0 |
|
29 | - * @todo decide how to implement textdomain |
|
30 | - */ |
|
31 | - class AyeCode_UI_Settings { |
|
32 | - |
|
33 | - /** |
|
34 | - * Class version version. |
|
35 | - * |
|
36 | - * @var string |
|
37 | - */ |
|
38 | - public $version = '0.1.43'; |
|
39 | - |
|
40 | - /** |
|
41 | - * Class textdomain. |
|
42 | - * |
|
43 | - * @var string |
|
44 | - */ |
|
45 | - public $textdomain = 'aui'; |
|
46 | - |
|
47 | - /** |
|
48 | - * Latest version of Bootstrap at time of publish published. |
|
49 | - * |
|
50 | - * @var string |
|
51 | - */ |
|
52 | - public $latest = "4.5.3"; |
|
53 | - |
|
54 | - /** |
|
55 | - * Current version of select2 being used. |
|
56 | - * |
|
57 | - * @var string |
|
58 | - */ |
|
59 | - public $select2_version = "4.0.11"; |
|
60 | - |
|
61 | - /** |
|
62 | - * The title. |
|
63 | - * |
|
64 | - * @var string |
|
65 | - */ |
|
66 | - public $name = 'AyeCode UI'; |
|
67 | - |
|
68 | - /** |
|
69 | - * The relative url to the assets. |
|
70 | - * |
|
71 | - * @var string |
|
72 | - */ |
|
73 | - public $url = ''; |
|
74 | - |
|
75 | - /** |
|
76 | - * Holds the settings values. |
|
77 | - * |
|
78 | - * @var array |
|
79 | - */ |
|
80 | - private $settings; |
|
81 | - |
|
82 | - /** |
|
83 | - * AyeCode_UI_Settings instance. |
|
84 | - * |
|
85 | - * @access private |
|
86 | - * @since 1.0.0 |
|
87 | - * @var AyeCode_UI_Settings There can be only one! |
|
88 | - */ |
|
89 | - private static $instance = null; |
|
90 | - |
|
91 | - /** |
|
92 | - * Main AyeCode_UI_Settings Instance. |
|
93 | - * |
|
94 | - * Ensures only one instance of AyeCode_UI_Settings is loaded or can be loaded. |
|
95 | - * |
|
96 | - * @since 1.0.0 |
|
97 | - * @static |
|
98 | - * @return AyeCode_UI_Settings - Main instance. |
|
99 | - */ |
|
100 | - public static function instance() { |
|
101 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_UI_Settings ) ) { |
|
102 | - |
|
103 | - self::$instance = new AyeCode_UI_Settings; |
|
104 | - |
|
105 | - add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
106 | - |
|
107 | - if ( is_admin() ) { |
|
108 | - add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
109 | - add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
110 | - |
|
111 | - // Maybe show example page |
|
112 | - add_action( 'template_redirect', array( self::$instance,'maybe_show_examples' ) ); |
|
113 | - } |
|
24 | + /** |
|
25 | + * A Class to be able to change settings for Font Awesome. |
|
26 | + * |
|
27 | + * Class AyeCode_UI_Settings |
|
28 | + * @ver 1.0.0 |
|
29 | + * @todo decide how to implement textdomain |
|
30 | + */ |
|
31 | + class AyeCode_UI_Settings { |
|
32 | + |
|
33 | + /** |
|
34 | + * Class version version. |
|
35 | + * |
|
36 | + * @var string |
|
37 | + */ |
|
38 | + public $version = '0.1.43'; |
|
39 | + |
|
40 | + /** |
|
41 | + * Class textdomain. |
|
42 | + * |
|
43 | + * @var string |
|
44 | + */ |
|
45 | + public $textdomain = 'aui'; |
|
46 | + |
|
47 | + /** |
|
48 | + * Latest version of Bootstrap at time of publish published. |
|
49 | + * |
|
50 | + * @var string |
|
51 | + */ |
|
52 | + public $latest = "4.5.3"; |
|
53 | + |
|
54 | + /** |
|
55 | + * Current version of select2 being used. |
|
56 | + * |
|
57 | + * @var string |
|
58 | + */ |
|
59 | + public $select2_version = "4.0.11"; |
|
60 | + |
|
61 | + /** |
|
62 | + * The title. |
|
63 | + * |
|
64 | + * @var string |
|
65 | + */ |
|
66 | + public $name = 'AyeCode UI'; |
|
67 | + |
|
68 | + /** |
|
69 | + * The relative url to the assets. |
|
70 | + * |
|
71 | + * @var string |
|
72 | + */ |
|
73 | + public $url = ''; |
|
74 | + |
|
75 | + /** |
|
76 | + * Holds the settings values. |
|
77 | + * |
|
78 | + * @var array |
|
79 | + */ |
|
80 | + private $settings; |
|
81 | + |
|
82 | + /** |
|
83 | + * AyeCode_UI_Settings instance. |
|
84 | + * |
|
85 | + * @access private |
|
86 | + * @since 1.0.0 |
|
87 | + * @var AyeCode_UI_Settings There can be only one! |
|
88 | + */ |
|
89 | + private static $instance = null; |
|
90 | + |
|
91 | + /** |
|
92 | + * Main AyeCode_UI_Settings Instance. |
|
93 | + * |
|
94 | + * Ensures only one instance of AyeCode_UI_Settings is loaded or can be loaded. |
|
95 | + * |
|
96 | + * @since 1.0.0 |
|
97 | + * @static |
|
98 | + * @return AyeCode_UI_Settings - Main instance. |
|
99 | + */ |
|
100 | + public static function instance() { |
|
101 | + if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_UI_Settings ) ) { |
|
102 | + |
|
103 | + self::$instance = new AyeCode_UI_Settings; |
|
104 | + |
|
105 | + add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
106 | + |
|
107 | + if ( is_admin() ) { |
|
108 | + add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
109 | + add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
110 | + |
|
111 | + // Maybe show example page |
|
112 | + add_action( 'template_redirect', array( self::$instance,'maybe_show_examples' ) ); |
|
113 | + } |
|
114 | 114 | |
115 | - add_action( 'customize_register', array( self::$instance, 'customizer_settings' )); |
|
116 | - |
|
117 | - do_action( 'ayecode_ui_settings_loaded' ); |
|
118 | - } |
|
119 | - |
|
120 | - return self::$instance; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Setup some constants. |
|
125 | - */ |
|
126 | - public function constants(){ |
|
127 | - define('AUI_PRIMARY_COLOR_ORIGINAL', "#1e73be"); |
|
128 | - define('AUI_SECONDARY_COLOR_ORIGINAL', '#6c757d'); |
|
129 | - if (!defined('AUI_PRIMARY_COLOR')) define('AUI_PRIMARY_COLOR', AUI_PRIMARY_COLOR_ORIGINAL); |
|
130 | - if (!defined('AUI_SECONDARY_COLOR')) define('AUI_SECONDARY_COLOR', AUI_SECONDARY_COLOR_ORIGINAL); |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Initiate the settings and add the required action hooks. |
|
135 | - */ |
|
136 | - public function init() { |
|
137 | - $this->constants(); |
|
138 | - $this->settings = $this->get_settings(); |
|
139 | - $this->url = $this->get_url(); |
|
140 | - |
|
141 | - /** |
|
142 | - * Maybe load CSS |
|
143 | - * |
|
144 | - * We load super early in case there is a theme version that might change the colors |
|
145 | - */ |
|
146 | - if ( $this->settings['css'] ) { |
|
147 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 1 ); |
|
148 | - } |
|
149 | - if ( $this->settings['css_backend'] && $this->load_admin_scripts() ) { |
|
150 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 1 ); |
|
151 | - } |
|
152 | - |
|
153 | - // maybe load JS |
|
154 | - if ( $this->settings['js'] ) { |
|
155 | - $priority = $this->is_bs3_compat() ? 100 : 1; |
|
156 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), $priority ); |
|
157 | - } |
|
158 | - if ( $this->settings['js_backend'] && $this->load_admin_scripts() ) { |
|
159 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 ); |
|
160 | - } |
|
161 | - |
|
162 | - // Maybe set the HTML font size |
|
163 | - if ( $this->settings['html_font_size'] ) { |
|
164 | - add_action( 'wp_footer', array( $this, 'html_font_size' ), 10 ); |
|
165 | - } |
|
166 | - |
|
167 | - |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Check if we should load the admin scripts or not. |
|
172 | - * |
|
173 | - * @return bool |
|
174 | - */ |
|
175 | - public function load_admin_scripts(){ |
|
176 | - $result = true; |
|
177 | - |
|
178 | - // check if specifically disabled |
|
179 | - if(!empty($this->settings['disable_admin'])){ |
|
180 | - $url_parts = explode("\n",$this->settings['disable_admin']); |
|
181 | - foreach($url_parts as $part){ |
|
182 | - if( strpos($_SERVER['REQUEST_URI'], trim($part)) !== false ){ |
|
183 | - return false; // return early, no point checking further |
|
184 | - } |
|
185 | - } |
|
186 | - } |
|
187 | - |
|
188 | - return $result; |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * Add a html font size to the footer. |
|
193 | - */ |
|
194 | - public function html_font_size(){ |
|
195 | - $this->settings = $this->get_settings(); |
|
196 | - echo "<style>html{font-size:".absint($this->settings['html_font_size'])."px;}</style>"; |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * Check if the current admin screen should load scripts. |
|
201 | - * |
|
202 | - * @return bool |
|
203 | - */ |
|
204 | - public function is_aui_screen(){ |
|
205 | - $load = false; |
|
206 | - // check if we should load or not |
|
207 | - if ( is_admin() ) { |
|
208 | - // Only enable on set pages |
|
209 | - $aui_screens = array( |
|
210 | - 'page', |
|
211 | - 'post', |
|
212 | - 'settings_page_ayecode-ui-settings' |
|
213 | - ); |
|
214 | - $screen_ids = apply_filters( 'aui_screen_ids', $aui_screens ); |
|
215 | - |
|
216 | - $screen = get_current_screen(); |
|
115 | + add_action( 'customize_register', array( self::$instance, 'customizer_settings' )); |
|
116 | + |
|
117 | + do_action( 'ayecode_ui_settings_loaded' ); |
|
118 | + } |
|
119 | + |
|
120 | + return self::$instance; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Setup some constants. |
|
125 | + */ |
|
126 | + public function constants(){ |
|
127 | + define('AUI_PRIMARY_COLOR_ORIGINAL', "#1e73be"); |
|
128 | + define('AUI_SECONDARY_COLOR_ORIGINAL', '#6c757d'); |
|
129 | + if (!defined('AUI_PRIMARY_COLOR')) define('AUI_PRIMARY_COLOR', AUI_PRIMARY_COLOR_ORIGINAL); |
|
130 | + if (!defined('AUI_SECONDARY_COLOR')) define('AUI_SECONDARY_COLOR', AUI_SECONDARY_COLOR_ORIGINAL); |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Initiate the settings and add the required action hooks. |
|
135 | + */ |
|
136 | + public function init() { |
|
137 | + $this->constants(); |
|
138 | + $this->settings = $this->get_settings(); |
|
139 | + $this->url = $this->get_url(); |
|
140 | + |
|
141 | + /** |
|
142 | + * Maybe load CSS |
|
143 | + * |
|
144 | + * We load super early in case there is a theme version that might change the colors |
|
145 | + */ |
|
146 | + if ( $this->settings['css'] ) { |
|
147 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 1 ); |
|
148 | + } |
|
149 | + if ( $this->settings['css_backend'] && $this->load_admin_scripts() ) { |
|
150 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 1 ); |
|
151 | + } |
|
152 | + |
|
153 | + // maybe load JS |
|
154 | + if ( $this->settings['js'] ) { |
|
155 | + $priority = $this->is_bs3_compat() ? 100 : 1; |
|
156 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), $priority ); |
|
157 | + } |
|
158 | + if ( $this->settings['js_backend'] && $this->load_admin_scripts() ) { |
|
159 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 ); |
|
160 | + } |
|
161 | + |
|
162 | + // Maybe set the HTML font size |
|
163 | + if ( $this->settings['html_font_size'] ) { |
|
164 | + add_action( 'wp_footer', array( $this, 'html_font_size' ), 10 ); |
|
165 | + } |
|
166 | + |
|
167 | + |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * Check if we should load the admin scripts or not. |
|
172 | + * |
|
173 | + * @return bool |
|
174 | + */ |
|
175 | + public function load_admin_scripts(){ |
|
176 | + $result = true; |
|
177 | + |
|
178 | + // check if specifically disabled |
|
179 | + if(!empty($this->settings['disable_admin'])){ |
|
180 | + $url_parts = explode("\n",$this->settings['disable_admin']); |
|
181 | + foreach($url_parts as $part){ |
|
182 | + if( strpos($_SERVER['REQUEST_URI'], trim($part)) !== false ){ |
|
183 | + return false; // return early, no point checking further |
|
184 | + } |
|
185 | + } |
|
186 | + } |
|
187 | + |
|
188 | + return $result; |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * Add a html font size to the footer. |
|
193 | + */ |
|
194 | + public function html_font_size(){ |
|
195 | + $this->settings = $this->get_settings(); |
|
196 | + echo "<style>html{font-size:".absint($this->settings['html_font_size'])."px;}</style>"; |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * Check if the current admin screen should load scripts. |
|
201 | + * |
|
202 | + * @return bool |
|
203 | + */ |
|
204 | + public function is_aui_screen(){ |
|
205 | + $load = false; |
|
206 | + // check if we should load or not |
|
207 | + if ( is_admin() ) { |
|
208 | + // Only enable on set pages |
|
209 | + $aui_screens = array( |
|
210 | + 'page', |
|
211 | + 'post', |
|
212 | + 'settings_page_ayecode-ui-settings' |
|
213 | + ); |
|
214 | + $screen_ids = apply_filters( 'aui_screen_ids', $aui_screens ); |
|
215 | + |
|
216 | + $screen = get_current_screen(); |
|
217 | 217 | |
218 | 218 | // echo '###'.$screen->id; |
219 | 219 | |
220 | - if ( $screen && in_array( $screen->id, $screen_ids ) ) { |
|
221 | - $load = true; |
|
222 | - } |
|
223 | - } |
|
220 | + if ( $screen && in_array( $screen->id, $screen_ids ) ) { |
|
221 | + $load = true; |
|
222 | + } |
|
223 | + } |
|
224 | 224 | |
225 | - return $load; |
|
226 | - } |
|
225 | + return $load; |
|
226 | + } |
|
227 | 227 | |
228 | - /** |
|
229 | - * Adds the styles. |
|
230 | - */ |
|
231 | - public function enqueue_style() { |
|
228 | + /** |
|
229 | + * Adds the styles. |
|
230 | + */ |
|
231 | + public function enqueue_style() { |
|
232 | 232 | |
233 | - if( is_admin() && !$this->is_aui_screen()){ |
|
234 | - // don't add wp-admin scripts if not requested to |
|
235 | - }else{ |
|
236 | - $css_setting = current_action() == 'wp_enqueue_scripts' ? 'css' : 'css_backend'; |
|
233 | + if( is_admin() && !$this->is_aui_screen()){ |
|
234 | + // don't add wp-admin scripts if not requested to |
|
235 | + }else{ |
|
236 | + $css_setting = current_action() == 'wp_enqueue_scripts' ? 'css' : 'css_backend'; |
|
237 | 237 | |
238 | - $rtl = is_rtl() ? '-rtl' : ''; |
|
238 | + $rtl = is_rtl() ? '-rtl' : ''; |
|
239 | 239 | |
240 | - if($this->settings[$css_setting]){ |
|
241 | - $compatibility = $this->settings[$css_setting]=='core' ? false : true; |
|
242 | - $url = $this->settings[$css_setting]=='core' ? $this->url.'assets/css/ayecode-ui'.$rtl.'.css' : $this->url.'assets/css/ayecode-ui-compatibility'.$rtl.'.css'; |
|
243 | - wp_register_style( 'ayecode-ui', $url, array(), $this->latest ); |
|
244 | - wp_enqueue_style( 'ayecode-ui' ); |
|
240 | + if($this->settings[$css_setting]){ |
|
241 | + $compatibility = $this->settings[$css_setting]=='core' ? false : true; |
|
242 | + $url = $this->settings[$css_setting]=='core' ? $this->url.'assets/css/ayecode-ui'.$rtl.'.css' : $this->url.'assets/css/ayecode-ui-compatibility'.$rtl.'.css'; |
|
243 | + wp_register_style( 'ayecode-ui', $url, array(), $this->latest ); |
|
244 | + wp_enqueue_style( 'ayecode-ui' ); |
|
245 | 245 | |
246 | - // flatpickr |
|
247 | - wp_register_style( 'flatpickr', $this->url.'assets/css/flatpickr.min.css', array(), $this->latest ); |
|
246 | + // flatpickr |
|
247 | + wp_register_style( 'flatpickr', $this->url.'assets/css/flatpickr.min.css', array(), $this->latest ); |
|
248 | 248 | |
249 | 249 | |
250 | - // fix some wp-admin issues |
|
251 | - if(is_admin()){ |
|
252 | - $custom_css = " |
|
250 | + // fix some wp-admin issues |
|
251 | + if(is_admin()){ |
|
252 | + $custom_css = " |
|
253 | 253 | body{ |
254 | 254 | background-color: #f1f1f1; |
255 | 255 | font-family: -apple-system,BlinkMacSystemFont,\"Segoe UI\",Roboto,Oxygen-Sans,Ubuntu,Cantarell,\"Helvetica Neue\",sans-serif; |
@@ -285,32 +285,32 @@ discard block |
||
285 | 285 | } |
286 | 286 | "; |
287 | 287 | |
288 | - // @todo, remove once fixed :: fix for this bug https://github.com/WordPress/gutenberg/issues/14377 |
|
289 | - $custom_css .= " |
|
288 | + // @todo, remove once fixed :: fix for this bug https://github.com/WordPress/gutenberg/issues/14377 |
|
289 | + $custom_css .= " |
|
290 | 290 | .edit-post-sidebar input[type=color].components-text-control__input{ |
291 | 291 | padding: 0; |
292 | 292 | } |
293 | 293 | "; |
294 | - wp_add_inline_style( 'ayecode-ui', $custom_css ); |
|
295 | - } |
|
294 | + wp_add_inline_style( 'ayecode-ui', $custom_css ); |
|
295 | + } |
|
296 | 296 | |
297 | - // custom changes |
|
298 | - wp_add_inline_style( 'ayecode-ui', self::custom_css($compatibility) ); |
|
297 | + // custom changes |
|
298 | + wp_add_inline_style( 'ayecode-ui', self::custom_css($compatibility) ); |
|
299 | 299 | |
300 | - } |
|
301 | - } |
|
300 | + } |
|
301 | + } |
|
302 | 302 | |
303 | 303 | |
304 | - } |
|
304 | + } |
|
305 | 305 | |
306 | - /** |
|
307 | - * Get inline script used if bootstrap enqueued |
|
308 | - * |
|
309 | - * If this remains small then its best to use this than to add another JS file. |
|
310 | - */ |
|
311 | - public function inline_script(){ |
|
312 | - ob_start(); |
|
313 | - ?> |
|
306 | + /** |
|
307 | + * Get inline script used if bootstrap enqueued |
|
308 | + * |
|
309 | + * If this remains small then its best to use this than to add another JS file. |
|
310 | + */ |
|
311 | + public function inline_script(){ |
|
312 | + ob_start(); |
|
313 | + ?> |
|
314 | 314 | <script> |
315 | 315 | |
316 | 316 | /** |
@@ -802,27 +802,27 @@ discard block |
||
802 | 802 | |
803 | 803 | </script> |
804 | 804 | <?php |
805 | - $output = ob_get_clean(); |
|
805 | + $output = ob_get_clean(); |
|
806 | 806 | |
807 | - /* |
|
807 | + /* |
|
808 | 808 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
809 | 809 | */ |
810 | - return str_replace( array( |
|
811 | - '<script>', |
|
812 | - '</script>' |
|
813 | - ), '', $output ); |
|
814 | - } |
|
815 | - |
|
816 | - |
|
817 | - /** |
|
818 | - * JS to help with conflict issues with other plugins and themes using bootstrap v3. |
|
819 | - * |
|
820 | - * @TODO we may need this when other conflicts arrise. |
|
821 | - * @return mixed |
|
822 | - */ |
|
823 | - public static function bs3_compat_js() { |
|
824 | - ob_start(); |
|
825 | - ?> |
|
810 | + return str_replace( array( |
|
811 | + '<script>', |
|
812 | + '</script>' |
|
813 | + ), '', $output ); |
|
814 | + } |
|
815 | + |
|
816 | + |
|
817 | + /** |
|
818 | + * JS to help with conflict issues with other plugins and themes using bootstrap v3. |
|
819 | + * |
|
820 | + * @TODO we may need this when other conflicts arrise. |
|
821 | + * @return mixed |
|
822 | + */ |
|
823 | + public static function bs3_compat_js() { |
|
824 | + ob_start(); |
|
825 | + ?> |
|
826 | 826 | <script> |
827 | 827 | <?php if( defined( 'FUSION_BUILDER_VERSION' ) ){ ?> |
828 | 828 | /* With Avada builder */ |
@@ -830,20 +830,20 @@ discard block |
||
830 | 830 | <?php } ?> |
831 | 831 | </script> |
832 | 832 | <?php |
833 | - return str_replace( array( |
|
834 | - '<script>', |
|
835 | - '</script>' |
|
836 | - ), '', ob_get_clean()); |
|
837 | - } |
|
838 | - |
|
839 | - /** |
|
840 | - * Get inline script used if bootstrap file browser enqueued. |
|
841 | - * |
|
842 | - * If this remains small then its best to use this than to add another JS file. |
|
843 | - */ |
|
844 | - public function inline_script_file_browser(){ |
|
845 | - ob_start(); |
|
846 | - ?> |
|
833 | + return str_replace( array( |
|
834 | + '<script>', |
|
835 | + '</script>' |
|
836 | + ), '', ob_get_clean()); |
|
837 | + } |
|
838 | + |
|
839 | + /** |
|
840 | + * Get inline script used if bootstrap file browser enqueued. |
|
841 | + * |
|
842 | + * If this remains small then its best to use this than to add another JS file. |
|
843 | + */ |
|
844 | + public function inline_script_file_browser(){ |
|
845 | + ob_start(); |
|
846 | + ?> |
|
847 | 847 | <script> |
848 | 848 | // run on doc ready |
849 | 849 | jQuery(document).ready(function () { |
@@ -851,192 +851,192 @@ discard block |
||
851 | 851 | }); |
852 | 852 | </script> |
853 | 853 | <?php |
854 | - $output = ob_get_clean(); |
|
854 | + $output = ob_get_clean(); |
|
855 | 855 | |
856 | - /* |
|
856 | + /* |
|
857 | 857 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
858 | 858 | */ |
859 | - return str_replace( array( |
|
860 | - '<script>', |
|
861 | - '</script>' |
|
862 | - ), '', $output ); |
|
863 | - } |
|
864 | - |
|
865 | - /** |
|
866 | - * Adds the Font Awesome JS. |
|
867 | - */ |
|
868 | - public function enqueue_scripts() { |
|
869 | - |
|
870 | - if( is_admin() && !$this->is_aui_screen()){ |
|
871 | - // don't add wp-admin scripts if not requested to |
|
872 | - }else { |
|
873 | - |
|
874 | - $js_setting = current_action() == 'wp_enqueue_scripts' ? 'js' : 'js_backend'; |
|
875 | - |
|
876 | - // select2 |
|
877 | - wp_register_script( 'select2', $this->url . 'assets/js/select2.min.js', array( 'jquery' ), $this->select2_version ); |
|
878 | - |
|
879 | - // flatpickr |
|
880 | - wp_register_script( 'flatpickr', $this->url . 'assets/js/flatpickr.min.js', array(), $this->latest ); |
|
881 | - |
|
882 | - // Bootstrap file browser |
|
883 | - wp_register_script( 'aui-custom-file-input', $url = $this->url . 'assets/js/bs-custom-file-input.min.js', array( 'jquery' ), $this->select2_version ); |
|
884 | - wp_add_inline_script( 'aui-custom-file-input', $this->inline_script_file_browser() ); |
|
885 | - |
|
886 | - $load_inline = false; |
|
887 | - |
|
888 | - if ( $this->settings[ $js_setting ] == 'core-popper' ) { |
|
889 | - // Bootstrap bundle |
|
890 | - $url = $this->url . 'assets/js/bootstrap.bundle.min.js'; |
|
891 | - wp_register_script( 'bootstrap-js-bundle', $url, array( |
|
892 | - 'select2', |
|
893 | - 'jquery' |
|
894 | - ), $this->latest, $this->is_bs3_compat() ); |
|
895 | - // if in admin then add to footer for compatibility. |
|
896 | - is_admin() ? wp_enqueue_script( 'bootstrap-js-bundle', '', null, null, true ) : wp_enqueue_script( 'bootstrap-js-bundle' ); |
|
897 | - $script = $this->inline_script(); |
|
898 | - wp_add_inline_script( 'bootstrap-js-bundle', $script ); |
|
899 | - } elseif ( $this->settings[ $js_setting ] == 'popper' ) { |
|
900 | - $url = $this->url . 'assets/js/popper.min.js'; |
|
901 | - wp_register_script( 'bootstrap-js-popper', $url, array( 'select2', 'jquery' ), $this->latest ); |
|
902 | - wp_enqueue_script( 'bootstrap-js-popper' ); |
|
903 | - $load_inline = true; |
|
904 | - } else { |
|
905 | - $load_inline = true; |
|
906 | - } |
|
859 | + return str_replace( array( |
|
860 | + '<script>', |
|
861 | + '</script>' |
|
862 | + ), '', $output ); |
|
863 | + } |
|
864 | + |
|
865 | + /** |
|
866 | + * Adds the Font Awesome JS. |
|
867 | + */ |
|
868 | + public function enqueue_scripts() { |
|
869 | + |
|
870 | + if( is_admin() && !$this->is_aui_screen()){ |
|
871 | + // don't add wp-admin scripts if not requested to |
|
872 | + }else { |
|
873 | + |
|
874 | + $js_setting = current_action() == 'wp_enqueue_scripts' ? 'js' : 'js_backend'; |
|
875 | + |
|
876 | + // select2 |
|
877 | + wp_register_script( 'select2', $this->url . 'assets/js/select2.min.js', array( 'jquery' ), $this->select2_version ); |
|
878 | + |
|
879 | + // flatpickr |
|
880 | + wp_register_script( 'flatpickr', $this->url . 'assets/js/flatpickr.min.js', array(), $this->latest ); |
|
881 | + |
|
882 | + // Bootstrap file browser |
|
883 | + wp_register_script( 'aui-custom-file-input', $url = $this->url . 'assets/js/bs-custom-file-input.min.js', array( 'jquery' ), $this->select2_version ); |
|
884 | + wp_add_inline_script( 'aui-custom-file-input', $this->inline_script_file_browser() ); |
|
885 | + |
|
886 | + $load_inline = false; |
|
887 | + |
|
888 | + if ( $this->settings[ $js_setting ] == 'core-popper' ) { |
|
889 | + // Bootstrap bundle |
|
890 | + $url = $this->url . 'assets/js/bootstrap.bundle.min.js'; |
|
891 | + wp_register_script( 'bootstrap-js-bundle', $url, array( |
|
892 | + 'select2', |
|
893 | + 'jquery' |
|
894 | + ), $this->latest, $this->is_bs3_compat() ); |
|
895 | + // if in admin then add to footer for compatibility. |
|
896 | + is_admin() ? wp_enqueue_script( 'bootstrap-js-bundle', '', null, null, true ) : wp_enqueue_script( 'bootstrap-js-bundle' ); |
|
897 | + $script = $this->inline_script(); |
|
898 | + wp_add_inline_script( 'bootstrap-js-bundle', $script ); |
|
899 | + } elseif ( $this->settings[ $js_setting ] == 'popper' ) { |
|
900 | + $url = $this->url . 'assets/js/popper.min.js'; |
|
901 | + wp_register_script( 'bootstrap-js-popper', $url, array( 'select2', 'jquery' ), $this->latest ); |
|
902 | + wp_enqueue_script( 'bootstrap-js-popper' ); |
|
903 | + $load_inline = true; |
|
904 | + } else { |
|
905 | + $load_inline = true; |
|
906 | + } |
|
907 | 907 | |
908 | - // Load needed inline scripts by faking the loading of a script if the main script is not being loaded |
|
909 | - if ( $load_inline ) { |
|
910 | - wp_register_script( 'bootstrap-dummy', '', array( 'select2', 'jquery' ) ); |
|
911 | - wp_enqueue_script( 'bootstrap-dummy' ); |
|
912 | - $script = $this->inline_script(); |
|
913 | - wp_add_inline_script( 'bootstrap-dummy', $script ); |
|
914 | - } |
|
915 | - } |
|
916 | - |
|
917 | - } |
|
918 | - |
|
919 | - /** |
|
920 | - * Enqueue flatpickr if called. |
|
921 | - */ |
|
922 | - public function enqueue_flatpickr(){ |
|
923 | - wp_enqueue_style( 'flatpickr' ); |
|
924 | - wp_enqueue_script( 'flatpickr' ); |
|
925 | - } |
|
926 | - |
|
927 | - /** |
|
928 | - * Get the url path to the current folder. |
|
929 | - * |
|
930 | - * @return string |
|
931 | - */ |
|
932 | - public function get_url() { |
|
933 | - |
|
934 | - $url = ''; |
|
935 | - // check if we are inside a plugin |
|
936 | - $file_dir = str_replace( "/includes","", wp_normalize_path( dirname( __FILE__ ) ) ); |
|
937 | - |
|
938 | - // add check in-case user has changed wp-content dir name. |
|
939 | - $wp_content_folder_name = basename(WP_CONTENT_DIR); |
|
940 | - $dir_parts = explode("/$wp_content_folder_name/",$file_dir); |
|
941 | - $url_parts = explode("/$wp_content_folder_name/",plugins_url()); |
|
942 | - |
|
943 | - if(!empty($url_parts[0]) && !empty($dir_parts[1])){ |
|
944 | - $url = trailingslashit( $url_parts[0]."/$wp_content_folder_name/".$dir_parts[1] ); |
|
945 | - } |
|
946 | - |
|
947 | - return $url; |
|
948 | - } |
|
949 | - |
|
950 | - /** |
|
951 | - * Register the database settings with WordPress. |
|
952 | - */ |
|
953 | - public function register_settings() { |
|
954 | - register_setting( 'ayecode-ui-settings', 'ayecode-ui-settings' ); |
|
955 | - } |
|
956 | - |
|
957 | - /** |
|
958 | - * Add the WordPress settings menu item. |
|
959 | - * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
960 | - */ |
|
961 | - public function menu_item() { |
|
962 | - $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
963 | - call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'ayecode-ui-settings', array( |
|
964 | - $this, |
|
965 | - 'settings_page' |
|
966 | - ) ); |
|
967 | - } |
|
968 | - |
|
969 | - /** |
|
970 | - * Get a list of themes and their default JS settings. |
|
971 | - * |
|
972 | - * @return array |
|
973 | - */ |
|
974 | - public function theme_js_settings(){ |
|
975 | - return array( |
|
976 | - 'ayetheme' => 'popper', |
|
977 | - 'listimia' => 'required', |
|
978 | - 'listimia_backend' => 'core-popper', |
|
979 | - //'avada' => 'required', // removed as we now add compatibility |
|
980 | - ); |
|
981 | - } |
|
982 | - |
|
983 | - /** |
|
984 | - * Get the current Font Awesome output settings. |
|
985 | - * |
|
986 | - * @return array The array of settings. |
|
987 | - */ |
|
988 | - public function get_settings() { |
|
989 | - |
|
990 | - $db_settings = get_option( 'ayecode-ui-settings' ); |
|
991 | - $js_default = 'core-popper'; |
|
992 | - $js_default_backend = $js_default; |
|
993 | - |
|
994 | - // maybe set defaults (if no settings set) |
|
995 | - if(empty($db_settings)){ |
|
996 | - $active_theme = strtolower( get_template() ); // active parent theme. |
|
997 | - $theme_js_settings = self::theme_js_settings(); |
|
998 | - if(isset($theme_js_settings[$active_theme])){ |
|
999 | - $js_default = $theme_js_settings[$active_theme]; |
|
1000 | - $js_default_backend = isset($theme_js_settings[$active_theme."_backend"]) ? $theme_js_settings[$active_theme."_backend"] : $js_default; |
|
1001 | - } |
|
1002 | - } |
|
1003 | - |
|
1004 | - $defaults = array( |
|
1005 | - 'css' => 'compatibility', // core, compatibility |
|
1006 | - 'js' => $js_default, // js to load, core-popper, popper |
|
1007 | - 'html_font_size' => '16', // js to load, core-popper, popper |
|
1008 | - 'css_backend' => 'compatibility', // core, compatibility |
|
1009 | - 'js_backend' => $js_default_backend, // js to load, core-popper, popper |
|
1010 | - 'disable_admin' => '', // URL snippets to disable loading on admin |
|
1011 | - ); |
|
1012 | - |
|
1013 | - $settings = wp_parse_args( $db_settings, $defaults ); |
|
1014 | - |
|
1015 | - /** |
|
1016 | - * Filter the Bootstrap settings. |
|
1017 | - * |
|
1018 | - * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
1019 | - */ |
|
1020 | - return $this->settings = apply_filters( 'ayecode-ui-settings', $settings, $db_settings, $defaults ); |
|
1021 | - } |
|
1022 | - |
|
1023 | - |
|
1024 | - /** |
|
1025 | - * The settings page html output. |
|
1026 | - */ |
|
1027 | - public function settings_page() { |
|
1028 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
1029 | - wp_die( __( 'You do not have sufficient permissions to access this page.', 'aui' ) ); |
|
1030 | - } |
|
1031 | - ?> |
|
908 | + // Load needed inline scripts by faking the loading of a script if the main script is not being loaded |
|
909 | + if ( $load_inline ) { |
|
910 | + wp_register_script( 'bootstrap-dummy', '', array( 'select2', 'jquery' ) ); |
|
911 | + wp_enqueue_script( 'bootstrap-dummy' ); |
|
912 | + $script = $this->inline_script(); |
|
913 | + wp_add_inline_script( 'bootstrap-dummy', $script ); |
|
914 | + } |
|
915 | + } |
|
916 | + |
|
917 | + } |
|
918 | + |
|
919 | + /** |
|
920 | + * Enqueue flatpickr if called. |
|
921 | + */ |
|
922 | + public function enqueue_flatpickr(){ |
|
923 | + wp_enqueue_style( 'flatpickr' ); |
|
924 | + wp_enqueue_script( 'flatpickr' ); |
|
925 | + } |
|
926 | + |
|
927 | + /** |
|
928 | + * Get the url path to the current folder. |
|
929 | + * |
|
930 | + * @return string |
|
931 | + */ |
|
932 | + public function get_url() { |
|
933 | + |
|
934 | + $url = ''; |
|
935 | + // check if we are inside a plugin |
|
936 | + $file_dir = str_replace( "/includes","", wp_normalize_path( dirname( __FILE__ ) ) ); |
|
937 | + |
|
938 | + // add check in-case user has changed wp-content dir name. |
|
939 | + $wp_content_folder_name = basename(WP_CONTENT_DIR); |
|
940 | + $dir_parts = explode("/$wp_content_folder_name/",$file_dir); |
|
941 | + $url_parts = explode("/$wp_content_folder_name/",plugins_url()); |
|
942 | + |
|
943 | + if(!empty($url_parts[0]) && !empty($dir_parts[1])){ |
|
944 | + $url = trailingslashit( $url_parts[0]."/$wp_content_folder_name/".$dir_parts[1] ); |
|
945 | + } |
|
946 | + |
|
947 | + return $url; |
|
948 | + } |
|
949 | + |
|
950 | + /** |
|
951 | + * Register the database settings with WordPress. |
|
952 | + */ |
|
953 | + public function register_settings() { |
|
954 | + register_setting( 'ayecode-ui-settings', 'ayecode-ui-settings' ); |
|
955 | + } |
|
956 | + |
|
957 | + /** |
|
958 | + * Add the WordPress settings menu item. |
|
959 | + * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
960 | + */ |
|
961 | + public function menu_item() { |
|
962 | + $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
963 | + call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'ayecode-ui-settings', array( |
|
964 | + $this, |
|
965 | + 'settings_page' |
|
966 | + ) ); |
|
967 | + } |
|
968 | + |
|
969 | + /** |
|
970 | + * Get a list of themes and their default JS settings. |
|
971 | + * |
|
972 | + * @return array |
|
973 | + */ |
|
974 | + public function theme_js_settings(){ |
|
975 | + return array( |
|
976 | + 'ayetheme' => 'popper', |
|
977 | + 'listimia' => 'required', |
|
978 | + 'listimia_backend' => 'core-popper', |
|
979 | + //'avada' => 'required', // removed as we now add compatibility |
|
980 | + ); |
|
981 | + } |
|
982 | + |
|
983 | + /** |
|
984 | + * Get the current Font Awesome output settings. |
|
985 | + * |
|
986 | + * @return array The array of settings. |
|
987 | + */ |
|
988 | + public function get_settings() { |
|
989 | + |
|
990 | + $db_settings = get_option( 'ayecode-ui-settings' ); |
|
991 | + $js_default = 'core-popper'; |
|
992 | + $js_default_backend = $js_default; |
|
993 | + |
|
994 | + // maybe set defaults (if no settings set) |
|
995 | + if(empty($db_settings)){ |
|
996 | + $active_theme = strtolower( get_template() ); // active parent theme. |
|
997 | + $theme_js_settings = self::theme_js_settings(); |
|
998 | + if(isset($theme_js_settings[$active_theme])){ |
|
999 | + $js_default = $theme_js_settings[$active_theme]; |
|
1000 | + $js_default_backend = isset($theme_js_settings[$active_theme."_backend"]) ? $theme_js_settings[$active_theme."_backend"] : $js_default; |
|
1001 | + } |
|
1002 | + } |
|
1003 | + |
|
1004 | + $defaults = array( |
|
1005 | + 'css' => 'compatibility', // core, compatibility |
|
1006 | + 'js' => $js_default, // js to load, core-popper, popper |
|
1007 | + 'html_font_size' => '16', // js to load, core-popper, popper |
|
1008 | + 'css_backend' => 'compatibility', // core, compatibility |
|
1009 | + 'js_backend' => $js_default_backend, // js to load, core-popper, popper |
|
1010 | + 'disable_admin' => '', // URL snippets to disable loading on admin |
|
1011 | + ); |
|
1012 | + |
|
1013 | + $settings = wp_parse_args( $db_settings, $defaults ); |
|
1014 | + |
|
1015 | + /** |
|
1016 | + * Filter the Bootstrap settings. |
|
1017 | + * |
|
1018 | + * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
1019 | + */ |
|
1020 | + return $this->settings = apply_filters( 'ayecode-ui-settings', $settings, $db_settings, $defaults ); |
|
1021 | + } |
|
1022 | + |
|
1023 | + |
|
1024 | + /** |
|
1025 | + * The settings page html output. |
|
1026 | + */ |
|
1027 | + public function settings_page() { |
|
1028 | + if ( ! current_user_can( 'manage_options' ) ) { |
|
1029 | + wp_die( __( 'You do not have sufficient permissions to access this page.', 'aui' ) ); |
|
1030 | + } |
|
1031 | + ?> |
|
1032 | 1032 | <div class="wrap"> |
1033 | 1033 | <h1><?php echo $this->name; ?></h1> |
1034 | 1034 | <p><?php _e("Here you can adjust settings if you are having compatibility issues.","aui");?></p> |
1035 | 1035 | <form method="post" action="options.php"> |
1036 | 1036 | <?php |
1037 | - settings_fields( 'ayecode-ui-settings' ); |
|
1038 | - do_settings_sections( 'ayecode-ui-settings' ); |
|
1039 | - ?> |
|
1037 | + settings_fields( 'ayecode-ui-settings' ); |
|
1038 | + do_settings_sections( 'ayecode-ui-settings' ); |
|
1039 | + ?> |
|
1040 | 1040 | |
1041 | 1041 | <h2><?php _e( 'Frontend', 'aui' ); ?></h2> |
1042 | 1042 | <table class="form-table wpbs-table-settings"> |
@@ -1116,60 +1116,60 @@ discard block |
||
1116 | 1116 | </table> |
1117 | 1117 | |
1118 | 1118 | <?php |
1119 | - submit_button(); |
|
1120 | - ?> |
|
1119 | + submit_button(); |
|
1120 | + ?> |
|
1121 | 1121 | </form> |
1122 | 1122 | |
1123 | 1123 | <div id="wpbs-version"><?php echo $this->version; ?></div> |
1124 | 1124 | </div> |
1125 | 1125 | |
1126 | 1126 | <?php |
1127 | - } |
|
1128 | - |
|
1129 | - public function customizer_settings($wp_customize){ |
|
1130 | - $wp_customize->add_section('aui_settings', array( |
|
1131 | - 'title' => __('AyeCode UI','aui'), |
|
1132 | - 'priority' => 120, |
|
1133 | - )); |
|
1134 | - |
|
1135 | - // ============================= |
|
1136 | - // = Color Picker = |
|
1137 | - // ============================= |
|
1138 | - $wp_customize->add_setting('aui_options[color_primary]', array( |
|
1139 | - 'default' => AUI_PRIMARY_COLOR, |
|
1140 | - 'sanitize_callback' => 'sanitize_hex_color', |
|
1141 | - 'capability' => 'edit_theme_options', |
|
1142 | - 'type' => 'option', |
|
1143 | - 'transport' => 'refresh', |
|
1144 | - )); |
|
1145 | - $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_primary', array( |
|
1146 | - 'label' => __('Primary Color','aui'), |
|
1147 | - 'section' => 'aui_settings', |
|
1148 | - 'settings' => 'aui_options[color_primary]', |
|
1149 | - ))); |
|
1150 | - |
|
1151 | - $wp_customize->add_setting('aui_options[color_secondary]', array( |
|
1152 | - 'default' => '#6c757d', |
|
1153 | - 'sanitize_callback' => 'sanitize_hex_color', |
|
1154 | - 'capability' => 'edit_theme_options', |
|
1155 | - 'type' => 'option', |
|
1156 | - 'transport' => 'refresh', |
|
1157 | - )); |
|
1158 | - $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_secondary', array( |
|
1159 | - 'label' => __('Secondary Color','aui'), |
|
1160 | - 'section' => 'aui_settings', |
|
1161 | - 'settings' => 'aui_options[color_secondary]', |
|
1162 | - ))); |
|
1163 | - } |
|
1164 | - |
|
1165 | - /** |
|
1166 | - * CSS to help with conflict issues with other plugins and themes using bootstrap v3. |
|
1167 | - * |
|
1168 | - * @return mixed |
|
1169 | - */ |
|
1170 | - public static function bs3_compat_css() { |
|
1171 | - ob_start(); |
|
1172 | - ?> |
|
1127 | + } |
|
1128 | + |
|
1129 | + public function customizer_settings($wp_customize){ |
|
1130 | + $wp_customize->add_section('aui_settings', array( |
|
1131 | + 'title' => __('AyeCode UI','aui'), |
|
1132 | + 'priority' => 120, |
|
1133 | + )); |
|
1134 | + |
|
1135 | + // ============================= |
|
1136 | + // = Color Picker = |
|
1137 | + // ============================= |
|
1138 | + $wp_customize->add_setting('aui_options[color_primary]', array( |
|
1139 | + 'default' => AUI_PRIMARY_COLOR, |
|
1140 | + 'sanitize_callback' => 'sanitize_hex_color', |
|
1141 | + 'capability' => 'edit_theme_options', |
|
1142 | + 'type' => 'option', |
|
1143 | + 'transport' => 'refresh', |
|
1144 | + )); |
|
1145 | + $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_primary', array( |
|
1146 | + 'label' => __('Primary Color','aui'), |
|
1147 | + 'section' => 'aui_settings', |
|
1148 | + 'settings' => 'aui_options[color_primary]', |
|
1149 | + ))); |
|
1150 | + |
|
1151 | + $wp_customize->add_setting('aui_options[color_secondary]', array( |
|
1152 | + 'default' => '#6c757d', |
|
1153 | + 'sanitize_callback' => 'sanitize_hex_color', |
|
1154 | + 'capability' => 'edit_theme_options', |
|
1155 | + 'type' => 'option', |
|
1156 | + 'transport' => 'refresh', |
|
1157 | + )); |
|
1158 | + $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_secondary', array( |
|
1159 | + 'label' => __('Secondary Color','aui'), |
|
1160 | + 'section' => 'aui_settings', |
|
1161 | + 'settings' => 'aui_options[color_secondary]', |
|
1162 | + ))); |
|
1163 | + } |
|
1164 | + |
|
1165 | + /** |
|
1166 | + * CSS to help with conflict issues with other plugins and themes using bootstrap v3. |
|
1167 | + * |
|
1168 | + * @return mixed |
|
1169 | + */ |
|
1170 | + public static function bs3_compat_css() { |
|
1171 | + ob_start(); |
|
1172 | + ?> |
|
1173 | 1173 | <style> |
1174 | 1174 | /* Bootstrap 3 compatibility */ |
1175 | 1175 | body.modal-open .modal-backdrop.show:not(.in) {opacity:0.5;} |
@@ -1195,467 +1195,467 @@ discard block |
||
1195 | 1195 | <?php } ?> |
1196 | 1196 | </style> |
1197 | 1197 | <?php |
1198 | - return str_replace( array( |
|
1199 | - '<style>', |
|
1200 | - '</style>' |
|
1201 | - ), '', ob_get_clean()); |
|
1202 | - } |
|
1198 | + return str_replace( array( |
|
1199 | + '<style>', |
|
1200 | + '</style>' |
|
1201 | + ), '', ob_get_clean()); |
|
1202 | + } |
|
1203 | 1203 | |
1204 | 1204 | |
1205 | - public static function custom_css($compatibility = true) { |
|
1206 | - $settings = get_option('aui_options'); |
|
1205 | + public static function custom_css($compatibility = true) { |
|
1206 | + $settings = get_option('aui_options'); |
|
1207 | 1207 | |
1208 | - ob_start(); |
|
1208 | + ob_start(); |
|
1209 | 1209 | |
1210 | - $primary_color = !empty($settings['color_primary']) ? $settings['color_primary'] : AUI_PRIMARY_COLOR; |
|
1211 | - $secondary_color = !empty($settings['color_secondary']) ? $settings['color_secondary'] : AUI_SECONDARY_COLOR; |
|
1212 | - //AUI_PRIMARY_COLOR_ORIGINAL |
|
1213 | - ?> |
|
1210 | + $primary_color = !empty($settings['color_primary']) ? $settings['color_primary'] : AUI_PRIMARY_COLOR; |
|
1211 | + $secondary_color = !empty($settings['color_secondary']) ? $settings['color_secondary'] : AUI_SECONDARY_COLOR; |
|
1212 | + //AUI_PRIMARY_COLOR_ORIGINAL |
|
1213 | + ?> |
|
1214 | 1214 | <style> |
1215 | 1215 | <?php |
1216 | 1216 | |
1217 | - // BS v3 compat |
|
1218 | - if( self::is_bs3_compat() ){ |
|
1219 | - echo self::bs3_compat_css(); |
|
1220 | - } |
|
1217 | + // BS v3 compat |
|
1218 | + if( self::is_bs3_compat() ){ |
|
1219 | + echo self::bs3_compat_css(); |
|
1220 | + } |
|
1221 | 1221 | |
1222 | - if(!is_admin() && $primary_color != AUI_PRIMARY_COLOR_ORIGINAL){ |
|
1223 | - echo self::css_primary($primary_color,$compatibility); |
|
1224 | - } |
|
1222 | + if(!is_admin() && $primary_color != AUI_PRIMARY_COLOR_ORIGINAL){ |
|
1223 | + echo self::css_primary($primary_color,$compatibility); |
|
1224 | + } |
|
1225 | 1225 | |
1226 | - if(!is_admin() && $secondary_color != AUI_SECONDARY_COLOR_ORIGINAL){ |
|
1227 | - echo self::css_secondary($settings['color_secondary'],$compatibility); |
|
1228 | - } |
|
1226 | + if(!is_admin() && $secondary_color != AUI_SECONDARY_COLOR_ORIGINAL){ |
|
1227 | + echo self::css_secondary($settings['color_secondary'],$compatibility); |
|
1228 | + } |
|
1229 | 1229 | |
1230 | - // Set admin bar z-index lower when modal is open. |
|
1231 | - echo ' body.modal-open #wpadminbar{z-index:999}'; |
|
1230 | + // Set admin bar z-index lower when modal is open. |
|
1231 | + echo ' body.modal-open #wpadminbar{z-index:999}'; |
|
1232 | 1232 | ?> |
1233 | 1233 | </style> |
1234 | 1234 | <?php |
1235 | 1235 | |
1236 | 1236 | |
1237 | - /* |
|
1237 | + /* |
|
1238 | 1238 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
1239 | 1239 | */ |
1240 | - return str_replace( array( |
|
1241 | - '<style>', |
|
1242 | - '</style>' |
|
1243 | - ), '', ob_get_clean()); |
|
1244 | - } |
|
1245 | - |
|
1246 | - /** |
|
1247 | - * Check if we should add booststrap 3 compatibility changes. |
|
1248 | - * |
|
1249 | - * @return bool |
|
1250 | - */ |
|
1251 | - public static function is_bs3_compat(){ |
|
1252 | - return defined('AYECODE_UI_BS3_COMPAT') || defined('SVQ_THEME_VERSION') || defined('FUSION_BUILDER_VERSION'); |
|
1253 | - } |
|
1254 | - |
|
1255 | - public static function css_primary($color_code,$compatibility){; |
|
1256 | - $color_code = sanitize_hex_color($color_code); |
|
1257 | - if(!$color_code){return '';} |
|
1258 | - /** |
|
1259 | - * c = color, b = background color, o = border-color, f = fill |
|
1260 | - */ |
|
1261 | - $selectors = array( |
|
1262 | - 'a' => array('c'), |
|
1263 | - '.btn-primary' => array('b','o'), |
|
1264 | - '.btn-primary.disabled' => array('b','o'), |
|
1265 | - '.btn-primary:disabled' => array('b','o'), |
|
1266 | - '.btn-outline-primary' => array('c','o'), |
|
1267 | - '.btn-outline-primary:hover' => array('b','o'), |
|
1268 | - '.btn-outline-primary:not(:disabled):not(.disabled).active' => array('b','o'), |
|
1269 | - '.btn-outline-primary:not(:disabled):not(.disabled):active' => array('b','o'), |
|
1270 | - '.show>.btn-outline-primary.dropdown-toggle' => array('b','o'), |
|
1271 | - '.btn-link' => array('c'), |
|
1272 | - '.dropdown-item.active' => array('b'), |
|
1273 | - '.custom-control-input:checked~.custom-control-label::before' => array('b','o'), |
|
1274 | - '.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array('b','o'), |
|
1240 | + return str_replace( array( |
|
1241 | + '<style>', |
|
1242 | + '</style>' |
|
1243 | + ), '', ob_get_clean()); |
|
1244 | + } |
|
1245 | + |
|
1246 | + /** |
|
1247 | + * Check if we should add booststrap 3 compatibility changes. |
|
1248 | + * |
|
1249 | + * @return bool |
|
1250 | + */ |
|
1251 | + public static function is_bs3_compat(){ |
|
1252 | + return defined('AYECODE_UI_BS3_COMPAT') || defined('SVQ_THEME_VERSION') || defined('FUSION_BUILDER_VERSION'); |
|
1253 | + } |
|
1254 | + |
|
1255 | + public static function css_primary($color_code,$compatibility){; |
|
1256 | + $color_code = sanitize_hex_color($color_code); |
|
1257 | + if(!$color_code){return '';} |
|
1258 | + /** |
|
1259 | + * c = color, b = background color, o = border-color, f = fill |
|
1260 | + */ |
|
1261 | + $selectors = array( |
|
1262 | + 'a' => array('c'), |
|
1263 | + '.btn-primary' => array('b','o'), |
|
1264 | + '.btn-primary.disabled' => array('b','o'), |
|
1265 | + '.btn-primary:disabled' => array('b','o'), |
|
1266 | + '.btn-outline-primary' => array('c','o'), |
|
1267 | + '.btn-outline-primary:hover' => array('b','o'), |
|
1268 | + '.btn-outline-primary:not(:disabled):not(.disabled).active' => array('b','o'), |
|
1269 | + '.btn-outline-primary:not(:disabled):not(.disabled):active' => array('b','o'), |
|
1270 | + '.show>.btn-outline-primary.dropdown-toggle' => array('b','o'), |
|
1271 | + '.btn-link' => array('c'), |
|
1272 | + '.dropdown-item.active' => array('b'), |
|
1273 | + '.custom-control-input:checked~.custom-control-label::before' => array('b','o'), |
|
1274 | + '.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array('b','o'), |
|
1275 | 1275 | // '.custom-range::-webkit-slider-thumb' => array('b'), // these break the inline rules... |
1276 | 1276 | // '.custom-range::-moz-range-thumb' => array('b'), |
1277 | 1277 | // '.custom-range::-ms-thumb' => array('b'), |
1278 | - '.nav-pills .nav-link.active' => array('b'), |
|
1279 | - '.nav-pills .show>.nav-link' => array('b'), |
|
1280 | - '.page-link' => array('c'), |
|
1281 | - '.page-item.active .page-link' => array('b','o'), |
|
1282 | - '.badge-primary' => array('b'), |
|
1283 | - '.alert-primary' => array('b','o'), |
|
1284 | - '.progress-bar' => array('b'), |
|
1285 | - '.list-group-item.active' => array('b','o'), |
|
1286 | - '.bg-primary' => array('b','f'), |
|
1287 | - '.btn-link.btn-primary' => array('c'), |
|
1288 | - '.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array('b'), |
|
1289 | - ); |
|
1290 | - |
|
1291 | - $important_selectors = array( |
|
1292 | - '.bg-primary' => array('b','f'), |
|
1293 | - '.border-primary' => array('o'), |
|
1294 | - '.text-primary' => array('c'), |
|
1295 | - ); |
|
1296 | - |
|
1297 | - $color = array(); |
|
1298 | - $color_i = array(); |
|
1299 | - $background = array(); |
|
1300 | - $background_i = array(); |
|
1301 | - $border = array(); |
|
1302 | - $border_i = array(); |
|
1303 | - $fill = array(); |
|
1304 | - $fill_i = array(); |
|
1305 | - |
|
1306 | - $output = ''; |
|
1307 | - |
|
1308 | - // build rules into each type |
|
1309 | - foreach($selectors as $selector => $types){ |
|
1310 | - $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1311 | - $types = array_combine($types,$types); |
|
1312 | - if(isset($types['c'])){$color[] = $selector;} |
|
1313 | - if(isset($types['b'])){$background[] = $selector;} |
|
1314 | - if(isset($types['o'])){$border[] = $selector;} |
|
1315 | - if(isset($types['f'])){$fill[] = $selector;} |
|
1316 | - } |
|
1317 | - |
|
1318 | - // build rules into each type |
|
1319 | - foreach($important_selectors as $selector => $types){ |
|
1320 | - $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1321 | - $types = array_combine($types,$types); |
|
1322 | - if(isset($types['c'])){$color_i[] = $selector;} |
|
1323 | - if(isset($types['b'])){$background_i[] = $selector;} |
|
1324 | - if(isset($types['o'])){$border_i[] = $selector;} |
|
1325 | - if(isset($types['f'])){$fill_i[] = $selector;} |
|
1326 | - } |
|
1327 | - |
|
1328 | - // add any color rules |
|
1329 | - if(!empty($color)){ |
|
1330 | - $output .= implode(",",$color) . "{color: $color_code;} "; |
|
1331 | - } |
|
1332 | - if(!empty($color_i)){ |
|
1333 | - $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
|
1334 | - } |
|
1335 | - |
|
1336 | - // add any background color rules |
|
1337 | - if(!empty($background)){ |
|
1338 | - $output .= implode(",",$background) . "{background-color: $color_code;} "; |
|
1339 | - } |
|
1340 | - if(!empty($background_i)){ |
|
1341 | - $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
|
1342 | - } |
|
1343 | - |
|
1344 | - // add any border color rules |
|
1345 | - if(!empty($border)){ |
|
1346 | - $output .= implode(",",$border) . "{border-color: $color_code;} "; |
|
1347 | - } |
|
1348 | - if(!empty($border_i)){ |
|
1349 | - $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
|
1350 | - } |
|
1351 | - |
|
1352 | - // add any fill color rules |
|
1353 | - if(!empty($fill)){ |
|
1354 | - $output .= implode(",",$fill) . "{fill: $color_code;} "; |
|
1355 | - } |
|
1356 | - if(!empty($fill_i)){ |
|
1357 | - $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
|
1358 | - } |
|
1359 | - |
|
1360 | - |
|
1361 | - $prefix = $compatibility ? ".bsui " : ""; |
|
1362 | - |
|
1363 | - // darken |
|
1364 | - $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075"); |
|
1365 | - $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10"); |
|
1366 | - $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125"); |
|
1367 | - |
|
1368 | - // lighten |
|
1369 | - $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25"); |
|
1370 | - |
|
1371 | - // opacity see https://css-tricks.com/8-digit-hex-codes/ |
|
1372 | - $op_25 = $color_code."40"; // 25% opacity |
|
1373 | - |
|
1374 | - |
|
1375 | - // button states |
|
1376 | - $output .= $prefix ." .btn-primary:hover{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
|
1377 | - $output .= $prefix ." .btn-outline-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-primary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1378 | - $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active, $prefix .btn-primary:not(:disabled):not(.disabled).active, .show>$prefix .btn-primary.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} "; |
|
1379 | - $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-primary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1380 | - |
|
1381 | - |
|
1382 | - // dropdown's |
|
1383 | - $output .= $prefix ." .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} "; |
|
1384 | - |
|
1385 | - |
|
1386 | - // input states |
|
1387 | - $output .= $prefix ." .form-control:focus{border-color: ".$lighten_25.";box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1388 | - |
|
1389 | - // page link |
|
1390 | - $output .= $prefix ." .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1391 | - |
|
1392 | - return $output; |
|
1393 | - } |
|
1394 | - |
|
1395 | - public static function css_secondary($color_code,$compatibility){; |
|
1396 | - $color_code = sanitize_hex_color($color_code); |
|
1397 | - if(!$color_code){return '';} |
|
1398 | - /** |
|
1399 | - * c = color, b = background color, o = border-color, f = fill |
|
1400 | - */ |
|
1401 | - $selectors = array( |
|
1402 | - '.btn-secondary' => array('b','o'), |
|
1403 | - '.btn-secondary.disabled' => array('b','o'), |
|
1404 | - '.btn-secondary:disabled' => array('b','o'), |
|
1405 | - '.btn-outline-secondary' => array('c','o'), |
|
1406 | - '.btn-outline-secondary:hover' => array('b','o'), |
|
1407 | - '.btn-outline-secondary.disabled' => array('c'), |
|
1408 | - '.btn-outline-secondary:disabled' => array('c'), |
|
1409 | - '.btn-outline-secondary:not(:disabled):not(.disabled):active' => array('b','o'), |
|
1410 | - '.btn-outline-secondary:not(:disabled):not(.disabled).active' => array('b','o'), |
|
1411 | - '.btn-outline-secondary.dropdown-toggle' => array('b','o'), |
|
1412 | - '.badge-secondary' => array('b'), |
|
1413 | - '.alert-secondary' => array('b','o'), |
|
1414 | - '.btn-link.btn-secondary' => array('c'), |
|
1415 | - ); |
|
1416 | - |
|
1417 | - $important_selectors = array( |
|
1418 | - '.bg-secondary' => array('b','f'), |
|
1419 | - '.border-secondary' => array('o'), |
|
1420 | - '.text-secondary' => array('c'), |
|
1421 | - ); |
|
1422 | - |
|
1423 | - $color = array(); |
|
1424 | - $color_i = array(); |
|
1425 | - $background = array(); |
|
1426 | - $background_i = array(); |
|
1427 | - $border = array(); |
|
1428 | - $border_i = array(); |
|
1429 | - $fill = array(); |
|
1430 | - $fill_i = array(); |
|
1431 | - |
|
1432 | - $output = ''; |
|
1433 | - |
|
1434 | - // build rules into each type |
|
1435 | - foreach($selectors as $selector => $types){ |
|
1436 | - $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1437 | - $types = array_combine($types,$types); |
|
1438 | - if(isset($types['c'])){$color[] = $selector;} |
|
1439 | - if(isset($types['b'])){$background[] = $selector;} |
|
1440 | - if(isset($types['o'])){$border[] = $selector;} |
|
1441 | - if(isset($types['f'])){$fill[] = $selector;} |
|
1442 | - } |
|
1443 | - |
|
1444 | - // build rules into each type |
|
1445 | - foreach($important_selectors as $selector => $types){ |
|
1446 | - $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1447 | - $types = array_combine($types,$types); |
|
1448 | - if(isset($types['c'])){$color_i[] = $selector;} |
|
1449 | - if(isset($types['b'])){$background_i[] = $selector;} |
|
1450 | - if(isset($types['o'])){$border_i[] = $selector;} |
|
1451 | - if(isset($types['f'])){$fill_i[] = $selector;} |
|
1452 | - } |
|
1453 | - |
|
1454 | - // add any color rules |
|
1455 | - if(!empty($color)){ |
|
1456 | - $output .= implode(",",$color) . "{color: $color_code;} "; |
|
1457 | - } |
|
1458 | - if(!empty($color_i)){ |
|
1459 | - $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
|
1460 | - } |
|
1461 | - |
|
1462 | - // add any background color rules |
|
1463 | - if(!empty($background)){ |
|
1464 | - $output .= implode(",",$background) . "{background-color: $color_code;} "; |
|
1465 | - } |
|
1466 | - if(!empty($background_i)){ |
|
1467 | - $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
|
1468 | - } |
|
1469 | - |
|
1470 | - // add any border color rules |
|
1471 | - if(!empty($border)){ |
|
1472 | - $output .= implode(",",$border) . "{border-color: $color_code;} "; |
|
1473 | - } |
|
1474 | - if(!empty($border_i)){ |
|
1475 | - $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
|
1476 | - } |
|
1477 | - |
|
1478 | - // add any fill color rules |
|
1479 | - if(!empty($fill)){ |
|
1480 | - $output .= implode(",",$fill) . "{fill: $color_code;} "; |
|
1481 | - } |
|
1482 | - if(!empty($fill_i)){ |
|
1483 | - $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
|
1484 | - } |
|
1485 | - |
|
1486 | - |
|
1487 | - $prefix = $compatibility ? ".bsui " : ""; |
|
1488 | - |
|
1489 | - // darken |
|
1490 | - $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075"); |
|
1491 | - $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10"); |
|
1492 | - $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125"); |
|
1493 | - |
|
1494 | - // lighten |
|
1495 | - $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25"); |
|
1496 | - |
|
1497 | - // opacity see https://css-tricks.com/8-digit-hex-codes/ |
|
1498 | - $op_25 = $color_code."40"; // 25% opacity |
|
1499 | - |
|
1500 | - |
|
1501 | - // button states |
|
1502 | - $output .= $prefix ." .btn-secondary:hover{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
|
1503 | - $output .= $prefix ." .btn-outline-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-secondary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1504 | - $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active, $prefix .btn-secondary:not(:disabled):not(.disabled).active, .show>$prefix .btn-secondary.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} "; |
|
1505 | - $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-secondary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1506 | - |
|
1507 | - |
|
1508 | - return $output; |
|
1509 | - } |
|
1510 | - |
|
1511 | - /** |
|
1512 | - * Increases or decreases the brightness of a color by a percentage of the current brightness. |
|
1513 | - * |
|
1514 | - * @param string $hexCode Supported formats: `#FFF`, `#FFFFFF`, `FFF`, `FFFFFF` |
|
1515 | - * @param float $adjustPercent A number between -1 and 1. E.g. 0.3 = 30% lighter; -0.4 = 40% darker. |
|
1516 | - * |
|
1517 | - * @return string |
|
1518 | - */ |
|
1519 | - public static function css_hex_lighten_darken($hexCode, $adjustPercent) { |
|
1520 | - $hexCode = ltrim($hexCode, '#'); |
|
1521 | - |
|
1522 | - if (strlen($hexCode) == 3) { |
|
1523 | - $hexCode = $hexCode[0] . $hexCode[0] . $hexCode[1] . $hexCode[1] . $hexCode[2] . $hexCode[2]; |
|
1524 | - } |
|
1525 | - |
|
1526 | - $hexCode = array_map('hexdec', str_split($hexCode, 2)); |
|
1527 | - |
|
1528 | - foreach ($hexCode as & $color) { |
|
1529 | - $adjustableLimit = $adjustPercent < 0 ? $color : 255 - $color; |
|
1530 | - $adjustAmount = ceil($adjustableLimit * $adjustPercent); |
|
1531 | - |
|
1532 | - $color = str_pad(dechex($color + $adjustAmount), 2, '0', STR_PAD_LEFT); |
|
1533 | - } |
|
1534 | - |
|
1535 | - return '#' . implode($hexCode); |
|
1536 | - } |
|
1537 | - |
|
1538 | - /** |
|
1539 | - * Check if we should display examples. |
|
1540 | - */ |
|
1541 | - public function maybe_show_examples(){ |
|
1542 | - if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){ |
|
1543 | - echo "<head>"; |
|
1544 | - wp_head(); |
|
1545 | - echo "</head>"; |
|
1546 | - echo "<body>"; |
|
1547 | - echo $this->get_examples(); |
|
1548 | - echo "</body>"; |
|
1549 | - exit; |
|
1550 | - } |
|
1551 | - } |
|
1552 | - |
|
1553 | - /** |
|
1554 | - * Get developer examples. |
|
1555 | - * |
|
1556 | - * @return string |
|
1557 | - */ |
|
1558 | - public function get_examples(){ |
|
1559 | - $output = ''; |
|
1560 | - |
|
1561 | - |
|
1562 | - // open form |
|
1563 | - $output .= "<form class='p-5 m-5 border rounded'>"; |
|
1564 | - |
|
1565 | - // input example |
|
1566 | - $output .= aui()->input(array( |
|
1567 | - 'type' => 'text', |
|
1568 | - 'id' => 'text-example', |
|
1569 | - 'name' => 'text-example', |
|
1570 | - 'placeholder' => 'text placeholder', |
|
1571 | - 'title' => 'Text input example', |
|
1572 | - 'value' => '', |
|
1573 | - 'required' => false, |
|
1574 | - 'help_text' => 'help text', |
|
1575 | - 'label' => 'Text input example label' |
|
1576 | - )); |
|
1577 | - |
|
1578 | - // input example |
|
1579 | - $output .= aui()->input(array( |
|
1580 | - 'type' => 'url', |
|
1581 | - 'id' => 'text-example2', |
|
1582 | - 'name' => 'text-example', |
|
1583 | - 'placeholder' => 'url placeholder', |
|
1584 | - 'title' => 'Text input example', |
|
1585 | - 'value' => '', |
|
1586 | - 'required' => false, |
|
1587 | - 'help_text' => 'help text', |
|
1588 | - 'label' => 'Text input example label' |
|
1589 | - )); |
|
1590 | - |
|
1591 | - // checkbox example |
|
1592 | - $output .= aui()->input(array( |
|
1593 | - 'type' => 'checkbox', |
|
1594 | - 'id' => 'checkbox-example', |
|
1595 | - 'name' => 'checkbox-example', |
|
1596 | - 'placeholder' => 'checkbox-example', |
|
1597 | - 'title' => 'Checkbox example', |
|
1598 | - 'value' => '1', |
|
1599 | - 'checked' => true, |
|
1600 | - 'required' => false, |
|
1601 | - 'help_text' => 'help text', |
|
1602 | - 'label' => 'Checkbox checked' |
|
1603 | - )); |
|
1604 | - |
|
1605 | - // checkbox example |
|
1606 | - $output .= aui()->input(array( |
|
1607 | - 'type' => 'checkbox', |
|
1608 | - 'id' => 'checkbox-example2', |
|
1609 | - 'name' => 'checkbox-example2', |
|
1610 | - 'placeholder' => 'checkbox-example', |
|
1611 | - 'title' => 'Checkbox example', |
|
1612 | - 'value' => '1', |
|
1613 | - 'checked' => false, |
|
1614 | - 'required' => false, |
|
1615 | - 'help_text' => 'help text', |
|
1616 | - 'label' => 'Checkbox un-checked' |
|
1617 | - )); |
|
1618 | - |
|
1619 | - // switch example |
|
1620 | - $output .= aui()->input(array( |
|
1621 | - 'type' => 'checkbox', |
|
1622 | - 'id' => 'switch-example', |
|
1623 | - 'name' => 'switch-example', |
|
1624 | - 'placeholder' => 'checkbox-example', |
|
1625 | - 'title' => 'Switch example', |
|
1626 | - 'value' => '1', |
|
1627 | - 'checked' => true, |
|
1628 | - 'switch' => true, |
|
1629 | - 'required' => false, |
|
1630 | - 'help_text' => 'help text', |
|
1631 | - 'label' => 'Switch on' |
|
1632 | - )); |
|
1633 | - |
|
1634 | - // switch example |
|
1635 | - $output .= aui()->input(array( |
|
1636 | - 'type' => 'checkbox', |
|
1637 | - 'id' => 'switch-example2', |
|
1638 | - 'name' => 'switch-example2', |
|
1639 | - 'placeholder' => 'checkbox-example', |
|
1640 | - 'title' => 'Switch example', |
|
1641 | - 'value' => '1', |
|
1642 | - 'checked' => false, |
|
1643 | - 'switch' => true, |
|
1644 | - 'required' => false, |
|
1645 | - 'help_text' => 'help text', |
|
1646 | - 'label' => 'Switch off' |
|
1647 | - )); |
|
1648 | - |
|
1649 | - // close form |
|
1650 | - $output .= "</form>"; |
|
1651 | - |
|
1652 | - return $output; |
|
1653 | - } |
|
1654 | - |
|
1655 | - } |
|
1656 | - |
|
1657 | - /** |
|
1658 | - * Run the class if found. |
|
1659 | - */ |
|
1660 | - AyeCode_UI_Settings::instance(); |
|
1278 | + '.nav-pills .nav-link.active' => array('b'), |
|
1279 | + '.nav-pills .show>.nav-link' => array('b'), |
|
1280 | + '.page-link' => array('c'), |
|
1281 | + '.page-item.active .page-link' => array('b','o'), |
|
1282 | + '.badge-primary' => array('b'), |
|
1283 | + '.alert-primary' => array('b','o'), |
|
1284 | + '.progress-bar' => array('b'), |
|
1285 | + '.list-group-item.active' => array('b','o'), |
|
1286 | + '.bg-primary' => array('b','f'), |
|
1287 | + '.btn-link.btn-primary' => array('c'), |
|
1288 | + '.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array('b'), |
|
1289 | + ); |
|
1290 | + |
|
1291 | + $important_selectors = array( |
|
1292 | + '.bg-primary' => array('b','f'), |
|
1293 | + '.border-primary' => array('o'), |
|
1294 | + '.text-primary' => array('c'), |
|
1295 | + ); |
|
1296 | + |
|
1297 | + $color = array(); |
|
1298 | + $color_i = array(); |
|
1299 | + $background = array(); |
|
1300 | + $background_i = array(); |
|
1301 | + $border = array(); |
|
1302 | + $border_i = array(); |
|
1303 | + $fill = array(); |
|
1304 | + $fill_i = array(); |
|
1305 | + |
|
1306 | + $output = ''; |
|
1307 | + |
|
1308 | + // build rules into each type |
|
1309 | + foreach($selectors as $selector => $types){ |
|
1310 | + $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1311 | + $types = array_combine($types,$types); |
|
1312 | + if(isset($types['c'])){$color[] = $selector;} |
|
1313 | + if(isset($types['b'])){$background[] = $selector;} |
|
1314 | + if(isset($types['o'])){$border[] = $selector;} |
|
1315 | + if(isset($types['f'])){$fill[] = $selector;} |
|
1316 | + } |
|
1317 | + |
|
1318 | + // build rules into each type |
|
1319 | + foreach($important_selectors as $selector => $types){ |
|
1320 | + $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1321 | + $types = array_combine($types,$types); |
|
1322 | + if(isset($types['c'])){$color_i[] = $selector;} |
|
1323 | + if(isset($types['b'])){$background_i[] = $selector;} |
|
1324 | + if(isset($types['o'])){$border_i[] = $selector;} |
|
1325 | + if(isset($types['f'])){$fill_i[] = $selector;} |
|
1326 | + } |
|
1327 | + |
|
1328 | + // add any color rules |
|
1329 | + if(!empty($color)){ |
|
1330 | + $output .= implode(",",$color) . "{color: $color_code;} "; |
|
1331 | + } |
|
1332 | + if(!empty($color_i)){ |
|
1333 | + $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
|
1334 | + } |
|
1335 | + |
|
1336 | + // add any background color rules |
|
1337 | + if(!empty($background)){ |
|
1338 | + $output .= implode(",",$background) . "{background-color: $color_code;} "; |
|
1339 | + } |
|
1340 | + if(!empty($background_i)){ |
|
1341 | + $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
|
1342 | + } |
|
1343 | + |
|
1344 | + // add any border color rules |
|
1345 | + if(!empty($border)){ |
|
1346 | + $output .= implode(",",$border) . "{border-color: $color_code;} "; |
|
1347 | + } |
|
1348 | + if(!empty($border_i)){ |
|
1349 | + $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
|
1350 | + } |
|
1351 | + |
|
1352 | + // add any fill color rules |
|
1353 | + if(!empty($fill)){ |
|
1354 | + $output .= implode(",",$fill) . "{fill: $color_code;} "; |
|
1355 | + } |
|
1356 | + if(!empty($fill_i)){ |
|
1357 | + $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
|
1358 | + } |
|
1359 | + |
|
1360 | + |
|
1361 | + $prefix = $compatibility ? ".bsui " : ""; |
|
1362 | + |
|
1363 | + // darken |
|
1364 | + $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075"); |
|
1365 | + $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10"); |
|
1366 | + $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125"); |
|
1367 | + |
|
1368 | + // lighten |
|
1369 | + $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25"); |
|
1370 | + |
|
1371 | + // opacity see https://css-tricks.com/8-digit-hex-codes/ |
|
1372 | + $op_25 = $color_code."40"; // 25% opacity |
|
1373 | + |
|
1374 | + |
|
1375 | + // button states |
|
1376 | + $output .= $prefix ." .btn-primary:hover{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
|
1377 | + $output .= $prefix ." .btn-outline-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-primary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1378 | + $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active, $prefix .btn-primary:not(:disabled):not(.disabled).active, .show>$prefix .btn-primary.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} "; |
|
1379 | + $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-primary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1380 | + |
|
1381 | + |
|
1382 | + // dropdown's |
|
1383 | + $output .= $prefix ." .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} "; |
|
1384 | + |
|
1385 | + |
|
1386 | + // input states |
|
1387 | + $output .= $prefix ." .form-control:focus{border-color: ".$lighten_25.";box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1388 | + |
|
1389 | + // page link |
|
1390 | + $output .= $prefix ." .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1391 | + |
|
1392 | + return $output; |
|
1393 | + } |
|
1394 | + |
|
1395 | + public static function css_secondary($color_code,$compatibility){; |
|
1396 | + $color_code = sanitize_hex_color($color_code); |
|
1397 | + if(!$color_code){return '';} |
|
1398 | + /** |
|
1399 | + * c = color, b = background color, o = border-color, f = fill |
|
1400 | + */ |
|
1401 | + $selectors = array( |
|
1402 | + '.btn-secondary' => array('b','o'), |
|
1403 | + '.btn-secondary.disabled' => array('b','o'), |
|
1404 | + '.btn-secondary:disabled' => array('b','o'), |
|
1405 | + '.btn-outline-secondary' => array('c','o'), |
|
1406 | + '.btn-outline-secondary:hover' => array('b','o'), |
|
1407 | + '.btn-outline-secondary.disabled' => array('c'), |
|
1408 | + '.btn-outline-secondary:disabled' => array('c'), |
|
1409 | + '.btn-outline-secondary:not(:disabled):not(.disabled):active' => array('b','o'), |
|
1410 | + '.btn-outline-secondary:not(:disabled):not(.disabled).active' => array('b','o'), |
|
1411 | + '.btn-outline-secondary.dropdown-toggle' => array('b','o'), |
|
1412 | + '.badge-secondary' => array('b'), |
|
1413 | + '.alert-secondary' => array('b','o'), |
|
1414 | + '.btn-link.btn-secondary' => array('c'), |
|
1415 | + ); |
|
1416 | + |
|
1417 | + $important_selectors = array( |
|
1418 | + '.bg-secondary' => array('b','f'), |
|
1419 | + '.border-secondary' => array('o'), |
|
1420 | + '.text-secondary' => array('c'), |
|
1421 | + ); |
|
1422 | + |
|
1423 | + $color = array(); |
|
1424 | + $color_i = array(); |
|
1425 | + $background = array(); |
|
1426 | + $background_i = array(); |
|
1427 | + $border = array(); |
|
1428 | + $border_i = array(); |
|
1429 | + $fill = array(); |
|
1430 | + $fill_i = array(); |
|
1431 | + |
|
1432 | + $output = ''; |
|
1433 | + |
|
1434 | + // build rules into each type |
|
1435 | + foreach($selectors as $selector => $types){ |
|
1436 | + $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1437 | + $types = array_combine($types,$types); |
|
1438 | + if(isset($types['c'])){$color[] = $selector;} |
|
1439 | + if(isset($types['b'])){$background[] = $selector;} |
|
1440 | + if(isset($types['o'])){$border[] = $selector;} |
|
1441 | + if(isset($types['f'])){$fill[] = $selector;} |
|
1442 | + } |
|
1443 | + |
|
1444 | + // build rules into each type |
|
1445 | + foreach($important_selectors as $selector => $types){ |
|
1446 | + $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1447 | + $types = array_combine($types,$types); |
|
1448 | + if(isset($types['c'])){$color_i[] = $selector;} |
|
1449 | + if(isset($types['b'])){$background_i[] = $selector;} |
|
1450 | + if(isset($types['o'])){$border_i[] = $selector;} |
|
1451 | + if(isset($types['f'])){$fill_i[] = $selector;} |
|
1452 | + } |
|
1453 | + |
|
1454 | + // add any color rules |
|
1455 | + if(!empty($color)){ |
|
1456 | + $output .= implode(",",$color) . "{color: $color_code;} "; |
|
1457 | + } |
|
1458 | + if(!empty($color_i)){ |
|
1459 | + $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
|
1460 | + } |
|
1461 | + |
|
1462 | + // add any background color rules |
|
1463 | + if(!empty($background)){ |
|
1464 | + $output .= implode(",",$background) . "{background-color: $color_code;} "; |
|
1465 | + } |
|
1466 | + if(!empty($background_i)){ |
|
1467 | + $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
|
1468 | + } |
|
1469 | + |
|
1470 | + // add any border color rules |
|
1471 | + if(!empty($border)){ |
|
1472 | + $output .= implode(",",$border) . "{border-color: $color_code;} "; |
|
1473 | + } |
|
1474 | + if(!empty($border_i)){ |
|
1475 | + $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
|
1476 | + } |
|
1477 | + |
|
1478 | + // add any fill color rules |
|
1479 | + if(!empty($fill)){ |
|
1480 | + $output .= implode(",",$fill) . "{fill: $color_code;} "; |
|
1481 | + } |
|
1482 | + if(!empty($fill_i)){ |
|
1483 | + $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
|
1484 | + } |
|
1485 | + |
|
1486 | + |
|
1487 | + $prefix = $compatibility ? ".bsui " : ""; |
|
1488 | + |
|
1489 | + // darken |
|
1490 | + $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075"); |
|
1491 | + $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10"); |
|
1492 | + $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125"); |
|
1493 | + |
|
1494 | + // lighten |
|
1495 | + $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25"); |
|
1496 | + |
|
1497 | + // opacity see https://css-tricks.com/8-digit-hex-codes/ |
|
1498 | + $op_25 = $color_code."40"; // 25% opacity |
|
1499 | + |
|
1500 | + |
|
1501 | + // button states |
|
1502 | + $output .= $prefix ." .btn-secondary:hover{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
|
1503 | + $output .= $prefix ." .btn-outline-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-secondary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1504 | + $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active, $prefix .btn-secondary:not(:disabled):not(.disabled).active, .show>$prefix .btn-secondary.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} "; |
|
1505 | + $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-secondary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1506 | + |
|
1507 | + |
|
1508 | + return $output; |
|
1509 | + } |
|
1510 | + |
|
1511 | + /** |
|
1512 | + * Increases or decreases the brightness of a color by a percentage of the current brightness. |
|
1513 | + * |
|
1514 | + * @param string $hexCode Supported formats: `#FFF`, `#FFFFFF`, `FFF`, `FFFFFF` |
|
1515 | + * @param float $adjustPercent A number between -1 and 1. E.g. 0.3 = 30% lighter; -0.4 = 40% darker. |
|
1516 | + * |
|
1517 | + * @return string |
|
1518 | + */ |
|
1519 | + public static function css_hex_lighten_darken($hexCode, $adjustPercent) { |
|
1520 | + $hexCode = ltrim($hexCode, '#'); |
|
1521 | + |
|
1522 | + if (strlen($hexCode) == 3) { |
|
1523 | + $hexCode = $hexCode[0] . $hexCode[0] . $hexCode[1] . $hexCode[1] . $hexCode[2] . $hexCode[2]; |
|
1524 | + } |
|
1525 | + |
|
1526 | + $hexCode = array_map('hexdec', str_split($hexCode, 2)); |
|
1527 | + |
|
1528 | + foreach ($hexCode as & $color) { |
|
1529 | + $adjustableLimit = $adjustPercent < 0 ? $color : 255 - $color; |
|
1530 | + $adjustAmount = ceil($adjustableLimit * $adjustPercent); |
|
1531 | + |
|
1532 | + $color = str_pad(dechex($color + $adjustAmount), 2, '0', STR_PAD_LEFT); |
|
1533 | + } |
|
1534 | + |
|
1535 | + return '#' . implode($hexCode); |
|
1536 | + } |
|
1537 | + |
|
1538 | + /** |
|
1539 | + * Check if we should display examples. |
|
1540 | + */ |
|
1541 | + public function maybe_show_examples(){ |
|
1542 | + if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){ |
|
1543 | + echo "<head>"; |
|
1544 | + wp_head(); |
|
1545 | + echo "</head>"; |
|
1546 | + echo "<body>"; |
|
1547 | + echo $this->get_examples(); |
|
1548 | + echo "</body>"; |
|
1549 | + exit; |
|
1550 | + } |
|
1551 | + } |
|
1552 | + |
|
1553 | + /** |
|
1554 | + * Get developer examples. |
|
1555 | + * |
|
1556 | + * @return string |
|
1557 | + */ |
|
1558 | + public function get_examples(){ |
|
1559 | + $output = ''; |
|
1560 | + |
|
1561 | + |
|
1562 | + // open form |
|
1563 | + $output .= "<form class='p-5 m-5 border rounded'>"; |
|
1564 | + |
|
1565 | + // input example |
|
1566 | + $output .= aui()->input(array( |
|
1567 | + 'type' => 'text', |
|
1568 | + 'id' => 'text-example', |
|
1569 | + 'name' => 'text-example', |
|
1570 | + 'placeholder' => 'text placeholder', |
|
1571 | + 'title' => 'Text input example', |
|
1572 | + 'value' => '', |
|
1573 | + 'required' => false, |
|
1574 | + 'help_text' => 'help text', |
|
1575 | + 'label' => 'Text input example label' |
|
1576 | + )); |
|
1577 | + |
|
1578 | + // input example |
|
1579 | + $output .= aui()->input(array( |
|
1580 | + 'type' => 'url', |
|
1581 | + 'id' => 'text-example2', |
|
1582 | + 'name' => 'text-example', |
|
1583 | + 'placeholder' => 'url placeholder', |
|
1584 | + 'title' => 'Text input example', |
|
1585 | + 'value' => '', |
|
1586 | + 'required' => false, |
|
1587 | + 'help_text' => 'help text', |
|
1588 | + 'label' => 'Text input example label' |
|
1589 | + )); |
|
1590 | + |
|
1591 | + // checkbox example |
|
1592 | + $output .= aui()->input(array( |
|
1593 | + 'type' => 'checkbox', |
|
1594 | + 'id' => 'checkbox-example', |
|
1595 | + 'name' => 'checkbox-example', |
|
1596 | + 'placeholder' => 'checkbox-example', |
|
1597 | + 'title' => 'Checkbox example', |
|
1598 | + 'value' => '1', |
|
1599 | + 'checked' => true, |
|
1600 | + 'required' => false, |
|
1601 | + 'help_text' => 'help text', |
|
1602 | + 'label' => 'Checkbox checked' |
|
1603 | + )); |
|
1604 | + |
|
1605 | + // checkbox example |
|
1606 | + $output .= aui()->input(array( |
|
1607 | + 'type' => 'checkbox', |
|
1608 | + 'id' => 'checkbox-example2', |
|
1609 | + 'name' => 'checkbox-example2', |
|
1610 | + 'placeholder' => 'checkbox-example', |
|
1611 | + 'title' => 'Checkbox example', |
|
1612 | + 'value' => '1', |
|
1613 | + 'checked' => false, |
|
1614 | + 'required' => false, |
|
1615 | + 'help_text' => 'help text', |
|
1616 | + 'label' => 'Checkbox un-checked' |
|
1617 | + )); |
|
1618 | + |
|
1619 | + // switch example |
|
1620 | + $output .= aui()->input(array( |
|
1621 | + 'type' => 'checkbox', |
|
1622 | + 'id' => 'switch-example', |
|
1623 | + 'name' => 'switch-example', |
|
1624 | + 'placeholder' => 'checkbox-example', |
|
1625 | + 'title' => 'Switch example', |
|
1626 | + 'value' => '1', |
|
1627 | + 'checked' => true, |
|
1628 | + 'switch' => true, |
|
1629 | + 'required' => false, |
|
1630 | + 'help_text' => 'help text', |
|
1631 | + 'label' => 'Switch on' |
|
1632 | + )); |
|
1633 | + |
|
1634 | + // switch example |
|
1635 | + $output .= aui()->input(array( |
|
1636 | + 'type' => 'checkbox', |
|
1637 | + 'id' => 'switch-example2', |
|
1638 | + 'name' => 'switch-example2', |
|
1639 | + 'placeholder' => 'checkbox-example', |
|
1640 | + 'title' => 'Switch example', |
|
1641 | + 'value' => '1', |
|
1642 | + 'checked' => false, |
|
1643 | + 'switch' => true, |
|
1644 | + 'required' => false, |
|
1645 | + 'help_text' => 'help text', |
|
1646 | + 'label' => 'Switch off' |
|
1647 | + )); |
|
1648 | + |
|
1649 | + // close form |
|
1650 | + $output .= "</form>"; |
|
1651 | + |
|
1652 | + return $output; |
|
1653 | + } |
|
1654 | + |
|
1655 | + } |
|
1656 | + |
|
1657 | + /** |
|
1658 | + * Run the class if found. |
|
1659 | + */ |
|
1660 | + AyeCode_UI_Settings::instance(); |
|
1661 | 1661 | } |
1662 | 1662 | \ No newline at end of file |
@@ -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,231 +11,231 @@ discard block |
||
11 | 11 | */ |
12 | 12 | class AUI { |
13 | 13 | |
14 | - /** |
|
15 | - * Holds the class instance. |
|
16 | - * |
|
17 | - * @since 1.0.0 |
|
18 | - * @var null |
|
19 | - */ |
|
20 | - private static $instance = null; |
|
21 | - |
|
22 | - /** |
|
23 | - * Holds the current AUI version number. |
|
24 | - * |
|
25 | - * @var string $ver The current version number. |
|
26 | - */ |
|
27 | - public static $ver = '0.1.43'; |
|
28 | - |
|
29 | - public static $options = null; |
|
30 | - |
|
31 | - /** |
|
32 | - * There can be only one. |
|
33 | - * |
|
34 | - * @since 1.0.0 |
|
35 | - * @return AUI|null |
|
36 | - */ |
|
37 | - public static function instance() { |
|
38 | - if ( self::$instance == null ) { |
|
39 | - self::$instance = new AUI(); |
|
40 | - } |
|
41 | - |
|
42 | - return self::$instance; |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * AUI constructor. |
|
47 | - * |
|
48 | - * @since 1.0.0 |
|
49 | - */ |
|
50 | - private function __construct() { |
|
51 | - if ( function_exists( "__autoload" ) ) { |
|
52 | - spl_autoload_register( "__autoload" ); |
|
53 | - } |
|
54 | - spl_autoload_register( array( $this, 'autoload' ) ); |
|
55 | - |
|
56 | - // load options |
|
57 | - self::$options = get_option('aui_options'); |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Autoload any components on the fly. |
|
62 | - * |
|
63 | - * @since 1.0.0 |
|
64 | - * |
|
65 | - * @param $classname |
|
66 | - */ |
|
67 | - private function autoload( $classname ) { |
|
68 | - $class = str_replace( '_', '-', strtolower( $classname ) ); |
|
69 | - $file_path = trailingslashit( dirname( __FILE__ ) ) . "components/class-" . $class . '.php'; |
|
70 | - if ( $file_path && is_readable( $file_path ) ) { |
|
71 | - include_once( $file_path ); |
|
72 | - } |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Get the AUI options. |
|
77 | - * |
|
78 | - * @param $option |
|
79 | - * |
|
80 | - * @return string|void |
|
81 | - */ |
|
82 | - public function get_option( $option ){ |
|
83 | - $result = isset(self::$options[$option]) ? esc_attr(self::$options[$option]) : ''; |
|
84 | - |
|
85 | - if ( ! $result && $option) { |
|
86 | - if( $option == 'color_primary' ){ |
|
87 | - $result = AUI_PRIMARY_COLOR; |
|
88 | - }elseif( $option == 'color_secondary' ){ |
|
89 | - $result = AUI_SECONDARY_COLOR; |
|
90 | - } |
|
91 | - } |
|
92 | - return $result; |
|
93 | - } |
|
94 | - |
|
95 | - public function render( $items = array() ) { |
|
96 | - $output = ''; |
|
97 | - |
|
98 | - if ( ! empty( $items ) ) { |
|
99 | - foreach ( $items as $args ) { |
|
100 | - $render = isset( $args['render'] ) ? $args['render'] : ''; |
|
101 | - if ( $render && method_exists( __CLASS__, $render ) ) { |
|
102 | - $output .= $this->$render( $args ); |
|
103 | - } |
|
104 | - } |
|
105 | - } |
|
106 | - |
|
107 | - return $output; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Render and return a bootstrap alert component. |
|
112 | - * |
|
113 | - * @since 1.0.0 |
|
114 | - * |
|
115 | - * @param array $args |
|
116 | - * |
|
117 | - * @return string The rendered component. |
|
118 | - */ |
|
119 | - public function alert( $args = array() ) { |
|
120 | - return AUI_Component_Alert::get( $args ); |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Render and return a bootstrap input component. |
|
125 | - * |
|
126 | - * @since 1.0.0 |
|
127 | - * |
|
128 | - * @param array $args |
|
129 | - * |
|
130 | - * @return string The rendered component. |
|
131 | - */ |
|
132 | - public function input( $args = array() ) { |
|
133 | - return AUI_Component_Input::input( $args ); |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Render and return a bootstrap textarea component. |
|
138 | - * |
|
139 | - * @since 1.0.0 |
|
140 | - * |
|
141 | - * @param array $args |
|
142 | - * |
|
143 | - * @return string The rendered component. |
|
144 | - */ |
|
145 | - public function textarea( $args = array() ) { |
|
146 | - return AUI_Component_Input::textarea( $args ); |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * Render and return a bootstrap button component. |
|
151 | - * |
|
152 | - * @since 1.0.0 |
|
153 | - * |
|
154 | - * @param array $args |
|
155 | - * |
|
156 | - * @return string The rendered component. |
|
157 | - */ |
|
158 | - public function button( $args = array() ) { |
|
159 | - return AUI_Component_Button::get( $args ); |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * Render and return a bootstrap button component. |
|
164 | - * |
|
165 | - * @since 1.0.0 |
|
166 | - * |
|
167 | - * @param array $args |
|
168 | - * |
|
169 | - * @return string The rendered component. |
|
170 | - */ |
|
171 | - public function badge( $args = array() ) { |
|
172 | - $defaults = array( |
|
173 | - 'class' => 'badge badge-primary align-middle', |
|
174 | - ); |
|
175 | - |
|
176 | - // maybe set type |
|
177 | - if ( empty( $args['href'] ) ) { |
|
178 | - $defaults['type'] = 'badge'; |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * Parse incoming $args into an array and merge it with $defaults |
|
183 | - */ |
|
184 | - $args = wp_parse_args( $args, $defaults ); |
|
185 | - |
|
186 | - return AUI_Component_Button::get( $args ); |
|
187 | - } |
|
188 | - |
|
189 | - /** |
|
190 | - * Render and return a bootstrap dropdown component. |
|
191 | - * |
|
192 | - * @since 1.0.0 |
|
193 | - * |
|
194 | - * @param array $args |
|
195 | - * |
|
196 | - * @return string The rendered component. |
|
197 | - */ |
|
198 | - public function dropdown( $args = array() ) { |
|
199 | - return AUI_Component_Dropdown::get( $args ); |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * Render and return a bootstrap select component. |
|
204 | - * |
|
205 | - * @since 1.0.0 |
|
206 | - * |
|
207 | - * @param array $args |
|
208 | - * |
|
209 | - * @return string The rendered component. |
|
210 | - */ |
|
211 | - public function select( $args = array() ) { |
|
212 | - return AUI_Component_Input::select( $args ); |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * Render and return a bootstrap radio component. |
|
217 | - * |
|
218 | - * @since 1.0.0 |
|
219 | - * |
|
220 | - * @param array $args |
|
221 | - * |
|
222 | - * @return string The rendered component. |
|
223 | - */ |
|
224 | - public function radio( $args = array() ) { |
|
225 | - return AUI_Component_Input::radio( $args ); |
|
226 | - } |
|
227 | - |
|
228 | - /** |
|
229 | - * Render and return a bootstrap pagination component. |
|
230 | - * |
|
231 | - * @since 1.0.0 |
|
232 | - * |
|
233 | - * @param array $args |
|
234 | - * |
|
235 | - * @return string The rendered component. |
|
236 | - */ |
|
237 | - public function pagination( $args = array() ) { |
|
238 | - return AUI_Component_Pagination::get( $args ); |
|
239 | - } |
|
14 | + /** |
|
15 | + * Holds the class instance. |
|
16 | + * |
|
17 | + * @since 1.0.0 |
|
18 | + * @var null |
|
19 | + */ |
|
20 | + private static $instance = null; |
|
21 | + |
|
22 | + /** |
|
23 | + * Holds the current AUI version number. |
|
24 | + * |
|
25 | + * @var string $ver The current version number. |
|
26 | + */ |
|
27 | + public static $ver = '0.1.43'; |
|
28 | + |
|
29 | + public static $options = null; |
|
30 | + |
|
31 | + /** |
|
32 | + * There can be only one. |
|
33 | + * |
|
34 | + * @since 1.0.0 |
|
35 | + * @return AUI|null |
|
36 | + */ |
|
37 | + public static function instance() { |
|
38 | + if ( self::$instance == null ) { |
|
39 | + self::$instance = new AUI(); |
|
40 | + } |
|
41 | + |
|
42 | + return self::$instance; |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * AUI constructor. |
|
47 | + * |
|
48 | + * @since 1.0.0 |
|
49 | + */ |
|
50 | + private function __construct() { |
|
51 | + if ( function_exists( "__autoload" ) ) { |
|
52 | + spl_autoload_register( "__autoload" ); |
|
53 | + } |
|
54 | + spl_autoload_register( array( $this, 'autoload' ) ); |
|
55 | + |
|
56 | + // load options |
|
57 | + self::$options = get_option('aui_options'); |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Autoload any components on the fly. |
|
62 | + * |
|
63 | + * @since 1.0.0 |
|
64 | + * |
|
65 | + * @param $classname |
|
66 | + */ |
|
67 | + private function autoload( $classname ) { |
|
68 | + $class = str_replace( '_', '-', strtolower( $classname ) ); |
|
69 | + $file_path = trailingslashit( dirname( __FILE__ ) ) . "components/class-" . $class . '.php'; |
|
70 | + if ( $file_path && is_readable( $file_path ) ) { |
|
71 | + include_once( $file_path ); |
|
72 | + } |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Get the AUI options. |
|
77 | + * |
|
78 | + * @param $option |
|
79 | + * |
|
80 | + * @return string|void |
|
81 | + */ |
|
82 | + public function get_option( $option ){ |
|
83 | + $result = isset(self::$options[$option]) ? esc_attr(self::$options[$option]) : ''; |
|
84 | + |
|
85 | + if ( ! $result && $option) { |
|
86 | + if( $option == 'color_primary' ){ |
|
87 | + $result = AUI_PRIMARY_COLOR; |
|
88 | + }elseif( $option == 'color_secondary' ){ |
|
89 | + $result = AUI_SECONDARY_COLOR; |
|
90 | + } |
|
91 | + } |
|
92 | + return $result; |
|
93 | + } |
|
94 | + |
|
95 | + public function render( $items = array() ) { |
|
96 | + $output = ''; |
|
97 | + |
|
98 | + if ( ! empty( $items ) ) { |
|
99 | + foreach ( $items as $args ) { |
|
100 | + $render = isset( $args['render'] ) ? $args['render'] : ''; |
|
101 | + if ( $render && method_exists( __CLASS__, $render ) ) { |
|
102 | + $output .= $this->$render( $args ); |
|
103 | + } |
|
104 | + } |
|
105 | + } |
|
106 | + |
|
107 | + return $output; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Render and return a bootstrap alert component. |
|
112 | + * |
|
113 | + * @since 1.0.0 |
|
114 | + * |
|
115 | + * @param array $args |
|
116 | + * |
|
117 | + * @return string The rendered component. |
|
118 | + */ |
|
119 | + public function alert( $args = array() ) { |
|
120 | + return AUI_Component_Alert::get( $args ); |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Render and return a bootstrap input component. |
|
125 | + * |
|
126 | + * @since 1.0.0 |
|
127 | + * |
|
128 | + * @param array $args |
|
129 | + * |
|
130 | + * @return string The rendered component. |
|
131 | + */ |
|
132 | + public function input( $args = array() ) { |
|
133 | + return AUI_Component_Input::input( $args ); |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Render and return a bootstrap textarea component. |
|
138 | + * |
|
139 | + * @since 1.0.0 |
|
140 | + * |
|
141 | + * @param array $args |
|
142 | + * |
|
143 | + * @return string The rendered component. |
|
144 | + */ |
|
145 | + public function textarea( $args = array() ) { |
|
146 | + return AUI_Component_Input::textarea( $args ); |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * Render and return a bootstrap button component. |
|
151 | + * |
|
152 | + * @since 1.0.0 |
|
153 | + * |
|
154 | + * @param array $args |
|
155 | + * |
|
156 | + * @return string The rendered component. |
|
157 | + */ |
|
158 | + public function button( $args = array() ) { |
|
159 | + return AUI_Component_Button::get( $args ); |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Render and return a bootstrap button component. |
|
164 | + * |
|
165 | + * @since 1.0.0 |
|
166 | + * |
|
167 | + * @param array $args |
|
168 | + * |
|
169 | + * @return string The rendered component. |
|
170 | + */ |
|
171 | + public function badge( $args = array() ) { |
|
172 | + $defaults = array( |
|
173 | + 'class' => 'badge badge-primary align-middle', |
|
174 | + ); |
|
175 | + |
|
176 | + // maybe set type |
|
177 | + if ( empty( $args['href'] ) ) { |
|
178 | + $defaults['type'] = 'badge'; |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * Parse incoming $args into an array and merge it with $defaults |
|
183 | + */ |
|
184 | + $args = wp_parse_args( $args, $defaults ); |
|
185 | + |
|
186 | + return AUI_Component_Button::get( $args ); |
|
187 | + } |
|
188 | + |
|
189 | + /** |
|
190 | + * Render and return a bootstrap dropdown component. |
|
191 | + * |
|
192 | + * @since 1.0.0 |
|
193 | + * |
|
194 | + * @param array $args |
|
195 | + * |
|
196 | + * @return string The rendered component. |
|
197 | + */ |
|
198 | + public function dropdown( $args = array() ) { |
|
199 | + return AUI_Component_Dropdown::get( $args ); |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * Render and return a bootstrap select component. |
|
204 | + * |
|
205 | + * @since 1.0.0 |
|
206 | + * |
|
207 | + * @param array $args |
|
208 | + * |
|
209 | + * @return string The rendered component. |
|
210 | + */ |
|
211 | + public function select( $args = array() ) { |
|
212 | + return AUI_Component_Input::select( $args ); |
|
213 | + } |
|
214 | + |
|
215 | + /** |
|
216 | + * Render and return a bootstrap radio component. |
|
217 | + * |
|
218 | + * @since 1.0.0 |
|
219 | + * |
|
220 | + * @param array $args |
|
221 | + * |
|
222 | + * @return string The rendered component. |
|
223 | + */ |
|
224 | + public function radio( $args = array() ) { |
|
225 | + return AUI_Component_Input::radio( $args ); |
|
226 | + } |
|
227 | + |
|
228 | + /** |
|
229 | + * Render and return a bootstrap pagination component. |
|
230 | + * |
|
231 | + * @since 1.0.0 |
|
232 | + * |
|
233 | + * @param array $args |
|
234 | + * |
|
235 | + * @return string The rendered component. |
|
236 | + */ |
|
237 | + public function pagination( $args = array() ) { |
|
238 | + return AUI_Component_Pagination::get( $args ); |
|
239 | + } |
|
240 | 240 | |
241 | 241 | } |
242 | 242 | \ No newline at end of file |
@@ -12,8 +12,8 @@ discard block |
||
12 | 12 | class InstalledVersions |
13 | 13 | { |
14 | 14 | private static $installed = array ( |
15 | - 'root' => |
|
16 | - array ( |
|
15 | + 'root' => |
|
16 | + array ( |
|
17 | 17 | 'pretty_version' => 'dev-master', |
18 | 18 | 'version' => 'dev-master', |
19 | 19 | 'aliases' => |
@@ -21,87 +21,87 @@ discard block |
||
21 | 21 | ), |
22 | 22 | 'reference' => '78277f1999221a9d2aa36ed867119bc4dd9b9ba5', |
23 | 23 | 'name' => 'ayecode/invoicing', |
24 | - ), |
|
25 | - 'versions' => |
|
26 | - array ( |
|
24 | + ), |
|
25 | + 'versions' => |
|
26 | + array ( |
|
27 | 27 | 'ayecode/ayecode-connect-helper' => |
28 | 28 | array ( |
29 | - 'pretty_version' => '1.0.3', |
|
30 | - 'version' => '1.0.3.0', |
|
31 | - 'aliases' => |
|
32 | - array ( |
|
33 | - ), |
|
34 | - 'reference' => '1af7cdefdbd20d4443a3ab4834e4c1cd8fe57fb4', |
|
29 | + 'pretty_version' => '1.0.3', |
|
30 | + 'version' => '1.0.3.0', |
|
31 | + 'aliases' => |
|
32 | + array ( |
|
33 | + ), |
|
34 | + 'reference' => '1af7cdefdbd20d4443a3ab4834e4c1cd8fe57fb4', |
|
35 | 35 | ), |
36 | 36 | 'ayecode/invoicing' => |
37 | 37 | array ( |
38 | - 'pretty_version' => 'dev-master', |
|
39 | - 'version' => 'dev-master', |
|
40 | - 'aliases' => |
|
41 | - array ( |
|
42 | - ), |
|
43 | - 'reference' => '78277f1999221a9d2aa36ed867119bc4dd9b9ba5', |
|
38 | + 'pretty_version' => 'dev-master', |
|
39 | + 'version' => 'dev-master', |
|
40 | + 'aliases' => |
|
41 | + array ( |
|
42 | + ), |
|
43 | + 'reference' => '78277f1999221a9d2aa36ed867119bc4dd9b9ba5', |
|
44 | 44 | ), |
45 | 45 | 'ayecode/wp-ayecode-ui' => |
46 | 46 | array ( |
47 | - 'pretty_version' => '0.1.43', |
|
48 | - 'version' => '0.1.43.0', |
|
49 | - 'aliases' => |
|
50 | - array ( |
|
51 | - ), |
|
52 | - 'reference' => '3606edd468c8a502df34237d0ac9e3470f2ad08d', |
|
47 | + 'pretty_version' => '0.1.43', |
|
48 | + 'version' => '0.1.43.0', |
|
49 | + 'aliases' => |
|
50 | + array ( |
|
51 | + ), |
|
52 | + 'reference' => '3606edd468c8a502df34237d0ac9e3470f2ad08d', |
|
53 | 53 | ), |
54 | 54 | 'ayecode/wp-font-awesome-settings' => |
55 | 55 | array ( |
56 | - 'pretty_version' => '1.0.12', |
|
57 | - 'version' => '1.0.12.0', |
|
58 | - 'aliases' => |
|
59 | - array ( |
|
60 | - ), |
|
61 | - 'reference' => '754cca6fda775f3e0b56b90a810dfcaea62ea288', |
|
56 | + 'pretty_version' => '1.0.12', |
|
57 | + 'version' => '1.0.12.0', |
|
58 | + 'aliases' => |
|
59 | + array ( |
|
60 | + ), |
|
61 | + 'reference' => '754cca6fda775f3e0b56b90a810dfcaea62ea288', |
|
62 | 62 | ), |
63 | 63 | 'ayecode/wp-super-duper' => |
64 | 64 | array ( |
65 | - 'pretty_version' => '1.0.24', |
|
66 | - 'version' => '1.0.24.0', |
|
67 | - 'aliases' => |
|
68 | - array ( |
|
69 | - ), |
|
70 | - 'reference' => '4eaa2f6f6e1a29ff71f7fdbd694892d7479ef754', |
|
65 | + 'pretty_version' => '1.0.24', |
|
66 | + 'version' => '1.0.24.0', |
|
67 | + 'aliases' => |
|
68 | + array ( |
|
69 | + ), |
|
70 | + 'reference' => '4eaa2f6f6e1a29ff71f7fdbd694892d7479ef754', |
|
71 | 71 | ), |
72 | 72 | 'composer/installers' => |
73 | 73 | array ( |
74 | - 'pretty_version' => 'v1.10.0', |
|
75 | - 'version' => '1.10.0.0', |
|
76 | - 'aliases' => |
|
77 | - array ( |
|
78 | - ), |
|
79 | - 'reference' => '1a0357fccad9d1cc1ea0c9a05b8847fbccccb78d', |
|
74 | + 'pretty_version' => 'v1.10.0', |
|
75 | + 'version' => '1.10.0.0', |
|
76 | + 'aliases' => |
|
77 | + array ( |
|
78 | + ), |
|
79 | + 'reference' => '1a0357fccad9d1cc1ea0c9a05b8847fbccccb78d', |
|
80 | 80 | ), |
81 | 81 | 'maxmind-db/reader' => |
82 | 82 | array ( |
83 | - 'pretty_version' => 'v1.6.0', |
|
84 | - 'version' => '1.6.0.0', |
|
85 | - 'aliases' => |
|
86 | - array ( |
|
87 | - ), |
|
88 | - 'reference' => 'febd4920bf17c1da84cef58e56a8227dfb37fbe4', |
|
83 | + 'pretty_version' => 'v1.6.0', |
|
84 | + 'version' => '1.6.0.0', |
|
85 | + 'aliases' => |
|
86 | + array ( |
|
87 | + ), |
|
88 | + 'reference' => 'febd4920bf17c1da84cef58e56a8227dfb37fbe4', |
|
89 | 89 | ), |
90 | 90 | 'roundcube/plugin-installer' => |
91 | 91 | array ( |
92 | - 'replaced' => |
|
93 | - array ( |
|
92 | + 'replaced' => |
|
93 | + array ( |
|
94 | 94 | 0 => '*', |
95 | - ), |
|
95 | + ), |
|
96 | 96 | ), |
97 | 97 | 'shama/baton' => |
98 | 98 | array ( |
99 | - 'replaced' => |
|
100 | - array ( |
|
99 | + 'replaced' => |
|
100 | + array ( |
|
101 | 101 | 0 => '*', |
102 | - ), |
|
102 | + ), |
|
103 | + ), |
|
103 | 104 | ), |
104 | - ), |
|
105 | 105 | ); |
106 | 106 | |
107 | 107 |