@@ -1,41 +1,41 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( !defined('ABSPATH') ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | global $post; |
6 | 6 | $invoice_id = $post->ID; |
7 | -$invoice = wpinv_get_invoice( $invoice_id ); |
|
8 | -if ( empty( $invoice ) ) { |
|
7 | +$invoice = wpinv_get_invoice($invoice_id); |
|
8 | +if (empty($invoice)) { |
|
9 | 9 | exit; |
10 | 10 | } |
11 | -$type = $post->post_type == 'wpi_invoice' ? __( 'Invoice', 'invoicing' ): __( 'Quotation', 'invoicing' ); |
|
12 | -do_action( 'wpinv_invoice_print_before_display', $invoice ); ?><!DOCTYPE html> |
|
11 | +$type = $post->post_type == 'wpi_invoice' ? __('Invoice', 'invoicing') : __('Quotation', 'invoicing'); |
|
12 | +do_action('wpinv_invoice_print_before_display', $invoice); ?><!DOCTYPE html> |
|
13 | 13 | <html <?php language_attributes(); ?>> |
14 | 14 | <head> |
15 | 15 | <meta charset="UTF-8"> |
16 | 16 | <title><?php wp_title() ?></title> |
17 | - <meta charset="<?php bloginfo( 'charset' ); ?>" /> |
|
17 | + <meta charset="<?php bloginfo('charset'); ?>" /> |
|
18 | 18 | <meta name="viewport" content="width=device-width, initial-scale=1"> |
19 | 19 | <meta name="robots" content="noindex,nofollow"> |
20 | 20 | |
21 | - <?php do_action( 'wpinv_invoice_print_head', $invoice ); ?> |
|
21 | + <?php do_action('wpinv_invoice_print_head', $invoice); ?> |
|
22 | 22 | </head> |
23 | 23 | <body class="body wpinv wpinv-print"> |
24 | - <?php do_action( 'wpinv_invoice_print_body_start', $invoice ); ?> |
|
24 | + <?php do_action('wpinv_invoice_print_body_start', $invoice); ?> |
|
25 | 25 | <div class="container wpinv-wrap"> |
26 | - <?php if ( $watermark = wpinv_watermark( $invoice_id ) ) { ?> |
|
27 | - <div class="watermark no-print"><p><?php echo esc_html( $watermark ) ?></p></div> |
|
26 | + <?php if ($watermark = wpinv_watermark($invoice_id)) { ?> |
|
27 | + <div class="watermark no-print"><p><?php echo esc_html($watermark) ?></p></div> |
|
28 | 28 | <?php } ?> |
29 | 29 | <!-- ///// Start PDF header --> |
30 | 30 | <htmlpageheader name="wpinv-pdf-header"> |
31 | - <?php do_action( 'wpinv_invoice_print_before_header', $invoice ); ?> |
|
31 | + <?php do_action('wpinv_invoice_print_before_header', $invoice); ?> |
|
32 | 32 | <div class="row wpinv-header"> |
33 | 33 | <div class="col-xs-6 wpinv-business"> |
34 | - <a target="_blank" href="<?php echo esc_url( wpinv_get_business_website() ); ?>"> |
|
35 | - <?php if ( $logo = wpinv_get_business_logo() ) { ?> |
|
36 | - <img class="logo" src="<?php echo esc_url( $logo ); ?>"> |
|
34 | + <a target="_blank" href="<?php echo esc_url(wpinv_get_business_website()); ?>"> |
|
35 | + <?php if ($logo = wpinv_get_business_logo()) { ?> |
|
36 | + <img class="logo" src="<?php echo esc_url($logo); ?>"> |
|
37 | 37 | <?php } else { ?> |
38 | - <h1><?php echo esc_html( wpinv_get_business_name() ); ?></h1> |
|
38 | + <h1><?php echo esc_html(wpinv_get_business_name()); ?></h1> |
|
39 | 39 | <?php } ?> |
40 | 40 | </a> |
41 | 41 | </div> |
@@ -44,56 +44,56 @@ discard block |
||
44 | 44 | <h2><?php echo $type; ?></h2> |
45 | 45 | </div> |
46 | 46 | </div> |
47 | - <?php do_action( 'wpinv_invoice_print_after_header', $invoice ); ?> |
|
47 | + <?php do_action('wpinv_invoice_print_after_header', $invoice); ?> |
|
48 | 48 | </htmlpageheader> |
49 | 49 | <!-- End PDF header ///// --> |
50 | 50 | |
51 | - <?php do_action( 'wpinv_invoice_print_before_top_content', $invoice ); ?> |
|
51 | + <?php do_action('wpinv_invoice_print_before_top_content', $invoice); ?> |
|
52 | 52 | <div class="row wpinv-top-content"> |
53 | 53 | <div class="col-xs-12 col-sm-6 wpinv-addresses"> |
54 | 54 | <div class="col-xs-12 wpinv-address wpinv-from-address"> |
55 | 55 | <?php wpinv_display_from_address(); ?> |
56 | 56 | </div> |
57 | 57 | <div class="col-xs-12 wpinv-address wpinv-to-address"> |
58 | - <?php wpinv_display_to_address( $invoice_id ); ?> |
|
58 | + <?php wpinv_display_to_address($invoice_id); ?> |
|
59 | 59 | </div> |
60 | 60 | </div> |
61 | 61 | <div class="col-xs-12 col-sm-6 wpinv-details"> |
62 | 62 | <div class="col-xs-12 wpinv-line-details"> |
63 | - <?php do_action( 'wpinv_invoice_print_before_details', $invoice ); ?> |
|
64 | - <?php wpinv_display_invoice_details( $invoice ); ?> |
|
65 | - <?php do_action( 'wpinv_invoice_print_after_details', $invoice ); ?> |
|
63 | + <?php do_action('wpinv_invoice_print_before_details', $invoice); ?> |
|
64 | + <?php wpinv_display_invoice_details($invoice); ?> |
|
65 | + <?php do_action('wpinv_invoice_print_after_details', $invoice); ?> |
|
66 | 66 | </div> |
67 | 67 | </div> |
68 | 68 | </div> |
69 | - <?php do_action( 'wpinv_invoice_print_after_top_content', $invoice ); ?> |
|
69 | + <?php do_action('wpinv_invoice_print_after_top_content', $invoice); ?> |
|
70 | 70 | |
71 | - <?php do_action( 'wpinv_invoice_print_middle', $invoice ); ?> |
|
71 | + <?php do_action('wpinv_invoice_print_middle', $invoice); ?> |
|
72 | 72 | |
73 | - <?php do_action( 'wpinv_invoice_print_before_line_items', $invoice ); ?> |
|
73 | + <?php do_action('wpinv_invoice_print_before_line_items', $invoice); ?> |
|
74 | 74 | <div class="row wpinv-items"> |
75 | 75 | <div class="col-sm-12 wpinv-line-items"> |
76 | - <?php wpinv_display_line_items( $invoice_id ); ?> |
|
76 | + <?php wpinv_display_line_items($invoice_id); ?> |
|
77 | 77 | </div> |
78 | 78 | </div> |
79 | - <?php do_action( 'wpinv_invoice_print_after_line_items', $invoice ); ?> |
|
79 | + <?php do_action('wpinv_invoice_print_after_line_items', $invoice); ?> |
|
80 | 80 | |
81 | 81 | <!-- ///// Start PDF footer --> |
82 | 82 | <htmlpagefooter name="wpinv-pdf-footer"> |
83 | - <?php do_action( 'wpinv_invoice_print_before_footer', $invoice ); ?> |
|
83 | + <?php do_action('wpinv_invoice_print_before_footer', $invoice); ?> |
|
84 | 84 | <div class="row wpinv-footer"> |
85 | 85 | <div class="col-sm-12"> |
86 | - <?php if ( $term_text = wpinv_get_terms_text() ) { ?> |
|
87 | - <div class="terms-text"><?php echo wpautop( $term_text ); ?></div> |
|
86 | + <?php if ($term_text = wpinv_get_terms_text()) { ?> |
|
87 | + <div class="terms-text"><?php echo wpautop($term_text); ?></div> |
|
88 | 88 | <?php } ?> |
89 | 89 | <div class="footer-text"><?php echo wpinv_get_business_footer(); ?></div> |
90 | - <div class="print-only"><?php _e( 'Page ', 'invoicing' ) ?> {PAGENO}/{nbpg}</div> |
|
90 | + <div class="print-only"><?php _e('Page ', 'invoicing') ?> {PAGENO}/{nbpg}</div> |
|
91 | 91 | </div> |
92 | 92 | </div> |
93 | - <?php do_action( 'wpinv_invoice_print_after_footer', $invoice ); ?> |
|
93 | + <?php do_action('wpinv_invoice_print_after_footer', $invoice); ?> |
|
94 | 94 | </htmlpagefooter> |
95 | 95 | <!-- End PDF footer ///// --> |
96 | 96 | </div><!-- END wpinv-wrap --> |
97 | - <?php do_action( 'wpinv_invoice_print_body_end', $invoice ); ?> |
|
97 | + <?php do_action('wpinv_invoice_print_body_end', $invoice); ?> |
|
98 | 98 | </body> |
99 | 99 | </html> |
100 | 100 | \ No newline at end of file |
@@ -7,15 +7,15 @@ 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 | class WPInv_Plugin { |
15 | 15 | private static $instance; |
16 | 16 | |
17 | 17 | public static function run() { |
18 | - if ( !isset( self::$instance ) && !( self::$instance instanceof WPInv_Plugin ) ) { |
|
18 | + if (!isset(self::$instance) && !(self::$instance instanceof WPInv_Plugin)) { |
|
19 | 19 | self::$instance = new WPInv_Plugin; |
20 | 20 | self::$instance->includes(); |
21 | 21 | self::$instance->actions(); |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | self::$instance->reports = new WPInv_Reports(); |
24 | 24 | } |
25 | 25 | |
26 | - do_action( 'wpinv_loaded' ); |
|
26 | + do_action('wpinv_loaded'); |
|
27 | 27 | |
28 | 28 | return self::$instance; |
29 | 29 | } |
@@ -33,31 +33,31 @@ discard block |
||
33 | 33 | } |
34 | 34 | |
35 | 35 | public function define_constants() { |
36 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
37 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
36 | + define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE)); |
|
37 | + define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE)); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | private function actions() { |
41 | 41 | /* Internationalize the text strings used. */ |
42 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
42 | + add_action('plugins_loaded', array(&$this, 'plugins_loaded')); |
|
43 | 43 | |
44 | 44 | /* Perform actions on admin initialization. */ |
45 | - add_action( 'admin_init', array( &$this, 'admin_init') ); |
|
46 | - add_action( 'init', array( &$this, 'init' ), 3 ); |
|
47 | - add_action( 'init', array( 'WPInv_Shortcodes', 'init' ) ); |
|
48 | - add_action( 'init', array( &$this, 'wpinv_actions' ) ); |
|
45 | + add_action('admin_init', array(&$this, 'admin_init')); |
|
46 | + add_action('init', array(&$this, 'init'), 3); |
|
47 | + add_action('init', array('WPInv_Shortcodes', 'init')); |
|
48 | + add_action('init', array(&$this, 'wpinv_actions')); |
|
49 | 49 | |
50 | - if ( class_exists( 'BuddyPress' ) ) { |
|
51 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
50 | + if (class_exists('BuddyPress')) { |
|
51 | + add_action('bp_include', array(&$this, 'bp_invoicing_init')); |
|
52 | 52 | } |
53 | 53 | |
54 | - add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
54 | + add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts')); |
|
55 | 55 | |
56 | - if ( is_admin() ) { |
|
57 | - add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) ); |
|
58 | - add_action( 'admin_body_class', array( &$this, 'admin_body_class' ) ); |
|
56 | + if (is_admin()) { |
|
57 | + add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts')); |
|
58 | + add_action('admin_body_class', array(&$this, 'admin_body_class')); |
|
59 | 59 | } else { |
60 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
60 | + add_filter('pre_get_posts', array(&$this, 'pre_get_posts')); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -67,9 +67,9 @@ discard block |
||
67 | 67 | * |
68 | 68 | * @param WPInv_Plugin $this. Current WPInv_Plugin instance. Passed by reference. |
69 | 69 | */ |
70 | - do_action_ref_array( 'wpinv_actions', array( &$this ) ); |
|
70 | + do_action_ref_array('wpinv_actions', array(&$this)); |
|
71 | 71 | |
72 | - add_action( 'admin_init', array( &$this, 'activation_redirect') ); |
|
72 | + add_action('admin_init', array(&$this, 'activation_redirect')); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | public function plugins_loaded() { |
@@ -83,187 +83,187 @@ discard block |
||
83 | 83 | * @since 1.0 |
84 | 84 | */ |
85 | 85 | public function load_textdomain() { |
86 | - $locale = apply_filters( 'plugin_locale', get_locale(), 'invoicing' ); |
|
86 | + $locale = apply_filters('plugin_locale', get_locale(), 'invoicing'); |
|
87 | 87 | |
88 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
89 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
88 | + load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo'); |
|
89 | + load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages'); |
|
90 | 90 | |
91 | 91 | /** |
92 | 92 | * Define language constants. |
93 | 93 | */ |
94 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
94 | + require_once(WPINV_PLUGIN_DIR . 'language.php'); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | public function includes() { |
98 | 98 | global $wpinv_options; |
99 | 99 | |
100 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
100 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'); |
|
101 | 101 | $wpinv_options = wpinv_get_settings(); |
102 | 102 | |
103 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php' ); |
|
104 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
105 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
106 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
107 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
108 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
109 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
110 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php' ); |
|
111 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
112 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
113 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
114 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
115 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
116 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gd-functions.php' ); |
|
117 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' ); |
|
118 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php' ); |
|
119 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php' ); |
|
120 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php' ); |
|
121 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php' ); |
|
122 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
123 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
124 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
125 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php' ); |
|
126 | - if ( !class_exists( 'Geodir_EUVat' ) ) { |
|
127 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
103 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php'); |
|
104 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'); |
|
105 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'); |
|
106 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'); |
|
107 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'); |
|
108 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'); |
|
109 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'); |
|
110 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php'); |
|
111 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'); |
|
112 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'); |
|
113 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'); |
|
114 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'); |
|
115 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php'); |
|
116 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gd-functions.php'); |
|
117 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php'); |
|
118 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php'); |
|
119 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php'); |
|
120 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php'); |
|
121 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php'); |
|
122 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'); |
|
123 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'); |
|
124 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php'); |
|
125 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php'); |
|
126 | + if (!class_exists('Geodir_EUVat')) { |
|
127 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php'); |
|
128 | 128 | } |
129 | 129 | |
130 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
131 | - if ( !empty( $gateways ) ) { |
|
132 | - foreach ( $gateways as $gateway ) { |
|
133 | - if ( $gateway == 'manual' ) { |
|
130 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
131 | + if (!empty($gateways)) { |
|
132 | + foreach ($gateways as $gateway) { |
|
133 | + if ($gateway == 'manual') { |
|
134 | 134 | continue; |
135 | 135 | } |
136 | 136 | |
137 | 137 | $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php'; |
138 | 138 | |
139 | - if ( file_exists( $gateway_file ) ) { |
|
140 | - require_once( $gateway_file ); |
|
139 | + if (file_exists($gateway_file)) { |
|
140 | + require_once($gateway_file); |
|
141 | 141 | } |
142 | 142 | } |
143 | 143 | } |
144 | - require_once( WPINV_PLUGIN_DIR . 'includes/gateways/manual.php' ); |
|
145 | - |
|
146 | - if ( is_admin() ) { |
|
147 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
148 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php' ); |
|
149 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php' ); |
|
150 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php' ); |
|
151 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
152 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php' ); |
|
153 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
144 | + require_once(WPINV_PLUGIN_DIR . 'includes/gateways/manual.php'); |
|
145 | + |
|
146 | + if (is_admin()) { |
|
147 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'); |
|
148 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php'); |
|
149 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php'); |
|
150 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php'); |
|
151 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'); |
|
152 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php'); |
|
153 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | // include css inliner |
157 | - if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) { |
|
158 | - include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' ); |
|
157 | + if (!class_exists('Emogrifier') && class_exists('DOMDocument')) { |
|
158 | + include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php'); |
|
159 | 159 | } |
160 | 160 | |
161 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
161 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php'); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | public function init() { |
165 | 165 | } |
166 | 166 | |
167 | 167 | public function admin_init() { |
168 | - if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) { |
|
168 | + if (!(defined('DOING_AJAX') && DOING_AJAX)) { |
|
169 | 169 | } |
170 | 170 | |
171 | - add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) ); |
|
171 | + add_action('admin_print_scripts-edit.php', array(&$this, 'admin_print_scripts_edit_php')); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | public function activation_redirect() { |
175 | 175 | // Bail if no activation redirect |
176 | - if ( !get_transient( '_wpinv_activation_redirect' ) ) { |
|
176 | + if (!get_transient('_wpinv_activation_redirect')) { |
|
177 | 177 | return; |
178 | 178 | } |
179 | 179 | |
180 | 180 | // Delete the redirect transient |
181 | - delete_transient( '_wpinv_activation_redirect' ); |
|
181 | + delete_transient('_wpinv_activation_redirect'); |
|
182 | 182 | |
183 | 183 | // Bail if activating from network, or bulk |
184 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
184 | + if (is_network_admin() || isset($_GET['activate-multi'])) { |
|
185 | 185 | return; |
186 | 186 | } |
187 | 187 | |
188 | - wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
188 | + wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general')); |
|
189 | 189 | exit; |
190 | 190 | } |
191 | 191 | |
192 | 192 | public function enqueue_scripts() { |
193 | - $suffix = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
193 | + $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
194 | 194 | |
195 | - wp_deregister_style( 'font-awesome' ); |
|
196 | - wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' ); |
|
197 | - wp_enqueue_style( 'font-awesome' ); |
|
195 | + wp_deregister_style('font-awesome'); |
|
196 | + wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0'); |
|
197 | + wp_enqueue_style('font-awesome'); |
|
198 | 198 | |
199 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION ); |
|
200 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
199 | + wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION); |
|
200 | + wp_enqueue_style('wpinv_front_style'); |
|
201 | 201 | |
202 | 202 | // Register scripts |
203 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
204 | - wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array( 'jquery', 'wpinv-vat-script' ), WPINV_VERSION ); |
|
203 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
204 | + wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array('jquery', 'wpinv-vat-script'), WPINV_VERSION); |
|
205 | 205 | |
206 | 206 | $localize = array(); |
207 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
208 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
207 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
208 | + $localize['nonce'] = wp_create_nonce('wpinv-nonce'); |
|
209 | 209 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
210 | 210 | $localize['currency_pos'] = wpinv_currency_position(); |
211 | 211 | $localize['thousand_sep'] = wpinv_thousands_seperator(); |
212 | 212 | $localize['decimal_sep'] = wpinv_decimal_seperator(); |
213 | 213 | $localize['decimals'] = wpinv_decimals(); |
214 | 214 | |
215 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
215 | + $localize = apply_filters('wpinv_front_js_localize', $localize); |
|
216 | 216 | |
217 | - wp_enqueue_script( 'jquery-blockui' ); |
|
218 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
219 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
217 | + wp_enqueue_script('jquery-blockui'); |
|
218 | + wp_enqueue_script('wpinv-front-script'); |
|
219 | + wp_localize_script('wpinv-front-script', 'WPInv', $localize); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | public function admin_enqueue_scripts() { |
223 | 223 | global $post, $pagenow; |
224 | 224 | |
225 | 225 | $post_type = wpinv_admin_post_type(); |
226 | - $suffix = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
226 | + $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
227 | 227 | |
228 | - wp_deregister_style( 'font-awesome' ); |
|
229 | - wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' ); |
|
230 | - wp_enqueue_style( 'font-awesome' ); |
|
228 | + wp_deregister_style('font-awesome'); |
|
229 | + wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0'); |
|
230 | + wp_enqueue_style('font-awesome'); |
|
231 | 231 | |
232 | - wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' ); |
|
233 | - wp_enqueue_style( 'jquery-ui-css' ); |
|
232 | + wp_register_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16'); |
|
233 | + wp_enqueue_style('jquery-ui-css'); |
|
234 | 234 | |
235 | - wp_register_style( 'jquery-chosen', WPINV_PLUGIN_URL . 'assets/css/chosen' . $suffix . '.css', array(), '1.6.2' ); |
|
236 | - wp_enqueue_style( 'jquery-chosen' ); |
|
235 | + wp_register_style('jquery-chosen', WPINV_PLUGIN_URL . 'assets/css/chosen' . $suffix . '.css', array(), '1.6.2'); |
|
236 | + wp_enqueue_style('jquery-chosen'); |
|
237 | 237 | |
238 | - wp_register_script( 'jquery-chosen', WPINV_PLUGIN_URL . 'assets/js/chosen.jquery' . $suffix . '.js', array( 'jquery' ), '1.6.2' ); |
|
239 | - wp_enqueue_script( 'jquery-chosen' ); |
|
238 | + wp_register_script('jquery-chosen', WPINV_PLUGIN_URL . 'assets/js/chosen.jquery' . $suffix . '.js', array('jquery'), '1.6.2'); |
|
239 | + wp_enqueue_script('jquery-chosen'); |
|
240 | 240 | |
241 | - wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION ); |
|
242 | - wp_enqueue_style( 'wpinv_meta_box_style' ); |
|
241 | + wp_register_style('wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION); |
|
242 | + wp_enqueue_style('wpinv_meta_box_style'); |
|
243 | 243 | |
244 | - wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION ); |
|
245 | - wp_enqueue_style( 'wpinv_admin_style' ); |
|
244 | + wp_register_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION); |
|
245 | + wp_enqueue_style('wpinv_admin_style'); |
|
246 | 246 | |
247 | - if ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) { |
|
248 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
247 | + if ($post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
|
248 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
249 | 249 | } |
250 | 250 | |
251 | - wp_enqueue_style( 'wp-color-picker' ); |
|
252 | - wp_enqueue_script( 'wp-color-picker' ); |
|
251 | + wp_enqueue_style('wp-color-picker'); |
|
252 | + wp_enqueue_script('wp-color-picker'); |
|
253 | 253 | |
254 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
254 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
255 | 255 | |
256 | - wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array( 'jquery', 'jquery-blockui' ), WPINV_VERSION ); |
|
257 | - wp_enqueue_script( 'wpinv-admin-script' ); |
|
256 | + wp_register_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array('jquery', 'jquery-blockui'), WPINV_VERSION); |
|
257 | + wp_enqueue_script('wpinv-admin-script'); |
|
258 | 258 | |
259 | 259 | $localize = array(); |
260 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
261 | - $localize['post_ID'] = isset( $post->ID ) ? $post->ID : ''; |
|
262 | - $localize['wpinv_nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
263 | - $localize['add_invoice_note_nonce'] = wp_create_nonce( 'add-invoice-note' ); |
|
264 | - $localize['delete_invoice_note_nonce'] = wp_create_nonce( 'delete-invoice-note' ); |
|
265 | - $localize['invoice_item_nonce'] = wp_create_nonce( 'invoice-item' ); |
|
266 | - $localize['billing_details_nonce'] = wp_create_nonce( 'get-billing-details' ); |
|
260 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
261 | + $localize['post_ID'] = isset($post->ID) ? $post->ID : ''; |
|
262 | + $localize['wpinv_nonce'] = wp_create_nonce('wpinv-nonce'); |
|
263 | + $localize['add_invoice_note_nonce'] = wp_create_nonce('add-invoice-note'); |
|
264 | + $localize['delete_invoice_note_nonce'] = wp_create_nonce('delete-invoice-note'); |
|
265 | + $localize['invoice_item_nonce'] = wp_create_nonce('invoice-item'); |
|
266 | + $localize['billing_details_nonce'] = wp_create_nonce('get-billing-details'); |
|
267 | 267 | $localize['tax'] = wpinv_tax_amount(); |
268 | 268 | $localize['discount'] = wpinv_discount_amount(); |
269 | 269 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
@@ -271,55 +271,55 @@ discard block |
||
271 | 271 | $localize['thousand_sep'] = wpinv_thousands_seperator(); |
272 | 272 | $localize['decimal_sep'] = wpinv_decimal_seperator(); |
273 | 273 | $localize['decimals'] = wpinv_decimals(); |
274 | - $localize['save_invoice'] = __( 'Save Invoice', 'invoicing' ); |
|
275 | - $localize['status_publish'] = wpinv_status_nicename( 'publish' ); |
|
276 | - $localize['status_pending'] = wpinv_status_nicename( 'pending' ); |
|
277 | - $localize['delete_tax_rate'] = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ); |
|
278 | - $localize['OneItemMin'] = __( 'Invoice must contain at least one item', 'invoicing' ); |
|
279 | - $localize['DeleteInvoiceItem'] = __( 'Are you sure you wish to delete this item?', 'invoicing' ); |
|
280 | - $localize['FillBillingDetails'] = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ); |
|
281 | - $localize['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' ); |
|
282 | - $localize['AreYouSure'] = __( 'Are you sure?', 'invoicing' ); |
|
283 | - $localize['hasGD'] = wpinv_gd_active();; |
|
274 | + $localize['save_invoice'] = __('Save Invoice', 'invoicing'); |
|
275 | + $localize['status_publish'] = wpinv_status_nicename('publish'); |
|
276 | + $localize['status_pending'] = wpinv_status_nicename('pending'); |
|
277 | + $localize['delete_tax_rate'] = __('Are you sure you wish to delete this tax rate?', 'invoicing'); |
|
278 | + $localize['OneItemMin'] = __('Invoice must contain at least one item', 'invoicing'); |
|
279 | + $localize['DeleteInvoiceItem'] = __('Are you sure you wish to delete this item?', 'invoicing'); |
|
280 | + $localize['FillBillingDetails'] = __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'); |
|
281 | + $localize['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'); |
|
282 | + $localize['AreYouSure'] = __('Are you sure?', 'invoicing'); |
|
283 | + $localize['hasGD'] = wpinv_gd_active(); ; |
|
284 | 284 | $localize['hasPM'] = wpinv_pm_active(); |
285 | - $localize['emptyInvoice'] = __( 'Add atleast one item to save invoice!', 'invoicing' ); |
|
286 | - $localize['deletePackage'] = __( 'GD package items should be deleted from GD payment manager only, otherwise it will break invoices that created with this package!', 'invoicing' ); |
|
287 | - $localize['deletePackages'] = __( 'GD package items should be deleted from GD payment manager only', 'invoicing' ); |
|
288 | - $localize['deleteInvoiceFirst'] = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ); |
|
285 | + $localize['emptyInvoice'] = __('Add atleast one item to save invoice!', 'invoicing'); |
|
286 | + $localize['deletePackage'] = __('GD package items should be deleted from GD payment manager only, otherwise it will break invoices that created with this package!', 'invoicing'); |
|
287 | + $localize['deletePackages'] = __('GD package items should be deleted from GD payment manager only', 'invoicing'); |
|
288 | + $localize['deleteInvoiceFirst'] = __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'); |
|
289 | 289 | |
290 | - wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize ); |
|
290 | + wp_localize_script('wpinv-admin-script', 'WPInv_Admin', $localize); |
|
291 | 291 | } |
292 | 292 | |
293 | - public function admin_body_class( $classes ) { |
|
293 | + public function admin_body_class($classes) { |
|
294 | 294 | global $pagenow; |
295 | 295 | |
296 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false; |
|
296 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : false; |
|
297 | 297 | |
298 | 298 | $add_class = false; |
299 | - if ( $pagenow == 'admin.php' && $page ) { |
|
300 | - $add_class = strpos( $page, 'wpinv-' ); |
|
299 | + if ($pagenow == 'admin.php' && $page) { |
|
300 | + $add_class = strpos($page, 'wpinv-'); |
|
301 | 301 | } |
302 | 302 | |
303 | 303 | $settings_class = array(); |
304 | - if ( $page == 'wpinv-settings' ) { |
|
305 | - if ( !empty( $_REQUEST['tab'] ) ) { |
|
306 | - $settings_class[] = sanitize_text_field( $_REQUEST['tab'] ); |
|
304 | + if ($page == 'wpinv-settings') { |
|
305 | + if (!empty($_REQUEST['tab'])) { |
|
306 | + $settings_class[] = sanitize_text_field($_REQUEST['tab']); |
|
307 | 307 | } |
308 | 308 | |
309 | - if ( !empty( $_REQUEST['section'] ) ) { |
|
310 | - $settings_class[] = sanitize_text_field( $_REQUEST['section'] ); |
|
309 | + if (!empty($_REQUEST['section'])) { |
|
310 | + $settings_class[] = sanitize_text_field($_REQUEST['section']); |
|
311 | 311 | } |
312 | 312 | |
313 | - $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main'; |
|
313 | + $settings_class[] = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field($_REQUEST['wpi_sub']) : 'main'; |
|
314 | 314 | } |
315 | 315 | |
316 | - if ( !empty( $settings_class ) ) { |
|
317 | - $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) ); |
|
316 | + if (!empty($settings_class)) { |
|
317 | + $classes .= ' wpi-' . wpinv_sanitize_key(implode($settings_class, '-')); |
|
318 | 318 | } |
319 | 319 | |
320 | 320 | $post_type = wpinv_admin_post_type(); |
321 | 321 | |
322 | - if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) { |
|
322 | + if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false) { |
|
323 | 323 | return $classes .= ' wpinv'; |
324 | 324 | } else { |
325 | 325 | return $classes; |
@@ -331,26 +331,26 @@ discard block |
||
331 | 331 | public function admin_print_scripts_edit_php() { |
332 | 332 | $post_type = wpinv_admin_post_type(); |
333 | 333 | |
334 | - if ( $post_type == 'wpi_item' ) { |
|
335 | - wp_enqueue_script( 'wpinv-inline-edit-post', WPINV_PLUGIN_URL . 'assets/js/quick-edit.js', array( 'jquery', 'inline-edit-post' ), '', true ); |
|
334 | + if ($post_type == 'wpi_item') { |
|
335 | + wp_enqueue_script('wpinv-inline-edit-post', WPINV_PLUGIN_URL . 'assets/js/quick-edit.js', array('jquery', 'inline-edit-post'), '', true); |
|
336 | 336 | } |
337 | 337 | } |
338 | 338 | |
339 | 339 | public function wpinv_actions() { |
340 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
341 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
340 | + if (isset($_REQUEST['wpi_action'])) { |
|
341 | + do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST); |
|
342 | 342 | } |
343 | 343 | } |
344 | 344 | |
345 | - public function pre_get_posts( $wp_query ) { |
|
346 | - if ( !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() ) { |
|
347 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
345 | + public function pre_get_posts($wp_query) { |
|
346 | + if (!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()) { |
|
347 | + $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses()); |
|
348 | 348 | } |
349 | 349 | |
350 | 350 | return $wp_query; |
351 | 351 | } |
352 | 352 | |
353 | 353 | public function bp_invoicing_init() { |
354 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
354 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php'); |
|
355 | 355 | } |
356 | 356 | } |
357 | 357 | \ No newline at end of file |
@@ -1,65 +1,65 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // MUST have WordPress. |
3 | -if ( !defined( 'WPINC' ) ) { |
|
4 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
3 | +if (!defined('WPINC')) { |
|
4 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
5 | 5 | } |
6 | 6 | |
7 | -function wpinv_add_meta_boxes( $post_type, $post ) { |
|
7 | +function wpinv_add_meta_boxes($post_type, $post) { |
|
8 | 8 | global $wpi_mb_invoice; |
9 | - if ( $post_type == 'wpi_invoice' && !empty( $post->ID ) ) { |
|
10 | - $wpi_mb_invoice = wpinv_get_invoice( $post->ID ); |
|
9 | + if ($post_type == 'wpi_invoice' && !empty($post->ID)) { |
|
10 | + $wpi_mb_invoice = wpinv_get_invoice($post->ID); |
|
11 | 11 | } |
12 | 12 | |
13 | - if ( !empty( $wpi_mb_invoice ) && !$wpi_mb_invoice->has_status( array( 'draft', 'auto-draft' ) ) ) { |
|
14 | - add_meta_box( 'wpinv-mb-resend-invoice', __( 'Resend Invoice', 'invoicing' ), 'WPInv_Meta_Box_Details::resend_invoice', 'wpi_invoice', 'side', 'high' ); |
|
13 | + if (!empty($wpi_mb_invoice) && !$wpi_mb_invoice->has_status(array('draft', 'auto-draft'))) { |
|
14 | + add_meta_box('wpinv-mb-resend-invoice', __('Resend Invoice', 'invoicing'), 'WPInv_Meta_Box_Details::resend_invoice', 'wpi_invoice', 'side', 'high'); |
|
15 | 15 | } |
16 | 16 | |
17 | - if ( !empty( $wpi_mb_invoice ) && $wpi_mb_invoice->is_recurring() && $wpi_mb_invoice->is_parent() ) { |
|
18 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscriptions', 'invoicing' ), 'WPInv_Meta_Box_Details::subscriptions', 'wpi_invoice', 'side', 'high' ); |
|
17 | + if (!empty($wpi_mb_invoice) && $wpi_mb_invoice->is_recurring() && $wpi_mb_invoice->is_parent()) { |
|
18 | + add_meta_box('wpinv-mb-subscriptions', __('Subscriptions', 'invoicing'), 'WPInv_Meta_Box_Details::subscriptions', 'wpi_invoice', 'side', 'high'); |
|
19 | 19 | } |
20 | 20 | |
21 | - if ( wpinv_is_subscription_payment( $wpi_mb_invoice ) ) { |
|
22 | - add_meta_box( 'wpinv-mb-renewals', __( 'Renewal Payment', 'invoicing' ), 'WPInv_Meta_Box_Details::renewals', 'wpi_invoice', 'side', 'high' ); |
|
21 | + if (wpinv_is_subscription_payment($wpi_mb_invoice)) { |
|
22 | + add_meta_box('wpinv-mb-renewals', __('Renewal Payment', 'invoicing'), 'WPInv_Meta_Box_Details::renewals', 'wpi_invoice', 'side', 'high'); |
|
23 | 23 | } |
24 | 24 | |
25 | - add_meta_box( 'wpinv-details', __( 'Invoice Details', 'invoicing' ), 'WPInv_Meta_Box_Details::output', 'wpi_invoice', 'side', 'default' ); |
|
26 | - add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'WPInv_Meta_Box_Details::payment_meta', 'wpi_invoice', 'side', 'default' ); |
|
25 | + add_meta_box('wpinv-details', __('Invoice Details', 'invoicing'), 'WPInv_Meta_Box_Details::output', 'wpi_invoice', 'side', 'default'); |
|
26 | + add_meta_box('wpinv-payment-meta', __('Payment Meta', 'invoicing'), 'WPInv_Meta_Box_Details::payment_meta', 'wpi_invoice', 'side', 'default'); |
|
27 | 27 | |
28 | - add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'WPInv_Meta_Box_Billing_Details::output', 'wpi_invoice', 'normal', 'high' ); |
|
29 | - add_meta_box( 'wpinv-items', __( 'Invoice Items', 'invoicing' ), 'WPInv_Meta_Box_Items::output', 'wpi_invoice', 'normal', 'high' ); |
|
30 | - add_meta_box( 'wpinv-notes', __( 'Invoice Notes', 'invoicing' ), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high' ); |
|
28 | + add_meta_box('wpinv-address', __('Billing Details', 'invoicing'), 'WPInv_Meta_Box_Billing_Details::output', 'wpi_invoice', 'normal', 'high'); |
|
29 | + add_meta_box('wpinv-items', __('Invoice Items', 'invoicing'), 'WPInv_Meta_Box_Items::output', 'wpi_invoice', 'normal', 'high'); |
|
30 | + add_meta_box('wpinv-notes', __('Invoice Notes', 'invoicing'), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high'); |
|
31 | 31 | } |
32 | -add_action( 'add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2 ); |
|
32 | +add_action('add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2); |
|
33 | 33 | |
34 | -function wpinv_save_meta_boxes( $post_id, $post, $update = false ) { |
|
35 | - remove_action( 'save_post', __FUNCTION__ ); |
|
34 | +function wpinv_save_meta_boxes($post_id, $post, $update = false) { |
|
35 | + remove_action('save_post', __FUNCTION__); |
|
36 | 36 | |
37 | 37 | // $post_id and $post are required |
38 | - if ( empty( $post_id ) || empty( $post ) ) { |
|
38 | + if (empty($post_id) || empty($post)) { |
|
39 | 39 | return; |
40 | 40 | } |
41 | 41 | |
42 | - if ( !current_user_can( 'edit_post', $post_id ) || empty( $post->post_type ) ) { |
|
42 | + if (!current_user_can('edit_post', $post_id) || empty($post->post_type)) { |
|
43 | 43 | return; |
44 | 44 | } |
45 | 45 | |
46 | 46 | // Dont' save meta boxes for revisions or autosaves |
47 | - if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
47 | + if (defined('DOING_AUTOSAVE') || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) { |
|
48 | 48 | return; |
49 | 49 | } |
50 | 50 | |
51 | - if ( $post->post_type == 'wpi_invoice' or $post->post_type == 'wpi_quote' ) { |
|
52 | - if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
51 | + if ($post->post_type == 'wpi_invoice' or $post->post_type == 'wpi_quote') { |
|
52 | + if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) { |
|
53 | 53 | return; |
54 | 54 | } |
55 | 55 | |
56 | - if ( isset( $_POST['wpinv_save_invoice'] ) && wp_verify_nonce( $_POST['wpinv_save_invoice'], 'wpinv_save_invoice' ) ) { |
|
57 | - WPInv_Meta_Box_Items::save( $post_id, $_POST, $post ); |
|
56 | + if (isset($_POST['wpinv_save_invoice']) && wp_verify_nonce($_POST['wpinv_save_invoice'], 'wpinv_save_invoice')) { |
|
57 | + WPInv_Meta_Box_Items::save($post_id, $_POST, $post); |
|
58 | 58 | } |
59 | - } else if ( $post->post_type == 'wpi_item' ) { |
|
59 | + } else if ($post->post_type == 'wpi_item') { |
|
60 | 60 | // verify nonce |
61 | - if ( isset( $_POST['wpinv_vat_meta_box_nonce'] ) && wp_verify_nonce( $_POST['wpinv_vat_meta_box_nonce'], 'wpinv_item_meta_box_save' ) ) { |
|
62 | - $fields = array(); |
|
61 | + if (isset($_POST['wpinv_vat_meta_box_nonce']) && wp_verify_nonce($_POST['wpinv_vat_meta_box_nonce'], 'wpinv_item_meta_box_save')) { |
|
62 | + $fields = array(); |
|
63 | 63 | $fields['_wpinv_price'] = 'wpinv_item_price'; |
64 | 64 | $fields['_wpinv_vat_class'] = 'wpinv_vat_class'; |
65 | 65 | $fields['_wpinv_vat_rule'] = 'wpinv_vat_rules'; |
@@ -72,291 +72,291 @@ discard block |
||
72 | 72 | $fields['_wpinv_trial_period'] = 'wpinv_trial_period'; |
73 | 73 | $fields['_wpinv_trial_interval'] = 'wpinv_trial_interval'; |
74 | 74 | |
75 | - if ( !isset( $_POST['wpinv_is_recurring'] ) ) { |
|
75 | + if (!isset($_POST['wpinv_is_recurring'])) { |
|
76 | 76 | $_POST['wpinv_is_recurring'] = 0; |
77 | 77 | } |
78 | 78 | |
79 | - if ( !isset( $_POST['wpinv_free_trial'] ) || empty( $_POST['wpinv_is_recurring'] ) ) { |
|
79 | + if (!isset($_POST['wpinv_free_trial']) || empty($_POST['wpinv_is_recurring'])) { |
|
80 | 80 | $_POST['wpinv_free_trial'] = 0; |
81 | 81 | } |
82 | 82 | |
83 | - foreach ( $fields as $field => $name ) { |
|
84 | - if ( isset( $_POST[ $name ] ) ) { |
|
85 | - if ( $field == '_wpinv_price' ) { |
|
86 | - if ( get_post_meta( $post_id, '_wpinv_type', true ) === 'package' ) { |
|
87 | - $value = wpinv_sanitize_amount( get_post_meta( $post_id, '_wpinv_price', true ) ); // Don't allow edit GD package item price. |
|
83 | + foreach ($fields as $field => $name) { |
|
84 | + if (isset($_POST[$name])) { |
|
85 | + if ($field == '_wpinv_price') { |
|
86 | + if (get_post_meta($post_id, '_wpinv_type', true) === 'package') { |
|
87 | + $value = wpinv_sanitize_amount(get_post_meta($post_id, '_wpinv_price', true)); // Don't allow edit GD package item price. |
|
88 | 88 | } else { |
89 | - $value = wpinv_sanitize_amount( $_POST[ $name ] ); |
|
89 | + $value = wpinv_sanitize_amount($_POST[$name]); |
|
90 | 90 | } |
91 | 91 | } else { |
92 | - $value = is_string( $_POST[ $name ] ) ? sanitize_text_field( $_POST[ $name ] ) : $_POST[ $name ]; |
|
92 | + $value = is_string($_POST[$name]) ? sanitize_text_field($_POST[$name]) : $_POST[$name]; |
|
93 | 93 | } |
94 | 94 | |
95 | - $value = apply_filters( 'wpinv_item_metabox_save_' . $field, $value, $name ); |
|
96 | - update_post_meta( $post_id, $field, $value ); |
|
95 | + $value = apply_filters('wpinv_item_metabox_save_' . $field, $value, $name); |
|
96 | + update_post_meta($post_id, $field, $value); |
|
97 | 97 | } |
98 | 98 | } |
99 | 99 | } |
100 | 100 | } |
101 | 101 | } |
102 | -add_action( 'save_post', 'wpinv_save_meta_boxes', 10, 3 ); |
|
102 | +add_action('save_post', 'wpinv_save_meta_boxes', 10, 3); |
|
103 | 103 | |
104 | -function wpinv_bulk_and_quick_edit_save( $post_id, $post, $update = false ) { |
|
105 | - if ( !( !empty( $_POST['action'] ) && $_POST['action'] == 'inline-save' ) ) { |
|
104 | +function wpinv_bulk_and_quick_edit_save($post_id, $post, $update = false) { |
|
105 | + if (!(!empty($_POST['action']) && $_POST['action'] == 'inline-save')) { |
|
106 | 106 | return; |
107 | 107 | } |
108 | 108 | |
109 | 109 | // $post_id and $post are required |
110 | - if ( empty( $post_id ) || empty( $post ) ) { |
|
110 | + if (empty($post_id) || empty($post)) { |
|
111 | 111 | return; |
112 | 112 | } |
113 | 113 | |
114 | - if ( !current_user_can( 'edit_post', $post_id ) || empty( $post->post_type ) ) { |
|
114 | + if (!current_user_can('edit_post', $post_id) || empty($post->post_type)) { |
|
115 | 115 | return; |
116 | 116 | } |
117 | 117 | |
118 | 118 | // Dont' save meta boxes for revisions or autosaves |
119 | - if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
119 | + if (defined('DOING_AUTOSAVE') || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) { |
|
120 | 120 | return; |
121 | 121 | } |
122 | 122 | |
123 | - if ( $post->post_type == 'wpi_item' ) { |
|
123 | + if ($post->post_type == 'wpi_item') { |
|
124 | 124 | // verify nonce |
125 | - if ( isset( $_POST['_wpinv_item_price'] ) && get_post_meta( $post->ID, '_wpinv_type', true ) !== 'package' ) { |
|
126 | - update_post_meta( $post_id, '_wpinv_price', wpinv_sanitize_amount( $_POST['_wpinv_item_price'] ) ); |
|
125 | + if (isset($_POST['_wpinv_item_price']) && get_post_meta($post->ID, '_wpinv_type', true) !== 'package') { |
|
126 | + update_post_meta($post_id, '_wpinv_price', wpinv_sanitize_amount($_POST['_wpinv_item_price'])); |
|
127 | 127 | } |
128 | 128 | |
129 | - if ( isset( $_POST['_wpinv_vat_class'] ) ) { |
|
130 | - update_post_meta( $post_id, '_wpinv_vat_class', sanitize_text_field( $_POST['_wpinv_vat_class'] ) ); |
|
129 | + if (isset($_POST['_wpinv_vat_class'])) { |
|
130 | + update_post_meta($post_id, '_wpinv_vat_class', sanitize_text_field($_POST['_wpinv_vat_class'])); |
|
131 | 131 | } |
132 | 132 | |
133 | - if ( isset( $_POST['_wpinv_vat_rules'] ) ) { |
|
134 | - update_post_meta( $post_id, '_wpinv_vat_rule', sanitize_text_field( $_POST['_wpinv_vat_rules'] ) ); |
|
133 | + if (isset($_POST['_wpinv_vat_rules'])) { |
|
134 | + update_post_meta($post_id, '_wpinv_vat_rule', sanitize_text_field($_POST['_wpinv_vat_rules'])); |
|
135 | 135 | } |
136 | 136 | |
137 | - if ( isset( $_POST['_wpinv_item_type'] ) ) { |
|
138 | - update_post_meta( $post_id, '_wpinv_type', sanitize_text_field( $_POST['_wpinv_item_type'] ) ); |
|
137 | + if (isset($_POST['_wpinv_item_type'])) { |
|
138 | + update_post_meta($post_id, '_wpinv_type', sanitize_text_field($_POST['_wpinv_item_type'])); |
|
139 | 139 | } |
140 | 140 | } |
141 | 141 | } |
142 | -add_action( 'save_post', 'wpinv_bulk_and_quick_edit_save', 10, 3 ); |
|
142 | +add_action('save_post', 'wpinv_bulk_and_quick_edit_save', 10, 3); |
|
143 | 143 | |
144 | 144 | function wpinv_register_item_meta_boxes() { |
145 | 145 | global $wpinv_euvat; |
146 | 146 | |
147 | - add_meta_box( 'wpinv_field_prices', __( 'Item Price', 'invoicing' ), 'WPInv_Meta_Box_Items::prices', 'wpi_item', 'normal', 'high' ); |
|
147 | + add_meta_box('wpinv_field_prices', __('Item Price', 'invoicing'), 'WPInv_Meta_Box_Items::prices', 'wpi_item', 'normal', 'high'); |
|
148 | 148 | |
149 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
150 | - add_meta_box( 'wpinv_field_vat_rules', __( 'VAT rules type to use', 'invoicing' ), 'WPInv_Meta_Box_Items::vat_rules', 'wpi_item', 'normal', 'high' ); |
|
149 | + if ($wpinv_euvat->allow_vat_rules()) { |
|
150 | + add_meta_box('wpinv_field_vat_rules', __('VAT rules type to use', 'invoicing'), 'WPInv_Meta_Box_Items::vat_rules', 'wpi_item', 'normal', 'high'); |
|
151 | 151 | } |
152 | 152 | |
153 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
154 | - add_meta_box( 'wpinv_field_vat_classes', __( 'VAT rates class to use', 'invoicing' ), 'WPInv_Meta_Box_Items::vat_classes', 'wpi_item', 'normal', 'high' ); |
|
153 | + if ($wpinv_euvat->allow_vat_classes()) { |
|
154 | + add_meta_box('wpinv_field_vat_classes', __('VAT rates class to use', 'invoicing'), 'WPInv_Meta_Box_Items::vat_classes', 'wpi_item', 'normal', 'high'); |
|
155 | 155 | } |
156 | 156 | |
157 | - add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'WPInv_Meta_Box_Items::item_info', 'wpi_item', 'side', 'core' ); |
|
157 | + add_meta_box('wpinv_field_item_info', __('Item info', 'invoicing'), 'WPInv_Meta_Box_Items::item_info', 'wpi_item', 'side', 'core'); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | function wpinv_register_discount_meta_boxes() { |
161 | - add_meta_box( 'wpinv_discount_fields', __( 'Discount Details', 'invoicing' ), 'wpinv_discount_metabox_details', 'wpi_discount', 'normal', 'high' ); |
|
161 | + add_meta_box('wpinv_discount_fields', __('Discount Details', 'invoicing'), 'wpinv_discount_metabox_details', 'wpi_discount', 'normal', 'high'); |
|
162 | 162 | } |
163 | 163 | |
164 | -function wpinv_discount_metabox_details( $post ) { |
|
164 | +function wpinv_discount_metabox_details($post) { |
|
165 | 165 | $discount_id = $post->ID; |
166 | - $discount = wpinv_get_discount( $discount_id ); |
|
166 | + $discount = wpinv_get_discount($discount_id); |
|
167 | 167 | |
168 | - $type = wpinv_get_discount_type( $discount_id ); |
|
169 | - $item_reqs = wpinv_get_discount_item_reqs( $discount_id ); |
|
170 | - $excluded_items = wpinv_get_discount_excluded_items( $discount_id ); |
|
171 | - $min_total = wpinv_get_discount_min_total( $discount_id ); |
|
172 | - $max_total = wpinv_get_discount_max_total( $discount_id ); |
|
173 | - $max_uses = wpinv_get_discount_max_uses( $discount_id ); |
|
174 | - $single_use = wpinv_discount_is_single_use( $discount_id ); |
|
175 | - $recurring = (bool)wpinv_discount_is_recurring( $discount_id ); |
|
168 | + $type = wpinv_get_discount_type($discount_id); |
|
169 | + $item_reqs = wpinv_get_discount_item_reqs($discount_id); |
|
170 | + $excluded_items = wpinv_get_discount_excluded_items($discount_id); |
|
171 | + $min_total = wpinv_get_discount_min_total($discount_id); |
|
172 | + $max_total = wpinv_get_discount_max_total($discount_id); |
|
173 | + $max_uses = wpinv_get_discount_max_uses($discount_id); |
|
174 | + $single_use = wpinv_discount_is_single_use($discount_id); |
|
175 | + $recurring = (bool)wpinv_discount_is_recurring($discount_id); |
|
176 | 176 | |
177 | 177 | $min_total = $min_total > 0 ? $min_total : ''; |
178 | 178 | $max_total = $max_total > 0 ? $max_total : ''; |
179 | 179 | $max_uses = $max_uses > 0 ? $max_uses : ''; |
180 | 180 | ?> |
181 | -<?php do_action( 'wpinv_discount_form_top', $post ); ?> |
|
182 | -<?php wp_nonce_field( 'wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce' ); ;?> |
|
181 | +<?php do_action('wpinv_discount_form_top', $post); ?> |
|
182 | +<?php wp_nonce_field('wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce'); ;?> |
|
183 | 183 | <table class="form-table wpi-form-table"> |
184 | 184 | <tbody> |
185 | - <?php do_action( 'wpinv_discount_form_first', $post ); ?> |
|
186 | - <?php do_action( 'wpinv_discount_form_before_code', $post ); ?> |
|
185 | + <?php do_action('wpinv_discount_form_first', $post); ?> |
|
186 | + <?php do_action('wpinv_discount_form_before_code', $post); ?> |
|
187 | 187 | <tr> |
188 | 188 | <th valign="top" scope="row"> |
189 | - <label for="wpinv_discount_code"><?php _e( 'Discount Code', 'invoicing' ); ?></label> |
|
189 | + <label for="wpinv_discount_code"><?php _e('Discount Code', 'invoicing'); ?></label> |
|
190 | 190 | </th> |
191 | 191 | <td> |
192 | - <input type="text" name="code" id="wpinv_discount_code" class="medium-text" value="<?php echo esc_attr( wpinv_get_discount_code( $discount_id ) ); ?>" required> |
|
193 | - <p class="description"><?php _e( 'Enter a code for this discount, such as 10OFF', 'invoicing' ); ?></p> |
|
192 | + <input type="text" name="code" id="wpinv_discount_code" class="medium-text" value="<?php echo esc_attr(wpinv_get_discount_code($discount_id)); ?>" required> |
|
193 | + <p class="description"><?php _e('Enter a code for this discount, such as 10OFF', 'invoicing'); ?></p> |
|
194 | 194 | </td> |
195 | 195 | </tr> |
196 | - <?php do_action( 'wpinv_discount_form_before_type', $post ); ?> |
|
196 | + <?php do_action('wpinv_discount_form_before_type', $post); ?> |
|
197 | 197 | <tr> |
198 | 198 | <th valign="top" scope="row"> |
199 | - <label for="wpinv_discount_type"><?php _e( 'Discount Type', 'invoicing' ); ?></label> |
|
199 | + <label for="wpinv_discount_type"><?php _e('Discount Type', 'invoicing'); ?></label> |
|
200 | 200 | </th> |
201 | 201 | <td> |
202 | 202 | <select id="wpinv_discount_type" name="type" class="medium-text"> |
203 | - <?php foreach ( wpinv_get_discount_types() as $value => $label ) { ?> |
|
204 | - <option value="<?php echo $value ;?>" <?php selected( $type, $value ); ?>><?php echo $label; ?></option> |
|
203 | + <?php foreach (wpinv_get_discount_types() as $value => $label) { ?> |
|
204 | + <option value="<?php echo $value; ?>" <?php selected($type, $value); ?>><?php echo $label; ?></option> |
|
205 | 205 | <?php } ?> |
206 | 206 | </select> |
207 | - <p class="description"><?php _e( 'The kind of discount to apply for this discount.', 'invoicing' ); ?></p> |
|
207 | + <p class="description"><?php _e('The kind of discount to apply for this discount.', 'invoicing'); ?></p> |
|
208 | 208 | </td> |
209 | 209 | </tr> |
210 | - <?php do_action( 'wpinv_discount_form_before_amount', $post ); ?> |
|
210 | + <?php do_action('wpinv_discount_form_before_amount', $post); ?> |
|
211 | 211 | <tr> |
212 | 212 | <th valign="top" scope="row"> |
213 | - <label for="wpinv_discount_amount"><?php _e( 'Amount', 'invoicing' ); ?></label> |
|
213 | + <label for="wpinv_discount_amount"><?php _e('Amount', 'invoicing'); ?></label> |
|
214 | 214 | </th> |
215 | 215 | <td> |
216 | - <input type="text" name="amount" id="wpinv_discount_amount" class="wpi-field-price wpi-price" value="<?php echo esc_attr( wpinv_get_discount_amount( $discount_id ) ); ?>" required> <font class="wpi-discount-p">%</font><font class="wpi-discount-f" style="display:none;"><?php echo wpinv_currency_symbol() ;?></font> |
|
217 | - <p style="display:none;" class="description"><?php _e( 'Enter the discount amount in USD', 'invoicing' ); ?></p> |
|
218 | - <p class="description"><?php _e( 'Enter the discount value. Ex: 10', 'invoicing' ); ?></p> |
|
216 | + <input type="text" name="amount" id="wpinv_discount_amount" class="wpi-field-price wpi-price" value="<?php echo esc_attr(wpinv_get_discount_amount($discount_id)); ?>" required> <font class="wpi-discount-p">%</font><font class="wpi-discount-f" style="display:none;"><?php echo wpinv_currency_symbol(); ?></font> |
|
217 | + <p style="display:none;" class="description"><?php _e('Enter the discount amount in USD', 'invoicing'); ?></p> |
|
218 | + <p class="description"><?php _e('Enter the discount value. Ex: 10', 'invoicing'); ?></p> |
|
219 | 219 | </td> |
220 | 220 | </tr> |
221 | - <?php do_action( 'wpinv_discount_form_before_items', $post ); ?> |
|
221 | + <?php do_action('wpinv_discount_form_before_items', $post); ?> |
|
222 | 222 | <tr> |
223 | 223 | <th valign="top" scope="row"> |
224 | - <label for="wpinv_discount_items"><?php _e( 'Items', 'invoicing' ); ?></label> |
|
224 | + <label for="wpinv_discount_items"><?php _e('Items', 'invoicing'); ?></label> |
|
225 | 225 | </th> |
226 | 226 | <td> |
227 | - <p><?php echo wpinv_item_dropdown( array( |
|
227 | + <p><?php echo wpinv_item_dropdown(array( |
|
228 | 228 | 'name' => 'items[]', |
229 | 229 | 'id' => 'items', |
230 | 230 | 'selected' => $item_reqs, |
231 | 231 | 'multiple' => true, |
232 | 232 | 'chosen' => true, |
233 | 233 | 'class' => 'medium-text', |
234 | - 'placeholder' => __( 'Select one or more Items', 'invoicing' ), |
|
234 | + 'placeholder' => __('Select one or more Items', 'invoicing'), |
|
235 | 235 | 'show_recurring' => true, |
236 | - ) ); ?> |
|
236 | + )); ?> |
|
237 | 237 | </p> |
238 | - <p class="description"><?php _e( 'Items which need to be in the cart to use this discount or, for "Item Discounts", which items are discounted. If left blank, this discount can be used on any item.', 'invoicing' ); ?></p> |
|
238 | + <p class="description"><?php _e('Items which need to be in the cart to use this discount or, for "Item Discounts", which items are discounted. If left blank, this discount can be used on any item.', 'invoicing'); ?></p> |
|
239 | 239 | </td> |
240 | 240 | </tr> |
241 | - <?php do_action( 'wpinv_discount_form_before_excluded_items', $post ); ?> |
|
241 | + <?php do_action('wpinv_discount_form_before_excluded_items', $post); ?> |
|
242 | 242 | <tr> |
243 | 243 | <th valign="top" scope="row"> |
244 | - <label for="wpinv_discount_excluded_items"><?php _e( 'Excluded Items', 'invoicing' ); ?></label> |
|
244 | + <label for="wpinv_discount_excluded_items"><?php _e('Excluded Items', 'invoicing'); ?></label> |
|
245 | 245 | </th> |
246 | 246 | <td> |
247 | - <p><?php echo wpinv_item_dropdown( array( |
|
247 | + <p><?php echo wpinv_item_dropdown(array( |
|
248 | 248 | 'name' => 'excluded_items[]', |
249 | 249 | 'id' => 'excluded_items', |
250 | 250 | 'selected' => $excluded_items, |
251 | 251 | 'multiple' => true, |
252 | 252 | 'chosen' => true, |
253 | 253 | 'class' => 'medium-text', |
254 | - 'placeholder' => __( 'Select one or more Items', 'invoicing' ), |
|
254 | + 'placeholder' => __('Select one or more Items', 'invoicing'), |
|
255 | 255 | 'show_recurring' => true, |
256 | - ) ); ?> |
|
256 | + )); ?> |
|
257 | 257 | </p> |
258 | - <p class="description"><?php _e( 'Items which are NOT allowed to use this discount.', 'invoicing' ); ?></p> |
|
258 | + <p class="description"><?php _e('Items which are NOT allowed to use this discount.', 'invoicing'); ?></p> |
|
259 | 259 | </td> |
260 | 260 | </tr> |
261 | - <?php do_action( 'wpinv_discount_form_before_start', $post ); ?> |
|
261 | + <?php do_action('wpinv_discount_form_before_start', $post); ?> |
|
262 | 262 | <tr> |
263 | 263 | <th valign="top" scope="row"> |
264 | - <label for="wpinv_discount_start"><?php _e( 'Start date', 'invoicing' ); ?></label> |
|
264 | + <label for="wpinv_discount_start"><?php _e('Start date', 'invoicing'); ?></label> |
|
265 | 265 | </th> |
266 | 266 | <td> |
267 | - <input type="text" class="medium-text wpiDatepicker" id="wpinv_discount_start" data-dateFormat="yy-mm-dd" name="start" value="<?php echo esc_attr( wpinv_get_discount_start_date( $discount_id ) ); ?>"> |
|
268 | - <p class="description"><?php _e( 'Enter the start date for this discount code in the format of yyyy-mm-dd. For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing' ); ?></p> |
|
267 | + <input type="text" class="medium-text wpiDatepicker" id="wpinv_discount_start" data-dateFormat="yy-mm-dd" name="start" value="<?php echo esc_attr(wpinv_get_discount_start_date($discount_id)); ?>"> |
|
268 | + <p class="description"><?php _e('Enter the start date for this discount code in the format of yyyy-mm-dd. For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing'); ?></p> |
|
269 | 269 | </td> |
270 | 270 | </tr> |
271 | - <?php do_action( 'wpinv_discount_form_before_expiration', $post ); ?> |
|
271 | + <?php do_action('wpinv_discount_form_before_expiration', $post); ?> |
|
272 | 272 | <tr> |
273 | 273 | <th valign="top" scope="row"> |
274 | - <label for="wpinv_discount_expiration"><?php _e( 'Expiration date', 'invoicing' ); ?></label> |
|
274 | + <label for="wpinv_discount_expiration"><?php _e('Expiration date', 'invoicing'); ?></label> |
|
275 | 275 | </th> |
276 | 276 | <td> |
277 | - <input type="text" class="medium-text wpiDatepicker" id="wpinv_discount_expiration" data-dateFormat="yy-mm-dd" name="expiration" value="<?php echo esc_attr( wpinv_get_discount_expiration( $discount_id ) ); ?>"> |
|
278 | - <p class="description"><?php _e( 'Enter the expiration date for this discount code in the format of yyyy-mm-dd. Leave blank for no expiration.', 'invoicing' ); ?></p> |
|
277 | + <input type="text" class="medium-text wpiDatepicker" id="wpinv_discount_expiration" data-dateFormat="yy-mm-dd" name="expiration" value="<?php echo esc_attr(wpinv_get_discount_expiration($discount_id)); ?>"> |
|
278 | + <p class="description"><?php _e('Enter the expiration date for this discount code in the format of yyyy-mm-dd. Leave blank for no expiration.', 'invoicing'); ?></p> |
|
279 | 279 | </td> |
280 | 280 | </tr> |
281 | - <?php do_action( 'wpinv_discount_form_before_min_total', $post ); ?> |
|
281 | + <?php do_action('wpinv_discount_form_before_min_total', $post); ?> |
|
282 | 282 | <tr> |
283 | 283 | <th valign="top" scope="row"> |
284 | - <label for="wpinv_discount_min_total"><?php _e( 'Minimum Amount', 'invoicing' ); ?></label> |
|
284 | + <label for="wpinv_discount_min_total"><?php _e('Minimum Amount', 'invoicing'); ?></label> |
|
285 | 285 | </th> |
286 | 286 | <td> |
287 | 287 | <input type="text" name="min_total" id="wpinv_discount_min_total" class="wpi-field-price wpi-price" value="<?php echo $min_total; ?>"> |
288 | - <p class="description"><?php _e( 'This allows you to set the minimum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p> |
|
288 | + <p class="description"><?php _e('This allows you to set the minimum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing'); ?></p> |
|
289 | 289 | </td> |
290 | 290 | </tr> |
291 | - <?php do_action( 'wpinv_discount_form_before_max_total', $post ); ?> |
|
291 | + <?php do_action('wpinv_discount_form_before_max_total', $post); ?> |
|
292 | 292 | <tr> |
293 | 293 | <th valign="top" scope="row"> |
294 | - <label for="wpinv_discount_max_total"><?php _e( 'Maximum Amount', 'invoicing' ); ?></label> |
|
294 | + <label for="wpinv_discount_max_total"><?php _e('Maximum Amount', 'invoicing'); ?></label> |
|
295 | 295 | </th> |
296 | 296 | <td> |
297 | 297 | <input type="text" name="max_total" id="wpinv_discount_max_total" class="wpi-field-price wpi-price" value="<?php echo $max_total; ?>"> |
298 | - <p class="description"><?php _e( 'This allows you to set the maximum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p> |
|
298 | + <p class="description"><?php _e('This allows you to set the maximum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing'); ?></p> |
|
299 | 299 | </td> |
300 | 300 | </tr> |
301 | - <?php do_action( 'wpinv_discount_form_before_recurring', $post ); ?> |
|
301 | + <?php do_action('wpinv_discount_form_before_recurring', $post); ?> |
|
302 | 302 | <tr> |
303 | 303 | <th valign="top" scope="row"> |
304 | - <label for="wpinv_discount_recurring"><?php _e( 'For recurring apply to', 'invoicing' ); ?></label> |
|
304 | + <label for="wpinv_discount_recurring"><?php _e('For recurring apply to', 'invoicing'); ?></label> |
|
305 | 305 | </th> |
306 | 306 | <td> |
307 | 307 | <select id="wpinv_discount_recurring" name="recurring" class="medium-text"> |
308 | - <option value="0" <?php selected( false, $recurring ); ?>><?php _e( 'All payments', 'invoicing' ); ?></option> |
|
309 | - <option value="1" <?php selected( true, $recurring ); ?>><?php _e( 'First payment only', 'invoicing' ); ?></option> |
|
308 | + <option value="0" <?php selected(false, $recurring); ?>><?php _e('All payments', 'invoicing'); ?></option> |
|
309 | + <option value="1" <?php selected(true, $recurring); ?>><?php _e('First payment only', 'invoicing'); ?></option> |
|
310 | 310 | </select> |
311 | - <p class="description"><?php _e( '<b>All payments:</b> apply this discount to all recurring payments of the recurring invoice. <br><b>First payment only:</b> apply this discount to only first payment of the recurring invoice.', 'invoicing' ); ?></p> |
|
311 | + <p class="description"><?php _e('<b>All payments:</b> apply this discount to all recurring payments of the recurring invoice. <br><b>First payment only:</b> apply this discount to only first payment of the recurring invoice.', 'invoicing'); ?></p> |
|
312 | 312 | </td> |
313 | 313 | </tr> |
314 | - <?php do_action( 'wpinv_discount_form_before_max_uses', $post ); ?> |
|
314 | + <?php do_action('wpinv_discount_form_before_max_uses', $post); ?> |
|
315 | 315 | <tr> |
316 | 316 | <th valign="top" scope="row"> |
317 | - <label for="wpinv_discount_max_uses"><?php _e( 'Max Uses', 'invoicing' ); ?></label> |
|
317 | + <label for="wpinv_discount_max_uses"><?php _e('Max Uses', 'invoicing'); ?></label> |
|
318 | 318 | </th> |
319 | 319 | <td> |
320 | 320 | <input type="number" min="0" step="1" id="wpinv_discount_max_uses" name="max_uses" class="medium-text" value="<?php echo $max_uses; ?>"> |
321 | - <p class="description"><?php _e( 'The maximum number of times this discount can be used. Leave blank for unlimited.', 'invoicing' ); ?></p> |
|
321 | + <p class="description"><?php _e('The maximum number of times this discount can be used. Leave blank for unlimited.', 'invoicing'); ?></p> |
|
322 | 322 | </td> |
323 | 323 | </tr> |
324 | - <?php do_action( 'wpinv_discount_form_before_single_use', $post ); ?> |
|
324 | + <?php do_action('wpinv_discount_form_before_single_use', $post); ?> |
|
325 | 325 | <tr> |
326 | 326 | <th valign="top" scope="row"> |
327 | - <label for="wpinv_discount_single_use"><?php _e( 'Use Once Per User', 'invoicing' ); ?></label> |
|
327 | + <label for="wpinv_discount_single_use"><?php _e('Use Once Per User', 'invoicing'); ?></label> |
|
328 | 328 | </th> |
329 | 329 | <td> |
330 | - <input type="checkbox" value="1" name="single_use" id="wpinv_discount_single_use" <?php checked( true, $single_use ); ?>> |
|
331 | - <span class="description"><?php _e( 'Limit this discount to a single use per user?', 'invoicing' ); ?></span> |
|
330 | + <input type="checkbox" value="1" name="single_use" id="wpinv_discount_single_use" <?php checked(true, $single_use); ?>> |
|
331 | + <span class="description"><?php _e('Limit this discount to a single use per user?', 'invoicing'); ?></span> |
|
332 | 332 | </td> |
333 | 333 | </tr> |
334 | - <?php do_action( 'wpinv_discount_form_last', $post ); ?> |
|
334 | + <?php do_action('wpinv_discount_form_last', $post); ?> |
|
335 | 335 | </tbody> |
336 | 336 | </table> |
337 | -<?php do_action( 'wpinv_discount_form_bottom', $post ); ?> |
|
337 | +<?php do_action('wpinv_discount_form_bottom', $post); ?> |
|
338 | 338 | <?php |
339 | 339 | } |
340 | 340 | |
341 | -function wpinv_discount_metabox_save( $post_id, $post, $update = false ) { |
|
342 | - $post_type = !empty( $post ) ? $post->post_type : ''; |
|
341 | +function wpinv_discount_metabox_save($post_id, $post, $update = false) { |
|
342 | + $post_type = !empty($post) ? $post->post_type : ''; |
|
343 | 343 | |
344 | - if ( $post_type != 'wpi_discount' ) { |
|
344 | + if ($post_type != 'wpi_discount') { |
|
345 | 345 | return; |
346 | 346 | } |
347 | 347 | |
348 | - if ( !isset( $_POST['wpinv_discount_metabox_nonce'] ) || ( isset( $_POST['wpinv_discount_metabox_nonce'] ) && !wp_verify_nonce( $_POST['wpinv_discount_metabox_nonce'], 'wpinv_discount_metabox_nonce' ) ) ) { |
|
348 | + if (!isset($_POST['wpinv_discount_metabox_nonce']) || (isset($_POST['wpinv_discount_metabox_nonce']) && !wp_verify_nonce($_POST['wpinv_discount_metabox_nonce'], 'wpinv_discount_metabox_nonce'))) { |
|
349 | 349 | return; |
350 | 350 | } |
351 | 351 | |
352 | - if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
352 | + if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || (defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) { |
|
353 | 353 | return; |
354 | 354 | } |
355 | 355 | |
356 | - if ( !current_user_can( 'manage_options', $post_id ) ) { |
|
356 | + if (!current_user_can('manage_options', $post_id)) { |
|
357 | 357 | return; |
358 | 358 | } |
359 | 359 | |
360 | - return wpinv_store_discount( $post_id, $_POST, $post, $update ); |
|
360 | + return wpinv_store_discount($post_id, $_POST, $post, $update); |
|
361 | 361 | } |
362 | -add_action( 'save_post', 'wpinv_discount_metabox_save', 10, 3 ); |
|
363 | 362 | \ No newline at end of file |
363 | +add_action('save_post', 'wpinv_discount_metabox_save', 10, 3); |
|
364 | 364 | \ No newline at end of file |
@@ -7,228 +7,228 @@ 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 | -function wpinv_columns( $columns ) { |
|
14 | +function wpinv_columns($columns) { |
|
15 | 15 | $columns = array( |
16 | 16 | 'cb' => $columns['cb'], |
17 | - 'ID' => __( 'ID', 'invoicing' ), |
|
18 | - 'details' => __( 'Details', 'invoicing' ), |
|
17 | + 'ID' => __('ID', 'invoicing'), |
|
18 | + 'details' => __('Details', 'invoicing'), |
|
19 | 19 | //'email' => __( 'Email', 'invoicing' ), |
20 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
21 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
22 | - 'invoice_date' => __( 'Date', 'invoicing' ), |
|
23 | - 'status' => __( 'Status', 'invoicing' ), |
|
24 | - 'wpi_actions' => __( 'Actions', 'invoicing' ), |
|
20 | + 'customer' => __('Customer', 'invoicing'), |
|
21 | + 'amount' => __('Amount', 'invoicing'), |
|
22 | + 'invoice_date' => __('Date', 'invoicing'), |
|
23 | + 'status' => __('Status', 'invoicing'), |
|
24 | + 'wpi_actions' => __('Actions', 'invoicing'), |
|
25 | 25 | ); |
26 | 26 | |
27 | - return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
27 | + return apply_filters('wpi_invoice_table_columns', $columns); |
|
28 | 28 | } |
29 | -add_filter( 'manage_wpi_invoice_posts_columns', 'wpinv_columns' ); |
|
29 | +add_filter('manage_wpi_invoice_posts_columns', 'wpinv_columns'); |
|
30 | 30 | |
31 | -function wpinv_bulk_actions( $actions ) { |
|
32 | - if ( isset( $actions['edit'] ) ) { |
|
33 | - unset( $actions['edit'] ); |
|
31 | +function wpinv_bulk_actions($actions) { |
|
32 | + if (isset($actions['edit'])) { |
|
33 | + unset($actions['edit']); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | return $actions; |
37 | 37 | } |
38 | -add_filter( 'bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions' ); |
|
38 | +add_filter('bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions'); |
|
39 | 39 | |
40 | -function wpinv_sortable_columns( $columns ) { |
|
40 | +function wpinv_sortable_columns($columns) { |
|
41 | 41 | $columns = array( |
42 | - 'ID' => array( 'ID', true ), |
|
43 | - 'amount' => array( 'amount', false ), |
|
44 | - 'invoice_date' => array( 'date', false ), |
|
45 | - 'customer' => array( 'customer', false ), |
|
42 | + 'ID' => array('ID', true), |
|
43 | + 'amount' => array('amount', false), |
|
44 | + 'invoice_date' => array('date', false), |
|
45 | + 'customer' => array('customer', false), |
|
46 | 46 | ///'email' => array( 'email', false ), |
47 | - 'status' => array( 'status', false ), |
|
47 | + 'status' => array('status', false), |
|
48 | 48 | ); |
49 | 49 | |
50 | - return apply_filters( 'wpi_invoice_table_sortable_columns', $columns ); |
|
50 | + return apply_filters('wpi_invoice_table_sortable_columns', $columns); |
|
51 | 51 | } |
52 | -add_filter( 'manage_edit-wpi_invoice_sortable_columns', 'wpinv_sortable_columns' ); |
|
52 | +add_filter('manage_edit-wpi_invoice_sortable_columns', 'wpinv_sortable_columns'); |
|
53 | 53 | |
54 | -add_action( 'manage_wpi_invoice_posts_custom_column', 'wpinv_posts_custom_column'); |
|
55 | -function wpinv_posts_custom_column( $column_name, $post_id = 0 ) { |
|
54 | +add_action('manage_wpi_invoice_posts_custom_column', 'wpinv_posts_custom_column'); |
|
55 | +function wpinv_posts_custom_column($column_name, $post_id = 0) { |
|
56 | 56 | global $post, $wpi_invoice; |
57 | 57 | |
58 | - if ( empty( $wpi_invoice ) || ( !empty( $wpi_invoice ) && $post->ID != $wpi_invoice->ID ) ) { |
|
59 | - $wpi_invoice = new WPInv_Invoice( $post->ID ); |
|
58 | + if (empty($wpi_invoice) || (!empty($wpi_invoice) && $post->ID != $wpi_invoice->ID)) { |
|
59 | + $wpi_invoice = new WPInv_Invoice($post->ID); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | $value = NULL; |
63 | 63 | |
64 | - switch ( $column_name ) { |
|
64 | + switch ($column_name) { |
|
65 | 65 | case 'email' : |
66 | - $value = $wpi_invoice->get_email(); |
|
66 | + $value = $wpi_invoice->get_email(); |
|
67 | 67 | break; |
68 | 68 | case 'customer' : |
69 | 69 | $customer_name = $wpi_invoice->get_user_full_name(); |
70 | - $customer_name = $customer_name != '' ? $customer_name : __( 'Customer', 'invoicing' ); |
|
71 | - $value = '<a href="' . esc_url( get_edit_user_link( $wpi_invoice->get_user_id() ) ) . '">' . $customer_name . '</a>'; |
|
72 | - if ( $email = $wpi_invoice->get_email() ) { |
|
70 | + $customer_name = $customer_name != '' ? $customer_name : __('Customer', 'invoicing'); |
|
71 | + $value = '<a href="' . esc_url(get_edit_user_link($wpi_invoice->get_user_id())) . '">' . $customer_name . '</a>'; |
|
72 | + if ($email = $wpi_invoice->get_email()) { |
|
73 | 73 | $value .= '<br><a class="email" href="mailto:' . $email . '">' . $email . '</a>'; |
74 | 74 | } |
75 | 75 | break; |
76 | 76 | case 'amount' : |
77 | - echo $wpi_invoice->get_total( true ); |
|
77 | + echo $wpi_invoice->get_total(true); |
|
78 | 78 | break; |
79 | 79 | case 'invoice_date' : |
80 | - $date_format = get_option( 'date_format' ); |
|
81 | - $time_format = get_option( 'time_format' ); |
|
82 | - $date_time_format = $date_format . ' '. $time_format; |
|
80 | + $date_format = get_option('date_format'); |
|
81 | + $time_format = get_option('time_format'); |
|
82 | + $date_time_format = $date_format . ' ' . $time_format; |
|
83 | 83 | |
84 | - $t_time = get_the_time( $date_time_format ); |
|
84 | + $t_time = get_the_time($date_time_format); |
|
85 | 85 | $m_time = $post->post_date; |
86 | - $h_time = mysql2date( $date_format, $m_time ); |
|
86 | + $h_time = mysql2date($date_format, $m_time); |
|
87 | 87 | |
88 | 88 | $value = '<abbr title="' . $t_time . '">' . $h_time . '</abbr>'; |
89 | 89 | break; |
90 | 90 | case 'status' : |
91 | - $value = $wpi_invoice->get_status( true ) . ( $wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '' ); |
|
91 | + $value = $wpi_invoice->get_status(true) . ($wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : ''); |
|
92 | 92 | break; |
93 | 93 | case 'details' : |
94 | - $edit_link = get_edit_post_link( $post->ID ); |
|
95 | - $value = '<a href="' . esc_url( $edit_link ) . '">' . __( 'View Invoice Details', 'invoicing' ) . '</a>'; |
|
94 | + $edit_link = get_edit_post_link($post->ID); |
|
95 | + $value = '<a href="' . esc_url($edit_link) . '">' . __('View Invoice Details', 'invoicing') . '</a>'; |
|
96 | 96 | break; |
97 | 97 | case 'wpi_actions' : |
98 | 98 | $value = ''; |
99 | - if ( !empty( $post->post_name ) ) { |
|
100 | - $value .= '<a title="' . esc_attr__( 'Print invoice', 'invoicing' ) . '" href="' . esc_url( get_permalink( $post->ID ) ) . '" class="button ui-tip column-act-btn" title="" target="_blank"><span class="dashicons dashicons-print"><i style="" class="fa fa-print"></i></span></a>'; |
|
99 | + if (!empty($post->post_name)) { |
|
100 | + $value .= '<a title="' . esc_attr__('Print invoice', 'invoicing') . '" href="' . esc_url(get_permalink($post->ID)) . '" class="button ui-tip column-act-btn" title="" target="_blank"><span class="dashicons dashicons-print"><i style="" class="fa fa-print"></i></span></a>'; |
|
101 | 101 | } |
102 | 102 | |
103 | - if ( $email = $wpi_invoice->get_email() ) { |
|
104 | - $value .= '<a title="' . esc_attr__( 'Send invoice to customer', 'invoicing' ) . '" href="' . esc_url( add_query_arg( array( 'wpi_action' => 'send_invoice', 'invoice_id' => $post->ID ) ) ) . '" class="button ui-tip column-act-btn"><span class="dashicons dashicons-email-alt"></span></a>'; |
|
103 | + if ($email = $wpi_invoice->get_email()) { |
|
104 | + $value .= '<a title="' . esc_attr__('Send invoice to customer', 'invoicing') . '" href="' . esc_url(add_query_arg(array('wpi_action' => 'send_invoice', 'invoice_id' => $post->ID))) . '" class="button ui-tip column-act-btn"><span class="dashicons dashicons-email-alt"></span></a>'; |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | break; |
108 | 108 | default: |
109 | - $value = isset( $post->$column_name ) ? $post->$column_name : ''; |
|
109 | + $value = isset($post->$column_name) ? $post->$column_name : ''; |
|
110 | 110 | break; |
111 | 111 | |
112 | 112 | } |
113 | - $value = apply_filters( 'wpinv_payments_table_column', $value, $post->ID, $column_name ); |
|
113 | + $value = apply_filters('wpinv_payments_table_column', $value, $post->ID, $column_name); |
|
114 | 114 | |
115 | - if ( $value !== NULL ) { |
|
115 | + if ($value !== NULL) { |
|
116 | 116 | echo $value; |
117 | 117 | } |
118 | 118 | } |
119 | 119 | |
120 | -function wpinv_admin_post_id( $id = 0 ) { |
|
120 | +function wpinv_admin_post_id($id = 0) { |
|
121 | 121 | global $post; |
122 | 122 | |
123 | - if ( isset( $id ) && ! empty( $id ) ) { |
|
123 | + if (isset($id) && !empty($id)) { |
|
124 | 124 | return (int)$id; |
125 | - } else if ( get_the_ID() ) { |
|
126 | - return (int) get_the_ID(); |
|
127 | - } else if ( isset( $post->ID ) && !empty( $post->ID ) ) { |
|
128 | - return (int) $post->ID; |
|
129 | - } else if ( isset( $_GET['post'] ) && !empty( $_GET['post'] ) ) { |
|
130 | - return (int) $_GET['post']; |
|
131 | - } else if ( isset( $_GET['id'] ) && !empty( $_GET['id'] ) ) { |
|
132 | - return (int) $_GET['id']; |
|
133 | - } else if ( isset( $_POST['id'] ) && !empty( $_POST['id'] ) ) { |
|
134 | - return (int) $_POST['id']; |
|
125 | + } else if (get_the_ID()) { |
|
126 | + return (int)get_the_ID(); |
|
127 | + } else if (isset($post->ID) && !empty($post->ID)) { |
|
128 | + return (int)$post->ID; |
|
129 | + } else if (isset($_GET['post']) && !empty($_GET['post'])) { |
|
130 | + return (int)$_GET['post']; |
|
131 | + } else if (isset($_GET['id']) && !empty($_GET['id'])) { |
|
132 | + return (int)$_GET['id']; |
|
133 | + } else if (isset($_POST['id']) && !empty($_POST['id'])) { |
|
134 | + return (int)$_POST['id']; |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | return null; |
138 | 138 | } |
139 | 139 | |
140 | -function wpinv_admin_post_type( $id = 0 ) { |
|
141 | - if ( !$id ) { |
|
140 | +function wpinv_admin_post_type($id = 0) { |
|
141 | + if (!$id) { |
|
142 | 142 | $id = wpinv_admin_post_id(); |
143 | 143 | } |
144 | 144 | |
145 | - $type = get_post_type( $id ); |
|
145 | + $type = get_post_type($id); |
|
146 | 146 | |
147 | - if ( !$type ) { |
|
148 | - $type = isset( $_GET['post_type'] ) && !empty( $_GET['post_type'] ) ? $_GET['post_type'] : null; |
|
147 | + if (!$type) { |
|
148 | + $type = isset($_GET['post_type']) && !empty($_GET['post_type']) ? $_GET['post_type'] : null; |
|
149 | 149 | } |
150 | 150 | |
151 | - return apply_filters( 'wpinv_admin_post_type', $type, $id ); |
|
151 | + return apply_filters('wpinv_admin_post_type', $type, $id); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | function wpinv_admin_messages() { |
155 | 155 | global $wpinv_options; |
156 | 156 | |
157 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_added' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
158 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-added', __( 'Discount code added.', 'invoicing' ), 'updated' ); |
|
157 | + if (isset($_GET['wpinv-message']) && 'discount_added' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
158 | + add_settings_error('wpinv-notices', 'wpinv-discount-added', __('Discount code added.', 'invoicing'), 'updated'); |
|
159 | 159 | } |
160 | 160 | |
161 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_add_failed' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
162 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-add-fail', __( 'There was a problem adding your discount code, please try again.', 'invoicing' ), 'error' ); |
|
161 | + if (isset($_GET['wpinv-message']) && 'discount_add_failed' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
162 | + add_settings_error('wpinv-notices', 'wpinv-discount-add-fail', __('There was a problem adding your discount code, please try again.', 'invoicing'), 'error'); |
|
163 | 163 | } |
164 | 164 | |
165 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_exists' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
166 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-exists', __( 'A discount with that code already exists, please use a different code.', 'invoicing' ), 'error' ); |
|
165 | + if (isset($_GET['wpinv-message']) && 'discount_exists' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
166 | + add_settings_error('wpinv-notices', 'wpinv-discount-exists', __('A discount with that code already exists, please use a different code.', 'invoicing'), 'error'); |
|
167 | 167 | } |
168 | 168 | |
169 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_updated' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
170 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-updated', __( 'Discount code updated.', 'invoicing' ), 'updated' ); |
|
169 | + if (isset($_GET['wpinv-message']) && 'discount_updated' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
170 | + add_settings_error('wpinv-notices', 'wpinv-discount-updated', __('Discount code updated.', 'invoicing'), 'updated'); |
|
171 | 171 | } |
172 | 172 | |
173 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_update_failed' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
174 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-updated-fail', __( 'There was a problem updating your discount code, please try again.', 'invoicing' ), 'error' ); |
|
173 | + if (isset($_GET['wpinv-message']) && 'discount_update_failed' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
174 | + add_settings_error('wpinv-notices', 'wpinv-discount-updated-fail', __('There was a problem updating your discount code, please try again.', 'invoicing'), 'error'); |
|
175 | 175 | } |
176 | 176 | |
177 | - if ( isset( $_GET['wpinv-message'] ) && 'invoice_deleted' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
178 | - add_settings_error( 'wpinv-notices', 'wpinv-deleted', __( 'The invoice has been deleted.', 'invoicing' ), 'updated' ); |
|
177 | + if (isset($_GET['wpinv-message']) && 'invoice_deleted' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
178 | + add_settings_error('wpinv-notices', 'wpinv-deleted', __('The invoice has been deleted.', 'invoicing'), 'updated'); |
|
179 | 179 | } |
180 | 180 | |
181 | - if ( isset( $_GET['wpinv-message'] ) && 'email_sent' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
182 | - add_settings_error( 'wpinv-notices', 'wpinv-sent', __( 'The email has been sent to customer.', 'invoicing' ), 'updated' ); |
|
181 | + if (isset($_GET['wpinv-message']) && 'email_sent' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
182 | + add_settings_error('wpinv-notices', 'wpinv-sent', __('The email has been sent to customer.', 'invoicing'), 'updated'); |
|
183 | 183 | } |
184 | 184 | |
185 | - if ( isset( $_GET['wpinv-message'] ) && 'email_fail' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
186 | - add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Fail to send email to the customer.', 'invoicing' ), 'error' ); |
|
185 | + if (isset($_GET['wpinv-message']) && 'email_fail' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
186 | + add_settings_error('wpinv-notices', 'wpinv-sent-fail', __('Fail to send email to the customer.', 'invoicing'), 'error'); |
|
187 | 187 | } |
188 | 188 | |
189 | - if ( isset( $_GET['wpinv-message'] ) && 'invoice-note-deleted' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
190 | - add_settings_error( 'wpinv-notices', 'wpinv-note-deleted', __( 'The invoice note has been deleted.', 'invoicing' ), 'updated' ); |
|
189 | + if (isset($_GET['wpinv-message']) && 'invoice-note-deleted' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
190 | + add_settings_error('wpinv-notices', 'wpinv-note-deleted', __('The invoice note has been deleted.', 'invoicing'), 'updated'); |
|
191 | 191 | } |
192 | 192 | |
193 | - if ( isset( $_GET['wpinv-message'] ) && 'settings-imported' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
194 | - add_settings_error( 'wpinv-notices', 'wpinv-settings-imported', __( 'The settings have been imported.', 'invoicing' ), 'updated' ); |
|
193 | + if (isset($_GET['wpinv-message']) && 'settings-imported' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
194 | + add_settings_error('wpinv-notices', 'wpinv-settings-imported', __('The settings have been imported.', 'invoicing'), 'updated'); |
|
195 | 195 | } |
196 | 196 | |
197 | - if ( isset( $_GET['wpinv-message'] ) && 'note-added' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
198 | - add_settings_error( 'wpinv-notices', 'wpinv-note-added', __( 'The invoice note has been added successfully.', 'invoicing' ), 'updated' ); |
|
197 | + if (isset($_GET['wpinv-message']) && 'note-added' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
198 | + add_settings_error('wpinv-notices', 'wpinv-note-added', __('The invoice note has been added successfully.', 'invoicing'), 'updated'); |
|
199 | 199 | } |
200 | 200 | |
201 | - if ( isset( $_GET['wpinv-message'] ) && 'invoice-updated' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
202 | - add_settings_error( 'wpinv-notices', 'wpinv-updated', __( 'The invoice has been successfully updated.', 'invoicing' ), 'updated' ); |
|
201 | + if (isset($_GET['wpinv-message']) && 'invoice-updated' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
202 | + add_settings_error('wpinv-notices', 'wpinv-updated', __('The invoice has been successfully updated.', 'invoicing'), 'updated'); |
|
203 | 203 | } |
204 | 204 | |
205 | - settings_errors( 'wpinv-notices' ); |
|
205 | + settings_errors('wpinv-notices'); |
|
206 | 206 | } |
207 | -add_action( 'admin_notices', 'wpinv_admin_messages' ); |
|
207 | +add_action('admin_notices', 'wpinv_admin_messages'); |
|
208 | 208 | |
209 | -function wpinv_items_columns( $existing_columns ) { |
|
209 | +function wpinv_items_columns($existing_columns) { |
|
210 | 210 | global $wpinv_euvat; |
211 | 211 | |
212 | 212 | $columns = array(); |
213 | 213 | $columns['cb'] = $existing_columns['cb']; |
214 | - $columns['title'] = __( 'Title', 'invoicing' ); |
|
215 | - $columns['price'] = __( 'Price', 'invoicing' ); |
|
216 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
217 | - $columns['vat_rule'] = __( 'VAT rule type', 'invoicing' ); |
|
214 | + $columns['title'] = __('Title', 'invoicing'); |
|
215 | + $columns['price'] = __('Price', 'invoicing'); |
|
216 | + if ($wpinv_euvat->allow_vat_rules()) { |
|
217 | + $columns['vat_rule'] = __('VAT rule type', 'invoicing'); |
|
218 | 218 | } |
219 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
220 | - $columns['vat_class'] = __( 'VAT class', 'invoicing' ); |
|
219 | + if ($wpinv_euvat->allow_vat_classes()) { |
|
220 | + $columns['vat_class'] = __('VAT class', 'invoicing'); |
|
221 | 221 | } |
222 | - $columns['type'] = __( 'Type', 'invoicing' ); |
|
223 | - $columns['recurring'] = __( 'Recurring', 'invoicing' ); |
|
224 | - $columns['date'] = __( 'Date', 'invoicing' ); |
|
225 | - $columns['id'] = __( 'ID', 'invoicing' ); |
|
222 | + $columns['type'] = __('Type', 'invoicing'); |
|
223 | + $columns['recurring'] = __('Recurring', 'invoicing'); |
|
224 | + $columns['date'] = __('Date', 'invoicing'); |
|
225 | + $columns['id'] = __('ID', 'invoicing'); |
|
226 | 226 | |
227 | - return apply_filters( 'wpinv_items_columns', $columns ); |
|
227 | + return apply_filters('wpinv_items_columns', $columns); |
|
228 | 228 | } |
229 | -add_filter( 'manage_wpi_item_posts_columns', 'wpinv_items_columns' ); |
|
229 | +add_filter('manage_wpi_item_posts_columns', 'wpinv_items_columns'); |
|
230 | 230 | |
231 | -function wpinv_items_sortable_columns( $columns ) { |
|
231 | +function wpinv_items_sortable_columns($columns) { |
|
232 | 232 | $columns['price'] = 'price'; |
233 | 233 | $columns['vat_rule'] = 'vat_rule'; |
234 | 234 | $columns['vat_class'] = 'vat_class'; |
@@ -238,10 +238,10 @@ discard block |
||
238 | 238 | |
239 | 239 | return $columns; |
240 | 240 | } |
241 | -add_filter( 'manage_edit-wpi_item_sortable_columns', 'wpinv_items_sortable_columns' ); |
|
241 | +add_filter('manage_edit-wpi_item_sortable_columns', 'wpinv_items_sortable_columns'); |
|
242 | 242 | |
243 | -function wpinv_item_quick_edit( $column_name, $post_type ) { |
|
244 | - if ( !( $post_type == 'wpi_item' && $column_name == 'price' ) ) { |
|
243 | +function wpinv_item_quick_edit($column_name, $post_type) { |
|
244 | + if (!($post_type == 'wpi_item' && $column_name == 'price')) { |
|
245 | 245 | return; |
246 | 246 | } |
247 | 247 | global $wpinv_euvat, $post; |
@@ -249,23 +249,23 @@ discard block |
||
249 | 249 | $symbol = wpinv_currency_symbol(); |
250 | 250 | $position = wpinv_currency_position(); |
251 | 251 | |
252 | - $price = wpinv_get_item_price( $post->ID ); |
|
253 | - $item_type = wpinv_get_item_type( $post->ID ); |
|
252 | + $price = wpinv_get_item_price($post->ID); |
|
253 | + $item_type = wpinv_get_item_type($post->ID); |
|
254 | 254 | ?> |
255 | 255 | <fieldset class="inline-edit-col-right wpi-inline-item-col"> |
256 | 256 | <div class="inline-edit-col"> |
257 | 257 | <div class="inline-edit-group wp-clearfix"> |
258 | 258 | <label class="inline-edit-wpinv-price"> |
259 | - <span class="title"><?php _e( 'Item price', 'invoicing' );?></span> |
|
260 | - <span class="input-text-wrap"><?php echo ( $position != 'right' ? $symbol . ' ' : '' );?><input type="text" placeholder="<?php echo wpinv_format_amount( 0 ); ?>" value="<?php echo wpinv_format_amount( $price );?>" name="_wpinv_item_price" class="wpi-field-price wpi-price" id="wpinv_item_price-<?php echo $post->ID;?>"><?php echo ( $position == 'right' ? $symbol . ' ' : '' );?></span> |
|
259 | + <span class="title"><?php _e('Item price', 'invoicing'); ?></span> |
|
260 | + <span class="input-text-wrap"><?php echo ($position != 'right' ? $symbol . ' ' : ''); ?><input type="text" placeholder="<?php echo wpinv_format_amount(0); ?>" value="<?php echo wpinv_format_amount($price); ?>" name="_wpinv_item_price" class="wpi-field-price wpi-price" id="wpinv_item_price-<?php echo $post->ID; ?>"><?php echo ($position == 'right' ? $symbol . ' ' : ''); ?></span> |
|
261 | 261 | </label> |
262 | 262 | </div> |
263 | - <?php if ( $wpinv_euvat->allow_vat_rules() ) { $rule_type = $wpinv_euvat->get_item_rule( $post->ID ); ?> |
|
263 | + <?php if ($wpinv_euvat->allow_vat_rules()) { $rule_type = $wpinv_euvat->get_item_rule($post->ID); ?> |
|
264 | 264 | <div class="inline-edit-group wp-clearfix"> |
265 | 265 | <label class="inline-edit-wpinv-vat-rate"> |
266 | - <span class="title"><?php _e( 'VAT rule type to use', 'invoicing' );?></span> |
|
266 | + <span class="title"><?php _e('VAT rule type to use', 'invoicing'); ?></span> |
|
267 | 267 | <span class="input-text-wrap"> |
268 | - <?php echo wpinv_html_select( array( |
|
268 | + <?php echo wpinv_html_select(array( |
|
269 | 269 | 'options' => $wpinv_euvat->get_rules(), |
270 | 270 | 'name' => '_wpinv_vat_rules', |
271 | 271 | 'id' => 'wpinv_vat_rules-' . $post->ID, |
@@ -273,16 +273,16 @@ discard block |
||
273 | 273 | 'show_option_all' => false, |
274 | 274 | 'show_option_none' => false, |
275 | 275 | 'class' => 'gdmbx2-text-medium wpinv-vat-rules', |
276 | - ) ); ?> |
|
276 | + )); ?> |
|
277 | 277 | </span> |
278 | 278 | </label> |
279 | 279 | </div> |
280 | - <?php } if ( $wpinv_euvat->allow_vat_classes() ) { $vat_class = $wpinv_euvat->get_item_class( $post->ID ); ?> |
|
280 | + <?php } if ($wpinv_euvat->allow_vat_classes()) { $vat_class = $wpinv_euvat->get_item_class($post->ID); ?> |
|
281 | 281 | <div class="inline-edit-group wp-clearfix"> |
282 | 282 | <label class="inline-edit-wpinv-vat-class"> |
283 | - <span class="title"><?php _e( 'VAT class to use', 'invoicing' );?></span> |
|
283 | + <span class="title"><?php _e('VAT class to use', 'invoicing'); ?></span> |
|
284 | 284 | <span class="input-text-wrap"> |
285 | - <?php echo wpinv_html_select( array( |
|
285 | + <?php echo wpinv_html_select(array( |
|
286 | 286 | 'options' => $wpinv_euvat->get_all_classes(), |
287 | 287 | 'name' => '_wpinv_vat_class', |
288 | 288 | 'id' => 'wpinv_vat_class-' . $post->ID, |
@@ -290,16 +290,16 @@ discard block |
||
290 | 290 | 'show_option_all' => false, |
291 | 291 | 'show_option_none' => false, |
292 | 292 | 'class' => 'gdmbx2-text-medium wpinv-vat-class', |
293 | - ) ); ?> |
|
293 | + )); ?> |
|
294 | 294 | </span> |
295 | 295 | </label> |
296 | 296 | </div> |
297 | 297 | <?php } ?> |
298 | 298 | <div class="inline-edit-group wp-clearfix"> |
299 | 299 | <label class="inline-edit-wpinv-type"> |
300 | - <span class="title"><?php _e( 'Item type', 'invoicing' );?></span> |
|
300 | + <span class="title"><?php _e('Item type', 'invoicing'); ?></span> |
|
301 | 301 | <span class="input-text-wrap"> |
302 | - <?php echo wpinv_html_select( array( |
|
302 | + <?php echo wpinv_html_select(array( |
|
303 | 303 | 'options' => wpinv_get_item_types(), |
304 | 304 | 'name' => '_wpinv_item_type', |
305 | 305 | 'id' => 'wpinv_item_type-' . $post->ID, |
@@ -307,7 +307,7 @@ discard block |
||
307 | 307 | 'show_option_all' => false, |
308 | 308 | 'show_option_none' => false, |
309 | 309 | 'class' => 'gdmbx2-text-medium wpinv-item-type', |
310 | - ) ); ?> |
|
310 | + )); ?> |
|
311 | 311 | </span> |
312 | 312 | </label> |
313 | 313 | </div> |
@@ -315,150 +315,150 @@ discard block |
||
315 | 315 | </fieldset> |
316 | 316 | <?php |
317 | 317 | } |
318 | -add_action( 'quick_edit_custom_box', 'wpinv_item_quick_edit', 10, 2 ); |
|
319 | -add_action( 'bulk_edit_custom_box', 'wpinv_item_quick_edit', 10, 2 ); |
|
318 | +add_action('quick_edit_custom_box', 'wpinv_item_quick_edit', 10, 2); |
|
319 | +add_action('bulk_edit_custom_box', 'wpinv_item_quick_edit', 10, 2); |
|
320 | 320 | |
321 | -function wpinv_items_table_custom_column( $column ) { |
|
321 | +function wpinv_items_table_custom_column($column) { |
|
322 | 322 | global $wpinv_euvat, $post, $wpi_item; |
323 | 323 | |
324 | - if ( empty( $wpi_item ) || ( !empty( $wpi_item ) && $post->ID != $wpi_item->ID ) ) { |
|
325 | - $wpi_item = new WPInv_Item( $post->ID ); |
|
324 | + if (empty($wpi_item) || (!empty($wpi_item) && $post->ID != $wpi_item->ID)) { |
|
325 | + $wpi_item = new WPInv_Item($post->ID); |
|
326 | 326 | } |
327 | 327 | |
328 | - switch ( $column ) { |
|
328 | + switch ($column) { |
|
329 | 329 | case 'price' : |
330 | - echo wpinv_item_price( $post->ID ); |
|
330 | + echo wpinv_item_price($post->ID); |
|
331 | 331 | break; |
332 | 332 | case 'vat_rule' : |
333 | - echo $wpinv_euvat->item_rule_label( $post->ID ); |
|
333 | + echo $wpinv_euvat->item_rule_label($post->ID); |
|
334 | 334 | break; |
335 | 335 | case 'vat_class' : |
336 | - echo $wpinv_euvat->item_class_label( $post->ID ); |
|
336 | + echo $wpinv_euvat->item_class_label($post->ID); |
|
337 | 337 | break; |
338 | 338 | case 'type' : |
339 | - echo wpinv_item_type( $post->ID ) . '<span class="meta">' . $wpi_item->get_cpt_singular_name() . '</span>'; |
|
339 | + echo wpinv_item_type($post->ID) . '<span class="meta">' . $wpi_item->get_cpt_singular_name() . '</span>'; |
|
340 | 340 | break; |
341 | 341 | case 'recurring' : |
342 | - echo ( wpinv_is_recurring_item( $post->ID ) ? '<i class="fa fa-check fa-recurring-y"></i>' : '<i class="fa fa-close fa-recurring-n"></i>' ); |
|
342 | + echo (wpinv_is_recurring_item($post->ID) ? '<i class="fa fa-check fa-recurring-y"></i>' : '<i class="fa fa-close fa-recurring-n"></i>'); |
|
343 | 343 | break; |
344 | 344 | case 'id' : |
345 | 345 | echo $post->ID; |
346 | 346 | echo '<div class="hidden" id="wpinv_inline-' . $post->ID . '"> |
347 | - <div class="price">' . wpinv_get_item_price( $post->ID ) . '</div>'; |
|
348 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
349 | - echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule( $post->ID ) . '</div>'; |
|
347 | + <div class="price">' . wpinv_get_item_price($post->ID) . '</div>'; |
|
348 | + if ($wpinv_euvat->allow_vat_rules()) { |
|
349 | + echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule($post->ID) . '</div>'; |
|
350 | 350 | } |
351 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
352 | - echo '<div class="vat_class">' . $wpinv_euvat->get_item_class( $post->ID ) . '</div>'; |
|
351 | + if ($wpinv_euvat->allow_vat_classes()) { |
|
352 | + echo '<div class="vat_class">' . $wpinv_euvat->get_item_class($post->ID) . '</div>'; |
|
353 | 353 | } |
354 | - echo '<div class="type">' . wpinv_get_item_type( $post->ID ) . '</div> |
|
354 | + echo '<div class="type">' . wpinv_get_item_type($post->ID) . '</div> |
|
355 | 355 | </div>'; |
356 | 356 | break; |
357 | 357 | } |
358 | 358 | |
359 | - do_action( 'wpinv_items_table_column_item_' . $column, $wpi_item, $post ); |
|
359 | + do_action('wpinv_items_table_column_item_' . $column, $wpi_item, $post); |
|
360 | 360 | } |
361 | -add_action( 'manage_wpi_item_posts_custom_column', 'wpinv_items_table_custom_column' ); |
|
361 | +add_action('manage_wpi_item_posts_custom_column', 'wpinv_items_table_custom_column'); |
|
362 | 362 | |
363 | 363 | function wpinv_add_items_filters() { |
364 | 364 | global $wpinv_euvat, $typenow; |
365 | 365 | |
366 | 366 | // Checks if the current post type is 'item' |
367 | - if ( $typenow == 'wpi_item') { |
|
368 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
369 | - echo wpinv_html_select( array( |
|
370 | - 'options' => array_merge( array( '' => __( 'All VAT rules', 'invoicing' ) ), $wpinv_euvat->get_rules() ), |
|
367 | + if ($typenow == 'wpi_item') { |
|
368 | + if ($wpinv_euvat->allow_vat_rules()) { |
|
369 | + echo wpinv_html_select(array( |
|
370 | + 'options' => array_merge(array('' => __('All VAT rules', 'invoicing')), $wpinv_euvat->get_rules()), |
|
371 | 371 | 'name' => 'vat_rule', |
372 | 372 | 'id' => 'vat_rule', |
373 | - 'selected' => ( isset( $_GET['vat_rule'] ) ? $_GET['vat_rule'] : '' ), |
|
373 | + 'selected' => (isset($_GET['vat_rule']) ? $_GET['vat_rule'] : ''), |
|
374 | 374 | 'show_option_all' => false, |
375 | 375 | 'show_option_none' => false, |
376 | 376 | 'class' => 'gdmbx2-text-medium', |
377 | - ) ); |
|
377 | + )); |
|
378 | 378 | } |
379 | 379 | |
380 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
381 | - echo wpinv_html_select( array( |
|
382 | - 'options' => array_merge( array( '' => __( 'All VAT classes', 'invoicing' ) ), $wpinv_euvat->get_all_classes() ), |
|
380 | + if ($wpinv_euvat->allow_vat_classes()) { |
|
381 | + echo wpinv_html_select(array( |
|
382 | + 'options' => array_merge(array('' => __('All VAT classes', 'invoicing')), $wpinv_euvat->get_all_classes()), |
|
383 | 383 | 'name' => 'vat_class', |
384 | 384 | 'id' => 'vat_class', |
385 | - 'selected' => ( isset( $_GET['vat_class'] ) ? $_GET['vat_class'] : '' ), |
|
385 | + 'selected' => (isset($_GET['vat_class']) ? $_GET['vat_class'] : ''), |
|
386 | 386 | 'show_option_all' => false, |
387 | 387 | 'show_option_none' => false, |
388 | 388 | 'class' => 'gdmbx2-text-medium', |
389 | - ) ); |
|
389 | + )); |
|
390 | 390 | } |
391 | 391 | |
392 | - echo wpinv_html_select( array( |
|
393 | - 'options' => array_merge( array( '' => __( 'All item types', 'invoicing' ) ), wpinv_get_item_types() ), |
|
392 | + echo wpinv_html_select(array( |
|
393 | + 'options' => array_merge(array('' => __('All item types', 'invoicing')), wpinv_get_item_types()), |
|
394 | 394 | 'name' => 'type', |
395 | 395 | 'id' => 'type', |
396 | - 'selected' => ( isset( $_GET['type'] ) ? $_GET['type'] : '' ), |
|
396 | + 'selected' => (isset($_GET['type']) ? $_GET['type'] : ''), |
|
397 | 397 | 'show_option_all' => false, |
398 | 398 | 'show_option_none' => false, |
399 | 399 | 'class' => 'gdmbx2-text-medium', |
400 | - ) ); |
|
400 | + )); |
|
401 | 401 | |
402 | - if ( isset( $_REQUEST['all_posts'] ) && '1' === $_REQUEST['all_posts'] ) { |
|
402 | + if (isset($_REQUEST['all_posts']) && '1' === $_REQUEST['all_posts']) { |
|
403 | 403 | echo '<input type="hidden" name="all_posts" value="1" />'; |
404 | 404 | } |
405 | 405 | } |
406 | 406 | } |
407 | -add_action( 'restrict_manage_posts', 'wpinv_add_items_filters', 100 ); |
|
407 | +add_action('restrict_manage_posts', 'wpinv_add_items_filters', 100); |
|
408 | 408 | |
409 | -function wpinv_send_invoice_after_save( $post_id ) { |
|
409 | +function wpinv_send_invoice_after_save($post_id) { |
|
410 | 410 | // If this is just a revision, don't send the email. |
411 | - if ( wp_is_post_revision( $post_id ) ) { |
|
411 | + if (wp_is_post_revision($post_id)) { |
|
412 | 412 | return; |
413 | 413 | } |
414 | 414 | |
415 | - if ( !current_user_can( 'manage_options' ) || !(get_post_type( $post_id ) == 'wpi_invoice' || get_post_type( $post_id ) == 'wpi_quote') ) { |
|
415 | + if (!current_user_can('manage_options') || !(get_post_type($post_id) == 'wpi_invoice' || get_post_type($post_id) == 'wpi_quote')) { |
|
416 | 416 | return; |
417 | 417 | } |
418 | 418 | |
419 | - if ( !empty( $_POST['wpi_save_send'] ) ) { |
|
420 | - wpinv_user_invoice_notification( $post_id ); |
|
419 | + if (!empty($_POST['wpi_save_send'])) { |
|
420 | + wpinv_user_invoice_notification($post_id); |
|
421 | 421 | } |
422 | 422 | } |
423 | -add_action( 'save_post', 'wpinv_send_invoice_after_save', 100, 1 ); |
|
423 | +add_action('save_post', 'wpinv_send_invoice_after_save', 100, 1); |
|
424 | 424 | |
425 | -function wpinv_send_register_new_user( $data, $postarr ) { |
|
426 | - if ( current_user_can( 'manage_options' ) && !empty( $data['post_type'] ) && $data['post_type'] == 'wpi_invoice' ) { |
|
427 | - $is_new_user = !empty( $postarr['wpinv_new_user'] ) ? true : false; |
|
428 | - $email = !empty( $postarr['wpinv_email'] ) && $postarr['wpinv_email'] && is_email( $postarr['wpinv_email'] ) ? $postarr['wpinv_email'] : NULL; |
|
425 | +function wpinv_send_register_new_user($data, $postarr) { |
|
426 | + if (current_user_can('manage_options') && !empty($data['post_type']) && $data['post_type'] == 'wpi_invoice') { |
|
427 | + $is_new_user = !empty($postarr['wpinv_new_user']) ? true : false; |
|
428 | + $email = !empty($postarr['wpinv_email']) && $postarr['wpinv_email'] && is_email($postarr['wpinv_email']) ? $postarr['wpinv_email'] : NULL; |
|
429 | 429 | |
430 | - if ( $is_new_user && $email && !email_exists( $email ) ) { |
|
431 | - $first_name = !empty( $postarr['wpinv_first_name'] ) ? sanitize_text_field( $postarr['wpinv_first_name'] ) : ''; |
|
432 | - $last_name = !empty( $postarr['wpinv_last_name'] ) ? sanitize_text_field( $postarr['wpinv_last_name'] ) : ''; |
|
433 | - $display_name = $first_name || $last_name ? trim( $first_name . ' ' . $last_name ) : ''; |
|
434 | - $user_nicename = $display_name ? trim( $display_name ) : $email; |
|
435 | - $user_company = !empty( $postarr['wpinv_company'] ) ? sanitize_text_field( $postarr['wpinv_company'] ) : ''; |
|
430 | + if ($is_new_user && $email && !email_exists($email)) { |
|
431 | + $first_name = !empty($postarr['wpinv_first_name']) ? sanitize_text_field($postarr['wpinv_first_name']) : ''; |
|
432 | + $last_name = !empty($postarr['wpinv_last_name']) ? sanitize_text_field($postarr['wpinv_last_name']) : ''; |
|
433 | + $display_name = $first_name || $last_name ? trim($first_name . ' ' . $last_name) : ''; |
|
434 | + $user_nicename = $display_name ? trim($display_name) : $email; |
|
435 | + $user_company = !empty($postarr['wpinv_company']) ? sanitize_text_field($postarr['wpinv_company']) : ''; |
|
436 | 436 | |
437 | - $user_login = sanitize_user( str_replace( ' ', '', $display_name ), true ); |
|
438 | - if ( !( validate_username( $user_login ) && !username_exists( $user_login ) ) ) { |
|
439 | - $user_login = sanitize_user( str_replace( ' ', '', $user_company ), true ); |
|
437 | + $user_login = sanitize_user(str_replace(' ', '', $display_name), true); |
|
438 | + if (!(validate_username($user_login) && !username_exists($user_login))) { |
|
439 | + $user_login = sanitize_user(str_replace(' ', '', $user_company), true); |
|
440 | 440 | |
441 | - if ( !( validate_username( $user_login ) && !username_exists( $user_login ) ) ) { |
|
441 | + if (!(validate_username($user_login) && !username_exists($user_login))) { |
|
442 | 442 | $user_login = $email; |
443 | 443 | } |
444 | 444 | } |
445 | 445 | |
446 | 446 | $userdata = array( |
447 | 447 | 'user_login' => $user_login, |
448 | - 'user_pass' => wp_generate_password( 12, false ), |
|
449 | - 'user_email' => sanitize_text_field( $email ), |
|
448 | + 'user_pass' => wp_generate_password(12, false), |
|
449 | + 'user_email' => sanitize_text_field($email), |
|
450 | 450 | 'first_name' => $first_name, |
451 | 451 | 'last_name' => $last_name, |
452 | - 'user_nicename' => wpinv_utf8_substr( $user_nicename, 0, 50 ), |
|
452 | + 'user_nicename' => wpinv_utf8_substr($user_nicename, 0, 50), |
|
453 | 453 | 'nickname' => $display_name, |
454 | 454 | 'display_name' => $display_name, |
455 | 455 | ); |
456 | 456 | |
457 | - $userdata = apply_filters( 'wpinv_register_new_user_data', $userdata ); |
|
457 | + $userdata = apply_filters('wpinv_register_new_user_data', $userdata); |
|
458 | 458 | |
459 | - $new_user_id = wp_insert_user( $userdata ); |
|
459 | + $new_user_id = wp_insert_user($userdata); |
|
460 | 460 | |
461 | - if ( !is_wp_error( $new_user_id ) ) { |
|
461 | + if (!is_wp_error($new_user_id)) { |
|
462 | 462 | $data['post_author'] = $new_user_id; |
463 | 463 | $_POST['post_author'] = $new_user_id; |
464 | 464 | $_POST['post_author_override'] = $new_user_id; |
@@ -479,27 +479,27 @@ discard block |
||
479 | 479 | |
480 | 480 | $meta = array(); |
481 | 481 | ///$meta['_wpinv_user_id'] = $new_user_id; |
482 | - foreach ( $meta_fields as $field ) { |
|
483 | - $meta['_wpinv_' . $field] = isset( $postarr['wpinv_' . $field] ) ? sanitize_text_field( $postarr['wpinv_' . $field] ) : ''; |
|
482 | + foreach ($meta_fields as $field) { |
|
483 | + $meta['_wpinv_' . $field] = isset($postarr['wpinv_' . $field]) ? sanitize_text_field($postarr['wpinv_' . $field]) : ''; |
|
484 | 484 | } |
485 | 485 | |
486 | - $meta = apply_filters( 'wpinv_register_new_user_meta', $meta, $new_user_id ); |
|
486 | + $meta = apply_filters('wpinv_register_new_user_meta', $meta, $new_user_id); |
|
487 | 487 | |
488 | 488 | // Update user meta. |
489 | - foreach ( $meta as $key => $value ) { |
|
490 | - update_user_meta( $new_user_id, $key, $value ); |
|
489 | + foreach ($meta as $key => $value) { |
|
490 | + update_user_meta($new_user_id, $key, $value); |
|
491 | 491 | } |
492 | 492 | |
493 | - if ( function_exists( 'wp_send_new_user_notifications' ) ) { |
|
493 | + if (function_exists('wp_send_new_user_notifications')) { |
|
494 | 494 | // Send email notifications related to the creation of new user. |
495 | - wp_send_new_user_notifications( $new_user_id, 'user' ); |
|
495 | + wp_send_new_user_notifications($new_user_id, 'user'); |
|
496 | 496 | } |
497 | 497 | } else { |
498 | - wpinv_error_log( $new_user_id->get_error_message(), 'Invoice add new user', __FILE__, __LINE__ ); |
|
498 | + wpinv_error_log($new_user_id->get_error_message(), 'Invoice add new user', __FILE__, __LINE__); |
|
499 | 499 | } |
500 | 500 | } |
501 | 501 | } |
502 | 502 | |
503 | 503 | return $data; |
504 | 504 | } |
505 | -add_filter( 'wp_insert_post_data', 'wpinv_send_register_new_user', 10, 2 ); |
|
506 | 505 | \ No newline at end of file |
506 | +add_filter('wp_insert_post_data', 'wpinv_send_register_new_user', 10, 2); |
|
507 | 507 | \ No newline at end of file |
@@ -1,29 +1,29 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // MUST have WordPress. |
3 | -if ( !defined( 'WPINC' ) ) { |
|
4 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
3 | +if (!defined('WPINC')) { |
|
4 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | class WPInv_Meta_Box_Details { |
8 | - public static function output( $post ) { |
|
8 | + public static function output($post) { |
|
9 | 9 | $currency_symbol = wpinv_currency_symbol(); |
10 | 10 | $statuses = wpinv_get_invoice_statuses(); |
11 | 11 | |
12 | - $post_id = !empty( $post->ID ) ? $post->ID : 0; |
|
13 | - $invoice = new WPInv_Invoice( $post_id ); |
|
12 | + $post_id = !empty($post->ID) ? $post->ID : 0; |
|
13 | + $invoice = new WPInv_Invoice($post_id); |
|
14 | 14 | |
15 | - $status = $invoice->get_status( false ); // Current status |
|
15 | + $status = $invoice->get_status(false); // Current status |
|
16 | 16 | $discount = $invoice->get_discount(); |
17 | 17 | $discount_code = $discount > 0 ? $invoice->get_discount_code() : ''; |
18 | 18 | $invoice_number = $invoice->get_number(); |
19 | 19 | |
20 | 20 | $date_created = $invoice->get_created_date(); |
21 | - $datetime_created = strtotime( $date_created ); |
|
22 | - $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $datetime_created ) : ''; |
|
21 | + $datetime_created = strtotime($date_created); |
|
22 | + $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $datetime_created) : ''; |
|
23 | 23 | $date_completed = $invoice->get_completed_date(); |
24 | - $date_completed = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( $date_completed ) ) : 'n/a'; |
|
25 | - $title['status'] = __( 'Invoice Status:', 'invoicing' ); |
|
26 | - $title['number'] = __( 'Invoice Number:', 'invoicing' ); |
|
24 | + $date_completed = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n(get_option('date_format') . ' ' . get_option('time_format'), strtotime($date_completed)) : 'n/a'; |
|
25 | + $title['status'] = __('Invoice Status:', 'invoicing'); |
|
26 | + $title['number'] = __('Invoice Number:', 'invoicing'); |
|
27 | 27 | |
28 | 28 | $title = apply_filters('invoice_detail_metabox_titles', $title, $invoice); |
29 | 29 | $statuses = apply_filters('wpinv_metabox_statuses', $statuses, $invoice); |
@@ -31,29 +31,29 @@ discard block |
||
31 | 31 | <div class="gdmbx2-wrap form-table"> |
32 | 32 | <div class="gdmbx2-metabox gdmbx-field-list" id="gdmbx2-metabox-wpinv_details"> |
33 | 33 | <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-date-created"> |
34 | - <div class="gdmbx-th"><label><?php _e( 'Date Created:', 'invoicing' );?></label></div> |
|
35 | - <div class="gdmbx-td"><?php echo $date_created;?></div> |
|
34 | + <div class="gdmbx-th"><label><?php _e('Date Created:', 'invoicing'); ?></label></div> |
|
35 | + <div class="gdmbx-td"><?php echo $date_created; ?></div> |
|
36 | 36 | </div> |
37 | - <?php if ( wpinv_get_option( 'overdue_active' ) && ( $invoice->needs_payment() || $invoice->has_status( array( 'auto-draft' ) ) ) ) { ?> |
|
37 | + <?php if (wpinv_get_option('overdue_active') && ($invoice->needs_payment() || $invoice->has_status(array('auto-draft')))) { ?> |
|
38 | 38 | <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-date-overdue"> |
39 | - <div class="gdmbx-th"><label for="wpinv_due_date"><?php _e( 'Due Date:', 'invoicing' );?></label></div> |
|
39 | + <div class="gdmbx-th"><label for="wpinv_due_date"><?php _e('Due Date:', 'invoicing'); ?></label></div> |
|
40 | 40 | <div class="gdmbx-td"> |
41 | - <input type="text" placeholder="<?php esc_attr_e( 'Y-m-d', 'invoicing' );?>" value="<?php echo esc_attr( $invoice->get_due_date() );?>" id="wpinv_due_date" name="wpinv_due_date" class="regular-text wpiDatepicker" data-minDate="<?php echo esc_attr( date_i18n( 'Y-m-d', $datetime_created ) );?>" data-dateFormat="yy-mm-dd"> |
|
41 | + <input type="text" placeholder="<?php esc_attr_e('Y-m-d', 'invoicing'); ?>" value="<?php echo esc_attr($invoice->get_due_date()); ?>" id="wpinv_due_date" name="wpinv_due_date" class="regular-text wpiDatepicker" data-minDate="<?php echo esc_attr(date_i18n('Y-m-d', $datetime_created)); ?>" data-dateFormat="yy-mm-dd"> |
|
42 | 42 | </div> |
43 | 43 | </div> |
44 | 44 | <?php } ?> |
45 | - <?php if ( $date_completed && $date_completed != 'n/a' ) { ?> |
|
45 | + <?php if ($date_completed && $date_completed != 'n/a') { ?> |
|
46 | 46 | <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-date-completed"> |
47 | - <div class="gdmbx-th"><label><?php _e( 'Payment Date:', 'invoicing' );?></label></div> |
|
48 | - <div class="gdmbx-td"><?php echo $date_completed;?></div> |
|
47 | + <div class="gdmbx-th"><label><?php _e('Payment Date:', 'invoicing'); ?></label></div> |
|
48 | + <div class="gdmbx-td"><?php echo $date_completed; ?></div> |
|
49 | 49 | </div> |
50 | 50 | <?php } ?> |
51 | 51 | <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-status"> |
52 | 52 | <div class="gdmbx-th"><label for="wpinv_status"><?php echo $title['status']; ?></label></div> |
53 | 53 | <div class="gdmbx-td"> |
54 | 54 | <select required="required" id="wpinv_status" name="wpinv_status" class="gdmbx2_select"> |
55 | - <?php foreach ( $statuses as $value => $label ) { ?> |
|
56 | - <option value="<?php echo $value;?>" <?php selected( $status, $value );?>><?php echo $label;?></option> |
|
55 | + <?php foreach ($statuses as $value => $label) { ?> |
|
56 | + <option value="<?php echo $value; ?>" <?php selected($status, $value); ?>><?php echo $label; ?></option> |
|
57 | 57 | <?php } ?> |
58 | 58 | </select> |
59 | 59 | </div> |
@@ -61,104 +61,104 @@ discard block |
||
61 | 61 | <div class="gdmbx-row gdmbx-type-text gdmbx2-id-wpinv-number table-layout"> |
62 | 62 | <div class="gdmbx-th"><label for="wpinv_number"><?php echo $title['number']; ?></label></div> |
63 | 63 | <div class="gdmbx-td"> |
64 | - <input type="text" placeholder="<?php echo esc_attr( wpinv_format_invoice_number( 1 ) ); ?>" value="<?php echo esc_attr( $invoice_number );?>" id="wpinv_number" name="wpinv_number" class="regular-text"> |
|
64 | + <input type="text" placeholder="<?php echo esc_attr(wpinv_format_invoice_number(1)); ?>" value="<?php echo esc_attr($invoice_number); ?>" id="wpinv_number" name="wpinv_number" class="regular-text"> |
|
65 | 65 | </div> |
66 | 66 | </div> |
67 | - <?php do_action( 'wpinv_meta_box_details_inner', $post_id ); ?> |
|
68 | - <?php if ( !( $is_paid = $invoice->is_paid() ) || $discount_code ) { ?> |
|
67 | + <?php do_action('wpinv_meta_box_details_inner', $post_id); ?> |
|
68 | + <?php if (!($is_paid = $invoice->is_paid()) || $discount_code) { ?> |
|
69 | 69 | <div class="gdmbx-row gdmbx-type-text gdmbx2-id-wpinv-discount-code table-layout"> |
70 | - <div class="gdmbx-th"><label for="wpinv_discount_code"><?php _e( 'Discount Code:', 'invoicing' );?></label></div> |
|
70 | + <div class="gdmbx-th"><label for="wpinv_discount_code"><?php _e('Discount Code:', 'invoicing'); ?></label></div> |
|
71 | 71 | <div class="gdmbx-td"> |
72 | - <input type="text" value="<?php echo esc_attr( $discount_code ); ?>" id="wpinv_discount" class="medium-text" <?php echo ( $discount_code ? 'readonly' : '' ); ?> /><?php if ( !$is_paid ) { ?><input value="<?php echo esc_attr_e( 'Apply', 'invoicing' ); ?>" class="button button-small button-primary <?php echo ( $discount_code ? 'wpi-hide' : 'wpi-inlineb' ); ?>" id="wpinv-apply-code" type="button" /><input value="<?php echo esc_attr_e( 'Remove', 'invoicing' ); ?>" class="button button-small button-primary <?php echo ( $discount_code ? 'wpi-inlineb' : 'wpi-hide' ); ?>" id="wpinv-remove-code" type="button" /><?php } ?> |
|
72 | + <input type="text" value="<?php echo esc_attr($discount_code); ?>" id="wpinv_discount" class="medium-text" <?php echo ($discount_code ? 'readonly' : ''); ?> /><?php if (!$is_paid) { ?><input value="<?php echo esc_attr_e('Apply', 'invoicing'); ?>" class="button button-small button-primary <?php echo ($discount_code ? 'wpi-hide' : 'wpi-inlineb'); ?>" id="wpinv-apply-code" type="button" /><input value="<?php echo esc_attr_e('Remove', 'invoicing'); ?>" class="button button-small button-primary <?php echo ($discount_code ? 'wpi-inlineb' : 'wpi-hide'); ?>" id="wpinv-remove-code" type="button" /><?php } ?> |
|
73 | 73 | </div> |
74 | 74 | </div> |
75 | 75 | <?php } ?> |
76 | 76 | </div> |
77 | 77 | </div> |
78 | 78 | <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-save-send table-layout"> |
79 | - <p class="wpi-meta-row wpi-save-send"><label for="wpi_save_send"><?php _e( 'Send Invoice:', 'invoicing' ); ?></label> |
|
79 | + <p class="wpi-meta-row wpi-save-send"><label for="wpi_save_send"><?php _e('Send Invoice:', 'invoicing'); ?></label> |
|
80 | 80 | <select id="wpi_save_send" name="wpi_save_send"> |
81 | - <option value="1"><?php _e( 'Yes', 'invoicing' ); ?></option> |
|
82 | - <option value="" selected="selected"><?php _e( 'No', 'invoicing' ); ?></option> |
|
81 | + <option value="1"><?php _e('Yes', 'invoicing'); ?></option> |
|
82 | + <option value="" selected="selected"><?php _e('No', 'invoicing'); ?></option> |
|
83 | 83 | </select> |
84 | 84 | </p> |
85 | - <p class="wpi-meta-row wpi-send-info"><?php esc_attr_e( 'After save invoice this will send a copy of the invoice to the user’s email address.', 'invoicing' ); ?></p> |
|
85 | + <p class="wpi-meta-row wpi-send-info"><?php esc_attr_e('After save invoice this will send a copy of the invoice to the user’s email address.', 'invoicing'); ?></p> |
|
86 | 86 | </div> |
87 | -<?php wp_nonce_field( 'wpinv_details', 'wpinv_details_nonce' ) ;?> |
|
87 | +<?php wp_nonce_field('wpinv_details', 'wpinv_details_nonce'); ?> |
|
88 | 88 | <?php |
89 | 89 | } |
90 | 90 | |
91 | - public static function resend_invoice( $post ) { |
|
91 | + public static function resend_invoice($post) { |
|
92 | 92 | global $wpi_mb_invoice; |
93 | 93 | |
94 | - if ( empty( $wpi_mb_invoice ) ) { |
|
94 | + if (empty($wpi_mb_invoice)) { |
|
95 | 95 | return; |
96 | 96 | } |
97 | 97 | |
98 | 98 | $text = array( |
99 | - 'message' => esc_attr__( 'This will send a copy of the invoice to the user’s email address.', 'invoicing' ), |
|
100 | - 'button_text' => __( 'Resend Invoice', 'invoicing' ), |
|
99 | + 'message' => esc_attr__('This will send a copy of the invoice to the user’s email address.', 'invoicing'), |
|
100 | + 'button_text' => __('Resend Invoice', 'invoicing'), |
|
101 | 101 | ); |
102 | 102 | |
103 | 103 | $text = apply_filters('resend_invoice_metabox_text', $text); |
104 | - do_action( 'wpinv_metabox_resend_invoice_before', $wpi_mb_invoice ); |
|
104 | + do_action('wpinv_metabox_resend_invoice_before', $wpi_mb_invoice); |
|
105 | 105 | |
106 | - if ( $email = $wpi_mb_invoice->get_email() ) { |
|
107 | - $email_url = add_query_arg( array( 'wpi_action' => 'send_invoice', 'invoice_id' => $post->ID ) ); |
|
108 | - $reminder_url = add_query_arg( array( 'wpi_action' => 'send_reminder', 'invoice_id' => $post->ID ) ); |
|
106 | + if ($email = $wpi_mb_invoice->get_email()) { |
|
107 | + $email_url = add_query_arg(array('wpi_action' => 'send_invoice', 'invoice_id' => $post->ID)); |
|
108 | + $reminder_url = add_query_arg(array('wpi_action' => 'send_reminder', 'invoice_id' => $post->ID)); |
|
109 | 109 | ?> |
110 | 110 | <p class="wpi-meta-row wpi-resend-info"><?php echo $text['message']; ?></p> |
111 | - <p class="wpi-meta-row wpi-resend-email"><a title="<?php esc_attr_e( 'Send invoice to customer', 'invoicing' ); ?>" href="<?php echo esc_url( $email_url ); ?>" class="button button-secondary"><?php echo $text['button_text']; ?></a></p> |
|
112 | - <?php if ( wpinv_get_option( 'overdue_active' ) && $wpi_mb_invoice->needs_payment() && ( $due_date = $wpi_mb_invoice->get_due_date() ) ) { ?> |
|
113 | - <p class="wpi-meta-row wpi-send-reminder"><a title="<?php esc_attr_e( 'Send overdue reminder notification to customer', 'invoicing' ); ?>" href="<?php echo esc_url( $reminder_url ); ?>" class="button button-secondary"><?php esc_attr_e( 'Send Reminder', 'invoicing' ); ?></a></p> |
|
111 | + <p class="wpi-meta-row wpi-resend-email"><a title="<?php esc_attr_e('Send invoice to customer', 'invoicing'); ?>" href="<?php echo esc_url($email_url); ?>" class="button button-secondary"><?php echo $text['button_text']; ?></a></p> |
|
112 | + <?php if (wpinv_get_option('overdue_active') && $wpi_mb_invoice->needs_payment() && ($due_date = $wpi_mb_invoice->get_due_date())) { ?> |
|
113 | + <p class="wpi-meta-row wpi-send-reminder"><a title="<?php esc_attr_e('Send overdue reminder notification to customer', 'invoicing'); ?>" href="<?php echo esc_url($reminder_url); ?>" class="button button-secondary"><?php esc_attr_e('Send Reminder', 'invoicing'); ?></a></p> |
|
114 | 114 | <?php } ?> |
115 | 115 | <?php |
116 | 116 | } |
117 | 117 | |
118 | - do_action( 'wpinv_metabox_resend_invoice_after', $wpi_mb_invoice ); |
|
118 | + do_action('wpinv_metabox_resend_invoice_after', $wpi_mb_invoice); |
|
119 | 119 | } |
120 | 120 | |
121 | - public static function subscriptions( $post ) { |
|
121 | + public static function subscriptions($post) { |
|
122 | 122 | global $wpi_mb_invoice; |
123 | 123 | |
124 | 124 | $invoice = $wpi_mb_invoice; |
125 | 125 | |
126 | - if ( !empty( $invoice ) && $invoice->is_recurring() && $invoice->is_parent() ) { |
|
126 | + if (!empty($invoice) && $invoice->is_recurring() && $invoice->is_parent()) { |
|
127 | 127 | $payments = $invoice->get_child_payments(); |
128 | 128 | |
129 | 129 | $total_payments = (int)$invoice->get_total_payments(); |
130 | 130 | $subscription = $invoice->get_subscription_data(); |
131 | 131 | |
132 | - $billing_cycle = wpinv_get_billing_cycle( $subscription['initial_amount'], $subscription['recurring_amount'], $subscription['period'], $subscription['interval'], $subscription['bill_times'], $subscription['trial_period'], $subscription['trial_interval'], $invoice->get_currency() ); |
|
133 | - $times_billed = $total_payments . ' / ' . ( ( (int)$subscription['bill_times'] == 0 ) ? __( 'Until cancelled', 'invoicing' ) : $subscription['bill_times'] ); |
|
132 | + $billing_cycle = wpinv_get_billing_cycle($subscription['initial_amount'], $subscription['recurring_amount'], $subscription['period'], $subscription['interval'], $subscription['bill_times'], $subscription['trial_period'], $subscription['trial_interval'], $invoice->get_currency()); |
|
133 | + $times_billed = $total_payments . ' / ' . (((int)$subscription['bill_times'] == 0) ? __('Until cancelled', 'invoicing') : $subscription['bill_times']); |
|
134 | 134 | $subscription_status = $invoice->get_subscription_status(); |
135 | 135 | ?> |
136 | - <p class="wpi-meta-row wpi-sub-label"><?php _e( 'Recurring Payment', 'invoicing' );?></p> |
|
137 | - <?php if ( $subscription_id = $invoice->get_subscription_id() ) { ?> |
|
138 | - <p class="wpi-meta-row wpi-sub-id"><label><?php _e( 'Subscription ID:', 'invoicing' );?> </label><?php echo $subscription_id; ?></p> |
|
136 | + <p class="wpi-meta-row wpi-sub-label"><?php _e('Recurring Payment', 'invoicing'); ?></p> |
|
137 | + <?php if ($subscription_id = $invoice->get_subscription_id()) { ?> |
|
138 | + <p class="wpi-meta-row wpi-sub-id"><label><?php _e('Subscription ID:', 'invoicing'); ?> </label><?php echo $subscription_id; ?></p> |
|
139 | 139 | <?php } ?> |
140 | - <p class="wpi-meta-row wpi-bill-cycle"><label><?php _e( 'Billing Cycle:', 'invoicing' );?> </label><?php echo $billing_cycle; ?></p> |
|
141 | - <p class="wpi-meta-row wpi-billed-times"><label><?php _e( 'Times Billed:', 'invoicing' );?> </label><?php echo $times_billed; ?></p> |
|
142 | - <?php if ( !empty( $payments ) || $invoice->is_paid() ) { ?> |
|
143 | - <p class="wpi-meta-row wpi-start-date"><label><?php _e( 'Start Date:', 'invoicing' );?> </label><?php echo $invoice->get_subscription_start(); ?></p> |
|
144 | - <p class="wpi-meta-row wpi-end-date"><label><?php _e( 'Expiration Date:', 'invoicing' );?> </label><?php echo $invoice->get_subscription_end(); ?></p> |
|
145 | - <?php if ( $status_label = $invoice->get_subscription_status_label( $subscription_status ) ) { ?> |
|
146 | - <p class="wpi-meta-row wpi-sub-status"><label><?php _e( 'Subscription Status:', 'invoicing' );?> </label><?php echo $status_label; ?></p> |
|
140 | + <p class="wpi-meta-row wpi-bill-cycle"><label><?php _e('Billing Cycle:', 'invoicing'); ?> </label><?php echo $billing_cycle; ?></p> |
|
141 | + <p class="wpi-meta-row wpi-billed-times"><label><?php _e('Times Billed:', 'invoicing'); ?> </label><?php echo $times_billed; ?></p> |
|
142 | + <?php if (!empty($payments) || $invoice->is_paid()) { ?> |
|
143 | + <p class="wpi-meta-row wpi-start-date"><label><?php _e('Start Date:', 'invoicing'); ?> </label><?php echo $invoice->get_subscription_start(); ?></p> |
|
144 | + <p class="wpi-meta-row wpi-end-date"><label><?php _e('Expiration Date:', 'invoicing'); ?> </label><?php echo $invoice->get_subscription_end(); ?></p> |
|
145 | + <?php if ($status_label = $invoice->get_subscription_status_label($subscription_status)) { ?> |
|
146 | + <p class="wpi-meta-row wpi-sub-status"><label><?php _e('Subscription Status:', 'invoicing'); ?> </label><?php echo $status_label; ?></p> |
|
147 | 147 | <?php } ?> |
148 | - <?php if ( $subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date() ) { ?> |
|
149 | - <p class="wpi-meta-row wpi-trial-date"><label><?php _e( 'Trial Until:', 'invoicing' );?> </label><?php echo $trial_end_date; ?></p> |
|
148 | + <?php if ($subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date()) { ?> |
|
149 | + <p class="wpi-meta-row wpi-trial-date"><label><?php _e('Trial Until:', 'invoicing'); ?> </label><?php echo $trial_end_date; ?></p> |
|
150 | 150 | <?php } ?> |
151 | - <?php if ( $cancelled_date = $invoice->get_cancelled_date() ) { ?> |
|
152 | - <p class="wpi-meta-row wpi-cancel-date"><label><?php _e( 'Cancelled On:', 'invoicing' );?> </label><?php echo $cancelled_date; ?></p> |
|
151 | + <?php if ($cancelled_date = $invoice->get_cancelled_date()) { ?> |
|
152 | + <p class="wpi-meta-row wpi-cancel-date"><label><?php _e('Cancelled On:', 'invoicing'); ?> </label><?php echo $cancelled_date; ?></p> |
|
153 | 153 | <?php } ?> |
154 | - <?php if ( !empty( $payments ) ) { ?> |
|
155 | - <p><strong><?php _e( 'Renewal Payments:', 'invoicing' ); ?></strong></p> |
|
154 | + <?php if (!empty($payments)) { ?> |
|
155 | + <p><strong><?php _e('Renewal Payments:', 'invoicing'); ?></strong></p> |
|
156 | 156 | <ul id="wpi-sub-payments"> |
157 | - <?php foreach ( $payments as $invoice_id ) { ?> |
|
157 | + <?php foreach ($payments as $invoice_id) { ?> |
|
158 | 158 | <li> |
159 | - <a href="<?php echo esc_url( get_edit_post_link( $invoice_id ) ); ?>"><?php echo wpinv_get_invoice_number( $invoice_id ); ?></a> – |
|
160 | - <span><?php echo wpinv_get_invoice_date( $invoice_id ); ?> – </span> |
|
161 | - <span><?php echo wpinv_payment_total( $invoice_id, true ); ?></span> |
|
159 | + <a href="<?php echo esc_url(get_edit_post_link($invoice_id)); ?>"><?php echo wpinv_get_invoice_number($invoice_id); ?></a> – |
|
160 | + <span><?php echo wpinv_get_invoice_date($invoice_id); ?> – </span> |
|
161 | + <span><?php echo wpinv_payment_total($invoice_id, true); ?></span> |
|
162 | 162 | </li> |
163 | 163 | <?php } ?> |
164 | 164 | </ul> |
@@ -166,47 +166,47 @@ discard block |
||
166 | 166 | } |
167 | 167 | } |
168 | 168 | |
169 | - public static function renewals( $post ) { |
|
169 | + public static function renewals($post) { |
|
170 | 170 | global $wpi_mb_invoice; |
171 | 171 | |
172 | - if ( wpinv_is_subscription_payment( $wpi_mb_invoice ) ) { |
|
173 | - $parent_url = get_edit_post_link( $wpi_mb_invoice->parent_invoice ); |
|
174 | - $parent_id = wpinv_get_invoice_number( $wpi_mb_invoice->parent_invoice ); |
|
172 | + if (wpinv_is_subscription_payment($wpi_mb_invoice)) { |
|
173 | + $parent_url = get_edit_post_link($wpi_mb_invoice->parent_invoice); |
|
174 | + $parent_id = wpinv_get_invoice_number($wpi_mb_invoice->parent_invoice); |
|
175 | 175 | ?> |
176 | - <p class="wpi-meta-row wpi-sub-id"><label><?php _e( 'Subscription ID:', 'invoicing' );?> </label><?php echo $wpi_mb_invoice->get_subscription_id(); ?></p> |
|
177 | - <p class="wpi-meta-row wpi-parent-id"><label><?php _e( 'Parent Invoice:', 'invoicing' );?> </label><a href="<?php echo esc_url( $parent_url ); ?>"><?php echo $parent_id; ?></a></p> |
|
176 | + <p class="wpi-meta-row wpi-sub-id"><label><?php _e('Subscription ID:', 'invoicing'); ?> </label><?php echo $wpi_mb_invoice->get_subscription_id(); ?></p> |
|
177 | + <p class="wpi-meta-row wpi-parent-id"><label><?php _e('Parent Invoice:', 'invoicing'); ?> </label><a href="<?php echo esc_url($parent_url); ?>"><?php echo $parent_id; ?></a></p> |
|
178 | 178 | <?php |
179 | 179 | } |
180 | 180 | } |
181 | 181 | |
182 | - public static function payment_meta( $post ) { |
|
182 | + public static function payment_meta($post) { |
|
183 | 183 | global $wpi_mb_invoice; |
184 | 184 | |
185 | - $set_dateway = empty( $wpi_mb_invoice->gateway ) ? true : false; |
|
186 | - if ( !$set_dateway && !$wpi_mb_invoice->get_meta( '_wpinv_checkout', true ) && !$wpi_mb_invoice->is_paid() ) { |
|
185 | + $set_dateway = empty($wpi_mb_invoice->gateway) ? true : false; |
|
186 | + if (!$set_dateway && !$wpi_mb_invoice->get_meta('_wpinv_checkout', true) && !$wpi_mb_invoice->is_paid()) { |
|
187 | 187 | $set_dateway = true; |
188 | 188 | } |
189 | 189 | |
190 | 190 | ?> |
191 | 191 | <p class="wpi-meta-row"> |
192 | - <?php if ( $set_dateway ) { $gateways = wpinv_get_enabled_payment_gateways( true ); ?> |
|
193 | - <label for="wpinv_gateway"><?php _e( 'Gateway:', 'invoicing' ) ; ?></label> |
|
192 | + <?php if ($set_dateway) { $gateways = wpinv_get_enabled_payment_gateways(true); ?> |
|
193 | + <label for="wpinv_gateway"><?php _e('Gateway:', 'invoicing'); ?></label> |
|
194 | 194 | <select required="required" id="wpinv_gateway" name="wpinv_gateway"> |
195 | - <?php foreach ( $gateways as $name => $gateway ) { |
|
196 | - if ( $wpi_mb_invoice->is_recurring() && !wpinv_gateway_support_subscription( $name ) ) { |
|
195 | + <?php foreach ($gateways as $name => $gateway) { |
|
196 | + if ($wpi_mb_invoice->is_recurring() && !wpinv_gateway_support_subscription($name)) { |
|
197 | 197 | continue; |
198 | 198 | } |
199 | 199 | ?> |
200 | - <option value="<?php echo $name;?>" <?php selected( $wpi_mb_invoice->gateway, $name );?>><?php echo !empty( $gateway['admin_label'] ) ? $gateway['admin_label'] : $gateway['checkout_label']; ?></option> |
|
200 | + <option value="<?php echo $name; ?>" <?php selected($wpi_mb_invoice->gateway, $name); ?>><?php echo !empty($gateway['admin_label']) ? $gateway['admin_label'] : $gateway['checkout_label']; ?></option> |
|
201 | 201 | <?php } ?> |
202 | 202 | </select> |
203 | 203 | <?php } else { |
204 | - echo wp_sprintf( __( '<label>Gateway:</label> %s', 'invoicing' ), wpinv_get_gateway_checkout_label( $wpi_mb_invoice->gateway ) ); |
|
204 | + echo wp_sprintf(__('<label>Gateway:</label> %s', 'invoicing'), wpinv_get_gateway_checkout_label($wpi_mb_invoice->gateway)); |
|
205 | 205 | } ?> |
206 | 206 | </p> |
207 | - <?php if ( $wpi_mb_invoice->is_paid() ) { ?> |
|
208 | - <p class="wpi-meta-row"><?php echo wp_sprintf( __( '<label>Key:</label> %s', 'invoicing' ), $wpi_mb_invoice->get_key() ); ?></p> |
|
209 | - <p class="wpi-meta-row"><?php echo wp_sprintf( __( '<label>Transaction ID:</label> %s', 'invoicing' ), wpinv_payment_link_transaction_id( $wpi_mb_invoice ) ); ?></p> |
|
207 | + <?php if ($wpi_mb_invoice->is_paid()) { ?> |
|
208 | + <p class="wpi-meta-row"><?php echo wp_sprintf(__('<label>Key:</label> %s', 'invoicing'), $wpi_mb_invoice->get_key()); ?></p> |
|
209 | + <p class="wpi-meta-row"><?php echo wp_sprintf(__('<label>Transaction ID:</label> %s', 'invoicing'), wpinv_payment_link_transaction_id($wpi_mb_invoice)); ?></p> |
|
210 | 210 | <?php } ?> |
211 | 211 | <?php |
212 | 212 | } |
@@ -7,109 +7,109 @@ 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 | -if ( !is_admin() ) { |
|
15 | - add_filter( 'template_include', 'wpinv_template', 10, 1 ); |
|
16 | - add_action( 'wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar' ); |
|
17 | - add_action( 'wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions' ); |
|
18 | - add_action( 'wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions' ); |
|
14 | +if (!is_admin()) { |
|
15 | + add_filter('template_include', 'wpinv_template', 10, 1); |
|
16 | + add_action('wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar'); |
|
17 | + add_action('wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions'); |
|
18 | + add_action('wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions'); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | function wpinv_template_path() { |
22 | - return apply_filters( 'wpinv_template_path', 'invoicing/' ); |
|
22 | + return apply_filters('wpinv_template_path', 'invoicing/'); |
|
23 | 23 | } |
24 | 24 | |
25 | -function wpinv_post_class( $classes, $class, $post_id ) { |
|
25 | +function wpinv_post_class($classes, $class, $post_id) { |
|
26 | 26 | global $pagenow, $typenow; |
27 | 27 | |
28 | - if ( $pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type( $post_id ) == $typenow && get_post_meta( $post_id, '_wpinv_type', true ) == 'package' ) { |
|
28 | + if ($pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type($post_id) == $typenow && get_post_meta($post_id, '_wpinv_type', true) == 'package') { |
|
29 | 29 | $classes[] = 'wpi-gd-package'; |
30 | 30 | } |
31 | 31 | return $classes; |
32 | 32 | } |
33 | -add_filter( 'post_class', 'wpinv_post_class', 10, 3 ); |
|
33 | +add_filter('post_class', 'wpinv_post_class', 10, 3); |
|
34 | 34 | |
35 | -function wpinv_display_invoice_top_bar( $invoice ) { |
|
36 | - if ( empty( $invoice ) ) { |
|
35 | +function wpinv_display_invoice_top_bar($invoice) { |
|
36 | + if (empty($invoice)) { |
|
37 | 37 | return; |
38 | 38 | } |
39 | 39 | ?> |
40 | 40 | <div class="row wpinv-top-bar no-print"> |
41 | 41 | <div class="container"> |
42 | 42 | <div class="col-xs-6"> |
43 | - <?php do_action( 'wpinv_invoice_top_bar_left', $invoice );?> |
|
43 | + <?php do_action('wpinv_invoice_top_bar_left', $invoice); ?> |
|
44 | 44 | </div> |
45 | 45 | <div class="col-xs-6 text-right"> |
46 | - <?php do_action( 'wpinv_invoice_top_bar_right', $invoice );?> |
|
46 | + <?php do_action('wpinv_invoice_top_bar_right', $invoice); ?> |
|
47 | 47 | </div> |
48 | 48 | </div> |
49 | 49 | </div> |
50 | 50 | <?php |
51 | 51 | } |
52 | 52 | |
53 | -function wpinv_invoice_display_left_actions( $invoice ) { |
|
54 | - if ( empty( $invoice ) ) { |
|
53 | +function wpinv_invoice_display_left_actions($invoice) { |
|
54 | + if (empty($invoice)) { |
|
55 | 55 | return; |
56 | 56 | } |
57 | 57 | |
58 | - if($invoice->post_type == 'wpi_invoice'){ |
|
58 | + if ($invoice->post_type == 'wpi_invoice') { |
|
59 | 59 | |
60 | 60 | $user_id = (int)$invoice->get_user_id(); |
61 | 61 | $current_user_id = (int)get_current_user_id(); |
62 | 62 | |
63 | - if ( $user_id > 0 && $user_id == $current_user_id && $invoice->needs_payment() ) { |
|
63 | + if ($user_id > 0 && $user_id == $current_user_id && $invoice->needs_payment()) { |
|
64 | 64 | ?> |
65 | - <a class="btn btn-success btn-sm" title="<?php esc_attr_e( 'Pay This Invoice', 'invoicing' ); ?>" href="<?php echo esc_url( $invoice->get_checkout_payment_url() ); ?>"><?php _e( 'Pay For Invoice', 'invoicing' ); ?></a> |
|
65 | + <a class="btn btn-success btn-sm" title="<?php esc_attr_e('Pay This Invoice', 'invoicing'); ?>" href="<?php echo esc_url($invoice->get_checkout_payment_url()); ?>"><?php _e('Pay For Invoice', 'invoicing'); ?></a> |
|
66 | 66 | <?php |
67 | 67 | } |
68 | 68 | } |
69 | 69 | do_action('wpinv_invoice_display_left_actions', $invoice); |
70 | 70 | } |
71 | 71 | |
72 | -function wpinv_invoice_display_right_actions( $invoice ) { |
|
73 | - if ( empty( $invoice ) ) return; //Exit if invoice is not set. |
|
72 | +function wpinv_invoice_display_right_actions($invoice) { |
|
73 | + if (empty($invoice)) return; //Exit if invoice is not set. |
|
74 | 74 | |
75 | - if($invoice->post_type == 'wpi_invoice'){ |
|
75 | + if ($invoice->post_type == 'wpi_invoice') { |
|
76 | 76 | $user_id = (int)$invoice->get_user_id(); |
77 | 77 | $current_user_id = (int)get_current_user_id(); |
78 | 78 | |
79 | - if ( $user_id > 0 && $user_id == $current_user_id ) { |
|
79 | + if ($user_id > 0 && $user_id == $current_user_id) { |
|
80 | 80 | ?> |
81 | - <a class="btn btn-primary btn-sm" onclick="window.print();" href="javascript:void(0)"><?php _e( 'Print Invoice', 'invoicing' ); ?></a> |
|
82 | - <a class="btn btn-warning btn-sm" href="<?php echo esc_url( wpinv_get_history_page_uri() ); ?>"><?php _e( 'Invoice History', 'invoicing' ); ?></a> |
|
81 | + <a class="btn btn-primary btn-sm" onclick="window.print();" href="javascript:void(0)"><?php _e('Print Invoice', 'invoicing'); ?></a> |
|
82 | + <a class="btn btn-warning btn-sm" href="<?php echo esc_url(wpinv_get_history_page_uri()); ?>"><?php _e('Invoice History', 'invoicing'); ?></a> |
|
83 | 83 | <?php } |
84 | 84 | } |
85 | 85 | do_action('wpinv_invoice_display_right_actions', $invoice); |
86 | 86 | } |
87 | 87 | |
88 | -function wpinv_before_invoice_content( $content ) { |
|
88 | +function wpinv_before_invoice_content($content) { |
|
89 | 89 | global $post; |
90 | 90 | |
91 | - if ( $post && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) { |
|
91 | + if ($post && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) { |
|
92 | 92 | ob_start(); |
93 | - do_action( 'wpinv_before_invoice_content', $post->ID ); |
|
93 | + do_action('wpinv_before_invoice_content', $post->ID); |
|
94 | 94 | $content = ob_get_clean() . $content; |
95 | 95 | } |
96 | 96 | |
97 | 97 | return $content; |
98 | 98 | } |
99 | -add_filter( 'the_content', 'wpinv_before_invoice_content' ); |
|
99 | +add_filter('the_content', 'wpinv_before_invoice_content'); |
|
100 | 100 | |
101 | -function wpinv_after_invoice_content( $content ) { |
|
101 | +function wpinv_after_invoice_content($content) { |
|
102 | 102 | global $post; |
103 | 103 | |
104 | - if ( $post && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) { |
|
104 | + if ($post && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) { |
|
105 | 105 | ob_start(); |
106 | - do_action( 'wpinv_after_invoice_content', $post->ID ); |
|
106 | + do_action('wpinv_after_invoice_content', $post->ID); |
|
107 | 107 | $content .= ob_get_clean(); |
108 | 108 | } |
109 | 109 | |
110 | 110 | return $content; |
111 | 111 | } |
112 | -add_filter( 'the_content', 'wpinv_after_invoice_content' ); |
|
112 | +add_filter('the_content', 'wpinv_after_invoice_content'); |
|
113 | 113 | |
114 | 114 | function wpinv_get_templates_dir() { |
115 | 115 | return WPINV_PLUGIN_DIR . 'templates'; |
@@ -119,105 +119,105 @@ discard block |
||
119 | 119 | return WPINV_PLUGIN_URL . 'templates'; |
120 | 120 | } |
121 | 121 | |
122 | -function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
123 | - if ( ! empty( $args ) && is_array( $args ) ) { |
|
124 | - extract( $args ); |
|
122 | +function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
123 | + if (!empty($args) && is_array($args)) { |
|
124 | + extract($args); |
|
125 | 125 | } |
126 | 126 | |
127 | - $located = wpinv_locate_template( $template_name, $template_path, $default_path ); |
|
128 | - if ( ! file_exists( $located ) ) { |
|
129 | - _doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' ); |
|
127 | + $located = wpinv_locate_template($template_name, $template_path, $default_path); |
|
128 | + if (!file_exists($located)) { |
|
129 | + _doing_it_wrong(__FUNCTION__, sprintf('<code>%s</code> does not exist.', $located), '2.1'); |
|
130 | 130 | return; |
131 | 131 | } |
132 | 132 | |
133 | 133 | // Allow 3rd party plugin filter template file from their plugin. |
134 | - $located = apply_filters( 'wpinv_get_template', $located, $template_name, $args, $template_path, $default_path ); |
|
134 | + $located = apply_filters('wpinv_get_template', $located, $template_name, $args, $template_path, $default_path); |
|
135 | 135 | |
136 | - do_action( 'wpinv_before_template_part', $template_name, $template_path, $located, $args ); |
|
136 | + do_action('wpinv_before_template_part', $template_name, $template_path, $located, $args); |
|
137 | 137 | |
138 | - include( $located ); |
|
138 | + include($located); |
|
139 | 139 | |
140 | - do_action( 'wpinv_after_template_part', $template_name, $template_path, $located, $args ); |
|
140 | + do_action('wpinv_after_template_part', $template_name, $template_path, $located, $args); |
|
141 | 141 | } |
142 | 142 | |
143 | -function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
143 | +function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
144 | 144 | ob_start(); |
145 | - wpinv_get_template( $template_name, $args, $template_path, $default_path ); |
|
145 | + wpinv_get_template($template_name, $args, $template_path, $default_path); |
|
146 | 146 | return ob_get_clean(); |
147 | 147 | } |
148 | 148 | |
149 | -function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) { |
|
150 | - if ( ! $template_path ) { |
|
149 | +function wpinv_locate_template($template_name, $template_path = '', $default_path = '') { |
|
150 | + if (!$template_path) { |
|
151 | 151 | $template_path = wpinv_template_path(); |
152 | 152 | } |
153 | 153 | |
154 | - if ( ! $default_path ) { |
|
154 | + if (!$default_path) { |
|
155 | 155 | $default_path = WPINV_PLUGIN_DIR . 'templates/'; |
156 | 156 | } |
157 | 157 | |
158 | 158 | // Look within passed path within the theme - this is priority. |
159 | 159 | $template = locate_template( |
160 | 160 | array( |
161 | - trailingslashit( $template_path ) . $template_name, |
|
161 | + trailingslashit($template_path) . $template_name, |
|
162 | 162 | $template_name |
163 | 163 | ) |
164 | 164 | ); |
165 | 165 | |
166 | 166 | // Get default templates/ |
167 | - if ( !$template && $default_path ) { |
|
168 | - $template = trailingslashit( $default_path ) . $template_name; |
|
167 | + if (!$template && $default_path) { |
|
168 | + $template = trailingslashit($default_path) . $template_name; |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | // Return what we found. |
172 | - return apply_filters( 'wpinv_locate_template', $template, $template_name, $template_path ); |
|
172 | + return apply_filters('wpinv_locate_template', $template, $template_name, $template_path); |
|
173 | 173 | } |
174 | 174 | |
175 | -function wpinv_get_template_part( $slug, $name = null, $load = true ) { |
|
176 | - do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
175 | +function wpinv_get_template_part($slug, $name = null, $load = true) { |
|
176 | + do_action('get_template_part_' . $slug, $slug, $name); |
|
177 | 177 | |
178 | 178 | // Setup possible parts |
179 | 179 | $templates = array(); |
180 | - if ( isset( $name ) ) |
|
180 | + if (isset($name)) |
|
181 | 181 | $templates[] = $slug . '-' . $name . '.php'; |
182 | 182 | $templates[] = $slug . '.php'; |
183 | 183 | |
184 | 184 | // Allow template parts to be filtered |
185 | - $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
185 | + $templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name); |
|
186 | 186 | |
187 | 187 | // Return the part that is found |
188 | - return wpinv_locate_tmpl( $templates, $load, false ); |
|
188 | + return wpinv_locate_tmpl($templates, $load, false); |
|
189 | 189 | } |
190 | 190 | |
191 | -function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) { |
|
191 | +function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) { |
|
192 | 192 | // No file found yet |
193 | 193 | $located = false; |
194 | 194 | |
195 | 195 | // Try to find a template file |
196 | - foreach ( (array)$template_names as $template_name ) { |
|
196 | + foreach ((array)$template_names as $template_name) { |
|
197 | 197 | |
198 | 198 | // Continue if template is empty |
199 | - if ( empty( $template_name ) ) |
|
199 | + if (empty($template_name)) |
|
200 | 200 | continue; |
201 | 201 | |
202 | 202 | // Trim off any slashes from the template name |
203 | - $template_name = ltrim( $template_name, '/' ); |
|
203 | + $template_name = ltrim($template_name, '/'); |
|
204 | 204 | |
205 | 205 | // try locating this template file by looping through the template paths |
206 | - foreach( wpinv_get_theme_template_paths() as $template_path ) { |
|
206 | + foreach (wpinv_get_theme_template_paths() as $template_path) { |
|
207 | 207 | |
208 | - if( file_exists( $template_path . $template_name ) ) { |
|
208 | + if (file_exists($template_path . $template_name)) { |
|
209 | 209 | $located = $template_path . $template_name; |
210 | 210 | break; |
211 | 211 | } |
212 | 212 | } |
213 | 213 | |
214 | - if( !empty( $located ) ) { |
|
214 | + if (!empty($located)) { |
|
215 | 215 | break; |
216 | 216 | } |
217 | 217 | } |
218 | 218 | |
219 | - if ( ( true == $load ) && ! empty( $located ) ) |
|
220 | - load_template( $located, $require_once ); |
|
219 | + if ((true == $load) && !empty($located)) |
|
220 | + load_template($located, $require_once); |
|
221 | 221 | |
222 | 222 | return $located; |
223 | 223 | } |
@@ -226,143 +226,143 @@ discard block |
||
226 | 226 | $template_dir = wpinv_get_theme_template_dir_name(); |
227 | 227 | |
228 | 228 | $file_paths = array( |
229 | - 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
230 | - 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
229 | + 1 => trailingslashit(get_stylesheet_directory()) . $template_dir, |
|
230 | + 10 => trailingslashit(get_template_directory()) . $template_dir, |
|
231 | 231 | 100 => wpinv_get_templates_dir() |
232 | 232 | ); |
233 | 233 | |
234 | - $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
234 | + $file_paths = apply_filters('wpinv_template_paths', $file_paths); |
|
235 | 235 | |
236 | 236 | // sort the file paths based on priority |
237 | - ksort( $file_paths, SORT_NUMERIC ); |
|
237 | + ksort($file_paths, SORT_NUMERIC); |
|
238 | 238 | |
239 | - return array_map( 'trailingslashit', $file_paths ); |
|
239 | + return array_map('trailingslashit', $file_paths); |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | function wpinv_get_theme_template_dir_name() { |
243 | - return trailingslashit( apply_filters( 'wpinv_templates_dir', 'wpinv_templates' ) ); |
|
243 | + return trailingslashit(apply_filters('wpinv_templates_dir', 'wpinv_templates')); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | function wpinv_checkout_meta_tags() { |
247 | 247 | |
248 | 248 | $pages = array(); |
249 | - $pages[] = wpinv_get_option( 'success_page' ); |
|
250 | - $pages[] = wpinv_get_option( 'failure_page' ); |
|
251 | - $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
249 | + $pages[] = wpinv_get_option('success_page'); |
|
250 | + $pages[] = wpinv_get_option('failure_page'); |
|
251 | + $pages[] = wpinv_get_option('invoice_history_page'); |
|
252 | 252 | |
253 | - if( !wpinv_is_checkout() && !is_page( $pages ) ) { |
|
253 | + if (!wpinv_is_checkout() && !is_page($pages)) { |
|
254 | 254 | return; |
255 | 255 | } |
256 | 256 | |
257 | 257 | echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
258 | 258 | } |
259 | -add_action( 'wp_head', 'wpinv_checkout_meta_tags' ); |
|
259 | +add_action('wp_head', 'wpinv_checkout_meta_tags'); |
|
260 | 260 | |
261 | -function wpinv_add_body_classes( $class ) { |
|
261 | +function wpinv_add_body_classes($class) { |
|
262 | 262 | $classes = (array)$class; |
263 | 263 | |
264 | - if( wpinv_is_checkout() ) { |
|
264 | + if (wpinv_is_checkout()) { |
|
265 | 265 | $classes[] = 'wpinv-checkout'; |
266 | 266 | $classes[] = 'wpinv-page'; |
267 | 267 | } |
268 | 268 | |
269 | - if( wpinv_is_success_page() ) { |
|
269 | + if (wpinv_is_success_page()) { |
|
270 | 270 | $classes[] = 'wpinv-success'; |
271 | 271 | $classes[] = 'wpinv-page'; |
272 | 272 | } |
273 | 273 | |
274 | - if( wpinv_is_failed_transaction_page() ) { |
|
274 | + if (wpinv_is_failed_transaction_page()) { |
|
275 | 275 | $classes[] = 'wpinv-failed-transaction'; |
276 | 276 | $classes[] = 'wpinv-page'; |
277 | 277 | } |
278 | 278 | |
279 | - if( wpinv_is_invoice_history_page() ) { |
|
279 | + if (wpinv_is_invoice_history_page()) { |
|
280 | 280 | $classes[] = 'wpinv-history'; |
281 | 281 | $classes[] = 'wpinv-page'; |
282 | 282 | } |
283 | 283 | |
284 | - if( wpinv_is_test_mode() ) { |
|
284 | + if (wpinv_is_test_mode()) { |
|
285 | 285 | $classes[] = 'wpinv-test-mode'; |
286 | 286 | $classes[] = 'wpinv-page'; |
287 | 287 | } |
288 | 288 | |
289 | - return array_unique( $classes ); |
|
289 | + return array_unique($classes); |
|
290 | 290 | } |
291 | -add_filter( 'body_class', 'wpinv_add_body_classes' ); |
|
291 | +add_filter('body_class', 'wpinv_add_body_classes'); |
|
292 | 292 | |
293 | -function wpinv_html_dropdown( $name = 'wpinv_discounts', $selected = 0, $status = '' ) { |
|
294 | - $args = array( 'nopaging' => true ); |
|
293 | +function wpinv_html_dropdown($name = 'wpinv_discounts', $selected = 0, $status = '') { |
|
294 | + $args = array('nopaging' => true); |
|
295 | 295 | |
296 | - if ( ! empty( $status ) ) |
|
296 | + if (!empty($status)) |
|
297 | 297 | $args['post_status'] = $status; |
298 | 298 | |
299 | - $discounts = wpinv_get_discounts( $args ); |
|
299 | + $discounts = wpinv_get_discounts($args); |
|
300 | 300 | $options = array(); |
301 | 301 | |
302 | - if ( $discounts ) { |
|
303 | - foreach ( $discounts as $discount ) { |
|
304 | - $options[ absint( $discount->ID ) ] = esc_html( get_the_title( $discount->ID ) ); |
|
302 | + if ($discounts) { |
|
303 | + foreach ($discounts as $discount) { |
|
304 | + $options[absint($discount->ID)] = esc_html(get_the_title($discount->ID)); |
|
305 | 305 | } |
306 | 306 | } else { |
307 | - $options[0] = __( 'No discounts found', 'invoicing' ); |
|
307 | + $options[0] = __('No discounts found', 'invoicing'); |
|
308 | 308 | } |
309 | 309 | |
310 | - $output = wpinv_html_select( array( |
|
310 | + $output = wpinv_html_select(array( |
|
311 | 311 | 'name' => $name, |
312 | 312 | 'selected' => $selected, |
313 | 313 | 'options' => $options, |
314 | 314 | 'show_option_all' => false, |
315 | 315 | 'show_option_none' => false, |
316 | - ) ); |
|
316 | + )); |
|
317 | 317 | |
318 | 318 | return $output; |
319 | 319 | } |
320 | 320 | |
321 | -function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) { |
|
322 | - $current = date( 'Y' ); |
|
323 | - $start_year = $current - absint( $years_before ); |
|
324 | - $end_year = $current + absint( $years_after ); |
|
325 | - $selected = empty( $selected ) ? date( 'Y' ) : $selected; |
|
321 | +function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) { |
|
322 | + $current = date('Y'); |
|
323 | + $start_year = $current - absint($years_before); |
|
324 | + $end_year = $current + absint($years_after); |
|
325 | + $selected = empty($selected) ? date('Y') : $selected; |
|
326 | 326 | $options = array(); |
327 | 327 | |
328 | - while ( $start_year <= $end_year ) { |
|
329 | - $options[ absint( $start_year ) ] = $start_year; |
|
328 | + while ($start_year <= $end_year) { |
|
329 | + $options[absint($start_year)] = $start_year; |
|
330 | 330 | $start_year++; |
331 | 331 | } |
332 | 332 | |
333 | - $output = wpinv_html_select( array( |
|
333 | + $output = wpinv_html_select(array( |
|
334 | 334 | 'name' => $name, |
335 | 335 | 'selected' => $selected, |
336 | 336 | 'options' => $options, |
337 | 337 | 'show_option_all' => false, |
338 | 338 | 'show_option_none' => false |
339 | - ) ); |
|
339 | + )); |
|
340 | 340 | |
341 | 341 | return $output; |
342 | 342 | } |
343 | 343 | |
344 | -function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) { |
|
344 | +function wpinv_html_month_dropdown($name = 'month', $selected = 0) { |
|
345 | 345 | $month = 1; |
346 | 346 | $options = array(); |
347 | - $selected = empty( $selected ) ? date( 'n' ) : $selected; |
|
347 | + $selected = empty($selected) ? date('n') : $selected; |
|
348 | 348 | |
349 | - while ( $month <= 12 ) { |
|
350 | - $options[ absint( $month ) ] = wpinv_month_num_to_name( $month ); |
|
349 | + while ($month <= 12) { |
|
350 | + $options[absint($month)] = wpinv_month_num_to_name($month); |
|
351 | 351 | $month++; |
352 | 352 | } |
353 | 353 | |
354 | - $output = wpinv_html_select( array( |
|
354 | + $output = wpinv_html_select(array( |
|
355 | 355 | 'name' => $name, |
356 | 356 | 'selected' => $selected, |
357 | 357 | 'options' => $options, |
358 | 358 | 'show_option_all' => false, |
359 | 359 | 'show_option_none' => false |
360 | - ) ); |
|
360 | + )); |
|
361 | 361 | |
362 | 362 | return $output; |
363 | 363 | } |
364 | 364 | |
365 | -function wpinv_html_select( $args = array() ) { |
|
365 | +function wpinv_html_select($args = array()) { |
|
366 | 366 | $defaults = array( |
367 | 367 | 'options' => array(), |
368 | 368 | 'name' => null, |
@@ -372,8 +372,8 @@ discard block |
||
372 | 372 | 'chosen' => false, |
373 | 373 | 'placeholder' => null, |
374 | 374 | 'multiple' => false, |
375 | - 'show_option_all' => _x( 'All', 'all dropdown items', 'invoicing' ), |
|
376 | - 'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ), |
|
375 | + 'show_option_all' => _x('All', 'all dropdown items', 'invoicing'), |
|
376 | + 'show_option_none' => _x('None', 'no dropdown items', 'invoicing'), |
|
377 | 377 | 'data' => array(), |
378 | 378 | 'onchange' => null, |
379 | 379 | 'required' => false, |
@@ -381,78 +381,78 @@ discard block |
||
381 | 381 | 'readonly' => false, |
382 | 382 | ); |
383 | 383 | |
384 | - $args = wp_parse_args( $args, $defaults ); |
|
384 | + $args = wp_parse_args($args, $defaults); |
|
385 | 385 | |
386 | 386 | $data_elements = ''; |
387 | - foreach ( $args['data'] as $key => $value ) { |
|
388 | - $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"'; |
|
387 | + foreach ($args['data'] as $key => $value) { |
|
388 | + $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"'; |
|
389 | 389 | } |
390 | 390 | |
391 | - if( $args['multiple'] ) { |
|
391 | + if ($args['multiple']) { |
|
392 | 392 | $multiple = ' MULTIPLE'; |
393 | 393 | } else { |
394 | 394 | $multiple = ''; |
395 | 395 | } |
396 | 396 | |
397 | - if( $args['chosen'] ) { |
|
397 | + if ($args['chosen']) { |
|
398 | 398 | $args['class'] .= ' wpinv-select-chosen'; |
399 | 399 | } |
400 | 400 | |
401 | - if( $args['placeholder'] ) { |
|
401 | + if ($args['placeholder']) { |
|
402 | 402 | $placeholder = $args['placeholder']; |
403 | 403 | } else { |
404 | 404 | $placeholder = ''; |
405 | 405 | } |
406 | 406 | |
407 | 407 | $options = ''; |
408 | - if( !empty( $args['onchange'] ) ) { |
|
409 | - $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"'; |
|
408 | + if (!empty($args['onchange'])) { |
|
409 | + $options .= ' onchange="' . esc_attr($args['onchange']) . '"'; |
|
410 | 410 | } |
411 | 411 | |
412 | - if( !empty( $args['required'] ) ) { |
|
412 | + if (!empty($args['required'])) { |
|
413 | 413 | $options .= ' required="required"'; |
414 | 414 | } |
415 | 415 | |
416 | - if( !empty( $args['disabled'] ) ) { |
|
416 | + if (!empty($args['disabled'])) { |
|
417 | 417 | $options .= ' disabled'; |
418 | 418 | } |
419 | 419 | |
420 | - if( !empty( $args['readonly'] ) ) { |
|
420 | + if (!empty($args['readonly'])) { |
|
421 | 421 | $options .= ' readonly'; |
422 | 422 | } |
423 | 423 | |
424 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
425 | - $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>'; |
|
424 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
425 | + $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>'; |
|
426 | 426 | |
427 | - if ( $args['show_option_all'] ) { |
|
428 | - if( $args['multiple'] ) { |
|
429 | - $selected = selected( true, in_array( 0, $args['selected'] ), false ); |
|
427 | + if ($args['show_option_all']) { |
|
428 | + if ($args['multiple']) { |
|
429 | + $selected = selected(true, in_array(0, $args['selected']), false); |
|
430 | 430 | } else { |
431 | - $selected = selected( $args['selected'], 0, false ); |
|
431 | + $selected = selected($args['selected'], 0, false); |
|
432 | 432 | } |
433 | - $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>'; |
|
433 | + $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>'; |
|
434 | 434 | } |
435 | 435 | |
436 | - if ( !empty( $args['options'] ) ) { |
|
436 | + if (!empty($args['options'])) { |
|
437 | 437 | |
438 | - if ( $args['show_option_none'] ) { |
|
439 | - if( $args['multiple'] ) { |
|
440 | - $selected = selected( true, in_array( "", $args['selected'] ), false ); |
|
438 | + if ($args['show_option_none']) { |
|
439 | + if ($args['multiple']) { |
|
440 | + $selected = selected(true, in_array("", $args['selected']), false); |
|
441 | 441 | } else { |
442 | - $selected = selected( $args['selected'] === "", true, false ); |
|
442 | + $selected = selected($args['selected'] === "", true, false); |
|
443 | 443 | } |
444 | - $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>'; |
|
444 | + $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>'; |
|
445 | 445 | } |
446 | 446 | |
447 | - foreach( $args['options'] as $key => $option ) { |
|
447 | + foreach ($args['options'] as $key => $option) { |
|
448 | 448 | |
449 | - if( $args['multiple'] && is_array( $args['selected'] ) ) { |
|
450 | - $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false ); |
|
449 | + if ($args['multiple'] && is_array($args['selected'])) { |
|
450 | + $selected = selected(true, (bool)in_array($key, $args['selected']), false); |
|
451 | 451 | } else { |
452 | - $selected = selected( $args['selected'], $key, false ); |
|
452 | + $selected = selected($args['selected'], $key, false); |
|
453 | 453 | } |
454 | 454 | |
455 | - $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>'; |
|
455 | + $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>'; |
|
456 | 456 | } |
457 | 457 | } |
458 | 458 | |
@@ -461,7 +461,7 @@ discard block |
||
461 | 461 | return $output; |
462 | 462 | } |
463 | 463 | |
464 | -function wpinv_item_dropdown( $args = array() ) { |
|
464 | +function wpinv_item_dropdown($args = array()) { |
|
465 | 465 | $defaults = array( |
466 | 466 | 'name' => 'wpi_item', |
467 | 467 | 'id' => 'wpi_item', |
@@ -470,15 +470,15 @@ discard block |
||
470 | 470 | 'selected' => 0, |
471 | 471 | 'chosen' => false, |
472 | 472 | 'number' => 100, |
473 | - 'placeholder' => __( 'Choose a item', 'invoicing' ), |
|
474 | - 'data' => array( 'search-type' => 'item' ), |
|
473 | + 'placeholder' => __('Choose a item', 'invoicing'), |
|
474 | + 'data' => array('search-type' => 'item'), |
|
475 | 475 | 'show_option_all' => false, |
476 | 476 | 'show_option_none' => false, |
477 | 477 | 'with_packages' => true, |
478 | 478 | 'show_recurring' => false, |
479 | 479 | ); |
480 | 480 | |
481 | - $args = wp_parse_args( $args, $defaults ); |
|
481 | + $args = wp_parse_args($args, $defaults); |
|
482 | 482 | |
483 | 483 | $item_args = array( |
484 | 484 | 'post_type' => 'wpi_item', |
@@ -487,7 +487,7 @@ discard block |
||
487 | 487 | 'posts_per_page' => $args['number'] |
488 | 488 | ); |
489 | 489 | |
490 | - if ( !$args['with_packages'] ) { |
|
490 | + if (!$args['with_packages']) { |
|
491 | 491 | $item_args['meta_query'] = array( |
492 | 492 | array( |
493 | 493 | 'key' => '_wpinv_type', |
@@ -497,42 +497,42 @@ discard block |
||
497 | 497 | ); |
498 | 498 | } |
499 | 499 | |
500 | - $items = get_posts( $item_args ); |
|
500 | + $items = get_posts($item_args); |
|
501 | 501 | $options = array(); |
502 | - if ( $items ) { |
|
503 | - foreach ( $items as $item ) { |
|
504 | - $title = esc_html( $item->post_title ); |
|
502 | + if ($items) { |
|
503 | + foreach ($items as $item) { |
|
504 | + $title = esc_html($item->post_title); |
|
505 | 505 | |
506 | - if ( !empty( $args['show_recurring'] ) ) { |
|
507 | - $title .= wpinv_get_item_suffix( $item->ID, false ); |
|
506 | + if (!empty($args['show_recurring'])) { |
|
507 | + $title .= wpinv_get_item_suffix($item->ID, false); |
|
508 | 508 | } |
509 | 509 | |
510 | - $options[ absint( $item->ID ) ] = $title; |
|
510 | + $options[absint($item->ID)] = $title; |
|
511 | 511 | } |
512 | 512 | } |
513 | 513 | |
514 | 514 | // This ensures that any selected items are included in the drop down |
515 | - if( is_array( $args['selected'] ) ) { |
|
516 | - foreach( $args['selected'] as $item ) { |
|
517 | - if( ! in_array( $item, $options ) ) { |
|
518 | - $title = get_the_title( $item ); |
|
519 | - if ( !empty( $args['show_recurring'] ) ) { |
|
520 | - $title .= wpinv_get_item_suffix( $item, false ); |
|
515 | + if (is_array($args['selected'])) { |
|
516 | + foreach ($args['selected'] as $item) { |
|
517 | + if (!in_array($item, $options)) { |
|
518 | + $title = get_the_title($item); |
|
519 | + if (!empty($args['show_recurring'])) { |
|
520 | + $title .= wpinv_get_item_suffix($item, false); |
|
521 | 521 | } |
522 | 522 | $options[$item] = $title; |
523 | 523 | } |
524 | 524 | } |
525 | - } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) { |
|
526 | - if ( ! in_array( $args['selected'], $options ) ) { |
|
527 | - $title = get_the_title( $args['selected'] ); |
|
528 | - if ( !empty( $args['show_recurring'] ) ) { |
|
529 | - $title .= wpinv_get_item_suffix( $args['selected'], false ); |
|
525 | + } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) { |
|
526 | + if (!in_array($args['selected'], $options)) { |
|
527 | + $title = get_the_title($args['selected']); |
|
528 | + if (!empty($args['show_recurring'])) { |
|
529 | + $title .= wpinv_get_item_suffix($args['selected'], false); |
|
530 | 530 | } |
531 | - $options[$args['selected']] = get_the_title( $args['selected'] ); |
|
531 | + $options[$args['selected']] = get_the_title($args['selected']); |
|
532 | 532 | } |
533 | 533 | } |
534 | 534 | |
535 | - $output = wpinv_html_select( array( |
|
535 | + $output = wpinv_html_select(array( |
|
536 | 536 | 'name' => $args['name'], |
537 | 537 | 'selected' => $args['selected'], |
538 | 538 | 'id' => $args['id'], |
@@ -544,12 +544,12 @@ discard block |
||
544 | 544 | 'show_option_all' => $args['show_option_all'], |
545 | 545 | 'show_option_none' => $args['show_option_none'], |
546 | 546 | 'data' => $args['data'], |
547 | - ) ); |
|
547 | + )); |
|
548 | 548 | |
549 | 549 | return $output; |
550 | 550 | } |
551 | 551 | |
552 | -function wpinv_html_checkbox( $args = array() ) { |
|
552 | +function wpinv_html_checkbox($args = array()) { |
|
553 | 553 | $defaults = array( |
554 | 554 | 'name' => null, |
555 | 555 | 'current' => null, |
@@ -560,38 +560,38 @@ discard block |
||
560 | 560 | ) |
561 | 561 | ); |
562 | 562 | |
563 | - $args = wp_parse_args( $args, $defaults ); |
|
563 | + $args = wp_parse_args($args, $defaults); |
|
564 | 564 | |
565 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
565 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
566 | 566 | $options = ''; |
567 | - if ( ! empty( $args['options']['disabled'] ) ) { |
|
567 | + if (!empty($args['options']['disabled'])) { |
|
568 | 568 | $options .= ' disabled="disabled"'; |
569 | - } elseif ( ! empty( $args['options']['readonly'] ) ) { |
|
569 | + } elseif (!empty($args['options']['readonly'])) { |
|
570 | 570 | $options .= ' readonly'; |
571 | 571 | } |
572 | 572 | |
573 | - $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 ) . ' />'; |
|
573 | + $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) . ' />'; |
|
574 | 574 | |
575 | 575 | return $output; |
576 | 576 | } |
577 | 577 | |
578 | -function wpinv_html_text( $args = array() ) { |
|
578 | +function wpinv_html_text($args = array()) { |
|
579 | 579 | // Backwards compatibility |
580 | - if ( func_num_args() > 1 ) { |
|
580 | + if (func_num_args() > 1) { |
|
581 | 581 | $args = func_get_args(); |
582 | 582 | |
583 | 583 | $name = $args[0]; |
584 | - $value = isset( $args[1] ) ? $args[1] : ''; |
|
585 | - $label = isset( $args[2] ) ? $args[2] : ''; |
|
586 | - $desc = isset( $args[3] ) ? $args[3] : ''; |
|
584 | + $value = isset($args[1]) ? $args[1] : ''; |
|
585 | + $label = isset($args[2]) ? $args[2] : ''; |
|
586 | + $desc = isset($args[3]) ? $args[3] : ''; |
|
587 | 587 | } |
588 | 588 | |
589 | 589 | $defaults = array( |
590 | 590 | 'id' => '', |
591 | - 'name' => isset( $name ) ? $name : 'text', |
|
592 | - 'value' => isset( $value ) ? $value : null, |
|
593 | - 'label' => isset( $label ) ? $label : null, |
|
594 | - 'desc' => isset( $desc ) ? $desc : null, |
|
591 | + 'name' => isset($name) ? $name : 'text', |
|
592 | + 'value' => isset($value) ? $value : null, |
|
593 | + 'label' => isset($label) ? $label : null, |
|
594 | + 'desc' => isset($desc) ? $desc : null, |
|
595 | 595 | 'placeholder' => '', |
596 | 596 | 'class' => 'regular-text', |
597 | 597 | 'disabled' => false, |
@@ -601,51 +601,51 @@ discard block |
||
601 | 601 | 'data' => false |
602 | 602 | ); |
603 | 603 | |
604 | - $args = wp_parse_args( $args, $defaults ); |
|
604 | + $args = wp_parse_args($args, $defaults); |
|
605 | 605 | |
606 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
606 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
607 | 607 | $options = ''; |
608 | - if( $args['required'] ) { |
|
608 | + if ($args['required']) { |
|
609 | 609 | $options .= ' required="required"'; |
610 | 610 | } |
611 | - if( $args['readonly'] ) { |
|
611 | + if ($args['readonly']) { |
|
612 | 612 | $options .= ' readonly'; |
613 | 613 | } |
614 | - if( $args['readonly'] ) { |
|
614 | + if ($args['readonly']) { |
|
615 | 615 | $options .= ' readonly'; |
616 | 616 | } |
617 | 617 | |
618 | 618 | $data = ''; |
619 | - if ( !empty( $args['data'] ) ) { |
|
620 | - foreach ( $args['data'] as $key => $value ) { |
|
621 | - $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" '; |
|
619 | + if (!empty($args['data'])) { |
|
620 | + foreach ($args['data'] as $key => $value) { |
|
621 | + $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" '; |
|
622 | 622 | } |
623 | 623 | } |
624 | 624 | |
625 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
626 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
627 | - if ( ! empty( $args['desc'] ) ) { |
|
628 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
625 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
626 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>'; |
|
627 | + if (!empty($args['desc'])) { |
|
628 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
629 | 629 | } |
630 | 630 | |
631 | - $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 ) . '/>'; |
|
631 | + $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) . '/>'; |
|
632 | 632 | |
633 | 633 | $output .= '</span>'; |
634 | 634 | |
635 | 635 | return $output; |
636 | 636 | } |
637 | 637 | |
638 | -function wpinv_html_date_field( $args = array() ) { |
|
639 | - if( empty( $args['class'] ) ) { |
|
638 | +function wpinv_html_date_field($args = array()) { |
|
639 | + if (empty($args['class'])) { |
|
640 | 640 | $args['class'] = 'wpiDatepicker'; |
641 | - } elseif( ! strpos( $args['class'], 'wpiDatepicker' ) ) { |
|
641 | + } elseif (!strpos($args['class'], 'wpiDatepicker')) { |
|
642 | 642 | $args['class'] .= ' wpiDatepicker'; |
643 | 643 | } |
644 | 644 | |
645 | - return wpinv_html_text( $args ); |
|
645 | + return wpinv_html_text($args); |
|
646 | 646 | } |
647 | 647 | |
648 | -function wpinv_html_textarea( $args = array() ) { |
|
648 | +function wpinv_html_textarea($args = array()) { |
|
649 | 649 | $defaults = array( |
650 | 650 | 'name' => 'textarea', |
651 | 651 | 'value' => null, |
@@ -655,31 +655,31 @@ discard block |
||
655 | 655 | 'disabled' => false |
656 | 656 | ); |
657 | 657 | |
658 | - $args = wp_parse_args( $args, $defaults ); |
|
658 | + $args = wp_parse_args($args, $defaults); |
|
659 | 659 | |
660 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
660 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
661 | 661 | $disabled = ''; |
662 | - if( $args['disabled'] ) { |
|
662 | + if ($args['disabled']) { |
|
663 | 663 | $disabled = ' disabled="disabled"'; |
664 | 664 | } |
665 | 665 | |
666 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
667 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
668 | - $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>'; |
|
666 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
667 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>'; |
|
668 | + $output .= '<textarea name="' . esc_attr($args['name']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>'; |
|
669 | 669 | |
670 | - if ( ! empty( $args['desc'] ) ) { |
|
671 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
670 | + if (!empty($args['desc'])) { |
|
671 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
672 | 672 | } |
673 | 673 | $output .= '</span>'; |
674 | 674 | |
675 | 675 | return $output; |
676 | 676 | } |
677 | 677 | |
678 | -function wpinv_html_ajax_user_search( $args = array() ) { |
|
678 | +function wpinv_html_ajax_user_search($args = array()) { |
|
679 | 679 | $defaults = array( |
680 | 680 | 'name' => 'user_id', |
681 | 681 | 'value' => null, |
682 | - 'placeholder' => __( 'Enter username', 'invoicing' ), |
|
682 | + 'placeholder' => __('Enter username', 'invoicing'), |
|
683 | 683 | 'label' => null, |
684 | 684 | 'desc' => null, |
685 | 685 | 'class' => '', |
@@ -688,13 +688,13 @@ discard block |
||
688 | 688 | 'data' => false |
689 | 689 | ); |
690 | 690 | |
691 | - $args = wp_parse_args( $args, $defaults ); |
|
691 | + $args = wp_parse_args($args, $defaults); |
|
692 | 692 | |
693 | 693 | $args['class'] = 'wpinv-ajax-user-search ' . $args['class']; |
694 | 694 | |
695 | 695 | $output = '<span class="wpinv_user_search_wrap">'; |
696 | - $output .= wpinv_html_text( $args ); |
|
697 | - $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>'; |
|
696 | + $output .= wpinv_html_text($args); |
|
697 | + $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>'; |
|
698 | 698 | $output .= '</span>'; |
699 | 699 | |
700 | 700 | return $output; |
@@ -703,7 +703,7 @@ discard block |
||
703 | 703 | function wpinv_ip_geolocation() { |
704 | 704 | global $wpinv_euvat; |
705 | 705 | |
706 | - $ip = !empty( $_GET['ip'] ) ? sanitize_text_field( $_GET['ip'] ) : ''; |
|
706 | + $ip = !empty($_GET['ip']) ? sanitize_text_field($_GET['ip']) : ''; |
|
707 | 707 | $content = ''; |
708 | 708 | $iso = ''; |
709 | 709 | $country = ''; |
@@ -714,69 +714,69 @@ discard block |
||
714 | 714 | $credit = ''; |
715 | 715 | $address = ''; |
716 | 716 | |
717 | - if ( wpinv_get_option( 'vat_ip_lookup' ) == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record( $ip ) ) { |
|
717 | + if (wpinv_get_option('vat_ip_lookup') == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record($ip)) { |
|
718 | 718 | try { |
719 | 719 | $iso = $geoip2_city->country->isoCode; |
720 | 720 | $country = $geoip2_city->country->name; |
721 | - $region = !empty( $geoip2_city->subdivisions ) && !empty( $geoip2_city->subdivisions[0]->name ) ? $geoip2_city->subdivisions[0]->name : ''; |
|
721 | + $region = !empty($geoip2_city->subdivisions) && !empty($geoip2_city->subdivisions[0]->name) ? $geoip2_city->subdivisions[0]->name : ''; |
|
722 | 722 | $city = $geoip2_city->city->name; |
723 | 723 | $longitude = $geoip2_city->location->longitude; |
724 | 724 | $latitude = $geoip2_city->location->latitude; |
725 | - $credit = __( 'Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing' ); |
|
726 | - } catch( Exception $e ) { } |
|
725 | + $credit = __('Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing'); |
|
726 | + } catch (Exception $e) { } |
|
727 | 727 | } |
728 | 728 | |
729 | - if ( !( $iso && $longitude && $latitude ) && function_exists( 'simplexml_load_file' ) ) { |
|
729 | + if (!($iso && $longitude && $latitude) && function_exists('simplexml_load_file')) { |
|
730 | 730 | try { |
731 | - $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip ); |
|
731 | + $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip); |
|
732 | 732 | |
733 | - if ( !empty( $load_xml ) && isset( $load_xml->geoplugin_countryCode ) && !empty( $load_xml->geoplugin_latitude ) && !empty( $load_xml->geoplugin_longitude ) ) { |
|
733 | + if (!empty($load_xml) && isset($load_xml->geoplugin_countryCode) && !empty($load_xml->geoplugin_latitude) && !empty($load_xml->geoplugin_longitude)) { |
|
734 | 734 | $iso = $load_xml->geoplugin_countryCode; |
735 | 735 | $country = $load_xml->geoplugin_countryName; |
736 | - $region = !empty( $load_xml->geoplugin_regionName ) ? $load_xml->geoplugin_regionName : ''; |
|
737 | - $city = !empty( $load_xml->geoplugin_city ) ? $load_xml->geoplugin_city : ''; |
|
736 | + $region = !empty($load_xml->geoplugin_regionName) ? $load_xml->geoplugin_regionName : ''; |
|
737 | + $city = !empty($load_xml->geoplugin_city) ? $load_xml->geoplugin_city : ''; |
|
738 | 738 | $longitude = $load_xml->geoplugin_longitude; |
739 | 739 | $latitude = $load_xml->geoplugin_latitude; |
740 | 740 | $credit = $load_xml->geoplugin_credit; |
741 | - $credit = __( 'Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing' ) . '<br>' . $load_xml->geoplugin_credit; |
|
741 | + $credit = __('Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing') . '<br>' . $load_xml->geoplugin_credit; |
|
742 | 742 | } |
743 | - } catch( Exception $e ) { } |
|
743 | + } catch (Exception $e) { } |
|
744 | 744 | } |
745 | 745 | |
746 | - if ( $iso && $longitude && $latitude ) { |
|
747 | - if ( $city ) { |
|
746 | + if ($iso && $longitude && $latitude) { |
|
747 | + if ($city) { |
|
748 | 748 | $address .= $city . ', '; |
749 | 749 | } |
750 | 750 | |
751 | - if ( $region ) { |
|
751 | + if ($region) { |
|
752 | 752 | $address .= $region . ', '; |
753 | 753 | } |
754 | 754 | |
755 | 755 | $address .= $country . ' (' . $iso . ')'; |
756 | - $content = '<p>'. sprintf( __( '<b>Address:</b> %s', 'invoicing' ), $address ) . '</p>'; |
|
757 | - $content .= '<p>'. $credit . '</p>'; |
|
756 | + $content = '<p>' . sprintf(__('<b>Address:</b> %s', 'invoicing'), $address) . '</p>'; |
|
757 | + $content .= '<p>' . $credit . '</p>'; |
|
758 | 758 | } else { |
759 | - $content = '<p>'. sprintf( __( 'Unable to find geolocation for the IP address: %s', 'invoicing' ), $ip ) . '</p>'; |
|
759 | + $content = '<p>' . sprintf(__('Unable to find geolocation for the IP address: %s', 'invoicing'), $ip) . '</p>'; |
|
760 | 760 | } |
761 | 761 | ?> |
762 | 762 | <!DOCTYPE html> |
763 | -<html><head><title><?php echo sprintf( __( 'IP: %s', 'invoicing' ), $ip );?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head> |
|
763 | +<html><head><title><?php echo sprintf(__('IP: %s', 'invoicing'), $ip); ?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head> |
|
764 | 764 | <body> |
765 | - <?php if ( $latitude && $latitude ) { ?> |
|
765 | + <?php if ($latitude && $latitude) { ?> |
|
766 | 766 | <div id="map"></div> |
767 | 767 | <script src="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.js"></script> |
768 | 768 | <script type="text/javascript"> |
769 | 769 | var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', |
770 | 770 | osmAttrib = '© <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors', |
771 | 771 | osm = L.tileLayer(osmUrl, {maxZoom: 18, attribution: osmAttrib}), |
772 | - latlng = new L.LatLng(<?php echo $latitude;?>, <?php echo $longitude;?>); |
|
772 | + latlng = new L.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>); |
|
773 | 773 | |
774 | 774 | var map = new L.Map('map', {center: latlng, zoom: 12, layers: [osm]}); |
775 | 775 | |
776 | 776 | var marker = new L.Marker(latlng); |
777 | 777 | map.addLayer(marker); |
778 | 778 | |
779 | - marker.bindPopup("<p><?php esc_attr_e( $address );?></p>"); |
|
779 | + marker.bindPopup("<p><?php esc_attr_e($address); ?></p>"); |
|
780 | 780 | </script> |
781 | 781 | <?php } ?> |
782 | 782 | <div style="height:100px"><?php echo $content; ?></div> |
@@ -784,31 +784,31 @@ discard block |
||
784 | 784 | <?php |
785 | 785 | exit; |
786 | 786 | } |
787 | -add_action( 'wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation' ); |
|
788 | -add_action( 'wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation' ); |
|
787 | +add_action('wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation'); |
|
788 | +add_action('wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation'); |
|
789 | 789 | |
790 | 790 | // Set up the template for the invoice. |
791 | -function wpinv_template( $template ) { |
|
791 | +function wpinv_template($template) { |
|
792 | 792 | global $post, $wp_query; |
793 | 793 | |
794 | - if ( ( is_single() || is_404() ) && !empty( $post->ID ) && (get_post_type( $post->ID ) == 'wpi_invoice' or get_post_type( $post->ID ) == 'wpi_quote')) { |
|
795 | - if ( wpinv_user_can_print_invoice( $post->ID ) ) { |
|
796 | - $template = wpinv_get_template_part( 'wpinv-invoice-print', false, false ); |
|
794 | + if ((is_single() || is_404()) && !empty($post->ID) && (get_post_type($post->ID) == 'wpi_invoice' or get_post_type($post->ID) == 'wpi_quote')) { |
|
795 | + if (wpinv_user_can_print_invoice($post->ID)) { |
|
796 | + $template = wpinv_get_template_part('wpinv-invoice-print', false, false); |
|
797 | 797 | } else { |
798 | - if ( !is_user_logged_in() && !empty( $_REQUEST['_wpipay'] ) && $invoice = wpinv_get_invoice( $post->ID ) ) { |
|
798 | + if (!is_user_logged_in() && !empty($_REQUEST['_wpipay']) && $invoice = wpinv_get_invoice($post->ID)) { |
|
799 | 799 | $user_id = $invoice->get_user_id(); |
800 | - $secret = sanitize_text_field( $_GET['_wpipay'] ); |
|
800 | + $secret = sanitize_text_field($_GET['_wpipay']); |
|
801 | 801 | |
802 | - if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice->get_key() ) ) { // valid invoice link |
|
803 | - $redirect_to = remove_query_arg( '_wpipay', get_permalink() ); |
|
802 | + if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice->get_key())) { // valid invoice link |
|
803 | + $redirect_to = remove_query_arg('_wpipay', get_permalink()); |
|
804 | 804 | |
805 | - wpinv_guest_redirect( $redirect_to, $user_id ); |
|
805 | + wpinv_guest_redirect($redirect_to, $user_id); |
|
806 | 806 | wpinv_die(); |
807 | 807 | } |
808 | 808 | } |
809 | - $redirect_to = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() ); |
|
809 | + $redirect_to = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink()); |
|
810 | 810 | |
811 | - wp_redirect( $redirect_to ); |
|
811 | + wp_redirect($redirect_to); |
|
812 | 812 | wpinv_die(); |
813 | 813 | } |
814 | 814 | } |
@@ -818,7 +818,7 @@ discard block |
||
818 | 818 | |
819 | 819 | function wpinv_get_business_address() { |
820 | 820 | $business_address = wpinv_store_address(); |
821 | - $business_address = !empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : ''; |
|
821 | + $business_address = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : ''; |
|
822 | 822 | |
823 | 823 | /* |
824 | 824 | $default_country = wpinv_get_default_country(); |
@@ -842,7 +842,7 @@ discard block |
||
842 | 842 | |
843 | 843 | $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : ''; |
844 | 844 | |
845 | - return apply_filters( 'wpinv_get_business_address', $business_address ); |
|
845 | + return apply_filters('wpinv_get_business_address', $business_address); |
|
846 | 846 | } |
847 | 847 | |
848 | 848 | function wpinv_display_from_address() { |
@@ -852,185 +852,185 @@ discard block |
||
852 | 852 | if (empty($from_name)) { |
853 | 853 | $from_name = wpinv_get_business_name(); |
854 | 854 | } |
855 | - ?><div class="from col-xs-2"><strong><?php _e( 'From:', 'invoicing' ) ?></strong></div> |
|
855 | + ?><div class="from col-xs-2"><strong><?php _e('From:', 'invoicing') ?></strong></div> |
|
856 | 856 | <div class="wrapper col-xs-10"> |
857 | - <div class="name"><?php echo esc_html( $from_name ); ?></div> |
|
858 | - <?php if ( $address = wpinv_get_business_address() ) { ?> |
|
859 | - <div class="address"><?php echo wpautop( wp_kses_post( $address ) );?></div> |
|
857 | + <div class="name"><?php echo esc_html($from_name); ?></div> |
|
858 | + <?php if ($address = wpinv_get_business_address()) { ?> |
|
859 | + <div class="address"><?php echo wpautop(wp_kses_post($address)); ?></div> |
|
860 | 860 | <?php } ?> |
861 | - <?php if ( $email_from = wpinv_mail_get_from_address() ) { ?> |
|
862 | - <div class="email_from"><?php echo wp_sprintf( __( 'Email: %s' ), $email_from );?></div> |
|
861 | + <?php if ($email_from = wpinv_mail_get_from_address()) { ?> |
|
862 | + <div class="email_from"><?php echo wp_sprintf(__('Email: %s'), $email_from); ?></div> |
|
863 | 863 | <?php } ?> |
864 | 864 | </div> |
865 | 865 | <?php |
866 | 866 | } |
867 | 867 | |
868 | -function wpinv_watermark( $id = 0 ) { |
|
869 | - $output = wpinv_get_watermark( $id ); |
|
868 | +function wpinv_watermark($id = 0) { |
|
869 | + $output = wpinv_get_watermark($id); |
|
870 | 870 | |
871 | - return apply_filters( 'wpinv_get_watermark', $output, $id ); |
|
871 | + return apply_filters('wpinv_get_watermark', $output, $id); |
|
872 | 872 | } |
873 | 873 | |
874 | -function wpinv_get_watermark( $id ) { |
|
875 | - if ( !$id > 0 ) { |
|
874 | +function wpinv_get_watermark($id) { |
|
875 | + if (!$id > 0) { |
|
876 | 876 | return NULL; |
877 | 877 | } |
878 | - $invoice = wpinv_get_invoice( $id ); |
|
878 | + $invoice = wpinv_get_invoice($id); |
|
879 | 879 | |
880 | - if ( !empty( $invoice ) ) { |
|
881 | - if ( $invoice->is_paid() ) { |
|
882 | - return __( 'Paid', 'invoicing' ); |
|
880 | + if (!empty($invoice)) { |
|
881 | + if ($invoice->is_paid()) { |
|
882 | + return __('Paid', 'invoicing'); |
|
883 | 883 | } |
884 | - if ( $invoice->has_status( array( 'cancelled' ) ) ) { |
|
885 | - return __( 'Cancelled', 'invoicing' ); |
|
884 | + if ($invoice->has_status(array('cancelled'))) { |
|
885 | + return __('Cancelled', 'invoicing'); |
|
886 | 886 | } |
887 | 887 | } |
888 | 888 | |
889 | 889 | return NULL; |
890 | 890 | } |
891 | 891 | |
892 | -function wpinv_display_invoice_details( $invoice ) { |
|
892 | +function wpinv_display_invoice_details($invoice) { |
|
893 | 893 | global $wpinv_euvat; |
894 | 894 | |
895 | 895 | $invoice_id = $invoice->ID; |
896 | 896 | $vat_name = $wpinv_euvat->get_vat_name(); |
897 | 897 | $use_taxes = wpinv_use_taxes(); |
898 | 898 | |
899 | - $invoice_status = wpinv_get_invoice_status( $invoice_id ); |
|
899 | + $invoice_status = wpinv_get_invoice_status($invoice_id); |
|
900 | 900 | |
901 | - if($invoice->post_type == 'wpi_invoice') $type = 'Invoice'; |
|
902 | - elseif($invoice->post_type == 'wpi_quote') $type = 'Quote'; |
|
901 | + if ($invoice->post_type == 'wpi_invoice') $type = 'Invoice'; |
|
902 | + elseif ($invoice->post_type == 'wpi_quote') $type = 'Quote'; |
|
903 | 903 | ?> |
904 | 904 | <table class="table table-bordered table-sm"> |
905 | - <?php if ( $invoice_number = wpinv_get_invoice_number( $invoice_id ) ) { ?> |
|
905 | + <?php if ($invoice_number = wpinv_get_invoice_number($invoice_id)) { ?> |
|
906 | 906 | <tr class="wpi-row-number"> |
907 | - <th><?php echo sprintf(__( '%s Number', 'invoicing' ), $type); ?></th> |
|
908 | - <td><?php echo esc_html( $invoice_number ); ?></td> |
|
907 | + <th><?php echo sprintf(__('%s Number', 'invoicing'), $type); ?></th> |
|
908 | + <td><?php echo esc_html($invoice_number); ?></td> |
|
909 | 909 | </tr> |
910 | 910 | <?php } ?> |
911 | 911 | <tr class="wpi-row-status"> |
912 | - <th><?php echo wp_sprintf(__( '%s Status', 'invoicing' ), $type); ?></th> |
|
913 | - <td><?php echo wpinv_invoice_status_label( $invoice_status, wpinv_get_invoice_status( $invoice_id, true ) ); ?></td> |
|
912 | + <th><?php echo wp_sprintf(__('%s Status', 'invoicing'), $type); ?></th> |
|
913 | + <td><?php echo wpinv_invoice_status_label($invoice_status, wpinv_get_invoice_status($invoice_id, true)); ?></td> |
|
914 | 914 | </tr> |
915 | - <?php if ( $invoice->is_renewal() ) { ?> |
|
915 | + <?php if ($invoice->is_renewal()) { ?> |
|
916 | 916 | <tr class="wpi-row-parent"> |
917 | - <th><?php echo wp_sprintf(__( 'Parent %s', 'invoicing' ), $type); ?></th> |
|
918 | - <td><?php echo wpinv_invoice_link( $invoice->parent_invoice ); ?></td> |
|
917 | + <th><?php echo wp_sprintf(__('Parent %s', 'invoicing'), $type); ?></th> |
|
918 | + <td><?php echo wpinv_invoice_link($invoice->parent_invoice); ?></td> |
|
919 | 919 | </tr> |
920 | 920 | <?php } ?> |
921 | 921 | <tr class="wpi-row-gateway"> |
922 | - <th><?php _e( 'Payment Method', 'invoicing' ); ?></th> |
|
923 | - <td><?php echo wpinv_get_payment_gateway_name( $invoice_id ); ?></td> |
|
922 | + <th><?php _e('Payment Method', 'invoicing'); ?></th> |
|
923 | + <td><?php echo wpinv_get_payment_gateway_name($invoice_id); ?></td> |
|
924 | 924 | </tr> |
925 | - <?php if ( $invoice_date = wpinv_get_invoice_date( $invoice_id ) ) { ?> |
|
925 | + <?php if ($invoice_date = wpinv_get_invoice_date($invoice_id)) { ?> |
|
926 | 926 | <tr class="wpi-row-date"> |
927 | - <th><?php echo wp_sprintf(__( '%s Date', 'invoicing' ), $type); ?></th> |
|
927 | + <th><?php echo wp_sprintf(__('%s Date', 'invoicing'), $type); ?></th> |
|
928 | 928 | <td><?php echo $invoice_date; ?></td> |
929 | 929 | </tr> |
930 | 930 | <?php } ?> |
931 | - <?php if ( wpinv_get_option( 'overdue_active' ) && $invoice->needs_payment() && ( $due_date = $invoice->get_due_date( true ) ) ) { ?> |
|
931 | + <?php if (wpinv_get_option('overdue_active') && $invoice->needs_payment() && ($due_date = $invoice->get_due_date(true))) { ?> |
|
932 | 932 | <tr class="wpi-row-date"> |
933 | - <th><?php _e( 'Due Date', 'invoicing' ); ?></th> |
|
933 | + <th><?php _e('Due Date', 'invoicing'); ?></th> |
|
934 | 934 | <td><?php echo $due_date; ?></td> |
935 | 935 | </tr> |
936 | 936 | <?php } ?> |
937 | - <?php if ( $owner_vat_number = $wpinv_euvat->get_vat_number() ) { ?> |
|
937 | + <?php if ($owner_vat_number = $wpinv_euvat->get_vat_number()) { ?> |
|
938 | 938 | <tr class="wpi-row-ovatno"> |
939 | - <th><?php echo wp_sprintf( __( 'Owner %s Number', 'invoicing' ), $vat_name ); ?></th> |
|
939 | + <th><?php echo wp_sprintf(__('Owner %s Number', 'invoicing'), $vat_name); ?></th> |
|
940 | 940 | <td><?php echo $owner_vat_number; ?></td> |
941 | 941 | </tr> |
942 | 942 | <?php } ?> |
943 | - <?php if ( $use_taxes && $user_vat_number = wpinv_get_invoice_vat_number( $invoice_id ) ) { ?> |
|
943 | + <?php if ($use_taxes && $user_vat_number = wpinv_get_invoice_vat_number($invoice_id)) { ?> |
|
944 | 944 | <tr class="wpi-row-uvatno"> |
945 | - <th><?php echo wp_sprintf( __( 'Your %s Number', 'invoicing' ), $vat_name ); ?></th> |
|
945 | + <th><?php echo wp_sprintf(__('Your %s Number', 'invoicing'), $vat_name); ?></th> |
|
946 | 946 | <td><?php echo $user_vat_number; ?></td> |
947 | 947 | </tr> |
948 | 948 | <?php } ?> |
949 | 949 | <tr class="table-active tr-total wpi-row-total"> |
950 | - <th><strong><?php _e( 'Total Amount', 'invoicing' ) ?></strong></th> |
|
951 | - <td><strong><?php echo wpinv_payment_total( $invoice_id, true ); ?></strong></td> |
|
950 | + <th><strong><?php _e('Total Amount', 'invoicing') ?></strong></th> |
|
951 | + <td><strong><?php echo wpinv_payment_total($invoice_id, true); ?></strong></td> |
|
952 | 952 | </tr> |
953 | 953 | </table> |
954 | 954 | <?php |
955 | 955 | } |
956 | 956 | |
957 | -function wpinv_display_to_address( $invoice_id = 0 ) { |
|
958 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
957 | +function wpinv_display_to_address($invoice_id = 0) { |
|
958 | + $invoice = wpinv_get_invoice($invoice_id); |
|
959 | 959 | |
960 | - if ( empty( $invoice ) ) { |
|
960 | + if (empty($invoice)) { |
|
961 | 961 | return NULL; |
962 | 962 | } |
963 | 963 | |
964 | 964 | $billing_details = $invoice->get_user_info(); |
965 | - $output = '<div class="to col-xs-2"><strong>' . __( 'To:', 'invoicing' ) . '</strong></div>'; |
|
965 | + $output = '<div class="to col-xs-2"><strong>' . __('To:', 'invoicing') . '</strong></div>'; |
|
966 | 966 | $output .= '<div class="wrapper col-xs-10">'; |
967 | 967 | |
968 | 968 | ob_start(); |
969 | - do_action( 'wpinv_display_to_address_top', $invoice ); |
|
969 | + do_action('wpinv_display_to_address_top', $invoice); |
|
970 | 970 | $output .= ob_get_clean(); |
971 | 971 | |
972 | - $output .= '<div class="name">' . esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) . '</div>'; |
|
973 | - if ( $company = $billing_details['company'] ) { |
|
974 | - $output .= '<div class="company">' . wpautop( wp_kses_post( $company ) ) . '</div>'; |
|
972 | + $output .= '<div class="name">' . esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])) . '</div>'; |
|
973 | + if ($company = $billing_details['company']) { |
|
974 | + $output .= '<div class="company">' . wpautop(wp_kses_post($company)) . '</div>'; |
|
975 | 975 | } |
976 | 976 | $address_row = ''; |
977 | - if ( $address = $billing_details['address'] ) { |
|
978 | - $address_row .= wpautop( wp_kses_post( $address ) ); |
|
977 | + if ($address = $billing_details['address']) { |
|
978 | + $address_row .= wpautop(wp_kses_post($address)); |
|
979 | 979 | } |
980 | 980 | |
981 | 981 | $address_fields = array(); |
982 | - if ( !empty( $billing_details['city'] ) ) { |
|
982 | + if (!empty($billing_details['city'])) { |
|
983 | 983 | $address_fields[] = $billing_details['city']; |
984 | 984 | } |
985 | 985 | |
986 | - $billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : ''; |
|
987 | - if ( !empty( $billing_details['state'] ) ) { |
|
988 | - $address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country ); |
|
986 | + $billing_country = !empty($billing_details['country']) ? $billing_details['country'] : ''; |
|
987 | + if (!empty($billing_details['state'])) { |
|
988 | + $address_fields[] = wpinv_state_name($billing_details['state'], $billing_country); |
|
989 | 989 | } |
990 | 990 | |
991 | - if ( !empty( $billing_country ) ) { |
|
992 | - $address_fields[] = wpinv_country_name( $billing_country ); |
|
991 | + if (!empty($billing_country)) { |
|
992 | + $address_fields[] = wpinv_country_name($billing_country); |
|
993 | 993 | } |
994 | 994 | |
995 | - if ( !empty( $address_fields ) ) { |
|
996 | - $address_fields = implode( ", ", $address_fields ); |
|
995 | + if (!empty($address_fields)) { |
|
996 | + $address_fields = implode(", ", $address_fields); |
|
997 | 997 | |
998 | - if ( !empty( $billing_details['zip'] ) ) { |
|
998 | + if (!empty($billing_details['zip'])) { |
|
999 | 999 | $address_fields .= ' ' . $billing_details['zip']; |
1000 | 1000 | } |
1001 | 1001 | |
1002 | - $address_row .= wpautop( wp_kses_post( $address_fields ) ); |
|
1002 | + $address_row .= wpautop(wp_kses_post($address_fields)); |
|
1003 | 1003 | } |
1004 | 1004 | |
1005 | - if ( $address_row ) { |
|
1005 | + if ($address_row) { |
|
1006 | 1006 | $output .= '<div class="address">' . $address_row . '</div>'; |
1007 | 1007 | } |
1008 | 1008 | |
1009 | - if ( $phone = $invoice->get_phone() ) { |
|
1010 | - $output .= '<div class="phone">' . wp_sprintf( __( 'Phone: %s' ), esc_html( $phone ) ) . '</div>'; |
|
1009 | + if ($phone = $invoice->get_phone()) { |
|
1010 | + $output .= '<div class="phone">' . wp_sprintf(__('Phone: %s'), esc_html($phone)) . '</div>'; |
|
1011 | 1011 | } |
1012 | - if ( $email = $invoice->get_email() ) { |
|
1013 | - $output .= '<div class="email">' . wp_sprintf( __( 'Email: %s' ), esc_html( $email ) ) . '</div>'; |
|
1012 | + if ($email = $invoice->get_email()) { |
|
1013 | + $output .= '<div class="email">' . wp_sprintf(__('Email: %s'), esc_html($email)) . '</div>'; |
|
1014 | 1014 | } |
1015 | 1015 | |
1016 | 1016 | ob_start(); |
1017 | - do_action( 'wpinv_display_to_address_bottom', $invoice ); |
|
1017 | + do_action('wpinv_display_to_address_bottom', $invoice); |
|
1018 | 1018 | $output .= ob_get_clean(); |
1019 | 1019 | |
1020 | 1020 | $output .= '</div>'; |
1021 | - $output = apply_filters( 'wpinv_display_to_address', $output, $invoice ); |
|
1021 | + $output = apply_filters('wpinv_display_to_address', $output, $invoice); |
|
1022 | 1022 | |
1023 | 1023 | echo $output; |
1024 | 1024 | } |
1025 | 1025 | |
1026 | -function wpinv_display_line_items( $invoice_id = 0 ) { |
|
1026 | +function wpinv_display_line_items($invoice_id = 0) { |
|
1027 | 1027 | global $wpinv_euvat, $ajax_cart_details; |
1028 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1028 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1029 | 1029 | $quantities_enabled = wpinv_item_quantities_enabled(); |
1030 | 1030 | $use_taxes = wpinv_use_taxes(); |
1031 | 1031 | $zero_tax = !(float)$invoice->get_tax() > 0 ? true : false; |
1032 | - $tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __( 'Tax', 'invoicing' ); |
|
1033 | - $tax_title = !$zero_tax && $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : ''; |
|
1032 | + $tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __('Tax', 'invoicing'); |
|
1033 | + $tax_title = !$zero_tax && $use_taxes ? (wpinv_prices_include_tax() ? wp_sprintf(__('(%s Incl.)', 'invoicing'), $tax_label) : wp_sprintf(__('(%s Excl.)', 'invoicing'), $tax_label)) : ''; |
|
1034 | 1034 | |
1035 | 1035 | $cart_details = $invoice->get_cart_details(); |
1036 | 1036 | $ajax_cart_details = $cart_details; |
@@ -1039,68 +1039,68 @@ discard block |
||
1039 | 1039 | <table class="table table-sm table-bordered table-responsive"> |
1040 | 1040 | <thead> |
1041 | 1041 | <tr> |
1042 | - <th class="name"><strong><?php _e( "Item Name", "invoicing" );?></strong></th> |
|
1043 | - <th class="rate"><strong><?php _e( "Price", "invoicing" );?></strong></th> |
|
1042 | + <th class="name"><strong><?php _e("Item Name", "invoicing"); ?></strong></th> |
|
1043 | + <th class="rate"><strong><?php _e("Price", "invoicing"); ?></strong></th> |
|
1044 | 1044 | <?php if ($quantities_enabled) { ?> |
1045 | - <th class="qty"><strong><?php _e( "Qty", "invoicing" );?></strong></th> |
|
1045 | + <th class="qty"><strong><?php _e("Qty", "invoicing"); ?></strong></th> |
|
1046 | 1046 | <?php } ?> |
1047 | 1047 | <?php if ($use_taxes && !$zero_tax) { ?> |
1048 | 1048 | <th class="tax"><strong><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></strong></th> |
1049 | 1049 | <?php } ?> |
1050 | - <th class="total"><strong><?php echo __( "Item Total", "invoicing" ) . ' <span class="normal small">' . $tax_title . '<span>';?></strong></th> |
|
1050 | + <th class="total"><strong><?php echo __("Item Total", "invoicing") . ' <span class="normal small">' . $tax_title . '<span>'; ?></strong></th> |
|
1051 | 1051 | </tr> |
1052 | 1052 | </thead> |
1053 | 1053 | <tbody> |
1054 | 1054 | <?php |
1055 | - if ( !empty( $cart_details ) ) { |
|
1056 | - do_action( 'wpinv_display_line_items_start', $invoice ); |
|
1055 | + if (!empty($cart_details)) { |
|
1056 | + do_action('wpinv_display_line_items_start', $invoice); |
|
1057 | 1057 | |
1058 | 1058 | $count = 0; |
1059 | 1059 | $cols = 3; |
1060 | - foreach ( $cart_details as $key => $cart_item ) { |
|
1061 | - $item_id = !empty($cart_item['id']) ? absint( $cart_item['id'] ) : ''; |
|
1062 | - $item_price = isset($cart_item["item_price"]) ? wpinv_format_amount( $cart_item["item_price"] ) : 0; |
|
1063 | - $line_total = isset($cart_item["subtotal"]) ? wpinv_format_amount( $cart_item["subtotal"] ) : 0; |
|
1064 | - $quantity = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint( $cart_item['quantity'] ) : 1; |
|
1060 | + foreach ($cart_details as $key => $cart_item) { |
|
1061 | + $item_id = !empty($cart_item['id']) ? absint($cart_item['id']) : ''; |
|
1062 | + $item_price = isset($cart_item["item_price"]) ? wpinv_format_amount($cart_item["item_price"]) : 0; |
|
1063 | + $line_total = isset($cart_item["subtotal"]) ? wpinv_format_amount($cart_item["subtotal"]) : 0; |
|
1064 | + $quantity = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint($cart_item['quantity']) : 1; |
|
1065 | 1065 | |
1066 | - $item = $item_id ? new WPInv_Item( $item_id ) : NULL; |
|
1066 | + $item = $item_id ? new WPInv_Item($item_id) : NULL; |
|
1067 | 1067 | $summary = ''; |
1068 | 1068 | $cols = 3; |
1069 | - if ( !empty($item) ) { |
|
1069 | + if (!empty($item)) { |
|
1070 | 1070 | $item_name = $item->get_name(); |
1071 | 1071 | $summary = $item->get_summary(); |
1072 | 1072 | } |
1073 | - $item_name = !empty($cart_item['name']) ? $cart_item['name'] : $item_name; |
|
1073 | + $item_name = !empty($cart_item['name']) ? $cart_item['name'] : $item_name; |
|
1074 | 1074 | |
1075 | 1075 | if (!empty($item) && $item->is_package() && !empty($cart_item['meta']['post_id'])) { |
1076 | - $post_link = '<a href="' . get_edit_post_link( $cart_item['meta']['post_id'] ) .'" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title( $cart_item['meta']['post_id']) ) . '</a>'; |
|
1077 | - $summary = wp_sprintf( __( '%s: %s', 'invoicing' ), $item->get_cpt_singular_name(), $post_link ); |
|
1076 | + $post_link = '<a href="' . get_edit_post_link($cart_item['meta']['post_id']) . '" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title($cart_item['meta']['post_id'])) . '</a>'; |
|
1077 | + $summary = wp_sprintf(__('%s: %s', 'invoicing'), $item->get_cpt_singular_name(), $post_link); |
|
1078 | 1078 | } |
1079 | - $summary = apply_filters( 'wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice ); |
|
1079 | + $summary = apply_filters('wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice); |
|
1080 | 1080 | |
1081 | 1081 | $item_tax = ''; |
1082 | 1082 | $tax_rate = ''; |
1083 | - if ( $use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) { |
|
1084 | - $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ) ); |
|
1085 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100; |
|
1086 | - $tax_rate = $tax_rate > 0 ? (float)wpinv_format_amount( $tax_rate, 2 ) : ''; |
|
1083 | + if ($use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) { |
|
1084 | + $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax'])); |
|
1085 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100; |
|
1086 | + $tax_rate = $tax_rate > 0 ? (float)wpinv_format_amount($tax_rate, 2) : ''; |
|
1087 | 1087 | $tax_rate = $tax_rate != '' ? ' <small class="tax-rate">(' . $tax_rate . '%)</small>' : ''; |
1088 | 1088 | } |
1089 | 1089 | |
1090 | 1090 | $line_item_tax = $item_tax . $tax_rate; |
1091 | 1091 | |
1092 | - if ( $line_item_tax === '' ) { |
|
1092 | + if ($line_item_tax === '') { |
|
1093 | 1093 | $line_item_tax = 0; // Zero tax |
1094 | 1094 | } |
1095 | 1095 | |
1096 | - $line_item = '<tr class="row-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . ' wpinv-item">'; |
|
1097 | - $line_item .= '<td class="name">' . esc_html__( $item_name, 'invoicing' ) . wpinv_get_item_suffix( $item ); |
|
1098 | - if ( $summary !== '' ) { |
|
1099 | - $line_item .= '<br/><small class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</small>'; |
|
1096 | + $line_item = '<tr class="row-' . (($count % 2 == 0) ? 'even' : 'odd') . ' wpinv-item">'; |
|
1097 | + $line_item .= '<td class="name">' . esc_html__($item_name, 'invoicing') . wpinv_get_item_suffix($item); |
|
1098 | + if ($summary !== '') { |
|
1099 | + $line_item .= '<br/><small class="meta">' . wpautop(wp_kses_post($summary)) . '</small>'; |
|
1100 | 1100 | } |
1101 | 1101 | $line_item .= '</td>'; |
1102 | 1102 | |
1103 | - $line_item .= '<td class="rate">' . esc_html__( wpinv_price( $item_price, $invoice->get_currency() ) ) . '</td>'; |
|
1103 | + $line_item .= '<td class="rate">' . esc_html__(wpinv_price($item_price, $invoice->get_currency())) . '</td>'; |
|
1104 | 1104 | if ($quantities_enabled) { |
1105 | 1105 | $cols++; |
1106 | 1106 | $line_item .= '<td class="qty">' . $quantity . '</td>'; |
@@ -1109,55 +1109,55 @@ discard block |
||
1109 | 1109 | $cols++; |
1110 | 1110 | $line_item .= '<td class="tax">' . $line_item_tax . '</td>'; |
1111 | 1111 | } |
1112 | - $line_item .= '<td class="total">' . esc_html__( wpinv_price( $line_total, $invoice->get_currency() ) ) . '</td>'; |
|
1112 | + $line_item .= '<td class="total">' . esc_html__(wpinv_price($line_total, $invoice->get_currency())) . '</td>'; |
|
1113 | 1113 | $line_item .= '</tr>'; |
1114 | 1114 | |
1115 | - echo apply_filters( 'wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols ); |
|
1115 | + echo apply_filters('wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols); |
|
1116 | 1116 | |
1117 | 1117 | $count++; |
1118 | 1118 | } |
1119 | 1119 | |
1120 | - do_action( 'wpinv_display_before_subtotal', $invoice, $cols ); |
|
1120 | + do_action('wpinv_display_before_subtotal', $invoice, $cols); |
|
1121 | 1121 | ?> |
1122 | 1122 | <tr class="row-sub-total row_odd"> |
1123 | - <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_subtotal_label', '<strong>' . __( 'Sub Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td> |
|
1124 | - <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td> |
|
1123 | + <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_subtotal_label', '<strong>' . __('Sub Total', 'invoicing') . ':</strong>', $invoice); ?></td> |
|
1124 | + <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td> |
|
1125 | 1125 | </tr> |
1126 | 1126 | <?php |
1127 | - do_action( 'wpinv_display_after_subtotal', $invoice, $cols ); |
|
1127 | + do_action('wpinv_display_after_subtotal', $invoice, $cols); |
|
1128 | 1128 | |
1129 | - if ( wpinv_discount( $invoice_id, false ) > 0 ) { |
|
1130 | - do_action( 'wpinv_display_before_discount', $invoice, $cols ); |
|
1129 | + if (wpinv_discount($invoice_id, false) > 0) { |
|
1130 | + do_action('wpinv_display_before_discount', $invoice, $cols); |
|
1131 | 1131 | ?> |
1132 | 1132 | <tr class="row-discount"> |
1133 | - <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?>:</td> |
|
1134 | - <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td> |
|
1133 | + <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?>:</td> |
|
1134 | + <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td> |
|
1135 | 1135 | </tr> |
1136 | 1136 | <?php |
1137 | - do_action( 'wpinv_display_after_discount', $invoice, $cols ); |
|
1137 | + do_action('wpinv_display_after_discount', $invoice, $cols); |
|
1138 | 1138 | } |
1139 | 1139 | |
1140 | - if ( $use_taxes ) { |
|
1141 | - do_action( 'wpinv_display_before_tax', $invoice, $cols ); |
|
1140 | + if ($use_taxes) { |
|
1141 | + do_action('wpinv_display_before_tax', $invoice, $cols); |
|
1142 | 1142 | ?> |
1143 | 1143 | <tr class="row-tax"> |
1144 | - <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice ); ?></td> |
|
1145 | - <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td> |
|
1144 | + <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice); ?></td> |
|
1145 | + <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td> |
|
1146 | 1146 | </tr> |
1147 | 1147 | <?php |
1148 | - do_action( 'wpinv_display_after_tax', $invoice, $cols ); |
|
1148 | + do_action('wpinv_display_after_tax', $invoice, $cols); |
|
1149 | 1149 | } |
1150 | 1150 | |
1151 | - do_action( 'wpinv_display_before_total', $invoice, $cols ); |
|
1151 | + do_action('wpinv_display_before_total', $invoice, $cols); |
|
1152 | 1152 | ?> |
1153 | 1153 | <tr class="table-active row-total"> |
1154 | - <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_total_label', '<strong>' . __( 'Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td> |
|
1155 | - <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td> |
|
1154 | + <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_total_label', '<strong>' . __('Total', 'invoicing') . ':</strong>', $invoice); ?></td> |
|
1155 | + <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td> |
|
1156 | 1156 | </tr> |
1157 | 1157 | <?php |
1158 | - do_action( 'wpinv_display_after_total', $invoice, $cols ); |
|
1158 | + do_action('wpinv_display_after_total', $invoice, $cols); |
|
1159 | 1159 | |
1160 | - do_action( 'wpinv_display_line_end', $invoice, $cols ); |
|
1160 | + do_action('wpinv_display_line_end', $invoice, $cols); |
|
1161 | 1161 | } |
1162 | 1162 | ?> |
1163 | 1163 | </tbody> |
@@ -1166,35 +1166,35 @@ discard block |
||
1166 | 1166 | echo ob_get_clean(); |
1167 | 1167 | } |
1168 | 1168 | |
1169 | -function wpinv_display_invoice_totals( $invoice_id = 0 ) { |
|
1169 | +function wpinv_display_invoice_totals($invoice_id = 0) { |
|
1170 | 1170 | $use_taxes = wpinv_use_taxes(); |
1171 | 1171 | |
1172 | - do_action( 'wpinv_before_display_totals_table', $invoice_id ); |
|
1172 | + do_action('wpinv_before_display_totals_table', $invoice_id); |
|
1173 | 1173 | ?> |
1174 | 1174 | <table class="table table-sm table-bordered table-responsive"> |
1175 | 1175 | <tbody> |
1176 | - <?php do_action( 'wpinv_before_display_totals' ); ?> |
|
1176 | + <?php do_action('wpinv_before_display_totals'); ?> |
|
1177 | 1177 | <tr class="row-sub-total"> |
1178 | - <td class="rate"><strong><?php _e( 'Sub Total', 'invoicing' ); ?></strong></td> |
|
1179 | - <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td> |
|
1178 | + <td class="rate"><strong><?php _e('Sub Total', 'invoicing'); ?></strong></td> |
|
1179 | + <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td> |
|
1180 | 1180 | </tr> |
1181 | - <?php do_action( 'wpinv_after_display_totals' ); ?> |
|
1182 | - <?php if ( wpinv_discount( $invoice_id, false ) > 0 ) { ?> |
|
1181 | + <?php do_action('wpinv_after_display_totals'); ?> |
|
1182 | + <?php if (wpinv_discount($invoice_id, false) > 0) { ?> |
|
1183 | 1183 | <tr class="row-discount"> |
1184 | - <td class="rate"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?></td> |
|
1185 | - <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td> |
|
1184 | + <td class="rate"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?></td> |
|
1185 | + <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td> |
|
1186 | 1186 | </tr> |
1187 | - <?php do_action( 'wpinv_after_display_discount' ); ?> |
|
1187 | + <?php do_action('wpinv_after_display_discount'); ?> |
|
1188 | 1188 | <?php } ?> |
1189 | - <?php if ( $use_taxes ) { ?> |
|
1189 | + <?php if ($use_taxes) { ?> |
|
1190 | 1190 | <tr class="row-tax"> |
1191 | - <td class="rate"><?php _e( 'Tax', 'invoicing' ); ?></td> |
|
1192 | - <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td> |
|
1191 | + <td class="rate"><?php _e('Tax', 'invoicing'); ?></td> |
|
1192 | + <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td> |
|
1193 | 1193 | </tr> |
1194 | - <?php do_action( 'wpinv_after_display_tax' ); ?> |
|
1194 | + <?php do_action('wpinv_after_display_tax'); ?> |
|
1195 | 1195 | <?php } ?> |
1196 | - <?php if ( $fees = wpinv_get_fees( $invoice_id ) ) { ?> |
|
1197 | - <?php foreach ( $fees as $fee ) { ?> |
|
1196 | + <?php if ($fees = wpinv_get_fees($invoice_id)) { ?> |
|
1197 | + <?php foreach ($fees as $fee) { ?> |
|
1198 | 1198 | <tr class="row-fee"> |
1199 | 1199 | <td class="rate"><?php echo $fee['label']; ?></td> |
1200 | 1200 | <td class="total"><?php echo $fee['amount_display']; ?></td> |
@@ -1202,72 +1202,72 @@ discard block |
||
1202 | 1202 | <?php } ?> |
1203 | 1203 | <?php } ?> |
1204 | 1204 | <tr class="table-active row-total"> |
1205 | - <td class="rate"><strong><?php _e( 'Total', 'invoicing' ) ?></strong></td> |
|
1206 | - <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td> |
|
1205 | + <td class="rate"><strong><?php _e('Total', 'invoicing') ?></strong></td> |
|
1206 | + <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td> |
|
1207 | 1207 | </tr> |
1208 | - <?php do_action( 'wpinv_after_totals' ); ?> |
|
1208 | + <?php do_action('wpinv_after_totals'); ?> |
|
1209 | 1209 | </tbody> |
1210 | 1210 | |
1211 | 1211 | </table> |
1212 | 1212 | |
1213 | - <?php do_action( 'wpinv_after_totals_table' ); |
|
1213 | + <?php do_action('wpinv_after_totals_table'); |
|
1214 | 1214 | } |
1215 | 1215 | |
1216 | -function wpinv_display_payments_info( $invoice_id = 0, $echo = true ) { |
|
1217 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1216 | +function wpinv_display_payments_info($invoice_id = 0, $echo = true) { |
|
1217 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1218 | 1218 | |
1219 | 1219 | ob_start(); |
1220 | - do_action( 'wpinv_before_display_payments_info', $invoice_id ); |
|
1221 | - if ( ( $gateway_title = $invoice->get_gateway_title() ) || $invoice->is_paid() ) { |
|
1220 | + do_action('wpinv_before_display_payments_info', $invoice_id); |
|
1221 | + if (($gateway_title = $invoice->get_gateway_title()) || $invoice->is_paid()) { |
|
1222 | 1222 | ?> |
1223 | 1223 | <div class="wpi-payment-info"> |
1224 | - <p class="wpi-payment-gateway"><?php echo wp_sprintf( __( 'Payment via %s', 'invoicing' ), $gateway_title ? $gateway_title : __( 'Manually', 'invoicing' ) ); ?></p> |
|
1225 | - <?php if ( $gateway_title ) { ?> |
|
1226 | - <p class="wpi-payment-transid"><?php echo wp_sprintf( __( 'Transaction ID: %s', 'invoicing' ), $invoice->get_transaction_id() ); ?></p> |
|
1224 | + <p class="wpi-payment-gateway"><?php echo wp_sprintf(__('Payment via %s', 'invoicing'), $gateway_title ? $gateway_title : __('Manually', 'invoicing')); ?></p> |
|
1225 | + <?php if ($gateway_title) { ?> |
|
1226 | + <p class="wpi-payment-transid"><?php echo wp_sprintf(__('Transaction ID: %s', 'invoicing'), $invoice->get_transaction_id()); ?></p> |
|
1227 | 1227 | <?php } ?> |
1228 | 1228 | </div> |
1229 | 1229 | <?php |
1230 | 1230 | } |
1231 | - do_action( 'wpinv_after_display_payments_info', $invoice_id ); |
|
1231 | + do_action('wpinv_after_display_payments_info', $invoice_id); |
|
1232 | 1232 | $outout = ob_get_clean(); |
1233 | 1233 | |
1234 | - if ( $echo ) { |
|
1234 | + if ($echo) { |
|
1235 | 1235 | echo $outout; |
1236 | 1236 | } else { |
1237 | 1237 | return $outout; |
1238 | 1238 | } |
1239 | 1239 | } |
1240 | 1240 | |
1241 | -function wpinv_display_style( $invoice ) { |
|
1242 | - wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION ); |
|
1241 | +function wpinv_display_style($invoice) { |
|
1242 | + wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION); |
|
1243 | 1243 | |
1244 | - wp_print_styles( 'open-sans' ); |
|
1245 | - wp_print_styles( 'wpinv-single-style' ); |
|
1244 | + wp_print_styles('open-sans'); |
|
1245 | + wp_print_styles('wpinv-single-style'); |
|
1246 | 1246 | } |
1247 | -add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' ); |
|
1247 | +add_action('wpinv_invoice_print_head', 'wpinv_display_style'); |
|
1248 | 1248 | |
1249 | 1249 | function wpinv_checkout_billing_details() { |
1250 | 1250 | $invoice_id = (int)wpinv_get_invoice_cart_id(); |
1251 | 1251 | if (empty($invoice_id)) { |
1252 | - wpinv_error_log( 'Invoice id not found', 'ERROR', __FILE__, __LINE__ ); |
|
1252 | + wpinv_error_log('Invoice id not found', 'ERROR', __FILE__, __LINE__); |
|
1253 | 1253 | return null; |
1254 | 1254 | } |
1255 | 1255 | |
1256 | - $invoice = wpinv_get_invoice_cart( $invoice_id ); |
|
1256 | + $invoice = wpinv_get_invoice_cart($invoice_id); |
|
1257 | 1257 | if (empty($invoice)) { |
1258 | - wpinv_error_log( 'Invoice not found', 'ERROR', __FILE__, __LINE__ ); |
|
1258 | + wpinv_error_log('Invoice not found', 'ERROR', __FILE__, __LINE__); |
|
1259 | 1259 | return null; |
1260 | 1260 | } |
1261 | 1261 | $user_id = $invoice->get_user_id(); |
1262 | 1262 | $user_info = $invoice->get_user_info(); |
1263 | - $address_info = wpinv_get_user_address( $user_id ); |
|
1263 | + $address_info = wpinv_get_user_address($user_id); |
|
1264 | 1264 | |
1265 | - if ( empty( $user_info['first_name'] ) && !empty( $user_info['first_name'] ) ) { |
|
1265 | + if (empty($user_info['first_name']) && !empty($user_info['first_name'])) { |
|
1266 | 1266 | $user_info['first_name'] = $user_info['first_name']; |
1267 | 1267 | $user_info['last_name'] = $user_info['last_name']; |
1268 | 1268 | } |
1269 | 1269 | |
1270 | - if ( ( ( empty( $user_info['country'] ) && !empty( $address_info['country'] ) ) || ( empty( $user_info['state'] ) && !empty( $address_info['state'] ) && $user_info['country'] == $address_info['country'] ) ) ) { |
|
1270 | + if (((empty($user_info['country']) && !empty($address_info['country'])) || (empty($user_info['state']) && !empty($address_info['state']) && $user_info['country'] == $address_info['country']))) { |
|
1271 | 1271 | $user_info['country'] = $address_info['country']; |
1272 | 1272 | $user_info['state'] = $address_info['state']; |
1273 | 1273 | $user_info['city'] = $address_info['city']; |
@@ -1283,103 +1283,103 @@ discard block |
||
1283 | 1283 | 'address' |
1284 | 1284 | ); |
1285 | 1285 | |
1286 | - foreach ( $address_fields as $field ) { |
|
1287 | - if ( empty( $user_info[$field] ) ) { |
|
1286 | + foreach ($address_fields as $field) { |
|
1287 | + if (empty($user_info[$field])) { |
|
1288 | 1288 | $user_info[$field] = $address_info[$field]; |
1289 | 1289 | } |
1290 | 1290 | } |
1291 | 1291 | |
1292 | - return apply_filters( 'wpinv_checkout_billing_details', $user_info, $invoice ); |
|
1292 | + return apply_filters('wpinv_checkout_billing_details', $user_info, $invoice); |
|
1293 | 1293 | } |
1294 | 1294 | |
1295 | 1295 | function wpinv_admin_get_line_items($invoice = array()) { |
1296 | 1296 | $item_quantities = wpinv_item_quantities_enabled(); |
1297 | 1297 | $use_taxes = wpinv_use_taxes(); |
1298 | 1298 | |
1299 | - if ( empty( $invoice ) ) { |
|
1299 | + if (empty($invoice)) { |
|
1300 | 1300 | return NULL; |
1301 | 1301 | } |
1302 | 1302 | |
1303 | 1303 | $cart_items = $invoice->get_cart_details(); |
1304 | - if ( empty( $cart_items ) ) { |
|
1304 | + if (empty($cart_items)) { |
|
1305 | 1305 | return NULL; |
1306 | 1306 | } |
1307 | 1307 | ob_start(); |
1308 | 1308 | |
1309 | - do_action( 'wpinv_admin_before_line_items', $cart_items, $invoice ); |
|
1309 | + do_action('wpinv_admin_before_line_items', $cart_items, $invoice); |
|
1310 | 1310 | |
1311 | 1311 | $count = 0; |
1312 | - foreach ( $cart_items as $key => $cart_item ) { |
|
1312 | + foreach ($cart_items as $key => $cart_item) { |
|
1313 | 1313 | $item_id = $cart_item['id']; |
1314 | - $wpi_item = $item_id > 0 ? new WPInv_Item( $item_id ) : NULL; |
|
1314 | + $wpi_item = $item_id > 0 ? new WPInv_Item($item_id) : NULL; |
|
1315 | 1315 | |
1316 | 1316 | if (empty($wpi_item)) { |
1317 | 1317 | continue; |
1318 | 1318 | } |
1319 | 1319 | |
1320 | - $item_price = wpinv_price( wpinv_format_amount( $cart_item['item_price'] ) ); |
|
1321 | - $quantity = !empty( $cart_item['quantity'] ) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1; |
|
1322 | - $item_subtotal = wpinv_price( wpinv_format_amount( $cart_item['subtotal'] ) ); |
|
1320 | + $item_price = wpinv_price(wpinv_format_amount($cart_item['item_price'])); |
|
1321 | + $quantity = !empty($cart_item['quantity']) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1; |
|
1322 | + $item_subtotal = wpinv_price(wpinv_format_amount($cart_item['subtotal'])); |
|
1323 | 1323 | $can_remove = true; |
1324 | 1324 | |
1325 | 1325 | $summary = ''; |
1326 | 1326 | if ($wpi_item->is_package() && !empty($cart_item['meta']['post_id'])) { |
1327 | - $post_link = '<a href="' . get_edit_post_link( $cart_item['meta']['post_id'] ) .'" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title( $cart_item['meta']['post_id']) ) . '</a>'; |
|
1328 | - $summary = wp_sprintf( __( '%s: %s', 'invoicing' ), $wpi_item->get_cpt_singular_name(), $post_link ); |
|
1327 | + $post_link = '<a href="' . get_edit_post_link($cart_item['meta']['post_id']) . '" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title($cart_item['meta']['post_id'])) . '</a>'; |
|
1328 | + $summary = wp_sprintf(__('%s: %s', 'invoicing'), $wpi_item->get_cpt_singular_name(), $post_link); |
|
1329 | 1329 | } |
1330 | - $summary = apply_filters( 'wpinv_admin_invoice_line_item_summary', $summary, $cart_item, $wpi_item, $invoice ); |
|
1330 | + $summary = apply_filters('wpinv_admin_invoice_line_item_summary', $summary, $cart_item, $wpi_item, $invoice); |
|
1331 | 1331 | |
1332 | 1332 | $item_tax = ''; |
1333 | 1333 | $tax_rate = ''; |
1334 | - if ( $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) { |
|
1335 | - $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ) ); |
|
1336 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100; |
|
1337 | - $tax_rate = $tax_rate > 0 ? (float)wpinv_format_amount( $tax_rate, 2 ) : ''; |
|
1334 | + if ($cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) { |
|
1335 | + $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax'])); |
|
1336 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100; |
|
1337 | + $tax_rate = $tax_rate > 0 ? (float)wpinv_format_amount($tax_rate, 2) : ''; |
|
1338 | 1338 | $tax_rate = $tax_rate != '' ? ' <span class="tax-rate">(' . $tax_rate . '%)</span>' : ''; |
1339 | 1339 | } |
1340 | 1340 | $line_item_tax = $item_tax . $tax_rate; |
1341 | 1341 | |
1342 | - if ( $line_item_tax === '' ) { |
|
1342 | + if ($line_item_tax === '') { |
|
1343 | 1343 | $line_item_tax = 0; // Zero tax |
1344 | 1344 | } |
1345 | 1345 | |
1346 | - $line_item = '<tr class="item item-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . '" data-item-id="' . $item_id . '">'; |
|
1346 | + $line_item = '<tr class="item item-' . (($count % 2 == 0) ? 'even' : 'odd') . '" data-item-id="' . $item_id . '">'; |
|
1347 | 1347 | $line_item .= '<td class="id">' . $item_id . '</td>'; |
1348 | - $line_item .= '<td class="title"><a href="' . get_edit_post_link( $item_id ) . '" target="_blank">' . $cart_item['name'] . '</a>' . wpinv_get_item_suffix( $wpi_item ); |
|
1349 | - if ( $summary !== '' ) { |
|
1350 | - $line_item .= '<span class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</span>'; |
|
1348 | + $line_item .= '<td class="title"><a href="' . get_edit_post_link($item_id) . '" target="_blank">' . $cart_item['name'] . '</a>' . wpinv_get_item_suffix($wpi_item); |
|
1349 | + if ($summary !== '') { |
|
1350 | + $line_item .= '<span class="meta">' . wpautop(wp_kses_post($summary)) . '</span>'; |
|
1351 | 1351 | } |
1352 | 1352 | $line_item .= '</td>'; |
1353 | 1353 | $line_item .= '<td class="price">' . $item_price . '</td>'; |
1354 | 1354 | |
1355 | - if ( $item_quantities ) { |
|
1356 | - if ( count( $cart_items ) == 1 && $quantity <= 1 ) { |
|
1355 | + if ($item_quantities) { |
|
1356 | + if (count($cart_items) == 1 && $quantity <= 1) { |
|
1357 | 1357 | $can_remove = false; |
1358 | 1358 | } |
1359 | 1359 | $line_item .= '<td class="qty" data-quantity="' . $quantity . '"> × ' . $quantity . '</td>'; |
1360 | 1360 | } else { |
1361 | - if ( count( $cart_items ) == 1 ) { |
|
1361 | + if (count($cart_items) == 1) { |
|
1362 | 1362 | $can_remove = false; |
1363 | 1363 | } |
1364 | 1364 | } |
1365 | 1365 | $line_item .= '<td class="total">' . $item_subtotal . '</td>'; |
1366 | 1366 | |
1367 | - if ( $use_taxes ) { |
|
1367 | + if ($use_taxes) { |
|
1368 | 1368 | $line_item .= '<td class="tax">' . $line_item_tax . '</td>'; |
1369 | 1369 | } |
1370 | 1370 | $line_item .= '<td class="action">'; |
1371 | - if ( !$invoice->is_paid() && $can_remove ) { |
|
1371 | + if (!$invoice->is_paid() && $can_remove) { |
|
1372 | 1372 | $line_item .= '<i class="fa fa-remove wpinv-item-remove"></i>'; |
1373 | 1373 | } |
1374 | 1374 | $line_item .= '</td>'; |
1375 | 1375 | $line_item .= '</tr>'; |
1376 | 1376 | |
1377 | - echo apply_filters( 'wpinv_admin_line_item', $line_item, $cart_item, $invoice ); |
|
1377 | + echo apply_filters('wpinv_admin_line_item', $line_item, $cart_item, $invoice); |
|
1378 | 1378 | |
1379 | 1379 | $count++; |
1380 | 1380 | } |
1381 | 1381 | |
1382 | - do_action( 'wpinv_admin_after_line_items', $cart_items, $invoice ); |
|
1382 | + do_action('wpinv_admin_after_line_items', $cart_items, $invoice); |
|
1383 | 1383 | |
1384 | 1384 | return ob_get_clean(); |
1385 | 1385 | } |
@@ -1390,35 +1390,35 @@ discard block |
||
1390 | 1390 | // Set current invoice id. |
1391 | 1391 | $wpi_checkout_id = wpinv_get_invoice_cart_id(); |
1392 | 1392 | |
1393 | - $form_action = esc_url( wpinv_get_checkout_uri() ); |
|
1393 | + $form_action = esc_url(wpinv_get_checkout_uri()); |
|
1394 | 1394 | |
1395 | 1395 | ob_start(); |
1396 | 1396 | echo '<div id="wpinv_checkout_wrap">'; |
1397 | 1397 | |
1398 | - if ( wpinv_get_cart_contents() || wpinv_cart_has_fees() ) { |
|
1398 | + if (wpinv_get_cart_contents() || wpinv_cart_has_fees()) { |
|
1399 | 1399 | ?> |
1400 | 1400 | <div id="wpinv_checkout_form_wrap" class="wpinv_clearfix table-responsive"> |
1401 | - <?php do_action( 'wpinv_before_checkout_form' ); ?> |
|
1401 | + <?php do_action('wpinv_before_checkout_form'); ?> |
|
1402 | 1402 | <form id="wpinv_checkout_form" class="wpi-form" action="<?php echo $form_action; ?>" method="POST"> |
1403 | 1403 | <?php |
1404 | - do_action( 'wpinv_checkout_form_top' ); |
|
1405 | - do_action( 'wpinv_checkout_billing_info' ); |
|
1406 | - do_action( 'wpinv_checkout_cart' ); |
|
1407 | - do_action( 'wpinv_payment_mode_select' ); |
|
1408 | - do_action( 'wpinv_checkout_form_bottom' ) |
|
1404 | + do_action('wpinv_checkout_form_top'); |
|
1405 | + do_action('wpinv_checkout_billing_info'); |
|
1406 | + do_action('wpinv_checkout_cart'); |
|
1407 | + do_action('wpinv_payment_mode_select'); |
|
1408 | + do_action('wpinv_checkout_form_bottom') |
|
1409 | 1409 | ?> |
1410 | 1410 | </form> |
1411 | - <?php do_action( 'wpinv_after_purchase_form' ); ?> |
|
1411 | + <?php do_action('wpinv_after_purchase_form'); ?> |
|
1412 | 1412 | </div><!--end #wpinv_checkout_form_wrap--> |
1413 | 1413 | <?php |
1414 | 1414 | } else { |
1415 | - do_action( 'wpinv_cart_empty' ); |
|
1415 | + do_action('wpinv_cart_empty'); |
|
1416 | 1416 | } |
1417 | 1417 | echo '</div><!--end #wpinv_checkout_wrap-->'; |
1418 | 1418 | return ob_get_clean(); |
1419 | 1419 | } |
1420 | 1420 | |
1421 | -function wpinv_checkout_cart( $cart_details = array(), $echo = true ) { |
|
1421 | +function wpinv_checkout_cart($cart_details = array(), $echo = true) { |
|
1422 | 1422 | global $ajax_cart_details; |
1423 | 1423 | $ajax_cart_details = $cart_details; |
1424 | 1424 | /* |
@@ -1433,25 +1433,25 @@ discard block |
||
1433 | 1433 | } |
1434 | 1434 | */ |
1435 | 1435 | ob_start(); |
1436 | - do_action( 'wpinv_before_checkout_cart' ); |
|
1436 | + do_action('wpinv_before_checkout_cart'); |
|
1437 | 1437 | echo '<div id="wpinv_checkout_cart_form" method="post">'; |
1438 | 1438 | echo '<div id="wpinv_checkout_cart_wrap">'; |
1439 | - wpinv_get_template_part( 'wpinv-checkout-cart' ); |
|
1439 | + wpinv_get_template_part('wpinv-checkout-cart'); |
|
1440 | 1440 | echo '</div>'; |
1441 | 1441 | echo '</div>'; |
1442 | - do_action( 'wpinv_after_checkout_cart' ); |
|
1442 | + do_action('wpinv_after_checkout_cart'); |
|
1443 | 1443 | $content = ob_get_clean(); |
1444 | 1444 | |
1445 | - if ( $echo ) { |
|
1445 | + if ($echo) { |
|
1446 | 1446 | echo $content; |
1447 | 1447 | } else { |
1448 | 1448 | return $content; |
1449 | 1449 | } |
1450 | 1450 | } |
1451 | -add_action( 'wpinv_checkout_cart', 'wpinv_checkout_cart', 10 ); |
|
1451 | +add_action('wpinv_checkout_cart', 'wpinv_checkout_cart', 10); |
|
1452 | 1452 | |
1453 | 1453 | function wpinv_empty_cart_message() { |
1454 | - return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1454 | + return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>'); |
|
1455 | 1455 | } |
1456 | 1456 | |
1457 | 1457 | /** |
@@ -1463,91 +1463,91 @@ discard block |
||
1463 | 1463 | function wpinv_empty_checkout_cart() { |
1464 | 1464 | echo wpinv_empty_cart_message(); |
1465 | 1465 | } |
1466 | -add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' ); |
|
1466 | +add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart'); |
|
1467 | 1467 | |
1468 | 1468 | function wpinv_save_cart_button() { |
1469 | - if ( wpinv_is_cart_saving_disabled() ) |
|
1469 | + if (wpinv_is_cart_saving_disabled()) |
|
1470 | 1470 | return; |
1471 | 1471 | ?> |
1472 | - <a class="wpinv-cart-saving-button wpinv-submit button" id="wpinv-save-cart-button" href="<?php echo esc_url( add_query_arg( 'wpi_action', 'save_cart' ) ); ?>"><?php _e( 'Save Cart', 'invoicing' ); ?></a> |
|
1472 | + <a class="wpinv-cart-saving-button wpinv-submit button" id="wpinv-save-cart-button" href="<?php echo esc_url(add_query_arg('wpi_action', 'save_cart')); ?>"><?php _e('Save Cart', 'invoicing'); ?></a> |
|
1473 | 1473 | <?php |
1474 | 1474 | } |
1475 | 1475 | |
1476 | 1476 | function wpinv_update_cart_button() { |
1477 | - if ( !wpinv_item_quantities_enabled() ) |
|
1477 | + if (!wpinv_item_quantities_enabled()) |
|
1478 | 1478 | return; |
1479 | 1479 | ?> |
1480 | - <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e( 'Update Cart', 'invoicing' ); ?>"/> |
|
1480 | + <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e('Update Cart', 'invoicing'); ?>"/> |
|
1481 | 1481 | <input type="hidden" name="wpi_action" value="update_cart"/> |
1482 | 1482 | <?php |
1483 | 1483 | } |
1484 | 1484 | |
1485 | 1485 | function wpinv_checkout_cart_columns() { |
1486 | 1486 | $default = 3; |
1487 | - if ( wpinv_item_quantities_enabled() ) { |
|
1487 | + if (wpinv_item_quantities_enabled()) { |
|
1488 | 1488 | $default++; |
1489 | 1489 | } |
1490 | 1490 | |
1491 | - if ( wpinv_use_taxes() ) { |
|
1491 | + if (wpinv_use_taxes()) { |
|
1492 | 1492 | $default++; |
1493 | 1493 | } |
1494 | 1494 | |
1495 | - return apply_filters( 'wpinv_checkout_cart_columns', $default ); |
|
1495 | + return apply_filters('wpinv_checkout_cart_columns', $default); |
|
1496 | 1496 | } |
1497 | 1497 | |
1498 | 1498 | function wpinv_display_cart_messages() { |
1499 | 1499 | global $wpi_session; |
1500 | 1500 | |
1501 | - $messages = $wpi_session->get( 'wpinv_cart_messages' ); |
|
1501 | + $messages = $wpi_session->get('wpinv_cart_messages'); |
|
1502 | 1502 | |
1503 | - if ( $messages ) { |
|
1504 | - foreach ( $messages as $message_id => $message ) { |
|
1503 | + if ($messages) { |
|
1504 | + foreach ($messages as $message_id => $message) { |
|
1505 | 1505 | // Try and detect what type of message this is |
1506 | - if ( strpos( strtolower( $message ), 'error' ) ) { |
|
1506 | + if (strpos(strtolower($message), 'error')) { |
|
1507 | 1507 | $type = 'error'; |
1508 | - } elseif ( strpos( strtolower( $message ), 'success' ) ) { |
|
1508 | + } elseif (strpos(strtolower($message), 'success')) { |
|
1509 | 1509 | $type = 'success'; |
1510 | 1510 | } else { |
1511 | 1511 | $type = 'info'; |
1512 | 1512 | } |
1513 | 1513 | |
1514 | - $classes = apply_filters( 'wpinv_' . $type . '_class', array( 'wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type ) ); |
|
1514 | + $classes = apply_filters('wpinv_' . $type . '_class', array('wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type)); |
|
1515 | 1515 | |
1516 | - echo '<div class="' . implode( ' ', $classes ) . '">'; |
|
1516 | + echo '<div class="' . implode(' ', $classes) . '">'; |
|
1517 | 1517 | // Loop message codes and display messages |
1518 | 1518 | echo '<p class="wpinv_error" id="wpinv_msg_' . $message_id . '">' . $message . '</p>'; |
1519 | 1519 | echo '</div>'; |
1520 | 1520 | } |
1521 | 1521 | |
1522 | 1522 | // Remove all of the cart saving messages |
1523 | - $wpi_session->set( 'wpinv_cart_messages', null ); |
|
1523 | + $wpi_session->set('wpinv_cart_messages', null); |
|
1524 | 1524 | } |
1525 | 1525 | } |
1526 | -add_action( 'wpinv_before_checkout_cart', 'wpinv_display_cart_messages' ); |
|
1526 | +add_action('wpinv_before_checkout_cart', 'wpinv_display_cart_messages'); |
|
1527 | 1527 | |
1528 | 1528 | function wpinv_discount_field() { |
1529 | - if ( isset( $_GET['wpi-gateway'] ) && wpinv_is_ajax_disabled() ) { |
|
1529 | + if (isset($_GET['wpi-gateway']) && wpinv_is_ajax_disabled()) { |
|
1530 | 1530 | return; // Only show before a payment method has been selected if ajax is disabled |
1531 | 1531 | } |
1532 | 1532 | |
1533 | - if ( !wpinv_is_checkout() ) { |
|
1533 | + if (!wpinv_is_checkout()) { |
|
1534 | 1534 | return; |
1535 | 1535 | } |
1536 | 1536 | |
1537 | - if ( wpinv_has_active_discounts() && wpinv_get_cart_total() ) { |
|
1537 | + if (wpinv_has_active_discounts() && wpinv_get_cart_total()) { |
|
1538 | 1538 | ?> |
1539 | 1539 | <div id="wpinv-discount-field" class="panel panel-default"> |
1540 | 1540 | <div class="panel-body"> |
1541 | 1541 | <p> |
1542 | - <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e( 'Discount', 'invoicing' ); ?></strong></label> |
|
1543 | - <span class="wpinv-description"><?php _e( 'Enter a discount code if you have one.', 'invoicing' ); ?></span> |
|
1542 | + <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e('Discount', 'invoicing'); ?></strong></label> |
|
1543 | + <span class="wpinv-description"><?php _e('Enter a discount code if you have one.', 'invoicing'); ?></span> |
|
1544 | 1544 | </p> |
1545 | 1545 | <div class="form-group row"> |
1546 | 1546 | <div class="col-sm-4"> |
1547 | - <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e( 'Enter discount code', 'invoicing' ); ?>"/> |
|
1547 | + <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e('Enter discount code', 'invoicing'); ?>"/> |
|
1548 | 1548 | </div> |
1549 | 1549 | <div class="col-sm-3"> |
1550 | - <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e( 'Apply Discount', 'invoicing' ); ?></button> |
|
1550 | + <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e('Apply Discount', 'invoicing'); ?></button> |
|
1551 | 1551 | </div> |
1552 | 1552 | <div class="col-sm-12 wpinv-discount-msg"> |
1553 | 1553 | <div class="alert alert-success"><i class="fa fa-check-circle"></i><span class="wpi-msg"></span></div> |
@@ -1559,10 +1559,10 @@ discard block |
||
1559 | 1559 | <?php |
1560 | 1560 | } |
1561 | 1561 | } |
1562 | -add_action( 'wpinv_after_checkout_cart', 'wpinv_discount_field', -10 ); |
|
1562 | +add_action('wpinv_after_checkout_cart', 'wpinv_discount_field', -10); |
|
1563 | 1563 | |
1564 | 1564 | function wpinv_agree_to_terms_js() { |
1565 | - if ( wpinv_get_option( 'show_agree_to_terms', false ) ) { |
|
1565 | + if (wpinv_get_option('show_agree_to_terms', false)) { |
|
1566 | 1566 | ?> |
1567 | 1567 | <script type="text/javascript"> |
1568 | 1568 | jQuery(document).ready(function($){ |
@@ -1577,124 +1577,124 @@ discard block |
||
1577 | 1577 | <?php |
1578 | 1578 | } |
1579 | 1579 | } |
1580 | -add_action( 'wpinv_checkout_form_top', 'wpinv_agree_to_terms_js' ); |
|
1580 | +add_action('wpinv_checkout_form_top', 'wpinv_agree_to_terms_js'); |
|
1581 | 1581 | |
1582 | 1582 | function wpinv_payment_mode_select() { |
1583 | - $gateways = wpinv_get_enabled_payment_gateways( true ); |
|
1584 | - $gateways = apply_filters( 'wpinv_payment_gateways_on_cart', $gateways ); |
|
1583 | + $gateways = wpinv_get_enabled_payment_gateways(true); |
|
1584 | + $gateways = apply_filters('wpinv_payment_gateways_on_cart', $gateways); |
|
1585 | 1585 | $page_URL = wpinv_get_current_page_url(); |
1586 | 1586 | |
1587 | 1587 | do_action('wpinv_payment_mode_top'); |
1588 | 1588 | $invoice_id = (int)wpinv_get_invoice_cart_id(); |
1589 | 1589 | ?> |
1590 | 1590 | <div id="wpinv_payment_mode_select"> |
1591 | - <?php do_action( 'wpinv_payment_mode_before_gateways_wrap' ); ?> |
|
1591 | + <?php do_action('wpinv_payment_mode_before_gateways_wrap'); ?> |
|
1592 | 1592 | <div id="wpinv-payment-mode-wrap" class="panel panel-default"> |
1593 | - <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Select Payment Method', 'invoicing' ); ?></h3></div> |
|
1593 | + <div class="panel-heading"><h3 class="panel-title"><?php _e('Select Payment Method', 'invoicing'); ?></h3></div> |
|
1594 | 1594 | <div class="panel-body list-group wpi-payment_methods"> |
1595 | 1595 | <?php |
1596 | - do_action( 'wpinv_payment_mode_before_gateways' ); |
|
1597 | - $chosen_gateway = wpinv_get_chosen_gateway( $invoice_id ); |
|
1596 | + do_action('wpinv_payment_mode_before_gateways'); |
|
1597 | + $chosen_gateway = wpinv_get_chosen_gateway($invoice_id); |
|
1598 | 1598 | |
1599 | - if(!empty($gateways)){ |
|
1600 | - foreach ( $gateways as $gateway_id => $gateway ) { |
|
1601 | - $checked = checked( $gateway_id, $chosen_gateway, false ); |
|
1602 | - $button_label = wpinv_get_gateway_button_label( $gateway_id ); |
|
1603 | - $description = wpinv_get_gateway_description( $gateway_id ); |
|
1599 | + if (!empty($gateways)) { |
|
1600 | + foreach ($gateways as $gateway_id => $gateway) { |
|
1601 | + $checked = checked($gateway_id, $chosen_gateway, false); |
|
1602 | + $button_label = wpinv_get_gateway_button_label($gateway_id); |
|
1603 | + $description = wpinv_get_gateway_description($gateway_id); |
|
1604 | 1604 | ?> |
1605 | 1605 | <div class="list-group-item"> |
1606 | 1606 | <div class="radio"> |
1607 | - <label><input type="radio" data-button-text="<?php echo esc_attr( $button_label );?>" value="<?php echo esc_attr( $gateway_id ) ;?>" <?php echo $checked ;?> id="wpi_gateway_<?php echo esc_attr( $gateway_id );?>" name="wpi-gateway" class="wpi-pmethod"><?php echo esc_html( $gateway['checkout_label'] ); ?></label> |
|
1607 | + <label><input type="radio" data-button-text="<?php echo esc_attr($button_label); ?>" value="<?php echo esc_attr($gateway_id); ?>" <?php echo $checked; ?> id="wpi_gateway_<?php echo esc_attr($gateway_id); ?>" name="wpi-gateway" class="wpi-pmethod"><?php echo esc_html($gateway['checkout_label']); ?></label> |
|
1608 | 1608 | </div> |
1609 | - <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr( $gateway_id );?>" role="alert"> |
|
1610 | - <?php if ( !empty( $description ) ) { ?> |
|
1611 | - <div class="wpi-gateway-desc alert alert-info"><?php echo $description;?></div> |
|
1609 | + <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr($gateway_id); ?>" role="alert"> |
|
1610 | + <?php if (!empty($description)) { ?> |
|
1611 | + <div class="wpi-gateway-desc alert alert-info"><?php echo $description; ?></div> |
|
1612 | 1612 | <?php } ?> |
1613 | - <?php do_action( 'wpinv_' . $gateway_id . '_cc_form', $invoice_id ) ;?> |
|
1613 | + <?php do_action('wpinv_' . $gateway_id . '_cc_form', $invoice_id); ?> |
|
1614 | 1614 | </div> |
1615 | 1615 | </div> |
1616 | 1616 | <?php |
1617 | 1617 | } |
1618 | - }else{ |
|
1619 | - echo '<div class="alert alert-warning">'. __('No payment gateway active','invoicing') .'</div>'; |
|
1618 | + } else { |
|
1619 | + echo '<div class="alert alert-warning">' . __('No payment gateway active', 'invoicing') . '</div>'; |
|
1620 | 1620 | } |
1621 | 1621 | |
1622 | - do_action( 'wpinv_payment_mode_after_gateways' ); |
|
1622 | + do_action('wpinv_payment_mode_after_gateways'); |
|
1623 | 1623 | ?> |
1624 | 1624 | </div> |
1625 | 1625 | </div> |
1626 | - <?php do_action( 'wpinv_payment_mode_after_gateways_wrap' ); ?> |
|
1626 | + <?php do_action('wpinv_payment_mode_after_gateways_wrap'); ?> |
|
1627 | 1627 | </div> |
1628 | 1628 | <?php |
1629 | 1629 | do_action('wpinv_payment_mode_bottom'); |
1630 | 1630 | } |
1631 | -add_action( 'wpinv_payment_mode_select', 'wpinv_payment_mode_select' ); |
|
1631 | +add_action('wpinv_payment_mode_select', 'wpinv_payment_mode_select'); |
|
1632 | 1632 | |
1633 | 1633 | function wpinv_checkout_billing_info() { |
1634 | - if ( wpinv_is_checkout() ) { |
|
1634 | + if (wpinv_is_checkout()) { |
|
1635 | 1635 | $logged_in = is_user_logged_in(); |
1636 | 1636 | $billing_details = wpinv_checkout_billing_details(); |
1637 | - $selected_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : wpinv_default_billing_country(); |
|
1637 | + $selected_country = !empty($billing_details['country']) ? $billing_details['country'] : wpinv_default_billing_country(); |
|
1638 | 1638 | ?> |
1639 | 1639 | <div id="wpinv-fields" class="clearfix"> |
1640 | 1640 | <div id="wpi-billing" class="wpi-billing clearfix panel panel-default"> |
1641 | - <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Billing Details', 'invoicing' );?></h3></div> |
|
1641 | + <div class="panel-heading"><h3 class="panel-title"><?php _e('Billing Details', 'invoicing'); ?></h3></div> |
|
1642 | 1642 | <div id="wpinv-fields-box" class="panel-body"> |
1643 | - <?php do_action( 'wpinv_checkout_billing_fields_first', $billing_details ); ?> |
|
1643 | + <?php do_action('wpinv_checkout_billing_fields_first', $billing_details); ?> |
|
1644 | 1644 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
1645 | - <label for="wpinv_first_name" class="wpi-label"><?php _e( 'First Name', 'invoicing' );?><span class="wpi-required">*</span></label> |
|
1645 | + <label for="wpinv_first_name" class="wpi-label"><?php _e('First Name', 'invoicing'); ?><span class="wpi-required">*</span></label> |
|
1646 | 1646 | <?php |
1647 | - echo wpinv_html_text( array( |
|
1647 | + echo wpinv_html_text(array( |
|
1648 | 1648 | 'id' => 'wpinv_first_name', |
1649 | 1649 | 'name' => 'wpinv_first_name', |
1650 | 1650 | 'value' => $billing_details['first_name'], |
1651 | 1651 | 'class' => 'wpi-input form-control required', |
1652 | - 'placeholder' => __( 'First name', 'invoicing' ), |
|
1652 | + 'placeholder' => __('First name', 'invoicing'), |
|
1653 | 1653 | 'required' => true, |
1654 | - ) ); |
|
1654 | + )); |
|
1655 | 1655 | ?> |
1656 | 1656 | </p> |
1657 | 1657 | <p class="wpi-cart-field wpi-col2 wpi-coll"> |
1658 | - <label for="wpinv_last_name" class="wpi-label"><?php _e( 'Last Name', 'invoicing' );?></label> |
|
1658 | + <label for="wpinv_last_name" class="wpi-label"><?php _e('Last Name', 'invoicing'); ?></label> |
|
1659 | 1659 | <?php |
1660 | - echo wpinv_html_text( array( |
|
1660 | + echo wpinv_html_text(array( |
|
1661 | 1661 | 'id' => 'wpinv_last_name', |
1662 | 1662 | 'name' => 'wpinv_last_name', |
1663 | 1663 | 'value' => $billing_details['last_name'], |
1664 | 1664 | 'class' => 'wpi-input form-control', |
1665 | - 'placeholder' => __( 'Last name', 'invoicing' ), |
|
1666 | - ) ); |
|
1665 | + 'placeholder' => __('Last name', 'invoicing'), |
|
1666 | + )); |
|
1667 | 1667 | ?> |
1668 | 1668 | </p> |
1669 | 1669 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
1670 | - <label for="wpinv_address" class="wpi-label"><?php _e( 'Address', 'invoicing' );?><span class="wpi-required">*</span></label> |
|
1670 | + <label for="wpinv_address" class="wpi-label"><?php _e('Address', 'invoicing'); ?><span class="wpi-required">*</span></label> |
|
1671 | 1671 | <?php |
1672 | - echo wpinv_html_text( array( |
|
1672 | + echo wpinv_html_text(array( |
|
1673 | 1673 | 'id' => 'wpinv_address', |
1674 | 1674 | 'name' => 'wpinv_address', |
1675 | 1675 | 'value' => $billing_details['address'], |
1676 | 1676 | 'class' => 'wpi-input form-control required', |
1677 | - 'placeholder' => __( 'Address', 'invoicing' ), |
|
1677 | + 'placeholder' => __('Address', 'invoicing'), |
|
1678 | 1678 | 'required' => true, |
1679 | - ) ); |
|
1679 | + )); |
|
1680 | 1680 | ?> |
1681 | 1681 | </p> |
1682 | 1682 | <p class="wpi-cart-field wpi-col2 wpi-coll"> |
1683 | - <label for="wpinv_city" class="wpi-label"><?php _e( 'City', 'invoicing' );?><span class="wpi-required">*</span></label> |
|
1683 | + <label for="wpinv_city" class="wpi-label"><?php _e('City', 'invoicing'); ?><span class="wpi-required">*</span></label> |
|
1684 | 1684 | <?php |
1685 | - echo wpinv_html_text( array( |
|
1685 | + echo wpinv_html_text(array( |
|
1686 | 1686 | 'id' => 'wpinv_city', |
1687 | 1687 | 'name' => 'wpinv_city', |
1688 | 1688 | 'value' => $billing_details['city'], |
1689 | 1689 | 'class' => 'wpi-input form-control required', |
1690 | - 'placeholder' => __( 'City', 'invoicing' ), |
|
1690 | + 'placeholder' => __('City', 'invoicing'), |
|
1691 | 1691 | 'required' => true, |
1692 | - ) ); |
|
1692 | + )); |
|
1693 | 1693 | ?> |
1694 | 1694 | </p> |
1695 | 1695 | <p id="wpinv_country_box" class="wpi-cart-field wpi-col2 wpi-colf"> |
1696 | - <label for="wpinv_country" class="wpi-label"><?php _e( 'Country', 'invoicing' );?><span class="wpi-required">*</span></label> |
|
1697 | - <?php echo wpinv_html_select( array( |
|
1696 | + <label for="wpinv_country" class="wpi-label"><?php _e('Country', 'invoicing'); ?><span class="wpi-required">*</span></label> |
|
1697 | + <?php echo wpinv_html_select(array( |
|
1698 | 1698 | 'options' => wpinv_get_country_list(), |
1699 | 1699 | 'name' => 'wpinv_country', |
1700 | 1700 | 'id' => 'wpinv_country', |
@@ -1702,16 +1702,16 @@ discard block |
||
1702 | 1702 | 'show_option_all' => false, |
1703 | 1703 | 'show_option_none' => false, |
1704 | 1704 | 'class' => 'wpi-input form-control required', |
1705 | - 'placeholder' => __( 'Choose a country', 'invoicing' ), |
|
1705 | + 'placeholder' => __('Choose a country', 'invoicing'), |
|
1706 | 1706 | 'required' => true, |
1707 | - ) ); ?> |
|
1707 | + )); ?> |
|
1708 | 1708 | </p> |
1709 | 1709 | <p id="wpinv_state_box" class="wpi-cart-field wpi-col2 wpi-coll"> |
1710 | - <label for="wpinv_state" class="wpi-label"><?php _e( 'State / Province', 'invoicing' );?><span class="wpi-required">*</span></label> |
|
1710 | + <label for="wpinv_state" class="wpi-label"><?php _e('State / Province', 'invoicing'); ?><span class="wpi-required">*</span></label> |
|
1711 | 1711 | <?php |
1712 | - $states = wpinv_get_country_states( $selected_country ); |
|
1713 | - if( !empty( $states ) ) { |
|
1714 | - echo wpinv_html_select( array( |
|
1712 | + $states = wpinv_get_country_states($selected_country); |
|
1713 | + if (!empty($states)) { |
|
1714 | + echo wpinv_html_select(array( |
|
1715 | 1715 | 'options' => $states, |
1716 | 1716 | 'name' => 'wpinv_state', |
1717 | 1717 | 'id' => 'wpinv_state', |
@@ -1719,60 +1719,60 @@ discard block |
||
1719 | 1719 | 'show_option_all' => false, |
1720 | 1720 | 'show_option_none' => false, |
1721 | 1721 | 'class' => 'wpi-input form-control required', |
1722 | - 'placeholder' => __( 'Choose a state', 'invoicing' ), |
|
1722 | + 'placeholder' => __('Choose a state', 'invoicing'), |
|
1723 | 1723 | 'required' => true, |
1724 | - ) ); |
|
1724 | + )); |
|
1725 | 1725 | } else { |
1726 | - echo wpinv_html_text( array( |
|
1726 | + echo wpinv_html_text(array( |
|
1727 | 1727 | 'name' => 'wpinv_state', |
1728 | 1728 | 'value' => $billing_details['state'], |
1729 | 1729 | 'id' => 'wpinv_state', |
1730 | 1730 | 'class' => 'wpi-input form-control required', |
1731 | - 'placeholder' => __( 'State / Province', 'invoicing' ), |
|
1731 | + 'placeholder' => __('State / Province', 'invoicing'), |
|
1732 | 1732 | 'required' => true, |
1733 | - ) ); |
|
1733 | + )); |
|
1734 | 1734 | } |
1735 | 1735 | ?> |
1736 | 1736 | </p> |
1737 | 1737 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
1738 | - <label for="wpinv_zip" class="wpi-label"><?php _e( 'ZIP / Postcode', 'invoicing' );?></label> |
|
1738 | + <label for="wpinv_zip" class="wpi-label"><?php _e('ZIP / Postcode', 'invoicing'); ?></label> |
|
1739 | 1739 | <?php |
1740 | - echo wpinv_html_text( array( |
|
1740 | + echo wpinv_html_text(array( |
|
1741 | 1741 | 'name' => 'wpinv_zip', |
1742 | 1742 | 'value' => $billing_details['zip'], |
1743 | 1743 | 'id' => 'wpinv_zip', |
1744 | 1744 | 'class' => 'wpi-input form-control', |
1745 | - 'placeholder' => __( 'ZIP / Postcode', 'invoicing' ), |
|
1746 | - ) ); |
|
1745 | + 'placeholder' => __('ZIP / Postcode', 'invoicing'), |
|
1746 | + )); |
|
1747 | 1747 | ?> |
1748 | 1748 | </p> |
1749 | 1749 | <p class="wpi-cart-field wpi-col2 wpi-coll"> |
1750 | - <label for="wpinv_phone" class="wpi-label"><?php _e( 'Phone', 'invoicing' );?><?php if ( wpinv_get_option( 'phone_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
1750 | + <label for="wpinv_phone" class="wpi-label"><?php _e('Phone', 'invoicing'); ?><?php if (wpinv_get_option('phone_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
1751 | 1751 | <?php |
1752 | - echo wpinv_html_text( array( |
|
1752 | + echo wpinv_html_text(array( |
|
1753 | 1753 | 'id' => 'wpinv_phone', |
1754 | 1754 | 'name' => 'wpinv_phone', |
1755 | 1755 | 'value' => $billing_details['phone'], |
1756 | 1756 | 'class' => 'wpi-input form-control', |
1757 | - 'placeholder' => __( 'Phone', 'invoicing' ), |
|
1758 | - 'required' => (bool)wpinv_get_option( 'phone_mandatory' ), |
|
1759 | - ) ); |
|
1757 | + 'placeholder' => __('Phone', 'invoicing'), |
|
1758 | + 'required' => (bool)wpinv_get_option('phone_mandatory'), |
|
1759 | + )); |
|
1760 | 1760 | ?> |
1761 | 1761 | </p> |
1762 | - <?php do_action( 'wpinv_checkout_billing_fields_last', $billing_details ); ?> |
|
1762 | + <?php do_action('wpinv_checkout_billing_fields_last', $billing_details); ?> |
|
1763 | 1763 | <div class="clearfix"></div> |
1764 | 1764 | </div> |
1765 | 1765 | </div> |
1766 | - <?php do_action( 'wpinv_after_billing_fields', $billing_details ); ?> |
|
1766 | + <?php do_action('wpinv_after_billing_fields', $billing_details); ?> |
|
1767 | 1767 | </div> |
1768 | 1768 | <?php |
1769 | 1769 | } |
1770 | 1770 | } |
1771 | -add_action( 'wpinv_checkout_billing_info', 'wpinv_checkout_billing_info' ); |
|
1771 | +add_action('wpinv_checkout_billing_info', 'wpinv_checkout_billing_info'); |
|
1772 | 1772 | |
1773 | 1773 | function wpinv_checkout_hidden_fields() { |
1774 | 1774 | ?> |
1775 | - <?php if ( is_user_logged_in() ) { ?> |
|
1775 | + <?php if (is_user_logged_in()) { ?> |
|
1776 | 1776 | <input type="hidden" name="wpinv_user_id" value="<?php echo get_current_user_id(); ?>"/> |
1777 | 1777 | <?php } ?> |
1778 | 1778 | <input type="hidden" name="wpi_action" value="payment" /> |
@@ -1782,9 +1782,9 @@ discard block |
||
1782 | 1782 | function wpinv_checkout_button_purchase() { |
1783 | 1783 | ob_start(); |
1784 | 1784 | ?> |
1785 | - <input type="submit" class="btn btn-success wpinv-submit" id="wpinv-payment-button" data-value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>" name="wpinv_payment" value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>"/> |
|
1785 | + <input type="submit" class="btn btn-success wpinv-submit" id="wpinv-payment-button" data-value="<?php esc_attr_e('Proceed to Pay', 'invoicing') ?>" name="wpinv_payment" value="<?php esc_attr_e('Proceed to Pay', 'invoicing') ?>"/> |
|
1786 | 1786 | <?php |
1787 | - return apply_filters( 'wpinv_checkout_button_purchase', ob_get_clean() ); |
|
1787 | + return apply_filters('wpinv_checkout_button_purchase', ob_get_clean()); |
|
1788 | 1788 | } |
1789 | 1789 | |
1790 | 1790 | function wpinv_checkout_total() { |
@@ -1793,96 +1793,96 @@ discard block |
||
1793 | 1793 | <div id="wpinv_checkout_total" class="panel panel-info"> |
1794 | 1794 | <div class="panel-body"> |
1795 | 1795 | <?php |
1796 | - do_action( 'wpinv_purchase_form_before_checkout_total' ); |
|
1796 | + do_action('wpinv_purchase_form_before_checkout_total'); |
|
1797 | 1797 | ?> |
1798 | - <strong><?php _e( 'Invoice Total:', 'invoicing' ) ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total;?></span> |
|
1798 | + <strong><?php _e('Invoice Total:', 'invoicing') ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total; ?></span> |
|
1799 | 1799 | <?php |
1800 | - do_action( 'wpinv_purchase_form_after_checkout_total' ); |
|
1800 | + do_action('wpinv_purchase_form_after_checkout_total'); |
|
1801 | 1801 | ?> |
1802 | 1802 | </div> |
1803 | 1803 | </div> |
1804 | 1804 | <?php |
1805 | 1805 | } |
1806 | -add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998 ); |
|
1806 | +add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998); |
|
1807 | 1807 | |
1808 | 1808 | function wpinv_checkout_submit() { |
1809 | 1809 | ?> |
1810 | 1810 | <div id="wpinv_purchase_submit" class="panel panel-success"> |
1811 | 1811 | <div class="panel-body text-center"> |
1812 | 1812 | <?php |
1813 | - do_action( 'wpinv_purchase_form_before_submit' ); |
|
1813 | + do_action('wpinv_purchase_form_before_submit'); |
|
1814 | 1814 | wpinv_checkout_hidden_fields(); |
1815 | 1815 | echo wpinv_checkout_button_purchase(); |
1816 | - do_action( 'wpinv_purchase_form_after_submit' ); |
|
1816 | + do_action('wpinv_purchase_form_after_submit'); |
|
1817 | 1817 | ?> |
1818 | 1818 | </div> |
1819 | 1819 | </div> |
1820 | 1820 | <?php |
1821 | 1821 | } |
1822 | -add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999 ); |
|
1822 | +add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999); |
|
1823 | 1823 | |
1824 | -function wpinv_receipt_billing_address( $invoice_id = 0 ) { |
|
1825 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1824 | +function wpinv_receipt_billing_address($invoice_id = 0) { |
|
1825 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1826 | 1826 | |
1827 | - if ( empty( $invoice ) ) { |
|
1827 | + if (empty($invoice)) { |
|
1828 | 1828 | return NULL; |
1829 | 1829 | } |
1830 | 1830 | |
1831 | 1831 | $billing_details = $invoice->get_user_info(); |
1832 | 1832 | $address_row = ''; |
1833 | - if ( $address = $billing_details['address'] ) { |
|
1834 | - $address_row .= wpautop( wp_kses_post( $address ) ); |
|
1833 | + if ($address = $billing_details['address']) { |
|
1834 | + $address_row .= wpautop(wp_kses_post($address)); |
|
1835 | 1835 | } |
1836 | 1836 | |
1837 | 1837 | $address_fields = array(); |
1838 | - if ( !empty( $billing_details['city'] ) ) { |
|
1838 | + if (!empty($billing_details['city'])) { |
|
1839 | 1839 | $address_fields[] = $billing_details['city']; |
1840 | 1840 | } |
1841 | 1841 | |
1842 | - $billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : ''; |
|
1843 | - if ( !empty( $billing_details['state'] ) ) { |
|
1844 | - $address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country ); |
|
1842 | + $billing_country = !empty($billing_details['country']) ? $billing_details['country'] : ''; |
|
1843 | + if (!empty($billing_details['state'])) { |
|
1844 | + $address_fields[] = wpinv_state_name($billing_details['state'], $billing_country); |
|
1845 | 1845 | } |
1846 | 1846 | |
1847 | - if ( !empty( $billing_country ) ) { |
|
1848 | - $address_fields[] = wpinv_country_name( $billing_country ); |
|
1847 | + if (!empty($billing_country)) { |
|
1848 | + $address_fields[] = wpinv_country_name($billing_country); |
|
1849 | 1849 | } |
1850 | 1850 | |
1851 | - if ( !empty( $address_fields ) ) { |
|
1852 | - $address_fields = implode( ", ", $address_fields ); |
|
1851 | + if (!empty($address_fields)) { |
|
1852 | + $address_fields = implode(", ", $address_fields); |
|
1853 | 1853 | |
1854 | - if ( !empty( $billing_details['zip'] ) ) { |
|
1854 | + if (!empty($billing_details['zip'])) { |
|
1855 | 1855 | $address_fields .= ' ' . $billing_details['zip']; |
1856 | 1856 | } |
1857 | 1857 | |
1858 | - $address_row .= wpautop( wp_kses_post( $address_fields ) ); |
|
1858 | + $address_row .= wpautop(wp_kses_post($address_fields)); |
|
1859 | 1859 | } |
1860 | 1860 | ob_start(); |
1861 | 1861 | ?> |
1862 | 1862 | <table class="table table-bordered table-sm wpi-billing-details"> |
1863 | 1863 | <tbody> |
1864 | 1864 | <tr class="wpi-receipt-name"> |
1865 | - <th class="text-left"><?php _e( 'Name', 'invoicing' ); ?></th> |
|
1866 | - <td><?php echo esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) ;?></td> |
|
1865 | + <th class="text-left"><?php _e('Name', 'invoicing'); ?></th> |
|
1866 | + <td><?php echo esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])); ?></td> |
|
1867 | 1867 | </tr> |
1868 | 1868 | <tr class="wpi-receipt-email"> |
1869 | - <th class="text-left"><?php _e( 'Email', 'invoicing' ); ?></th> |
|
1870 | - <td><?php echo $billing_details['email'] ;?></td> |
|
1869 | + <th class="text-left"><?php _e('Email', 'invoicing'); ?></th> |
|
1870 | + <td><?php echo $billing_details['email']; ?></td> |
|
1871 | 1871 | </tr> |
1872 | - <?php if ( $billing_details['company'] ) { ?> |
|
1872 | + <?php if ($billing_details['company']) { ?> |
|
1873 | 1873 | <tr class="wpi-receipt-company"> |
1874 | - <th class="text-left"><?php _e( 'Company', 'invoicing' ); ?></th> |
|
1875 | - <td><?php echo esc_html( $billing_details['company'] ) ;?></td> |
|
1874 | + <th class="text-left"><?php _e('Company', 'invoicing'); ?></th> |
|
1875 | + <td><?php echo esc_html($billing_details['company']); ?></td> |
|
1876 | 1876 | </tr> |
1877 | 1877 | <?php } ?> |
1878 | 1878 | <tr class="wpi-receipt-address"> |
1879 | - <th class="text-left"><?php _e( 'Address', 'invoicing' ); ?></th> |
|
1880 | - <td><?php echo $address_row ;?></td> |
|
1879 | + <th class="text-left"><?php _e('Address', 'invoicing'); ?></th> |
|
1880 | + <td><?php echo $address_row; ?></td> |
|
1881 | 1881 | </tr> |
1882 | - <?php if ( $billing_details['phone'] ) { ?> |
|
1882 | + <?php if ($billing_details['phone']) { ?> |
|
1883 | 1883 | <tr class="wpi-receipt-phone"> |
1884 | - <th class="text-left"><?php _e( 'Phone', 'invoicing' ); ?></th> |
|
1885 | - <td><?php echo esc_html( $billing_details['phone'] ) ;?></td> |
|
1884 | + <th class="text-left"><?php _e('Phone', 'invoicing'); ?></th> |
|
1885 | + <td><?php echo esc_html($billing_details['phone']); ?></td> |
|
1886 | 1886 | </tr> |
1887 | 1887 | <?php } ?> |
1888 | 1888 | </tbody> |
@@ -1890,98 +1890,98 @@ discard block |
||
1890 | 1890 | <?php |
1891 | 1891 | $output = ob_get_clean(); |
1892 | 1892 | |
1893 | - $output = apply_filters( 'wpinv_receipt_billing_address', $output, $invoice_id ); |
|
1893 | + $output = apply_filters('wpinv_receipt_billing_address', $output, $invoice_id); |
|
1894 | 1894 | |
1895 | 1895 | echo $output; |
1896 | 1896 | } |
1897 | 1897 | |
1898 | -function wpinv_filter_success_page_content( $content ) { |
|
1899 | - if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) { |
|
1900 | - if ( has_filter( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ) ) ) { |
|
1901 | - $content = apply_filters( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ), $content ); |
|
1898 | +function wpinv_filter_success_page_content($content) { |
|
1899 | + if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) { |
|
1900 | + if (has_filter('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']))) { |
|
1901 | + $content = apply_filters('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']), $content); |
|
1902 | 1902 | } |
1903 | 1903 | } |
1904 | 1904 | |
1905 | 1905 | return $content; |
1906 | 1906 | } |
1907 | -add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 ); |
|
1907 | +add_filter('the_content', 'wpinv_filter_success_page_content', 99999); |
|
1908 | 1908 | |
1909 | -function wpinv_receipt_actions( $invoice ) { |
|
1910 | - if ( !empty( $invoice ) ) { |
|
1909 | +function wpinv_receipt_actions($invoice) { |
|
1910 | + if (!empty($invoice)) { |
|
1911 | 1911 | $actions = array( |
1912 | 1912 | 'print' => array( |
1913 | 1913 | 'url' => $invoice->get_view_url(), |
1914 | - 'name' => __( 'Print Invoice', 'invoicing' ), |
|
1914 | + 'name' => __('Print Invoice', 'invoicing'), |
|
1915 | 1915 | 'class' => 'btn-primary', |
1916 | 1916 | ), |
1917 | 1917 | 'history' => array( |
1918 | 1918 | 'url' => wpinv_get_history_page_uri(), |
1919 | - 'name' => __( 'Invoice History', 'invoicing' ), |
|
1919 | + 'name' => __('Invoice History', 'invoicing'), |
|
1920 | 1920 | 'class' => 'btn-warning', |
1921 | 1921 | ) |
1922 | 1922 | ); |
1923 | 1923 | |
1924 | - $actions = apply_filters( 'wpinv_invoice_receipt_actions', $actions, $invoice ); |
|
1924 | + $actions = apply_filters('wpinv_invoice_receipt_actions', $actions, $invoice); |
|
1925 | 1925 | |
1926 | - if ( !empty( $actions ) ) { |
|
1926 | + if (!empty($actions)) { |
|
1927 | 1927 | ?> |
1928 | 1928 | <div class="wpinv-receipt-actions text-right"> |
1929 | - <?php foreach ( $actions as $key => $action ) { $class = !empty($action['class']) ? sanitize_html_class( $action['class'] ) : ''; ?> |
|
1930 | - <a href="<?php echo esc_url( $action['url'] );?>" class="btn btn-sm <?php echo $class . ' ' . sanitize_html_class( $key );?>" <?php echo ( !empty($action['attrs']) ? $action['attrs'] : '' ) ;?>><?php echo esc_html( $action['name'] );?></a> |
|
1929 | + <?php foreach ($actions as $key => $action) { $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; ?> |
|
1930 | + <a href="<?php echo esc_url($action['url']); ?>" class="btn btn-sm <?php echo $class . ' ' . sanitize_html_class($key); ?>" <?php echo (!empty($action['attrs']) ? $action['attrs'] : ''); ?>><?php echo esc_html($action['name']); ?></a> |
|
1931 | 1931 | <?php } ?> |
1932 | 1932 | </div> |
1933 | 1933 | <?php |
1934 | 1934 | } |
1935 | 1935 | } |
1936 | 1936 | } |
1937 | -add_action( 'wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1 ); |
|
1937 | +add_action('wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1); |
|
1938 | 1938 | |
1939 | -function wpinv_invoice_link( $invoice_id ) { |
|
1940 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1939 | +function wpinv_invoice_link($invoice_id) { |
|
1940 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1941 | 1941 | |
1942 | - if ( empty( $invoice ) ) { |
|
1942 | + if (empty($invoice)) { |
|
1943 | 1943 | return NULL; |
1944 | 1944 | } |
1945 | 1945 | |
1946 | - $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>'; |
|
1946 | + $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>'; |
|
1947 | 1947 | |
1948 | - return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice ); |
|
1948 | + return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice); |
|
1949 | 1949 | } |
1950 | 1950 | |
1951 | -function wpinv_invoice_subscription_details( $invoice ) { |
|
1952 | - if ( !empty( $invoice ) && $invoice->is_recurring() && !wpinv_is_subscription_payment( $invoice ) ) { |
|
1951 | +function wpinv_invoice_subscription_details($invoice) { |
|
1952 | + if (!empty($invoice) && $invoice->is_recurring() && !wpinv_is_subscription_payment($invoice)) { |
|
1953 | 1953 | $total_payments = (int)$invoice->get_total_payments(); |
1954 | 1954 | $payments = $invoice->get_child_payments(); |
1955 | 1955 | |
1956 | 1956 | $subscription = $invoice->get_subscription_data(); |
1957 | 1957 | |
1958 | - if ( !( !empty( $subscription ) && !empty( $subscription['item_id'] ) ) ) { |
|
1958 | + if (!(!empty($subscription) && !empty($subscription['item_id']))) { |
|
1959 | 1959 | return; |
1960 | 1960 | } |
1961 | 1961 | |
1962 | - $billing_cycle = wpinv_get_billing_cycle( $subscription['initial_amount'], $subscription['recurring_amount'], $subscription['period'], $subscription['interval'], $subscription['bill_times'], $subscription['trial_period'], $subscription['trial_interval'], $invoice->get_currency() ); |
|
1963 | - $times_billed = $total_payments . ' / ' . ( ( (int)$subscription['bill_times'] == 0 ) ? __( 'Until cancelled', 'invoicing' ) : $subscription['bill_times'] ); |
|
1962 | + $billing_cycle = wpinv_get_billing_cycle($subscription['initial_amount'], $subscription['recurring_amount'], $subscription['period'], $subscription['interval'], $subscription['bill_times'], $subscription['trial_period'], $subscription['trial_interval'], $invoice->get_currency()); |
|
1963 | + $times_billed = $total_payments . ' / ' . (((int)$subscription['bill_times'] == 0) ? __('Until cancelled', 'invoicing') : $subscription['bill_times']); |
|
1964 | 1964 | |
1965 | 1965 | $subscription_status = $invoice->get_subscription_status(); |
1966 | 1966 | |
1967 | 1967 | $status_desc = ''; |
1968 | - if ( $subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date() ) { |
|
1969 | - $status_desc = wp_sprintf( __( 'Until: %s', 'invoicing' ), $trial_end_date ); |
|
1970 | - } else if ( $subscription_status == 'cancelled' && $cancelled_date = $invoice->get_cancelled_date() ) { |
|
1971 | - $status_desc = wp_sprintf( __( 'On: %s', 'invoicing' ), $cancelled_date ); |
|
1968 | + if ($subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date()) { |
|
1969 | + $status_desc = wp_sprintf(__('Until: %s', 'invoicing'), $trial_end_date); |
|
1970 | + } else if ($subscription_status == 'cancelled' && $cancelled_date = $invoice->get_cancelled_date()) { |
|
1971 | + $status_desc = wp_sprintf(__('On: %s', 'invoicing'), $cancelled_date); |
|
1972 | 1972 | } |
1973 | 1973 | $status_desc = $status_desc != '' ? '<span class="meta">' . $status_desc . '</span>' : ''; |
1974 | 1974 | ?> |
1975 | 1975 | <div class="wpinv-subscriptions-details"> |
1976 | - <h3 class="wpinv-subscriptions-t"><?php echo apply_filters( 'wpinv_subscription_details_title', __( 'Subscription Details', 'invoicing' ) ); ?></h3> |
|
1976 | + <h3 class="wpinv-subscriptions-t"><?php echo apply_filters('wpinv_subscription_details_title', __('Subscription Details', 'invoicing')); ?></h3> |
|
1977 | 1977 | <table class="table"> |
1978 | 1978 | <thead> |
1979 | 1979 | <tr> |
1980 | - <th><?php _e( 'Billing Cycle', 'invoicing' ) ;?></th> |
|
1981 | - <th><?php _e( 'Start Date', 'invoicing' ) ;?></th> |
|
1982 | - <th><?php _e( 'Expiration Date', 'invoicing' ) ;?></th> |
|
1983 | - <th class="text-center"><?php _e( 'Times Billed', 'invoicing' ) ;?></th> |
|
1984 | - <th class="text-center"><?php _e( 'Status', 'invoicing' ) ;?></th> |
|
1980 | + <th><?php _e('Billing Cycle', 'invoicing'); ?></th> |
|
1981 | + <th><?php _e('Start Date', 'invoicing'); ?></th> |
|
1982 | + <th><?php _e('Expiration Date', 'invoicing'); ?></th> |
|
1983 | + <th class="text-center"><?php _e('Times Billed', 'invoicing'); ?></th> |
|
1984 | + <th class="text-center"><?php _e('Status', 'invoicing'); ?></th> |
|
1985 | 1985 | </tr> |
1986 | 1986 | </thead> |
1987 | 1987 | <tbody> |
@@ -1990,32 +1990,32 @@ discard block |
||
1990 | 1990 | <td><?php echo $invoice->get_subscription_start(); ?></td> |
1991 | 1991 | <td><?php echo $invoice->get_subscription_end(); ?></td> |
1992 | 1992 | <td class="text-center"><?php echo $times_billed; ?></td> |
1993 | - <td class="text-center wpi-sub-status"><?php echo $invoice->get_subscription_status_label() ;?> |
|
1993 | + <td class="text-center wpi-sub-status"><?php echo $invoice->get_subscription_status_label(); ?> |
|
1994 | 1994 | <?php echo $status_desc; ?> |
1995 | 1995 | </td> |
1996 | 1996 | </tr> |
1997 | 1997 | </tbody> |
1998 | 1998 | </table> |
1999 | 1999 | </div> |
2000 | - <?php if ( !empty( $payments ) ) { ?> |
|
2000 | + <?php if (!empty($payments)) { ?> |
|
2001 | 2001 | <div class="wpinv-renewal-payments"> |
2002 | - <h3 class="wpinv-renewals-t"><?php echo apply_filters( 'wpinv_renewal_payments_title', __( 'Renewal Payments', 'invoicing' ) ); ?></h3> |
|
2002 | + <h3 class="wpinv-renewals-t"><?php echo apply_filters('wpinv_renewal_payments_title', __('Renewal Payments', 'invoicing')); ?></h3> |
|
2003 | 2003 | <table class="table"> |
2004 | 2004 | <thead> |
2005 | 2005 | <tr> |
2006 | 2006 | <th>#</th> |
2007 | - <th><?php _e( 'Invoice', 'invoicing' ) ;?></th> |
|
2008 | - <th><?php _e( 'Date', 'invoicing' ) ;?></th> |
|
2009 | - <th class="text-right"><?php _e( 'Amount', 'invoicing' ) ;?></th> |
|
2007 | + <th><?php _e('Invoice', 'invoicing'); ?></th> |
|
2008 | + <th><?php _e('Date', 'invoicing'); ?></th> |
|
2009 | + <th class="text-right"><?php _e('Amount', 'invoicing'); ?></th> |
|
2010 | 2010 | </tr> |
2011 | 2011 | </thead> |
2012 | 2012 | <tbody> |
2013 | - <?php foreach ( $payments as $key => $invoice_id ) { ?> |
|
2013 | + <?php foreach ($payments as $key => $invoice_id) { ?> |
|
2014 | 2014 | <tr> |
2015 | - <th scope="row"><?php echo ( $key + 1 );?></th> |
|
2016 | - <td><?php echo wpinv_invoice_link( $invoice_id ) ;?></td> |
|
2017 | - <td><?php echo wpinv_get_invoice_date( $invoice_id ); ?></td> |
|
2018 | - <td class="text-right"><?php echo wpinv_payment_total( $invoice_id, true ); ?></td> |
|
2015 | + <th scope="row"><?php echo ($key + 1); ?></th> |
|
2016 | + <td><?php echo wpinv_invoice_link($invoice_id); ?></td> |
|
2017 | + <td><?php echo wpinv_get_invoice_date($invoice_id); ?></td> |
|
2018 | + <td class="text-right"><?php echo wpinv_payment_total($invoice_id, true); ?></td> |
|
2019 | 2019 | </tr> |
2020 | 2020 | <?php } ?> |
2021 | 2021 | <tr><td colspan="4" style="padding:0"></td></tr> |
@@ -2027,52 +2027,52 @@ discard block |
||
2027 | 2027 | } |
2028 | 2028 | } |
2029 | 2029 | |
2030 | -function wpinv_cart_total_label( $label, $invoice ) { |
|
2031 | - if ( empty( $invoice ) ) { |
|
2030 | +function wpinv_cart_total_label($label, $invoice) { |
|
2031 | + if (empty($invoice)) { |
|
2032 | 2032 | return $label; |
2033 | 2033 | } |
2034 | 2034 | |
2035 | 2035 | $prefix_label = ''; |
2036 | - if ( $invoice->is_parent() && $item_id = $invoice->get_recurring() ) { |
|
2037 | - $prefix_label = '<span class="label label-primary label-recurring">' . __( 'Recurring Payment', 'invoicing' ) . '</span> ' . wpinv_subscription_payment_desc( $invoice ); |
|
2038 | - } else if ( $invoice->is_renewal() ) { |
|
2039 | - $prefix_label = '<span class="label label-primary label-renewal">' . __( 'Renewal Payment', 'invoicing' ) . '</span> '; |
|
2036 | + if ($invoice->is_parent() && $item_id = $invoice->get_recurring()) { |
|
2037 | + $prefix_label = '<span class="label label-primary label-recurring">' . __('Recurring Payment', 'invoicing') . '</span> ' . wpinv_subscription_payment_desc($invoice); |
|
2038 | + } else if ($invoice->is_renewal()) { |
|
2039 | + $prefix_label = '<span class="label label-primary label-renewal">' . __('Renewal Payment', 'invoicing') . '</span> '; |
|
2040 | 2040 | } |
2041 | 2041 | |
2042 | - if ( $prefix_label != '' ) { |
|
2043 | - $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label; |
|
2042 | + if ($prefix_label != '') { |
|
2043 | + $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label; |
|
2044 | 2044 | } |
2045 | 2045 | |
2046 | 2046 | return $label; |
2047 | 2047 | } |
2048 | -add_filter( 'wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
2049 | -add_filter( 'wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
2050 | -add_filter( 'wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
2048 | +add_filter('wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
2049 | +add_filter('wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
2050 | +add_filter('wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
2051 | 2051 | |
2052 | -add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1 ); |
|
2052 | +add_action('wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1); |
|
2053 | 2053 | |
2054 | -function wpinv_invoice_print_description( $invoice ) { |
|
2055 | - if ( empty( $invoice ) ) { |
|
2054 | +function wpinv_invoice_print_description($invoice) { |
|
2055 | + if (empty($invoice)) { |
|
2056 | 2056 | return NULL; |
2057 | 2057 | } |
2058 | - if ( $description = wpinv_get_invoice_description( $invoice->ID ) ) { |
|
2058 | + if ($description = wpinv_get_invoice_description($invoice->ID)) { |
|
2059 | 2059 | ?> |
2060 | 2060 | <div class="row wpinv-lower"> |
2061 | 2061 | <div class="col-sm-12 wpinv-description"> |
2062 | - <?php echo wpautop( $description ); ?> |
|
2062 | + <?php echo wpautop($description); ?> |
|
2063 | 2063 | </div> |
2064 | 2064 | </div> |
2065 | 2065 | <?php |
2066 | 2066 | } |
2067 | 2067 | } |
2068 | -add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1 ); |
|
2068 | +add_action('wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1); |
|
2069 | 2069 | |
2070 | -function wpinv_invoice_print_payment_info( $invoice ) { |
|
2071 | - if ( empty( $invoice ) ) { |
|
2070 | +function wpinv_invoice_print_payment_info($invoice) { |
|
2071 | + if (empty($invoice)) { |
|
2072 | 2072 | return NULL; |
2073 | 2073 | } |
2074 | 2074 | |
2075 | - if ( $payments_info = wpinv_display_payments_info( $invoice->ID, false ) ) { |
|
2075 | + if ($payments_info = wpinv_display_payments_info($invoice->ID, false)) { |
|
2076 | 2076 | ?> |
2077 | 2077 | <div class="row wpinv-payments"> |
2078 | 2078 | <div class="col-sm-12"> |
@@ -2084,40 +2084,40 @@ discard block |
||
2084 | 2084 | } |
2085 | 2085 | // add_action( 'wpinv_invoice_print_after_line_items', 'wpinv_invoice_print_payment_info', 10, 1 ); |
2086 | 2086 | |
2087 | -function wpinv_get_invoice_note_line_item( $note, $echo = true ) { |
|
2088 | - if ( empty( $note ) ) { |
|
2087 | +function wpinv_get_invoice_note_line_item($note, $echo = true) { |
|
2088 | + if (empty($note)) { |
|
2089 | 2089 | return NULL; |
2090 | 2090 | } |
2091 | 2091 | |
2092 | - if ( is_int( $note ) ) { |
|
2093 | - $note = get_comment( $note ); |
|
2092 | + if (is_int($note)) { |
|
2093 | + $note = get_comment($note); |
|
2094 | 2094 | } |
2095 | 2095 | |
2096 | - if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) { |
|
2096 | + if (!(is_object($note) && is_a($note, 'WP_Comment'))) { |
|
2097 | 2097 | return NULL; |
2098 | 2098 | } |
2099 | 2099 | |
2100 | - $note_classes = array( 'note' ); |
|
2101 | - $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : ''; |
|
2102 | - $note_classes[] = $note->comment_author === __( 'GeoDirectory', 'invoicing' ) ? 'system-note' : ''; |
|
2103 | - $note_classes = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note ); |
|
2104 | - $note_classes = !empty( $note_classes ) ? implode( ' ', $note_classes ) : ''; |
|
2100 | + $note_classes = array('note'); |
|
2101 | + $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : ''; |
|
2102 | + $note_classes[] = $note->comment_author === __('GeoDirectory', 'invoicing') ? 'system-note' : ''; |
|
2103 | + $note_classes = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note); |
|
2104 | + $note_classes = !empty($note_classes) ? implode(' ', $note_classes) : ''; |
|
2105 | 2105 | |
2106 | 2106 | ob_start(); |
2107 | 2107 | ?> |
2108 | - <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?>"> |
|
2108 | + <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?>"> |
|
2109 | 2109 | <div class="note_content"> |
2110 | - <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?> |
|
2110 | + <?php echo wpautop(wptexturize(wp_kses_post($note->comment_content))); ?> |
|
2111 | 2111 | </div> |
2112 | 2112 | <p class="meta"> |
2113 | - <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf( __( '%1$s - %2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( get_option( 'date_format' ), strtotime( $note->comment_date ) ), date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) ); ?></abbr> <a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a> |
|
2113 | + <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf(__('%1$s - %2$s at %3$s', 'invoicing'), $note->comment_author, date_i18n(get_option('date_format'), strtotime($note->comment_date)), date_i18n(get_option('time_format'), strtotime($note->comment_date))); ?></abbr> <a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a> |
|
2114 | 2114 | </p> |
2115 | 2115 | </li> |
2116 | 2116 | <?php |
2117 | 2117 | $note_content = ob_get_clean(); |
2118 | - $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo ); |
|
2118 | + $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo); |
|
2119 | 2119 | |
2120 | - if ( $echo ) { |
|
2120 | + if ($echo) { |
|
2121 | 2121 | echo $note_content; |
2122 | 2122 | } else { |
2123 | 2123 | return $note_content; |
@@ -70,7 +70,10 @@ discard block |
||
70 | 70 | } |
71 | 71 | |
72 | 72 | function wpinv_invoice_display_right_actions( $invoice ) { |
73 | - if ( empty( $invoice ) ) return; //Exit if invoice is not set. |
|
73 | + if ( empty( $invoice ) ) { |
|
74 | + return; |
|
75 | + } |
|
76 | + //Exit if invoice is not set. |
|
74 | 77 | |
75 | 78 | if($invoice->post_type == 'wpi_invoice'){ |
76 | 79 | $user_id = (int)$invoice->get_user_id(); |
@@ -177,8 +180,9 @@ discard block |
||
177 | 180 | |
178 | 181 | // Setup possible parts |
179 | 182 | $templates = array(); |
180 | - if ( isset( $name ) ) |
|
181 | - $templates[] = $slug . '-' . $name . '.php'; |
|
183 | + if ( isset( $name ) ) { |
|
184 | + $templates[] = $slug . '-' . $name . '.php'; |
|
185 | + } |
|
182 | 186 | $templates[] = $slug . '.php'; |
183 | 187 | |
184 | 188 | // Allow template parts to be filtered |
@@ -196,8 +200,9 @@ discard block |
||
196 | 200 | foreach ( (array)$template_names as $template_name ) { |
197 | 201 | |
198 | 202 | // Continue if template is empty |
199 | - if ( empty( $template_name ) ) |
|
200 | - continue; |
|
203 | + if ( empty( $template_name ) ) { |
|
204 | + continue; |
|
205 | + } |
|
201 | 206 | |
202 | 207 | // Trim off any slashes from the template name |
203 | 208 | $template_name = ltrim( $template_name, '/' ); |
@@ -216,8 +221,9 @@ discard block |
||
216 | 221 | } |
217 | 222 | } |
218 | 223 | |
219 | - if ( ( true == $load ) && ! empty( $located ) ) |
|
220 | - load_template( $located, $require_once ); |
|
224 | + if ( ( true == $load ) && ! empty( $located ) ) { |
|
225 | + load_template( $located, $require_once ); |
|
226 | + } |
|
221 | 227 | |
222 | 228 | return $located; |
223 | 229 | } |
@@ -293,8 +299,9 @@ discard block |
||
293 | 299 | function wpinv_html_dropdown( $name = 'wpinv_discounts', $selected = 0, $status = '' ) { |
294 | 300 | $args = array( 'nopaging' => true ); |
295 | 301 | |
296 | - if ( ! empty( $status ) ) |
|
297 | - $args['post_status'] = $status; |
|
302 | + if ( ! empty( $status ) ) { |
|
303 | + $args['post_status'] = $status; |
|
304 | + } |
|
298 | 305 | |
299 | 306 | $discounts = wpinv_get_discounts( $args ); |
300 | 307 | $options = array(); |
@@ -898,8 +905,11 @@ discard block |
||
898 | 905 | |
899 | 906 | $invoice_status = wpinv_get_invoice_status( $invoice_id ); |
900 | 907 | |
901 | - if($invoice->post_type == 'wpi_invoice') $type = 'Invoice'; |
|
902 | - elseif($invoice->post_type == 'wpi_quote') $type = 'Quote'; |
|
908 | + if($invoice->post_type == 'wpi_invoice') { |
|
909 | + $type = 'Invoice'; |
|
910 | + } elseif($invoice->post_type == 'wpi_quote') { |
|
911 | + $type = 'Quote'; |
|
912 | + } |
|
903 | 913 | ?> |
904 | 914 | <table class="table table-bordered table-sm"> |
905 | 915 | <?php if ( $invoice_number = wpinv_get_invoice_number( $invoice_id ) ) { ?> |
@@ -1466,17 +1476,19 @@ discard block |
||
1466 | 1476 | add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' ); |
1467 | 1477 | |
1468 | 1478 | function wpinv_save_cart_button() { |
1469 | - if ( wpinv_is_cart_saving_disabled() ) |
|
1470 | - return; |
|
1471 | -?> |
|
1479 | + if ( wpinv_is_cart_saving_disabled() ) { |
|
1480 | + return; |
|
1481 | + } |
|
1482 | + ?> |
|
1472 | 1483 | <a class="wpinv-cart-saving-button wpinv-submit button" id="wpinv-save-cart-button" href="<?php echo esc_url( add_query_arg( 'wpi_action', 'save_cart' ) ); ?>"><?php _e( 'Save Cart', 'invoicing' ); ?></a> |
1473 | 1484 | <?php |
1474 | 1485 | } |
1475 | 1486 | |
1476 | 1487 | function wpinv_update_cart_button() { |
1477 | - if ( !wpinv_item_quantities_enabled() ) |
|
1478 | - return; |
|
1479 | -?> |
|
1488 | + if ( !wpinv_item_quantities_enabled() ) { |
|
1489 | + return; |
|
1490 | + } |
|
1491 | + ?> |
|
1480 | 1492 | <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e( 'Update Cart', 'invoicing' ); ?>"/> |
1481 | 1493 | <input type="hidden" name="wpi_action" value="update_cart"/> |
1482 | 1494 | <?php |
@@ -1615,7 +1627,7 @@ discard block |
||
1615 | 1627 | </div> |
1616 | 1628 | <?php |
1617 | 1629 | } |
1618 | - }else{ |
|
1630 | + } else{ |
|
1619 | 1631 | echo '<div class="alert alert-warning">'. __('No payment gateway active','invoicing') .'</div>'; |
1620 | 1632 | } |
1621 | 1633 |
@@ -7,12 +7,12 @@ 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 | final class WPInv_Invoice { |
15 | - public $ID = 0; |
|
15 | + public $ID = 0; |
|
16 | 16 | public $title; |
17 | 17 | public $post_type; |
18 | 18 | |
@@ -65,17 +65,17 @@ discard block |
||
65 | 65 | public $full_name = ''; |
66 | 66 | public $parent_invoice = 0; |
67 | 67 | |
68 | - public function __construct( $invoice_id = false ) { |
|
69 | - if( empty( $invoice_id ) ) { |
|
68 | + public function __construct($invoice_id = false) { |
|
69 | + if (empty($invoice_id)) { |
|
70 | 70 | return false; |
71 | 71 | } |
72 | 72 | |
73 | - $this->setup_invoice( $invoice_id ); |
|
73 | + $this->setup_invoice($invoice_id); |
|
74 | 74 | } |
75 | 75 | |
76 | - public function get( $key ) { |
|
77 | - if ( method_exists( $this, 'get_' . $key ) ) { |
|
78 | - $value = call_user_func( array( $this, 'get_' . $key ) ); |
|
76 | + public function get($key) { |
|
77 | + if (method_exists($this, 'get_' . $key)) { |
|
78 | + $value = call_user_func(array($this, 'get_' . $key)); |
|
79 | 79 | } else { |
80 | 80 | $value = $this->$key; |
81 | 81 | } |
@@ -83,52 +83,52 @@ discard block |
||
83 | 83 | return $value; |
84 | 84 | } |
85 | 85 | |
86 | - public function set( $key, $value ) { |
|
87 | - $ignore = array( 'items', 'cart_details', 'fees', '_ID' ); |
|
86 | + public function set($key, $value) { |
|
87 | + $ignore = array('items', 'cart_details', 'fees', '_ID'); |
|
88 | 88 | |
89 | - if ( $key === 'status' ) { |
|
89 | + if ($key === 'status') { |
|
90 | 90 | $this->old_status = $this->status; |
91 | 91 | } |
92 | 92 | |
93 | - if ( ! in_array( $key, $ignore ) ) { |
|
94 | - $this->pending[ $key ] = $value; |
|
93 | + if (!in_array($key, $ignore)) { |
|
94 | + $this->pending[$key] = $value; |
|
95 | 95 | } |
96 | 96 | |
97 | - if( '_ID' !== $key ) { |
|
97 | + if ('_ID' !== $key) { |
|
98 | 98 | $this->$key = $value; |
99 | 99 | } |
100 | 100 | } |
101 | 101 | |
102 | - public function _isset( $name ) { |
|
103 | - if ( property_exists( $this, $name) ) { |
|
104 | - return false === empty( $this->$name ); |
|
102 | + public function _isset($name) { |
|
103 | + if (property_exists($this, $name)) { |
|
104 | + return false === empty($this->$name); |
|
105 | 105 | } else { |
106 | 106 | return null; |
107 | 107 | } |
108 | 108 | } |
109 | 109 | |
110 | - private function setup_invoice( $invoice_id ) { |
|
110 | + private function setup_invoice($invoice_id) { |
|
111 | 111 | $this->pending = array(); |
112 | 112 | |
113 | - if ( empty( $invoice_id ) ) { |
|
113 | + if (empty($invoice_id)) { |
|
114 | 114 | return false; |
115 | 115 | } |
116 | 116 | |
117 | - $invoice = get_post( $invoice_id ); |
|
117 | + $invoice = get_post($invoice_id); |
|
118 | 118 | |
119 | - if( !$invoice || is_wp_error( $invoice ) ) { |
|
119 | + if (!$invoice || is_wp_error($invoice)) { |
|
120 | 120 | return false; |
121 | 121 | } |
122 | 122 | |
123 | - if( !('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type) ) { |
|
123 | + if (!('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type)) { |
|
124 | 124 | return false; |
125 | 125 | } |
126 | 126 | |
127 | - do_action( 'wpinv_pre_setup_invoice', $this, $invoice_id ); |
|
127 | + do_action('wpinv_pre_setup_invoice', $this, $invoice_id); |
|
128 | 128 | |
129 | 129 | // Primary Identifier |
130 | - $this->ID = absint( $invoice_id ); |
|
131 | - $this->post_type = $invoice->post_type; |
|
130 | + $this->ID = absint($invoice_id); |
|
131 | + $this->post_type = $invoice->post_type; |
|
132 | 132 | |
133 | 133 | // We have a payment, get the generic payment_meta item to reduce calls to it |
134 | 134 | $this->payment_meta = $this->get_meta(); |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | $this->post_status = $this->status; |
140 | 140 | $this->mode = $this->setup_mode(); |
141 | 141 | $this->parent_invoice = $invoice->post_parent; |
142 | - $this->post_name = $this->setup_post_name( $invoice ); |
|
142 | + $this->post_name = $this->setup_post_name($invoice); |
|
143 | 143 | $this->status_nicename = $this->setup_status_nicename(); |
144 | 144 | |
145 | 145 | // Items |
@@ -161,8 +161,8 @@ discard block |
||
161 | 161 | |
162 | 162 | // User based |
163 | 163 | $this->ip = $this->setup_ip(); |
164 | - $this->user_id = !empty( $invoice->post_author ) ? $invoice->post_author : get_current_user_id();///$this->setup_user_id(); |
|
165 | - $this->email = get_the_author_meta( 'email', $this->user_id ); |
|
164 | + $this->user_id = !empty($invoice->post_author) ? $invoice->post_author : get_current_user_id(); ///$this->setup_user_id(); |
|
165 | + $this->email = get_the_author_meta('email', $this->user_id); |
|
166 | 166 | |
167 | 167 | $this->user_info = $this->setup_user_info(); |
168 | 168 | |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | $this->company = $this->user_info['company']; |
172 | 172 | $this->vat_number = $this->user_info['vat_number']; |
173 | 173 | $this->vat_rate = $this->user_info['vat_rate']; |
174 | - $this->adddress_confirmed = $this->user_info['adddress_confirmed']; |
|
174 | + $this->adddress_confirmed = $this->user_info['adddress_confirmed']; |
|
175 | 175 | $this->address = $this->user_info['address']; |
176 | 176 | $this->city = $this->user_info['city']; |
177 | 177 | $this->country = $this->user_info['country']; |
@@ -186,48 +186,48 @@ discard block |
||
186 | 186 | // Other Identifiers |
187 | 187 | $this->key = $this->setup_invoice_key(); |
188 | 188 | $this->number = $this->setup_invoice_number(); |
189 | - $this->title = !empty( $invoice->post_title ) ? $invoice->post_title : $this->number; |
|
189 | + $this->title = !empty($invoice->post_title) ? $invoice->post_title : $this->number; |
|
190 | 190 | |
191 | - $this->full_name = trim( $this->first_name . ' '. $this->last_name ); |
|
191 | + $this->full_name = trim($this->first_name . ' ' . $this->last_name); |
|
192 | 192 | |
193 | 193 | // Allow extensions to add items to this object via hook |
194 | - do_action( 'wpinv_setup_invoice', $this, $invoice_id ); |
|
194 | + do_action('wpinv_setup_invoice', $this, $invoice_id); |
|
195 | 195 | |
196 | 196 | return true; |
197 | 197 | } |
198 | 198 | |
199 | 199 | private function setup_status_nicename() { |
200 | - $all_invoice_statuses = wpinv_get_invoice_statuses(); |
|
200 | + $all_invoice_statuses = wpinv_get_invoice_statuses(); |
|
201 | 201 | |
202 | - $status = array_key_exists( $this->status, $all_invoice_statuses ) ? $all_invoice_statuses[$this->status] : ucfirst( $this->status ); |
|
202 | + $status = array_key_exists($this->status, $all_invoice_statuses) ? $all_invoice_statuses[$this->status] : ucfirst($this->status); |
|
203 | 203 | |
204 | 204 | return $status; |
205 | 205 | } |
206 | 206 | |
207 | - private function setup_post_name( $post = NULL ) { |
|
207 | + private function setup_post_name($post = NULL) { |
|
208 | 208 | $post_name = ''; |
209 | 209 | |
210 | - if ( !empty( $post ) ) { |
|
211 | - if( !empty( $post->post_name ) ) { |
|
210 | + if (!empty($post)) { |
|
211 | + if (!empty($post->post_name)) { |
|
212 | 212 | $post_name = $post->post_name; |
213 | - } else if ( !empty( $post->ID ) && !empty( $post->post_title ) ) { |
|
214 | - $post_name = sanitize_title( $post->post_title ); |
|
213 | + } else if (!empty($post->ID) && !empty($post->post_title)) { |
|
214 | + $post_name = sanitize_title($post->post_title); |
|
215 | 215 | |
216 | 216 | global $wpdb; |
217 | - $wpdb->update( $wpdb->posts, array( 'post_name' => $post_name ), array( 'ID' => $post->ID ) ); |
|
217 | + $wpdb->update($wpdb->posts, array('post_name' => $post_name), array('ID' => $post->ID)); |
|
218 | 218 | } |
219 | 219 | } |
220 | 220 | |
221 | - $this->post_name = $post_name; |
|
221 | + $this->post_name = $post_name; |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | private function setup_due_date() { |
225 | - $due_date = $this->get_meta( '_wpinv_due_date' ); |
|
225 | + $due_date = $this->get_meta('_wpinv_due_date'); |
|
226 | 226 | |
227 | - if ( empty( $due_date ) ) { |
|
228 | - $overdue_time = strtotime( $this->date ) + ( DAY_IN_SECONDS * absint( wpinv_get_option( 'overdue_days' ) ) ); |
|
229 | - $due_date = date_i18n( 'Y-m-d', $overdue_time ); |
|
230 | - } else if ( $due_date == 'none' ) { |
|
227 | + if (empty($due_date)) { |
|
228 | + $overdue_time = strtotime($this->date) + (DAY_IN_SECONDS * absint(wpinv_get_option('overdue_days'))); |
|
229 | + $due_date = date_i18n('Y-m-d', $overdue_time); |
|
230 | + } else if ($due_date == 'none') { |
|
231 | 231 | $due_date = ''; |
232 | 232 | } |
233 | 233 | |
@@ -235,63 +235,63 @@ discard block |
||
235 | 235 | } |
236 | 236 | |
237 | 237 | private function setup_completed_date() { |
238 | - $invoice = get_post( $this->ID ); |
|
238 | + $invoice = get_post($this->ID); |
|
239 | 239 | |
240 | - if ( 'pending' == $invoice->post_status || 'preapproved' == $invoice->post_status ) { |
|
240 | + if ('pending' == $invoice->post_status || 'preapproved' == $invoice->post_status) { |
|
241 | 241 | return false; // This invoice was never paid |
242 | 242 | } |
243 | 243 | |
244 | - $date = ( $date = $this->get_meta( '_wpinv_completed_date', true ) ) ? $date : $invoice->modified_date; |
|
244 | + $date = ($date = $this->get_meta('_wpinv_completed_date', true)) ? $date : $invoice->modified_date; |
|
245 | 245 | |
246 | 246 | return $date; |
247 | 247 | } |
248 | 248 | |
249 | 249 | private function setup_cart_details() { |
250 | - $cart_details = isset( $this->payment_meta['cart_details'] ) ? maybe_unserialize( $this->payment_meta['cart_details'] ) : array(); |
|
250 | + $cart_details = isset($this->payment_meta['cart_details']) ? maybe_unserialize($this->payment_meta['cart_details']) : array(); |
|
251 | 251 | return $cart_details; |
252 | 252 | } |
253 | 253 | |
254 | 254 | public function array_convert() { |
255 | - return get_object_vars( $this ); |
|
255 | + return get_object_vars($this); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | private function setup_items() { |
259 | - $items = isset( $this->payment_meta['items'] ) ? maybe_unserialize( $this->payment_meta['items'] ) : array(); |
|
259 | + $items = isset($this->payment_meta['items']) ? maybe_unserialize($this->payment_meta['items']) : array(); |
|
260 | 260 | return $items; |
261 | 261 | } |
262 | 262 | |
263 | 263 | private function setup_fees() { |
264 | - $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array(); |
|
264 | + $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array(); |
|
265 | 265 | return $payment_fees; |
266 | 266 | } |
267 | 267 | |
268 | 268 | private function setup_currency() { |
269 | - $currency = isset( $this->payment_meta['currency'] ) ? $this->payment_meta['currency'] : apply_filters( 'wpinv_currency_default', wpinv_get_currency(), $this ); |
|
269 | + $currency = isset($this->payment_meta['currency']) ? $this->payment_meta['currency'] : apply_filters('wpinv_currency_default', wpinv_get_currency(), $this); |
|
270 | 270 | return $currency; |
271 | 271 | } |
272 | 272 | |
273 | 273 | private function setup_discount() { |
274 | 274 | //$discount = $this->get_meta( '_wpinv_discount', true ); |
275 | - $discount = $this->subtotal - ( $this->total - $this->tax - $this->fees_total ); |
|
276 | - if ( $discount < 0 ) { |
|
275 | + $discount = $this->subtotal - ($this->total - $this->tax - $this->fees_total); |
|
276 | + if ($discount < 0) { |
|
277 | 277 | $discount = 0; |
278 | 278 | } |
279 | - $discount = wpinv_format_amount( $discount, NULL, true ); |
|
279 | + $discount = wpinv_format_amount($discount, NULL, true); |
|
280 | 280 | |
281 | 281 | return $discount; |
282 | 282 | } |
283 | 283 | |
284 | 284 | private function setup_discount_code() { |
285 | - $discount_code = !empty( $this->discounts ) ? $this->discounts : $this->get_meta( '_wpinv_discount_code', true ); |
|
285 | + $discount_code = !empty($this->discounts) ? $this->discounts : $this->get_meta('_wpinv_discount_code', true); |
|
286 | 286 | return $discount_code; |
287 | 287 | } |
288 | 288 | |
289 | 289 | private function setup_tax() { |
290 | - $tax = $this->get_meta( '_wpinv_tax', true ); |
|
290 | + $tax = $this->get_meta('_wpinv_tax', true); |
|
291 | 291 | |
292 | 292 | // We don't have tax as it's own meta and no meta was passed |
293 | - if ( '' === $tax ) { |
|
294 | - $tax = isset( $this->payment_meta['tax'] ) ? $this->payment_meta['tax'] : 0; |
|
293 | + if ('' === $tax) { |
|
294 | + $tax = isset($this->payment_meta['tax']) ? $this->payment_meta['tax'] : 0; |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | return $tax; |
@@ -305,9 +305,9 @@ discard block |
||
305 | 305 | $subtotal = 0; |
306 | 306 | $cart_details = $this->cart_details; |
307 | 307 | |
308 | - if ( is_array( $cart_details ) ) { |
|
309 | - foreach ( $cart_details as $item ) { |
|
310 | - if ( isset( $item['subtotal'] ) ) { |
|
308 | + if (is_array($cart_details)) { |
|
309 | + foreach ($cart_details as $item) { |
|
310 | + if (isset($item['subtotal'])) { |
|
311 | 311 | $subtotal += $item['subtotal']; |
312 | 312 | } |
313 | 313 | } |
@@ -321,18 +321,18 @@ discard block |
||
321 | 321 | } |
322 | 322 | |
323 | 323 | private function setup_discounts() { |
324 | - $discounts = ! empty( $this->payment_meta['user_info']['discount'] ) ? $this->payment_meta['user_info']['discount'] : array(); |
|
324 | + $discounts = !empty($this->payment_meta['user_info']['discount']) ? $this->payment_meta['user_info']['discount'] : array(); |
|
325 | 325 | return $discounts; |
326 | 326 | } |
327 | 327 | |
328 | 328 | private function setup_total() { |
329 | - $amount = $this->get_meta( '_wpinv_total', true ); |
|
329 | + $amount = $this->get_meta('_wpinv_total', true); |
|
330 | 330 | |
331 | - if ( empty( $amount ) && '0.00' != $amount ) { |
|
332 | - $meta = $this->get_meta( '_wpinv_payment_meta', true ); |
|
333 | - $meta = maybe_unserialize( $meta ); |
|
331 | + if (empty($amount) && '0.00' != $amount) { |
|
332 | + $meta = $this->get_meta('_wpinv_payment_meta', true); |
|
333 | + $meta = maybe_unserialize($meta); |
|
334 | 334 | |
335 | - if ( isset( $meta['amount'] ) ) { |
|
335 | + if (isset($meta['amount'])) { |
|
336 | 336 | $amount = $meta['amount']; |
337 | 337 | } |
338 | 338 | } |
@@ -341,13 +341,13 @@ discard block |
||
341 | 341 | } |
342 | 342 | |
343 | 343 | private function setup_mode() { |
344 | - return $this->get_meta( '_wpinv_mode' ); |
|
344 | + return $this->get_meta('_wpinv_mode'); |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | private function setup_gateway() { |
348 | - $gateway = $this->get_meta( '_wpinv_gateway' ); |
|
348 | + $gateway = $this->get_meta('_wpinv_gateway'); |
|
349 | 349 | |
350 | - if ( empty( $gateway ) && 'publish' === $this->status || 'complete' === $this->status ) { |
|
350 | + if (empty($gateway) && 'publish' === $this->status || 'complete' === $this->status) { |
|
351 | 351 | $gateway = 'manual'; |
352 | 352 | } |
353 | 353 | |
@@ -355,23 +355,23 @@ discard block |
||
355 | 355 | } |
356 | 356 | |
357 | 357 | private function setup_gateway_title() { |
358 | - $gateway_title = wpinv_get_gateway_checkout_label( $this->gateway ); |
|
358 | + $gateway_title = wpinv_get_gateway_checkout_label($this->gateway); |
|
359 | 359 | return $gateway_title; |
360 | 360 | } |
361 | 361 | |
362 | 362 | private function setup_transaction_id() { |
363 | - $transaction_id = $this->get_meta( '_wpinv_transaction_id' ); |
|
363 | + $transaction_id = $this->get_meta('_wpinv_transaction_id'); |
|
364 | 364 | |
365 | - if ( empty( $transaction_id ) || (int) $transaction_id === (int) $this->ID ) { |
|
365 | + if (empty($transaction_id) || (int)$transaction_id === (int)$this->ID) { |
|
366 | 366 | $gateway = $this->gateway; |
367 | - $transaction_id = apply_filters( 'wpinv_get_invoice_transaction_id-' . $gateway, $this->ID ); |
|
367 | + $transaction_id = apply_filters('wpinv_get_invoice_transaction_id-' . $gateway, $this->ID); |
|
368 | 368 | } |
369 | 369 | |
370 | 370 | return $transaction_id; |
371 | 371 | } |
372 | 372 | |
373 | 373 | private function setup_ip() { |
374 | - $ip = $this->get_meta( '_wpinv_user_ip' ); |
|
374 | + $ip = $this->get_meta('_wpinv_user_ip'); |
|
375 | 375 | return $ip; |
376 | 376 | } |
377 | 377 | |
@@ -381,62 +381,62 @@ discard block |
||
381 | 381 | ///} |
382 | 382 | |
383 | 383 | private function setup_first_name() { |
384 | - $first_name = $this->get_meta( '_wpinv_first_name' ); |
|
384 | + $first_name = $this->get_meta('_wpinv_first_name'); |
|
385 | 385 | return $first_name; |
386 | 386 | } |
387 | 387 | |
388 | 388 | private function setup_last_name() { |
389 | - $last_name = $this->get_meta( '_wpinv_last_name' ); |
|
389 | + $last_name = $this->get_meta('_wpinv_last_name'); |
|
390 | 390 | return $last_name; |
391 | 391 | } |
392 | 392 | |
393 | 393 | private function setup_company() { |
394 | - $company = $this->get_meta( '_wpinv_company' ); |
|
394 | + $company = $this->get_meta('_wpinv_company'); |
|
395 | 395 | return $company; |
396 | 396 | } |
397 | 397 | |
398 | 398 | private function setup_vat_number() { |
399 | - $vat_number = $this->get_meta( '_wpinv_vat_number' ); |
|
399 | + $vat_number = $this->get_meta('_wpinv_vat_number'); |
|
400 | 400 | return $vat_number; |
401 | 401 | } |
402 | 402 | |
403 | 403 | private function setup_vat_rate() { |
404 | - $vat_rate = $this->get_meta( '_wpinv_vat_rate' ); |
|
404 | + $vat_rate = $this->get_meta('_wpinv_vat_rate'); |
|
405 | 405 | return $vat_rate; |
406 | 406 | } |
407 | 407 | |
408 | 408 | private function setup_adddress_confirmed() { |
409 | - $adddress_confirmed = $this->get_meta( '_wpinv_adddress_confirmed' ); |
|
409 | + $adddress_confirmed = $this->get_meta('_wpinv_adddress_confirmed'); |
|
410 | 410 | return $adddress_confirmed; |
411 | 411 | } |
412 | 412 | |
413 | 413 | private function setup_phone() { |
414 | - $phone = $this->get_meta( '_wpinv_phone' ); |
|
414 | + $phone = $this->get_meta('_wpinv_phone'); |
|
415 | 415 | return $phone; |
416 | 416 | } |
417 | 417 | |
418 | 418 | private function setup_address() { |
419 | - $address = $this->get_meta( '_wpinv_address', true ); |
|
419 | + $address = $this->get_meta('_wpinv_address', true); |
|
420 | 420 | return $address; |
421 | 421 | } |
422 | 422 | |
423 | 423 | private function setup_city() { |
424 | - $city = $this->get_meta( '_wpinv_city', true ); |
|
424 | + $city = $this->get_meta('_wpinv_city', true); |
|
425 | 425 | return $city; |
426 | 426 | } |
427 | 427 | |
428 | 428 | private function setup_country() { |
429 | - $country = $this->get_meta( '_wpinv_country', true ); |
|
429 | + $country = $this->get_meta('_wpinv_country', true); |
|
430 | 430 | return $country; |
431 | 431 | } |
432 | 432 | |
433 | 433 | private function setup_state() { |
434 | - $state = $this->get_meta( '_wpinv_state', true ); |
|
434 | + $state = $this->get_meta('_wpinv_state', true); |
|
435 | 435 | return $state; |
436 | 436 | } |
437 | 437 | |
438 | 438 | private function setup_zip() { |
439 | - $zip = $this->get_meta( '_wpinv_zip', true ); |
|
439 | + $zip = $this->get_meta('_wpinv_zip', true); |
|
440 | 440 | return $zip; |
441 | 441 | } |
442 | 442 | |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | 'user_id' => $this->user_id, |
446 | 446 | 'first_name' => $this->first_name, |
447 | 447 | 'last_name' => $this->last_name, |
448 | - 'email' => get_the_author_meta( 'email', $this->user_id ), |
|
448 | + 'email' => get_the_author_meta('email', $this->user_id), |
|
449 | 449 | 'phone' => $this->phone, |
450 | 450 | 'address' => $this->address, |
451 | 451 | 'city' => $this->city, |
@@ -460,12 +460,12 @@ discard block |
||
460 | 460 | ); |
461 | 461 | |
462 | 462 | $user_info = array(); |
463 | - if ( isset( $this->payment_meta['user_info'] ) ) { |
|
464 | - $user_info = maybe_unserialize( $this->payment_meta['user_info'] ); |
|
463 | + if (isset($this->payment_meta['user_info'])) { |
|
464 | + $user_info = maybe_unserialize($this->payment_meta['user_info']); |
|
465 | 465 | |
466 | - if ( !empty( $user_info ) && isset( $user_info['user_id'] ) && $post = get_post( $this->ID ) ) { |
|
466 | + if (!empty($user_info) && isset($user_info['user_id']) && $post = get_post($this->ID)) { |
|
467 | 467 | $this->user_id = $post->post_author; |
468 | - $this->email = get_the_author_meta( 'email', $this->user_id ); |
|
468 | + $this->email = get_the_author_meta('email', $this->user_id); |
|
469 | 469 | |
470 | 470 | $user_info['user_id'] = $this->user_id; |
471 | 471 | $user_info['email'] = $this->email; |
@@ -474,13 +474,13 @@ discard block |
||
474 | 474 | } |
475 | 475 | } |
476 | 476 | |
477 | - $user_info = wp_parse_args( $user_info, $defaults ); |
|
477 | + $user_info = wp_parse_args($user_info, $defaults); |
|
478 | 478 | |
479 | 479 | // Get the user, but only if it's been created |
480 | - $user = get_userdata( $this->user_id ); |
|
480 | + $user = get_userdata($this->user_id); |
|
481 | 481 | |
482 | - if ( !empty( $user ) && $user->ID > 0 ) { |
|
483 | - if ( empty( $user_info ) ) { |
|
482 | + if (!empty($user) && $user->ID > 0) { |
|
483 | + if (empty($user_info)) { |
|
484 | 484 | $user_info = array( |
485 | 485 | 'user_id' => $user->ID, |
486 | 486 | 'first_name' => $user->first_name, |
@@ -489,23 +489,23 @@ discard block |
||
489 | 489 | 'discount' => '', |
490 | 490 | ); |
491 | 491 | } else { |
492 | - foreach ( $user_info as $key => $value ) { |
|
493 | - if ( ! empty( $value ) ) { |
|
492 | + foreach ($user_info as $key => $value) { |
|
493 | + if (!empty($value)) { |
|
494 | 494 | continue; |
495 | 495 | } |
496 | 496 | |
497 | - switch( $key ) { |
|
497 | + switch ($key) { |
|
498 | 498 | case 'user_id': |
499 | - $user_info[ $key ] = $user->ID; |
|
499 | + $user_info[$key] = $user->ID; |
|
500 | 500 | break; |
501 | 501 | case 'first_name': |
502 | - $user_info[ $key ] = $user->first_name; |
|
502 | + $user_info[$key] = $user->first_name; |
|
503 | 503 | break; |
504 | 504 | case 'last_name': |
505 | - $user_info[ $key ] = $user->last_name; |
|
505 | + $user_info[$key] = $user->last_name; |
|
506 | 506 | break; |
507 | 507 | case 'email': |
508 | - $user_info[ $key ] = $user->user_email; |
|
508 | + $user_info[$key] = $user->user_email; |
|
509 | 509 | break; |
510 | 510 | } |
511 | 511 | } |
@@ -516,16 +516,16 @@ discard block |
||
516 | 516 | } |
517 | 517 | |
518 | 518 | private function setup_invoice_key() { |
519 | - $key = $this->get_meta( '_wpinv_key', true ); |
|
519 | + $key = $this->get_meta('_wpinv_key', true); |
|
520 | 520 | |
521 | 521 | return $key; |
522 | 522 | } |
523 | 523 | |
524 | 524 | private function setup_invoice_number() { |
525 | - $number = $this->get_meta( '_wpinv_number', true ); |
|
525 | + $number = $this->get_meta('_wpinv_number', true); |
|
526 | 526 | |
527 | - if ( !$number ) { |
|
528 | - $number = wpinv_format_invoice_number( $this->ID ); |
|
527 | + if (!$number) { |
|
528 | + $number = wpinv_format_invoice_number($this->ID); |
|
529 | 529 | } |
530 | 530 | |
531 | 531 | return $number; |
@@ -536,18 +536,18 @@ discard block |
||
536 | 536 | |
537 | 537 | if ($number = $this->get_number()) { |
538 | 538 | $invoice_title = $number; |
539 | - } else if ( ! empty( $this->ID ) ) { |
|
540 | - $invoice_title = wpinv_format_invoice_number( $this->ID ); |
|
539 | + } else if (!empty($this->ID)) { |
|
540 | + $invoice_title = wpinv_format_invoice_number($this->ID); |
|
541 | 541 | } else { |
542 | - $invoice_title = wpinv_format_invoice_number( 0 ); |
|
542 | + $invoice_title = wpinv_format_invoice_number(0); |
|
543 | 543 | } |
544 | 544 | |
545 | - if ( empty( $this->key ) ) { |
|
545 | + if (empty($this->key)) { |
|
546 | 546 | $this->key = self::generate_key(); |
547 | 547 | $this->pending['key'] = $this->key; |
548 | 548 | } |
549 | 549 | |
550 | - if ( empty( $this->ip ) ) { |
|
550 | + if (empty($this->ip)) { |
|
551 | 551 | $this->ip = wpinv_get_ip(); |
552 | 552 | $this->pending['ip'] = $this->ip; |
553 | 553 | } |
@@ -579,75 +579,75 @@ discard block |
||
579 | 579 | 'fees' => $this->fees, |
580 | 580 | ); |
581 | 581 | |
582 | - $post_name = sanitize_title( $invoice_title ); |
|
582 | + $post_name = sanitize_title($invoice_title); |
|
583 | 583 | |
584 | 584 | $post_data = array( |
585 | 585 | 'post_title' => $invoice_title, |
586 | 586 | 'post_status' => $this->status, |
587 | 587 | 'post_author' => $this->user_id, |
588 | 588 | 'post_type' => $this->post_type, |
589 | - 'post_date' => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time( 'mysql' ), |
|
590 | - 'post_date_gmt' => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date( $this->date ) : current_time( 'mysql', 1 ), |
|
589 | + 'post_date' => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time('mysql'), |
|
590 | + 'post_date_gmt' => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date($this->date) : current_time('mysql', 1), |
|
591 | 591 | 'post_parent' => $this->parent_invoice, |
592 | 592 | ); |
593 | - $args = apply_filters( 'wpinv_insert_invoice_args', $post_data, $this ); |
|
593 | + $args = apply_filters('wpinv_insert_invoice_args', $post_data, $this); |
|
594 | 594 | |
595 | 595 | // Create a blank invoice |
596 | - if ( !empty( $this->ID ) ) { |
|
596 | + if (!empty($this->ID)) { |
|
597 | 597 | $args['ID'] = $this->ID; |
598 | 598 | $args['post_name'] = $post_name; |
599 | 599 | |
600 | - $invoice_id = wp_update_post( $args ); |
|
600 | + $invoice_id = wp_update_post($args); |
|
601 | 601 | } else { |
602 | - $invoice_id = wp_insert_post( $args ); |
|
602 | + $invoice_id = wp_insert_post($args); |
|
603 | 603 | |
604 | - $post_title = wpinv_format_invoice_number( $invoice_id ); |
|
604 | + $post_title = wpinv_format_invoice_number($invoice_id); |
|
605 | 605 | global $wpdb; |
606 | - $wpdb->update( $wpdb->posts, array( 'post_title' => $post_title, 'post_name' => sanitize_title( $post_title ) ), array( 'ID' => $invoice_id ) ); |
|
607 | - clean_post_cache( $invoice_id ); |
|
606 | + $wpdb->update($wpdb->posts, array('post_title' => $post_title, 'post_name' => sanitize_title($post_title)), array('ID' => $invoice_id)); |
|
607 | + clean_post_cache($invoice_id); |
|
608 | 608 | } |
609 | 609 | |
610 | - if ( !empty( $invoice_id ) ) { |
|
610 | + if (!empty($invoice_id)) { |
|
611 | 611 | $this->ID = $invoice_id; |
612 | 612 | $this->_ID = $invoice_id; |
613 | 613 | |
614 | 614 | ///$this->pending['user_id'] = $this->user_id; |
615 | - if ( isset( $this->pending['number'] ) ) { |
|
615 | + if (isset($this->pending['number'])) { |
|
616 | 616 | $this->pending['number'] = $post_name; |
617 | 617 | } |
618 | 618 | |
619 | - $this->payment_meta = apply_filters( 'wpinv_payment_meta', $this->payment_meta, $payment_data ); |
|
620 | - if ( ! empty( $this->payment_meta['fees'] ) ) { |
|
621 | - $this->fees = array_merge( $this->fees, $this->payment_meta['fees'] ); |
|
622 | - foreach( $this->fees as $fee ) { |
|
623 | - $this->increase_fees( $fee['amount'] ); |
|
619 | + $this->payment_meta = apply_filters('wpinv_payment_meta', $this->payment_meta, $payment_data); |
|
620 | + if (!empty($this->payment_meta['fees'])) { |
|
621 | + $this->fees = array_merge($this->fees, $this->payment_meta['fees']); |
|
622 | + foreach ($this->fees as $fee) { |
|
623 | + $this->increase_fees($fee['amount']); |
|
624 | 624 | } |
625 | 625 | } |
626 | 626 | |
627 | - $this->update_meta( '_wpinv_payment_meta', $this->payment_meta ); |
|
627 | + $this->update_meta('_wpinv_payment_meta', $this->payment_meta); |
|
628 | 628 | $this->new = true; |
629 | 629 | } |
630 | 630 | |
631 | 631 | return $this->ID; |
632 | 632 | } |
633 | 633 | |
634 | - public function save( $setup = false ) { |
|
634 | + public function save($setup = false) { |
|
635 | 635 | global $wpi_session; |
636 | 636 | |
637 | 637 | $saved = false; |
638 | - if ( empty( $this->items ) ) { |
|
638 | + if (empty($this->items)) { |
|
639 | 639 | return $saved; // Don't save empty invoice. |
640 | 640 | } |
641 | 641 | |
642 | - if ( empty( $this->key ) ) { |
|
642 | + if (empty($this->key)) { |
|
643 | 643 | $this->key = self::generate_key(); |
644 | 644 | $this->pending['key'] = $this->key; |
645 | 645 | } |
646 | 646 | |
647 | - if ( empty( $this->ID ) ) { |
|
647 | + if (empty($this->ID)) { |
|
648 | 648 | $invoice_id = $this->insert_invoice(); |
649 | 649 | |
650 | - if ( false === $invoice_id ) { |
|
650 | + if (false === $invoice_id) { |
|
651 | 651 | $saved = false; |
652 | 652 | } else { |
653 | 653 | $this->ID = $invoice_id; |
@@ -655,27 +655,27 @@ discard block |
||
655 | 655 | } |
656 | 656 | |
657 | 657 | // If we have something pending, let's save it |
658 | - if ( !empty( $this->pending ) ) { |
|
658 | + if (!empty($this->pending)) { |
|
659 | 659 | $total_increase = 0; |
660 | 660 | $total_decrease = 0; |
661 | 661 | |
662 | - foreach ( $this->pending as $key => $value ) { |
|
663 | - switch( $key ) { |
|
662 | + foreach ($this->pending as $key => $value) { |
|
663 | + switch ($key) { |
|
664 | 664 | case 'items': |
665 | 665 | // Update totals for pending items |
666 | - foreach ( $this->pending[ $key ] as $item ) { |
|
667 | - switch( $item['action'] ) { |
|
666 | + foreach ($this->pending[$key] as $item) { |
|
667 | + switch ($item['action']) { |
|
668 | 668 | case 'add': |
669 | 669 | $price = $item['price']; |
670 | 670 | $taxes = $item['tax']; |
671 | 671 | |
672 | - if ( 'publish' === $this->status || 'complete' === $this->status || 'revoked' === $this->status ) { |
|
672 | + if ('publish' === $this->status || 'complete' === $this->status || 'revoked' === $this->status) { |
|
673 | 673 | $total_increase += $price; |
674 | 674 | } |
675 | 675 | break; |
676 | 676 | |
677 | 677 | case 'remove': |
678 | - if ( 'publish' === $this->status || 'complete' === $this->status || 'revoked' === $this->status ) { |
|
678 | + if ('publish' === $this->status || 'complete' === $this->status || 'revoked' === $this->status) { |
|
679 | 679 | $total_decrease += $item['price']; |
680 | 680 | } |
681 | 681 | break; |
@@ -683,16 +683,16 @@ discard block |
||
683 | 683 | } |
684 | 684 | break; |
685 | 685 | case 'fees': |
686 | - if ( 'publish' !== $this->status && 'complete' !== $this->status && 'revoked' !== $this->status ) { |
|
686 | + if ('publish' !== $this->status && 'complete' !== $this->status && 'revoked' !== $this->status) { |
|
687 | 687 | break; |
688 | 688 | } |
689 | 689 | |
690 | - if ( empty( $this->pending[ $key ] ) ) { |
|
690 | + if (empty($this->pending[$key])) { |
|
691 | 691 | break; |
692 | 692 | } |
693 | 693 | |
694 | - foreach ( $this->pending[ $key ] as $fee ) { |
|
695 | - switch( $fee['action'] ) { |
|
694 | + foreach ($this->pending[$key] as $fee) { |
|
695 | + switch ($fee['action']) { |
|
696 | 696 | case 'add': |
697 | 697 | $total_increase += $fee['amount']; |
698 | 698 | break; |
@@ -704,86 +704,86 @@ discard block |
||
704 | 704 | } |
705 | 705 | break; |
706 | 706 | case 'status': |
707 | - $this->update_status( $this->status ); |
|
707 | + $this->update_status($this->status); |
|
708 | 708 | break; |
709 | 709 | case 'gateway': |
710 | - $this->update_meta( '_wpinv_gateway', $this->gateway ); |
|
710 | + $this->update_meta('_wpinv_gateway', $this->gateway); |
|
711 | 711 | break; |
712 | 712 | case 'mode': |
713 | - $this->update_meta( '_wpinv_mode', $this->mode ); |
|
713 | + $this->update_meta('_wpinv_mode', $this->mode); |
|
714 | 714 | break; |
715 | 715 | case 'transaction_id': |
716 | - $this->update_meta( '_wpinv_transaction_id', $this->transaction_id ); |
|
716 | + $this->update_meta('_wpinv_transaction_id', $this->transaction_id); |
|
717 | 717 | break; |
718 | 718 | case 'ip': |
719 | - $this->update_meta( '_wpinv_user_ip', $this->ip ); |
|
719 | + $this->update_meta('_wpinv_user_ip', $this->ip); |
|
720 | 720 | break; |
721 | 721 | ///case 'user_id': |
722 | 722 | ///$this->update_meta( '_wpinv_user_id', $this->user_id ); |
723 | 723 | ///$this->user_info['user_id'] = $this->user_id; |
724 | 724 | ///break; |
725 | 725 | case 'first_name': |
726 | - $this->update_meta( '_wpinv_first_name', $this->first_name ); |
|
726 | + $this->update_meta('_wpinv_first_name', $this->first_name); |
|
727 | 727 | $this->user_info['first_name'] = $this->first_name; |
728 | 728 | break; |
729 | 729 | case 'last_name': |
730 | - $this->update_meta( '_wpinv_last_name', $this->last_name ); |
|
730 | + $this->update_meta('_wpinv_last_name', $this->last_name); |
|
731 | 731 | $this->user_info['last_name'] = $this->last_name; |
732 | 732 | break; |
733 | 733 | case 'phone': |
734 | - $this->update_meta( '_wpinv_phone', $this->phone ); |
|
734 | + $this->update_meta('_wpinv_phone', $this->phone); |
|
735 | 735 | $this->user_info['phone'] = $this->phone; |
736 | 736 | break; |
737 | 737 | case 'address': |
738 | - $this->update_meta( '_wpinv_address', $this->address ); |
|
738 | + $this->update_meta('_wpinv_address', $this->address); |
|
739 | 739 | $this->user_info['address'] = $this->address; |
740 | 740 | break; |
741 | 741 | case 'city': |
742 | - $this->update_meta( '_wpinv_city', $this->city ); |
|
742 | + $this->update_meta('_wpinv_city', $this->city); |
|
743 | 743 | $this->user_info['city'] = $this->city; |
744 | 744 | break; |
745 | 745 | case 'country': |
746 | - $this->update_meta( '_wpinv_country', $this->country ); |
|
746 | + $this->update_meta('_wpinv_country', $this->country); |
|
747 | 747 | $this->user_info['country'] = $this->country; |
748 | 748 | break; |
749 | 749 | case 'state': |
750 | - $this->update_meta( '_wpinv_state', $this->state ); |
|
750 | + $this->update_meta('_wpinv_state', $this->state); |
|
751 | 751 | $this->user_info['state'] = $this->state; |
752 | 752 | break; |
753 | 753 | case 'zip': |
754 | - $this->update_meta( '_wpinv_zip', $this->zip ); |
|
754 | + $this->update_meta('_wpinv_zip', $this->zip); |
|
755 | 755 | $this->user_info['zip'] = $this->zip; |
756 | 756 | break; |
757 | 757 | case 'company': |
758 | - $this->update_meta( '_wpinv_company', $this->company ); |
|
758 | + $this->update_meta('_wpinv_company', $this->company); |
|
759 | 759 | $this->user_info['company'] = $this->company; |
760 | 760 | break; |
761 | 761 | case 'vat_number': |
762 | - $this->update_meta( '_wpinv_vat_number', $this->vat_number ); |
|
762 | + $this->update_meta('_wpinv_vat_number', $this->vat_number); |
|
763 | 763 | $this->user_info['vat_number'] = $this->vat_number; |
764 | 764 | |
765 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
766 | - if ( $this->vat_number && !empty( $vat_info ) && isset( $vat_info['number'] ) && isset( $vat_info['valid'] ) && $vat_info['number'] == $this->vat_number ) { |
|
767 | - $adddress_confirmed = isset( $vat_info['adddress_confirmed'] ) ? $vat_info['adddress_confirmed'] : false; |
|
768 | - $this->update_meta( '_wpinv_adddress_confirmed', (bool)$adddress_confirmed ); |
|
765 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
766 | + if ($this->vat_number && !empty($vat_info) && isset($vat_info['number']) && isset($vat_info['valid']) && $vat_info['number'] == $this->vat_number) { |
|
767 | + $adddress_confirmed = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false; |
|
768 | + $this->update_meta('_wpinv_adddress_confirmed', (bool)$adddress_confirmed); |
|
769 | 769 | $this->user_info['adddress_confirmed'] = (bool)$adddress_confirmed; |
770 | 770 | } |
771 | 771 | |
772 | 772 | break; |
773 | 773 | case 'vat_rate': |
774 | - $this->update_meta( '_wpinv_vat_rate', $this->vat_rate ); |
|
774 | + $this->update_meta('_wpinv_vat_rate', $this->vat_rate); |
|
775 | 775 | $this->user_info['vat_rate'] = $this->vat_rate; |
776 | 776 | break; |
777 | 777 | case 'adddress_confirmed': |
778 | - $this->update_meta( '_wpinv_adddress_confirmed', $this->adddress_confirmed ); |
|
778 | + $this->update_meta('_wpinv_adddress_confirmed', $this->adddress_confirmed); |
|
779 | 779 | $this->user_info['adddress_confirmed'] = $this->adddress_confirmed; |
780 | 780 | break; |
781 | 781 | |
782 | 782 | case 'key': |
783 | - $this->update_meta( '_wpinv_key', $this->key ); |
|
783 | + $this->update_meta('_wpinv_key', $this->key); |
|
784 | 784 | break; |
785 | 785 | case 'number': |
786 | - $this->update_meta( '_wpinv_number', $this->number ); |
|
786 | + $this->update_meta('_wpinv_number', $this->number); |
|
787 | 787 | break; |
788 | 788 | case 'date': |
789 | 789 | $args = array( |
@@ -792,34 +792,34 @@ discard block |
||
792 | 792 | 'edit_date' => true, |
793 | 793 | ); |
794 | 794 | |
795 | - wp_update_post( $args ); |
|
795 | + wp_update_post($args); |
|
796 | 796 | break; |
797 | 797 | case 'due_date': |
798 | - if ( empty( $this->due_date ) ) { |
|
798 | + if (empty($this->due_date)) { |
|
799 | 799 | $this->due_date = 'none'; |
800 | 800 | } |
801 | 801 | |
802 | - $this->update_meta( '_wpinv_due_date', $this->due_date ); |
|
802 | + $this->update_meta('_wpinv_due_date', $this->due_date); |
|
803 | 803 | break; |
804 | 804 | case 'completed_date': |
805 | - $this->update_meta( '_wpinv_completed_date', $this->completed_date ); |
|
805 | + $this->update_meta('_wpinv_completed_date', $this->completed_date); |
|
806 | 806 | break; |
807 | 807 | case 'discounts': |
808 | - if ( ! is_array( $this->discounts ) ) { |
|
809 | - $this->discounts = explode( ',', $this->discounts ); |
|
808 | + if (!is_array($this->discounts)) { |
|
809 | + $this->discounts = explode(',', $this->discounts); |
|
810 | 810 | } |
811 | 811 | |
812 | - $this->user_info['discount'] = implode( ',', $this->discounts ); |
|
812 | + $this->user_info['discount'] = implode(',', $this->discounts); |
|
813 | 813 | break; |
814 | 814 | |
815 | 815 | //case 'tax': |
816 | 816 | //$this->update_meta( '_wpinv_tax', wpinv_format_amount( $this->tax, NULL, true ) ); |
817 | 817 | //break; |
818 | 818 | case 'discount': |
819 | - $this->update_meta( '_wpinv_discount', wpinv_format_amount( $this->discount, NULL, true ) ); |
|
819 | + $this->update_meta('_wpinv_discount', wpinv_format_amount($this->discount, NULL, true)); |
|
820 | 820 | break; |
821 | 821 | case 'discount_code': |
822 | - $this->update_meta( '_wpinv_discount_code', $this->discount_code ); |
|
822 | + $this->update_meta('_wpinv_discount_code', $this->discount_code); |
|
823 | 823 | break; |
824 | 824 | //case 'fees': |
825 | 825 | //$this->update_meta( '_wpinv_fees', $this->fees ); |
@@ -829,19 +829,19 @@ discard block |
||
829 | 829 | 'ID' => $this->ID, |
830 | 830 | 'post_parent' => $this->parent_invoice, |
831 | 831 | ); |
832 | - wp_update_post( $args ); |
|
832 | + wp_update_post($args); |
|
833 | 833 | break; |
834 | 834 | default: |
835 | - do_action( 'wpinv_save', $this, $key ); |
|
835 | + do_action('wpinv_save', $this, $key); |
|
836 | 836 | break; |
837 | 837 | } |
838 | 838 | } |
839 | 839 | |
840 | - $this->update_meta( '_wpinv_subtotal', wpinv_format_amount( $this->subtotal, NULL, true ) ); |
|
841 | - $this->update_meta( '_wpinv_total', wpinv_format_amount( $this->total, NULL, true ) ); |
|
842 | - $this->update_meta( '_wpinv_tax', wpinv_format_amount( $this->tax, NULL, true ) ); |
|
840 | + $this->update_meta('_wpinv_subtotal', wpinv_format_amount($this->subtotal, NULL, true)); |
|
841 | + $this->update_meta('_wpinv_total', wpinv_format_amount($this->total, NULL, true)); |
|
842 | + $this->update_meta('_wpinv_tax', wpinv_format_amount($this->tax, NULL, true)); |
|
843 | 843 | |
844 | - $this->items = array_values( $this->items ); |
|
844 | + $this->items = array_values($this->items); |
|
845 | 845 | |
846 | 846 | $new_meta = array( |
847 | 847 | 'items' => $this->items, |
@@ -852,12 +852,12 @@ discard block |
||
852 | 852 | ); |
853 | 853 | |
854 | 854 | $meta = $this->get_meta(); |
855 | - $merged_meta = array_merge( $meta, $new_meta ); |
|
855 | + $merged_meta = array_merge($meta, $new_meta); |
|
856 | 856 | |
857 | 857 | // Only save the payment meta if it's changed |
858 | - if ( md5( serialize( $meta ) ) !== md5( serialize( $merged_meta) ) ) { |
|
859 | - $updated = $this->update_meta( '_wpinv_payment_meta', $merged_meta ); |
|
860 | - if ( false !== $updated ) { |
|
858 | + if (md5(serialize($meta)) !== md5(serialize($merged_meta))) { |
|
859 | + $updated = $this->update_meta('_wpinv_payment_meta', $merged_meta); |
|
860 | + if (false !== $updated) { |
|
861 | 861 | $saved = true; |
862 | 862 | } |
863 | 863 | } |
@@ -865,15 +865,15 @@ discard block |
||
865 | 865 | $this->pending = array(); |
866 | 866 | $saved = true; |
867 | 867 | } else { |
868 | - $this->update_meta( '_wpinv_subtotal', wpinv_format_amount( $this->subtotal, NULL, true ) ); |
|
869 | - $this->update_meta( '_wpinv_total', wpinv_format_amount( $this->total, NULL, true ) ); |
|
870 | - $this->update_meta( '_wpinv_tax', wpinv_format_amount( $this->tax, NULL, true ) ); |
|
868 | + $this->update_meta('_wpinv_subtotal', wpinv_format_amount($this->subtotal, NULL, true)); |
|
869 | + $this->update_meta('_wpinv_total', wpinv_format_amount($this->total, NULL, true)); |
|
870 | + $this->update_meta('_wpinv_tax', wpinv_format_amount($this->tax, NULL, true)); |
|
871 | 871 | } |
872 | 872 | |
873 | - do_action( 'wpinv_invoice_save', $this, $saved ); |
|
873 | + do_action('wpinv_invoice_save', $this, $saved); |
|
874 | 874 | |
875 | - if ( true === $saved || $setup ) { |
|
876 | - $this->setup_invoice( $this->ID ); |
|
875 | + if (true === $saved || $setup) { |
|
876 | + $this->setup_invoice($this->ID); |
|
877 | 877 | } |
878 | 878 | |
879 | 879 | $this->refresh_item_ids(); |
@@ -881,7 +881,7 @@ discard block |
||
881 | 881 | return $saved; |
882 | 882 | } |
883 | 883 | |
884 | - public function add_fee( $args, $global = true ) { |
|
884 | + public function add_fee($args, $global = true) { |
|
885 | 885 | $default_args = array( |
886 | 886 | 'label' => '', |
887 | 887 | 'amount' => 0, |
@@ -891,75 +891,75 @@ discard block |
||
891 | 891 | 'item_id' => 0, |
892 | 892 | ); |
893 | 893 | |
894 | - $fee = wp_parse_args( $args, $default_args ); |
|
894 | + $fee = wp_parse_args($args, $default_args); |
|
895 | 895 | |
896 | - if ( !empty( $fee['label'] ) ) { |
|
896 | + if (!empty($fee['label'])) { |
|
897 | 897 | return false; |
898 | 898 | } |
899 | 899 | |
900 | - $fee['id'] = sanitize_title( $fee['label'] ); |
|
900 | + $fee['id'] = sanitize_title($fee['label']); |
|
901 | 901 | |
902 | - $this->fees[] = $fee; |
|
902 | + $this->fees[] = $fee; |
|
903 | 903 | |
904 | 904 | $added_fee = $fee; |
905 | 905 | $added_fee['action'] = 'add'; |
906 | 906 | $this->pending['fees'][] = $added_fee; |
907 | - reset( $this->fees ); |
|
907 | + reset($this->fees); |
|
908 | 908 | |
909 | - $this->increase_fees( $fee['amount'] ); |
|
909 | + $this->increase_fees($fee['amount']); |
|
910 | 910 | return true; |
911 | 911 | } |
912 | 912 | |
913 | - public function remove_fee( $key ) { |
|
913 | + public function remove_fee($key) { |
|
914 | 914 | $removed = false; |
915 | 915 | |
916 | - if ( is_numeric( $key ) ) { |
|
917 | - $removed = $this->remove_fee_by( 'index', $key ); |
|
916 | + if (is_numeric($key)) { |
|
917 | + $removed = $this->remove_fee_by('index', $key); |
|
918 | 918 | } |
919 | 919 | |
920 | 920 | return $removed; |
921 | 921 | } |
922 | 922 | |
923 | - public function remove_fee_by( $key, $value, $global = false ) { |
|
924 | - $allowed_fee_keys = apply_filters( 'wpinv_fee_keys', array( |
|
923 | + public function remove_fee_by($key, $value, $global = false) { |
|
924 | + $allowed_fee_keys = apply_filters('wpinv_fee_keys', array( |
|
925 | 925 | 'index', 'label', 'amount', 'type', |
926 | - ) ); |
|
926 | + )); |
|
927 | 927 | |
928 | - if ( ! in_array( $key, $allowed_fee_keys ) ) { |
|
928 | + if (!in_array($key, $allowed_fee_keys)) { |
|
929 | 929 | return false; |
930 | 930 | } |
931 | 931 | |
932 | 932 | $removed = false; |
933 | - if ( 'index' === $key && array_key_exists( $value, $this->fees ) ) { |
|
934 | - $removed_fee = $this->fees[ $value ]; |
|
933 | + if ('index' === $key && array_key_exists($value, $this->fees)) { |
|
934 | + $removed_fee = $this->fees[$value]; |
|
935 | 935 | $removed_fee['action'] = 'remove'; |
936 | 936 | $this->pending['fees'][] = $removed_fee; |
937 | 937 | |
938 | - $this->decrease_fees( $removed_fee['amount'] ); |
|
938 | + $this->decrease_fees($removed_fee['amount']); |
|
939 | 939 | |
940 | - unset( $this->fees[ $value ] ); |
|
940 | + unset($this->fees[$value]); |
|
941 | 941 | $removed = true; |
942 | - } else if ( 'index' !== $key ) { |
|
943 | - foreach ( $this->fees as $index => $fee ) { |
|
944 | - if ( isset( $fee[ $key ] ) && $fee[ $key ] == $value ) { |
|
942 | + } else if ('index' !== $key) { |
|
943 | + foreach ($this->fees as $index => $fee) { |
|
944 | + if (isset($fee[$key]) && $fee[$key] == $value) { |
|
945 | 945 | $removed_fee = $fee; |
946 | 946 | $removed_fee['action'] = 'remove'; |
947 | 947 | $this->pending['fees'][] = $removed_fee; |
948 | 948 | |
949 | - $this->decrease_fees( $removed_fee['amount'] ); |
|
949 | + $this->decrease_fees($removed_fee['amount']); |
|
950 | 950 | |
951 | - unset( $this->fees[ $index ] ); |
|
951 | + unset($this->fees[$index]); |
|
952 | 952 | $removed = true; |
953 | 953 | |
954 | - if ( false === $global ) { |
|
954 | + if (false === $global) { |
|
955 | 955 | break; |
956 | 956 | } |
957 | 957 | } |
958 | 958 | } |
959 | 959 | } |
960 | 960 | |
961 | - if ( true === $removed ) { |
|
962 | - $this->fees = array_values( $this->fees ); |
|
961 | + if (true === $removed) { |
|
962 | + $this->fees = array_values($this->fees); |
|
963 | 963 | } |
964 | 964 | |
965 | 965 | return $removed; |
@@ -967,35 +967,35 @@ discard block |
||
967 | 967 | |
968 | 968 | |
969 | 969 | |
970 | - public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) { |
|
970 | + public function add_note($note = '', $customer_type = false, $added_by_user = false, $system = false) { |
|
971 | 971 | // Bail if no note specified |
972 | - if( !$note ) { |
|
972 | + if (!$note) { |
|
973 | 973 | return false; |
974 | 974 | } |
975 | 975 | |
976 | - if ( empty( $this->ID ) ) |
|
976 | + if (empty($this->ID)) |
|
977 | 977 | return false; |
978 | 978 | |
979 | - if ( ( ( is_user_logged_in() && current_user_can( 'manage_options' ) ) || $added_by_user ) && !$system ) { |
|
980 | - $user = get_user_by( 'id', get_current_user_id() ); |
|
979 | + if (((is_user_logged_in() && current_user_can('manage_options')) || $added_by_user) && !$system) { |
|
980 | + $user = get_user_by('id', get_current_user_id()); |
|
981 | 981 | $comment_author = $user->display_name; |
982 | 982 | $comment_author_email = $user->user_email; |
983 | 983 | } else { |
984 | - $comment_author = __( 'System', 'invoicing' ); |
|
985 | - $comment_author_email = strtolower( __( 'System', 'invoicing' ) ) . '@'; |
|
986 | - $comment_author_email .= isset( $_SERVER['HTTP_HOST'] ) ? str_replace( 'www.', '', $_SERVER['HTTP_HOST'] ) : 'noreply.com'; |
|
987 | - $comment_author_email = sanitize_email( $comment_author_email ); |
|
984 | + $comment_author = __('System', 'invoicing'); |
|
985 | + $comment_author_email = strtolower(__('System', 'invoicing')) . '@'; |
|
986 | + $comment_author_email .= isset($_SERVER['HTTP_HOST']) ? str_replace('www.', '', $_SERVER['HTTP_HOST']) : 'noreply.com'; |
|
987 | + $comment_author_email = sanitize_email($comment_author_email); |
|
988 | 988 | } |
989 | 989 | |
990 | - do_action( 'wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type ); |
|
990 | + do_action('wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type); |
|
991 | 991 | |
992 | - $note_id = wp_insert_comment( wp_filter_comment( array( |
|
992 | + $note_id = wp_insert_comment(wp_filter_comment(array( |
|
993 | 993 | 'comment_post_ID' => $this->ID, |
994 | 994 | 'comment_content' => $note, |
995 | 995 | 'comment_agent' => 'GeoDirectory', |
996 | 996 | 'user_id' => is_admin() ? get_current_user_id() : 0, |
997 | - 'comment_date' => current_time( 'mysql' ), |
|
998 | - 'comment_date_gmt' => current_time( 'mysql', 1 ), |
|
997 | + 'comment_date' => current_time('mysql'), |
|
998 | + 'comment_date_gmt' => current_time('mysql', 1), |
|
999 | 999 | 'comment_approved' => 1, |
1000 | 1000 | 'comment_parent' => 0, |
1001 | 1001 | 'comment_author' => $comment_author, |
@@ -1003,53 +1003,53 @@ discard block |
||
1003 | 1003 | 'comment_author_url' => '', |
1004 | 1004 | 'comment_author_email' => $comment_author_email, |
1005 | 1005 | 'comment_type' => 'wpinv_note' |
1006 | - ) ) ); |
|
1006 | + ))); |
|
1007 | 1007 | |
1008 | - do_action( 'wpinv_insert_payment_note', $note_id, $this->ID, $note ); |
|
1008 | + do_action('wpinv_insert_payment_note', $note_id, $this->ID, $note); |
|
1009 | 1009 | |
1010 | - if ( $customer_type ) { |
|
1011 | - add_comment_meta( $note_id, '_wpi_customer_note', 1 ); |
|
1010 | + if ($customer_type) { |
|
1011 | + add_comment_meta($note_id, '_wpi_customer_note', 1); |
|
1012 | 1012 | |
1013 | - do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $this->ID, 'user_note' => $note ) ); |
|
1013 | + do_action('wpinv_new_customer_note', array('invoice_id' => $this->ID, 'user_note' => $note)); |
|
1014 | 1014 | } |
1015 | 1015 | |
1016 | 1016 | return $note_id; |
1017 | 1017 | } |
1018 | 1018 | |
1019 | - private function increase_subtotal( $amount = 0.00 ) { |
|
1020 | - $amount = (float) $amount; |
|
1019 | + private function increase_subtotal($amount = 0.00) { |
|
1020 | + $amount = (float)$amount; |
|
1021 | 1021 | $this->subtotal += $amount; |
1022 | - $this->subtotal = wpinv_format_amount( $this->subtotal, NULL, true ); |
|
1022 | + $this->subtotal = wpinv_format_amount($this->subtotal, NULL, true); |
|
1023 | 1023 | |
1024 | 1024 | $this->recalculate_total(); |
1025 | 1025 | } |
1026 | 1026 | |
1027 | - private function decrease_subtotal( $amount = 0.00 ) { |
|
1028 | - $amount = (float) $amount; |
|
1027 | + private function decrease_subtotal($amount = 0.00) { |
|
1028 | + $amount = (float)$amount; |
|
1029 | 1029 | $this->subtotal -= $amount; |
1030 | - $this->subtotal = wpinv_format_amount( $this->subtotal, NULL, true ); |
|
1030 | + $this->subtotal = wpinv_format_amount($this->subtotal, NULL, true); |
|
1031 | 1031 | |
1032 | - if ( $this->subtotal < 0 ) { |
|
1032 | + if ($this->subtotal < 0) { |
|
1033 | 1033 | $this->subtotal = 0; |
1034 | 1034 | } |
1035 | 1035 | |
1036 | 1036 | $this->recalculate_total(); |
1037 | 1037 | } |
1038 | 1038 | |
1039 | - private function increase_fees( $amount = 0.00 ) { |
|
1039 | + private function increase_fees($amount = 0.00) { |
|
1040 | 1040 | $amount = (float)$amount; |
1041 | 1041 | $this->fees_total += $amount; |
1042 | - $this->fees_total = wpinv_format_amount( $this->fees_total, NULL, true ); |
|
1042 | + $this->fees_total = wpinv_format_amount($this->fees_total, NULL, true); |
|
1043 | 1043 | |
1044 | 1044 | $this->recalculate_total(); |
1045 | 1045 | } |
1046 | 1046 | |
1047 | - private function decrease_fees( $amount = 0.00 ) { |
|
1048 | - $amount = (float) $amount; |
|
1047 | + private function decrease_fees($amount = 0.00) { |
|
1048 | + $amount = (float)$amount; |
|
1049 | 1049 | $this->fees_total -= $amount; |
1050 | - $this->fees_total = wpinv_format_amount( $this->fees_total, NULL, true ); |
|
1050 | + $this->fees_total = wpinv_format_amount($this->fees_total, NULL, true); |
|
1051 | 1051 | |
1052 | - if ( $this->fees_total < 0 ) { |
|
1052 | + if ($this->fees_total < 0) { |
|
1053 | 1053 | $this->fees_total = 0; |
1054 | 1054 | } |
1055 | 1055 | |
@@ -1060,54 +1060,54 @@ discard block |
||
1060 | 1060 | global $wpi_nosave; |
1061 | 1061 | |
1062 | 1062 | $this->total = $this->subtotal + $this->tax + $this->fees_total; |
1063 | - $this->total = wpinv_format_amount( $this->total, NULL, true ); |
|
1063 | + $this->total = wpinv_format_amount($this->total, NULL, true); |
|
1064 | 1064 | |
1065 | - do_action( 'wpinv_invoice_recalculate_total', $this, $wpi_nosave ); |
|
1065 | + do_action('wpinv_invoice_recalculate_total', $this, $wpi_nosave); |
|
1066 | 1066 | } |
1067 | 1067 | |
1068 | - public function increase_tax( $amount = 0.00 ) { |
|
1069 | - $amount = (float) $amount; |
|
1068 | + public function increase_tax($amount = 0.00) { |
|
1069 | + $amount = (float)$amount; |
|
1070 | 1070 | $this->tax += $amount; |
1071 | 1071 | |
1072 | 1072 | $this->recalculate_total(); |
1073 | 1073 | } |
1074 | 1074 | |
1075 | - public function decrease_tax( $amount = 0.00 ) { |
|
1076 | - $amount = (float) $amount; |
|
1075 | + public function decrease_tax($amount = 0.00) { |
|
1076 | + $amount = (float)$amount; |
|
1077 | 1077 | $this->tax -= $amount; |
1078 | 1078 | |
1079 | - if ( $this->tax < 0 ) { |
|
1079 | + if ($this->tax < 0) { |
|
1080 | 1080 | $this->tax = 0; |
1081 | 1081 | } |
1082 | 1082 | |
1083 | 1083 | $this->recalculate_total(); |
1084 | 1084 | } |
1085 | 1085 | |
1086 | - public function update_status( $new_status = false, $note = '', $manual = false ) { |
|
1087 | - $old_status = ! empty( $this->old_status ) ? $this->old_status : get_post_status( $this->ID ); |
|
1086 | + public function update_status($new_status = false, $note = '', $manual = false) { |
|
1087 | + $old_status = !empty($this->old_status) ? $this->old_status : get_post_status($this->ID); |
|
1088 | 1088 | |
1089 | - if ( $old_status === $new_status && in_array( $new_status, array_keys( wpinv_get_invoice_statuses() ) ) ) { |
|
1089 | + if ($old_status === $new_status && in_array($new_status, array_keys(wpinv_get_invoice_statuses()))) { |
|
1090 | 1090 | return false; // Don't permit status changes that aren't changes |
1091 | 1091 | } |
1092 | 1092 | |
1093 | - $do_change = apply_filters( 'wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status ); |
|
1093 | + $do_change = apply_filters('wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status); |
|
1094 | 1094 | $updated = false; |
1095 | 1095 | |
1096 | - if ( $do_change ) { |
|
1097 | - do_action( 'wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status ); |
|
1096 | + if ($do_change) { |
|
1097 | + do_action('wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status); |
|
1098 | 1098 | |
1099 | 1099 | $update_post_data = array(); |
1100 | 1100 | $update_post_data['ID'] = $this->ID; |
1101 | 1101 | $update_post_data['post_status'] = $new_status; |
1102 | - $update_post_data['edit_date'] = current_time( 'mysql', 0 ); |
|
1103 | - $update_post_data['edit_date_gmt'] = current_time( 'mysql', 1 ); |
|
1102 | + $update_post_data['edit_date'] = current_time('mysql', 0); |
|
1103 | + $update_post_data['edit_date_gmt'] = current_time('mysql', 1); |
|
1104 | 1104 | |
1105 | - $update_post_data = apply_filters( 'wpinv_update_invoice_status_fields', $update_post_data, $this->ID ); |
|
1105 | + $update_post_data = apply_filters('wpinv_update_invoice_status_fields', $update_post_data, $this->ID); |
|
1106 | 1106 | |
1107 | - $updated = wp_update_post( $update_post_data ); |
|
1107 | + $updated = wp_update_post($update_post_data); |
|
1108 | 1108 | |
1109 | 1109 | // Process any specific status functions |
1110 | - switch( $new_status ) { |
|
1110 | + switch ($new_status) { |
|
1111 | 1111 | case 'refunded': |
1112 | 1112 | $this->process_refund(); |
1113 | 1113 | break; |
@@ -1120,9 +1120,9 @@ discard block |
||
1120 | 1120 | } |
1121 | 1121 | |
1122 | 1122 | // Status was changed. |
1123 | - do_action( 'wpinv_status_' . $new_status, $this->ID, $old_status ); |
|
1124 | - do_action( 'wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status ); |
|
1125 | - do_action( 'wpinv_update_status', $this->ID, $new_status, $old_status ); |
|
1123 | + do_action('wpinv_status_' . $new_status, $this->ID, $old_status); |
|
1124 | + do_action('wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status); |
|
1125 | + do_action('wpinv_update_status', $this->ID, $new_status, $old_status); |
|
1126 | 1126 | } |
1127 | 1127 | |
1128 | 1128 | return $updated; |
@@ -1136,72 +1136,72 @@ discard block |
||
1136 | 1136 | $this->save(); |
1137 | 1137 | } |
1138 | 1138 | |
1139 | - public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) { |
|
1140 | - if ( empty( $meta_key ) ) { |
|
1139 | + public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') { |
|
1140 | + if (empty($meta_key)) { |
|
1141 | 1141 | return false; |
1142 | 1142 | } |
1143 | 1143 | |
1144 | - if ( $meta_key == 'key' || $meta_key == 'date' ) { |
|
1144 | + if ($meta_key == 'key' || $meta_key == 'date') { |
|
1145 | 1145 | $current_meta = $this->get_meta(); |
1146 | - $current_meta[ $meta_key ] = $meta_value; |
|
1146 | + $current_meta[$meta_key] = $meta_value; |
|
1147 | 1147 | |
1148 | 1148 | $meta_key = '_wpinv_payment_meta'; |
1149 | 1149 | $meta_value = $current_meta; |
1150 | 1150 | } |
1151 | 1151 | |
1152 | - $meta_value = apply_filters( 'wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID ); |
|
1152 | + $meta_value = apply_filters('wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID); |
|
1153 | 1153 | |
1154 | - if ( $meta_key == '_wpinv_completed_date' && !empty( $meta_value ) ) { |
|
1154 | + if ($meta_key == '_wpinv_completed_date' && !empty($meta_value)) { |
|
1155 | 1155 | $args = array( |
1156 | 1156 | 'ID' => $this->ID, |
1157 | 1157 | 'post_date' => $meta_value, |
1158 | 1158 | 'edit_date' => true, |
1159 | - 'post_date_gmt' => get_gmt_from_date( $meta_value ), |
|
1159 | + 'post_date_gmt' => get_gmt_from_date($meta_value), |
|
1160 | 1160 | 'post_modified' => $meta_value, |
1161 | - 'post_modified_gmt' => get_gmt_from_date( $meta_value ) |
|
1161 | + 'post_modified_gmt' => get_gmt_from_date($meta_value) |
|
1162 | 1162 | ); |
1163 | - wp_update_post( $args ); |
|
1163 | + wp_update_post($args); |
|
1164 | 1164 | } |
1165 | 1165 | |
1166 | - return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value ); |
|
1166 | + return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value); |
|
1167 | 1167 | } |
1168 | 1168 | |
1169 | 1169 | private function process_refund() { |
1170 | 1170 | $process_refund = true; |
1171 | 1171 | |
1172 | 1172 | // If the payment was not in publish or revoked status, don't decrement stats as they were never incremented |
1173 | - if ( ( 'publish' != $this->old_status && 'revoked' != $this->old_status ) || 'refunded' != $this->status ) { |
|
1173 | + if (('publish' != $this->old_status && 'revoked' != $this->old_status) || 'refunded' != $this->status) { |
|
1174 | 1174 | $process_refund = false; |
1175 | 1175 | } |
1176 | 1176 | |
1177 | 1177 | // Allow extensions to filter for their own payment types, Example: Recurring Payments |
1178 | - $process_refund = apply_filters( 'wpinv_should_process_refund', $process_refund, $this ); |
|
1178 | + $process_refund = apply_filters('wpinv_should_process_refund', $process_refund, $this); |
|
1179 | 1179 | |
1180 | - if ( false === $process_refund ) { |
|
1180 | + if (false === $process_refund) { |
|
1181 | 1181 | return; |
1182 | 1182 | } |
1183 | 1183 | |
1184 | - do_action( 'wpinv_pre_refund_invoice', $this ); |
|
1184 | + do_action('wpinv_pre_refund_invoice', $this); |
|
1185 | 1185 | |
1186 | - $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_refund', true, $this ); |
|
1187 | - $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_refund', true, $this ); |
|
1188 | - $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_refund', true, $this ); |
|
1186 | + $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_refund', true, $this); |
|
1187 | + $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_refund', true, $this); |
|
1188 | + $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_refund', true, $this); |
|
1189 | 1189 | |
1190 | - do_action( 'wpinv_post_refund_invoice', $this ); |
|
1190 | + do_action('wpinv_post_refund_invoice', $this); |
|
1191 | 1191 | } |
1192 | 1192 | |
1193 | 1193 | private function process_failure() { |
1194 | 1194 | $discounts = $this->discounts; |
1195 | - if ( empty( $discounts ) ) { |
|
1195 | + if (empty($discounts)) { |
|
1196 | 1196 | return; |
1197 | 1197 | } |
1198 | 1198 | |
1199 | - if ( ! is_array( $discounts ) ) { |
|
1200 | - $discounts = array_map( 'trim', explode( ',', $discounts ) ); |
|
1199 | + if (!is_array($discounts)) { |
|
1200 | + $discounts = array_map('trim', explode(',', $discounts)); |
|
1201 | 1201 | } |
1202 | 1202 | |
1203 | - foreach ( $discounts as $discount ) { |
|
1204 | - wpinv_decrease_discount_usage( $discount ); |
|
1203 | + foreach ($discounts as $discount) { |
|
1204 | + wpinv_decrease_discount_usage($discount); |
|
1205 | 1205 | } |
1206 | 1206 | } |
1207 | 1207 | |
@@ -1209,92 +1209,92 @@ discard block |
||
1209 | 1209 | $process_pending = true; |
1210 | 1210 | |
1211 | 1211 | // If the payment was not in publish or revoked status, don't decrement stats as they were never incremented |
1212 | - if ( ( 'publish' != $this->old_status && 'revoked' != $this->old_status ) || 'pending' != $this->status ) { |
|
1212 | + if (('publish' != $this->old_status && 'revoked' != $this->old_status) || 'pending' != $this->status) { |
|
1213 | 1213 | $process_pending = false; |
1214 | 1214 | } |
1215 | 1215 | |
1216 | 1216 | // Allow extensions to filter for their own payment types, Example: Recurring Payments |
1217 | - $process_pending = apply_filters( 'wpinv_should_process_pending', $process_pending, $this ); |
|
1217 | + $process_pending = apply_filters('wpinv_should_process_pending', $process_pending, $this); |
|
1218 | 1218 | |
1219 | - if ( false === $process_pending ) { |
|
1219 | + if (false === $process_pending) { |
|
1220 | 1220 | return; |
1221 | 1221 | } |
1222 | 1222 | |
1223 | - $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_pending', true, $this ); |
|
1224 | - $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_pending', true, $this ); |
|
1225 | - $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_pending', true, $this ); |
|
1223 | + $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_pending', true, $this); |
|
1224 | + $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_pending', true, $this); |
|
1225 | + $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_pending', true, $this); |
|
1226 | 1226 | |
1227 | 1227 | $this->completed_date = ''; |
1228 | - $this->update_meta( '_wpinv_completed_date', '' ); |
|
1228 | + $this->update_meta('_wpinv_completed_date', ''); |
|
1229 | 1229 | } |
1230 | 1230 | |
1231 | 1231 | // get data |
1232 | - public function get_meta( $meta_key = '_wpinv_payment_meta', $single = true ) { |
|
1233 | - $meta = get_post_meta( $this->ID, $meta_key, $single ); |
|
1232 | + public function get_meta($meta_key = '_wpinv_payment_meta', $single = true) { |
|
1233 | + $meta = get_post_meta($this->ID, $meta_key, $single); |
|
1234 | 1234 | |
1235 | - if ( $meta_key === '_wpinv_payment_meta' ) { |
|
1235 | + if ($meta_key === '_wpinv_payment_meta') { |
|
1236 | 1236 | |
1237 | - if(!is_array($meta)){$meta = array();} // we need this to be an array so make sure it is. |
|
1237 | + if (!is_array($meta)) {$meta = array(); } // we need this to be an array so make sure it is. |
|
1238 | 1238 | |
1239 | - if ( empty( $meta['key'] ) ) { |
|
1239 | + if (empty($meta['key'])) { |
|
1240 | 1240 | $meta['key'] = $this->setup_invoice_key(); |
1241 | 1241 | } |
1242 | 1242 | |
1243 | - if ( empty( $meta['date'] ) ) { |
|
1244 | - $meta['date'] = get_post_field( 'post_date', $this->ID ); |
|
1243 | + if (empty($meta['date'])) { |
|
1244 | + $meta['date'] = get_post_field('post_date', $this->ID); |
|
1245 | 1245 | } |
1246 | 1246 | } |
1247 | 1247 | |
1248 | - $meta = apply_filters( 'wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID ); |
|
1248 | + $meta = apply_filters('wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID); |
|
1249 | 1249 | |
1250 | - return apply_filters( 'wpinv_get_invoice_meta', $meta, $this->ID, $meta_key ); |
|
1250 | + return apply_filters('wpinv_get_invoice_meta', $meta, $this->ID, $meta_key); |
|
1251 | 1251 | } |
1252 | 1252 | |
1253 | 1253 | public function get_description() { |
1254 | - $post = get_post( $this->ID ); |
|
1254 | + $post = get_post($this->ID); |
|
1255 | 1255 | |
1256 | - $description = !empty( $post ) ? $post->post_content : ''; |
|
1257 | - return apply_filters( 'wpinv_get_description', $description, $this->ID, $this ); |
|
1256 | + $description = !empty($post) ? $post->post_content : ''; |
|
1257 | + return apply_filters('wpinv_get_description', $description, $this->ID, $this); |
|
1258 | 1258 | } |
1259 | 1259 | |
1260 | - public function get_status( $nicename = false ) { |
|
1261 | - if ( !$nicename ) { |
|
1260 | + public function get_status($nicename = false) { |
|
1261 | + if (!$nicename) { |
|
1262 | 1262 | $status = $this->status; |
1263 | 1263 | } else { |
1264 | 1264 | $status = $this->status_nicename; |
1265 | 1265 | } |
1266 | 1266 | |
1267 | - return apply_filters( 'wpinv_get_status', $status, $nicename, $this->ID, $this ); |
|
1267 | + return apply_filters('wpinv_get_status', $status, $nicename, $this->ID, $this); |
|
1268 | 1268 | } |
1269 | 1269 | |
1270 | 1270 | public function get_cart_details() { |
1271 | - return apply_filters( 'wpinv_cart_details', $this->cart_details, $this->ID, $this ); |
|
1271 | + return apply_filters('wpinv_cart_details', $this->cart_details, $this->ID, $this); |
|
1272 | 1272 | } |
1273 | 1273 | |
1274 | - public function get_subtotal( $currency = false ) { |
|
1275 | - $subtotal = wpinv_format_amount( $this->subtotal, NULL, !$currency ); |
|
1274 | + public function get_subtotal($currency = false) { |
|
1275 | + $subtotal = wpinv_format_amount($this->subtotal, NULL, !$currency); |
|
1276 | 1276 | |
1277 | - if ( $currency ) { |
|
1278 | - $subtotal = wpinv_price( $subtotal, $this->get_currency() ); |
|
1277 | + if ($currency) { |
|
1278 | + $subtotal = wpinv_price($subtotal, $this->get_currency()); |
|
1279 | 1279 | } |
1280 | 1280 | |
1281 | - return apply_filters( 'wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency ); |
|
1281 | + return apply_filters('wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency); |
|
1282 | 1282 | } |
1283 | 1283 | |
1284 | - public function get_total( $currency = false ) { |
|
1285 | - if ( $this->is_free_trial() ) { |
|
1286 | - $total = wpinv_format_amount( 0, NULL, !$currency ); |
|
1284 | + public function get_total($currency = false) { |
|
1285 | + if ($this->is_free_trial()) { |
|
1286 | + $total = wpinv_format_amount(0, NULL, !$currency); |
|
1287 | 1287 | } else { |
1288 | - $total = wpinv_format_amount( $this->total, NULL, !$currency ); |
|
1288 | + $total = wpinv_format_amount($this->total, NULL, !$currency); |
|
1289 | 1289 | } |
1290 | - if ( $currency ) { |
|
1291 | - $total = wpinv_price( $total, $this->get_currency() ); |
|
1290 | + if ($currency) { |
|
1291 | + $total = wpinv_price($total, $this->get_currency()); |
|
1292 | 1292 | } |
1293 | 1293 | |
1294 | - return apply_filters( 'wpinv_get_invoice_total', $total, $this->ID, $this, $currency ); |
|
1294 | + return apply_filters('wpinv_get_invoice_total', $total, $this->ID, $this, $currency); |
|
1295 | 1295 | } |
1296 | 1296 | |
1297 | - public function get_recurring_details( $field = '', $currency = false ) { |
|
1297 | + public function get_recurring_details($field = '', $currency = false) { |
|
1298 | 1298 | $data = array(); |
1299 | 1299 | $data['cart_details'] = $this->cart_details; |
1300 | 1300 | $data['subtotal'] = $this->get_subtotal(); |
@@ -1302,45 +1302,45 @@ discard block |
||
1302 | 1302 | $data['tax'] = $this->get_tax(); |
1303 | 1303 | $data['total'] = $this->get_total(); |
1304 | 1304 | |
1305 | - if ( !empty( $this->cart_details ) && ( $this->is_parent() || $this->is_renewal() ) ) { |
|
1305 | + if (!empty($this->cart_details) && ($this->is_parent() || $this->is_renewal())) { |
|
1306 | 1306 | $is_free_trial = $this->is_free_trial(); |
1307 | - $discounts = $this->get_discounts( true ); |
|
1307 | + $discounts = $this->get_discounts(true); |
|
1308 | 1308 | |
1309 | - if ( $is_free_trial || !empty( $discounts ) ) { |
|
1309 | + if ($is_free_trial || !empty($discounts)) { |
|
1310 | 1310 | $first_use_only = false; |
1311 | 1311 | |
1312 | - if ( !empty( $discounts ) ) { |
|
1313 | - foreach ( $discounts as $key => $code ) { |
|
1314 | - if ( wpinv_discount_is_recurring( $code, true ) ) { |
|
1312 | + if (!empty($discounts)) { |
|
1313 | + foreach ($discounts as $key => $code) { |
|
1314 | + if (wpinv_discount_is_recurring($code, true)) { |
|
1315 | 1315 | $first_use_only = true; |
1316 | 1316 | break; |
1317 | 1317 | } |
1318 | 1318 | } |
1319 | 1319 | } |
1320 | 1320 | |
1321 | - if ( !$first_use_only ) { |
|
1322 | - $data['subtotal'] = wpinv_format_amount( $this->subtotal, NULL, true ); |
|
1323 | - $data['discount'] = wpinv_format_amount( $this->discount, NULL, true ); |
|
1324 | - $data['tax'] = wpinv_format_amount( $this->tax, NULL, true ); |
|
1325 | - $data['total'] = wpinv_format_amount( $this->total, NULL, true ); |
|
1321 | + if (!$first_use_only) { |
|
1322 | + $data['subtotal'] = wpinv_format_amount($this->subtotal, NULL, true); |
|
1323 | + $data['discount'] = wpinv_format_amount($this->discount, NULL, true); |
|
1324 | + $data['tax'] = wpinv_format_amount($this->tax, NULL, true); |
|
1325 | + $data['total'] = wpinv_format_amount($this->total, NULL, true); |
|
1326 | 1326 | } else { |
1327 | 1327 | $cart_subtotal = 0; |
1328 | 1328 | $cart_discount = 0; |
1329 | 1329 | $cart_tax = 0; |
1330 | 1330 | |
1331 | - foreach ( $this->cart_details as $key => $item ) { |
|
1332 | - $item_quantity = $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1; |
|
1333 | - $item_subtotal = !empty( $item['subtotal'] ) ? $item['subtotal'] : $item['item_price'] * $item_quantity; |
|
1331 | + foreach ($this->cart_details as $key => $item) { |
|
1332 | + $item_quantity = $item['quantity'] > 0 ? absint($item['quantity']) : 1; |
|
1333 | + $item_subtotal = !empty($item['subtotal']) ? $item['subtotal'] : $item['item_price'] * $item_quantity; |
|
1334 | 1334 | $item_discount = 0; |
1335 | - $item_tax = $item_subtotal > 0 && !empty( $item['vat_rate'] ) ? ( $item_subtotal * 0.01 * (float)$item['vat_rate'] ) : 0; |
|
1335 | + $item_tax = $item_subtotal > 0 && !empty($item['vat_rate']) ? ($item_subtotal * 0.01 * (float)$item['vat_rate']) : 0; |
|
1336 | 1336 | |
1337 | - if ( wpinv_prices_include_tax() ) { |
|
1338 | - $item_subtotal -= wpinv_format_amount( $item_tax, NULL, true ); |
|
1337 | + if (wpinv_prices_include_tax()) { |
|
1338 | + $item_subtotal -= wpinv_format_amount($item_tax, NULL, true); |
|
1339 | 1339 | } |
1340 | 1340 | |
1341 | 1341 | $item_total = $item_subtotal - $item_discount + $item_tax; |
1342 | 1342 | // Do not allow totals to go negative |
1343 | - if ( $item_total < 0 ) { |
|
1343 | + if ($item_total < 0) { |
|
1344 | 1344 | $item_total = 0; |
1345 | 1345 | } |
1346 | 1346 | |
@@ -1348,107 +1348,107 @@ discard block |
||
1348 | 1348 | $cart_discount += (float)($item_discount); |
1349 | 1349 | $cart_tax += (float)($item_tax); |
1350 | 1350 | |
1351 | - $data['cart_details'][$key]['discount'] = wpinv_format_amount( $item_discount, NULL, true ); |
|
1352 | - $data['cart_details'][$key]['tax'] = wpinv_format_amount( $item_tax, NULL, true ); |
|
1353 | - $data['cart_details'][$key]['price'] = wpinv_format_amount( $item_total, NULL, true ); |
|
1351 | + $data['cart_details'][$key]['discount'] = wpinv_format_amount($item_discount, NULL, true); |
|
1352 | + $data['cart_details'][$key]['tax'] = wpinv_format_amount($item_tax, NULL, true); |
|
1353 | + $data['cart_details'][$key]['price'] = wpinv_format_amount($item_total, NULL, true); |
|
1354 | 1354 | } |
1355 | 1355 | |
1356 | - $data['subtotal'] = wpinv_format_amount( $cart_subtotal, NULL, true ); |
|
1357 | - $data['discount'] = wpinv_format_amount( $cart_discount, NULL, true ); |
|
1358 | - $data['tax'] = wpinv_format_amount( $cart_tax, NULL, true ); |
|
1359 | - $data['total'] = wpinv_format_amount( ( $data['subtotal'] + $data['tax'] ), NULL, true ); |
|
1356 | + $data['subtotal'] = wpinv_format_amount($cart_subtotal, NULL, true); |
|
1357 | + $data['discount'] = wpinv_format_amount($cart_discount, NULL, true); |
|
1358 | + $data['tax'] = wpinv_format_amount($cart_tax, NULL, true); |
|
1359 | + $data['total'] = wpinv_format_amount(($data['subtotal'] + $data['tax']), NULL, true); |
|
1360 | 1360 | } |
1361 | 1361 | } |
1362 | 1362 | } |
1363 | 1363 | |
1364 | - $data = apply_filters( 'wpinv_get_invoice_recurring_details', $data, $this, $field, $currency ); |
|
1364 | + $data = apply_filters('wpinv_get_invoice_recurring_details', $data, $this, $field, $currency); |
|
1365 | 1365 | |
1366 | - if ( isset( $data[$field] ) ) { |
|
1367 | - return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] ); |
|
1366 | + if (isset($data[$field])) { |
|
1367 | + return ($currency ? wpinv_price($data[$field], $this->get_currency()) : $data[$field]); |
|
1368 | 1368 | } |
1369 | 1369 | |
1370 | 1370 | return $data; |
1371 | 1371 | } |
1372 | 1372 | |
1373 | - public function get_final_tax( $currency = false ) { |
|
1374 | - $final_total = wpinv_format_amount( $this->tax, NULL, !$currency ); |
|
1375 | - if ( $currency ) { |
|
1376 | - $final_total = wpinv_price( $final_total, $this->get_currency() ); |
|
1373 | + public function get_final_tax($currency = false) { |
|
1374 | + $final_total = wpinv_format_amount($this->tax, NULL, !$currency); |
|
1375 | + if ($currency) { |
|
1376 | + $final_total = wpinv_price($final_total, $this->get_currency()); |
|
1377 | 1377 | } |
1378 | 1378 | |
1379 | - return apply_filters( 'wpinv_get_invoice_final_total', $final_total, $this, $currency ); |
|
1379 | + return apply_filters('wpinv_get_invoice_final_total', $final_total, $this, $currency); |
|
1380 | 1380 | } |
1381 | 1381 | |
1382 | - public function get_discounts( $array = false ) { |
|
1382 | + public function get_discounts($array = false) { |
|
1383 | 1383 | $discounts = $this->discounts; |
1384 | - if ( $array && $discounts ) { |
|
1385 | - $discounts = explode( ',', $discounts ); |
|
1384 | + if ($array && $discounts) { |
|
1385 | + $discounts = explode(',', $discounts); |
|
1386 | 1386 | } |
1387 | - return apply_filters( 'wpinv_payment_discounts', $discounts, $this->ID, $this, $array ); |
|
1387 | + return apply_filters('wpinv_payment_discounts', $discounts, $this->ID, $this, $array); |
|
1388 | 1388 | } |
1389 | 1389 | |
1390 | - public function get_discount( $currency = false, $dash = false ) { |
|
1391 | - if ( !empty( $this->discounts ) ) { |
|
1390 | + public function get_discount($currency = false, $dash = false) { |
|
1391 | + if (!empty($this->discounts)) { |
|
1392 | 1392 | global $ajax_cart_details; |
1393 | 1393 | $ajax_cart_details = $this->get_cart_details(); |
1394 | 1394 | |
1395 | - $this->discount = wpinv_get_cart_items_discount_amount( $this->items , $this->discounts ); |
|
1395 | + $this->discount = wpinv_get_cart_items_discount_amount($this->items, $this->discounts); |
|
1396 | 1396 | } |
1397 | - $discount = wpinv_format_amount( $this->discount, NULL, !$currency ); |
|
1397 | + $discount = wpinv_format_amount($this->discount, NULL, !$currency); |
|
1398 | 1398 | $dash = $dash && $discount > 0 ? '–' : ''; |
1399 | 1399 | |
1400 | - if ( $currency ) { |
|
1401 | - $discount = wpinv_price( $discount, $this->get_currency() ); |
|
1400 | + if ($currency) { |
|
1401 | + $discount = wpinv_price($discount, $this->get_currency()); |
|
1402 | 1402 | } |
1403 | 1403 | |
1404 | - $discount = $dash . $discount; |
|
1404 | + $discount = $dash . $discount; |
|
1405 | 1405 | |
1406 | - return apply_filters( 'wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash ); |
|
1406 | + return apply_filters('wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash); |
|
1407 | 1407 | } |
1408 | 1408 | |
1409 | 1409 | public function get_discount_code() { |
1410 | 1410 | return $this->discount_code; |
1411 | 1411 | } |
1412 | 1412 | |
1413 | - public function get_tax( $currency = false ) { |
|
1414 | - $tax = wpinv_format_amount( $this->tax, NULL, !$currency ); |
|
1413 | + public function get_tax($currency = false) { |
|
1414 | + $tax = wpinv_format_amount($this->tax, NULL, !$currency); |
|
1415 | 1415 | |
1416 | - if ( $currency ) { |
|
1417 | - $tax = wpinv_price( $tax, $this->get_currency() ); |
|
1416 | + if ($currency) { |
|
1417 | + $tax = wpinv_price($tax, $this->get_currency()); |
|
1418 | 1418 | } |
1419 | 1419 | |
1420 | - return apply_filters( 'wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency ); |
|
1420 | + return apply_filters('wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency); |
|
1421 | 1421 | } |
1422 | 1422 | |
1423 | - public function get_fees( $type = 'all' ) { |
|
1424 | - $fees = array(); |
|
1423 | + public function get_fees($type = 'all') { |
|
1424 | + $fees = array(); |
|
1425 | 1425 | |
1426 | - if ( ! empty( $this->fees ) && is_array( $this->fees ) ) { |
|
1427 | - foreach ( $this->fees as $fee ) { |
|
1428 | - if( 'all' != $type && ! empty( $fee['type'] ) && $type != $fee['type'] ) { |
|
1426 | + if (!empty($this->fees) && is_array($this->fees)) { |
|
1427 | + foreach ($this->fees as $fee) { |
|
1428 | + if ('all' != $type && !empty($fee['type']) && $type != $fee['type']) { |
|
1429 | 1429 | continue; |
1430 | 1430 | } |
1431 | 1431 | |
1432 | - $fee['label'] = stripslashes( $fee['label'] ); |
|
1433 | - $fee['amount_display'] = wpinv_price( $fee['amount'], $this->get_currency() ); |
|
1434 | - $fees[] = $fee; |
|
1432 | + $fee['label'] = stripslashes($fee['label']); |
|
1433 | + $fee['amount_display'] = wpinv_price($fee['amount'], $this->get_currency()); |
|
1434 | + $fees[] = $fee; |
|
1435 | 1435 | } |
1436 | 1436 | } |
1437 | 1437 | |
1438 | - return apply_filters( 'wpinv_get_invoice_fees', $fees, $this->ID, $this ); |
|
1438 | + return apply_filters('wpinv_get_invoice_fees', $fees, $this->ID, $this); |
|
1439 | 1439 | } |
1440 | 1440 | |
1441 | - public function get_fees_total( $type = 'all' ) { |
|
1442 | - $fees_total = (float) 0.00; |
|
1441 | + public function get_fees_total($type = 'all') { |
|
1442 | + $fees_total = (float)0.00; |
|
1443 | 1443 | |
1444 | - $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array(); |
|
1445 | - if ( ! empty( $payment_fees ) ) { |
|
1446 | - foreach ( $payment_fees as $fee ) { |
|
1447 | - $fees_total += (float) $fee['amount']; |
|
1444 | + $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array(); |
|
1445 | + if (!empty($payment_fees)) { |
|
1446 | + foreach ($payment_fees as $fee) { |
|
1447 | + $fees_total += (float)$fee['amount']; |
|
1448 | 1448 | } |
1449 | 1449 | } |
1450 | 1450 | |
1451 | - return apply_filters( 'wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this ); |
|
1451 | + return apply_filters('wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this); |
|
1452 | 1452 | /* |
1453 | 1453 | $fees = $this->get_fees( $type ); |
1454 | 1454 | |
@@ -1468,116 +1468,116 @@ discard block |
||
1468 | 1468 | } |
1469 | 1469 | |
1470 | 1470 | public function get_user_id() { |
1471 | - return apply_filters( 'wpinv_user_id', $this->user_id, $this->ID, $this ); |
|
1471 | + return apply_filters('wpinv_user_id', $this->user_id, $this->ID, $this); |
|
1472 | 1472 | } |
1473 | 1473 | |
1474 | 1474 | public function get_first_name() { |
1475 | - return apply_filters( 'wpinv_first_name', $this->first_name, $this->ID, $this ); |
|
1475 | + return apply_filters('wpinv_first_name', $this->first_name, $this->ID, $this); |
|
1476 | 1476 | } |
1477 | 1477 | |
1478 | 1478 | public function get_last_name() { |
1479 | - return apply_filters( 'wpinv_last_name', $this->last_name, $this->ID, $this ); |
|
1479 | + return apply_filters('wpinv_last_name', $this->last_name, $this->ID, $this); |
|
1480 | 1480 | } |
1481 | 1481 | |
1482 | 1482 | public function get_user_full_name() { |
1483 | - return apply_filters( 'wpinv_user_full_name', $this->full_name, $this->ID, $this ); |
|
1483 | + return apply_filters('wpinv_user_full_name', $this->full_name, $this->ID, $this); |
|
1484 | 1484 | } |
1485 | 1485 | |
1486 | 1486 | public function get_user_info() { |
1487 | - return apply_filters( 'wpinv_user_info', $this->user_info, $this->ID, $this ); |
|
1487 | + return apply_filters('wpinv_user_info', $this->user_info, $this->ID, $this); |
|
1488 | 1488 | } |
1489 | 1489 | |
1490 | 1490 | public function get_email() { |
1491 | - return apply_filters( 'wpinv_user_email', $this->email, $this->ID, $this ); |
|
1491 | + return apply_filters('wpinv_user_email', $this->email, $this->ID, $this); |
|
1492 | 1492 | } |
1493 | 1493 | |
1494 | 1494 | public function get_address() { |
1495 | - return apply_filters( 'wpinv_address', $this->address, $this->ID, $this ); |
|
1495 | + return apply_filters('wpinv_address', $this->address, $this->ID, $this); |
|
1496 | 1496 | } |
1497 | 1497 | |
1498 | 1498 | public function get_phone() { |
1499 | - return apply_filters( 'wpinv_phone', $this->phone, $this->ID, $this ); |
|
1499 | + return apply_filters('wpinv_phone', $this->phone, $this->ID, $this); |
|
1500 | 1500 | } |
1501 | 1501 | |
1502 | 1502 | public function get_number() { |
1503 | - return apply_filters( 'wpinv_number', $this->number, $this->ID, $this ); |
|
1503 | + return apply_filters('wpinv_number', $this->number, $this->ID, $this); |
|
1504 | 1504 | } |
1505 | 1505 | |
1506 | 1506 | public function get_items() { |
1507 | - return apply_filters( 'wpinv_payment_meta_items', $this->items, $this->ID, $this ); |
|
1507 | + return apply_filters('wpinv_payment_meta_items', $this->items, $this->ID, $this); |
|
1508 | 1508 | } |
1509 | 1509 | |
1510 | 1510 | public function get_key() { |
1511 | - return apply_filters( 'wpinv_key', $this->key, $this->ID, $this ); |
|
1511 | + return apply_filters('wpinv_key', $this->key, $this->ID, $this); |
|
1512 | 1512 | } |
1513 | 1513 | |
1514 | 1514 | public function get_transaction_id() { |
1515 | - return apply_filters( 'wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this ); |
|
1515 | + return apply_filters('wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this); |
|
1516 | 1516 | } |
1517 | 1517 | |
1518 | 1518 | public function get_gateway() { |
1519 | - return apply_filters( 'wpinv_gateway', $this->gateway, $this->ID, $this ); |
|
1519 | + return apply_filters('wpinv_gateway', $this->gateway, $this->ID, $this); |
|
1520 | 1520 | } |
1521 | 1521 | |
1522 | 1522 | public function get_gateway_title() { |
1523 | - $this->gateway_title = !empty( $this->gateway_title ) ? $this->gateway_title : wpinv_get_gateway_checkout_label( $this->gateway ); |
|
1523 | + $this->gateway_title = !empty($this->gateway_title) ? $this->gateway_title : wpinv_get_gateway_checkout_label($this->gateway); |
|
1524 | 1524 | |
1525 | - return apply_filters( 'wpinv_gateway_title', $this->gateway_title, $this->ID, $this ); |
|
1525 | + return apply_filters('wpinv_gateway_title', $this->gateway_title, $this->ID, $this); |
|
1526 | 1526 | } |
1527 | 1527 | |
1528 | 1528 | public function get_currency() { |
1529 | - return apply_filters( 'wpinv_currency_code', $this->currency, $this->ID, $this ); |
|
1529 | + return apply_filters('wpinv_currency_code', $this->currency, $this->ID, $this); |
|
1530 | 1530 | } |
1531 | 1531 | |
1532 | 1532 | public function get_created_date() { |
1533 | - return apply_filters( 'wpinv_created_date', $this->date, $this->ID, $this ); |
|
1533 | + return apply_filters('wpinv_created_date', $this->date, $this->ID, $this); |
|
1534 | 1534 | } |
1535 | 1535 | |
1536 | - public function get_due_date( $display = false ) { |
|
1537 | - $due_date = apply_filters( 'wpinv_due_date', $this->due_date, $this->ID, $this ); |
|
1536 | + public function get_due_date($display = false) { |
|
1537 | + $due_date = apply_filters('wpinv_due_date', $this->due_date, $this->ID, $this); |
|
1538 | 1538 | |
1539 | - if ( !$display || empty( $due_date ) ) { |
|
1539 | + if (!$display || empty($due_date)) { |
|
1540 | 1540 | return $due_date; |
1541 | 1541 | } |
1542 | 1542 | |
1543 | - return date_i18n( get_option( 'date_format' ), strtotime( $due_date ) ); |
|
1543 | + return date_i18n(get_option('date_format'), strtotime($due_date)); |
|
1544 | 1544 | } |
1545 | 1545 | |
1546 | 1546 | public function get_completed_date() { |
1547 | - return apply_filters( 'wpinv_completed_date', $this->completed_date, $this->ID, $this ); |
|
1547 | + return apply_filters('wpinv_completed_date', $this->completed_date, $this->ID, $this); |
|
1548 | 1548 | } |
1549 | 1549 | |
1550 | - public function get_invoice_date( $formatted = true ) { |
|
1550 | + public function get_invoice_date($formatted = true) { |
|
1551 | 1551 | $date_completed = $this->completed_date; |
1552 | 1552 | $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? $date_completed : ''; |
1553 | 1553 | |
1554 | - if ( $invoice_date == '' ) { |
|
1554 | + if ($invoice_date == '') { |
|
1555 | 1555 | $date_created = $this->date; |
1556 | 1556 | $invoice_date = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? $date_created : ''; |
1557 | 1557 | } |
1558 | 1558 | |
1559 | - if ( $formatted && $invoice_date ) { |
|
1560 | - $invoice_date = date_i18n( get_option( 'date_format' ), strtotime( $invoice_date ) ); |
|
1559 | + if ($formatted && $invoice_date) { |
|
1560 | + $invoice_date = date_i18n(get_option('date_format'), strtotime($invoice_date)); |
|
1561 | 1561 | } |
1562 | 1562 | |
1563 | - return apply_filters( 'wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this ); |
|
1563 | + return apply_filters('wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this); |
|
1564 | 1564 | } |
1565 | 1565 | |
1566 | 1566 | public function get_ip() { |
1567 | - return apply_filters( 'wpinv_user_ip', $this->ip, $this->ID, $this ); |
|
1567 | + return apply_filters('wpinv_user_ip', $this->ip, $this->ID, $this); |
|
1568 | 1568 | } |
1569 | 1569 | |
1570 | - public function has_status( $status ) { |
|
1571 | - return apply_filters( 'wpinv_has_status', ( is_array( $status ) && in_array( $this->get_status(), $status ) ) || $this->get_status() === $status ? true : false, $this, $status ); |
|
1570 | + public function has_status($status) { |
|
1571 | + return apply_filters('wpinv_has_status', (is_array($status) && in_array($this->get_status(), $status)) || $this->get_status() === $status ? true : false, $this, $status); |
|
1572 | 1572 | } |
1573 | 1573 | |
1574 | - public function add_item( $item_id = 0, $args = array() ) { |
|
1574 | + public function add_item($item_id = 0, $args = array()) { |
|
1575 | 1575 | global $wpi_current_id, $wpi_item_id; |
1576 | 1576 | |
1577 | - $item = new WPInv_Item( $item_id ); |
|
1577 | + $item = new WPInv_Item($item_id); |
|
1578 | 1578 | |
1579 | 1579 | // Bail if this post isn't a item |
1580 | - if( !$item || $item->post_type !== 'wpi_item' ) { |
|
1580 | + if (!$item || $item->post_type !== 'wpi_item') { |
|
1581 | 1581 | return false; |
1582 | 1582 | } |
1583 | 1583 | |
@@ -1595,8 +1595,8 @@ discard block |
||
1595 | 1595 | 'fees' => array() |
1596 | 1596 | ); |
1597 | 1597 | |
1598 | - $args = wp_parse_args( apply_filters( 'wpinv_add_item_args', $args, $item->ID ), $defaults ); |
|
1599 | - $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint( $args['quantity'] ) : 1; |
|
1598 | + $args = wp_parse_args(apply_filters('wpinv_add_item_args', $args, $item->ID), $defaults); |
|
1599 | + $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint($args['quantity']) : 1; |
|
1600 | 1600 | |
1601 | 1601 | $wpi_current_id = $this->ID; |
1602 | 1602 | $wpi_item_id = $item->ID; |
@@ -1608,19 +1608,19 @@ discard block |
||
1608 | 1608 | $found_cart_key = false; |
1609 | 1609 | |
1610 | 1610 | if ($has_quantities) { |
1611 | - $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details; |
|
1611 | + $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details; |
|
1612 | 1612 | |
1613 | - foreach ( $this->items as $key => $cart_item ) { |
|
1614 | - if ( (int)$item_id !== (int)$cart_item['id'] ) { |
|
1613 | + foreach ($this->items as $key => $cart_item) { |
|
1614 | + if ((int)$item_id !== (int)$cart_item['id']) { |
|
1615 | 1615 | continue; |
1616 | 1616 | } |
1617 | 1617 | |
1618 | - $this->items[ $key ]['quantity'] += $args['quantity']; |
|
1618 | + $this->items[$key]['quantity'] += $args['quantity']; |
|
1619 | 1619 | break; |
1620 | 1620 | } |
1621 | 1621 | |
1622 | - foreach ( $this->cart_details as $cart_key => $cart_item ) { |
|
1623 | - if ( $item_id != $cart_item['id'] ) { |
|
1622 | + foreach ($this->cart_details as $cart_key => $cart_item) { |
|
1623 | + if ($item_id != $cart_item['id']) { |
|
1624 | 1624 | continue; |
1625 | 1625 | } |
1626 | 1626 | |
@@ -1632,29 +1632,29 @@ discard block |
||
1632 | 1632 | if ($has_quantities && $found_cart_key !== false) { |
1633 | 1633 | $cart_item = $this->cart_details[$found_cart_key]; |
1634 | 1634 | $item_price = $cart_item['item_price']; |
1635 | - $quantity = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1; |
|
1636 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0; |
|
1635 | + $quantity = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1; |
|
1636 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0; |
|
1637 | 1637 | |
1638 | 1638 | $new_quantity = $quantity + $args['quantity']; |
1639 | 1639 | $subtotal = $item_price * $new_quantity; |
1640 | 1640 | |
1641 | 1641 | $args['quantity'] = $new_quantity; |
1642 | - $discount = !empty( $args['discount'] ) ? $args['discount'] : 0; |
|
1643 | - $tax = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
1642 | + $discount = !empty($args['discount']) ? $args['discount'] : 0; |
|
1643 | + $tax = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0; |
|
1644 | 1644 | |
1645 | 1645 | $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float)$cart_item['discount'] ? $discount - (float)$cart_item['discount'] : 0; |
1646 | 1646 | $tax_increased = $tax > 0 && $subtotal > 0 && $tax > (float)$cart_item['tax'] ? $tax - (float)$cart_item['tax'] : 0; |
1647 | 1647 | // The total increase equals the number removed * the item_price |
1648 | - $total_increased = wpinv_format_amount( $item_price, NULL, true ); |
|
1648 | + $total_increased = wpinv_format_amount($item_price, NULL, true); |
|
1649 | 1649 | |
1650 | - if ( wpinv_prices_include_tax() ) { |
|
1651 | - $subtotal -= wpinv_format_amount( $tax, NULL, true ); |
|
1650 | + if (wpinv_prices_include_tax()) { |
|
1651 | + $subtotal -= wpinv_format_amount($tax, NULL, true); |
|
1652 | 1652 | } |
1653 | 1653 | |
1654 | - $total = $subtotal - $discount + $tax; |
|
1654 | + $total = $subtotal - $discount + $tax; |
|
1655 | 1655 | |
1656 | 1656 | // Do not allow totals to go negative |
1657 | - if( $total < 0 ) { |
|
1657 | + if ($total < 0) { |
|
1658 | 1658 | $total = 0; |
1659 | 1659 | } |
1660 | 1660 | |
@@ -1670,20 +1670,20 @@ discard block |
||
1670 | 1670 | $this->cart_details[$found_cart_key] = $cart_item; |
1671 | 1671 | } else { |
1672 | 1672 | // Allow overriding the price |
1673 | - if( false !== $args['item_price'] ) { |
|
1673 | + if (false !== $args['item_price']) { |
|
1674 | 1674 | $item_price = $args['item_price']; |
1675 | 1675 | } else { |
1676 | - $item_price = wpinv_get_item_price( $item->ID ); |
|
1676 | + $item_price = wpinv_get_item_price($item->ID); |
|
1677 | 1677 | } |
1678 | 1678 | |
1679 | 1679 | // Sanitizing the price here so we don't have a dozen calls later |
1680 | - $item_price = wpinv_sanitize_amount( $item_price ); |
|
1681 | - $subtotal = wpinv_format_amount( $item_price * $args['quantity'], NULL, true ); |
|
1680 | + $item_price = wpinv_sanitize_amount($item_price); |
|
1681 | + $subtotal = wpinv_format_amount($item_price * $args['quantity'], NULL, true); |
|
1682 | 1682 | |
1683 | - $discount = !empty( $args['discount'] ) ? $args['discount'] : 0; |
|
1684 | - $tax_class = !empty( $args['vat_class'] ) ? $args['vat_class'] : ''; |
|
1685 | - $tax_rate = !empty( $args['vat_rate'] ) ? $args['vat_rate'] : 0; |
|
1686 | - $tax = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
1683 | + $discount = !empty($args['discount']) ? $args['discount'] : 0; |
|
1684 | + $tax_class = !empty($args['vat_class']) ? $args['vat_class'] : ''; |
|
1685 | + $tax_rate = !empty($args['vat_rate']) ? $args['vat_rate'] : 0; |
|
1686 | + $tax = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0; |
|
1687 | 1687 | |
1688 | 1688 | // Setup the items meta item |
1689 | 1689 | $new_item = array( |
@@ -1691,28 +1691,28 @@ discard block |
||
1691 | 1691 | 'quantity' => $args['quantity'], |
1692 | 1692 | ); |
1693 | 1693 | |
1694 | - $this->items[] = $new_item; |
|
1694 | + $this->items[] = $new_item; |
|
1695 | 1695 | |
1696 | - if ( wpinv_prices_include_tax() ) { |
|
1697 | - $subtotal -= wpinv_format_amount( $tax, NULL, true ); |
|
1696 | + if (wpinv_prices_include_tax()) { |
|
1697 | + $subtotal -= wpinv_format_amount($tax, NULL, true); |
|
1698 | 1698 | } |
1699 | 1699 | |
1700 | - $total = $subtotal - $discount + $tax; |
|
1700 | + $total = $subtotal - $discount + $tax; |
|
1701 | 1701 | |
1702 | 1702 | // Do not allow totals to go negative |
1703 | - if( $total < 0 ) { |
|
1703 | + if ($total < 0) { |
|
1704 | 1704 | $total = 0; |
1705 | 1705 | } |
1706 | 1706 | |
1707 | 1707 | $this->cart_details[] = array( |
1708 | 1708 | 'name' => !empty($args['name']) ? $args['name'] : $item->get_name(), |
1709 | 1709 | 'id' => $item->ID, |
1710 | - 'item_price' => wpinv_format_amount( $item_price, NULL, true ), |
|
1710 | + 'item_price' => wpinv_format_amount($item_price, NULL, true), |
|
1711 | 1711 | 'quantity' => $args['quantity'], |
1712 | 1712 | 'discount' => $discount, |
1713 | - 'subtotal' => wpinv_format_amount( $subtotal, NULL, true ), |
|
1714 | - 'tax' => wpinv_format_amount( $tax, NULL, true ), |
|
1715 | - 'price' => wpinv_format_amount( $total, NULL, true ), |
|
1713 | + 'subtotal' => wpinv_format_amount($subtotal, NULL, true), |
|
1714 | + 'tax' => wpinv_format_amount($tax, NULL, true), |
|
1715 | + 'price' => wpinv_format_amount($total, NULL, true), |
|
1716 | 1716 | 'vat_rate' => $tax_rate, |
1717 | 1717 | 'vat_class' => $tax_class, |
1718 | 1718 | 'meta' => $args['meta'], |
@@ -1722,69 +1722,69 @@ discard block |
||
1722 | 1722 | $subtotal = $subtotal - $discount; |
1723 | 1723 | } |
1724 | 1724 | |
1725 | - $added_item = end( $this->cart_details ); |
|
1726 | - $added_item['action'] = 'add'; |
|
1725 | + $added_item = end($this->cart_details); |
|
1726 | + $added_item['action'] = 'add'; |
|
1727 | 1727 | |
1728 | 1728 | $this->pending['items'][] = $added_item; |
1729 | 1729 | |
1730 | - $this->increase_subtotal( $subtotal ); |
|
1731 | - $this->increase_tax( $tax ); |
|
1730 | + $this->increase_subtotal($subtotal); |
|
1731 | + $this->increase_tax($tax); |
|
1732 | 1732 | |
1733 | 1733 | return true; |
1734 | 1734 | } |
1735 | 1735 | |
1736 | - public function remove_item( $item_id, $args = array() ) { |
|
1736 | + public function remove_item($item_id, $args = array()) { |
|
1737 | 1737 | // Set some defaults |
1738 | 1738 | $defaults = array( |
1739 | 1739 | 'quantity' => 1, |
1740 | 1740 | 'item_price' => false, |
1741 | 1741 | 'cart_index' => false, |
1742 | 1742 | ); |
1743 | - $args = wp_parse_args( $args, $defaults ); |
|
1743 | + $args = wp_parse_args($args, $defaults); |
|
1744 | 1744 | |
1745 | 1745 | // Bail if this post isn't a item |
1746 | - if ( get_post_type( $item_id ) !== 'wpi_item' ) { |
|
1746 | + if (get_post_type($item_id) !== 'wpi_item') { |
|
1747 | 1747 | return false; |
1748 | 1748 | } |
1749 | 1749 | |
1750 | - $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details; |
|
1750 | + $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details; |
|
1751 | 1751 | |
1752 | - foreach ( $this->items as $key => $item ) { |
|
1753 | - if ( !empty($item['id']) && (int)$item_id !== (int)$item['id'] ) { |
|
1752 | + foreach ($this->items as $key => $item) { |
|
1753 | + if (!empty($item['id']) && (int)$item_id !== (int)$item['id']) { |
|
1754 | 1754 | continue; |
1755 | 1755 | } |
1756 | 1756 | |
1757 | - if ( false !== $args['cart_index'] ) { |
|
1758 | - $cart_index = absint( $args['cart_index'] ); |
|
1759 | - $cart_item = ! empty( $this->cart_details[ $cart_index ] ) ? $this->cart_details[ $cart_index ] : false; |
|
1757 | + if (false !== $args['cart_index']) { |
|
1758 | + $cart_index = absint($args['cart_index']); |
|
1759 | + $cart_item = !empty($this->cart_details[$cart_index]) ? $this->cart_details[$cart_index] : false; |
|
1760 | 1760 | |
1761 | - if ( ! empty( $cart_item ) ) { |
|
1761 | + if (!empty($cart_item)) { |
|
1762 | 1762 | // If the cart index item isn't the same item ID, don't remove it |
1763 | - if ( !empty($cart_item['id']) && $cart_item['id'] != $item['id'] ) { |
|
1763 | + if (!empty($cart_item['id']) && $cart_item['id'] != $item['id']) { |
|
1764 | 1764 | continue; |
1765 | 1765 | } |
1766 | 1766 | } |
1767 | 1767 | } |
1768 | 1768 | |
1769 | - $item_quantity = $this->items[ $key ]['quantity']; |
|
1770 | - if ( $item_quantity > $args['quantity'] ) { |
|
1771 | - $this->items[ $key ]['quantity'] -= $args['quantity']; |
|
1769 | + $item_quantity = $this->items[$key]['quantity']; |
|
1770 | + if ($item_quantity > $args['quantity']) { |
|
1771 | + $this->items[$key]['quantity'] -= $args['quantity']; |
|
1772 | 1772 | break; |
1773 | 1773 | } else { |
1774 | - unset( $this->items[ $key ] ); |
|
1774 | + unset($this->items[$key]); |
|
1775 | 1775 | break; |
1776 | 1776 | } |
1777 | 1777 | } |
1778 | 1778 | |
1779 | 1779 | $found_cart_key = false; |
1780 | - if ( false === $args['cart_index'] ) { |
|
1781 | - foreach ( $this->cart_details as $cart_key => $item ) { |
|
1782 | - if ( $item_id != $item['id'] ) { |
|
1780 | + if (false === $args['cart_index']) { |
|
1781 | + foreach ($this->cart_details as $cart_key => $item) { |
|
1782 | + if ($item_id != $item['id']) { |
|
1783 | 1783 | continue; |
1784 | 1784 | } |
1785 | 1785 | |
1786 | - if ( false !== $args['item_price'] ) { |
|
1787 | - if ( isset( $item['item_price'] ) && (float) $args['item_price'] != (float) $item['item_price'] ) { |
|
1786 | + if (false !== $args['item_price']) { |
|
1787 | + if (isset($item['item_price']) && (float)$args['item_price'] != (float)$item['item_price']) { |
|
1788 | 1788 | continue; |
1789 | 1789 | } |
1790 | 1790 | } |
@@ -1793,13 +1793,13 @@ discard block |
||
1793 | 1793 | break; |
1794 | 1794 | } |
1795 | 1795 | } else { |
1796 | - $cart_index = absint( $args['cart_index'] ); |
|
1796 | + $cart_index = absint($args['cart_index']); |
|
1797 | 1797 | |
1798 | - if ( ! array_key_exists( $cart_index, $this->cart_details ) ) { |
|
1798 | + if (!array_key_exists($cart_index, $this->cart_details)) { |
|
1799 | 1799 | return false; // Invalid cart index passed. |
1800 | 1800 | } |
1801 | 1801 | |
1802 | - if ( (int) $this->cart_details[ $cart_index ]['id'] > 0 && (int) $this->cart_details[ $cart_index ]['id'] !== (int) $item_id ) { |
|
1802 | + if ((int)$this->cart_details[$cart_index]['id'] > 0 && (int)$this->cart_details[$cart_index]['id'] !== (int)$item_id) { |
|
1803 | 1803 | return false; // We still need the proper Item ID to be sure. |
1804 | 1804 | } |
1805 | 1805 | |
@@ -1807,41 +1807,41 @@ discard block |
||
1807 | 1807 | } |
1808 | 1808 | |
1809 | 1809 | $cart_item = $this->cart_details[$found_cart_key]; |
1810 | - $quantity = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1; |
|
1810 | + $quantity = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1; |
|
1811 | 1811 | |
1812 | - if ( count( $this->cart_details ) == 1 && ( $quantity - $args['quantity'] ) < 1 ) { |
|
1812 | + if (count($this->cart_details) == 1 && ($quantity - $args['quantity']) < 1) { |
|
1813 | 1813 | return false; // Invoice must contain at least one item. |
1814 | 1814 | } |
1815 | 1815 | |
1816 | - $discounts = $this->get_discounts(); |
|
1816 | + $discounts = $this->get_discounts(); |
|
1817 | 1817 | |
1818 | - if ( $quantity > $args['quantity'] ) { |
|
1818 | + if ($quantity > $args['quantity']) { |
|
1819 | 1819 | $item_price = $cart_item['item_price']; |
1820 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0; |
|
1820 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0; |
|
1821 | 1821 | |
1822 | - $new_quantity = max( $quantity - $args['quantity'], 1); |
|
1822 | + $new_quantity = max($quantity - $args['quantity'], 1); |
|
1823 | 1823 | $subtotal = $item_price * $new_quantity; |
1824 | 1824 | |
1825 | 1825 | $args['quantity'] = $new_quantity; |
1826 | - $discount = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0; |
|
1827 | - $tax = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
1826 | + $discount = !empty($cart_item['discount']) ? $cart_item['discount'] : 0; |
|
1827 | + $tax = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0; |
|
1828 | 1828 | |
1829 | - $discount_decrease = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_format_amount( ( (float)$cart_item['discount'] / $quantity ), NULL, true ) : 0; |
|
1829 | + $discount_decrease = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_format_amount(((float)$cart_item['discount'] / $quantity), NULL, true) : 0; |
|
1830 | 1830 | $discount_decrease = $discount > 0 && $subtotal > 0 && (float)$cart_item['discount'] > $discount ? (float)$cart_item['discount'] - $discount : $discount_decrease; |
1831 | - $tax_decrease = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_format_amount( ( (float)$cart_item['tax'] / $quantity ), NULL, true ) : 0; |
|
1831 | + $tax_decrease = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_format_amount(((float)$cart_item['tax'] / $quantity), NULL, true) : 0; |
|
1832 | 1832 | $tax_decrease = $tax > 0 && $subtotal > 0 && (float)$cart_item['tax'] > $tax ? (float)$cart_item['tax'] - $tax : $tax_decrease; |
1833 | 1833 | |
1834 | 1834 | // The total increase equals the number removed * the item_price |
1835 | - $total_decrease = wpinv_format_amount( $item_price, NULL, true ); |
|
1835 | + $total_decrease = wpinv_format_amount($item_price, NULL, true); |
|
1836 | 1836 | |
1837 | - if ( wpinv_prices_include_tax() ) { |
|
1838 | - $subtotal -= wpinv_format_amount( $tax, NULL, true ); |
|
1837 | + if (wpinv_prices_include_tax()) { |
|
1838 | + $subtotal -= wpinv_format_amount($tax, NULL, true); |
|
1839 | 1839 | } |
1840 | 1840 | |
1841 | - $total = $subtotal - $discount + $tax; |
|
1841 | + $total = $subtotal - $discount + $tax; |
|
1842 | 1842 | |
1843 | 1843 | // Do not allow totals to go negative |
1844 | - if( $total < 0 ) { |
|
1844 | + if ($total < 0) { |
|
1845 | 1845 | $total = 0; |
1846 | 1846 | } |
1847 | 1847 | |
@@ -1860,16 +1860,16 @@ discard block |
||
1860 | 1860 | |
1861 | 1861 | $this->cart_details[$found_cart_key] = $cart_item; |
1862 | 1862 | |
1863 | - $remove_item = end( $this->cart_details ); |
|
1863 | + $remove_item = end($this->cart_details); |
|
1864 | 1864 | } else { |
1865 | 1865 | $item_price = $cart_item['item_price']; |
1866 | - $discount = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0; |
|
1867 | - $tax = !empty( $cart_item['tax'] ) ? $cart_item['tax'] : 0; |
|
1866 | + $discount = !empty($cart_item['discount']) ? $cart_item['discount'] : 0; |
|
1867 | + $tax = !empty($cart_item['tax']) ? $cart_item['tax'] : 0; |
|
1868 | 1868 | |
1869 | - $subtotal_decrease = ( $item_price * $quantity ) - $discount; |
|
1869 | + $subtotal_decrease = ($item_price * $quantity) - $discount; |
|
1870 | 1870 | $tax_decrease = $tax; |
1871 | 1871 | |
1872 | - unset( $this->cart_details[$found_cart_key] ); |
|
1872 | + unset($this->cart_details[$found_cart_key]); |
|
1873 | 1873 | |
1874 | 1874 | $remove_item = $args; |
1875 | 1875 | $remove_item['id'] = $item_id; |
@@ -1880,8 +1880,8 @@ discard block |
||
1880 | 1880 | $remove_item['action'] = 'remove'; |
1881 | 1881 | $this->pending['items'][] = $remove_item; |
1882 | 1882 | |
1883 | - $this->decrease_subtotal( $subtotal_decrease ); |
|
1884 | - $this->decrease_tax( $tax_decrease ); |
|
1883 | + $this->decrease_subtotal($subtotal_decrease); |
|
1884 | + $this->decrease_tax($tax_decrease); |
|
1885 | 1885 | |
1886 | 1886 | return true; |
1887 | 1887 | } |
@@ -1889,7 +1889,7 @@ discard block |
||
1889 | 1889 | public function update_items($temp = false) { |
1890 | 1890 | global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpi_nosave; |
1891 | 1891 | |
1892 | - if ( !empty( $this->cart_details ) ) { |
|
1892 | + if (!empty($this->cart_details)) { |
|
1893 | 1893 | $wpi_nosave = $temp; |
1894 | 1894 | $cart_subtotal = 0; |
1895 | 1895 | $cart_discount = 0; |
@@ -1899,41 +1899,41 @@ discard block |
||
1899 | 1899 | $_POST['wpinv_country'] = $this->country; |
1900 | 1900 | $_POST['wpinv_state'] = $this->state; |
1901 | 1901 | |
1902 | - foreach ( $this->cart_details as $key => $item ) { |
|
1902 | + foreach ($this->cart_details as $key => $item) { |
|
1903 | 1903 | $item_price = $item['item_price']; |
1904 | - $quantity = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1; |
|
1905 | - $amount = wpinv_format_amount( $item_price * $quantity, NULL, true ); |
|
1904 | + $quantity = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint($item['quantity']) : 1; |
|
1905 | + $amount = wpinv_format_amount($item_price * $quantity, NULL, true); |
|
1906 | 1906 | $subtotal = $item_price * $quantity; |
1907 | 1907 | |
1908 | 1908 | $wpi_current_id = $this->ID; |
1909 | 1909 | $wpi_item_id = $item['id']; |
1910 | 1910 | |
1911 | - $discount = wpinv_get_cart_item_discount_amount( $item, $this->get_discounts() ); |
|
1911 | + $discount = wpinv_get_cart_item_discount_amount($item, $this->get_discounts()); |
|
1912 | 1912 | |
1913 | - $tax_rate = wpinv_get_tax_rate( $this->country, $this->state, $wpi_item_id ); |
|
1914 | - $tax_class = $wpinv_euvat->get_item_class( $wpi_item_id ); |
|
1915 | - $tax = $item_price > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
1913 | + $tax_rate = wpinv_get_tax_rate($this->country, $this->state, $wpi_item_id); |
|
1914 | + $tax_class = $wpinv_euvat->get_item_class($wpi_item_id); |
|
1915 | + $tax = $item_price > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0; |
|
1916 | 1916 | |
1917 | - if ( wpinv_prices_include_tax() ) { |
|
1918 | - $subtotal -= wpinv_format_amount( $tax, NULL, true ); |
|
1917 | + if (wpinv_prices_include_tax()) { |
|
1918 | + $subtotal -= wpinv_format_amount($tax, NULL, true); |
|
1919 | 1919 | } |
1920 | 1920 | |
1921 | - $total = $subtotal - $discount + $tax; |
|
1921 | + $total = $subtotal - $discount + $tax; |
|
1922 | 1922 | |
1923 | 1923 | // Do not allow totals to go negative |
1924 | - if( $total < 0 ) { |
|
1924 | + if ($total < 0) { |
|
1925 | 1925 | $total = 0; |
1926 | 1926 | } |
1927 | 1927 | |
1928 | 1928 | $cart_details[] = array( |
1929 | 1929 | 'id' => $item['id'], |
1930 | 1930 | 'name' => $item['name'], |
1931 | - 'item_price' => wpinv_format_amount( $item_price, NULL, true ), |
|
1931 | + 'item_price' => wpinv_format_amount($item_price, NULL, true), |
|
1932 | 1932 | 'quantity' => $quantity, |
1933 | 1933 | 'discount' => $discount, |
1934 | - 'subtotal' => wpinv_format_amount( $subtotal, NULL, true ), |
|
1935 | - 'tax' => wpinv_format_amount( $tax, NULL, true ), |
|
1936 | - 'price' => wpinv_format_amount( $total, NULL, true ), |
|
1934 | + 'subtotal' => wpinv_format_amount($subtotal, NULL, true), |
|
1935 | + 'tax' => wpinv_format_amount($tax, NULL, true), |
|
1936 | + 'price' => wpinv_format_amount($total, NULL, true), |
|
1937 | 1937 | 'vat_rate' => $tax_rate, |
1938 | 1938 | 'vat_class' => $tax_class, |
1939 | 1939 | 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
@@ -1944,9 +1944,9 @@ discard block |
||
1944 | 1944 | $cart_discount += (float)($discount); |
1945 | 1945 | $cart_tax += (float)($tax); |
1946 | 1946 | } |
1947 | - $this->subtotal = wpinv_format_amount( $cart_subtotal, NULL, true ); |
|
1948 | - $this->tax = wpinv_format_amount( $cart_tax, NULL, true ); |
|
1949 | - $this->discount = wpinv_format_amount( $cart_discount, NULL, true ); |
|
1947 | + $this->subtotal = wpinv_format_amount($cart_subtotal, NULL, true); |
|
1948 | + $this->tax = wpinv_format_amount($cart_tax, NULL, true); |
|
1949 | + $this->discount = wpinv_format_amount($cart_discount, NULL, true); |
|
1950 | 1950 | |
1951 | 1951 | $this->recalculate_total(); |
1952 | 1952 | |
@@ -1958,221 +1958,221 @@ discard block |
||
1958 | 1958 | |
1959 | 1959 | public function recalculate_totals($temp = false) { |
1960 | 1960 | $this->update_items($temp); |
1961 | - $this->save( true ); |
|
1961 | + $this->save(true); |
|
1962 | 1962 | |
1963 | 1963 | return $this; |
1964 | 1964 | } |
1965 | 1965 | |
1966 | 1966 | public function needs_payment() { |
1967 | - $valid_invoice_statuses = apply_filters( 'wpinv_valid_invoice_statuses_for_payment', array( 'pending' ), $this ); |
|
1967 | + $valid_invoice_statuses = apply_filters('wpinv_valid_invoice_statuses_for_payment', array('pending'), $this); |
|
1968 | 1968 | |
1969 | - if ( $this->has_status( $valid_invoice_statuses ) && ( $this->get_total() > 0 || $this->is_free_trial() ) ) { |
|
1969 | + if ($this->has_status($valid_invoice_statuses) && ($this->get_total() > 0 || $this->is_free_trial())) { |
|
1970 | 1970 | $needs_payment = true; |
1971 | 1971 | } else { |
1972 | 1972 | $needs_payment = false; |
1973 | 1973 | } |
1974 | 1974 | |
1975 | - return apply_filters( 'wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses ); |
|
1975 | + return apply_filters('wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses); |
|
1976 | 1976 | } |
1977 | 1977 | |
1978 | - public function get_checkout_payment_url( $on_checkout = false, $secret = false ) { |
|
1978 | + public function get_checkout_payment_url($on_checkout = false, $secret = false) { |
|
1979 | 1979 | $pay_url = wpinv_get_checkout_uri(); |
1980 | 1980 | |
1981 | - if ( is_ssl() ) { |
|
1982 | - $pay_url = str_replace( 'http:', 'https:', $pay_url ); |
|
1981 | + if (is_ssl()) { |
|
1982 | + $pay_url = str_replace('http:', 'https:', $pay_url); |
|
1983 | 1983 | } |
1984 | 1984 | |
1985 | 1985 | $key = $this->get_key(); |
1986 | 1986 | |
1987 | - if ( $on_checkout ) { |
|
1988 | - $pay_url = add_query_arg( 'invoice_key', $key, $pay_url ); |
|
1987 | + if ($on_checkout) { |
|
1988 | + $pay_url = add_query_arg('invoice_key', $key, $pay_url); |
|
1989 | 1989 | } else { |
1990 | - $pay_url = add_query_arg( array( 'wpi_action' => 'pay_for_invoice', 'invoice_key' => $key ), $pay_url ); |
|
1990 | + $pay_url = add_query_arg(array('wpi_action' => 'pay_for_invoice', 'invoice_key' => $key), $pay_url); |
|
1991 | 1991 | } |
1992 | 1992 | |
1993 | - if ( $secret ) { |
|
1994 | - $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $key ) ), $pay_url ); |
|
1993 | + if ($secret) { |
|
1994 | + $pay_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $key)), $pay_url); |
|
1995 | 1995 | } |
1996 | 1996 | |
1997 | - return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this ); |
|
1997 | + return apply_filters('wpinv_get_checkout_payment_url', $pay_url, $this); |
|
1998 | 1998 | } |
1999 | 1999 | |
2000 | - public function get_view_url( $secret = false ) { |
|
2001 | - $print_url = get_permalink( $this->ID ); |
|
2000 | + public function get_view_url($secret = false) { |
|
2001 | + $print_url = get_permalink($this->ID); |
|
2002 | 2002 | |
2003 | - if ( $secret ) { |
|
2004 | - $print_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $print_url ); |
|
2003 | + if ($secret) { |
|
2004 | + $print_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key())), $print_url); |
|
2005 | 2005 | } |
2006 | 2006 | |
2007 | - return apply_filters( 'wpinv_get_view_url', $print_url, $this ); |
|
2007 | + return apply_filters('wpinv_get_view_url', $print_url, $this); |
|
2008 | 2008 | } |
2009 | 2009 | |
2010 | - public function generate_key( $string = '' ) { |
|
2011 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
2012 | - return strtolower( md5( $string . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'wpinv', true ) ) ); // Unique key |
|
2010 | + public function generate_key($string = '') { |
|
2011 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
2012 | + return strtolower(md5($string . date('Y-m-d H:i:s') . $auth_key . uniqid('wpinv', true))); // Unique key |
|
2013 | 2013 | } |
2014 | 2014 | |
2015 | 2015 | public function is_recurring() { |
2016 | - if ( empty( $this->cart_details ) ) { |
|
2016 | + if (empty($this->cart_details)) { |
|
2017 | 2017 | return false; |
2018 | 2018 | } |
2019 | 2019 | |
2020 | 2020 | $has_subscription = false; |
2021 | - foreach( $this->cart_details as $cart_item ) { |
|
2022 | - if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] ) ) { |
|
2021 | + foreach ($this->cart_details as $cart_item) { |
|
2022 | + if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { |
|
2023 | 2023 | $has_subscription = true; |
2024 | 2024 | break; |
2025 | 2025 | } |
2026 | 2026 | } |
2027 | 2027 | |
2028 | - if ( count( $this->cart_details ) > 1 ) { |
|
2028 | + if (count($this->cart_details) > 1) { |
|
2029 | 2029 | $has_subscription = false; |
2030 | 2030 | } |
2031 | 2031 | |
2032 | - return apply_filters( 'wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details ); |
|
2032 | + return apply_filters('wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details); |
|
2033 | 2033 | } |
2034 | 2034 | |
2035 | 2035 | public function is_free_trial() { |
2036 | 2036 | $is_free_trial = false; |
2037 | 2037 | |
2038 | - if ( $this->is_parent() && $item = $this->get_recurring( true ) ) { |
|
2039 | - if ( !empty( $item ) && $item->has_free_trial() ) { |
|
2038 | + if ($this->is_parent() && $item = $this->get_recurring(true)) { |
|
2039 | + if (!empty($item) && $item->has_free_trial()) { |
|
2040 | 2040 | $is_free_trial = true; |
2041 | 2041 | } |
2042 | 2042 | } |
2043 | 2043 | |
2044 | - return apply_filters( 'wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details ); |
|
2044 | + return apply_filters('wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details); |
|
2045 | 2045 | } |
2046 | 2046 | |
2047 | - public function get_recurring( $object = false ) { |
|
2047 | + public function get_recurring($object = false) { |
|
2048 | 2048 | $item = NULL; |
2049 | 2049 | |
2050 | - if ( empty( $this->cart_details ) ) { |
|
2050 | + if (empty($this->cart_details)) { |
|
2051 | 2051 | return $item; |
2052 | 2052 | } |
2053 | 2053 | |
2054 | - foreach( $this->cart_details as $cart_item ) { |
|
2055 | - if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] ) ) { |
|
2054 | + foreach ($this->cart_details as $cart_item) { |
|
2055 | + if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { |
|
2056 | 2056 | $item = $cart_item['id']; |
2057 | 2057 | break; |
2058 | 2058 | } |
2059 | 2059 | } |
2060 | 2060 | |
2061 | - if ( $object ) { |
|
2062 | - $item = $item ? new WPInv_Item( $item ) : NULL; |
|
2061 | + if ($object) { |
|
2062 | + $item = $item ? new WPInv_Item($item) : NULL; |
|
2063 | 2063 | |
2064 | - apply_filters( 'wpinv_invoice_get_recurring_item', $item, $this ); |
|
2064 | + apply_filters('wpinv_invoice_get_recurring_item', $item, $this); |
|
2065 | 2065 | } |
2066 | 2066 | |
2067 | - return apply_filters( 'wpinv_invoice_get_recurring_item_id', $item, $this ); |
|
2067 | + return apply_filters('wpinv_invoice_get_recurring_item_id', $item, $this); |
|
2068 | 2068 | } |
2069 | 2069 | |
2070 | 2070 | public function get_subscription_name() { |
2071 | - $item = $this->get_recurring( true ); |
|
2071 | + $item = $this->get_recurring(true); |
|
2072 | 2072 | |
2073 | - if ( empty( $item ) ) { |
|
2073 | + if (empty($item)) { |
|
2074 | 2074 | return NULL; |
2075 | 2075 | } |
2076 | 2076 | |
2077 | - if ( !($name = $item->get_name()) ) { |
|
2077 | + if (!($name = $item->get_name())) { |
|
2078 | 2078 | $name = $item->post_name; |
2079 | 2079 | } |
2080 | 2080 | |
2081 | - return apply_filters( 'wpinv_invoice_get_subscription_name', $name, $this ); |
|
2081 | + return apply_filters('wpinv_invoice_get_subscription_name', $name, $this); |
|
2082 | 2082 | } |
2083 | 2083 | |
2084 | 2084 | public function get_expiration() { |
2085 | - $expiration = $this->get_meta( '_wpinv_subscr_expiration', true ); |
|
2085 | + $expiration = $this->get_meta('_wpinv_subscr_expiration', true); |
|
2086 | 2086 | return $expiration; |
2087 | 2087 | } |
2088 | 2088 | |
2089 | - public function get_cancelled_date( $formatted = true ) { |
|
2090 | - $cancelled_date = $this->get_subscription_status() == 'cancelled' ? $this->get_meta( '_wpinv_subscr_cancelled_on', true ) : ''; |
|
2089 | + public function get_cancelled_date($formatted = true) { |
|
2090 | + $cancelled_date = $this->get_subscription_status() == 'cancelled' ? $this->get_meta('_wpinv_subscr_cancelled_on', true) : ''; |
|
2091 | 2091 | |
2092 | - if ( $formatted && $cancelled_date ) { |
|
2093 | - $cancelled_date = date_i18n( get_option( 'date_format' ), strtotime( $cancelled_date ) ); |
|
2092 | + if ($formatted && $cancelled_date) { |
|
2093 | + $cancelled_date = date_i18n(get_option('date_format'), strtotime($cancelled_date)); |
|
2094 | 2094 | } |
2095 | 2095 | |
2096 | 2096 | return $cancelled_date; |
2097 | 2097 | } |
2098 | 2098 | |
2099 | - public function get_trial_end_date( $formatted = true ) { |
|
2100 | - if ( !$this->is_free_trial() || !$this->is_paid() ) { |
|
2099 | + public function get_trial_end_date($formatted = true) { |
|
2100 | + if (!$this->is_free_trial() || !$this->is_paid()) { |
|
2101 | 2101 | return NULL; |
2102 | 2102 | } |
2103 | 2103 | |
2104 | - $trial_end_date = $this->get_subscription_status() == 'trialing' ? $this->get_meta( '_wpinv_subscr_trial_end', true ) : ''; |
|
2104 | + $trial_end_date = $this->get_subscription_status() == 'trialing' ? $this->get_meta('_wpinv_subscr_trial_end', true) : ''; |
|
2105 | 2105 | |
2106 | - if ( empty( $trial_end_date ) ) { |
|
2107 | - $trial_start_time = strtotime( $this->get_subscription_start() ); |
|
2108 | - $trial_start_time += ( wpinv_period_in_days( $this->get_subscription_trial_interval(), $this->get_subscription_trial_period() ) * DAY_IN_SECONDS ) ; |
|
2106 | + if (empty($trial_end_date)) { |
|
2107 | + $trial_start_time = strtotime($this->get_subscription_start()); |
|
2108 | + $trial_start_time += (wpinv_period_in_days($this->get_subscription_trial_interval(), $this->get_subscription_trial_period()) * DAY_IN_SECONDS); |
|
2109 | 2109 | |
2110 | - $trial_end_date = date_i18n( 'Y-m-d H:i:s', $trial_start_time ); |
|
2110 | + $trial_end_date = date_i18n('Y-m-d H:i:s', $trial_start_time); |
|
2111 | 2111 | } |
2112 | 2112 | |
2113 | - if ( $formatted && $trial_end_date ) { |
|
2114 | - $trial_end_date = date_i18n( get_option( 'date_format' ), strtotime( $trial_end_date ) ); |
|
2113 | + if ($formatted && $trial_end_date) { |
|
2114 | + $trial_end_date = date_i18n(get_option('date_format'), strtotime($trial_end_date)); |
|
2115 | 2115 | } |
2116 | 2116 | |
2117 | 2117 | return $trial_end_date; |
2118 | 2118 | } |
2119 | 2119 | |
2120 | - public function get_subscription_created( $default = true ) { |
|
2121 | - $created = $this->get_meta( '_wpinv_subscr_created', true ); |
|
2120 | + public function get_subscription_created($default = true) { |
|
2121 | + $created = $this->get_meta('_wpinv_subscr_created', true); |
|
2122 | 2122 | |
2123 | - if ( empty( $created ) && $default ) { |
|
2123 | + if (empty($created) && $default) { |
|
2124 | 2124 | $created = $this->date; |
2125 | 2125 | } |
2126 | 2126 | return $created; |
2127 | 2127 | } |
2128 | 2128 | |
2129 | - public function get_subscription_start( $formatted = true ) { |
|
2130 | - if ( !$this->is_paid() ) { |
|
2129 | + public function get_subscription_start($formatted = true) { |
|
2130 | + if (!$this->is_paid()) { |
|
2131 | 2131 | return '-'; |
2132 | 2132 | } |
2133 | - $start = $this->get_subscription_created(); |
|
2133 | + $start = $this->get_subscription_created(); |
|
2134 | 2134 | |
2135 | - if ( $formatted ) { |
|
2136 | - $date = date_i18n( get_option( 'date_format' ), strtotime( $start ) ); |
|
2135 | + if ($formatted) { |
|
2136 | + $date = date_i18n(get_option('date_format'), strtotime($start)); |
|
2137 | 2137 | } else { |
2138 | - $date = date_i18n( 'Y-m-d H:i:s', strtotime( $start ) ); |
|
2138 | + $date = date_i18n('Y-m-d H:i:s', strtotime($start)); |
|
2139 | 2139 | } |
2140 | 2140 | |
2141 | 2141 | return $date; |
2142 | 2142 | } |
2143 | 2143 | |
2144 | - public function get_subscription_end( $formatted = true ) { |
|
2145 | - if ( !$this->is_paid() ) { |
|
2144 | + public function get_subscription_end($formatted = true) { |
|
2145 | + if (!$this->is_paid()) { |
|
2146 | 2146 | return '-'; |
2147 | 2147 | } |
2148 | 2148 | $start = $this->get_subscription_created(); |
2149 | 2149 | $interval = $this->get_subscription_interval(); |
2150 | - $period = $this->get_subscription_period( true ); |
|
2150 | + $period = $this->get_subscription_period(true); |
|
2151 | 2151 | $bill_times = (int)$this->get_bill_times(); |
2152 | 2152 | |
2153 | - if ( $bill_times == 0 ) { |
|
2154 | - return $formatted ? __( 'Until cancelled', 'invoicing' ) : $bill_times; |
|
2153 | + if ($bill_times == 0) { |
|
2154 | + return $formatted ? __('Until cancelled', 'invoicing') : $bill_times; |
|
2155 | 2155 | } |
2156 | 2156 | |
2157 | - $total_period = $start . '+' . ( $interval * $bill_times ) . ' ' . $period; |
|
2157 | + $total_period = $start . '+' . ($interval * $bill_times) . ' ' . $period; |
|
2158 | 2158 | |
2159 | - $end_time = strtotime( $start . '+' . ( $interval * $bill_times ) . ' ' . $period ); |
|
2159 | + $end_time = strtotime($start . '+' . ($interval * $bill_times) . ' ' . $period); |
|
2160 | 2160 | |
2161 | - if ( $this->is_free_trial() ) { |
|
2162 | - $end_time += ( wpinv_period_in_days( $this->get_subscription_trial_interval(), $this->get_subscription_trial_period() ) * DAY_IN_SECONDS ) ; |
|
2161 | + if ($this->is_free_trial()) { |
|
2162 | + $end_time += (wpinv_period_in_days($this->get_subscription_trial_interval(), $this->get_subscription_trial_period()) * DAY_IN_SECONDS); |
|
2163 | 2163 | } |
2164 | 2164 | |
2165 | - if ( $formatted ) { |
|
2166 | - $date = date_i18n( get_option( 'date_format' ), $end_time ); |
|
2165 | + if ($formatted) { |
|
2166 | + $date = date_i18n(get_option('date_format'), $end_time); |
|
2167 | 2167 | } else { |
2168 | - $date = date_i18n( 'Y-m-d H:i:s', $end_time ); |
|
2168 | + $date = date_i18n('Y-m-d H:i:s', $end_time); |
|
2169 | 2169 | } |
2170 | 2170 | |
2171 | 2171 | return $date; |
2172 | 2172 | } |
2173 | 2173 | |
2174 | 2174 | public function get_expiration_time() { |
2175 | - return strtotime( $this->get_expiration(), current_time( 'timestamp' ) ); |
|
2175 | + return strtotime($this->get_expiration(), current_time('timestamp')); |
|
2176 | 2176 | } |
2177 | 2177 | |
2178 | 2178 | public function get_original_invoice_id() { |
@@ -2184,125 +2184,125 @@ discard block |
||
2184 | 2184 | return $subscription_data['bill_times']; |
2185 | 2185 | } |
2186 | 2186 | |
2187 | - public function get_child_payments( $self = false ) { |
|
2188 | - $invoices = get_posts( array( |
|
2187 | + public function get_child_payments($self = false) { |
|
2188 | + $invoices = get_posts(array( |
|
2189 | 2189 | 'post_type' => $this->post_type, |
2190 | 2190 | 'post_parent' => (int)$this->ID, |
2191 | 2191 | 'posts_per_page' => '999', |
2192 | - 'post_status' => array( 'publish', 'complete', 'processing', 'renewal' ), |
|
2192 | + 'post_status' => array('publish', 'complete', 'processing', 'renewal'), |
|
2193 | 2193 | 'orderby' => 'ID', |
2194 | 2194 | 'order' => 'DESC', |
2195 | 2195 | 'fields' => 'ids' |
2196 | - ) ); |
|
2196 | + )); |
|
2197 | 2197 | |
2198 | - if ( $this->is_free_trial() ) { |
|
2198 | + if ($this->is_free_trial()) { |
|
2199 | 2199 | $self = false; |
2200 | 2200 | } |
2201 | 2201 | |
2202 | - if ( $self && $this->is_paid() ) { |
|
2203 | - if ( !empty( $invoices ) ) { |
|
2202 | + if ($self && $this->is_paid()) { |
|
2203 | + if (!empty($invoices)) { |
|
2204 | 2204 | $invoices[] = (int)$this->ID; |
2205 | 2205 | } else { |
2206 | - $invoices = array( $this->ID ); |
|
2206 | + $invoices = array($this->ID); |
|
2207 | 2207 | } |
2208 | 2208 | |
2209 | - $invoices = array_unique( $invoices ); |
|
2209 | + $invoices = array_unique($invoices); |
|
2210 | 2210 | } |
2211 | 2211 | |
2212 | 2212 | return $invoices; |
2213 | 2213 | } |
2214 | 2214 | |
2215 | - public function get_total_payments( $self = true ) { |
|
2216 | - return count( $this->get_child_payments( $self ) ); |
|
2215 | + public function get_total_payments($self = true) { |
|
2216 | + return count($this->get_child_payments($self)); |
|
2217 | 2217 | } |
2218 | 2218 | |
2219 | - public function get_subscriptions( $limit = -1 ) { |
|
2220 | - $subscriptions = wpinv_get_subscriptions( array( 'parent_invoice_id' => $this->ID, 'numberposts' => $limit ) ); |
|
2219 | + public function get_subscriptions($limit = -1) { |
|
2220 | + $subscriptions = wpinv_get_subscriptions(array('parent_invoice_id' => $this->ID, 'numberposts' => $limit)); |
|
2221 | 2221 | |
2222 | 2222 | return $subscriptions; |
2223 | 2223 | } |
2224 | 2224 | |
2225 | 2225 | public function get_subscription_id() { |
2226 | - $subscription_id = $this->get_meta( '_wpinv_subscr_profile_id', true ); |
|
2226 | + $subscription_id = $this->get_meta('_wpinv_subscr_profile_id', true); |
|
2227 | 2227 | |
2228 | - if ( empty( $subscription_id ) && !empty( $this->parent_invoice ) ) { |
|
2229 | - $parent_invoice = wpinv_get_invoice( $this->parent_invoice ); |
|
2228 | + if (empty($subscription_id) && !empty($this->parent_invoice)) { |
|
2229 | + $parent_invoice = wpinv_get_invoice($this->parent_invoice); |
|
2230 | 2230 | |
2231 | - $subscription_id = $parent_invoice->get_meta( '_wpinv_subscr_profile_id', true ); |
|
2231 | + $subscription_id = $parent_invoice->get_meta('_wpinv_subscr_profile_id', true); |
|
2232 | 2232 | } |
2233 | 2233 | |
2234 | 2234 | return $subscription_id; |
2235 | 2235 | } |
2236 | 2236 | |
2237 | 2237 | public function get_subscription_status() { |
2238 | - $subscription_status = $this->get_meta( '_wpinv_subscr_status', true ); |
|
2238 | + $subscription_status = $this->get_meta('_wpinv_subscr_status', true); |
|
2239 | 2239 | |
2240 | - if ( empty( $subscription_status ) ) { |
|
2240 | + if (empty($subscription_status)) { |
|
2241 | 2241 | $status = 'pending'; |
2242 | 2242 | |
2243 | - if ( $this->is_paid() ) { |
|
2243 | + if ($this->is_paid()) { |
|
2244 | 2244 | $bill_times = (int)$this->get_bill_times(); |
2245 | 2245 | $times_billed = (int)$this->get_total_payments(); |
2246 | - $expiration = $this->get_subscription_end( false ); |
|
2247 | - $expired = $bill_times != 0 && $expiration != '' && $expiration != '-' && strtotime( date_i18n( 'Y-m-d', strtotime( $expiration ) ) ) < strtotime( date_i18n( 'Y-m-d', current_time( 'timestamp' ) ) ) ? true : false; |
|
2246 | + $expiration = $this->get_subscription_end(false); |
|
2247 | + $expired = $bill_times != 0 && $expiration != '' && $expiration != '-' && strtotime(date_i18n('Y-m-d', strtotime($expiration))) < strtotime(date_i18n('Y-m-d', current_time('timestamp'))) ? true : false; |
|
2248 | 2248 | |
2249 | - if ( (int)$bill_times == 0 ) { |
|
2249 | + if ((int)$bill_times == 0) { |
|
2250 | 2250 | $status = $expired ? 'expired' : 'active'; |
2251 | - } else if ( $bill_times > 0 && $times_billed >= $bill_times ) { |
|
2251 | + } else if ($bill_times > 0 && $times_billed >= $bill_times) { |
|
2252 | 2252 | $status = 'completed'; |
2253 | - } else if ( $expired ) { |
|
2253 | + } else if ($expired) { |
|
2254 | 2254 | $status = 'expired'; |
2255 | - } else if ( $bill_times > 0 ) { |
|
2255 | + } else if ($bill_times > 0) { |
|
2256 | 2256 | $status = 'active'; |
2257 | 2257 | } else { |
2258 | 2258 | $status = 'pending'; |
2259 | 2259 | } |
2260 | 2260 | } |
2261 | 2261 | |
2262 | - if ( $status && $status != $subscription_status ) { |
|
2262 | + if ($status && $status != $subscription_status) { |
|
2263 | 2263 | $subscription_status = $status; |
2264 | 2264 | |
2265 | - $this->update_meta( '_wpinv_subscr_status', $status ); |
|
2265 | + $this->update_meta('_wpinv_subscr_status', $status); |
|
2266 | 2266 | } |
2267 | 2267 | } |
2268 | 2268 | |
2269 | 2269 | return $subscription_status; |
2270 | 2270 | } |
2271 | 2271 | |
2272 | - public function get_subscription_status_label( $status = '' ) { |
|
2273 | - $status = !empty( $status ) ? $status : $this->get_subscription_status(); |
|
2272 | + public function get_subscription_status_label($status = '') { |
|
2273 | + $status = !empty($status) ? $status : $this->get_subscription_status(); |
|
2274 | 2274 | |
2275 | - switch( $status ) { |
|
2275 | + switch ($status) { |
|
2276 | 2276 | case 'active' : |
2277 | - $status_label = __( 'Active', 'invoicing' ); |
|
2277 | + $status_label = __('Active', 'invoicing'); |
|
2278 | 2278 | break; |
2279 | 2279 | |
2280 | 2280 | case 'cancelled' : |
2281 | - $status_label = __( 'Cancelled', 'invoicing' ); |
|
2281 | + $status_label = __('Cancelled', 'invoicing'); |
|
2282 | 2282 | break; |
2283 | 2283 | |
2284 | 2284 | case 'completed' : |
2285 | - $status_label = __( 'Completed', 'invoicing' ); |
|
2285 | + $status_label = __('Completed', 'invoicing'); |
|
2286 | 2286 | break; |
2287 | 2287 | |
2288 | 2288 | case 'expired' : |
2289 | - $status_label = __( 'Expired', 'invoicing' ); |
|
2289 | + $status_label = __('Expired', 'invoicing'); |
|
2290 | 2290 | break; |
2291 | 2291 | |
2292 | 2292 | case 'pending' : |
2293 | - $status_label = __( 'Pending', 'invoicing' ); |
|
2293 | + $status_label = __('Pending', 'invoicing'); |
|
2294 | 2294 | break; |
2295 | 2295 | |
2296 | 2296 | case 'failing' : |
2297 | - $status_label = __( 'Failing', 'invoicing' ); |
|
2297 | + $status_label = __('Failing', 'invoicing'); |
|
2298 | 2298 | break; |
2299 | 2299 | |
2300 | 2300 | case 'stopped' : |
2301 | - $status_label = __( 'Stopped', 'invoicing' ); |
|
2301 | + $status_label = __('Stopped', 'invoicing'); |
|
2302 | 2302 | break; |
2303 | 2303 | |
2304 | 2304 | case 'trialing' : |
2305 | - $status_label = __( 'Trialing', 'invoicing' ); |
|
2305 | + $status_label = __('Trialing', 'invoicing'); |
|
2306 | 2306 | break; |
2307 | 2307 | |
2308 | 2308 | default: |
@@ -2313,15 +2313,15 @@ discard block |
||
2313 | 2313 | return $status_label; |
2314 | 2314 | } |
2315 | 2315 | |
2316 | - public function get_subscription_period( $full = false ) { |
|
2317 | - $period = $this->get_meta( '_wpinv_subscr_period', true ); |
|
2316 | + public function get_subscription_period($full = false) { |
|
2317 | + $period = $this->get_meta('_wpinv_subscr_period', true); |
|
2318 | 2318 | |
2319 | - if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) { |
|
2319 | + if (!in_array($period, array('D', 'W', 'M', 'Y'))) { |
|
2320 | 2320 | $period = 'D'; |
2321 | 2321 | } |
2322 | 2322 | |
2323 | - if ( $full ) { |
|
2324 | - switch( $period ) { |
|
2323 | + if ($full) { |
|
2324 | + switch ($period) { |
|
2325 | 2325 | case 'D': |
2326 | 2326 | $period = 'day'; |
2327 | 2327 | break; |
@@ -2341,28 +2341,28 @@ discard block |
||
2341 | 2341 | } |
2342 | 2342 | |
2343 | 2343 | public function get_subscription_interval() { |
2344 | - $interval = (int)$this->get_meta( '_wpinv_subscr_interval', true ); |
|
2344 | + $interval = (int)$this->get_meta('_wpinv_subscr_interval', true); |
|
2345 | 2345 | |
2346 | - if ( !$interval > 0 ) { |
|
2346 | + if (!$interval > 0) { |
|
2347 | 2347 | $interval = 1; |
2348 | 2348 | } |
2349 | 2349 | |
2350 | 2350 | return $interval; |
2351 | 2351 | } |
2352 | 2352 | |
2353 | - public function get_subscription_trial_period( $full = false ) { |
|
2354 | - if ( !$this->is_free_trial() ) { |
|
2353 | + public function get_subscription_trial_period($full = false) { |
|
2354 | + if (!$this->is_free_trial()) { |
|
2355 | 2355 | return ''; |
2356 | 2356 | } |
2357 | 2357 | |
2358 | - $period = $this->get_meta( '_wpinv_subscr_trial_period', true ); |
|
2358 | + $period = $this->get_meta('_wpinv_subscr_trial_period', true); |
|
2359 | 2359 | |
2360 | - if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) { |
|
2360 | + if (!in_array($period, array('D', 'W', 'M', 'Y'))) { |
|
2361 | 2361 | $period = 'D'; |
2362 | 2362 | } |
2363 | 2363 | |
2364 | - if ( $full ) { |
|
2365 | - switch( $period ) { |
|
2364 | + if ($full) { |
|
2365 | + switch ($period) { |
|
2366 | 2366 | case 'D': |
2367 | 2367 | $period = 'day'; |
2368 | 2368 | break; |
@@ -2382,13 +2382,13 @@ discard block |
||
2382 | 2382 | } |
2383 | 2383 | |
2384 | 2384 | public function get_subscription_trial_interval() { |
2385 | - if ( !$this->is_free_trial() ) { |
|
2385 | + if (!$this->is_free_trial()) { |
|
2386 | 2386 | return 0; |
2387 | 2387 | } |
2388 | 2388 | |
2389 | - $interval = (int)$this->get_meta( '_wpinv_subscr_trial_interval', true ); |
|
2389 | + $interval = (int)$this->get_meta('_wpinv_subscr_trial_interval', true); |
|
2390 | 2390 | |
2391 | - if ( !$interval > 0 ) { |
|
2391 | + if (!$interval > 0) { |
|
2392 | 2392 | $interval = 1; |
2393 | 2393 | } |
2394 | 2394 | |
@@ -2400,8 +2400,8 @@ discard block |
||
2400 | 2400 | 'status' => 'failing' |
2401 | 2401 | ); |
2402 | 2402 | |
2403 | - if ( $this->update_subscription( $args ) ) { |
|
2404 | - do_action( 'wpinv_subscription_failing', $this->ID, $this ); |
|
2403 | + if ($this->update_subscription($args)) { |
|
2404 | + do_action('wpinv_subscription_failing', $this->ID, $this); |
|
2405 | 2405 | return true; |
2406 | 2406 | } |
2407 | 2407 | |
@@ -2413,8 +2413,8 @@ discard block |
||
2413 | 2413 | 'status' => 'stopped' |
2414 | 2414 | ); |
2415 | 2415 | |
2416 | - if ( $this->update_subscription( $args ) ) { |
|
2417 | - do_action( 'wpinv_subscription_stopped', $this->ID, $this ); |
|
2416 | + if ($this->update_subscription($args)) { |
|
2417 | + do_action('wpinv_subscription_stopped', $this->ID, $this); |
|
2418 | 2418 | return true; |
2419 | 2419 | } |
2420 | 2420 | |
@@ -2426,8 +2426,8 @@ discard block |
||
2426 | 2426 | 'status' => 'active' |
2427 | 2427 | ); |
2428 | 2428 | |
2429 | - if ( $this->update_subscription( $args ) ) { |
|
2430 | - do_action( 'wpinv_subscription_restarted', $this->ID, $this ); |
|
2429 | + if ($this->update_subscription($args)) { |
|
2430 | + do_action('wpinv_subscription_restarted', $this->ID, $this); |
|
2431 | 2431 | return true; |
2432 | 2432 | } |
2433 | 2433 | |
@@ -2439,23 +2439,23 @@ discard block |
||
2439 | 2439 | 'status' => 'cancelled' |
2440 | 2440 | ); |
2441 | 2441 | |
2442 | - if ( $this->update_subscription( $args ) ) { |
|
2443 | - if ( is_user_logged_in() ) { |
|
2444 | - $userdata = get_userdata( get_current_user_id() ); |
|
2442 | + if ($this->update_subscription($args)) { |
|
2443 | + if (is_user_logged_in()) { |
|
2444 | + $userdata = get_userdata(get_current_user_id()); |
|
2445 | 2445 | $user = $userdata->user_login; |
2446 | 2446 | } else { |
2447 | - $user = __( 'gateway', 'invoicing' ); |
|
2447 | + $user = __('gateway', 'invoicing'); |
|
2448 | 2448 | } |
2449 | 2449 | |
2450 | 2450 | $subscription_id = $this->get_subscription_id(); |
2451 | - if ( !$subscription_id ) { |
|
2451 | + if (!$subscription_id) { |
|
2452 | 2452 | $subscription_id = $this->ID; |
2453 | 2453 | } |
2454 | 2454 | |
2455 | - $note = sprintf( __( 'Subscription %s has been cancelled by %s', 'invoicing' ), $subscription_id, $user ); |
|
2456 | - $this->add_note( $note ); |
|
2455 | + $note = sprintf(__('Subscription %s has been cancelled by %s', 'invoicing'), $subscription_id, $user); |
|
2456 | + $this->add_note($note); |
|
2457 | 2457 | |
2458 | - do_action( 'wpinv_subscription_cancelled', $this->ID, $this ); |
|
2458 | + do_action('wpinv_subscription_cancelled', $this->ID, $this); |
|
2459 | 2459 | return true; |
2460 | 2460 | } |
2461 | 2461 | |
@@ -2463,11 +2463,11 @@ discard block |
||
2463 | 2463 | } |
2464 | 2464 | |
2465 | 2465 | public function can_cancel() { |
2466 | - return apply_filters( 'wpinv_subscription_can_cancel', false, $this ); |
|
2466 | + return apply_filters('wpinv_subscription_can_cancel', false, $this); |
|
2467 | 2467 | } |
2468 | 2468 | |
2469 | - public function add_subscription( $data = array() ) { |
|
2470 | - if ( empty( $this->ID ) ) { |
|
2469 | + public function add_subscription($data = array()) { |
|
2470 | + if (empty($this->ID)) { |
|
2471 | 2471 | return false; |
2472 | 2472 | } |
2473 | 2473 | |
@@ -2486,85 +2486,85 @@ discard block |
||
2486 | 2486 | 'profile_id' => '', |
2487 | 2487 | ); |
2488 | 2488 | |
2489 | - $args = wp_parse_args( $data, $defaults ); |
|
2489 | + $args = wp_parse_args($data, $defaults); |
|
2490 | 2490 | |
2491 | - if ( $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) { |
|
2492 | - if ( 'active' == $args['status'] || $args['status'] == 'trialing' ) { |
|
2491 | + if ($args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) { |
|
2492 | + if ('active' == $args['status'] || $args['status'] == 'trialing') { |
|
2493 | 2493 | $args['status'] = 'expired'; |
2494 | 2494 | } |
2495 | 2495 | } |
2496 | 2496 | |
2497 | - do_action( 'wpinv_subscription_pre_create', $args, $data, $this ); |
|
2497 | + do_action('wpinv_subscription_pre_create', $args, $data, $this); |
|
2498 | 2498 | |
2499 | - if ( !empty( $args ) ) { |
|
2500 | - foreach ( $args as $key => $value ) { |
|
2501 | - $this->update_meta( '_wpinv_subscr_' . $key, $value ); |
|
2499 | + if (!empty($args)) { |
|
2500 | + foreach ($args as $key => $value) { |
|
2501 | + $this->update_meta('_wpinv_subscr_' . $key, $value); |
|
2502 | 2502 | } |
2503 | 2503 | } |
2504 | 2504 | |
2505 | - do_action( 'wpinv_subscription_post_create', $args, $data, $this ); |
|
2505 | + do_action('wpinv_subscription_post_create', $args, $data, $this); |
|
2506 | 2506 | |
2507 | 2507 | return true; |
2508 | 2508 | } |
2509 | 2509 | |
2510 | - public function update_subscription( $args = array() ) { |
|
2511 | - if ( empty( $this->ID ) ) { |
|
2510 | + public function update_subscription($args = array()) { |
|
2511 | + if (empty($this->ID)) { |
|
2512 | 2512 | return false; |
2513 | 2513 | } |
2514 | 2514 | |
2515 | - if ( !empty( $args['expiration'] ) && $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) { |
|
2516 | - if ( !isset( $args['status'] ) || ( isset( $args['status'] ) && ( 'active' == $args['status'] || $args['status'] == 'trialing' ) ) ) { |
|
2515 | + if (!empty($args['expiration']) && $args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) { |
|
2516 | + if (!isset($args['status']) || (isset($args['status']) && ('active' == $args['status'] || $args['status'] == 'trialing'))) { |
|
2517 | 2517 | $args['status'] = 'expired'; |
2518 | 2518 | } |
2519 | 2519 | } |
2520 | 2520 | |
2521 | - if ( isset( $args['status'] ) && $args['status'] == 'cancelled' && empty( $args['cancelled_on'] ) ) { |
|
2522 | - $args['cancelled_on'] = date_i18n( 'Y-m-d H:i:s', current_time( 'timestamp' ) ); |
|
2521 | + if (isset($args['status']) && $args['status'] == 'cancelled' && empty($args['cancelled_on'])) { |
|
2522 | + $args['cancelled_on'] = date_i18n('Y-m-d H:i:s', current_time('timestamp')); |
|
2523 | 2523 | } |
2524 | 2524 | |
2525 | - do_action( 'wpinv_subscription_pre_update', $args, $this ); |
|
2525 | + do_action('wpinv_subscription_pre_update', $args, $this); |
|
2526 | 2526 | |
2527 | - if ( !empty( $args ) ) { |
|
2528 | - foreach ( $args as $key => $value ) { |
|
2529 | - $this->update_meta( '_wpinv_subscr_' . $key, $value ); |
|
2527 | + if (!empty($args)) { |
|
2528 | + foreach ($args as $key => $value) { |
|
2529 | + $this->update_meta('_wpinv_subscr_' . $key, $value); |
|
2530 | 2530 | } |
2531 | 2531 | } |
2532 | 2532 | |
2533 | - do_action( 'wpinv_subscription_post_update', $args, $this ); |
|
2533 | + do_action('wpinv_subscription_post_update', $args, $this); |
|
2534 | 2534 | |
2535 | 2535 | return true; |
2536 | 2536 | } |
2537 | 2537 | |
2538 | 2538 | public function renew_subscription() { |
2539 | 2539 | $parent_invoice = $this->get_parent_payment(); |
2540 | - $parent_invoice = empty( $parent_invoice ) ? $this : $parent_invoice; |
|
2540 | + $parent_invoice = empty($parent_invoice) ? $this : $parent_invoice; |
|
2541 | 2541 | |
2542 | - $current_time = current_time( 'timestamp' ); |
|
2542 | + $current_time = current_time('timestamp'); |
|
2543 | 2543 | $start = $this->get_subscription_created(); |
2544 | - $start = $start ? strtotime( $start ) : $current_time; |
|
2544 | + $start = $start ? strtotime($start) : $current_time; |
|
2545 | 2545 | $expires = $this->get_expiration_time(); |
2546 | 2546 | |
2547 | - if ( !$expires ) { |
|
2548 | - $expires = strtotime( '+' . $parent_invoice->get_subscription_interval() . ' ' . $parent_invoice->get_subscription_period( true ), $start ); |
|
2547 | + if (!$expires) { |
|
2548 | + $expires = strtotime('+' . $parent_invoice->get_subscription_interval() . ' ' . $parent_invoice->get_subscription_period(true), $start); |
|
2549 | 2549 | } |
2550 | 2550 | |
2551 | - $expiration = date_i18n( 'Y-m-d 23:59:59', $expires ); |
|
2552 | - $expiration = apply_filters( 'wpinv_subscription_renewal_expiration', $expiration, $this->ID, $this ); |
|
2551 | + $expiration = date_i18n('Y-m-d 23:59:59', $expires); |
|
2552 | + $expiration = apply_filters('wpinv_subscription_renewal_expiration', $expiration, $this->ID, $this); |
|
2553 | 2553 | $bill_times = $parent_invoice->get_bill_times(); |
2554 | 2554 | $times_billed = $parent_invoice->get_total_payments(); |
2555 | 2555 | |
2556 | - if ( $parent_invoice->get_subscription_status() == 'trialing' && ( $times_billed > 0 || strtotime( date_i18n( 'Y-m-d' ) ) < strtotime( $parent_invoice->get_trial_end_date( false ) ) ) ) { |
|
2556 | + if ($parent_invoice->get_subscription_status() == 'trialing' && ($times_billed > 0 || strtotime(date_i18n('Y-m-d')) < strtotime($parent_invoice->get_trial_end_date(false)))) { |
|
2557 | 2557 | $args = array( |
2558 | 2558 | 'status' => 'active', |
2559 | 2559 | ); |
2560 | 2560 | |
2561 | - $parent_invoice->update_subscription( $args ); |
|
2561 | + $parent_invoice->update_subscription($args); |
|
2562 | 2562 | } |
2563 | 2563 | |
2564 | - do_action( 'wpinv_subscription_pre_renew', $this->ID, $expiration, $this ); |
|
2564 | + do_action('wpinv_subscription_pre_renew', $this->ID, $expiration, $this); |
|
2565 | 2565 | |
2566 | - $status = 'active'; |
|
2567 | - if ( $bill_times > 0 && $times_billed >= $bill_times ) { |
|
2566 | + $status = 'active'; |
|
2567 | + if ($bill_times > 0 && $times_billed >= $bill_times) { |
|
2568 | 2568 | $this->complete_subscription(); |
2569 | 2569 | $status = 'completed'; |
2570 | 2570 | } |
@@ -2574,10 +2574,10 @@ discard block |
||
2574 | 2574 | 'status' => $status, |
2575 | 2575 | ); |
2576 | 2576 | |
2577 | - $this->update_subscription( $args ); |
|
2577 | + $this->update_subscription($args); |
|
2578 | 2578 | |
2579 | - do_action( 'wpinv_subscription_post_renew', $this->ID, $expiration, $this ); |
|
2580 | - do_action( 'wpinv_recurring_set_subscription_status', $this->ID, $status, $this ); |
|
2579 | + do_action('wpinv_subscription_post_renew', $this->ID, $expiration, $this); |
|
2580 | + do_action('wpinv_recurring_set_subscription_status', $this->ID, $status, $this); |
|
2581 | 2581 | } |
2582 | 2582 | |
2583 | 2583 | public function complete_subscription() { |
@@ -2585,8 +2585,8 @@ discard block |
||
2585 | 2585 | 'status' => 'completed' |
2586 | 2586 | ); |
2587 | 2587 | |
2588 | - if ( $this->update_subscription( $args ) ) { |
|
2589 | - do_action( 'wpinv_subscription_completed', $this->ID, $this ); |
|
2588 | + if ($this->update_subscription($args)) { |
|
2589 | + do_action('wpinv_subscription_completed', $this->ID, $this); |
|
2590 | 2590 | } |
2591 | 2591 | } |
2592 | 2592 | |
@@ -2595,44 +2595,44 @@ discard block |
||
2595 | 2595 | 'status' => 'expired' |
2596 | 2596 | ); |
2597 | 2597 | |
2598 | - if ( $this->update_subscription( $args ) ) { |
|
2599 | - do_action( 'wpinv_subscription_expired', $this->ID, $this ); |
|
2598 | + if ($this->update_subscription($args)) { |
|
2599 | + do_action('wpinv_subscription_expired', $this->ID, $this); |
|
2600 | 2600 | } |
2601 | 2601 | } |
2602 | 2602 | |
2603 | 2603 | public function get_cancel_url() { |
2604 | - $url = wp_nonce_url( add_query_arg( array( 'wpi_action' => 'cancel_subscription', 'sub_id' => $this->ID ) ), 'wpinv-recurring-cancel' ); |
|
2604 | + $url = wp_nonce_url(add_query_arg(array('wpi_action' => 'cancel_subscription', 'sub_id' => $this->ID)), 'wpinv-recurring-cancel'); |
|
2605 | 2605 | |
2606 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
2606 | + return apply_filters('wpinv_subscription_cancel_url', $url, $this); |
|
2607 | 2607 | } |
2608 | 2608 | |
2609 | 2609 | public function can_update() { |
2610 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
2610 | + return apply_filters('wpinv_subscription_can_update', false, $this); |
|
2611 | 2611 | } |
2612 | 2612 | |
2613 | 2613 | public function get_update_url() { |
2614 | - $url = add_query_arg( array( 'action' => 'update', 'sub_id' => $this->ID ) ); |
|
2614 | + $url = add_query_arg(array('action' => 'update', 'sub_id' => $this->ID)); |
|
2615 | 2615 | |
2616 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
2616 | + return apply_filters('wpinv_subscription_update_url', $url, $this); |
|
2617 | 2617 | } |
2618 | 2618 | |
2619 | 2619 | public function is_parent() { |
2620 | - $is_parent = empty( $this->parent_invoice ) ? true : false; |
|
2620 | + $is_parent = empty($this->parent_invoice) ? true : false; |
|
2621 | 2621 | |
2622 | - return apply_filters( 'wpinv_invoice_is_parent', $is_parent, $this ); |
|
2622 | + return apply_filters('wpinv_invoice_is_parent', $is_parent, $this); |
|
2623 | 2623 | } |
2624 | 2624 | |
2625 | 2625 | public function is_renewal() { |
2626 | 2626 | $is_renewal = $this->parent_invoice && $this->parent_invoice != $this->ID ? true : false; |
2627 | 2627 | |
2628 | - return apply_filters( 'wpinv_invoice_is_renewal', $is_renewal, $this ); |
|
2628 | + return apply_filters('wpinv_invoice_is_renewal', $is_renewal, $this); |
|
2629 | 2629 | } |
2630 | 2630 | |
2631 | 2631 | public function get_parent_payment() { |
2632 | 2632 | $parent_payment = NULL; |
2633 | 2633 | |
2634 | - if ( $this->is_renewal() ) { |
|
2635 | - $parent_payment = wpinv_get_invoice( $this->parent_invoice ); |
|
2634 | + if ($this->is_renewal()) { |
|
2635 | + $parent_payment = wpinv_get_invoice($this->parent_invoice); |
|
2636 | 2636 | } |
2637 | 2637 | |
2638 | 2638 | return $parent_payment; |
@@ -2643,100 +2643,100 @@ discard block |
||
2643 | 2643 | |
2644 | 2644 | $subscription_status = $this->get_subscription_status(); |
2645 | 2645 | |
2646 | - if( ! $this->is_subscription_expired() && ( $subscription_status == 'active' || $subscription_status == 'cancelled' || $subscription_status == 'trialing' ) ) { |
|
2646 | + if (!$this->is_subscription_expired() && ($subscription_status == 'active' || $subscription_status == 'cancelled' || $subscription_status == 'trialing')) { |
|
2647 | 2647 | $ret = true; |
2648 | 2648 | } |
2649 | 2649 | |
2650 | - return apply_filters( 'wpinv_subscription_is_active', $ret, $this->ID, $this ); |
|
2650 | + return apply_filters('wpinv_subscription_is_active', $ret, $this->ID, $this); |
|
2651 | 2651 | } |
2652 | 2652 | |
2653 | 2653 | public function is_subscription_expired() { |
2654 | 2654 | $ret = false; |
2655 | 2655 | $subscription_status = $this->get_subscription_status(); |
2656 | 2656 | |
2657 | - if ( $subscription_status == 'expired' ) { |
|
2657 | + if ($subscription_status == 'expired') { |
|
2658 | 2658 | $ret = true; |
2659 | - } else if ( 'active' === $subscription_status || 'cancelled' === $subscription_status || 'trialing' == $subscription_status ) { |
|
2659 | + } else if ('active' === $subscription_status || 'cancelled' === $subscription_status || 'trialing' == $subscription_status) { |
|
2660 | 2660 | $ret = false; |
2661 | 2661 | $expiration = $this->get_expiration_time(); |
2662 | 2662 | |
2663 | - if ( $expiration && strtotime( 'NOW', current_time( 'timestamp' ) ) > $expiration ) { |
|
2663 | + if ($expiration && strtotime('NOW', current_time('timestamp')) > $expiration) { |
|
2664 | 2664 | $ret = true; |
2665 | 2665 | |
2666 | - if ( 'active' === $subscription_status || 'trialing' === $subscription_status ) { |
|
2666 | + if ('active' === $subscription_status || 'trialing' === $subscription_status) { |
|
2667 | 2667 | $this->expire_subscription(); |
2668 | 2668 | } |
2669 | 2669 | } |
2670 | 2670 | } |
2671 | 2671 | |
2672 | - return apply_filters( 'wpinv_subscription_is_expired', $ret, $this->ID, $this ); |
|
2672 | + return apply_filters('wpinv_subscription_is_expired', $ret, $this->ID, $this); |
|
2673 | 2673 | } |
2674 | 2674 | |
2675 | - public function get_new_expiration( $item_id = 0, $trial = true ) { |
|
2676 | - $item = new WPInv_Item( $item_id ); |
|
2675 | + public function get_new_expiration($item_id = 0, $trial = true) { |
|
2676 | + $item = new WPInv_Item($item_id); |
|
2677 | 2677 | $interval = $item->get_recurring_interval(); |
2678 | - $period = $item->get_recurring_period( true ); |
|
2678 | + $period = $item->get_recurring_period(true); |
|
2679 | 2679 | |
2680 | - $expiration_time = strtotime( '+' . $interval . ' ' . $period ); |
|
2680 | + $expiration_time = strtotime('+' . $interval . ' ' . $period); |
|
2681 | 2681 | |
2682 | - if ( $trial && $this->is_free_trial() && $item->has_free_trial() ) { |
|
2683 | - $expiration_time += ( wpinv_period_in_days( $item->get_trial_interval(), $item->get_trial_period() ) * DAY_IN_SECONDS ) ; |
|
2682 | + if ($trial && $this->is_free_trial() && $item->has_free_trial()) { |
|
2683 | + $expiration_time += (wpinv_period_in_days($item->get_trial_interval(), $item->get_trial_period()) * DAY_IN_SECONDS); |
|
2684 | 2684 | } |
2685 | 2685 | |
2686 | - return date_i18n( 'Y-m-d 23:59:59', $expiration_time ); |
|
2686 | + return date_i18n('Y-m-d 23:59:59', $expiration_time); |
|
2687 | 2687 | } |
2688 | 2688 | |
2689 | - public function get_subscription_data( $filed = '' ) { |
|
2690 | - $fields = array( 'item_id', 'status', 'period', 'initial_amount', 'recurring_amount', 'interval', 'bill_times', 'trial_period', 'trial_interval', 'expiration', 'profile_id', 'created', 'cancelled_on' ); |
|
2689 | + public function get_subscription_data($filed = '') { |
|
2690 | + $fields = array('item_id', 'status', 'period', 'initial_amount', 'recurring_amount', 'interval', 'bill_times', 'trial_period', 'trial_interval', 'expiration', 'profile_id', 'created', 'cancelled_on'); |
|
2691 | 2691 | |
2692 | 2692 | $subscription_meta = array(); |
2693 | - foreach ( $fields as $field ) { |
|
2694 | - $subscription_meta[ $field ] = $this->get_meta( '_wpinv_subscr_' . $field ); |
|
2693 | + foreach ($fields as $field) { |
|
2694 | + $subscription_meta[$field] = $this->get_meta('_wpinv_subscr_' . $field); |
|
2695 | 2695 | } |
2696 | 2696 | |
2697 | - $item = $this->get_recurring( true ); |
|
2697 | + $item = $this->get_recurring(true); |
|
2698 | 2698 | |
2699 | - if ( !empty( $item ) ) { |
|
2700 | - if ( empty( $subscription_meta['item_id'] ) ) { |
|
2699 | + if (!empty($item)) { |
|
2700 | + if (empty($subscription_meta['item_id'])) { |
|
2701 | 2701 | $subscription_meta['item_id'] = $item->ID; |
2702 | 2702 | } |
2703 | - if ( empty( $subscription_meta['period'] ) ) { |
|
2703 | + if (empty($subscription_meta['period'])) { |
|
2704 | 2704 | $subscription_meta['period'] = $item->get_recurring_period(); |
2705 | 2705 | } |
2706 | - if ( empty( $subscription_meta['interval'] ) ) { |
|
2706 | + if (empty($subscription_meta['interval'])) { |
|
2707 | 2707 | $subscription_meta['interval'] = $item->get_recurring_interval(); |
2708 | 2708 | } |
2709 | - if ( $item->has_free_trial() ) { |
|
2710 | - if ( empty( $subscription_meta['trial_period'] ) ) { |
|
2709 | + if ($item->has_free_trial()) { |
|
2710 | + if (empty($subscription_meta['trial_period'])) { |
|
2711 | 2711 | $subscription_meta['trial_period'] = $item->get_trial_period(); |
2712 | 2712 | } |
2713 | - if ( empty( $subscription_meta['trial_interval'] ) ) { |
|
2713 | + if (empty($subscription_meta['trial_interval'])) { |
|
2714 | 2714 | $subscription_meta['trial_interval'] = $item->get_trial_interval(); |
2715 | 2715 | } |
2716 | 2716 | } else { |
2717 | 2717 | $subscription_meta['trial_period'] = ''; |
2718 | 2718 | $subscription_meta['trial_interval'] = 0; |
2719 | 2719 | } |
2720 | - if ( !$subscription_meta['bill_times'] && $subscription_meta['bill_times'] !== 0 ) { |
|
2720 | + if (!$subscription_meta['bill_times'] && $subscription_meta['bill_times'] !== 0) { |
|
2721 | 2721 | $subscription_meta['bill_times'] = $item->get_recurring_limit(); |
2722 | 2722 | } |
2723 | - if ( $subscription_meta['initial_amount'] === '' || $subscription_meta['recurring_amount'] === '' ) { |
|
2724 | - $subscription_meta['initial_amount'] = wpinv_format_amount( $this->get_total() ); |
|
2725 | - $subscription_meta['recurring_amount'] = wpinv_format_amount( $this->get_recurring_details( 'total' ) ); |
|
2723 | + if ($subscription_meta['initial_amount'] === '' || $subscription_meta['recurring_amount'] === '') { |
|
2724 | + $subscription_meta['initial_amount'] = wpinv_format_amount($this->get_total()); |
|
2725 | + $subscription_meta['recurring_amount'] = wpinv_format_amount($this->get_recurring_details('total')); |
|
2726 | 2726 | } |
2727 | 2727 | } |
2728 | 2728 | |
2729 | - if ( $filed === '' ) { |
|
2730 | - return apply_filters( 'wpinv_get_invoice_subscription_data', $subscription_meta, $this ); |
|
2729 | + if ($filed === '') { |
|
2730 | + return apply_filters('wpinv_get_invoice_subscription_data', $subscription_meta, $this); |
|
2731 | 2731 | } |
2732 | 2732 | |
2733 | - $value = isset( $subscription_meta[$filed] ) ? $subscription_meta[$filed] : ''; |
|
2733 | + $value = isset($subscription_meta[$filed]) ? $subscription_meta[$filed] : ''; |
|
2734 | 2734 | |
2735 | - return apply_filters( 'wpinv_invoice_subscription_data_value', $value, $subscription_meta, $this ); |
|
2735 | + return apply_filters('wpinv_invoice_subscription_data_value', $value, $subscription_meta, $this); |
|
2736 | 2736 | } |
2737 | 2737 | |
2738 | 2738 | public function is_paid() { |
2739 | - if ( $this->has_status( array( 'publish', 'complete', 'processing', 'renewal' ) ) ) { |
|
2739 | + if ($this->has_status(array('publish', 'complete', 'processing', 'renewal'))) { |
|
2740 | 2740 | return true; |
2741 | 2741 | } |
2742 | 2742 | |
@@ -2748,28 +2748,28 @@ discard block |
||
2748 | 2748 | |
2749 | 2749 | $requires_vat = false; |
2750 | 2750 | |
2751 | - if ( $this->country ) { |
|
2751 | + if ($this->country) { |
|
2752 | 2752 | $wpi_country = $this->country; |
2753 | 2753 | |
2754 | - $requires_vat = $wpinv_euvat->requires_vat( $requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule( $this ) ); |
|
2754 | + $requires_vat = $wpinv_euvat->requires_vat($requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule($this)); |
|
2755 | 2755 | } |
2756 | 2756 | |
2757 | - return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this ); |
|
2757 | + return apply_filters('wpinv_invoice_has_vat', $requires_vat, $this); |
|
2758 | 2758 | } |
2759 | 2759 | |
2760 | 2760 | public function refresh_item_ids() { |
2761 | 2761 | $item_ids = array(); |
2762 | 2762 | |
2763 | - if ( !empty( $this->cart_details ) ) { |
|
2764 | - foreach ( $this->cart_details as $key => $item ) { |
|
2765 | - if ( !empty( $item['id'] ) ) { |
|
2763 | + if (!empty($this->cart_details)) { |
|
2764 | + foreach ($this->cart_details as $key => $item) { |
|
2765 | + if (!empty($item['id'])) { |
|
2766 | 2766 | $item_ids[] = $item['id']; |
2767 | 2767 | } |
2768 | 2768 | } |
2769 | 2769 | } |
2770 | 2770 | |
2771 | - $item_ids = !empty( $item_ids ) ? implode( ',', array_unique( $item_ids ) ) : ''; |
|
2771 | + $item_ids = !empty($item_ids) ? implode(',', array_unique($item_ids)) : ''; |
|
2772 | 2772 | |
2773 | - update_post_meta( $this->ID, '_wpinv_item_ids', $item_ids ); |
|
2773 | + update_post_meta($this->ID, '_wpinv_item_ids', $item_ids); |
|
2774 | 2774 | } |
2775 | 2775 | } |
@@ -1,66 +1,66 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // MUST have WordPress. |
3 | -if ( !defined( 'WPINC' ) ) { |
|
4 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
3 | +if (!defined('WPINC')) { |
|
4 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
5 | 5 | } |
6 | 6 | |
7 | -add_action( 'admin_menu', 'wpinv_add_options_link', 10 ); |
|
7 | +add_action('admin_menu', 'wpinv_add_options_link', 10); |
|
8 | 8 | function wpinv_add_options_link() { |
9 | 9 | global $menu; |
10 | 10 | |
11 | - if ( current_user_can( 'manage_options' ) ) { |
|
12 | - $menu[] = array( '', 'read', 'separator-wpinv', '', 'wp-menu-separator wpinv' ); |
|
11 | + if (current_user_can('manage_options')) { |
|
12 | + $menu[] = array('', 'read', 'separator-wpinv', '', 'wp-menu-separator wpinv'); |
|
13 | 13 | } |
14 | 14 | |
15 | - $wpi_invoice = get_post_type_object( 'wpi_invoice' ); |
|
15 | + $wpi_invoice = get_post_type_object('wpi_invoice'); |
|
16 | 16 | |
17 | - add_menu_page( __( 'Invoicing', 'invoicing' ), __( 'Invoicing', 'invoicing' ), 'manage_options', 'wpinv', null, $wpi_invoice->menu_icon, '54.123460' ); |
|
17 | + add_menu_page(__('Invoicing', 'invoicing'), __('Invoicing', 'invoicing'), 'manage_options', 'wpinv', null, $wpi_invoice->menu_icon, '54.123460'); |
|
18 | 18 | |
19 | - $wpi_settings_page = add_submenu_page( 'wpinv', __( 'Invoice Settings', 'invoicing' ), __( 'Settings', 'invoicing' ), 'manage_options', 'wpinv-settings', 'wpinv_options_page' ); |
|
19 | + $wpi_settings_page = add_submenu_page('wpinv', __('Invoice Settings', 'invoicing'), __('Settings', 'invoicing'), 'manage_options', 'wpinv-settings', 'wpinv_options_page'); |
|
20 | 20 | } |
21 | 21 | |
22 | -add_action( 'admin_menu', 'wpinv_remove_admin_submenus', 999 ); |
|
22 | +add_action('admin_menu', 'wpinv_remove_admin_submenus', 999); |
|
23 | 23 | function wpinv_remove_admin_submenus() { |
24 | - remove_submenu_page( 'edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice' ); |
|
24 | + remove_submenu_page('edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice'); |
|
25 | 25 | } |
26 | 26 | |
27 | -add_filter( 'manage_wpi_discount_posts_columns', 'wpinv_discount_columns' ); |
|
28 | -function wpinv_discount_columns( $existing_columns ) { |
|
27 | +add_filter('manage_wpi_discount_posts_columns', 'wpinv_discount_columns'); |
|
28 | +function wpinv_discount_columns($existing_columns) { |
|
29 | 29 | $columns = array(); |
30 | 30 | $columns['cb'] = $existing_columns['cb']; |
31 | - $columns['name'] = __( 'Name', 'invoicing' ); |
|
32 | - $columns['code'] = __( 'Code', 'invoicing' ); |
|
33 | - $columns['amount'] = __( 'Amount', 'invoicing' ); |
|
34 | - $columns['usage'] = __( 'Usage / Limit', 'invoicing' ); |
|
35 | - $columns['expiry_date'] = __( 'Expiry Date', 'invoicing' ); |
|
36 | - $columns['status'] = __( 'Status', 'invoicing' ); |
|
31 | + $columns['name'] = __('Name', 'invoicing'); |
|
32 | + $columns['code'] = __('Code', 'invoicing'); |
|
33 | + $columns['amount'] = __('Amount', 'invoicing'); |
|
34 | + $columns['usage'] = __('Usage / Limit', 'invoicing'); |
|
35 | + $columns['expiry_date'] = __('Expiry Date', 'invoicing'); |
|
36 | + $columns['status'] = __('Status', 'invoicing'); |
|
37 | 37 | |
38 | 38 | return $columns; |
39 | 39 | } |
40 | 40 | |
41 | -add_action( 'manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column' ); |
|
42 | -function wpinv_discount_custom_column( $column ) { |
|
41 | +add_action('manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column'); |
|
42 | +function wpinv_discount_custom_column($column) { |
|
43 | 43 | global $post; |
44 | 44 | |
45 | 45 | $discount = $post; |
46 | 46 | |
47 | - switch ( $column ) { |
|
47 | + switch ($column) { |
|
48 | 48 | case 'name' : |
49 | - echo get_the_title( $discount->ID ); |
|
49 | + echo get_the_title($discount->ID); |
|
50 | 50 | break; |
51 | 51 | case 'code' : |
52 | - echo wpinv_get_discount_code( $discount->ID ); |
|
52 | + echo wpinv_get_discount_code($discount->ID); |
|
53 | 53 | break; |
54 | 54 | case 'amount' : |
55 | - echo wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) ); |
|
55 | + echo wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID)); |
|
56 | 56 | break; |
57 | 57 | case 'usage_limit' : |
58 | - echo wpinv_get_discount_uses( $discount->ID ); |
|
58 | + echo wpinv_get_discount_uses($discount->ID); |
|
59 | 59 | break; |
60 | 60 | case 'usage' : |
61 | - $usage = wpinv_get_discount_uses( $discount->ID ) . ' / '; |
|
62 | - if ( wpinv_get_discount_max_uses( $discount->ID ) ) { |
|
63 | - $usage .= wpinv_get_discount_max_uses( $discount->ID ); |
|
61 | + $usage = wpinv_get_discount_uses($discount->ID) . ' / '; |
|
62 | + if (wpinv_get_discount_max_uses($discount->ID)) { |
|
63 | + $usage .= wpinv_get_discount_max_uses($discount->ID); |
|
64 | 64 | } else { |
65 | 65 | $usage .= ' ∞'; |
66 | 66 | } |
@@ -68,162 +68,162 @@ discard block |
||
68 | 68 | echo $usage; |
69 | 69 | break; |
70 | 70 | case 'expiry_date' : |
71 | - if ( wpinv_get_discount_expiration( $discount->ID ) ) { |
|
72 | - $expiration = date_i18n( get_option( 'date_format' ), strtotime( wpinv_get_discount_expiration( $discount->ID ) ) ); |
|
71 | + if (wpinv_get_discount_expiration($discount->ID)) { |
|
72 | + $expiration = date_i18n(get_option('date_format'), strtotime(wpinv_get_discount_expiration($discount->ID))); |
|
73 | 73 | } else { |
74 | - $expiration = __( 'Never', 'invoicing' ); |
|
74 | + $expiration = __('Never', 'invoicing'); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | echo $expiration; |
78 | 78 | break; |
79 | 79 | case 'description' : |
80 | - echo wp_kses_post( $post->post_excerpt ); |
|
80 | + echo wp_kses_post($post->post_excerpt); |
|
81 | 81 | break; |
82 | 82 | case 'status' : |
83 | - $status = wpinv_is_discount_expired( $discount->ID ) ? 'expired' : $discount->post_status; |
|
83 | + $status = wpinv_is_discount_expired($discount->ID) ? 'expired' : $discount->post_status; |
|
84 | 84 | |
85 | - echo wpinv_discount_status( $status ); |
|
85 | + echo wpinv_discount_status($status); |
|
86 | 86 | break; |
87 | 87 | } |
88 | 88 | } |
89 | 89 | |
90 | -add_filter( 'post_row_actions', 'wpinv_post_row_actions', 9999, 2 ); |
|
91 | -function wpinv_post_row_actions( $actions, $post ) { |
|
92 | - $post_type = !empty( $post->post_type ) ? $post->post_type : ''; |
|
90 | +add_filter('post_row_actions', 'wpinv_post_row_actions', 9999, 2); |
|
91 | +function wpinv_post_row_actions($actions, $post) { |
|
92 | + $post_type = !empty($post->post_type) ? $post->post_type : ''; |
|
93 | 93 | |
94 | - if ( $post_type == 'wpi_invoice' ) { |
|
94 | + if ($post_type == 'wpi_invoice') { |
|
95 | 95 | $actions = array(); |
96 | 96 | } |
97 | 97 | |
98 | - if ( $post_type == 'wpi_discount' ) { |
|
99 | - $actions = wpinv_discount_row_actions( $post, $actions ); |
|
98 | + if ($post_type == 'wpi_discount') { |
|
99 | + $actions = wpinv_discount_row_actions($post, $actions); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | return $actions; |
103 | 103 | } |
104 | 104 | |
105 | -function wpinv_discount_row_actions( $discount, $row_actions ) { |
|
106 | - $row_actions = array(); |
|
107 | - $edit_link = get_edit_post_link( $discount->ID ); |
|
108 | - $row_actions['edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'invoicing' ) . '</a>'; |
|
105 | +function wpinv_discount_row_actions($discount, $row_actions) { |
|
106 | + $row_actions = array(); |
|
107 | + $edit_link = get_edit_post_link($discount->ID); |
|
108 | + $row_actions['edit'] = '<a href="' . esc_url($edit_link) . '">' . __('Edit', 'invoicing') . '</a>'; |
|
109 | 109 | |
110 | - if( in_array( strtolower( $discount->post_status ), array( 'publish' ) ) ) { |
|
111 | - $row_actions['deactivate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'deactivate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Deactivate', 'invoicing' ) . '</a>'; |
|
112 | - } elseif( in_array( strtolower( $discount->post_status ), array( 'pending', 'draft' ) ) ) { |
|
113 | - $row_actions['activate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'activate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Activate', 'invoicing' ) . '</a>'; |
|
110 | + if (in_array(strtolower($discount->post_status), array('publish'))) { |
|
111 | + $row_actions['deactivate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'deactivate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Deactivate', 'invoicing') . '</a>'; |
|
112 | + } elseif (in_array(strtolower($discount->post_status), array('pending', 'draft'))) { |
|
113 | + $row_actions['activate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'activate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Activate', 'invoicing') . '</a>'; |
|
114 | 114 | } |
115 | 115 | |
116 | - if ( wpinv_get_discount_uses( $discount->ID ) > 0 ) { |
|
117 | - if ( isset( $row_actions['delete'] ) ) { |
|
118 | - unset( $row_actions['delete'] ); // Don't delete used discounts. |
|
116 | + if (wpinv_get_discount_uses($discount->ID) > 0) { |
|
117 | + if (isset($row_actions['delete'])) { |
|
118 | + unset($row_actions['delete']); // Don't delete used discounts. |
|
119 | 119 | } |
120 | 120 | } else { |
121 | - $row_actions['delete'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'delete_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Delete', 'invoicing' ) . '</a>'; |
|
121 | + $row_actions['delete'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'delete_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Delete', 'invoicing') . '</a>'; |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | |
125 | - $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount ); |
|
125 | + $row_actions = apply_filters('wpinv_discount_row_actions', $row_actions, $discount); |
|
126 | 126 | |
127 | 127 | return $row_actions; |
128 | 128 | } |
129 | 129 | |
130 | -add_filter( 'list_table_primary_column', 'wpinv_table_primary_column', 10, 2 ); |
|
131 | -function wpinv_table_primary_column( $default, $screen_id ) { |
|
132 | - if ( 'edit-wpi_invoice' === $screen_id ) { |
|
130 | +add_filter('list_table_primary_column', 'wpinv_table_primary_column', 10, 2); |
|
131 | +function wpinv_table_primary_column($default, $screen_id) { |
|
132 | + if ('edit-wpi_invoice' === $screen_id) { |
|
133 | 133 | return 'name'; |
134 | 134 | } |
135 | 135 | |
136 | 136 | return $default; |
137 | 137 | } |
138 | 138 | |
139 | -function wpinv_discount_bulk_actions( $actions, $display = false ) { |
|
140 | - if ( !$display ) { |
|
139 | +function wpinv_discount_bulk_actions($actions, $display = false) { |
|
140 | + if (!$display) { |
|
141 | 141 | return array(); |
142 | 142 | } |
143 | 143 | |
144 | 144 | $actions = array( |
145 | - 'activate' => __( 'Activate', 'invoicing' ), |
|
146 | - 'deactivate' => __( 'Deactivate', 'invoicing' ), |
|
147 | - 'delete' => __( 'Delete', 'invoicing' ), |
|
145 | + 'activate' => __('Activate', 'invoicing'), |
|
146 | + 'deactivate' => __('Deactivate', 'invoicing'), |
|
147 | + 'delete' => __('Delete', 'invoicing'), |
|
148 | 148 | ); |
149 | 149 | $two = ''; |
150 | 150 | $which = 'top'; |
151 | 151 | echo '</div><div class="alignleft actions bulkactions">'; |
152 | - echo '<label for="bulk-action-selector-' . esc_attr( $which ) . '" class="screen-reader-text">' . __( 'Select bulk action' ) . '</label>'; |
|
153 | - echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr( $which ) . "\">"; |
|
154 | - echo '<option value="-1">' . __( 'Bulk Actions' ) . "</option>"; |
|
152 | + echo '<label for="bulk-action-selector-' . esc_attr($which) . '" class="screen-reader-text">' . __('Select bulk action') . '</label>'; |
|
153 | + echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr($which) . "\">"; |
|
154 | + echo '<option value="-1">' . __('Bulk Actions') . "</option>"; |
|
155 | 155 | |
156 | - foreach ( $actions as $name => $title ) { |
|
156 | + foreach ($actions as $name => $title) { |
|
157 | 157 | $class = 'edit' === $name ? ' class="hide-if-no-js"' : ''; |
158 | 158 | |
159 | 159 | echo "" . '<option value="' . $name . '"' . $class . '>' . $title . "</option>"; |
160 | 160 | } |
161 | 161 | echo "</select>"; |
162 | 162 | |
163 | - submit_button( __( 'Apply' ), 'action', '', false, array( 'id' => "doaction$two" ) ); |
|
163 | + submit_button(__('Apply'), 'action', '', false, array('id' => "doaction$two")); |
|
164 | 164 | |
165 | 165 | echo '</div><div class="alignleft actions">'; |
166 | 166 | } |
167 | -add_filter( 'bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10 ); |
|
167 | +add_filter('bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10); |
|
168 | 168 | |
169 | -function wpinv_disable_months_dropdown( $disable, $post_type ) { |
|
170 | - if ( $post_type == 'wpi_discount' ) { |
|
169 | +function wpinv_disable_months_dropdown($disable, $post_type) { |
|
170 | + if ($post_type == 'wpi_discount') { |
|
171 | 171 | $disable = true; |
172 | 172 | } |
173 | 173 | |
174 | 174 | return $disable; |
175 | 175 | } |
176 | -add_filter( 'disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2 ); |
|
176 | +add_filter('disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2); |
|
177 | 177 | |
178 | 178 | function wpinv_restrict_manage_posts() { |
179 | 179 | global $typenow; |
180 | 180 | |
181 | - if( 'wpi_discount' == $typenow ) { |
|
181 | + if ('wpi_discount' == $typenow) { |
|
182 | 182 | wpinv_discount_filters(); |
183 | 183 | } |
184 | 184 | } |
185 | -add_action( 'restrict_manage_posts', 'wpinv_restrict_manage_posts', 10 ); |
|
185 | +add_action('restrict_manage_posts', 'wpinv_restrict_manage_posts', 10); |
|
186 | 186 | |
187 | 187 | function wpinv_discount_filters() { |
188 | - echo wpinv_discount_bulk_actions( array(), true ); |
|
188 | + echo wpinv_discount_bulk_actions(array(), true); |
|
189 | 189 | |
190 | 190 | ?> |
191 | 191 | <select name="discount_type" id="dropdown_wpinv_discount_type"> |
192 | - <option value=""><?php _e( 'Show all types', 'invoicing' ); ?></option> |
|
192 | + <option value=""><?php _e('Show all types', 'invoicing'); ?></option> |
|
193 | 193 | <?php |
194 | 194 | $types = wpinv_get_discount_types(); |
195 | 195 | |
196 | - foreach ( $types as $name => $type ) { |
|
197 | - echo '<option value="' . esc_attr( $name ) . '"'; |
|
196 | + foreach ($types as $name => $type) { |
|
197 | + echo '<option value="' . esc_attr($name) . '"'; |
|
198 | 198 | |
199 | - if ( isset( $_GET['discount_type'] ) ) |
|
200 | - selected( $name, $_GET['discount_type'] ); |
|
199 | + if (isset($_GET['discount_type'])) |
|
200 | + selected($name, $_GET['discount_type']); |
|
201 | 201 | |
202 | - echo '>' . esc_html__( $type, 'invoicing' ) . '</option>'; |
|
202 | + echo '>' . esc_html__($type, 'invoicing') . '</option>'; |
|
203 | 203 | } |
204 | 204 | ?> |
205 | 205 | </select> |
206 | 206 | <?php |
207 | 207 | } |
208 | 208 | |
209 | -function wpinv_request( $vars ) { |
|
209 | +function wpinv_request($vars) { |
|
210 | 210 | global $typenow, $wp_query, $wp_post_statuses; |
211 | 211 | |
212 | - if ( 'wpi_invoice' === $typenow or 'wpi_quote' === $typenow ) { |
|
213 | - if ( !isset( $vars['post_status'] ) ) { |
|
212 | + if ('wpi_invoice' === $typenow or 'wpi_quote' === $typenow) { |
|
213 | + if (!isset($vars['post_status'])) { |
|
214 | 214 | $post_statuses = wpinv_get_invoice_statuses(); |
215 | 215 | |
216 | - foreach ( $post_statuses as $status => $value ) { |
|
217 | - if ( isset( $wp_post_statuses[ $status ] ) && false === $wp_post_statuses[ $status ]->show_in_admin_all_list ) { |
|
218 | - unset( $post_statuses[ $status ] ); |
|
216 | + foreach ($post_statuses as $status => $value) { |
|
217 | + if (isset($wp_post_statuses[$status]) && false === $wp_post_statuses[$status]->show_in_admin_all_list) { |
|
218 | + unset($post_statuses[$status]); |
|
219 | 219 | } |
220 | 220 | } |
221 | 221 | |
222 | - $vars['post_status'] = array_keys( $post_statuses ); |
|
222 | + $vars['post_status'] = array_keys($post_statuses); |
|
223 | 223 | } |
224 | 224 | |
225 | - if ( isset( $vars['orderby'] ) ) { |
|
226 | - if ( 'amount' == $vars['orderby'] ) { |
|
225 | + if (isset($vars['orderby'])) { |
|
226 | + if ('amount' == $vars['orderby']) { |
|
227 | 227 | $vars = array_merge( |
228 | 228 | $vars, |
229 | 229 | array( |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | 'orderby' => 'meta_value_num' |
232 | 232 | ) |
233 | 233 | ); |
234 | - } else if ( 'customer' == $vars['orderby'] ) { |
|
234 | + } else if ('customer' == $vars['orderby']) { |
|
235 | 235 | $vars = array_merge( |
236 | 236 | $vars, |
237 | 237 | array( |
@@ -241,9 +241,9 @@ discard block |
||
241 | 241 | ); |
242 | 242 | } |
243 | 243 | } |
244 | - } else if ( 'wpi_item' == $typenow ) { |
|
244 | + } else if ('wpi_item' == $typenow) { |
|
245 | 245 | // Check if 'orderby' is set to "price" |
246 | - if ( isset( $vars['orderby'] ) && 'price' == $vars['orderby'] ) { |
|
246 | + if (isset($vars['orderby']) && 'price' == $vars['orderby']) { |
|
247 | 247 | $vars = array_merge( |
248 | 248 | $vars, |
249 | 249 | array( |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | } |
255 | 255 | |
256 | 256 | // Check if "orderby" is set to "vat_rule" |
257 | - if ( isset( $vars['orderby'] ) && 'vat_rule' == $vars['orderby'] ) { |
|
257 | + if (isset($vars['orderby']) && 'vat_rule' == $vars['orderby']) { |
|
258 | 258 | $vars = array_merge( |
259 | 259 | $vars, |
260 | 260 | array( |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | } |
266 | 266 | |
267 | 267 | // Check if "orderby" is set to "vat_class" |
268 | - if ( isset( $vars['orderby'] ) && 'vat_class' == $vars['orderby'] ) { |
|
268 | + if (isset($vars['orderby']) && 'vat_class' == $vars['orderby']) { |
|
269 | 269 | $vars = array_merge( |
270 | 270 | $vars, |
271 | 271 | array( |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | } |
277 | 277 | |
278 | 278 | // Check if "orderby" is set to "type" |
279 | - if ( isset( $vars['orderby'] ) && 'type' == $vars['orderby'] ) { |
|
279 | + if (isset($vars['orderby']) && 'type' == $vars['orderby']) { |
|
280 | 280 | $vars = array_merge( |
281 | 281 | $vars, |
282 | 282 | array( |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | } |
288 | 288 | |
289 | 289 | // Check if "orderby" is set to "recurring" |
290 | - if ( isset( $vars['orderby'] ) && 'recurring' == $vars['orderby'] ) { |
|
290 | + if (isset($vars['orderby']) && 'recurring' == $vars['orderby']) { |
|
291 | 291 | $vars = array_merge( |
292 | 292 | $vars, |
293 | 293 | array( |
@@ -297,120 +297,120 @@ discard block |
||
297 | 297 | ); |
298 | 298 | } |
299 | 299 | |
300 | - $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array(); |
|
300 | + $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array(); |
|
301 | 301 | // Filter vat rule type |
302 | - if ( isset( $_GET['vat_rule'] ) && $_GET['vat_rule'] !== '' ) { |
|
302 | + if (isset($_GET['vat_rule']) && $_GET['vat_rule'] !== '') { |
|
303 | 303 | $meta_query[] = array( |
304 | 304 | 'key' => '_wpinv_vat_rule', |
305 | - 'value' => sanitize_text_field( $_GET['vat_rule'] ), |
|
305 | + 'value' => sanitize_text_field($_GET['vat_rule']), |
|
306 | 306 | 'compare' => '=' |
307 | 307 | ); |
308 | 308 | } |
309 | 309 | |
310 | 310 | // Filter vat class |
311 | - if ( isset( $_GET['vat_class'] ) && $_GET['vat_class'] !== '' ) { |
|
311 | + if (isset($_GET['vat_class']) && $_GET['vat_class'] !== '') { |
|
312 | 312 | $meta_query[] = array( |
313 | 313 | 'key' => '_wpinv_vat_class', |
314 | - 'value' => sanitize_text_field( $_GET['vat_class'] ), |
|
314 | + 'value' => sanitize_text_field($_GET['vat_class']), |
|
315 | 315 | 'compare' => '=' |
316 | 316 | ); |
317 | 317 | } |
318 | 318 | |
319 | 319 | // Filter item type |
320 | - if ( isset( $_GET['type'] ) && $_GET['type'] !== '' ) { |
|
320 | + if (isset($_GET['type']) && $_GET['type'] !== '') { |
|
321 | 321 | $meta_query[] = array( |
322 | 322 | 'key' => '_wpinv_type', |
323 | - 'value' => sanitize_text_field( $_GET['type'] ), |
|
323 | + 'value' => sanitize_text_field($_GET['type']), |
|
324 | 324 | 'compare' => '=' |
325 | 325 | ); |
326 | 326 | } |
327 | 327 | |
328 | - if ( !empty( $meta_query ) ) { |
|
328 | + if (!empty($meta_query)) { |
|
329 | 329 | $vars['meta_query'] = $meta_query; |
330 | 330 | } |
331 | - } else if ( 'wpi_discount' == $typenow ) { |
|
332 | - $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array(); |
|
331 | + } else if ('wpi_discount' == $typenow) { |
|
332 | + $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array(); |
|
333 | 333 | // Filter vat rule type |
334 | - if ( isset( $_GET['discount_type'] ) && $_GET['discount_type'] !== '' ) { |
|
334 | + if (isset($_GET['discount_type']) && $_GET['discount_type'] !== '') { |
|
335 | 335 | $meta_query[] = array( |
336 | 336 | 'key' => '_wpi_discount_type', |
337 | - 'value' => sanitize_text_field( $_GET['discount_type'] ), |
|
337 | + 'value' => sanitize_text_field($_GET['discount_type']), |
|
338 | 338 | 'compare' => '=' |
339 | 339 | ); |
340 | 340 | } |
341 | 341 | |
342 | - if ( !empty( $meta_query ) ) { |
|
342 | + if (!empty($meta_query)) { |
|
343 | 343 | $vars['meta_query'] = $meta_query; |
344 | 344 | } |
345 | 345 | } |
346 | 346 | |
347 | 347 | return $vars; |
348 | 348 | } |
349 | -add_filter( 'request', 'wpinv_request' ); |
|
349 | +add_filter('request', 'wpinv_request'); |
|
350 | 350 | |
351 | 351 | function wpinv_options_page() { |
352 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false; |
|
352 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : false; |
|
353 | 353 | |
354 | - if ( $page !== 'wpinv-settings' ) { |
|
354 | + if ($page !== 'wpinv-settings') { |
|
355 | 355 | return; |
356 | 356 | } |
357 | 357 | |
358 | 358 | $settings_tabs = wpinv_get_settings_tabs(); |
359 | 359 | $settings_tabs = empty($settings_tabs) ? array() : $settings_tabs; |
360 | - $active_tab = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $settings_tabs ) ? sanitize_text_field( $_GET['tab'] ) : 'general'; |
|
361 | - $sections = wpinv_get_settings_tab_sections( $active_tab ); |
|
360 | + $active_tab = isset($_GET['tab']) && array_key_exists($_GET['tab'], $settings_tabs) ? sanitize_text_field($_GET['tab']) : 'general'; |
|
361 | + $sections = wpinv_get_settings_tab_sections($active_tab); |
|
362 | 362 | $key = 'main'; |
363 | 363 | |
364 | - if ( is_array( $sections ) ) { |
|
365 | - $key = key( $sections ); |
|
364 | + if (is_array($sections)) { |
|
365 | + $key = key($sections); |
|
366 | 366 | } |
367 | 367 | |
368 | - $registered_sections = wpinv_get_settings_tab_sections( $active_tab ); |
|
369 | - $section = isset( $_GET['section'] ) && ! empty( $registered_sections ) && array_key_exists( $_GET['section'], $registered_sections ) ? $_GET['section'] : $key; |
|
368 | + $registered_sections = wpinv_get_settings_tab_sections($active_tab); |
|
369 | + $section = isset($_GET['section']) && !empty($registered_sections) && array_key_exists($_GET['section'], $registered_sections) ? $_GET['section'] : $key; |
|
370 | 370 | ob_start(); |
371 | 371 | ?> |
372 | 372 | <div class="wrap"> |
373 | 373 | <h1 class="nav-tab-wrapper"> |
374 | 374 | <?php |
375 | - foreach( wpinv_get_settings_tabs() as $tab_id => $tab_name ) { |
|
376 | - $tab_url = add_query_arg( array( |
|
375 | + foreach (wpinv_get_settings_tabs() as $tab_id => $tab_name) { |
|
376 | + $tab_url = add_query_arg(array( |
|
377 | 377 | 'settings-updated' => false, |
378 | 378 | 'tab' => $tab_id, |
379 | - ) ); |
|
379 | + )); |
|
380 | 380 | |
381 | 381 | // Remove the section from the tabs so we always end up at the main section |
382 | - $tab_url = remove_query_arg( 'section', $tab_url ); |
|
383 | - $tab_url = remove_query_arg( 'wpi_sub', $tab_url ); |
|
382 | + $tab_url = remove_query_arg('section', $tab_url); |
|
383 | + $tab_url = remove_query_arg('wpi_sub', $tab_url); |
|
384 | 384 | |
385 | 385 | $active = $active_tab == $tab_id ? ' nav-tab-active' : ''; |
386 | 386 | |
387 | - echo '<a href="' . esc_url( $tab_url ) . '" title="' . esc_attr( $tab_name ) . '" class="nav-tab' . $active . '">'; |
|
388 | - echo esc_html( $tab_name ); |
|
387 | + echo '<a href="' . esc_url($tab_url) . '" title="' . esc_attr($tab_name) . '" class="nav-tab' . $active . '">'; |
|
388 | + echo esc_html($tab_name); |
|
389 | 389 | echo '</a>'; |
390 | 390 | } |
391 | 391 | ?> |
392 | 392 | </h1> |
393 | 393 | <?php |
394 | - $number_of_sections = count( $sections ); |
|
394 | + $number_of_sections = count($sections); |
|
395 | 395 | $number = 0; |
396 | - if ( $number_of_sections > 1 ) { |
|
396 | + if ($number_of_sections > 1) { |
|
397 | 397 | echo '<div><ul class="subsubsub">'; |
398 | - foreach( $sections as $section_id => $section_name ) { |
|
398 | + foreach ($sections as $section_id => $section_name) { |
|
399 | 399 | echo '<li>'; |
400 | 400 | $number++; |
401 | - $tab_url = add_query_arg( array( |
|
401 | + $tab_url = add_query_arg(array( |
|
402 | 402 | 'settings-updated' => false, |
403 | 403 | 'tab' => $active_tab, |
404 | 404 | 'section' => $section_id |
405 | - ) ); |
|
406 | - $tab_url = remove_query_arg( 'wpi_sub', $tab_url ); |
|
405 | + )); |
|
406 | + $tab_url = remove_query_arg('wpi_sub', $tab_url); |
|
407 | 407 | $class = ''; |
408 | - if ( $section == $section_id ) { |
|
408 | + if ($section == $section_id) { |
|
409 | 409 | $class = 'current'; |
410 | 410 | } |
411 | - echo '<a class="' . $class . '" href="' . esc_url( $tab_url ) . '">' . $section_name . '</a>'; |
|
411 | + echo '<a class="' . $class . '" href="' . esc_url($tab_url) . '">' . $section_name . '</a>'; |
|
412 | 412 | |
413 | - if ( $number != $number_of_sections ) { |
|
413 | + if ($number != $number_of_sections) { |
|
414 | 414 | echo ' | '; |
415 | 415 | } |
416 | 416 | echo '</li>'; |
@@ -422,19 +422,19 @@ discard block |
||
422 | 422 | <form method="post" action="options.php"> |
423 | 423 | <table class="form-table"> |
424 | 424 | <?php |
425 | - settings_fields( 'wpinv_settings' ); |
|
425 | + settings_fields('wpinv_settings'); |
|
426 | 426 | |
427 | - if ( 'main' === $section ) { |
|
428 | - do_action( 'wpinv_settings_tab_top', $active_tab ); |
|
427 | + if ('main' === $section) { |
|
428 | + do_action('wpinv_settings_tab_top', $active_tab); |
|
429 | 429 | } |
430 | 430 | |
431 | - do_action( 'wpinv_settings_tab_top_' . $active_tab . '_' . $section ); |
|
432 | - do_settings_sections( 'wpinv_settings_' . $active_tab . '_' . $section ); |
|
433 | - do_action( 'wpinv_settings_tab_bottom_' . $active_tab . '_' . $section ); |
|
431 | + do_action('wpinv_settings_tab_top_' . $active_tab . '_' . $section); |
|
432 | + do_settings_sections('wpinv_settings_' . $active_tab . '_' . $section); |
|
433 | + do_action('wpinv_settings_tab_bottom_' . $active_tab . '_' . $section); |
|
434 | 434 | |
435 | 435 | // For backwards compatibility |
436 | - if ( 'main' === $section ) { |
|
437 | - do_action( 'wpinv_settings_tab_bottom', $active_tab ); |
|
436 | + if ('main' === $section) { |
|
437 | + do_action('wpinv_settings_tab_bottom', $active_tab); |
|
438 | 438 | } |
439 | 439 | ?> |
440 | 440 | </table> |
@@ -447,12 +447,12 @@ discard block |
||
447 | 447 | echo $content; |
448 | 448 | } |
449 | 449 | |
450 | -function wpinv_item_type_class( $classes, $class, $post_id ) { |
|
450 | +function wpinv_item_type_class($classes, $class, $post_id) { |
|
451 | 451 | global $pagenow, $typenow; |
452 | 452 | |
453 | - if ( $pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type( $post_id ) == $typenow && $type = get_post_meta( $post_id, '_wpinv_type', true ) ) { |
|
454 | - $classes[] = 'wpi-type-' . sanitize_html_class( $type ); |
|
453 | + if ($pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type($post_id) == $typenow && $type = get_post_meta($post_id, '_wpinv_type', true)) { |
|
454 | + $classes[] = 'wpi-type-' . sanitize_html_class($type); |
|
455 | 455 | } |
456 | 456 | return $classes; |
457 | 457 | } |
458 | -add_filter( 'post_class', 'wpinv_item_type_class', 10, 3 ); |
|
459 | 458 | \ No newline at end of file |
459 | +add_filter('post_class', 'wpinv_item_type_class', 10, 3); |
|
460 | 460 | \ No newline at end of file |