@@ -20,402 +20,402 @@ 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 | - |
|
69 | - // Save default tax rates. |
|
70 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Upgrade to 0.0.5 |
|
75 | - * |
|
76 | - */ |
|
77 | - public function upgrade_from_004() { |
|
78 | - global $wpdb; |
|
79 | - |
|
80 | - // Invoices. |
|
81 | - $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' )" ); |
|
82 | - if ( ! empty( $results ) ) { |
|
83 | - $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' )" ); |
|
84 | - |
|
85 | - // Clean post cache |
|
86 | - foreach ( $results as $row ) { |
|
87 | - clean_post_cache( $row->ID ); |
|
88 | - } |
|
89 | - } |
|
90 | - |
|
91 | - // Item meta key changes |
|
92 | - $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' )"; |
|
93 | - $results = $wpdb->get_results( $query ); |
|
94 | - |
|
95 | - if ( ! empty( $results ) ) { |
|
96 | - $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
97 | - $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
98 | - $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
99 | - |
|
100 | - foreach ( $results as $row ) { |
|
101 | - clean_post_cache( $row->post_id ); |
|
102 | - } |
|
103 | - } |
|
104 | - |
|
105 | - $this->upgrade_from_118(); |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Upgrade to version 2.0.0. |
|
110 | - * |
|
111 | - */ |
|
112 | - public function upgrade_from_118() { |
|
113 | - $this->migrate_old_invoices(); |
|
114 | - $this->upgrade_from_279(); |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * Upgrade to version 2.0.0. |
|
119 | - * |
|
120 | - */ |
|
121 | - public function upgrade_from_279() { |
|
122 | - $this->migrate_old_customers(); |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * Give administrators the capability to manage GetPaid. |
|
127 | - * |
|
128 | - */ |
|
129 | - public function add_capabilities() { |
|
130 | - $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' ); |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Retreives GetPaid pages. |
|
135 | - * |
|
136 | - */ |
|
137 | - public static function get_pages() { |
|
138 | - |
|
139 | - return apply_filters( |
|
140 | - 'wpinv_create_pages', |
|
141 | - array( |
|
142 | - |
|
143 | - // Checkout page. |
|
144 | - 'checkout_page' => array( |
|
145 | - 'name' => _x( 'gp-checkout', 'Page slug', 'invoicing' ), |
|
146 | - 'title' => _x( 'Checkout', 'Page title', 'invoicing' ), |
|
147 | - 'content' => ' |
|
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 | + |
|
69 | + // Save default tax rates. |
|
70 | + update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Upgrade to 0.0.5 |
|
75 | + * |
|
76 | + */ |
|
77 | + public function upgrade_from_004() { |
|
78 | + global $wpdb; |
|
79 | + |
|
80 | + // Invoices. |
|
81 | + $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' )" ); |
|
82 | + if ( ! empty( $results ) ) { |
|
83 | + $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' )" ); |
|
84 | + |
|
85 | + // Clean post cache |
|
86 | + foreach ( $results as $row ) { |
|
87 | + clean_post_cache( $row->ID ); |
|
88 | + } |
|
89 | + } |
|
90 | + |
|
91 | + // Item meta key changes |
|
92 | + $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' )"; |
|
93 | + $results = $wpdb->get_results( $query ); |
|
94 | + |
|
95 | + if ( ! empty( $results ) ) { |
|
96 | + $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
97 | + $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
98 | + $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
99 | + |
|
100 | + foreach ( $results as $row ) { |
|
101 | + clean_post_cache( $row->post_id ); |
|
102 | + } |
|
103 | + } |
|
104 | + |
|
105 | + $this->upgrade_from_118(); |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Upgrade to version 2.0.0. |
|
110 | + * |
|
111 | + */ |
|
112 | + public function upgrade_from_118() { |
|
113 | + $this->migrate_old_invoices(); |
|
114 | + $this->upgrade_from_279(); |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * Upgrade to version 2.0.0. |
|
119 | + * |
|
120 | + */ |
|
121 | + public function upgrade_from_279() { |
|
122 | + $this->migrate_old_customers(); |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * Give administrators the capability to manage GetPaid. |
|
127 | + * |
|
128 | + */ |
|
129 | + public function add_capabilities() { |
|
130 | + $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' ); |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Retreives GetPaid pages. |
|
135 | + * |
|
136 | + */ |
|
137 | + public static function get_pages() { |
|
138 | + |
|
139 | + return apply_filters( |
|
140 | + 'wpinv_create_pages', |
|
141 | + array( |
|
142 | + |
|
143 | + // Checkout page. |
|
144 | + 'checkout_page' => array( |
|
145 | + 'name' => _x( 'gp-checkout', 'Page slug', 'invoicing' ), |
|
146 | + 'title' => _x( 'Checkout', 'Page title', 'invoicing' ), |
|
147 | + 'content' => ' |
|
148 | 148 | <!-- wp:shortcode --> |
149 | 149 | [wpinv_checkout] |
150 | 150 | <!-- /wp:shortcode --> |
151 | 151 | ', |
152 | - 'parent' => '', |
|
153 | - ), |
|
154 | - |
|
155 | - // Invoice history page. |
|
156 | - 'invoice_history_page' => array( |
|
157 | - 'name' => _x( 'gp-invoices', 'Page slug', 'invoicing' ), |
|
158 | - 'title' => _x( 'My Invoices', 'Page title', 'invoicing' ), |
|
159 | - 'content' => ' |
|
152 | + 'parent' => '', |
|
153 | + ), |
|
154 | + |
|
155 | + // Invoice history page. |
|
156 | + 'invoice_history_page' => array( |
|
157 | + 'name' => _x( 'gp-invoices', 'Page slug', 'invoicing' ), |
|
158 | + 'title' => _x( 'My Invoices', 'Page title', 'invoicing' ), |
|
159 | + 'content' => ' |
|
160 | 160 | <!-- wp:shortcode --> |
161 | 161 | [wpinv_history] |
162 | 162 | <!-- /wp:shortcode --> |
163 | 163 | ', |
164 | - 'parent' => '', |
|
165 | - ), |
|
166 | - |
|
167 | - // Success page content. |
|
168 | - 'success_page' => array( |
|
169 | - 'name' => _x( 'gp-receipt', 'Page slug', 'invoicing' ), |
|
170 | - 'title' => _x( 'Payment Confirmation', 'Page title', 'invoicing' ), |
|
171 | - 'content' => ' |
|
164 | + 'parent' => '', |
|
165 | + ), |
|
166 | + |
|
167 | + // Success page content. |
|
168 | + 'success_page' => array( |
|
169 | + 'name' => _x( 'gp-receipt', 'Page slug', 'invoicing' ), |
|
170 | + 'title' => _x( 'Payment Confirmation', 'Page title', 'invoicing' ), |
|
171 | + 'content' => ' |
|
172 | 172 | <!-- wp:shortcode --> |
173 | 173 | [wpinv_receipt] |
174 | 174 | <!-- /wp:shortcode --> |
175 | 175 | ', |
176 | - 'parent' => 'gp-checkout', |
|
177 | - ), |
|
178 | - |
|
179 | - // Failure page content. |
|
180 | - 'failure_page' => array( |
|
181 | - 'name' => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ), |
|
182 | - 'title' => _x( 'Transaction Failed', 'Page title', 'invoicing' ), |
|
183 | - 'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ), |
|
184 | - 'parent' => 'gp-checkout', |
|
185 | - ), |
|
186 | - |
|
187 | - // Subscriptions history page. |
|
188 | - 'invoice_subscription_page' => array( |
|
189 | - 'name' => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ), |
|
190 | - 'title' => _x( 'My Subscriptions', 'Page title', 'invoicing' ), |
|
191 | - 'content' => ' |
|
176 | + 'parent' => 'gp-checkout', |
|
177 | + ), |
|
178 | + |
|
179 | + // Failure page content. |
|
180 | + 'failure_page' => array( |
|
181 | + 'name' => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ), |
|
182 | + 'title' => _x( 'Transaction Failed', 'Page title', 'invoicing' ), |
|
183 | + 'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ), |
|
184 | + 'parent' => 'gp-checkout', |
|
185 | + ), |
|
186 | + |
|
187 | + // Subscriptions history page. |
|
188 | + 'invoice_subscription_page' => array( |
|
189 | + 'name' => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ), |
|
190 | + 'title' => _x( 'My Subscriptions', 'Page title', 'invoicing' ), |
|
191 | + 'content' => ' |
|
192 | 192 | <!-- wp:shortcode --> |
193 | 193 | [wpinv_subscriptions] |
194 | 194 | <!-- /wp:shortcode --> |
195 | 195 | ', |
196 | - 'parent' => '', |
|
197 | - ), |
|
198 | - |
|
199 | - ) |
|
200 | - ); |
|
201 | - |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Re-create GetPaid pages. |
|
206 | - * |
|
207 | - */ |
|
208 | - public function create_pages() { |
|
209 | - |
|
210 | - foreach ( self::get_pages() as $key => $page ) { |
|
211 | - wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] ); |
|
212 | - } |
|
213 | - |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * Migrates old invoices to new invoices. |
|
218 | - * |
|
219 | - */ |
|
220 | - public function migrate_old_invoices() { |
|
221 | - global $wpdb; |
|
222 | - |
|
223 | - $invoices_table = $wpdb->prefix . 'getpaid_invoices'; |
|
224 | - $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
225 | - $migrated = $wpdb->get_col( "SELECT post_id FROM $invoices_table" ); |
|
226 | - $invoices = array_unique( |
|
227 | - get_posts( |
|
228 | - array( |
|
229 | - 'post_type' => array( 'wpi_invoice', 'wpi_quote' ), |
|
230 | - 'posts_per_page' => -1, |
|
231 | - 'fields' => 'ids', |
|
232 | - 'post_status' => array_keys( get_post_stati() ), |
|
233 | - 'exclude' => (array) $migrated, |
|
234 | - ) |
|
235 | - ) |
|
236 | - ); |
|
237 | - |
|
238 | - // Abort if we do not have any invoices. |
|
239 | - if ( empty( $invoices ) ) { |
|
240 | - return; |
|
241 | - } |
|
242 | - |
|
243 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php'; |
|
244 | - |
|
245 | - $invoice_rows = array(); |
|
246 | - foreach ( $invoices as $invoice ) { |
|
247 | - |
|
248 | - $invoice = new WPInv_Legacy_Invoice( $invoice ); |
|
249 | - |
|
250 | - if ( empty( $invoice->ID ) ) { |
|
251 | - return; |
|
252 | - } |
|
253 | - |
|
254 | - $fields = array( |
|
255 | - 'post_id' => $invoice->ID, |
|
256 | - 'number' => $invoice->get_number(), |
|
257 | - 'key' => $invoice->get_key(), |
|
258 | - 'type' => str_replace( 'wpi_', '', $invoice->post_type ), |
|
259 | - 'mode' => $invoice->mode, |
|
260 | - 'user_ip' => $invoice->get_ip(), |
|
261 | - 'first_name' => $invoice->get_first_name(), |
|
262 | - 'last_name' => $invoice->get_last_name(), |
|
263 | - 'address' => $invoice->get_address(), |
|
264 | - 'city' => $invoice->city, |
|
265 | - 'state' => $invoice->state, |
|
266 | - 'country' => $invoice->country, |
|
267 | - 'zip' => $invoice->zip, |
|
268 | - 'adddress_confirmed' => (int) $invoice->adddress_confirmed, |
|
269 | - 'gateway' => $invoice->get_gateway(), |
|
270 | - 'transaction_id' => $invoice->get_transaction_id(), |
|
271 | - 'currency' => $invoice->get_currency(), |
|
272 | - 'subtotal' => $invoice->get_subtotal(), |
|
273 | - 'tax' => $invoice->get_tax(), |
|
274 | - 'fees_total' => $invoice->get_fees_total(), |
|
275 | - 'total' => $invoice->get_total(), |
|
276 | - 'discount' => $invoice->get_discount(), |
|
277 | - 'discount_code' => $invoice->get_discount_code(), |
|
278 | - 'disable_taxes' => $invoice->disable_taxes, |
|
279 | - 'due_date' => $invoice->get_due_date(), |
|
280 | - 'completed_date' => $invoice->get_completed_date(), |
|
281 | - 'company' => $invoice->company, |
|
282 | - 'vat_number' => $invoice->vat_number, |
|
283 | - 'vat_rate' => $invoice->vat_rate, |
|
284 | - 'custom_meta' => $invoice->payment_meta, |
|
285 | - ); |
|
286 | - |
|
287 | - foreach ( $fields as $key => $val ) { |
|
288 | - if ( is_null( $val ) ) { |
|
289 | - $val = ''; |
|
290 | - } |
|
291 | - $val = maybe_serialize( $val ); |
|
292 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
293 | - } |
|
294 | - |
|
295 | - $fields = implode( ', ', $fields ); |
|
296 | - $invoice_rows[] = "($fields)"; |
|
297 | - |
|
298 | - $item_rows = array(); |
|
299 | - $item_columns = array(); |
|
300 | - foreach ( $invoice->get_cart_details() as $details ) { |
|
301 | - $fields = array( |
|
302 | - 'post_id' => $invoice->ID, |
|
303 | - 'item_id' => $details['id'], |
|
304 | - 'item_name' => $details['name'], |
|
305 | - 'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'], |
|
306 | - 'vat_rate' => $details['vat_rate'], |
|
307 | - 'vat_class' => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'], |
|
308 | - 'tax' => $details['tax'], |
|
309 | - 'item_price' => $details['item_price'], |
|
310 | - 'custom_price' => $details['custom_price'], |
|
311 | - 'quantity' => $details['quantity'], |
|
312 | - 'discount' => $details['discount'], |
|
313 | - 'subtotal' => $details['subtotal'], |
|
314 | - 'price' => $details['price'], |
|
315 | - 'meta' => $details['meta'], |
|
316 | - 'fees' => $details['fees'], |
|
317 | - ); |
|
318 | - |
|
319 | - $item_columns = array_keys( $fields ); |
|
320 | - |
|
321 | - foreach ( $fields as $key => $val ) { |
|
322 | - if ( is_null( $val ) ) { |
|
323 | - $val = ''; |
|
324 | - } |
|
325 | - $val = maybe_serialize( $val ); |
|
326 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
327 | - } |
|
328 | - |
|
329 | - $fields = implode( ', ', $fields ); |
|
330 | - $item_rows[] = "($fields)"; |
|
331 | - } |
|
332 | - |
|
333 | - $item_rows = implode( ', ', $item_rows ); |
|
334 | - $item_columns = implode( ', ', $item_columns ); |
|
335 | - $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" ); |
|
336 | - } |
|
337 | - |
|
338 | - if ( empty( $invoice_rows ) ) { |
|
339 | - return; |
|
340 | - } |
|
341 | - |
|
342 | - $invoice_rows = implode( ', ', $invoice_rows ); |
|
343 | - $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" ); |
|
344 | - |
|
345 | - } |
|
346 | - |
|
347 | - /** |
|
348 | - * Migrates old customers to new table. |
|
349 | - * |
|
350 | - */ |
|
351 | - public function migrate_old_customers() { |
|
352 | - global $wpdb; |
|
353 | - |
|
354 | - // Fetch post_id from $wpdb->prefix . 'getpaid_invoices' where customer_id = 0 or null. |
|
355 | - $invoice_ids = $wpdb->get_col( "SELECT post_id FROM {$wpdb->prefix}getpaid_invoices WHERE customer_id = 0 OR customer_id IS NULL" ); |
|
356 | - |
|
357 | - foreach ( $invoice_ids as $invoice_id ) { |
|
358 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
359 | - |
|
360 | - if ( empty( $invoice ) ) { |
|
361 | - continue; |
|
362 | - } |
|
363 | - |
|
364 | - // Fetch customer from the user ID. |
|
365 | - $user_id = $invoice->get_user_id(); |
|
366 | - |
|
367 | - if ( empty( $user_id ) ) { |
|
368 | - continue; |
|
369 | - } |
|
370 | - |
|
371 | - $customer = getpaid_get_customer_by_user_id( $user_id ); |
|
372 | - |
|
373 | - // Create if not exists. |
|
374 | - if ( empty( $customer ) ) { |
|
375 | - $customer = new GetPaid_Customer( 0 ); |
|
376 | - $customer->clone_user( $user_id ); |
|
377 | - $customer->save(); |
|
378 | - } |
|
379 | - |
|
380 | - $invoice->set_customer_id( $customer->get_id() ); |
|
381 | - $invoice->save(); |
|
382 | - } |
|
383 | - |
|
384 | - } |
|
385 | - |
|
386 | - /** |
|
387 | - * Migrates old invoices to new invoices. |
|
388 | - * |
|
389 | - */ |
|
390 | - public static function rename_gateways_label() { |
|
391 | - global $wpdb; |
|
392 | - |
|
393 | - foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) { |
|
394 | - |
|
395 | - $wpdb->update( |
|
396 | - $wpdb->prefix . 'getpaid_invoices', |
|
397 | - array( 'gateway' => $gateway ), |
|
398 | - array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ), |
|
399 | - '%s', |
|
400 | - '%s' |
|
401 | - ); |
|
402 | - |
|
403 | - } |
|
404 | - } |
|
405 | - |
|
406 | - /** |
|
407 | - * Returns the DB schema. |
|
408 | - * |
|
409 | - */ |
|
410 | - public static function get_db_schema() { |
|
411 | - global $wpdb; |
|
412 | - |
|
413 | - require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
414 | - |
|
415 | - $charset_collate = $wpdb->get_charset_collate(); |
|
196 | + 'parent' => '', |
|
197 | + ), |
|
198 | + |
|
199 | + ) |
|
200 | + ); |
|
201 | + |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Re-create GetPaid pages. |
|
206 | + * |
|
207 | + */ |
|
208 | + public function create_pages() { |
|
209 | + |
|
210 | + foreach ( self::get_pages() as $key => $page ) { |
|
211 | + wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] ); |
|
212 | + } |
|
213 | + |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * Migrates old invoices to new invoices. |
|
218 | + * |
|
219 | + */ |
|
220 | + public function migrate_old_invoices() { |
|
221 | + global $wpdb; |
|
222 | + |
|
223 | + $invoices_table = $wpdb->prefix . 'getpaid_invoices'; |
|
224 | + $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
225 | + $migrated = $wpdb->get_col( "SELECT post_id FROM $invoices_table" ); |
|
226 | + $invoices = array_unique( |
|
227 | + get_posts( |
|
228 | + array( |
|
229 | + 'post_type' => array( 'wpi_invoice', 'wpi_quote' ), |
|
230 | + 'posts_per_page' => -1, |
|
231 | + 'fields' => 'ids', |
|
232 | + 'post_status' => array_keys( get_post_stati() ), |
|
233 | + 'exclude' => (array) $migrated, |
|
234 | + ) |
|
235 | + ) |
|
236 | + ); |
|
237 | + |
|
238 | + // Abort if we do not have any invoices. |
|
239 | + if ( empty( $invoices ) ) { |
|
240 | + return; |
|
241 | + } |
|
242 | + |
|
243 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php'; |
|
244 | + |
|
245 | + $invoice_rows = array(); |
|
246 | + foreach ( $invoices as $invoice ) { |
|
247 | + |
|
248 | + $invoice = new WPInv_Legacy_Invoice( $invoice ); |
|
249 | + |
|
250 | + if ( empty( $invoice->ID ) ) { |
|
251 | + return; |
|
252 | + } |
|
253 | + |
|
254 | + $fields = array( |
|
255 | + 'post_id' => $invoice->ID, |
|
256 | + 'number' => $invoice->get_number(), |
|
257 | + 'key' => $invoice->get_key(), |
|
258 | + 'type' => str_replace( 'wpi_', '', $invoice->post_type ), |
|
259 | + 'mode' => $invoice->mode, |
|
260 | + 'user_ip' => $invoice->get_ip(), |
|
261 | + 'first_name' => $invoice->get_first_name(), |
|
262 | + 'last_name' => $invoice->get_last_name(), |
|
263 | + 'address' => $invoice->get_address(), |
|
264 | + 'city' => $invoice->city, |
|
265 | + 'state' => $invoice->state, |
|
266 | + 'country' => $invoice->country, |
|
267 | + 'zip' => $invoice->zip, |
|
268 | + 'adddress_confirmed' => (int) $invoice->adddress_confirmed, |
|
269 | + 'gateway' => $invoice->get_gateway(), |
|
270 | + 'transaction_id' => $invoice->get_transaction_id(), |
|
271 | + 'currency' => $invoice->get_currency(), |
|
272 | + 'subtotal' => $invoice->get_subtotal(), |
|
273 | + 'tax' => $invoice->get_tax(), |
|
274 | + 'fees_total' => $invoice->get_fees_total(), |
|
275 | + 'total' => $invoice->get_total(), |
|
276 | + 'discount' => $invoice->get_discount(), |
|
277 | + 'discount_code' => $invoice->get_discount_code(), |
|
278 | + 'disable_taxes' => $invoice->disable_taxes, |
|
279 | + 'due_date' => $invoice->get_due_date(), |
|
280 | + 'completed_date' => $invoice->get_completed_date(), |
|
281 | + 'company' => $invoice->company, |
|
282 | + 'vat_number' => $invoice->vat_number, |
|
283 | + 'vat_rate' => $invoice->vat_rate, |
|
284 | + 'custom_meta' => $invoice->payment_meta, |
|
285 | + ); |
|
286 | + |
|
287 | + foreach ( $fields as $key => $val ) { |
|
288 | + if ( is_null( $val ) ) { |
|
289 | + $val = ''; |
|
290 | + } |
|
291 | + $val = maybe_serialize( $val ); |
|
292 | + $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
293 | + } |
|
294 | + |
|
295 | + $fields = implode( ', ', $fields ); |
|
296 | + $invoice_rows[] = "($fields)"; |
|
297 | + |
|
298 | + $item_rows = array(); |
|
299 | + $item_columns = array(); |
|
300 | + foreach ( $invoice->get_cart_details() as $details ) { |
|
301 | + $fields = array( |
|
302 | + 'post_id' => $invoice->ID, |
|
303 | + 'item_id' => $details['id'], |
|
304 | + 'item_name' => $details['name'], |
|
305 | + 'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'], |
|
306 | + 'vat_rate' => $details['vat_rate'], |
|
307 | + 'vat_class' => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'], |
|
308 | + 'tax' => $details['tax'], |
|
309 | + 'item_price' => $details['item_price'], |
|
310 | + 'custom_price' => $details['custom_price'], |
|
311 | + 'quantity' => $details['quantity'], |
|
312 | + 'discount' => $details['discount'], |
|
313 | + 'subtotal' => $details['subtotal'], |
|
314 | + 'price' => $details['price'], |
|
315 | + 'meta' => $details['meta'], |
|
316 | + 'fees' => $details['fees'], |
|
317 | + ); |
|
318 | + |
|
319 | + $item_columns = array_keys( $fields ); |
|
320 | + |
|
321 | + foreach ( $fields as $key => $val ) { |
|
322 | + if ( is_null( $val ) ) { |
|
323 | + $val = ''; |
|
324 | + } |
|
325 | + $val = maybe_serialize( $val ); |
|
326 | + $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
327 | + } |
|
328 | + |
|
329 | + $fields = implode( ', ', $fields ); |
|
330 | + $item_rows[] = "($fields)"; |
|
331 | + } |
|
332 | + |
|
333 | + $item_rows = implode( ', ', $item_rows ); |
|
334 | + $item_columns = implode( ', ', $item_columns ); |
|
335 | + $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" ); |
|
336 | + } |
|
337 | + |
|
338 | + if ( empty( $invoice_rows ) ) { |
|
339 | + return; |
|
340 | + } |
|
341 | + |
|
342 | + $invoice_rows = implode( ', ', $invoice_rows ); |
|
343 | + $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" ); |
|
344 | + |
|
345 | + } |
|
346 | + |
|
347 | + /** |
|
348 | + * Migrates old customers to new table. |
|
349 | + * |
|
350 | + */ |
|
351 | + public function migrate_old_customers() { |
|
352 | + global $wpdb; |
|
353 | + |
|
354 | + // Fetch post_id from $wpdb->prefix . 'getpaid_invoices' where customer_id = 0 or null. |
|
355 | + $invoice_ids = $wpdb->get_col( "SELECT post_id FROM {$wpdb->prefix}getpaid_invoices WHERE customer_id = 0 OR customer_id IS NULL" ); |
|
356 | + |
|
357 | + foreach ( $invoice_ids as $invoice_id ) { |
|
358 | + $invoice = wpinv_get_invoice( $invoice_id ); |
|
359 | + |
|
360 | + if ( empty( $invoice ) ) { |
|
361 | + continue; |
|
362 | + } |
|
363 | + |
|
364 | + // Fetch customer from the user ID. |
|
365 | + $user_id = $invoice->get_user_id(); |
|
366 | + |
|
367 | + if ( empty( $user_id ) ) { |
|
368 | + continue; |
|
369 | + } |
|
370 | + |
|
371 | + $customer = getpaid_get_customer_by_user_id( $user_id ); |
|
372 | + |
|
373 | + // Create if not exists. |
|
374 | + if ( empty( $customer ) ) { |
|
375 | + $customer = new GetPaid_Customer( 0 ); |
|
376 | + $customer->clone_user( $user_id ); |
|
377 | + $customer->save(); |
|
378 | + } |
|
379 | + |
|
380 | + $invoice->set_customer_id( $customer->get_id() ); |
|
381 | + $invoice->save(); |
|
382 | + } |
|
383 | + |
|
384 | + } |
|
385 | + |
|
386 | + /** |
|
387 | + * Migrates old invoices to new invoices. |
|
388 | + * |
|
389 | + */ |
|
390 | + public static function rename_gateways_label() { |
|
391 | + global $wpdb; |
|
392 | + |
|
393 | + foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) { |
|
394 | + |
|
395 | + $wpdb->update( |
|
396 | + $wpdb->prefix . 'getpaid_invoices', |
|
397 | + array( 'gateway' => $gateway ), |
|
398 | + array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ), |
|
399 | + '%s', |
|
400 | + '%s' |
|
401 | + ); |
|
402 | + |
|
403 | + } |
|
404 | + } |
|
405 | + |
|
406 | + /** |
|
407 | + * Returns the DB schema. |
|
408 | + * |
|
409 | + */ |
|
410 | + public static function get_db_schema() { |
|
411 | + global $wpdb; |
|
412 | + |
|
413 | + require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
414 | + |
|
415 | + $charset_collate = $wpdb->get_charset_collate(); |
|
416 | 416 | |
417 | - // Subscriptions. |
|
418 | - $schema = "CREATE TABLE {$wpdb->prefix}wpinv_subscriptions ( |
|
417 | + // Subscriptions. |
|
418 | + $schema = "CREATE TABLE {$wpdb->prefix}wpinv_subscriptions ( |
|
419 | 419 | id bigint(20) unsigned NOT NULL auto_increment, |
420 | 420 | customer_id bigint(20) NOT NULL, |
421 | 421 | frequency int(11) NOT NULL DEFAULT '1', |
@@ -438,8 +438,8 @@ discard block |
||
438 | 438 | KEY customer_and_status (customer_id, status) |
439 | 439 | ) $charset_collate;"; |
440 | 440 | |
441 | - // Invoices. |
|
442 | - $schema .= "CREATE TABLE {$wpdb->prefix}getpaid_invoices ( |
|
441 | + // Invoices. |
|
442 | + $schema .= "CREATE TABLE {$wpdb->prefix}getpaid_invoices ( |
|
443 | 443 | post_id BIGINT(20) NOT NULL, |
444 | 444 | customer_id BIGINT(20) NOT NULL DEFAULT 0, |
445 | 445 | `number` VARCHAR(100), |
@@ -476,8 +476,8 @@ discard block |
||
476 | 476 | KEY invoice_key (invoice_key) |
477 | 477 | ) $charset_collate;"; |
478 | 478 | |
479 | - // Invoice items. |
|
480 | - $schema .= "CREATE TABLE {$wpdb->prefix}getpaid_invoice_items ( |
|
479 | + // Invoice items. |
|
480 | + $schema .= "CREATE TABLE {$wpdb->prefix}getpaid_invoice_items ( |
|
481 | 481 | ID BIGINT(20) NOT NULL AUTO_INCREMENT, |
482 | 482 | post_id BIGINT(20) NOT NULL, |
483 | 483 | item_id BIGINT(20) NOT NULL, |
@@ -499,8 +499,8 @@ discard block |
||
499 | 499 | KEY post_id (post_id) |
500 | 500 | ) $charset_collate;"; |
501 | 501 | |
502 | - // Customers. |
|
503 | - $schema .= "CREATE TABLE {$wpdb->prefix}getpaid_customers ( |
|
502 | + // Customers. |
|
503 | + $schema .= "CREATE TABLE {$wpdb->prefix}getpaid_customers ( |
|
504 | 504 | id BIGINT(20) NOT NULL AUTO_INCREMENT, |
505 | 505 | user_id BIGINT(20) NOT NULL, |
506 | 506 | email VARCHAR(100) NOT NULL, |
@@ -510,38 +510,38 @@ discard block |
||
510 | 510 | purchase_count BIGINT(20) NOT NULL DEFAULT 0, |
511 | 511 | "; |
512 | 512 | |
513 | - // Add address fields. |
|
514 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
515 | - // Skip id, user_id and email. |
|
516 | - if ( in_array( $field, array( 'id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid' ), true ) ) { |
|
517 | - continue; |
|
518 | - } |
|
519 | - |
|
520 | - $field = sanitize_key( $field ); |
|
521 | - $length = 100; |
|
522 | - $default = ''; |
|
523 | - |
|
524 | - // Country. |
|
525 | - if ( 'country' === $field ) { |
|
526 | - $length = 2; |
|
527 | - $default = wpinv_get_default_country(); |
|
528 | - } |
|
529 | - |
|
530 | - // State. |
|
531 | - if ( 'state' === $field ) { |
|
532 | - $default = wpinv_get_default_state(); |
|
533 | - } |
|
534 | - |
|
535 | - // Phone, zip. |
|
536 | - if ( in_array( $field, array( 'phone', 'zip' ), true ) ) { |
|
537 | - $length = 20; |
|
538 | - } |
|
539 | - |
|
540 | - $schema .= "`$field` VARCHAR($length) NOT NULL DEFAULT '$default', |
|
513 | + // Add address fields. |
|
514 | + foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
515 | + // Skip id, user_id and email. |
|
516 | + if ( in_array( $field, array( 'id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid' ), true ) ) { |
|
517 | + continue; |
|
518 | + } |
|
519 | + |
|
520 | + $field = sanitize_key( $field ); |
|
521 | + $length = 100; |
|
522 | + $default = ''; |
|
523 | + |
|
524 | + // Country. |
|
525 | + if ( 'country' === $field ) { |
|
526 | + $length = 2; |
|
527 | + $default = wpinv_get_default_country(); |
|
528 | + } |
|
529 | + |
|
530 | + // State. |
|
531 | + if ( 'state' === $field ) { |
|
532 | + $default = wpinv_get_default_state(); |
|
533 | + } |
|
534 | + |
|
535 | + // Phone, zip. |
|
536 | + if ( in_array( $field, array( 'phone', 'zip' ), true ) ) { |
|
537 | + $length = 20; |
|
538 | + } |
|
539 | + |
|
540 | + $schema .= "`$field` VARCHAR($length) NOT NULL DEFAULT '$default', |
|
541 | 541 | "; |
542 | - } |
|
542 | + } |
|
543 | 543 | |
544 | - $schema .= "date_created DATETIME NOT NULL, |
|
544 | + $schema .= "date_created DATETIME NOT NULL, |
|
545 | 545 | date_modified DATETIME NOT NULL, |
546 | 546 | uuid VARCHAR(100) NOT NULL, |
547 | 547 | PRIMARY KEY (id), |
@@ -549,8 +549,8 @@ discard block |
||
549 | 549 | KEY email (email) |
550 | 550 | ) $charset_collate;"; |
551 | 551 | |
552 | - // Customer meta. |
|
553 | - $schema .= "CREATE TABLE {$wpdb->prefix}getpaid_customer_meta ( |
|
552 | + // Customer meta. |
|
553 | + $schema .= "CREATE TABLE {$wpdb->prefix}getpaid_customer_meta ( |
|
554 | 554 | meta_id BIGINT(20) NOT NULL AUTO_INCREMENT, |
555 | 555 | customer_id BIGINT(20) NOT NULL, |
556 | 556 | meta_key VARCHAR(255) NOT NULL, |
@@ -560,55 +560,55 @@ discard block |
||
560 | 560 | KEY meta_key (meta_key(191)) |
561 | 561 | ) $charset_collate;"; |
562 | 562 | |
563 | - return $schema; |
|
564 | - } |
|
565 | - |
|
566 | - /** |
|
567 | - * Checks if the db schema is up to date. |
|
568 | - * |
|
569 | - * @return bool |
|
570 | - */ |
|
571 | - public static function is_db_schema_up_to_date() { |
|
572 | - return md5( self::get_db_schema() ) === get_option( 'getpaid_db_schema' ); |
|
573 | - } |
|
574 | - |
|
575 | - /** |
|
576 | - * Set up the database tables which the plugin needs to function. |
|
577 | - */ |
|
578 | - public static function create_db_tables() { |
|
579 | - global $wpdb; |
|
580 | - |
|
581 | - $wpdb->hide_errors(); |
|
582 | - |
|
583 | - require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
584 | - |
|
585 | - $schema = self::get_db_schema(); |
|
586 | - |
|
587 | - // If invoices table exists, rename key to invoice_key. |
|
588 | - $invoices_table = "{$wpdb->prefix}getpaid_invoices"; |
|
589 | - |
|
590 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) === $invoices_table ) { |
|
591 | - $fields = $wpdb->get_results( "SHOW COLUMNS FROM {$wpdb->prefix}getpaid_invoices" ); |
|
592 | - |
|
593 | - foreach ( $fields as $field ) { |
|
594 | - if ( 'key' === $field->Field ) { |
|
595 | - $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoices CHANGE `key` `invoice_key` VARCHAR(100)" ); |
|
596 | - break; |
|
597 | - } |
|
598 | - } |
|
599 | - } |
|
600 | - |
|
601 | - dbDelta( $schema ); |
|
602 | - wp_cache_flush(); |
|
603 | - update_option( 'getpaid_db_schema', md5( self::get_db_schema() ) ); |
|
604 | - } |
|
605 | - |
|
606 | - /** |
|
607 | - * Creates tables if schema is not up to date. |
|
608 | - */ |
|
609 | - public static function maybe_create_db_tables() { |
|
610 | - if ( ! self::is_db_schema_up_to_date() ) { |
|
611 | - self::create_db_tables(); |
|
612 | - } |
|
613 | - } |
|
563 | + return $schema; |
|
564 | + } |
|
565 | + |
|
566 | + /** |
|
567 | + * Checks if the db schema is up to date. |
|
568 | + * |
|
569 | + * @return bool |
|
570 | + */ |
|
571 | + public static function is_db_schema_up_to_date() { |
|
572 | + return md5( self::get_db_schema() ) === get_option( 'getpaid_db_schema' ); |
|
573 | + } |
|
574 | + |
|
575 | + /** |
|
576 | + * Set up the database tables which the plugin needs to function. |
|
577 | + */ |
|
578 | + public static function create_db_tables() { |
|
579 | + global $wpdb; |
|
580 | + |
|
581 | + $wpdb->hide_errors(); |
|
582 | + |
|
583 | + require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
584 | + |
|
585 | + $schema = self::get_db_schema(); |
|
586 | + |
|
587 | + // If invoices table exists, rename key to invoice_key. |
|
588 | + $invoices_table = "{$wpdb->prefix}getpaid_invoices"; |
|
589 | + |
|
590 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) === $invoices_table ) { |
|
591 | + $fields = $wpdb->get_results( "SHOW COLUMNS FROM {$wpdb->prefix}getpaid_invoices" ); |
|
592 | + |
|
593 | + foreach ( $fields as $field ) { |
|
594 | + if ( 'key' === $field->Field ) { |
|
595 | + $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoices CHANGE `key` `invoice_key` VARCHAR(100)" ); |
|
596 | + break; |
|
597 | + } |
|
598 | + } |
|
599 | + } |
|
600 | + |
|
601 | + dbDelta( $schema ); |
|
602 | + wp_cache_flush(); |
|
603 | + update_option( 'getpaid_db_schema', md5( self::get_db_schema() ) ); |
|
604 | + } |
|
605 | + |
|
606 | + /** |
|
607 | + * Creates tables if schema is not up to date. |
|
608 | + */ |
|
609 | + public static function maybe_create_db_tables() { |
|
610 | + if ( ! self::is_db_schema_up_to_date() ) { |
|
611 | + self::create_db_tables(); |
|
612 | + } |
|
613 | + } |
|
614 | 614 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @since 2.0.2 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * The main installer/updater class. |
@@ -25,10 +25,10 @@ discard block |
||
25 | 25 | * |
26 | 26 | * @param string $upgrade_from The current invoicing version. |
27 | 27 | */ |
28 | - public function upgrade_db( $upgrade_from ) { |
|
28 | + public function upgrade_db($upgrade_from) { |
|
29 | 29 | |
30 | 30 | // Save the current invoicing version. |
31 | - update_option( 'wpinv_version', WPINV_VERSION ); |
|
31 | + update_option('wpinv_version', WPINV_VERSION); |
|
32 | 32 | |
33 | 33 | // Setup the invoice Custom Post Type. |
34 | 34 | GetPaid_Post_Types::register_post_types(); |
@@ -48,13 +48,13 @@ discard block |
||
48 | 48 | // Create any missing database tables. |
49 | 49 | $method = "upgrade_from_$upgrade_from"; |
50 | 50 | |
51 | - $installed = get_option( 'gepaid_installed_on' ); |
|
51 | + $installed = get_option('gepaid_installed_on'); |
|
52 | 52 | |
53 | - if ( empty( $installed ) ) { |
|
54 | - update_option( 'gepaid_installed_on', time() ); |
|
53 | + if (empty($installed)) { |
|
54 | + update_option('gepaid_installed_on', time()); |
|
55 | 55 | } |
56 | 56 | |
57 | - if ( method_exists( $this, $method ) ) { |
|
57 | + if (method_exists($this, $method)) { |
|
58 | 58 | $this->$method(); |
59 | 59 | } |
60 | 60 | |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | public function upgrade_from_0() { |
68 | 68 | |
69 | 69 | // Save default tax rates. |
70 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
70 | + update_option('wpinv_tax_rates', wpinv_get_data('tax-rates')); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
@@ -78,27 +78,27 @@ discard block |
||
78 | 78 | global $wpdb; |
79 | 79 | |
80 | 80 | // Invoices. |
81 | - $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' )" ); |
|
82 | - if ( ! empty( $results ) ) { |
|
83 | - $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' )" ); |
|
81 | + $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' )"); |
|
82 | + if (!empty($results)) { |
|
83 | + $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' )"); |
|
84 | 84 | |
85 | 85 | // Clean post cache |
86 | - foreach ( $results as $row ) { |
|
87 | - clean_post_cache( $row->ID ); |
|
86 | + foreach ($results as $row) { |
|
87 | + clean_post_cache($row->ID); |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 | |
91 | 91 | // Item meta key changes |
92 | 92 | $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' )"; |
93 | - $results = $wpdb->get_results( $query ); |
|
93 | + $results = $wpdb->get_results($query); |
|
94 | 94 | |
95 | - if ( ! empty( $results ) ) { |
|
96 | - $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
97 | - $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
98 | - $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
95 | + if (!empty($results)) { |
|
96 | + $wpdb->query('UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )"); |
|
97 | + $wpdb->query('UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'"); |
|
98 | + $wpdb->query('UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'"); |
|
99 | 99 | |
100 | - foreach ( $results as $row ) { |
|
101 | - clean_post_cache( $row->post_id ); |
|
100 | + foreach ($results as $row) { |
|
101 | + clean_post_cache($row->post_id); |
|
102 | 102 | } |
103 | 103 | } |
104 | 104 | |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | * |
128 | 128 | */ |
129 | 129 | public function add_capabilities() { |
130 | - $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' ); |
|
130 | + $GLOBALS['wp_roles']->add_cap('administrator', 'manage_invoicing'); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
@@ -142,8 +142,8 @@ discard block |
||
142 | 142 | |
143 | 143 | // Checkout page. |
144 | 144 | 'checkout_page' => array( |
145 | - 'name' => _x( 'gp-checkout', 'Page slug', 'invoicing' ), |
|
146 | - 'title' => _x( 'Checkout', 'Page title', 'invoicing' ), |
|
145 | + 'name' => _x('gp-checkout', 'Page slug', 'invoicing'), |
|
146 | + 'title' => _x('Checkout', 'Page title', 'invoicing'), |
|
147 | 147 | 'content' => ' |
148 | 148 | <!-- wp:shortcode --> |
149 | 149 | [wpinv_checkout] |
@@ -154,8 +154,8 @@ discard block |
||
154 | 154 | |
155 | 155 | // Invoice history page. |
156 | 156 | 'invoice_history_page' => array( |
157 | - 'name' => _x( 'gp-invoices', 'Page slug', 'invoicing' ), |
|
158 | - 'title' => _x( 'My Invoices', 'Page title', 'invoicing' ), |
|
157 | + 'name' => _x('gp-invoices', 'Page slug', 'invoicing'), |
|
158 | + 'title' => _x('My Invoices', 'Page title', 'invoicing'), |
|
159 | 159 | 'content' => ' |
160 | 160 | <!-- wp:shortcode --> |
161 | 161 | [wpinv_history] |
@@ -166,8 +166,8 @@ discard block |
||
166 | 166 | |
167 | 167 | // Success page content. |
168 | 168 | 'success_page' => array( |
169 | - 'name' => _x( 'gp-receipt', 'Page slug', 'invoicing' ), |
|
170 | - 'title' => _x( 'Payment Confirmation', 'Page title', 'invoicing' ), |
|
169 | + 'name' => _x('gp-receipt', 'Page slug', 'invoicing'), |
|
170 | + 'title' => _x('Payment Confirmation', 'Page title', 'invoicing'), |
|
171 | 171 | 'content' => ' |
172 | 172 | <!-- wp:shortcode --> |
173 | 173 | [wpinv_receipt] |
@@ -178,16 +178,16 @@ discard block |
||
178 | 178 | |
179 | 179 | // Failure page content. |
180 | 180 | 'failure_page' => array( |
181 | - 'name' => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ), |
|
182 | - 'title' => _x( 'Transaction Failed', 'Page title', 'invoicing' ), |
|
183 | - 'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ), |
|
181 | + 'name' => _x('gp-transaction-failed', 'Page slug', 'invoicing'), |
|
182 | + 'title' => _x('Transaction Failed', 'Page title', 'invoicing'), |
|
183 | + 'content' => __('Your transaction failed, please try again or contact site support.', 'invoicing'), |
|
184 | 184 | 'parent' => 'gp-checkout', |
185 | 185 | ), |
186 | 186 | |
187 | 187 | // Subscriptions history page. |
188 | 188 | 'invoice_subscription_page' => array( |
189 | - 'name' => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ), |
|
190 | - 'title' => _x( 'My Subscriptions', 'Page title', 'invoicing' ), |
|
189 | + 'name' => _x('gp-subscriptions', 'Page slug', 'invoicing'), |
|
190 | + 'title' => _x('My Subscriptions', 'Page title', 'invoicing'), |
|
191 | 191 | 'content' => ' |
192 | 192 | <!-- wp:shortcode --> |
193 | 193 | [wpinv_subscriptions] |
@@ -207,8 +207,8 @@ discard block |
||
207 | 207 | */ |
208 | 208 | public function create_pages() { |
209 | 209 | |
210 | - foreach ( self::get_pages() as $key => $page ) { |
|
211 | - wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] ); |
|
210 | + foreach (self::get_pages() as $key => $page) { |
|
211 | + wpinv_create_page(esc_sql($page['name']), $key, $page['title'], $page['content'], $page['parent']); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | } |
@@ -222,32 +222,32 @@ discard block |
||
222 | 222 | |
223 | 223 | $invoices_table = $wpdb->prefix . 'getpaid_invoices'; |
224 | 224 | $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items'; |
225 | - $migrated = $wpdb->get_col( "SELECT post_id FROM $invoices_table" ); |
|
225 | + $migrated = $wpdb->get_col("SELECT post_id FROM $invoices_table"); |
|
226 | 226 | $invoices = array_unique( |
227 | 227 | get_posts( |
228 | 228 | array( |
229 | - 'post_type' => array( 'wpi_invoice', 'wpi_quote' ), |
|
229 | + 'post_type' => array('wpi_invoice', 'wpi_quote'), |
|
230 | 230 | 'posts_per_page' => -1, |
231 | 231 | 'fields' => 'ids', |
232 | - 'post_status' => array_keys( get_post_stati() ), |
|
232 | + 'post_status' => array_keys(get_post_stati()), |
|
233 | 233 | 'exclude' => (array) $migrated, |
234 | 234 | ) |
235 | 235 | ) |
236 | 236 | ); |
237 | 237 | |
238 | 238 | // Abort if we do not have any invoices. |
239 | - if ( empty( $invoices ) ) { |
|
239 | + if (empty($invoices)) { |
|
240 | 240 | return; |
241 | 241 | } |
242 | 242 | |
243 | 243 | require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php'; |
244 | 244 | |
245 | 245 | $invoice_rows = array(); |
246 | - foreach ( $invoices as $invoice ) { |
|
246 | + foreach ($invoices as $invoice) { |
|
247 | 247 | |
248 | - $invoice = new WPInv_Legacy_Invoice( $invoice ); |
|
248 | + $invoice = new WPInv_Legacy_Invoice($invoice); |
|
249 | 249 | |
250 | - if ( empty( $invoice->ID ) ) { |
|
250 | + if (empty($invoice->ID)) { |
|
251 | 251 | return; |
252 | 252 | } |
253 | 253 | |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | 'post_id' => $invoice->ID, |
256 | 256 | 'number' => $invoice->get_number(), |
257 | 257 | 'key' => $invoice->get_key(), |
258 | - 'type' => str_replace( 'wpi_', '', $invoice->post_type ), |
|
258 | + 'type' => str_replace('wpi_', '', $invoice->post_type), |
|
259 | 259 | 'mode' => $invoice->mode, |
260 | 260 | 'user_ip' => $invoice->get_ip(), |
261 | 261 | 'first_name' => $invoice->get_first_name(), |
@@ -284,27 +284,27 @@ discard block |
||
284 | 284 | 'custom_meta' => $invoice->payment_meta, |
285 | 285 | ); |
286 | 286 | |
287 | - foreach ( $fields as $key => $val ) { |
|
288 | - if ( is_null( $val ) ) { |
|
287 | + foreach ($fields as $key => $val) { |
|
288 | + if (is_null($val)) { |
|
289 | 289 | $val = ''; |
290 | 290 | } |
291 | - $val = maybe_serialize( $val ); |
|
292 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
291 | + $val = maybe_serialize($val); |
|
292 | + $fields[$key] = $wpdb->prepare('%s', $val); |
|
293 | 293 | } |
294 | 294 | |
295 | - $fields = implode( ', ', $fields ); |
|
295 | + $fields = implode(', ', $fields); |
|
296 | 296 | $invoice_rows[] = "($fields)"; |
297 | 297 | |
298 | 298 | $item_rows = array(); |
299 | 299 | $item_columns = array(); |
300 | - foreach ( $invoice->get_cart_details() as $details ) { |
|
300 | + foreach ($invoice->get_cart_details() as $details) { |
|
301 | 301 | $fields = array( |
302 | 302 | 'post_id' => $invoice->ID, |
303 | 303 | 'item_id' => $details['id'], |
304 | 304 | 'item_name' => $details['name'], |
305 | - 'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'], |
|
305 | + 'item_description' => empty($details['meta']['description']) ? '' : $details['meta']['description'], |
|
306 | 306 | 'vat_rate' => $details['vat_rate'], |
307 | - 'vat_class' => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'], |
|
307 | + 'vat_class' => empty($details['vat_class']) ? '_standard' : $details['vat_class'], |
|
308 | 308 | 'tax' => $details['tax'], |
309 | 309 | 'item_price' => $details['item_price'], |
310 | 310 | 'custom_price' => $details['custom_price'], |
@@ -316,31 +316,31 @@ discard block |
||
316 | 316 | 'fees' => $details['fees'], |
317 | 317 | ); |
318 | 318 | |
319 | - $item_columns = array_keys( $fields ); |
|
319 | + $item_columns = array_keys($fields); |
|
320 | 320 | |
321 | - foreach ( $fields as $key => $val ) { |
|
322 | - if ( is_null( $val ) ) { |
|
321 | + foreach ($fields as $key => $val) { |
|
322 | + if (is_null($val)) { |
|
323 | 323 | $val = ''; |
324 | 324 | } |
325 | - $val = maybe_serialize( $val ); |
|
326 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
325 | + $val = maybe_serialize($val); |
|
326 | + $fields[$key] = $wpdb->prepare('%s', $val); |
|
327 | 327 | } |
328 | 328 | |
329 | - $fields = implode( ', ', $fields ); |
|
329 | + $fields = implode(', ', $fields); |
|
330 | 330 | $item_rows[] = "($fields)"; |
331 | 331 | } |
332 | 332 | |
333 | - $item_rows = implode( ', ', $item_rows ); |
|
334 | - $item_columns = implode( ', ', $item_columns ); |
|
335 | - $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" ); |
|
333 | + $item_rows = implode(', ', $item_rows); |
|
334 | + $item_columns = implode(', ', $item_columns); |
|
335 | + $wpdb->query("INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows"); |
|
336 | 336 | } |
337 | 337 | |
338 | - if ( empty( $invoice_rows ) ) { |
|
338 | + if (empty($invoice_rows)) { |
|
339 | 339 | return; |
340 | 340 | } |
341 | 341 | |
342 | - $invoice_rows = implode( ', ', $invoice_rows ); |
|
343 | - $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" ); |
|
342 | + $invoice_rows = implode(', ', $invoice_rows); |
|
343 | + $wpdb->query("INSERT INTO $invoices_table VALUES $invoice_rows"); |
|
344 | 344 | |
345 | 345 | } |
346 | 346 | |
@@ -352,32 +352,32 @@ discard block |
||
352 | 352 | global $wpdb; |
353 | 353 | |
354 | 354 | // Fetch post_id from $wpdb->prefix . 'getpaid_invoices' where customer_id = 0 or null. |
355 | - $invoice_ids = $wpdb->get_col( "SELECT post_id FROM {$wpdb->prefix}getpaid_invoices WHERE customer_id = 0 OR customer_id IS NULL" ); |
|
355 | + $invoice_ids = $wpdb->get_col("SELECT post_id FROM {$wpdb->prefix}getpaid_invoices WHERE customer_id = 0 OR customer_id IS NULL"); |
|
356 | 356 | |
357 | - foreach ( $invoice_ids as $invoice_id ) { |
|
358 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
357 | + foreach ($invoice_ids as $invoice_id) { |
|
358 | + $invoice = wpinv_get_invoice($invoice_id); |
|
359 | 359 | |
360 | - if ( empty( $invoice ) ) { |
|
360 | + if (empty($invoice)) { |
|
361 | 361 | continue; |
362 | 362 | } |
363 | 363 | |
364 | 364 | // Fetch customer from the user ID. |
365 | 365 | $user_id = $invoice->get_user_id(); |
366 | 366 | |
367 | - if ( empty( $user_id ) ) { |
|
367 | + if (empty($user_id)) { |
|
368 | 368 | continue; |
369 | 369 | } |
370 | 370 | |
371 | - $customer = getpaid_get_customer_by_user_id( $user_id ); |
|
371 | + $customer = getpaid_get_customer_by_user_id($user_id); |
|
372 | 372 | |
373 | 373 | // Create if not exists. |
374 | - if ( empty( $customer ) ) { |
|
375 | - $customer = new GetPaid_Customer( 0 ); |
|
376 | - $customer->clone_user( $user_id ); |
|
374 | + if (empty($customer)) { |
|
375 | + $customer = new GetPaid_Customer(0); |
|
376 | + $customer->clone_user($user_id); |
|
377 | 377 | $customer->save(); |
378 | 378 | } |
379 | 379 | |
380 | - $invoice->set_customer_id( $customer->get_id() ); |
|
380 | + $invoice->set_customer_id($customer->get_id()); |
|
381 | 381 | $invoice->save(); |
382 | 382 | } |
383 | 383 | |
@@ -390,12 +390,12 @@ discard block |
||
390 | 390 | public static function rename_gateways_label() { |
391 | 391 | global $wpdb; |
392 | 392 | |
393 | - foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) { |
|
393 | + foreach (array_keys(wpinv_get_payment_gateways()) as $gateway) { |
|
394 | 394 | |
395 | 395 | $wpdb->update( |
396 | 396 | $wpdb->prefix . 'getpaid_invoices', |
397 | - array( 'gateway' => $gateway ), |
|
398 | - array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ), |
|
397 | + array('gateway' => $gateway), |
|
398 | + array('gateway' => wpinv_get_gateway_admin_label($gateway)), |
|
399 | 399 | '%s', |
400 | 400 | '%s' |
401 | 401 | ); |
@@ -511,29 +511,29 @@ discard block |
||
511 | 511 | "; |
512 | 512 | |
513 | 513 | // Add address fields. |
514 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
514 | + foreach (array_keys(getpaid_user_address_fields()) as $field) { |
|
515 | 515 | // Skip id, user_id and email. |
516 | - if ( in_array( $field, array( 'id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid' ), true ) ) { |
|
516 | + if (in_array($field, array('id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid'), true)) { |
|
517 | 517 | continue; |
518 | 518 | } |
519 | 519 | |
520 | - $field = sanitize_key( $field ); |
|
520 | + $field = sanitize_key($field); |
|
521 | 521 | $length = 100; |
522 | 522 | $default = ''; |
523 | 523 | |
524 | 524 | // Country. |
525 | - if ( 'country' === $field ) { |
|
525 | + if ('country' === $field) { |
|
526 | 526 | $length = 2; |
527 | 527 | $default = wpinv_get_default_country(); |
528 | 528 | } |
529 | 529 | |
530 | 530 | // State. |
531 | - if ( 'state' === $field ) { |
|
531 | + if ('state' === $field) { |
|
532 | 532 | $default = wpinv_get_default_state(); |
533 | 533 | } |
534 | 534 | |
535 | 535 | // Phone, zip. |
536 | - if ( in_array( $field, array( 'phone', 'zip' ), true ) ) { |
|
536 | + if (in_array($field, array('phone', 'zip'), true)) { |
|
537 | 537 | $length = 20; |
538 | 538 | } |
539 | 539 | |
@@ -569,7 +569,7 @@ discard block |
||
569 | 569 | * @return bool |
570 | 570 | */ |
571 | 571 | public static function is_db_schema_up_to_date() { |
572 | - return md5( self::get_db_schema() ) === get_option( 'getpaid_db_schema' ); |
|
572 | + return md5(self::get_db_schema()) === get_option('getpaid_db_schema'); |
|
573 | 573 | } |
574 | 574 | |
575 | 575 | /** |
@@ -587,27 +587,27 @@ discard block |
||
587 | 587 | // If invoices table exists, rename key to invoice_key. |
588 | 588 | $invoices_table = "{$wpdb->prefix}getpaid_invoices"; |
589 | 589 | |
590 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) === $invoices_table ) { |
|
591 | - $fields = $wpdb->get_results( "SHOW COLUMNS FROM {$wpdb->prefix}getpaid_invoices" ); |
|
590 | + if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'") === $invoices_table) { |
|
591 | + $fields = $wpdb->get_results("SHOW COLUMNS FROM {$wpdb->prefix}getpaid_invoices"); |
|
592 | 592 | |
593 | - foreach ( $fields as $field ) { |
|
594 | - if ( 'key' === $field->Field ) { |
|
595 | - $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoices CHANGE `key` `invoice_key` VARCHAR(100)" ); |
|
593 | + foreach ($fields as $field) { |
|
594 | + if ('key' === $field->Field) { |
|
595 | + $wpdb->query("ALTER TABLE {$wpdb->prefix}getpaid_invoices CHANGE `key` `invoice_key` VARCHAR(100)"); |
|
596 | 596 | break; |
597 | 597 | } |
598 | 598 | } |
599 | 599 | } |
600 | 600 | |
601 | - dbDelta( $schema ); |
|
601 | + dbDelta($schema); |
|
602 | 602 | wp_cache_flush(); |
603 | - update_option( 'getpaid_db_schema', md5( self::get_db_schema() ) ); |
|
603 | + update_option('getpaid_db_schema', md5(self::get_db_schema())); |
|
604 | 604 | } |
605 | 605 | |
606 | 606 | /** |
607 | 607 | * Creates tables if schema is not up to date. |
608 | 608 | */ |
609 | 609 | public static function maybe_create_db_tables() { |
610 | - if ( ! self::is_db_schema_up_to_date() ) { |
|
610 | + if (!self::is_db_schema_up_to_date()) { |
|
611 | 611 | self::create_db_tables(); |
612 | 612 | } |
613 | 613 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @since 1.0.0 |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Retrieves all default settings. |
@@ -16,13 +16,13 @@ discard block |
||
16 | 16 | function wpinv_get_settings() { |
17 | 17 | $defaults = array(); |
18 | 18 | |
19 | - foreach ( array_values( wpinv_get_registered_settings() ) as $tab_settings ) { |
|
19 | + foreach (array_values(wpinv_get_registered_settings()) as $tab_settings) { |
|
20 | 20 | |
21 | - foreach ( array_values( $tab_settings ) as $section_settings ) { |
|
21 | + foreach (array_values($tab_settings) as $section_settings) { |
|
22 | 22 | |
23 | - foreach ( $section_settings as $key => $setting ) { |
|
24 | - if ( isset( $setting['std'] ) ) { |
|
25 | - $defaults[ $key ] = $setting['std']; |
|
23 | + foreach ($section_settings as $key => $setting) { |
|
24 | + if (isset($setting['std'])) { |
|
25 | + $defaults[$key] = $setting['std']; |
|
26 | 26 | } |
27 | 27 | } |
28 | 28 | } |
@@ -41,12 +41,12 @@ discard block |
||
41 | 41 | global $wpinv_options; |
42 | 42 | |
43 | 43 | // Try fetching the saved options. |
44 | - if ( empty( $wpinv_options ) ) { |
|
45 | - $wpinv_options = get_option( 'wpinv_settings' ); |
|
44 | + if (empty($wpinv_options)) { |
|
45 | + $wpinv_options = get_option('wpinv_settings'); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | // If that fails, don't fetch the default settings to prevent a loop. |
49 | - if ( ! is_array( $wpinv_options ) ) { |
|
49 | + if (!is_array($wpinv_options)) { |
|
50 | 50 | $wpinv_options = array(); |
51 | 51 | } |
52 | 52 | |
@@ -60,13 +60,13 @@ discard block |
||
60 | 60 | * @param mixed $default The default value to use if the setting has not been set. |
61 | 61 | * @return mixed |
62 | 62 | */ |
63 | -function wpinv_get_option( $key = '', $default = false ) { |
|
63 | +function wpinv_get_option($key = '', $default = false) { |
|
64 | 64 | |
65 | 65 | $options = wpinv_get_options(); |
66 | - $value = isset( $options[ $key ] ) ? $options[ $key ] : $default; |
|
67 | - $value = apply_filters( 'wpinv_get_option', $value, $key, $default ); |
|
66 | + $value = isset($options[$key]) ? $options[$key] : $default; |
|
67 | + $value = apply_filters('wpinv_get_option', $value, $key, $default); |
|
68 | 68 | |
69 | - return apply_filters( 'wpinv_get_option_' . $key, $value, $key, $default ); |
|
69 | + return apply_filters('wpinv_get_option_' . $key, $value, $key, $default); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -75,11 +75,11 @@ discard block |
||
75 | 75 | * @param array $options the new options. |
76 | 76 | * @return bool |
77 | 77 | */ |
78 | -function wpinv_update_options( $options ) { |
|
78 | +function wpinv_update_options($options) { |
|
79 | 79 | global $wpinv_options; |
80 | 80 | |
81 | 81 | // update the option. |
82 | - if ( is_array( $options ) && update_option( 'wpinv_settings', $options ) ) { |
|
82 | + if (is_array($options) && update_option('wpinv_settings', $options)) { |
|
83 | 83 | $wpinv_options = $options; |
84 | 84 | return true; |
85 | 85 | } |
@@ -94,24 +94,24 @@ discard block |
||
94 | 94 | * @param mixed $value The setting value. |
95 | 95 | * @return bool |
96 | 96 | */ |
97 | -function wpinv_update_option( $key = '', $value = false ) { |
|
97 | +function wpinv_update_option($key = '', $value = false) { |
|
98 | 98 | |
99 | 99 | // If no key, exit. |
100 | - if ( empty( $key ) ) { |
|
100 | + if (empty($key)) { |
|
101 | 101 | return false; |
102 | 102 | } |
103 | 103 | |
104 | 104 | // Maybe delete the option instead. |
105 | - if ( is_null( $value ) ) { |
|
106 | - return wpinv_delete_option( $key ); |
|
105 | + if (is_null($value)) { |
|
106 | + return wpinv_delete_option($key); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | // Prepare the new options. |
110 | 110 | $options = wpinv_get_options(); |
111 | - $options[ $key ] = apply_filters( 'wpinv_update_option', $value, $key ); |
|
111 | + $options[$key] = apply_filters('wpinv_update_option', $value, $key); |
|
112 | 112 | |
113 | 113 | // Save the new options. |
114 | - return wpinv_update_options( $options ); |
|
114 | + return wpinv_update_options($options); |
|
115 | 115 | |
116 | 116 | } |
117 | 117 | |
@@ -121,18 +121,18 @@ discard block |
||
121 | 121 | * @param string $key the setting key. |
122 | 122 | * @return bool |
123 | 123 | */ |
124 | -function wpinv_delete_option( $key = '' ) { |
|
124 | +function wpinv_delete_option($key = '') { |
|
125 | 125 | |
126 | 126 | // If no key, exit |
127 | - if ( empty( $key ) ) { |
|
127 | + if (empty($key)) { |
|
128 | 128 | return false; |
129 | 129 | } |
130 | 130 | |
131 | 131 | $options = wpinv_get_options(); |
132 | 132 | |
133 | - if ( isset( $options[ $key ] ) ) { |
|
134 | - unset( $options[ $key ] ); |
|
135 | - return wpinv_update_options( $options ); |
|
133 | + if (isset($options[$key])) { |
|
134 | + unset($options[$key]); |
|
135 | + return wpinv_update_options($options); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | return true; |
@@ -144,22 +144,22 @@ discard block |
||
144 | 144 | * |
145 | 145 | */ |
146 | 146 | function wpinv_register_settings() { |
147 | - do_action( 'getpaid_before_register_settings' ); |
|
147 | + do_action('getpaid_before_register_settings'); |
|
148 | 148 | |
149 | 149 | // Loop through all tabs. |
150 | - foreach ( wpinv_get_registered_settings() as $tab => $sections ) { |
|
150 | + foreach (wpinv_get_registered_settings() as $tab => $sections) { |
|
151 | 151 | |
152 | 152 | // In each tab, loop through sections. |
153 | - foreach ( $sections as $section => $settings ) { |
|
153 | + foreach ($sections as $section => $settings) { |
|
154 | 154 | |
155 | 155 | // Check for backwards compatibility |
156 | - $section_tabs = wpinv_get_settings_tab_sections( $tab ); |
|
157 | - if ( ! is_array( $section_tabs ) || ! array_key_exists( $section, $section_tabs ) ) { |
|
156 | + $section_tabs = wpinv_get_settings_tab_sections($tab); |
|
157 | + if (!is_array($section_tabs) || !array_key_exists($section, $section_tabs)) { |
|
158 | 158 | $section = 'main'; |
159 | 159 | $settings = $sections; |
160 | 160 | } |
161 | 161 | |
162 | - do_action( "getpaid_register_{$tab}_{$section}" ); |
|
162 | + do_action("getpaid_register_{$tab}_{$section}"); |
|
163 | 163 | |
164 | 164 | // Register the setting section. |
165 | 165 | add_settings_section( |
@@ -169,20 +169,20 @@ discard block |
||
169 | 169 | 'wpinv_settings_' . $tab . '_' . $section |
170 | 170 | ); |
171 | 171 | |
172 | - foreach ( $settings as $option ) { |
|
173 | - if ( ! empty( $option['id'] ) ) { |
|
174 | - wpinv_register_settings_option( $tab, $section, $option ); |
|
172 | + foreach ($settings as $option) { |
|
173 | + if (!empty($option['id'])) { |
|
174 | + wpinv_register_settings_option($tab, $section, $option); |
|
175 | 175 | } |
176 | 176 | } |
177 | 177 | } |
178 | 178 | } |
179 | 179 | |
180 | 180 | // Creates our settings in the options table. |
181 | - register_setting( 'wpinv_settings', 'wpinv_settings', 'wpinv_settings_sanitize' ); |
|
181 | + register_setting('wpinv_settings', 'wpinv_settings', 'wpinv_settings_sanitize'); |
|
182 | 182 | |
183 | - do_action( 'getpaid_after_register_settings' ); |
|
183 | + do_action('getpaid_after_register_settings'); |
|
184 | 184 | } |
185 | -add_action( 'admin_init', 'wpinv_register_settings' ); |
|
185 | +add_action('admin_init', 'wpinv_register_settings'); |
|
186 | 186 | |
187 | 187 | /** |
188 | 188 | * Register a single settings option. |
@@ -192,49 +192,49 @@ discard block |
||
192 | 192 | * @param string $option |
193 | 193 | * |
194 | 194 | */ |
195 | -function wpinv_register_settings_option( $tab, $section, $option ) { |
|
195 | +function wpinv_register_settings_option($tab, $section, $option) { |
|
196 | 196 | |
197 | - $name = isset( $option['name'] ) ? $option['name'] : ''; |
|
197 | + $name = isset($option['name']) ? $option['name'] : ''; |
|
198 | 198 | $cb = "wpinv_{$option['type']}_callback"; |
199 | 199 | $section = "wpinv_settings_{$tab}_$section"; |
200 | - $is_wizzard = is_admin() && isset( $_GET['page'] ) && 'gp-setup' == $_GET['page']; |
|
200 | + $is_wizzard = is_admin() && isset($_GET['page']) && 'gp-setup' == $_GET['page']; |
|
201 | 201 | |
202 | - if ( isset( $option['desc'] ) && ( ! $is_wizzard && ! empty( $option['help-tip'] ) ) ) { |
|
203 | - $tip = wpinv_clean( $option['desc'] ); |
|
202 | + if (isset($option['desc']) && (!$is_wizzard && !empty($option['help-tip']))) { |
|
203 | + $tip = wpinv_clean($option['desc']); |
|
204 | 204 | $name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>"; |
205 | - unset( $option['desc'] ); |
|
205 | + unset($option['desc']); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | // Loop through all tabs. |
209 | 209 | add_settings_field( |
210 | 210 | 'wpinv_settings[' . $option['id'] . ']', |
211 | 211 | $name, |
212 | - function_exists( $cb ) ? $cb : 'wpinv_missing_callback', |
|
212 | + function_exists($cb) ? $cb : 'wpinv_missing_callback', |
|
213 | 213 | $section, |
214 | 214 | $section, |
215 | 215 | array( |
216 | 216 | 'section' => $section, |
217 | - 'id' => isset( $option['id'] ) ? $option['id'] : uniqid( 'wpinv-' ), |
|
218 | - 'desc' => isset( $option['desc'] ) ? $option['desc'] : '', |
|
217 | + 'id' => isset($option['id']) ? $option['id'] : uniqid('wpinv-'), |
|
218 | + 'desc' => isset($option['desc']) ? $option['desc'] : '', |
|
219 | 219 | 'name' => $name, |
220 | - 'size' => isset( $option['size'] ) ? $option['size'] : null, |
|
221 | - 'options' => isset( $option['options'] ) ? $option['options'] : '', |
|
222 | - 'selected' => isset( $option['selected'] ) ? $option['selected'] : null, |
|
223 | - 'std' => isset( $option['std'] ) ? $option['std'] : '', |
|
224 | - 'min' => isset( $option['min'] ) ? $option['min'] : 0, |
|
225 | - 'max' => isset( $option['max'] ) ? $option['max'] : 999999, |
|
226 | - 'step' => isset( $option['step'] ) ? $option['step'] : 1, |
|
227 | - 'placeholder' => isset( $option['placeholder'] ) ? $option['placeholder'] : null, |
|
228 | - 'allow_blank' => isset( $option['allow_blank'] ) ? $option['allow_blank'] : true, |
|
229 | - 'readonly' => isset( $option['readonly'] ) ? $option['readonly'] : false, |
|
230 | - 'faux' => isset( $option['faux'] ) ? $option['faux'] : false, |
|
231 | - 'onchange' => isset( $option['onchange'] ) ? $option['onchange'] : '', |
|
232 | - 'custom' => isset( $option['custom'] ) ? $option['custom'] : '', |
|
233 | - 'default_content' => isset( $option['default_content'] ) ? $option['default_content'] : '', |
|
234 | - 'class' => isset( $option['class'] ) ? $option['class'] : '', |
|
235 | - 'style' => isset( $option['style'] ) ? $option['style'] : '', |
|
236 | - 'cols' => isset( $option['cols'] ) && (int) $option['cols'] > 0 ? (int) $option['cols'] : 50, |
|
237 | - 'rows' => isset( $option['rows'] ) && (int) $option['rows'] > 0 ? (int) $option['rows'] : 5, |
|
220 | + 'size' => isset($option['size']) ? $option['size'] : null, |
|
221 | + 'options' => isset($option['options']) ? $option['options'] : '', |
|
222 | + 'selected' => isset($option['selected']) ? $option['selected'] : null, |
|
223 | + 'std' => isset($option['std']) ? $option['std'] : '', |
|
224 | + 'min' => isset($option['min']) ? $option['min'] : 0, |
|
225 | + 'max' => isset($option['max']) ? $option['max'] : 999999, |
|
226 | + 'step' => isset($option['step']) ? $option['step'] : 1, |
|
227 | + 'placeholder' => isset($option['placeholder']) ? $option['placeholder'] : null, |
|
228 | + 'allow_blank' => isset($option['allow_blank']) ? $option['allow_blank'] : true, |
|
229 | + 'readonly' => isset($option['readonly']) ? $option['readonly'] : false, |
|
230 | + 'faux' => isset($option['faux']) ? $option['faux'] : false, |
|
231 | + 'onchange' => isset($option['onchange']) ? $option['onchange'] : '', |
|
232 | + 'custom' => isset($option['custom']) ? $option['custom'] : '', |
|
233 | + 'default_content' => isset($option['default_content']) ? $option['default_content'] : '', |
|
234 | + 'class' => isset($option['class']) ? $option['class'] : '', |
|
235 | + 'style' => isset($option['style']) ? $option['style'] : '', |
|
236 | + 'cols' => isset($option['cols']) && (int) $option['cols'] > 0 ? (int) $option['cols'] : 50, |
|
237 | + 'rows' => isset($option['rows']) && (int) $option['rows'] > 0 ? (int) $option['rows'] : 5, |
|
238 | 238 | ) |
239 | 239 | ); |
240 | 240 | |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | * @return array |
247 | 247 | */ |
248 | 248 | function wpinv_get_registered_settings() { |
249 | - return array_filter( apply_filters( 'wpinv_registered_settings', wpinv_get_data( 'admin-settings' ) ) ); |
|
249 | + return array_filter(apply_filters('wpinv_registered_settings', wpinv_get_data('admin-settings'))); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | /** |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | * @return array |
256 | 256 | */ |
257 | 257 | function getpaid_get_integration_settings() { |
258 | - return apply_filters( 'getpaid_integration_settings', array() ); |
|
258 | + return apply_filters('getpaid_integration_settings', array()); |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | /** |
@@ -263,153 +263,153 @@ discard block |
||
263 | 263 | * |
264 | 264 | * @return array |
265 | 265 | */ |
266 | -function wpinv_settings_sanitize( $input = array() ) { |
|
266 | +function wpinv_settings_sanitize($input = array()) { |
|
267 | 267 | |
268 | 268 | $wpinv_options = wpinv_get_options(); |
269 | 269 | $raw_referrer = wp_get_raw_referer(); |
270 | 270 | |
271 | - if ( empty( $raw_referrer ) ) { |
|
272 | - return array_merge( $wpinv_options, $input ); |
|
271 | + if (empty($raw_referrer)) { |
|
272 | + return array_merge($wpinv_options, $input); |
|
273 | 273 | } |
274 | 274 | |
275 | - wp_parse_str( $raw_referrer, $referrer ); |
|
275 | + wp_parse_str($raw_referrer, $referrer); |
|
276 | 276 | |
277 | - if ( in_array( 'gp-setup', $referrer ) ) { |
|
278 | - return array_merge( $wpinv_options, $input ); |
|
277 | + if (in_array('gp-setup', $referrer)) { |
|
278 | + return array_merge($wpinv_options, $input); |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | $settings = wpinv_get_registered_settings(); |
282 | - $tab = isset( $referrer['tab'] ) ? $referrer['tab'] : 'general'; |
|
283 | - $section = isset( $referrer['section'] ) ? $referrer['section'] : 'main'; |
|
282 | + $tab = isset($referrer['tab']) ? $referrer['tab'] : 'general'; |
|
283 | + $section = isset($referrer['section']) ? $referrer['section'] : 'main'; |
|
284 | 284 | |
285 | 285 | $input = $input ? $input : array(); |
286 | - $input = apply_filters( 'wpinv_settings_tab_' . $tab . '_sanitize', $input ); |
|
287 | - $input = apply_filters( 'wpinv_settings_' . $tab . '-' . $section . '_sanitize', $input ); |
|
286 | + $input = apply_filters('wpinv_settings_tab_' . $tab . '_sanitize', $input); |
|
287 | + $input = apply_filters('wpinv_settings_' . $tab . '-' . $section . '_sanitize', $input); |
|
288 | 288 | |
289 | 289 | // Loop through each setting being saved and pass it through a sanitization filter |
290 | - foreach ( $input as $key => $value ) { |
|
290 | + foreach ($input as $key => $value) { |
|
291 | 291 | |
292 | 292 | // Get the setting type (checkbox, select, etc) |
293 | - $type = isset( $settings[ $tab ][ $section ][ $key ]['type'] ) ? $settings[ $tab ][ $section ][ $key ]['type'] : false; |
|
293 | + $type = isset($settings[$tab][$section][$key]['type']) ? $settings[$tab][$section][$key]['type'] : false; |
|
294 | 294 | |
295 | - if ( $type ) { |
|
295 | + if ($type) { |
|
296 | 296 | // Field type specific filter |
297 | - $input[ $key ] = apply_filters( "wpinv_settings_sanitize_$type", $value, $key ); |
|
297 | + $input[$key] = apply_filters("wpinv_settings_sanitize_$type", $value, $key); |
|
298 | 298 | } |
299 | 299 | |
300 | 300 | // General filter |
301 | - $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key ); |
|
301 | + $input[$key] = apply_filters('wpinv_settings_sanitize', $input[$key], $key); |
|
302 | 302 | |
303 | 303 | // Key specific filter. |
304 | - $input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] ); |
|
304 | + $input[$key] = apply_filters("wpinv_settings_sanitize_$key", $input[$key]); |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | // Loop through the whitelist and unset any that are empty for the tab being saved |
308 | - $main_settings = isset( $settings[ $tab ] ) ? $settings[ $tab ] : array(); // Check for extensions that aren't using new sections |
|
309 | - $section_settings = ! empty( $settings[ $tab ][ $section ] ) ? $settings[ $tab ][ $section ] : array(); |
|
308 | + $main_settings = isset($settings[$tab]) ? $settings[$tab] : array(); // Check for extensions that aren't using new sections |
|
309 | + $section_settings = !empty($settings[$tab][$section]) ? $settings[$tab][$section] : array(); |
|
310 | 310 | |
311 | - $found_settings = array_merge( $main_settings, $section_settings ); |
|
311 | + $found_settings = array_merge($main_settings, $section_settings); |
|
312 | 312 | |
313 | - if ( ! empty( $found_settings ) ) { |
|
314 | - foreach ( $found_settings as $key => $value ) { |
|
313 | + if (!empty($found_settings)) { |
|
314 | + foreach ($found_settings as $key => $value) { |
|
315 | 315 | |
316 | 316 | // settings used to have numeric keys, now they have keys that match the option ID. This ensures both methods work |
317 | - if ( is_numeric( $key ) ) { |
|
317 | + if (is_numeric($key)) { |
|
318 | 318 | $key = $value['id']; |
319 | 319 | } |
320 | 320 | |
321 | - if ( ! isset( $input[ $key ] ) && isset( $wpinv_options[ $key ] ) ) { |
|
322 | - unset( $wpinv_options[ $key ] ); |
|
321 | + if (!isset($input[$key]) && isset($wpinv_options[$key])) { |
|
322 | + unset($wpinv_options[$key]); |
|
323 | 323 | } |
324 | 324 | } |
325 | 325 | } |
326 | 326 | |
327 | 327 | // Merge our new settings with the existing |
328 | - $output = array_merge( $wpinv_options, $input ); |
|
328 | + $output = array_merge($wpinv_options, $input); |
|
329 | 329 | |
330 | - add_settings_error( 'wpinv-notices', '', __( 'Settings updated.', 'invoicing' ), 'updated' ); |
|
330 | + add_settings_error('wpinv-notices', '', __('Settings updated.', 'invoicing'), 'updated'); |
|
331 | 331 | |
332 | 332 | return $output; |
333 | 333 | } |
334 | -add_filter( 'wpinv_settings_sanitize_text', 'trim', 10, 1 ); |
|
335 | -add_filter( 'wpinv_settings_sanitize_tax_rate', 'wpinv_sanitize_amount' ); |
|
334 | +add_filter('wpinv_settings_sanitize_text', 'trim', 10, 1); |
|
335 | +add_filter('wpinv_settings_sanitize_tax_rate', 'wpinv_sanitize_amount'); |
|
336 | 336 | |
337 | -function wpinv_settings_sanitize_tax_rates( $input ) { |
|
338 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
337 | +function wpinv_settings_sanitize_tax_rates($input) { |
|
338 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
339 | 339 | return $input; |
340 | 340 | } |
341 | 341 | |
342 | - $new_rates = ! empty( $_POST['tax_rates'] ) ? wp_kses_post_deep( array_values( $_POST['tax_rates'] ) ) : array(); |
|
342 | + $new_rates = !empty($_POST['tax_rates']) ? wp_kses_post_deep(array_values($_POST['tax_rates'])) : array(); |
|
343 | 343 | $tax_rates = array(); |
344 | 344 | |
345 | - foreach ( $new_rates as $rate ) { |
|
345 | + foreach ($new_rates as $rate) { |
|
346 | 346 | |
347 | - $rate['rate'] = wpinv_sanitize_amount( $rate['rate'] ); |
|
348 | - $rate['name'] = sanitize_text_field( $rate['name'] ); |
|
349 | - $rate['state'] = sanitize_text_field( $rate['state'] ); |
|
350 | - $rate['country'] = sanitize_text_field( $rate['country'] ); |
|
351 | - $rate['global'] = empty( $rate['state'] ); |
|
347 | + $rate['rate'] = wpinv_sanitize_amount($rate['rate']); |
|
348 | + $rate['name'] = sanitize_text_field($rate['name']); |
|
349 | + $rate['state'] = sanitize_text_field($rate['state']); |
|
350 | + $rate['country'] = sanitize_text_field($rate['country']); |
|
351 | + $rate['global'] = empty($rate['state']); |
|
352 | 352 | $tax_rates[] = $rate; |
353 | 353 | |
354 | 354 | } |
355 | 355 | |
356 | - update_option( 'wpinv_tax_rates', $tax_rates ); |
|
356 | + update_option('wpinv_tax_rates', $tax_rates); |
|
357 | 357 | |
358 | 358 | return $input; |
359 | 359 | } |
360 | -add_filter( 'wpinv_settings_taxes-rates_sanitize', 'wpinv_settings_sanitize_tax_rates' ); |
|
360 | +add_filter('wpinv_settings_taxes-rates_sanitize', 'wpinv_settings_sanitize_tax_rates'); |
|
361 | 361 | |
362 | -function wpinv_settings_sanitize_tax_rules( $input ) { |
|
363 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
362 | +function wpinv_settings_sanitize_tax_rules($input) { |
|
363 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
364 | 364 | return $input; |
365 | 365 | } |
366 | 366 | |
367 | - if ( empty( $_POST['wpinv_tax_rules_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_tax_rules_nonce'], 'wpinv_tax_rules' ) ) { |
|
367 | + if (empty($_POST['wpinv_tax_rules_nonce']) || !wp_verify_nonce($_POST['wpinv_tax_rules_nonce'], 'wpinv_tax_rules')) { |
|
368 | 368 | return $input; |
369 | 369 | } |
370 | 370 | |
371 | - $new_rules = ! empty( $_POST['tax_rules'] ) ? wp_kses_post_deep( array_values( $_POST['tax_rules'] ) ) : array(); |
|
371 | + $new_rules = !empty($_POST['tax_rules']) ? wp_kses_post_deep(array_values($_POST['tax_rules'])) : array(); |
|
372 | 372 | $tax_rules = array(); |
373 | 373 | |
374 | - foreach ( $new_rules as $rule ) { |
|
374 | + foreach ($new_rules as $rule) { |
|
375 | 375 | |
376 | - $rule['key'] = sanitize_title_with_dashes( $rule['key'] ); |
|
377 | - $rule['label'] = sanitize_text_field( $rule['label'] ); |
|
378 | - $rule['tax_base'] = sanitize_text_field( $rule['tax_base'] ); |
|
376 | + $rule['key'] = sanitize_title_with_dashes($rule['key']); |
|
377 | + $rule['label'] = sanitize_text_field($rule['label']); |
|
378 | + $rule['tax_base'] = sanitize_text_field($rule['tax_base']); |
|
379 | 379 | $tax_rules[] = $rule; |
380 | 380 | |
381 | 381 | } |
382 | 382 | |
383 | - update_option( 'wpinv_tax_rules', $tax_rules ); |
|
383 | + update_option('wpinv_tax_rules', $tax_rules); |
|
384 | 384 | |
385 | 385 | return $input; |
386 | 386 | } |
387 | -add_filter( 'wpinv_settings_taxes-rules_sanitize', 'wpinv_settings_sanitize_tax_rules' ); |
|
387 | +add_filter('wpinv_settings_taxes-rules_sanitize', 'wpinv_settings_sanitize_tax_rules'); |
|
388 | 388 | |
389 | 389 | function wpinv_get_settings_tabs() { |
390 | 390 | $tabs = array(); |
391 | - $tabs['general'] = __( 'General', 'invoicing' ); |
|
392 | - $tabs['gateways'] = __( 'Payment Gateways', 'invoicing' ); |
|
393 | - $tabs['taxes'] = __( 'Taxes', 'invoicing' ); |
|
394 | - $tabs['emails'] = __( 'Emails', 'invoicing' ); |
|
391 | + $tabs['general'] = __('General', 'invoicing'); |
|
392 | + $tabs['gateways'] = __('Payment Gateways', 'invoicing'); |
|
393 | + $tabs['taxes'] = __('Taxes', 'invoicing'); |
|
394 | + $tabs['emails'] = __('Emails', 'invoicing'); |
|
395 | 395 | |
396 | - if ( count( getpaid_get_integration_settings() ) > 0 ) { |
|
397 | - $tabs['integrations'] = __( 'Integrations', 'invoicing' ); |
|
396 | + if (count(getpaid_get_integration_settings()) > 0) { |
|
397 | + $tabs['integrations'] = __('Integrations', 'invoicing'); |
|
398 | 398 | } |
399 | 399 | |
400 | - $tabs['privacy'] = __( 'Privacy', 'invoicing' ); |
|
401 | - $tabs['misc'] = __( 'Misc', 'invoicing' ); |
|
402 | - $tabs['tools'] = __( 'Tools', 'invoicing' ); |
|
400 | + $tabs['privacy'] = __('Privacy', 'invoicing'); |
|
401 | + $tabs['misc'] = __('Misc', 'invoicing'); |
|
402 | + $tabs['tools'] = __('Tools', 'invoicing'); |
|
403 | 403 | |
404 | - return apply_filters( 'wpinv_settings_tabs', $tabs ); |
|
404 | + return apply_filters('wpinv_settings_tabs', $tabs); |
|
405 | 405 | } |
406 | 406 | |
407 | -function wpinv_get_settings_tab_sections( $tab = false ) { |
|
407 | +function wpinv_get_settings_tab_sections($tab = false) { |
|
408 | 408 | $tabs = false; |
409 | 409 | $sections = wpinv_get_registered_settings_sections(); |
410 | 410 | |
411 | - if ( $tab && ! empty( $sections[ $tab ] ) ) { |
|
412 | - $tabs = $sections[ $tab ]; |
|
411 | + if ($tab && !empty($sections[$tab])) { |
|
412 | + $tabs = $sections[$tab]; |
|
413 | 413 | } |
414 | 414 | |
415 | 415 | return $tabs; |
@@ -418,7 +418,7 @@ discard block |
||
418 | 418 | function wpinv_get_registered_settings_sections() { |
419 | 419 | static $sections = false; |
420 | 420 | |
421 | - if ( false !== $sections ) { |
|
421 | + if (false !== $sections) { |
|
422 | 422 | return $sections; |
423 | 423 | } |
424 | 424 | |
@@ -426,229 +426,229 @@ discard block |
||
426 | 426 | 'general' => apply_filters( |
427 | 427 | 'wpinv_settings_sections_general', |
428 | 428 | array( |
429 | - 'main' => __( 'General Settings', 'invoicing' ), |
|
430 | - 'page_section' => __( 'Page Settings', 'invoicing' ), |
|
431 | - 'currency_section' => __( 'Currency Settings', 'invoicing' ), |
|
432 | - 'labels' => __( 'Label Texts', 'invoicing' ), |
|
429 | + 'main' => __('General Settings', 'invoicing'), |
|
430 | + 'page_section' => __('Page Settings', 'invoicing'), |
|
431 | + 'currency_section' => __('Currency Settings', 'invoicing'), |
|
432 | + 'labels' => __('Label Texts', 'invoicing'), |
|
433 | 433 | ) |
434 | 434 | ), |
435 | 435 | 'gateways' => apply_filters( |
436 | 436 | 'wpinv_settings_sections_gateways', |
437 | 437 | array( |
438 | - 'main' => __( 'Gateway Settings', 'invoicing' ), |
|
438 | + 'main' => __('Gateway Settings', 'invoicing'), |
|
439 | 439 | ) |
440 | 440 | ), |
441 | 441 | 'taxes' => apply_filters( |
442 | 442 | 'wpinv_settings_sections_taxes', |
443 | 443 | array( |
444 | - 'main' => __( 'Tax Settings', 'invoicing' ), |
|
445 | - 'rules' => __( 'Tax Rules', 'invoicing' ), |
|
446 | - 'rates' => __( 'Tax Rates', 'invoicing' ), |
|
447 | - 'vat' => __( 'EU VAT Settings', 'invoicing' ), |
|
444 | + 'main' => __('Tax Settings', 'invoicing'), |
|
445 | + 'rules' => __('Tax Rules', 'invoicing'), |
|
446 | + 'rates' => __('Tax Rates', 'invoicing'), |
|
447 | + 'vat' => __('EU VAT Settings', 'invoicing'), |
|
448 | 448 | ) |
449 | 449 | ), |
450 | 450 | 'emails' => apply_filters( |
451 | 451 | 'wpinv_settings_sections_emails', |
452 | 452 | array( |
453 | - 'main' => __( 'Email Settings', 'invoicing' ), |
|
453 | + 'main' => __('Email Settings', 'invoicing'), |
|
454 | 454 | ) |
455 | 455 | ), |
456 | 456 | |
457 | - 'integrations' => wp_list_pluck( getpaid_get_integration_settings(), 'label', 'id' ), |
|
457 | + 'integrations' => wp_list_pluck(getpaid_get_integration_settings(), 'label', 'id'), |
|
458 | 458 | |
459 | 459 | 'privacy' => apply_filters( |
460 | 460 | 'wpinv_settings_sections_privacy', |
461 | 461 | array( |
462 | - 'main' => __( 'Privacy policy', 'invoicing' ), |
|
462 | + 'main' => __('Privacy policy', 'invoicing'), |
|
463 | 463 | ) |
464 | 464 | ), |
465 | 465 | 'misc' => apply_filters( |
466 | 466 | 'wpinv_settings_sections_misc', |
467 | 467 | array( |
468 | - 'main' => __( 'Miscellaneous', 'invoicing' ), |
|
469 | - 'custom-css' => __( 'Custom CSS', 'invoicing' ), |
|
468 | + 'main' => __('Miscellaneous', 'invoicing'), |
|
469 | + 'custom-css' => __('Custom CSS', 'invoicing'), |
|
470 | 470 | ) |
471 | 471 | ), |
472 | 472 | 'tools' => apply_filters( |
473 | 473 | 'wpinv_settings_sections_tools', |
474 | 474 | array( |
475 | - 'main' => __( 'Diagnostic Tools', 'invoicing' ), |
|
475 | + 'main' => __('Diagnostic Tools', 'invoicing'), |
|
476 | 476 | ) |
477 | 477 | ), |
478 | 478 | ); |
479 | 479 | |
480 | - $sections = apply_filters( 'wpinv_settings_sections', $sections ); |
|
480 | + $sections = apply_filters('wpinv_settings_sections', $sections); |
|
481 | 481 | |
482 | 482 | return $sections; |
483 | 483 | } |
484 | 484 | |
485 | -function wpinv_get_pages( $with_slug = false, $default_label = null ) { |
|
485 | +function wpinv_get_pages($with_slug = false, $default_label = null) { |
|
486 | 486 | $pages_options = array(); |
487 | 487 | |
488 | - if ( $default_label !== null && $default_label !== false ) { |
|
489 | - $pages_options = array( '' => $default_label ); // Blank option |
|
488 | + if ($default_label !== null && $default_label !== false) { |
|
489 | + $pages_options = array('' => $default_label); // Blank option |
|
490 | 490 | } |
491 | 491 | |
492 | 492 | $pages = get_pages(); |
493 | - if ( $pages ) { |
|
494 | - foreach ( $pages as $page ) { |
|
493 | + if ($pages) { |
|
494 | + foreach ($pages as $page) { |
|
495 | 495 | $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title; |
496 | - $pages_options[ $page->ID ] = $title; |
|
496 | + $pages_options[$page->ID] = $title; |
|
497 | 497 | } |
498 | 498 | } |
499 | 499 | |
500 | 500 | return $pages_options; |
501 | 501 | } |
502 | 502 | |
503 | -function wpinv_header_callback( $args ) { |
|
504 | - if ( ! empty( $args['desc'] ) ) { |
|
505 | - echo wp_kses_post( $args['desc'] ); |
|
503 | +function wpinv_header_callback($args) { |
|
504 | + if (!empty($args['desc'])) { |
|
505 | + echo wp_kses_post($args['desc']); |
|
506 | 506 | } |
507 | 507 | } |
508 | 508 | |
509 | -function wpinv_hidden_callback( $args ) { |
|
509 | +function wpinv_hidden_callback($args) { |
|
510 | 510 | |
511 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
512 | - $value = wpinv_get_option( $args['id'], $std ); |
|
511 | + $std = isset($args['std']) ? $args['std'] : ''; |
|
512 | + $value = wpinv_get_option($args['id'], $std); |
|
513 | 513 | |
514 | - if ( isset( $args['set_value'] ) ) { |
|
514 | + if (isset($args['set_value'])) { |
|
515 | 515 | $value = $args['set_value']; |
516 | 516 | } |
517 | 517 | |
518 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
518 | + if (isset($args['faux']) && true === $args['faux']) { |
|
519 | 519 | $args['readonly'] = true; |
520 | - $name = ''; |
|
520 | + $name = ''; |
|
521 | 521 | } else { |
522 | - $name = 'wpinv_settings[' . esc_attr( $args['id'] ) . ']'; |
|
522 | + $name = 'wpinv_settings[' . esc_attr($args['id']) . ']'; |
|
523 | 523 | } |
524 | 524 | |
525 | - echo '<input type="hidden" id="wpinv_settings[' . esc_attr( $args['id'] ) . ']" name="' . esc_attr( $name ) . '" value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
525 | + echo '<input type="hidden" id="wpinv_settings[' . esc_attr($args['id']) . ']" name="' . esc_attr($name) . '" value="' . esc_attr(stripslashes($value)) . '" />'; |
|
526 | 526 | |
527 | 527 | } |
528 | 528 | |
529 | 529 | /** |
530 | 530 | * Displays a checkbox settings callback. |
531 | 531 | */ |
532 | -function wpinv_checkbox_callback( $args ) { |
|
532 | +function wpinv_checkbox_callback($args) { |
|
533 | 533 | |
534 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
535 | - $std = wpinv_get_option( $args['id'], $std ); |
|
536 | - $id = esc_attr( $args['id'] ); |
|
534 | + $std = isset($args['std']) ? $args['std'] : ''; |
|
535 | + $std = wpinv_get_option($args['id'], $std); |
|
536 | + $id = esc_attr($args['id']); |
|
537 | 537 | |
538 | - getpaid_hidden_field( "wpinv_settings[$id]", '0' ); |
|
538 | + getpaid_hidden_field("wpinv_settings[$id]", '0'); |
|
539 | 539 | ?> |
540 | 540 | <label> |
541 | - <input id="wpinv-settings-<?php echo esc_attr( $id ); ?>" name="wpinv_settings[<?php echo esc_attr( $id ); ?>]" <?php checked( empty( $std ), false ); ?> value="1" type="checkbox" /> |
|
542 | - <?php echo wp_kses_post( $args['desc'] ); ?> |
|
541 | + <input id="wpinv-settings-<?php echo esc_attr($id); ?>" name="wpinv_settings[<?php echo esc_attr($id); ?>]" <?php checked(empty($std), false); ?> value="1" type="checkbox" /> |
|
542 | + <?php echo wp_kses_post($args['desc']); ?> |
|
543 | 543 | </label> |
544 | 544 | <?php |
545 | 545 | } |
546 | 546 | |
547 | -function wpinv_multicheck_callback( $args ) { |
|
547 | +function wpinv_multicheck_callback($args) { |
|
548 | 548 | |
549 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
550 | - $class = ! empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
|
549 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
550 | + $class = !empty($args['class']) ? ' ' . esc_attr($args['class']) : ''; |
|
551 | 551 | |
552 | - if ( ! empty( $args['options'] ) ) { |
|
552 | + if (!empty($args['options'])) { |
|
553 | 553 | |
554 | - $std = isset( $args['std'] ) ? $args['std'] : array(); |
|
555 | - $value = wpinv_get_option( $args['id'], $std ); |
|
554 | + $std = isset($args['std']) ? $args['std'] : array(); |
|
555 | + $value = wpinv_get_option($args['id'], $std); |
|
556 | 556 | |
557 | - echo '<div class="wpi-mcheck-rows wpi-mcheck-' . esc_attr( $sanitize_id . $class ) . '">'; |
|
558 | - foreach ( $args['options'] as $key => $option ) : |
|
559 | - $sanitize_key = esc_attr( wpinv_sanitize_key( $key ) ); |
|
560 | - if ( in_array( $sanitize_key, $value ) ) { |
|
557 | + echo '<div class="wpi-mcheck-rows wpi-mcheck-' . esc_attr($sanitize_id . $class) . '">'; |
|
558 | + foreach ($args['options'] as $key => $option) : |
|
559 | + $sanitize_key = esc_attr(wpinv_sanitize_key($key)); |
|
560 | + if (in_array($sanitize_key, $value)) { |
|
561 | 561 | $enabled = $sanitize_key; |
562 | 562 | } else { |
563 | 563 | $enabled = null; |
564 | 564 | } |
565 | - echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" id="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/> '; |
|
566 | - echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']">' . wp_kses_post( $option ) . '</label></div>'; |
|
565 | + echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . esc_attr($sanitize_id) . '][' . esc_attr($sanitize_key) . ']" id="wpinv_settings[' . esc_attr($sanitize_id) . '][' . esc_attr($sanitize_key) . ']" type="checkbox" value="' . esc_attr($sanitize_key) . '" ' . checked($sanitize_key, $enabled, false) . '/> '; |
|
566 | + echo '<label for="wpinv_settings[' . esc_attr($sanitize_id) . '][' . esc_attr($sanitize_key) . ']">' . wp_kses_post($option) . '</label></div>'; |
|
567 | 567 | endforeach; |
568 | 568 | echo '</div>'; |
569 | - echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
569 | + echo '<p class="description">' . wp_kses_post($args['desc']) . '</p>'; |
|
570 | 570 | } |
571 | 571 | } |
572 | 572 | |
573 | -function wpinv_payment_icons_callback( $args ) { |
|
573 | +function wpinv_payment_icons_callback($args) { |
|
574 | 574 | |
575 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
576 | - $value = wpinv_get_option( $args['id'], false ); |
|
575 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
576 | + $value = wpinv_get_option($args['id'], false); |
|
577 | 577 | |
578 | - if ( ! empty( $args['options'] ) ) { |
|
579 | - foreach ( $args['options'] as $key => $option ) { |
|
580 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
578 | + if (!empty($args['options'])) { |
|
579 | + foreach ($args['options'] as $key => $option) { |
|
580 | + $sanitize_key = wpinv_sanitize_key($key); |
|
581 | 581 | |
582 | - if ( empty( $value ) ) { |
|
582 | + if (empty($value)) { |
|
583 | 583 | $enabled = $option; |
584 | 584 | } else { |
585 | 585 | $enabled = null; |
586 | 586 | } |
587 | 587 | |
588 | - echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">'; |
|
588 | + echo '<label for="wpinv_settings[' . esc_attr($sanitize_id) . '][' . esc_attr($sanitize_key) . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">'; |
|
589 | 589 | |
590 | - echo '<input name="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" id="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/> '; |
|
590 | + echo '<input name="wpinv_settings[' . esc_attr($sanitize_id) . '][' . esc_attr($sanitize_key) . ']" id="wpinv_settings[' . esc_attr($sanitize_id) . '][' . esc_attr($sanitize_key) . ']" type="checkbox" value="' . esc_attr($option) . '" ' . checked($option, $enabled, false) . '/> '; |
|
591 | 591 | |
592 | - if ( wpinv_string_is_image_url( $key ) ) { |
|
593 | - echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
592 | + if (wpinv_string_is_image_url($key)) { |
|
593 | + echo '<img class="payment-icon" src="' . esc_url($key) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
594 | 594 | } else { |
595 | - $card = strtolower( str_replace( ' ', '', $option ) ); |
|
595 | + $card = strtolower(str_replace(' ', '', $option)); |
|
596 | 596 | |
597 | - if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) { |
|
598 | - $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' ); |
|
597 | + if (has_filter('wpinv_accepted_payment_' . $card . '_image')) { |
|
598 | + $image = apply_filters('wpinv_accepted_payment_' . $card . '_image', ''); |
|
599 | 599 | } else { |
600 | - $image = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false ); |
|
600 | + $image = wpinv_locate_template('images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false); |
|
601 | 601 | $content_dir = WP_CONTENT_DIR; |
602 | 602 | |
603 | - if ( function_exists( 'wp_normalize_path' ) ) { |
|
603 | + if (function_exists('wp_normalize_path')) { |
|
604 | 604 | // Replaces backslashes with forward slashes for Windows systems |
605 | - $image = wp_normalize_path( $image ); |
|
606 | - $content_dir = wp_normalize_path( $content_dir ); |
|
605 | + $image = wp_normalize_path($image); |
|
606 | + $content_dir = wp_normalize_path($content_dir); |
|
607 | 607 | } |
608 | 608 | |
609 | - $image = str_replace( $content_dir, content_url(), $image ); |
|
609 | + $image = str_replace($content_dir, content_url(), $image); |
|
610 | 610 | } |
611 | 611 | |
612 | - echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
612 | + echo '<img class="payment-icon" src="' . esc_url($image) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
613 | 613 | } |
614 | - echo wp_kses_post( $option ) . '</label>'; |
|
614 | + echo wp_kses_post($option) . '</label>'; |
|
615 | 615 | } |
616 | - echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
616 | + echo '<p class="description" style="margin-top:16px;">' . wp_kses_post($args['desc']) . '</p>'; |
|
617 | 617 | } |
618 | 618 | } |
619 | 619 | |
620 | 620 | /** |
621 | 621 | * Displays a radio settings field. |
622 | 622 | */ |
623 | -function wpinv_radio_callback( $args ) { |
|
623 | +function wpinv_radio_callback($args) { |
|
624 | 624 | |
625 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
626 | - $std = wpinv_get_option( $args['id'], $std ); |
|
625 | + $std = isset($args['std']) ? $args['std'] : ''; |
|
626 | + $std = wpinv_get_option($args['id'], $std); |
|
627 | 627 | ?> |
628 | 628 | <fieldset> |
629 | - <ul id="wpinv-settings-<?php echo esc_attr( $args['id'] ); ?>" style="margin-top: 0;"> |
|
630 | - <?php foreach ( $args['options'] as $key => $option ) : ?> |
|
629 | + <ul id="wpinv-settings-<?php echo esc_attr($args['id']); ?>" style="margin-top: 0;"> |
|
630 | + <?php foreach ($args['options'] as $key => $option) : ?> |
|
631 | 631 | <li> |
632 | 632 | <label> |
633 | - <input name="wpinv_settings[<?php echo esc_attr( $args['id'] ); ?>]" <?php checked( $std, $key ); ?> value="<?php echo esc_attr( $key ); ?>" type="radio"> |
|
634 | - <?php echo wp_kses_post( $option ); ?> |
|
633 | + <input name="wpinv_settings[<?php echo esc_attr($args['id']); ?>]" <?php checked($std, $key); ?> value="<?php echo esc_attr($key); ?>" type="radio"> |
|
634 | + <?php echo wp_kses_post($option); ?> |
|
635 | 635 | </label> |
636 | 636 | </li> |
637 | 637 | <?php endforeach; ?> |
638 | 638 | </ul> |
639 | 639 | </fieldset> |
640 | 640 | <?php |
641 | - getpaid_settings_description_callback( $args ); |
|
641 | + getpaid_settings_description_callback($args); |
|
642 | 642 | } |
643 | 643 | |
644 | 644 | /** |
645 | 645 | * Displays a description if available. |
646 | 646 | */ |
647 | -function getpaid_settings_description_callback( $args ) { |
|
647 | +function getpaid_settings_description_callback($args) { |
|
648 | 648 | |
649 | - if ( ! empty( $args['desc'] ) ) { |
|
649 | + if (!empty($args['desc'])) { |
|
650 | 650 | $description = $args['desc']; |
651 | - echo wp_kses_post( "<p class='description'>$description</p>" ); |
|
651 | + echo wp_kses_post("<p class='description'>$description</p>"); |
|
652 | 652 | } |
653 | 653 | |
654 | 654 | } |
@@ -663,35 +663,35 @@ discard block |
||
663 | 663 | </tr> |
664 | 664 | <tr class="bsui"> |
665 | 665 | <td colspan="2" class="p-0"> |
666 | - <?php include plugin_dir_path( __FILE__ ) . 'views/html-gateways-edit.php'; ?> |
|
666 | + <?php include plugin_dir_path(__FILE__) . 'views/html-gateways-edit.php'; ?> |
|
667 | 667 | |
668 | 668 | <?php |
669 | 669 | } |
670 | 670 | |
671 | -function wpinv_gateway_select_callback( $args ) { |
|
671 | +function wpinv_gateway_select_callback($args) { |
|
672 | 672 | |
673 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
674 | - $class = ! empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
|
675 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
676 | - $value = wpinv_get_option( $args['id'], $std ); |
|
673 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
674 | + $class = !empty($args['class']) ? ' ' . esc_attr($args['class']) : ''; |
|
675 | + $std = isset($args['std']) ? $args['std'] : ''; |
|
676 | + $value = wpinv_get_option($args['id'], $std); |
|
677 | 677 | |
678 | - echo '<select name="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" class="' . esc_attr( $class ) . '" >'; |
|
678 | + echo '<select name="wpinv_settings[' . esc_attr($sanitize_id) . ']"" id="wpinv_settings[' . esc_attr($sanitize_id) . ']" class="' . esc_attr($class) . '" >'; |
|
679 | 679 | |
680 | - foreach ( $args['options'] as $key => $option ) : |
|
680 | + foreach ($args['options'] as $key => $option) : |
|
681 | 681 | |
682 | - echo '<option value="' . esc_attr( $key ) . '" '; |
|
682 | + echo '<option value="' . esc_attr($key) . '" '; |
|
683 | 683 | |
684 | - if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
685 | - selected( $key, $args['selected'] ); |
|
684 | + if (isset($args['selected']) && $args['selected'] !== null && $args['selected'] !== false) { |
|
685 | + selected($key, $args['selected']); |
|
686 | 686 | } else { |
687 | - selected( $key, $value ); |
|
687 | + selected($key, $value); |
|
688 | 688 | } |
689 | 689 | |
690 | - echo '>' . esc_html( $option['admin_label'] ) . '</option>'; |
|
690 | + echo '>' . esc_html($option['admin_label']) . '</option>'; |
|
691 | 691 | endforeach; |
692 | 692 | |
693 | 693 | echo '</select>'; |
694 | - echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
694 | + echo '<label for="wpinv_settings[' . esc_attr($sanitize_id) . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
695 | 695 | } |
696 | 696 | |
697 | 697 | /** |
@@ -700,16 +700,16 @@ discard block |
||
700 | 700 | * @param array $args |
701 | 701 | * @return string |
702 | 702 | */ |
703 | -function wpinv_settings_attrs_helper( $args ) { |
|
703 | +function wpinv_settings_attrs_helper($args) { |
|
704 | 704 | |
705 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
706 | - $id = esc_attr( $args['id'] ); |
|
707 | - $value = is_scalar( $value ) ? $value : ''; |
|
705 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
706 | + $id = esc_attr($args['id']); |
|
707 | + $value = is_scalar($value) ? $value : ''; |
|
708 | 708 | |
709 | 709 | $attrs = array( |
710 | - 'name' => ! empty( $args['faux'] ) ? false : "wpinv_settings[$id]", |
|
711 | - 'readonly' => ! empty( $args['faux'] ), |
|
712 | - 'value' => ! empty( $args['faux'] ) ? $value : wpinv_get_option( $args['id'], $value ), |
|
710 | + 'name' => !empty($args['faux']) ? false : "wpinv_settings[$id]", |
|
711 | + 'readonly' => !empty($args['faux']), |
|
712 | + 'value' => !empty($args['faux']) ? $value : wpinv_get_option($args['id'], $value), |
|
713 | 713 | 'id' => 'wpinv-settings-' . $args['id'], |
714 | 714 | 'style' => $args['style'], |
715 | 715 | 'class' => $args['class'], |
@@ -717,20 +717,20 @@ discard block |
||
717 | 717 | 'data-placeholder' => $args['placeholder'], |
718 | 718 | ); |
719 | 719 | |
720 | - if ( ! empty( $args['onchange'] ) ) { |
|
720 | + if (!empty($args['onchange'])) { |
|
721 | 721 | $attrs['onchange'] = $args['onchange']; |
722 | 722 | } |
723 | 723 | |
724 | - foreach ( $attrs as $key => $value ) { |
|
724 | + foreach ($attrs as $key => $value) { |
|
725 | 725 | |
726 | - if ( false === $value ) { |
|
726 | + if (false === $value) { |
|
727 | 727 | continue; |
728 | 728 | } |
729 | 729 | |
730 | - if ( true === $value ) { |
|
731 | - echo ' ' . esc_attr( $key ); |
|
730 | + if (true === $value) { |
|
731 | + echo ' ' . esc_attr($key); |
|
732 | 732 | } else { |
733 | - echo ' ' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"'; |
|
733 | + echo ' ' . esc_attr($key) . '="' . esc_attr($value) . '"'; |
|
734 | 734 | } |
735 | 735 | |
736 | 736 | } |
@@ -740,12 +740,12 @@ discard block |
||
740 | 740 | /** |
741 | 741 | * Displays a text input settings callback. |
742 | 742 | */ |
743 | -function wpinv_text_callback( $args ) { |
|
743 | +function wpinv_text_callback($args) { |
|
744 | 744 | |
745 | 745 | ?> |
746 | 746 | <label style="width: 100%;"> |
747 | - <input type="text" <?php wpinv_settings_attrs_helper( $args ); ?>> |
|
748 | - <?php getpaid_settings_description_callback( $args ); ?> |
|
747 | + <input type="text" <?php wpinv_settings_attrs_helper($args); ?>> |
|
748 | + <?php getpaid_settings_description_callback($args); ?> |
|
749 | 749 | </label> |
750 | 750 | <?php |
751 | 751 | |
@@ -754,174 +754,174 @@ discard block |
||
754 | 754 | /** |
755 | 755 | * Displays a number input settings callback. |
756 | 756 | */ |
757 | -function wpinv_number_callback( $args ) { |
|
757 | +function wpinv_number_callback($args) { |
|
758 | 758 | |
759 | 759 | ?> |
760 | 760 | <label style="width: 100%;"> |
761 | - <input type="number" step="<?php echo esc_attr( $args['step'] ); ?>" max="<?php echo intval( $args['max'] ); ?>" min="<?php echo intval( $args['min'] ); ?>" <?php wpinv_settings_attrs_helper( $args ); ?>> |
|
762 | - <?php getpaid_settings_description_callback( $args ); ?> |
|
761 | + <input type="number" step="<?php echo esc_attr($args['step']); ?>" max="<?php echo intval($args['max']); ?>" min="<?php echo intval($args['min']); ?>" <?php wpinv_settings_attrs_helper($args); ?>> |
|
762 | + <?php getpaid_settings_description_callback($args); ?> |
|
763 | 763 | </label> |
764 | 764 | <?php |
765 | 765 | |
766 | 766 | } |
767 | 767 | |
768 | -function wpinv_textarea_callback( $args ) { |
|
768 | +function wpinv_textarea_callback($args) { |
|
769 | 769 | |
770 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
771 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
772 | - $value = wpinv_get_option( $args['id'], $std ); |
|
770 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
771 | + $std = isset($args['std']) ? $args['std'] : ''; |
|
772 | + $value = wpinv_get_option($args['id'], $std); |
|
773 | 773 | |
774 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
775 | - $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text'; |
|
774 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
775 | + $class = (isset($args['class']) && !is_null($args['class'])) ? $args['class'] : 'large-text'; |
|
776 | 776 | |
777 | - echo '<textarea class="' . esc_attr( $class ) . ' txtarea-' . esc_attr( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . esc_attr( $args['cols'] ) . '" rows="' . esc_attr( $args['rows'] ) . '" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
778 | - echo '<br /><label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
777 | + echo '<textarea class="' . esc_attr($class) . ' txtarea-' . esc_attr($size) . ' wpi-' . esc_attr(sanitize_html_class($sanitize_id)) . ' " cols="' . esc_attr($args['cols']) . '" rows="' . esc_attr($args['rows']) . '" id="wpinv_settings[' . esc_attr($sanitize_id) . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']">' . esc_textarea(stripslashes($value)) . '</textarea>'; |
|
778 | + echo '<br /><label for="wpinv_settings[' . esc_attr($sanitize_id) . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
779 | 779 | |
780 | 780 | } |
781 | 781 | |
782 | -function wpinv_password_callback( $args ) { |
|
782 | +function wpinv_password_callback($args) { |
|
783 | 783 | |
784 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
785 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
786 | - $value = wpinv_get_option( $args['id'], $std ); |
|
784 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
785 | + $std = isset($args['std']) ? $args['std'] : ''; |
|
786 | + $value = wpinv_get_option($args['id'], $std); |
|
787 | 787 | |
788 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
789 | - echo '<input type="password" class="' . esc_attr( $size ) . '-text" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>'; |
|
790 | - echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
788 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
789 | + echo '<input type="password" class="' . esc_attr($size) . '-text" id="wpinv_settings[' . esc_attr($sanitize_id) . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr($value) . '"/>'; |
|
790 | + echo '<label for="wpinv_settings[' . esc_attr($sanitize_id) . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
791 | 791 | |
792 | 792 | } |
793 | 793 | |
794 | -function wpinv_missing_callback( $args ) { |
|
794 | +function wpinv_missing_callback($args) { |
|
795 | 795 | printf( |
796 | - esc_html__( 'The callback function used for the %s setting is missing.', 'invoicing' ), |
|
797 | - '<strong>' . esc_html( $args['id'] ) . '</strong>' |
|
796 | + esc_html__('The callback function used for the %s setting is missing.', 'invoicing'), |
|
797 | + '<strong>' . esc_html($args['id']) . '</strong>' |
|
798 | 798 | ); |
799 | 799 | } |
800 | 800 | |
801 | 801 | /** |
802 | 802 | * Displays a number input settings callback. |
803 | 803 | */ |
804 | -function wpinv_select_callback( $args ) { |
|
804 | +function wpinv_select_callback($args) { |
|
805 | 805 | |
806 | - $desc = wp_kses_post( $args['desc'] ); |
|
807 | - $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>"; |
|
808 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
809 | - $value = wpinv_get_option( $args['id'], $value ); |
|
810 | - $rand = uniqid( 'random_id' ); |
|
806 | + $desc = wp_kses_post($args['desc']); |
|
807 | + $desc = empty($desc) ? '' : "<p class='description'>$desc</p>"; |
|
808 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
809 | + $value = wpinv_get_option($args['id'], $value); |
|
810 | + $rand = uniqid('random_id'); |
|
811 | 811 | |
812 | 812 | ?> |
813 | 813 | <label style="width: 100%;"> |
814 | - <select <?php wpinv_settings_attrs_helper( $args ); ?> data-allow-clear="true"> |
|
815 | - <?php foreach ( $args['options'] as $option => $name ) : ?> |
|
816 | - <option value="<?php echo esc_attr( $option ); ?>" <?php echo selected( $option, $value ); ?>><?php echo esc_html( $name ); ?></option> |
|
814 | + <select <?php wpinv_settings_attrs_helper($args); ?> data-allow-clear="true"> |
|
815 | + <?php foreach ($args['options'] as $option => $name) : ?> |
|
816 | + <option value="<?php echo esc_attr($option); ?>" <?php echo selected($option, $value); ?>><?php echo esc_html($name); ?></option> |
|
817 | 817 | <?php endforeach; ?> |
818 | 818 | </select> |
819 | 819 | |
820 | - <?php if ( substr( $args['id'], -5 ) === '_page' && is_numeric( $value ) ) : ?> |
|
821 | - <a href="<?php echo esc_url( get_edit_post_link( $value ) ); ?>" target="_blank" class="button getpaid-page-setting-edit"><?php esc_html_e( 'Edit Page', 'invoicing' ); ?></a> |
|
820 | + <?php if (substr($args['id'], -5) === '_page' && is_numeric($value)) : ?> |
|
821 | + <a href="<?php echo esc_url(get_edit_post_link($value)); ?>" target="_blank" class="button getpaid-page-setting-edit"><?php esc_html_e('Edit Page', 'invoicing'); ?></a> |
|
822 | 822 | <?php endif; ?> |
823 | 823 | |
824 | - <?php if ( substr( $args['id'], -5 ) === '_page' && ! empty( $args['default_content'] ) ) : ?> |
|
825 | - <a href="#TB_inline?&width=400&height=550&inlineId=<?php echo esc_attr( $rand ); ?>" class="button thickbox getpaid-page-setting-view-default"><?php esc_html_e( 'View Default Content', 'invoicing' ); ?></a> |
|
826 | - <div id='<?php echo esc_attr( $rand ); ?>' style='display:none;'> |
|
824 | + <?php if (substr($args['id'], -5) === '_page' && !empty($args['default_content'])) : ?> |
|
825 | + <a href="#TB_inline?&width=400&height=550&inlineId=<?php echo esc_attr($rand); ?>" class="button thickbox getpaid-page-setting-view-default"><?php esc_html_e('View Default Content', 'invoicing'); ?></a> |
|
826 | + <div id='<?php echo esc_attr($rand); ?>' style='display:none;'> |
|
827 | 827 | <div> |
828 | - <h3><?php esc_html_e( 'Original Content', 'invoicing' ); ?></h3> |
|
829 | - <textarea readonly onclick="this.select()" rows="8" style="width: 100%;"><?php echo wp_kses_post( gepaid_trim_lines( $args['default_content'] ) ); ?></textarea> |
|
830 | - <h3><?php esc_html_e( 'Current Content', 'invoicing' ); ?></h3> |
|
831 | - <textarea readonly onclick="this.select()" rows="8" style="width: 100%;"><?php $_post = get_post( $value ); echo empty( $_post ) ? '' : wp_kses_post( gepaid_trim_lines( $_post->post_content ) ); ?></textarea> |
|
828 | + <h3><?php esc_html_e('Original Content', 'invoicing'); ?></h3> |
|
829 | + <textarea readonly onclick="this.select()" rows="8" style="width: 100%;"><?php echo wp_kses_post(gepaid_trim_lines($args['default_content'])); ?></textarea> |
|
830 | + <h3><?php esc_html_e('Current Content', 'invoicing'); ?></h3> |
|
831 | + <textarea readonly onclick="this.select()" rows="8" style="width: 100%;"><?php $_post = get_post($value); echo empty($_post) ? '' : wp_kses_post(gepaid_trim_lines($_post->post_content)); ?></textarea> |
|
832 | 832 | </div> |
833 | 833 | </div> |
834 | 834 | <?php endif; ?> |
835 | 835 | |
836 | - <?php echo wp_kses_post( $desc ); ?> |
|
836 | + <?php echo wp_kses_post($desc); ?> |
|
837 | 837 | </label> |
838 | 838 | <?php |
839 | 839 | |
840 | 840 | } |
841 | 841 | |
842 | -function wpinv_color_select_callback( $args ) { |
|
842 | +function wpinv_color_select_callback($args) { |
|
843 | 843 | |
844 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
845 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
846 | - $value = wpinv_get_option( $args['id'], $std ); |
|
844 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
845 | + $std = isset($args['std']) ? $args['std'] : ''; |
|
846 | + $value = wpinv_get_option($args['id'], $std); |
|
847 | 847 | |
848 | - echo '<select id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>'; |
|
848 | + echo '<select id="wpinv_settings[' . esc_attr($sanitize_id) . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']"/>'; |
|
849 | 849 | |
850 | - foreach ( $args['options'] as $option => $color ) { |
|
851 | - echo '<option value="' . esc_attr( $option ) . '" ' . selected( $option, $value ) . '>' . esc_html( $color['label'] ) . '</option>'; |
|
850 | + foreach ($args['options'] as $option => $color) { |
|
851 | + echo '<option value="' . esc_attr($option) . '" ' . selected($option, $value) . '>' . esc_html($color['label']) . '</option>'; |
|
852 | 852 | } |
853 | 853 | |
854 | 854 | echo '</select>'; |
855 | - echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
855 | + echo '<label for="wpinv_settings[' . esc_attr($sanitize_id) . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
856 | 856 | |
857 | 857 | } |
858 | 858 | |
859 | -function wpinv_rich_editor_callback( $args ) { |
|
859 | +function wpinv_rich_editor_callback($args) { |
|
860 | 860 | global $wp_version; |
861 | 861 | |
862 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
862 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
863 | 863 | |
864 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
865 | - $value = wpinv_get_option( $args['id'], $std ); |
|
864 | + $std = isset($args['std']) ? $args['std'] : ''; |
|
865 | + $value = wpinv_get_option($args['id'], $std); |
|
866 | 866 | |
867 | - if ( ! empty( $args['allow_blank'] ) && empty( $value ) ) { |
|
867 | + if (!empty($args['allow_blank']) && empty($value)) { |
|
868 | 868 | $value = $std; |
869 | 869 | } |
870 | 870 | |
871 | - $rows = isset( $args['size'] ) ? $args['size'] : 20; |
|
871 | + $rows = isset($args['size']) ? $args['size'] : 20; |
|
872 | 872 | |
873 | 873 | echo '<div class="getpaid-settings-editor-input">'; |
874 | - if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) { |
|
874 | + if ($wp_version >= 3.3 && function_exists('wp_editor')) { |
|
875 | 875 | wp_editor( |
876 | - stripslashes( $value ), |
|
877 | - 'wpinv_settings_' . esc_attr( $args['id'] ), |
|
876 | + stripslashes($value), |
|
877 | + 'wpinv_settings_' . esc_attr($args['id']), |
|
878 | 878 | array( |
879 | - 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', |
|
880 | - 'textarea_rows' => absint( $rows ), |
|
879 | + 'textarea_name' => 'wpinv_settings[' . esc_attr($args['id']) . ']', |
|
880 | + 'textarea_rows' => absint($rows), |
|
881 | 881 | 'media_buttons' => false, |
882 | 882 | ) |
883 | 883 | ); |
884 | 884 | } else { |
885 | - echo '<textarea class="large-text" rows="10" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
885 | + echo '<textarea class="large-text" rows="10" id="wpinv_settings[' . esc_attr($sanitize_id) . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" class="wpi-' . esc_attr(sanitize_html_class($args['id'])) . '">' . esc_textarea(stripslashes($value)) . '</textarea>'; |
|
886 | 886 | } |
887 | 887 | |
888 | - echo '</div><br/><label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
888 | + echo '</div><br/><label for="wpinv_settings[' . esc_attr($sanitize_id) . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
889 | 889 | |
890 | 890 | } |
891 | 891 | |
892 | -function wpinv_upload_callback( $args ) { |
|
892 | +function wpinv_upload_callback($args) { |
|
893 | 893 | |
894 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
894 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
895 | 895 | |
896 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
897 | - $value = wpinv_get_option( $args['id'], $std ); |
|
896 | + $std = isset($args['std']) ? $args['std'] : ''; |
|
897 | + $value = wpinv_get_option($args['id'], $std); |
|
898 | 898 | |
899 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
900 | - echo '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
901 | - echo '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . esc_attr__( 'Upload File', 'invoicing' ) . '"/></span>'; |
|
902 | - echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
899 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
900 | + echo '<input type="text" class="' . sanitize_html_class($size) . '-text" id="wpinv_settings[' . esc_attr($sanitize_id) . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr(stripslashes($value)) . '"/>'; |
|
901 | + echo '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . esc_attr__('Upload File', 'invoicing') . '"/></span>'; |
|
902 | + echo '<label for="wpinv_settings[' . esc_attr($sanitize_id) . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
903 | 903 | |
904 | 904 | } |
905 | 905 | |
906 | -function wpinv_color_callback( $args ) { |
|
906 | +function wpinv_color_callback($args) { |
|
907 | 907 | |
908 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
909 | - $value = wpinv_get_option( $args['id'], $std ); |
|
910 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
908 | + $std = isset($args['std']) ? $args['std'] : ''; |
|
909 | + $value = wpinv_get_option($args['id'], $std); |
|
910 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
911 | 911 | |
912 | - echo '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $std ) . '" />'; |
|
913 | - echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
912 | + echo '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . esc_attr($sanitize_id) . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr($value) . '" data-default-color="' . esc_attr($std) . '" />'; |
|
913 | + echo '<label for="wpinv_settings[' . esc_attr($sanitize_id) . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
914 | 914 | |
915 | 915 | } |
916 | 916 | |
917 | -function wpinv_country_states_callback( $args ) { |
|
917 | +function wpinv_country_states_callback($args) { |
|
918 | 918 | |
919 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
920 | - $value = wpinv_get_option( $args['id'], $std ); |
|
919 | + $std = isset($args['std']) ? $args['std'] : ''; |
|
920 | + $value = wpinv_get_option($args['id'], $std); |
|
921 | 921 | |
922 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
922 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
923 | 923 | |
924 | - if ( isset( $args['placeholder'] ) ) { |
|
924 | + if (isset($args['placeholder'])) { |
|
925 | 925 | $placeholder = $args['placeholder']; |
926 | 926 | } else { |
927 | 927 | $placeholder = ''; |
@@ -929,15 +929,15 @@ discard block |
||
929 | 929 | |
930 | 930 | $states = wpinv_get_country_states(); |
931 | 931 | |
932 | - $class = empty( $states ) ? 'wpinv-no-states' : 'wpi_select2'; |
|
933 | - echo '<select id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="' . esc_attr( $class ) . '" data-placeholder="' . esc_html( $placeholder ) . '"/>'; |
|
932 | + $class = empty($states) ? 'wpinv-no-states' : 'wpi_select2'; |
|
933 | + echo '<select id="wpinv_settings[' . esc_attr($sanitize_id) . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" class="' . esc_attr($class) . '" data-placeholder="' . esc_html($placeholder) . '"/>'; |
|
934 | 934 | |
935 | - foreach ( $states as $option => $name ) { |
|
936 | - echo '<option value="' . esc_attr( $option ) . '" ' . selected( $option, $value ) . '>' . esc_html( $name ) . '</option>'; |
|
935 | + foreach ($states as $option => $name) { |
|
936 | + echo '<option value="' . esc_attr($option) . '" ' . selected($option, $value) . '>' . esc_html($name) . '</option>'; |
|
937 | 937 | } |
938 | 938 | |
939 | 939 | echo '</select>'; |
940 | - echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
940 | + echo '<label for="wpinv_settings[' . esc_attr($sanitize_id) . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
941 | 941 | |
942 | 942 | } |
943 | 943 | |
@@ -951,7 +951,7 @@ discard block |
||
951 | 951 | </tr> |
952 | 952 | <tr class="bsui"> |
953 | 953 | <td colspan="2" class="p-0"> |
954 | - <?php include plugin_dir_path( __FILE__ ) . 'views/html-tax-rates-edit.php'; ?> |
|
954 | + <?php include plugin_dir_path(__FILE__) . 'views/html-tax-rates-edit.php'; ?> |
|
955 | 955 | |
956 | 956 | <?php |
957 | 957 | |
@@ -960,11 +960,11 @@ discard block |
||
960 | 960 | /** |
961 | 961 | * Displays a tax rate' edit row. |
962 | 962 | */ |
963 | -function wpinv_tax_rate_callback( $tax_rate, $key ) { |
|
963 | +function wpinv_tax_rate_callback($tax_rate, $key) { |
|
964 | 964 | |
965 | - $key = sanitize_key( $key ); |
|
966 | - $tax_rate['reduced_rate'] = empty( $tax_rate['reduced_rate'] ) ? 0 : $tax_rate['reduced_rate']; |
|
967 | - include plugin_dir_path( __FILE__ ) . 'views/html-tax-rate-edit.php'; |
|
965 | + $key = sanitize_key($key); |
|
966 | + $tax_rate['reduced_rate'] = empty($tax_rate['reduced_rate']) ? 0 : $tax_rate['reduced_rate']; |
|
967 | + include plugin_dir_path(__FILE__) . 'views/html-tax-rate-edit.php'; |
|
968 | 968 | |
969 | 969 | } |
970 | 970 | |
@@ -978,177 +978,177 @@ discard block |
||
978 | 978 | </tr> |
979 | 979 | <tr class="bsui"> |
980 | 980 | <td colspan="2" class="p-0"> |
981 | - <?php include plugin_dir_path( __FILE__ ) . 'views/html-tax-rules-edit.php'; ?> |
|
981 | + <?php include plugin_dir_path(__FILE__) . 'views/html-tax-rules-edit.php'; ?> |
|
982 | 982 | |
983 | 983 | <?php |
984 | 984 | |
985 | 985 | } |
986 | 986 | |
987 | -function wpinv_tools_callback( $args ) { |
|
987 | +function wpinv_tools_callback($args) { |
|
988 | 988 | ?> |
989 | 989 | </td><tr> |
990 | 990 | <td colspan="2" class="wpinv_tools_tdbox"> |
991 | 991 | <?php |
992 | - if ( $args['desc'] ) { |
|
992 | + if ($args['desc']) { |
|
993 | 993 | ?> |
994 | -<p><?php echo wp_kses_post( $args['desc'] ); ?></p><?php } ?> |
|
995 | - <?php do_action( 'wpinv_tools_before' ); ?> |
|
994 | +<p><?php echo wp_kses_post($args['desc']); ?></p><?php } ?> |
|
995 | + <?php do_action('wpinv_tools_before'); ?> |
|
996 | 996 | <table id="wpinv_tools_table" class="wp-list-table widefat fixed posts"> |
997 | 997 | <thead> |
998 | 998 | <tr> |
999 | - <th scope="col" class="wpinv-th-tool"><?php esc_html_e( 'Tool', 'invoicing' ); ?></th> |
|
1000 | - <th scope="col" class="wpinv-th-desc"><?php esc_html_e( 'Description', 'invoicing' ); ?></th> |
|
1001 | - <th scope="col" class="wpinv-th-action"><?php esc_html_e( 'Action', 'invoicing' ); ?></th> |
|
999 | + <th scope="col" class="wpinv-th-tool"><?php esc_html_e('Tool', 'invoicing'); ?></th> |
|
1000 | + <th scope="col" class="wpinv-th-desc"><?php esc_html_e('Description', 'invoicing'); ?></th> |
|
1001 | + <th scope="col" class="wpinv-th-action"><?php esc_html_e('Action', 'invoicing'); ?></th> |
|
1002 | 1002 | </tr> |
1003 | 1003 | </thead> |
1004 | 1004 | |
1005 | 1005 | <tbody> |
1006 | 1006 | <tr> |
1007 | - <td><?php esc_html_e( 'Check Pages', 'invoicing' ); ?></td> |
|
1007 | + <td><?php esc_html_e('Check Pages', 'invoicing'); ?></td> |
|
1008 | 1008 | <td> |
1009 | - <small><?php esc_html_e( 'Creates any missing GetPaid pages.', 'invoicing' ); ?></small> |
|
1009 | + <small><?php esc_html_e('Creates any missing GetPaid pages.', 'invoicing'); ?></small> |
|
1010 | 1010 | </td> |
1011 | 1011 | <td> |
1012 | 1012 | <a href=" |
1013 | 1013 | <?php |
1014 | 1014 | echo esc_url( |
1015 | 1015 | wp_nonce_url( |
1016 | - add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
1016 | + add_query_arg('getpaid-admin-action', 'create_missing_pages'), |
|
1017 | 1017 | 'getpaid-nonce', |
1018 | 1018 | 'getpaid-nonce' |
1019 | 1019 | ) |
1020 | 1020 | ); |
1021 | 1021 | ?> |
1022 | - " class="button button-primary"><?php esc_html_e( 'Run', 'invoicing' ); ?></a> |
|
1022 | + " class="button button-primary"><?php esc_html_e('Run', 'invoicing'); ?></a> |
|
1023 | 1023 | </td> |
1024 | 1024 | </tr> |
1025 | 1025 | <tr> |
1026 | - <td><?php esc_html_e( 'Refresh Permalinks', 'invoicing' ); ?></td> |
|
1026 | + <td><?php esc_html_e('Refresh Permalinks', 'invoicing'); ?></td> |
|
1027 | 1027 | <td> |
1028 | - <small><?php esc_html_e( 'Might fix the page not found error when viewing an invoice.', 'invoicing' ); ?></small> |
|
1028 | + <small><?php esc_html_e('Might fix the page not found error when viewing an invoice.', 'invoicing'); ?></small> |
|
1029 | 1029 | </td> |
1030 | 1030 | <td> |
1031 | 1031 | <a href=" |
1032 | 1032 | <?php |
1033 | 1033 | echo esc_url( |
1034 | 1034 | wp_nonce_url( |
1035 | - add_query_arg( 'getpaid-admin-action', 'refresh_permalinks' ), |
|
1035 | + add_query_arg('getpaid-admin-action', 'refresh_permalinks'), |
|
1036 | 1036 | 'getpaid-nonce', |
1037 | 1037 | 'getpaid-nonce' |
1038 | 1038 | ) |
1039 | 1039 | ); |
1040 | 1040 | ?> |
1041 | - " class="button button-primary"><?php esc_html_e( 'Run', 'invoicing' ); ?></a> |
|
1041 | + " class="button button-primary"><?php esc_html_e('Run', 'invoicing'); ?></a> |
|
1042 | 1042 | </td> |
1043 | 1043 | </tr> |
1044 | 1044 | <tr> |
1045 | - <td><?php esc_html_e( 'Repair Database Tables', 'invoicing' ); ?></td> |
|
1045 | + <td><?php esc_html_e('Repair Database Tables', 'invoicing'); ?></td> |
|
1046 | 1046 | <td> |
1047 | - <small><?php esc_html_e( 'Run this tool to create any missing database tables.', 'invoicing' ); ?></small> |
|
1047 | + <small><?php esc_html_e('Run this tool to create any missing database tables.', 'invoicing'); ?></small> |
|
1048 | 1048 | </td> |
1049 | 1049 | <td> |
1050 | 1050 | <a href=" |
1051 | 1051 | <?php |
1052 | 1052 | echo esc_url( |
1053 | 1053 | wp_nonce_url( |
1054 | - add_query_arg( 'getpaid-admin-action', 'create_missing_tables' ), |
|
1054 | + add_query_arg('getpaid-admin-action', 'create_missing_tables'), |
|
1055 | 1055 | 'getpaid-nonce', |
1056 | 1056 | 'getpaid-nonce' |
1057 | 1057 | ) |
1058 | 1058 | ); |
1059 | 1059 | ?> |
1060 | - " class="button button-primary"><?php esc_html_e( 'Run', 'invoicing' ); ?></a> |
|
1060 | + " class="button button-primary"><?php esc_html_e('Run', 'invoicing'); ?></a> |
|
1061 | 1061 | </td> |
1062 | 1062 | </tr> |
1063 | 1063 | <tr> |
1064 | - <td><?php esc_html_e( 'Migrate old invoices', 'invoicing' ); ?></td> |
|
1064 | + <td><?php esc_html_e('Migrate old invoices', 'invoicing'); ?></td> |
|
1065 | 1065 | <td> |
1066 | - <small><?php esc_html_e( 'If your old invoices were not migrated after updating from Invoicing to GetPaid, you can use this tool to migrate them.', 'invoicing' ); ?></small> |
|
1066 | + <small><?php esc_html_e('If your old invoices were not migrated after updating from Invoicing to GetPaid, you can use this tool to migrate them.', 'invoicing'); ?></small> |
|
1067 | 1067 | </td> |
1068 | 1068 | <td> |
1069 | 1069 | <a href=" |
1070 | 1070 | <?php |
1071 | 1071 | echo esc_url( |
1072 | 1072 | wp_nonce_url( |
1073 | - add_query_arg( 'getpaid-admin-action', 'migrate_old_invoices' ), |
|
1073 | + add_query_arg('getpaid-admin-action', 'migrate_old_invoices'), |
|
1074 | 1074 | 'getpaid-nonce', |
1075 | 1075 | 'getpaid-nonce' |
1076 | 1076 | ) |
1077 | 1077 | ); |
1078 | 1078 | ?> |
1079 | - " class="button button-primary"><?php esc_html_e( 'Run', 'invoicing' ); ?></a> |
|
1079 | + " class="button button-primary"><?php esc_html_e('Run', 'invoicing'); ?></a> |
|
1080 | 1080 | </td> |
1081 | 1081 | </tr> |
1082 | 1082 | |
1083 | 1083 | <tr> |
1084 | - <td><?php esc_html_e( 'Recalculate Discounts', 'invoicing' ); ?></td> |
|
1084 | + <td><?php esc_html_e('Recalculate Discounts', 'invoicing'); ?></td> |
|
1085 | 1085 | <td> |
1086 | - <small><?php esc_html_e( 'Recalculate discounts for existing invoices that have discount codes but are not discounted.', 'invoicing' ); ?></small> |
|
1086 | + <small><?php esc_html_e('Recalculate discounts for existing invoices that have discount codes but are not discounted.', 'invoicing'); ?></small> |
|
1087 | 1087 | </td> |
1088 | 1088 | <td> |
1089 | 1089 | <a href=" |
1090 | 1090 | <?php |
1091 | 1091 | echo esc_url( |
1092 | 1092 | wp_nonce_url( |
1093 | - add_query_arg( 'getpaid-admin-action', 'recalculate_discounts' ), |
|
1093 | + add_query_arg('getpaid-admin-action', 'recalculate_discounts'), |
|
1094 | 1094 | 'getpaid-nonce', |
1095 | 1095 | 'getpaid-nonce' |
1096 | 1096 | ) |
1097 | 1097 | ); |
1098 | 1098 | ?> |
1099 | - " class="button button-primary"><?php esc_html_e( 'Run', 'invoicing' ); ?></a> |
|
1099 | + " class="button button-primary"><?php esc_html_e('Run', 'invoicing'); ?></a> |
|
1100 | 1100 | </td> |
1101 | 1101 | </tr> |
1102 | 1102 | |
1103 | 1103 | <tr> |
1104 | - <td><?php esc_html_e( 'Set-up Wizard', 'invoicing' ); ?></td> |
|
1104 | + <td><?php esc_html_e('Set-up Wizard', 'invoicing'); ?></td> |
|
1105 | 1105 | <td> |
1106 | - <small><?php esc_html_e( 'Launch the quick set-up wizard.', 'invoicing' ); ?></small> |
|
1106 | + <small><?php esc_html_e('Launch the quick set-up wizard.', 'invoicing'); ?></small> |
|
1107 | 1107 | </td> |
1108 | 1108 | <td> |
1109 | 1109 | <a href=" |
1110 | 1110 | <?php |
1111 | - echo esc_url( admin_url( 'index.php?page=gp-setup' ) ); |
|
1111 | + echo esc_url(admin_url('index.php?page=gp-setup')); |
|
1112 | 1112 | ?> |
1113 | - " class="button button-primary"><?php esc_html_e( 'Launch', 'invoicing' ); ?></a> |
|
1113 | + " class="button button-primary"><?php esc_html_e('Launch', 'invoicing'); ?></a> |
|
1114 | 1114 | </td> |
1115 | 1115 | </tr> |
1116 | 1116 | |
1117 | - <?php do_action( 'wpinv_tools_row' ); ?> |
|
1117 | + <?php do_action('wpinv_tools_row'); ?> |
|
1118 | 1118 | </tbody> |
1119 | 1119 | </table> |
1120 | - <?php do_action( 'wpinv_tools_after' ); ?> |
|
1120 | + <?php do_action('wpinv_tools_after'); ?> |
|
1121 | 1121 | <?php |
1122 | 1122 | } |
1123 | 1123 | |
1124 | 1124 | |
1125 | -function wpinv_descriptive_text_callback( $args ) { |
|
1126 | - echo wp_kses_post( $args['desc'] ); |
|
1125 | +function wpinv_descriptive_text_callback($args) { |
|
1126 | + echo wp_kses_post($args['desc']); |
|
1127 | 1127 | } |
1128 | 1128 | |
1129 | -function wpinv_raw_html_callback( $args ) { |
|
1130 | - echo wp_kses( $args['desc'], getpaid_allowed_html() ); |
|
1129 | +function wpinv_raw_html_callback($args) { |
|
1130 | + echo wp_kses($args['desc'], getpaid_allowed_html()); |
|
1131 | 1131 | } |
1132 | 1132 | |
1133 | -function wpinv_hook_callback( $args ) { |
|
1134 | - do_action( 'wpinv_' . $args['id'], $args ); |
|
1133 | +function wpinv_hook_callback($args) { |
|
1134 | + do_action('wpinv_' . $args['id'], $args); |
|
1135 | 1135 | } |
1136 | 1136 | |
1137 | 1137 | function wpinv_set_settings_cap() { |
1138 | 1138 | return wpinv_get_capability(); |
1139 | 1139 | } |
1140 | -add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' ); |
|
1140 | +add_filter('option_page_capability_wpinv_settings', 'wpinv_set_settings_cap'); |
|
1141 | 1141 | |
1142 | 1142 | |
1143 | -function wpinv_on_update_settings( $old_value, $value, $option ) { |
|
1144 | - $old = ! empty( $old_value['remove_data_on_unistall'] ) ? 1 : ''; |
|
1145 | - $new = ! empty( $value['remove_data_on_unistall'] ) ? 1 : ''; |
|
1143 | +function wpinv_on_update_settings($old_value, $value, $option) { |
|
1144 | + $old = !empty($old_value['remove_data_on_unistall']) ? 1 : ''; |
|
1145 | + $new = !empty($value['remove_data_on_unistall']) ? 1 : ''; |
|
1146 | 1146 | |
1147 | - if ( $old != $new ) { |
|
1148 | - update_option( 'wpinv_remove_data_on_invoice_unistall', $new ); |
|
1147 | + if ($old != $new) { |
|
1148 | + update_option('wpinv_remove_data_on_invoice_unistall', $new); |
|
1149 | 1149 | } |
1150 | 1150 | } |
1151 | -add_action( 'update_option_wpinv_settings', 'wpinv_on_update_settings', 10, 3 ); |
|
1151 | +add_action('update_option_wpinv_settings', 'wpinv_on_update_settings', 10, 3); |
|
1152 | 1152 | |
1153 | 1153 | /** |
1154 | 1154 | * Returns the merge tags help text. |
@@ -1157,16 +1157,16 @@ discard block |
||
1157 | 1157 | * |
1158 | 1158 | * @return string |
1159 | 1159 | */ |
1160 | -function wpinv_get_merge_tags_help_text( $subscription = false ) { |
|
1160 | +function wpinv_get_merge_tags_help_text($subscription = false) { |
|
1161 | 1161 | |
1162 | 1162 | $url = $subscription ? 'https://gist.github.com/picocodes/3d213982d57c34edf7a46fd3f0e8583e' : 'https://gist.github.com/picocodes/43bdc4d4bbba844534b2722e2af0b58f'; |
1163 | 1163 | $link = sprintf( |
1164 | 1164 | '<strong><a href="%s" target="_blank">%s</a></strong>', |
1165 | 1165 | $url, |
1166 | - esc_html__( 'View available merge tags.', 'invoicing' ) |
|
1166 | + esc_html__('View available merge tags.', 'invoicing') |
|
1167 | 1167 | ); |
1168 | 1168 | |
1169 | - $description = esc_html__( 'The content of the email (Merge Tags and HTML are allowed).', 'invoicing' ); |
|
1169 | + $description = esc_html__('The content of the email (Merge Tags and HTML are allowed).', 'invoicing'); |
|
1170 | 1170 | |
1171 | 1171 | return "$description $link"; |
1172 | 1172 |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | if ( ! defined( 'ABSPATH' ) ) { |
8 | - exit; |
|
8 | + exit; |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | /** |
@@ -15,544 +15,544 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class GetPaid_Invoice_Data_Store extends GetPaid_Data_Store_WP { |
17 | 17 | |
18 | - /** |
|
19 | - * Data stored in meta keys, but not considered "meta" for a discount. |
|
20 | - * |
|
21 | - * @since 1.0.19 |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $internal_meta_keys = array( |
|
25 | - '_wpinv_subscr_profile_id', |
|
26 | - '_wpinv_subscription_id', |
|
27 | - '_wpinv_taxes', |
|
28 | - '_wpinv_fees', |
|
29 | - '_wpinv_discounts', |
|
30 | - '_wpinv_submission_id', |
|
31 | - '_wpinv_payment_form', |
|
32 | - '_wpinv_is_viewed', |
|
33 | - '_wpinv_phone', |
|
34 | - '_wpinv_company_id', |
|
35 | - 'wpinv_shipping', |
|
36 | - 'wpinv_email_cc', |
|
37 | - 'wpinv_template', |
|
38 | - 'wpinv_created_via', |
|
39 | - ); |
|
40 | - |
|
41 | - /** |
|
42 | - * A map of meta keys to data props. |
|
43 | - * |
|
44 | - * @since 1.0.19 |
|
45 | - * |
|
46 | - * @var array |
|
47 | - */ |
|
48 | - protected $meta_key_to_props = array( |
|
49 | - '_wpinv_subscr_profile_id' => 'remote_subscription_id', |
|
50 | - '_wpinv_subscription_id' => 'subscription_id', |
|
51 | - '_wpinv_taxes' => 'taxes', |
|
52 | - '_wpinv_fees' => 'fees', |
|
53 | - '_wpinv_discounts' => 'discounts', |
|
54 | - '_wpinv_submission_id' => 'submission_id', |
|
55 | - '_wpinv_payment_form' => 'payment_form', |
|
56 | - '_wpinv_is_viewed' => 'is_viewed', |
|
57 | - 'wpinv_email_cc' => 'email_cc', |
|
58 | - 'wpinv_template' => 'template', |
|
59 | - 'wpinv_created_via' => 'created_via', |
|
60 | - '_wpinv_phone' => 'phone', |
|
61 | - '_wpinv_company_id' => 'company_id', |
|
62 | - 'wpinv_shipping' => 'shipping', |
|
63 | - ); |
|
64 | - |
|
65 | - /** |
|
66 | - * A map of database fields to data props. |
|
67 | - * |
|
68 | - * @since 1.0.19 |
|
69 | - * |
|
70 | - * @var array |
|
71 | - */ |
|
72 | - protected $database_fields_to_props = array( |
|
73 | - 'post_id' => 'id', |
|
74 | - 'number' => 'number', |
|
75 | - 'currency' => 'currency', |
|
76 | - 'invoice_key' => 'key', |
|
77 | - 'type' => 'type', |
|
78 | - 'mode' => 'mode', |
|
79 | - 'user_ip' => 'user_ip', |
|
80 | - 'first_name' => 'first_name', |
|
81 | - 'last_name' => 'last_name', |
|
82 | - 'address' => 'address', |
|
83 | - 'city' => 'city', |
|
84 | - 'state' => 'state', |
|
85 | - 'country' => 'country', |
|
86 | - 'zip' => 'zip', |
|
87 | - 'zip' => 'zip', |
|
88 | - 'adddress_confirmed' => 'address_confirmed', |
|
89 | - 'gateway' => 'gateway', |
|
90 | - 'transaction_id' => 'transaction_id', |
|
91 | - 'currency' => 'currency', |
|
92 | - 'subtotal' => 'subtotal', |
|
93 | - 'tax' => 'total_tax', |
|
94 | - 'fees_total' => 'total_fees', |
|
95 | - 'discount' => 'total_discount', |
|
96 | - 'total' => 'total', |
|
97 | - 'discount_code' => 'discount_code', |
|
98 | - 'disable_taxes' => 'disable_taxes', |
|
99 | - 'due_date' => 'due_date', |
|
100 | - 'completed_date' => 'completed_date', |
|
101 | - 'company' => 'company', |
|
102 | - 'vat_number' => 'vat_number', |
|
103 | - 'vat_rate' => 'vat_rate', |
|
104 | - ); |
|
105 | - |
|
106 | - /* |
|
18 | + /** |
|
19 | + * Data stored in meta keys, but not considered "meta" for a discount. |
|
20 | + * |
|
21 | + * @since 1.0.19 |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $internal_meta_keys = array( |
|
25 | + '_wpinv_subscr_profile_id', |
|
26 | + '_wpinv_subscription_id', |
|
27 | + '_wpinv_taxes', |
|
28 | + '_wpinv_fees', |
|
29 | + '_wpinv_discounts', |
|
30 | + '_wpinv_submission_id', |
|
31 | + '_wpinv_payment_form', |
|
32 | + '_wpinv_is_viewed', |
|
33 | + '_wpinv_phone', |
|
34 | + '_wpinv_company_id', |
|
35 | + 'wpinv_shipping', |
|
36 | + 'wpinv_email_cc', |
|
37 | + 'wpinv_template', |
|
38 | + 'wpinv_created_via', |
|
39 | + ); |
|
40 | + |
|
41 | + /** |
|
42 | + * A map of meta keys to data props. |
|
43 | + * |
|
44 | + * @since 1.0.19 |
|
45 | + * |
|
46 | + * @var array |
|
47 | + */ |
|
48 | + protected $meta_key_to_props = array( |
|
49 | + '_wpinv_subscr_profile_id' => 'remote_subscription_id', |
|
50 | + '_wpinv_subscription_id' => 'subscription_id', |
|
51 | + '_wpinv_taxes' => 'taxes', |
|
52 | + '_wpinv_fees' => 'fees', |
|
53 | + '_wpinv_discounts' => 'discounts', |
|
54 | + '_wpinv_submission_id' => 'submission_id', |
|
55 | + '_wpinv_payment_form' => 'payment_form', |
|
56 | + '_wpinv_is_viewed' => 'is_viewed', |
|
57 | + 'wpinv_email_cc' => 'email_cc', |
|
58 | + 'wpinv_template' => 'template', |
|
59 | + 'wpinv_created_via' => 'created_via', |
|
60 | + '_wpinv_phone' => 'phone', |
|
61 | + '_wpinv_company_id' => 'company_id', |
|
62 | + 'wpinv_shipping' => 'shipping', |
|
63 | + ); |
|
64 | + |
|
65 | + /** |
|
66 | + * A map of database fields to data props. |
|
67 | + * |
|
68 | + * @since 1.0.19 |
|
69 | + * |
|
70 | + * @var array |
|
71 | + */ |
|
72 | + protected $database_fields_to_props = array( |
|
73 | + 'post_id' => 'id', |
|
74 | + 'number' => 'number', |
|
75 | + 'currency' => 'currency', |
|
76 | + 'invoice_key' => 'key', |
|
77 | + 'type' => 'type', |
|
78 | + 'mode' => 'mode', |
|
79 | + 'user_ip' => 'user_ip', |
|
80 | + 'first_name' => 'first_name', |
|
81 | + 'last_name' => 'last_name', |
|
82 | + 'address' => 'address', |
|
83 | + 'city' => 'city', |
|
84 | + 'state' => 'state', |
|
85 | + 'country' => 'country', |
|
86 | + 'zip' => 'zip', |
|
87 | + 'zip' => 'zip', |
|
88 | + 'adddress_confirmed' => 'address_confirmed', |
|
89 | + 'gateway' => 'gateway', |
|
90 | + 'transaction_id' => 'transaction_id', |
|
91 | + 'currency' => 'currency', |
|
92 | + 'subtotal' => 'subtotal', |
|
93 | + 'tax' => 'total_tax', |
|
94 | + 'fees_total' => 'total_fees', |
|
95 | + 'discount' => 'total_discount', |
|
96 | + 'total' => 'total', |
|
97 | + 'discount_code' => 'discount_code', |
|
98 | + 'disable_taxes' => 'disable_taxes', |
|
99 | + 'due_date' => 'due_date', |
|
100 | + 'completed_date' => 'completed_date', |
|
101 | + 'company' => 'company', |
|
102 | + 'vat_number' => 'vat_number', |
|
103 | + 'vat_rate' => 'vat_rate', |
|
104 | + ); |
|
105 | + |
|
106 | + /* |
|
107 | 107 | |-------------------------------------------------------------------------- |
108 | 108 | | CRUD Methods |
109 | 109 | |-------------------------------------------------------------------------- |
110 | 110 | */ |
111 | 111 | |
112 | - /** |
|
113 | - * Method to create a new invoice in the database. |
|
114 | - * |
|
115 | - * @param WPInv_Invoice $invoice Invoice object. |
|
116 | - */ |
|
117 | - public function create( &$invoice ) { |
|
118 | - $invoice->set_version( WPINV_VERSION ); |
|
119 | - $invoice->set_date_created( current_time( 'mysql' ) ); |
|
120 | - |
|
121 | - // Create a new post. |
|
122 | - $id = wp_insert_post( |
|
123 | - apply_filters( |
|
124 | - 'getpaid_new_invoice_data', |
|
125 | - array( |
|
126 | - 'post_date' => $invoice->get_date_created( 'edit' ), |
|
127 | - 'post_type' => $invoice->get_post_type( 'edit' ), |
|
128 | - 'post_status' => $this->get_post_status( $invoice ), |
|
129 | - 'ping_status' => 'closed', |
|
130 | - 'post_author' => $invoice->get_user_id( 'edit' ), |
|
131 | - 'post_title' => $invoice->get_title( 'edit' ), |
|
132 | - 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
133 | - 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
134 | - ) |
|
135 | - ), |
|
136 | - true |
|
137 | - ); |
|
138 | - |
|
139 | - if ( $id && ! is_wp_error( $id ) ) { |
|
140 | - |
|
141 | - // Update the new id and regenerate a title. |
|
142 | - $invoice->set_id( $id ); |
|
143 | - |
|
144 | - $invoice->maybe_set_number(); |
|
145 | - |
|
146 | - wp_update_post( |
|
147 | - array( |
|
148 | - 'ID' => $invoice->get_id(), |
|
149 | - 'post_title' => $invoice->get_number( 'edit' ), |
|
150 | - 'post_name' => $invoice->get_path( 'edit' ), |
|
151 | - ) |
|
152 | - ); |
|
153 | - |
|
154 | - // Save special fields and items. |
|
155 | - $this->save_special_fields( $invoice ); |
|
156 | - $this->save_items( $invoice ); |
|
157 | - |
|
158 | - // Update meta data. |
|
159 | - $this->update_post_meta( $invoice ); |
|
160 | - $invoice->save_meta_data(); |
|
161 | - |
|
162 | - // Apply changes. |
|
163 | - $invoice->apply_changes(); |
|
164 | - $this->clear_caches( $invoice ); |
|
165 | - |
|
166 | - // Fires after a new invoice is created. |
|
167 | - do_action( 'getpaid_new_invoice', $invoice ); |
|
168 | - return true; |
|
169 | - } |
|
170 | - |
|
171 | - if ( is_wp_error( $id ) ) { |
|
172 | - $invoice->last_error = $id->get_error_message(); |
|
173 | - } |
|
174 | - |
|
175 | - return false; |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Method to read an invoice from the database. |
|
180 | - * |
|
181 | - * @param WPInv_Invoice $invoice Invoice object. |
|
182 | - * |
|
183 | - */ |
|
184 | - public function read( &$invoice ) { |
|
185 | - |
|
186 | - $invoice->set_defaults(); |
|
187 | - $invoice_object = get_post( $invoice->get_id() ); |
|
188 | - |
|
189 | - if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) { |
|
190 | - $invoice->last_error = __( 'Invalid invoice.', 'invoicing' ); |
|
191 | - $invoice->set_id( 0 ); |
|
192 | - return false; |
|
193 | - } |
|
194 | - |
|
195 | - $invoice->set_props( |
|
196 | - array( |
|
197 | - 'date_created' => 0 < $invoice_object->post_date ? $invoice_object->post_date : null, |
|
198 | - 'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null, |
|
199 | - 'status' => $invoice_object->post_status, |
|
200 | - 'author' => $invoice_object->post_author, |
|
201 | - 'description' => $invoice_object->post_excerpt, |
|
202 | - 'parent_id' => $invoice_object->post_parent, |
|
203 | - 'name' => $invoice_object->post_title, |
|
204 | - 'path' => $invoice_object->post_name, |
|
205 | - 'post_type' => $invoice_object->post_type, |
|
206 | - ) |
|
207 | - ); |
|
208 | - |
|
209 | - $invoice->set_type( $invoice_object->post_type ); |
|
210 | - |
|
211 | - $this->read_object_data( $invoice, $invoice_object ); |
|
212 | - $this->add_special_fields( $invoice ); |
|
213 | - $this->add_items( $invoice ); |
|
214 | - $invoice->read_meta_data(); |
|
215 | - $invoice->set_object_read( true ); |
|
216 | - do_action( 'getpaid_read_invoice', $invoice ); |
|
217 | - |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * Method to update an invoice in the database. |
|
222 | - * |
|
223 | - * @param WPInv_Invoice $invoice Invoice object. |
|
224 | - */ |
|
225 | - public function update( &$invoice ) { |
|
226 | - $invoice->save_meta_data(); |
|
227 | - $invoice->set_version( WPINV_VERSION ); |
|
228 | - |
|
229 | - if ( null === $invoice->get_date_created( 'edit' ) ) { |
|
230 | - $invoice->set_date_created( current_time( 'mysql' ) ); |
|
231 | - } |
|
232 | - |
|
233 | - // Ensure both the key and number are set. |
|
234 | - $invoice->get_path(); |
|
235 | - |
|
236 | - // Grab the current status so we can compare. |
|
237 | - $previous_status = get_post_status( $invoice->get_id() ); |
|
238 | - |
|
239 | - $changes = $invoice->get_changes(); |
|
240 | - |
|
241 | - // Only update the post when the post data changes. |
|
242 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) { |
|
243 | - $post_data = array( |
|
244 | - 'post_date' => $invoice->get_date_created( 'edit' ), |
|
245 | - 'post_date_gmt' => $invoice->get_date_created_gmt( 'edit' ), |
|
246 | - 'post_status' => $invoice->get_status( 'edit' ), |
|
247 | - 'post_title' => $invoice->get_name( 'edit' ), |
|
248 | - 'post_author' => $invoice->get_user_id( 'edit' ), |
|
249 | - 'post_modified' => $invoice->get_date_modified( 'edit' ), |
|
250 | - 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
251 | - 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
252 | - 'post_name' => $invoice->get_path( 'edit' ), |
|
253 | - 'post_type' => $invoice->get_post_type( 'edit' ), |
|
254 | - ); |
|
255 | - |
|
256 | - /** |
|
257 | - * When updating this object, to prevent infinite loops, use $wpdb |
|
258 | - * to update data, since wp_update_post spawns more calls to the |
|
259 | - * save_post action. |
|
260 | - * |
|
261 | - * This ensures hooks are fired by either WP itself (admin screen save), |
|
262 | - * or an update purely from CRUD. |
|
263 | - */ |
|
264 | - if ( doing_action( 'save_post' ) ) { |
|
265 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) ); |
|
266 | - clean_post_cache( $invoice->get_id() ); |
|
267 | - } else { |
|
268 | - wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) ); |
|
269 | - } |
|
270 | - $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
271 | - } |
|
272 | - |
|
273 | - // Update meta data. |
|
274 | - $this->update_post_meta( $invoice ); |
|
275 | - |
|
276 | - // Save special fields and items. |
|
277 | - $this->save_special_fields( $invoice ); |
|
278 | - $this->save_items( $invoice ); |
|
279 | - |
|
280 | - // Apply the changes. |
|
281 | - $invoice->apply_changes(); |
|
282 | - |
|
283 | - // Clear caches. |
|
284 | - $this->clear_caches( $invoice ); |
|
285 | - |
|
286 | - // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
287 | - $new_status = $invoice->get_status( 'edit' ); |
|
288 | - |
|
289 | - if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
290 | - do_action( 'getpaid_new_invoice', $invoice ); |
|
291 | - } else { |
|
292 | - do_action( 'getpaid_update_invoice', $invoice ); |
|
293 | - } |
|
294 | - |
|
295 | - } |
|
296 | - |
|
297 | - /* |
|
112 | + /** |
|
113 | + * Method to create a new invoice in the database. |
|
114 | + * |
|
115 | + * @param WPInv_Invoice $invoice Invoice object. |
|
116 | + */ |
|
117 | + public function create( &$invoice ) { |
|
118 | + $invoice->set_version( WPINV_VERSION ); |
|
119 | + $invoice->set_date_created( current_time( 'mysql' ) ); |
|
120 | + |
|
121 | + // Create a new post. |
|
122 | + $id = wp_insert_post( |
|
123 | + apply_filters( |
|
124 | + 'getpaid_new_invoice_data', |
|
125 | + array( |
|
126 | + 'post_date' => $invoice->get_date_created( 'edit' ), |
|
127 | + 'post_type' => $invoice->get_post_type( 'edit' ), |
|
128 | + 'post_status' => $this->get_post_status( $invoice ), |
|
129 | + 'ping_status' => 'closed', |
|
130 | + 'post_author' => $invoice->get_user_id( 'edit' ), |
|
131 | + 'post_title' => $invoice->get_title( 'edit' ), |
|
132 | + 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
133 | + 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
134 | + ) |
|
135 | + ), |
|
136 | + true |
|
137 | + ); |
|
138 | + |
|
139 | + if ( $id && ! is_wp_error( $id ) ) { |
|
140 | + |
|
141 | + // Update the new id and regenerate a title. |
|
142 | + $invoice->set_id( $id ); |
|
143 | + |
|
144 | + $invoice->maybe_set_number(); |
|
145 | + |
|
146 | + wp_update_post( |
|
147 | + array( |
|
148 | + 'ID' => $invoice->get_id(), |
|
149 | + 'post_title' => $invoice->get_number( 'edit' ), |
|
150 | + 'post_name' => $invoice->get_path( 'edit' ), |
|
151 | + ) |
|
152 | + ); |
|
153 | + |
|
154 | + // Save special fields and items. |
|
155 | + $this->save_special_fields( $invoice ); |
|
156 | + $this->save_items( $invoice ); |
|
157 | + |
|
158 | + // Update meta data. |
|
159 | + $this->update_post_meta( $invoice ); |
|
160 | + $invoice->save_meta_data(); |
|
161 | + |
|
162 | + // Apply changes. |
|
163 | + $invoice->apply_changes(); |
|
164 | + $this->clear_caches( $invoice ); |
|
165 | + |
|
166 | + // Fires after a new invoice is created. |
|
167 | + do_action( 'getpaid_new_invoice', $invoice ); |
|
168 | + return true; |
|
169 | + } |
|
170 | + |
|
171 | + if ( is_wp_error( $id ) ) { |
|
172 | + $invoice->last_error = $id->get_error_message(); |
|
173 | + } |
|
174 | + |
|
175 | + return false; |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Method to read an invoice from the database. |
|
180 | + * |
|
181 | + * @param WPInv_Invoice $invoice Invoice object. |
|
182 | + * |
|
183 | + */ |
|
184 | + public function read( &$invoice ) { |
|
185 | + |
|
186 | + $invoice->set_defaults(); |
|
187 | + $invoice_object = get_post( $invoice->get_id() ); |
|
188 | + |
|
189 | + if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) { |
|
190 | + $invoice->last_error = __( 'Invalid invoice.', 'invoicing' ); |
|
191 | + $invoice->set_id( 0 ); |
|
192 | + return false; |
|
193 | + } |
|
194 | + |
|
195 | + $invoice->set_props( |
|
196 | + array( |
|
197 | + 'date_created' => 0 < $invoice_object->post_date ? $invoice_object->post_date : null, |
|
198 | + 'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null, |
|
199 | + 'status' => $invoice_object->post_status, |
|
200 | + 'author' => $invoice_object->post_author, |
|
201 | + 'description' => $invoice_object->post_excerpt, |
|
202 | + 'parent_id' => $invoice_object->post_parent, |
|
203 | + 'name' => $invoice_object->post_title, |
|
204 | + 'path' => $invoice_object->post_name, |
|
205 | + 'post_type' => $invoice_object->post_type, |
|
206 | + ) |
|
207 | + ); |
|
208 | + |
|
209 | + $invoice->set_type( $invoice_object->post_type ); |
|
210 | + |
|
211 | + $this->read_object_data( $invoice, $invoice_object ); |
|
212 | + $this->add_special_fields( $invoice ); |
|
213 | + $this->add_items( $invoice ); |
|
214 | + $invoice->read_meta_data(); |
|
215 | + $invoice->set_object_read( true ); |
|
216 | + do_action( 'getpaid_read_invoice', $invoice ); |
|
217 | + |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * Method to update an invoice in the database. |
|
222 | + * |
|
223 | + * @param WPInv_Invoice $invoice Invoice object. |
|
224 | + */ |
|
225 | + public function update( &$invoice ) { |
|
226 | + $invoice->save_meta_data(); |
|
227 | + $invoice->set_version( WPINV_VERSION ); |
|
228 | + |
|
229 | + if ( null === $invoice->get_date_created( 'edit' ) ) { |
|
230 | + $invoice->set_date_created( current_time( 'mysql' ) ); |
|
231 | + } |
|
232 | + |
|
233 | + // Ensure both the key and number are set. |
|
234 | + $invoice->get_path(); |
|
235 | + |
|
236 | + // Grab the current status so we can compare. |
|
237 | + $previous_status = get_post_status( $invoice->get_id() ); |
|
238 | + |
|
239 | + $changes = $invoice->get_changes(); |
|
240 | + |
|
241 | + // Only update the post when the post data changes. |
|
242 | + if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) { |
|
243 | + $post_data = array( |
|
244 | + 'post_date' => $invoice->get_date_created( 'edit' ), |
|
245 | + 'post_date_gmt' => $invoice->get_date_created_gmt( 'edit' ), |
|
246 | + 'post_status' => $invoice->get_status( 'edit' ), |
|
247 | + 'post_title' => $invoice->get_name( 'edit' ), |
|
248 | + 'post_author' => $invoice->get_user_id( 'edit' ), |
|
249 | + 'post_modified' => $invoice->get_date_modified( 'edit' ), |
|
250 | + 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
251 | + 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
252 | + 'post_name' => $invoice->get_path( 'edit' ), |
|
253 | + 'post_type' => $invoice->get_post_type( 'edit' ), |
|
254 | + ); |
|
255 | + |
|
256 | + /** |
|
257 | + * When updating this object, to prevent infinite loops, use $wpdb |
|
258 | + * to update data, since wp_update_post spawns more calls to the |
|
259 | + * save_post action. |
|
260 | + * |
|
261 | + * This ensures hooks are fired by either WP itself (admin screen save), |
|
262 | + * or an update purely from CRUD. |
|
263 | + */ |
|
264 | + if ( doing_action( 'save_post' ) ) { |
|
265 | + $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) ); |
|
266 | + clean_post_cache( $invoice->get_id() ); |
|
267 | + } else { |
|
268 | + wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) ); |
|
269 | + } |
|
270 | + $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
271 | + } |
|
272 | + |
|
273 | + // Update meta data. |
|
274 | + $this->update_post_meta( $invoice ); |
|
275 | + |
|
276 | + // Save special fields and items. |
|
277 | + $this->save_special_fields( $invoice ); |
|
278 | + $this->save_items( $invoice ); |
|
279 | + |
|
280 | + // Apply the changes. |
|
281 | + $invoice->apply_changes(); |
|
282 | + |
|
283 | + // Clear caches. |
|
284 | + $this->clear_caches( $invoice ); |
|
285 | + |
|
286 | + // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
287 | + $new_status = $invoice->get_status( 'edit' ); |
|
288 | + |
|
289 | + if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
290 | + do_action( 'getpaid_new_invoice', $invoice ); |
|
291 | + } else { |
|
292 | + do_action( 'getpaid_update_invoice', $invoice ); |
|
293 | + } |
|
294 | + |
|
295 | + } |
|
296 | + |
|
297 | + /* |
|
298 | 298 | |-------------------------------------------------------------------------- |
299 | 299 | | Additional Methods |
300 | 300 | |-------------------------------------------------------------------------- |
301 | 301 | */ |
302 | 302 | |
303 | - /** |
|
303 | + /** |
|
304 | 304 | * Retrieves special fields and adds to the invoice. |
305 | - * |
|
306 | - * @param WPInv_Invoice $invoice Invoice object. |
|
305 | + * |
|
306 | + * @param WPInv_Invoice $invoice Invoice object. |
|
307 | 307 | */ |
308 | 308 | public function add_special_fields( &$invoice ) { |
309 | - global $wpdb; |
|
310 | - |
|
311 | - // Maybe retrieve from the cache. |
|
312 | - $data = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
313 | - |
|
314 | - // If not found, retrieve from the db. |
|
315 | - if ( false === $data ) { |
|
316 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
317 | - |
|
318 | - $data = $wpdb->get_row( |
|
319 | - $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ), |
|
320 | - ARRAY_A |
|
321 | - ); |
|
322 | - |
|
323 | - // Update the cache with our data |
|
324 | - wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' ); |
|
325 | - |
|
326 | - } |
|
327 | - |
|
328 | - // Abort if the data does not exist. |
|
329 | - if ( empty( $data ) ) { |
|
330 | - $invoice->set_object_read( true ); |
|
331 | - $invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) ); |
|
332 | - return; |
|
333 | - } |
|
334 | - |
|
335 | - $props = array(); |
|
336 | - |
|
337 | - foreach ( $this->database_fields_to_props as $db_field => $prop ) { |
|
338 | - |
|
339 | - if ( $db_field == 'post_id' ) { |
|
340 | - continue; |
|
341 | - } |
|
342 | - |
|
343 | - $props[ $prop ] = $data[ $db_field ]; |
|
344 | - } |
|
345 | - |
|
346 | - $invoice->set_props( $props ); |
|
347 | - |
|
348 | - } |
|
349 | - |
|
350 | - /** |
|
351 | - * Gets a list of special fields that need updated based on change state |
|
352 | - * or if they are present in the database or not. |
|
353 | - * |
|
354 | - * @param WPInv_Invoice $invoice The Invoice object. |
|
355 | - * @return array A mapping of field keys => prop names, filtered by ones that should be updated. |
|
356 | - */ |
|
357 | - protected function get_special_fields_to_update( $invoice ) { |
|
358 | - $fields_to_update = array(); |
|
359 | - $changed_props = $invoice->get_changes(); |
|
360 | - |
|
361 | - // Props should be updated if they are a part of the $changed array or don't exist yet. |
|
362 | - foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
363 | - if ( array_key_exists( $prop, $changed_props ) ) { |
|
364 | - $fields_to_update[ $database_field ] = $prop; |
|
365 | - } |
|
366 | - } |
|
367 | - |
|
368 | - return $fields_to_update; |
|
369 | - } |
|
370 | - |
|
371 | - /** |
|
372 | - * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class. |
|
373 | - * |
|
374 | - * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
375 | - * @since 1.0.19 |
|
376 | - */ |
|
377 | - protected function update_special_fields( &$invoice ) { |
|
378 | - global $wpdb; |
|
379 | - |
|
380 | - $updated_props = array(); |
|
381 | - $fields_to_update = $this->get_special_fields_to_update( $invoice ); |
|
382 | - |
|
383 | - foreach ( $fields_to_update as $database_field => $prop ) { |
|
384 | - $value = $invoice->{"get_$prop"}( 'edit' ); |
|
385 | - $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
386 | - $value = is_bool( $value ) ? (int) $value : $value; |
|
387 | - $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
388 | - } |
|
389 | - |
|
390 | - if ( ! empty( $updated_props ) ) { |
|
391 | - |
|
392 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
393 | - $wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) ); |
|
394 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
395 | - do_action( 'getpaid_invoice_update_database_fields', $invoice, $updated_props ); |
|
396 | - |
|
397 | - } |
|
398 | - |
|
399 | - } |
|
400 | - |
|
401 | - /** |
|
402 | - * Helper method that inserts special fields to the database. |
|
403 | - * |
|
404 | - * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
405 | - * @since 1.0.19 |
|
406 | - */ |
|
407 | - protected function insert_special_fields( &$invoice ) { |
|
408 | - global $wpdb; |
|
409 | - |
|
410 | - $updated_props = array(); |
|
411 | - |
|
412 | - foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
413 | - $value = $invoice->{"get_$prop"}( 'edit' ); |
|
414 | - $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
415 | - $value = is_bool( $value ) ? (int) $value : $value; |
|
416 | - $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
417 | - } |
|
418 | - |
|
419 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
420 | - $wpdb->insert( $table, $updated_props ); |
|
421 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
422 | - do_action( 'getpaid_invoice_insert_database_fields', $invoice, $updated_props ); |
|
423 | - |
|
424 | - } |
|
425 | - |
|
426 | - /** |
|
309 | + global $wpdb; |
|
310 | + |
|
311 | + // Maybe retrieve from the cache. |
|
312 | + $data = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
313 | + |
|
314 | + // If not found, retrieve from the db. |
|
315 | + if ( false === $data ) { |
|
316 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
317 | + |
|
318 | + $data = $wpdb->get_row( |
|
319 | + $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ), |
|
320 | + ARRAY_A |
|
321 | + ); |
|
322 | + |
|
323 | + // Update the cache with our data |
|
324 | + wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' ); |
|
325 | + |
|
326 | + } |
|
327 | + |
|
328 | + // Abort if the data does not exist. |
|
329 | + if ( empty( $data ) ) { |
|
330 | + $invoice->set_object_read( true ); |
|
331 | + $invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) ); |
|
332 | + return; |
|
333 | + } |
|
334 | + |
|
335 | + $props = array(); |
|
336 | + |
|
337 | + foreach ( $this->database_fields_to_props as $db_field => $prop ) { |
|
338 | + |
|
339 | + if ( $db_field == 'post_id' ) { |
|
340 | + continue; |
|
341 | + } |
|
342 | + |
|
343 | + $props[ $prop ] = $data[ $db_field ]; |
|
344 | + } |
|
345 | + |
|
346 | + $invoice->set_props( $props ); |
|
347 | + |
|
348 | + } |
|
349 | + |
|
350 | + /** |
|
351 | + * Gets a list of special fields that need updated based on change state |
|
352 | + * or if they are present in the database or not. |
|
353 | + * |
|
354 | + * @param WPInv_Invoice $invoice The Invoice object. |
|
355 | + * @return array A mapping of field keys => prop names, filtered by ones that should be updated. |
|
356 | + */ |
|
357 | + protected function get_special_fields_to_update( $invoice ) { |
|
358 | + $fields_to_update = array(); |
|
359 | + $changed_props = $invoice->get_changes(); |
|
360 | + |
|
361 | + // Props should be updated if they are a part of the $changed array or don't exist yet. |
|
362 | + foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
363 | + if ( array_key_exists( $prop, $changed_props ) ) { |
|
364 | + $fields_to_update[ $database_field ] = $prop; |
|
365 | + } |
|
366 | + } |
|
367 | + |
|
368 | + return $fields_to_update; |
|
369 | + } |
|
370 | + |
|
371 | + /** |
|
372 | + * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class. |
|
373 | + * |
|
374 | + * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
375 | + * @since 1.0.19 |
|
376 | + */ |
|
377 | + protected function update_special_fields( &$invoice ) { |
|
378 | + global $wpdb; |
|
379 | + |
|
380 | + $updated_props = array(); |
|
381 | + $fields_to_update = $this->get_special_fields_to_update( $invoice ); |
|
382 | + |
|
383 | + foreach ( $fields_to_update as $database_field => $prop ) { |
|
384 | + $value = $invoice->{"get_$prop"}( 'edit' ); |
|
385 | + $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
386 | + $value = is_bool( $value ) ? (int) $value : $value; |
|
387 | + $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
388 | + } |
|
389 | + |
|
390 | + if ( ! empty( $updated_props ) ) { |
|
391 | + |
|
392 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
393 | + $wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) ); |
|
394 | + wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
395 | + do_action( 'getpaid_invoice_update_database_fields', $invoice, $updated_props ); |
|
396 | + |
|
397 | + } |
|
398 | + |
|
399 | + } |
|
400 | + |
|
401 | + /** |
|
402 | + * Helper method that inserts special fields to the database. |
|
403 | + * |
|
404 | + * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
405 | + * @since 1.0.19 |
|
406 | + */ |
|
407 | + protected function insert_special_fields( &$invoice ) { |
|
408 | + global $wpdb; |
|
409 | + |
|
410 | + $updated_props = array(); |
|
411 | + |
|
412 | + foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
413 | + $value = $invoice->{"get_$prop"}( 'edit' ); |
|
414 | + $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
415 | + $value = is_bool( $value ) ? (int) $value : $value; |
|
416 | + $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
417 | + } |
|
418 | + |
|
419 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
420 | + $wpdb->insert( $table, $updated_props ); |
|
421 | + wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
422 | + do_action( 'getpaid_invoice_insert_database_fields', $invoice, $updated_props ); |
|
423 | + |
|
424 | + } |
|
425 | + |
|
426 | + /** |
|
427 | 427 | * Saves all special fields. |
428 | - * |
|
429 | - * @param WPInv_Invoice $invoice Invoice object. |
|
428 | + * |
|
429 | + * @param WPInv_Invoice $invoice Invoice object. |
|
430 | 430 | */ |
431 | 431 | public function save_special_fields( &$invoice ) { |
432 | - global $wpdb; |
|
432 | + global $wpdb; |
|
433 | 433 | |
434 | - // The invoices table. |
|
435 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
436 | - $id = (int) $invoice->get_id(); |
|
437 | - $invoice->maybe_set_key(); |
|
434 | + // The invoices table. |
|
435 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
436 | + $id = (int) $invoice->get_id(); |
|
437 | + $invoice->maybe_set_key(); |
|
438 | 438 | |
439 | - if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) { |
|
439 | + if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) { |
|
440 | 440 | |
441 | - $this->update_special_fields( $invoice ); |
|
441 | + $this->update_special_fields( $invoice ); |
|
442 | 442 | |
443 | - } else { |
|
443 | + } else { |
|
444 | 444 | |
445 | - $this->insert_special_fields( $invoice ); |
|
445 | + $this->insert_special_fields( $invoice ); |
|
446 | 446 | |
447 | - } |
|
447 | + } |
|
448 | 448 | |
449 | - } |
|
449 | + } |
|
450 | 450 | |
451 | - /** |
|
451 | + /** |
|
452 | 452 | * Set's up cart details. |
453 | - * |
|
454 | - * @param WPInv_Invoice $invoice Invoice object. |
|
453 | + * |
|
454 | + * @param WPInv_Invoice $invoice Invoice object. |
|
455 | 455 | */ |
456 | 456 | public function add_items( &$invoice ) { |
457 | - global $wpdb; |
|
457 | + global $wpdb; |
|
458 | 458 | |
459 | - // Maybe retrieve from the cache. |
|
460 | - $items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
459 | + // Maybe retrieve from the cache. |
|
460 | + $items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
461 | 461 | |
462 | - // If not found, retrieve from the db. |
|
463 | - if ( false === $items ) { |
|
464 | - $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
462 | + // If not found, retrieve from the db. |
|
463 | + if ( false === $items ) { |
|
464 | + $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
465 | 465 | |
466 | - $items = $wpdb->get_results( |
|
467 | - $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() ) |
|
468 | - ); |
|
466 | + $items = $wpdb->get_results( |
|
467 | + $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() ) |
|
468 | + ); |
|
469 | 469 | |
470 | - // Update the cache with our data |
|
471 | - wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' ); |
|
470 | + // Update the cache with our data |
|
471 | + wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' ); |
|
472 | 472 | |
473 | - } |
|
473 | + } |
|
474 | 474 | |
475 | - // Abort if no items found. |
|
475 | + // Abort if no items found. |
|
476 | 476 | if ( empty( $items ) ) { |
477 | 477 | return; |
478 | - } |
|
479 | - |
|
480 | - $_items = array(); |
|
481 | - foreach ( $items as $item_data ) { |
|
482 | - $item = new GetPaid_Form_Item( $item_data->item_id ); |
|
483 | - |
|
484 | - // Set item data. |
|
485 | - $item->item_tax = wpinv_sanitize_amount( $item_data->tax ); |
|
486 | - $item->item_discount = wpinv_sanitize_amount( $item_data->discount ); |
|
487 | - $item->set_name( $item_data->item_name ); |
|
488 | - $item->set_description( $item_data->item_description ); |
|
489 | - $item->set_price( $item_data->item_price ); |
|
490 | - $item->set_quantity( $item_data->quantity ); |
|
491 | - $item->set_item_meta( $item_data->meta ); |
|
492 | - $_items[] = $item; |
|
493 | - } |
|
494 | - |
|
495 | - $invoice->set_items( $_items ); |
|
496 | - } |
|
497 | - |
|
498 | - /** |
|
478 | + } |
|
479 | + |
|
480 | + $_items = array(); |
|
481 | + foreach ( $items as $item_data ) { |
|
482 | + $item = new GetPaid_Form_Item( $item_data->item_id ); |
|
483 | + |
|
484 | + // Set item data. |
|
485 | + $item->item_tax = wpinv_sanitize_amount( $item_data->tax ); |
|
486 | + $item->item_discount = wpinv_sanitize_amount( $item_data->discount ); |
|
487 | + $item->set_name( $item_data->item_name ); |
|
488 | + $item->set_description( $item_data->item_description ); |
|
489 | + $item->set_price( $item_data->item_price ); |
|
490 | + $item->set_quantity( $item_data->quantity ); |
|
491 | + $item->set_item_meta( $item_data->meta ); |
|
492 | + $_items[] = $item; |
|
493 | + } |
|
494 | + |
|
495 | + $invoice->set_items( $_items ); |
|
496 | + } |
|
497 | + |
|
498 | + /** |
|
499 | 499 | * Saves cart details. |
500 | - * |
|
501 | - * @param WPInv_Invoice $invoice Invoice object. |
|
500 | + * |
|
501 | + * @param WPInv_Invoice $invoice Invoice object. |
|
502 | 502 | */ |
503 | 503 | public function save_items( $invoice ) { |
504 | 504 | |
505 | - // Delete previously existing items. |
|
506 | - $this->delete_items( $invoice ); |
|
505 | + // Delete previously existing items. |
|
506 | + $this->delete_items( $invoice ); |
|
507 | 507 | |
508 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
508 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
509 | 509 | |
510 | - foreach ( $invoice->get_cart_details() as $item_data ) { |
|
511 | - $item_data = array_map( 'maybe_serialize', $item_data ); |
|
512 | - $GLOBALS['wpdb']->insert( $table, $item_data ); |
|
513 | - } |
|
510 | + foreach ( $invoice->get_cart_details() as $item_data ) { |
|
511 | + $item_data = array_map( 'maybe_serialize', $item_data ); |
|
512 | + $GLOBALS['wpdb']->insert( $table, $item_data ); |
|
513 | + } |
|
514 | 514 | |
515 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
516 | - do_action( 'getpaid_invoice_save_items', $invoice ); |
|
515 | + wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
516 | + do_action( 'getpaid_invoice_save_items', $invoice ); |
|
517 | 517 | |
518 | - } |
|
518 | + } |
|
519 | 519 | |
520 | - /** |
|
520 | + /** |
|
521 | 521 | * Deletes an invoice's cart details from the database. |
522 | - * |
|
523 | - * @param WPInv_Invoice $invoice Invoice object. |
|
522 | + * |
|
523 | + * @param WPInv_Invoice $invoice Invoice object. |
|
524 | 524 | */ |
525 | 525 | public function delete_items( $invoice ) { |
526 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
527 | - return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
528 | - } |
|
526 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
527 | + return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
528 | + } |
|
529 | 529 | |
530 | - /** |
|
530 | + /** |
|
531 | 531 | * Deletes an invoice's special fields from the database. |
532 | - * |
|
533 | - * @param WPInv_Invoice $invoice Invoice object. |
|
532 | + * |
|
533 | + * @param WPInv_Invoice $invoice Invoice object. |
|
534 | 534 | */ |
535 | 535 | public function delete_special_fields( $invoice ) { |
536 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices'; |
|
537 | - return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
538 | - } |
|
539 | - |
|
540 | - /** |
|
541 | - * Get the status to save to the post object. |
|
542 | - * |
|
543 | - * |
|
544 | - * @since 1.0.19 |
|
545 | - * @param WPInv_Invoice $object GetPaid_Data object. |
|
546 | - * @return string |
|
547 | - */ |
|
548 | - protected function get_post_status( $object ) { |
|
549 | - $object_status = $object->get_status( 'edit' ); |
|
550 | - |
|
551 | - if ( ! $object_status ) { |
|
552 | - $object_status = $object->get_default_status(); |
|
553 | - } |
|
554 | - |
|
555 | - return $object_status; |
|
556 | - } |
|
536 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices'; |
|
537 | + return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
538 | + } |
|
539 | + |
|
540 | + /** |
|
541 | + * Get the status to save to the post object. |
|
542 | + * |
|
543 | + * |
|
544 | + * @since 1.0.19 |
|
545 | + * @param WPInv_Invoice $object GetPaid_Data object. |
|
546 | + * @return string |
|
547 | + */ |
|
548 | + protected function get_post_status( $object ) { |
|
549 | + $object_status = $object->get_status( 'edit' ); |
|
550 | + |
|
551 | + if ( ! $object_status ) { |
|
552 | + $object_status = $object->get_default_status(); |
|
553 | + } |
|
554 | + |
|
555 | + return $object_status; |
|
556 | + } |
|
557 | 557 | |
558 | 558 | } |