@@ -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(); |
@@ -33,34 +33,34 @@ 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( &$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(&$this, 'wpinv_actions')); |
|
48 | 48 | |
49 | - if ( class_exists( 'BuddyPress' ) ) { |
|
50 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
49 | + if (class_exists('BuddyPress')) { |
|
50 | + add_action('bp_include', array(&$this, 'bp_invoicing_init')); |
|
51 | 51 | } |
52 | 52 | |
53 | - add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
54 | - add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
55 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
53 | + add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts')); |
|
54 | + add_action('widgets_init', array(&$this, 'register_widgets')); |
|
55 | + add_filter('wpseo_exclude_from_sitemap_by_post_ids', array($this, 'wpseo_exclude_from_sitemap_by_post_ids')); |
|
56 | 56 | |
57 | - if ( is_admin() ) { |
|
58 | - add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) ); |
|
59 | - add_filter( 'admin_body_class', array( &$this, 'admin_body_class' ) ); |
|
60 | - add_action( 'admin_init', array( &$this, 'init_ayecode_connect_helper' ) ); |
|
57 | + if (is_admin()) { |
|
58 | + add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts')); |
|
59 | + add_filter('admin_body_class', array(&$this, 'admin_body_class')); |
|
60 | + add_action('admin_init', array(&$this, 'init_ayecode_connect_helper')); |
|
61 | 61 | |
62 | 62 | } else { |
63 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
63 | + add_filter('pre_get_posts', array(&$this, 'pre_get_posts')); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
@@ -70,28 +70,28 @@ discard block |
||
70 | 70 | * |
71 | 71 | * @param WPInv_Plugin $this. Current WPInv_Plugin instance. Passed by reference. |
72 | 72 | */ |
73 | - do_action_ref_array( 'wpinv_actions', array( &$this ) ); |
|
73 | + do_action_ref_array('wpinv_actions', array(&$this)); |
|
74 | 74 | |
75 | - add_action( 'admin_init', array( &$this, 'activation_redirect') ); |
|
75 | + add_action('admin_init', array(&$this, 'activation_redirect')); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | 79 | * Maybe show the AyeCode Connect Notice. |
80 | 80 | */ |
81 | - public function init_ayecode_connect_helper(){ |
|
81 | + public function init_ayecode_connect_helper() { |
|
82 | 82 | // AyeCode Connect notice |
83 | - if ( is_admin() ){ |
|
83 | + if (is_admin()) { |
|
84 | 84 | // set the strings so they can be translated |
85 | 85 | $strings = array( |
86 | - 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
87 | - 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
88 | - 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
89 | - 'connect_button' => __("Connect Site","invoicing"), |
|
90 | - 'connecting_button' => __("Connecting...","invoicing"), |
|
91 | - 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
92 | - 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
86 | + 'connect_title' => __("WP Invoicing - an AyeCode product!", "invoicing"), |
|
87 | + 'connect_external' => __("Please confirm you wish to connect your site?", "invoicing"), |
|
88 | + 'connect' => sprintf(__("<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s", "invoicing"), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>"), |
|
89 | + 'connect_button' => __("Connect Site", "invoicing"), |
|
90 | + 'connecting_button' => __("Connecting...", "invoicing"), |
|
91 | + 'error_localhost' => __("This service will only work with a live domain, not a localhost.", "invoicing"), |
|
92 | + 'error' => __("Something went wrong, please refresh and try again.", "invoicing"), |
|
93 | 93 | ); |
94 | - new AyeCode_Connect_Helper($strings,array('wpi-addons')); |
|
94 | + new AyeCode_Connect_Helper($strings, array('wpi-addons')); |
|
95 | 95 | } |
96 | 96 | } |
97 | 97 | |
@@ -99,10 +99,10 @@ discard block |
||
99 | 99 | /* Internationalize the text strings used. */ |
100 | 100 | $this->load_textdomain(); |
101 | 101 | |
102 | - do_action( 'wpinv_loaded' ); |
|
102 | + do_action('wpinv_loaded'); |
|
103 | 103 | |
104 | 104 | // Fix oxygen page builder conflict |
105 | - if ( function_exists( 'ct_css_output' ) ) { |
|
105 | + if (function_exists('ct_css_output')) { |
|
106 | 106 | wpinv_oxygen_fix_conflict(); |
107 | 107 | } |
108 | 108 | } |
@@ -112,237 +112,237 @@ discard block |
||
112 | 112 | * |
113 | 113 | * @since 1.0 |
114 | 114 | */ |
115 | - public function load_textdomain( $locale = NULL ) { |
|
116 | - if ( empty( $locale ) ) { |
|
117 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
115 | + public function load_textdomain($locale = NULL) { |
|
116 | + if (empty($locale)) { |
|
117 | + $locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale(); |
|
118 | 118 | } |
119 | 119 | |
120 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
120 | + $locale = apply_filters('plugin_locale', $locale, 'invoicing'); |
|
121 | 121 | |
122 | - unload_textdomain( 'invoicing' ); |
|
123 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
124 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
122 | + unload_textdomain('invoicing'); |
|
123 | + load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo'); |
|
124 | + load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages'); |
|
125 | 125 | |
126 | 126 | /** |
127 | 127 | * Define language constants. |
128 | 128 | */ |
129 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
129 | + require_once(WPINV_PLUGIN_DIR . 'language.php'); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | public function includes() { |
133 | 133 | global $wpinv_options; |
134 | 134 | |
135 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
135 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'); |
|
136 | 136 | $wpinv_options = wpinv_get_settings(); |
137 | 137 | |
138 | - require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
139 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php' ); |
|
140 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
141 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
142 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
143 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
144 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
145 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
146 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php' ); |
|
147 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
148 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
149 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
150 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
151 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
152 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' ); |
|
153 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php' ); |
|
154 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php' ); |
|
155 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-discount.php' ); |
|
156 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php' ); |
|
157 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php' ); |
|
158 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
159 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
160 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
161 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
162 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
163 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
164 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
165 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
166 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
167 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php' ); |
|
168 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
169 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php' ); |
|
170 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
171 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
172 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
173 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
174 | - require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
175 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
176 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
177 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
178 | - require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
179 | - require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
180 | - require_once( WPINV_PLUGIN_DIR . 'widgets/payment-form.php' ); |
|
181 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php' ); |
|
182 | - |
|
183 | - if ( !class_exists( 'WPInv_EUVat' ) ) { |
|
184 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
138 | + require_once(WPINV_PLUGIN_DIR . 'vendor/autoload.php'); |
|
139 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php'); |
|
140 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'); |
|
141 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'); |
|
142 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'); |
|
143 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'); |
|
144 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'); |
|
145 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'); |
|
146 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php'); |
|
147 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'); |
|
148 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'); |
|
149 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'); |
|
150 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'); |
|
151 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php'); |
|
152 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php'); |
|
153 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php'); |
|
154 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php'); |
|
155 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-discount.php'); |
|
156 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php'); |
|
157 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php'); |
|
158 | + require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'); |
|
159 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'); |
|
160 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'); |
|
161 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'); |
|
162 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php'); |
|
163 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'); |
|
164 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'); |
|
165 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'); |
|
166 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'); |
|
167 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php'); |
|
168 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'); |
|
169 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php'); |
|
170 | + require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'); |
|
171 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'); |
|
172 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'); |
|
173 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'); |
|
174 | + require_once(WPINV_PLUGIN_DIR . 'widgets/checkout.php'); |
|
175 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'); |
|
176 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'); |
|
177 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'); |
|
178 | + require_once(WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'); |
|
179 | + require_once(WPINV_PLUGIN_DIR . 'widgets/buy-item.php'); |
|
180 | + require_once(WPINV_PLUGIN_DIR . 'widgets/payment-form.php'); |
|
181 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php'); |
|
182 | + |
|
183 | + if (!class_exists('WPInv_EUVat')) { |
|
184 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php'); |
|
185 | 185 | } |
186 | 186 | |
187 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
188 | - if ( !empty( $gateways ) ) { |
|
189 | - foreach ( $gateways as $gateway ) { |
|
190 | - if ( $gateway == 'manual' ) { |
|
187 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
188 | + if (!empty($gateways)) { |
|
189 | + foreach ($gateways as $gateway) { |
|
190 | + if ($gateway == 'manual') { |
|
191 | 191 | continue; |
192 | 192 | } |
193 | 193 | |
194 | 194 | $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php'; |
195 | 195 | |
196 | - if ( file_exists( $gateway_file ) ) { |
|
197 | - require_once( $gateway_file ); |
|
196 | + if (file_exists($gateway_file)) { |
|
197 | + require_once($gateway_file); |
|
198 | 198 | } |
199 | 199 | } |
200 | 200 | } |
201 | - require_once( WPINV_PLUGIN_DIR . 'includes/gateways/manual.php' ); |
|
201 | + require_once(WPINV_PLUGIN_DIR . 'includes/gateways/manual.php'); |
|
202 | 202 | |
203 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
204 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
205 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
206 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php' ); |
|
203 | + if (is_admin() || (defined('WP_CLI') && WP_CLI)) { |
|
204 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php'); |
|
205 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'); |
|
206 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php'); |
|
207 | 207 | //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' ); |
208 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php' ); |
|
209 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php' ); |
|
210 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
211 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
212 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php' ); |
|
213 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
214 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
215 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
208 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php'); |
|
209 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php'); |
|
210 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'); |
|
211 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'); |
|
212 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php'); |
|
213 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'); |
|
214 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'); |
|
215 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'); |
|
216 | 216 | //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
217 | 217 | // load the user class only on the users.php page |
218 | 218 | global $pagenow; |
219 | - if($pagenow=='users.php'){ |
|
219 | + if ($pagenow == 'users.php') { |
|
220 | 220 | new WPInv_Admin_Users(); |
221 | 221 | } |
222 | 222 | } |
223 | 223 | |
224 | 224 | // Register cli commands |
225 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
226 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
227 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
225 | + if (defined('WP_CLI') && WP_CLI) { |
|
226 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'); |
|
227 | + WP_CLI::add_command('invoicing', 'WPInv_CLI'); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | // include css inliner |
231 | - if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) { |
|
232 | - include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' ); |
|
231 | + if (!class_exists('Emogrifier') && class_exists('DOMDocument')) { |
|
232 | + include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php'); |
|
233 | 233 | } |
234 | 234 | |
235 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
235 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php'); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | public function init() { |
239 | 239 | } |
240 | 240 | |
241 | 241 | public function admin_init() { |
242 | - add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) ); |
|
242 | + add_action('admin_print_scripts-edit.php', array(&$this, 'admin_print_scripts_edit_php')); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | public function activation_redirect() { |
246 | 246 | // Bail if no activation redirect |
247 | - if ( !get_transient( '_wpinv_activation_redirect' ) ) { |
|
247 | + if (!get_transient('_wpinv_activation_redirect')) { |
|
248 | 248 | return; |
249 | 249 | } |
250 | 250 | |
251 | 251 | // Delete the redirect transient |
252 | - delete_transient( '_wpinv_activation_redirect' ); |
|
252 | + delete_transient('_wpinv_activation_redirect'); |
|
253 | 253 | |
254 | 254 | // Bail if activating from network, or bulk |
255 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
255 | + if (is_network_admin() || isset($_GET['activate-multi'])) { |
|
256 | 256 | return; |
257 | 257 | } |
258 | 258 | |
259 | - wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
259 | + wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general')); |
|
260 | 260 | exit; |
261 | 261 | } |
262 | 262 | |
263 | 263 | public function enqueue_scripts() { |
264 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
264 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
265 | 265 | |
266 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION ); |
|
267 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
266 | + wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION); |
|
267 | + wp_enqueue_style('wpinv_front_style'); |
|
268 | 268 | |
269 | 269 | // Register scripts |
270 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
271 | - wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ), filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) ); |
|
270 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
271 | + wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array('jquery'), filemtime(WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js')); |
|
272 | 272 | |
273 | 273 | $localize = array(); |
274 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
275 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
274 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
275 | + $localize['nonce'] = wp_create_nonce('wpinv-nonce'); |
|
276 | 276 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
277 | 277 | $localize['currency_pos'] = wpinv_currency_position(); |
278 | 278 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
279 | 279 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
280 | 280 | $localize['decimals'] = wpinv_decimals(); |
281 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
281 | + $localize['txtComplete'] = __('Continue', 'invoicing'); |
|
282 | 282 | $localize['UseTaxes'] = wpinv_use_taxes(); |
283 | - $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
283 | + $localize['checkoutNonce'] = wp_create_nonce('wpinv_checkout_nonce'); |
|
284 | 284 | |
285 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
285 | + $localize = apply_filters('wpinv_front_js_localize', $localize); |
|
286 | 286 | |
287 | - wp_enqueue_script( 'jquery-blockui' ); |
|
287 | + wp_enqueue_script('jquery-blockui'); |
|
288 | 288 | $autofill_api = wpinv_get_option('address_autofill_api'); |
289 | 289 | $autofill_active = wpinv_get_option('address_autofill_active'); |
290 | - if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) { |
|
291 | - if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) { |
|
292 | - wp_dequeue_script( 'google-maps-api' ); |
|
290 | + if (isset($autofill_active) && 1 == $autofill_active && !empty($autofill_api) && wpinv_is_checkout()) { |
|
291 | + if (wp_script_is('google-maps-api', 'enqueued')) { |
|
292 | + wp_dequeue_script('google-maps-api'); |
|
293 | 293 | } |
294 | - wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false ); |
|
295 | - wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true ); |
|
294 | + wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array('jquery'), '', false); |
|
295 | + wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery', 'google-maps-api'), '', true); |
|
296 | 296 | } |
297 | 297 | |
298 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' ); |
|
299 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
298 | + wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all'); |
|
299 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
300 | 300 | |
301 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
302 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
301 | + wp_enqueue_script('wpinv-front-script'); |
|
302 | + wp_localize_script('wpinv-front-script', 'WPInv', $localize); |
|
303 | 303 | |
304 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
305 | - wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ), $version, true ); |
|
304 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js'); |
|
305 | + wp_enqueue_script('wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array('wpinv-front-script', 'wp-hooks'), $version, true); |
|
306 | 306 | } |
307 | 307 | |
308 | - public function admin_enqueue_scripts( $hook ) { |
|
308 | + public function admin_enqueue_scripts($hook) { |
|
309 | 309 | global $post, $pagenow; |
310 | 310 | |
311 | 311 | $post_type = wpinv_admin_post_type(); |
312 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
313 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : ''; |
|
312 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
313 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : ''; |
|
314 | 314 | |
315 | 315 | $jquery_ui_css = false; |
316 | - if ( ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount' ) && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) { |
|
316 | + if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
|
317 | 317 | $jquery_ui_css = true; |
318 | - } else if ( $page == 'wpinv-settings' || $page == 'wpinv-reports' ) { |
|
318 | + } else if ($page == 'wpinv-settings' || $page == 'wpinv-reports') { |
|
319 | 319 | $jquery_ui_css = true; |
320 | 320 | } |
321 | - if ( $jquery_ui_css ) { |
|
322 | - wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' ); |
|
323 | - wp_enqueue_style( 'jquery-ui-css' ); |
|
321 | + if ($jquery_ui_css) { |
|
322 | + wp_register_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16'); |
|
323 | + wp_enqueue_style('jquery-ui-css'); |
|
324 | 324 | } |
325 | 325 | |
326 | - wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION ); |
|
327 | - wp_enqueue_style( 'wpinv_meta_box_style' ); |
|
326 | + wp_register_style('wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION); |
|
327 | + wp_enqueue_style('wpinv_meta_box_style'); |
|
328 | 328 | |
329 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' ); |
|
330 | - wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), $version ); |
|
331 | - wp_enqueue_style( 'wpinv_admin_style' ); |
|
329 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/admin.css'); |
|
330 | + wp_register_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), $version); |
|
331 | + wp_enqueue_style('wpinv_admin_style'); |
|
332 | 332 | |
333 | - $enqueue = ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ); |
|
334 | - if ( $page == 'wpinv-subscriptions' ) { |
|
335 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
333 | + $enqueue = ($post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ($pagenow == 'post-new.php' || $pagenow == 'post.php')); |
|
334 | + if ($page == 'wpinv-subscriptions') { |
|
335 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
336 | 336 | } |
337 | 337 | |
338 | - if ( $enqueue_datepicker = apply_filters( 'wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue ) ) { |
|
339 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
338 | + if ($enqueue_datepicker = apply_filters('wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue)) { |
|
339 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
340 | 340 | } |
341 | 341 | |
342 | - wp_enqueue_style( 'wp-color-picker' ); |
|
343 | - wp_enqueue_script( 'wp-color-picker' ); |
|
342 | + wp_enqueue_style('wp-color-picker'); |
|
343 | + wp_enqueue_script('wp-color-picker'); |
|
344 | 344 | |
345 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
345 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
346 | 346 | |
347 | 347 | if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
348 | 348 | $autofill_api = wpinv_get_option('address_autofill_api'); |
@@ -353,21 +353,21 @@ discard block |
||
353 | 353 | } |
354 | 354 | } |
355 | 355 | |
356 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' ); |
|
357 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
356 | + wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all'); |
|
357 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
358 | 358 | |
359 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' ); |
|
360 | - wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip' ), $version ); |
|
361 | - wp_enqueue_script( 'wpinv-admin-script' ); |
|
359 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin.js'); |
|
360 | + wp_register_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array('jquery', 'jquery-blockui', 'jquery-ui-tooltip'), $version); |
|
361 | + wp_enqueue_script('wpinv-admin-script'); |
|
362 | 362 | |
363 | 363 | $localize = array(); |
364 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
365 | - $localize['post_ID'] = isset( $post->ID ) ? $post->ID : ''; |
|
366 | - $localize['wpinv_nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
367 | - $localize['add_invoice_note_nonce'] = wp_create_nonce( 'add-invoice-note' ); |
|
368 | - $localize['delete_invoice_note_nonce'] = wp_create_nonce( 'delete-invoice-note' ); |
|
369 | - $localize['invoice_item_nonce'] = wp_create_nonce( 'invoice-item' ); |
|
370 | - $localize['billing_details_nonce'] = wp_create_nonce( 'get-billing-details' ); |
|
364 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
365 | + $localize['post_ID'] = isset($post->ID) ? $post->ID : ''; |
|
366 | + $localize['wpinv_nonce'] = wp_create_nonce('wpinv-nonce'); |
|
367 | + $localize['add_invoice_note_nonce'] = wp_create_nonce('add-invoice-note'); |
|
368 | + $localize['delete_invoice_note_nonce'] = wp_create_nonce('delete-invoice-note'); |
|
369 | + $localize['invoice_item_nonce'] = wp_create_nonce('invoice-item'); |
|
370 | + $localize['billing_details_nonce'] = wp_create_nonce('get-billing-details'); |
|
371 | 371 | $localize['tax'] = wpinv_tax_amount(); |
372 | 372 | $localize['discount'] = wpinv_discount_amount(); |
373 | 373 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
@@ -375,95 +375,95 @@ discard block |
||
375 | 375 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
376 | 376 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
377 | 377 | $localize['decimals'] = wpinv_decimals(); |
378 | - $localize['save_invoice'] = __( 'Save Invoice', 'invoicing' ); |
|
379 | - $localize['status_publish'] = wpinv_status_nicename( 'publish' ); |
|
380 | - $localize['status_pending'] = wpinv_status_nicename( 'wpi-pending' ); |
|
381 | - $localize['delete_tax_rate'] = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ); |
|
382 | - $localize['OneItemMin'] = __( 'Invoice must contain at least one item', 'invoicing' ); |
|
383 | - $localize['DeleteInvoiceItem'] = __( 'Are you sure you wish to delete this item?', 'invoicing' ); |
|
384 | - $localize['FillBillingDetails'] = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ); |
|
385 | - $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' ); |
|
386 | - $localize['AreYouSure'] = __( 'Are you sure?', 'invoicing' ); |
|
387 | - $localize['emptyInvoice'] = __( 'Add at least one item to save invoice!', 'invoicing' ); |
|
388 | - $localize['errDeleteItem'] = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ); |
|
389 | - $localize['delete_subscription'] = __( 'Are you sure you want to delete this subscription?', 'invoicing' ); |
|
390 | - $localize['action_edit'] = __( 'Edit', 'invoicing' ); |
|
391 | - $localize['action_cancel'] = __( 'Cancel', 'invoicing' ); |
|
392 | - |
|
393 | - $localize = apply_filters( 'wpinv_admin_js_localize', $localize ); |
|
394 | - |
|
395 | - wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize ); |
|
378 | + $localize['save_invoice'] = __('Save Invoice', 'invoicing'); |
|
379 | + $localize['status_publish'] = wpinv_status_nicename('publish'); |
|
380 | + $localize['status_pending'] = wpinv_status_nicename('wpi-pending'); |
|
381 | + $localize['delete_tax_rate'] = __('Are you sure you wish to delete this tax rate?', 'invoicing'); |
|
382 | + $localize['OneItemMin'] = __('Invoice must contain at least one item', 'invoicing'); |
|
383 | + $localize['DeleteInvoiceItem'] = __('Are you sure you wish to delete this item?', 'invoicing'); |
|
384 | + $localize['FillBillingDetails'] = __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'); |
|
385 | + $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'); |
|
386 | + $localize['AreYouSure'] = __('Are you sure?', 'invoicing'); |
|
387 | + $localize['emptyInvoice'] = __('Add at least one item to save invoice!', 'invoicing'); |
|
388 | + $localize['errDeleteItem'] = __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'); |
|
389 | + $localize['delete_subscription'] = __('Are you sure you want to delete this subscription?', 'invoicing'); |
|
390 | + $localize['action_edit'] = __('Edit', 'invoicing'); |
|
391 | + $localize['action_cancel'] = __('Cancel', 'invoicing'); |
|
392 | + |
|
393 | + $localize = apply_filters('wpinv_admin_js_localize', $localize); |
|
394 | + |
|
395 | + wp_localize_script('wpinv-admin-script', 'WPInv_Admin', $localize); |
|
396 | 396 | |
397 | 397 | // Load payment form scripts on our admin pages only. |
398 | - if ( ( $hook == 'post-new.php' || $hook == 'post.php' ) && 'wpi_payment_form' === $post->post_type ) { |
|
398 | + if (($hook == 'post-new.php' || $hook == 'post.php') && 'wpi_payment_form' === $post->post_type) { |
|
399 | 399 | |
400 | - wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION ); |
|
401 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
402 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
400 | + wp_enqueue_script('vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION); |
|
401 | + wp_enqueue_script('sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION); |
|
402 | + wp_enqueue_script('vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array('sortable', 'vue'), WPINV_VERSION); |
|
403 | 403 | |
404 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
405 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
404 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js'); |
|
405 | + wp_register_script('wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array('wpinv-admin-script', 'vue_draggable'), $version); |
|
406 | 406 | |
407 | - wp_localize_script( 'wpinv-admin-payment-form-script', 'wpinvPaymentFormAdmin', array( |
|
407 | + wp_localize_script('wpinv-admin-payment-form-script', 'wpinvPaymentFormAdmin', array( |
|
408 | 408 | 'elements' => $this->form_elements->get_elements(), |
409 | - 'form_elements' => $this->form_elements->get_form_elements( $post->ID ), |
|
409 | + 'form_elements' => $this->form_elements->get_form_elements($post->ID), |
|
410 | 410 | 'all_items' => $this->form_elements->get_published_items(), |
411 | 411 | 'currency' => wpinv_currency_symbol(), |
412 | 412 | 'position' => wpinv_currency_position(), |
413 | 413 | 'decimals' => (int) wpinv_decimals(), |
414 | 414 | 'thousands_sep' => wpinv_thousands_separator(), |
415 | 415 | 'decimals_sep' => wpinv_decimal_separator(), |
416 | - 'form_items' => $this->form_elements->get_form_items( $post->ID ), |
|
417 | - ) ); |
|
416 | + 'form_items' => $this->form_elements->get_form_items($post->ID), |
|
417 | + )); |
|
418 | 418 | |
419 | - wp_enqueue_script( 'wpinv-admin-payment-form-script' ); |
|
419 | + wp_enqueue_script('wpinv-admin-payment-form-script'); |
|
420 | 420 | } |
421 | 421 | |
422 | - if ( $page == 'wpinv-subscriptions' ) { |
|
423 | - wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ), WPINV_VERSION ); |
|
424 | - wp_enqueue_script( 'wpinv-sub-admin-script' ); |
|
422 | + if ($page == 'wpinv-subscriptions') { |
|
423 | + wp_register_script('wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array('wpinv-admin-script'), WPINV_VERSION); |
|
424 | + wp_enqueue_script('wpinv-sub-admin-script'); |
|
425 | 425 | } |
426 | 426 | |
427 | 427 | } |
428 | 428 | |
429 | - public function admin_body_class( $classes ) { |
|
429 | + public function admin_body_class($classes) { |
|
430 | 430 | global $pagenow, $post, $current_screen; |
431 | 431 | |
432 | - if ( !empty( $current_screen->post_type ) && ( $current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_payment_form' || $current_screen->post_type == 'wpi_quote' ) ) { |
|
432 | + if (!empty($current_screen->post_type) && ($current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_payment_form' || $current_screen->post_type == 'wpi_quote')) { |
|
433 | 433 | $classes .= ' wpinv-cpt'; |
434 | 434 | } |
435 | 435 | |
436 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false; |
|
436 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : false; |
|
437 | 437 | |
438 | - $add_class = $page && $pagenow == 'admin.php' && strpos( $page, 'wpinv-' ) === 0 ? true : false; |
|
439 | - if ( $add_class ) { |
|
440 | - $classes .= ' wpi-' . wpinv_sanitize_key( $page ); |
|
438 | + $add_class = $page && $pagenow == 'admin.php' && strpos($page, 'wpinv-') === 0 ? true : false; |
|
439 | + if ($add_class) { |
|
440 | + $classes .= ' wpi-' . wpinv_sanitize_key($page); |
|
441 | 441 | } |
442 | 442 | |
443 | 443 | $settings_class = array(); |
444 | - if ( $page == 'wpinv-settings' ) { |
|
445 | - if ( !empty( $_REQUEST['tab'] ) ) { |
|
446 | - $settings_class[] = sanitize_text_field( $_REQUEST['tab'] ); |
|
444 | + if ($page == 'wpinv-settings') { |
|
445 | + if (!empty($_REQUEST['tab'])) { |
|
446 | + $settings_class[] = sanitize_text_field($_REQUEST['tab']); |
|
447 | 447 | } |
448 | 448 | |
449 | - if ( !empty( $_REQUEST['section'] ) ) { |
|
450 | - $settings_class[] = sanitize_text_field( $_REQUEST['section'] ); |
|
449 | + if (!empty($_REQUEST['section'])) { |
|
450 | + $settings_class[] = sanitize_text_field($_REQUEST['section']); |
|
451 | 451 | } |
452 | 452 | |
453 | - $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main'; |
|
453 | + $settings_class[] = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field($_REQUEST['wpi_sub']) : 'main'; |
|
454 | 454 | } |
455 | 455 | |
456 | - if ( !empty( $settings_class ) ) { |
|
457 | - $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) ); |
|
456 | + if (!empty($settings_class)) { |
|
457 | + $classes .= ' wpi-' . wpinv_sanitize_key(implode($settings_class, '-')); |
|
458 | 458 | } |
459 | 459 | |
460 | 460 | $post_type = wpinv_admin_post_type(); |
461 | 461 | |
462 | - if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) { |
|
462 | + if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false) { |
|
463 | 463 | return $classes .= ' wpinv'; |
464 | 464 | } |
465 | 465 | |
466 | - if ( $pagenow == 'post.php' && $post_type == 'wpi_item' && !empty( $post ) && !wpinv_item_is_editable( $post ) ) { |
|
466 | + if ($pagenow == 'post.php' && $post_type == 'wpi_item' && !empty($post) && !wpinv_item_is_editable($post)) { |
|
467 | 467 | $classes .= ' wpi-editable-n'; |
468 | 468 | } |
469 | 469 | |
@@ -475,21 +475,21 @@ discard block |
||
475 | 475 | } |
476 | 476 | |
477 | 477 | public function wpinv_actions() { |
478 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
479 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
478 | + if (isset($_REQUEST['wpi_action'])) { |
|
479 | + do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST); |
|
480 | 480 | } |
481 | 481 | } |
482 | 482 | |
483 | - public function pre_get_posts( $wp_query ) { |
|
484 | - 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() ) { |
|
485 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
483 | + public function pre_get_posts($wp_query) { |
|
484 | + 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()) { |
|
485 | + $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses()); |
|
486 | 486 | } |
487 | 487 | |
488 | 488 | return $wp_query; |
489 | 489 | } |
490 | 490 | |
491 | 491 | public function bp_invoicing_init() { |
492 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
492 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php'); |
|
493 | 493 | } |
494 | 494 | |
495 | 495 | /** |
@@ -497,13 +497,13 @@ discard block |
||
497 | 497 | * |
498 | 498 | */ |
499 | 499 | public function register_widgets() { |
500 | - register_widget( "WPInv_Checkout_Widget" ); |
|
501 | - register_widget( "WPInv_History_Widget" ); |
|
502 | - register_widget( "WPInv_Receipt_Widget" ); |
|
503 | - register_widget( "WPInv_Subscriptions_Widget" ); |
|
504 | - register_widget( "WPInv_Buy_Item_Widget" ); |
|
505 | - register_widget( "WPInv_Messages_Widget" ); |
|
506 | - register_widget( 'WPInv_Payment_Form_Widget' ); |
|
500 | + register_widget("WPInv_Checkout_Widget"); |
|
501 | + register_widget("WPInv_History_Widget"); |
|
502 | + register_widget("WPInv_Receipt_Widget"); |
|
503 | + register_widget("WPInv_Subscriptions_Widget"); |
|
504 | + register_widget("WPInv_Buy_Item_Widget"); |
|
505 | + register_widget("WPInv_Messages_Widget"); |
|
506 | + register_widget('WPInv_Payment_Form_Widget'); |
|
507 | 507 | } |
508 | 508 | |
509 | 509 | /** |
@@ -512,10 +512,10 @@ discard block |
||
512 | 512 | * @since 1.0.19 |
513 | 513 | * @param int[] $excluded_posts_ids |
514 | 514 | */ |
515 | - function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
515 | + function wpseo_exclude_from_sitemap_by_post_ids($excluded_posts_ids) { |
|
516 | 516 | |
517 | 517 | // Ensure that we have an array. |
518 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
518 | + if (!is_array($excluded_posts_ids)) { |
|
519 | 519 | $excluded_posts_ids = array(); |
520 | 520 | } |
521 | 521 | |
@@ -523,24 +523,24 @@ discard block |
||
523 | 523 | $our_pages = array(); |
524 | 524 | |
525 | 525 | // Checkout page. |
526 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
526 | + $our_pages[] = wpinv_get_option('checkout_page', false); |
|
527 | 527 | |
528 | 528 | // Success page. |
529 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
529 | + $our_pages[] = wpinv_get_option('success_page', false); |
|
530 | 530 | |
531 | 531 | // Failure page. |
532 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
532 | + $our_pages[] = wpinv_get_option('failure_page', false); |
|
533 | 533 | |
534 | 534 | // History page. |
535 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
535 | + $our_pages[] = wpinv_get_option('invoice_history_page', false); |
|
536 | 536 | |
537 | 537 | // Subscriptions page. |
538 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
538 | + $our_pages[] = wpinv_get_option('invoice_subscription_page', false); |
|
539 | 539 | |
540 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
540 | + $our_pages = array_map('intval', array_filter($our_pages)); |
|
541 | 541 | |
542 | 542 | $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
543 | - return array_unique( $excluded_posts_ids ); |
|
543 | + return array_unique($excluded_posts_ids); |
|
544 | 544 | |
545 | 545 | } |
546 | 546 | } |
@@ -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 | |
@@ -66,17 +66,17 @@ discard block |
||
66 | 66 | public $full_name = ''; |
67 | 67 | public $parent_invoice = 0; |
68 | 68 | |
69 | - public function __construct( $invoice_id = false ) { |
|
70 | - if( empty( $invoice_id ) ) { |
|
69 | + public function __construct($invoice_id = false) { |
|
70 | + if (empty($invoice_id)) { |
|
71 | 71 | return false; |
72 | 72 | } |
73 | 73 | |
74 | - $this->setup_invoice( $invoice_id ); |
|
74 | + $this->setup_invoice($invoice_id); |
|
75 | 75 | } |
76 | 76 | |
77 | - public function get( $key ) { |
|
78 | - if ( method_exists( $this, 'get_' . $key ) ) { |
|
79 | - $value = call_user_func( array( $this, 'get_' . $key ) ); |
|
77 | + public function get($key) { |
|
78 | + if (method_exists($this, 'get_' . $key)) { |
|
79 | + $value = call_user_func(array($this, 'get_' . $key)); |
|
80 | 80 | } else { |
81 | 81 | $value = $this->$key; |
82 | 82 | } |
@@ -84,51 +84,51 @@ discard block |
||
84 | 84 | return $value; |
85 | 85 | } |
86 | 86 | |
87 | - public function set( $key, $value ) { |
|
88 | - $ignore = array( 'items', 'cart_details', 'fees', '_ID' ); |
|
87 | + public function set($key, $value) { |
|
88 | + $ignore = array('items', 'cart_details', 'fees', '_ID'); |
|
89 | 89 | |
90 | - if ( $key === 'status' ) { |
|
90 | + if ($key === 'status') { |
|
91 | 91 | $this->old_status = $this->status; |
92 | 92 | } |
93 | 93 | |
94 | - if ( ! in_array( $key, $ignore ) ) { |
|
95 | - $this->pending[ $key ] = $value; |
|
94 | + if (!in_array($key, $ignore)) { |
|
95 | + $this->pending[$key] = $value; |
|
96 | 96 | } |
97 | 97 | |
98 | - if( '_ID' !== $key ) { |
|
98 | + if ('_ID' !== $key) { |
|
99 | 99 | $this->$key = $value; |
100 | 100 | } |
101 | 101 | } |
102 | 102 | |
103 | - public function _isset( $name ) { |
|
104 | - if ( property_exists( $this, $name) ) { |
|
105 | - return false === empty( $this->$name ); |
|
103 | + public function _isset($name) { |
|
104 | + if (property_exists($this, $name)) { |
|
105 | + return false === empty($this->$name); |
|
106 | 106 | } else { |
107 | 107 | return null; |
108 | 108 | } |
109 | 109 | } |
110 | 110 | |
111 | - private function setup_invoice( $invoice_id ) { |
|
111 | + private function setup_invoice($invoice_id) { |
|
112 | 112 | $this->pending = array(); |
113 | 113 | |
114 | - if ( empty( $invoice_id ) ) { |
|
114 | + if (empty($invoice_id)) { |
|
115 | 115 | return false; |
116 | 116 | } |
117 | 117 | |
118 | - $invoice = get_post( $invoice_id ); |
|
118 | + $invoice = get_post($invoice_id); |
|
119 | 119 | |
120 | - if( !$invoice || is_wp_error( $invoice ) ) { |
|
120 | + if (!$invoice || is_wp_error($invoice)) { |
|
121 | 121 | return false; |
122 | 122 | } |
123 | 123 | |
124 | - if( !('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type) ) { |
|
124 | + if (!('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type)) { |
|
125 | 125 | return false; |
126 | 126 | } |
127 | 127 | |
128 | - do_action( 'wpinv_pre_setup_invoice', $this, $invoice_id ); |
|
128 | + do_action('wpinv_pre_setup_invoice', $this, $invoice_id); |
|
129 | 129 | |
130 | 130 | // Primary Identifier |
131 | - $this->ID = absint( $invoice_id ); |
|
131 | + $this->ID = absint($invoice_id); |
|
132 | 132 | $this->post_type = $invoice->post_type; |
133 | 133 | |
134 | 134 | // We have a payment, get the generic payment_meta item to reduce calls to it |
@@ -138,14 +138,14 @@ discard block |
||
138 | 138 | $this->completed_date = $this->setup_completed_date(); |
139 | 139 | $this->status = $invoice->post_status; |
140 | 140 | |
141 | - if ( 'future' == $this->status ) { |
|
141 | + if ('future' == $this->status) { |
|
142 | 142 | $this->status = 'publish'; |
143 | 143 | } |
144 | 144 | |
145 | 145 | $this->post_status = $this->status; |
146 | 146 | $this->mode = $this->setup_mode(); |
147 | 147 | $this->parent_invoice = $invoice->post_parent; |
148 | - $this->post_name = $this->setup_post_name( $invoice ); |
|
148 | + $this->post_name = $this->setup_post_name($invoice); |
|
149 | 149 | $this->status_nicename = $this->setup_status_nicename($invoice->post_status); |
150 | 150 | |
151 | 151 | // Items |
@@ -168,8 +168,8 @@ discard block |
||
168 | 168 | |
169 | 169 | // User based |
170 | 170 | $this->ip = $this->setup_ip(); |
171 | - $this->user_id = !empty( $invoice->post_author ) ? $invoice->post_author : get_current_user_id();///$this->setup_user_id(); |
|
172 | - $this->email = get_the_author_meta( 'email', $this->user_id ); |
|
171 | + $this->user_id = !empty($invoice->post_author) ? $invoice->post_author : get_current_user_id(); ///$this->setup_user_id(); |
|
172 | + $this->email = get_the_author_meta('email', $this->user_id); |
|
173 | 173 | |
174 | 174 | $this->user_info = $this->setup_user_info(); |
175 | 175 | |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | $this->company = $this->user_info['company']; |
179 | 179 | $this->vat_number = $this->user_info['vat_number']; |
180 | 180 | $this->vat_rate = $this->user_info['vat_rate']; |
181 | - $this->adddress_confirmed = $this->user_info['adddress_confirmed']; |
|
181 | + $this->adddress_confirmed = $this->user_info['adddress_confirmed']; |
|
182 | 182 | $this->address = $this->user_info['address']; |
183 | 183 | $this->city = $this->user_info['city']; |
184 | 184 | $this->country = $this->user_info['country']; |
@@ -193,39 +193,39 @@ discard block |
||
193 | 193 | // Other Identifiers |
194 | 194 | $this->key = $this->setup_invoice_key(); |
195 | 195 | $this->number = $this->setup_invoice_number(); |
196 | - $this->title = !empty( $invoice->post_title ) ? $invoice->post_title : $this->number; |
|
196 | + $this->title = !empty($invoice->post_title) ? $invoice->post_title : $this->number; |
|
197 | 197 | |
198 | - $this->full_name = trim( $this->first_name . ' '. $this->last_name ); |
|
198 | + $this->full_name = trim($this->first_name . ' ' . $this->last_name); |
|
199 | 199 | |
200 | 200 | // Allow extensions to add items to this object via hook |
201 | - do_action( 'wpinv_setup_invoice', $this, $invoice_id ); |
|
201 | + do_action('wpinv_setup_invoice', $this, $invoice_id); |
|
202 | 202 | |
203 | 203 | return true; |
204 | 204 | } |
205 | 205 | |
206 | - private function setup_status_nicename( $status ) { |
|
207 | - $all_invoice_statuses = wpinv_get_invoice_statuses( true, true, $this ); |
|
206 | + private function setup_status_nicename($status) { |
|
207 | + $all_invoice_statuses = wpinv_get_invoice_statuses(true, true, $this); |
|
208 | 208 | |
209 | - if ( $this->is_quote() && class_exists( 'Wpinv_Quotes_Shared' ) ) { |
|
210 | - $all_invoice_statuses = Wpinv_Quotes_Shared::wpinv_get_quote_statuses(); |
|
209 | + if ($this->is_quote() && class_exists('Wpinv_Quotes_Shared')) { |
|
210 | + $all_invoice_statuses = Wpinv_Quotes_Shared::wpinv_get_quote_statuses(); |
|
211 | 211 | } |
212 | - $status = isset( $all_invoice_statuses[$status] ) ? $all_invoice_statuses[$status] : __( $status, 'invoicing' ); |
|
212 | + $status = isset($all_invoice_statuses[$status]) ? $all_invoice_statuses[$status] : __($status, 'invoicing'); |
|
213 | 213 | |
214 | - return apply_filters( 'setup_status_nicename', $status ); |
|
214 | + return apply_filters('setup_status_nicename', $status); |
|
215 | 215 | } |
216 | 216 | |
217 | - private function setup_post_name( $post = NULL ) { |
|
217 | + private function setup_post_name($post = NULL) { |
|
218 | 218 | global $wpdb; |
219 | 219 | |
220 | 220 | $post_name = ''; |
221 | 221 | |
222 | - if ( !empty( $post ) ) { |
|
223 | - if( !empty( $post->post_name ) ) { |
|
222 | + if (!empty($post)) { |
|
223 | + if (!empty($post->post_name)) { |
|
224 | 224 | $post_name = $post->post_name; |
225 | - } else if ( !empty( $post->ID ) ) { |
|
226 | - $post_name = wpinv_generate_post_name( $post->ID ); |
|
225 | + } else if (!empty($post->ID)) { |
|
226 | + $post_name = wpinv_generate_post_name($post->ID); |
|
227 | 227 | |
228 | - $wpdb->update( $wpdb->posts, array( 'post_name' => $post_name ), array( 'ID' => $post->ID ) ); |
|
228 | + $wpdb->update($wpdb->posts, array('post_name' => $post_name), array('ID' => $post->ID)); |
|
229 | 229 | } |
230 | 230 | } |
231 | 231 | |
@@ -233,12 +233,12 @@ discard block |
||
233 | 233 | } |
234 | 234 | |
235 | 235 | private function setup_due_date() { |
236 | - $due_date = $this->get_meta( '_wpinv_due_date' ); |
|
236 | + $due_date = $this->get_meta('_wpinv_due_date'); |
|
237 | 237 | |
238 | - if ( empty( $due_date ) ) { |
|
239 | - $overdue_time = strtotime( $this->date ) + ( DAY_IN_SECONDS * absint( wpinv_get_option( 'overdue_days' ) ) ); |
|
240 | - $due_date = date_i18n( 'Y-m-d', $overdue_time ); |
|
241 | - } else if ( $due_date == 'none' ) { |
|
238 | + if (empty($due_date)) { |
|
239 | + $overdue_time = strtotime($this->date) + (DAY_IN_SECONDS * absint(wpinv_get_option('overdue_days'))); |
|
240 | + $due_date = date_i18n('Y-m-d', $overdue_time); |
|
241 | + } else if ($due_date == 'none') { |
|
242 | 242 | $due_date = ''; |
243 | 243 | } |
244 | 244 | |
@@ -246,67 +246,67 @@ discard block |
||
246 | 246 | } |
247 | 247 | |
248 | 248 | private function setup_completed_date() { |
249 | - $invoice = get_post( $this->ID ); |
|
249 | + $invoice = get_post($this->ID); |
|
250 | 250 | |
251 | - if ( 'wpi-pending' == $invoice->post_status || 'preapproved' == $invoice->post_status ) { |
|
251 | + if ('wpi-pending' == $invoice->post_status || 'preapproved' == $invoice->post_status) { |
|
252 | 252 | return false; // This invoice was never paid |
253 | 253 | } |
254 | 254 | |
255 | - $date = ( $date = $this->get_meta( '_wpinv_completed_date', true ) ) ? $date : $invoice->modified_date; |
|
255 | + $date = ($date = $this->get_meta('_wpinv_completed_date', true)) ? $date : $invoice->modified_date; |
|
256 | 256 | |
257 | 257 | return $date; |
258 | 258 | } |
259 | 259 | |
260 | 260 | private function setup_cart_details() { |
261 | - $cart_details = isset( $this->payment_meta['cart_details'] ) ? maybe_unserialize( $this->payment_meta['cart_details'] ) : array(); |
|
261 | + $cart_details = isset($this->payment_meta['cart_details']) ? maybe_unserialize($this->payment_meta['cart_details']) : array(); |
|
262 | 262 | return $cart_details; |
263 | 263 | } |
264 | 264 | |
265 | 265 | public function array_convert() { |
266 | - return get_object_vars( $this ); |
|
266 | + return get_object_vars($this); |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | private function setup_items() { |
270 | - $items = isset( $this->payment_meta['items'] ) ? maybe_unserialize( $this->payment_meta['items'] ) : array(); |
|
270 | + $items = isset($this->payment_meta['items']) ? maybe_unserialize($this->payment_meta['items']) : array(); |
|
271 | 271 | return $items; |
272 | 272 | } |
273 | 273 | |
274 | 274 | private function setup_fees() { |
275 | - $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array(); |
|
275 | + $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array(); |
|
276 | 276 | return $payment_fees; |
277 | 277 | } |
278 | 278 | |
279 | 279 | private function setup_currency() { |
280 | - $currency = isset( $this->payment_meta['currency'] ) ? $this->payment_meta['currency'] : apply_filters( 'wpinv_currency_default', wpinv_get_currency(), $this ); |
|
280 | + $currency = isset($this->payment_meta['currency']) ? $this->payment_meta['currency'] : apply_filters('wpinv_currency_default', wpinv_get_currency(), $this); |
|
281 | 281 | return $currency; |
282 | 282 | } |
283 | 283 | |
284 | 284 | private function setup_discount() { |
285 | 285 | //$discount = $this->get_meta( '_wpinv_discount', true ); |
286 | - $discount = (float)$this->subtotal - ( (float)$this->total - (float)$this->tax - (float)$this->fees_total ); |
|
287 | - if ( $discount < 0 ) { |
|
286 | + $discount = (float) $this->subtotal - ((float) $this->total - (float) $this->tax - (float) $this->fees_total); |
|
287 | + if ($discount < 0) { |
|
288 | 288 | $discount = 0; |
289 | 289 | } |
290 | - $discount = wpinv_round_amount( $discount ); |
|
290 | + $discount = wpinv_round_amount($discount); |
|
291 | 291 | |
292 | 292 | return $discount; |
293 | 293 | } |
294 | 294 | |
295 | 295 | private function setup_discount_code() { |
296 | - $discount_code = !empty( $this->discounts ) ? $this->discounts : $this->get_meta( '_wpinv_discount_code', true ); |
|
296 | + $discount_code = !empty($this->discounts) ? $this->discounts : $this->get_meta('_wpinv_discount_code', true); |
|
297 | 297 | return $discount_code; |
298 | 298 | } |
299 | 299 | |
300 | 300 | private function setup_tax() { |
301 | 301 | |
302 | - $tax = $this->get_meta( '_wpinv_tax', true ); |
|
302 | + $tax = $this->get_meta('_wpinv_tax', true); |
|
303 | 303 | |
304 | 304 | // We don't have tax as it's own meta and no meta was passed |
305 | - if ( '' === $tax ) { |
|
306 | - $tax = isset( $this->payment_meta['tax'] ) ? $this->payment_meta['tax'] : 0; |
|
305 | + if ('' === $tax) { |
|
306 | + $tax = isset($this->payment_meta['tax']) ? $this->payment_meta['tax'] : 0; |
|
307 | 307 | } |
308 | 308 | |
309 | - if ( $tax < 0 || ! $this->is_taxable() ) { |
|
309 | + if ($tax < 0 || !$this->is_taxable()) { |
|
310 | 310 | $tax = 0; |
311 | 311 | } |
312 | 312 | |
@@ -317,16 +317,16 @@ discard block |
||
317 | 317 | * If taxes are enabled, allow users to enable/disable taxes per invoice. |
318 | 318 | */ |
319 | 319 | private function setup_is_taxable() { |
320 | - return (int) $this->get_meta( '_wpinv_disable_taxes', true ); |
|
320 | + return (int) $this->get_meta('_wpinv_disable_taxes', true); |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | private function setup_subtotal() { |
324 | 324 | $subtotal = 0; |
325 | 325 | $cart_details = $this->cart_details; |
326 | 326 | |
327 | - if ( is_array( $cart_details ) ) { |
|
328 | - foreach ( $cart_details as $item ) { |
|
329 | - if ( isset( $item['subtotal'] ) ) { |
|
327 | + if (is_array($cart_details)) { |
|
328 | + foreach ($cart_details as $item) { |
|
329 | + if (isset($item['subtotal'])) { |
|
330 | 330 | $subtotal += $item['subtotal']; |
331 | 331 | } |
332 | 332 | } |
@@ -340,23 +340,23 @@ discard block |
||
340 | 340 | } |
341 | 341 | |
342 | 342 | private function setup_discounts() { |
343 | - $discounts = ! empty( $this->payment_meta['user_info']['discount'] ) ? $this->payment_meta['user_info']['discount'] : array(); |
|
343 | + $discounts = !empty($this->payment_meta['user_info']['discount']) ? $this->payment_meta['user_info']['discount'] : array(); |
|
344 | 344 | return $discounts; |
345 | 345 | } |
346 | 346 | |
347 | 347 | private function setup_total() { |
348 | - $amount = $this->get_meta( '_wpinv_total', true ); |
|
348 | + $amount = $this->get_meta('_wpinv_total', true); |
|
349 | 349 | |
350 | - if ( empty( $amount ) && '0.00' != $amount ) { |
|
351 | - $meta = $this->get_meta( '_wpinv_payment_meta', true ); |
|
352 | - $meta = maybe_unserialize( $meta ); |
|
350 | + if (empty($amount) && '0.00' != $amount) { |
|
351 | + $meta = $this->get_meta('_wpinv_payment_meta', true); |
|
352 | + $meta = maybe_unserialize($meta); |
|
353 | 353 | |
354 | - if ( isset( $meta['amount'] ) ) { |
|
354 | + if (isset($meta['amount'])) { |
|
355 | 355 | $amount = $meta['amount']; |
356 | 356 | } |
357 | 357 | } |
358 | 358 | |
359 | - if($amount < 0){ |
|
359 | + if ($amount < 0) { |
|
360 | 360 | $amount = 0; |
361 | 361 | } |
362 | 362 | |
@@ -364,13 +364,13 @@ discard block |
||
364 | 364 | } |
365 | 365 | |
366 | 366 | private function setup_mode() { |
367 | - return $this->get_meta( '_wpinv_mode' ); |
|
367 | + return $this->get_meta('_wpinv_mode'); |
|
368 | 368 | } |
369 | 369 | |
370 | 370 | private function setup_gateway() { |
371 | - $gateway = $this->get_meta( '_wpinv_gateway' ); |
|
371 | + $gateway = $this->get_meta('_wpinv_gateway'); |
|
372 | 372 | |
373 | - if ( empty( $gateway ) && 'publish' === $this->status ) { |
|
373 | + if (empty($gateway) && 'publish' === $this->status) { |
|
374 | 374 | $gateway = 'manual'; |
375 | 375 | } |
376 | 376 | |
@@ -378,23 +378,23 @@ discard block |
||
378 | 378 | } |
379 | 379 | |
380 | 380 | private function setup_gateway_title() { |
381 | - $gateway_title = wpinv_get_gateway_checkout_label( $this->gateway ); |
|
381 | + $gateway_title = wpinv_get_gateway_checkout_label($this->gateway); |
|
382 | 382 | return $gateway_title; |
383 | 383 | } |
384 | 384 | |
385 | 385 | private function setup_transaction_id() { |
386 | - $transaction_id = $this->get_meta( '_wpinv_transaction_id' ); |
|
386 | + $transaction_id = $this->get_meta('_wpinv_transaction_id'); |
|
387 | 387 | |
388 | - if ( empty( $transaction_id ) || (int) $transaction_id === (int) $this->ID ) { |
|
388 | + if (empty($transaction_id) || (int) $transaction_id === (int) $this->ID) { |
|
389 | 389 | $gateway = $this->gateway; |
390 | - $transaction_id = apply_filters( 'wpinv_get_invoice_transaction_id-' . $gateway, $this->ID ); |
|
390 | + $transaction_id = apply_filters('wpinv_get_invoice_transaction_id-' . $gateway, $this->ID); |
|
391 | 391 | } |
392 | 392 | |
393 | 393 | return $transaction_id; |
394 | 394 | } |
395 | 395 | |
396 | 396 | private function setup_ip() { |
397 | - $ip = $this->get_meta( '_wpinv_user_ip' ); |
|
397 | + $ip = $this->get_meta('_wpinv_user_ip'); |
|
398 | 398 | return $ip; |
399 | 399 | } |
400 | 400 | |
@@ -404,62 +404,62 @@ discard block |
||
404 | 404 | ///} |
405 | 405 | |
406 | 406 | private function setup_first_name() { |
407 | - $first_name = $this->get_meta( '_wpinv_first_name' ); |
|
407 | + $first_name = $this->get_meta('_wpinv_first_name'); |
|
408 | 408 | return $first_name; |
409 | 409 | } |
410 | 410 | |
411 | 411 | private function setup_last_name() { |
412 | - $last_name = $this->get_meta( '_wpinv_last_name' ); |
|
412 | + $last_name = $this->get_meta('_wpinv_last_name'); |
|
413 | 413 | return $last_name; |
414 | 414 | } |
415 | 415 | |
416 | 416 | private function setup_company() { |
417 | - $company = $this->get_meta( '_wpinv_company' ); |
|
417 | + $company = $this->get_meta('_wpinv_company'); |
|
418 | 418 | return $company; |
419 | 419 | } |
420 | 420 | |
421 | 421 | private function setup_vat_number() { |
422 | - $vat_number = $this->get_meta( '_wpinv_vat_number' ); |
|
422 | + $vat_number = $this->get_meta('_wpinv_vat_number'); |
|
423 | 423 | return $vat_number; |
424 | 424 | } |
425 | 425 | |
426 | 426 | private function setup_vat_rate() { |
427 | - $vat_rate = $this->get_meta( '_wpinv_vat_rate' ); |
|
427 | + $vat_rate = $this->get_meta('_wpinv_vat_rate'); |
|
428 | 428 | return $vat_rate; |
429 | 429 | } |
430 | 430 | |
431 | 431 | private function setup_adddress_confirmed() { |
432 | - $adddress_confirmed = $this->get_meta( '_wpinv_adddress_confirmed' ); |
|
432 | + $adddress_confirmed = $this->get_meta('_wpinv_adddress_confirmed'); |
|
433 | 433 | return $adddress_confirmed; |
434 | 434 | } |
435 | 435 | |
436 | 436 | private function setup_phone() { |
437 | - $phone = $this->get_meta( '_wpinv_phone' ); |
|
437 | + $phone = $this->get_meta('_wpinv_phone'); |
|
438 | 438 | return $phone; |
439 | 439 | } |
440 | 440 | |
441 | 441 | private function setup_address() { |
442 | - $address = $this->get_meta( '_wpinv_address', true ); |
|
442 | + $address = $this->get_meta('_wpinv_address', true); |
|
443 | 443 | return $address; |
444 | 444 | } |
445 | 445 | |
446 | 446 | private function setup_city() { |
447 | - $city = $this->get_meta( '_wpinv_city', true ); |
|
447 | + $city = $this->get_meta('_wpinv_city', true); |
|
448 | 448 | return $city; |
449 | 449 | } |
450 | 450 | |
451 | 451 | private function setup_country() { |
452 | - $country = $this->get_meta( '_wpinv_country', true ); |
|
452 | + $country = $this->get_meta('_wpinv_country', true); |
|
453 | 453 | return $country; |
454 | 454 | } |
455 | 455 | |
456 | 456 | private function setup_state() { |
457 | - $state = $this->get_meta( '_wpinv_state', true ); |
|
457 | + $state = $this->get_meta('_wpinv_state', true); |
|
458 | 458 | return $state; |
459 | 459 | } |
460 | 460 | |
461 | 461 | private function setup_zip() { |
462 | - $zip = $this->get_meta( '_wpinv_zip', true ); |
|
462 | + $zip = $this->get_meta('_wpinv_zip', true); |
|
463 | 463 | return $zip; |
464 | 464 | } |
465 | 465 | |
@@ -468,7 +468,7 @@ discard block |
||
468 | 468 | 'user_id' => $this->user_id, |
469 | 469 | 'first_name' => $this->first_name, |
470 | 470 | 'last_name' => $this->last_name, |
471 | - 'email' => get_the_author_meta( 'email', $this->user_id ), |
|
471 | + 'email' => get_the_author_meta('email', $this->user_id), |
|
472 | 472 | 'phone' => $this->phone, |
473 | 473 | 'address' => $this->address, |
474 | 474 | 'city' => $this->city, |
@@ -483,12 +483,12 @@ discard block |
||
483 | 483 | ); |
484 | 484 | |
485 | 485 | $user_info = array(); |
486 | - if ( isset( $this->payment_meta['user_info'] ) ) { |
|
487 | - $user_info = maybe_unserialize( $this->payment_meta['user_info'] ); |
|
486 | + if (isset($this->payment_meta['user_info'])) { |
|
487 | + $user_info = maybe_unserialize($this->payment_meta['user_info']); |
|
488 | 488 | |
489 | - if ( !empty( $user_info ) && isset( $user_info['user_id'] ) && $post = get_post( $this->ID ) ) { |
|
489 | + if (!empty($user_info) && isset($user_info['user_id']) && $post = get_post($this->ID)) { |
|
490 | 490 | $this->user_id = $post->post_author; |
491 | - $this->email = get_the_author_meta( 'email', $this->user_id ); |
|
491 | + $this->email = get_the_author_meta('email', $this->user_id); |
|
492 | 492 | |
493 | 493 | $user_info['user_id'] = $this->user_id; |
494 | 494 | $user_info['email'] = $this->email; |
@@ -497,13 +497,13 @@ discard block |
||
497 | 497 | } |
498 | 498 | } |
499 | 499 | |
500 | - $user_info = wp_parse_args( $user_info, $defaults ); |
|
500 | + $user_info = wp_parse_args($user_info, $defaults); |
|
501 | 501 | |
502 | 502 | // Get the user, but only if it's been created |
503 | - $user = get_userdata( $this->user_id ); |
|
503 | + $user = get_userdata($this->user_id); |
|
504 | 504 | |
505 | - if ( !empty( $user ) && $user->ID > 0 ) { |
|
506 | - if ( empty( $user_info ) ) { |
|
505 | + if (!empty($user) && $user->ID > 0) { |
|
506 | + if (empty($user_info)) { |
|
507 | 507 | $user_info = array( |
508 | 508 | 'user_id' => $user->ID, |
509 | 509 | 'first_name' => $user->first_name, |
@@ -512,23 +512,23 @@ discard block |
||
512 | 512 | 'discount' => '', |
513 | 513 | ); |
514 | 514 | } else { |
515 | - foreach ( $user_info as $key => $value ) { |
|
516 | - if ( ! empty( $value ) ) { |
|
515 | + foreach ($user_info as $key => $value) { |
|
516 | + if (!empty($value)) { |
|
517 | 517 | continue; |
518 | 518 | } |
519 | 519 | |
520 | - switch( $key ) { |
|
520 | + switch ($key) { |
|
521 | 521 | case 'user_id': |
522 | - $user_info[ $key ] = $user->ID; |
|
522 | + $user_info[$key] = $user->ID; |
|
523 | 523 | break; |
524 | 524 | case 'first_name': |
525 | - $user_info[ $key ] = $user->first_name; |
|
525 | + $user_info[$key] = $user->first_name; |
|
526 | 526 | break; |
527 | 527 | case 'last_name': |
528 | - $user_info[ $key ] = $user->last_name; |
|
528 | + $user_info[$key] = $user->last_name; |
|
529 | 529 | break; |
530 | 530 | case 'email': |
531 | - $user_info[ $key ] = $user->user_email; |
|
531 | + $user_info[$key] = $user->user_email; |
|
532 | 532 | break; |
533 | 533 | } |
534 | 534 | } |
@@ -539,25 +539,25 @@ discard block |
||
539 | 539 | } |
540 | 540 | |
541 | 541 | private function setup_invoice_key() { |
542 | - $key = $this->get_meta( '_wpinv_key', true ); |
|
542 | + $key = $this->get_meta('_wpinv_key', true); |
|
543 | 543 | |
544 | 544 | return $key; |
545 | 545 | } |
546 | 546 | |
547 | 547 | private function setup_invoice_number() { |
548 | - $number = $this->get_meta( '_wpinv_number', true ); |
|
548 | + $number = $this->get_meta('_wpinv_number', true); |
|
549 | 549 | |
550 | - if ( !$number ) { |
|
550 | + if (!$number) { |
|
551 | 551 | $number = $this->ID; |
552 | 552 | |
553 | - if ( $this->status == 'auto-draft' ) { |
|
554 | - if ( wpinv_sequential_number_active( $this->post_type ) ) { |
|
555 | - $next_number = wpinv_get_next_invoice_number( $this->post_type ); |
|
553 | + if ($this->status == 'auto-draft') { |
|
554 | + if (wpinv_sequential_number_active($this->post_type)) { |
|
555 | + $next_number = wpinv_get_next_invoice_number($this->post_type); |
|
556 | 556 | $number = $next_number; |
557 | 557 | } |
558 | 558 | } |
559 | 559 | |
560 | - $number = wpinv_format_invoice_number( $number, $this->post_type ); |
|
560 | + $number = wpinv_format_invoice_number($number, $this->post_type); |
|
561 | 561 | } |
562 | 562 | |
563 | 563 | return $number; |
@@ -566,10 +566,10 @@ discard block |
||
566 | 566 | private function insert_invoice() { |
567 | 567 | global $wpdb; |
568 | 568 | |
569 | - if ( empty( $this->post_type ) ) { |
|
570 | - if ( !empty( $this->ID ) && $post_type = get_post_type( $this->ID ) ) { |
|
569 | + if (empty($this->post_type)) { |
|
570 | + if (!empty($this->ID) && $post_type = get_post_type($this->ID)) { |
|
571 | 571 | $this->post_type = $post_type; |
572 | - } else if ( !empty( $this->parent_invoice ) && $post_type = get_post_type( $this->parent_invoice ) ) { |
|
572 | + } else if (!empty($this->parent_invoice) && $post_type = get_post_type($this->parent_invoice)) { |
|
573 | 573 | $this->post_type = $post_type; |
574 | 574 | } else { |
575 | 575 | $this->post_type = 'wpi_invoice'; |
@@ -577,16 +577,16 @@ discard block |
||
577 | 577 | } |
578 | 578 | |
579 | 579 | $invoice_number = $this->ID; |
580 | - if ( $number = $this->get_meta( '_wpinv_number', true ) ) { |
|
580 | + if ($number = $this->get_meta('_wpinv_number', true)) { |
|
581 | 581 | $invoice_number = $number; |
582 | 582 | } |
583 | 583 | |
584 | - if ( empty( $this->key ) ) { |
|
584 | + if (empty($this->key)) { |
|
585 | 585 | $this->key = self::generate_key(); |
586 | 586 | $this->pending['key'] = $this->key; |
587 | 587 | } |
588 | 588 | |
589 | - if ( empty( $this->ip ) ) { |
|
589 | + if (empty($this->ip)) { |
|
590 | 590 | $this->ip = wpinv_get_ip(); |
591 | 591 | $this->pending['ip'] = $this->ip; |
592 | 592 | } |
@@ -623,61 +623,61 @@ discard block |
||
623 | 623 | 'post_status' => $this->status, |
624 | 624 | 'post_author' => $this->user_id, |
625 | 625 | 'post_type' => $this->post_type, |
626 | - 'post_date' => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time( 'mysql' ), |
|
627 | - 'post_date_gmt' => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date( $this->date ) : current_time( 'mysql', 1 ), |
|
626 | + 'post_date' => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time('mysql'), |
|
627 | + 'post_date_gmt' => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date($this->date) : current_time('mysql', 1), |
|
628 | 628 | 'post_parent' => $this->parent_invoice, |
629 | 629 | ); |
630 | - $args = apply_filters( 'wpinv_insert_invoice_args', $post_data, $this ); |
|
630 | + $args = apply_filters('wpinv_insert_invoice_args', $post_data, $this); |
|
631 | 631 | |
632 | 632 | // Create a blank invoice |
633 | - if ( !empty( $this->ID ) ) { |
|
634 | - $args['ID'] = $this->ID; |
|
633 | + if (!empty($this->ID)) { |
|
634 | + $args['ID'] = $this->ID; |
|
635 | 635 | |
636 | - $invoice_id = wp_update_post( $args, true ); |
|
636 | + $invoice_id = wp_update_post($args, true); |
|
637 | 637 | } else { |
638 | - $invoice_id = wp_insert_post( $args, true ); |
|
638 | + $invoice_id = wp_insert_post($args, true); |
|
639 | 639 | } |
640 | 640 | |
641 | - if ( is_wp_error( $invoice_id ) ) { |
|
641 | + if (is_wp_error($invoice_id)) { |
|
642 | 642 | return false; |
643 | 643 | } |
644 | 644 | |
645 | - if ( !empty( $invoice_id ) ) { |
|
645 | + if (!empty($invoice_id)) { |
|
646 | 646 | $this->ID = $invoice_id; |
647 | 647 | $this->_ID = $invoice_id; |
648 | 648 | |
649 | - $this->payment_meta = apply_filters( 'wpinv_payment_meta', $this->payment_meta, $payment_data ); |
|
650 | - if ( ! empty( $this->payment_meta['fees'] ) ) { |
|
651 | - $this->fees = array_merge( $this->fees, $this->payment_meta['fees'] ); |
|
652 | - foreach( $this->fees as $fee ) { |
|
653 | - $this->increase_fees( $fee['amount'] ); |
|
649 | + $this->payment_meta = apply_filters('wpinv_payment_meta', $this->payment_meta, $payment_data); |
|
650 | + if (!empty($this->payment_meta['fees'])) { |
|
651 | + $this->fees = array_merge($this->fees, $this->payment_meta['fees']); |
|
652 | + foreach ($this->fees as $fee) { |
|
653 | + $this->increase_fees($fee['amount']); |
|
654 | 654 | } |
655 | 655 | } |
656 | 656 | |
657 | - $this->update_meta( '_wpinv_payment_meta', $this->payment_meta ); |
|
657 | + $this->update_meta('_wpinv_payment_meta', $this->payment_meta); |
|
658 | 658 | $this->new = true; |
659 | 659 | } |
660 | 660 | |
661 | 661 | return $this->ID; |
662 | 662 | } |
663 | 663 | |
664 | - public function save( $setup = false ) { |
|
664 | + public function save($setup = false) { |
|
665 | 665 | global $wpi_session; |
666 | 666 | |
667 | 667 | $saved = false; |
668 | - if ( empty( $this->items ) ) { |
|
668 | + if (empty($this->items)) { |
|
669 | 669 | return $saved; // Don't save empty invoice. |
670 | 670 | } |
671 | 671 | |
672 | - if ( empty( $this->key ) ) { |
|
672 | + if (empty($this->key)) { |
|
673 | 673 | $this->key = self::generate_key(); |
674 | 674 | $this->pending['key'] = $this->key; |
675 | 675 | } |
676 | 676 | |
677 | - if ( empty( $this->ID ) ) { |
|
677 | + if (empty($this->ID)) { |
|
678 | 678 | $invoice_id = $this->insert_invoice(); |
679 | 679 | |
680 | - if ( false === $invoice_id ) { |
|
680 | + if (false === $invoice_id) { |
|
681 | 681 | $saved = false; |
682 | 682 | } else { |
683 | 683 | $this->ID = $invoice_id; |
@@ -685,27 +685,27 @@ discard block |
||
685 | 685 | } |
686 | 686 | |
687 | 687 | // If we have something pending, let's save it |
688 | - if ( !empty( $this->pending ) ) { |
|
688 | + if (!empty($this->pending)) { |
|
689 | 689 | $total_increase = 0; |
690 | 690 | $total_decrease = 0; |
691 | 691 | |
692 | - foreach ( $this->pending as $key => $value ) { |
|
693 | - switch( $key ) { |
|
692 | + foreach ($this->pending as $key => $value) { |
|
693 | + switch ($key) { |
|
694 | 694 | case 'items': |
695 | 695 | // Update totals for pending items |
696 | - foreach ( $this->pending[ $key ] as $item ) { |
|
697 | - switch( $item['action'] ) { |
|
696 | + foreach ($this->pending[$key] as $item) { |
|
697 | + switch ($item['action']) { |
|
698 | 698 | case 'add': |
699 | 699 | $price = $item['price']; |
700 | 700 | $taxes = $item['tax']; |
701 | 701 | |
702 | - if ( 'publish' === $this->status ) { |
|
702 | + if ('publish' === $this->status) { |
|
703 | 703 | $total_increase += $price; |
704 | 704 | } |
705 | 705 | break; |
706 | 706 | |
707 | 707 | case 'remove': |
708 | - if ( 'publish' === $this->status ) { |
|
708 | + if ('publish' === $this->status) { |
|
709 | 709 | $total_decrease += $item['price']; |
710 | 710 | } |
711 | 711 | break; |
@@ -713,16 +713,16 @@ discard block |
||
713 | 713 | } |
714 | 714 | break; |
715 | 715 | case 'fees': |
716 | - if ( 'publish' !== $this->status ) { |
|
716 | + if ('publish' !== $this->status) { |
|
717 | 717 | break; |
718 | 718 | } |
719 | 719 | |
720 | - if ( empty( $this->pending[ $key ] ) ) { |
|
720 | + if (empty($this->pending[$key])) { |
|
721 | 721 | break; |
722 | 722 | } |
723 | 723 | |
724 | - foreach ( $this->pending[ $key ] as $fee ) { |
|
725 | - switch( $fee['action'] ) { |
|
724 | + foreach ($this->pending[$key] as $fee) { |
|
725 | + switch ($fee['action']) { |
|
726 | 726 | case 'add': |
727 | 727 | $total_increase += $fee['amount']; |
728 | 728 | break; |
@@ -734,86 +734,86 @@ discard block |
||
734 | 734 | } |
735 | 735 | break; |
736 | 736 | case 'status': |
737 | - $this->update_status( $this->status ); |
|
737 | + $this->update_status($this->status); |
|
738 | 738 | break; |
739 | 739 | case 'gateway': |
740 | - $this->update_meta( '_wpinv_gateway', $this->gateway ); |
|
740 | + $this->update_meta('_wpinv_gateway', $this->gateway); |
|
741 | 741 | break; |
742 | 742 | case 'mode': |
743 | - $this->update_meta( '_wpinv_mode', $this->mode ); |
|
743 | + $this->update_meta('_wpinv_mode', $this->mode); |
|
744 | 744 | break; |
745 | 745 | case 'transaction_id': |
746 | - $this->update_meta( '_wpinv_transaction_id', $this->transaction_id ); |
|
746 | + $this->update_meta('_wpinv_transaction_id', $this->transaction_id); |
|
747 | 747 | break; |
748 | 748 | case 'ip': |
749 | - $this->update_meta( '_wpinv_user_ip', $this->ip ); |
|
749 | + $this->update_meta('_wpinv_user_ip', $this->ip); |
|
750 | 750 | break; |
751 | 751 | ///case 'user_id': |
752 | 752 | ///$this->update_meta( '_wpinv_user_id', $this->user_id ); |
753 | 753 | ///$this->user_info['user_id'] = $this->user_id; |
754 | 754 | ///break; |
755 | 755 | case 'first_name': |
756 | - $this->update_meta( '_wpinv_first_name', $this->first_name ); |
|
756 | + $this->update_meta('_wpinv_first_name', $this->first_name); |
|
757 | 757 | $this->user_info['first_name'] = $this->first_name; |
758 | 758 | break; |
759 | 759 | case 'last_name': |
760 | - $this->update_meta( '_wpinv_last_name', $this->last_name ); |
|
760 | + $this->update_meta('_wpinv_last_name', $this->last_name); |
|
761 | 761 | $this->user_info['last_name'] = $this->last_name; |
762 | 762 | break; |
763 | 763 | case 'phone': |
764 | - $this->update_meta( '_wpinv_phone', $this->phone ); |
|
764 | + $this->update_meta('_wpinv_phone', $this->phone); |
|
765 | 765 | $this->user_info['phone'] = $this->phone; |
766 | 766 | break; |
767 | 767 | case 'address': |
768 | - $this->update_meta( '_wpinv_address', $this->address ); |
|
768 | + $this->update_meta('_wpinv_address', $this->address); |
|
769 | 769 | $this->user_info['address'] = $this->address; |
770 | 770 | break; |
771 | 771 | case 'city': |
772 | - $this->update_meta( '_wpinv_city', $this->city ); |
|
772 | + $this->update_meta('_wpinv_city', $this->city); |
|
773 | 773 | $this->user_info['city'] = $this->city; |
774 | 774 | break; |
775 | 775 | case 'country': |
776 | - $this->update_meta( '_wpinv_country', $this->country ); |
|
776 | + $this->update_meta('_wpinv_country', $this->country); |
|
777 | 777 | $this->user_info['country'] = $this->country; |
778 | 778 | break; |
779 | 779 | case 'state': |
780 | - $this->update_meta( '_wpinv_state', $this->state ); |
|
780 | + $this->update_meta('_wpinv_state', $this->state); |
|
781 | 781 | $this->user_info['state'] = $this->state; |
782 | 782 | break; |
783 | 783 | case 'zip': |
784 | - $this->update_meta( '_wpinv_zip', $this->zip ); |
|
784 | + $this->update_meta('_wpinv_zip', $this->zip); |
|
785 | 785 | $this->user_info['zip'] = $this->zip; |
786 | 786 | break; |
787 | 787 | case 'company': |
788 | - $this->update_meta( '_wpinv_company', $this->company ); |
|
788 | + $this->update_meta('_wpinv_company', $this->company); |
|
789 | 789 | $this->user_info['company'] = $this->company; |
790 | 790 | break; |
791 | 791 | case 'vat_number': |
792 | - $this->update_meta( '_wpinv_vat_number', $this->vat_number ); |
|
792 | + $this->update_meta('_wpinv_vat_number', $this->vat_number); |
|
793 | 793 | $this->user_info['vat_number'] = $this->vat_number; |
794 | 794 | |
795 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
796 | - if ( $this->vat_number && !empty( $vat_info ) && isset( $vat_info['number'] ) && isset( $vat_info['valid'] ) && $vat_info['number'] == $this->vat_number ) { |
|
797 | - $adddress_confirmed = isset( $vat_info['adddress_confirmed'] ) ? $vat_info['adddress_confirmed'] : false; |
|
798 | - $this->update_meta( '_wpinv_adddress_confirmed', (bool)$adddress_confirmed ); |
|
799 | - $this->user_info['adddress_confirmed'] = (bool)$adddress_confirmed; |
|
795 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
796 | + if ($this->vat_number && !empty($vat_info) && isset($vat_info['number']) && isset($vat_info['valid']) && $vat_info['number'] == $this->vat_number) { |
|
797 | + $adddress_confirmed = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false; |
|
798 | + $this->update_meta('_wpinv_adddress_confirmed', (bool) $adddress_confirmed); |
|
799 | + $this->user_info['adddress_confirmed'] = (bool) $adddress_confirmed; |
|
800 | 800 | } |
801 | 801 | |
802 | 802 | break; |
803 | 803 | case 'vat_rate': |
804 | - $this->update_meta( '_wpinv_vat_rate', $this->vat_rate ); |
|
804 | + $this->update_meta('_wpinv_vat_rate', $this->vat_rate); |
|
805 | 805 | $this->user_info['vat_rate'] = $this->vat_rate; |
806 | 806 | break; |
807 | 807 | case 'adddress_confirmed': |
808 | - $this->update_meta( '_wpinv_adddress_confirmed', $this->adddress_confirmed ); |
|
808 | + $this->update_meta('_wpinv_adddress_confirmed', $this->adddress_confirmed); |
|
809 | 809 | $this->user_info['adddress_confirmed'] = $this->adddress_confirmed; |
810 | 810 | break; |
811 | 811 | |
812 | 812 | case 'key': |
813 | - $this->update_meta( '_wpinv_key', $this->key ); |
|
813 | + $this->update_meta('_wpinv_key', $this->key); |
|
814 | 814 | break; |
815 | 815 | case 'disable_taxes': |
816 | - $this->update_meta( '_wpinv_disable_taxes', $this->disable_taxes ); |
|
816 | + $this->update_meta('_wpinv_disable_taxes', $this->disable_taxes); |
|
817 | 817 | break; |
818 | 818 | case 'date': |
819 | 819 | $args = array( |
@@ -822,49 +822,49 @@ discard block |
||
822 | 822 | 'edit_date' => true, |
823 | 823 | ); |
824 | 824 | |
825 | - wp_update_post( $args ); |
|
825 | + wp_update_post($args); |
|
826 | 826 | break; |
827 | 827 | case 'due_date': |
828 | - if ( empty( $this->due_date ) ) { |
|
828 | + if (empty($this->due_date)) { |
|
829 | 829 | $this->due_date = 'none'; |
830 | 830 | } |
831 | 831 | |
832 | - $this->update_meta( '_wpinv_due_date', $this->due_date ); |
|
832 | + $this->update_meta('_wpinv_due_date', $this->due_date); |
|
833 | 833 | break; |
834 | 834 | case 'completed_date': |
835 | - $this->update_meta( '_wpinv_completed_date', $this->completed_date ); |
|
835 | + $this->update_meta('_wpinv_completed_date', $this->completed_date); |
|
836 | 836 | break; |
837 | 837 | case 'discounts': |
838 | - if ( ! is_array( $this->discounts ) ) { |
|
839 | - $this->discounts = explode( ',', $this->discounts ); |
|
838 | + if (!is_array($this->discounts)) { |
|
839 | + $this->discounts = explode(',', $this->discounts); |
|
840 | 840 | } |
841 | 841 | |
842 | - $this->user_info['discount'] = implode( ',', $this->discounts ); |
|
842 | + $this->user_info['discount'] = implode(',', $this->discounts); |
|
843 | 843 | break; |
844 | 844 | case 'discount': |
845 | - $this->update_meta( '_wpinv_discount', wpinv_round_amount( $this->discount ) ); |
|
845 | + $this->update_meta('_wpinv_discount', wpinv_round_amount($this->discount)); |
|
846 | 846 | break; |
847 | 847 | case 'discount_code': |
848 | - $this->update_meta( '_wpinv_discount_code', $this->discount_code ); |
|
848 | + $this->update_meta('_wpinv_discount_code', $this->discount_code); |
|
849 | 849 | break; |
850 | 850 | case 'parent_invoice': |
851 | 851 | $args = array( |
852 | 852 | 'ID' => $this->ID, |
853 | 853 | 'post_parent' => $this->parent_invoice, |
854 | 854 | ); |
855 | - wp_update_post( $args ); |
|
855 | + wp_update_post($args); |
|
856 | 856 | break; |
857 | 857 | default: |
858 | - do_action( 'wpinv_save', $this, $key ); |
|
858 | + do_action('wpinv_save', $this, $key); |
|
859 | 859 | break; |
860 | 860 | } |
861 | 861 | } |
862 | 862 | |
863 | - $this->update_meta( '_wpinv_subtotal', wpinv_round_amount( $this->subtotal ) ); |
|
864 | - $this->update_meta( '_wpinv_total', wpinv_round_amount( $this->total ) ); |
|
865 | - $this->update_meta( '_wpinv_tax', wpinv_round_amount( $this->tax ) ); |
|
863 | + $this->update_meta('_wpinv_subtotal', wpinv_round_amount($this->subtotal)); |
|
864 | + $this->update_meta('_wpinv_total', wpinv_round_amount($this->total)); |
|
865 | + $this->update_meta('_wpinv_tax', wpinv_round_amount($this->tax)); |
|
866 | 866 | |
867 | - $this->items = array_values( $this->items ); |
|
867 | + $this->items = array_values($this->items); |
|
868 | 868 | |
869 | 869 | $new_meta = array( |
870 | 870 | 'items' => $this->items, |
@@ -875,12 +875,12 @@ discard block |
||
875 | 875 | ); |
876 | 876 | |
877 | 877 | $meta = $this->get_meta(); |
878 | - $merged_meta = array_merge( $meta, $new_meta ); |
|
878 | + $merged_meta = array_merge($meta, $new_meta); |
|
879 | 879 | |
880 | 880 | // Only save the payment meta if it's changed |
881 | - if ( md5( serialize( $meta ) ) !== md5( serialize( $merged_meta) ) ) { |
|
882 | - $updated = $this->update_meta( '_wpinv_payment_meta', $merged_meta ); |
|
883 | - if ( false !== $updated ) { |
|
881 | + if (md5(serialize($meta)) !== md5(serialize($merged_meta))) { |
|
882 | + $updated = $this->update_meta('_wpinv_payment_meta', $merged_meta); |
|
883 | + if (false !== $updated) { |
|
884 | 884 | $saved = true; |
885 | 885 | } |
886 | 886 | } |
@@ -888,15 +888,15 @@ discard block |
||
888 | 888 | $this->pending = array(); |
889 | 889 | $saved = true; |
890 | 890 | } else { |
891 | - $this->update_meta( '_wpinv_subtotal', wpinv_round_amount( $this->subtotal ) ); |
|
892 | - $this->update_meta( '_wpinv_total', wpinv_round_amount( $this->total ) ); |
|
893 | - $this->update_meta( '_wpinv_tax', wpinv_round_amount( $this->tax ) ); |
|
891 | + $this->update_meta('_wpinv_subtotal', wpinv_round_amount($this->subtotal)); |
|
892 | + $this->update_meta('_wpinv_total', wpinv_round_amount($this->total)); |
|
893 | + $this->update_meta('_wpinv_tax', wpinv_round_amount($this->tax)); |
|
894 | 894 | } |
895 | 895 | |
896 | - do_action( 'wpinv_invoice_save', $this, $saved ); |
|
896 | + do_action('wpinv_invoice_save', $this, $saved); |
|
897 | 897 | |
898 | - if ( true === $saved || $setup ) { |
|
899 | - $this->setup_invoice( $this->ID ); |
|
898 | + if (true === $saved || $setup) { |
|
899 | + $this->setup_invoice($this->ID); |
|
900 | 900 | } |
901 | 901 | |
902 | 902 | $this->refresh_item_ids(); |
@@ -904,7 +904,7 @@ discard block |
||
904 | 904 | return $saved; |
905 | 905 | } |
906 | 906 | |
907 | - public function add_fee( $args, $global = true ) { |
|
907 | + public function add_fee($args, $global = true) { |
|
908 | 908 | $default_args = array( |
909 | 909 | 'label' => '', |
910 | 910 | 'amount' => 0, |
@@ -914,75 +914,75 @@ discard block |
||
914 | 914 | 'item_id' => 0, |
915 | 915 | ); |
916 | 916 | |
917 | - $fee = wp_parse_args( $args, $default_args ); |
|
917 | + $fee = wp_parse_args($args, $default_args); |
|
918 | 918 | |
919 | - if ( empty( $fee['label'] ) ) { |
|
919 | + if (empty($fee['label'])) { |
|
920 | 920 | return false; |
921 | 921 | } |
922 | 922 | |
923 | - $fee['id'] = sanitize_title( $fee['label'] ); |
|
923 | + $fee['id'] = sanitize_title($fee['label']); |
|
924 | 924 | |
925 | - $this->fees[] = $fee; |
|
925 | + $this->fees[] = $fee; |
|
926 | 926 | |
927 | 927 | $added_fee = $fee; |
928 | 928 | $added_fee['action'] = 'add'; |
929 | 929 | $this->pending['fees'][] = $added_fee; |
930 | - reset( $this->fees ); |
|
930 | + reset($this->fees); |
|
931 | 931 | |
932 | - $this->increase_fees( $fee['amount'] ); |
|
932 | + $this->increase_fees($fee['amount']); |
|
933 | 933 | return true; |
934 | 934 | } |
935 | 935 | |
936 | - public function remove_fee( $key ) { |
|
936 | + public function remove_fee($key) { |
|
937 | 937 | $removed = false; |
938 | 938 | |
939 | - if ( is_numeric( $key ) ) { |
|
940 | - $removed = $this->remove_fee_by( 'index', $key ); |
|
939 | + if (is_numeric($key)) { |
|
940 | + $removed = $this->remove_fee_by('index', $key); |
|
941 | 941 | } |
942 | 942 | |
943 | 943 | return $removed; |
944 | 944 | } |
945 | 945 | |
946 | - public function remove_fee_by( $key, $value, $global = false ) { |
|
947 | - $allowed_fee_keys = apply_filters( 'wpinv_fee_keys', array( |
|
946 | + public function remove_fee_by($key, $value, $global = false) { |
|
947 | + $allowed_fee_keys = apply_filters('wpinv_fee_keys', array( |
|
948 | 948 | 'index', 'label', 'amount', 'type', |
949 | - ) ); |
|
949 | + )); |
|
950 | 950 | |
951 | - if ( ! in_array( $key, $allowed_fee_keys ) ) { |
|
951 | + if (!in_array($key, $allowed_fee_keys)) { |
|
952 | 952 | return false; |
953 | 953 | } |
954 | 954 | |
955 | 955 | $removed = false; |
956 | - if ( 'index' === $key && array_key_exists( $value, $this->fees ) ) { |
|
957 | - $removed_fee = $this->fees[ $value ]; |
|
956 | + if ('index' === $key && array_key_exists($value, $this->fees)) { |
|
957 | + $removed_fee = $this->fees[$value]; |
|
958 | 958 | $removed_fee['action'] = 'remove'; |
959 | 959 | $this->pending['fees'][] = $removed_fee; |
960 | 960 | |
961 | - $this->decrease_fees( $removed_fee['amount'] ); |
|
961 | + $this->decrease_fees($removed_fee['amount']); |
|
962 | 962 | |
963 | - unset( $this->fees[ $value ] ); |
|
963 | + unset($this->fees[$value]); |
|
964 | 964 | $removed = true; |
965 | - } else if ( 'index' !== $key ) { |
|
966 | - foreach ( $this->fees as $index => $fee ) { |
|
967 | - if ( isset( $fee[ $key ] ) && $fee[ $key ] == $value ) { |
|
965 | + } else if ('index' !== $key) { |
|
966 | + foreach ($this->fees as $index => $fee) { |
|
967 | + if (isset($fee[$key]) && $fee[$key] == $value) { |
|
968 | 968 | $removed_fee = $fee; |
969 | 969 | $removed_fee['action'] = 'remove'; |
970 | 970 | $this->pending['fees'][] = $removed_fee; |
971 | 971 | |
972 | - $this->decrease_fees( $removed_fee['amount'] ); |
|
972 | + $this->decrease_fees($removed_fee['amount']); |
|
973 | 973 | |
974 | - unset( $this->fees[ $index ] ); |
|
974 | + unset($this->fees[$index]); |
|
975 | 975 | $removed = true; |
976 | 976 | |
977 | - if ( false === $global ) { |
|
977 | + if (false === $global) { |
|
978 | 978 | break; |
979 | 979 | } |
980 | 980 | } |
981 | 981 | } |
982 | 982 | } |
983 | 983 | |
984 | - if ( true === $removed ) { |
|
985 | - $this->fees = array_values( $this->fees ); |
|
984 | + if (true === $removed) { |
|
985 | + $this->fees = array_values($this->fees); |
|
986 | 986 | } |
987 | 987 | |
988 | 988 | return $removed; |
@@ -990,35 +990,35 @@ discard block |
||
990 | 990 | |
991 | 991 | |
992 | 992 | |
993 | - public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) { |
|
993 | + public function add_note($note = '', $customer_type = false, $added_by_user = false, $system = false) { |
|
994 | 994 | // Bail if no note specified |
995 | - if( !$note ) { |
|
995 | + if (!$note) { |
|
996 | 996 | return false; |
997 | 997 | } |
998 | 998 | |
999 | - if ( empty( $this->ID ) ) |
|
999 | + if (empty($this->ID)) |
|
1000 | 1000 | return false; |
1001 | 1001 | |
1002 | - if ( ( ( is_user_logged_in() && wpinv_current_user_can_manage_invoicing() ) || $added_by_user ) && !$system ) { |
|
1003 | - $user = get_user_by( 'id', get_current_user_id() ); |
|
1002 | + if (((is_user_logged_in() && wpinv_current_user_can_manage_invoicing()) || $added_by_user) && !$system) { |
|
1003 | + $user = get_user_by('id', get_current_user_id()); |
|
1004 | 1004 | $comment_author = $user->display_name; |
1005 | 1005 | $comment_author_email = $user->user_email; |
1006 | 1006 | } else { |
1007 | 1007 | $comment_author = 'System'; |
1008 | 1008 | $comment_author_email = 'system@'; |
1009 | - $comment_author_email .= isset( $_SERVER['HTTP_HOST'] ) ? str_replace( 'www.', '', $_SERVER['HTTP_HOST'] ) : 'noreply.com'; |
|
1010 | - $comment_author_email = sanitize_email( $comment_author_email ); |
|
1009 | + $comment_author_email .= isset($_SERVER['HTTP_HOST']) ? str_replace('www.', '', $_SERVER['HTTP_HOST']) : 'noreply.com'; |
|
1010 | + $comment_author_email = sanitize_email($comment_author_email); |
|
1011 | 1011 | } |
1012 | 1012 | |
1013 | - do_action( 'wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type ); |
|
1013 | + do_action('wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type); |
|
1014 | 1014 | |
1015 | - $note_id = wp_insert_comment( wp_filter_comment( array( |
|
1015 | + $note_id = wp_insert_comment(wp_filter_comment(array( |
|
1016 | 1016 | 'comment_post_ID' => $this->ID, |
1017 | 1017 | 'comment_content' => $note, |
1018 | 1018 | 'comment_agent' => 'WPInvoicing', |
1019 | 1019 | 'user_id' => is_admin() ? get_current_user_id() : 0, |
1020 | - 'comment_date' => current_time( 'mysql' ), |
|
1021 | - 'comment_date_gmt' => current_time( 'mysql', 1 ), |
|
1020 | + 'comment_date' => current_time('mysql'), |
|
1021 | + 'comment_date_gmt' => current_time('mysql', 1), |
|
1022 | 1022 | 'comment_approved' => 1, |
1023 | 1023 | 'comment_parent' => 0, |
1024 | 1024 | 'comment_author' => $comment_author, |
@@ -1026,53 +1026,53 @@ discard block |
||
1026 | 1026 | 'comment_author_url' => '', |
1027 | 1027 | 'comment_author_email' => $comment_author_email, |
1028 | 1028 | 'comment_type' => 'wpinv_note' |
1029 | - ) ) ); |
|
1029 | + ))); |
|
1030 | 1030 | |
1031 | - do_action( 'wpinv_insert_payment_note', $note_id, $this->ID, $note ); |
|
1031 | + do_action('wpinv_insert_payment_note', $note_id, $this->ID, $note); |
|
1032 | 1032 | |
1033 | - if ( $customer_type ) { |
|
1034 | - add_comment_meta( $note_id, '_wpi_customer_note', 1 ); |
|
1033 | + if ($customer_type) { |
|
1034 | + add_comment_meta($note_id, '_wpi_customer_note', 1); |
|
1035 | 1035 | |
1036 | - do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $this->ID, 'user_note' => $note ) ); |
|
1036 | + do_action('wpinv_new_customer_note', array('invoice_id' => $this->ID, 'user_note' => $note)); |
|
1037 | 1037 | } |
1038 | 1038 | |
1039 | 1039 | return $note_id; |
1040 | 1040 | } |
1041 | 1041 | |
1042 | - private function increase_subtotal( $amount = 0.00 ) { |
|
1042 | + private function increase_subtotal($amount = 0.00) { |
|
1043 | 1043 | $amount = (float) $amount; |
1044 | 1044 | $this->subtotal += $amount; |
1045 | - $this->subtotal = wpinv_round_amount( $this->subtotal ); |
|
1045 | + $this->subtotal = wpinv_round_amount($this->subtotal); |
|
1046 | 1046 | |
1047 | 1047 | $this->recalculate_total(); |
1048 | 1048 | } |
1049 | 1049 | |
1050 | - private function decrease_subtotal( $amount = 0.00 ) { |
|
1050 | + private function decrease_subtotal($amount = 0.00) { |
|
1051 | 1051 | $amount = (float) $amount; |
1052 | 1052 | $this->subtotal -= $amount; |
1053 | - $this->subtotal = wpinv_round_amount( $this->subtotal ); |
|
1053 | + $this->subtotal = wpinv_round_amount($this->subtotal); |
|
1054 | 1054 | |
1055 | - if ( $this->subtotal < 0 ) { |
|
1055 | + if ($this->subtotal < 0) { |
|
1056 | 1056 | $this->subtotal = 0; |
1057 | 1057 | } |
1058 | 1058 | |
1059 | 1059 | $this->recalculate_total(); |
1060 | 1060 | } |
1061 | 1061 | |
1062 | - private function increase_fees( $amount = 0.00 ) { |
|
1063 | - $amount = (float)$amount; |
|
1062 | + private function increase_fees($amount = 0.00) { |
|
1063 | + $amount = (float) $amount; |
|
1064 | 1064 | $this->fees_total += $amount; |
1065 | - $this->fees_total = wpinv_round_amount( $this->fees_total ); |
|
1065 | + $this->fees_total = wpinv_round_amount($this->fees_total); |
|
1066 | 1066 | |
1067 | 1067 | $this->recalculate_total(); |
1068 | 1068 | } |
1069 | 1069 | |
1070 | - private function decrease_fees( $amount = 0.00 ) { |
|
1070 | + private function decrease_fees($amount = 0.00) { |
|
1071 | 1071 | $amount = (float) $amount; |
1072 | 1072 | $this->fees_total -= $amount; |
1073 | - $this->fees_total = wpinv_round_amount( $this->fees_total ); |
|
1073 | + $this->fees_total = wpinv_round_amount($this->fees_total); |
|
1074 | 1074 | |
1075 | - if ( $this->fees_total < 0 ) { |
|
1075 | + if ($this->fees_total < 0) { |
|
1076 | 1076 | $this->fees_total = 0; |
1077 | 1077 | } |
1078 | 1078 | |
@@ -1083,54 +1083,54 @@ discard block |
||
1083 | 1083 | global $wpi_nosave; |
1084 | 1084 | |
1085 | 1085 | $this->total = $this->subtotal + $this->tax + $this->fees_total; |
1086 | - $this->total = wpinv_round_amount( $this->total ); |
|
1086 | + $this->total = wpinv_round_amount($this->total); |
|
1087 | 1087 | |
1088 | - do_action( 'wpinv_invoice_recalculate_total', $this, $wpi_nosave ); |
|
1088 | + do_action('wpinv_invoice_recalculate_total', $this, $wpi_nosave); |
|
1089 | 1089 | } |
1090 | 1090 | |
1091 | - public function increase_tax( $amount = 0.00 ) { |
|
1091 | + public function increase_tax($amount = 0.00) { |
|
1092 | 1092 | $amount = (float) $amount; |
1093 | 1093 | $this->tax += $amount; |
1094 | 1094 | |
1095 | 1095 | $this->recalculate_total(); |
1096 | 1096 | } |
1097 | 1097 | |
1098 | - public function decrease_tax( $amount = 0.00 ) { |
|
1098 | + public function decrease_tax($amount = 0.00) { |
|
1099 | 1099 | $amount = (float) $amount; |
1100 | 1100 | $this->tax -= $amount; |
1101 | 1101 | |
1102 | - if ( $this->tax < 0 ) { |
|
1102 | + if ($this->tax < 0) { |
|
1103 | 1103 | $this->tax = 0; |
1104 | 1104 | } |
1105 | 1105 | |
1106 | 1106 | $this->recalculate_total(); |
1107 | 1107 | } |
1108 | 1108 | |
1109 | - public function update_status( $new_status = false, $note = '', $manual = false ) { |
|
1110 | - $old_status = ! empty( $this->old_status ) ? $this->old_status : get_post_status( $this->ID ); |
|
1109 | + public function update_status($new_status = false, $note = '', $manual = false) { |
|
1110 | + $old_status = !empty($this->old_status) ? $this->old_status : get_post_status($this->ID); |
|
1111 | 1111 | |
1112 | - if ( $old_status === $new_status && in_array( $new_status, array_keys( wpinv_get_invoice_statuses( true ) ) ) ) { |
|
1112 | + if ($old_status === $new_status && in_array($new_status, array_keys(wpinv_get_invoice_statuses(true)))) { |
|
1113 | 1113 | return false; // Don't permit status changes that aren't changes |
1114 | 1114 | } |
1115 | 1115 | |
1116 | - $do_change = apply_filters( 'wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status ); |
|
1116 | + $do_change = apply_filters('wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status); |
|
1117 | 1117 | $updated = false; |
1118 | 1118 | |
1119 | - if ( $do_change ) { |
|
1120 | - do_action( 'wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status ); |
|
1119 | + if ($do_change) { |
|
1120 | + do_action('wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status); |
|
1121 | 1121 | |
1122 | 1122 | $update_post_data = array(); |
1123 | 1123 | $update_post_data['ID'] = $this->ID; |
1124 | 1124 | $update_post_data['post_status'] = $new_status; |
1125 | - $update_post_data['edit_date'] = current_time( 'mysql', 0 ); |
|
1126 | - $update_post_data['edit_date_gmt'] = current_time( 'mysql', 1 ); |
|
1125 | + $update_post_data['edit_date'] = current_time('mysql', 0); |
|
1126 | + $update_post_data['edit_date_gmt'] = current_time('mysql', 1); |
|
1127 | 1127 | |
1128 | - $update_post_data = apply_filters( 'wpinv_update_invoice_status_fields', $update_post_data, $this->ID ); |
|
1128 | + $update_post_data = apply_filters('wpinv_update_invoice_status_fields', $update_post_data, $this->ID); |
|
1129 | 1129 | |
1130 | - $updated = wp_update_post( $update_post_data ); |
|
1130 | + $updated = wp_update_post($update_post_data); |
|
1131 | 1131 | |
1132 | 1132 | // Process any specific status functions |
1133 | - switch( $new_status ) { |
|
1133 | + switch ($new_status) { |
|
1134 | 1134 | case 'wpi-refunded': |
1135 | 1135 | $this->process_refund(); |
1136 | 1136 | break; |
@@ -1143,9 +1143,9 @@ discard block |
||
1143 | 1143 | } |
1144 | 1144 | |
1145 | 1145 | // Status was changed. |
1146 | - do_action( 'wpinv_status_' . $new_status, $this->ID, $old_status ); |
|
1147 | - do_action( 'wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status ); |
|
1148 | - do_action( 'wpinv_update_status', $this->ID, $new_status, $old_status ); |
|
1146 | + do_action('wpinv_status_' . $new_status, $this->ID, $old_status); |
|
1147 | + do_action('wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status); |
|
1148 | + do_action('wpinv_update_status', $this->ID, $new_status, $old_status); |
|
1149 | 1149 | } |
1150 | 1150 | |
1151 | 1151 | return $updated; |
@@ -1159,20 +1159,20 @@ discard block |
||
1159 | 1159 | $this->save(); |
1160 | 1160 | } |
1161 | 1161 | |
1162 | - public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) { |
|
1163 | - if ( empty( $meta_key ) ) { |
|
1162 | + public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') { |
|
1163 | + if (empty($meta_key)) { |
|
1164 | 1164 | return false; |
1165 | 1165 | } |
1166 | 1166 | |
1167 | - if ( $meta_key == 'key' || $meta_key == 'date' ) { |
|
1167 | + if ($meta_key == 'key' || $meta_key == 'date') { |
|
1168 | 1168 | $current_meta = $this->get_meta(); |
1169 | - $current_meta[ $meta_key ] = $meta_value; |
|
1169 | + $current_meta[$meta_key] = $meta_value; |
|
1170 | 1170 | |
1171 | 1171 | $meta_key = '_wpinv_payment_meta'; |
1172 | 1172 | $meta_value = $current_meta; |
1173 | 1173 | } |
1174 | 1174 | |
1175 | - $meta_value = apply_filters( 'wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID ); |
|
1175 | + $meta_value = apply_filters('wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID); |
|
1176 | 1176 | |
1177 | 1177 | // Do not update created date on invoice marked as paid. |
1178 | 1178 | /*if ( $meta_key == '_wpinv_completed_date' && !empty( $meta_value ) ) { |
@@ -1187,45 +1187,45 @@ discard block |
||
1187 | 1187 | wp_update_post( $args ); |
1188 | 1188 | }*/ |
1189 | 1189 | |
1190 | - return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value ); |
|
1190 | + return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value); |
|
1191 | 1191 | } |
1192 | 1192 | |
1193 | 1193 | private function process_refund() { |
1194 | 1194 | $process_refund = true; |
1195 | 1195 | |
1196 | 1196 | // If the payment was not in publish, don't decrement stats as they were never incremented |
1197 | - if ( 'publish' != $this->old_status || 'wpi-refunded' != $this->status ) { |
|
1197 | + if ('publish' != $this->old_status || 'wpi-refunded' != $this->status) { |
|
1198 | 1198 | $process_refund = false; |
1199 | 1199 | } |
1200 | 1200 | |
1201 | 1201 | // Allow extensions to filter for their own payment types, Example: Recurring Payments |
1202 | - $process_refund = apply_filters( 'wpinv_should_process_refund', $process_refund, $this ); |
|
1202 | + $process_refund = apply_filters('wpinv_should_process_refund', $process_refund, $this); |
|
1203 | 1203 | |
1204 | - if ( false === $process_refund ) { |
|
1204 | + if (false === $process_refund) { |
|
1205 | 1205 | return; |
1206 | 1206 | } |
1207 | 1207 | |
1208 | - do_action( 'wpinv_pre_refund_invoice', $this ); |
|
1208 | + do_action('wpinv_pre_refund_invoice', $this); |
|
1209 | 1209 | |
1210 | - $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_refund', true, $this ); |
|
1211 | - $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_refund', true, $this ); |
|
1212 | - $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_refund', true, $this ); |
|
1210 | + $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_refund', true, $this); |
|
1211 | + $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_refund', true, $this); |
|
1212 | + $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_refund', true, $this); |
|
1213 | 1213 | |
1214 | - do_action( 'wpinv_post_refund_invoice', $this ); |
|
1214 | + do_action('wpinv_post_refund_invoice', $this); |
|
1215 | 1215 | } |
1216 | 1216 | |
1217 | 1217 | private function process_failure() { |
1218 | 1218 | $discounts = $this->discounts; |
1219 | - if ( empty( $discounts ) ) { |
|
1219 | + if (empty($discounts)) { |
|
1220 | 1220 | return; |
1221 | 1221 | } |
1222 | 1222 | |
1223 | - if ( ! is_array( $discounts ) ) { |
|
1224 | - $discounts = array_map( 'trim', explode( ',', $discounts ) ); |
|
1223 | + if (!is_array($discounts)) { |
|
1224 | + $discounts = array_map('trim', explode(',', $discounts)); |
|
1225 | 1225 | } |
1226 | 1226 | |
1227 | - foreach ( $discounts as $discount ) { |
|
1228 | - wpinv_decrease_discount_usage( $discount ); |
|
1227 | + foreach ($discounts as $discount) { |
|
1228 | + wpinv_decrease_discount_usage($discount); |
|
1229 | 1229 | } |
1230 | 1230 | } |
1231 | 1231 | |
@@ -1233,92 +1233,92 @@ discard block |
||
1233 | 1233 | $process_pending = true; |
1234 | 1234 | |
1235 | 1235 | // If the payment was not in publish or revoked status, don't decrement stats as they were never incremented |
1236 | - if ( ( 'publish' != $this->old_status && 'revoked' != $this->old_status ) || 'wpi-pending' != $this->status ) { |
|
1236 | + if (('publish' != $this->old_status && 'revoked' != $this->old_status) || 'wpi-pending' != $this->status) { |
|
1237 | 1237 | $process_pending = false; |
1238 | 1238 | } |
1239 | 1239 | |
1240 | 1240 | // Allow extensions to filter for their own payment types, Example: Recurring Payments |
1241 | - $process_pending = apply_filters( 'wpinv_should_process_pending', $process_pending, $this ); |
|
1241 | + $process_pending = apply_filters('wpinv_should_process_pending', $process_pending, $this); |
|
1242 | 1242 | |
1243 | - if ( false === $process_pending ) { |
|
1243 | + if (false === $process_pending) { |
|
1244 | 1244 | return; |
1245 | 1245 | } |
1246 | 1246 | |
1247 | - $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_pending', true, $this ); |
|
1248 | - $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_pending', true, $this ); |
|
1249 | - $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_pending', true, $this ); |
|
1247 | + $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_pending', true, $this); |
|
1248 | + $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_pending', true, $this); |
|
1249 | + $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_pending', true, $this); |
|
1250 | 1250 | |
1251 | 1251 | $this->completed_date = ''; |
1252 | - $this->update_meta( '_wpinv_completed_date', '' ); |
|
1252 | + $this->update_meta('_wpinv_completed_date', ''); |
|
1253 | 1253 | } |
1254 | 1254 | |
1255 | 1255 | // get data |
1256 | - public function get_meta( $meta_key = '_wpinv_payment_meta', $single = true ) { |
|
1257 | - $meta = get_post_meta( $this->ID, $meta_key, $single ); |
|
1256 | + public function get_meta($meta_key = '_wpinv_payment_meta', $single = true) { |
|
1257 | + $meta = get_post_meta($this->ID, $meta_key, $single); |
|
1258 | 1258 | |
1259 | - if ( $meta_key === '_wpinv_payment_meta' ) { |
|
1259 | + if ($meta_key === '_wpinv_payment_meta') { |
|
1260 | 1260 | |
1261 | - if(!is_array($meta)){$meta = array();} // we need this to be an array so make sure it is. |
|
1261 | + if (!is_array($meta)) {$meta = array(); } // we need this to be an array so make sure it is. |
|
1262 | 1262 | |
1263 | - if ( empty( $meta['key'] ) ) { |
|
1263 | + if (empty($meta['key'])) { |
|
1264 | 1264 | $meta['key'] = $this->setup_invoice_key(); |
1265 | 1265 | } |
1266 | 1266 | |
1267 | - if ( empty( $meta['date'] ) ) { |
|
1268 | - $meta['date'] = get_post_field( 'post_date', $this->ID ); |
|
1267 | + if (empty($meta['date'])) { |
|
1268 | + $meta['date'] = get_post_field('post_date', $this->ID); |
|
1269 | 1269 | } |
1270 | 1270 | } |
1271 | 1271 | |
1272 | - $meta = apply_filters( 'wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID ); |
|
1272 | + $meta = apply_filters('wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID); |
|
1273 | 1273 | |
1274 | - return apply_filters( 'wpinv_get_invoice_meta', $meta, $this->ID, $meta_key ); |
|
1274 | + return apply_filters('wpinv_get_invoice_meta', $meta, $this->ID, $meta_key); |
|
1275 | 1275 | } |
1276 | 1276 | |
1277 | 1277 | public function get_description() { |
1278 | - $post = get_post( $this->ID ); |
|
1278 | + $post = get_post($this->ID); |
|
1279 | 1279 | |
1280 | - $description = !empty( $post ) ? $post->post_content : ''; |
|
1281 | - return apply_filters( 'wpinv_get_description', $description, $this->ID, $this ); |
|
1280 | + $description = !empty($post) ? $post->post_content : ''; |
|
1281 | + return apply_filters('wpinv_get_description', $description, $this->ID, $this); |
|
1282 | 1282 | } |
1283 | 1283 | |
1284 | - public function get_status( $nicename = false ) { |
|
1285 | - if ( !$nicename ) { |
|
1284 | + public function get_status($nicename = false) { |
|
1285 | + if (!$nicename) { |
|
1286 | 1286 | $status = $this->status; |
1287 | 1287 | } else { |
1288 | 1288 | $status = $this->status_nicename; |
1289 | 1289 | } |
1290 | 1290 | |
1291 | - return apply_filters( 'wpinv_get_status', $status, $nicename, $this->ID, $this ); |
|
1291 | + return apply_filters('wpinv_get_status', $status, $nicename, $this->ID, $this); |
|
1292 | 1292 | } |
1293 | 1293 | |
1294 | 1294 | public function get_cart_details() { |
1295 | - return apply_filters( 'wpinv_cart_details', $this->cart_details, $this->ID, $this ); |
|
1295 | + return apply_filters('wpinv_cart_details', $this->cart_details, $this->ID, $this); |
|
1296 | 1296 | } |
1297 | 1297 | |
1298 | - public function get_subtotal( $currency = false ) { |
|
1299 | - $subtotal = wpinv_round_amount( $this->subtotal ); |
|
1298 | + public function get_subtotal($currency = false) { |
|
1299 | + $subtotal = wpinv_round_amount($this->subtotal); |
|
1300 | 1300 | |
1301 | - if ( $currency ) { |
|
1302 | - $subtotal = wpinv_price( wpinv_format_amount( $subtotal, NULL, !$currency ), $this->get_currency() ); |
|
1301 | + if ($currency) { |
|
1302 | + $subtotal = wpinv_price(wpinv_format_amount($subtotal, NULL, !$currency), $this->get_currency()); |
|
1303 | 1303 | } |
1304 | 1304 | |
1305 | - return apply_filters( 'wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency ); |
|
1305 | + return apply_filters('wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency); |
|
1306 | 1306 | } |
1307 | 1307 | |
1308 | - public function get_total( $currency = false ) { |
|
1309 | - if ( $this->is_free_trial() ) { |
|
1310 | - $total = wpinv_round_amount( 0 ); |
|
1308 | + public function get_total($currency = false) { |
|
1309 | + if ($this->is_free_trial()) { |
|
1310 | + $total = wpinv_round_amount(0); |
|
1311 | 1311 | } else { |
1312 | - $total = wpinv_round_amount( $this->total ); |
|
1312 | + $total = wpinv_round_amount($this->total); |
|
1313 | 1313 | } |
1314 | - if ( $currency ) { |
|
1315 | - $total = wpinv_price( wpinv_format_amount( $total, NULL, !$currency ), $this->get_currency() ); |
|
1314 | + if ($currency) { |
|
1315 | + $total = wpinv_price(wpinv_format_amount($total, NULL, !$currency), $this->get_currency()); |
|
1316 | 1316 | } |
1317 | 1317 | |
1318 | - return apply_filters( 'wpinv_get_invoice_total', $total, $this->ID, $this, $currency ); |
|
1318 | + return apply_filters('wpinv_get_invoice_total', $total, $this->ID, $this, $currency); |
|
1319 | 1319 | } |
1320 | 1320 | |
1321 | - public function get_recurring_details( $field = '', $currency = false ) { |
|
1321 | + public function get_recurring_details($field = '', $currency = false) { |
|
1322 | 1322 | $data = array(); |
1323 | 1323 | $data['cart_details'] = $this->cart_details; |
1324 | 1324 | $data['subtotal'] = $this->get_subtotal(); |
@@ -1326,119 +1326,119 @@ discard block |
||
1326 | 1326 | $data['tax'] = $this->get_tax(); |
1327 | 1327 | $data['total'] = $this->get_total(); |
1328 | 1328 | |
1329 | - if ( !empty( $this->cart_details ) && ( $this->is_parent() || $this->is_renewal() ) ) { |
|
1329 | + if (!empty($this->cart_details) && ($this->is_parent() || $this->is_renewal())) { |
|
1330 | 1330 | $is_free_trial = $this->is_free_trial(); |
1331 | - $discounts = $this->get_discounts( true ); |
|
1331 | + $discounts = $this->get_discounts(true); |
|
1332 | 1332 | |
1333 | - if ( $is_free_trial || !empty( $discounts ) ) { |
|
1333 | + if ($is_free_trial || !empty($discounts)) { |
|
1334 | 1334 | $first_use_only = false; |
1335 | 1335 | |
1336 | - if ( !empty( $discounts ) ) { |
|
1337 | - foreach ( $discounts as $key => $code ) { |
|
1338 | - if ( wpinv_discount_is_recurring( $code, true ) && !$this->is_renewal() ) { |
|
1336 | + if (!empty($discounts)) { |
|
1337 | + foreach ($discounts as $key => $code) { |
|
1338 | + if (wpinv_discount_is_recurring($code, true) && !$this->is_renewal()) { |
|
1339 | 1339 | $first_use_only = true; |
1340 | 1340 | break; |
1341 | 1341 | } |
1342 | 1342 | } |
1343 | 1343 | } |
1344 | 1344 | |
1345 | - if ( !$first_use_only ) { |
|
1346 | - $data['subtotal'] = wpinv_round_amount( $this->subtotal ); |
|
1347 | - $data['discount'] = wpinv_round_amount( $this->discount ); |
|
1348 | - $data['tax'] = wpinv_round_amount( $this->tax ); |
|
1349 | - $data['total'] = wpinv_round_amount( $this->total ); |
|
1345 | + if (!$first_use_only) { |
|
1346 | + $data['subtotal'] = wpinv_round_amount($this->subtotal); |
|
1347 | + $data['discount'] = wpinv_round_amount($this->discount); |
|
1348 | + $data['tax'] = wpinv_round_amount($this->tax); |
|
1349 | + $data['total'] = wpinv_round_amount($this->total); |
|
1350 | 1350 | } else { |
1351 | 1351 | $cart_subtotal = 0; |
1352 | 1352 | $cart_discount = $this->discount; |
1353 | 1353 | $cart_tax = 0; |
1354 | 1354 | |
1355 | - foreach ( $this->cart_details as $key => $item ) { |
|
1356 | - $item_quantity = $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1; |
|
1357 | - $item_subtotal = !empty( $item['subtotal'] ) ? $item['subtotal'] : $item['item_price'] * $item_quantity; |
|
1355 | + foreach ($this->cart_details as $key => $item) { |
|
1356 | + $item_quantity = $item['quantity'] > 0 ? absint($item['quantity']) : 1; |
|
1357 | + $item_subtotal = !empty($item['subtotal']) ? $item['subtotal'] : $item['item_price'] * $item_quantity; |
|
1358 | 1358 | $item_discount = 0; |
1359 | - $item_tax = $item_subtotal > 0 && !empty( $item['vat_rate'] ) ? ( $item_subtotal * 0.01 * (float)$item['vat_rate'] ) : 0; |
|
1359 | + $item_tax = $item_subtotal > 0 && !empty($item['vat_rate']) ? ($item_subtotal * 0.01 * (float) $item['vat_rate']) : 0; |
|
1360 | 1360 | |
1361 | - if ( wpinv_prices_include_tax() ) { |
|
1362 | - $item_subtotal -= wpinv_round_amount( $item_tax ); |
|
1361 | + if (wpinv_prices_include_tax()) { |
|
1362 | + $item_subtotal -= wpinv_round_amount($item_tax); |
|
1363 | 1363 | } |
1364 | 1364 | |
1365 | 1365 | $item_total = $item_subtotal - $item_discount + $item_tax; |
1366 | 1366 | // Do not allow totals to go negative |
1367 | - if ( $item_total < 0 ) { |
|
1367 | + if ($item_total < 0) { |
|
1368 | 1368 | $item_total = 0; |
1369 | 1369 | } |
1370 | 1370 | |
1371 | - $cart_subtotal += (float)($item_subtotal); |
|
1372 | - $cart_discount += (float)($item_discount); |
|
1373 | - $cart_tax += (float)($item_tax); |
|
1371 | + $cart_subtotal += (float) ($item_subtotal); |
|
1372 | + $cart_discount += (float) ($item_discount); |
|
1373 | + $cart_tax += (float) ($item_tax); |
|
1374 | 1374 | |
1375 | - $data['cart_details'][$key]['discount'] = wpinv_round_amount( $item_discount ); |
|
1376 | - $data['cart_details'][$key]['tax'] = wpinv_round_amount( $item_tax ); |
|
1377 | - $data['cart_details'][$key]['price'] = wpinv_round_amount( $item_total ); |
|
1375 | + $data['cart_details'][$key]['discount'] = wpinv_round_amount($item_discount); |
|
1376 | + $data['cart_details'][$key]['tax'] = wpinv_round_amount($item_tax); |
|
1377 | + $data['cart_details'][$key]['price'] = wpinv_round_amount($item_total); |
|
1378 | 1378 | } |
1379 | 1379 | |
1380 | 1380 | $total = $data['subtotal'] - $data['discount'] + $data['tax']; |
1381 | - if ( $total < 0 ) { |
|
1381 | + if ($total < 0) { |
|
1382 | 1382 | $total = 0; |
1383 | 1383 | } |
1384 | 1384 | |
1385 | - $data['subtotal'] = wpinv_round_amount( $cart_subtotal ); |
|
1386 | - $data['discount'] = wpinv_round_amount( $cart_discount ); |
|
1387 | - $data['tax'] = wpinv_round_amount( $cart_tax ); |
|
1388 | - $data['total'] = wpinv_round_amount( $total ); |
|
1385 | + $data['subtotal'] = wpinv_round_amount($cart_subtotal); |
|
1386 | + $data['discount'] = wpinv_round_amount($cart_discount); |
|
1387 | + $data['tax'] = wpinv_round_amount($cart_tax); |
|
1388 | + $data['total'] = wpinv_round_amount($total); |
|
1389 | 1389 | } |
1390 | 1390 | } |
1391 | 1391 | } |
1392 | 1392 | |
1393 | - $data = apply_filters( 'wpinv_get_invoice_recurring_details', $data, $this, $field, $currency ); |
|
1393 | + $data = apply_filters('wpinv_get_invoice_recurring_details', $data, $this, $field, $currency); |
|
1394 | 1394 | |
1395 | - if ( isset( $data[$field] ) ) { |
|
1396 | - return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] ); |
|
1395 | + if (isset($data[$field])) { |
|
1396 | + return ($currency ? wpinv_price($data[$field], $this->get_currency()) : $data[$field]); |
|
1397 | 1397 | } |
1398 | 1398 | |
1399 | 1399 | return $data; |
1400 | 1400 | } |
1401 | 1401 | |
1402 | - public function get_final_tax( $currency = false ) { |
|
1403 | - $final_total = wpinv_round_amount( $this->tax ); |
|
1404 | - if ( $currency ) { |
|
1405 | - $final_total = wpinv_price( wpinv_format_amount( $final_total, NULL, !$currency ), $this->get_currency() ); |
|
1402 | + public function get_final_tax($currency = false) { |
|
1403 | + $final_total = wpinv_round_amount($this->tax); |
|
1404 | + if ($currency) { |
|
1405 | + $final_total = wpinv_price(wpinv_format_amount($final_total, NULL, !$currency), $this->get_currency()); |
|
1406 | 1406 | } |
1407 | 1407 | |
1408 | - return apply_filters( 'wpinv_get_invoice_final_total', $final_total, $this, $currency ); |
|
1408 | + return apply_filters('wpinv_get_invoice_final_total', $final_total, $this, $currency); |
|
1409 | 1409 | } |
1410 | 1410 | |
1411 | - public function get_discounts( $array = false ) { |
|
1411 | + public function get_discounts($array = false) { |
|
1412 | 1412 | $discounts = $this->discounts; |
1413 | - if ( $array && $discounts ) { |
|
1414 | - $discounts = explode( ',', $discounts ); |
|
1413 | + if ($array && $discounts) { |
|
1414 | + $discounts = explode(',', $discounts); |
|
1415 | 1415 | } |
1416 | - return apply_filters( 'wpinv_payment_discounts', $discounts, $this->ID, $this, $array ); |
|
1416 | + return apply_filters('wpinv_payment_discounts', $discounts, $this->ID, $this, $array); |
|
1417 | 1417 | } |
1418 | 1418 | |
1419 | - public function get_discount( $currency = false, $dash = false ) { |
|
1420 | - if ( !empty( $this->discounts ) ) { |
|
1419 | + public function get_discount($currency = false, $dash = false) { |
|
1420 | + if (!empty($this->discounts)) { |
|
1421 | 1421 | global $ajax_cart_details; |
1422 | 1422 | $ajax_cart_details = $this->get_cart_details(); |
1423 | 1423 | |
1424 | - if ( !empty( $ajax_cart_details ) && count( $ajax_cart_details ) == count( $this->items ) ) { |
|
1424 | + if (!empty($ajax_cart_details) && count($ajax_cart_details) == count($this->items)) { |
|
1425 | 1425 | $cart_items = $ajax_cart_details; |
1426 | 1426 | } else { |
1427 | 1427 | $cart_items = $this->items; |
1428 | 1428 | } |
1429 | 1429 | |
1430 | - $this->discount = wpinv_get_cart_items_discount_amount( $cart_items , $this->discounts ); |
|
1430 | + $this->discount = wpinv_get_cart_items_discount_amount($cart_items, $this->discounts); |
|
1431 | 1431 | } |
1432 | - $discount = wpinv_round_amount( $this->discount ); |
|
1432 | + $discount = wpinv_round_amount($this->discount); |
|
1433 | 1433 | $dash = $dash && $discount > 0 ? '–' : ''; |
1434 | 1434 | |
1435 | - if ( $currency ) { |
|
1436 | - $discount = wpinv_price( wpinv_format_amount( $discount, NULL, !$currency ), $this->get_currency() ); |
|
1435 | + if ($currency) { |
|
1436 | + $discount = wpinv_price(wpinv_format_amount($discount, NULL, !$currency), $this->get_currency()); |
|
1437 | 1437 | } |
1438 | 1438 | |
1439 | - $discount = $dash . $discount; |
|
1439 | + $discount = $dash . $discount; |
|
1440 | 1440 | |
1441 | - return apply_filters( 'wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash ); |
|
1441 | + return apply_filters('wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash); |
|
1442 | 1442 | } |
1443 | 1443 | |
1444 | 1444 | public function get_discount_code() { |
@@ -1450,49 +1450,49 @@ discard block |
||
1450 | 1450 | return (int) $this->disable_taxes === 0; |
1451 | 1451 | } |
1452 | 1452 | |
1453 | - public function get_tax( $currency = false ) { |
|
1454 | - $tax = wpinv_round_amount( $this->tax ); |
|
1453 | + public function get_tax($currency = false) { |
|
1454 | + $tax = wpinv_round_amount($this->tax); |
|
1455 | 1455 | |
1456 | - if ( $currency ) { |
|
1457 | - $tax = wpinv_price( wpinv_format_amount( $tax, NULL, !$currency ), $this->get_currency() ); |
|
1456 | + if ($currency) { |
|
1457 | + $tax = wpinv_price(wpinv_format_amount($tax, NULL, !$currency), $this->get_currency()); |
|
1458 | 1458 | } |
1459 | 1459 | |
1460 | - if ( ! $this->is_taxable() ) { |
|
1461 | - $tax = wpinv_round_amount( 0.00 ); |
|
1460 | + if (!$this->is_taxable()) { |
|
1461 | + $tax = wpinv_round_amount(0.00); |
|
1462 | 1462 | } |
1463 | 1463 | |
1464 | - return apply_filters( 'wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency ); |
|
1464 | + return apply_filters('wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency); |
|
1465 | 1465 | } |
1466 | 1466 | |
1467 | - public function get_fees( $type = 'all' ) { |
|
1468 | - $fees = array(); |
|
1467 | + public function get_fees($type = 'all') { |
|
1468 | + $fees = array(); |
|
1469 | 1469 | |
1470 | - if ( ! empty( $this->fees ) && is_array( $this->fees ) ) { |
|
1471 | - foreach ( $this->fees as $fee ) { |
|
1472 | - if( 'all' != $type && ! empty( $fee['type'] ) && $type != $fee['type'] ) { |
|
1470 | + if (!empty($this->fees) && is_array($this->fees)) { |
|
1471 | + foreach ($this->fees as $fee) { |
|
1472 | + if ('all' != $type && !empty($fee['type']) && $type != $fee['type']) { |
|
1473 | 1473 | continue; |
1474 | 1474 | } |
1475 | 1475 | |
1476 | - $fee['label'] = stripslashes( $fee['label'] ); |
|
1477 | - $fee['amount_display'] = wpinv_price( $fee['amount'], $this->get_currency() ); |
|
1478 | - $fees[] = $fee; |
|
1476 | + $fee['label'] = stripslashes($fee['label']); |
|
1477 | + $fee['amount_display'] = wpinv_price($fee['amount'], $this->get_currency()); |
|
1478 | + $fees[] = $fee; |
|
1479 | 1479 | } |
1480 | 1480 | } |
1481 | 1481 | |
1482 | - return apply_filters( 'wpinv_get_invoice_fees', $fees, $this->ID, $this ); |
|
1482 | + return apply_filters('wpinv_get_invoice_fees', $fees, $this->ID, $this); |
|
1483 | 1483 | } |
1484 | 1484 | |
1485 | - public function get_fees_total( $type = 'all' ) { |
|
1485 | + public function get_fees_total($type = 'all') { |
|
1486 | 1486 | $fees_total = (float) 0.00; |
1487 | 1487 | |
1488 | - $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array(); |
|
1489 | - if ( ! empty( $payment_fees ) ) { |
|
1490 | - foreach ( $payment_fees as $fee ) { |
|
1488 | + $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array(); |
|
1489 | + if (!empty($payment_fees)) { |
|
1490 | + foreach ($payment_fees as $fee) { |
|
1491 | 1491 | $fees_total += (float) $fee['amount']; |
1492 | 1492 | } |
1493 | 1493 | } |
1494 | 1494 | |
1495 | - return apply_filters( 'wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this ); |
|
1495 | + return apply_filters('wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this); |
|
1496 | 1496 | /* |
1497 | 1497 | $fees = $this->get_fees( $type ); |
1498 | 1498 | |
@@ -1512,116 +1512,116 @@ discard block |
||
1512 | 1512 | } |
1513 | 1513 | |
1514 | 1514 | public function get_user_id() { |
1515 | - return apply_filters( 'wpinv_user_id', $this->user_id, $this->ID, $this ); |
|
1515 | + return apply_filters('wpinv_user_id', $this->user_id, $this->ID, $this); |
|
1516 | 1516 | } |
1517 | 1517 | |
1518 | 1518 | public function get_first_name() { |
1519 | - return apply_filters( 'wpinv_first_name', $this->first_name, $this->ID, $this ); |
|
1519 | + return apply_filters('wpinv_first_name', $this->first_name, $this->ID, $this); |
|
1520 | 1520 | } |
1521 | 1521 | |
1522 | 1522 | public function get_last_name() { |
1523 | - return apply_filters( 'wpinv_last_name', $this->last_name, $this->ID, $this ); |
|
1523 | + return apply_filters('wpinv_last_name', $this->last_name, $this->ID, $this); |
|
1524 | 1524 | } |
1525 | 1525 | |
1526 | 1526 | public function get_user_full_name() { |
1527 | - return apply_filters( 'wpinv_user_full_name', $this->full_name, $this->ID, $this ); |
|
1527 | + return apply_filters('wpinv_user_full_name', $this->full_name, $this->ID, $this); |
|
1528 | 1528 | } |
1529 | 1529 | |
1530 | 1530 | public function get_user_info() { |
1531 | - return apply_filters( 'wpinv_user_info', $this->user_info, $this->ID, $this ); |
|
1531 | + return apply_filters('wpinv_user_info', $this->user_info, $this->ID, $this); |
|
1532 | 1532 | } |
1533 | 1533 | |
1534 | 1534 | public function get_email() { |
1535 | - return apply_filters( 'wpinv_user_email', $this->email, $this->ID, $this ); |
|
1535 | + return apply_filters('wpinv_user_email', $this->email, $this->ID, $this); |
|
1536 | 1536 | } |
1537 | 1537 | |
1538 | 1538 | public function get_address() { |
1539 | - return apply_filters( 'wpinv_address', $this->address, $this->ID, $this ); |
|
1539 | + return apply_filters('wpinv_address', $this->address, $this->ID, $this); |
|
1540 | 1540 | } |
1541 | 1541 | |
1542 | 1542 | public function get_phone() { |
1543 | - return apply_filters( 'wpinv_phone', $this->phone, $this->ID, $this ); |
|
1543 | + return apply_filters('wpinv_phone', $this->phone, $this->ID, $this); |
|
1544 | 1544 | } |
1545 | 1545 | |
1546 | 1546 | public function get_number() { |
1547 | - return apply_filters( 'wpinv_number', $this->number, $this->ID, $this ); |
|
1547 | + return apply_filters('wpinv_number', $this->number, $this->ID, $this); |
|
1548 | 1548 | } |
1549 | 1549 | |
1550 | 1550 | public function get_items() { |
1551 | - return apply_filters( 'wpinv_payment_meta_items', $this->items, $this->ID, $this ); |
|
1551 | + return apply_filters('wpinv_payment_meta_items', $this->items, $this->ID, $this); |
|
1552 | 1552 | } |
1553 | 1553 | |
1554 | 1554 | public function get_key() { |
1555 | - return apply_filters( 'wpinv_key', $this->key, $this->ID, $this ); |
|
1555 | + return apply_filters('wpinv_key', $this->key, $this->ID, $this); |
|
1556 | 1556 | } |
1557 | 1557 | |
1558 | 1558 | public function get_transaction_id() { |
1559 | - return apply_filters( 'wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this ); |
|
1559 | + return apply_filters('wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this); |
|
1560 | 1560 | } |
1561 | 1561 | |
1562 | 1562 | public function get_gateway() { |
1563 | - return apply_filters( 'wpinv_gateway', $this->gateway, $this->ID, $this ); |
|
1563 | + return apply_filters('wpinv_gateway', $this->gateway, $this->ID, $this); |
|
1564 | 1564 | } |
1565 | 1565 | |
1566 | 1566 | public function get_gateway_title() { |
1567 | - $this->gateway_title = !empty( $this->gateway_title ) ? $this->gateway_title : wpinv_get_gateway_checkout_label( $this->gateway ); |
|
1567 | + $this->gateway_title = !empty($this->gateway_title) ? $this->gateway_title : wpinv_get_gateway_checkout_label($this->gateway); |
|
1568 | 1568 | |
1569 | - return apply_filters( 'wpinv_gateway_title', $this->gateway_title, $this->ID, $this ); |
|
1569 | + return apply_filters('wpinv_gateway_title', $this->gateway_title, $this->ID, $this); |
|
1570 | 1570 | } |
1571 | 1571 | |
1572 | 1572 | public function get_currency() { |
1573 | - return apply_filters( 'wpinv_currency_code', $this->currency, $this->ID, $this ); |
|
1573 | + return apply_filters('wpinv_currency_code', $this->currency, $this->ID, $this); |
|
1574 | 1574 | } |
1575 | 1575 | |
1576 | 1576 | public function get_created_date() { |
1577 | - return apply_filters( 'wpinv_created_date', $this->date, $this->ID, $this ); |
|
1577 | + return apply_filters('wpinv_created_date', $this->date, $this->ID, $this); |
|
1578 | 1578 | } |
1579 | 1579 | |
1580 | - public function get_due_date( $display = false ) { |
|
1581 | - $due_date = apply_filters( 'wpinv_due_date', $this->due_date, $this->ID, $this ); |
|
1580 | + public function get_due_date($display = false) { |
|
1581 | + $due_date = apply_filters('wpinv_due_date', $this->due_date, $this->ID, $this); |
|
1582 | 1582 | |
1583 | - if ( !$display || empty( $due_date ) ) { |
|
1583 | + if (!$display || empty($due_date)) { |
|
1584 | 1584 | return $due_date; |
1585 | 1585 | } |
1586 | 1586 | |
1587 | - return date_i18n( get_option( 'date_format' ), strtotime( $due_date ) ); |
|
1587 | + return date_i18n(get_option('date_format'), strtotime($due_date)); |
|
1588 | 1588 | } |
1589 | 1589 | |
1590 | 1590 | public function get_completed_date() { |
1591 | - return apply_filters( 'wpinv_completed_date', $this->completed_date, $this->ID, $this ); |
|
1591 | + return apply_filters('wpinv_completed_date', $this->completed_date, $this->ID, $this); |
|
1592 | 1592 | } |
1593 | 1593 | |
1594 | - public function get_invoice_date( $formatted = true ) { |
|
1594 | + public function get_invoice_date($formatted = true) { |
|
1595 | 1595 | $date_completed = $this->completed_date; |
1596 | 1596 | $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? $date_completed : ''; |
1597 | 1597 | |
1598 | - if ( $invoice_date == '' ) { |
|
1598 | + if ($invoice_date == '') { |
|
1599 | 1599 | $date_created = $this->date; |
1600 | 1600 | $invoice_date = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? $date_created : ''; |
1601 | 1601 | } |
1602 | 1602 | |
1603 | - if ( $formatted && $invoice_date ) { |
|
1604 | - $invoice_date = date_i18n( get_option( 'date_format' ), strtotime( $invoice_date ) ); |
|
1603 | + if ($formatted && $invoice_date) { |
|
1604 | + $invoice_date = date_i18n(get_option('date_format'), strtotime($invoice_date)); |
|
1605 | 1605 | } |
1606 | 1606 | |
1607 | - return apply_filters( 'wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this ); |
|
1607 | + return apply_filters('wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this); |
|
1608 | 1608 | } |
1609 | 1609 | |
1610 | 1610 | public function get_ip() { |
1611 | - return apply_filters( 'wpinv_user_ip', $this->ip, $this->ID, $this ); |
|
1611 | + return apply_filters('wpinv_user_ip', $this->ip, $this->ID, $this); |
|
1612 | 1612 | } |
1613 | 1613 | |
1614 | - public function has_status( $status ) { |
|
1615 | - return apply_filters( 'wpinv_has_status', ( is_array( $status ) && in_array( $this->get_status(), $status ) ) || $this->get_status() === $status ? true : false, $this, $status ); |
|
1614 | + public function has_status($status) { |
|
1615 | + return apply_filters('wpinv_has_status', (is_array($status) && in_array($this->get_status(), $status)) || $this->get_status() === $status ? true : false, $this, $status); |
|
1616 | 1616 | } |
1617 | 1617 | |
1618 | - public function add_item( $item_id = 0, $args = array() ) { |
|
1618 | + public function add_item($item_id = 0, $args = array()) { |
|
1619 | 1619 | global $wpi_current_id, $wpi_item_id; |
1620 | 1620 | |
1621 | - $item = new WPInv_Item( $item_id ); |
|
1621 | + $item = new WPInv_Item($item_id); |
|
1622 | 1622 | |
1623 | 1623 | // Bail if this post isn't a item |
1624 | - if( !$item || $item->post_type !== 'wpi_item' ) { |
|
1624 | + if (!$item || $item->post_type !== 'wpi_item') { |
|
1625 | 1625 | return false; |
1626 | 1626 | } |
1627 | 1627 | |
@@ -1640,8 +1640,8 @@ discard block |
||
1640 | 1640 | 'fees' => array() |
1641 | 1641 | ); |
1642 | 1642 | |
1643 | - $args = wp_parse_args( apply_filters( 'wpinv_add_item_args', $args, $item->ID ), $defaults ); |
|
1644 | - $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint( $args['quantity'] ) : 1; |
|
1643 | + $args = wp_parse_args(apply_filters('wpinv_add_item_args', $args, $item->ID), $defaults); |
|
1644 | + $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint($args['quantity']) : 1; |
|
1645 | 1645 | |
1646 | 1646 | $wpi_current_id = $this->ID; |
1647 | 1647 | $wpi_item_id = $item->ID; |
@@ -1653,19 +1653,19 @@ discard block |
||
1653 | 1653 | $found_cart_key = false; |
1654 | 1654 | |
1655 | 1655 | if ($has_quantities) { |
1656 | - $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details; |
|
1656 | + $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details; |
|
1657 | 1657 | |
1658 | - foreach ( $this->items as $key => $cart_item ) { |
|
1659 | - if ( (int)$item_id !== (int)$cart_item['id'] ) { |
|
1658 | + foreach ($this->items as $key => $cart_item) { |
|
1659 | + if ((int) $item_id !== (int) $cart_item['id']) { |
|
1660 | 1660 | continue; |
1661 | 1661 | } |
1662 | 1662 | |
1663 | - $this->items[ $key ]['quantity'] += $args['quantity']; |
|
1663 | + $this->items[$key]['quantity'] += $args['quantity']; |
|
1664 | 1664 | break; |
1665 | 1665 | } |
1666 | 1666 | |
1667 | - foreach ( $this->cart_details as $cart_key => $cart_item ) { |
|
1668 | - if ( $item_id != $cart_item['id'] ) { |
|
1667 | + foreach ($this->cart_details as $cart_key => $cart_item) { |
|
1668 | + if ($item_id != $cart_item['id']) { |
|
1669 | 1669 | continue; |
1670 | 1670 | } |
1671 | 1671 | |
@@ -1677,29 +1677,29 @@ discard block |
||
1677 | 1677 | if ($has_quantities && $found_cart_key !== false) { |
1678 | 1678 | $cart_item = $this->cart_details[$found_cart_key]; |
1679 | 1679 | $item_price = $cart_item['item_price']; |
1680 | - $quantity = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1; |
|
1681 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0; |
|
1680 | + $quantity = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1; |
|
1681 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0; |
|
1682 | 1682 | |
1683 | 1683 | $new_quantity = $quantity + $args['quantity']; |
1684 | 1684 | $subtotal = $item_price * $new_quantity; |
1685 | 1685 | |
1686 | 1686 | $args['quantity'] = $new_quantity; |
1687 | - $discount = !empty( $args['discount'] ) ? $args['discount'] : 0; |
|
1688 | - $tax = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
1687 | + $discount = !empty($args['discount']) ? $args['discount'] : 0; |
|
1688 | + $tax = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0; |
|
1689 | 1689 | |
1690 | - $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float)$cart_item['discount'] ? $discount - (float)$cart_item['discount'] : 0; |
|
1691 | - $tax_increased = $tax > 0 && $subtotal > 0 && $tax > (float)$cart_item['tax'] ? $tax - (float)$cart_item['tax'] : 0; |
|
1690 | + $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float) $cart_item['discount'] ? $discount - (float) $cart_item['discount'] : 0; |
|
1691 | + $tax_increased = $tax > 0 && $subtotal > 0 && $tax > (float) $cart_item['tax'] ? $tax - (float) $cart_item['tax'] : 0; |
|
1692 | 1692 | // The total increase equals the number removed * the item_price |
1693 | - $total_increased = wpinv_round_amount( $item_price ); |
|
1693 | + $total_increased = wpinv_round_amount($item_price); |
|
1694 | 1694 | |
1695 | - if ( wpinv_prices_include_tax() ) { |
|
1696 | - $subtotal -= wpinv_round_amount( $tax ); |
|
1695 | + if (wpinv_prices_include_tax()) { |
|
1696 | + $subtotal -= wpinv_round_amount($tax); |
|
1697 | 1697 | } |
1698 | 1698 | |
1699 | - $total = $subtotal - $discount + $tax; |
|
1699 | + $total = $subtotal - $discount + $tax; |
|
1700 | 1700 | |
1701 | 1701 | // Do not allow totals to go negative |
1702 | - if( $total < 0 ) { |
|
1702 | + if ($total < 0) { |
|
1703 | 1703 | $total = 0; |
1704 | 1704 | } |
1705 | 1705 | |
@@ -1715,25 +1715,25 @@ discard block |
||
1715 | 1715 | $this->cart_details[$found_cart_key] = $cart_item; |
1716 | 1716 | } else { |
1717 | 1717 | // Set custom price. |
1718 | - if ( $args['custom_price'] !== '' ) { |
|
1718 | + if ($args['custom_price'] !== '') { |
|
1719 | 1719 | $item_price = $args['custom_price']; |
1720 | 1720 | } else { |
1721 | 1721 | // Allow overriding the price |
1722 | - if ( false !== $args['item_price'] ) { |
|
1722 | + if (false !== $args['item_price']) { |
|
1723 | 1723 | $item_price = $args['item_price']; |
1724 | 1724 | } else { |
1725 | - $item_price = wpinv_get_item_price( $item->ID ); |
|
1725 | + $item_price = wpinv_get_item_price($item->ID); |
|
1726 | 1726 | } |
1727 | 1727 | } |
1728 | 1728 | |
1729 | 1729 | // Sanitizing the price here so we don't have a dozen calls later |
1730 | - $item_price = wpinv_sanitize_amount( $item_price ); |
|
1731 | - $subtotal = wpinv_round_amount( $item_price * $args['quantity'] ); |
|
1730 | + $item_price = wpinv_sanitize_amount($item_price); |
|
1731 | + $subtotal = wpinv_round_amount($item_price * $args['quantity']); |
|
1732 | 1732 | |
1733 | - $discount = !empty( $args['discount'] ) ? $args['discount'] : 0; |
|
1734 | - $tax_class = !empty( $args['vat_class'] ) ? $args['vat_class'] : ''; |
|
1735 | - $tax_rate = !empty( $args['vat_rate'] ) ? $args['vat_rate'] : 0; |
|
1736 | - $tax = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
1733 | + $discount = !empty($args['discount']) ? $args['discount'] : 0; |
|
1734 | + $tax_class = !empty($args['vat_class']) ? $args['vat_class'] : ''; |
|
1735 | + $tax_rate = !empty($args['vat_rate']) ? $args['vat_rate'] : 0; |
|
1736 | + $tax = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0; |
|
1737 | 1737 | |
1738 | 1738 | // Setup the items meta item |
1739 | 1739 | $new_item = array( |
@@ -1741,29 +1741,29 @@ discard block |
||
1741 | 1741 | 'quantity' => $args['quantity'], |
1742 | 1742 | ); |
1743 | 1743 | |
1744 | - $this->items[] = $new_item; |
|
1744 | + $this->items[] = $new_item; |
|
1745 | 1745 | |
1746 | - if ( wpinv_prices_include_tax() ) { |
|
1747 | - $subtotal -= wpinv_round_amount( $tax ); |
|
1746 | + if (wpinv_prices_include_tax()) { |
|
1747 | + $subtotal -= wpinv_round_amount($tax); |
|
1748 | 1748 | } |
1749 | 1749 | |
1750 | - $total = $subtotal - $discount + $tax; |
|
1750 | + $total = $subtotal - $discount + $tax; |
|
1751 | 1751 | |
1752 | 1752 | // Do not allow totals to go negative |
1753 | - if( $total < 0 ) { |
|
1753 | + if ($total < 0) { |
|
1754 | 1754 | $total = 0; |
1755 | 1755 | } |
1756 | 1756 | |
1757 | 1757 | $this->cart_details[] = array( |
1758 | 1758 | 'name' => !empty($args['name']) ? $args['name'] : $item->get_name(), |
1759 | 1759 | 'id' => $item->ID, |
1760 | - 'item_price' => wpinv_round_amount( $item_price ), |
|
1761 | - 'custom_price' => ( $args['custom_price'] !== '' ? wpinv_round_amount( $args['custom_price'] ) : '' ), |
|
1760 | + 'item_price' => wpinv_round_amount($item_price), |
|
1761 | + 'custom_price' => ($args['custom_price'] !== '' ? wpinv_round_amount($args['custom_price']) : ''), |
|
1762 | 1762 | 'quantity' => $args['quantity'], |
1763 | 1763 | 'discount' => $discount, |
1764 | - 'subtotal' => wpinv_round_amount( $subtotal ), |
|
1765 | - 'tax' => wpinv_round_amount( $tax ), |
|
1766 | - 'price' => wpinv_round_amount( $total ), |
|
1764 | + 'subtotal' => wpinv_round_amount($subtotal), |
|
1765 | + 'tax' => wpinv_round_amount($tax), |
|
1766 | + 'price' => wpinv_round_amount($total), |
|
1767 | 1767 | 'vat_rate' => $tax_rate, |
1768 | 1768 | 'vat_class' => $tax_class, |
1769 | 1769 | 'meta' => $args['meta'], |
@@ -1773,18 +1773,18 @@ discard block |
||
1773 | 1773 | $subtotal = $subtotal - $discount; |
1774 | 1774 | } |
1775 | 1775 | |
1776 | - $added_item = end( $this->cart_details ); |
|
1777 | - $added_item['action'] = 'add'; |
|
1776 | + $added_item = end($this->cart_details); |
|
1777 | + $added_item['action'] = 'add'; |
|
1778 | 1778 | |
1779 | 1779 | $this->pending['items'][] = $added_item; |
1780 | 1780 | |
1781 | - $this->increase_subtotal( $subtotal ); |
|
1782 | - $this->increase_tax( $tax ); |
|
1781 | + $this->increase_subtotal($subtotal); |
|
1782 | + $this->increase_tax($tax); |
|
1783 | 1783 | |
1784 | 1784 | return true; |
1785 | 1785 | } |
1786 | 1786 | |
1787 | - public function remove_item( $item_id, $args = array() ) { |
|
1787 | + public function remove_item($item_id, $args = array()) { |
|
1788 | 1788 | // Set some defaults |
1789 | 1789 | $defaults = array( |
1790 | 1790 | 'quantity' => 1, |
@@ -1792,51 +1792,51 @@ discard block |
||
1792 | 1792 | 'custom_price' => '', |
1793 | 1793 | 'cart_index' => false, |
1794 | 1794 | ); |
1795 | - $args = wp_parse_args( $args, $defaults ); |
|
1795 | + $args = wp_parse_args($args, $defaults); |
|
1796 | 1796 | |
1797 | 1797 | // Bail if this post isn't a item |
1798 | - if ( get_post_type( $item_id ) !== 'wpi_item' ) { |
|
1798 | + if (get_post_type($item_id) !== 'wpi_item') { |
|
1799 | 1799 | return false; |
1800 | 1800 | } |
1801 | 1801 | |
1802 | - $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details; |
|
1802 | + $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details; |
|
1803 | 1803 | |
1804 | - foreach ( $this->items as $key => $item ) { |
|
1805 | - if ( !empty($item['id']) && (int)$item_id !== (int)$item['id'] ) { |
|
1804 | + foreach ($this->items as $key => $item) { |
|
1805 | + if (!empty($item['id']) && (int) $item_id !== (int) $item['id']) { |
|
1806 | 1806 | continue; |
1807 | 1807 | } |
1808 | 1808 | |
1809 | - if ( false !== $args['cart_index'] ) { |
|
1810 | - $cart_index = absint( $args['cart_index'] ); |
|
1811 | - $cart_item = ! empty( $this->cart_details[ $cart_index ] ) ? $this->cart_details[ $cart_index ] : false; |
|
1809 | + if (false !== $args['cart_index']) { |
|
1810 | + $cart_index = absint($args['cart_index']); |
|
1811 | + $cart_item = !empty($this->cart_details[$cart_index]) ? $this->cart_details[$cart_index] : false; |
|
1812 | 1812 | |
1813 | - if ( ! empty( $cart_item ) ) { |
|
1813 | + if (!empty($cart_item)) { |
|
1814 | 1814 | // If the cart index item isn't the same item ID, don't remove it |
1815 | - if ( !empty($cart_item['id']) && $cart_item['id'] != $item['id'] ) { |
|
1815 | + if (!empty($cart_item['id']) && $cart_item['id'] != $item['id']) { |
|
1816 | 1816 | continue; |
1817 | 1817 | } |
1818 | 1818 | } |
1819 | 1819 | } |
1820 | 1820 | |
1821 | - $item_quantity = $this->items[ $key ]['quantity']; |
|
1822 | - if ( $item_quantity > $args['quantity'] ) { |
|
1823 | - $this->items[ $key ]['quantity'] -= $args['quantity']; |
|
1821 | + $item_quantity = $this->items[$key]['quantity']; |
|
1822 | + if ($item_quantity > $args['quantity']) { |
|
1823 | + $this->items[$key]['quantity'] -= $args['quantity']; |
|
1824 | 1824 | break; |
1825 | 1825 | } else { |
1826 | - unset( $this->items[ $key ] ); |
|
1826 | + unset($this->items[$key]); |
|
1827 | 1827 | break; |
1828 | 1828 | } |
1829 | 1829 | } |
1830 | 1830 | |
1831 | 1831 | $found_cart_key = false; |
1832 | - if ( false === $args['cart_index'] ) { |
|
1833 | - foreach ( $this->cart_details as $cart_key => $item ) { |
|
1834 | - if ( $item_id != $item['id'] ) { |
|
1832 | + if (false === $args['cart_index']) { |
|
1833 | + foreach ($this->cart_details as $cart_key => $item) { |
|
1834 | + if ($item_id != $item['id']) { |
|
1835 | 1835 | continue; |
1836 | 1836 | } |
1837 | 1837 | |
1838 | - if ( false !== $args['item_price'] ) { |
|
1839 | - if ( isset( $item['item_price'] ) && (float) $args['item_price'] != (float) $item['item_price'] ) { |
|
1838 | + if (false !== $args['item_price']) { |
|
1839 | + if (isset($item['item_price']) && (float) $args['item_price'] != (float) $item['item_price']) { |
|
1840 | 1840 | continue; |
1841 | 1841 | } |
1842 | 1842 | } |
@@ -1845,13 +1845,13 @@ discard block |
||
1845 | 1845 | break; |
1846 | 1846 | } |
1847 | 1847 | } else { |
1848 | - $cart_index = absint( $args['cart_index'] ); |
|
1848 | + $cart_index = absint($args['cart_index']); |
|
1849 | 1849 | |
1850 | - if ( ! array_key_exists( $cart_index, $this->cart_details ) ) { |
|
1850 | + if (!array_key_exists($cart_index, $this->cart_details)) { |
|
1851 | 1851 | return false; // Invalid cart index passed. |
1852 | 1852 | } |
1853 | 1853 | |
1854 | - if ( (int) $this->cart_details[ $cart_index ]['id'] > 0 && (int) $this->cart_details[ $cart_index ]['id'] !== (int) $item_id ) { |
|
1854 | + if ((int) $this->cart_details[$cart_index]['id'] > 0 && (int) $this->cart_details[$cart_index]['id'] !== (int) $item_id) { |
|
1855 | 1855 | return false; // We still need the proper Item ID to be sure. |
1856 | 1856 | } |
1857 | 1857 | |
@@ -1859,41 +1859,41 @@ discard block |
||
1859 | 1859 | } |
1860 | 1860 | |
1861 | 1861 | $cart_item = $this->cart_details[$found_cart_key]; |
1862 | - $quantity = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1; |
|
1862 | + $quantity = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1; |
|
1863 | 1863 | |
1864 | - if ( count( $this->cart_details ) == 1 && ( $quantity - $args['quantity'] ) < 1 ) { |
|
1864 | + if (count($this->cart_details) == 1 && ($quantity - $args['quantity']) < 1) { |
|
1865 | 1865 | //return false; // Invoice must contain at least one item. |
1866 | 1866 | } |
1867 | 1867 | |
1868 | - $discounts = $this->get_discounts(); |
|
1868 | + $discounts = $this->get_discounts(); |
|
1869 | 1869 | |
1870 | - if ( $quantity > $args['quantity'] ) { |
|
1870 | + if ($quantity > $args['quantity']) { |
|
1871 | 1871 | $item_price = $cart_item['item_price']; |
1872 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0; |
|
1872 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0; |
|
1873 | 1873 | |
1874 | - $new_quantity = max( $quantity - $args['quantity'], 1); |
|
1874 | + $new_quantity = max($quantity - $args['quantity'], 1); |
|
1875 | 1875 | $subtotal = $item_price * $new_quantity; |
1876 | 1876 | |
1877 | 1877 | $args['quantity'] = $new_quantity; |
1878 | - $discount = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0; |
|
1879 | - $tax = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
1878 | + $discount = !empty($cart_item['discount']) ? $cart_item['discount'] : 0; |
|
1879 | + $tax = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0; |
|
1880 | 1880 | |
1881 | - $discount_decrease = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['discount'] / $quantity ) ) : 0; |
|
1882 | - $discount_decrease = $discount > 0 && $subtotal > 0 && (float)$cart_item['discount'] > $discount ? (float)$cart_item['discount'] - $discount : $discount_decrease; |
|
1883 | - $tax_decrease = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['tax'] / $quantity ) ) : 0; |
|
1884 | - $tax_decrease = $tax > 0 && $subtotal > 0 && (float)$cart_item['tax'] > $tax ? (float)$cart_item['tax'] - $tax : $tax_decrease; |
|
1881 | + $discount_decrease = (float) $cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount(((float) $cart_item['discount'] / $quantity)) : 0; |
|
1882 | + $discount_decrease = $discount > 0 && $subtotal > 0 && (float) $cart_item['discount'] > $discount ? (float) $cart_item['discount'] - $discount : $discount_decrease; |
|
1883 | + $tax_decrease = (float) $cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount(((float) $cart_item['tax'] / $quantity)) : 0; |
|
1884 | + $tax_decrease = $tax > 0 && $subtotal > 0 && (float) $cart_item['tax'] > $tax ? (float) $cart_item['tax'] - $tax : $tax_decrease; |
|
1885 | 1885 | |
1886 | 1886 | // The total increase equals the number removed * the item_price |
1887 | - $total_decrease = wpinv_round_amount( $item_price ); |
|
1887 | + $total_decrease = wpinv_round_amount($item_price); |
|
1888 | 1888 | |
1889 | - if ( wpinv_prices_include_tax() ) { |
|
1890 | - $subtotal -= wpinv_round_amount( $tax ); |
|
1889 | + if (wpinv_prices_include_tax()) { |
|
1890 | + $subtotal -= wpinv_round_amount($tax); |
|
1891 | 1891 | } |
1892 | 1892 | |
1893 | - $total = $subtotal - $discount + $tax; |
|
1893 | + $total = $subtotal - $discount + $tax; |
|
1894 | 1894 | |
1895 | 1895 | // Do not allow totals to go negative |
1896 | - if( $total < 0 ) { |
|
1896 | + if ($total < 0) { |
|
1897 | 1897 | $total = 0; |
1898 | 1898 | } |
1899 | 1899 | |
@@ -1912,16 +1912,16 @@ discard block |
||
1912 | 1912 | |
1913 | 1913 | $this->cart_details[$found_cart_key] = $cart_item; |
1914 | 1914 | |
1915 | - $remove_item = end( $this->cart_details ); |
|
1915 | + $remove_item = end($this->cart_details); |
|
1916 | 1916 | } else { |
1917 | 1917 | $item_price = $cart_item['item_price']; |
1918 | - $discount = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0; |
|
1919 | - $tax = !empty( $cart_item['tax'] ) ? $cart_item['tax'] : 0; |
|
1918 | + $discount = !empty($cart_item['discount']) ? $cart_item['discount'] : 0; |
|
1919 | + $tax = !empty($cart_item['tax']) ? $cart_item['tax'] : 0; |
|
1920 | 1920 | |
1921 | - $subtotal_decrease = ( $item_price * $quantity ) - $discount; |
|
1921 | + $subtotal_decrease = ($item_price * $quantity) - $discount; |
|
1922 | 1922 | $tax_decrease = $tax; |
1923 | 1923 | |
1924 | - unset( $this->cart_details[$found_cart_key] ); |
|
1924 | + unset($this->cart_details[$found_cart_key]); |
|
1925 | 1925 | |
1926 | 1926 | $remove_item = $args; |
1927 | 1927 | $remove_item['id'] = $item_id; |
@@ -1932,8 +1932,8 @@ discard block |
||
1932 | 1932 | $remove_item['action'] = 'remove'; |
1933 | 1933 | $this->pending['items'][] = $remove_item; |
1934 | 1934 | |
1935 | - $this->decrease_subtotal( $subtotal_decrease ); |
|
1936 | - $this->decrease_tax( $tax_decrease ); |
|
1935 | + $this->decrease_subtotal($subtotal_decrease); |
|
1936 | + $this->decrease_tax($tax_decrease); |
|
1937 | 1937 | |
1938 | 1938 | return true; |
1939 | 1939 | } |
@@ -1941,7 +1941,7 @@ discard block |
||
1941 | 1941 | public function update_items($temp = false) { |
1942 | 1942 | global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpi_nosave; |
1943 | 1943 | |
1944 | - if ( !empty( $this->cart_details ) ) { |
|
1944 | + if (!empty($this->cart_details)) { |
|
1945 | 1945 | $wpi_nosave = $temp; |
1946 | 1946 | $cart_subtotal = 0; |
1947 | 1947 | $cart_discount = 0; |
@@ -1951,65 +1951,65 @@ discard block |
||
1951 | 1951 | $_POST['wpinv_country'] = $this->country; |
1952 | 1952 | $_POST['wpinv_state'] = $this->state; |
1953 | 1953 | |
1954 | - foreach ( $this->cart_details as $key => $item ) { |
|
1954 | + foreach ($this->cart_details as $key => $item) { |
|
1955 | 1955 | $item_price = $item['item_price']; |
1956 | - $quantity = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1; |
|
1957 | - $amount = wpinv_round_amount( $item_price * $quantity ); |
|
1956 | + $quantity = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint($item['quantity']) : 1; |
|
1957 | + $amount = wpinv_round_amount($item_price * $quantity); |
|
1958 | 1958 | $subtotal = $item_price * $quantity; |
1959 | 1959 | |
1960 | 1960 | $wpi_current_id = $this->ID; |
1961 | 1961 | $wpi_item_id = $item['id']; |
1962 | 1962 | |
1963 | - $discount = wpinv_get_cart_item_discount_amount( $item, $this->get_discounts() ); |
|
1963 | + $discount = wpinv_get_cart_item_discount_amount($item, $this->get_discounts()); |
|
1964 | 1964 | |
1965 | - $tax_rate = wpinv_get_tax_rate( $this->country, $this->state, $wpi_item_id ); |
|
1966 | - $tax_class = $wpinv_euvat->get_item_class( $wpi_item_id ); |
|
1967 | - $tax = $item_price > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
1965 | + $tax_rate = wpinv_get_tax_rate($this->country, $this->state, $wpi_item_id); |
|
1966 | + $tax_class = $wpinv_euvat->get_item_class($wpi_item_id); |
|
1967 | + $tax = $item_price > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0; |
|
1968 | 1968 | |
1969 | - if ( ! $this->is_taxable() ) { |
|
1969 | + if (!$this->is_taxable()) { |
|
1970 | 1970 | $tax = 0; |
1971 | 1971 | } |
1972 | 1972 | |
1973 | - if ( wpinv_prices_include_tax() ) { |
|
1974 | - $subtotal -= wpinv_round_amount( $tax ); |
|
1973 | + if (wpinv_prices_include_tax()) { |
|
1974 | + $subtotal -= wpinv_round_amount($tax); |
|
1975 | 1975 | } |
1976 | 1976 | |
1977 | - $total = $subtotal - $discount + $tax; |
|
1977 | + $total = $subtotal - $discount + $tax; |
|
1978 | 1978 | |
1979 | 1979 | // Do not allow totals to go negative |
1980 | - if( $total < 0 ) { |
|
1980 | + if ($total < 0) { |
|
1981 | 1981 | $total = 0; |
1982 | 1982 | } |
1983 | 1983 | |
1984 | 1984 | $cart_details[] = array( |
1985 | 1985 | 'id' => $item['id'], |
1986 | 1986 | 'name' => $item['name'], |
1987 | - 'item_price' => wpinv_round_amount( $item_price ), |
|
1988 | - 'custom_price'=> ( isset( $item['custom_price'] ) ? $item['custom_price'] : '' ), |
|
1987 | + 'item_price' => wpinv_round_amount($item_price), |
|
1988 | + 'custom_price'=> (isset($item['custom_price']) ? $item['custom_price'] : ''), |
|
1989 | 1989 | 'quantity' => $quantity, |
1990 | 1990 | 'discount' => $discount, |
1991 | - 'subtotal' => wpinv_round_amount( $subtotal ), |
|
1992 | - 'tax' => wpinv_round_amount( $tax ), |
|
1993 | - 'price' => wpinv_round_amount( $total ), |
|
1991 | + 'subtotal' => wpinv_round_amount($subtotal), |
|
1992 | + 'tax' => wpinv_round_amount($tax), |
|
1993 | + 'price' => wpinv_round_amount($total), |
|
1994 | 1994 | 'vat_rate' => $tax_rate, |
1995 | 1995 | 'vat_class' => $tax_class, |
1996 | 1996 | 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
1997 | 1997 | 'fees' => isset($item['fees']) ? $item['fees'] : array(), |
1998 | 1998 | ); |
1999 | 1999 | |
2000 | - $cart_subtotal += (float)($subtotal - $discount); // TODO |
|
2001 | - $cart_discount += (float)($discount); |
|
2002 | - $cart_tax += (float)($tax); |
|
2000 | + $cart_subtotal += (float) ($subtotal - $discount); // TODO |
|
2001 | + $cart_discount += (float) ($discount); |
|
2002 | + $cart_tax += (float) ($tax); |
|
2003 | 2003 | } |
2004 | - if ( $cart_subtotal < 0 ) { |
|
2004 | + if ($cart_subtotal < 0) { |
|
2005 | 2005 | $cart_subtotal = 0; |
2006 | 2006 | } |
2007 | - if ( $cart_tax < 0 ) { |
|
2007 | + if ($cart_tax < 0) { |
|
2008 | 2008 | $cart_tax = 0; |
2009 | 2009 | } |
2010 | - $this->subtotal = wpinv_round_amount( $cart_subtotal ); |
|
2011 | - $this->tax = wpinv_round_amount( $cart_tax ); |
|
2012 | - $this->discount = wpinv_round_amount( $cart_discount ); |
|
2010 | + $this->subtotal = wpinv_round_amount($cart_subtotal); |
|
2011 | + $this->tax = wpinv_round_amount($cart_tax); |
|
2012 | + $this->discount = wpinv_round_amount($cart_discount); |
|
2013 | 2013 | |
2014 | 2014 | $this->recalculate_total(); |
2015 | 2015 | |
@@ -2021,177 +2021,177 @@ discard block |
||
2021 | 2021 | |
2022 | 2022 | public function recalculate_totals($temp = false) { |
2023 | 2023 | $this->update_items($temp); |
2024 | - $this->save( true ); |
|
2024 | + $this->save(true); |
|
2025 | 2025 | |
2026 | 2026 | return $this; |
2027 | 2027 | } |
2028 | 2028 | |
2029 | 2029 | public function needs_payment() { |
2030 | - $valid_invoice_statuses = apply_filters( 'wpinv_valid_invoice_statuses_for_payment', array( 'wpi-pending' ), $this ); |
|
2030 | + $valid_invoice_statuses = apply_filters('wpinv_valid_invoice_statuses_for_payment', array('wpi-pending'), $this); |
|
2031 | 2031 | |
2032 | - if ( $this->has_status( $valid_invoice_statuses ) && ( $this->get_total() > 0 || $this->is_free_trial() || $this->is_free() || $this->is_initial_free() ) ) { |
|
2032 | + if ($this->has_status($valid_invoice_statuses) && ($this->get_total() > 0 || $this->is_free_trial() || $this->is_free() || $this->is_initial_free())) { |
|
2033 | 2033 | $needs_payment = true; |
2034 | 2034 | } else { |
2035 | 2035 | $needs_payment = false; |
2036 | 2036 | } |
2037 | 2037 | |
2038 | - return apply_filters( 'wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses ); |
|
2038 | + return apply_filters('wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses); |
|
2039 | 2039 | } |
2040 | 2040 | |
2041 | - public function get_checkout_payment_url( $with_key = false, $secret = false ) { |
|
2041 | + public function get_checkout_payment_url($with_key = false, $secret = false) { |
|
2042 | 2042 | $pay_url = wpinv_get_checkout_uri(); |
2043 | 2043 | |
2044 | - if ( is_ssl() ) { |
|
2045 | - $pay_url = str_replace( 'http:', 'https:', $pay_url ); |
|
2044 | + if (is_ssl()) { |
|
2045 | + $pay_url = str_replace('http:', 'https:', $pay_url); |
|
2046 | 2046 | } |
2047 | 2047 | |
2048 | 2048 | $key = $this->get_key(); |
2049 | 2049 | |
2050 | - if ( $with_key ) { |
|
2051 | - $pay_url = add_query_arg( 'invoice_key', $key, $pay_url ); |
|
2050 | + if ($with_key) { |
|
2051 | + $pay_url = add_query_arg('invoice_key', $key, $pay_url); |
|
2052 | 2052 | } else { |
2053 | - $pay_url = add_query_arg( array( 'wpi_action' => 'pay_for_invoice', 'invoice_key' => $key ), $pay_url ); |
|
2053 | + $pay_url = add_query_arg(array('wpi_action' => 'pay_for_invoice', 'invoice_key' => $key), $pay_url); |
|
2054 | 2054 | } |
2055 | 2055 | |
2056 | - if ( $secret ) { |
|
2057 | - $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $key ) ), $pay_url ); |
|
2056 | + if ($secret) { |
|
2057 | + $pay_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $key)), $pay_url); |
|
2058 | 2058 | } |
2059 | 2059 | |
2060 | - return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $with_key, $secret ); |
|
2060 | + return apply_filters('wpinv_get_checkout_payment_url', $pay_url, $this, $with_key, $secret); |
|
2061 | 2061 | } |
2062 | 2062 | |
2063 | - public function get_view_url( $with_key = false ) { |
|
2064 | - $invoice_url = get_permalink( $this->ID ); |
|
2063 | + public function get_view_url($with_key = false) { |
|
2064 | + $invoice_url = get_permalink($this->ID); |
|
2065 | 2065 | |
2066 | - if ( $with_key ) { |
|
2067 | - $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url ); |
|
2066 | + if ($with_key) { |
|
2067 | + $invoice_url = add_query_arg('invoice_key', $this->get_key(), $invoice_url); |
|
2068 | 2068 | } |
2069 | 2069 | |
2070 | - return apply_filters( 'wpinv_get_view_url', $invoice_url, $this, $with_key ); |
|
2070 | + return apply_filters('wpinv_get_view_url', $invoice_url, $this, $with_key); |
|
2071 | 2071 | } |
2072 | 2072 | |
2073 | - public function generate_key( $string = '' ) { |
|
2074 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
2075 | - return strtolower( md5( $string . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'wpinv', true ) ) ); // Unique key |
|
2073 | + public function generate_key($string = '') { |
|
2074 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
2075 | + return strtolower(md5($string . date('Y-m-d H:i:s') . $auth_key . uniqid('wpinv', true))); // Unique key |
|
2076 | 2076 | } |
2077 | 2077 | |
2078 | 2078 | public function is_recurring() { |
2079 | - if ( empty( $this->cart_details ) ) { |
|
2079 | + if (empty($this->cart_details)) { |
|
2080 | 2080 | return false; |
2081 | 2081 | } |
2082 | 2082 | |
2083 | 2083 | $has_subscription = false; |
2084 | - foreach( $this->cart_details as $cart_item ) { |
|
2085 | - if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] ) ) { |
|
2084 | + foreach ($this->cart_details as $cart_item) { |
|
2085 | + if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { |
|
2086 | 2086 | $has_subscription = true; |
2087 | 2087 | break; |
2088 | 2088 | } |
2089 | 2089 | } |
2090 | 2090 | |
2091 | - if ( count( $this->cart_details ) > 1 ) { |
|
2091 | + if (count($this->cart_details) > 1) { |
|
2092 | 2092 | $has_subscription = false; |
2093 | 2093 | } |
2094 | 2094 | |
2095 | - return apply_filters( 'wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details ); |
|
2095 | + return apply_filters('wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details); |
|
2096 | 2096 | } |
2097 | 2097 | |
2098 | 2098 | public function is_free_trial() { |
2099 | 2099 | $is_free_trial = false; |
2100 | 2100 | |
2101 | - if ( $this->is_parent() && $item = $this->get_recurring( true ) ) { |
|
2102 | - if ( !empty( $item ) && $item->has_free_trial() ) { |
|
2101 | + if ($this->is_parent() && $item = $this->get_recurring(true)) { |
|
2102 | + if (!empty($item) && $item->has_free_trial()) { |
|
2103 | 2103 | $is_free_trial = true; |
2104 | 2104 | } |
2105 | 2105 | } |
2106 | 2106 | |
2107 | - return apply_filters( 'wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details, $this ); |
|
2107 | + return apply_filters('wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details, $this); |
|
2108 | 2108 | } |
2109 | 2109 | |
2110 | 2110 | public function is_initial_free() { |
2111 | 2111 | $is_initial_free = false; |
2112 | 2112 | |
2113 | - if ( ! ( (float)wpinv_round_amount( $this->get_total() ) > 0 ) && $this->is_parent() && $this->is_recurring() && ! $this->is_free_trial() && ! $this->is_free() ) { |
|
2113 | + if (!((float) wpinv_round_amount($this->get_total()) > 0) && $this->is_parent() && $this->is_recurring() && !$this->is_free_trial() && !$this->is_free()) { |
|
2114 | 2114 | $is_initial_free = true; |
2115 | 2115 | } |
2116 | 2116 | |
2117 | - return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->cart_details ); |
|
2117 | + return apply_filters('wpinv_invoice_is_initial_free', $is_initial_free, $this->cart_details); |
|
2118 | 2118 | } |
2119 | 2119 | |
2120 | - public function get_recurring( $object = false ) { |
|
2120 | + public function get_recurring($object = false) { |
|
2121 | 2121 | $item = NULL; |
2122 | 2122 | |
2123 | - if ( empty( $this->cart_details ) ) { |
|
2123 | + if (empty($this->cart_details)) { |
|
2124 | 2124 | return $item; |
2125 | 2125 | } |
2126 | 2126 | |
2127 | - foreach( $this->cart_details as $cart_item ) { |
|
2128 | - if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] ) ) { |
|
2127 | + foreach ($this->cart_details as $cart_item) { |
|
2128 | + if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { |
|
2129 | 2129 | $item = $cart_item['id']; |
2130 | 2130 | break; |
2131 | 2131 | } |
2132 | 2132 | } |
2133 | 2133 | |
2134 | - if ( $object ) { |
|
2135 | - $item = $item ? new WPInv_Item( $item ) : NULL; |
|
2134 | + if ($object) { |
|
2135 | + $item = $item ? new WPInv_Item($item) : NULL; |
|
2136 | 2136 | |
2137 | - apply_filters( 'wpinv_invoice_get_recurring_item', $item, $this ); |
|
2137 | + apply_filters('wpinv_invoice_get_recurring_item', $item, $this); |
|
2138 | 2138 | } |
2139 | 2139 | |
2140 | - return apply_filters( 'wpinv_invoice_get_recurring_item_id', $item, $this ); |
|
2140 | + return apply_filters('wpinv_invoice_get_recurring_item_id', $item, $this); |
|
2141 | 2141 | } |
2142 | 2142 | |
2143 | 2143 | public function get_subscription_name() { |
2144 | - $item = $this->get_recurring( true ); |
|
2144 | + $item = $this->get_recurring(true); |
|
2145 | 2145 | |
2146 | - if ( empty( $item ) ) { |
|
2146 | + if (empty($item)) { |
|
2147 | 2147 | return NULL; |
2148 | 2148 | } |
2149 | 2149 | |
2150 | - if ( !($name = $item->get_name()) ) { |
|
2150 | + if (!($name = $item->get_name())) { |
|
2151 | 2151 | $name = $item->post_name; |
2152 | 2152 | } |
2153 | 2153 | |
2154 | - return apply_filters( 'wpinv_invoice_get_subscription_name', $name, $this ); |
|
2154 | + return apply_filters('wpinv_invoice_get_subscription_name', $name, $this); |
|
2155 | 2155 | } |
2156 | 2156 | |
2157 | 2157 | public function get_subscription_id() { |
2158 | - $subscription_id = $this->get_meta( '_wpinv_subscr_profile_id', true ); |
|
2158 | + $subscription_id = $this->get_meta('_wpinv_subscr_profile_id', true); |
|
2159 | 2159 | |
2160 | - if ( empty( $subscription_id ) && !empty( $this->parent_invoice ) ) { |
|
2161 | - $parent_invoice = wpinv_get_invoice( $this->parent_invoice ); |
|
2160 | + if (empty($subscription_id) && !empty($this->parent_invoice)) { |
|
2161 | + $parent_invoice = wpinv_get_invoice($this->parent_invoice); |
|
2162 | 2162 | |
2163 | - $subscription_id = $parent_invoice->get_meta( '_wpinv_subscr_profile_id', true ); |
|
2163 | + $subscription_id = $parent_invoice->get_meta('_wpinv_subscr_profile_id', true); |
|
2164 | 2164 | } |
2165 | 2165 | |
2166 | 2166 | return $subscription_id; |
2167 | 2167 | } |
2168 | 2168 | |
2169 | 2169 | public function is_parent() { |
2170 | - $is_parent = empty( $this->parent_invoice ) ? true : false; |
|
2170 | + $is_parent = empty($this->parent_invoice) ? true : false; |
|
2171 | 2171 | |
2172 | - return apply_filters( 'wpinv_invoice_is_parent', $is_parent, $this ); |
|
2172 | + return apply_filters('wpinv_invoice_is_parent', $is_parent, $this); |
|
2173 | 2173 | } |
2174 | 2174 | |
2175 | 2175 | public function is_renewal() { |
2176 | 2176 | $is_renewal = $this->parent_invoice && $this->parent_invoice != $this->ID ? true : false; |
2177 | 2177 | |
2178 | - return apply_filters( 'wpinv_invoice_is_renewal', $is_renewal, $this ); |
|
2178 | + return apply_filters('wpinv_invoice_is_renewal', $is_renewal, $this); |
|
2179 | 2179 | } |
2180 | 2180 | |
2181 | 2181 | public function get_parent_payment() { |
2182 | 2182 | $parent_payment = NULL; |
2183 | 2183 | |
2184 | - if ( $this->is_renewal() ) { |
|
2185 | - $parent_payment = wpinv_get_invoice( $this->parent_invoice ); |
|
2184 | + if ($this->is_renewal()) { |
|
2185 | + $parent_payment = wpinv_get_invoice($this->parent_invoice); |
|
2186 | 2186 | } |
2187 | 2187 | |
2188 | 2188 | return $parent_payment; |
2189 | 2189 | } |
2190 | 2190 | |
2191 | 2191 | public function is_paid() { |
2192 | - $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) ); |
|
2192 | + $is_paid = $this->has_status(array('publish', 'wpi-processing', 'wpi-renewal')); |
|
2193 | 2193 | |
2194 | - return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this ); |
|
2194 | + return apply_filters('wpinv_invoice_is_paid', $is_paid, $this); |
|
2195 | 2195 | } |
2196 | 2196 | |
2197 | 2197 | /** |
@@ -2204,23 +2204,23 @@ discard block |
||
2204 | 2204 | } |
2205 | 2205 | |
2206 | 2206 | public function is_refunded() { |
2207 | - $is_refunded = $this->has_status( array( 'wpi-refunded' ) ); |
|
2207 | + $is_refunded = $this->has_status(array('wpi-refunded')); |
|
2208 | 2208 | |
2209 | - return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this ); |
|
2209 | + return apply_filters('wpinv_invoice_is_refunded', $is_refunded, $this); |
|
2210 | 2210 | } |
2211 | 2211 | |
2212 | 2212 | public function is_free() { |
2213 | 2213 | $is_free = false; |
2214 | 2214 | |
2215 | - if ( !( (float)wpinv_round_amount( $this->get_total() ) > 0 ) ) { |
|
2216 | - if ( $this->is_parent() && $this->is_recurring() ) { |
|
2217 | - $is_free = (float)wpinv_round_amount( $this->get_recurring_details( 'total' ) ) > 0 ? false : true; |
|
2215 | + if (!((float) wpinv_round_amount($this->get_total()) > 0)) { |
|
2216 | + if ($this->is_parent() && $this->is_recurring()) { |
|
2217 | + $is_free = (float) wpinv_round_amount($this->get_recurring_details('total')) > 0 ? false : true; |
|
2218 | 2218 | } else { |
2219 | 2219 | $is_free = true; |
2220 | 2220 | } |
2221 | 2221 | } |
2222 | 2222 | |
2223 | - return apply_filters( 'wpinv_invoice_is_free', $is_free, $this ); |
|
2223 | + return apply_filters('wpinv_invoice_is_free', $is_free, $this); |
|
2224 | 2224 | } |
2225 | 2225 | |
2226 | 2226 | public function has_vat() { |
@@ -2228,41 +2228,41 @@ discard block |
||
2228 | 2228 | |
2229 | 2229 | $requires_vat = false; |
2230 | 2230 | |
2231 | - if ( $this->country ) { |
|
2231 | + if ($this->country) { |
|
2232 | 2232 | $wpi_country = $this->country; |
2233 | 2233 | |
2234 | - $requires_vat = $wpinv_euvat->requires_vat( $requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule( $this ) ); |
|
2234 | + $requires_vat = $wpinv_euvat->requires_vat($requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule($this)); |
|
2235 | 2235 | } |
2236 | 2236 | |
2237 | - return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this ); |
|
2237 | + return apply_filters('wpinv_invoice_has_vat', $requires_vat, $this); |
|
2238 | 2238 | } |
2239 | 2239 | |
2240 | 2240 | public function refresh_item_ids() { |
2241 | 2241 | $item_ids = array(); |
2242 | 2242 | |
2243 | - if ( !empty( $this->cart_details ) ) { |
|
2244 | - foreach ( $this->cart_details as $key => $item ) { |
|
2245 | - if ( !empty( $item['id'] ) ) { |
|
2243 | + if (!empty($this->cart_details)) { |
|
2244 | + foreach ($this->cart_details as $key => $item) { |
|
2245 | + if (!empty($item['id'])) { |
|
2246 | 2246 | $item_ids[] = $item['id']; |
2247 | 2247 | } |
2248 | 2248 | } |
2249 | 2249 | } |
2250 | 2250 | |
2251 | - $item_ids = !empty( $item_ids ) ? implode( ',', array_unique( $item_ids ) ) : ''; |
|
2251 | + $item_ids = !empty($item_ids) ? implode(',', array_unique($item_ids)) : ''; |
|
2252 | 2252 | |
2253 | - update_post_meta( $this->ID, '_wpinv_item_ids', $item_ids ); |
|
2253 | + update_post_meta($this->ID, '_wpinv_item_ids', $item_ids); |
|
2254 | 2254 | } |
2255 | 2255 | |
2256 | - public function get_invoice_quote_type( $post_id ) { |
|
2257 | - if ( empty( $post_id ) ) { |
|
2256 | + public function get_invoice_quote_type($post_id) { |
|
2257 | + if (empty($post_id)) { |
|
2258 | 2258 | return ''; |
2259 | 2259 | } |
2260 | 2260 | |
2261 | - $type = get_post_type( $post_id ); |
|
2261 | + $type = get_post_type($post_id); |
|
2262 | 2262 | |
2263 | - if ( 'wpi_invoice' === $type ) { |
|
2263 | + if ('wpi_invoice' === $type) { |
|
2264 | 2264 | $post_type = __('Invoice', 'invoicing'); |
2265 | - } else{ |
|
2265 | + } else { |
|
2266 | 2266 | $post_type = __('Quote', 'invoicing'); |
2267 | 2267 | } |
2268 | 2268 |
@@ -1,74 +1,74 @@ 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-payment-form-design', __( 'Payment Form', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
|
29 | - add_meta_box( 'wpinv-payment-form-shortcode', __( 'Shortcode', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_shortcode', 'wpi_payment_form', 'side' ); |
|
28 | + add_meta_box('wpinv-payment-form-design', __('Payment Form', 'invoicing'), 'WPInv_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal'); |
|
29 | + add_meta_box('wpinv-payment-form-shortcode', __('Shortcode', 'invoicing'), 'WPInv_Meta_Box_Payment_Form::output_shortcode', 'wpi_payment_form', 'side'); |
|
30 | 30 | |
31 | - add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'WPInv_Meta_Box_Billing_Details::output', 'wpi_invoice', 'normal', 'high' ); |
|
32 | - add_meta_box( 'wpinv-items', __( 'Invoice Items', 'invoicing' ), 'WPInv_Meta_Box_Items::output', 'wpi_invoice', 'normal', 'high' ); |
|
33 | - add_meta_box( 'wpinv-notes', __( 'Invoice Notes', 'invoicing' ), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high' ); |
|
31 | + add_meta_box('wpinv-address', __('Billing Details', 'invoicing'), 'WPInv_Meta_Box_Billing_Details::output', 'wpi_invoice', 'normal', 'high'); |
|
32 | + add_meta_box('wpinv-items', __('Invoice Items', 'invoicing'), 'WPInv_Meta_Box_Items::output', 'wpi_invoice', 'normal', 'high'); |
|
33 | + add_meta_box('wpinv-notes', __('Invoice Notes', 'invoicing'), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high'); |
|
34 | 34 | |
35 | - if ( ! empty( $post->ID ) && get_post_meta( $post->ID, 'payment_form_data', true ) ) { |
|
36 | - add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', 'wpi_invoice', 'side', 'high' ); |
|
35 | + if (!empty($post->ID) && get_post_meta($post->ID, 'payment_form_data', true)) { |
|
36 | + add_meta_box('wpinv-invoice-payment-form-details', __('Payment Form Details', 'invoicing'), 'WPInv_Meta_Box_Payment_Form::output_details', 'wpi_invoice', 'side', 'high'); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | remove_meta_box('wpseo_meta', 'wpi_invoice', 'normal'); |
40 | 40 | } |
41 | -add_action( 'add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2 ); |
|
41 | +add_action('add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2); |
|
42 | 42 | |
43 | -function wpinv_save_meta_boxes( $post_id, $post, $update = false ) { |
|
44 | - remove_action( 'save_post', __FUNCTION__ ); |
|
43 | +function wpinv_save_meta_boxes($post_id, $post, $update = false) { |
|
44 | + remove_action('save_post', __FUNCTION__); |
|
45 | 45 | |
46 | 46 | // $post_id and $post are required |
47 | - if ( empty( $post_id ) || empty( $post ) ) { |
|
47 | + if (empty($post_id) || empty($post)) { |
|
48 | 48 | return; |
49 | 49 | } |
50 | 50 | |
51 | - if ( !current_user_can( 'edit_post', $post_id ) || empty( $post->post_type ) ) { |
|
51 | + if (!current_user_can('edit_post', $post_id) || empty($post->post_type)) { |
|
52 | 52 | return; |
53 | 53 | } |
54 | 54 | |
55 | 55 | // Dont' save meta boxes for revisions or autosaves |
56 | - if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
56 | + if (defined('DOING_AUTOSAVE') || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) { |
|
57 | 57 | return; |
58 | 58 | } |
59 | 59 | |
60 | - if ( $post->post_type == 'wpi_invoice' or $post->post_type == 'wpi_quote' ) { |
|
61 | - if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
60 | + if ($post->post_type == 'wpi_invoice' or $post->post_type == 'wpi_quote') { |
|
61 | + if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) { |
|
62 | 62 | return; |
63 | 63 | } |
64 | 64 | |
65 | - if ( isset( $_POST['wpinv_save_invoice'] ) && wp_verify_nonce( $_POST['wpinv_save_invoice'], 'wpinv_save_invoice' ) ) { |
|
66 | - WPInv_Meta_Box_Items::save( $post_id, $_POST, $post ); |
|
65 | + if (isset($_POST['wpinv_save_invoice']) && wp_verify_nonce($_POST['wpinv_save_invoice'], 'wpinv_save_invoice')) { |
|
66 | + WPInv_Meta_Box_Items::save($post_id, $_POST, $post); |
|
67 | 67 | } |
68 | - } else if ( $post->post_type == 'wpi_item' ) { |
|
68 | + } else if ($post->post_type == 'wpi_item') { |
|
69 | 69 | // verify nonce |
70 | - if ( isset( $_POST['wpinv_vat_meta_box_nonce'] ) && wp_verify_nonce( $_POST['wpinv_vat_meta_box_nonce'], 'wpinv_item_meta_box_save' ) ) { |
|
71 | - $fields = array(); |
|
70 | + if (isset($_POST['wpinv_vat_meta_box_nonce']) && wp_verify_nonce($_POST['wpinv_vat_meta_box_nonce'], 'wpinv_item_meta_box_save')) { |
|
71 | + $fields = array(); |
|
72 | 72 | $fields['_wpinv_price'] = 'wpinv_item_price'; |
73 | 73 | $fields['_wpinv_vat_class'] = 'wpinv_vat_class'; |
74 | 74 | $fields['_wpinv_vat_rule'] = 'wpinv_vat_rules'; |
@@ -83,97 +83,97 @@ discard block |
||
83 | 83 | $fields['_wpinv_dynamic_pricing'] = 'wpinv_name_your_price'; |
84 | 84 | $fields['_minimum_price'] = 'wpinv_minimum_price'; |
85 | 85 | |
86 | - if ( !isset( $_POST['wpinv_is_recurring'] ) ) { |
|
86 | + if (!isset($_POST['wpinv_is_recurring'])) { |
|
87 | 87 | $_POST['wpinv_is_recurring'] = 0; |
88 | 88 | } |
89 | 89 | |
90 | - if ( !isset( $_POST['wpinv_name_your_price'] ) ) { |
|
90 | + if (!isset($_POST['wpinv_name_your_price'])) { |
|
91 | 91 | $_POST['wpinv_name_your_price'] = 0; |
92 | 92 | } |
93 | 93 | |
94 | - if ( !isset( $_POST['wpinv_free_trial'] ) || empty( $_POST['wpinv_is_recurring'] ) ) { |
|
94 | + if (!isset($_POST['wpinv_free_trial']) || empty($_POST['wpinv_is_recurring'])) { |
|
95 | 95 | $_POST['wpinv_free_trial'] = 0; |
96 | 96 | } |
97 | 97 | |
98 | - foreach ( $fields as $field => $name ) { |
|
99 | - if ( isset( $_POST[ $name ] ) ) { |
|
100 | - $allowed = apply_filters( 'wpinv_item_allowed_save_meta_value', true, $field, $post_id ); |
|
98 | + foreach ($fields as $field => $name) { |
|
99 | + if (isset($_POST[$name])) { |
|
100 | + $allowed = apply_filters('wpinv_item_allowed_save_meta_value', true, $field, $post_id); |
|
101 | 101 | |
102 | - if ( !$allowed ) { |
|
102 | + if (!$allowed) { |
|
103 | 103 | continue; |
104 | 104 | } |
105 | 105 | |
106 | - if ( $field == '_wpinv_price' ) { |
|
107 | - $value = wpinv_sanitize_amount( $_POST[ $name ] ); |
|
106 | + if ($field == '_wpinv_price') { |
|
107 | + $value = wpinv_sanitize_amount($_POST[$name]); |
|
108 | 108 | } else { |
109 | - $value = is_string( $_POST[ $name ] ) ? sanitize_text_field( $_POST[ $name ] ) : $_POST[ $name ]; |
|
109 | + $value = is_string($_POST[$name]) ? sanitize_text_field($_POST[$name]) : $_POST[$name]; |
|
110 | 110 | } |
111 | 111 | |
112 | - $value = apply_filters( 'wpinv_item_metabox_save_' . $field, $value, $name ); |
|
113 | - update_post_meta( $post_id, $field, $value ); |
|
112 | + $value = apply_filters('wpinv_item_metabox_save_' . $field, $value, $name); |
|
113 | + update_post_meta($post_id, $field, $value); |
|
114 | 114 | } |
115 | 115 | } |
116 | 116 | |
117 | - if ( !get_post_meta( $post_id, '_wpinv_custom_id', true ) ) { |
|
118 | - update_post_meta( $post_id, '_wpinv_custom_id', $post_id ); |
|
117 | + if (!get_post_meta($post_id, '_wpinv_custom_id', true)) { |
|
118 | + update_post_meta($post_id, '_wpinv_custom_id', $post_id); |
|
119 | 119 | } |
120 | 120 | } |
121 | 121 | } |
122 | 122 | } |
123 | -add_action( 'save_post', 'wpinv_save_meta_boxes', 10, 3 ); |
|
123 | +add_action('save_post', 'wpinv_save_meta_boxes', 10, 3); |
|
124 | 124 | |
125 | 125 | function wpinv_register_item_meta_boxes() { |
126 | 126 | global $wpinv_euvat; |
127 | 127 | |
128 | - add_meta_box( 'wpinv_field_prices', __( 'Item Price', 'invoicing' ), 'WPInv_Meta_Box_Items::prices', 'wpi_item', 'normal', 'high' ); |
|
128 | + add_meta_box('wpinv_field_prices', __('Item Price', 'invoicing'), 'WPInv_Meta_Box_Items::prices', 'wpi_item', 'normal', 'high'); |
|
129 | 129 | |
130 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
131 | - add_meta_box( 'wpinv_field_vat_rules', __( 'VAT rules type to use', 'invoicing' ), 'WPInv_Meta_Box_Items::vat_rules', 'wpi_item', 'normal', 'high' ); |
|
130 | + if ($wpinv_euvat->allow_vat_rules()) { |
|
131 | + add_meta_box('wpinv_field_vat_rules', __('VAT rules type to use', 'invoicing'), 'WPInv_Meta_Box_Items::vat_rules', 'wpi_item', 'normal', 'high'); |
|
132 | 132 | } |
133 | 133 | |
134 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
135 | - add_meta_box( 'wpinv_field_vat_classes', __( 'VAT rates class to use', 'invoicing' ), 'WPInv_Meta_Box_Items::vat_classes', 'wpi_item', 'normal', 'high' ); |
|
134 | + if ($wpinv_euvat->allow_vat_classes()) { |
|
135 | + add_meta_box('wpinv_field_vat_classes', __('VAT rates class to use', 'invoicing'), 'WPInv_Meta_Box_Items::vat_classes', 'wpi_item', 'normal', 'high'); |
|
136 | 136 | } |
137 | 137 | |
138 | - add_meta_box( 'wpinv_field_item_shortcode', __( 'Shortcode', 'invoicing' ), 'WPInv_Meta_Box_Items::shortcode', 'wpi_item', 'side', 'core' ); |
|
139 | - add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'WPInv_Meta_Box_Items::item_info', 'wpi_item', 'side', 'core' ); |
|
140 | - add_meta_box( 'wpinv_field_meta_values', __( 'Item Meta Values', 'invoicing' ), 'WPInv_Meta_Box_Items::meta_values', 'wpi_item', 'side', 'core' ); |
|
138 | + add_meta_box('wpinv_field_item_shortcode', __('Shortcode', 'invoicing'), 'WPInv_Meta_Box_Items::shortcode', 'wpi_item', 'side', 'core'); |
|
139 | + add_meta_box('wpinv_field_item_info', __('Item info', 'invoicing'), 'WPInv_Meta_Box_Items::item_info', 'wpi_item', 'side', 'core'); |
|
140 | + add_meta_box('wpinv_field_meta_values', __('Item Meta Values', 'invoicing'), 'WPInv_Meta_Box_Items::meta_values', 'wpi_item', 'side', 'core'); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | function wpinv_register_discount_meta_boxes() { |
144 | - add_meta_box( 'wpinv_discount_fields', __( 'Discount Details', 'invoicing' ), 'wpinv_discount_metabox_details', 'wpi_discount', 'normal', 'high' ); |
|
144 | + add_meta_box('wpinv_discount_fields', __('Discount Details', 'invoicing'), 'wpinv_discount_metabox_details', 'wpi_discount', 'normal', 'high'); |
|
145 | 145 | } |
146 | 146 | |
147 | -function wpinv_discount_metabox_details( $post ) { |
|
147 | +function wpinv_discount_metabox_details($post) { |
|
148 | 148 | $discount_id = $post->ID; |
149 | - $discount = wpinv_get_discount( $discount_id ); |
|
149 | + $discount = wpinv_get_discount($discount_id); |
|
150 | 150 | |
151 | - $type = wpinv_get_discount_type( $discount_id ); |
|
152 | - $item_reqs = wpinv_get_discount_item_reqs( $discount_id ); |
|
153 | - $excluded_items = wpinv_get_discount_excluded_items( $discount_id ); |
|
154 | - $min_total = wpinv_get_discount_min_total( $discount_id ); |
|
155 | - $max_total = wpinv_get_discount_max_total( $discount_id ); |
|
156 | - $max_uses = wpinv_get_discount_max_uses( $discount_id ); |
|
157 | - $single_use = wpinv_discount_is_single_use( $discount_id ); |
|
158 | - $recurring = (bool)wpinv_discount_is_recurring( $discount_id ); |
|
159 | - $start_date = wpinv_get_discount_start_date( $discount_id ); |
|
160 | - $expiration_date = wpinv_get_discount_expiration( $discount_id ); |
|
151 | + $type = wpinv_get_discount_type($discount_id); |
|
152 | + $item_reqs = wpinv_get_discount_item_reqs($discount_id); |
|
153 | + $excluded_items = wpinv_get_discount_excluded_items($discount_id); |
|
154 | + $min_total = wpinv_get_discount_min_total($discount_id); |
|
155 | + $max_total = wpinv_get_discount_max_total($discount_id); |
|
156 | + $max_uses = wpinv_get_discount_max_uses($discount_id); |
|
157 | + $single_use = wpinv_discount_is_single_use($discount_id); |
|
158 | + $recurring = (bool) wpinv_discount_is_recurring($discount_id); |
|
159 | + $start_date = wpinv_get_discount_start_date($discount_id); |
|
160 | + $expiration_date = wpinv_get_discount_expiration($discount_id); |
|
161 | 161 | |
162 | - if ( ! empty( $start_date ) && strpos( $start_date, '0000' ) === false ) { |
|
163 | - $start_time = strtotime( $start_date ); |
|
164 | - $start_h = date_i18n( 'H', $start_time ); |
|
165 | - $start_m = date_i18n( 'i', $start_time ); |
|
166 | - $start_date = date_i18n( 'Y-m-d', $start_time ); |
|
162 | + if (!empty($start_date) && strpos($start_date, '0000') === false) { |
|
163 | + $start_time = strtotime($start_date); |
|
164 | + $start_h = date_i18n('H', $start_time); |
|
165 | + $start_m = date_i18n('i', $start_time); |
|
166 | + $start_date = date_i18n('Y-m-d', $start_time); |
|
167 | 167 | } else { |
168 | 168 | $start_h = '00'; |
169 | 169 | $start_m = '00'; |
170 | 170 | } |
171 | 171 | |
172 | - if ( ! empty( $expiration_date ) && strpos( $expiration_date, '0000' ) === false ) { |
|
173 | - $expiration_time = strtotime( $expiration_date ); |
|
174 | - $expiration_h = date_i18n( 'H', $expiration_time ); |
|
175 | - $expiration_m = date_i18n( 'i', $expiration_time ); |
|
176 | - $expiration_date = date_i18n( 'Y-m-d', $expiration_time ); |
|
172 | + if (!empty($expiration_date) && strpos($expiration_date, '0000') === false) { |
|
173 | + $expiration_time = strtotime($expiration_date); |
|
174 | + $expiration_h = date_i18n('H', $expiration_time); |
|
175 | + $expiration_m = date_i18n('i', $expiration_time); |
|
176 | + $expiration_date = date_i18n('Y-m-d', $expiration_time); |
|
177 | 177 | } else { |
178 | 178 | $expiration_h = '23'; |
179 | 179 | $expiration_m = '59'; |
@@ -183,207 +183,207 @@ discard block |
||
183 | 183 | $max_total = $max_total > 0 ? $max_total : ''; |
184 | 184 | $max_uses = $max_uses > 0 ? $max_uses : ''; |
185 | 185 | ?> |
186 | -<?php do_action( 'wpinv_discount_form_top', $post ); ?> |
|
187 | -<?php wp_nonce_field( 'wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce' ); ;?> |
|
186 | +<?php do_action('wpinv_discount_form_top', $post); ?> |
|
187 | +<?php wp_nonce_field('wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce'); ;?> |
|
188 | 188 | <table class="form-table wpi-form-table"> |
189 | 189 | <tbody> |
190 | - <?php do_action( 'wpinv_discount_form_first', $post ); ?> |
|
191 | - <?php do_action( 'wpinv_discount_form_before_code', $post ); ?> |
|
190 | + <?php do_action('wpinv_discount_form_first', $post); ?> |
|
191 | + <?php do_action('wpinv_discount_form_before_code', $post); ?> |
|
192 | 192 | <tr> |
193 | 193 | <th valign="top" scope="row"> |
194 | - <label for="wpinv_discount_code"><?php _e( 'Discount Code', 'invoicing' ); ?></label> |
|
194 | + <label for="wpinv_discount_code"><?php _e('Discount Code', 'invoicing'); ?></label> |
|
195 | 195 | </th> |
196 | 196 | <td> |
197 | - <input type="text" name="code" id="wpinv_discount_code" class="medium-text" value="<?php echo esc_attr( wpinv_get_discount_code( $discount_id ) ); ?>" required> |
|
198 | - <p class="description"><?php _e( 'Enter a code for this discount, such as 10OFF', 'invoicing' ); ?></p> |
|
197 | + <input type="text" name="code" id="wpinv_discount_code" class="medium-text" value="<?php echo esc_attr(wpinv_get_discount_code($discount_id)); ?>" required> |
|
198 | + <p class="description"><?php _e('Enter a code for this discount, such as 10OFF', 'invoicing'); ?></p> |
|
199 | 199 | </td> |
200 | 200 | </tr> |
201 | - <?php do_action( 'wpinv_discount_form_before_type', $post ); ?> |
|
201 | + <?php do_action('wpinv_discount_form_before_type', $post); ?> |
|
202 | 202 | <tr> |
203 | 203 | <th valign="top" scope="row"> |
204 | - <label for="wpinv_discount_type"><?php _e( 'Discount Type', 'invoicing' ); ?></label> |
|
204 | + <label for="wpinv_discount_type"><?php _e('Discount Type', 'invoicing'); ?></label> |
|
205 | 205 | </th> |
206 | 206 | <td> |
207 | 207 | <select id="wpinv_discount_type" name="type" class="medium-text wpi_select2"> |
208 | - <?php foreach ( wpinv_get_discount_types() as $value => $label ) { ?> |
|
209 | - <option value="<?php echo $value ;?>" <?php selected( $type, $value ); ?>><?php echo $label; ?></option> |
|
208 | + <?php foreach (wpinv_get_discount_types() as $value => $label) { ?> |
|
209 | + <option value="<?php echo $value; ?>" <?php selected($type, $value); ?>><?php echo $label; ?></option> |
|
210 | 210 | <?php } ?> |
211 | 211 | </select> |
212 | - <p class="description"><?php _e( 'The kind of discount to apply for this discount.', 'invoicing' ); ?></p> |
|
212 | + <p class="description"><?php _e('The kind of discount to apply for this discount.', 'invoicing'); ?></p> |
|
213 | 213 | </td> |
214 | 214 | </tr> |
215 | - <?php do_action( 'wpinv_discount_form_before_amount', $post ); ?> |
|
215 | + <?php do_action('wpinv_discount_form_before_amount', $post); ?> |
|
216 | 216 | <tr> |
217 | 217 | <th valign="top" scope="row"> |
218 | - <label for="wpinv_discount_amount"><?php _e( 'Amount', 'invoicing' ); ?></label> |
|
218 | + <label for="wpinv_discount_amount"><?php _e('Amount', 'invoicing'); ?></label> |
|
219 | 219 | </th> |
220 | 220 | <td> |
221 | - <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> |
|
222 | - <p style="display:none;" class="description"><?php _e( 'Enter the discount amount in USD', 'invoicing' ); ?></p> |
|
223 | - <p class="description"><?php _e( 'Enter the discount value. Ex: 10', 'invoicing' ); ?></p> |
|
221 | + <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> |
|
222 | + <p style="display:none;" class="description"><?php _e('Enter the discount amount in USD', 'invoicing'); ?></p> |
|
223 | + <p class="description"><?php _e('Enter the discount value. Ex: 10', 'invoicing'); ?></p> |
|
224 | 224 | </td> |
225 | 225 | </tr> |
226 | - <?php do_action( 'wpinv_discount_form_before_items', $post ); ?> |
|
226 | + <?php do_action('wpinv_discount_form_before_items', $post); ?> |
|
227 | 227 | <tr> |
228 | 228 | <th valign="top" scope="row"> |
229 | - <label for="wpinv_discount_items"><?php _e( 'Items', 'invoicing' ); ?></label> |
|
229 | + <label for="wpinv_discount_items"><?php _e('Items', 'invoicing'); ?></label> |
|
230 | 230 | </th> |
231 | 231 | <td> |
232 | - <p><?php echo wpinv_item_dropdown( array( |
|
232 | + <p><?php echo wpinv_item_dropdown(array( |
|
233 | 233 | 'name' => 'items[]', |
234 | 234 | 'id' => 'items', |
235 | 235 | 'selected' => $item_reqs, |
236 | 236 | 'multiple' => true, |
237 | 237 | 'class' => 'medium-text wpi_select2', |
238 | - 'placeholder' => __( 'Select one or more Items', 'invoicing' ), |
|
238 | + 'placeholder' => __('Select one or more Items', 'invoicing'), |
|
239 | 239 | 'show_recurring' => true, |
240 | - ) ); ?> |
|
240 | + )); ?> |
|
241 | 241 | </p> |
242 | - <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> |
|
242 | + <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> |
|
243 | 243 | </td> |
244 | 244 | </tr> |
245 | - <?php do_action( 'wpinv_discount_form_before_excluded_items', $post ); ?> |
|
245 | + <?php do_action('wpinv_discount_form_before_excluded_items', $post); ?> |
|
246 | 246 | <tr> |
247 | 247 | <th valign="top" scope="row"> |
248 | - <label for="wpinv_discount_excluded_items"><?php _e( 'Excluded Items', 'invoicing' ); ?></label> |
|
248 | + <label for="wpinv_discount_excluded_items"><?php _e('Excluded Items', 'invoicing'); ?></label> |
|
249 | 249 | </th> |
250 | 250 | <td> |
251 | - <p><?php echo wpinv_item_dropdown( array( |
|
251 | + <p><?php echo wpinv_item_dropdown(array( |
|
252 | 252 | 'name' => 'excluded_items[]', |
253 | 253 | 'id' => 'excluded_items', |
254 | 254 | 'selected' => $excluded_items, |
255 | 255 | 'multiple' => true, |
256 | 256 | 'class' => 'medium-text wpi_select2', |
257 | - 'placeholder' => __( 'Select one or more Items', 'invoicing' ), |
|
257 | + 'placeholder' => __('Select one or more Items', 'invoicing'), |
|
258 | 258 | 'show_recurring' => true, |
259 | - ) ); ?> |
|
259 | + )); ?> |
|
260 | 260 | </p> |
261 | - <p class="description"><?php _e( 'Items which are NOT allowed to use this discount.', 'invoicing' ); ?></p> |
|
261 | + <p class="description"><?php _e('Items which are NOT allowed to use this discount.', 'invoicing'); ?></p> |
|
262 | 262 | </td> |
263 | 263 | </tr> |
264 | - <?php do_action( 'wpinv_discount_form_before_start', $post ); ?> |
|
264 | + <?php do_action('wpinv_discount_form_before_start', $post); ?> |
|
265 | 265 | <tr> |
266 | 266 | <th valign="top" scope="row"> |
267 | - <label for="wpinv_discount_start"><?php _e( 'Start Date', 'invoicing' ); ?></label> |
|
267 | + <label for="wpinv_discount_start"><?php _e('Start Date', 'invoicing'); ?></label> |
|
268 | 268 | </th> |
269 | 269 | <td> |
270 | - <input type="text" class="w120 wpiDatepicker" id="wpinv_discount_start" data-dateFormat="yy-mm-dd" name="start" value="<?php echo esc_attr( $start_date ); ?>"> @ <select id="wpinv_discount_start_h" name="start_h"> |
|
271 | - <?php for ( $i = 0; $i <= 23; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
272 | - <option value="<?php echo $value;?>" <?php selected( $value, $start_h ); ?>><?php echo $value;?></option> |
|
270 | + <input type="text" class="w120 wpiDatepicker" id="wpinv_discount_start" data-dateFormat="yy-mm-dd" name="start" value="<?php echo esc_attr($start_date); ?>"> @ <select id="wpinv_discount_start_h" name="start_h"> |
|
271 | + <?php for ($i = 0; $i <= 23; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?> |
|
272 | + <option value="<?php echo $value; ?>" <?php selected($value, $start_h); ?>><?php echo $value; ?></option> |
|
273 | 273 | <?php } ?> |
274 | 274 | </select> : <select id="wpinv_discount_start_m" name="start_m"> |
275 | - <?php for ( $i = 0; $i <= 59; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
276 | - <option value="<?php echo $value;?>" <?php selected( $value, $start_m ); ?>><?php echo $value;?></option> |
|
275 | + <?php for ($i = 0; $i <= 59; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?> |
|
276 | + <option value="<?php echo $value; ?>" <?php selected($value, $start_m); ?>><?php echo $value; ?></option> |
|
277 | 277 | <?php } ?> |
278 | 278 | </select> |
279 | - <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> |
|
279 | + <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> |
|
280 | 280 | </td> |
281 | 281 | </tr> |
282 | - <?php do_action( 'wpinv_discount_form_before_expiration', $post ); ?> |
|
282 | + <?php do_action('wpinv_discount_form_before_expiration', $post); ?> |
|
283 | 283 | <tr> |
284 | 284 | <th valign="top" scope="row"> |
285 | - <label for="wpinv_discount_expiration"><?php _e( 'Expiration Date', 'invoicing' ); ?></label> |
|
285 | + <label for="wpinv_discount_expiration"><?php _e('Expiration Date', 'invoicing'); ?></label> |
|
286 | 286 | </th> |
287 | 287 | <td> |
288 | - <input type="text" class="w120 wpiDatepicker" id="wpinv_discount_expiration" data-dateFormat="yy-mm-dd" name="expiration" value="<?php echo esc_attr( $expiration_date ); ?>"> @ <select id="wpinv_discount_expiration_h" name="expiration_h"> |
|
289 | - <?php for ( $i = 0; $i <= 23; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
290 | - <option value="<?php echo $value;?>" <?php selected( $value, $expiration_h ); ?>><?php echo $value;?></option> |
|
288 | + <input type="text" class="w120 wpiDatepicker" id="wpinv_discount_expiration" data-dateFormat="yy-mm-dd" name="expiration" value="<?php echo esc_attr($expiration_date); ?>"> @ <select id="wpinv_discount_expiration_h" name="expiration_h"> |
|
289 | + <?php for ($i = 0; $i <= 23; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?> |
|
290 | + <option value="<?php echo $value; ?>" <?php selected($value, $expiration_h); ?>><?php echo $value; ?></option> |
|
291 | 291 | <?php } ?> |
292 | 292 | </select> : <select id="wpinv_discount_expiration_m" name="expiration_m"> |
293 | - <?php for ( $i = 0; $i <= 59; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
294 | - <option value="<?php echo $value;?>" <?php selected( $value, $expiration_m ); ?>><?php echo $value;?></option> |
|
293 | + <?php for ($i = 0; $i <= 59; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?> |
|
294 | + <option value="<?php echo $value; ?>" <?php selected($value, $expiration_m); ?>><?php echo $value; ?></option> |
|
295 | 295 | <?php } ?> |
296 | 296 | </select> |
297 | - <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> |
|
297 | + <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> |
|
298 | 298 | </td> |
299 | 299 | </tr> |
300 | - <?php do_action( 'wpinv_discount_form_before_min_total', $post ); ?> |
|
300 | + <?php do_action('wpinv_discount_form_before_min_total', $post); ?> |
|
301 | 301 | <tr> |
302 | 302 | <th valign="top" scope="row"> |
303 | - <label for="wpinv_discount_min_total"><?php _e( 'Minimum Amount', 'invoicing' ); ?></label> |
|
303 | + <label for="wpinv_discount_min_total"><?php _e('Minimum Amount', 'invoicing'); ?></label> |
|
304 | 304 | </th> |
305 | 305 | <td> |
306 | 306 | <input type="text" name="min_total" id="wpinv_discount_min_total" class="wpi-field-price wpi-price" value="<?php echo $min_total; ?>"> |
307 | - <p class="description"><?php _e( 'This allows you to set the minimum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p> |
|
307 | + <p class="description"><?php _e('This allows you to set the minimum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing'); ?></p> |
|
308 | 308 | </td> |
309 | 309 | </tr> |
310 | - <?php do_action( 'wpinv_discount_form_before_max_total', $post ); ?> |
|
310 | + <?php do_action('wpinv_discount_form_before_max_total', $post); ?> |
|
311 | 311 | <tr> |
312 | 312 | <th valign="top" scope="row"> |
313 | - <label for="wpinv_discount_max_total"><?php _e( 'Maximum Amount', 'invoicing' ); ?></label> |
|
313 | + <label for="wpinv_discount_max_total"><?php _e('Maximum Amount', 'invoicing'); ?></label> |
|
314 | 314 | </th> |
315 | 315 | <td> |
316 | 316 | <input type="text" name="max_total" id="wpinv_discount_max_total" class="wpi-field-price wpi-price" value="<?php echo $max_total; ?>"> |
317 | - <p class="description"><?php _e( 'This allows you to set the maximum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p> |
|
317 | + <p class="description"><?php _e('This allows you to set the maximum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing'); ?></p> |
|
318 | 318 | </td> |
319 | 319 | </tr> |
320 | - <?php do_action( 'wpinv_discount_form_before_recurring', $post ); ?> |
|
320 | + <?php do_action('wpinv_discount_form_before_recurring', $post); ?> |
|
321 | 321 | <tr> |
322 | 322 | <th valign="top" scope="row"> |
323 | - <label for="wpinv_discount_recurring"><?php _e( 'For recurring apply to', 'invoicing' ); ?></label> |
|
323 | + <label for="wpinv_discount_recurring"><?php _e('For recurring apply to', 'invoicing'); ?></label> |
|
324 | 324 | </th> |
325 | 325 | <td> |
326 | 326 | <select id="wpinv_discount_recurring" name="recurring" class="medium-text wpi_select2"> |
327 | - <option value="0" <?php selected( false, $recurring ); ?>><?php _e( 'First payment only', 'invoicing' ); ?></option> |
|
328 | - <option value="1" <?php selected( true, $recurring ); ?>><?php _e( 'All payments', 'invoicing' ); ?></option> |
|
327 | + <option value="0" <?php selected(false, $recurring); ?>><?php _e('First payment only', 'invoicing'); ?></option> |
|
328 | + <option value="1" <?php selected(true, $recurring); ?>><?php _e('All payments', 'invoicing'); ?></option> |
|
329 | 329 | </select> |
330 | - <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> |
|
330 | + <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> |
|
331 | 331 | </td> |
332 | 332 | </tr> |
333 | - <?php do_action( 'wpinv_discount_form_before_max_uses', $post ); ?> |
|
333 | + <?php do_action('wpinv_discount_form_before_max_uses', $post); ?> |
|
334 | 334 | <tr> |
335 | 335 | <th valign="top" scope="row"> |
336 | - <label for="wpinv_discount_max_uses"><?php _e( 'Max Uses', 'invoicing' ); ?></label> |
|
336 | + <label for="wpinv_discount_max_uses"><?php _e('Max Uses', 'invoicing'); ?></label> |
|
337 | 337 | </th> |
338 | 338 | <td> |
339 | 339 | <input type="number" min="0" step="1" id="wpinv_discount_max_uses" name="max_uses" class="medium-text" value="<?php echo $max_uses; ?>"> |
340 | - <p class="description"><?php _e( 'The maximum number of times this discount can be used. Leave blank for unlimited.', 'invoicing' ); ?></p> |
|
340 | + <p class="description"><?php _e('The maximum number of times this discount can be used. Leave blank for unlimited.', 'invoicing'); ?></p> |
|
341 | 341 | </td> |
342 | 342 | </tr> |
343 | - <?php do_action( 'wpinv_discount_form_before_single_use', $post ); ?> |
|
343 | + <?php do_action('wpinv_discount_form_before_single_use', $post); ?> |
|
344 | 344 | <tr> |
345 | 345 | <th valign="top" scope="row"> |
346 | - <label for="wpinv_discount_single_use"><?php _e( 'Use Once Per User', 'invoicing' ); ?></label> |
|
346 | + <label for="wpinv_discount_single_use"><?php _e('Use Once Per User', 'invoicing'); ?></label> |
|
347 | 347 | </th> |
348 | 348 | <td> |
349 | - <input type="checkbox" value="1" name="single_use" id="wpinv_discount_single_use" <?php checked( true, $single_use ); ?>> |
|
350 | - <span class="description"><?php _e( 'Limit this discount to a single use per user?', 'invoicing' ); ?></span> |
|
349 | + <input type="checkbox" value="1" name="single_use" id="wpinv_discount_single_use" <?php checked(true, $single_use); ?>> |
|
350 | + <span class="description"><?php _e('Limit this discount to a single use per user?', 'invoicing'); ?></span> |
|
351 | 351 | </td> |
352 | 352 | </tr> |
353 | - <?php do_action( 'wpinv_discount_form_last', $post ); ?> |
|
353 | + <?php do_action('wpinv_discount_form_last', $post); ?> |
|
354 | 354 | </tbody> |
355 | 355 | </table> |
356 | -<?php do_action( 'wpinv_discount_form_bottom', $post ); ?> |
|
356 | +<?php do_action('wpinv_discount_form_bottom', $post); ?> |
|
357 | 357 | <?php |
358 | 358 | } |
359 | 359 | |
360 | -function wpinv_discount_metabox_save( $post_id, $post, $update = false ) { |
|
361 | - $post_type = !empty( $post ) ? $post->post_type : ''; |
|
360 | +function wpinv_discount_metabox_save($post_id, $post, $update = false) { |
|
361 | + $post_type = !empty($post) ? $post->post_type : ''; |
|
362 | 362 | |
363 | - if ( $post_type != 'wpi_discount' ) { |
|
363 | + if ($post_type != 'wpi_discount') { |
|
364 | 364 | return; |
365 | 365 | } |
366 | 366 | |
367 | - 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' ) ) ) { |
|
367 | + 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'))) { |
|
368 | 368 | return; |
369 | 369 | } |
370 | 370 | |
371 | - if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
371 | + if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || (defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) { |
|
372 | 372 | return; |
373 | 373 | } |
374 | 374 | |
375 | - if ( !current_user_can( wpinv_get_capability(), $post_id ) ) { |
|
375 | + if (!current_user_can(wpinv_get_capability(), $post_id)) { |
|
376 | 376 | return; |
377 | 377 | } |
378 | 378 | |
379 | - if ( !empty( $_POST['start'] ) && isset( $_POST['start_h'] ) && isset( $_POST['start_m'] ) && $_POST['start_h'] !== '' && $_POST['start_m'] !== '' ) { |
|
379 | + if (!empty($_POST['start']) && isset($_POST['start_h']) && isset($_POST['start_m']) && $_POST['start_h'] !== '' && $_POST['start_m'] !== '') { |
|
380 | 380 | $_POST['start'] = $_POST['start'] . ' ' . $_POST['start_h'] . ':' . $_POST['start_m']; |
381 | 381 | } |
382 | 382 | |
383 | - if ( !empty( $_POST['expiration'] ) && isset( $_POST['expiration_h'] ) && isset( $_POST['expiration_m'] ) ) { |
|
383 | + if (!empty($_POST['expiration']) && isset($_POST['expiration_h']) && isset($_POST['expiration_m'])) { |
|
384 | 384 | $_POST['expiration'] = $_POST['expiration'] . ' ' . $_POST['expiration_h'] . ':' . $_POST['expiration_m']; |
385 | 385 | } |
386 | 386 | |
387 | - return /** @scrutinizer ignore-call */ wpinv_store_discount( $post_id, $_POST, $post, $update ); |
|
387 | + return /** @scrutinizer ignore-call */ wpinv_store_discount($post_id, $_POST, $post, $update); |
|
388 | 388 | } |
389 | -add_action( 'save_post', 'wpinv_discount_metabox_save', 10, 3 ); |
|
390 | 389 | \ No newline at end of file |
390 | +add_action('save_post', 'wpinv_discount_metabox_save', 10, 3); |
|
391 | 391 | \ No newline at end of file |
@@ -1,47 +1,47 @@ 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_Items { |
8 | - public static function output( $post ) { |
|
8 | + public static function output($post) { |
|
9 | 9 | global $wpinv_euvat, $ajax_cart_details; |
10 | 10 | |
11 | - $post_id = !empty( $post->ID ) ? $post->ID : 0; |
|
12 | - $invoice = new WPInv_Invoice( $post_id ); |
|
11 | + $post_id = !empty($post->ID) ? $post->ID : 0; |
|
12 | + $invoice = new WPInv_Invoice($post_id); |
|
13 | 13 | $ajax_cart_details = $invoice->get_cart_details(); |
14 | - $subtotal = $invoice->get_subtotal( true ); |
|
14 | + $subtotal = $invoice->get_subtotal(true); |
|
15 | 15 | $discount_raw = $invoice->get_discount(); |
16 | - $discount = wpinv_price( $discount_raw, $invoice->get_currency() ); |
|
16 | + $discount = wpinv_price($discount_raw, $invoice->get_currency()); |
|
17 | 17 | $discounts = $discount_raw > 0 ? $invoice->get_discounts() : ''; |
18 | - $tax = $invoice->get_tax( true ); |
|
19 | - $total = $invoice->get_total( true ); |
|
18 | + $tax = $invoice->get_tax(true); |
|
19 | + $total = $invoice->get_total(true); |
|
20 | 20 | $item_quantities = wpinv_item_quantities_enabled(); |
21 | 21 | $use_taxes = wpinv_use_taxes(); |
22 | - if ( !$use_taxes && (float)$invoice->get_tax() > 0 ) { |
|
22 | + if (!$use_taxes && (float) $invoice->get_tax() > 0) { |
|
23 | 23 | $use_taxes = true; |
24 | 24 | } |
25 | - $item_types = apply_filters( 'wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post ); |
|
25 | + $item_types = apply_filters('wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post); |
|
26 | 26 | $is_recurring = $invoice->is_recurring(); |
27 | 27 | $post_type_object = get_post_type_object($invoice->post_type); |
28 | 28 | $type_title = $post_type_object->labels->singular_name; |
29 | 29 | |
30 | 30 | $cols = 5; |
31 | - if ( $item_quantities ) { |
|
31 | + if ($item_quantities) { |
|
32 | 32 | $cols++; |
33 | 33 | } |
34 | - if ( $use_taxes ) { |
|
34 | + if ($use_taxes) { |
|
35 | 35 | $cols++; |
36 | 36 | } |
37 | 37 | $class = ''; |
38 | - if ( $invoice->is_paid() ) { |
|
38 | + if ($invoice->is_paid()) { |
|
39 | 39 | $class .= ' wpinv-paid'; |
40 | 40 | } |
41 | - if ( $invoice->is_refunded() ) { |
|
41 | + if ($invoice->is_refunded()) { |
|
42 | 42 | $class .= ' wpinv-refunded'; |
43 | 43 | } |
44 | - if ( $is_recurring ) { |
|
44 | + if ($is_recurring) { |
|
45 | 45 | $class .= ' wpi-recurring'; |
46 | 46 | } |
47 | 47 | ?> |
@@ -49,21 +49,21 @@ discard block |
||
49 | 49 | <table id="wpinv_items" class="wpinv-items" cellspacing="0" cellpadding="0"> |
50 | 50 | <thead> |
51 | 51 | <tr> |
52 | - <th class="id"><?php _e( 'ID', 'invoicing' );?></th> |
|
53 | - <th class="title"><?php _e( 'Item', 'invoicing' );?></th> |
|
54 | - <th class="price"><?php _e( 'Price', 'invoicing' );?></th> |
|
55 | - <?php if ( $item_quantities ) { ?> |
|
56 | - <th class="qty"><?php _e( 'Qty', 'invoicing' );?></th> |
|
52 | + <th class="id"><?php _e('ID', 'invoicing'); ?></th> |
|
53 | + <th class="title"><?php _e('Item', 'invoicing'); ?></th> |
|
54 | + <th class="price"><?php _e('Price', 'invoicing'); ?></th> |
|
55 | + <?php if ($item_quantities) { ?> |
|
56 | + <th class="qty"><?php _e('Qty', 'invoicing'); ?></th> |
|
57 | 57 | <?php } ?> |
58 | - <th class="total"><?php _e( 'Total', 'invoicing' );?></th> |
|
59 | - <?php if ( $use_taxes ) { ?> |
|
60 | - <th class="tax"><?php _e( 'Tax (%)', 'invoicing' );?></th> |
|
58 | + <th class="total"><?php _e('Total', 'invoicing'); ?></th> |
|
59 | + <?php if ($use_taxes) { ?> |
|
60 | + <th class="tax"><?php _e('Tax (%)', 'invoicing'); ?></th> |
|
61 | 61 | <?php } ?> |
62 | 62 | <th class="action"></th> |
63 | 63 | </tr> |
64 | 64 | </thead> |
65 | 65 | <tbody class="wpinv-line-items"> |
66 | - <?php echo wpinv_admin_get_line_items( $invoice ); ?> |
|
66 | + <?php echo wpinv_admin_get_line_items($invoice); ?> |
|
67 | 67 | </tbody> |
68 | 68 | <tfoot class="wpinv-totals"> |
69 | 69 | <tr> |
@@ -74,45 +74,45 @@ discard block |
||
74 | 74 | <td class="id"> |
75 | 75 | </td> |
76 | 76 | <td class="title"> |
77 | - <input type="text" class="regular-text" placeholder="<?php _e( 'Item Name', 'invoicing' ); ?>" value="" name="_wpinv_quick[name]"> |
|
78 | - <?php if ( $wpinv_euvat->allow_vat_rules() ) { ?> |
|
77 | + <input type="text" class="regular-text" placeholder="<?php _e('Item Name', 'invoicing'); ?>" value="" name="_wpinv_quick[name]"> |
|
78 | + <?php if ($wpinv_euvat->allow_vat_rules()) { ?> |
|
79 | 79 | <div class="wp-clearfix"> |
80 | 80 | <label class="wpi-vat-rule"> |
81 | - <span class="title"><?php _e( 'VAT rule type', 'invoicing' );?></span> |
|
81 | + <span class="title"><?php _e('VAT rule type', 'invoicing'); ?></span> |
|
82 | 82 | <span class="input-text-wrap"> |
83 | - <?php echo wpinv_html_select( array( |
|
83 | + <?php echo wpinv_html_select(array( |
|
84 | 84 | 'options' => $wpinv_euvat->get_rules(), |
85 | 85 | 'name' => '_wpinv_quick[vat_rule]', |
86 | 86 | 'id' => '_wpinv_quick_vat_rule', |
87 | 87 | 'show_option_all' => false, |
88 | 88 | 'show_option_none' => false, |
89 | 89 | 'class' => 'gdmbx2-text-medium wpinv-quick-vat-rule wpi_select2', |
90 | - ) ); ?> |
|
90 | + )); ?> |
|
91 | 91 | </span> |
92 | 92 | </label> |
93 | 93 | </div> |
94 | - <?php } if ( $wpinv_euvat->allow_vat_classes() ) { ?> |
|
94 | + <?php } if ($wpinv_euvat->allow_vat_classes()) { ?> |
|
95 | 95 | <div class="wp-clearfix"> |
96 | 96 | <label class="wpi-vat-class"> |
97 | - <span class="title"><?php _e( 'VAT class', 'invoicing' );?></span> |
|
97 | + <span class="title"><?php _e('VAT class', 'invoicing'); ?></span> |
|
98 | 98 | <span class="input-text-wrap"> |
99 | - <?php echo wpinv_html_select( array( |
|
99 | + <?php echo wpinv_html_select(array( |
|
100 | 100 | 'options' => $wpinv_euvat->get_all_classes(), |
101 | 101 | 'name' => '_wpinv_quick[vat_class]', |
102 | 102 | 'id' => '_wpinv_quick_vat_class', |
103 | 103 | 'show_option_all' => false, |
104 | 104 | 'show_option_none' => false, |
105 | 105 | 'class' => 'gdmbx2-text-medium wpinv-quick-vat-class wpi_select2', |
106 | - ) ); ?> |
|
106 | + )); ?> |
|
107 | 107 | </span> |
108 | 108 | </label> |
109 | 109 | </div> |
110 | 110 | <?php } ?> |
111 | 111 | <div class="wp-clearfix"> |
112 | 112 | <label class="wpi-item-type"> |
113 | - <span class="title"><?php _e( 'Item type', 'invoicing' );?></span> |
|
113 | + <span class="title"><?php _e('Item type', 'invoicing'); ?></span> |
|
114 | 114 | <span class="input-text-wrap"> |
115 | - <?php echo wpinv_html_select( array( |
|
115 | + <?php echo wpinv_html_select(array( |
|
116 | 116 | 'options' => $item_types, |
117 | 117 | 'name' => '_wpinv_quick[type]', |
118 | 118 | 'id' => '_wpinv_quick_type', |
@@ -120,37 +120,37 @@ discard block |
||
120 | 120 | 'show_option_all' => false, |
121 | 121 | 'show_option_none' => false, |
122 | 122 | 'class' => 'gdmbx2-text-medium wpinv-quick-type wpi_select2', |
123 | - ) ); ?> |
|
123 | + )); ?> |
|
124 | 124 | </span> |
125 | 125 | </label> |
126 | 126 | </div> |
127 | 127 | |
128 | 128 | <div class="wp-clearfix"> |
129 | 129 | <?php |
130 | - echo wpinv_html_textarea( array( |
|
130 | + echo wpinv_html_textarea(array( |
|
131 | 131 | 'name' => '_wpinv_quick[excerpt]', |
132 | 132 | 'id' => '_wpinv_quick_excerpt', |
133 | 133 | 'value' => '', |
134 | 134 | 'class' => 'large-text', |
135 | - 'label' => __( 'Item description', 'invoicing' ), |
|
136 | - ) ); |
|
135 | + 'label' => __('Item description', 'invoicing'), |
|
136 | + )); |
|
137 | 137 | ?> |
138 | 138 | </div> |
139 | 139 | |
140 | 140 | <div class="wp-clearfix"> |
141 | 141 | <label class="wpi-item-actions"> |
142 | 142 | <span class="input-text-wrap"> |
143 | - <input type="button" value="<?php esc_attr_e( 'Add', 'invoicing' ); ?>" class="button button-primary" id="wpinv-save-item"><input type="button" value="Cancel" class="button button-secondary" id="wpinv-cancel-item"> |
|
143 | + <input type="button" value="<?php esc_attr_e('Add', 'invoicing'); ?>" class="button button-primary" id="wpinv-save-item"><input type="button" value="Cancel" class="button button-secondary" id="wpinv-cancel-item"> |
|
144 | 144 | </span> |
145 | 145 | </label> |
146 | 146 | </div> |
147 | 147 | </td> |
148 | 148 | <td class="price"><input type="text" placeholder="0.00" class="wpi-field-price wpi-price" name="_wpinv_quick[price]" /></td> |
149 | - <?php if ( $item_quantities ) { ?> |
|
149 | + <?php if ($item_quantities) { ?> |
|
150 | 150 | <td class="qty"><input type="number" class="small-text" step="1" min="1" value="1" name="_wpinv_quick[qty]" /></td> |
151 | 151 | <?php } ?> |
152 | 152 | <td class="total"></td> |
153 | - <?php if ( $use_taxes ) { ?> |
|
153 | + <?php if ($use_taxes) { ?> |
|
154 | 154 | <td class="tax"></td> |
155 | 155 | <?php } ?> |
156 | 156 | <td class="action"></td> |
@@ -163,29 +163,29 @@ discard block |
||
163 | 163 | <td colspan="<?php echo $cols; ?>"></td> |
164 | 164 | </tr> |
165 | 165 | <tr class="totals"> |
166 | - <td colspan="<?php echo ( $cols - 4 ); ?>"></td> |
|
166 | + <td colspan="<?php echo ($cols - 4); ?>"></td> |
|
167 | 167 | <td colspan="4"> |
168 | 168 | <table cellspacing="0" cellpadding="0"> |
169 | 169 | <tr class="subtotal"> |
170 | - <td class="name"><?php _e( 'Sub Total:', 'invoicing' );?></td> |
|
171 | - <td class="total"><?php echo $subtotal;?></td> |
|
170 | + <td class="name"><?php _e('Sub Total:', 'invoicing'); ?></td> |
|
171 | + <td class="total"><?php echo $subtotal; ?></td> |
|
172 | 172 | <td class="action"></td> |
173 | 173 | </tr> |
174 | 174 | <tr class="discount"> |
175 | - <td class="name"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice->ID ) ); ?>:</td> |
|
176 | - <td class="total"><?php echo wpinv_discount( $invoice->ID, true, true ); ?></td> |
|
175 | + <td class="name"><?php wpinv_get_discount_label(wpinv_discount_code($invoice->ID)); ?>:</td> |
|
176 | + <td class="total"><?php echo wpinv_discount($invoice->ID, true, true); ?></td> |
|
177 | 177 | <td class="action"></td> |
178 | 178 | </tr> |
179 | - <?php if ( $use_taxes ) { ?> |
|
179 | + <?php if ($use_taxes) { ?> |
|
180 | 180 | <tr class="tax"> |
181 | - <td class="name"><?php _e( 'Tax:', 'invoicing' );?></td> |
|
182 | - <td class="total"><?php echo $tax;?></td> |
|
181 | + <td class="name"><?php _e('Tax:', 'invoicing'); ?></td> |
|
182 | + <td class="total"><?php echo $tax; ?></td> |
|
183 | 183 | <td class="action"></td> |
184 | 184 | </tr> |
185 | 185 | <?php } ?> |
186 | 186 | <tr class="total"> |
187 | - <td class="name"><?php echo apply_filters( 'wpinv_invoice_items_total_label', __( 'Invoice Total:', 'invoicing' ), $invoice );?></td> |
|
188 | - <td class="total"><?php echo $total;?></td> |
|
187 | + <td class="name"><?php echo apply_filters('wpinv_invoice_items_total_label', __('Invoice Total:', 'invoicing'), $invoice); ?></td> |
|
188 | + <td class="total"><?php echo $total; ?></td> |
|
189 | 189 | <td class="action"></td> |
190 | 190 | </tr> |
191 | 191 | </table> |
@@ -196,90 +196,90 @@ discard block |
||
196 | 196 | <div class="wpinv-actions"> |
197 | 197 | <?php ob_start(); ?> |
198 | 198 | <?php |
199 | - if ( !$invoice->is_paid() && !$invoice->is_refunded() ) { |
|
200 | - if ( !$invoice->is_recurring() ) { |
|
201 | - echo wpinv_item_dropdown( array( |
|
199 | + if (!$invoice->is_paid() && !$invoice->is_refunded()) { |
|
200 | + if (!$invoice->is_recurring()) { |
|
201 | + echo wpinv_item_dropdown(array( |
|
202 | 202 | 'name' => 'wpinv_invoice_item', |
203 | 203 | 'id' => 'wpinv_invoice_item', |
204 | 204 | 'show_recurring' => true, |
205 | 205 | 'class' => 'wpi_select2', |
206 | - ) ); |
|
206 | + )); |
|
207 | 207 | ?> |
208 | - <input type="button" value="<?php echo sprintf(esc_attr__( 'Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e( 'Create new item', 'invoicing' );?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e( 'Recalculate Totals', 'invoicing' );?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals"> |
|
208 | + <input type="button" value="<?php echo sprintf(esc_attr__('Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e('Create new item', 'invoicing'); ?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e('Recalculate Totals', 'invoicing'); ?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals"> |
|
209 | 209 | <?php } ?> |
210 | - <?php do_action( 'wpinv_invoice_items_actions', $invoice ); ?> |
|
211 | - <?php $item_actions = ob_get_clean(); echo apply_filters( 'wpinv_invoice_items_actions_content', $item_actions, $invoice, $post ); ?> |
|
210 | + <?php do_action('wpinv_invoice_items_actions', $invoice); ?> |
|
211 | + <?php $item_actions = ob_get_clean(); echo apply_filters('wpinv_invoice_items_actions_content', $item_actions, $invoice, $post); ?> |
|
212 | 212 | </div> |
213 | 213 | </div> |
214 | 214 | <?php |
215 | 215 | } |
216 | 216 | |
217 | - public static function prices( $post ) { |
|
217 | + public static function prices($post) { |
|
218 | 218 | $symbol = wpinv_currency_symbol(); |
219 | 219 | $position = wpinv_currency_position(); |
220 | - $item = new WPInv_Item( $post->ID ); |
|
220 | + $item = new WPInv_Item($post->ID); |
|
221 | 221 | |
222 | 222 | $price = $item->get_price(); |
223 | 223 | $is_dynamic_pricing = $item->get_is_dynamic_pricing(); |
224 | 224 | $minimum_price = $item->get_minimum_price(); |
225 | 225 | $is_recurring = $item->is_recurring(); |
226 | 226 | $period = $item->get_recurring_period(); |
227 | - $interval = absint( $item->get_recurring_interval() ); |
|
228 | - $times = absint( $item->get_recurring_limit() ); |
|
227 | + $interval = absint($item->get_recurring_interval()); |
|
228 | + $times = absint($item->get_recurring_limit()); |
|
229 | 229 | $free_trial = $item->has_free_trial(); |
230 | 230 | $trial_interval = $item->get_trial_interval(); |
231 | 231 | $trial_period = $item->get_trial_period(); |
232 | 232 | |
233 | 233 | $intervals = array(); |
234 | - for ( $i = 1; $i <= 90; $i++ ) { |
|
234 | + for ($i = 1; $i <= 90; $i++) { |
|
235 | 235 | $intervals[$i] = $i; |
236 | 236 | } |
237 | 237 | |
238 | - $interval = $interval > 0 ? $interval : 1; |
|
238 | + $interval = $interval > 0 ? $interval : 1; |
|
239 | 239 | |
240 | 240 | $class = $is_recurring ? 'wpinv-recurring-y' : 'wpinv-recurring-n'; |
241 | 241 | |
242 | 242 | $minimum_price_style = 'margin-left: 24px;'; |
243 | - if(! $is_dynamic_pricing ) { |
|
243 | + if (!$is_dynamic_pricing) { |
|
244 | 244 | $minimum_price_style .= 'display: none;'; |
245 | 245 | } |
246 | 246 | |
247 | 247 | ?> |
248 | - <p class="wpinv-row-prices"><?php echo ( $position != 'right' ? $symbol . ' ' : '' );?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount( 0 ); ?>" value="<?php echo $price;?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled( $item->is_editable(), false ); ?> /><?php echo ( $position == 'right' ? ' ' . $symbol : '' );?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce( 'wpinv_item_meta_box_save' ) ;?>" /> |
|
249 | - <?php do_action( 'wpinv_prices_metabox_price', $item ); ?> |
|
248 | + <p class="wpinv-row-prices"><?php echo ($position != 'right' ? $symbol . ' ' : ''); ?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount(0); ?>" value="<?php echo $price; ?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled($item->is_editable(), false); ?> /><?php echo ($position == 'right' ? ' ' . $symbol : ''); ?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce('wpinv_item_meta_box_save'); ?>" /> |
|
249 | + <?php do_action('wpinv_prices_metabox_price', $item); ?> |
|
250 | 250 | </p> |
251 | 251 | |
252 | - <?php if( $item->supports_dynamic_pricing() ) { ?> |
|
252 | + <?php if ($item->supports_dynamic_pricing()) { ?> |
|
253 | 253 | |
254 | 254 | <p class="wpinv-row-name-your-price"> |
255 | 255 | <label> |
256 | - <input type="checkbox" name="wpinv_name_your_price" id="wpinv_name_your_price" value="1" <?php checked( 1, $is_dynamic_pricing ); ?> /> |
|
257 | - <?php echo apply_filters( 'wpinv_name_your_price_toggle_text', __( 'User can set a custom price', 'invoicing' ) ); ?> |
|
256 | + <input type="checkbox" name="wpinv_name_your_price" id="wpinv_name_your_price" value="1" <?php checked(1, $is_dynamic_pricing); ?> /> |
|
257 | + <?php echo apply_filters('wpinv_name_your_price_toggle_text', __('User can set a custom price', 'invoicing')); ?> |
|
258 | 258 | </label> |
259 | - <?php do_action( 'wpinv_prices_metabox_name_your_price_field', $item ); ?> |
|
259 | + <?php do_action('wpinv_prices_metabox_name_your_price_field', $item); ?> |
|
260 | 260 | </p> |
261 | 261 | |
262 | 262 | <p class="wpinv-row-minimum-price" style="<?php echo $minimum_price_style; ?>"> |
263 | 263 | <label> |
264 | - <?php _e( 'Minimum Price', 'invoicing' ); ?> |
|
265 | - <?php echo ( $position != 'right' ? $symbol . ' ' : '' );?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount( 0 ); ?>" value="<?php echo $minimum_price;?>" id="wpinv_minimum_price" name="wpinv_minimum_price" class="medium-text wpi-field-price" <?php disabled( $item->is_editable(), false ); ?> /><?php echo ( $position == 'right' ? ' ' . $symbol : '' );?> |
|
264 | + <?php _e('Minimum Price', 'invoicing'); ?> |
|
265 | + <?php echo ($position != 'right' ? $symbol . ' ' : ''); ?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount(0); ?>" value="<?php echo $minimum_price; ?>" id="wpinv_minimum_price" name="wpinv_minimum_price" class="medium-text wpi-field-price" <?php disabled($item->is_editable(), false); ?> /><?php echo ($position == 'right' ? ' ' . $symbol : ''); ?> |
|
266 | 266 | </label> |
267 | 267 | |
268 | - <?php do_action( 'wpinv_prices_metabox_minimum_price_field', $item ); ?> |
|
268 | + <?php do_action('wpinv_prices_metabox_minimum_price_field', $item); ?> |
|
269 | 269 | </p> |
270 | 270 | |
271 | 271 | <?php } ?> |
272 | 272 | |
273 | 273 | <p class="wpinv-row-is-recurring"> |
274 | 274 | <label for="wpinv_is_recurring"> |
275 | - <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked( 1, $is_recurring ); ?> /> |
|
276 | - <?php echo apply_filters( 'wpinv_is_recurring_toggle_text', __( 'Is Recurring Item?', 'invoicing' ) ); ?> |
|
275 | + <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked(1, $is_recurring); ?> /> |
|
276 | + <?php echo apply_filters('wpinv_is_recurring_toggle_text', __('Is Recurring Item?', 'invoicing')); ?> |
|
277 | 277 | </label> |
278 | - <?php do_action( 'wpinv_prices_metabox_is_recurring_field', $item ); ?> |
|
278 | + <?php do_action('wpinv_prices_metabox_is_recurring_field', $item); ?> |
|
279 | 279 | </p> |
280 | - <p class="wpinv-row-recurring-fields <?php echo $class;?>"> |
|
281 | - <label class="wpinv-period" for="wpinv_recurring_period"><?php _e( 'Recurring', 'invoicing' );?> <select class="wpinv-select wpi_select2" id="wpinv_recurring_period" name="wpinv_recurring_period"><option value="D" data-text="<?php esc_attr_e( 'day(s)', 'invoicing' ); ?>" <?php selected( 'D', $period );?>><?php _e( 'Daily', 'invoicing' ); ?></option><option value="W" data-text="<?php esc_attr_e( 'week(s)', 'invoicing' ); ?>" <?php selected( 'W', $period );?>><?php _e( 'Weekly', 'invoicing' ); ?></option><option value="M" data-text="<?php esc_attr_e( 'month(s)', 'invoicing' ); ?>" <?php selected( 'M', $period );?>><?php _e( 'Monthly', 'invoicing' ); ?></option><option value="Y" data-text="<?php esc_attr_e( 'year(s)', 'invoicing' ); ?>" <?php selected( 'Y', $period );?>><?php _e( 'Yearly', 'invoicing' ); ?></option></select></label> |
|
282 | - <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e( 'at every', 'invoicing' );?> <?php echo wpinv_html_select( array( |
|
280 | + <p class="wpinv-row-recurring-fields <?php echo $class; ?>"> |
|
281 | + <label class="wpinv-period" for="wpinv_recurring_period"><?php _e('Recurring', 'invoicing'); ?> <select class="wpinv-select wpi_select2" id="wpinv_recurring_period" name="wpinv_recurring_period"><option value="D" data-text="<?php esc_attr_e('day(s)', 'invoicing'); ?>" <?php selected('D', $period); ?>><?php _e('Daily', 'invoicing'); ?></option><option value="W" data-text="<?php esc_attr_e('week(s)', 'invoicing'); ?>" <?php selected('W', $period); ?>><?php _e('Weekly', 'invoicing'); ?></option><option value="M" data-text="<?php esc_attr_e('month(s)', 'invoicing'); ?>" <?php selected('M', $period); ?>><?php _e('Monthly', 'invoicing'); ?></option><option value="Y" data-text="<?php esc_attr_e('year(s)', 'invoicing'); ?>" <?php selected('Y', $period); ?>><?php _e('Yearly', 'invoicing'); ?></option></select></label> |
|
282 | + <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e('at every', 'invoicing'); ?> <?php echo wpinv_html_select(array( |
|
283 | 283 | 'options' => $intervals, |
284 | 284 | 'name' => 'wpinv_recurring_interval', |
285 | 285 | 'id' => 'wpinv_recurring_interval', |
@@ -287,30 +287,30 @@ discard block |
||
287 | 287 | 'show_option_all' => false, |
288 | 288 | 'show_option_none' => false, |
289 | 289 | 'class' => 'wpi_select2', |
290 | - ) ); ?> <span id="wpinv_interval_text"><?php _e( 'day(s)', 'invoicing' );?></span></label> |
|
291 | - <label class="wpinv-times" for="wpinv_recurring_limit"> <?php _e( 'for', 'invoicing' );?> <input class="small-text" type="number" value="<?php echo $times;?>" size="4" id="wpinv_recurring_limit" name="wpinv_recurring_limit" step="1" min="0"> <?php _e( 'time(s) <i>(select 0 for recurring forever until cancelled</i>)', 'invoicing' );?></label> |
|
290 | + )); ?> <span id="wpinv_interval_text"><?php _e('day(s)', 'invoicing'); ?></span></label> |
|
291 | + <label class="wpinv-times" for="wpinv_recurring_limit"> <?php _e('for', 'invoicing'); ?> <input class="small-text" type="number" value="<?php echo $times; ?>" size="4" id="wpinv_recurring_limit" name="wpinv_recurring_limit" step="1" min="0"> <?php _e('time(s) <i>(select 0 for recurring forever until cancelled</i>)', 'invoicing'); ?></label> |
|
292 | 292 | <span class="clear wpi-trial-clr"></span> |
293 | 293 | <label class="wpinv-free-trial" for="wpinv_free_trial"> |
294 | - <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked( true, (bool)$free_trial ); ?> /> |
|
295 | - <?php echo __( 'Offer free trial for', 'invoicing' ); ?> |
|
294 | + <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked(true, (bool) $free_trial); ?> /> |
|
295 | + <?php echo __('Offer free trial for', 'invoicing'); ?> |
|
296 | 296 | </label> |
297 | 297 | <label class="wpinv-trial-interval" for="wpinv_trial_interval"> |
298 | - <input class="small-text" type="number" value="<?php echo $trial_interval;?>" size="4" id="wpinv_trial_interval" name="wpinv_trial_interval" step="1" min="1"> <select class="wpinv-select wpi_select2" id="wpinv_trial_period" name="wpinv_trial_period"><option value="D" <?php selected( 'D', $trial_period );?>><?php _e( 'day(s)', 'invoicing' ); ?></option><option value="W" <?php selected( 'W', $trial_period );?>><?php _e( 'week(s)', 'invoicing' ); ?></option><option value="M" <?php selected( 'M', $trial_period );?>><?php _e( 'month(s)', 'invoicing' ); ?></option><option value="Y" <?php selected( 'Y', $trial_period );?>><?php _e( 'year(s)', 'invoicing' ); ?></option></select> |
|
298 | + <input class="small-text" type="number" value="<?php echo $trial_interval; ?>" size="4" id="wpinv_trial_interval" name="wpinv_trial_interval" step="1" min="1"> <select class="wpinv-select wpi_select2" id="wpinv_trial_period" name="wpinv_trial_period"><option value="D" <?php selected('D', $trial_period); ?>><?php _e('day(s)', 'invoicing'); ?></option><option value="W" <?php selected('W', $trial_period); ?>><?php _e('week(s)', 'invoicing'); ?></option><option value="M" <?php selected('M', $trial_period); ?>><?php _e('month(s)', 'invoicing'); ?></option><option value="Y" <?php selected('Y', $trial_period); ?>><?php _e('year(s)', 'invoicing'); ?></option></select> |
|
299 | 299 | </label> |
300 | - <?php do_action( 'wpinv_prices_metabox_recurring_fields', $item ); ?> |
|
300 | + <?php do_action('wpinv_prices_metabox_recurring_fields', $item); ?> |
|
301 | 301 | </p> |
302 | - <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type( $post->ID ); ?>" /> |
|
303 | - <?php do_action( 'wpinv_item_price_field', $post->ID ); ?> |
|
302 | + <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type($post->ID); ?>" /> |
|
303 | + <?php do_action('wpinv_item_price_field', $post->ID); ?> |
|
304 | 304 | <?php |
305 | 305 | } |
306 | 306 | |
307 | - public static function vat_rules( $post ) { |
|
307 | + public static function vat_rules($post) { |
|
308 | 308 | global $wpinv_euvat; |
309 | 309 | |
310 | - $rule_type = $wpinv_euvat->get_item_rule( $post->ID ); |
|
310 | + $rule_type = $wpinv_euvat->get_item_rule($post->ID); |
|
311 | 311 | ?> |
312 | - <p><label for="wpinv_vat_rules"><strong><?php _e( 'Select how VAT rules will be applied:', 'invoicing' );?></strong></label> |
|
313 | - <?php echo wpinv_html_select( array( |
|
312 | + <p><label for="wpinv_vat_rules"><strong><?php _e('Select how VAT rules will be applied:', 'invoicing'); ?></strong></label> |
|
313 | + <?php echo wpinv_html_select(array( |
|
314 | 314 | 'options' => $wpinv_euvat->get_rules(), |
315 | 315 | 'name' => 'wpinv_vat_rules', |
316 | 316 | 'id' => 'wpinv_vat_rules', |
@@ -318,20 +318,20 @@ discard block |
||
318 | 318 | 'show_option_all' => false, |
319 | 319 | 'show_option_none' => false, |
320 | 320 | 'class' => 'gdmbx2-text-medium wpinv-vat-rules wpi_select2', |
321 | - ) ); ?> |
|
321 | + )); ?> |
|
322 | 322 | </p> |
323 | - <p class="wpi-m0"><?php _e( 'When you select physical product rules, only consumers and businesses in your country will be charged VAT. The VAT rate used will be the rate in your country.', 'invoicing' ); ?></p> |
|
324 | - <p class="wpi-m0"><?php _e( 'If you select Digital product rules, VAT will be charged at the rate that applies in the country of the consumer. Only businesses in your country will be charged VAT.', 'invoicing' ); ?></p> |
|
325 | - <p class="wpi-m0"><?php _e( 'Select "Tax-Free" if you do not want to charge VAT for this item.', 'invoicing' ); ?></p> |
|
323 | + <p class="wpi-m0"><?php _e('When you select physical product rules, only consumers and businesses in your country will be charged VAT. The VAT rate used will be the rate in your country.', 'invoicing'); ?></p> |
|
324 | + <p class="wpi-m0"><?php _e('If you select Digital product rules, VAT will be charged at the rate that applies in the country of the consumer. Only businesses in your country will be charged VAT.', 'invoicing'); ?></p> |
|
325 | + <p class="wpi-m0"><?php _e('Select "Tax-Free" if you do not want to charge VAT for this item.', 'invoicing'); ?></p> |
|
326 | 326 | <?php |
327 | 327 | } |
328 | 328 | |
329 | - public static function vat_classes( $post ) { |
|
329 | + public static function vat_classes($post) { |
|
330 | 330 | global $wpinv_euvat; |
331 | 331 | |
332 | - $vat_class = $wpinv_euvat->get_item_class( $post->ID ); |
|
332 | + $vat_class = $wpinv_euvat->get_item_class($post->ID); |
|
333 | 333 | ?> |
334 | - <p><?php echo wpinv_html_select( array( |
|
334 | + <p><?php echo wpinv_html_select(array( |
|
335 | 335 | 'options' => $wpinv_euvat->get_all_classes(), |
336 | 336 | 'name' => 'wpinv_vat_class', |
337 | 337 | 'id' => 'wpinv_vat_class', |
@@ -339,18 +339,18 @@ discard block |
||
339 | 339 | 'show_option_all' => false, |
340 | 340 | 'show_option_none' => false, |
341 | 341 | 'class' => 'gdmbx2-text-medium wpinv-vat-class wpi_select2', |
342 | - ) ); ?> |
|
342 | + )); ?> |
|
343 | 343 | </p> |
344 | - <p class="wpi-m0"><?php _e( 'Select the VAT rate class to use for this invoice item.', 'invoicing' ); ?></p> |
|
344 | + <p class="wpi-m0"><?php _e('Select the VAT rate class to use for this invoice item.', 'invoicing'); ?></p> |
|
345 | 345 | <?php |
346 | 346 | } |
347 | 347 | |
348 | - public static function item_info( $post ) { |
|
349 | - $item_type = wpinv_get_item_type( $post->ID ); |
|
350 | - do_action( 'wpinv_item_info_metabox_before', $post ); |
|
348 | + public static function item_info($post) { |
|
349 | + $item_type = wpinv_get_item_type($post->ID); |
|
350 | + do_action('wpinv_item_info_metabox_before', $post); |
|
351 | 351 | ?> |
352 | - <p><label for="wpinv_item_type"><strong><?php _e( 'Type:', 'invoicing' );?></strong></label> |
|
353 | - <?php echo wpinv_html_select( array( |
|
352 | + <p><label for="wpinv_item_type"><strong><?php _e('Type:', 'invoicing'); ?></strong></label> |
|
353 | + <?php echo wpinv_html_select(array( |
|
354 | 354 | 'options' => wpinv_get_item_types(), |
355 | 355 | 'name' => 'wpinv_item_type', |
356 | 356 | 'id' => 'wpinv_item_type', |
@@ -358,123 +358,123 @@ discard block |
||
358 | 358 | 'show_option_all' => false, |
359 | 359 | 'show_option_none' => false, |
360 | 360 | 'class' => 'gdmbx2-text-medium wpinv-item-type', |
361 | - ) ); ?> |
|
361 | + )); ?> |
|
362 | 362 | </p> |
363 | - <p class="wpi-m0"><?php _e( 'Select item type.', 'invoicing' );?><br><?php _e( '<b>Standard:</b> Standard item type', 'invoicing' );?><br><?php _e( '<b>Fee:</b> Like Registration Fee, Sign up Fee etc.', 'invoicing' );?></p> |
|
363 | + <p class="wpi-m0"><?php _e('Select item type.', 'invoicing'); ?><br><?php _e('<b>Standard:</b> Standard item type', 'invoicing'); ?><br><?php _e('<b>Fee:</b> Like Registration Fee, Sign up Fee etc.', 'invoicing'); ?></p> |
|
364 | 364 | <?php |
365 | - do_action( 'wpinv_item_info_metabox_after', $post ); |
|
365 | + do_action('wpinv_item_info_metabox_after', $post); |
|
366 | 366 | } |
367 | 367 | |
368 | - public static function meta_values( $post ) { |
|
369 | - $meta_keys = apply_filters( 'wpinv_show_meta_values_for_keys', array( |
|
368 | + public static function meta_values($post) { |
|
369 | + $meta_keys = apply_filters('wpinv_show_meta_values_for_keys', array( |
|
370 | 370 | 'type', |
371 | 371 | 'custom_id' |
372 | - ) ); |
|
372 | + )); |
|
373 | 373 | |
374 | - if ( empty( $meta_keys ) ) { |
|
374 | + if (empty($meta_keys)) { |
|
375 | 375 | return; |
376 | 376 | } |
377 | 377 | |
378 | - do_action( 'wpinv_meta_values_metabox_before', $post ); |
|
378 | + do_action('wpinv_meta_values_metabox_before', $post); |
|
379 | 379 | |
380 | - foreach ( $meta_keys as $meta_key ) { |
|
380 | + foreach ($meta_keys as $meta_key) { |
|
381 | 381 | ?> |
382 | - <p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta( $post->ID, '_wpinv_' . $meta_key, true ); ?></label></p> |
|
382 | + <p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta($post->ID, '_wpinv_' . $meta_key, true); ?></label></p> |
|
383 | 383 | <?php |
384 | 384 | } |
385 | 385 | |
386 | - do_action( 'wpinv_meta_values_metabox_after', $post ); |
|
386 | + do_action('wpinv_meta_values_metabox_after', $post); |
|
387 | 387 | } |
388 | 388 | |
389 | 389 | /** |
390 | 390 | * Display the items buy now shortcode. |
391 | 391 | */ |
392 | - public static function shortcode( $post ) { |
|
392 | + public static function shortcode($post) { |
|
393 | 393 | |
394 | - if ( ! is_numeric( $post ) ) { |
|
394 | + if (!is_numeric($post)) { |
|
395 | 395 | $post = $post->ID; |
396 | 396 | } |
397 | - $label = '"' . __( 'Buy', 'invoicing' ) . '"'; |
|
397 | + $label = '"' . __('Buy', 'invoicing') . '"'; |
|
398 | 398 | |
399 | 399 | echo "<input type='text' style='min-width: 100%; font-size: small;' value='[wpinv_buy items=$post label=$label]' disabled>"; |
400 | - echo "<p class='description'><a target='_blank' href='https://wpinvoicing.com/docs/core-plugin/core-shortcodes/#buy-button'>" . __( 'Learn More', 'invoicing' ) ."</a></p>"; |
|
400 | + echo "<p class='description'><a target='_blank' href='https://wpinvoicing.com/docs/core-plugin/core-shortcodes/#buy-button'>" . __('Learn More', 'invoicing') . "</a></p>"; |
|
401 | 401 | } |
402 | 402 | |
403 | - public static function save( $post_id, $data, $post ) { |
|
404 | - $invoice = new WPInv_Invoice( $post_id ); |
|
403 | + public static function save($post_id, $data, $post) { |
|
404 | + $invoice = new WPInv_Invoice($post_id); |
|
405 | 405 | |
406 | 406 | // Billing |
407 | - $first_name = sanitize_text_field( $data['wpinv_first_name'] ); |
|
408 | - $last_name = sanitize_text_field( $data['wpinv_last_name'] ); |
|
409 | - $company = sanitize_text_field( $data['wpinv_company'] ); |
|
410 | - $vat_number = sanitize_text_field( $data['wpinv_vat_number'] ); |
|
411 | - $phone = sanitize_text_field( $data['wpinv_phone'] ); |
|
412 | - $address = sanitize_text_field( $data['wpinv_address'] ); |
|
413 | - $city = sanitize_text_field( $data['wpinv_city'] ); |
|
414 | - $zip = sanitize_text_field( $data['wpinv_zip'] ); |
|
415 | - $country = sanitize_text_field( $data['wpinv_country'] ); |
|
416 | - $state = sanitize_text_field( $data['wpinv_state'] ); |
|
407 | + $first_name = sanitize_text_field($data['wpinv_first_name']); |
|
408 | + $last_name = sanitize_text_field($data['wpinv_last_name']); |
|
409 | + $company = sanitize_text_field($data['wpinv_company']); |
|
410 | + $vat_number = sanitize_text_field($data['wpinv_vat_number']); |
|
411 | + $phone = sanitize_text_field($data['wpinv_phone']); |
|
412 | + $address = sanitize_text_field($data['wpinv_address']); |
|
413 | + $city = sanitize_text_field($data['wpinv_city']); |
|
414 | + $zip = sanitize_text_field($data['wpinv_zip']); |
|
415 | + $country = sanitize_text_field($data['wpinv_country']); |
|
416 | + $state = sanitize_text_field($data['wpinv_state']); |
|
417 | 417 | |
418 | 418 | // Details |
419 | - $status = sanitize_text_field( $data['wpinv_status'] ); |
|
420 | - $old_status = !empty( $data['original_post_status'] ) ? sanitize_text_field( $data['original_post_status'] ) : $status; |
|
421 | - $number = sanitize_text_field( $data['wpinv_number'] ); |
|
422 | - $due_date = isset( $data['wpinv_due_date'] ) ? sanitize_text_field( $data['wpinv_due_date'] ) : ''; |
|
423 | - $date_created = isset( $data['date_created'] ) ? sanitize_text_field( $data['date_created'] ) : ''; |
|
419 | + $status = sanitize_text_field($data['wpinv_status']); |
|
420 | + $old_status = !empty($data['original_post_status']) ? sanitize_text_field($data['original_post_status']) : $status; |
|
421 | + $number = sanitize_text_field($data['wpinv_number']); |
|
422 | + $due_date = isset($data['wpinv_due_date']) ? sanitize_text_field($data['wpinv_due_date']) : ''; |
|
423 | + $date_created = isset($data['date_created']) ? sanitize_text_field($data['date_created']) : ''; |
|
424 | 424 | //$discounts = sanitize_text_field( $data['wpinv_discounts'] ); |
425 | 425 | //$discount = sanitize_text_field( $data['wpinv_discount'] ); |
426 | 426 | |
427 | 427 | $disable_taxes = 0; |
428 | 428 | |
429 | - if ( ! empty( $data['disable_taxes'] ) ) { |
|
429 | + if (!empty($data['disable_taxes'])) { |
|
430 | 430 | $disable_taxes = 1; |
431 | 431 | } |
432 | 432 | |
433 | - $ip = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip(); |
|
434 | - |
|
435 | - $invoice->set( 'due_date', $due_date ); |
|
436 | - $invoice->set( 'first_name', $first_name ); |
|
437 | - $invoice->set( 'last_name', $last_name ); |
|
438 | - $invoice->set( 'company', $company ); |
|
439 | - $invoice->set( 'vat_number', $vat_number ); |
|
440 | - $invoice->set( 'phone', $phone ); |
|
441 | - $invoice->set( 'address', $address ); |
|
442 | - $invoice->set( 'city', $city ); |
|
443 | - $invoice->set( 'zip', $zip ); |
|
444 | - $invoice->set( 'country', $country ); |
|
445 | - $invoice->set( 'state', $state ); |
|
446 | - $invoice->set( 'status', $status ); |
|
447 | - $invoice->set( 'set', $status ); |
|
433 | + $ip = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip(); |
|
434 | + |
|
435 | + $invoice->set('due_date', $due_date); |
|
436 | + $invoice->set('first_name', $first_name); |
|
437 | + $invoice->set('last_name', $last_name); |
|
438 | + $invoice->set('company', $company); |
|
439 | + $invoice->set('vat_number', $vat_number); |
|
440 | + $invoice->set('phone', $phone); |
|
441 | + $invoice->set('address', $address); |
|
442 | + $invoice->set('city', $city); |
|
443 | + $invoice->set('zip', $zip); |
|
444 | + $invoice->set('country', $country); |
|
445 | + $invoice->set('state', $state); |
|
446 | + $invoice->set('status', $status); |
|
447 | + $invoice->set('set', $status); |
|
448 | 448 | //$invoice->set( 'number', $number ); |
449 | 449 | //$invoice->set( 'discounts', $discounts ); |
450 | 450 | //$invoice->set( 'discount', $discount ); |
451 | - $invoice->set( 'disable_taxes', $disable_taxes ); |
|
452 | - $invoice->set( 'ip', $ip ); |
|
451 | + $invoice->set('disable_taxes', $disable_taxes); |
|
452 | + $invoice->set('ip', $ip); |
|
453 | 453 | $invoice->old_status = $_POST['original_post_status']; |
454 | 454 | |
455 | 455 | $currency = $invoice->get_currency(); |
456 | - if ( ! empty( $data['wpinv_currency'] ) ) { |
|
457 | - $currency = sanitize_text_field( $data['wpinv_currency'] ); |
|
456 | + if (!empty($data['wpinv_currency'])) { |
|
457 | + $currency = sanitize_text_field($data['wpinv_currency']); |
|
458 | 458 | } |
459 | 459 | |
460 | - if ( empty( $currency ) ) { |
|
460 | + if (empty($currency)) { |
|
461 | 461 | $currency = wpinv_get_currency(); |
462 | 462 | } |
463 | 463 | |
464 | - if ( ! $invoice->is_paid() ) { |
|
464 | + if (!$invoice->is_paid()) { |
|
465 | 465 | $invoice->currency = $currency; |
466 | 466 | } |
467 | 467 | |
468 | - if ( !empty( $data['wpinv_gateway'] ) ) { |
|
469 | - $invoice->set( 'gateway', sanitize_text_field( $data['wpinv_gateway'] ) ); |
|
468 | + if (!empty($data['wpinv_gateway'])) { |
|
469 | + $invoice->set('gateway', sanitize_text_field($data['wpinv_gateway'])); |
|
470 | 470 | } |
471 | 471 | $saved = $invoice->save(); |
472 | 472 | |
473 | - if ( ! empty( $date_created ) && strtotime( $date_created, current_time( 'timestamp' ) ) ) { |
|
473 | + if (!empty($date_created) && strtotime($date_created, current_time('timestamp'))) { |
|
474 | 474 | |
475 | - $time = strtotime( $date_created, current_time( 'timestamp' ) ); |
|
476 | - $date = date( 'Y-m-d H:i:s', $time ); |
|
477 | - $date_gmt = get_gmt_from_date( $date ); |
|
475 | + $time = strtotime($date_created, current_time('timestamp')); |
|
476 | + $date = date('Y-m-d H:i:s', $time); |
|
477 | + $date_gmt = get_gmt_from_date($date); |
|
478 | 478 | |
479 | 479 | wp_update_post( |
480 | 480 | array( |
@@ -489,37 +489,37 @@ discard block |
||
489 | 489 | } |
490 | 490 | |
491 | 491 | // Check for payment notes |
492 | - if ( !empty( $data['invoice_note'] ) ) { |
|
493 | - $note = wp_kses( $data['invoice_note'], array() ); |
|
494 | - $note_type = sanitize_text_field( $data['invoice_note_type'] ); |
|
492 | + if (!empty($data['invoice_note'])) { |
|
493 | + $note = wp_kses($data['invoice_note'], array()); |
|
494 | + $note_type = sanitize_text_field($data['invoice_note_type']); |
|
495 | 495 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
496 | 496 | |
497 | - wpinv_insert_payment_note( $invoice->ID, $note, $is_customer_note ); |
|
497 | + wpinv_insert_payment_note($invoice->ID, $note, $is_customer_note); |
|
498 | 498 | } |
499 | 499 | |
500 | 500 | // Update user address if empty. |
501 | - if ( $saved && !empty( $invoice ) ) { |
|
502 | - if ( $user_id = $invoice->get_user_id() ) { |
|
503 | - $user_address = wpinv_get_user_address( $user_id, false ); |
|
501 | + if ($saved && !empty($invoice)) { |
|
502 | + if ($user_id = $invoice->get_user_id()) { |
|
503 | + $user_address = wpinv_get_user_address($user_id, false); |
|
504 | 504 | |
505 | 505 | if (empty($user_address['first_name'])) { |
506 | - update_user_meta( $user_id, '_wpinv_first_name', $first_name ); |
|
507 | - update_user_meta( $user_id, '_wpinv_last_name', $last_name ); |
|
506 | + update_user_meta($user_id, '_wpinv_first_name', $first_name); |
|
507 | + update_user_meta($user_id, '_wpinv_last_name', $last_name); |
|
508 | 508 | } else if (empty($user_address['last_name']) && $user_address['first_name'] == $first_name) { |
509 | - update_user_meta( $user_id, '_wpinv_last_name', $last_name ); |
|
509 | + update_user_meta($user_id, '_wpinv_last_name', $last_name); |
|
510 | 510 | } |
511 | 511 | |
512 | 512 | if (empty($user_address['address']) || empty($user_address['city']) || empty($user_address['state']) || empty($user_address['country'])) { |
513 | - update_user_meta( $user_id, '_wpinv_address', $address ); |
|
514 | - update_user_meta( $user_id, '_wpinv_city', $city ); |
|
515 | - update_user_meta( $user_id, '_wpinv_state', $state ); |
|
516 | - update_user_meta( $user_id, '_wpinv_country', $country ); |
|
517 | - update_user_meta( $user_id, '_wpinv_zip', $zip ); |
|
518 | - update_user_meta( $user_id, '_wpinv_phone', $phone ); |
|
513 | + update_user_meta($user_id, '_wpinv_address', $address); |
|
514 | + update_user_meta($user_id, '_wpinv_city', $city); |
|
515 | + update_user_meta($user_id, '_wpinv_state', $state); |
|
516 | + update_user_meta($user_id, '_wpinv_country', $country); |
|
517 | + update_user_meta($user_id, '_wpinv_zip', $zip); |
|
518 | + update_user_meta($user_id, '_wpinv_phone', $phone); |
|
519 | 519 | } |
520 | 520 | } |
521 | 521 | |
522 | - do_action( 'wpinv_invoice_metabox_saved', $invoice ); |
|
522 | + do_action('wpinv_invoice_metabox_saved', $invoice); |
|
523 | 523 | } |
524 | 524 | |
525 | 525 | return $saved; |
@@ -7,41 +7,41 @@ 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 | -add_action( 'init', 'wpinv_register_post_types', 1 ); |
|
14 | +add_action('init', 'wpinv_register_post_types', 1); |
|
15 | 15 | function wpinv_register_post_types() { |
16 | 16 | |
17 | 17 | $items_labels = array( |
18 | - 'name' => _x( 'Items', 'post type general name', 'invoicing' ), |
|
19 | - 'singular_name' => _x( 'Item', 'post type singular name', 'invoicing' ), |
|
20 | - 'menu_name' => _x( 'Items', 'admin menu', 'invoicing' ), |
|
21 | - 'add_new' => _x( 'Add New', 'wpi_item', 'invoicing' ), |
|
22 | - 'add_new_item' => __( 'Add New Item', 'invoicing' ), |
|
23 | - 'new_item' => __( 'New Item', 'invoicing' ), |
|
24 | - 'edit_item' => __( 'Edit Item', 'invoicing' ), |
|
25 | - 'view_item' => __( 'View Item', 'invoicing' ), |
|
26 | - 'all_items' => __( 'Items', 'invoicing' ), |
|
27 | - 'search_items' => __( 'Search Items', 'invoicing' ), |
|
18 | + 'name' => _x('Items', 'post type general name', 'invoicing'), |
|
19 | + 'singular_name' => _x('Item', 'post type singular name', 'invoicing'), |
|
20 | + 'menu_name' => _x('Items', 'admin menu', 'invoicing'), |
|
21 | + 'add_new' => _x('Add New', 'wpi_item', 'invoicing'), |
|
22 | + 'add_new_item' => __('Add New Item', 'invoicing'), |
|
23 | + 'new_item' => __('New Item', 'invoicing'), |
|
24 | + 'edit_item' => __('Edit Item', 'invoicing'), |
|
25 | + 'view_item' => __('View Item', 'invoicing'), |
|
26 | + 'all_items' => __('Items', 'invoicing'), |
|
27 | + 'search_items' => __('Search Items', 'invoicing'), |
|
28 | 28 | 'parent_item_colon' => '', |
29 | - 'not_found' => __( 'No items found.', 'invoicing' ), |
|
30 | - 'not_found_in_trash' => __( 'No items found in trash.', 'invoicing' ) |
|
29 | + 'not_found' => __('No items found.', 'invoicing'), |
|
30 | + 'not_found_in_trash' => __('No items found in trash.', 'invoicing') |
|
31 | 31 | ); |
32 | - $items_labels = apply_filters( 'wpinv_items_labels', $items_labels ); |
|
32 | + $items_labels = apply_filters('wpinv_items_labels', $items_labels); |
|
33 | 33 | |
34 | 34 | $cap_type = 'wpi_item'; |
35 | 35 | $invoice_item_args = array( |
36 | 36 | 'labels' => $items_labels, |
37 | - 'description' => __( 'This is where you can add new invoice items.', 'invoicing' ), |
|
37 | + 'description' => __('This is where you can add new invoice items.', 'invoicing'), |
|
38 | 38 | 'public' => false, |
39 | 39 | 'has_archive' => false, |
40 | 40 | '_builtin' => false, |
41 | 41 | 'show_ui' => true, |
42 | 42 | 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false, |
43 | 43 | 'show_in_nav_menus' => false, |
44 | - 'supports' => array( 'title', 'excerpt' ), |
|
44 | + 'supports' => array('title', 'excerpt'), |
|
45 | 45 | 'register_meta_box_cb' => 'wpinv_register_item_meta_boxes', |
46 | 46 | 'rewrite' => false, |
47 | 47 | 'query_var' => false, |
@@ -68,9 +68,9 @@ discard block |
||
68 | 68 | ), |
69 | 69 | 'can_export' => true, |
70 | 70 | ); |
71 | - $invoice_item_args = apply_filters( 'wpinv_register_post_type_invoice_item', $invoice_item_args ); |
|
71 | + $invoice_item_args = apply_filters('wpinv_register_post_type_invoice_item', $invoice_item_args); |
|
72 | 72 | |
73 | - register_post_type( 'wpi_item', $invoice_item_args ); |
|
73 | + register_post_type('wpi_item', $invoice_item_args); |
|
74 | 74 | |
75 | 75 | $cap_type = 'wpi_payment_form'; |
76 | 76 | register_post_type( |
@@ -79,22 +79,22 @@ discard block |
||
79 | 79 | 'wpinv_register_post_type_payment_form', |
80 | 80 | array( |
81 | 81 | 'labels' => array( |
82 | - 'name' => _x( 'Payment Forms', 'post type general name', 'invoicing' ), |
|
83 | - 'singular_name' => _x( 'Payment Form', 'post type singular name', 'invoicing' ), |
|
84 | - 'menu_name' => _x( 'Payment Forms', 'admin menu', 'invoicing' ), |
|
85 | - 'name_admin_bar' => _x( 'Payment Form', 'add new on admin bar', 'invoicing' ), |
|
86 | - 'add_new' => _x( 'Add New', 'Payment Form', 'invoicing' ), |
|
87 | - 'add_new_item' => __( 'Add New Payment Form', 'invoicing' ), |
|
88 | - 'new_item' => __( 'New Payment Form', 'invoicing' ), |
|
89 | - 'edit_item' => __( 'Edit Payment Form', 'invoicing' ), |
|
90 | - 'view_item' => __( 'View Payment Form', 'invoicing' ), |
|
91 | - 'all_items' => __( 'Payment Forms', 'invoicing' ), |
|
92 | - 'search_items' => __( 'Search Payment Forms', 'invoicing' ), |
|
93 | - 'parent_item_colon' => __( 'Parent Payment Forms:', 'invoicing' ), |
|
94 | - 'not_found' => __( 'No payment forms found.', 'invoicing' ), |
|
95 | - 'not_found_in_trash' => __( 'No payment forms found in trash.', 'invoicing' ) |
|
82 | + 'name' => _x('Payment Forms', 'post type general name', 'invoicing'), |
|
83 | + 'singular_name' => _x('Payment Form', 'post type singular name', 'invoicing'), |
|
84 | + 'menu_name' => _x('Payment Forms', 'admin menu', 'invoicing'), |
|
85 | + 'name_admin_bar' => _x('Payment Form', 'add new on admin bar', 'invoicing'), |
|
86 | + 'add_new' => _x('Add New', 'Payment Form', 'invoicing'), |
|
87 | + 'add_new_item' => __('Add New Payment Form', 'invoicing'), |
|
88 | + 'new_item' => __('New Payment Form', 'invoicing'), |
|
89 | + 'edit_item' => __('Edit Payment Form', 'invoicing'), |
|
90 | + 'view_item' => __('View Payment Form', 'invoicing'), |
|
91 | + 'all_items' => __('Payment Forms', 'invoicing'), |
|
92 | + 'search_items' => __('Search Payment Forms', 'invoicing'), |
|
93 | + 'parent_item_colon' => __('Parent Payment Forms:', 'invoicing'), |
|
94 | + 'not_found' => __('No payment forms found.', 'invoicing'), |
|
95 | + 'not_found_in_trash' => __('No payment forms found in trash.', 'invoicing') |
|
96 | 96 | ), |
97 | - 'description' => __( 'Stores payment forms.', 'invoicing' ), |
|
97 | + 'description' => __('Stores payment forms.', 'invoicing'), |
|
98 | 98 | 'public' => false, |
99 | 99 | 'show_ui' => true, |
100 | 100 | 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : true, |
@@ -105,37 +105,37 @@ discard block |
||
105 | 105 | 'has_archive' => false, |
106 | 106 | 'hierarchical' => false, |
107 | 107 | 'menu_position' => null, |
108 | - 'supports' => array( 'title' ), |
|
108 | + 'supports' => array('title'), |
|
109 | 109 | 'menu_icon' => 'dashicons-media-form', |
110 | 110 | ) |
111 | 111 | ) |
112 | 112 | ); |
113 | 113 | |
114 | 114 | $labels = array( |
115 | - 'name' => _x( 'Invoices', 'post type general name', 'invoicing' ), |
|
116 | - 'singular_name' => _x( 'Invoice', 'post type singular name', 'invoicing' ), |
|
117 | - 'menu_name' => _x( 'Invoices', 'admin menu', 'invoicing' ), |
|
118 | - 'name_admin_bar' => _x( 'Invoice', 'add new on admin bar', 'invoicing' ), |
|
119 | - 'add_new' => _x( 'Add New', 'book', 'invoicing' ), |
|
120 | - 'add_new_item' => __( 'Add New Invoice', 'invoicing' ), |
|
121 | - 'new_item' => __( 'New Invoice', 'invoicing' ), |
|
122 | - 'edit_item' => __( 'Edit Invoice', 'invoicing' ), |
|
123 | - 'view_item' => __( 'View Invoice', 'invoicing' ), |
|
124 | - 'all_items' => __( 'Invoices', 'invoicing' ), |
|
125 | - 'search_items' => __( 'Search Invoices', 'invoicing' ), |
|
126 | - 'parent_item_colon' => __( 'Parent Invoices:', 'invoicing' ), |
|
127 | - 'not_found' => __( 'No invoices found.', 'invoicing' ), |
|
128 | - 'not_found_in_trash' => __( 'No invoices found in trash.', 'invoicing' ) |
|
115 | + 'name' => _x('Invoices', 'post type general name', 'invoicing'), |
|
116 | + 'singular_name' => _x('Invoice', 'post type singular name', 'invoicing'), |
|
117 | + 'menu_name' => _x('Invoices', 'admin menu', 'invoicing'), |
|
118 | + 'name_admin_bar' => _x('Invoice', 'add new on admin bar', 'invoicing'), |
|
119 | + 'add_new' => _x('Add New', 'book', 'invoicing'), |
|
120 | + 'add_new_item' => __('Add New Invoice', 'invoicing'), |
|
121 | + 'new_item' => __('New Invoice', 'invoicing'), |
|
122 | + 'edit_item' => __('Edit Invoice', 'invoicing'), |
|
123 | + 'view_item' => __('View Invoice', 'invoicing'), |
|
124 | + 'all_items' => __('Invoices', 'invoicing'), |
|
125 | + 'search_items' => __('Search Invoices', 'invoicing'), |
|
126 | + 'parent_item_colon' => __('Parent Invoices:', 'invoicing'), |
|
127 | + 'not_found' => __('No invoices found.', 'invoicing'), |
|
128 | + 'not_found_in_trash' => __('No invoices found in trash.', 'invoicing') |
|
129 | 129 | ); |
130 | - $labels = apply_filters( 'wpinv_labels', $labels ); |
|
130 | + $labels = apply_filters('wpinv_labels', $labels); |
|
131 | 131 | |
132 | 132 | $menu_icon = WPINV_PLUGIN_URL . '/assets/images/favicon.ico'; |
133 | - $menu_icon = apply_filters( 'wpinv_menu_icon_invoice', $menu_icon ); |
|
133 | + $menu_icon = apply_filters('wpinv_menu_icon_invoice', $menu_icon); |
|
134 | 134 | |
135 | 135 | $cap_type = 'wpi_invoice'; |
136 | 136 | $args = array( |
137 | 137 | 'labels' => $labels, |
138 | - 'description' => __( 'This is where invoices are stored.', 'invoicing' ), |
|
138 | + 'description' => __('This is where invoices are stored.', 'invoicing'), |
|
139 | 139 | 'public' => true, |
140 | 140 | 'can_export' => true, |
141 | 141 | '_builtin' => false, |
@@ -168,37 +168,37 @@ discard block |
||
168 | 168 | 'has_archive' => false, |
169 | 169 | 'hierarchical' => false, |
170 | 170 | 'menu_position' => null, |
171 | - 'supports' => array( 'title', 'author' ), |
|
171 | + 'supports' => array('title', 'author'), |
|
172 | 172 | 'menu_icon' => 'dashicons-media-spreadsheet', |
173 | 173 | ); |
174 | 174 | |
175 | - $args = apply_filters( 'wpinv_register_post_type_invoice', $args ); |
|
175 | + $args = apply_filters('wpinv_register_post_type_invoice', $args); |
|
176 | 176 | |
177 | - register_post_type( 'wpi_invoice', $args ); |
|
177 | + register_post_type('wpi_invoice', $args); |
|
178 | 178 | |
179 | 179 | $labels = array( |
180 | - 'name' => _x( 'Discounts', 'post type general name', 'invoicing' ), |
|
181 | - 'singular_name' => _x( 'Discount', 'post type singular name', 'invoicing' ), |
|
182 | - 'menu_name' => _x( 'Discounts', 'admin menu', 'invoicing' ), |
|
183 | - 'name_admin_bar' => _x( 'Discount', 'add new on admin bar', 'invoicing' ), |
|
184 | - 'add_new' => _x( 'Add New', 'book', 'invoicing' ), |
|
185 | - 'add_new_item' => __( 'Add New Discount', 'invoicing' ), |
|
186 | - 'new_item' => __( 'New Discount', 'invoicing' ), |
|
187 | - 'edit_item' => __( 'Edit Discount', 'invoicing' ), |
|
188 | - 'view_item' => __( 'View Discount', 'invoicing' ), |
|
189 | - 'all_items' => __( 'Discounts', 'invoicing' ), |
|
190 | - 'search_items' => __( 'Search Discounts', 'invoicing' ), |
|
191 | - 'parent_item_colon' => __( 'Parent Discounts:', 'invoicing' ), |
|
192 | - 'not_found' => __( 'No discounts found.', 'invoicing' ), |
|
193 | - 'not_found_in_trash' => __( 'No discounts found in trash.', 'invoicing' ) |
|
180 | + 'name' => _x('Discounts', 'post type general name', 'invoicing'), |
|
181 | + 'singular_name' => _x('Discount', 'post type singular name', 'invoicing'), |
|
182 | + 'menu_name' => _x('Discounts', 'admin menu', 'invoicing'), |
|
183 | + 'name_admin_bar' => _x('Discount', 'add new on admin bar', 'invoicing'), |
|
184 | + 'add_new' => _x('Add New', 'book', 'invoicing'), |
|
185 | + 'add_new_item' => __('Add New Discount', 'invoicing'), |
|
186 | + 'new_item' => __('New Discount', 'invoicing'), |
|
187 | + 'edit_item' => __('Edit Discount', 'invoicing'), |
|
188 | + 'view_item' => __('View Discount', 'invoicing'), |
|
189 | + 'all_items' => __('Discounts', 'invoicing'), |
|
190 | + 'search_items' => __('Search Discounts', 'invoicing'), |
|
191 | + 'parent_item_colon' => __('Parent Discounts:', 'invoicing'), |
|
192 | + 'not_found' => __('No discounts found.', 'invoicing'), |
|
193 | + 'not_found_in_trash' => __('No discounts found in trash.', 'invoicing') |
|
194 | 194 | ); |
195 | - $labels = apply_filters( 'wpinv_discounts_labels', $labels ); |
|
195 | + $labels = apply_filters('wpinv_discounts_labels', $labels); |
|
196 | 196 | |
197 | 197 | $cap_type = 'wpi_discount'; |
198 | 198 | |
199 | 199 | $args = array( |
200 | 200 | 'labels' => $labels, |
201 | - 'description' => __( 'This is where you can add new discounts that users can use in invoices.', 'invoicing' ), |
|
201 | + 'description' => __('This is where you can add new discounts that users can use in invoices.', 'invoicing'), |
|
202 | 202 | 'public' => false, |
203 | 203 | 'can_export' => true, |
204 | 204 | '_builtin' => false, |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | ), |
230 | 230 | 'has_archive' => false, |
231 | 231 | 'hierarchical' => false, |
232 | - 'supports' => array( 'title', 'excerpt' ), |
|
232 | + 'supports' => array('title', 'excerpt'), |
|
233 | 233 | 'register_meta_box_cb' => 'wpinv_register_discount_meta_boxes', |
234 | 234 | 'show_in_nav_menus' => false, |
235 | 235 | 'show_in_admin_bar' => true, |
@@ -237,106 +237,106 @@ discard block |
||
237 | 237 | 'menu_position' => null, |
238 | 238 | ); |
239 | 239 | |
240 | - $args = apply_filters( 'wpinv_register_post_type_discount', $args ); |
|
240 | + $args = apply_filters('wpinv_register_post_type_discount', $args); |
|
241 | 241 | |
242 | - register_post_type( 'wpi_discount', $args ); |
|
242 | + register_post_type('wpi_discount', $args); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | function wpinv_get_default_labels() { |
246 | 246 | $defaults = array( |
247 | - 'singular' => __( 'Invoice', 'invoicing' ), |
|
248 | - 'plural' => __( 'Invoices', 'invoicing' ) |
|
247 | + 'singular' => __('Invoice', 'invoicing'), |
|
248 | + 'plural' => __('Invoices', 'invoicing') |
|
249 | 249 | ); |
250 | 250 | |
251 | - return apply_filters( 'wpinv_default_invoices_name', $defaults ); |
|
251 | + return apply_filters('wpinv_default_invoices_name', $defaults); |
|
252 | 252 | } |
253 | 253 | |
254 | -function wpinv_get_label_singular( $lowercase = false ) { |
|
254 | +function wpinv_get_label_singular($lowercase = false) { |
|
255 | 255 | $defaults = wpinv_get_default_labels(); |
256 | 256 | |
257 | - return ($lowercase) ? strtolower( $defaults['singular'] ) : $defaults['singular']; |
|
257 | + return ($lowercase) ? strtolower($defaults['singular']) : $defaults['singular']; |
|
258 | 258 | } |
259 | 259 | |
260 | -function wpinv_get_label_plural( $lowercase = false ) { |
|
260 | +function wpinv_get_label_plural($lowercase = false) { |
|
261 | 261 | $defaults = wpinv_get_default_labels(); |
262 | 262 | |
263 | - return ( $lowercase ) ? strtolower( $defaults['plural'] ) : $defaults['plural']; |
|
263 | + return ($lowercase) ? strtolower($defaults['plural']) : $defaults['plural']; |
|
264 | 264 | } |
265 | 265 | |
266 | -function wpinv_change_default_title( $title ) { |
|
267 | - if ( !is_admin() ) { |
|
266 | +function wpinv_change_default_title($title) { |
|
267 | + if (!is_admin()) { |
|
268 | 268 | $label = wpinv_get_label_singular(); |
269 | - $title = sprintf( __( 'Enter %s name here', 'invoicing' ), $label ); |
|
269 | + $title = sprintf(__('Enter %s name here', 'invoicing'), $label); |
|
270 | 270 | return $title; |
271 | 271 | } |
272 | 272 | |
273 | 273 | $screen = get_current_screen(); |
274 | 274 | |
275 | - if ( 'wpi_invoice' == $screen->post_type ) { |
|
275 | + if ('wpi_invoice' == $screen->post_type) { |
|
276 | 276 | $label = wpinv_get_label_singular(); |
277 | - $title = sprintf( __( 'Enter %s name here', 'invoicing' ), $label ); |
|
277 | + $title = sprintf(__('Enter %s name here', 'invoicing'), $label); |
|
278 | 278 | } |
279 | 279 | |
280 | 280 | return $title; |
281 | 281 | } |
282 | -add_filter( 'enter_title_here', 'wpinv_change_default_title' ); |
|
282 | +add_filter('enter_title_here', 'wpinv_change_default_title'); |
|
283 | 283 | |
284 | 284 | function wpinv_register_post_status() { |
285 | - register_post_status( 'wpi-pending', array( |
|
286 | - 'label' => _x( 'Pending', 'Invoice status', 'invoicing' ), |
|
285 | + register_post_status('wpi-pending', array( |
|
286 | + 'label' => _x('Pending', 'Invoice status', 'invoicing'), |
|
287 | 287 | 'public' => true, |
288 | 288 | 'exclude_from_search' => true, |
289 | 289 | 'show_in_admin_all_list' => true, |
290 | 290 | 'show_in_admin_status_list' => true, |
291 | - 'label_count' => _n_noop( 'Pending <span class="count">(%s)</span>', 'Pending <span class="count">(%s)</span>', 'invoicing' ) |
|
292 | - ) ); |
|
293 | - register_post_status( 'wpi-processing', array( |
|
294 | - 'label' => _x( 'Processing', 'Invoice status', 'invoicing' ), |
|
291 | + 'label_count' => _n_noop('Pending <span class="count">(%s)</span>', 'Pending <span class="count">(%s)</span>', 'invoicing') |
|
292 | + )); |
|
293 | + register_post_status('wpi-processing', array( |
|
294 | + 'label' => _x('Processing', 'Invoice status', 'invoicing'), |
|
295 | 295 | 'public' => true, |
296 | 296 | 'exclude_from_search' => true, |
297 | 297 | 'show_in_admin_all_list' => true, |
298 | 298 | 'show_in_admin_status_list' => true, |
299 | - 'label_count' => _n_noop( 'Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing' ) |
|
300 | - ) ); |
|
301 | - register_post_status( 'wpi-onhold', array( |
|
302 | - 'label' => _x( 'On Hold', 'Invoice status', 'invoicing' ), |
|
299 | + 'label_count' => _n_noop('Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing') |
|
300 | + )); |
|
301 | + register_post_status('wpi-onhold', array( |
|
302 | + 'label' => _x('On Hold', 'Invoice status', 'invoicing'), |
|
303 | 303 | 'public' => true, |
304 | 304 | 'exclude_from_search' => true, |
305 | 305 | 'show_in_admin_all_list' => true, |
306 | 306 | 'show_in_admin_status_list' => true, |
307 | - 'label_count' => _n_noop( 'On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing' ) |
|
308 | - ) ); |
|
309 | - register_post_status( 'wpi-cancelled', array( |
|
310 | - 'label' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
307 | + 'label_count' => _n_noop('On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing') |
|
308 | + )); |
|
309 | + register_post_status('wpi-cancelled', array( |
|
310 | + 'label' => _x('Cancelled', 'Invoice status', 'invoicing'), |
|
311 | 311 | 'public' => true, |
312 | 312 | 'exclude_from_search' => true, |
313 | 313 | 'show_in_admin_all_list' => true, |
314 | 314 | 'show_in_admin_status_list' => true, |
315 | - 'label_count' => _n_noop( 'Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing' ) |
|
316 | - ) ); |
|
317 | - register_post_status( 'wpi-refunded', array( |
|
318 | - 'label' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
315 | + 'label_count' => _n_noop('Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing') |
|
316 | + )); |
|
317 | + register_post_status('wpi-refunded', array( |
|
318 | + 'label' => _x('Refunded', 'Invoice status', 'invoicing'), |
|
319 | 319 | 'public' => true, |
320 | 320 | 'exclude_from_search' => true, |
321 | 321 | 'show_in_admin_all_list' => true, |
322 | 322 | 'show_in_admin_status_list' => true, |
323 | - 'label_count' => _n_noop( 'Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing' ) |
|
324 | - ) ); |
|
325 | - register_post_status( 'wpi-failed', array( |
|
326 | - 'label' => _x( 'Failed', 'Invoice status', 'invoicing' ), |
|
323 | + 'label_count' => _n_noop('Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing') |
|
324 | + )); |
|
325 | + register_post_status('wpi-failed', array( |
|
326 | + 'label' => _x('Failed', 'Invoice status', 'invoicing'), |
|
327 | 327 | 'public' => true, |
328 | 328 | 'exclude_from_search' => true, |
329 | 329 | 'show_in_admin_all_list' => true, |
330 | 330 | 'show_in_admin_status_list' => true, |
331 | - 'label_count' => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing' ) |
|
332 | - ) ); |
|
333 | - register_post_status( 'wpi-renewal', array( |
|
334 | - 'label' => _x( 'Renewal', 'Invoice status', 'invoicing' ), |
|
331 | + 'label_count' => _n_noop('Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing') |
|
332 | + )); |
|
333 | + register_post_status('wpi-renewal', array( |
|
334 | + 'label' => _x('Renewal', 'Invoice status', 'invoicing'), |
|
335 | 335 | 'public' => true, |
336 | 336 | 'exclude_from_search' => true, |
337 | 337 | 'show_in_admin_all_list' => true, |
338 | 338 | 'show_in_admin_status_list' => true, |
339 | - 'label_count' => _n_noop( 'Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing' ) |
|
340 | - ) ); |
|
339 | + 'label_count' => _n_noop('Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing') |
|
340 | + )); |
|
341 | 341 | } |
342 | -add_action( 'init', 'wpinv_register_post_status', 10 ); |
|
342 | +add_action('init', 'wpinv_register_post_status', 10); |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Setup menus in WP admin. |
4 | 4 | */ |
5 | 5 | |
6 | -defined( 'ABSPATH' ) || exit; |
|
6 | +defined('ABSPATH') || exit; |
|
7 | 7 | |
8 | 8 | /** |
9 | 9 | * WC_Admin_Menus Class. |
@@ -13,35 +13,35 @@ discard block |
||
13 | 13 | * Hook in tabs. |
14 | 14 | */ |
15 | 15 | public function __construct() { |
16 | - add_action( 'admin_menu', array( $this, 'admin_menu' ), 10 ); |
|
17 | - add_action( 'admin_menu', array( $this, 'add_addons_menu' ), 100 ); |
|
18 | - add_action( 'admin_menu', array( $this, 'add_settings_menu' ), 60 ); |
|
19 | - add_action( 'admin_menu', array( $this, 'remove_admin_submenus' ), 10 ); |
|
20 | - add_action( 'admin_head-nav-menus.php', array( $this, 'add_nav_menu_meta_boxes' ) ); |
|
16 | + add_action('admin_menu', array($this, 'admin_menu'), 10); |
|
17 | + add_action('admin_menu', array($this, 'add_addons_menu'), 100); |
|
18 | + add_action('admin_menu', array($this, 'add_settings_menu'), 60); |
|
19 | + add_action('admin_menu', array($this, 'remove_admin_submenus'), 10); |
|
20 | + add_action('admin_head-nav-menus.php', array($this, 'add_nav_menu_meta_boxes')); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | public function admin_menu() { |
24 | 24 | global $menu, $submenu; |
25 | 25 | |
26 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
26 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
27 | 27 | return; |
28 | 28 | } |
29 | 29 | |
30 | - $capability = apply_filters( 'invoicing_capability', wpinv_get_capability() ); |
|
30 | + $capability = apply_filters('invoicing_capability', wpinv_get_capability()); |
|
31 | 31 | |
32 | - if ( wpinv_current_user_can_manage_invoicing() ) { |
|
33 | - $menu[] = array( '', 'read', 'separator-wpinv', '', 'wp-menu-separator wpinv' ); |
|
32 | + if (wpinv_current_user_can_manage_invoicing()) { |
|
33 | + $menu[] = array('', 'read', 'separator-wpinv', '', 'wp-menu-separator wpinv'); |
|
34 | 34 | |
35 | 35 | // Allow users with 'manage_invocing' capability to create new invoices |
36 | - $submenu['post-new.php?post_type=wpi_item'][] = array( '', '', 'post-new.php?post_type=wpi_item', '' ); |
|
37 | - $submenu['post-new.php?post_type=wpi_invoice'][] = array( '', '', 'post-new.php?post_type=wpi_invoice', '' ); |
|
38 | - $submenu['post-new.php?post_type=wpi_discount'][] = array( '', '', 'post-new.php?post_type=wpi_discount', '' ); |
|
36 | + $submenu['post-new.php?post_type=wpi_item'][] = array('', '', 'post-new.php?post_type=wpi_item', ''); |
|
37 | + $submenu['post-new.php?post_type=wpi_invoice'][] = array('', '', 'post-new.php?post_type=wpi_invoice', ''); |
|
38 | + $submenu['post-new.php?post_type=wpi_discount'][] = array('', '', 'post-new.php?post_type=wpi_discount', ''); |
|
39 | 39 | |
40 | 40 | } |
41 | 41 | |
42 | - $wpi_invoice = get_post_type_object( 'wpi_invoice' ); |
|
42 | + $wpi_invoice = get_post_type_object('wpi_invoice'); |
|
43 | 43 | |
44 | - add_menu_page( __( 'Invoicing', 'invoicing' ), __( 'Invoicing', 'invoicing' ), $capability, 'wpinv', null, $wpi_invoice->menu_icon, '54.123460' ); |
|
44 | + add_menu_page(__('Invoicing', 'invoicing'), __('Invoicing', 'invoicing'), $capability, 'wpinv', null, $wpi_invoice->menu_icon, '54.123460'); |
|
45 | 45 | |
46 | 46 | } |
47 | 47 | |
@@ -51,16 +51,16 @@ discard block |
||
51 | 51 | public function add_settings_menu() { |
52 | 52 | add_submenu_page( |
53 | 53 | 'wpinv', |
54 | - __( 'Invoice Settings', 'invoicing' ), |
|
55 | - __( 'Settings', 'invoicing' ), |
|
56 | - apply_filters( 'invoicing_capability', wpinv_get_capability() ), |
|
54 | + __('Invoice Settings', 'invoicing'), |
|
55 | + __('Settings', 'invoicing'), |
|
56 | + apply_filters('invoicing_capability', wpinv_get_capability()), |
|
57 | 57 | 'wpinv-settings', |
58 | - array( $this, 'options_page' ) |
|
58 | + array($this, 'options_page') |
|
59 | 59 | ); |
60 | 60 | } |
61 | 61 | |
62 | - public function add_addons_menu(){ |
|
63 | - if ( !apply_filters( 'wpi_show_addons_page', true ) ) { |
|
62 | + public function add_addons_menu() { |
|
63 | + if (!apply_filters('wpi_show_addons_page', true)) { |
|
64 | 64 | return; |
65 | 65 | } |
66 | 66 | |
@@ -70,78 +70,78 @@ discard block |
||
70 | 70 | __('Extensions', 'invoicing'), |
71 | 71 | 'manage_options', |
72 | 72 | 'wpi-addons', |
73 | - array( $this, 'addons_page' ) |
|
73 | + array($this, 'addons_page') |
|
74 | 74 | ); |
75 | 75 | } |
76 | 76 | |
77 | - public function addons_page(){ |
|
77 | + public function addons_page() { |
|
78 | 78 | $addon_obj = new WPInv_Admin_Addons(); |
79 | 79 | $addon_obj->output(); |
80 | 80 | } |
81 | 81 | |
82 | 82 | function options_page() { |
83 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false; |
|
83 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : false; |
|
84 | 84 | |
85 | - if ( $page !== 'wpinv-settings' ) { |
|
85 | + if ($page !== 'wpinv-settings') { |
|
86 | 86 | return; |
87 | 87 | } |
88 | 88 | |
89 | 89 | $settings_tabs = wpinv_get_settings_tabs(); |
90 | 90 | $settings_tabs = empty($settings_tabs) ? array() : $settings_tabs; |
91 | - $active_tab = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $settings_tabs ) ? sanitize_text_field( $_GET['tab'] ) : 'general'; |
|
92 | - $sections = wpinv_get_settings_tab_sections( $active_tab ); |
|
91 | + $active_tab = isset($_GET['tab']) && array_key_exists($_GET['tab'], $settings_tabs) ? sanitize_text_field($_GET['tab']) : 'general'; |
|
92 | + $sections = wpinv_get_settings_tab_sections($active_tab); |
|
93 | 93 | $key = 'main'; |
94 | 94 | |
95 | - if ( is_array( $sections ) ) { |
|
96 | - $key = key( $sections ); |
|
95 | + if (is_array($sections)) { |
|
96 | + $key = key($sections); |
|
97 | 97 | } |
98 | 98 | |
99 | - $registered_sections = wpinv_get_settings_tab_sections( $active_tab ); |
|
100 | - $section = isset( $_GET['section'] ) && ! empty( $registered_sections ) && array_key_exists( $_GET['section'], $registered_sections ) ? $_GET['section'] : $key; |
|
99 | + $registered_sections = wpinv_get_settings_tab_sections($active_tab); |
|
100 | + $section = isset($_GET['section']) && !empty($registered_sections) && array_key_exists($_GET['section'], $registered_sections) ? $_GET['section'] : $key; |
|
101 | 101 | ob_start(); |
102 | 102 | ?> |
103 | 103 | <div class="wrap"> |
104 | 104 | <h1 class="nav-tab-wrapper"> |
105 | 105 | <?php |
106 | - foreach( wpinv_get_settings_tabs() as $tab_id => $tab_name ) { |
|
107 | - $tab_url = add_query_arg( array( |
|
106 | + foreach (wpinv_get_settings_tabs() as $tab_id => $tab_name) { |
|
107 | + $tab_url = add_query_arg(array( |
|
108 | 108 | 'settings-updated' => false, |
109 | 109 | 'tab' => $tab_id, |
110 | - ) ); |
|
110 | + )); |
|
111 | 111 | |
112 | 112 | // Remove the section from the tabs so we always end up at the main section |
113 | - $tab_url = remove_query_arg( 'section', $tab_url ); |
|
114 | - $tab_url = remove_query_arg( 'wpi_sub', $tab_url ); |
|
113 | + $tab_url = remove_query_arg('section', $tab_url); |
|
114 | + $tab_url = remove_query_arg('wpi_sub', $tab_url); |
|
115 | 115 | |
116 | 116 | $active = $active_tab == $tab_id ? ' nav-tab-active' : ''; |
117 | 117 | |
118 | - echo '<a href="' . esc_url( $tab_url ) . '" title="' . esc_attr( $tab_name ) . '" class="nav-tab' . $active . '">'; |
|
119 | - echo esc_html( $tab_name ); |
|
118 | + echo '<a href="' . esc_url($tab_url) . '" title="' . esc_attr($tab_name) . '" class="nav-tab' . $active . '">'; |
|
119 | + echo esc_html($tab_name); |
|
120 | 120 | echo '</a>'; |
121 | 121 | } |
122 | 122 | ?> |
123 | 123 | </h1> |
124 | 124 | <?php |
125 | - $number_of_sections = count( $sections ); |
|
125 | + $number_of_sections = count($sections); |
|
126 | 126 | $number = 0; |
127 | - if ( $number_of_sections > 1 ) { |
|
127 | + if ($number_of_sections > 1) { |
|
128 | 128 | echo '<div><ul class="subsubsub">'; |
129 | - foreach( $sections as $section_id => $section_name ) { |
|
129 | + foreach ($sections as $section_id => $section_name) { |
|
130 | 130 | echo '<li>'; |
131 | 131 | $number++; |
132 | - $tab_url = add_query_arg( array( |
|
132 | + $tab_url = add_query_arg(array( |
|
133 | 133 | 'settings-updated' => false, |
134 | 134 | 'tab' => $active_tab, |
135 | 135 | 'section' => $section_id |
136 | - ) ); |
|
137 | - $tab_url = remove_query_arg( 'wpi_sub', $tab_url ); |
|
136 | + )); |
|
137 | + $tab_url = remove_query_arg('wpi_sub', $tab_url); |
|
138 | 138 | $class = ''; |
139 | - if ( $section == $section_id ) { |
|
139 | + if ($section == $section_id) { |
|
140 | 140 | $class = 'current'; |
141 | 141 | } |
142 | - echo '<a class="' . $class . '" href="' . esc_url( $tab_url ) . '">' . $section_name . '</a>'; |
|
142 | + echo '<a class="' . $class . '" href="' . esc_url($tab_url) . '">' . $section_name . '</a>'; |
|
143 | 143 | |
144 | - if ( $number != $number_of_sections ) { |
|
144 | + if ($number != $number_of_sections) { |
|
145 | 145 | echo ' | '; |
146 | 146 | } |
147 | 147 | echo '</li>'; |
@@ -153,19 +153,19 @@ discard block |
||
153 | 153 | <form method="post" action="options.php"> |
154 | 154 | <table class="form-table"> |
155 | 155 | <?php |
156 | - settings_fields( 'wpinv_settings' ); |
|
156 | + settings_fields('wpinv_settings'); |
|
157 | 157 | |
158 | - if ( 'main' === $section ) { |
|
159 | - do_action( 'wpinv_settings_tab_top', $active_tab ); |
|
158 | + if ('main' === $section) { |
|
159 | + do_action('wpinv_settings_tab_top', $active_tab); |
|
160 | 160 | } |
161 | 161 | |
162 | - do_action( 'wpinv_settings_tab_top_' . $active_tab . '_' . $section, $active_tab, $section ); |
|
163 | - do_settings_sections( 'wpinv_settings_' . $active_tab . '_' . $section, $active_tab, $section ); |
|
164 | - do_action( 'wpinv_settings_tab_bottom_' . $active_tab . '_' . $section, $active_tab, $section ); |
|
162 | + do_action('wpinv_settings_tab_top_' . $active_tab . '_' . $section, $active_tab, $section); |
|
163 | + do_settings_sections('wpinv_settings_' . $active_tab . '_' . $section, $active_tab, $section); |
|
164 | + do_action('wpinv_settings_tab_bottom_' . $active_tab . '_' . $section, $active_tab, $section); |
|
165 | 165 | |
166 | 166 | // For backwards compatibility |
167 | - if ( 'main' === $section ) { |
|
168 | - do_action( 'wpinv_settings_tab_bottom', $active_tab ); |
|
167 | + if ('main' === $section) { |
|
168 | + do_action('wpinv_settings_tab_bottom', $active_tab); |
|
169 | 169 | } |
170 | 170 | ?> |
171 | 171 | </table> |
@@ -179,18 +179,18 @@ discard block |
||
179 | 179 | } |
180 | 180 | |
181 | 181 | public function remove_admin_submenus() { |
182 | - remove_submenu_page( 'edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice' ); |
|
182 | + remove_submenu_page('edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice'); |
|
183 | 183 | } |
184 | 184 | |
185 | - public function add_nav_menu_meta_boxes(){ |
|
186 | - add_meta_box( 'wpinv_endpoints_nav_link', __( 'Invoicing Pages', 'invoicing' ), array( $this, 'nav_menu_links' ), 'nav-menus', 'side', 'low' ); |
|
185 | + public function add_nav_menu_meta_boxes() { |
|
186 | + add_meta_box('wpinv_endpoints_nav_link', __('Invoicing Pages', 'invoicing'), array($this, 'nav_menu_links'), 'nav-menus', 'side', 'low'); |
|
187 | 187 | } |
188 | 188 | |
189 | - public function nav_menu_links(){ |
|
189 | + public function nav_menu_links() { |
|
190 | 190 | $endpoints = $this->get_menu_items(); |
191 | 191 | ?> |
192 | 192 | <div id="invoicing-endpoints" class="posttypediv"> |
193 | - <?php if(!empty($endpoints['pages'])){ ?> |
|
193 | + <?php if (!empty($endpoints['pages'])) { ?> |
|
194 | 194 | <div id="tabs-panel-invoicing-endpoints" class="tabs-panel tabs-panel-active"> |
195 | 195 | <ul id="invoicing-endpoints-checklist" class="categorychecklist form-no-clear"> |
196 | 196 | <?php |
@@ -202,29 +202,29 @@ discard block |
||
202 | 202 | <?php } ?> |
203 | 203 | <p class="button-controls"> |
204 | 204 | <span class="list-controls"> |
205 | - <a href="<?php echo admin_url( 'nav-menus.php?page-tab=all&selectall=1#invoicing-endpoints' ); ?>" class="select-all"><?php _e( 'Select all', 'invoicing' ); ?></a> |
|
205 | + <a href="<?php echo admin_url('nav-menus.php?page-tab=all&selectall=1#invoicing-endpoints'); ?>" class="select-all"><?php _e('Select all', 'invoicing'); ?></a> |
|
206 | 206 | </span> |
207 | 207 | <span class="add-to-menu"> |
208 | - <input type="submit" class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( 'Add to menu', 'invoicing' ); ?>" name="add-post-type-menu-item" id="submit-invoicing-endpoints"> |
|
208 | + <input type="submit" class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e('Add to menu', 'invoicing'); ?>" name="add-post-type-menu-item" id="submit-invoicing-endpoints"> |
|
209 | 209 | <span class="spinner"></span> |
210 | 210 | </span> |
211 | 211 | </p> |
212 | 212 | <?php |
213 | 213 | } |
214 | 214 | |
215 | - public function get_menu_items(){ |
|
215 | + public function get_menu_items() { |
|
216 | 216 | $items = array(); |
217 | 217 | |
218 | - $wpinv_history_page_id = (int)wpinv_get_option( 'invoice_history_page' ); |
|
219 | - if($wpinv_history_page_id > 0){ |
|
218 | + $wpinv_history_page_id = (int) wpinv_get_option('invoice_history_page'); |
|
219 | + if ($wpinv_history_page_id > 0) { |
|
220 | 220 | $item = new stdClass(); |
221 | 221 | $item->object_id = $wpinv_history_page_id; |
222 | 222 | $item->db_id = 0; |
223 | - $item->object = 'page'; |
|
223 | + $item->object = 'page'; |
|
224 | 224 | $item->menu_item_parent = 0; |
225 | 225 | $item->type = 'post_type'; |
226 | - $item->title = __('Invoice History Page','invoicing'); |
|
227 | - $item->url = get_permalink( $wpinv_history_page_id ); |
|
226 | + $item->title = __('Invoice History Page', 'invoicing'); |
|
227 | + $item->url = get_permalink($wpinv_history_page_id); |
|
228 | 228 | $item->target = ''; |
229 | 229 | $item->attr_title = ''; |
230 | 230 | $item->classes = array('wpinv-menu-item'); |
@@ -233,16 +233,16 @@ discard block |
||
233 | 233 | $items['pages'][] = $item; |
234 | 234 | } |
235 | 235 | |
236 | - $wpinv_sub_history_page_id = (int)wpinv_get_option( 'invoice_subscription_page' ); |
|
237 | - if($wpinv_sub_history_page_id > 0){ |
|
236 | + $wpinv_sub_history_page_id = (int) wpinv_get_option('invoice_subscription_page'); |
|
237 | + if ($wpinv_sub_history_page_id > 0) { |
|
238 | 238 | $item = new stdClass(); |
239 | 239 | $item->object_id = $wpinv_sub_history_page_id; |
240 | 240 | $item->db_id = 0; |
241 | - $item->object = 'page'; |
|
241 | + $item->object = 'page'; |
|
242 | 242 | $item->menu_item_parent = 0; |
243 | 243 | $item->type = 'post_type'; |
244 | - $item->title = __('Invoice Subscriptions Page','invoicing'); |
|
245 | - $item->url = get_permalink( $wpinv_sub_history_page_id ); |
|
244 | + $item->title = __('Invoice Subscriptions Page', 'invoicing'); |
|
245 | + $item->url = get_permalink($wpinv_sub_history_page_id); |
|
246 | 246 | $item->target = ''; |
247 | 247 | $item->attr_title = ''; |
248 | 248 | $item->classes = array('wpinv-menu-item'); |
@@ -251,16 +251,16 @@ discard block |
||
251 | 251 | $items['pages'][] = $item; |
252 | 252 | } |
253 | 253 | |
254 | - $wpinv_checkout_page_id = (int)wpinv_get_option( 'checkout_page' ); |
|
255 | - if($wpinv_checkout_page_id > 0){ |
|
254 | + $wpinv_checkout_page_id = (int) wpinv_get_option('checkout_page'); |
|
255 | + if ($wpinv_checkout_page_id > 0) { |
|
256 | 256 | $item = new stdClass(); |
257 | 257 | $item->object_id = $wpinv_checkout_page_id; |
258 | 258 | $item->db_id = 0; |
259 | - $item->object = 'page'; |
|
259 | + $item->object = 'page'; |
|
260 | 260 | $item->menu_item_parent = 0; |
261 | 261 | $item->type = 'post_type'; |
262 | - $item->title = __('Checkout Page','invoicing'); |
|
263 | - $item->url = get_permalink( $wpinv_checkout_page_id ); |
|
262 | + $item->title = __('Checkout Page', 'invoicing'); |
|
263 | + $item->url = get_permalink($wpinv_checkout_page_id); |
|
264 | 264 | $item->target = ''; |
265 | 265 | $item->attr_title = ''; |
266 | 266 | $item->classes = array('wpinv-menu-item'); |
@@ -269,16 +269,16 @@ discard block |
||
269 | 269 | $items['pages'][] = $item; |
270 | 270 | } |
271 | 271 | |
272 | - $wpinv_tandc_page_id = (int)wpinv_get_option( 'tandc_page' ); |
|
273 | - if($wpinv_tandc_page_id > 0){ |
|
272 | + $wpinv_tandc_page_id = (int) wpinv_get_option('tandc_page'); |
|
273 | + if ($wpinv_tandc_page_id > 0) { |
|
274 | 274 | $item = new stdClass(); |
275 | 275 | $item->object_id = $wpinv_tandc_page_id; |
276 | 276 | $item->db_id = 0; |
277 | - $item->object = 'page'; |
|
277 | + $item->object = 'page'; |
|
278 | 278 | $item->menu_item_parent = 0; |
279 | 279 | $item->type = 'post_type'; |
280 | - $item->title = __('Terms & Conditions','invoicing'); |
|
281 | - $item->url = get_permalink( $wpinv_tandc_page_id ); |
|
280 | + $item->title = __('Terms & Conditions', 'invoicing'); |
|
281 | + $item->url = get_permalink($wpinv_tandc_page_id); |
|
282 | 282 | $item->target = ''; |
283 | 283 | $item->attr_title = ''; |
284 | 284 | $item->classes = array('wpinv-menu-item'); |
@@ -287,16 +287,16 @@ discard block |
||
287 | 287 | $items['pages'][] = $item; |
288 | 288 | } |
289 | 289 | |
290 | - $wpinv_success_page_id = (int)wpinv_get_option( 'success_page' ); |
|
291 | - if($wpinv_success_page_id > 0){ |
|
290 | + $wpinv_success_page_id = (int) wpinv_get_option('success_page'); |
|
291 | + if ($wpinv_success_page_id > 0) { |
|
292 | 292 | $item = new stdClass(); |
293 | 293 | $item->object_id = $wpinv_success_page_id; |
294 | 294 | $item->db_id = 0; |
295 | - $item->object = 'page'; |
|
295 | + $item->object = 'page'; |
|
296 | 296 | $item->menu_item_parent = 0; |
297 | 297 | $item->type = 'post_type'; |
298 | - $item->title = __('Success Page','invoicing'); |
|
299 | - $item->url = get_permalink( $wpinv_success_page_id ); |
|
298 | + $item->title = __('Success Page', 'invoicing'); |
|
299 | + $item->url = get_permalink($wpinv_success_page_id); |
|
300 | 300 | $item->target = ''; |
301 | 301 | $item->attr_title = ''; |
302 | 302 | $item->classes = array('wpinv-menu-item'); |
@@ -305,16 +305,16 @@ discard block |
||
305 | 305 | $items['pages'][] = $item; |
306 | 306 | } |
307 | 307 | |
308 | - $wpinv_failure_page_id = (int)wpinv_get_option( 'failure_page' ); |
|
309 | - if($wpinv_failure_page_id > 0){ |
|
308 | + $wpinv_failure_page_id = (int) wpinv_get_option('failure_page'); |
|
309 | + if ($wpinv_failure_page_id > 0) { |
|
310 | 310 | $item = new stdClass(); |
311 | 311 | $item->object_id = $wpinv_failure_page_id; |
312 | 312 | $item->db_id = 0; |
313 | - $item->object = 'page'; |
|
313 | + $item->object = 'page'; |
|
314 | 314 | $item->menu_item_parent = 0; |
315 | 315 | $item->type = 'post_type'; |
316 | - $item->title = __('Failed Transaction Page','invoicing'); |
|
317 | - $item->url = get_permalink( $wpinv_failure_page_id ); |
|
316 | + $item->title = __('Failed Transaction Page', 'invoicing'); |
|
317 | + $item->url = get_permalink($wpinv_failure_page_id); |
|
318 | 318 | $item->target = ''; |
319 | 319 | $item->attr_title = ''; |
320 | 320 | $item->classes = array('wpinv-menu-item'); |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | $items['pages'][] = $item; |
324 | 324 | } |
325 | 325 | |
326 | - return apply_filters( 'wpinv_menu_items', $items ); |
|
326 | + return apply_filters('wpinv_menu_items', $items); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | } |
@@ -1,11 +1,11 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly. |
3 | -if (!defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | 5 | function wpinv_subscription_init() { |
6 | 6 | return WPInv_Subscriptions::instance(); |
7 | 7 | } |
8 | -add_action( 'plugins_loaded', 'wpinv_subscription_init', 100 ); |
|
8 | +add_action('plugins_loaded', 'wpinv_subscription_init', 100); |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * WPInv_Subscriptions Class. |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | * Main WPInv_Subscriptions Instance |
21 | 21 | */ |
22 | 22 | public static function instance() { |
23 | - if ( ! isset( self::$instance ) ) { |
|
23 | + if (!isset(self::$instance)) { |
|
24 | 24 | self::$instance = new WPInv_Subscriptions; |
25 | 25 | |
26 | 26 | self::$instance->init(); |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * |
35 | 35 | * @since 1.0.0 |
36 | 36 | */ |
37 | - private function __construct(){ |
|
37 | + private function __construct() { |
|
38 | 38 | |
39 | 39 | } |
40 | 40 | |
@@ -63,8 +63,8 @@ discard block |
||
63 | 63 | private function setup_constants() { |
64 | 64 | |
65 | 65 | // Make sure CAL_GREGORIAN is defined. |
66 | - if ( ! defined( 'CAL_GREGORIAN' ) ) { |
|
67 | - define( 'CAL_GREGORIAN', 1 ); |
|
66 | + if (!defined('CAL_GREGORIAN')) { |
|
67 | + define('CAL_GREGORIAN', 1); |
|
68 | 68 | } |
69 | 69 | } |
70 | 70 | |
@@ -76,13 +76,13 @@ discard block |
||
76 | 76 | */ |
77 | 77 | private function actions() { |
78 | 78 | |
79 | - add_action( 'admin_menu', array( $this, 'wpinv_subscriptions_list' ), 40 ); |
|
80 | - add_action( 'admin_notices', array( $this, 'notices' ) ); |
|
81 | - add_action( 'init', array( $this, 'wpinv_post_actions' ) ); |
|
82 | - add_action( 'init', array( $this, 'wpinv_get_actions' ) ); |
|
83 | - add_action( 'wpinv_cancel_subscription', array( $this, 'wpinv_process_cancellation' ) ); |
|
84 | - add_action( 'wpinv_checkout_before_send_to_gateway', array( $this, 'wpinv_checkout_add_subscription' ), -999, 2 ); |
|
85 | - add_action( 'wpinv_subscriptions_front_notices', array( $this, 'notices' ) ); |
|
79 | + add_action('admin_menu', array($this, 'wpinv_subscriptions_list'), 40); |
|
80 | + add_action('admin_notices', array($this, 'notices')); |
|
81 | + add_action('init', array($this, 'wpinv_post_actions')); |
|
82 | + add_action('init', array($this, 'wpinv_get_actions')); |
|
83 | + add_action('wpinv_cancel_subscription', array($this, 'wpinv_process_cancellation')); |
|
84 | + add_action('wpinv_checkout_before_send_to_gateway', array($this, 'wpinv_checkout_add_subscription'), -999, 2); |
|
85 | + add_action('wpinv_subscriptions_front_notices', array($this, 'notices')); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
@@ -104,8 +104,8 @@ discard block |
||
104 | 104 | public function wpinv_subscriptions_list() { |
105 | 105 | add_submenu_page( |
106 | 106 | 'wpinv', |
107 | - __( 'Subscriptions', 'invoicing' ), |
|
108 | - __( 'Subscriptions', 'invoicing' ), |
|
107 | + __('Subscriptions', 'invoicing'), |
|
108 | + __('Subscriptions', 'invoicing'), |
|
109 | 109 | wpinv_get_capability(), |
110 | 110 | 'wpinv-subscriptions', |
111 | 111 | 'wpinv_subscriptions_page' |
@@ -114,37 +114,37 @@ discard block |
||
114 | 114 | |
115 | 115 | public function notices() { |
116 | 116 | |
117 | - if( empty( $_GET['wpinv-message'] ) ) { |
|
117 | + if (empty($_GET['wpinv-message'])) { |
|
118 | 118 | return; |
119 | 119 | } |
120 | 120 | |
121 | 121 | $type = 'updated'; |
122 | 122 | $message = ''; |
123 | 123 | |
124 | - switch( strtolower( $_GET['wpinv-message'] ) ) { |
|
124 | + switch (strtolower($_GET['wpinv-message'])) { |
|
125 | 125 | |
126 | 126 | case 'updated' : |
127 | 127 | |
128 | - $message = __( 'Subscription updated successfully.', 'invoicing' ); |
|
128 | + $message = __('Subscription updated successfully.', 'invoicing'); |
|
129 | 129 | |
130 | 130 | break; |
131 | 131 | |
132 | 132 | case 'deleted' : |
133 | 133 | |
134 | - $message = __( 'Subscription deleted successfully.', 'invoicing' ); |
|
134 | + $message = __('Subscription deleted successfully.', 'invoicing'); |
|
135 | 135 | |
136 | 136 | break; |
137 | 137 | |
138 | 138 | case 'cancelled' : |
139 | 139 | |
140 | - $message = __( 'Subscription cancelled successfully.', 'invoicing' ); |
|
140 | + $message = __('Subscription cancelled successfully.', 'invoicing'); |
|
141 | 141 | |
142 | 142 | break; |
143 | 143 | |
144 | 144 | } |
145 | 145 | |
146 | - if ( ! empty( $message ) ) { |
|
147 | - echo '<div class="' . esc_attr( $type ) . '"><p>' . $message . '</p></div>'; |
|
146 | + if (!empty($message)) { |
|
147 | + echo '<div class="' . esc_attr($type) . '"><p>' . $message . '</p></div>'; |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | } |
@@ -157,8 +157,8 @@ discard block |
||
157 | 157 | * @return void |
158 | 158 | */ |
159 | 159 | function wpinv_get_actions() { |
160 | - if ( isset( $_GET['wpinv_action'] ) ) { |
|
161 | - do_action( 'wpinv_' . $_GET['wpinv_action'], $_GET ); |
|
160 | + if (isset($_GET['wpinv_action'])) { |
|
161 | + do_action('wpinv_' . $_GET['wpinv_action'], $_GET); |
|
162 | 162 | } |
163 | 163 | } |
164 | 164 | |
@@ -170,8 +170,8 @@ discard block |
||
170 | 170 | * @return void |
171 | 171 | */ |
172 | 172 | function wpinv_post_actions() { |
173 | - if ( isset( $_POST['wpinv_action'] ) ) { |
|
174 | - do_action( 'wpinv_' . $_POST['wpinv_action'], $_POST ); |
|
173 | + if (isset($_POST['wpinv_action'])) { |
|
174 | + do_action('wpinv_' . $_POST['wpinv_action'], $_POST); |
|
175 | 175 | } |
176 | 176 | } |
177 | 177 | |
@@ -182,24 +182,24 @@ discard block |
||
182 | 182 | * @param int $frequency_count The frequency of the period. |
183 | 183 | * @return mixed|string|void |
184 | 184 | */ |
185 | - public static function wpinv_get_pretty_subscription_frequency( $period, $frequency_count = 1) { |
|
185 | + public static function wpinv_get_pretty_subscription_frequency($period, $frequency_count = 1) { |
|
186 | 186 | $frequency = ''; |
187 | 187 | //Format period details |
188 | - switch ( $period ) { |
|
188 | + switch ($period) { |
|
189 | 189 | case 'day' : |
190 | - $frequency = sprintf( _n('%d Day', '%d Days', $frequency_count, 'invoicing'), $frequency_count); |
|
190 | + $frequency = sprintf(_n('%d Day', '%d Days', $frequency_count, 'invoicing'), $frequency_count); |
|
191 | 191 | break; |
192 | 192 | case 'week' : |
193 | - $frequency = sprintf( _n('%d Week', '%d Weeks', $frequency_count, 'invoicing'), $frequency_count); |
|
193 | + $frequency = sprintf(_n('%d Week', '%d Weeks', $frequency_count, 'invoicing'), $frequency_count); |
|
194 | 194 | break; |
195 | 195 | case 'month' : |
196 | - $frequency = sprintf( _n('%d Month', '%d Months', $frequency_count, 'invoicing'), $frequency_count); |
|
196 | + $frequency = sprintf(_n('%d Month', '%d Months', $frequency_count, 'invoicing'), $frequency_count); |
|
197 | 197 | break; |
198 | 198 | case 'year' : |
199 | - $frequency = sprintf( _n('%d Year', '%d Years', $frequency_count, 'invoicing'), $frequency_count); |
|
199 | + $frequency = sprintf(_n('%d Year', '%d Years', $frequency_count, 'invoicing'), $frequency_count); |
|
200 | 200 | break; |
201 | 201 | default : |
202 | - $frequency = apply_filters( 'wpinv_recurring_subscription_frequency', $frequency, $period, $frequency_count ); |
|
202 | + $frequency = apply_filters('wpinv_recurring_subscription_frequency', $frequency, $period, $frequency_count); |
|
203 | 203 | break; |
204 | 204 | } |
205 | 205 | |
@@ -214,50 +214,50 @@ discard block |
||
214 | 214 | * @since 1.0.0 |
215 | 215 | * @return void |
216 | 216 | */ |
217 | - public function wpinv_process_cancellation( $data ) { |
|
217 | + public function wpinv_process_cancellation($data) { |
|
218 | 218 | |
219 | 219 | |
220 | - if( empty( $data['sub_id'] ) ) { |
|
220 | + if (empty($data['sub_id'])) { |
|
221 | 221 | return; |
222 | 222 | } |
223 | 223 | |
224 | - if( ! is_user_logged_in() ) { |
|
224 | + if (!is_user_logged_in()) { |
|
225 | 225 | return; |
226 | 226 | } |
227 | 227 | |
228 | - if( ! wp_verify_nonce( $data['_wpnonce'], 'wpinv-recurring-cancel' ) ) { |
|
229 | - wp_die( __( 'Error', 'invoicing' ), __( 'Nonce verification failed', 'invoicing' ), array( 'response' => 403 ) ); |
|
228 | + if (!wp_verify_nonce($data['_wpnonce'], 'wpinv-recurring-cancel')) { |
|
229 | + wp_die(__('Error', 'invoicing'), __('Nonce verification failed', 'invoicing'), array('response' => 403)); |
|
230 | 230 | } |
231 | 231 | |
232 | - $data['sub_id'] = absint( $data['sub_id'] ); |
|
233 | - $subscription = new WPInv_Subscription( $data['sub_id'] ); |
|
232 | + $data['sub_id'] = absint($data['sub_id']); |
|
233 | + $subscription = new WPInv_Subscription($data['sub_id']); |
|
234 | 234 | |
235 | - if( ! $subscription->can_cancel() ) { |
|
236 | - wp_die( __( 'Error', 'invoicing' ), __( 'This subscription cannot be cancelled', 'invoicing' ), array( 'response' => 403 ) ); |
|
235 | + if (!$subscription->can_cancel()) { |
|
236 | + wp_die(__('Error', 'invoicing'), __('This subscription cannot be cancelled', 'invoicing'), array('response' => 403)); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | try { |
240 | 240 | |
241 | - do_action( 'wpinv_recurring_cancel_' . $subscription->gateway . '_subscription', $subscription, true ); |
|
241 | + do_action('wpinv_recurring_cancel_' . $subscription->gateway . '_subscription', $subscription, true); |
|
242 | 242 | |
243 | 243 | $subscription->cancel(); |
244 | 244 | |
245 | - if( is_admin() ) { |
|
245 | + if (is_admin()) { |
|
246 | 246 | |
247 | - wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=cancelled&id=' . $subscription->id ) ); |
|
247 | + wp_redirect(admin_url('admin.php?page=wpinv-subscriptions&wpinv-message=cancelled&id=' . $subscription->id)); |
|
248 | 248 | exit; |
249 | 249 | |
250 | 250 | } else { |
251 | 251 | |
252 | - $redirect = remove_query_arg( array( '_wpnonce', 'wpinv_action', 'sub_id' ), add_query_arg( array( 'wpinv-message' => 'cancelled' ) ) ); |
|
253 | - $redirect = apply_filters( 'wpinv_recurring_cancellation_redirect', $redirect, $subscription ); |
|
254 | - wp_safe_redirect( $redirect ); |
|
252 | + $redirect = remove_query_arg(array('_wpnonce', 'wpinv_action', 'sub_id'), add_query_arg(array('wpinv-message' => 'cancelled'))); |
|
253 | + $redirect = apply_filters('wpinv_recurring_cancellation_redirect', $redirect, $subscription); |
|
254 | + wp_safe_redirect($redirect); |
|
255 | 255 | exit; |
256 | 256 | |
257 | 257 | } |
258 | 258 | |
259 | - } catch ( Exception $e ) { |
|
260 | - wp_die( __( 'Error', 'invoicing' ), $e->getMessage(), array( 'response' => 403 ) ); |
|
259 | + } catch (Exception $e) { |
|
260 | + wp_die(__('Error', 'invoicing'), $e->getMessage(), array('response' => 403)); |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | } |
@@ -270,40 +270,40 @@ discard block |
||
270 | 270 | * @since 1.0.0 |
271 | 271 | * @return void |
272 | 272 | */ |
273 | - public function wpinv_checkout_add_subscription( $invoice, $invoice_data ) { |
|
274 | - if ( ! ( ! empty( $invoice->ID ) && $invoice->is_recurring() ) ) { |
|
273 | + public function wpinv_checkout_add_subscription($invoice, $invoice_data) { |
|
274 | + if (!(!empty($invoice->ID) && $invoice->is_recurring())) { |
|
275 | 275 | return; |
276 | 276 | } |
277 | 277 | |
278 | 278 | // Should we create a subscription for the invoice? |
279 | - if ( apply_filters( 'wpinv_skip_invoice_subscription_creation', false, $invoice ) ) { |
|
279 | + if (apply_filters('wpinv_skip_invoice_subscription_creation', false, $invoice)) { |
|
280 | 280 | return; |
281 | 281 | } |
282 | 282 | |
283 | - $item = $invoice->get_recurring( true ); |
|
284 | - if ( empty( $item ) ) { |
|
283 | + $item = $invoice->get_recurring(true); |
|
284 | + if (empty($item)) { |
|
285 | 285 | return; |
286 | 286 | } |
287 | 287 | |
288 | - $invoice_date = $invoice->get_invoice_date( false ); |
|
288 | + $invoice_date = $invoice->get_invoice_date(false); |
|
289 | 289 | $status = 'pending'; |
290 | 290 | |
291 | - $period = $item->get_recurring_period( true ); |
|
291 | + $period = $item->get_recurring_period(true); |
|
292 | 292 | $interval = $item->get_recurring_interval(); |
293 | - $bill_times = (int)$item->get_recurring_limit(); |
|
293 | + $bill_times = (int) $item->get_recurring_limit(); |
|
294 | 294 | $add_period = $interval . ' ' . $period; |
295 | 295 | $trial_period = ''; |
296 | 296 | |
297 | - if ( $invoice->is_free_trial() ) { |
|
297 | + if ($invoice->is_free_trial()) { |
|
298 | 298 | $status = 'trialling'; |
299 | - $trial_period = $item->get_trial_period( true ); |
|
299 | + $trial_period = $item->get_trial_period(true); |
|
300 | 300 | $free_interval = $item->get_trial_interval(); |
301 | 301 | $trial_period = $free_interval . ' ' . $trial_period; |
302 | 302 | |
303 | 303 | $add_period = $trial_period; |
304 | 304 | } |
305 | 305 | |
306 | - $expiration = date_i18n( 'Y-m-d H:i:s', strtotime( '+' . $add_period . ' 23:59:59', strtotime( $invoice_date ) ) ); |
|
306 | + $expiration = date_i18n('Y-m-d H:i:s', strtotime('+' . $add_period . ' 23:59:59', strtotime($invoice_date))); |
|
307 | 307 | |
308 | 308 | $args = array( |
309 | 309 | 'product_id' => $item->ID, |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | 'frequency' => $interval, |
314 | 314 | 'period' => $period, |
315 | 315 | 'initial_amount' => $invoice->get_total(), |
316 | - 'recurring_amount' => $invoice->get_recurring_details( 'total' ), |
|
316 | + 'recurring_amount' => $invoice->get_recurring_details('total'), |
|
317 | 317 | 'bill_times' => $bill_times, |
318 | 318 | 'created' => $invoice_date, |
319 | 319 | 'expiration' => $expiration, |
@@ -322,11 +322,11 @@ discard block |
||
322 | 322 | 'transaction_id' => '', |
323 | 323 | ); |
324 | 324 | |
325 | - $subscription = wpinv_get_subscription( $invoice ); |
|
325 | + $subscription = wpinv_get_subscription($invoice); |
|
326 | 326 | |
327 | - if ( empty( $subscription ) ) { |
|
327 | + if (empty($subscription)) { |
|
328 | 328 | $subscription = new WPInv_Subscription(); |
329 | - $subscription->create( $args ); |
|
329 | + $subscription->create($args); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | return $subscription; |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; // Exit if accessed directly |
4 | 4 | } |
5 | 5 | |
@@ -21,175 +21,175 @@ discard block |
||
21 | 21 | public function init() { |
22 | 22 | global $wp_filesystem; |
23 | 23 | |
24 | - if ( empty( $wp_filesystem ) ) { |
|
25 | - require_once( ABSPATH . '/wp-admin/includes/file.php' ); |
|
24 | + if (empty($wp_filesystem)) { |
|
25 | + require_once(ABSPATH . '/wp-admin/includes/file.php'); |
|
26 | 26 | WP_Filesystem(); |
27 | 27 | global $wp_filesystem; |
28 | 28 | } |
29 | 29 | $this->wp_filesystem = $wp_filesystem; |
30 | 30 | |
31 | 31 | $this->export_dir = $this->export_location(); |
32 | - $this->export_url = $this->export_location( true ); |
|
32 | + $this->export_url = $this->export_location(true); |
|
33 | 33 | $this->export = 'invoicing'; |
34 | 34 | $this->filetype = 'csv'; |
35 | 35 | $this->per_page = 20; |
36 | 36 | |
37 | - do_action( 'wpinv_class_reports_init', $this ); |
|
37 | + do_action('wpinv_class_reports_init', $this); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | public function includes() { |
41 | - do_action( 'wpinv_class_reports_includes', $this ); |
|
41 | + do_action('wpinv_class_reports_includes', $this); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | public function actions() { |
45 | - if ( is_admin() ) { |
|
46 | - add_action( 'admin_menu', array( $this, 'add_submenu' ), 20 ); |
|
47 | - add_action( 'wpinv_reports_tab_export', array( $this, 'export' ) ); |
|
48 | - add_action( 'wp_ajax_wpinv_ajax_export', array( $this, 'ajax_export' ) ); |
|
49 | - add_action( 'wp_ajax_wpinv_ajax_discount_use_export', array( $this, 'discount_use_export' ) ); |
|
45 | + if (is_admin()) { |
|
46 | + add_action('admin_menu', array($this, 'add_submenu'), 20); |
|
47 | + add_action('wpinv_reports_tab_export', array($this, 'export')); |
|
48 | + add_action('wp_ajax_wpinv_ajax_export', array($this, 'ajax_export')); |
|
49 | + add_action('wp_ajax_wpinv_ajax_discount_use_export', array($this, 'discount_use_export')); |
|
50 | 50 | |
51 | 51 | // Export Invoices. |
52 | - add_action( 'wpinv_export_set_params_invoices', array( $this, 'set_invoices_export' ) ); |
|
53 | - add_filter( 'wpinv_export_get_columns_invoices', array( $this, 'get_invoices_columns' ) ); |
|
54 | - add_filter( 'wpinv_export_get_data_invoices', array( $this, 'get_invoices_data' ) ); |
|
55 | - add_filter( 'wpinv_get_export_status_invoices', array( $this, 'invoices_export_status' ) ); |
|
52 | + add_action('wpinv_export_set_params_invoices', array($this, 'set_invoices_export')); |
|
53 | + add_filter('wpinv_export_get_columns_invoices', array($this, 'get_invoices_columns')); |
|
54 | + add_filter('wpinv_export_get_data_invoices', array($this, 'get_invoices_data')); |
|
55 | + add_filter('wpinv_get_export_status_invoices', array($this, 'invoices_export_status')); |
|
56 | 56 | } |
57 | - do_action( 'wpinv_class_reports_actions', $this ); |
|
57 | + do_action('wpinv_class_reports_actions', $this); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | public function add_submenu() { |
61 | 61 | global $wpi_reports_page; |
62 | - $wpi_reports_page = add_submenu_page( 'wpinv', __( 'Reports', 'invoicing' ), __( 'Reports', 'invoicing' ), wpinv_get_capability(), 'wpinv-reports', array( $this, 'reports_page' ) ); |
|
62 | + $wpi_reports_page = add_submenu_page('wpinv', __('Reports', 'invoicing'), __('Reports', 'invoicing'), wpinv_get_capability(), 'wpinv-reports', array($this, 'reports_page')); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | public function reports_page() { |
66 | - if ( !wp_script_is( 'postbox', 'enqueued' ) ) { |
|
67 | - wp_enqueue_script( 'postbox' ); |
|
66 | + if (!wp_script_is('postbox', 'enqueued')) { |
|
67 | + wp_enqueue_script('postbox'); |
|
68 | 68 | } |
69 | - if ( !wp_script_is( 'jquery-ui-datepicker', 'enqueued' ) ) { |
|
70 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
69 | + if (!wp_script_is('jquery-ui-datepicker', 'enqueued')) { |
|
70 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
71 | 71 | } |
72 | 72 | |
73 | - $current_page = admin_url( 'admin.php?page=wpinv-reports' ); |
|
74 | - $active_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'export'; |
|
73 | + $current_page = admin_url('admin.php?page=wpinv-reports'); |
|
74 | + $active_tab = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : 'export'; |
|
75 | 75 | ?> |
76 | 76 | <div class="wrap wpi-reports-wrap"> |
77 | - <h1><?php echo esc_html( __( 'Reports', 'invoicing' ) ); ?></h1> |
|
77 | + <h1><?php echo esc_html(__('Reports', 'invoicing')); ?></h1> |
|
78 | 78 | <h2 class="nav-tab-wrapper wp-clearfix"> |
79 | - <a href="<?php echo add_query_arg( array( 'tab' => 'export', 'settings-updated' => false ), $current_page ); ?>" class="nav-tab <?php echo $active_tab == 'export' ? 'nav-tab-active' : ''; ?>"><?php _e( 'Export', 'invoicing' ); ?></a> |
|
80 | - <?php do_action( 'wpinv_reports_page_tabs' ); ;?> |
|
79 | + <a href="<?php echo add_query_arg(array('tab' => 'export', 'settings-updated' => false), $current_page); ?>" class="nav-tab <?php echo $active_tab == 'export' ? 'nav-tab-active' : ''; ?>"><?php _e('Export', 'invoicing'); ?></a> |
|
80 | + <?php do_action('wpinv_reports_page_tabs'); ;?> |
|
81 | 81 | </h2> |
82 | - <div class="wpi-reports-content wpi-reports-<?php echo esc_attr( $active_tab ); ?>"> |
|
82 | + <div class="wpi-reports-content wpi-reports-<?php echo esc_attr($active_tab); ?>"> |
|
83 | 83 | <?php |
84 | - do_action( 'wpinv_reports_page_top' ); |
|
85 | - do_action( 'wpinv_reports_tab_' . $active_tab ); |
|
86 | - do_action( 'wpinv_reports_page_bottom' ); |
|
84 | + do_action('wpinv_reports_page_top'); |
|
85 | + do_action('wpinv_reports_tab_' . $active_tab); |
|
86 | + do_action('wpinv_reports_page_bottom'); |
|
87 | 87 | ?> |
88 | 88 | </div> |
89 | 89 | <?php |
90 | 90 | } |
91 | 91 | |
92 | 92 | public function export() { |
93 | - $statuses = wpinv_get_invoice_statuses( true ); |
|
94 | - $statuses = array_merge( array( 'any' => __( 'All Statuses', 'invoicing' ) ), $statuses ); |
|
93 | + $statuses = wpinv_get_invoice_statuses(true); |
|
94 | + $statuses = array_merge(array('any' => __('All Statuses', 'invoicing')), $statuses); |
|
95 | 95 | ?> |
96 | 96 | <div class="metabox-holder"> |
97 | 97 | <div id="post-body"> |
98 | 98 | <div id="post-body-content"> |
99 | - <?php do_action( 'wpinv_reports_tab_export_content_top' ); ?> |
|
99 | + <?php do_action('wpinv_reports_tab_export_content_top'); ?> |
|
100 | 100 | |
101 | 101 | <div class="postbox wpi-export-invoices"> |
102 | - <h2 class="hndle ui-sortabled-handle"><span><?php _e( 'Invoices','invoicing' ); ?></span></h2> |
|
102 | + <h2 class="hndle ui-sortabled-handle"><span><?php _e('Invoices', 'invoicing'); ?></span></h2> |
|
103 | 103 | <div class="inside"> |
104 | - <p><?php _e( 'Download a CSV of all payment invoices.', 'invoicing' ); ?></p> |
|
104 | + <p><?php _e('Download a CSV of all payment invoices.', 'invoicing'); ?></p> |
|
105 | 105 | <form id="wpi-export-invoices" class="wpi-export-form" method="post"> |
106 | - <?php echo wpinv_html_date_field( array( |
|
106 | + <?php echo wpinv_html_date_field(array( |
|
107 | 107 | 'id' => 'wpi_export_from_date', |
108 | 108 | 'name' => 'from_date', |
109 | 109 | 'data' => array( |
110 | 110 | 'dateFormat' => 'yy-mm-dd' |
111 | 111 | ), |
112 | - 'placeholder' => __( 'From date', 'invoicing' ) ) |
|
112 | + 'placeholder' => __('From date', 'invoicing') ) |
|
113 | 113 | ); ?> |
114 | - <?php echo wpinv_html_date_field( array( |
|
114 | + <?php echo wpinv_html_date_field(array( |
|
115 | 115 | 'id' => 'wpi_export_to_date', |
116 | 116 | 'name' => 'to_date', |
117 | 117 | 'data' => array( |
118 | 118 | 'dateFormat' => 'yy-mm-dd' |
119 | 119 | ), |
120 | - 'placeholder' => __( 'To date', 'invoicing' ) ) |
|
120 | + 'placeholder' => __('To date', 'invoicing') ) |
|
121 | 121 | ); ?> |
122 | 122 | <span id="wpinv-status-wrap"> |
123 | - <?php echo wpinv_html_select( array( |
|
123 | + <?php echo wpinv_html_select(array( |
|
124 | 124 | 'options' => $statuses, |
125 | 125 | 'name' => 'status', |
126 | 126 | 'id' => 'wpi_export_status', |
127 | 127 | 'show_option_all' => false, |
128 | 128 | 'show_option_none' => false, |
129 | 129 | 'class' => 'wpi_select2', |
130 | - ) ); ?> |
|
131 | - <?php wp_nonce_field( 'wpi_ajax_export', 'wpi_ajax_export' ); ?> |
|
130 | + )); ?> |
|
131 | + <?php wp_nonce_field('wpi_ajax_export', 'wpi_ajax_export'); ?> |
|
132 | 132 | </span> |
133 | 133 | <span id="wpinv-submit-wrap"> |
134 | 134 | <input type="hidden" value="invoices" name="export" /> |
135 | - <input type="submit" value="<?php _e( 'Generate CSV', 'invoicing' ); ?>" class="button-primary" /> |
|
135 | + <input type="submit" value="<?php _e('Generate CSV', 'invoicing'); ?>" class="button-primary" /> |
|
136 | 136 | </span> |
137 | 137 | </form> |
138 | 138 | </div> |
139 | 139 | </div> |
140 | 140 | |
141 | 141 | <div class="postbox wpi-export-discount-uses"> |
142 | - <h2 class="hndle ui-sortabled-handle"><span><?php _e( 'Discount Use','invoicing' ); ?></span></h2> |
|
142 | + <h2 class="hndle ui-sortabled-handle"><span><?php _e('Discount Use', 'invoicing'); ?></span></h2> |
|
143 | 143 | <div class="inside"> |
144 | - <p><?php _e( 'Download a CSV of discount uses.', 'invoicing' ); ?></p> |
|
145 | - <a class="button-primary" href="<?php echo esc_url( wp_nonce_url( admin_url( 'admin-ajax.php?action=wpinv_ajax_discount_use_export' ), 'wpi_discount_ajax_export', 'wpi_discount_ajax_export' ) ); ?>"><?php _e( 'Generate CSV', 'invoicing' ); ?></a> |
|
144 | + <p><?php _e('Download a CSV of discount uses.', 'invoicing'); ?></p> |
|
145 | + <a class="button-primary" href="<?php echo esc_url(wp_nonce_url(admin_url('admin-ajax.php?action=wpinv_ajax_discount_use_export'), 'wpi_discount_ajax_export', 'wpi_discount_ajax_export')); ?>"><?php _e('Generate CSV', 'invoicing'); ?></a> |
|
146 | 146 | </div> |
147 | 147 | </div> |
148 | 148 | |
149 | - <?php do_action( 'wpinv_reports_tab_export_content_bottom' ); ?> |
|
149 | + <?php do_action('wpinv_reports_tab_export_content_bottom'); ?> |
|
150 | 150 | </div> |
151 | 151 | </div> |
152 | 152 | </div> |
153 | 153 | <?php |
154 | 154 | } |
155 | 155 | |
156 | - public function export_location( $relative = false ) { |
|
156 | + public function export_location($relative = false) { |
|
157 | 157 | $upload_dir = wp_upload_dir(); |
158 | - $export_location = $relative ? trailingslashit( $upload_dir['baseurl'] ) . 'cache' : trailingslashit( $upload_dir['basedir'] ) . 'cache'; |
|
159 | - $export_location = apply_filters( 'wpinv_export_location', $export_location, $relative ); |
|
158 | + $export_location = $relative ? trailingslashit($upload_dir['baseurl']) . 'cache' : trailingslashit($upload_dir['basedir']) . 'cache'; |
|
159 | + $export_location = apply_filters('wpinv_export_location', $export_location, $relative); |
|
160 | 160 | |
161 | - return trailingslashit( $export_location ); |
|
161 | + return trailingslashit($export_location); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | public function check_export_location() { |
165 | 165 | try { |
166 | - if ( empty( $this->wp_filesystem ) ) { |
|
167 | - return __( 'Filesystem ERROR: Could not access filesystem.', 'invoicing' ); |
|
166 | + if (empty($this->wp_filesystem)) { |
|
167 | + return __('Filesystem ERROR: Could not access filesystem.', 'invoicing'); |
|
168 | 168 | } |
169 | 169 | |
170 | - if ( is_wp_error( $this->wp_filesystem ) ) { |
|
171 | - return __( 'Filesystem ERROR: ' . $this->wp_filesystem->get_error_message(), 'invoicing' ); |
|
170 | + if (is_wp_error($this->wp_filesystem)) { |
|
171 | + return __('Filesystem ERROR: ' . $this->wp_filesystem->get_error_message(), 'invoicing'); |
|
172 | 172 | } |
173 | 173 | |
174 | - $is_dir = $this->wp_filesystem->is_dir( $this->export_dir ); |
|
175 | - $is_writeable = $is_dir && is_writeable( $this->export_dir ); |
|
174 | + $is_dir = $this->wp_filesystem->is_dir($this->export_dir); |
|
175 | + $is_writeable = $is_dir && is_writeable($this->export_dir); |
|
176 | 176 | |
177 | - if ( $is_dir && $is_writeable ) { |
|
177 | + if ($is_dir && $is_writeable) { |
|
178 | 178 | return true; |
179 | - } else if ( $is_dir && !$is_writeable ) { |
|
180 | - if ( !$this->wp_filesystem->chmod( $this->export_dir, FS_CHMOD_DIR ) ) { |
|
181 | - return wp_sprintf( __( 'Filesystem ERROR: Export location %s is not writable, check your file permissions.', 'invoicing' ), $this->export_dir ); |
|
179 | + } else if ($is_dir && !$is_writeable) { |
|
180 | + if (!$this->wp_filesystem->chmod($this->export_dir, FS_CHMOD_DIR)) { |
|
181 | + return wp_sprintf(__('Filesystem ERROR: Export location %s is not writable, check your file permissions.', 'invoicing'), $this->export_dir); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | return true; |
185 | 185 | } else { |
186 | - if ( !$this->wp_filesystem->mkdir( $this->export_dir, FS_CHMOD_DIR ) ) { |
|
187 | - return wp_sprintf( __( 'Filesystem ERROR: Could not create directory %s. This is usually due to inconsistent file permissions.', 'invoicing' ), $this->export_dir ); |
|
186 | + if (!$this->wp_filesystem->mkdir($this->export_dir, FS_CHMOD_DIR)) { |
|
187 | + return wp_sprintf(__('Filesystem ERROR: Could not create directory %s. This is usually due to inconsistent file permissions.', 'invoicing'), $this->export_dir); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | return true; |
191 | 191 | } |
192 | - } catch ( Exception $e ) { |
|
192 | + } catch (Exception $e) { |
|
193 | 193 | return $e->getMessage(); |
194 | 194 | } |
195 | 195 | } |
@@ -197,59 +197,59 @@ discard block |
||
197 | 197 | public function ajax_export() { |
198 | 198 | $response = array(); |
199 | 199 | $response['success'] = false; |
200 | - $response['msg'] = __( 'Invalid export request found.', 'invoicing' ); |
|
200 | + $response['msg'] = __('Invalid export request found.', 'invoicing'); |
|
201 | 201 | |
202 | - if ( empty( $_POST['data'] ) || ! wpinv_current_user_can_manage_invoicing() ) { |
|
203 | - wp_send_json( $response ); |
|
202 | + if (empty($_POST['data']) || !wpinv_current_user_can_manage_invoicing()) { |
|
203 | + wp_send_json($response); |
|
204 | 204 | } |
205 | 205 | |
206 | - parse_str( $_POST['data'], $data ); |
|
206 | + parse_str($_POST['data'], $data); |
|
207 | 207 | |
208 | - $data['step'] = !empty( $_POST['step'] ) ? absint( $_POST['step'] ) : 1; |
|
208 | + $data['step'] = !empty($_POST['step']) ? absint($_POST['step']) : 1; |
|
209 | 209 | |
210 | - $_REQUEST = (array)$data; |
|
211 | - if ( !( !empty( $_REQUEST['wpi_ajax_export'] ) && wp_verify_nonce( $_REQUEST['wpi_ajax_export'], 'wpi_ajax_export' ) ) ) { |
|
212 | - $response['msg'] = __( 'Security check failed.', 'invoicing' ); |
|
213 | - wp_send_json( $response ); |
|
210 | + $_REQUEST = (array) $data; |
|
211 | + if (!(!empty($_REQUEST['wpi_ajax_export']) && wp_verify_nonce($_REQUEST['wpi_ajax_export'], 'wpi_ajax_export'))) { |
|
212 | + $response['msg'] = __('Security check failed.', 'invoicing'); |
|
213 | + wp_send_json($response); |
|
214 | 214 | } |
215 | 215 | |
216 | - if ( ( $error = $this->check_export_location( true ) ) !== true ) { |
|
217 | - $response['msg'] = __( 'Filesystem ERROR: ' . $error, 'invoicing' ); |
|
218 | - wp_send_json( $response ); |
|
216 | + if (($error = $this->check_export_location(true)) !== true) { |
|
217 | + $response['msg'] = __('Filesystem ERROR: ' . $error, 'invoicing'); |
|
218 | + wp_send_json($response); |
|
219 | 219 | } |
220 | 220 | |
221 | - $this->set_export_params( $_REQUEST ); |
|
221 | + $this->set_export_params($_REQUEST); |
|
222 | 222 | |
223 | 223 | $return = $this->process_export_step(); |
224 | 224 | $done = $this->get_export_status(); |
225 | 225 | |
226 | - if ( $return ) { |
|
226 | + if ($return) { |
|
227 | 227 | $this->step += 1; |
228 | 228 | |
229 | 229 | $response['success'] = true; |
230 | 230 | $response['msg'] = ''; |
231 | 231 | |
232 | - if ( $done >= 100 ) { |
|
232 | + if ($done >= 100) { |
|
233 | 233 | $this->step = 'done'; |
234 | - $new_filename = 'wpi-' . $this->export . '-' . date( 'y-m-d-H-i' ) . '.' . $this->filetype; |
|
234 | + $new_filename = 'wpi-' . $this->export . '-' . date('y-m-d-H-i') . '.' . $this->filetype; |
|
235 | 235 | $new_file = $this->export_dir . $new_filename; |
236 | 236 | |
237 | - if ( file_exists( $this->file ) ) { |
|
238 | - $this->wp_filesystem->move( $this->file, $new_file, true ); |
|
237 | + if (file_exists($this->file)) { |
|
238 | + $this->wp_filesystem->move($this->file, $new_file, true); |
|
239 | 239 | } |
240 | 240 | |
241 | - if ( file_exists( $new_file ) ) { |
|
242 | - $response['data']['file'] = array( 'u' => $this->export_url . $new_filename, 's' => size_format( filesize( $new_file ), 2 ) ); |
|
241 | + if (file_exists($new_file)) { |
|
242 | + $response['data']['file'] = array('u' => $this->export_url . $new_filename, 's' => size_format(filesize($new_file), 2)); |
|
243 | 243 | } |
244 | 244 | } |
245 | 245 | |
246 | 246 | $response['data']['step'] = $this->step; |
247 | 247 | $response['data']['done'] = $done; |
248 | 248 | } else { |
249 | - $response['msg'] = __( 'No data found for export.', 'invoicing' ); |
|
249 | + $response['msg'] = __('No data found for export.', 'invoicing'); |
|
250 | 250 | } |
251 | 251 | |
252 | - wp_send_json( $response ); |
|
252 | + wp_send_json($response); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | /** |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | */ |
258 | 258 | public function discount_use_export() { |
259 | 259 | |
260 | - if ( ! wp_verify_nonce( $_GET['wpi_discount_ajax_export'], 'wpi_discount_ajax_export' ) || ! wpinv_current_user_can_manage_invoicing() ) { |
|
260 | + if (!wp_verify_nonce($_GET['wpi_discount_ajax_export'], 'wpi_discount_ajax_export') || !wpinv_current_user_can_manage_invoicing()) { |
|
261 | 261 | wp_die( -1, 403 ); |
262 | 262 | } |
263 | 263 | |
@@ -267,115 +267,115 @@ discard block |
||
267 | 267 | 'posts_per_page' => -1, |
268 | 268 | ); |
269 | 269 | |
270 | - $discounts = get_posts( $args ); |
|
270 | + $discounts = get_posts($args); |
|
271 | 271 | |
272 | - if ( empty( $discounts ) ) { |
|
273 | - die ( __( 'You have not set up any discounts', 'invoicing' ) ); |
|
272 | + if (empty($discounts)) { |
|
273 | + die (__('You have not set up any discounts', 'invoicing')); |
|
274 | 274 | } |
275 | 275 | |
276 | - $output = fopen( 'php://output', 'w' ) or die( 'Unsupported server' ); |
|
276 | + $output = fopen('php://output', 'w') or die('Unsupported server'); |
|
277 | 277 | |
278 | 278 | // Let the browser know what content we're streaming and how it should save the content. |
279 | 279 | $name = time(); |
280 | - header( "Content-Type:application/csv" ); |
|
281 | - header( "Content-Disposition:attachment;filename=noptin-subscribers-$name.csv" ); |
|
280 | + header("Content-Type:application/csv"); |
|
281 | + header("Content-Disposition:attachment;filename=noptin-subscribers-$name.csv"); |
|
282 | 282 | |
283 | 283 | // Output the csv column headers. |
284 | 284 | fputcsv( |
285 | 285 | $output, |
286 | 286 | array( |
287 | - __( 'Discount Id', 'invoicing' ), |
|
288 | - __( 'Discount Code', 'invoicing' ), |
|
289 | - __( 'Discount Type', 'invoicing' ), |
|
290 | - __( 'Discount Amount', 'invoicing' ), |
|
291 | - __( 'Uses', 'invoicing' ), |
|
287 | + __('Discount Id', 'invoicing'), |
|
288 | + __('Discount Code', 'invoicing'), |
|
289 | + __('Discount Type', 'invoicing'), |
|
290 | + __('Discount Amount', 'invoicing'), |
|
291 | + __('Uses', 'invoicing'), |
|
292 | 292 | ) |
293 | 293 | ); |
294 | 294 | |
295 | - foreach ( $discounts as $discount ) { |
|
295 | + foreach ($discounts as $discount) { |
|
296 | 296 | |
297 | 297 | $discount = (int) $discount; |
298 | 298 | $row = array( |
299 | 299 | $discount, |
300 | - get_post_meta( $discount, '_wpi_discount_code', true ), |
|
301 | - get_post_meta( $discount, '_wpi_discount_type', true ), |
|
302 | - get_post_meta( $discount, '_wpi_discount_amount', true ), |
|
303 | - (int) get_post_meta( $discount, '_wpi_discount_uses', true ) |
|
300 | + get_post_meta($discount, '_wpi_discount_code', true), |
|
301 | + get_post_meta($discount, '_wpi_discount_type', true), |
|
302 | + get_post_meta($discount, '_wpi_discount_amount', true), |
|
303 | + (int) get_post_meta($discount, '_wpi_discount_uses', true) |
|
304 | 304 | ); |
305 | - fputcsv( $output, $row ); |
|
305 | + fputcsv($output, $row); |
|
306 | 306 | } |
307 | 307 | |
308 | - fclose( $output ); |
|
308 | + fclose($output); |
|
309 | 309 | exit; |
310 | 310 | |
311 | 311 | } |
312 | 312 | |
313 | - public function set_export_params( $request ) { |
|
313 | + public function set_export_params($request) { |
|
314 | 314 | $this->empty = false; |
315 | - $this->step = !empty( $request['step'] ) ? absint( $request['step'] ) : 1; |
|
316 | - $this->export = !empty( $request['export'] ) ? $request['export'] : $this->export; |
|
315 | + $this->step = !empty($request['step']) ? absint($request['step']) : 1; |
|
316 | + $this->export = !empty($request['export']) ? $request['export'] : $this->export; |
|
317 | 317 | $this->filename = 'wpi-' . $this->export . '-' . $request['wpi_ajax_export'] . '.' . $this->filetype; |
318 | 318 | $this->file = $this->export_dir . $this->filename; |
319 | 319 | |
320 | - do_action( 'wpinv_export_set_params_' . $this->export, $request ); |
|
320 | + do_action('wpinv_export_set_params_' . $this->export, $request); |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | public function get_columns() { |
324 | 324 | $columns = array(); |
325 | 325 | |
326 | - return apply_filters( 'wpinv_export_get_columns_' . $this->export, $columns ); |
|
326 | + return apply_filters('wpinv_export_get_columns_' . $this->export, $columns); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | protected function get_export_file() { |
330 | 330 | $file = ''; |
331 | 331 | |
332 | - if ( $this->wp_filesystem->exists( $this->file ) ) { |
|
333 | - $file = $this->wp_filesystem->get_contents( $this->file ); |
|
332 | + if ($this->wp_filesystem->exists($this->file)) { |
|
333 | + $file = $this->wp_filesystem->get_contents($this->file); |
|
334 | 334 | } else { |
335 | - $this->wp_filesystem->put_contents( $this->file, '' ); |
|
335 | + $this->wp_filesystem->put_contents($this->file, ''); |
|
336 | 336 | } |
337 | 337 | |
338 | 338 | return $file; |
339 | 339 | } |
340 | 340 | |
341 | - protected function attach_export_data( $data = '' ) { |
|
342 | - $filedata = $this->get_export_file(); |
|
343 | - $filedata .= $data; |
|
341 | + protected function attach_export_data($data = '') { |
|
342 | + $filedata = $this->get_export_file(); |
|
343 | + $filedata .= $data; |
|
344 | 344 | |
345 | - $this->wp_filesystem->put_contents( $this->file, $filedata ); |
|
345 | + $this->wp_filesystem->put_contents($this->file, $filedata); |
|
346 | 346 | |
347 | - $rows = file( $this->file, FILE_SKIP_EMPTY_LINES ); |
|
347 | + $rows = file($this->file, FILE_SKIP_EMPTY_LINES); |
|
348 | 348 | $columns = $this->get_columns(); |
349 | - $columns = empty( $columns ) ? 0 : 1; |
|
349 | + $columns = empty($columns) ? 0 : 1; |
|
350 | 350 | |
351 | - $this->empty = count( $rows ) == $columns ? true : false; |
|
351 | + $this->empty = count($rows) == $columns ? true : false; |
|
352 | 352 | } |
353 | 353 | |
354 | 354 | public function print_columns() { |
355 | 355 | $column_data = ''; |
356 | 356 | $columns = $this->get_columns(); |
357 | 357 | $i = 1; |
358 | - foreach( $columns as $key => $column ) { |
|
359 | - $column_data .= '"' . addslashes( $column ) . '"'; |
|
360 | - $column_data .= $i == count( $columns ) ? '' : ','; |
|
358 | + foreach ($columns as $key => $column) { |
|
359 | + $column_data .= '"' . addslashes($column) . '"'; |
|
360 | + $column_data .= $i == count($columns) ? '' : ','; |
|
361 | 361 | $i++; |
362 | 362 | } |
363 | 363 | $column_data .= "\r\n"; |
364 | 364 | |
365 | - $this->attach_export_data( $column_data ); |
|
365 | + $this->attach_export_data($column_data); |
|
366 | 366 | |
367 | 367 | return $column_data; |
368 | 368 | } |
369 | 369 | |
370 | 370 | public function process_export_step() { |
371 | - if ( $this->step < 2 ) { |
|
372 | - /** @scrutinizer ignore-unhandled */ @unlink( $this->file ); |
|
371 | + if ($this->step < 2) { |
|
372 | + /** @scrutinizer ignore-unhandled */ @unlink($this->file); |
|
373 | 373 | $this->print_columns(); |
374 | 374 | } |
375 | 375 | |
376 | 376 | $return = $this->print_rows(); |
377 | 377 | |
378 | - if ( $return ) { |
|
378 | + if ($return) { |
|
379 | 379 | return true; |
380 | 380 | } else { |
381 | 381 | return false; |
@@ -384,14 +384,14 @@ discard block |
||
384 | 384 | |
385 | 385 | public function get_export_status() { |
386 | 386 | $status = 100; |
387 | - return apply_filters( 'wpinv_get_export_status_' . $this->export, $status ); |
|
387 | + return apply_filters('wpinv_get_export_status_' . $this->export, $status); |
|
388 | 388 | } |
389 | 389 | |
390 | 390 | public function get_export_data() { |
391 | 391 | $data = array(); |
392 | 392 | |
393 | - $data = apply_filters( 'wpinv_export_get_data', $data ); |
|
394 | - $data = apply_filters( 'wpinv_export_get_data_' . $this->export, $data ); |
|
393 | + $data = apply_filters('wpinv_export_get_data', $data); |
|
394 | + $data = apply_filters('wpinv_export_get_data_' . $this->export, $data); |
|
395 | 395 | |
396 | 396 | return $data; |
397 | 397 | } |
@@ -401,20 +401,20 @@ discard block |
||
401 | 401 | $data = $this->get_export_data(); |
402 | 402 | $columns = $this->get_columns(); |
403 | 403 | |
404 | - if ( $data ) { |
|
405 | - foreach ( $data as $row ) { |
|
404 | + if ($data) { |
|
405 | + foreach ($data as $row) { |
|
406 | 406 | $i = 1; |
407 | - foreach ( $row as $key => $column ) { |
|
408 | - if ( array_key_exists( $key, $columns ) ) { |
|
409 | - $row_data .= '"' . addslashes( preg_replace( "/\"/","'", $column ) ) . '"'; |
|
410 | - $row_data .= $i == count( $columns ) ? '' : ','; |
|
407 | + foreach ($row as $key => $column) { |
|
408 | + if (array_key_exists($key, $columns)) { |
|
409 | + $row_data .= '"' . addslashes(preg_replace("/\"/", "'", $column)) . '"'; |
|
410 | + $row_data .= $i == count($columns) ? '' : ','; |
|
411 | 411 | $i++; |
412 | 412 | } |
413 | 413 | } |
414 | 414 | $row_data .= "\r\n"; |
415 | 415 | } |
416 | 416 | |
417 | - $this->attach_export_data( $row_data ); |
|
417 | + $this->attach_export_data($row_data); |
|
418 | 418 | |
419 | 419 | return $row_data; |
420 | 420 | } |
@@ -423,48 +423,48 @@ discard block |
||
423 | 423 | } |
424 | 424 | |
425 | 425 | // Export Invoices. |
426 | - public function set_invoices_export( $request ) { |
|
427 | - $this->from_date = isset( $request['from_date'] ) ? sanitize_text_field( $request['from_date'] ) : ''; |
|
428 | - $this->to_date = isset( $request['to_date'] ) ? sanitize_text_field( $request['to_date'] ) : ''; |
|
429 | - $this->status = isset( $request['status'] ) ? sanitize_text_field( $request['status'] ) : 'publish'; |
|
426 | + public function set_invoices_export($request) { |
|
427 | + $this->from_date = isset($request['from_date']) ? sanitize_text_field($request['from_date']) : ''; |
|
428 | + $this->to_date = isset($request['to_date']) ? sanitize_text_field($request['to_date']) : ''; |
|
429 | + $this->status = isset($request['status']) ? sanitize_text_field($request['status']) : 'publish'; |
|
430 | 430 | } |
431 | 431 | |
432 | - public function get_invoices_columns( $columns = array() ) { |
|
432 | + public function get_invoices_columns($columns = array()) { |
|
433 | 433 | $columns = array( |
434 | - 'id' => __( 'ID', 'invoicing' ), |
|
435 | - 'number' => __( 'Number', 'invoicing' ), |
|
436 | - 'date' => __( 'Date', 'invoicing' ), |
|
437 | - 'due_date' => __( 'Due Date', 'invoicing' ), |
|
438 | - 'completed_date'=> __( 'Payment Done Date', 'invoicing' ), |
|
439 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
440 | - 'currency' => __( 'Currency', 'invoicing' ), |
|
441 | - 'items' => __( 'Items', 'invoicing' ), |
|
442 | - 'status_nicename' => __( 'Status Nicename', 'invoicing' ), |
|
443 | - 'status' => __( 'Status', 'invoicing' ), |
|
444 | - 'tax' => __( 'Tax', 'invoicing' ), |
|
445 | - 'discount' => __( 'Discount', 'invoicing' ), |
|
446 | - 'user_id' => __( 'User ID', 'invoicing' ), |
|
447 | - 'email' => __( 'Email', 'invoicing' ), |
|
448 | - 'first_name' => __( 'First Name', 'invoicing' ), |
|
449 | - 'last_name' => __( 'Last Name', 'invoicing' ), |
|
450 | - 'address' => __( 'Address', 'invoicing' ), |
|
451 | - 'city' => __( 'City', 'invoicing' ), |
|
452 | - 'state' => __( 'State', 'invoicing' ), |
|
453 | - 'country' => __( 'Country', 'invoicing' ), |
|
454 | - 'zip' => __( 'Zipcode', 'invoicing' ), |
|
455 | - 'phone' => __( 'Phone', 'invoicing' ), |
|
456 | - 'company' => __( 'Company', 'invoicing' ), |
|
457 | - 'vat_number' => __( 'Vat Number', 'invoicing' ), |
|
458 | - 'ip' => __( 'IP', 'invoicing' ), |
|
459 | - 'gateway' => __( 'Gateway', 'invoicing' ), |
|
460 | - 'gateway_nicename' => __( 'Gateway Nicename', 'invoicing' ), |
|
461 | - 'transaction_id'=> __( 'Transaction ID', 'invoicing' ), |
|
434 | + 'id' => __('ID', 'invoicing'), |
|
435 | + 'number' => __('Number', 'invoicing'), |
|
436 | + 'date' => __('Date', 'invoicing'), |
|
437 | + 'due_date' => __('Due Date', 'invoicing'), |
|
438 | + 'completed_date'=> __('Payment Done Date', 'invoicing'), |
|
439 | + 'amount' => __('Amount', 'invoicing'), |
|
440 | + 'currency' => __('Currency', 'invoicing'), |
|
441 | + 'items' => __('Items', 'invoicing'), |
|
442 | + 'status_nicename' => __('Status Nicename', 'invoicing'), |
|
443 | + 'status' => __('Status', 'invoicing'), |
|
444 | + 'tax' => __('Tax', 'invoicing'), |
|
445 | + 'discount' => __('Discount', 'invoicing'), |
|
446 | + 'user_id' => __('User ID', 'invoicing'), |
|
447 | + 'email' => __('Email', 'invoicing'), |
|
448 | + 'first_name' => __('First Name', 'invoicing'), |
|
449 | + 'last_name' => __('Last Name', 'invoicing'), |
|
450 | + 'address' => __('Address', 'invoicing'), |
|
451 | + 'city' => __('City', 'invoicing'), |
|
452 | + 'state' => __('State', 'invoicing'), |
|
453 | + 'country' => __('Country', 'invoicing'), |
|
454 | + 'zip' => __('Zipcode', 'invoicing'), |
|
455 | + 'phone' => __('Phone', 'invoicing'), |
|
456 | + 'company' => __('Company', 'invoicing'), |
|
457 | + 'vat_number' => __('Vat Number', 'invoicing'), |
|
458 | + 'ip' => __('IP', 'invoicing'), |
|
459 | + 'gateway' => __('Gateway', 'invoicing'), |
|
460 | + 'gateway_nicename' => __('Gateway Nicename', 'invoicing'), |
|
461 | + 'transaction_id'=> __('Transaction ID', 'invoicing'), |
|
462 | 462 | ); |
463 | 463 | |
464 | 464 | return $columns; |
465 | 465 | } |
466 | 466 | |
467 | - public function get_invoices_data( $response = array() ) { |
|
467 | + public function get_invoices_data($response = array()) { |
|
468 | 468 | $args = array( |
469 | 469 | 'limit' => $this->per_page, |
470 | 470 | 'page' => $this->step, |
@@ -472,42 +472,42 @@ discard block |
||
472 | 472 | 'orderby' => 'date', |
473 | 473 | ); |
474 | 474 | |
475 | - if ( $this->status != 'any' ) { |
|
475 | + if ($this->status != 'any') { |
|
476 | 476 | $args['status'] = $this->status; |
477 | 477 | } else { |
478 | - $args['status'] = array_keys( wpinv_get_invoice_statuses( true ) ); |
|
478 | + $args['status'] = array_keys(wpinv_get_invoice_statuses(true)); |
|
479 | 479 | } |
480 | 480 | |
481 | - if ( !empty( $this->from_date ) || !empty( $this->to_date ) ) { |
|
481 | + if (!empty($this->from_date) || !empty($this->to_date)) { |
|
482 | 482 | $args['date_query'] = array( |
483 | 483 | array( |
484 | - 'after' => date( 'Y-n-d 00:00:00', strtotime( $this->from_date ) ), |
|
485 | - 'before' => date( 'Y-n-d 23:59:59', strtotime( $this->to_date ) ), |
|
484 | + 'after' => date('Y-n-d 00:00:00', strtotime($this->from_date)), |
|
485 | + 'before' => date('Y-n-d 23:59:59', strtotime($this->to_date)), |
|
486 | 486 | 'inclusive' => true |
487 | 487 | ) |
488 | 488 | ); |
489 | 489 | } |
490 | 490 | |
491 | - $invoices = wpinv_get_invoices( $args ); |
|
491 | + $invoices = wpinv_get_invoices($args); |
|
492 | 492 | |
493 | 493 | $data = array(); |
494 | 494 | |
495 | - if ( !empty( $invoices ) ) { |
|
496 | - foreach ( $invoices as $invoice ) { |
|
495 | + if (!empty($invoices)) { |
|
496 | + foreach ($invoices as $invoice) { |
|
497 | 497 | $items = $this->get_invoice_items($invoice); |
498 | 498 | $row = array( |
499 | 499 | 'id' => $invoice->ID, |
500 | 500 | 'number' => $invoice->get_number(), |
501 | - 'date' => $invoice->get_invoice_date( false ), |
|
502 | - 'due_date' => $invoice->get_due_date( false ), |
|
501 | + 'date' => $invoice->get_invoice_date(false), |
|
502 | + 'due_date' => $invoice->get_due_date(false), |
|
503 | 503 | 'completed_date'=> $invoice->get_completed_date(), |
504 | - 'amount' => wpinv_round_amount( $invoice->get_total() ), |
|
504 | + 'amount' => wpinv_round_amount($invoice->get_total()), |
|
505 | 505 | 'currency' => $invoice->get_currency(), |
506 | 506 | 'items' => $items, |
507 | - 'status_nicename' => $invoice->get_status( true ), |
|
507 | + 'status_nicename' => $invoice->get_status(true), |
|
508 | 508 | 'status' => $invoice->get_status(), |
509 | - 'tax' => $invoice->get_tax() > 0 ? wpinv_round_amount( $invoice->get_tax() ) : '', |
|
510 | - 'discount' => $invoice->get_discount() > 0 ? wpinv_round_amount( $invoice->get_discount() ) : '', |
|
509 | + 'tax' => $invoice->get_tax() > 0 ? wpinv_round_amount($invoice->get_tax()) : '', |
|
510 | + 'discount' => $invoice->get_discount() > 0 ? wpinv_round_amount($invoice->get_discount()) : '', |
|
511 | 511 | 'user_id' => $invoice->get_user_id(), |
512 | 512 | 'email' => $invoice->get_email(), |
513 | 513 | 'first_name' => $invoice->get_first_name(), |
@@ -526,7 +526,7 @@ discard block |
||
526 | 526 | 'transaction_id'=> $invoice->gateway ? $invoice->get_transaction_id() : '', |
527 | 527 | ); |
528 | 528 | |
529 | - $data[] = apply_filters( 'wpinv_export_invoice_row', $row, $invoice ); |
|
529 | + $data[] = apply_filters('wpinv_export_invoice_row', $row, $invoice); |
|
530 | 530 | } |
531 | 531 | |
532 | 532 | return $data; |
@@ -542,44 +542,44 @@ discard block |
||
542 | 542 | 'return' => 'ids', |
543 | 543 | ); |
544 | 544 | |
545 | - if ( $this->status != 'any' ) { |
|
545 | + if ($this->status != 'any') { |
|
546 | 546 | $args['status'] = $this->status; |
547 | 547 | } else { |
548 | - $args['status'] = array_keys( wpinv_get_invoice_statuses( true ) ); |
|
548 | + $args['status'] = array_keys(wpinv_get_invoice_statuses(true)); |
|
549 | 549 | } |
550 | 550 | |
551 | - if ( !empty( $this->from_date ) || !empty( $this->to_date ) ) { |
|
551 | + if (!empty($this->from_date) || !empty($this->to_date)) { |
|
552 | 552 | $args['date_query'] = array( |
553 | 553 | array( |
554 | - 'after' => date( 'Y-n-d 00:00:00', strtotime( $this->from_date ) ), |
|
555 | - 'before' => date( 'Y-n-d 23:59:59', strtotime( $this->to_date ) ), |
|
554 | + 'after' => date('Y-n-d 00:00:00', strtotime($this->from_date)), |
|
555 | + 'before' => date('Y-n-d 23:59:59', strtotime($this->to_date)), |
|
556 | 556 | 'inclusive' => true |
557 | 557 | ) |
558 | 558 | ); |
559 | 559 | } |
560 | 560 | |
561 | - $invoices = wpinv_get_invoices( $args ); |
|
562 | - $total = !empty( $invoices ) ? count( $invoices ) : 0; |
|
561 | + $invoices = wpinv_get_invoices($args); |
|
562 | + $total = !empty($invoices) ? count($invoices) : 0; |
|
563 | 563 | $status = 100; |
564 | 564 | |
565 | - if ( $total > 0 ) { |
|
566 | - $status = ( ( $this->per_page * $this->step ) / $total ) * 100; |
|
565 | + if ($total > 0) { |
|
566 | + $status = (($this->per_page * $this->step) / $total) * 100; |
|
567 | 567 | } |
568 | 568 | |
569 | - if ( $status > 100 ) { |
|
569 | + if ($status > 100) { |
|
570 | 570 | $status = 100; |
571 | 571 | } |
572 | 572 | |
573 | 573 | return $status; |
574 | 574 | } |
575 | 575 | |
576 | - public function get_invoice_items($invoice){ |
|
577 | - if(!$invoice){ |
|
576 | + public function get_invoice_items($invoice) { |
|
577 | + if (!$invoice) { |
|
578 | 578 | return ''; |
579 | 579 | } |
580 | 580 | |
581 | 581 | $cart_details = $invoice->get_cart_details(); |
582 | - if(!empty($cart_details)){ |
|
582 | + if (!empty($cart_details)) { |
|
583 | 583 | $cart_details = maybe_serialize($cart_details); |
584 | 584 | } else { |
585 | 585 | $cart_details = ''; |
@@ -1,7 +1,7 @@ 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_Payment_Form { |
@@ -11,23 +11,23 @@ discard block |
||
11 | 11 | * |
12 | 12 | * @param WP_Post $post |
13 | 13 | */ |
14 | - public static function output_details( $post ) { |
|
15 | - $details = get_post_meta( $post->ID, 'payment_form_data', true ); |
|
14 | + public static function output_details($post) { |
|
15 | + $details = get_post_meta($post->ID, 'payment_form_data', true); |
|
16 | 16 | |
17 | - if ( ! is_array( $details ) ) { |
|
17 | + if (!is_array($details)) { |
|
18 | 18 | return; |
19 | 19 | } |
20 | 20 | |
21 | 21 | echo '<div class="gdmbx2-wrap form-table"> <div class="gdmbx2-metabox gdmbx-field-list">'; |
22 | 22 | |
23 | - foreach ( $details as $key => $value ) { |
|
24 | - $key = sanitize_text_field( $key ); |
|
23 | + foreach ($details as $key => $value) { |
|
24 | + $key = sanitize_text_field($key); |
|
25 | 25 | |
26 | - if ( is_array( $value ) ) { |
|
27 | - $value = implode( ',', $value ); |
|
26 | + if (is_array($value)) { |
|
27 | + $value = implode(',', $value); |
|
28 | 28 | } |
29 | 29 | |
30 | - $value = esc_html( $value ); |
|
30 | + $value = esc_html($value); |
|
31 | 31 | |
32 | 32 | echo "<div class='gdmbx-row gdmbx-type-select'>"; |
33 | 33 | echo "<div class='gdmbx-th'><label>$key:</label></div>"; |
@@ -43,9 +43,9 @@ discard block |
||
43 | 43 | * |
44 | 44 | * @param WP_Post $post |
45 | 45 | */ |
46 | - public static function output_shortcode( $post ) { |
|
46 | + public static function output_shortcode($post) { |
|
47 | 47 | |
48 | - if ( ! is_numeric( $post ) ) { |
|
48 | + if (!is_numeric($post)) { |
|
49 | 49 | $post = $post->ID; |
50 | 50 | } |
51 | 51 | |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | * |
58 | 58 | * @param WP_Post $post |
59 | 59 | */ |
60 | - public static function output ( $post ) { |
|
61 | - $success_page = get_post_meta( $post->ID, 'wpinv_success_page', true ); |
|
62 | - $success_page = empty( $success_page ) ? wpinv_get_success_page_uri() : $success_page |
|
60 | + public static function output($post) { |
|
61 | + $success_page = get_post_meta($post->ID, 'wpinv_success_page', true); |
|
62 | + $success_page = empty($success_page) ? wpinv_get_success_page_uri() : $success_page |
|
63 | 63 | ?> |
64 | 64 | |
65 | 65 | <div id="wpinv-form-builder" style="display: flex; flex-flow: wrap;"> |
@@ -67,20 +67,20 @@ discard block |
||
67 | 67 | <div class="wpinv-form-builder-left bsui" style="flex: 0 0 320px;"> |
68 | 68 | <ul class="wpinv-form-builder-tabs nav nav-tabs"> |
69 | 69 | <li class='nav-item' v-if="active_tab!='new_item'"> |
70 | - <a @click.prevent="active_tab='new_item'" class="nav-link p-3" :class="{ 'active': active_tab=='new_item' }" href="#"><?php _e( 'Add new element', 'invoicing' ); ?></a> |
|
70 | + <a @click.prevent="active_tab='new_item'" class="nav-link p-3" :class="{ 'active': active_tab=='new_item' }" href="#"><?php _e('Add new element', 'invoicing'); ?></a> |
|
71 | 71 | </li> |
72 | 72 | <li class='nav-item' v-if='false'> |
73 | - <a @click.prevent="active_tab='edit_item'" class="nav-link p-3" :class="{ 'active': active_tab=='edit_item' }" href="#"><?php _e( 'Edit element', 'invoicing' ); ?></a> |
|
73 | + <a @click.prevent="active_tab='edit_item'" class="nav-link p-3" :class="{ 'active': active_tab=='edit_item' }" href="#"><?php _e('Edit element', 'invoicing'); ?></a> |
|
74 | 74 | </li> |
75 | 75 | <li class='nav-item' v-if='false'> |
76 | - <a @click.prevent="active_tab='settings'" class="nav-link p-3" :class="{ 'active': active_tab=='settings' }" href="#"><?php _e( 'Settings', 'invoicing' ); ?></a> |
|
76 | + <a @click.prevent="active_tab='settings'" class="nav-link p-3" :class="{ 'active': active_tab=='settings' }" href="#"><?php _e('Settings', 'invoicing'); ?></a> |
|
77 | 77 | </li> |
78 | 78 | </ul> |
79 | 79 | |
80 | 80 | <div class="wpinv-form-builder-tab-content bsui" style="margin-top: 16px;"> |
81 | 81 | <div class="wpinv-form-builder-tab-pane" v-if="active_tab=='new_item'"> |
82 | 82 | <div class="wpinv-form-builder-add-field-types"> |
83 | - <small class='form-text text-muted'><?php _e( 'Add an element by dragging it to the payment form.', 'invoicing' ); ?></small> |
|
83 | + <small class='form-text text-muted'><?php _e('Add an element by dragging it to the payment form.', 'invoicing'); ?></small> |
|
84 | 84 | <draggable class="section mt-2" style="display: flex; flex-flow: wrap; justify-content: space-between;" v-model="elements" :group="{ name: 'fields', pull: 'clone', put: false }" :sort="false" :clone="addDraggedField" tag="ul" filter=".wpinv-undraggable"> |
85 | 85 | <li v-for="element in elements" class= "wpinv-payment-form-left-fields-field" @click.prevent="addField(element)" :class="{ 'd-none': element.defaults.premade }"> |
86 | 86 | <button class="button btn"> |
@@ -95,9 +95,9 @@ discard block |
||
95 | 95 | |
96 | 96 | <div class="wpinv-form-builder-tab-pane bsui" v-if="active_tab=='edit_item'" style="font-size: 16px;"> |
97 | 97 | <div class="wpinv-form-builder-edit-field-wrapper"> |
98 | - <?php do_action( 'wpinv_payment_form_edit_element_template', 'active_form_element', $post ); ?> |
|
98 | + <?php do_action('wpinv_payment_form_edit_element_template', 'active_form_element', $post); ?> |
|
99 | 99 | <div> |
100 | - <button type="button" class="button button-link button-link-delete" @click.prevent="removeField(active_form_element)" v-show="! active_form_element.premade"><?php _e( 'Delete Field', 'invoicing' ); ?></button> |
|
100 | + <button type="button" class="button button-link button-link-delete" @click.prevent="removeField(active_form_element)" v-show="! active_form_element.premade"><?php _e('Delete Field', 'invoicing'); ?></button> |
|
101 | 101 | </div> |
102 | 102 | </div> |
103 | 103 | </div> |
@@ -106,9 +106,9 @@ discard block |
||
106 | 106 | <div class="wpinv-form-builder-settings-wrapper"> |
107 | 107 | |
108 | 108 | <div class='form-group'> |
109 | - <label for="wpi-success-page"><?php _e( 'Success Page', 'invoicing' ); ?></label> |
|
110 | - <input placeholder="https://" id='wpi-success-page' value="<?php echo esc_url( $success_page ); ?>" class='form-control' type='text'> |
|
111 | - <small class='form-text text-muted'><?php _e( 'Where should we redirect users after successfuly completing their payment?', 'invoicing' ); ?></small> |
|
109 | + <label for="wpi-success-page"><?php _e('Success Page', 'invoicing'); ?></label> |
|
110 | + <input placeholder="https://" id='wpi-success-page' value="<?php echo esc_url($success_page); ?>" class='form-control' type='text'> |
|
111 | + <small class='form-text text-muted'><?php _e('Where should we redirect users after successfuly completing their payment?', 'invoicing'); ?></small> |
|
112 | 112 | </div> |
113 | 113 | |
114 | 114 | </div> |
@@ -119,12 +119,12 @@ discard block |
||
119 | 119 | |
120 | 120 | <div class="wpinv-form-builder-right" style="flex: 1; padding-top: 40px;border-left: 1px solid #ddd;padding-left: 20px;min-height: 520px;margin-left: 10px;"> |
121 | 121 | |
122 | - <small class='form-text text-muted' v-if='form_elements.length'><?php _e( 'Click on any element to edit or delete it.', 'invoicing' ); ?></small> |
|
123 | - <p class='form-text text-muted' v-if='! form_elements.length'><?php _e( 'This form is empty. Add new elements by dragging them from the right.', 'invoicing' ); ?></p> |
|
122 | + <small class='form-text text-muted' v-if='form_elements.length'><?php _e('Click on any element to edit or delete it.', 'invoicing'); ?></small> |
|
123 | + <p class='form-text text-muted' v-if='! form_elements.length'><?php _e('This form is empty. Add new elements by dragging them from the right.', 'invoicing'); ?></p> |
|
124 | 124 | |
125 | 125 | <draggable class="section bsui" v-model="form_elements" @add="highlightLastDroppedField" group="fields" tag="div" style="min-height: 100%; font-size: 16px;"> |
126 | 126 | <div v-for="form_element in form_elements" class="wpinv-form-builder-element-preview" :class="{ active: active_form_element==form_element && active_tab=='edit_item' }" @click="active_tab = 'edit_item'; active_form_element = form_element"> |
127 | - <?php do_action( 'wpinv_payment_form_render_element_template', 'form_element', $post ); ?> |
|
127 | + <?php do_action('wpinv_payment_form_render_element_template', 'form_element', $post); ?> |
|
128 | 128 | </div> |
129 | 129 | </draggable> |
130 | 130 | </div> |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | <textarea style="display:none;" name="wpinv_form_items" v-model="itemString"></textarea> |
134 | 134 | </div> |
135 | 135 | |
136 | - <?php wp_nonce_field( 'wpinv_save_payment_form', 'wpinv_save_payment_form' ) ;?> |
|
136 | + <?php wp_nonce_field('wpinv_save_payment_form', 'wpinv_save_payment_form'); ?> |
|
137 | 137 | |
138 | 138 | <?php |
139 | 139 | } |
@@ -141,86 +141,86 @@ discard block |
||
141 | 141 | /** |
142 | 142 | * Saves our payment forms. |
143 | 143 | */ |
144 | - public static function save( $post_id, $post ) { |
|
144 | + public static function save($post_id, $post) { |
|
145 | 145 | |
146 | - remove_action( 'save_post', 'WPInv_Meta_Box_Payment_Form::save' ); |
|
146 | + remove_action('save_post', 'WPInv_Meta_Box_Payment_Form::save'); |
|
147 | 147 | |
148 | 148 | // $post_id and $post are required. |
149 | - if ( empty( $post_id ) || empty( $post ) ) { |
|
149 | + if (empty($post_id) || empty($post)) { |
|
150 | 150 | return; |
151 | 151 | } |
152 | 152 | |
153 | 153 | // Ensure that this user can edit the post. |
154 | - if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
154 | + if (!current_user_can('edit_post', $post_id)) { |
|
155 | 155 | return; |
156 | 156 | } |
157 | 157 | |
158 | 158 | // Dont' save meta boxes for revisions or autosaves |
159 | - if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
159 | + if (defined('DOING_AUTOSAVE') || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) { |
|
160 | 160 | return; |
161 | 161 | } |
162 | 162 | |
163 | 163 | // Do not save for ajax requests. |
164 | - if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
164 | + if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) { |
|
165 | 165 | return; |
166 | 166 | } |
167 | 167 | |
168 | 168 | // Confirm the security nonce. |
169 | - if ( empty( $_POST['wpinv_save_payment_form'] ) || ! wp_verify_nonce( $_POST['wpinv_save_payment_form'], 'wpinv_save_payment_form' ) ) { |
|
169 | + if (empty($_POST['wpinv_save_payment_form']) || !wp_verify_nonce($_POST['wpinv_save_payment_form'], 'wpinv_save_payment_form')) { |
|
170 | 170 | return; |
171 | 171 | } |
172 | 172 | |
173 | 173 | // Save form items. |
174 | - $form_items = json_decode( wp_unslash( $_POST['wpinv_form_items'] ), true ); |
|
174 | + $form_items = json_decode(wp_unslash($_POST['wpinv_form_items']), true); |
|
175 | 175 | |
176 | - if ( empty( $form_items ) ) { |
|
176 | + if (empty($form_items)) { |
|
177 | 177 | $form_items = array(); |
178 | 178 | } |
179 | 179 | |
180 | - update_post_meta( $post_id, 'wpinv_form_items', self::maybe_save_items( $form_items ) ); |
|
180 | + update_post_meta($post_id, 'wpinv_form_items', self::maybe_save_items($form_items)); |
|
181 | 181 | |
182 | 182 | // Save form elements. |
183 | - $wpinv_form_elements = json_decode( wp_unslash( $_POST['wpinv_form_elements'] ), true ); |
|
184 | - if ( empty( $wpinv_form_elements ) ) { |
|
183 | + $wpinv_form_elements = json_decode(wp_unslash($_POST['wpinv_form_elements']), true); |
|
184 | + if (empty($wpinv_form_elements)) { |
|
185 | 185 | $wpinv_form_elements = array(); |
186 | 186 | } |
187 | 187 | |
188 | - update_post_meta( $post_id, 'wpinv_form_elements', $wpinv_form_elements ); |
|
188 | + update_post_meta($post_id, 'wpinv_form_elements', $wpinv_form_elements); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
192 | 192 | * Saves unsaved form items. |
193 | 193 | */ |
194 | - public static function maybe_save_items( $items ) { |
|
194 | + public static function maybe_save_items($items) { |
|
195 | 195 | |
196 | 196 | $saved = array(); |
197 | 197 | |
198 | - foreach( $items as $item ) { |
|
198 | + foreach ($items as $item) { |
|
199 | 199 | |
200 | - if ( is_numeric( $item['id'] ) ) { |
|
200 | + if (is_numeric($item['id'])) { |
|
201 | 201 | $saved[] = $item; |
202 | 202 | continue; |
203 | 203 | } |
204 | 204 | |
205 | 205 | $data = array( |
206 | - 'post_title' => sanitize_text_field( $item['title'] ), |
|
207 | - 'post_excerpt' => wp_kses_post( $item['description'] ), |
|
206 | + 'post_title' => sanitize_text_field($item['title']), |
|
207 | + 'post_excerpt' => wp_kses_post($item['description']), |
|
208 | 208 | 'post_status' => 'publish', |
209 | 209 | 'meta' => array( |
210 | - 'type' => empty( $item['type'] ) ? 'custom' : $item['type'] , |
|
211 | - 'price' => wpinv_sanitize_amount( $item['price'] ), |
|
212 | - 'vat_rule' => empty( $item['rule'] ) ? 'digital' : $item['rule'], |
|
213 | - 'vat_class' => empty( $item['class'] ) ? '_standard' : $item['class'], |
|
210 | + 'type' => empty($item['type']) ? 'custom' : $item['type'], |
|
211 | + 'price' => wpinv_sanitize_amount($item['price']), |
|
212 | + 'vat_rule' => empty($item['rule']) ? 'digital' : $item['rule'], |
|
213 | + 'vat_class' => empty($item['class']) ? '_standard' : $item['class'], |
|
214 | 214 | ) |
215 | 215 | ); |
216 | 216 | |
217 | - $new_item = new WPInv_Item(); |
|
218 | - $new_item->create( $data ); |
|
217 | + $new_item = new WPInv_Item(); |
|
218 | + $new_item->create($data); |
|
219 | 219 | |
220 | - if ( ! empty( $new_item ) ) { |
|
220 | + if (!empty($new_item)) { |
|
221 | 221 | $item['id'] = $new_item->ID; |
222 | - unset( $item['new'] ); |
|
223 | - unset( $item['type'] ); |
|
222 | + unset($item['new']); |
|
223 | + unset($item['type']); |
|
224 | 224 | $saved[] = $item; |
225 | 225 | } |
226 | 226 | |
@@ -232,5 +232,5 @@ discard block |
||
232 | 232 | |
233 | 233 | } |
234 | 234 | |
235 | -add_action( 'save_post_wpi_payment_form', 'WPInv_Meta_Box_Payment_Form::save', 10, 2 ); |
|
235 | +add_action('save_post_wpi_payment_form', 'WPInv_Meta_Box_Payment_Form::save', 10, 2); |
|
236 | 236 |