@@ -14,419 +14,419 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class WPInv_Plugin { |
16 | 16 | |
17 | - /** |
|
18 | - * GetPaid version. |
|
19 | - * |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - public $version; |
|
23 | - |
|
24 | - /** |
|
25 | - * Data container. |
|
26 | - * |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected $data = array(); |
|
30 | - |
|
31 | - /** |
|
32 | - * Form elements instance. |
|
33 | - * |
|
34 | - * @var WPInv_Payment_Form_Elements |
|
35 | - */ |
|
36 | - public $form_elements; |
|
37 | - |
|
38 | - /** |
|
39 | - * Tax instance. |
|
40 | - * |
|
41 | - * @var WPInv_EUVat |
|
42 | - */ |
|
43 | - public $tax; |
|
44 | - |
|
45 | - /** |
|
46 | - * @param array An array of payment gateways. |
|
47 | - */ |
|
48 | - public $gateways; |
|
49 | - |
|
50 | - /** |
|
51 | - * Class constructor. |
|
52 | - */ |
|
53 | - public function __construct() { |
|
54 | - $this->define_constants(); |
|
55 | - $this->includes(); |
|
56 | - $this->init_hooks(); |
|
57 | - $this->set_properties(); |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Sets a custom data property. |
|
62 | - * |
|
63 | - * @param string $prop The prop to set. |
|
64 | - * @param mixed $value The value to retrieve. |
|
65 | - */ |
|
66 | - public function set( $prop, $value ) { |
|
67 | - $this->data[ $prop ] = $value; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Gets a custom data property. |
|
72 | - * |
|
73 | - * @param string $prop The prop to set. |
|
74 | - * @return mixed The value. |
|
75 | - */ |
|
76 | - public function get( $prop ) { |
|
77 | - |
|
78 | - if ( isset( $this->data[ $prop ] ) ) { |
|
79 | - return $this->data[ $prop ]; |
|
80 | - } |
|
81 | - |
|
82 | - return null; |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Define class properties. |
|
87 | - */ |
|
88 | - public function set_properties() { |
|
89 | - |
|
90 | - // Sessions. |
|
91 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
92 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
93 | - $this->tax = new WPInv_EUVat(); |
|
94 | - $this->tax->init(); |
|
95 | - $GLOBALS['wpinv_euvat'] = $this->tax; // Backwards compatibility. |
|
96 | - |
|
97 | - // Init other objects. |
|
98 | - $this->set( 'reports', new WPInv_Reports() ); // TODO: Refactor. |
|
99 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
100 | - $this->set( 'notes', new WPInv_Notes() ); |
|
101 | - $this->set( 'api', new WPInv_API() ); |
|
102 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
103 | - $this->set( 'template', new GetPaid_Template() ); |
|
104 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
105 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
106 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
107 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
108 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
109 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
110 | - |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Define plugin constants. |
|
115 | - */ |
|
116 | - public function define_constants() { |
|
117 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
118 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
119 | - $this->version = WPINV_VERSION; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Hook into actions and filters. |
|
124 | - * |
|
125 | - * @since 1.0.19 |
|
126 | - */ |
|
127 | - protected function init_hooks() { |
|
128 | - /* Internationalize the text strings used. */ |
|
129 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
130 | - |
|
131 | - // Init the plugin after WordPress inits. |
|
132 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
133 | - add_action( 'getpaid_init', array( $this, 'maybe_process_ipn' ), 5 ); |
|
134 | - add_action( 'init', array( &$this, 'wpinv_actions' ) ); |
|
135 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
136 | - |
|
137 | - if ( class_exists( 'BuddyPress' ) ) { |
|
138 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
139 | - } |
|
140 | - |
|
141 | - add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
142 | - add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
143 | - add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
144 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
145 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
146 | - |
|
147 | - // Fires after registering actions. |
|
148 | - do_action( 'wpinv_actions', $this ); |
|
149 | - do_action( 'getpaid_actions', $this ); |
|
150 | - |
|
151 | - } |
|
152 | - |
|
153 | - public function plugins_loaded() { |
|
154 | - /* Internationalize the text strings used. */ |
|
155 | - $this->load_textdomain(); |
|
156 | - |
|
157 | - do_action( 'wpinv_loaded' ); |
|
158 | - |
|
159 | - // Fix oxygen page builder conflict |
|
160 | - if ( function_exists( 'ct_css_output' ) ) { |
|
161 | - wpinv_oxygen_fix_conflict(); |
|
162 | - } |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * Load the translation of the plugin. |
|
167 | - * |
|
168 | - * @since 1.0 |
|
169 | - */ |
|
170 | - public function load_textdomain( $locale = NULL ) { |
|
171 | - if ( empty( $locale ) ) { |
|
172 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
173 | - } |
|
174 | - |
|
175 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
176 | - |
|
177 | - unload_textdomain( 'invoicing' ); |
|
178 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
179 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
180 | - |
|
181 | - /** |
|
182 | - * Define language constants. |
|
183 | - */ |
|
184 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * Include required core files used in admin and on the frontend. |
|
189 | - */ |
|
190 | - public function includes() { |
|
191 | - |
|
192 | - // Start with the settings. |
|
193 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
194 | - |
|
195 | - // Packages/libraries. |
|
196 | - require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
197 | - require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
198 | - |
|
199 | - // Load functions. |
|
200 | - require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
201 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
202 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
203 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
204 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
205 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
206 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
207 | - require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
208 | - require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' ); |
|
209 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
210 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
211 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
212 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
213 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
214 | - require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
215 | - |
|
216 | - // Register autoloader. |
|
217 | - try { |
|
218 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
219 | - } catch ( Exception $e ) { |
|
220 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
221 | - } |
|
222 | - |
|
223 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
224 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
225 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
226 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
227 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
228 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
229 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
230 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
231 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
232 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
233 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
234 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
235 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
236 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
237 | - require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
238 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
239 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
240 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
241 | - require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
242 | - require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
243 | - require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
244 | - |
|
245 | - /** |
|
246 | - * Load the tax class. |
|
247 | - */ |
|
248 | - if ( ! class_exists( 'WPInv_EUVat' ) ) { |
|
249 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
250 | - } |
|
251 | - |
|
252 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
253 | - GetPaid_Post_Types_Admin::init(); |
|
254 | - |
|
255 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
256 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
257 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
258 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
259 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
260 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
261 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
262 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
263 | - // load the user class only on the users.php page |
|
264 | - global $pagenow; |
|
265 | - if($pagenow=='users.php'){ |
|
266 | - new WPInv_Admin_Users(); |
|
267 | - } |
|
268 | - } |
|
269 | - |
|
270 | - // Register cli commands |
|
271 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
272 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
273 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
274 | - } |
|
275 | - |
|
276 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
277 | - } |
|
278 | - |
|
279 | - /** |
|
280 | - * Class autoloader |
|
281 | - * |
|
282 | - * @param string $class_name The name of the class to load. |
|
283 | - * @access public |
|
284 | - * @since 1.0.19 |
|
285 | - * @return void |
|
286 | - */ |
|
287 | - public function autoload( $class_name ) { |
|
288 | - |
|
289 | - // Normalize the class name... |
|
290 | - $class_name = strtolower( $class_name ); |
|
291 | - |
|
292 | - // ... and make sure it is our class. |
|
293 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
294 | - return; |
|
295 | - } |
|
296 | - |
|
297 | - // Next, prepare the file name from the class. |
|
298 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
299 | - |
|
300 | - // Base path of the classes. |
|
301 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
302 | - |
|
303 | - // And an array of possible locations in order of importance. |
|
304 | - $locations = array( |
|
305 | - "$plugin_path/includes", |
|
306 | - "$plugin_path/includes/data-stores", |
|
307 | - "$plugin_path/includes/gateways", |
|
308 | - "$plugin_path/includes/api", |
|
309 | - "$plugin_path/includes/admin", |
|
310 | - "$plugin_path/includes/admin/meta-boxes", |
|
311 | - ); |
|
312 | - |
|
313 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
314 | - |
|
315 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
316 | - include trailingslashit( $location ) . $file_name; |
|
317 | - break; |
|
318 | - } |
|
319 | - |
|
320 | - } |
|
321 | - |
|
322 | - } |
|
323 | - |
|
324 | - /** |
|
325 | - * Inits hooks etc. |
|
326 | - */ |
|
327 | - public function init() { |
|
328 | - |
|
329 | - // Fires before getpaid inits. |
|
330 | - do_action( 'before_getpaid_init', $this ); |
|
331 | - |
|
332 | - // Load default gateways. |
|
333 | - $gateways = apply_filters( |
|
334 | - 'getpaid_default_gateways', |
|
335 | - array( |
|
336 | - 'manual' => 'GetPaid_Manual_Gateway', |
|
337 | - 'paypal' => 'GetPaid_Paypal_Gateway', |
|
338 | - 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
339 | - 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
340 | - 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
341 | - ) |
|
342 | - ); |
|
343 | - |
|
344 | - foreach ( $gateways as $id => $class ) { |
|
345 | - $this->gateways[ $id ] = new $class(); |
|
346 | - } |
|
347 | - |
|
348 | - // Fires after getpaid inits. |
|
349 | - do_action( 'getpaid_init', $this ); |
|
350 | - |
|
351 | - } |
|
352 | - |
|
353 | - /** |
|
354 | - * Checks if this is an IPN request and processes it. |
|
355 | - */ |
|
356 | - public function maybe_process_ipn() { |
|
357 | - |
|
358 | - // Ensure that this is an IPN request. |
|
359 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
360 | - return; |
|
361 | - } |
|
362 | - |
|
363 | - $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
364 | - |
|
365 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
366 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
367 | - exit; |
|
368 | - |
|
369 | - } |
|
370 | - |
|
371 | - public function enqueue_scripts() { |
|
372 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
373 | - |
|
374 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
375 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
376 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
377 | - |
|
378 | - // Register scripts |
|
379 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
380 | - wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ), filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) ); |
|
381 | - |
|
382 | - $localize = array(); |
|
383 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
384 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
385 | - $localize['currency_symbol'] = wpinv_currency_symbol(); |
|
386 | - $localize['currency_pos'] = wpinv_currency_position(); |
|
387 | - $localize['thousand_sep'] = wpinv_thousands_separator(); |
|
388 | - $localize['decimal_sep'] = wpinv_decimal_separator(); |
|
389 | - $localize['decimals'] = wpinv_decimals(); |
|
390 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
391 | - $localize['UseTaxes'] = wpinv_use_taxes(); |
|
392 | - $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
393 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
394 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
395 | - |
|
396 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
397 | - |
|
398 | - wp_enqueue_script( 'jquery-blockui' ); |
|
399 | - $autofill_api = wpinv_get_option('address_autofill_api'); |
|
400 | - $autofill_active = wpinv_get_option('address_autofill_active'); |
|
401 | - if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) { |
|
402 | - if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) { |
|
403 | - wp_dequeue_script( 'google-maps-api' ); |
|
404 | - } |
|
405 | - wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false ); |
|
406 | - wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true ); |
|
407 | - } |
|
408 | - |
|
409 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), WPINV_VERSION, 'all' ); |
|
410 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
411 | - |
|
412 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
413 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
414 | - |
|
415 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
416 | - wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ), $version, true ); |
|
417 | - } |
|
418 | - |
|
419 | - public function wpinv_actions() { |
|
420 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
421 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
422 | - } |
|
423 | - } |
|
424 | - |
|
425 | - /** |
|
17 | + /** |
|
18 | + * GetPaid version. |
|
19 | + * |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + public $version; |
|
23 | + |
|
24 | + /** |
|
25 | + * Data container. |
|
26 | + * |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected $data = array(); |
|
30 | + |
|
31 | + /** |
|
32 | + * Form elements instance. |
|
33 | + * |
|
34 | + * @var WPInv_Payment_Form_Elements |
|
35 | + */ |
|
36 | + public $form_elements; |
|
37 | + |
|
38 | + /** |
|
39 | + * Tax instance. |
|
40 | + * |
|
41 | + * @var WPInv_EUVat |
|
42 | + */ |
|
43 | + public $tax; |
|
44 | + |
|
45 | + /** |
|
46 | + * @param array An array of payment gateways. |
|
47 | + */ |
|
48 | + public $gateways; |
|
49 | + |
|
50 | + /** |
|
51 | + * Class constructor. |
|
52 | + */ |
|
53 | + public function __construct() { |
|
54 | + $this->define_constants(); |
|
55 | + $this->includes(); |
|
56 | + $this->init_hooks(); |
|
57 | + $this->set_properties(); |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Sets a custom data property. |
|
62 | + * |
|
63 | + * @param string $prop The prop to set. |
|
64 | + * @param mixed $value The value to retrieve. |
|
65 | + */ |
|
66 | + public function set( $prop, $value ) { |
|
67 | + $this->data[ $prop ] = $value; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Gets a custom data property. |
|
72 | + * |
|
73 | + * @param string $prop The prop to set. |
|
74 | + * @return mixed The value. |
|
75 | + */ |
|
76 | + public function get( $prop ) { |
|
77 | + |
|
78 | + if ( isset( $this->data[ $prop ] ) ) { |
|
79 | + return $this->data[ $prop ]; |
|
80 | + } |
|
81 | + |
|
82 | + return null; |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Define class properties. |
|
87 | + */ |
|
88 | + public function set_properties() { |
|
89 | + |
|
90 | + // Sessions. |
|
91 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
92 | + $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
93 | + $this->tax = new WPInv_EUVat(); |
|
94 | + $this->tax->init(); |
|
95 | + $GLOBALS['wpinv_euvat'] = $this->tax; // Backwards compatibility. |
|
96 | + |
|
97 | + // Init other objects. |
|
98 | + $this->set( 'reports', new WPInv_Reports() ); // TODO: Refactor. |
|
99 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
100 | + $this->set( 'notes', new WPInv_Notes() ); |
|
101 | + $this->set( 'api', new WPInv_API() ); |
|
102 | + $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
103 | + $this->set( 'template', new GetPaid_Template() ); |
|
104 | + $this->set( 'admin', new GetPaid_Admin() ); |
|
105 | + $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
106 | + $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
107 | + $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
108 | + $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
109 | + $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
110 | + |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Define plugin constants. |
|
115 | + */ |
|
116 | + public function define_constants() { |
|
117 | + define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
118 | + define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
119 | + $this->version = WPINV_VERSION; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Hook into actions and filters. |
|
124 | + * |
|
125 | + * @since 1.0.19 |
|
126 | + */ |
|
127 | + protected function init_hooks() { |
|
128 | + /* Internationalize the text strings used. */ |
|
129 | + add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
130 | + |
|
131 | + // Init the plugin after WordPress inits. |
|
132 | + add_action( 'init', array( $this, 'init' ), 1 ); |
|
133 | + add_action( 'getpaid_init', array( $this, 'maybe_process_ipn' ), 5 ); |
|
134 | + add_action( 'init', array( &$this, 'wpinv_actions' ) ); |
|
135 | + add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
136 | + |
|
137 | + if ( class_exists( 'BuddyPress' ) ) { |
|
138 | + add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
139 | + } |
|
140 | + |
|
141 | + add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
142 | + add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
143 | + add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
144 | + add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
145 | + add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
146 | + |
|
147 | + // Fires after registering actions. |
|
148 | + do_action( 'wpinv_actions', $this ); |
|
149 | + do_action( 'getpaid_actions', $this ); |
|
150 | + |
|
151 | + } |
|
152 | + |
|
153 | + public function plugins_loaded() { |
|
154 | + /* Internationalize the text strings used. */ |
|
155 | + $this->load_textdomain(); |
|
156 | + |
|
157 | + do_action( 'wpinv_loaded' ); |
|
158 | + |
|
159 | + // Fix oxygen page builder conflict |
|
160 | + if ( function_exists( 'ct_css_output' ) ) { |
|
161 | + wpinv_oxygen_fix_conflict(); |
|
162 | + } |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Load the translation of the plugin. |
|
167 | + * |
|
168 | + * @since 1.0 |
|
169 | + */ |
|
170 | + public function load_textdomain( $locale = NULL ) { |
|
171 | + if ( empty( $locale ) ) { |
|
172 | + $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
173 | + } |
|
174 | + |
|
175 | + $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
176 | + |
|
177 | + unload_textdomain( 'invoicing' ); |
|
178 | + load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
179 | + load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
180 | + |
|
181 | + /** |
|
182 | + * Define language constants. |
|
183 | + */ |
|
184 | + require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * Include required core files used in admin and on the frontend. |
|
189 | + */ |
|
190 | + public function includes() { |
|
191 | + |
|
192 | + // Start with the settings. |
|
193 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
194 | + |
|
195 | + // Packages/libraries. |
|
196 | + require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
197 | + require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
198 | + |
|
199 | + // Load functions. |
|
200 | + require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
201 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
202 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
203 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
204 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
205 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
206 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
207 | + require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
208 | + require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' ); |
|
209 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
210 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
211 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
212 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
213 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
214 | + require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
215 | + |
|
216 | + // Register autoloader. |
|
217 | + try { |
|
218 | + spl_autoload_register( array( $this, 'autoload' ), true ); |
|
219 | + } catch ( Exception $e ) { |
|
220 | + wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
221 | + } |
|
222 | + |
|
223 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
224 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
225 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
226 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
227 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
228 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
229 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
230 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
231 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
232 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
233 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
234 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
235 | + require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
236 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
237 | + require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
238 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
239 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
240 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
241 | + require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
242 | + require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
243 | + require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
244 | + |
|
245 | + /** |
|
246 | + * Load the tax class. |
|
247 | + */ |
|
248 | + if ( ! class_exists( 'WPInv_EUVat' ) ) { |
|
249 | + require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
250 | + } |
|
251 | + |
|
252 | + if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
253 | + GetPaid_Post_Types_Admin::init(); |
|
254 | + |
|
255 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
256 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
257 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
258 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
259 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
260 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
261 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
262 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
263 | + // load the user class only on the users.php page |
|
264 | + global $pagenow; |
|
265 | + if($pagenow=='users.php'){ |
|
266 | + new WPInv_Admin_Users(); |
|
267 | + } |
|
268 | + } |
|
269 | + |
|
270 | + // Register cli commands |
|
271 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
272 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
273 | + WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
274 | + } |
|
275 | + |
|
276 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
277 | + } |
|
278 | + |
|
279 | + /** |
|
280 | + * Class autoloader |
|
281 | + * |
|
282 | + * @param string $class_name The name of the class to load. |
|
283 | + * @access public |
|
284 | + * @since 1.0.19 |
|
285 | + * @return void |
|
286 | + */ |
|
287 | + public function autoload( $class_name ) { |
|
288 | + |
|
289 | + // Normalize the class name... |
|
290 | + $class_name = strtolower( $class_name ); |
|
291 | + |
|
292 | + // ... and make sure it is our class. |
|
293 | + if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
294 | + return; |
|
295 | + } |
|
296 | + |
|
297 | + // Next, prepare the file name from the class. |
|
298 | + $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
299 | + |
|
300 | + // Base path of the classes. |
|
301 | + $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
302 | + |
|
303 | + // And an array of possible locations in order of importance. |
|
304 | + $locations = array( |
|
305 | + "$plugin_path/includes", |
|
306 | + "$plugin_path/includes/data-stores", |
|
307 | + "$plugin_path/includes/gateways", |
|
308 | + "$plugin_path/includes/api", |
|
309 | + "$plugin_path/includes/admin", |
|
310 | + "$plugin_path/includes/admin/meta-boxes", |
|
311 | + ); |
|
312 | + |
|
313 | + foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
314 | + |
|
315 | + if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
316 | + include trailingslashit( $location ) . $file_name; |
|
317 | + break; |
|
318 | + } |
|
319 | + |
|
320 | + } |
|
321 | + |
|
322 | + } |
|
323 | + |
|
324 | + /** |
|
325 | + * Inits hooks etc. |
|
326 | + */ |
|
327 | + public function init() { |
|
328 | + |
|
329 | + // Fires before getpaid inits. |
|
330 | + do_action( 'before_getpaid_init', $this ); |
|
331 | + |
|
332 | + // Load default gateways. |
|
333 | + $gateways = apply_filters( |
|
334 | + 'getpaid_default_gateways', |
|
335 | + array( |
|
336 | + 'manual' => 'GetPaid_Manual_Gateway', |
|
337 | + 'paypal' => 'GetPaid_Paypal_Gateway', |
|
338 | + 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
339 | + 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
340 | + 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
341 | + ) |
|
342 | + ); |
|
343 | + |
|
344 | + foreach ( $gateways as $id => $class ) { |
|
345 | + $this->gateways[ $id ] = new $class(); |
|
346 | + } |
|
347 | + |
|
348 | + // Fires after getpaid inits. |
|
349 | + do_action( 'getpaid_init', $this ); |
|
350 | + |
|
351 | + } |
|
352 | + |
|
353 | + /** |
|
354 | + * Checks if this is an IPN request and processes it. |
|
355 | + */ |
|
356 | + public function maybe_process_ipn() { |
|
357 | + |
|
358 | + // Ensure that this is an IPN request. |
|
359 | + if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
360 | + return; |
|
361 | + } |
|
362 | + |
|
363 | + $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
364 | + |
|
365 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
366 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
367 | + exit; |
|
368 | + |
|
369 | + } |
|
370 | + |
|
371 | + public function enqueue_scripts() { |
|
372 | + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
373 | + |
|
374 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
375 | + wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
376 | + wp_enqueue_style( 'wpinv_front_style' ); |
|
377 | + |
|
378 | + // Register scripts |
|
379 | + wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
380 | + wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ), filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) ); |
|
381 | + |
|
382 | + $localize = array(); |
|
383 | + $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
384 | + $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
385 | + $localize['currency_symbol'] = wpinv_currency_symbol(); |
|
386 | + $localize['currency_pos'] = wpinv_currency_position(); |
|
387 | + $localize['thousand_sep'] = wpinv_thousands_separator(); |
|
388 | + $localize['decimal_sep'] = wpinv_decimal_separator(); |
|
389 | + $localize['decimals'] = wpinv_decimals(); |
|
390 | + $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
391 | + $localize['UseTaxes'] = wpinv_use_taxes(); |
|
392 | + $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
393 | + $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
394 | + $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
395 | + |
|
396 | + $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
397 | + |
|
398 | + wp_enqueue_script( 'jquery-blockui' ); |
|
399 | + $autofill_api = wpinv_get_option('address_autofill_api'); |
|
400 | + $autofill_active = wpinv_get_option('address_autofill_active'); |
|
401 | + if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) { |
|
402 | + if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) { |
|
403 | + wp_dequeue_script( 'google-maps-api' ); |
|
404 | + } |
|
405 | + wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false ); |
|
406 | + wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true ); |
|
407 | + } |
|
408 | + |
|
409 | + wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), WPINV_VERSION, 'all' ); |
|
410 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
411 | + |
|
412 | + wp_enqueue_script( 'wpinv-front-script' ); |
|
413 | + wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
414 | + |
|
415 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
416 | + wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ), $version, true ); |
|
417 | + } |
|
418 | + |
|
419 | + public function wpinv_actions() { |
|
420 | + if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
421 | + do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
422 | + } |
|
423 | + } |
|
424 | + |
|
425 | + /** |
|
426 | 426 | * Fires an action after verifying that a user can fire them. |
427 | - * |
|
428 | - * Note: If the action is on an invoice, subscription etc, esure that the |
|
429 | - * current user owns the invoice/subscription. |
|
427 | + * |
|
428 | + * Note: If the action is on an invoice, subscription etc, esure that the |
|
429 | + * current user owns the invoice/subscription. |
|
430 | 430 | */ |
431 | 431 | public function maybe_do_authenticated_action() { |
432 | 432 | |
@@ -437,82 +437,82 @@ discard block |
||
437 | 437 | |
438 | 438 | } |
439 | 439 | |
440 | - public function pre_get_posts( $wp_query ) { |
|
441 | - if ( ! is_admin() && !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
442 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
443 | - } |
|
444 | - |
|
445 | - return $wp_query; |
|
446 | - } |
|
447 | - |
|
448 | - public function bp_invoicing_init() { |
|
449 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
450 | - } |
|
451 | - |
|
452 | - /** |
|
453 | - * Register widgets |
|
454 | - * |
|
455 | - */ |
|
456 | - public function register_widgets() { |
|
457 | - $widgets = apply_filters( |
|
458 | - 'getpaid_widget_classes', |
|
459 | - array( |
|
460 | - 'WPInv_Checkout_Widget', |
|
461 | - 'WPInv_History_Widget', |
|
462 | - 'WPInv_Receipt_Widget', |
|
463 | - 'WPInv_Subscriptions_Widget', |
|
464 | - 'WPInv_Buy_Item_Widget', |
|
465 | - 'WPInv_Messages_Widget', |
|
466 | - 'WPInv_GetPaid_Widget' |
|
467 | - ) |
|
468 | - ); |
|
469 | - |
|
470 | - foreach ( $widgets as $widget ) { |
|
471 | - register_widget( $widget ); |
|
472 | - } |
|
440 | + public function pre_get_posts( $wp_query ) { |
|
441 | + if ( ! is_admin() && !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
442 | + $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
443 | + } |
|
444 | + |
|
445 | + return $wp_query; |
|
446 | + } |
|
447 | + |
|
448 | + public function bp_invoicing_init() { |
|
449 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
450 | + } |
|
451 | + |
|
452 | + /** |
|
453 | + * Register widgets |
|
454 | + * |
|
455 | + */ |
|
456 | + public function register_widgets() { |
|
457 | + $widgets = apply_filters( |
|
458 | + 'getpaid_widget_classes', |
|
459 | + array( |
|
460 | + 'WPInv_Checkout_Widget', |
|
461 | + 'WPInv_History_Widget', |
|
462 | + 'WPInv_Receipt_Widget', |
|
463 | + 'WPInv_Subscriptions_Widget', |
|
464 | + 'WPInv_Buy_Item_Widget', |
|
465 | + 'WPInv_Messages_Widget', |
|
466 | + 'WPInv_GetPaid_Widget' |
|
467 | + ) |
|
468 | + ); |
|
469 | + |
|
470 | + foreach ( $widgets as $widget ) { |
|
471 | + register_widget( $widget ); |
|
472 | + } |
|
473 | 473 | |
474 | - } |
|
474 | + } |
|
475 | 475 | |
476 | - /** |
|
477 | - * Remove our pages from yoast sitemaps. |
|
478 | - * |
|
479 | - * @since 1.0.19 |
|
480 | - * @param int[] $excluded_posts_ids |
|
481 | - */ |
|
482 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
476 | + /** |
|
477 | + * Remove our pages from yoast sitemaps. |
|
478 | + * |
|
479 | + * @since 1.0.19 |
|
480 | + * @param int[] $excluded_posts_ids |
|
481 | + */ |
|
482 | + public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
483 | 483 | |
484 | - // Ensure that we have an array. |
|
485 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
486 | - $excluded_posts_ids = array(); |
|
487 | - } |
|
484 | + // Ensure that we have an array. |
|
485 | + if ( ! is_array( $excluded_posts_ids ) ) { |
|
486 | + $excluded_posts_ids = array(); |
|
487 | + } |
|
488 | 488 | |
489 | - // Prepare our pages. |
|
490 | - $our_pages = array(); |
|
489 | + // Prepare our pages. |
|
490 | + $our_pages = array(); |
|
491 | 491 | |
492 | - // Checkout page. |
|
493 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
492 | + // Checkout page. |
|
493 | + $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
494 | 494 | |
495 | - // Success page. |
|
496 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
495 | + // Success page. |
|
496 | + $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
497 | 497 | |
498 | - // Failure page. |
|
499 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
498 | + // Failure page. |
|
499 | + $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
500 | 500 | |
501 | - // History page. |
|
502 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
501 | + // History page. |
|
502 | + $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
503 | 503 | |
504 | - // Subscriptions page. |
|
505 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
504 | + // Subscriptions page. |
|
505 | + $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
506 | 506 | |
507 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
507 | + $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
508 | 508 | |
509 | - $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
510 | - return array_unique( $excluded_posts_ids ); |
|
509 | + $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
510 | + return array_unique( $excluded_posts_ids ); |
|
511 | 511 | |
512 | - } |
|
512 | + } |
|
513 | 513 | |
514 | - public function wp_footer() { |
|
515 | - echo ' |
|
514 | + public function wp_footer() { |
|
515 | + echo ' |
|
516 | 516 | <div class="bsui"> |
517 | 517 | <div id="getpaid-payment-modal" class="modal" tabindex="-1" role="dialog"> |
518 | 518 | <div class="modal-dialog modal-dialog-centered modal-lg" role="checkout" style="max-width: 650px;"> |
@@ -523,6 +523,6 @@ discard block |
||
523 | 523 | </div> |
524 | 524 | </div> |
525 | 525 | '; |
526 | - } |
|
526 | + } |
|
527 | 527 | |
528 | 528 | } |
@@ -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 | * Main Invoicing class. |
@@ -63,8 +63,8 @@ discard block |
||
63 | 63 | * @param string $prop The prop to set. |
64 | 64 | * @param mixed $value The value to retrieve. |
65 | 65 | */ |
66 | - public function set( $prop, $value ) { |
|
67 | - $this->data[ $prop ] = $value; |
|
66 | + public function set($prop, $value) { |
|
67 | + $this->data[$prop] = $value; |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
@@ -73,10 +73,10 @@ discard block |
||
73 | 73 | * @param string $prop The prop to set. |
74 | 74 | * @return mixed The value. |
75 | 75 | */ |
76 | - public function get( $prop ) { |
|
76 | + public function get($prop) { |
|
77 | 77 | |
78 | - if ( isset( $this->data[ $prop ] ) ) { |
|
79 | - return $this->data[ $prop ]; |
|
78 | + if (isset($this->data[$prop])) { |
|
79 | + return $this->data[$prop]; |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | return null; |
@@ -88,25 +88,25 @@ discard block |
||
88 | 88 | public function set_properties() { |
89 | 89 | |
90 | 90 | // Sessions. |
91 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
92 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
91 | + $this->set('session', new WPInv_Session_Handler()); |
|
92 | + $GLOBALS['wpi_session'] = $this->get('session'); // Backwards compatibility. |
|
93 | 93 | $this->tax = new WPInv_EUVat(); |
94 | 94 | $this->tax->init(); |
95 | 95 | $GLOBALS['wpinv_euvat'] = $this->tax; // Backwards compatibility. |
96 | 96 | |
97 | 97 | // Init other objects. |
98 | - $this->set( 'reports', new WPInv_Reports() ); // TODO: Refactor. |
|
99 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
100 | - $this->set( 'notes', new WPInv_Notes() ); |
|
101 | - $this->set( 'api', new WPInv_API() ); |
|
102 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
103 | - $this->set( 'template', new GetPaid_Template() ); |
|
104 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
105 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
106 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
107 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
108 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
109 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
98 | + $this->set('reports', new WPInv_Reports()); // TODO: Refactor. |
|
99 | + $this->set('session', new WPInv_Session_Handler()); |
|
100 | + $this->set('notes', new WPInv_Notes()); |
|
101 | + $this->set('api', new WPInv_API()); |
|
102 | + $this->set('post_types', new GetPaid_Post_Types()); |
|
103 | + $this->set('template', new GetPaid_Template()); |
|
104 | + $this->set('admin', new GetPaid_Admin()); |
|
105 | + $this->set('subscriptions', new WPInv_Subscriptions()); |
|
106 | + $this->set('invoice_emails', new GetPaid_Invoice_Notification_Emails()); |
|
107 | + $this->set('subscription_emails', new GetPaid_Subscription_Notification_Emails()); |
|
108 | + $this->set('daily_maintenace', new GetPaid_Daily_Maintenance()); |
|
109 | + $this->set('payment_forms', new GetPaid_Payment_Forms()); |
|
110 | 110 | |
111 | 111 | } |
112 | 112 | |
@@ -114,8 +114,8 @@ discard block |
||
114 | 114 | * Define plugin constants. |
115 | 115 | */ |
116 | 116 | public function define_constants() { |
117 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
118 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
117 | + define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE)); |
|
118 | + define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE)); |
|
119 | 119 | $this->version = WPINV_VERSION; |
120 | 120 | } |
121 | 121 | |
@@ -126,27 +126,27 @@ discard block |
||
126 | 126 | */ |
127 | 127 | protected function init_hooks() { |
128 | 128 | /* Internationalize the text strings used. */ |
129 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
129 | + add_action('plugins_loaded', array(&$this, 'plugins_loaded')); |
|
130 | 130 | |
131 | 131 | // Init the plugin after WordPress inits. |
132 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
133 | - add_action( 'getpaid_init', array( $this, 'maybe_process_ipn' ), 5 ); |
|
134 | - add_action( 'init', array( &$this, 'wpinv_actions' ) ); |
|
135 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
132 | + add_action('init', array($this, 'init'), 1); |
|
133 | + add_action('getpaid_init', array($this, 'maybe_process_ipn'), 5); |
|
134 | + add_action('init', array(&$this, 'wpinv_actions')); |
|
135 | + add_action('init', array($this, 'maybe_do_authenticated_action'), 100); |
|
136 | 136 | |
137 | - if ( class_exists( 'BuddyPress' ) ) { |
|
138 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
137 | + if (class_exists('BuddyPress')) { |
|
138 | + add_action('bp_include', array(&$this, 'bp_invoicing_init')); |
|
139 | 139 | } |
140 | 140 | |
141 | - add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
142 | - add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
143 | - add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
144 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
145 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
141 | + add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts')); |
|
142 | + add_action('wp_footer', array(&$this, 'wp_footer')); |
|
143 | + add_action('widgets_init', array(&$this, 'register_widgets')); |
|
144 | + add_filter('wpseo_exclude_from_sitemap_by_post_ids', array($this, 'wpseo_exclude_from_sitemap_by_post_ids')); |
|
145 | + add_filter('pre_get_posts', array(&$this, 'pre_get_posts')); |
|
146 | 146 | |
147 | 147 | // Fires after registering actions. |
148 | - do_action( 'wpinv_actions', $this ); |
|
149 | - do_action( 'getpaid_actions', $this ); |
|
148 | + do_action('wpinv_actions', $this); |
|
149 | + do_action('getpaid_actions', $this); |
|
150 | 150 | |
151 | 151 | } |
152 | 152 | |
@@ -154,10 +154,10 @@ discard block |
||
154 | 154 | /* Internationalize the text strings used. */ |
155 | 155 | $this->load_textdomain(); |
156 | 156 | |
157 | - do_action( 'wpinv_loaded' ); |
|
157 | + do_action('wpinv_loaded'); |
|
158 | 158 | |
159 | 159 | // Fix oxygen page builder conflict |
160 | - if ( function_exists( 'ct_css_output' ) ) { |
|
160 | + if (function_exists('ct_css_output')) { |
|
161 | 161 | wpinv_oxygen_fix_conflict(); |
162 | 162 | } |
163 | 163 | } |
@@ -167,21 +167,21 @@ discard block |
||
167 | 167 | * |
168 | 168 | * @since 1.0 |
169 | 169 | */ |
170 | - public function load_textdomain( $locale = NULL ) { |
|
171 | - if ( empty( $locale ) ) { |
|
172 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
170 | + public function load_textdomain($locale = NULL) { |
|
171 | + if (empty($locale)) { |
|
172 | + $locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale(); |
|
173 | 173 | } |
174 | 174 | |
175 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
175 | + $locale = apply_filters('plugin_locale', $locale, 'invoicing'); |
|
176 | 176 | |
177 | - unload_textdomain( 'invoicing' ); |
|
178 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
179 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
177 | + unload_textdomain('invoicing'); |
|
178 | + load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo'); |
|
179 | + load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages'); |
|
180 | 180 | |
181 | 181 | /** |
182 | 182 | * Define language constants. |
183 | 183 | */ |
184 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
184 | + require_once(WPINV_PLUGIN_DIR . 'language.php'); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | /** |
@@ -190,90 +190,90 @@ discard block |
||
190 | 190 | public function includes() { |
191 | 191 | |
192 | 192 | // Start with the settings. |
193 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
193 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'); |
|
194 | 194 | |
195 | 195 | // Packages/libraries. |
196 | - require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
197 | - require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
196 | + require_once(WPINV_PLUGIN_DIR . 'vendor/autoload.php'); |
|
197 | + require_once(WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'); |
|
198 | 198 | |
199 | 199 | // Load functions. |
200 | - require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
201 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
202 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
203 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
204 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
205 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
206 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
207 | - require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
208 | - require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' ); |
|
209 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
210 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
211 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
212 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
213 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
214 | - require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
200 | + require_once(WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php'); |
|
201 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'); |
|
202 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'); |
|
203 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'); |
|
204 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'); |
|
205 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'); |
|
206 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'); |
|
207 | + require_once(WPINV_PLUGIN_DIR . 'includes/invoice-functions.php'); |
|
208 | + require_once(WPINV_PLUGIN_DIR . 'includes/subscription-functions.php'); |
|
209 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'); |
|
210 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'); |
|
211 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'); |
|
212 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'); |
|
213 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php'); |
|
214 | + require_once(WPINV_PLUGIN_DIR . 'includes/error-functions.php'); |
|
215 | 215 | |
216 | 216 | // Register autoloader. |
217 | 217 | try { |
218 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
219 | - } catch ( Exception $e ) { |
|
220 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
218 | + spl_autoload_register(array($this, 'autoload'), true); |
|
219 | + } catch (Exception $e) { |
|
220 | + wpinv_error_log($e->getMessage(), '', __FILE__, 149, true); |
|
221 | 221 | } |
222 | 222 | |
223 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
224 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
225 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
226 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
227 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
228 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
229 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
230 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
231 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
232 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
233 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
234 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
235 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
236 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
237 | - require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
238 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
239 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
240 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
241 | - require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
242 | - require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
243 | - require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
223 | + require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'); |
|
224 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'); |
|
225 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'); |
|
226 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'); |
|
227 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php'); |
|
228 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'); |
|
229 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'); |
|
230 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'); |
|
231 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'); |
|
232 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'); |
|
233 | + require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'); |
|
234 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'); |
|
235 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'); |
|
236 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'); |
|
237 | + require_once(WPINV_PLUGIN_DIR . 'widgets/checkout.php'); |
|
238 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'); |
|
239 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'); |
|
240 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'); |
|
241 | + require_once(WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'); |
|
242 | + require_once(WPINV_PLUGIN_DIR . 'widgets/buy-item.php'); |
|
243 | + require_once(WPINV_PLUGIN_DIR . 'widgets/getpaid.php'); |
|
244 | 244 | |
245 | 245 | /** |
246 | 246 | * Load the tax class. |
247 | 247 | */ |
248 | - if ( ! class_exists( 'WPInv_EUVat' ) ) { |
|
249 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
248 | + if (!class_exists('WPInv_EUVat')) { |
|
249 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php'); |
|
250 | 250 | } |
251 | 251 | |
252 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
252 | + if (is_admin() || (defined('WP_CLI') && WP_CLI)) { |
|
253 | 253 | GetPaid_Post_Types_Admin::init(); |
254 | 254 | |
255 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
256 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
257 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
258 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
259 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
260 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
261 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
262 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
255 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php'); |
|
256 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'); |
|
257 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'); |
|
258 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'); |
|
259 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'); |
|
260 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'); |
|
261 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'); |
|
262 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'); |
|
263 | 263 | // load the user class only on the users.php page |
264 | 264 | global $pagenow; |
265 | - if($pagenow=='users.php'){ |
|
265 | + if ($pagenow == 'users.php') { |
|
266 | 266 | new WPInv_Admin_Users(); |
267 | 267 | } |
268 | 268 | } |
269 | 269 | |
270 | 270 | // Register cli commands |
271 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
272 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
273 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
271 | + if (defined('WP_CLI') && WP_CLI) { |
|
272 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'); |
|
273 | + WP_CLI::add_command('invoicing', 'WPInv_CLI'); |
|
274 | 274 | } |
275 | 275 | |
276 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
276 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php'); |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | /** |
@@ -284,21 +284,21 @@ discard block |
||
284 | 284 | * @since 1.0.19 |
285 | 285 | * @return void |
286 | 286 | */ |
287 | - public function autoload( $class_name ) { |
|
287 | + public function autoload($class_name) { |
|
288 | 288 | |
289 | 289 | // Normalize the class name... |
290 | - $class_name = strtolower( $class_name ); |
|
290 | + $class_name = strtolower($class_name); |
|
291 | 291 | |
292 | 292 | // ... and make sure it is our class. |
293 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
293 | + if (false === strpos($class_name, 'getpaid_') && false === strpos($class_name, 'wpinv_')) { |
|
294 | 294 | return; |
295 | 295 | } |
296 | 296 | |
297 | 297 | // Next, prepare the file name from the class. |
298 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
298 | + $file_name = 'class-' . str_replace('_', '-', $class_name) . '.php'; |
|
299 | 299 | |
300 | 300 | // Base path of the classes. |
301 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
301 | + $plugin_path = untrailingslashit(WPINV_PLUGIN_DIR); |
|
302 | 302 | |
303 | 303 | // And an array of possible locations in order of importance. |
304 | 304 | $locations = array( |
@@ -310,10 +310,10 @@ discard block |
||
310 | 310 | "$plugin_path/includes/admin/meta-boxes", |
311 | 311 | ); |
312 | 312 | |
313 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
313 | + foreach (apply_filters('getpaid_autoload_locations', $locations) as $location) { |
|
314 | 314 | |
315 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
316 | - include trailingslashit( $location ) . $file_name; |
|
315 | + if (file_exists(trailingslashit($location) . $file_name)) { |
|
316 | + include trailingslashit($location) . $file_name; |
|
317 | 317 | break; |
318 | 318 | } |
319 | 319 | |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | public function init() { |
328 | 328 | |
329 | 329 | // Fires before getpaid inits. |
330 | - do_action( 'before_getpaid_init', $this ); |
|
330 | + do_action('before_getpaid_init', $this); |
|
331 | 331 | |
332 | 332 | // Load default gateways. |
333 | 333 | $gateways = apply_filters( |
@@ -341,12 +341,12 @@ discard block |
||
341 | 341 | ) |
342 | 342 | ); |
343 | 343 | |
344 | - foreach ( $gateways as $id => $class ) { |
|
345 | - $this->gateways[ $id ] = new $class(); |
|
344 | + foreach ($gateways as $id => $class) { |
|
345 | + $this->gateways[$id] = new $class(); |
|
346 | 346 | } |
347 | 347 | |
348 | 348 | // Fires after getpaid inits. |
349 | - do_action( 'getpaid_init', $this ); |
|
349 | + do_action('getpaid_init', $this); |
|
350 | 350 | |
351 | 351 | } |
352 | 352 | |
@@ -356,69 +356,69 @@ discard block |
||
356 | 356 | public function maybe_process_ipn() { |
357 | 357 | |
358 | 358 | // Ensure that this is an IPN request. |
359 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
359 | + if (empty($_GET['wpi-listener']) || 'IPN' !== $_GET['wpi-listener'] || empty($_GET['wpi-gateway'])) { |
|
360 | 360 | return; |
361 | 361 | } |
362 | 362 | |
363 | - $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
363 | + $gateway = wpinv_clean($_GET['wpi-gateway']); |
|
364 | 364 | |
365 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
366 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
365 | + do_action('wpinv_verify_payment_ipn', $gateway); |
|
366 | + do_action("wpinv_verify_{$gateway}_ipn"); |
|
367 | 367 | exit; |
368 | 368 | |
369 | 369 | } |
370 | 370 | |
371 | 371 | public function enqueue_scripts() { |
372 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
372 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
373 | 373 | |
374 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
375 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
376 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
374 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css'); |
|
375 | + wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version); |
|
376 | + wp_enqueue_style('wpinv_front_style'); |
|
377 | 377 | |
378 | 378 | // Register scripts |
379 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
380 | - wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ), filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) ); |
|
379 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
380 | + wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array('jquery'), filemtime(WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js')); |
|
381 | 381 | |
382 | 382 | $localize = array(); |
383 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
384 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
383 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
384 | + $localize['nonce'] = wp_create_nonce('wpinv-nonce'); |
|
385 | 385 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
386 | 386 | $localize['currency_pos'] = wpinv_currency_position(); |
387 | 387 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
388 | 388 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
389 | 389 | $localize['decimals'] = wpinv_decimals(); |
390 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
390 | + $localize['txtComplete'] = __('Continue', 'invoicing'); |
|
391 | 391 | $localize['UseTaxes'] = wpinv_use_taxes(); |
392 | - $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
393 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
394 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
392 | + $localize['checkoutNonce'] = wp_create_nonce('wpinv_checkout_nonce'); |
|
393 | + $localize['formNonce'] = wp_create_nonce('getpaid_form_nonce'); |
|
394 | + $localize['connectionError'] = __('Could not establish a connection to the server.', 'invoicing'); |
|
395 | 395 | |
396 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
396 | + $localize = apply_filters('wpinv_front_js_localize', $localize); |
|
397 | 397 | |
398 | - wp_enqueue_script( 'jquery-blockui' ); |
|
398 | + wp_enqueue_script('jquery-blockui'); |
|
399 | 399 | $autofill_api = wpinv_get_option('address_autofill_api'); |
400 | 400 | $autofill_active = wpinv_get_option('address_autofill_active'); |
401 | - if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) { |
|
402 | - if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) { |
|
403 | - wp_dequeue_script( 'google-maps-api' ); |
|
401 | + if (isset($autofill_active) && 1 == $autofill_active && !empty($autofill_api) && wpinv_is_checkout()) { |
|
402 | + if (wp_script_is('google-maps-api', 'enqueued')) { |
|
403 | + wp_dequeue_script('google-maps-api'); |
|
404 | 404 | } |
405 | - wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false ); |
|
406 | - wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true ); |
|
405 | + wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array('jquery'), '', false); |
|
406 | + wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery', 'google-maps-api'), '', true); |
|
407 | 407 | } |
408 | 408 | |
409 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), WPINV_VERSION, 'all' ); |
|
410 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
409 | + wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), WPINV_VERSION, 'all'); |
|
410 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
411 | 411 | |
412 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
413 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
412 | + wp_enqueue_script('wpinv-front-script'); |
|
413 | + wp_localize_script('wpinv-front-script', 'WPInv', $localize); |
|
414 | 414 | |
415 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
416 | - wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ), $version, true ); |
|
415 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js'); |
|
416 | + wp_enqueue_script('wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array('wpinv-front-script', 'wp-hooks'), $version, true); |
|
417 | 417 | } |
418 | 418 | |
419 | 419 | public function wpinv_actions() { |
420 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
421 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
420 | + if (isset($_REQUEST['wpi_action'])) { |
|
421 | + do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST); |
|
422 | 422 | } |
423 | 423 | } |
424 | 424 | |
@@ -430,23 +430,23 @@ discard block |
||
430 | 430 | */ |
431 | 431 | public function maybe_do_authenticated_action() { |
432 | 432 | |
433 | - if ( is_user_logged_in() && isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
434 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
435 | - do_action( "getpaid_authenticated_action_$key", $_REQUEST ); |
|
433 | + if (is_user_logged_in() && isset($_REQUEST['getpaid-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) { |
|
434 | + $key = sanitize_key($_REQUEST['getpaid-action']); |
|
435 | + do_action("getpaid_authenticated_action_$key", $_REQUEST); |
|
436 | 436 | } |
437 | 437 | |
438 | 438 | } |
439 | 439 | |
440 | - public function pre_get_posts( $wp_query ) { |
|
441 | - if ( ! is_admin() && !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
442 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
440 | + public function pre_get_posts($wp_query) { |
|
441 | + if (!is_admin() && !empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query()) { |
|
442 | + $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses()); |
|
443 | 443 | } |
444 | 444 | |
445 | 445 | return $wp_query; |
446 | 446 | } |
447 | 447 | |
448 | 448 | public function bp_invoicing_init() { |
449 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
449 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php'); |
|
450 | 450 | } |
451 | 451 | |
452 | 452 | /** |
@@ -467,8 +467,8 @@ discard block |
||
467 | 467 | ) |
468 | 468 | ); |
469 | 469 | |
470 | - foreach ( $widgets as $widget ) { |
|
471 | - register_widget( $widget ); |
|
470 | + foreach ($widgets as $widget) { |
|
471 | + register_widget($widget); |
|
472 | 472 | } |
473 | 473 | |
474 | 474 | } |
@@ -479,10 +479,10 @@ discard block |
||
479 | 479 | * @since 1.0.19 |
480 | 480 | * @param int[] $excluded_posts_ids |
481 | 481 | */ |
482 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
482 | + public function wpseo_exclude_from_sitemap_by_post_ids($excluded_posts_ids) { |
|
483 | 483 | |
484 | 484 | // Ensure that we have an array. |
485 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
485 | + if (!is_array($excluded_posts_ids)) { |
|
486 | 486 | $excluded_posts_ids = array(); |
487 | 487 | } |
488 | 488 | |
@@ -490,24 +490,24 @@ discard block |
||
490 | 490 | $our_pages = array(); |
491 | 491 | |
492 | 492 | // Checkout page. |
493 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
493 | + $our_pages[] = wpinv_get_option('checkout_page', false); |
|
494 | 494 | |
495 | 495 | // Success page. |
496 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
496 | + $our_pages[] = wpinv_get_option('success_page', false); |
|
497 | 497 | |
498 | 498 | // Failure page. |
499 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
499 | + $our_pages[] = wpinv_get_option('failure_page', false); |
|
500 | 500 | |
501 | 501 | // History page. |
502 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
502 | + $our_pages[] = wpinv_get_option('invoice_history_page', false); |
|
503 | 503 | |
504 | 504 | // Subscriptions page. |
505 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
505 | + $our_pages[] = wpinv_get_option('invoice_subscription_page', false); |
|
506 | 506 | |
507 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
507 | + $our_pages = array_map('intval', array_filter($our_pages)); |
|
508 | 508 | |
509 | 509 | $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
510 | - return array_unique( $excluded_posts_ids ); |
|
510 | + return array_unique($excluded_posts_ids); |
|
511 | 511 | |
512 | 512 | } |
513 | 513 |
@@ -7,172 +7,172 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
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 | function wpinv_get_history_page_uri() { |
47 | - $page_id = wpinv_get_option( 'invoice_history_page', 0 ); |
|
48 | - $page_id = absint( $page_id ); |
|
47 | + $page_id = wpinv_get_option('invoice_history_page', 0); |
|
48 | + $page_id = absint($page_id); |
|
49 | 49 | |
50 | - return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ) ); |
|
50 | + return apply_filters('wpinv_get_history_page_uri', get_permalink($page_id)); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | function wpinv_is_success_page() { |
54 | - $is_success_page = wpinv_get_option( 'success_page', false ); |
|
55 | - $is_success_page = ! empty( $is_success_page ) ? is_page( $is_success_page ) : false; |
|
54 | + $is_success_page = wpinv_get_option('success_page', false); |
|
55 | + $is_success_page = !empty($is_success_page) ? is_page($is_success_page) : false; |
|
56 | 56 | |
57 | - return apply_filters( 'wpinv_is_success_page', $is_success_page ); |
|
57 | + return apply_filters('wpinv_is_success_page', $is_success_page); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | function wpinv_is_invoice_history_page() { |
61 | - $ret = wpinv_get_option( 'invoice_history_page', false ); |
|
62 | - $ret = $ret ? is_page( $ret ) : false; |
|
63 | - return apply_filters( 'wpinv_is_invoice_history_page', $ret ); |
|
61 | + $ret = wpinv_get_option('invoice_history_page', false); |
|
62 | + $ret = $ret ? is_page($ret) : false; |
|
63 | + return apply_filters('wpinv_is_invoice_history_page', $ret); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | function wpinv_is_subscriptions_history_page() { |
67 | - $ret = wpinv_get_option( 'invoice_subscription_page', false ); |
|
68 | - $ret = $ret ? is_page( $ret ) : false; |
|
69 | - return apply_filters( 'wpinv_is_subscriptions_history_page', $ret ); |
|
67 | + $ret = wpinv_get_option('invoice_subscription_page', false); |
|
68 | + $ret = $ret ? is_page($ret) : false; |
|
69 | + return apply_filters('wpinv_is_subscriptions_history_page', $ret); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
73 | 73 | * Redirects a user the success page. |
74 | 74 | */ |
75 | -function wpinv_send_to_success_page( $args = array() ) { |
|
75 | +function wpinv_send_to_success_page($args = array()) { |
|
76 | 76 | $redirect = add_query_arg( |
77 | - wp_parse_args( $args ), |
|
77 | + wp_parse_args($args), |
|
78 | 78 | wpinv_get_success_page_uri() |
79 | 79 | ); |
80 | 80 | |
81 | - wp_redirect( $redirect ); |
|
81 | + wp_redirect($redirect); |
|
82 | 82 | exit; |
83 | 83 | } |
84 | 84 | |
85 | -function wpinv_send_to_failed_page( $args = null ) { |
|
85 | +function wpinv_send_to_failed_page($args = null) { |
|
86 | 86 | $redirect = wpinv_get_failed_transaction_uri(); |
87 | 87 | |
88 | - if ( !empty( $args ) ) { |
|
88 | + if (!empty($args)) { |
|
89 | 89 | // Check for backward compatibility |
90 | - if ( is_string( $args ) ) |
|
91 | - $args = str_replace( '?', '', $args ); |
|
90 | + if (is_string($args)) |
|
91 | + $args = str_replace('?', '', $args); |
|
92 | 92 | |
93 | - $args = wp_parse_args( $args ); |
|
93 | + $args = wp_parse_args($args); |
|
94 | 94 | |
95 | - $redirect = add_query_arg( $args, $redirect ); |
|
95 | + $redirect = add_query_arg($args, $redirect); |
|
96 | 96 | } |
97 | 97 | |
98 | - $gateway = isset( $_REQUEST['wpi-gateway'] ) ? $_REQUEST['wpi-gateway'] : ''; |
|
98 | + $gateway = isset($_REQUEST['wpi-gateway']) ? $_REQUEST['wpi-gateway'] : ''; |
|
99 | 99 | |
100 | - $redirect = apply_filters( 'wpinv_failed_page_redirect', $redirect, $gateway, $args ); |
|
101 | - wp_redirect( $redirect ); |
|
100 | + $redirect = apply_filters('wpinv_failed_page_redirect', $redirect, $gateway, $args); |
|
101 | + wp_redirect($redirect); |
|
102 | 102 | exit; |
103 | 103 | } |
104 | 104 | |
105 | -function wpinv_get_checkout_uri( $args = array() ) { |
|
106 | - $uri = wpinv_get_option( 'checkout_page', false ); |
|
107 | - $uri = isset( $uri ) ? get_permalink( $uri ) : NULL; |
|
105 | +function wpinv_get_checkout_uri($args = array()) { |
|
106 | + $uri = wpinv_get_option('checkout_page', false); |
|
107 | + $uri = isset($uri) ? get_permalink($uri) : NULL; |
|
108 | 108 | |
109 | - if ( !empty( $args ) ) { |
|
109 | + if (!empty($args)) { |
|
110 | 110 | // Check for backward compatibility |
111 | - if ( is_string( $args ) ) |
|
112 | - $args = str_replace( '?', '', $args ); |
|
111 | + if (is_string($args)) |
|
112 | + $args = str_replace('?', '', $args); |
|
113 | 113 | |
114 | - $args = wp_parse_args( $args ); |
|
114 | + $args = wp_parse_args($args); |
|
115 | 115 | |
116 | - $uri = add_query_arg( $args, $uri ); |
|
116 | + $uri = add_query_arg($args, $uri); |
|
117 | 117 | } |
118 | 118 | |
119 | - $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
119 | + $scheme = defined('FORCE_SSL_ADMIN') && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
120 | 120 | |
121 | - $ajax_url = admin_url( 'admin-ajax.php', $scheme ); |
|
121 | + $ajax_url = admin_url('admin-ajax.php', $scheme); |
|
122 | 122 | |
123 | - if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) { |
|
124 | - $uri = preg_replace( '/^http:/', 'https:', $uri ); |
|
123 | + if ((!preg_match('/^https/', $uri) && preg_match('/^https/', $ajax_url)) || wpinv_is_ssl_enforced()) { |
|
124 | + $uri = preg_replace('/^http:/', 'https:', $uri); |
|
125 | 125 | } |
126 | 126 | |
127 | - return apply_filters( 'wpinv_get_checkout_uri', $uri ); |
|
127 | + return apply_filters('wpinv_get_checkout_uri', $uri); |
|
128 | 128 | } |
129 | 129 | |
130 | -function wpinv_get_success_page_url( $query_string = null ) { |
|
131 | - $success_page = wpinv_get_option( 'success_page', 0 ); |
|
132 | - $success_page = get_permalink( $success_page ); |
|
130 | +function wpinv_get_success_page_url($query_string = null) { |
|
131 | + $success_page = wpinv_get_option('success_page', 0); |
|
132 | + $success_page = get_permalink($success_page); |
|
133 | 133 | |
134 | - if ( $query_string ) |
|
134 | + if ($query_string) |
|
135 | 135 | $success_page .= $query_string; |
136 | 136 | |
137 | - return apply_filters( 'wpinv_success_page_url', $success_page ); |
|
137 | + return apply_filters('wpinv_success_page_url', $success_page); |
|
138 | 138 | } |
139 | 139 | |
140 | -function wpinv_get_failed_transaction_uri( $extras = false ) { |
|
141 | - $uri = wpinv_get_option( 'failure_page', '' ); |
|
142 | - $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url(); |
|
140 | +function wpinv_get_failed_transaction_uri($extras = false) { |
|
141 | + $uri = wpinv_get_option('failure_page', ''); |
|
142 | + $uri = !empty($uri) ? trailingslashit(get_permalink($uri)) : home_url(); |
|
143 | 143 | |
144 | - if ( $extras ) |
|
144 | + if ($extras) |
|
145 | 145 | $uri .= $extras; |
146 | 146 | |
147 | - return apply_filters( 'wpinv_get_failed_transaction_uri', $uri ); |
|
147 | + return apply_filters('wpinv_get_failed_transaction_uri', $uri); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | function wpinv_is_failed_transaction_page() { |
151 | - $ret = wpinv_get_option( 'failure_page', false ); |
|
152 | - $ret = isset( $ret ) ? is_page( $ret ) : false; |
|
151 | + $ret = wpinv_get_option('failure_page', false); |
|
152 | + $ret = isset($ret) ? is_page($ret) : false; |
|
153 | 153 | |
154 | - return apply_filters( 'wpinv_is_failure_page', $ret ); |
|
154 | + return apply_filters('wpinv_is_failure_page', $ret); |
|
155 | 155 | } |
156 | 156 | |
157 | -function wpinv_transaction_query( $type = 'start' ) { |
|
157 | +function wpinv_transaction_query($type = 'start') { |
|
158 | 158 | global $wpdb; |
159 | 159 | |
160 | 160 | $wpdb->hide_errors(); |
161 | 161 | |
162 | - if ( ! defined( 'WPINV_USE_TRANSACTIONS' ) ) { |
|
163 | - define( 'WPINV_USE_TRANSACTIONS', true ); |
|
162 | + if (!defined('WPINV_USE_TRANSACTIONS')) { |
|
163 | + define('WPINV_USE_TRANSACTIONS', true); |
|
164 | 164 | } |
165 | 165 | |
166 | - if ( WPINV_USE_TRANSACTIONS ) { |
|
167 | - switch ( $type ) { |
|
166 | + if (WPINV_USE_TRANSACTIONS) { |
|
167 | + switch ($type) { |
|
168 | 168 | case 'commit' : |
169 | - $wpdb->query( 'COMMIT' ); |
|
169 | + $wpdb->query('COMMIT'); |
|
170 | 170 | break; |
171 | 171 | case 'rollback' : |
172 | - $wpdb->query( 'ROLLBACK' ); |
|
172 | + $wpdb->query('ROLLBACK'); |
|
173 | 173 | break; |
174 | 174 | default : |
175 | - $wpdb->query( 'START TRANSACTION' ); |
|
175 | + $wpdb->query('START TRANSACTION'); |
|
176 | 176 | break; |
177 | 177 | } |
178 | 178 | } |
@@ -181,141 +181,141 @@ discard block |
||
181 | 181 | function wpinv_get_prefix() { |
182 | 182 | $invoice_prefix = 'INV-'; |
183 | 183 | |
184 | - return apply_filters( 'wpinv_get_prefix', $invoice_prefix ); |
|
184 | + return apply_filters('wpinv_get_prefix', $invoice_prefix); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | function wpinv_get_business_logo() { |
188 | - $business_logo = wpinv_get_option( 'logo' ); |
|
189 | - return apply_filters( 'wpinv_get_business_logo', $business_logo ); |
|
188 | + $business_logo = wpinv_get_option('logo'); |
|
189 | + return apply_filters('wpinv_get_business_logo', $business_logo); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | function wpinv_get_business_name() { |
193 | 193 | $business_name = wpinv_get_option('store_name'); |
194 | - return apply_filters( 'wpinv_get_business_name', $business_name ); |
|
194 | + return apply_filters('wpinv_get_business_name', $business_name); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | function wpinv_get_blogname() { |
198 | - return wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); |
|
198 | + return wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | function wpinv_get_admin_email() { |
202 | - $admin_email = wpinv_get_option( 'admin_email', get_option( 'admin_email' ) ); |
|
203 | - return apply_filters( 'wpinv_admin_email', $admin_email ); |
|
202 | + $admin_email = wpinv_get_option('admin_email', get_option('admin_email')); |
|
203 | + return apply_filters('wpinv_admin_email', $admin_email); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | function wpinv_get_business_website() { |
207 | - $business_website = home_url( '/' ); |
|
208 | - return apply_filters( 'wpinv_get_business_website', $business_website ); |
|
207 | + $business_website = home_url('/'); |
|
208 | + return apply_filters('wpinv_get_business_website', $business_website); |
|
209 | 209 | } |
210 | 210 | |
211 | -function wpinv_get_terms_text( $invoice_id = 0 ) { |
|
211 | +function wpinv_get_terms_text($invoice_id = 0) { |
|
212 | 212 | $terms_text = ''; |
213 | - return apply_filters( 'wpinv_get_terms_text', $terms_text, $invoice_id ); |
|
213 | + return apply_filters('wpinv_get_terms_text', $terms_text, $invoice_id); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | function wpinv_get_business_footer() { |
217 | - $site_link = '<a target="_blank" href="' . esc_url( wpinv_get_business_website() ) . '">' . esc_html( wpinv_get_business_name() ) . '</a>'; |
|
218 | - $business_footer = wp_sprintf( __( 'Thanks for using %s', 'invoicing' ), $site_link ); |
|
219 | - return apply_filters( 'wpinv_get_business_footer', $business_footer ); |
|
217 | + $site_link = '<a target="_blank" href="' . esc_url(wpinv_get_business_website()) . '">' . esc_html(wpinv_get_business_name()) . '</a>'; |
|
218 | + $business_footer = wp_sprintf(__('Thanks for using %s', 'invoicing'), $site_link); |
|
219 | + return apply_filters('wpinv_get_business_footer', $business_footer); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | function wpinv_checkout_required_fields() { |
223 | 223 | $required_fields = array(); |
224 | 224 | |
225 | 225 | // Let payment gateways and other extensions determine if address fields should be required |
226 | - $require_billing_details = apply_filters( 'wpinv_checkout_required_billing_details', wpinv_use_taxes() ); |
|
226 | + $require_billing_details = apply_filters('wpinv_checkout_required_billing_details', wpinv_use_taxes()); |
|
227 | 227 | |
228 | - if ( $require_billing_details ) { |
|
229 | - if ( (bool)wpinv_get_option( 'fname_mandatory' ) ) { |
|
228 | + if ($require_billing_details) { |
|
229 | + if ((bool) wpinv_get_option('fname_mandatory')) { |
|
230 | 230 | $required_fields['first_name'] = array( |
231 | 231 | 'error_id' => 'invalid_first_name', |
232 | - 'error_message' => __( 'Please enter your first name', 'invoicing' ) |
|
232 | + 'error_message' => __('Please enter your first name', 'invoicing') |
|
233 | 233 | ); |
234 | 234 | } |
235 | - if ( (bool)wpinv_get_option( 'address_mandatory' ) ) { |
|
235 | + if ((bool) wpinv_get_option('address_mandatory')) { |
|
236 | 236 | $required_fields['address'] = array( |
237 | 237 | 'error_id' => 'invalid_address', |
238 | - 'error_message' => __( 'Please enter your address', 'invoicing' ) |
|
238 | + 'error_message' => __('Please enter your address', 'invoicing') |
|
239 | 239 | ); |
240 | 240 | } |
241 | - if ( (bool)wpinv_get_option( 'city_mandatory' ) ) { |
|
241 | + if ((bool) wpinv_get_option('city_mandatory')) { |
|
242 | 242 | $required_fields['city'] = array( |
243 | 243 | 'error_id' => 'invalid_city', |
244 | - 'error_message' => __( 'Please enter your billing city', 'invoicing' ) |
|
244 | + 'error_message' => __('Please enter your billing city', 'invoicing') |
|
245 | 245 | ); |
246 | 246 | } |
247 | - if ( (bool)wpinv_get_option( 'state_mandatory' ) ) { |
|
247 | + if ((bool) wpinv_get_option('state_mandatory')) { |
|
248 | 248 | $required_fields['state'] = array( |
249 | 249 | 'error_id' => 'invalid_state', |
250 | - 'error_message' => __( 'Please enter billing state / province', 'invoicing' ) |
|
250 | + 'error_message' => __('Please enter billing state / province', 'invoicing') |
|
251 | 251 | ); |
252 | 252 | } |
253 | - if ( (bool)wpinv_get_option( 'country_mandatory' ) ) { |
|
253 | + if ((bool) wpinv_get_option('country_mandatory')) { |
|
254 | 254 | $required_fields['country'] = array( |
255 | 255 | 'error_id' => 'invalid_country', |
256 | - 'error_message' => __( 'Please select your billing country', 'invoicing' ) |
|
256 | + 'error_message' => __('Please select your billing country', 'invoicing') |
|
257 | 257 | ); |
258 | 258 | } |
259 | 259 | } |
260 | 260 | |
261 | - return apply_filters( 'wpinv_checkout_required_fields', $required_fields ); |
|
261 | + return apply_filters('wpinv_checkout_required_fields', $required_fields); |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | function wpinv_is_ssl_enforced() { |
265 | - $ssl_enforced = wpinv_get_option( 'enforce_ssl', false ); |
|
266 | - return (bool) apply_filters( 'wpinv_is_ssl_enforced', $ssl_enforced ); |
|
265 | + $ssl_enforced = wpinv_get_option('enforce_ssl', false); |
|
266 | + return (bool) apply_filters('wpinv_is_ssl_enforced', $ssl_enforced); |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | function wpinv_schedule_event_twicedaily() { |
270 | 270 | wpinv_email_payment_reminders(); |
271 | 271 | } |
272 | -add_action( 'wpinv_register_schedule_event_daily', 'wpinv_schedule_event_twicedaily' ); |
|
272 | +add_action('wpinv_register_schedule_event_daily', 'wpinv_schedule_event_twicedaily'); |
|
273 | 273 | |
274 | 274 | function wpinv_require_login_to_checkout() { |
275 | - $return = wpinv_get_option( 'login_to_checkout', false ); |
|
276 | - return (bool) apply_filters( 'wpinv_require_login_to_checkout', $return ); |
|
275 | + $return = wpinv_get_option('login_to_checkout', false); |
|
276 | + return (bool) apply_filters('wpinv_require_login_to_checkout', $return); |
|
277 | 277 | } |
278 | 278 | |
279 | -function wpinv_sequential_number_active( $type = '' ) { |
|
280 | - $check = apply_filters( 'wpinv_pre_check_sequential_number_active', null, $type ); |
|
281 | - if ( null !== $check ) { |
|
279 | +function wpinv_sequential_number_active($type = '') { |
|
280 | + $check = apply_filters('wpinv_pre_check_sequential_number_active', null, $type); |
|
281 | + if (null !== $check) { |
|
282 | 282 | return $check; |
283 | 283 | } |
284 | 284 | |
285 | - return wpinv_get_option( 'sequential_invoice_number' ); |
|
285 | + return wpinv_get_option('sequential_invoice_number'); |
|
286 | 286 | } |
287 | 287 | |
288 | -function wpinv_switch_to_locale( $locale = NULL ) { |
|
288 | +function wpinv_switch_to_locale($locale = NULL) { |
|
289 | 289 | global $invoicing, $wpi_switch_locale; |
290 | 290 | |
291 | - if ( ! empty( $invoicing ) && function_exists( 'switch_to_locale' ) ) { |
|
292 | - $locale = empty( $locale ) ? get_locale() : $locale; |
|
291 | + if (!empty($invoicing) && function_exists('switch_to_locale')) { |
|
292 | + $locale = empty($locale) ? get_locale() : $locale; |
|
293 | 293 | |
294 | - switch_to_locale( $locale ); |
|
294 | + switch_to_locale($locale); |
|
295 | 295 | |
296 | 296 | $wpi_switch_locale = $locale; |
297 | 297 | |
298 | - add_filter( 'plugin_locale', 'get_locale' ); |
|
298 | + add_filter('plugin_locale', 'get_locale'); |
|
299 | 299 | |
300 | 300 | $invoicing->load_textdomain(); |
301 | 301 | |
302 | - do_action( 'wpinv_switch_to_locale', $locale ); |
|
302 | + do_action('wpinv_switch_to_locale', $locale); |
|
303 | 303 | } |
304 | 304 | } |
305 | 305 | |
306 | 306 | function wpinv_restore_locale() { |
307 | 307 | global $invoicing, $wpi_switch_locale; |
308 | 308 | |
309 | - if ( ! empty( $invoicing ) && function_exists( 'restore_previous_locale' ) && $wpi_switch_locale ) { |
|
309 | + if (!empty($invoicing) && function_exists('restore_previous_locale') && $wpi_switch_locale) { |
|
310 | 310 | restore_previous_locale(); |
311 | 311 | |
312 | 312 | $wpi_switch_locale = NULL; |
313 | 313 | |
314 | - remove_filter( 'plugin_locale', 'get_locale' ); |
|
314 | + remove_filter('plugin_locale', 'get_locale'); |
|
315 | 315 | |
316 | 316 | $invoicing->load_textdomain(); |
317 | 317 | |
318 | - do_action( 'wpinv_restore_locale' ); |
|
318 | + do_action('wpinv_restore_locale'); |
|
319 | 319 | } |
320 | 320 | } |
321 | 321 | |
@@ -323,22 +323,22 @@ discard block |
||
323 | 323 | * Returns the default form's id. |
324 | 324 | */ |
325 | 325 | function wpinv_get_default_payment_form() { |
326 | - $form = get_option( 'wpinv_default_payment_form' ); |
|
326 | + $form = get_option('wpinv_default_payment_form'); |
|
327 | 327 | |
328 | - if ( empty( $form ) || 'publish' != get_post_status( $form ) ) { |
|
328 | + if (empty($form) || 'publish' != get_post_status($form)) { |
|
329 | 329 | $form = wp_insert_post( |
330 | 330 | array( |
331 | 331 | 'post_type' => 'wpi_payment_form', |
332 | - 'post_title' => __( 'Checkout (default)', 'invoicing' ), |
|
332 | + 'post_title' => __('Checkout (default)', 'invoicing'), |
|
333 | 333 | 'post_status' => 'publish', |
334 | 334 | 'meta_input' => array( |
335 | - 'wpinv_form_elements' => wpinv_get_data( 'default-payment-form' ), |
|
335 | + 'wpinv_form_elements' => wpinv_get_data('default-payment-form'), |
|
336 | 336 | 'wpinv_form_items' => array(), |
337 | 337 | ) |
338 | 338 | ) |
339 | 339 | ); |
340 | 340 | |
341 | - update_option( 'wpinv_default_payment_form', $form ); |
|
341 | + update_option('wpinv_default_payment_form', $form); |
|
342 | 342 | } |
343 | 343 | |
344 | 344 | return $form; |
@@ -349,19 +349,19 @@ discard block |
||
349 | 349 | * |
350 | 350 | * @param int $payment_form |
351 | 351 | */ |
352 | -function getpaid_get_payment_form_elements( $payment_form ) { |
|
352 | +function getpaid_get_payment_form_elements($payment_form) { |
|
353 | 353 | |
354 | - if ( empty( $payment_form ) ) { |
|
355 | - return wpinv_get_data( 'sample-payment-form' ); |
|
354 | + if (empty($payment_form)) { |
|
355 | + return wpinv_get_data('sample-payment-form'); |
|
356 | 356 | } |
357 | 357 | |
358 | - $form_elements = get_post_meta( $payment_form, 'wpinv_form_elements', true ); |
|
358 | + $form_elements = get_post_meta($payment_form, 'wpinv_form_elements', true); |
|
359 | 359 | |
360 | - if ( is_array( $form_elements ) ) { |
|
360 | + if (is_array($form_elements)) { |
|
361 | 361 | return $form_elements; |
362 | 362 | } |
363 | 363 | |
364 | - return wpinv_get_data( 'sample-payment-form' ); |
|
364 | + return wpinv_get_data('sample-payment-form'); |
|
365 | 365 | |
366 | 366 | } |
367 | 367 | |
@@ -370,13 +370,13 @@ discard block |
||
370 | 370 | * |
371 | 371 | * @param int $payment_form |
372 | 372 | */ |
373 | -function gepaid_get_form_items( $id ) { |
|
374 | - $form = new GetPaid_Payment_Form( $id ); |
|
373 | +function gepaid_get_form_items($id) { |
|
374 | + $form = new GetPaid_Payment_Form($id); |
|
375 | 375 | |
376 | 376 | // Is this a default form? |
377 | - if ( $form->is_default() ) { |
|
377 | + if ($form->is_default()) { |
|
378 | 378 | return array(); |
379 | 379 | } |
380 | 380 | |
381 | - return $form->get_items( 'view', 'arrays' ); |
|
381 | + return $form->get_items('view', 'arrays'); |
|
382 | 382 | } |
@@ -14,62 +14,62 @@ discard block |
||
14 | 14 | class GetPaid_Admin { |
15 | 15 | |
16 | 16 | /** |
17 | - * Local path to this plugins admin directory |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - public $admin_path; |
|
22 | - |
|
23 | - /** |
|
24 | - * Web path to this plugins admin directory |
|
25 | - * |
|
26 | - * @var string |
|
27 | - */ |
|
17 | + * Local path to this plugins admin directory |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + public $admin_path; |
|
22 | + |
|
23 | + /** |
|
24 | + * Web path to this plugins admin directory |
|
25 | + * |
|
26 | + * @var string |
|
27 | + */ |
|
28 | 28 | public $admin_url; |
29 | 29 | |
30 | 30 | /** |
31 | - * Class constructor. |
|
32 | - */ |
|
33 | - public function __construct(){ |
|
31 | + * Class constructor. |
|
32 | + */ |
|
33 | + public function __construct(){ |
|
34 | 34 | |
35 | 35 | $this->admin_path = plugin_dir_path( __FILE__ ); |
36 | 36 | $this->admin_url = plugins_url( '/', __FILE__ ); |
37 | 37 | |
38 | 38 | if ( is_admin() ) { |
39 | - $this->init_admin_hooks(); |
|
39 | + $this->init_admin_hooks(); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
45 | - * Init action and filter hooks |
|
46 | - * |
|
47 | - */ |
|
48 | - private function init_admin_hooks() { |
|
45 | + * Init action and filter hooks |
|
46 | + * |
|
47 | + */ |
|
48 | + private function init_admin_hooks() { |
|
49 | 49 | add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ) ); |
50 | 50 | add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
51 | 51 | add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) ); |
52 | 52 | add_action( 'admin_init', array( $this, 'activation_redirect') ); |
53 | 53 | add_action( 'admin_init', array( $this, 'maybe_do_admin_action') ); |
54 | - add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
55 | - add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
56 | - add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
57 | - do_action( 'getpaid_init_admin_hooks', $this ); |
|
54 | + add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
55 | + add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
56 | + add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
57 | + do_action( 'getpaid_init_admin_hooks', $this ); |
|
58 | 58 | |
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
62 | - * Register admin scripts |
|
63 | - * |
|
64 | - */ |
|
65 | - public function enqeue_scripts() { |
|
62 | + * Register admin scripts |
|
63 | + * |
|
64 | + */ |
|
65 | + public function enqeue_scripts() { |
|
66 | 66 | global $current_screen, $pagenow; |
67 | 67 | |
68 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
69 | - $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
68 | + $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
69 | + $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
70 | 70 | |
71 | 71 | if ( ! empty( $current_screen->post_type ) ) { |
72 | - $page = $current_screen->post_type; |
|
72 | + $page = $current_screen->post_type; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | // General styles. |
@@ -93,30 +93,30 @@ discard block |
||
93 | 93 | } |
94 | 94 | |
95 | 95 | // Payment form scripts. |
96 | - if ( 'wpi_payment_form' == $page && $editing ) { |
|
96 | + if ( 'wpi_payment_form' == $page && $editing ) { |
|
97 | 97 | $this->load_payment_form_scripts(); |
98 | 98 | } |
99 | 99 | |
100 | 100 | if ( $page == 'wpinv-subscriptions' ) { |
101 | - wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ), WPINV_VERSION ); |
|
102 | - wp_enqueue_script( 'wpinv-sub-admin-script' ); |
|
103 | - } |
|
101 | + wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ), WPINV_VERSION ); |
|
102 | + wp_enqueue_script( 'wpinv-sub-admin-script' ); |
|
103 | + } |
|
104 | 104 | |
105 | - if ( $page == 'wpinv-reports' ) { |
|
106 | - wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' ); |
|
107 | - } |
|
105 | + if ( $page == 'wpinv-reports' ) { |
|
106 | + wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' ); |
|
107 | + } |
|
108 | 108 | |
109 | - if ( $page == 'wpinv-subscriptions' ) { |
|
110 | - wp_enqueue_script( 'postbox' ); |
|
111 | - } |
|
109 | + if ( $page == 'wpinv-subscriptions' ) { |
|
110 | + wp_enqueue_script( 'postbox' ); |
|
111 | + } |
|
112 | 112 | |
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
116 | - * Returns admin js translations. |
|
117 | - * |
|
118 | - */ |
|
119 | - protected function get_admin_i18() { |
|
116 | + * Returns admin js translations. |
|
117 | + * |
|
118 | + */ |
|
119 | + protected function get_admin_i18() { |
|
120 | 120 | global $post; |
121 | 121 | |
122 | 122 | return array( |
@@ -157,32 +157,32 @@ discard block |
||
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
160 | - * Loads payment form js. |
|
161 | - * |
|
162 | - */ |
|
163 | - protected function load_payment_form_scripts() { |
|
160 | + * Loads payment form js. |
|
161 | + * |
|
162 | + */ |
|
163 | + protected function load_payment_form_scripts() { |
|
164 | 164 | global $post; |
165 | 165 | |
166 | 166 | wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION ); |
167 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
168 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
167 | + wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
168 | + wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
169 | 169 | |
170 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
171 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
170 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
171 | + wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
172 | 172 | |
173 | - wp_localize_script( |
|
173 | + wp_localize_script( |
|
174 | 174 | 'wpinv-admin-payment-form-script', |
175 | 175 | 'wpinvPaymentFormAdmin', |
176 | 176 | array( |
177 | - 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
178 | - 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
179 | - 'currency' => wpinv_currency_symbol(), |
|
180 | - 'position' => wpinv_currency_position(), |
|
181 | - 'decimals' => (int) wpinv_decimals(), |
|
182 | - 'thousands_sep' => wpinv_thousands_separator(), |
|
183 | - 'decimals_sep' => wpinv_decimal_separator(), |
|
184 | - 'form_items' => gepaid_get_form_items( $post->ID ), |
|
185 | - 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
177 | + 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
178 | + 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
179 | + 'currency' => wpinv_currency_symbol(), |
|
180 | + 'position' => wpinv_currency_position(), |
|
181 | + 'decimals' => (int) wpinv_decimals(), |
|
182 | + 'thousands_sep' => wpinv_thousands_separator(), |
|
183 | + 'decimals_sep' => wpinv_decimal_separator(), |
|
184 | + 'form_items' => gepaid_get_form_items( $post->ID ), |
|
185 | + 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
186 | 186 | ) |
187 | 187 | ); |
188 | 188 | |
@@ -191,20 +191,20 @@ discard block |
||
191 | 191 | } |
192 | 192 | |
193 | 193 | /** |
194 | - * Add our classes to admin pages. |
|
194 | + * Add our classes to admin pages. |
|
195 | 195 | * |
196 | 196 | * @param string $classes |
197 | 197 | * @return string |
198 | - * |
|
199 | - */ |
|
198 | + * |
|
199 | + */ |
|
200 | 200 | public function admin_body_class( $classes ) { |
201 | - global $pagenow, $post, $current_screen; |
|
201 | + global $pagenow, $post, $current_screen; |
|
202 | 202 | |
203 | 203 | |
204 | 204 | $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
205 | 205 | |
206 | 206 | if ( ! empty( $current_screen->post_type ) ) { |
207 | - $page = $current_screen->post_type; |
|
207 | + $page = $current_screen->post_type; |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | if ( false !== stripos( $page, 'wpi' ) ) { |
@@ -215,27 +215,27 @@ discard block |
||
215 | 215 | $classes .= ' wpinv-cpt wpinv'; |
216 | 216 | } |
217 | 217 | |
218 | - if ( $pagenow == 'post.php' && $page == 'wpi_item' && ! empty( $post ) && ! wpinv_item_is_editable( $post ) ) { |
|
219 | - $classes .= ' wpi-editable-n'; |
|
220 | - } |
|
218 | + if ( $pagenow == 'post.php' && $page == 'wpi_item' && ! empty( $post ) && ! wpinv_item_is_editable( $post ) ) { |
|
219 | + $classes .= ' wpi-editable-n'; |
|
220 | + } |
|
221 | 221 | |
222 | - return $classes; |
|
222 | + return $classes; |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | /** |
226 | - * Maybe show the AyeCode Connect Notice. |
|
227 | - */ |
|
228 | - public function init_ayecode_connect_helper(){ |
|
226 | + * Maybe show the AyeCode Connect Notice. |
|
227 | + */ |
|
228 | + public function init_ayecode_connect_helper(){ |
|
229 | 229 | |
230 | 230 | new AyeCode_Connect_Helper( |
231 | 231 | array( |
232 | - 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
233 | - 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
234 | - 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
235 | - 'connect_button' => __("Connect Site","invoicing"), |
|
236 | - 'connecting_button' => __("Connecting...","invoicing"), |
|
237 | - 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
238 | - 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
232 | + 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
233 | + 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
234 | + 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
235 | + 'connect_button' => __("Connect Site","invoicing"), |
|
236 | + 'connecting_button' => __("Connecting...","invoicing"), |
|
237 | + 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
238 | + 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
239 | 239 | ), |
240 | 240 | array( 'wpi-addons' ) |
241 | 241 | ); |
@@ -247,21 +247,21 @@ discard block |
||
247 | 247 | */ |
248 | 248 | public function activation_redirect() { |
249 | 249 | |
250 | - // Bail if no activation redirect. |
|
251 | - if ( ! get_transient( '_wpinv_activation_redirect' ) || wp_doing_ajax() ) { |
|
252 | - return; |
|
253 | - } |
|
250 | + // Bail if no activation redirect. |
|
251 | + if ( ! get_transient( '_wpinv_activation_redirect' ) || wp_doing_ajax() ) { |
|
252 | + return; |
|
253 | + } |
|
254 | 254 | |
255 | - // Delete the redirect transient. |
|
256 | - delete_transient( '_wpinv_activation_redirect' ); |
|
255 | + // Delete the redirect transient. |
|
256 | + delete_transient( '_wpinv_activation_redirect' ); |
|
257 | 257 | |
258 | - // Bail if activating from network, or bulk |
|
259 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
260 | - return; |
|
261 | - } |
|
258 | + // Bail if activating from network, or bulk |
|
259 | + if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
260 | + return; |
|
261 | + } |
|
262 | 262 | |
263 | - wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
264 | - exit; |
|
263 | + wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
264 | + exit; |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | /** |
@@ -276,150 +276,150 @@ discard block |
||
276 | 276 | |
277 | 277 | } |
278 | 278 | |
279 | - /** |
|
279 | + /** |
|
280 | 280 | * Sends a payment reminder to a customer. |
281 | - * |
|
282 | - * @param array $args |
|
281 | + * |
|
282 | + * @param array $args |
|
283 | 283 | */ |
284 | 284 | public function send_customer_invoice( $args ) { |
285 | - $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
285 | + $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
286 | 286 | |
287 | - if ( $sent ) { |
|
288 | - $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) ); |
|
289 | - } else { |
|
290 | - $this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) ); |
|
291 | - } |
|
287 | + if ( $sent ) { |
|
288 | + $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) ); |
|
289 | + } else { |
|
290 | + $this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) ); |
|
291 | + } |
|
292 | 292 | |
293 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
294 | - exit; |
|
295 | - } |
|
293 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
294 | + exit; |
|
295 | + } |
|
296 | 296 | |
297 | - /** |
|
297 | + /** |
|
298 | 298 | * Sends a payment reminder to a customer. |
299 | - * |
|
300 | - * @param array $args |
|
299 | + * |
|
300 | + * @param array $args |
|
301 | 301 | */ |
302 | 302 | public function send_customer_payment_reminder( $args ) { |
303 | - $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
303 | + $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
304 | 304 | |
305 | - if ( $sent ) { |
|
306 | - $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
307 | - } else { |
|
308 | - $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
309 | - } |
|
305 | + if ( $sent ) { |
|
306 | + $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
307 | + } else { |
|
308 | + $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
309 | + } |
|
310 | 310 | |
311 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
312 | - exit; |
|
313 | - } |
|
311 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
312 | + exit; |
|
313 | + } |
|
314 | 314 | |
315 | 315 | /** |
316 | - * Returns an array of admin notices. |
|
317 | - * |
|
318 | - * @since 1.0.19 |
|
316 | + * Returns an array of admin notices. |
|
317 | + * |
|
318 | + * @since 1.0.19 |
|
319 | 319 | * @return array |
320 | - */ |
|
321 | - public function get_notices() { |
|
322 | - $notices = get_option( 'wpinv_admin_notices' ); |
|
320 | + */ |
|
321 | + public function get_notices() { |
|
322 | + $notices = get_option( 'wpinv_admin_notices' ); |
|
323 | 323 | return is_array( $notices ) ? $notices : array(); |
324 | - } |
|
325 | - |
|
326 | - /** |
|
327 | - * Clears all admin notices |
|
328 | - * |
|
329 | - * @access public |
|
330 | - * @since 1.0.19 |
|
331 | - */ |
|
332 | - public function clear_notices() { |
|
333 | - delete_option( 'wpinv_admin_notices' ); |
|
334 | - } |
|
335 | - |
|
336 | - /** |
|
337 | - * Saves a new admin notice |
|
338 | - * |
|
339 | - * @access public |
|
340 | - * @since 1.0.19 |
|
341 | - */ |
|
342 | - public function save_notice( $type, $message ) { |
|
343 | - $notices = $this->get_notices(); |
|
344 | - |
|
345 | - if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) { |
|
346 | - $notices[ $type ] = array(); |
|
347 | - } |
|
348 | - |
|
349 | - $notices[ $type ][] = $message; |
|
350 | - |
|
351 | - update_option( 'wpinv_admin_notices', $notices ); |
|
352 | - } |
|
353 | - |
|
354 | - /** |
|
355 | - * Displays a success notice |
|
356 | - * |
|
357 | - * @param string $msg The message to qeue. |
|
358 | - * @access public |
|
359 | - * @since 1.0.19 |
|
360 | - */ |
|
361 | - public function show_success( $msg ) { |
|
362 | - $this->save_notice( 'success', $msg ); |
|
363 | - } |
|
364 | - |
|
365 | - /** |
|
366 | - * Displays a error notice |
|
367 | - * |
|
368 | - * @access public |
|
369 | - * @param string $msg The message to qeue. |
|
370 | - * @since 1.0.19 |
|
371 | - */ |
|
372 | - public function show_error( $msg ) { |
|
373 | - $this->save_notice( 'error', $msg ); |
|
374 | - } |
|
375 | - |
|
376 | - /** |
|
377 | - * Displays a warning notice |
|
378 | - * |
|
379 | - * @access public |
|
380 | - * @param string $msg The message to qeue. |
|
381 | - * @since 1.0.19 |
|
382 | - */ |
|
383 | - public function show_warning( $msg ) { |
|
384 | - $this->save_notice( 'warning', $msg ); |
|
385 | - } |
|
386 | - |
|
387 | - /** |
|
388 | - * Displays a info notice |
|
389 | - * |
|
390 | - * @access public |
|
391 | - * @param string $msg The message to qeue. |
|
392 | - * @since 1.0.19 |
|
393 | - */ |
|
394 | - public function show_info( $msg ) { |
|
395 | - $this->save_notice( 'info', $msg ); |
|
396 | - } |
|
397 | - |
|
398 | - /** |
|
399 | - * Show notices |
|
400 | - * |
|
401 | - * @access public |
|
402 | - * @since 1.0.19 |
|
403 | - */ |
|
404 | - public function show_notices() { |
|
324 | + } |
|
325 | + |
|
326 | + /** |
|
327 | + * Clears all admin notices |
|
328 | + * |
|
329 | + * @access public |
|
330 | + * @since 1.0.19 |
|
331 | + */ |
|
332 | + public function clear_notices() { |
|
333 | + delete_option( 'wpinv_admin_notices' ); |
|
334 | + } |
|
335 | + |
|
336 | + /** |
|
337 | + * Saves a new admin notice |
|
338 | + * |
|
339 | + * @access public |
|
340 | + * @since 1.0.19 |
|
341 | + */ |
|
342 | + public function save_notice( $type, $message ) { |
|
343 | + $notices = $this->get_notices(); |
|
344 | + |
|
345 | + if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) { |
|
346 | + $notices[ $type ] = array(); |
|
347 | + } |
|
348 | + |
|
349 | + $notices[ $type ][] = $message; |
|
350 | + |
|
351 | + update_option( 'wpinv_admin_notices', $notices ); |
|
352 | + } |
|
353 | + |
|
354 | + /** |
|
355 | + * Displays a success notice |
|
356 | + * |
|
357 | + * @param string $msg The message to qeue. |
|
358 | + * @access public |
|
359 | + * @since 1.0.19 |
|
360 | + */ |
|
361 | + public function show_success( $msg ) { |
|
362 | + $this->save_notice( 'success', $msg ); |
|
363 | + } |
|
364 | + |
|
365 | + /** |
|
366 | + * Displays a error notice |
|
367 | + * |
|
368 | + * @access public |
|
369 | + * @param string $msg The message to qeue. |
|
370 | + * @since 1.0.19 |
|
371 | + */ |
|
372 | + public function show_error( $msg ) { |
|
373 | + $this->save_notice( 'error', $msg ); |
|
374 | + } |
|
375 | + |
|
376 | + /** |
|
377 | + * Displays a warning notice |
|
378 | + * |
|
379 | + * @access public |
|
380 | + * @param string $msg The message to qeue. |
|
381 | + * @since 1.0.19 |
|
382 | + */ |
|
383 | + public function show_warning( $msg ) { |
|
384 | + $this->save_notice( 'warning', $msg ); |
|
385 | + } |
|
386 | + |
|
387 | + /** |
|
388 | + * Displays a info notice |
|
389 | + * |
|
390 | + * @access public |
|
391 | + * @param string $msg The message to qeue. |
|
392 | + * @since 1.0.19 |
|
393 | + */ |
|
394 | + public function show_info( $msg ) { |
|
395 | + $this->save_notice( 'info', $msg ); |
|
396 | + } |
|
397 | + |
|
398 | + /** |
|
399 | + * Show notices |
|
400 | + * |
|
401 | + * @access public |
|
402 | + * @since 1.0.19 |
|
403 | + */ |
|
404 | + public function show_notices() { |
|
405 | 405 | |
406 | 406 | $notices = $this->get_notices(); |
407 | 407 | $this->clear_notices(); |
408 | 408 | |
409 | - foreach ( $notices as $type => $messages ) { |
|
409 | + foreach ( $notices as $type => $messages ) { |
|
410 | 410 | |
411 | - if ( ! is_array( $messages ) ) { |
|
412 | - continue; |
|
413 | - } |
|
411 | + if ( ! is_array( $messages ) ) { |
|
412 | + continue; |
|
413 | + } |
|
414 | 414 | |
415 | 415 | $type = sanitize_key( $type ); |
416 | - foreach ( $messages as $message ) { |
|
416 | + foreach ( $messages as $message ) { |
|
417 | 417 | $message = wp_kses_post( $message ); |
418 | - echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>"; |
|
418 | + echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>"; |
|
419 | 419 | } |
420 | 420 | |
421 | 421 | } |
422 | 422 | |
423 | - } |
|
423 | + } |
|
424 | 424 | |
425 | 425 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * The main admin class. |
@@ -30,12 +30,12 @@ discard block |
||
30 | 30 | /** |
31 | 31 | * Class constructor. |
32 | 32 | */ |
33 | - public function __construct(){ |
|
33 | + public function __construct() { |
|
34 | 34 | |
35 | - $this->admin_path = plugin_dir_path( __FILE__ ); |
|
36 | - $this->admin_url = plugins_url( '/', __FILE__ ); |
|
35 | + $this->admin_path = plugin_dir_path(__FILE__); |
|
36 | + $this->admin_url = plugins_url('/', __FILE__); |
|
37 | 37 | |
38 | - if ( is_admin() ) { |
|
38 | + if (is_admin()) { |
|
39 | 39 | $this->init_admin_hooks(); |
40 | 40 | } |
41 | 41 | |
@@ -46,15 +46,15 @@ discard block |
||
46 | 46 | * |
47 | 47 | */ |
48 | 48 | private function init_admin_hooks() { |
49 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ) ); |
|
50 | - add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
|
51 | - add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) ); |
|
52 | - add_action( 'admin_init', array( $this, 'activation_redirect') ); |
|
53 | - add_action( 'admin_init', array( $this, 'maybe_do_admin_action') ); |
|
54 | - add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
55 | - add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
56 | - add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
57 | - do_action( 'getpaid_init_admin_hooks', $this ); |
|
49 | + add_action('admin_enqueue_scripts', array($this, 'enqeue_scripts')); |
|
50 | + add_filter('admin_body_class', array($this, 'admin_body_class')); |
|
51 | + add_action('admin_init', array($this, 'init_ayecode_connect_helper')); |
|
52 | + add_action('admin_init', array($this, 'activation_redirect')); |
|
53 | + add_action('admin_init', array($this, 'maybe_do_admin_action')); |
|
54 | + add_action('admin_notices', array($this, 'show_notices')); |
|
55 | + add_action('getpaid_authenticated_admin_action_send_invoice', array($this, 'send_customer_invoice')); |
|
56 | + add_action('getpaid_authenticated_admin_action_send_invoice_reminder', array($this, 'send_customer_payment_reminder')); |
|
57 | + do_action('getpaid_init_admin_hooks', $this); |
|
58 | 58 | |
59 | 59 | } |
60 | 60 | |
@@ -65,49 +65,49 @@ discard block |
||
65 | 65 | public function enqeue_scripts() { |
66 | 66 | global $current_screen, $pagenow; |
67 | 67 | |
68 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
68 | + $page = isset($_GET['page']) ? $_GET['page'] : ''; |
|
69 | 69 | $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
70 | 70 | |
71 | - if ( ! empty( $current_screen->post_type ) ) { |
|
71 | + if (!empty($current_screen->post_type)) { |
|
72 | 72 | $page = $current_screen->post_type; |
73 | 73 | } |
74 | 74 | |
75 | 75 | // General styles. |
76 | - if ( false !== stripos( $page, 'wpi' ) ) { |
|
76 | + if (false !== stripos($page, 'wpi')) { |
|
77 | 77 | |
78 | 78 | // Styles. |
79 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' ); |
|
80 | - wp_enqueue_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array( 'wp-color-picker' ), $version ); |
|
81 | - wp_enqueue_style( 'select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all' ); |
|
82 | - wp_enqueue_style( 'wp_enqueue_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION ); |
|
83 | - wp_enqueue_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui.min.css', array(), '1.8.16' ); |
|
79 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/admin.css'); |
|
80 | + wp_enqueue_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array('wp-color-picker'), $version); |
|
81 | + wp_enqueue_style('select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all'); |
|
82 | + wp_enqueue_style('wp_enqueue_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION); |
|
83 | + wp_enqueue_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui.min.css', array(), '1.8.16'); |
|
84 | 84 | |
85 | 85 | // Scripts. |
86 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '4.0.13', true ); |
|
87 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array( 'jquery' ), WPINV_VERSION ); |
|
86 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '4.0.13', true); |
|
87 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array('jquery'), WPINV_VERSION); |
|
88 | 88 | |
89 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' ); |
|
90 | - wp_enqueue_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip', 'wp-color-picker', 'jquery-ui-datepicker' ), $version ); |
|
91 | - wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', apply_filters( 'wpinv_admin_js_localize', $this->get_admin_i18() ) ); |
|
89 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin.js'); |
|
90 | + wp_enqueue_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array('jquery', 'jquery-blockui', 'jquery-ui-tooltip', 'wp-color-picker', 'jquery-ui-datepicker'), $version); |
|
91 | + wp_localize_script('wpinv-admin-script', 'WPInv_Admin', apply_filters('wpinv_admin_js_localize', $this->get_admin_i18())); |
|
92 | 92 | |
93 | 93 | } |
94 | 94 | |
95 | 95 | // Payment form scripts. |
96 | - if ( 'wpi_payment_form' == $page && $editing ) { |
|
96 | + if ('wpi_payment_form' == $page && $editing) { |
|
97 | 97 | $this->load_payment_form_scripts(); |
98 | 98 | } |
99 | 99 | |
100 | - if ( $page == 'wpinv-subscriptions' ) { |
|
101 | - wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ), WPINV_VERSION ); |
|
102 | - wp_enqueue_script( 'wpinv-sub-admin-script' ); |
|
100 | + if ($page == 'wpinv-subscriptions') { |
|
101 | + wp_register_script('wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array('wpinv-admin-script'), WPINV_VERSION); |
|
102 | + wp_enqueue_script('wpinv-sub-admin-script'); |
|
103 | 103 | } |
104 | 104 | |
105 | - if ( $page == 'wpinv-reports' ) { |
|
106 | - wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' ); |
|
105 | + if ($page == 'wpinv-reports') { |
|
106 | + wp_enqueue_script('jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array('jquery'), '0.7'); |
|
107 | 107 | } |
108 | 108 | |
109 | - if ( $page == 'wpinv-subscriptions' ) { |
|
110 | - wp_enqueue_script( 'postbox' ); |
|
109 | + if ($page == 'wpinv-subscriptions') { |
|
110 | + wp_enqueue_script('postbox'); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | } |
@@ -120,13 +120,13 @@ discard block |
||
120 | 120 | global $post; |
121 | 121 | |
122 | 122 | return array( |
123 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
124 | - 'post_ID' => isset( $post->ID ) ? $post->ID : '', |
|
125 | - 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
126 | - 'add_invoice_note_nonce' => wp_create_nonce( 'add-invoice-note' ), |
|
127 | - 'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ), |
|
128 | - 'invoice_item_nonce' => wp_create_nonce( 'invoice-item' ), |
|
129 | - 'billing_details_nonce' => wp_create_nonce( 'get-billing-details' ), |
|
123 | + 'ajax_url' => admin_url('admin-ajax.php'), |
|
124 | + 'post_ID' => isset($post->ID) ? $post->ID : '', |
|
125 | + 'wpinv_nonce' => wp_create_nonce('wpinv-nonce'), |
|
126 | + 'add_invoice_note_nonce' => wp_create_nonce('add-invoice-note'), |
|
127 | + 'delete_invoice_note_nonce' => wp_create_nonce('delete-invoice-note'), |
|
128 | + 'invoice_item_nonce' => wp_create_nonce('invoice-item'), |
|
129 | + 'billing_details_nonce' => wp_create_nonce('get-billing-details'), |
|
130 | 130 | 'tax' => wpinv_tax_amount(), |
131 | 131 | 'discount' => wpinv_discount_amount(), |
132 | 132 | 'currency_symbol' => wpinv_currency_symbol(), |
@@ -134,24 +134,24 @@ discard block |
||
134 | 134 | 'thousand_sep' => wpinv_thousands_separator(), |
135 | 135 | 'decimal_sep' => wpinv_decimal_separator(), |
136 | 136 | 'decimals' => wpinv_decimals(), |
137 | - 'save_invoice' => __( 'Save Invoice', 'invoicing' ), |
|
138 | - 'status_publish' => wpinv_status_nicename( 'publish' ), |
|
139 | - 'status_pending' => wpinv_status_nicename( 'wpi-pending' ), |
|
140 | - 'delete_tax_rate' => __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ), |
|
141 | - 'status_pending' => wpinv_status_nicename( 'wpi-pending' ), |
|
142 | - 'OneItemMin' => __( 'Invoice must contain at least one item', 'invoicing' ), |
|
143 | - 'FillBillingDetails' => __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ), |
|
144 | - 'confirmCalcTotals' => __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' ), |
|
145 | - 'AreYouSure' => __( 'Are you sure?', 'invoicing' ), |
|
146 | - 'emptyInvoice' => __( 'Add at least one item to save invoice!', 'invoicing' ), |
|
147 | - 'errDeleteItem' => __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ), |
|
148 | - 'delete_subscription' => __( 'Are you sure you want to delete this subscription?', 'invoicing' ), |
|
149 | - 'action_edit' => __( 'Edit', 'invoicing' ), |
|
150 | - 'action_cancel' => __( 'Cancel', 'invoicing' ), |
|
151 | - 'item_description' => __( 'Item Description', 'invoicing' ), |
|
152 | - 'invoice_description' => __( 'Invoice Description', 'invoicing' ), |
|
153 | - 'discount_description' => __( 'Discount Description', 'invoicing' ), |
|
154 | - 'searching' => __( 'Searching', 'invoicing' ), |
|
137 | + 'save_invoice' => __('Save Invoice', 'invoicing'), |
|
138 | + 'status_publish' => wpinv_status_nicename('publish'), |
|
139 | + 'status_pending' => wpinv_status_nicename('wpi-pending'), |
|
140 | + 'delete_tax_rate' => __('Are you sure you wish to delete this tax rate?', 'invoicing'), |
|
141 | + 'status_pending' => wpinv_status_nicename('wpi-pending'), |
|
142 | + 'OneItemMin' => __('Invoice must contain at least one item', 'invoicing'), |
|
143 | + 'FillBillingDetails' => __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'), |
|
144 | + 'confirmCalcTotals' => __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing'), |
|
145 | + 'AreYouSure' => __('Are you sure?', 'invoicing'), |
|
146 | + 'emptyInvoice' => __('Add at least one item to save invoice!', 'invoicing'), |
|
147 | + 'errDeleteItem' => __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'), |
|
148 | + 'delete_subscription' => __('Are you sure you want to delete this subscription?', 'invoicing'), |
|
149 | + 'action_edit' => __('Edit', 'invoicing'), |
|
150 | + 'action_cancel' => __('Cancel', 'invoicing'), |
|
151 | + 'item_description' => __('Item Description', 'invoicing'), |
|
152 | + 'invoice_description' => __('Invoice Description', 'invoicing'), |
|
153 | + 'discount_description' => __('Discount Description', 'invoicing'), |
|
154 | + 'searching' => __('Searching', 'invoicing'), |
|
155 | 155 | ); |
156 | 156 | |
157 | 157 | } |
@@ -163,30 +163,30 @@ discard block |
||
163 | 163 | protected function load_payment_form_scripts() { |
164 | 164 | global $post; |
165 | 165 | |
166 | - wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION ); |
|
167 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
168 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
166 | + wp_enqueue_script('vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION); |
|
167 | + wp_enqueue_script('sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION); |
|
168 | + wp_enqueue_script('vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array('sortable', 'vue'), WPINV_VERSION); |
|
169 | 169 | |
170 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
171 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
170 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js'); |
|
171 | + wp_register_script('wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array('wpinv-admin-script', 'vue_draggable'), $version); |
|
172 | 172 | |
173 | 173 | wp_localize_script( |
174 | 174 | 'wpinv-admin-payment-form-script', |
175 | 175 | 'wpinvPaymentFormAdmin', |
176 | 176 | array( |
177 | - 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
178 | - 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
177 | + 'elements' => wpinv_get_data('payment-form-elements'), |
|
178 | + 'form_elements' => getpaid_get_payment_form_elements($post->ID), |
|
179 | 179 | 'currency' => wpinv_currency_symbol(), |
180 | 180 | 'position' => wpinv_currency_position(), |
181 | 181 | 'decimals' => (int) wpinv_decimals(), |
182 | 182 | 'thousands_sep' => wpinv_thousands_separator(), |
183 | 183 | 'decimals_sep' => wpinv_decimal_separator(), |
184 | - 'form_items' => gepaid_get_form_items( $post->ID ), |
|
184 | + 'form_items' => gepaid_get_form_items($post->ID), |
|
185 | 185 | 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
186 | 186 | ) |
187 | 187 | ); |
188 | 188 | |
189 | - wp_enqueue_script( 'wpinv-admin-payment-form-script' ); |
|
189 | + wp_enqueue_script('wpinv-admin-payment-form-script'); |
|
190 | 190 | |
191 | 191 | } |
192 | 192 | |
@@ -197,25 +197,25 @@ discard block |
||
197 | 197 | * @return string |
198 | 198 | * |
199 | 199 | */ |
200 | - public function admin_body_class( $classes ) { |
|
200 | + public function admin_body_class($classes) { |
|
201 | 201 | global $pagenow, $post, $current_screen; |
202 | 202 | |
203 | 203 | |
204 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
204 | + $page = isset($_GET['page']) ? $_GET['page'] : ''; |
|
205 | 205 | |
206 | - if ( ! empty( $current_screen->post_type ) ) { |
|
206 | + if (!empty($current_screen->post_type)) { |
|
207 | 207 | $page = $current_screen->post_type; |
208 | 208 | } |
209 | 209 | |
210 | - if ( false !== stripos( $page, 'wpi' ) ) { |
|
211 | - $classes .= ' wpi-' . sanitize_key( $page ); |
|
210 | + if (false !== stripos($page, 'wpi')) { |
|
211 | + $classes .= ' wpi-' . sanitize_key($page); |
|
212 | 212 | } |
213 | 213 | |
214 | - if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) { |
|
214 | + if (in_array($page, wpinv_parse_list('wpi_invoice wpi_payment_form wpi_quote'))) { |
|
215 | 215 | $classes .= ' wpinv-cpt wpinv'; |
216 | 216 | } |
217 | 217 | |
218 | - if ( $pagenow == 'post.php' && $page == 'wpi_item' && ! empty( $post ) && ! wpinv_item_is_editable( $post ) ) { |
|
218 | + if ($pagenow == 'post.php' && $page == 'wpi_item' && !empty($post) && !wpinv_item_is_editable($post)) { |
|
219 | 219 | $classes .= ' wpi-editable-n'; |
220 | 220 | } |
221 | 221 | |
@@ -225,19 +225,19 @@ discard block |
||
225 | 225 | /** |
226 | 226 | * Maybe show the AyeCode Connect Notice. |
227 | 227 | */ |
228 | - public function init_ayecode_connect_helper(){ |
|
228 | + public function init_ayecode_connect_helper() { |
|
229 | 229 | |
230 | 230 | new AyeCode_Connect_Helper( |
231 | 231 | array( |
232 | - 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
233 | - 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
234 | - 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
235 | - 'connect_button' => __("Connect Site","invoicing"), |
|
236 | - 'connecting_button' => __("Connecting...","invoicing"), |
|
237 | - 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
238 | - 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
232 | + 'connect_title' => __("WP Invoicing - an AyeCode product!", "invoicing"), |
|
233 | + 'connect_external' => __("Please confirm you wish to connect your site?", "invoicing"), |
|
234 | + 'connect' => sprintf(__("<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s", "invoicing"), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>"), |
|
235 | + 'connect_button' => __("Connect Site", "invoicing"), |
|
236 | + 'connecting_button' => __("Connecting...", "invoicing"), |
|
237 | + 'error_localhost' => __("This service will only work with a live domain, not a localhost.", "invoicing"), |
|
238 | + 'error' => __("Something went wrong, please refresh and try again.", "invoicing"), |
|
239 | 239 | ), |
240 | - array( 'wpi-addons' ) |
|
240 | + array('wpi-addons') |
|
241 | 241 | ); |
242 | 242 | |
243 | 243 | } |
@@ -248,19 +248,19 @@ discard block |
||
248 | 248 | public function activation_redirect() { |
249 | 249 | |
250 | 250 | // Bail if no activation redirect. |
251 | - if ( ! get_transient( '_wpinv_activation_redirect' ) || wp_doing_ajax() ) { |
|
251 | + if (!get_transient('_wpinv_activation_redirect') || wp_doing_ajax()) { |
|
252 | 252 | return; |
253 | 253 | } |
254 | 254 | |
255 | 255 | // Delete the redirect transient. |
256 | - delete_transient( '_wpinv_activation_redirect' ); |
|
256 | + delete_transient('_wpinv_activation_redirect'); |
|
257 | 257 | |
258 | 258 | // Bail if activating from network, or bulk |
259 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
259 | + if (is_network_admin() || isset($_GET['activate-multi'])) { |
|
260 | 260 | return; |
261 | 261 | } |
262 | 262 | |
263 | - wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
263 | + wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general')); |
|
264 | 264 | exit; |
265 | 265 | } |
266 | 266 | |
@@ -269,9 +269,9 @@ discard block |
||
269 | 269 | */ |
270 | 270 | public function maybe_do_admin_action() { |
271 | 271 | |
272 | - if ( wpinv_current_user_can_manage_invoicing() && isset( $_REQUEST['getpaid-admin-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
273 | - $key = sanitize_key( $_REQUEST['getpaid-admin-action'] ); |
|
274 | - do_action( "getpaid_authenticated_admin_action_$key", $_REQUEST ); |
|
272 | + if (wpinv_current_user_can_manage_invoicing() && isset($_REQUEST['getpaid-admin-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) { |
|
273 | + $key = sanitize_key($_REQUEST['getpaid-admin-action']); |
|
274 | + do_action("getpaid_authenticated_admin_action_$key", $_REQUEST); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | } |
@@ -281,16 +281,16 @@ discard block |
||
281 | 281 | * |
282 | 282 | * @param array $args |
283 | 283 | */ |
284 | - public function send_customer_invoice( $args ) { |
|
285 | - $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
284 | + public function send_customer_invoice($args) { |
|
285 | + $sent = getpaid()->get('invoice_emails')->user_invoice(new WPInv_Invoice($args['invoice_id'])); |
|
286 | 286 | |
287 | - if ( $sent ) { |
|
288 | - $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) ); |
|
287 | + if ($sent) { |
|
288 | + $this->show_success(__('Invoice was successfully sent to the customer', 'invoicing')); |
|
289 | 289 | } else { |
290 | - $this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) ); |
|
290 | + $this->show_error(__('Could not sent the invoice to the customer', 'invoicing')); |
|
291 | 291 | } |
292 | 292 | |
293 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
293 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id'))); |
|
294 | 294 | exit; |
295 | 295 | } |
296 | 296 | |
@@ -299,16 +299,16 @@ discard block |
||
299 | 299 | * |
300 | 300 | * @param array $args |
301 | 301 | */ |
302 | - public function send_customer_payment_reminder( $args ) { |
|
303 | - $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
302 | + public function send_customer_payment_reminder($args) { |
|
303 | + $sent = getpaid()->get('invoice_emails')->force_send_overdue_notice(new WPInv_Invoice($args['invoice_id'])); |
|
304 | 304 | |
305 | - if ( $sent ) { |
|
306 | - $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
305 | + if ($sent) { |
|
306 | + $this->show_success(__('Payment reminder was successfully sent to the customer', 'invoicing')); |
|
307 | 307 | } else { |
308 | - $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
308 | + $this->show_error(__('Could not sent payment reminder to the customer', 'invoicing')); |
|
309 | 309 | } |
310 | 310 | |
311 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
311 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id'))); |
|
312 | 312 | exit; |
313 | 313 | } |
314 | 314 | |
@@ -319,8 +319,8 @@ discard block |
||
319 | 319 | * @return array |
320 | 320 | */ |
321 | 321 | public function get_notices() { |
322 | - $notices = get_option( 'wpinv_admin_notices' ); |
|
323 | - return is_array( $notices ) ? $notices : array(); |
|
322 | + $notices = get_option('wpinv_admin_notices'); |
|
323 | + return is_array($notices) ? $notices : array(); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | /** |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | * @since 1.0.19 |
331 | 331 | */ |
332 | 332 | public function clear_notices() { |
333 | - delete_option( 'wpinv_admin_notices' ); |
|
333 | + delete_option('wpinv_admin_notices'); |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | /** |
@@ -339,16 +339,16 @@ discard block |
||
339 | 339 | * @access public |
340 | 340 | * @since 1.0.19 |
341 | 341 | */ |
342 | - public function save_notice( $type, $message ) { |
|
342 | + public function save_notice($type, $message) { |
|
343 | 343 | $notices = $this->get_notices(); |
344 | 344 | |
345 | - if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) { |
|
346 | - $notices[ $type ] = array(); |
|
345 | + if (empty($notices[$type]) || !is_array($notices[$type])) { |
|
346 | + $notices[$type] = array(); |
|
347 | 347 | } |
348 | 348 | |
349 | - $notices[ $type ][] = $message; |
|
349 | + $notices[$type][] = $message; |
|
350 | 350 | |
351 | - update_option( 'wpinv_admin_notices', $notices ); |
|
351 | + update_option('wpinv_admin_notices', $notices); |
|
352 | 352 | } |
353 | 353 | |
354 | 354 | /** |
@@ -358,8 +358,8 @@ discard block |
||
358 | 358 | * @access public |
359 | 359 | * @since 1.0.19 |
360 | 360 | */ |
361 | - public function show_success( $msg ) { |
|
362 | - $this->save_notice( 'success', $msg ); |
|
361 | + public function show_success($msg) { |
|
362 | + $this->save_notice('success', $msg); |
|
363 | 363 | } |
364 | 364 | |
365 | 365 | /** |
@@ -369,8 +369,8 @@ discard block |
||
369 | 369 | * @param string $msg The message to qeue. |
370 | 370 | * @since 1.0.19 |
371 | 371 | */ |
372 | - public function show_error( $msg ) { |
|
373 | - $this->save_notice( 'error', $msg ); |
|
372 | + public function show_error($msg) { |
|
373 | + $this->save_notice('error', $msg); |
|
374 | 374 | } |
375 | 375 | |
376 | 376 | /** |
@@ -380,8 +380,8 @@ discard block |
||
380 | 380 | * @param string $msg The message to qeue. |
381 | 381 | * @since 1.0.19 |
382 | 382 | */ |
383 | - public function show_warning( $msg ) { |
|
384 | - $this->save_notice( 'warning', $msg ); |
|
383 | + public function show_warning($msg) { |
|
384 | + $this->save_notice('warning', $msg); |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | /** |
@@ -391,8 +391,8 @@ discard block |
||
391 | 391 | * @param string $msg The message to qeue. |
392 | 392 | * @since 1.0.19 |
393 | 393 | */ |
394 | - public function show_info( $msg ) { |
|
395 | - $this->save_notice( 'info', $msg ); |
|
394 | + public function show_info($msg) { |
|
395 | + $this->save_notice('info', $msg); |
|
396 | 396 | } |
397 | 397 | |
398 | 398 | /** |
@@ -406,15 +406,15 @@ discard block |
||
406 | 406 | $notices = $this->get_notices(); |
407 | 407 | $this->clear_notices(); |
408 | 408 | |
409 | - foreach ( $notices as $type => $messages ) { |
|
409 | + foreach ($notices as $type => $messages) { |
|
410 | 410 | |
411 | - if ( ! is_array( $messages ) ) { |
|
411 | + if (!is_array($messages)) { |
|
412 | 412 | continue; |
413 | 413 | } |
414 | 414 | |
415 | - $type = sanitize_key( $type ); |
|
416 | - foreach ( $messages as $message ) { |
|
417 | - $message = wp_kses_post( $message ); |
|
415 | + $type = sanitize_key($type); |
|
416 | + foreach ($messages as $message) { |
|
417 | + $message = wp_kses_post($message); |
|
418 | 418 | echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>"; |
419 | 419 | } |
420 | 420 |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
141 | 141 | */ |
142 | 142 | function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
143 | - return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path ); |
|
143 | + return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path ); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | * @return string |
159 | 159 | */ |
160 | 160 | function wpinv_get_theme_template_dir_name() { |
161 | - return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
161 | + return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -175,122 +175,122 @@ discard block |
||
175 | 175 | } |
176 | 176 | |
177 | 177 | function wpinv_get_template_part( $slug, $name = null, $load = true ) { |
178 | - do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
178 | + do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
179 | 179 | |
180 | - // Setup possible parts |
|
181 | - $templates = array(); |
|
182 | - if ( isset( $name ) ) |
|
183 | - $templates[] = $slug . '-' . $name . '.php'; |
|
184 | - $templates[] = $slug . '.php'; |
|
180 | + // Setup possible parts |
|
181 | + $templates = array(); |
|
182 | + if ( isset( $name ) ) |
|
183 | + $templates[] = $slug . '-' . $name . '.php'; |
|
184 | + $templates[] = $slug . '.php'; |
|
185 | 185 | |
186 | - // Allow template parts to be filtered |
|
187 | - $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
186 | + // Allow template parts to be filtered |
|
187 | + $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
188 | 188 | |
189 | - // Return the part that is found |
|
190 | - return wpinv_locate_tmpl( $templates, $load, false ); |
|
189 | + // Return the part that is found |
|
190 | + return wpinv_locate_tmpl( $templates, $load, false ); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) { |
194 | - // No file found yet |
|
195 | - $located = false; |
|
194 | + // No file found yet |
|
195 | + $located = false; |
|
196 | 196 | |
197 | - // Try to find a template file |
|
198 | - foreach ( (array)$template_names as $template_name ) { |
|
197 | + // Try to find a template file |
|
198 | + foreach ( (array)$template_names as $template_name ) { |
|
199 | 199 | |
200 | - // Continue if template is empty |
|
201 | - if ( empty( $template_name ) ) |
|
202 | - continue; |
|
200 | + // Continue if template is empty |
|
201 | + if ( empty( $template_name ) ) |
|
202 | + continue; |
|
203 | 203 | |
204 | - // Trim off any slashes from the template name |
|
205 | - $template_name = ltrim( $template_name, '/' ); |
|
204 | + // Trim off any slashes from the template name |
|
205 | + $template_name = ltrim( $template_name, '/' ); |
|
206 | 206 | |
207 | - // try locating this template file by looping through the template paths |
|
208 | - foreach( wpinv_get_theme_template_paths() as $template_path ) { |
|
207 | + // try locating this template file by looping through the template paths |
|
208 | + foreach( wpinv_get_theme_template_paths() as $template_path ) { |
|
209 | 209 | |
210 | - if( file_exists( $template_path . $template_name ) ) { |
|
211 | - $located = $template_path . $template_name; |
|
212 | - break; |
|
213 | - } |
|
214 | - } |
|
210 | + if( file_exists( $template_path . $template_name ) ) { |
|
211 | + $located = $template_path . $template_name; |
|
212 | + break; |
|
213 | + } |
|
214 | + } |
|
215 | 215 | |
216 | - if( !empty( $located ) ) { |
|
217 | - break; |
|
218 | - } |
|
219 | - } |
|
216 | + if( !empty( $located ) ) { |
|
217 | + break; |
|
218 | + } |
|
219 | + } |
|
220 | 220 | |
221 | - if ( ( true == $load ) && ! empty( $located ) ) |
|
222 | - load_template( $located, $require_once ); |
|
221 | + if ( ( true == $load ) && ! empty( $located ) ) |
|
222 | + load_template( $located, $require_once ); |
|
223 | 223 | |
224 | - return $located; |
|
224 | + return $located; |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | function wpinv_get_theme_template_paths() { |
228 | - $template_dir = wpinv_get_theme_template_dir_name(); |
|
228 | + $template_dir = wpinv_get_theme_template_dir_name(); |
|
229 | 229 | |
230 | - $file_paths = array( |
|
231 | - 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
232 | - 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
233 | - 100 => wpinv_get_templates_dir() |
|
234 | - ); |
|
230 | + $file_paths = array( |
|
231 | + 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
232 | + 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
233 | + 100 => wpinv_get_templates_dir() |
|
234 | + ); |
|
235 | 235 | |
236 | - $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
236 | + $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
237 | 237 | |
238 | - // sort the file paths based on priority |
|
239 | - ksort( $file_paths, SORT_NUMERIC ); |
|
238 | + // sort the file paths based on priority |
|
239 | + ksort( $file_paths, SORT_NUMERIC ); |
|
240 | 240 | |
241 | - return array_map( 'trailingslashit', $file_paths ); |
|
241 | + return array_map( 'trailingslashit', $file_paths ); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | function wpinv_checkout_meta_tags() { |
245 | 245 | |
246 | - $pages = array(); |
|
247 | - $pages[] = wpinv_get_option( 'success_page' ); |
|
248 | - $pages[] = wpinv_get_option( 'failure_page' ); |
|
249 | - $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
250 | - $pages[] = wpinv_get_option( 'invoice_subscription_page' ); |
|
246 | + $pages = array(); |
|
247 | + $pages[] = wpinv_get_option( 'success_page' ); |
|
248 | + $pages[] = wpinv_get_option( 'failure_page' ); |
|
249 | + $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
250 | + $pages[] = wpinv_get_option( 'invoice_subscription_page' ); |
|
251 | 251 | |
252 | - if( !wpinv_is_checkout() && !is_page( $pages ) ) { |
|
253 | - return; |
|
254 | - } |
|
252 | + if( !wpinv_is_checkout() && !is_page( $pages ) ) { |
|
253 | + return; |
|
254 | + } |
|
255 | 255 | |
256 | - echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
|
256 | + echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
|
257 | 257 | } |
258 | 258 | add_action( 'wp_head', 'wpinv_checkout_meta_tags' ); |
259 | 259 | |
260 | 260 | function wpinv_add_body_classes( $class ) { |
261 | - $classes = (array)$class; |
|
261 | + $classes = (array)$class; |
|
262 | 262 | |
263 | - if( wpinv_is_checkout() ) { |
|
264 | - $classes[] = 'wpinv-checkout'; |
|
265 | - $classes[] = 'wpinv-page'; |
|
266 | - } |
|
263 | + if( wpinv_is_checkout() ) { |
|
264 | + $classes[] = 'wpinv-checkout'; |
|
265 | + $classes[] = 'wpinv-page'; |
|
266 | + } |
|
267 | 267 | |
268 | - if( wpinv_is_success_page() ) { |
|
269 | - $classes[] = 'wpinv-success'; |
|
270 | - $classes[] = 'wpinv-page'; |
|
271 | - } |
|
268 | + if( wpinv_is_success_page() ) { |
|
269 | + $classes[] = 'wpinv-success'; |
|
270 | + $classes[] = 'wpinv-page'; |
|
271 | + } |
|
272 | 272 | |
273 | - if( wpinv_is_failed_transaction_page() ) { |
|
274 | - $classes[] = 'wpinv-failed-transaction'; |
|
275 | - $classes[] = 'wpinv-page'; |
|
276 | - } |
|
273 | + if( wpinv_is_failed_transaction_page() ) { |
|
274 | + $classes[] = 'wpinv-failed-transaction'; |
|
275 | + $classes[] = 'wpinv-page'; |
|
276 | + } |
|
277 | 277 | |
278 | - if( wpinv_is_invoice_history_page() ) { |
|
279 | - $classes[] = 'wpinv-history'; |
|
280 | - $classes[] = 'wpinv-page'; |
|
281 | - } |
|
278 | + if( wpinv_is_invoice_history_page() ) { |
|
279 | + $classes[] = 'wpinv-history'; |
|
280 | + $classes[] = 'wpinv-page'; |
|
281 | + } |
|
282 | 282 | |
283 | - if( wpinv_is_subscriptions_history_page() ) { |
|
284 | - $classes[] = 'wpinv-subscription'; |
|
285 | - $classes[] = 'wpinv-page'; |
|
286 | - } |
|
283 | + if( wpinv_is_subscriptions_history_page() ) { |
|
284 | + $classes[] = 'wpinv-subscription'; |
|
285 | + $classes[] = 'wpinv-page'; |
|
286 | + } |
|
287 | 287 | |
288 | - if( wpinv_is_test_mode() ) { |
|
289 | - $classes[] = 'wpinv-test-mode'; |
|
290 | - $classes[] = 'wpinv-page'; |
|
291 | - } |
|
288 | + if( wpinv_is_test_mode() ) { |
|
289 | + $classes[] = 'wpinv-test-mode'; |
|
290 | + $classes[] = 'wpinv-page'; |
|
291 | + } |
|
292 | 292 | |
293 | - return array_unique( $classes ); |
|
293 | + return array_unique( $classes ); |
|
294 | 294 | } |
295 | 295 | add_filter( 'body_class', 'wpinv_add_body_classes' ); |
296 | 296 | |
@@ -992,21 +992,21 @@ discard block |
||
992 | 992 | |
993 | 993 | $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format ); |
994 | 994 | |
995 | - // Remove unavailable tags. |
|
995 | + // Remove unavailable tags. |
|
996 | 996 | $formatted_address = preg_replace( "/\{\{\w+\}\}/", '', $formatted_address ); |
997 | 997 | |
998 | 998 | // Clean up white space. |
999 | - $formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) ); |
|
999 | + $formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) ); |
|
1000 | 1000 | $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address ); |
1001 | 1001 | |
1002 | 1002 | // Break newlines apart and remove empty lines/trim commas and white space. |
1003 | - $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) ); |
|
1003 | + $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) ); |
|
1004 | 1004 | |
1005 | 1005 | // Add html breaks. |
1006 | - $formatted_address = implode( $separator, $formatted_address ); |
|
1006 | + $formatted_address = implode( $separator, $formatted_address ); |
|
1007 | 1007 | |
1008 | - // We're done! |
|
1009 | - return $formatted_address; |
|
1008 | + // We're done! |
|
1009 | + return $formatted_address; |
|
1010 | 1010 | |
1011 | 1011 | } |
1012 | 1012 | |
@@ -1208,7 +1208,7 @@ discard block |
||
1208 | 1208 | } |
1209 | 1209 | |
1210 | 1210 | function wpinv_empty_cart_message() { |
1211 | - return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1211 | + return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1212 | 1212 | } |
1213 | 1213 | |
1214 | 1214 | /** |
@@ -1498,10 +1498,10 @@ discard block |
||
1498 | 1498 | |
1499 | 1499 | if ( 0 == count( $form->get_items() ) ) { |
1500 | 1500 | echo aui()->alert( |
1501 | - array( |
|
1502 | - 'type' => 'warning', |
|
1503 | - 'content' => __( 'No published items found', 'invoicing' ), |
|
1504 | - ) |
|
1501 | + array( |
|
1502 | + 'type' => 'warning', |
|
1503 | + 'content' => __( 'No published items found', 'invoicing' ), |
|
1504 | + ) |
|
1505 | 1505 | ); |
1506 | 1506 | return; |
1507 | 1507 | } |
@@ -1517,21 +1517,21 @@ discard block |
||
1517 | 1517 | $invoice = wpinv_get_invoice( $invoice_id ); |
1518 | 1518 | |
1519 | 1519 | if ( empty( $invoice ) ) { |
1520 | - echo aui()->alert( |
|
1521 | - array( |
|
1522 | - 'type' => 'warning', |
|
1523 | - 'content' => __( 'Invoice not found', 'invoicing' ), |
|
1524 | - ) |
|
1520 | + echo aui()->alert( |
|
1521 | + array( |
|
1522 | + 'type' => 'warning', |
|
1523 | + 'content' => __( 'Invoice not found', 'invoicing' ), |
|
1524 | + ) |
|
1525 | 1525 | ); |
1526 | 1526 | return; |
1527 | 1527 | } |
1528 | 1528 | |
1529 | 1529 | if ( $invoice->is_paid() ) { |
1530 | - echo aui()->alert( |
|
1531 | - array( |
|
1532 | - 'type' => 'warning', |
|
1533 | - 'content' => __( 'Invoice has already been paid', 'invoicing' ), |
|
1534 | - ) |
|
1530 | + echo aui()->alert( |
|
1531 | + array( |
|
1532 | + 'type' => 'warning', |
|
1533 | + 'content' => __( 'Invoice has already been paid', 'invoicing' ), |
|
1534 | + ) |
|
1535 | 1535 | ); |
1536 | 1536 | return; |
1537 | 1537 | } |
@@ -1594,7 +1594,7 @@ discard block |
||
1594 | 1594 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-form='$form'>$label</button>"; |
1595 | 1595 | } |
1596 | 1596 | |
1597 | - if ( ! empty( $items ) ) { |
|
1597 | + if ( ! empty( $items ) ) { |
|
1598 | 1598 | $items = esc_attr( $items ); |
1599 | 1599 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-item='$items'>$label</button>"; |
1600 | 1600 | } |
@@ -4,99 +4,99 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Displays an invoice. |
11 | 11 | * |
12 | 12 | * @param WPInv_Invoice $invoice. |
13 | 13 | */ |
14 | -function getpaid_invoice( $invoice ) { |
|
15 | - if ( ! empty( $invoice ) ) { |
|
16 | - wpinv_get_template( 'invoice/invoice.php', compact( 'invoice' ) ); |
|
14 | +function getpaid_invoice($invoice) { |
|
15 | + if (!empty($invoice)) { |
|
16 | + wpinv_get_template('invoice/invoice.php', compact('invoice')); |
|
17 | 17 | } |
18 | 18 | } |
19 | -add_action( 'getpaid_invoice', 'getpaid_invoice', 10 ); |
|
19 | +add_action('getpaid_invoice', 'getpaid_invoice', 10); |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * Displays the invoice footer. |
23 | 23 | */ |
24 | -function getpaid_invoice_footer( $invoice ) { |
|
25 | - if ( ! empty( $invoice ) ) { |
|
26 | - wpinv_get_template( 'invoice/footer.php', compact( 'invoice' ) ); |
|
24 | +function getpaid_invoice_footer($invoice) { |
|
25 | + if (!empty($invoice)) { |
|
26 | + wpinv_get_template('invoice/footer.php', compact('invoice')); |
|
27 | 27 | } |
28 | 28 | } |
29 | -add_action( 'getpaid_invoice_footer', 'getpaid_invoice_footer', 10 ); |
|
29 | +add_action('getpaid_invoice_footer', 'getpaid_invoice_footer', 10); |
|
30 | 30 | |
31 | 31 | /** |
32 | 32 | * Displays the invoice top bar. |
33 | 33 | */ |
34 | -function getpaid_invoice_header( $invoice ) { |
|
35 | - if ( ! empty( $invoice ) ) { |
|
36 | - wpinv_get_template( 'invoice/header.php', compact( 'invoice' ) ); |
|
34 | +function getpaid_invoice_header($invoice) { |
|
35 | + if (!empty($invoice)) { |
|
36 | + wpinv_get_template('invoice/header.php', compact('invoice')); |
|
37 | 37 | } |
38 | 38 | } |
39 | -add_action( 'getpaid_invoice_header', 'getpaid_invoice_header', 10 ); |
|
39 | +add_action('getpaid_invoice_header', 'getpaid_invoice_header', 10); |
|
40 | 40 | |
41 | 41 | /** |
42 | 42 | * Displays actions on the left side of the header. |
43 | 43 | */ |
44 | -function getpaid_invoice_header_left_actions( $invoice ) { |
|
45 | - if ( ! empty( $invoice ) ) { |
|
46 | - wpinv_get_template( 'invoice/header-left-actions.php', compact( 'invoice' ) ); |
|
44 | +function getpaid_invoice_header_left_actions($invoice) { |
|
45 | + if (!empty($invoice)) { |
|
46 | + wpinv_get_template('invoice/header-left-actions.php', compact('invoice')); |
|
47 | 47 | } |
48 | 48 | } |
49 | -add_action( 'getpaid_invoice_header_left', 'getpaid_invoice_header_left_actions', 10 ); |
|
49 | +add_action('getpaid_invoice_header_left', 'getpaid_invoice_header_left_actions', 10); |
|
50 | 50 | |
51 | 51 | /** |
52 | 52 | * Displays actions on the right side of the invoice top bar. |
53 | 53 | */ |
54 | -function getpaid_invoice_header_right_actions( $invoice ) { |
|
55 | - if ( ! empty( $invoice ) ) { |
|
56 | - wpinv_get_template( 'invoice/header-right-actions.php', compact( 'invoice' ) ); |
|
54 | +function getpaid_invoice_header_right_actions($invoice) { |
|
55 | + if (!empty($invoice)) { |
|
56 | + wpinv_get_template('invoice/header-right-actions.php', compact('invoice')); |
|
57 | 57 | } |
58 | 58 | } |
59 | -add_action( 'getpaid_invoice_header_right', 'getpaid_invoice_header_right_actions', 10 ); |
|
59 | +add_action('getpaid_invoice_header_right', 'getpaid_invoice_header_right_actions', 10); |
|
60 | 60 | |
61 | 61 | /** |
62 | 62 | * Displays the invoice title, watermark, logo etc. |
63 | 63 | */ |
64 | -function getpaid_invoice_details_top( $invoice ) { |
|
65 | - if ( ! empty( $invoice ) ) { |
|
66 | - wpinv_get_template( 'invoice/details-top.php', compact( 'invoice' ) ); |
|
64 | +function getpaid_invoice_details_top($invoice) { |
|
65 | + if (!empty($invoice)) { |
|
66 | + wpinv_get_template('invoice/details-top.php', compact('invoice')); |
|
67 | 67 | } |
68 | 68 | } |
69 | -add_action( 'getpaid_invoice_details', 'getpaid_invoice_details_top', 10 ); |
|
69 | +add_action('getpaid_invoice_details', 'getpaid_invoice_details_top', 10); |
|
70 | 70 | |
71 | 71 | /** |
72 | 72 | * Displays the company logo. |
73 | 73 | */ |
74 | -function getpaid_invoice_logo( $invoice ) { |
|
75 | - if ( ! empty( $invoice ) ) { |
|
76 | - wpinv_get_template( 'invoice/invoice-logo.php', compact( 'invoice' ) ); |
|
74 | +function getpaid_invoice_logo($invoice) { |
|
75 | + if (!empty($invoice)) { |
|
76 | + wpinv_get_template('invoice/invoice-logo.php', compact('invoice')); |
|
77 | 77 | } |
78 | 78 | } |
79 | -add_action( 'getpaid_invoice_details_top_left', 'getpaid_invoice_logo' ); |
|
79 | +add_action('getpaid_invoice_details_top_left', 'getpaid_invoice_logo'); |
|
80 | 80 | |
81 | 81 | /** |
82 | 82 | * Displays the type of invoice. |
83 | 83 | */ |
84 | -function getpaid_invoice_type( $invoice ) { |
|
85 | - if ( ! empty( $invoice ) ) { |
|
86 | - wpinv_get_template( 'invoice/invoice-type.php', compact( 'invoice' ) ); |
|
84 | +function getpaid_invoice_type($invoice) { |
|
85 | + if (!empty($invoice)) { |
|
86 | + wpinv_get_template('invoice/invoice-type.php', compact('invoice')); |
|
87 | 87 | } |
88 | 88 | } |
89 | -add_action( 'getpaid_invoice_details_top_right', 'getpaid_invoice_type' ); |
|
89 | +add_action('getpaid_invoice_details_top_right', 'getpaid_invoice_type'); |
|
90 | 90 | |
91 | 91 | /** |
92 | 92 | * Displays the invoice details. |
93 | 93 | */ |
94 | -function getpaid_invoice_details_main( $invoice ) { |
|
95 | - if ( ! empty( $invoice ) ) { |
|
96 | - wpinv_get_template( 'invoice/details.php', compact( 'invoice' ) ); |
|
94 | +function getpaid_invoice_details_main($invoice) { |
|
95 | + if (!empty($invoice)) { |
|
96 | + wpinv_get_template('invoice/details.php', compact('invoice')); |
|
97 | 97 | } |
98 | 98 | } |
99 | -add_action( 'getpaid_invoice_details', 'getpaid_invoice_details_main', 50 ); |
|
99 | +add_action('getpaid_invoice_details', 'getpaid_invoice_details_main', 50); |
|
100 | 100 | |
101 | 101 | /** |
102 | 102 | * Returns a path to the templates directory. |
@@ -125,8 +125,8 @@ discard block |
||
125 | 125 | * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'. |
126 | 126 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
127 | 127 | */ |
128 | -function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
129 | - return getpaid_template()->display_template( $template_name, $args, $template_path, $default_path ); |
|
128 | +function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
129 | + return getpaid_template()->display_template($template_name, $args, $template_path, $default_path); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -139,8 +139,8 @@ discard block |
||
139 | 139 | * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'. |
140 | 140 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
141 | 141 | */ |
142 | -function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
143 | - return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path ); |
|
142 | +function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
143 | + return getpaid_template()->get_template($template_name, $args, $template_path, $default_path); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * @return string |
150 | 150 | */ |
151 | 151 | function wpinv_template_path() { |
152 | - return apply_filters( 'wpinv_template_path', wpinv_get_theme_template_dir_name() ); |
|
152 | + return apply_filters('wpinv_template_path', wpinv_get_theme_template_dir_name()); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | * @return string |
159 | 159 | */ |
160 | 160 | function wpinv_get_theme_template_dir_name() { |
161 | - return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
161 | + return trailingslashit(apply_filters('wpinv_templates_dir', 'invoicing')); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -170,56 +170,56 @@ discard block |
||
170 | 170 | * @param string $template_path The template path relative to the theme's root dir. Defaults to 'invoicing'. |
171 | 171 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
172 | 172 | */ |
173 | -function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) { |
|
174 | - return getpaid_template()->locate_template( $template_name, $template_path, $default_path ); |
|
173 | +function wpinv_locate_template($template_name, $template_path = '', $default_path = '') { |
|
174 | + return getpaid_template()->locate_template($template_name, $template_path, $default_path); |
|
175 | 175 | } |
176 | 176 | |
177 | -function wpinv_get_template_part( $slug, $name = null, $load = true ) { |
|
178 | - do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
177 | +function wpinv_get_template_part($slug, $name = null, $load = true) { |
|
178 | + do_action('get_template_part_' . $slug, $slug, $name); |
|
179 | 179 | |
180 | 180 | // Setup possible parts |
181 | 181 | $templates = array(); |
182 | - if ( isset( $name ) ) |
|
182 | + if (isset($name)) |
|
183 | 183 | $templates[] = $slug . '-' . $name . '.php'; |
184 | 184 | $templates[] = $slug . '.php'; |
185 | 185 | |
186 | 186 | // Allow template parts to be filtered |
187 | - $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
187 | + $templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name); |
|
188 | 188 | |
189 | 189 | // Return the part that is found |
190 | - return wpinv_locate_tmpl( $templates, $load, false ); |
|
190 | + return wpinv_locate_tmpl($templates, $load, false); |
|
191 | 191 | } |
192 | 192 | |
193 | -function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) { |
|
193 | +function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) { |
|
194 | 194 | // No file found yet |
195 | 195 | $located = false; |
196 | 196 | |
197 | 197 | // Try to find a template file |
198 | - foreach ( (array)$template_names as $template_name ) { |
|
198 | + foreach ((array) $template_names as $template_name) { |
|
199 | 199 | |
200 | 200 | // Continue if template is empty |
201 | - if ( empty( $template_name ) ) |
|
201 | + if (empty($template_name)) |
|
202 | 202 | continue; |
203 | 203 | |
204 | 204 | // Trim off any slashes from the template name |
205 | - $template_name = ltrim( $template_name, '/' ); |
|
205 | + $template_name = ltrim($template_name, '/'); |
|
206 | 206 | |
207 | 207 | // try locating this template file by looping through the template paths |
208 | - foreach( wpinv_get_theme_template_paths() as $template_path ) { |
|
208 | + foreach (wpinv_get_theme_template_paths() as $template_path) { |
|
209 | 209 | |
210 | - if( file_exists( $template_path . $template_name ) ) { |
|
210 | + if (file_exists($template_path . $template_name)) { |
|
211 | 211 | $located = $template_path . $template_name; |
212 | 212 | break; |
213 | 213 | } |
214 | 214 | } |
215 | 215 | |
216 | - if( !empty( $located ) ) { |
|
216 | + if (!empty($located)) { |
|
217 | 217 | break; |
218 | 218 | } |
219 | 219 | } |
220 | 220 | |
221 | - if ( ( true == $load ) && ! empty( $located ) ) |
|
222 | - load_template( $located, $require_once ); |
|
221 | + if ((true == $load) && !empty($located)) |
|
222 | + load_template($located, $require_once); |
|
223 | 223 | |
224 | 224 | return $located; |
225 | 225 | } |
@@ -228,155 +228,155 @@ discard block |
||
228 | 228 | $template_dir = wpinv_get_theme_template_dir_name(); |
229 | 229 | |
230 | 230 | $file_paths = array( |
231 | - 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
232 | - 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
231 | + 1 => trailingslashit(get_stylesheet_directory()) . $template_dir, |
|
232 | + 10 => trailingslashit(get_template_directory()) . $template_dir, |
|
233 | 233 | 100 => wpinv_get_templates_dir() |
234 | 234 | ); |
235 | 235 | |
236 | - $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
236 | + $file_paths = apply_filters('wpinv_template_paths', $file_paths); |
|
237 | 237 | |
238 | 238 | // sort the file paths based on priority |
239 | - ksort( $file_paths, SORT_NUMERIC ); |
|
239 | + ksort($file_paths, SORT_NUMERIC); |
|
240 | 240 | |
241 | - return array_map( 'trailingslashit', $file_paths ); |
|
241 | + return array_map('trailingslashit', $file_paths); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | function wpinv_checkout_meta_tags() { |
245 | 245 | |
246 | 246 | $pages = array(); |
247 | - $pages[] = wpinv_get_option( 'success_page' ); |
|
248 | - $pages[] = wpinv_get_option( 'failure_page' ); |
|
249 | - $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
250 | - $pages[] = wpinv_get_option( 'invoice_subscription_page' ); |
|
247 | + $pages[] = wpinv_get_option('success_page'); |
|
248 | + $pages[] = wpinv_get_option('failure_page'); |
|
249 | + $pages[] = wpinv_get_option('invoice_history_page'); |
|
250 | + $pages[] = wpinv_get_option('invoice_subscription_page'); |
|
251 | 251 | |
252 | - if( !wpinv_is_checkout() && !is_page( $pages ) ) { |
|
252 | + if (!wpinv_is_checkout() && !is_page($pages)) { |
|
253 | 253 | return; |
254 | 254 | } |
255 | 255 | |
256 | 256 | echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
257 | 257 | } |
258 | -add_action( 'wp_head', 'wpinv_checkout_meta_tags' ); |
|
258 | +add_action('wp_head', 'wpinv_checkout_meta_tags'); |
|
259 | 259 | |
260 | -function wpinv_add_body_classes( $class ) { |
|
261 | - $classes = (array)$class; |
|
260 | +function wpinv_add_body_classes($class) { |
|
261 | + $classes = (array) $class; |
|
262 | 262 | |
263 | - if( wpinv_is_checkout() ) { |
|
263 | + if (wpinv_is_checkout()) { |
|
264 | 264 | $classes[] = 'wpinv-checkout'; |
265 | 265 | $classes[] = 'wpinv-page'; |
266 | 266 | } |
267 | 267 | |
268 | - if( wpinv_is_success_page() ) { |
|
268 | + if (wpinv_is_success_page()) { |
|
269 | 269 | $classes[] = 'wpinv-success'; |
270 | 270 | $classes[] = 'wpinv-page'; |
271 | 271 | } |
272 | 272 | |
273 | - if( wpinv_is_failed_transaction_page() ) { |
|
273 | + if (wpinv_is_failed_transaction_page()) { |
|
274 | 274 | $classes[] = 'wpinv-failed-transaction'; |
275 | 275 | $classes[] = 'wpinv-page'; |
276 | 276 | } |
277 | 277 | |
278 | - if( wpinv_is_invoice_history_page() ) { |
|
278 | + if (wpinv_is_invoice_history_page()) { |
|
279 | 279 | $classes[] = 'wpinv-history'; |
280 | 280 | $classes[] = 'wpinv-page'; |
281 | 281 | } |
282 | 282 | |
283 | - if( wpinv_is_subscriptions_history_page() ) { |
|
283 | + if (wpinv_is_subscriptions_history_page()) { |
|
284 | 284 | $classes[] = 'wpinv-subscription'; |
285 | 285 | $classes[] = 'wpinv-page'; |
286 | 286 | } |
287 | 287 | |
288 | - if( wpinv_is_test_mode() ) { |
|
288 | + if (wpinv_is_test_mode()) { |
|
289 | 289 | $classes[] = 'wpinv-test-mode'; |
290 | 290 | $classes[] = 'wpinv-page'; |
291 | 291 | } |
292 | 292 | |
293 | - return array_unique( $classes ); |
|
293 | + return array_unique($classes); |
|
294 | 294 | } |
295 | -add_filter( 'body_class', 'wpinv_add_body_classes' ); |
|
295 | +add_filter('body_class', 'wpinv_add_body_classes'); |
|
296 | 296 | |
297 | -function wpinv_html_dropdown( $name = 'wpinv_discounts', $selected = 0, $status = '' ) { |
|
298 | - $args = array( 'nopaging' => true ); |
|
297 | +function wpinv_html_dropdown($name = 'wpinv_discounts', $selected = 0, $status = '') { |
|
298 | + $args = array('nopaging' => true); |
|
299 | 299 | |
300 | - if ( ! empty( $status ) ) |
|
300 | + if (!empty($status)) |
|
301 | 301 | $args['post_status'] = $status; |
302 | 302 | |
303 | - $discounts = wpinv_get_discounts( $args ); |
|
303 | + $discounts = wpinv_get_discounts($args); |
|
304 | 304 | $options = array(); |
305 | 305 | |
306 | - if ( $discounts ) { |
|
307 | - foreach ( $discounts as $discount ) { |
|
308 | - $options[ absint( $discount->ID ) ] = esc_html( get_the_title( $discount->ID ) ); |
|
306 | + if ($discounts) { |
|
307 | + foreach ($discounts as $discount) { |
|
308 | + $options[absint($discount->ID)] = esc_html(get_the_title($discount->ID)); |
|
309 | 309 | } |
310 | 310 | } else { |
311 | - $options[0] = __( 'No discounts found', 'invoicing' ); |
|
311 | + $options[0] = __('No discounts found', 'invoicing'); |
|
312 | 312 | } |
313 | 313 | |
314 | - $output = wpinv_html_select( array( |
|
314 | + $output = wpinv_html_select(array( |
|
315 | 315 | 'name' => $name, |
316 | 316 | 'selected' => $selected, |
317 | 317 | 'options' => $options, |
318 | 318 | 'show_option_all' => false, |
319 | 319 | 'show_option_none' => false, |
320 | - ) ); |
|
320 | + )); |
|
321 | 321 | |
322 | 322 | return $output; |
323 | 323 | } |
324 | 324 | |
325 | -function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) { |
|
326 | - $current = date( 'Y' ); |
|
327 | - $start_year = $current - absint( $years_before ); |
|
328 | - $end_year = $current + absint( $years_after ); |
|
329 | - $selected = empty( $selected ) ? date( 'Y' ) : $selected; |
|
325 | +function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) { |
|
326 | + $current = date('Y'); |
|
327 | + $start_year = $current - absint($years_before); |
|
328 | + $end_year = $current + absint($years_after); |
|
329 | + $selected = empty($selected) ? date('Y') : $selected; |
|
330 | 330 | $options = array(); |
331 | 331 | |
332 | - while ( $start_year <= $end_year ) { |
|
333 | - $options[ absint( $start_year ) ] = $start_year; |
|
332 | + while ($start_year <= $end_year) { |
|
333 | + $options[absint($start_year)] = $start_year; |
|
334 | 334 | $start_year++; |
335 | 335 | } |
336 | 336 | |
337 | - $output = wpinv_html_select( array( |
|
337 | + $output = wpinv_html_select(array( |
|
338 | 338 | 'name' => $name, |
339 | 339 | 'selected' => $selected, |
340 | 340 | 'options' => $options, |
341 | 341 | 'show_option_all' => false, |
342 | 342 | 'show_option_none' => false |
343 | - ) ); |
|
343 | + )); |
|
344 | 344 | |
345 | 345 | return $output; |
346 | 346 | } |
347 | 347 | |
348 | -function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) { |
|
348 | +function wpinv_html_month_dropdown($name = 'month', $selected = 0) { |
|
349 | 349 | |
350 | 350 | $options = array( |
351 | - '1' => __( 'January', 'invoicing' ), |
|
352 | - '2' => __( 'February', 'invoicing' ), |
|
353 | - '3' => __( 'March', 'invoicing' ), |
|
354 | - '4' => __( 'April', 'invoicing' ), |
|
355 | - '5' => __( 'May', 'invoicing' ), |
|
356 | - '6' => __( 'June', 'invoicing' ), |
|
357 | - '7' => __( 'July', 'invoicing' ), |
|
358 | - '8' => __( 'August', 'invoicing' ), |
|
359 | - '9' => __( 'September', 'invoicing' ), |
|
360 | - '10' => __( 'October', 'invoicing' ), |
|
361 | - '11' => __( 'November', 'invoicing' ), |
|
362 | - '12' => __( 'December', 'invoicing' ), |
|
351 | + '1' => __('January', 'invoicing'), |
|
352 | + '2' => __('February', 'invoicing'), |
|
353 | + '3' => __('March', 'invoicing'), |
|
354 | + '4' => __('April', 'invoicing'), |
|
355 | + '5' => __('May', 'invoicing'), |
|
356 | + '6' => __('June', 'invoicing'), |
|
357 | + '7' => __('July', 'invoicing'), |
|
358 | + '8' => __('August', 'invoicing'), |
|
359 | + '9' => __('September', 'invoicing'), |
|
360 | + '10' => __('October', 'invoicing'), |
|
361 | + '11' => __('November', 'invoicing'), |
|
362 | + '12' => __('December', 'invoicing'), |
|
363 | 363 | ); |
364 | 364 | |
365 | 365 | // If no month is selected, default to the current month |
366 | - $selected = empty( $selected ) ? date( 'n' ) : $selected; |
|
366 | + $selected = empty($selected) ? date('n') : $selected; |
|
367 | 367 | |
368 | - $output = wpinv_html_select( array( |
|
368 | + $output = wpinv_html_select(array( |
|
369 | 369 | 'name' => $name, |
370 | 370 | 'selected' => $selected, |
371 | 371 | 'options' => $options, |
372 | 372 | 'show_option_all' => false, |
373 | 373 | 'show_option_none' => false |
374 | - ) ); |
|
374 | + )); |
|
375 | 375 | |
376 | 376 | return $output; |
377 | 377 | } |
378 | 378 | |
379 | -function wpinv_html_select( $args = array() ) { |
|
379 | +function wpinv_html_select($args = array()) { |
|
380 | 380 | $defaults = array( |
381 | 381 | 'options' => array(), |
382 | 382 | 'name' => null, |
@@ -385,8 +385,8 @@ discard block |
||
385 | 385 | 'selected' => 0, |
386 | 386 | 'placeholder' => null, |
387 | 387 | 'multiple' => false, |
388 | - 'show_option_all' => _x( 'All', 'all dropdown items', 'invoicing' ), |
|
389 | - 'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ), |
|
388 | + 'show_option_all' => _x('All', 'all dropdown items', 'invoicing'), |
|
389 | + 'show_option_none' => _x('None', 'no dropdown items', 'invoicing'), |
|
390 | 390 | 'data' => array(), |
391 | 391 | 'onchange' => null, |
392 | 392 | 'required' => false, |
@@ -394,74 +394,74 @@ discard block |
||
394 | 394 | 'readonly' => false, |
395 | 395 | ); |
396 | 396 | |
397 | - $args = wp_parse_args( $args, $defaults ); |
|
397 | + $args = wp_parse_args($args, $defaults); |
|
398 | 398 | |
399 | 399 | $data_elements = ''; |
400 | - foreach ( $args['data'] as $key => $value ) { |
|
401 | - $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"'; |
|
400 | + foreach ($args['data'] as $key => $value) { |
|
401 | + $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"'; |
|
402 | 402 | } |
403 | 403 | |
404 | - if( $args['multiple'] ) { |
|
404 | + if ($args['multiple']) { |
|
405 | 405 | $multiple = ' MULTIPLE'; |
406 | 406 | } else { |
407 | 407 | $multiple = ''; |
408 | 408 | } |
409 | 409 | |
410 | - if( $args['placeholder'] ) { |
|
410 | + if ($args['placeholder']) { |
|
411 | 411 | $placeholder = $args['placeholder']; |
412 | 412 | } else { |
413 | 413 | $placeholder = ''; |
414 | 414 | } |
415 | 415 | |
416 | 416 | $options = ''; |
417 | - if( !empty( $args['onchange'] ) ) { |
|
418 | - $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"'; |
|
417 | + if (!empty($args['onchange'])) { |
|
418 | + $options .= ' onchange="' . esc_attr($args['onchange']) . '"'; |
|
419 | 419 | } |
420 | 420 | |
421 | - if( !empty( $args['required'] ) ) { |
|
421 | + if (!empty($args['required'])) { |
|
422 | 422 | $options .= ' required="required"'; |
423 | 423 | } |
424 | 424 | |
425 | - if( !empty( $args['disabled'] ) ) { |
|
425 | + if (!empty($args['disabled'])) { |
|
426 | 426 | $options .= ' disabled'; |
427 | 427 | } |
428 | 428 | |
429 | - if( !empty( $args['readonly'] ) ) { |
|
429 | + if (!empty($args['readonly'])) { |
|
430 | 430 | $options .= ' readonly'; |
431 | 431 | } |
432 | 432 | |
433 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
434 | - $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>'; |
|
433 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
434 | + $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>'; |
|
435 | 435 | |
436 | - if ( $args['show_option_all'] ) { |
|
437 | - if( $args['multiple'] ) { |
|
438 | - $selected = selected( true, in_array( 0, $args['selected'] ), false ); |
|
436 | + if ($args['show_option_all']) { |
|
437 | + if ($args['multiple']) { |
|
438 | + $selected = selected(true, in_array(0, $args['selected']), false); |
|
439 | 439 | } else { |
440 | - $selected = selected( $args['selected'], 0, false ); |
|
440 | + $selected = selected($args['selected'], 0, false); |
|
441 | 441 | } |
442 | - $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>'; |
|
442 | + $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>'; |
|
443 | 443 | } |
444 | 444 | |
445 | - if ( !empty( $args['options'] ) ) { |
|
445 | + if (!empty($args['options'])) { |
|
446 | 446 | |
447 | - if ( $args['show_option_none'] ) { |
|
448 | - if( $args['multiple'] ) { |
|
449 | - $selected = selected( true, in_array( "", $args['selected'] ), false ); |
|
447 | + if ($args['show_option_none']) { |
|
448 | + if ($args['multiple']) { |
|
449 | + $selected = selected(true, in_array("", $args['selected']), false); |
|
450 | 450 | } else { |
451 | - $selected = selected( $args['selected'] === "", true, false ); |
|
451 | + $selected = selected($args['selected'] === "", true, false); |
|
452 | 452 | } |
453 | - $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>'; |
|
453 | + $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>'; |
|
454 | 454 | } |
455 | 455 | |
456 | - foreach( $args['options'] as $key => $option ) { |
|
456 | + foreach ($args['options'] as $key => $option) { |
|
457 | 457 | |
458 | - if( $args['multiple'] && is_array( $args['selected'] ) ) { |
|
459 | - $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false ); |
|
458 | + if ($args['multiple'] && is_array($args['selected'])) { |
|
459 | + $selected = selected(true, (bool) in_array($key, $args['selected']), false); |
|
460 | 460 | } else { |
461 | - $selected = selected( $args['selected'], $key, false ); |
|
461 | + $selected = selected($args['selected'], $key, false); |
|
462 | 462 | } |
463 | 463 | |
464 | - $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>'; |
|
464 | + $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>'; |
|
465 | 465 | } |
466 | 466 | } |
467 | 467 | |
@@ -470,7 +470,7 @@ discard block |
||
470 | 470 | return $output; |
471 | 471 | } |
472 | 472 | |
473 | -function wpinv_item_dropdown( $args = array() ) { |
|
473 | +function wpinv_item_dropdown($args = array()) { |
|
474 | 474 | $defaults = array( |
475 | 475 | 'name' => 'wpi_item', |
476 | 476 | 'id' => 'wpi_item', |
@@ -478,14 +478,14 @@ discard block |
||
478 | 478 | 'multiple' => false, |
479 | 479 | 'selected' => 0, |
480 | 480 | 'number' => 100, |
481 | - 'placeholder' => __( 'Choose a item', 'invoicing' ), |
|
482 | - 'data' => array( 'search-type' => 'item' ), |
|
481 | + 'placeholder' => __('Choose a item', 'invoicing'), |
|
482 | + 'data' => array('search-type' => 'item'), |
|
483 | 483 | 'show_option_all' => false, |
484 | 484 | 'show_option_none' => false, |
485 | 485 | 'show_recurring' => false, |
486 | 486 | ); |
487 | 487 | |
488 | - $args = wp_parse_args( $args, $defaults ); |
|
488 | + $args = wp_parse_args($args, $defaults); |
|
489 | 489 | |
490 | 490 | $item_args = array( |
491 | 491 | 'post_type' => 'wpi_item', |
@@ -494,44 +494,44 @@ discard block |
||
494 | 494 | 'posts_per_page' => $args['number'] |
495 | 495 | ); |
496 | 496 | |
497 | - $item_args = apply_filters( 'wpinv_item_dropdown_query_args', $item_args, $args, $defaults ); |
|
497 | + $item_args = apply_filters('wpinv_item_dropdown_query_args', $item_args, $args, $defaults); |
|
498 | 498 | |
499 | - $items = get_posts( $item_args ); |
|
499 | + $items = get_posts($item_args); |
|
500 | 500 | $options = array(); |
501 | - if ( $items ) { |
|
502 | - foreach ( $items as $item ) { |
|
503 | - $title = esc_html( $item->post_title ); |
|
501 | + if ($items) { |
|
502 | + foreach ($items as $item) { |
|
503 | + $title = esc_html($item->post_title); |
|
504 | 504 | |
505 | - if ( !empty( $args['show_recurring'] ) ) { |
|
506 | - $title .= wpinv_get_item_suffix( $item->ID, false ); |
|
505 | + if (!empty($args['show_recurring'])) { |
|
506 | + $title .= wpinv_get_item_suffix($item->ID, false); |
|
507 | 507 | } |
508 | 508 | |
509 | - $options[ absint( $item->ID ) ] = $title; |
|
509 | + $options[absint($item->ID)] = $title; |
|
510 | 510 | } |
511 | 511 | } |
512 | 512 | |
513 | 513 | // This ensures that any selected items are included in the drop down |
514 | - if( is_array( $args['selected'] ) ) { |
|
515 | - foreach( $args['selected'] as $item ) { |
|
516 | - if( ! in_array( $item, $options ) ) { |
|
517 | - $title = get_the_title( $item ); |
|
518 | - if ( !empty( $args['show_recurring'] ) ) { |
|
519 | - $title .= wpinv_get_item_suffix( $item, false ); |
|
514 | + if (is_array($args['selected'])) { |
|
515 | + foreach ($args['selected'] as $item) { |
|
516 | + if (!in_array($item, $options)) { |
|
517 | + $title = get_the_title($item); |
|
518 | + if (!empty($args['show_recurring'])) { |
|
519 | + $title .= wpinv_get_item_suffix($item, false); |
|
520 | 520 | } |
521 | 521 | $options[$item] = $title; |
522 | 522 | } |
523 | 523 | } |
524 | - } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) { |
|
525 | - if ( ! in_array( $args['selected'], $options ) ) { |
|
526 | - $title = get_the_title( $args['selected'] ); |
|
527 | - if ( !empty( $args['show_recurring'] ) ) { |
|
528 | - $title .= wpinv_get_item_suffix( $args['selected'], false ); |
|
524 | + } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) { |
|
525 | + if (!in_array($args['selected'], $options)) { |
|
526 | + $title = get_the_title($args['selected']); |
|
527 | + if (!empty($args['show_recurring'])) { |
|
528 | + $title .= wpinv_get_item_suffix($args['selected'], false); |
|
529 | 529 | } |
530 | - $options[$args['selected']] = get_the_title( $args['selected'] ); |
|
530 | + $options[$args['selected']] = get_the_title($args['selected']); |
|
531 | 531 | } |
532 | 532 | } |
533 | 533 | |
534 | - $output = wpinv_html_select( array( |
|
534 | + $output = wpinv_html_select(array( |
|
535 | 535 | 'name' => $args['name'], |
536 | 536 | 'selected' => $args['selected'], |
537 | 537 | 'id' => $args['id'], |
@@ -542,7 +542,7 @@ discard block |
||
542 | 542 | 'show_option_all' => $args['show_option_all'], |
543 | 543 | 'show_option_none' => $args['show_option_none'], |
544 | 544 | 'data' => $args['data'], |
545 | - ) ); |
|
545 | + )); |
|
546 | 546 | |
547 | 547 | return $output; |
548 | 548 | } |
@@ -562,16 +562,16 @@ discard block |
||
562 | 562 | ); |
563 | 563 | |
564 | 564 | $options = array(); |
565 | - if ( $items ) { |
|
566 | - foreach ( $items as $item ) { |
|
567 | - $options[ $item->ID ] = esc_html( $item->post_title ) . wpinv_get_item_suffix( $item->ID, false ); |
|
565 | + if ($items) { |
|
566 | + foreach ($items as $item) { |
|
567 | + $options[$item->ID] = esc_html($item->post_title) . wpinv_get_item_suffix($item->ID, false); |
|
568 | 568 | } |
569 | 569 | } |
570 | 570 | |
571 | 571 | return $options; |
572 | 572 | } |
573 | 573 | |
574 | -function wpinv_html_checkbox( $args = array() ) { |
|
574 | +function wpinv_html_checkbox($args = array()) { |
|
575 | 575 | $defaults = array( |
576 | 576 | 'name' => null, |
577 | 577 | 'current' => null, |
@@ -582,17 +582,17 @@ discard block |
||
582 | 582 | ) |
583 | 583 | ); |
584 | 584 | |
585 | - $args = wp_parse_args( $args, $defaults ); |
|
585 | + $args = wp_parse_args($args, $defaults); |
|
586 | 586 | |
587 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
587 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
588 | 588 | $options = ''; |
589 | - if ( ! empty( $args['options']['disabled'] ) ) { |
|
589 | + if (!empty($args['options']['disabled'])) { |
|
590 | 590 | $options .= ' disabled="disabled"'; |
591 | - } elseif ( ! empty( $args['options']['readonly'] ) ) { |
|
591 | + } elseif (!empty($args['options']['readonly'])) { |
|
592 | 592 | $options .= ' readonly'; |
593 | 593 | } |
594 | 594 | |
595 | - $output = '<input type="checkbox"' . $options . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $class . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />'; |
|
595 | + $output = '<input type="checkbox"' . $options . ' name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . $class . ' ' . esc_attr($args['name']) . '" ' . checked(1, $args['current'], false) . ' />'; |
|
596 | 596 | |
597 | 597 | return $output; |
598 | 598 | } |
@@ -600,30 +600,30 @@ discard block |
||
600 | 600 | /** |
601 | 601 | * Displays a hidden field. |
602 | 602 | */ |
603 | -function getpaid_hidden_field( $name, $value ) { |
|
604 | - $name = sanitize_text_field( $name ); |
|
605 | - $value = esc_attr( $value ); |
|
603 | +function getpaid_hidden_field($name, $value) { |
|
604 | + $name = sanitize_text_field($name); |
|
605 | + $value = esc_attr($value); |
|
606 | 606 | |
607 | 607 | echo "<input type='hidden' name='$name' value='$value' />"; |
608 | 608 | } |
609 | 609 | |
610 | -function wpinv_html_text( $args = array() ) { |
|
610 | +function wpinv_html_text($args = array()) { |
|
611 | 611 | // Backwards compatibility |
612 | - if ( func_num_args() > 1 ) { |
|
612 | + if (func_num_args() > 1) { |
|
613 | 613 | $args = func_get_args(); |
614 | 614 | |
615 | 615 | $name = $args[0]; |
616 | - $value = isset( $args[1] ) ? $args[1] : ''; |
|
617 | - $label = isset( $args[2] ) ? $args[2] : ''; |
|
618 | - $desc = isset( $args[3] ) ? $args[3] : ''; |
|
616 | + $value = isset($args[1]) ? $args[1] : ''; |
|
617 | + $label = isset($args[2]) ? $args[2] : ''; |
|
618 | + $desc = isset($args[3]) ? $args[3] : ''; |
|
619 | 619 | } |
620 | 620 | |
621 | 621 | $defaults = array( |
622 | 622 | 'id' => '', |
623 | - 'name' => isset( $name ) ? $name : 'text', |
|
624 | - 'value' => isset( $value ) ? $value : null, |
|
625 | - 'label' => isset( $label ) ? $label : null, |
|
626 | - 'desc' => isset( $desc ) ? $desc : null, |
|
623 | + 'name' => isset($name) ? $name : 'text', |
|
624 | + 'value' => isset($value) ? $value : null, |
|
625 | + 'label' => isset($label) ? $label : null, |
|
626 | + 'desc' => isset($desc) ? $desc : null, |
|
627 | 627 | 'placeholder' => '', |
628 | 628 | 'class' => 'regular-text', |
629 | 629 | 'disabled' => false, |
@@ -633,51 +633,51 @@ discard block |
||
633 | 633 | 'data' => false |
634 | 634 | ); |
635 | 635 | |
636 | - $args = wp_parse_args( $args, $defaults ); |
|
636 | + $args = wp_parse_args($args, $defaults); |
|
637 | 637 | |
638 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
638 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
639 | 639 | $options = ''; |
640 | - if( $args['required'] ) { |
|
640 | + if ($args['required']) { |
|
641 | 641 | $options .= ' required="required"'; |
642 | 642 | } |
643 | - if( $args['readonly'] ) { |
|
643 | + if ($args['readonly']) { |
|
644 | 644 | $options .= ' readonly'; |
645 | 645 | } |
646 | - if( $args['readonly'] ) { |
|
646 | + if ($args['readonly']) { |
|
647 | 647 | $options .= ' readonly'; |
648 | 648 | } |
649 | 649 | |
650 | 650 | $data = ''; |
651 | - if ( !empty( $args['data'] ) ) { |
|
652 | - foreach ( $args['data'] as $key => $value ) { |
|
653 | - $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" '; |
|
651 | + if (!empty($args['data'])) { |
|
652 | + foreach ($args['data'] as $key => $value) { |
|
653 | + $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" '; |
|
654 | 654 | } |
655 | 655 | } |
656 | 656 | |
657 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
658 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
659 | - if ( ! empty( $args['desc'] ) ) { |
|
660 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
657 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
658 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>'; |
|
659 | + if (!empty($args['desc'])) { |
|
660 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
661 | 661 | } |
662 | 662 | |
663 | - $output .= '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" autocomplete="' . esc_attr( $args['autocomplete'] ) . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $class . '" ' . $data . ' ' . trim( $options ) . '/>'; |
|
663 | + $output .= '<input type="text" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" autocomplete="' . esc_attr($args['autocomplete']) . '" value="' . esc_attr($args['value']) . '" placeholder="' . esc_attr($args['placeholder']) . '" class="' . $class . '" ' . $data . ' ' . trim($options) . '/>'; |
|
664 | 664 | |
665 | 665 | $output .= '</span>'; |
666 | 666 | |
667 | 667 | return $output; |
668 | 668 | } |
669 | 669 | |
670 | -function wpinv_html_date_field( $args = array() ) { |
|
671 | - if( empty( $args['class'] ) ) { |
|
670 | +function wpinv_html_date_field($args = array()) { |
|
671 | + if (empty($args['class'])) { |
|
672 | 672 | $args['class'] = 'wpiDatepicker'; |
673 | - } elseif( ! strpos( $args['class'], 'wpiDatepicker' ) ) { |
|
673 | + } elseif (!strpos($args['class'], 'wpiDatepicker')) { |
|
674 | 674 | $args['class'] .= ' wpiDatepicker'; |
675 | 675 | } |
676 | 676 | |
677 | - return wpinv_html_text( $args ); |
|
677 | + return wpinv_html_text($args); |
|
678 | 678 | } |
679 | 679 | |
680 | -function wpinv_html_textarea( $args = array() ) { |
|
680 | +function wpinv_html_textarea($args = array()) { |
|
681 | 681 | $defaults = array( |
682 | 682 | 'name' => 'textarea', |
683 | 683 | 'value' => null, |
@@ -688,31 +688,31 @@ discard block |
||
688 | 688 | 'placeholder' => '', |
689 | 689 | ); |
690 | 690 | |
691 | - $args = wp_parse_args( $args, $defaults ); |
|
691 | + $args = wp_parse_args($args, $defaults); |
|
692 | 692 | |
693 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
693 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
694 | 694 | $disabled = ''; |
695 | - if( $args['disabled'] ) { |
|
695 | + if ($args['disabled']) { |
|
696 | 696 | $disabled = ' disabled="disabled"'; |
697 | 697 | } |
698 | 698 | |
699 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
700 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
701 | - $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>'; |
|
699 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
700 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>'; |
|
701 | + $output .= '<textarea name="' . esc_attr($args['name']) . '" placeholder="' . esc_attr($args['placeholder']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>'; |
|
702 | 702 | |
703 | - if ( ! empty( $args['desc'] ) ) { |
|
704 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
703 | + if (!empty($args['desc'])) { |
|
704 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
705 | 705 | } |
706 | 706 | $output .= '</span>'; |
707 | 707 | |
708 | 708 | return $output; |
709 | 709 | } |
710 | 710 | |
711 | -function wpinv_html_ajax_user_search( $args = array() ) { |
|
711 | +function wpinv_html_ajax_user_search($args = array()) { |
|
712 | 712 | $defaults = array( |
713 | 713 | 'name' => 'user_id', |
714 | 714 | 'value' => null, |
715 | - 'placeholder' => __( 'Enter username', 'invoicing' ), |
|
715 | + 'placeholder' => __('Enter username', 'invoicing'), |
|
716 | 716 | 'label' => null, |
717 | 717 | 'desc' => null, |
718 | 718 | 'class' => '', |
@@ -721,13 +721,13 @@ discard block |
||
721 | 721 | 'data' => false |
722 | 722 | ); |
723 | 723 | |
724 | - $args = wp_parse_args( $args, $defaults ); |
|
724 | + $args = wp_parse_args($args, $defaults); |
|
725 | 725 | |
726 | 726 | $args['class'] = 'wpinv-ajax-user-search ' . $args['class']; |
727 | 727 | |
728 | 728 | $output = '<span class="wpinv_user_search_wrap">'; |
729 | - $output .= wpinv_html_text( $args ); |
|
730 | - $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __( 'Cancel', 'invoicing' ) . '" aria-label="' . __( 'Cancel', 'invoicing' ) . '" href="#">x</a><span></span></span>'; |
|
729 | + $output .= wpinv_html_text($args); |
|
730 | + $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __('Cancel', 'invoicing') . '" aria-label="' . __('Cancel', 'invoicing') . '" href="#">x</a><span></span></span>'; |
|
731 | 731 | $output .= '</span>'; |
732 | 732 | |
733 | 733 | return $output; |
@@ -743,20 +743,20 @@ discard block |
||
743 | 743 | * |
744 | 744 | * @param string $template the template that is currently being used. |
745 | 745 | */ |
746 | -function wpinv_template( $template ) { |
|
746 | +function wpinv_template($template) { |
|
747 | 747 | global $post; |
748 | 748 | |
749 | - if ( ! is_admin() && ( is_single() || is_404() ) && ! empty( $post->ID ) && getpaid_is_invoice_post_type( get_post_type( $post->ID ) ) ) { |
|
749 | + if (!is_admin() && (is_single() || is_404()) && !empty($post->ID) && getpaid_is_invoice_post_type(get_post_type($post->ID))) { |
|
750 | 750 | |
751 | 751 | // If the user can view this invoice, display it. |
752 | - if ( wpinv_user_can_view_invoice( $post->ID ) ) { |
|
752 | + if (wpinv_user_can_view_invoice($post->ID)) { |
|
753 | 753 | |
754 | - return wpinv_get_template_part( 'wpinv-invoice-print', false, false ); |
|
754 | + return wpinv_get_template_part('wpinv-invoice-print', false, false); |
|
755 | 755 | |
756 | 756 | // Else display an error message. |
757 | 757 | } else { |
758 | 758 | |
759 | - return wpinv_get_template_part( 'wpinv-invalid-access', false, false ); |
|
759 | + return wpinv_get_template_part('wpinv-invalid-access', false, false); |
|
760 | 760 | |
761 | 761 | } |
762 | 762 | |
@@ -764,46 +764,46 @@ discard block |
||
764 | 764 | |
765 | 765 | return $template; |
766 | 766 | } |
767 | -add_filter( 'template_include', 'wpinv_template', 10, 1 ); |
|
767 | +add_filter('template_include', 'wpinv_template', 10, 1); |
|
768 | 768 | |
769 | 769 | function wpinv_get_business_address() { |
770 | 770 | $business_address = wpinv_store_address(); |
771 | - $business_address = !empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : ''; |
|
771 | + $business_address = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : ''; |
|
772 | 772 | |
773 | 773 | $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : ''; |
774 | 774 | |
775 | - return apply_filters( 'wpinv_get_business_address', $business_address ); |
|
775 | + return apply_filters('wpinv_get_business_address', $business_address); |
|
776 | 776 | } |
777 | 777 | |
778 | 778 | /** |
779 | 779 | * Displays the company address. |
780 | 780 | */ |
781 | 781 | function wpinv_display_from_address() { |
782 | - wpinv_get_template( 'invoice/company-address.php' ); |
|
782 | + wpinv_get_template('invoice/company-address.php'); |
|
783 | 783 | } |
784 | -add_action( 'getpaid_invoice_details_left', 'wpinv_display_from_address', 10 ); |
|
784 | +add_action('getpaid_invoice_details_left', 'wpinv_display_from_address', 10); |
|
785 | 785 | |
786 | -function wpinv_watermark( $id = 0 ) { |
|
787 | - $output = wpinv_get_watermark( $id ); |
|
788 | - return apply_filters( 'wpinv_get_watermark', $output, $id ); |
|
786 | +function wpinv_watermark($id = 0) { |
|
787 | + $output = wpinv_get_watermark($id); |
|
788 | + return apply_filters('wpinv_get_watermark', $output, $id); |
|
789 | 789 | } |
790 | 790 | |
791 | -function wpinv_get_watermark( $id ) { |
|
792 | - if ( !$id > 0 ) { |
|
791 | +function wpinv_get_watermark($id) { |
|
792 | + if (!$id > 0) { |
|
793 | 793 | return NULL; |
794 | 794 | } |
795 | 795 | |
796 | - $invoice = wpinv_get_invoice( $id ); |
|
796 | + $invoice = wpinv_get_invoice($id); |
|
797 | 797 | |
798 | - if ( !empty( $invoice ) && "wpi_invoice" === $invoice->post_type ) { |
|
799 | - if ( $invoice->is_paid() ) { |
|
800 | - return __( 'Paid', 'invoicing' ); |
|
798 | + if (!empty($invoice) && "wpi_invoice" === $invoice->post_type) { |
|
799 | + if ($invoice->is_paid()) { |
|
800 | + return __('Paid', 'invoicing'); |
|
801 | 801 | } |
802 | - if ( $invoice->is_refunded() ) { |
|
803 | - return __( 'Refunded', 'invoicing' ); |
|
802 | + if ($invoice->is_refunded()) { |
|
803 | + return __('Refunded', 'invoicing'); |
|
804 | 804 | } |
805 | - if ( $invoice->has_status( array( 'wpi-cancelled' ) ) ) { |
|
806 | - return __( 'Cancelled', 'invoicing' ); |
|
805 | + if ($invoice->has_status(array('wpi-cancelled'))) { |
|
806 | + return __('Cancelled', 'invoicing'); |
|
807 | 807 | } |
808 | 808 | } |
809 | 809 | |
@@ -813,140 +813,140 @@ discard block |
||
813 | 813 | /** |
814 | 814 | * @deprecated |
815 | 815 | */ |
816 | -function wpinv_display_invoice_details( $invoice ) { |
|
817 | - return getpaid_invoice_meta( $invoice ); |
|
816 | +function wpinv_display_invoice_details($invoice) { |
|
817 | + return getpaid_invoice_meta($invoice); |
|
818 | 818 | } |
819 | 819 | |
820 | 820 | /** |
821 | 821 | * Displays invoice meta. |
822 | 822 | */ |
823 | -function getpaid_invoice_meta( $invoice ) { |
|
823 | +function getpaid_invoice_meta($invoice) { |
|
824 | 824 | |
825 | - $invoice = new WPInv_Invoice( $invoice ); |
|
825 | + $invoice = new WPInv_Invoice($invoice); |
|
826 | 826 | |
827 | 827 | // Ensure that we have an invoice. |
828 | - if ( 0 == $invoice->get_id() ) { |
|
828 | + if (0 == $invoice->get_id()) { |
|
829 | 829 | return; |
830 | 830 | } |
831 | 831 | |
832 | 832 | // Load the invoice meta. |
833 | - $meta = array( |
|
833 | + $meta = array( |
|
834 | 834 | |
835 | 835 | 'number' => array( |
836 | 836 | 'label' => sprintf( |
837 | - __( '%s Number', 'invoicing' ), |
|
838 | - ucfirst( $invoice->get_type() ) |
|
837 | + __('%s Number', 'invoicing'), |
|
838 | + ucfirst($invoice->get_type()) |
|
839 | 839 | ), |
840 | - 'value' => sanitize_text_field( $invoice->get_number() ), |
|
840 | + 'value' => sanitize_text_field($invoice->get_number()), |
|
841 | 841 | ), |
842 | 842 | |
843 | 843 | 'status' => array( |
844 | 844 | 'label' => sprintf( |
845 | - __( '%s Status', 'invoicing' ), |
|
846 | - ucfirst( $invoice->get_type() ) |
|
845 | + __('%s Status', 'invoicing'), |
|
846 | + ucfirst($invoice->get_type()) |
|
847 | 847 | ), |
848 | 848 | 'value' => $invoice->get_status_label_html(), |
849 | 849 | ), |
850 | 850 | |
851 | 851 | 'date' => array( |
852 | 852 | 'label' => sprintf( |
853 | - __( '%s Date', 'invoicing' ), |
|
854 | - ucfirst( $invoice->get_type() ) |
|
853 | + __('%s Date', 'invoicing'), |
|
854 | + ucfirst($invoice->get_type()) |
|
855 | 855 | ), |
856 | - 'value' => getpaid_format_date( $invoice->get_created_date() ), |
|
856 | + 'value' => getpaid_format_date($invoice->get_created_date()), |
|
857 | 857 | ), |
858 | 858 | |
859 | 859 | 'date_paid' => array( |
860 | - 'label' => __( 'Paid On', 'invoicing' ), |
|
861 | - 'value' => getpaid_format_date( $invoice->get_completed_date() ), |
|
860 | + 'label' => __('Paid On', 'invoicing'), |
|
861 | + 'value' => getpaid_format_date($invoice->get_completed_date()), |
|
862 | 862 | ), |
863 | 863 | |
864 | 864 | 'gateway' => array( |
865 | - 'label' => __( 'Payment Method', 'invoicing' ), |
|
866 | - 'value' => sanitize_text_field( $invoice->get_gateway_title() ), |
|
865 | + 'label' => __('Payment Method', 'invoicing'), |
|
866 | + 'value' => sanitize_text_field($invoice->get_gateway_title()), |
|
867 | 867 | ), |
868 | 868 | |
869 | 869 | 'transaction_id' => array( |
870 | - 'label' => __( 'Transaction ID', 'invoicing' ), |
|
871 | - 'value' => sanitize_text_field( $invoice->get_transaction_id() ), |
|
870 | + 'label' => __('Transaction ID', 'invoicing'), |
|
871 | + 'value' => sanitize_text_field($invoice->get_transaction_id()), |
|
872 | 872 | ), |
873 | 873 | |
874 | 874 | 'due_date' => array( |
875 | - 'label' => __( 'Due Date', 'invoicing' ), |
|
876 | - 'value' => getpaid_format_date( $invoice->get_due_date() ), |
|
875 | + 'label' => __('Due Date', 'invoicing'), |
|
876 | + 'value' => getpaid_format_date($invoice->get_due_date()), |
|
877 | 877 | ), |
878 | 878 | |
879 | 879 | 'vat_number' => array( |
880 | 880 | 'label' => sprintf( |
881 | - __( '%s Number', 'invoicing' ), |
|
881 | + __('%s Number', 'invoicing'), |
|
882 | 882 | getpaid_tax()->get_vat_name() |
883 | 883 | ), |
884 | - 'value' => sanitize_text_field( $invoice->get_vat_number() ), |
|
884 | + 'value' => sanitize_text_field($invoice->get_vat_number()), |
|
885 | 885 | ), |
886 | 886 | |
887 | 887 | ); |
888 | 888 | |
889 | 889 | // If it is not paid, remove the date of payment. |
890 | - if ( ! $invoice->is_paid() ) { |
|
891 | - unset( $meta[ 'date_paid' ] ); |
|
892 | - unset( $meta[ 'transaction_id' ] ); |
|
890 | + if (!$invoice->is_paid()) { |
|
891 | + unset($meta['date_paid']); |
|
892 | + unset($meta['transaction_id']); |
|
893 | 893 | } |
894 | 894 | |
895 | - if ( ! $invoice->is_paid() || 'none' == $invoice->get_gateway() ) { |
|
896 | - unset( $meta[ 'gateway' ] ); |
|
895 | + if (!$invoice->is_paid() || 'none' == $invoice->get_gateway()) { |
|
896 | + unset($meta['gateway']); |
|
897 | 897 | } |
898 | 898 | |
899 | 899 | // Only display the due date if due dates are enabled. |
900 | - if ( ! $invoice->needs_payment() || ! wpinv_get_option( 'overdue_active' ) ) { |
|
901 | - unset( $meta[ 'due_date' ] ); |
|
900 | + if (!$invoice->needs_payment() || !wpinv_get_option('overdue_active')) { |
|
901 | + unset($meta['due_date']); |
|
902 | 902 | } |
903 | 903 | |
904 | 904 | // Only display the vat number if taxes are enabled. |
905 | - if ( ! wpinv_use_taxes() ) { |
|
906 | - unset( $meta[ 'vat_number' ] ); |
|
905 | + if (!wpinv_use_taxes()) { |
|
906 | + unset($meta['vat_number']); |
|
907 | 907 | } |
908 | 908 | |
909 | - if ( $invoice->is_recurring() ) { |
|
909 | + if ($invoice->is_recurring()) { |
|
910 | 910 | |
911 | 911 | // Link to the parent invoice. |
912 | - if ( $invoice->is_renewal() ) { |
|
912 | + if ($invoice->is_renewal()) { |
|
913 | 913 | |
914 | - $meta[ 'parent' ] = array( |
|
914 | + $meta['parent'] = array( |
|
915 | 915 | |
916 | 916 | 'label' => sprintf( |
917 | - __( 'Parent %s', 'invoicing' ), |
|
918 | - ucfirst( $invoice->get_type() ) |
|
917 | + __('Parent %s', 'invoicing'), |
|
918 | + ucfirst($invoice->get_type()) |
|
919 | 919 | ), |
920 | 920 | |
921 | - 'value' => wpinv_invoice_link( $invoice->get_parent_id() ), |
|
921 | + 'value' => wpinv_invoice_link($invoice->get_parent_id()), |
|
922 | 922 | |
923 | 923 | ); |
924 | 924 | |
925 | 925 | } |
926 | 926 | |
927 | - $subscription = wpinv_get_subscription( $invoice ); |
|
927 | + $subscription = wpinv_get_subscription($invoice); |
|
928 | 928 | |
929 | - if ( ! empty ( $subscription ) ) { |
|
929 | + if (!empty ($subscription)) { |
|
930 | 930 | |
931 | 931 | // Display the renewal date. |
932 | - if ( $subscription->is_active() && 'cancelled' != $subscription->status ) { |
|
932 | + if ($subscription->is_active() && 'cancelled' != $subscription->status) { |
|
933 | 933 | |
934 | - $meta[ 'renewal_date' ] = array( |
|
934 | + $meta['renewal_date'] = array( |
|
935 | 935 | |
936 | - 'label' => __( 'Renews On', 'invoicing' ), |
|
937 | - 'value' => getpaid_format_date( $subscription->expiration ), |
|
936 | + 'label' => __('Renews On', 'invoicing'), |
|
937 | + 'value' => getpaid_format_date($subscription->expiration), |
|
938 | 938 | |
939 | 939 | ); |
940 | 940 | |
941 | 941 | } |
942 | 942 | |
943 | - if ( $invoice->is_parent() ) { |
|
943 | + if ($invoice->is_parent()) { |
|
944 | 944 | |
945 | 945 | // Display the recurring amount. |
946 | - $meta[ 'recurring_total' ] = array( |
|
946 | + $meta['recurring_total'] = array( |
|
947 | 947 | |
948 | - 'label' => __( 'Recurring Amount', 'invoicing' ), |
|
949 | - 'value' => wpinv_price( wpinv_format_amount( $subscription->recurring_amount ), $invoice->get_currency() ), |
|
948 | + 'label' => __('Recurring Amount', 'invoicing'), |
|
949 | + 'value' => wpinv_price(wpinv_format_amount($subscription->recurring_amount), $invoice->get_currency()), |
|
950 | 950 | |
951 | 951 | ); |
952 | 952 | |
@@ -956,20 +956,20 @@ discard block |
||
956 | 956 | } |
957 | 957 | |
958 | 958 | // Add the invoice total to the meta. |
959 | - $meta[ 'invoice_total' ] = array( |
|
959 | + $meta['invoice_total'] = array( |
|
960 | 960 | |
961 | - 'label' => __( 'Total Amount', 'invoicing' ), |
|
962 | - 'value' => wpinv_price( wpinv_format_amount( $invoice->get_total() ), $invoice->get_currency() ), |
|
961 | + 'label' => __('Total Amount', 'invoicing'), |
|
962 | + 'value' => wpinv_price(wpinv_format_amount($invoice->get_total()), $invoice->get_currency()), |
|
963 | 963 | |
964 | 964 | ); |
965 | 965 | |
966 | 966 | // Provide a way for third party plugins to filter the meta. |
967 | - $meta = apply_filters( 'getpaid_invoice_meta_data', $meta, $invoice ); |
|
967 | + $meta = apply_filters('getpaid_invoice_meta_data', $meta, $invoice); |
|
968 | 968 | |
969 | - wpinv_get_template( 'invoice/invoice-meta.php', compact( 'invoice', 'meta' ) ); |
|
969 | + wpinv_get_template('invoice/invoice-meta.php', compact('invoice', 'meta')); |
|
970 | 970 | |
971 | 971 | } |
972 | -add_action( 'getpaid_invoice_details_right', 'getpaid_invoice_meta', 10 ); |
|
972 | +add_action('getpaid_invoice_details_right', 'getpaid_invoice_meta', 10); |
|
973 | 973 | |
974 | 974 | /** |
975 | 975 | * Retrieves the address markup to use on Invoices. |
@@ -981,29 +981,29 @@ discard block |
||
981 | 981 | * @param string $separator How to separate address lines. |
982 | 982 | * @return string |
983 | 983 | */ |
984 | -function wpinv_get_invoice_address_markup( $billing_details, $separator = '<br/>' ) { |
|
984 | +function wpinv_get_invoice_address_markup($billing_details, $separator = '<br/>') { |
|
985 | 985 | |
986 | 986 | // Retrieve the address markup... |
987 | - $country= empty( $billing_details['country'] ) ? '' : $billing_details['country']; |
|
988 | - $format = wpinv_get_full_address_format( $country ); |
|
987 | + $country = empty($billing_details['country']) ? '' : $billing_details['country']; |
|
988 | + $format = wpinv_get_full_address_format($country); |
|
989 | 989 | |
990 | 990 | // ... and the replacements. |
991 | - $replacements = wpinv_get_invoice_address_replacements( $billing_details ); |
|
991 | + $replacements = wpinv_get_invoice_address_replacements($billing_details); |
|
992 | 992 | |
993 | - $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format ); |
|
993 | + $formatted_address = str_ireplace(array_keys($replacements), $replacements, $format); |
|
994 | 994 | |
995 | 995 | // Remove unavailable tags. |
996 | - $formatted_address = preg_replace( "/\{\{\w+\}\}/", '', $formatted_address ); |
|
996 | + $formatted_address = preg_replace("/\{\{\w+\}\}/", '', $formatted_address); |
|
997 | 997 | |
998 | 998 | // Clean up white space. |
999 | - $formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) ); |
|
1000 | - $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address ); |
|
999 | + $formatted_address = preg_replace('/ +/', ' ', trim($formatted_address)); |
|
1000 | + $formatted_address = preg_replace('/\n\n+/', "\n", $formatted_address); |
|
1001 | 1001 | |
1002 | 1002 | // Break newlines apart and remove empty lines/trim commas and white space. |
1003 | - $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) ); |
|
1003 | + $formatted_address = array_filter(array_map('wpinv_trim_formatted_address_line', explode("\n", $formatted_address))); |
|
1004 | 1004 | |
1005 | 1005 | // Add html breaks. |
1006 | - $formatted_address = implode( $separator, $formatted_address ); |
|
1006 | + $formatted_address = implode($separator, $formatted_address); |
|
1007 | 1007 | |
1008 | 1008 | // We're done! |
1009 | 1009 | return $formatted_address; |
@@ -1015,88 +1015,88 @@ discard block |
||
1015 | 1015 | * |
1016 | 1016 | * @param WPInv_Invoice $invoice |
1017 | 1017 | */ |
1018 | -function wpinv_display_to_address( $invoice = 0 ) { |
|
1019 | - if ( ! empty( $invoice ) ) { |
|
1020 | - wpinv_get_template( 'invoice/billing-address.php', compact( 'invoice' ) ); |
|
1018 | +function wpinv_display_to_address($invoice = 0) { |
|
1019 | + if (!empty($invoice)) { |
|
1020 | + wpinv_get_template('invoice/billing-address.php', compact('invoice')); |
|
1021 | 1021 | } |
1022 | 1022 | } |
1023 | -add_action( 'getpaid_invoice_details_left', 'wpinv_display_to_address', 40 ); |
|
1023 | +add_action('getpaid_invoice_details_left', 'wpinv_display_to_address', 40); |
|
1024 | 1024 | |
1025 | 1025 | |
1026 | 1026 | /** |
1027 | 1027 | * Displays invoice line items. |
1028 | 1028 | */ |
1029 | -function wpinv_display_line_items( $invoice_id = 0 ) { |
|
1029 | +function wpinv_display_line_items($invoice_id = 0) { |
|
1030 | 1030 | |
1031 | 1031 | // Prepare the invoice. |
1032 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
1032 | + $invoice = new WPInv_Invoice($invoice_id); |
|
1033 | 1033 | |
1034 | 1034 | // Abort if there is no invoice. |
1035 | - if ( 0 == $invoice->get_id() ) { |
|
1035 | + if (0 == $invoice->get_id()) { |
|
1036 | 1036 | return; |
1037 | 1037 | } |
1038 | 1038 | |
1039 | 1039 | // Line item columns. |
1040 | - $columns = getpaid_invoice_item_columns( $invoice ); |
|
1041 | - $columns = apply_filters( 'getpaid_invoice_line_items_table_columns', $columns, $invoice ); |
|
1040 | + $columns = getpaid_invoice_item_columns($invoice); |
|
1041 | + $columns = apply_filters('getpaid_invoice_line_items_table_columns', $columns, $invoice); |
|
1042 | 1042 | |
1043 | - wpinv_get_template( 'invoice/line-items.php', compact( 'invoice', 'columns' ) ); |
|
1043 | + wpinv_get_template('invoice/line-items.php', compact('invoice', 'columns')); |
|
1044 | 1044 | } |
1045 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_line_items', 10 ); |
|
1045 | +add_action('getpaid_invoice_line_items', 'wpinv_display_line_items', 10); |
|
1046 | 1046 | |
1047 | 1047 | /** |
1048 | 1048 | * Displays invoice notices on invoices. |
1049 | 1049 | */ |
1050 | 1050 | function wpinv_display_invoice_notice() { |
1051 | 1051 | |
1052 | - $label = wpinv_get_option( 'vat_invoice_notice_label' ); |
|
1053 | - $notice = wpinv_get_option( 'vat_invoice_notice' ); |
|
1052 | + $label = wpinv_get_option('vat_invoice_notice_label'); |
|
1053 | + $notice = wpinv_get_option('vat_invoice_notice'); |
|
1054 | 1054 | |
1055 | - if ( empty( $label ) && empty( $notice ) ) { |
|
1055 | + if (empty($label) && empty($notice)) { |
|
1056 | 1056 | return; |
1057 | 1057 | } |
1058 | 1058 | |
1059 | 1059 | echo '<div class="mt-4 mb-4 wpinv-vat-notice">'; |
1060 | 1060 | |
1061 | - if ( ! empty( $label ) ) { |
|
1062 | - $label = sanitize_text_field( $label ); |
|
1061 | + if (!empty($label)) { |
|
1062 | + $label = sanitize_text_field($label); |
|
1063 | 1063 | echo "<h5>$label</h5>"; |
1064 | 1064 | } |
1065 | 1065 | |
1066 | - if ( ! empty( $notice ) ) { |
|
1067 | - echo '<small class="form-text text-muted">' . wpautop( wptexturize( $notice ) ) . '</small>'; |
|
1066 | + if (!empty($notice)) { |
|
1067 | + echo '<small class="form-text text-muted">' . wpautop(wptexturize($notice)) . '</small>'; |
|
1068 | 1068 | } |
1069 | 1069 | |
1070 | 1070 | echo '</div>'; |
1071 | 1071 | } |
1072 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100 ); |
|
1072 | +add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100); |
|
1073 | 1073 | |
1074 | 1074 | /** |
1075 | 1075 | * @param WPInv_Invoice $invoice |
1076 | 1076 | */ |
1077 | -function wpinv_display_invoice_notes( $invoice ) { |
|
1077 | +function wpinv_display_invoice_notes($invoice) { |
|
1078 | 1078 | |
1079 | 1079 | // Retrieve the notes. |
1080 | - $notes = wpinv_get_invoice_notes( $invoice->get_id(), 'customer' ); |
|
1080 | + $notes = wpinv_get_invoice_notes($invoice->get_id(), 'customer'); |
|
1081 | 1081 | |
1082 | 1082 | // Abort if we have non. |
1083 | - if ( empty( $notes ) ) { |
|
1083 | + if (empty($notes)) { |
|
1084 | 1084 | return; |
1085 | 1085 | } |
1086 | 1086 | |
1087 | 1087 | // Echo the note. |
1088 | 1088 | echo '<div class="getpaid-invoice-notes-wrapper border position-relative w-100 mb-4 p-0">'; |
1089 | - echo '<h3 class="getpaid-invoice-notes-title text-dark bg-light border-bottom m-0 d-block">' . __( 'Notes', 'invoicing' ) .'</h3>'; |
|
1089 | + echo '<h3 class="getpaid-invoice-notes-title text-dark bg-light border-bottom m-0 d-block">' . __('Notes', 'invoicing') . '</h3>'; |
|
1090 | 1090 | echo '<ul class="getpaid-invoice-notes mt-4 p-0">'; |
1091 | 1091 | |
1092 | - foreach( $notes as $note ) { |
|
1093 | - wpinv_get_invoice_note_line_item( $note ); |
|
1092 | + foreach ($notes as $note) { |
|
1093 | + wpinv_get_invoice_note_line_item($note); |
|
1094 | 1094 | } |
1095 | 1095 | |
1096 | 1096 | echo '</ul>'; |
1097 | 1097 | echo '</div>'; |
1098 | 1098 | } |
1099 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60 ); |
|
1099 | +add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60); |
|
1100 | 1100 | |
1101 | 1101 | /** |
1102 | 1102 | * Loads scripts on our invoice templates. |
@@ -1104,32 +1104,32 @@ discard block |
||
1104 | 1104 | function wpinv_display_style() { |
1105 | 1105 | |
1106 | 1106 | // Make sure that all scripts have been loaded. |
1107 | - if ( ! did_action( 'wp_enqueue_scripts' ) ) { |
|
1108 | - do_action( 'wp_enqueue_scripts' ); |
|
1107 | + if (!did_action('wp_enqueue_scripts')) { |
|
1108 | + do_action('wp_enqueue_scripts'); |
|
1109 | 1109 | } |
1110 | 1110 | |
1111 | 1111 | // Register the invoices style. |
1112 | - wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice.css' ) ); |
|
1112 | + wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime(WPINV_PLUGIN_DIR . 'assets/css/invoice.css')); |
|
1113 | 1113 | |
1114 | 1114 | // Load required styles |
1115 | - wp_print_styles( 'open-sans' ); |
|
1116 | - wp_print_styles( 'wpinv-single-style' ); |
|
1117 | - wp_print_styles( 'ayecode-ui' ); |
|
1115 | + wp_print_styles('open-sans'); |
|
1116 | + wp_print_styles('wpinv-single-style'); |
|
1117 | + wp_print_styles('ayecode-ui'); |
|
1118 | 1118 | |
1119 | 1119 | // Maybe load custom css. |
1120 | - $custom_css = wpinv_get_option( 'template_custom_css' ); |
|
1120 | + $custom_css = wpinv_get_option('template_custom_css'); |
|
1121 | 1121 | |
1122 | - if ( isset( $custom_css ) && ! empty( $custom_css ) ) { |
|
1123 | - $custom_css = wp_kses( $custom_css, array( '\'', '\"' ) ); |
|
1124 | - $custom_css = str_replace( '>', '>', $custom_css ); |
|
1122 | + if (isset($custom_css) && !empty($custom_css)) { |
|
1123 | + $custom_css = wp_kses($custom_css, array('\'', '\"')); |
|
1124 | + $custom_css = str_replace('>', '>', $custom_css); |
|
1125 | 1125 | echo '<style type="text/css">'; |
1126 | 1126 | echo $custom_css; |
1127 | 1127 | echo '</style>'; |
1128 | 1128 | } |
1129 | 1129 | |
1130 | 1130 | } |
1131 | -add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' ); |
|
1132 | -add_action( 'wpinv_invalid_invoice_head', 'wpinv_display_style' ); |
|
1131 | +add_action('wpinv_invoice_print_head', 'wpinv_display_style'); |
|
1132 | +add_action('wpinv_invalid_invoice_head', 'wpinv_display_style'); |
|
1133 | 1133 | |
1134 | 1134 | |
1135 | 1135 | /** |
@@ -1141,41 +1141,41 @@ discard block |
||
1141 | 1141 | // Retrieve the current invoice. |
1142 | 1142 | $invoice_id = getpaid_get_current_invoice_id(); |
1143 | 1143 | |
1144 | - if ( empty( $invoice_id ) ) { |
|
1144 | + if (empty($invoice_id)) { |
|
1145 | 1145 | |
1146 | 1146 | return aui()->alert( |
1147 | 1147 | array( |
1148 | 1148 | 'type' => 'warning', |
1149 | - 'content' => __( 'Invalid invoice', 'invoicing' ), |
|
1149 | + 'content' => __('Invalid invoice', 'invoicing'), |
|
1150 | 1150 | ) |
1151 | 1151 | ); |
1152 | 1152 | |
1153 | 1153 | } |
1154 | 1154 | |
1155 | 1155 | // Can the user view this invoice? |
1156 | - if ( ! wpinv_user_can_view_invoice( $invoice_id ) ) { |
|
1156 | + if (!wpinv_user_can_view_invoice($invoice_id)) { |
|
1157 | 1157 | |
1158 | 1158 | return aui()->alert( |
1159 | 1159 | array( |
1160 | 1160 | 'type' => 'warning', |
1161 | - 'content' => __( 'You are not allowed to view this invoice', 'invoicing' ), |
|
1161 | + 'content' => __('You are not allowed to view this invoice', 'invoicing'), |
|
1162 | 1162 | ) |
1163 | 1163 | ); |
1164 | 1164 | |
1165 | 1165 | } |
1166 | 1166 | |
1167 | 1167 | // Ensure that it is not yet paid for. |
1168 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
1168 | + $invoice = new WPInv_Invoice($invoice_id); |
|
1169 | 1169 | |
1170 | 1170 | // Maybe mark it as viewed. |
1171 | - getpaid_maybe_mark_invoice_as_viewed( $invoice ); |
|
1171 | + getpaid_maybe_mark_invoice_as_viewed($invoice); |
|
1172 | 1172 | |
1173 | - if ( $invoice->is_paid() ) { |
|
1173 | + if ($invoice->is_paid()) { |
|
1174 | 1174 | |
1175 | 1175 | return aui()->alert( |
1176 | 1176 | array( |
1177 | 1177 | 'type' => 'success', |
1178 | - 'content' => __( 'This invoice has already been paid.', 'invoicing' ), |
|
1178 | + 'content' => __('This invoice has already been paid.', 'invoicing'), |
|
1179 | 1179 | ) |
1180 | 1180 | ); |
1181 | 1181 | |
@@ -1185,14 +1185,14 @@ discard block |
||
1185 | 1185 | $wpi_checkout_id = $invoice_id; |
1186 | 1186 | |
1187 | 1187 | // We'll display this invoice via the default form. |
1188 | - $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
1188 | + $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
1189 | 1189 | |
1190 | - if ( 0 == $form->get_id() ) { |
|
1190 | + if (0 == $form->get_id()) { |
|
1191 | 1191 | |
1192 | 1192 | return aui()->alert( |
1193 | 1193 | array( |
1194 | 1194 | 'type' => 'warning', |
1195 | - 'content' => __( 'Error loading the payment form', 'invoicing' ), |
|
1195 | + 'content' => __('Error loading the payment form', 'invoicing'), |
|
1196 | 1196 | ) |
1197 | 1197 | ); |
1198 | 1198 | |
@@ -1200,7 +1200,7 @@ discard block |
||
1200 | 1200 | |
1201 | 1201 | // Set the invoice. |
1202 | 1202 | $form->invoice = $invoice; |
1203 | - $form->set_items( $invoice->get_items() ); |
|
1203 | + $form->set_items($invoice->get_items()); |
|
1204 | 1204 | |
1205 | 1205 | // Generate the html. |
1206 | 1206 | return $form->get_html(); |
@@ -1208,7 +1208,7 @@ discard block |
||
1208 | 1208 | } |
1209 | 1209 | |
1210 | 1210 | function wpinv_empty_cart_message() { |
1211 | - return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1211 | + return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>'); |
|
1212 | 1212 | } |
1213 | 1213 | |
1214 | 1214 | /** |
@@ -1225,38 +1225,38 @@ discard block |
||
1225 | 1225 | ) |
1226 | 1226 | ); |
1227 | 1227 | } |
1228 | -add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' ); |
|
1228 | +add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart'); |
|
1229 | 1229 | |
1230 | -function wpinv_receipt_billing_address( $invoice_id = 0 ) { |
|
1231 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1230 | +function wpinv_receipt_billing_address($invoice_id = 0) { |
|
1231 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1232 | 1232 | |
1233 | - if ( empty( $invoice ) ) { |
|
1233 | + if (empty($invoice)) { |
|
1234 | 1234 | return NULL; |
1235 | 1235 | } |
1236 | 1236 | |
1237 | 1237 | $billing_details = $invoice->get_user_info(); |
1238 | - $address_row = wpinv_get_invoice_address_markup( $billing_details ); |
|
1238 | + $address_row = wpinv_get_invoice_address_markup($billing_details); |
|
1239 | 1239 | |
1240 | 1240 | ob_start(); |
1241 | 1241 | ?> |
1242 | 1242 | <table class="table table-bordered table-sm wpi-billing-details"> |
1243 | 1243 | <tbody> |
1244 | 1244 | <tr class="wpi-receipt-name"> |
1245 | - <th class="text-left"><?php _e( 'Name', 'invoicing' ); ?></th> |
|
1246 | - <td><?php echo esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) ;?></td> |
|
1245 | + <th class="text-left"><?php _e('Name', 'invoicing'); ?></th> |
|
1246 | + <td><?php echo esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])); ?></td> |
|
1247 | 1247 | </tr> |
1248 | 1248 | <tr class="wpi-receipt-email"> |
1249 | - <th class="text-left"><?php _e( 'Email', 'invoicing' ); ?></th> |
|
1250 | - <td><?php echo $billing_details['email'] ;?></td> |
|
1249 | + <th class="text-left"><?php _e('Email', 'invoicing'); ?></th> |
|
1250 | + <td><?php echo $billing_details['email']; ?></td> |
|
1251 | 1251 | </tr> |
1252 | 1252 | <tr class="wpi-receipt-address"> |
1253 | - <th class="text-left"><?php _e( 'Address', 'invoicing' ); ?></th> |
|
1254 | - <td><?php echo $address_row ;?></td> |
|
1253 | + <th class="text-left"><?php _e('Address', 'invoicing'); ?></th> |
|
1254 | + <td><?php echo $address_row; ?></td> |
|
1255 | 1255 | </tr> |
1256 | - <?php if ( $billing_details['phone'] ) { ?> |
|
1256 | + <?php if ($billing_details['phone']) { ?> |
|
1257 | 1257 | <tr class="wpi-receipt-phone"> |
1258 | - <th class="text-left"><?php _e( 'Phone', 'invoicing' ); ?></th> |
|
1259 | - <td><?php echo esc_html( $billing_details['phone'] ) ;?></td> |
|
1258 | + <th class="text-left"><?php _e('Phone', 'invoicing'); ?></th> |
|
1259 | + <td><?php echo esc_html($billing_details['phone']); ?></td> |
|
1260 | 1260 | </tr> |
1261 | 1261 | <?php } ?> |
1262 | 1262 | </tbody> |
@@ -1264,7 +1264,7 @@ discard block |
||
1264 | 1264 | <?php |
1265 | 1265 | $output = ob_get_clean(); |
1266 | 1266 | |
1267 | - $output = apply_filters( 'wpinv_receipt_billing_address', $output, $invoice_id ); |
|
1267 | + $output = apply_filters('wpinv_receipt_billing_address', $output, $invoice_id); |
|
1268 | 1268 | |
1269 | 1269 | echo $output; |
1270 | 1270 | } |
@@ -1272,88 +1272,88 @@ discard block |
||
1272 | 1272 | /** |
1273 | 1273 | * Filters the receipt page. |
1274 | 1274 | */ |
1275 | -function wpinv_filter_success_page_content( $content ) { |
|
1275 | +function wpinv_filter_success_page_content($content) { |
|
1276 | 1276 | |
1277 | 1277 | // Ensure this is our page. |
1278 | - if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) { |
|
1278 | + if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) { |
|
1279 | 1279 | |
1280 | - $gateway = sanitize_text_field( $_GET['payment-confirm'] ); |
|
1281 | - return apply_filters( "wpinv_payment_confirm_$gateway", $content ); |
|
1280 | + $gateway = sanitize_text_field($_GET['payment-confirm']); |
|
1281 | + return apply_filters("wpinv_payment_confirm_$gateway", $content); |
|
1282 | 1282 | |
1283 | 1283 | } |
1284 | 1284 | |
1285 | 1285 | return $content; |
1286 | 1286 | } |
1287 | -add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 ); |
|
1287 | +add_filter('the_content', 'wpinv_filter_success_page_content', 99999); |
|
1288 | 1288 | |
1289 | -function wpinv_invoice_link( $invoice_id ) { |
|
1290 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1289 | +function wpinv_invoice_link($invoice_id) { |
|
1290 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1291 | 1291 | |
1292 | - if ( empty( $invoice ) ) { |
|
1292 | + if (empty($invoice)) { |
|
1293 | 1293 | return NULL; |
1294 | 1294 | } |
1295 | 1295 | |
1296 | - $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>'; |
|
1296 | + $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>'; |
|
1297 | 1297 | |
1298 | - return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice ); |
|
1298 | + return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice); |
|
1299 | 1299 | } |
1300 | 1300 | |
1301 | -function wpinv_cart_total_label( $label, $invoice ) { |
|
1302 | - if ( empty( $invoice ) ) { |
|
1301 | +function wpinv_cart_total_label($label, $invoice) { |
|
1302 | + if (empty($invoice)) { |
|
1303 | 1303 | return $label; |
1304 | 1304 | } |
1305 | 1305 | |
1306 | 1306 | $prefix_label = ''; |
1307 | - if ( $invoice->is_parent() && $item_id = $invoice->get_recurring() ) { |
|
1308 | - $prefix_label = '<span class="label label-primary label-recurring">' . __( 'Recurring Payment', 'invoicing' ) . '</span> ' . wpinv_subscription_payment_desc( $invoice ); |
|
1309 | - } else if ( $invoice->is_renewal() ) { |
|
1310 | - $prefix_label = '<span class="label label-primary label-renewal">' . __( 'Renewal Payment', 'invoicing' ) . '</span> '; |
|
1307 | + if ($invoice->is_parent() && $item_id = $invoice->get_recurring()) { |
|
1308 | + $prefix_label = '<span class="label label-primary label-recurring">' . __('Recurring Payment', 'invoicing') . '</span> ' . wpinv_subscription_payment_desc($invoice); |
|
1309 | + } else if ($invoice->is_renewal()) { |
|
1310 | + $prefix_label = '<span class="label label-primary label-renewal">' . __('Renewal Payment', 'invoicing') . '</span> '; |
|
1311 | 1311 | } |
1312 | 1312 | |
1313 | - if ( $prefix_label != '' ) { |
|
1314 | - $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label; |
|
1313 | + if ($prefix_label != '') { |
|
1314 | + $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label; |
|
1315 | 1315 | } |
1316 | 1316 | |
1317 | 1317 | return $label; |
1318 | 1318 | } |
1319 | -add_filter( 'wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
1320 | -add_filter( 'wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
1321 | -add_filter( 'wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
1319 | +add_filter('wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
1320 | +add_filter('wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
1321 | +add_filter('wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
1322 | 1322 | |
1323 | -function wpinv_get_invoice_note_line_item( $note, $echo = true ) { |
|
1324 | - if ( empty( $note ) ) { |
|
1323 | +function wpinv_get_invoice_note_line_item($note, $echo = true) { |
|
1324 | + if (empty($note)) { |
|
1325 | 1325 | return NULL; |
1326 | 1326 | } |
1327 | 1327 | |
1328 | - if ( is_int( $note ) ) { |
|
1329 | - $note = get_comment( $note ); |
|
1328 | + if (is_int($note)) { |
|
1329 | + $note = get_comment($note); |
|
1330 | 1330 | } |
1331 | 1331 | |
1332 | - if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) { |
|
1332 | + if (!(is_object($note) && is_a($note, 'WP_Comment'))) { |
|
1333 | 1333 | return NULL; |
1334 | 1334 | } |
1335 | 1335 | |
1336 | - $note_classes = array( 'note' ); |
|
1337 | - $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : ''; |
|
1336 | + $note_classes = array('note'); |
|
1337 | + $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : ''; |
|
1338 | 1338 | $note_classes[] = $note->comment_author === 'System' ? 'system-note' : ''; |
1339 | - $note_classes = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note ); |
|
1340 | - $note_classes = !empty( $note_classes ) ? implode( ' ', $note_classes ) : ''; |
|
1339 | + $note_classes = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note); |
|
1340 | + $note_classes = !empty($note_classes) ? implode(' ', $note_classes) : ''; |
|
1341 | 1341 | |
1342 | 1342 | ob_start(); |
1343 | 1343 | ?> |
1344 | - <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?> mt-4 pl-3 pr-3"> |
|
1344 | + <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?> mt-4 pl-3 pr-3"> |
|
1345 | 1345 | <div class="note_content bg-light border position-relative p-4"> |
1346 | 1346 | |
1347 | - <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?> |
|
1347 | + <?php echo wpautop(wptexturize(wp_kses_post($note->comment_content))); ?> |
|
1348 | 1348 | |
1349 | - <?php if ( ! is_admin() ) : ?> |
|
1349 | + <?php if (!is_admin()) : ?> |
|
1350 | 1350 | <em class="meta position-absolute form-text"> |
1351 | 1351 | <?php |
1352 | 1352 | printf( |
1353 | - __( '%1$s - %2$s at %3$s', 'invoicing' ), |
|
1353 | + __('%1$s - %2$s at %3$s', 'invoicing'), |
|
1354 | 1354 | $note->comment_author, |
1355 | - getpaid_format_date_value( $note->comment_date ), |
|
1356 | - date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) |
|
1355 | + getpaid_format_date_value($note->comment_date), |
|
1356 | + date_i18n(get_option('time_format'), strtotime($note->comment_date)) |
|
1357 | 1357 | ); |
1358 | 1358 | ?> |
1359 | 1359 | </em> |
@@ -1361,21 +1361,21 @@ discard block |
||
1361 | 1361 | |
1362 | 1362 | </div> |
1363 | 1363 | |
1364 | - <?php if ( is_admin() ) : ?> |
|
1364 | + <?php if (is_admin()) : ?> |
|
1365 | 1365 | |
1366 | 1366 | <p class="meta px-4 py-2"> |
1367 | - <abbr class="exact-date" title="<?php echo esc_attr( $note->comment_date ); ?>"> |
|
1367 | + <abbr class="exact-date" title="<?php echo esc_attr($note->comment_date); ?>"> |
|
1368 | 1368 | <?php |
1369 | 1369 | printf( |
1370 | - __( '%1$s - %2$s at %3$s', 'invoicing' ), |
|
1370 | + __('%1$s - %2$s at %3$s', 'invoicing'), |
|
1371 | 1371 | $note->comment_author, |
1372 | - getpaid_format_date_value( $note->comment_date ), |
|
1373 | - date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) |
|
1372 | + getpaid_format_date_value($note->comment_date), |
|
1373 | + date_i18n(get_option('time_format'), strtotime($note->comment_date)) |
|
1374 | 1374 | ); |
1375 | 1375 | ?> |
1376 | 1376 | </abbr> |
1377 | - <?php if ( $note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing() ) { ?> |
|
1378 | - <a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a> |
|
1377 | + <?php if ($note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing()) { ?> |
|
1378 | + <a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a> |
|
1379 | 1379 | <?php } ?> |
1380 | 1380 | </p> |
1381 | 1381 | |
@@ -1384,9 +1384,9 @@ discard block |
||
1384 | 1384 | </li> |
1385 | 1385 | <?php |
1386 | 1386 | $note_content = ob_get_clean(); |
1387 | - $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo ); |
|
1387 | + $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo); |
|
1388 | 1388 | |
1389 | - if ( $echo ) { |
|
1389 | + if ($echo) { |
|
1390 | 1390 | echo $note_content; |
1391 | 1391 | } else { |
1392 | 1392 | return $note_content; |
@@ -1396,36 +1396,36 @@ discard block |
||
1396 | 1396 | function wpinv_invalid_invoice_content() { |
1397 | 1397 | global $post; |
1398 | 1398 | |
1399 | - $invoice = wpinv_get_invoice( $post->ID ); |
|
1399 | + $invoice = wpinv_get_invoice($post->ID); |
|
1400 | 1400 | |
1401 | - $error = __( 'This invoice is only viewable by clicking on the invoice link that was sent to you via email.', 'invoicing' ); |
|
1402 | - if ( !empty( $invoice->get_id() ) && $invoice->has_status( array_keys( wpinv_get_invoice_statuses() ) ) ) { |
|
1403 | - if ( is_user_logged_in() ) { |
|
1404 | - if ( wpinv_require_login_to_checkout() ) { |
|
1405 | - if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
1406 | - $error = __( 'You are not allowed to view this invoice.', 'invoicing' ); |
|
1401 | + $error = __('This invoice is only viewable by clicking on the invoice link that was sent to you via email.', 'invoicing'); |
|
1402 | + if (!empty($invoice->get_id()) && $invoice->has_status(array_keys(wpinv_get_invoice_statuses()))) { |
|
1403 | + if (is_user_logged_in()) { |
|
1404 | + if (wpinv_require_login_to_checkout()) { |
|
1405 | + if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) { |
|
1406 | + $error = __('You are not allowed to view this invoice.', 'invoicing'); |
|
1407 | 1407 | } |
1408 | 1408 | } |
1409 | 1409 | } else { |
1410 | - if ( wpinv_require_login_to_checkout() ) { |
|
1411 | - if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
1412 | - $error = __( 'You must be logged in to view this invoice.', 'invoicing' ); |
|
1410 | + if (wpinv_require_login_to_checkout()) { |
|
1411 | + if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) { |
|
1412 | + $error = __('You must be logged in to view this invoice.', 'invoicing'); |
|
1413 | 1413 | } |
1414 | 1414 | } |
1415 | 1415 | } |
1416 | 1416 | } else { |
1417 | - $error = __( 'This invoice is deleted or does not exist.', 'invoicing' ); |
|
1417 | + $error = __('This invoice is deleted or does not exist.', 'invoicing'); |
|
1418 | 1418 | } |
1419 | 1419 | ?> |
1420 | 1420 | <div class="row wpinv-row-invalid"> |
1421 | 1421 | <div class="col-md-6 col-md-offset-3 wpinv-message error"> |
1422 | - <h3><?php _e( 'Access Denied', 'invoicing' ); ?></h3> |
|
1422 | + <h3><?php _e('Access Denied', 'invoicing'); ?></h3> |
|
1423 | 1423 | <p class="wpinv-msg-text"><?php echo $error; ?></p> |
1424 | 1424 | </div> |
1425 | 1425 | </div> |
1426 | 1426 | <?php |
1427 | 1427 | } |
1428 | -add_action( 'wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content' ); |
|
1428 | +add_action('wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content'); |
|
1429 | 1429 | |
1430 | 1430 | /** |
1431 | 1431 | * Function to get privacy policy text. |
@@ -1434,21 +1434,21 @@ discard block |
||
1434 | 1434 | * @return string |
1435 | 1435 | */ |
1436 | 1436 | function wpinv_get_policy_text() { |
1437 | - $privacy_page_id = get_option( 'wp_page_for_privacy_policy', 0 ); |
|
1437 | + $privacy_page_id = get_option('wp_page_for_privacy_policy', 0); |
|
1438 | 1438 | |
1439 | - $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf( __( 'Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing' ), '[wpinv_privacy_policy]' )); |
|
1439 | + $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf(__('Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing'), '[wpinv_privacy_policy]')); |
|
1440 | 1440 | |
1441 | - if(!$privacy_page_id){ |
|
1442 | - $privacy_page_id = wpinv_get_option( 'privacy_page', 0 ); |
|
1441 | + if (!$privacy_page_id) { |
|
1442 | + $privacy_page_id = wpinv_get_option('privacy_page', 0); |
|
1443 | 1443 | } |
1444 | 1444 | |
1445 | - $privacy_link = $privacy_page_id ? '<a href="' . esc_url( get_permalink( $privacy_page_id ) ) . '" class="wpinv-privacy-policy-link" target="_blank">' . __( 'privacy policy', 'invoicing' ) . '</a>' : __( 'privacy policy', 'invoicing' ); |
|
1445 | + $privacy_link = $privacy_page_id ? '<a href="' . esc_url(get_permalink($privacy_page_id)) . '" class="wpinv-privacy-policy-link" target="_blank">' . __('privacy policy', 'invoicing') . '</a>' : __('privacy policy', 'invoicing'); |
|
1446 | 1446 | |
1447 | 1447 | $find_replace = array( |
1448 | 1448 | '[wpinv_privacy_policy]' => $privacy_link, |
1449 | 1449 | ); |
1450 | 1450 | |
1451 | - $privacy_text = str_replace( array_keys( $find_replace ), array_values( $find_replace ), $text ); |
|
1451 | + $privacy_text = str_replace(array_keys($find_replace), array_values($find_replace), $text); |
|
1452 | 1452 | |
1453 | 1453 | return wp_kses_post(wpautop($privacy_text)); |
1454 | 1454 | } |
@@ -1456,21 +1456,21 @@ discard block |
||
1456 | 1456 | function wpinv_oxygen_fix_conflict() { |
1457 | 1457 | global $ct_ignore_post_types; |
1458 | 1458 | |
1459 | - if ( ! is_array( $ct_ignore_post_types ) ) { |
|
1459 | + if (!is_array($ct_ignore_post_types)) { |
|
1460 | 1460 | $ct_ignore_post_types = array(); |
1461 | 1461 | } |
1462 | 1462 | |
1463 | - $post_types = array( 'wpi_discount', 'wpi_invoice', 'wpi_item' ); |
|
1463 | + $post_types = array('wpi_discount', 'wpi_invoice', 'wpi_item'); |
|
1464 | 1464 | |
1465 | - foreach ( $post_types as $post_type ) { |
|
1465 | + foreach ($post_types as $post_type) { |
|
1466 | 1466 | $ct_ignore_post_types[] = $post_type; |
1467 | 1467 | |
1468 | 1468 | // Ignore post type |
1469 | - add_filter( 'pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999 ); |
|
1469 | + add_filter('pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999); |
|
1470 | 1470 | } |
1471 | 1471 | |
1472 | - remove_filter( 'template_include', 'wpinv_template', 10, 1 ); |
|
1473 | - add_filter( 'template_include', 'wpinv_template', 999, 1 ); |
|
1472 | + remove_filter('template_include', 'wpinv_template', 10, 1); |
|
1473 | + add_filter('template_include', 'wpinv_template', 999, 1); |
|
1474 | 1474 | } |
1475 | 1475 | |
1476 | 1476 | /** |
@@ -1478,10 +1478,10 @@ discard block |
||
1478 | 1478 | * |
1479 | 1479 | * @param GetPaid_Payment_Form $form |
1480 | 1480 | */ |
1481 | -function getpaid_display_payment_form( $form ) { |
|
1481 | +function getpaid_display_payment_form($form) { |
|
1482 | 1482 | |
1483 | - if ( is_numeric( $form ) ) { |
|
1484 | - $form = new GetPaid_Payment_Form( $form ); |
|
1483 | + if (is_numeric($form)) { |
|
1484 | + $form = new GetPaid_Payment_Form($form); |
|
1485 | 1485 | } |
1486 | 1486 | |
1487 | 1487 | $form->display(); |
@@ -1491,16 +1491,16 @@ discard block |
||
1491 | 1491 | /** |
1492 | 1492 | * Helper function to display a item payment form on the frontend. |
1493 | 1493 | */ |
1494 | -function getpaid_display_item_payment_form( $items ) { |
|
1494 | +function getpaid_display_item_payment_form($items) { |
|
1495 | 1495 | |
1496 | - $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
1497 | - $form->set_items( $items ); |
|
1496 | + $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
1497 | + $form->set_items($items); |
|
1498 | 1498 | |
1499 | - if ( 0 == count( $form->get_items() ) ) { |
|
1499 | + if (0 == count($form->get_items())) { |
|
1500 | 1500 | echo aui()->alert( |
1501 | 1501 | array( |
1502 | 1502 | 'type' => 'warning', |
1503 | - 'content' => __( 'No published items found', 'invoicing' ), |
|
1503 | + 'content' => __('No published items found', 'invoicing'), |
|
1504 | 1504 | ) |
1505 | 1505 | ); |
1506 | 1506 | return; |
@@ -1512,32 +1512,32 @@ discard block |
||
1512 | 1512 | /** |
1513 | 1513 | * Helper function to display an invoice payment form on the frontend. |
1514 | 1514 | */ |
1515 | -function getpaid_display_invoice_payment_form( $invoice_id ) { |
|
1515 | +function getpaid_display_invoice_payment_form($invoice_id) { |
|
1516 | 1516 | |
1517 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1517 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1518 | 1518 | |
1519 | - if ( empty( $invoice ) ) { |
|
1519 | + if (empty($invoice)) { |
|
1520 | 1520 | echo aui()->alert( |
1521 | 1521 | array( |
1522 | 1522 | 'type' => 'warning', |
1523 | - 'content' => __( 'Invoice not found', 'invoicing' ), |
|
1523 | + 'content' => __('Invoice not found', 'invoicing'), |
|
1524 | 1524 | ) |
1525 | 1525 | ); |
1526 | 1526 | return; |
1527 | 1527 | } |
1528 | 1528 | |
1529 | - if ( $invoice->is_paid() ) { |
|
1529 | + if ($invoice->is_paid()) { |
|
1530 | 1530 | echo aui()->alert( |
1531 | 1531 | array( |
1532 | 1532 | 'type' => 'warning', |
1533 | - 'content' => __( 'Invoice has already been paid', 'invoicing' ), |
|
1533 | + 'content' => __('Invoice has already been paid', 'invoicing'), |
|
1534 | 1534 | ) |
1535 | 1535 | ); |
1536 | 1536 | return; |
1537 | 1537 | } |
1538 | 1538 | |
1539 | - $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
1540 | - $form->set_items( $invoice->get_items() ); |
|
1539 | + $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
1540 | + $form->set_items($invoice->get_items()); |
|
1541 | 1541 | |
1542 | 1542 | $form->display(); |
1543 | 1543 | } |
@@ -1545,23 +1545,23 @@ discard block |
||
1545 | 1545 | /** |
1546 | 1546 | * Helper function to convert item string to array. |
1547 | 1547 | */ |
1548 | -function getpaid_convert_items_to_array( $items ) { |
|
1549 | - $items = array_filter( array_map( 'trim', explode( ',', $items ) ) ); |
|
1548 | +function getpaid_convert_items_to_array($items) { |
|
1549 | + $items = array_filter(array_map('trim', explode(',', $items))); |
|
1550 | 1550 | $prepared = array(); |
1551 | 1551 | |
1552 | - foreach ( $items as $item ) { |
|
1553 | - $data = array_map( 'trim', explode( '|', $item ) ); |
|
1552 | + foreach ($items as $item) { |
|
1553 | + $data = array_map('trim', explode('|', $item)); |
|
1554 | 1554 | |
1555 | - if ( empty( $data[0] ) || ! is_numeric( $data[0] ) ) { |
|
1555 | + if (empty($data[0]) || !is_numeric($data[0])) { |
|
1556 | 1556 | continue; |
1557 | 1557 | } |
1558 | 1558 | |
1559 | 1559 | $quantity = 1; |
1560 | - if ( isset( $data[1] ) && is_numeric( $data[1] ) ) { |
|
1560 | + if (isset($data[1]) && is_numeric($data[1])) { |
|
1561 | 1561 | $quantity = (int) $data[1]; |
1562 | 1562 | } |
1563 | 1563 | |
1564 | - $prepared[ $data[0] ] = $quantity; |
|
1564 | + $prepared[$data[0]] = $quantity; |
|
1565 | 1565 | |
1566 | 1566 | } |
1567 | 1567 | |
@@ -1571,13 +1571,13 @@ discard block |
||
1571 | 1571 | /** |
1572 | 1572 | * Helper function to convert item array to string. |
1573 | 1573 | */ |
1574 | -function getpaid_convert_items_to_string( $items ) { |
|
1574 | +function getpaid_convert_items_to_string($items) { |
|
1575 | 1575 | $prepared = array(); |
1576 | 1576 | |
1577 | - foreach ( $items as $item => $quantity ) { |
|
1577 | + foreach ($items as $item => $quantity) { |
|
1578 | 1578 | $prepared[] = "$item|$quantity"; |
1579 | 1579 | } |
1580 | - return implode( ',', $prepared ); |
|
1580 | + return implode(',', $prepared); |
|
1581 | 1581 | } |
1582 | 1582 | |
1583 | 1583 | /** |
@@ -1585,22 +1585,22 @@ discard block |
||
1585 | 1585 | * |
1586 | 1586 | * Provide a label and one of $form, $items or $invoice. |
1587 | 1587 | */ |
1588 | -function getpaid_get_payment_button( $label, $form = null, $items = null, $invoice = null ) { |
|
1589 | - $label = sanitize_text_field( $label ); |
|
1588 | +function getpaid_get_payment_button($label, $form = null, $items = null, $invoice = null) { |
|
1589 | + $label = sanitize_text_field($label); |
|
1590 | 1590 | $nonce = wp_create_nonce('getpaid_ajax_form'); |
1591 | 1591 | |
1592 | - if ( ! empty( $form ) ) { |
|
1593 | - $form = esc_attr( $form ); |
|
1592 | + if (!empty($form)) { |
|
1593 | + $form = esc_attr($form); |
|
1594 | 1594 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-form='$form'>$label</button>"; |
1595 | 1595 | } |
1596 | 1596 | |
1597 | - if ( ! empty( $items ) ) { |
|
1598 | - $items = esc_attr( $items ); |
|
1597 | + if (!empty($items)) { |
|
1598 | + $items = esc_attr($items); |
|
1599 | 1599 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-item='$items'>$label</button>"; |
1600 | 1600 | } |
1601 | 1601 | |
1602 | - if ( ! empty( $invoice ) ) { |
|
1603 | - $invoice = esc_attr( $invoice ); |
|
1602 | + if (!empty($invoice)) { |
|
1603 | + $invoice = esc_attr($invoice); |
|
1604 | 1604 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-invoice='$invoice'>$label</button>"; |
1605 | 1605 | } |
1606 | 1606 | |
@@ -1611,17 +1611,17 @@ discard block |
||
1611 | 1611 | * |
1612 | 1612 | * @param WPInv_Invoice $invoice |
1613 | 1613 | */ |
1614 | -function getpaid_the_invoice_description( $invoice ) { |
|
1614 | +function getpaid_the_invoice_description($invoice) { |
|
1615 | 1615 | $description = $invoice->get_description(); |
1616 | 1616 | |
1617 | - if ( empty( $description ) ) { |
|
1617 | + if (empty($description)) { |
|
1618 | 1618 | return; |
1619 | 1619 | } |
1620 | 1620 | |
1621 | - $description = wp_kses_post( $description ); |
|
1621 | + $description = wp_kses_post($description); |
|
1622 | 1622 | echo "<small class='getpaid-invoice-description text-dark p-2 form-text'><em>$description</em></small>"; |
1623 | 1623 | } |
1624 | -add_action( 'getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100 ); |
|
1624 | +add_action('getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100); |
|
1625 | 1625 | |
1626 | 1626 | /** |
1627 | 1627 | * Render element on a form. |
@@ -1629,60 +1629,60 @@ discard block |
||
1629 | 1629 | * @param array $element |
1630 | 1630 | * @param GetPaid_Payment_Form $form |
1631 | 1631 | */ |
1632 | -function getpaid_payment_form_element( $element, $form ) { |
|
1632 | +function getpaid_payment_form_element($element, $form) { |
|
1633 | 1633 | |
1634 | 1634 | // Set up the args. |
1635 | - $element_type = trim( $element['type'] ); |
|
1635 | + $element_type = trim($element['type']); |
|
1636 | 1636 | $element['form'] = $form; |
1637 | - extract( $element ); |
|
1637 | + extract($element); |
|
1638 | 1638 | |
1639 | 1639 | // Try to locate the appropriate template. |
1640 | - $located = wpinv_locate_template( "payment-forms/elements/$element_type.php" ); |
|
1640 | + $located = wpinv_locate_template("payment-forms/elements/$element_type.php"); |
|
1641 | 1641 | |
1642 | 1642 | // Abort if this is not our element. |
1643 | - if ( empty( $located ) || ! file_exists( $located ) ) { |
|
1643 | + if (empty($located) || !file_exists($located)) { |
|
1644 | 1644 | return; |
1645 | 1645 | } |
1646 | 1646 | |
1647 | 1647 | // Generate the class and id of the element. |
1648 | - $wrapper_class = 'getpaid-payment-form-element-' . trim( esc_attr( $element_type ) ); |
|
1649 | - $id = isset( $id ) ? $id : uniqid( 'gp' ); |
|
1648 | + $wrapper_class = 'getpaid-payment-form-element-' . trim(esc_attr($element_type)); |
|
1649 | + $id = isset($id) ? $id : uniqid('gp'); |
|
1650 | 1650 | |
1651 | 1651 | // Echo the opening wrapper. |
1652 | 1652 | echo "<div class='getpaid-payment-form-element $wrapper_class'>"; |
1653 | 1653 | |
1654 | 1654 | // Fires before displaying a given element type's content. |
1655 | - do_action( "getpaid_before_payment_form_{$element_type}_element", $element, $form ); |
|
1655 | + do_action("getpaid_before_payment_form_{$element_type}_element", $element, $form); |
|
1656 | 1656 | |
1657 | 1657 | // Include the template for the element. |
1658 | 1658 | include $located; |
1659 | 1659 | |
1660 | 1660 | // Fires after displaying a given element type's content. |
1661 | - do_action( "getpaid_payment_form_{$element_type}_element", $element, $form ); |
|
1661 | + do_action("getpaid_payment_form_{$element_type}_element", $element, $form); |
|
1662 | 1662 | |
1663 | 1663 | // Echo the closing wrapper. |
1664 | 1664 | echo '</div>'; |
1665 | 1665 | } |
1666 | -add_action( 'getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2 ); |
|
1666 | +add_action('getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2); |
|
1667 | 1667 | |
1668 | 1668 | /** |
1669 | 1669 | * Render an element's edit page. |
1670 | 1670 | * |
1671 | 1671 | * @param WP_Post $post |
1672 | 1672 | */ |
1673 | -function getpaid_payment_form_edit_element_template( $post ) { |
|
1673 | +function getpaid_payment_form_edit_element_template($post) { |
|
1674 | 1674 | |
1675 | 1675 | // Retrieve all elements. |
1676 | - $all_elements = wp_list_pluck( wpinv_get_data( 'payment-form-elements' ), 'type' ); |
|
1676 | + $all_elements = wp_list_pluck(wpinv_get_data('payment-form-elements'), 'type'); |
|
1677 | 1677 | |
1678 | - foreach ( $all_elements as $element ) { |
|
1678 | + foreach ($all_elements as $element) { |
|
1679 | 1679 | |
1680 | 1680 | // Try to locate the appropriate template. |
1681 | - $element = sanitize_key( $element ); |
|
1682 | - $located = wpinv_locate_template( "payment-forms-admin/edit/$element.php" ); |
|
1681 | + $element = sanitize_key($element); |
|
1682 | + $located = wpinv_locate_template("payment-forms-admin/edit/$element.php"); |
|
1683 | 1683 | |
1684 | 1684 | // Continue if this is not our element. |
1685 | - if ( empty( $located ) || ! file_exists( $located ) ) { |
|
1685 | + if (empty($located) || !file_exists($located)) { |
|
1686 | 1686 | continue; |
1687 | 1687 | } |
1688 | 1688 | |
@@ -1693,7 +1693,7 @@ discard block |
||
1693 | 1693 | } |
1694 | 1694 | |
1695 | 1695 | } |
1696 | -add_action( 'getpaid_payment_form_edit_element_template', 'getpaid_payment_form_edit_element_template' ); |
|
1696 | +add_action('getpaid_payment_form_edit_element_template', 'getpaid_payment_form_edit_element_template'); |
|
1697 | 1697 | |
1698 | 1698 | /** |
1699 | 1699 | * Render an element's preview. |
@@ -1702,16 +1702,16 @@ discard block |
||
1702 | 1702 | function getpaid_payment_form_render_element_preview_template() { |
1703 | 1703 | |
1704 | 1704 | // Retrieve all elements. |
1705 | - $all_elements = wp_list_pluck( wpinv_get_data( 'payment-form-elements' ), 'type' ); |
|
1705 | + $all_elements = wp_list_pluck(wpinv_get_data('payment-form-elements'), 'type'); |
|
1706 | 1706 | |
1707 | - foreach ( $all_elements as $element ) { |
|
1707 | + foreach ($all_elements as $element) { |
|
1708 | 1708 | |
1709 | 1709 | // Try to locate the appropriate template. |
1710 | - $element = sanitize_key( $element ); |
|
1711 | - $located = wpinv_locate_template( "payment-forms-admin/previews/$element.php" ); |
|
1710 | + $element = sanitize_key($element); |
|
1711 | + $located = wpinv_locate_template("payment-forms-admin/previews/$element.php"); |
|
1712 | 1712 | |
1713 | 1713 | // Continue if this is not our element. |
1714 | - if ( empty( $located ) || ! file_exists( $located ) ) { |
|
1714 | + if (empty($located) || !file_exists($located)) { |
|
1715 | 1715 | continue; |
1716 | 1716 | } |
1717 | 1717 | |
@@ -1722,7 +1722,7 @@ discard block |
||
1722 | 1722 | } |
1723 | 1723 | |
1724 | 1724 | } |
1725 | -add_action( 'wpinv_payment_form_render_element_template', 'getpaid_payment_form_render_element_preview_template' ); |
|
1725 | +add_action('wpinv_payment_form_render_element_template', 'getpaid_payment_form_render_element_preview_template'); |
|
1726 | 1726 | |
1727 | 1727 | /** |
1728 | 1728 | * Shows a list of gateways that support recurring payments. |
@@ -1730,17 +1730,17 @@ discard block |
||
1730 | 1730 | function wpinv_get_recurring_gateways_text() { |
1731 | 1731 | $gateways = array(); |
1732 | 1732 | |
1733 | - foreach ( wpinv_get_payment_gateways() as $key => $gateway ) { |
|
1734 | - if ( wpinv_gateway_support_subscription( $key ) ) { |
|
1735 | - $gateways[] = sanitize_text_field( $gateway['admin_label'] ); |
|
1733 | + foreach (wpinv_get_payment_gateways() as $key => $gateway) { |
|
1734 | + if (wpinv_gateway_support_subscription($key)) { |
|
1735 | + $gateways[] = sanitize_text_field($gateway['admin_label']); |
|
1736 | 1736 | } |
1737 | 1737 | } |
1738 | 1738 | |
1739 | - if ( empty( $gateways ) ) { |
|
1740 | - return "<span class='form-text text-danger'>" . __( 'No active gateways support subscription payments.', 'invoicing' ) ."</span>"; |
|
1739 | + if (empty($gateways)) { |
|
1740 | + return "<span class='form-text text-danger'>" . __('No active gateways support subscription payments.', 'invoicing') . "</span>"; |
|
1741 | 1741 | } |
1742 | 1742 | |
1743 | - return "<span class='form-text text-muted'>" . wp_sprintf( __( 'Subscription payments only supported by: %s', 'invoicing' ), implode( ', ', $gateways ) ) ."</span>"; |
|
1743 | + return "<span class='form-text text-muted'>" . wp_sprintf(__('Subscription payments only supported by: %s', 'invoicing'), implode(', ', $gateways)) . "</span>"; |
|
1744 | 1744 | |
1745 | 1745 | } |
1746 | 1746 | |
@@ -1750,7 +1750,7 @@ discard block |
||
1750 | 1750 | * @return GetPaid_Template |
1751 | 1751 | */ |
1752 | 1752 | function getpaid_template() { |
1753 | - return getpaid()->get( 'template' ); |
|
1753 | + return getpaid()->get('template'); |
|
1754 | 1754 | } |
1755 | 1755 | |
1756 | 1756 | /** |
@@ -1759,23 +1759,23 @@ discard block |
||
1759 | 1759 | * @param array args |
1760 | 1760 | * @return string |
1761 | 1761 | */ |
1762 | -function getpaid_paginate_links( $args ) { |
|
1762 | +function getpaid_paginate_links($args) { |
|
1763 | 1763 | |
1764 | 1764 | $args['type'] = 'array'; |
1765 | 1765 | $args['mid_size'] = 1; |
1766 | - $pages = paginate_links( $args ); |
|
1766 | + $pages = paginate_links($args); |
|
1767 | 1767 | |
1768 | - if ( ! is_array( $pages ) ) { |
|
1768 | + if (!is_array($pages)) { |
|
1769 | 1769 | return ''; |
1770 | 1770 | } |
1771 | 1771 | |
1772 | 1772 | $_pages = array(); |
1773 | - foreach ( $pages as $page ) { |
|
1774 | - $_pages[] = str_replace( 'page-numbers', 'page-link text-decoration-none', $page ); |
|
1773 | + foreach ($pages as $page) { |
|
1774 | + $_pages[] = str_replace('page-numbers', 'page-link text-decoration-none', $page); |
|
1775 | 1775 | } |
1776 | 1776 | |
1777 | 1777 | $links = "<nav>\n\t<ul class='pagination justify-content-end m-0'>\n\t\t<li class='page-item'>"; |
1778 | - $links .= join( "</li>\n\t\t<li class='page-item'>", $_pages ); |
|
1778 | + $links .= join("</li>\n\t\t<li class='page-item'>", $_pages); |
|
1779 | 1779 | $links .= "</li>\n\t</ul>\n</nav>\n"; |
1780 | 1780 | |
1781 | 1781 | return $links; |
@@ -14,70 +14,70 @@ discard block |
||
14 | 14 | class WPInv_Ajax { |
15 | 15 | |
16 | 16 | /** |
17 | - * Hook in ajax handlers. |
|
18 | - */ |
|
19 | - public static function init() { |
|
20 | - add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 ); |
|
21 | - add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 ); |
|
22 | - self::add_ajax_events(); |
|
17 | + * Hook in ajax handlers. |
|
18 | + */ |
|
19 | + public static function init() { |
|
20 | + add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 ); |
|
21 | + add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 ); |
|
22 | + self::add_ajax_events(); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
26 | - * Set GetPaid AJAX constant and headers. |
|
27 | - */ |
|
28 | - public static function define_ajax() { |
|
29 | - |
|
30 | - if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
31 | - getpaid_maybe_define_constant( 'DOING_AJAX', true ); |
|
32 | - getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true ); |
|
33 | - if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { |
|
34 | - /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 ); |
|
35 | - } |
|
36 | - $GLOBALS['wpdb']->hide_errors(); |
|
37 | - } |
|
26 | + * Set GetPaid AJAX constant and headers. |
|
27 | + */ |
|
28 | + public static function define_ajax() { |
|
29 | + |
|
30 | + if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
31 | + getpaid_maybe_define_constant( 'DOING_AJAX', true ); |
|
32 | + getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true ); |
|
33 | + if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { |
|
34 | + /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 ); |
|
35 | + } |
|
36 | + $GLOBALS['wpdb']->hide_errors(); |
|
37 | + } |
|
38 | 38 | |
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
42 | - * Send headers for GetPaid Ajax Requests. |
|
43 | - * |
|
44 | - * @since 1.0.18 |
|
45 | - */ |
|
46 | - private static function wpinv_ajax_headers() { |
|
47 | - if ( ! headers_sent() ) { |
|
48 | - send_origin_headers(); |
|
49 | - send_nosniff_header(); |
|
50 | - nocache_headers(); |
|
51 | - header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
52 | - header( 'X-Robots-Tag: noindex' ); |
|
53 | - status_header( 200 ); |
|
54 | - } |
|
42 | + * Send headers for GetPaid Ajax Requests. |
|
43 | + * |
|
44 | + * @since 1.0.18 |
|
45 | + */ |
|
46 | + private static function wpinv_ajax_headers() { |
|
47 | + if ( ! headers_sent() ) { |
|
48 | + send_origin_headers(); |
|
49 | + send_nosniff_header(); |
|
50 | + nocache_headers(); |
|
51 | + header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
52 | + header( 'X-Robots-Tag: noindex' ); |
|
53 | + status_header( 200 ); |
|
54 | + } |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
58 | - * Check for GetPaid Ajax request and fire action. |
|
59 | - */ |
|
60 | - public static function do_wpinv_ajax() { |
|
61 | - global $wp_query; |
|
58 | + * Check for GetPaid Ajax request and fire action. |
|
59 | + */ |
|
60 | + public static function do_wpinv_ajax() { |
|
61 | + global $wp_query; |
|
62 | 62 | |
63 | - if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
64 | - $wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) ); |
|
65 | - } |
|
63 | + if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
64 | + $wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) ); |
|
65 | + } |
|
66 | 66 | |
67 | - $action = $wp_query->get( 'wpinv-ajax' ); |
|
67 | + $action = $wp_query->get( 'wpinv-ajax' ); |
|
68 | 68 | |
69 | - if ( $action ) { |
|
70 | - self::wpinv_ajax_headers(); |
|
71 | - $action = sanitize_text_field( $action ); |
|
72 | - do_action( 'wpinv_ajax_' . $action ); |
|
73 | - wp_die(); |
|
74 | - } |
|
69 | + if ( $action ) { |
|
70 | + self::wpinv_ajax_headers(); |
|
71 | + $action = sanitize_text_field( $action ); |
|
72 | + do_action( 'wpinv_ajax_' . $action ); |
|
73 | + wp_die(); |
|
74 | + } |
|
75 | 75 | |
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | - * Hook in ajax methods. |
|
80 | - */ |
|
79 | + * Hook in ajax methods. |
|
80 | + */ |
|
81 | 81 | public static function add_ajax_events() { |
82 | 82 | |
83 | 83 | // array( 'event' => is_frontend ) |
@@ -260,24 +260,24 @@ discard block |
||
260 | 260 | } |
261 | 261 | |
262 | 262 | // Is the request set up correctly? |
263 | - if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) { |
|
264 | - echo aui()->alert( |
|
265 | - array( |
|
266 | - 'type' => 'warning', |
|
267 | - 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
268 | - ) |
|
263 | + if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) { |
|
264 | + echo aui()->alert( |
|
265 | + array( |
|
266 | + 'type' => 'warning', |
|
267 | + 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
268 | + ) |
|
269 | 269 | ); |
270 | 270 | exit; |
271 | 271 | } |
272 | 272 | |
273 | 273 | // Payment form or button? |
274 | - if ( ! empty( $_GET['form'] ) ) { |
|
274 | + if ( ! empty( $_GET['form'] ) ) { |
|
275 | 275 | getpaid_display_payment_form( $_GET['form'] ); |
276 | - } else if( ! empty( $_GET['invoice'] ) ) { |
|
277 | - getpaid_display_invoice_payment_form( $_GET['invoice'] ); |
|
276 | + } else if( ! empty( $_GET['invoice'] ) ) { |
|
277 | + getpaid_display_invoice_payment_form( $_GET['invoice'] ); |
|
278 | 278 | } else { |
279 | - $items = getpaid_convert_items_to_array( $_GET['item'] ); |
|
280 | - getpaid_display_item_payment_form( $items ); |
|
279 | + $items = getpaid_convert_items_to_array( $_GET['item'] ); |
|
280 | + getpaid_display_item_payment_form( $items ); |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | exit; |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @package Invoicing |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * WPInv_Ajax class. |
@@ -17,8 +17,8 @@ discard block |
||
17 | 17 | * Hook in ajax handlers. |
18 | 18 | */ |
19 | 19 | public static function init() { |
20 | - add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 ); |
|
21 | - add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 ); |
|
20 | + add_action('init', array(__CLASS__, 'define_ajax'), 0); |
|
21 | + add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0); |
|
22 | 22 | self::add_ajax_events(); |
23 | 23 | } |
24 | 24 | |
@@ -27,11 +27,11 @@ discard block |
||
27 | 27 | */ |
28 | 28 | public static function define_ajax() { |
29 | 29 | |
30 | - if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
31 | - getpaid_maybe_define_constant( 'DOING_AJAX', true ); |
|
32 | - getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true ); |
|
33 | - if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { |
|
34 | - /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 ); |
|
30 | + if (!empty($_GET['wpinv-ajax'])) { |
|
31 | + getpaid_maybe_define_constant('DOING_AJAX', true); |
|
32 | + getpaid_maybe_define_constant('WPInv_DOING_AJAX', true); |
|
33 | + if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) { |
|
34 | + /** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0); |
|
35 | 35 | } |
36 | 36 | $GLOBALS['wpdb']->hide_errors(); |
37 | 37 | } |
@@ -44,13 +44,13 @@ discard block |
||
44 | 44 | * @since 1.0.18 |
45 | 45 | */ |
46 | 46 | private static function wpinv_ajax_headers() { |
47 | - if ( ! headers_sent() ) { |
|
47 | + if (!headers_sent()) { |
|
48 | 48 | send_origin_headers(); |
49 | 49 | send_nosniff_header(); |
50 | 50 | nocache_headers(); |
51 | - header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
52 | - header( 'X-Robots-Tag: noindex' ); |
|
53 | - status_header( 200 ); |
|
51 | + header('Content-Type: text/html; charset=' . get_option('blog_charset')); |
|
52 | + header('X-Robots-Tag: noindex'); |
|
53 | + status_header(200); |
|
54 | 54 | } |
55 | 55 | } |
56 | 56 | |
@@ -60,16 +60,16 @@ discard block |
||
60 | 60 | public static function do_wpinv_ajax() { |
61 | 61 | global $wp_query; |
62 | 62 | |
63 | - if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
64 | - $wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) ); |
|
63 | + if (!empty($_GET['wpinv-ajax'])) { |
|
64 | + $wp_query->set('wpinv-ajax', sanitize_text_field(wp_unslash($_GET['wpinv-ajax']))); |
|
65 | 65 | } |
66 | 66 | |
67 | - $action = $wp_query->get( 'wpinv-ajax' ); |
|
67 | + $action = $wp_query->get('wpinv-ajax'); |
|
68 | 68 | |
69 | - if ( $action ) { |
|
69 | + if ($action) { |
|
70 | 70 | self::wpinv_ajax_headers(); |
71 | - $action = sanitize_text_field( $action ); |
|
72 | - do_action( 'wpinv_ajax_' . $action ); |
|
71 | + $action = sanitize_text_field($action); |
|
72 | + do_action('wpinv_ajax_' . $action); |
|
73 | 73 | wp_die(); |
74 | 74 | } |
75 | 75 | |
@@ -103,36 +103,36 @@ discard block |
||
103 | 103 | 'ip_geolocation' => true, |
104 | 104 | ); |
105 | 105 | |
106 | - foreach ( $ajax_events as $ajax_event => $nopriv ) { |
|
107 | - add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
108 | - add_action( 'wp_ajax_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
106 | + foreach ($ajax_events as $ajax_event => $nopriv) { |
|
107 | + add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
108 | + add_action('wp_ajax_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
109 | 109 | |
110 | - if ( $nopriv ) { |
|
111 | - add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
112 | - add_action( 'wp_ajax_nopriv_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
113 | - add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
110 | + if ($nopriv) { |
|
111 | + add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
112 | + add_action('wp_ajax_nopriv_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
113 | + add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
114 | 114 | } |
115 | 115 | } |
116 | 116 | } |
117 | 117 | |
118 | 118 | public static function add_note() { |
119 | - check_ajax_referer( 'add-invoice-note', '_nonce' ); |
|
119 | + check_ajax_referer('add-invoice-note', '_nonce'); |
|
120 | 120 | |
121 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
121 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
122 | 122 | die(-1); |
123 | 123 | } |
124 | 124 | |
125 | - $post_id = absint( $_POST['post_id'] ); |
|
126 | - $note = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) ); |
|
127 | - $note_type = sanitize_text_field( $_POST['note_type'] ); |
|
125 | + $post_id = absint($_POST['post_id']); |
|
126 | + $note = wp_kses_post(trim(stripslashes($_POST['note']))); |
|
127 | + $note_type = sanitize_text_field($_POST['note_type']); |
|
128 | 128 | |
129 | 129 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
130 | 130 | |
131 | - if ( $post_id > 0 ) { |
|
132 | - $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note ); |
|
131 | + if ($post_id > 0) { |
|
132 | + $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note); |
|
133 | 133 | |
134 | - if ( $note_id > 0 && !is_wp_error( $note_id ) ) { |
|
135 | - wpinv_get_invoice_note_line_item( $note_id ); |
|
134 | + if ($note_id > 0 && !is_wp_error($note_id)) { |
|
135 | + wpinv_get_invoice_note_line_item($note_id); |
|
136 | 136 | } |
137 | 137 | } |
138 | 138 | |
@@ -140,16 +140,16 @@ discard block |
||
140 | 140 | } |
141 | 141 | |
142 | 142 | public static function delete_note() { |
143 | - check_ajax_referer( 'delete-invoice-note', '_nonce' ); |
|
143 | + check_ajax_referer('delete-invoice-note', '_nonce'); |
|
144 | 144 | |
145 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
145 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
146 | 146 | die(-1); |
147 | 147 | } |
148 | 148 | |
149 | - $note_id = (int)$_POST['note_id']; |
|
149 | + $note_id = (int) $_POST['note_id']; |
|
150 | 150 | |
151 | - if ( $note_id > 0 ) { |
|
152 | - wp_delete_comment( $note_id, true ); |
|
151 | + if ($note_id > 0) { |
|
152 | + wp_delete_comment($note_id, true); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | die(); |
@@ -167,34 +167,34 @@ discard block |
||
167 | 167 | public static function get_billing_details() { |
168 | 168 | |
169 | 169 | // Verify nonce. |
170 | - check_ajax_referer( 'wpinv-nonce' ); |
|
170 | + check_ajax_referer('wpinv-nonce'); |
|
171 | 171 | |
172 | 172 | // Can the user manage the plugin? |
173 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
173 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
174 | 174 | die(-1); |
175 | 175 | } |
176 | 176 | |
177 | 177 | // Do we have a user id? |
178 | 178 | $user_id = $_GET['user_id']; |
179 | 179 | |
180 | - if ( empty( $user_id ) || ! is_numeric( $user_id ) ) { |
|
180 | + if (empty($user_id) || !is_numeric($user_id)) { |
|
181 | 181 | die(-1); |
182 | 182 | } |
183 | 183 | |
184 | 184 | // Fetch the billing details. |
185 | - $billing_details = wpinv_get_user_address( $user_id ); |
|
186 | - $billing_details = apply_filters( 'wpinv_ajax_billing_details', $billing_details, $user_id ); |
|
185 | + $billing_details = wpinv_get_user_address($user_id); |
|
186 | + $billing_details = apply_filters('wpinv_ajax_billing_details', $billing_details, $user_id); |
|
187 | 187 | |
188 | 188 | // unset the user id and email. |
189 | - $to_ignore = array( 'user_id', 'email' ); |
|
189 | + $to_ignore = array('user_id', 'email'); |
|
190 | 190 | |
191 | - foreach ( $to_ignore as $key ) { |
|
192 | - if ( isset( $billing_details[ $key ] ) ) { |
|
193 | - unset( $billing_details[ $key ] ); |
|
191 | + foreach ($to_ignore as $key) { |
|
192 | + if (isset($billing_details[$key])) { |
|
193 | + unset($billing_details[$key]); |
|
194 | 194 | } |
195 | 195 | } |
196 | 196 | |
197 | - wp_send_json_success( $billing_details ); |
|
197 | + wp_send_json_success($billing_details); |
|
198 | 198 | |
199 | 199 | } |
200 | 200 | |
@@ -204,47 +204,47 @@ discard block |
||
204 | 204 | public static function check_new_user_email() { |
205 | 205 | |
206 | 206 | // Verify nonce. |
207 | - check_ajax_referer( 'wpinv-nonce' ); |
|
207 | + check_ajax_referer('wpinv-nonce'); |
|
208 | 208 | |
209 | 209 | // Can the user manage the plugin? |
210 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
210 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
211 | 211 | die(-1); |
212 | 212 | } |
213 | 213 | |
214 | 214 | // We need an email address. |
215 | - if ( empty( $_GET['email'] ) ) { |
|
216 | - _e( "Provide the new user's email address", 'invoicing' ); |
|
215 | + if (empty($_GET['email'])) { |
|
216 | + _e("Provide the new user's email address", 'invoicing'); |
|
217 | 217 | exit; |
218 | 218 | } |
219 | 219 | |
220 | 220 | // Ensure the email is valid. |
221 | - $email = sanitize_text_field( $_GET['email'] ); |
|
222 | - if ( ! is_email( $email ) ) { |
|
223 | - _e( 'Invalid email address', 'invoicing' ); |
|
221 | + $email = sanitize_text_field($_GET['email']); |
|
222 | + if (!is_email($email)) { |
|
223 | + _e('Invalid email address', 'invoicing'); |
|
224 | 224 | exit; |
225 | 225 | } |
226 | 226 | |
227 | 227 | // And it does not exist. |
228 | - if ( email_exists( $email ) ) { |
|
229 | - _e( 'A user with this email address already exists', 'invoicing' ); |
|
228 | + if (email_exists($email)) { |
|
229 | + _e('A user with this email address already exists', 'invoicing'); |
|
230 | 230 | exit; |
231 | 231 | } |
232 | 232 | |
233 | - wp_send_json_success( true ); |
|
233 | + wp_send_json_success(true); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | public static function run_tool() { |
237 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
238 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
237 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
238 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
239 | 239 | die(-1); |
240 | 240 | } |
241 | 241 | |
242 | - $tool = sanitize_text_field( $_POST['tool'] ); |
|
242 | + $tool = sanitize_text_field($_POST['tool']); |
|
243 | 243 | |
244 | - do_action( 'wpinv_run_tool' ); |
|
244 | + do_action('wpinv_run_tool'); |
|
245 | 245 | |
246 | - if ( !empty( $tool ) ) { |
|
247 | - do_action( 'wpinv_tool_' . $tool ); |
|
246 | + if (!empty($tool)) { |
|
247 | + do_action('wpinv_tool_' . $tool); |
|
248 | 248 | } |
249 | 249 | } |
250 | 250 | |
@@ -254,30 +254,30 @@ discard block |
||
254 | 254 | public static function get_payment_form() { |
255 | 255 | |
256 | 256 | // Check nonce. |
257 | - if ( ! isset( $_GET['nonce'] ) || ! wp_verify_nonce( $_GET['nonce'], 'getpaid_ajax_form' ) ) { |
|
258 | - _e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
257 | + if (!isset($_GET['nonce']) || !wp_verify_nonce($_GET['nonce'], 'getpaid_ajax_form')) { |
|
258 | + _e('Error: Reload the page and try again.', 'invoicing'); |
|
259 | 259 | exit; |
260 | 260 | } |
261 | 261 | |
262 | 262 | // Is the request set up correctly? |
263 | - if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) { |
|
263 | + if (empty($_GET['form']) && empty($_GET['item'])) { |
|
264 | 264 | echo aui()->alert( |
265 | 265 | array( |
266 | 266 | 'type' => 'warning', |
267 | - 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
267 | + 'content' => __('No payment form or item provided', 'invoicing'), |
|
268 | 268 | ) |
269 | 269 | ); |
270 | 270 | exit; |
271 | 271 | } |
272 | 272 | |
273 | 273 | // Payment form or button? |
274 | - if ( ! empty( $_GET['form'] ) ) { |
|
275 | - getpaid_display_payment_form( $_GET['form'] ); |
|
276 | - } else if( ! empty( $_GET['invoice'] ) ) { |
|
277 | - getpaid_display_invoice_payment_form( $_GET['invoice'] ); |
|
274 | + if (!empty($_GET['form'])) { |
|
275 | + getpaid_display_payment_form($_GET['form']); |
|
276 | + } else if (!empty($_GET['invoice'])) { |
|
277 | + getpaid_display_invoice_payment_form($_GET['invoice']); |
|
278 | 278 | } else { |
279 | - $items = getpaid_convert_items_to_array( $_GET['item'] ); |
|
280 | - getpaid_display_item_payment_form( $items ); |
|
279 | + $items = getpaid_convert_items_to_array($_GET['item']); |
|
280 | + getpaid_display_item_payment_form($items); |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | exit; |
@@ -292,17 +292,17 @@ discard block |
||
292 | 292 | public static function payment_form() { |
293 | 293 | |
294 | 294 | // Check nonce. |
295 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
295 | + check_ajax_referer('getpaid_form_nonce'); |
|
296 | 296 | |
297 | 297 | // ... form fields... |
298 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
299 | - _e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
298 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
299 | + _e('Error: Reload the page and try again.', 'invoicing'); |
|
300 | 300 | exit; |
301 | 301 | } |
302 | 302 | |
303 | 303 | // Process the payment form. |
304 | - $checkout_class = apply_filters( 'getpaid_checkout_class', 'GetPaid_Checkout' ); |
|
305 | - $checkout = new $checkout_class( new GetPaid_Payment_Form_Submission() ); |
|
304 | + $checkout_class = apply_filters('getpaid_checkout_class', 'GetPaid_Checkout'); |
|
305 | + $checkout = new $checkout_class(new GetPaid_Payment_Form_Submission()); |
|
306 | 306 | $checkout->process_checkout(); |
307 | 307 | |
308 | 308 | exit; |
@@ -315,51 +315,51 @@ discard block |
||
315 | 315 | */ |
316 | 316 | public static function get_payment_form_states_field() { |
317 | 317 | |
318 | - if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) { |
|
318 | + if (empty($_GET['country']) || empty($_GET['form'])) { |
|
319 | 319 | exit; |
320 | 320 | } |
321 | 321 | |
322 | - $elements = getpaid_get_payment_form_elements( $_GET['form'] ); |
|
322 | + $elements = getpaid_get_payment_form_elements($_GET['form']); |
|
323 | 323 | |
324 | - if ( empty( $elements ) ) { |
|
324 | + if (empty($elements)) { |
|
325 | 325 | exit; |
326 | 326 | } |
327 | 327 | |
328 | 328 | $address_fields = array(); |
329 | - foreach ( $elements as $element ) { |
|
330 | - if ( 'address' === $element['type'] ) { |
|
329 | + foreach ($elements as $element) { |
|
330 | + if ('address' === $element['type']) { |
|
331 | 331 | $address_fields = $element; |
332 | 332 | break; |
333 | 333 | } |
334 | 334 | } |
335 | 335 | |
336 | - if ( empty( $address_fields ) ) { |
|
336 | + if (empty($address_fields)) { |
|
337 | 337 | exit; |
338 | 338 | } |
339 | 339 | |
340 | - foreach( $address_fields['fields'] as $address_field ) { |
|
340 | + foreach ($address_fields['fields'] as $address_field) { |
|
341 | 341 | |
342 | - if ( 'wpinv_state' == $address_field['name'] ) { |
|
342 | + if ('wpinv_state' == $address_field['name']) { |
|
343 | 343 | |
344 | 344 | $label = $address_field['label']; |
345 | 345 | |
346 | - if ( ! empty( $address_field['required'] ) ) { |
|
346 | + if (!empty($address_field['required'])) { |
|
347 | 347 | $label .= "<span class='text-danger'> *</span>"; |
348 | 348 | } |
349 | 349 | |
350 | - $states = wpinv_get_country_states( $_GET['country'] ); |
|
350 | + $states = wpinv_get_country_states($_GET['country']); |
|
351 | 351 | |
352 | - if ( ! empty( $states ) ) { |
|
352 | + if (!empty($states)) { |
|
353 | 353 | |
354 | 354 | $html = aui()->select( |
355 | 355 | array( |
356 | 356 | 'options' => $states, |
357 | - 'name' => esc_attr( $address_field['name'] ), |
|
358 | - 'id' => esc_attr( $address_field['name'] ), |
|
359 | - 'placeholder' => esc_attr( $address_field['placeholder'] ), |
|
357 | + 'name' => esc_attr($address_field['name']), |
|
358 | + 'id' => esc_attr($address_field['name']), |
|
359 | + 'placeholder' => esc_attr($address_field['placeholder']), |
|
360 | 360 | 'required' => (bool) $address_field['required'], |
361 | 361 | 'no_wrap' => true, |
362 | - 'label' => wp_kses_post( $label ), |
|
362 | + 'label' => wp_kses_post($label), |
|
363 | 363 | 'select2' => false, |
364 | 364 | ) |
365 | 365 | ); |
@@ -368,10 +368,10 @@ discard block |
||
368 | 368 | |
369 | 369 | $html = aui()->input( |
370 | 370 | array( |
371 | - 'name' => esc_attr( $address_field['name'] ), |
|
372 | - 'id' => esc_attr( $address_field['name'] ), |
|
371 | + 'name' => esc_attr($address_field['name']), |
|
372 | + 'id' => esc_attr($address_field['name']), |
|
373 | 373 | 'required' => (bool) $address_field['required'], |
374 | - 'label' => wp_kses_post( $label ), |
|
374 | + 'label' => wp_kses_post($label), |
|
375 | 375 | 'no_wrap' => true, |
376 | 376 | 'type' => 'text', |
377 | 377 | ) |
@@ -379,7 +379,7 @@ discard block |
||
379 | 379 | |
380 | 380 | } |
381 | 381 | |
382 | - wp_send_json_success( str_replace( 'sr-only', '', $html ) ); |
|
382 | + wp_send_json_success(str_replace('sr-only', '', $html)); |
|
383 | 383 | exit; |
384 | 384 | |
385 | 385 | } |
@@ -395,56 +395,56 @@ discard block |
||
395 | 395 | public static function recalculate_invoice_totals() { |
396 | 396 | |
397 | 397 | // Verify nonce. |
398 | - check_ajax_referer( 'wpinv-nonce' ); |
|
398 | + check_ajax_referer('wpinv-nonce'); |
|
399 | 399 | |
400 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
400 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
401 | 401 | exit; |
402 | 402 | } |
403 | 403 | |
404 | 404 | // We need an invoice. |
405 | - if ( empty( $_POST['post_id'] ) ) { |
|
405 | + if (empty($_POST['post_id'])) { |
|
406 | 406 | exit; |
407 | 407 | } |
408 | 408 | |
409 | 409 | // Fetch the invoice. |
410 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
410 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
411 | 411 | |
412 | 412 | // Ensure it exists. |
413 | - if ( ! $invoice->get_id() ) { |
|
413 | + if (!$invoice->get_id()) { |
|
414 | 414 | exit; |
415 | 415 | } |
416 | 416 | |
417 | 417 | // Maybe set the country, state, currency. |
418 | - foreach ( array( 'country', 'state', 'currency' ) as $key ) { |
|
419 | - if ( isset( $_POST[ $key ] ) ) { |
|
418 | + foreach (array('country', 'state', 'currency') as $key) { |
|
419 | + if (isset($_POST[$key])) { |
|
420 | 420 | $method = "set_$key"; |
421 | - $invoice->$method( $_POST[ $key ] ); |
|
421 | + $invoice->$method($_POST[$key]); |
|
422 | 422 | } |
423 | 423 | } |
424 | 424 | |
425 | 425 | // Maybe disable taxes. |
426 | - $invoice->set_disable_taxes( ! empty( $_POST['taxes'] ) ); |
|
426 | + $invoice->set_disable_taxes(!empty($_POST['taxes'])); |
|
427 | 427 | |
428 | 428 | // Recalculate totals. |
429 | 429 | $invoice->recalculate_total(); |
430 | 430 | |
431 | - $total = wpinv_price( wpinv_format_amount( $invoice->get_total() ), $invoice->get_currency() ); |
|
431 | + $total = wpinv_price(wpinv_format_amount($invoice->get_total()), $invoice->get_currency()); |
|
432 | 432 | |
433 | - if ( $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total() ) { |
|
434 | - $recurring_total = wpinv_price( wpinv_format_amount( $invoice->get_recurring_total() ), $invoice->get_currency() ); |
|
435 | - $total .= '<small class="form-text text-muted">' . sprintf( __( 'Recurring Price: %s', 'invoicing' ), $recurring_total ) . '</small>'; |
|
433 | + if ($invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total()) { |
|
434 | + $recurring_total = wpinv_price(wpinv_format_amount($invoice->get_recurring_total()), $invoice->get_currency()); |
|
435 | + $total .= '<small class="form-text text-muted">' . sprintf(__('Recurring Price: %s', 'invoicing'), $recurring_total) . '</small>'; |
|
436 | 436 | } |
437 | 437 | |
438 | 438 | $totals = array( |
439 | - 'subtotal' => wpinv_price( wpinv_format_amount( $invoice->get_subtotal() ), $invoice->get_currency() ), |
|
440 | - 'discount' => wpinv_price( wpinv_format_amount( $invoice->get_total_discount() ), $invoice->get_currency() ), |
|
441 | - 'tax' => wpinv_price( wpinv_format_amount( $invoice->get_total_tax() ), $invoice->get_currency() ), |
|
439 | + 'subtotal' => wpinv_price(wpinv_format_amount($invoice->get_subtotal()), $invoice->get_currency()), |
|
440 | + 'discount' => wpinv_price(wpinv_format_amount($invoice->get_total_discount()), $invoice->get_currency()), |
|
441 | + 'tax' => wpinv_price(wpinv_format_amount($invoice->get_total_tax()), $invoice->get_currency()), |
|
442 | 442 | 'total' => $total, |
443 | 443 | ); |
444 | 444 | |
445 | - $totals = apply_filters( 'getpaid_invoice_totals', $totals, $invoice ); |
|
445 | + $totals = apply_filters('getpaid_invoice_totals', $totals, $invoice); |
|
446 | 446 | |
447 | - wp_send_json_success( compact( 'totals' ) ); |
|
447 | + wp_send_json_success(compact('totals')); |
|
448 | 448 | } |
449 | 449 | |
450 | 450 | /** |
@@ -453,33 +453,33 @@ discard block |
||
453 | 453 | public static function get_invoice_items() { |
454 | 454 | |
455 | 455 | // Verify nonce. |
456 | - check_ajax_referer( 'wpinv-nonce' ); |
|
456 | + check_ajax_referer('wpinv-nonce'); |
|
457 | 457 | |
458 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
458 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
459 | 459 | exit; |
460 | 460 | } |
461 | 461 | |
462 | 462 | // We need an invoice and items. |
463 | - if ( empty( $_POST['post_id'] ) ) { |
|
463 | + if (empty($_POST['post_id'])) { |
|
464 | 464 | exit; |
465 | 465 | } |
466 | 466 | |
467 | 467 | // Fetch the invoice. |
468 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
468 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
469 | 469 | |
470 | 470 | // Ensure it exists. |
471 | - if ( ! $invoice->get_id() ) { |
|
471 | + if (!$invoice->get_id()) { |
|
472 | 472 | exit; |
473 | 473 | } |
474 | 474 | |
475 | 475 | // Return an array of invoice items. |
476 | 476 | $items = array(); |
477 | 477 | |
478 | - foreach ( $invoice->get_items() as $item_id => $item ) { |
|
479 | - $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
478 | + foreach ($invoice->get_items() as $item_id => $item) { |
|
479 | + $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
480 | 480 | } |
481 | 481 | |
482 | - wp_send_json_success( compact( 'items' ) ); |
|
482 | + wp_send_json_success(compact('items')); |
|
483 | 483 | } |
484 | 484 | |
485 | 485 | /** |
@@ -488,50 +488,50 @@ discard block |
||
488 | 488 | public static function edit_invoice_item() { |
489 | 489 | |
490 | 490 | // Verify nonce. |
491 | - check_ajax_referer( 'wpinv-nonce' ); |
|
491 | + check_ajax_referer('wpinv-nonce'); |
|
492 | 492 | |
493 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
493 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
494 | 494 | exit; |
495 | 495 | } |
496 | 496 | |
497 | 497 | // We need an invoice and item details. |
498 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['data'] ) ) { |
|
498 | + if (empty($_POST['post_id']) || empty($_POST['data'])) { |
|
499 | 499 | exit; |
500 | 500 | } |
501 | 501 | |
502 | 502 | // Fetch the invoice. |
503 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
503 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
504 | 504 | |
505 | 505 | // Ensure it exists and its not been paid for. |
506 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
506 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
507 | 507 | exit; |
508 | 508 | } |
509 | 509 | |
510 | 510 | // Format the data. |
511 | - $data = wp_list_pluck( $_POST['data'], 'value', 'field' ); |
|
511 | + $data = wp_list_pluck($_POST['data'], 'value', 'field'); |
|
512 | 512 | |
513 | 513 | // Ensure that we have an item id. |
514 | - if ( empty( $data['id'] ) ) { |
|
514 | + if (empty($data['id'])) { |
|
515 | 515 | exit; |
516 | 516 | } |
517 | 517 | |
518 | 518 | // Abort if the invoice does not have the specified item. |
519 | - $item = $invoice->get_item( (int) $data['id'] ); |
|
519 | + $item = $invoice->get_item((int) $data['id']); |
|
520 | 520 | |
521 | - if ( empty( $item ) ) { |
|
521 | + if (empty($item)) { |
|
522 | 522 | exit; |
523 | 523 | } |
524 | 524 | |
525 | 525 | // Update the item. |
526 | - $item->set_price( $data['price'] ); |
|
527 | - $item->set_name( $data['name'] ); |
|
528 | - $item->set_description( $data['description'] ); |
|
529 | - $item->set_quantity( $data['quantity'] ); |
|
526 | + $item->set_price($data['price']); |
|
527 | + $item->set_name($data['name']); |
|
528 | + $item->set_description($data['description']); |
|
529 | + $item->set_quantity($data['quantity']); |
|
530 | 530 | |
531 | 531 | // Add it to the invoice. |
532 | - $error = $invoice->add_item( $item ); |
|
532 | + $error = $invoice->add_item($item); |
|
533 | 533 | $alert = false; |
534 | - if ( is_wp_error( $error ) ) { |
|
534 | + if (is_wp_error($error)) { |
|
535 | 535 | $alert = $error->get_error_message(); |
536 | 536 | } |
537 | 537 | |
@@ -544,11 +544,11 @@ discard block |
||
544 | 544 | // Return an array of invoice items. |
545 | 545 | $items = array(); |
546 | 546 | |
547 | - foreach ( $invoice->get_items() as $item_id => $item ) { |
|
548 | - $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
547 | + foreach ($invoice->get_items() as $item_id => $item) { |
|
548 | + $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
549 | 549 | } |
550 | 550 | |
551 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
551 | + wp_send_json_success(compact('items', 'alert')); |
|
552 | 552 | } |
553 | 553 | |
554 | 554 | /** |
@@ -557,33 +557,33 @@ discard block |
||
557 | 557 | public static function remove_invoice_item() { |
558 | 558 | |
559 | 559 | // Verify nonce. |
560 | - check_ajax_referer( 'wpinv-nonce' ); |
|
560 | + check_ajax_referer('wpinv-nonce'); |
|
561 | 561 | |
562 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
562 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
563 | 563 | exit; |
564 | 564 | } |
565 | 565 | |
566 | 566 | // We need an invoice and an item. |
567 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) { |
|
567 | + if (empty($_POST['post_id']) || empty($_POST['item_id'])) { |
|
568 | 568 | exit; |
569 | 569 | } |
570 | 570 | |
571 | 571 | // Fetch the invoice. |
572 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
572 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
573 | 573 | |
574 | 574 | // Ensure it exists and its not been paid for. |
575 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
575 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
576 | 576 | exit; |
577 | 577 | } |
578 | 578 | |
579 | 579 | // Abort if the invoice does not have the specified item. |
580 | - $item = $invoice->get_item( (int) $_POST['item_id'] ); |
|
580 | + $item = $invoice->get_item((int) $_POST['item_id']); |
|
581 | 581 | |
582 | - if ( empty( $item ) ) { |
|
582 | + if (empty($item)) { |
|
583 | 583 | exit; |
584 | 584 | } |
585 | 585 | |
586 | - $invoice->remove_item( (int) $_POST['item_id'] ); |
|
586 | + $invoice->remove_item((int) $_POST['item_id']); |
|
587 | 587 | |
588 | 588 | // Update totals. |
589 | 589 | $invoice->recalculate_total(); |
@@ -594,11 +594,11 @@ discard block |
||
594 | 594 | // Return an array of invoice items. |
595 | 595 | $items = array(); |
596 | 596 | |
597 | - foreach ( $invoice->get_items() as $item_id => $item ) { |
|
598 | - $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
597 | + foreach ($invoice->get_items() as $item_id => $item) { |
|
598 | + $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
599 | 599 | } |
600 | 600 | |
601 | - wp_send_json_success( compact( 'items' ) ); |
|
601 | + wp_send_json_success(compact('items')); |
|
602 | 602 | } |
603 | 603 | |
604 | 604 | /** |
@@ -607,39 +607,39 @@ discard block |
||
607 | 607 | public static function add_invoice_items() { |
608 | 608 | |
609 | 609 | // Verify nonce. |
610 | - check_ajax_referer( 'wpinv-nonce' ); |
|
610 | + check_ajax_referer('wpinv-nonce'); |
|
611 | 611 | |
612 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
612 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
613 | 613 | exit; |
614 | 614 | } |
615 | 615 | |
616 | 616 | // We need an invoice and items. |
617 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['items'] ) ) { |
|
617 | + if (empty($_POST['post_id']) || empty($_POST['items'])) { |
|
618 | 618 | exit; |
619 | 619 | } |
620 | 620 | |
621 | 621 | // Fetch the invoice. |
622 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
622 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
623 | 623 | $alert = false; |
624 | 624 | |
625 | 625 | // Ensure it exists and its not been paid for. |
626 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
626 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
627 | 627 | exit; |
628 | 628 | } |
629 | 629 | |
630 | 630 | // Add the items. |
631 | - foreach ( $_POST['items'] as $data ) { |
|
631 | + foreach ($_POST['items'] as $data) { |
|
632 | 632 | |
633 | - $item = new GetPaid_Form_Item( $data[ 'id' ] ); |
|
633 | + $item = new GetPaid_Form_Item($data['id']); |
|
634 | 634 | |
635 | - if ( is_numeric( $data[ 'qty' ] ) && (int) $data[ 'qty' ] > 0 ) { |
|
636 | - $item->set_quantity( $data[ 'qty' ] ); |
|
635 | + if (is_numeric($data['qty']) && (int) $data['qty'] > 0) { |
|
636 | + $item->set_quantity($data['qty']); |
|
637 | 637 | } |
638 | 638 | |
639 | - if ( $item->get_id() > 0 ) { |
|
640 | - $error = $invoice->add_item( $item ); |
|
639 | + if ($item->get_id() > 0) { |
|
640 | + $error = $invoice->add_item($item); |
|
641 | 641 | |
642 | - if ( is_wp_error( $error ) ) { |
|
642 | + if (is_wp_error($error)) { |
|
643 | 643 | $alert = $error->get_error_message(); |
644 | 644 | } |
645 | 645 | |
@@ -654,11 +654,11 @@ discard block |
||
654 | 654 | // Return an array of invoice items. |
655 | 655 | $items = array(); |
656 | 656 | |
657 | - foreach ( $invoice->get_items() as $item_id => $item ) { |
|
658 | - $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
657 | + foreach ($invoice->get_items() as $item_id => $item) { |
|
658 | + $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
659 | 659 | } |
660 | 660 | |
661 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
661 | + wp_send_json_success(compact('items', 'alert')); |
|
662 | 662 | } |
663 | 663 | |
664 | 664 | /** |
@@ -667,15 +667,15 @@ discard block |
||
667 | 667 | public static function get_invoicing_items() { |
668 | 668 | |
669 | 669 | // Verify nonce. |
670 | - check_ajax_referer( 'wpinv-nonce' ); |
|
670 | + check_ajax_referer('wpinv-nonce'); |
|
671 | 671 | |
672 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
672 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
673 | 673 | exit; |
674 | 674 | } |
675 | 675 | |
676 | 676 | // We need a search term. |
677 | - if ( empty( $_GET['search'] ) ) { |
|
678 | - wp_send_json_success( array() ); |
|
677 | + if (empty($_GET['search'])) { |
|
678 | + wp_send_json_success(array()); |
|
679 | 679 | } |
680 | 680 | |
681 | 681 | // Retrieve items. |
@@ -684,8 +684,8 @@ discard block |
||
684 | 684 | 'orderby' => 'title', |
685 | 685 | 'order' => 'ASC', |
686 | 686 | 'posts_per_page' => -1, |
687 | - 'post_status' => array( 'publish' ), |
|
688 | - 's' => trim( $_GET['search'] ), |
|
687 | + 'post_status' => array('publish'), |
|
688 | + 's' => trim($_GET['search']), |
|
689 | 689 | 'meta_query' => array( |
690 | 690 | array( |
691 | 691 | 'key' => '_wpinv_type', |
@@ -695,14 +695,14 @@ discard block |
||
695 | 695 | ) |
696 | 696 | ); |
697 | 697 | |
698 | - $items = get_posts( apply_filters( 'getpaid_ajax_invoice_items_query_args', $item_args ) ); |
|
698 | + $items = get_posts(apply_filters('getpaid_ajax_invoice_items_query_args', $item_args)); |
|
699 | 699 | $data = array(); |
700 | 700 | |
701 | 701 | |
702 | - $is_payment_form = ( ! empty( $_GET['post_id'] ) && 'wpi_payment_form' == get_post_type( $_GET['post_id'] ) ); |
|
702 | + $is_payment_form = (!empty($_GET['post_id']) && 'wpi_payment_form' == get_post_type($_GET['post_id'])); |
|
703 | 703 | |
704 | - foreach ( $items as $item ) { |
|
705 | - $item = new GetPaid_Form_Item( $item ); |
|
704 | + foreach ($items as $item) { |
|
705 | + $item = new GetPaid_Form_Item($item); |
|
706 | 706 | $data[] = array( |
707 | 707 | 'id' => $item->get_id(), |
708 | 708 | 'text' => $item->get_name(), |
@@ -710,7 +710,7 @@ discard block |
||
710 | 710 | ); |
711 | 711 | } |
712 | 712 | |
713 | - wp_send_json_success( $data ); |
|
713 | + wp_send_json_success($data); |
|
714 | 714 | |
715 | 715 | } |
716 | 716 | |
@@ -720,24 +720,24 @@ discard block |
||
720 | 720 | public static function get_aui_states_field() { |
721 | 721 | |
722 | 722 | // Verify nonce. |
723 | - check_ajax_referer( 'wpinv-nonce' ); |
|
723 | + check_ajax_referer('wpinv-nonce'); |
|
724 | 724 | |
725 | 725 | // We need a country. |
726 | - if ( empty( $_GET['country'] ) ) { |
|
726 | + if (empty($_GET['country'])) { |
|
727 | 727 | exit; |
728 | 728 | } |
729 | 729 | |
730 | - $states = wpinv_get_country_states( trim( $_GET['country'] ) ); |
|
731 | - $state = isset( $_GET['state'] ) ? trim( $_GET['state'] ) : wpinv_get_default_state(); |
|
730 | + $states = wpinv_get_country_states(trim($_GET['country'])); |
|
731 | + $state = isset($_GET['state']) ? trim($_GET['state']) : wpinv_get_default_state(); |
|
732 | 732 | |
733 | - if ( empty( $states ) ) { |
|
733 | + if (empty($states)) { |
|
734 | 734 | |
735 | 735 | $html = aui()->input( |
736 | 736 | array( |
737 | 737 | 'type' => 'text', |
738 | 738 | 'id' => 'wpinv_state', |
739 | 739 | 'name' => 'wpinv_state', |
740 | - 'label' => __( 'State', 'invoicing' ), |
|
740 | + 'label' => __('State', 'invoicing'), |
|
741 | 741 | 'label_type' => 'vertical', |
742 | 742 | 'placeholder' => 'Liège', |
743 | 743 | 'class' => 'form-control-sm', |
@@ -751,9 +751,9 @@ discard block |
||
751 | 751 | array( |
752 | 752 | 'id' => 'wpinv_state', |
753 | 753 | 'name' => 'wpinv_state', |
754 | - 'label' => __( 'State', 'invoicing' ), |
|
754 | + 'label' => __('State', 'invoicing'), |
|
755 | 755 | 'label_type' => 'vertical', |
756 | - 'placeholder' => __( 'Select a state', 'invoicing' ), |
|
756 | + 'placeholder' => __('Select a state', 'invoicing'), |
|
757 | 757 | 'class' => 'form-control-sm', |
758 | 758 | 'value' => $state, |
759 | 759 | 'options' => $states, |
@@ -767,7 +767,7 @@ discard block |
||
767 | 767 | wp_send_json_success( |
768 | 768 | array( |
769 | 769 | 'html' => $html, |
770 | - 'select' => ! empty ( $states ) |
|
770 | + 'select' => !empty ($states) |
|
771 | 771 | ) |
772 | 772 | ); |
773 | 773 | |
@@ -781,46 +781,46 @@ discard block |
||
781 | 781 | public static function ip_geolocation() { |
782 | 782 | |
783 | 783 | // Check nonce. |
784 | - check_ajax_referer( 'getpaid-ip-location' ); |
|
784 | + check_ajax_referer('getpaid-ip-location'); |
|
785 | 785 | |
786 | 786 | // IP address. |
787 | - if ( empty( $_GET['ip'] ) || ! rest_is_ip_address( $_GET['ip'] ) ) { |
|
788 | - _e( 'Invalid IP Address.', 'invoicing' ); |
|
787 | + if (empty($_GET['ip']) || !rest_is_ip_address($_GET['ip'])) { |
|
788 | + _e('Invalid IP Address.', 'invoicing'); |
|
789 | 789 | exit; |
790 | 790 | } |
791 | 791 | |
792 | 792 | // Retrieve location info. |
793 | - $location = getpaid_geolocate_ip_address( $_GET['ip'] ); |
|
793 | + $location = getpaid_geolocate_ip_address($_GET['ip']); |
|
794 | 794 | |
795 | - if ( empty( $location ) ) { |
|
796 | - _e( 'Unable to find geolocation for the IP Address.', 'invoicing' ); |
|
795 | + if (empty($location)) { |
|
796 | + _e('Unable to find geolocation for the IP Address.', 'invoicing'); |
|
797 | 797 | exit; |
798 | 798 | } |
799 | 799 | |
800 | 800 | // Sorry. |
801 | - extract( $location ); |
|
801 | + extract($location); |
|
802 | 802 | |
803 | 803 | // Prepare the address. |
804 | 804 | $content = ''; |
805 | 805 | |
806 | - if ( ! empty( $location['city'] ) ) { |
|
807 | - $content .= $location['city'] . ', '; |
|
806 | + if (!empty($location['city'])) { |
|
807 | + $content .= $location['city'] . ', '; |
|
808 | 808 | } |
809 | 809 | |
810 | - if ( ! empty( $location['region'] ) ) { |
|
811 | - $content .= $location['region'] . ', '; |
|
810 | + if (!empty($location['region'])) { |
|
811 | + $content .= $location['region'] . ', '; |
|
812 | 812 | } |
813 | 813 | |
814 | - $content .= $location['country'] . ' (' . $location['iso'] . ')'; |
|
814 | + $content .= $location['country'] . ' (' . $location['iso'] . ')'; |
|
815 | 815 | |
816 | 816 | $location['address'] = $content; |
817 | 817 | |
818 | - $content = '<p>'. sprintf( __( '<b>Address:</b> %s', 'invoicing' ), $content ) . '</p>'; |
|
819 | - $content .= '<p>'. $location['credit'] . '</p>'; |
|
818 | + $content = '<p>' . sprintf(__('<b>Address:</b> %s', 'invoicing'), $content) . '</p>'; |
|
819 | + $content .= '<p>' . $location['credit'] . '</p>'; |
|
820 | 820 | |
821 | 821 | $location['content'] = $content; |
822 | 822 | |
823 | - wpinv_get_template( 'geolocation.php', $location ); |
|
823 | + wpinv_get_template('geolocation.php', $location); |
|
824 | 824 | |
825 | 825 | exit; |
826 | 826 | } |
@@ -833,11 +833,11 @@ discard block |
||
833 | 833 | public static function payment_form_refresh_prices() { |
834 | 834 | |
835 | 835 | // Check nonce. |
836 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
836 | + check_ajax_referer('getpaid_form_nonce'); |
|
837 | 837 | |
838 | 838 | // ... form fields... |
839 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
840 | - _e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
839 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
840 | + _e('Error: Reload the page and try again.', 'invoicing'); |
|
841 | 841 | exit; |
842 | 842 | } |
843 | 843 | |
@@ -845,7 +845,7 @@ discard block |
||
845 | 845 | $submission = new GetPaid_Payment_Form_Submission(); |
846 | 846 | |
847 | 847 | // Do we have an error? |
848 | - if ( ! empty( $submission->last_error ) ) { |
|
848 | + if (!empty($submission->last_error)) { |
|
849 | 849 | echo $submission->last_error; |
850 | 850 | exit; |
851 | 851 | } |
@@ -858,43 +858,43 @@ discard block |
||
858 | 858 | 'is_free' => $submission->get_payment_details(), |
859 | 859 | |
860 | 860 | 'totals' => array( |
861 | - 'subtotal' => wpinv_price( wpinv_format_amount( $submission->subtotal_amount ), $submission->get_currency() ), |
|
862 | - 'discount' => wpinv_price( wpinv_format_amount( $submission->get_total_discount() ), $submission->get_currency() ), |
|
863 | - 'fees' => wpinv_price( wpinv_format_amount( $submission->get_total_fees() ), $submission->get_currency() ), |
|
864 | - 'tax' => wpinv_price( wpinv_format_amount( $submission->get_total_tax() ), $submission->get_currency() ), |
|
865 | - 'total' => wpinv_price( wpinv_format_amount( $submission->get_total() ), $submission->get_currency() ), |
|
861 | + 'subtotal' => wpinv_price(wpinv_format_amount($submission->subtotal_amount), $submission->get_currency()), |
|
862 | + 'discount' => wpinv_price(wpinv_format_amount($submission->get_total_discount()), $submission->get_currency()), |
|
863 | + 'fees' => wpinv_price(wpinv_format_amount($submission->get_total_fees()), $submission->get_currency()), |
|
864 | + 'tax' => wpinv_price(wpinv_format_amount($submission->get_total_tax()), $submission->get_currency()), |
|
865 | + 'total' => wpinv_price(wpinv_format_amount($submission->get_total()), $submission->get_currency()), |
|
866 | 866 | ), |
867 | 867 | |
868 | 868 | 'texts' => array( |
869 | - '.getpaid-checkout-total-payable' => wpinv_price( wpinv_format_amount( $submission->get_total() ), $submission->get_currency() ), |
|
869 | + '.getpaid-checkout-total-payable' => wpinv_price(wpinv_format_amount($submission->get_total()), $submission->get_currency()), |
|
870 | 870 | ) |
871 | 871 | |
872 | 872 | ); |
873 | 873 | |
874 | 874 | // Add items. |
875 | 875 | $items = $submission->get_items(); |
876 | - if ( ! empty( $items ) ) { |
|
876 | + if (!empty($items)) { |
|
877 | 877 | $result['items'] = array(); |
878 | 878 | |
879 | - foreach( $items as $item_id => $item ) { |
|
880 | - $result['items']["$item_id"] = wpinv_price( wpinv_format_amount( $item->get_price() * $item->get_quantity() ) ); |
|
879 | + foreach ($items as $item_id => $item) { |
|
880 | + $result['items']["$item_id"] = wpinv_price(wpinv_format_amount($item->get_price() * $item->get_quantity())); |
|
881 | 881 | } |
882 | 882 | } |
883 | 883 | |
884 | 884 | // Add invoice. |
885 | - if ( $submission->has_invoice() ) { |
|
885 | + if ($submission->has_invoice()) { |
|
886 | 886 | $result['invoice'] = $submission->get_invoice()->ID; |
887 | 887 | } |
888 | 888 | |
889 | 889 | // Add discount code. |
890 | - if ( $submission->has_discount_code() ) { |
|
890 | + if ($submission->has_discount_code()) { |
|
891 | 891 | $result['discount_code'] = $submission->get_discount_code(); |
892 | 892 | } |
893 | 893 | |
894 | 894 | // Filter the result. |
895 | - $result = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $result, $submission ); |
|
895 | + $result = apply_filters('getpaid_payment_form_ajax_refresh_prices', $result, $submission); |
|
896 | 896 | |
897 | - wp_send_json_success( $result ); |
|
897 | + wp_send_json_success($result); |
|
898 | 898 | } |
899 | 899 | |
900 | 900 | /** |
@@ -905,53 +905,53 @@ discard block |
||
905 | 905 | public static function buy_items() { |
906 | 906 | $user_id = get_current_user_id(); |
907 | 907 | |
908 | - if ( empty( $user_id ) ) { // If not logged in then lets redirect to the login page |
|
909 | - wp_send_json( array( |
|
910 | - 'success' => wp_login_url( wp_get_referer() ) |
|
911 | - ) ); |
|
908 | + if (empty($user_id)) { // If not logged in then lets redirect to the login page |
|
909 | + wp_send_json(array( |
|
910 | + 'success' => wp_login_url(wp_get_referer()) |
|
911 | + )); |
|
912 | 912 | } else { |
913 | 913 | // Only check nonce if logged in as it could be cached when logged out. |
914 | - if ( ! isset( $_POST['wpinv_buy_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_buy_nonce'], 'wpinv_buy_items' ) ) { |
|
915 | - wp_send_json( array( |
|
916 | - 'error' => __( 'Security checks failed.', 'invoicing' ) |
|
917 | - ) ); |
|
914 | + if (!isset($_POST['wpinv_buy_nonce']) || !wp_verify_nonce($_POST['wpinv_buy_nonce'], 'wpinv_buy_items')) { |
|
915 | + wp_send_json(array( |
|
916 | + 'error' => __('Security checks failed.', 'invoicing') |
|
917 | + )); |
|
918 | 918 | wp_die(); |
919 | 919 | } |
920 | 920 | |
921 | 921 | // allow to set a custom price through post_id |
922 | 922 | $items = $_POST['items']; |
923 | - $related_post_id = isset( $_POST['post_id'] ) ? (int)$_POST['post_id'] : 0; |
|
924 | - $custom_item_price = $related_post_id ? abs( get_post_meta( $related_post_id, '_wpi_custom_price', true ) ) : 0; |
|
923 | + $related_post_id = isset($_POST['post_id']) ? (int) $_POST['post_id'] : 0; |
|
924 | + $custom_item_price = $related_post_id ? abs(get_post_meta($related_post_id, '_wpi_custom_price', true)) : 0; |
|
925 | 925 | |
926 | 926 | $cart_items = array(); |
927 | - if ( $items ) { |
|
928 | - $items = explode( ',', $items ); |
|
927 | + if ($items) { |
|
928 | + $items = explode(',', $items); |
|
929 | 929 | |
930 | - foreach( $items as $item ) { |
|
930 | + foreach ($items as $item) { |
|
931 | 931 | $item_id = $item; |
932 | 932 | $quantity = 1; |
933 | 933 | |
934 | - if ( strpos( $item, '|' ) !== false ) { |
|
935 | - $item_parts = explode( '|', $item ); |
|
934 | + if (strpos($item, '|') !== false) { |
|
935 | + $item_parts = explode('|', $item); |
|
936 | 936 | $item_id = $item_parts[0]; |
937 | 937 | $quantity = $item_parts[1]; |
938 | 938 | } |
939 | 939 | |
940 | - if ( $item_id && $quantity ) { |
|
940 | + if ($item_id && $quantity) { |
|
941 | 941 | $cart_items_arr = array( |
942 | - 'id' => (int)$item_id, |
|
943 | - 'quantity' => (int)$quantity |
|
942 | + 'id' => (int) $item_id, |
|
943 | + 'quantity' => (int) $quantity |
|
944 | 944 | ); |
945 | 945 | |
946 | 946 | // If there is a related post id then add it to meta |
947 | - if ( $related_post_id ) { |
|
947 | + if ($related_post_id) { |
|
948 | 948 | $cart_items_arr['meta'] = array( |
949 | 949 | 'post_id' => $related_post_id |
950 | 950 | ); |
951 | 951 | } |
952 | 952 | |
953 | 953 | // If there is a custom price then set it. |
954 | - if ( $custom_item_price ) { |
|
954 | + if ($custom_item_price) { |
|
955 | 955 | $cart_items_arr['custom_price'] = $custom_item_price; |
956 | 956 | } |
957 | 957 | |
@@ -967,37 +967,37 @@ discard block |
||
967 | 967 | * @param int $related_post_id The related post id if any. |
968 | 968 | * @since 1.0.0 |
969 | 969 | */ |
970 | - $cart_items = apply_filters( 'wpinv_buy_cart_items', $cart_items, $related_post_id ); |
|
970 | + $cart_items = apply_filters('wpinv_buy_cart_items', $cart_items, $related_post_id); |
|
971 | 971 | |
972 | 972 | // Make sure its not in the cart already, if it is then redirect to checkout. |
973 | 973 | $cart_invoice = wpinv_get_invoice_cart(); |
974 | 974 | |
975 | - if ( isset( $cart_invoice->items ) && !empty( $cart_invoice->items ) && !empty( $cart_items ) && serialize( $cart_invoice->items ) == serialize( $cart_items ) ) { |
|
976 | - wp_send_json( array( |
|
975 | + if (isset($cart_invoice->items) && !empty($cart_invoice->items) && !empty($cart_items) && serialize($cart_invoice->items) == serialize($cart_items)) { |
|
976 | + wp_send_json(array( |
|
977 | 977 | 'success' => $cart_invoice->get_checkout_payment_url() |
978 | - ) ); |
|
978 | + )); |
|
979 | 979 | wp_die(); |
980 | 980 | } |
981 | 981 | |
982 | 982 | // Check if user has invoice with same items waiting to be paid. |
983 | - $user_invoices = wpinv_get_users_invoices( $user_id , 10 , false , 'wpi-pending' ); |
|
984 | - if ( !empty( $user_invoices ) ) { |
|
985 | - foreach( $user_invoices as $user_invoice ) { |
|
983 | + $user_invoices = wpinv_get_users_invoices($user_id, 10, false, 'wpi-pending'); |
|
984 | + if (!empty($user_invoices)) { |
|
985 | + foreach ($user_invoices as $user_invoice) { |
|
986 | 986 | $user_cart_details = array(); |
987 | - $invoice = wpinv_get_invoice( $user_invoice->ID ); |
|
987 | + $invoice = wpinv_get_invoice($user_invoice->ID); |
|
988 | 988 | $cart_details = $invoice->get_cart_details(); |
989 | 989 | |
990 | - if ( !empty( $cart_details ) ) { |
|
991 | - foreach ( $cart_details as $invoice_item ) { |
|
990 | + if (!empty($cart_details)) { |
|
991 | + foreach ($cart_details as $invoice_item) { |
|
992 | 992 | $ii_arr = array(); |
993 | - $ii_arr['id'] = (int)$invoice_item['id']; |
|
994 | - $ii_arr['quantity'] = (int)$invoice_item['quantity']; |
|
993 | + $ii_arr['id'] = (int) $invoice_item['id']; |
|
994 | + $ii_arr['quantity'] = (int) $invoice_item['quantity']; |
|
995 | 995 | |
996 | - if (isset( $invoice_item['meta'] ) && !empty( $invoice_item['meta'] ) ) { |
|
996 | + if (isset($invoice_item['meta']) && !empty($invoice_item['meta'])) { |
|
997 | 997 | $ii_arr['meta'] = $invoice_item['meta']; |
998 | 998 | } |
999 | 999 | |
1000 | - if ( isset( $invoice_item['custom_price'] ) && !empty( $invoice_item['custom_price'] ) ) { |
|
1000 | + if (isset($invoice_item['custom_price']) && !empty($invoice_item['custom_price'])) { |
|
1001 | 1001 | $ii_arr['custom_price'] = $invoice_item['custom_price']; |
1002 | 1002 | } |
1003 | 1003 | |
@@ -1005,17 +1005,17 @@ discard block |
||
1005 | 1005 | } |
1006 | 1006 | } |
1007 | 1007 | |
1008 | - if ( !empty( $user_cart_details ) && serialize( $cart_items ) == serialize( $user_cart_details ) ) { |
|
1009 | - wp_send_json( array( |
|
1008 | + if (!empty($user_cart_details) && serialize($cart_items) == serialize($user_cart_details)) { |
|
1009 | + wp_send_json(array( |
|
1010 | 1010 | 'success' => $invoice->get_checkout_payment_url() |
1011 | - ) ); |
|
1011 | + )); |
|
1012 | 1012 | wp_die(); |
1013 | 1013 | } |
1014 | 1014 | } |
1015 | 1015 | } |
1016 | 1016 | |
1017 | 1017 | // Create invoice and send user to checkout |
1018 | - if ( !empty( $cart_items ) ) { |
|
1018 | + if (!empty($cart_items)) { |
|
1019 | 1019 | $invoice_data = array( |
1020 | 1020 | 'status' => 'wpi-pending', |
1021 | 1021 | 'created_via' => 'wpi', |
@@ -1023,21 +1023,21 @@ discard block |
||
1023 | 1023 | 'cart_details' => $cart_items, |
1024 | 1024 | ); |
1025 | 1025 | |
1026 | - $invoice = wpinv_insert_invoice( $invoice_data, true ); |
|
1026 | + $invoice = wpinv_insert_invoice($invoice_data, true); |
|
1027 | 1027 | |
1028 | - if ( !empty( $invoice ) && isset( $invoice->ID ) ) { |
|
1029 | - wp_send_json( array( |
|
1028 | + if (!empty($invoice) && isset($invoice->ID)) { |
|
1029 | + wp_send_json(array( |
|
1030 | 1030 | 'success' => $invoice->get_checkout_payment_url() |
1031 | - ) ); |
|
1031 | + )); |
|
1032 | 1032 | } else { |
1033 | - wp_send_json( array( |
|
1034 | - 'error' => __( 'Invoice failed to create', 'invoicing' ) |
|
1035 | - ) ); |
|
1033 | + wp_send_json(array( |
|
1034 | + 'error' => __('Invoice failed to create', 'invoicing') |
|
1035 | + )); |
|
1036 | 1036 | } |
1037 | 1037 | } else { |
1038 | - wp_send_json( array( |
|
1039 | - 'error' => __( 'Items not valid.', 'invoicing' ) |
|
1040 | - ) ); |
|
1038 | + wp_send_json(array( |
|
1039 | + 'error' => __('Items not valid.', 'invoicing') |
|
1040 | + )); |
|
1041 | 1041 | } |
1042 | 1042 | } |
1043 | 1043 |