@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * All Invoicing extensions screen related functions can be found here. |
6 | 6 | * |
7 | 7 | */ |
8 | -if ( ! defined( 'ABSPATH' ) ) { |
|
8 | +if (!defined('ABSPATH')) { |
|
9 | 9 | exit; |
10 | 10 | } |
11 | 11 | |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | * |
21 | 21 | * @return array of tabs. |
22 | 22 | */ |
23 | - public function get_tabs(){ |
|
23 | + public function get_tabs() { |
|
24 | 24 | $tabs = array( |
25 | 25 | 'addons' => __("Addons", "invoicing"), |
26 | 26 | 'gateways' => __("Payment Gateways", "invoicing"), |
@@ -38,28 +38,28 @@ discard block |
||
38 | 38 | * |
39 | 39 | * @return array |
40 | 40 | */ |
41 | - public function get_section_data( $section_id ) { |
|
42 | - $section = self::get_tab( $section_id ); |
|
41 | + public function get_section_data($section_id) { |
|
42 | + $section = self::get_tab($section_id); |
|
43 | 43 | $api_url = "https://wpinvoicing.com/edd-api/v2/products/"; |
44 | 44 | $section_data = new stdClass(); |
45 | 45 | |
46 | - if($section_id=='recommended_plugins'){ |
|
46 | + if ($section_id == 'recommended_plugins') { |
|
47 | 47 | $section_data->products = self::get_recommend_wp_plugins_edd_formatted(); |
48 | 48 | } |
49 | - elseif ( ! empty( $section ) ) { |
|
50 | - if ( false === ( $section_data = get_transient( 'wpi_addons_section_' . $section_id ) ) ) { //@todo restore after testing |
|
49 | + elseif (!empty($section)) { |
|
50 | + if (false === ($section_data = get_transient('wpi_addons_section_' . $section_id))) { //@todo restore after testing |
|
51 | 51 | //if ( 1==1) { |
52 | 52 | |
53 | - $query_args = array( 'category' => $section_id, 'number' => 100); |
|
54 | - $query_args = apply_filters('wpeu_edd_api_query_args',$query_args,$api_url,$section_id); |
|
53 | + $query_args = array('category' => $section_id, 'number' => 100); |
|
54 | + $query_args = apply_filters('wpeu_edd_api_query_args', $query_args, $api_url, $section_id); |
|
55 | 55 | |
56 | - $raw_section = wp_safe_remote_get( esc_url_raw( add_query_arg($query_args ,$api_url) ), array( 'user-agent' => 'Invoicing Addons Page','timeout' => 15, ) ); |
|
56 | + $raw_section = wp_safe_remote_get(esc_url_raw(add_query_arg($query_args, $api_url)), array('user-agent' => 'Invoicing Addons Page', 'timeout' => 15,)); |
|
57 | 57 | |
58 | - if ( ! is_wp_error( $raw_section ) ) { |
|
59 | - $section_data = json_decode( wp_remote_retrieve_body( $raw_section ) ); |
|
58 | + if (!is_wp_error($raw_section)) { |
|
59 | + $section_data = json_decode(wp_remote_retrieve_body($raw_section)); |
|
60 | 60 | |
61 | - if ( ! empty( $section_data->products ) ) { |
|
62 | - set_transient( 'wpi_addons_section_' . $section_id, $section_data, DAY_IN_SECONDS ); |
|
61 | + if (!empty($section_data->products)) { |
|
62 | + set_transient('wpi_addons_section_' . $section_id, $section_data, DAY_IN_SECONDS); |
|
63 | 63 | } |
64 | 64 | } |
65 | 65 | } |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | |
68 | 68 | $products = isset($section_data->products) ? $section_data->products : ''; |
69 | 69 | |
70 | - return apply_filters( 'wpi_addons_section_data', $products, $section_id ); |
|
70 | + return apply_filters('wpi_addons_section_data', $products, $section_id); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
@@ -78,8 +78,8 @@ discard block |
||
78 | 78 | * @param string $theme |
79 | 79 | * @param string $plugin |
80 | 80 | */ |
81 | - public function output_button( $addon ) { |
|
82 | - $current_tab = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] ); |
|
81 | + public function output_button($addon) { |
|
82 | + $current_tab = empty($_GET['tab']) ? 'addons' : sanitize_title($_GET['tab']); |
|
83 | 83 | // $button_text = __('Free','invoicing'); |
84 | 84 | // $licensing = false; |
85 | 85 | // $installed = false; |
@@ -91,14 +91,14 @@ discard block |
||
91 | 91 | // $install_status = 'get'; |
92 | 92 | // $onclick = ''; |
93 | 93 | |
94 | - $wp_org_themes = array('supreme-directory','directory-starter'); |
|
94 | + $wp_org_themes = array('supreme-directory', 'directory-starter'); |
|
95 | 95 | |
96 | 96 | $button_args = array( |
97 | - 'type' => ($current_tab == 'addons' || $current_tab =='gateways') ? 'addons' : $current_tab, |
|
97 | + 'type' => ($current_tab == 'addons' || $current_tab == 'gateways') ? 'addons' : $current_tab, |
|
98 | 98 | 'id' => isset($addon->info->id) ? absint($addon->info->id) : '', |
99 | 99 | 'title' => isset($addon->info->title) ? $addon->info->title : '', |
100 | - 'button_text' => __('Free','invoicing'), |
|
101 | - 'price_text' => __('Free','invoicing'), |
|
100 | + 'button_text' => __('Free', 'invoicing'), |
|
101 | + 'price_text' => __('Free', 'invoicing'), |
|
102 | 102 | 'link' => isset($addon->info->link) ? $addon->info->link : '', // link to product |
103 | 103 | 'url' => isset($addon->info->link) ? $addon->info->link : '', // button url |
104 | 104 | 'class' => 'button-primary', |
@@ -114,83 +114,83 @@ discard block |
||
114 | 114 | 'update_url' => '', |
115 | 115 | ); |
116 | 116 | |
117 | - if( ($current_tab == 'addons' || $current_tab =='gateways') && isset($addon->info->id) && $addon->info->id){ |
|
118 | - include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api.. |
|
119 | - if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;} |
|
117 | + if (($current_tab == 'addons' || $current_tab == 'gateways') && isset($addon->info->id) && $addon->info->id) { |
|
118 | + include_once(ABSPATH . 'wp-admin/includes/plugin-install.php'); //for plugins_api.. |
|
119 | + if (!empty($addon->licensing->edd_slug)) {$button_args['slug'] = $addon->licensing->edd_slug; } |
|
120 | 120 | $status = self::install_plugin_install_status($addon); |
121 | 121 | $button_args['file'] = isset($status['file']) ? $status['file'] : ''; |
122 | - if(isset($status['status'])){$button_args['install_status'] = $status['status'];} |
|
122 | + if (isset($status['status'])) {$button_args['install_status'] = $status['status']; } |
|
123 | 123 | $button_args['update_url'] = "https://wpinvoicing.com"; |
124 | - }elseif($current_tab == 'themes' && isset($addon->info->id) && $addon->info->id) { |
|
125 | - if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;} |
|
124 | + }elseif ($current_tab == 'themes' && isset($addon->info->id) && $addon->info->id) { |
|
125 | + if (!empty($addon->licensing->edd_slug)) {$button_args['slug'] = $addon->licensing->edd_slug; } |
|
126 | 126 | $button_args['installed'] = self::is_theme_installed($addon); |
127 | - if(!in_array($button_args['slug'],$wp_org_themes)){ |
|
127 | + if (!in_array($button_args['slug'], $wp_org_themes)) { |
|
128 | 128 | $button_args['update_url'] = "https://wpinvoicing.com"; |
129 | 129 | } |
130 | - }elseif($current_tab == 'recommended_plugins' && isset($addon->info->slug) && $addon->info->slug){ |
|
131 | - include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api.. |
|
132 | - $status = install_plugin_install_status(array("slug"=>$button_args['slug'],"version"=>"")); |
|
130 | + }elseif ($current_tab == 'recommended_plugins' && isset($addon->info->slug) && $addon->info->slug) { |
|
131 | + include_once(ABSPATH . 'wp-admin/includes/plugin-install.php'); //for plugins_api.. |
|
132 | + $status = install_plugin_install_status(array("slug"=>$button_args['slug'], "version"=>"")); |
|
133 | 133 | $button_args['install_status'] = isset($status['status']) ? $status['status'] : 'install'; |
134 | 134 | $button_args['file'] = isset($status['file']) ? $status['file'] : ''; |
135 | 135 | } |
136 | 136 | |
137 | 137 | // set price |
138 | - if(isset($addon->pricing) && !empty($addon->pricing)){ |
|
139 | - if(is_object($addon->pricing)){ |
|
140 | - $prices = (Array)$addon->pricing; |
|
138 | + if (isset($addon->pricing) && !empty($addon->pricing)) { |
|
139 | + if (is_object($addon->pricing)) { |
|
140 | + $prices = (Array) $addon->pricing; |
|
141 | 141 | $button_args['price'] = reset($prices); |
142 | - }elseif(isset($addon->pricing)){ |
|
142 | + }elseif (isset($addon->pricing)) { |
|
143 | 143 | $button_args['price'] = $addon->pricing; |
144 | 144 | } |
145 | 145 | } |
146 | 146 | |
147 | 147 | // set price text |
148 | - if( $button_args['price'] && $button_args['price'] != '0.00' ){ |
|
149 | - $button_args['price_text'] = sprintf( __('From: $%d', 'invoicing'), $button_args['price']); |
|
148 | + if ($button_args['price'] && $button_args['price'] != '0.00') { |
|
149 | + $button_args['price_text'] = sprintf(__('From: $%d', 'invoicing'), $button_args['price']); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | |
153 | 153 | // set if installed |
154 | - if(in_array($button_args['install_status'], array('installed','latest_installed','update_available','newer_installed'))){ |
|
154 | + if (in_array($button_args['install_status'], array('installed', 'latest_installed', 'update_available', 'newer_installed'))) { |
|
155 | 155 | $button_args['installed'] = true; |
156 | 156 | } |
157 | 157 | |
158 | 158 | // print_r($button_args); |
159 | 159 | // set if active |
160 | - if($button_args['installed'] && ($button_args['file'] || $button_args['type'] == 'themes')){ |
|
161 | - if($button_args['type'] != 'themes'){ |
|
160 | + if ($button_args['installed'] && ($button_args['file'] || $button_args['type'] == 'themes')) { |
|
161 | + if ($button_args['type'] != 'themes') { |
|
162 | 162 | $button_args['active'] = is_plugin_active($button_args['file']); |
163 | - }else{ |
|
163 | + } else { |
|
164 | 164 | $button_args['active'] = self::is_theme_active($addon); |
165 | 165 | } |
166 | 166 | } |
167 | 167 | |
168 | 168 | // set button text and class |
169 | - if($button_args['active']){ |
|
170 | - $button_args['button_text'] = __('Active','invoicing'); |
|
169 | + if ($button_args['active']) { |
|
170 | + $button_args['button_text'] = __('Active', 'invoicing'); |
|
171 | 171 | $button_args['class'] = ' button-secondary disabled '; |
172 | - }elseif($button_args['installed']){ |
|
173 | - $button_args['button_text'] = __('Activate','invoicing'); |
|
172 | + }elseif ($button_args['installed']) { |
|
173 | + $button_args['button_text'] = __('Activate', 'invoicing'); |
|
174 | 174 | |
175 | - if($button_args['type'] != 'themes'){ |
|
176 | - if ( current_user_can( 'manage_options' ) ) { |
|
177 | - $button_args['url'] = wp_nonce_url(admin_url('plugins.php?action=activate&plugin='.$button_args['file']), 'activate-plugin_' . $button_args['file']); |
|
178 | - }else{ |
|
175 | + if ($button_args['type'] != 'themes') { |
|
176 | + if (current_user_can('manage_options')) { |
|
177 | + $button_args['url'] = wp_nonce_url(admin_url('plugins.php?action=activate&plugin=' . $button_args['file']), 'activate-plugin_' . $button_args['file']); |
|
178 | + } else { |
|
179 | 179 | $button_args['url'] = '#'; |
180 | 180 | } |
181 | - }else{ |
|
182 | - if ( current_user_can( 'switch_themes' ) ) { |
|
181 | + } else { |
|
182 | + if (current_user_can('switch_themes')) { |
|
183 | 183 | $button_args['url'] = self::get_theme_activation_url($addon); |
184 | - }else{ |
|
184 | + } else { |
|
185 | 185 | $button_args['url'] = '#'; |
186 | 186 | } |
187 | 187 | } |
188 | 188 | |
189 | - }else{ |
|
190 | - if($button_args['type'] == 'recommended_plugins'){ |
|
191 | - $button_args['button_text'] = __('Install','invoicing'); |
|
192 | - }else{ |
|
193 | - $button_args['button_text'] = __('Get it','invoicing'); |
|
189 | + } else { |
|
190 | + if ($button_args['type'] == 'recommended_plugins') { |
|
191 | + $button_args['button_text'] = __('Install', 'invoicing'); |
|
192 | + } else { |
|
193 | + $button_args['button_text'] = __('Get it', 'invoicing'); |
|
194 | 194 | |
195 | 195 | /*if($button_args['type'] == 'themes' && in_array($button_args['slug'],$wp_org_themes) ){ |
196 | 196 | $button_args['button_text'] = __('Install','invoicing'); |
@@ -203,45 +203,45 @@ discard block |
||
203 | 203 | |
204 | 204 | |
205 | 205 | // filter the button arguments |
206 | - $button_args = apply_filters('edd_api_button_args',$button_args); |
|
206 | + $button_args = apply_filters('edd_api_button_args', $button_args); |
|
207 | 207 | // print_r($button_args); |
208 | 208 | // set price text |
209 | - if(isset($button_args['price_text'])){ |
|
209 | + if (isset($button_args['price_text'])) { |
|
210 | 210 | ?> |
211 | 211 | <a |
212 | 212 | target="_blank" |
213 | 213 | class="addons-price-text" |
214 | - href="<?php echo esc_url( $button_args['link'] ); ?>"> |
|
215 | - <?php echo esc_html( $button_args['price_text'] ); ?> |
|
214 | + href="<?php echo esc_url($button_args['link']); ?>"> |
|
215 | + <?php echo esc_html($button_args['price_text']); ?> |
|
216 | 216 | </a> |
217 | 217 | <?php |
218 | 218 | } |
219 | 219 | |
220 | 220 | |
221 | 221 | $target = ''; |
222 | - if ( ! empty( $button_args['url'] ) ) { |
|
222 | + if (!empty($button_args['url'])) { |
|
223 | 223 | $target = strpos($button_args['url'], get_site_url()) !== false ? '' : ' target="_blank" '; |
224 | 224 | } |
225 | 225 | |
226 | 226 | ?> |
227 | 227 | <a |
228 | - data-licence="<?php echo esc_attr($button_args['license']);?>" |
|
229 | - data-licensing="<?php echo $button_args['licensing'] ? 1 : 0;?>" |
|
230 | - data-title="<?php echo esc_attr($button_args['title']);?>" |
|
231 | - data-type="<?php echo esc_attr($button_args['type']);?>" |
|
232 | - data-text-error-message="<?php _e('Something went wrong!','invoicing');?>" |
|
233 | - data-text-activate="<?php _e('Activate','invoicing');?>" |
|
234 | - data-text-activating="<?php _e('Activating','invoicing');?>" |
|
235 | - data-text-deactivate="<?php _e('Deactivate','invoicing');?>" |
|
236 | - data-text-installed="<?php _e('Installed','invoicing');?>" |
|
237 | - data-text-install="<?php _e('Install','invoicing');?>" |
|
238 | - data-text-installing="<?php _e('Installing','invoicing');?>" |
|
239 | - data-text-error="<?php _e('Error','invoicing');?>" |
|
240 | - <?php if(!empty($button_args['onclick'])){echo " onclick='".$button_args['onclick']."' ";}?> |
|
241 | - <?php echo $target;?> |
|
242 | - class="addons-button <?php echo esc_attr( $button_args['class'] ); ?>" |
|
243 | - href="<?php echo esc_url( $button_args['url'] ); ?>"> |
|
244 | - <?php echo esc_html( $button_args['button_text'] ); ?> |
|
228 | + data-licence="<?php echo esc_attr($button_args['license']); ?>" |
|
229 | + data-licensing="<?php echo $button_args['licensing'] ? 1 : 0; ?>" |
|
230 | + data-title="<?php echo esc_attr($button_args['title']); ?>" |
|
231 | + data-type="<?php echo esc_attr($button_args['type']); ?>" |
|
232 | + data-text-error-message="<?php _e('Something went wrong!', 'invoicing'); ?>" |
|
233 | + data-text-activate="<?php _e('Activate', 'invoicing'); ?>" |
|
234 | + data-text-activating="<?php _e('Activating', 'invoicing'); ?>" |
|
235 | + data-text-deactivate="<?php _e('Deactivate', 'invoicing'); ?>" |
|
236 | + data-text-installed="<?php _e('Installed', 'invoicing'); ?>" |
|
237 | + data-text-install="<?php _e('Install', 'invoicing'); ?>" |
|
238 | + data-text-installing="<?php _e('Installing', 'invoicing'); ?>" |
|
239 | + data-text-error="<?php _e('Error', 'invoicing'); ?>" |
|
240 | + <?php if (!empty($button_args['onclick'])) {echo " onclick='" . $button_args['onclick'] . "' "; }?> |
|
241 | + <?php echo $target; ?> |
|
242 | + class="addons-button <?php echo esc_attr($button_args['class']); ?>" |
|
243 | + href="<?php echo esc_url($button_args['url']); ?>"> |
|
244 | + <?php echo esc_html($button_args['button_text']); ?> |
|
245 | 245 | </a> |
246 | 246 | <?php |
247 | 247 | |
@@ -256,35 +256,35 @@ discard block |
||
256 | 256 | $tabs = self::get_tabs(); |
257 | 257 | $sections = self::get_sections(); |
258 | 258 | $theme = wp_get_theme(); |
259 | - $section_keys = array_keys( $sections ); |
|
260 | - $current_section = isset( $_GET['section'] ) ? sanitize_text_field( $_GET['section'] ) : current( $section_keys ); |
|
261 | - $current_tab = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] ); |
|
262 | - include_once( WPINV_PLUGIN_DIR . '/includes/admin/html-admin-page-addons.php' ); |
|
259 | + $section_keys = array_keys($sections); |
|
260 | + $current_section = isset($_GET['section']) ? sanitize_text_field($_GET['section']) : current($section_keys); |
|
261 | + $current_tab = empty($_GET['tab']) ? 'addons' : sanitize_title($_GET['tab']); |
|
262 | + include_once(WPINV_PLUGIN_DIR . '/includes/admin/html-admin-page-addons.php'); |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | /** |
266 | 266 | * A list of recommended wp.org plugins. |
267 | 267 | * @return array |
268 | 268 | */ |
269 | - public function get_recommend_wp_plugins(){ |
|
269 | + public function get_recommend_wp_plugins() { |
|
270 | 270 | $plugins = array( |
271 | 271 | 'invoicing-quotes' => array( |
272 | 272 | 'url' => 'https://wordpress.org/plugins/invoicing-quotes/', |
273 | 273 | 'slug' => 'invoicing-quotes', |
274 | 274 | 'name' => 'Quotes', |
275 | - 'desc' => __('Allows you to create quotes, send them to clients and convert them to Invoices when accepted by the customer.','invoicing'), |
|
275 | + 'desc' => __('Allows you to create quotes, send them to clients and convert them to Invoices when accepted by the customer.', 'invoicing'), |
|
276 | 276 | ), |
277 | 277 | 'geodirectory' => array( |
278 | 278 | 'url' => 'https://wordpress.org/plugins/geodirectory/', |
279 | 279 | 'slug' => 'geodirectory', |
280 | 280 | 'name' => 'GeoDirectory', |
281 | - 'desc' => __('Turn any WordPress theme into a global business directory portal.','invoicing'), |
|
281 | + 'desc' => __('Turn any WordPress theme into a global business directory portal.', 'invoicing'), |
|
282 | 282 | ), |
283 | 283 | 'userswp' => array( |
284 | 284 | 'url' => 'https://wordpress.org/plugins/userswp/', |
285 | 285 | 'slug' => 'userswp', |
286 | 286 | 'name' => 'UsersWP', |
287 | - 'desc' => __('Allow frontend user login and registration as well as have slick profile pages.','invoicing'), |
|
287 | + 'desc' => __('Allow frontend user login and registration as well as have slick profile pages.', 'invoicing'), |
|
288 | 288 | ), |
289 | 289 | ); |
290 | 290 |
@@ -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 | function wpinv_init_transactional_emails() { |
15 | - $email_actions = apply_filters( 'wpinv_email_actions', array( |
|
15 | + $email_actions = apply_filters('wpinv_email_actions', array( |
|
16 | 16 | 'wpinv_status_wpi-pending_to_wpi-processing', |
17 | 17 | 'wpinv_status_wpi-pending_to_publish', |
18 | 18 | 'wpinv_status_wpi-pending_to_wpi-cancelled', |
@@ -30,381 +30,381 @@ discard block |
||
30 | 30 | 'wpinv_fully_refunded', |
31 | 31 | 'wpinv_partially_refunded', |
32 | 32 | 'wpinv_new_invoice_note' |
33 | - ) ); |
|
33 | + )); |
|
34 | 34 | |
35 | - foreach ( $email_actions as $action ) { |
|
36 | - add_action( $action, 'wpinv_send_transactional_email', 10, 10 ); |
|
35 | + foreach ($email_actions as $action) { |
|
36 | + add_action($action, 'wpinv_send_transactional_email', 10, 10); |
|
37 | 37 | } |
38 | 38 | } |
39 | -add_action( 'init', 'wpinv_init_transactional_emails' ); |
|
39 | +add_action('init', 'wpinv_init_transactional_emails'); |
|
40 | 40 | |
41 | 41 | // New invoice email |
42 | -add_action( 'wpinv_status_wpi-pending_to_wpi-processing_notification', 'wpinv_new_invoice_notification' ); |
|
43 | -add_action( 'wpinv_status_wpi-pending_to_publish_notification', 'wpinv_new_invoice_notification' ); |
|
44 | -add_action( 'wpinv_status_wpi-pending_to_wpi-onhold_notification', 'wpinv_new_invoice_notification' ); |
|
45 | -add_action( 'wpinv_status_wpi-failed_to_wpi-processing_notification', 'wpinv_new_invoice_notification' ); |
|
46 | -add_action( 'wpinv_status_wpi-failed_to_publish_notification', 'wpinv_new_invoice_notification' ); |
|
47 | -add_action( 'wpinv_status_wpi-failed_to_wpi-onhold_notification', 'wpinv_new_invoice_notification' ); |
|
42 | +add_action('wpinv_status_wpi-pending_to_wpi-processing_notification', 'wpinv_new_invoice_notification'); |
|
43 | +add_action('wpinv_status_wpi-pending_to_publish_notification', 'wpinv_new_invoice_notification'); |
|
44 | +add_action('wpinv_status_wpi-pending_to_wpi-onhold_notification', 'wpinv_new_invoice_notification'); |
|
45 | +add_action('wpinv_status_wpi-failed_to_wpi-processing_notification', 'wpinv_new_invoice_notification'); |
|
46 | +add_action('wpinv_status_wpi-failed_to_publish_notification', 'wpinv_new_invoice_notification'); |
|
47 | +add_action('wpinv_status_wpi-failed_to_wpi-onhold_notification', 'wpinv_new_invoice_notification'); |
|
48 | 48 | |
49 | 49 | // Cancelled invoice email |
50 | -add_action( 'wpinv_status_wpi-pending_to_wpi-cancelled_notification', 'wpinv_cancelled_invoice_notification' ); |
|
51 | -add_action( 'wpinv_status_wpi-onhold_to_wpi-cancelled_notification', 'wpinv_cancelled_invoice_notification' ); |
|
50 | +add_action('wpinv_status_wpi-pending_to_wpi-cancelled_notification', 'wpinv_cancelled_invoice_notification'); |
|
51 | +add_action('wpinv_status_wpi-onhold_to_wpi-cancelled_notification', 'wpinv_cancelled_invoice_notification'); |
|
52 | 52 | |
53 | 53 | // Failed invoice email |
54 | -add_action( 'wpinv_status_wpi-pending_to_wpi-failed_notification', 'wpinv_failed_invoice_notification' ); |
|
55 | -add_action( 'wpinv_status_wpi-onhold_to_wpi-failed_notification', 'wpinv_failed_invoice_notification' ); |
|
54 | +add_action('wpinv_status_wpi-pending_to_wpi-failed_notification', 'wpinv_failed_invoice_notification'); |
|
55 | +add_action('wpinv_status_wpi-onhold_to_wpi-failed_notification', 'wpinv_failed_invoice_notification'); |
|
56 | 56 | |
57 | 57 | // On hold invoice email |
58 | -add_action( 'wpinv_status_wpi-pending_to_wpi-onhold_notification', 'wpinv_onhold_invoice_notification' ); |
|
59 | -add_action( 'wpinv_status_wpi-failed_to_wpi-onhold_notification', 'wpinv_onhold_invoice_notification' ); |
|
58 | +add_action('wpinv_status_wpi-pending_to_wpi-onhold_notification', 'wpinv_onhold_invoice_notification'); |
|
59 | +add_action('wpinv_status_wpi-failed_to_wpi-onhold_notification', 'wpinv_onhold_invoice_notification'); |
|
60 | 60 | |
61 | 61 | // Processing invoice email |
62 | -add_action( 'wpinv_status_wpi-pending_to_wpi-processing_notification', 'wpinv_processing_invoice_notification' ); |
|
62 | +add_action('wpinv_status_wpi-pending_to_wpi-processing_notification', 'wpinv_processing_invoice_notification'); |
|
63 | 63 | |
64 | 64 | // Paid invoice email |
65 | -add_action( 'wpinv_status_publish_notification', 'wpinv_completed_invoice_notification' ); |
|
65 | +add_action('wpinv_status_publish_notification', 'wpinv_completed_invoice_notification'); |
|
66 | 66 | |
67 | 67 | // Refunded invoice email |
68 | -add_action( 'wpinv_fully_refunded_notification', 'wpinv_fully_refunded_notification' ); |
|
69 | -add_action( 'wpinv_partially_refunded_notification', 'wpinv_partially_refunded_notification' ); |
|
70 | -add_action( 'wpinv_status_publish_to_wpi-refunded_notification', 'wpinv_fully_refunded_notification' ); |
|
71 | -add_action( 'wpinv_status_wpi-processing_to_wpi-refunded_notification', 'wpinv_fully_refunded_notification' ); |
|
68 | +add_action('wpinv_fully_refunded_notification', 'wpinv_fully_refunded_notification'); |
|
69 | +add_action('wpinv_partially_refunded_notification', 'wpinv_partially_refunded_notification'); |
|
70 | +add_action('wpinv_status_publish_to_wpi-refunded_notification', 'wpinv_fully_refunded_notification'); |
|
71 | +add_action('wpinv_status_wpi-processing_to_wpi-refunded_notification', 'wpinv_fully_refunded_notification'); |
|
72 | 72 | |
73 | 73 | // Invoice note |
74 | -add_action( 'wpinv_new_invoice_note_notification', 'wpinv_new_invoice_note_notification' ); |
|
74 | +add_action('wpinv_new_invoice_note_notification', 'wpinv_new_invoice_note_notification'); |
|
75 | 75 | |
76 | -add_action( 'wpinv_email_header', 'wpinv_email_header' ); |
|
77 | -add_action( 'wpinv_email_footer', 'wpinv_email_footer' ); |
|
78 | -add_action( 'wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3 ); |
|
79 | -add_action( 'wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3 ); |
|
80 | -add_action( 'wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3 ); |
|
76 | +add_action('wpinv_email_header', 'wpinv_email_header'); |
|
77 | +add_action('wpinv_email_footer', 'wpinv_email_footer'); |
|
78 | +add_action('wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3); |
|
79 | +add_action('wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3); |
|
80 | +add_action('wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3); |
|
81 | 81 | |
82 | 82 | function wpinv_send_transactional_email() { |
83 | 83 | $args = func_get_args(); |
84 | 84 | $function = current_filter() . '_notification'; |
85 | - do_action_ref_array( $function, $args ); |
|
85 | + do_action_ref_array($function, $args); |
|
86 | 86 | } |
87 | 87 | |
88 | -function wpinv_new_invoice_notification( $invoice_id, $new_status = '' ) { |
|
88 | +function wpinv_new_invoice_notification($invoice_id, $new_status = '') { |
|
89 | 89 | $email_type = 'new_invoice'; |
90 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
90 | + if (!wpinv_email_is_enabled($email_type)) { |
|
91 | 91 | return false; |
92 | 92 | } |
93 | 93 | |
94 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
95 | - if ( empty( $invoice ) ) { |
|
94 | + $invoice = wpinv_get_invoice($invoice_id); |
|
95 | + if (empty($invoice)) { |
|
96 | 96 | return false; |
97 | 97 | } |
98 | 98 | |
99 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
99 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
100 | 100 | return false; |
101 | 101 | } |
102 | 102 | |
103 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
104 | - if ( !is_email( $recipient ) ) { |
|
103 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
104 | + if (!is_email($recipient)) { |
|
105 | 105 | return false; |
106 | 106 | } |
107 | 107 | |
108 | - do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type, true ); |
|
108 | + do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type, true); |
|
109 | 109 | |
110 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
111 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
112 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
113 | - $message_body = wpinv_email_get_content( $email_type, $invoice_id, $invoice ); |
|
114 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
110 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
111 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
112 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
113 | + $message_body = wpinv_email_get_content($email_type, $invoice_id, $invoice); |
|
114 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
115 | 115 | |
116 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
116 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
117 | 117 | 'invoice' => $invoice, |
118 | 118 | 'email_type' => $email_type, |
119 | 119 | 'email_heading' => $email_heading, |
120 | 120 | 'sent_to_admin' => true, |
121 | 121 | 'plain_text' => false, |
122 | 122 | 'message_body' => $message_body, |
123 | - ) ); |
|
123 | + )); |
|
124 | 124 | |
125 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
125 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
126 | 126 | |
127 | - do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type, true ); |
|
127 | + do_action('wpinv_post_send_invoice_notification', $invoice, $email_type, true); |
|
128 | 128 | |
129 | 129 | return $sent; |
130 | 130 | } |
131 | 131 | |
132 | -function wpinv_cancelled_invoice_notification( $invoice_id, $new_status = '' ) { |
|
132 | +function wpinv_cancelled_invoice_notification($invoice_id, $new_status = '') { |
|
133 | 133 | $email_type = 'cancelled_invoice'; |
134 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
134 | + if (!wpinv_email_is_enabled($email_type)) { |
|
135 | 135 | return false; |
136 | 136 | } |
137 | 137 | |
138 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
139 | - if ( empty( $invoice ) ) { |
|
138 | + $invoice = wpinv_get_invoice($invoice_id); |
|
139 | + if (empty($invoice)) { |
|
140 | 140 | return false; |
141 | 141 | } |
142 | 142 | |
143 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
143 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
144 | 144 | return false; |
145 | 145 | } |
146 | 146 | |
147 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
148 | - if ( !is_email( $recipient ) ) { |
|
147 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
148 | + if (!is_email($recipient)) { |
|
149 | 149 | return false; |
150 | 150 | } |
151 | 151 | |
152 | - do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type, true ); |
|
152 | + do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type, true); |
|
153 | 153 | |
154 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
155 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
156 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
157 | - $message_body = wpinv_email_get_content( $email_type, $invoice_id, $invoice ); |
|
158 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
154 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
155 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
156 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
157 | + $message_body = wpinv_email_get_content($email_type, $invoice_id, $invoice); |
|
158 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
159 | 159 | |
160 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
160 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
161 | 161 | 'invoice' => $invoice, |
162 | 162 | 'email_type' => $email_type, |
163 | 163 | 'email_heading' => $email_heading, |
164 | 164 | 'sent_to_admin' => true, |
165 | 165 | 'plain_text' => false, |
166 | 166 | 'message_body' => $message_body, |
167 | - ) ); |
|
167 | + )); |
|
168 | 168 | |
169 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
169 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
170 | 170 | |
171 | - do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type, true ); |
|
171 | + do_action('wpinv_post_send_invoice_notification', $invoice, $email_type, true); |
|
172 | 172 | |
173 | 173 | return $sent; |
174 | 174 | } |
175 | 175 | |
176 | -function wpinv_failed_invoice_notification( $invoice_id, $new_status = '' ) { |
|
176 | +function wpinv_failed_invoice_notification($invoice_id, $new_status = '') { |
|
177 | 177 | $email_type = 'failed_invoice'; |
178 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
178 | + if (!wpinv_email_is_enabled($email_type)) { |
|
179 | 179 | return false; |
180 | 180 | } |
181 | 181 | |
182 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
183 | - if ( empty( $invoice ) ) { |
|
182 | + $invoice = wpinv_get_invoice($invoice_id); |
|
183 | + if (empty($invoice)) { |
|
184 | 184 | return false; |
185 | 185 | } |
186 | 186 | |
187 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
187 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
188 | 188 | return false; |
189 | 189 | } |
190 | 190 | |
191 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
192 | - if ( !is_email( $recipient ) ) { |
|
191 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
192 | + if (!is_email($recipient)) { |
|
193 | 193 | return false; |
194 | 194 | } |
195 | 195 | |
196 | - do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type, true ); |
|
196 | + do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type, true); |
|
197 | 197 | |
198 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
199 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
200 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
201 | - $message_body = wpinv_email_get_content( $email_type, $invoice_id, $invoice ); |
|
202 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
198 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
199 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
200 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
201 | + $message_body = wpinv_email_get_content($email_type, $invoice_id, $invoice); |
|
202 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
203 | 203 | |
204 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
204 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
205 | 205 | 'invoice' => $invoice, |
206 | 206 | 'email_type' => $email_type, |
207 | 207 | 'email_heading' => $email_heading, |
208 | 208 | 'sent_to_admin' => true, |
209 | 209 | 'plain_text' => false, |
210 | 210 | 'message_body' => $message_body, |
211 | - ) ); |
|
211 | + )); |
|
212 | 212 | |
213 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
213 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
214 | 214 | |
215 | - do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type, true ); |
|
215 | + do_action('wpinv_post_send_invoice_notification', $invoice, $email_type, true); |
|
216 | 216 | |
217 | 217 | return $sent; |
218 | 218 | } |
219 | 219 | |
220 | -function wpinv_onhold_invoice_notification( $invoice_id, $new_status = '' ) { |
|
220 | +function wpinv_onhold_invoice_notification($invoice_id, $new_status = '') { |
|
221 | 221 | $email_type = 'onhold_invoice'; |
222 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
222 | + if (!wpinv_email_is_enabled($email_type)) { |
|
223 | 223 | return false; |
224 | 224 | } |
225 | 225 | |
226 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
227 | - if ( empty( $invoice ) ) { |
|
226 | + $invoice = wpinv_get_invoice($invoice_id); |
|
227 | + if (empty($invoice)) { |
|
228 | 228 | return false; |
229 | 229 | } |
230 | 230 | |
231 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
231 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
232 | 232 | return false; |
233 | 233 | } |
234 | 234 | |
235 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
236 | - if ( !is_email( $recipient ) ) { |
|
235 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
236 | + if (!is_email($recipient)) { |
|
237 | 237 | return false; |
238 | 238 | } |
239 | 239 | |
240 | - do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type ); |
|
240 | + do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type); |
|
241 | 241 | |
242 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
243 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
244 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
245 | - $message_body = wpinv_email_get_content( $email_type, $invoice_id, $invoice ); |
|
246 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
242 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
243 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
244 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
245 | + $message_body = wpinv_email_get_content($email_type, $invoice_id, $invoice); |
|
246 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
247 | 247 | |
248 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
248 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
249 | 249 | 'invoice' => $invoice, |
250 | 250 | 'email_type' => $email_type, |
251 | 251 | 'email_heading' => $email_heading, |
252 | 252 | 'sent_to_admin' => false, |
253 | 253 | 'plain_text' => false, |
254 | 254 | 'message_body' => $message_body, |
255 | - ) ); |
|
255 | + )); |
|
256 | 256 | |
257 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
257 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
258 | 258 | |
259 | - if ( wpinv_mail_admin_bcc_active( $email_type ) ) { |
|
260 | - $recipient = wpinv_get_admin_email(); |
|
261 | - $subject .= ' - ADMIN BCC COPY'; |
|
262 | - wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
259 | + if (wpinv_mail_admin_bcc_active($email_type)) { |
|
260 | + $recipient = wpinv_get_admin_email(); |
|
261 | + $subject .= ' - ADMIN BCC COPY'; |
|
262 | + wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
263 | 263 | } |
264 | 264 | |
265 | - do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type ); |
|
265 | + do_action('wpinv_post_send_invoice_notification', $invoice, $email_type); |
|
266 | 266 | |
267 | 267 | return $sent; |
268 | 268 | } |
269 | 269 | |
270 | -function wpinv_processing_invoice_notification( $invoice_id, $new_status = '' ) { |
|
270 | +function wpinv_processing_invoice_notification($invoice_id, $new_status = '') { |
|
271 | 271 | $email_type = 'processing_invoice'; |
272 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
272 | + if (!wpinv_email_is_enabled($email_type)) { |
|
273 | 273 | return false; |
274 | 274 | } |
275 | 275 | |
276 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
277 | - if ( empty( $invoice ) ) { |
|
276 | + $invoice = wpinv_get_invoice($invoice_id); |
|
277 | + if (empty($invoice)) { |
|
278 | 278 | return false; |
279 | 279 | } |
280 | 280 | |
281 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
281 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
282 | 282 | return false; |
283 | 283 | } |
284 | 284 | |
285 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
286 | - if ( !is_email( $recipient ) ) { |
|
285 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
286 | + if (!is_email($recipient)) { |
|
287 | 287 | return false; |
288 | 288 | } |
289 | 289 | |
290 | - do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type ); |
|
290 | + do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type); |
|
291 | 291 | |
292 | 292 | $search = array(); |
293 | 293 | $search['invoice_number'] = '{invoice_number}'; |
294 | 294 | $search['invoice_date'] = '{invoice_date}'; |
295 | 295 | $search['name'] = '{name}'; |
296 | 296 | |
297 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
298 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
299 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
300 | - $message_body = wpinv_email_get_content( $email_type, $invoice_id, $invoice ); |
|
301 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
297 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
298 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
299 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
300 | + $message_body = wpinv_email_get_content($email_type, $invoice_id, $invoice); |
|
301 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
302 | 302 | |
303 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
303 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
304 | 304 | 'invoice' => $invoice, |
305 | 305 | 'email_type' => $email_type, |
306 | 306 | 'email_heading' => $email_heading, |
307 | 307 | 'sent_to_admin' => false, |
308 | 308 | 'plain_text' => false, |
309 | 309 | 'message_body' => $message_body, |
310 | - ) ); |
|
310 | + )); |
|
311 | 311 | |
312 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
312 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
313 | 313 | |
314 | - if ( wpinv_mail_admin_bcc_active( $email_type ) ) { |
|
315 | - $recipient = wpinv_get_admin_email(); |
|
316 | - $subject .= ' - ADMIN BCC COPY'; |
|
317 | - wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
314 | + if (wpinv_mail_admin_bcc_active($email_type)) { |
|
315 | + $recipient = wpinv_get_admin_email(); |
|
316 | + $subject .= ' - ADMIN BCC COPY'; |
|
317 | + wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
318 | 318 | } |
319 | 319 | |
320 | - do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type ); |
|
320 | + do_action('wpinv_post_send_invoice_notification', $invoice, $email_type); |
|
321 | 321 | |
322 | 322 | return $sent; |
323 | 323 | } |
324 | 324 | |
325 | -function wpinv_completed_invoice_notification( $invoice_id, $new_status = '' ) { |
|
325 | +function wpinv_completed_invoice_notification($invoice_id, $new_status = '') { |
|
326 | 326 | $email_type = 'completed_invoice'; |
327 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
327 | + if (!wpinv_email_is_enabled($email_type)) { |
|
328 | 328 | return false; |
329 | 329 | } |
330 | 330 | |
331 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
332 | - if ( empty( $invoice ) ) { |
|
331 | + $invoice = wpinv_get_invoice($invoice_id); |
|
332 | + if (empty($invoice)) { |
|
333 | 333 | return false; |
334 | 334 | } |
335 | 335 | |
336 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
336 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
337 | 337 | return false; |
338 | 338 | } |
339 | 339 | |
340 | - if($invoice->is_renewal() && wpinv_email_is_enabled( 'completed_invoice_renewal' )){ |
|
340 | + if ($invoice->is_renewal() && wpinv_email_is_enabled('completed_invoice_renewal')) { |
|
341 | 341 | return false; |
342 | 342 | } |
343 | 343 | |
344 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
345 | - if ( !is_email( $recipient ) ) { |
|
344 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
345 | + if (!is_email($recipient)) { |
|
346 | 346 | return false; |
347 | 347 | } |
348 | 348 | |
349 | - do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type ); |
|
349 | + do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type); |
|
350 | 350 | |
351 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
352 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
353 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
354 | - $message_body = wpinv_email_get_content( $email_type, $invoice_id, $invoice ); |
|
355 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
351 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
352 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
353 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
354 | + $message_body = wpinv_email_get_content($email_type, $invoice_id, $invoice); |
|
355 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
356 | 356 | |
357 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
357 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
358 | 358 | 'invoice' => $invoice, |
359 | 359 | 'email_type' => $email_type, |
360 | 360 | 'email_heading' => $email_heading, |
361 | 361 | 'sent_to_admin' => false, |
362 | 362 | 'plain_text' => false, |
363 | 363 | 'message_body' => $message_body, |
364 | - ) ); |
|
364 | + )); |
|
365 | 365 | |
366 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
366 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
367 | 367 | |
368 | - if ( wpinv_mail_admin_bcc_active( $email_type ) ) { |
|
369 | - $recipient = wpinv_get_admin_email(); |
|
370 | - $subject .= ' - ADMIN BCC COPY'; |
|
371 | - wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
368 | + if (wpinv_mail_admin_bcc_active($email_type)) { |
|
369 | + $recipient = wpinv_get_admin_email(); |
|
370 | + $subject .= ' - ADMIN BCC COPY'; |
|
371 | + wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
372 | 372 | } |
373 | 373 | |
374 | - do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type ); |
|
374 | + do_action('wpinv_post_send_invoice_notification', $invoice, $email_type); |
|
375 | 375 | |
376 | 376 | return $sent; |
377 | 377 | } |
378 | 378 | |
379 | -function wpinv_fully_refunded_notification( $invoice_id, $new_status = '' ) { |
|
379 | +function wpinv_fully_refunded_notification($invoice_id, $new_status = '') { |
|
380 | 380 | $email_type = 'refunded_invoice'; |
381 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
381 | + if (!wpinv_email_is_enabled($email_type)) { |
|
382 | 382 | return false; |
383 | 383 | } |
384 | 384 | |
385 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
386 | - if ( empty( $invoice ) ) { |
|
385 | + $invoice = wpinv_get_invoice($invoice_id); |
|
386 | + if (empty($invoice)) { |
|
387 | 387 | return false; |
388 | 388 | } |
389 | 389 | |
390 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
390 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
391 | 391 | return false; |
392 | 392 | } |
393 | 393 | |
394 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
395 | - if ( !is_email( $recipient ) ) { |
|
394 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
395 | + if (!is_email($recipient)) { |
|
396 | 396 | return false; |
397 | 397 | } |
398 | 398 | |
399 | - do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type ); |
|
399 | + do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type); |
|
400 | 400 | |
401 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
402 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
403 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
404 | - $message_body = wpinv_email_get_content( $email_type, $invoice_id, $invoice ); |
|
405 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
401 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
402 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
403 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
404 | + $message_body = wpinv_email_get_content($email_type, $invoice_id, $invoice); |
|
405 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
406 | 406 | |
407 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
407 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
408 | 408 | 'invoice' => $invoice, |
409 | 409 | 'email_type' => $email_type, |
410 | 410 | 'email_heading' => $email_heading, |
@@ -412,50 +412,50 @@ discard block |
||
412 | 412 | 'plain_text' => false, |
413 | 413 | 'partial_refund' => false, |
414 | 414 | 'message_body' => $message_body, |
415 | - ) ); |
|
415 | + )); |
|
416 | 416 | |
417 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
417 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
418 | 418 | |
419 | - if ( wpinv_mail_admin_bcc_active( $email_type ) ) { |
|
420 | - $recipient = wpinv_get_admin_email(); |
|
421 | - $subject .= ' - ADMIN BCC COPY'; |
|
422 | - wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
419 | + if (wpinv_mail_admin_bcc_active($email_type)) { |
|
420 | + $recipient = wpinv_get_admin_email(); |
|
421 | + $subject .= ' - ADMIN BCC COPY'; |
|
422 | + wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
423 | 423 | } |
424 | 424 | |
425 | - do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type ); |
|
425 | + do_action('wpinv_post_send_invoice_notification', $invoice, $email_type); |
|
426 | 426 | |
427 | 427 | return $sent; |
428 | 428 | } |
429 | 429 | |
430 | -function wpinv_partially_refunded_notification( $invoice_id, $new_status = '' ) { |
|
430 | +function wpinv_partially_refunded_notification($invoice_id, $new_status = '') { |
|
431 | 431 | $email_type = 'refunded_invoice'; |
432 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
432 | + if (!wpinv_email_is_enabled($email_type)) { |
|
433 | 433 | return false; |
434 | 434 | } |
435 | 435 | |
436 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
437 | - if ( empty( $invoice ) ) { |
|
436 | + $invoice = wpinv_get_invoice($invoice_id); |
|
437 | + if (empty($invoice)) { |
|
438 | 438 | return false; |
439 | 439 | } |
440 | 440 | |
441 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
441 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
442 | 442 | return false; |
443 | 443 | } |
444 | 444 | |
445 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
446 | - if ( !is_email( $recipient ) ) { |
|
445 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
446 | + if (!is_email($recipient)) { |
|
447 | 447 | return false; |
448 | 448 | } |
449 | 449 | |
450 | - do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type ); |
|
450 | + do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type); |
|
451 | 451 | |
452 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
453 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
454 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
455 | - $message_body = wpinv_email_get_content( $email_type, $invoice_id, $invoice ); |
|
456 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
452 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
453 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
454 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
455 | + $message_body = wpinv_email_get_content($email_type, $invoice_id, $invoice); |
|
456 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
457 | 457 | |
458 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
458 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
459 | 459 | 'invoice' => $invoice, |
460 | 460 | 'email_type' => $email_type, |
461 | 461 | 'email_heading' => $email_heading, |
@@ -463,95 +463,95 @@ discard block |
||
463 | 463 | 'plain_text' => false, |
464 | 464 | 'partial_refund' => true, |
465 | 465 | 'message_body' => $message_body, |
466 | - ) ); |
|
466 | + )); |
|
467 | 467 | |
468 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
468 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
469 | 469 | |
470 | - if ( wpinv_mail_admin_bcc_active( $email_type ) ) { |
|
471 | - $recipient = wpinv_get_admin_email(); |
|
472 | - $subject .= ' - ADMIN BCC COPY'; |
|
473 | - wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
470 | + if (wpinv_mail_admin_bcc_active($email_type)) { |
|
471 | + $recipient = wpinv_get_admin_email(); |
|
472 | + $subject .= ' - ADMIN BCC COPY'; |
|
473 | + wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
474 | 474 | } |
475 | 475 | |
476 | - do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type ); |
|
476 | + do_action('wpinv_post_send_invoice_notification', $invoice, $email_type); |
|
477 | 477 | |
478 | 478 | return $sent; |
479 | 479 | } |
480 | 480 | |
481 | -function wpinv_new_invoice_note_notification( $invoice_id, $new_status = '' ) { |
|
481 | +function wpinv_new_invoice_note_notification($invoice_id, $new_status = '') { |
|
482 | 482 | } |
483 | 483 | |
484 | -function wpinv_user_invoice_notification( $invoice_id ) { |
|
484 | +function wpinv_user_invoice_notification($invoice_id) { |
|
485 | 485 | $email_type = 'user_invoice'; |
486 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
486 | + if (!wpinv_email_is_enabled($email_type)) { |
|
487 | 487 | return -1; |
488 | 488 | } |
489 | 489 | |
490 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
491 | - if ( empty( $invoice ) ) { |
|
490 | + $invoice = wpinv_get_invoice($invoice_id); |
|
491 | + if (empty($invoice)) { |
|
492 | 492 | return false; |
493 | 493 | } |
494 | 494 | |
495 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
495 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
496 | 496 | return false; |
497 | 497 | } |
498 | 498 | |
499 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
500 | - if ( !is_email( $recipient ) ) { |
|
499 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
500 | + if (!is_email($recipient)) { |
|
501 | 501 | return false; |
502 | 502 | } |
503 | 503 | |
504 | - do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type ); |
|
504 | + do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type); |
|
505 | 505 | |
506 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
507 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
508 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
509 | - $message_body = wpinv_email_get_content( $email_type, $invoice_id, $invoice ); |
|
510 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
506 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
507 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
508 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
509 | + $message_body = wpinv_email_get_content($email_type, $invoice_id, $invoice); |
|
510 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
511 | 511 | |
512 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
512 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
513 | 513 | 'invoice' => $invoice, |
514 | 514 | 'email_type' => $email_type, |
515 | 515 | 'email_heading' => $email_heading, |
516 | 516 | 'sent_to_admin' => false, |
517 | 517 | 'plain_text' => false, |
518 | 518 | 'message_body' => $message_body, |
519 | - ) ); |
|
519 | + )); |
|
520 | 520 | |
521 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
521 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
522 | 522 | |
523 | - if ( wpinv_mail_admin_bcc_active( $email_type ) ) { |
|
524 | - $recipient = wpinv_get_admin_email(); |
|
525 | - $subject .= ' - ADMIN BCC COPY'; |
|
526 | - wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
523 | + if (wpinv_mail_admin_bcc_active($email_type)) { |
|
524 | + $recipient = wpinv_get_admin_email(); |
|
525 | + $subject .= ' - ADMIN BCC COPY'; |
|
526 | + wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
527 | 527 | } |
528 | 528 | |
529 | - do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type ); |
|
529 | + do_action('wpinv_post_send_invoice_notification', $invoice, $email_type); |
|
530 | 530 | |
531 | - if ( $sent ) { |
|
532 | - $note = __( 'Invoice has been emailed to the user.', 'invoicing' ); |
|
531 | + if ($sent) { |
|
532 | + $note = __('Invoice has been emailed to the user.', 'invoicing'); |
|
533 | 533 | } else { |
534 | - $note = __( 'Fail to send invoice to the user!', 'invoicing' ); |
|
534 | + $note = __('Fail to send invoice to the user!', 'invoicing'); |
|
535 | 535 | } |
536 | 536 | |
537 | - $invoice->add_note( $note, '', '', true ); // Add system note. |
|
537 | + $invoice->add_note($note, '', '', true); // Add system note. |
|
538 | 538 | |
539 | 539 | return $sent; |
540 | 540 | } |
541 | 541 | |
542 | -function wpinv_user_note_notification( $invoice_id, $args = array() ) { |
|
542 | +function wpinv_user_note_notification($invoice_id, $args = array()) { |
|
543 | 543 | $email_type = 'user_note'; |
544 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
544 | + if (!wpinv_email_is_enabled($email_type)) { |
|
545 | 545 | return false; |
546 | 546 | } |
547 | 547 | |
548 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
549 | - if ( empty( $invoice ) ) { |
|
548 | + $invoice = wpinv_get_invoice($invoice_id); |
|
549 | + if (empty($invoice)) { |
|
550 | 550 | return false; |
551 | 551 | } |
552 | 552 | |
553 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
554 | - if ( !is_email( $recipient ) ) { |
|
553 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
554 | + if (!is_email($recipient)) { |
|
555 | 555 | return false; |
556 | 556 | } |
557 | 557 | |
@@ -559,19 +559,19 @@ discard block |
||
559 | 559 | 'user_note' => '' |
560 | 560 | ); |
561 | 561 | |
562 | - $args = wp_parse_args( $args, $defaults ); |
|
562 | + $args = wp_parse_args($args, $defaults); |
|
563 | 563 | |
564 | - do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type ); |
|
564 | + do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type); |
|
565 | 565 | |
566 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
567 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
568 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
569 | - $message_body = wpinv_email_get_content( $email_type, $invoice_id, $invoice ); |
|
570 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
566 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
567 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
568 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
569 | + $message_body = wpinv_email_get_content($email_type, $invoice_id, $invoice); |
|
570 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
571 | 571 | |
572 | - $message_body = str_replace( '{customer_note}', $args['user_note'], $message_body ); |
|
572 | + $message_body = str_replace('{customer_note}', $args['user_note'], $message_body); |
|
573 | 573 | |
574 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
574 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
575 | 575 | 'invoice' => $invoice, |
576 | 576 | 'email_type' => $email_type, |
577 | 577 | 'email_heading' => $email_heading, |
@@ -579,36 +579,36 @@ discard block |
||
579 | 579 | 'plain_text' => false, |
580 | 580 | 'message_body' => $message_body, |
581 | 581 | 'customer_note' => $args['user_note'] |
582 | - ) ); |
|
582 | + )); |
|
583 | 583 | |
584 | - $content = wpinv_email_format_text( $content, $invoice ); |
|
584 | + $content = wpinv_email_format_text($content, $invoice); |
|
585 | 585 | |
586 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
586 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
587 | 587 | |
588 | - do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type ); |
|
588 | + do_action('wpinv_post_send_invoice_notification', $invoice, $email_type); |
|
589 | 589 | |
590 | 590 | return $sent; |
591 | 591 | } |
592 | 592 | |
593 | 593 | function wpinv_mail_get_from_address() { |
594 | - $from_address = apply_filters( 'wpinv_mail_from_address', wpinv_get_option( 'email_from' ) ); |
|
595 | - return sanitize_email( $from_address ); |
|
594 | + $from_address = apply_filters('wpinv_mail_from_address', wpinv_get_option('email_from')); |
|
595 | + return sanitize_email($from_address); |
|
596 | 596 | } |
597 | 597 | |
598 | 598 | function wpinv_mail_get_from_name() { |
599 | - $from_name = apply_filters( 'wpinv_mail_from_name', wpinv_get_option( 'email_from_name' ) ); |
|
600 | - return wp_specialchars_decode( esc_html( $from_name ), ENT_QUOTES ); |
|
599 | + $from_name = apply_filters('wpinv_mail_from_name', wpinv_get_option('email_from_name')); |
|
600 | + return wp_specialchars_decode(esc_html($from_name), ENT_QUOTES); |
|
601 | 601 | } |
602 | 602 | |
603 | -function wpinv_mail_admin_bcc_active( $mail_type = '' ) { |
|
604 | - $active = apply_filters( 'wpinv_mail_admin_bcc_active', wpinv_get_option( 'email_' . $mail_type . '_admin_bcc' ) ); |
|
605 | - return ( $active ? true : false ); |
|
603 | +function wpinv_mail_admin_bcc_active($mail_type = '') { |
|
604 | + $active = apply_filters('wpinv_mail_admin_bcc_active', wpinv_get_option('email_' . $mail_type . '_admin_bcc')); |
|
605 | + return ($active ? true : false); |
|
606 | 606 | } |
607 | 607 | |
608 | -function wpinv_mail_get_content_type( $content_type = 'text/html', $email_type = 'html' ) { |
|
609 | - $email_type = apply_filters( 'wpinv_mail_content_type', $email_type ); |
|
608 | +function wpinv_mail_get_content_type($content_type = 'text/html', $email_type = 'html') { |
|
609 | + $email_type = apply_filters('wpinv_mail_content_type', $email_type); |
|
610 | 610 | |
611 | - switch ( $email_type ) { |
|
611 | + switch ($email_type) { |
|
612 | 612 | case 'html' : |
613 | 613 | $content_type = 'text/html'; |
614 | 614 | break; |
@@ -623,35 +623,35 @@ discard block |
||
623 | 623 | return $content_type; |
624 | 624 | } |
625 | 625 | |
626 | -function wpinv_mail_send( $to, $subject, $message, $headers, $attachments ) { |
|
627 | - add_filter( 'wp_mail_from', 'wpinv_mail_get_from_address' ); |
|
628 | - add_filter( 'wp_mail_from_name', 'wpinv_mail_get_from_name' ); |
|
629 | - add_filter( 'wp_mail_content_type', 'wpinv_mail_get_content_type' ); |
|
626 | +function wpinv_mail_send($to, $subject, $message, $headers, $attachments) { |
|
627 | + add_filter('wp_mail_from', 'wpinv_mail_get_from_address'); |
|
628 | + add_filter('wp_mail_from_name', 'wpinv_mail_get_from_name'); |
|
629 | + add_filter('wp_mail_content_type', 'wpinv_mail_get_content_type'); |
|
630 | 630 | |
631 | - $message = wpinv_email_style_body( $message ); |
|
632 | - $message = apply_filters( 'wpinv_mail_content', $message ); |
|
631 | + $message = wpinv_email_style_body($message); |
|
632 | + $message = apply_filters('wpinv_mail_content', $message); |
|
633 | 633 | |
634 | - $sent = wp_mail( $to, $subject, $message, $headers, $attachments ); |
|
634 | + $sent = wp_mail($to, $subject, $message, $headers, $attachments); |
|
635 | 635 | |
636 | - if ( !$sent ) { |
|
637 | - $log_message = wp_sprintf( __( "\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), ( is_array( $to ) ? implode( ', ', $to ) : $to ), $subject ); |
|
638 | - wpinv_error_log( $log_message, __( "Email from Invoicing plugin failed to send", 'invoicing' ), __FILE__, __LINE__ ); |
|
636 | + if (!$sent) { |
|
637 | + $log_message = wp_sprintf(__("\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing'), date_i18n('F j Y H:i:s', current_time('timestamp')), (is_array($to) ? implode(', ', $to) : $to), $subject); |
|
638 | + wpinv_error_log($log_message, __("Email from Invoicing plugin failed to send", 'invoicing'), __FILE__, __LINE__); |
|
639 | 639 | } |
640 | 640 | |
641 | - remove_filter( 'wp_mail_from', 'wpinv_mail_get_from_address' ); |
|
642 | - remove_filter( 'wp_mail_from_name', 'wpinv_mail_get_from_name' ); |
|
643 | - remove_filter( 'wp_mail_content_type', 'wpinv_mail_get_content_type' ); |
|
641 | + remove_filter('wp_mail_from', 'wpinv_mail_get_from_address'); |
|
642 | + remove_filter('wp_mail_from_name', 'wpinv_mail_get_from_name'); |
|
643 | + remove_filter('wp_mail_content_type', 'wpinv_mail_get_content_type'); |
|
644 | 644 | |
645 | 645 | return $sent; |
646 | 646 | } |
647 | 647 | |
648 | 648 | function wpinv_get_emails() { |
649 | 649 | $overdue_days_options = array(); |
650 | - $overdue_days_options[0] = __( 'On the Due Date', 'invoicing' ); |
|
651 | - $overdue_days_options[1] = __( '1 day after Due Date', 'invoicing' ); |
|
650 | + $overdue_days_options[0] = __('On the Due Date', 'invoicing'); |
|
651 | + $overdue_days_options[1] = __('1 day after Due Date', 'invoicing'); |
|
652 | 652 | |
653 | - for ( $i = 2; $i <= 10; $i++ ) { |
|
654 | - $overdue_days_options[$i] = wp_sprintf( __( '%d days after Due Date', 'invoicing' ), $i ); |
|
653 | + for ($i = 2; $i <= 10; $i++) { |
|
654 | + $overdue_days_options[$i] = wp_sprintf(__('%d days after Due Date', 'invoicing'), $i); |
|
655 | 655 | } |
656 | 656 | |
657 | 657 | // Default, built-in gateways |
@@ -659,39 +659,39 @@ discard block |
||
659 | 659 | 'new_invoice' => array( |
660 | 660 | 'email_new_invoice_header' => array( |
661 | 661 | 'id' => 'email_new_invoice_header', |
662 | - 'name' => '<h3>' . __( 'New Invoice', 'invoicing' ) . '</h3>', |
|
663 | - 'desc' => __( 'New invoice emails are sent to admin when a new invoice is received.', 'invoicing' ), |
|
662 | + 'name' => '<h3>' . __('New Invoice', 'invoicing') . '</h3>', |
|
663 | + 'desc' => __('New invoice emails are sent to admin when a new invoice is received.', 'invoicing'), |
|
664 | 664 | 'type' => 'header', |
665 | 665 | ), |
666 | 666 | 'email_new_invoice_active' => array( |
667 | 667 | 'id' => 'email_new_invoice_active', |
668 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
669 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
668 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
669 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
670 | 670 | 'type' => 'checkbox', |
671 | 671 | 'std' => 1 |
672 | 672 | ), |
673 | 673 | 'email_new_invoice_subject' => array( |
674 | 674 | 'id' => 'email_new_invoice_subject', |
675 | - 'name' => __( 'Subject', 'invoicing' ), |
|
676 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
675 | + 'name' => __('Subject', 'invoicing'), |
|
676 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
677 | 677 | 'type' => 'text', |
678 | - 'std' => __( '[{site_title}] New payment invoice ({invoice_number}) - {invoice_date}', 'invoicing' ), |
|
678 | + 'std' => __('[{site_title}] New payment invoice ({invoice_number}) - {invoice_date}', 'invoicing'), |
|
679 | 679 | 'size' => 'large' |
680 | 680 | ), |
681 | 681 | 'email_new_invoice_heading' => array( |
682 | 682 | 'id' => 'email_new_invoice_heading', |
683 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
684 | - 'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ), |
|
683 | + 'name' => __('Email Heading', 'invoicing'), |
|
684 | + 'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'), |
|
685 | 685 | 'type' => 'text', |
686 | - 'std' => __( 'New payment invoice', 'invoicing' ), |
|
686 | + 'std' => __('New payment invoice', 'invoicing'), |
|
687 | 687 | 'size' => 'large' |
688 | 688 | ), |
689 | 689 | 'email_new_invoice_body' => array( |
690 | 690 | 'id' => 'email_new_invoice_body', |
691 | - 'name' => __( 'Email Content', 'invoicing' ), |
|
692 | - 'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ), |
|
691 | + 'name' => __('Email Content', 'invoicing'), |
|
692 | + 'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'), |
|
693 | 693 | 'type' => 'rich_editor', |
694 | - 'std' => __( '<p>Hi Admin,</p><p>You have received payment invoice from {name}.</p>', 'invoicing' ), |
|
694 | + 'std' => __('<p>Hi Admin,</p><p>You have received payment invoice from {name}.</p>', 'invoicing'), |
|
695 | 695 | 'class' => 'large', |
696 | 696 | 'size' => '10' |
697 | 697 | ), |
@@ -699,39 +699,39 @@ discard block |
||
699 | 699 | 'cancelled_invoice' => array( |
700 | 700 | 'email_cancelled_invoice_header' => array( |
701 | 701 | 'id' => 'email_cancelled_invoice_header', |
702 | - 'name' => '<h3>' . __( 'Cancelled Invoice', 'invoicing' ) . '</h3>', |
|
703 | - 'desc' => __( 'Cancelled invoice emails are sent to admin when invoices have been marked cancelled.', 'invoicing' ), |
|
702 | + 'name' => '<h3>' . __('Cancelled Invoice', 'invoicing') . '</h3>', |
|
703 | + 'desc' => __('Cancelled invoice emails are sent to admin when invoices have been marked cancelled.', 'invoicing'), |
|
704 | 704 | 'type' => 'header', |
705 | 705 | ), |
706 | 706 | 'email_cancelled_invoice_active' => array( |
707 | 707 | 'id' => 'email_cancelled_invoice_active', |
708 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
709 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
708 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
709 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
710 | 710 | 'type' => 'checkbox', |
711 | 711 | 'std' => 1 |
712 | 712 | ), |
713 | 713 | 'email_cancelled_invoice_subject' => array( |
714 | 714 | 'id' => 'email_cancelled_invoice_subject', |
715 | - 'name' => __( 'Subject', 'invoicing' ), |
|
716 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
715 | + 'name' => __('Subject', 'invoicing'), |
|
716 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
717 | 717 | 'type' => 'text', |
718 | - 'std' => __( '[{site_title}] Cancelled invoice ({invoice_number})', 'invoicing' ), |
|
718 | + 'std' => __('[{site_title}] Cancelled invoice ({invoice_number})', 'invoicing'), |
|
719 | 719 | 'size' => 'large' |
720 | 720 | ), |
721 | 721 | 'email_cancelled_invoice_heading' => array( |
722 | 722 | 'id' => 'email_cancelled_invoice_heading', |
723 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
724 | - 'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ), |
|
723 | + 'name' => __('Email Heading', 'invoicing'), |
|
724 | + 'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'), |
|
725 | 725 | 'type' => 'text', |
726 | - 'std' => __( 'Cancelled invoice', 'invoicing' ), |
|
726 | + 'std' => __('Cancelled invoice', 'invoicing'), |
|
727 | 727 | 'size' => 'large' |
728 | 728 | ), |
729 | 729 | 'email_cancelled_invoice_body' => array( |
730 | 730 | 'id' => 'email_cancelled_invoice_body', |
731 | - 'name' => __( 'Email Content', 'invoicing' ), |
|
732 | - 'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ), |
|
731 | + 'name' => __('Email Content', 'invoicing'), |
|
732 | + 'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'), |
|
733 | 733 | 'type' => 'rich_editor', |
734 | - 'std' => __( '<p>Hi Admin,</p><p>The invoice #{invoice_number} from {site_title} has been cancelled.</p>', 'invoicing' ), |
|
734 | + 'std' => __('<p>Hi Admin,</p><p>The invoice #{invoice_number} from {site_title} has been cancelled.</p>', 'invoicing'), |
|
735 | 735 | 'class' => 'large', |
736 | 736 | 'size' => '10' |
737 | 737 | ), |
@@ -739,39 +739,39 @@ discard block |
||
739 | 739 | 'failed_invoice' => array( |
740 | 740 | 'email_failed_invoice_header' => array( |
741 | 741 | 'id' => 'email_failed_invoice_header', |
742 | - 'name' => '<h3>' . __( 'Failed Invoice', 'invoicing' ) . '</h3>', |
|
743 | - 'desc' => __( 'Failed invoice emails are sent to admin when invoices have been marked failed (if they were previously processing or on-hold).', 'invoicing' ), |
|
742 | + 'name' => '<h3>' . __('Failed Invoice', 'invoicing') . '</h3>', |
|
743 | + 'desc' => __('Failed invoice emails are sent to admin when invoices have been marked failed (if they were previously processing or on-hold).', 'invoicing'), |
|
744 | 744 | 'type' => 'header', |
745 | 745 | ), |
746 | 746 | 'email_failed_invoice_active' => array( |
747 | 747 | 'id' => 'email_failed_invoice_active', |
748 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
749 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
748 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
749 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
750 | 750 | 'type' => 'checkbox', |
751 | 751 | 'std' => 1 |
752 | 752 | ), |
753 | 753 | 'email_failed_invoice_subject' => array( |
754 | 754 | 'id' => 'email_failed_invoice_subject', |
755 | - 'name' => __( 'Subject', 'invoicing' ), |
|
756 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
755 | + 'name' => __('Subject', 'invoicing'), |
|
756 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
757 | 757 | 'type' => 'text', |
758 | - 'std' => __( '[{site_title}] Failed invoice ({invoice_number})', 'invoicing' ), |
|
758 | + 'std' => __('[{site_title}] Failed invoice ({invoice_number})', 'invoicing'), |
|
759 | 759 | 'size' => 'large' |
760 | 760 | ), |
761 | 761 | 'email_failed_invoice_heading' => array( |
762 | 762 | 'id' => 'email_failed_invoice_heading', |
763 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
764 | - 'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ), |
|
763 | + 'name' => __('Email Heading', 'invoicing'), |
|
764 | + 'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'), |
|
765 | 765 | 'type' => 'text', |
766 | - 'std' => __( 'Failed invoice', 'invoicing' ), |
|
766 | + 'std' => __('Failed invoice', 'invoicing'), |
|
767 | 767 | 'size' => 'large' |
768 | 768 | ), |
769 | 769 | 'email_failed_invoice_body' => array( |
770 | 770 | 'id' => 'email_failed_invoice_body', |
771 | - 'name' => __( 'Email Content', 'invoicing' ), |
|
772 | - 'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ), |
|
771 | + 'name' => __('Email Content', 'invoicing'), |
|
772 | + 'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'), |
|
773 | 773 | 'type' => 'rich_editor', |
774 | - 'std' => __( '<p>Hi Admin,</p><p>Payment for invoice #{invoice_number} from {site_title} has been failed.</p>', 'invoicing' ), |
|
774 | + 'std' => __('<p>Hi Admin,</p><p>Payment for invoice #{invoice_number} from {site_title} has been failed.</p>', 'invoicing'), |
|
775 | 775 | 'class' => 'large', |
776 | 776 | 'size' => '10' |
777 | 777 | ), |
@@ -779,46 +779,46 @@ discard block |
||
779 | 779 | 'onhold_invoice' => array( |
780 | 780 | 'email_onhold_invoice_header' => array( |
781 | 781 | 'id' => 'email_onhold_invoice_header', |
782 | - 'name' => '<h3>' . __( 'On Hold Invoice', 'invoicing' ) . '</h3>', |
|
783 | - 'desc' => __( 'This is an invoice notification sent to users containing invoice details after an invoice is placed on-hold.', 'invoicing' ), |
|
782 | + 'name' => '<h3>' . __('On Hold Invoice', 'invoicing') . '</h3>', |
|
783 | + 'desc' => __('This is an invoice notification sent to users containing invoice details after an invoice is placed on-hold.', 'invoicing'), |
|
784 | 784 | 'type' => 'header', |
785 | 785 | ), |
786 | 786 | 'email_onhold_invoice_active' => array( |
787 | 787 | 'id' => 'email_onhold_invoice_active', |
788 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
789 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
788 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
789 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
790 | 790 | 'type' => 'checkbox', |
791 | 791 | 'std' => 1 |
792 | 792 | ), |
793 | 793 | 'email_onhold_invoice_subject' => array( |
794 | 794 | 'id' => 'email_onhold_invoice_subject', |
795 | - 'name' => __( 'Subject', 'invoicing' ), |
|
796 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
795 | + 'name' => __('Subject', 'invoicing'), |
|
796 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
797 | 797 | 'type' => 'text', |
798 | - 'std' => __( '[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing' ), |
|
798 | + 'std' => __('[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing'), |
|
799 | 799 | 'size' => 'large' |
800 | 800 | ), |
801 | 801 | 'email_onhold_invoice_heading' => array( |
802 | 802 | 'id' => 'email_onhold_invoice_heading', |
803 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
804 | - 'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ), |
|
803 | + 'name' => __('Email Heading', 'invoicing'), |
|
804 | + 'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'), |
|
805 | 805 | 'type' => 'text', |
806 | - 'std' => __( 'Thank you for your invoice', 'invoicing' ), |
|
806 | + 'std' => __('Thank you for your invoice', 'invoicing'), |
|
807 | 807 | 'size' => 'large' |
808 | 808 | ), |
809 | 809 | 'email_onhold_invoice_admin_bcc' => array( |
810 | 810 | 'id' => 'email_onhold_invoice_admin_bcc', |
811 | - 'name' => __( 'Enable Admin BCC', 'invoicing' ), |
|
812 | - 'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ), |
|
811 | + 'name' => __('Enable Admin BCC', 'invoicing'), |
|
812 | + 'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'), |
|
813 | 813 | 'type' => 'checkbox', |
814 | 814 | 'std' => 1 |
815 | 815 | ), |
816 | 816 | 'email_onhold_invoice_body' => array( |
817 | 817 | 'id' => 'email_onhold_invoice_body', |
818 | - 'name' => __( 'Email Content', 'invoicing' ), |
|
819 | - 'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ), |
|
818 | + 'name' => __('Email Content', 'invoicing'), |
|
819 | + 'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'), |
|
820 | 820 | 'type' => 'rich_editor', |
821 | - 'std' => __( '<p>Hi {name},</p><p>Your invoice is on-hold until we confirm your payment has been received.</p>', 'invoicing' ), |
|
821 | + 'std' => __('<p>Hi {name},</p><p>Your invoice is on-hold until we confirm your payment has been received.</p>', 'invoicing'), |
|
822 | 822 | 'class' => 'large', |
823 | 823 | 'size' => '10' |
824 | 824 | ), |
@@ -826,46 +826,46 @@ discard block |
||
826 | 826 | 'processing_invoice' => array( |
827 | 827 | 'email_processing_invoice_header' => array( |
828 | 828 | 'id' => 'email_processing_invoice_header', |
829 | - 'name' => '<h3>' . __( 'Processing Invoice', 'invoicing' ) . '</h3>', |
|
830 | - 'desc' => __( 'This is an invoice notification sent to users containing invoice details after payment.', 'invoicing' ), |
|
829 | + 'name' => '<h3>' . __('Processing Invoice', 'invoicing') . '</h3>', |
|
830 | + 'desc' => __('This is an invoice notification sent to users containing invoice details after payment.', 'invoicing'), |
|
831 | 831 | 'type' => 'header', |
832 | 832 | ), |
833 | 833 | 'email_processing_invoice_active' => array( |
834 | 834 | 'id' => 'email_processing_invoice_active', |
835 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
836 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
835 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
836 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
837 | 837 | 'type' => 'checkbox', |
838 | 838 | 'std' => 1 |
839 | 839 | ), |
840 | 840 | 'email_processing_invoice_subject' => array( |
841 | 841 | 'id' => 'email_processing_invoice_subject', |
842 | - 'name' => __( 'Subject', 'invoicing' ), |
|
843 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
842 | + 'name' => __('Subject', 'invoicing'), |
|
843 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
844 | 844 | 'type' => 'text', |
845 | - 'std' => __( '[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing' ), |
|
845 | + 'std' => __('[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing'), |
|
846 | 846 | 'size' => 'large' |
847 | 847 | ), |
848 | 848 | 'email_processing_invoice_heading' => array( |
849 | 849 | 'id' => 'email_processing_invoice_heading', |
850 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
851 | - 'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ), |
|
850 | + 'name' => __('Email Heading', 'invoicing'), |
|
851 | + 'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'), |
|
852 | 852 | 'type' => 'text', |
853 | - 'std' => __( 'Thank you for your invoice', 'invoicing' ), |
|
853 | + 'std' => __('Thank you for your invoice', 'invoicing'), |
|
854 | 854 | 'size' => 'large' |
855 | 855 | ), |
856 | 856 | 'email_processing_invoice_admin_bcc' => array( |
857 | 857 | 'id' => 'email_processing_invoice_admin_bcc', |
858 | - 'name' => __( 'Enable Admin BCC', 'invoicing' ), |
|
859 | - 'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ), |
|
858 | + 'name' => __('Enable Admin BCC', 'invoicing'), |
|
859 | + 'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'), |
|
860 | 860 | 'type' => 'checkbox', |
861 | 861 | 'std' => 1 |
862 | 862 | ), |
863 | 863 | 'email_processing_invoice_body' => array( |
864 | 864 | 'id' => 'email_processing_invoice_body', |
865 | - 'name' => __( 'Email Content', 'invoicing' ), |
|
866 | - 'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ), |
|
865 | + 'name' => __('Email Content', 'invoicing'), |
|
866 | + 'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'), |
|
867 | 867 | 'type' => 'rich_editor', |
868 | - 'std' => __( '<p>Hi {name},</p><p>Your invoice has been received at {site_title} and is now being processed.</p>', 'invoicing' ), |
|
868 | + 'std' => __('<p>Hi {name},</p><p>Your invoice has been received at {site_title} and is now being processed.</p>', 'invoicing'), |
|
869 | 869 | 'class' => 'large', |
870 | 870 | 'size' => '10' |
871 | 871 | ), |
@@ -873,52 +873,52 @@ discard block |
||
873 | 873 | 'completed_invoice' => array( |
874 | 874 | 'email_completed_invoice_header' => array( |
875 | 875 | 'id' => 'email_completed_invoice_header', |
876 | - 'name' => '<h3>' . __( 'Paid Invoice', 'invoicing' ) . '</h3>', |
|
877 | - 'desc' => __( 'Invoice paid emails are sent to users when their invoices are marked paid and usually indicate that their payment has been done.', 'invoicing' ), |
|
876 | + 'name' => '<h3>' . __('Paid Invoice', 'invoicing') . '</h3>', |
|
877 | + 'desc' => __('Invoice paid emails are sent to users when their invoices are marked paid and usually indicate that their payment has been done.', 'invoicing'), |
|
878 | 878 | 'type' => 'header', |
879 | 879 | ), |
880 | 880 | 'email_completed_invoice_active' => array( |
881 | 881 | 'id' => 'email_completed_invoice_active', |
882 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
883 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
882 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
883 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
884 | 884 | 'type' => 'checkbox', |
885 | 885 | 'std' => 1 |
886 | 886 | ), |
887 | 887 | 'email_completed_invoice_renewal_active' => array( |
888 | 888 | 'id' => 'email_completed_invoice_renewal_active', |
889 | - 'name' => __( 'Enable renewal notification', 'invoicing' ), |
|
890 | - 'desc' => __( 'Enable renewal invoice email notification. This notification will be sent on renewal.', 'invoicing' ), |
|
889 | + 'name' => __('Enable renewal notification', 'invoicing'), |
|
890 | + 'desc' => __('Enable renewal invoice email notification. This notification will be sent on renewal.', 'invoicing'), |
|
891 | 891 | 'type' => 'checkbox', |
892 | 892 | 'std' => 0 |
893 | 893 | ), |
894 | 894 | 'email_completed_invoice_subject' => array( |
895 | 895 | 'id' => 'email_completed_invoice_subject', |
896 | - 'name' => __( 'Subject', 'invoicing' ), |
|
897 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
896 | + 'name' => __('Subject', 'invoicing'), |
|
897 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
898 | 898 | 'type' => 'text', |
899 | - 'std' => __( '[{site_title}] Your invoice from {invoice_date} has been paid', 'invoicing' ), |
|
899 | + 'std' => __('[{site_title}] Your invoice from {invoice_date} has been paid', 'invoicing'), |
|
900 | 900 | 'size' => 'large' |
901 | 901 | ), |
902 | 902 | 'email_completed_invoice_heading' => array( |
903 | 903 | 'id' => 'email_completed_invoice_heading', |
904 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
905 | - 'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ), |
|
904 | + 'name' => __('Email Heading', 'invoicing'), |
|
905 | + 'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'), |
|
906 | 906 | 'type' => 'text', |
907 | - 'std' => __( 'Your invoice has been paid', 'invoicing' ), |
|
907 | + 'std' => __('Your invoice has been paid', 'invoicing'), |
|
908 | 908 | 'size' => 'large' |
909 | 909 | ), |
910 | 910 | 'email_completed_invoice_admin_bcc' => array( |
911 | 911 | 'id' => 'email_completed_invoice_admin_bcc', |
912 | - 'name' => __( 'Enable Admin BCC', 'invoicing' ), |
|
913 | - 'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ), |
|
912 | + 'name' => __('Enable Admin BCC', 'invoicing'), |
|
913 | + 'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'), |
|
914 | 914 | 'type' => 'checkbox', |
915 | 915 | ), |
916 | 916 | 'email_completed_invoice_body' => array( |
917 | 917 | 'id' => 'email_completed_invoice_body', |
918 | - 'name' => __( 'Email Content', 'invoicing' ), |
|
919 | - 'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ), |
|
918 | + 'name' => __('Email Content', 'invoicing'), |
|
919 | + 'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'), |
|
920 | 920 | 'type' => 'rich_editor', |
921 | - 'std' => __( '<p>Hi {name},</p><p>Your recent invoice on {site_title} has been paid.</p>', 'invoicing' ), |
|
921 | + 'std' => __('<p>Hi {name},</p><p>Your recent invoice on {site_title} has been paid.</p>', 'invoicing'), |
|
922 | 922 | 'class' => 'large', |
923 | 923 | 'size' => '10' |
924 | 924 | ), |
@@ -927,46 +927,46 @@ discard block |
||
927 | 927 | 'refunded_invoice' => array( |
928 | 928 | 'email_refunded_invoice_header' => array( |
929 | 929 | 'id' => 'email_refunded_invoice_header', |
930 | - 'name' => '<h3>' . __( 'Refunded Invoice', 'invoicing' ) . '</h3>', |
|
931 | - 'desc' => __( 'Invoice refunded emails are sent to users when their invoices are marked refunded.', 'invoicing' ), |
|
930 | + 'name' => '<h3>' . __('Refunded Invoice', 'invoicing') . '</h3>', |
|
931 | + 'desc' => __('Invoice refunded emails are sent to users when their invoices are marked refunded.', 'invoicing'), |
|
932 | 932 | 'type' => 'header', |
933 | 933 | ), |
934 | 934 | 'email_refunded_invoice_active' => array( |
935 | 935 | 'id' => 'email_refunded_invoice_active', |
936 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
937 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
936 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
937 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
938 | 938 | 'type' => 'checkbox', |
939 | 939 | 'std' => 1 |
940 | 940 | ), |
941 | 941 | 'email_refunded_invoice_subject' => array( |
942 | 942 | 'id' => 'email_refunded_invoice_subject', |
943 | - 'name' => __( 'Subject', 'invoicing' ), |
|
944 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
943 | + 'name' => __('Subject', 'invoicing'), |
|
944 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
945 | 945 | 'type' => 'text', |
946 | - 'std' => __( '[{site_title}] Your invoice from {invoice_date} has been refunded', 'invoicing' ), |
|
946 | + 'std' => __('[{site_title}] Your invoice from {invoice_date} has been refunded', 'invoicing'), |
|
947 | 947 | 'size' => 'large' |
948 | 948 | ), |
949 | 949 | 'email_refunded_invoice_heading' => array( |
950 | 950 | 'id' => 'email_refunded_invoice_heading', |
951 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
952 | - 'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ), |
|
951 | + 'name' => __('Email Heading', 'invoicing'), |
|
952 | + 'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'), |
|
953 | 953 | 'type' => 'text', |
954 | - 'std' => __( 'Your invoice has been refunded', 'invoicing' ), |
|
954 | + 'std' => __('Your invoice has been refunded', 'invoicing'), |
|
955 | 955 | 'size' => 'large' |
956 | 956 | ), |
957 | 957 | 'email_refunded_invoice_admin_bcc' => array( |
958 | 958 | 'id' => 'email_refunded_invoice_admin_bcc', |
959 | - 'name' => __( 'Enable Admin BCC', 'invoicing' ), |
|
960 | - 'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ), |
|
959 | + 'name' => __('Enable Admin BCC', 'invoicing'), |
|
960 | + 'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'), |
|
961 | 961 | 'type' => 'checkbox', |
962 | 962 | 'std' => 1 |
963 | 963 | ), |
964 | 964 | 'email_refunded_invoice_body' => array( |
965 | 965 | 'id' => 'email_refunded_invoice_body', |
966 | - 'name' => __( 'Email Content', 'invoicing' ), |
|
967 | - 'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ), |
|
966 | + 'name' => __('Email Content', 'invoicing'), |
|
967 | + 'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'), |
|
968 | 968 | 'type' => 'rich_editor', |
969 | - 'std' => __( '<p>Hi {name},</p><p>Your invoice on {site_title} has been refunded.</p>', 'invoicing' ), |
|
969 | + 'std' => __('<p>Hi {name},</p><p>Your invoice on {site_title} has been refunded.</p>', 'invoicing'), |
|
970 | 970 | 'class' => 'large', |
971 | 971 | 'size' => '10' |
972 | 972 | ), |
@@ -974,46 +974,46 @@ discard block |
||
974 | 974 | 'user_invoice' => array( |
975 | 975 | 'email_user_invoice_header' => array( |
976 | 976 | 'id' => 'email_user_invoice_header', |
977 | - 'name' => '<h3>' . __( 'Customer Invoice', 'invoicing' ) . '</h3>', |
|
978 | - 'desc' => __( 'Customer invoice emails can be sent to customers containing their invoice information and payment links.', 'invoicing' ), |
|
977 | + 'name' => '<h3>' . __('Customer Invoice', 'invoicing') . '</h3>', |
|
978 | + 'desc' => __('Customer invoice emails can be sent to customers containing their invoice information and payment links.', 'invoicing'), |
|
979 | 979 | 'type' => 'header', |
980 | 980 | ), |
981 | 981 | 'email_user_invoice_active' => array( |
982 | 982 | 'id' => 'email_user_invoice_active', |
983 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
984 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
983 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
984 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
985 | 985 | 'type' => 'checkbox', |
986 | 986 | 'std' => 1 |
987 | 987 | ), |
988 | 988 | 'email_user_invoice_subject' => array( |
989 | 989 | 'id' => 'email_user_invoice_subject', |
990 | - 'name' => __( 'Subject', 'invoicing' ), |
|
991 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
990 | + 'name' => __('Subject', 'invoicing'), |
|
991 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
992 | 992 | 'type' => 'text', |
993 | - 'std' => __( '[{site_title}] Your invoice from {invoice_date}', 'invoicing' ), |
|
993 | + 'std' => __('[{site_title}] Your invoice from {invoice_date}', 'invoicing'), |
|
994 | 994 | 'size' => 'large' |
995 | 995 | ), |
996 | 996 | 'email_user_invoice_heading' => array( |
997 | 997 | 'id' => 'email_user_invoice_heading', |
998 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
999 | - 'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ), |
|
998 | + 'name' => __('Email Heading', 'invoicing'), |
|
999 | + 'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'), |
|
1000 | 1000 | 'type' => 'text', |
1001 | - 'std' => __( 'Your invoice {invoice_number} details', 'invoicing' ), |
|
1001 | + 'std' => __('Your invoice {invoice_number} details', 'invoicing'), |
|
1002 | 1002 | 'size' => 'large' |
1003 | 1003 | ), |
1004 | 1004 | 'email_user_invoice_admin_bcc' => array( |
1005 | 1005 | 'id' => 'email_user_invoice_admin_bcc', |
1006 | - 'name' => __( 'Enable Admin BCC', 'invoicing' ), |
|
1007 | - 'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ), |
|
1006 | + 'name' => __('Enable Admin BCC', 'invoicing'), |
|
1007 | + 'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'), |
|
1008 | 1008 | 'type' => 'checkbox', |
1009 | 1009 | 'std' => 1 |
1010 | 1010 | ), |
1011 | 1011 | 'email_user_invoice_body' => array( |
1012 | 1012 | 'id' => 'email_user_invoice_body', |
1013 | - 'name' => __( 'Email Content', 'invoicing' ), |
|
1014 | - 'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ), |
|
1013 | + 'name' => __('Email Content', 'invoicing'), |
|
1014 | + 'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'), |
|
1015 | 1015 | 'type' => 'rich_editor', |
1016 | - 'std' => __( '<p>Hi {name},</p><p>An invoice has been created for you on {site_title}. To view / pay for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing' ), |
|
1016 | + 'std' => __('<p>Hi {name},</p><p>An invoice has been created for you on {site_title}. To view / pay for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing'), |
|
1017 | 1017 | 'class' => 'large', |
1018 | 1018 | 'size' => '10' |
1019 | 1019 | ), |
@@ -1021,39 +1021,39 @@ discard block |
||
1021 | 1021 | 'user_note' => array( |
1022 | 1022 | 'email_user_note_header' => array( |
1023 | 1023 | 'id' => 'email_user_note_header', |
1024 | - 'name' => '<h3>' . __( 'Customer Note', 'invoicing' ) . '</h3>', |
|
1025 | - 'desc' => __( 'Customer note emails are sent when you add a note to an invoice/quote.', 'invoicing' ), |
|
1024 | + 'name' => '<h3>' . __('Customer Note', 'invoicing') . '</h3>', |
|
1025 | + 'desc' => __('Customer note emails are sent when you add a note to an invoice/quote.', 'invoicing'), |
|
1026 | 1026 | 'type' => 'header', |
1027 | 1027 | ), |
1028 | 1028 | 'email_user_note_active' => array( |
1029 | 1029 | 'id' => 'email_user_note_active', |
1030 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
1031 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
1030 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
1031 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
1032 | 1032 | 'type' => 'checkbox', |
1033 | 1033 | 'std' => 1 |
1034 | 1034 | ), |
1035 | 1035 | 'email_user_note_subject' => array( |
1036 | 1036 | 'id' => 'email_user_note_subject', |
1037 | - 'name' => __( 'Subject', 'invoicing' ), |
|
1038 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
1037 | + 'name' => __('Subject', 'invoicing'), |
|
1038 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
1039 | 1039 | 'type' => 'text', |
1040 | - 'std' => __( '[{site_title}] Note added to your {invoice_label} #{invoice_number} from {invoice_date}', 'invoicing' ), |
|
1040 | + 'std' => __('[{site_title}] Note added to your {invoice_label} #{invoice_number} from {invoice_date}', 'invoicing'), |
|
1041 | 1041 | 'size' => 'large' |
1042 | 1042 | ), |
1043 | 1043 | 'email_user_note_heading' => array( |
1044 | 1044 | 'id' => 'email_user_note_heading', |
1045 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
1046 | - 'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ), |
|
1045 | + 'name' => __('Email Heading', 'invoicing'), |
|
1046 | + 'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'), |
|
1047 | 1047 | 'type' => 'text', |
1048 | - 'std' => __( 'A note has been added to your {invoice_label}', 'invoicing' ), |
|
1048 | + 'std' => __('A note has been added to your {invoice_label}', 'invoicing'), |
|
1049 | 1049 | 'size' => 'large' |
1050 | 1050 | ), |
1051 | 1051 | 'email_user_note_body' => array( |
1052 | 1052 | 'id' => 'email_user_note_body', |
1053 | - 'name' => __( 'Email Content', 'invoicing' ), |
|
1054 | - 'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ), |
|
1053 | + 'name' => __('Email Content', 'invoicing'), |
|
1054 | + 'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'), |
|
1055 | 1055 | 'type' => 'rich_editor', |
1056 | - 'std' => __( '<p>Hi {name},</p><p>Following note has been added to your {invoice_label}:</p><blockquote class="wpinv-note">{customer_note}</blockquote>', 'invoicing' ), |
|
1056 | + 'std' => __('<p>Hi {name},</p><p>Following note has been added to your {invoice_label}:</p><blockquote class="wpinv-note">{customer_note}</blockquote>', 'invoicing'), |
|
1057 | 1057 | 'class' => 'large', |
1058 | 1058 | 'size' => '10' |
1059 | 1059 | ), |
@@ -1061,158 +1061,158 @@ discard block |
||
1061 | 1061 | 'overdue' => array( |
1062 | 1062 | 'email_overdue_header' => array( |
1063 | 1063 | 'id' => 'email_overdue_header', |
1064 | - 'name' => '<h3>' . __( 'Payment Reminder', 'invoicing' ) . '</h3>', |
|
1065 | - 'desc' => __( 'Payment reminder emails are sent to user automatically.', 'invoicing' ), |
|
1064 | + 'name' => '<h3>' . __('Payment Reminder', 'invoicing') . '</h3>', |
|
1065 | + 'desc' => __('Payment reminder emails are sent to user automatically.', 'invoicing'), |
|
1066 | 1066 | 'type' => 'header', |
1067 | 1067 | ), |
1068 | 1068 | 'email_overdue_active' => array( |
1069 | 1069 | 'id' => 'email_overdue_active', |
1070 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
1071 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
1070 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
1071 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
1072 | 1072 | 'type' => 'checkbox', |
1073 | 1073 | 'std' => 1 |
1074 | 1074 | ), |
1075 | 1075 | 'email_due_reminder_days' => array( |
1076 | 1076 | 'id' => 'email_due_reminder_days', |
1077 | - 'name' => __( 'When to Send', 'invoicing' ), |
|
1078 | - 'desc' => __( 'Check when you would like payment reminders sent out.', 'invoicing' ), |
|
1077 | + 'name' => __('When to Send', 'invoicing'), |
|
1078 | + 'desc' => __('Check when you would like payment reminders sent out.', 'invoicing'), |
|
1079 | 1079 | 'default' => '', |
1080 | 1080 | 'type' => 'multicheck', |
1081 | 1081 | 'options' => $overdue_days_options, |
1082 | 1082 | ), |
1083 | 1083 | 'email_overdue_subject' => array( |
1084 | 1084 | 'id' => 'email_overdue_subject', |
1085 | - 'name' => __( 'Subject', 'invoicing' ), |
|
1086 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
1085 | + 'name' => __('Subject', 'invoicing'), |
|
1086 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
1087 | 1087 | 'type' => 'text', |
1088 | - 'std' => __( '[{site_title}] Payment Reminder', 'invoicing' ), |
|
1088 | + 'std' => __('[{site_title}] Payment Reminder', 'invoicing'), |
|
1089 | 1089 | 'size' => 'large' |
1090 | 1090 | ), |
1091 | 1091 | 'email_overdue_heading' => array( |
1092 | 1092 | 'id' => 'email_overdue_heading', |
1093 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
1094 | - 'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ), |
|
1093 | + 'name' => __('Email Heading', 'invoicing'), |
|
1094 | + 'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'), |
|
1095 | 1095 | 'type' => 'text', |
1096 | - 'std' => __( 'Payment reminder for your invoice', 'invoicing' ), |
|
1096 | + 'std' => __('Payment reminder for your invoice', 'invoicing'), |
|
1097 | 1097 | 'size' => 'large' |
1098 | 1098 | ), |
1099 | 1099 | 'email_overdue_body' => array( |
1100 | 1100 | 'id' => 'email_overdue_body', |
1101 | - 'name' => __( 'Email Content', 'invoicing' ), |
|
1102 | - 'desc' => __( 'The content of the email.', 'invoicing' ), |
|
1101 | + 'name' => __('Email Content', 'invoicing'), |
|
1102 | + 'desc' => __('The content of the email.', 'invoicing'), |
|
1103 | 1103 | 'type' => 'rich_editor', |
1104 | - 'std' => __( '<p>Hi {full_name},</p><p>This is just a friendly reminder that your invoice <a href="{invoice_link}">#{invoice_number}</a> {is_was} due on {invoice_due_date}.</p><p>The total of this invoice is {invoice_total}</p><p>To view / pay now for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing' ), |
|
1104 | + 'std' => __('<p>Hi {full_name},</p><p>This is just a friendly reminder that your invoice <a href="{invoice_link}">#{invoice_number}</a> {is_was} due on {invoice_due_date}.</p><p>The total of this invoice is {invoice_total}</p><p>To view / pay now for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing'), |
|
1105 | 1105 | 'class' => 'large', |
1106 | 1106 | 'size' => 10, |
1107 | 1107 | ), |
1108 | 1108 | ), |
1109 | 1109 | ); |
1110 | 1110 | |
1111 | - return apply_filters( 'wpinv_get_emails', $emails ); |
|
1111 | + return apply_filters('wpinv_get_emails', $emails); |
|
1112 | 1112 | } |
1113 | 1113 | |
1114 | -function wpinv_settings_emails( $settings = array() ) { |
|
1114 | +function wpinv_settings_emails($settings = array()) { |
|
1115 | 1115 | $emails = wpinv_get_emails(); |
1116 | 1116 | |
1117 | - if ( !empty( $emails ) ) { |
|
1118 | - foreach ( $emails as $key => $email ) { |
|
1117 | + if (!empty($emails)) { |
|
1118 | + foreach ($emails as $key => $email) { |
|
1119 | 1119 | $settings[$key] = $email; |
1120 | 1120 | } |
1121 | 1121 | } |
1122 | 1122 | |
1123 | - return apply_filters( 'wpinv_settings_get_emails', $settings ); |
|
1123 | + return apply_filters('wpinv_settings_get_emails', $settings); |
|
1124 | 1124 | } |
1125 | -add_filter( 'wpinv_settings_emails', 'wpinv_settings_emails', 10, 1 ); |
|
1125 | +add_filter('wpinv_settings_emails', 'wpinv_settings_emails', 10, 1); |
|
1126 | 1126 | |
1127 | -function wpinv_settings_sections_emails( $settings ) { |
|
1127 | +function wpinv_settings_sections_emails($settings) { |
|
1128 | 1128 | $emails = wpinv_get_emails(); |
1129 | 1129 | |
1130 | 1130 | if (!empty($emails)) { |
1131 | - foreach ($emails as $key => $email) { |
|
1132 | - $settings[$key] = !empty( $email['email_' . $key . '_header']['name'] ) ? strip_tags( $email['email_' . $key . '_header']['name'] ) : $key; |
|
1131 | + foreach ($emails as $key => $email) { |
|
1132 | + $settings[$key] = !empty($email['email_' . $key . '_header']['name']) ? strip_tags($email['email_' . $key . '_header']['name']) : $key; |
|
1133 | 1133 | } |
1134 | 1134 | } |
1135 | 1135 | |
1136 | 1136 | return $settings; |
1137 | 1137 | } |
1138 | -add_filter( 'wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1 ); |
|
1138 | +add_filter('wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1); |
|
1139 | 1139 | |
1140 | -function wpinv_email_is_enabled( $email_type ) { |
|
1140 | +function wpinv_email_is_enabled($email_type) { |
|
1141 | 1141 | $emails = wpinv_get_emails(); |
1142 | - $enabled = isset( $emails[$email_type] ) && wpinv_get_option( 'email_'. $email_type . '_active', 0 ) ? true : false; |
|
1142 | + $enabled = isset($emails[$email_type]) && wpinv_get_option('email_' . $email_type . '_active', 0) ? true : false; |
|
1143 | 1143 | |
1144 | - return apply_filters( 'wpinv_email_is_enabled', $enabled, $email_type ); |
|
1144 | + return apply_filters('wpinv_email_is_enabled', $enabled, $email_type); |
|
1145 | 1145 | } |
1146 | 1146 | |
1147 | -function wpinv_email_get_recipient( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
1148 | - switch ( $email_type ) { |
|
1147 | +function wpinv_email_get_recipient($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
1148 | + switch ($email_type) { |
|
1149 | 1149 | case 'new_invoice': |
1150 | 1150 | case 'cancelled_invoice': |
1151 | 1151 | case 'failed_invoice': |
1152 | 1152 | $recipient = wpinv_get_admin_email(); |
1153 | 1153 | break; |
1154 | 1154 | default: |
1155 | - $invoice = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL ); |
|
1156 | - $recipient = !empty( $invoice ) ? $invoice->get_email() : ''; |
|
1155 | + $invoice = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL); |
|
1156 | + $recipient = !empty($invoice) ? $invoice->get_email() : ''; |
|
1157 | 1157 | break; |
1158 | 1158 | } |
1159 | 1159 | |
1160 | - return apply_filters( 'wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice ); |
|
1160 | + return apply_filters('wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice); |
|
1161 | 1161 | } |
1162 | 1162 | |
1163 | -function wpinv_email_get_subject( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
1164 | - $subject = wpinv_get_option( 'email_' . $email_type . '_subject' ); |
|
1165 | - $subject = __( $subject, 'invoicing' ); |
|
1163 | +function wpinv_email_get_subject($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
1164 | + $subject = wpinv_get_option('email_' . $email_type . '_subject'); |
|
1165 | + $subject = __($subject, 'invoicing'); |
|
1166 | 1166 | |
1167 | - $subject = wpinv_email_format_text( $subject, $invoice ); |
|
1167 | + $subject = wpinv_email_format_text($subject, $invoice); |
|
1168 | 1168 | |
1169 | - return apply_filters( 'wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice ); |
|
1169 | + return apply_filters('wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice); |
|
1170 | 1170 | } |
1171 | 1171 | |
1172 | -function wpinv_email_get_heading( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
1173 | - $email_heading = wpinv_get_option( 'email_' . $email_type . '_heading' ); |
|
1174 | - $email_heading = __( $email_heading, 'invoicing' ); |
|
1172 | +function wpinv_email_get_heading($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
1173 | + $email_heading = wpinv_get_option('email_' . $email_type . '_heading'); |
|
1174 | + $email_heading = __($email_heading, 'invoicing'); |
|
1175 | 1175 | |
1176 | - $email_heading = wpinv_email_format_text( $email_heading, $invoice ); |
|
1176 | + $email_heading = wpinv_email_format_text($email_heading, $invoice); |
|
1177 | 1177 | |
1178 | - return apply_filters( 'wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice ); |
|
1178 | + return apply_filters('wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice); |
|
1179 | 1179 | } |
1180 | 1180 | |
1181 | -function wpinv_email_get_content( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
1182 | - $content = wpinv_get_option( 'email_' . $email_type . '_body' ); |
|
1183 | - $content = __( $content, 'invoicing' ); |
|
1181 | +function wpinv_email_get_content($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
1182 | + $content = wpinv_get_option('email_' . $email_type . '_body'); |
|
1183 | + $content = __($content, 'invoicing'); |
|
1184 | 1184 | |
1185 | - $content = wpinv_email_format_text( $content, $invoice ); |
|
1185 | + $content = wpinv_email_format_text($content, $invoice); |
|
1186 | 1186 | |
1187 | - return apply_filters( 'wpinv_email_content', $content, $email_type, $invoice_id, $invoice ); |
|
1187 | + return apply_filters('wpinv_email_content', $content, $email_type, $invoice_id, $invoice); |
|
1188 | 1188 | } |
1189 | 1189 | |
1190 | -function wpinv_email_get_headers( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
1190 | +function wpinv_email_get_headers($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
1191 | 1191 | $from_name = wpinv_mail_get_from_address(); |
1192 | 1192 | $from_email = wpinv_mail_get_from_address(); |
1193 | 1193 | |
1194 | - $invoice = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL ); |
|
1194 | + $invoice = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL); |
|
1195 | 1195 | |
1196 | - $headers = "From: " . stripslashes_deep( html_entity_decode( $from_name, ENT_COMPAT, 'UTF-8' ) ) . " <$from_email>\r\n"; |
|
1197 | - $headers .= "Reply-To: ". $from_email . "\r\n"; |
|
1196 | + $headers = "From: " . stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8')) . " <$from_email>\r\n"; |
|
1197 | + $headers .= "Reply-To: " . $from_email . "\r\n"; |
|
1198 | 1198 | $headers .= "Content-Type: " . wpinv_mail_get_content_type() . "\r\n"; |
1199 | 1199 | |
1200 | - return apply_filters( 'wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice ); |
|
1200 | + return apply_filters('wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice); |
|
1201 | 1201 | } |
1202 | 1202 | |
1203 | -function wpinv_email_get_attachments( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
1203 | +function wpinv_email_get_attachments($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
1204 | 1204 | $attachments = array(); |
1205 | 1205 | |
1206 | - return apply_filters( 'wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice ); |
|
1206 | + return apply_filters('wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice); |
|
1207 | 1207 | } |
1208 | 1208 | |
1209 | -function wpinv_email_format_text( $content, $invoice ) { |
|
1209 | +function wpinv_email_format_text($content, $invoice) { |
|
1210 | 1210 | $replace_array = array( |
1211 | 1211 | '{site_title}' => wpinv_get_blogname(), |
1212 | - '{date}' => date_i18n( get_option( 'date_format' ), (int) current_time( 'timestamp' ) ), |
|
1212 | + '{date}' => date_i18n(get_option('date_format'), (int) current_time('timestamp')), |
|
1213 | 1213 | ); |
1214 | 1214 | |
1215 | - if ( !empty( $invoice->ID ) ) { |
|
1215 | + if (!empty($invoice->ID)) { |
|
1216 | 1216 | $replace_array = array_merge( |
1217 | 1217 | $replace_array, |
1218 | 1218 | array( |
@@ -1222,65 +1222,65 @@ discard block |
||
1222 | 1222 | '{last_name}' => $invoice->get_last_name(), |
1223 | 1223 | '{email}' => $invoice->get_email(), |
1224 | 1224 | '{invoice_number}' => $invoice->get_number(), |
1225 | - '{invoice_total}' => $invoice->get_total( true ), |
|
1226 | - '{invoice_link}' => $invoice->get_view_url( true ), |
|
1227 | - '{invoice_pay_link}'=> $invoice->get_view_url( true ), |
|
1228 | - '{invoice_date}' => $invoice->get_invoice_date( true ), |
|
1229 | - '{invoice_due_date}'=> $invoice->get_due_date( true ), |
|
1230 | - '{invoice_quote}' => $invoice->get_invoice_quote_type( $invoice->ID ), |
|
1231 | - '{invoice_label}' => $invoice->get_invoice_quote_type( $invoice->ID ), |
|
1232 | - '{is_was}' => strtotime( $invoice->get_due_date() ) < strtotime( date_i18n( 'Y-m-d' ) ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
1225 | + '{invoice_total}' => $invoice->get_total(true), |
|
1226 | + '{invoice_link}' => $invoice->get_view_url(true), |
|
1227 | + '{invoice_pay_link}'=> $invoice->get_view_url(true), |
|
1228 | + '{invoice_date}' => $invoice->get_invoice_date(true), |
|
1229 | + '{invoice_due_date}'=> $invoice->get_due_date(true), |
|
1230 | + '{invoice_quote}' => $invoice->get_invoice_quote_type($invoice->ID), |
|
1231 | + '{invoice_label}' => $invoice->get_invoice_quote_type($invoice->ID), |
|
1232 | + '{is_was}' => strtotime($invoice->get_due_date()) < strtotime(date_i18n('Y-m-d')) ? __('was', 'invoicing') : __('is', 'invoicing'), |
|
1233 | 1233 | ) |
1234 | 1234 | ); |
1235 | 1235 | } |
1236 | 1236 | |
1237 | - $replace_array = apply_filters( 'wpinv_email_format_text', $replace_array, $content, $invoice ); |
|
1237 | + $replace_array = apply_filters('wpinv_email_format_text', $replace_array, $content, $invoice); |
|
1238 | 1238 | |
1239 | - foreach ( $replace_array as $key => $value ) { |
|
1240 | - $content = str_replace( $key, $value, $content ); |
|
1239 | + foreach ($replace_array as $key => $value) { |
|
1240 | + $content = str_replace($key, $value, $content); |
|
1241 | 1241 | } |
1242 | 1242 | |
1243 | - return apply_filters( 'wpinv_email_content_replace', $content ); |
|
1243 | + return apply_filters('wpinv_email_content_replace', $content); |
|
1244 | 1244 | } |
1245 | 1245 | |
1246 | -function wpinv_email_style_body( $content ) { |
|
1246 | +function wpinv_email_style_body($content) { |
|
1247 | 1247 | // make sure we only inline CSS for html emails |
1248 | - if ( in_array( wpinv_mail_get_content_type(), array( 'text/html', 'multipart/alternative' ) ) && class_exists( 'DOMDocument' ) ) { |
|
1248 | + if (in_array(wpinv_mail_get_content_type(), array('text/html', 'multipart/alternative')) && class_exists('DOMDocument')) { |
|
1249 | 1249 | ob_start(); |
1250 | - wpinv_get_template( 'emails/wpinv-email-styles.php' ); |
|
1251 | - $css = apply_filters( 'wpinv_email_styles', ob_get_clean() ); |
|
1250 | + wpinv_get_template('emails/wpinv-email-styles.php'); |
|
1251 | + $css = apply_filters('wpinv_email_styles', ob_get_clean()); |
|
1252 | 1252 | |
1253 | 1253 | // apply CSS styles inline for picky email clients |
1254 | 1254 | try { |
1255 | - $emogrifier = new Emogrifier( $content, $css ); |
|
1255 | + $emogrifier = new Emogrifier($content, $css); |
|
1256 | 1256 | $content = $emogrifier->emogrify(); |
1257 | - } catch ( Exception $e ) { |
|
1258 | - wpinv_error_log( $e->getMessage(), 'emogrifier' ); |
|
1257 | + } catch (Exception $e) { |
|
1258 | + wpinv_error_log($e->getMessage(), 'emogrifier'); |
|
1259 | 1259 | } |
1260 | 1260 | } |
1261 | 1261 | return $content; |
1262 | 1262 | } |
1263 | 1263 | |
1264 | -function wpinv_email_header( $email_heading = '', $invoice = array(), $email_type = '', $sent_to_admin = false ) { |
|
1265 | - wpinv_get_template( 'emails/wpinv-email-header.php', array( 'email_heading' => $email_heading, 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) ); |
|
1264 | +function wpinv_email_header($email_heading = '', $invoice = array(), $email_type = '', $sent_to_admin = false) { |
|
1265 | + wpinv_get_template('emails/wpinv-email-header.php', array('email_heading' => $email_heading, 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin)); |
|
1266 | 1266 | } |
1267 | 1267 | |
1268 | 1268 | /** |
1269 | 1269 | * Get the email footer. |
1270 | 1270 | */ |
1271 | -function wpinv_email_footer( $invoice = array(), $email_type = '', $sent_to_admin = false ) { |
|
1272 | - wpinv_get_template( 'emails/wpinv-email-footer.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) ); |
|
1271 | +function wpinv_email_footer($invoice = array(), $email_type = '', $sent_to_admin = false) { |
|
1272 | + wpinv_get_template('emails/wpinv-email-footer.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin)); |
|
1273 | 1273 | } |
1274 | 1274 | |
1275 | -function wpinv_email_wrap_message( $message ) { |
|
1275 | +function wpinv_email_wrap_message($message) { |
|
1276 | 1276 | // Buffer |
1277 | 1277 | ob_start(); |
1278 | 1278 | |
1279 | - do_action( 'wpinv_email_header' ); |
|
1279 | + do_action('wpinv_email_header'); |
|
1280 | 1280 | |
1281 | - echo wpautop( wptexturize( $message ) ); |
|
1281 | + echo wpautop(wptexturize($message)); |
|
1282 | 1282 | |
1283 | - do_action( 'wpinv_email_footer' ); |
|
1283 | + do_action('wpinv_email_footer'); |
|
1284 | 1284 | |
1285 | 1285 | // Get contents |
1286 | 1286 | $message = ob_get_clean(); |
@@ -1288,92 +1288,92 @@ discard block |
||
1288 | 1288 | return $message; |
1289 | 1289 | } |
1290 | 1290 | |
1291 | -function wpinv_email_invoice_details( $invoice, $email_type = '', $sent_to_admin = false ) { |
|
1292 | - wpinv_get_template( 'emails/wpinv-email-invoice-details.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) ); |
|
1291 | +function wpinv_email_invoice_details($invoice, $email_type = '', $sent_to_admin = false) { |
|
1292 | + wpinv_get_template('emails/wpinv-email-invoice-details.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin)); |
|
1293 | 1293 | } |
1294 | 1294 | |
1295 | -function wpinv_email_invoice_items( $invoice, $email_type = '', $sent_to_admin = false ) { |
|
1296 | - wpinv_get_template( 'emails/wpinv-email-invoice-items.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) ); |
|
1295 | +function wpinv_email_invoice_items($invoice, $email_type = '', $sent_to_admin = false) { |
|
1296 | + wpinv_get_template('emails/wpinv-email-invoice-items.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin)); |
|
1297 | 1297 | } |
1298 | 1298 | |
1299 | -function wpinv_email_billing_details( $invoice, $email_type = '', $sent_to_admin = false ) { |
|
1300 | - wpinv_get_template( 'emails/wpinv-email-billing-details.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) ); |
|
1299 | +function wpinv_email_billing_details($invoice, $email_type = '', $sent_to_admin = false) { |
|
1300 | + wpinv_get_template('emails/wpinv-email-billing-details.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin)); |
|
1301 | 1301 | } |
1302 | 1302 | |
1303 | -function wpinv_send_customer_invoice( $data = array() ) { |
|
1304 | - $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL; |
|
1303 | +function wpinv_send_customer_invoice($data = array()) { |
|
1304 | + $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL; |
|
1305 | 1305 | |
1306 | - if ( empty( $invoice_id ) ) { |
|
1306 | + if (empty($invoice_id)) { |
|
1307 | 1307 | return; |
1308 | 1308 | } |
1309 | 1309 | |
1310 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
1311 | - wp_die( __( 'You do not have permission to send invoice notification', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
1310 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
1311 | + wp_die(__('You do not have permission to send invoice notification', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
1312 | 1312 | } |
1313 | 1313 | |
1314 | - $sent = wpinv_user_invoice_notification( $invoice_id ); |
|
1314 | + $sent = wpinv_user_invoice_notification($invoice_id); |
|
1315 | 1315 | |
1316 | 1316 | if ( -1 === $sent ) { |
1317 | 1317 | $status = 'email_disabled'; |
1318 | - } elseif ( $sent ) { |
|
1318 | + } elseif ($sent) { |
|
1319 | 1319 | $status = 'email_sent'; |
1320 | 1320 | } else { |
1321 | 1321 | $status = 'email_fail'; |
1322 | 1322 | } |
1323 | 1323 | |
1324 | - $redirect = add_query_arg( array( 'wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false ) ); |
|
1325 | - wp_redirect( $redirect ); |
|
1324 | + $redirect = add_query_arg(array('wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false)); |
|
1325 | + wp_redirect($redirect); |
|
1326 | 1326 | exit; |
1327 | 1327 | } |
1328 | -add_action( 'wpinv_send_invoice', 'wpinv_send_customer_invoice' ); |
|
1328 | +add_action('wpinv_send_invoice', 'wpinv_send_customer_invoice'); |
|
1329 | 1329 | |
1330 | -function wpinv_send_overdue_reminder( $data = array() ) { |
|
1331 | - $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL; |
|
1330 | +function wpinv_send_overdue_reminder($data = array()) { |
|
1331 | + $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL; |
|
1332 | 1332 | |
1333 | - if ( empty( $invoice_id ) ) { |
|
1333 | + if (empty($invoice_id)) { |
|
1334 | 1334 | return; |
1335 | 1335 | } |
1336 | 1336 | |
1337 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
1338 | - wp_die( __( 'You do not have permission to send reminder notification', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
1337 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
1338 | + wp_die(__('You do not have permission to send reminder notification', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
1339 | 1339 | } |
1340 | 1340 | |
1341 | - $sent = wpinv_send_payment_reminder_notification( $invoice_id ); |
|
1341 | + $sent = wpinv_send_payment_reminder_notification($invoice_id); |
|
1342 | 1342 | |
1343 | 1343 | $status = $sent ? 'email_sent' : 'email_fail'; |
1344 | 1344 | |
1345 | - $redirect = add_query_arg( array( 'wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false ) ); |
|
1346 | - wp_redirect( $redirect ); |
|
1345 | + $redirect = add_query_arg(array('wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false)); |
|
1346 | + wp_redirect($redirect); |
|
1347 | 1347 | exit; |
1348 | 1348 | } |
1349 | -add_action( 'wpinv_send_reminder', 'wpinv_send_overdue_reminder' ); |
|
1349 | +add_action('wpinv_send_reminder', 'wpinv_send_overdue_reminder'); |
|
1350 | 1350 | |
1351 | -function wpinv_send_customer_note_email( $data ) { |
|
1352 | - $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL; |
|
1351 | +function wpinv_send_customer_note_email($data) { |
|
1352 | + $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL; |
|
1353 | 1353 | |
1354 | - if ( empty( $invoice_id ) ) { |
|
1354 | + if (empty($invoice_id)) { |
|
1355 | 1355 | return; |
1356 | 1356 | } |
1357 | 1357 | |
1358 | - $sent = wpinv_user_note_notification( $invoice_id, $data ); |
|
1358 | + $sent = wpinv_user_note_notification($invoice_id, $data); |
|
1359 | 1359 | } |
1360 | -add_action( 'wpinv_new_customer_note', 'wpinv_send_customer_note_email', 10, 1 ); |
|
1360 | +add_action('wpinv_new_customer_note', 'wpinv_send_customer_note_email', 10, 1); |
|
1361 | 1361 | |
1362 | -function wpinv_add_notes_to_invoice_email( $invoice, $email_type, $sent_to_admin ) { |
|
1363 | - if ( !empty( $invoice ) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes( $invoice->ID, true ) ) { |
|
1364 | - $date_format = get_option( 'date_format' ); |
|
1365 | - $time_format = get_option( 'time_format' ); |
|
1362 | +function wpinv_add_notes_to_invoice_email($invoice, $email_type, $sent_to_admin) { |
|
1363 | + if (!empty($invoice) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes($invoice->ID, true)) { |
|
1364 | + $date_format = get_option('date_format'); |
|
1365 | + $time_format = get_option('time_format'); |
|
1366 | 1366 | ?> |
1367 | 1367 | <div id="wpinv-email-notes"> |
1368 | - <h3 class="wpinv-notes-t"><?php echo apply_filters( 'wpinv_email_invoice_notes_title', __( 'Invoice Notes', 'invoicing' ) ); ?></h3> |
|
1368 | + <h3 class="wpinv-notes-t"><?php echo apply_filters('wpinv_email_invoice_notes_title', __('Invoice Notes', 'invoicing')); ?></h3> |
|
1369 | 1369 | <ol class="wpinv-notes-lists"> |
1370 | 1370 | <?php |
1371 | - foreach ( $invoice_notes as $note ) { |
|
1372 | - $note_time = strtotime( $note->comment_date ); |
|
1371 | + foreach ($invoice_notes as $note) { |
|
1372 | + $note_time = strtotime($note->comment_date); |
|
1373 | 1373 | ?> |
1374 | 1374 | <li class="comment wpinv-note"> |
1375 | - <p class="wpinv-note-date meta"><?php printf( __( '%2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( $date_format, $note_time ), date_i18n( $time_format, $note_time ), $note_time ); ?></p> |
|
1376 | - <div class="wpinv-note-desc description"><?php echo wpautop( wptexturize( $note->comment_content ) ); ?></div> |
|
1375 | + <p class="wpinv-note-date meta"><?php printf(__('%2$s at %3$s', 'invoicing'), $note->comment_author, date_i18n($date_format, $note_time), date_i18n($time_format, $note_time), $note_time); ?></p> |
|
1376 | + <div class="wpinv-note-desc description"><?php echo wpautop(wptexturize($note->comment_content)); ?></div> |
|
1377 | 1377 | </li> |
1378 | 1378 | <?php |
1379 | 1379 | } |
@@ -1382,21 +1382,21 @@ discard block |
||
1382 | 1382 | <?php |
1383 | 1383 | } |
1384 | 1384 | } |
1385 | -add_action( 'wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3 ); |
|
1385 | +add_action('wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3); |
|
1386 | 1386 | |
1387 | 1387 | function wpinv_email_payment_reminders() { |
1388 | 1388 | global $wpi_auto_reminder; |
1389 | - if ( !wpinv_get_option( 'email_overdue_active' ) ) { |
|
1389 | + if (!wpinv_get_option('email_overdue_active')) { |
|
1390 | 1390 | return; |
1391 | 1391 | } |
1392 | 1392 | |
1393 | - if ( $reminder_days = wpinv_get_option( 'email_due_reminder_days' ) ) { |
|
1394 | - $reminder_days = is_array( $reminder_days ) ? array_values( $reminder_days ) : ''; |
|
1393 | + if ($reminder_days = wpinv_get_option('email_due_reminder_days')) { |
|
1394 | + $reminder_days = is_array($reminder_days) ? array_values($reminder_days) : ''; |
|
1395 | 1395 | |
1396 | - if ( empty( $reminder_days ) ) { |
|
1396 | + if (empty($reminder_days)) { |
|
1397 | 1397 | return; |
1398 | 1398 | } |
1399 | - $reminder_days = array_unique( array_map( 'absint', $reminder_days ) ); |
|
1399 | + $reminder_days = array_unique(array_map('absint', $reminder_days)); |
|
1400 | 1400 | |
1401 | 1401 | $args = array( |
1402 | 1402 | 'post_type' => 'wpi_invoice', |
@@ -1406,7 +1406,7 @@ discard block |
||
1406 | 1406 | 'meta_query' => array( |
1407 | 1407 | array( |
1408 | 1408 | 'key' => '_wpinv_due_date', |
1409 | - 'value' => array( '', 'none' ), |
|
1409 | + 'value' => array('', 'none'), |
|
1410 | 1410 | 'compare' => 'NOT IN', |
1411 | 1411 | ) |
1412 | 1412 | ), |
@@ -1415,143 +1415,143 @@ discard block |
||
1415 | 1415 | 'order' => 'ASC', |
1416 | 1416 | ); |
1417 | 1417 | |
1418 | - $invoices = get_posts( $args ); |
|
1418 | + $invoices = get_posts($args); |
|
1419 | 1419 | |
1420 | - if ( empty( $invoices ) ) { |
|
1420 | + if (empty($invoices)) { |
|
1421 | 1421 | return; |
1422 | 1422 | } |
1423 | 1423 | |
1424 | - $date_to_send = array(); |
|
1424 | + $date_to_send = array(); |
|
1425 | 1425 | |
1426 | - foreach ( $invoices as $id ) { |
|
1427 | - $due_date = get_post_meta( $id, '_wpinv_due_date', true ); |
|
1426 | + foreach ($invoices as $id) { |
|
1427 | + $due_date = get_post_meta($id, '_wpinv_due_date', true); |
|
1428 | 1428 | |
1429 | - foreach ( $reminder_days as $key => $days ) { |
|
1430 | - if ( $days !== '' ) { |
|
1431 | - $date_to_send[$id][] = date_i18n( 'Y-m-d', strtotime( $due_date ) + ( $days * DAY_IN_SECONDS ) ); |
|
1429 | + foreach ($reminder_days as $key => $days) { |
|
1430 | + if ($days !== '') { |
|
1431 | + $date_to_send[$id][] = date_i18n('Y-m-d', strtotime($due_date) + ($days * DAY_IN_SECONDS)); |
|
1432 | 1432 | } |
1433 | 1433 | } |
1434 | 1434 | } |
1435 | 1435 | |
1436 | - $today = date_i18n( 'Y-m-d' ); |
|
1436 | + $today = date_i18n('Y-m-d'); |
|
1437 | 1437 | $wpi_auto_reminder = true; |
1438 | 1438 | |
1439 | - foreach ( $date_to_send as $id => $values ) { |
|
1440 | - if ( in_array( $today, $values ) ) { |
|
1441 | - $sent = get_post_meta( $id, '_wpinv_reminder_sent', true ); |
|
1439 | + foreach ($date_to_send as $id => $values) { |
|
1440 | + if (in_array($today, $values)) { |
|
1441 | + $sent = get_post_meta($id, '_wpinv_reminder_sent', true); |
|
1442 | 1442 | |
1443 | - if ( isset( $sent ) && !empty( $sent ) ) { |
|
1444 | - if ( !in_array( $today, $sent ) ) { |
|
1445 | - do_action( 'wpinv_send_payment_reminder_notification', $id ); |
|
1443 | + if (isset($sent) && !empty($sent)) { |
|
1444 | + if (!in_array($today, $sent)) { |
|
1445 | + do_action('wpinv_send_payment_reminder_notification', $id); |
|
1446 | 1446 | } |
1447 | 1447 | } else { |
1448 | - do_action( 'wpinv_send_payment_reminder_notification', $id ); |
|
1448 | + do_action('wpinv_send_payment_reminder_notification', $id); |
|
1449 | 1449 | } |
1450 | 1450 | } |
1451 | 1451 | } |
1452 | 1452 | |
1453 | - $wpi_auto_reminder = false; |
|
1453 | + $wpi_auto_reminder = false; |
|
1454 | 1454 | } |
1455 | 1455 | } |
1456 | 1456 | |
1457 | -function wpinv_send_payment_reminder_notification( $invoice_id ) { |
|
1457 | +function wpinv_send_payment_reminder_notification($invoice_id) { |
|
1458 | 1458 | $email_type = 'overdue'; |
1459 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
1459 | + if (!wpinv_email_is_enabled($email_type)) { |
|
1460 | 1460 | return false; |
1461 | 1461 | } |
1462 | 1462 | |
1463 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1464 | - if ( empty( $invoice ) ) { |
|
1463 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1464 | + if (empty($invoice)) { |
|
1465 | 1465 | return false; |
1466 | 1466 | } |
1467 | 1467 | |
1468 | - if ( !$invoice->needs_payment() ) { |
|
1468 | + if (!$invoice->needs_payment()) { |
|
1469 | 1469 | return false; |
1470 | 1470 | } |
1471 | 1471 | |
1472 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
1473 | - if ( !is_email( $recipient ) ) { |
|
1472 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
1473 | + if (!is_email($recipient)) { |
|
1474 | 1474 | return false; |
1475 | 1475 | } |
1476 | 1476 | |
1477 | - do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type ); |
|
1477 | + do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type); |
|
1478 | 1478 | |
1479 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
1480 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
1481 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
1482 | - $message_body = wpinv_email_get_content( $email_type, $invoice_id, $invoice ); |
|
1483 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
1479 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
1480 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
1481 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
1482 | + $message_body = wpinv_email_get_content($email_type, $invoice_id, $invoice); |
|
1483 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
1484 | 1484 | |
1485 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
1485 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
1486 | 1486 | 'invoice' => $invoice, |
1487 | 1487 | 'email_type' => $email_type, |
1488 | 1488 | 'email_heading' => $email_heading, |
1489 | 1489 | 'sent_to_admin' => false, |
1490 | 1490 | 'plain_text' => false, |
1491 | 1491 | 'message_body' => $message_body |
1492 | - ) ); |
|
1492 | + )); |
|
1493 | 1493 | |
1494 | - $content = wpinv_email_format_text( $content, $invoice ); |
|
1494 | + $content = wpinv_email_format_text($content, $invoice); |
|
1495 | 1495 | |
1496 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
1497 | - if ( $sent ) { |
|
1498 | - do_action( 'wpinv_payment_reminder_sent', $invoice_id, $invoice ); |
|
1496 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
1497 | + if ($sent) { |
|
1498 | + do_action('wpinv_payment_reminder_sent', $invoice_id, $invoice); |
|
1499 | 1499 | } |
1500 | 1500 | |
1501 | - do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type ); |
|
1501 | + do_action('wpinv_post_send_invoice_notification', $invoice, $email_type); |
|
1502 | 1502 | |
1503 | 1503 | return $sent; |
1504 | 1504 | } |
1505 | -add_action( 'wpinv_send_payment_reminder_notification', 'wpinv_send_payment_reminder_notification', 10, 1 ); |
|
1505 | +add_action('wpinv_send_payment_reminder_notification', 'wpinv_send_payment_reminder_notification', 10, 1); |
|
1506 | 1506 | |
1507 | -function wpinv_payment_reminder_sent( $invoice_id, $invoice ) { |
|
1507 | +function wpinv_payment_reminder_sent($invoice_id, $invoice) { |
|
1508 | 1508 | global $wpi_auto_reminder; |
1509 | 1509 | |
1510 | - $sent = get_post_meta( $invoice_id, '_wpinv_reminder_sent', true ); |
|
1510 | + $sent = get_post_meta($invoice_id, '_wpinv_reminder_sent', true); |
|
1511 | 1511 | |
1512 | - if ( empty( $sent ) ) { |
|
1512 | + if (empty($sent)) { |
|
1513 | 1513 | $sent = array(); |
1514 | 1514 | } |
1515 | - $sent[] = date_i18n( 'Y-m-d' ); |
|
1515 | + $sent[] = date_i18n('Y-m-d'); |
|
1516 | 1516 | |
1517 | - update_post_meta( $invoice_id, '_wpinv_reminder_sent', $sent ); |
|
1517 | + update_post_meta($invoice_id, '_wpinv_reminder_sent', $sent); |
|
1518 | 1518 | |
1519 | - if ( $wpi_auto_reminder ) { // Auto reminder note. |
|
1520 | - $note = __( 'Automated reminder sent to the user.', 'invoicing' ); |
|
1521 | - $invoice->add_note( $note, false, false, true ); |
|
1519 | + if ($wpi_auto_reminder) { // Auto reminder note. |
|
1520 | + $note = __('Automated reminder sent to the user.', 'invoicing'); |
|
1521 | + $invoice->add_note($note, false, false, true); |
|
1522 | 1522 | } else { // Menual reminder note. |
1523 | - $note = __( 'Manual reminder sent to the user.', 'invoicing' ); |
|
1524 | - $invoice->add_note( $note ); |
|
1523 | + $note = __('Manual reminder sent to the user.', 'invoicing'); |
|
1524 | + $invoice->add_note($note); |
|
1525 | 1525 | } |
1526 | 1526 | } |
1527 | -add_action( 'wpinv_payment_reminder_sent', 'wpinv_payment_reminder_sent', 10, 2 ); |
|
1527 | +add_action('wpinv_payment_reminder_sent', 'wpinv_payment_reminder_sent', 10, 2); |
|
1528 | 1528 | |
1529 | -function wpinv_invoice_notification_set_locale( $invoice, $email_type, $site = false ) { |
|
1530 | - if ( empty( $invoice ) ) { |
|
1529 | +function wpinv_invoice_notification_set_locale($invoice, $email_type, $site = false) { |
|
1530 | + if (empty($invoice)) { |
|
1531 | 1531 | return; |
1532 | 1532 | } |
1533 | 1533 | |
1534 | - if ( is_int( $invoice ) ) { |
|
1535 | - $invoice = wpinv_get_invoice( $invoice ); |
|
1534 | + if (is_int($invoice)) { |
|
1535 | + $invoice = wpinv_get_invoice($invoice); |
|
1536 | 1536 | } |
1537 | 1537 | |
1538 | - if ( ! empty( $invoice ) && is_object( $invoice ) ) { |
|
1539 | - if ( ! $site && function_exists( 'get_user_locale' ) ) { |
|
1540 | - $locale = get_user_locale( $invoice->get_user_id() ); |
|
1538 | + if (!empty($invoice) && is_object($invoice)) { |
|
1539 | + if (!$site && function_exists('get_user_locale')) { |
|
1540 | + $locale = get_user_locale($invoice->get_user_id()); |
|
1541 | 1541 | } else { |
1542 | 1542 | $locale = get_locale(); |
1543 | 1543 | } |
1544 | 1544 | |
1545 | - wpinv_switch_to_locale( $locale ); |
|
1545 | + wpinv_switch_to_locale($locale); |
|
1546 | 1546 | } |
1547 | 1547 | } |
1548 | -add_action( 'wpinv_pre_send_invoice_notification', 'wpinv_invoice_notification_set_locale', 10, 3 ); |
|
1548 | +add_action('wpinv_pre_send_invoice_notification', 'wpinv_invoice_notification_set_locale', 10, 3); |
|
1549 | 1549 | |
1550 | -function wpinv_invoice_notification_restore_locale( $invoice, $email_type, $site = false ) { |
|
1551 | - if ( empty( $invoice ) ) { |
|
1550 | +function wpinv_invoice_notification_restore_locale($invoice, $email_type, $site = false) { |
|
1551 | + if (empty($invoice)) { |
|
1552 | 1552 | return; |
1553 | 1553 | } |
1554 | 1554 | |
1555 | 1555 | wpinv_restore_locale(); |
1556 | 1556 | } |
1557 | -add_action( 'wpinv_post_send_invoice_notification', 'wpinv_invoice_notification_restore_locale', 10, 3 ); |
|
1557 | +add_action('wpinv_post_send_invoice_notification', 'wpinv_invoice_notification_restore_locale', 10, 3); |
@@ -7,14 +7,14 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | function wpinv_get_invoice_cart_id() { |
15 | 15 | $wpinv_checkout = wpinv_get_checkout_session(); |
16 | 16 | |
17 | - if ( !empty( $wpinv_checkout['invoice_id'] ) ) { |
|
17 | + if (!empty($wpinv_checkout['invoice_id'])) { |
|
18 | 18 | return $wpinv_checkout['invoice_id']; |
19 | 19 | } |
20 | 20 | |
@@ -28,43 +28,43 @@ discard block |
||
28 | 28 | * @param bool $wp_error Whether to return false or WP_Error on failure. |
29 | 29 | * @return mixed The value 0 or WP_Error on failure. The WPInv_Invoice object on success. |
30 | 30 | */ |
31 | -function wpinv_insert_invoice( $invoice_data = array(), $wp_error = false ) { |
|
32 | - if ( empty( $invoice_data ) ) { |
|
31 | +function wpinv_insert_invoice($invoice_data = array(), $wp_error = false) { |
|
32 | + if (empty($invoice_data)) { |
|
33 | 33 | return false; |
34 | 34 | } |
35 | 35 | |
36 | - if ( !( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) ) { |
|
37 | - return $wp_error ? new WP_Error( 'wpinv_invalid_items', __( 'Invoice must have atleast one item.', 'invoicing' ) ) : 0; |
|
36 | + if (!(!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']))) { |
|
37 | + return $wp_error ? new WP_Error('wpinv_invalid_items', __('Invoice must have atleast one item.', 'invoicing')) : 0; |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | // If no user id is provided, default to the current user id |
41 | - if ( empty( $invoice_data['user_id'] ) ) { |
|
41 | + if (empty($invoice_data['user_id'])) { |
|
42 | 42 | $invoice_data['user_id'] = get_current_user_id(); |
43 | 43 | } |
44 | 44 | |
45 | - $invoice_data['invoice_id'] = !empty( $invoice_data['invoice_id'] ) ? (int)$invoice_data['invoice_id'] : 0; |
|
45 | + $invoice_data['invoice_id'] = !empty($invoice_data['invoice_id']) ? (int) $invoice_data['invoice_id'] : 0; |
|
46 | 46 | |
47 | - if ( empty( $invoice_data['status'] ) ) { |
|
47 | + if (empty($invoice_data['status'])) { |
|
48 | 48 | $invoice_data['status'] = 'wpi-pending'; |
49 | 49 | } |
50 | 50 | |
51 | - if ( empty( $invoice_data['ip'] ) ) { |
|
51 | + if (empty($invoice_data['ip'])) { |
|
52 | 52 | $invoice_data['ip'] = wpinv_get_ip(); |
53 | 53 | } |
54 | 54 | |
55 | 55 | // default invoice args, note that status is checked for validity in wpinv_create_invoice() |
56 | 56 | $default_args = array( |
57 | - 'invoice_id' => (int)$invoice_data['invoice_id'], |
|
58 | - 'user_id' => (int)$invoice_data['user_id'], |
|
57 | + 'invoice_id' => (int) $invoice_data['invoice_id'], |
|
58 | + 'user_id' => (int) $invoice_data['user_id'], |
|
59 | 59 | 'status' => $invoice_data['status'], |
60 | 60 | ); |
61 | 61 | |
62 | - $invoice = wpinv_create_invoice( $default_args, $invoice_data, true ); |
|
63 | - if ( is_wp_error( $invoice ) ) { |
|
62 | + $invoice = wpinv_create_invoice($default_args, $invoice_data, true); |
|
63 | + if (is_wp_error($invoice)) { |
|
64 | 64 | return $wp_error ? $invoice : 0; |
65 | 65 | } |
66 | 66 | |
67 | - if ( empty( $invoice_data['invoice_id'] ) ) { |
|
67 | + if (empty($invoice_data['invoice_id'])) { |
|
68 | 68 | //$invoice->add_note( wp_sprintf( __( 'Invoice is created with status %s.', 'invoicing' ), wpinv_status_nicename( $invoice->status ) ) ); |
69 | 69 | } |
70 | 70 | |
@@ -87,24 +87,24 @@ discard block |
||
87 | 87 | 'discount' => array(), |
88 | 88 | ); |
89 | 89 | |
90 | - if ( $user_id = (int)$invoice->get_user_id() ) { |
|
91 | - if ( $user_address = wpinv_get_user_address( $user_id ) ) { |
|
92 | - $default_user_info = wp_parse_args( $user_address, $default_user_info ); |
|
90 | + if ($user_id = (int) $invoice->get_user_id()) { |
|
91 | + if ($user_address = wpinv_get_user_address($user_id)) { |
|
92 | + $default_user_info = wp_parse_args($user_address, $default_user_info); |
|
93 | 93 | } |
94 | 94 | } |
95 | 95 | |
96 | - if ( empty( $invoice_data['user_info'] ) ) { |
|
96 | + if (empty($invoice_data['user_info'])) { |
|
97 | 97 | $invoice_data['user_info'] = array(); |
98 | 98 | } |
99 | 99 | |
100 | - $user_info = wp_parse_args( $invoice_data['user_info'], $default_user_info ); |
|
100 | + $user_info = wp_parse_args($invoice_data['user_info'], $default_user_info); |
|
101 | 101 | |
102 | - if ( empty( $user_info['first_name'] ) ) { |
|
102 | + if (empty($user_info['first_name'])) { |
|
103 | 103 | $user_info['first_name'] = $default_user_info['first_name']; |
104 | 104 | $user_info['last_name'] = $default_user_info['last_name']; |
105 | 105 | } |
106 | 106 | |
107 | - if ( empty( $user_info['country'] ) ) { |
|
107 | + if (empty($user_info['country'])) { |
|
108 | 108 | $user_info['country'] = $default_user_info['country']; |
109 | 109 | $user_info['state'] = $default_user_info['state']; |
110 | 110 | $user_info['city'] = $default_user_info['city']; |
@@ -113,13 +113,13 @@ discard block |
||
113 | 113 | $user_info['phone'] = $default_user_info['phone']; |
114 | 114 | } |
115 | 115 | |
116 | - if ( !empty( $user_info['discount'] ) && !is_array( $user_info['discount'] ) ) { |
|
117 | - $user_info['discount'] = (array)$user_info['discount']; |
|
116 | + if (!empty($user_info['discount']) && !is_array($user_info['discount'])) { |
|
117 | + $user_info['discount'] = (array) $user_info['discount']; |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | // Payment details |
121 | 121 | $payment_details = array(); |
122 | - if ( !empty( $invoice_data['payment_details'] ) ) { |
|
122 | + if (!empty($invoice_data['payment_details'])) { |
|
123 | 123 | $default_payment_details = array( |
124 | 124 | 'gateway' => 'manual', |
125 | 125 | 'gateway_title' => '', |
@@ -127,56 +127,56 @@ discard block |
||
127 | 127 | 'transaction_id' => '', |
128 | 128 | ); |
129 | 129 | |
130 | - $payment_details = wp_parse_args( $invoice_data['payment_details'], $default_payment_details ); |
|
130 | + $payment_details = wp_parse_args($invoice_data['payment_details'], $default_payment_details); |
|
131 | 131 | |
132 | - if ( empty( $payment_details['gateway'] ) ) { |
|
132 | + if (empty($payment_details['gateway'])) { |
|
133 | 133 | $payment_details['gateway'] = 'manual'; |
134 | 134 | } |
135 | 135 | |
136 | - if ( empty( $payment_details['currency'] ) ) { |
|
136 | + if (empty($payment_details['currency'])) { |
|
137 | 137 | $payment_details['currency'] = wpinv_get_default_country(); |
138 | 138 | } |
139 | 139 | |
140 | - if ( empty( $payment_details['gateway_title'] ) ) { |
|
141 | - $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label( $payment_details['gateway'] ); |
|
140 | + if (empty($payment_details['gateway_title'])) { |
|
141 | + $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label($payment_details['gateway']); |
|
142 | 142 | } |
143 | 143 | } |
144 | 144 | |
145 | - $invoice->set( 'status', ( !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'wpi-pending' ) ); |
|
146 | - |
|
147 | - if ( !empty( $payment_details ) ) { |
|
148 | - $invoice->set( 'currency', $payment_details['currency'] ); |
|
149 | - $invoice->set( 'gateway', $payment_details['gateway'] ); |
|
150 | - $invoice->set( 'gateway_title', $payment_details['gateway_title'] ); |
|
151 | - $invoice->set( 'transaction_id', $payment_details['transaction_id'] ); |
|
152 | - } |
|
153 | - |
|
154 | - $invoice->set( 'user_info', $user_info ); |
|
155 | - $invoice->set( 'first_name', $user_info['first_name'] ); |
|
156 | - $invoice->set( 'last_name', $user_info['last_name'] ); |
|
157 | - $invoice->set( 'address', $user_info['address'] ); |
|
158 | - $invoice->set( 'company', $user_info['company'] ); |
|
159 | - $invoice->set( 'vat_number', $user_info['vat_number'] ); |
|
160 | - $invoice->set( 'phone', $user_info['phone'] ); |
|
161 | - $invoice->set( 'city', $user_info['city'] ); |
|
162 | - $invoice->set( 'country', $user_info['country'] ); |
|
163 | - $invoice->set( 'state', $user_info['state'] ); |
|
164 | - $invoice->set( 'zip', $user_info['zip'] ); |
|
165 | - $invoice->set( 'discounts', $user_info['discount'] ); |
|
166 | - $invoice->set( 'ip', ( !empty( $invoice_data['ip'] ) ? $invoice_data['ip'] : wpinv_get_ip() ) ); |
|
167 | - $invoice->set( 'mode', ( wpinv_is_test_mode() ? 'test' : 'live' ) ); |
|
168 | - $invoice->set( 'parent_invoice', ( !empty( $invoice_data['parent'] ) ? absint( $invoice_data['parent'] ) : '' ) ); |
|
169 | - |
|
170 | - if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) { |
|
171 | - foreach ( $invoice_data['cart_details'] as $key => $item ) { |
|
172 | - $item_id = !empty( $item['id'] ) ? $item['id'] : 0; |
|
173 | - $quantity = !empty( $item['quantity'] ) ? $item['quantity'] : 1; |
|
174 | - $name = !empty( $item['name'] ) ? $item['name'] : ''; |
|
175 | - $item_price = isset( $item['item_price'] ) ? $item['item_price'] : ''; |
|
145 | + $invoice->set('status', (!empty($invoice_data['status']) ? $invoice_data['status'] : 'wpi-pending')); |
|
146 | + |
|
147 | + if (!empty($payment_details)) { |
|
148 | + $invoice->set('currency', $payment_details['currency']); |
|
149 | + $invoice->set('gateway', $payment_details['gateway']); |
|
150 | + $invoice->set('gateway_title', $payment_details['gateway_title']); |
|
151 | + $invoice->set('transaction_id', $payment_details['transaction_id']); |
|
152 | + } |
|
153 | + |
|
154 | + $invoice->set('user_info', $user_info); |
|
155 | + $invoice->set('first_name', $user_info['first_name']); |
|
156 | + $invoice->set('last_name', $user_info['last_name']); |
|
157 | + $invoice->set('address', $user_info['address']); |
|
158 | + $invoice->set('company', $user_info['company']); |
|
159 | + $invoice->set('vat_number', $user_info['vat_number']); |
|
160 | + $invoice->set('phone', $user_info['phone']); |
|
161 | + $invoice->set('city', $user_info['city']); |
|
162 | + $invoice->set('country', $user_info['country']); |
|
163 | + $invoice->set('state', $user_info['state']); |
|
164 | + $invoice->set('zip', $user_info['zip']); |
|
165 | + $invoice->set('discounts', $user_info['discount']); |
|
166 | + $invoice->set('ip', (!empty($invoice_data['ip']) ? $invoice_data['ip'] : wpinv_get_ip())); |
|
167 | + $invoice->set('mode', (wpinv_is_test_mode() ? 'test' : 'live')); |
|
168 | + $invoice->set('parent_invoice', (!empty($invoice_data['parent']) ? absint($invoice_data['parent']) : '')); |
|
169 | + |
|
170 | + if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details'])) { |
|
171 | + foreach ($invoice_data['cart_details'] as $key => $item) { |
|
172 | + $item_id = !empty($item['id']) ? $item['id'] : 0; |
|
173 | + $quantity = !empty($item['quantity']) ? $item['quantity'] : 1; |
|
174 | + $name = !empty($item['name']) ? $item['name'] : ''; |
|
175 | + $item_price = isset($item['item_price']) ? $item['item_price'] : ''; |
|
176 | 176 | |
177 | - $post_item = new WPInv_Item( $item_id ); |
|
178 | - if ( !empty( $post_item ) ) { |
|
179 | - $name = !empty( $name ) ? $name : $post_item->get_name(); |
|
177 | + $post_item = new WPInv_Item($item_id); |
|
178 | + if (!empty($post_item)) { |
|
179 | + $name = !empty($name) ? $name : $post_item->get_name(); |
|
180 | 180 | $item_price = $item_price !== '' ? $item_price : $post_item->get_price(); |
181 | 181 | } else { |
182 | 182 | continue; |
@@ -186,253 +186,253 @@ discard block |
||
186 | 186 | 'name' => $name, |
187 | 187 | 'quantity' => $quantity, |
188 | 188 | 'item_price' => $item_price, |
189 | - 'custom_price' => isset( $item['custom_price'] ) ? $item['custom_price'] : '', |
|
190 | - 'tax' => !empty( $item['tax'] ) ? $item['tax'] : 0.00, |
|
191 | - 'discount' => isset( $item['discount'] ) ? $item['discount'] : 0, |
|
192 | - 'meta' => isset( $item['meta'] ) ? $item['meta'] : array(), |
|
193 | - 'fees' => isset( $item['fees'] ) ? $item['fees'] : array(), |
|
189 | + 'custom_price' => isset($item['custom_price']) ? $item['custom_price'] : '', |
|
190 | + 'tax' => !empty($item['tax']) ? $item['tax'] : 0.00, |
|
191 | + 'discount' => isset($item['discount']) ? $item['discount'] : 0, |
|
192 | + 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
|
193 | + 'fees' => isset($item['fees']) ? $item['fees'] : array(), |
|
194 | 194 | ); |
195 | 195 | |
196 | - $invoice->add_item( $item_id, $args ); |
|
196 | + $invoice->add_item($item_id, $args); |
|
197 | 197 | } |
198 | 198 | } |
199 | 199 | |
200 | - $invoice->increase_tax( wpinv_get_cart_fee_tax() ); |
|
200 | + $invoice->increase_tax(wpinv_get_cart_fee_tax()); |
|
201 | 201 | |
202 | - if ( isset( $invoice_data['post_date'] ) ) { |
|
203 | - $invoice->set( 'date', $invoice_data['post_date'] ); |
|
202 | + if (isset($invoice_data['post_date'])) { |
|
203 | + $invoice->set('date', $invoice_data['post_date']); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | // Invoice due date |
207 | - if ( isset( $invoice_data['due_date'] ) ) { |
|
208 | - $invoice->set( 'due_date', $invoice_data['due_date'] ); |
|
207 | + if (isset($invoice_data['due_date'])) { |
|
208 | + $invoice->set('due_date', $invoice_data['due_date']); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | $invoice->save(); |
212 | 212 | |
213 | 213 | // Add notes |
214 | - if ( !empty( $invoice_data['private_note'] ) ) { |
|
215 | - $invoice->add_note( $invoice_data['private_note'] ); |
|
214 | + if (!empty($invoice_data['private_note'])) { |
|
215 | + $invoice->add_note($invoice_data['private_note']); |
|
216 | 216 | } |
217 | - if ( !empty( $invoice_data['user_note'] ) ) { |
|
218 | - $invoice->add_note( $invoice_data['user_note'], true ); |
|
217 | + if (!empty($invoice_data['user_note'])) { |
|
218 | + $invoice->add_note($invoice_data['user_note'], true); |
|
219 | 219 | } |
220 | 220 | |
221 | - do_action( 'wpinv_insert_invoice', $invoice->ID, $invoice_data ); |
|
221 | + do_action('wpinv_insert_invoice', $invoice->ID, $invoice_data); |
|
222 | 222 | |
223 | - if ( ! empty( $invoice->ID ) ) { |
|
223 | + if (!empty($invoice->ID)) { |
|
224 | 224 | global $wpi_userID, $wpinv_ip_address_country; |
225 | 225 | |
226 | 226 | $checkout_session = wpinv_get_checkout_session(); |
227 | 227 | |
228 | 228 | $data_session = array(); |
229 | 229 | $data_session['invoice_id'] = $invoice->ID; |
230 | - $data_session['cart_discounts'] = $invoice->get_discounts( true ); |
|
230 | + $data_session['cart_discounts'] = $invoice->get_discounts(true); |
|
231 | 231 | |
232 | - wpinv_set_checkout_session( $data_session ); |
|
232 | + wpinv_set_checkout_session($data_session); |
|
233 | 233 | |
234 | - $wpi_userID = (int)$invoice->get_user_id(); |
|
234 | + $wpi_userID = (int) $invoice->get_user_id(); |
|
235 | 235 | |
236 | - $_POST['country'] = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country(); |
|
236 | + $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
|
237 | 237 | $_POST['state'] = $invoice->state; |
238 | 238 | |
239 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
240 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
239 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
240 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
241 | 241 | |
242 | 242 | $wpinv_ip_address_country = $invoice->country; |
243 | 243 | |
244 | - $invoice = $invoice->recalculate_totals( true ); |
|
244 | + $invoice = $invoice->recalculate_totals(true); |
|
245 | 245 | |
246 | - wpinv_set_checkout_session( $checkout_session ); |
|
246 | + wpinv_set_checkout_session($checkout_session); |
|
247 | 247 | |
248 | 248 | return $invoice; |
249 | 249 | } |
250 | 250 | |
251 | - if ( $wp_error ) { |
|
252 | - if ( is_wp_error( $invoice ) ) { |
|
251 | + if ($wp_error) { |
|
252 | + if (is_wp_error($invoice)) { |
|
253 | 253 | return $invoice; |
254 | 254 | } else { |
255 | - return new WP_Error( 'wpinv_insert_invoice_error', __( 'Error in insert invoice.', 'invoicing' ) ); |
|
255 | + return new WP_Error('wpinv_insert_invoice_error', __('Error in insert invoice.', 'invoicing')); |
|
256 | 256 | } |
257 | 257 | } else { |
258 | 258 | return 0; |
259 | 259 | } |
260 | 260 | } |
261 | 261 | |
262 | -function wpinv_update_invoice( $invoice_data = array(), $wp_error = false ) { |
|
263 | - $invoice_ID = !empty( $invoice_data['ID'] ) ? absint( $invoice_data['ID'] ) : NULL; |
|
262 | +function wpinv_update_invoice($invoice_data = array(), $wp_error = false) { |
|
263 | + $invoice_ID = !empty($invoice_data['ID']) ? absint($invoice_data['ID']) : NULL; |
|
264 | 264 | |
265 | - if ( !$invoice_ID ) { |
|
266 | - if ( $wp_error ) { |
|
267 | - return new WP_Error( 'invalid_invoice_id', __( 'Invalid invoice ID.', 'invoicing' ) ); |
|
265 | + if (!$invoice_ID) { |
|
266 | + if ($wp_error) { |
|
267 | + return new WP_Error('invalid_invoice_id', __('Invalid invoice ID.', 'invoicing')); |
|
268 | 268 | } |
269 | 269 | return 0; |
270 | 270 | } |
271 | 271 | |
272 | - $invoice = wpinv_get_invoice( $invoice_ID ); |
|
272 | + $invoice = wpinv_get_invoice($invoice_ID); |
|
273 | 273 | |
274 | - $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring( true ) : NULL; |
|
274 | + $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring(true) : NULL; |
|
275 | 275 | |
276 | - if ( empty( $invoice->ID ) ) { |
|
277 | - if ( $wp_error ) { |
|
278 | - return new WP_Error( 'invalid_invoice', __( 'Invalid invoice.', 'invoicing' ) ); |
|
276 | + if (empty($invoice->ID)) { |
|
277 | + if ($wp_error) { |
|
278 | + return new WP_Error('invalid_invoice', __('Invalid invoice.', 'invoicing')); |
|
279 | 279 | } |
280 | 280 | return 0; |
281 | 281 | } |
282 | 282 | |
283 | - if ( !$invoice->has_status( array( 'wpi-pending' ) ) ) { |
|
284 | - if ( $wp_error ) { |
|
285 | - return new WP_Error( 'invalid_invoice_status', __( 'Only invoice with pending payment is allowed to update.', 'invoicing' ) ); |
|
283 | + if (!$invoice->has_status(array('wpi-pending'))) { |
|
284 | + if ($wp_error) { |
|
285 | + return new WP_Error('invalid_invoice_status', __('Only invoice with pending payment is allowed to update.', 'invoicing')); |
|
286 | 286 | } |
287 | 287 | return 0; |
288 | 288 | } |
289 | 289 | |
290 | 290 | // Invoice status |
291 | - if ( !empty( $invoice_data['status'] ) ) { |
|
292 | - $invoice->set( 'status', $invoice_data['status'] ); |
|
291 | + if (!empty($invoice_data['status'])) { |
|
292 | + $invoice->set('status', $invoice_data['status']); |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | // Invoice date |
296 | - if ( !empty( $invoice_data['post_date'] ) ) { |
|
297 | - $invoice->set( 'date', $invoice_data['post_date'] ); |
|
296 | + if (!empty($invoice_data['post_date'])) { |
|
297 | + $invoice->set('date', $invoice_data['post_date']); |
|
298 | 298 | } |
299 | 299 | |
300 | 300 | // Invoice due date |
301 | - if ( isset( $invoice_data['due_date'] ) ) { |
|
302 | - $invoice->set( 'due_date', $invoice_data['due_date'] ); |
|
301 | + if (isset($invoice_data['due_date'])) { |
|
302 | + $invoice->set('due_date', $invoice_data['due_date']); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | // Invoice IP address |
306 | - if ( !empty( $invoice_data['ip'] ) ) { |
|
307 | - $invoice->set( 'ip', $invoice_data['ip'] ); |
|
306 | + if (!empty($invoice_data['ip'])) { |
|
307 | + $invoice->set('ip', $invoice_data['ip']); |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | // User info |
311 | - if ( !empty( $invoice_data['user_info'] ) && is_array( $invoice_data['user_info'] ) ) { |
|
312 | - $user_info = wp_parse_args( $invoice_data['user_info'], $invoice->user_info ); |
|
311 | + if (!empty($invoice_data['user_info']) && is_array($invoice_data['user_info'])) { |
|
312 | + $user_info = wp_parse_args($invoice_data['user_info'], $invoice->user_info); |
|
313 | 313 | |
314 | - if ( $discounts = $invoice->get_discounts() ) { |
|
314 | + if ($discounts = $invoice->get_discounts()) { |
|
315 | 315 | $set_discount = $discounts; |
316 | 316 | } else { |
317 | 317 | $set_discount = ''; |
318 | 318 | } |
319 | 319 | |
320 | 320 | // Manage discount |
321 | - if ( !empty( $invoice_data['user_info']['discount'] ) ) { |
|
321 | + if (!empty($invoice_data['user_info']['discount'])) { |
|
322 | 322 | // Remove discount |
323 | - if ( $invoice_data['user_info']['discount'] == 'none' ) { |
|
323 | + if ($invoice_data['user_info']['discount'] == 'none') { |
|
324 | 324 | $set_discount = ''; |
325 | 325 | } else { |
326 | 326 | $set_discount = $invoice_data['user_info']['discount']; |
327 | 327 | } |
328 | 328 | |
329 | - $invoice->set( 'discounts', $set_discount ); |
|
329 | + $invoice->set('discounts', $set_discount); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | $user_info['discount'] = $set_discount; |
333 | 333 | |
334 | - $invoice->set( 'user_info', $user_info ); |
|
334 | + $invoice->set('user_info', $user_info); |
|
335 | 335 | } |
336 | 336 | |
337 | - if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) && $cart_details = $invoice_data['cart_details'] ) { |
|
338 | - $remove_items = !empty( $cart_details['remove_items'] ) && is_array( $cart_details['remove_items'] ) ? $cart_details['remove_items'] : array(); |
|
337 | + if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']) && $cart_details = $invoice_data['cart_details']) { |
|
338 | + $remove_items = !empty($cart_details['remove_items']) && is_array($cart_details['remove_items']) ? $cart_details['remove_items'] : array(); |
|
339 | 339 | |
340 | - if ( !empty( $remove_items[0]['id'] ) ) { |
|
341 | - foreach ( $remove_items as $item ) { |
|
342 | - $item_id = !empty( $item['id'] ) ? $item['id'] : 0; |
|
343 | - $quantity = !empty( $item['quantity'] ) ? $item['quantity'] : 1; |
|
344 | - if ( empty( $item_id ) ) { |
|
340 | + if (!empty($remove_items[0]['id'])) { |
|
341 | + foreach ($remove_items as $item) { |
|
342 | + $item_id = !empty($item['id']) ? $item['id'] : 0; |
|
343 | + $quantity = !empty($item['quantity']) ? $item['quantity'] : 1; |
|
344 | + if (empty($item_id)) { |
|
345 | 345 | continue; |
346 | 346 | } |
347 | 347 | |
348 | - foreach ( $invoice->cart_details as $cart_index => $cart_item ) { |
|
349 | - if ( $item_id == $cart_item['id'] ) { |
|
348 | + foreach ($invoice->cart_details as $cart_index => $cart_item) { |
|
349 | + if ($item_id == $cart_item['id']) { |
|
350 | 350 | $args = array( |
351 | 351 | 'id' => $item_id, |
352 | 352 | 'quantity' => $quantity, |
353 | 353 | 'cart_index' => $cart_index |
354 | 354 | ); |
355 | 355 | |
356 | - $invoice->remove_item( $item_id, $args ); |
|
356 | + $invoice->remove_item($item_id, $args); |
|
357 | 357 | break; |
358 | 358 | } |
359 | 359 | } |
360 | 360 | } |
361 | 361 | } |
362 | 362 | |
363 | - $add_items = !empty( $cart_details['add_items'] ) && is_array( $cart_details['add_items'] ) ? $cart_details['add_items'] : array(); |
|
363 | + $add_items = !empty($cart_details['add_items']) && is_array($cart_details['add_items']) ? $cart_details['add_items'] : array(); |
|
364 | 364 | |
365 | - if ( !empty( $add_items[0]['id'] ) ) { |
|
366 | - foreach ( $add_items as $item ) { |
|
367 | - $item_id = !empty( $item['id'] ) ? $item['id'] : 0; |
|
368 | - $post_item = new WPInv_Item( $item_id ); |
|
369 | - if ( empty( $post_item ) ) { |
|
365 | + if (!empty($add_items[0]['id'])) { |
|
366 | + foreach ($add_items as $item) { |
|
367 | + $item_id = !empty($item['id']) ? $item['id'] : 0; |
|
368 | + $post_item = new WPInv_Item($item_id); |
|
369 | + if (empty($post_item)) { |
|
370 | 370 | continue; |
371 | 371 | } |
372 | 372 | |
373 | 373 | $valid_item = true; |
374 | - if ( !empty( $recurring_item ) ) { |
|
375 | - if ( $recurring_item->ID != $item_id ) { |
|
374 | + if (!empty($recurring_item)) { |
|
375 | + if ($recurring_item->ID != $item_id) { |
|
376 | 376 | $valid_item = false; |
377 | 377 | } |
378 | - } else if ( wpinv_is_recurring_item( $item_id ) ) { |
|
378 | + } else if (wpinv_is_recurring_item($item_id)) { |
|
379 | 379 | $valid_item = false; |
380 | 380 | } |
381 | 381 | |
382 | - if ( !$valid_item ) { |
|
383 | - if ( $wp_error ) { |
|
384 | - return new WP_Error( 'invalid_invoice_item', __( 'You can not add item because recurring item must be paid individually!', 'invoicing' ) ); |
|
382 | + if (!$valid_item) { |
|
383 | + if ($wp_error) { |
|
384 | + return new WP_Error('invalid_invoice_item', __('You can not add item because recurring item must be paid individually!', 'invoicing')); |
|
385 | 385 | } |
386 | 386 | return 0; |
387 | 387 | } |
388 | 388 | |
389 | - $quantity = !empty( $item['quantity'] ) ? $item['quantity'] : 1; |
|
390 | - $name = !empty( $item['name'] ) ? $item['name'] : $post_item->get_name(); |
|
391 | - $item_price = isset( $item['item_price'] ) ? $item['item_price'] : $post_item->get_price(); |
|
389 | + $quantity = !empty($item['quantity']) ? $item['quantity'] : 1; |
|
390 | + $name = !empty($item['name']) ? $item['name'] : $post_item->get_name(); |
|
391 | + $item_price = isset($item['item_price']) ? $item['item_price'] : $post_item->get_price(); |
|
392 | 392 | |
393 | 393 | $args = array( |
394 | 394 | 'name' => $name, |
395 | 395 | 'quantity' => $quantity, |
396 | 396 | 'item_price' => $item_price, |
397 | - 'custom_price' => isset( $item['custom_price'] ) ? $item['custom_price'] : '', |
|
398 | - 'tax' => !empty( $item['tax'] ) ? $item['tax'] : 0, |
|
399 | - 'discount' => isset( $item['discount'] ) ? $item['discount'] : 0, |
|
400 | - 'meta' => isset( $item['meta'] ) ? $item['meta'] : array(), |
|
401 | - 'fees' => isset( $item['fees'] ) ? $item['fees'] : array(), |
|
397 | + 'custom_price' => isset($item['custom_price']) ? $item['custom_price'] : '', |
|
398 | + 'tax' => !empty($item['tax']) ? $item['tax'] : 0, |
|
399 | + 'discount' => isset($item['discount']) ? $item['discount'] : 0, |
|
400 | + 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
|
401 | + 'fees' => isset($item['fees']) ? $item['fees'] : array(), |
|
402 | 402 | ); |
403 | 403 | |
404 | - $invoice->add_item( $item_id, $args ); |
|
404 | + $invoice->add_item($item_id, $args); |
|
405 | 405 | } |
406 | 406 | } |
407 | 407 | } |
408 | 408 | |
409 | 409 | // Payment details |
410 | - if ( !empty( $invoice_data['payment_details'] ) && $payment_details = $invoice_data['payment_details'] ) { |
|
411 | - if ( !empty( $payment_details['gateway'] ) ) { |
|
412 | - $invoice->set( 'gateway', $payment_details['gateway'] ); |
|
410 | + if (!empty($invoice_data['payment_details']) && $payment_details = $invoice_data['payment_details']) { |
|
411 | + if (!empty($payment_details['gateway'])) { |
|
412 | + $invoice->set('gateway', $payment_details['gateway']); |
|
413 | 413 | } |
414 | 414 | |
415 | - if ( !empty( $payment_details['transaction_id'] ) ) { |
|
416 | - $invoice->set( 'transaction_id', $payment_details['transaction_id'] ); |
|
415 | + if (!empty($payment_details['transaction_id'])) { |
|
416 | + $invoice->set('transaction_id', $payment_details['transaction_id']); |
|
417 | 417 | } |
418 | 418 | } |
419 | 419 | |
420 | - do_action( 'wpinv_pre_update_invoice', $invoice->ID, $invoice_data ); |
|
420 | + do_action('wpinv_pre_update_invoice', $invoice->ID, $invoice_data); |
|
421 | 421 | |
422 | 422 | // Parent invoice |
423 | - if ( !empty( $invoice_data['parent'] ) ) { |
|
424 | - $invoice->set( 'parent_invoice', $invoice_data['parent'] ); |
|
423 | + if (!empty($invoice_data['parent'])) { |
|
424 | + $invoice->set('parent_invoice', $invoice_data['parent']); |
|
425 | 425 | } |
426 | 426 | |
427 | 427 | // Save invoice data. |
428 | 428 | $invoice->save(); |
429 | 429 | |
430 | - if ( empty( $invoice->ID ) || is_wp_error( $invoice ) ) { |
|
431 | - if ( $wp_error ) { |
|
432 | - if ( is_wp_error( $invoice ) ) { |
|
430 | + if (empty($invoice->ID) || is_wp_error($invoice)) { |
|
431 | + if ($wp_error) { |
|
432 | + if (is_wp_error($invoice)) { |
|
433 | 433 | return $invoice; |
434 | 434 | } else { |
435 | - return new WP_Error( 'wpinv_update_invoice_error', __( 'Error in update invoice.', 'invoicing' ) ); |
|
435 | + return new WP_Error('wpinv_update_invoice_error', __('Error in update invoice.', 'invoicing')); |
|
436 | 436 | } |
437 | 437 | } else { |
438 | 438 | return 0; |
@@ -440,13 +440,13 @@ discard block |
||
440 | 440 | } |
441 | 441 | |
442 | 442 | // Add private note |
443 | - if ( !empty( $invoice_data['private_note'] ) ) { |
|
444 | - $invoice->add_note( $invoice_data['private_note'] ); |
|
443 | + if (!empty($invoice_data['private_note'])) { |
|
444 | + $invoice->add_note($invoice_data['private_note']); |
|
445 | 445 | } |
446 | 446 | |
447 | 447 | // Add user note |
448 | - if ( !empty( $invoice_data['user_note'] ) ) { |
|
449 | - $invoice->add_note( $invoice_data['user_note'], true ); |
|
448 | + if (!empty($invoice_data['user_note'])) { |
|
449 | + $invoice->add_note($invoice_data['user_note'], true); |
|
450 | 450 | } |
451 | 451 | |
452 | 452 | global $wpi_userID, $wpinv_ip_address_country; |
@@ -455,450 +455,450 @@ discard block |
||
455 | 455 | |
456 | 456 | $data_session = array(); |
457 | 457 | $data_session['invoice_id'] = $invoice->ID; |
458 | - $data_session['cart_discounts'] = $invoice->get_discounts( true ); |
|
458 | + $data_session['cart_discounts'] = $invoice->get_discounts(true); |
|
459 | 459 | |
460 | - wpinv_set_checkout_session( $data_session ); |
|
460 | + wpinv_set_checkout_session($data_session); |
|
461 | 461 | |
462 | - $wpi_userID = (int)$invoice->get_user_id(); |
|
462 | + $wpi_userID = (int) $invoice->get_user_id(); |
|
463 | 463 | |
464 | - $_POST['country'] = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country(); |
|
464 | + $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
|
465 | 465 | $_POST['state'] = $invoice->state; |
466 | 466 | |
467 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
468 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
467 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
468 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
469 | 469 | |
470 | 470 | $wpinv_ip_address_country = $invoice->country; |
471 | 471 | |
472 | - $invoice = $invoice->recalculate_totals( true ); |
|
472 | + $invoice = $invoice->recalculate_totals(true); |
|
473 | 473 | |
474 | - do_action( 'wpinv_post_update_invoice', $invoice->ID, $invoice_data ); |
|
474 | + do_action('wpinv_post_update_invoice', $invoice->ID, $invoice_data); |
|
475 | 475 | |
476 | - wpinv_set_checkout_session( $checkout_session ); |
|
476 | + wpinv_set_checkout_session($checkout_session); |
|
477 | 477 | |
478 | 478 | return $invoice; |
479 | 479 | } |
480 | 480 | |
481 | -function wpinv_get_invoice( $invoice_id = 0, $cart = false ) { |
|
482 | - if ( $cart && empty( $invoice_id ) ) { |
|
483 | - $invoice_id = (int)wpinv_get_invoice_cart_id(); |
|
481 | +function wpinv_get_invoice($invoice_id = 0, $cart = false) { |
|
482 | + if ($cart && empty($invoice_id)) { |
|
483 | + $invoice_id = (int) wpinv_get_invoice_cart_id(); |
|
484 | 484 | } |
485 | 485 | |
486 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
486 | + $invoice = new WPInv_Invoice($invoice_id); |
|
487 | 487 | |
488 | - if ( ! empty( $invoice ) && ! empty( $invoice->ID ) ) { |
|
488 | + if (!empty($invoice) && !empty($invoice->ID)) { |
|
489 | 489 | return $invoice; |
490 | 490 | } |
491 | 491 | |
492 | 492 | return NULL; |
493 | 493 | } |
494 | 494 | |
495 | -function wpinv_get_invoice_cart( $invoice_id = 0 ) { |
|
496 | - return wpinv_get_invoice( $invoice_id, true ); |
|
495 | +function wpinv_get_invoice_cart($invoice_id = 0) { |
|
496 | + return wpinv_get_invoice($invoice_id, true); |
|
497 | 497 | } |
498 | 498 | |
499 | -function wpinv_get_invoice_description( $invoice_id = 0 ) { |
|
500 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
499 | +function wpinv_get_invoice_description($invoice_id = 0) { |
|
500 | + $invoice = new WPInv_Invoice($invoice_id); |
|
501 | 501 | return $invoice->get_description(); |
502 | 502 | } |
503 | 503 | |
504 | -function wpinv_get_invoice_currency_code( $invoice_id = 0 ) { |
|
505 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
504 | +function wpinv_get_invoice_currency_code($invoice_id = 0) { |
|
505 | + $invoice = new WPInv_Invoice($invoice_id); |
|
506 | 506 | return $invoice->get_currency(); |
507 | 507 | } |
508 | 508 | |
509 | -function wpinv_get_payment_user_email( $invoice_id ) { |
|
510 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
509 | +function wpinv_get_payment_user_email($invoice_id) { |
|
510 | + $invoice = new WPInv_Invoice($invoice_id); |
|
511 | 511 | return $invoice->get_email(); |
512 | 512 | } |
513 | 513 | |
514 | -function wpinv_get_user_id( $invoice_id ) { |
|
515 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
514 | +function wpinv_get_user_id($invoice_id) { |
|
515 | + $invoice = new WPInv_Invoice($invoice_id); |
|
516 | 516 | return $invoice->get_user_id(); |
517 | 517 | } |
518 | 518 | |
519 | -function wpinv_get_invoice_status( $invoice_id, $return_label = false ) { |
|
520 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
519 | +function wpinv_get_invoice_status($invoice_id, $return_label = false) { |
|
520 | + $invoice = new WPInv_Invoice($invoice_id); |
|
521 | 521 | |
522 | - return $invoice->get_status( $return_label ); |
|
522 | + return $invoice->get_status($return_label); |
|
523 | 523 | } |
524 | 524 | |
525 | -function wpinv_get_payment_gateway( $invoice_id, $return_label = false ) { |
|
526 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
525 | +function wpinv_get_payment_gateway($invoice_id, $return_label = false) { |
|
526 | + $invoice = new WPInv_Invoice($invoice_id); |
|
527 | 527 | |
528 | - return $invoice->get_gateway( $return_label ); |
|
528 | + return $invoice->get_gateway($return_label); |
|
529 | 529 | } |
530 | 530 | |
531 | -function wpinv_get_payment_gateway_name( $invoice_id ) { |
|
532 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
531 | +function wpinv_get_payment_gateway_name($invoice_id) { |
|
532 | + $invoice = new WPInv_Invoice($invoice_id); |
|
533 | 533 | |
534 | 534 | return $invoice->get_gateway_title(); |
535 | 535 | } |
536 | 536 | |
537 | -function wpinv_get_payment_transaction_id( $invoice_id ) { |
|
538 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
537 | +function wpinv_get_payment_transaction_id($invoice_id) { |
|
538 | + $invoice = new WPInv_Invoice($invoice_id); |
|
539 | 539 | |
540 | 540 | return $invoice->get_transaction_id(); |
541 | 541 | } |
542 | 542 | |
543 | -function wpinv_get_id_by_transaction_id( $key ) { |
|
543 | +function wpinv_get_id_by_transaction_id($key) { |
|
544 | 544 | global $wpdb; |
545 | 545 | |
546 | - $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key ) ); |
|
546 | + $invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key)); |
|
547 | 547 | |
548 | - if ( $invoice_id != NULL ) |
|
548 | + if ($invoice_id != NULL) |
|
549 | 549 | return $invoice_id; |
550 | 550 | |
551 | 551 | return 0; |
552 | 552 | } |
553 | 553 | |
554 | -function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) { |
|
555 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
554 | +function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) { |
|
555 | + $invoice = new WPInv_Invoice($invoice_id); |
|
556 | 556 | |
557 | - return $invoice->get_meta( $meta_key, $single ); |
|
557 | + return $invoice->get_meta($meta_key, $single); |
|
558 | 558 | } |
559 | 559 | |
560 | -function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) { |
|
561 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
560 | +function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '') { |
|
561 | + $invoice = new WPInv_Invoice($invoice_id); |
|
562 | 562 | |
563 | - return $invoice->update_meta( $meta_key, $meta_value, $prev_value ); |
|
563 | + return $invoice->update_meta($meta_key, $meta_value, $prev_value); |
|
564 | 564 | } |
565 | 565 | |
566 | -function wpinv_get_items( $invoice_id = 0 ) { |
|
567 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
566 | +function wpinv_get_items($invoice_id = 0) { |
|
567 | + $invoice = wpinv_get_invoice($invoice_id); |
|
568 | 568 | |
569 | 569 | $items = $invoice->get_items(); |
570 | 570 | $invoice_currency = $invoice->get_currency(); |
571 | 571 | |
572 | - if ( !empty( $items ) && is_array( $items ) ) { |
|
573 | - foreach ( $items as $key => $item ) { |
|
572 | + if (!empty($items) && is_array($items)) { |
|
573 | + foreach ($items as $key => $item) { |
|
574 | 574 | $items[$key]['currency'] = $invoice_currency; |
575 | 575 | |
576 | - if ( !isset( $item['subtotal'] ) ) { |
|
576 | + if (!isset($item['subtotal'])) { |
|
577 | 577 | $items[$key]['subtotal'] = $items[$key]['amount'] * 1; |
578 | 578 | } |
579 | 579 | } |
580 | 580 | } |
581 | 581 | |
582 | - return apply_filters( 'wpinv_get_items', $items, $invoice_id ); |
|
582 | + return apply_filters('wpinv_get_items', $items, $invoice_id); |
|
583 | 583 | } |
584 | 584 | |
585 | -function wpinv_get_fees( $invoice_id = 0 ) { |
|
586 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
585 | +function wpinv_get_fees($invoice_id = 0) { |
|
586 | + $invoice = wpinv_get_invoice($invoice_id); |
|
587 | 587 | $fees = $invoice->get_fees(); |
588 | 588 | |
589 | - return apply_filters( 'wpinv_get_fees', $fees, $invoice_id ); |
|
589 | + return apply_filters('wpinv_get_fees', $fees, $invoice_id); |
|
590 | 590 | } |
591 | 591 | |
592 | -function wpinv_get_invoice_ip( $invoice_id ) { |
|
593 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
592 | +function wpinv_get_invoice_ip($invoice_id) { |
|
593 | + $invoice = new WPInv_Invoice($invoice_id); |
|
594 | 594 | return $invoice->get_ip(); |
595 | 595 | } |
596 | 596 | |
597 | -function wpinv_get_invoice_user_info( $invoice_id ) { |
|
598 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
597 | +function wpinv_get_invoice_user_info($invoice_id) { |
|
598 | + $invoice = new WPInv_Invoice($invoice_id); |
|
599 | 599 | return $invoice->get_user_info(); |
600 | 600 | } |
601 | 601 | |
602 | -function wpinv_subtotal( $invoice_id = 0, $currency = false ) { |
|
603 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
602 | +function wpinv_subtotal($invoice_id = 0, $currency = false) { |
|
603 | + $invoice = new WPInv_Invoice($invoice_id); |
|
604 | 604 | |
605 | - return $invoice->get_subtotal( $currency ); |
|
605 | + return $invoice->get_subtotal($currency); |
|
606 | 606 | } |
607 | 607 | |
608 | -function wpinv_tax( $invoice_id = 0, $currency = false ) { |
|
609 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
608 | +function wpinv_tax($invoice_id = 0, $currency = false) { |
|
609 | + $invoice = new WPInv_Invoice($invoice_id); |
|
610 | 610 | |
611 | - return $invoice->get_tax( $currency ); |
|
611 | + return $invoice->get_tax($currency); |
|
612 | 612 | } |
613 | 613 | |
614 | -function wpinv_discount( $invoice_id = 0, $currency = false, $dash = false ) { |
|
615 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
614 | +function wpinv_discount($invoice_id = 0, $currency = false, $dash = false) { |
|
615 | + $invoice = wpinv_get_invoice($invoice_id); |
|
616 | 616 | |
617 | - return $invoice->get_discount( $currency, $dash ); |
|
617 | + return $invoice->get_discount($currency, $dash); |
|
618 | 618 | } |
619 | 619 | |
620 | -function wpinv_discount_code( $invoice_id = 0 ) { |
|
621 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
620 | +function wpinv_discount_code($invoice_id = 0) { |
|
621 | + $invoice = new WPInv_Invoice($invoice_id); |
|
622 | 622 | |
623 | 623 | return $invoice->get_discount_code(); |
624 | 624 | } |
625 | 625 | |
626 | -function wpinv_payment_total( $invoice_id = 0, $currency = false ) { |
|
627 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
626 | +function wpinv_payment_total($invoice_id = 0, $currency = false) { |
|
627 | + $invoice = new WPInv_Invoice($invoice_id); |
|
628 | 628 | |
629 | - return $invoice->get_total( $currency ); |
|
629 | + return $invoice->get_total($currency); |
|
630 | 630 | } |
631 | 631 | |
632 | -function wpinv_get_date_created( $invoice_id = 0, $format = '' ) { |
|
633 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
632 | +function wpinv_get_date_created($invoice_id = 0, $format = '') { |
|
633 | + $invoice = new WPInv_Invoice($invoice_id); |
|
634 | 634 | |
635 | - $format = !empty( $format ) ? $format : get_option( 'date_format' ); |
|
635 | + $format = !empty($format) ? $format : get_option('date_format'); |
|
636 | 636 | $date_created = $invoice->get_created_date(); |
637 | - $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_created ) ) : ''; |
|
637 | + $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_created)) : ''; |
|
638 | 638 | |
639 | 639 | return $date_created; |
640 | 640 | } |
641 | 641 | |
642 | -function wpinv_get_invoice_date( $invoice_id = 0, $format = '', $default = true ) { |
|
643 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
642 | +function wpinv_get_invoice_date($invoice_id = 0, $format = '', $default = true) { |
|
643 | + $invoice = new WPInv_Invoice($invoice_id); |
|
644 | 644 | |
645 | - $format = !empty( $format ) ? $format : get_option( 'date_format' ); |
|
645 | + $format = !empty($format) ? $format : get_option('date_format'); |
|
646 | 646 | $date_completed = $invoice->get_completed_date(); |
647 | - $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_completed ) ) : ''; |
|
648 | - if ( $invoice_date == '' && $default ) { |
|
649 | - $invoice_date = wpinv_get_date_created( $invoice_id, $format ); |
|
647 | + $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_completed)) : ''; |
|
648 | + if ($invoice_date == '' && $default) { |
|
649 | + $invoice_date = wpinv_get_date_created($invoice_id, $format); |
|
650 | 650 | } |
651 | 651 | |
652 | 652 | return $invoice_date; |
653 | 653 | } |
654 | 654 | |
655 | -function wpinv_get_invoice_vat_number( $invoice_id = 0 ) { |
|
656 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
655 | +function wpinv_get_invoice_vat_number($invoice_id = 0) { |
|
656 | + $invoice = new WPInv_Invoice($invoice_id); |
|
657 | 657 | |
658 | 658 | return $invoice->vat_number; |
659 | 659 | } |
660 | 660 | |
661 | -function wpinv_insert_payment_note( $invoice_id = 0, $note = '', $user_type = false, $added_by_user = false, $system = false ) { |
|
662 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
661 | +function wpinv_insert_payment_note($invoice_id = 0, $note = '', $user_type = false, $added_by_user = false, $system = false) { |
|
662 | + $invoice = new WPInv_Invoice($invoice_id); |
|
663 | 663 | |
664 | - return $invoice->add_note( $note, $user_type, $added_by_user, $system ); |
|
664 | + return $invoice->add_note($note, $user_type, $added_by_user, $system); |
|
665 | 665 | } |
666 | 666 | |
667 | -function wpinv_get_invoice_notes( $invoice_id = 0, $type = '' ) { |
|
667 | +function wpinv_get_invoice_notes($invoice_id = 0, $type = '') { |
|
668 | 668 | global $invoicing; |
669 | 669 | |
670 | - if ( empty( $invoice_id ) ) { |
|
670 | + if (empty($invoice_id)) { |
|
671 | 671 | return NULL; |
672 | 672 | } |
673 | 673 | |
674 | - $notes = $invoicing->notes->get_invoice_notes( $invoice_id, $type ); |
|
674 | + $notes = $invoicing->notes->get_invoice_notes($invoice_id, $type); |
|
675 | 675 | |
676 | - return apply_filters( 'wpinv_invoice_notes', $notes, $invoice_id, $type ); |
|
676 | + return apply_filters('wpinv_invoice_notes', $notes, $invoice_id, $type); |
|
677 | 677 | } |
678 | 678 | |
679 | -function wpinv_get_payment_key( $invoice_id = 0 ) { |
|
680 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
679 | +function wpinv_get_payment_key($invoice_id = 0) { |
|
680 | + $invoice = new WPInv_Invoice($invoice_id); |
|
681 | 681 | return $invoice->get_key(); |
682 | 682 | } |
683 | 683 | |
684 | -function wpinv_get_invoice_number( $invoice_id = 0 ) { |
|
685 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
684 | +function wpinv_get_invoice_number($invoice_id = 0) { |
|
685 | + $invoice = new WPInv_Invoice($invoice_id); |
|
686 | 686 | return $invoice->get_number(); |
687 | 687 | } |
688 | 688 | |
689 | -function wpinv_get_cart_discountable_subtotal( $code_id ) { |
|
689 | +function wpinv_get_cart_discountable_subtotal($code_id) { |
|
690 | 690 | $cart_items = wpinv_get_cart_content_details(); |
691 | 691 | $items = array(); |
692 | 692 | |
693 | - $excluded_items = wpinv_get_discount_excluded_items( $code_id ); |
|
693 | + $excluded_items = wpinv_get_discount_excluded_items($code_id); |
|
694 | 694 | |
695 | - if( $cart_items ) { |
|
695 | + if ($cart_items) { |
|
696 | 696 | |
697 | - foreach( $cart_items as $item ) { |
|
697 | + foreach ($cart_items as $item) { |
|
698 | 698 | |
699 | - if( ! in_array( $item['id'], $excluded_items ) ) { |
|
700 | - $items[] = $item; |
|
699 | + if (!in_array($item['id'], $excluded_items)) { |
|
700 | + $items[] = $item; |
|
701 | 701 | } |
702 | 702 | } |
703 | 703 | } |
704 | 704 | |
705 | - $subtotal = wpinv_get_cart_items_subtotal( $items ); |
|
705 | + $subtotal = wpinv_get_cart_items_subtotal($items); |
|
706 | 706 | |
707 | - return apply_filters( 'wpinv_get_cart_discountable_subtotal', $subtotal ); |
|
707 | + return apply_filters('wpinv_get_cart_discountable_subtotal', $subtotal); |
|
708 | 708 | } |
709 | 709 | |
710 | -function wpinv_get_cart_items_subtotal( $items ) { |
|
710 | +function wpinv_get_cart_items_subtotal($items) { |
|
711 | 711 | $subtotal = 0.00; |
712 | 712 | |
713 | - if ( is_array( $items ) && ! empty( $items ) ) { |
|
714 | - $prices = wp_list_pluck( $items, 'subtotal' ); |
|
713 | + if (is_array($items) && !empty($items)) { |
|
714 | + $prices = wp_list_pluck($items, 'subtotal'); |
|
715 | 715 | |
716 | - if( is_array( $prices ) ) { |
|
717 | - $subtotal = array_sum( $prices ); |
|
716 | + if (is_array($prices)) { |
|
717 | + $subtotal = array_sum($prices); |
|
718 | 718 | } else { |
719 | 719 | $subtotal = 0.00; |
720 | 720 | } |
721 | 721 | |
722 | - if( $subtotal < 0 ) { |
|
722 | + if ($subtotal < 0) { |
|
723 | 723 | $subtotal = 0.00; |
724 | 724 | } |
725 | 725 | } |
726 | 726 | |
727 | - return apply_filters( 'wpinv_get_cart_items_subtotal', $subtotal ); |
|
727 | + return apply_filters('wpinv_get_cart_items_subtotal', $subtotal); |
|
728 | 728 | } |
729 | 729 | |
730 | -function wpinv_get_cart_subtotal( $items = array() ) { |
|
731 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
732 | - $subtotal = wpinv_get_cart_items_subtotal( $items ); |
|
730 | +function wpinv_get_cart_subtotal($items = array()) { |
|
731 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
732 | + $subtotal = wpinv_get_cart_items_subtotal($items); |
|
733 | 733 | |
734 | - return apply_filters( 'wpinv_get_cart_subtotal', $subtotal ); |
|
734 | + return apply_filters('wpinv_get_cart_subtotal', $subtotal); |
|
735 | 735 | } |
736 | 736 | |
737 | -function wpinv_cart_subtotal( $items = array() ) { |
|
738 | - $price = wpinv_price( wpinv_format_amount( wpinv_get_cart_subtotal( $items ) ) ); |
|
737 | +function wpinv_cart_subtotal($items = array()) { |
|
738 | + $price = wpinv_price(wpinv_format_amount(wpinv_get_cart_subtotal($items))); |
|
739 | 739 | |
740 | 740 | return $price; |
741 | 741 | } |
742 | 742 | |
743 | -function wpinv_get_cart_total( $items = array(), $discounts = false, $invoice = array() ) { |
|
744 | - $subtotal = (float)wpinv_get_cart_subtotal( $items ); |
|
745 | - $discounts = (float)wpinv_get_cart_discounted_amount( $items ); |
|
746 | - $cart_tax = (float)wpinv_get_cart_tax( $items ); |
|
747 | - $fees = (float)wpinv_get_cart_fee_total(); |
|
748 | - if ( !empty( $invoice ) && $invoice->is_free_trial() ) { |
|
743 | +function wpinv_get_cart_total($items = array(), $discounts = false, $invoice = array()) { |
|
744 | + $subtotal = (float) wpinv_get_cart_subtotal($items); |
|
745 | + $discounts = (float) wpinv_get_cart_discounted_amount($items); |
|
746 | + $cart_tax = (float) wpinv_get_cart_tax($items); |
|
747 | + $fees = (float) wpinv_get_cart_fee_total(); |
|
748 | + if (!empty($invoice) && $invoice->is_free_trial()) { |
|
749 | 749 | $total = 0; |
750 | 750 | } else { |
751 | - $total = $subtotal - $discounts + $cart_tax + $fees; |
|
751 | + $total = $subtotal - $discounts + $cart_tax + $fees; |
|
752 | 752 | } |
753 | 753 | |
754 | - if ( $total < 0 ) { |
|
754 | + if ($total < 0) { |
|
755 | 755 | $total = 0.00; |
756 | 756 | } |
757 | 757 | |
758 | - $total = (float)apply_filters( 'wpinv_get_cart_total', $total, $items ); |
|
758 | + $total = (float) apply_filters('wpinv_get_cart_total', $total, $items); |
|
759 | 759 | |
760 | - return wpinv_sanitize_amount( $total ); |
|
760 | + return wpinv_sanitize_amount($total); |
|
761 | 761 | } |
762 | 762 | |
763 | -function wpinv_cart_total( $cart_items = array(), $echo = true, $invoice = array() ) { |
|
763 | +function wpinv_cart_total($cart_items = array(), $echo = true, $invoice = array()) { |
|
764 | 764 | global $cart_total; |
765 | - $total = wpinv_price( wpinv_format_amount( wpinv_get_cart_total( $cart_items, NULL, $invoice ) ) ); |
|
766 | - $total = apply_filters( 'wpinv_cart_total', $total, $cart_items, $invoice ); |
|
765 | + $total = wpinv_price(wpinv_format_amount(wpinv_get_cart_total($cart_items, NULL, $invoice))); |
|
766 | + $total = apply_filters('wpinv_cart_total', $total, $cart_items, $invoice); |
|
767 | 767 | |
768 | 768 | $cart_total = $total; |
769 | 769 | |
770 | - if ( !$echo ) { |
|
770 | + if (!$echo) { |
|
771 | 771 | return $total; |
772 | 772 | } |
773 | 773 | |
774 | 774 | echo $total; |
775 | 775 | } |
776 | 776 | |
777 | -function wpinv_get_cart_tax( $items = array() ) { |
|
777 | +function wpinv_get_cart_tax($items = array()) { |
|
778 | 778 | $cart_tax = 0; |
779 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
779 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
780 | 780 | |
781 | - if ( $items ) { |
|
782 | - $taxes = wp_list_pluck( $items, 'tax' ); |
|
781 | + if ($items) { |
|
782 | + $taxes = wp_list_pluck($items, 'tax'); |
|
783 | 783 | |
784 | - if( is_array( $taxes ) ) { |
|
785 | - $cart_tax = array_sum( $taxes ); |
|
784 | + if (is_array($taxes)) { |
|
785 | + $cart_tax = array_sum($taxes); |
|
786 | 786 | } |
787 | 787 | } |
788 | 788 | |
789 | 789 | $cart_tax += wpinv_get_cart_fee_tax(); |
790 | 790 | |
791 | - return apply_filters( 'wpinv_get_cart_tax', wpinv_sanitize_amount( $cart_tax ) ); |
|
791 | + return apply_filters('wpinv_get_cart_tax', wpinv_sanitize_amount($cart_tax)); |
|
792 | 792 | } |
793 | 793 | |
794 | -function wpinv_cart_tax( $items = array(), $echo = false ) { |
|
795 | - $cart_tax = wpinv_get_cart_tax( $items ); |
|
796 | - $cart_tax = wpinv_price( wpinv_format_amount( $cart_tax ) ); |
|
794 | +function wpinv_cart_tax($items = array(), $echo = false) { |
|
795 | + $cart_tax = wpinv_get_cart_tax($items); |
|
796 | + $cart_tax = wpinv_price(wpinv_format_amount($cart_tax)); |
|
797 | 797 | |
798 | - $tax = apply_filters( 'wpinv_cart_tax', $cart_tax, $items ); |
|
798 | + $tax = apply_filters('wpinv_cart_tax', $cart_tax, $items); |
|
799 | 799 | |
800 | - if ( !$echo ) { |
|
800 | + if (!$echo) { |
|
801 | 801 | return $tax; |
802 | 802 | } |
803 | 803 | |
804 | 804 | echo $tax; |
805 | 805 | } |
806 | 806 | |
807 | -function wpinv_get_cart_discount_code( $items = array() ) { |
|
807 | +function wpinv_get_cart_discount_code($items = array()) { |
|
808 | 808 | $invoice = wpinv_get_invoice_cart(); |
809 | - $cart_discount_code = !empty( $invoice ) ? $invoice->get_discount_code() : ''; |
|
809 | + $cart_discount_code = !empty($invoice) ? $invoice->get_discount_code() : ''; |
|
810 | 810 | |
811 | - return apply_filters( 'wpinv_get_cart_discount_code', $cart_discount_code ); |
|
811 | + return apply_filters('wpinv_get_cart_discount_code', $cart_discount_code); |
|
812 | 812 | } |
813 | 813 | |
814 | -function wpinv_cart_discount_code( $items = array(), $echo = false ) { |
|
815 | - $cart_discount_code = wpinv_get_cart_discount_code( $items ); |
|
814 | +function wpinv_cart_discount_code($items = array(), $echo = false) { |
|
815 | + $cart_discount_code = wpinv_get_cart_discount_code($items); |
|
816 | 816 | |
817 | - if ( $cart_discount_code != '' ) { |
|
817 | + if ($cart_discount_code != '') { |
|
818 | 818 | $cart_discount_code = ' (' . $cart_discount_code . ')'; |
819 | 819 | } |
820 | 820 | |
821 | - $discount_code = apply_filters( 'wpinv_cart_discount_code', $cart_discount_code, $items ); |
|
821 | + $discount_code = apply_filters('wpinv_cart_discount_code', $cart_discount_code, $items); |
|
822 | 822 | |
823 | - if ( !$echo ) { |
|
823 | + if (!$echo) { |
|
824 | 824 | return $discount_code; |
825 | 825 | } |
826 | 826 | |
827 | 827 | echo $discount_code; |
828 | 828 | } |
829 | 829 | |
830 | -function wpinv_get_cart_discount( $items = array() ) { |
|
830 | +function wpinv_get_cart_discount($items = array()) { |
|
831 | 831 | $invoice = wpinv_get_invoice_cart(); |
832 | - $cart_discount = !empty( $invoice ) ? $invoice->get_discount() : 0; |
|
832 | + $cart_discount = !empty($invoice) ? $invoice->get_discount() : 0; |
|
833 | 833 | |
834 | - return apply_filters( 'wpinv_get_cart_discount', wpinv_sanitize_amount( $cart_discount ), $items ); |
|
834 | + return apply_filters('wpinv_get_cart_discount', wpinv_sanitize_amount($cart_discount), $items); |
|
835 | 835 | } |
836 | 836 | |
837 | -function wpinv_cart_discount( $items = array(), $echo = false ) { |
|
838 | - $cart_discount = wpinv_get_cart_discount( $items ); |
|
839 | - $cart_discount = wpinv_price( wpinv_format_amount( $cart_discount ) ); |
|
837 | +function wpinv_cart_discount($items = array(), $echo = false) { |
|
838 | + $cart_discount = wpinv_get_cart_discount($items); |
|
839 | + $cart_discount = wpinv_price(wpinv_format_amount($cart_discount)); |
|
840 | 840 | |
841 | - $discount = apply_filters( 'wpinv_cart_discount', $cart_discount, $items ); |
|
841 | + $discount = apply_filters('wpinv_cart_discount', $cart_discount, $items); |
|
842 | 842 | |
843 | - if ( !$echo ) { |
|
843 | + if (!$echo) { |
|
844 | 844 | return $discount; |
845 | 845 | } |
846 | 846 | |
847 | 847 | echo $discount; |
848 | 848 | } |
849 | 849 | |
850 | -function wpinv_get_cart_fees( $type = 'all', $item_id = 0 ) { |
|
851 | - $item = new WPInv_Item( $item_id ); |
|
850 | +function wpinv_get_cart_fees($type = 'all', $item_id = 0) { |
|
851 | + $item = new WPInv_Item($item_id); |
|
852 | 852 | |
853 | - return $item->get_fees( $type, $item_id ); |
|
853 | + return $item->get_fees($type, $item_id); |
|
854 | 854 | } |
855 | 855 | |
856 | 856 | function wpinv_get_cart_fee_total() { |
857 | - $total = 0; |
|
857 | + $total = 0; |
|
858 | 858 | $fees = wpinv_get_cart_fees(); |
859 | 859 | |
860 | - if ( $fees ) { |
|
861 | - foreach ( $fees as $fee_id => $fee ) { |
|
860 | + if ($fees) { |
|
861 | + foreach ($fees as $fee_id => $fee) { |
|
862 | 862 | $total += $fee['amount']; |
863 | 863 | } |
864 | 864 | } |
865 | 865 | |
866 | - return apply_filters( 'wpinv_get_cart_fee_total', $total ); |
|
866 | + return apply_filters('wpinv_get_cart_fee_total', $total); |
|
867 | 867 | } |
868 | 868 | |
869 | 869 | function wpinv_get_cart_fee_tax() { |
870 | 870 | $tax = 0; |
871 | 871 | $fees = wpinv_get_cart_fees(); |
872 | 872 | |
873 | - if ( $fees ) { |
|
874 | - foreach ( $fees as $fee_id => $fee ) { |
|
875 | - if( ! empty( $fee['no_tax'] ) ) { |
|
873 | + if ($fees) { |
|
874 | + foreach ($fees as $fee_id => $fee) { |
|
875 | + if (!empty($fee['no_tax'])) { |
|
876 | 876 | continue; |
877 | 877 | } |
878 | 878 | |
879 | - $tax += wpinv_calculate_tax( $fee['amount'] ); |
|
879 | + $tax += wpinv_calculate_tax($fee['amount']); |
|
880 | 880 | } |
881 | 881 | } |
882 | 882 | |
883 | - return apply_filters( 'wpinv_get_cart_fee_tax', $tax ); |
|
883 | + return apply_filters('wpinv_get_cart_fee_tax', $tax); |
|
884 | 884 | } |
885 | 885 | |
886 | 886 | function wpinv_cart_has_recurring_item() { |
887 | 887 | $cart_items = wpinv_get_cart_contents(); |
888 | 888 | |
889 | - if ( empty( $cart_items ) ) { |
|
889 | + if (empty($cart_items)) { |
|
890 | 890 | return false; |
891 | 891 | } |
892 | 892 | |
893 | 893 | $has_subscription = false; |
894 | - foreach( $cart_items as $cart_item ) { |
|
895 | - if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] ) ) { |
|
894 | + foreach ($cart_items as $cart_item) { |
|
895 | + if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { |
|
896 | 896 | $has_subscription = true; |
897 | 897 | break; |
898 | 898 | } |
899 | 899 | } |
900 | 900 | |
901 | - return apply_filters( 'wpinv_cart_has_recurring_item', $has_subscription, $cart_items ); |
|
901 | + return apply_filters('wpinv_cart_has_recurring_item', $has_subscription, $cart_items); |
|
902 | 902 | } |
903 | 903 | |
904 | 904 | function wpinv_cart_has_free_trial() { |
@@ -906,97 +906,97 @@ discard block |
||
906 | 906 | |
907 | 907 | $free_trial = false; |
908 | 908 | |
909 | - if ( !empty( $invoice ) && $invoice->is_free_trial() ) { |
|
909 | + if (!empty($invoice) && $invoice->is_free_trial()) { |
|
910 | 910 | $free_trial = true; |
911 | 911 | } |
912 | 912 | |
913 | - return apply_filters( 'wpinv_cart_has_free_trial', $free_trial, $invoice ); |
|
913 | + return apply_filters('wpinv_cart_has_free_trial', $free_trial, $invoice); |
|
914 | 914 | } |
915 | 915 | |
916 | 916 | function wpinv_get_cart_contents() { |
917 | 917 | $cart_details = wpinv_get_cart_details(); |
918 | 918 | |
919 | - return apply_filters( 'wpinv_get_cart_contents', $cart_details ); |
|
919 | + return apply_filters('wpinv_get_cart_contents', $cart_details); |
|
920 | 920 | } |
921 | 921 | |
922 | 922 | function wpinv_get_cart_content_details() { |
923 | 923 | global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpinv_is_last_cart_item, $wpinv_flat_discount_total; |
924 | 924 | $cart_items = wpinv_get_cart_contents(); |
925 | 925 | |
926 | - if ( empty( $cart_items ) ) { |
|
926 | + if (empty($cart_items)) { |
|
927 | 927 | return false; |
928 | 928 | } |
929 | 929 | $invoice = wpinv_get_invoice_cart(); |
930 | - if ( empty( $invoice ) ) { |
|
930 | + if (empty($invoice)) { |
|
931 | 931 | return false; |
932 | 932 | } |
933 | 933 | |
934 | 934 | $details = array(); |
935 | - $length = count( $cart_items ) - 1; |
|
935 | + $length = count($cart_items) - 1; |
|
936 | 936 | |
937 | - if ( empty( $_POST['country'] ) ) { |
|
937 | + if (empty($_POST['country'])) { |
|
938 | 938 | $_POST['country'] = $invoice->country; |
939 | 939 | } |
940 | - if ( !isset( $_POST['state'] ) ) { |
|
940 | + if (!isset($_POST['state'])) { |
|
941 | 941 | $_POST['state'] = $invoice->state; |
942 | 942 | } |
943 | 943 | |
944 | - foreach( $cart_items as $key => $item ) { |
|
945 | - $item_id = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : ''; |
|
946 | - if ( empty( $item_id ) ) { |
|
944 | + foreach ($cart_items as $key => $item) { |
|
945 | + $item_id = isset($item['id']) ? sanitize_text_field($item['id']) : ''; |
|
946 | + if (empty($item_id)) { |
|
947 | 947 | continue; |
948 | 948 | } |
949 | 949 | |
950 | 950 | $wpi_current_id = $invoice->ID; |
951 | 951 | $wpi_item_id = $item_id; |
952 | 952 | |
953 | - if ( isset( $item['custom_price'] ) && $item['custom_price'] !== '' ) { |
|
953 | + if (isset($item['custom_price']) && $item['custom_price'] !== '') { |
|
954 | 954 | $item_price = $item['custom_price']; |
955 | 955 | } else { |
956 | - if ( isset( $item['item_price'] ) && $item['item_price'] !== '' && $item['item_price'] !== false ) { |
|
956 | + if (isset($item['item_price']) && $item['item_price'] !== '' && $item['item_price'] !== false) { |
|
957 | 957 | $item_price = $item['item_price']; |
958 | 958 | } else { |
959 | - $item_price = wpinv_get_item_price( $item_id ); |
|
959 | + $item_price = wpinv_get_item_price($item_id); |
|
960 | 960 | } |
961 | 961 | } |
962 | - $discount = wpinv_get_cart_item_discount_amount( $item ); |
|
963 | - $discount = apply_filters( 'wpinv_get_cart_content_details_item_discount_amount', $discount, $item ); |
|
964 | - $quantity = wpinv_get_cart_item_quantity( $item ); |
|
965 | - $fees = wpinv_get_cart_fees( 'fee', $item_id ); |
|
962 | + $discount = wpinv_get_cart_item_discount_amount($item); |
|
963 | + $discount = apply_filters('wpinv_get_cart_content_details_item_discount_amount', $discount, $item); |
|
964 | + $quantity = wpinv_get_cart_item_quantity($item); |
|
965 | + $fees = wpinv_get_cart_fees('fee', $item_id); |
|
966 | 966 | |
967 | 967 | $subtotal = $item_price * $quantity; |
968 | - $tax_rate = wpinv_get_tax_rate( $_POST['country'], $_POST['state'], $wpi_item_id ); |
|
969 | - $tax_class = $wpinv_euvat->get_item_class( $item_id ); |
|
970 | - $tax = wpinv_get_cart_item_tax( $item_id, $subtotal - $discount ); |
|
968 | + $tax_rate = wpinv_get_tax_rate($_POST['country'], $_POST['state'], $wpi_item_id); |
|
969 | + $tax_class = $wpinv_euvat->get_item_class($item_id); |
|
970 | + $tax = wpinv_get_cart_item_tax($item_id, $subtotal - $discount); |
|
971 | 971 | |
972 | - if ( wpinv_prices_include_tax() ) { |
|
973 | - $subtotal -= wpinv_round_amount( $tax ); |
|
972 | + if (wpinv_prices_include_tax()) { |
|
973 | + $subtotal -= wpinv_round_amount($tax); |
|
974 | 974 | } |
975 | 975 | |
976 | - $total = $subtotal - $discount + $tax; |
|
976 | + $total = $subtotal - $discount + $tax; |
|
977 | 977 | |
978 | 978 | // Do not allow totals to go negatve |
979 | - if( $total < 0 ) { |
|
979 | + if ($total < 0) { |
|
980 | 980 | $total = 0; |
981 | 981 | } |
982 | 982 | |
983 | - $details[ $key ] = array( |
|
983 | + $details[$key] = array( |
|
984 | 984 | 'id' => $item_id, |
985 | - 'name' => !empty($item['name']) ? $item['name'] : get_the_title( $item_id ), |
|
986 | - 'item_price' => wpinv_round_amount( $item_price ), |
|
987 | - 'custom_price' => isset( $item['custom_price'] ) ? $item['custom_price'] : '', |
|
985 | + 'name' => !empty($item['name']) ? $item['name'] : get_the_title($item_id), |
|
986 | + 'item_price' => wpinv_round_amount($item_price), |
|
987 | + 'custom_price' => isset($item['custom_price']) ? $item['custom_price'] : '', |
|
988 | 988 | 'quantity' => $quantity, |
989 | - 'discount' => wpinv_round_amount( $discount ), |
|
990 | - 'subtotal' => wpinv_round_amount( $subtotal ), |
|
991 | - 'tax' => wpinv_round_amount( $tax ), |
|
992 | - 'price' => wpinv_round_amount( $total ), |
|
989 | + 'discount' => wpinv_round_amount($discount), |
|
990 | + 'subtotal' => wpinv_round_amount($subtotal), |
|
991 | + 'tax' => wpinv_round_amount($tax), |
|
992 | + 'price' => wpinv_round_amount($total), |
|
993 | 993 | 'vat_rates_class' => $tax_class, |
994 | 994 | 'vat_rate' => $tax_rate, |
995 | - 'meta' => isset( $item['meta'] ) ? $item['meta'] : array(), |
|
995 | + 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
|
996 | 996 | 'fees' => $fees, |
997 | 997 | ); |
998 | 998 | |
999 | - if ( $wpinv_is_last_cart_item ) { |
|
999 | + if ($wpinv_is_last_cart_item) { |
|
1000 | 1000 | $wpinv_is_last_cart_item = false; |
1001 | 1001 | $wpinv_flat_discount_total = 0.00; |
1002 | 1002 | } |
@@ -1005,67 +1005,67 @@ discard block |
||
1005 | 1005 | return $details; |
1006 | 1006 | } |
1007 | 1007 | |
1008 | -function wpinv_get_cart_details( $invoice_id = 0 ) { |
|
1008 | +function wpinv_get_cart_details($invoice_id = 0) { |
|
1009 | 1009 | global $ajax_cart_details; |
1010 | 1010 | |
1011 | - $invoice = wpinv_get_invoice_cart( $invoice_id ); |
|
1011 | + $invoice = wpinv_get_invoice_cart($invoice_id); |
|
1012 | 1012 | $cart_details = $ajax_cart_details; |
1013 | - if ( empty( $cart_details ) && ! empty( $invoice->cart_details ) ) { |
|
1013 | + if (empty($cart_details) && !empty($invoice->cart_details)) { |
|
1014 | 1014 | $cart_details = $invoice->cart_details; |
1015 | 1015 | } |
1016 | 1016 | |
1017 | - if ( ! empty( $cart_details ) && is_array( $cart_details ) ) { |
|
1018 | - $invoice_currency = ! empty( $invoice->currency ) ? $invoice->currency : wpinv_get_default_country(); |
|
1017 | + if (!empty($cart_details) && is_array($cart_details)) { |
|
1018 | + $invoice_currency = !empty($invoice->currency) ? $invoice->currency : wpinv_get_default_country(); |
|
1019 | 1019 | |
1020 | - foreach ( $cart_details as $key => $cart_item ) { |
|
1021 | - $cart_details[ $key ]['currency'] = $invoice_currency; |
|
1020 | + foreach ($cart_details as $key => $cart_item) { |
|
1021 | + $cart_details[$key]['currency'] = $invoice_currency; |
|
1022 | 1022 | |
1023 | - if ( ! isset( $cart_item['subtotal'] ) ) { |
|
1024 | - $cart_details[ $key ]['subtotal'] = $cart_item['price']; |
|
1023 | + if (!isset($cart_item['subtotal'])) { |
|
1024 | + $cart_details[$key]['subtotal'] = $cart_item['price']; |
|
1025 | 1025 | } |
1026 | 1026 | } |
1027 | 1027 | } |
1028 | 1028 | |
1029 | - return apply_filters( 'wpinv_get_cart_details', $cart_details, $invoice_id ); |
|
1029 | + return apply_filters('wpinv_get_cart_details', $cart_details, $invoice_id); |
|
1030 | 1030 | } |
1031 | 1031 | |
1032 | -function wpinv_record_status_change( $invoice_id, $new_status, $old_status ) { |
|
1033 | - if ( 'wpi_invoice' != get_post_type( $invoice_id ) ) { |
|
1032 | +function wpinv_record_status_change($invoice_id, $new_status, $old_status) { |
|
1033 | + if ('wpi_invoice' != get_post_type($invoice_id)) { |
|
1034 | 1034 | return; |
1035 | 1035 | } |
1036 | 1036 | |
1037 | - if ( ( $old_status == 'wpi-pending' && $new_status == 'draft' ) || ( $old_status == 'draft' && $new_status == 'wpi-pending' ) ) { |
|
1037 | + if (($old_status == 'wpi-pending' && $new_status == 'draft') || ($old_status == 'draft' && $new_status == 'wpi-pending')) { |
|
1038 | 1038 | return; |
1039 | 1039 | } |
1040 | 1040 | |
1041 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1041 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1042 | 1042 | |
1043 | - $old_status = wpinv_status_nicename( $old_status ); |
|
1044 | - $new_status = wpinv_status_nicename( $new_status ); |
|
1043 | + $old_status = wpinv_status_nicename($old_status); |
|
1044 | + $new_status = wpinv_status_nicename($new_status); |
|
1045 | 1045 | |
1046 | - $status_change = sprintf( __( 'Invoice status changed from %s to %s', 'invoicing' ), $old_status, $new_status ); |
|
1046 | + $status_change = sprintf(__('Invoice status changed from %s to %s', 'invoicing'), $old_status, $new_status); |
|
1047 | 1047 | |
1048 | 1048 | // Add note |
1049 | - return $invoice->add_note( $status_change, false, false, true ); |
|
1049 | + return $invoice->add_note($status_change, false, false, true); |
|
1050 | 1050 | } |
1051 | -add_action( 'wpinv_update_status', 'wpinv_record_status_change', 100, 3 ); |
|
1051 | +add_action('wpinv_update_status', 'wpinv_record_status_change', 100, 3); |
|
1052 | 1052 | |
1053 | -function wpinv_complete_payment( $invoice_id, $new_status, $old_status ) { |
|
1053 | +function wpinv_complete_payment($invoice_id, $new_status, $old_status) { |
|
1054 | 1054 | global $wpi_has_free_trial; |
1055 | 1055 | |
1056 | 1056 | $wpi_has_free_trial = false; |
1057 | 1057 | |
1058 | - if ( $old_status == 'publish' ) { |
|
1058 | + if ($old_status == 'publish') { |
|
1059 | 1059 | return; // Make sure that payments are only paid once |
1060 | 1060 | } |
1061 | 1061 | |
1062 | 1062 | // Make sure the payment completion is only processed when new status is paid |
1063 | - if ( $new_status != 'publish' ) { |
|
1063 | + if ($new_status != 'publish') { |
|
1064 | 1064 | return; |
1065 | 1065 | } |
1066 | 1066 | |
1067 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
1068 | - if ( empty( $invoice ) ) { |
|
1067 | + $invoice = new WPInv_Invoice($invoice_id); |
|
1068 | + if (empty($invoice)) { |
|
1069 | 1069 | return; |
1070 | 1070 | } |
1071 | 1071 | |
@@ -1073,58 +1073,58 @@ discard block |
||
1073 | 1073 | $completed_date = $invoice->completed_date; |
1074 | 1074 | $cart_details = $invoice->cart_details; |
1075 | 1075 | |
1076 | - do_action( 'wpinv_pre_complete_payment', $invoice_id ); |
|
1076 | + do_action('wpinv_pre_complete_payment', $invoice_id); |
|
1077 | 1077 | |
1078 | - if ( is_array( $cart_details ) ) { |
|
1078 | + if (is_array($cart_details)) { |
|
1079 | 1079 | // Increase purchase count and earnings |
1080 | - foreach ( $cart_details as $cart_index => $item ) { |
|
1080 | + foreach ($cart_details as $cart_index => $item) { |
|
1081 | 1081 | // Ensure these actions only run once, ever |
1082 | - if ( empty( $completed_date ) ) { |
|
1083 | - do_action( 'wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index ); |
|
1082 | + if (empty($completed_date)) { |
|
1083 | + do_action('wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index); |
|
1084 | 1084 | } |
1085 | 1085 | } |
1086 | 1086 | } |
1087 | 1087 | |
1088 | 1088 | // Check for discount codes and increment their use counts |
1089 | - if ( $discounts = $invoice->get_discounts( true ) ) { |
|
1090 | - if( ! empty( $discounts ) ) { |
|
1091 | - foreach( $discounts as $code ) { |
|
1092 | - wpinv_increase_discount_usage( $code ); |
|
1089 | + if ($discounts = $invoice->get_discounts(true)) { |
|
1090 | + if (!empty($discounts)) { |
|
1091 | + foreach ($discounts as $code) { |
|
1092 | + wpinv_increase_discount_usage($code); |
|
1093 | 1093 | } |
1094 | 1094 | } |
1095 | 1095 | } |
1096 | 1096 | |
1097 | 1097 | // Ensure this action only runs once ever |
1098 | - if( empty( $completed_date ) ) { |
|
1098 | + if (empty($completed_date)) { |
|
1099 | 1099 | // Save the completed date |
1100 | - $invoice->set( 'completed_date', current_time( 'mysql', 0 ) ); |
|
1100 | + $invoice->set('completed_date', current_time('mysql', 0)); |
|
1101 | 1101 | $invoice->save(); |
1102 | 1102 | |
1103 | - do_action( 'wpinv_complete_payment', $invoice_id ); |
|
1103 | + do_action('wpinv_complete_payment', $invoice_id); |
|
1104 | 1104 | } |
1105 | 1105 | |
1106 | 1106 | // Empty the shopping cart |
1107 | 1107 | wpinv_empty_cart(); |
1108 | 1108 | } |
1109 | -add_action( 'wpinv_update_status', 'wpinv_complete_payment', 100, 3 ); |
|
1109 | +add_action('wpinv_update_status', 'wpinv_complete_payment', 100, 3); |
|
1110 | 1110 | |
1111 | -function wpinv_update_payment_status( $invoice_id, $new_status = 'publish' ) { |
|
1112 | - $invoice = !empty( $invoice_id ) && is_object( $invoice_id ) ? $invoice_id : wpinv_get_invoice( (int)$invoice_id ); |
|
1111 | +function wpinv_update_payment_status($invoice_id, $new_status = 'publish') { |
|
1112 | + $invoice = !empty($invoice_id) && is_object($invoice_id) ? $invoice_id : wpinv_get_invoice((int) $invoice_id); |
|
1113 | 1113 | |
1114 | - if ( empty( $invoice ) ) { |
|
1114 | + if (empty($invoice)) { |
|
1115 | 1115 | return false; |
1116 | 1116 | } |
1117 | 1117 | |
1118 | - return $invoice->update_status( $new_status ); |
|
1118 | + return $invoice->update_status($new_status); |
|
1119 | 1119 | } |
1120 | 1120 | |
1121 | -function wpinv_cart_has_fees( $type = 'all' ) { |
|
1121 | +function wpinv_cart_has_fees($type = 'all') { |
|
1122 | 1122 | return false; |
1123 | 1123 | } |
1124 | 1124 | |
1125 | 1125 | function wpinv_validate_checkout_fields() { |
1126 | 1126 | // Check if there is $_POST |
1127 | - if ( empty( $_POST ) ) { |
|
1127 | + if (empty($_POST)) { |
|
1128 | 1128 | return false; |
1129 | 1129 | } |
1130 | 1130 | |
@@ -1136,11 +1136,11 @@ discard block |
||
1136 | 1136 | ); |
1137 | 1137 | |
1138 | 1138 | // Validate agree to terms |
1139 | - $page = wpinv_get_option( 'tandc_page' ); |
|
1140 | - if(isset($page) && (int)$page > 0 && apply_filters( 'wpinv_checkout_show_terms', true )){ |
|
1139 | + $page = wpinv_get_option('tandc_page'); |
|
1140 | + if (isset($page) && (int) $page > 0 && apply_filters('wpinv_checkout_show_terms', true)) { |
|
1141 | 1141 | // Validate agree to terms |
1142 | - if ( ! isset( $_POST['wpi_terms'] ) || !$_POST['wpi_terms'] ) { |
|
1143 | - wpinv_set_error( 'accept_terms', apply_filters( 'wpinv_accept_terms_error_text', __( 'You must accept terms and conditions', 'invoicing' ) ) ); |
|
1142 | + if (!isset($_POST['wpi_terms']) || !$_POST['wpi_terms']) { |
|
1143 | + wpinv_set_error('accept_terms', apply_filters('wpinv_accept_terms_error_text', __('You must accept terms and conditions', 'invoicing'))); |
|
1144 | 1144 | } |
1145 | 1145 | } |
1146 | 1146 | |
@@ -1156,26 +1156,26 @@ discard block |
||
1156 | 1156 | |
1157 | 1157 | $invoice = wpinv_get_invoice_cart(); |
1158 | 1158 | $has_subscription = $invoice->is_recurring(); |
1159 | - if ( empty( $invoice ) ) { |
|
1160 | - wpinv_set_error( 'invalid_invoice', __( 'Your cart is empty.', 'invoicing' ) ); |
|
1159 | + if (empty($invoice)) { |
|
1160 | + wpinv_set_error('invalid_invoice', __('Your cart is empty.', 'invoicing')); |
|
1161 | 1161 | return $gateway; |
1162 | 1162 | } |
1163 | 1163 | |
1164 | 1164 | // Check if a gateway value is present |
1165 | - if ( !empty( $_REQUEST['wpi-gateway'] ) ) { |
|
1166 | - $gateway = sanitize_text_field( $_REQUEST['wpi-gateway'] ); |
|
1165 | + if (!empty($_REQUEST['wpi-gateway'])) { |
|
1166 | + $gateway = sanitize_text_field($_REQUEST['wpi-gateway']); |
|
1167 | 1167 | |
1168 | - if ( $invoice->is_free() ) { |
|
1168 | + if ($invoice->is_free()) { |
|
1169 | 1169 | $gateway = 'manual'; |
1170 | - } elseif ( !wpinv_is_gateway_active( $gateway ) ) { |
|
1171 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled', 'invoicing' ) ); |
|
1172 | - } elseif ( $has_subscription && !wpinv_gateway_support_subscription( $gateway ) ) { |
|
1173 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway doesnot support subscription payment', 'invoicing' ) ); |
|
1170 | + } elseif (!wpinv_is_gateway_active($gateway)) { |
|
1171 | + wpinv_set_error('invalid_gateway', __('The selected payment gateway is not enabled', 'invoicing')); |
|
1172 | + } elseif ($has_subscription && !wpinv_gateway_support_subscription($gateway)) { |
|
1173 | + wpinv_set_error('invalid_gateway', __('The selected payment gateway doesnot support subscription payment', 'invoicing')); |
|
1174 | 1174 | } |
1175 | 1175 | } |
1176 | 1176 | |
1177 | - if ( $has_subscription && count( wpinv_get_cart_contents() ) > 1 ) { |
|
1178 | - wpinv_set_error( 'subscription_invalid', __( 'Only one subscription may be purchased through payment per checkout.', 'invoicing' ) ); |
|
1177 | + if ($has_subscription && count(wpinv_get_cart_contents()) > 1) { |
|
1178 | + wpinv_set_error('subscription_invalid', __('Only one subscription may be purchased through payment per checkout.', 'invoicing')); |
|
1179 | 1179 | } |
1180 | 1180 | |
1181 | 1181 | return $gateway; |
@@ -1189,10 +1189,10 @@ discard block |
||
1189 | 1189 | |
1190 | 1190 | $error = false; |
1191 | 1191 | // If we have discounts, loop through them |
1192 | - if ( ! empty( $discounts ) ) { |
|
1193 | - foreach ( $discounts as $discount ) { |
|
1192 | + if (!empty($discounts)) { |
|
1193 | + foreach ($discounts as $discount) { |
|
1194 | 1194 | // Check if valid |
1195 | - if ( !wpinv_is_discount_valid( $discount, (int)$wpi_cart->get_user_id() ) ) { |
|
1195 | + if (!wpinv_is_discount_valid($discount, (int) $wpi_cart->get_user_id())) { |
|
1196 | 1196 | // Discount is not valid |
1197 | 1197 | $error = true; |
1198 | 1198 | } |
@@ -1202,20 +1202,20 @@ discard block |
||
1202 | 1202 | return NULL; |
1203 | 1203 | } |
1204 | 1204 | |
1205 | - if ( $error && !wpinv_get_errors() ) { |
|
1206 | - wpinv_set_error( 'invalid_discount', __( 'Discount code you entered is invalid', 'invoicing' ) ); |
|
1205 | + if ($error && !wpinv_get_errors()) { |
|
1206 | + wpinv_set_error('invalid_discount', __('Discount code you entered is invalid', 'invoicing')); |
|
1207 | 1207 | } |
1208 | 1208 | |
1209 | - return implode( ',', $discounts ); |
|
1209 | + return implode(',', $discounts); |
|
1210 | 1210 | } |
1211 | 1211 | |
1212 | 1212 | function wpinv_checkout_validate_cc() { |
1213 | 1213 | $card_data = wpinv_checkout_get_cc_info(); |
1214 | 1214 | |
1215 | 1215 | // Validate the card zip |
1216 | - if ( !empty( $card_data['wpinv_zip'] ) ) { |
|
1217 | - if ( !wpinv_checkout_validate_cc_zip( $card_data['wpinv_zip'], $card_data['wpinv_country'] ) ) { |
|
1218 | - wpinv_set_error( 'invalid_cc_zip', __( 'The zip / postcode you entered for your billing address is invalid', 'invoicing' ) ); |
|
1216 | + if (!empty($card_data['wpinv_zip'])) { |
|
1217 | + if (!wpinv_checkout_validate_cc_zip($card_data['wpinv_zip'], $card_data['wpinv_country'])) { |
|
1218 | + wpinv_set_error('invalid_cc_zip', __('The zip / postcode you entered for your billing address is invalid', 'invoicing')); |
|
1219 | 1219 | } |
1220 | 1220 | } |
1221 | 1221 | |
@@ -1225,28 +1225,28 @@ discard block |
||
1225 | 1225 | |
1226 | 1226 | function wpinv_checkout_get_cc_info() { |
1227 | 1227 | $cc_info = array(); |
1228 | - $cc_info['card_name'] = isset( $_POST['card_name'] ) ? sanitize_text_field( $_POST['card_name'] ) : ''; |
|
1229 | - $cc_info['card_number'] = isset( $_POST['card_number'] ) ? sanitize_text_field( $_POST['card_number'] ) : ''; |
|
1230 | - $cc_info['card_cvc'] = isset( $_POST['card_cvc'] ) ? sanitize_text_field( $_POST['card_cvc'] ) : ''; |
|
1231 | - $cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] ) ? sanitize_text_field( $_POST['card_exp_month'] ) : ''; |
|
1232 | - $cc_info['card_exp_year'] = isset( $_POST['card_exp_year'] ) ? sanitize_text_field( $_POST['card_exp_year'] ) : ''; |
|
1233 | - $cc_info['card_address'] = isset( $_POST['wpinv_address'] ) ? sanitize_text_field( $_POST['wpinv_address'] ) : ''; |
|
1234 | - $cc_info['card_city'] = isset( $_POST['wpinv_city'] ) ? sanitize_text_field( $_POST['wpinv_city'] ) : ''; |
|
1235 | - $cc_info['card_state'] = isset( $_POST['wpinv_state'] ) ? sanitize_text_field( $_POST['wpinv_state'] ) : ''; |
|
1236 | - $cc_info['card_country'] = isset( $_POST['wpinv_country'] ) ? sanitize_text_field( $_POST['wpinv_country'] ) : ''; |
|
1237 | - $cc_info['card_zip'] = isset( $_POST['wpinv_zip'] ) ? sanitize_text_field( $_POST['wpinv_zip'] ) : ''; |
|
1228 | + $cc_info['card_name'] = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : ''; |
|
1229 | + $cc_info['card_number'] = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : ''; |
|
1230 | + $cc_info['card_cvc'] = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : ''; |
|
1231 | + $cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : ''; |
|
1232 | + $cc_info['card_exp_year'] = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : ''; |
|
1233 | + $cc_info['card_address'] = isset($_POST['wpinv_address']) ? sanitize_text_field($_POST['wpinv_address']) : ''; |
|
1234 | + $cc_info['card_city'] = isset($_POST['wpinv_city']) ? sanitize_text_field($_POST['wpinv_city']) : ''; |
|
1235 | + $cc_info['card_state'] = isset($_POST['wpinv_state']) ? sanitize_text_field($_POST['wpinv_state']) : ''; |
|
1236 | + $cc_info['card_country'] = isset($_POST['wpinv_country']) ? sanitize_text_field($_POST['wpinv_country']) : ''; |
|
1237 | + $cc_info['card_zip'] = isset($_POST['wpinv_zip']) ? sanitize_text_field($_POST['wpinv_zip']) : ''; |
|
1238 | 1238 | |
1239 | 1239 | // Return cc info |
1240 | 1240 | return $cc_info; |
1241 | 1241 | } |
1242 | 1242 | |
1243 | -function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) { |
|
1243 | +function wpinv_checkout_validate_cc_zip($zip = 0, $country_code = '') { |
|
1244 | 1244 | $ret = false; |
1245 | 1245 | |
1246 | - if ( empty( $zip ) || empty( $country_code ) ) |
|
1246 | + if (empty($zip) || empty($country_code)) |
|
1247 | 1247 | return $ret; |
1248 | 1248 | |
1249 | - $country_code = strtoupper( $country_code ); |
|
1249 | + $country_code = strtoupper($country_code); |
|
1250 | 1250 | |
1251 | 1251 | $zip_regex = array( |
1252 | 1252 | "AD" => "AD\d{3}", |
@@ -1406,72 +1406,72 @@ discard block |
||
1406 | 1406 | "ZM" => "\d{5}" |
1407 | 1407 | ); |
1408 | 1408 | |
1409 | - if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) ) |
|
1409 | + if (!isset ($zip_regex[$country_code]) || preg_match("/" . $zip_regex[$country_code] . "/i", $zip)) |
|
1410 | 1410 | $ret = true; |
1411 | 1411 | |
1412 | - return apply_filters( 'wpinv_is_zip_valid', $ret, $zip, $country_code ); |
|
1412 | + return apply_filters('wpinv_is_zip_valid', $ret, $zip, $country_code); |
|
1413 | 1413 | } |
1414 | 1414 | |
1415 | 1415 | function wpinv_checkout_validate_agree_to_terms() { |
1416 | 1416 | // Validate agree to terms |
1417 | - if ( ! isset( $_POST['wpi_agree_to_terms'] ) || $_POST['wpi_agree_to_terms'] != 1 ) { |
|
1417 | + if (!isset($_POST['wpi_agree_to_terms']) || $_POST['wpi_agree_to_terms'] != 1) { |
|
1418 | 1418 | // User did not agree |
1419 | - wpinv_set_error( 'agree_to_terms', apply_filters( 'wpinv_agree_to_terms_text', __( 'You must agree to the terms of use', 'invoicing' ) ) ); |
|
1419 | + wpinv_set_error('agree_to_terms', apply_filters('wpinv_agree_to_terms_text', __('You must agree to the terms of use', 'invoicing'))); |
|
1420 | 1420 | } |
1421 | 1421 | } |
1422 | 1422 | |
1423 | 1423 | function wpinv_checkout_validate_invoice_user() { |
1424 | 1424 | global $wpi_cart, $user_ID; |
1425 | 1425 | |
1426 | - if(empty($wpi_cart)){ |
|
1426 | + if (empty($wpi_cart)) { |
|
1427 | 1427 | $wpi_cart = wpinv_get_invoice_cart(); |
1428 | 1428 | } |
1429 | 1429 | |
1430 | - $invoice_user = (int)$wpi_cart->get_user_id(); |
|
1430 | + $invoice_user = (int) $wpi_cart->get_user_id(); |
|
1431 | 1431 | $valid_user_data = array( |
1432 | 1432 | 'user_id' => $invoice_user |
1433 | 1433 | ); |
1434 | 1434 | |
1435 | 1435 | // If guest checkout allowed |
1436 | - if ( !wpinv_require_login_to_checkout() ) { |
|
1436 | + if (!wpinv_require_login_to_checkout()) { |
|
1437 | 1437 | return $valid_user_data; |
1438 | 1438 | } |
1439 | 1439 | |
1440 | 1440 | // Verify there is a user_ID |
1441 | - if ( $user_ID == $invoice_user ) { |
|
1441 | + if ($user_ID == $invoice_user) { |
|
1442 | 1442 | // Get the logged in user data |
1443 | - $user_data = get_userdata( $user_ID ); |
|
1444 | - $required_fields = wpinv_checkout_required_fields(); |
|
1443 | + $user_data = get_userdata($user_ID); |
|
1444 | + $required_fields = wpinv_checkout_required_fields(); |
|
1445 | 1445 | |
1446 | 1446 | // Loop through required fields and show error messages |
1447 | - if ( !empty( $required_fields ) ) { |
|
1448 | - foreach ( $required_fields as $field_name => $value ) { |
|
1449 | - if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) { |
|
1450 | - wpinv_set_error( $value['error_id'], $value['error_message'] ); |
|
1447 | + if (!empty($required_fields)) { |
|
1448 | + foreach ($required_fields as $field_name => $value) { |
|
1449 | + if (in_array($value, $required_fields) && empty($_POST['wpinv_' . $field_name])) { |
|
1450 | + wpinv_set_error($value['error_id'], $value['error_message']); |
|
1451 | 1451 | } |
1452 | 1452 | } |
1453 | 1453 | } |
1454 | 1454 | |
1455 | 1455 | // Verify data |
1456 | - if ( $user_data ) { |
|
1456 | + if ($user_data) { |
|
1457 | 1457 | // Collected logged in user data |
1458 | 1458 | $valid_user_data = array( |
1459 | 1459 | 'user_id' => $user_ID, |
1460 | - 'email' => isset( $_POST['wpinv_email'] ) ? sanitize_email( $_POST['wpinv_email'] ) : $user_data->user_email, |
|
1461 | - 'first_name' => isset( $_POST['wpinv_first_name'] ) && ! empty( $_POST['wpinv_first_name'] ) ? sanitize_text_field( $_POST['wpinv_first_name'] ) : $user_data->first_name, |
|
1462 | - 'last_name' => isset( $_POST['wpinv_last_name'] ) && ! empty( $_POST['wpinv_last_name'] ) ? sanitize_text_field( $_POST['wpinv_last_name'] ) : $user_data->last_name, |
|
1460 | + 'email' => isset($_POST['wpinv_email']) ? sanitize_email($_POST['wpinv_email']) : $user_data->user_email, |
|
1461 | + 'first_name' => isset($_POST['wpinv_first_name']) && !empty($_POST['wpinv_first_name']) ? sanitize_text_field($_POST['wpinv_first_name']) : $user_data->first_name, |
|
1462 | + 'last_name' => isset($_POST['wpinv_last_name']) && !empty($_POST['wpinv_last_name']) ? sanitize_text_field($_POST['wpinv_last_name']) : $user_data->last_name, |
|
1463 | 1463 | ); |
1464 | 1464 | |
1465 | - if ( !empty( $_POST[ 'wpinv_email' ] ) && !is_email( $_POST[ 'wpinv_email' ] ) ) { |
|
1466 | - wpinv_set_error( 'invalid_email', __( 'Please enter a valid email address', 'invoicing' ) ); |
|
1465 | + if (!empty($_POST['wpinv_email']) && !is_email($_POST['wpinv_email'])) { |
|
1466 | + wpinv_set_error('invalid_email', __('Please enter a valid email address', 'invoicing')); |
|
1467 | 1467 | } |
1468 | 1468 | } else { |
1469 | 1469 | // Set invalid user error |
1470 | - wpinv_set_error( 'invalid_user', __( 'The user billing information is invalid', 'invoicing' ) ); |
|
1470 | + wpinv_set_error('invalid_user', __('The user billing information is invalid', 'invoicing')); |
|
1471 | 1471 | } |
1472 | 1472 | } else { |
1473 | 1473 | // Set invalid user error |
1474 | - wpinv_set_error( 'invalid_user_id', __( 'The invalid invoice user id', 'invoicing' ) ); |
|
1474 | + wpinv_set_error('invalid_user_id', __('The invalid invoice user id', 'invoicing')); |
|
1475 | 1475 | } |
1476 | 1476 | |
1477 | 1477 | // Return user data |
@@ -1483,27 +1483,27 @@ discard block |
||
1483 | 1483 | |
1484 | 1484 | $data = array(); |
1485 | 1485 | |
1486 | - if ( is_user_logged_in() ) { |
|
1487 | - if ( !wpinv_require_login_to_checkout() || ( wpinv_require_login_to_checkout() && (int)$wpi_cart->get_user_id() === (int)get_current_user_id() ) ) { |
|
1488 | - $data['user_id'] = (int)get_current_user_id(); |
|
1486 | + if (is_user_logged_in()) { |
|
1487 | + if (!wpinv_require_login_to_checkout() || (wpinv_require_login_to_checkout() && (int) $wpi_cart->get_user_id() === (int) get_current_user_id())) { |
|
1488 | + $data['user_id'] = (int) get_current_user_id(); |
|
1489 | 1489 | } else { |
1490 | - wpinv_set_error( 'logged_in_only', __( 'You are not allowed to pay for this invoice', 'invoicing' ) ); |
|
1490 | + wpinv_set_error('logged_in_only', __('You are not allowed to pay for this invoice', 'invoicing')); |
|
1491 | 1491 | } |
1492 | 1492 | } else { |
1493 | 1493 | // If guest checkout allowed |
1494 | - if ( !wpinv_require_login_to_checkout() ) { |
|
1494 | + if (!wpinv_require_login_to_checkout()) { |
|
1495 | 1495 | $data['user_id'] = 0; |
1496 | 1496 | } else { |
1497 | - wpinv_set_error( 'logged_in_only', __( 'You must be logged in to pay for this invoice', 'invoicing' ) ); |
|
1497 | + wpinv_set_error('logged_in_only', __('You must be logged in to pay for this invoice', 'invoicing')); |
|
1498 | 1498 | } |
1499 | 1499 | } |
1500 | 1500 | |
1501 | 1501 | return $data; |
1502 | 1502 | } |
1503 | 1503 | |
1504 | -function wpinv_checkout_form_get_user( $valid_data = array() ) { |
|
1504 | +function wpinv_checkout_form_get_user($valid_data = array()) { |
|
1505 | 1505 | |
1506 | - if ( !empty( $valid_data['current_user']['user_id'] ) ) { |
|
1506 | + if (!empty($valid_data['current_user']['user_id'])) { |
|
1507 | 1507 | $user = $valid_data['current_user']; |
1508 | 1508 | } else { |
1509 | 1509 | // Set the valid invoice user |
@@ -1511,7 +1511,7 @@ discard block |
||
1511 | 1511 | } |
1512 | 1512 | |
1513 | 1513 | // Verify invoice have an user |
1514 | - if ( false === $user || empty( $user ) ) { |
|
1514 | + if (false === $user || empty($user)) { |
|
1515 | 1515 | return false; |
1516 | 1516 | } |
1517 | 1517 | |
@@ -1528,11 +1528,11 @@ discard block |
||
1528 | 1528 | 'zip', |
1529 | 1529 | ); |
1530 | 1530 | |
1531 | - foreach ( $address_fields as $field ) { |
|
1532 | - $user[$field] = !empty( $_POST['wpinv_' . $field] ) ? sanitize_text_field( $_POST['wpinv_' . $field] ) : false; |
|
1531 | + foreach ($address_fields as $field) { |
|
1532 | + $user[$field] = !empty($_POST['wpinv_' . $field]) ? sanitize_text_field($_POST['wpinv_' . $field]) : false; |
|
1533 | 1533 | |
1534 | - if ( !empty( $user['user_id'] ) && !empty( $valid_data['current_user']['user_id'] ) && $valid_data['current_user']['user_id'] == $valid_data['invoice_user']['user_id'] ) { |
|
1535 | - update_user_meta( $user['user_id'], '_wpinv_' . $field, $user[$field] ); |
|
1534 | + if (!empty($user['user_id']) && !empty($valid_data['current_user']['user_id']) && $valid_data['current_user']['user_id'] == $valid_data['invoice_user']['user_id']) { |
|
1535 | + update_user_meta($user['user_id'], '_wpinv_' . $field, $user[$field]); |
|
1536 | 1536 | } |
1537 | 1537 | } |
1538 | 1538 | |
@@ -1540,28 +1540,28 @@ discard block |
||
1540 | 1540 | return $user; |
1541 | 1541 | } |
1542 | 1542 | |
1543 | -function wpinv_set_checkout_session( $invoice_data = array() ) { |
|
1543 | +function wpinv_set_checkout_session($invoice_data = array()) { |
|
1544 | 1544 | global $wpi_session; |
1545 | 1545 | |
1546 | - return $wpi_session->set( 'wpinv_checkout', $invoice_data ); |
|
1546 | + return $wpi_session->set('wpinv_checkout', $invoice_data); |
|
1547 | 1547 | } |
1548 | 1548 | |
1549 | 1549 | function wpinv_get_checkout_session() { |
1550 | 1550 | global $wpi_session; |
1551 | 1551 | |
1552 | - return $wpi_session->get( 'wpinv_checkout' ); |
|
1552 | + return $wpi_session->get('wpinv_checkout'); |
|
1553 | 1553 | } |
1554 | 1554 | |
1555 | 1555 | function wpinv_empty_cart() { |
1556 | 1556 | global $wpi_session; |
1557 | 1557 | |
1558 | 1558 | // Remove cart contents |
1559 | - $wpi_session->set( 'wpinv_checkout', NULL ); |
|
1559 | + $wpi_session->set('wpinv_checkout', NULL); |
|
1560 | 1560 | |
1561 | 1561 | // Remove all cart fees |
1562 | - $wpi_session->set( 'wpi_cart_fees', NULL ); |
|
1562 | + $wpi_session->set('wpi_cart_fees', NULL); |
|
1563 | 1563 | |
1564 | - do_action( 'wpinv_empty_cart' ); |
|
1564 | + do_action('wpinv_empty_cart'); |
|
1565 | 1565 | } |
1566 | 1566 | |
1567 | 1567 | function wpinv_process_checkout() { |
@@ -1570,7 +1570,7 @@ discard block |
||
1570 | 1570 | wpinv_clear_errors(); |
1571 | 1571 | |
1572 | 1572 | $invoice = wpinv_get_invoice_cart(); |
1573 | - if ( empty( $invoice ) ) { |
|
1573 | + if (empty($invoice)) { |
|
1574 | 1574 | return false; |
1575 | 1575 | } |
1576 | 1576 | |
@@ -1578,42 +1578,42 @@ discard block |
||
1578 | 1578 | |
1579 | 1579 | $wpi_checkout_id = $invoice->ID; |
1580 | 1580 | |
1581 | - do_action( 'wpinv_pre_process_checkout' ); |
|
1581 | + do_action('wpinv_pre_process_checkout'); |
|
1582 | 1582 | |
1583 | - if ( !wpinv_get_cart_contents() ) { // Make sure the cart isn't empty |
|
1583 | + if (!wpinv_get_cart_contents()) { // Make sure the cart isn't empty |
|
1584 | 1584 | $valid_data = false; |
1585 | - wpinv_set_error( 'empty_cart', __( 'Your cart is empty', 'invoicing' ) ); |
|
1585 | + wpinv_set_error('empty_cart', __('Your cart is empty', 'invoicing')); |
|
1586 | 1586 | } else { |
1587 | 1587 | // Validate the form $_POST data |
1588 | 1588 | $valid_data = wpinv_validate_checkout_fields(); |
1589 | 1589 | |
1590 | 1590 | // Allow themes and plugins to hook to errors |
1591 | - do_action( 'wpinv_checkout_error_checks', $valid_data, $_POST ); |
|
1591 | + do_action('wpinv_checkout_error_checks', $valid_data, $_POST); |
|
1592 | 1592 | } |
1593 | 1593 | |
1594 | - $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; |
|
1594 | + $is_ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
1595 | 1595 | |
1596 | 1596 | // Validate the user |
1597 | - $user = wpinv_checkout_form_get_user( $valid_data ); |
|
1597 | + $user = wpinv_checkout_form_get_user($valid_data); |
|
1598 | 1598 | |
1599 | 1599 | // Let extensions validate fields after user is logged in if user has used login/registration form |
1600 | - do_action( 'wpinv_checkout_user_error_checks', $user, $valid_data, $_POST ); |
|
1600 | + do_action('wpinv_checkout_user_error_checks', $user, $valid_data, $_POST); |
|
1601 | 1601 | |
1602 | - if ( false === $valid_data || wpinv_get_errors() || ! $user ) { |
|
1603 | - if ( $is_ajax ) { |
|
1604 | - do_action( 'wpinv_ajax_checkout_errors' ); |
|
1602 | + if (false === $valid_data || wpinv_get_errors() || !$user) { |
|
1603 | + if ($is_ajax) { |
|
1604 | + do_action('wpinv_ajax_checkout_errors'); |
|
1605 | 1605 | die(); |
1606 | 1606 | } else { |
1607 | 1607 | return false; |
1608 | 1608 | } |
1609 | 1609 | } |
1610 | 1610 | |
1611 | - if ( $is_ajax ) { |
|
1611 | + if ($is_ajax) { |
|
1612 | 1612 | // Save address fields. |
1613 | - $address_fields = array( 'first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company' ); |
|
1614 | - foreach ( $address_fields as $field ) { |
|
1615 | - if ( isset( $user[$field] ) ) { |
|
1616 | - $invoice->set( $field, $user[$field] ); |
|
1613 | + $address_fields = array('first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company'); |
|
1614 | + foreach ($address_fields as $field) { |
|
1615 | + if (isset($user[$field])) { |
|
1616 | + $invoice->set($field, $user[$field]); |
|
1617 | 1617 | } |
1618 | 1618 | |
1619 | 1619 | $invoice->save(); |
@@ -1621,16 +1621,16 @@ discard block |
||
1621 | 1621 | |
1622 | 1622 | $response['success'] = true; |
1623 | 1623 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
1624 | - $response['data']['subtotalf'] = $invoice->get_subtotal( true ); |
|
1624 | + $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
|
1625 | 1625 | $response['data']['discount'] = $invoice->get_discount(); |
1626 | - $response['data']['discountf'] = $invoice->get_discount( true ); |
|
1626 | + $response['data']['discountf'] = $invoice->get_discount(true); |
|
1627 | 1627 | $response['data']['tax'] = $invoice->get_tax(); |
1628 | - $response['data']['taxf'] = $invoice->get_tax( true ); |
|
1628 | + $response['data']['taxf'] = $invoice->get_tax(true); |
|
1629 | 1629 | $response['data']['total'] = $invoice->get_total(); |
1630 | - $response['data']['totalf'] = $invoice->get_total( true ); |
|
1631 | - $response['data']['free'] = $invoice->is_free() && ( ! ( (float) $response['data']['total'] > 0 ) || $invoice->is_free_trial() ) ? true : false; |
|
1630 | + $response['data']['totalf'] = $invoice->get_total(true); |
|
1631 | + $response['data']['free'] = $invoice->is_free() && (!((float) $response['data']['total'] > 0) || $invoice->is_free_trial()) ? true : false; |
|
1632 | 1632 | |
1633 | - wp_send_json( $response ); |
|
1633 | + wp_send_json($response); |
|
1634 | 1634 | } |
1635 | 1635 | |
1636 | 1636 | $user_info = array( |
@@ -1652,42 +1652,42 @@ discard block |
||
1652 | 1652 | |
1653 | 1653 | // Setup invoice information |
1654 | 1654 | $invoice_data = array( |
1655 | - 'invoice_id' => !empty( $invoice ) ? $invoice->ID : 0, |
|
1655 | + 'invoice_id' => !empty($invoice) ? $invoice->ID : 0, |
|
1656 | 1656 | 'items' => $cart_items, |
1657 | 1657 | 'cart_discounts' => $discounts, |
1658 | - 'fees' => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart |
|
1659 | - 'subtotal' => wpinv_get_cart_subtotal( $cart_items ), // Amount before taxes and discounts |
|
1660 | - 'discount' => wpinv_get_cart_items_discount_amount( $cart_items, $discounts ), // Discounted amount |
|
1661 | - 'tax' => wpinv_get_cart_tax( $cart_items ), // Taxed amount |
|
1662 | - 'price' => wpinv_get_cart_total( $cart_items, $discounts ), // Amount after taxes |
|
1658 | + 'fees' => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart |
|
1659 | + 'subtotal' => wpinv_get_cart_subtotal($cart_items), // Amount before taxes and discounts |
|
1660 | + 'discount' => wpinv_get_cart_items_discount_amount($cart_items, $discounts), // Discounted amount |
|
1661 | + 'tax' => wpinv_get_cart_tax($cart_items), // Taxed amount |
|
1662 | + 'price' => wpinv_get_cart_total($cart_items, $discounts), // Amount after taxes |
|
1663 | 1663 | 'invoice_key' => $invoice->get_key() ? $invoice->get_key() : $invoice->generate_key(), |
1664 | 1664 | 'user_email' => $invoice->get_email(), |
1665 | - 'date' => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ), |
|
1666 | - 'user_info' => stripslashes_deep( $user_info ), |
|
1665 | + 'date' => date('Y-m-d H:i:s', current_time('timestamp')), |
|
1666 | + 'user_info' => stripslashes_deep($user_info), |
|
1667 | 1667 | 'post_data' => $_POST, |
1668 | 1668 | 'cart_details' => $cart_items, |
1669 | 1669 | 'gateway' => $valid_data['gateway'], |
1670 | 1670 | 'card_info' => $valid_data['cc_info'] |
1671 | 1671 | ); |
1672 | 1672 | |
1673 | - $vat_info = $wpinv_euvat->current_vat_data(); |
|
1674 | - if ( is_array( $vat_info ) ) { |
|
1673 | + $vat_info = $wpinv_euvat->current_vat_data(); |
|
1674 | + if (is_array($vat_info)) { |
|
1675 | 1675 | $invoice_data['user_info']['vat_number'] = $vat_info['number']; |
1676 | 1676 | $invoice_data['user_info']['vat_rate'] = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state']); |
1677 | - $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false; |
|
1677 | + $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false; |
|
1678 | 1678 | |
1679 | 1679 | // Add the VAT rate to each item in the cart |
1680 | - foreach( $invoice_data['cart_details'] as $key => $item_data) { |
|
1680 | + foreach ($invoice_data['cart_details'] as $key => $item_data) { |
|
1681 | 1681 | $rate = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state'], $item_data['id']); |
1682 | - $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount( $rate, 4 ); |
|
1682 | + $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount($rate, 4); |
|
1683 | 1683 | } |
1684 | 1684 | } |
1685 | 1685 | |
1686 | 1686 | // Save vat fields. |
1687 | - $address_fields = array( 'vat_number', 'vat_rate', 'adddress_confirmed' ); |
|
1688 | - foreach ( $address_fields as $field ) { |
|
1689 | - if ( isset( $invoice_data['user_info'][$field] ) ) { |
|
1690 | - $invoice->set( $field, $invoice_data['user_info'][$field] ); |
|
1687 | + $address_fields = array('vat_number', 'vat_rate', 'adddress_confirmed'); |
|
1688 | + foreach ($address_fields as $field) { |
|
1689 | + if (isset($invoice_data['user_info'][$field])) { |
|
1690 | + $invoice->set($field, $invoice_data['user_info'][$field]); |
|
1691 | 1691 | } |
1692 | 1692 | |
1693 | 1693 | $invoice->save(); |
@@ -1697,55 +1697,55 @@ discard block |
||
1697 | 1697 | $valid_data['user'] = $user; |
1698 | 1698 | |
1699 | 1699 | // Allow themes and plugins to hook before the gateway |
1700 | - do_action( 'wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data ); |
|
1700 | + do_action('wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data); |
|
1701 | 1701 | |
1702 | 1702 | // If the total amount in the cart is 0, send to the manual gateway. This emulates a free invoice |
1703 | - if ( !$invoice_data['price'] ) { |
|
1703 | + if (!$invoice_data['price']) { |
|
1704 | 1704 | // Revert to manual |
1705 | 1705 | $invoice_data['gateway'] = 'manual'; |
1706 | 1706 | $_POST['wpi-gateway'] = 'manual'; |
1707 | 1707 | } |
1708 | 1708 | |
1709 | 1709 | // Allow the invoice data to be modified before it is sent to the gateway |
1710 | - $invoice_data = apply_filters( 'wpinv_data_before_gateway', $invoice_data, $valid_data ); |
|
1710 | + $invoice_data = apply_filters('wpinv_data_before_gateway', $invoice_data, $valid_data); |
|
1711 | 1711 | |
1712 | - if ( $invoice_data['price'] && $invoice_data['gateway'] == 'manual' ) { |
|
1712 | + if ($invoice_data['price'] && $invoice_data['gateway'] == 'manual') { |
|
1713 | 1713 | $mode = 'test'; |
1714 | 1714 | } else { |
1715 | - $mode = wpinv_is_test_mode( $invoice_data['gateway'] ) ? 'test' : 'live'; |
|
1715 | + $mode = wpinv_is_test_mode($invoice_data['gateway']) ? 'test' : 'live'; |
|
1716 | 1716 | } |
1717 | 1717 | |
1718 | 1718 | // Setup the data we're storing in the purchase session |
1719 | 1719 | $session_data = $invoice_data; |
1720 | 1720 | // Make sure credit card numbers are never stored in sessions |
1721 | - if ( !empty( $session_data['card_info']['card_number'] ) ) { |
|
1722 | - unset( $session_data['card_info']['card_number'] ); |
|
1721 | + if (!empty($session_data['card_info']['card_number'])) { |
|
1722 | + unset($session_data['card_info']['card_number']); |
|
1723 | 1723 | } |
1724 | 1724 | |
1725 | 1725 | // Used for showing item links to non logged-in users after purchase, and for other plugins needing purchase data. |
1726 | - wpinv_set_checkout_session( $invoice_data ); |
|
1726 | + wpinv_set_checkout_session($invoice_data); |
|
1727 | 1727 | |
1728 | 1728 | // Set gateway |
1729 | - $invoice->update_meta( '_wpinv_gateway', $invoice_data['gateway'] ); |
|
1730 | - $invoice->update_meta( '_wpinv_mode', $mode ); |
|
1731 | - $invoice->update_meta( '_wpinv_checkout', date_i18n( 'Y-m-d H:i:s', current_time( 'timestamp' ) ) ); |
|
1729 | + $invoice->update_meta('_wpinv_gateway', $invoice_data['gateway']); |
|
1730 | + $invoice->update_meta('_wpinv_mode', $mode); |
|
1731 | + $invoice->update_meta('_wpinv_checkout', date_i18n('Y-m-d H:i:s', current_time('timestamp'))); |
|
1732 | 1732 | |
1733 | - do_action( 'wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data ); |
|
1733 | + do_action('wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data); |
|
1734 | 1734 | |
1735 | 1735 | // Send info to the gateway for payment processing |
1736 | - wpinv_send_to_gateway( $invoice_data['gateway'], $invoice_data ); |
|
1736 | + wpinv_send_to_gateway($invoice_data['gateway'], $invoice_data); |
|
1737 | 1737 | die(); |
1738 | 1738 | } |
1739 | -add_action( 'wpinv_payment', 'wpinv_process_checkout' ); |
|
1739 | +add_action('wpinv_payment', 'wpinv_process_checkout'); |
|
1740 | 1740 | |
1741 | -function wpinv_get_invoices( $args ) { |
|
1742 | - $args = wp_parse_args( $args, array( |
|
1743 | - 'status' => array_keys( wpinv_get_invoice_statuses() ), |
|
1741 | +function wpinv_get_invoices($args) { |
|
1742 | + $args = wp_parse_args($args, array( |
|
1743 | + 'status' => array_keys(wpinv_get_invoice_statuses()), |
|
1744 | 1744 | 'type' => 'wpi_invoice', |
1745 | 1745 | 'parent' => null, |
1746 | 1746 | 'user' => null, |
1747 | 1747 | 'email' => '', |
1748 | - 'limit' => get_option( 'posts_per_page' ), |
|
1748 | + 'limit' => get_option('posts_per_page'), |
|
1749 | 1749 | 'offset' => null, |
1750 | 1750 | 'page' => 1, |
1751 | 1751 | 'exclude' => array(), |
@@ -1753,7 +1753,7 @@ discard block |
||
1753 | 1753 | 'order' => 'DESC', |
1754 | 1754 | 'return' => 'objects', |
1755 | 1755 | 'paginate' => false, |
1756 | - ) ); |
|
1756 | + )); |
|
1757 | 1757 | |
1758 | 1758 | // Handle some BW compatibility arg names where wp_query args differ in naming. |
1759 | 1759 | $map_legacy = array( |
@@ -1766,18 +1766,18 @@ discard block |
||
1766 | 1766 | 'paged' => 'page', |
1767 | 1767 | ); |
1768 | 1768 | |
1769 | - foreach ( $map_legacy as $from => $to ) { |
|
1770 | - if ( isset( $args[ $from ] ) ) { |
|
1771 | - $args[ $to ] = $args[ $from ]; |
|
1769 | + foreach ($map_legacy as $from => $to) { |
|
1770 | + if (isset($args[$from])) { |
|
1771 | + $args[$to] = $args[$from]; |
|
1772 | 1772 | } |
1773 | 1773 | } |
1774 | 1774 | |
1775 | - if ( get_query_var( 'paged' ) ) |
|
1775 | + if (get_query_var('paged')) |
|
1776 | 1776 | $args['page'] = get_query_var('paged'); |
1777 | - else if ( get_query_var( 'page' ) ) |
|
1778 | - $args['page'] = get_query_var( 'page' ); |
|
1779 | - else if ( !empty( $args[ 'page' ] ) ) |
|
1780 | - $args['page'] = $args[ 'page' ]; |
|
1777 | + else if (get_query_var('page')) |
|
1778 | + $args['page'] = get_query_var('page'); |
|
1779 | + else if (!empty($args['page'])) |
|
1780 | + $args['page'] = $args['page']; |
|
1781 | 1781 | else |
1782 | 1782 | $args['page'] = 1; |
1783 | 1783 | |
@@ -1790,48 +1790,48 @@ discard block |
||
1790 | 1790 | 'post_status' => $args['status'], |
1791 | 1791 | 'posts_per_page' => $args['limit'], |
1792 | 1792 | 'meta_query' => array(), |
1793 | - 'date_query' => !empty( $args['date_query'] ) ? $args['date_query'] : array(), |
|
1793 | + 'date_query' => !empty($args['date_query']) ? $args['date_query'] : array(), |
|
1794 | 1794 | 'fields' => 'ids', |
1795 | 1795 | 'orderby' => $args['orderby'], |
1796 | 1796 | 'order' => $args['order'], |
1797 | 1797 | ); |
1798 | 1798 | |
1799 | - if ( !empty( $args['user'] ) ) { |
|
1800 | - $wp_query_args['author'] = absint( $args['user'] ); |
|
1799 | + if (!empty($args['user'])) { |
|
1800 | + $wp_query_args['author'] = absint($args['user']); |
|
1801 | 1801 | } |
1802 | 1802 | |
1803 | - if ( ! is_null( $args['parent'] ) ) { |
|
1804 | - $wp_query_args['post_parent'] = absint( $args['parent'] ); |
|
1803 | + if (!is_null($args['parent'])) { |
|
1804 | + $wp_query_args['post_parent'] = absint($args['parent']); |
|
1805 | 1805 | } |
1806 | 1806 | |
1807 | - if ( ! is_null( $args['offset'] ) ) { |
|
1808 | - $wp_query_args['offset'] = absint( $args['offset'] ); |
|
1807 | + if (!is_null($args['offset'])) { |
|
1808 | + $wp_query_args['offset'] = absint($args['offset']); |
|
1809 | 1809 | } else { |
1810 | - $wp_query_args['paged'] = absint( $args['page'] ); |
|
1810 | + $wp_query_args['paged'] = absint($args['page']); |
|
1811 | 1811 | } |
1812 | 1812 | |
1813 | - if ( ! empty( $args['exclude'] ) ) { |
|
1814 | - $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] ); |
|
1813 | + if (!empty($args['exclude'])) { |
|
1814 | + $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']); |
|
1815 | 1815 | } |
1816 | 1816 | |
1817 | - if ( ! $args['paginate' ] ) { |
|
1817 | + if (!$args['paginate']) { |
|
1818 | 1818 | $wp_query_args['no_found_rows'] = true; |
1819 | 1819 | } |
1820 | 1820 | |
1821 | 1821 | $wp_query_args = apply_filters('wpinv_get_invoices_args', $wp_query_args, $args); |
1822 | 1822 | |
1823 | 1823 | // Get results. |
1824 | - $invoices = new WP_Query( $wp_query_args ); |
|
1824 | + $invoices = new WP_Query($wp_query_args); |
|
1825 | 1825 | |
1826 | - if ( 'objects' === $args['return'] ) { |
|
1827 | - $return = array_map( 'wpinv_get_invoice', $invoices->posts ); |
|
1828 | - } elseif ( 'self' === $args['return'] ) { |
|
1826 | + if ('objects' === $args['return']) { |
|
1827 | + $return = array_map('wpinv_get_invoice', $invoices->posts); |
|
1828 | + } elseif ('self' === $args['return']) { |
|
1829 | 1829 | return $invoices; |
1830 | 1830 | } else { |
1831 | 1831 | $return = $invoices->posts; |
1832 | 1832 | } |
1833 | 1833 | |
1834 | - if ( $args['paginate' ] ) { |
|
1834 | + if ($args['paginate']) { |
|
1835 | 1835 | return (object) array( |
1836 | 1836 | 'invoices' => $return, |
1837 | 1837 | 'total' => $invoices->found_posts, |
@@ -1844,22 +1844,22 @@ discard block |
||
1844 | 1844 | |
1845 | 1845 | function wpinv_get_user_invoices_columns() { |
1846 | 1846 | $columns = array( |
1847 | - 'invoice-number' => array( 'title' => __( 'ID', 'invoicing' ), 'class' => 'text-left' ), |
|
1848 | - 'created-date' => array( 'title' => __( 'Created Date', 'invoicing' ), 'class' => 'text-left' ), |
|
1849 | - 'payment-date' => array( 'title' => __( 'Payment Date', 'invoicing' ), 'class' => 'text-left' ), |
|
1850 | - 'invoice-status' => array( 'title' => __( 'Status', 'invoicing' ), 'class' => 'text-center' ), |
|
1851 | - 'invoice-total' => array( 'title' => __( 'Total', 'invoicing' ), 'class' => 'text-right' ), |
|
1852 | - 'invoice-actions' => array( 'title' => ' ', 'class' => 'text-center' ), |
|
1847 | + 'invoice-number' => array('title' => __('ID', 'invoicing'), 'class' => 'text-left'), |
|
1848 | + 'created-date' => array('title' => __('Created Date', 'invoicing'), 'class' => 'text-left'), |
|
1849 | + 'payment-date' => array('title' => __('Payment Date', 'invoicing'), 'class' => 'text-left'), |
|
1850 | + 'invoice-status' => array('title' => __('Status', 'invoicing'), 'class' => 'text-center'), |
|
1851 | + 'invoice-total' => array('title' => __('Total', 'invoicing'), 'class' => 'text-right'), |
|
1852 | + 'invoice-actions' => array('title' => ' ', 'class' => 'text-center'), |
|
1853 | 1853 | ); |
1854 | 1854 | |
1855 | - return apply_filters( 'wpinv_user_invoices_columns', $columns ); |
|
1855 | + return apply_filters('wpinv_user_invoices_columns', $columns); |
|
1856 | 1856 | } |
1857 | 1857 | |
1858 | -function wpinv_payment_receipt( $atts, $content = null ) { |
|
1858 | +function wpinv_payment_receipt($atts, $content = null) { |
|
1859 | 1859 | global $wpinv_receipt_args; |
1860 | 1860 | |
1861 | - $wpinv_receipt_args = shortcode_atts( array( |
|
1862 | - 'error' => __( 'Sorry, trouble retrieving payment receipt.', 'invoicing' ), |
|
1861 | + $wpinv_receipt_args = shortcode_atts(array( |
|
1862 | + 'error' => __('Sorry, trouble retrieving payment receipt.', 'invoicing'), |
|
1863 | 1863 | 'price' => true, |
1864 | 1864 | 'discount' => true, |
1865 | 1865 | 'items' => true, |
@@ -1868,197 +1868,197 @@ discard block |
||
1868 | 1868 | 'invoice_key' => false, |
1869 | 1869 | 'payment_method' => true, |
1870 | 1870 | 'invoice_id' => true |
1871 | - ), $atts, 'wpinv_receipt' ); |
|
1871 | + ), $atts, 'wpinv_receipt'); |
|
1872 | 1872 | |
1873 | 1873 | $session = wpinv_get_checkout_session(); |
1874 | - if ( isset( $_GET['invoice_key'] ) ) { |
|
1875 | - $invoice_key = urldecode( $_GET['invoice_key'] ); |
|
1876 | - } else if ( $session && isset( $session['invoice_key'] ) ) { |
|
1874 | + if (isset($_GET['invoice_key'])) { |
|
1875 | + $invoice_key = urldecode($_GET['invoice_key']); |
|
1876 | + } else if ($session && isset($session['invoice_key'])) { |
|
1877 | 1877 | $invoice_key = $session['invoice_key']; |
1878 | - } elseif ( isset( $wpinv_receipt_args['invoice_key'] ) && $wpinv_receipt_args['invoice_key'] ) { |
|
1878 | + } elseif (isset($wpinv_receipt_args['invoice_key']) && $wpinv_receipt_args['invoice_key']) { |
|
1879 | 1879 | $invoice_key = $wpinv_receipt_args['invoice_key']; |
1880 | - } else if ( isset( $_GET['invoice-id'] ) ) { |
|
1881 | - $invoice_key = wpinv_get_payment_key( (int)$_GET['invoice-id'] ); |
|
1880 | + } else if (isset($_GET['invoice-id'])) { |
|
1881 | + $invoice_key = wpinv_get_payment_key((int) $_GET['invoice-id']); |
|
1882 | 1882 | } |
1883 | 1883 | |
1884 | 1884 | // No key found |
1885 | - if ( ! isset( $invoice_key ) ) { |
|
1885 | + if (!isset($invoice_key)) { |
|
1886 | 1886 | return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>'; |
1887 | 1887 | } |
1888 | 1888 | |
1889 | - $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
1890 | - $user_can_view = wpinv_can_view_receipt( $invoice_key ); |
|
1891 | - if ( $user_can_view && isset( $_GET['invoice-id'] ) ) { |
|
1892 | - $invoice_id = (int)$_GET['invoice-id']; |
|
1893 | - $user_can_view = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false; |
|
1889 | + $invoice_id = wpinv_get_invoice_id_by_key($invoice_key); |
|
1890 | + $user_can_view = wpinv_can_view_receipt($invoice_key); |
|
1891 | + if ($user_can_view && isset($_GET['invoice-id'])) { |
|
1892 | + $invoice_id = (int) $_GET['invoice-id']; |
|
1893 | + $user_can_view = $invoice_key == wpinv_get_payment_key((int) $_GET['invoice-id']) ? true : false; |
|
1894 | 1894 | } |
1895 | 1895 | |
1896 | 1896 | // Key was provided, but user is logged out. Offer them the ability to login and view the receipt |
1897 | - if ( ! $user_can_view && ! empty( $invoice_key ) && ! is_user_logged_in() ) { |
|
1897 | + if (!$user_can_view && !empty($invoice_key) && !is_user_logged_in()) { |
|
1898 | 1898 | // login redirect |
1899 | - return '<p class="alert alert-error">' . __( 'You are not allowed to access this section', 'invoicing' ) . '</p>'; |
|
1899 | + return '<p class="alert alert-error">' . __('You are not allowed to access this section', 'invoicing') . '</p>'; |
|
1900 | 1900 | } |
1901 | 1901 | |
1902 | - if ( ! apply_filters( 'wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args ) ) { |
|
1902 | + if (!apply_filters('wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args)) { |
|
1903 | 1903 | return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>'; |
1904 | 1904 | } |
1905 | 1905 | |
1906 | 1906 | ob_start(); |
1907 | 1907 | |
1908 | - wpinv_get_template_part( 'wpinv-invoice-receipt' ); |
|
1908 | + wpinv_get_template_part('wpinv-invoice-receipt'); |
|
1909 | 1909 | |
1910 | 1910 | $display = ob_get_clean(); |
1911 | 1911 | |
1912 | 1912 | return $display; |
1913 | 1913 | } |
1914 | 1914 | |
1915 | -function wpinv_get_invoice_id_by_key( $key ) { |
|
1915 | +function wpinv_get_invoice_id_by_key($key) { |
|
1916 | 1916 | global $wpdb; |
1917 | 1917 | |
1918 | - $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key ) ); |
|
1918 | + $invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key)); |
|
1919 | 1919 | |
1920 | - if ( $invoice_id != NULL ) |
|
1920 | + if ($invoice_id != NULL) |
|
1921 | 1921 | return $invoice_id; |
1922 | 1922 | |
1923 | 1923 | return 0; |
1924 | 1924 | } |
1925 | 1925 | |
1926 | -function wpinv_can_view_receipt( $invoice_key = '' ) { |
|
1926 | +function wpinv_can_view_receipt($invoice_key = '') { |
|
1927 | 1927 | $return = false; |
1928 | 1928 | |
1929 | - if ( empty( $invoice_key ) ) { |
|
1929 | + if (empty($invoice_key)) { |
|
1930 | 1930 | return $return; |
1931 | 1931 | } |
1932 | 1932 | |
1933 | 1933 | global $wpinv_receipt_args; |
1934 | 1934 | |
1935 | - $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
1936 | - if ( isset( $_GET['invoice-id'] ) ) { |
|
1937 | - $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0; |
|
1935 | + $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key($invoice_key); |
|
1936 | + if (isset($_GET['invoice-id'])) { |
|
1937 | + $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key((int) $_GET['invoice-id']) ? (int) $_GET['invoice-id'] : 0; |
|
1938 | 1938 | } |
1939 | 1939 | |
1940 | - if ( empty( $wpinv_receipt_args['id'] ) ) { |
|
1940 | + if (empty($wpinv_receipt_args['id'])) { |
|
1941 | 1941 | return $return; |
1942 | 1942 | } |
1943 | 1943 | |
1944 | - $invoice = wpinv_get_invoice( $wpinv_receipt_args['id'] ); |
|
1945 | - if ( !( !empty( $invoice->ID ) && $invoice->get_key() === $invoice_key ) ) { |
|
1944 | + $invoice = wpinv_get_invoice($wpinv_receipt_args['id']); |
|
1945 | + if (!(!empty($invoice->ID) && $invoice->get_key() === $invoice_key)) { |
|
1946 | 1946 | return $return; |
1947 | 1947 | } |
1948 | 1948 | |
1949 | - if ( is_user_logged_in() ) { |
|
1950 | - if ( (int)$invoice->get_user_id() === (int) get_current_user_id() ) { |
|
1949 | + if (is_user_logged_in()) { |
|
1950 | + if ((int) $invoice->get_user_id() === (int) get_current_user_id()) { |
|
1951 | 1951 | $return = true; |
1952 | 1952 | } |
1953 | 1953 | } |
1954 | 1954 | |
1955 | 1955 | $session = wpinv_get_checkout_session(); |
1956 | - if ( isset( $_GET['invoice_key'] ) || ( $session && isset( $session['invoice_key'] ) ) ) { |
|
1957 | - $check_key = isset( $_GET['invoice_key'] ) ? $_GET['invoice_key'] : $session['invoice_key']; |
|
1956 | + if (isset($_GET['invoice_key']) || ($session && isset($session['invoice_key']))) { |
|
1957 | + $check_key = isset($_GET['invoice_key']) ? $_GET['invoice_key'] : $session['invoice_key']; |
|
1958 | 1958 | |
1959 | - if ( wpinv_require_login_to_checkout() ) { |
|
1959 | + if (wpinv_require_login_to_checkout()) { |
|
1960 | 1960 | $return = $return && $check_key === $invoice_key; |
1961 | 1961 | } else { |
1962 | 1962 | $return = $check_key === $invoice_key; |
1963 | 1963 | } |
1964 | 1964 | } |
1965 | 1965 | |
1966 | - return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key ); |
|
1966 | + return (bool) apply_filters('wpinv_can_view_receipt', $return, $invoice_key); |
|
1967 | 1967 | } |
1968 | 1968 | |
1969 | 1969 | function wpinv_pay_for_invoice() { |
1970 | 1970 | global $wpinv_euvat; |
1971 | 1971 | |
1972 | - if ( isset( $_GET['invoice_key'] ) ) { |
|
1972 | + if (isset($_GET['invoice_key'])) { |
|
1973 | 1973 | $checkout_uri = wpinv_get_checkout_uri(); |
1974 | - $invoice_key = sanitize_text_field( $_GET['invoice_key'] ); |
|
1974 | + $invoice_key = sanitize_text_field($_GET['invoice_key']); |
|
1975 | 1975 | |
1976 | - if ( empty( $invoice_key ) ) { |
|
1977 | - wpinv_set_error( 'invalid_invoice', __( 'Invoice not found', 'invoicing' ) ); |
|
1978 | - wp_redirect( $checkout_uri ); |
|
1976 | + if (empty($invoice_key)) { |
|
1977 | + wpinv_set_error('invalid_invoice', __('Invoice not found', 'invoicing')); |
|
1978 | + wp_redirect($checkout_uri); |
|
1979 | 1979 | exit(); |
1980 | 1980 | } |
1981 | 1981 | |
1982 | - do_action( 'wpinv_check_pay_for_invoice', $invoice_key ); |
|
1982 | + do_action('wpinv_check_pay_for_invoice', $invoice_key); |
|
1983 | 1983 | |
1984 | - $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
1985 | - $user_can_view = wpinv_can_view_receipt( $invoice_key ); |
|
1986 | - if ( $user_can_view && isset( $_GET['invoice-id'] ) ) { |
|
1987 | - $invoice_id = (int)$_GET['invoice-id']; |
|
1988 | - $user_can_view = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false; |
|
1984 | + $invoice_id = wpinv_get_invoice_id_by_key($invoice_key); |
|
1985 | + $user_can_view = wpinv_can_view_receipt($invoice_key); |
|
1986 | + if ($user_can_view && isset($_GET['invoice-id'])) { |
|
1987 | + $invoice_id = (int) $_GET['invoice-id']; |
|
1988 | + $user_can_view = $invoice_key == wpinv_get_payment_key((int) $_GET['invoice-id']) ? true : false; |
|
1989 | 1989 | } |
1990 | 1990 | |
1991 | - if ( $invoice_id && $user_can_view && ( $invoice = wpinv_get_invoice( $invoice_id ) ) ) { |
|
1992 | - if ( $invoice->needs_payment() ) { |
|
1991 | + if ($invoice_id && $user_can_view && ($invoice = wpinv_get_invoice($invoice_id))) { |
|
1992 | + if ($invoice->needs_payment()) { |
|
1993 | 1993 | $data = array(); |
1994 | 1994 | $data['invoice_id'] = $invoice_id; |
1995 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
1995 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
1996 | 1996 | |
1997 | - wpinv_set_checkout_session( $data ); |
|
1997 | + wpinv_set_checkout_session($data); |
|
1998 | 1998 | |
1999 | - if ( wpinv_get_option( 'vat_ip_country_default' ) ) { |
|
1999 | + if (wpinv_get_option('vat_ip_country_default')) { |
|
2000 | 2000 | $_POST['country'] = $wpinv_euvat->get_country_by_ip(); |
2001 | 2001 | $_POST['state'] = $_POST['country'] == $invoice->country ? $invoice->state : ''; |
2002 | 2002 | |
2003 | - wpinv_recalculate_tax( true ); |
|
2003 | + wpinv_recalculate_tax(true); |
|
2004 | 2004 | } |
2005 | 2005 | |
2006 | 2006 | } else { |
2007 | 2007 | $checkout_uri = $invoice->get_view_url(); |
2008 | 2008 | } |
2009 | 2009 | } else { |
2010 | - wpinv_set_error( 'invalid_invoice', __( 'You are not allowed to view this invoice', 'invoicing' ) ); |
|
2010 | + wpinv_set_error('invalid_invoice', __('You are not allowed to view this invoice', 'invoicing')); |
|
2011 | 2011 | |
2012 | - $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() ); |
|
2012 | + $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink()); |
|
2013 | 2013 | } |
2014 | 2014 | |
2015 | - if(wp_redirect( $checkout_uri )){ |
|
2015 | + if (wp_redirect($checkout_uri)) { |
|
2016 | 2016 | exit; |
2017 | 2017 | }; |
2018 | 2018 | wpinv_die(); |
2019 | 2019 | } |
2020 | 2020 | } |
2021 | -add_action( 'wpinv_pay_for_invoice', 'wpinv_pay_for_invoice' ); |
|
2021 | +add_action('wpinv_pay_for_invoice', 'wpinv_pay_for_invoice'); |
|
2022 | 2022 | |
2023 | -function wpinv_handle_pay_via_invoice_link( $invoice_key ) { |
|
2024 | - if ( !empty( $invoice_key ) && !empty( $_REQUEST['_wpipay'] ) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ) ) { |
|
2025 | - if ( $invoice = wpinv_get_invoice( $invoice_id ) ) { |
|
2023 | +function wpinv_handle_pay_via_invoice_link($invoice_key) { |
|
2024 | + if (!empty($invoice_key) && !empty($_REQUEST['_wpipay']) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key($invoice_key)) { |
|
2025 | + if ($invoice = wpinv_get_invoice($invoice_id)) { |
|
2026 | 2026 | $user_id = $invoice->get_user_id(); |
2027 | - $secret = sanitize_text_field( $_GET['_wpipay'] ); |
|
2027 | + $secret = sanitize_text_field($_GET['_wpipay']); |
|
2028 | 2028 | |
2029 | - if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice_key ) ) { // valid invoice link |
|
2030 | - $redirect_to = remove_query_arg( '_wpipay', get_permalink() ); |
|
2029 | + if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice_key)) { // valid invoice link |
|
2030 | + $redirect_to = remove_query_arg('_wpipay', get_permalink()); |
|
2031 | 2031 | |
2032 | - wpinv_guest_redirect( $redirect_to, $user_id ); |
|
2032 | + wpinv_guest_redirect($redirect_to, $user_id); |
|
2033 | 2033 | exit(); |
2034 | 2034 | } |
2035 | 2035 | } |
2036 | 2036 | } |
2037 | 2037 | } |
2038 | -add_action( 'wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link' ); |
|
2038 | +add_action('wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link'); |
|
2039 | 2039 | |
2040 | -function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) { |
|
2041 | - $invoice_id = is_object( $invoice_id ) && !empty( $invoice_id->ID ) ? $invoice_id : $invoice_id; |
|
2040 | +function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') { |
|
2041 | + $invoice_id = is_object($invoice_id) && !empty($invoice_id->ID) ? $invoice_id : $invoice_id; |
|
2042 | 2042 | |
2043 | - if ( empty( $invoice_id ) && $invoice_id > 0 ) { |
|
2043 | + if (empty($invoice_id) && $invoice_id > 0) { |
|
2044 | 2044 | return false; |
2045 | 2045 | } |
2046 | 2046 | |
2047 | - if ( empty( $transaction_id ) ) { |
|
2047 | + if (empty($transaction_id)) { |
|
2048 | 2048 | $transaction_id = $invoice_id; |
2049 | 2049 | } |
2050 | 2050 | |
2051 | - $transaction_id = apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice_id ); |
|
2051 | + $transaction_id = apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice_id); |
|
2052 | 2052 | |
2053 | - return wpinv_update_invoice_meta( $invoice_id, '_wpinv_transaction_id', $transaction_id ); |
|
2053 | + return wpinv_update_invoice_meta($invoice_id, '_wpinv_transaction_id', $transaction_id); |
|
2054 | 2054 | } |
2055 | 2055 | |
2056 | -function wpinv_invoice_status_label( $status, $status_display = '' ) { |
|
2057 | - if ( empty( $status_display ) ) { |
|
2058 | - $status_display = wpinv_status_nicename( $status ); |
|
2056 | +function wpinv_invoice_status_label($status, $status_display = '') { |
|
2057 | + if (empty($status_display)) { |
|
2058 | + $status_display = wpinv_status_nicename($status); |
|
2059 | 2059 | } |
2060 | 2060 | |
2061 | - switch ( $status ) { |
|
2061 | + switch ($status) { |
|
2062 | 2062 | case 'publish' : |
2063 | 2063 | case 'wpi-renewal' : |
2064 | 2064 | $class = 'label-success'; |
@@ -2083,201 +2083,201 @@ discard block |
||
2083 | 2083 | |
2084 | 2084 | $label = '<span class="label label-inv-' . $status . ' ' . $class . '">' . $status_display . '</span>'; |
2085 | 2085 | |
2086 | - return apply_filters( 'wpinv_invoice_status_label', $label, $status, $status_display ); |
|
2086 | + return apply_filters('wpinv_invoice_status_label', $label, $status, $status_display); |
|
2087 | 2087 | } |
2088 | 2088 | |
2089 | -function wpinv_format_invoice_number( $number, $type = '' ) { |
|
2090 | - $check = apply_filters( 'wpinv_pre_format_invoice_number', null, $number, $type ); |
|
2091 | - if ( null !== $check ) { |
|
2089 | +function wpinv_format_invoice_number($number, $type = '') { |
|
2090 | + $check = apply_filters('wpinv_pre_format_invoice_number', null, $number, $type); |
|
2091 | + if (null !== $check) { |
|
2092 | 2092 | return $check; |
2093 | 2093 | } |
2094 | 2094 | |
2095 | - if ( !empty( $number ) && !is_numeric( $number ) ) { |
|
2095 | + if (!empty($number) && !is_numeric($number)) { |
|
2096 | 2096 | return $number; |
2097 | 2097 | } |
2098 | 2098 | |
2099 | - $padd = wpinv_get_option( 'invoice_number_padd' ); |
|
2100 | - $prefix = wpinv_get_option( 'invoice_number_prefix' ); |
|
2101 | - $postfix = wpinv_get_option( 'invoice_number_postfix' ); |
|
2099 | + $padd = wpinv_get_option('invoice_number_padd'); |
|
2100 | + $prefix = wpinv_get_option('invoice_number_prefix'); |
|
2101 | + $postfix = wpinv_get_option('invoice_number_postfix'); |
|
2102 | 2102 | |
2103 | - $padd = absint( $padd ); |
|
2104 | - $formatted_number = absint( $number ); |
|
2103 | + $padd = absint($padd); |
|
2104 | + $formatted_number = absint($number); |
|
2105 | 2105 | |
2106 | - if ( $padd > 0 ) { |
|
2107 | - $formatted_number = zeroise( $formatted_number, $padd ); |
|
2106 | + if ($padd > 0) { |
|
2107 | + $formatted_number = zeroise($formatted_number, $padd); |
|
2108 | 2108 | } |
2109 | 2109 | |
2110 | 2110 | $formatted_number = $prefix . $formatted_number . $postfix; |
2111 | 2111 | |
2112 | - return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd ); |
|
2112 | + return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd); |
|
2113 | 2113 | } |
2114 | 2114 | |
2115 | -function wpinv_get_next_invoice_number( $type = '' ) { |
|
2116 | - $check = apply_filters( 'wpinv_get_pre_next_invoice_number', null, $type ); |
|
2117 | - if ( null !== $check ) { |
|
2115 | +function wpinv_get_next_invoice_number($type = '') { |
|
2116 | + $check = apply_filters('wpinv_get_pre_next_invoice_number', null, $type); |
|
2117 | + if (null !== $check) { |
|
2118 | 2118 | return $check; |
2119 | 2119 | } |
2120 | 2120 | |
2121 | - if ( !wpinv_sequential_number_active() ) { |
|
2121 | + if (!wpinv_sequential_number_active()) { |
|
2122 | 2122 | return false; |
2123 | 2123 | } |
2124 | 2124 | |
2125 | - $number = $last_number = get_option( 'wpinv_last_invoice_number', 0 ); |
|
2126 | - $start = wpinv_get_option( 'invoice_sequence_start', 1 ); |
|
2127 | - if ( !absint( $start ) > 0 ) { |
|
2125 | + $number = $last_number = get_option('wpinv_last_invoice_number', 0); |
|
2126 | + $start = wpinv_get_option('invoice_sequence_start', 1); |
|
2127 | + if (!absint($start) > 0) { |
|
2128 | 2128 | $start = 1; |
2129 | 2129 | } |
2130 | 2130 | $increment_number = true; |
2131 | 2131 | $save_number = false; |
2132 | 2132 | |
2133 | - if ( !empty( $number ) && !is_numeric( $number ) && $number == wpinv_format_invoice_number( $number ) ) { |
|
2134 | - $number = wpinv_clean_invoice_number( $number ); |
|
2133 | + if (!empty($number) && !is_numeric($number) && $number == wpinv_format_invoice_number($number)) { |
|
2134 | + $number = wpinv_clean_invoice_number($number); |
|
2135 | 2135 | } |
2136 | 2136 | |
2137 | - if ( empty( $number ) ) { |
|
2138 | - if ( !( $last_number === 0 || $last_number === '0' ) ) { |
|
2139 | - $last_invoice = wpinv_get_invoices( array( 'limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys( wpinv_get_invoice_statuses( true, true ) ) ) ); |
|
2137 | + if (empty($number)) { |
|
2138 | + if (!($last_number === 0 || $last_number === '0')) { |
|
2139 | + $last_invoice = wpinv_get_invoices(array('limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys(wpinv_get_invoice_statuses(true, true)))); |
|
2140 | 2140 | |
2141 | - if ( !empty( $last_invoice[0] ) && $invoice_number = wpinv_get_invoice_number( $last_invoice[0] ) ) { |
|
2142 | - if ( is_numeric( $invoice_number ) ) { |
|
2141 | + if (!empty($last_invoice[0]) && $invoice_number = wpinv_get_invoice_number($last_invoice[0])) { |
|
2142 | + if (is_numeric($invoice_number)) { |
|
2143 | 2143 | $number = $invoice_number; |
2144 | 2144 | } else { |
2145 | - $number = wpinv_clean_invoice_number( $invoice_number ); |
|
2145 | + $number = wpinv_clean_invoice_number($invoice_number); |
|
2146 | 2146 | } |
2147 | 2147 | } |
2148 | 2148 | |
2149 | - if ( empty( $number ) ) { |
|
2149 | + if (empty($number)) { |
|
2150 | 2150 | $increment_number = false; |
2151 | 2151 | $number = $start; |
2152 | - $save_number = ( $number - 1 ); |
|
2152 | + $save_number = ($number - 1); |
|
2153 | 2153 | } else { |
2154 | 2154 | $save_number = $number; |
2155 | 2155 | } |
2156 | 2156 | } |
2157 | 2157 | } |
2158 | 2158 | |
2159 | - if ( $start > $number ) { |
|
2159 | + if ($start > $number) { |
|
2160 | 2160 | $increment_number = false; |
2161 | 2161 | $number = $start; |
2162 | - $save_number = ( $number - 1 ); |
|
2162 | + $save_number = ($number - 1); |
|
2163 | 2163 | } |
2164 | 2164 | |
2165 | - if ( $save_number !== false ) { |
|
2166 | - update_option( 'wpinv_last_invoice_number', $save_number ); |
|
2165 | + if ($save_number !== false) { |
|
2166 | + update_option('wpinv_last_invoice_number', $save_number); |
|
2167 | 2167 | } |
2168 | 2168 | |
2169 | - $increment_number = apply_filters( 'wpinv_increment_payment_number', $increment_number, $number ); |
|
2169 | + $increment_number = apply_filters('wpinv_increment_payment_number', $increment_number, $number); |
|
2170 | 2170 | |
2171 | - if ( $increment_number ) { |
|
2171 | + if ($increment_number) { |
|
2172 | 2172 | $number++; |
2173 | 2173 | } |
2174 | 2174 | |
2175 | - return apply_filters( 'wpinv_get_next_invoice_number', $number ); |
|
2175 | + return apply_filters('wpinv_get_next_invoice_number', $number); |
|
2176 | 2176 | } |
2177 | 2177 | |
2178 | -function wpinv_clean_invoice_number( $number, $type = '' ) { |
|
2179 | - $check = apply_filters( 'wpinv_pre_clean_invoice_number', null, $number, $type ); |
|
2180 | - if ( null !== $check ) { |
|
2178 | +function wpinv_clean_invoice_number($number, $type = '') { |
|
2179 | + $check = apply_filters('wpinv_pre_clean_invoice_number', null, $number, $type); |
|
2180 | + if (null !== $check) { |
|
2181 | 2181 | return $check; |
2182 | 2182 | } |
2183 | 2183 | |
2184 | - $prefix = wpinv_get_option( 'invoice_number_prefix' ); |
|
2185 | - $postfix = wpinv_get_option( 'invoice_number_postfix' ); |
|
2184 | + $prefix = wpinv_get_option('invoice_number_prefix'); |
|
2185 | + $postfix = wpinv_get_option('invoice_number_postfix'); |
|
2186 | 2186 | |
2187 | - $number = preg_replace( '/' . $prefix . '/', '', $number, 1 ); |
|
2187 | + $number = preg_replace('/' . $prefix . '/', '', $number, 1); |
|
2188 | 2188 | |
2189 | - $length = strlen( $number ); |
|
2190 | - $postfix_pos = strrpos( $number, $postfix ); |
|
2189 | + $length = strlen($number); |
|
2190 | + $postfix_pos = strrpos($number, $postfix); |
|
2191 | 2191 | |
2192 | - if ( false !== $postfix_pos ) { |
|
2193 | - $number = substr_replace( $number, '', $postfix_pos, $length ); |
|
2192 | + if (false !== $postfix_pos) { |
|
2193 | + $number = substr_replace($number, '', $postfix_pos, $length); |
|
2194 | 2194 | } |
2195 | 2195 | |
2196 | - $number = intval( $number ); |
|
2196 | + $number = intval($number); |
|
2197 | 2197 | |
2198 | - return apply_filters( 'wpinv_clean_invoice_number', $number, $prefix, $postfix ); |
|
2198 | + return apply_filters('wpinv_clean_invoice_number', $number, $prefix, $postfix); |
|
2199 | 2199 | } |
2200 | 2200 | |
2201 | -function wpinv_save_number_post_saved( $post_ID, $post, $update ) { |
|
2201 | +function wpinv_save_number_post_saved($post_ID, $post, $update) { |
|
2202 | 2202 | global $wpdb; |
2203 | 2203 | |
2204 | - if ( !$update && !get_post_meta( $post_ID, '_wpinv_number', true ) ) { |
|
2205 | - wpinv_update_invoice_number( $post_ID, $post->post_status != 'auto-draft', $post->post_type ); |
|
2204 | + if (!$update && !get_post_meta($post_ID, '_wpinv_number', true)) { |
|
2205 | + wpinv_update_invoice_number($post_ID, $post->post_status != 'auto-draft', $post->post_type); |
|
2206 | 2206 | } |
2207 | 2207 | |
2208 | - if ( !$update ) { |
|
2209 | - $wpdb->update( $wpdb->posts, array( 'post_name' => wpinv_generate_post_name( $post_ID ) ), array( 'ID' => $post_ID ) ); |
|
2210 | - clean_post_cache( $post_ID ); |
|
2208 | + if (!$update) { |
|
2209 | + $wpdb->update($wpdb->posts, array('post_name' => wpinv_generate_post_name($post_ID)), array('ID' => $post_ID)); |
|
2210 | + clean_post_cache($post_ID); |
|
2211 | 2211 | } |
2212 | 2212 | } |
2213 | -add_action( 'save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3 ); |
|
2213 | +add_action('save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3); |
|
2214 | 2214 | |
2215 | -function wpinv_save_number_post_updated( $post_ID, $post_after, $post_before ) { |
|
2216 | - if ( !empty( $post_after->post_type ) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status ) { |
|
2217 | - wpinv_update_invoice_number( $post_ID, true, $post_after->post_type ); |
|
2215 | +function wpinv_save_number_post_updated($post_ID, $post_after, $post_before) { |
|
2216 | + if (!empty($post_after->post_type) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status) { |
|
2217 | + wpinv_update_invoice_number($post_ID, true, $post_after->post_type); |
|
2218 | 2218 | } |
2219 | 2219 | } |
2220 | -add_action( 'post_updated', 'wpinv_save_number_post_updated', 1, 3 ); |
|
2220 | +add_action('post_updated', 'wpinv_save_number_post_updated', 1, 3); |
|
2221 | 2221 | |
2222 | -function wpinv_update_invoice_number( $post_ID, $save_sequential = false, $type = '' ) { |
|
2222 | +function wpinv_update_invoice_number($post_ID, $save_sequential = false, $type = '') { |
|
2223 | 2223 | global $wpdb; |
2224 | 2224 | |
2225 | - $check = apply_filters( 'wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type ); |
|
2226 | - if ( null !== $check ) { |
|
2225 | + $check = apply_filters('wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type); |
|
2226 | + if (null !== $check) { |
|
2227 | 2227 | return $check; |
2228 | 2228 | } |
2229 | 2229 | |
2230 | - if ( wpinv_sequential_number_active() ) { |
|
2230 | + if (wpinv_sequential_number_active()) { |
|
2231 | 2231 | $number = wpinv_get_next_invoice_number(); |
2232 | 2232 | |
2233 | - if ( $save_sequential ) { |
|
2234 | - update_option( 'wpinv_last_invoice_number', $number ); |
|
2233 | + if ($save_sequential) { |
|
2234 | + update_option('wpinv_last_invoice_number', $number); |
|
2235 | 2235 | } |
2236 | 2236 | } else { |
2237 | 2237 | $number = $post_ID; |
2238 | 2238 | } |
2239 | 2239 | |
2240 | - $number = wpinv_format_invoice_number( $number ); |
|
2240 | + $number = wpinv_format_invoice_number($number); |
|
2241 | 2241 | |
2242 | - update_post_meta( $post_ID, '_wpinv_number', $number ); |
|
2242 | + update_post_meta($post_ID, '_wpinv_number', $number); |
|
2243 | 2243 | |
2244 | - $wpdb->update( $wpdb->posts, array( 'post_title' => $number ), array( 'ID' => $post_ID ) ); |
|
2244 | + $wpdb->update($wpdb->posts, array('post_title' => $number), array('ID' => $post_ID)); |
|
2245 | 2245 | |
2246 | - clean_post_cache( $post_ID ); |
|
2246 | + clean_post_cache($post_ID); |
|
2247 | 2247 | |
2248 | 2248 | return $number; |
2249 | 2249 | } |
2250 | 2250 | |
2251 | -function wpinv_post_name_prefix( $post_type = 'wpi_invoice' ) { |
|
2252 | - return apply_filters( 'wpinv_post_name_prefix', 'inv-', $post_type ); |
|
2251 | +function wpinv_post_name_prefix($post_type = 'wpi_invoice') { |
|
2252 | + return apply_filters('wpinv_post_name_prefix', 'inv-', $post_type); |
|
2253 | 2253 | } |
2254 | 2254 | |
2255 | -function wpinv_generate_post_name( $post_ID ) { |
|
2256 | - $prefix = wpinv_post_name_prefix( get_post_type( $post_ID ) ); |
|
2257 | - $post_name = sanitize_title( $prefix . $post_ID ); |
|
2255 | +function wpinv_generate_post_name($post_ID) { |
|
2256 | + $prefix = wpinv_post_name_prefix(get_post_type($post_ID)); |
|
2257 | + $post_name = sanitize_title($prefix . $post_ID); |
|
2258 | 2258 | |
2259 | - return apply_filters( 'wpinv_generate_post_name', $post_name, $post_ID, $prefix ); |
|
2259 | + return apply_filters('wpinv_generate_post_name', $post_name, $post_ID, $prefix); |
|
2260 | 2260 | } |
2261 | 2261 | |
2262 | -function wpinv_is_invoice_viewed( $invoice_id ) { |
|
2263 | - if ( empty( $invoice_id ) ) { |
|
2262 | +function wpinv_is_invoice_viewed($invoice_id) { |
|
2263 | + if (empty($invoice_id)) { |
|
2264 | 2264 | return false; |
2265 | 2265 | } |
2266 | 2266 | |
2267 | - $viewed_meta = get_post_meta( $invoice_id, '_wpinv_is_viewed', true ); |
|
2267 | + $viewed_meta = get_post_meta($invoice_id, '_wpinv_is_viewed', true); |
|
2268 | 2268 | |
2269 | - return apply_filters( 'wpinv_is_invoice_viewed', 1 === (int)$viewed_meta, $invoice_id ); |
|
2269 | + return apply_filters('wpinv_is_invoice_viewed', 1 === (int) $viewed_meta, $invoice_id); |
|
2270 | 2270 | } |
2271 | 2271 | |
2272 | 2272 | function wpinv_mark_invoice_viewed() { |
2273 | 2273 | |
2274 | - if ( isset( $_GET['invoice_key'] ) || is_singular( 'wpi_invoice' ) || is_singular( 'wpi_quote' ) ) { |
|
2275 | - $invoice_key = isset( $_GET['invoice_key'] ) ? urldecode($_GET['invoice_key']) : ''; |
|
2274 | + if (isset($_GET['invoice_key']) || is_singular('wpi_invoice') || is_singular('wpi_quote')) { |
|
2275 | + $invoice_key = isset($_GET['invoice_key']) ? urldecode($_GET['invoice_key']) : ''; |
|
2276 | 2276 | global $post; |
2277 | 2277 | |
2278 | - if(!empty($invoice_key)){ |
|
2278 | + if (!empty($invoice_key)) { |
|
2279 | 2279 | $invoice_id = wpinv_get_invoice_id_by_key($invoice_key); |
2280 | - } else if(!empty( $post ) && ($post->post_type == 'wpi_invoice' || $post->post_type == 'wpi_quote')) { |
|
2280 | + } else if (!empty($post) && ($post->post_type == 'wpi_invoice' || $post->post_type == 'wpi_quote')) { |
|
2281 | 2281 | $invoice_id = $post->ID; |
2282 | 2282 | } else { |
2283 | 2283 | return; |
@@ -2285,60 +2285,60 @@ discard block |
||
2285 | 2285 | |
2286 | 2286 | $invoice = new WPInv_Invoice($invoice_id); |
2287 | 2287 | |
2288 | - if(!$invoice_id){ |
|
2288 | + if (!$invoice_id) { |
|
2289 | 2289 | return; |
2290 | 2290 | } |
2291 | 2291 | |
2292 | - if ( is_user_logged_in() ) { |
|
2293 | - if ( (int)$invoice->get_user_id() === get_current_user_id() ) { |
|
2294 | - update_post_meta($invoice_id,'_wpinv_is_viewed', 1); |
|
2295 | - } else if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
2296 | - update_post_meta($invoice_id,'_wpinv_is_viewed', 1); |
|
2292 | + if (is_user_logged_in()) { |
|
2293 | + if ((int) $invoice->get_user_id() === get_current_user_id()) { |
|
2294 | + update_post_meta($invoice_id, '_wpinv_is_viewed', 1); |
|
2295 | + } else if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) { |
|
2296 | + update_post_meta($invoice_id, '_wpinv_is_viewed', 1); |
|
2297 | 2297 | } |
2298 | 2298 | } else { |
2299 | - if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
2300 | - update_post_meta($invoice_id,'_wpinv_is_viewed', 1); |
|
2299 | + if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) { |
|
2300 | + update_post_meta($invoice_id, '_wpinv_is_viewed', 1); |
|
2301 | 2301 | } |
2302 | 2302 | } |
2303 | 2303 | } |
2304 | 2304 | |
2305 | 2305 | } |
2306 | -add_action( 'template_redirect', 'wpinv_mark_invoice_viewed' ); |
|
2306 | +add_action('template_redirect', 'wpinv_mark_invoice_viewed'); |
|
2307 | 2307 | |
2308 | -function wpinv_get_subscription( $invoice, $by_parent = false ) { |
|
2309 | - if ( empty( $invoice ) ) { |
|
2308 | +function wpinv_get_subscription($invoice, $by_parent = false) { |
|
2309 | + if (empty($invoice)) { |
|
2310 | 2310 | return false; |
2311 | 2311 | } |
2312 | 2312 | |
2313 | - if ( ! is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
2314 | - $invoice = wpinv_get_invoice( $invoice ); |
|
2313 | + if (!is_object($invoice) && is_scalar($invoice)) { |
|
2314 | + $invoice = wpinv_get_invoice($invoice); |
|
2315 | 2315 | } |
2316 | 2316 | |
2317 | - if ( !( is_object( $invoice ) && ! empty( $invoice->ID ) && $invoice->is_recurring() ) ) { |
|
2317 | + if (!(is_object($invoice) && !empty($invoice->ID) && $invoice->is_recurring())) { |
|
2318 | 2318 | return false; |
2319 | 2319 | } |
2320 | 2320 | |
2321 | - $invoice_id = ! $by_parent && ! empty( $invoice->parent_invoice ) ? $invoice->parent_invoice : $invoice->ID; |
|
2321 | + $invoice_id = !$by_parent && !empty($invoice->parent_invoice) ? $invoice->parent_invoice : $invoice->ID; |
|
2322 | 2322 | |
2323 | 2323 | $subs_db = new WPInv_Subscriptions_DB; |
2324 | - $subs = $subs_db->get_subscriptions( array( 'parent_payment_id' => $invoice_id, 'number' => 1 ) ); |
|
2324 | + $subs = $subs_db->get_subscriptions(array('parent_payment_id' => $invoice_id, 'number' => 1)); |
|
2325 | 2325 | |
2326 | - if ( ! empty( $subs ) ) { |
|
2327 | - return reset( $subs ); |
|
2326 | + if (!empty($subs)) { |
|
2327 | + return reset($subs); |
|
2328 | 2328 | } |
2329 | 2329 | |
2330 | 2330 | return false; |
2331 | 2331 | } |
2332 | 2332 | |
2333 | -function wpinv_filter_posts_clauses( $clauses, $wp_query ) { |
|
2333 | +function wpinv_filter_posts_clauses($clauses, $wp_query) { |
|
2334 | 2334 | global $wpdb; |
2335 | 2335 | |
2336 | - if ( ! empty( $wp_query->query_vars['orderby'] ) && $wp_query->query_vars['orderby'] == 'invoice_date' ) { |
|
2337 | - if ( !empty( $clauses['join'] ) ) { |
|
2336 | + if (!empty($wp_query->query_vars['orderby']) && $wp_query->query_vars['orderby'] == 'invoice_date') { |
|
2337 | + if (!empty($clauses['join'])) { |
|
2338 | 2338 | $clauses['join'] .= " "; |
2339 | 2339 | } |
2340 | 2340 | |
2341 | - if ( !empty( $clauses['fields'] ) ) { |
|
2341 | + if (!empty($clauses['fields'])) { |
|
2342 | 2342 | $clauses['fields'] .= ", "; |
2343 | 2343 | } |
2344 | 2344 | |
@@ -2349,4 +2349,4 @@ discard block |
||
2349 | 2349 | |
2350 | 2350 | return $clauses; |
2351 | 2351 | } |
2352 | -add_filter( 'posts_clauses', 'wpinv_filter_posts_clauses', 10, 2 ); |
|
2353 | 2352 | \ No newline at end of file |
2353 | +add_filter('posts_clauses', 'wpinv_filter_posts_clauses', 10, 2); |
|
2354 | 2354 | \ No newline at end of file |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | */ |
9 | 9 | function wpinv_subscriptions_page() { |
10 | 10 | |
11 | - if ( ! empty( $_GET['id'] ) ) { |
|
11 | + if (!empty($_GET['id'])) { |
|
12 | 12 | |
13 | 13 | wpinv_recurring_subscription_details(); |
14 | 14 | |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | <div class="wrap"> |
20 | 20 | |
21 | 21 | <h1> |
22 | - <?php _e( 'Subscriptions', 'invoicing' ); ?> |
|
22 | + <?php _e('Subscriptions', 'invoicing'); ?> |
|
23 | 23 | </h1> |
24 | 24 | <?php |
25 | 25 | $subscribers_table = new WPInv_Subscription_Reports_Table(); |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | <input type="hidden" name="post_type" value="download" /> |
32 | 32 | <input type="hidden" name="page" value="wpinv-subscriptions" /> |
33 | 33 | <?php $subscribers_table->views(); ?> |
34 | - <?php $subscribers_table->search_box( __( 'Search', 'wpinvoicing' ), 'subscriptions' ); ?> |
|
34 | + <?php $subscribers_table->search_box(__('Search', 'wpinvoicing'), 'subscriptions'); ?> |
|
35 | 35 | <?php $subscribers_table->display(); ?> |
36 | 36 | |
37 | 37 | </form> |
@@ -49,34 +49,34 @@ discard block |
||
49 | 49 | |
50 | 50 | $render = true; |
51 | 51 | |
52 | - if ( ! current_user_can( 'manage_invoicing' ) ) { |
|
53 | - die( __( 'You are not permitted to view this data.', 'invoicing' ) ); |
|
52 | + if (!current_user_can('manage_invoicing')) { |
|
53 | + die(__('You are not permitted to view this data.', 'invoicing')); |
|
54 | 54 | } |
55 | 55 | |
56 | - if ( ! isset( $_GET['id'] ) || ! is_numeric( $_GET['id'] ) ) { |
|
57 | - die( __( 'Invalid subscription ID Provided.', 'invoicing' ) ); |
|
56 | + if (!isset($_GET['id']) || !is_numeric($_GET['id'])) { |
|
57 | + die(__('Invalid subscription ID Provided.', 'invoicing')); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | $sub_id = (int) $_GET['id']; |
61 | - $sub = new WPInv_Subscription( $sub_id ); |
|
61 | + $sub = new WPInv_Subscription($sub_id); |
|
62 | 62 | |
63 | - if ( empty( $sub ) ) { |
|
64 | - die( __( 'Invalid subscription ID Provided.', 'invoicing' ) ); |
|
63 | + if (empty($sub)) { |
|
64 | + die(__('Invalid subscription ID Provided.', 'invoicing')); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | ?> |
68 | 68 | <div class="wrap"> |
69 | - <h2><?php _e( 'Subscription Details', 'invoicing' ); ?></h2> |
|
69 | + <h2><?php _e('Subscription Details', 'invoicing'); ?></h2> |
|
70 | 70 | |
71 | - <?php if ( $sub ) : ?> |
|
71 | + <?php if ($sub) : ?> |
|
72 | 72 | |
73 | 73 | <div id="wpinv-item-card-wrapper"> |
74 | 74 | |
75 | - <?php do_action( 'wpinv_subscription_card_top', $sub ); ?> |
|
75 | + <?php do_action('wpinv_subscription_card_top', $sub); ?> |
|
76 | 76 | |
77 | 77 | <div class="info-wrapper item-section"> |
78 | 78 | |
79 | - <form id="edit-item-info" method="post" action="<?php echo admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $sub->id ); ?>"> |
|
79 | + <form id="edit-item-info" method="post" action="<?php echo admin_url('admin.php?page=wpinv-subscriptions&id=' . $sub->id); ?>"> |
|
80 | 80 | |
81 | 81 | <div class="item-info"> |
82 | 82 | |
@@ -84,124 +84,124 @@ discard block |
||
84 | 84 | <tbody> |
85 | 85 | <tr> |
86 | 86 | <td class="row-title"> |
87 | - <label for="tablecell"><?php _e( 'Billing Cycle:', 'invoicing' ); ?></label> |
|
87 | + <label for="tablecell"><?php _e('Billing Cycle:', 'invoicing'); ?></label> |
|
88 | 88 | </td> |
89 | 89 | <td> |
90 | 90 | <?php |
91 | - $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $sub->period, $sub->frequency ); |
|
92 | - $billing = wpinv_price( wpinv_format_amount( $sub->recurring_amount ), wpinv_get_invoice_currency_code( $sub->parent_payment_id ) ) . ' / ' . $frequency; |
|
93 | - $initial = wpinv_price( wpinv_format_amount( $sub->initial_amount ), wpinv_get_invoice_currency_code( $sub->parent_payment_id ) ); |
|
94 | - printf( _x( '%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing' ), $initial, $billing ); |
|
91 | + $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($sub->period, $sub->frequency); |
|
92 | + $billing = wpinv_price(wpinv_format_amount($sub->recurring_amount), wpinv_get_invoice_currency_code($sub->parent_payment_id)) . ' / ' . $frequency; |
|
93 | + $initial = wpinv_price(wpinv_format_amount($sub->initial_amount), wpinv_get_invoice_currency_code($sub->parent_payment_id)); |
|
94 | + printf(_x('%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing'), $initial, $billing); |
|
95 | 95 | ?> |
96 | 96 | </td> |
97 | 97 | </tr> |
98 | 98 | <tr> |
99 | 99 | <td class="row-title"> |
100 | - <label for="tablecell"><?php _e( 'Times Billed:', 'invoicing' ); ?></label> |
|
100 | + <label for="tablecell"><?php _e('Times Billed:', 'invoicing'); ?></label> |
|
101 | 101 | </td> |
102 | - <td><?php echo $sub->get_times_billed() . ' / ' . ( ( $sub->bill_times == 0 ) ? 'Until Cancelled' : $sub->bill_times ); ?></td> |
|
102 | + <td><?php echo $sub->get_times_billed() . ' / ' . (($sub->bill_times == 0) ? 'Until Cancelled' : $sub->bill_times); ?></td> |
|
103 | 103 | </tr> |
104 | 104 | <tr> |
105 | 105 | <td class="row-title"> |
106 | - <label for="tablecell"><?php _e( 'Customer:', 'invoicing' ); ?></label> |
|
106 | + <label for="tablecell"><?php _e('Customer:', 'invoicing'); ?></label> |
|
107 | 107 | </td> |
108 | 108 | <td> |
109 | - <?php $subscriber = get_userdata( $sub->customer_id ); ?> |
|
110 | - <a href="<?php echo esc_url( get_edit_user_link( $sub->customer_id ) ); ?>" target="_blank"><?php echo ! empty( $subscriber->display_name ) ? $subscriber->display_name : $subscriber->user_email; ?></a> |
|
109 | + <?php $subscriber = get_userdata($sub->customer_id); ?> |
|
110 | + <a href="<?php echo esc_url(get_edit_user_link($sub->customer_id)); ?>" target="_blank"><?php echo !empty($subscriber->display_name) ? $subscriber->display_name : $subscriber->user_email; ?></a> |
|
111 | 111 | </td> |
112 | 112 | </tr> |
113 | 113 | <tr> |
114 | 114 | <td class="row-title"> |
115 | - <label for="tablecell"><?php _e( 'Initial Invoice:', 'invoicing' ); ?></label> |
|
115 | + <label for="tablecell"><?php _e('Initial Invoice:', 'invoicing'); ?></label> |
|
116 | 116 | </td> |
117 | 117 | <td> |
118 | - <a target="_blank" title="<?php _e( 'View invoice', 'invoicing' ); ?>" href="<?php echo esc_url( get_permalink( $sub->parent_payment_id ) ); ?>"><?php echo wpinv_get_invoice_number( $sub->parent_payment_id ); ?></a> <?php echo wp_sprintf( __( '( ID: %s )', 'invoicing' ), '<a title="' . esc_attr( __( 'View invoice details', 'invoicing' ) ) . '" href="' . get_edit_post_link( $sub->parent_payment_id ) . '" target="_blank">' . $sub->parent_payment_id . '</a>' ); ?></td> |
|
118 | + <a target="_blank" title="<?php _e('View invoice', 'invoicing'); ?>" href="<?php echo esc_url(get_permalink($sub->parent_payment_id)); ?>"><?php echo wpinv_get_invoice_number($sub->parent_payment_id); ?></a> <?php echo wp_sprintf(__('( ID: %s )', 'invoicing'), '<a title="' . esc_attr(__('View invoice details', 'invoicing')) . '" href="' . get_edit_post_link($sub->parent_payment_id) . '" target="_blank">' . $sub->parent_payment_id . '</a>'); ?></td> |
|
119 | 119 | </tr> |
120 | 120 | <tr> |
121 | 121 | <td class="row-title"> |
122 | - <label for="tablecell"><?php _e( 'Item:', 'invoicing' ); ?></label> |
|
122 | + <label for="tablecell"><?php _e('Item:', 'invoicing'); ?></label> |
|
123 | 123 | </td> |
124 | 124 | <td> |
125 | 125 | <?php |
126 | - echo wpinv_item_dropdown( array( |
|
126 | + echo wpinv_item_dropdown(array( |
|
127 | 127 | 'name' => 'product_id', |
128 | 128 | 'id' => 'wpinv_invoice_item', |
129 | 129 | 'with_packages' => false, |
130 | 130 | 'show_recurring' => true, |
131 | 131 | 'selected' => $sub->product_id, |
132 | 132 | 'class' => 'wpinv-sub-product-id wpi_select2', |
133 | - ) ); |
|
133 | + )); |
|
134 | 134 | |
135 | 135 | ?> |
136 | - <a href="<?php echo esc_url( add_query_arg( array( |
|
136 | + <a href="<?php echo esc_url(add_query_arg(array( |
|
137 | 137 | 'post' => $sub->product_id, |
138 | 138 | 'action' => 'edit' |
139 | - ), admin_url( 'post.php' ) ) ); ?>" target="_blank"><?php _e( 'View Item', 'invoicing' ) ; ?></a> |
|
139 | + ), admin_url('post.php'))); ?>" target="_blank"><?php _e('View Item', 'invoicing'); ?></a> |
|
140 | 140 | </td> |
141 | 141 | </tr> |
142 | 142 | <tr> |
143 | 143 | <td class="row-title"> |
144 | - <label for="tablecell"><?php _e( 'Payment Method:', 'invoicing' ); ?></label> |
|
144 | + <label for="tablecell"><?php _e('Payment Method:', 'invoicing'); ?></label> |
|
145 | 145 | </td> |
146 | - <td><?php echo wpinv_get_gateway_admin_label( wpinv_get_payment_gateway( $sub->parent_payment_id ) ); ?></td> |
|
146 | + <td><?php echo wpinv_get_gateway_admin_label(wpinv_get_payment_gateway($sub->parent_payment_id)); ?></td> |
|
147 | 147 | </tr> |
148 | 148 | <tr> |
149 | 149 | <td class="row-title"> |
150 | - <label for="tablecell"><?php _e( 'Profile ID:', 'invoicing' ); ?></label> |
|
150 | + <label for="tablecell"><?php _e('Profile ID:', 'invoicing'); ?></label> |
|
151 | 151 | </td> |
152 | 152 | <td> |
153 | 153 | <span class="wpinv-sub-profile-id"> |
154 | - <?php echo apply_filters( 'wpinv_subscription_profile_link_' . $sub->gateway, $sub->profile_id, $sub ); ?> |
|
154 | + <?php echo apply_filters('wpinv_subscription_profile_link_' . $sub->gateway, $sub->profile_id, $sub); ?> |
|
155 | 155 | </span> |
156 | - <input type="text" name="profile_id" class="hidden wpinv-sub-profile-id" value="<?php echo esc_attr( $sub->profile_id ); ?>" /> |
|
156 | + <input type="text" name="profile_id" class="hidden wpinv-sub-profile-id" value="<?php echo esc_attr($sub->profile_id); ?>" /> |
|
157 | 157 | <span> – </span> |
158 | - <a href="#" class="wpinv-edit-sub-profile-id"><?php _e( 'Edit', 'invoicing' ); ?></a> |
|
158 | + <a href="#" class="wpinv-edit-sub-profile-id"><?php _e('Edit', 'invoicing'); ?></a> |
|
159 | 159 | </td> |
160 | 160 | </tr> |
161 | 161 | <tr> |
162 | 162 | <td class="row-title"> |
163 | - <label for="tablecell"><?php _e( 'Transaction ID:', 'invoicing' ); ?></label> |
|
163 | + <label for="tablecell"><?php _e('Transaction ID:', 'invoicing'); ?></label> |
|
164 | 164 | </td> |
165 | 165 | <td> |
166 | - <span class="wpinv-sub-transaction-id"><?php echo apply_filters( 'wpinv_subscription_transaction_link_' . $sub->gateway, $sub->get_transaction_id(), $sub ); ?></span> |
|
167 | - <input type="text" name="transaction_id" class="hidden wpinv-sub-transaction-id" value="<?php echo esc_attr( $sub->get_transaction_id() ); ?>" /> |
|
166 | + <span class="wpinv-sub-transaction-id"><?php echo apply_filters('wpinv_subscription_transaction_link_' . $sub->gateway, $sub->get_transaction_id(), $sub); ?></span> |
|
167 | + <input type="text" name="transaction_id" class="hidden wpinv-sub-transaction-id" value="<?php echo esc_attr($sub->get_transaction_id()); ?>" /> |
|
168 | 168 | <span> – </span> |
169 | - <a href="#" class="wpinv-edit-sub-transaction-id"><?php _e( 'Edit', 'invoicing' ); ?></a> |
|
169 | + <a href="#" class="wpinv-edit-sub-transaction-id"><?php _e('Edit', 'invoicing'); ?></a> |
|
170 | 170 | </td> |
171 | 171 | </tr> |
172 | 172 | <tr> |
173 | 173 | <td class="row-title"> |
174 | - <label for="tablecell"><?php _e( 'Date Created:', 'invoicing' ); ?></label> |
|
174 | + <label for="tablecell"><?php _e('Date Created:', 'invoicing'); ?></label> |
|
175 | 175 | </td> |
176 | - <td><?php echo date_i18n( get_option( 'date_format' ), strtotime( $sub->created, current_time( 'timestamp' ) ) ); ?></td> |
|
176 | + <td><?php echo date_i18n(get_option('date_format'), strtotime($sub->created, current_time('timestamp'))); ?></td> |
|
177 | 177 | </tr> |
178 | 178 | <tr> |
179 | 179 | <td class="row-title"> |
180 | 180 | <label for="tablecell"> |
181 | - <?php if( 'trialling' == $sub->status ) : ?> |
|
182 | - <?php _e( 'Trialling Until:', 'invoicing' ); ?> |
|
181 | + <?php if ('trialling' == $sub->status) : ?> |
|
182 | + <?php _e('Trialling Until:', 'invoicing'); ?> |
|
183 | 183 | <?php else: ?> |
184 | - <?php _e( 'Expiration Date:', 'invoicing' ); ?> |
|
184 | + <?php _e('Expiration Date:', 'invoicing'); ?> |
|
185 | 185 | <?php endif; ?> |
186 | 186 | </label> |
187 | 187 | </td> |
188 | 188 | <td> |
189 | - <span class="wpinv-sub-expiration"><?php echo date_i18n( get_option( 'date_format' ), strtotime( $sub->expiration, current_time( 'timestamp' ) ) ); ?></span> |
|
189 | + <span class="wpinv-sub-expiration"><?php echo date_i18n(get_option('date_format'), strtotime($sub->expiration, current_time('timestamp'))); ?></span> |
|
190 | 190 | </td> |
191 | 191 | </tr> |
192 | 192 | <tr> |
193 | 193 | <td class="row-title"> |
194 | - <label for="tablecell"><?php _e( 'Subscription Status:', 'invoicing' ); ?></label> |
|
194 | + <label for="tablecell"><?php _e('Subscription Status:', 'invoicing'); ?></label> |
|
195 | 195 | </td> |
196 | 196 | <td> |
197 | 197 | <select name="status" class="wpi_select2"> |
198 | - <option value="pending"<?php selected( 'pending', $sub->status ); ?>><?php _e( 'Pending', 'invoicing' ); ?></option> |
|
199 | - <option value="active"<?php selected( 'active', $sub->status ); ?>><?php _e( 'Active', 'invoicing' ); ?></option> |
|
200 | - <option value="cancelled"<?php selected( 'cancelled', $sub->status ); ?>><?php _e( 'Cancelled', 'invoicing' ); ?></option> |
|
201 | - <option value="expired"<?php selected( 'expired', $sub->status ); ?>><?php _e( 'Expired', 'invoicing' ); ?></option> |
|
202 | - <option value="trialling"<?php selected( 'trialling', $sub->status ); ?>><?php _e( 'Trialling', 'invoicing' ); ?></option> |
|
203 | - <option value="failing"<?php selected( 'failing', $sub->status ); ?>><?php _e( 'Failing', 'invoicing' ); ?></option> |
|
204 | - <option value="completed"<?php selected( 'completed', $sub->status ); ?>><?php _e( 'Completed', 'invoicing' ); ?></option> |
|
198 | + <option value="pending"<?php selected('pending', $sub->status); ?>><?php _e('Pending', 'invoicing'); ?></option> |
|
199 | + <option value="active"<?php selected('active', $sub->status); ?>><?php _e('Active', 'invoicing'); ?></option> |
|
200 | + <option value="cancelled"<?php selected('cancelled', $sub->status); ?>><?php _e('Cancelled', 'invoicing'); ?></option> |
|
201 | + <option value="expired"<?php selected('expired', $sub->status); ?>><?php _e('Expired', 'invoicing'); ?></option> |
|
202 | + <option value="trialling"<?php selected('trialling', $sub->status); ?>><?php _e('Trialling', 'invoicing'); ?></option> |
|
203 | + <option value="failing"<?php selected('failing', $sub->status); ?>><?php _e('Failing', 'invoicing'); ?></option> |
|
204 | + <option value="completed"<?php selected('completed', $sub->status); ?>><?php _e('Completed', 'invoicing'); ?></option> |
|
205 | 205 | </select> |
206 | 206 | </td> |
207 | 207 | </tr> |
@@ -209,79 +209,79 @@ discard block |
||
209 | 209 | </table> |
210 | 210 | </div> |
211 | 211 | <div id="wpinv-sub-notices"> |
212 | - <div class="notice notice-info inline hidden" id="wpinv-sub-product-update-notice"><p><?php _e( 'Changing the product assigned will not automatically adjust any pricing.', 'invoicing' ); ?></p></div> |
|
213 | - <div class="notice notice-warning inline hidden" id="wpinv-sub-profile-id-update-notice"><p><?php _e( 'Changing the profile ID can result in renewals not being processed. Do this with caution.', 'invoicing' ); ?></p></div> |
|
212 | + <div class="notice notice-info inline hidden" id="wpinv-sub-product-update-notice"><p><?php _e('Changing the product assigned will not automatically adjust any pricing.', 'invoicing'); ?></p></div> |
|
213 | + <div class="notice notice-warning inline hidden" id="wpinv-sub-profile-id-update-notice"><p><?php _e('Changing the profile ID can result in renewals not being processed. Do this with caution.', 'invoicing'); ?></p></div> |
|
214 | 214 | </div> |
215 | 215 | <div id="item-edit-actions" class="edit-item" style="float:right; margin: 10px 0 0; display: block;"> |
216 | - <?php wp_nonce_field( 'wpinv-recurring-update', 'wpinv-recurring-update-nonce', false, true ); ?> |
|
217 | - <input type="submit" name="wpinv_update_subscription" id="wpinv_update_subscription" class="button button-primary" value="<?php _e( 'Update Subscription', 'invoicing' ); ?>"/> |
|
218 | - <input type="hidden" name="sub_id" value="<?php echo absint( $sub->id ); ?>" /> |
|
219 | - <?php if( $sub->can_cancel() ) : ?> |
|
220 | - <a class="button button-primary" href="<?php echo $sub->get_cancel_url(); ?>" ><?php _e( 'Cancel Subscription', 'invoicing' ); ?></a> |
|
216 | + <?php wp_nonce_field('wpinv-recurring-update', 'wpinv-recurring-update-nonce', false, true); ?> |
|
217 | + <input type="submit" name="wpinv_update_subscription" id="wpinv_update_subscription" class="button button-primary" value="<?php _e('Update Subscription', 'invoicing'); ?>"/> |
|
218 | + <input type="hidden" name="sub_id" value="<?php echo absint($sub->id); ?>" /> |
|
219 | + <?php if ($sub->can_cancel()) : ?> |
|
220 | + <a class="button button-primary" href="<?php echo $sub->get_cancel_url(); ?>" ><?php _e('Cancel Subscription', 'invoicing'); ?></a> |
|
221 | 221 | <?php endif; ?> |
222 | - <input type="submit" name="wpinv_delete_subscription" class="wpinv-delete-subscription button" value="<?php _e( 'Delete Subscription', 'invoicing' ); ?>"/> |
|
222 | + <input type="submit" name="wpinv_delete_subscription" class="wpinv-delete-subscription button" value="<?php _e('Delete Subscription', 'invoicing'); ?>"/> |
|
223 | 223 | </div> |
224 | 224 | |
225 | 225 | </form> |
226 | 226 | </div> |
227 | 227 | |
228 | - <?php do_action( 'wpinv_subscription_before_stats', $sub ); ?> |
|
228 | + <?php do_action('wpinv_subscription_before_stats', $sub); ?> |
|
229 | 229 | |
230 | - <?php do_action( 'wpinv_subscription_before_tables_wrapper', $sub ); ?> |
|
230 | + <?php do_action('wpinv_subscription_before_tables_wrapper', $sub); ?> |
|
231 | 231 | |
232 | 232 | <div id="item-tables-wrapper" class="item-section"> |
233 | 233 | |
234 | - <?php do_action( 'wpinv_subscription_before_tables', $sub ); ?> |
|
234 | + <?php do_action('wpinv_subscription_before_tables', $sub); ?> |
|
235 | 235 | |
236 | - <h3><?php _e( 'Renewal Payments:', 'invoicing' ); ?></h3> |
|
236 | + <h3><?php _e('Renewal Payments:', 'invoicing'); ?></h3> |
|
237 | 237 | <?php $payments = $sub->get_child_payments(); ?> |
238 | - <?php if ( 'manual' == $sub->gateway ) : ?> |
|
239 | - <p><strong><?php _e( 'Note:', 'invoicing' ); ?></strong> <?php _e( 'Subscriptions purchased with the Test Payment gateway will not renew automatically.', 'invoicing' ); ?></p> |
|
238 | + <?php if ('manual' == $sub->gateway) : ?> |
|
239 | + <p><strong><?php _e('Note:', 'invoicing'); ?></strong> <?php _e('Subscriptions purchased with the Test Payment gateway will not renew automatically.', 'invoicing'); ?></p> |
|
240 | 240 | <?php endif; ?> |
241 | 241 | <table class="wp-list-table widefat striped payments"> |
242 | 242 | <thead> |
243 | 243 | <tr> |
244 | - <th><?php _e( 'ID', 'invoicing' ); ?></th> |
|
245 | - <th><?php _e( 'Amount', 'invoicing' ); ?></th> |
|
246 | - <th><?php _e( 'Date', 'invoicing' ); ?></th> |
|
247 | - <th><?php _e( 'Status', 'invoicing' ); ?></th> |
|
248 | - <th><?php _e( 'Invoice', 'invoicing' ); ?></th> |
|
249 | - <th class="column-wpi_actions"><?php _e( 'Actions', 'invoicing' ); ?></th> |
|
244 | + <th><?php _e('ID', 'invoicing'); ?></th> |
|
245 | + <th><?php _e('Amount', 'invoicing'); ?></th> |
|
246 | + <th><?php _e('Date', 'invoicing'); ?></th> |
|
247 | + <th><?php _e('Status', 'invoicing'); ?></th> |
|
248 | + <th><?php _e('Invoice', 'invoicing'); ?></th> |
|
249 | + <th class="column-wpi_actions"><?php _e('Actions', 'invoicing'); ?></th> |
|
250 | 250 | </tr> |
251 | 251 | </thead> |
252 | 252 | <tbody> |
253 | - <?php if ( ! empty( $payments ) ) : ?> |
|
254 | - <?php foreach ( $payments as $payment ) : $invoice = wpinv_get_invoice( $payment->ID ); if ( empty( $invoice->ID ) ) continue; ?> |
|
253 | + <?php if (!empty($payments)) : ?> |
|
254 | + <?php foreach ($payments as $payment) : $invoice = wpinv_get_invoice($payment->ID); if (empty($invoice->ID)) continue; ?> |
|
255 | 255 | <tr> |
256 | 256 | <td><?php echo $payment->ID; ?></td> |
257 | - <td><?php echo $invoice->get_total( true ); ?></td> |
|
257 | + <td><?php echo $invoice->get_total(true); ?></td> |
|
258 | 258 | <td><?php echo $invoice->get_invoice_date(); ?></td> |
259 | - <td><?php echo $invoice->get_status( true ); ?></td> |
|
259 | + <td><?php echo $invoice->get_status(true); ?></td> |
|
260 | 260 | <td> |
261 | - <a target="_blank" title="<?php _e( 'View invoice', 'invoicing' ); ?>" href="<?php echo esc_url( get_permalink( $payment->ID ) ); ?>"><?php echo $invoice->get_number(); ?></a> |
|
262 | - <?php do_action( 'wpinv_subscription_payments_actions', $sub, $payment ); ?> |
|
261 | + <a target="_blank" title="<?php _e('View invoice', 'invoicing'); ?>" href="<?php echo esc_url(get_permalink($payment->ID)); ?>"><?php echo $invoice->get_number(); ?></a> |
|
262 | + <?php do_action('wpinv_subscription_payments_actions', $sub, $payment); ?> |
|
263 | 263 | </td> |
264 | 264 | <td class="column-wpi_actions"> |
265 | - <a title="<?php echo esc_attr( wp_sprintf( __( 'View details for invoice: %s', 'invoicing' ), $invoice->get_number() ) ); ?>" href="<?php echo get_edit_post_link( $payment->ID ); ?>"><?php _e( 'View Details', 'invoicing' ); ?> |
|
265 | + <a title="<?php echo esc_attr(wp_sprintf(__('View details for invoice: %s', 'invoicing'), $invoice->get_number())); ?>" href="<?php echo get_edit_post_link($payment->ID); ?>"><?php _e('View Details', 'invoicing'); ?> |
|
266 | 266 | </a> |
267 | - <?php do_action( 'wpinv_subscription_payments_actions', $sub, $payment ); ?> |
|
267 | + <?php do_action('wpinv_subscription_payments_actions', $sub, $payment); ?> |
|
268 | 268 | </td> |
269 | 269 | </tr> |
270 | 270 | <?php endforeach; ?> |
271 | 271 | <?php else: ?> |
272 | 272 | <tr> |
273 | - <td colspan="5"><?php _e( 'No Invoices Found.', 'invoicing' ); ?></td> |
|
273 | + <td colspan="5"><?php _e('No Invoices Found.', 'invoicing'); ?></td> |
|
274 | 274 | </tr> |
275 | 275 | <?php endif; ?> |
276 | 276 | </tbody> |
277 | 277 | <tfoot></tfoot> |
278 | 278 | </table> |
279 | 279 | |
280 | - <?php do_action( 'wpinv_subscription_after_tables', $sub ); ?> |
|
280 | + <?php do_action('wpinv_subscription_after_tables', $sub); ?> |
|
281 | 281 | |
282 | 282 | </div> |
283 | 283 | |
284 | - <?php do_action( 'wpinv_subscription_card_bottom', $sub ); ?> |
|
284 | + <?php do_action('wpinv_subscription_card_bottom', $sub); ?> |
|
285 | 285 | </div> |
286 | 286 | |
287 | 287 | <?php endif; ?> |
@@ -299,36 +299,36 @@ discard block |
||
299 | 299 | */ |
300 | 300 | function wpinv_recurring_process_subscription_update() { |
301 | 301 | |
302 | - if( empty( $_POST['sub_id'] ) ) { |
|
302 | + if (empty($_POST['sub_id'])) { |
|
303 | 303 | return; |
304 | 304 | } |
305 | 305 | |
306 | - if( empty( $_POST['wpinv_update_subscription'] ) ) { |
|
306 | + if (empty($_POST['wpinv_update_subscription'])) { |
|
307 | 307 | return; |
308 | 308 | } |
309 | 309 | |
310 | - if( ! current_user_can( 'manage_invoicing') ) { |
|
310 | + if (!current_user_can('manage_invoicing')) { |
|
311 | 311 | return; |
312 | 312 | } |
313 | 313 | |
314 | - if( ! wp_verify_nonce( $_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update' ) ) { |
|
315 | - wp_die( __( 'Nonce verification failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
314 | + if (!wp_verify_nonce($_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update')) { |
|
315 | + wp_die(__('Nonce verification failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
316 | 316 | } |
317 | 317 | |
318 | - $profile_id = sanitize_text_field( $_POST['profile_id'] ); |
|
319 | - $transaction_id = sanitize_text_field( $_POST['transaction_id'] ); |
|
320 | - $product_id = absint( $_POST['product_id'] ); |
|
321 | - $subscription = new WPInv_Subscription( absint( $_POST['sub_id'] ) ); |
|
322 | - $subscription->update( array( |
|
323 | - 'status' => sanitize_text_field( $_POST['status'] ), |
|
318 | + $profile_id = sanitize_text_field($_POST['profile_id']); |
|
319 | + $transaction_id = sanitize_text_field($_POST['transaction_id']); |
|
320 | + $product_id = absint($_POST['product_id']); |
|
321 | + $subscription = new WPInv_Subscription(absint($_POST['sub_id'])); |
|
322 | + $subscription->update(array( |
|
323 | + 'status' => sanitize_text_field($_POST['status']), |
|
324 | 324 | 'profile_id' => $profile_id, |
325 | 325 | 'product_id' => $product_id, |
326 | 326 | 'transaction_id' => $transaction_id, |
327 | - ) ); |
|
327 | + )); |
|
328 | 328 | |
329 | - $status = sanitize_text_field( $_POST['status'] ); |
|
329 | + $status = sanitize_text_field($_POST['status']); |
|
330 | 330 | |
331 | - switch( $status ) { |
|
331 | + switch ($status) { |
|
332 | 332 | |
333 | 333 | case 'cancelled' : |
334 | 334 | |
@@ -347,11 +347,11 @@ discard block |
||
347 | 347 | |
348 | 348 | } |
349 | 349 | |
350 | - wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=updated&id=' . $subscription->id ) ); |
|
350 | + wp_redirect(admin_url('admin.php?page=wpinv-subscriptions&wpinv-message=updated&id=' . $subscription->id)); |
|
351 | 351 | exit; |
352 | 352 | |
353 | 353 | } |
354 | -add_action( 'admin_init', 'wpinv_recurring_process_subscription_update', 1 ); |
|
354 | +add_action('admin_init', 'wpinv_recurring_process_subscription_update', 1); |
|
355 | 355 | |
356 | 356 | /** |
357 | 357 | * Handles subscription deletion |
@@ -362,30 +362,30 @@ discard block |
||
362 | 362 | */ |
363 | 363 | function wpinv_recurring_process_subscription_deletion() { |
364 | 364 | |
365 | - if( empty( $_POST['sub_id'] ) ) { |
|
365 | + if (empty($_POST['sub_id'])) { |
|
366 | 366 | return; |
367 | 367 | } |
368 | 368 | |
369 | - if( empty( $_POST['wpinv_delete_subscription'] ) ) { |
|
369 | + if (empty($_POST['wpinv_delete_subscription'])) { |
|
370 | 370 | return; |
371 | 371 | } |
372 | 372 | |
373 | - if( ! current_user_can( 'manage_invoicing') ) { |
|
373 | + if (!current_user_can('manage_invoicing')) { |
|
374 | 374 | return; |
375 | 375 | } |
376 | 376 | |
377 | - if( ! wp_verify_nonce( $_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update' ) ) { |
|
378 | - wp_die( __( 'Nonce verification failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
377 | + if (!wp_verify_nonce($_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update')) { |
|
378 | + wp_die(__('Nonce verification failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
379 | 379 | } |
380 | 380 | |
381 | - $subscription = new WPInv_Subscription( absint( $_POST['sub_id'] ) ); |
|
381 | + $subscription = new WPInv_Subscription(absint($_POST['sub_id'])); |
|
382 | 382 | |
383 | - delete_post_meta( $subscription->parent_payment_id, '_wpinv_subscription_payment' ); |
|
383 | + delete_post_meta($subscription->parent_payment_id, '_wpinv_subscription_payment'); |
|
384 | 384 | |
385 | 385 | $subscription->delete(); |
386 | 386 | |
387 | - wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=deleted' ) ); |
|
387 | + wp_redirect(admin_url('admin.php?page=wpinv-subscriptions&wpinv-message=deleted')); |
|
388 | 388 | exit; |
389 | 389 | |
390 | 390 | } |
391 | -add_action( 'admin_init', 'wpinv_recurring_process_subscription_deletion', 2 ); |
|
391 | +add_action('admin_init', 'wpinv_recurring_process_subscription_deletion', 2); |
@@ -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 | -add_filter( 'manage_wpi_discount_posts_columns', 'wpinv_discount_columns' ); |
|
8 | -function wpinv_discount_columns( $existing_columns ) { |
|
7 | +add_filter('manage_wpi_discount_posts_columns', 'wpinv_discount_columns'); |
|
8 | +function wpinv_discount_columns($existing_columns) { |
|
9 | 9 | $columns = array(); |
10 | 10 | $columns['cb'] = $existing_columns['cb']; |
11 | - $columns['name'] = __( 'Name', 'invoicing' ); |
|
12 | - $columns['code'] = __( 'Code', 'invoicing' ); |
|
13 | - $columns['amount'] = __( 'Amount', 'invoicing' ); |
|
14 | - $columns['usage'] = __( 'Usage / Limit', 'invoicing' ); |
|
15 | - $columns['start_date'] = __( 'Start Date', 'invoicing' ); |
|
16 | - $columns['expiry_date'] = __( 'Expiry Date', 'invoicing' ); |
|
17 | - $columns['status'] = __( 'Status', 'invoicing' ); |
|
11 | + $columns['name'] = __('Name', 'invoicing'); |
|
12 | + $columns['code'] = __('Code', 'invoicing'); |
|
13 | + $columns['amount'] = __('Amount', 'invoicing'); |
|
14 | + $columns['usage'] = __('Usage / Limit', 'invoicing'); |
|
15 | + $columns['start_date'] = __('Start Date', 'invoicing'); |
|
16 | + $columns['expiry_date'] = __('Expiry Date', 'invoicing'); |
|
17 | + $columns['status'] = __('Status', 'invoicing'); |
|
18 | 18 | |
19 | 19 | return $columns; |
20 | 20 | } |
21 | 21 | |
22 | -add_action( 'manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column' ); |
|
23 | -function wpinv_discount_custom_column( $column ) { |
|
22 | +add_action('manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column'); |
|
23 | +function wpinv_discount_custom_column($column) { |
|
24 | 24 | global $post; |
25 | 25 | |
26 | 26 | $discount = $post; |
27 | 27 | |
28 | - switch ( $column ) { |
|
28 | + switch ($column) { |
|
29 | 29 | case 'name' : |
30 | - echo get_the_title( $discount->ID ); |
|
30 | + echo get_the_title($discount->ID); |
|
31 | 31 | break; |
32 | 32 | case 'code' : |
33 | - echo wpinv_get_discount_code( $discount->ID ); |
|
33 | + echo wpinv_get_discount_code($discount->ID); |
|
34 | 34 | break; |
35 | 35 | case 'amount' : |
36 | - echo wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) ); |
|
36 | + echo wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID)); |
|
37 | 37 | break; |
38 | 38 | case 'usage_limit' : |
39 | - echo wpinv_get_discount_uses( $discount->ID ); |
|
39 | + echo wpinv_get_discount_uses($discount->ID); |
|
40 | 40 | break; |
41 | 41 | case 'usage' : |
42 | - $usage = wpinv_get_discount_uses( $discount->ID ) . ' / '; |
|
43 | - if ( wpinv_get_discount_max_uses( $discount->ID ) ) { |
|
44 | - $usage .= wpinv_get_discount_max_uses( $discount->ID ); |
|
42 | + $usage = wpinv_get_discount_uses($discount->ID) . ' / '; |
|
43 | + if (wpinv_get_discount_max_uses($discount->ID)) { |
|
44 | + $usage .= wpinv_get_discount_max_uses($discount->ID); |
|
45 | 45 | } else { |
46 | 46 | $usage .= ' ∞'; |
47 | 47 | } |
@@ -49,8 +49,8 @@ discard block |
||
49 | 49 | echo $usage; |
50 | 50 | break; |
51 | 51 | case 'start_date' : |
52 | - if ( $start_date = wpinv_get_discount_start_date( $discount->ID ) ) { |
|
53 | - $value = date_i18n( get_option( 'date_format' ) . ' @ ' . get_option( 'time_format' ), strtotime( $start_date ) ); |
|
52 | + if ($start_date = wpinv_get_discount_start_date($discount->ID)) { |
|
53 | + $value = date_i18n(get_option('date_format') . ' @ ' . get_option('time_format'), strtotime($start_date)); |
|
54 | 54 | } else { |
55 | 55 | $value = '-'; |
56 | 56 | } |
@@ -58,163 +58,163 @@ discard block |
||
58 | 58 | echo $value; |
59 | 59 | break; |
60 | 60 | case 'expiry_date' : |
61 | - if ( $expiration = wpinv_get_discount_expiration( $discount->ID ) ) { |
|
62 | - $value = date_i18n( get_option( 'date_format' ) . ' @ ' . get_option( 'time_format' ), strtotime( $expiration ) ); |
|
61 | + if ($expiration = wpinv_get_discount_expiration($discount->ID)) { |
|
62 | + $value = date_i18n(get_option('date_format') . ' @ ' . get_option('time_format'), strtotime($expiration)); |
|
63 | 63 | } else { |
64 | - $value = __( 'Never', 'invoicing' ); |
|
64 | + $value = __('Never', 'invoicing'); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | echo $value; |
68 | 68 | break; |
69 | 69 | break; |
70 | 70 | case 'description' : |
71 | - echo wp_kses_post( $post->post_excerpt ); |
|
71 | + echo wp_kses_post($post->post_excerpt); |
|
72 | 72 | break; |
73 | 73 | case 'status' : |
74 | - $status = wpinv_is_discount_expired( $discount->ID ) ? 'expired' : $discount->post_status; |
|
74 | + $status = wpinv_is_discount_expired($discount->ID) ? 'expired' : $discount->post_status; |
|
75 | 75 | |
76 | - echo wpinv_discount_status( $status ); |
|
76 | + echo wpinv_discount_status($status); |
|
77 | 77 | break; |
78 | 78 | } |
79 | 79 | } |
80 | 80 | |
81 | -add_filter( 'post_row_actions', 'wpinv_post_row_actions', 9999, 2 ); |
|
82 | -function wpinv_post_row_actions( $actions, $post ) { |
|
83 | - $post_type = !empty( $post->post_type ) ? $post->post_type : ''; |
|
81 | +add_filter('post_row_actions', 'wpinv_post_row_actions', 9999, 2); |
|
82 | +function wpinv_post_row_actions($actions, $post) { |
|
83 | + $post_type = !empty($post->post_type) ? $post->post_type : ''; |
|
84 | 84 | |
85 | - if ( $post_type == 'wpi_invoice' ) { |
|
85 | + if ($post_type == 'wpi_invoice') { |
|
86 | 86 | $actions = array(); |
87 | 87 | } |
88 | 88 | |
89 | - if ( $post_type == 'wpi_discount' ) { |
|
90 | - $actions = wpinv_discount_row_actions( $post, $actions ); |
|
89 | + if ($post_type == 'wpi_discount') { |
|
90 | + $actions = wpinv_discount_row_actions($post, $actions); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | return $actions; |
94 | 94 | } |
95 | 95 | |
96 | -function wpinv_discount_row_actions( $discount, $row_actions ) { |
|
97 | - $row_actions = array(); |
|
98 | - $edit_link = get_edit_post_link( $discount->ID ); |
|
99 | - $row_actions['edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'invoicing' ) . '</a>'; |
|
96 | +function wpinv_discount_row_actions($discount, $row_actions) { |
|
97 | + $row_actions = array(); |
|
98 | + $edit_link = get_edit_post_link($discount->ID); |
|
99 | + $row_actions['edit'] = '<a href="' . esc_url($edit_link) . '">' . __('Edit', 'invoicing') . '</a>'; |
|
100 | 100 | |
101 | - if( in_array( strtolower( $discount->post_status ), array( 'publish' ) ) ) { |
|
102 | - $row_actions['deactivate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'deactivate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Deactivate', 'invoicing' ) . '</a>'; |
|
103 | - } elseif( in_array( strtolower( $discount->post_status ), array( 'pending', 'draft' ) ) ) { |
|
104 | - $row_actions['activate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'activate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Activate', 'invoicing' ) . '</a>'; |
|
101 | + if (in_array(strtolower($discount->post_status), array('publish'))) { |
|
102 | + $row_actions['deactivate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'deactivate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Deactivate', 'invoicing') . '</a>'; |
|
103 | + } elseif (in_array(strtolower($discount->post_status), array('pending', 'draft'))) { |
|
104 | + $row_actions['activate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'activate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Activate', 'invoicing') . '</a>'; |
|
105 | 105 | } |
106 | 106 | |
107 | - if ( wpinv_get_discount_uses( $discount->ID ) > 0 ) { |
|
108 | - if ( isset( $row_actions['delete'] ) ) { |
|
109 | - unset( $row_actions['delete'] ); // Don't delete used discounts. |
|
107 | + if (wpinv_get_discount_uses($discount->ID) > 0) { |
|
108 | + if (isset($row_actions['delete'])) { |
|
109 | + unset($row_actions['delete']); // Don't delete used discounts. |
|
110 | 110 | } |
111 | 111 | } else { |
112 | - $row_actions['delete'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'delete_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Delete', 'invoicing' ) . '</a>'; |
|
112 | + $row_actions['delete'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'delete_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Delete', 'invoicing') . '</a>'; |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | |
116 | - $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount ); |
|
116 | + $row_actions = apply_filters('wpinv_discount_row_actions', $row_actions, $discount); |
|
117 | 117 | |
118 | 118 | return $row_actions; |
119 | 119 | } |
120 | 120 | |
121 | -add_filter( 'list_table_primary_column', 'wpinv_table_primary_column', 10, 2 ); |
|
122 | -function wpinv_table_primary_column( $default, $screen_id ) { |
|
123 | - if ( 'edit-wpi_invoice' === $screen_id ) { |
|
121 | +add_filter('list_table_primary_column', 'wpinv_table_primary_column', 10, 2); |
|
122 | +function wpinv_table_primary_column($default, $screen_id) { |
|
123 | + if ('edit-wpi_invoice' === $screen_id) { |
|
124 | 124 | return 'name'; |
125 | 125 | } |
126 | 126 | |
127 | 127 | return $default; |
128 | 128 | } |
129 | 129 | |
130 | -function wpinv_discount_bulk_actions( $actions, $display = false ) { |
|
131 | - if ( !$display ) { |
|
130 | +function wpinv_discount_bulk_actions($actions, $display = false) { |
|
131 | + if (!$display) { |
|
132 | 132 | return array(); |
133 | 133 | } |
134 | 134 | |
135 | 135 | $actions = array( |
136 | - 'activate' => __( 'Activate', 'invoicing' ), |
|
137 | - 'deactivate' => __( 'Deactivate', 'invoicing' ), |
|
138 | - 'delete' => __( 'Delete', 'invoicing' ), |
|
136 | + 'activate' => __('Activate', 'invoicing'), |
|
137 | + 'deactivate' => __('Deactivate', 'invoicing'), |
|
138 | + 'delete' => __('Delete', 'invoicing'), |
|
139 | 139 | ); |
140 | 140 | $two = ''; |
141 | 141 | $which = 'top'; |
142 | 142 | echo '</div><div class="alignleft actions bulkactions">'; |
143 | - echo '<label for="bulk-action-selector-' . esc_attr( $which ) . '" class="screen-reader-text">' . __( 'Select bulk action' ) . '</label>'; |
|
144 | - echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr( $which ) . "\">"; |
|
145 | - echo '<option value="-1">' . __( 'Bulk Actions' ) . "</option>"; |
|
143 | + echo '<label for="bulk-action-selector-' . esc_attr($which) . '" class="screen-reader-text">' . __('Select bulk action') . '</label>'; |
|
144 | + echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr($which) . "\">"; |
|
145 | + echo '<option value="-1">' . __('Bulk Actions') . "</option>"; |
|
146 | 146 | |
147 | - foreach ( $actions as $name => $title ) { |
|
147 | + foreach ($actions as $name => $title) { |
|
148 | 148 | $class = 'edit' === $name ? ' class="hide-if-no-js"' : ''; |
149 | 149 | |
150 | 150 | echo "" . '<option value="' . $name . '"' . $class . '>' . $title . "</option>"; |
151 | 151 | } |
152 | 152 | echo "</select>"; |
153 | 153 | |
154 | - submit_button( __( 'Apply' ), 'action', '', false, array( 'id' => "doaction$two" ) ); |
|
154 | + submit_button(__('Apply'), 'action', '', false, array('id' => "doaction$two")); |
|
155 | 155 | |
156 | 156 | echo '</div><div class="alignleft actions">'; |
157 | 157 | } |
158 | -add_filter( 'bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10 ); |
|
158 | +add_filter('bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10); |
|
159 | 159 | |
160 | -function wpinv_disable_months_dropdown( $disable, $post_type ) { |
|
161 | - if ( $post_type == 'wpi_discount' ) { |
|
160 | +function wpinv_disable_months_dropdown($disable, $post_type) { |
|
161 | + if ($post_type == 'wpi_discount') { |
|
162 | 162 | $disable = true; |
163 | 163 | } |
164 | 164 | |
165 | 165 | return $disable; |
166 | 166 | } |
167 | -add_filter( 'disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2 ); |
|
167 | +add_filter('disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2); |
|
168 | 168 | |
169 | 169 | function wpinv_restrict_manage_posts() { |
170 | 170 | global $typenow; |
171 | 171 | |
172 | - if( 'wpi_discount' == $typenow ) { |
|
172 | + if ('wpi_discount' == $typenow) { |
|
173 | 173 | wpinv_discount_filters(); |
174 | 174 | } |
175 | 175 | } |
176 | -add_action( 'restrict_manage_posts', 'wpinv_restrict_manage_posts', 10 ); |
|
176 | +add_action('restrict_manage_posts', 'wpinv_restrict_manage_posts', 10); |
|
177 | 177 | |
178 | 178 | function wpinv_discount_filters() { |
179 | - echo wpinv_discount_bulk_actions( array(), true ); |
|
179 | + echo wpinv_discount_bulk_actions(array(), true); |
|
180 | 180 | |
181 | 181 | ?> |
182 | 182 | <select name="discount_type" id="dropdown_wpinv_discount_type"> |
183 | - <option value=""><?php _e( 'Show all types', 'invoicing' ); ?></option> |
|
183 | + <option value=""><?php _e('Show all types', 'invoicing'); ?></option> |
|
184 | 184 | <?php |
185 | 185 | $types = wpinv_get_discount_types(); |
186 | 186 | |
187 | - foreach ( $types as $name => $type ) { |
|
188 | - echo '<option value="' . esc_attr( $name ) . '"'; |
|
187 | + foreach ($types as $name => $type) { |
|
188 | + echo '<option value="' . esc_attr($name) . '"'; |
|
189 | 189 | |
190 | - if ( isset( $_GET['discount_type'] ) ) |
|
191 | - selected( $name, $_GET['discount_type'] ); |
|
190 | + if (isset($_GET['discount_type'])) |
|
191 | + selected($name, $_GET['discount_type']); |
|
192 | 192 | |
193 | - echo '>' . esc_html__( $type, 'invoicing' ) . '</option>'; |
|
193 | + echo '>' . esc_html__($type, 'invoicing') . '</option>'; |
|
194 | 194 | } |
195 | 195 | ?> |
196 | 196 | </select> |
197 | 197 | <?php |
198 | 198 | } |
199 | 199 | |
200 | -function wpinv_request( $vars ) { |
|
200 | +function wpinv_request($vars) { |
|
201 | 201 | global $typenow, $wp_query, $wp_post_statuses; |
202 | 202 | |
203 | - if ( 'wpi_invoice' === $typenow ) { |
|
204 | - if ( !isset( $vars['post_status'] ) ) { |
|
203 | + if ('wpi_invoice' === $typenow) { |
|
204 | + if (!isset($vars['post_status'])) { |
|
205 | 205 | $post_statuses = wpinv_get_invoice_statuses(); |
206 | 206 | |
207 | - foreach ( $post_statuses as $status => $value ) { |
|
208 | - if ( isset( $wp_post_statuses[ $status ] ) && false === $wp_post_statuses[ $status ]->show_in_admin_all_list ) { |
|
209 | - unset( $post_statuses[ $status ] ); |
|
207 | + foreach ($post_statuses as $status => $value) { |
|
208 | + if (isset($wp_post_statuses[$status]) && false === $wp_post_statuses[$status]->show_in_admin_all_list) { |
|
209 | + unset($post_statuses[$status]); |
|
210 | 210 | } |
211 | 211 | } |
212 | 212 | |
213 | - $vars['post_status'] = array_keys( $post_statuses ); |
|
213 | + $vars['post_status'] = array_keys($post_statuses); |
|
214 | 214 | } |
215 | 215 | |
216 | - if ( isset( $vars['orderby'] ) ) { |
|
217 | - if ( 'amount' == $vars['orderby'] ) { |
|
216 | + if (isset($vars['orderby'])) { |
|
217 | + if ('amount' == $vars['orderby']) { |
|
218 | 218 | $vars = array_merge( |
219 | 219 | $vars, |
220 | 220 | array( |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | 'orderby' => 'meta_value_num' |
223 | 223 | ) |
224 | 224 | ); |
225 | - } else if ( 'customer' == $vars['orderby'] ) { |
|
225 | + } else if ('customer' == $vars['orderby']) { |
|
226 | 226 | $vars = array_merge( |
227 | 227 | $vars, |
228 | 228 | array( |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | 'orderby' => 'meta_value' |
231 | 231 | ) |
232 | 232 | ); |
233 | - } else if ( 'number' == $vars['orderby'] ) { |
|
233 | + } else if ('number' == $vars['orderby']) { |
|
234 | 234 | $vars = array_merge( |
235 | 235 | $vars, |
236 | 236 | array( |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | 'orderby' => 'meta_value' |
239 | 239 | ) |
240 | 240 | ); |
241 | - } else if ( 'payment_date' == $vars['orderby'] ) { |
|
241 | + } else if ('payment_date' == $vars['orderby']) { |
|
242 | 242 | $vars = array_merge( |
243 | 243 | $vars, |
244 | 244 | array( |
@@ -248,9 +248,9 @@ discard block |
||
248 | 248 | ); |
249 | 249 | } |
250 | 250 | } |
251 | - } else if ( 'wpi_item' == $typenow ) { |
|
251 | + } else if ('wpi_item' == $typenow) { |
|
252 | 252 | // Check if 'orderby' is set to "price" |
253 | - if ( isset( $vars['orderby'] ) && 'price' == $vars['orderby'] ) { |
|
253 | + if (isset($vars['orderby']) && 'price' == $vars['orderby']) { |
|
254 | 254 | $vars = array_merge( |
255 | 255 | $vars, |
256 | 256 | array( |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | } |
262 | 262 | |
263 | 263 | // Check if "orderby" is set to "vat_rule" |
264 | - if ( isset( $vars['orderby'] ) && 'vat_rule' == $vars['orderby'] ) { |
|
264 | + if (isset($vars['orderby']) && 'vat_rule' == $vars['orderby']) { |
|
265 | 265 | $vars = array_merge( |
266 | 266 | $vars, |
267 | 267 | array( |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | } |
273 | 273 | |
274 | 274 | // Check if "orderby" is set to "vat_class" |
275 | - if ( isset( $vars['orderby'] ) && 'vat_class' == $vars['orderby'] ) { |
|
275 | + if (isset($vars['orderby']) && 'vat_class' == $vars['orderby']) { |
|
276 | 276 | $vars = array_merge( |
277 | 277 | $vars, |
278 | 278 | array( |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | } |
284 | 284 | |
285 | 285 | // Check if "orderby" is set to "type" |
286 | - if ( isset( $vars['orderby'] ) && 'type' == $vars['orderby'] ) { |
|
286 | + if (isset($vars['orderby']) && 'type' == $vars['orderby']) { |
|
287 | 287 | $vars = array_merge( |
288 | 288 | $vars, |
289 | 289 | array( |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | } |
295 | 295 | |
296 | 296 | // Check if "orderby" is set to "recurring" |
297 | - if ( isset( $vars['orderby'] ) && 'recurring' == $vars['orderby'] ) { |
|
297 | + if (isset($vars['orderby']) && 'recurring' == $vars['orderby']) { |
|
298 | 298 | $vars = array_merge( |
299 | 299 | $vars, |
300 | 300 | array( |
@@ -304,104 +304,104 @@ discard block |
||
304 | 304 | ); |
305 | 305 | } |
306 | 306 | |
307 | - $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array(); |
|
307 | + $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array(); |
|
308 | 308 | // Filter vat rule type |
309 | - if ( isset( $_GET['vat_rule'] ) && $_GET['vat_rule'] !== '' ) { |
|
309 | + if (isset($_GET['vat_rule']) && $_GET['vat_rule'] !== '') { |
|
310 | 310 | $meta_query[] = array( |
311 | 311 | 'key' => '_wpinv_vat_rule', |
312 | - 'value' => sanitize_text_field( $_GET['vat_rule'] ), |
|
312 | + 'value' => sanitize_text_field($_GET['vat_rule']), |
|
313 | 313 | 'compare' => '=' |
314 | 314 | ); |
315 | 315 | } |
316 | 316 | |
317 | 317 | // Filter vat class |
318 | - if ( isset( $_GET['vat_class'] ) && $_GET['vat_class'] !== '' ) { |
|
318 | + if (isset($_GET['vat_class']) && $_GET['vat_class'] !== '') { |
|
319 | 319 | $meta_query[] = array( |
320 | 320 | 'key' => '_wpinv_vat_class', |
321 | - 'value' => sanitize_text_field( $_GET['vat_class'] ), |
|
321 | + 'value' => sanitize_text_field($_GET['vat_class']), |
|
322 | 322 | 'compare' => '=' |
323 | 323 | ); |
324 | 324 | } |
325 | 325 | |
326 | 326 | // Filter item type |
327 | - if ( isset( $_GET['type'] ) && $_GET['type'] !== '' ) { |
|
327 | + if (isset($_GET['type']) && $_GET['type'] !== '') { |
|
328 | 328 | $meta_query[] = array( |
329 | 329 | 'key' => '_wpinv_type', |
330 | - 'value' => sanitize_text_field( $_GET['type'] ), |
|
330 | + 'value' => sanitize_text_field($_GET['type']), |
|
331 | 331 | 'compare' => '=' |
332 | 332 | ); |
333 | 333 | } |
334 | 334 | |
335 | - if ( !empty( $meta_query ) ) { |
|
335 | + if (!empty($meta_query)) { |
|
336 | 336 | $vars['meta_query'] = $meta_query; |
337 | 337 | } |
338 | - } else if ( 'wpi_discount' == $typenow ) { |
|
339 | - $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array(); |
|
338 | + } else if ('wpi_discount' == $typenow) { |
|
339 | + $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array(); |
|
340 | 340 | // Filter vat rule type |
341 | - if ( isset( $_GET['discount_type'] ) && $_GET['discount_type'] !== '' ) { |
|
341 | + if (isset($_GET['discount_type']) && $_GET['discount_type'] !== '') { |
|
342 | 342 | $meta_query[] = array( |
343 | 343 | 'key' => '_wpi_discount_type', |
344 | - 'value' => sanitize_text_field( $_GET['discount_type'] ), |
|
344 | + 'value' => sanitize_text_field($_GET['discount_type']), |
|
345 | 345 | 'compare' => '=' |
346 | 346 | ); |
347 | 347 | } |
348 | 348 | |
349 | - if ( !empty( $meta_query ) ) { |
|
349 | + if (!empty($meta_query)) { |
|
350 | 350 | $vars['meta_query'] = $meta_query; |
351 | 351 | } |
352 | 352 | } |
353 | 353 | |
354 | 354 | return $vars; |
355 | 355 | } |
356 | -add_filter( 'request', 'wpinv_request' ); |
|
356 | +add_filter('request', 'wpinv_request'); |
|
357 | 357 | |
358 | -function wpinv_item_type_class( $classes, $class, $post_id ) { |
|
358 | +function wpinv_item_type_class($classes, $class, $post_id) { |
|
359 | 359 | global $pagenow, $typenow; |
360 | 360 | |
361 | - if ( $pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type( $post_id ) == $typenow ) { |
|
362 | - if ( $type = get_post_meta( $post_id, '_wpinv_type', true ) ) { |
|
363 | - $classes[] = 'wpi-type-' . sanitize_html_class( $type ); |
|
361 | + if ($pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type($post_id) == $typenow) { |
|
362 | + if ($type = get_post_meta($post_id, '_wpinv_type', true)) { |
|
363 | + $classes[] = 'wpi-type-' . sanitize_html_class($type); |
|
364 | 364 | } |
365 | 365 | |
366 | - if ( !wpinv_item_is_editable( $post_id ) ) { |
|
366 | + if (!wpinv_item_is_editable($post_id)) { |
|
367 | 367 | $classes[] = 'wpi-editable-n'; |
368 | 368 | } |
369 | 369 | } |
370 | 370 | return $classes; |
371 | 371 | } |
372 | -add_filter( 'post_class', 'wpinv_item_type_class', 10, 3 ); |
|
372 | +add_filter('post_class', 'wpinv_item_type_class', 10, 3); |
|
373 | 373 | |
374 | 374 | function wpinv_check_quick_edit() { |
375 | 375 | global $pagenow, $current_screen, $wpinv_item_screen; |
376 | 376 | |
377 | - if ( $pagenow == 'edit.php' && !empty( $current_screen->post_type ) ) { |
|
378 | - if ( empty( $wpinv_item_screen ) ) { |
|
379 | - if ( $current_screen->post_type == 'wpi_item' ) { |
|
377 | + if ($pagenow == 'edit.php' && !empty($current_screen->post_type)) { |
|
378 | + if (empty($wpinv_item_screen)) { |
|
379 | + if ($current_screen->post_type == 'wpi_item') { |
|
380 | 380 | $wpinv_item_screen = 'y'; |
381 | 381 | } else { |
382 | 382 | $wpinv_item_screen = 'n'; |
383 | 383 | } |
384 | 384 | } |
385 | 385 | |
386 | - if ( $wpinv_item_screen == 'y' && $pagenow == 'edit.php' ) { |
|
387 | - add_filter( 'post_row_actions', 'wpinv_item_disable_quick_edit', 10, 2 ); |
|
388 | - add_filter( 'page_row_actions', 'wpinv_item_disable_quick_edit', 10, 2 ); |
|
386 | + if ($wpinv_item_screen == 'y' && $pagenow == 'edit.php') { |
|
387 | + add_filter('post_row_actions', 'wpinv_item_disable_quick_edit', 10, 2); |
|
388 | + add_filter('page_row_actions', 'wpinv_item_disable_quick_edit', 10, 2); |
|
389 | 389 | } |
390 | 390 | } |
391 | 391 | } |
392 | -add_action( 'admin_head', 'wpinv_check_quick_edit', 10 ); |
|
392 | +add_action('admin_head', 'wpinv_check_quick_edit', 10); |
|
393 | 393 | |
394 | -function wpinv_item_disable_quick_edit( $actions = array(), $row = null ) { |
|
395 | - if ( isset( $actions['inline hide-if-no-js'] ) ) { |
|
396 | - unset( $actions['inline hide-if-no-js'] ); |
|
394 | +function wpinv_item_disable_quick_edit($actions = array(), $row = null) { |
|
395 | + if (isset($actions['inline hide-if-no-js'])) { |
|
396 | + unset($actions['inline hide-if-no-js']); |
|
397 | 397 | } |
398 | 398 | |
399 | - if ( !empty( $row->post_type ) && $row->post_type == 'wpi_item' && !wpinv_item_is_editable( $row ) ) { |
|
400 | - if ( isset( $actions['trash'] ) ) { |
|
401 | - unset( $actions['trash'] ); |
|
399 | + if (!empty($row->post_type) && $row->post_type == 'wpi_item' && !wpinv_item_is_editable($row)) { |
|
400 | + if (isset($actions['trash'])) { |
|
401 | + unset($actions['trash']); |
|
402 | 402 | } |
403 | - if ( isset( $actions['delete'] ) ) { |
|
404 | - unset( $actions['delete'] ); |
|
403 | + if (isset($actions['delete'])) { |
|
404 | + unset($actions['delete']); |
|
405 | 405 | } |
406 | 406 | } |
407 | 407 | |
@@ -418,19 +418,19 @@ discard block |
||
418 | 418 | * @param int $post_parent (default: 0) Parent for the new page |
419 | 419 | * @return int page ID |
420 | 420 | */ |
421 | -function wpinv_create_page( $slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0 ) { |
|
421 | +function wpinv_create_page($slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0) { |
|
422 | 422 | global $wpdb; |
423 | 423 | |
424 | - $option_value = wpinv_get_option( $option ); |
|
424 | + $option_value = wpinv_get_option($option); |
|
425 | 425 | |
426 | - if ( $option_value > 0 && ( $page_object = get_post( $option_value ) ) ) { |
|
427 | - if ( 'page' === $page_object->post_type && ! in_array( $page_object->post_status, array( 'pending', 'trash', 'future', 'auto-draft' ) ) ) { |
|
426 | + if ($option_value > 0 && ($page_object = get_post($option_value))) { |
|
427 | + if ('page' === $page_object->post_type && !in_array($page_object->post_status, array('pending', 'trash', 'future', 'auto-draft'))) { |
|
428 | 428 | // Valid page is already in place |
429 | 429 | return $page_object->ID; |
430 | 430 | } |
431 | 431 | } |
432 | 432 | |
433 | - if(!empty($post_parent)){ |
|
433 | + if (!empty($post_parent)) { |
|
434 | 434 | $page = get_page_by_path($post_parent); |
435 | 435 | if ($page) { |
436 | 436 | $post_parent = $page->ID; |
@@ -439,40 +439,40 @@ discard block |
||
439 | 439 | } |
440 | 440 | } |
441 | 441 | |
442 | - if ( strlen( $page_content ) > 0 ) { |
|
442 | + if (strlen($page_content) > 0) { |
|
443 | 443 | // Search for an existing page with the specified page content (typically a shortcode) |
444 | - $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) ); |
|
444 | + $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%")); |
|
445 | 445 | } else { |
446 | 446 | // Search for an existing page with the specified page slug |
447 | - $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_name = %s LIMIT 1;", $slug ) ); |
|
447 | + $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_name = %s LIMIT 1;", $slug)); |
|
448 | 448 | } |
449 | 449 | |
450 | - $valid_page_found = apply_filters( 'wpinv_create_page_id', $valid_page_found, $slug, $page_content ); |
|
450 | + $valid_page_found = apply_filters('wpinv_create_page_id', $valid_page_found, $slug, $page_content); |
|
451 | 451 | |
452 | - if ( $valid_page_found ) { |
|
453 | - if ( $option ) { |
|
454 | - wpinv_update_option( $option, $valid_page_found ); |
|
452 | + if ($valid_page_found) { |
|
453 | + if ($option) { |
|
454 | + wpinv_update_option($option, $valid_page_found); |
|
455 | 455 | } |
456 | 456 | return $valid_page_found; |
457 | 457 | } |
458 | 458 | |
459 | 459 | // Search for a matching valid trashed page |
460 | - if ( strlen( $page_content ) > 0 ) { |
|
460 | + if (strlen($page_content) > 0) { |
|
461 | 461 | // Search for an existing page with the specified page content (typically a shortcode) |
462 | - $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) ); |
|
462 | + $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%")); |
|
463 | 463 | } else { |
464 | 464 | // Search for an existing page with the specified page slug |
465 | - $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug ) ); |
|
465 | + $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug)); |
|
466 | 466 | } |
467 | 467 | |
468 | - if ( $trashed_page_found ) { |
|
468 | + if ($trashed_page_found) { |
|
469 | 469 | $page_id = $trashed_page_found; |
470 | 470 | $page_data = array( |
471 | 471 | 'ID' => $page_id, |
472 | 472 | 'post_status' => 'publish', |
473 | 473 | 'post_parent' => $post_parent, |
474 | 474 | ); |
475 | - wp_update_post( $page_data ); |
|
475 | + wp_update_post($page_data); |
|
476 | 476 | } else { |
477 | 477 | $page_data = array( |
478 | 478 | 'post_status' => 'publish', |
@@ -484,11 +484,11 @@ discard block |
||
484 | 484 | 'post_parent' => $post_parent, |
485 | 485 | 'comment_status' => 'closed', |
486 | 486 | ); |
487 | - $page_id = wp_insert_post( $page_data ); |
|
487 | + $page_id = wp_insert_post($page_data); |
|
488 | 488 | } |
489 | 489 | |
490 | - if ( $option ) { |
|
491 | - wpinv_update_option( $option, (int)$page_id ); |
|
490 | + if ($option) { |
|
491 | + wpinv_update_option($option, (int) $page_id); |
|
492 | 492 | } |
493 | 493 | |
494 | 494 | return $page_id; |
@@ -1,67 +1,67 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // MUST have WordPress. |
3 | -if ( !defined( 'WPINC' ) ) { |
|
4 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
3 | +if (!defined('WPINC')) { |
|
4 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
5 | 5 | } |
6 | 6 | |
7 | -function wpinv_add_meta_boxes( $post_type, $post ) { |
|
7 | +function wpinv_add_meta_boxes($post_type, $post) { |
|
8 | 8 | global $wpi_mb_invoice; |
9 | - if ( $post_type == 'wpi_invoice' && !empty( $post->ID ) ) { |
|
10 | - $wpi_mb_invoice = wpinv_get_invoice( $post->ID ); |
|
9 | + if ($post_type == 'wpi_invoice' && !empty($post->ID)) { |
|
10 | + $wpi_mb_invoice = wpinv_get_invoice($post->ID); |
|
11 | 11 | } |
12 | 12 | |
13 | - if ( !empty( $wpi_mb_invoice ) && !$wpi_mb_invoice->has_status( array( 'draft', 'auto-draft' ) ) ) { |
|
14 | - add_meta_box( 'wpinv-mb-resend-invoice', __( 'Resend Invoice', 'invoicing' ), 'WPInv_Meta_Box_Details::resend_invoice', 'wpi_invoice', 'side', 'high' ); |
|
13 | + if (!empty($wpi_mb_invoice) && !$wpi_mb_invoice->has_status(array('draft', 'auto-draft'))) { |
|
14 | + add_meta_box('wpinv-mb-resend-invoice', __('Resend Invoice', 'invoicing'), 'WPInv_Meta_Box_Details::resend_invoice', 'wpi_invoice', 'side', 'high'); |
|
15 | 15 | } |
16 | 16 | |
17 | - if ( !empty( $wpi_mb_invoice ) && $wpi_mb_invoice->is_recurring() && $wpi_mb_invoice->is_parent() ) { |
|
18 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscriptions', 'invoicing' ), 'WPInv_Meta_Box_Details::subscriptions', 'wpi_invoice', 'side', 'high' ); |
|
17 | + if (!empty($wpi_mb_invoice) && $wpi_mb_invoice->is_recurring() && $wpi_mb_invoice->is_parent()) { |
|
18 | + add_meta_box('wpinv-mb-subscriptions', __('Subscriptions', 'invoicing'), 'WPInv_Meta_Box_Details::subscriptions', 'wpi_invoice', 'side', 'high'); |
|
19 | 19 | } |
20 | 20 | |
21 | - if ( wpinv_is_subscription_payment( $wpi_mb_invoice ) ) { |
|
22 | - add_meta_box( 'wpinv-mb-renewals', __( 'Renewal Payment', 'invoicing' ), 'WPInv_Meta_Box_Details::renewals', 'wpi_invoice', 'side', 'high' ); |
|
21 | + if (wpinv_is_subscription_payment($wpi_mb_invoice)) { |
|
22 | + add_meta_box('wpinv-mb-renewals', __('Renewal Payment', 'invoicing'), 'WPInv_Meta_Box_Details::renewals', 'wpi_invoice', 'side', 'high'); |
|
23 | 23 | } |
24 | 24 | |
25 | - add_meta_box( 'wpinv-details', __( 'Invoice Details', 'invoicing' ), 'WPInv_Meta_Box_Details::output', 'wpi_invoice', 'side', 'default' ); |
|
26 | - add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'WPInv_Meta_Box_Details::payment_meta', 'wpi_invoice', 'side', 'default' ); |
|
25 | + add_meta_box('wpinv-details', __('Invoice Details', 'invoicing'), 'WPInv_Meta_Box_Details::output', 'wpi_invoice', 'side', 'default'); |
|
26 | + add_meta_box('wpinv-payment-meta', __('Payment Meta', 'invoicing'), 'WPInv_Meta_Box_Details::payment_meta', 'wpi_invoice', 'side', 'default'); |
|
27 | 27 | |
28 | - add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'WPInv_Meta_Box_Billing_Details::output', 'wpi_invoice', 'normal', 'high' ); |
|
29 | - add_meta_box( 'wpinv-items', __( 'Invoice Items', 'invoicing' ), 'WPInv_Meta_Box_Items::output', 'wpi_invoice', 'normal', 'high' ); |
|
30 | - add_meta_box( 'wpinv-notes', __( 'Invoice Notes', 'invoicing' ), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high' ); |
|
28 | + add_meta_box('wpinv-address', __('Billing Details', 'invoicing'), 'WPInv_Meta_Box_Billing_Details::output', 'wpi_invoice', 'normal', 'high'); |
|
29 | + add_meta_box('wpinv-items', __('Invoice Items', 'invoicing'), 'WPInv_Meta_Box_Items::output', 'wpi_invoice', 'normal', 'high'); |
|
30 | + add_meta_box('wpinv-notes', __('Invoice Notes', 'invoicing'), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high'); |
|
31 | 31 | |
32 | 32 | remove_meta_box('wpseo_meta', 'wpi_invoice', 'normal'); |
33 | 33 | } |
34 | -add_action( 'add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2 ); |
|
34 | +add_action('add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2); |
|
35 | 35 | |
36 | -function wpinv_save_meta_boxes( $post_id, $post, $update = false ) { |
|
37 | - remove_action( 'save_post', __FUNCTION__ ); |
|
36 | +function wpinv_save_meta_boxes($post_id, $post, $update = false) { |
|
37 | + remove_action('save_post', __FUNCTION__); |
|
38 | 38 | |
39 | 39 | // $post_id and $post are required |
40 | - if ( empty( $post_id ) || empty( $post ) ) { |
|
40 | + if (empty($post_id) || empty($post)) { |
|
41 | 41 | return; |
42 | 42 | } |
43 | 43 | |
44 | - if ( !current_user_can( 'edit_post', $post_id ) || empty( $post->post_type ) ) { |
|
44 | + if (!current_user_can('edit_post', $post_id) || empty($post->post_type)) { |
|
45 | 45 | return; |
46 | 46 | } |
47 | 47 | |
48 | 48 | // Dont' save meta boxes for revisions or autosaves |
49 | - if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
49 | + if (defined('DOING_AUTOSAVE') || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) { |
|
50 | 50 | return; |
51 | 51 | } |
52 | 52 | |
53 | - if ( $post->post_type == 'wpi_invoice' or $post->post_type == 'wpi_quote' ) { |
|
54 | - if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
53 | + if ($post->post_type == 'wpi_invoice' or $post->post_type == 'wpi_quote') { |
|
54 | + if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) { |
|
55 | 55 | return; |
56 | 56 | } |
57 | 57 | |
58 | - if ( isset( $_POST['wpinv_save_invoice'] ) && wp_verify_nonce( $_POST['wpinv_save_invoice'], 'wpinv_save_invoice' ) ) { |
|
59 | - WPInv_Meta_Box_Items::save( $post_id, $_POST, $post ); |
|
58 | + if (isset($_POST['wpinv_save_invoice']) && wp_verify_nonce($_POST['wpinv_save_invoice'], 'wpinv_save_invoice')) { |
|
59 | + WPInv_Meta_Box_Items::save($post_id, $_POST, $post); |
|
60 | 60 | } |
61 | - } else if ( $post->post_type == 'wpi_item' ) { |
|
61 | + } else if ($post->post_type == 'wpi_item') { |
|
62 | 62 | // verify nonce |
63 | - if ( isset( $_POST['wpinv_vat_meta_box_nonce'] ) && wp_verify_nonce( $_POST['wpinv_vat_meta_box_nonce'], 'wpinv_item_meta_box_save' ) ) { |
|
64 | - $fields = array(); |
|
63 | + if (isset($_POST['wpinv_vat_meta_box_nonce']) && wp_verify_nonce($_POST['wpinv_vat_meta_box_nonce'], 'wpinv_item_meta_box_save')) { |
|
64 | + $fields = array(); |
|
65 | 65 | $fields['_wpinv_price'] = 'wpinv_item_price'; |
66 | 66 | $fields['_wpinv_vat_class'] = 'wpinv_vat_class'; |
67 | 67 | $fields['_wpinv_vat_rule'] = 'wpinv_vat_rules'; |
@@ -76,96 +76,96 @@ discard block |
||
76 | 76 | $fields['_wpinv_dynamic_pricing'] = 'wpinv_name_your_price'; |
77 | 77 | $fields['_minimum_price'] = 'wpinv_minimum_price'; |
78 | 78 | |
79 | - if ( !isset( $_POST['wpinv_is_recurring'] ) ) { |
|
79 | + if (!isset($_POST['wpinv_is_recurring'])) { |
|
80 | 80 | $_POST['wpinv_is_recurring'] = 0; |
81 | 81 | } |
82 | 82 | |
83 | - if ( !isset( $_POST['wpinv_name_your_price'] ) ) { |
|
83 | + if (!isset($_POST['wpinv_name_your_price'])) { |
|
84 | 84 | $_POST['wpinv_name_your_price'] = 0; |
85 | 85 | } |
86 | 86 | |
87 | - if ( !isset( $_POST['wpinv_free_trial'] ) || empty( $_POST['wpinv_is_recurring'] ) ) { |
|
87 | + if (!isset($_POST['wpinv_free_trial']) || empty($_POST['wpinv_is_recurring'])) { |
|
88 | 88 | $_POST['wpinv_free_trial'] = 0; |
89 | 89 | } |
90 | 90 | |
91 | - foreach ( $fields as $field => $name ) { |
|
92 | - if ( isset( $_POST[ $name ] ) ) { |
|
93 | - $allowed = apply_filters( 'wpinv_item_allowed_save_meta_value', true, $field, $post_id ); |
|
91 | + foreach ($fields as $field => $name) { |
|
92 | + if (isset($_POST[$name])) { |
|
93 | + $allowed = apply_filters('wpinv_item_allowed_save_meta_value', true, $field, $post_id); |
|
94 | 94 | |
95 | - if ( !$allowed ) { |
|
95 | + if (!$allowed) { |
|
96 | 96 | continue; |
97 | 97 | } |
98 | 98 | |
99 | - if ( $field == '_wpinv_price' ) { |
|
100 | - $value = wpinv_sanitize_amount( $_POST[ $name ] ); |
|
99 | + if ($field == '_wpinv_price') { |
|
100 | + $value = wpinv_sanitize_amount($_POST[$name]); |
|
101 | 101 | } else { |
102 | - $value = is_string( $_POST[ $name ] ) ? sanitize_text_field( $_POST[ $name ] ) : $_POST[ $name ]; |
|
102 | + $value = is_string($_POST[$name]) ? sanitize_text_field($_POST[$name]) : $_POST[$name]; |
|
103 | 103 | } |
104 | 104 | |
105 | - $value = apply_filters( 'wpinv_item_metabox_save_' . $field, $value, $name ); |
|
106 | - update_post_meta( $post_id, $field, $value ); |
|
105 | + $value = apply_filters('wpinv_item_metabox_save_' . $field, $value, $name); |
|
106 | + update_post_meta($post_id, $field, $value); |
|
107 | 107 | } |
108 | 108 | } |
109 | 109 | |
110 | - if ( !get_post_meta( $post_id, '_wpinv_custom_id', true ) ) { |
|
111 | - update_post_meta( $post_id, '_wpinv_custom_id', $post_id ); |
|
110 | + if (!get_post_meta($post_id, '_wpinv_custom_id', true)) { |
|
111 | + update_post_meta($post_id, '_wpinv_custom_id', $post_id); |
|
112 | 112 | } |
113 | 113 | } |
114 | 114 | } |
115 | 115 | } |
116 | -add_action( 'save_post', 'wpinv_save_meta_boxes', 10, 3 ); |
|
116 | +add_action('save_post', 'wpinv_save_meta_boxes', 10, 3); |
|
117 | 117 | |
118 | 118 | function wpinv_register_item_meta_boxes() { |
119 | 119 | global $wpinv_euvat; |
120 | 120 | |
121 | - add_meta_box( 'wpinv_field_prices', __( 'Item Price', 'invoicing' ), 'WPInv_Meta_Box_Items::prices', 'wpi_item', 'normal', 'high' ); |
|
121 | + add_meta_box('wpinv_field_prices', __('Item Price', 'invoicing'), 'WPInv_Meta_Box_Items::prices', 'wpi_item', 'normal', 'high'); |
|
122 | 122 | |
123 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
124 | - add_meta_box( 'wpinv_field_vat_rules', __( 'VAT rules type to use', 'invoicing' ), 'WPInv_Meta_Box_Items::vat_rules', 'wpi_item', 'normal', 'high' ); |
|
123 | + if ($wpinv_euvat->allow_vat_rules()) { |
|
124 | + add_meta_box('wpinv_field_vat_rules', __('VAT rules type to use', 'invoicing'), 'WPInv_Meta_Box_Items::vat_rules', 'wpi_item', 'normal', 'high'); |
|
125 | 125 | } |
126 | 126 | |
127 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
128 | - add_meta_box( 'wpinv_field_vat_classes', __( 'VAT rates class to use', 'invoicing' ), 'WPInv_Meta_Box_Items::vat_classes', 'wpi_item', 'normal', 'high' ); |
|
127 | + if ($wpinv_euvat->allow_vat_classes()) { |
|
128 | + add_meta_box('wpinv_field_vat_classes', __('VAT rates class to use', 'invoicing'), 'WPInv_Meta_Box_Items::vat_classes', 'wpi_item', 'normal', 'high'); |
|
129 | 129 | } |
130 | 130 | |
131 | - add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'WPInv_Meta_Box_Items::item_info', 'wpi_item', 'side', 'core' ); |
|
132 | - add_meta_box( 'wpinv_field_meta_values', __( 'Item Meta Values', 'invoicing' ), 'WPInv_Meta_Box_Items::meta_values', 'wpi_item', 'side', 'core' ); |
|
131 | + add_meta_box('wpinv_field_item_info', __('Item info', 'invoicing'), 'WPInv_Meta_Box_Items::item_info', 'wpi_item', 'side', 'core'); |
|
132 | + add_meta_box('wpinv_field_meta_values', __('Item Meta Values', 'invoicing'), 'WPInv_Meta_Box_Items::meta_values', 'wpi_item', 'side', 'core'); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | function wpinv_register_discount_meta_boxes() { |
136 | - add_meta_box( 'wpinv_discount_fields', __( 'Discount Details', 'invoicing' ), 'wpinv_discount_metabox_details', 'wpi_discount', 'normal', 'high' ); |
|
136 | + add_meta_box('wpinv_discount_fields', __('Discount Details', 'invoicing'), 'wpinv_discount_metabox_details', 'wpi_discount', 'normal', 'high'); |
|
137 | 137 | } |
138 | 138 | |
139 | -function wpinv_discount_metabox_details( $post ) { |
|
139 | +function wpinv_discount_metabox_details($post) { |
|
140 | 140 | $discount_id = $post->ID; |
141 | - $discount = wpinv_get_discount( $discount_id ); |
|
141 | + $discount = wpinv_get_discount($discount_id); |
|
142 | 142 | |
143 | - $type = wpinv_get_discount_type( $discount_id ); |
|
144 | - $item_reqs = wpinv_get_discount_item_reqs( $discount_id ); |
|
145 | - $excluded_items = wpinv_get_discount_excluded_items( $discount_id ); |
|
146 | - $min_total = wpinv_get_discount_min_total( $discount_id ); |
|
147 | - $max_total = wpinv_get_discount_max_total( $discount_id ); |
|
148 | - $max_uses = wpinv_get_discount_max_uses( $discount_id ); |
|
149 | - $single_use = wpinv_discount_is_single_use( $discount_id ); |
|
150 | - $recurring = (bool)wpinv_discount_is_recurring( $discount_id ); |
|
151 | - $start_date = wpinv_get_discount_start_date( $discount_id ); |
|
152 | - $expiration_date = wpinv_get_discount_expiration( $discount_id ); |
|
143 | + $type = wpinv_get_discount_type($discount_id); |
|
144 | + $item_reqs = wpinv_get_discount_item_reqs($discount_id); |
|
145 | + $excluded_items = wpinv_get_discount_excluded_items($discount_id); |
|
146 | + $min_total = wpinv_get_discount_min_total($discount_id); |
|
147 | + $max_total = wpinv_get_discount_max_total($discount_id); |
|
148 | + $max_uses = wpinv_get_discount_max_uses($discount_id); |
|
149 | + $single_use = wpinv_discount_is_single_use($discount_id); |
|
150 | + $recurring = (bool) wpinv_discount_is_recurring($discount_id); |
|
151 | + $start_date = wpinv_get_discount_start_date($discount_id); |
|
152 | + $expiration_date = wpinv_get_discount_expiration($discount_id); |
|
153 | 153 | |
154 | - if ( ! empty( $start_date ) && strpos( $start_date, '0000' ) === false ) { |
|
155 | - $start_time = strtotime( $start_date ); |
|
156 | - $start_h = date_i18n( 'H', $start_time ); |
|
157 | - $start_m = date_i18n( 'i', $start_time ); |
|
158 | - $start_date = date_i18n( 'Y-m-d', $start_time ); |
|
154 | + if (!empty($start_date) && strpos($start_date, '0000') === false) { |
|
155 | + $start_time = strtotime($start_date); |
|
156 | + $start_h = date_i18n('H', $start_time); |
|
157 | + $start_m = date_i18n('i', $start_time); |
|
158 | + $start_date = date_i18n('Y-m-d', $start_time); |
|
159 | 159 | } else { |
160 | 160 | $start_h = '00'; |
161 | 161 | $start_m = '00'; |
162 | 162 | } |
163 | 163 | |
164 | - if ( ! empty( $expiration_date ) && strpos( $expiration_date, '0000' ) === false ) { |
|
165 | - $expiration_time = strtotime( $expiration_date ); |
|
166 | - $expiration_h = date_i18n( 'H', $expiration_time ); |
|
167 | - $expiration_m = date_i18n( 'i', $expiration_time ); |
|
168 | - $expiration_date = date_i18n( 'Y-m-d', $expiration_time ); |
|
164 | + if (!empty($expiration_date) && strpos($expiration_date, '0000') === false) { |
|
165 | + $expiration_time = strtotime($expiration_date); |
|
166 | + $expiration_h = date_i18n('H', $expiration_time); |
|
167 | + $expiration_m = date_i18n('i', $expiration_time); |
|
168 | + $expiration_date = date_i18n('Y-m-d', $expiration_time); |
|
169 | 169 | } else { |
170 | 170 | $expiration_h = '23'; |
171 | 171 | $expiration_m = '59'; |
@@ -175,207 +175,207 @@ discard block |
||
175 | 175 | $max_total = $max_total > 0 ? $max_total : ''; |
176 | 176 | $max_uses = $max_uses > 0 ? $max_uses : ''; |
177 | 177 | ?> |
178 | -<?php do_action( 'wpinv_discount_form_top', $post ); ?> |
|
179 | -<?php wp_nonce_field( 'wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce' ); ;?> |
|
178 | +<?php do_action('wpinv_discount_form_top', $post); ?> |
|
179 | +<?php wp_nonce_field('wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce'); ;?> |
|
180 | 180 | <table class="form-table wpi-form-table"> |
181 | 181 | <tbody> |
182 | - <?php do_action( 'wpinv_discount_form_first', $post ); ?> |
|
183 | - <?php do_action( 'wpinv_discount_form_before_code', $post ); ?> |
|
182 | + <?php do_action('wpinv_discount_form_first', $post); ?> |
|
183 | + <?php do_action('wpinv_discount_form_before_code', $post); ?> |
|
184 | 184 | <tr> |
185 | 185 | <th valign="top" scope="row"> |
186 | - <label for="wpinv_discount_code"><?php _e( 'Discount Code', 'invoicing' ); ?></label> |
|
186 | + <label for="wpinv_discount_code"><?php _e('Discount Code', 'invoicing'); ?></label> |
|
187 | 187 | </th> |
188 | 188 | <td> |
189 | - <input type="text" name="code" id="wpinv_discount_code" class="medium-text" value="<?php echo esc_attr( wpinv_get_discount_code( $discount_id ) ); ?>" required> |
|
190 | - <p class="description"><?php _e( 'Enter a code for this discount, such as 10OFF', 'invoicing' ); ?></p> |
|
189 | + <input type="text" name="code" id="wpinv_discount_code" class="medium-text" value="<?php echo esc_attr(wpinv_get_discount_code($discount_id)); ?>" required> |
|
190 | + <p class="description"><?php _e('Enter a code for this discount, such as 10OFF', 'invoicing'); ?></p> |
|
191 | 191 | </td> |
192 | 192 | </tr> |
193 | - <?php do_action( 'wpinv_discount_form_before_type', $post ); ?> |
|
193 | + <?php do_action('wpinv_discount_form_before_type', $post); ?> |
|
194 | 194 | <tr> |
195 | 195 | <th valign="top" scope="row"> |
196 | - <label for="wpinv_discount_type"><?php _e( 'Discount Type', 'invoicing' ); ?></label> |
|
196 | + <label for="wpinv_discount_type"><?php _e('Discount Type', 'invoicing'); ?></label> |
|
197 | 197 | </th> |
198 | 198 | <td> |
199 | 199 | <select id="wpinv_discount_type" name="type" class="medium-text wpi_select2"> |
200 | - <?php foreach ( wpinv_get_discount_types() as $value => $label ) { ?> |
|
201 | - <option value="<?php echo $value ;?>" <?php selected( $type, $value ); ?>><?php echo $label; ?></option> |
|
200 | + <?php foreach (wpinv_get_discount_types() as $value => $label) { ?> |
|
201 | + <option value="<?php echo $value; ?>" <?php selected($type, $value); ?>><?php echo $label; ?></option> |
|
202 | 202 | <?php } ?> |
203 | 203 | </select> |
204 | - <p class="description"><?php _e( 'The kind of discount to apply for this discount.', 'invoicing' ); ?></p> |
|
204 | + <p class="description"><?php _e('The kind of discount to apply for this discount.', 'invoicing'); ?></p> |
|
205 | 205 | </td> |
206 | 206 | </tr> |
207 | - <?php do_action( 'wpinv_discount_form_before_amount', $post ); ?> |
|
207 | + <?php do_action('wpinv_discount_form_before_amount', $post); ?> |
|
208 | 208 | <tr> |
209 | 209 | <th valign="top" scope="row"> |
210 | - <label for="wpinv_discount_amount"><?php _e( 'Amount', 'invoicing' ); ?></label> |
|
210 | + <label for="wpinv_discount_amount"><?php _e('Amount', 'invoicing'); ?></label> |
|
211 | 211 | </th> |
212 | 212 | <td> |
213 | - <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> |
|
214 | - <p style="display:none;" class="description"><?php _e( 'Enter the discount amount in USD', 'invoicing' ); ?></p> |
|
215 | - <p class="description"><?php _e( 'Enter the discount value. Ex: 10', 'invoicing' ); ?></p> |
|
213 | + <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> |
|
214 | + <p style="display:none;" class="description"><?php _e('Enter the discount amount in USD', 'invoicing'); ?></p> |
|
215 | + <p class="description"><?php _e('Enter the discount value. Ex: 10', 'invoicing'); ?></p> |
|
216 | 216 | </td> |
217 | 217 | </tr> |
218 | - <?php do_action( 'wpinv_discount_form_before_items', $post ); ?> |
|
218 | + <?php do_action('wpinv_discount_form_before_items', $post); ?> |
|
219 | 219 | <tr> |
220 | 220 | <th valign="top" scope="row"> |
221 | - <label for="wpinv_discount_items"><?php _e( 'Items', 'invoicing' ); ?></label> |
|
221 | + <label for="wpinv_discount_items"><?php _e('Items', 'invoicing'); ?></label> |
|
222 | 222 | </th> |
223 | 223 | <td> |
224 | - <p><?php echo wpinv_item_dropdown( array( |
|
224 | + <p><?php echo wpinv_item_dropdown(array( |
|
225 | 225 | 'name' => 'items[]', |
226 | 226 | 'id' => 'items', |
227 | 227 | 'selected' => $item_reqs, |
228 | 228 | 'multiple' => true, |
229 | 229 | 'class' => 'medium-text wpi_select2', |
230 | - 'placeholder' => __( 'Select one or more Items', 'invoicing' ), |
|
230 | + 'placeholder' => __('Select one or more Items', 'invoicing'), |
|
231 | 231 | 'show_recurring' => true, |
232 | - ) ); ?> |
|
232 | + )); ?> |
|
233 | 233 | </p> |
234 | - <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> |
|
234 | + <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> |
|
235 | 235 | </td> |
236 | 236 | </tr> |
237 | - <?php do_action( 'wpinv_discount_form_before_excluded_items', $post ); ?> |
|
237 | + <?php do_action('wpinv_discount_form_before_excluded_items', $post); ?> |
|
238 | 238 | <tr> |
239 | 239 | <th valign="top" scope="row"> |
240 | - <label for="wpinv_discount_excluded_items"><?php _e( 'Excluded Items', 'invoicing' ); ?></label> |
|
240 | + <label for="wpinv_discount_excluded_items"><?php _e('Excluded Items', 'invoicing'); ?></label> |
|
241 | 241 | </th> |
242 | 242 | <td> |
243 | - <p><?php echo wpinv_item_dropdown( array( |
|
243 | + <p><?php echo wpinv_item_dropdown(array( |
|
244 | 244 | 'name' => 'excluded_items[]', |
245 | 245 | 'id' => 'excluded_items', |
246 | 246 | 'selected' => $excluded_items, |
247 | 247 | 'multiple' => true, |
248 | 248 | 'class' => 'medium-text wpi_select2', |
249 | - 'placeholder' => __( 'Select one or more Items', 'invoicing' ), |
|
249 | + 'placeholder' => __('Select one or more Items', 'invoicing'), |
|
250 | 250 | 'show_recurring' => true, |
251 | - ) ); ?> |
|
251 | + )); ?> |
|
252 | 252 | </p> |
253 | - <p class="description"><?php _e( 'Items which are NOT allowed to use this discount.', 'invoicing' ); ?></p> |
|
253 | + <p class="description"><?php _e('Items which are NOT allowed to use this discount.', 'invoicing'); ?></p> |
|
254 | 254 | </td> |
255 | 255 | </tr> |
256 | - <?php do_action( 'wpinv_discount_form_before_start', $post ); ?> |
|
256 | + <?php do_action('wpinv_discount_form_before_start', $post); ?> |
|
257 | 257 | <tr> |
258 | 258 | <th valign="top" scope="row"> |
259 | - <label for="wpinv_discount_start"><?php _e( 'Start Date', 'invoicing' ); ?></label> |
|
259 | + <label for="wpinv_discount_start"><?php _e('Start Date', 'invoicing'); ?></label> |
|
260 | 260 | </th> |
261 | 261 | <td> |
262 | - <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"> |
|
263 | - <?php for ( $i = 0; $i <= 23; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
264 | - <option value="<?php echo $value;?>" <?php selected( $value, $start_h ); ?>><?php echo $value;?></option> |
|
262 | + <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"> |
|
263 | + <?php for ($i = 0; $i <= 23; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?> |
|
264 | + <option value="<?php echo $value; ?>" <?php selected($value, $start_h); ?>><?php echo $value; ?></option> |
|
265 | 265 | <?php } ?> |
266 | 266 | </select> : <select id="wpinv_discount_start_m" name="start_m"> |
267 | - <?php for ( $i = 0; $i <= 59; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
268 | - <option value="<?php echo $value;?>" <?php selected( $value, $start_m ); ?>><?php echo $value;?></option> |
|
267 | + <?php for ($i = 0; $i <= 59; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?> |
|
268 | + <option value="<?php echo $value; ?>" <?php selected($value, $start_m); ?>><?php echo $value; ?></option> |
|
269 | 269 | <?php } ?> |
270 | 270 | </select> |
271 | - <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> |
|
271 | + <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> |
|
272 | 272 | </td> |
273 | 273 | </tr> |
274 | - <?php do_action( 'wpinv_discount_form_before_expiration', $post ); ?> |
|
274 | + <?php do_action('wpinv_discount_form_before_expiration', $post); ?> |
|
275 | 275 | <tr> |
276 | 276 | <th valign="top" scope="row"> |
277 | - <label for="wpinv_discount_expiration"><?php _e( 'Expiration Date', 'invoicing' ); ?></label> |
|
277 | + <label for="wpinv_discount_expiration"><?php _e('Expiration Date', 'invoicing'); ?></label> |
|
278 | 278 | </th> |
279 | 279 | <td> |
280 | - <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"> |
|
281 | - <?php for ( $i = 0; $i <= 23; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
282 | - <option value="<?php echo $value;?>" <?php selected( $value, $expiration_h ); ?>><?php echo $value;?></option> |
|
280 | + <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"> |
|
281 | + <?php for ($i = 0; $i <= 23; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?> |
|
282 | + <option value="<?php echo $value; ?>" <?php selected($value, $expiration_h); ?>><?php echo $value; ?></option> |
|
283 | 283 | <?php } ?> |
284 | 284 | </select> : <select id="wpinv_discount_expiration_m" name="expiration_m"> |
285 | - <?php for ( $i = 0; $i <= 59; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
286 | - <option value="<?php echo $value;?>" <?php selected( $value, $expiration_m ); ?>><?php echo $value;?></option> |
|
285 | + <?php for ($i = 0; $i <= 59; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?> |
|
286 | + <option value="<?php echo $value; ?>" <?php selected($value, $expiration_m); ?>><?php echo $value; ?></option> |
|
287 | 287 | <?php } ?> |
288 | 288 | </select> |
289 | - <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> |
|
289 | + <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> |
|
290 | 290 | </td> |
291 | 291 | </tr> |
292 | - <?php do_action( 'wpinv_discount_form_before_min_total', $post ); ?> |
|
292 | + <?php do_action('wpinv_discount_form_before_min_total', $post); ?> |
|
293 | 293 | <tr> |
294 | 294 | <th valign="top" scope="row"> |
295 | - <label for="wpinv_discount_min_total"><?php _e( 'Minimum Amount', 'invoicing' ); ?></label> |
|
295 | + <label for="wpinv_discount_min_total"><?php _e('Minimum Amount', 'invoicing'); ?></label> |
|
296 | 296 | </th> |
297 | 297 | <td> |
298 | 298 | <input type="text" name="min_total" id="wpinv_discount_min_total" class="wpi-field-price wpi-price" value="<?php echo $min_total; ?>"> |
299 | - <p class="description"><?php _e( 'This allows you to set the minimum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p> |
|
299 | + <p class="description"><?php _e('This allows you to set the minimum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing'); ?></p> |
|
300 | 300 | </td> |
301 | 301 | </tr> |
302 | - <?php do_action( 'wpinv_discount_form_before_max_total', $post ); ?> |
|
302 | + <?php do_action('wpinv_discount_form_before_max_total', $post); ?> |
|
303 | 303 | <tr> |
304 | 304 | <th valign="top" scope="row"> |
305 | - <label for="wpinv_discount_max_total"><?php _e( 'Maximum Amount', 'invoicing' ); ?></label> |
|
305 | + <label for="wpinv_discount_max_total"><?php _e('Maximum Amount', 'invoicing'); ?></label> |
|
306 | 306 | </th> |
307 | 307 | <td> |
308 | 308 | <input type="text" name="max_total" id="wpinv_discount_max_total" class="wpi-field-price wpi-price" value="<?php echo $max_total; ?>"> |
309 | - <p class="description"><?php _e( 'This allows you to set the maximum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p> |
|
309 | + <p class="description"><?php _e('This allows you to set the maximum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing'); ?></p> |
|
310 | 310 | </td> |
311 | 311 | </tr> |
312 | - <?php do_action( 'wpinv_discount_form_before_recurring', $post ); ?> |
|
312 | + <?php do_action('wpinv_discount_form_before_recurring', $post); ?> |
|
313 | 313 | <tr> |
314 | 314 | <th valign="top" scope="row"> |
315 | - <label for="wpinv_discount_recurring"><?php _e( 'For recurring apply to', 'invoicing' ); ?></label> |
|
315 | + <label for="wpinv_discount_recurring"><?php _e('For recurring apply to', 'invoicing'); ?></label> |
|
316 | 316 | </th> |
317 | 317 | <td> |
318 | 318 | <select id="wpinv_discount_recurring" name="recurring" class="medium-text wpi_select2"> |
319 | - <option value="0" <?php selected( false, $recurring ); ?>><?php _e( 'All payments', 'invoicing' ); ?></option> |
|
320 | - <option value="1" <?php selected( true, $recurring ); ?>><?php _e( 'First payment only', 'invoicing' ); ?></option> |
|
319 | + <option value="0" <?php selected(false, $recurring); ?>><?php _e('All payments', 'invoicing'); ?></option> |
|
320 | + <option value="1" <?php selected(true, $recurring); ?>><?php _e('First payment only', 'invoicing'); ?></option> |
|
321 | 321 | </select> |
322 | - <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> |
|
322 | + <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> |
|
323 | 323 | </td> |
324 | 324 | </tr> |
325 | - <?php do_action( 'wpinv_discount_form_before_max_uses', $post ); ?> |
|
325 | + <?php do_action('wpinv_discount_form_before_max_uses', $post); ?> |
|
326 | 326 | <tr> |
327 | 327 | <th valign="top" scope="row"> |
328 | - <label for="wpinv_discount_max_uses"><?php _e( 'Max Uses', 'invoicing' ); ?></label> |
|
328 | + <label for="wpinv_discount_max_uses"><?php _e('Max Uses', 'invoicing'); ?></label> |
|
329 | 329 | </th> |
330 | 330 | <td> |
331 | 331 | <input type="number" min="0" step="1" id="wpinv_discount_max_uses" name="max_uses" class="medium-text" value="<?php echo $max_uses; ?>"> |
332 | - <p class="description"><?php _e( 'The maximum number of times this discount can be used. Leave blank for unlimited.', 'invoicing' ); ?></p> |
|
332 | + <p class="description"><?php _e('The maximum number of times this discount can be used. Leave blank for unlimited.', 'invoicing'); ?></p> |
|
333 | 333 | </td> |
334 | 334 | </tr> |
335 | - <?php do_action( 'wpinv_discount_form_before_single_use', $post ); ?> |
|
335 | + <?php do_action('wpinv_discount_form_before_single_use', $post); ?> |
|
336 | 336 | <tr> |
337 | 337 | <th valign="top" scope="row"> |
338 | - <label for="wpinv_discount_single_use"><?php _e( 'Use Once Per User', 'invoicing' ); ?></label> |
|
338 | + <label for="wpinv_discount_single_use"><?php _e('Use Once Per User', 'invoicing'); ?></label> |
|
339 | 339 | </th> |
340 | 340 | <td> |
341 | - <input type="checkbox" value="1" name="single_use" id="wpinv_discount_single_use" <?php checked( true, $single_use ); ?>> |
|
342 | - <span class="description"><?php _e( 'Limit this discount to a single use per user?', 'invoicing' ); ?></span> |
|
341 | + <input type="checkbox" value="1" name="single_use" id="wpinv_discount_single_use" <?php checked(true, $single_use); ?>> |
|
342 | + <span class="description"><?php _e('Limit this discount to a single use per user?', 'invoicing'); ?></span> |
|
343 | 343 | </td> |
344 | 344 | </tr> |
345 | - <?php do_action( 'wpinv_discount_form_last', $post ); ?> |
|
345 | + <?php do_action('wpinv_discount_form_last', $post); ?> |
|
346 | 346 | </tbody> |
347 | 347 | </table> |
348 | -<?php do_action( 'wpinv_discount_form_bottom', $post ); ?> |
|
348 | +<?php do_action('wpinv_discount_form_bottom', $post); ?> |
|
349 | 349 | <?php |
350 | 350 | } |
351 | 351 | |
352 | -function wpinv_discount_metabox_save( $post_id, $post, $update = false ) { |
|
353 | - $post_type = !empty( $post ) ? $post->post_type : ''; |
|
352 | +function wpinv_discount_metabox_save($post_id, $post, $update = false) { |
|
353 | + $post_type = !empty($post) ? $post->post_type : ''; |
|
354 | 354 | |
355 | - if ( $post_type != 'wpi_discount' ) { |
|
355 | + if ($post_type != 'wpi_discount') { |
|
356 | 356 | return; |
357 | 357 | } |
358 | 358 | |
359 | - 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' ) ) ) { |
|
359 | + 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'))) { |
|
360 | 360 | return; |
361 | 361 | } |
362 | 362 | |
363 | - if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
363 | + if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || (defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) { |
|
364 | 364 | return; |
365 | 365 | } |
366 | 366 | |
367 | - if ( !current_user_can( wpinv_get_capability(), $post_id ) ) { |
|
367 | + if (!current_user_can(wpinv_get_capability(), $post_id)) { |
|
368 | 368 | return; |
369 | 369 | } |
370 | 370 | |
371 | - if ( !empty( $_POST['start'] ) && isset( $_POST['start_h'] ) && isset( $_POST['start_m'] ) && $_POST['start_h'] !== '' && $_POST['start_m'] !== '' ) { |
|
371 | + if (!empty($_POST['start']) && isset($_POST['start_h']) && isset($_POST['start_m']) && $_POST['start_h'] !== '' && $_POST['start_m'] !== '') { |
|
372 | 372 | $_POST['start'] = $_POST['start'] . ' ' . $_POST['start_h'] . ':' . $_POST['start_m']; |
373 | 373 | } |
374 | 374 | |
375 | - if ( !empty( $_POST['expiration'] ) && isset( $_POST['expiration_h'] ) && isset( $_POST['expiration_m'] ) ) { |
|
375 | + if (!empty($_POST['expiration']) && isset($_POST['expiration_h']) && isset($_POST['expiration_m'])) { |
|
376 | 376 | $_POST['expiration'] = $_POST['expiration'] . ' ' . $_POST['expiration_h'] . ':' . $_POST['expiration_m']; |
377 | 377 | } |
378 | 378 | |
379 | - return wpinv_store_discount( $post_id, $_POST, $post, $update ); |
|
379 | + return wpinv_store_discount($post_id, $_POST, $post, $update); |
|
380 | 380 | } |
381 | -add_action( 'save_post', 'wpinv_discount_metabox_save', 10, 3 ); |
|
382 | 381 | \ No newline at end of file |
382 | +add_action('save_post', 'wpinv_discount_metabox_save', 10, 3); |
|
383 | 383 | \ 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,7 +120,7 @@ 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> |
@@ -133,11 +133,11 @@ discard block |
||
133 | 133 | </div> |
134 | 134 | </td> |
135 | 135 | <td class="price"><input type="text" placeholder="0.00" class="wpi-field-price wpi-price" name="_wpinv_quick[price]" /></td> |
136 | - <?php if ( $item_quantities ) { ?> |
|
136 | + <?php if ($item_quantities) { ?> |
|
137 | 137 | <td class="qty"><input type="number" class="small-text" step="1" min="1" value="1" name="_wpinv_quick[qty]" /></td> |
138 | 138 | <?php } ?> |
139 | 139 | <td class="total"></td> |
140 | - <?php if ( $use_taxes ) { ?> |
|
140 | + <?php if ($use_taxes) { ?> |
|
141 | 141 | <td class="tax"></td> |
142 | 142 | <?php } ?> |
143 | 143 | <td class="action"></td> |
@@ -150,29 +150,29 @@ discard block |
||
150 | 150 | <td colspan="<?php echo $cols; ?>"></td> |
151 | 151 | </tr> |
152 | 152 | <tr class="totals"> |
153 | - <td colspan="<?php echo ( $cols - 4 ); ?>"></td> |
|
153 | + <td colspan="<?php echo ($cols - 4); ?>"></td> |
|
154 | 154 | <td colspan="4"> |
155 | 155 | <table cellspacing="0" cellpadding="0"> |
156 | 156 | <tr class="subtotal"> |
157 | - <td class="name"><?php _e( 'Sub Total:', 'invoicing' );?></td> |
|
158 | - <td class="total"><?php echo $subtotal;?></td> |
|
157 | + <td class="name"><?php _e('Sub Total:', 'invoicing'); ?></td> |
|
158 | + <td class="total"><?php echo $subtotal; ?></td> |
|
159 | 159 | <td class="action"></td> |
160 | 160 | </tr> |
161 | 161 | <tr class="discount"> |
162 | - <td class="name"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice->ID ) ); ?>:</td> |
|
163 | - <td class="total"><?php echo wpinv_discount( $invoice->ID, true, true ); ?></td> |
|
162 | + <td class="name"><?php wpinv_get_discount_label(wpinv_discount_code($invoice->ID)); ?>:</td> |
|
163 | + <td class="total"><?php echo wpinv_discount($invoice->ID, true, true); ?></td> |
|
164 | 164 | <td class="action"></td> |
165 | 165 | </tr> |
166 | - <?php if ( $use_taxes ) { ?> |
|
166 | + <?php if ($use_taxes) { ?> |
|
167 | 167 | <tr class="tax"> |
168 | - <td class="name"><?php _e( 'Tax:', 'invoicing' );?></td> |
|
169 | - <td class="total"><?php echo $tax;?></td> |
|
168 | + <td class="name"><?php _e('Tax:', 'invoicing'); ?></td> |
|
169 | + <td class="total"><?php echo $tax; ?></td> |
|
170 | 170 | <td class="action"></td> |
171 | 171 | </tr> |
172 | 172 | <?php } ?> |
173 | 173 | <tr class="total"> |
174 | - <td class="name"><?php echo apply_filters( 'wpinv_invoice_items_total_label', __( 'Invoice Total:', 'invoicing' ), $invoice );?></td> |
|
175 | - <td class="total"><?php echo $total;?></td> |
|
174 | + <td class="name"><?php echo apply_filters('wpinv_invoice_items_total_label', __('Invoice Total:', 'invoicing'), $invoice); ?></td> |
|
175 | + <td class="total"><?php echo $total; ?></td> |
|
176 | 176 | <td class="action"></td> |
177 | 177 | </tr> |
178 | 178 | </table> |
@@ -183,90 +183,90 @@ discard block |
||
183 | 183 | <div class="wpinv-actions"> |
184 | 184 | <?php ob_start(); ?> |
185 | 185 | <?php |
186 | - if ( !$invoice->is_paid() && !$invoice->is_refunded() ) { |
|
187 | - if ( !$invoice->is_recurring() ) { |
|
188 | - echo wpinv_item_dropdown( array( |
|
186 | + if (!$invoice->is_paid() && !$invoice->is_refunded()) { |
|
187 | + if (!$invoice->is_recurring()) { |
|
188 | + echo wpinv_item_dropdown(array( |
|
189 | 189 | 'name' => 'wpinv_invoice_item', |
190 | 190 | 'id' => 'wpinv_invoice_item', |
191 | 191 | 'show_recurring' => true, |
192 | 192 | 'class' => 'wpi_select2', |
193 | - ) ); |
|
193 | + )); |
|
194 | 194 | ?> |
195 | - <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"> |
|
195 | + <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"> |
|
196 | 196 | <?php } ?> |
197 | - <?php do_action( 'wpinv_invoice_items_actions', $invoice ); ?> |
|
198 | - <?php $item_actions = ob_get_clean(); echo apply_filters( 'wpinv_invoice_items_actions_content', $item_actions, $invoice, $post ); ?> |
|
197 | + <?php do_action('wpinv_invoice_items_actions', $invoice); ?> |
|
198 | + <?php $item_actions = ob_get_clean(); echo apply_filters('wpinv_invoice_items_actions_content', $item_actions, $invoice, $post); ?> |
|
199 | 199 | </div> |
200 | 200 | </div> |
201 | 201 | <?php |
202 | 202 | } |
203 | 203 | |
204 | - public static function prices( $post ) { |
|
204 | + public static function prices($post) { |
|
205 | 205 | $symbol = wpinv_currency_symbol(); |
206 | 206 | $position = wpinv_currency_position(); |
207 | - $item = new WPInv_Item( $post->ID ); |
|
207 | + $item = new WPInv_Item($post->ID); |
|
208 | 208 | |
209 | 209 | $price = $item->get_price(); |
210 | 210 | $is_dynamic_pricing = $item->get_is_dynamic_pricing(); |
211 | 211 | $minimum_price = $item->get_minimum_price(); |
212 | 212 | $is_recurring = $item->is_recurring(); |
213 | 213 | $period = $item->get_recurring_period(); |
214 | - $interval = absint( $item->get_recurring_interval() ); |
|
215 | - $times = absint( $item->get_recurring_limit() ); |
|
214 | + $interval = absint($item->get_recurring_interval()); |
|
215 | + $times = absint($item->get_recurring_limit()); |
|
216 | 216 | $free_trial = $item->has_free_trial(); |
217 | 217 | $trial_interval = $item->get_trial_interval(); |
218 | 218 | $trial_period = $item->get_trial_period(); |
219 | 219 | |
220 | 220 | $intervals = array(); |
221 | - for ( $i = 1; $i <= 90; $i++ ) { |
|
221 | + for ($i = 1; $i <= 90; $i++) { |
|
222 | 222 | $intervals[$i] = $i; |
223 | 223 | } |
224 | 224 | |
225 | - $interval = $interval > 0 ? $interval : 1; |
|
225 | + $interval = $interval > 0 ? $interval : 1; |
|
226 | 226 | |
227 | 227 | $class = $is_recurring ? 'wpinv-recurring-y' : 'wpinv-recurring-n'; |
228 | 228 | |
229 | 229 | $minimum_price_style = 'margin-left: 24px;'; |
230 | - if(! $is_dynamic_pricing ) { |
|
230 | + if (!$is_dynamic_pricing) { |
|
231 | 231 | $minimum_price_style .= 'display: none;'; |
232 | 232 | } |
233 | 233 | |
234 | 234 | ?> |
235 | - <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' ) ;?>" /> |
|
236 | - <?php do_action( 'wpinv_prices_metabox_price', $item ); ?> |
|
235 | + <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'); ?>" /> |
|
236 | + <?php do_action('wpinv_prices_metabox_price', $item); ?> |
|
237 | 237 | </p> |
238 | 238 | |
239 | - <?php if( $item->supports_dynamic_pricing() ) { ?> |
|
239 | + <?php if ($item->supports_dynamic_pricing()) { ?> |
|
240 | 240 | |
241 | 241 | <p class="wpinv-row-name-your-price"> |
242 | 242 | <label> |
243 | - <input type="checkbox" name="wpinv_name_your_price" id="wpinv_name_your_price" value="1" <?php checked( 1, $is_dynamic_pricing ); ?> /> |
|
244 | - <?php echo apply_filters( 'wpinv_name_your_price_toggle_text', __( 'User can set a custom price', 'invoicing' ) ); ?> |
|
243 | + <input type="checkbox" name="wpinv_name_your_price" id="wpinv_name_your_price" value="1" <?php checked(1, $is_dynamic_pricing); ?> /> |
|
244 | + <?php echo apply_filters('wpinv_name_your_price_toggle_text', __('User can set a custom price', 'invoicing')); ?> |
|
245 | 245 | </label> |
246 | - <?php do_action( 'wpinv_prices_metabox_name_your_price_field', $item ); ?> |
|
246 | + <?php do_action('wpinv_prices_metabox_name_your_price_field', $item); ?> |
|
247 | 247 | </p> |
248 | 248 | |
249 | 249 | <p class="wpinv-row-minimum-price" style="<?php echo $minimum_price_style; ?>"> |
250 | 250 | <label> |
251 | - <?php _e( 'Minimum Price', 'invoicing' ); ?> |
|
252 | - <?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 : '' );?> |
|
251 | + <?php _e('Minimum Price', 'invoicing'); ?> |
|
252 | + <?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 : ''); ?> |
|
253 | 253 | </label> |
254 | 254 | |
255 | - <?php do_action( 'wpinv_prices_metabox_minimum_price_field', $item ); ?> |
|
255 | + <?php do_action('wpinv_prices_metabox_minimum_price_field', $item); ?> |
|
256 | 256 | </p> |
257 | 257 | |
258 | 258 | <?php } ?> |
259 | 259 | |
260 | 260 | <p class="wpinv-row-is-recurring"> |
261 | 261 | <label for="wpinv_is_recurring"> |
262 | - <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked( 1, $is_recurring ); ?> /> |
|
263 | - <?php echo apply_filters( 'wpinv_is_recurring_toggle_text', __( 'Is Recurring Item?', 'invoicing' ) ); ?> |
|
262 | + <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked(1, $is_recurring); ?> /> |
|
263 | + <?php echo apply_filters('wpinv_is_recurring_toggle_text', __('Is Recurring Item?', 'invoicing')); ?> |
|
264 | 264 | </label> |
265 | - <?php do_action( 'wpinv_prices_metabox_is_recurring_field', $item ); ?> |
|
265 | + <?php do_action('wpinv_prices_metabox_is_recurring_field', $item); ?> |
|
266 | 266 | </p> |
267 | - <p class="wpinv-row-recurring-fields <?php echo $class;?>"> |
|
268 | - <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> |
|
269 | - <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e( 'at every', 'invoicing' );?> <?php echo wpinv_html_select( array( |
|
267 | + <p class="wpinv-row-recurring-fields <?php echo $class; ?>"> |
|
268 | + <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> |
|
269 | + <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e('at every', 'invoicing'); ?> <?php echo wpinv_html_select(array( |
|
270 | 270 | 'options' => $intervals, |
271 | 271 | 'name' => 'wpinv_recurring_interval', |
272 | 272 | 'id' => 'wpinv_recurring_interval', |
@@ -274,30 +274,30 @@ discard block |
||
274 | 274 | 'show_option_all' => false, |
275 | 275 | 'show_option_none' => false, |
276 | 276 | 'class' => 'wpi_select2', |
277 | - ) ); ?> <span id="wpinv_interval_text"><?php _e( 'day(s)', 'invoicing' );?></span></label> |
|
278 | - <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> |
|
277 | + )); ?> <span id="wpinv_interval_text"><?php _e('day(s)', 'invoicing'); ?></span></label> |
|
278 | + <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> |
|
279 | 279 | <span class="clear wpi-trial-clr"></span> |
280 | 280 | <label class="wpinv-free-trial" for="wpinv_free_trial"> |
281 | - <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked( true, (bool)$free_trial ); ?> /> |
|
282 | - <?php echo __( 'Offer free trial for', 'invoicing' ); ?> |
|
281 | + <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked(true, (bool) $free_trial); ?> /> |
|
282 | + <?php echo __('Offer free trial for', 'invoicing'); ?> |
|
283 | 283 | </label> |
284 | 284 | <label class="wpinv-trial-interval" for="wpinv_trial_interval"> |
285 | - <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> |
|
285 | + <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> |
|
286 | 286 | </label> |
287 | - <?php do_action( 'wpinv_prices_metabox_recurring_fields', $item ); ?> |
|
287 | + <?php do_action('wpinv_prices_metabox_recurring_fields', $item); ?> |
|
288 | 288 | </p> |
289 | - <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type( $post->ID ); ?>" /> |
|
290 | - <?php do_action( 'wpinv_item_price_field', $post->ID ); ?> |
|
289 | + <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type($post->ID); ?>" /> |
|
290 | + <?php do_action('wpinv_item_price_field', $post->ID); ?> |
|
291 | 291 | <?php |
292 | 292 | } |
293 | 293 | |
294 | - public static function vat_rules( $post ) { |
|
294 | + public static function vat_rules($post) { |
|
295 | 295 | global $wpinv_euvat; |
296 | 296 | |
297 | - $rule_type = $wpinv_euvat->get_item_rule( $post->ID ); |
|
297 | + $rule_type = $wpinv_euvat->get_item_rule($post->ID); |
|
298 | 298 | ?> |
299 | - <p><label for="wpinv_vat_rules"><strong><?php _e( 'Select how VAT rules will be applied:', 'invoicing' );?></strong></label> |
|
300 | - <?php echo wpinv_html_select( array( |
|
299 | + <p><label for="wpinv_vat_rules"><strong><?php _e('Select how VAT rules will be applied:', 'invoicing'); ?></strong></label> |
|
300 | + <?php echo wpinv_html_select(array( |
|
301 | 301 | 'options' => $wpinv_euvat->get_rules(), |
302 | 302 | 'name' => 'wpinv_vat_rules', |
303 | 303 | 'id' => 'wpinv_vat_rules', |
@@ -305,19 +305,19 @@ discard block |
||
305 | 305 | 'show_option_all' => false, |
306 | 306 | 'show_option_none' => false, |
307 | 307 | 'class' => 'gdmbx2-text-medium wpinv-vat-rules wpi_select2', |
308 | - ) ); ?> |
|
308 | + )); ?> |
|
309 | 309 | </p> |
310 | - <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> |
|
311 | - <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> |
|
310 | + <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> |
|
311 | + <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> |
|
312 | 312 | <?php |
313 | 313 | } |
314 | 314 | |
315 | - public static function vat_classes( $post ) { |
|
315 | + public static function vat_classes($post) { |
|
316 | 316 | global $wpinv_euvat; |
317 | 317 | |
318 | - $vat_class = $wpinv_euvat->get_item_class( $post->ID ); |
|
318 | + $vat_class = $wpinv_euvat->get_item_class($post->ID); |
|
319 | 319 | ?> |
320 | - <p><?php echo wpinv_html_select( array( |
|
320 | + <p><?php echo wpinv_html_select(array( |
|
321 | 321 | 'options' => $wpinv_euvat->get_all_classes(), |
322 | 322 | 'name' => 'wpinv_vat_class', |
323 | 323 | 'id' => 'wpinv_vat_class', |
@@ -325,18 +325,18 @@ discard block |
||
325 | 325 | 'show_option_all' => false, |
326 | 326 | 'show_option_none' => false, |
327 | 327 | 'class' => 'gdmbx2-text-medium wpinv-vat-class wpi_select2', |
328 | - ) ); ?> |
|
328 | + )); ?> |
|
329 | 329 | </p> |
330 | - <p class="wpi-m0"><?php _e( 'Select the VAT rate class to use for this invoice item.', 'invoicing' ); ?></p> |
|
330 | + <p class="wpi-m0"><?php _e('Select the VAT rate class to use for this invoice item.', 'invoicing'); ?></p> |
|
331 | 331 | <?php |
332 | 332 | } |
333 | 333 | |
334 | - public static function item_info( $post ) { |
|
335 | - $item_type = wpinv_get_item_type( $post->ID ); |
|
336 | - do_action( 'wpinv_item_info_metabox_before', $post ); |
|
334 | + public static function item_info($post) { |
|
335 | + $item_type = wpinv_get_item_type($post->ID); |
|
336 | + do_action('wpinv_item_info_metabox_before', $post); |
|
337 | 337 | ?> |
338 | - <p><label for="wpinv_item_type"><strong><?php _e( 'Type:', 'invoicing' );?></strong></label> |
|
339 | - <?php echo wpinv_html_select( array( |
|
338 | + <p><label for="wpinv_item_type"><strong><?php _e('Type:', 'invoicing'); ?></strong></label> |
|
339 | + <?php echo wpinv_html_select(array( |
|
340 | 340 | 'options' => wpinv_get_item_types(), |
341 | 341 | 'name' => 'wpinv_item_type', |
342 | 342 | 'id' => 'wpinv_item_type', |
@@ -344,114 +344,114 @@ discard block |
||
344 | 344 | 'show_option_all' => false, |
345 | 345 | 'show_option_none' => false, |
346 | 346 | 'class' => 'gdmbx2-text-medium wpinv-item-type', |
347 | - ) ); ?> |
|
347 | + )); ?> |
|
348 | 348 | </p> |
349 | - <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> |
|
349 | + <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> |
|
350 | 350 | <?php |
351 | - do_action( 'wpinv_item_info_metabox_after', $post ); |
|
351 | + do_action('wpinv_item_info_metabox_after', $post); |
|
352 | 352 | } |
353 | 353 | |
354 | - public static function meta_values( $post ) { |
|
355 | - $meta_keys = apply_filters( 'wpinv_show_meta_values_for_keys', array( |
|
354 | + public static function meta_values($post) { |
|
355 | + $meta_keys = apply_filters('wpinv_show_meta_values_for_keys', array( |
|
356 | 356 | 'type', |
357 | 357 | 'custom_id' |
358 | - ) ); |
|
358 | + )); |
|
359 | 359 | |
360 | - if ( empty( $meta_keys ) ) { |
|
360 | + if (empty($meta_keys)) { |
|
361 | 361 | return; |
362 | 362 | } |
363 | 363 | |
364 | - do_action( 'wpinv_meta_values_metabox_before', $post ); |
|
364 | + do_action('wpinv_meta_values_metabox_before', $post); |
|
365 | 365 | |
366 | - foreach ( $meta_keys as $meta_key ) { |
|
366 | + foreach ($meta_keys as $meta_key) { |
|
367 | 367 | ?> |
368 | - <p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta( $post->ID, '_wpinv_' . $meta_key, true ); ?></label></p> |
|
368 | + <p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta($post->ID, '_wpinv_' . $meta_key, true); ?></label></p> |
|
369 | 369 | <?php |
370 | 370 | } |
371 | 371 | |
372 | - do_action( 'wpinv_meta_values_metabox_after', $post ); |
|
372 | + do_action('wpinv_meta_values_metabox_after', $post); |
|
373 | 373 | } |
374 | 374 | |
375 | - public static function save( $post_id, $data, $post ) { |
|
376 | - $invoice = new WPInv_Invoice( $post_id ); |
|
375 | + public static function save($post_id, $data, $post) { |
|
376 | + $invoice = new WPInv_Invoice($post_id); |
|
377 | 377 | |
378 | 378 | // Billing |
379 | - $first_name = sanitize_text_field( $data['wpinv_first_name'] ); |
|
380 | - $last_name = sanitize_text_field( $data['wpinv_last_name'] ); |
|
381 | - $company = sanitize_text_field( $data['wpinv_company'] ); |
|
382 | - $vat_number = sanitize_text_field( $data['wpinv_vat_number'] ); |
|
383 | - $phone = sanitize_text_field( $data['wpinv_phone'] ); |
|
384 | - $address = sanitize_text_field( $data['wpinv_address'] ); |
|
385 | - $city = sanitize_text_field( $data['wpinv_city'] ); |
|
386 | - $zip = sanitize_text_field( $data['wpinv_zip'] ); |
|
387 | - $country = sanitize_text_field( $data['wpinv_country'] ); |
|
388 | - $state = sanitize_text_field( $data['wpinv_state'] ); |
|
379 | + $first_name = sanitize_text_field($data['wpinv_first_name']); |
|
380 | + $last_name = sanitize_text_field($data['wpinv_last_name']); |
|
381 | + $company = sanitize_text_field($data['wpinv_company']); |
|
382 | + $vat_number = sanitize_text_field($data['wpinv_vat_number']); |
|
383 | + $phone = sanitize_text_field($data['wpinv_phone']); |
|
384 | + $address = sanitize_text_field($data['wpinv_address']); |
|
385 | + $city = sanitize_text_field($data['wpinv_city']); |
|
386 | + $zip = sanitize_text_field($data['wpinv_zip']); |
|
387 | + $country = sanitize_text_field($data['wpinv_country']); |
|
388 | + $state = sanitize_text_field($data['wpinv_state']); |
|
389 | 389 | |
390 | 390 | // Details |
391 | - $status = sanitize_text_field( $data['wpinv_status'] ); |
|
392 | - $old_status = !empty( $data['original_post_status'] ) ? sanitize_text_field( $data['original_post_status'] ) : $status; |
|
393 | - $number = sanitize_text_field( $data['wpinv_number'] ); |
|
394 | - $due_date = isset( $data['wpinv_due_date'] ) ? sanitize_text_field( $data['wpinv_due_date'] ) : ''; |
|
391 | + $status = sanitize_text_field($data['wpinv_status']); |
|
392 | + $old_status = !empty($data['original_post_status']) ? sanitize_text_field($data['original_post_status']) : $status; |
|
393 | + $number = sanitize_text_field($data['wpinv_number']); |
|
394 | + $due_date = isset($data['wpinv_due_date']) ? sanitize_text_field($data['wpinv_due_date']) : ''; |
|
395 | 395 | //$discounts = sanitize_text_field( $data['wpinv_discounts'] ); |
396 | 396 | //$discount = sanitize_text_field( $data['wpinv_discount'] ); |
397 | 397 | |
398 | - $ip = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip(); |
|
399 | - |
|
400 | - $invoice->set( 'due_date', $due_date ); |
|
401 | - $invoice->set( 'first_name', $first_name ); |
|
402 | - $invoice->set( 'last_name', $last_name ); |
|
403 | - $invoice->set( 'company', $company ); |
|
404 | - $invoice->set( 'vat_number', $vat_number ); |
|
405 | - $invoice->set( 'phone', $phone ); |
|
406 | - $invoice->set( 'address', $address ); |
|
407 | - $invoice->set( 'city', $city ); |
|
408 | - $invoice->set( 'zip', $zip ); |
|
409 | - $invoice->set( 'country', $country ); |
|
410 | - $invoice->set( 'state', $state ); |
|
411 | - $invoice->set( 'status', $status ); |
|
398 | + $ip = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip(); |
|
399 | + |
|
400 | + $invoice->set('due_date', $due_date); |
|
401 | + $invoice->set('first_name', $first_name); |
|
402 | + $invoice->set('last_name', $last_name); |
|
403 | + $invoice->set('company', $company); |
|
404 | + $invoice->set('vat_number', $vat_number); |
|
405 | + $invoice->set('phone', $phone); |
|
406 | + $invoice->set('address', $address); |
|
407 | + $invoice->set('city', $city); |
|
408 | + $invoice->set('zip', $zip); |
|
409 | + $invoice->set('country', $country); |
|
410 | + $invoice->set('state', $state); |
|
411 | + $invoice->set('status', $status); |
|
412 | 412 | //$invoice->set( 'number', $number ); |
413 | 413 | //$invoice->set( 'discounts', $discounts ); |
414 | 414 | //$invoice->set( 'discount', $discount ); |
415 | - $invoice->set( 'ip', $ip ); |
|
415 | + $invoice->set('ip', $ip); |
|
416 | 416 | $invoice->old_status = $_POST['original_post_status']; |
417 | 417 | $invoice->currency = wpinv_get_currency(); |
418 | - if ( !empty( $data['wpinv_gateway'] ) ) { |
|
419 | - $invoice->set( 'gateway', sanitize_text_field( $data['wpinv_gateway'] ) ); |
|
418 | + if (!empty($data['wpinv_gateway'])) { |
|
419 | + $invoice->set('gateway', sanitize_text_field($data['wpinv_gateway'])); |
|
420 | 420 | } |
421 | 421 | $saved = $invoice->save(); |
422 | 422 | |
423 | 423 | // Check for payment notes |
424 | - if ( !empty( $data['invoice_note'] ) ) { |
|
425 | - $note = wp_kses( $data['invoice_note'], array() ); |
|
426 | - $note_type = sanitize_text_field( $data['invoice_note_type'] ); |
|
424 | + if (!empty($data['invoice_note'])) { |
|
425 | + $note = wp_kses($data['invoice_note'], array()); |
|
426 | + $note_type = sanitize_text_field($data['invoice_note_type']); |
|
427 | 427 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
428 | 428 | |
429 | - wpinv_insert_payment_note( $invoice->ID, $note, $is_customer_note ); |
|
429 | + wpinv_insert_payment_note($invoice->ID, $note, $is_customer_note); |
|
430 | 430 | } |
431 | 431 | |
432 | 432 | // Update user address if empty. |
433 | - if ( $saved && !empty( $invoice ) ) { |
|
434 | - if ( $user_id = $invoice->get_user_id() ) { |
|
435 | - $user_address = wpinv_get_user_address( $user_id, false ); |
|
433 | + if ($saved && !empty($invoice)) { |
|
434 | + if ($user_id = $invoice->get_user_id()) { |
|
435 | + $user_address = wpinv_get_user_address($user_id, false); |
|
436 | 436 | |
437 | 437 | if (empty($user_address['first_name'])) { |
438 | - update_user_meta( $user_id, '_wpinv_first_name', $first_name ); |
|
439 | - update_user_meta( $user_id, '_wpinv_last_name', $last_name ); |
|
438 | + update_user_meta($user_id, '_wpinv_first_name', $first_name); |
|
439 | + update_user_meta($user_id, '_wpinv_last_name', $last_name); |
|
440 | 440 | } else if (empty($user_address['last_name']) && $user_address['first_name'] == $first_name) { |
441 | - update_user_meta( $user_id, '_wpinv_last_name', $last_name ); |
|
441 | + update_user_meta($user_id, '_wpinv_last_name', $last_name); |
|
442 | 442 | } |
443 | 443 | |
444 | 444 | if (empty($user_address['address']) || empty($user_address['city']) || empty($user_address['state']) || empty($user_address['country'])) { |
445 | - update_user_meta( $user_id, '_wpinv_address', $address ); |
|
446 | - update_user_meta( $user_id, '_wpinv_city', $city ); |
|
447 | - update_user_meta( $user_id, '_wpinv_state', $state ); |
|
448 | - update_user_meta( $user_id, '_wpinv_country', $country ); |
|
449 | - update_user_meta( $user_id, '_wpinv_zip', $zip ); |
|
450 | - update_user_meta( $user_id, '_wpinv_phone', $phone ); |
|
445 | + update_user_meta($user_id, '_wpinv_address', $address); |
|
446 | + update_user_meta($user_id, '_wpinv_city', $city); |
|
447 | + update_user_meta($user_id, '_wpinv_state', $state); |
|
448 | + update_user_meta($user_id, '_wpinv_country', $country); |
|
449 | + update_user_meta($user_id, '_wpinv_zip', $zip); |
|
450 | + update_user_meta($user_id, '_wpinv_phone', $phone); |
|
451 | 451 | } |
452 | 452 | } |
453 | 453 | |
454 | - do_action( 'wpinv_invoice_metabox_saved', $invoice ); |
|
454 | + do_action('wpinv_invoice_metabox_saved', $invoice); |
|
455 | 455 | } |
456 | 456 | |
457 | 457 | return $saved; |
@@ -11,49 +11,49 @@ discard block |
||
11 | 11 | * @since 1.0.0 |
12 | 12 | */ |
13 | 13 | function wpinv_automatic_upgrade() { |
14 | - $wpi_version = get_option( 'wpinv_version' ); |
|
14 | + $wpi_version = get_option('wpinv_version'); |
|
15 | 15 | |
16 | - if ( $wpi_version == WPINV_VERSION ) { |
|
16 | + if ($wpi_version == WPINV_VERSION) { |
|
17 | 17 | return; |
18 | 18 | } |
19 | 19 | |
20 | - if ( version_compare( $wpi_version, '0.0.5', '<' ) ) { |
|
20 | + if (version_compare($wpi_version, '0.0.5', '<')) { |
|
21 | 21 | wpinv_v005_upgrades(); |
22 | 22 | } |
23 | 23 | |
24 | - if ( version_compare( $wpi_version, '1.0.3', '<' ) ) { |
|
24 | + if (version_compare($wpi_version, '1.0.3', '<')) { |
|
25 | 25 | wpinv_v110_upgrades(); |
26 | 26 | } |
27 | 27 | |
28 | - update_option( 'wpinv_version', WPINV_VERSION ); |
|
28 | + update_option('wpinv_version', WPINV_VERSION); |
|
29 | 29 | } |
30 | -add_action( 'admin_init', 'wpinv_automatic_upgrade' ); |
|
30 | +add_action('admin_init', 'wpinv_automatic_upgrade'); |
|
31 | 31 | |
32 | 32 | function wpinv_v005_upgrades() { |
33 | 33 | global $wpdb; |
34 | 34 | |
35 | 35 | // Invoices status |
36 | - $results = $wpdb->get_results( "SELECT ID FROM " . $wpdb->posts . " WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
37 | - if ( !empty( $results ) ) { |
|
38 | - $wpdb->query( "UPDATE " . $wpdb->posts . " SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
36 | + $results = $wpdb->get_results("SELECT ID FROM " . $wpdb->posts . " WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )"); |
|
37 | + if (!empty($results)) { |
|
38 | + $wpdb->query("UPDATE " . $wpdb->posts . " SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )"); |
|
39 | 39 | |
40 | 40 | // Clean post cache |
41 | - foreach ( $results as $row ) { |
|
42 | - clean_post_cache( $row->ID ); |
|
41 | + foreach ($results as $row) { |
|
42 | + clean_post_cache($row->ID); |
|
43 | 43 | } |
44 | 44 | } |
45 | 45 | |
46 | 46 | // Item meta key changes |
47 | 47 | $query = "SELECT DISTINCT post_id FROM " . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )"; |
48 | - $results = $wpdb->get_results( $query ); |
|
48 | + $results = $wpdb->get_results($query); |
|
49 | 49 | |
50 | - if ( !empty( $results ) ) { |
|
51 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
52 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
53 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
50 | + if (!empty($results)) { |
|
51 | + $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )"); |
|
52 | + $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'"); |
|
53 | + $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'"); |
|
54 | 54 | |
55 | - foreach ( $results as $row ) { |
|
56 | - clean_post_cache( $row->post_id ); |
|
55 | + foreach ($results as $row) { |
|
56 | + clean_post_cache($row->post_id); |
|
57 | 57 | } |
58 | 58 | } |
59 | 59 | |
@@ -74,79 +74,79 @@ discard block |
||
74 | 74 | function wpinv_convert_old_subscriptions() { |
75 | 75 | global $wpdb; |
76 | 76 | |
77 | - $query = "SELECT ". $wpdb->posts .".ID FROM ". $wpdb->posts ." INNER JOIN ". $wpdb->postmeta ." ON ( ". $wpdb->posts .".ID = ". $wpdb->postmeta .".post_id ) WHERE 1=1 AND ". $wpdb->postmeta .".meta_key = '_wpinv_subscr_status' AND (". $wpdb->postmeta .".meta_value = 'pending' OR ". $wpdb->postmeta .".meta_value = 'active' OR ". $wpdb->postmeta .".meta_value = 'cancelled' OR ". $wpdb->postmeta .".meta_value = 'completed' OR ". $wpdb->postmeta .".meta_value = 'expired' OR ". $wpdb->postmeta .".meta_value = 'trialling' OR ". $wpdb->postmeta .".meta_value = 'failing') AND ". $wpdb->posts .".post_type = 'wpi_invoice' GROUP BY ". $wpdb->posts .".ID ORDER BY ". $wpdb->posts .".ID ASC"; |
|
77 | + $query = "SELECT " . $wpdb->posts . ".ID FROM " . $wpdb->posts . " INNER JOIN " . $wpdb->postmeta . " ON ( " . $wpdb->posts . ".ID = " . $wpdb->postmeta . ".post_id ) WHERE 1=1 AND " . $wpdb->postmeta . ".meta_key = '_wpinv_subscr_status' AND (" . $wpdb->postmeta . ".meta_value = 'pending' OR " . $wpdb->postmeta . ".meta_value = 'active' OR " . $wpdb->postmeta . ".meta_value = 'cancelled' OR " . $wpdb->postmeta . ".meta_value = 'completed' OR " . $wpdb->postmeta . ".meta_value = 'expired' OR " . $wpdb->postmeta . ".meta_value = 'trialling' OR " . $wpdb->postmeta . ".meta_value = 'failing') AND " . $wpdb->posts . ".post_type = 'wpi_invoice' GROUP BY " . $wpdb->posts . ".ID ORDER BY " . $wpdb->posts . ".ID ASC"; |
|
78 | 78 | |
79 | - $results = $wpdb->get_results( $query ); |
|
79 | + $results = $wpdb->get_results($query); |
|
80 | 80 | |
81 | - if ( empty( $results ) ) { |
|
81 | + if (empty($results)) { |
|
82 | 82 | return; |
83 | 83 | } |
84 | 84 | |
85 | - foreach ( $results as $row ) { |
|
86 | - $invoice = new WPInv_Invoice( $row->ID ); |
|
85 | + foreach ($results as $row) { |
|
86 | + $invoice = new WPInv_Invoice($row->ID); |
|
87 | 87 | |
88 | - if ( empty( $invoice->ID ) ) { |
|
88 | + if (empty($invoice->ID)) { |
|
89 | 89 | continue; |
90 | 90 | } |
91 | 91 | |
92 | - if ( $invoice->has_status( 'wpi-renewal' ) ) { |
|
92 | + if ($invoice->has_status('wpi-renewal')) { |
|
93 | 93 | continue; |
94 | 94 | } |
95 | 95 | |
96 | - $item = $invoice->get_recurring( true ); |
|
96 | + $item = $invoice->get_recurring(true); |
|
97 | 97 | |
98 | - if ( empty( $item ) ) { |
|
98 | + if (empty($item)) { |
|
99 | 99 | continue; |
100 | 100 | } |
101 | 101 | |
102 | 102 | $is_free_trial = $invoice->is_free_trial(); |
103 | - $profile_id = get_post_meta( $invoice->ID, '_wpinv_subscr_profile_id', true ); |
|
104 | - $subscription_status = get_post_meta( $invoice->ID, '_wpinv_subscr_status', true ); |
|
103 | + $profile_id = get_post_meta($invoice->ID, '_wpinv_subscr_profile_id', true); |
|
104 | + $subscription_status = get_post_meta($invoice->ID, '_wpinv_subscr_status', true); |
|
105 | 105 | $transaction_id = $invoice->get_transaction_id(); |
106 | 106 | |
107 | 107 | // Last invoice |
108 | - $query = "SELECT ID, post_date FROM ". $wpdb->posts ." WHERE post_type = 'wpi_invoice' AND post_parent = '" . $invoice->ID . "' ORDER BY ID DESC LIMIT 1"; |
|
109 | - $last_payment = $wpdb->get_row( $query ); |
|
108 | + $query = "SELECT ID, post_date FROM " . $wpdb->posts . " WHERE post_type = 'wpi_invoice' AND post_parent = '" . $invoice->ID . "' ORDER BY ID DESC LIMIT 1"; |
|
109 | + $last_payment = $wpdb->get_row($query); |
|
110 | 110 | |
111 | - if ( !empty( $last_payment ) ) { |
|
112 | - $invoice_date = $last_payment->post_date; |
|
111 | + if (!empty($last_payment)) { |
|
112 | + $invoice_date = $last_payment->post_date; |
|
113 | 113 | |
114 | - $meta_profile_id = get_post_meta( $last_payment->ID, '_wpinv_subscr_profile_id', true ); |
|
115 | - $meta_transaction_id = get_post_meta( $last_payment->ID, '_wpinv_transaction_id', true ); |
|
114 | + $meta_profile_id = get_post_meta($last_payment->ID, '_wpinv_subscr_profile_id', true); |
|
115 | + $meta_transaction_id = get_post_meta($last_payment->ID, '_wpinv_transaction_id', true); |
|
116 | 116 | |
117 | - if ( !empty( $meta_profile_id ) ) { |
|
118 | - $profile_id = $meta_profile_id; |
|
117 | + if (!empty($meta_profile_id)) { |
|
118 | + $profile_id = $meta_profile_id; |
|
119 | 119 | } |
120 | 120 | |
121 | - if ( !empty( $meta_transaction_id ) ) { |
|
122 | - $transaction_id = $meta_transaction_id; |
|
121 | + if (!empty($meta_transaction_id)) { |
|
122 | + $transaction_id = $meta_transaction_id; |
|
123 | 123 | } |
124 | 124 | } else { |
125 | - $invoice_date = $invoice->get_invoice_date( false ); |
|
125 | + $invoice_date = $invoice->get_invoice_date(false); |
|
126 | 126 | } |
127 | 127 | |
128 | - $profile_id = empty( $profile_id ) ? $invoice->ID : $profile_id; |
|
129 | - $status = empty( $subscription_status ) ? 'pending' : $subscription_status; |
|
128 | + $profile_id = empty($profile_id) ? $invoice->ID : $profile_id; |
|
129 | + $status = empty($subscription_status) ? 'pending' : $subscription_status; |
|
130 | 130 | |
131 | - $period = $item->get_recurring_period( true ); |
|
131 | + $period = $item->get_recurring_period(true); |
|
132 | 132 | $interval = $item->get_recurring_interval(); |
133 | - $bill_times = (int)$item->get_recurring_limit(); |
|
133 | + $bill_times = (int) $item->get_recurring_limit(); |
|
134 | 134 | $add_period = $interval . ' ' . $period; |
135 | 135 | $trial_period = ''; |
136 | 136 | |
137 | - if ( $invoice->is_free_trial() ) { |
|
138 | - $trial_period = $item->get_trial_period( true ); |
|
137 | + if ($invoice->is_free_trial()) { |
|
138 | + $trial_period = $item->get_trial_period(true); |
|
139 | 139 | $free_interval = $item->get_trial_interval(); |
140 | 140 | $trial_period = $free_interval . ' ' . $trial_period; |
141 | 141 | |
142 | - if ( empty( $last_payment ) ) { |
|
142 | + if (empty($last_payment)) { |
|
143 | 143 | $add_period = $trial_period; |
144 | 144 | } |
145 | 145 | } |
146 | 146 | |
147 | - $expiration = date_i18n( 'Y-m-d H:i:s', strtotime( '+' . $add_period . ' 23:59:59', strtotime( $invoice_date ) ) ); |
|
148 | - if ( strtotime( $expiration ) < strtotime( date_i18n( 'Y-m-d' ) ) ) { |
|
149 | - if ( $status == 'active' || $status == 'trialling' || $status == 'pending' ) { |
|
147 | + $expiration = date_i18n('Y-m-d H:i:s', strtotime('+' . $add_period . ' 23:59:59', strtotime($invoice_date))); |
|
148 | + if (strtotime($expiration) < strtotime(date_i18n('Y-m-d'))) { |
|
149 | + if ($status == 'active' || $status == 'trialling' || $status == 'pending') { |
|
150 | 150 | $status = 'expired'; |
151 | 151 | } |
152 | 152 | } |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | 'frequency' => $interval, |
160 | 160 | 'period' => $period, |
161 | 161 | 'initial_amount' => $invoice->get_total(), |
162 | - 'recurring_amount' => $invoice->get_recurring_details( 'total' ), |
|
162 | + 'recurring_amount' => $invoice->get_recurring_details('total'), |
|
163 | 163 | 'bill_times' => $bill_times, |
164 | 164 | 'created' => $invoice_date, |
165 | 165 | 'expiration' => $expiration, |
@@ -169,14 +169,14 @@ discard block |
||
169 | 169 | ); |
170 | 170 | |
171 | 171 | $subs_db = new WPInv_Subscriptions_DB; |
172 | - $subs = $subs_db->get_subscriptions( array( 'parent_payment_id' => $invoice->ID, 'number' => 1 ) ); |
|
173 | - $subscription = reset( $subs ); |
|
172 | + $subs = $subs_db->get_subscriptions(array('parent_payment_id' => $invoice->ID, 'number' => 1)); |
|
173 | + $subscription = reset($subs); |
|
174 | 174 | |
175 | - if ( empty( $subscription ) || $subscription->id <= 0 ) { |
|
175 | + if (empty($subscription) || $subscription->id <= 0) { |
|
176 | 176 | $subscription = new WPInv_Subscription(); |
177 | - $new_sub = $subscription->create( $args ); |
|
177 | + $new_sub = $subscription->create($args); |
|
178 | 178 | |
179 | - if ( !empty( $bill_times ) && $new_sub->get_times_billed() >= $bill_times && ( 'active' == $new_sub->status || 'trialling' == $new_sub->status ) ) { |
|
179 | + if (!empty($bill_times) && $new_sub->get_times_billed() >= $bill_times && ('active' == $new_sub->status || 'trialling' == $new_sub->status)) { |
|
180 | 180 | $new_sub->complete(); // Mark completed if all times billed |
181 | 181 | } |
182 | 182 | } |
@@ -186,20 +186,20 @@ discard block |
||
186 | 186 | function wpinv_update_new_email_settings() { |
187 | 187 | global $wpinv_options; |
188 | 188 | |
189 | - $current_options = get_option( 'wpinv_settings', array() ); |
|
189 | + $current_options = get_option('wpinv_settings', array()); |
|
190 | 190 | $options = array( |
191 | - 'email_new_invoice_body' => __( '<p>Hi Admin,</p><p>You have received payment invoice from {name}.</p>', 'invoicing' ), |
|
192 | - 'email_cancelled_invoice_body' => __( '<p>Hi Admin,</p><p>The invoice #{invoice_number} from {site_title} has been cancelled.</p>', 'invoicing' ), |
|
193 | - 'email_failed_invoice_body' => __( '<p>Hi Admin,</p><p>Payment for invoice #{invoice_number} from {site_title} has been failed.</p>', 'invoicing' ), |
|
194 | - 'email_onhold_invoice_body' => __( '<p>Hi {name},</p><p>Your invoice is on-hold until we confirm your payment has been received.</p>', 'invoicing' ), |
|
195 | - 'email_processing_invoice_body' => __( '<p>Hi {name},</p><p>Your invoice has been received at {site_title} and is now being processed.</p>', 'invoicing' ), |
|
196 | - 'email_refunded_invoice_body' => __( '<p>Hi {name},</p><p>Your invoice on {site_title} has been refunded.</p>', 'invoicing' ), |
|
197 | - 'email_user_invoice_body' => __( '<p>Hi {name},</p><p>An invoice has been created for you on {site_title}. To view / pay for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing' ), |
|
198 | - 'email_user_note_body' => __( '<p>Hi {name},</p><p>Following note has been added to your {invoice_label}:</p><blockquote class="wpinv-note">{customer_note}</blockquote>', 'invoicing' ), |
|
199 | - 'email_overdue_body' => __( '<p>Hi {full_name},</p><p>This is just a friendly reminder that your invoice <a href="{invoice_link}">#{invoice_number}</a> {is_was} due on {invoice_due_date}.</p><p>The total of this invoice is {invoice_total}</p><p>To view / pay now for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing' ), |
|
191 | + 'email_new_invoice_body' => __('<p>Hi Admin,</p><p>You have received payment invoice from {name}.</p>', 'invoicing'), |
|
192 | + 'email_cancelled_invoice_body' => __('<p>Hi Admin,</p><p>The invoice #{invoice_number} from {site_title} has been cancelled.</p>', 'invoicing'), |
|
193 | + 'email_failed_invoice_body' => __('<p>Hi Admin,</p><p>Payment for invoice #{invoice_number} from {site_title} has been failed.</p>', 'invoicing'), |
|
194 | + 'email_onhold_invoice_body' => __('<p>Hi {name},</p><p>Your invoice is on-hold until we confirm your payment has been received.</p>', 'invoicing'), |
|
195 | + 'email_processing_invoice_body' => __('<p>Hi {name},</p><p>Your invoice has been received at {site_title} and is now being processed.</p>', 'invoicing'), |
|
196 | + 'email_refunded_invoice_body' => __('<p>Hi {name},</p><p>Your invoice on {site_title} has been refunded.</p>', 'invoicing'), |
|
197 | + 'email_user_invoice_body' => __('<p>Hi {name},</p><p>An invoice has been created for you on {site_title}. To view / pay for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing'), |
|
198 | + 'email_user_note_body' => __('<p>Hi {name},</p><p>Following note has been added to your {invoice_label}:</p><blockquote class="wpinv-note">{customer_note}</blockquote>', 'invoicing'), |
|
199 | + 'email_overdue_body' => __('<p>Hi {full_name},</p><p>This is just a friendly reminder that your invoice <a href="{invoice_link}">#{invoice_number}</a> {is_was} due on {invoice_due_date}.</p><p>The total of this invoice is {invoice_total}</p><p>To view / pay now for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing'), |
|
200 | 200 | ); |
201 | 201 | |
202 | - foreach ($options as $option => $value){ |
|
202 | + foreach ($options as $option => $value) { |
|
203 | 203 | if (!isset($current_options[$option])) { |
204 | 204 | $current_options[$option] = $value; |
205 | 205 | } |
@@ -207,5 +207,5 @@ discard block |
||
207 | 207 | |
208 | 208 | $wpinv_options = $current_options; |
209 | 209 | |
210 | - update_option( 'wpinv_settings', $current_options ); |
|
210 | + update_option('wpinv_settings', $current_options); |
|
211 | 211 | } |
212 | 212 | \ No newline at end of file |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | // Exit if accessed directly |
4 | -if ( ! defined( 'ABSPATH' ) ) { |
|
4 | +if (!defined('ABSPATH')) { |
|
5 | 5 | exit; |
6 | 6 | } |
7 | 7 | |
@@ -38,15 +38,15 @@ discard block |
||
38 | 38 | * @since 1.0.0 |
39 | 39 | * @return void |
40 | 40 | */ |
41 | - function __construct( $_id_or_object = 0, $_by_profile_id = false ) { |
|
41 | + function __construct($_id_or_object = 0, $_by_profile_id = false) { |
|
42 | 42 | |
43 | 43 | $this->subs_db = new WPInv_Subscriptions_DB; |
44 | 44 | |
45 | - if( $_by_profile_id ) { |
|
45 | + if ($_by_profile_id) { |
|
46 | 46 | |
47 | - $_sub = $this->subs_db->get_by( 'profile_id', $_id_or_object ); |
|
47 | + $_sub = $this->subs_db->get_by('profile_id', $_id_or_object); |
|
48 | 48 | |
49 | - if( empty( $_sub ) ) { |
|
49 | + if (empty($_sub)) { |
|
50 | 50 | return false; |
51 | 51 | } |
52 | 52 | |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | |
55 | 55 | } |
56 | 56 | |
57 | - return $this->setup_subscription( $_id_or_object ); |
|
57 | + return $this->setup_subscription($_id_or_object); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -63,34 +63,34 @@ discard block |
||
63 | 63 | * @since 1.0.0 |
64 | 64 | * @return void |
65 | 65 | */ |
66 | - private function setup_subscription( $id_or_object = 0 ) { |
|
66 | + private function setup_subscription($id_or_object = 0) { |
|
67 | 67 | |
68 | - if( empty( $id_or_object ) ) { |
|
68 | + if (empty($id_or_object)) { |
|
69 | 69 | return false; |
70 | 70 | } |
71 | 71 | |
72 | - if( is_numeric( $id_or_object ) ) { |
|
72 | + if (is_numeric($id_or_object)) { |
|
73 | 73 | |
74 | - $sub = $this->subs_db->get( $id_or_object ); |
|
74 | + $sub = $this->subs_db->get($id_or_object); |
|
75 | 75 | |
76 | - } elseif( is_object( $id_or_object ) ) { |
|
76 | + } elseif (is_object($id_or_object)) { |
|
77 | 77 | |
78 | 78 | $sub = $id_or_object; |
79 | 79 | |
80 | 80 | } |
81 | 81 | |
82 | - if( empty( $sub ) ) { |
|
82 | + if (empty($sub)) { |
|
83 | 83 | return false; |
84 | 84 | } |
85 | 85 | |
86 | - foreach( $sub as $key => $value ) { |
|
86 | + foreach ($sub as $key => $value) { |
|
87 | 87 | $this->$key = $value; |
88 | 88 | } |
89 | 89 | |
90 | - $this->customer = get_userdata( $this->customer_id ); |
|
91 | - $this->gateway = wpinv_get_payment_gateway( $this->parent_payment_id ); |
|
90 | + $this->customer = get_userdata($this->customer_id); |
|
91 | + $this->gateway = wpinv_get_payment_gateway($this->parent_payment_id); |
|
92 | 92 | |
93 | - do_action( 'wpinv_recurring_setup_subscription', $this ); |
|
93 | + do_action('wpinv_recurring_setup_subscription', $this); |
|
94 | 94 | |
95 | 95 | return $this; |
96 | 96 | } |
@@ -100,15 +100,15 @@ discard block |
||
100 | 100 | * |
101 | 101 | * @since 1.0.0 |
102 | 102 | */ |
103 | - public function __get( $key ) { |
|
103 | + public function __get($key) { |
|
104 | 104 | |
105 | - if( method_exists( $this, 'get_' . $key ) ) { |
|
105 | + if (method_exists($this, 'get_' . $key)) { |
|
106 | 106 | |
107 | - return call_user_func( array( $this, 'get_' . $key ) ); |
|
107 | + return call_user_func(array($this, 'get_' . $key)); |
|
108 | 108 | |
109 | 109 | } else { |
110 | 110 | |
111 | - return new WP_Error( 'wpinv-subscription-invalid-property', sprintf( __( 'Can\'t get property %s', 'invoicing' ), $key ) ); |
|
111 | + return new WP_Error('wpinv-subscription-invalid-property', sprintf(__('Can\'t get property %s', 'invoicing'), $key)); |
|
112 | 112 | |
113 | 113 | } |
114 | 114 | |
@@ -121,9 +121,9 @@ discard block |
||
121 | 121 | * @param array $data Array of attributes for a subscription |
122 | 122 | * @return mixed false if data isn't passed and class not instantiated for creation |
123 | 123 | */ |
124 | - public function create( $data = array() ) { |
|
124 | + public function create($data = array()) { |
|
125 | 125 | |
126 | - if ( $this->id != 0 ) { |
|
126 | + if ($this->id != 0) { |
|
127 | 127 | return false; |
128 | 128 | } |
129 | 129 | |
@@ -142,11 +142,11 @@ discard block |
||
142 | 142 | 'profile_id' => '', |
143 | 143 | ); |
144 | 144 | |
145 | - $args = wp_parse_args( $data, $defaults ); |
|
145 | + $args = wp_parse_args($data, $defaults); |
|
146 | 146 | |
147 | - if( $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) { |
|
147 | + if ($args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) { |
|
148 | 148 | |
149 | - if( 'active' == $args['status'] || 'trialling' == $args['status'] ) { |
|
149 | + if ('active' == $args['status'] || 'trialling' == $args['status']) { |
|
150 | 150 | |
151 | 151 | // Force an active subscription to expired if expiration date is in the past |
152 | 152 | $args['status'] = 'expired'; |
@@ -154,13 +154,13 @@ discard block |
||
154 | 154 | } |
155 | 155 | } |
156 | 156 | |
157 | - do_action( 'wpinv_subscription_pre_create', $args ); |
|
157 | + do_action('wpinv_subscription_pre_create', $args); |
|
158 | 158 | |
159 | - $id = $this->subs_db->insert( $args, 'subscription' ); |
|
159 | + $id = $this->subs_db->insert($args, 'subscription'); |
|
160 | 160 | |
161 | - do_action( 'wpinv_subscription_post_create', $id, $args ); |
|
161 | + do_action('wpinv_subscription_post_create', $id, $args); |
|
162 | 162 | |
163 | - return $this->setup_subscription( $id ); |
|
163 | + return $this->setup_subscription($id); |
|
164 | 164 | |
165 | 165 | } |
166 | 166 | |
@@ -171,11 +171,11 @@ discard block |
||
171 | 171 | * @param array $args Array of fields to update |
172 | 172 | * @return bool |
173 | 173 | */ |
174 | - public function update( $args = array() ) { |
|
174 | + public function update($args = array()) { |
|
175 | 175 | |
176 | - $ret = $this->subs_db->update( $this->id, $args ); |
|
176 | + $ret = $this->subs_db->update($this->id, $args); |
|
177 | 177 | |
178 | - do_action( 'wpinv_recurring_update_subscription', $this->id, $args, $this ); |
|
178 | + do_action('wpinv_recurring_update_subscription', $this->id, $args, $this); |
|
179 | 179 | |
180 | 180 | return $ret; |
181 | 181 | |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | * @return bool |
189 | 189 | */ |
190 | 190 | public function delete() { |
191 | - return $this->subs_db->delete( $this->id ); |
|
191 | + return $this->subs_db->delete($this->id); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -208,14 +208,14 @@ discard block |
||
208 | 208 | * @return array |
209 | 209 | */ |
210 | 210 | public function get_child_payments() { |
211 | - $payments = get_posts( array( |
|
211 | + $payments = get_posts(array( |
|
212 | 212 | 'post_parent' => (int) $this->parent_payment_id, |
213 | 213 | 'posts_per_page' => '999', |
214 | - 'post_status' => array( 'publish', 'wpi-processing', 'wpi-renewal' ), |
|
214 | + 'post_status' => array('publish', 'wpi-processing', 'wpi-renewal'), |
|
215 | 215 | 'orderby' => 'ID', |
216 | 216 | 'order' => 'DESC', |
217 | 217 | 'post_type' => 'wpi_invoice' |
218 | - ) ); |
|
218 | + )); |
|
219 | 219 | |
220 | 220 | return $payments; |
221 | 221 | } |
@@ -228,9 +228,9 @@ discard block |
||
228 | 228 | */ |
229 | 229 | public function get_total_payments() { |
230 | 230 | $child_payments = $this->get_child_payments(); |
231 | - $total_payments = !empty( $child_payments ) ? count( $child_payments ) : 0; |
|
231 | + $total_payments = !empty($child_payments) ? count($child_payments) : 0; |
|
232 | 232 | |
233 | - if ( 'pending' != $this->status ) { |
|
233 | + if ('pending' != $this->status) { |
|
234 | 234 | $total_payments++; |
235 | 235 | } |
236 | 236 | |
@@ -244,9 +244,9 @@ discard block |
||
244 | 244 | * @return int |
245 | 245 | */ |
246 | 246 | public function get_times_billed() { |
247 | - $times_billed = (int)$this->get_total_payments(); |
|
247 | + $times_billed = (int) $this->get_total_payments(); |
|
248 | 248 | |
249 | - if ( ! empty( $this->trial_period ) && $times_billed > 0 ) { |
|
249 | + if (!empty($this->trial_period) && $times_billed > 0) { |
|
250 | 250 | $times_billed--; |
251 | 251 | } |
252 | 252 | |
@@ -260,51 +260,51 @@ discard block |
||
260 | 260 | * @param array $args Array of values for the payment, including amount and transaction ID |
261 | 261 | * @return bool |
262 | 262 | */ |
263 | - public function add_payment( $args = array() ) { |
|
264 | - if ( ! $this->parent_payment_id ) { |
|
263 | + public function add_payment($args = array()) { |
|
264 | + if (!$this->parent_payment_id) { |
|
265 | 265 | return false; |
266 | 266 | } |
267 | 267 | |
268 | - $args = wp_parse_args( $args, array( |
|
268 | + $args = wp_parse_args($args, array( |
|
269 | 269 | 'amount' => '', |
270 | 270 | 'transaction_id' => '', |
271 | 271 | 'gateway' => '' |
272 | - ) ); |
|
272 | + )); |
|
273 | 273 | |
274 | - if ( empty( $args['transaction_id'] ) || $this->payment_exists( $args['transaction_id'] ) ) { |
|
274 | + if (empty($args['transaction_id']) || $this->payment_exists($args['transaction_id'])) { |
|
275 | 275 | return false; |
276 | 276 | } |
277 | 277 | |
278 | - $parent_invoice = wpinv_get_invoice( $this->parent_payment_id ); |
|
279 | - if ( empty( $parent_invoice->ID ) ) { |
|
278 | + $parent_invoice = wpinv_get_invoice($this->parent_payment_id); |
|
279 | + if (empty($parent_invoice->ID)) { |
|
280 | 280 | return false; |
281 | 281 | } |
282 | 282 | |
283 | 283 | $invoice = new WPInv_Invoice(); |
284 | - $invoice->set( 'post_type', 'wpi_invoice' ); |
|
285 | - $invoice->set( 'parent_invoice', $this->parent_payment_id ); |
|
286 | - $invoice->set( 'currency', $parent_invoice->get_currency() ); |
|
287 | - $invoice->set( 'transaction_id', $args['transaction_id'] ); |
|
288 | - $invoice->set( 'key', $parent_invoice->generate_key() ); |
|
289 | - $invoice->set( 'ip', $parent_invoice->ip ); |
|
290 | - $invoice->set( 'user_id', $parent_invoice->get_user_id() ); |
|
291 | - $invoice->set( 'first_name', $parent_invoice->get_first_name() ); |
|
292 | - $invoice->set( 'last_name', $parent_invoice->get_last_name() ); |
|
293 | - $invoice->set( 'phone', $parent_invoice->phone ); |
|
294 | - $invoice->set( 'address', $parent_invoice->address ); |
|
295 | - $invoice->set( 'city', $parent_invoice->city ); |
|
296 | - $invoice->set( 'country', $parent_invoice->country ); |
|
297 | - $invoice->set( 'state', $parent_invoice->state ); |
|
298 | - $invoice->set( 'zip', $parent_invoice->zip ); |
|
299 | - $invoice->set( 'company', $parent_invoice->company ); |
|
300 | - $invoice->set( 'vat_number', $parent_invoice->vat_number ); |
|
301 | - $invoice->set( 'vat_rate', $parent_invoice->vat_rate ); |
|
302 | - $invoice->set( 'adddress_confirmed', $parent_invoice->adddress_confirmed ); |
|
303 | - |
|
304 | - if ( empty( $args['gateway'] ) ) { |
|
305 | - $invoice->set( 'gateway', $parent_invoice->get_gateway() ); |
|
284 | + $invoice->set('post_type', 'wpi_invoice'); |
|
285 | + $invoice->set('parent_invoice', $this->parent_payment_id); |
|
286 | + $invoice->set('currency', $parent_invoice->get_currency()); |
|
287 | + $invoice->set('transaction_id', $args['transaction_id']); |
|
288 | + $invoice->set('key', $parent_invoice->generate_key()); |
|
289 | + $invoice->set('ip', $parent_invoice->ip); |
|
290 | + $invoice->set('user_id', $parent_invoice->get_user_id()); |
|
291 | + $invoice->set('first_name', $parent_invoice->get_first_name()); |
|
292 | + $invoice->set('last_name', $parent_invoice->get_last_name()); |
|
293 | + $invoice->set('phone', $parent_invoice->phone); |
|
294 | + $invoice->set('address', $parent_invoice->address); |
|
295 | + $invoice->set('city', $parent_invoice->city); |
|
296 | + $invoice->set('country', $parent_invoice->country); |
|
297 | + $invoice->set('state', $parent_invoice->state); |
|
298 | + $invoice->set('zip', $parent_invoice->zip); |
|
299 | + $invoice->set('company', $parent_invoice->company); |
|
300 | + $invoice->set('vat_number', $parent_invoice->vat_number); |
|
301 | + $invoice->set('vat_rate', $parent_invoice->vat_rate); |
|
302 | + $invoice->set('adddress_confirmed', $parent_invoice->adddress_confirmed); |
|
303 | + |
|
304 | + if (empty($args['gateway'])) { |
|
305 | + $invoice->set('gateway', $parent_invoice->get_gateway()); |
|
306 | 306 | } else { |
307 | - $invoice->set( 'gateway', $args['gateway'] ); |
|
307 | + $invoice->set('gateway', $args['gateway']); |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | $recurring_details = $parent_invoice->get_recurring_details(); |
@@ -312,11 +312,11 @@ discard block |
||
312 | 312 | // increase the earnings for each item in the subscription |
313 | 313 | $items = $recurring_details['cart_details']; |
314 | 314 | |
315 | - if ( $items ) { |
|
315 | + if ($items) { |
|
316 | 316 | $add_items = array(); |
317 | 317 | $cart_details = array(); |
318 | 318 | |
319 | - foreach ( $items as $item ) { |
|
319 | + foreach ($items as $item) { |
|
320 | 320 | $add_item = array(); |
321 | 321 | $add_item['id'] = $item['id']; |
322 | 322 | $add_item['quantity'] = $item['quantity']; |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | break; |
327 | 327 | } |
328 | 328 | |
329 | - $invoice->set( 'items', $add_items ); |
|
329 | + $invoice->set('items', $add_items); |
|
330 | 330 | $invoice->cart_details = $cart_details; |
331 | 331 | } |
332 | 332 | |
@@ -336,29 +336,29 @@ discard block |
||
336 | 336 | $tax = $recurring_details['tax']; |
337 | 337 | $discount = $recurring_details['discount']; |
338 | 338 | |
339 | - if ( $discount > 0 ) { |
|
340 | - $invoice->set( 'discount_code', $parent_invoice->discount_code ); |
|
339 | + if ($discount > 0) { |
|
340 | + $invoice->set('discount_code', $parent_invoice->discount_code); |
|
341 | 341 | } |
342 | 342 | |
343 | - $invoice->subtotal = wpinv_round_amount( $subtotal ); |
|
344 | - $invoice->tax = wpinv_round_amount( $tax ); |
|
345 | - $invoice->discount = wpinv_round_amount( $discount ); |
|
346 | - $invoice->total = wpinv_round_amount( $total ); |
|
343 | + $invoice->subtotal = wpinv_round_amount($subtotal); |
|
344 | + $invoice->tax = wpinv_round_amount($tax); |
|
345 | + $invoice->discount = wpinv_round_amount($discount); |
|
346 | + $invoice->total = wpinv_round_amount($total); |
|
347 | 347 | |
348 | - $invoice = apply_filters( 'wpinv_subscription_add_payment_save', $invoice, $this, $args ); |
|
348 | + $invoice = apply_filters('wpinv_subscription_add_payment_save', $invoice, $this, $args); |
|
349 | 349 | |
350 | 350 | $invoice->save(); |
351 | - $invoice->update_meta( '_wpinv_subscription_id', $this->id ); |
|
351 | + $invoice->update_meta('_wpinv_subscription_id', $this->id); |
|
352 | 352 | |
353 | - if ( !empty( $invoice->ID ) ) { |
|
354 | - wpinv_update_payment_status( $invoice->ID, 'publish' ); |
|
353 | + if (!empty($invoice->ID)) { |
|
354 | + wpinv_update_payment_status($invoice->ID, 'publish'); |
|
355 | 355 | sleep(1); |
356 | - wpinv_update_payment_status( $invoice->ID, 'wpi-renewal' ); |
|
356 | + wpinv_update_payment_status($invoice->ID, 'wpi-renewal'); |
|
357 | 357 | |
358 | - $invoice = wpinv_get_invoice( $invoice->ID ); |
|
358 | + $invoice = wpinv_get_invoice($invoice->ID); |
|
359 | 359 | |
360 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
361 | - do_action( 'wpinv_recurring_record_payment', $invoice->ID, $this->parent_payment_id, $args['amount'], $args['transaction_id'] ); |
|
360 | + do_action('wpinv_recurring_add_subscription_payment', $invoice, $this); |
|
361 | + do_action('wpinv_recurring_record_payment', $invoice->ID, $this->parent_payment_id, $args['amount'], $args['transaction_id']); |
|
362 | 362 | |
363 | 363 | return $invoice->ID; |
364 | 364 | } |
@@ -374,12 +374,12 @@ discard block |
||
374 | 374 | */ |
375 | 375 | public function get_transaction_id() { |
376 | 376 | |
377 | - if( empty( $this->transaction_id ) ) { |
|
377 | + if (empty($this->transaction_id)) { |
|
378 | 378 | |
379 | - $txn_id = wpinv_get_payment_transaction_id( $this->parent_payment_id ); |
|
379 | + $txn_id = wpinv_get_payment_transaction_id($this->parent_payment_id); |
|
380 | 380 | |
381 | - if( ! empty( $txn_id ) && (int) $this->parent_payment_id !== (int) $txn_id ) { |
|
382 | - $this->set_transaction_id( $txn_id ); |
|
381 | + if (!empty($txn_id) && (int) $this->parent_payment_id !== (int) $txn_id) { |
|
382 | + $this->set_transaction_id($txn_id); |
|
383 | 383 | } |
384 | 384 | |
385 | 385 | } |
@@ -394,8 +394,8 @@ discard block |
||
394 | 394 | * @since 1.0.0.4 |
395 | 395 | * @return bool |
396 | 396 | */ |
397 | - public function set_transaction_id( $txn_id = '' ) { |
|
398 | - $this->update( array( 'transaction_id' => $txn_id ) ); |
|
397 | + public function set_transaction_id($txn_id = '') { |
|
398 | + $this->update(array('transaction_id' => $txn_id)); |
|
399 | 399 | $this->transaction_id = $txn_id; |
400 | 400 | } |
401 | 401 | |
@@ -411,35 +411,35 @@ discard block |
||
411 | 411 | |
412 | 412 | |
413 | 413 | // Determine what date to use as the start for the new expiration calculation |
414 | - if( $expires > current_time( 'timestamp' ) && $this->is_active() ) { |
|
414 | + if ($expires > current_time('timestamp') && $this->is_active()) { |
|
415 | 415 | |
416 | - $base_date = $expires; |
|
416 | + $base_date = $expires; |
|
417 | 417 | |
418 | 418 | } else { |
419 | 419 | |
420 | - $base_date = current_time( 'timestamp' ); |
|
420 | + $base_date = current_time('timestamp'); |
|
421 | 421 | |
422 | 422 | } |
423 | 423 | |
424 | - $last_day = wpinv_cal_days_in_month( CAL_GREGORIAN, date( 'n', $base_date ), date( 'Y', $base_date ) ); |
|
424 | + $last_day = wpinv_cal_days_in_month(CAL_GREGORIAN, date('n', $base_date), date('Y', $base_date)); |
|
425 | 425 | |
426 | 426 | |
427 | 427 | $frequency = isset($this->frequency) ? $this->frequency : 1; |
428 | - $expiration = date( 'Y-m-d H:i:s', strtotime( '+' . $frequency . ' ' . $this->period . ' 23:59:59', $base_date ) ); |
|
428 | + $expiration = date('Y-m-d H:i:s', strtotime('+' . $frequency . ' ' . $this->period . ' 23:59:59', $base_date)); |
|
429 | 429 | |
430 | - if( date( 'j', $base_date ) == $last_day && 'day' != $this->period ) { |
|
431 | - $expiration = date( 'Y-m-d H:i:s', strtotime( $expiration . ' +2 days' ) ); |
|
430 | + if (date('j', $base_date) == $last_day && 'day' != $this->period) { |
|
431 | + $expiration = date('Y-m-d H:i:s', strtotime($expiration . ' +2 days')); |
|
432 | 432 | } |
433 | 433 | |
434 | - $expiration = apply_filters( 'wpinv_subscription_renewal_expiration', $expiration, $this->id, $this ); |
|
434 | + $expiration = apply_filters('wpinv_subscription_renewal_expiration', $expiration, $this->id, $this); |
|
435 | 435 | |
436 | - do_action( 'wpinv_subscription_pre_renew', $this->id, $expiration, $this ); |
|
436 | + do_action('wpinv_subscription_pre_renew', $this->id, $expiration, $this); |
|
437 | 437 | |
438 | 438 | $this->status = 'active'; |
439 | 439 | $times_billed = $this->get_times_billed(); |
440 | 440 | |
441 | 441 | // Complete subscription if applicable |
442 | - if ( $this->bill_times > 0 && $times_billed >= $this->bill_times ) { |
|
442 | + if ($this->bill_times > 0 && $times_billed >= $this->bill_times) { |
|
443 | 443 | $this->complete(); |
444 | 444 | $this->status = 'completed'; |
445 | 445 | } |
@@ -449,10 +449,10 @@ discard block |
||
449 | 449 | 'status' => $this->status, |
450 | 450 | ); |
451 | 451 | |
452 | - $this->subs_db->update( $this->id, $args ); |
|
452 | + $this->subs_db->update($this->id, $args); |
|
453 | 453 | |
454 | - do_action( 'wpinv_subscription_post_renew', $this->id, $expiration, $this ); |
|
455 | - do_action( 'wpinv_recurring_set_subscription_status', $this->id, $this->status, $this ); |
|
454 | + do_action('wpinv_subscription_post_renew', $this->id, $expiration, $this); |
|
455 | + do_action('wpinv_recurring_set_subscription_status', $this->id, $this->status, $this); |
|
456 | 456 | |
457 | 457 | } |
458 | 458 | |
@@ -467,7 +467,7 @@ discard block |
||
467 | 467 | public function complete() { |
468 | 468 | |
469 | 469 | // Only mark a subscription as complete if it's not already cancelled. |
470 | - if ( 'cancelled' === $this->status ) { |
|
470 | + if ('cancelled' === $this->status) { |
|
471 | 471 | return; |
472 | 472 | } |
473 | 473 | |
@@ -475,11 +475,11 @@ discard block |
||
475 | 475 | 'status' => 'completed' |
476 | 476 | ); |
477 | 477 | |
478 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
478 | + if ($this->subs_db->update($this->id, $args)) { |
|
479 | 479 | |
480 | 480 | $this->status = 'completed'; |
481 | 481 | |
482 | - do_action( 'wpinv_subscription_completed', $this->id, $this ); |
|
482 | + do_action('wpinv_subscription_completed', $this->id, $this); |
|
483 | 483 | |
484 | 484 | } |
485 | 485 | |
@@ -494,15 +494,15 @@ discard block |
||
494 | 494 | * @param $check_expiration bool True if expiration date should be checked with merchant processor before expiring |
495 | 495 | * @return void |
496 | 496 | */ |
497 | - public function expire( $check_expiration = false ) { |
|
497 | + public function expire($check_expiration = false) { |
|
498 | 498 | |
499 | 499 | $expiration = $this->expiration; |
500 | 500 | |
501 | - if( $check_expiration ) { |
|
501 | + if ($check_expiration) { |
|
502 | 502 | |
503 | 503 | // check_expiration() updates $this->expiration so compare to $expiration above |
504 | 504 | |
505 | - if( $expiration < $this->get_expiration() && current_time( 'timestamp' ) < $this->get_expiration_time() ) { |
|
505 | + if ($expiration < $this->get_expiration() && current_time('timestamp') < $this->get_expiration_time()) { |
|
506 | 506 | |
507 | 507 | return false; // Do not mark as expired since real expiration date is in the future |
508 | 508 | } |
@@ -513,11 +513,11 @@ discard block |
||
513 | 513 | 'status' => 'expired' |
514 | 514 | ); |
515 | 515 | |
516 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
516 | + if ($this->subs_db->update($this->id, $args)) { |
|
517 | 517 | |
518 | 518 | $this->status = 'expired'; |
519 | 519 | |
520 | - do_action( 'wpinv_subscription_expired', $this->id, $this ); |
|
520 | + do_action('wpinv_subscription_expired', $this->id, $this); |
|
521 | 521 | |
522 | 522 | } |
523 | 523 | |
@@ -535,11 +535,11 @@ discard block |
||
535 | 535 | 'status' => 'failing' |
536 | 536 | ); |
537 | 537 | |
538 | - if( $this->subs_db->update( $this->id, $args ) ) { |
|
538 | + if ($this->subs_db->update($this->id, $args)) { |
|
539 | 539 | |
540 | 540 | $this->status = 'failing'; |
541 | 541 | |
542 | - do_action( 'wpinv_subscription_failing', $this->id, $this ); |
|
542 | + do_action('wpinv_subscription_failing', $this->id, $this); |
|
543 | 543 | |
544 | 544 | |
545 | 545 | } |
@@ -553,7 +553,7 @@ discard block |
||
553 | 553 | * @return void |
554 | 554 | */ |
555 | 555 | public function cancel() { |
556 | - if ( 'cancelled' === $this->status ) { |
|
556 | + if ('cancelled' === $this->status) { |
|
557 | 557 | return; // Already cancelled |
558 | 558 | } |
559 | 559 | |
@@ -561,20 +561,20 @@ discard block |
||
561 | 561 | 'status' => 'cancelled' |
562 | 562 | ); |
563 | 563 | |
564 | - if ( $this->subs_db->update( $this->id, $args ) ) { |
|
565 | - if ( is_user_logged_in() ) { |
|
566 | - $userdata = get_userdata( get_current_user_id() ); |
|
564 | + if ($this->subs_db->update($this->id, $args)) { |
|
565 | + if (is_user_logged_in()) { |
|
566 | + $userdata = get_userdata(get_current_user_id()); |
|
567 | 567 | $user = $userdata->display_name; |
568 | 568 | } else { |
569 | - $user = __( 'gateway', 'invoicing' ); |
|
569 | + $user = __('gateway', 'invoicing'); |
|
570 | 570 | } |
571 | 571 | |
572 | - $note = sprintf( __( 'Subscription has been cancelled by %s', 'invoicing' ), $user ); |
|
573 | - wpinv_insert_payment_note( $this->parent_payment_id, $note, '', '', true ); |
|
572 | + $note = sprintf(__('Subscription has been cancelled by %s', 'invoicing'), $user); |
|
573 | + wpinv_insert_payment_note($this->parent_payment_id, $note, '', '', true); |
|
574 | 574 | |
575 | 575 | $this->status = 'cancelled'; |
576 | 576 | |
577 | - do_action( 'wpinv_subscription_cancelled', $this->id, $this ); |
|
577 | + do_action('wpinv_subscription_cancelled', $this->id, $this); |
|
578 | 578 | } |
579 | 579 | } |
580 | 580 | |
@@ -589,10 +589,10 @@ discard block |
||
589 | 589 | */ |
590 | 590 | public function can_cancel() { |
591 | 591 | $ret = false; |
592 | - if( $this->gateway === 'manual' || in_array( $this->status, $this->get_cancellable_statuses() ) ) { |
|
592 | + if ($this->gateway === 'manual' || in_array($this->status, $this->get_cancellable_statuses())) { |
|
593 | 593 | $ret = true; |
594 | 594 | } |
595 | - return apply_filters( 'wpinv_subscription_can_cancel', $ret, $this ); |
|
595 | + return apply_filters('wpinv_subscription_can_cancel', $ret, $this); |
|
596 | 596 | } |
597 | 597 | |
598 | 598 | /** |
@@ -603,7 +603,7 @@ discard block |
||
603 | 603 | * @return array |
604 | 604 | */ |
605 | 605 | public function get_cancellable_statuses() { |
606 | - return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) ); |
|
606 | + return apply_filters('wpinv_recurring_cancellable_statuses', array('active', 'trialling', 'failing')); |
|
607 | 607 | } |
608 | 608 | |
609 | 609 | /** |
@@ -614,9 +614,9 @@ discard block |
||
614 | 614 | */ |
615 | 615 | public function get_cancel_url() { |
616 | 616 | |
617 | - $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'cancel_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-cancel' ); |
|
617 | + $url = wp_nonce_url(add_query_arg(array('wpinv_action' => 'cancel_subscription', 'sub_id' => $this->id)), 'wpinv-recurring-cancel'); |
|
618 | 618 | |
619 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
619 | + return apply_filters('wpinv_subscription_cancel_url', $url, $this); |
|
620 | 620 | } |
621 | 621 | |
622 | 622 | /** |
@@ -630,7 +630,7 @@ discard block |
||
630 | 630 | */ |
631 | 631 | public function can_renew() { |
632 | 632 | |
633 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
633 | + return apply_filters('wpinv_subscription_can_renew', true, $this); |
|
634 | 634 | } |
635 | 635 | |
636 | 636 | /** |
@@ -641,9 +641,9 @@ discard block |
||
641 | 641 | */ |
642 | 642 | public function get_renew_url() { |
643 | 643 | |
644 | - $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'renew_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-renew' ); |
|
644 | + $url = wp_nonce_url(add_query_arg(array('wpinv_action' => 'renew_subscription', 'sub_id' => $this->id)), 'wpinv-recurring-renew'); |
|
645 | 645 | |
646 | - return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
646 | + return apply_filters('wpinv_subscription_renew_url', $url, $this); |
|
647 | 647 | } |
648 | 648 | |
649 | 649 | /** |
@@ -653,7 +653,7 @@ discard block |
||
653 | 653 | * @return bool |
654 | 654 | */ |
655 | 655 | public function can_update() { |
656 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
656 | + return apply_filters('wpinv_subscription_can_update', false, $this); |
|
657 | 657 | } |
658 | 658 | |
659 | 659 | /** |
@@ -664,9 +664,9 @@ discard block |
||
664 | 664 | */ |
665 | 665 | public function get_update_url() { |
666 | 666 | |
667 | - $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->id ) ); |
|
667 | + $url = add_query_arg(array('action' => 'update', 'subscription_id' => $this->id)); |
|
668 | 668 | |
669 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
669 | + return apply_filters('wpinv_subscription_update_url', $url, $this); |
|
670 | 670 | } |
671 | 671 | |
672 | 672 | /** |
@@ -679,11 +679,11 @@ discard block |
||
679 | 679 | |
680 | 680 | $ret = false; |
681 | 681 | |
682 | - if( ! $this->is_expired() && ( $this->status == 'active' || $this->status == 'cancelled' || $this->status == 'trialling' ) ) { |
|
682 | + if (!$this->is_expired() && ($this->status == 'active' || $this->status == 'cancelled' || $this->status == 'trialling')) { |
|
683 | 683 | $ret = true; |
684 | 684 | } |
685 | 685 | |
686 | - return apply_filters( 'wpinv_subscription_is_active', $ret, $this->id, $this ); |
|
686 | + return apply_filters('wpinv_subscription_is_active', $ret, $this->id, $this); |
|
687 | 687 | |
688 | 688 | } |
689 | 689 | |
@@ -697,26 +697,26 @@ discard block |
||
697 | 697 | |
698 | 698 | $ret = false; |
699 | 699 | |
700 | - if ( $this->status == 'expired' ) { |
|
700 | + if ($this->status == 'expired') { |
|
701 | 701 | |
702 | 702 | $ret = true; |
703 | 703 | |
704 | - } elseif( 'active' === $this->status || 'cancelled' === $this->status || $this->status == 'trialling' ) { |
|
704 | + } elseif ('active' === $this->status || 'cancelled' === $this->status || $this->status == 'trialling') { |
|
705 | 705 | |
706 | 706 | $ret = false; |
707 | 707 | $expiration = $this->get_expiration_time(); |
708 | 708 | |
709 | - if( $expiration && strtotime( 'NOW', current_time( 'timestamp' ) ) > $expiration ) { |
|
709 | + if ($expiration && strtotime('NOW', current_time('timestamp')) > $expiration) { |
|
710 | 710 | $ret = true; |
711 | 711 | |
712 | - if ( 'active' === $this->status || $this->status == 'trialling' ) { |
|
712 | + if ('active' === $this->status || $this->status == 'trialling') { |
|
713 | 713 | $this->expire(); |
714 | 714 | } |
715 | 715 | } |
716 | 716 | |
717 | 717 | } |
718 | 718 | |
719 | - return apply_filters( 'wpinv_subscription_is_expired', $ret, $this->id, $this ); |
|
719 | + return apply_filters('wpinv_subscription_is_expired', $ret, $this->id, $this); |
|
720 | 720 | |
721 | 721 | } |
722 | 722 | |
@@ -737,7 +737,7 @@ discard block |
||
737 | 737 | * @return int |
738 | 738 | */ |
739 | 739 | public function get_expiration_time() { |
740 | - return strtotime( $this->expiration, current_time( 'timestamp' ) ); |
|
740 | + return strtotime($this->expiration, current_time('timestamp')); |
|
741 | 741 | } |
742 | 742 | |
743 | 743 | /** |
@@ -761,37 +761,37 @@ discard block |
||
761 | 761 | */ |
762 | 762 | public function get_status_label() { |
763 | 763 | |
764 | - switch( $this->get_status() ) { |
|
764 | + switch ($this->get_status()) { |
|
765 | 765 | case 'active' : |
766 | - $status = __( 'Active', 'invoicing' ); |
|
766 | + $status = __('Active', 'invoicing'); |
|
767 | 767 | break; |
768 | 768 | |
769 | 769 | case 'cancelled' : |
770 | - $status = __( 'Cancelled', 'invoicing' ); |
|
770 | + $status = __('Cancelled', 'invoicing'); |
|
771 | 771 | break; |
772 | 772 | |
773 | 773 | case 'expired' : |
774 | - $status = __( 'Expired', 'invoicing' ); |
|
774 | + $status = __('Expired', 'invoicing'); |
|
775 | 775 | break; |
776 | 776 | |
777 | 777 | case 'pending' : |
778 | - $status = __( 'Pending', 'invoicing' ); |
|
778 | + $status = __('Pending', 'invoicing'); |
|
779 | 779 | break; |
780 | 780 | |
781 | 781 | case 'failing' : |
782 | - $status = __( 'Failing', 'invoicing' ); |
|
782 | + $status = __('Failing', 'invoicing'); |
|
783 | 783 | break; |
784 | 784 | |
785 | 785 | case 'trialling' : |
786 | - $status = __( 'Trialling', 'invoicing' ); |
|
786 | + $status = __('Trialling', 'invoicing'); |
|
787 | 787 | break; |
788 | 788 | |
789 | 789 | case 'completed' : |
790 | - $status = __( 'Completed', 'invoicing' ); |
|
790 | + $status = __('Completed', 'invoicing'); |
|
791 | 791 | break; |
792 | 792 | |
793 | 793 | default: |
794 | - $status = ucfirst( $this->get_status() ); |
|
794 | + $status = ucfirst($this->get_status()); |
|
795 | 795 | break; |
796 | 796 | } |
797 | 797 | |
@@ -806,51 +806,51 @@ discard block |
||
806 | 806 | */ |
807 | 807 | public function get_status_label_html() { |
808 | 808 | |
809 | - switch( $get_status = $this->get_status() ) { |
|
809 | + switch ($get_status = $this->get_status()) { |
|
810 | 810 | case 'active' : |
811 | - $status = __( 'Active', 'invoicing' ); |
|
811 | + $status = __('Active', 'invoicing'); |
|
812 | 812 | $class = 'label-info'; |
813 | 813 | break; |
814 | 814 | |
815 | 815 | case 'cancelled' : |
816 | - $status = __( 'Cancelled', 'invoicing' ); |
|
816 | + $status = __('Cancelled', 'invoicing'); |
|
817 | 817 | $class = 'label-danger'; |
818 | 818 | break; |
819 | 819 | |
820 | 820 | case 'expired' : |
821 | - $status = __( 'Expired', 'invoicing' ); |
|
821 | + $status = __('Expired', 'invoicing'); |
|
822 | 822 | $class = 'label-default'; |
823 | 823 | break; |
824 | 824 | |
825 | 825 | case 'pending' : |
826 | - $status = __( 'Pending', 'invoicing' ); |
|
826 | + $status = __('Pending', 'invoicing'); |
|
827 | 827 | $class = 'label-primary'; |
828 | 828 | break; |
829 | 829 | |
830 | 830 | case 'failing' : |
831 | - $status = __( 'Failing', 'invoicing' ); |
|
831 | + $status = __('Failing', 'invoicing'); |
|
832 | 832 | $class = 'label-danger'; |
833 | 833 | break; |
834 | 834 | |
835 | 835 | case 'trialling' : |
836 | - $status = __( 'Trialling', 'invoicing' ); |
|
836 | + $status = __('Trialling', 'invoicing'); |
|
837 | 837 | $class = 'label-info'; |
838 | 838 | break; |
839 | 839 | |
840 | 840 | case 'completed' : |
841 | - $status = __( 'Completed', 'invoicing' ); |
|
841 | + $status = __('Completed', 'invoicing'); |
|
842 | 842 | $class = 'label-success'; |
843 | 843 | break; |
844 | 844 | |
845 | 845 | default: |
846 | - $status = ucfirst( $this->get_status() ); |
|
846 | + $status = ucfirst($this->get_status()); |
|
847 | 847 | $class = 'label-default'; |
848 | 848 | break; |
849 | 849 | } |
850 | 850 | |
851 | 851 | $label = '<span class="sub-status label label-sub-' . $get_status . ' ' . $class . '">' . $status . '</span>'; |
852 | 852 | |
853 | - return apply_filters( 'wpinv_subscription_status_label_html', $label, $get_status, $status ); |
|
853 | + return apply_filters('wpinv_subscription_status_label_html', $label, $get_status, $status); |
|
854 | 854 | } |
855 | 855 | |
856 | 856 | /** |
@@ -860,18 +860,18 @@ discard block |
||
860 | 860 | * @param string $txn_id The transaction ID from the merchant processor |
861 | 861 | * @return bool |
862 | 862 | */ |
863 | - public function payment_exists( $txn_id = '' ) { |
|
863 | + public function payment_exists($txn_id = '') { |
|
864 | 864 | global $wpdb; |
865 | 865 | |
866 | - if ( empty( $txn_id ) ) { |
|
866 | + if (empty($txn_id)) { |
|
867 | 867 | return false; |
868 | 868 | } |
869 | 869 | |
870 | - $txn_id = esc_sql( $txn_id ); |
|
870 | + $txn_id = esc_sql($txn_id); |
|
871 | 871 | |
872 | - $purchase = $wpdb->get_var( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1" ); |
|
872 | + $purchase = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1"); |
|
873 | 873 | |
874 | - if ( $purchase != null ) { |
|
874 | + if ($purchase != null) { |
|
875 | 875 | return true; |
876 | 876 | } |
877 | 877 |