@@ -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 | } |
@@ -14,77 +14,77 @@ discard block |
||
14 | 14 | class GetPaid_Admin { |
15 | 15 | |
16 | 16 | /** |
17 | - * Local path to this plugins admin directory |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - public $admin_path; |
|
22 | - |
|
23 | - /** |
|
24 | - * Web path to this plugins admin directory |
|
25 | - * |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - public $admin_url; |
|
17 | + * Local path to this plugins admin directory |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + public $admin_path; |
|
22 | + |
|
23 | + /** |
|
24 | + * Web path to this plugins admin directory |
|
25 | + * |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + public $admin_url; |
|
29 | 29 | |
30 | - /** |
|
31 | - * Reports components. |
|
32 | - * |
|
33 | - * @var GetPaid_Reports |
|
34 | - */ |
|
30 | + /** |
|
31 | + * Reports components. |
|
32 | + * |
|
33 | + * @var GetPaid_Reports |
|
34 | + */ |
|
35 | 35 | public $reports; |
36 | 36 | |
37 | 37 | /** |
38 | - * Class constructor. |
|
39 | - */ |
|
40 | - public function __construct(){ |
|
38 | + * Class constructor. |
|
39 | + */ |
|
40 | + public function __construct(){ |
|
41 | 41 | |
42 | 42 | $this->admin_path = plugin_dir_path( __FILE__ ); |
43 | - $this->admin_url = plugins_url( '/', __FILE__ ); |
|
44 | - $this->reports = new GetPaid_Reports(); |
|
43 | + $this->admin_url = plugins_url( '/', __FILE__ ); |
|
44 | + $this->reports = new GetPaid_Reports(); |
|
45 | 45 | |
46 | 46 | if ( is_admin() ) { |
47 | - $this->init_admin_hooks(); |
|
47 | + $this->init_admin_hooks(); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
53 | - * Init action and filter hooks |
|
54 | - * |
|
55 | - */ |
|
56 | - private function init_admin_hooks() { |
|
53 | + * Init action and filter hooks |
|
54 | + * |
|
55 | + */ |
|
56 | + private function init_admin_hooks() { |
|
57 | 57 | add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ) ); |
58 | 58 | add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
59 | 59 | add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) ); |
60 | 60 | add_action( 'admin_init', array( $this, 'activation_redirect') ); |
61 | 61 | add_action( 'admin_init', array( $this, 'maybe_do_admin_action') ); |
62 | - add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
63 | - add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) ); |
|
64 | - add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
65 | - add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
62 | + add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
63 | + add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) ); |
|
64 | + add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
65 | + add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
66 | 66 | add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) ); |
67 | - add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
68 | - add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
69 | - add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
70 | - add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) ); |
|
71 | - add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
72 | - do_action( 'getpaid_init_admin_hooks', $this ); |
|
67 | + add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
68 | + add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
69 | + add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
70 | + add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) ); |
|
71 | + add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
72 | + do_action( 'getpaid_init_admin_hooks', $this ); |
|
73 | 73 | |
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
77 | - * Register admin scripts |
|
78 | - * |
|
79 | - */ |
|
80 | - public function enqeue_scripts() { |
|
77 | + * Register admin scripts |
|
78 | + * |
|
79 | + */ |
|
80 | + public function enqeue_scripts() { |
|
81 | 81 | global $current_screen, $pagenow; |
82 | 82 | |
83 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
84 | - $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
83 | + $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
84 | + $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
85 | 85 | |
86 | 86 | if ( ! empty( $current_screen->post_type ) ) { |
87 | - $page = $current_screen->post_type; |
|
87 | + $page = $current_screen->post_type; |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | // General styles. |
@@ -105,54 +105,54 @@ discard block |
||
105 | 105 | } |
106 | 106 | |
107 | 107 | // Payment form scripts. |
108 | - if ( 'wpi_payment_form' == $page && $editing ) { |
|
108 | + if ( 'wpi_payment_form' == $page && $editing ) { |
|
109 | 109 | $this->load_payment_form_scripts(); |
110 | 110 | } |
111 | 111 | |
112 | - if ( $page == 'wpinv-subscriptions' ) { |
|
113 | - wp_enqueue_script( 'postbox' ); |
|
114 | - } |
|
112 | + if ( $page == 'wpinv-subscriptions' ) { |
|
113 | + wp_enqueue_script( 'postbox' ); |
|
114 | + } |
|
115 | 115 | |
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
119 | - * Returns admin js translations. |
|
120 | - * |
|
121 | - */ |
|
122 | - protected function get_admin_i18() { |
|
119 | + * Returns admin js translations. |
|
120 | + * |
|
121 | + */ |
|
122 | + protected function get_admin_i18() { |
|
123 | 123 | global $post; |
124 | 124 | |
125 | - $date_range = array( |
|
126 | - 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days' |
|
127 | - ); |
|
125 | + $date_range = array( |
|
126 | + 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days' |
|
127 | + ); |
|
128 | 128 | |
129 | - if ( $date_range['period'] == 'custom' ) { |
|
129 | + if ( $date_range['period'] == 'custom' ) { |
|
130 | 130 | |
131 | - if ( isset( $_GET['from'] ) ) { |
|
132 | - $date_range[ 'after' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
133 | - } |
|
131 | + if ( isset( $_GET['from'] ) ) { |
|
132 | + $date_range[ 'after' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
133 | + } |
|
134 | 134 | |
135 | - if ( isset( $_GET['to'] ) ) { |
|
136 | - $date_range[ 'before' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
137 | - } |
|
135 | + if ( isset( $_GET['to'] ) ) { |
|
136 | + $date_range[ 'before' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
137 | + } |
|
138 | 138 | |
139 | - } |
|
139 | + } |
|
140 | 140 | |
141 | 141 | $i18n = array( |
142 | 142 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
143 | 143 | 'post_ID' => isset( $post->ID ) ? $post->ID : '', |
144 | - 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
145 | - 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
146 | - 'rest_root' => esc_url_raw( rest_url() ), |
|
147 | - 'date_range' => $date_range, |
|
144 | + 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
145 | + 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
146 | + 'rest_root' => esc_url_raw( rest_url() ), |
|
147 | + 'date_range' => $date_range, |
|
148 | 148 | 'add_invoice_note_nonce' => wp_create_nonce( 'add-invoice-note' ), |
149 | 149 | 'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ), |
150 | 150 | 'invoice_item_nonce' => wp_create_nonce( 'invoice-item' ), |
151 | 151 | 'billing_details_nonce' => wp_create_nonce( 'get-billing-details' ), |
152 | 152 | 'tax' => wpinv_tax_amount(), |
153 | 153 | 'discount' => 0, |
154 | - 'currency_symbol' => wpinv_currency_symbol(), |
|
155 | - 'currency' => wpinv_get_currency(), |
|
154 | + 'currency_symbol' => wpinv_currency_symbol(), |
|
155 | + 'currency' => wpinv_get_currency(), |
|
156 | 156 | 'currency_pos' => wpinv_currency_position(), |
157 | 157 | 'thousand_sep' => wpinv_thousands_separator(), |
158 | 158 | 'decimal_sep' => wpinv_decimal_separator(), |
@@ -172,117 +172,117 @@ discard block |
||
172 | 172 | 'item_description' => __( 'Item Description', 'invoicing' ), |
173 | 173 | 'invoice_description' => __( 'Invoice Description', 'invoicing' ), |
174 | 174 | 'discount_description' => __( 'Discount Description', 'invoicing' ), |
175 | - 'searching' => __( 'Searching', 'invoicing' ), |
|
176 | - 'loading' => __( 'Loading...', 'invoicing' ), |
|
177 | - 'search_customers' => __( 'Enter customer name or email', 'invoicing' ), |
|
175 | + 'searching' => __( 'Searching', 'invoicing' ), |
|
176 | + 'loading' => __( 'Loading...', 'invoicing' ), |
|
177 | + 'search_customers' => __( 'Enter customer name or email', 'invoicing' ), |
|
178 | 178 | ); |
179 | 179 | |
180 | - if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
180 | + if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
181 | 181 | |
182 | - $invoice = new WPInv_Invoice( $post ); |
|
183 | - $i18n['save_invoice'] = sprintf( |
|
184 | - __( 'Save %s', 'invoicing' ), |
|
185 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
186 | - ); |
|
182 | + $invoice = new WPInv_Invoice( $post ); |
|
183 | + $i18n['save_invoice'] = sprintf( |
|
184 | + __( 'Save %s', 'invoicing' ), |
|
185 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
186 | + ); |
|
187 | 187 | |
188 | - $i18n['invoice_description'] = sprintf( |
|
189 | - __( '%s Description', 'invoicing' ), |
|
190 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
191 | - ); |
|
188 | + $i18n['invoice_description'] = sprintf( |
|
189 | + __( '%s Description', 'invoicing' ), |
|
190 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
191 | + ); |
|
192 | 192 | |
193 | - } |
|
194 | - return $i18n; |
|
195 | - } |
|
193 | + } |
|
194 | + return $i18n; |
|
195 | + } |
|
196 | 196 | |
197 | - /** |
|
198 | - * Change the admin footer text on GetPaid admin pages. |
|
199 | - * |
|
200 | - * @since 2.0.0 |
|
201 | - * @param string $footer_text |
|
202 | - * @return string |
|
203 | - */ |
|
204 | - public function admin_footer_text( $footer_text ) { |
|
205 | - global $current_screen; |
|
197 | + /** |
|
198 | + * Change the admin footer text on GetPaid admin pages. |
|
199 | + * |
|
200 | + * @since 2.0.0 |
|
201 | + * @param string $footer_text |
|
202 | + * @return string |
|
203 | + */ |
|
204 | + public function admin_footer_text( $footer_text ) { |
|
205 | + global $current_screen; |
|
206 | 206 | |
207 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
207 | + $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
208 | 208 | |
209 | 209 | if ( ! empty( $current_screen->post_type ) ) { |
210 | - $page = $current_screen->post_type; |
|
210 | + $page = $current_screen->post_type; |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | // General styles. |
214 | 214 | if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) { |
215 | 215 | |
216 | - // Change the footer text |
|
217 | - if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
218 | - |
|
219 | - $rating_url = esc_url( |
|
220 | - wp_nonce_url( |
|
221 | - admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
222 | - 'getpaid-nonce', |
|
223 | - 'getpaid-nonce' |
|
224 | - ) |
|
225 | - ); |
|
226 | - |
|
227 | - $footer_text = sprintf( |
|
228 | - /* translators: %s: five stars */ |
|
229 | - __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
230 | - "<a href='$rating_url'>★★★★★</a>" |
|
231 | - ); |
|
232 | - |
|
233 | - } else { |
|
234 | - |
|
235 | - $footer_text = sprintf( |
|
236 | - /* translators: %s: GetPaid */ |
|
237 | - __( 'Thank you for using %s!', 'invoicing' ), |
|
238 | - "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
|
239 | - ); |
|
240 | - |
|
241 | - } |
|
242 | - |
|
243 | - } |
|
244 | - |
|
245 | - return $footer_text; |
|
246 | - } |
|
247 | - |
|
248 | - /** |
|
249 | - * Redirects to wp.org to rate the plugin. |
|
250 | - * |
|
251 | - * @since 2.0.0 |
|
252 | - */ |
|
253 | - public function redirect_to_wordpress_rating_page() { |
|
254 | - update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
255 | - wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
256 | - exit; |
|
257 | - } |
|
216 | + // Change the footer text |
|
217 | + if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
218 | + |
|
219 | + $rating_url = esc_url( |
|
220 | + wp_nonce_url( |
|
221 | + admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
222 | + 'getpaid-nonce', |
|
223 | + 'getpaid-nonce' |
|
224 | + ) |
|
225 | + ); |
|
226 | + |
|
227 | + $footer_text = sprintf( |
|
228 | + /* translators: %s: five stars */ |
|
229 | + __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
230 | + "<a href='$rating_url'>★★★★★</a>" |
|
231 | + ); |
|
232 | + |
|
233 | + } else { |
|
234 | + |
|
235 | + $footer_text = sprintf( |
|
236 | + /* translators: %s: GetPaid */ |
|
237 | + __( 'Thank you for using %s!', 'invoicing' ), |
|
238 | + "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
|
239 | + ); |
|
240 | + |
|
241 | + } |
|
242 | + |
|
243 | + } |
|
244 | + |
|
245 | + return $footer_text; |
|
246 | + } |
|
258 | 247 | |
259 | 248 | /** |
260 | - * Loads payment form js. |
|
261 | - * |
|
262 | - */ |
|
263 | - protected function load_payment_form_scripts() { |
|
249 | + * Redirects to wp.org to rate the plugin. |
|
250 | + * |
|
251 | + * @since 2.0.0 |
|
252 | + */ |
|
253 | + public function redirect_to_wordpress_rating_page() { |
|
254 | + update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
255 | + wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
256 | + exit; |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * Loads payment form js. |
|
261 | + * |
|
262 | + */ |
|
263 | + protected function load_payment_form_scripts() { |
|
264 | 264 | global $post; |
265 | 265 | |
266 | 266 | wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION ); |
267 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
268 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
267 | + wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
268 | + wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
269 | 269 | |
270 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
271 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
270 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
271 | + wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
272 | 272 | |
273 | - wp_localize_script( |
|
273 | + wp_localize_script( |
|
274 | 274 | 'wpinv-admin-payment-form-script', |
275 | 275 | 'wpinvPaymentFormAdmin', |
276 | 276 | array( |
277 | - 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
278 | - 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
279 | - 'currency' => wpinv_currency_symbol(), |
|
280 | - 'position' => wpinv_currency_position(), |
|
281 | - 'decimals' => (int) wpinv_decimals(), |
|
282 | - 'thousands_sep' => wpinv_thousands_separator(), |
|
283 | - 'decimals_sep' => wpinv_decimal_separator(), |
|
284 | - 'form_items' => gepaid_get_form_items( $post->ID ), |
|
285 | - 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
277 | + 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
278 | + 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
279 | + 'currency' => wpinv_currency_symbol(), |
|
280 | + 'position' => wpinv_currency_position(), |
|
281 | + 'decimals' => (int) wpinv_decimals(), |
|
282 | + 'thousands_sep' => wpinv_thousands_separator(), |
|
283 | + 'decimals_sep' => wpinv_decimal_separator(), |
|
284 | + 'form_items' => gepaid_get_form_items( $post->ID ), |
|
285 | + 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
286 | 286 | ) |
287 | 287 | ); |
288 | 288 | |
@@ -291,20 +291,20 @@ discard block |
||
291 | 291 | } |
292 | 292 | |
293 | 293 | /** |
294 | - * Add our classes to admin pages. |
|
294 | + * Add our classes to admin pages. |
|
295 | 295 | * |
296 | 296 | * @param string $classes |
297 | 297 | * @return string |
298 | - * |
|
299 | - */ |
|
298 | + * |
|
299 | + */ |
|
300 | 300 | public function admin_body_class( $classes ) { |
301 | - global $pagenow, $post, $current_screen; |
|
301 | + global $pagenow, $post, $current_screen; |
|
302 | 302 | |
303 | 303 | |
304 | 304 | $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
305 | 305 | |
306 | 306 | if ( ! empty( $current_screen->post_type ) ) { |
307 | - $page = $current_screen->post_type; |
|
307 | + $page = $current_screen->post_type; |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | if ( false !== stripos( $page, 'wpi' ) ) { |
@@ -313,59 +313,59 @@ discard block |
||
313 | 313 | |
314 | 314 | if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) { |
315 | 315 | $classes .= ' wpinv-cpt wpinv'; |
316 | - } |
|
316 | + } |
|
317 | 317 | |
318 | - if ( getpaid_is_invoice_post_type( $page ) ) { |
|
318 | + if ( getpaid_is_invoice_post_type( $page ) ) { |
|
319 | 319 | $classes .= ' getpaid-is-invoice-cpt'; |
320 | 320 | } |
321 | 321 | |
322 | - return $classes; |
|
322 | + return $classes; |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | /** |
326 | - * Maybe show the AyeCode Connect Notice. |
|
327 | - */ |
|
328 | - public function init_ayecode_connect_helper(){ |
|
326 | + * Maybe show the AyeCode Connect Notice. |
|
327 | + */ |
|
328 | + public function init_ayecode_connect_helper(){ |
|
329 | 329 | |
330 | 330 | new AyeCode_Connect_Helper( |
331 | 331 | array( |
332 | - 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
333 | - 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
334 | - 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
335 | - 'connect_button' => __("Connect Site","invoicing"), |
|
336 | - 'connecting_button' => __("Connecting...","invoicing"), |
|
337 | - 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
338 | - 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
332 | + 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
333 | + 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
334 | + 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
335 | + 'connect_button' => __("Connect Site","invoicing"), |
|
336 | + 'connecting_button' => __("Connecting...","invoicing"), |
|
337 | + 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
338 | + 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
339 | 339 | ), |
340 | 340 | array( 'wpi-addons' ) |
341 | 341 | ); |
342 | 342 | |
343 | 343 | } |
344 | 344 | |
345 | - /** |
|
346 | - * Redirect users to settings on activation. |
|
347 | - * |
|
348 | - * @return void |
|
349 | - */ |
|
350 | - public function activation_redirect() { |
|
345 | + /** |
|
346 | + * Redirect users to settings on activation. |
|
347 | + * |
|
348 | + * @return void |
|
349 | + */ |
|
350 | + public function activation_redirect() { |
|
351 | 351 | |
352 | - $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
352 | + $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
353 | 353 | |
354 | - if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
355 | - return; |
|
356 | - } |
|
354 | + if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
355 | + return; |
|
356 | + } |
|
357 | 357 | |
358 | - // Bail if activating from network, or bulk |
|
359 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
360 | - return; |
|
361 | - } |
|
358 | + // Bail if activating from network, or bulk |
|
359 | + if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
360 | + return; |
|
361 | + } |
|
362 | 362 | |
363 | - update_option( 'wpinv_redirected_to_settings', 1 ); |
|
363 | + update_option( 'wpinv_redirected_to_settings', 1 ); |
|
364 | 364 | |
365 | 365 | wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
366 | 366 | exit; |
367 | 367 | |
368 | - } |
|
368 | + } |
|
369 | 369 | |
370 | 370 | /** |
371 | 371 | * Fires an admin action after verifying that a user can fire them. |
@@ -379,304 +379,304 @@ discard block |
||
379 | 379 | |
380 | 380 | } |
381 | 381 | |
382 | - /** |
|
382 | + /** |
|
383 | 383 | * Sends a payment reminder to a customer. |
384 | - * |
|
385 | - * @param array $args |
|
384 | + * |
|
385 | + * @param array $args |
|
386 | 386 | */ |
387 | 387 | public function send_customer_invoice( $args ) { |
388 | - $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
388 | + $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
389 | 389 | |
390 | - if ( $sent ) { |
|
391 | - $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) ); |
|
392 | - } else { |
|
393 | - $this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) ); |
|
394 | - } |
|
390 | + if ( $sent ) { |
|
391 | + $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) ); |
|
392 | + } else { |
|
393 | + $this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) ); |
|
394 | + } |
|
395 | 395 | |
396 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
397 | - exit; |
|
398 | - } |
|
396 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
397 | + exit; |
|
398 | + } |
|
399 | 399 | |
400 | - /** |
|
400 | + /** |
|
401 | 401 | * Sends a payment reminder to a customer. |
402 | - * |
|
403 | - * @param array $args |
|
402 | + * |
|
403 | + * @param array $args |
|
404 | 404 | */ |
405 | 405 | public function send_customer_payment_reminder( $args ) { |
406 | - $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
406 | + $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
407 | 407 | |
408 | - if ( $sent ) { |
|
409 | - $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
410 | - } else { |
|
411 | - $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
412 | - } |
|
408 | + if ( $sent ) { |
|
409 | + $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
410 | + } else { |
|
411 | + $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
412 | + } |
|
413 | 413 | |
414 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
415 | - exit; |
|
416 | - } |
|
414 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
415 | + exit; |
|
416 | + } |
|
417 | 417 | |
418 | - /** |
|
418 | + /** |
|
419 | 419 | * Resets tax rates. |
420 | - * |
|
420 | + * |
|
421 | 421 | */ |
422 | 422 | public function admin_reset_tax_rates() { |
423 | 423 | |
424 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
425 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
426 | - exit; |
|
424 | + update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
425 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
426 | + exit; |
|
427 | 427 | |
428 | - } |
|
428 | + } |
|
429 | 429 | |
430 | - /** |
|
430 | + /** |
|
431 | 431 | * Resets admin pages. |
432 | - * |
|
432 | + * |
|
433 | 433 | */ |
434 | 434 | public function admin_create_missing_pages() { |
435 | - $installer = new GetPaid_Installer(); |
|
436 | - $installer->create_pages(); |
|
437 | - $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
438 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
439 | - exit; |
|
440 | - } |
|
441 | - |
|
442 | - /** |
|
435 | + $installer = new GetPaid_Installer(); |
|
436 | + $installer->create_pages(); |
|
437 | + $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
438 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
439 | + exit; |
|
440 | + } |
|
441 | + |
|
442 | + /** |
|
443 | 443 | * Creates an missing admin tables. |
444 | - * |
|
444 | + * |
|
445 | 445 | */ |
446 | 446 | public function admin_create_missing_tables() { |
447 | - global $wpdb; |
|
448 | - $installer = new GetPaid_Installer(); |
|
447 | + global $wpdb; |
|
448 | + $installer = new GetPaid_Installer(); |
|
449 | 449 | |
450 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) { |
|
451 | - $installer->create_subscriptions_table(); |
|
450 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) { |
|
451 | + $installer->create_subscriptions_table(); |
|
452 | 452 | |
453 | - if ( $wpdb->last_error !== '' ) { |
|
454 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
455 | - } |
|
456 | - } |
|
453 | + if ( $wpdb->last_error !== '' ) { |
|
454 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
455 | + } |
|
456 | + } |
|
457 | 457 | |
458 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) { |
|
459 | - $installer->create_invoices_table(); |
|
458 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) { |
|
459 | + $installer->create_invoices_table(); |
|
460 | 460 | |
461 | - if ( $wpdb->last_error !== '' ) { |
|
462 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
463 | - } |
|
464 | - } |
|
461 | + if ( $wpdb->last_error !== '' ) { |
|
462 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
463 | + } |
|
464 | + } |
|
465 | 465 | |
466 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) { |
|
467 | - $installer->create_invoice_items_table(); |
|
466 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) { |
|
467 | + $installer->create_invoice_items_table(); |
|
468 | 468 | |
469 | - if ( $wpdb->last_error !== '' ) { |
|
470 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
471 | - } |
|
472 | - } |
|
469 | + if ( $wpdb->last_error !== '' ) { |
|
470 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
471 | + } |
|
472 | + } |
|
473 | 473 | |
474 | - if ( ! $this->has_notices() ) { |
|
475 | - $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
476 | - } |
|
474 | + if ( ! $this->has_notices() ) { |
|
475 | + $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
476 | + } |
|
477 | 477 | |
478 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
479 | - exit; |
|
480 | - } |
|
478 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
479 | + exit; |
|
480 | + } |
|
481 | 481 | |
482 | - /** |
|
482 | + /** |
|
483 | 483 | * Migrates old invoices to the new database tables. |
484 | - * |
|
484 | + * |
|
485 | 485 | */ |
486 | 486 | public function admin_migrate_old_invoices() { |
487 | 487 | |
488 | - // Migrate the invoices. |
|
489 | - $installer = new GetPaid_Installer(); |
|
490 | - $installer->migrate_old_invoices(); |
|
488 | + // Migrate the invoices. |
|
489 | + $installer = new GetPaid_Installer(); |
|
490 | + $installer->migrate_old_invoices(); |
|
491 | 491 | |
492 | - // Show an admin message. |
|
493 | - $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
492 | + // Show an admin message. |
|
493 | + $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
494 | 494 | |
495 | - // Redirect the admin. |
|
496 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
497 | - exit; |
|
495 | + // Redirect the admin. |
|
496 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
497 | + exit; |
|
498 | 498 | |
499 | - } |
|
499 | + } |
|
500 | 500 | |
501 | - /** |
|
501 | + /** |
|
502 | 502 | * Recalculates discounts. |
503 | - * |
|
503 | + * |
|
504 | 504 | */ |
505 | 505 | public function admin_recalculate_discounts() { |
506 | - global $wpdb; |
|
506 | + global $wpdb; |
|
507 | 507 | |
508 | - // Fetch all invoices that have discount codes. |
|
509 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
510 | - $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" ); |
|
508 | + // Fetch all invoices that have discount codes. |
|
509 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
510 | + $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" ); |
|
511 | 511 | |
512 | - foreach ( $invoices as $invoice ) { |
|
512 | + foreach ( $invoices as $invoice ) { |
|
513 | 513 | |
514 | - $invoice = new WPInv_Invoice( $invoice ); |
|
514 | + $invoice = new WPInv_Invoice( $invoice ); |
|
515 | 515 | |
516 | - if ( ! $invoice->exists() ) { |
|
517 | - continue; |
|
518 | - } |
|
516 | + if ( ! $invoice->exists() ) { |
|
517 | + continue; |
|
518 | + } |
|
519 | 519 | |
520 | - // Abort if the discount does not exist or does not apply here. |
|
521 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
522 | - if ( ! $discount->exists() ) { |
|
523 | - continue; |
|
524 | - } |
|
520 | + // Abort if the discount does not exist or does not apply here. |
|
521 | + $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
522 | + if ( ! $discount->exists() ) { |
|
523 | + continue; |
|
524 | + } |
|
525 | 525 | |
526 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
527 | - $invoice->recalculate_total(); |
|
526 | + $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
527 | + $invoice->recalculate_total(); |
|
528 | 528 | |
529 | - if ( $invoice->get_total_discount() > 0 ) { |
|
530 | - $invoice->save(); |
|
531 | - } |
|
529 | + if ( $invoice->get_total_discount() > 0 ) { |
|
530 | + $invoice->save(); |
|
531 | + } |
|
532 | 532 | |
533 | - } |
|
533 | + } |
|
534 | 534 | |
535 | - // Show an admin message. |
|
536 | - $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) ); |
|
535 | + // Show an admin message. |
|
536 | + $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) ); |
|
537 | 537 | |
538 | - // Redirect the admin. |
|
539 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
540 | - exit; |
|
538 | + // Redirect the admin. |
|
539 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
540 | + exit; |
|
541 | 541 | |
542 | - } |
|
542 | + } |
|
543 | 543 | |
544 | 544 | /** |
545 | - * Returns an array of admin notices. |
|
546 | - * |
|
547 | - * @since 1.0.19 |
|
545 | + * Returns an array of admin notices. |
|
546 | + * |
|
547 | + * @since 1.0.19 |
|
548 | 548 | * @return array |
549 | - */ |
|
550 | - public function get_notices() { |
|
551 | - $notices = get_option( 'wpinv_admin_notices' ); |
|
549 | + */ |
|
550 | + public function get_notices() { |
|
551 | + $notices = get_option( 'wpinv_admin_notices' ); |
|
552 | 552 | return is_array( $notices ) ? $notices : array(); |
553 | - } |
|
553 | + } |
|
554 | 554 | |
555 | - /** |
|
556 | - * Checks if we have any admin notices. |
|
557 | - * |
|
558 | - * @since 2.0.4 |
|
555 | + /** |
|
556 | + * Checks if we have any admin notices. |
|
557 | + * |
|
558 | + * @since 2.0.4 |
|
559 | 559 | * @return array |
560 | - */ |
|
561 | - public function has_notices() { |
|
562 | - return count( $this->get_notices() ) > 0; |
|
563 | - } |
|
564 | - |
|
565 | - /** |
|
566 | - * Clears all admin notices |
|
567 | - * |
|
568 | - * @access public |
|
569 | - * @since 1.0.19 |
|
570 | - */ |
|
571 | - public function clear_notices() { |
|
572 | - delete_option( 'wpinv_admin_notices' ); |
|
573 | - } |
|
574 | - |
|
575 | - /** |
|
576 | - * Saves a new admin notice |
|
577 | - * |
|
578 | - * @access public |
|
579 | - * @since 1.0.19 |
|
580 | - */ |
|
581 | - public function save_notice( $type, $message ) { |
|
582 | - $notices = $this->get_notices(); |
|
583 | - |
|
584 | - if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) { |
|
585 | - $notices[ $type ] = array(); |
|
586 | - } |
|
587 | - |
|
588 | - $notices[ $type ][] = $message; |
|
589 | - |
|
590 | - update_option( 'wpinv_admin_notices', $notices ); |
|
591 | - } |
|
592 | - |
|
593 | - /** |
|
594 | - * Displays a success notice |
|
595 | - * |
|
596 | - * @param string $msg The message to qeue. |
|
597 | - * @access public |
|
598 | - * @since 1.0.19 |
|
599 | - */ |
|
600 | - public function show_success( $msg ) { |
|
601 | - $this->save_notice( 'success', $msg ); |
|
602 | - } |
|
603 | - |
|
604 | - /** |
|
605 | - * Displays a error notice |
|
606 | - * |
|
607 | - * @access public |
|
608 | - * @param string $msg The message to qeue. |
|
609 | - * @since 1.0.19 |
|
610 | - */ |
|
611 | - public function show_error( $msg ) { |
|
612 | - $this->save_notice( 'error', $msg ); |
|
613 | - } |
|
614 | - |
|
615 | - /** |
|
616 | - * Displays a warning notice |
|
617 | - * |
|
618 | - * @access public |
|
619 | - * @param string $msg The message to qeue. |
|
620 | - * @since 1.0.19 |
|
621 | - */ |
|
622 | - public function show_warning( $msg ) { |
|
623 | - $this->save_notice( 'warning', $msg ); |
|
624 | - } |
|
625 | - |
|
626 | - /** |
|
627 | - * Displays a info notice |
|
628 | - * |
|
629 | - * @access public |
|
630 | - * @param string $msg The message to qeue. |
|
631 | - * @since 1.0.19 |
|
632 | - */ |
|
633 | - public function show_info( $msg ) { |
|
634 | - $this->save_notice( 'info', $msg ); |
|
635 | - } |
|
636 | - |
|
637 | - /** |
|
638 | - * Show notices |
|
639 | - * |
|
640 | - * @access public |
|
641 | - * @since 1.0.19 |
|
642 | - */ |
|
643 | - public function show_notices() { |
|
560 | + */ |
|
561 | + public function has_notices() { |
|
562 | + return count( $this->get_notices() ) > 0; |
|
563 | + } |
|
564 | + |
|
565 | + /** |
|
566 | + * Clears all admin notices |
|
567 | + * |
|
568 | + * @access public |
|
569 | + * @since 1.0.19 |
|
570 | + */ |
|
571 | + public function clear_notices() { |
|
572 | + delete_option( 'wpinv_admin_notices' ); |
|
573 | + } |
|
574 | + |
|
575 | + /** |
|
576 | + * Saves a new admin notice |
|
577 | + * |
|
578 | + * @access public |
|
579 | + * @since 1.0.19 |
|
580 | + */ |
|
581 | + public function save_notice( $type, $message ) { |
|
582 | + $notices = $this->get_notices(); |
|
583 | + |
|
584 | + if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) { |
|
585 | + $notices[ $type ] = array(); |
|
586 | + } |
|
587 | + |
|
588 | + $notices[ $type ][] = $message; |
|
589 | + |
|
590 | + update_option( 'wpinv_admin_notices', $notices ); |
|
591 | + } |
|
592 | + |
|
593 | + /** |
|
594 | + * Displays a success notice |
|
595 | + * |
|
596 | + * @param string $msg The message to qeue. |
|
597 | + * @access public |
|
598 | + * @since 1.0.19 |
|
599 | + */ |
|
600 | + public function show_success( $msg ) { |
|
601 | + $this->save_notice( 'success', $msg ); |
|
602 | + } |
|
603 | + |
|
604 | + /** |
|
605 | + * Displays a error notice |
|
606 | + * |
|
607 | + * @access public |
|
608 | + * @param string $msg The message to qeue. |
|
609 | + * @since 1.0.19 |
|
610 | + */ |
|
611 | + public function show_error( $msg ) { |
|
612 | + $this->save_notice( 'error', $msg ); |
|
613 | + } |
|
614 | + |
|
615 | + /** |
|
616 | + * Displays a warning notice |
|
617 | + * |
|
618 | + * @access public |
|
619 | + * @param string $msg The message to qeue. |
|
620 | + * @since 1.0.19 |
|
621 | + */ |
|
622 | + public function show_warning( $msg ) { |
|
623 | + $this->save_notice( 'warning', $msg ); |
|
624 | + } |
|
625 | + |
|
626 | + /** |
|
627 | + * Displays a info notice |
|
628 | + * |
|
629 | + * @access public |
|
630 | + * @param string $msg The message to qeue. |
|
631 | + * @since 1.0.19 |
|
632 | + */ |
|
633 | + public function show_info( $msg ) { |
|
634 | + $this->save_notice( 'info', $msg ); |
|
635 | + } |
|
636 | + |
|
637 | + /** |
|
638 | + * Show notices |
|
639 | + * |
|
640 | + * @access public |
|
641 | + * @since 1.0.19 |
|
642 | + */ |
|
643 | + public function show_notices() { |
|
644 | 644 | |
645 | 645 | $notices = $this->get_notices(); |
646 | 646 | $this->clear_notices(); |
647 | 647 | |
648 | - foreach ( $notices as $type => $messages ) { |
|
648 | + foreach ( $notices as $type => $messages ) { |
|
649 | 649 | |
650 | - if ( ! is_array( $messages ) ) { |
|
651 | - continue; |
|
652 | - } |
|
650 | + if ( ! is_array( $messages ) ) { |
|
651 | + continue; |
|
652 | + } |
|
653 | 653 | |
654 | 654 | $type = sanitize_key( $type ); |
655 | - foreach ( $messages as $message ) { |
|
655 | + foreach ( $messages as $message ) { |
|
656 | 656 | $message = wp_kses_post( $message ); |
657 | - echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>"; |
|
657 | + echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>"; |
|
658 | + } |
|
659 | + |
|
660 | + } |
|
661 | + |
|
662 | + foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
663 | + |
|
664 | + if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
665 | + $url = esc_url( |
|
666 | + wp_nonce_url( |
|
667 | + add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
668 | + 'getpaid-nonce', |
|
669 | + 'getpaid-nonce' |
|
670 | + ) |
|
671 | + ); |
|
672 | + $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
673 | + $message2 = __( 'Generate Pages', 'invoicing' ); |
|
674 | + echo "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>"; |
|
675 | + break; |
|
658 | 676 | } |
659 | 677 | |
660 | 678 | } |
661 | 679 | |
662 | - foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
663 | - |
|
664 | - if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
665 | - $url = esc_url( |
|
666 | - wp_nonce_url( |
|
667 | - add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
668 | - 'getpaid-nonce', |
|
669 | - 'getpaid-nonce' |
|
670 | - ) |
|
671 | - ); |
|
672 | - $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
673 | - $message2 = __( 'Generate Pages', 'invoicing' ); |
|
674 | - echo "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>"; |
|
675 | - break; |
|
676 | - } |
|
677 | - |
|
678 | - } |
|
679 | - |
|
680 | - } |
|
680 | + } |
|
681 | 681 | |
682 | 682 | } |