@@ -7,109 +7,109 @@ discard block |
||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | // MUST have WordPress. |
| 10 | -if ( !defined( 'WPINC' ) ) { |
|
| 11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
| 10 | +if (!defined('WPINC')) { |
|
| 11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | -if ( !is_admin() ) { |
|
| 15 | - add_filter( 'template_include', 'wpinv_template', 10, 1 ); |
|
| 16 | - add_action( 'wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar' ); |
|
| 17 | - add_action( 'wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions' ); |
|
| 18 | - add_action( 'wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions' ); |
|
| 14 | +if (!is_admin()) { |
|
| 15 | + add_filter('template_include', 'wpinv_template', 10, 1); |
|
| 16 | + add_action('wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar'); |
|
| 17 | + add_action('wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions'); |
|
| 18 | + add_action('wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions'); |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | function wpinv_template_path() { |
| 22 | - return apply_filters( 'wpinv_template_path', 'invoicing/' ); |
|
| 22 | + return apply_filters('wpinv_template_path', 'invoicing/'); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | -function wpinv_post_class( $classes, $class, $post_id ) { |
|
| 25 | +function wpinv_post_class($classes, $class, $post_id) { |
|
| 26 | 26 | global $pagenow, $typenow; |
| 27 | 27 | |
| 28 | - if ( $pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type( $post_id ) == $typenow && get_post_meta( $post_id, '_wpinv_type', true ) == 'package' ) { |
|
| 28 | + if ($pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type($post_id) == $typenow && get_post_meta($post_id, '_wpinv_type', true) == 'package') { |
|
| 29 | 29 | $classes[] = 'wpi-gd-package'; |
| 30 | 30 | } |
| 31 | 31 | return $classes; |
| 32 | 32 | } |
| 33 | -add_filter( 'post_class', 'wpinv_post_class', 10, 3 ); |
|
| 33 | +add_filter('post_class', 'wpinv_post_class', 10, 3); |
|
| 34 | 34 | |
| 35 | -function wpinv_display_invoice_top_bar( $invoice ) { |
|
| 36 | - if ( empty( $invoice ) ) { |
|
| 35 | +function wpinv_display_invoice_top_bar($invoice) { |
|
| 36 | + if (empty($invoice)) { |
|
| 37 | 37 | return; |
| 38 | 38 | } |
| 39 | 39 | ?> |
| 40 | 40 | <div class="row wpinv-top-bar no-print"> |
| 41 | 41 | <div class="container"> |
| 42 | 42 | <div class="col-xs-6"> |
| 43 | - <?php do_action( 'wpinv_invoice_top_bar_left', $invoice );?> |
|
| 43 | + <?php do_action('wpinv_invoice_top_bar_left', $invoice); ?> |
|
| 44 | 44 | </div> |
| 45 | 45 | <div class="col-xs-6 text-right"> |
| 46 | - <?php do_action( 'wpinv_invoice_top_bar_right', $invoice );?> |
|
| 46 | + <?php do_action('wpinv_invoice_top_bar_right', $invoice); ?> |
|
| 47 | 47 | </div> |
| 48 | 48 | </div> |
| 49 | 49 | </div> |
| 50 | 50 | <?php |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | -function wpinv_invoice_display_left_actions( $invoice ) { |
|
| 54 | - if ( empty( $invoice ) ) { |
|
| 53 | +function wpinv_invoice_display_left_actions($invoice) { |
|
| 54 | + if (empty($invoice)) { |
|
| 55 | 55 | return; |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - if($invoice->post_type == 'wpi_invoice'){ |
|
| 58 | + if ($invoice->post_type == 'wpi_invoice') { |
|
| 59 | 59 | |
| 60 | 60 | $user_id = (int)$invoice->get_user_id(); |
| 61 | 61 | $current_user_id = (int)get_current_user_id(); |
| 62 | 62 | |
| 63 | - if ( $user_id > 0 && $user_id == $current_user_id && $invoice->needs_payment() ) { |
|
| 63 | + if ($user_id > 0 && $user_id == $current_user_id && $invoice->needs_payment()) { |
|
| 64 | 64 | ?> |
| 65 | - <a class="btn btn-success btn-sm" title="<?php esc_attr_e( 'Pay This Invoice', 'invoicing' ); ?>" href="<?php echo esc_url( $invoice->get_checkout_payment_url() ); ?>"><?php _e( 'Pay For Invoice', 'invoicing' ); ?></a> |
|
| 65 | + <a class="btn btn-success btn-sm" title="<?php esc_attr_e('Pay This Invoice', 'invoicing'); ?>" href="<?php echo esc_url($invoice->get_checkout_payment_url()); ?>"><?php _e('Pay For Invoice', 'invoicing'); ?></a> |
|
| 66 | 66 | <?php |
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | 69 | do_action('wpinv_invoice_display_left_actions', $invoice); |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | -function wpinv_invoice_display_right_actions( $invoice ) { |
|
| 73 | - if ( empty( $invoice ) ) return; //Exit if invoice is not set. |
|
| 72 | +function wpinv_invoice_display_right_actions($invoice) { |
|
| 73 | + if (empty($invoice)) return; //Exit if invoice is not set. |
|
| 74 | 74 | |
| 75 | - if($invoice->post_type == 'wpi_invoice'){ |
|
| 75 | + if ($invoice->post_type == 'wpi_invoice') { |
|
| 76 | 76 | $user_id = (int)$invoice->get_user_id(); |
| 77 | 77 | $current_user_id = (int)get_current_user_id(); |
| 78 | 78 | |
| 79 | - if ( $user_id > 0 && $user_id == $current_user_id ) { |
|
| 79 | + if ($user_id > 0 && $user_id == $current_user_id) { |
|
| 80 | 80 | ?> |
| 81 | - <a class="btn btn-primary btn-sm" onclick="window.print();" href="javascript:void(0)"><?php _e( 'Print Invoice', 'invoicing' ); ?></a> |
|
| 82 | - <a class="btn btn-warning btn-sm" href="<?php echo esc_url( wpinv_get_history_page_uri() ); ?>"><?php _e( 'Invoice History', 'invoicing' ); ?></a> |
|
| 81 | + <a class="btn btn-primary btn-sm" onclick="window.print();" href="javascript:void(0)"><?php _e('Print Invoice', 'invoicing'); ?></a> |
|
| 82 | + <a class="btn btn-warning btn-sm" href="<?php echo esc_url(wpinv_get_history_page_uri()); ?>"><?php _e('Invoice History', 'invoicing'); ?></a> |
|
| 83 | 83 | <?php } |
| 84 | 84 | } |
| 85 | 85 | do_action('wpinv_invoice_display_right_actions', $invoice); |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | -function wpinv_before_invoice_content( $content ) { |
|
| 88 | +function wpinv_before_invoice_content($content) { |
|
| 89 | 89 | global $post; |
| 90 | 90 | |
| 91 | - if ( $post && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) { |
|
| 91 | + if ($post && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) { |
|
| 92 | 92 | ob_start(); |
| 93 | - do_action( 'wpinv_before_invoice_content', $post->ID ); |
|
| 93 | + do_action('wpinv_before_invoice_content', $post->ID); |
|
| 94 | 94 | $content = ob_get_clean() . $content; |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | return $content; |
| 98 | 98 | } |
| 99 | -add_filter( 'the_content', 'wpinv_before_invoice_content' ); |
|
| 99 | +add_filter('the_content', 'wpinv_before_invoice_content'); |
|
| 100 | 100 | |
| 101 | -function wpinv_after_invoice_content( $content ) { |
|
| 101 | +function wpinv_after_invoice_content($content) { |
|
| 102 | 102 | global $post; |
| 103 | 103 | |
| 104 | - if ( $post && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) { |
|
| 104 | + if ($post && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) { |
|
| 105 | 105 | ob_start(); |
| 106 | - do_action( 'wpinv_after_invoice_content', $post->ID ); |
|
| 106 | + do_action('wpinv_after_invoice_content', $post->ID); |
|
| 107 | 107 | $content .= ob_get_clean(); |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | return $content; |
| 111 | 111 | } |
| 112 | -add_filter( 'the_content', 'wpinv_after_invoice_content' ); |
|
| 112 | +add_filter('the_content', 'wpinv_after_invoice_content'); |
|
| 113 | 113 | |
| 114 | 114 | function wpinv_get_templates_dir() { |
| 115 | 115 | return WPINV_PLUGIN_DIR . 'templates'; |
@@ -119,105 +119,105 @@ discard block |
||
| 119 | 119 | return WPINV_PLUGIN_URL . 'templates'; |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | -function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
| 123 | - if ( ! empty( $args ) && is_array( $args ) ) { |
|
| 124 | - extract( $args ); |
|
| 122 | +function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
| 123 | + if (!empty($args) && is_array($args)) { |
|
| 124 | + extract($args); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - $located = wpinv_locate_template( $template_name, $template_path, $default_path ); |
|
| 127 | + $located = wpinv_locate_template($template_name, $template_path, $default_path); |
|
| 128 | 128 | // Allow 3rd party plugin filter template file from their plugin. |
| 129 | - $located = apply_filters( 'wpinv_get_template', $located, $template_name, $args, $template_path, $default_path ); |
|
| 129 | + $located = apply_filters('wpinv_get_template', $located, $template_name, $args, $template_path, $default_path); |
|
| 130 | 130 | |
| 131 | - if ( ! file_exists( $located ) ) { |
|
| 132 | - _doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' ); |
|
| 131 | + if (!file_exists($located)) { |
|
| 132 | + _doing_it_wrong(__FUNCTION__, sprintf('<code>%s</code> does not exist.', $located), '2.1'); |
|
| 133 | 133 | return; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - do_action( 'wpinv_before_template_part', $template_name, $template_path, $located, $args ); |
|
| 136 | + do_action('wpinv_before_template_part', $template_name, $template_path, $located, $args); |
|
| 137 | 137 | |
| 138 | - include( $located ); |
|
| 138 | + include($located); |
|
| 139 | 139 | |
| 140 | - do_action( 'wpinv_after_template_part', $template_name, $template_path, $located, $args ); |
|
| 140 | + do_action('wpinv_after_template_part', $template_name, $template_path, $located, $args); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | -function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
| 143 | +function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
| 144 | 144 | ob_start(); |
| 145 | - wpinv_get_template( $template_name, $args, $template_path, $default_path ); |
|
| 145 | + wpinv_get_template($template_name, $args, $template_path, $default_path); |
|
| 146 | 146 | return ob_get_clean(); |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | -function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) { |
|
| 150 | - if ( ! $template_path ) { |
|
| 149 | +function wpinv_locate_template($template_name, $template_path = '', $default_path = '') { |
|
| 150 | + if (!$template_path) { |
|
| 151 | 151 | $template_path = wpinv_template_path(); |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - if ( ! $default_path ) { |
|
| 154 | + if (!$default_path) { |
|
| 155 | 155 | $default_path = WPINV_PLUGIN_DIR . 'templates/'; |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | // Look within passed path within the theme - this is priority. |
| 159 | 159 | $template = locate_template( |
| 160 | 160 | array( |
| 161 | - trailingslashit( $template_path ) . $template_name, |
|
| 161 | + trailingslashit($template_path) . $template_name, |
|
| 162 | 162 | $template_name |
| 163 | 163 | ) |
| 164 | 164 | ); |
| 165 | 165 | |
| 166 | 166 | // Get default templates/ |
| 167 | - if ( !$template && $default_path ) { |
|
| 168 | - $template = trailingslashit( $default_path ) . $template_name; |
|
| 167 | + if (!$template && $default_path) { |
|
| 168 | + $template = trailingslashit($default_path) . $template_name; |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | // Return what we found. |
| 172 | - return apply_filters( 'wpinv_locate_template', $template, $template_name, $template_path ); |
|
| 172 | + return apply_filters('wpinv_locate_template', $template, $template_name, $template_path); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | -function wpinv_get_template_part( $slug, $name = null, $load = true ) { |
|
| 176 | - do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
| 175 | +function wpinv_get_template_part($slug, $name = null, $load = true) { |
|
| 176 | + do_action('get_template_part_' . $slug, $slug, $name); |
|
| 177 | 177 | |
| 178 | 178 | // Setup possible parts |
| 179 | 179 | $templates = array(); |
| 180 | - if ( isset( $name ) ) |
|
| 180 | + if (isset($name)) |
|
| 181 | 181 | $templates[] = $slug . '-' . $name . '.php'; |
| 182 | 182 | $templates[] = $slug . '.php'; |
| 183 | 183 | |
| 184 | 184 | // Allow template parts to be filtered |
| 185 | - $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
| 185 | + $templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name); |
|
| 186 | 186 | |
| 187 | 187 | // Return the part that is found |
| 188 | - return wpinv_locate_tmpl( $templates, $load, false ); |
|
| 188 | + return wpinv_locate_tmpl($templates, $load, false); |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | -function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) { |
|
| 191 | +function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) { |
|
| 192 | 192 | // No file found yet |
| 193 | 193 | $located = false; |
| 194 | 194 | |
| 195 | 195 | // Try to find a template file |
| 196 | - foreach ( (array)$template_names as $template_name ) { |
|
| 196 | + foreach ((array)$template_names as $template_name) { |
|
| 197 | 197 | |
| 198 | 198 | // Continue if template is empty |
| 199 | - if ( empty( $template_name ) ) |
|
| 199 | + if (empty($template_name)) |
|
| 200 | 200 | continue; |
| 201 | 201 | |
| 202 | 202 | // Trim off any slashes from the template name |
| 203 | - $template_name = ltrim( $template_name, '/' ); |
|
| 203 | + $template_name = ltrim($template_name, '/'); |
|
| 204 | 204 | |
| 205 | 205 | // try locating this template file by looping through the template paths |
| 206 | - foreach( wpinv_get_theme_template_paths() as $template_path ) { |
|
| 206 | + foreach (wpinv_get_theme_template_paths() as $template_path) { |
|
| 207 | 207 | |
| 208 | - if( file_exists( $template_path . $template_name ) ) { |
|
| 208 | + if (file_exists($template_path . $template_name)) { |
|
| 209 | 209 | $located = $template_path . $template_name; |
| 210 | 210 | break; |
| 211 | 211 | } |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | - if( !empty( $located ) ) { |
|
| 214 | + if (!empty($located)) { |
|
| 215 | 215 | break; |
| 216 | 216 | } |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | - if ( ( true == $load ) && ! empty( $located ) ) |
|
| 220 | - load_template( $located, $require_once ); |
|
| 219 | + if ((true == $load) && !empty($located)) |
|
| 220 | + load_template($located, $require_once); |
|
| 221 | 221 | |
| 222 | 222 | return $located; |
| 223 | 223 | } |
@@ -226,143 +226,143 @@ discard block |
||
| 226 | 226 | $template_dir = wpinv_get_theme_template_dir_name(); |
| 227 | 227 | |
| 228 | 228 | $file_paths = array( |
| 229 | - 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
| 230 | - 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
| 229 | + 1 => trailingslashit(get_stylesheet_directory()) . $template_dir, |
|
| 230 | + 10 => trailingslashit(get_template_directory()) . $template_dir, |
|
| 231 | 231 | 100 => wpinv_get_templates_dir() |
| 232 | 232 | ); |
| 233 | 233 | |
| 234 | - $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
| 234 | + $file_paths = apply_filters('wpinv_template_paths', $file_paths); |
|
| 235 | 235 | |
| 236 | 236 | // sort the file paths based on priority |
| 237 | - ksort( $file_paths, SORT_NUMERIC ); |
|
| 237 | + ksort($file_paths, SORT_NUMERIC); |
|
| 238 | 238 | |
| 239 | - return array_map( 'trailingslashit', $file_paths ); |
|
| 239 | + return array_map('trailingslashit', $file_paths); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | function wpinv_get_theme_template_dir_name() { |
| 243 | - return trailingslashit( apply_filters( 'wpinv_templates_dir', 'wpinv_templates' ) ); |
|
| 243 | + return trailingslashit(apply_filters('wpinv_templates_dir', 'wpinv_templates')); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | function wpinv_checkout_meta_tags() { |
| 247 | 247 | |
| 248 | 248 | $pages = array(); |
| 249 | - $pages[] = wpinv_get_option( 'success_page' ); |
|
| 250 | - $pages[] = wpinv_get_option( 'failure_page' ); |
|
| 251 | - $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
| 249 | + $pages[] = wpinv_get_option('success_page'); |
|
| 250 | + $pages[] = wpinv_get_option('failure_page'); |
|
| 251 | + $pages[] = wpinv_get_option('invoice_history_page'); |
|
| 252 | 252 | |
| 253 | - if( !wpinv_is_checkout() && !is_page( $pages ) ) { |
|
| 253 | + if (!wpinv_is_checkout() && !is_page($pages)) { |
|
| 254 | 254 | return; |
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
| 258 | 258 | } |
| 259 | -add_action( 'wp_head', 'wpinv_checkout_meta_tags' ); |
|
| 259 | +add_action('wp_head', 'wpinv_checkout_meta_tags'); |
|
| 260 | 260 | |
| 261 | -function wpinv_add_body_classes( $class ) { |
|
| 261 | +function wpinv_add_body_classes($class) { |
|
| 262 | 262 | $classes = (array)$class; |
| 263 | 263 | |
| 264 | - if( wpinv_is_checkout() ) { |
|
| 264 | + if (wpinv_is_checkout()) { |
|
| 265 | 265 | $classes[] = 'wpinv-checkout'; |
| 266 | 266 | $classes[] = 'wpinv-page'; |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | - if( wpinv_is_success_page() ) { |
|
| 269 | + if (wpinv_is_success_page()) { |
|
| 270 | 270 | $classes[] = 'wpinv-success'; |
| 271 | 271 | $classes[] = 'wpinv-page'; |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | - if( wpinv_is_failed_transaction_page() ) { |
|
| 274 | + if (wpinv_is_failed_transaction_page()) { |
|
| 275 | 275 | $classes[] = 'wpinv-failed-transaction'; |
| 276 | 276 | $classes[] = 'wpinv-page'; |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | - if( wpinv_is_invoice_history_page() ) { |
|
| 279 | + if (wpinv_is_invoice_history_page()) { |
|
| 280 | 280 | $classes[] = 'wpinv-history'; |
| 281 | 281 | $classes[] = 'wpinv-page'; |
| 282 | 282 | } |
| 283 | 283 | |
| 284 | - if( wpinv_is_test_mode() ) { |
|
| 284 | + if (wpinv_is_test_mode()) { |
|
| 285 | 285 | $classes[] = 'wpinv-test-mode'; |
| 286 | 286 | $classes[] = 'wpinv-page'; |
| 287 | 287 | } |
| 288 | 288 | |
| 289 | - return array_unique( $classes ); |
|
| 289 | + return array_unique($classes); |
|
| 290 | 290 | } |
| 291 | -add_filter( 'body_class', 'wpinv_add_body_classes' ); |
|
| 291 | +add_filter('body_class', 'wpinv_add_body_classes'); |
|
| 292 | 292 | |
| 293 | -function wpinv_html_dropdown( $name = 'wpinv_discounts', $selected = 0, $status = '' ) { |
|
| 294 | - $args = array( 'nopaging' => true ); |
|
| 293 | +function wpinv_html_dropdown($name = 'wpinv_discounts', $selected = 0, $status = '') { |
|
| 294 | + $args = array('nopaging' => true); |
|
| 295 | 295 | |
| 296 | - if ( ! empty( $status ) ) |
|
| 296 | + if (!empty($status)) |
|
| 297 | 297 | $args['post_status'] = $status; |
| 298 | 298 | |
| 299 | - $discounts = wpinv_get_discounts( $args ); |
|
| 299 | + $discounts = wpinv_get_discounts($args); |
|
| 300 | 300 | $options = array(); |
| 301 | 301 | |
| 302 | - if ( $discounts ) { |
|
| 303 | - foreach ( $discounts as $discount ) { |
|
| 304 | - $options[ absint( $discount->ID ) ] = esc_html( get_the_title( $discount->ID ) ); |
|
| 302 | + if ($discounts) { |
|
| 303 | + foreach ($discounts as $discount) { |
|
| 304 | + $options[absint($discount->ID)] = esc_html(get_the_title($discount->ID)); |
|
| 305 | 305 | } |
| 306 | 306 | } else { |
| 307 | - $options[0] = __( 'No discounts found', 'invoicing' ); |
|
| 307 | + $options[0] = __('No discounts found', 'invoicing'); |
|
| 308 | 308 | } |
| 309 | 309 | |
| 310 | - $output = wpinv_html_select( array( |
|
| 310 | + $output = wpinv_html_select(array( |
|
| 311 | 311 | 'name' => $name, |
| 312 | 312 | 'selected' => $selected, |
| 313 | 313 | 'options' => $options, |
| 314 | 314 | 'show_option_all' => false, |
| 315 | 315 | 'show_option_none' => false, |
| 316 | - ) ); |
|
| 316 | + )); |
|
| 317 | 317 | |
| 318 | 318 | return $output; |
| 319 | 319 | } |
| 320 | 320 | |
| 321 | -function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) { |
|
| 322 | - $current = date( 'Y' ); |
|
| 323 | - $start_year = $current - absint( $years_before ); |
|
| 324 | - $end_year = $current + absint( $years_after ); |
|
| 325 | - $selected = empty( $selected ) ? date( 'Y' ) : $selected; |
|
| 321 | +function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) { |
|
| 322 | + $current = date('Y'); |
|
| 323 | + $start_year = $current - absint($years_before); |
|
| 324 | + $end_year = $current + absint($years_after); |
|
| 325 | + $selected = empty($selected) ? date('Y') : $selected; |
|
| 326 | 326 | $options = array(); |
| 327 | 327 | |
| 328 | - while ( $start_year <= $end_year ) { |
|
| 329 | - $options[ absint( $start_year ) ] = $start_year; |
|
| 328 | + while ($start_year <= $end_year) { |
|
| 329 | + $options[absint($start_year)] = $start_year; |
|
| 330 | 330 | $start_year++; |
| 331 | 331 | } |
| 332 | 332 | |
| 333 | - $output = wpinv_html_select( array( |
|
| 333 | + $output = wpinv_html_select(array( |
|
| 334 | 334 | 'name' => $name, |
| 335 | 335 | 'selected' => $selected, |
| 336 | 336 | 'options' => $options, |
| 337 | 337 | 'show_option_all' => false, |
| 338 | 338 | 'show_option_none' => false |
| 339 | - ) ); |
|
| 339 | + )); |
|
| 340 | 340 | |
| 341 | 341 | return $output; |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | -function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) { |
|
| 344 | +function wpinv_html_month_dropdown($name = 'month', $selected = 0) { |
|
| 345 | 345 | $month = 1; |
| 346 | 346 | $options = array(); |
| 347 | - $selected = empty( $selected ) ? date( 'n' ) : $selected; |
|
| 347 | + $selected = empty($selected) ? date('n') : $selected; |
|
| 348 | 348 | |
| 349 | - while ( $month <= 12 ) { |
|
| 350 | - $options[ absint( $month ) ] = wpinv_month_num_to_name( $month ); |
|
| 349 | + while ($month <= 12) { |
|
| 350 | + $options[absint($month)] = wpinv_month_num_to_name($month); |
|
| 351 | 351 | $month++; |
| 352 | 352 | } |
| 353 | 353 | |
| 354 | - $output = wpinv_html_select( array( |
|
| 354 | + $output = wpinv_html_select(array( |
|
| 355 | 355 | 'name' => $name, |
| 356 | 356 | 'selected' => $selected, |
| 357 | 357 | 'options' => $options, |
| 358 | 358 | 'show_option_all' => false, |
| 359 | 359 | 'show_option_none' => false |
| 360 | - ) ); |
|
| 360 | + )); |
|
| 361 | 361 | |
| 362 | 362 | return $output; |
| 363 | 363 | } |
| 364 | 364 | |
| 365 | -function wpinv_html_select( $args = array() ) { |
|
| 365 | +function wpinv_html_select($args = array()) { |
|
| 366 | 366 | $defaults = array( |
| 367 | 367 | 'options' => array(), |
| 368 | 368 | 'name' => null, |
@@ -372,8 +372,8 @@ discard block |
||
| 372 | 372 | 'chosen' => false, |
| 373 | 373 | 'placeholder' => null, |
| 374 | 374 | 'multiple' => false, |
| 375 | - 'show_option_all' => _x( 'All', 'all dropdown items', 'invoicing' ), |
|
| 376 | - 'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ), |
|
| 375 | + 'show_option_all' => _x('All', 'all dropdown items', 'invoicing'), |
|
| 376 | + 'show_option_none' => _x('None', 'no dropdown items', 'invoicing'), |
|
| 377 | 377 | 'data' => array(), |
| 378 | 378 | 'onchange' => null, |
| 379 | 379 | 'required' => false, |
@@ -381,78 +381,78 @@ discard block |
||
| 381 | 381 | 'readonly' => false, |
| 382 | 382 | ); |
| 383 | 383 | |
| 384 | - $args = wp_parse_args( $args, $defaults ); |
|
| 384 | + $args = wp_parse_args($args, $defaults); |
|
| 385 | 385 | |
| 386 | 386 | $data_elements = ''; |
| 387 | - foreach ( $args['data'] as $key => $value ) { |
|
| 388 | - $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"'; |
|
| 387 | + foreach ($args['data'] as $key => $value) { |
|
| 388 | + $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"'; |
|
| 389 | 389 | } |
| 390 | 390 | |
| 391 | - if( $args['multiple'] ) { |
|
| 391 | + if ($args['multiple']) { |
|
| 392 | 392 | $multiple = ' MULTIPLE'; |
| 393 | 393 | } else { |
| 394 | 394 | $multiple = ''; |
| 395 | 395 | } |
| 396 | 396 | |
| 397 | - if( $args['chosen'] ) { |
|
| 397 | + if ($args['chosen']) { |
|
| 398 | 398 | $args['class'] .= ' wpinv-select-chosen'; |
| 399 | 399 | } |
| 400 | 400 | |
| 401 | - if( $args['placeholder'] ) { |
|
| 401 | + if ($args['placeholder']) { |
|
| 402 | 402 | $placeholder = $args['placeholder']; |
| 403 | 403 | } else { |
| 404 | 404 | $placeholder = ''; |
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | $options = ''; |
| 408 | - if( !empty( $args['onchange'] ) ) { |
|
| 409 | - $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"'; |
|
| 408 | + if (!empty($args['onchange'])) { |
|
| 409 | + $options .= ' onchange="' . esc_attr($args['onchange']) . '"'; |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | - if( !empty( $args['required'] ) ) { |
|
| 412 | + if (!empty($args['required'])) { |
|
| 413 | 413 | $options .= ' required="required"'; |
| 414 | 414 | } |
| 415 | 415 | |
| 416 | - if( !empty( $args['disabled'] ) ) { |
|
| 416 | + if (!empty($args['disabled'])) { |
|
| 417 | 417 | $options .= ' disabled'; |
| 418 | 418 | } |
| 419 | 419 | |
| 420 | - if( !empty( $args['readonly'] ) ) { |
|
| 420 | + if (!empty($args['readonly'])) { |
|
| 421 | 421 | $options .= ' readonly'; |
| 422 | 422 | } |
| 423 | 423 | |
| 424 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
| 425 | - $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>'; |
|
| 424 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
| 425 | + $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>'; |
|
| 426 | 426 | |
| 427 | - if ( $args['show_option_all'] ) { |
|
| 428 | - if( $args['multiple'] ) { |
|
| 429 | - $selected = selected( true, in_array( 0, $args['selected'] ), false ); |
|
| 427 | + if ($args['show_option_all']) { |
|
| 428 | + if ($args['multiple']) { |
|
| 429 | + $selected = selected(true, in_array(0, $args['selected']), false); |
|
| 430 | 430 | } else { |
| 431 | - $selected = selected( $args['selected'], 0, false ); |
|
| 431 | + $selected = selected($args['selected'], 0, false); |
|
| 432 | 432 | } |
| 433 | - $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>'; |
|
| 433 | + $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>'; |
|
| 434 | 434 | } |
| 435 | 435 | |
| 436 | - if ( !empty( $args['options'] ) ) { |
|
| 436 | + if (!empty($args['options'])) { |
|
| 437 | 437 | |
| 438 | - if ( $args['show_option_none'] ) { |
|
| 439 | - if( $args['multiple'] ) { |
|
| 440 | - $selected = selected( true, in_array( "", $args['selected'] ), false ); |
|
| 438 | + if ($args['show_option_none']) { |
|
| 439 | + if ($args['multiple']) { |
|
| 440 | + $selected = selected(true, in_array("", $args['selected']), false); |
|
| 441 | 441 | } else { |
| 442 | - $selected = selected( $args['selected'] === "", true, false ); |
|
| 442 | + $selected = selected($args['selected'] === "", true, false); |
|
| 443 | 443 | } |
| 444 | - $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>'; |
|
| 444 | + $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>'; |
|
| 445 | 445 | } |
| 446 | 446 | |
| 447 | - foreach( $args['options'] as $key => $option ) { |
|
| 447 | + foreach ($args['options'] as $key => $option) { |
|
| 448 | 448 | |
| 449 | - if( $args['multiple'] && is_array( $args['selected'] ) ) { |
|
| 450 | - $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false ); |
|
| 449 | + if ($args['multiple'] && is_array($args['selected'])) { |
|
| 450 | + $selected = selected(true, (bool)in_array($key, $args['selected']), false); |
|
| 451 | 451 | } else { |
| 452 | - $selected = selected( $args['selected'], $key, false ); |
|
| 452 | + $selected = selected($args['selected'], $key, false); |
|
| 453 | 453 | } |
| 454 | 454 | |
| 455 | - $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>'; |
|
| 455 | + $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>'; |
|
| 456 | 456 | } |
| 457 | 457 | } |
| 458 | 458 | |
@@ -461,7 +461,7 @@ discard block |
||
| 461 | 461 | return $output; |
| 462 | 462 | } |
| 463 | 463 | |
| 464 | -function wpinv_item_dropdown( $args = array() ) { |
|
| 464 | +function wpinv_item_dropdown($args = array()) { |
|
| 465 | 465 | $defaults = array( |
| 466 | 466 | 'name' => 'wpi_item', |
| 467 | 467 | 'id' => 'wpi_item', |
@@ -470,15 +470,15 @@ discard block |
||
| 470 | 470 | 'selected' => 0, |
| 471 | 471 | 'chosen' => false, |
| 472 | 472 | 'number' => 100, |
| 473 | - 'placeholder' => __( 'Choose a item', 'invoicing' ), |
|
| 474 | - 'data' => array( 'search-type' => 'item' ), |
|
| 473 | + 'placeholder' => __('Choose a item', 'invoicing'), |
|
| 474 | + 'data' => array('search-type' => 'item'), |
|
| 475 | 475 | 'show_option_all' => false, |
| 476 | 476 | 'show_option_none' => false, |
| 477 | 477 | 'with_packages' => true, |
| 478 | 478 | 'show_recurring' => false, |
| 479 | 479 | ); |
| 480 | 480 | |
| 481 | - $args = wp_parse_args( $args, $defaults ); |
|
| 481 | + $args = wp_parse_args($args, $defaults); |
|
| 482 | 482 | |
| 483 | 483 | $item_args = array( |
| 484 | 484 | 'post_type' => 'wpi_item', |
@@ -487,7 +487,7 @@ discard block |
||
| 487 | 487 | 'posts_per_page' => $args['number'] |
| 488 | 488 | ); |
| 489 | 489 | |
| 490 | - if ( !$args['with_packages'] ) { |
|
| 490 | + if (!$args['with_packages']) { |
|
| 491 | 491 | $item_args['meta_query'] = array( |
| 492 | 492 | array( |
| 493 | 493 | 'key' => '_wpinv_type', |
@@ -497,42 +497,42 @@ discard block |
||
| 497 | 497 | ); |
| 498 | 498 | } |
| 499 | 499 | |
| 500 | - $items = get_posts( $item_args ); |
|
| 500 | + $items = get_posts($item_args); |
|
| 501 | 501 | $options = array(); |
| 502 | - if ( $items ) { |
|
| 503 | - foreach ( $items as $item ) { |
|
| 504 | - $title = esc_html( $item->post_title ); |
|
| 502 | + if ($items) { |
|
| 503 | + foreach ($items as $item) { |
|
| 504 | + $title = esc_html($item->post_title); |
|
| 505 | 505 | |
| 506 | - if ( !empty( $args['show_recurring'] ) ) { |
|
| 507 | - $title .= wpinv_get_item_suffix( $item->ID, false ); |
|
| 506 | + if (!empty($args['show_recurring'])) { |
|
| 507 | + $title .= wpinv_get_item_suffix($item->ID, false); |
|
| 508 | 508 | } |
| 509 | 509 | |
| 510 | - $options[ absint( $item->ID ) ] = $title; |
|
| 510 | + $options[absint($item->ID)] = $title; |
|
| 511 | 511 | } |
| 512 | 512 | } |
| 513 | 513 | |
| 514 | 514 | // This ensures that any selected items are included in the drop down |
| 515 | - if( is_array( $args['selected'] ) ) { |
|
| 516 | - foreach( $args['selected'] as $item ) { |
|
| 517 | - if( ! in_array( $item, $options ) ) { |
|
| 518 | - $title = get_the_title( $item ); |
|
| 519 | - if ( !empty( $args['show_recurring'] ) ) { |
|
| 520 | - $title .= wpinv_get_item_suffix( $item, false ); |
|
| 515 | + if (is_array($args['selected'])) { |
|
| 516 | + foreach ($args['selected'] as $item) { |
|
| 517 | + if (!in_array($item, $options)) { |
|
| 518 | + $title = get_the_title($item); |
|
| 519 | + if (!empty($args['show_recurring'])) { |
|
| 520 | + $title .= wpinv_get_item_suffix($item, false); |
|
| 521 | 521 | } |
| 522 | 522 | $options[$item] = $title; |
| 523 | 523 | } |
| 524 | 524 | } |
| 525 | - } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) { |
|
| 526 | - if ( ! in_array( $args['selected'], $options ) ) { |
|
| 527 | - $title = get_the_title( $args['selected'] ); |
|
| 528 | - if ( !empty( $args['show_recurring'] ) ) { |
|
| 529 | - $title .= wpinv_get_item_suffix( $args['selected'], false ); |
|
| 525 | + } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) { |
|
| 526 | + if (!in_array($args['selected'], $options)) { |
|
| 527 | + $title = get_the_title($args['selected']); |
|
| 528 | + if (!empty($args['show_recurring'])) { |
|
| 529 | + $title .= wpinv_get_item_suffix($args['selected'], false); |
|
| 530 | 530 | } |
| 531 | - $options[$args['selected']] = get_the_title( $args['selected'] ); |
|
| 531 | + $options[$args['selected']] = get_the_title($args['selected']); |
|
| 532 | 532 | } |
| 533 | 533 | } |
| 534 | 534 | |
| 535 | - $output = wpinv_html_select( array( |
|
| 535 | + $output = wpinv_html_select(array( |
|
| 536 | 536 | 'name' => $args['name'], |
| 537 | 537 | 'selected' => $args['selected'], |
| 538 | 538 | 'id' => $args['id'], |
@@ -544,12 +544,12 @@ discard block |
||
| 544 | 544 | 'show_option_all' => $args['show_option_all'], |
| 545 | 545 | 'show_option_none' => $args['show_option_none'], |
| 546 | 546 | 'data' => $args['data'], |
| 547 | - ) ); |
|
| 547 | + )); |
|
| 548 | 548 | |
| 549 | 549 | return $output; |
| 550 | 550 | } |
| 551 | 551 | |
| 552 | -function wpinv_html_checkbox( $args = array() ) { |
|
| 552 | +function wpinv_html_checkbox($args = array()) { |
|
| 553 | 553 | $defaults = array( |
| 554 | 554 | 'name' => null, |
| 555 | 555 | 'current' => null, |
@@ -560,38 +560,38 @@ discard block |
||
| 560 | 560 | ) |
| 561 | 561 | ); |
| 562 | 562 | |
| 563 | - $args = wp_parse_args( $args, $defaults ); |
|
| 563 | + $args = wp_parse_args($args, $defaults); |
|
| 564 | 564 | |
| 565 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
| 565 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
| 566 | 566 | $options = ''; |
| 567 | - if ( ! empty( $args['options']['disabled'] ) ) { |
|
| 567 | + if (!empty($args['options']['disabled'])) { |
|
| 568 | 568 | $options .= ' disabled="disabled"'; |
| 569 | - } elseif ( ! empty( $args['options']['readonly'] ) ) { |
|
| 569 | + } elseif (!empty($args['options']['readonly'])) { |
|
| 570 | 570 | $options .= ' readonly'; |
| 571 | 571 | } |
| 572 | 572 | |
| 573 | - $output = '<input type="checkbox"' . $options . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $class . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />'; |
|
| 573 | + $output = '<input type="checkbox"' . $options . ' name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . $class . ' ' . esc_attr($args['name']) . '" ' . checked(1, $args['current'], false) . ' />'; |
|
| 574 | 574 | |
| 575 | 575 | return $output; |
| 576 | 576 | } |
| 577 | 577 | |
| 578 | -function wpinv_html_text( $args = array() ) { |
|
| 578 | +function wpinv_html_text($args = array()) { |
|
| 579 | 579 | // Backwards compatibility |
| 580 | - if ( func_num_args() > 1 ) { |
|
| 580 | + if (func_num_args() > 1) { |
|
| 581 | 581 | $args = func_get_args(); |
| 582 | 582 | |
| 583 | 583 | $name = $args[0]; |
| 584 | - $value = isset( $args[1] ) ? $args[1] : ''; |
|
| 585 | - $label = isset( $args[2] ) ? $args[2] : ''; |
|
| 586 | - $desc = isset( $args[3] ) ? $args[3] : ''; |
|
| 584 | + $value = isset($args[1]) ? $args[1] : ''; |
|
| 585 | + $label = isset($args[2]) ? $args[2] : ''; |
|
| 586 | + $desc = isset($args[3]) ? $args[3] : ''; |
|
| 587 | 587 | } |
| 588 | 588 | |
| 589 | 589 | $defaults = array( |
| 590 | 590 | 'id' => '', |
| 591 | - 'name' => isset( $name ) ? $name : 'text', |
|
| 592 | - 'value' => isset( $value ) ? $value : null, |
|
| 593 | - 'label' => isset( $label ) ? $label : null, |
|
| 594 | - 'desc' => isset( $desc ) ? $desc : null, |
|
| 591 | + 'name' => isset($name) ? $name : 'text', |
|
| 592 | + 'value' => isset($value) ? $value : null, |
|
| 593 | + 'label' => isset($label) ? $label : null, |
|
| 594 | + 'desc' => isset($desc) ? $desc : null, |
|
| 595 | 595 | 'placeholder' => '', |
| 596 | 596 | 'class' => 'regular-text', |
| 597 | 597 | 'disabled' => false, |
@@ -601,51 +601,51 @@ discard block |
||
| 601 | 601 | 'data' => false |
| 602 | 602 | ); |
| 603 | 603 | |
| 604 | - $args = wp_parse_args( $args, $defaults ); |
|
| 604 | + $args = wp_parse_args($args, $defaults); |
|
| 605 | 605 | |
| 606 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
| 606 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
| 607 | 607 | $options = ''; |
| 608 | - if( $args['required'] ) { |
|
| 608 | + if ($args['required']) { |
|
| 609 | 609 | $options .= ' required="required"'; |
| 610 | 610 | } |
| 611 | - if( $args['readonly'] ) { |
|
| 611 | + if ($args['readonly']) { |
|
| 612 | 612 | $options .= ' readonly'; |
| 613 | 613 | } |
| 614 | - if( $args['readonly'] ) { |
|
| 614 | + if ($args['readonly']) { |
|
| 615 | 615 | $options .= ' readonly'; |
| 616 | 616 | } |
| 617 | 617 | |
| 618 | 618 | $data = ''; |
| 619 | - if ( !empty( $args['data'] ) ) { |
|
| 620 | - foreach ( $args['data'] as $key => $value ) { |
|
| 621 | - $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" '; |
|
| 619 | + if (!empty($args['data'])) { |
|
| 620 | + foreach ($args['data'] as $key => $value) { |
|
| 621 | + $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" '; |
|
| 622 | 622 | } |
| 623 | 623 | } |
| 624 | 624 | |
| 625 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
| 626 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
| 627 | - if ( ! empty( $args['desc'] ) ) { |
|
| 628 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
| 625 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
| 626 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>'; |
|
| 627 | + if (!empty($args['desc'])) { |
|
| 628 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
| 629 | 629 | } |
| 630 | 630 | |
| 631 | - $output .= '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" autocomplete="' . esc_attr( $args['autocomplete'] ) . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $class . '" ' . $data . ' ' . trim( $options ) . '/>'; |
|
| 631 | + $output .= '<input type="text" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" autocomplete="' . esc_attr($args['autocomplete']) . '" value="' . esc_attr($args['value']) . '" placeholder="' . esc_attr($args['placeholder']) . '" class="' . $class . '" ' . $data . ' ' . trim($options) . '/>'; |
|
| 632 | 632 | |
| 633 | 633 | $output .= '</span>'; |
| 634 | 634 | |
| 635 | 635 | return $output; |
| 636 | 636 | } |
| 637 | 637 | |
| 638 | -function wpinv_html_date_field( $args = array() ) { |
|
| 639 | - if( empty( $args['class'] ) ) { |
|
| 638 | +function wpinv_html_date_field($args = array()) { |
|
| 639 | + if (empty($args['class'])) { |
|
| 640 | 640 | $args['class'] = 'wpiDatepicker'; |
| 641 | - } elseif( ! strpos( $args['class'], 'wpiDatepicker' ) ) { |
|
| 641 | + } elseif (!strpos($args['class'], 'wpiDatepicker')) { |
|
| 642 | 642 | $args['class'] .= ' wpiDatepicker'; |
| 643 | 643 | } |
| 644 | 644 | |
| 645 | - return wpinv_html_text( $args ); |
|
| 645 | + return wpinv_html_text($args); |
|
| 646 | 646 | } |
| 647 | 647 | |
| 648 | -function wpinv_html_textarea( $args = array() ) { |
|
| 648 | +function wpinv_html_textarea($args = array()) { |
|
| 649 | 649 | $defaults = array( |
| 650 | 650 | 'name' => 'textarea', |
| 651 | 651 | 'value' => null, |
@@ -655,31 +655,31 @@ discard block |
||
| 655 | 655 | 'disabled' => false |
| 656 | 656 | ); |
| 657 | 657 | |
| 658 | - $args = wp_parse_args( $args, $defaults ); |
|
| 658 | + $args = wp_parse_args($args, $defaults); |
|
| 659 | 659 | |
| 660 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
| 660 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
| 661 | 661 | $disabled = ''; |
| 662 | - if( $args['disabled'] ) { |
|
| 662 | + if ($args['disabled']) { |
|
| 663 | 663 | $disabled = ' disabled="disabled"'; |
| 664 | 664 | } |
| 665 | 665 | |
| 666 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
| 667 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
| 668 | - $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>'; |
|
| 666 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
| 667 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>'; |
|
| 668 | + $output .= '<textarea name="' . esc_attr($args['name']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>'; |
|
| 669 | 669 | |
| 670 | - if ( ! empty( $args['desc'] ) ) { |
|
| 671 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
| 670 | + if (!empty($args['desc'])) { |
|
| 671 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
| 672 | 672 | } |
| 673 | 673 | $output .= '</span>'; |
| 674 | 674 | |
| 675 | 675 | return $output; |
| 676 | 676 | } |
| 677 | 677 | |
| 678 | -function wpinv_html_ajax_user_search( $args = array() ) { |
|
| 678 | +function wpinv_html_ajax_user_search($args = array()) { |
|
| 679 | 679 | $defaults = array( |
| 680 | 680 | 'name' => 'user_id', |
| 681 | 681 | 'value' => null, |
| 682 | - 'placeholder' => __( 'Enter username', 'invoicing' ), |
|
| 682 | + 'placeholder' => __('Enter username', 'invoicing'), |
|
| 683 | 683 | 'label' => null, |
| 684 | 684 | 'desc' => null, |
| 685 | 685 | 'class' => '', |
@@ -688,13 +688,13 @@ discard block |
||
| 688 | 688 | 'data' => false |
| 689 | 689 | ); |
| 690 | 690 | |
| 691 | - $args = wp_parse_args( $args, $defaults ); |
|
| 691 | + $args = wp_parse_args($args, $defaults); |
|
| 692 | 692 | |
| 693 | 693 | $args['class'] = 'wpinv-ajax-user-search ' . $args['class']; |
| 694 | 694 | |
| 695 | 695 | $output = '<span class="wpinv_user_search_wrap">'; |
| 696 | - $output .= wpinv_html_text( $args ); |
|
| 697 | - $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __( 'Cancel', 'invoicing' ) . '" aria-label="' . __( 'Cancel', 'invoicing' ) . '" href="#">x</a><span></span></span>'; |
|
| 696 | + $output .= wpinv_html_text($args); |
|
| 697 | + $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __('Cancel', 'invoicing') . '" aria-label="' . __('Cancel', 'invoicing') . '" href="#">x</a><span></span></span>'; |
|
| 698 | 698 | $output .= '</span>'; |
| 699 | 699 | |
| 700 | 700 | return $output; |
@@ -703,7 +703,7 @@ discard block |
||
| 703 | 703 | function wpinv_ip_geolocation() { |
| 704 | 704 | global $wpinv_euvat; |
| 705 | 705 | |
| 706 | - $ip = !empty( $_GET['ip'] ) ? sanitize_text_field( $_GET['ip'] ) : ''; |
|
| 706 | + $ip = !empty($_GET['ip']) ? sanitize_text_field($_GET['ip']) : ''; |
|
| 707 | 707 | $content = ''; |
| 708 | 708 | $iso = ''; |
| 709 | 709 | $country = ''; |
@@ -714,69 +714,69 @@ discard block |
||
| 714 | 714 | $credit = ''; |
| 715 | 715 | $address = ''; |
| 716 | 716 | |
| 717 | - if ( wpinv_get_option( 'vat_ip_lookup' ) == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record( $ip ) ) { |
|
| 717 | + if (wpinv_get_option('vat_ip_lookup') == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record($ip)) { |
|
| 718 | 718 | try { |
| 719 | 719 | $iso = $geoip2_city->country->isoCode; |
| 720 | 720 | $country = $geoip2_city->country->name; |
| 721 | - $region = !empty( $geoip2_city->subdivisions ) && !empty( $geoip2_city->subdivisions[0]->name ) ? $geoip2_city->subdivisions[0]->name : ''; |
|
| 721 | + $region = !empty($geoip2_city->subdivisions) && !empty($geoip2_city->subdivisions[0]->name) ? $geoip2_city->subdivisions[0]->name : ''; |
|
| 722 | 722 | $city = $geoip2_city->city->name; |
| 723 | 723 | $longitude = $geoip2_city->location->longitude; |
| 724 | 724 | $latitude = $geoip2_city->location->latitude; |
| 725 | - $credit = __( 'Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing' ); |
|
| 726 | - } catch( Exception $e ) { } |
|
| 725 | + $credit = __('Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing'); |
|
| 726 | + } catch (Exception $e) { } |
|
| 727 | 727 | } |
| 728 | 728 | |
| 729 | - if ( !( $iso && $longitude && $latitude ) && function_exists( 'simplexml_load_file' ) ) { |
|
| 729 | + if (!($iso && $longitude && $latitude) && function_exists('simplexml_load_file')) { |
|
| 730 | 730 | try { |
| 731 | - $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip ); |
|
| 731 | + $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip); |
|
| 732 | 732 | |
| 733 | - if ( !empty( $load_xml ) && isset( $load_xml->geoplugin_countryCode ) && !empty( $load_xml->geoplugin_latitude ) && !empty( $load_xml->geoplugin_longitude ) ) { |
|
| 733 | + if (!empty($load_xml) && isset($load_xml->geoplugin_countryCode) && !empty($load_xml->geoplugin_latitude) && !empty($load_xml->geoplugin_longitude)) { |
|
| 734 | 734 | $iso = $load_xml->geoplugin_countryCode; |
| 735 | 735 | $country = $load_xml->geoplugin_countryName; |
| 736 | - $region = !empty( $load_xml->geoplugin_regionName ) ? $load_xml->geoplugin_regionName : ''; |
|
| 737 | - $city = !empty( $load_xml->geoplugin_city ) ? $load_xml->geoplugin_city : ''; |
|
| 736 | + $region = !empty($load_xml->geoplugin_regionName) ? $load_xml->geoplugin_regionName : ''; |
|
| 737 | + $city = !empty($load_xml->geoplugin_city) ? $load_xml->geoplugin_city : ''; |
|
| 738 | 738 | $longitude = $load_xml->geoplugin_longitude; |
| 739 | 739 | $latitude = $load_xml->geoplugin_latitude; |
| 740 | 740 | $credit = $load_xml->geoplugin_credit; |
| 741 | - $credit = __( 'Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing' ) . '<br>' . $load_xml->geoplugin_credit; |
|
| 741 | + $credit = __('Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing') . '<br>' . $load_xml->geoplugin_credit; |
|
| 742 | 742 | } |
| 743 | - } catch( Exception $e ) { } |
|
| 743 | + } catch (Exception $e) { } |
|
| 744 | 744 | } |
| 745 | 745 | |
| 746 | - if ( $iso && $longitude && $latitude ) { |
|
| 747 | - if ( $city ) { |
|
| 746 | + if ($iso && $longitude && $latitude) { |
|
| 747 | + if ($city) { |
|
| 748 | 748 | $address .= $city . ', '; |
| 749 | 749 | } |
| 750 | 750 | |
| 751 | - if ( $region ) { |
|
| 751 | + if ($region) { |
|
| 752 | 752 | $address .= $region . ', '; |
| 753 | 753 | } |
| 754 | 754 | |
| 755 | 755 | $address .= $country . ' (' . $iso . ')'; |
| 756 | - $content = '<p>'. sprintf( __( '<b>Address:</b> %s', 'invoicing' ), $address ) . '</p>'; |
|
| 757 | - $content .= '<p>'. $credit . '</p>'; |
|
| 756 | + $content = '<p>' . sprintf(__('<b>Address:</b> %s', 'invoicing'), $address) . '</p>'; |
|
| 757 | + $content .= '<p>' . $credit . '</p>'; |
|
| 758 | 758 | } else { |
| 759 | - $content = '<p>'. sprintf( __( 'Unable to find geolocation for the IP address: %s', 'invoicing' ), $ip ) . '</p>'; |
|
| 759 | + $content = '<p>' . sprintf(__('Unable to find geolocation for the IP address: %s', 'invoicing'), $ip) . '</p>'; |
|
| 760 | 760 | } |
| 761 | 761 | ?> |
| 762 | 762 | <!DOCTYPE html> |
| 763 | -<html><head><title><?php echo sprintf( __( 'IP: %s', 'invoicing' ), $ip );?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head> |
|
| 763 | +<html><head><title><?php echo sprintf(__('IP: %s', 'invoicing'), $ip); ?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head> |
|
| 764 | 764 | <body> |
| 765 | - <?php if ( $latitude && $latitude ) { ?> |
|
| 765 | + <?php if ($latitude && $latitude) { ?> |
|
| 766 | 766 | <div id="map"></div> |
| 767 | 767 | <script src="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.js"></script> |
| 768 | 768 | <script type="text/javascript"> |
| 769 | 769 | var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', |
| 770 | 770 | osmAttrib = '© <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors', |
| 771 | 771 | osm = L.tileLayer(osmUrl, {maxZoom: 18, attribution: osmAttrib}), |
| 772 | - latlng = new L.LatLng(<?php echo $latitude;?>, <?php echo $longitude;?>); |
|
| 772 | + latlng = new L.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>); |
|
| 773 | 773 | |
| 774 | 774 | var map = new L.Map('map', {center: latlng, zoom: 12, layers: [osm]}); |
| 775 | 775 | |
| 776 | 776 | var marker = new L.Marker(latlng); |
| 777 | 777 | map.addLayer(marker); |
| 778 | 778 | |
| 779 | - marker.bindPopup("<p><?php esc_attr_e( $address );?></p>"); |
|
| 779 | + marker.bindPopup("<p><?php esc_attr_e($address); ?></p>"); |
|
| 780 | 780 | </script> |
| 781 | 781 | <?php } ?> |
| 782 | 782 | <div style="height:100px"><?php echo $content; ?></div> |
@@ -784,31 +784,31 @@ discard block |
||
| 784 | 784 | <?php |
| 785 | 785 | exit; |
| 786 | 786 | } |
| 787 | -add_action( 'wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation' ); |
|
| 788 | -add_action( 'wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation' ); |
|
| 787 | +add_action('wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation'); |
|
| 788 | +add_action('wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation'); |
|
| 789 | 789 | |
| 790 | 790 | // Set up the template for the invoice. |
| 791 | -function wpinv_template( $template ) { |
|
| 791 | +function wpinv_template($template) { |
|
| 792 | 792 | global $post, $wp_query; |
| 793 | 793 | |
| 794 | - if ( ( is_single() || is_404() ) && !empty( $post->ID ) && (get_post_type( $post->ID ) == 'wpi_invoice' or get_post_type( $post->ID ) == 'wpi_quote')) { |
|
| 795 | - if ( wpinv_user_can_print_invoice( $post->ID ) ) { |
|
| 796 | - $template = wpinv_get_template_part( 'wpinv-invoice-print', false, false ); |
|
| 794 | + if ((is_single() || is_404()) && !empty($post->ID) && (get_post_type($post->ID) == 'wpi_invoice' or get_post_type($post->ID) == 'wpi_quote')) { |
|
| 795 | + if (wpinv_user_can_print_invoice($post->ID)) { |
|
| 796 | + $template = wpinv_get_template_part('wpinv-invoice-print', false, false); |
|
| 797 | 797 | } else { |
| 798 | - if ( !is_user_logged_in() && !empty( $_REQUEST['_wpipay'] ) && $invoice = wpinv_get_invoice( $post->ID ) ) { |
|
| 798 | + if (!is_user_logged_in() && !empty($_REQUEST['_wpipay']) && $invoice = wpinv_get_invoice($post->ID)) { |
|
| 799 | 799 | $user_id = $invoice->get_user_id(); |
| 800 | - $secret = sanitize_text_field( $_GET['_wpipay'] ); |
|
| 800 | + $secret = sanitize_text_field($_GET['_wpipay']); |
|
| 801 | 801 | |
| 802 | - if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice->get_key() ) ) { // valid invoice link |
|
| 803 | - $redirect_to = remove_query_arg( '_wpipay', get_permalink() ); |
|
| 802 | + if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice->get_key())) { // valid invoice link |
|
| 803 | + $redirect_to = remove_query_arg('_wpipay', get_permalink()); |
|
| 804 | 804 | |
| 805 | - wpinv_guest_redirect( $redirect_to, $user_id ); |
|
| 805 | + wpinv_guest_redirect($redirect_to, $user_id); |
|
| 806 | 806 | wpinv_die(); |
| 807 | 807 | } |
| 808 | 808 | } |
| 809 | - $redirect_to = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() ); |
|
| 809 | + $redirect_to = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink()); |
|
| 810 | 810 | |
| 811 | - wp_redirect( $redirect_to ); |
|
| 811 | + wp_redirect($redirect_to); |
|
| 812 | 812 | wpinv_die(); |
| 813 | 813 | } |
| 814 | 814 | } |
@@ -818,7 +818,7 @@ discard block |
||
| 818 | 818 | |
| 819 | 819 | function wpinv_get_business_address() { |
| 820 | 820 | $business_address = wpinv_store_address(); |
| 821 | - $business_address = !empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : ''; |
|
| 821 | + $business_address = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : ''; |
|
| 822 | 822 | |
| 823 | 823 | /* |
| 824 | 824 | $default_country = wpinv_get_default_country(); |
@@ -842,7 +842,7 @@ discard block |
||
| 842 | 842 | |
| 843 | 843 | $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : ''; |
| 844 | 844 | |
| 845 | - return apply_filters( 'wpinv_get_business_address', $business_address ); |
|
| 845 | + return apply_filters('wpinv_get_business_address', $business_address); |
|
| 846 | 846 | } |
| 847 | 847 | |
| 848 | 848 | function wpinv_display_from_address() { |
@@ -852,185 +852,185 @@ discard block |
||
| 852 | 852 | if (empty($from_name)) { |
| 853 | 853 | $from_name = wpinv_get_business_name(); |
| 854 | 854 | } |
| 855 | - ?><div class="from col-xs-2"><strong><?php _e( 'From:', 'invoicing' ) ?></strong></div> |
|
| 855 | + ?><div class="from col-xs-2"><strong><?php _e('From:', 'invoicing') ?></strong></div> |
|
| 856 | 856 | <div class="wrapper col-xs-10"> |
| 857 | - <div class="name"><?php echo esc_html( $from_name ); ?></div> |
|
| 858 | - <?php if ( $address = wpinv_get_business_address() ) { ?> |
|
| 859 | - <div class="address"><?php echo wpautop( wp_kses_post( $address ) );?></div> |
|
| 857 | + <div class="name"><?php echo esc_html($from_name); ?></div> |
|
| 858 | + <?php if ($address = wpinv_get_business_address()) { ?> |
|
| 859 | + <div class="address"><?php echo wpautop(wp_kses_post($address)); ?></div> |
|
| 860 | 860 | <?php } ?> |
| 861 | - <?php if ( $email_from = wpinv_mail_get_from_address() ) { ?> |
|
| 862 | - <div class="email_from"><?php echo wp_sprintf( __( 'Email: %s' ), $email_from );?></div> |
|
| 861 | + <?php if ($email_from = wpinv_mail_get_from_address()) { ?> |
|
| 862 | + <div class="email_from"><?php echo wp_sprintf(__('Email: %s'), $email_from); ?></div> |
|
| 863 | 863 | <?php } ?> |
| 864 | 864 | </div> |
| 865 | 865 | <?php |
| 866 | 866 | } |
| 867 | 867 | |
| 868 | -function wpinv_watermark( $id = 0 ) { |
|
| 869 | - $output = wpinv_get_watermark( $id ); |
|
| 868 | +function wpinv_watermark($id = 0) { |
|
| 869 | + $output = wpinv_get_watermark($id); |
|
| 870 | 870 | |
| 871 | - return apply_filters( 'wpinv_get_watermark', $output, $id ); |
|
| 871 | + return apply_filters('wpinv_get_watermark', $output, $id); |
|
| 872 | 872 | } |
| 873 | 873 | |
| 874 | -function wpinv_get_watermark( $id ) { |
|
| 875 | - if ( !$id > 0 ) { |
|
| 874 | +function wpinv_get_watermark($id) { |
|
| 875 | + if (!$id > 0) { |
|
| 876 | 876 | return NULL; |
| 877 | 877 | } |
| 878 | - $invoice = wpinv_get_invoice( $id ); |
|
| 878 | + $invoice = wpinv_get_invoice($id); |
|
| 879 | 879 | |
| 880 | - if ( !empty( $invoice ) ) { |
|
| 881 | - if ( $invoice->is_paid() ) { |
|
| 882 | - return __( 'Paid', 'invoicing' ); |
|
| 880 | + if (!empty($invoice)) { |
|
| 881 | + if ($invoice->is_paid()) { |
|
| 882 | + return __('Paid', 'invoicing'); |
|
| 883 | 883 | } |
| 884 | - if ( $invoice->has_status( array( 'wpi-cancelled' ) ) ) { |
|
| 885 | - return __( 'Cancelled', 'invoicing' ); |
|
| 884 | + if ($invoice->has_status(array('wpi-cancelled'))) { |
|
| 885 | + return __('Cancelled', 'invoicing'); |
|
| 886 | 886 | } |
| 887 | 887 | } |
| 888 | 888 | |
| 889 | 889 | return NULL; |
| 890 | 890 | } |
| 891 | 891 | |
| 892 | -function wpinv_display_invoice_details( $invoice ) { |
|
| 892 | +function wpinv_display_invoice_details($invoice) { |
|
| 893 | 893 | global $wpinv_euvat; |
| 894 | 894 | |
| 895 | 895 | $invoice_id = $invoice->ID; |
| 896 | 896 | $vat_name = $wpinv_euvat->get_vat_name(); |
| 897 | 897 | $use_taxes = wpinv_use_taxes(); |
| 898 | 898 | |
| 899 | - $invoice_status = wpinv_get_invoice_status( $invoice_id ); |
|
| 899 | + $invoice_status = wpinv_get_invoice_status($invoice_id); |
|
| 900 | 900 | |
| 901 | - if($invoice->post_type == 'wpi_invoice') $type = 'Invoice'; |
|
| 902 | - elseif($invoice->post_type == 'wpi_quote') $type = 'Quote'; |
|
| 901 | + if ($invoice->post_type == 'wpi_invoice') $type = 'Invoice'; |
|
| 902 | + elseif ($invoice->post_type == 'wpi_quote') $type = 'Quote'; |
|
| 903 | 903 | ?> |
| 904 | 904 | <table class="table table-bordered table-sm"> |
| 905 | - <?php if ( $invoice_number = wpinv_get_invoice_number( $invoice_id ) ) { ?> |
|
| 905 | + <?php if ($invoice_number = wpinv_get_invoice_number($invoice_id)) { ?> |
|
| 906 | 906 | <tr class="wpi-row-number"> |
| 907 | - <th><?php echo sprintf(__( '%s Number', 'invoicing' ), $type); ?></th> |
|
| 908 | - <td><?php echo esc_html( $invoice_number ); ?></td> |
|
| 907 | + <th><?php echo sprintf(__('%s Number', 'invoicing'), $type); ?></th> |
|
| 908 | + <td><?php echo esc_html($invoice_number); ?></td> |
|
| 909 | 909 | </tr> |
| 910 | 910 | <?php } ?> |
| 911 | 911 | <tr class="wpi-row-status"> |
| 912 | - <th><?php echo wp_sprintf(__( '%s Status', 'invoicing' ), $type); ?></th> |
|
| 913 | - <td><?php echo wpinv_invoice_status_label( $invoice_status, wpinv_get_invoice_status( $invoice_id, true ) ); ?></td> |
|
| 912 | + <th><?php echo wp_sprintf(__('%s Status', 'invoicing'), $type); ?></th> |
|
| 913 | + <td><?php echo wpinv_invoice_status_label($invoice_status, wpinv_get_invoice_status($invoice_id, true)); ?></td> |
|
| 914 | 914 | </tr> |
| 915 | - <?php if ( $invoice->is_renewal() ) { ?> |
|
| 915 | + <?php if ($invoice->is_renewal()) { ?> |
|
| 916 | 916 | <tr class="wpi-row-parent"> |
| 917 | - <th><?php echo wp_sprintf(__( 'Parent %s', 'invoicing' ), $type); ?></th> |
|
| 918 | - <td><?php echo wpinv_invoice_link( $invoice->parent_invoice ); ?></td> |
|
| 917 | + <th><?php echo wp_sprintf(__('Parent %s', 'invoicing'), $type); ?></th> |
|
| 918 | + <td><?php echo wpinv_invoice_link($invoice->parent_invoice); ?></td> |
|
| 919 | 919 | </tr> |
| 920 | 920 | <?php } ?> |
| 921 | 921 | <tr class="wpi-row-gateway"> |
| 922 | - <th><?php _e( 'Payment Method', 'invoicing' ); ?></th> |
|
| 923 | - <td><?php echo wpinv_get_payment_gateway_name( $invoice_id ); ?></td> |
|
| 922 | + <th><?php _e('Payment Method', 'invoicing'); ?></th> |
|
| 923 | + <td><?php echo wpinv_get_payment_gateway_name($invoice_id); ?></td> |
|
| 924 | 924 | </tr> |
| 925 | - <?php if ( $invoice_date = wpinv_get_invoice_date( $invoice_id ) ) { ?> |
|
| 925 | + <?php if ($invoice_date = wpinv_get_invoice_date($invoice_id)) { ?> |
|
| 926 | 926 | <tr class="wpi-row-date"> |
| 927 | - <th><?php echo wp_sprintf(__( '%s Date', 'invoicing' ), $type); ?></th> |
|
| 927 | + <th><?php echo wp_sprintf(__('%s Date', 'invoicing'), $type); ?></th> |
|
| 928 | 928 | <td><?php echo $invoice_date; ?></td> |
| 929 | 929 | </tr> |
| 930 | 930 | <?php } ?> |
| 931 | - <?php if ( wpinv_get_option( 'overdue_active' ) && $invoice->needs_payment() && ( $due_date = $invoice->get_due_date( true ) ) ) { ?> |
|
| 931 | + <?php if (wpinv_get_option('overdue_active') && $invoice->needs_payment() && ($due_date = $invoice->get_due_date(true))) { ?> |
|
| 932 | 932 | <tr class="wpi-row-date"> |
| 933 | - <th><?php _e( 'Due Date', 'invoicing' ); ?></th> |
|
| 933 | + <th><?php _e('Due Date', 'invoicing'); ?></th> |
|
| 934 | 934 | <td><?php echo $due_date; ?></td> |
| 935 | 935 | </tr> |
| 936 | 936 | <?php } ?> |
| 937 | - <?php if ( $owner_vat_number = $wpinv_euvat->get_vat_number() ) { ?> |
|
| 937 | + <?php if ($owner_vat_number = $wpinv_euvat->get_vat_number()) { ?> |
|
| 938 | 938 | <tr class="wpi-row-ovatno"> |
| 939 | - <th><?php echo wp_sprintf( __( 'Owner %s Number', 'invoicing' ), $vat_name ); ?></th> |
|
| 939 | + <th><?php echo wp_sprintf(__('Owner %s Number', 'invoicing'), $vat_name); ?></th> |
|
| 940 | 940 | <td><?php echo $owner_vat_number; ?></td> |
| 941 | 941 | </tr> |
| 942 | 942 | <?php } ?> |
| 943 | - <?php if ( $use_taxes && $user_vat_number = wpinv_get_invoice_vat_number( $invoice_id ) ) { ?> |
|
| 943 | + <?php if ($use_taxes && $user_vat_number = wpinv_get_invoice_vat_number($invoice_id)) { ?> |
|
| 944 | 944 | <tr class="wpi-row-uvatno"> |
| 945 | - <th><?php echo wp_sprintf( __( 'Your %s Number', 'invoicing' ), $vat_name ); ?></th> |
|
| 945 | + <th><?php echo wp_sprintf(__('Your %s Number', 'invoicing'), $vat_name); ?></th> |
|
| 946 | 946 | <td><?php echo $user_vat_number; ?></td> |
| 947 | 947 | </tr> |
| 948 | 948 | <?php } ?> |
| 949 | 949 | <tr class="table-active tr-total wpi-row-total"> |
| 950 | - <th><strong><?php _e( 'Total Amount', 'invoicing' ) ?></strong></th> |
|
| 951 | - <td><strong><?php echo wpinv_payment_total( $invoice_id, true ); ?></strong></td> |
|
| 950 | + <th><strong><?php _e('Total Amount', 'invoicing') ?></strong></th> |
|
| 951 | + <td><strong><?php echo wpinv_payment_total($invoice_id, true); ?></strong></td> |
|
| 952 | 952 | </tr> |
| 953 | 953 | </table> |
| 954 | 954 | <?php |
| 955 | 955 | } |
| 956 | 956 | |
| 957 | -function wpinv_display_to_address( $invoice_id = 0 ) { |
|
| 958 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 957 | +function wpinv_display_to_address($invoice_id = 0) { |
|
| 958 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 959 | 959 | |
| 960 | - if ( empty( $invoice ) ) { |
|
| 960 | + if (empty($invoice)) { |
|
| 961 | 961 | return NULL; |
| 962 | 962 | } |
| 963 | 963 | |
| 964 | 964 | $billing_details = $invoice->get_user_info(); |
| 965 | - $output = '<div class="to col-xs-2"><strong>' . __( 'To:', 'invoicing' ) . '</strong></div>'; |
|
| 965 | + $output = '<div class="to col-xs-2"><strong>' . __('To:', 'invoicing') . '</strong></div>'; |
|
| 966 | 966 | $output .= '<div class="wrapper col-xs-10">'; |
| 967 | 967 | |
| 968 | 968 | ob_start(); |
| 969 | - do_action( 'wpinv_display_to_address_top', $invoice ); |
|
| 969 | + do_action('wpinv_display_to_address_top', $invoice); |
|
| 970 | 970 | $output .= ob_get_clean(); |
| 971 | 971 | |
| 972 | - $output .= '<div class="name">' . esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) . '</div>'; |
|
| 973 | - if ( $company = $billing_details['company'] ) { |
|
| 974 | - $output .= '<div class="company">' . wpautop( wp_kses_post( $company ) ) . '</div>'; |
|
| 972 | + $output .= '<div class="name">' . esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])) . '</div>'; |
|
| 973 | + if ($company = $billing_details['company']) { |
|
| 974 | + $output .= '<div class="company">' . wpautop(wp_kses_post($company)) . '</div>'; |
|
| 975 | 975 | } |
| 976 | 976 | $address_row = ''; |
| 977 | - if ( $address = $billing_details['address'] ) { |
|
| 978 | - $address_row .= wpautop( wp_kses_post( $address ) ); |
|
| 977 | + if ($address = $billing_details['address']) { |
|
| 978 | + $address_row .= wpautop(wp_kses_post($address)); |
|
| 979 | 979 | } |
| 980 | 980 | |
| 981 | 981 | $address_fields = array(); |
| 982 | - if ( !empty( $billing_details['city'] ) ) { |
|
| 982 | + if (!empty($billing_details['city'])) { |
|
| 983 | 983 | $address_fields[] = $billing_details['city']; |
| 984 | 984 | } |
| 985 | 985 | |
| 986 | - $billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : ''; |
|
| 987 | - if ( !empty( $billing_details['state'] ) ) { |
|
| 988 | - $address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country ); |
|
| 986 | + $billing_country = !empty($billing_details['country']) ? $billing_details['country'] : ''; |
|
| 987 | + if (!empty($billing_details['state'])) { |
|
| 988 | + $address_fields[] = wpinv_state_name($billing_details['state'], $billing_country); |
|
| 989 | 989 | } |
| 990 | 990 | |
| 991 | - if ( !empty( $billing_country ) ) { |
|
| 992 | - $address_fields[] = wpinv_country_name( $billing_country ); |
|
| 991 | + if (!empty($billing_country)) { |
|
| 992 | + $address_fields[] = wpinv_country_name($billing_country); |
|
| 993 | 993 | } |
| 994 | 994 | |
| 995 | - if ( !empty( $address_fields ) ) { |
|
| 996 | - $address_fields = implode( ", ", $address_fields ); |
|
| 995 | + if (!empty($address_fields)) { |
|
| 996 | + $address_fields = implode(", ", $address_fields); |
|
| 997 | 997 | |
| 998 | - if ( !empty( $billing_details['zip'] ) ) { |
|
| 998 | + if (!empty($billing_details['zip'])) { |
|
| 999 | 999 | $address_fields .= ' ' . $billing_details['zip']; |
| 1000 | 1000 | } |
| 1001 | 1001 | |
| 1002 | - $address_row .= wpautop( wp_kses_post( $address_fields ) ); |
|
| 1002 | + $address_row .= wpautop(wp_kses_post($address_fields)); |
|
| 1003 | 1003 | } |
| 1004 | 1004 | |
| 1005 | - if ( $address_row ) { |
|
| 1005 | + if ($address_row) { |
|
| 1006 | 1006 | $output .= '<div class="address">' . $address_row . '</div>'; |
| 1007 | 1007 | } |
| 1008 | 1008 | |
| 1009 | - if ( $phone = $invoice->get_phone() ) { |
|
| 1010 | - $output .= '<div class="phone">' . wp_sprintf( __( 'Phone: %s' ), esc_html( $phone ) ) . '</div>'; |
|
| 1009 | + if ($phone = $invoice->get_phone()) { |
|
| 1010 | + $output .= '<div class="phone">' . wp_sprintf(__('Phone: %s'), esc_html($phone)) . '</div>'; |
|
| 1011 | 1011 | } |
| 1012 | - if ( $email = $invoice->get_email() ) { |
|
| 1013 | - $output .= '<div class="email">' . wp_sprintf( __( 'Email: %s' ), esc_html( $email ) ) . '</div>'; |
|
| 1012 | + if ($email = $invoice->get_email()) { |
|
| 1013 | + $output .= '<div class="email">' . wp_sprintf(__('Email: %s'), esc_html($email)) . '</div>'; |
|
| 1014 | 1014 | } |
| 1015 | 1015 | |
| 1016 | 1016 | ob_start(); |
| 1017 | - do_action( 'wpinv_display_to_address_bottom', $invoice ); |
|
| 1017 | + do_action('wpinv_display_to_address_bottom', $invoice); |
|
| 1018 | 1018 | $output .= ob_get_clean(); |
| 1019 | 1019 | |
| 1020 | 1020 | $output .= '</div>'; |
| 1021 | - $output = apply_filters( 'wpinv_display_to_address', $output, $invoice ); |
|
| 1021 | + $output = apply_filters('wpinv_display_to_address', $output, $invoice); |
|
| 1022 | 1022 | |
| 1023 | 1023 | echo $output; |
| 1024 | 1024 | } |
| 1025 | 1025 | |
| 1026 | -function wpinv_display_line_items( $invoice_id = 0 ) { |
|
| 1026 | +function wpinv_display_line_items($invoice_id = 0) { |
|
| 1027 | 1027 | global $wpinv_euvat, $ajax_cart_details; |
| 1028 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 1028 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 1029 | 1029 | $quantities_enabled = wpinv_item_quantities_enabled(); |
| 1030 | 1030 | $use_taxes = wpinv_use_taxes(); |
| 1031 | 1031 | $zero_tax = !(float)$invoice->get_tax() > 0 ? true : false; |
| 1032 | - $tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __( 'Tax', 'invoicing' ); |
|
| 1033 | - $tax_title = !$zero_tax && $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : ''; |
|
| 1032 | + $tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __('Tax', 'invoicing'); |
|
| 1033 | + $tax_title = !$zero_tax && $use_taxes ? (wpinv_prices_include_tax() ? wp_sprintf(__('(%s Incl.)', 'invoicing'), $tax_label) : wp_sprintf(__('(%s Excl.)', 'invoicing'), $tax_label)) : ''; |
|
| 1034 | 1034 | |
| 1035 | 1035 | $cart_details = $invoice->get_cart_details(); |
| 1036 | 1036 | $ajax_cart_details = $cart_details; |
@@ -1039,68 +1039,68 @@ discard block |
||
| 1039 | 1039 | <table class="table table-sm table-bordered table-responsive"> |
| 1040 | 1040 | <thead> |
| 1041 | 1041 | <tr> |
| 1042 | - <th class="name"><strong><?php _e( "Item Name", "invoicing" );?></strong></th> |
|
| 1043 | - <th class="rate"><strong><?php _e( "Price", "invoicing" );?></strong></th> |
|
| 1042 | + <th class="name"><strong><?php _e("Item Name", "invoicing"); ?></strong></th> |
|
| 1043 | + <th class="rate"><strong><?php _e("Price", "invoicing"); ?></strong></th> |
|
| 1044 | 1044 | <?php if ($quantities_enabled) { ?> |
| 1045 | - <th class="qty"><strong><?php _e( "Qty", "invoicing" );?></strong></th> |
|
| 1045 | + <th class="qty"><strong><?php _e("Qty", "invoicing"); ?></strong></th> |
|
| 1046 | 1046 | <?php } ?> |
| 1047 | 1047 | <?php if ($use_taxes && !$zero_tax) { ?> |
| 1048 | 1048 | <th class="tax"><strong><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></strong></th> |
| 1049 | 1049 | <?php } ?> |
| 1050 | - <th class="total"><strong><?php echo __( "Item Total", "invoicing" ) . ' <span class="normal small">' . $tax_title . '<span>';?></strong></th> |
|
| 1050 | + <th class="total"><strong><?php echo __("Item Total", "invoicing") . ' <span class="normal small">' . $tax_title . '<span>'; ?></strong></th> |
|
| 1051 | 1051 | </tr> |
| 1052 | 1052 | </thead> |
| 1053 | 1053 | <tbody> |
| 1054 | 1054 | <?php |
| 1055 | - if ( !empty( $cart_details ) ) { |
|
| 1056 | - do_action( 'wpinv_display_line_items_start', $invoice ); |
|
| 1055 | + if (!empty($cart_details)) { |
|
| 1056 | + do_action('wpinv_display_line_items_start', $invoice); |
|
| 1057 | 1057 | |
| 1058 | 1058 | $count = 0; |
| 1059 | 1059 | $cols = 3; |
| 1060 | - foreach ( $cart_details as $key => $cart_item ) { |
|
| 1061 | - $item_id = !empty($cart_item['id']) ? absint( $cart_item['id'] ) : ''; |
|
| 1062 | - $item_price = isset($cart_item["item_price"]) ? wpinv_round_amount( $cart_item["item_price"] ) : 0; |
|
| 1063 | - $line_total = isset($cart_item["subtotal"]) ? wpinv_round_amount( $cart_item["subtotal"] ) : 0; |
|
| 1064 | - $quantity = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint( $cart_item['quantity'] ) : 1; |
|
| 1060 | + foreach ($cart_details as $key => $cart_item) { |
|
| 1061 | + $item_id = !empty($cart_item['id']) ? absint($cart_item['id']) : ''; |
|
| 1062 | + $item_price = isset($cart_item["item_price"]) ? wpinv_round_amount($cart_item["item_price"]) : 0; |
|
| 1063 | + $line_total = isset($cart_item["subtotal"]) ? wpinv_round_amount($cart_item["subtotal"]) : 0; |
|
| 1064 | + $quantity = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint($cart_item['quantity']) : 1; |
|
| 1065 | 1065 | |
| 1066 | - $item = $item_id ? new WPInv_Item( $item_id ) : NULL; |
|
| 1066 | + $item = $item_id ? new WPInv_Item($item_id) : NULL; |
|
| 1067 | 1067 | $summary = ''; |
| 1068 | 1068 | $cols = 3; |
| 1069 | - if ( !empty($item) ) { |
|
| 1069 | + if (!empty($item)) { |
|
| 1070 | 1070 | $item_name = $item->get_name(); |
| 1071 | 1071 | $summary = $item->get_summary(); |
| 1072 | 1072 | } |
| 1073 | - $item_name = !empty($cart_item['name']) ? $cart_item['name'] : $item_name; |
|
| 1073 | + $item_name = !empty($cart_item['name']) ? $cart_item['name'] : $item_name; |
|
| 1074 | 1074 | |
| 1075 | 1075 | if (!empty($item) && $item->is_package() && !empty($cart_item['meta']['post_id'])) { |
| 1076 | - $post_link = '<a href="' . get_edit_post_link( $cart_item['meta']['post_id'] ) .'" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title( $cart_item['meta']['post_id']) ) . '</a>'; |
|
| 1077 | - $summary = wp_sprintf( __( '%s: %s', 'invoicing' ), $item->get_custom_singular_name(), $post_link ); |
|
| 1076 | + $post_link = '<a href="' . get_edit_post_link($cart_item['meta']['post_id']) . '" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title($cart_item['meta']['post_id'])) . '</a>'; |
|
| 1077 | + $summary = wp_sprintf(__('%s: %s', 'invoicing'), $item->get_custom_singular_name(), $post_link); |
|
| 1078 | 1078 | } |
| 1079 | - $summary = apply_filters( 'wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice ); |
|
| 1079 | + $summary = apply_filters('wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice); |
|
| 1080 | 1080 | |
| 1081 | 1081 | $item_tax = ''; |
| 1082 | 1082 | $tax_rate = ''; |
| 1083 | - if ( $use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) { |
|
| 1084 | - $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ) ); |
|
| 1085 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100; |
|
| 1086 | - $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : ''; |
|
| 1083 | + if ($use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) { |
|
| 1084 | + $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax'])); |
|
| 1085 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100; |
|
| 1086 | + $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate, 4) : ''; |
|
| 1087 | 1087 | $tax_rate = $tax_rate != '' ? ' <small class="tax-rate">(' . $tax_rate . '%)</small>' : ''; |
| 1088 | 1088 | } |
| 1089 | 1089 | |
| 1090 | 1090 | $line_item_tax = $item_tax . $tax_rate; |
| 1091 | 1091 | |
| 1092 | - if ( $line_item_tax === '' ) { |
|
| 1092 | + if ($line_item_tax === '') { |
|
| 1093 | 1093 | $line_item_tax = 0; // Zero tax |
| 1094 | 1094 | } |
| 1095 | 1095 | |
| 1096 | - $line_item = '<tr class="row-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . ' wpinv-item">'; |
|
| 1097 | - $line_item .= '<td class="name">' . esc_html__( $item_name, 'invoicing' ) . wpinv_get_item_suffix( $item ); |
|
| 1098 | - if ( $summary !== '' ) { |
|
| 1099 | - $line_item .= '<br/><small class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</small>'; |
|
| 1096 | + $line_item = '<tr class="row-' . (($count % 2 == 0) ? 'even' : 'odd') . ' wpinv-item">'; |
|
| 1097 | + $line_item .= '<td class="name">' . esc_html__($item_name, 'invoicing') . wpinv_get_item_suffix($item); |
|
| 1098 | + if ($summary !== '') { |
|
| 1099 | + $line_item .= '<br/><small class="meta">' . wpautop(wp_kses_post($summary)) . '</small>'; |
|
| 1100 | 1100 | } |
| 1101 | 1101 | $line_item .= '</td>'; |
| 1102 | 1102 | |
| 1103 | - $line_item .= '<td class="rate">' . esc_html__( wpinv_price( wpinv_format_amount( $item_price ), $invoice->get_currency() ) ) . '</td>'; |
|
| 1103 | + $line_item .= '<td class="rate">' . esc_html__(wpinv_price(wpinv_format_amount($item_price), $invoice->get_currency())) . '</td>'; |
|
| 1104 | 1104 | if ($quantities_enabled) { |
| 1105 | 1105 | $cols++; |
| 1106 | 1106 | $line_item .= '<td class="qty">' . $quantity . '</td>'; |
@@ -1109,55 +1109,55 @@ discard block |
||
| 1109 | 1109 | $cols++; |
| 1110 | 1110 | $line_item .= '<td class="tax">' . $line_item_tax . '</td>'; |
| 1111 | 1111 | } |
| 1112 | - $line_item .= '<td class="total">' . esc_html__( wpinv_price( wpinv_format_amount( $line_total ), $invoice->get_currency() ) ) . '</td>'; |
|
| 1112 | + $line_item .= '<td class="total">' . esc_html__(wpinv_price(wpinv_format_amount($line_total), $invoice->get_currency())) . '</td>'; |
|
| 1113 | 1113 | $line_item .= '</tr>'; |
| 1114 | 1114 | |
| 1115 | - echo apply_filters( 'wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols ); |
|
| 1115 | + echo apply_filters('wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols); |
|
| 1116 | 1116 | |
| 1117 | 1117 | $count++; |
| 1118 | 1118 | } |
| 1119 | 1119 | |
| 1120 | - do_action( 'wpinv_display_before_subtotal', $invoice, $cols ); |
|
| 1120 | + do_action('wpinv_display_before_subtotal', $invoice, $cols); |
|
| 1121 | 1121 | ?> |
| 1122 | 1122 | <tr class="row-sub-total row_odd"> |
| 1123 | - <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_subtotal_label', '<strong>' . __( 'Sub Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td> |
|
| 1124 | - <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td> |
|
| 1123 | + <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_subtotal_label', '<strong>' . __('Sub Total', 'invoicing') . ':</strong>', $invoice); ?></td> |
|
| 1124 | + <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td> |
|
| 1125 | 1125 | </tr> |
| 1126 | 1126 | <?php |
| 1127 | - do_action( 'wpinv_display_after_subtotal', $invoice, $cols ); |
|
| 1127 | + do_action('wpinv_display_after_subtotal', $invoice, $cols); |
|
| 1128 | 1128 | |
| 1129 | - if ( wpinv_discount( $invoice_id, false ) > 0 ) { |
|
| 1130 | - do_action( 'wpinv_display_before_discount', $invoice, $cols ); |
|
| 1129 | + if (wpinv_discount($invoice_id, false) > 0) { |
|
| 1130 | + do_action('wpinv_display_before_discount', $invoice, $cols); |
|
| 1131 | 1131 | ?> |
| 1132 | 1132 | <tr class="row-discount"> |
| 1133 | - <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?>:</td> |
|
| 1134 | - <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td> |
|
| 1133 | + <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?>:</td> |
|
| 1134 | + <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td> |
|
| 1135 | 1135 | </tr> |
| 1136 | 1136 | <?php |
| 1137 | - do_action( 'wpinv_display_after_discount', $invoice, $cols ); |
|
| 1137 | + do_action('wpinv_display_after_discount', $invoice, $cols); |
|
| 1138 | 1138 | } |
| 1139 | 1139 | |
| 1140 | - if ( $use_taxes ) { |
|
| 1141 | - do_action( 'wpinv_display_before_tax', $invoice, $cols ); |
|
| 1140 | + if ($use_taxes) { |
|
| 1141 | + do_action('wpinv_display_before_tax', $invoice, $cols); |
|
| 1142 | 1142 | ?> |
| 1143 | 1143 | <tr class="row-tax"> |
| 1144 | - <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice ); ?></td> |
|
| 1145 | - <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td> |
|
| 1144 | + <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice); ?></td> |
|
| 1145 | + <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td> |
|
| 1146 | 1146 | </tr> |
| 1147 | 1147 | <?php |
| 1148 | - do_action( 'wpinv_display_after_tax', $invoice, $cols ); |
|
| 1148 | + do_action('wpinv_display_after_tax', $invoice, $cols); |
|
| 1149 | 1149 | } |
| 1150 | 1150 | |
| 1151 | - do_action( 'wpinv_display_before_total', $invoice, $cols ); |
|
| 1151 | + do_action('wpinv_display_before_total', $invoice, $cols); |
|
| 1152 | 1152 | ?> |
| 1153 | 1153 | <tr class="table-active row-total"> |
| 1154 | - <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_total_label', '<strong>' . __( 'Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td> |
|
| 1155 | - <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td> |
|
| 1154 | + <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_total_label', '<strong>' . __('Total', 'invoicing') . ':</strong>', $invoice); ?></td> |
|
| 1155 | + <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td> |
|
| 1156 | 1156 | </tr> |
| 1157 | 1157 | <?php |
| 1158 | - do_action( 'wpinv_display_after_total', $invoice, $cols ); |
|
| 1158 | + do_action('wpinv_display_after_total', $invoice, $cols); |
|
| 1159 | 1159 | |
| 1160 | - do_action( 'wpinv_display_line_end', $invoice, $cols ); |
|
| 1160 | + do_action('wpinv_display_line_end', $invoice, $cols); |
|
| 1161 | 1161 | } |
| 1162 | 1162 | ?> |
| 1163 | 1163 | </tbody> |
@@ -1166,35 +1166,35 @@ discard block |
||
| 1166 | 1166 | echo ob_get_clean(); |
| 1167 | 1167 | } |
| 1168 | 1168 | |
| 1169 | -function wpinv_display_invoice_totals( $invoice_id = 0 ) { |
|
| 1169 | +function wpinv_display_invoice_totals($invoice_id = 0) { |
|
| 1170 | 1170 | $use_taxes = wpinv_use_taxes(); |
| 1171 | 1171 | |
| 1172 | - do_action( 'wpinv_before_display_totals_table', $invoice_id ); |
|
| 1172 | + do_action('wpinv_before_display_totals_table', $invoice_id); |
|
| 1173 | 1173 | ?> |
| 1174 | 1174 | <table class="table table-sm table-bordered table-responsive"> |
| 1175 | 1175 | <tbody> |
| 1176 | - <?php do_action( 'wpinv_before_display_totals' ); ?> |
|
| 1176 | + <?php do_action('wpinv_before_display_totals'); ?> |
|
| 1177 | 1177 | <tr class="row-sub-total"> |
| 1178 | - <td class="rate"><strong><?php _e( 'Sub Total', 'invoicing' ); ?></strong></td> |
|
| 1179 | - <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td> |
|
| 1178 | + <td class="rate"><strong><?php _e('Sub Total', 'invoicing'); ?></strong></td> |
|
| 1179 | + <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td> |
|
| 1180 | 1180 | </tr> |
| 1181 | - <?php do_action( 'wpinv_after_display_totals' ); ?> |
|
| 1182 | - <?php if ( wpinv_discount( $invoice_id, false ) > 0 ) { ?> |
|
| 1181 | + <?php do_action('wpinv_after_display_totals'); ?> |
|
| 1182 | + <?php if (wpinv_discount($invoice_id, false) > 0) { ?> |
|
| 1183 | 1183 | <tr class="row-discount"> |
| 1184 | - <td class="rate"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?></td> |
|
| 1185 | - <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td> |
|
| 1184 | + <td class="rate"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?></td> |
|
| 1185 | + <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td> |
|
| 1186 | 1186 | </tr> |
| 1187 | - <?php do_action( 'wpinv_after_display_discount' ); ?> |
|
| 1187 | + <?php do_action('wpinv_after_display_discount'); ?> |
|
| 1188 | 1188 | <?php } ?> |
| 1189 | - <?php if ( $use_taxes ) { ?> |
|
| 1189 | + <?php if ($use_taxes) { ?> |
|
| 1190 | 1190 | <tr class="row-tax"> |
| 1191 | - <td class="rate"><?php _e( 'Tax', 'invoicing' ); ?></td> |
|
| 1192 | - <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td> |
|
| 1191 | + <td class="rate"><?php _e('Tax', 'invoicing'); ?></td> |
|
| 1192 | + <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td> |
|
| 1193 | 1193 | </tr> |
| 1194 | - <?php do_action( 'wpinv_after_display_tax' ); ?> |
|
| 1194 | + <?php do_action('wpinv_after_display_tax'); ?> |
|
| 1195 | 1195 | <?php } ?> |
| 1196 | - <?php if ( $fees = wpinv_get_fees( $invoice_id ) ) { ?> |
|
| 1197 | - <?php foreach ( $fees as $fee ) { ?> |
|
| 1196 | + <?php if ($fees = wpinv_get_fees($invoice_id)) { ?> |
|
| 1197 | + <?php foreach ($fees as $fee) { ?> |
|
| 1198 | 1198 | <tr class="row-fee"> |
| 1199 | 1199 | <td class="rate"><?php echo $fee['label']; ?></td> |
| 1200 | 1200 | <td class="total"><?php echo $fee['amount_display']; ?></td> |
@@ -1202,72 +1202,72 @@ discard block |
||
| 1202 | 1202 | <?php } ?> |
| 1203 | 1203 | <?php } ?> |
| 1204 | 1204 | <tr class="table-active row-total"> |
| 1205 | - <td class="rate"><strong><?php _e( 'Total', 'invoicing' ) ?></strong></td> |
|
| 1206 | - <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td> |
|
| 1205 | + <td class="rate"><strong><?php _e('Total', 'invoicing') ?></strong></td> |
|
| 1206 | + <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td> |
|
| 1207 | 1207 | </tr> |
| 1208 | - <?php do_action( 'wpinv_after_totals' ); ?> |
|
| 1208 | + <?php do_action('wpinv_after_totals'); ?> |
|
| 1209 | 1209 | </tbody> |
| 1210 | 1210 | |
| 1211 | 1211 | </table> |
| 1212 | 1212 | |
| 1213 | - <?php do_action( 'wpinv_after_totals_table' ); |
|
| 1213 | + <?php do_action('wpinv_after_totals_table'); |
|
| 1214 | 1214 | } |
| 1215 | 1215 | |
| 1216 | -function wpinv_display_payments_info( $invoice_id = 0, $echo = true ) { |
|
| 1217 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 1216 | +function wpinv_display_payments_info($invoice_id = 0, $echo = true) { |
|
| 1217 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 1218 | 1218 | |
| 1219 | 1219 | ob_start(); |
| 1220 | - do_action( 'wpinv_before_display_payments_info', $invoice_id ); |
|
| 1221 | - if ( ( $gateway_title = $invoice->get_gateway_title() ) || $invoice->is_paid() ) { |
|
| 1220 | + do_action('wpinv_before_display_payments_info', $invoice_id); |
|
| 1221 | + if (($gateway_title = $invoice->get_gateway_title()) || $invoice->is_paid()) { |
|
| 1222 | 1222 | ?> |
| 1223 | 1223 | <div class="wpi-payment-info"> |
| 1224 | - <p class="wpi-payment-gateway"><?php echo wp_sprintf( __( 'Payment via %s', 'invoicing' ), $gateway_title ? $gateway_title : __( 'Manually', 'invoicing' ) ); ?></p> |
|
| 1225 | - <?php if ( $gateway_title ) { ?> |
|
| 1226 | - <p class="wpi-payment-transid"><?php echo wp_sprintf( __( 'Transaction ID: %s', 'invoicing' ), $invoice->get_transaction_id() ); ?></p> |
|
| 1224 | + <p class="wpi-payment-gateway"><?php echo wp_sprintf(__('Payment via %s', 'invoicing'), $gateway_title ? $gateway_title : __('Manually', 'invoicing')); ?></p> |
|
| 1225 | + <?php if ($gateway_title) { ?> |
|
| 1226 | + <p class="wpi-payment-transid"><?php echo wp_sprintf(__('Transaction ID: %s', 'invoicing'), $invoice->get_transaction_id()); ?></p> |
|
| 1227 | 1227 | <?php } ?> |
| 1228 | 1228 | </div> |
| 1229 | 1229 | <?php |
| 1230 | 1230 | } |
| 1231 | - do_action( 'wpinv_after_display_payments_info', $invoice_id ); |
|
| 1231 | + do_action('wpinv_after_display_payments_info', $invoice_id); |
|
| 1232 | 1232 | $outout = ob_get_clean(); |
| 1233 | 1233 | |
| 1234 | - if ( $echo ) { |
|
| 1234 | + if ($echo) { |
|
| 1235 | 1235 | echo $outout; |
| 1236 | 1236 | } else { |
| 1237 | 1237 | return $outout; |
| 1238 | 1238 | } |
| 1239 | 1239 | } |
| 1240 | 1240 | |
| 1241 | -function wpinv_display_style( $invoice ) { |
|
| 1242 | - wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION ); |
|
| 1241 | +function wpinv_display_style($invoice) { |
|
| 1242 | + wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION); |
|
| 1243 | 1243 | |
| 1244 | - wp_print_styles( 'open-sans' ); |
|
| 1245 | - wp_print_styles( 'wpinv-single-style' ); |
|
| 1244 | + wp_print_styles('open-sans'); |
|
| 1245 | + wp_print_styles('wpinv-single-style'); |
|
| 1246 | 1246 | } |
| 1247 | -add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' ); |
|
| 1247 | +add_action('wpinv_invoice_print_head', 'wpinv_display_style'); |
|
| 1248 | 1248 | |
| 1249 | 1249 | function wpinv_checkout_billing_details() { |
| 1250 | 1250 | $invoice_id = (int)wpinv_get_invoice_cart_id(); |
| 1251 | 1251 | if (empty($invoice_id)) { |
| 1252 | - wpinv_error_log( 'Invoice id not found', 'ERROR', __FILE__, __LINE__ ); |
|
| 1252 | + wpinv_error_log('Invoice id not found', 'ERROR', __FILE__, __LINE__); |
|
| 1253 | 1253 | return null; |
| 1254 | 1254 | } |
| 1255 | 1255 | |
| 1256 | - $invoice = wpinv_get_invoice_cart( $invoice_id ); |
|
| 1256 | + $invoice = wpinv_get_invoice_cart($invoice_id); |
|
| 1257 | 1257 | if (empty($invoice)) { |
| 1258 | - wpinv_error_log( 'Invoice not found', 'ERROR', __FILE__, __LINE__ ); |
|
| 1258 | + wpinv_error_log('Invoice not found', 'ERROR', __FILE__, __LINE__); |
|
| 1259 | 1259 | return null; |
| 1260 | 1260 | } |
| 1261 | 1261 | $user_id = $invoice->get_user_id(); |
| 1262 | 1262 | $user_info = $invoice->get_user_info(); |
| 1263 | - $address_info = wpinv_get_user_address( $user_id ); |
|
| 1263 | + $address_info = wpinv_get_user_address($user_id); |
|
| 1264 | 1264 | |
| 1265 | - if ( empty( $user_info['first_name'] ) && !empty( $user_info['first_name'] ) ) { |
|
| 1265 | + if (empty($user_info['first_name']) && !empty($user_info['first_name'])) { |
|
| 1266 | 1266 | $user_info['first_name'] = $user_info['first_name']; |
| 1267 | 1267 | $user_info['last_name'] = $user_info['last_name']; |
| 1268 | 1268 | } |
| 1269 | 1269 | |
| 1270 | - if ( ( ( empty( $user_info['country'] ) && !empty( $address_info['country'] ) ) || ( empty( $user_info['state'] ) && !empty( $address_info['state'] ) && $user_info['country'] == $address_info['country'] ) ) ) { |
|
| 1270 | + if (((empty($user_info['country']) && !empty($address_info['country'])) || (empty($user_info['state']) && !empty($address_info['state']) && $user_info['country'] == $address_info['country']))) { |
|
| 1271 | 1271 | $user_info['country'] = $address_info['country']; |
| 1272 | 1272 | $user_info['state'] = $address_info['state']; |
| 1273 | 1273 | $user_info['city'] = $address_info['city']; |
@@ -1283,103 +1283,103 @@ discard block |
||
| 1283 | 1283 | 'address' |
| 1284 | 1284 | ); |
| 1285 | 1285 | |
| 1286 | - foreach ( $address_fields as $field ) { |
|
| 1287 | - if ( empty( $user_info[$field] ) ) { |
|
| 1286 | + foreach ($address_fields as $field) { |
|
| 1287 | + if (empty($user_info[$field])) { |
|
| 1288 | 1288 | $user_info[$field] = $address_info[$field]; |
| 1289 | 1289 | } |
| 1290 | 1290 | } |
| 1291 | 1291 | |
| 1292 | - return apply_filters( 'wpinv_checkout_billing_details', $user_info, $invoice ); |
|
| 1292 | + return apply_filters('wpinv_checkout_billing_details', $user_info, $invoice); |
|
| 1293 | 1293 | } |
| 1294 | 1294 | |
| 1295 | 1295 | function wpinv_admin_get_line_items($invoice = array()) { |
| 1296 | 1296 | $item_quantities = wpinv_item_quantities_enabled(); |
| 1297 | 1297 | $use_taxes = wpinv_use_taxes(); |
| 1298 | 1298 | |
| 1299 | - if ( empty( $invoice ) ) { |
|
| 1299 | + if (empty($invoice)) { |
|
| 1300 | 1300 | return NULL; |
| 1301 | 1301 | } |
| 1302 | 1302 | |
| 1303 | 1303 | $cart_items = $invoice->get_cart_details(); |
| 1304 | - if ( empty( $cart_items ) ) { |
|
| 1304 | + if (empty($cart_items)) { |
|
| 1305 | 1305 | return NULL; |
| 1306 | 1306 | } |
| 1307 | 1307 | ob_start(); |
| 1308 | 1308 | |
| 1309 | - do_action( 'wpinv_admin_before_line_items', $cart_items, $invoice ); |
|
| 1309 | + do_action('wpinv_admin_before_line_items', $cart_items, $invoice); |
|
| 1310 | 1310 | |
| 1311 | 1311 | $count = 0; |
| 1312 | - foreach ( $cart_items as $key => $cart_item ) { |
|
| 1312 | + foreach ($cart_items as $key => $cart_item) { |
|
| 1313 | 1313 | $item_id = $cart_item['id']; |
| 1314 | - $wpi_item = $item_id > 0 ? new WPInv_Item( $item_id ) : NULL; |
|
| 1314 | + $wpi_item = $item_id > 0 ? new WPInv_Item($item_id) : NULL; |
|
| 1315 | 1315 | |
| 1316 | 1316 | if (empty($wpi_item)) { |
| 1317 | 1317 | continue; |
| 1318 | 1318 | } |
| 1319 | 1319 | |
| 1320 | - $item_price = wpinv_price( wpinv_format_amount( $cart_item['item_price'] ) ); |
|
| 1321 | - $quantity = !empty( $cart_item['quantity'] ) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1; |
|
| 1322 | - $item_subtotal = wpinv_price( wpinv_format_amount( $cart_item['subtotal'] ) ); |
|
| 1320 | + $item_price = wpinv_price(wpinv_format_amount($cart_item['item_price'])); |
|
| 1321 | + $quantity = !empty($cart_item['quantity']) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1; |
|
| 1322 | + $item_subtotal = wpinv_price(wpinv_format_amount($cart_item['subtotal'])); |
|
| 1323 | 1323 | $can_remove = true; |
| 1324 | 1324 | |
| 1325 | 1325 | $summary = ''; |
| 1326 | 1326 | if ($wpi_item->is_package() && !empty($cart_item['meta']['post_id'])) { |
| 1327 | - $post_link = '<a href="' . get_edit_post_link( $cart_item['meta']['post_id'] ) .'" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title( $cart_item['meta']['post_id']) ) . '</a>'; |
|
| 1328 | - $summary = wp_sprintf( __( '%s: %s', 'invoicing' ), $wpi_item->get_custom_singular_name(), $post_link ); |
|
| 1327 | + $post_link = '<a href="' . get_edit_post_link($cart_item['meta']['post_id']) . '" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title($cart_item['meta']['post_id'])) . '</a>'; |
|
| 1328 | + $summary = wp_sprintf(__('%s: %s', 'invoicing'), $wpi_item->get_custom_singular_name(), $post_link); |
|
| 1329 | 1329 | } |
| 1330 | - $summary = apply_filters( 'wpinv_admin_invoice_line_item_summary', $summary, $cart_item, $wpi_item, $invoice ); |
|
| 1330 | + $summary = apply_filters('wpinv_admin_invoice_line_item_summary', $summary, $cart_item, $wpi_item, $invoice); |
|
| 1331 | 1331 | |
| 1332 | 1332 | $item_tax = ''; |
| 1333 | 1333 | $tax_rate = ''; |
| 1334 | - if ( $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) { |
|
| 1335 | - $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ) ); |
|
| 1336 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100; |
|
| 1337 | - $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : ''; |
|
| 1334 | + if ($cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) { |
|
| 1335 | + $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax'])); |
|
| 1336 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100; |
|
| 1337 | + $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate, 4) : ''; |
|
| 1338 | 1338 | $tax_rate = $tax_rate != '' ? ' <span class="tax-rate">(' . $tax_rate . '%)</span>' : ''; |
| 1339 | 1339 | } |
| 1340 | 1340 | $line_item_tax = $item_tax . $tax_rate; |
| 1341 | 1341 | |
| 1342 | - if ( $line_item_tax === '' ) { |
|
| 1342 | + if ($line_item_tax === '') { |
|
| 1343 | 1343 | $line_item_tax = 0; // Zero tax |
| 1344 | 1344 | } |
| 1345 | 1345 | |
| 1346 | - $line_item = '<tr class="item item-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . '" data-item-id="' . $item_id . '">'; |
|
| 1346 | + $line_item = '<tr class="item item-' . (($count % 2 == 0) ? 'even' : 'odd') . '" data-item-id="' . $item_id . '">'; |
|
| 1347 | 1347 | $line_item .= '<td class="id">' . $item_id . '</td>'; |
| 1348 | - $line_item .= '<td class="title"><a href="' . get_edit_post_link( $item_id ) . '" target="_blank">' . $cart_item['name'] . '</a>' . wpinv_get_item_suffix( $wpi_item ); |
|
| 1349 | - if ( $summary !== '' ) { |
|
| 1350 | - $line_item .= '<span class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</span>'; |
|
| 1348 | + $line_item .= '<td class="title"><a href="' . get_edit_post_link($item_id) . '" target="_blank">' . $cart_item['name'] . '</a>' . wpinv_get_item_suffix($wpi_item); |
|
| 1349 | + if ($summary !== '') { |
|
| 1350 | + $line_item .= '<span class="meta">' . wpautop(wp_kses_post($summary)) . '</span>'; |
|
| 1351 | 1351 | } |
| 1352 | 1352 | $line_item .= '</td>'; |
| 1353 | 1353 | $line_item .= '<td class="price">' . $item_price . '</td>'; |
| 1354 | 1354 | |
| 1355 | - if ( $item_quantities ) { |
|
| 1356 | - if ( count( $cart_items ) == 1 && $quantity <= 1 ) { |
|
| 1355 | + if ($item_quantities) { |
|
| 1356 | + if (count($cart_items) == 1 && $quantity <= 1) { |
|
| 1357 | 1357 | $can_remove = false; |
| 1358 | 1358 | } |
| 1359 | 1359 | $line_item .= '<td class="qty" data-quantity="' . $quantity . '"> × ' . $quantity . '</td>'; |
| 1360 | 1360 | } else { |
| 1361 | - if ( count( $cart_items ) == 1 ) { |
|
| 1361 | + if (count($cart_items) == 1) { |
|
| 1362 | 1362 | $can_remove = false; |
| 1363 | 1363 | } |
| 1364 | 1364 | } |
| 1365 | 1365 | $line_item .= '<td class="total">' . $item_subtotal . '</td>'; |
| 1366 | 1366 | |
| 1367 | - if ( $use_taxes ) { |
|
| 1367 | + if ($use_taxes) { |
|
| 1368 | 1368 | $line_item .= '<td class="tax">' . $line_item_tax . '</td>'; |
| 1369 | 1369 | } |
| 1370 | 1370 | $line_item .= '<td class="action">'; |
| 1371 | - if ( !$invoice->is_paid() && $can_remove ) { |
|
| 1371 | + if (!$invoice->is_paid() && $can_remove) { |
|
| 1372 | 1372 | $line_item .= '<i class="fa fa-remove wpinv-item-remove"></i>'; |
| 1373 | 1373 | } |
| 1374 | 1374 | $line_item .= '</td>'; |
| 1375 | 1375 | $line_item .= '</tr>'; |
| 1376 | 1376 | |
| 1377 | - echo apply_filters( 'wpinv_admin_line_item', $line_item, $cart_item, $invoice ); |
|
| 1377 | + echo apply_filters('wpinv_admin_line_item', $line_item, $cart_item, $invoice); |
|
| 1378 | 1378 | |
| 1379 | 1379 | $count++; |
| 1380 | 1380 | } |
| 1381 | 1381 | |
| 1382 | - do_action( 'wpinv_admin_after_line_items', $cart_items, $invoice ); |
|
| 1382 | + do_action('wpinv_admin_after_line_items', $cart_items, $invoice); |
|
| 1383 | 1383 | |
| 1384 | 1384 | return ob_get_clean(); |
| 1385 | 1385 | } |
@@ -1390,35 +1390,35 @@ discard block |
||
| 1390 | 1390 | // Set current invoice id. |
| 1391 | 1391 | $wpi_checkout_id = wpinv_get_invoice_cart_id(); |
| 1392 | 1392 | |
| 1393 | - $form_action = esc_url( wpinv_get_checkout_uri() ); |
|
| 1393 | + $form_action = esc_url(wpinv_get_checkout_uri()); |
|
| 1394 | 1394 | |
| 1395 | 1395 | ob_start(); |
| 1396 | 1396 | echo '<div id="wpinv_checkout_wrap">'; |
| 1397 | 1397 | |
| 1398 | - if ( wpinv_get_cart_contents() || wpinv_cart_has_fees() ) { |
|
| 1398 | + if (wpinv_get_cart_contents() || wpinv_cart_has_fees()) { |
|
| 1399 | 1399 | ?> |
| 1400 | 1400 | <div id="wpinv_checkout_form_wrap" class="wpinv_clearfix table-responsive"> |
| 1401 | - <?php do_action( 'wpinv_before_checkout_form' ); ?> |
|
| 1401 | + <?php do_action('wpinv_before_checkout_form'); ?> |
|
| 1402 | 1402 | <form id="wpinv_checkout_form" class="wpi-form" action="<?php echo $form_action; ?>" method="POST"> |
| 1403 | 1403 | <?php |
| 1404 | - do_action( 'wpinv_checkout_form_top' ); |
|
| 1405 | - do_action( 'wpinv_checkout_billing_info' ); |
|
| 1406 | - do_action( 'wpinv_checkout_cart' ); |
|
| 1407 | - do_action( 'wpinv_payment_mode_select' ); |
|
| 1408 | - do_action( 'wpinv_checkout_form_bottom' ) |
|
| 1404 | + do_action('wpinv_checkout_form_top'); |
|
| 1405 | + do_action('wpinv_checkout_billing_info'); |
|
| 1406 | + do_action('wpinv_checkout_cart'); |
|
| 1407 | + do_action('wpinv_payment_mode_select'); |
|
| 1408 | + do_action('wpinv_checkout_form_bottom') |
|
| 1409 | 1409 | ?> |
| 1410 | 1410 | </form> |
| 1411 | - <?php do_action( 'wpinv_after_purchase_form' ); ?> |
|
| 1411 | + <?php do_action('wpinv_after_purchase_form'); ?> |
|
| 1412 | 1412 | </div><!--end #wpinv_checkout_form_wrap--> |
| 1413 | 1413 | <?php |
| 1414 | 1414 | } else { |
| 1415 | - do_action( 'wpinv_cart_empty' ); |
|
| 1415 | + do_action('wpinv_cart_empty'); |
|
| 1416 | 1416 | } |
| 1417 | 1417 | echo '</div><!--end #wpinv_checkout_wrap-->'; |
| 1418 | 1418 | return ob_get_clean(); |
| 1419 | 1419 | } |
| 1420 | 1420 | |
| 1421 | -function wpinv_checkout_cart( $cart_details = array(), $echo = true ) { |
|
| 1421 | +function wpinv_checkout_cart($cart_details = array(), $echo = true) { |
|
| 1422 | 1422 | global $ajax_cart_details; |
| 1423 | 1423 | $ajax_cart_details = $cart_details; |
| 1424 | 1424 | /* |
@@ -1433,25 +1433,25 @@ discard block |
||
| 1433 | 1433 | } |
| 1434 | 1434 | */ |
| 1435 | 1435 | ob_start(); |
| 1436 | - do_action( 'wpinv_before_checkout_cart' ); |
|
| 1436 | + do_action('wpinv_before_checkout_cart'); |
|
| 1437 | 1437 | echo '<div id="wpinv_checkout_cart_form" method="post">'; |
| 1438 | 1438 | echo '<div id="wpinv_checkout_cart_wrap">'; |
| 1439 | - wpinv_get_template_part( 'wpinv-checkout-cart' ); |
|
| 1439 | + wpinv_get_template_part('wpinv-checkout-cart'); |
|
| 1440 | 1440 | echo '</div>'; |
| 1441 | 1441 | echo '</div>'; |
| 1442 | - do_action( 'wpinv_after_checkout_cart' ); |
|
| 1442 | + do_action('wpinv_after_checkout_cart'); |
|
| 1443 | 1443 | $content = ob_get_clean(); |
| 1444 | 1444 | |
| 1445 | - if ( $echo ) { |
|
| 1445 | + if ($echo) { |
|
| 1446 | 1446 | echo $content; |
| 1447 | 1447 | } else { |
| 1448 | 1448 | return $content; |
| 1449 | 1449 | } |
| 1450 | 1450 | } |
| 1451 | -add_action( 'wpinv_checkout_cart', 'wpinv_checkout_cart', 10 ); |
|
| 1451 | +add_action('wpinv_checkout_cart', 'wpinv_checkout_cart', 10); |
|
| 1452 | 1452 | |
| 1453 | 1453 | function wpinv_empty_cart_message() { |
| 1454 | - return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
| 1454 | + return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>'); |
|
| 1455 | 1455 | } |
| 1456 | 1456 | |
| 1457 | 1457 | /** |
@@ -1463,91 +1463,91 @@ discard block |
||
| 1463 | 1463 | function wpinv_empty_checkout_cart() { |
| 1464 | 1464 | echo wpinv_empty_cart_message(); |
| 1465 | 1465 | } |
| 1466 | -add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' ); |
|
| 1466 | +add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart'); |
|
| 1467 | 1467 | |
| 1468 | 1468 | function wpinv_save_cart_button() { |
| 1469 | - if ( wpinv_is_cart_saving_disabled() ) |
|
| 1469 | + if (wpinv_is_cart_saving_disabled()) |
|
| 1470 | 1470 | return; |
| 1471 | 1471 | ?> |
| 1472 | - <a class="wpinv-cart-saving-button wpinv-submit button" id="wpinv-save-cart-button" href="<?php echo esc_url( add_query_arg( 'wpi_action', 'save_cart' ) ); ?>"><?php _e( 'Save Cart', 'invoicing' ); ?></a> |
|
| 1472 | + <a class="wpinv-cart-saving-button wpinv-submit button" id="wpinv-save-cart-button" href="<?php echo esc_url(add_query_arg('wpi_action', 'save_cart')); ?>"><?php _e('Save Cart', 'invoicing'); ?></a> |
|
| 1473 | 1473 | <?php |
| 1474 | 1474 | } |
| 1475 | 1475 | |
| 1476 | 1476 | function wpinv_update_cart_button() { |
| 1477 | - if ( !wpinv_item_quantities_enabled() ) |
|
| 1477 | + if (!wpinv_item_quantities_enabled()) |
|
| 1478 | 1478 | return; |
| 1479 | 1479 | ?> |
| 1480 | - <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e( 'Update Cart', 'invoicing' ); ?>"/> |
|
| 1480 | + <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e('Update Cart', 'invoicing'); ?>"/> |
|
| 1481 | 1481 | <input type="hidden" name="wpi_action" value="update_cart"/> |
| 1482 | 1482 | <?php |
| 1483 | 1483 | } |
| 1484 | 1484 | |
| 1485 | 1485 | function wpinv_checkout_cart_columns() { |
| 1486 | 1486 | $default = 3; |
| 1487 | - if ( wpinv_item_quantities_enabled() ) { |
|
| 1487 | + if (wpinv_item_quantities_enabled()) { |
|
| 1488 | 1488 | $default++; |
| 1489 | 1489 | } |
| 1490 | 1490 | |
| 1491 | - if ( wpinv_use_taxes() ) { |
|
| 1491 | + if (wpinv_use_taxes()) { |
|
| 1492 | 1492 | $default++; |
| 1493 | 1493 | } |
| 1494 | 1494 | |
| 1495 | - return apply_filters( 'wpinv_checkout_cart_columns', $default ); |
|
| 1495 | + return apply_filters('wpinv_checkout_cart_columns', $default); |
|
| 1496 | 1496 | } |
| 1497 | 1497 | |
| 1498 | 1498 | function wpinv_display_cart_messages() { |
| 1499 | 1499 | global $wpi_session; |
| 1500 | 1500 | |
| 1501 | - $messages = $wpi_session->get( 'wpinv_cart_messages' ); |
|
| 1501 | + $messages = $wpi_session->get('wpinv_cart_messages'); |
|
| 1502 | 1502 | |
| 1503 | - if ( $messages ) { |
|
| 1504 | - foreach ( $messages as $message_id => $message ) { |
|
| 1503 | + if ($messages) { |
|
| 1504 | + foreach ($messages as $message_id => $message) { |
|
| 1505 | 1505 | // Try and detect what type of message this is |
| 1506 | - if ( strpos( strtolower( $message ), 'error' ) ) { |
|
| 1506 | + if (strpos(strtolower($message), 'error')) { |
|
| 1507 | 1507 | $type = 'error'; |
| 1508 | - } elseif ( strpos( strtolower( $message ), 'success' ) ) { |
|
| 1508 | + } elseif (strpos(strtolower($message), 'success')) { |
|
| 1509 | 1509 | $type = 'success'; |
| 1510 | 1510 | } else { |
| 1511 | 1511 | $type = 'info'; |
| 1512 | 1512 | } |
| 1513 | 1513 | |
| 1514 | - $classes = apply_filters( 'wpinv_' . $type . '_class', array( 'wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type ) ); |
|
| 1514 | + $classes = apply_filters('wpinv_' . $type . '_class', array('wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type)); |
|
| 1515 | 1515 | |
| 1516 | - echo '<div class="' . implode( ' ', $classes ) . '">'; |
|
| 1516 | + echo '<div class="' . implode(' ', $classes) . '">'; |
|
| 1517 | 1517 | // Loop message codes and display messages |
| 1518 | 1518 | echo '<p class="wpinv_error" id="wpinv_msg_' . $message_id . '">' . $message . '</p>'; |
| 1519 | 1519 | echo '</div>'; |
| 1520 | 1520 | } |
| 1521 | 1521 | |
| 1522 | 1522 | // Remove all of the cart saving messages |
| 1523 | - $wpi_session->set( 'wpinv_cart_messages', null ); |
|
| 1523 | + $wpi_session->set('wpinv_cart_messages', null); |
|
| 1524 | 1524 | } |
| 1525 | 1525 | } |
| 1526 | -add_action( 'wpinv_before_checkout_cart', 'wpinv_display_cart_messages' ); |
|
| 1526 | +add_action('wpinv_before_checkout_cart', 'wpinv_display_cart_messages'); |
|
| 1527 | 1527 | |
| 1528 | 1528 | function wpinv_discount_field() { |
| 1529 | - if ( isset( $_GET['wpi-gateway'] ) && wpinv_is_ajax_disabled() ) { |
|
| 1529 | + if (isset($_GET['wpi-gateway']) && wpinv_is_ajax_disabled()) { |
|
| 1530 | 1530 | return; // Only show before a payment method has been selected if ajax is disabled |
| 1531 | 1531 | } |
| 1532 | 1532 | |
| 1533 | - if ( !wpinv_is_checkout() ) { |
|
| 1533 | + if (!wpinv_is_checkout()) { |
|
| 1534 | 1534 | return; |
| 1535 | 1535 | } |
| 1536 | 1536 | |
| 1537 | - if ( wpinv_has_active_discounts() && wpinv_get_cart_total() ) { |
|
| 1537 | + if (wpinv_has_active_discounts() && wpinv_get_cart_total()) { |
|
| 1538 | 1538 | ?> |
| 1539 | 1539 | <div id="wpinv-discount-field" class="panel panel-default"> |
| 1540 | 1540 | <div class="panel-body"> |
| 1541 | 1541 | <p> |
| 1542 | - <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e( 'Discount', 'invoicing' ); ?></strong></label> |
|
| 1543 | - <span class="wpinv-description"><?php _e( 'Enter a discount code if you have one.', 'invoicing' ); ?></span> |
|
| 1542 | + <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e('Discount', 'invoicing'); ?></strong></label> |
|
| 1543 | + <span class="wpinv-description"><?php _e('Enter a discount code if you have one.', 'invoicing'); ?></span> |
|
| 1544 | 1544 | </p> |
| 1545 | 1545 | <div class="form-group row"> |
| 1546 | 1546 | <div class="col-sm-4"> |
| 1547 | - <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e( 'Enter discount code', 'invoicing' ); ?>"/> |
|
| 1547 | + <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e('Enter discount code', 'invoicing'); ?>"/> |
|
| 1548 | 1548 | </div> |
| 1549 | 1549 | <div class="col-sm-3"> |
| 1550 | - <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e( 'Apply Discount', 'invoicing' ); ?></button> |
|
| 1550 | + <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e('Apply Discount', 'invoicing'); ?></button> |
|
| 1551 | 1551 | </div> |
| 1552 | 1552 | <div class="col-sm-12 wpinv-discount-msg"> |
| 1553 | 1553 | <div class="alert alert-success"><i class="fa fa-check-circle"></i><span class="wpi-msg"></span></div> |
@@ -1559,10 +1559,10 @@ discard block |
||
| 1559 | 1559 | <?php |
| 1560 | 1560 | } |
| 1561 | 1561 | } |
| 1562 | -add_action( 'wpinv_after_checkout_cart', 'wpinv_discount_field', -10 ); |
|
| 1562 | +add_action('wpinv_after_checkout_cart', 'wpinv_discount_field', -10); |
|
| 1563 | 1563 | |
| 1564 | 1564 | function wpinv_agree_to_terms_js() { |
| 1565 | - if ( wpinv_get_option( 'show_agree_to_terms', false ) ) { |
|
| 1565 | + if (wpinv_get_option('show_agree_to_terms', false)) { |
|
| 1566 | 1566 | ?> |
| 1567 | 1567 | <script type="text/javascript"> |
| 1568 | 1568 | jQuery(document).ready(function($){ |
@@ -1577,125 +1577,125 @@ discard block |
||
| 1577 | 1577 | <?php |
| 1578 | 1578 | } |
| 1579 | 1579 | } |
| 1580 | -add_action( 'wpinv_checkout_form_top', 'wpinv_agree_to_terms_js' ); |
|
| 1580 | +add_action('wpinv_checkout_form_top', 'wpinv_agree_to_terms_js'); |
|
| 1581 | 1581 | |
| 1582 | 1582 | function wpinv_payment_mode_select() { |
| 1583 | - $gateways = wpinv_get_enabled_payment_gateways( true ); |
|
| 1584 | - $gateways = apply_filters( 'wpinv_payment_gateways_on_cart', $gateways ); |
|
| 1583 | + $gateways = wpinv_get_enabled_payment_gateways(true); |
|
| 1584 | + $gateways = apply_filters('wpinv_payment_gateways_on_cart', $gateways); |
|
| 1585 | 1585 | $page_URL = wpinv_get_current_page_url(); |
| 1586 | - $invoice = wpinv_get_invoice( 0, true ); |
|
| 1586 | + $invoice = wpinv_get_invoice(0, true); |
|
| 1587 | 1587 | |
| 1588 | 1588 | do_action('wpinv_payment_mode_top'); |
| 1589 | 1589 | $invoice_id = (int)$invoice->ID; |
| 1590 | - $chosen_gateway = wpinv_get_chosen_gateway( $invoice_id ); |
|
| 1590 | + $chosen_gateway = wpinv_get_chosen_gateway($invoice_id); |
|
| 1591 | 1591 | ?> |
| 1592 | - <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo ( $invoice->is_free() ? 'style="display:none;"' : '' ); ?>> |
|
| 1593 | - <?php do_action( 'wpinv_payment_mode_before_gateways_wrap' ); ?> |
|
| 1592 | + <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo ($invoice->is_free() ? 'style="display:none;"' : ''); ?>> |
|
| 1593 | + <?php do_action('wpinv_payment_mode_before_gateways_wrap'); ?> |
|
| 1594 | 1594 | <div id="wpinv-payment-mode-wrap" class="panel panel-default"> |
| 1595 | - <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Select Payment Method', 'invoicing' ); ?></h3></div> |
|
| 1595 | + <div class="panel-heading"><h3 class="panel-title"><?php _e('Select Payment Method', 'invoicing'); ?></h3></div> |
|
| 1596 | 1596 | <div class="panel-body list-group wpi-payment_methods"> |
| 1597 | 1597 | <?php |
| 1598 | - do_action( 'wpinv_payment_mode_before_gateways' ); |
|
| 1598 | + do_action('wpinv_payment_mode_before_gateways'); |
|
| 1599 | 1599 | |
| 1600 | - if(!empty($gateways)){ |
|
| 1601 | - foreach ( $gateways as $gateway_id => $gateway ) { |
|
| 1602 | - $checked = checked( $gateway_id, $chosen_gateway, false ); |
|
| 1603 | - $button_label = wpinv_get_gateway_button_label( $gateway_id ); |
|
| 1604 | - $description = wpinv_get_gateway_description( $gateway_id ); |
|
| 1600 | + if (!empty($gateways)) { |
|
| 1601 | + foreach ($gateways as $gateway_id => $gateway) { |
|
| 1602 | + $checked = checked($gateway_id, $chosen_gateway, false); |
|
| 1603 | + $button_label = wpinv_get_gateway_button_label($gateway_id); |
|
| 1604 | + $description = wpinv_get_gateway_description($gateway_id); |
|
| 1605 | 1605 | ?> |
| 1606 | 1606 | <div class="list-group-item"> |
| 1607 | 1607 | <div class="radio"> |
| 1608 | - <label><input type="radio" data-button-text="<?php echo esc_attr( $button_label );?>" value="<?php echo esc_attr( $gateway_id ) ;?>" <?php echo $checked ;?> id="wpi_gateway_<?php echo esc_attr( $gateway_id );?>" name="wpi-gateway" class="wpi-pmethod"><?php echo esc_html( $gateway['checkout_label'] ); ?></label> |
|
| 1608 | + <label><input type="radio" data-button-text="<?php echo esc_attr($button_label); ?>" value="<?php echo esc_attr($gateway_id); ?>" <?php echo $checked; ?> id="wpi_gateway_<?php echo esc_attr($gateway_id); ?>" name="wpi-gateway" class="wpi-pmethod"><?php echo esc_html($gateway['checkout_label']); ?></label> |
|
| 1609 | 1609 | </div> |
| 1610 | - <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr( $gateway_id );?>" role="alert"> |
|
| 1611 | - <?php if ( !empty( $description ) ) { ?> |
|
| 1612 | - <div class="wpi-gateway-desc alert alert-info"><?php echo $description;?></div> |
|
| 1610 | + <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr($gateway_id); ?>" role="alert"> |
|
| 1611 | + <?php if (!empty($description)) { ?> |
|
| 1612 | + <div class="wpi-gateway-desc alert alert-info"><?php echo $description; ?></div> |
|
| 1613 | 1613 | <?php } ?> |
| 1614 | - <?php do_action( 'wpinv_' . $gateway_id . '_cc_form', $invoice_id ) ;?> |
|
| 1614 | + <?php do_action('wpinv_' . $gateway_id . '_cc_form', $invoice_id); ?> |
|
| 1615 | 1615 | </div> |
| 1616 | 1616 | </div> |
| 1617 | 1617 | <?php |
| 1618 | 1618 | } |
| 1619 | - }else{ |
|
| 1620 | - echo '<div class="alert alert-warning">'. __('No payment gateway active','invoicing') .'</div>'; |
|
| 1619 | + } else { |
|
| 1620 | + echo '<div class="alert alert-warning">' . __('No payment gateway active', 'invoicing') . '</div>'; |
|
| 1621 | 1621 | } |
| 1622 | 1622 | |
| 1623 | - do_action( 'wpinv_payment_mode_after_gateways' ); |
|
| 1623 | + do_action('wpinv_payment_mode_after_gateways'); |
|
| 1624 | 1624 | ?> |
| 1625 | 1625 | </div> |
| 1626 | 1626 | </div> |
| 1627 | - <?php do_action( 'wpinv_payment_mode_after_gateways_wrap' ); ?> |
|
| 1627 | + <?php do_action('wpinv_payment_mode_after_gateways_wrap'); ?> |
|
| 1628 | 1628 | </div> |
| 1629 | 1629 | <?php |
| 1630 | 1630 | do_action('wpinv_payment_mode_bottom'); |
| 1631 | 1631 | } |
| 1632 | -add_action( 'wpinv_payment_mode_select', 'wpinv_payment_mode_select' ); |
|
| 1632 | +add_action('wpinv_payment_mode_select', 'wpinv_payment_mode_select'); |
|
| 1633 | 1633 | |
| 1634 | 1634 | function wpinv_checkout_billing_info() { |
| 1635 | - if ( wpinv_is_checkout() ) { |
|
| 1635 | + if (wpinv_is_checkout()) { |
|
| 1636 | 1636 | $logged_in = is_user_logged_in(); |
| 1637 | 1637 | $billing_details = wpinv_checkout_billing_details(); |
| 1638 | - $selected_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : wpinv_default_billing_country(); |
|
| 1638 | + $selected_country = !empty($billing_details['country']) ? $billing_details['country'] : wpinv_default_billing_country(); |
|
| 1639 | 1639 | ?> |
| 1640 | 1640 | <div id="wpinv-fields" class="clearfix"> |
| 1641 | 1641 | <div id="wpi-billing" class="wpi-billing clearfix panel panel-default"> |
| 1642 | - <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Billing Details', 'invoicing' );?></h3></div> |
|
| 1642 | + <div class="panel-heading"><h3 class="panel-title"><?php _e('Billing Details', 'invoicing'); ?></h3></div> |
|
| 1643 | 1643 | <div id="wpinv-fields-box" class="panel-body"> |
| 1644 | - <?php do_action( 'wpinv_checkout_billing_fields_first', $billing_details ); ?> |
|
| 1644 | + <?php do_action('wpinv_checkout_billing_fields_first', $billing_details); ?> |
|
| 1645 | 1645 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
| 1646 | - <label for="wpinv_first_name" class="wpi-label"><?php _e( 'First Name', 'invoicing' );?><span class="wpi-required">*</span></label> |
|
| 1646 | + <label for="wpinv_first_name" class="wpi-label"><?php _e('First Name', 'invoicing'); ?><span class="wpi-required">*</span></label> |
|
| 1647 | 1647 | <?php |
| 1648 | - echo wpinv_html_text( array( |
|
| 1648 | + echo wpinv_html_text(array( |
|
| 1649 | 1649 | 'id' => 'wpinv_first_name', |
| 1650 | 1650 | 'name' => 'wpinv_first_name', |
| 1651 | 1651 | 'value' => $billing_details['first_name'], |
| 1652 | 1652 | 'class' => 'wpi-input form-control required', |
| 1653 | - 'placeholder' => __( 'First name', 'invoicing' ), |
|
| 1653 | + 'placeholder' => __('First name', 'invoicing'), |
|
| 1654 | 1654 | 'required' => true, |
| 1655 | - ) ); |
|
| 1655 | + )); |
|
| 1656 | 1656 | ?> |
| 1657 | 1657 | </p> |
| 1658 | 1658 | <p class="wpi-cart-field wpi-col2 wpi-coll"> |
| 1659 | - <label for="wpinv_last_name" class="wpi-label"><?php _e( 'Last Name', 'invoicing' );?></label> |
|
| 1659 | + <label for="wpinv_last_name" class="wpi-label"><?php _e('Last Name', 'invoicing'); ?></label> |
|
| 1660 | 1660 | <?php |
| 1661 | - echo wpinv_html_text( array( |
|
| 1661 | + echo wpinv_html_text(array( |
|
| 1662 | 1662 | 'id' => 'wpinv_last_name', |
| 1663 | 1663 | 'name' => 'wpinv_last_name', |
| 1664 | 1664 | 'value' => $billing_details['last_name'], |
| 1665 | 1665 | 'class' => 'wpi-input form-control', |
| 1666 | - 'placeholder' => __( 'Last name', 'invoicing' ), |
|
| 1667 | - ) ); |
|
| 1666 | + 'placeholder' => __('Last name', 'invoicing'), |
|
| 1667 | + )); |
|
| 1668 | 1668 | ?> |
| 1669 | 1669 | </p> |
| 1670 | 1670 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
| 1671 | - <label for="wpinv_address" class="wpi-label"><?php _e( 'Address', 'invoicing' );?><span class="wpi-required">*</span></label> |
|
| 1671 | + <label for="wpinv_address" class="wpi-label"><?php _e('Address', 'invoicing'); ?><span class="wpi-required">*</span></label> |
|
| 1672 | 1672 | <?php |
| 1673 | - echo wpinv_html_text( array( |
|
| 1673 | + echo wpinv_html_text(array( |
|
| 1674 | 1674 | 'id' => 'wpinv_address', |
| 1675 | 1675 | 'name' => 'wpinv_address', |
| 1676 | 1676 | 'value' => $billing_details['address'], |
| 1677 | 1677 | 'class' => 'wpi-input form-control required', |
| 1678 | - 'placeholder' => __( 'Address', 'invoicing' ), |
|
| 1678 | + 'placeholder' => __('Address', 'invoicing'), |
|
| 1679 | 1679 | 'required' => true, |
| 1680 | - ) ); |
|
| 1680 | + )); |
|
| 1681 | 1681 | ?> |
| 1682 | 1682 | </p> |
| 1683 | 1683 | <p class="wpi-cart-field wpi-col2 wpi-coll"> |
| 1684 | - <label for="wpinv_city" class="wpi-label"><?php _e( 'City', 'invoicing' );?><span class="wpi-required">*</span></label> |
|
| 1684 | + <label for="wpinv_city" class="wpi-label"><?php _e('City', 'invoicing'); ?><span class="wpi-required">*</span></label> |
|
| 1685 | 1685 | <?php |
| 1686 | - echo wpinv_html_text( array( |
|
| 1686 | + echo wpinv_html_text(array( |
|
| 1687 | 1687 | 'id' => 'wpinv_city', |
| 1688 | 1688 | 'name' => 'wpinv_city', |
| 1689 | 1689 | 'value' => $billing_details['city'], |
| 1690 | 1690 | 'class' => 'wpi-input form-control required', |
| 1691 | - 'placeholder' => __( 'City', 'invoicing' ), |
|
| 1691 | + 'placeholder' => __('City', 'invoicing'), |
|
| 1692 | 1692 | 'required' => true, |
| 1693 | - ) ); |
|
| 1693 | + )); |
|
| 1694 | 1694 | ?> |
| 1695 | 1695 | </p> |
| 1696 | 1696 | <p id="wpinv_country_box" class="wpi-cart-field wpi-col2 wpi-colf"> |
| 1697 | - <label for="wpinv_country" class="wpi-label"><?php _e( 'Country', 'invoicing' );?><span class="wpi-required">*</span></label> |
|
| 1698 | - <?php echo wpinv_html_select( array( |
|
| 1697 | + <label for="wpinv_country" class="wpi-label"><?php _e('Country', 'invoicing'); ?><span class="wpi-required">*</span></label> |
|
| 1698 | + <?php echo wpinv_html_select(array( |
|
| 1699 | 1699 | 'options' => wpinv_get_country_list(), |
| 1700 | 1700 | 'name' => 'wpinv_country', |
| 1701 | 1701 | 'id' => 'wpinv_country', |
@@ -1703,16 +1703,16 @@ discard block |
||
| 1703 | 1703 | 'show_option_all' => false, |
| 1704 | 1704 | 'show_option_none' => false, |
| 1705 | 1705 | 'class' => 'wpi-input form-control required', |
| 1706 | - 'placeholder' => __( 'Choose a country', 'invoicing' ), |
|
| 1706 | + 'placeholder' => __('Choose a country', 'invoicing'), |
|
| 1707 | 1707 | 'required' => true, |
| 1708 | - ) ); ?> |
|
| 1708 | + )); ?> |
|
| 1709 | 1709 | </p> |
| 1710 | 1710 | <p id="wpinv_state_box" class="wpi-cart-field wpi-col2 wpi-coll"> |
| 1711 | - <label for="wpinv_state" class="wpi-label"><?php _e( 'State / Province', 'invoicing' );?><span class="wpi-required">*</span></label> |
|
| 1711 | + <label for="wpinv_state" class="wpi-label"><?php _e('State / Province', 'invoicing'); ?><span class="wpi-required">*</span></label> |
|
| 1712 | 1712 | <?php |
| 1713 | - $states = wpinv_get_country_states( $selected_country ); |
|
| 1714 | - if( !empty( $states ) ) { |
|
| 1715 | - echo wpinv_html_select( array( |
|
| 1713 | + $states = wpinv_get_country_states($selected_country); |
|
| 1714 | + if (!empty($states)) { |
|
| 1715 | + echo wpinv_html_select(array( |
|
| 1716 | 1716 | 'options' => $states, |
| 1717 | 1717 | 'name' => 'wpinv_state', |
| 1718 | 1718 | 'id' => 'wpinv_state', |
@@ -1720,60 +1720,60 @@ discard block |
||
| 1720 | 1720 | 'show_option_all' => false, |
| 1721 | 1721 | 'show_option_none' => false, |
| 1722 | 1722 | 'class' => 'wpi-input form-control required', |
| 1723 | - 'placeholder' => __( 'Choose a state', 'invoicing' ), |
|
| 1723 | + 'placeholder' => __('Choose a state', 'invoicing'), |
|
| 1724 | 1724 | 'required' => true, |
| 1725 | - ) ); |
|
| 1725 | + )); |
|
| 1726 | 1726 | } else { |
| 1727 | - echo wpinv_html_text( array( |
|
| 1727 | + echo wpinv_html_text(array( |
|
| 1728 | 1728 | 'name' => 'wpinv_state', |
| 1729 | 1729 | 'value' => $billing_details['state'], |
| 1730 | 1730 | 'id' => 'wpinv_state', |
| 1731 | 1731 | 'class' => 'wpi-input form-control required', |
| 1732 | - 'placeholder' => __( 'State / Province', 'invoicing' ), |
|
| 1732 | + 'placeholder' => __('State / Province', 'invoicing'), |
|
| 1733 | 1733 | 'required' => true, |
| 1734 | - ) ); |
|
| 1734 | + )); |
|
| 1735 | 1735 | } |
| 1736 | 1736 | ?> |
| 1737 | 1737 | </p> |
| 1738 | 1738 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
| 1739 | - <label for="wpinv_zip" class="wpi-label"><?php _e( 'ZIP / Postcode', 'invoicing' );?></label> |
|
| 1739 | + <label for="wpinv_zip" class="wpi-label"><?php _e('ZIP / Postcode', 'invoicing'); ?></label> |
|
| 1740 | 1740 | <?php |
| 1741 | - echo wpinv_html_text( array( |
|
| 1741 | + echo wpinv_html_text(array( |
|
| 1742 | 1742 | 'name' => 'wpinv_zip', |
| 1743 | 1743 | 'value' => $billing_details['zip'], |
| 1744 | 1744 | 'id' => 'wpinv_zip', |
| 1745 | 1745 | 'class' => 'wpi-input form-control', |
| 1746 | - 'placeholder' => __( 'ZIP / Postcode', 'invoicing' ), |
|
| 1747 | - ) ); |
|
| 1746 | + 'placeholder' => __('ZIP / Postcode', 'invoicing'), |
|
| 1747 | + )); |
|
| 1748 | 1748 | ?> |
| 1749 | 1749 | </p> |
| 1750 | 1750 | <p class="wpi-cart-field wpi-col2 wpi-coll"> |
| 1751 | - <label for="wpinv_phone" class="wpi-label"><?php _e( 'Phone', 'invoicing' );?><?php if ( wpinv_get_option( 'phone_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1751 | + <label for="wpinv_phone" class="wpi-label"><?php _e('Phone', 'invoicing'); ?><?php if (wpinv_get_option('phone_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1752 | 1752 | <?php |
| 1753 | - echo wpinv_html_text( array( |
|
| 1753 | + echo wpinv_html_text(array( |
|
| 1754 | 1754 | 'id' => 'wpinv_phone', |
| 1755 | 1755 | 'name' => 'wpinv_phone', |
| 1756 | 1756 | 'value' => $billing_details['phone'], |
| 1757 | 1757 | 'class' => 'wpi-input form-control', |
| 1758 | - 'placeholder' => __( 'Phone', 'invoicing' ), |
|
| 1759 | - 'required' => (bool)wpinv_get_option( 'phone_mandatory' ), |
|
| 1760 | - ) ); |
|
| 1758 | + 'placeholder' => __('Phone', 'invoicing'), |
|
| 1759 | + 'required' => (bool)wpinv_get_option('phone_mandatory'), |
|
| 1760 | + )); |
|
| 1761 | 1761 | ?> |
| 1762 | 1762 | </p> |
| 1763 | - <?php do_action( 'wpinv_checkout_billing_fields_last', $billing_details ); ?> |
|
| 1763 | + <?php do_action('wpinv_checkout_billing_fields_last', $billing_details); ?> |
|
| 1764 | 1764 | <div class="clearfix"></div> |
| 1765 | 1765 | </div> |
| 1766 | 1766 | </div> |
| 1767 | - <?php do_action( 'wpinv_after_billing_fields', $billing_details ); ?> |
|
| 1767 | + <?php do_action('wpinv_after_billing_fields', $billing_details); ?> |
|
| 1768 | 1768 | </div> |
| 1769 | 1769 | <?php |
| 1770 | 1770 | } |
| 1771 | 1771 | } |
| 1772 | -add_action( 'wpinv_checkout_billing_info', 'wpinv_checkout_billing_info' ); |
|
| 1772 | +add_action('wpinv_checkout_billing_info', 'wpinv_checkout_billing_info'); |
|
| 1773 | 1773 | |
| 1774 | 1774 | function wpinv_checkout_hidden_fields() { |
| 1775 | 1775 | ?> |
| 1776 | - <?php if ( is_user_logged_in() ) { ?> |
|
| 1776 | + <?php if (is_user_logged_in()) { ?> |
|
| 1777 | 1777 | <input type="hidden" name="wpinv_user_id" value="<?php echo get_current_user_id(); ?>"/> |
| 1778 | 1778 | <?php } ?> |
| 1779 | 1779 | <input type="hidden" name="wpi_action" value="payment" /> |
@@ -1783,9 +1783,9 @@ discard block |
||
| 1783 | 1783 | function wpinv_checkout_button_purchase() { |
| 1784 | 1784 | ob_start(); |
| 1785 | 1785 | ?> |
| 1786 | - <input type="submit" class="btn btn-success wpinv-submit" id="wpinv-payment-button" data-value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>" name="wpinv_payment" value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>"/> |
|
| 1786 | + <input type="submit" class="btn btn-success wpinv-submit" id="wpinv-payment-button" data-value="<?php esc_attr_e('Proceed to Pay', 'invoicing') ?>" name="wpinv_payment" value="<?php esc_attr_e('Proceed to Pay', 'invoicing') ?>"/> |
|
| 1787 | 1787 | <?php |
| 1788 | - return apply_filters( 'wpinv_checkout_button_purchase', ob_get_clean() ); |
|
| 1788 | + return apply_filters('wpinv_checkout_button_purchase', ob_get_clean()); |
|
| 1789 | 1789 | } |
| 1790 | 1790 | |
| 1791 | 1791 | function wpinv_checkout_total() { |
@@ -1794,96 +1794,96 @@ discard block |
||
| 1794 | 1794 | <div id="wpinv_checkout_total" class="panel panel-info"> |
| 1795 | 1795 | <div class="panel-body"> |
| 1796 | 1796 | <?php |
| 1797 | - do_action( 'wpinv_purchase_form_before_checkout_total' ); |
|
| 1797 | + do_action('wpinv_purchase_form_before_checkout_total'); |
|
| 1798 | 1798 | ?> |
| 1799 | - <strong><?php _e( 'Invoice Total:', 'invoicing' ) ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total;?></span> |
|
| 1799 | + <strong><?php _e('Invoice Total:', 'invoicing') ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total; ?></span> |
|
| 1800 | 1800 | <?php |
| 1801 | - do_action( 'wpinv_purchase_form_after_checkout_total' ); |
|
| 1801 | + do_action('wpinv_purchase_form_after_checkout_total'); |
|
| 1802 | 1802 | ?> |
| 1803 | 1803 | </div> |
| 1804 | 1804 | </div> |
| 1805 | 1805 | <?php |
| 1806 | 1806 | } |
| 1807 | -add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998 ); |
|
| 1807 | +add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998); |
|
| 1808 | 1808 | |
| 1809 | 1809 | function wpinv_checkout_submit() { |
| 1810 | 1810 | ?> |
| 1811 | 1811 | <div id="wpinv_purchase_submit" class="panel panel-success"> |
| 1812 | 1812 | <div class="panel-body text-center"> |
| 1813 | 1813 | <?php |
| 1814 | - do_action( 'wpinv_purchase_form_before_submit' ); |
|
| 1814 | + do_action('wpinv_purchase_form_before_submit'); |
|
| 1815 | 1815 | wpinv_checkout_hidden_fields(); |
| 1816 | 1816 | echo wpinv_checkout_button_purchase(); |
| 1817 | - do_action( 'wpinv_purchase_form_after_submit' ); |
|
| 1817 | + do_action('wpinv_purchase_form_after_submit'); |
|
| 1818 | 1818 | ?> |
| 1819 | 1819 | </div> |
| 1820 | 1820 | </div> |
| 1821 | 1821 | <?php |
| 1822 | 1822 | } |
| 1823 | -add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999 ); |
|
| 1823 | +add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999); |
|
| 1824 | 1824 | |
| 1825 | -function wpinv_receipt_billing_address( $invoice_id = 0 ) { |
|
| 1826 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 1825 | +function wpinv_receipt_billing_address($invoice_id = 0) { |
|
| 1826 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 1827 | 1827 | |
| 1828 | - if ( empty( $invoice ) ) { |
|
| 1828 | + if (empty($invoice)) { |
|
| 1829 | 1829 | return NULL; |
| 1830 | 1830 | } |
| 1831 | 1831 | |
| 1832 | 1832 | $billing_details = $invoice->get_user_info(); |
| 1833 | 1833 | $address_row = ''; |
| 1834 | - if ( $address = $billing_details['address'] ) { |
|
| 1835 | - $address_row .= wpautop( wp_kses_post( $address ) ); |
|
| 1834 | + if ($address = $billing_details['address']) { |
|
| 1835 | + $address_row .= wpautop(wp_kses_post($address)); |
|
| 1836 | 1836 | } |
| 1837 | 1837 | |
| 1838 | 1838 | $address_fields = array(); |
| 1839 | - if ( !empty( $billing_details['city'] ) ) { |
|
| 1839 | + if (!empty($billing_details['city'])) { |
|
| 1840 | 1840 | $address_fields[] = $billing_details['city']; |
| 1841 | 1841 | } |
| 1842 | 1842 | |
| 1843 | - $billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : ''; |
|
| 1844 | - if ( !empty( $billing_details['state'] ) ) { |
|
| 1845 | - $address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country ); |
|
| 1843 | + $billing_country = !empty($billing_details['country']) ? $billing_details['country'] : ''; |
|
| 1844 | + if (!empty($billing_details['state'])) { |
|
| 1845 | + $address_fields[] = wpinv_state_name($billing_details['state'], $billing_country); |
|
| 1846 | 1846 | } |
| 1847 | 1847 | |
| 1848 | - if ( !empty( $billing_country ) ) { |
|
| 1849 | - $address_fields[] = wpinv_country_name( $billing_country ); |
|
| 1848 | + if (!empty($billing_country)) { |
|
| 1849 | + $address_fields[] = wpinv_country_name($billing_country); |
|
| 1850 | 1850 | } |
| 1851 | 1851 | |
| 1852 | - if ( !empty( $address_fields ) ) { |
|
| 1853 | - $address_fields = implode( ", ", $address_fields ); |
|
| 1852 | + if (!empty($address_fields)) { |
|
| 1853 | + $address_fields = implode(", ", $address_fields); |
|
| 1854 | 1854 | |
| 1855 | - if ( !empty( $billing_details['zip'] ) ) { |
|
| 1855 | + if (!empty($billing_details['zip'])) { |
|
| 1856 | 1856 | $address_fields .= ' ' . $billing_details['zip']; |
| 1857 | 1857 | } |
| 1858 | 1858 | |
| 1859 | - $address_row .= wpautop( wp_kses_post( $address_fields ) ); |
|
| 1859 | + $address_row .= wpautop(wp_kses_post($address_fields)); |
|
| 1860 | 1860 | } |
| 1861 | 1861 | ob_start(); |
| 1862 | 1862 | ?> |
| 1863 | 1863 | <table class="table table-bordered table-sm wpi-billing-details"> |
| 1864 | 1864 | <tbody> |
| 1865 | 1865 | <tr class="wpi-receipt-name"> |
| 1866 | - <th class="text-left"><?php _e( 'Name', 'invoicing' ); ?></th> |
|
| 1867 | - <td><?php echo esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) ;?></td> |
|
| 1866 | + <th class="text-left"><?php _e('Name', 'invoicing'); ?></th> |
|
| 1867 | + <td><?php echo esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])); ?></td> |
|
| 1868 | 1868 | </tr> |
| 1869 | 1869 | <tr class="wpi-receipt-email"> |
| 1870 | - <th class="text-left"><?php _e( 'Email', 'invoicing' ); ?></th> |
|
| 1871 | - <td><?php echo $billing_details['email'] ;?></td> |
|
| 1870 | + <th class="text-left"><?php _e('Email', 'invoicing'); ?></th> |
|
| 1871 | + <td><?php echo $billing_details['email']; ?></td> |
|
| 1872 | 1872 | </tr> |
| 1873 | - <?php if ( $billing_details['company'] ) { ?> |
|
| 1873 | + <?php if ($billing_details['company']) { ?> |
|
| 1874 | 1874 | <tr class="wpi-receipt-company"> |
| 1875 | - <th class="text-left"><?php _e( 'Company', 'invoicing' ); ?></th> |
|
| 1876 | - <td><?php echo esc_html( $billing_details['company'] ) ;?></td> |
|
| 1875 | + <th class="text-left"><?php _e('Company', 'invoicing'); ?></th> |
|
| 1876 | + <td><?php echo esc_html($billing_details['company']); ?></td> |
|
| 1877 | 1877 | </tr> |
| 1878 | 1878 | <?php } ?> |
| 1879 | 1879 | <tr class="wpi-receipt-address"> |
| 1880 | - <th class="text-left"><?php _e( 'Address', 'invoicing' ); ?></th> |
|
| 1881 | - <td><?php echo $address_row ;?></td> |
|
| 1880 | + <th class="text-left"><?php _e('Address', 'invoicing'); ?></th> |
|
| 1881 | + <td><?php echo $address_row; ?></td> |
|
| 1882 | 1882 | </tr> |
| 1883 | - <?php if ( $billing_details['phone'] ) { ?> |
|
| 1883 | + <?php if ($billing_details['phone']) { ?> |
|
| 1884 | 1884 | <tr class="wpi-receipt-phone"> |
| 1885 | - <th class="text-left"><?php _e( 'Phone', 'invoicing' ); ?></th> |
|
| 1886 | - <td><?php echo esc_html( $billing_details['phone'] ) ;?></td> |
|
| 1885 | + <th class="text-left"><?php _e('Phone', 'invoicing'); ?></th> |
|
| 1886 | + <td><?php echo esc_html($billing_details['phone']); ?></td> |
|
| 1887 | 1887 | </tr> |
| 1888 | 1888 | <?php } ?> |
| 1889 | 1889 | </tbody> |
@@ -1891,98 +1891,98 @@ discard block |
||
| 1891 | 1891 | <?php |
| 1892 | 1892 | $output = ob_get_clean(); |
| 1893 | 1893 | |
| 1894 | - $output = apply_filters( 'wpinv_receipt_billing_address', $output, $invoice_id ); |
|
| 1894 | + $output = apply_filters('wpinv_receipt_billing_address', $output, $invoice_id); |
|
| 1895 | 1895 | |
| 1896 | 1896 | echo $output; |
| 1897 | 1897 | } |
| 1898 | 1898 | |
| 1899 | -function wpinv_filter_success_page_content( $content ) { |
|
| 1900 | - if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) { |
|
| 1901 | - if ( has_filter( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ) ) ) { |
|
| 1902 | - $content = apply_filters( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ), $content ); |
|
| 1899 | +function wpinv_filter_success_page_content($content) { |
|
| 1900 | + if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) { |
|
| 1901 | + if (has_filter('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']))) { |
|
| 1902 | + $content = apply_filters('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']), $content); |
|
| 1903 | 1903 | } |
| 1904 | 1904 | } |
| 1905 | 1905 | |
| 1906 | 1906 | return $content; |
| 1907 | 1907 | } |
| 1908 | -add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 ); |
|
| 1908 | +add_filter('the_content', 'wpinv_filter_success_page_content', 99999); |
|
| 1909 | 1909 | |
| 1910 | -function wpinv_receipt_actions( $invoice ) { |
|
| 1911 | - if ( !empty( $invoice ) ) { |
|
| 1910 | +function wpinv_receipt_actions($invoice) { |
|
| 1911 | + if (!empty($invoice)) { |
|
| 1912 | 1912 | $actions = array( |
| 1913 | 1913 | 'print' => array( |
| 1914 | 1914 | 'url' => $invoice->get_view_url(), |
| 1915 | - 'name' => __( 'Print Invoice', 'invoicing' ), |
|
| 1915 | + 'name' => __('Print Invoice', 'invoicing'), |
|
| 1916 | 1916 | 'class' => 'btn-primary', |
| 1917 | 1917 | ), |
| 1918 | 1918 | 'history' => array( |
| 1919 | 1919 | 'url' => wpinv_get_history_page_uri(), |
| 1920 | - 'name' => __( 'Invoice History', 'invoicing' ), |
|
| 1920 | + 'name' => __('Invoice History', 'invoicing'), |
|
| 1921 | 1921 | 'class' => 'btn-warning', |
| 1922 | 1922 | ) |
| 1923 | 1923 | ); |
| 1924 | 1924 | |
| 1925 | - $actions = apply_filters( 'wpinv_invoice_receipt_actions', $actions, $invoice ); |
|
| 1925 | + $actions = apply_filters('wpinv_invoice_receipt_actions', $actions, $invoice); |
|
| 1926 | 1926 | |
| 1927 | - if ( !empty( $actions ) ) { |
|
| 1927 | + if (!empty($actions)) { |
|
| 1928 | 1928 | ?> |
| 1929 | 1929 | <div class="wpinv-receipt-actions text-right"> |
| 1930 | - <?php foreach ( $actions as $key => $action ) { $class = !empty($action['class']) ? sanitize_html_class( $action['class'] ) : ''; ?> |
|
| 1931 | - <a href="<?php echo esc_url( $action['url'] );?>" class="btn btn-sm <?php echo $class . ' ' . sanitize_html_class( $key );?>" <?php echo ( !empty($action['attrs']) ? $action['attrs'] : '' ) ;?>><?php echo esc_html( $action['name'] );?></a> |
|
| 1930 | + <?php foreach ($actions as $key => $action) { $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; ?> |
|
| 1931 | + <a href="<?php echo esc_url($action['url']); ?>" class="btn btn-sm <?php echo $class . ' ' . sanitize_html_class($key); ?>" <?php echo (!empty($action['attrs']) ? $action['attrs'] : ''); ?>><?php echo esc_html($action['name']); ?></a> |
|
| 1932 | 1932 | <?php } ?> |
| 1933 | 1933 | </div> |
| 1934 | 1934 | <?php |
| 1935 | 1935 | } |
| 1936 | 1936 | } |
| 1937 | 1937 | } |
| 1938 | -add_action( 'wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1 ); |
|
| 1938 | +add_action('wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1); |
|
| 1939 | 1939 | |
| 1940 | -function wpinv_invoice_link( $invoice_id ) { |
|
| 1941 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 1940 | +function wpinv_invoice_link($invoice_id) { |
|
| 1941 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 1942 | 1942 | |
| 1943 | - if ( empty( $invoice ) ) { |
|
| 1943 | + if (empty($invoice)) { |
|
| 1944 | 1944 | return NULL; |
| 1945 | 1945 | } |
| 1946 | 1946 | |
| 1947 | - $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>'; |
|
| 1947 | + $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>'; |
|
| 1948 | 1948 | |
| 1949 | - return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice ); |
|
| 1949 | + return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice); |
|
| 1950 | 1950 | } |
| 1951 | 1951 | |
| 1952 | -function wpinv_invoice_subscription_details( $invoice ) { |
|
| 1953 | - if ( !empty( $invoice ) && $invoice->is_recurring() && !wpinv_is_subscription_payment( $invoice ) ) { |
|
| 1952 | +function wpinv_invoice_subscription_details($invoice) { |
|
| 1953 | + if (!empty($invoice) && $invoice->is_recurring() && !wpinv_is_subscription_payment($invoice)) { |
|
| 1954 | 1954 | $total_payments = (int)$invoice->get_total_payments(); |
| 1955 | 1955 | $payments = $invoice->get_child_payments(); |
| 1956 | 1956 | |
| 1957 | 1957 | $subscription = $invoice->get_subscription_data(); |
| 1958 | 1958 | |
| 1959 | - if ( !( !empty( $subscription ) && !empty( $subscription['item_id'] ) ) ) { |
|
| 1959 | + if (!(!empty($subscription) && !empty($subscription['item_id']))) { |
|
| 1960 | 1960 | return; |
| 1961 | 1961 | } |
| 1962 | 1962 | |
| 1963 | - $billing_cycle = wpinv_get_billing_cycle( $subscription['initial_amount'], $subscription['recurring_amount'], $subscription['period'], $subscription['interval'], $subscription['bill_times'], $subscription['trial_period'], $subscription['trial_interval'], $invoice->get_currency() ); |
|
| 1964 | - $times_billed = $total_payments . ' / ' . ( ( (int)$subscription['bill_times'] == 0 ) ? __( 'Until cancelled', 'invoicing' ) : $subscription['bill_times'] ); |
|
| 1963 | + $billing_cycle = wpinv_get_billing_cycle($subscription['initial_amount'], $subscription['recurring_amount'], $subscription['period'], $subscription['interval'], $subscription['bill_times'], $subscription['trial_period'], $subscription['trial_interval'], $invoice->get_currency()); |
|
| 1964 | + $times_billed = $total_payments . ' / ' . (((int)$subscription['bill_times'] == 0) ? __('Until cancelled', 'invoicing') : $subscription['bill_times']); |
|
| 1965 | 1965 | |
| 1966 | 1966 | $subscription_status = $invoice->get_subscription_status(); |
| 1967 | 1967 | |
| 1968 | 1968 | $status_desc = ''; |
| 1969 | - if ( $subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date() ) { |
|
| 1970 | - $status_desc = wp_sprintf( __( 'Until: %s', 'invoicing' ), $trial_end_date ); |
|
| 1971 | - } else if ( $subscription_status == 'cancelled' && $cancelled_date = $invoice->get_cancelled_date() ) { |
|
| 1972 | - $status_desc = wp_sprintf( __( 'On: %s', 'invoicing' ), $cancelled_date ); |
|
| 1969 | + if ($subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date()) { |
|
| 1970 | + $status_desc = wp_sprintf(__('Until: %s', 'invoicing'), $trial_end_date); |
|
| 1971 | + } else if ($subscription_status == 'cancelled' && $cancelled_date = $invoice->get_cancelled_date()) { |
|
| 1972 | + $status_desc = wp_sprintf(__('On: %s', 'invoicing'), $cancelled_date); |
|
| 1973 | 1973 | } |
| 1974 | 1974 | $status_desc = $status_desc != '' ? '<span class="meta">' . $status_desc . '</span>' : ''; |
| 1975 | 1975 | ?> |
| 1976 | 1976 | <div class="wpinv-subscriptions-details"> |
| 1977 | - <h3 class="wpinv-subscriptions-t"><?php echo apply_filters( 'wpinv_subscription_details_title', __( 'Subscription Details', 'invoicing' ) ); ?></h3> |
|
| 1977 | + <h3 class="wpinv-subscriptions-t"><?php echo apply_filters('wpinv_subscription_details_title', __('Subscription Details', 'invoicing')); ?></h3> |
|
| 1978 | 1978 | <table class="table"> |
| 1979 | 1979 | <thead> |
| 1980 | 1980 | <tr> |
| 1981 | - <th><?php _e( 'Billing Cycle', 'invoicing' ) ;?></th> |
|
| 1982 | - <th><?php _e( 'Start Date', 'invoicing' ) ;?></th> |
|
| 1983 | - <th><?php _e( 'Expiration Date', 'invoicing' ) ;?></th> |
|
| 1984 | - <th class="text-center"><?php _e( 'Times Billed', 'invoicing' ) ;?></th> |
|
| 1985 | - <th class="text-center"><?php _e( 'Status', 'invoicing' ) ;?></th> |
|
| 1981 | + <th><?php _e('Billing Cycle', 'invoicing'); ?></th> |
|
| 1982 | + <th><?php _e('Start Date', 'invoicing'); ?></th> |
|
| 1983 | + <th><?php _e('Expiration Date', 'invoicing'); ?></th> |
|
| 1984 | + <th class="text-center"><?php _e('Times Billed', 'invoicing'); ?></th> |
|
| 1985 | + <th class="text-center"><?php _e('Status', 'invoicing'); ?></th> |
|
| 1986 | 1986 | </tr> |
| 1987 | 1987 | </thead> |
| 1988 | 1988 | <tbody> |
@@ -1991,32 +1991,32 @@ discard block |
||
| 1991 | 1991 | <td><?php echo $invoice->get_subscription_start(); ?></td> |
| 1992 | 1992 | <td><?php echo $invoice->get_subscription_end(); ?></td> |
| 1993 | 1993 | <td class="text-center"><?php echo $times_billed; ?></td> |
| 1994 | - <td class="text-center wpi-sub-status"><?php echo $invoice->get_subscription_status_label() ;?> |
|
| 1994 | + <td class="text-center wpi-sub-status"><?php echo $invoice->get_subscription_status_label(); ?> |
|
| 1995 | 1995 | <?php echo $status_desc; ?> |
| 1996 | 1996 | </td> |
| 1997 | 1997 | </tr> |
| 1998 | 1998 | </tbody> |
| 1999 | 1999 | </table> |
| 2000 | 2000 | </div> |
| 2001 | - <?php if ( !empty( $payments ) ) { ?> |
|
| 2001 | + <?php if (!empty($payments)) { ?> |
|
| 2002 | 2002 | <div class="wpinv-renewal-payments"> |
| 2003 | - <h3 class="wpinv-renewals-t"><?php echo apply_filters( 'wpinv_renewal_payments_title', __( 'Renewal Payments', 'invoicing' ) ); ?></h3> |
|
| 2003 | + <h3 class="wpinv-renewals-t"><?php echo apply_filters('wpinv_renewal_payments_title', __('Renewal Payments', 'invoicing')); ?></h3> |
|
| 2004 | 2004 | <table class="table"> |
| 2005 | 2005 | <thead> |
| 2006 | 2006 | <tr> |
| 2007 | 2007 | <th>#</th> |
| 2008 | - <th><?php _e( 'Invoice', 'invoicing' ) ;?></th> |
|
| 2009 | - <th><?php _e( 'Date', 'invoicing' ) ;?></th> |
|
| 2010 | - <th class="text-right"><?php _e( 'Amount', 'invoicing' ) ;?></th> |
|
| 2008 | + <th><?php _e('Invoice', 'invoicing'); ?></th> |
|
| 2009 | + <th><?php _e('Date', 'invoicing'); ?></th> |
|
| 2010 | + <th class="text-right"><?php _e('Amount', 'invoicing'); ?></th> |
|
| 2011 | 2011 | </tr> |
| 2012 | 2012 | </thead> |
| 2013 | 2013 | <tbody> |
| 2014 | - <?php foreach ( $payments as $key => $invoice_id ) { ?> |
|
| 2014 | + <?php foreach ($payments as $key => $invoice_id) { ?> |
|
| 2015 | 2015 | <tr> |
| 2016 | - <th scope="row"><?php echo ( $key + 1 );?></th> |
|
| 2017 | - <td><?php echo wpinv_invoice_link( $invoice_id ) ;?></td> |
|
| 2018 | - <td><?php echo wpinv_get_invoice_date( $invoice_id ); ?></td> |
|
| 2019 | - <td class="text-right"><?php echo wpinv_payment_total( $invoice_id, true ); ?></td> |
|
| 2016 | + <th scope="row"><?php echo ($key + 1); ?></th> |
|
| 2017 | + <td><?php echo wpinv_invoice_link($invoice_id); ?></td> |
|
| 2018 | + <td><?php echo wpinv_get_invoice_date($invoice_id); ?></td> |
|
| 2019 | + <td class="text-right"><?php echo wpinv_payment_total($invoice_id, true); ?></td> |
|
| 2020 | 2020 | </tr> |
| 2021 | 2021 | <?php } ?> |
| 2022 | 2022 | <tr><td colspan="4" style="padding:0"></td></tr> |
@@ -2028,52 +2028,52 @@ discard block |
||
| 2028 | 2028 | } |
| 2029 | 2029 | } |
| 2030 | 2030 | |
| 2031 | -function wpinv_cart_total_label( $label, $invoice ) { |
|
| 2032 | - if ( empty( $invoice ) ) { |
|
| 2031 | +function wpinv_cart_total_label($label, $invoice) { |
|
| 2032 | + if (empty($invoice)) { |
|
| 2033 | 2033 | return $label; |
| 2034 | 2034 | } |
| 2035 | 2035 | |
| 2036 | 2036 | $prefix_label = ''; |
| 2037 | - if ( $invoice->is_parent() && $item_id = $invoice->get_recurring() ) { |
|
| 2038 | - $prefix_label = '<span class="label label-primary label-recurring">' . __( 'Recurring Payment', 'invoicing' ) . '</span> ' . wpinv_subscription_payment_desc( $invoice ); |
|
| 2039 | - } else if ( $invoice->is_renewal() ) { |
|
| 2040 | - $prefix_label = '<span class="label label-primary label-renewal">' . __( 'Renewal Payment', 'invoicing' ) . '</span> '; |
|
| 2037 | + if ($invoice->is_parent() && $item_id = $invoice->get_recurring()) { |
|
| 2038 | + $prefix_label = '<span class="label label-primary label-recurring">' . __('Recurring Payment', 'invoicing') . '</span> ' . wpinv_subscription_payment_desc($invoice); |
|
| 2039 | + } else if ($invoice->is_renewal()) { |
|
| 2040 | + $prefix_label = '<span class="label label-primary label-renewal">' . __('Renewal Payment', 'invoicing') . '</span> '; |
|
| 2041 | 2041 | } |
| 2042 | 2042 | |
| 2043 | - if ( $prefix_label != '' ) { |
|
| 2044 | - $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label; |
|
| 2043 | + if ($prefix_label != '') { |
|
| 2044 | + $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label; |
|
| 2045 | 2045 | } |
| 2046 | 2046 | |
| 2047 | 2047 | return $label; |
| 2048 | 2048 | } |
| 2049 | -add_filter( 'wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
| 2050 | -add_filter( 'wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
| 2051 | -add_filter( 'wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
| 2049 | +add_filter('wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
| 2050 | +add_filter('wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
| 2051 | +add_filter('wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
| 2052 | 2052 | |
| 2053 | -add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1 ); |
|
| 2053 | +add_action('wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1); |
|
| 2054 | 2054 | |
| 2055 | -function wpinv_invoice_print_description( $invoice ) { |
|
| 2056 | - if ( empty( $invoice ) ) { |
|
| 2055 | +function wpinv_invoice_print_description($invoice) { |
|
| 2056 | + if (empty($invoice)) { |
|
| 2057 | 2057 | return NULL; |
| 2058 | 2058 | } |
| 2059 | - if ( $description = wpinv_get_invoice_description( $invoice->ID ) ) { |
|
| 2059 | + if ($description = wpinv_get_invoice_description($invoice->ID)) { |
|
| 2060 | 2060 | ?> |
| 2061 | 2061 | <div class="row wpinv-lower"> |
| 2062 | 2062 | <div class="col-sm-12 wpinv-description"> |
| 2063 | - <?php echo wpautop( $description ); ?> |
|
| 2063 | + <?php echo wpautop($description); ?> |
|
| 2064 | 2064 | </div> |
| 2065 | 2065 | </div> |
| 2066 | 2066 | <?php |
| 2067 | 2067 | } |
| 2068 | 2068 | } |
| 2069 | -add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1 ); |
|
| 2069 | +add_action('wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1); |
|
| 2070 | 2070 | |
| 2071 | -function wpinv_invoice_print_payment_info( $invoice ) { |
|
| 2072 | - if ( empty( $invoice ) ) { |
|
| 2071 | +function wpinv_invoice_print_payment_info($invoice) { |
|
| 2072 | + if (empty($invoice)) { |
|
| 2073 | 2073 | return NULL; |
| 2074 | 2074 | } |
| 2075 | 2075 | |
| 2076 | - if ( $payments_info = wpinv_display_payments_info( $invoice->ID, false ) ) { |
|
| 2076 | + if ($payments_info = wpinv_display_payments_info($invoice->ID, false)) { |
|
| 2077 | 2077 | ?> |
| 2078 | 2078 | <div class="row wpinv-payments"> |
| 2079 | 2079 | <div class="col-sm-12"> |
@@ -2085,40 +2085,40 @@ discard block |
||
| 2085 | 2085 | } |
| 2086 | 2086 | // add_action( 'wpinv_invoice_print_after_line_items', 'wpinv_invoice_print_payment_info', 10, 1 ); |
| 2087 | 2087 | |
| 2088 | -function wpinv_get_invoice_note_line_item( $note, $echo = true ) { |
|
| 2089 | - if ( empty( $note ) ) { |
|
| 2088 | +function wpinv_get_invoice_note_line_item($note, $echo = true) { |
|
| 2089 | + if (empty($note)) { |
|
| 2090 | 2090 | return NULL; |
| 2091 | 2091 | } |
| 2092 | 2092 | |
| 2093 | - if ( is_int( $note ) ) { |
|
| 2094 | - $note = get_comment( $note ); |
|
| 2093 | + if (is_int($note)) { |
|
| 2094 | + $note = get_comment($note); |
|
| 2095 | 2095 | } |
| 2096 | 2096 | |
| 2097 | - if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) { |
|
| 2097 | + if (!(is_object($note) && is_a($note, 'WP_Comment'))) { |
|
| 2098 | 2098 | return NULL; |
| 2099 | 2099 | } |
| 2100 | 2100 | |
| 2101 | - $note_classes = array( 'note' ); |
|
| 2102 | - $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : ''; |
|
| 2103 | - $note_classes[] = $note->comment_author === __( 'GeoDirectory', 'invoicing' ) ? 'system-note' : ''; |
|
| 2104 | - $note_classes = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note ); |
|
| 2105 | - $note_classes = !empty( $note_classes ) ? implode( ' ', $note_classes ) : ''; |
|
| 2101 | + $note_classes = array('note'); |
|
| 2102 | + $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : ''; |
|
| 2103 | + $note_classes[] = $note->comment_author === __('GeoDirectory', 'invoicing') ? 'system-note' : ''; |
|
| 2104 | + $note_classes = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note); |
|
| 2105 | + $note_classes = !empty($note_classes) ? implode(' ', $note_classes) : ''; |
|
| 2106 | 2106 | |
| 2107 | 2107 | ob_start(); |
| 2108 | 2108 | ?> |
| 2109 | - <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?>"> |
|
| 2109 | + <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?>"> |
|
| 2110 | 2110 | <div class="note_content"> |
| 2111 | - <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?> |
|
| 2111 | + <?php echo wpautop(wptexturize(wp_kses_post($note->comment_content))); ?> |
|
| 2112 | 2112 | </div> |
| 2113 | 2113 | <p class="meta"> |
| 2114 | - <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf( __( '%1$s - %2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( get_option( 'date_format' ), strtotime( $note->comment_date ) ), date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) ); ?></abbr> <a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a> |
|
| 2114 | + <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf(__('%1$s - %2$s at %3$s', 'invoicing'), $note->comment_author, date_i18n(get_option('date_format'), strtotime($note->comment_date)), date_i18n(get_option('time_format'), strtotime($note->comment_date))); ?></abbr> <a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a> |
|
| 2115 | 2115 | </p> |
| 2116 | 2116 | </li> |
| 2117 | 2117 | <?php |
| 2118 | 2118 | $note_content = ob_get_clean(); |
| 2119 | - $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo ); |
|
| 2119 | + $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo); |
|
| 2120 | 2120 | |
| 2121 | - if ( $echo ) { |
|
| 2121 | + if ($echo) { |
|
| 2122 | 2122 | echo $note_content; |
| 2123 | 2123 | } else { |
| 2124 | 2124 | return $note_content; |
@@ -1,19 +1,19 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | // Exit if accessed directly |
| 3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 3 | +if (!defined('ABSPATH')) exit; |
|
| 4 | 4 | |
| 5 | -function wpinv_get_item_by( $field = '', $value = '', $type = '' ) { |
|
| 6 | - if( empty( $field ) || empty( $value ) ) { |
|
| 5 | +function wpinv_get_item_by($field = '', $value = '', $type = '') { |
|
| 6 | + if (empty($field) || empty($value)) { |
|
| 7 | 7 | return false; |
| 8 | 8 | } |
| 9 | 9 | |
| 10 | 10 | $posts = array(); |
| 11 | 11 | |
| 12 | - switch( strtolower( $field ) ) { |
|
| 12 | + switch (strtolower($field)) { |
|
| 13 | 13 | case 'id': |
| 14 | - $item = get_post( $value ); |
|
| 14 | + $item = get_post($value); |
|
| 15 | 15 | |
| 16 | - if( get_post_type( $item ) != 'wpi_item' ) { |
|
| 16 | + if (get_post_type($item) != 'wpi_item') { |
|
| 17 | 17 | return false; |
| 18 | 18 | } |
| 19 | 19 | |
@@ -21,16 +21,16 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | case 'slug': |
| 23 | 23 | case 'name': |
| 24 | - $posts = get_posts( array( |
|
| 24 | + $posts = get_posts(array( |
|
| 25 | 25 | 'post_type' => 'wpi_item', |
| 26 | 26 | 'name' => $value, |
| 27 | 27 | 'posts_per_page' => 1, |
| 28 | 28 | 'post_status' => 'any' |
| 29 | - ) ); |
|
| 29 | + )); |
|
| 30 | 30 | |
| 31 | 31 | break; |
| 32 | 32 | case 'custom_id': |
| 33 | - if ( empty( $value ) || empty( $type ) ) { |
|
| 33 | + if (empty($value) || empty($type)) { |
|
| 34 | 34 | return false; |
| 35 | 35 | } |
| 36 | 36 | |
@@ -50,10 +50,10 @@ discard block |
||
| 50 | 50 | 'post_status' => 'any', |
| 51 | 51 | 'orderby' => 'ID', |
| 52 | 52 | 'order' => 'ASC', |
| 53 | - 'meta_query' => array( $meta_query ) |
|
| 53 | + 'meta_query' => array($meta_query) |
|
| 54 | 54 | ); |
| 55 | 55 | |
| 56 | - $posts = get_posts( $args ); |
|
| 56 | + $posts = get_posts($args); |
|
| 57 | 57 | |
| 58 | 58 | break; |
| 59 | 59 | |
@@ -61,17 +61,17 @@ discard block |
||
| 61 | 61 | return false; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - if ( !empty( $posts[0] ) ) { |
|
| 65 | - return new WPInv_Item( $posts[0]->ID ); |
|
| 64 | + if (!empty($posts[0])) { |
|
| 65 | + return new WPInv_Item($posts[0]->ID); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | return false; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | -function wpinv_get_item( $item = 0 ) { |
|
| 72 | - if ( is_numeric( $item ) ) { |
|
| 73 | - $item = get_post( $item ); |
|
| 74 | - if ( ! $item || 'wpi_item' !== $item->post_type ) |
|
| 71 | +function wpinv_get_item($item = 0) { |
|
| 72 | + if (is_numeric($item)) { |
|
| 73 | + $item = get_post($item); |
|
| 74 | + if (!$item || 'wpi_item' !== $item->post_type) |
|
| 75 | 75 | return null; |
| 76 | 76 | return $item; |
| 77 | 77 | } |
@@ -84,136 +84,136 @@ discard block |
||
| 84 | 84 | |
| 85 | 85 | $item = get_posts($args); |
| 86 | 86 | |
| 87 | - if ( $item ) { |
|
| 87 | + if ($item) { |
|
| 88 | 88 | return $item[0]; |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | return null; |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | -function wpinv_is_free_item( $item_id = 0 ) { |
|
| 95 | - if( empty( $item_id ) ) { |
|
| 94 | +function wpinv_is_free_item($item_id = 0) { |
|
| 95 | + if (empty($item_id)) { |
|
| 96 | 96 | return false; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - $item = new WPInv_Item( $item_id ); |
|
| 99 | + $item = new WPInv_Item($item_id); |
|
| 100 | 100 | |
| 101 | 101 | return $item->is_free(); |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | -function wpinv_get_item_price( $item_id = 0 ) { |
|
| 105 | - if( empty( $item_id ) ) { |
|
| 104 | +function wpinv_get_item_price($item_id = 0) { |
|
| 105 | + if (empty($item_id)) { |
|
| 106 | 106 | return false; |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - $item = new WPInv_Item( $item_id ); |
|
| 109 | + $item = new WPInv_Item($item_id); |
|
| 110 | 110 | |
| 111 | 111 | return $item->get_price(); |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | -function wpinv_is_recurring_item( $item_id = 0 ) { |
|
| 115 | - if( empty( $item_id ) ) { |
|
| 114 | +function wpinv_is_recurring_item($item_id = 0) { |
|
| 115 | + if (empty($item_id)) { |
|
| 116 | 116 | return false; |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - $item = new WPInv_Item( $item_id ); |
|
| 119 | + $item = new WPInv_Item($item_id); |
|
| 120 | 120 | |
| 121 | 121 | return $item->is_recurring(); |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | -function wpinv_item_price( $item_id = 0 ) { |
|
| 125 | - if( empty( $item_id ) ) { |
|
| 124 | +function wpinv_item_price($item_id = 0) { |
|
| 125 | + if (empty($item_id)) { |
|
| 126 | 126 | return false; |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | - $price = wpinv_get_item_price( $item_id ); |
|
| 130 | - $price = wpinv_price( wpinv_format_amount( $price ) ); |
|
| 129 | + $price = wpinv_get_item_price($item_id); |
|
| 130 | + $price = wpinv_price(wpinv_format_amount($price)); |
|
| 131 | 131 | |
| 132 | - return apply_filters( 'wpinv_item_price', $price, $item_id ); |
|
| 132 | + return apply_filters('wpinv_item_price', $price, $item_id); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | -function wpinv_item_show_price( $item_id = 0, $echo = true ) { |
|
| 136 | - if ( empty( $item_id ) ) { |
|
| 135 | +function wpinv_item_show_price($item_id = 0, $echo = true) { |
|
| 136 | + if (empty($item_id)) { |
|
| 137 | 137 | $item_id = get_the_ID(); |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - $price = wpinv_item_price( $item_id ); |
|
| 140 | + $price = wpinv_item_price($item_id); |
|
| 141 | 141 | |
| 142 | - $price = apply_filters( 'wpinv_item_price', wpinv_sanitize_amount( $price ), $item_id ); |
|
| 142 | + $price = apply_filters('wpinv_item_price', wpinv_sanitize_amount($price), $item_id); |
|
| 143 | 143 | $formatted_price = '<span class="wpinv_price" id="wpinv_item_' . $item_id . '">' . $price . '</span>'; |
| 144 | - $formatted_price = apply_filters( 'wpinv_item_price_after_html', $formatted_price, $item_id, $price ); |
|
| 144 | + $formatted_price = apply_filters('wpinv_item_price_after_html', $formatted_price, $item_id, $price); |
|
| 145 | 145 | |
| 146 | - if ( $echo ) { |
|
| 146 | + if ($echo) { |
|
| 147 | 147 | echo $formatted_price; |
| 148 | 148 | } else { |
| 149 | 149 | return $formatted_price; |
| 150 | 150 | } |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | -function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) { |
|
| 154 | - if ( is_null( $amount_override ) ) { |
|
| 155 | - $original_price = get_post_meta( $item_id, '_wpinv_price', true ); |
|
| 153 | +function wpinv_get_item_final_price($item_id = 0, $amount_override = null) { |
|
| 154 | + if (is_null($amount_override)) { |
|
| 155 | + $original_price = get_post_meta($item_id, '_wpinv_price', true); |
|
| 156 | 156 | } else { |
| 157 | 157 | $original_price = $amount_override; |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | $price = $original_price; |
| 161 | 161 | |
| 162 | - return apply_filters( 'wpinv_get_item_final_price', $price, $item_id ); |
|
| 162 | + return apply_filters('wpinv_get_item_final_price', $price, $item_id); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | -function wpinv_item_custom_singular_name( $item_id ) { |
|
| 166 | - if( empty( $item_id ) ) { |
|
| 165 | +function wpinv_item_custom_singular_name($item_id) { |
|
| 166 | + if (empty($item_id)) { |
|
| 167 | 167 | return false; |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | - $item = new WPInv_Item( $item_id ); |
|
| 170 | + $item = new WPInv_Item($item_id); |
|
| 171 | 171 | |
| 172 | 172 | return $item->get_custom_singular_name(); |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | function wpinv_get_item_types() { |
| 176 | 176 | $item_types = array( |
| 177 | - 'custom' => __( 'Standard', 'invoicing' ), |
|
| 178 | - 'fee' => __( 'Fee', 'invoicing' ), |
|
| 177 | + 'custom' => __('Standard', 'invoicing'), |
|
| 178 | + 'fee' => __('Fee', 'invoicing'), |
|
| 179 | 179 | ); |
| 180 | - return apply_filters( 'wpinv_get_item_types', $item_types ); |
|
| 180 | + return apply_filters('wpinv_get_item_types', $item_types); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | function wpinv_item_types() { |
| 184 | 184 | $item_types = wpinv_get_item_types(); |
| 185 | 185 | |
| 186 | - return ( !empty( $item_types ) ? array_keys( $item_types ) : array() ); |
|
| 186 | + return (!empty($item_types) ? array_keys($item_types) : array()); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | -function wpinv_get_item_type( $item_id ) { |
|
| 190 | - if( empty( $item_id ) ) { |
|
| 189 | +function wpinv_get_item_type($item_id) { |
|
| 190 | + if (empty($item_id)) { |
|
| 191 | 191 | return false; |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | - $item = new WPInv_Item( $item_id ); |
|
| 194 | + $item = new WPInv_Item($item_id); |
|
| 195 | 195 | |
| 196 | 196 | return $item->get_type(); |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | -function wpinv_item_type( $item_id ) { |
|
| 199 | +function wpinv_item_type($item_id) { |
|
| 200 | 200 | $item_types = wpinv_get_item_types(); |
| 201 | 201 | |
| 202 | - $item_type = wpinv_get_item_type( $item_id ); |
|
| 202 | + $item_type = wpinv_get_item_type($item_id); |
|
| 203 | 203 | |
| 204 | - if ( empty( $item_type ) ) { |
|
| 204 | + if (empty($item_type)) { |
|
| 205 | 205 | $item_type = '-'; |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | - $item_type = isset( $item_types[$item_type] ) ? $item_types[$item_type] : __( $item_type, 'invoicing' ); |
|
| 208 | + $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing'); |
|
| 209 | 209 | |
| 210 | - return apply_filters( 'wpinv_item_type', $item_type, $item_id ); |
|
| 210 | + return apply_filters('wpinv_item_type', $item_type, $item_id); |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | -function wpinv_record_item_in_log( $item_id = 0, $file_id, $user_info, $ip, $invoice_id ) { |
|
| 213 | +function wpinv_record_item_in_log($item_id = 0, $file_id, $user_info, $ip, $invoice_id) { |
|
| 214 | 214 | global $wpinv_logs; |
| 215 | 215 | |
| 216 | - if ( empty( $wpinv_logs ) ) { |
|
| 216 | + if (empty($wpinv_logs)) { |
|
| 217 | 217 | return false; |
| 218 | 218 | } |
| 219 | 219 | |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | 'log_type' => 'wpi_item' |
| 223 | 223 | ); |
| 224 | 224 | |
| 225 | - $user_id = isset( $user_info['user_id'] ) ? $user_info['user_id'] : (int) -1; |
|
| 225 | + $user_id = isset($user_info['user_id']) ? $user_info['user_id'] : (int) -1; |
|
| 226 | 226 | |
| 227 | 227 | $log_meta = array( |
| 228 | 228 | 'user_info' => $user_info, |
@@ -232,247 +232,247 @@ discard block |
||
| 232 | 232 | 'invoice_id'=> $invoice_id, |
| 233 | 233 | ); |
| 234 | 234 | |
| 235 | - $wpinv_logs->insert_log( $log_data, $log_meta ); |
|
| 235 | + $wpinv_logs->insert_log($log_data, $log_meta); |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | -function wpinv_remove_item_logs_on_delete( $item_id = 0 ) { |
|
| 239 | - if ( 'wpi_item' !== get_post_type( $item_id ) ) |
|
| 238 | +function wpinv_remove_item_logs_on_delete($item_id = 0) { |
|
| 239 | + if ('wpi_item' !== get_post_type($item_id)) |
|
| 240 | 240 | return; |
| 241 | 241 | |
| 242 | 242 | global $wpinv_logs; |
| 243 | 243 | |
| 244 | - if ( empty( $wpinv_logs ) ) { |
|
| 244 | + if (empty($wpinv_logs)) { |
|
| 245 | 245 | return false; |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | // Remove all log entries related to this item |
| 249 | - $wpinv_logs->delete_logs( $item_id ); |
|
| 249 | + $wpinv_logs->delete_logs($item_id); |
|
| 250 | 250 | } |
| 251 | -add_action( 'delete_post', 'wpinv_remove_item_logs_on_delete' ); |
|
| 251 | +add_action('delete_post', 'wpinv_remove_item_logs_on_delete'); |
|
| 252 | 252 | |
| 253 | -function wpinv_get_random_item( $post_ids = true ) { |
|
| 254 | - wpinv_get_random_items( 1, $post_ids ); |
|
| 253 | +function wpinv_get_random_item($post_ids = true) { |
|
| 254 | + wpinv_get_random_items(1, $post_ids); |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | -function wpinv_get_random_items( $num = 3, $post_ids = true ) { |
|
| 258 | - if ( $post_ids ) { |
|
| 259 | - $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids' ); |
|
| 257 | +function wpinv_get_random_items($num = 3, $post_ids = true) { |
|
| 258 | + if ($post_ids) { |
|
| 259 | + $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids'); |
|
| 260 | 260 | } else { |
| 261 | - $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num ); |
|
| 261 | + $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num); |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | - $args = apply_filters( 'wpinv_get_random_items', $args ); |
|
| 264 | + $args = apply_filters('wpinv_get_random_items', $args); |
|
| 265 | 265 | |
| 266 | - return get_posts( $args ); |
|
| 266 | + return get_posts($args); |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | -function wpinv_get_item_token( $url = '' ) { |
|
| 269 | +function wpinv_get_item_token($url = '') { |
|
| 270 | 270 | $args = array(); |
| 271 | - $hash = apply_filters( 'wpinv_get_url_token_algorithm', 'sha256' ); |
|
| 272 | - $secret = apply_filters( 'wpinv_get_url_token_secret', hash( $hash, wp_salt() ) ); |
|
| 271 | + $hash = apply_filters('wpinv_get_url_token_algorithm', 'sha256'); |
|
| 272 | + $secret = apply_filters('wpinv_get_url_token_secret', hash($hash, wp_salt())); |
|
| 273 | 273 | |
| 274 | - $parts = parse_url( $url ); |
|
| 274 | + $parts = parse_url($url); |
|
| 275 | 275 | $options = array(); |
| 276 | 276 | |
| 277 | - if ( isset( $parts['query'] ) ) { |
|
| 278 | - wp_parse_str( $parts['query'], $query_args ); |
|
| 277 | + if (isset($parts['query'])) { |
|
| 278 | + wp_parse_str($parts['query'], $query_args); |
|
| 279 | 279 | |
| 280 | - if ( ! empty( $query_args['o'] ) ) { |
|
| 281 | - $options = explode( ':', rawurldecode( $query_args['o'] ) ); |
|
| 280 | + if (!empty($query_args['o'])) { |
|
| 281 | + $options = explode(':', rawurldecode($query_args['o'])); |
|
| 282 | 282 | |
| 283 | - if ( in_array( 'ip', $options ) ) { |
|
| 283 | + if (in_array('ip', $options)) { |
|
| 284 | 284 | $args['ip'] = wpinv_get_ip(); |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | - if ( in_array( 'ua', $options ) ) { |
|
| 287 | + if (in_array('ua', $options)) { |
|
| 288 | 288 | $ua = wpinv_get_user_agent(); |
| 289 | - $args['user_agent'] = rawurlencode( $ua ); |
|
| 289 | + $args['user_agent'] = rawurlencode($ua); |
|
| 290 | 290 | } |
| 291 | 291 | } |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | - $args = apply_filters( 'wpinv_get_url_token_args', $args, $url, $options ); |
|
| 294 | + $args = apply_filters('wpinv_get_url_token_args', $args, $url, $options); |
|
| 295 | 295 | |
| 296 | 296 | $args['secret'] = $secret; |
| 297 | 297 | $args['token'] = false; |
| 298 | 298 | |
| 299 | - $url = add_query_arg( $args, $url ); |
|
| 300 | - $parts = parse_url( $url ); |
|
| 299 | + $url = add_query_arg($args, $url); |
|
| 300 | + $parts = parse_url($url); |
|
| 301 | 301 | |
| 302 | - if ( ! isset( $parts['path'] ) ) { |
|
| 302 | + if (!isset($parts['path'])) { |
|
| 303 | 303 | $parts['path'] = ''; |
| 304 | 304 | } |
| 305 | 305 | |
| 306 | - $token = md5( $parts['path'] . '?' . $parts['query'] ); |
|
| 306 | + $token = md5($parts['path'] . '?' . $parts['query']); |
|
| 307 | 307 | |
| 308 | 308 | return $token; |
| 309 | 309 | } |
| 310 | 310 | |
| 311 | -function wpinv_validate_url_token( $url = '' ) { |
|
| 311 | +function wpinv_validate_url_token($url = '') { |
|
| 312 | 312 | $ret = false; |
| 313 | - $parts = parse_url( $url ); |
|
| 313 | + $parts = parse_url($url); |
|
| 314 | 314 | |
| 315 | - if ( isset( $parts['query'] ) ) { |
|
| 316 | - wp_parse_str( $parts['query'], $query_args ); |
|
| 315 | + if (isset($parts['query'])) { |
|
| 316 | + wp_parse_str($parts['query'], $query_args); |
|
| 317 | 317 | |
| 318 | - $allowed = apply_filters( 'wpinv_url_token_allowed_params', array( |
|
| 318 | + $allowed = apply_filters('wpinv_url_token_allowed_params', array( |
|
| 319 | 319 | 'item', |
| 320 | 320 | 'ttl', |
| 321 | 321 | 'token' |
| 322 | - ) ); |
|
| 322 | + )); |
|
| 323 | 323 | |
| 324 | 324 | $remove = array(); |
| 325 | 325 | |
| 326 | - foreach( $query_args as $key => $value ) { |
|
| 327 | - if( false === in_array( $key, $allowed ) ) { |
|
| 326 | + foreach ($query_args as $key => $value) { |
|
| 327 | + if (false === in_array($key, $allowed)) { |
|
| 328 | 328 | $remove[] = $key; |
| 329 | 329 | } |
| 330 | 330 | } |
| 331 | 331 | |
| 332 | - if( ! empty( $remove ) ) { |
|
| 333 | - $url = remove_query_arg( $remove, $url ); |
|
| 332 | + if (!empty($remove)) { |
|
| 333 | + $url = remove_query_arg($remove, $url); |
|
| 334 | 334 | } |
| 335 | 335 | |
| 336 | - if ( isset( $query_args['ttl'] ) && current_time( 'timestamp' ) > $query_args['ttl'] ) { |
|
| 337 | - wp_die( apply_filters( 'wpinv_item_link_expired_text', __( 'Sorry but your item link has expired.', 'invoicing' ) ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 336 | + if (isset($query_args['ttl']) && current_time('timestamp') > $query_args['ttl']) { |
|
| 337 | + wp_die(apply_filters('wpinv_item_link_expired_text', __('Sorry but your item link has expired.', 'invoicing')), __('Error', 'invoicing'), array('response' => 403)); |
|
| 338 | 338 | } |
| 339 | 339 | |
| 340 | - if ( isset( $query_args['token'] ) && $query_args['token'] == wpinv_get_item_token( $url ) ) { |
|
| 340 | + if (isset($query_args['token']) && $query_args['token'] == wpinv_get_item_token($url)) { |
|
| 341 | 341 | $ret = true; |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | } |
| 345 | 345 | |
| 346 | - return apply_filters( 'wpinv_validate_url_token', $ret, $url, $query_args ); |
|
| 346 | + return apply_filters('wpinv_validate_url_token', $ret, $url, $query_args); |
|
| 347 | 347 | } |
| 348 | 348 | |
| 349 | -function wpinv_item_in_cart( $item_id = 0, $options = array() ) { |
|
| 349 | +function wpinv_item_in_cart($item_id = 0, $options = array()) { |
|
| 350 | 350 | $cart_items = wpinv_get_cart_contents(); |
| 351 | 351 | |
| 352 | 352 | $ret = false; |
| 353 | 353 | |
| 354 | - if ( is_array( $cart_items ) ) { |
|
| 355 | - foreach ( $cart_items as $item ) { |
|
| 356 | - if ( $item['id'] == $item_id ) { |
|
| 354 | + if (is_array($cart_items)) { |
|
| 355 | + foreach ($cart_items as $item) { |
|
| 356 | + if ($item['id'] == $item_id) { |
|
| 357 | 357 | $ret = true; |
| 358 | 358 | break; |
| 359 | 359 | } |
| 360 | 360 | } |
| 361 | 361 | } |
| 362 | 362 | |
| 363 | - return (bool) apply_filters( 'wpinv_item_in_cart', $ret, $item_id, $options ); |
|
| 363 | + return (bool)apply_filters('wpinv_item_in_cart', $ret, $item_id, $options); |
|
| 364 | 364 | } |
| 365 | 365 | |
| 366 | -function wpinv_get_cart_item_tax( $item_id = 0, $subtotal = '', $options = array() ) { |
|
| 366 | +function wpinv_get_cart_item_tax($item_id = 0, $subtotal = '', $options = array()) { |
|
| 367 | 367 | $tax = 0; |
| 368 | - if ( ! wpinv_item_is_tax_exclusive( $item_id ) ) { |
|
| 369 | - $country = !empty( $_POST['country'] ) ? $_POST['country'] : false; |
|
| 370 | - $state = isset( $_POST['state'] ) ? $_POST['state'] : ''; |
|
| 368 | + if (!wpinv_item_is_tax_exclusive($item_id)) { |
|
| 369 | + $country = !empty($_POST['country']) ? $_POST['country'] : false; |
|
| 370 | + $state = isset($_POST['state']) ? $_POST['state'] : ''; |
|
| 371 | 371 | |
| 372 | - $tax = wpinv_calculate_tax( $subtotal, $country, $state, $item_id ); |
|
| 372 | + $tax = wpinv_calculate_tax($subtotal, $country, $state, $item_id); |
|
| 373 | 373 | } |
| 374 | 374 | |
| 375 | - return apply_filters( 'wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options ); |
|
| 375 | + return apply_filters('wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options); |
|
| 376 | 376 | } |
| 377 | 377 | |
| 378 | -function wpinv_cart_item_price( $item ) { |
|
| 378 | +function wpinv_cart_item_price($item) { |
|
| 379 | 379 | $use_taxes = wpinv_use_taxes(); |
| 380 | - $item_id = isset( $item['id'] ) ? $item['id'] : 0; |
|
| 381 | - $price = isset( $item['item_price'] ) ? wpinv_round_amount( $item['item_price'] ) : 0; |
|
| 382 | - $options = isset( $item['options'] ) ? $item['options'] : array(); |
|
| 383 | - $price_id = isset( $options['price_id'] ) ? $options['price_id'] : false; |
|
| 384 | - $tax = wpinv_price( wpinv_format_amount( $item['tax'] ) ); |
|
| 385 | - |
|
| 386 | - if ( !wpinv_is_free_item( $item_id, $price_id ) && !wpinv_item_is_tax_exclusive( $item_id ) ) { |
|
| 387 | - if ( wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax() ) { |
|
| 380 | + $item_id = isset($item['id']) ? $item['id'] : 0; |
|
| 381 | + $price = isset($item['item_price']) ? wpinv_round_amount($item['item_price']) : 0; |
|
| 382 | + $options = isset($item['options']) ? $item['options'] : array(); |
|
| 383 | + $price_id = isset($options['price_id']) ? $options['price_id'] : false; |
|
| 384 | + $tax = wpinv_price(wpinv_format_amount($item['tax'])); |
|
| 385 | + |
|
| 386 | + if (!wpinv_is_free_item($item_id, $price_id) && !wpinv_item_is_tax_exclusive($item_id)) { |
|
| 387 | + if (wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax()) { |
|
| 388 | 388 | $price += $tax; |
| 389 | 389 | } |
| 390 | 390 | |
| 391 | - if( !wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax() ) { |
|
| 391 | + if (!wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax()) { |
|
| 392 | 392 | $price -= $tax; |
| 393 | 393 | } |
| 394 | 394 | } |
| 395 | 395 | |
| 396 | - $price = wpinv_price( wpinv_format_amount( $price ) ); |
|
| 396 | + $price = wpinv_price(wpinv_format_amount($price)); |
|
| 397 | 397 | |
| 398 | - return apply_filters( 'wpinv_cart_item_price_label', $price, $item ); |
|
| 398 | + return apply_filters('wpinv_cart_item_price_label', $price, $item); |
|
| 399 | 399 | } |
| 400 | 400 | |
| 401 | -function wpinv_cart_item_subtotal( $item ) { |
|
| 402 | - $subtotal = isset( $item['subtotal'] ) ? $item['subtotal'] : 0; |
|
| 403 | - $subtotal = wpinv_price( wpinv_format_amount( $subtotal ) ); |
|
| 401 | +function wpinv_cart_item_subtotal($item) { |
|
| 402 | + $subtotal = isset($item['subtotal']) ? $item['subtotal'] : 0; |
|
| 403 | + $subtotal = wpinv_price(wpinv_format_amount($subtotal)); |
|
| 404 | 404 | |
| 405 | - return apply_filters( 'wpinv_cart_item_subtotal_label', $subtotal, $item ); |
|
| 405 | + return apply_filters('wpinv_cart_item_subtotal_label', $subtotal, $item); |
|
| 406 | 406 | } |
| 407 | 407 | |
| 408 | -function wpinv_cart_item_tax( $item ) { |
|
| 408 | +function wpinv_cart_item_tax($item) { |
|
| 409 | 409 | $tax = ''; |
| 410 | 410 | $tax_rate = ''; |
| 411 | 411 | |
| 412 | - if ( isset( $item['tax'] ) && $item['tax'] > 0 && $item['subtotal'] > 0 ) { |
|
| 413 | - $tax = wpinv_price( wpinv_format_amount( $item['tax'] ) ); |
|
| 414 | - $tax_rate = !empty( $item['vat_rate'] ) ? $item['vat_rate'] : ( $item['tax'] / $item['subtotal'] ) * 100; |
|
| 415 | - $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : ''; |
|
| 412 | + if (isset($item['tax']) && $item['tax'] > 0 && $item['subtotal'] > 0) { |
|
| 413 | + $tax = wpinv_price(wpinv_format_amount($item['tax'])); |
|
| 414 | + $tax_rate = !empty($item['vat_rate']) ? $item['vat_rate'] : ($item['tax'] / $item['subtotal']) * 100; |
|
| 415 | + $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate, 4) : ''; |
|
| 416 | 416 | $tax_rate = $tax_rate != '' ? ' <small class="tax-rate normal small">(' . $tax_rate . '%)</small>' : ''; |
| 417 | 417 | } |
| 418 | 418 | |
| 419 | - $tax = $tax . $tax_rate; |
|
| 419 | + $tax = $tax . $tax_rate; |
|
| 420 | 420 | |
| 421 | - if ( $tax === '' ) { |
|
| 421 | + if ($tax === '') { |
|
| 422 | 422 | $tax = 0; // Zero tax |
| 423 | 423 | } |
| 424 | 424 | |
| 425 | - return apply_filters( 'wpinv_cart_item_tax_label', $tax, $item ); |
|
| 425 | + return apply_filters('wpinv_cart_item_tax_label', $tax, $item); |
|
| 426 | 426 | } |
| 427 | 427 | |
| 428 | -function wpinv_get_cart_item_price( $item_id = 0, $options = array(), $remove_tax_from_inclusive = false ) { |
|
| 428 | +function wpinv_get_cart_item_price($item_id = 0, $options = array(), $remove_tax_from_inclusive = false) { |
|
| 429 | 429 | $price = 0; |
| 430 | - $variable_prices = wpinv_has_variable_prices( $item_id ); |
|
| 430 | + $variable_prices = wpinv_has_variable_prices($item_id); |
|
| 431 | 431 | |
| 432 | - if ( $variable_prices ) { |
|
| 433 | - $prices = wpinv_get_variable_prices( $item_id ); |
|
| 432 | + if ($variable_prices) { |
|
| 433 | + $prices = wpinv_get_variable_prices($item_id); |
|
| 434 | 434 | |
| 435 | - if ( $prices ) { |
|
| 436 | - if( ! empty( $options ) ) { |
|
| 437 | - $price = isset( $prices[ $options['price_id'] ] ) ? $prices[ $options['price_id'] ]['amount'] : false; |
|
| 435 | + if ($prices) { |
|
| 436 | + if (!empty($options)) { |
|
| 437 | + $price = isset($prices[$options['price_id']]) ? $prices[$options['price_id']]['amount'] : false; |
|
| 438 | 438 | } else { |
| 439 | 439 | $price = false; |
| 440 | 440 | } |
| 441 | 441 | } |
| 442 | 442 | } |
| 443 | 443 | |
| 444 | - if( ! $variable_prices || false === $price ) { |
|
| 444 | + if (!$variable_prices || false === $price) { |
|
| 445 | 445 | // Get the standard Item price if not using variable prices |
| 446 | - $price = wpinv_get_item_price( $item_id ); |
|
| 446 | + $price = wpinv_get_item_price($item_id); |
|
| 447 | 447 | } |
| 448 | 448 | |
| 449 | - if ( $remove_tax_from_inclusive && wpinv_prices_include_tax() ) { |
|
| 450 | - $price -= wpinv_get_cart_item_tax( $item_id, $price, $options ); |
|
| 449 | + if ($remove_tax_from_inclusive && wpinv_prices_include_tax()) { |
|
| 450 | + $price -= wpinv_get_cart_item_tax($item_id, $price, $options); |
|
| 451 | 451 | } |
| 452 | 452 | |
| 453 | - return apply_filters( 'wpinv_cart_item_price', $price, $item_id, $options ); |
|
| 453 | + return apply_filters('wpinv_cart_item_price', $price, $item_id, $options); |
|
| 454 | 454 | } |
| 455 | 455 | |
| 456 | -function wpinv_get_cart_item_price_id( $item = array() ) { |
|
| 457 | - if( isset( $item['item_number'] ) ) { |
|
| 458 | - $price_id = isset( $item['item_number']['options']['price_id'] ) ? $item['item_number']['options']['price_id'] : null; |
|
| 456 | +function wpinv_get_cart_item_price_id($item = array()) { |
|
| 457 | + if (isset($item['item_number'])) { |
|
| 458 | + $price_id = isset($item['item_number']['options']['price_id']) ? $item['item_number']['options']['price_id'] : null; |
|
| 459 | 459 | } else { |
| 460 | - $price_id = isset( $item['options']['price_id'] ) ? $item['options']['price_id'] : null; |
|
| 460 | + $price_id = isset($item['options']['price_id']) ? $item['options']['price_id'] : null; |
|
| 461 | 461 | } |
| 462 | 462 | return $price_id; |
| 463 | 463 | } |
| 464 | 464 | |
| 465 | -function wpinv_get_cart_item_price_name( $item = array() ) { |
|
| 466 | - $price_id = (int)wpinv_get_cart_item_price_id( $item ); |
|
| 467 | - $prices = wpinv_get_variable_prices( $item['id'] ); |
|
| 468 | - $name = ! empty( $prices[ $price_id ] ) ? $prices[ $price_id ]['name'] : ''; |
|
| 469 | - return apply_filters( 'wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item ); |
|
| 465 | +function wpinv_get_cart_item_price_name($item = array()) { |
|
| 466 | + $price_id = (int)wpinv_get_cart_item_price_id($item); |
|
| 467 | + $prices = wpinv_get_variable_prices($item['id']); |
|
| 468 | + $name = !empty($prices[$price_id]) ? $prices[$price_id]['name'] : ''; |
|
| 469 | + return apply_filters('wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item); |
|
| 470 | 470 | } |
| 471 | 471 | |
| 472 | -function wpinv_get_cart_item_name( $item = array() ) { |
|
| 473 | - $item_title = !empty( $item['name'] ) ? $item['name'] : get_the_title( $item['id'] ); |
|
| 472 | +function wpinv_get_cart_item_name($item = array()) { |
|
| 473 | + $item_title = !empty($item['name']) ? $item['name'] : get_the_title($item['id']); |
|
| 474 | 474 | |
| 475 | - if ( empty( $item_title ) ) { |
|
| 475 | + if (empty($item_title)) { |
|
| 476 | 476 | $item_title = $item['id']; |
| 477 | 477 | } |
| 478 | 478 | |
@@ -482,23 +482,23 @@ discard block |
||
| 482 | 482 | } |
| 483 | 483 | */ |
| 484 | 484 | |
| 485 | - return apply_filters( 'wpinv_get_cart_item_name', $item_title, $item['id'], $item ); |
|
| 485 | + return apply_filters('wpinv_get_cart_item_name', $item_title, $item['id'], $item); |
|
| 486 | 486 | } |
| 487 | 487 | |
| 488 | -function wpinv_has_variable_prices( $item_id = 0 ) { |
|
| 488 | +function wpinv_has_variable_prices($item_id = 0) { |
|
| 489 | 489 | return false; |
| 490 | 490 | } |
| 491 | 491 | |
| 492 | -function wpinv_get_item_position_in_cart( $item_id = 0, $options = array() ) { |
|
| 492 | +function wpinv_get_item_position_in_cart($item_id = 0, $options = array()) { |
|
| 493 | 493 | $cart_items = wpinv_get_cart_contents(); |
| 494 | 494 | |
| 495 | - if ( !is_array( $cart_items ) ) { |
|
| 495 | + if (!is_array($cart_items)) { |
|
| 496 | 496 | return false; // Empty cart |
| 497 | 497 | } else { |
| 498 | - foreach ( $cart_items as $position => $item ) { |
|
| 499 | - if ( $item['id'] == $item_id ) { |
|
| 500 | - if ( isset( $options['price_id'] ) && isset( $item['options']['price_id'] ) ) { |
|
| 501 | - if ( (int) $options['price_id'] == (int) $item['options']['price_id'] ) { |
|
| 498 | + foreach ($cart_items as $position => $item) { |
|
| 499 | + if ($item['id'] == $item_id) { |
|
| 500 | + if (isset($options['price_id']) && isset($item['options']['price_id'])) { |
|
| 501 | + if ((int)$options['price_id'] == (int)$item['options']['price_id']) { |
|
| 502 | 502 | return $position; |
| 503 | 503 | } |
| 504 | 504 | } else { |
@@ -511,80 +511,80 @@ discard block |
||
| 511 | 511 | return false; // Not found |
| 512 | 512 | } |
| 513 | 513 | |
| 514 | -function wpinv_get_cart_item_quantity( $item ) { |
|
| 515 | - if ( wpinv_item_quantities_enabled() ) { |
|
| 516 | - $quantity = !empty( $item['quantity'] ) && (int)$item['quantity'] > 0 ? absint( $item['quantity'] ) : 1; |
|
| 514 | +function wpinv_get_cart_item_quantity($item) { |
|
| 515 | + if (wpinv_item_quantities_enabled()) { |
|
| 516 | + $quantity = !empty($item['quantity']) && (int)$item['quantity'] > 0 ? absint($item['quantity']) : 1; |
|
| 517 | 517 | } else { |
| 518 | 518 | $quantity = 1; |
| 519 | 519 | } |
| 520 | 520 | |
| 521 | - if ( $quantity < 1 ) { |
|
| 521 | + if ($quantity < 1) { |
|
| 522 | 522 | $quantity = 1; |
| 523 | 523 | } |
| 524 | 524 | |
| 525 | - return apply_filters( 'wpinv_get_cart_item_quantity', $quantity, $item ); |
|
| 525 | + return apply_filters('wpinv_get_cart_item_quantity', $quantity, $item); |
|
| 526 | 526 | } |
| 527 | 527 | |
| 528 | -function wpinv_get_item_suffix( $item, $html = true ) { |
|
| 529 | - if ( empty( $item ) ) { |
|
| 528 | +function wpinv_get_item_suffix($item, $html = true) { |
|
| 529 | + if (empty($item)) { |
|
| 530 | 530 | return NULL; |
| 531 | 531 | } |
| 532 | 532 | |
| 533 | - if ( is_int( $item ) ) { |
|
| 534 | - $item = new WPInv_Item( $item ); |
|
| 533 | + if (is_int($item)) { |
|
| 534 | + $item = new WPInv_Item($item); |
|
| 535 | 535 | } |
| 536 | 536 | |
| 537 | - if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) { |
|
| 537 | + if (!(is_object($item) && is_a($item, 'WPInv_Item'))) { |
|
| 538 | 538 | return NULL; |
| 539 | 539 | } |
| 540 | 540 | |
| 541 | - $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : ''; |
|
| 541 | + $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : ''; |
|
| 542 | 542 | |
| 543 | - if ( !$html && $suffix ) { |
|
| 544 | - $suffix = strip_tags( $suffix ); |
|
| 543 | + if (!$html && $suffix) { |
|
| 544 | + $suffix = strip_tags($suffix); |
|
| 545 | 545 | } |
| 546 | 546 | |
| 547 | - return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html ); |
|
| 547 | + return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html); |
|
| 548 | 548 | } |
| 549 | 549 | |
| 550 | -function wpinv_remove_item( $item = 0, $force_delete = false ) { |
|
| 551 | - if ( empty( $item ) ) { |
|
| 550 | +function wpinv_remove_item($item = 0, $force_delete = false) { |
|
| 551 | + if (empty($item)) { |
|
| 552 | 552 | return NULL; |
| 553 | 553 | } |
| 554 | 554 | |
| 555 | - if ( is_int( $item ) ) { |
|
| 556 | - $item = new WPInv_Item( $item ); |
|
| 555 | + if (is_int($item)) { |
|
| 556 | + $item = new WPInv_Item($item); |
|
| 557 | 557 | } |
| 558 | 558 | |
| 559 | - if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) { |
|
| 559 | + if (!(is_object($item) && is_a($item, 'WPInv_Item'))) { |
|
| 560 | 560 | return NULL; |
| 561 | 561 | } |
| 562 | 562 | |
| 563 | - do_action( 'wpinv_pre_delete_item', $item ); |
|
| 563 | + do_action('wpinv_pre_delete_item', $item); |
|
| 564 | 564 | |
| 565 | - wp_delete_post( $item->ID, $force_delete ); |
|
| 565 | + wp_delete_post($item->ID, $force_delete); |
|
| 566 | 566 | |
| 567 | - do_action( 'wpinv_post_delete_item', $item ); |
|
| 567 | + do_action('wpinv_post_delete_item', $item); |
|
| 568 | 568 | } |
| 569 | 569 | |
| 570 | -function wpinv_can_delete_item( $post_id ) { |
|
| 571 | - $return = current_user_can( 'manage_options' ) ? true : false; |
|
| 570 | +function wpinv_can_delete_item($post_id) { |
|
| 571 | + $return = current_user_can('manage_options') ? true : false; |
|
| 572 | 572 | |
| 573 | - if ( $return && wpinv_item_in_use( $post_id ) ) { |
|
| 573 | + if ($return && wpinv_item_in_use($post_id)) { |
|
| 574 | 574 | $return = false; // Don't delete item already use in invoices. |
| 575 | 575 | } |
| 576 | 576 | |
| 577 | - return apply_filters( 'wpinv_can_delete_item', $return, $post_id ); |
|
| 577 | + return apply_filters('wpinv_can_delete_item', $return, $post_id); |
|
| 578 | 578 | } |
| 579 | 579 | |
| 580 | 580 | function wpinv_admin_action_delete() { |
| 581 | 581 | $screen = get_current_screen(); |
| 582 | 582 | |
| 583 | - if ( !empty( $screen->post_type ) && $screen->post_type == 'wpi_item' && !empty( $_REQUEST['post'] ) && is_array( $_REQUEST['post'] ) ) { |
|
| 583 | + if (!empty($screen->post_type) && $screen->post_type == 'wpi_item' && !empty($_REQUEST['post']) && is_array($_REQUEST['post'])) { |
|
| 584 | 584 | $post_ids = array(); |
| 585 | 585 | |
| 586 | - foreach ( $_REQUEST['post'] as $post_id ) { |
|
| 587 | - if ( !wpinv_can_delete_item( $post_id ) ) { |
|
| 586 | + foreach ($_REQUEST['post'] as $post_id) { |
|
| 587 | + if (!wpinv_can_delete_item($post_id)) { |
|
| 588 | 588 | continue; |
| 589 | 589 | } |
| 590 | 590 | |
@@ -594,80 +594,80 @@ discard block |
||
| 594 | 594 | $_REQUEST['post'] = $post_ids; |
| 595 | 595 | } |
| 596 | 596 | } |
| 597 | -add_action( 'admin_action_trash', 'wpinv_admin_action_delete', -10 ); |
|
| 598 | -add_action( 'admin_action_delete', 'wpinv_admin_action_delete', -10 ); |
|
| 597 | +add_action('admin_action_trash', 'wpinv_admin_action_delete', -10); |
|
| 598 | +add_action('admin_action_delete', 'wpinv_admin_action_delete', -10); |
|
| 599 | 599 | |
| 600 | -function wpinv_check_delete_item( $check, $post, $force_delete ) { |
|
| 601 | - if ( $post->post_type == 'wpi_item' ) { |
|
| 602 | - if ( $force_delete && !wpinv_can_delete_item( $post->ID ) ) { |
|
| 600 | +function wpinv_check_delete_item($check, $post, $force_delete) { |
|
| 601 | + if ($post->post_type == 'wpi_item') { |
|
| 602 | + if ($force_delete && !wpinv_can_delete_item($post->ID)) { |
|
| 603 | 603 | return true; |
| 604 | 604 | } |
| 605 | 605 | } |
| 606 | 606 | |
| 607 | 607 | return $check; |
| 608 | 608 | } |
| 609 | -add_filter( 'pre_delete_post', 'wpinv_check_delete_item', 10, 3 ); |
|
| 609 | +add_filter('pre_delete_post', 'wpinv_check_delete_item', 10, 3); |
|
| 610 | 610 | |
| 611 | -function wpinv_item_in_use( $item_id ) { |
|
| 611 | +function wpinv_item_in_use($item_id) { |
|
| 612 | 612 | global $wpdb, $wpi_items_in_use; |
| 613 | 613 | |
| 614 | - if ( !$item_id > 0 ) { |
|
| 614 | + if (!$item_id > 0) { |
|
| 615 | 615 | return false; |
| 616 | 616 | } |
| 617 | 617 | |
| 618 | - if ( !empty( $wpi_items_in_use ) ) { |
|
| 619 | - if ( isset( $wpi_items_in_use[$item_id] ) ) { |
|
| 618 | + if (!empty($wpi_items_in_use)) { |
|
| 619 | + if (isset($wpi_items_in_use[$item_id])) { |
|
| 620 | 620 | return $wpi_items_in_use[$item_id]; |
| 621 | 621 | } |
| 622 | 622 | } else { |
| 623 | 623 | $wpi_items_in_use = array(); |
| 624 | 624 | } |
| 625 | 625 | |
| 626 | - $statuses = array_keys( wpinv_get_invoice_statuses( true ) ); |
|
| 626 | + $statuses = array_keys(wpinv_get_invoice_statuses(true)); |
|
| 627 | 627 | |
| 628 | - $query = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode( "','", $statuses ) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )"; |
|
| 629 | - $in_use = $wpdb->get_var( $query ) > 0 ? true : false; |
|
| 628 | + $query = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode("','", $statuses) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )"; |
|
| 629 | + $in_use = $wpdb->get_var($query) > 0 ? true : false; |
|
| 630 | 630 | |
| 631 | 631 | $wpi_items_in_use[$item_id] = $in_use; |
| 632 | 632 | |
| 633 | 633 | return $in_use; |
| 634 | 634 | } |
| 635 | 635 | |
| 636 | -function wpinv_create_item( $args = array(), $wp_error = false, $force_update = false ) { |
|
| 636 | +function wpinv_create_item($args = array(), $wp_error = false, $force_update = false) { |
|
| 637 | 637 | // Set some defaults |
| 638 | 638 | $defaults = array( |
| 639 | - 'type' => 'custom', // Optional. Item type. Default 'custom'. |
|
| 640 | - 'title' => '', // Required. Item title. |
|
| 641 | - 'custom_id' => 0, // Optional. Any integer or non numeric id. Must be unique within item type. |
|
| 642 | - 'price' => '0.00', // Optional. Item price. Default '0.00'. |
|
| 643 | - 'status' => 'pending', // Optional. pending, publish |
|
| 644 | - 'custom_name' => '', // Optional. Plural sub title for item. |
|
| 645 | - 'custom_singular_name' => '', // Optional. Singular sub title for item. |
|
| 646 | - 'vat_rule' => 'digital', // Optional. digital => Digital item, physical => Physical item |
|
| 647 | - 'excerpt' => '', // Optional. Item short description |
|
| 639 | + 'type' => 'custom', // Optional. Item type. Default 'custom'. |
|
| 640 | + 'title' => '', // Required. Item title. |
|
| 641 | + 'custom_id' => 0, // Optional. Any integer or non numeric id. Must be unique within item type. |
|
| 642 | + 'price' => '0.00', // Optional. Item price. Default '0.00'. |
|
| 643 | + 'status' => 'pending', // Optional. pending, publish |
|
| 644 | + 'custom_name' => '', // Optional. Plural sub title for item. |
|
| 645 | + 'custom_singular_name' => '', // Optional. Singular sub title for item. |
|
| 646 | + 'vat_rule' => 'digital', // Optional. digital => Digital item, physical => Physical item |
|
| 647 | + 'excerpt' => '', // Optional. Item short description |
|
| 648 | 648 | /* Recurring item fields */ |
| 649 | - 'is_recurring' => 0, // Optional. 1 => Allow recurring or 0 => Don't allow recurring |
|
| 650 | - 'recurring_period' => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly |
|
| 651 | - 'recurring_interval' => 0, // Optional. Integer value between 1 - 90. |
|
| 652 | - 'recurring_limit' => 0, // Optional. Any integer number. 0 for recurring forever until cancelled. |
|
| 653 | - 'free_trial' => 0, // Optional. 1 => Allow free trial or 0 => Don't free trial |
|
| 654 | - 'trial_period' => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly |
|
| 655 | - 'trial_interval' => 0, // Optional. Any integer number. |
|
| 649 | + 'is_recurring' => 0, // Optional. 1 => Allow recurring or 0 => Don't allow recurring |
|
| 650 | + 'recurring_period' => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly |
|
| 651 | + 'recurring_interval' => 0, // Optional. Integer value between 1 - 90. |
|
| 652 | + 'recurring_limit' => 0, // Optional. Any integer number. 0 for recurring forever until cancelled. |
|
| 653 | + 'free_trial' => 0, // Optional. 1 => Allow free trial or 0 => Don't free trial |
|
| 654 | + 'trial_period' => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly |
|
| 655 | + 'trial_interval' => 0, // Optional. Any integer number. |
|
| 656 | 656 | ); |
| 657 | 657 | |
| 658 | - $data = wp_parse_args( $args, $defaults ); |
|
| 658 | + $data = wp_parse_args($args, $defaults); |
|
| 659 | 659 | |
| 660 | - if ( empty( $data['type'] ) ) { |
|
| 660 | + if (empty($data['type'])) { |
|
| 661 | 661 | $data['type'] = 'custom'; |
| 662 | 662 | } |
| 663 | 663 | |
| 664 | - if ( !empty( $data['custom_id'] ) ) { |
|
| 665 | - $item = wpinv_get_item_by( 'custom_id', $data['custom_id'], $data['type'] ); |
|
| 664 | + if (!empty($data['custom_id'])) { |
|
| 665 | + $item = wpinv_get_item_by('custom_id', $data['custom_id'], $data['type']); |
|
| 666 | 666 | } else { |
| 667 | 667 | $item = NULL; |
| 668 | 668 | } |
| 669 | 669 | |
| 670 | - if ( !$force_update && !empty( $item ) ) { |
|
| 670 | + if (!$force_update && !empty($item)) { |
|
| 671 | 671 | return $item; |
| 672 | 672 | } |
| 673 | 673 | |
@@ -676,18 +676,18 @@ discard block |
||
| 676 | 676 | $meta['custom_id'] = $data['custom_id']; |
| 677 | 677 | $meta['custom_singular_name'] = $data['custom_singular_name']; |
| 678 | 678 | $meta['custom_name'] = $data['custom_name']; |
| 679 | - $meta['price'] = wpinv_round_amount( $data['price'] ); |
|
| 679 | + $meta['price'] = wpinv_round_amount($data['price']); |
|
| 680 | 680 | $meta['vat_rule'] = $data['vat_rule']; |
| 681 | 681 | $meta['vat_class'] = '_standard'; |
| 682 | 682 | |
| 683 | - if ( !empty( $data['is_recurring'] ) ) { |
|
| 683 | + if (!empty($data['is_recurring'])) { |
|
| 684 | 684 | $meta['is_recurring'] = $data['is_recurring']; |
| 685 | 685 | $meta['recurring_period'] = $data['recurring_period']; |
| 686 | - $meta['recurring_interval'] = absint( $data['recurring_interval'] ); |
|
| 687 | - $meta['recurring_limit'] = absint( $data['recurring_limit'] ); |
|
| 686 | + $meta['recurring_interval'] = absint($data['recurring_interval']); |
|
| 687 | + $meta['recurring_limit'] = absint($data['recurring_limit']); |
|
| 688 | 688 | $meta['free_trial'] = $data['free_trial']; |
| 689 | 689 | $meta['trial_period'] = $data['trial_period']; |
| 690 | - $meta['trial_interval'] = absint( $data['trial_interval'] ); |
|
| 690 | + $meta['trial_interval'] = absint($data['trial_interval']); |
|
| 691 | 691 | } else { |
| 692 | 692 | $meta['is_recurring'] = 0; |
| 693 | 693 | $meta['recurring_period'] = ''; |
@@ -698,18 +698,18 @@ discard block |
||
| 698 | 698 | $meta['trial_interval'] = ''; |
| 699 | 699 | } |
| 700 | 700 | |
| 701 | - $post_data = array( |
|
| 701 | + $post_data = array( |
|
| 702 | 702 | 'post_title' => $data['title'], |
| 703 | 703 | 'post_excerpt' => $data['excerpt'], |
| 704 | 704 | 'post_status' => $data['status'], |
| 705 | 705 | 'meta' => $meta |
| 706 | 706 | ); |
| 707 | 707 | |
| 708 | - if ( !empty( $item ) ) { |
|
| 709 | - $item->update( $post_data, $wp_error ); |
|
| 708 | + if (!empty($item)) { |
|
| 709 | + $item->update($post_data, $wp_error); |
|
| 710 | 710 | } else { |
| 711 | 711 | $item = new WPInv_Item(); |
| 712 | - $item->create( $post_data, $wp_error ); |
|
| 712 | + $item->create($post_data, $wp_error); |
|
| 713 | 713 | } |
| 714 | 714 | |
| 715 | 715 | return $item; |
@@ -7,126 +7,126 @@ 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_item_quantities_enabled() { |
| 15 | - $ret = wpinv_get_option( 'item_quantities', true ); |
|
| 15 | + $ret = wpinv_get_option('item_quantities', true); |
|
| 16 | 16 | |
| 17 | - return (bool) apply_filters( 'wpinv_item_quantities_enabled', $ret ); |
|
| 17 | + return (bool)apply_filters('wpinv_item_quantities_enabled', $ret); |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | function wpinv_get_ip() { |
| 21 | 21 | $ip = '127.0.0.1'; |
| 22 | 22 | |
| 23 | - if ( !empty( $_SERVER['HTTP_CLIENT_IP'] ) ) { |
|
| 24 | - $ip = sanitize_text_field( $_SERVER['HTTP_CLIENT_IP'] ); |
|
| 25 | - } elseif ( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { |
|
| 26 | - $ip = sanitize_text_field( $_SERVER['HTTP_X_FORWARDED_FOR'] ); |
|
| 27 | - } elseif( !empty( $_SERVER['REMOTE_ADDR'] ) ) { |
|
| 28 | - $ip = sanitize_text_field( $_SERVER['REMOTE_ADDR'] ); |
|
| 23 | + if (!empty($_SERVER['HTTP_CLIENT_IP'])) { |
|
| 24 | + $ip = sanitize_text_field($_SERVER['HTTP_CLIENT_IP']); |
|
| 25 | + } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|
| 26 | + $ip = sanitize_text_field($_SERVER['HTTP_X_FORWARDED_FOR']); |
|
| 27 | + } elseif (!empty($_SERVER['REMOTE_ADDR'])) { |
|
| 28 | + $ip = sanitize_text_field($_SERVER['REMOTE_ADDR']); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - return apply_filters( 'wpinv_get_ip', $ip ); |
|
| 31 | + return apply_filters('wpinv_get_ip', $ip); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | function wpinv_get_user_agent() { |
| 35 | - if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
|
| 36 | - $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] ); |
|
| 35 | + if (!empty($_SERVER['HTTP_USER_AGENT'])) { |
|
| 36 | + $user_agent = sanitize_text_field($_SERVER['HTTP_USER_AGENT']); |
|
| 37 | 37 | } else { |
| 38 | 38 | $user_agent = ''; |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - return apply_filters( 'wpinv_get_user_agent', $user_agent ); |
|
| 41 | + return apply_filters('wpinv_get_user_agent', $user_agent); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | -function wpinv_sanitize_amount( $amount, $decimals = NULL ) { |
|
| 44 | +function wpinv_sanitize_amount($amount, $decimals = NULL) { |
|
| 45 | 45 | $is_negative = false; |
| 46 | 46 | $thousands_sep = wpinv_thousands_separator(); |
| 47 | 47 | $decimal_sep = wpinv_decimal_separator(); |
| 48 | - if ( $decimals === NULL ) { |
|
| 48 | + if ($decimals === NULL) { |
|
| 49 | 49 | $decimals = wpinv_decimals(); |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | // Sanitize the amount |
| 53 | - if ( $decimal_sep == ',' && false !== ( $found = strpos( $amount, $decimal_sep ) ) ) { |
|
| 54 | - if ( ( $thousands_sep == '.' || $thousands_sep == ' ' ) && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
| 55 | - $amount = str_replace( $thousands_sep, '', $amount ); |
|
| 56 | - } elseif( empty( $thousands_sep ) && false !== ( $found = strpos( $amount, '.' ) ) ) { |
|
| 57 | - $amount = str_replace( '.', '', $amount ); |
|
| 53 | + if ($decimal_sep == ',' && false !== ($found = strpos($amount, $decimal_sep))) { |
|
| 54 | + if (($thousands_sep == '.' || $thousands_sep == ' ') && false !== ($found = strpos($amount, $thousands_sep))) { |
|
| 55 | + $amount = str_replace($thousands_sep, '', $amount); |
|
| 56 | + } elseif (empty($thousands_sep) && false !== ($found = strpos($amount, '.'))) { |
|
| 57 | + $amount = str_replace('.', '', $amount); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - $amount = str_replace( $decimal_sep, '.', $amount ); |
|
| 61 | - } elseif( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
| 62 | - $amount = str_replace( $thousands_sep, '', $amount ); |
|
| 60 | + $amount = str_replace($decimal_sep, '.', $amount); |
|
| 61 | + } elseif ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) { |
|
| 62 | + $amount = str_replace($thousands_sep, '', $amount); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - if( $amount < 0 ) { |
|
| 65 | + if ($amount < 0) { |
|
| 66 | 66 | $is_negative = true; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - $amount = preg_replace( '/[^0-9\.]/', '', $amount ); |
|
| 69 | + $amount = preg_replace('/[^0-9\.]/', '', $amount); |
|
| 70 | 70 | |
| 71 | - $decimals = apply_filters( 'wpinv_sanitize_amount_decimals', absint( $decimals ), $amount ); |
|
| 72 | - $amount = number_format( (double) $amount, absint( $decimals ), '.', '' ); |
|
| 71 | + $decimals = apply_filters('wpinv_sanitize_amount_decimals', absint($decimals), $amount); |
|
| 72 | + $amount = number_format((double)$amount, absint($decimals), '.', ''); |
|
| 73 | 73 | |
| 74 | - if( $is_negative ) { |
|
| 74 | + if ($is_negative) { |
|
| 75 | 75 | $amount *= -1; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - return apply_filters( 'wpinv_sanitize_amount', $amount, $decimals ); |
|
| 78 | + return apply_filters('wpinv_sanitize_amount', $amount, $decimals); |
|
| 79 | 79 | } |
| 80 | -add_filter( 'wpinv_sanitize_amount_decimals', 'wpinv_currency_decimal_filter', 10, 1 ); |
|
| 80 | +add_filter('wpinv_sanitize_amount_decimals', 'wpinv_currency_decimal_filter', 10, 1); |
|
| 81 | 81 | |
| 82 | -function wpinv_round_amount( $amount, $decimals = NULL ) { |
|
| 83 | - if ( $decimals === NULL ) { |
|
| 82 | +function wpinv_round_amount($amount, $decimals = NULL) { |
|
| 83 | + if ($decimals === NULL) { |
|
| 84 | 84 | $decimals = wpinv_decimals(); |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - $amount = round( (double)$amount, wpinv_currency_decimal_filter( absint( $decimals ) ) ); |
|
| 87 | + $amount = round((double)$amount, wpinv_currency_decimal_filter(absint($decimals))); |
|
| 88 | 88 | |
| 89 | - return apply_filters( 'wpinv_round_amount', $amount, $decimals ); |
|
| 89 | + return apply_filters('wpinv_round_amount', $amount, $decimals); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | -function wpinv_get_invoice_statuses( $trashed = false ) { |
|
| 92 | +function wpinv_get_invoice_statuses($trashed = false) { |
|
| 93 | 93 | $invoice_statuses = array( |
| 94 | - 'pending' => __( 'Pending Payment', 'invoicing' ), |
|
| 95 | - 'publish' => __( 'Paid', 'invoicing' ), |
|
| 96 | - 'wpi-processing' => __( 'Processing', 'invoicing' ), |
|
| 97 | - 'wpi-onhold' => __( 'On Hold', 'invoicing' ), |
|
| 98 | - 'wpi-refunded' => __( 'Refunded', 'invoicing' ), |
|
| 99 | - 'wpi-cancelled' => __( 'Cancelled', 'invoicing' ), |
|
| 100 | - 'wpi-failed' => __( 'Failed', 'invoicing' ), |
|
| 101 | - 'wpi-renewal' => __( 'Renewal Payment', 'invoicing' ) |
|
| 94 | + 'pending' => __('Pending Payment', 'invoicing'), |
|
| 95 | + 'publish' => __('Paid', 'invoicing'), |
|
| 96 | + 'wpi-processing' => __('Processing', 'invoicing'), |
|
| 97 | + 'wpi-onhold' => __('On Hold', 'invoicing'), |
|
| 98 | + 'wpi-refunded' => __('Refunded', 'invoicing'), |
|
| 99 | + 'wpi-cancelled' => __('Cancelled', 'invoicing'), |
|
| 100 | + 'wpi-failed' => __('Failed', 'invoicing'), |
|
| 101 | + 'wpi-renewal' => __('Renewal Payment', 'invoicing') |
|
| 102 | 102 | ); |
| 103 | 103 | |
| 104 | - if ( $trashed ) { |
|
| 105 | - $invoice_statuses['trash'] = __( 'Trash', 'invoicing' ); |
|
| 104 | + if ($trashed) { |
|
| 105 | + $invoice_statuses['trash'] = __('Trash', 'invoicing'); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - return apply_filters( 'wpinv_statuses', $invoice_statuses ); |
|
| 108 | + return apply_filters('wpinv_statuses', $invoice_statuses); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | -function wpinv_status_nicename( $status ) { |
|
| 111 | +function wpinv_status_nicename($status) { |
|
| 112 | 112 | $statuses = wpinv_get_invoice_statuses(); |
| 113 | - $status = isset( $statuses[$status] ) ? $statuses[$status] : __( $status, 'invoicing' ); |
|
| 113 | + $status = isset($statuses[$status]) ? $statuses[$status] : __($status, 'invoicing'); |
|
| 114 | 114 | |
| 115 | 115 | return $status; |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | function wpinv_get_currency() { |
| 119 | - $currency = wpinv_get_option( 'currency', 'USD' ); |
|
| 119 | + $currency = wpinv_get_option('currency', 'USD'); |
|
| 120 | 120 | |
| 121 | - return apply_filters( 'wpinv_currency', $currency ); |
|
| 121 | + return apply_filters('wpinv_currency', $currency); |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | -function wpinv_currency_symbol( $currency = '' ) { |
|
| 125 | - if ( empty( $currency ) ) { |
|
| 124 | +function wpinv_currency_symbol($currency = '') { |
|
| 125 | + if (empty($currency)) { |
|
| 126 | 126 | $currency = wpinv_get_currency(); |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | - $symbols = apply_filters( 'wpinv_currency_symbols', array( |
|
| 129 | + $symbols = apply_filters('wpinv_currency_symbols', array( |
|
| 130 | 130 | 'AED' => 'د.إ', |
| 131 | 131 | 'ARS' => '$', |
| 132 | 132 | 'AUD' => '$', |
@@ -178,78 +178,78 @@ discard block |
||
| 178 | 178 | 'USD' => '$', |
| 179 | 179 | 'VND' => '₫', |
| 180 | 180 | 'ZAR' => 'R', |
| 181 | - ) ); |
|
| 181 | + )); |
|
| 182 | 182 | |
| 183 | - $currency_symbol = isset( $symbols[$currency] ) ? $symbols[$currency] : '$'; |
|
| 183 | + $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : '$'; |
|
| 184 | 184 | |
| 185 | - return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency ); |
|
| 185 | + return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | function wpinv_currency_position() { |
| 189 | - $position = wpinv_get_option( 'currency_position', 'left' ); |
|
| 189 | + $position = wpinv_get_option('currency_position', 'left'); |
|
| 190 | 190 | |
| 191 | - return apply_filters( 'wpinv_currency_position', $position ); |
|
| 191 | + return apply_filters('wpinv_currency_position', $position); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | function wpinv_thousands_separator() { |
| 195 | - $thousand_sep = wpinv_get_option( 'thousands_separator', ',' ); |
|
| 195 | + $thousand_sep = wpinv_get_option('thousands_separator', ','); |
|
| 196 | 196 | |
| 197 | - return apply_filters( 'wpinv_thousands_separator', $thousand_sep ); |
|
| 197 | + return apply_filters('wpinv_thousands_separator', $thousand_sep); |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | function wpinv_decimal_separator() { |
| 201 | - $decimal_sep = wpinv_get_option( 'decimal_separator', '.' ); |
|
| 201 | + $decimal_sep = wpinv_get_option('decimal_separator', '.'); |
|
| 202 | 202 | |
| 203 | - return apply_filters( 'wpinv_decimal_separator', $decimal_sep ); |
|
| 203 | + return apply_filters('wpinv_decimal_separator', $decimal_sep); |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | function wpinv_decimals() { |
| 207 | - $decimals = apply_filters( 'wpinv_decimals', wpinv_get_option( 'decimals', 2 ) ); |
|
| 207 | + $decimals = apply_filters('wpinv_decimals', wpinv_get_option('decimals', 2)); |
|
| 208 | 208 | |
| 209 | - return absint( $decimals ); |
|
| 209 | + return absint($decimals); |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | function wpinv_get_currencies() { |
| 213 | 213 | $currencies = array( |
| 214 | - 'USD' => __( 'US Dollars ($)', 'invoicing' ), |
|
| 215 | - 'EUR' => __( 'Euros (€)', 'invoicing' ), |
|
| 216 | - 'GBP' => __( 'Pounds Sterling (£)', 'invoicing' ), |
|
| 217 | - 'AUD' => __( 'Australian Dollars ($)', 'invoicing' ), |
|
| 218 | - 'BRL' => __( 'Brazilian Real (R$)', 'invoicing' ), |
|
| 219 | - 'CAD' => __( 'Canadian Dollars ($)', 'invoicing' ), |
|
| 220 | - 'CLP' => __( 'Chilean Peso ($)', 'invoicing' ), |
|
| 221 | - 'CNY' => __( 'Chinese Yuan (¥)', 'invoicing' ), |
|
| 222 | - 'CZK' => __( 'Czech Koruna (Kč)', 'invoicing' ), |
|
| 223 | - 'DKK' => __( 'Danish Krone (DKK)', 'invoicing' ), |
|
| 224 | - 'HKD' => __( 'Hong Kong Dollar ($)', 'invoicing' ), |
|
| 225 | - 'HUF' => __( 'Hungarian Forint (Ft)', 'invoicing' ), |
|
| 226 | - 'INR' => __( 'Indian Rupee (₹)', 'invoicing' ), |
|
| 227 | - 'ILS' => __( 'Israeli Shekel (₪)', 'invoicing' ), |
|
| 228 | - 'JPY' => __( 'Japanese Yen (¥)', 'invoicing' ), |
|
| 229 | - 'MYR' => __( 'Malaysian Ringgit (RM)', 'invoicing' ), |
|
| 230 | - 'MXN' => __( 'Mexican Peso ($)', 'invoicing' ), |
|
| 231 | - 'NZD' => __( 'New Zealand Dollar ($)', 'invoicing' ), |
|
| 232 | - 'NOK' => __( 'Norwegian Krone (kr)', 'invoicing' ), |
|
| 233 | - 'PHP' => __( 'Philippine Peso (₱)', 'invoicing' ), |
|
| 234 | - 'PLN' => __( 'Polish Zloty (zł)', 'invoicing' ), |
|
| 235 | - 'SGD' => __( 'Singapore Dollar ($)', 'invoicing' ), |
|
| 236 | - 'SEK' => __( 'Swedish Krona (kr)', 'invoicing' ), |
|
| 237 | - 'CHF' => __( 'Swiss Franc (CHF)', 'invoicing' ), |
|
| 238 | - 'TWD' => __( 'Taiwan New Dollar (NT$)', 'invoicing' ), |
|
| 239 | - 'THB' => __( 'Thai Baht (฿)', 'invoicing' ), |
|
| 240 | - 'TRY' => __( 'Turkish Lira (₺)', 'invoicing' ), |
|
| 241 | - 'RIAL' => __( 'Iranian Rial (﷼)', 'invoicing' ), |
|
| 242 | - 'RUB' => __( 'Russian Ruble (₽)', 'invoicing' ), |
|
| 243 | - 'ZAR' => __( 'South African Rand (R)', 'invoicing' ) |
|
| 214 | + 'USD' => __('US Dollars ($)', 'invoicing'), |
|
| 215 | + 'EUR' => __('Euros (€)', 'invoicing'), |
|
| 216 | + 'GBP' => __('Pounds Sterling (£)', 'invoicing'), |
|
| 217 | + 'AUD' => __('Australian Dollars ($)', 'invoicing'), |
|
| 218 | + 'BRL' => __('Brazilian Real (R$)', 'invoicing'), |
|
| 219 | + 'CAD' => __('Canadian Dollars ($)', 'invoicing'), |
|
| 220 | + 'CLP' => __('Chilean Peso ($)', 'invoicing'), |
|
| 221 | + 'CNY' => __('Chinese Yuan (¥)', 'invoicing'), |
|
| 222 | + 'CZK' => __('Czech Koruna (Kč)', 'invoicing'), |
|
| 223 | + 'DKK' => __('Danish Krone (DKK)', 'invoicing'), |
|
| 224 | + 'HKD' => __('Hong Kong Dollar ($)', 'invoicing'), |
|
| 225 | + 'HUF' => __('Hungarian Forint (Ft)', 'invoicing'), |
|
| 226 | + 'INR' => __('Indian Rupee (₹)', 'invoicing'), |
|
| 227 | + 'ILS' => __('Israeli Shekel (₪)', 'invoicing'), |
|
| 228 | + 'JPY' => __('Japanese Yen (¥)', 'invoicing'), |
|
| 229 | + 'MYR' => __('Malaysian Ringgit (RM)', 'invoicing'), |
|
| 230 | + 'MXN' => __('Mexican Peso ($)', 'invoicing'), |
|
| 231 | + 'NZD' => __('New Zealand Dollar ($)', 'invoicing'), |
|
| 232 | + 'NOK' => __('Norwegian Krone (kr)', 'invoicing'), |
|
| 233 | + 'PHP' => __('Philippine Peso (₱)', 'invoicing'), |
|
| 234 | + 'PLN' => __('Polish Zloty (zł)', 'invoicing'), |
|
| 235 | + 'SGD' => __('Singapore Dollar ($)', 'invoicing'), |
|
| 236 | + 'SEK' => __('Swedish Krona (kr)', 'invoicing'), |
|
| 237 | + 'CHF' => __('Swiss Franc (CHF)', 'invoicing'), |
|
| 238 | + 'TWD' => __('Taiwan New Dollar (NT$)', 'invoicing'), |
|
| 239 | + 'THB' => __('Thai Baht (฿)', 'invoicing'), |
|
| 240 | + 'TRY' => __('Turkish Lira (₺)', 'invoicing'), |
|
| 241 | + 'RIAL' => __('Iranian Rial (﷼)', 'invoicing'), |
|
| 242 | + 'RUB' => __('Russian Ruble (₽)', 'invoicing'), |
|
| 243 | + 'ZAR' => __('South African Rand (R)', 'invoicing') |
|
| 244 | 244 | ); |
| 245 | 245 | |
| 246 | - asort( $currencies ); |
|
| 246 | + asort($currencies); |
|
| 247 | 247 | |
| 248 | - return apply_filters( 'wpinv_currencies', $currencies ); |
|
| 248 | + return apply_filters('wpinv_currencies', $currencies); |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | -function wpinv_price( $amount = '', $currency = '' ) { |
|
| 252 | - if( empty( $currency ) ) { |
|
| 251 | +function wpinv_price($amount = '', $currency = '') { |
|
| 252 | + if (empty($currency)) { |
|
| 253 | 253 | $currency = wpinv_get_currency(); |
| 254 | 254 | } |
| 255 | 255 | |
@@ -257,14 +257,14 @@ discard block |
||
| 257 | 257 | |
| 258 | 258 | $negative = $amount < 0; |
| 259 | 259 | |
| 260 | - if ( $negative ) { |
|
| 261 | - $amount = substr( $amount, 1 ); |
|
| 260 | + if ($negative) { |
|
| 261 | + $amount = substr($amount, 1); |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | - $symbol = wpinv_currency_symbol( $currency ); |
|
| 264 | + $symbol = wpinv_currency_symbol($currency); |
|
| 265 | 265 | |
| 266 | - if ( $position == 'left' || $position == 'left_space' ) { |
|
| 267 | - switch ( $currency ) { |
|
| 266 | + if ($position == 'left' || $position == 'left_space') { |
|
| 267 | + switch ($currency) { |
|
| 268 | 268 | case "GBP" : |
| 269 | 269 | case "BRL" : |
| 270 | 270 | case "EUR" : |
@@ -276,15 +276,15 @@ discard block |
||
| 276 | 276 | case "NZD" : |
| 277 | 277 | case "SGD" : |
| 278 | 278 | case "JPY" : |
| 279 | - $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount; |
|
| 279 | + $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount; |
|
| 280 | 280 | break; |
| 281 | 281 | default : |
| 282 | 282 | //$price = $currency . ' ' . $amount; |
| 283 | - $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount; |
|
| 283 | + $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount; |
|
| 284 | 284 | break; |
| 285 | 285 | } |
| 286 | 286 | } else { |
| 287 | - switch ( $currency ) { |
|
| 287 | + switch ($currency) { |
|
| 288 | 288 | case "GBP" : |
| 289 | 289 | case "BRL" : |
| 290 | 290 | case "EUR" : |
@@ -295,83 +295,83 @@ discard block |
||
| 295 | 295 | case "MXN" : |
| 296 | 296 | case "SGD" : |
| 297 | 297 | case "JPY" : |
| 298 | - $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol; |
|
| 298 | + $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol; |
|
| 299 | 299 | break; |
| 300 | 300 | default : |
| 301 | 301 | //$price = $amount . ' ' . $currency; |
| 302 | - $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol; |
|
| 302 | + $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol; |
|
| 303 | 303 | break; |
| 304 | 304 | } |
| 305 | 305 | } |
| 306 | 306 | |
| 307 | - if ( $negative ) { |
|
| 307 | + if ($negative) { |
|
| 308 | 308 | $price = '-' . $price; |
| 309 | 309 | } |
| 310 | 310 | |
| 311 | - $price = apply_filters( 'wpinv_' . strtolower( $currency ) . '_currency_filter_' . $position, $price, $currency, $amount ); |
|
| 311 | + $price = apply_filters('wpinv_' . strtolower($currency) . '_currency_filter_' . $position, $price, $currency, $amount); |
|
| 312 | 312 | |
| 313 | 313 | return $price; |
| 314 | 314 | } |
| 315 | 315 | |
| 316 | -function wpinv_format_amount( $amount, $decimals = NULL, $calculate = false ) { |
|
| 316 | +function wpinv_format_amount($amount, $decimals = NULL, $calculate = false) { |
|
| 317 | 317 | $thousands_sep = wpinv_thousands_separator(); |
| 318 | 318 | $decimal_sep = wpinv_decimal_separator(); |
| 319 | 319 | |
| 320 | - if ( $decimals === NULL ) { |
|
| 320 | + if ($decimals === NULL) { |
|
| 321 | 321 | $decimals = wpinv_decimals(); |
| 322 | 322 | } |
| 323 | 323 | |
| 324 | - if ( $decimal_sep == ',' && false !== ( $sep_found = strpos( $amount, $decimal_sep ) ) ) { |
|
| 325 | - $whole = substr( $amount, 0, $sep_found ); |
|
| 326 | - $part = substr( $amount, $sep_found + 1, ( strlen( $amount ) - 1 ) ); |
|
| 324 | + if ($decimal_sep == ',' && false !== ($sep_found = strpos($amount, $decimal_sep))) { |
|
| 325 | + $whole = substr($amount, 0, $sep_found); |
|
| 326 | + $part = substr($amount, $sep_found + 1, (strlen($amount) - 1)); |
|
| 327 | 327 | $amount = $whole . '.' . $part; |
| 328 | 328 | } |
| 329 | 329 | |
| 330 | - if ( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
| 331 | - $amount = str_replace( ',', '', $amount ); |
|
| 330 | + if ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) { |
|
| 331 | + $amount = str_replace(',', '', $amount); |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | - if ( $thousands_sep == ' ' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
| 335 | - $amount = str_replace( ' ', '', $amount ); |
|
| 334 | + if ($thousands_sep == ' ' && false !== ($found = strpos($amount, $thousands_sep))) { |
|
| 335 | + $amount = str_replace(' ', '', $amount); |
|
| 336 | 336 | } |
| 337 | 337 | |
| 338 | - if ( empty( $amount ) ) { |
|
| 338 | + if (empty($amount)) { |
|
| 339 | 339 | $amount = 0; |
| 340 | 340 | } |
| 341 | 341 | |
| 342 | - $decimals = apply_filters( 'wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate ); |
|
| 343 | - $formatted = number_format( (float)$amount, $decimals, $decimal_sep, $thousands_sep ); |
|
| 342 | + $decimals = apply_filters('wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate); |
|
| 343 | + $formatted = number_format((float)$amount, $decimals, $decimal_sep, $thousands_sep); |
|
| 344 | 344 | |
| 345 | - if ( $calculate ) { |
|
| 346 | - if ( $thousands_sep === "," ) { |
|
| 347 | - $formatted = str_replace( ",", "", $formatted ); |
|
| 345 | + if ($calculate) { |
|
| 346 | + if ($thousands_sep === ",") { |
|
| 347 | + $formatted = str_replace(",", "", $formatted); |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | - if ( $decimal_sep === "," ) { |
|
| 351 | - $formatted = str_replace( ",", ".", $formatted ); |
|
| 350 | + if ($decimal_sep === ",") { |
|
| 351 | + $formatted = str_replace(",", ".", $formatted); |
|
| 352 | 352 | } |
| 353 | 353 | } |
| 354 | 354 | |
| 355 | - return apply_filters( 'wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate ); |
|
| 355 | + return apply_filters('wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate); |
|
| 356 | 356 | } |
| 357 | -add_filter( 'wpinv_amount_format_decimals', 'wpinv_currency_decimal_filter', 10, 1 ); |
|
| 357 | +add_filter('wpinv_amount_format_decimals', 'wpinv_currency_decimal_filter', 10, 1); |
|
| 358 | 358 | |
| 359 | -function wpinv_sanitize_key( $key ) { |
|
| 359 | +function wpinv_sanitize_key($key) { |
|
| 360 | 360 | $raw_key = $key; |
| 361 | - $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key ); |
|
| 361 | + $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key); |
|
| 362 | 362 | |
| 363 | - return apply_filters( 'wpinv_sanitize_key', $key, $raw_key ); |
|
| 363 | + return apply_filters('wpinv_sanitize_key', $key, $raw_key); |
|
| 364 | 364 | } |
| 365 | 365 | |
| 366 | -function wpinv_get_file_extension( $str ) { |
|
| 367 | - $parts = explode( '.', $str ); |
|
| 368 | - return end( $parts ); |
|
| 366 | +function wpinv_get_file_extension($str) { |
|
| 367 | + $parts = explode('.', $str); |
|
| 368 | + return end($parts); |
|
| 369 | 369 | } |
| 370 | 370 | |
| 371 | -function wpinv_string_is_image_url( $str ) { |
|
| 372 | - $ext = wpinv_get_file_extension( $str ); |
|
| 371 | +function wpinv_string_is_image_url($str) { |
|
| 372 | + $ext = wpinv_get_file_extension($str); |
|
| 373 | 373 | |
| 374 | - switch ( strtolower( $ext ) ) { |
|
| 374 | + switch (strtolower($ext)) { |
|
| 375 | 375 | case 'jpeg'; |
| 376 | 376 | case 'jpg'; |
| 377 | 377 | $return = true; |
@@ -387,32 +387,32 @@ discard block |
||
| 387 | 387 | break; |
| 388 | 388 | } |
| 389 | 389 | |
| 390 | - return (bool)apply_filters( 'wpinv_string_is_image', $return, $str ); |
|
| 390 | + return (bool)apply_filters('wpinv_string_is_image', $return, $str); |
|
| 391 | 391 | } |
| 392 | 392 | |
| 393 | -function wpinv_error_log( $log, $title = '', $file = '', $line = '', $exit = false ) { |
|
| 394 | - $should_log = apply_filters( 'wpinv_log_errors', WP_DEBUG ); |
|
| 393 | +function wpinv_error_log($log, $title = '', $file = '', $line = '', $exit = false) { |
|
| 394 | + $should_log = apply_filters('wpinv_log_errors', WP_DEBUG); |
|
| 395 | 395 | |
| 396 | - if ( true === $should_log ) { |
|
| 396 | + if (true === $should_log) { |
|
| 397 | 397 | $label = ''; |
| 398 | - if ( $file && $file !== '' ) { |
|
| 399 | - $label .= basename( $file ) . ( $line ? '(' . $line . ')' : '' ); |
|
| 398 | + if ($file && $file !== '') { |
|
| 399 | + $label .= basename($file) . ($line ? '(' . $line . ')' : ''); |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | - if ( $title && $title !== '' ) { |
|
| 402 | + if ($title && $title !== '') { |
|
| 403 | 403 | $label = $label !== '' ? $label . ' ' : ''; |
| 404 | 404 | $label .= $title . ' '; |
| 405 | 405 | } |
| 406 | 406 | |
| 407 | - $label = $label !== '' ? trim( $label ) . ' : ' : ''; |
|
| 407 | + $label = $label !== '' ? trim($label) . ' : ' : ''; |
|
| 408 | 408 | |
| 409 | - if ( is_array( $log ) || is_object( $log ) ) { |
|
| 410 | - error_log( $label . print_r( $log, true ) ); |
|
| 409 | + if (is_array($log) || is_object($log)) { |
|
| 410 | + error_log($label . print_r($log, true)); |
|
| 411 | 411 | } else { |
| 412 | - error_log( $label . $log ); |
|
| 412 | + error_log($label . $log); |
|
| 413 | 413 | } |
| 414 | 414 | |
| 415 | - if ( $exit ) { |
|
| 415 | + if ($exit) { |
|
| 416 | 416 | exit; |
| 417 | 417 | } |
| 418 | 418 | } |
@@ -420,65 +420,65 @@ discard block |
||
| 420 | 420 | |
| 421 | 421 | function wpinv_is_ajax_disabled() { |
| 422 | 422 | $retval = false; |
| 423 | - return apply_filters( 'wpinv_is_ajax_disabled', $retval ); |
|
| 423 | + return apply_filters('wpinv_is_ajax_disabled', $retval); |
|
| 424 | 424 | } |
| 425 | 425 | |
| 426 | -function wpinv_get_current_page_url( $nocache = false ) { |
|
| 426 | +function wpinv_get_current_page_url($nocache = false) { |
|
| 427 | 427 | global $wp; |
| 428 | 428 | |
| 429 | - if ( get_option( 'permalink_structure' ) ) { |
|
| 430 | - $base = trailingslashit( home_url( $wp->request ) ); |
|
| 429 | + if (get_option('permalink_structure')) { |
|
| 430 | + $base = trailingslashit(home_url($wp->request)); |
|
| 431 | 431 | } else { |
| 432 | - $base = add_query_arg( $wp->query_string, '', trailingslashit( home_url( $wp->request ) ) ); |
|
| 433 | - $base = remove_query_arg( array( 'post_type', 'name' ), $base ); |
|
| 432 | + $base = add_query_arg($wp->query_string, '', trailingslashit(home_url($wp->request))); |
|
| 433 | + $base = remove_query_arg(array('post_type', 'name'), $base); |
|
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | $scheme = is_ssl() ? 'https' : 'http'; |
| 437 | - $uri = set_url_scheme( $base, $scheme ); |
|
| 437 | + $uri = set_url_scheme($base, $scheme); |
|
| 438 | 438 | |
| 439 | - if ( is_front_page() ) { |
|
| 440 | - $uri = home_url( '/' ); |
|
| 441 | - } elseif ( wpinv_is_checkout( array(), false ) ) { |
|
| 439 | + if (is_front_page()) { |
|
| 440 | + $uri = home_url('/'); |
|
| 441 | + } elseif (wpinv_is_checkout(array(), false)) { |
|
| 442 | 442 | $uri = wpinv_get_checkout_uri(); |
| 443 | 443 | } |
| 444 | 444 | |
| 445 | - $uri = apply_filters( 'wpinv_get_current_page_url', $uri ); |
|
| 445 | + $uri = apply_filters('wpinv_get_current_page_url', $uri); |
|
| 446 | 446 | |
| 447 | - if ( $nocache ) { |
|
| 448 | - $uri = wpinv_add_cache_busting( $uri ); |
|
| 447 | + if ($nocache) { |
|
| 448 | + $uri = wpinv_add_cache_busting($uri); |
|
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | return $uri; |
| 452 | 452 | } |
| 453 | 453 | |
| 454 | 454 | function wpinv_get_php_arg_separator_output() { |
| 455 | - return ini_get( 'arg_separator.output' ); |
|
| 455 | + return ini_get('arg_separator.output'); |
|
| 456 | 456 | } |
| 457 | 457 | |
| 458 | -function wpinv_rgb_from_hex( $color ) { |
|
| 459 | - $color = str_replace( '#', '', $color ); |
|
| 458 | +function wpinv_rgb_from_hex($color) { |
|
| 459 | + $color = str_replace('#', '', $color); |
|
| 460 | 460 | // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF" |
| 461 | - $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color ); |
|
| 461 | + $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color); |
|
| 462 | 462 | |
| 463 | 463 | $rgb = array(); |
| 464 | - $rgb['R'] = hexdec( $color{0}.$color{1} ); |
|
| 465 | - $rgb['G'] = hexdec( $color{2}.$color{3} ); |
|
| 466 | - $rgb['B'] = hexdec( $color{4}.$color{5} ); |
|
| 464 | + $rgb['R'] = hexdec($color{0} . $color{1} ); |
|
| 465 | + $rgb['G'] = hexdec($color{2} . $color{3} ); |
|
| 466 | + $rgb['B'] = hexdec($color{4} . $color{5} ); |
|
| 467 | 467 | |
| 468 | 468 | return $rgb; |
| 469 | 469 | } |
| 470 | 470 | |
| 471 | -function wpinv_hex_darker( $color, $factor = 30 ) { |
|
| 472 | - $base = wpinv_rgb_from_hex( $color ); |
|
| 471 | +function wpinv_hex_darker($color, $factor = 30) { |
|
| 472 | + $base = wpinv_rgb_from_hex($color); |
|
| 473 | 473 | $color = '#'; |
| 474 | 474 | |
| 475 | - foreach ( $base as $k => $v ) { |
|
| 475 | + foreach ($base as $k => $v) { |
|
| 476 | 476 | $amount = $v / 100; |
| 477 | - $amount = round( $amount * $factor ); |
|
| 477 | + $amount = round($amount * $factor); |
|
| 478 | 478 | $new_decimal = $v - $amount; |
| 479 | 479 | |
| 480 | - $new_hex_component = dechex( $new_decimal ); |
|
| 481 | - if ( strlen( $new_hex_component ) < 2 ) { |
|
| 480 | + $new_hex_component = dechex($new_decimal); |
|
| 481 | + if (strlen($new_hex_component) < 2) { |
|
| 482 | 482 | $new_hex_component = "0" . $new_hex_component; |
| 483 | 483 | } |
| 484 | 484 | $color .= $new_hex_component; |
@@ -487,18 +487,18 @@ discard block |
||
| 487 | 487 | return $color; |
| 488 | 488 | } |
| 489 | 489 | |
| 490 | -function wpinv_hex_lighter( $color, $factor = 30 ) { |
|
| 491 | - $base = wpinv_rgb_from_hex( $color ); |
|
| 490 | +function wpinv_hex_lighter($color, $factor = 30) { |
|
| 491 | + $base = wpinv_rgb_from_hex($color); |
|
| 492 | 492 | $color = '#'; |
| 493 | 493 | |
| 494 | - foreach ( $base as $k => $v ) { |
|
| 494 | + foreach ($base as $k => $v) { |
|
| 495 | 495 | $amount = 255 - $v; |
| 496 | 496 | $amount = $amount / 100; |
| 497 | - $amount = round( $amount * $factor ); |
|
| 497 | + $amount = round($amount * $factor); |
|
| 498 | 498 | $new_decimal = $v + $amount; |
| 499 | 499 | |
| 500 | - $new_hex_component = dechex( $new_decimal ); |
|
| 501 | - if ( strlen( $new_hex_component ) < 2 ) { |
|
| 500 | + $new_hex_component = dechex($new_decimal); |
|
| 501 | + if (strlen($new_hex_component) < 2) { |
|
| 502 | 502 | $new_hex_component = "0" . $new_hex_component; |
| 503 | 503 | } |
| 504 | 504 | $color .= $new_hex_component; |
@@ -507,22 +507,22 @@ discard block |
||
| 507 | 507 | return $color; |
| 508 | 508 | } |
| 509 | 509 | |
| 510 | -function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) { |
|
| 511 | - $hex = str_replace( '#', '', $color ); |
|
| 510 | +function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') { |
|
| 511 | + $hex = str_replace('#', '', $color); |
|
| 512 | 512 | |
| 513 | - $c_r = hexdec( substr( $hex, 0, 2 ) ); |
|
| 514 | - $c_g = hexdec( substr( $hex, 2, 2 ) ); |
|
| 515 | - $c_b = hexdec( substr( $hex, 4, 2 ) ); |
|
| 513 | + $c_r = hexdec(substr($hex, 0, 2)); |
|
| 514 | + $c_g = hexdec(substr($hex, 2, 2)); |
|
| 515 | + $c_b = hexdec(substr($hex, 4, 2)); |
|
| 516 | 516 | |
| 517 | - $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000; |
|
| 517 | + $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000; |
|
| 518 | 518 | |
| 519 | 519 | return $brightness > 155 ? $dark : $light; |
| 520 | 520 | } |
| 521 | 521 | |
| 522 | -function wpinv_format_hex( $hex ) { |
|
| 523 | - $hex = trim( str_replace( '#', '', $hex ) ); |
|
| 522 | +function wpinv_format_hex($hex) { |
|
| 523 | + $hex = trim(str_replace('#', '', $hex)); |
|
| 524 | 524 | |
| 525 | - if ( strlen( $hex ) == 3 ) { |
|
| 525 | + if (strlen($hex) == 3) { |
|
| 526 | 526 | $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2]; |
| 527 | 527 | } |
| 528 | 528 | |
@@ -542,12 +542,12 @@ discard block |
||
| 542 | 542 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 543 | 543 | * @return string |
| 544 | 544 | */ |
| 545 | -function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) { |
|
| 546 | - if ( function_exists( 'mb_strimwidth' ) ) { |
|
| 547 | - return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding ); |
|
| 545 | +function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') { |
|
| 546 | + if (function_exists('mb_strimwidth')) { |
|
| 547 | + return mb_strimwidth($str, $start, $width, $trimmaker, $encoding); |
|
| 548 | 548 | } |
| 549 | 549 | |
| 550 | - return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker; |
|
| 550 | + return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker; |
|
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | /** |
@@ -559,28 +559,28 @@ discard block |
||
| 559 | 559 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 560 | 560 | * @return int Returns the number of characters in string. |
| 561 | 561 | */ |
| 562 | -function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) { |
|
| 563 | - if ( function_exists( 'mb_strlen' ) ) { |
|
| 564 | - return mb_strlen( $str, $encoding ); |
|
| 562 | +function wpinv_utf8_strlen($str, $encoding = 'UTF-8') { |
|
| 563 | + if (function_exists('mb_strlen')) { |
|
| 564 | + return mb_strlen($str, $encoding); |
|
| 565 | 565 | } |
| 566 | 566 | |
| 567 | - return strlen( $str ); |
|
| 567 | + return strlen($str); |
|
| 568 | 568 | } |
| 569 | 569 | |
| 570 | -function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) { |
|
| 571 | - if ( function_exists( 'mb_strtolower' ) ) { |
|
| 572 | - return mb_strtolower( $str, $encoding ); |
|
| 570 | +function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') { |
|
| 571 | + if (function_exists('mb_strtolower')) { |
|
| 572 | + return mb_strtolower($str, $encoding); |
|
| 573 | 573 | } |
| 574 | 574 | |
| 575 | - return strtolower( $str ); |
|
| 575 | + return strtolower($str); |
|
| 576 | 576 | } |
| 577 | 577 | |
| 578 | -function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) { |
|
| 579 | - if ( function_exists( 'mb_strtoupper' ) ) { |
|
| 580 | - return mb_strtoupper( $str, $encoding ); |
|
| 578 | +function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') { |
|
| 579 | + if (function_exists('mb_strtoupper')) { |
|
| 580 | + return mb_strtoupper($str, $encoding); |
|
| 581 | 581 | } |
| 582 | 582 | |
| 583 | - return strtoupper( $str ); |
|
| 583 | + return strtoupper($str); |
|
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | /** |
@@ -594,12 +594,12 @@ discard block |
||
| 594 | 594 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 595 | 595 | * @return int Returns the position of the first occurrence of search in the string. |
| 596 | 596 | */ |
| 597 | -function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) { |
|
| 598 | - if ( function_exists( 'mb_strpos' ) ) { |
|
| 599 | - return mb_strpos( $str, $find, $offset, $encoding ); |
|
| 597 | +function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') { |
|
| 598 | + if (function_exists('mb_strpos')) { |
|
| 599 | + return mb_strpos($str, $find, $offset, $encoding); |
|
| 600 | 600 | } |
| 601 | 601 | |
| 602 | - return strpos( $str, $find, $offset ); |
|
| 602 | + return strpos($str, $find, $offset); |
|
| 603 | 603 | } |
| 604 | 604 | |
| 605 | 605 | /** |
@@ -613,12 +613,12 @@ discard block |
||
| 613 | 613 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 614 | 614 | * @return int Returns the position of the last occurrence of search. |
| 615 | 615 | */ |
| 616 | -function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) { |
|
| 617 | - if ( function_exists( 'mb_strrpos' ) ) { |
|
| 618 | - return mb_strrpos( $str, $find, $offset, $encoding ); |
|
| 616 | +function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') { |
|
| 617 | + if (function_exists('mb_strrpos')) { |
|
| 618 | + return mb_strrpos($str, $find, $offset, $encoding); |
|
| 619 | 619 | } |
| 620 | 620 | |
| 621 | - return strrpos( $str, $find, $offset ); |
|
| 621 | + return strrpos($str, $find, $offset); |
|
| 622 | 622 | } |
| 623 | 623 | |
| 624 | 624 | /** |
@@ -633,16 +633,16 @@ discard block |
||
| 633 | 633 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 634 | 634 | * @return string |
| 635 | 635 | */ |
| 636 | -function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) { |
|
| 637 | - if ( function_exists( 'mb_substr' ) ) { |
|
| 638 | - if ( $length === null ) { |
|
| 639 | - return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding ); |
|
| 636 | +function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') { |
|
| 637 | + if (function_exists('mb_substr')) { |
|
| 638 | + if ($length === null) { |
|
| 639 | + return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding); |
|
| 640 | 640 | } else { |
| 641 | - return mb_substr( $str, $start, $length, $encoding ); |
|
| 641 | + return mb_substr($str, $start, $length, $encoding); |
|
| 642 | 642 | } |
| 643 | 643 | } |
| 644 | 644 | |
| 645 | - return substr( $str, $start, $length ); |
|
| 645 | + return substr($str, $start, $length); |
|
| 646 | 646 | } |
| 647 | 647 | |
| 648 | 648 | /** |
@@ -654,48 +654,48 @@ discard block |
||
| 654 | 654 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 655 | 655 | * @return string The width of string. |
| 656 | 656 | */ |
| 657 | -function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) { |
|
| 658 | - if ( function_exists( 'mb_strwidth' ) ) { |
|
| 659 | - return mb_strwidth( $str, $encoding ); |
|
| 657 | +function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') { |
|
| 658 | + if (function_exists('mb_strwidth')) { |
|
| 659 | + return mb_strwidth($str, $encoding); |
|
| 660 | 660 | } |
| 661 | 661 | |
| 662 | - return wpinv_utf8_strlen( $str, $encoding ); |
|
| 662 | + return wpinv_utf8_strlen($str, $encoding); |
|
| 663 | 663 | } |
| 664 | 664 | |
| 665 | -function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) { |
|
| 666 | - if ( function_exists( 'mb_strlen' ) ) { |
|
| 667 | - $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding ); |
|
| 665 | +function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') { |
|
| 666 | + if (function_exists('mb_strlen')) { |
|
| 667 | + $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding); |
|
| 668 | 668 | $str_end = ""; |
| 669 | 669 | |
| 670 | - if ( $lower_str_end ) { |
|
| 671 | - $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding ); |
|
| 670 | + if ($lower_str_end) { |
|
| 671 | + $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding); |
|
| 672 | 672 | } else { |
| 673 | - $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ); |
|
| 673 | + $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding); |
|
| 674 | 674 | } |
| 675 | 675 | |
| 676 | 676 | return $first_letter . $str_end; |
| 677 | 677 | } |
| 678 | 678 | |
| 679 | - return ucfirst( $str ); |
|
| 679 | + return ucfirst($str); |
|
| 680 | 680 | } |
| 681 | 681 | |
| 682 | -function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) { |
|
| 683 | - if ( function_exists( 'mb_convert_case' ) ) { |
|
| 684 | - return mb_convert_case( $str, MB_CASE_TITLE, $encoding ); |
|
| 682 | +function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') { |
|
| 683 | + if (function_exists('mb_convert_case')) { |
|
| 684 | + return mb_convert_case($str, MB_CASE_TITLE, $encoding); |
|
| 685 | 685 | } |
| 686 | 686 | |
| 687 | - return ucwords( $str ); |
|
| 687 | + return ucwords($str); |
|
| 688 | 688 | } |
| 689 | 689 | |
| 690 | -function wpinv_period_in_days( $period, $unit ) { |
|
| 691 | - $period = absint( $period ); |
|
| 690 | +function wpinv_period_in_days($period, $unit) { |
|
| 691 | + $period = absint($period); |
|
| 692 | 692 | |
| 693 | - if ( $period > 0 ) { |
|
| 694 | - if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) { |
|
| 693 | + if ($period > 0) { |
|
| 694 | + if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) { |
|
| 695 | 695 | $period = $period * 7; |
| 696 | - } else if ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) { |
|
| 696 | + } else if (in_array(strtolower($unit), array('m', 'month', 'months'))) { |
|
| 697 | 697 | $period = $period * 30; |
| 698 | - } else if ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) { |
|
| 698 | + } else if (in_array(strtolower($unit), array('y', 'year', 'years'))) { |
|
| 699 | 699 | $period = $period * 365; |
| 700 | 700 | } |
| 701 | 701 | } |
@@ -7,15 +7,15 @@ discard block |
||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | // MUST have WordPress. |
| 10 | -if ( !defined( 'WPINC' ) ) { |
|
| 11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
| 10 | +if (!defined('WPINC')) { |
|
| 11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | class WPInv_Plugin { |
| 15 | 15 | private static $instance; |
| 16 | 16 | |
| 17 | 17 | public static function run() { |
| 18 | - if ( !isset( self::$instance ) && !( self::$instance instanceof WPInv_Plugin ) ) { |
|
| 18 | + if (!isset(self::$instance) && !(self::$instance instanceof WPInv_Plugin)) { |
|
| 19 | 19 | self::$instance = new WPInv_Plugin; |
| 20 | 20 | self::$instance->includes(); |
| 21 | 21 | self::$instance->actions(); |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | self::$instance->reports = new WPInv_Reports(); |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | - do_action( 'wpinv_loaded' ); |
|
| 26 | + do_action('wpinv_loaded'); |
|
| 27 | 27 | |
| 28 | 28 | return self::$instance; |
| 29 | 29 | } |
@@ -33,31 +33,31 @@ discard block |
||
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | public function define_constants() { |
| 36 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
| 37 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
| 36 | + define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE)); |
|
| 37 | + define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE)); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | private function actions() { |
| 41 | 41 | /* Internationalize the text strings used. */ |
| 42 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
| 42 | + add_action('plugins_loaded', array(&$this, 'plugins_loaded')); |
|
| 43 | 43 | |
| 44 | 44 | /* Perform actions on admin initialization. */ |
| 45 | - add_action( 'admin_init', array( &$this, 'admin_init') ); |
|
| 46 | - add_action( 'init', array( &$this, 'init' ), 3 ); |
|
| 47 | - add_action( 'init', array( 'WPInv_Shortcodes', 'init' ) ); |
|
| 48 | - add_action( 'init', array( &$this, 'wpinv_actions' ) ); |
|
| 45 | + add_action('admin_init', array(&$this, 'admin_init')); |
|
| 46 | + add_action('init', array(&$this, 'init'), 3); |
|
| 47 | + add_action('init', array('WPInv_Shortcodes', 'init')); |
|
| 48 | + add_action('init', array(&$this, 'wpinv_actions')); |
|
| 49 | 49 | |
| 50 | - if ( class_exists( 'BuddyPress' ) ) { |
|
| 51 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
| 50 | + if (class_exists('BuddyPress')) { |
|
| 51 | + add_action('bp_include', array(&$this, 'bp_invoicing_init')); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
| 54 | + add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts')); |
|
| 55 | 55 | |
| 56 | - if ( is_admin() ) { |
|
| 57 | - add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) ); |
|
| 58 | - add_action( 'admin_body_class', array( &$this, 'admin_body_class' ) ); |
|
| 56 | + if (is_admin()) { |
|
| 57 | + add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts')); |
|
| 58 | + add_action('admin_body_class', array(&$this, 'admin_body_class')); |
|
| 59 | 59 | } else { |
| 60 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
| 60 | + add_filter('pre_get_posts', array(&$this, 'pre_get_posts')); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
@@ -67,9 +67,9 @@ discard block |
||
| 67 | 67 | * |
| 68 | 68 | * @param WPInv_Plugin $this. Current WPInv_Plugin instance. Passed by reference. |
| 69 | 69 | */ |
| 70 | - do_action_ref_array( 'wpinv_actions', array( &$this ) ); |
|
| 70 | + do_action_ref_array('wpinv_actions', array(&$this)); |
|
| 71 | 71 | |
| 72 | - add_action( 'admin_init', array( &$this, 'activation_redirect') ); |
|
| 72 | + add_action('admin_init', array(&$this, 'activation_redirect')); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | public function plugins_loaded() { |
@@ -83,193 +83,193 @@ discard block |
||
| 83 | 83 | * @since 1.0 |
| 84 | 84 | */ |
| 85 | 85 | public function load_textdomain() { |
| 86 | - $locale = apply_filters( 'plugin_locale', get_locale(), 'invoicing' ); |
|
| 86 | + $locale = apply_filters('plugin_locale', get_locale(), 'invoicing'); |
|
| 87 | 87 | |
| 88 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
| 89 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
| 88 | + load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo'); |
|
| 89 | + load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages'); |
|
| 90 | 90 | |
| 91 | 91 | /** |
| 92 | 92 | * Define language constants. |
| 93 | 93 | */ |
| 94 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
| 94 | + require_once(WPINV_PLUGIN_DIR . 'language.php'); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | public function includes() { |
| 98 | 98 | global $wpinv_options; |
| 99 | 99 | |
| 100 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
| 100 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'); |
|
| 101 | 101 | $wpinv_options = wpinv_get_settings(); |
| 102 | 102 | |
| 103 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php' ); |
|
| 104 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
| 105 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
| 106 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
| 107 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
| 108 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
| 109 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
| 110 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php' ); |
|
| 111 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
| 112 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
| 113 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
| 114 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
| 115 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
| 116 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gd-functions.php' ); |
|
| 117 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' ); |
|
| 103 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php'); |
|
| 104 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'); |
|
| 105 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'); |
|
| 106 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'); |
|
| 107 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'); |
|
| 108 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'); |
|
| 109 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'); |
|
| 110 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php'); |
|
| 111 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'); |
|
| 112 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'); |
|
| 113 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'); |
|
| 114 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'); |
|
| 115 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php'); |
|
| 116 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gd-functions.php'); |
|
| 117 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php'); |
|
| 118 | 118 | //require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
| 119 | 119 | //require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
| 120 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php' ); |
|
| 120 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php'); |
|
| 121 | 121 | //require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscription.php' ); |
| 122 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php' ); |
|
| 123 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php' ); |
|
| 124 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php' ); |
|
| 125 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
| 126 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
| 127 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
| 128 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php' ); |
|
| 129 | - if ( !class_exists( 'Geodir_EUVat' ) ) { |
|
| 130 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
| 122 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php'); |
|
| 123 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php'); |
|
| 124 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php'); |
|
| 125 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'); |
|
| 126 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'); |
|
| 127 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php'); |
|
| 128 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php'); |
|
| 129 | + if (!class_exists('Geodir_EUVat')) { |
|
| 130 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php'); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
| 134 | - if ( !empty( $gateways ) ) { |
|
| 135 | - foreach ( $gateways as $gateway ) { |
|
| 136 | - if ( $gateway == 'manual' ) { |
|
| 133 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
| 134 | + if (!empty($gateways)) { |
|
| 135 | + foreach ($gateways as $gateway) { |
|
| 136 | + if ($gateway == 'manual') { |
|
| 137 | 137 | continue; |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php'; |
| 141 | 141 | |
| 142 | - if ( file_exists( $gateway_file ) ) { |
|
| 143 | - require_once( $gateway_file ); |
|
| 142 | + if (file_exists($gateway_file)) { |
|
| 143 | + require_once($gateway_file); |
|
| 144 | 144 | } |
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | - require_once( WPINV_PLUGIN_DIR . 'includes/gateways/manual.php' ); |
|
| 148 | - |
|
| 149 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
| 150 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
| 151 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
| 152 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php' ); |
|
| 153 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' ); |
|
| 154 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php' ); |
|
| 155 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php' ); |
|
| 156 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
| 157 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php' ); |
|
| 158 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
| 147 | + require_once(WPINV_PLUGIN_DIR . 'includes/gateways/manual.php'); |
|
| 148 | + |
|
| 149 | + if (is_admin() || (defined('WP_CLI') && WP_CLI)) { |
|
| 150 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php'); |
|
| 151 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'); |
|
| 152 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php'); |
|
| 153 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php'); |
|
| 154 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php'); |
|
| 155 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php'); |
|
| 156 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'); |
|
| 157 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php'); |
|
| 158 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'); |
|
| 159 | 159 | //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | // include css inliner |
| 163 | - if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) { |
|
| 164 | - include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' ); |
|
| 163 | + if (!class_exists('Emogrifier') && class_exists('DOMDocument')) { |
|
| 164 | + include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php'); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
| 167 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php'); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | public function init() { |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | public function admin_init() { |
| 174 | - if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) { |
|
| 174 | + if (!(defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | - add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) ); |
|
| 177 | + add_action('admin_print_scripts-edit.php', array(&$this, 'admin_print_scripts_edit_php')); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | public function activation_redirect() { |
| 181 | 181 | // Bail if no activation redirect |
| 182 | - if ( !get_transient( '_wpinv_activation_redirect' ) ) { |
|
| 182 | + if (!get_transient('_wpinv_activation_redirect')) { |
|
| 183 | 183 | return; |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | // Delete the redirect transient |
| 187 | - delete_transient( '_wpinv_activation_redirect' ); |
|
| 187 | + delete_transient('_wpinv_activation_redirect'); |
|
| 188 | 188 | |
| 189 | 189 | // Bail if activating from network, or bulk |
| 190 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
| 190 | + if (is_network_admin() || isset($_GET['activate-multi'])) { |
|
| 191 | 191 | return; |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | - wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
| 194 | + wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general')); |
|
| 195 | 195 | exit; |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | public function enqueue_scripts() { |
| 199 | - $suffix = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 199 | + $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 200 | 200 | |
| 201 | - wp_deregister_style( 'font-awesome' ); |
|
| 202 | - wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' ); |
|
| 203 | - wp_enqueue_style( 'font-awesome' ); |
|
| 201 | + wp_deregister_style('font-awesome'); |
|
| 202 | + wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0'); |
|
| 203 | + wp_enqueue_style('font-awesome'); |
|
| 204 | 204 | |
| 205 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION ); |
|
| 206 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
| 205 | + wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION); |
|
| 206 | + wp_enqueue_style('wpinv_front_style'); |
|
| 207 | 207 | |
| 208 | 208 | // Register scripts |
| 209 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
| 210 | - wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array( 'jquery', 'wpinv-vat-script' ), WPINV_VERSION ); |
|
| 209 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
| 210 | + wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array('jquery', 'wpinv-vat-script'), WPINV_VERSION); |
|
| 211 | 211 | |
| 212 | 212 | $localize = array(); |
| 213 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 214 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 213 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
| 214 | + $localize['nonce'] = wp_create_nonce('wpinv-nonce'); |
|
| 215 | 215 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
| 216 | 216 | $localize['currency_pos'] = wpinv_currency_position(); |
| 217 | 217 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
| 218 | 218 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
| 219 | 219 | $localize['decimals'] = wpinv_decimals(); |
| 220 | 220 | |
| 221 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
| 221 | + $localize = apply_filters('wpinv_front_js_localize', $localize); |
|
| 222 | 222 | |
| 223 | - wp_enqueue_script( 'jquery-blockui' ); |
|
| 224 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
| 225 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
| 223 | + wp_enqueue_script('jquery-blockui'); |
|
| 224 | + wp_enqueue_script('wpinv-front-script'); |
|
| 225 | + wp_localize_script('wpinv-front-script', 'WPInv', $localize); |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | public function admin_enqueue_scripts() { |
| 229 | 229 | global $post, $pagenow; |
| 230 | 230 | |
| 231 | 231 | $post_type = wpinv_admin_post_type(); |
| 232 | - $suffix = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 232 | + $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 233 | 233 | |
| 234 | - wp_deregister_style( 'font-awesome' ); |
|
| 235 | - wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' ); |
|
| 236 | - wp_enqueue_style( 'font-awesome' ); |
|
| 234 | + wp_deregister_style('font-awesome'); |
|
| 235 | + wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0'); |
|
| 236 | + wp_enqueue_style('font-awesome'); |
|
| 237 | 237 | |
| 238 | - wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' ); |
|
| 239 | - wp_enqueue_style( 'jquery-ui-css' ); |
|
| 238 | + wp_register_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16'); |
|
| 239 | + wp_enqueue_style('jquery-ui-css'); |
|
| 240 | 240 | |
| 241 | - wp_register_style( 'jquery-chosen', WPINV_PLUGIN_URL . 'assets/css/chosen' . $suffix . '.css', array(), '1.6.2' ); |
|
| 242 | - wp_enqueue_style( 'jquery-chosen' ); |
|
| 241 | + wp_register_style('jquery-chosen', WPINV_PLUGIN_URL . 'assets/css/chosen' . $suffix . '.css', array(), '1.6.2'); |
|
| 242 | + wp_enqueue_style('jquery-chosen'); |
|
| 243 | 243 | |
| 244 | - wp_register_script( 'jquery-chosen', WPINV_PLUGIN_URL . 'assets/js/chosen.jquery' . $suffix . '.js', array( 'jquery' ), '1.6.2' ); |
|
| 245 | - wp_enqueue_script( 'jquery-chosen' ); |
|
| 244 | + wp_register_script('jquery-chosen', WPINV_PLUGIN_URL . 'assets/js/chosen.jquery' . $suffix . '.js', array('jquery'), '1.6.2'); |
|
| 245 | + wp_enqueue_script('jquery-chosen'); |
|
| 246 | 246 | |
| 247 | - wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION ); |
|
| 248 | - wp_enqueue_style( 'wpinv_meta_box_style' ); |
|
| 247 | + wp_register_style('wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION); |
|
| 248 | + wp_enqueue_style('wpinv_meta_box_style'); |
|
| 249 | 249 | |
| 250 | - wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION ); |
|
| 251 | - wp_enqueue_style( 'wpinv_admin_style' ); |
|
| 250 | + wp_register_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION); |
|
| 251 | + wp_enqueue_style('wpinv_admin_style'); |
|
| 252 | 252 | |
| 253 | - if ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) { |
|
| 254 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
| 253 | + if ($post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
|
| 254 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | - wp_enqueue_style( 'wp-color-picker' ); |
|
| 258 | - wp_enqueue_script( 'wp-color-picker' ); |
|
| 257 | + wp_enqueue_style('wp-color-picker'); |
|
| 258 | + wp_enqueue_script('wp-color-picker'); |
|
| 259 | 259 | |
| 260 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
| 260 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
| 261 | 261 | |
| 262 | - wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array( 'jquery', 'jquery-blockui' ), WPINV_VERSION ); |
|
| 263 | - wp_enqueue_script( 'wpinv-admin-script' ); |
|
| 262 | + wp_register_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array('jquery', 'jquery-blockui'), WPINV_VERSION); |
|
| 263 | + wp_enqueue_script('wpinv-admin-script'); |
|
| 264 | 264 | |
| 265 | 265 | $localize = array(); |
| 266 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 267 | - $localize['post_ID'] = isset( $post->ID ) ? $post->ID : ''; |
|
| 268 | - $localize['wpinv_nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 269 | - $localize['add_invoice_note_nonce'] = wp_create_nonce( 'add-invoice-note' ); |
|
| 270 | - $localize['delete_invoice_note_nonce'] = wp_create_nonce( 'delete-invoice-note' ); |
|
| 271 | - $localize['invoice_item_nonce'] = wp_create_nonce( 'invoice-item' ); |
|
| 272 | - $localize['billing_details_nonce'] = wp_create_nonce( 'get-billing-details' ); |
|
| 266 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
| 267 | + $localize['post_ID'] = isset($post->ID) ? $post->ID : ''; |
|
| 268 | + $localize['wpinv_nonce'] = wp_create_nonce('wpinv-nonce'); |
|
| 269 | + $localize['add_invoice_note_nonce'] = wp_create_nonce('add-invoice-note'); |
|
| 270 | + $localize['delete_invoice_note_nonce'] = wp_create_nonce('delete-invoice-note'); |
|
| 271 | + $localize['invoice_item_nonce'] = wp_create_nonce('invoice-item'); |
|
| 272 | + $localize['billing_details_nonce'] = wp_create_nonce('get-billing-details'); |
|
| 273 | 273 | $localize['tax'] = wpinv_tax_amount(); |
| 274 | 274 | $localize['discount'] = wpinv_discount_amount(); |
| 275 | 275 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
@@ -277,55 +277,55 @@ discard block |
||
| 277 | 277 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
| 278 | 278 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
| 279 | 279 | $localize['decimals'] = wpinv_decimals(); |
| 280 | - $localize['save_invoice'] = __( 'Save Invoice', 'invoicing' ); |
|
| 281 | - $localize['status_publish'] = wpinv_status_nicename( 'publish' ); |
|
| 282 | - $localize['status_pending'] = wpinv_status_nicename( 'pending' ); |
|
| 283 | - $localize['delete_tax_rate'] = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ); |
|
| 284 | - $localize['OneItemMin'] = __( 'Invoice must contain at least one item', 'invoicing' ); |
|
| 285 | - $localize['DeleteInvoiceItem'] = __( 'Are you sure you wish to delete this item?', 'invoicing' ); |
|
| 286 | - $localize['FillBillingDetails'] = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ); |
|
| 287 | - $localize['confirmCalcTotals'] = __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' ); |
|
| 288 | - $localize['AreYouSure'] = __( 'Are you sure?', 'invoicing' ); |
|
| 289 | - $localize['hasGD'] = wpinv_gd_active();; |
|
| 280 | + $localize['save_invoice'] = __('Save Invoice', 'invoicing'); |
|
| 281 | + $localize['status_publish'] = wpinv_status_nicename('publish'); |
|
| 282 | + $localize['status_pending'] = wpinv_status_nicename('pending'); |
|
| 283 | + $localize['delete_tax_rate'] = __('Are you sure you wish to delete this tax rate?', 'invoicing'); |
|
| 284 | + $localize['OneItemMin'] = __('Invoice must contain at least one item', 'invoicing'); |
|
| 285 | + $localize['DeleteInvoiceItem'] = __('Are you sure you wish to delete this item?', 'invoicing'); |
|
| 286 | + $localize['FillBillingDetails'] = __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'); |
|
| 287 | + $localize['confirmCalcTotals'] = __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing'); |
|
| 288 | + $localize['AreYouSure'] = __('Are you sure?', 'invoicing'); |
|
| 289 | + $localize['hasGD'] = wpinv_gd_active(); ; |
|
| 290 | 290 | $localize['hasPM'] = wpinv_pm_active(); |
| 291 | - $localize['emptyInvoice'] = __( 'Add atleast one item to save invoice!', 'invoicing' ); |
|
| 292 | - $localize['deletePackage'] = __( 'GD package items should be deleted from GD payment manager only, otherwise it will break invoices that created with this package!', 'invoicing' ); |
|
| 293 | - $localize['deletePackages'] = __( 'GD package items should be deleted from GD payment manager only', 'invoicing' ); |
|
| 294 | - $localize['deleteInvoiceFirst'] = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ); |
|
| 291 | + $localize['emptyInvoice'] = __('Add atleast one item to save invoice!', 'invoicing'); |
|
| 292 | + $localize['deletePackage'] = __('GD package items should be deleted from GD payment manager only, otherwise it will break invoices that created with this package!', 'invoicing'); |
|
| 293 | + $localize['deletePackages'] = __('GD package items should be deleted from GD payment manager only', 'invoicing'); |
|
| 294 | + $localize['deleteInvoiceFirst'] = __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'); |
|
| 295 | 295 | |
| 296 | - wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize ); |
|
| 296 | + wp_localize_script('wpinv-admin-script', 'WPInv_Admin', $localize); |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - public function admin_body_class( $classes ) { |
|
| 299 | + public function admin_body_class($classes) { |
|
| 300 | 300 | global $pagenow; |
| 301 | 301 | |
| 302 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false; |
|
| 302 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : false; |
|
| 303 | 303 | |
| 304 | 304 | $add_class = false; |
| 305 | - if ( $pagenow == 'admin.php' && $page ) { |
|
| 306 | - $add_class = strpos( $page, 'wpinv-' ); |
|
| 305 | + if ($pagenow == 'admin.php' && $page) { |
|
| 306 | + $add_class = strpos($page, 'wpinv-'); |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | $settings_class = array(); |
| 310 | - if ( $page == 'wpinv-settings' ) { |
|
| 311 | - if ( !empty( $_REQUEST['tab'] ) ) { |
|
| 312 | - $settings_class[] = sanitize_text_field( $_REQUEST['tab'] ); |
|
| 310 | + if ($page == 'wpinv-settings') { |
|
| 311 | + if (!empty($_REQUEST['tab'])) { |
|
| 312 | + $settings_class[] = sanitize_text_field($_REQUEST['tab']); |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | - if ( !empty( $_REQUEST['section'] ) ) { |
|
| 316 | - $settings_class[] = sanitize_text_field( $_REQUEST['section'] ); |
|
| 315 | + if (!empty($_REQUEST['section'])) { |
|
| 316 | + $settings_class[] = sanitize_text_field($_REQUEST['section']); |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | - $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main'; |
|
| 319 | + $settings_class[] = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field($_REQUEST['wpi_sub']) : 'main'; |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | - if ( !empty( $settings_class ) ) { |
|
| 323 | - $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) ); |
|
| 322 | + if (!empty($settings_class)) { |
|
| 323 | + $classes .= ' wpi-' . wpinv_sanitize_key(implode($settings_class, '-')); |
|
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | $post_type = wpinv_admin_post_type(); |
| 327 | 327 | |
| 328 | - if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) { |
|
| 328 | + if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false) { |
|
| 329 | 329 | return $classes .= ' wpinv'; |
| 330 | 330 | } else { |
| 331 | 331 | return $classes; |
@@ -337,26 +337,26 @@ discard block |
||
| 337 | 337 | public function admin_print_scripts_edit_php() { |
| 338 | 338 | $post_type = wpinv_admin_post_type(); |
| 339 | 339 | |
| 340 | - if ( $post_type == 'wpi_item' ) { |
|
| 341 | - wp_enqueue_script( 'wpinv-inline-edit-post', WPINV_PLUGIN_URL . 'assets/js/quick-edit.js', array( 'jquery', 'inline-edit-post' ), '', true ); |
|
| 340 | + if ($post_type == 'wpi_item') { |
|
| 341 | + wp_enqueue_script('wpinv-inline-edit-post', WPINV_PLUGIN_URL . 'assets/js/quick-edit.js', array('jquery', 'inline-edit-post'), '', true); |
|
| 342 | 342 | } |
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | public function wpinv_actions() { |
| 346 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
| 347 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
| 346 | + if (isset($_REQUEST['wpi_action'])) { |
|
| 347 | + do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST); |
|
| 348 | 348 | } |
| 349 | 349 | } |
| 350 | 350 | |
| 351 | - public function pre_get_posts( $wp_query ) { |
|
| 352 | - if ( !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
| 353 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
| 351 | + public function pre_get_posts($wp_query) { |
|
| 352 | + if (!empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query()) { |
|
| 353 | + $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses()); |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | return $wp_query; |
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | public function bp_invoicing_init() { |
| 360 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
| 360 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php'); |
|
| 361 | 361 | } |
| 362 | 362 | } |
| 363 | 363 | \ No newline at end of file |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | // Exit if accessed directly |
| 3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 3 | +if (!defined('ABSPATH')) exit; |
|
| 4 | 4 | |
| 5 | 5 | class WPInv_Item { |
| 6 | 6 | public $ID = 0; |
@@ -33,26 +33,26 @@ discard block |
||
| 33 | 33 | public $filter; |
| 34 | 34 | |
| 35 | 35 | |
| 36 | - public function __construct( $_id = false, $_args = array() ) { |
|
| 37 | - $item = WP_Post::get_instance( $_id ); |
|
| 38 | - return $this->setup_item( $item ); |
|
| 36 | + public function __construct($_id = false, $_args = array()) { |
|
| 37 | + $item = WP_Post::get_instance($_id); |
|
| 38 | + return $this->setup_item($item); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - private function setup_item( $item ) { |
|
| 42 | - if( ! is_object( $item ) ) { |
|
| 41 | + private function setup_item($item) { |
|
| 42 | + if (!is_object($item)) { |
|
| 43 | 43 | return false; |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - if( ! is_a( $item, 'WP_Post' ) ) { |
|
| 46 | + if (!is_a($item, 'WP_Post')) { |
|
| 47 | 47 | return false; |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - if( 'wpi_item' !== $item->post_type ) { |
|
| 50 | + if ('wpi_item' !== $item->post_type) { |
|
| 51 | 51 | return false; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - foreach ( $item as $key => $value ) { |
|
| 55 | - switch ( $key ) { |
|
| 54 | + foreach ($item as $key => $value) { |
|
| 55 | + switch ($key) { |
|
| 56 | 56 | default: |
| 57 | 57 | $this->$key = $value; |
| 58 | 58 | break; |
@@ -62,38 +62,38 @@ discard block |
||
| 62 | 62 | return true; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - public function __get( $key ) { |
|
| 66 | - if ( method_exists( $this, 'get_' . $key ) ) { |
|
| 67 | - return call_user_func( array( $this, 'get_' . $key ) ); |
|
| 65 | + public function __get($key) { |
|
| 66 | + if (method_exists($this, 'get_' . $key)) { |
|
| 67 | + return call_user_func(array($this, 'get_' . $key)); |
|
| 68 | 68 | } else { |
| 69 | - return new WP_Error( 'wpinv-item-invalid-property', sprintf( __( 'Can\'t get property %s', 'invoicing' ), $key ) ); |
|
| 69 | + return new WP_Error('wpinv-item-invalid-property', sprintf(__('Can\'t get property %s', 'invoicing'), $key)); |
|
| 70 | 70 | } |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - public function create( $data = array(), $wp_error = false ) { |
|
| 74 | - if ( $this->ID != 0 ) { |
|
| 73 | + public function create($data = array(), $wp_error = false) { |
|
| 74 | + if ($this->ID != 0) { |
|
| 75 | 75 | return false; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | $defaults = array( |
| 79 | 79 | 'post_type' => 'wpi_item', |
| 80 | 80 | 'post_status' => 'draft', |
| 81 | - 'post_title' => __( 'New Invoice Item', 'invoicing' ) |
|
| 81 | + 'post_title' => __('New Invoice Item', 'invoicing') |
|
| 82 | 82 | ); |
| 83 | 83 | |
| 84 | - $args = wp_parse_args( $data, $defaults ); |
|
| 84 | + $args = wp_parse_args($data, $defaults); |
|
| 85 | 85 | |
| 86 | - do_action( 'wpinv_item_pre_create', $args ); |
|
| 86 | + do_action('wpinv_item_pre_create', $args); |
|
| 87 | 87 | |
| 88 | - $id = wp_insert_post( $args, $wp_error ); |
|
| 88 | + $id = wp_insert_post($args, $wp_error); |
|
| 89 | 89 | if ($wp_error && is_wp_error($id)) { |
| 90 | 90 | return $id; |
| 91 | 91 | } |
| 92 | - if ( !$id ) { |
|
| 92 | + if (!$id) { |
|
| 93 | 93 | return false; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - $item = WP_Post::get_instance( $id ); |
|
| 96 | + $item = WP_Post::get_instance($id); |
|
| 97 | 97 | |
| 98 | 98 | if (!empty($item) && !empty($data['meta'])) { |
| 99 | 99 | $this->ID = $item->ID; |
@@ -101,47 +101,47 @@ discard block |
||
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | // Set custom id if not set. |
| 104 | - if ( empty( $data['meta']['custom_id'] ) && !$this->get_custom_id() ) { |
|
| 105 | - $item->save_metas( array( 'custom_id' => $id ) ); |
|
| 104 | + if (empty($data['meta']['custom_id']) && !$this->get_custom_id()) { |
|
| 105 | + $item->save_metas(array('custom_id' => $id)); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - do_action( 'wpinv_item_create', $id, $args ); |
|
| 108 | + do_action('wpinv_item_create', $id, $args); |
|
| 109 | 109 | |
| 110 | - return $this->setup_item( $item ); |
|
| 110 | + return $this->setup_item($item); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - public function update( $data = array(), $wp_error = false ) { |
|
| 114 | - if ( !$this->ID > 0 ) { |
|
| 113 | + public function update($data = array(), $wp_error = false) { |
|
| 114 | + if (!$this->ID > 0) { |
|
| 115 | 115 | return false; |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | $data['ID'] = $this->ID; |
| 119 | 119 | |
| 120 | - do_action( 'wpinv_item_pre_update', $data ); |
|
| 120 | + do_action('wpinv_item_pre_update', $data); |
|
| 121 | 121 | |
| 122 | - $id = wp_update_post( $data, $wp_error ); |
|
| 122 | + $id = wp_update_post($data, $wp_error); |
|
| 123 | 123 | if ($wp_error && is_wp_error($id)) { |
| 124 | 124 | return $id; |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - if ( !$id ) { |
|
| 127 | + if (!$id) { |
|
| 128 | 128 | return false; |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - $item = WP_Post::get_instance( $id ); |
|
| 131 | + $item = WP_Post::get_instance($id); |
|
| 132 | 132 | if (!empty($item) && !empty($data['meta'])) { |
| 133 | 133 | $this->ID = $item->ID; |
| 134 | 134 | $this->save_metas($data['meta']); |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | // Set custom id if not set. |
| 138 | - if ( empty( $data['meta']['custom_id'] ) && !$this->get_custom_id() ) { |
|
| 139 | - $item->save_metas( array( 'custom_id' => $id ) ); |
|
| 138 | + if (empty($data['meta']['custom_id']) && !$this->get_custom_id()) { |
|
| 139 | + $item->save_metas(array('custom_id' => $id)); |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - do_action( 'wpinv_item_update', $id, $data ); |
|
| 142 | + do_action('wpinv_item_update', $id, $data); |
|
| 143 | 143 | |
| 144 | - return $this->setup_item( $item ); |
|
| 144 | + return $this->setup_item($item); |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | public function get_ID() { |
@@ -149,105 +149,105 @@ discard block |
||
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | public function get_name() { |
| 152 | - return get_the_title( $this->ID ); |
|
| 152 | + return get_the_title($this->ID); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | public function get_summary() { |
| 156 | - return get_the_excerpt( $this->ID ); |
|
| 156 | + return get_the_excerpt($this->ID); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | public function get_price() { |
| 160 | - if ( ! isset( $this->price ) ) { |
|
| 161 | - $this->price = get_post_meta( $this->ID, '_wpinv_price', true ); |
|
| 160 | + if (!isset($this->price)) { |
|
| 161 | + $this->price = get_post_meta($this->ID, '_wpinv_price', true); |
|
| 162 | 162 | |
| 163 | - if ( $this->price ) { |
|
| 164 | - $this->price = wpinv_sanitize_amount( $this->price ); |
|
| 163 | + if ($this->price) { |
|
| 164 | + $this->price = wpinv_sanitize_amount($this->price); |
|
| 165 | 165 | } else { |
| 166 | 166 | $this->price = 0; |
| 167 | 167 | } |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | - return apply_filters( 'wpinv_get_item_price', $this->price, $this->ID ); |
|
| 170 | + return apply_filters('wpinv_get_item_price', $this->price, $this->ID); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | public function get_the_price() { |
| 174 | - $item_price = wpinv_price( wpinv_format_amount( $this->price ) ); |
|
| 174 | + $item_price = wpinv_price(wpinv_format_amount($this->price)); |
|
| 175 | 175 | |
| 176 | - return apply_filters( 'wpinv_get_the_item_price', $item_price, $this->ID ); |
|
| 176 | + return apply_filters('wpinv_get_the_item_price', $item_price, $this->ID); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | public function get_vat_rule() { |
| 180 | 180 | global $wpinv_euvat; |
| 181 | 181 | |
| 182 | - if( !isset( $this->vat_rule ) ) { |
|
| 183 | - $this->vat_rule = get_post_meta( $this->ID, '_wpinv_vat_rule', true ); |
|
| 182 | + if (!isset($this->vat_rule)) { |
|
| 183 | + $this->vat_rule = get_post_meta($this->ID, '_wpinv_vat_rule', true); |
|
| 184 | 184 | |
| 185 | - if ( empty( $this->vat_rule ) ) { |
|
| 185 | + if (empty($this->vat_rule)) { |
|
| 186 | 186 | $this->vat_rule = $wpinv_euvat->allow_vat_rules() ? 'digital' : 'physical'; |
| 187 | 187 | } |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - return apply_filters( 'wpinv_get_item_vat_rule', $this->vat_rule, $this->ID ); |
|
| 190 | + return apply_filters('wpinv_get_item_vat_rule', $this->vat_rule, $this->ID); |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | public function get_vat_class() { |
| 194 | - if( !isset( $this->vat_class ) ) { |
|
| 195 | - $this->vat_class = get_post_meta( $this->ID, '_wpinv_vat_class', true ); |
|
| 194 | + if (!isset($this->vat_class)) { |
|
| 195 | + $this->vat_class = get_post_meta($this->ID, '_wpinv_vat_class', true); |
|
| 196 | 196 | |
| 197 | - if ( empty( $this->vat_class ) ) { |
|
| 197 | + if (empty($this->vat_class)) { |
|
| 198 | 198 | $this->vat_class = '_standard'; |
| 199 | 199 | } |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | - return apply_filters( 'wpinv_get_item_vat_class', $this->vat_class, $this->ID ); |
|
| 202 | + return apply_filters('wpinv_get_item_vat_class', $this->vat_class, $this->ID); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | public function get_type() { |
| 206 | - if( ! isset( $this->type ) ) { |
|
| 207 | - $this->type = get_post_meta( $this->ID, '_wpinv_type', true ); |
|
| 206 | + if (!isset($this->type)) { |
|
| 207 | + $this->type = get_post_meta($this->ID, '_wpinv_type', true); |
|
| 208 | 208 | |
| 209 | - if ( empty( $this->type ) ) { |
|
| 209 | + if (empty($this->type)) { |
|
| 210 | 210 | $this->type = 'custom'; |
| 211 | 211 | } |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | - return apply_filters( 'wpinv_get_item_type', $this->type, $this->ID ); |
|
| 214 | + return apply_filters('wpinv_get_item_type', $this->type, $this->ID); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | public function get_custom_id() { |
| 218 | - $custom_id = get_post_meta( $this->ID, '_wpinv_custom_id', true ); |
|
| 218 | + $custom_id = get_post_meta($this->ID, '_wpinv_custom_id', true); |
|
| 219 | 219 | |
| 220 | - return apply_filters( 'wpinv_get_item_custom_id', $custom_id, $this->ID ); |
|
| 220 | + return apply_filters('wpinv_get_item_custom_id', $custom_id, $this->ID); |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | public function get_custom_name() { |
| 224 | - $custom_name = get_post_meta( $this->ID, '_wpinv_custom_name', true ); |
|
| 224 | + $custom_name = get_post_meta($this->ID, '_wpinv_custom_name', true); |
|
| 225 | 225 | |
| 226 | - return apply_filters( 'wpinv_get_item_custom_name', $custom_name, $this->ID ); |
|
| 226 | + return apply_filters('wpinv_get_item_custom_name', $custom_name, $this->ID); |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | public function get_custom_singular_name() { |
| 230 | - $custom_singular_name = get_post_meta( $this->ID, '_wpinv_custom_singular_name', true ); |
|
| 230 | + $custom_singular_name = get_post_meta($this->ID, '_wpinv_custom_singular_name', true); |
|
| 231 | 231 | |
| 232 | - return apply_filters( 'wpinv_get_item_custom_singular_name', $custom_singular_name, $this->ID ); |
|
| 232 | + return apply_filters('wpinv_get_item_custom_singular_name', $custom_singular_name, $this->ID); |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | public function is_recurring() { |
| 236 | - $is_recurring = get_post_meta( $this->ID, '_wpinv_is_recurring', true ); |
|
| 236 | + $is_recurring = get_post_meta($this->ID, '_wpinv_is_recurring', true); |
|
| 237 | 237 | |
| 238 | - return (bool)apply_filters( 'wpinv_is_recurring_item', $is_recurring, $this->ID ); |
|
| 238 | + return (bool)apply_filters('wpinv_is_recurring_item', $is_recurring, $this->ID); |
|
| 239 | 239 | |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | - public function get_recurring_period( $full = false ) { |
|
| 243 | - $period = get_post_meta( $this->ID, '_wpinv_recurring_period', true ); |
|
| 242 | + public function get_recurring_period($full = false) { |
|
| 243 | + $period = get_post_meta($this->ID, '_wpinv_recurring_period', true); |
|
| 244 | 244 | |
| 245 | - if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) { |
|
| 245 | + if (!in_array($period, array('D', 'W', 'M', 'Y'))) { |
|
| 246 | 246 | $period = 'D'; |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | - if ( $full ) { |
|
| 250 | - switch( $period ) { |
|
| 249 | + if ($full) { |
|
| 250 | + switch ($period) { |
|
| 251 | 251 | case 'D': |
| 252 | 252 | $period = 'day'; |
| 253 | 253 | break; |
@@ -263,45 +263,45 @@ discard block |
||
| 263 | 263 | } |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | - return apply_filters( 'wpinv_item_recurring_period', $period, $full, $this->ID ); |
|
| 266 | + return apply_filters('wpinv_item_recurring_period', $period, $full, $this->ID); |
|
| 267 | 267 | |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | public function get_recurring_interval() { |
| 271 | - $interval = (int)get_post_meta( $this->ID, '_wpinv_recurring_interval', true ); |
|
| 271 | + $interval = (int)get_post_meta($this->ID, '_wpinv_recurring_interval', true); |
|
| 272 | 272 | |
| 273 | - if ( !$interval > 0 ) { |
|
| 273 | + if (!$interval > 0) { |
|
| 274 | 274 | $interval = 1; |
| 275 | 275 | } |
| 276 | 276 | |
| 277 | - return apply_filters( 'wpinv_item_recurring_interval', $interval, $this->ID ); |
|
| 277 | + return apply_filters('wpinv_item_recurring_interval', $interval, $this->ID); |
|
| 278 | 278 | |
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | public function get_recurring_limit() { |
| 282 | - $limit = get_post_meta( $this->ID, '_wpinv_recurring_limit', true ); |
|
| 282 | + $limit = get_post_meta($this->ID, '_wpinv_recurring_limit', true); |
|
| 283 | 283 | |
| 284 | - return (int)apply_filters( 'wpinv_item_recurring_limit', $limit, $this->ID ); |
|
| 284 | + return (int)apply_filters('wpinv_item_recurring_limit', $limit, $this->ID); |
|
| 285 | 285 | |
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | public function has_free_trial() { |
| 289 | - $free_trial = get_post_meta( $this->ID, '_wpinv_free_trial', true ); |
|
| 290 | - $free_trial = $this->is_recurring() && !empty( $free_trial ) ? true : false; |
|
| 289 | + $free_trial = get_post_meta($this->ID, '_wpinv_free_trial', true); |
|
| 290 | + $free_trial = $this->is_recurring() && !empty($free_trial) ? true : false; |
|
| 291 | 291 | |
| 292 | - return (bool)apply_filters( 'wpinv_item_has_free_trial', $free_trial, $this->ID ); |
|
| 292 | + return (bool)apply_filters('wpinv_item_has_free_trial', $free_trial, $this->ID); |
|
| 293 | 293 | |
| 294 | 294 | } |
| 295 | 295 | |
| 296 | - public function get_trial_period( $full = false ) { |
|
| 297 | - $period = get_post_meta( $this->ID, '_wpinv_trial_period', true ); |
|
| 296 | + public function get_trial_period($full = false) { |
|
| 297 | + $period = get_post_meta($this->ID, '_wpinv_trial_period', true); |
|
| 298 | 298 | |
| 299 | - if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) { |
|
| 299 | + if (!in_array($period, array('D', 'W', 'M', 'Y'))) { |
|
| 300 | 300 | $period = 'D'; |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | - if ( $full ) { |
|
| 304 | - switch( $period ) { |
|
| 303 | + if ($full) { |
|
| 304 | + switch ($period) { |
|
| 305 | 305 | case 'D': |
| 306 | 306 | $period = 'day'; |
| 307 | 307 | break; |
@@ -317,47 +317,47 @@ discard block |
||
| 317 | 317 | } |
| 318 | 318 | } |
| 319 | 319 | |
| 320 | - return apply_filters( 'wpinv_item_trial_period', $period, $full, $this->ID ); |
|
| 320 | + return apply_filters('wpinv_item_trial_period', $period, $full, $this->ID); |
|
| 321 | 321 | |
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | public function get_trial_interval() { |
| 325 | - $interval = absint( get_post_meta( $this->ID, '_wpinv_trial_interval', true ) ); |
|
| 325 | + $interval = absint(get_post_meta($this->ID, '_wpinv_trial_interval', true)); |
|
| 326 | 326 | |
| 327 | - if ( !$interval > 0 ) { |
|
| 327 | + if (!$interval > 0) { |
|
| 328 | 328 | $interval = 1; |
| 329 | 329 | } |
| 330 | 330 | |
| 331 | - return apply_filters( 'wpinv_item_trial_interval', $interval, $this->ID ); |
|
| 331 | + return apply_filters('wpinv_item_trial_interval', $interval, $this->ID); |
|
| 332 | 332 | |
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | public function is_free() { |
| 336 | 336 | $is_free = false; |
| 337 | 337 | |
| 338 | - $price = get_post_meta( $this->ID, '_wpinv_price', true ); |
|
| 338 | + $price = get_post_meta($this->ID, '_wpinv_price', true); |
|
| 339 | 339 | |
| 340 | - if ( (float)$price == 0 ) { |
|
| 340 | + if ((float)$price == 0) { |
|
| 341 | 341 | $is_free = true; |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | - return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID ); |
|
| 344 | + return (bool)apply_filters('wpinv_is_free_item', $is_free, $this->ID); |
|
| 345 | 345 | |
| 346 | 346 | } |
| 347 | 347 | |
| 348 | 348 | public function is_package() { |
| 349 | 349 | $is_package = $this->get_type() == 'package' ? true : false; |
| 350 | 350 | |
| 351 | - return (bool) apply_filters( 'wpinv_is_package_item', $is_package, $this->ID ); |
|
| 351 | + return (bool)apply_filters('wpinv_is_package_item', $is_package, $this->ID); |
|
| 352 | 352 | |
| 353 | 353 | } |
| 354 | 354 | |
| 355 | - public function save_metas( $metas = array() ) { |
|
| 356 | - if ( empty( $metas ) ) { |
|
| 355 | + public function save_metas($metas = array()) { |
|
| 356 | + if (empty($metas)) { |
|
| 357 | 357 | return false; |
| 358 | 358 | } |
| 359 | 359 | |
| 360 | - foreach ( $metas as $meta_key => $meta_value ) { |
|
| 360 | + foreach ($metas as $meta_key => $meta_value) { |
|
| 361 | 361 | $meta_key = strpos($meta_key, '_wpinv_') !== 0 ? '_wpinv_' . $meta_key : $meta_key; |
| 362 | 362 | |
| 363 | 363 | $this->update_meta($meta_key, $meta_value); |
@@ -366,66 +366,66 @@ discard block |
||
| 366 | 366 | return true; |
| 367 | 367 | } |
| 368 | 368 | |
| 369 | - public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) { |
|
| 370 | - if ( empty( $meta_key ) ) { |
|
| 369 | + public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') { |
|
| 370 | + if (empty($meta_key)) { |
|
| 371 | 371 | return false; |
| 372 | 372 | } |
| 373 | 373 | |
| 374 | - $meta_value = apply_filters( 'wpinv_update_item_meta_' . $meta_key, $meta_value, $this->ID ); |
|
| 374 | + $meta_value = apply_filters('wpinv_update_item_meta_' . $meta_key, $meta_value, $this->ID); |
|
| 375 | 375 | |
| 376 | - return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value ); |
|
| 376 | + return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value); |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | - public function get_fees( $type = 'fee', $item_id = 0 ) { |
|
| 379 | + public function get_fees($type = 'fee', $item_id = 0) { |
|
| 380 | 380 | global $wpi_session; |
| 381 | 381 | |
| 382 | - $fees = $wpi_session->get( 'wpi_cart_fees' ); |
|
| 382 | + $fees = $wpi_session->get('wpi_cart_fees'); |
|
| 383 | 383 | |
| 384 | - if ( ! wpinv_get_cart_contents() ) { |
|
| 384 | + if (!wpinv_get_cart_contents()) { |
|
| 385 | 385 | // We can only get item type fees when the cart is empty |
| 386 | 386 | $type = 'custom'; |
| 387 | 387 | } |
| 388 | 388 | |
| 389 | - if ( ! empty( $fees ) && ! empty( $type ) && 'all' !== $type ) { |
|
| 390 | - foreach( $fees as $key => $fee ) { |
|
| 391 | - if( ! empty( $fee['type'] ) && $type != $fee['type'] ) { |
|
| 392 | - unset( $fees[ $key ] ); |
|
| 389 | + if (!empty($fees) && !empty($type) && 'all' !== $type) { |
|
| 390 | + foreach ($fees as $key => $fee) { |
|
| 391 | + if (!empty($fee['type']) && $type != $fee['type']) { |
|
| 392 | + unset($fees[$key]); |
|
| 393 | 393 | } |
| 394 | 394 | } |
| 395 | 395 | } |
| 396 | 396 | |
| 397 | - if ( ! empty( $fees ) && ! empty( $item_id ) ) { |
|
| 397 | + if (!empty($fees) && !empty($item_id)) { |
|
| 398 | 398 | // Remove fees that don't belong to the specified Item |
| 399 | - foreach ( $fees as $key => $fee ) { |
|
| 400 | - if ( (int) $item_id !== (int)$fee['custom_id'] ) { |
|
| 401 | - unset( $fees[ $key ] ); |
|
| 399 | + foreach ($fees as $key => $fee) { |
|
| 400 | + if ((int)$item_id !== (int)$fee['custom_id']) { |
|
| 401 | + unset($fees[$key]); |
|
| 402 | 402 | } |
| 403 | 403 | } |
| 404 | 404 | } |
| 405 | 405 | |
| 406 | - if ( ! empty( $fees ) ) { |
|
| 406 | + if (!empty($fees)) { |
|
| 407 | 407 | // Remove fees that belong to a specific item but are not in the cart |
| 408 | - foreach( $fees as $key => $fee ) { |
|
| 409 | - if( empty( $fee['custom_id'] ) ) { |
|
| 408 | + foreach ($fees as $key => $fee) { |
|
| 409 | + if (empty($fee['custom_id'])) { |
|
| 410 | 410 | continue; |
| 411 | 411 | } |
| 412 | 412 | |
| 413 | - if ( !wpinv_item_in_cart( $fee['custom_id'] ) ) { |
|
| 414 | - unset( $fees[ $key ] ); |
|
| 413 | + if (!wpinv_item_in_cart($fee['custom_id'])) { |
|
| 414 | + unset($fees[$key]); |
|
| 415 | 415 | } |
| 416 | 416 | } |
| 417 | 417 | } |
| 418 | 418 | |
| 419 | - return ! empty( $fees ) ? $fees : array(); |
|
| 419 | + return !empty($fees) ? $fees : array(); |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | public function can_purchase() { |
| 423 | 423 | $can_purchase = true; |
| 424 | 424 | |
| 425 | - if ( !current_user_can( 'edit_post', $this->ID ) && $this->post_status != 'publish' ) { |
|
| 425 | + if (!current_user_can('edit_post', $this->ID) && $this->post_status != 'publish') { |
|
| 426 | 426 | $can_purchase = false; |
| 427 | 427 | } |
| 428 | 428 | |
| 429 | - return (bool)apply_filters( 'wpinv_can_purchase_item', $can_purchase, $this ); |
|
| 429 | + return (bool)apply_filters('wpinv_can_purchase_item', $can_purchase, $this); |
|
| 430 | 430 | } |
| 431 | 431 | } |
@@ -7,195 +7,195 @@ discard block |
||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | // MUST have WordPress. |
| 10 | -if ( !defined( 'WPINC' ) ) { |
|
| 11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
| 10 | +if (!defined('WPINC')) { |
|
| 11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | function wpinv_is_checkout() { |
| 15 | 15 | global $wp_query; |
| 16 | 16 | |
| 17 | - $is_object_set = isset( $wp_query->queried_object ); |
|
| 18 | - $is_object_id_set = isset( $wp_query->queried_object_id ); |
|
| 19 | - $is_checkout = is_page( wpinv_get_option( 'checkout_page' ) ); |
|
| 17 | + $is_object_set = isset($wp_query->queried_object); |
|
| 18 | + $is_object_id_set = isset($wp_query->queried_object_id); |
|
| 19 | + $is_checkout = is_page(wpinv_get_option('checkout_page')); |
|
| 20 | 20 | |
| 21 | - if ( !$is_object_set ) { |
|
| 22 | - unset( $wp_query->queried_object ); |
|
| 21 | + if (!$is_object_set) { |
|
| 22 | + unset($wp_query->queried_object); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - if ( !$is_object_id_set ) { |
|
| 26 | - unset( $wp_query->queried_object_id ); |
|
| 25 | + if (!$is_object_id_set) { |
|
| 26 | + unset($wp_query->queried_object_id); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - return apply_filters( 'wpinv_is_checkout', $is_checkout ); |
|
| 29 | + return apply_filters('wpinv_is_checkout', $is_checkout); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | function wpinv_can_checkout() { |
| 33 | 33 | $can_checkout = true; // Always true for now |
| 34 | 34 | |
| 35 | - return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout ); |
|
| 35 | + return (bool)apply_filters('wpinv_can_checkout', $can_checkout); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | function wpinv_get_success_page_uri() { |
| 39 | - $page_id = wpinv_get_option( 'success_page', 0 ); |
|
| 40 | - $page_id = absint( $page_id ); |
|
| 39 | + $page_id = wpinv_get_option('success_page', 0); |
|
| 40 | + $page_id = absint($page_id); |
|
| 41 | 41 | |
| 42 | - return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) ); |
|
| 42 | + return apply_filters('wpinv_get_success_page_uri', get_permalink($page_id)); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | function wpinv_get_history_page_uri() { |
| 46 | - $page_id = wpinv_get_option( 'invoice_history_page', 0 ); |
|
| 47 | - $page_id = absint( $page_id ); |
|
| 46 | + $page_id = wpinv_get_option('invoice_history_page', 0); |
|
| 47 | + $page_id = absint($page_id); |
|
| 48 | 48 | |
| 49 | - return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ) ); |
|
| 49 | + return apply_filters('wpinv_get_history_page_uri', get_permalink($page_id)); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | function wpinv_is_success_page() { |
| 53 | - $is_success_page = wpinv_get_option( 'success_page', false ); |
|
| 54 | - $is_success_page = isset( $is_success_page ) ? is_page( $is_success_page ) : false; |
|
| 53 | + $is_success_page = wpinv_get_option('success_page', false); |
|
| 54 | + $is_success_page = isset($is_success_page) ? is_page($is_success_page) : false; |
|
| 55 | 55 | |
| 56 | - return apply_filters( 'wpinv_is_success_page', $is_success_page ); |
|
| 56 | + return apply_filters('wpinv_is_success_page', $is_success_page); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | function wpinv_is_invoice_history_page() { |
| 60 | - $ret = wpinv_get_option( 'invoice_history_page', false ); |
|
| 61 | - $ret = $ret ? is_page( $ret ) : false; |
|
| 62 | - return apply_filters( 'wpinv_is_invoice_history_page', $ret ); |
|
| 60 | + $ret = wpinv_get_option('invoice_history_page', false); |
|
| 61 | + $ret = $ret ? is_page($ret) : false; |
|
| 62 | + return apply_filters('wpinv_is_invoice_history_page', $ret); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | -function wpinv_send_to_success_page( $args = null ) { |
|
| 65 | +function wpinv_send_to_success_page($args = null) { |
|
| 66 | 66 | $redirect = wpinv_get_success_page_uri(); |
| 67 | 67 | |
| 68 | - if ( !empty( $args ) ) { |
|
| 68 | + if (!empty($args)) { |
|
| 69 | 69 | // Check for backward compatibility |
| 70 | - if ( is_string( $args ) ) |
|
| 71 | - $args = str_replace( '?', '', $args ); |
|
| 70 | + if (is_string($args)) |
|
| 71 | + $args = str_replace('?', '', $args); |
|
| 72 | 72 | |
| 73 | - $args = wp_parse_args( $args ); |
|
| 73 | + $args = wp_parse_args($args); |
|
| 74 | 74 | |
| 75 | - $redirect = add_query_arg( $args, $redirect ); |
|
| 75 | + $redirect = add_query_arg($args, $redirect); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - $gateway = isset( $_REQUEST['wpi-gateway'] ) ? $_REQUEST['wpi-gateway'] : ''; |
|
| 78 | + $gateway = isset($_REQUEST['wpi-gateway']) ? $_REQUEST['wpi-gateway'] : ''; |
|
| 79 | 79 | |
| 80 | - $redirect = apply_filters( 'wpinv_success_page_redirect', $redirect, $gateway, $args ); |
|
| 81 | - wp_redirect( $redirect ); |
|
| 80 | + $redirect = apply_filters('wpinv_success_page_redirect', $redirect, $gateway, $args); |
|
| 81 | + wp_redirect($redirect); |
|
| 82 | 82 | exit; |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | -function wpinv_send_to_failed_page( $args = null ) { |
|
| 85 | +function wpinv_send_to_failed_page($args = null) { |
|
| 86 | 86 | $redirect = wpinv_get_failed_transaction_uri(); |
| 87 | 87 | |
| 88 | - if ( !empty( $args ) ) { |
|
| 88 | + if (!empty($args)) { |
|
| 89 | 89 | // Check for backward compatibility |
| 90 | - if ( is_string( $args ) ) |
|
| 91 | - $args = str_replace( '?', '', $args ); |
|
| 90 | + if (is_string($args)) |
|
| 91 | + $args = str_replace('?', '', $args); |
|
| 92 | 92 | |
| 93 | - $args = wp_parse_args( $args ); |
|
| 93 | + $args = wp_parse_args($args); |
|
| 94 | 94 | |
| 95 | - $redirect = add_query_arg( $args, $redirect ); |
|
| 95 | + $redirect = add_query_arg($args, $redirect); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - $gateway = isset( $_REQUEST['wpi-gateway'] ) ? $_REQUEST['wpi-gateway'] : ''; |
|
| 98 | + $gateway = isset($_REQUEST['wpi-gateway']) ? $_REQUEST['wpi-gateway'] : ''; |
|
| 99 | 99 | |
| 100 | - $redirect = apply_filters( 'wpinv_failed_page_redirect', $redirect, $gateway, $args ); |
|
| 101 | - wp_redirect( $redirect ); |
|
| 100 | + $redirect = apply_filters('wpinv_failed_page_redirect', $redirect, $gateway, $args); |
|
| 101 | + wp_redirect($redirect); |
|
| 102 | 102 | exit; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | -function wpinv_get_checkout_uri( $args = array() ) { |
|
| 106 | - $uri = wpinv_get_option( 'checkout_page', false ); |
|
| 107 | - $uri = isset( $uri ) ? get_permalink( $uri ) : NULL; |
|
| 105 | +function wpinv_get_checkout_uri($args = array()) { |
|
| 106 | + $uri = wpinv_get_option('checkout_page', false); |
|
| 107 | + $uri = isset($uri) ? get_permalink($uri) : NULL; |
|
| 108 | 108 | |
| 109 | - if ( !empty( $args ) ) { |
|
| 109 | + if (!empty($args)) { |
|
| 110 | 110 | // Check for backward compatibility |
| 111 | - if ( is_string( $args ) ) |
|
| 112 | - $args = str_replace( '?', '', $args ); |
|
| 111 | + if (is_string($args)) |
|
| 112 | + $args = str_replace('?', '', $args); |
|
| 113 | 113 | |
| 114 | - $args = wp_parse_args( $args ); |
|
| 114 | + $args = wp_parse_args($args); |
|
| 115 | 115 | |
| 116 | - $uri = add_query_arg( $args, $uri ); |
|
| 116 | + $uri = add_query_arg($args, $uri); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
| 119 | + $scheme = defined('FORCE_SSL_ADMIN') && FORCE_SSL_ADMIN ? 'https' : 'admin'; |
|
| 120 | 120 | |
| 121 | - $ajax_url = admin_url( 'admin-ajax.php', $scheme ); |
|
| 121 | + $ajax_url = admin_url('admin-ajax.php', $scheme); |
|
| 122 | 122 | |
| 123 | - if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) { |
|
| 124 | - $uri = preg_replace( '/^http:/', 'https:', $uri ); |
|
| 123 | + if ((!preg_match('/^https/', $uri) && preg_match('/^https/', $ajax_url)) || wpinv_is_ssl_enforced()) { |
|
| 124 | + $uri = preg_replace('/^http:/', 'https:', $uri); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - return apply_filters( 'wpinv_get_checkout_uri', $uri ); |
|
| 127 | + return apply_filters('wpinv_get_checkout_uri', $uri); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | -function wpinv_send_back_to_checkout( $args = array() ) { |
|
| 130 | +function wpinv_send_back_to_checkout($args = array()) { |
|
| 131 | 131 | $redirect = wpinv_get_checkout_uri(); |
| 132 | 132 | |
| 133 | - if ( ! empty( $args ) ) { |
|
| 133 | + if (!empty($args)) { |
|
| 134 | 134 | // Check for backward compatibility |
| 135 | - if ( is_string( $args ) ) |
|
| 136 | - $args = str_replace( '?', '', $args ); |
|
| 135 | + if (is_string($args)) |
|
| 136 | + $args = str_replace('?', '', $args); |
|
| 137 | 137 | |
| 138 | - $args = wp_parse_args( $args ); |
|
| 138 | + $args = wp_parse_args($args); |
|
| 139 | 139 | |
| 140 | - $redirect = add_query_arg( $args, $redirect ); |
|
| 140 | + $redirect = add_query_arg($args, $redirect); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - wp_redirect( apply_filters( 'wpinv_send_back_to_checkout', $redirect, $args ) ); |
|
| 143 | + wp_redirect(apply_filters('wpinv_send_back_to_checkout', $redirect, $args)); |
|
| 144 | 144 | exit; |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | -function wpinv_get_success_page_url( $query_string = null ) { |
|
| 148 | - $success_page = wpinv_get_option( 'success_page', 0 ); |
|
| 149 | - $success_page = get_permalink( $success_page ); |
|
| 147 | +function wpinv_get_success_page_url($query_string = null) { |
|
| 148 | + $success_page = wpinv_get_option('success_page', 0); |
|
| 149 | + $success_page = get_permalink($success_page); |
|
| 150 | 150 | |
| 151 | - if ( $query_string ) |
|
| 151 | + if ($query_string) |
|
| 152 | 152 | $success_page .= $query_string; |
| 153 | 153 | |
| 154 | - return apply_filters( 'wpinv_success_page_url', $success_page ); |
|
| 154 | + return apply_filters('wpinv_success_page_url', $success_page); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | -function wpinv_get_failed_transaction_uri( $extras = false ) { |
|
| 158 | - $uri = wpinv_get_option( 'failure_page', '' ); |
|
| 159 | - $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url(); |
|
| 157 | +function wpinv_get_failed_transaction_uri($extras = false) { |
|
| 158 | + $uri = wpinv_get_option('failure_page', ''); |
|
| 159 | + $uri = !empty($uri) ? trailingslashit(get_permalink($uri)) : home_url(); |
|
| 160 | 160 | |
| 161 | - if ( $extras ) |
|
| 161 | + if ($extras) |
|
| 162 | 162 | $uri .= $extras; |
| 163 | 163 | |
| 164 | - return apply_filters( 'wpinv_get_failed_transaction_uri', $uri ); |
|
| 164 | + return apply_filters('wpinv_get_failed_transaction_uri', $uri); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | function wpinv_is_failed_transaction_page() { |
| 168 | - $ret = wpinv_get_option( 'failure_page', false ); |
|
| 169 | - $ret = isset( $ret ) ? is_page( $ret ) : false; |
|
| 168 | + $ret = wpinv_get_option('failure_page', false); |
|
| 169 | + $ret = isset($ret) ? is_page($ret) : false; |
|
| 170 | 170 | |
| 171 | - return apply_filters( 'wpinv_is_failure_page', $ret ); |
|
| 171 | + return apply_filters('wpinv_is_failure_page', $ret); |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | -function wpinv_transaction_query( $type = 'start' ) { |
|
| 174 | +function wpinv_transaction_query($type = 'start') { |
|
| 175 | 175 | global $wpdb; |
| 176 | 176 | |
| 177 | 177 | $wpdb->hide_errors(); |
| 178 | 178 | |
| 179 | - if ( ! defined( 'WPINV_USE_TRANSACTIONS' ) ) { |
|
| 180 | - define( 'WPINV_USE_TRANSACTIONS', true ); |
|
| 179 | + if (!defined('WPINV_USE_TRANSACTIONS')) { |
|
| 180 | + define('WPINV_USE_TRANSACTIONS', true); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | - if ( WPINV_USE_TRANSACTIONS ) { |
|
| 184 | - switch ( $type ) { |
|
| 183 | + if (WPINV_USE_TRANSACTIONS) { |
|
| 184 | + switch ($type) { |
|
| 185 | 185 | case 'commit' : |
| 186 | - $wpdb->query( 'COMMIT' ); |
|
| 186 | + $wpdb->query('COMMIT'); |
|
| 187 | 187 | break; |
| 188 | 188 | case 'rollback' : |
| 189 | - $wpdb->query( 'ROLLBACK' ); |
|
| 189 | + $wpdb->query('ROLLBACK'); |
|
| 190 | 190 | break; |
| 191 | 191 | default : |
| 192 | - $wpdb->query( 'START TRANSACTION' ); |
|
| 192 | + $wpdb->query('START TRANSACTION'); |
|
| 193 | 193 | break; |
| 194 | 194 | } |
| 195 | 195 | } |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | -function wpinv_create_invoice( $args = array(), $data = array(), $wp_error = false ) { |
|
| 198 | +function wpinv_create_invoice($args = array(), $data = array(), $wp_error = false) { |
|
| 199 | 199 | $default_args = array( |
| 200 | 200 | 'status' => '', |
| 201 | 201 | 'user_id' => null, |
@@ -205,72 +205,72 @@ discard block |
||
| 205 | 205 | 'parent' => 0 |
| 206 | 206 | ); |
| 207 | 207 | |
| 208 | - $args = wp_parse_args( $args, $default_args ); |
|
| 208 | + $args = wp_parse_args($args, $default_args); |
|
| 209 | 209 | $invoice_data = array(); |
| 210 | 210 | |
| 211 | - if ( $args['invoice_id'] > 0 ) { |
|
| 212 | - $updating = true; |
|
| 211 | + if ($args['invoice_id'] > 0) { |
|
| 212 | + $updating = true; |
|
| 213 | 213 | $invoice_data['post_type'] = 'wpi_invoice'; |
| 214 | 214 | $invoice_data['ID'] = $args['invoice_id']; |
| 215 | 215 | } else { |
| 216 | 216 | $updating = false; |
| 217 | 217 | $invoice_data['post_type'] = 'wpi_invoice'; |
| 218 | - $invoice_data['post_status'] = apply_filters( 'wpinv_default_invoice_status', 'pending' ); |
|
| 218 | + $invoice_data['post_status'] = apply_filters('wpinv_default_invoice_status', 'pending'); |
|
| 219 | 219 | $invoice_data['ping_status'] = 'closed'; |
| 220 | - $invoice_data['post_author'] = !empty( $args['user_id'] ) ? $args['user_id'] : get_current_user_id(); |
|
| 221 | - $invoice_data['post_title'] = wpinv_format_invoice_number( '0' ); |
|
| 222 | - $invoice_data['post_parent'] = absint( $args['parent'] ); |
|
| 223 | - if ( !empty( $args['created_date'] ) ) { |
|
| 220 | + $invoice_data['post_author'] = !empty($args['user_id']) ? $args['user_id'] : get_current_user_id(); |
|
| 221 | + $invoice_data['post_title'] = wpinv_format_invoice_number('0'); |
|
| 222 | + $invoice_data['post_parent'] = absint($args['parent']); |
|
| 223 | + if (!empty($args['created_date'])) { |
|
| 224 | 224 | $invoice_data['post_date'] = $args['created_date']; |
| 225 | - $invoice_data['post_date_gmt'] = get_gmt_from_date( $args['created_date'] ); |
|
| 225 | + $invoice_data['post_date_gmt'] = get_gmt_from_date($args['created_date']); |
|
| 226 | 226 | } |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | - if ( $args['status'] ) { |
|
| 230 | - if ( ! in_array( $args['status'], array_keys( wpinv_get_invoice_statuses() ) ) ) { |
|
| 231 | - return new WP_Error( 'wpinv_invalid_invoice_status', wp_sprintf( __( 'Invalid invoice status: %s', 'invoicing' ), $args['status'] ) ); |
|
| 229 | + if ($args['status']) { |
|
| 230 | + if (!in_array($args['status'], array_keys(wpinv_get_invoice_statuses()))) { |
|
| 231 | + return new WP_Error('wpinv_invalid_invoice_status', wp_sprintf(__('Invalid invoice status: %s', 'invoicing'), $args['status'])); |
|
| 232 | 232 | } |
| 233 | - $invoice_data['post_status'] = $args['status']; |
|
| 233 | + $invoice_data['post_status'] = $args['status']; |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | - if ( ! is_null( $args['user_note'] ) ) { |
|
| 237 | - $invoice_data['post_excerpt'] = $args['user_note']; |
|
| 236 | + if (!is_null($args['user_note'])) { |
|
| 237 | + $invoice_data['post_excerpt'] = $args['user_note']; |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | - if ( $updating ) { |
|
| 241 | - $invoice_id = wp_update_post( $invoice_data, true ); |
|
| 240 | + if ($updating) { |
|
| 241 | + $invoice_id = wp_update_post($invoice_data, true); |
|
| 242 | 242 | } else { |
| 243 | - $invoice_id = wp_insert_post( apply_filters( 'wpinv_new_invoice_data', $invoice_data ), true ); |
|
| 243 | + $invoice_id = wp_insert_post(apply_filters('wpinv_new_invoice_data', $invoice_data), true); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | - if ( is_wp_error( $invoice_id ) ) { |
|
| 246 | + if (is_wp_error($invoice_id)) { |
|
| 247 | 247 | return $wp_error ? $invoice_id : 0; |
| 248 | 248 | } else { |
| 249 | - if ( !$updating ) { |
|
| 250 | - $invoice_number = wpinv_format_invoice_number( $invoice_id ); |
|
| 249 | + if (!$updating) { |
|
| 250 | + $invoice_number = wpinv_format_invoice_number($invoice_id); |
|
| 251 | 251 | |
| 252 | - $update = array( 'ID' => $invoice_id, 'post_title' => $invoice_number, 'post_name' => sanitize_title( $invoice_number ) ); |
|
| 253 | - wp_update_post( $update ); |
|
| 252 | + $update = array('ID' => $invoice_id, 'post_title' => $invoice_number, 'post_name' => sanitize_title($invoice_number)); |
|
| 253 | + wp_update_post($update); |
|
| 254 | 254 | |
| 255 | - update_post_meta( $invoice_id, '_wpinv_number', $invoice_number ); |
|
| 255 | + update_post_meta($invoice_id, '_wpinv_number', $invoice_number); |
|
| 256 | 256 | } |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 260 | - |
|
| 261 | - if ( !$updating ) { |
|
| 262 | - update_post_meta( $invoice_id, '_wpinv_key', apply_filters( 'wpinv_generate_invoice_key', uniqid( 'wpinv_' ) ) ); |
|
| 263 | - update_post_meta( $invoice_id, '_wpinv_currency', wpinv_get_currency() ); |
|
| 264 | - update_post_meta( $invoice_id, '_wpinv_include_tax', get_option( 'wpinv_prices_include_tax' ) ); |
|
| 265 | - update_post_meta( $invoice_id, '_wpinv_user_ip', wpinv_get_ip() ); |
|
| 266 | - update_post_meta( $invoice_id, '_wpinv_user_agent', wpinv_get_user_agent() ); |
|
| 267 | - update_post_meta( $invoice_id, '_wpinv_created_via', sanitize_text_field( $args['created_via'] ) ); |
|
| 259 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 260 | + |
|
| 261 | + if (!$updating) { |
|
| 262 | + update_post_meta($invoice_id, '_wpinv_key', apply_filters('wpinv_generate_invoice_key', uniqid('wpinv_'))); |
|
| 263 | + update_post_meta($invoice_id, '_wpinv_currency', wpinv_get_currency()); |
|
| 264 | + update_post_meta($invoice_id, '_wpinv_include_tax', get_option('wpinv_prices_include_tax')); |
|
| 265 | + update_post_meta($invoice_id, '_wpinv_user_ip', wpinv_get_ip()); |
|
| 266 | + update_post_meta($invoice_id, '_wpinv_user_agent', wpinv_get_user_agent()); |
|
| 267 | + update_post_meta($invoice_id, '_wpinv_created_via', sanitize_text_field($args['created_via'])); |
|
| 268 | 268 | |
| 269 | 269 | // Add invoice note |
| 270 | - $invoice->add_note( wp_sprintf( __( 'Invoice is created with status %s.', 'invoicing' ), wpinv_status_nicename( $invoice->status ) ) ); |
|
| 270 | + $invoice->add_note(wp_sprintf(__('Invoice is created with status %s.', 'invoicing'), wpinv_status_nicename($invoice->status))); |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | - update_post_meta( $invoice_id, '_wpinv_version', WPINV_VERSION ); |
|
| 273 | + update_post_meta($invoice_id, '_wpinv_version', WPINV_VERSION); |
|
| 274 | 274 | |
| 275 | 275 | return $invoice; |
| 276 | 276 | } |
@@ -278,118 +278,118 @@ discard block |
||
| 278 | 278 | function wpinv_get_prefix() { |
| 279 | 279 | $invoice_prefix = 'INV-'; |
| 280 | 280 | |
| 281 | - return apply_filters( 'wpinv_get_prefix', $invoice_prefix ); |
|
| 281 | + return apply_filters('wpinv_get_prefix', $invoice_prefix); |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | function wpinv_get_business_logo() { |
| 285 | - $business_logo = wpinv_get_option( 'logo' ); |
|
| 286 | - return apply_filters( 'wpinv_get_business_logo', $business_logo ); |
|
| 285 | + $business_logo = wpinv_get_option('logo'); |
|
| 286 | + return apply_filters('wpinv_get_business_logo', $business_logo); |
|
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | function wpinv_get_business_name() { |
| 290 | 290 | $business_name = wpinv_get_option('store_name'); |
| 291 | - return apply_filters( 'wpinv_get_business_name', $business_name ); |
|
| 291 | + return apply_filters('wpinv_get_business_name', $business_name); |
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | function wpinv_get_blogname() { |
| 295 | - return wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); |
|
| 295 | + return wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | 298 | function wpinv_get_admin_email() { |
| 299 | - $admin_email = get_option( 'admin_email' ); |
|
| 300 | - return apply_filters( 'wpinv_admin_email', $admin_email ); |
|
| 299 | + $admin_email = get_option('admin_email'); |
|
| 300 | + return apply_filters('wpinv_admin_email', $admin_email); |
|
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | function wpinv_get_business_website() { |
| 304 | - $business_website = home_url( '/' ); |
|
| 305 | - return apply_filters( 'wpinv_get_business_website', $business_website ); |
|
| 304 | + $business_website = home_url('/'); |
|
| 305 | + return apply_filters('wpinv_get_business_website', $business_website); |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | -function wpinv_get_terms_text( $invoice_id = 0 ) { |
|
| 308 | +function wpinv_get_terms_text($invoice_id = 0) { |
|
| 309 | 309 | $terms_text = ''; |
| 310 | - return apply_filters( 'wpinv_get_terms_text', $terms_text, $invoice_id ); |
|
| 310 | + return apply_filters('wpinv_get_terms_text', $terms_text, $invoice_id); |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | function wpinv_get_business_footer() { |
| 314 | - $site_link = '<a target="_blank" href="' . esc_url( wpinv_get_business_website() ) . '">' . esc_html( wpinv_get_business_name() ) . '</a>'; |
|
| 315 | - $business_footer = wp_sprintf( __( 'Thanks for using %s', 'invoicing' ), $site_link ); |
|
| 316 | - return apply_filters( 'wpinv_get_business_footer', $business_footer ); |
|
| 314 | + $site_link = '<a target="_blank" href="' . esc_url(wpinv_get_business_website()) . '">' . esc_html(wpinv_get_business_name()) . '</a>'; |
|
| 315 | + $business_footer = wp_sprintf(__('Thanks for using %s', 'invoicing'), $site_link); |
|
| 316 | + return apply_filters('wpinv_get_business_footer', $business_footer); |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | function wpinv_checkout_required_fields() { |
| 320 | 320 | $required_fields = array(); |
| 321 | 321 | |
| 322 | 322 | // Let payment gateways and other extensions determine if address fields should be required |
| 323 | - $require_billing_details = apply_filters( 'wpinv_checkout_required_billing_details', wpinv_use_taxes() ); |
|
| 323 | + $require_billing_details = apply_filters('wpinv_checkout_required_billing_details', wpinv_use_taxes()); |
|
| 324 | 324 | |
| 325 | - if ( $require_billing_details ) { |
|
| 325 | + if ($require_billing_details) { |
|
| 326 | 326 | ///$required_fields['email'] = array( |
| 327 | 327 | ///'error_id' => 'invalid_email', |
| 328 | 328 | ///'error_message' => __( 'Please enter a valid email address', 'invoicing' ) |
| 329 | 329 | ///); |
| 330 | 330 | $required_fields['first_name'] = array( |
| 331 | 331 | 'error_id' => 'invalid_first_name', |
| 332 | - 'error_message' => __( 'Please enter your first name', 'invoicing' ) |
|
| 332 | + 'error_message' => __('Please enter your first name', 'invoicing') |
|
| 333 | 333 | ); |
| 334 | 334 | $required_fields['address'] = array( |
| 335 | 335 | 'error_id' => 'invalid_address', |
| 336 | - 'error_message' => __( 'Please enter your address', 'invoicing' ) |
|
| 336 | + 'error_message' => __('Please enter your address', 'invoicing') |
|
| 337 | 337 | ); |
| 338 | 338 | $required_fields['city'] = array( |
| 339 | 339 | 'error_id' => 'invalid_city', |
| 340 | - 'error_message' => __( 'Please enter your billing city', 'invoicing' ) |
|
| 340 | + 'error_message' => __('Please enter your billing city', 'invoicing') |
|
| 341 | 341 | ); |
| 342 | 342 | $required_fields['state'] = array( |
| 343 | 343 | 'error_id' => 'invalid_state', |
| 344 | - 'error_message' => __( 'Please enter billing state / province', 'invoicing' ) |
|
| 344 | + 'error_message' => __('Please enter billing state / province', 'invoicing') |
|
| 345 | 345 | ); |
| 346 | 346 | $required_fields['country'] = array( |
| 347 | 347 | 'error_id' => 'invalid_country', |
| 348 | - 'error_message' => __( 'Please select your billing country', 'invoicing' ) |
|
| 348 | + 'error_message' => __('Please select your billing country', 'invoicing') |
|
| 349 | 349 | ); |
| 350 | 350 | } |
| 351 | 351 | |
| 352 | - return apply_filters( 'wpinv_checkout_required_fields', $required_fields ); |
|
| 352 | + return apply_filters('wpinv_checkout_required_fields', $required_fields); |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | function wpinv_is_ssl_enforced() { |
| 356 | - $ssl_enforced = wpinv_get_option( 'enforce_ssl', false ); |
|
| 357 | - return (bool) apply_filters( 'wpinv_is_ssl_enforced', $ssl_enforced ); |
|
| 356 | + $ssl_enforced = wpinv_get_option('enforce_ssl', false); |
|
| 357 | + return (bool)apply_filters('wpinv_is_ssl_enforced', $ssl_enforced); |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | -function wpinv_user_can_print_invoice( $post ) { |
|
| 360 | +function wpinv_user_can_print_invoice($post) { |
|
| 361 | 361 | $allow = false; |
| 362 | 362 | |
| 363 | - if ( !( $user_id = get_current_user_id() ) ) { |
|
| 363 | + if (!($user_id = get_current_user_id())) { |
|
| 364 | 364 | return $allow; |
| 365 | 365 | } |
| 366 | 366 | |
| 367 | - if ( is_int( $post ) ) { |
|
| 368 | - $post = get_post( $post ); |
|
| 367 | + if (is_int($post)) { |
|
| 368 | + $post = get_post($post); |
|
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | // Allow to owner. |
| 372 | - if ( is_object( $post ) && !empty( $post->post_author ) && $post->post_author == $user_id ) { |
|
| 372 | + if (is_object($post) && !empty($post->post_author) && $post->post_author == $user_id) { |
|
| 373 | 373 | $allow = true; |
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | // Allow to admin user. |
| 377 | - if ( current_user_can( 'manage_options' ) ) { |
|
| 377 | + if (current_user_can('manage_options')) { |
|
| 378 | 378 | $allow = true; |
| 379 | 379 | } |
| 380 | 380 | |
| 381 | - return apply_filters( 'wpinv_can_print_invoice', $allow, $post ); |
|
| 381 | + return apply_filters('wpinv_can_print_invoice', $allow, $post); |
|
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | function wpinv_schedule_events() { |
| 385 | 385 | // hourly, daily and twicedaily |
| 386 | - if ( !wp_next_scheduled( 'wpinv_register_schedule_event_twicedaily' ) ) { |
|
| 387 | - wp_schedule_event( current_time( 'timestamp' ), 'twicedaily', 'wpinv_register_schedule_event_twicedaily' ); |
|
| 386 | + if (!wp_next_scheduled('wpinv_register_schedule_event_twicedaily')) { |
|
| 387 | + wp_schedule_event(current_time('timestamp'), 'twicedaily', 'wpinv_register_schedule_event_twicedaily'); |
|
| 388 | 388 | } |
| 389 | 389 | } |
| 390 | -add_action( 'wp', 'wpinv_schedule_events' ); |
|
| 390 | +add_action('wp', 'wpinv_schedule_events'); |
|
| 391 | 391 | |
| 392 | 392 | function wpinv_schedule_event_twicedaily() { |
| 393 | 393 | wpinv_email_payment_reminders(); |
| 394 | 394 | } |
| 395 | -add_action( 'wpinv_register_schedule_event_twicedaily', 'wpinv_schedule_event_twicedaily' ); |
|
| 396 | 395 | \ No newline at end of file |
| 396 | +add_action('wpinv_register_schedule_event_twicedaily', 'wpinv_schedule_event_twicedaily'); |
|
| 397 | 397 | \ No newline at end of file |
@@ -1,23 +1,23 @@ 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 | function wpinv_gd_active() { |
| 8 | - return (bool)defined( 'GEODIRECTORY_VERSION' ); |
|
| 8 | + return (bool)defined('GEODIRECTORY_VERSION'); |
|
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | function wpinv_pm_active() { |
| 12 | - return (bool)wpinv_gd_active() && (bool)defined( 'GEODIRPAYMENT_VERSION' ); |
|
| 12 | + return (bool)wpinv_gd_active() && (bool)defined('GEODIRPAYMENT_VERSION'); |
|
| 13 | 13 | } |
| 14 | 14 | |
| 15 | -function wpinv_is_gd_post_type( $post_type ) { |
|
| 15 | +function wpinv_is_gd_post_type($post_type) { |
|
| 16 | 16 | global $gd_posttypes; |
| 17 | 17 | |
| 18 | - $gd_posttypes = !empty( $gd_posttypes ) && is_array( $gd_posttypes ) ? $gd_posttypes : geodir_get_posttypes(); |
|
| 18 | + $gd_posttypes = !empty($gd_posttypes) && is_array($gd_posttypes) ? $gd_posttypes : geodir_get_posttypes(); |
|
| 19 | 19 | |
| 20 | - if ( !empty( $post_type ) && !empty( $gd_posttypes ) && in_array( $post_type, $gd_posttypes ) ) { |
|
| 20 | + if (!empty($post_type) && !empty($gd_posttypes) && in_array($post_type, $gd_posttypes)) { |
|
| 21 | 21 | return true; |
| 22 | 22 | } |
| 23 | 23 | |
@@ -29,10 +29,10 @@ discard block |
||
| 29 | 29 | return; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) { |
|
| 32 | + if (!(defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 33 | 33 | // Add fields for force upgrade |
| 34 | - if ( defined('INVOICE_TABLE') && !get_option('wpinv_gdp_column') ) { |
|
| 35 | - geodir_add_column_if_not_exist( INVOICE_TABLE, 'invoice_id', 'INT( 11 ) NOT NULL DEFAULT 0' ); |
|
| 34 | + if (defined('INVOICE_TABLE') && !get_option('wpinv_gdp_column')) { |
|
| 35 | + geodir_add_column_if_not_exist(INVOICE_TABLE, 'invoice_id', 'INT( 11 ) NOT NULL DEFAULT 0'); |
|
| 36 | 36 | |
| 37 | 37 | update_option('wpinv_gdp_column', '1'); |
| 38 | 38 | } |
@@ -40,39 +40,39 @@ discard block |
||
| 40 | 40 | wpinv_merge_gd_packages_to_items(); |
| 41 | 41 | } |
| 42 | 42 | } |
| 43 | -add_action( 'admin_init', 'wpinv_geodir_integration' ); |
|
| 43 | +add_action('admin_init', 'wpinv_geodir_integration'); |
|
| 44 | 44 | |
| 45 | -function wpinv_get_gdp_package_type( $item_types ) { |
|
| 46 | - if ( wpinv_pm_active() ) { |
|
| 47 | - $item_types['package'] = __( 'Package', 'invoicing' ); |
|
| 45 | +function wpinv_get_gdp_package_type($item_types) { |
|
| 46 | + if (wpinv_pm_active()) { |
|
| 47 | + $item_types['package'] = __('Package', 'invoicing'); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | return $item_types; |
| 51 | 51 | } |
| 52 | -add_filter( 'wpinv_get_item_types', 'wpinv_get_gdp_package_type', 10, 1 ); |
|
| 52 | +add_filter('wpinv_get_item_types', 'wpinv_get_gdp_package_type', 10, 1); |
|
| 53 | 53 | |
| 54 | 54 | function wpinv_update_package_item($package_id) { |
| 55 | 55 | return wpinv_merge_gd_package_to_item($package_id, true); |
| 56 | 56 | } |
| 57 | 57 | add_action('geodir_after_save_package', 'wpinv_update_package_item', 10, 1); |
| 58 | 58 | |
| 59 | -function wpinv_merge_gd_packages_to_items( $force = false ) { |
|
| 60 | - if ( $merged = get_option( 'wpinv_merge_gd_packages' ) && !$force ) { |
|
| 59 | +function wpinv_merge_gd_packages_to_items($force = false) { |
|
| 60 | + if ($merged = get_option('wpinv_merge_gd_packages') && !$force) { |
|
| 61 | 61 | return true; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - if(!function_exists('geodir_package_list_info')){ |
|
| 64 | + if (!function_exists('geodir_package_list_info')) { |
|
| 65 | 65 | return false; |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | $packages = geodir_package_list_info(); |
| 69 | 69 | |
| 70 | - foreach ( $packages as $key => $package ) { |
|
| 71 | - wpinv_merge_gd_package_to_item( $package->pid, $force, $package ); |
|
| 70 | + foreach ($packages as $key => $package) { |
|
| 71 | + wpinv_merge_gd_package_to_item($package->pid, $force, $package); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - if ( !$merged ) { |
|
| 75 | - update_option( 'wpinv_merge_gd_packages', 1 ); |
|
| 74 | + if (!$merged) { |
|
| 75 | + update_option('wpinv_merge_gd_packages', 1); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | return true; |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | |
| 102 | 102 | $package = empty($package) ? geodir_get_package_info_by_id($package_id, '') : $package; |
| 103 | 103 | |
| 104 | - if ( empty($package) || !wpinv_is_gd_post_type( $package->post_type ) ) { |
|
| 104 | + if (empty($package) || !wpinv_is_gd_post_type($package->post_type)) { |
|
| 105 | 105 | return false; |
| 106 | 106 | } |
| 107 | 107 | |
@@ -110,17 +110,17 @@ discard block |
||
| 110 | 110 | $meta['custom_id'] = $package_id; |
| 111 | 111 | $meta['custom_singular_name'] = get_post_type_singular_label($package->post_type); |
| 112 | 112 | $meta['custom_name'] = get_post_type_plural_label($package->post_type); |
| 113 | - $meta['price'] = wpinv_round_amount( $package->amount ); |
|
| 113 | + $meta['price'] = wpinv_round_amount($package->amount); |
|
| 114 | 114 | $meta['vat_rule'] = 'digital'; |
| 115 | 115 | $meta['vat_class'] = '_standard'; |
| 116 | 116 | |
| 117 | - if ( !empty( $package->sub_active ) ) { |
|
| 118 | - $sub_num_trial_days = absint( $package->sub_num_trial_days ); |
|
| 117 | + if (!empty($package->sub_active)) { |
|
| 118 | + $sub_num_trial_days = absint($package->sub_num_trial_days); |
|
| 119 | 119 | |
| 120 | 120 | $meta['is_recurring'] = 1; |
| 121 | 121 | $meta['recurring_period'] = $package->sub_units; |
| 122 | - $meta['recurring_interval'] = absint( $package->sub_units_num ); |
|
| 123 | - $meta['recurring_limit'] = absint( $package->sub_units_num_times ); |
|
| 122 | + $meta['recurring_interval'] = absint($package->sub_units_num); |
|
| 123 | + $meta['recurring_limit'] = absint($package->sub_units_num_times); |
|
| 124 | 124 | $meta['free_trial'] = $sub_num_trial_days > 0 ? 1 : 0; |
| 125 | 125 | $meta['trial_period'] = $package->sub_num_trial_units; |
| 126 | 126 | $meta['trial_interval'] = $sub_num_trial_days; |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | $meta['trial_interval'] = ''; |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - $data = array( |
|
| 137 | + $data = array( |
|
| 138 | 138 | 'post_title' => $package->title, |
| 139 | 139 | 'post_excerpt' => $package->title_desc, |
| 140 | 140 | 'post_status' => $package->status == 1 ? 'publish' : 'pending', |
@@ -151,48 +151,48 @@ discard block |
||
| 151 | 151 | return $item; |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | -function wpinv_gdp_to_wpi_gateway( $payment_method ) { |
|
| 155 | - switch( $payment_method ) { |
|
| 154 | +function wpinv_gdp_to_wpi_gateway($payment_method) { |
|
| 155 | + switch ($payment_method) { |
|
| 156 | 156 | case 'prebanktransfer': |
| 157 | 157 | $gateway = 'bank_transfer'; |
| 158 | 158 | break; |
| 159 | 159 | default: |
| 160 | - $gateway = empty( $payment_method ) ? 'manual' : $payment_method; |
|
| 160 | + $gateway = empty($payment_method) ? 'manual' : $payment_method; |
|
| 161 | 161 | break; |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | - return apply_filters( 'wpinv_gdp_to_wpi_gateway', $gateway, $payment_method ); |
|
| 164 | + return apply_filters('wpinv_gdp_to_wpi_gateway', $gateway, $payment_method); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | -function wpinv_gdp_to_wpi_gateway_title( $payment_method ) { |
|
| 168 | - $gateway = wpinv_gdp_to_wpi_gateway( $payment_method ); |
|
| 167 | +function wpinv_gdp_to_wpi_gateway_title($payment_method) { |
|
| 168 | + $gateway = wpinv_gdp_to_wpi_gateway($payment_method); |
|
| 169 | 169 | |
| 170 | - $gateway_title = wpinv_get_gateway_checkout_label( $gateway ); |
|
| 170 | + $gateway_title = wpinv_get_gateway_checkout_label($gateway); |
|
| 171 | 171 | |
| 172 | - if ( $gateway == $gateway_title ) { |
|
| 173 | - $gateway_title = geodir_payment_method_title( $gateway ); |
|
| 172 | + if ($gateway == $gateway_title) { |
|
| 173 | + $gateway_title = geodir_payment_method_title($gateway); |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - return apply_filters( 'wpinv_gdp_to_wpi_gateway_title', $gateway_title, $payment_method ); |
|
| 176 | + return apply_filters('wpinv_gdp_to_wpi_gateway_title', $gateway_title, $payment_method); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | function wpinv_print_checkout_errors() { |
| 180 | 180 | global $wpi_session; |
| 181 | 181 | wpinv_print_errors(); |
| 182 | 182 | } |
| 183 | -add_action( 'geodir_checkout_page_content', 'wpinv_print_checkout_errors', -10 ); |
|
| 183 | +add_action('geodir_checkout_page_content', 'wpinv_print_checkout_errors', -10); |
|
| 184 | 184 | |
| 185 | -function wpinv_cpt_save( $invoice_id, $update = false, $pre_status = NULL ) { |
|
| 185 | +function wpinv_cpt_save($invoice_id, $update = false, $pre_status = NULL) { |
|
| 186 | 186 | global $wpi_nosave, $wpi_zero_tax, $wpi_gdp_inv_merge; |
| 187 | 187 | |
| 188 | - $invoice_info = geodir_get_invoice( $invoice_id ); |
|
| 188 | + $invoice_info = geodir_get_invoice($invoice_id); |
|
| 189 | 189 | |
| 190 | - $wpi_invoice_id = !empty( $invoice_info->invoice_id ) ? $invoice_info->invoice_id : 0; |
|
| 190 | + $wpi_invoice_id = !empty($invoice_info->invoice_id) ? $invoice_info->invoice_id : 0; |
|
| 191 | 191 | |
| 192 | 192 | if (!empty($invoice_info)) { |
| 193 | - $wpi_invoice = $wpi_invoice_id > 0 ? wpinv_get_invoice( $wpi_invoice_id ) : NULL; |
|
| 193 | + $wpi_invoice = $wpi_invoice_id > 0 ? wpinv_get_invoice($wpi_invoice_id) : NULL; |
|
| 194 | 194 | |
| 195 | - if ( !empty( $wpi_invoice ) ) { // update invoice |
|
| 195 | + if (!empty($wpi_invoice)) { // update invoice |
|
| 196 | 196 | $save = false; |
| 197 | 197 | if ($invoice_info->coupon_code !== $wpi_invoice->discount_code || (float)$invoice_info->discount < (float)$wpi_invoice->discount || (float)$invoice_info->discount > (float)$wpi_invoice->discount) { |
| 198 | 198 | $save = true; |
@@ -202,16 +202,16 @@ discard block |
||
| 202 | 202 | |
| 203 | 203 | if ($invoice_info->paymentmethod !== $wpi_invoice->gateway) { |
| 204 | 204 | $save = true; |
| 205 | - $gateway = !empty( $invoice_info->paymentmethod ) ? $invoice_info->paymentmethod : ''; |
|
| 206 | - $gateway = wpinv_gdp_to_wpi_gateway( $gateway ); |
|
| 207 | - $gateway_title = wpinv_gdp_to_wpi_gateway_title( $gateway ); |
|
| 208 | - $wpi_invoice->set('gateway', $gateway ); |
|
| 209 | - $wpi_invoice->set('gateway_title', $gateway_title ); |
|
| 205 | + $gateway = !empty($invoice_info->paymentmethod) ? $invoice_info->paymentmethod : ''; |
|
| 206 | + $gateway = wpinv_gdp_to_wpi_gateway($gateway); |
|
| 207 | + $gateway_title = wpinv_gdp_to_wpi_gateway_title($gateway); |
|
| 208 | + $wpi_invoice->set('gateway', $gateway); |
|
| 209 | + $wpi_invoice->set('gateway_title', $gateway_title); |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | - if ( ( $status = wpinv_gdp_to_wpi_status( $invoice_info->status ) ) !== $wpi_invoice->status ) { |
|
| 212 | + if (($status = wpinv_gdp_to_wpi_status($invoice_info->status)) !== $wpi_invoice->status) { |
|
| 213 | 213 | $save = true; |
| 214 | - $wpi_invoice->set( 'status', $status ); |
|
| 214 | + $wpi_invoice->set('status', $status); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | if ($save) { |
@@ -222,16 +222,16 @@ discard block |
||
| 222 | 222 | |
| 223 | 223 | return $wpi_invoice; |
| 224 | 224 | } else { // create invoice |
| 225 | - $user_info = get_userdata( $invoice_info->user_id ); |
|
| 225 | + $user_info = get_userdata($invoice_info->user_id); |
|
| 226 | 226 | |
| 227 | - if ( !empty( $pre_status ) ) { |
|
| 227 | + if (!empty($pre_status)) { |
|
| 228 | 228 | $invoice_info->status = $pre_status; |
| 229 | 229 | } |
| 230 | - $status = wpinv_gdp_to_wpi_status( $invoice_info->status ); |
|
| 230 | + $status = wpinv_gdp_to_wpi_status($invoice_info->status); |
|
| 231 | 231 | |
| 232 | 232 | $wpi_zero_tax = false; |
| 233 | 233 | |
| 234 | - if ( $wpi_gdp_inv_merge && in_array( $status, array( 'publish', 'wpi-processing', 'wpi-renewal' ) ) ) { |
|
| 234 | + if ($wpi_gdp_inv_merge && in_array($status, array('publish', 'wpi-processing', 'wpi-renewal'))) { |
|
| 235 | 235 | $wpi_zero_tax = true; |
| 236 | 236 | } |
| 237 | 237 | |
@@ -241,13 +241,13 @@ discard block |
||
| 241 | 241 | $invoice_data['user_id'] = $invoice_info->user_id; |
| 242 | 242 | $invoice_data['created_via'] = 'API'; |
| 243 | 243 | |
| 244 | - if ( !empty( $invoice_info->date ) ) { |
|
| 245 | - $invoice_data['created_date'] = $invoice_info->date; |
|
| 244 | + if (!empty($invoice_info->date)) { |
|
| 245 | + $invoice_data['created_date'] = $invoice_info->date; |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | - $paymentmethod = !empty( $invoice_info->paymentmethod ) ? $invoice_info->paymentmethod : ''; |
|
| 249 | - $paymentmethod = wpinv_gdp_to_wpi_gateway( $paymentmethod ); |
|
| 250 | - $payment_method_title = wpinv_gdp_to_wpi_gateway_title( $paymentmethod ); |
|
| 248 | + $paymentmethod = !empty($invoice_info->paymentmethod) ? $invoice_info->paymentmethod : ''; |
|
| 249 | + $paymentmethod = wpinv_gdp_to_wpi_gateway($paymentmethod); |
|
| 250 | + $payment_method_title = wpinv_gdp_to_wpi_gateway_title($paymentmethod); |
|
| 251 | 251 | |
| 252 | 252 | $invoice_data['payment_details'] = array( |
| 253 | 253 | 'gateway' => $paymentmethod, |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | 'currency' => geodir_get_currency_type(), |
| 256 | 256 | ); |
| 257 | 257 | |
| 258 | - $user_address = wpinv_get_user_address( $invoice_info->user_id, false ); |
|
| 258 | + $user_address = wpinv_get_user_address($invoice_info->user_id, false); |
|
| 259 | 259 | |
| 260 | 260 | $invoice_data['user_info'] = array( |
| 261 | 261 | 'user_id' => $invoice_info->user_id, |
@@ -278,8 +278,8 @@ discard block |
||
| 278 | 278 | |
| 279 | 279 | $post_item = wpinv_get_gd_package_item($invoice_info->package_id); |
| 280 | 280 | |
| 281 | - if ( !empty( $post_item ) ) { |
|
| 282 | - $cart_details = array(); |
|
| 281 | + if (!empty($post_item)) { |
|
| 282 | + $cart_details = array(); |
|
| 283 | 283 | $cart_details[] = array( |
| 284 | 284 | 'id' => $post_item->ID, |
| 285 | 285 | 'name' => $post_item->get_name(), |
@@ -293,19 +293,19 @@ discard block |
||
| 293 | 293 | ), |
| 294 | 294 | ); |
| 295 | 295 | |
| 296 | - $invoice_data['cart_details'] = $cart_details; |
|
| 296 | + $invoice_data['cart_details'] = $cart_details; |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - $data = array( 'invoice' => $invoice_data ); |
|
| 299 | + $data = array('invoice' => $invoice_data); |
|
| 300 | 300 | |
| 301 | 301 | $wpinv_api = new WPInv_API(); |
| 302 | - $data = $wpinv_api->insert_invoice( $data ); |
|
| 302 | + $data = $wpinv_api->insert_invoice($data); |
|
| 303 | 303 | |
| 304 | - if ( is_wp_error( $data ) ) { |
|
| 305 | - wpinv_error_log( 'WPInv_Invoice: ' . $data->get_error_message() ); |
|
| 304 | + if (is_wp_error($data)) { |
|
| 305 | + wpinv_error_log('WPInv_Invoice: ' . $data->get_error_message()); |
|
| 306 | 306 | } else { |
| 307 | - if ( !empty( $data ) ) { |
|
| 308 | - update_post_meta( $data->ID, '_wpinv_gdp_id', $invoice_id ); |
|
| 307 | + if (!empty($data)) { |
|
| 308 | + update_post_meta($data->ID, '_wpinv_gdp_id', $invoice_id); |
|
| 309 | 309 | |
| 310 | 310 | $update_data = array(); |
| 311 | 311 | $update_data['tax_amount'] = $data->get_tax(); |
@@ -313,14 +313,14 @@ discard block |
||
| 313 | 313 | $update_data['invoice_id'] = $data->ID; |
| 314 | 314 | |
| 315 | 315 | global $wpdb; |
| 316 | - $wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $invoice_id ) ); |
|
| 316 | + $wpdb->update(INVOICE_TABLE, $update_data, array('id' => $invoice_id)); |
|
| 317 | 317 | |
| 318 | 318 | return $data; |
| 319 | 319 | } else { |
| 320 | - if ( $update ) { |
|
| 321 | - wpinv_error_log( 'WPInv_Invoice: ' . __( 'Fail to update invoice.', 'invoicing' ) ); |
|
| 320 | + if ($update) { |
|
| 321 | + wpinv_error_log('WPInv_Invoice: ' . __('Fail to update invoice.', 'invoicing')); |
|
| 322 | 322 | } else { |
| 323 | - wpinv_error_log( 'WPInv_Invoice: ' . __( 'Fail to create invoice.', 'invoicing' ) ); |
|
| 323 | + wpinv_error_log('WPInv_Invoice: ' . __('Fail to create invoice.', 'invoicing')); |
|
| 324 | 324 | } |
| 325 | 325 | } |
| 326 | 326 | } |
@@ -331,59 +331,59 @@ discard block |
||
| 331 | 331 | } |
| 332 | 332 | add_action('geodir_payment_invoice_created', 'wpinv_cpt_save', 11, 3); |
| 333 | 333 | |
| 334 | -function wpinv_cpt_update( $invoice_id ) { |
|
| 335 | - return wpinv_cpt_save( $invoice_id, true ); |
|
| 334 | +function wpinv_cpt_update($invoice_id) { |
|
| 335 | + return wpinv_cpt_save($invoice_id, true); |
|
| 336 | 336 | } |
| 337 | 337 | add_action('geodir_payment_invoice_updated', 'wpinv_cpt_update', 11, 1); |
| 338 | 338 | |
| 339 | -function wpinv_payment_status_changed( $invoice_id, $new_status, $old_status = 'pending', $subscription = false ) { |
|
| 340 | - $invoice_info = geodir_get_invoice( $invoice_id ); |
|
| 341 | - if ( empty( $invoice_info ) ) { |
|
| 339 | +function wpinv_payment_status_changed($invoice_id, $new_status, $old_status = 'pending', $subscription = false) { |
|
| 340 | + $invoice_info = geodir_get_invoice($invoice_id); |
|
| 341 | + if (empty($invoice_info)) { |
|
| 342 | 342 | return false; |
| 343 | 343 | } |
| 344 | 344 | |
| 345 | - $invoice = !empty( $invoice_info->invoice_id ) ? wpinv_get_invoice( $invoice_info->invoice_id ) : NULL; |
|
| 346 | - if ( !empty( $invoice ) ) { |
|
| 345 | + $invoice = !empty($invoice_info->invoice_id) ? wpinv_get_invoice($invoice_info->invoice_id) : NULL; |
|
| 346 | + if (!empty($invoice)) { |
|
| 347 | 347 | $new_status = wpinv_gdp_to_wpi_status($new_status); |
| 348 | - $invoice = wpinv_update_payment_status( $invoice->ID, $new_status ); |
|
| 348 | + $invoice = wpinv_update_payment_status($invoice->ID, $new_status); |
|
| 349 | 349 | } else { |
| 350 | - $invoice = wpinv_cpt_save( $invoice_id ); |
|
| 350 | + $invoice = wpinv_cpt_save($invoice_id); |
|
| 351 | 351 | } |
| 352 | 352 | |
| 353 | 353 | return $invoice; |
| 354 | 354 | } |
| 355 | -add_action( 'geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4 ); |
|
| 355 | +add_action('geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4); |
|
| 356 | 356 | |
| 357 | -function wpinv_transaction_details_note( $invoice_id, $html ) { |
|
| 358 | - $invoice_info = geodir_get_invoice( $invoice_id ); |
|
| 359 | - if ( empty( $invoice_info ) ) { |
|
| 357 | +function wpinv_transaction_details_note($invoice_id, $html) { |
|
| 358 | + $invoice_info = geodir_get_invoice($invoice_id); |
|
| 359 | + if (empty($invoice_info)) { |
|
| 360 | 360 | return false; |
| 361 | 361 | } |
| 362 | 362 | |
| 363 | - $wpi_invoice_id = !empty( $invoice_info->invoice_id ) ? $invoice_info->invoice_id : NULL; |
|
| 363 | + $wpi_invoice_id = !empty($invoice_info->invoice_id) ? $invoice_info->invoice_id : NULL; |
|
| 364 | 364 | |
| 365 | - if ( !$wpi_invoice_id ) { |
|
| 366 | - $invoice = wpinv_cpt_save( $invoice_id, false, $old_status ); |
|
| 365 | + if (!$wpi_invoice_id) { |
|
| 366 | + $invoice = wpinv_cpt_save($invoice_id, false, $old_status); |
|
| 367 | 367 | |
| 368 | - if ( !empty( $invoice ) ) { |
|
| 368 | + if (!empty($invoice)) { |
|
| 369 | 369 | $wpi_invoice_id = $invoice->ID; |
| 370 | 370 | } |
| 371 | 371 | } |
| 372 | 372 | |
| 373 | - $invoice = wpinv_get_invoice( $wpi_invoice_id ); |
|
| 373 | + $invoice = wpinv_get_invoice($wpi_invoice_id); |
|
| 374 | 374 | |
| 375 | - if ( empty( $invoice ) ) { |
|
| 375 | + if (empty($invoice)) { |
|
| 376 | 376 | return false; |
| 377 | 377 | } |
| 378 | 378 | |
| 379 | - return $invoice->add_note( $html, true ); |
|
| 379 | + return $invoice->add_note($html, true); |
|
| 380 | 380 | } |
| 381 | -add_action( 'geodir_payment_invoice_transaction_details_changed', 'wpinv_transaction_details_note', 11, 2 ); |
|
| 381 | +add_action('geodir_payment_invoice_transaction_details_changed', 'wpinv_transaction_details_note', 11, 2); |
|
| 382 | 382 | |
| 383 | -function wpinv_gdp_to_wpi_status( $status ) { |
|
| 383 | +function wpinv_gdp_to_wpi_status($status) { |
|
| 384 | 384 | $inv_status = $status ? $status : 'pending'; |
| 385 | 385 | |
| 386 | - switch ( $status ) { |
|
| 386 | + switch ($status) { |
|
| 387 | 387 | case 'confirmed': |
| 388 | 388 | $inv_status = 'publish'; |
| 389 | 389 | break; |
@@ -403,10 +403,10 @@ discard block |
||
| 403 | 403 | return $inv_status; |
| 404 | 404 | } |
| 405 | 405 | |
| 406 | -function wpinv_wpi_to_gdp_status( $status ) { |
|
| 406 | +function wpinv_wpi_to_gdp_status($status) { |
|
| 407 | 407 | $inv_status = $status ? $status : 'pending'; |
| 408 | 408 | |
| 409 | - switch ( $status ) { |
|
| 409 | + switch ($status) { |
|
| 410 | 410 | case 'publish': |
| 411 | 411 | case 'wpi-processing': |
| 412 | 412 | case 'wpi-renewal': |
@@ -429,72 +429,72 @@ discard block |
||
| 429 | 429 | return $inv_status; |
| 430 | 430 | } |
| 431 | 431 | |
| 432 | -function wpinv_wpi_to_gdp_id( $invoice_id ) { |
|
| 432 | +function wpinv_wpi_to_gdp_id($invoice_id) { |
|
| 433 | 433 | global $wpdb; |
| 434 | 434 | |
| 435 | - return $wpdb->get_var( $wpdb->prepare( "SELECT `id` FROM `" . INVOICE_TABLE . "` WHERE `invoice_id` = %d AND `invoice_id` > 0 ORDER BY id DESC LIMIT 1", array( (int)$invoice_id ) ) ); |
|
| 435 | + return $wpdb->get_var($wpdb->prepare("SELECT `id` FROM `" . INVOICE_TABLE . "` WHERE `invoice_id` = %d AND `invoice_id` > 0 ORDER BY id DESC LIMIT 1", array((int)$invoice_id))); |
|
| 436 | 436 | } |
| 437 | 437 | |
| 438 | -function wpinv_gdp_to_wpi_id( $invoice_id ) { |
|
| 439 | - $invoice = geodir_get_invoice( $invoice_id ); |
|
| 440 | - return ( empty( $invoice->invoice_id ) ? $invoice->invoice_id : false); |
|
| 438 | +function wpinv_gdp_to_wpi_id($invoice_id) { |
|
| 439 | + $invoice = geodir_get_invoice($invoice_id); |
|
| 440 | + return (empty($invoice->invoice_id) ? $invoice->invoice_id : false); |
|
| 441 | 441 | } |
| 442 | 442 | |
| 443 | -function wpinv_to_gdp_recalculate_total( $invoice, $wpi_nosave ) { |
|
| 443 | +function wpinv_to_gdp_recalculate_total($invoice, $wpi_nosave) { |
|
| 444 | 444 | global $wpdb; |
| 445 | 445 | |
| 446 | - if ( !empty( $wpi_nosave ) ) { |
|
| 446 | + if (!empty($wpi_nosave)) { |
|
| 447 | 447 | return; |
| 448 | 448 | } |
| 449 | 449 | |
| 450 | - $gdp_invoice_id = wpinv_wpi_to_gdp_id( $invoice->ID ); |
|
| 450 | + $gdp_invoice_id = wpinv_wpi_to_gdp_id($invoice->ID); |
|
| 451 | 451 | |
| 452 | - if ( $gdp_invoice_id > 0 ) { |
|
| 452 | + if ($gdp_invoice_id > 0) { |
|
| 453 | 453 | $update_data = array(); |
| 454 | 454 | $update_data['tax_amount'] = $invoice->tax; |
| 455 | 455 | $update_data['paied_amount'] = $invoice->total; |
| 456 | 456 | $update_data['discount'] = $invoice->discount; |
| 457 | 457 | $update_data['coupon_code'] = $invoice->discount_code; |
| 458 | 458 | |
| 459 | - $wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $gdp_invoice_id ) ); |
|
| 459 | + $wpdb->update(INVOICE_TABLE, $update_data, array('id' => $gdp_invoice_id)); |
|
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | return; |
| 463 | 463 | } |
| 464 | 464 | //add_action( 'wpinv_invoice_recalculate_total', 'wpinv_to_gdp_recalculate_total', 10, 2 ); |
| 465 | 465 | |
| 466 | -function wpinv_gdp_to_wpi_invoice( $invoice_id ) { |
|
| 467 | - $invoice = geodir_get_invoice( $invoice_id ); |
|
| 468 | - if ( empty( $invoice->invoice_id ) ) { |
|
| 466 | +function wpinv_gdp_to_wpi_invoice($invoice_id) { |
|
| 467 | + $invoice = geodir_get_invoice($invoice_id); |
|
| 468 | + if (empty($invoice->invoice_id)) { |
|
| 469 | 469 | return false; |
| 470 | 470 | } |
| 471 | 471 | |
| 472 | - return wpinv_get_invoice( $invoice->invoice_id ); |
|
| 472 | + return wpinv_get_invoice($invoice->invoice_id); |
|
| 473 | 473 | } |
| 474 | 474 | |
| 475 | -function wpinv_payment_set_coupon_code( $status, $invoice_id, $coupon_code ) { |
|
| 476 | - $invoice = wpinv_gdp_to_wpi_invoice( $invoice_id ); |
|
| 477 | - if ( empty( $invoice ) ) { |
|
| 475 | +function wpinv_payment_set_coupon_code($status, $invoice_id, $coupon_code) { |
|
| 476 | + $invoice = wpinv_gdp_to_wpi_invoice($invoice_id); |
|
| 477 | + if (empty($invoice)) { |
|
| 478 | 478 | return $status; |
| 479 | 479 | } |
| 480 | 480 | |
| 481 | - if ( $status === 1 || $status === 0 ) { |
|
| 482 | - if ( $status === 1 ) { |
|
| 483 | - $discount = geodir_get_discount_amount( $coupon_code, $invoice->get_subtotal() ); |
|
| 481 | + if ($status === 1 || $status === 0) { |
|
| 482 | + if ($status === 1) { |
|
| 483 | + $discount = geodir_get_discount_amount($coupon_code, $invoice->get_subtotal()); |
|
| 484 | 484 | } else { |
| 485 | 485 | $discount = ''; |
| 486 | 486 | $coupon_code = ''; |
| 487 | 487 | } |
| 488 | 488 | |
| 489 | - $invoice->set( 'discount', $discount ); |
|
| 490 | - $invoice->set( 'discount_code', $coupon_code ); |
|
| 489 | + $invoice->set('discount', $discount); |
|
| 490 | + $invoice->set('discount_code', $coupon_code); |
|
| 491 | 491 | $invoice->save(); |
| 492 | 492 | $invoice->recalculate_total(); |
| 493 | 493 | } |
| 494 | 494 | |
| 495 | 495 | return $status; |
| 496 | 496 | } |
| 497 | -add_filter( 'geodir_payment_set_coupon_code', 'wpinv_payment_set_coupon_code', 10, 3 ); |
|
| 497 | +add_filter('geodir_payment_set_coupon_code', 'wpinv_payment_set_coupon_code', 10, 3); |
|
| 498 | 498 | |
| 499 | 499 | function wpinv_merge_gd_invoices() { |
| 500 | 500 | if (!defined('GEODIRPAYMENT_VERSION')) { |
@@ -502,157 +502,157 @@ discard block |
||
| 502 | 502 | } |
| 503 | 503 | ?> |
| 504 | 504 | <tr> |
| 505 | - <td><?php _e( 'Merge Price Packages', 'invoicing' ); ?></td> |
|
| 506 | - <td><p><?php _e( 'Merge GeoDirectory Payment Manager price packages to the Invoicing items.', 'invoicing' ); ?></p></td> |
|
| 507 | - <td><input type="button" data-tool="merge_packages" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td> |
|
| 505 | + <td><?php _e('Merge Price Packages', 'invoicing'); ?></td> |
|
| 506 | + <td><p><?php _e('Merge GeoDirectory Payment Manager price packages to the Invoicing items.', 'invoicing'); ?></p></td> |
|
| 507 | + <td><input type="button" data-tool="merge_packages" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td> |
|
| 508 | 508 | </tr> |
| 509 | 509 | <tr> |
| 510 | - <td><?php _e( 'Merge Invoices', 'invoicing' ); ?></td> |
|
| 511 | - <td><p><?php _e( 'Merge GeoDirectory Payment Manager invoices to the Invoicing.', 'invoicing' ); ?></p></td> |
|
| 512 | - <td><input type="button" data-tool="merge_invoices" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td> |
|
| 510 | + <td><?php _e('Merge Invoices', 'invoicing'); ?></td> |
|
| 511 | + <td><p><?php _e('Merge GeoDirectory Payment Manager invoices to the Invoicing.', 'invoicing'); ?></p></td> |
|
| 512 | + <td><input type="button" data-tool="merge_invoices" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td> |
|
| 513 | 513 | </tr> |
| 514 | 514 | <tr> |
| 515 | - <td><?php _e( 'Fix Taxes for Merged Invoices', 'invoicing' ); ?></td> |
|
| 516 | - <td><p><?php _e( 'Fix taxes for NON-PAID invoices which are merged before, from GeoDirectory Payment Manager invoices to Invoicing. This will recalculate taxes for non-paid merged invoices.', 'invoicing' ); ?></p></td> |
|
| 517 | - <td><input type="button" data-tool="merge_fix_taxes" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td> |
|
| 515 | + <td><?php _e('Fix Taxes for Merged Invoices', 'invoicing'); ?></td> |
|
| 516 | + <td><p><?php _e('Fix taxes for NON-PAID invoices which are merged before, from GeoDirectory Payment Manager invoices to Invoicing. This will recalculate taxes for non-paid merged invoices.', 'invoicing'); ?></p></td> |
|
| 517 | + <td><input type="button" data-tool="merge_fix_taxes" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td> |
|
| 518 | 518 | </tr> |
| 519 | 519 | <tr> |
| 520 | - <td><?php _e( 'Merge Coupons', 'invoicing' ); ?></td> |
|
| 521 | - <td><p><?php _e( 'Merge GeoDirectory Payment Manager coupons to the Invoicing.', 'invoicing' ); ?></p></td> |
|
| 522 | - <td><input type="button" data-tool="merge_coupons" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td> |
|
| 520 | + <td><?php _e('Merge Coupons', 'invoicing'); ?></td> |
|
| 521 | + <td><p><?php _e('Merge GeoDirectory Payment Manager coupons to the Invoicing.', 'invoicing'); ?></p></td> |
|
| 522 | + <td><input type="button" data-tool="merge_coupons" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td> |
|
| 523 | 523 | </tr> |
| 524 | 524 | <?php |
| 525 | 525 | } |
| 526 | -add_action( 'wpinv_tools_row', 'wpinv_merge_gd_invoices', 10 ); |
|
| 526 | +add_action('wpinv_tools_row', 'wpinv_merge_gd_invoices', 10); |
|
| 527 | 527 | |
| 528 | 528 | function wpinv_tool_merge_packages() { |
| 529 | 529 | $packages = geodir_package_list_info(); |
| 530 | 530 | |
| 531 | 531 | $count = 0; |
| 532 | 532 | |
| 533 | - if ( !empty( $packages ) ) { |
|
| 533 | + if (!empty($packages)) { |
|
| 534 | 534 | $success = true; |
| 535 | 535 | |
| 536 | - foreach ( $packages as $key => $package ) { |
|
| 536 | + foreach ($packages as $key => $package) { |
|
| 537 | 537 | $item = wpinv_get_item_by('custom_id', $package->pid, 'package'); |
| 538 | - if ( !empty( $item ) ) { |
|
| 538 | + if (!empty($item)) { |
|
| 539 | 539 | continue; |
| 540 | 540 | } |
| 541 | 541 | |
| 542 | - $merged = wpinv_merge_gd_package_to_item( $package->pid, false, $package ); |
|
| 542 | + $merged = wpinv_merge_gd_package_to_item($package->pid, false, $package); |
|
| 543 | 543 | |
| 544 | - if ( !empty( $merged ) ) { |
|
| 545 | - wpinv_error_log( 'Package merge S : ' . $package->pid ); |
|
| 544 | + if (!empty($merged)) { |
|
| 545 | + wpinv_error_log('Package merge S : ' . $package->pid); |
|
| 546 | 546 | $count++; |
| 547 | 547 | } else { |
| 548 | - wpinv_error_log( 'Package merge F : ' . $package->pid ); |
|
| 548 | + wpinv_error_log('Package merge F : ' . $package->pid); |
|
| 549 | 549 | } |
| 550 | 550 | } |
| 551 | 551 | |
| 552 | - if ( $count > 0 ) { |
|
| 553 | - $message = sprintf( _n( 'Total <b>%d</b> price package is merged successfully.', 'Total <b>%d</b> price packages are merged successfully.', $count, 'invoicing' ), $count ); |
|
| 552 | + if ($count > 0) { |
|
| 553 | + $message = sprintf(_n('Total <b>%d</b> price package is merged successfully.', 'Total <b>%d</b> price packages are merged successfully.', $count, 'invoicing'), $count); |
|
| 554 | 554 | } else { |
| 555 | - $message = __( 'No price packages merged.', 'invoicing' ); |
|
| 555 | + $message = __('No price packages merged.', 'invoicing'); |
|
| 556 | 556 | } |
| 557 | 557 | } else { |
| 558 | 558 | $success = false; |
| 559 | - $message = __( 'No price packages found to merge!', 'invoicing' ); |
|
| 559 | + $message = __('No price packages found to merge!', 'invoicing'); |
|
| 560 | 560 | } |
| 561 | 561 | |
| 562 | 562 | $response = array(); |
| 563 | 563 | $response['success'] = $success; |
| 564 | 564 | $response['data']['message'] = $message; |
| 565 | - wp_send_json( $response ); |
|
| 565 | + wp_send_json($response); |
|
| 566 | 566 | } |
| 567 | -add_action( 'wpinv_tool_merge_packages', 'wpinv_tool_merge_packages' ); |
|
| 567 | +add_action('wpinv_tool_merge_packages', 'wpinv_tool_merge_packages'); |
|
| 568 | 568 | |
| 569 | 569 | function wpinv_tool_merge_invoices() { |
| 570 | 570 | global $wpdb, $wpi_gdp_inv_merge, $wpi_tax_rates; |
| 571 | 571 | |
| 572 | 572 | $sql = "SELECT `gdi`.`id`, `gdi`.`date`, `gdi`.`date_updated` FROM `" . INVOICE_TABLE . "` AS gdi LEFT JOIN `" . $wpdb->posts . "` AS p ON `p`.`ID` = `gdi`.`invoice_id` AND `p`.`post_type` = 'wpi_invoice' WHERE `p`.`ID` IS NULL ORDER BY `gdi`.`id` ASC"; |
| 573 | 573 | |
| 574 | - $items = $wpdb->get_results( $sql ); |
|
| 574 | + $items = $wpdb->get_results($sql); |
|
| 575 | 575 | |
| 576 | 576 | $count = 0; |
| 577 | 577 | |
| 578 | - if ( !empty( $items ) ) { |
|
| 578 | + if (!empty($items)) { |
|
| 579 | 579 | $success = true; |
| 580 | 580 | $wpi_gdp_inv_merge = true; |
| 581 | 581 | |
| 582 | - foreach ( $items as $item ) { |
|
| 582 | + foreach ($items as $item) { |
|
| 583 | 583 | $wpi_tax_rates = NULL; |
| 584 | 584 | |
| 585 | - $wpdb->query( "UPDATE `" . INVOICE_TABLE . "` SET `invoice_id` = 0 WHERE id = '" . $item->id . "'" ); |
|
| 585 | + $wpdb->query("UPDATE `" . INVOICE_TABLE . "` SET `invoice_id` = 0 WHERE id = '" . $item->id . "'"); |
|
| 586 | 586 | |
| 587 | - $merged = wpinv_cpt_save( $item->id ); |
|
| 587 | + $merged = wpinv_cpt_save($item->id); |
|
| 588 | 588 | |
| 589 | - if ( !empty( $merged ) && !empty( $merged->ID ) ) { |
|
| 589 | + if (!empty($merged) && !empty($merged->ID)) { |
|
| 590 | 590 | $count++; |
| 591 | 591 | |
| 592 | - $post_date = !empty( $item->date ) && $item->date != '0000-00-00 00:00:00' ? $item->date : current_time( 'mysql' ); |
|
| 593 | - $post_date_gmt = get_gmt_from_date( $post_date ); |
|
| 594 | - $post_modified = !empty( $item->date_updated ) && $item->date_updated != '0000-00-00 00:00:00' ? $item->date_updated : $post_date; |
|
| 595 | - $post_modified_gmt = get_gmt_from_date( $post_modified ); |
|
| 592 | + $post_date = !empty($item->date) && $item->date != '0000-00-00 00:00:00' ? $item->date : current_time('mysql'); |
|
| 593 | + $post_date_gmt = get_gmt_from_date($post_date); |
|
| 594 | + $post_modified = !empty($item->date_updated) && $item->date_updated != '0000-00-00 00:00:00' ? $item->date_updated : $post_date; |
|
| 595 | + $post_modified_gmt = get_gmt_from_date($post_modified); |
|
| 596 | 596 | |
| 597 | - $wpdb->update( $wpdb->posts, array( 'post_date' => $post_date, 'post_date_gmt' => $post_date_gmt, 'post_modified' => $post_modified, 'post_modified_gmt' => $post_modified_gmt ), array( 'ID' => $merged->ID ) ); |
|
| 597 | + $wpdb->update($wpdb->posts, array('post_date' => $post_date, 'post_date_gmt' => $post_date_gmt, 'post_modified' => $post_modified, 'post_modified_gmt' => $post_modified_gmt), array('ID' => $merged->ID)); |
|
| 598 | 598 | |
| 599 | - if ( $merged->is_paid() ) { |
|
| 600 | - update_post_meta( $merged->ID, '_wpinv_completed_date', $post_modified ); |
|
| 599 | + if ($merged->is_paid()) { |
|
| 600 | + update_post_meta($merged->ID, '_wpinv_completed_date', $post_modified); |
|
| 601 | 601 | } |
| 602 | 602 | |
| 603 | - clean_post_cache( $merged->ID ); |
|
| 603 | + clean_post_cache($merged->ID); |
|
| 604 | 604 | |
| 605 | - wpinv_error_log( 'Invoice merge S : ' . $item->id . ' => ' . $merged->ID ); |
|
| 605 | + wpinv_error_log('Invoice merge S : ' . $item->id . ' => ' . $merged->ID); |
|
| 606 | 606 | } else { |
| 607 | - wpinv_error_log( 'Invoice merge F : ' . $item->id ); |
|
| 607 | + wpinv_error_log('Invoice merge F : ' . $item->id); |
|
| 608 | 608 | } |
| 609 | 609 | } |
| 610 | 610 | |
| 611 | 611 | $wpi_gdp_inv_merge = false; |
| 612 | 612 | |
| 613 | - if ( $count > 0 ) { |
|
| 614 | - $message = sprintf( _n( 'Total <b>%d</b> invoice is merged successfully.', 'Total <b>%d</b> invoices are merged successfully.', $count, 'invoicing' ), $count ); |
|
| 613 | + if ($count > 0) { |
|
| 614 | + $message = sprintf(_n('Total <b>%d</b> invoice is merged successfully.', 'Total <b>%d</b> invoices are merged successfully.', $count, 'invoicing'), $count); |
|
| 615 | 615 | } else { |
| 616 | - $message = __( 'No invoices merged.', 'invoicing' ); |
|
| 616 | + $message = __('No invoices merged.', 'invoicing'); |
|
| 617 | 617 | } |
| 618 | 618 | } else { |
| 619 | 619 | $success = false; |
| 620 | - $message = __( 'No invoices found to merge!', 'invoicing' ); |
|
| 620 | + $message = __('No invoices found to merge!', 'invoicing'); |
|
| 621 | 621 | } |
| 622 | 622 | |
| 623 | 623 | $response = array(); |
| 624 | 624 | $response['success'] = $success; |
| 625 | 625 | $response['data']['message'] = $message; |
| 626 | - wp_send_json( $response ); |
|
| 626 | + wp_send_json($response); |
|
| 627 | 627 | } |
| 628 | -add_action( 'wpinv_tool_merge_invoices', 'wpinv_tool_merge_invoices' ); |
|
| 628 | +add_action('wpinv_tool_merge_invoices', 'wpinv_tool_merge_invoices'); |
|
| 629 | 629 | |
| 630 | 630 | function wpinv_tool_merge_coupons() { |
| 631 | 631 | global $wpdb; |
| 632 | 632 | |
| 633 | 633 | $sql = "SELECT * FROM `" . COUPON_TABLE . "` WHERE `coupon_code` IS NOT NULL AND `coupon_code` != '' ORDER BY `cid` ASC"; |
| 634 | - $items = $wpdb->get_results( $sql ); |
|
| 634 | + $items = $wpdb->get_results($sql); |
|
| 635 | 635 | $count = 0; |
| 636 | 636 | |
| 637 | - if ( !empty( $items ) ) { |
|
| 637 | + if (!empty($items)) { |
|
| 638 | 638 | $success = true; |
| 639 | 639 | |
| 640 | - foreach ( $items as $item ) { |
|
| 641 | - if ( wpinv_get_discount_by_code( $item->coupon_code ) ) { |
|
| 640 | + foreach ($items as $item) { |
|
| 641 | + if (wpinv_get_discount_by_code($item->coupon_code)) { |
|
| 642 | 642 | continue; |
| 643 | 643 | } |
| 644 | 644 | |
| 645 | 645 | $args = array( |
| 646 | 646 | 'post_type' => 'wpi_discount', |
| 647 | 647 | 'post_title' => $item->coupon_code, |
| 648 | - 'post_status' => !empty( $item->status ) ? 'publish' : 'pending' |
|
| 648 | + 'post_status' => !empty($item->status) ? 'publish' : 'pending' |
|
| 649 | 649 | ); |
| 650 | 650 | |
| 651 | - $merged = wp_insert_post( $args ); |
|
| 651 | + $merged = wp_insert_post($args); |
|
| 652 | 652 | |
| 653 | 653 | $item_id = $item->cid; |
| 654 | 654 | |
| 655 | - if ( $merged ) { |
|
| 655 | + if ($merged) { |
|
| 656 | 656 | $meta = array( |
| 657 | 657 | 'code' => $item->coupon_code, |
| 658 | 658 | 'type' => $item->discount_type != 'per' ? 'flat' : 'percent', |
@@ -660,65 +660,65 @@ discard block |
||
| 660 | 660 | 'max_uses' => (int)$item->usage_limit, |
| 661 | 661 | 'uses' => (int)$item->usage_count, |
| 662 | 662 | ); |
| 663 | - wpinv_store_discount( $merged, $meta, get_post( $merged ) ); |
|
| 663 | + wpinv_store_discount($merged, $meta, get_post($merged)); |
|
| 664 | 664 | |
| 665 | 665 | $count++; |
| 666 | 666 | |
| 667 | - wpinv_error_log( 'Coupon merge S : ' . $item_id . ' => ' . $merged ); |
|
| 667 | + wpinv_error_log('Coupon merge S : ' . $item_id . ' => ' . $merged); |
|
| 668 | 668 | } else { |
| 669 | - wpinv_error_log( 'Coupon merge F : ' . $item_id ); |
|
| 669 | + wpinv_error_log('Coupon merge F : ' . $item_id); |
|
| 670 | 670 | } |
| 671 | 671 | } |
| 672 | 672 | |
| 673 | - if ( $count > 0 ) { |
|
| 674 | - $message = sprintf( _n( 'Total <b>%d</b> coupon is merged successfully.', 'Total <b>%d</b> coupons are merged successfully.', $count, 'invoicing' ), $count ); |
|
| 673 | + if ($count > 0) { |
|
| 674 | + $message = sprintf(_n('Total <b>%d</b> coupon is merged successfully.', 'Total <b>%d</b> coupons are merged successfully.', $count, 'invoicing'), $count); |
|
| 675 | 675 | } else { |
| 676 | - $message = __( 'No coupons merged.', 'invoicing' ); |
|
| 676 | + $message = __('No coupons merged.', 'invoicing'); |
|
| 677 | 677 | } |
| 678 | 678 | } else { |
| 679 | 679 | $success = false; |
| 680 | - $message = __( 'No coupons found to merge!', 'invoicing' ); |
|
| 680 | + $message = __('No coupons found to merge!', 'invoicing'); |
|
| 681 | 681 | } |
| 682 | 682 | |
| 683 | 683 | $response = array(); |
| 684 | 684 | $response['success'] = $success; |
| 685 | 685 | $response['data']['message'] = $message; |
| 686 | - wp_send_json( $response ); |
|
| 686 | + wp_send_json($response); |
|
| 687 | 687 | } |
| 688 | -add_action( 'wpinv_tool_merge_coupons', 'wpinv_tool_merge_coupons' ); |
|
| 688 | +add_action('wpinv_tool_merge_coupons', 'wpinv_tool_merge_coupons'); |
|
| 689 | 689 | |
| 690 | -function wpinv_gdp_to_wpi_currency( $value, $option = '' ) { |
|
| 690 | +function wpinv_gdp_to_wpi_currency($value, $option = '') { |
|
| 691 | 691 | return wpinv_get_currency(); |
| 692 | 692 | } |
| 693 | -add_filter( 'pre_option_geodir_currency', 'wpinv_gdp_to_wpi_currency', 10, 2 ); |
|
| 693 | +add_filter('pre_option_geodir_currency', 'wpinv_gdp_to_wpi_currency', 10, 2); |
|
| 694 | 694 | |
| 695 | -function wpinv_gdp_to_wpi_currency_sign( $value, $option = '' ) { |
|
| 695 | +function wpinv_gdp_to_wpi_currency_sign($value, $option = '') { |
|
| 696 | 696 | return wpinv_currency_symbol(); |
| 697 | 697 | } |
| 698 | -add_filter( 'pre_option_geodir_currencysym', 'wpinv_gdp_to_wpi_currency_sign', 10, 2 ); |
|
| 698 | +add_filter('pre_option_geodir_currencysym', 'wpinv_gdp_to_wpi_currency_sign', 10, 2); |
|
| 699 | 699 | |
| 700 | -function wpinv_gdp_to_wpi_display_price( $price, $amount, $display = true , $decimal_sep, $thousand_sep ) { |
|
| 701 | - if ( !$display ) { |
|
| 702 | - $price = wpinv_round_amount( $amount ); |
|
| 700 | +function wpinv_gdp_to_wpi_display_price($price, $amount, $display = true, $decimal_sep, $thousand_sep) { |
|
| 701 | + if (!$display) { |
|
| 702 | + $price = wpinv_round_amount($amount); |
|
| 703 | 703 | } else { |
| 704 | - $price = wpinv_price( wpinv_format_amount( $amount ) ); |
|
| 704 | + $price = wpinv_price(wpinv_format_amount($amount)); |
|
| 705 | 705 | } |
| 706 | 706 | |
| 707 | 707 | return $price; |
| 708 | 708 | } |
| 709 | -add_filter( 'geodir_payment_price' , 'wpinv_gdp_to_wpi_display_price', 10000, 5 ); |
|
| 709 | +add_filter('geodir_payment_price', 'wpinv_gdp_to_wpi_display_price', 10000, 5); |
|
| 710 | 710 | |
| 711 | -function wpinv_gdp_to_inv_checkout_redirect( $redirect_url ) { |
|
| 711 | +function wpinv_gdp_to_inv_checkout_redirect($redirect_url) { |
|
| 712 | 712 | $invoice_id = geodir_payment_cart_id(); |
| 713 | - $invoice_info = geodir_get_invoice( $invoice_id ); |
|
| 714 | - $wpi_invoice = !empty( $invoice_info->invoice_id ) ? wpinv_get_invoice( $invoice_info->invoice_id ) : NULL; |
|
| 713 | + $invoice_info = geodir_get_invoice($invoice_id); |
|
| 714 | + $wpi_invoice = !empty($invoice_info->invoice_id) ? wpinv_get_invoice($invoice_info->invoice_id) : NULL; |
|
| 715 | 715 | |
| 716 | - if ( !( !empty( $wpi_invoice ) && !empty( $wpi_invoice->ID ) ) ) { |
|
| 717 | - $wpi_invoice_id = wpinv_cpt_save( $invoice_id ); |
|
| 718 | - $wpi_invoice = wpinv_get_invoice( $wpi_invoice_id ); |
|
| 716 | + if (!(!empty($wpi_invoice) && !empty($wpi_invoice->ID))) { |
|
| 717 | + $wpi_invoice_id = wpinv_cpt_save($invoice_id); |
|
| 718 | + $wpi_invoice = wpinv_get_invoice($wpi_invoice_id); |
|
| 719 | 719 | } |
| 720 | 720 | |
| 721 | - if ( !empty( $wpi_invoice ) && !empty( $wpi_invoice->ID ) ) { |
|
| 721 | + if (!empty($wpi_invoice) && !empty($wpi_invoice->ID)) { |
|
| 722 | 722 | |
| 723 | 723 | // Clear cart |
| 724 | 724 | geodir_payment_clear_cart(); |
@@ -728,121 +728,121 @@ discard block |
||
| 728 | 728 | |
| 729 | 729 | return $redirect_url; |
| 730 | 730 | } |
| 731 | -add_filter( 'geodir_payment_checkout_redirect_url', 'wpinv_gdp_to_inv_checkout_redirect', 100, 1 ); |
|
| 731 | +add_filter('geodir_payment_checkout_redirect_url', 'wpinv_gdp_to_inv_checkout_redirect', 100, 1); |
|
| 732 | 732 | |
| 733 | -function wpinv_gdp_dashboard_invoice_history_link( $dashboard_links ) { |
|
| 734 | - if ( get_current_user_id() ) { |
|
| 735 | - $dashboard_links .= '<li><i class="fa fa-shopping-cart"></i><a class="gd-invoice-link" href="' . esc_url( wpinv_get_history_page_uri() ) . '">' . __( 'My Invoice History', 'invoicing' ) . '</a></li>'; |
|
| 733 | +function wpinv_gdp_dashboard_invoice_history_link($dashboard_links) { |
|
| 734 | + if (get_current_user_id()) { |
|
| 735 | + $dashboard_links .= '<li><i class="fa fa-shopping-cart"></i><a class="gd-invoice-link" href="' . esc_url(wpinv_get_history_page_uri()) . '">' . __('My Invoice History', 'invoicing') . '</a></li>'; |
|
| 736 | 736 | } |
| 737 | 737 | |
| 738 | 738 | return $dashboard_links; |
| 739 | 739 | } |
| 740 | -add_action( 'geodir_dashboard_links', 'wpinv_gdp_dashboard_invoice_history_link' ); |
|
| 741 | -remove_action( 'geodir_dashboard_links', 'geodir_payment_invoices_list_page_link' ); |
|
| 740 | +add_action('geodir_dashboard_links', 'wpinv_gdp_dashboard_invoice_history_link'); |
|
| 741 | +remove_action('geodir_dashboard_links', 'geodir_payment_invoices_list_page_link'); |
|
| 742 | 742 | |
| 743 | -function wpinv_wpi_to_gdp_update_status( $invoice_id, $new_status, $old_status ) { |
|
| 743 | +function wpinv_wpi_to_gdp_update_status($invoice_id, $new_status, $old_status) { |
|
| 744 | 744 | if (!defined('GEODIRPAYMENT_VERSION')) { |
| 745 | 745 | return false; |
| 746 | 746 | } |
| 747 | 747 | |
| 748 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 749 | - if ( empty( $invoice ) ) { |
|
| 748 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 749 | + if (empty($invoice)) { |
|
| 750 | 750 | return false; |
| 751 | 751 | } |
| 752 | 752 | |
| 753 | - remove_action( 'geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4 ); |
|
| 753 | + remove_action('geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4); |
|
| 754 | 754 | |
| 755 | - $invoice_id = wpinv_wpi_to_gdp_id( $invoice_id ); |
|
| 756 | - $new_status = wpinv_wpi_to_gdp_status( $new_status ); |
|
| 755 | + $invoice_id = wpinv_wpi_to_gdp_id($invoice_id); |
|
| 756 | + $new_status = wpinv_wpi_to_gdp_status($new_status); |
|
| 757 | 757 | |
| 758 | - geodir_update_invoice_status( $invoice_id, $new_status, $invoice->is_recurring() ); |
|
| 758 | + geodir_update_invoice_status($invoice_id, $new_status, $invoice->is_recurring()); |
|
| 759 | 759 | } |
| 760 | -add_action( 'wpinv_update_status', 'wpinv_wpi_to_gdp_update_status', 999, 3 ); |
|
| 760 | +add_action('wpinv_update_status', 'wpinv_wpi_to_gdp_update_status', 999, 3); |
|
| 761 | 761 | |
| 762 | -function wpinv_gdp_to_wpi_delete_package( $gd_package_id ) { |
|
| 763 | - $item = wpinv_get_item_by( 'custom_id', $gd_package_id, 'package' ); |
|
| 762 | +function wpinv_gdp_to_wpi_delete_package($gd_package_id) { |
|
| 763 | + $item = wpinv_get_item_by('custom_id', $gd_package_id, 'package'); |
|
| 764 | 764 | |
| 765 | - if ( !empty( $item ) ) { |
|
| 766 | - wpinv_remove_item( $item, true ); |
|
| 765 | + if (!empty($item)) { |
|
| 766 | + wpinv_remove_item($item, true); |
|
| 767 | 767 | } |
| 768 | 768 | } |
| 769 | -add_action( 'geodir_payment_post_delete_package', 'wpinv_gdp_to_wpi_delete_package', 10, 1 ) ; |
|
| 769 | +add_action('geodir_payment_post_delete_package', 'wpinv_gdp_to_wpi_delete_package', 10, 1); |
|
| 770 | 770 | |
| 771 | -function wpinv_can_delete_package_item( $return, $post_id ) { |
|
| 772 | - if ( $return && function_exists( 'geodir_get_package_info_by_id' ) && get_post_meta( $post_id, '_wpinv_type', true ) == 'package' && $package_id = get_post_meta( $post_id, '_wpinv_custom_id', true ) ) { |
|
| 773 | - $gd_package = geodir_get_package_info_by_id( $package_id, '' ); |
|
| 771 | +function wpinv_can_delete_package_item($return, $post_id) { |
|
| 772 | + if ($return && function_exists('geodir_get_package_info_by_id') && get_post_meta($post_id, '_wpinv_type', true) == 'package' && $package_id = get_post_meta($post_id, '_wpinv_custom_id', true)) { |
|
| 773 | + $gd_package = geodir_get_package_info_by_id($package_id, ''); |
|
| 774 | 774 | |
| 775 | - if ( !empty( $gd_package ) ) { |
|
| 775 | + if (!empty($gd_package)) { |
|
| 776 | 776 | $return = false; |
| 777 | 777 | } |
| 778 | 778 | } |
| 779 | 779 | |
| 780 | 780 | return $return; |
| 781 | 781 | } |
| 782 | -add_filter( 'wpinv_can_delete_item', 'wpinv_can_delete_package_item', 10, 2 ); |
|
| 782 | +add_filter('wpinv_can_delete_item', 'wpinv_can_delete_package_item', 10, 2); |
|
| 783 | 783 | |
| 784 | -function wpinv_package_item_classes( $classes, $class, $post_id ) { |
|
| 784 | +function wpinv_package_item_classes($classes, $class, $post_id) { |
|
| 785 | 785 | global $typenow; |
| 786 | 786 | |
| 787 | - if ( $typenow == 'wpi_item' && in_array( 'wpi-gd-package', $classes ) ) { |
|
| 788 | - if ( wpinv_item_in_use( $post_id ) ) { |
|
| 787 | + if ($typenow == 'wpi_item' && in_array('wpi-gd-package', $classes)) { |
|
| 788 | + if (wpinv_item_in_use($post_id)) { |
|
| 789 | 789 | $classes[] = 'wpi-inuse-pkg'; |
| 790 | - } else if ( !( function_exists( 'geodir_get_package_info_by_id' ) && get_post_meta( $post_id, '_wpinv_type', true ) == 'package' && geodir_get_package_info_by_id( (int)get_post_meta( $post_id, '_wpinv_custom_id', true ), '' ) ) ) { |
|
| 790 | + } else if (!(function_exists('geodir_get_package_info_by_id') && get_post_meta($post_id, '_wpinv_type', true) == 'package' && geodir_get_package_info_by_id((int)get_post_meta($post_id, '_wpinv_custom_id', true), ''))) { |
|
| 791 | 791 | $classes[] = 'wpi-delete-pkg'; |
| 792 | 792 | } |
| 793 | 793 | } |
| 794 | 794 | |
| 795 | 795 | return $classes; |
| 796 | 796 | } |
| 797 | -add_filter( 'post_class', 'wpinv_package_item_classes', 10, 3 ); |
|
| 797 | +add_filter('post_class', 'wpinv_package_item_classes', 10, 3); |
|
| 798 | 798 | |
| 799 | -function wpinv_gdp_package_type_info( $post ) { |
|
| 800 | - if ( wpinv_pm_active() ) { |
|
| 801 | - ?><p class="wpi-m0"><?php _e( 'Package: GeoDirectory price packages items.', 'invoicing' );?></p> |
|
| 799 | +function wpinv_gdp_package_type_info($post) { |
|
| 800 | + if (wpinv_pm_active()) { |
|
| 801 | + ?><p class="wpi-m0"><?php _e('Package: GeoDirectory price packages items.', 'invoicing'); ?></p> |
|
| 802 | 802 | <?php |
| 803 | 803 | } |
| 804 | 804 | } |
| 805 | -add_action( 'wpinv_item_info_metabox_after', 'wpinv_gdp_package_type_info', 10, 1 ) ; |
|
| 805 | +add_action('wpinv_item_info_metabox_after', 'wpinv_gdp_package_type_info', 10, 1); |
|
| 806 | 806 | |
| 807 | -function wpinv_gdp_to_gdi_set_zero_tax( $is_taxable, $item_id, $country , $state ) { |
|
| 807 | +function wpinv_gdp_to_gdi_set_zero_tax($is_taxable, $item_id, $country, $state) { |
|
| 808 | 808 | global $wpi_zero_tax; |
| 809 | 809 | |
| 810 | - if ( $wpi_zero_tax ) { |
|
| 810 | + if ($wpi_zero_tax) { |
|
| 811 | 811 | $is_taxable = false; |
| 812 | 812 | } |
| 813 | 813 | |
| 814 | 814 | return $is_taxable; |
| 815 | 815 | } |
| 816 | -add_action( 'wpinv_item_is_taxable', 'wpinv_gdp_to_gdi_set_zero_tax', 10, 4 ) ; |
|
| 816 | +add_action('wpinv_item_is_taxable', 'wpinv_gdp_to_gdi_set_zero_tax', 10, 4); |
|
| 817 | 817 | |
| 818 | 818 | function wpinv_tool_merge_fix_taxes() { |
| 819 | 819 | global $wpdb; |
| 820 | 820 | |
| 821 | 821 | $sql = "SELECT DISTINCT p.ID FROM `" . $wpdb->posts . "` AS p LEFT JOIN " . $wpdb->postmeta . " AS pm ON pm.post_id = p.ID WHERE p.post_type = 'wpi_item' AND pm.meta_key = '_wpinv_type' AND pm.meta_value = 'package'"; |
| 822 | - $items = $wpdb->get_results( $sql ); |
|
| 822 | + $items = $wpdb->get_results($sql); |
|
| 823 | 823 | |
| 824 | - if ( !empty( $items ) ) { |
|
| 825 | - foreach ( $items as $item ) { |
|
| 826 | - if ( get_post_meta( $item->ID, '_wpinv_vat_class', true ) == '_exempt' ) { |
|
| 827 | - update_post_meta( $item->ID, '_wpinv_vat_class', '_standard' ); |
|
| 824 | + if (!empty($items)) { |
|
| 825 | + foreach ($items as $item) { |
|
| 826 | + if (get_post_meta($item->ID, '_wpinv_vat_class', true) == '_exempt') { |
|
| 827 | + update_post_meta($item->ID, '_wpinv_vat_class', '_standard'); |
|
| 828 | 828 | } |
| 829 | 829 | } |
| 830 | 830 | } |
| 831 | 831 | |
| 832 | 832 | $sql = "SELECT `p`.`ID`, gdi.id AS gdp_id FROM `" . INVOICE_TABLE . "` AS gdi LEFT JOIN `" . $wpdb->posts . "` AS p ON `p`.`ID` = `gdi`.`invoice_id` AND `p`.`post_type` = 'wpi_invoice' WHERE `p`.`ID` IS NOT NULL AND p.post_status NOT IN( 'publish', 'wpi-processing', 'wpi-renewal' ) ORDER BY `gdi`.`id` ASC"; |
| 833 | - $items = $wpdb->get_results( $sql ); |
|
| 833 | + $items = $wpdb->get_results($sql); |
|
| 834 | 834 | |
| 835 | - if ( !empty( $items ) ) { |
|
| 835 | + if (!empty($items)) { |
|
| 836 | 836 | $success = false; |
| 837 | - $message = __( 'Taxes fixed for non-paid merged GD invoices.', 'invoicing' ); |
|
| 837 | + $message = __('Taxes fixed for non-paid merged GD invoices.', 'invoicing'); |
|
| 838 | 838 | |
| 839 | 839 | global $wpi_userID, $wpinv_ip_address_country, $wpi_tax_rates; |
| 840 | 840 | |
| 841 | - foreach ( $items as $item ) { |
|
| 841 | + foreach ($items as $item) { |
|
| 842 | 842 | $wpi_tax_rates = NULL; |
| 843 | 843 | $data = wpinv_get_invoice($item->ID); |
| 844 | 844 | |
| 845 | - if ( empty( $data ) ) { |
|
| 845 | + if (empty($data)) { |
|
| 846 | 846 | continue; |
| 847 | 847 | } |
| 848 | 848 | |
@@ -850,51 +850,51 @@ discard block |
||
| 850 | 850 | |
| 851 | 851 | $data_session = array(); |
| 852 | 852 | $data_session['invoice_id'] = $data->ID; |
| 853 | - $data_session['cart_discounts'] = $data->get_discounts( true ); |
|
| 853 | + $data_session['cart_discounts'] = $data->get_discounts(true); |
|
| 854 | 854 | |
| 855 | - wpinv_set_checkout_session( $data_session ); |
|
| 855 | + wpinv_set_checkout_session($data_session); |
|
| 856 | 856 | |
| 857 | 857 | $wpi_userID = (int)$data->get_user_id(); |
| 858 | 858 | $_POST['country'] = !empty($data->country) ? $data->country : wpinv_get_default_country(); |
| 859 | 859 | |
| 860 | - $data->country = sanitize_text_field( $_POST['country'] ); |
|
| 861 | - $data->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
| 860 | + $data->country = sanitize_text_field($_POST['country']); |
|
| 861 | + $data->set('country', sanitize_text_field($_POST['country'])); |
|
| 862 | 862 | |
| 863 | 863 | $wpinv_ip_address_country = $data->country; |
| 864 | 864 | |
| 865 | 865 | $data->recalculate_totals(true); |
| 866 | 866 | |
| 867 | - wpinv_set_checkout_session( $checkout_session ); |
|
| 867 | + wpinv_set_checkout_session($checkout_session); |
|
| 868 | 868 | |
| 869 | 869 | $update_data = array(); |
| 870 | 870 | $update_data['tax_amount'] = $data->get_tax(); |
| 871 | 871 | $update_data['paied_amount'] = $data->get_total(); |
| 872 | 872 | $update_data['invoice_id'] = $data->ID; |
| 873 | 873 | |
| 874 | - $wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $item->gdp_id ) ); |
|
| 874 | + $wpdb->update(INVOICE_TABLE, $update_data, array('id' => $item->gdp_id)); |
|
| 875 | 875 | } |
| 876 | 876 | } else { |
| 877 | 877 | $success = false; |
| 878 | - $message = __( 'No invoices found to fix taxes!', 'invoicing' ); |
|
| 878 | + $message = __('No invoices found to fix taxes!', 'invoicing'); |
|
| 879 | 879 | } |
| 880 | 880 | |
| 881 | 881 | $response = array(); |
| 882 | 882 | $response['success'] = $success; |
| 883 | 883 | $response['data']['message'] = $message; |
| 884 | - wp_send_json( $response ); |
|
| 884 | + wp_send_json($response); |
|
| 885 | 885 | } |
| 886 | -add_action( 'wpinv_tool_merge_fix_taxes', 'wpinv_tool_merge_fix_taxes' ); |
|
| 887 | -remove_action( 'geodir_before_detail_fields' , 'geodir_build_coupon', 2 ); |
|
| 886 | +add_action('wpinv_tool_merge_fix_taxes', 'wpinv_tool_merge_fix_taxes'); |
|
| 887 | +remove_action('geodir_before_detail_fields', 'geodir_build_coupon', 2); |
|
| 888 | 888 | |
| 889 | -function wpinv_wpi_to_gdp_handle_subscription_cancel( $invoice_id, $invoice ) { |
|
| 890 | - if ( wpinv_pm_active() && !empty( $invoice ) && $invoice->is_recurring() ) { |
|
| 891 | - if ( $invoice->is_renewal() ) { |
|
| 889 | +function wpinv_wpi_to_gdp_handle_subscription_cancel($invoice_id, $invoice) { |
|
| 890 | + if (wpinv_pm_active() && !empty($invoice) && $invoice->is_recurring()) { |
|
| 891 | + if ($invoice->is_renewal()) { |
|
| 892 | 892 | $invoice = $invoice->get_parent_payment(); |
| 893 | 893 | } |
| 894 | 894 | |
| 895 | - if ( !empty( $invoice ) ) { |
|
| 896 | - wpinv_wpi_to_gdp_update_status( $invoice->ID, 'wpi-cancelled', $invoice->get_status() ); |
|
| 895 | + if (!empty($invoice)) { |
|
| 896 | + wpinv_wpi_to_gdp_update_status($invoice->ID, 'wpi-cancelled', $invoice->get_status()); |
|
| 897 | 897 | } |
| 898 | 898 | } |
| 899 | 899 | } |
| 900 | -add_action( 'wpinv_subscription_cancelled', 'wpinv_wpi_to_gdp_handle_subscription_cancel', 10, 2 ); |
|
| 901 | 900 | \ No newline at end of file |
| 901 | +add_action('wpinv_subscription_cancelled', 'wpinv_wpi_to_gdp_handle_subscription_cancel', 10, 2); |
|
| 902 | 902 | \ No newline at end of file |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if (!defined('ABSPATH')) { |
|
| 3 | 3 | exit; // Exit if accessed directly |
| 4 | 4 | } |
| 5 | 5 | |
@@ -14,73 +14,73 @@ discard block |
||
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | public function init() { |
| 17 | - do_action( 'wpinv_class_notes_init', $this ); |
|
| 17 | + do_action('wpinv_class_notes_init', $this); |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | public function includes() { |
| 21 | - do_action( 'wpinv_class_notes_includes', $this ); |
|
| 21 | + do_action('wpinv_class_notes_includes', $this); |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | public function actions() { |
| 25 | 25 | // Secure inovice notes |
| 26 | - add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 ); |
|
| 26 | + add_action('pre_get_comments', array($this, 'set_invoice_note_type'), 11, 1); |
|
| 27 | 27 | |
| 28 | 28 | // Count comments |
| 29 | - add_filter( 'wp_count_comments', array( $this, 'wp_count_comments' ), 11, 2 ); |
|
| 29 | + add_filter('wp_count_comments', array($this, 'wp_count_comments'), 11, 2); |
|
| 30 | 30 | |
| 31 | 31 | // Delete comments count cache whenever there is a new comment or a comment status changes |
| 32 | - add_action( 'wp_insert_comment', array( $this, 'delete_comments_count_cache' ) ); |
|
| 33 | - add_action( 'wp_set_comment_status', array( $this, 'delete_comments_count_cache' ) ); |
|
| 32 | + add_action('wp_insert_comment', array($this, 'delete_comments_count_cache')); |
|
| 33 | + add_action('wp_set_comment_status', array($this, 'delete_comments_count_cache')); |
|
| 34 | 34 | |
| 35 | - do_action( 'wpinv_class_notes_actions', $this ); |
|
| 35 | + do_action('wpinv_class_notes_actions', $this); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | - public function set_invoice_note_type( $query ) { |
|
| 39 | - $post_ID = !empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id']; |
|
| 38 | + public function set_invoice_note_type($query) { |
|
| 39 | + $post_ID = !empty($query->query_vars['post_ID']) ? $query->query_vars['post_ID'] : $query->query_vars['post_id']; |
|
| 40 | 40 | |
| 41 | - if ( $post_ID && get_post_type( $post_ID ) == $this->invoice_post_type ) { |
|
| 41 | + if ($post_ID && get_post_type($post_ID) == $this->invoice_post_type) { |
|
| 42 | 42 | $query->query_vars['type__in'] = $this->comment_type; |
| 43 | 43 | $query->query_vars['type__not_in'] = ''; |
| 44 | 44 | } else { |
| 45 | - if ( isset( $query->query_vars['type__in'] ) && $type_in = $query->query_vars['type__in'] ) { |
|
| 46 | - if ( is_array( $type_in ) && in_array( $this->comment_type, $type_in ) ) { |
|
| 47 | - $key = array_search( $this->comment_type, $type_in ); |
|
| 48 | - unset( $query->query_vars['type__in'][$key] ); |
|
| 49 | - } else if ( !is_array( $type_in ) && $type_in == $this->comment_type ) { |
|
| 45 | + if (isset($query->query_vars['type__in']) && $type_in = $query->query_vars['type__in']) { |
|
| 46 | + if (is_array($type_in) && in_array($this->comment_type, $type_in)) { |
|
| 47 | + $key = array_search($this->comment_type, $type_in); |
|
| 48 | + unset($query->query_vars['type__in'][$key]); |
|
| 49 | + } else if (!is_array($type_in) && $type_in == $this->comment_type) { |
|
| 50 | 50 | $query->query_vars['type__in'] = ''; |
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - if ( isset( $query->query_vars['type__not_in'] ) && $type_not_in = $query->query_vars['type__not_in'] ) { |
|
| 55 | - if ( is_array( $type_not_in ) && !in_array( $this->comment_type, $type_not_in ) ) { |
|
| 54 | + if (isset($query->query_vars['type__not_in']) && $type_not_in = $query->query_vars['type__not_in']) { |
|
| 55 | + if (is_array($type_not_in) && !in_array($this->comment_type, $type_not_in)) { |
|
| 56 | 56 | $query->query_vars['type__not_in'][] = $this->comment_type; |
| 57 | - } else if ( !is_array( $type_not_in ) && $type_not_in != $this->comment_type ) { |
|
| 57 | + } else if (!is_array($type_not_in) && $type_not_in != $this->comment_type) { |
|
| 58 | 58 | $query->query_vars['type__not_in'] = (array)$query->query_vars['type__not_in']; |
| 59 | 59 | $query->query_vars['type__not_in'][] = $this->comment_type; |
| 60 | 60 | } |
| 61 | 61 | } else { |
| 62 | - $query->query_vars['type__not_in'] = $this->comment_type; |
|
| 62 | + $query->query_vars['type__not_in'] = $this->comment_type; |
|
| 63 | 63 | } |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | return $query; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - public function get_invoice_notes( $invoice_id = 0, $type = '' ) { |
|
| 69 | + public function get_invoice_notes($invoice_id = 0, $type = '') { |
|
| 70 | 70 | $args = array( |
| 71 | 71 | 'post_id' => $invoice_id, |
| 72 | 72 | 'orderby' => 'comment_ID', |
| 73 | 73 | 'order' => 'DESC', |
| 74 | 74 | ); |
| 75 | 75 | |
| 76 | - if ( $type == 'customer' ) { |
|
| 76 | + if ($type == 'customer') { |
|
| 77 | 77 | $args['meta_key'] = '_wpi_customer_note'; |
| 78 | 78 | $args['meta_value'] = 1; |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - $args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type ); |
|
| 81 | + $args = apply_filters('wpinv_invoice_notes_args', $args, $this, $invoice_id, $type); |
|
| 82 | 82 | |
| 83 | - return get_comments( $args ); |
|
| 83 | + return get_comments($args); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | * @return void |
| 92 | 92 | */ |
| 93 | 93 | public function delete_comments_count_cache() { |
| 94 | - delete_transient( 'wpinv_count_comments' ); |
|
| 94 | + delete_transient('wpinv_count_comments'); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -102,16 +102,16 @@ discard block |
||
| 102 | 102 | * @param int $post_id Post ID. |
| 103 | 103 | * @return object |
| 104 | 104 | */ |
| 105 | - public function wp_count_comments( $stats, $post_id ) { |
|
| 105 | + public function wp_count_comments($stats, $post_id) { |
|
| 106 | 106 | global $wpdb; |
| 107 | 107 | |
| 108 | - if ( 0 === $post_id ) { |
|
| 109 | - $stats = get_transient( 'wpinv_count_comments' ); |
|
| 108 | + if (0 === $post_id) { |
|
| 109 | + $stats = get_transient('wpinv_count_comments'); |
|
| 110 | 110 | |
| 111 | - if ( ! $stats ) { |
|
| 111 | + if (!$stats) { |
|
| 112 | 112 | $stats = array(); |
| 113 | 113 | |
| 114 | - $count = $wpdb->get_results( "SELECT comment_approved, COUNT(*) AS num_comments FROM {$wpdb->comments} WHERE comment_type NOT IN ('" . $this->comment_type . "') GROUP BY comment_approved", ARRAY_A ); |
|
| 114 | + $count = $wpdb->get_results("SELECT comment_approved, COUNT(*) AS num_comments FROM {$wpdb->comments} WHERE comment_type NOT IN ('" . $this->comment_type . "') GROUP BY comment_approved", ARRAY_A); |
|
| 115 | 115 | |
| 116 | 116 | $total = 0; |
| 117 | 117 | $approved = array( |
@@ -122,26 +122,26 @@ discard block |
||
| 122 | 122 | 'post-trashed' => 'post-trashed', |
| 123 | 123 | ); |
| 124 | 124 | |
| 125 | - foreach ( (array) $count as $row ) { |
|
| 125 | + foreach ((array)$count as $row) { |
|
| 126 | 126 | // Do not count post-trashed toward totals. |
| 127 | - if ( 'post-trashed' !== $row['comment_approved'] && 'trash' !== $row['comment_approved'] ) { |
|
| 127 | + if ('post-trashed' !== $row['comment_approved'] && 'trash' !== $row['comment_approved']) { |
|
| 128 | 128 | $total += $row['num_comments']; |
| 129 | 129 | } |
| 130 | - if ( isset( $approved[ $row['comment_approved'] ] ) ) { |
|
| 131 | - $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments']; |
|
| 130 | + if (isset($approved[$row['comment_approved']])) { |
|
| 131 | + $stats[$approved[$row['comment_approved']]] = $row['num_comments']; |
|
| 132 | 132 | } |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | $stats['total_comments'] = $total; |
| 136 | 136 | $stats['all'] = $total; |
| 137 | - foreach ( $approved as $key ) { |
|
| 138 | - if ( empty( $stats[ $key ] ) ) { |
|
| 139 | - $stats[ $key ] = 0; |
|
| 137 | + foreach ($approved as $key) { |
|
| 138 | + if (empty($stats[$key])) { |
|
| 139 | + $stats[$key] = 0; |
|
| 140 | 140 | } |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - $stats = (object) $stats; |
|
| 144 | - set_transient( 'wpinv_count_comments', $stats ); |
|
| 143 | + $stats = (object)$stats; |
|
| 144 | + set_transient('wpinv_count_comments', $stats); |
|
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | 147 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if (!defined('ABSPATH')) { |
|
| 3 | 3 | exit; // Exit if accessed directly |
| 4 | 4 | } |
| 5 | 5 | |
@@ -21,108 +21,108 @@ discard block |
||
| 21 | 21 | return array(); |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | - public function get( $row_id ) { |
|
| 24 | + public function get($row_id) { |
|
| 25 | 25 | global $wpdb; |
| 26 | - return $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1", $row_id ) ); |
|
| 26 | + return $wpdb->get_row($wpdb->prepare("SELECT * FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1", $row_id)); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - public function get_by( $column, $row_id ) { |
|
| 29 | + public function get_by($column, $row_id) { |
|
| 30 | 30 | global $wpdb; |
| 31 | - $column = esc_sql( $column ); |
|
| 32 | - return $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $this->table_name WHERE $column = %s LIMIT 1", $row_id ) ); |
|
| 31 | + $column = esc_sql($column); |
|
| 32 | + return $wpdb->get_row($wpdb->prepare("SELECT * FROM $this->table_name WHERE $column = %s LIMIT 1", $row_id)); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - public function get_column( $column, $row_id ) { |
|
| 35 | + public function get_column($column, $row_id) { |
|
| 36 | 36 | global $wpdb; |
| 37 | - $column = esc_sql( $column ); |
|
| 38 | - return $wpdb->get_var( $wpdb->prepare( "SELECT $column FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1", $row_id ) ); |
|
| 37 | + $column = esc_sql($column); |
|
| 38 | + return $wpdb->get_var($wpdb->prepare("SELECT $column FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1", $row_id)); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - public function get_column_by( $column, $column_where, $column_value ) { |
|
| 41 | + public function get_column_by($column, $column_where, $column_value) { |
|
| 42 | 42 | global $wpdb; |
| 43 | - $column_where = esc_sql( $column_where ); |
|
| 44 | - $column = esc_sql( $column ); |
|
| 45 | - return $wpdb->get_var( $wpdb->prepare( "SELECT $column FROM $this->table_name WHERE $column_where = %s LIMIT 1", $column_value ) ); |
|
| 43 | + $column_where = esc_sql($column_where); |
|
| 44 | + $column = esc_sql($column); |
|
| 45 | + return $wpdb->get_var($wpdb->prepare("SELECT $column FROM $this->table_name WHERE $column_where = %s LIMIT 1", $column_value)); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - public function insert( $data, $type = '' ) { |
|
| 48 | + public function insert($data, $type = '') { |
|
| 49 | 49 | global $wpdb; |
| 50 | 50 | |
| 51 | - $data = wp_parse_args( $data, $this->get_column_defaults() ); |
|
| 51 | + $data = wp_parse_args($data, $this->get_column_defaults()); |
|
| 52 | 52 | |
| 53 | - do_action( 'wpinv_pre_insert_' . $type, $data ); |
|
| 53 | + do_action('wpinv_pre_insert_' . $type, $data); |
|
| 54 | 54 | |
| 55 | 55 | $column_formats = $this->get_columns(); |
| 56 | 56 | |
| 57 | - $data = array_change_key_case( $data ); |
|
| 57 | + $data = array_change_key_case($data); |
|
| 58 | 58 | |
| 59 | - $data = array_intersect_key( $data, $column_formats ); |
|
| 59 | + $data = array_intersect_key($data, $column_formats); |
|
| 60 | 60 | |
| 61 | - $data_keys = array_keys( $data ); |
|
| 62 | - $column_formats = array_merge( array_flip( $data_keys ), $column_formats ); |
|
| 61 | + $data_keys = array_keys($data); |
|
| 62 | + $column_formats = array_merge(array_flip($data_keys), $column_formats); |
|
| 63 | 63 | |
| 64 | - $wpdb->insert( $this->table_name, $data, $column_formats ); |
|
| 64 | + $wpdb->insert($this->table_name, $data, $column_formats); |
|
| 65 | 65 | $wpdb_insert_id = $wpdb->insert_id; |
| 66 | 66 | |
| 67 | - do_action( 'wpinv_post_insert_' . $type, $wpdb_insert_id, $data ); |
|
| 67 | + do_action('wpinv_post_insert_' . $type, $wpdb_insert_id, $data); |
|
| 68 | 68 | |
| 69 | 69 | return $wpdb_insert_id; |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - public function update( $row_id, $data = array(), $where = '' ) { |
|
| 72 | + public function update($row_id, $data = array(), $where = '') { |
|
| 73 | 73 | global $wpdb; |
| 74 | 74 | |
| 75 | - $row_id = absint( $row_id ); |
|
| 75 | + $row_id = absint($row_id); |
|
| 76 | 76 | |
| 77 | - if( empty( $row_id ) ) { |
|
| 77 | + if (empty($row_id)) { |
|
| 78 | 78 | return false; |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - if( empty( $where ) ) { |
|
| 81 | + if (empty($where)) { |
|
| 82 | 82 | $where = $this->primary_key; |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | $column_formats = $this->get_columns(); |
| 86 | 86 | |
| 87 | - $data = array_change_key_case( $data ); |
|
| 87 | + $data = array_change_key_case($data); |
|
| 88 | 88 | |
| 89 | - $data = array_intersect_key( $data, $column_formats ); |
|
| 89 | + $data = array_intersect_key($data, $column_formats); |
|
| 90 | 90 | |
| 91 | - $data_keys = array_keys( $data ); |
|
| 92 | - $column_formats = array_merge( array_flip( $data_keys ), $column_formats ); |
|
| 91 | + $data_keys = array_keys($data); |
|
| 92 | + $column_formats = array_merge(array_flip($data_keys), $column_formats); |
|
| 93 | 93 | |
| 94 | - if ( false === $wpdb->update( $this->table_name, $data, array( $where => $row_id ), $column_formats ) ) { |
|
| 94 | + if (false === $wpdb->update($this->table_name, $data, array($where => $row_id), $column_formats)) { |
|
| 95 | 95 | return false; |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | return true; |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - public function delete( $row_id = 0 ) { |
|
| 101 | + public function delete($row_id = 0) { |
|
| 102 | 102 | global $wpdb; |
| 103 | 103 | |
| 104 | - $row_id = absint( $row_id ); |
|
| 104 | + $row_id = absint($row_id); |
|
| 105 | 105 | |
| 106 | - if( empty( $row_id ) ) { |
|
| 106 | + if (empty($row_id)) { |
|
| 107 | 107 | return false; |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - if ( false === $wpdb->query( $wpdb->prepare( "DELETE FROM $this->table_name WHERE $this->primary_key = %d", $row_id ) ) ) { |
|
| 110 | + if (false === $wpdb->query($wpdb->prepare("DELETE FROM $this->table_name WHERE $this->primary_key = %d", $row_id))) { |
|
| 111 | 111 | return false; |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | return true; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - public function table_exists( $table ) { |
|
| 117 | + public function table_exists($table) { |
|
| 118 | 118 | global $wpdb; |
| 119 | - $table = sanitize_text_field( $table ); |
|
| 119 | + $table = sanitize_text_field($table); |
|
| 120 | 120 | |
| 121 | - return $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE '%s'", $table ) ) === $table; |
|
| 121 | + return $wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE '%s'", $table)) === $table; |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | public function installed() { |
| 125 | - return $this->table_exists( $this->table_name ); |
|
| 125 | + return $this->table_exists($this->table_name); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | } |