@@ -20,226 +20,226 @@ discard block |
||
20 | 20 | */ |
21 | 21 | class GetPaid_Installer { |
22 | 22 | |
23 | - /** |
|
24 | - * Upgrades the install. |
|
25 | - * |
|
26 | - * @param string $upgrade_from The current invoicing version. |
|
27 | - */ |
|
28 | - public function upgrade_db( $upgrade_from ) { |
|
29 | - |
|
30 | - // Save the current invoicing version. |
|
31 | - update_option( 'wpinv_version', WPINV_VERSION ); |
|
32 | - |
|
33 | - // Setup the invoice Custom Post Type. |
|
34 | - GetPaid_Post_Types::register_post_types(); |
|
35 | - |
|
36 | - // Clear the permalinks |
|
37 | - flush_rewrite_rules(); |
|
38 | - |
|
39 | - // Maybe create new/missing pages. |
|
40 | - $this->create_pages(); |
|
41 | - |
|
42 | - // Maybe re(add) admin capabilities. |
|
43 | - $this->add_capabilities(); |
|
44 | - |
|
45 | - // Maybe create the default payment form. |
|
46 | - wpinv_get_default_payment_form(); |
|
47 | - |
|
48 | - // Create any missing database tables. |
|
49 | - $method = "upgrade_from_$upgrade_from"; |
|
50 | - |
|
51 | - $installed = get_option( 'gepaid_installed_on' ); |
|
52 | - |
|
53 | - if ( empty( $installed ) ) { |
|
54 | - update_option( 'gepaid_installed_on', time() ); |
|
55 | - } |
|
56 | - |
|
57 | - if ( method_exists( $this, $method ) ) { |
|
58 | - $this->$method(); |
|
59 | - } |
|
60 | - |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Do a fresh install. |
|
65 | - * |
|
66 | - */ |
|
67 | - public function upgrade_from_0() { |
|
68 | - $this->create_subscriptions_table(); |
|
69 | - $this->create_invoices_table(); |
|
70 | - $this->create_invoice_items_table(); |
|
71 | - |
|
72 | - // Save default tax rates. |
|
73 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Upgrade to 0.0.5 |
|
78 | - * |
|
79 | - */ |
|
80 | - public function upgrade_from_004() { |
|
81 | - global $wpdb; |
|
82 | - |
|
83 | - // Invoices. |
|
84 | - $results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
85 | - if ( ! empty( $results ) ) { |
|
86 | - $wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
87 | - |
|
88 | - // Clean post cache |
|
89 | - foreach ( $results as $row ) { |
|
90 | - clean_post_cache( $row->ID ); |
|
91 | - } |
|
23 | + /** |
|
24 | + * Upgrades the install. |
|
25 | + * |
|
26 | + * @param string $upgrade_from The current invoicing version. |
|
27 | + */ |
|
28 | + public function upgrade_db( $upgrade_from ) { |
|
29 | + |
|
30 | + // Save the current invoicing version. |
|
31 | + update_option( 'wpinv_version', WPINV_VERSION ); |
|
32 | + |
|
33 | + // Setup the invoice Custom Post Type. |
|
34 | + GetPaid_Post_Types::register_post_types(); |
|
35 | + |
|
36 | + // Clear the permalinks |
|
37 | + flush_rewrite_rules(); |
|
38 | + |
|
39 | + // Maybe create new/missing pages. |
|
40 | + $this->create_pages(); |
|
41 | + |
|
42 | + // Maybe re(add) admin capabilities. |
|
43 | + $this->add_capabilities(); |
|
44 | + |
|
45 | + // Maybe create the default payment form. |
|
46 | + wpinv_get_default_payment_form(); |
|
47 | + |
|
48 | + // Create any missing database tables. |
|
49 | + $method = "upgrade_from_$upgrade_from"; |
|
50 | + |
|
51 | + $installed = get_option( 'gepaid_installed_on' ); |
|
52 | + |
|
53 | + if ( empty( $installed ) ) { |
|
54 | + update_option( 'gepaid_installed_on', time() ); |
|
55 | + } |
|
56 | + |
|
57 | + if ( method_exists( $this, $method ) ) { |
|
58 | + $this->$method(); |
|
59 | + } |
|
60 | + |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Do a fresh install. |
|
65 | + * |
|
66 | + */ |
|
67 | + public function upgrade_from_0() { |
|
68 | + $this->create_subscriptions_table(); |
|
69 | + $this->create_invoices_table(); |
|
70 | + $this->create_invoice_items_table(); |
|
71 | + |
|
72 | + // Save default tax rates. |
|
73 | + update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Upgrade to 0.0.5 |
|
78 | + * |
|
79 | + */ |
|
80 | + public function upgrade_from_004() { |
|
81 | + global $wpdb; |
|
82 | + |
|
83 | + // Invoices. |
|
84 | + $results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
85 | + if ( ! empty( $results ) ) { |
|
86 | + $wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
87 | + |
|
88 | + // Clean post cache |
|
89 | + foreach ( $results as $row ) { |
|
90 | + clean_post_cache( $row->ID ); |
|
91 | + } |
|
92 | 92 | } |
93 | 93 | |
94 | - // Item meta key changes |
|
95 | - $query = 'SELECT DISTINCT post_id FROM ' . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )"; |
|
96 | - $results = $wpdb->get_results( $query ); |
|
94 | + // Item meta key changes |
|
95 | + $query = 'SELECT DISTINCT post_id FROM ' . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )"; |
|
96 | + $results = $wpdb->get_results( $query ); |
|
97 | 97 | |
98 | - if ( ! empty( $results ) ) { |
|
99 | - $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
100 | - $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
101 | - $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
98 | + if ( ! empty( $results ) ) { |
|
99 | + $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
100 | + $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
101 | + $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
102 | 102 | |
103 | - foreach ( $results as $row ) { |
|
104 | - clean_post_cache( $row->post_id ); |
|
105 | - } |
|
103 | + foreach ( $results as $row ) { |
|
104 | + clean_post_cache( $row->post_id ); |
|
105 | + } |
|
106 | 106 | } |
107 | 107 | |
108 | - $this->upgrade_from_102(); |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * Upgrade to 1.0.3 |
|
113 | - * |
|
114 | - */ |
|
115 | - public function upgrade_from_102() { |
|
116 | - $this->create_subscriptions_table(); |
|
117 | - $this->upgrade_from_118(); |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Upgrade to version 2.0.0. |
|
122 | - * |
|
123 | - */ |
|
124 | - public function upgrade_from_118() { |
|
125 | - $this->create_invoices_table(); |
|
126 | - $this->create_invoice_items_table(); |
|
127 | - $this->migrate_old_invoices(); |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * Upgrade to version 2.0.8. |
|
132 | - * |
|
133 | - */ |
|
134 | - public function upgrade_from_207() { |
|
135 | - global $wpdb; |
|
136 | - $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN quantity FLOAT(20);" ); |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * Give administrators the capability to manage GetPaid. |
|
141 | - * |
|
142 | - */ |
|
143 | - public function add_capabilities() { |
|
144 | - $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' ); |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * Retreives GetPaid pages. |
|
149 | - * |
|
150 | - */ |
|
151 | - public static function get_pages() { |
|
152 | - |
|
153 | - return apply_filters( |
|
154 | - 'wpinv_create_pages', |
|
155 | - array( |
|
156 | - |
|
157 | - // Checkout page. |
|
158 | - 'checkout_page' => array( |
|
159 | - 'name' => _x( 'gp-checkout', 'Page slug', 'invoicing' ), |
|
160 | - 'title' => _x( 'Checkout', 'Page title', 'invoicing' ), |
|
161 | - 'content' => ' |
|
108 | + $this->upgrade_from_102(); |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * Upgrade to 1.0.3 |
|
113 | + * |
|
114 | + */ |
|
115 | + public function upgrade_from_102() { |
|
116 | + $this->create_subscriptions_table(); |
|
117 | + $this->upgrade_from_118(); |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * Upgrade to version 2.0.0. |
|
122 | + * |
|
123 | + */ |
|
124 | + public function upgrade_from_118() { |
|
125 | + $this->create_invoices_table(); |
|
126 | + $this->create_invoice_items_table(); |
|
127 | + $this->migrate_old_invoices(); |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * Upgrade to version 2.0.8. |
|
132 | + * |
|
133 | + */ |
|
134 | + public function upgrade_from_207() { |
|
135 | + global $wpdb; |
|
136 | + $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN quantity FLOAT(20);" ); |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * Give administrators the capability to manage GetPaid. |
|
141 | + * |
|
142 | + */ |
|
143 | + public function add_capabilities() { |
|
144 | + $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' ); |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * Retreives GetPaid pages. |
|
149 | + * |
|
150 | + */ |
|
151 | + public static function get_pages() { |
|
152 | + |
|
153 | + return apply_filters( |
|
154 | + 'wpinv_create_pages', |
|
155 | + array( |
|
156 | + |
|
157 | + // Checkout page. |
|
158 | + 'checkout_page' => array( |
|
159 | + 'name' => _x( 'gp-checkout', 'Page slug', 'invoicing' ), |
|
160 | + 'title' => _x( 'Checkout', 'Page title', 'invoicing' ), |
|
161 | + 'content' => ' |
|
162 | 162 | <!-- wp:shortcode --> |
163 | 163 | [wpinv_checkout] |
164 | 164 | <!-- /wp:shortcode --> |
165 | 165 | ', |
166 | - 'parent' => '', |
|
167 | - ), |
|
168 | - |
|
169 | - // Invoice history page. |
|
170 | - 'invoice_history_page' => array( |
|
171 | - 'name' => _x( 'gp-invoices', 'Page slug', 'invoicing' ), |
|
172 | - 'title' => _x( 'My Invoices', 'Page title', 'invoicing' ), |
|
173 | - 'content' => ' |
|
166 | + 'parent' => '', |
|
167 | + ), |
|
168 | + |
|
169 | + // Invoice history page. |
|
170 | + 'invoice_history_page' => array( |
|
171 | + 'name' => _x( 'gp-invoices', 'Page slug', 'invoicing' ), |
|
172 | + 'title' => _x( 'My Invoices', 'Page title', 'invoicing' ), |
|
173 | + 'content' => ' |
|
174 | 174 | <!-- wp:shortcode --> |
175 | 175 | [wpinv_history] |
176 | 176 | <!-- /wp:shortcode --> |
177 | 177 | ', |
178 | - 'parent' => '', |
|
179 | - ), |
|
180 | - |
|
181 | - // Success page content. |
|
182 | - 'success_page' => array( |
|
183 | - 'name' => _x( 'gp-receipt', 'Page slug', 'invoicing' ), |
|
184 | - 'title' => _x( 'Payment Confirmation', 'Page title', 'invoicing' ), |
|
185 | - 'content' => ' |
|
178 | + 'parent' => '', |
|
179 | + ), |
|
180 | + |
|
181 | + // Success page content. |
|
182 | + 'success_page' => array( |
|
183 | + 'name' => _x( 'gp-receipt', 'Page slug', 'invoicing' ), |
|
184 | + 'title' => _x( 'Payment Confirmation', 'Page title', 'invoicing' ), |
|
185 | + 'content' => ' |
|
186 | 186 | <!-- wp:shortcode --> |
187 | 187 | [wpinv_receipt] |
188 | 188 | <!-- /wp:shortcode --> |
189 | 189 | ', |
190 | - 'parent' => 'gp-checkout', |
|
191 | - ), |
|
192 | - |
|
193 | - // Failure page content. |
|
194 | - 'failure_page' => array( |
|
195 | - 'name' => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ), |
|
196 | - 'title' => _x( 'Transaction Failed', 'Page title', 'invoicing' ), |
|
197 | - 'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ), |
|
198 | - 'parent' => 'gp-checkout', |
|
199 | - ), |
|
200 | - |
|
201 | - // Subscriptions history page. |
|
202 | - 'invoice_subscription_page' => array( |
|
203 | - 'name' => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ), |
|
204 | - 'title' => _x( 'My Subscriptions', 'Page title', 'invoicing' ), |
|
205 | - 'content' => ' |
|
190 | + 'parent' => 'gp-checkout', |
|
191 | + ), |
|
192 | + |
|
193 | + // Failure page content. |
|
194 | + 'failure_page' => array( |
|
195 | + 'name' => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ), |
|
196 | + 'title' => _x( 'Transaction Failed', 'Page title', 'invoicing' ), |
|
197 | + 'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ), |
|
198 | + 'parent' => 'gp-checkout', |
|
199 | + ), |
|
200 | + |
|
201 | + // Subscriptions history page. |
|
202 | + 'invoice_subscription_page' => array( |
|
203 | + 'name' => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ), |
|
204 | + 'title' => _x( 'My Subscriptions', 'Page title', 'invoicing' ), |
|
205 | + 'content' => ' |
|
206 | 206 | <!-- wp:shortcode --> |
207 | 207 | [wpinv_subscriptions] |
208 | 208 | <!-- /wp:shortcode --> |
209 | 209 | ', |
210 | - 'parent' => '', |
|
211 | - ), |
|
210 | + 'parent' => '', |
|
211 | + ), |
|
212 | 212 | |
213 | - ) |
|
214 | - ); |
|
213 | + ) |
|
214 | + ); |
|
215 | 215 | |
216 | - } |
|
216 | + } |
|
217 | 217 | |
218 | - /** |
|
219 | - * Re-create GetPaid pages. |
|
220 | - * |
|
221 | - */ |
|
222 | - public function create_pages() { |
|
218 | + /** |
|
219 | + * Re-create GetPaid pages. |
|
220 | + * |
|
221 | + */ |
|
222 | + public function create_pages() { |
|
223 | 223 | |
224 | - foreach ( self::get_pages() as $key => $page ) { |
|
225 | - wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] ); |
|
226 | - } |
|
224 | + foreach ( self::get_pages() as $key => $page ) { |
|
225 | + wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] ); |
|
226 | + } |
|
227 | 227 | |
228 | - } |
|
228 | + } |
|
229 | 229 | |
230 | - /** |
|
231 | - * Create subscriptions table. |
|
232 | - * |
|
233 | - */ |
|
234 | - public function create_subscriptions_table() { |
|
230 | + /** |
|
231 | + * Create subscriptions table. |
|
232 | + * |
|
233 | + */ |
|
234 | + public function create_subscriptions_table() { |
|
235 | 235 | |
236 | - global $wpdb; |
|
236 | + global $wpdb; |
|
237 | 237 | |
238 | - require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
238 | + require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
239 | 239 | |
240 | - // Create tables. |
|
241 | - $charset_collate = $wpdb->get_charset_collate(); |
|
242 | - $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wpinv_subscriptions ( |
|
240 | + // Create tables. |
|
241 | + $charset_collate = $wpdb->get_charset_collate(); |
|
242 | + $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wpinv_subscriptions ( |
|
243 | 243 | id bigint(20) unsigned NOT NULL auto_increment, |
244 | 244 | customer_id bigint(20) NOT NULL, |
245 | 245 | frequency int(11) NOT NULL DEFAULT '1', |
@@ -262,22 +262,22 @@ discard block |
||
262 | 262 | KEY customer_and_status (customer_id, status) |
263 | 263 | ) $charset_collate;"; |
264 | 264 | |
265 | - dbDelta( $sql ); |
|
265 | + dbDelta( $sql ); |
|
266 | 266 | |
267 | - } |
|
267 | + } |
|
268 | 268 | |
269 | - /** |
|
270 | - * Create invoices table. |
|
271 | - * |
|
272 | - */ |
|
273 | - public function create_invoices_table() { |
|
274 | - global $wpdb; |
|
269 | + /** |
|
270 | + * Create invoices table. |
|
271 | + * |
|
272 | + */ |
|
273 | + public function create_invoices_table() { |
|
274 | + global $wpdb; |
|
275 | 275 | |
276 | - require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
276 | + require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
277 | 277 | |
278 | - // Create tables. |
|
279 | - $charset_collate = $wpdb->get_charset_collate(); |
|
280 | - $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoices ( |
|
278 | + // Create tables. |
|
279 | + $charset_collate = $wpdb->get_charset_collate(); |
|
280 | + $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoices ( |
|
281 | 281 | post_id BIGINT(20) NOT NULL, |
282 | 282 | `number` VARCHAR(100), |
283 | 283 | `key` VARCHAR(100), |
@@ -313,22 +313,22 @@ discard block |
||
313 | 313 | KEY `key` (`key`) |
314 | 314 | ) $charset_collate;"; |
315 | 315 | |
316 | - dbDelta( $sql ); |
|
316 | + dbDelta( $sql ); |
|
317 | 317 | |
318 | - } |
|
318 | + } |
|
319 | 319 | |
320 | - /** |
|
321 | - * Create invoice items table. |
|
322 | - * |
|
323 | - */ |
|
324 | - public function create_invoice_items_table() { |
|
325 | - global $wpdb; |
|
320 | + /** |
|
321 | + * Create invoice items table. |
|
322 | + * |
|
323 | + */ |
|
324 | + public function create_invoice_items_table() { |
|
325 | + global $wpdb; |
|
326 | 326 | |
327 | - require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
327 | + require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
328 | 328 | |
329 | - // Create tables. |
|
330 | - $charset_collate = $wpdb->get_charset_collate(); |
|
331 | - $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoice_items ( |
|
329 | + // Create tables. |
|
330 | + $charset_collate = $wpdb->get_charset_collate(); |
|
331 | + $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoice_items ( |
|
332 | 332 | ID BIGINT(20) NOT NULL AUTO_INCREMENT, |
333 | 333 | post_id BIGINT(20) NOT NULL, |
334 | 334 | item_id BIGINT(20) NOT NULL, |
@@ -350,159 +350,159 @@ discard block |
||
350 | 350 | KEY post_id (post_id) |
351 | 351 | ) $charset_collate;"; |
352 | 352 | |
353 | - dbDelta( $sql ); |
|
354 | - |
|
355 | - } |
|
356 | - |
|
357 | - /** |
|
358 | - * Migrates old invoices to new invoices. |
|
359 | - * |
|
360 | - */ |
|
361 | - public function migrate_old_invoices() { |
|
362 | - global $wpdb; |
|
363 | - |
|
364 | - $invoices_table = $wpdb->prefix . 'getpaid_invoices'; |
|
365 | - $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
366 | - $migrated = $wpdb->get_col( "SELECT post_id FROM $invoices_table" ); |
|
367 | - $invoices = array_unique( |
|
368 | - get_posts( |
|
369 | - array( |
|
370 | - 'post_type' => array( 'wpi_invoice', 'wpi_quote' ), |
|
371 | - 'posts_per_page' => -1, |
|
372 | - 'fields' => 'ids', |
|
373 | - 'post_status' => array_keys( get_post_stati() ), |
|
374 | - 'exclude' => (array) $migrated, |
|
375 | - ) |
|
376 | - ) |
|
377 | - ); |
|
378 | - |
|
379 | - // Abort if we do not have any invoices. |
|
380 | - if ( empty( $invoices ) ) { |
|
381 | - return; |
|
382 | - } |
|
383 | - |
|
384 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php'; |
|
385 | - |
|
386 | - $invoice_rows = array(); |
|
387 | - foreach ( $invoices as $invoice ) { |
|
388 | - |
|
389 | - $invoice = new WPInv_Legacy_Invoice( $invoice ); |
|
390 | - |
|
391 | - if ( empty( $invoice->ID ) ) { |
|
392 | - return; |
|
393 | - } |
|
394 | - |
|
395 | - $fields = array( |
|
396 | - 'post_id' => $invoice->ID, |
|
397 | - 'number' => $invoice->get_number(), |
|
398 | - 'key' => $invoice->get_key(), |
|
399 | - 'type' => str_replace( 'wpi_', '', $invoice->post_type ), |
|
400 | - 'mode' => $invoice->mode, |
|
401 | - 'user_ip' => $invoice->get_ip(), |
|
402 | - 'first_name' => $invoice->get_first_name(), |
|
403 | - 'last_name' => $invoice->get_last_name(), |
|
404 | - 'address' => $invoice->get_address(), |
|
405 | - 'city' => $invoice->city, |
|
406 | - 'state' => $invoice->state, |
|
407 | - 'country' => $invoice->country, |
|
408 | - 'zip' => $invoice->zip, |
|
409 | - 'adddress_confirmed' => (int) $invoice->adddress_confirmed, |
|
410 | - 'gateway' => $invoice->get_gateway(), |
|
411 | - 'transaction_id' => $invoice->get_transaction_id(), |
|
412 | - 'currency' => $invoice->get_currency(), |
|
413 | - 'subtotal' => $invoice->get_subtotal(), |
|
414 | - 'tax' => $invoice->get_tax(), |
|
415 | - 'fees_total' => $invoice->get_fees_total(), |
|
416 | - 'total' => $invoice->get_total(), |
|
417 | - 'discount' => $invoice->get_discount(), |
|
418 | - 'discount_code' => $invoice->get_discount_code(), |
|
419 | - 'disable_taxes' => $invoice->disable_taxes, |
|
420 | - 'due_date' => $invoice->get_due_date(), |
|
421 | - 'completed_date' => $invoice->get_completed_date(), |
|
422 | - 'company' => $invoice->company, |
|
423 | - 'vat_number' => $invoice->vat_number, |
|
424 | - 'vat_rate' => $invoice->vat_rate, |
|
425 | - 'custom_meta' => $invoice->payment_meta, |
|
426 | - ); |
|
427 | - |
|
428 | - foreach ( $fields as $key => $val ) { |
|
429 | - if ( is_null( $val ) ) { |
|
430 | - $val = ''; |
|
431 | - } |
|
432 | - $val = maybe_serialize( $val ); |
|
433 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
434 | - } |
|
435 | - |
|
436 | - $fields = implode( ', ', $fields ); |
|
437 | - $invoice_rows[] = "($fields)"; |
|
438 | - |
|
439 | - $item_rows = array(); |
|
440 | - $item_columns = array(); |
|
441 | - foreach ( $invoice->get_cart_details() as $details ) { |
|
442 | - $fields = array( |
|
443 | - 'post_id' => $invoice->ID, |
|
444 | - 'item_id' => $details['id'], |
|
445 | - 'item_name' => $details['name'], |
|
446 | - 'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'], |
|
447 | - 'vat_rate' => $details['vat_rate'], |
|
448 | - 'vat_class' => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'], |
|
449 | - 'tax' => $details['tax'], |
|
450 | - 'item_price' => $details['item_price'], |
|
451 | - 'custom_price' => $details['custom_price'], |
|
452 | - 'quantity' => $details['quantity'], |
|
453 | - 'discount' => $details['discount'], |
|
454 | - 'subtotal' => $details['subtotal'], |
|
455 | - 'price' => $details['price'], |
|
456 | - 'meta' => $details['meta'], |
|
457 | - 'fees' => $details['fees'], |
|
458 | - ); |
|
459 | - |
|
460 | - $item_columns = array_keys( $fields ); |
|
461 | - |
|
462 | - foreach ( $fields as $key => $val ) { |
|
463 | - if ( is_null( $val ) ) { |
|
464 | - $val = ''; |
|
465 | - } |
|
466 | - $val = maybe_serialize( $val ); |
|
467 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
468 | - } |
|
469 | - |
|
470 | - $fields = implode( ', ', $fields ); |
|
471 | - $item_rows[] = "($fields)"; |
|
472 | - } |
|
473 | - |
|
474 | - $item_rows = implode( ', ', $item_rows ); |
|
475 | - $item_columns = implode( ', ', $item_columns ); |
|
476 | - $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" ); |
|
477 | - } |
|
478 | - |
|
479 | - if ( empty( $invoice_rows ) ) { |
|
480 | - return; |
|
481 | - } |
|
482 | - |
|
483 | - $invoice_rows = implode( ', ', $invoice_rows ); |
|
484 | - $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" ); |
|
485 | - |
|
486 | - } |
|
487 | - |
|
488 | - /** |
|
489 | - * Migrates old invoices to new invoices. |
|
490 | - * |
|
491 | - */ |
|
492 | - public static function rename_gateways_label() { |
|
493 | - global $wpdb; |
|
494 | - |
|
495 | - foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) { |
|
496 | - |
|
497 | - $wpdb->update( |
|
498 | - $wpdb->prefix . 'getpaid_invoices', |
|
499 | - array( 'gateway' => $gateway ), |
|
500 | - array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ), |
|
501 | - '%s', |
|
502 | - '%s' |
|
503 | - ); |
|
504 | - |
|
505 | - } |
|
506 | - } |
|
353 | + dbDelta( $sql ); |
|
354 | + |
|
355 | + } |
|
356 | + |
|
357 | + /** |
|
358 | + * Migrates old invoices to new invoices. |
|
359 | + * |
|
360 | + */ |
|
361 | + public function migrate_old_invoices() { |
|
362 | + global $wpdb; |
|
363 | + |
|
364 | + $invoices_table = $wpdb->prefix . 'getpaid_invoices'; |
|
365 | + $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
366 | + $migrated = $wpdb->get_col( "SELECT post_id FROM $invoices_table" ); |
|
367 | + $invoices = array_unique( |
|
368 | + get_posts( |
|
369 | + array( |
|
370 | + 'post_type' => array( 'wpi_invoice', 'wpi_quote' ), |
|
371 | + 'posts_per_page' => -1, |
|
372 | + 'fields' => 'ids', |
|
373 | + 'post_status' => array_keys( get_post_stati() ), |
|
374 | + 'exclude' => (array) $migrated, |
|
375 | + ) |
|
376 | + ) |
|
377 | + ); |
|
378 | + |
|
379 | + // Abort if we do not have any invoices. |
|
380 | + if ( empty( $invoices ) ) { |
|
381 | + return; |
|
382 | + } |
|
383 | + |
|
384 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php'; |
|
385 | + |
|
386 | + $invoice_rows = array(); |
|
387 | + foreach ( $invoices as $invoice ) { |
|
388 | + |
|
389 | + $invoice = new WPInv_Legacy_Invoice( $invoice ); |
|
390 | + |
|
391 | + if ( empty( $invoice->ID ) ) { |
|
392 | + return; |
|
393 | + } |
|
394 | + |
|
395 | + $fields = array( |
|
396 | + 'post_id' => $invoice->ID, |
|
397 | + 'number' => $invoice->get_number(), |
|
398 | + 'key' => $invoice->get_key(), |
|
399 | + 'type' => str_replace( 'wpi_', '', $invoice->post_type ), |
|
400 | + 'mode' => $invoice->mode, |
|
401 | + 'user_ip' => $invoice->get_ip(), |
|
402 | + 'first_name' => $invoice->get_first_name(), |
|
403 | + 'last_name' => $invoice->get_last_name(), |
|
404 | + 'address' => $invoice->get_address(), |
|
405 | + 'city' => $invoice->city, |
|
406 | + 'state' => $invoice->state, |
|
407 | + 'country' => $invoice->country, |
|
408 | + 'zip' => $invoice->zip, |
|
409 | + 'adddress_confirmed' => (int) $invoice->adddress_confirmed, |
|
410 | + 'gateway' => $invoice->get_gateway(), |
|
411 | + 'transaction_id' => $invoice->get_transaction_id(), |
|
412 | + 'currency' => $invoice->get_currency(), |
|
413 | + 'subtotal' => $invoice->get_subtotal(), |
|
414 | + 'tax' => $invoice->get_tax(), |
|
415 | + 'fees_total' => $invoice->get_fees_total(), |
|
416 | + 'total' => $invoice->get_total(), |
|
417 | + 'discount' => $invoice->get_discount(), |
|
418 | + 'discount_code' => $invoice->get_discount_code(), |
|
419 | + 'disable_taxes' => $invoice->disable_taxes, |
|
420 | + 'due_date' => $invoice->get_due_date(), |
|
421 | + 'completed_date' => $invoice->get_completed_date(), |
|
422 | + 'company' => $invoice->company, |
|
423 | + 'vat_number' => $invoice->vat_number, |
|
424 | + 'vat_rate' => $invoice->vat_rate, |
|
425 | + 'custom_meta' => $invoice->payment_meta, |
|
426 | + ); |
|
427 | + |
|
428 | + foreach ( $fields as $key => $val ) { |
|
429 | + if ( is_null( $val ) ) { |
|
430 | + $val = ''; |
|
431 | + } |
|
432 | + $val = maybe_serialize( $val ); |
|
433 | + $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
434 | + } |
|
435 | + |
|
436 | + $fields = implode( ', ', $fields ); |
|
437 | + $invoice_rows[] = "($fields)"; |
|
438 | + |
|
439 | + $item_rows = array(); |
|
440 | + $item_columns = array(); |
|
441 | + foreach ( $invoice->get_cart_details() as $details ) { |
|
442 | + $fields = array( |
|
443 | + 'post_id' => $invoice->ID, |
|
444 | + 'item_id' => $details['id'], |
|
445 | + 'item_name' => $details['name'], |
|
446 | + 'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'], |
|
447 | + 'vat_rate' => $details['vat_rate'], |
|
448 | + 'vat_class' => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'], |
|
449 | + 'tax' => $details['tax'], |
|
450 | + 'item_price' => $details['item_price'], |
|
451 | + 'custom_price' => $details['custom_price'], |
|
452 | + 'quantity' => $details['quantity'], |
|
453 | + 'discount' => $details['discount'], |
|
454 | + 'subtotal' => $details['subtotal'], |
|
455 | + 'price' => $details['price'], |
|
456 | + 'meta' => $details['meta'], |
|
457 | + 'fees' => $details['fees'], |
|
458 | + ); |
|
459 | + |
|
460 | + $item_columns = array_keys( $fields ); |
|
461 | + |
|
462 | + foreach ( $fields as $key => $val ) { |
|
463 | + if ( is_null( $val ) ) { |
|
464 | + $val = ''; |
|
465 | + } |
|
466 | + $val = maybe_serialize( $val ); |
|
467 | + $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
468 | + } |
|
469 | + |
|
470 | + $fields = implode( ', ', $fields ); |
|
471 | + $item_rows[] = "($fields)"; |
|
472 | + } |
|
473 | + |
|
474 | + $item_rows = implode( ', ', $item_rows ); |
|
475 | + $item_columns = implode( ', ', $item_columns ); |
|
476 | + $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" ); |
|
477 | + } |
|
478 | + |
|
479 | + if ( empty( $invoice_rows ) ) { |
|
480 | + return; |
|
481 | + } |
|
482 | + |
|
483 | + $invoice_rows = implode( ', ', $invoice_rows ); |
|
484 | + $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" ); |
|
485 | + |
|
486 | + } |
|
487 | + |
|
488 | + /** |
|
489 | + * Migrates old invoices to new invoices. |
|
490 | + * |
|
491 | + */ |
|
492 | + public static function rename_gateways_label() { |
|
493 | + global $wpdb; |
|
494 | + |
|
495 | + foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) { |
|
496 | + |
|
497 | + $wpdb->update( |
|
498 | + $wpdb->prefix . 'getpaid_invoices', |
|
499 | + array( 'gateway' => $gateway ), |
|
500 | + array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ), |
|
501 | + '%s', |
|
502 | + '%s' |
|
503 | + ); |
|
504 | + |
|
505 | + } |
|
506 | + } |
|
507 | 507 | |
508 | 508 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | } |
9 | 9 | |
10 | 10 | if ( ! class_exists( 'WP_List_Table' ) ) { |
11 | - include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
11 | + include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | /** |
@@ -16,468 +16,468 @@ discard block |
||
16 | 16 | */ |
17 | 17 | class WPInv_Subscriptions_List_Table extends WP_List_Table { |
18 | 18 | |
19 | - /** |
|
20 | - * URL of this page |
|
21 | - * |
|
22 | - * @var string |
|
23 | - * @since 1.0.19 |
|
24 | - */ |
|
25 | - public $base_url; |
|
26 | - |
|
27 | - /** |
|
28 | - * Query |
|
29 | - * |
|
30 | - * @var GetPaid_Subscriptions_Query |
|
31 | - * @since 1.0.19 |
|
32 | - */ |
|
33 | - public $query; |
|
34 | - |
|
35 | - /** |
|
36 | - * Total subscriptions |
|
37 | - * |
|
38 | - * @var string |
|
39 | - * @since 1.0.0 |
|
40 | - */ |
|
41 | - public $total_count; |
|
42 | - |
|
43 | - /** |
|
44 | - * Current status subscriptions |
|
45 | - * |
|
46 | - * @var string |
|
47 | - * @since 1.0.0 |
|
48 | - */ |
|
49 | - public $current_total_count; |
|
50 | - |
|
51 | - /** |
|
52 | - * Status counts |
|
53 | - * |
|
54 | - * @var array |
|
55 | - * @since 1.0.19 |
|
56 | - */ |
|
57 | - public $status_counts; |
|
58 | - |
|
59 | - /** |
|
60 | - * Number of results to show per page |
|
61 | - * |
|
62 | - * @var int |
|
63 | - * @since 1.0.0 |
|
64 | - */ |
|
65 | - public $per_page = 10; |
|
66 | - |
|
67 | - /** |
|
68 | - * Constructor function. |
|
69 | - */ |
|
70 | - public function __construct() { |
|
71 | - |
|
72 | - parent::__construct( |
|
73 | - array( |
|
74 | - 'singular' => 'subscription', |
|
75 | - 'plural' => 'subscriptions', |
|
76 | - ) |
|
77 | - ); |
|
78 | - |
|
79 | - $this->process_bulk_action(); |
|
80 | - |
|
81 | - $this->prepare_query(); |
|
82 | - |
|
83 | - $this->base_url = remove_query_arg( 'status' ); |
|
84 | - |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Prepares the display query |
|
89 | - */ |
|
90 | - public function prepare_query() { |
|
91 | - |
|
92 | - // Prepare query args. |
|
93 | - $query = array( |
|
94 | - 'number' => $this->per_page, |
|
95 | - 'paged' => $this->get_paged(), |
|
96 | - 'status' => ( isset( $_GET['status'] ) && array_key_exists( $_GET['status'], getpaid_get_subscription_statuses() ) ) ? sanitize_text_field( $_GET['status'] ) : 'all', |
|
97 | - 'orderby' => ( isset( $_GET['orderby'] ) ) ? sanitize_text_field( $_GET['orderby'] ) : 'id', |
|
98 | - 'order' => ( isset( $_GET['order'] ) ) ? sanitize_text_field( $_GET['order'] ) : 'DESC', |
|
99 | - 'customer_in' => $this->get_user_in(), |
|
100 | - ); |
|
101 | - |
|
102 | - if ( is_array( $query['customer_in'] ) && empty( $query['customer_in'] ) ) { |
|
103 | - $this->total_count = 0; |
|
104 | - $this->current_total_count = 0; |
|
105 | - $this->items = array(); |
|
106 | - $this->status_counts = array(); |
|
107 | - return; |
|
108 | - } |
|
109 | - |
|
110 | - // Prepare class properties. |
|
111 | - $this->query = new GetPaid_Subscriptions_Query( $query ); |
|
112 | - $this->total_count = $this->query->get_total(); |
|
113 | - $this->current_total_count = $this->query->get_total(); |
|
114 | - $this->items = $this->query->get_results(); |
|
115 | - $this->status_counts = getpaid_get_subscription_status_counts( $query ); |
|
116 | - |
|
117 | - if ( 'all' != $query['status'] ) { |
|
118 | - unset( $query['status'] ); |
|
119 | - $this->total_count = getpaid_get_subscriptions( $query, 'count' ); |
|
120 | - } |
|
121 | - |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * Get user in. |
|
126 | - * |
|
127 | - */ |
|
128 | - public function get_user_in() { |
|
129 | - |
|
130 | - // Abort if no user. |
|
131 | - if ( empty( $_GET['s'] ) ) { |
|
132 | - return null; |
|
133 | - } |
|
134 | - |
|
135 | - // Or invalid user. |
|
136 | - $user = wp_unslash( sanitize_text_field( $_REQUEST['s'] ) ); |
|
137 | - |
|
138 | - if ( empty( $user ) ) { |
|
139 | - return null; |
|
140 | - } |
|
141 | - |
|
142 | - // Search matching users. |
|
143 | - $user = '*' . $user . '*'; |
|
144 | - $users = new WP_User_Query( |
|
145 | - array( |
|
146 | - 'fields' => 'ID', |
|
147 | - 'search' => $user, |
|
148 | - 'count_total' => false, |
|
149 | - ) |
|
150 | - ); |
|
151 | - |
|
152 | - return $users->get_results(); |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * Gets the list of views available on this table. |
|
157 | - * |
|
158 | - * The format is an associative array: |
|
159 | - * - `'id' => 'link'` |
|
160 | - * |
|
161 | - * @since 1.0.0 |
|
162 | - * |
|
163 | - * @return array |
|
164 | - */ |
|
165 | - public function get_views() { |
|
166 | - |
|
167 | - $current = isset( $_GET['status'] ) ? sanitize_text_field( $_GET['status'] ) : 'all'; |
|
168 | - $views = array( |
|
169 | - |
|
170 | - 'all' => sprintf( |
|
171 | - '<a href="%s" %s>%s <span class="count">(%d)</span></a>', |
|
172 | - esc_url( add_query_arg( 'status', false, $this->base_url ) ), |
|
173 | - $current === 'all' ? ' class="current"' : '', |
|
174 | - __( 'All', 'invoicing' ), |
|
175 | - $this->total_count |
|
176 | - ), |
|
177 | - |
|
178 | - ); |
|
179 | - |
|
180 | - foreach ( array_filter( $this->status_counts ) as $status => $count ) { |
|
181 | - |
|
182 | - $views[ $status ] = sprintf( |
|
183 | - '<a href="%s" %s>%s <span class="count">(%d)</span></a>', |
|
184 | - esc_url( add_query_arg( 'status', urlencode( $status ), $this->base_url ) ), |
|
185 | - $current === $status ? ' class="current"' : '', |
|
186 | - esc_html( getpaid_get_subscription_status_label( $status ) ), |
|
187 | - $count |
|
188 | - ); |
|
189 | - |
|
190 | - } |
|
191 | - |
|
192 | - return $views; |
|
193 | - |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * Render most columns |
|
198 | - * |
|
199 | - * @access private |
|
200 | - * @since 1.0.0 |
|
201 | - * @return string |
|
202 | - */ |
|
203 | - public function column_default( $item, $column_name ) { |
|
204 | - return apply_filters( "getpaid_subscriptions_table_column_$column_name", $item->$column_name ); |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * This is how checkbox column renders. |
|
209 | - * |
|
210 | - * @param WPInv_Subscription $item |
|
211 | - * @return string |
|
212 | - */ |
|
213 | - public function column_cb( $item ) { |
|
214 | - return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item->get_id() ) ); |
|
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * Status column |
|
219 | - * |
|
220 | - * @param WPInv_Subscription $item |
|
221 | - * @since 1.0.0 |
|
222 | - * @return string |
|
223 | - */ |
|
224 | - public function column_status( $item ) { |
|
225 | - return $item->get_status_label_html(); |
|
226 | - } |
|
227 | - |
|
228 | - /** |
|
229 | - * Subscription column |
|
230 | - * |
|
231 | - * @param WPInv_Subscription $item |
|
232 | - * @since 1.0.0 |
|
233 | - * @return string |
|
234 | - */ |
|
235 | - public function column_subscription( $item ) { |
|
236 | - |
|
237 | - $username = __( '(Missing User)', 'invoicing' ); |
|
238 | - |
|
239 | - $user = get_userdata( $item->get_customer_id() ); |
|
240 | - if ( $user ) { |
|
241 | - |
|
242 | - $username = sprintf( |
|
243 | - '<a href="user-edit.php?user_id=%s">%s</a>', |
|
244 | - absint( $user->ID ), |
|
245 | - ! empty( $user->display_name ) ? esc_html( $user->display_name ) : sanitize_email( $user->user_email ) |
|
246 | - ); |
|
247 | - |
|
248 | - } |
|
249 | - |
|
250 | - // translators: $1: is opening link, $2: is subscription id number, $3: is closing link tag, $4: is user's name |
|
251 | - $column_content = sprintf( |
|
252 | - _x( '%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing' ), |
|
253 | - '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $item->get_id() ) ) ) . '">', |
|
254 | - '<strong>' . esc_attr( $item->get_id() ) . '</strong>', |
|
19 | + /** |
|
20 | + * URL of this page |
|
21 | + * |
|
22 | + * @var string |
|
23 | + * @since 1.0.19 |
|
24 | + */ |
|
25 | + public $base_url; |
|
26 | + |
|
27 | + /** |
|
28 | + * Query |
|
29 | + * |
|
30 | + * @var GetPaid_Subscriptions_Query |
|
31 | + * @since 1.0.19 |
|
32 | + */ |
|
33 | + public $query; |
|
34 | + |
|
35 | + /** |
|
36 | + * Total subscriptions |
|
37 | + * |
|
38 | + * @var string |
|
39 | + * @since 1.0.0 |
|
40 | + */ |
|
41 | + public $total_count; |
|
42 | + |
|
43 | + /** |
|
44 | + * Current status subscriptions |
|
45 | + * |
|
46 | + * @var string |
|
47 | + * @since 1.0.0 |
|
48 | + */ |
|
49 | + public $current_total_count; |
|
50 | + |
|
51 | + /** |
|
52 | + * Status counts |
|
53 | + * |
|
54 | + * @var array |
|
55 | + * @since 1.0.19 |
|
56 | + */ |
|
57 | + public $status_counts; |
|
58 | + |
|
59 | + /** |
|
60 | + * Number of results to show per page |
|
61 | + * |
|
62 | + * @var int |
|
63 | + * @since 1.0.0 |
|
64 | + */ |
|
65 | + public $per_page = 10; |
|
66 | + |
|
67 | + /** |
|
68 | + * Constructor function. |
|
69 | + */ |
|
70 | + public function __construct() { |
|
71 | + |
|
72 | + parent::__construct( |
|
73 | + array( |
|
74 | + 'singular' => 'subscription', |
|
75 | + 'plural' => 'subscriptions', |
|
76 | + ) |
|
77 | + ); |
|
78 | + |
|
79 | + $this->process_bulk_action(); |
|
80 | + |
|
81 | + $this->prepare_query(); |
|
82 | + |
|
83 | + $this->base_url = remove_query_arg( 'status' ); |
|
84 | + |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * Prepares the display query |
|
89 | + */ |
|
90 | + public function prepare_query() { |
|
91 | + |
|
92 | + // Prepare query args. |
|
93 | + $query = array( |
|
94 | + 'number' => $this->per_page, |
|
95 | + 'paged' => $this->get_paged(), |
|
96 | + 'status' => ( isset( $_GET['status'] ) && array_key_exists( $_GET['status'], getpaid_get_subscription_statuses() ) ) ? sanitize_text_field( $_GET['status'] ) : 'all', |
|
97 | + 'orderby' => ( isset( $_GET['orderby'] ) ) ? sanitize_text_field( $_GET['orderby'] ) : 'id', |
|
98 | + 'order' => ( isset( $_GET['order'] ) ) ? sanitize_text_field( $_GET['order'] ) : 'DESC', |
|
99 | + 'customer_in' => $this->get_user_in(), |
|
100 | + ); |
|
101 | + |
|
102 | + if ( is_array( $query['customer_in'] ) && empty( $query['customer_in'] ) ) { |
|
103 | + $this->total_count = 0; |
|
104 | + $this->current_total_count = 0; |
|
105 | + $this->items = array(); |
|
106 | + $this->status_counts = array(); |
|
107 | + return; |
|
108 | + } |
|
109 | + |
|
110 | + // Prepare class properties. |
|
111 | + $this->query = new GetPaid_Subscriptions_Query( $query ); |
|
112 | + $this->total_count = $this->query->get_total(); |
|
113 | + $this->current_total_count = $this->query->get_total(); |
|
114 | + $this->items = $this->query->get_results(); |
|
115 | + $this->status_counts = getpaid_get_subscription_status_counts( $query ); |
|
116 | + |
|
117 | + if ( 'all' != $query['status'] ) { |
|
118 | + unset( $query['status'] ); |
|
119 | + $this->total_count = getpaid_get_subscriptions( $query, 'count' ); |
|
120 | + } |
|
121 | + |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * Get user in. |
|
126 | + * |
|
127 | + */ |
|
128 | + public function get_user_in() { |
|
129 | + |
|
130 | + // Abort if no user. |
|
131 | + if ( empty( $_GET['s'] ) ) { |
|
132 | + return null; |
|
133 | + } |
|
134 | + |
|
135 | + // Or invalid user. |
|
136 | + $user = wp_unslash( sanitize_text_field( $_REQUEST['s'] ) ); |
|
137 | + |
|
138 | + if ( empty( $user ) ) { |
|
139 | + return null; |
|
140 | + } |
|
141 | + |
|
142 | + // Search matching users. |
|
143 | + $user = '*' . $user . '*'; |
|
144 | + $users = new WP_User_Query( |
|
145 | + array( |
|
146 | + 'fields' => 'ID', |
|
147 | + 'search' => $user, |
|
148 | + 'count_total' => false, |
|
149 | + ) |
|
150 | + ); |
|
151 | + |
|
152 | + return $users->get_results(); |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * Gets the list of views available on this table. |
|
157 | + * |
|
158 | + * The format is an associative array: |
|
159 | + * - `'id' => 'link'` |
|
160 | + * |
|
161 | + * @since 1.0.0 |
|
162 | + * |
|
163 | + * @return array |
|
164 | + */ |
|
165 | + public function get_views() { |
|
166 | + |
|
167 | + $current = isset( $_GET['status'] ) ? sanitize_text_field( $_GET['status'] ) : 'all'; |
|
168 | + $views = array( |
|
169 | + |
|
170 | + 'all' => sprintf( |
|
171 | + '<a href="%s" %s>%s <span class="count">(%d)</span></a>', |
|
172 | + esc_url( add_query_arg( 'status', false, $this->base_url ) ), |
|
173 | + $current === 'all' ? ' class="current"' : '', |
|
174 | + __( 'All', 'invoicing' ), |
|
175 | + $this->total_count |
|
176 | + ), |
|
177 | + |
|
178 | + ); |
|
179 | + |
|
180 | + foreach ( array_filter( $this->status_counts ) as $status => $count ) { |
|
181 | + |
|
182 | + $views[ $status ] = sprintf( |
|
183 | + '<a href="%s" %s>%s <span class="count">(%d)</span></a>', |
|
184 | + esc_url( add_query_arg( 'status', urlencode( $status ), $this->base_url ) ), |
|
185 | + $current === $status ? ' class="current"' : '', |
|
186 | + esc_html( getpaid_get_subscription_status_label( $status ) ), |
|
187 | + $count |
|
188 | + ); |
|
189 | + |
|
190 | + } |
|
191 | + |
|
192 | + return $views; |
|
193 | + |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * Render most columns |
|
198 | + * |
|
199 | + * @access private |
|
200 | + * @since 1.0.0 |
|
201 | + * @return string |
|
202 | + */ |
|
203 | + public function column_default( $item, $column_name ) { |
|
204 | + return apply_filters( "getpaid_subscriptions_table_column_$column_name", $item->$column_name ); |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * This is how checkbox column renders. |
|
209 | + * |
|
210 | + * @param WPInv_Subscription $item |
|
211 | + * @return string |
|
212 | + */ |
|
213 | + public function column_cb( $item ) { |
|
214 | + return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item->get_id() ) ); |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * Status column |
|
219 | + * |
|
220 | + * @param WPInv_Subscription $item |
|
221 | + * @since 1.0.0 |
|
222 | + * @return string |
|
223 | + */ |
|
224 | + public function column_status( $item ) { |
|
225 | + return $item->get_status_label_html(); |
|
226 | + } |
|
227 | + |
|
228 | + /** |
|
229 | + * Subscription column |
|
230 | + * |
|
231 | + * @param WPInv_Subscription $item |
|
232 | + * @since 1.0.0 |
|
233 | + * @return string |
|
234 | + */ |
|
235 | + public function column_subscription( $item ) { |
|
236 | + |
|
237 | + $username = __( '(Missing User)', 'invoicing' ); |
|
238 | + |
|
239 | + $user = get_userdata( $item->get_customer_id() ); |
|
240 | + if ( $user ) { |
|
241 | + |
|
242 | + $username = sprintf( |
|
243 | + '<a href="user-edit.php?user_id=%s">%s</a>', |
|
244 | + absint( $user->ID ), |
|
245 | + ! empty( $user->display_name ) ? esc_html( $user->display_name ) : sanitize_email( $user->user_email ) |
|
246 | + ); |
|
247 | + |
|
248 | + } |
|
249 | + |
|
250 | + // translators: $1: is opening link, $2: is subscription id number, $3: is closing link tag, $4: is user's name |
|
251 | + $column_content = sprintf( |
|
252 | + _x( '%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing' ), |
|
253 | + '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $item->get_id() ) ) ) . '">', |
|
254 | + '<strong>' . esc_attr( $item->get_id() ) . '</strong>', |
|
255 | 255 | '</a>', |
256 | - $username |
|
257 | - ); |
|
258 | - |
|
259 | - $row_actions = array(); |
|
260 | - |
|
261 | - // View subscription. |
|
262 | - $view_url = esc_url( add_query_arg( 'id', $item->get_id(), admin_url( 'admin.php?page=wpinv-subscriptions' ) ) ); |
|
263 | - $row_actions['view'] = '<a href="' . $view_url . '">' . __( 'View Subscription', 'invoicing' ) . '</a>'; |
|
264 | - |
|
265 | - // View invoice. |
|
266 | - $invoice = get_post( $item->get_parent_invoice_id() ); |
|
267 | - |
|
268 | - if ( ! empty( $invoice ) ) { |
|
269 | - $invoice_url = get_edit_post_link( $invoice ); |
|
270 | - $row_actions['invoice'] = '<a href="' . $invoice_url . '">' . __( 'View Invoice', 'invoicing' ) . '</a>'; |
|
271 | - } |
|
272 | - |
|
273 | - $delete_url = esc_url( |
|
274 | - wp_nonce_url( |
|
275 | - add_query_arg( |
|
276 | - array( |
|
277 | - 'getpaid-admin-action' => 'subscription_manual_delete', |
|
278 | - 'id' => $item->get_id(), |
|
279 | - ) |
|
280 | - ), |
|
281 | - 'getpaid-nonce', |
|
282 | - 'getpaid-nonce' |
|
283 | - ) |
|
284 | - ); |
|
285 | - $row_actions['delete'] = '<a class="text-danger" href="' . $delete_url . '">' . __( 'Delete Subscription', 'invoicing' ) . '</a>'; |
|
286 | - |
|
287 | - $row_actions = $this->row_actions( apply_filters( 'getpaid_subscription_table_row_actions', $row_actions, $item ) ); |
|
288 | - |
|
289 | - return "<strong>$column_content</strong>" . $this->column_amount( $item ) . $row_actions; |
|
290 | - } |
|
291 | - |
|
292 | - /** |
|
293 | - * Renewal date column |
|
294 | - * |
|
295 | - * @param WPInv_Subscription $item |
|
296 | - * @since 1.0.0 |
|
297 | - * @return string |
|
298 | - */ |
|
299 | - public function column_renewal_date( $item ) { |
|
300 | - return getpaid_format_date_value( $item->get_expiration() ); |
|
301 | - } |
|
302 | - |
|
303 | - /** |
|
304 | - * Start date column |
|
305 | - * |
|
306 | - * @param WPInv_Subscription $item |
|
307 | - * @since 1.0.0 |
|
308 | - * @return string |
|
309 | - */ |
|
310 | - public function column_start_date( $item ) { |
|
311 | - |
|
312 | - $gateway = $item->get_parent_invoice()->get_gateway_title(); |
|
313 | - |
|
314 | - if ( empty( $gateway ) ) { |
|
315 | - return getpaid_format_date_value( $item->get_date_created() ); |
|
316 | - } |
|
317 | - |
|
318 | - $url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $item ); |
|
319 | - if ( ! empty( $url ) ) { |
|
320 | - |
|
321 | - return getpaid_format_date_value( $item->get_date_created() ) . '<br>' . sprintf( |
|
322 | - __( 'Via %s', 'invoicing' ), |
|
323 | - '<strong><a href="' . esc_url( $url ) . '" target="_blank">' . esc_html( $item->get_parent_invoice()->get_gateway_title() ) . '</a></strong>' |
|
324 | - ); |
|
325 | - |
|
326 | - } |
|
327 | - |
|
328 | - return getpaid_format_date_value( $item->get_date_created() ) . '<br>' . sprintf( |
|
329 | - __( 'Via %s', 'invoicing' ), |
|
330 | - '<strong>' . esc_html( $item->get_parent_invoice()->get_gateway_title() ) . '</strong>' |
|
331 | - ); |
|
332 | - |
|
333 | - } |
|
334 | - |
|
335 | - /** |
|
336 | - * Amount column |
|
337 | - * |
|
338 | - * @param WPInv_Subscription $item |
|
339 | - * @since 1.0.19 |
|
340 | - * @return string |
|
341 | - */ |
|
342 | - public static function column_amount( $item ) { |
|
343 | - $amount = getpaid_get_formatted_subscription_amount( $item ); |
|
344 | - return "<span class='text-muted form-text mt-2 mb-2'>$amount</span>"; |
|
345 | - } |
|
346 | - |
|
347 | - /** |
|
348 | - * Billing Times column |
|
349 | - * |
|
350 | - * @param WPInv_Subscription $item |
|
351 | - * @since 1.0.0 |
|
352 | - * @return string |
|
353 | - */ |
|
354 | - public function column_renewals( $item ) { |
|
355 | - $max_bills = $item->get_bill_times(); |
|
356 | - return $item->get_times_billed() . ' / ' . ( empty( $max_bills ) ? '∞' : $max_bills ); |
|
357 | - } |
|
358 | - |
|
359 | - /** |
|
360 | - * Product ID column |
|
361 | - * |
|
362 | - * @param WPInv_Subscription $item |
|
363 | - * @since 1.0.0 |
|
364 | - * @return string |
|
365 | - */ |
|
366 | - public function column_item( $item ) { |
|
367 | - $subscription_group = getpaid_get_invoice_subscription_group( $item->get_parent_invoice_id(), $item->get_id() ); |
|
368 | - |
|
369 | - if ( empty( $subscription_group ) ) { |
|
370 | - return $this->generate_item_markup( $item->get_product_id() ); |
|
371 | - } |
|
372 | - |
|
373 | - $markup = array_map( array( $this, 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
374 | - return implode( ' | ', $markup ); |
|
375 | - |
|
376 | - } |
|
377 | - |
|
378 | - /** |
|
379 | - * Generates the items markup. |
|
380 | - * |
|
381 | - * @param int $item_id |
|
382 | - * @since 1.0.0 |
|
383 | - * @return string |
|
384 | - */ |
|
385 | - public static function generate_item_markup( $item_id ) { |
|
386 | - $item = get_post( $item_id ); |
|
387 | - |
|
388 | - if ( ! empty( $item ) ) { |
|
389 | - $link = get_edit_post_link( $item ); |
|
390 | - $link = esc_url( $link ); |
|
391 | - $name = esc_html( get_the_title( $item ) ); |
|
392 | - return wpinv_current_user_can_manage_invoicing() ? "<a href='$link'>$name</a>" : $name; |
|
393 | - } else { |
|
394 | - return sprintf( __( 'Item #%s', 'invoicing' ), $item_id ); |
|
395 | - } |
|
396 | - |
|
397 | - } |
|
398 | - |
|
399 | - /** |
|
400 | - * Retrieve the current page number |
|
401 | - * |
|
402 | - * @return int |
|
403 | - */ |
|
404 | - public function get_paged() { |
|
405 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
406 | - } |
|
407 | - |
|
408 | - /** |
|
409 | - * Setup the final data for the table |
|
410 | - * |
|
411 | - */ |
|
412 | - public function prepare_items() { |
|
413 | - |
|
414 | - $columns = $this->get_columns(); |
|
415 | - $hidden = array(); |
|
416 | - $sortable = $this->get_sortable_columns(); |
|
417 | - |
|
418 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
419 | - |
|
420 | - $this->set_pagination_args( |
|
421 | - array( |
|
422 | - 'total_items' => $this->current_total_count, |
|
423 | - 'per_page' => $this->per_page, |
|
424 | - 'total_pages' => ceil( $this->current_total_count / $this->per_page ), |
|
425 | - ) |
|
426 | - ); |
|
427 | - } |
|
428 | - |
|
429 | - /** |
|
430 | - * Table columns |
|
431 | - * |
|
432 | - * @return array |
|
433 | - */ |
|
434 | - public function get_columns() { |
|
435 | - $columns = array( |
|
436 | - 'cb' => '<input type="checkbox" />', |
|
437 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
438 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
439 | - 'renewal_date' => __( 'Next Payment', 'invoicing' ), |
|
440 | - 'renewals' => __( 'Payments', 'invoicing' ), |
|
441 | - 'item' => __( 'Items', 'invoicing' ), |
|
442 | - 'status' => __( 'Status', 'invoicing' ), |
|
443 | - ); |
|
444 | - |
|
445 | - return apply_filters( 'manage_getpaid_subscriptions_table_columns', $columns ); |
|
446 | - } |
|
447 | - |
|
448 | - /** |
|
449 | - * Sortable table columns. |
|
450 | - * |
|
451 | - * @return array |
|
452 | - */ |
|
453 | - public function get_sortable_columns() { |
|
454 | - $sortable = array( |
|
455 | - 'subscription' => array( 'id', true ), |
|
456 | - 'start_date' => array( 'created', true ), |
|
457 | - 'renewal_date' => array( 'expiration', true ), |
|
458 | - 'renewals' => array( 'bill_times', true ), |
|
459 | - 'item' => array( 'product_id', true ), |
|
460 | - 'status' => array( 'status', true ), |
|
461 | - ); |
|
462 | - |
|
463 | - return apply_filters( 'manage_getpaid_subscriptions_sortable_table_columns', $sortable ); |
|
464 | - } |
|
465 | - |
|
466 | - /** |
|
467 | - * Whether the table has items to display or not |
|
468 | - * |
|
469 | - * @return bool |
|
470 | - */ |
|
471 | - public function has_items() { |
|
472 | - return ! empty( $this->current_total_count ); |
|
473 | - } |
|
474 | - |
|
475 | - /** |
|
476 | - * Processes bulk actions. |
|
477 | - * |
|
478 | - */ |
|
479 | - public function process_bulk_action() { |
|
480 | - |
|
481 | - } |
|
256 | + $username |
|
257 | + ); |
|
258 | + |
|
259 | + $row_actions = array(); |
|
260 | + |
|
261 | + // View subscription. |
|
262 | + $view_url = esc_url( add_query_arg( 'id', $item->get_id(), admin_url( 'admin.php?page=wpinv-subscriptions' ) ) ); |
|
263 | + $row_actions['view'] = '<a href="' . $view_url . '">' . __( 'View Subscription', 'invoicing' ) . '</a>'; |
|
264 | + |
|
265 | + // View invoice. |
|
266 | + $invoice = get_post( $item->get_parent_invoice_id() ); |
|
267 | + |
|
268 | + if ( ! empty( $invoice ) ) { |
|
269 | + $invoice_url = get_edit_post_link( $invoice ); |
|
270 | + $row_actions['invoice'] = '<a href="' . $invoice_url . '">' . __( 'View Invoice', 'invoicing' ) . '</a>'; |
|
271 | + } |
|
272 | + |
|
273 | + $delete_url = esc_url( |
|
274 | + wp_nonce_url( |
|
275 | + add_query_arg( |
|
276 | + array( |
|
277 | + 'getpaid-admin-action' => 'subscription_manual_delete', |
|
278 | + 'id' => $item->get_id(), |
|
279 | + ) |
|
280 | + ), |
|
281 | + 'getpaid-nonce', |
|
282 | + 'getpaid-nonce' |
|
283 | + ) |
|
284 | + ); |
|
285 | + $row_actions['delete'] = '<a class="text-danger" href="' . $delete_url . '">' . __( 'Delete Subscription', 'invoicing' ) . '</a>'; |
|
286 | + |
|
287 | + $row_actions = $this->row_actions( apply_filters( 'getpaid_subscription_table_row_actions', $row_actions, $item ) ); |
|
288 | + |
|
289 | + return "<strong>$column_content</strong>" . $this->column_amount( $item ) . $row_actions; |
|
290 | + } |
|
291 | + |
|
292 | + /** |
|
293 | + * Renewal date column |
|
294 | + * |
|
295 | + * @param WPInv_Subscription $item |
|
296 | + * @since 1.0.0 |
|
297 | + * @return string |
|
298 | + */ |
|
299 | + public function column_renewal_date( $item ) { |
|
300 | + return getpaid_format_date_value( $item->get_expiration() ); |
|
301 | + } |
|
302 | + |
|
303 | + /** |
|
304 | + * Start date column |
|
305 | + * |
|
306 | + * @param WPInv_Subscription $item |
|
307 | + * @since 1.0.0 |
|
308 | + * @return string |
|
309 | + */ |
|
310 | + public function column_start_date( $item ) { |
|
311 | + |
|
312 | + $gateway = $item->get_parent_invoice()->get_gateway_title(); |
|
313 | + |
|
314 | + if ( empty( $gateway ) ) { |
|
315 | + return getpaid_format_date_value( $item->get_date_created() ); |
|
316 | + } |
|
317 | + |
|
318 | + $url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $item ); |
|
319 | + if ( ! empty( $url ) ) { |
|
320 | + |
|
321 | + return getpaid_format_date_value( $item->get_date_created() ) . '<br>' . sprintf( |
|
322 | + __( 'Via %s', 'invoicing' ), |
|
323 | + '<strong><a href="' . esc_url( $url ) . '" target="_blank">' . esc_html( $item->get_parent_invoice()->get_gateway_title() ) . '</a></strong>' |
|
324 | + ); |
|
325 | + |
|
326 | + } |
|
327 | + |
|
328 | + return getpaid_format_date_value( $item->get_date_created() ) . '<br>' . sprintf( |
|
329 | + __( 'Via %s', 'invoicing' ), |
|
330 | + '<strong>' . esc_html( $item->get_parent_invoice()->get_gateway_title() ) . '</strong>' |
|
331 | + ); |
|
332 | + |
|
333 | + } |
|
334 | + |
|
335 | + /** |
|
336 | + * Amount column |
|
337 | + * |
|
338 | + * @param WPInv_Subscription $item |
|
339 | + * @since 1.0.19 |
|
340 | + * @return string |
|
341 | + */ |
|
342 | + public static function column_amount( $item ) { |
|
343 | + $amount = getpaid_get_formatted_subscription_amount( $item ); |
|
344 | + return "<span class='text-muted form-text mt-2 mb-2'>$amount</span>"; |
|
345 | + } |
|
346 | + |
|
347 | + /** |
|
348 | + * Billing Times column |
|
349 | + * |
|
350 | + * @param WPInv_Subscription $item |
|
351 | + * @since 1.0.0 |
|
352 | + * @return string |
|
353 | + */ |
|
354 | + public function column_renewals( $item ) { |
|
355 | + $max_bills = $item->get_bill_times(); |
|
356 | + return $item->get_times_billed() . ' / ' . ( empty( $max_bills ) ? '∞' : $max_bills ); |
|
357 | + } |
|
358 | + |
|
359 | + /** |
|
360 | + * Product ID column |
|
361 | + * |
|
362 | + * @param WPInv_Subscription $item |
|
363 | + * @since 1.0.0 |
|
364 | + * @return string |
|
365 | + */ |
|
366 | + public function column_item( $item ) { |
|
367 | + $subscription_group = getpaid_get_invoice_subscription_group( $item->get_parent_invoice_id(), $item->get_id() ); |
|
368 | + |
|
369 | + if ( empty( $subscription_group ) ) { |
|
370 | + return $this->generate_item_markup( $item->get_product_id() ); |
|
371 | + } |
|
372 | + |
|
373 | + $markup = array_map( array( $this, 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
374 | + return implode( ' | ', $markup ); |
|
375 | + |
|
376 | + } |
|
377 | + |
|
378 | + /** |
|
379 | + * Generates the items markup. |
|
380 | + * |
|
381 | + * @param int $item_id |
|
382 | + * @since 1.0.0 |
|
383 | + * @return string |
|
384 | + */ |
|
385 | + public static function generate_item_markup( $item_id ) { |
|
386 | + $item = get_post( $item_id ); |
|
387 | + |
|
388 | + if ( ! empty( $item ) ) { |
|
389 | + $link = get_edit_post_link( $item ); |
|
390 | + $link = esc_url( $link ); |
|
391 | + $name = esc_html( get_the_title( $item ) ); |
|
392 | + return wpinv_current_user_can_manage_invoicing() ? "<a href='$link'>$name</a>" : $name; |
|
393 | + } else { |
|
394 | + return sprintf( __( 'Item #%s', 'invoicing' ), $item_id ); |
|
395 | + } |
|
396 | + |
|
397 | + } |
|
398 | + |
|
399 | + /** |
|
400 | + * Retrieve the current page number |
|
401 | + * |
|
402 | + * @return int |
|
403 | + */ |
|
404 | + public function get_paged() { |
|
405 | + return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
406 | + } |
|
407 | + |
|
408 | + /** |
|
409 | + * Setup the final data for the table |
|
410 | + * |
|
411 | + */ |
|
412 | + public function prepare_items() { |
|
413 | + |
|
414 | + $columns = $this->get_columns(); |
|
415 | + $hidden = array(); |
|
416 | + $sortable = $this->get_sortable_columns(); |
|
417 | + |
|
418 | + $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
419 | + |
|
420 | + $this->set_pagination_args( |
|
421 | + array( |
|
422 | + 'total_items' => $this->current_total_count, |
|
423 | + 'per_page' => $this->per_page, |
|
424 | + 'total_pages' => ceil( $this->current_total_count / $this->per_page ), |
|
425 | + ) |
|
426 | + ); |
|
427 | + } |
|
428 | + |
|
429 | + /** |
|
430 | + * Table columns |
|
431 | + * |
|
432 | + * @return array |
|
433 | + */ |
|
434 | + public function get_columns() { |
|
435 | + $columns = array( |
|
436 | + 'cb' => '<input type="checkbox" />', |
|
437 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
438 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
439 | + 'renewal_date' => __( 'Next Payment', 'invoicing' ), |
|
440 | + 'renewals' => __( 'Payments', 'invoicing' ), |
|
441 | + 'item' => __( 'Items', 'invoicing' ), |
|
442 | + 'status' => __( 'Status', 'invoicing' ), |
|
443 | + ); |
|
444 | + |
|
445 | + return apply_filters( 'manage_getpaid_subscriptions_table_columns', $columns ); |
|
446 | + } |
|
447 | + |
|
448 | + /** |
|
449 | + * Sortable table columns. |
|
450 | + * |
|
451 | + * @return array |
|
452 | + */ |
|
453 | + public function get_sortable_columns() { |
|
454 | + $sortable = array( |
|
455 | + 'subscription' => array( 'id', true ), |
|
456 | + 'start_date' => array( 'created', true ), |
|
457 | + 'renewal_date' => array( 'expiration', true ), |
|
458 | + 'renewals' => array( 'bill_times', true ), |
|
459 | + 'item' => array( 'product_id', true ), |
|
460 | + 'status' => array( 'status', true ), |
|
461 | + ); |
|
462 | + |
|
463 | + return apply_filters( 'manage_getpaid_subscriptions_sortable_table_columns', $sortable ); |
|
464 | + } |
|
465 | + |
|
466 | + /** |
|
467 | + * Whether the table has items to display or not |
|
468 | + * |
|
469 | + * @return bool |
|
470 | + */ |
|
471 | + public function has_items() { |
|
472 | + return ! empty( $this->current_total_count ); |
|
473 | + } |
|
474 | + |
|
475 | + /** |
|
476 | + * Processes bulk actions. |
|
477 | + * |
|
478 | + */ |
|
479 | + public function process_bulk_action() { |
|
480 | + |
|
481 | + } |
|
482 | 482 | |
483 | 483 | } |
@@ -44,9 +44,9 @@ discard block |
||
44 | 44 | <?php |
45 | 45 | |
46 | 46 | if ( wpinv_is_gateway_active( $id ) ) { |
47 | - echo "<i class='text-success fa fa-check'></i>"; |
|
47 | + echo "<i class='text-success fa fa-check'></i>"; |
|
48 | 48 | } else { |
49 | - echo "<i class='text-dark fa fa-times'></i>"; |
|
49 | + echo "<i class='text-dark fa fa-times'></i>"; |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | ?> |
@@ -58,9 +58,9 @@ discard block |
||
58 | 58 | $supports = apply_filters( 'getapid_gateway_supports_subscription', $supports, $id ); |
59 | 59 | |
60 | 60 | if ( $supports ) { |
61 | - echo "<i class='text-success fa fa-check'></i>"; |
|
61 | + echo "<i class='text-success fa fa-check'></i>"; |
|
62 | 62 | } else { |
63 | - echo "<i class='text-dark fa fa-times'></i>"; |
|
63 | + echo "<i class='text-dark fa fa-times'></i>"; |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | ?> |
@@ -27,7 +27,7 @@ |
||
27 | 27 | <input type="checkbox" name="plugins[<?php echo esc_attr( $plugin['slug'] ); ?>]" value="<?php echo esc_attr( $plugin['file'] ); ?>" class="custom-control-input" |
28 | 28 | <?php |
29 | 29 | if ( is_plugin_active( $plugin['slug'] ) ) { |
30 | - echo 'checked';} |
|
30 | + echo 'checked';} |
|
31 | 31 | ?> |
32 | 32 | > |
33 | 33 | <label class="custom-control-label" for="ac-setting-updates"></label> |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
10 | - exit; // Exit if accessed directly |
|
10 | + exit; // Exit if accessed directly |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | /** |
@@ -15,22 +15,22 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class GetPaid_Meta_Box_Invoice_Shipping_Address { |
17 | 17 | |
18 | - /** |
|
19 | - * Output the metabox. |
|
20 | - * |
|
21 | - * @param WP_Post $post |
|
22 | - */ |
|
23 | - public static function output( $post ) { |
|
18 | + /** |
|
19 | + * Output the metabox. |
|
20 | + * |
|
21 | + * @param WP_Post $post |
|
22 | + */ |
|
23 | + public static function output( $post ) { |
|
24 | 24 | |
25 | - // Retrieve shipping address. |
|
26 | - $shipping_address = get_post_meta( $post->ID, 'shipping_address', true ); |
|
25 | + // Retrieve shipping address. |
|
26 | + $shipping_address = get_post_meta( $post->ID, 'shipping_address', true ); |
|
27 | 27 | |
28 | - // Abort if it is invalid. |
|
29 | - if ( ! is_array( $shipping_address ) ) { |
|
30 | - return; |
|
31 | - } |
|
28 | + // Abort if it is invalid. |
|
29 | + if ( ! is_array( $shipping_address ) ) { |
|
30 | + return; |
|
31 | + } |
|
32 | 32 | |
33 | - ?> |
|
33 | + ?> |
|
34 | 34 | |
35 | 35 | <div class="bsui"> |
36 | 36 | |
@@ -68,31 +68,31 @@ discard block |
||
68 | 68 | |
69 | 69 | <?php |
70 | 70 | |
71 | - } |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * Prepares a value. |
|
75 | - * |
|
76 | - * @param array $address |
|
77 | - * @param string $key |
|
78 | - * @return string |
|
79 | - */ |
|
80 | - public static function prepare_for_display( $address, $key ) { |
|
73 | + /** |
|
74 | + * Prepares a value. |
|
75 | + * |
|
76 | + * @param array $address |
|
77 | + * @param string $key |
|
78 | + * @return string |
|
79 | + */ |
|
80 | + public static function prepare_for_display( $address, $key ) { |
|
81 | 81 | |
82 | - // Prepare the value. |
|
83 | - $value = $address[ $key ]; |
|
82 | + // Prepare the value. |
|
83 | + $value = $address[ $key ]; |
|
84 | 84 | |
85 | - if ( $key == 'country' ) { |
|
86 | - $value = wpinv_country_name( $value ); |
|
87 | - } |
|
85 | + if ( $key == 'country' ) { |
|
86 | + $value = wpinv_country_name( $value ); |
|
87 | + } |
|
88 | 88 | |
89 | - if ( $key == 'state' ) { |
|
90 | - $country = isset( $address['country'] ) ? $address['country'] : wpinv_get_default_country(); |
|
91 | - $value = wpinv_state_name( $value, $country ); |
|
92 | - } |
|
89 | + if ( $key == 'state' ) { |
|
90 | + $country = isset( $address['country'] ) ? $address['country'] : wpinv_get_default_country(); |
|
91 | + $value = wpinv_state_name( $value, $country ); |
|
92 | + } |
|
93 | 93 | |
94 | - return esc_html( $value ); |
|
94 | + return esc_html( $value ); |
|
95 | 95 | |
96 | - } |
|
96 | + } |
|
97 | 97 | |
98 | 98 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
11 | - exit; // Exit if accessed directly |
|
11 | + exit; // Exit if accessed directly |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | /** |
@@ -17,10 +17,10 @@ discard block |
||
17 | 17 | class GetPaid_Meta_Box_Discount_Details { |
18 | 18 | |
19 | 19 | /** |
20 | - * Output the metabox. |
|
21 | - * |
|
22 | - * @param WP_Post $post |
|
23 | - */ |
|
20 | + * Output the metabox. |
|
21 | + * |
|
22 | + * @param WP_Post $post |
|
23 | + */ |
|
24 | 24 | public static function output( $post ) { |
25 | 25 | |
26 | 26 | // Prepare the discount. |
@@ -396,35 +396,35 @@ discard block |
||
396 | 396 | } |
397 | 397 | |
398 | 398 | /** |
399 | - * Save meta box data. |
|
400 | - * |
|
401 | - * @param int $post_id |
|
402 | - */ |
|
403 | - public static function save( $post_id ) { |
|
399 | + * Save meta box data. |
|
400 | + * |
|
401 | + * @param int $post_id |
|
402 | + */ |
|
403 | + public static function save( $post_id ) { |
|
404 | 404 | |
405 | 405 | // Prepare the discount. |
406 | 406 | $discount = new WPInv_Discount( $post_id ); |
407 | 407 | |
408 | 408 | // Load new data. |
409 | 409 | $discount->set_props( |
410 | - array( |
|
411 | - 'code' => isset( $_POST['wpinv_discount_code'] ) ? wpinv_clean( $_POST['wpinv_discount_code'] ) : null, |
|
412 | - 'amount' => isset( $_POST['wpinv_discount_amount'] ) ? floatval( $_POST['wpinv_discount_amount'] ) : null, |
|
413 | - 'start' => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null, |
|
414 | - 'expiration' => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null, |
|
415 | - 'is_single_use' => ! empty( $_POST['wpinv_discount_single_use'] ), |
|
410 | + array( |
|
411 | + 'code' => isset( $_POST['wpinv_discount_code'] ) ? wpinv_clean( $_POST['wpinv_discount_code'] ) : null, |
|
412 | + 'amount' => isset( $_POST['wpinv_discount_amount'] ) ? floatval( $_POST['wpinv_discount_amount'] ) : null, |
|
413 | + 'start' => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null, |
|
414 | + 'expiration' => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null, |
|
415 | + 'is_single_use' => ! empty( $_POST['wpinv_discount_single_use'] ), |
|
416 | 416 | 'type' => isset( $_POST['wpinv_discount_type'] ) ? wpinv_clean( $_POST['wpinv_discount_type'] ) : null, |
417 | - 'is_recurring' => ! empty( $_POST['wpinv_discount_recurring'] ), |
|
418 | - 'items' => isset( $_POST['wpinv_discount_items'] ) ? wpinv_clean( $_POST['wpinv_discount_items'] ) : array(), |
|
419 | - 'excluded_items' => isset( $_POST['wpinv_discount_excluded_items'] ) ? wpinv_clean( $_POST['wpinv_discount_excluded_items'] ) : array(), |
|
417 | + 'is_recurring' => ! empty( $_POST['wpinv_discount_recurring'] ), |
|
418 | + 'items' => isset( $_POST['wpinv_discount_items'] ) ? wpinv_clean( $_POST['wpinv_discount_items'] ) : array(), |
|
419 | + 'excluded_items' => isset( $_POST['wpinv_discount_excluded_items'] ) ? wpinv_clean( $_POST['wpinv_discount_excluded_items'] ) : array(), |
|
420 | 420 | 'required_items' => isset( $_POST['wpinv_discount_required_items'] ) ? wpinv_clean( $_POST['wpinv_discount_required_items'] ) : array(), |
421 | - 'max_uses' => isset( $_POST['wpinv_discount_max_uses'] ) ? intval( $_POST['wpinv_discount_max_uses'] ) : null, |
|
422 | - 'min_total' => isset( $_POST['wpinv_discount_min_total'] ) ? floatval( $_POST['wpinv_discount_min_total'] ) : null, |
|
423 | - 'max_total' => isset( $_POST['wpinv_discount_max_total'] ) ? floatval( $_POST['wpinv_discount_max_total'] ) : null, |
|
424 | - ) |
|
421 | + 'max_uses' => isset( $_POST['wpinv_discount_max_uses'] ) ? intval( $_POST['wpinv_discount_max_uses'] ) : null, |
|
422 | + 'min_total' => isset( $_POST['wpinv_discount_min_total'] ) ? floatval( $_POST['wpinv_discount_min_total'] ) : null, |
|
423 | + 'max_total' => isset( $_POST['wpinv_discount_max_total'] ) ? floatval( $_POST['wpinv_discount_max_total'] ) : null, |
|
424 | + ) |
|
425 | 425 | ); |
426 | 426 | |
427 | - $discount->save(); |
|
428 | - do_action( 'getpaid_discount_metabox_save', $post_id, $discount ); |
|
429 | - } |
|
427 | + $discount->save(); |
|
428 | + do_action( 'getpaid_discount_metabox_save', $post_id, $discount ); |
|
429 | + } |
|
430 | 430 | } |
@@ -5,110 +5,110 @@ discard block |
||
5 | 5 | */ |
6 | 6 | |
7 | 7 | if ( ! defined( 'ABSPATH' ) ) { |
8 | - exit; // Exit if accessed directly |
|
8 | + exit; // Exit if accessed directly |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | if ( ! class_exists( 'GetPaid_Admin_Profile', false ) ) : |
12 | 12 | |
13 | - /** |
|
14 | - * GetPaid_Admin_Profile Class. |
|
15 | - */ |
|
16 | - class GetPaid_Admin_Profile { |
|
17 | - |
|
18 | - /** |
|
19 | - * Hook in tabs. |
|
20 | - */ |
|
21 | - public function __construct() { |
|
22 | - add_action( 'show_user_profile', array( $this, 'add_customer_meta_fields' ), 100 ); |
|
23 | - add_action( 'edit_user_profile', array( $this, 'add_customer_meta_fields' ), 100 ); |
|
24 | - |
|
25 | - add_action( 'personal_options_update', array( $this, 'save_customer_meta_fields' ) ); |
|
26 | - add_action( 'edit_user_profile_update', array( $this, 'save_customer_meta_fields' ) ); |
|
27 | - } |
|
28 | - |
|
29 | - /** |
|
30 | - * Get Address Fields for the edit user pages. |
|
31 | - * |
|
32 | - * @return array Fields to display which are filtered through invoicing_customer_meta_fields before being returned |
|
33 | - */ |
|
34 | - public function get_customer_meta_fields() { |
|
35 | - |
|
36 | - $show_fields = apply_filters( |
|
37 | - 'getpaid_customer_meta_fields', |
|
38 | - array( |
|
39 | - 'billing' => array( |
|
40 | - 'title' => __( 'Billing Details (GetPaid)', 'invoicing' ), |
|
41 | - 'fields' => array( |
|
42 | - '_wpinv_first_name' => array( |
|
43 | - 'label' => __( 'First name', 'invoicing' ), |
|
44 | - 'description' => '', |
|
45 | - ), |
|
46 | - '_wpinv_last_name' => array( |
|
47 | - 'label' => __( 'Last name', 'invoicing' ), |
|
48 | - 'description' => '', |
|
49 | - ), |
|
50 | - '_wpinv_company' => array( |
|
51 | - 'label' => __( 'Company', 'invoicing' ), |
|
52 | - 'description' => '', |
|
53 | - ), |
|
54 | - '_wpinv_company_id' => array( |
|
55 | - 'label' => __( 'Company ID', 'invoicing' ), |
|
56 | - 'description' => '', |
|
57 | - ), |
|
58 | - '_wpinv_address' => array( |
|
59 | - 'label' => __( 'Address', 'invoicing' ), |
|
60 | - 'description' => '', |
|
61 | - ), |
|
62 | - '_wpinv_city' => array( |
|
63 | - 'label' => __( 'City', 'invoicing' ), |
|
64 | - 'description' => '', |
|
65 | - ), |
|
66 | - '_wpinv_zip' => array( |
|
67 | - 'label' => __( 'Postcode / ZIP', 'invoicing' ), |
|
68 | - 'description' => '', |
|
69 | - ), |
|
70 | - '_wpinv_country' => array( |
|
71 | - 'label' => __( 'Country / Region', 'invoicing' ), |
|
72 | - 'description' => '', |
|
73 | - 'class' => 'getpaid_js_field-country', |
|
74 | - 'type' => 'select', |
|
75 | - 'options' => array( '' => __( 'Select a country / region…', 'invoicing' ) ) + wpinv_get_country_list(), |
|
76 | - ), |
|
77 | - '_wpinv_state' => array( |
|
78 | - 'label' => __( 'State / County', 'invoicing' ), |
|
79 | - 'description' => __( 'State / County or state code', 'invoicing' ), |
|
80 | - 'class' => 'getpaid_js_field-state regular-text', |
|
81 | - ), |
|
82 | - '_wpinv_phone' => array( |
|
83 | - 'label' => __( 'Phone', 'invoicing' ), |
|
84 | - 'description' => '', |
|
85 | - ), |
|
86 | - '_wpinv_vat_number' => array( |
|
87 | - 'label' => __( 'VAT Number', 'invoicing' ), |
|
88 | - 'description' => '', |
|
89 | - ), |
|
90 | - ), |
|
91 | - ), |
|
92 | - ) |
|
93 | - ); |
|
94 | - return $show_fields; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Show Address Fields on edit user pages. |
|
99 | - * |
|
100 | - * @param WP_User $user |
|
101 | - */ |
|
102 | - public function add_customer_meta_fields( $user ) { |
|
103 | - |
|
104 | - if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user->ID ) ) { |
|
105 | - return; |
|
106 | - } |
|
107 | - |
|
108 | - $show_fields = $this->get_customer_meta_fields(); |
|
109 | - |
|
110 | - foreach ( $show_fields as $fieldset_key => $fieldset ) : |
|
111 | - ?> |
|
13 | + /** |
|
14 | + * GetPaid_Admin_Profile Class. |
|
15 | + */ |
|
16 | + class GetPaid_Admin_Profile { |
|
17 | + |
|
18 | + /** |
|
19 | + * Hook in tabs. |
|
20 | + */ |
|
21 | + public function __construct() { |
|
22 | + add_action( 'show_user_profile', array( $this, 'add_customer_meta_fields' ), 100 ); |
|
23 | + add_action( 'edit_user_profile', array( $this, 'add_customer_meta_fields' ), 100 ); |
|
24 | + |
|
25 | + add_action( 'personal_options_update', array( $this, 'save_customer_meta_fields' ) ); |
|
26 | + add_action( 'edit_user_profile_update', array( $this, 'save_customer_meta_fields' ) ); |
|
27 | + } |
|
28 | + |
|
29 | + /** |
|
30 | + * Get Address Fields for the edit user pages. |
|
31 | + * |
|
32 | + * @return array Fields to display which are filtered through invoicing_customer_meta_fields before being returned |
|
33 | + */ |
|
34 | + public function get_customer_meta_fields() { |
|
35 | + |
|
36 | + $show_fields = apply_filters( |
|
37 | + 'getpaid_customer_meta_fields', |
|
38 | + array( |
|
39 | + 'billing' => array( |
|
40 | + 'title' => __( 'Billing Details (GetPaid)', 'invoicing' ), |
|
41 | + 'fields' => array( |
|
42 | + '_wpinv_first_name' => array( |
|
43 | + 'label' => __( 'First name', 'invoicing' ), |
|
44 | + 'description' => '', |
|
45 | + ), |
|
46 | + '_wpinv_last_name' => array( |
|
47 | + 'label' => __( 'Last name', 'invoicing' ), |
|
48 | + 'description' => '', |
|
49 | + ), |
|
50 | + '_wpinv_company' => array( |
|
51 | + 'label' => __( 'Company', 'invoicing' ), |
|
52 | + 'description' => '', |
|
53 | + ), |
|
54 | + '_wpinv_company_id' => array( |
|
55 | + 'label' => __( 'Company ID', 'invoicing' ), |
|
56 | + 'description' => '', |
|
57 | + ), |
|
58 | + '_wpinv_address' => array( |
|
59 | + 'label' => __( 'Address', 'invoicing' ), |
|
60 | + 'description' => '', |
|
61 | + ), |
|
62 | + '_wpinv_city' => array( |
|
63 | + 'label' => __( 'City', 'invoicing' ), |
|
64 | + 'description' => '', |
|
65 | + ), |
|
66 | + '_wpinv_zip' => array( |
|
67 | + 'label' => __( 'Postcode / ZIP', 'invoicing' ), |
|
68 | + 'description' => '', |
|
69 | + ), |
|
70 | + '_wpinv_country' => array( |
|
71 | + 'label' => __( 'Country / Region', 'invoicing' ), |
|
72 | + 'description' => '', |
|
73 | + 'class' => 'getpaid_js_field-country', |
|
74 | + 'type' => 'select', |
|
75 | + 'options' => array( '' => __( 'Select a country / region…', 'invoicing' ) ) + wpinv_get_country_list(), |
|
76 | + ), |
|
77 | + '_wpinv_state' => array( |
|
78 | + 'label' => __( 'State / County', 'invoicing' ), |
|
79 | + 'description' => __( 'State / County or state code', 'invoicing' ), |
|
80 | + 'class' => 'getpaid_js_field-state regular-text', |
|
81 | + ), |
|
82 | + '_wpinv_phone' => array( |
|
83 | + 'label' => __( 'Phone', 'invoicing' ), |
|
84 | + 'description' => '', |
|
85 | + ), |
|
86 | + '_wpinv_vat_number' => array( |
|
87 | + 'label' => __( 'VAT Number', 'invoicing' ), |
|
88 | + 'description' => '', |
|
89 | + ), |
|
90 | + ), |
|
91 | + ), |
|
92 | + ) |
|
93 | + ); |
|
94 | + return $show_fields; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Show Address Fields on edit user pages. |
|
99 | + * |
|
100 | + * @param WP_User $user |
|
101 | + */ |
|
102 | + public function add_customer_meta_fields( $user ) { |
|
103 | + |
|
104 | + if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user->ID ) ) { |
|
105 | + return; |
|
106 | + } |
|
107 | + |
|
108 | + $show_fields = $this->get_customer_meta_fields(); |
|
109 | + |
|
110 | + foreach ( $show_fields as $fieldset_key => $fieldset ) : |
|
111 | + ?> |
|
112 | 112 | <h2><?php echo esc_html( $fieldset['title'] ); ?></h2> |
113 | 113 | <table class="form-table" id="<?php echo esc_attr( 'getpaid-fieldset-' . $fieldset_key ); ?>"> |
114 | 114 | <?php foreach ( $fieldset['fields'] as $key => $field ) : ?> |
@@ -120,9 +120,9 @@ discard block |
||
120 | 120 | <?php if ( ! empty( $field['type'] ) && 'select' === $field['type'] ) : ?> |
121 | 121 | <select name="<?php echo esc_attr( $key ); ?>" id="<?php echo esc_attr( $key ); ?>" class="<?php echo esc_attr( $field['class'] ); ?> wpi_select2" style="width: 25em;"> |
122 | 122 | <?php |
123 | - $selected = esc_attr( get_user_meta( $user->ID, $key, true ) ); |
|
124 | - foreach ( $field['options'] as $option_key => $option_value ) : |
|
125 | - ?> |
|
123 | + $selected = esc_attr( get_user_meta( $user->ID, $key, true ) ); |
|
124 | + foreach ( $field['options'] as $option_key => $option_value ) : |
|
125 | + ?> |
|
126 | 126 | <option value="<?php echo esc_attr( $option_key ); ?>" <?php selected( $selected, $option_key, true ); ?>><?php echo esc_html( $option_value ); ?></option> |
127 | 127 | <?php endforeach; ?> |
128 | 128 | </select> |
@@ -137,52 +137,52 @@ discard block |
||
137 | 137 | <?php endforeach; ?> |
138 | 138 | </table> |
139 | 139 | <?php |
140 | - endforeach; |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Save Address Fields on edit user pages. |
|
145 | - * |
|
146 | - * @param int $user_id User ID of the user being saved |
|
147 | - */ |
|
148 | - public function save_customer_meta_fields( $user_id ) { |
|
149 | - if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user_id ) ) { |
|
150 | - return; |
|
151 | - } |
|
152 | - |
|
153 | - $save_fields = $this->get_customer_meta_fields(); |
|
154 | - |
|
155 | - foreach ( $save_fields as $fieldset ) { |
|
156 | - |
|
157 | - foreach ( $fieldset['fields'] as $key => $field ) { |
|
158 | - |
|
159 | - if ( isset( $field['type'] ) && 'checkbox' === $field['type'] ) { |
|
160 | - update_user_meta( $user_id, $key, ! empty( $_POST[ $key ] ) ); |
|
161 | - } elseif ( isset( $_POST[ $key ] ) ) { |
|
162 | - update_user_meta( $user_id, $key, wpinv_clean( $_POST[ $key ] ) ); |
|
163 | - } |
|
164 | - } |
|
165 | - } |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Get user meta for a given key, with fallbacks to core user info for pre-existing fields. |
|
170 | - * |
|
171 | - * @since 3.1.0 |
|
172 | - * @param int $user_id User ID of the user being edited |
|
173 | - * @param string $key Key for user meta field |
|
174 | - * @return string |
|
175 | - */ |
|
176 | - protected function get_user_meta( $user_id, $key ) { |
|
177 | - $value = get_user_meta( $user_id, $key, true ); |
|
178 | - $existing_fields = array( '_wpinv_first_name', '_wpinv_last_name' ); |
|
179 | - if ( ! $value && in_array( $key, $existing_fields ) ) { |
|
180 | - $value = get_user_meta( $user_id, str_replace( '_wpinv_', '', $key ), true ); |
|
181 | - } |
|
182 | - |
|
183 | - return $value; |
|
184 | - } |
|
185 | - } |
|
140 | + endforeach; |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Save Address Fields on edit user pages. |
|
145 | + * |
|
146 | + * @param int $user_id User ID of the user being saved |
|
147 | + */ |
|
148 | + public function save_customer_meta_fields( $user_id ) { |
|
149 | + if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user_id ) ) { |
|
150 | + return; |
|
151 | + } |
|
152 | + |
|
153 | + $save_fields = $this->get_customer_meta_fields(); |
|
154 | + |
|
155 | + foreach ( $save_fields as $fieldset ) { |
|
156 | + |
|
157 | + foreach ( $fieldset['fields'] as $key => $field ) { |
|
158 | + |
|
159 | + if ( isset( $field['type'] ) && 'checkbox' === $field['type'] ) { |
|
160 | + update_user_meta( $user_id, $key, ! empty( $_POST[ $key ] ) ); |
|
161 | + } elseif ( isset( $_POST[ $key ] ) ) { |
|
162 | + update_user_meta( $user_id, $key, wpinv_clean( $_POST[ $key ] ) ); |
|
163 | + } |
|
164 | + } |
|
165 | + } |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Get user meta for a given key, with fallbacks to core user info for pre-existing fields. |
|
170 | + * |
|
171 | + * @since 3.1.0 |
|
172 | + * @param int $user_id User ID of the user being edited |
|
173 | + * @param string $key Key for user meta field |
|
174 | + * @return string |
|
175 | + */ |
|
176 | + protected function get_user_meta( $user_id, $key ) { |
|
177 | + $value = get_user_meta( $user_id, $key, true ); |
|
178 | + $existing_fields = array( '_wpinv_first_name', '_wpinv_last_name' ); |
|
179 | + if ( ! $value && in_array( $key, $existing_fields ) ) { |
|
180 | + $value = get_user_meta( $user_id, str_replace( '_wpinv_', '', $key ), true ); |
|
181 | + } |
|
182 | + |
|
183 | + return $value; |
|
184 | + } |
|
185 | + } |
|
186 | 186 | |
187 | 187 | endif; |
188 | 188 |
@@ -57,8 +57,8 @@ discard block |
||
57 | 57 | 'getpaid-nonce', |
58 | 58 | 'getpaid-nonce' |
59 | 59 | ); |
60 | - $anchor = __( 'Deactivate', 'invoicing' ); |
|
61 | - $title = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' ); |
|
60 | + $anchor = __( 'Deactivate', 'invoicing' ); |
|
61 | + $title = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' ); |
|
62 | 62 | $row_actions['deactivate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
63 | 63 | |
64 | 64 | } elseif ( in_array( strtolower( $discount->post_status ), array( 'pending', 'draft' ) ) ) { |
@@ -73,8 +73,8 @@ discard block |
||
73 | 73 | 'getpaid-nonce', |
74 | 74 | 'getpaid-nonce' |
75 | 75 | ); |
76 | - $anchor = __( 'Activate', 'invoicing' ); |
|
77 | - $title = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' ); |
|
76 | + $anchor = __( 'Activate', 'invoicing' ); |
|
77 | + $title = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' ); |
|
78 | 78 | $row_actions['activate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
79 | 79 | |
80 | 80 | } |
@@ -91,8 +91,8 @@ discard block |
||
91 | 91 | 'getpaid-nonce' |
92 | 92 | ) |
93 | 93 | ); |
94 | - $anchor = __( 'Delete', 'invoicing' ); |
|
95 | - $title = esc_attr__( 'Are you sure you want to delete this discount?', 'invoicing' ); |
|
94 | + $anchor = __( 'Delete', 'invoicing' ); |
|
95 | + $title = esc_attr__( 'Are you sure you want to delete this discount?', 'invoicing' ); |
|
96 | 96 | $row_actions['delete'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
97 | 97 | |
98 | 98 | $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount ); |
@@ -118,13 +118,13 @@ discard block |
||
118 | 118 | $types = wpinv_get_discount_types(); |
119 | 119 | |
120 | 120 | foreach ( $types as $name => $type ) { |
121 | - echo '<option value="' . esc_attr( $name ) . '"'; |
|
121 | + echo '<option value="' . esc_attr( $name ) . '"'; |
|
122 | 122 | |
123 | - if ( isset( $_GET['discount_type'] ) ) { |
|
124 | - selected( $name, sanitize_text_field( $_GET['discount_type'] ) ); |
|
123 | + if ( isset( $_GET['discount_type'] ) ) { |
|
124 | + selected( $name, sanitize_text_field( $_GET['discount_type'] ) ); |
|
125 | 125 | } |
126 | 126 | |
127 | - echo '>' . esc_html__( $type, 'invoicing' ) . '</option>'; |
|
127 | + echo '>' . esc_html__( $type, 'invoicing' ) . '</option>'; |
|
128 | 128 | } |
129 | 129 | ?> |
130 | 130 | </select> |
@@ -151,15 +151,15 @@ discard block |
||
151 | 151 | // Filter vat rule type |
152 | 152 | if ( isset( $_GET['discount_type'] ) && $_GET['discount_type'] !== '' ) { |
153 | 153 | $meta_query[] = array( |
154 | - 'key' => '_wpi_discount_type', |
|
155 | - 'value' => sanitize_key( urldecode( $_GET['discount_type'] ) ), |
|
156 | - 'compare' => '=', |
|
157 | - ); |
|
158 | - } |
|
154 | + 'key' => '_wpi_discount_type', |
|
155 | + 'value' => sanitize_key( urldecode( $_GET['discount_type'] ) ), |
|
156 | + 'compare' => '=', |
|
157 | + ); |
|
158 | + } |
|
159 | 159 | |
160 | 160 | if ( ! empty( $meta_query ) ) { |
161 | 161 | $vars['meta_query'] = $meta_query; |
162 | - } |
|
162 | + } |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | return $vars; |
@@ -24,14 +24,14 @@ discard block |
||
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
27 | - * Highlights sub menus. |
|
28 | - */ |
|
29 | - public function set_admin_menu_class() { |
|
30 | - global $current_screen, $parent_file, $submenu_file; |
|
27 | + * Highlights sub menus. |
|
28 | + */ |
|
29 | + public function set_admin_menu_class() { |
|
30 | + global $current_screen, $parent_file, $submenu_file; |
|
31 | 31 | |
32 | 32 | if ( ! empty( $current_screen->id ) && in_array( $current_screen->id, array( 'wpi_discount', 'wpi_payment_form', 'wpi_invoice' ) ) ) { |
33 | - $parent_file = 'wpinv'; |
|
34 | - $submenu_file = 'edit.php?post_type=' . $current_screen->id; |
|
33 | + $parent_file = 'wpinv'; |
|
34 | + $submenu_file = 'edit.php?post_type=' . $current_screen->id; |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | } |
@@ -165,8 +165,8 @@ discard block |
||
165 | 165 | foreach ( wpinv_get_settings_tabs() as $tab_id => $tab_name ) { |
166 | 166 | $tab_url = add_query_arg( |
167 | 167 | array( |
168 | - 'settings-updated' => false, |
|
169 | - 'tab' => $tab_id, |
|
168 | + 'settings-updated' => false, |
|
169 | + 'tab' => $tab_id, |
|
170 | 170 | ), |
171 | 171 | 'admin.php?page=wpinv-settings' |
172 | 172 | ); |
@@ -193,9 +193,9 @@ discard block |
||
193 | 193 | $number++; |
194 | 194 | $tab_url = add_query_arg( |
195 | 195 | array( |
196 | - 'settings-updated' => false, |
|
197 | - 'tab' => $active_tab, |
|
198 | - 'section' => $section_id, |
|
196 | + 'settings-updated' => false, |
|
197 | + 'tab' => $active_tab, |
|
198 | + 'section' => $section_id, |
|
199 | 199 | ), |
200 | 200 | admin_url( 'admin.php?page=wpinv-settings' ) |
201 | 201 | ); |