@@ -7,40 +7,40 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( ! defined( 'WPINC' ) ) { |
|
10 | +if (!defined('WPINC')) { |
|
11 | 11 | exit; |
12 | 12 | } |
13 | 13 | |
14 | 14 | function wpinv_is_checkout() { |
15 | 15 | global $wp_query; |
16 | 16 | |
17 | - $is_object_set = isset( $wp_query->queried_object ); |
|
18 | - $is_object_id_set = isset( $wp_query->queried_object_id ); |
|
19 | - $checkout_page = wpinv_get_option( 'checkout_page' ); |
|
20 | - $is_checkout = ! empty( $checkout_page ) && is_page( $checkout_page ); |
|
17 | + $is_object_set = isset($wp_query->queried_object); |
|
18 | + $is_object_id_set = isset($wp_query->queried_object_id); |
|
19 | + $checkout_page = wpinv_get_option('checkout_page'); |
|
20 | + $is_checkout = !empty($checkout_page) && is_page($checkout_page); |
|
21 | 21 | |
22 | - if ( ! $is_object_set ) { |
|
23 | - unset( $wp_query->queried_object ); |
|
22 | + if (!$is_object_set) { |
|
23 | + unset($wp_query->queried_object); |
|
24 | 24 | } |
25 | 25 | |
26 | - if ( ! $is_object_id_set ) { |
|
27 | - unset( $wp_query->queried_object_id ); |
|
26 | + if (!$is_object_id_set) { |
|
27 | + unset($wp_query->queried_object_id); |
|
28 | 28 | } |
29 | 29 | |
30 | - return apply_filters( 'wpinv_is_checkout', $is_checkout ); |
|
30 | + return apply_filters('wpinv_is_checkout', $is_checkout); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | function wpinv_can_checkout() { |
34 | 34 | $can_checkout = true; // Always true for now |
35 | 35 | |
36 | - return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout ); |
|
36 | + return (bool) apply_filters('wpinv_can_checkout', $can_checkout); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | function wpinv_get_success_page_uri() { |
40 | - $page_id = wpinv_get_option( 'success_page', 0 ); |
|
41 | - $page_id = absint( $page_id ); |
|
40 | + $page_id = wpinv_get_option('success_page', 0); |
|
41 | + $page_id = absint($page_id); |
|
42 | 42 | |
43 | - return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) ); |
|
43 | + return apply_filters('wpinv_get_success_page_uri', get_permalink($page_id)); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
@@ -49,154 +49,154 @@ discard block |
||
49 | 49 | * @param string $post_type The post type or invoice type. |
50 | 50 | * @return string The history page URL. |
51 | 51 | */ |
52 | -function wpinv_get_history_page_uri( $post_type = 'wpi_invoice' ) { |
|
53 | - $post_type = sanitize_key( str_replace( 'wpi_', '', $post_type ) ); |
|
54 | - $page_id = wpinv_get_option( "{$post_type}_history_page", 0 ); |
|
55 | - $page_id = absint( $page_id ); |
|
56 | - return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ), $post_type ); |
|
52 | +function wpinv_get_history_page_uri($post_type = 'wpi_invoice') { |
|
53 | + $post_type = sanitize_key(str_replace('wpi_', '', $post_type)); |
|
54 | + $page_id = wpinv_get_option("{$post_type}_history_page", 0); |
|
55 | + $page_id = absint($page_id); |
|
56 | + return apply_filters('wpinv_get_history_page_uri', get_permalink($page_id), $post_type); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | function wpinv_is_success_page() { |
60 | - $is_success_page = wpinv_get_option( 'success_page', false ); |
|
61 | - $is_success_page = ! empty( $is_success_page ) ? is_page( $is_success_page ) : false; |
|
60 | + $is_success_page = wpinv_get_option('success_page', false); |
|
61 | + $is_success_page = !empty($is_success_page) ? is_page($is_success_page) : false; |
|
62 | 62 | |
63 | - return apply_filters( 'wpinv_is_success_page', $is_success_page ); |
|
63 | + return apply_filters('wpinv_is_success_page', $is_success_page); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | function wpinv_is_invoice_history_page() { |
67 | - $ret = wpinv_get_option( 'invoice_history_page', false ); |
|
68 | - $ret = $ret ? is_page( $ret ) : false; |
|
69 | - return apply_filters( 'wpinv_is_invoice_history_page', $ret ); |
|
67 | + $ret = wpinv_get_option('invoice_history_page', false); |
|
68 | + $ret = $ret ? is_page($ret) : false; |
|
69 | + return apply_filters('wpinv_is_invoice_history_page', $ret); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | function wpinv_is_subscriptions_history_page() { |
73 | - $ret = wpinv_get_option( 'invoice_subscription_page', false ); |
|
74 | - $ret = $ret ? is_page( $ret ) : false; |
|
75 | - return apply_filters( 'wpinv_is_subscriptions_history_page', $ret ); |
|
73 | + $ret = wpinv_get_option('invoice_subscription_page', false); |
|
74 | + $ret = $ret ? is_page($ret) : false; |
|
75 | + return apply_filters('wpinv_is_subscriptions_history_page', $ret); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | 79 | * Redirects a user the success page. |
80 | 80 | */ |
81 | -function wpinv_send_to_success_page( $args = array() ) { |
|
81 | +function wpinv_send_to_success_page($args = array()) { |
|
82 | 82 | |
83 | - $args = wp_parse_args( $args ); |
|
83 | + $args = wp_parse_args($args); |
|
84 | 84 | |
85 | - if ( ! empty( $args['invoice_key'] ) ) { |
|
86 | - $invoice = wpinv_get_invoice( $args['invoice_key'] ); |
|
85 | + if (!empty($args['invoice_key'])) { |
|
86 | + $invoice = wpinv_get_invoice($args['invoice_key']); |
|
87 | 87 | |
88 | - if ( $invoice && $invoice->exists() ) { |
|
88 | + if ($invoice && $invoice->exists()) { |
|
89 | 89 | $success_page = $invoice->get_receipt_url(); |
90 | 90 | } |
91 | 91 | } |
92 | 92 | |
93 | - if ( empty( $success_page ) ) { |
|
93 | + if (empty($success_page)) { |
|
94 | 94 | $success_page = wpinv_get_success_page_uri(); |
95 | 95 | } |
96 | 96 | |
97 | - $redirect = add_query_arg( $args, $success_page ); |
|
97 | + $redirect = add_query_arg($args, $success_page); |
|
98 | 98 | |
99 | - $redirect = apply_filters( 'wpinv_send_to_success_page_url', $redirect, $args, $success_page ); |
|
99 | + $redirect = apply_filters('wpinv_send_to_success_page_url', $redirect, $args, $success_page); |
|
100 | 100 | |
101 | - wp_redirect( $redirect ); |
|
101 | + wp_redirect($redirect); |
|
102 | 102 | exit; |
103 | 103 | } |
104 | 104 | |
105 | -function wpinv_send_to_failed_page( $args = null ) { |
|
105 | +function wpinv_send_to_failed_page($args = null) { |
|
106 | 106 | $redirect = wpinv_get_failed_transaction_uri(); |
107 | 107 | |
108 | - if ( ! empty( $args ) ) { |
|
108 | + if (!empty($args)) { |
|
109 | 109 | // Check for backward compatibility |
110 | - if ( is_string( $args ) ) { |
|
111 | - $args = str_replace( '?', '', $args ); |
|
110 | + if (is_string($args)) { |
|
111 | + $args = str_replace('?', '', $args); |
|
112 | 112 | } |
113 | 113 | |
114 | - $args = wp_parse_args( $args ); |
|
114 | + $args = wp_parse_args($args); |
|
115 | 115 | |
116 | - $redirect = add_query_arg( $args, $redirect ); |
|
116 | + $redirect = add_query_arg($args, $redirect); |
|
117 | 117 | } |
118 | 118 | |
119 | - $gateway = isset( $_REQUEST['wpi-gateway'] ) ? $_REQUEST['wpi-gateway'] : ''; |
|
119 | + $gateway = isset($_REQUEST['wpi-gateway']) ? $_REQUEST['wpi-gateway'] : ''; |
|
120 | 120 | |
121 | - $redirect = apply_filters( 'wpinv_failed_page_redirect', $redirect, $gateway, $args ); |
|
122 | - wp_redirect( $redirect ); |
|
121 | + $redirect = apply_filters('wpinv_failed_page_redirect', $redirect, $gateway, $args); |
|
122 | + wp_redirect($redirect); |
|
123 | 123 | exit; |
124 | 124 | } |
125 | 125 | |
126 | -function wpinv_get_checkout_uri( $args = array() ) { |
|
127 | - $uri = wpinv_get_option( 'checkout_page', false ); |
|
128 | - $uri = isset( $uri ) ? get_permalink( $uri ) : null; |
|
126 | +function wpinv_get_checkout_uri($args = array()) { |
|
127 | + $uri = wpinv_get_option('checkout_page', false); |
|
128 | + $uri = isset($uri) ? get_permalink($uri) : null; |
|
129 | 129 | |
130 | - if ( ! empty( $args ) ) { |
|
130 | + if (!empty($args)) { |
|
131 | 131 | // Check for backward compatibility |
132 | - if ( is_string( $args ) ) { |
|
133 | - $args = str_replace( '?', '', $args ); |
|
132 | + if (is_string($args)) { |
|
133 | + $args = str_replace('?', '', $args); |
|
134 | 134 | } |
135 | 135 | |
136 | - $args = wp_parse_args( $args ); |
|
136 | + $args = wp_parse_args($args); |
|
137 | 137 | |
138 | - $uri = add_query_arg( $args, $uri ); |
|
138 | + $uri = add_query_arg($args, $uri); |
|
139 | 139 | } |
140 | 140 | |
141 | - $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
141 | + $scheme = defined('FORCE_SSL_ADMIN') && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
142 | 142 | |
143 | - $ajax_url = admin_url( 'admin-ajax.php', $scheme ); |
|
143 | + $ajax_url = admin_url('admin-ajax.php', $scheme); |
|
144 | 144 | |
145 | - if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) { |
|
146 | - $uri = preg_replace( '/^http:/', 'https:', $uri ); |
|
145 | + if ((!preg_match('/^https/', $uri) && preg_match('/^https/', $ajax_url)) || wpinv_is_ssl_enforced()) { |
|
146 | + $uri = preg_replace('/^http:/', 'https:', $uri); |
|
147 | 147 | } |
148 | 148 | |
149 | - return apply_filters( 'wpinv_get_checkout_uri', $uri ); |
|
149 | + return apply_filters('wpinv_get_checkout_uri', $uri); |
|
150 | 150 | } |
151 | 151 | |
152 | -function wpinv_get_success_page_url( $query_string = null ) { |
|
153 | - $success_page = wpinv_get_option( 'success_page', 0 ); |
|
154 | - $success_page = get_permalink( $success_page ); |
|
152 | +function wpinv_get_success_page_url($query_string = null) { |
|
153 | + $success_page = wpinv_get_option('success_page', 0); |
|
154 | + $success_page = get_permalink($success_page); |
|
155 | 155 | |
156 | - if ( $query_string ) { |
|
156 | + if ($query_string) { |
|
157 | 157 | $success_page .= $query_string; |
158 | 158 | } |
159 | 159 | |
160 | - return apply_filters( 'wpinv_success_page_url', $success_page ); |
|
160 | + return apply_filters('wpinv_success_page_url', $success_page); |
|
161 | 161 | } |
162 | 162 | |
163 | -function wpinv_get_failed_transaction_uri( $extras = false ) { |
|
164 | - $uri = wpinv_get_option( 'failure_page', '' ); |
|
165 | - $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url(); |
|
163 | +function wpinv_get_failed_transaction_uri($extras = false) { |
|
164 | + $uri = wpinv_get_option('failure_page', ''); |
|
165 | + $uri = !empty($uri) ? trailingslashit(get_permalink($uri)) : home_url(); |
|
166 | 166 | |
167 | - if ( $extras ) { |
|
167 | + if ($extras) { |
|
168 | 168 | $uri .= $extras; |
169 | 169 | } |
170 | 170 | |
171 | - return apply_filters( 'wpinv_get_failed_transaction_uri', $uri ); |
|
171 | + return apply_filters('wpinv_get_failed_transaction_uri', $uri); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | function wpinv_is_failed_transaction_page() { |
175 | - $ret = wpinv_get_option( 'failure_page', false ); |
|
176 | - $ret = isset( $ret ) ? is_page( $ret ) : false; |
|
175 | + $ret = wpinv_get_option('failure_page', false); |
|
176 | + $ret = isset($ret) ? is_page($ret) : false; |
|
177 | 177 | |
178 | - return apply_filters( 'wpinv_is_failure_page', $ret ); |
|
178 | + return apply_filters('wpinv_is_failure_page', $ret); |
|
179 | 179 | } |
180 | 180 | |
181 | -function wpinv_transaction_query( $type = 'start' ) { |
|
181 | +function wpinv_transaction_query($type = 'start') { |
|
182 | 182 | global $wpdb; |
183 | 183 | |
184 | 184 | $wpdb->hide_errors(); |
185 | 185 | |
186 | - if ( ! defined( 'WPINV_USE_TRANSACTIONS' ) ) { |
|
187 | - define( 'WPINV_USE_TRANSACTIONS', true ); |
|
186 | + if (!defined('WPINV_USE_TRANSACTIONS')) { |
|
187 | + define('WPINV_USE_TRANSACTIONS', true); |
|
188 | 188 | } |
189 | 189 | |
190 | - if ( WPINV_USE_TRANSACTIONS ) { |
|
191 | - switch ( $type ) { |
|
190 | + if (WPINV_USE_TRANSACTIONS) { |
|
191 | + switch ($type) { |
|
192 | 192 | case 'commit': |
193 | - $wpdb->query( 'COMMIT' ); |
|
193 | + $wpdb->query('COMMIT'); |
|
194 | 194 | break; |
195 | 195 | case 'rollback': |
196 | - $wpdb->query( 'ROLLBACK' ); |
|
196 | + $wpdb->query('ROLLBACK'); |
|
197 | 197 | break; |
198 | 198 | default: |
199 | - $wpdb->query( 'START TRANSACTION' ); |
|
199 | + $wpdb->query('START TRANSACTION'); |
|
200 | 200 | break; |
201 | 201 | } |
202 | 202 | } |
@@ -205,146 +205,146 @@ discard block |
||
205 | 205 | function wpinv_get_prefix() { |
206 | 206 | $invoice_prefix = 'INV-'; |
207 | 207 | |
208 | - return apply_filters( 'wpinv_get_prefix', $invoice_prefix ); |
|
208 | + return apply_filters('wpinv_get_prefix', $invoice_prefix); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | function wpinv_get_business_logo() { |
212 | - $business_logo = wpinv_get_option( 'logo' ); |
|
213 | - return apply_filters( 'wpinv_get_business_logo', $business_logo ); |
|
212 | + $business_logo = wpinv_get_option('logo'); |
|
213 | + return apply_filters('wpinv_get_business_logo', $business_logo); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | function wpinv_get_business_name() { |
217 | - $name = wpinv_get_option( 'store_name', wpinv_get_blogname() ); |
|
217 | + $name = wpinv_get_option('store_name', wpinv_get_blogname()); |
|
218 | 218 | |
219 | - if ( empty( $name ) ) { |
|
219 | + if (empty($name)) { |
|
220 | 220 | $name = wpinv_get_blogname(); |
221 | 221 | } |
222 | 222 | |
223 | - return apply_filters( 'wpinv_get_business_name', $name ); |
|
223 | + return apply_filters('wpinv_get_business_name', $name); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | function wpinv_get_blogname() { |
227 | - return wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); |
|
227 | + return wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | function wpinv_get_admin_email() { |
231 | - $admin_email = wpinv_get_option( 'admin_email', get_option( 'admin_email' ) ); |
|
232 | - return apply_filters( 'wpinv_admin_email', $admin_email ); |
|
231 | + $admin_email = wpinv_get_option('admin_email', get_option('admin_email')); |
|
232 | + return apply_filters('wpinv_admin_email', $admin_email); |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | function wpinv_get_business_website() { |
236 | - $business_website = home_url( '/' ); |
|
237 | - return apply_filters( 'wpinv_get_business_website', $business_website ); |
|
236 | + $business_website = home_url('/'); |
|
237 | + return apply_filters('wpinv_get_business_website', $business_website); |
|
238 | 238 | } |
239 | 239 | |
240 | -function wpinv_get_terms_text( $invoice_id = 0 ) { |
|
240 | +function wpinv_get_terms_text($invoice_id = 0) { |
|
241 | 241 | $terms_text = ''; |
242 | - return apply_filters( 'wpinv_get_terms_text', $terms_text, $invoice_id ); |
|
242 | + return apply_filters('wpinv_get_terms_text', $terms_text, $invoice_id); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | function wpinv_get_business_footer() { |
246 | - $site_link = '<a target="_blank" href="' . esc_url( wpinv_get_business_website() ) . '">' . esc_html( wpinv_get_business_name() ) . '</a>'; |
|
247 | - $business_footer = wp_sprintf( __( 'Thanks for using %s', 'invoicing' ), $site_link ); |
|
248 | - return apply_filters( 'wpinv_get_business_footer', $business_footer ); |
|
246 | + $site_link = '<a target="_blank" href="' . esc_url(wpinv_get_business_website()) . '">' . esc_html(wpinv_get_business_name()) . '</a>'; |
|
247 | + $business_footer = wp_sprintf(__('Thanks for using %s', 'invoicing'), $site_link); |
|
248 | + return apply_filters('wpinv_get_business_footer', $business_footer); |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | function wpinv_checkout_required_fields() { |
252 | 252 | $required_fields = array(); |
253 | 253 | |
254 | 254 | // Let payment gateways and other extensions determine if address fields should be required |
255 | - $require_billing_details = apply_filters( 'wpinv_checkout_required_billing_details', wpinv_use_taxes() ); |
|
255 | + $require_billing_details = apply_filters('wpinv_checkout_required_billing_details', wpinv_use_taxes()); |
|
256 | 256 | |
257 | - if ( $require_billing_details ) { |
|
258 | - if ( (bool)wpinv_get_option( 'fname_mandatory' ) ) { |
|
257 | + if ($require_billing_details) { |
|
258 | + if ((bool) wpinv_get_option('fname_mandatory')) { |
|
259 | 259 | $required_fields['first_name'] = array( |
260 | 260 | 'error_id' => 'invalid_first_name', |
261 | - 'error_message' => __( 'Please enter your first name', 'invoicing' ), |
|
261 | + 'error_message' => __('Please enter your first name', 'invoicing'), |
|
262 | 262 | ); |
263 | 263 | } |
264 | - if ( (bool)wpinv_get_option( 'address_mandatory' ) ) { |
|
264 | + if ((bool) wpinv_get_option('address_mandatory')) { |
|
265 | 265 | $required_fields['address'] = array( |
266 | 266 | 'error_id' => 'invalid_address', |
267 | - 'error_message' => __( 'Please enter your address', 'invoicing' ), |
|
267 | + 'error_message' => __('Please enter your address', 'invoicing'), |
|
268 | 268 | ); |
269 | 269 | } |
270 | - if ( (bool)wpinv_get_option( 'city_mandatory' ) ) { |
|
270 | + if ((bool) wpinv_get_option('city_mandatory')) { |
|
271 | 271 | $required_fields['city'] = array( |
272 | 272 | 'error_id' => 'invalid_city', |
273 | - 'error_message' => __( 'Please enter your billing city', 'invoicing' ), |
|
273 | + 'error_message' => __('Please enter your billing city', 'invoicing'), |
|
274 | 274 | ); |
275 | 275 | } |
276 | - if ( (bool)wpinv_get_option( 'state_mandatory' ) ) { |
|
276 | + if ((bool) wpinv_get_option('state_mandatory')) { |
|
277 | 277 | $required_fields['state'] = array( |
278 | 278 | 'error_id' => 'invalid_state', |
279 | - 'error_message' => __( 'Please enter billing state / province', 'invoicing' ), |
|
279 | + 'error_message' => __('Please enter billing state / province', 'invoicing'), |
|
280 | 280 | ); |
281 | 281 | } |
282 | - if ( (bool)wpinv_get_option( 'country_mandatory' ) ) { |
|
282 | + if ((bool) wpinv_get_option('country_mandatory')) { |
|
283 | 283 | $required_fields['country'] = array( |
284 | 284 | 'error_id' => 'invalid_country', |
285 | - 'error_message' => __( 'Please select your billing country', 'invoicing' ), |
|
285 | + 'error_message' => __('Please select your billing country', 'invoicing'), |
|
286 | 286 | ); |
287 | 287 | } |
288 | 288 | } |
289 | 289 | |
290 | - return apply_filters( 'wpinv_checkout_required_fields', $required_fields ); |
|
290 | + return apply_filters('wpinv_checkout_required_fields', $required_fields); |
|
291 | 291 | } |
292 | 292 | |
293 | 293 | function wpinv_is_ssl_enforced() { |
294 | - $ssl_enforced = wpinv_get_option( 'enforce_ssl', false ); |
|
295 | - return (bool) apply_filters( 'wpinv_is_ssl_enforced', $ssl_enforced ); |
|
294 | + $ssl_enforced = wpinv_get_option('enforce_ssl', false); |
|
295 | + return (bool) apply_filters('wpinv_is_ssl_enforced', $ssl_enforced); |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | function wpinv_schedule_event_twicedaily() { |
299 | 299 | wpinv_email_payment_reminders(); |
300 | 300 | } |
301 | -add_action( 'wpinv_register_schedule_event_daily', 'wpinv_schedule_event_twicedaily' ); |
|
301 | +add_action('wpinv_register_schedule_event_daily', 'wpinv_schedule_event_twicedaily'); |
|
302 | 302 | |
303 | 303 | function wpinv_require_login_to_checkout() { |
304 | - $return = wpinv_get_option( 'login_to_checkout', false ); |
|
305 | - return (bool) apply_filters( 'wpinv_require_login_to_checkout', $return ); |
|
304 | + $return = wpinv_get_option('login_to_checkout', false); |
|
305 | + return (bool) apply_filters('wpinv_require_login_to_checkout', $return); |
|
306 | 306 | } |
307 | 307 | |
308 | -function wpinv_sequential_number_active( $type = '' ) { |
|
309 | - $check = apply_filters( 'wpinv_pre_check_sequential_number_active', null, $type ); |
|
310 | - if ( null !== $check ) { |
|
308 | +function wpinv_sequential_number_active($type = '') { |
|
309 | + $check = apply_filters('wpinv_pre_check_sequential_number_active', null, $type); |
|
310 | + if (null !== $check) { |
|
311 | 311 | return $check; |
312 | 312 | } |
313 | 313 | |
314 | - return wpinv_get_option( 'sequential_invoice_number' ); |
|
314 | + return wpinv_get_option('sequential_invoice_number'); |
|
315 | 315 | } |
316 | 316 | |
317 | -function wpinv_switch_to_locale( $locale = null ) { |
|
317 | +function wpinv_switch_to_locale($locale = null) { |
|
318 | 318 | global $invoicing, $wpi_switch_locale; |
319 | 319 | |
320 | - if ( ! empty( $invoicing ) && function_exists( 'switch_to_locale' ) ) { |
|
321 | - $locale = empty( $locale ) ? get_locale() : $locale; |
|
320 | + if (!empty($invoicing) && function_exists('switch_to_locale')) { |
|
321 | + $locale = empty($locale) ? get_locale() : $locale; |
|
322 | 322 | |
323 | - switch_to_locale( $locale ); |
|
323 | + switch_to_locale($locale); |
|
324 | 324 | |
325 | 325 | $wpi_switch_locale = $locale; |
326 | 326 | |
327 | - add_filter( 'plugin_locale', 'get_locale' ); |
|
327 | + add_filter('plugin_locale', 'get_locale'); |
|
328 | 328 | |
329 | 329 | $invoicing->load_textdomain(); |
330 | 330 | |
331 | - do_action( 'wpinv_switch_to_locale', $locale ); |
|
331 | + do_action('wpinv_switch_to_locale', $locale); |
|
332 | 332 | } |
333 | 333 | } |
334 | 334 | |
335 | 335 | function wpinv_restore_locale() { |
336 | 336 | global $invoicing, $wpi_switch_locale; |
337 | 337 | |
338 | - if ( ! empty( $invoicing ) && function_exists( 'restore_previous_locale' ) && $wpi_switch_locale ) { |
|
338 | + if (!empty($invoicing) && function_exists('restore_previous_locale') && $wpi_switch_locale) { |
|
339 | 339 | restore_previous_locale(); |
340 | 340 | |
341 | 341 | $wpi_switch_locale = null; |
342 | 342 | |
343 | - remove_filter( 'plugin_locale', 'get_locale' ); |
|
343 | + remove_filter('plugin_locale', 'get_locale'); |
|
344 | 344 | |
345 | 345 | $invoicing->load_textdomain(); |
346 | 346 | |
347 | - do_action( 'wpinv_restore_locale' ); |
|
347 | + do_action('wpinv_restore_locale'); |
|
348 | 348 | } |
349 | 349 | } |
350 | 350 | |
@@ -352,26 +352,26 @@ discard block |
||
352 | 352 | * Returns the default form's id. |
353 | 353 | */ |
354 | 354 | function wpinv_get_default_payment_form() { |
355 | - $form = get_option( 'wpinv_default_payment_form' ); |
|
355 | + $form = get_option('wpinv_default_payment_form'); |
|
356 | 356 | |
357 | - if ( empty( $form ) || 'publish' != get_post_status( $form ) ) { |
|
357 | + if (empty($form) || 'publish' != get_post_status($form)) { |
|
358 | 358 | $form = wp_insert_post( |
359 | 359 | array( |
360 | 360 | 'post_type' => 'wpi_payment_form', |
361 | - 'post_title' => __( 'Checkout (default)', 'invoicing' ), |
|
361 | + 'post_title' => __('Checkout (default)', 'invoicing'), |
|
362 | 362 | 'post_status' => 'publish', |
363 | 363 | 'meta_input' => array( |
364 | - 'wpinv_form_elements' => wpinv_get_data( 'default-payment-form' ), |
|
364 | + 'wpinv_form_elements' => wpinv_get_data('default-payment-form'), |
|
365 | 365 | 'wpinv_form_items' => array(), |
366 | 366 | ), |
367 | 367 | ) |
368 | 368 | ); |
369 | 369 | |
370 | - update_option( 'wpinv_default_payment_form', $form ); |
|
370 | + update_option('wpinv_default_payment_form', $form); |
|
371 | 371 | } |
372 | 372 | |
373 | 373 | // WPML support. |
374 | - $form = apply_filters( 'wpml_object_id', $form, 'wpi_payment_form', true ); |
|
374 | + $form = apply_filters('wpml_object_id', $form, 'wpi_payment_form', true); |
|
375 | 375 | return (int) $form; |
376 | 376 | } |
377 | 377 | |
@@ -380,19 +380,19 @@ discard block |
||
380 | 380 | * |
381 | 381 | * @param int $payment_form |
382 | 382 | */ |
383 | -function getpaid_get_payment_form_elements( $payment_form ) { |
|
383 | +function getpaid_get_payment_form_elements($payment_form) { |
|
384 | 384 | |
385 | - if ( empty( $payment_form ) ) { |
|
386 | - return wpinv_get_data( 'sample-payment-form' ); |
|
385 | + if (empty($payment_form)) { |
|
386 | + return wpinv_get_data('sample-payment-form'); |
|
387 | 387 | } |
388 | 388 | |
389 | - $form_elements = get_post_meta( $payment_form, 'wpinv_form_elements', true ); |
|
389 | + $form_elements = get_post_meta($payment_form, 'wpinv_form_elements', true); |
|
390 | 390 | |
391 | - if ( is_array( $form_elements ) ) { |
|
391 | + if (is_array($form_elements)) { |
|
392 | 392 | return $form_elements; |
393 | 393 | } |
394 | 394 | |
395 | - return wpinv_get_data( 'sample-payment-form' ); |
|
395 | + return wpinv_get_data('sample-payment-form'); |
|
396 | 396 | |
397 | 397 | } |
398 | 398 | |
@@ -401,65 +401,65 @@ discard block |
||
401 | 401 | * |
402 | 402 | * @param int $payment_form |
403 | 403 | */ |
404 | -function gepaid_get_form_items( $id ) { |
|
405 | - $form = new GetPaid_Payment_Form( $id ); |
|
404 | +function gepaid_get_form_items($id) { |
|
405 | + $form = new GetPaid_Payment_Form($id); |
|
406 | 406 | |
407 | 407 | // Is this a default form? |
408 | - if ( $form->is_default() ) { |
|
408 | + if ($form->is_default()) { |
|
409 | 409 | return array(); |
410 | 410 | } |
411 | 411 | |
412 | - return $form->get_items( 'view', 'arrays' ); |
|
412 | + return $form->get_items('view', 'arrays'); |
|
413 | 413 | } |
414 | 414 | |
415 | 415 | /** |
416 | 416 | * Trims each line in a paragraph. |
417 | 417 | * |
418 | 418 | */ |
419 | -function gepaid_trim_lines( $content ) { |
|
420 | - return implode( "\n", array_map( 'trim', explode( "\n", $content ) ) ); |
|
419 | +function gepaid_trim_lines($content) { |
|
420 | + return implode("\n", array_map('trim', explode("\n", $content))); |
|
421 | 421 | } |
422 | 422 | |
423 | 423 | |
424 | -function wpinv_add_elementor_widget_categories( $elements_manager ) { |
|
424 | +function wpinv_add_elementor_widget_categories($elements_manager) { |
|
425 | 425 | $elements_manager->add_category( |
426 | 426 | 'getpaid', |
427 | 427 | array( |
428 | - 'title' => esc_html__( 'GetPaid', 'invoicing' ), |
|
428 | + 'title' => esc_html__('GetPaid', 'invoicing'), |
|
429 | 429 | 'icon' => 'fa fa-plug', |
430 | 430 | ) |
431 | 431 | ); |
432 | 432 | } |
433 | -add_filter( 'elementor/elements/categories_registered', 'wpinv_add_elementor_widget_categories' ); |
|
433 | +add_filter('elementor/elements/categories_registered', 'wpinv_add_elementor_widget_categories'); |
|
434 | 434 | |
435 | -function wpinv_alter_elementor_widget_config( $config ) { |
|
435 | +function wpinv_alter_elementor_widget_config($config) { |
|
436 | 436 | |
437 | - if ( ! empty( $config['initial_document']['widgets'] ) ) { |
|
438 | - foreach ( $config['initial_document']['widgets'] as $key => $widget ) { |
|
439 | - if ( substr( $key, 0, 16 ) === 'wp-widget-wpinv_' || $key === 'wp-widget-getpaid' ) { |
|
440 | - $config['initial_document']['widgets'][ $key ]['categories'][] = 'getpaid'; |
|
441 | - $config['initial_document']['widgets'][ $key ]['hide_on_search'] = false; |
|
442 | - $config['initial_document']['widgets'][ $key ]['icon'] = 'eicon-globe'; //@todo if no icons use on page then font-awesome is not loaded, wif we can fifure out how to force load we can use icons. <i class="fas fa-globe-americas"></i><i class="fa-solid fa-earth-americas"></i> |
|
437 | + if (!empty($config['initial_document']['widgets'])) { |
|
438 | + foreach ($config['initial_document']['widgets'] as $key => $widget) { |
|
439 | + if (substr($key, 0, 16) === 'wp-widget-wpinv_' || $key === 'wp-widget-getpaid') { |
|
440 | + $config['initial_document']['widgets'][$key]['categories'][] = 'getpaid'; |
|
441 | + $config['initial_document']['widgets'][$key]['hide_on_search'] = false; |
|
442 | + $config['initial_document']['widgets'][$key]['icon'] = 'eicon-globe'; //@todo if no icons use on page then font-awesome is not loaded, wif we can fifure out how to force load we can use icons. <i class="fas fa-globe-americas"></i><i class="fa-solid fa-earth-americas"></i> |
|
443 | 443 | } |
444 | 444 | } |
445 | 445 | } |
446 | 446 | |
447 | 447 | return $config; |
448 | 448 | } |
449 | -add_filter( 'elementor/editor/localize_settings', 'wpinv_alter_elementor_widget_config' ); |
|
449 | +add_filter('elementor/editor/localize_settings', 'wpinv_alter_elementor_widget_config'); |
|
450 | 450 | |
451 | 451 | function wpinv_get_report_graphs() { |
452 | 452 | |
453 | 453 | return apply_filters( |
454 | 454 | 'getpaid_report_graphs', |
455 | 455 | array( |
456 | - 'sales' => __( 'Earnings', 'invoicing' ), |
|
457 | - 'refunds' => __( 'Refunds', 'invoicing' ), |
|
458 | - 'tax' => __( 'Taxes', 'invoicing' ), |
|
459 | - 'fees' => __( 'Fees', 'invoicing' ), |
|
460 | - 'discount' => __( 'Discounts', 'invoicing' ), |
|
461 | - 'invoices' => __( 'Invoices', 'invoicing' ), |
|
462 | - 'items' => __( 'Purchased Items', 'invoicing' ), |
|
456 | + 'sales' => __('Earnings', 'invoicing'), |
|
457 | + 'refunds' => __('Refunds', 'invoicing'), |
|
458 | + 'tax' => __('Taxes', 'invoicing'), |
|
459 | + 'fees' => __('Fees', 'invoicing'), |
|
460 | + 'discount' => __('Discounts', 'invoicing'), |
|
461 | + 'invoices' => __('Invoices', 'invoicing'), |
|
462 | + 'items' => __('Purchased Items', 'invoicing'), |
|
463 | 463 | ) |
464 | 464 | ); |
465 | 465 |