@@ -7,90 +7,90 @@ discard block |
||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | // MUST have WordPress. |
| 10 | -if ( !defined( 'WPINC' ) ) { |
|
| 11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
| 10 | +if (!defined('WPINC')) { |
|
| 11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | function wpinv_get_discount_types() { |
| 15 | 15 | $discount_types = array( |
| 16 | - 'percent' => __( 'Percentage', 'invoicing' ), |
|
| 17 | - 'flat' => __( 'Flat Amount', 'invoicing' ), |
|
| 16 | + 'percent' => __('Percentage', 'invoicing'), |
|
| 17 | + 'flat' => __('Flat Amount', 'invoicing'), |
|
| 18 | 18 | ); |
| 19 | - return (array)apply_filters( 'wpinv_discount_types', $discount_types ); |
|
| 19 | + return (array)apply_filters('wpinv_discount_types', $discount_types); |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | -function wpinv_get_discount_type_name( $type = '' ) { |
|
| 22 | +function wpinv_get_discount_type_name($type = '') { |
|
| 23 | 23 | $types = wpinv_get_discount_types(); |
| 24 | - return isset( $types[ $type ] ) ? $types[ $type ] : ''; |
|
| 24 | + return isset($types[$type]) ? $types[$type] : ''; |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | -function wpinv_delete_discount( $data ) { |
|
| 28 | - if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) { |
|
| 29 | - wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 27 | +function wpinv_delete_discount($data) { |
|
| 28 | + if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) { |
|
| 29 | + wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - if( ! current_user_can( 'manage_options' ) ) { |
|
| 33 | - wp_die( __( 'You do not have permission to delete discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 32 | + if (!current_user_can('manage_options')) { |
|
| 33 | + wp_die(__('You do not have permission to delete discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | $discount_id = $data['discount']; |
| 37 | - wpinv_remove_discount( $discount_id ); |
|
| 37 | + wpinv_remove_discount($discount_id); |
|
| 38 | 38 | } |
| 39 | -add_action( 'wpinv_delete_discount', 'wpinv_delete_discount' ); |
|
| 39 | +add_action('wpinv_delete_discount', 'wpinv_delete_discount'); |
|
| 40 | 40 | |
| 41 | -function wpinv_activate_discount( $data ) { |
|
| 42 | - if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) { |
|
| 43 | - wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 41 | +function wpinv_activate_discount($data) { |
|
| 42 | + if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) { |
|
| 43 | + wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - if( ! current_user_can( 'manage_options' ) ) { |
|
| 47 | - wp_die( __( 'You do not have permission to edit discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 46 | + if (!current_user_can('manage_options')) { |
|
| 47 | + wp_die(__('You do not have permission to edit discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - $id = absint( $data['discount'] ); |
|
| 51 | - wpinv_update_discount_status( $id, 'publish' ); |
|
| 50 | + $id = absint($data['discount']); |
|
| 51 | + wpinv_update_discount_status($id, 'publish'); |
|
| 52 | 52 | } |
| 53 | -add_action( 'wpinv_activate_discount', 'wpinv_activate_discount' ); |
|
| 53 | +add_action('wpinv_activate_discount', 'wpinv_activate_discount'); |
|
| 54 | 54 | |
| 55 | -function wpinv_deactivate_discount( $data ) { |
|
| 56 | - if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) { |
|
| 57 | - wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 55 | +function wpinv_deactivate_discount($data) { |
|
| 56 | + if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) { |
|
| 57 | + wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - if( ! current_user_can( 'manage_options' ) ) { |
|
| 61 | - wp_die( __( 'You do not have permission to create discount codes', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 60 | + if (!current_user_can('manage_options')) { |
|
| 61 | + wp_die(__('You do not have permission to create discount codes', 'invoicing'), array('response' => 403)); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - $id = absint( $data['discount'] ); |
|
| 65 | - wpinv_update_discount_status( $id, 'pending' ); |
|
| 64 | + $id = absint($data['discount']); |
|
| 65 | + wpinv_update_discount_status($id, 'pending'); |
|
| 66 | 66 | } |
| 67 | -add_action( 'wpinv_deactivate_discount', 'wpinv_deactivate_discount' ); |
|
| 67 | +add_action('wpinv_deactivate_discount', 'wpinv_deactivate_discount'); |
|
| 68 | 68 | |
| 69 | -function wpinv_get_discounts( $args = array() ) { |
|
| 69 | +function wpinv_get_discounts($args = array()) { |
|
| 70 | 70 | $defaults = array( |
| 71 | 71 | 'post_type' => 'wpi_discount', |
| 72 | 72 | 'posts_per_page' => 20, |
| 73 | 73 | 'paged' => null, |
| 74 | - 'post_status' => array( 'publish', 'pending', 'draft', 'expired' ) |
|
| 74 | + 'post_status' => array('publish', 'pending', 'draft', 'expired') |
|
| 75 | 75 | ); |
| 76 | 76 | |
| 77 | - $args = wp_parse_args( $args, $defaults ); |
|
| 77 | + $args = wp_parse_args($args, $defaults); |
|
| 78 | 78 | |
| 79 | - $discounts = get_posts( $args ); |
|
| 79 | + $discounts = get_posts($args); |
|
| 80 | 80 | |
| 81 | - if ( $discounts ) { |
|
| 81 | + if ($discounts) { |
|
| 82 | 82 | return $discounts; |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - if( ! $discounts && ! empty( $args['s'] ) ) { |
|
| 85 | + if (!$discounts && !empty($args['s'])) { |
|
| 86 | 86 | $args['meta_key'] = 'gd_discount_code'; |
| 87 | 87 | $args['meta_value'] = $args['s']; |
| 88 | 88 | $args['meta_compare'] = 'LIKE'; |
| 89 | - unset( $args['s'] ); |
|
| 90 | - $discounts = get_posts( $args ); |
|
| 89 | + unset($args['s']); |
|
| 90 | + $discounts = get_posts($args); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - if( $discounts ) { |
|
| 93 | + if ($discounts) { |
|
| 94 | 94 | return $discounts; |
| 95 | 95 | } |
| 96 | 96 | |
@@ -102,9 +102,9 @@ discard block |
||
| 102 | 102 | |
| 103 | 103 | $discounts = wpinv_get_discounts(); |
| 104 | 104 | |
| 105 | - if ( $discounts) { |
|
| 106 | - foreach ( $discounts as $discount ) { |
|
| 107 | - if ( wpinv_is_discount_active( $discount->ID ) ) { |
|
| 105 | + if ($discounts) { |
|
| 106 | + foreach ($discounts as $discount) { |
|
| 107 | + if (wpinv_is_discount_active($discount->ID)) { |
|
| 108 | 108 | $has_active = true; |
| 109 | 109 | break; |
| 110 | 110 | } |
@@ -113,38 +113,38 @@ discard block |
||
| 113 | 113 | return $has_active; |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | -function wpinv_get_discount( $discount_id = 0 ) { |
|
| 117 | - if( empty( $discount_id ) ) { |
|
| 116 | +function wpinv_get_discount($discount_id = 0) { |
|
| 117 | + if (empty($discount_id)) { |
|
| 118 | 118 | return false; |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - if ( get_post_type( $discount_id ) != 'wpi_discount' ) { |
|
| 121 | + if (get_post_type($discount_id) != 'wpi_discount') { |
|
| 122 | 122 | return false; |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - $discount = get_post( $discount_id ); |
|
| 125 | + $discount = get_post($discount_id); |
|
| 126 | 126 | |
| 127 | 127 | return $discount; |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | -function wpinv_get_discount_by_code( $code = '' ) { |
|
| 131 | - if( empty( $code ) || ! is_string( $code ) ) { |
|
| 130 | +function wpinv_get_discount_by_code($code = '') { |
|
| 131 | + if (empty($code) || !is_string($code)) { |
|
| 132 | 132 | return false; |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | - return wpinv_get_discount_by( 'code', $code ); |
|
| 135 | + return wpinv_get_discount_by('code', $code); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | -function wpinv_get_discount_by( $field = '', $value = '' ) { |
|
| 139 | - if( empty( $field ) || empty( $value ) ) { |
|
| 138 | +function wpinv_get_discount_by($field = '', $value = '') { |
|
| 139 | + if (empty($field) || empty($value)) { |
|
| 140 | 140 | return false; |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - if( ! is_string( $field ) ) { |
|
| 143 | + if (!is_string($field)) { |
|
| 144 | 144 | return false; |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - switch( strtolower( $field ) ) { |
|
| 147 | + switch (strtolower($field)) { |
|
| 148 | 148 | |
| 149 | 149 | case 'code': |
| 150 | 150 | $meta_query = array(); |
@@ -154,32 +154,32 @@ discard block |
||
| 154 | 154 | 'compare' => '=' |
| 155 | 155 | ); |
| 156 | 156 | |
| 157 | - $discount = wpinv_get_discounts( array( |
|
| 157 | + $discount = wpinv_get_discounts(array( |
|
| 158 | 158 | 'posts_per_page' => 1, |
| 159 | 159 | 'post_status' => 'any', |
| 160 | 160 | 'meta_query' => $meta_query, |
| 161 | - ) ); |
|
| 161 | + )); |
|
| 162 | 162 | |
| 163 | - if( $discount ) { |
|
| 163 | + if ($discount) { |
|
| 164 | 164 | $discount = $discount[0]; |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | break; |
| 168 | 168 | |
| 169 | 169 | case 'id': |
| 170 | - $discount = wpinv_get_discount( $value ); |
|
| 170 | + $discount = wpinv_get_discount($value); |
|
| 171 | 171 | |
| 172 | 172 | break; |
| 173 | 173 | |
| 174 | 174 | case 'name': |
| 175 | - $discount = get_posts( array( |
|
| 175 | + $discount = get_posts(array( |
|
| 176 | 176 | 'post_type' => 'wpi_discount', |
| 177 | 177 | 'name' => $value, |
| 178 | 178 | 'posts_per_page' => 1, |
| 179 | 179 | 'post_status' => 'any' |
| 180 | - ) ); |
|
| 180 | + )); |
|
| 181 | 181 | |
| 182 | - if( $discount ) { |
|
| 182 | + if ($discount) { |
|
| 183 | 183 | $discount = $discount[0]; |
| 184 | 184 | } |
| 185 | 185 | |
@@ -189,99 +189,99 @@ discard block |
||
| 189 | 189 | return false; |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | - if( ! empty( $discount ) ) { |
|
| 192 | + if (!empty($discount)) { |
|
| 193 | 193 | return $discount; |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | return false; |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | -function wpinv_store_discount( $post_id, $data, $post, $update = false ) { |
|
| 199 | +function wpinv_store_discount($post_id, $data, $post, $update = false) { |
|
| 200 | 200 | $meta = array( |
| 201 | - 'code' => isset( $data['code'] ) ? sanitize_text_field( $data['code'] ) : '', |
|
| 202 | - 'type' => isset( $data['type'] ) ? sanitize_text_field( $data['type'] ) : 'percent', |
|
| 203 | - 'amount' => isset( $data['amount'] ) ? wpinv_sanitize_amount( $data['amount'] ) : '', |
|
| 204 | - 'start' => isset( $data['start'] ) ? sanitize_text_field( $data['start'] ) : '', |
|
| 205 | - 'expiration' => isset( $data['expiration'] ) ? sanitize_text_field( $data['expiration'] ) : '', |
|
| 206 | - 'min_total' => isset( $data['min_total'] ) ? wpinv_sanitize_amount( $data['min_total'] ) : '', |
|
| 207 | - 'max_total' => isset( $data['max_total'] ) ? wpinv_sanitize_amount( $data['max_total'] ) : '', |
|
| 208 | - 'max_uses' => isset( $data['max_uses'] ) ? absint( $data['max_uses'] ) : '', |
|
| 209 | - 'items' => isset( $data['items'] ) ? $data['items'] : array(), |
|
| 210 | - 'excluded_items' => isset( $data['excluded_items'] ) ? $data['excluded_items'] : array(), |
|
| 211 | - 'is_recurring' => isset( $data['recurring'] ) ? (bool)$data['recurring'] : false, |
|
| 212 | - 'is_single_use' => isset( $data['single_use'] ) ? (bool)$data['single_use'] : false, |
|
| 213 | - 'uses' => isset( $data['uses'] ) ? (int)$data['uses'] : false, |
|
| 201 | + 'code' => isset($data['code']) ? sanitize_text_field($data['code']) : '', |
|
| 202 | + 'type' => isset($data['type']) ? sanitize_text_field($data['type']) : 'percent', |
|
| 203 | + 'amount' => isset($data['amount']) ? wpinv_sanitize_amount($data['amount']) : '', |
|
| 204 | + 'start' => isset($data['start']) ? sanitize_text_field($data['start']) : '', |
|
| 205 | + 'expiration' => isset($data['expiration']) ? sanitize_text_field($data['expiration']) : '', |
|
| 206 | + 'min_total' => isset($data['min_total']) ? wpinv_sanitize_amount($data['min_total']) : '', |
|
| 207 | + 'max_total' => isset($data['max_total']) ? wpinv_sanitize_amount($data['max_total']) : '', |
|
| 208 | + 'max_uses' => isset($data['max_uses']) ? absint($data['max_uses']) : '', |
|
| 209 | + 'items' => isset($data['items']) ? $data['items'] : array(), |
|
| 210 | + 'excluded_items' => isset($data['excluded_items']) ? $data['excluded_items'] : array(), |
|
| 211 | + 'is_recurring' => isset($data['recurring']) ? (bool)$data['recurring'] : false, |
|
| 212 | + 'is_single_use' => isset($data['single_use']) ? (bool)$data['single_use'] : false, |
|
| 213 | + 'uses' => isset($data['uses']) ? (int)$data['uses'] : false, |
|
| 214 | 214 | ); |
| 215 | 215 | |
| 216 | - $start_timestamp = strtotime( $meta['start'] ); |
|
| 216 | + $start_timestamp = strtotime($meta['start']); |
|
| 217 | 217 | |
| 218 | - if ( !empty( $meta['start'] ) ) { |
|
| 219 | - $meta['start'] = date( 'Y-m-d H:i:s', $start_timestamp ); |
|
| 218 | + if (!empty($meta['start'])) { |
|
| 219 | + $meta['start'] = date('Y-m-d H:i:s', $start_timestamp); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | - if ( $meta['type'] == 'percent' && (float)$meta['amount'] > 100 ) { |
|
| 222 | + if ($meta['type'] == 'percent' && (float)$meta['amount'] > 100) { |
|
| 223 | 223 | $meta['amount'] = 100; |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | - if ( !empty( $meta['expiration'] ) ) { |
|
| 227 | - $meta['expiration'] = date( 'Y-m-d H:i:s', strtotime( date( 'Y-m-d', strtotime( $meta['expiration'] ) ) . ' 23:59:59' ) ); |
|
| 228 | - $end_timestamp = strtotime( $meta['expiration'] ); |
|
| 226 | + if (!empty($meta['expiration'])) { |
|
| 227 | + $meta['expiration'] = date('Y-m-d H:i:s', strtotime(date('Y-m-d', strtotime($meta['expiration'])) . ' 23:59:59')); |
|
| 228 | + $end_timestamp = strtotime($meta['expiration']); |
|
| 229 | 229 | |
| 230 | - if ( !empty( $meta['start'] ) && $start_timestamp > $end_timestamp ) { |
|
| 230 | + if (!empty($meta['start']) && $start_timestamp > $end_timestamp) { |
|
| 231 | 231 | $meta['expiration'] = $meta['start']; // Set the expiration date to the start date if start is later than expiration date. |
| 232 | 232 | } |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - if ( $meta['uses'] === false ) { |
|
| 236 | - unset( $meta['uses'] ); |
|
| 235 | + if ($meta['uses'] === false) { |
|
| 236 | + unset($meta['uses']); |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | - if ( ! empty( $meta['items'] ) ) { |
|
| 240 | - foreach ( $meta['items'] as $key => $item ) { |
|
| 241 | - if ( 0 === intval( $item ) ) { |
|
| 242 | - unset( $meta['items'][ $key ] ); |
|
| 239 | + if (!empty($meta['items'])) { |
|
| 240 | + foreach ($meta['items'] as $key => $item) { |
|
| 241 | + if (0 === intval($item)) { |
|
| 242 | + unset($meta['items'][$key]); |
|
| 243 | 243 | } |
| 244 | 244 | } |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | - if ( ! empty( $meta['excluded_items'] ) ) { |
|
| 248 | - foreach ( $meta['excluded_items'] as $key => $item ) { |
|
| 249 | - if ( 0 === intval( $item ) ) { |
|
| 250 | - unset( $meta['excluded_items'][ $key ] ); |
|
| 247 | + if (!empty($meta['excluded_items'])) { |
|
| 248 | + foreach ($meta['excluded_items'] as $key => $item) { |
|
| 249 | + if (0 === intval($item)) { |
|
| 250 | + unset($meta['excluded_items'][$key]); |
|
| 251 | 251 | } |
| 252 | 252 | } |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | - $meta = apply_filters( 'wpinv_update_discount', $meta, $post_id, $post ); |
|
| 255 | + $meta = apply_filters('wpinv_update_discount', $meta, $post_id, $post); |
|
| 256 | 256 | |
| 257 | - do_action( 'wpinv_pre_update_discount', $meta, $post_id, $post ); |
|
| 257 | + do_action('wpinv_pre_update_discount', $meta, $post_id, $post); |
|
| 258 | 258 | |
| 259 | - foreach( $meta as $key => $value ) { |
|
| 260 | - update_post_meta( $post_id, '_wpi_discount_' . $key, $value ); |
|
| 259 | + foreach ($meta as $key => $value) { |
|
| 260 | + update_post_meta($post_id, '_wpi_discount_' . $key, $value); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | - do_action( 'wpinv_post_update_discount', $meta, $post_id, $post ); |
|
| 263 | + do_action('wpinv_post_update_discount', $meta, $post_id, $post); |
|
| 264 | 264 | |
| 265 | 265 | return $post_id; |
| 266 | 266 | } |
| 267 | 267 | |
| 268 | -function wpinv_remove_discount( $discount_id = 0 ) { |
|
| 269 | - do_action( 'wpinv_pre_delete_discount', $discount_id ); |
|
| 268 | +function wpinv_remove_discount($discount_id = 0) { |
|
| 269 | + do_action('wpinv_pre_delete_discount', $discount_id); |
|
| 270 | 270 | |
| 271 | - wp_delete_post( $discount_id, true ); |
|
| 271 | + wp_delete_post($discount_id, true); |
|
| 272 | 272 | |
| 273 | - do_action( 'wpinv_post_delete_discount', $discount_id ); |
|
| 273 | + do_action('wpinv_post_delete_discount', $discount_id); |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | -function wpinv_update_discount_status( $code_id = 0, $new_status = 'publish' ) { |
|
| 277 | - $discount = wpinv_get_discount( $code_id ); |
|
| 276 | +function wpinv_update_discount_status($code_id = 0, $new_status = 'publish') { |
|
| 277 | + $discount = wpinv_get_discount($code_id); |
|
| 278 | 278 | |
| 279 | - if ( $discount ) { |
|
| 280 | - do_action( 'wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status ); |
|
| 279 | + if ($discount) { |
|
| 280 | + do_action('wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status); |
|
| 281 | 281 | |
| 282 | - wp_update_post( array( 'ID' => $code_id, 'post_status' => $new_status ) ); |
|
| 282 | + wp_update_post(array('ID' => $code_id, 'post_status' => $new_status)); |
|
| 283 | 283 | |
| 284 | - do_action( 'wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status ); |
|
| 284 | + do_action('wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status); |
|
| 285 | 285 | |
| 286 | 286 | return true; |
| 287 | 287 | } |
@@ -289,173 +289,173 @@ discard block |
||
| 289 | 289 | return false; |
| 290 | 290 | } |
| 291 | 291 | |
| 292 | -function wpinv_discount_exists( $code_id ) { |
|
| 293 | - if ( wpinv_get_discount( $code_id ) ) { |
|
| 292 | +function wpinv_discount_exists($code_id) { |
|
| 293 | + if (wpinv_get_discount($code_id)) { |
|
| 294 | 294 | return true; |
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | return false; |
| 298 | 298 | } |
| 299 | 299 | |
| 300 | -function wpinv_is_discount_active( $code_id = null ) { |
|
| 301 | - $discount = wpinv_get_discount( $code_id ); |
|
| 300 | +function wpinv_is_discount_active($code_id = null) { |
|
| 301 | + $discount = wpinv_get_discount($code_id); |
|
| 302 | 302 | $return = false; |
| 303 | 303 | |
| 304 | - if ( $discount ) { |
|
| 305 | - if ( wpinv_is_discount_expired( $code_id ) ) { |
|
| 306 | - if( defined( 'DOING_AJAX' ) ) { |
|
| 307 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is expired.', 'invoicing' ) ); |
|
| 304 | + if ($discount) { |
|
| 305 | + if (wpinv_is_discount_expired($code_id)) { |
|
| 306 | + if (defined('DOING_AJAX')) { |
|
| 307 | + wpinv_set_error('wpinv-discount-error', __('This discount is expired.', 'invoicing')); |
|
| 308 | 308 | } |
| 309 | - } elseif ( $discount->post_status == 'publish' ) { |
|
| 309 | + } elseif ($discount->post_status == 'publish') { |
|
| 310 | 310 | $return = true; |
| 311 | 311 | } else { |
| 312 | - if( defined( 'DOING_AJAX' ) ) { |
|
| 313 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active.', 'invoicing' ) ); |
|
| 312 | + if (defined('DOING_AJAX')) { |
|
| 313 | + wpinv_set_error('wpinv-discount-error', __('This discount is not active.', 'invoicing')); |
|
| 314 | 314 | } |
| 315 | 315 | } |
| 316 | 316 | } |
| 317 | 317 | |
| 318 | - return apply_filters( 'wpinv_is_discount_active', $return, $code_id ); |
|
| 318 | + return apply_filters('wpinv_is_discount_active', $return, $code_id); |
|
| 319 | 319 | } |
| 320 | 320 | |
| 321 | -function wpinv_get_discount_code( $code_id = null ) { |
|
| 322 | - $code = get_post_meta( $code_id, '_wpi_discount_code', true ); |
|
| 321 | +function wpinv_get_discount_code($code_id = null) { |
|
| 322 | + $code = get_post_meta($code_id, '_wpi_discount_code', true); |
|
| 323 | 323 | |
| 324 | - return apply_filters( 'wpinv_get_discount_code', $code, $code_id ); |
|
| 324 | + return apply_filters('wpinv_get_discount_code', $code, $code_id); |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | -function wpinv_get_discount_start_date( $code_id = null ) { |
|
| 328 | - $start_date = get_post_meta( $code_id, '_wpi_discount_start', true ); |
|
| 327 | +function wpinv_get_discount_start_date($code_id = null) { |
|
| 328 | + $start_date = get_post_meta($code_id, '_wpi_discount_start', true); |
|
| 329 | 329 | |
| 330 | - return apply_filters( 'wpinv_get_discount_start_date', $start_date, $code_id ); |
|
| 330 | + return apply_filters('wpinv_get_discount_start_date', $start_date, $code_id); |
|
| 331 | 331 | } |
| 332 | 332 | |
| 333 | -function wpinv_get_discount_expiration( $code_id = null ) { |
|
| 334 | - $expiration = get_post_meta( $code_id, '_wpi_discount_expiration', true ); |
|
| 333 | +function wpinv_get_discount_expiration($code_id = null) { |
|
| 334 | + $expiration = get_post_meta($code_id, '_wpi_discount_expiration', true); |
|
| 335 | 335 | |
| 336 | - return apply_filters( 'wpinv_get_discount_expiration', $expiration, $code_id ); |
|
| 336 | + return apply_filters('wpinv_get_discount_expiration', $expiration, $code_id); |
|
| 337 | 337 | } |
| 338 | 338 | |
| 339 | -function wpinv_get_discount_max_uses( $code_id = null ) { |
|
| 340 | - $max_uses = get_post_meta( $code_id, '_wpi_discount_max_uses', true ); |
|
| 339 | +function wpinv_get_discount_max_uses($code_id = null) { |
|
| 340 | + $max_uses = get_post_meta($code_id, '_wpi_discount_max_uses', true); |
|
| 341 | 341 | |
| 342 | - return (int) apply_filters( 'wpinv_get_discount_max_uses', $max_uses, $code_id ); |
|
| 342 | + return (int)apply_filters('wpinv_get_discount_max_uses', $max_uses, $code_id); |
|
| 343 | 343 | } |
| 344 | 344 | |
| 345 | -function wpinv_get_discount_uses( $code_id = null ) { |
|
| 346 | - $uses = get_post_meta( $code_id, '_wpi_discount_uses', true ); |
|
| 345 | +function wpinv_get_discount_uses($code_id = null) { |
|
| 346 | + $uses = get_post_meta($code_id, '_wpi_discount_uses', true); |
|
| 347 | 347 | |
| 348 | - return (int) apply_filters( 'wpinv_get_discount_uses', $uses, $code_id ); |
|
| 348 | + return (int)apply_filters('wpinv_get_discount_uses', $uses, $code_id); |
|
| 349 | 349 | } |
| 350 | 350 | |
| 351 | -function wpinv_get_discount_min_total( $code_id = null ) { |
|
| 352 | - $min_total = get_post_meta( $code_id, '_wpi_discount_min_total', true ); |
|
| 351 | +function wpinv_get_discount_min_total($code_id = null) { |
|
| 352 | + $min_total = get_post_meta($code_id, '_wpi_discount_min_total', true); |
|
| 353 | 353 | |
| 354 | - return (float) apply_filters( 'wpinv_get_discount_min_total', $min_total, $code_id ); |
|
| 354 | + return (float)apply_filters('wpinv_get_discount_min_total', $min_total, $code_id); |
|
| 355 | 355 | } |
| 356 | 356 | |
| 357 | -function wpinv_get_discount_max_total( $code_id = null ) { |
|
| 358 | - $max_total = get_post_meta( $code_id, '_wpi_discount_max_total', true ); |
|
| 357 | +function wpinv_get_discount_max_total($code_id = null) { |
|
| 358 | + $max_total = get_post_meta($code_id, '_wpi_discount_max_total', true); |
|
| 359 | 359 | |
| 360 | - return (float) apply_filters( 'wpinv_get_discount_max_total', $max_total, $code_id ); |
|
| 360 | + return (float)apply_filters('wpinv_get_discount_max_total', $max_total, $code_id); |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | -function wpinv_get_discount_amount( $code_id = null ) { |
|
| 364 | - $amount = get_post_meta( $code_id, '_wpi_discount_amount', true ); |
|
| 363 | +function wpinv_get_discount_amount($code_id = null) { |
|
| 364 | + $amount = get_post_meta($code_id, '_wpi_discount_amount', true); |
|
| 365 | 365 | |
| 366 | - return (float) apply_filters( 'wpinv_get_discount_amount', $amount, $code_id ); |
|
| 366 | + return (float)apply_filters('wpinv_get_discount_amount', $amount, $code_id); |
|
| 367 | 367 | } |
| 368 | 368 | |
| 369 | -function wpinv_get_discount_type( $code_id = null, $name = false ) { |
|
| 370 | - $type = strtolower( get_post_meta( $code_id, '_wpi_discount_type', true ) ); |
|
| 369 | +function wpinv_get_discount_type($code_id = null, $name = false) { |
|
| 370 | + $type = strtolower(get_post_meta($code_id, '_wpi_discount_type', true)); |
|
| 371 | 371 | |
| 372 | - if ( $name ) { |
|
| 373 | - $name = wpinv_get_discount_type_name( $type ); |
|
| 372 | + if ($name) { |
|
| 373 | + $name = wpinv_get_discount_type_name($type); |
|
| 374 | 374 | |
| 375 | - return apply_filters( 'wpinv_get_discount_type_name', $name, $code_id ); |
|
| 375 | + return apply_filters('wpinv_get_discount_type_name', $name, $code_id); |
|
| 376 | 376 | } |
| 377 | 377 | |
| 378 | - return apply_filters( 'wpinv_get_discount_type', $type, $code_id ); |
|
| 378 | + return apply_filters('wpinv_get_discount_type', $type, $code_id); |
|
| 379 | 379 | } |
| 380 | 380 | |
| 381 | -function wpinv_discount_status( $status ) { |
|
| 382 | - switch( $status ){ |
|
| 381 | +function wpinv_discount_status($status) { |
|
| 382 | + switch ($status) { |
|
| 383 | 383 | case 'expired' : |
| 384 | - $name = __( 'Expired', 'invoicing' ); |
|
| 384 | + $name = __('Expired', 'invoicing'); |
|
| 385 | 385 | break; |
| 386 | 386 | case 'publish' : |
| 387 | 387 | case 'active' : |
| 388 | - $name = __( 'Active', 'invoicing' ); |
|
| 388 | + $name = __('Active', 'invoicing'); |
|
| 389 | 389 | break; |
| 390 | 390 | default : |
| 391 | - $name = __( 'Inactive', 'invoicing' ); |
|
| 391 | + $name = __('Inactive', 'invoicing'); |
|
| 392 | 392 | break; |
| 393 | 393 | } |
| 394 | 394 | return $name; |
| 395 | 395 | } |
| 396 | 396 | |
| 397 | -function wpinv_get_discount_excluded_items( $code_id = null ) { |
|
| 398 | - $excluded_items = get_post_meta( $code_id, '_wpi_discount_excluded_items', true ); |
|
| 397 | +function wpinv_get_discount_excluded_items($code_id = null) { |
|
| 398 | + $excluded_items = get_post_meta($code_id, '_wpi_discount_excluded_items', true); |
|
| 399 | 399 | |
| 400 | - if ( empty( $excluded_items ) || ! is_array( $excluded_items ) ) { |
|
| 400 | + if (empty($excluded_items) || !is_array($excluded_items)) { |
|
| 401 | 401 | $excluded_items = array(); |
| 402 | 402 | } |
| 403 | 403 | |
| 404 | - return (array) apply_filters( 'wpinv_get_discount_excluded_items', $excluded_items, $code_id ); |
|
| 404 | + return (array)apply_filters('wpinv_get_discount_excluded_items', $excluded_items, $code_id); |
|
| 405 | 405 | } |
| 406 | 406 | |
| 407 | -function wpinv_get_discount_item_reqs( $code_id = null ) { |
|
| 408 | - $item_reqs = get_post_meta( $code_id, '_wpi_discount_items', true ); |
|
| 407 | +function wpinv_get_discount_item_reqs($code_id = null) { |
|
| 408 | + $item_reqs = get_post_meta($code_id, '_wpi_discount_items', true); |
|
| 409 | 409 | |
| 410 | - if ( empty( $item_reqs ) || ! is_array( $item_reqs ) ) { |
|
| 410 | + if (empty($item_reqs) || !is_array($item_reqs)) { |
|
| 411 | 411 | $item_reqs = array(); |
| 412 | 412 | } |
| 413 | 413 | |
| 414 | - return (array) apply_filters( 'wpinv_get_discount_item_reqs', $item_reqs, $code_id ); |
|
| 414 | + return (array)apply_filters('wpinv_get_discount_item_reqs', $item_reqs, $code_id); |
|
| 415 | 415 | } |
| 416 | 416 | |
| 417 | -function wpinv_get_discount_item_condition( $code_id = 0 ) { |
|
| 418 | - return get_post_meta( $code_id, '_wpi_discount_item_condition', true ); |
|
| 417 | +function wpinv_get_discount_item_condition($code_id = 0) { |
|
| 418 | + return get_post_meta($code_id, '_wpi_discount_item_condition', true); |
|
| 419 | 419 | } |
| 420 | 420 | |
| 421 | -function wpinv_is_discount_not_global( $code_id = 0 ) { |
|
| 422 | - return (bool) get_post_meta( $code_id, '_wpi_discount_is_not_global', true ); |
|
| 421 | +function wpinv_is_discount_not_global($code_id = 0) { |
|
| 422 | + return (bool)get_post_meta($code_id, '_wpi_discount_is_not_global', true); |
|
| 423 | 423 | } |
| 424 | 424 | |
| 425 | -function wpinv_is_discount_expired( $code_id = null ) { |
|
| 426 | - $discount = wpinv_get_discount( $code_id ); |
|
| 425 | +function wpinv_is_discount_expired($code_id = null) { |
|
| 426 | + $discount = wpinv_get_discount($code_id); |
|
| 427 | 427 | $return = false; |
| 428 | 428 | |
| 429 | - if ( $discount ) { |
|
| 430 | - $expiration = wpinv_get_discount_expiration( $code_id ); |
|
| 431 | - if ( $expiration ) { |
|
| 432 | - $expiration = strtotime( $expiration ); |
|
| 433 | - if ( $expiration < current_time( 'timestamp' ) ) { |
|
| 429 | + if ($discount) { |
|
| 430 | + $expiration = wpinv_get_discount_expiration($code_id); |
|
| 431 | + if ($expiration) { |
|
| 432 | + $expiration = strtotime($expiration); |
|
| 433 | + if ($expiration < current_time('timestamp')) { |
|
| 434 | 434 | // Discount is expired |
| 435 | - wpinv_update_discount_status( $code_id, 'pending' ); |
|
| 435 | + wpinv_update_discount_status($code_id, 'pending'); |
|
| 436 | 436 | $return = true; |
| 437 | 437 | } |
| 438 | 438 | } |
| 439 | 439 | } |
| 440 | 440 | |
| 441 | - return apply_filters( 'wpinv_is_discount_expired', $return, $code_id ); |
|
| 441 | + return apply_filters('wpinv_is_discount_expired', $return, $code_id); |
|
| 442 | 442 | } |
| 443 | 443 | |
| 444 | -function wpinv_is_discount_started( $code_id = null ) { |
|
| 445 | - $discount = wpinv_get_discount( $code_id ); |
|
| 444 | +function wpinv_is_discount_started($code_id = null) { |
|
| 445 | + $discount = wpinv_get_discount($code_id); |
|
| 446 | 446 | $return = false; |
| 447 | 447 | |
| 448 | - if ( $discount ) { |
|
| 449 | - $start_date = wpinv_get_discount_start_date( $code_id ); |
|
| 448 | + if ($discount) { |
|
| 449 | + $start_date = wpinv_get_discount_start_date($code_id); |
|
| 450 | 450 | |
| 451 | - if ( $start_date ) { |
|
| 452 | - $start_date = strtotime( $start_date ); |
|
| 451 | + if ($start_date) { |
|
| 452 | + $start_date = strtotime($start_date); |
|
| 453 | 453 | |
| 454 | - if ( $start_date < current_time( 'timestamp' ) ) { |
|
| 454 | + if ($start_date < current_time('timestamp')) { |
|
| 455 | 455 | // Discount has past the start date |
| 456 | 456 | $return = true; |
| 457 | 457 | } else { |
| 458 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) ); |
|
| 458 | + wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing')); |
|
| 459 | 459 | } |
| 460 | 460 | } else { |
| 461 | 461 | // No start date for this discount, so has to be true |
@@ -463,159 +463,159 @@ discard block |
||
| 463 | 463 | } |
| 464 | 464 | } |
| 465 | 465 | |
| 466 | - return apply_filters( 'wpinv_is_discount_started', $return, $code_id ); |
|
| 466 | + return apply_filters('wpinv_is_discount_started', $return, $code_id); |
|
| 467 | 467 | } |
| 468 | 468 | |
| 469 | -function wpinv_check_discount_dates( $code_id = null ) { |
|
| 470 | - $discount = wpinv_get_discount( $code_id ); |
|
| 469 | +function wpinv_check_discount_dates($code_id = null) { |
|
| 470 | + $discount = wpinv_get_discount($code_id); |
|
| 471 | 471 | $return = false; |
| 472 | 472 | |
| 473 | - if ( $discount ) { |
|
| 474 | - $start_date = wpinv_get_discount_start_date( $code_id ); |
|
| 473 | + if ($discount) { |
|
| 474 | + $start_date = wpinv_get_discount_start_date($code_id); |
|
| 475 | 475 | |
| 476 | - if ( $start_date ) { |
|
| 477 | - $start_date = strtotime( $start_date ); |
|
| 476 | + if ($start_date) { |
|
| 477 | + $start_date = strtotime($start_date); |
|
| 478 | 478 | |
| 479 | - if ( $start_date < current_time( 'timestamp' ) ) { |
|
| 479 | + if ($start_date < current_time('timestamp')) { |
|
| 480 | 480 | // Discount has past the start date |
| 481 | 481 | $return = true; |
| 482 | 482 | } else { |
| 483 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) ); |
|
| 483 | + wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing')); |
|
| 484 | 484 | } |
| 485 | 485 | } else { |
| 486 | 486 | // No start date for this discount, so has to be true |
| 487 | 487 | $return = true; |
| 488 | 488 | } |
| 489 | 489 | |
| 490 | - if ( $return ) { |
|
| 491 | - $expiration = wpinv_get_discount_expiration( $code_id ); |
|
| 490 | + if ($return) { |
|
| 491 | + $expiration = wpinv_get_discount_expiration($code_id); |
|
| 492 | 492 | |
| 493 | - if ( $expiration ) { |
|
| 494 | - $expiration = strtotime( $expiration ); |
|
| 495 | - if ( $expiration < current_time( 'timestamp' ) ) { |
|
| 493 | + if ($expiration) { |
|
| 494 | + $expiration = strtotime($expiration); |
|
| 495 | + if ($expiration < current_time('timestamp')) { |
|
| 496 | 496 | // Discount is expired |
| 497 | - wpinv_update_discount_status( $code_id, 'pending' ); |
|
| 497 | + wpinv_update_discount_status($code_id, 'pending'); |
|
| 498 | 498 | $return = true; |
| 499 | 499 | } |
| 500 | 500 | } |
| 501 | 501 | } |
| 502 | 502 | } |
| 503 | 503 | |
| 504 | - return apply_filters( 'wpinv_check_discount_dates', $return, $code_id ); |
|
| 504 | + return apply_filters('wpinv_check_discount_dates', $return, $code_id); |
|
| 505 | 505 | } |
| 506 | 506 | |
| 507 | -function wpinv_is_discount_maxed_out( $code_id = null ) { |
|
| 508 | - $discount = wpinv_get_discount( $code_id ); |
|
| 507 | +function wpinv_is_discount_maxed_out($code_id = null) { |
|
| 508 | + $discount = wpinv_get_discount($code_id); |
|
| 509 | 509 | $return = false; |
| 510 | 510 | |
| 511 | - if ( $discount ) { |
|
| 512 | - $uses = wpinv_get_discount_uses( $code_id ); |
|
| 511 | + if ($discount) { |
|
| 512 | + $uses = wpinv_get_discount_uses($code_id); |
|
| 513 | 513 | // Large number that will never be reached |
| 514 | - $max_uses = wpinv_get_discount_max_uses( $code_id ); |
|
| 514 | + $max_uses = wpinv_get_discount_max_uses($code_id); |
|
| 515 | 515 | // Should never be greater than, but just in case |
| 516 | - if ( $uses >= $max_uses && ! empty( $max_uses ) ) { |
|
| 516 | + if ($uses >= $max_uses && !empty($max_uses)) { |
|
| 517 | 517 | // Discount is maxed out |
| 518 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount has reached its maximum usage.', 'invoicing' ) ); |
|
| 518 | + wpinv_set_error('wpinv-discount-error', __('This discount has reached its maximum usage.', 'invoicing')); |
|
| 519 | 519 | $return = true; |
| 520 | 520 | } |
| 521 | 521 | } |
| 522 | 522 | |
| 523 | - return apply_filters( 'wpinv_is_discount_maxed_out', $return, $code_id ); |
|
| 523 | + return apply_filters('wpinv_is_discount_maxed_out', $return, $code_id); |
|
| 524 | 524 | } |
| 525 | 525 | |
| 526 | -function wpinv_discount_is_min_met( $code_id = null ) { |
|
| 527 | - $discount = wpinv_get_discount( $code_id ); |
|
| 526 | +function wpinv_discount_is_min_met($code_id = null) { |
|
| 527 | + $discount = wpinv_get_discount($code_id); |
|
| 528 | 528 | $return = false; |
| 529 | 529 | |
| 530 | - if ( $discount ) { |
|
| 531 | - $min = (float)wpinv_get_discount_min_total( $code_id ); |
|
| 532 | - $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id ); |
|
| 530 | + if ($discount) { |
|
| 531 | + $min = (float)wpinv_get_discount_min_total($code_id); |
|
| 532 | + $cart_amount = (float)wpinv_get_cart_discountable_subtotal($code_id); |
|
| 533 | 533 | |
| 534 | - if ( !$min > 0 || $cart_amount >= $min ) { |
|
| 534 | + if (!$min > 0 || $cart_amount >= $min) { |
|
| 535 | 535 | // Minimum has been met |
| 536 | 536 | $return = true; |
| 537 | 537 | } else { |
| 538 | - wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Minimum invoice of %s not met.', 'invoicing' ), wpinv_price( wpinv_format_amount( $min ) ) ) ); |
|
| 538 | + wpinv_set_error('wpinv-discount-error', sprintf(__('Minimum invoice of %s not met.', 'invoicing'), wpinv_price(wpinv_format_amount($min)))); |
|
| 539 | 539 | } |
| 540 | 540 | } |
| 541 | 541 | |
| 542 | - return apply_filters( 'wpinv_is_discount_min_met', $return, $code_id ); |
|
| 542 | + return apply_filters('wpinv_is_discount_min_met', $return, $code_id); |
|
| 543 | 543 | } |
| 544 | 544 | |
| 545 | -function wpinv_discount_is_max_met( $code_id = null ) { |
|
| 546 | - $discount = wpinv_get_discount( $code_id ); |
|
| 545 | +function wpinv_discount_is_max_met($code_id = null) { |
|
| 546 | + $discount = wpinv_get_discount($code_id); |
|
| 547 | 547 | $return = false; |
| 548 | 548 | |
| 549 | - if ( $discount ) { |
|
| 550 | - $max = (float)wpinv_get_discount_max_total( $code_id ); |
|
| 551 | - $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id ); |
|
| 549 | + if ($discount) { |
|
| 550 | + $max = (float)wpinv_get_discount_max_total($code_id); |
|
| 551 | + $cart_amount = (float)wpinv_get_cart_discountable_subtotal($code_id); |
|
| 552 | 552 | |
| 553 | - if ( !$max > 0 || $cart_amount <= $max ) { |
|
| 553 | + if (!$max > 0 || $cart_amount <= $max) { |
|
| 554 | 554 | // Minimum has been met |
| 555 | 555 | $return = true; |
| 556 | 556 | } else { |
| 557 | - wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Maximum invoice of %s not met.', 'invoicing' ), wpinv_price( wpinv_format_amount( $max ) ) ) ); |
|
| 557 | + wpinv_set_error('wpinv-discount-error', sprintf(__('Maximum invoice of %s not met.', 'invoicing'), wpinv_price(wpinv_format_amount($max)))); |
|
| 558 | 558 | } |
| 559 | 559 | } |
| 560 | 560 | |
| 561 | - return apply_filters( 'wpinv_is_discount_max_met', $return, $code_id ); |
|
| 561 | + return apply_filters('wpinv_is_discount_max_met', $return, $code_id); |
|
| 562 | 562 | } |
| 563 | 563 | |
| 564 | -function wpinv_discount_is_single_use( $code_id = 0 ) { |
|
| 565 | - $single_use = get_post_meta( $code_id, '_wpi_discount_is_single_use', true ); |
|
| 566 | - return (bool) apply_filters( 'wpinv_is_discount_single_use', $single_use, $code_id ); |
|
| 564 | +function wpinv_discount_is_single_use($code_id = 0) { |
|
| 565 | + $single_use = get_post_meta($code_id, '_wpi_discount_is_single_use', true); |
|
| 566 | + return (bool)apply_filters('wpinv_is_discount_single_use', $single_use, $code_id); |
|
| 567 | 567 | } |
| 568 | 568 | |
| 569 | -function wpinv_discount_is_recurring( $code_id = 0, $code = false ) { |
|
| 570 | - if ( $code ) { |
|
| 571 | - $discount = wpinv_get_discount_by_code( $code_id ); |
|
| 569 | +function wpinv_discount_is_recurring($code_id = 0, $code = false) { |
|
| 570 | + if ($code) { |
|
| 571 | + $discount = wpinv_get_discount_by_code($code_id); |
|
| 572 | 572 | |
| 573 | - if ( !empty( $discount ) ) { |
|
| 573 | + if (!empty($discount)) { |
|
| 574 | 574 | $code_id = $discount->ID; |
| 575 | 575 | } |
| 576 | 576 | } |
| 577 | 577 | |
| 578 | - $recurring = get_post_meta( $code_id, '_wpi_discount_is_recurring', true ); |
|
| 578 | + $recurring = get_post_meta($code_id, '_wpi_discount_is_recurring', true); |
|
| 579 | 579 | |
| 580 | - return (bool) apply_filters( 'wpinv_is_discount_recurring', $recurring, $code_id, $code ); |
|
| 580 | + return (bool)apply_filters('wpinv_is_discount_recurring', $recurring, $code_id, $code); |
|
| 581 | 581 | } |
| 582 | 582 | |
| 583 | -function wpinv_discount_item_reqs_met( $code_id = null ) { |
|
| 584 | - $item_reqs = wpinv_get_discount_item_reqs( $code_id ); |
|
| 585 | - $condition = wpinv_get_discount_item_condition( $code_id ); |
|
| 586 | - $excluded_ps = wpinv_get_discount_excluded_items( $code_id ); |
|
| 583 | +function wpinv_discount_item_reqs_met($code_id = null) { |
|
| 584 | + $item_reqs = wpinv_get_discount_item_reqs($code_id); |
|
| 585 | + $condition = wpinv_get_discount_item_condition($code_id); |
|
| 586 | + $excluded_ps = wpinv_get_discount_excluded_items($code_id); |
|
| 587 | 587 | $cart_items = wpinv_get_cart_contents(); |
| 588 | - $cart_ids = $cart_items ? wp_list_pluck( $cart_items, 'id' ) : null; |
|
| 588 | + $cart_ids = $cart_items ? wp_list_pluck($cart_items, 'id') : null; |
|
| 589 | 589 | $ret = false; |
| 590 | 590 | |
| 591 | - if ( empty( $item_reqs ) && empty( $excluded_ps ) ) { |
|
| 591 | + if (empty($item_reqs) && empty($excluded_ps)) { |
|
| 592 | 592 | $ret = true; |
| 593 | 593 | } |
| 594 | 594 | |
| 595 | 595 | // Normalize our data for item requirements, exclusions and cart data |
| 596 | 596 | // First absint the items, then sort, and reset the array keys |
| 597 | - $item_reqs = array_map( 'absint', $item_reqs ); |
|
| 598 | - asort( $item_reqs ); |
|
| 599 | - $item_reqs = array_values( $item_reqs ); |
|
| 597 | + $item_reqs = array_map('absint', $item_reqs); |
|
| 598 | + asort($item_reqs); |
|
| 599 | + $item_reqs = array_values($item_reqs); |
|
| 600 | 600 | |
| 601 | - $excluded_ps = array_map( 'absint', $excluded_ps ); |
|
| 602 | - asort( $excluded_ps ); |
|
| 603 | - $excluded_ps = array_values( $excluded_ps ); |
|
| 601 | + $excluded_ps = array_map('absint', $excluded_ps); |
|
| 602 | + asort($excluded_ps); |
|
| 603 | + $excluded_ps = array_values($excluded_ps); |
|
| 604 | 604 | |
| 605 | - $cart_ids = array_map( 'absint', $cart_ids ); |
|
| 606 | - asort( $cart_ids ); |
|
| 607 | - $cart_ids = array_values( $cart_ids ); |
|
| 605 | + $cart_ids = array_map('absint', $cart_ids); |
|
| 606 | + asort($cart_ids); |
|
| 607 | + $cart_ids = array_values($cart_ids); |
|
| 608 | 608 | |
| 609 | 609 | // Ensure we have requirements before proceeding |
| 610 | - if ( !$ret && ! empty( $item_reqs ) ) { |
|
| 611 | - switch( $condition ) { |
|
| 610 | + if (!$ret && !empty($item_reqs)) { |
|
| 611 | + switch ($condition) { |
|
| 612 | 612 | case 'all' : |
| 613 | 613 | // Default back to true |
| 614 | 614 | $ret = true; |
| 615 | 615 | |
| 616 | - foreach ( $item_reqs as $item_id ) { |
|
| 617 | - if ( !wpinv_item_in_cart( $item_id ) ) { |
|
| 618 | - wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) ); |
|
| 616 | + foreach ($item_reqs as $item_id) { |
|
| 617 | + if (!wpinv_item_in_cart($item_id)) { |
|
| 618 | + wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing')); |
|
| 619 | 619 | $ret = false; |
| 620 | 620 | break; |
| 621 | 621 | } |
@@ -624,15 +624,15 @@ discard block |
||
| 624 | 624 | break; |
| 625 | 625 | |
| 626 | 626 | default : // Any |
| 627 | - foreach ( $item_reqs as $item_id ) { |
|
| 628 | - if ( wpinv_item_in_cart( $item_id ) ) { |
|
| 627 | + foreach ($item_reqs as $item_id) { |
|
| 628 | + if (wpinv_item_in_cart($item_id)) { |
|
| 629 | 629 | $ret = true; |
| 630 | 630 | break; |
| 631 | 631 | } |
| 632 | 632 | } |
| 633 | 633 | |
| 634 | - if( ! $ret ) { |
|
| 635 | - wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) ); |
|
| 634 | + if (!$ret) { |
|
| 635 | + wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing')); |
|
| 636 | 636 | } |
| 637 | 637 | |
| 638 | 638 | break; |
@@ -641,68 +641,68 @@ discard block |
||
| 641 | 641 | $ret = true; |
| 642 | 642 | } |
| 643 | 643 | |
| 644 | - if( ! empty( $excluded_ps ) ) { |
|
| 644 | + if (!empty($excluded_ps)) { |
|
| 645 | 645 | // Check that there are items other than excluded ones in the cart |
| 646 | - if( $cart_ids == $excluded_ps ) { |
|
| 647 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not valid for the cart contents.', 'invoicing' ) ); |
|
| 646 | + if ($cart_ids == $excluded_ps) { |
|
| 647 | + wpinv_set_error('wpinv-discount-error', __('This discount is not valid for the cart contents.', 'invoicing')); |
|
| 648 | 648 | $ret = false; |
| 649 | 649 | } |
| 650 | 650 | } |
| 651 | 651 | |
| 652 | - return (bool) apply_filters( 'wpinv_is_discount_item_req_met', $ret, $code_id, $condition ); |
|
| 652 | + return (bool)apply_filters('wpinv_is_discount_item_req_met', $ret, $code_id, $condition); |
|
| 653 | 653 | } |
| 654 | 654 | |
| 655 | -function wpinv_is_discount_used( $code = null, $user = '', $code_id = 0 ) { |
|
| 655 | +function wpinv_is_discount_used($code = null, $user = '', $code_id = 0) { |
|
| 656 | 656 | global $wpi_checkout_id; |
| 657 | 657 | |
| 658 | 658 | $return = false; |
| 659 | 659 | |
| 660 | - if ( empty( $code_id ) ) { |
|
| 661 | - $code_id = wpinv_get_discount_id_by_code( $code ); |
|
| 660 | + if (empty($code_id)) { |
|
| 661 | + $code_id = wpinv_get_discount_id_by_code($code); |
|
| 662 | 662 | |
| 663 | - if( empty( $code_id ) ) { |
|
| 663 | + if (empty($code_id)) { |
|
| 664 | 664 | return false; // No discount was found |
| 665 | 665 | } |
| 666 | 666 | } |
| 667 | 667 | |
| 668 | - if ( wpinv_discount_is_single_use( $code_id ) ) { |
|
| 668 | + if (wpinv_discount_is_single_use($code_id)) { |
|
| 669 | 669 | $payments = array(); |
| 670 | 670 | |
| 671 | 671 | $user_id = 0; |
| 672 | - if ( is_int( $user ) ) { |
|
| 672 | + if (is_int($user)) { |
|
| 673 | 673 | $user_id = $user; |
| 674 | - } else if ( is_email( $user ) && $user_data = get_user_by( 'email', $user ) ) { |
|
| 674 | + } else if (is_email($user) && $user_data = get_user_by('email', $user)) { |
|
| 675 | 675 | $user_id = $user_data->ID; |
| 676 | - } else if ( $user_data = get_user_by( 'login', $user ) ) { |
|
| 676 | + } else if ($user_data = get_user_by('login', $user)) { |
|
| 677 | 677 | $user_id = $user_data->ID; |
| 678 | 678 | } |
| 679 | 679 | |
| 680 | - if ( !$user_id ) { |
|
| 681 | - $query = array( 'user' => $user_id, 'limit' => false ); |
|
| 682 | - $payments = wpinv_get_invoices( $query ); // Get all payments with matching email |
|
| 680 | + if (!$user_id) { |
|
| 681 | + $query = array('user' => $user_id, 'limit' => false); |
|
| 682 | + $payments = wpinv_get_invoices($query); // Get all payments with matching email |
|
| 683 | 683 | } |
| 684 | 684 | |
| 685 | - if ( $payments ) { |
|
| 686 | - foreach ( $payments as $payment ) { |
|
| 687 | - if ( $payment->has_status( array( 'wpi-cancelled', 'wpi-failed' ) ) ) { |
|
| 685 | + if ($payments) { |
|
| 686 | + foreach ($payments as $payment) { |
|
| 687 | + if ($payment->has_status(array('wpi-cancelled', 'wpi-failed'))) { |
|
| 688 | 688 | continue; |
| 689 | 689 | } |
| 690 | 690 | |
| 691 | 691 | // Don't count discount used for current invoice chekcout. |
| 692 | - if ( !empty( $wpi_checkout_id ) && $wpi_checkout_id == $payment->ID ) { |
|
| 692 | + if (!empty($wpi_checkout_id) && $wpi_checkout_id == $payment->ID) { |
|
| 693 | 693 | continue; |
| 694 | 694 | } |
| 695 | 695 | |
| 696 | - $discounts = $payment->get_discounts( true ); |
|
| 697 | - if ( empty( $discounts ) ) { |
|
| 696 | + $discounts = $payment->get_discounts(true); |
|
| 697 | + if (empty($discounts)) { |
|
| 698 | 698 | continue; |
| 699 | 699 | } |
| 700 | 700 | |
| 701 | - $discounts = $discounts && !is_array( $discounts ) ? explode( ',', $discounts ) : $discounts; |
|
| 701 | + $discounts = $discounts && !is_array($discounts) ? explode(',', $discounts) : $discounts; |
|
| 702 | 702 | |
| 703 | - if ( !empty( $discounts ) && is_array( $discounts ) ) { |
|
| 704 | - if ( in_array( strtolower( $code ), array_map( 'strtolower', $discounts ) ) ) { |
|
| 705 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount has already been redeemed.', 'invoicing' ) ); |
|
| 703 | + if (!empty($discounts) && is_array($discounts)) { |
|
| 704 | + if (in_array(strtolower($code), array_map('strtolower', $discounts))) { |
|
| 705 | + wpinv_set_error('wpinv-discount-error', __('This discount has already been redeemed.', 'invoicing')); |
|
| 706 | 706 | $return = true; |
| 707 | 707 | break; |
| 708 | 708 | } |
@@ -711,61 +711,61 @@ discard block |
||
| 711 | 711 | } |
| 712 | 712 | } |
| 713 | 713 | |
| 714 | - return apply_filters( 'wpinv_is_discount_used', $return, $code, $user ); |
|
| 714 | + return apply_filters('wpinv_is_discount_used', $return, $code, $user); |
|
| 715 | 715 | } |
| 716 | 716 | |
| 717 | -function wpinv_is_discount_valid( $code = '', $user = '', $set_error = true ) { |
|
| 717 | +function wpinv_is_discount_valid($code = '', $user = '', $set_error = true) { |
|
| 718 | 718 | $return = false; |
| 719 | - $discount_id = wpinv_get_discount_id_by_code( $code ); |
|
| 720 | - $user = trim( $user ); |
|
| 719 | + $discount_id = wpinv_get_discount_id_by_code($code); |
|
| 720 | + $user = trim($user); |
|
| 721 | 721 | |
| 722 | - if ( wpinv_get_cart_contents() ) { |
|
| 723 | - if ( $discount_id ) { |
|
| 722 | + if (wpinv_get_cart_contents()) { |
|
| 723 | + if ($discount_id) { |
|
| 724 | 724 | if ( |
| 725 | - wpinv_is_discount_active( $discount_id ) && |
|
| 726 | - wpinv_check_discount_dates( $discount_id ) && |
|
| 727 | - !wpinv_is_discount_maxed_out( $discount_id ) && |
|
| 728 | - !wpinv_is_discount_used( $code, $user, $discount_id ) && |
|
| 729 | - wpinv_discount_is_min_met( $discount_id ) && |
|
| 730 | - wpinv_discount_is_max_met( $discount_id ) && |
|
| 731 | - wpinv_discount_item_reqs_met( $discount_id ) |
|
| 725 | + wpinv_is_discount_active($discount_id) && |
|
| 726 | + wpinv_check_discount_dates($discount_id) && |
|
| 727 | + !wpinv_is_discount_maxed_out($discount_id) && |
|
| 728 | + !wpinv_is_discount_used($code, $user, $discount_id) && |
|
| 729 | + wpinv_discount_is_min_met($discount_id) && |
|
| 730 | + wpinv_discount_is_max_met($discount_id) && |
|
| 731 | + wpinv_discount_item_reqs_met($discount_id) |
|
| 732 | 732 | ) { |
| 733 | 733 | $return = true; |
| 734 | 734 | } |
| 735 | - } elseif( $set_error ) { |
|
| 736 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is invalid.', 'invoicing' ) ); |
|
| 735 | + } elseif ($set_error) { |
|
| 736 | + wpinv_set_error('wpinv-discount-error', __('This discount is invalid.', 'invoicing')); |
|
| 737 | 737 | } |
| 738 | 738 | } |
| 739 | 739 | |
| 740 | - return apply_filters( 'wpinv_is_discount_valid', $return, $discount_id, $code, $user ); |
|
| 740 | + return apply_filters('wpinv_is_discount_valid', $return, $discount_id, $code, $user); |
|
| 741 | 741 | } |
| 742 | 742 | |
| 743 | -function wpinv_get_discount_id_by_code( $code ) { |
|
| 744 | - $discount = wpinv_get_discount_by_code( $code ); |
|
| 745 | - if( $discount ) { |
|
| 743 | +function wpinv_get_discount_id_by_code($code) { |
|
| 744 | + $discount = wpinv_get_discount_by_code($code); |
|
| 745 | + if ($discount) { |
|
| 746 | 746 | return $discount->ID; |
| 747 | 747 | } |
| 748 | 748 | return false; |
| 749 | 749 | } |
| 750 | 750 | |
| 751 | -function wpinv_get_discounted_amount( $code, $base_price ) { |
|
| 751 | +function wpinv_get_discounted_amount($code, $base_price) { |
|
| 752 | 752 | $amount = $base_price; |
| 753 | - $discount_id = wpinv_get_discount_id_by_code( $code ); |
|
| 753 | + $discount_id = wpinv_get_discount_id_by_code($code); |
|
| 754 | 754 | |
| 755 | - if( $discount_id ) { |
|
| 756 | - $type = wpinv_get_discount_type( $discount_id ); |
|
| 757 | - $rate = wpinv_get_discount_amount( $discount_id ); |
|
| 755 | + if ($discount_id) { |
|
| 756 | + $type = wpinv_get_discount_type($discount_id); |
|
| 757 | + $rate = wpinv_get_discount_amount($discount_id); |
|
| 758 | 758 | |
| 759 | - if ( $type == 'flat' ) { |
|
| 759 | + if ($type == 'flat') { |
|
| 760 | 760 | // Set amount |
| 761 | 761 | $amount = $base_price - $rate; |
| 762 | - if ( $amount < 0 ) { |
|
| 762 | + if ($amount < 0) { |
|
| 763 | 763 | $amount = 0; |
| 764 | 764 | } |
| 765 | 765 | |
| 766 | 766 | } else { |
| 767 | 767 | // Percentage discount |
| 768 | - $amount = $base_price - ( $base_price * ( $rate / 100 ) ); |
|
| 768 | + $amount = $base_price - ($base_price * ($rate / 100)); |
|
| 769 | 769 | } |
| 770 | 770 | |
| 771 | 771 | } else { |
@@ -774,108 +774,108 @@ discard block |
||
| 774 | 774 | |
| 775 | 775 | } |
| 776 | 776 | |
| 777 | - return apply_filters( 'wpinv_discounted_amount', $amount ); |
|
| 777 | + return apply_filters('wpinv_discounted_amount', $amount); |
|
| 778 | 778 | } |
| 779 | 779 | |
| 780 | -function wpinv_increase_discount_usage( $code ) { |
|
| 780 | +function wpinv_increase_discount_usage($code) { |
|
| 781 | 781 | |
| 782 | - $id = wpinv_get_discount_id_by_code( $code ); |
|
| 783 | - $uses = wpinv_get_discount_uses( $id ); |
|
| 782 | + $id = wpinv_get_discount_id_by_code($code); |
|
| 783 | + $uses = wpinv_get_discount_uses($id); |
|
| 784 | 784 | |
| 785 | - if ( $uses ) { |
|
| 785 | + if ($uses) { |
|
| 786 | 786 | $uses++; |
| 787 | 787 | } else { |
| 788 | 788 | $uses = 1; |
| 789 | 789 | } |
| 790 | 790 | |
| 791 | - update_post_meta( $id, '_wpi_discount_uses', $uses ); |
|
| 791 | + update_post_meta($id, '_wpi_discount_uses', $uses); |
|
| 792 | 792 | |
| 793 | - do_action( 'wpinv_discount_increase_use_count', $uses, $id, $code ); |
|
| 793 | + do_action('wpinv_discount_increase_use_count', $uses, $id, $code); |
|
| 794 | 794 | |
| 795 | 795 | return $uses; |
| 796 | 796 | |
| 797 | 797 | } |
| 798 | 798 | |
| 799 | -function wpinv_decrease_discount_usage( $code ) { |
|
| 799 | +function wpinv_decrease_discount_usage($code) { |
|
| 800 | 800 | |
| 801 | - $id = wpinv_get_discount_id_by_code( $code ); |
|
| 802 | - $uses = wpinv_get_discount_uses( $id ); |
|
| 801 | + $id = wpinv_get_discount_id_by_code($code); |
|
| 802 | + $uses = wpinv_get_discount_uses($id); |
|
| 803 | 803 | |
| 804 | - if ( $uses ) { |
|
| 804 | + if ($uses) { |
|
| 805 | 805 | $uses--; |
| 806 | 806 | } |
| 807 | 807 | |
| 808 | - if ( $uses < 0 ) { |
|
| 808 | + if ($uses < 0) { |
|
| 809 | 809 | $uses = 0; |
| 810 | 810 | } |
| 811 | 811 | |
| 812 | - update_post_meta( $id, '_wpi_discount_uses', $uses ); |
|
| 812 | + update_post_meta($id, '_wpi_discount_uses', $uses); |
|
| 813 | 813 | |
| 814 | - do_action( 'wpinv_discount_decrease_use_count', $uses, $id, $code ); |
|
| 814 | + do_action('wpinv_discount_decrease_use_count', $uses, $id, $code); |
|
| 815 | 815 | |
| 816 | 816 | return $uses; |
| 817 | 817 | |
| 818 | 818 | } |
| 819 | 819 | |
| 820 | -function wpinv_format_discount_rate( $type, $amount ) { |
|
| 821 | - if ( $type == 'flat' ) { |
|
| 822 | - return wpinv_price( wpinv_format_amount( $amount ) ); |
|
| 820 | +function wpinv_format_discount_rate($type, $amount) { |
|
| 821 | + if ($type == 'flat') { |
|
| 822 | + return wpinv_price(wpinv_format_amount($amount)); |
|
| 823 | 823 | } else { |
| 824 | 824 | return $amount . '%'; |
| 825 | 825 | } |
| 826 | 826 | } |
| 827 | 827 | |
| 828 | -function wpinv_set_cart_discount( $code = '' ) { |
|
| 829 | - if ( wpinv_multiple_discounts_allowed() ) { |
|
| 828 | +function wpinv_set_cart_discount($code = '') { |
|
| 829 | + if (wpinv_multiple_discounts_allowed()) { |
|
| 830 | 830 | // Get all active cart discounts |
| 831 | 831 | $discounts = wpinv_get_cart_discounts(); |
| 832 | 832 | } else { |
| 833 | 833 | $discounts = false; // Only one discount allowed per purchase, so override any existing |
| 834 | 834 | } |
| 835 | 835 | |
| 836 | - if ( $discounts ) { |
|
| 837 | - $key = array_search( strtolower( $code ), array_map( 'strtolower', $discounts ) ); |
|
| 838 | - if( false !== $key ) { |
|
| 839 | - unset( $discounts[ $key ] ); // Can't set the same discount more than once |
|
| 836 | + if ($discounts) { |
|
| 837 | + $key = array_search(strtolower($code), array_map('strtolower', $discounts)); |
|
| 838 | + if (false !== $key) { |
|
| 839 | + unset($discounts[$key]); // Can't set the same discount more than once |
|
| 840 | 840 | } |
| 841 | 841 | $discounts[] = $code; |
| 842 | 842 | } else { |
| 843 | 843 | $discounts = array(); |
| 844 | 844 | $discounts[] = $code; |
| 845 | 845 | } |
| 846 | - $discounts = array_values( $discounts ); |
|
| 846 | + $discounts = array_values($discounts); |
|
| 847 | 847 | |
| 848 | 848 | $data = wpinv_get_checkout_session(); |
| 849 | - if ( empty( $data ) ) { |
|
| 849 | + if (empty($data)) { |
|
| 850 | 850 | $data = array(); |
| 851 | 851 | } else { |
| 852 | - if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) { |
|
| 853 | - $payment_meta['user_info']['discount'] = implode( ',', $discounts ); |
|
| 854 | - update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta ); |
|
| 852 | + if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) { |
|
| 853 | + $payment_meta['user_info']['discount'] = implode(',', $discounts); |
|
| 854 | + update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta); |
|
| 855 | 855 | } |
| 856 | 856 | } |
| 857 | 857 | $data['cart_discounts'] = $discounts; |
| 858 | 858 | |
| 859 | - wpinv_set_checkout_session( $data ); |
|
| 859 | + wpinv_set_checkout_session($data); |
|
| 860 | 860 | |
| 861 | 861 | return $discounts; |
| 862 | 862 | } |
| 863 | 863 | |
| 864 | -function wpinv_unset_cart_discount( $code = '' ) { |
|
| 864 | +function wpinv_unset_cart_discount($code = '') { |
|
| 865 | 865 | $discounts = wpinv_get_cart_discounts(); |
| 866 | 866 | |
| 867 | - if ( $code && !empty( $discounts ) && in_array( $code, $discounts ) ) { |
|
| 868 | - $key = array_search( $code, $discounts ); |
|
| 869 | - unset( $discounts[ $key ] ); |
|
| 867 | + if ($code && !empty($discounts) && in_array($code, $discounts)) { |
|
| 868 | + $key = array_search($code, $discounts); |
|
| 869 | + unset($discounts[$key]); |
|
| 870 | 870 | |
| 871 | 871 | $data = wpinv_get_checkout_session(); |
| 872 | 872 | $data['cart_discounts'] = $discounts; |
| 873 | - if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) { |
|
| 874 | - $payment_meta['user_info']['discount'] = !empty( $discounts ) ? implode( ',', $discounts ) : ''; |
|
| 875 | - update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta ); |
|
| 873 | + if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) { |
|
| 874 | + $payment_meta['user_info']['discount'] = !empty($discounts) ? implode(',', $discounts) : ''; |
|
| 875 | + update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta); |
|
| 876 | 876 | } |
| 877 | 877 | |
| 878 | - wpinv_set_checkout_session( $data ); |
|
| 878 | + wpinv_set_checkout_session($data); |
|
| 879 | 879 | } |
| 880 | 880 | |
| 881 | 881 | return $discounts; |
@@ -884,27 +884,27 @@ discard block |
||
| 884 | 884 | function wpinv_unset_all_cart_discounts() { |
| 885 | 885 | $data = wpinv_get_checkout_session(); |
| 886 | 886 | |
| 887 | - if ( !empty( $data ) && isset( $data['cart_discounts'] ) ) { |
|
| 888 | - unset( $data['cart_discounts'] ); |
|
| 887 | + if (!empty($data) && isset($data['cart_discounts'])) { |
|
| 888 | + unset($data['cart_discounts']); |
|
| 889 | 889 | |
| 890 | - wpinv_set_checkout_session( $data ); |
|
| 890 | + wpinv_set_checkout_session($data); |
|
| 891 | 891 | return true; |
| 892 | 892 | } |
| 893 | 893 | |
| 894 | 894 | return false; |
| 895 | 895 | } |
| 896 | 896 | |
| 897 | -function wpinv_get_cart_discounts( $items = array() ) { |
|
| 897 | +function wpinv_get_cart_discounts($items = array()) { |
|
| 898 | 898 | $session = wpinv_get_checkout_session(); |
| 899 | 899 | |
| 900 | - $discounts = !empty( $session['cart_discounts'] ) ? $session['cart_discounts'] : false; |
|
| 900 | + $discounts = !empty($session['cart_discounts']) ? $session['cart_discounts'] : false; |
|
| 901 | 901 | return $discounts; |
| 902 | 902 | } |
| 903 | 903 | |
| 904 | -function wpinv_cart_has_discounts( $items = array() ) { |
|
| 904 | +function wpinv_cart_has_discounts($items = array()) { |
|
| 905 | 905 | $ret = false; |
| 906 | 906 | |
| 907 | - if ( wpinv_get_cart_discounts( $items ) ) { |
|
| 907 | + if (wpinv_get_cart_discounts($items)) { |
|
| 908 | 908 | $ret = true; |
| 909 | 909 | } |
| 910 | 910 | |
@@ -915,131 +915,131 @@ discard block |
||
| 915 | 915 | } |
| 916 | 916 | */ |
| 917 | 917 | |
| 918 | - return apply_filters( 'wpinv_cart_has_discounts', $ret ); |
|
| 918 | + return apply_filters('wpinv_cart_has_discounts', $ret); |
|
| 919 | 919 | } |
| 920 | 920 | |
| 921 | -function wpinv_get_cart_discounted_amount( $items = array(), $discounts = false ) { |
|
| 921 | +function wpinv_get_cart_discounted_amount($items = array(), $discounts = false) { |
|
| 922 | 922 | $amount = 0.00; |
| 923 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
| 923 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
| 924 | 924 | |
| 925 | - if ( $items ) { |
|
| 926 | - $discounts = wp_list_pluck( $items, 'discount' ); |
|
| 925 | + if ($items) { |
|
| 926 | + $discounts = wp_list_pluck($items, 'discount'); |
|
| 927 | 927 | |
| 928 | - if ( is_array( $discounts ) ) { |
|
| 929 | - $discounts = array_map( 'floatval', $discounts ); |
|
| 930 | - $amount = array_sum( $discounts ); |
|
| 928 | + if (is_array($discounts)) { |
|
| 929 | + $discounts = array_map('floatval', $discounts); |
|
| 930 | + $amount = array_sum($discounts); |
|
| 931 | 931 | } |
| 932 | 932 | } |
| 933 | 933 | |
| 934 | - return apply_filters( 'wpinv_get_cart_discounted_amount', $amount ); |
|
| 934 | + return apply_filters('wpinv_get_cart_discounted_amount', $amount); |
|
| 935 | 935 | } |
| 936 | 936 | |
| 937 | -function wpinv_get_cart_items_discount_amount( $items = array(), $discount = false ) { |
|
| 938 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
| 937 | +function wpinv_get_cart_items_discount_amount($items = array(), $discount = false) { |
|
| 938 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
| 939 | 939 | |
| 940 | - if ( empty( $discount ) || empty( $items ) ) { |
|
| 940 | + if (empty($discount) || empty($items)) { |
|
| 941 | 941 | return 0; |
| 942 | 942 | } |
| 943 | 943 | |
| 944 | 944 | $amount = 0; |
| 945 | 945 | |
| 946 | - foreach ( $items as $item ) { |
|
| 947 | - $amount += wpinv_get_cart_item_discount_amount( $item, $discount ); |
|
| 946 | + foreach ($items as $item) { |
|
| 947 | + $amount += wpinv_get_cart_item_discount_amount($item, $discount); |
|
| 948 | 948 | } |
| 949 | 949 | |
| 950 | - $amount = wpinv_round_amount( $amount ); |
|
| 950 | + $amount = wpinv_round_amount($amount); |
|
| 951 | 951 | |
| 952 | 952 | return $amount; |
| 953 | 953 | } |
| 954 | 954 | |
| 955 | -function wpinv_get_cart_item_discount_amount( $item = array(), $discount = false ) { |
|
| 955 | +function wpinv_get_cart_item_discount_amount($item = array(), $discount = false) { |
|
| 956 | 956 | global $wpinv_is_last_cart_item, $wpinv_flat_discount_total; |
| 957 | 957 | |
| 958 | 958 | $amount = 0; |
| 959 | 959 | |
| 960 | - if ( empty( $item ) || empty( $item['id'] ) ) { |
|
| 960 | + if (empty($item) || empty($item['id'])) { |
|
| 961 | 961 | return $amount; |
| 962 | 962 | } |
| 963 | 963 | |
| 964 | - if ( empty( $item['quantity'] ) ) { |
|
| 964 | + if (empty($item['quantity'])) { |
|
| 965 | 965 | return $amount; |
| 966 | 966 | } |
| 967 | 967 | |
| 968 | - if ( empty( $item['options'] ) ) { |
|
| 968 | + if (empty($item['options'])) { |
|
| 969 | 969 | $item['options'] = array(); |
| 970 | 970 | } |
| 971 | 971 | |
| 972 | - $price = wpinv_get_cart_item_price( $item['id'], $item, $item['options'] ); |
|
| 972 | + $price = wpinv_get_cart_item_price($item['id'], $item, $item['options']); |
|
| 973 | 973 | $discounted_price = $price; |
| 974 | 974 | |
| 975 | 975 | $discounts = false === $discount ? wpinv_get_cart_discounts() : $discount; |
| 976 | - if ( empty( $discounts ) ) { |
|
| 976 | + if (empty($discounts)) { |
|
| 977 | 977 | return $amount; |
| 978 | 978 | } |
| 979 | 979 | |
| 980 | - if ( $discounts ) { |
|
| 981 | - if ( is_array( $discounts ) ) { |
|
| 982 | - $discounts = array_values( $discounts ); |
|
| 980 | + if ($discounts) { |
|
| 981 | + if (is_array($discounts)) { |
|
| 982 | + $discounts = array_values($discounts); |
|
| 983 | 983 | } else { |
| 984 | - $discounts = explode( ',', $discounts ); |
|
| 984 | + $discounts = explode(',', $discounts); |
|
| 985 | 985 | } |
| 986 | 986 | } |
| 987 | 987 | |
| 988 | - if( $discounts ) { |
|
| 989 | - foreach ( $discounts as $discount ) { |
|
| 990 | - $code_id = wpinv_get_discount_id_by_code( $discount ); |
|
| 988 | + if ($discounts) { |
|
| 989 | + foreach ($discounts as $discount) { |
|
| 990 | + $code_id = wpinv_get_discount_id_by_code($discount); |
|
| 991 | 991 | |
| 992 | 992 | // Check discount exists |
| 993 | - if( ! $code_id ) { |
|
| 993 | + if (!$code_id) { |
|
| 994 | 994 | continue; |
| 995 | 995 | } |
| 996 | 996 | |
| 997 | - $reqs = wpinv_get_discount_item_reqs( $code_id ); |
|
| 998 | - $excluded_items = wpinv_get_discount_excluded_items( $code_id ); |
|
| 997 | + $reqs = wpinv_get_discount_item_reqs($code_id); |
|
| 998 | + $excluded_items = wpinv_get_discount_excluded_items($code_id); |
|
| 999 | 999 | |
| 1000 | 1000 | // Make sure requirements are set and that this discount shouldn't apply to the whole cart |
| 1001 | - if ( !empty( $reqs ) && wpinv_is_discount_not_global( $code_id ) ) { |
|
| 1002 | - foreach ( $reqs as $item_id ) { |
|
| 1003 | - if ( $item_id == $item['id'] && ! in_array( $item['id'], $excluded_items ) ) { |
|
| 1004 | - $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price ); |
|
| 1001 | + if (!empty($reqs) && wpinv_is_discount_not_global($code_id)) { |
|
| 1002 | + foreach ($reqs as $item_id) { |
|
| 1003 | + if ($item_id == $item['id'] && !in_array($item['id'], $excluded_items)) { |
|
| 1004 | + $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price); |
|
| 1005 | 1005 | } |
| 1006 | 1006 | } |
| 1007 | 1007 | } else { |
| 1008 | 1008 | // This is a global cart discount |
| 1009 | - if ( !in_array( $item['id'], $excluded_items ) ) { |
|
| 1010 | - if ( 'flat' === wpinv_get_discount_type( $code_id ) ) { |
|
| 1009 | + if (!in_array($item['id'], $excluded_items)) { |
|
| 1010 | + if ('flat' === wpinv_get_discount_type($code_id)) { |
|
| 1011 | 1011 | $items_subtotal = 0.00; |
| 1012 | 1012 | $cart_items = wpinv_get_cart_contents(); |
| 1013 | 1013 | |
| 1014 | - foreach ( $cart_items as $cart_item ) { |
|
| 1015 | - if ( ! in_array( $cart_item['id'], $excluded_items ) ) { |
|
| 1016 | - $options = !empty( $cart_item['options'] ) ? $cart_item['options'] : array(); |
|
| 1017 | - $item_price = wpinv_get_cart_item_price( $cart_item['id'], $cart_item, $options ); |
|
| 1014 | + foreach ($cart_items as $cart_item) { |
|
| 1015 | + if (!in_array($cart_item['id'], $excluded_items)) { |
|
| 1016 | + $options = !empty($cart_item['options']) ? $cart_item['options'] : array(); |
|
| 1017 | + $item_price = wpinv_get_cart_item_price($cart_item['id'], $cart_item, $options); |
|
| 1018 | 1018 | $items_subtotal += $item_price * $cart_item['quantity']; |
| 1019 | 1019 | } |
| 1020 | 1020 | } |
| 1021 | 1021 | |
| 1022 | - $subtotal_percent = ( ( $price * $item['quantity'] ) / $items_subtotal ); |
|
| 1023 | - $code_amount = wpinv_get_discount_amount( $code_id ); |
|
| 1022 | + $subtotal_percent = (($price * $item['quantity']) / $items_subtotal); |
|
| 1023 | + $code_amount = wpinv_get_discount_amount($code_id); |
|
| 1024 | 1024 | $discounted_amount = $code_amount * $subtotal_percent; |
| 1025 | 1025 | $discounted_price -= $discounted_amount; |
| 1026 | 1026 | |
| 1027 | - $wpinv_flat_discount_total += round( $discounted_amount, wpinv_currency_decimal_filter() ); |
|
| 1027 | + $wpinv_flat_discount_total += round($discounted_amount, wpinv_currency_decimal_filter()); |
|
| 1028 | 1028 | |
| 1029 | - if ( $wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount ) { |
|
| 1029 | + if ($wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount) { |
|
| 1030 | 1030 | $adjustment = $code_amount - $wpinv_flat_discount_total; |
| 1031 | 1031 | $discounted_price -= $adjustment; |
| 1032 | 1032 | } |
| 1033 | 1033 | } else { |
| 1034 | - $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price ); |
|
| 1034 | + $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price); |
|
| 1035 | 1035 | } |
| 1036 | 1036 | } |
| 1037 | 1037 | } |
| 1038 | 1038 | } |
| 1039 | 1039 | |
| 1040 | - $amount = ( $price - apply_filters( 'wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price ) ); |
|
| 1040 | + $amount = ($price - apply_filters('wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price)); |
|
| 1041 | 1041 | |
| 1042 | - if ( 'flat' !== wpinv_get_discount_type( $code_id ) ) { |
|
| 1042 | + if ('flat' !== wpinv_get_discount_type($code_id)) { |
|
| 1043 | 1043 | $amount = $amount * $item['quantity']; |
| 1044 | 1044 | } |
| 1045 | 1045 | } |
@@ -1047,59 +1047,59 @@ discard block |
||
| 1047 | 1047 | return $amount; |
| 1048 | 1048 | } |
| 1049 | 1049 | |
| 1050 | -function wpinv_cart_discounts_html( $items = array() ) { |
|
| 1051 | - echo wpinv_get_cart_discounts_html( $items ); |
|
| 1050 | +function wpinv_cart_discounts_html($items = array()) { |
|
| 1051 | + echo wpinv_get_cart_discounts_html($items); |
|
| 1052 | 1052 | } |
| 1053 | 1053 | |
| 1054 | -function wpinv_get_cart_discounts_html( $items = array(), $discounts = false ) { |
|
| 1054 | +function wpinv_get_cart_discounts_html($items = array(), $discounts = false) { |
|
| 1055 | 1055 | global $wpi_cart_columns; |
| 1056 | 1056 | |
| 1057 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
| 1057 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
| 1058 | 1058 | |
| 1059 | - if ( !$discounts ) { |
|
| 1060 | - $discounts = wpinv_get_cart_discounts( $items ); |
|
| 1059 | + if (!$discounts) { |
|
| 1060 | + $discounts = wpinv_get_cart_discounts($items); |
|
| 1061 | 1061 | } |
| 1062 | 1062 | |
| 1063 | - if ( !$discounts ) { |
|
| 1063 | + if (!$discounts) { |
|
| 1064 | 1064 | return; |
| 1065 | 1065 | } |
| 1066 | 1066 | |
| 1067 | - $discounts = is_array( $discounts ) ? $discounts : array( $discounts ); |
|
| 1067 | + $discounts = is_array($discounts) ? $discounts : array($discounts); |
|
| 1068 | 1068 | |
| 1069 | 1069 | $html = ''; |
| 1070 | 1070 | |
| 1071 | - foreach ( $discounts as $discount ) { |
|
| 1072 | - $discount_id = wpinv_get_discount_id_by_code( $discount ); |
|
| 1073 | - $discount_value = wpinv_get_discount_amount( $discount_id ); |
|
| 1074 | - $rate = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), $discount_value ); |
|
| 1075 | - $amount = wpinv_get_cart_items_discount_amount( $items, $discount ); |
|
| 1076 | - $remove_btn = '<a title="' . esc_attr__( 'Remove discount', 'invoicing' ) . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> '; |
|
| 1071 | + foreach ($discounts as $discount) { |
|
| 1072 | + $discount_id = wpinv_get_discount_id_by_code($discount); |
|
| 1073 | + $discount_value = wpinv_get_discount_amount($discount_id); |
|
| 1074 | + $rate = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), $discount_value); |
|
| 1075 | + $amount = wpinv_get_cart_items_discount_amount($items, $discount); |
|
| 1076 | + $remove_btn = '<a title="' . esc_attr__('Remove discount', 'invoicing') . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> '; |
|
| 1077 | 1077 | |
| 1078 | 1078 | $html .= '<tr class="wpinv_cart_footer_row wpinv_cart_discount_row">'; |
| 1079 | 1079 | ob_start(); |
| 1080 | - do_action( 'wpinv_checkout_table_discount_first', $items ); |
|
| 1080 | + do_action('wpinv_checkout_table_discount_first', $items); |
|
| 1081 | 1081 | $html .= ob_get_clean(); |
| 1082 | - $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label( $discount, $rate, false ) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">–' . wpinv_price( wpinv_format_amount( $amount ) ) . '</span></td>'; |
|
| 1082 | + $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label($discount, $rate, false) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">–' . wpinv_price(wpinv_format_amount($amount)) . '</span></td>'; |
|
| 1083 | 1083 | ob_start(); |
| 1084 | - do_action( 'wpinv_checkout_table_discount_last', $items ); |
|
| 1084 | + do_action('wpinv_checkout_table_discount_last', $items); |
|
| 1085 | 1085 | $html .= ob_get_clean(); |
| 1086 | 1086 | $html .= '</tr>'; |
| 1087 | 1087 | } |
| 1088 | 1088 | |
| 1089 | - return apply_filters( 'wpinv_get_cart_discounts_html', $html, $discounts, $rate ); |
|
| 1089 | + return apply_filters('wpinv_get_cart_discounts_html', $html, $discounts, $rate); |
|
| 1090 | 1090 | } |
| 1091 | 1091 | |
| 1092 | -function wpinv_display_cart_discount( $formatted = false, $echo = false ) { |
|
| 1092 | +function wpinv_display_cart_discount($formatted = false, $echo = false) { |
|
| 1093 | 1093 | $discounts = wpinv_get_cart_discounts(); |
| 1094 | 1094 | |
| 1095 | - if ( empty( $discounts ) ) { |
|
| 1095 | + if (empty($discounts)) { |
|
| 1096 | 1096 | return false; |
| 1097 | 1097 | } |
| 1098 | 1098 | |
| 1099 | - $discount_id = wpinv_get_discount_id_by_code( $discounts[0] ); |
|
| 1100 | - $amount = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), wpinv_get_discount_amount( $discount_id ) ); |
|
| 1099 | + $discount_id = wpinv_get_discount_id_by_code($discounts[0]); |
|
| 1100 | + $amount = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), wpinv_get_discount_amount($discount_id)); |
|
| 1101 | 1101 | |
| 1102 | - if ( $echo ) { |
|
| 1102 | + if ($echo) { |
|
| 1103 | 1103 | echo $amount; |
| 1104 | 1104 | } |
| 1105 | 1105 | |
@@ -1107,133 +1107,133 @@ discard block |
||
| 1107 | 1107 | } |
| 1108 | 1108 | |
| 1109 | 1109 | function wpinv_remove_cart_discount() { |
| 1110 | - if ( !isset( $_GET['discount_id'] ) || ! isset( $_GET['discount_code'] ) ) { |
|
| 1110 | + if (!isset($_GET['discount_id']) || !isset($_GET['discount_code'])) { |
|
| 1111 | 1111 | return; |
| 1112 | 1112 | } |
| 1113 | 1113 | |
| 1114 | - do_action( 'wpinv_pre_remove_cart_discount', absint( $_GET['discount_id'] ) ); |
|
| 1114 | + do_action('wpinv_pre_remove_cart_discount', absint($_GET['discount_id'])); |
|
| 1115 | 1115 | |
| 1116 | - wpinv_unset_cart_discount( urldecode( $_GET['discount_code'] ) ); |
|
| 1116 | + wpinv_unset_cart_discount(urldecode($_GET['discount_code'])); |
|
| 1117 | 1117 | |
| 1118 | - do_action( 'wpinv_post_remove_cart_discount', absint( $_GET['discount_id'] ) ); |
|
| 1118 | + do_action('wpinv_post_remove_cart_discount', absint($_GET['discount_id'])); |
|
| 1119 | 1119 | |
| 1120 | - wp_redirect( wpinv_get_checkout_uri() ); wpinv_die(); |
|
| 1120 | + wp_redirect(wpinv_get_checkout_uri()); wpinv_die(); |
|
| 1121 | 1121 | } |
| 1122 | -add_action( 'wpinv_remove_cart_discount', 'wpinv_remove_cart_discount' ); |
|
| 1122 | +add_action('wpinv_remove_cart_discount', 'wpinv_remove_cart_discount'); |
|
| 1123 | 1123 | |
| 1124 | -function wpinv_maybe_remove_cart_discount( $cart_key = 0 ) { |
|
| 1124 | +function wpinv_maybe_remove_cart_discount($cart_key = 0) { |
|
| 1125 | 1125 | $discounts = wpinv_get_cart_discounts(); |
| 1126 | 1126 | |
| 1127 | - if ( !$discounts ) { |
|
| 1127 | + if (!$discounts) { |
|
| 1128 | 1128 | return; |
| 1129 | 1129 | } |
| 1130 | 1130 | |
| 1131 | - foreach ( $discounts as $discount ) { |
|
| 1132 | - if ( !wpinv_is_discount_valid( $discount ) ) { |
|
| 1133 | - wpinv_unset_cart_discount( $discount ); |
|
| 1131 | + foreach ($discounts as $discount) { |
|
| 1132 | + if (!wpinv_is_discount_valid($discount)) { |
|
| 1133 | + wpinv_unset_cart_discount($discount); |
|
| 1134 | 1134 | } |
| 1135 | 1135 | } |
| 1136 | 1136 | } |
| 1137 | -add_action( 'wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount' ); |
|
| 1137 | +add_action('wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount'); |
|
| 1138 | 1138 | |
| 1139 | 1139 | function wpinv_multiple_discounts_allowed() { |
| 1140 | - $ret = wpinv_get_option( 'allow_multiple_discounts', false ); |
|
| 1141 | - return (bool) apply_filters( 'wpinv_multiple_discounts_allowed', $ret ); |
|
| 1140 | + $ret = wpinv_get_option('allow_multiple_discounts', false); |
|
| 1141 | + return (bool)apply_filters('wpinv_multiple_discounts_allowed', $ret); |
|
| 1142 | 1142 | } |
| 1143 | 1143 | |
| 1144 | 1144 | function wpinv_listen_for_cart_discount() { |
| 1145 | 1145 | global $wpi_session; |
| 1146 | 1146 | |
| 1147 | - if ( empty( $_REQUEST['discount'] ) || is_array( $_REQUEST['discount'] ) ) { |
|
| 1147 | + if (empty($_REQUEST['discount']) || is_array($_REQUEST['discount'])) { |
|
| 1148 | 1148 | return; |
| 1149 | 1149 | } |
| 1150 | 1150 | |
| 1151 | - $code = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_REQUEST['discount'] ); |
|
| 1151 | + $code = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_REQUEST['discount']); |
|
| 1152 | 1152 | |
| 1153 | - $wpi_session->set( 'preset_discount', $code ); |
|
| 1153 | + $wpi_session->set('preset_discount', $code); |
|
| 1154 | 1154 | } |
| 1155 | 1155 | //add_action( 'init', 'wpinv_listen_for_cart_discount', 0 ); |
| 1156 | 1156 | |
| 1157 | 1157 | function wpinv_apply_preset_discount() { |
| 1158 | 1158 | global $wpi_session; |
| 1159 | 1159 | |
| 1160 | - $code = $wpi_session->get( 'preset_discount' ); |
|
| 1160 | + $code = $wpi_session->get('preset_discount'); |
|
| 1161 | 1161 | |
| 1162 | - if ( !$code ) { |
|
| 1162 | + if (!$code) { |
|
| 1163 | 1163 | return; |
| 1164 | 1164 | } |
| 1165 | 1165 | |
| 1166 | - if ( !wpinv_is_discount_valid( $code, '', false ) ) { |
|
| 1166 | + if (!wpinv_is_discount_valid($code, '', false)) { |
|
| 1167 | 1167 | return; |
| 1168 | 1168 | } |
| 1169 | 1169 | |
| 1170 | - $code = apply_filters( 'wpinv_apply_preset_discount', $code ); |
|
| 1170 | + $code = apply_filters('wpinv_apply_preset_discount', $code); |
|
| 1171 | 1171 | |
| 1172 | - wpinv_set_cart_discount( $code ); |
|
| 1172 | + wpinv_set_cart_discount($code); |
|
| 1173 | 1173 | |
| 1174 | - $wpi_session->set( 'preset_discount', null ); |
|
| 1174 | + $wpi_session->set('preset_discount', null); |
|
| 1175 | 1175 | } |
| 1176 | 1176 | //add_action( 'init', 'wpinv_apply_preset_discount', 999 ); |
| 1177 | 1177 | |
| 1178 | -function wpinv_get_discount_label( $code, $echo = true ) { |
|
| 1179 | - $label = wp_sprintf( __( 'Discount%1$s', 'invoicing' ), ( $code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)': '' ) ); |
|
| 1180 | - $label = apply_filters( 'wpinv_get_discount_label', $label, $code ); |
|
| 1178 | +function wpinv_get_discount_label($code, $echo = true) { |
|
| 1179 | + $label = wp_sprintf(__('Discount%1$s', 'invoicing'), ($code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)' : '')); |
|
| 1180 | + $label = apply_filters('wpinv_get_discount_label', $label, $code); |
|
| 1181 | 1181 | |
| 1182 | - if ( $echo ) { |
|
| 1182 | + if ($echo) { |
|
| 1183 | 1183 | echo $label; |
| 1184 | 1184 | } else { |
| 1185 | 1185 | return $label; |
| 1186 | 1186 | } |
| 1187 | 1187 | } |
| 1188 | 1188 | |
| 1189 | -function wpinv_cart_discount_label( $code, $rate, $echo = true ) { |
|
| 1190 | - $label = wp_sprintf( __( '%1$s Discount: %2$s', 'invoicing' ), $rate, $code ); |
|
| 1191 | - $label = apply_filters( 'wpinv_cart_discount_label', $label, $code, $rate ); |
|
| 1189 | +function wpinv_cart_discount_label($code, $rate, $echo = true) { |
|
| 1190 | + $label = wp_sprintf(__('%1$s Discount: %2$s', 'invoicing'), $rate, $code); |
|
| 1191 | + $label = apply_filters('wpinv_cart_discount_label', $label, $code, $rate); |
|
| 1192 | 1192 | |
| 1193 | - if ( $echo ) { |
|
| 1193 | + if ($echo) { |
|
| 1194 | 1194 | echo $label; |
| 1195 | 1195 | } else { |
| 1196 | 1196 | return $label; |
| 1197 | 1197 | } |
| 1198 | 1198 | } |
| 1199 | 1199 | |
| 1200 | -function wpinv_check_delete_discount( $check, $post, $force_delete ) { |
|
| 1201 | - if ( $post->post_type == 'wpi_discount' && wpinv_get_discount_uses( $post->ID ) > 0 ) { |
|
| 1200 | +function wpinv_check_delete_discount($check, $post, $force_delete) { |
|
| 1201 | + if ($post->post_type == 'wpi_discount' && wpinv_get_discount_uses($post->ID) > 0) { |
|
| 1202 | 1202 | return true; |
| 1203 | 1203 | } |
| 1204 | 1204 | |
| 1205 | 1205 | return $check; |
| 1206 | 1206 | } |
| 1207 | -add_filter( 'pre_delete_post', 'wpinv_check_delete_discount', 10, 3 ); |
|
| 1207 | +add_filter('pre_delete_post', 'wpinv_check_delete_discount', 10, 3); |
|
| 1208 | 1208 | |
| 1209 | 1209 | function wpinv_checkout_form_validate_discounts() { |
| 1210 | 1210 | $discounts = wpinv_get_cart_discounts(); |
| 1211 | 1211 | |
| 1212 | - if ( !empty( $discounts ) ) { |
|
| 1212 | + if (!empty($discounts)) { |
|
| 1213 | 1213 | $invalid = false; |
| 1214 | 1214 | |
| 1215 | - foreach ( $discounts as $key => $code ) { |
|
| 1216 | - if ( !wpinv_is_discount_valid( $code, get_current_user_id() ) ) { |
|
| 1215 | + foreach ($discounts as $key => $code) { |
|
| 1216 | + if (!wpinv_is_discount_valid($code, get_current_user_id())) { |
|
| 1217 | 1217 | $invalid = true; |
| 1218 | 1218 | |
| 1219 | - wpinv_unset_cart_discount( $code ); |
|
| 1219 | + wpinv_unset_cart_discount($code); |
|
| 1220 | 1220 | } |
| 1221 | 1221 | } |
| 1222 | 1222 | |
| 1223 | - if ( $invalid ) { |
|
| 1223 | + if ($invalid) { |
|
| 1224 | 1224 | $errors = wpinv_get_errors(); |
| 1225 | - $error = !empty( $errors['wpinv-discount-error'] ) ? $errors['wpinv-discount-error'] . ' ' : ''; |
|
| 1226 | - $error .= __( 'The discount has been removed from cart.', 'invoicing' ); |
|
| 1227 | - wpinv_set_error( 'wpinv-discount-error', $error ); |
|
| 1225 | + $error = !empty($errors['wpinv-discount-error']) ? $errors['wpinv-discount-error'] . ' ' : ''; |
|
| 1226 | + $error .= __('The discount has been removed from cart.', 'invoicing'); |
|
| 1227 | + wpinv_set_error('wpinv-discount-error', $error); |
|
| 1228 | 1228 | |
| 1229 | - wpinv_recalculate_tax( true ); |
|
| 1229 | + wpinv_recalculate_tax(true); |
|
| 1230 | 1230 | } |
| 1231 | 1231 | } |
| 1232 | 1232 | } |
| 1233 | -add_action( 'wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10 ); |
|
| 1233 | +add_action('wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10); |
|
| 1234 | 1234 | |
| 1235 | 1235 | function wpinv_discount_amount() { |
| 1236 | 1236 | $output = 0.00; |
| 1237 | 1237 | |
| 1238 | - return apply_filters( 'wpinv_discount_amount', $output ); |
|
| 1238 | + return apply_filters('wpinv_discount_amount', $output); |
|
| 1239 | 1239 | } |
| 1240 | 1240 | \ No newline at end of file |
@@ -7,89 +7,89 @@ 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 | global $post; |
| 94 | 94 | $invoice_statuses = array(); |
| 95 | 95 | $invoice_statuses = array( |
@@ -103,32 +103,32 @@ discard block |
||
| 103 | 103 | 'wpi-renewal' => __('Renewal Payment', 'invoicing') |
| 104 | 104 | ); |
| 105 | 105 | |
| 106 | - if ( $trashed ) { |
|
| 107 | - $invoice_statuses['trash'] = __( 'Trash', 'invoicing' ); |
|
| 106 | + if ($trashed) { |
|
| 107 | + $invoice_statuses['trash'] = __('Trash', 'invoicing'); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - return apply_filters( 'wpinv_statuses', $invoice_statuses ); |
|
| 110 | + return apply_filters('wpinv_statuses', $invoice_statuses); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | -function wpinv_status_nicename( $status ) { |
|
| 113 | +function wpinv_status_nicename($status) { |
|
| 114 | 114 | $statuses = wpinv_get_invoice_statuses(); |
| 115 | - $status = isset( $statuses[$status] ) ? $statuses[$status] : __( $status, 'invoicing' ); |
|
| 115 | + $status = isset($statuses[$status]) ? $statuses[$status] : __($status, 'invoicing'); |
|
| 116 | 116 | |
| 117 | 117 | return $status; |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | function wpinv_get_currency() { |
| 121 | - $currency = wpinv_get_option( 'currency', 'USD' ); |
|
| 121 | + $currency = wpinv_get_option('currency', 'USD'); |
|
| 122 | 122 | |
| 123 | - return apply_filters( 'wpinv_currency', $currency ); |
|
| 123 | + return apply_filters('wpinv_currency', $currency); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | -function wpinv_currency_symbol( $currency = '' ) { |
|
| 127 | - if ( empty( $currency ) ) { |
|
| 126 | +function wpinv_currency_symbol($currency = '') { |
|
| 127 | + if (empty($currency)) { |
|
| 128 | 128 | $currency = wpinv_get_currency(); |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - $symbols = apply_filters( 'wpinv_currency_symbols', array( |
|
| 131 | + $symbols = apply_filters('wpinv_currency_symbols', array( |
|
| 132 | 132 | 'AED' => 'د.إ', |
| 133 | 133 | 'ARS' => '$', |
| 134 | 134 | 'AUD' => '$', |
@@ -180,78 +180,78 @@ discard block |
||
| 180 | 180 | 'USD' => '$', |
| 181 | 181 | 'VND' => '₫', |
| 182 | 182 | 'ZAR' => 'R', |
| 183 | - ) ); |
|
| 183 | + )); |
|
| 184 | 184 | |
| 185 | - $currency_symbol = isset( $symbols[$currency] ) ? $symbols[$currency] : '$'; |
|
| 185 | + $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : '$'; |
|
| 186 | 186 | |
| 187 | - return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency ); |
|
| 187 | + return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | function wpinv_currency_position() { |
| 191 | - $position = wpinv_get_option( 'currency_position', 'left' ); |
|
| 191 | + $position = wpinv_get_option('currency_position', 'left'); |
|
| 192 | 192 | |
| 193 | - return apply_filters( 'wpinv_currency_position', $position ); |
|
| 193 | + return apply_filters('wpinv_currency_position', $position); |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | function wpinv_thousands_separator() { |
| 197 | - $thousand_sep = wpinv_get_option( 'thousands_separator', ',' ); |
|
| 197 | + $thousand_sep = wpinv_get_option('thousands_separator', ','); |
|
| 198 | 198 | |
| 199 | - return apply_filters( 'wpinv_thousands_separator', $thousand_sep ); |
|
| 199 | + return apply_filters('wpinv_thousands_separator', $thousand_sep); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | function wpinv_decimal_separator() { |
| 203 | - $decimal_sep = wpinv_get_option( 'decimal_separator', '.' ); |
|
| 203 | + $decimal_sep = wpinv_get_option('decimal_separator', '.'); |
|
| 204 | 204 | |
| 205 | - return apply_filters( 'wpinv_decimal_separator', $decimal_sep ); |
|
| 205 | + return apply_filters('wpinv_decimal_separator', $decimal_sep); |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | function wpinv_decimals() { |
| 209 | - $decimals = apply_filters( 'wpinv_decimals', wpinv_get_option( 'decimals', 2 ) ); |
|
| 209 | + $decimals = apply_filters('wpinv_decimals', wpinv_get_option('decimals', 2)); |
|
| 210 | 210 | |
| 211 | - return absint( $decimals ); |
|
| 211 | + return absint($decimals); |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | function wpinv_get_currencies() { |
| 215 | 215 | $currencies = array( |
| 216 | - 'USD' => __( 'US Dollars ($)', 'invoicing' ), |
|
| 217 | - 'EUR' => __( 'Euros (€)', 'invoicing' ), |
|
| 218 | - 'GBP' => __( 'Pounds Sterling (£)', 'invoicing' ), |
|
| 219 | - 'AUD' => __( 'Australian Dollars ($)', 'invoicing' ), |
|
| 220 | - 'BRL' => __( 'Brazilian Real (R$)', 'invoicing' ), |
|
| 221 | - 'CAD' => __( 'Canadian Dollars ($)', 'invoicing' ), |
|
| 222 | - 'CLP' => __( 'Chilean Peso ($)', 'invoicing' ), |
|
| 223 | - 'CNY' => __( 'Chinese Yuan (¥)', 'invoicing' ), |
|
| 224 | - 'CZK' => __( 'Czech Koruna (Kč)', 'invoicing' ), |
|
| 225 | - 'DKK' => __( 'Danish Krone (DKK)', 'invoicing' ), |
|
| 226 | - 'HKD' => __( 'Hong Kong Dollar ($)', 'invoicing' ), |
|
| 227 | - 'HUF' => __( 'Hungarian Forint (Ft)', 'invoicing' ), |
|
| 228 | - 'INR' => __( 'Indian Rupee (₹)', 'invoicing' ), |
|
| 229 | - 'ILS' => __( 'Israeli Shekel (₪)', 'invoicing' ), |
|
| 230 | - 'JPY' => __( 'Japanese Yen (¥)', 'invoicing' ), |
|
| 231 | - 'MYR' => __( 'Malaysian Ringgit (RM)', 'invoicing' ), |
|
| 232 | - 'MXN' => __( 'Mexican Peso ($)', 'invoicing' ), |
|
| 233 | - 'NZD' => __( 'New Zealand Dollar ($)', 'invoicing' ), |
|
| 234 | - 'NOK' => __( 'Norwegian Krone (kr)', 'invoicing' ), |
|
| 235 | - 'PHP' => __( 'Philippine Peso (₱)', 'invoicing' ), |
|
| 236 | - 'PLN' => __( 'Polish Zloty (zł)', 'invoicing' ), |
|
| 237 | - 'SGD' => __( 'Singapore Dollar ($)', 'invoicing' ), |
|
| 238 | - 'SEK' => __( 'Swedish Krona (kr)', 'invoicing' ), |
|
| 239 | - 'CHF' => __( 'Swiss Franc (CHF)', 'invoicing' ), |
|
| 240 | - 'TWD' => __( 'Taiwan New Dollar (NT$)', 'invoicing' ), |
|
| 241 | - 'THB' => __( 'Thai Baht (฿)', 'invoicing' ), |
|
| 242 | - 'TRY' => __( 'Turkish Lira (₺)', 'invoicing' ), |
|
| 243 | - 'RIAL' => __( 'Iranian Rial (﷼)', 'invoicing' ), |
|
| 244 | - 'RUB' => __( 'Russian Ruble (₽)', 'invoicing' ), |
|
| 245 | - 'ZAR' => __( 'South African Rand (R)', 'invoicing' ) |
|
| 216 | + 'USD' => __('US Dollars ($)', 'invoicing'), |
|
| 217 | + 'EUR' => __('Euros (€)', 'invoicing'), |
|
| 218 | + 'GBP' => __('Pounds Sterling (£)', 'invoicing'), |
|
| 219 | + 'AUD' => __('Australian Dollars ($)', 'invoicing'), |
|
| 220 | + 'BRL' => __('Brazilian Real (R$)', 'invoicing'), |
|
| 221 | + 'CAD' => __('Canadian Dollars ($)', 'invoicing'), |
|
| 222 | + 'CLP' => __('Chilean Peso ($)', 'invoicing'), |
|
| 223 | + 'CNY' => __('Chinese Yuan (¥)', 'invoicing'), |
|
| 224 | + 'CZK' => __('Czech Koruna (Kč)', 'invoicing'), |
|
| 225 | + 'DKK' => __('Danish Krone (DKK)', 'invoicing'), |
|
| 226 | + 'HKD' => __('Hong Kong Dollar ($)', 'invoicing'), |
|
| 227 | + 'HUF' => __('Hungarian Forint (Ft)', 'invoicing'), |
|
| 228 | + 'INR' => __('Indian Rupee (₹)', 'invoicing'), |
|
| 229 | + 'ILS' => __('Israeli Shekel (₪)', 'invoicing'), |
|
| 230 | + 'JPY' => __('Japanese Yen (¥)', 'invoicing'), |
|
| 231 | + 'MYR' => __('Malaysian Ringgit (RM)', 'invoicing'), |
|
| 232 | + 'MXN' => __('Mexican Peso ($)', 'invoicing'), |
|
| 233 | + 'NZD' => __('New Zealand Dollar ($)', 'invoicing'), |
|
| 234 | + 'NOK' => __('Norwegian Krone (kr)', 'invoicing'), |
|
| 235 | + 'PHP' => __('Philippine Peso (₱)', 'invoicing'), |
|
| 236 | + 'PLN' => __('Polish Zloty (zł)', 'invoicing'), |
|
| 237 | + 'SGD' => __('Singapore Dollar ($)', 'invoicing'), |
|
| 238 | + 'SEK' => __('Swedish Krona (kr)', 'invoicing'), |
|
| 239 | + 'CHF' => __('Swiss Franc (CHF)', 'invoicing'), |
|
| 240 | + 'TWD' => __('Taiwan New Dollar (NT$)', 'invoicing'), |
|
| 241 | + 'THB' => __('Thai Baht (฿)', 'invoicing'), |
|
| 242 | + 'TRY' => __('Turkish Lira (₺)', 'invoicing'), |
|
| 243 | + 'RIAL' => __('Iranian Rial (﷼)', 'invoicing'), |
|
| 244 | + 'RUB' => __('Russian Ruble (₽)', 'invoicing'), |
|
| 245 | + 'ZAR' => __('South African Rand (R)', 'invoicing') |
|
| 246 | 246 | ); |
| 247 | 247 | |
| 248 | - asort( $currencies ); |
|
| 248 | + asort($currencies); |
|
| 249 | 249 | |
| 250 | - return apply_filters( 'wpinv_currencies', $currencies ); |
|
| 250 | + return apply_filters('wpinv_currencies', $currencies); |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | -function wpinv_price( $amount = '', $currency = '' ) { |
|
| 254 | - if( empty( $currency ) ) { |
|
| 253 | +function wpinv_price($amount = '', $currency = '') { |
|
| 254 | + if (empty($currency)) { |
|
| 255 | 255 | $currency = wpinv_get_currency(); |
| 256 | 256 | } |
| 257 | 257 | |
@@ -259,14 +259,14 @@ discard block |
||
| 259 | 259 | |
| 260 | 260 | $negative = $amount < 0; |
| 261 | 261 | |
| 262 | - if ( $negative ) { |
|
| 263 | - $amount = substr( $amount, 1 ); |
|
| 262 | + if ($negative) { |
|
| 263 | + $amount = substr($amount, 1); |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | - $symbol = wpinv_currency_symbol( $currency ); |
|
| 266 | + $symbol = wpinv_currency_symbol($currency); |
|
| 267 | 267 | |
| 268 | - if ( $position == 'left' || $position == 'left_space' ) { |
|
| 269 | - switch ( $currency ) { |
|
| 268 | + if ($position == 'left' || $position == 'left_space') { |
|
| 269 | + switch ($currency) { |
|
| 270 | 270 | case "GBP" : |
| 271 | 271 | case "BRL" : |
| 272 | 272 | case "EUR" : |
@@ -278,15 +278,15 @@ discard block |
||
| 278 | 278 | case "NZD" : |
| 279 | 279 | case "SGD" : |
| 280 | 280 | case "JPY" : |
| 281 | - $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount; |
|
| 281 | + $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount; |
|
| 282 | 282 | break; |
| 283 | 283 | default : |
| 284 | 284 | //$price = $currency . ' ' . $amount; |
| 285 | - $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount; |
|
| 285 | + $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount; |
|
| 286 | 286 | break; |
| 287 | 287 | } |
| 288 | 288 | } else { |
| 289 | - switch ( $currency ) { |
|
| 289 | + switch ($currency) { |
|
| 290 | 290 | case "GBP" : |
| 291 | 291 | case "BRL" : |
| 292 | 292 | case "EUR" : |
@@ -297,83 +297,83 @@ discard block |
||
| 297 | 297 | case "MXN" : |
| 298 | 298 | case "SGD" : |
| 299 | 299 | case "JPY" : |
| 300 | - $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol; |
|
| 300 | + $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol; |
|
| 301 | 301 | break; |
| 302 | 302 | default : |
| 303 | 303 | //$price = $amount . ' ' . $currency; |
| 304 | - $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol; |
|
| 304 | + $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol; |
|
| 305 | 305 | break; |
| 306 | 306 | } |
| 307 | 307 | } |
| 308 | 308 | |
| 309 | - if ( $negative ) { |
|
| 309 | + if ($negative) { |
|
| 310 | 310 | $price = '-' . $price; |
| 311 | 311 | } |
| 312 | 312 | |
| 313 | - $price = apply_filters( 'wpinv_' . strtolower( $currency ) . '_currency_filter_' . $position, $price, $currency, $amount ); |
|
| 313 | + $price = apply_filters('wpinv_' . strtolower($currency) . '_currency_filter_' . $position, $price, $currency, $amount); |
|
| 314 | 314 | |
| 315 | 315 | return $price; |
| 316 | 316 | } |
| 317 | 317 | |
| 318 | -function wpinv_format_amount( $amount, $decimals = NULL, $calculate = false ) { |
|
| 318 | +function wpinv_format_amount($amount, $decimals = NULL, $calculate = false) { |
|
| 319 | 319 | $thousands_sep = wpinv_thousands_separator(); |
| 320 | 320 | $decimal_sep = wpinv_decimal_separator(); |
| 321 | 321 | |
| 322 | - if ( $decimals === NULL ) { |
|
| 322 | + if ($decimals === NULL) { |
|
| 323 | 323 | $decimals = wpinv_decimals(); |
| 324 | 324 | } |
| 325 | 325 | |
| 326 | - if ( $decimal_sep == ',' && false !== ( $sep_found = strpos( $amount, $decimal_sep ) ) ) { |
|
| 327 | - $whole = substr( $amount, 0, $sep_found ); |
|
| 328 | - $part = substr( $amount, $sep_found + 1, ( strlen( $amount ) - 1 ) ); |
|
| 326 | + if ($decimal_sep == ',' && false !== ($sep_found = strpos($amount, $decimal_sep))) { |
|
| 327 | + $whole = substr($amount, 0, $sep_found); |
|
| 328 | + $part = substr($amount, $sep_found + 1, (strlen($amount) - 1)); |
|
| 329 | 329 | $amount = $whole . '.' . $part; |
| 330 | 330 | } |
| 331 | 331 | |
| 332 | - if ( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
| 333 | - $amount = str_replace( ',', '', $amount ); |
|
| 332 | + if ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) { |
|
| 333 | + $amount = str_replace(',', '', $amount); |
|
| 334 | 334 | } |
| 335 | 335 | |
| 336 | - if ( $thousands_sep == ' ' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
| 337 | - $amount = str_replace( ' ', '', $amount ); |
|
| 336 | + if ($thousands_sep == ' ' && false !== ($found = strpos($amount, $thousands_sep))) { |
|
| 337 | + $amount = str_replace(' ', '', $amount); |
|
| 338 | 338 | } |
| 339 | 339 | |
| 340 | - if ( empty( $amount ) ) { |
|
| 340 | + if (empty($amount)) { |
|
| 341 | 341 | $amount = 0; |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | - $decimals = apply_filters( 'wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate ); |
|
| 345 | - $formatted = number_format( (float)$amount, $decimals, $decimal_sep, $thousands_sep ); |
|
| 344 | + $decimals = apply_filters('wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate); |
|
| 345 | + $formatted = number_format((float)$amount, $decimals, $decimal_sep, $thousands_sep); |
|
| 346 | 346 | |
| 347 | - if ( $calculate ) { |
|
| 348 | - if ( $thousands_sep === "," ) { |
|
| 349 | - $formatted = str_replace( ",", "", $formatted ); |
|
| 347 | + if ($calculate) { |
|
| 348 | + if ($thousands_sep === ",") { |
|
| 349 | + $formatted = str_replace(",", "", $formatted); |
|
| 350 | 350 | } |
| 351 | 351 | |
| 352 | - if ( $decimal_sep === "," ) { |
|
| 353 | - $formatted = str_replace( ",", ".", $formatted ); |
|
| 352 | + if ($decimal_sep === ",") { |
|
| 353 | + $formatted = str_replace(",", ".", $formatted); |
|
| 354 | 354 | } |
| 355 | 355 | } |
| 356 | 356 | |
| 357 | - return apply_filters( 'wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate ); |
|
| 357 | + return apply_filters('wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate); |
|
| 358 | 358 | } |
| 359 | -add_filter( 'wpinv_amount_format_decimals', 'wpinv_currency_decimal_filter', 10, 1 ); |
|
| 359 | +add_filter('wpinv_amount_format_decimals', 'wpinv_currency_decimal_filter', 10, 1); |
|
| 360 | 360 | |
| 361 | -function wpinv_sanitize_key( $key ) { |
|
| 361 | +function wpinv_sanitize_key($key) { |
|
| 362 | 362 | $raw_key = $key; |
| 363 | - $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key ); |
|
| 363 | + $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key); |
|
| 364 | 364 | |
| 365 | - return apply_filters( 'wpinv_sanitize_key', $key, $raw_key ); |
|
| 365 | + return apply_filters('wpinv_sanitize_key', $key, $raw_key); |
|
| 366 | 366 | } |
| 367 | 367 | |
| 368 | -function wpinv_get_file_extension( $str ) { |
|
| 369 | - $parts = explode( '.', $str ); |
|
| 370 | - return end( $parts ); |
|
| 368 | +function wpinv_get_file_extension($str) { |
|
| 369 | + $parts = explode('.', $str); |
|
| 370 | + return end($parts); |
|
| 371 | 371 | } |
| 372 | 372 | |
| 373 | -function wpinv_string_is_image_url( $str ) { |
|
| 374 | - $ext = wpinv_get_file_extension( $str ); |
|
| 373 | +function wpinv_string_is_image_url($str) { |
|
| 374 | + $ext = wpinv_get_file_extension($str); |
|
| 375 | 375 | |
| 376 | - switch ( strtolower( $ext ) ) { |
|
| 376 | + switch (strtolower($ext)) { |
|
| 377 | 377 | case 'jpeg'; |
| 378 | 378 | case 'jpg'; |
| 379 | 379 | $return = true; |
@@ -389,32 +389,32 @@ discard block |
||
| 389 | 389 | break; |
| 390 | 390 | } |
| 391 | 391 | |
| 392 | - return (bool)apply_filters( 'wpinv_string_is_image', $return, $str ); |
|
| 392 | + return (bool)apply_filters('wpinv_string_is_image', $return, $str); |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | -function wpinv_error_log( $log, $title = '', $file = '', $line = '', $exit = false ) { |
|
| 396 | - $should_log = apply_filters( 'wpinv_log_errors', WP_DEBUG ); |
|
| 395 | +function wpinv_error_log($log, $title = '', $file = '', $line = '', $exit = false) { |
|
| 396 | + $should_log = apply_filters('wpinv_log_errors', WP_DEBUG); |
|
| 397 | 397 | |
| 398 | - if ( true === $should_log ) { |
|
| 398 | + if (true === $should_log) { |
|
| 399 | 399 | $label = ''; |
| 400 | - if ( $file && $file !== '' ) { |
|
| 401 | - $label .= basename( $file ) . ( $line ? '(' . $line . ')' : '' ); |
|
| 400 | + if ($file && $file !== '') { |
|
| 401 | + $label .= basename($file) . ($line ? '(' . $line . ')' : ''); |
|
| 402 | 402 | } |
| 403 | 403 | |
| 404 | - if ( $title && $title !== '' ) { |
|
| 404 | + if ($title && $title !== '') { |
|
| 405 | 405 | $label = $label !== '' ? $label . ' ' : ''; |
| 406 | 406 | $label .= $title . ' '; |
| 407 | 407 | } |
| 408 | 408 | |
| 409 | - $label = $label !== '' ? trim( $label ) . ' : ' : ''; |
|
| 409 | + $label = $label !== '' ? trim($label) . ' : ' : ''; |
|
| 410 | 410 | |
| 411 | - if ( is_array( $log ) || is_object( $log ) ) { |
|
| 412 | - error_log( $label . print_r( $log, true ) ); |
|
| 411 | + if (is_array($log) || is_object($log)) { |
|
| 412 | + error_log($label . print_r($log, true)); |
|
| 413 | 413 | } else { |
| 414 | - error_log( $label . $log ); |
|
| 414 | + error_log($label . $log); |
|
| 415 | 415 | } |
| 416 | 416 | |
| 417 | - if ( $exit ) { |
|
| 417 | + if ($exit) { |
|
| 418 | 418 | exit; |
| 419 | 419 | } |
| 420 | 420 | } |
@@ -422,65 +422,65 @@ discard block |
||
| 422 | 422 | |
| 423 | 423 | function wpinv_is_ajax_disabled() { |
| 424 | 424 | $retval = false; |
| 425 | - return apply_filters( 'wpinv_is_ajax_disabled', $retval ); |
|
| 425 | + return apply_filters('wpinv_is_ajax_disabled', $retval); |
|
| 426 | 426 | } |
| 427 | 427 | |
| 428 | -function wpinv_get_current_page_url( $nocache = false ) { |
|
| 428 | +function wpinv_get_current_page_url($nocache = false) { |
|
| 429 | 429 | global $wp; |
| 430 | 430 | |
| 431 | - if ( get_option( 'permalink_structure' ) ) { |
|
| 432 | - $base = trailingslashit( home_url( $wp->request ) ); |
|
| 431 | + if (get_option('permalink_structure')) { |
|
| 432 | + $base = trailingslashit(home_url($wp->request)); |
|
| 433 | 433 | } else { |
| 434 | - $base = add_query_arg( $wp->query_string, '', trailingslashit( home_url( $wp->request ) ) ); |
|
| 435 | - $base = remove_query_arg( array( 'post_type', 'name' ), $base ); |
|
| 434 | + $base = add_query_arg($wp->query_string, '', trailingslashit(home_url($wp->request))); |
|
| 435 | + $base = remove_query_arg(array('post_type', 'name'), $base); |
|
| 436 | 436 | } |
| 437 | 437 | |
| 438 | 438 | $scheme = is_ssl() ? 'https' : 'http'; |
| 439 | - $uri = set_url_scheme( $base, $scheme ); |
|
| 439 | + $uri = set_url_scheme($base, $scheme); |
|
| 440 | 440 | |
| 441 | - if ( is_front_page() ) { |
|
| 442 | - $uri = home_url( '/' ); |
|
| 443 | - } elseif ( wpinv_is_checkout( array(), false ) ) { |
|
| 441 | + if (is_front_page()) { |
|
| 442 | + $uri = home_url('/'); |
|
| 443 | + } elseif (wpinv_is_checkout(array(), false)) { |
|
| 444 | 444 | $uri = wpinv_get_checkout_uri(); |
| 445 | 445 | } |
| 446 | 446 | |
| 447 | - $uri = apply_filters( 'wpinv_get_current_page_url', $uri ); |
|
| 447 | + $uri = apply_filters('wpinv_get_current_page_url', $uri); |
|
| 448 | 448 | |
| 449 | - if ( $nocache ) { |
|
| 450 | - $uri = wpinv_add_cache_busting( $uri ); |
|
| 449 | + if ($nocache) { |
|
| 450 | + $uri = wpinv_add_cache_busting($uri); |
|
| 451 | 451 | } |
| 452 | 452 | |
| 453 | 453 | return $uri; |
| 454 | 454 | } |
| 455 | 455 | |
| 456 | 456 | function wpinv_get_php_arg_separator_output() { |
| 457 | - return ini_get( 'arg_separator.output' ); |
|
| 457 | + return ini_get('arg_separator.output'); |
|
| 458 | 458 | } |
| 459 | 459 | |
| 460 | -function wpinv_rgb_from_hex( $color ) { |
|
| 461 | - $color = str_replace( '#', '', $color ); |
|
| 460 | +function wpinv_rgb_from_hex($color) { |
|
| 461 | + $color = str_replace('#', '', $color); |
|
| 462 | 462 | // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF" |
| 463 | - $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color ); |
|
| 463 | + $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color); |
|
| 464 | 464 | |
| 465 | 465 | $rgb = array(); |
| 466 | - $rgb['R'] = hexdec( $color{0}.$color{1} ); |
|
| 467 | - $rgb['G'] = hexdec( $color{2}.$color{3} ); |
|
| 468 | - $rgb['B'] = hexdec( $color{4}.$color{5} ); |
|
| 466 | + $rgb['R'] = hexdec($color{0} . $color{1} ); |
|
| 467 | + $rgb['G'] = hexdec($color{2} . $color{3} ); |
|
| 468 | + $rgb['B'] = hexdec($color{4} . $color{5} ); |
|
| 469 | 469 | |
| 470 | 470 | return $rgb; |
| 471 | 471 | } |
| 472 | 472 | |
| 473 | -function wpinv_hex_darker( $color, $factor = 30 ) { |
|
| 474 | - $base = wpinv_rgb_from_hex( $color ); |
|
| 473 | +function wpinv_hex_darker($color, $factor = 30) { |
|
| 474 | + $base = wpinv_rgb_from_hex($color); |
|
| 475 | 475 | $color = '#'; |
| 476 | 476 | |
| 477 | - foreach ( $base as $k => $v ) { |
|
| 477 | + foreach ($base as $k => $v) { |
|
| 478 | 478 | $amount = $v / 100; |
| 479 | - $amount = round( $amount * $factor ); |
|
| 479 | + $amount = round($amount * $factor); |
|
| 480 | 480 | $new_decimal = $v - $amount; |
| 481 | 481 | |
| 482 | - $new_hex_component = dechex( $new_decimal ); |
|
| 483 | - if ( strlen( $new_hex_component ) < 2 ) { |
|
| 482 | + $new_hex_component = dechex($new_decimal); |
|
| 483 | + if (strlen($new_hex_component) < 2) { |
|
| 484 | 484 | $new_hex_component = "0" . $new_hex_component; |
| 485 | 485 | } |
| 486 | 486 | $color .= $new_hex_component; |
@@ -489,18 +489,18 @@ discard block |
||
| 489 | 489 | return $color; |
| 490 | 490 | } |
| 491 | 491 | |
| 492 | -function wpinv_hex_lighter( $color, $factor = 30 ) { |
|
| 493 | - $base = wpinv_rgb_from_hex( $color ); |
|
| 492 | +function wpinv_hex_lighter($color, $factor = 30) { |
|
| 493 | + $base = wpinv_rgb_from_hex($color); |
|
| 494 | 494 | $color = '#'; |
| 495 | 495 | |
| 496 | - foreach ( $base as $k => $v ) { |
|
| 496 | + foreach ($base as $k => $v) { |
|
| 497 | 497 | $amount = 255 - $v; |
| 498 | 498 | $amount = $amount / 100; |
| 499 | - $amount = round( $amount * $factor ); |
|
| 499 | + $amount = round($amount * $factor); |
|
| 500 | 500 | $new_decimal = $v + $amount; |
| 501 | 501 | |
| 502 | - $new_hex_component = dechex( $new_decimal ); |
|
| 503 | - if ( strlen( $new_hex_component ) < 2 ) { |
|
| 502 | + $new_hex_component = dechex($new_decimal); |
|
| 503 | + if (strlen($new_hex_component) < 2) { |
|
| 504 | 504 | $new_hex_component = "0" . $new_hex_component; |
| 505 | 505 | } |
| 506 | 506 | $color .= $new_hex_component; |
@@ -509,22 +509,22 @@ discard block |
||
| 509 | 509 | return $color; |
| 510 | 510 | } |
| 511 | 511 | |
| 512 | -function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) { |
|
| 513 | - $hex = str_replace( '#', '', $color ); |
|
| 512 | +function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') { |
|
| 513 | + $hex = str_replace('#', '', $color); |
|
| 514 | 514 | |
| 515 | - $c_r = hexdec( substr( $hex, 0, 2 ) ); |
|
| 516 | - $c_g = hexdec( substr( $hex, 2, 2 ) ); |
|
| 517 | - $c_b = hexdec( substr( $hex, 4, 2 ) ); |
|
| 515 | + $c_r = hexdec(substr($hex, 0, 2)); |
|
| 516 | + $c_g = hexdec(substr($hex, 2, 2)); |
|
| 517 | + $c_b = hexdec(substr($hex, 4, 2)); |
|
| 518 | 518 | |
| 519 | - $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000; |
|
| 519 | + $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000; |
|
| 520 | 520 | |
| 521 | 521 | return $brightness > 155 ? $dark : $light; |
| 522 | 522 | } |
| 523 | 523 | |
| 524 | -function wpinv_format_hex( $hex ) { |
|
| 525 | - $hex = trim( str_replace( '#', '', $hex ) ); |
|
| 524 | +function wpinv_format_hex($hex) { |
|
| 525 | + $hex = trim(str_replace('#', '', $hex)); |
|
| 526 | 526 | |
| 527 | - if ( strlen( $hex ) == 3 ) { |
|
| 527 | + if (strlen($hex) == 3) { |
|
| 528 | 528 | $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2]; |
| 529 | 529 | } |
| 530 | 530 | |
@@ -544,12 +544,12 @@ discard block |
||
| 544 | 544 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 545 | 545 | * @return string |
| 546 | 546 | */ |
| 547 | -function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) { |
|
| 548 | - if ( function_exists( 'mb_strimwidth' ) ) { |
|
| 549 | - return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding ); |
|
| 547 | +function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') { |
|
| 548 | + if (function_exists('mb_strimwidth')) { |
|
| 549 | + return mb_strimwidth($str, $start, $width, $trimmaker, $encoding); |
|
| 550 | 550 | } |
| 551 | 551 | |
| 552 | - return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker; |
|
| 552 | + return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker; |
|
| 553 | 553 | } |
| 554 | 554 | |
| 555 | 555 | /** |
@@ -561,28 +561,28 @@ discard block |
||
| 561 | 561 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 562 | 562 | * @return int Returns the number of characters in string. |
| 563 | 563 | */ |
| 564 | -function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) { |
|
| 565 | - if ( function_exists( 'mb_strlen' ) ) { |
|
| 566 | - return mb_strlen( $str, $encoding ); |
|
| 564 | +function wpinv_utf8_strlen($str, $encoding = 'UTF-8') { |
|
| 565 | + if (function_exists('mb_strlen')) { |
|
| 566 | + return mb_strlen($str, $encoding); |
|
| 567 | 567 | } |
| 568 | 568 | |
| 569 | - return strlen( $str ); |
|
| 569 | + return strlen($str); |
|
| 570 | 570 | } |
| 571 | 571 | |
| 572 | -function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) { |
|
| 573 | - if ( function_exists( 'mb_strtolower' ) ) { |
|
| 574 | - return mb_strtolower( $str, $encoding ); |
|
| 572 | +function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') { |
|
| 573 | + if (function_exists('mb_strtolower')) { |
|
| 574 | + return mb_strtolower($str, $encoding); |
|
| 575 | 575 | } |
| 576 | 576 | |
| 577 | - return strtolower( $str ); |
|
| 577 | + return strtolower($str); |
|
| 578 | 578 | } |
| 579 | 579 | |
| 580 | -function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) { |
|
| 581 | - if ( function_exists( 'mb_strtoupper' ) ) { |
|
| 582 | - return mb_strtoupper( $str, $encoding ); |
|
| 580 | +function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') { |
|
| 581 | + if (function_exists('mb_strtoupper')) { |
|
| 582 | + return mb_strtoupper($str, $encoding); |
|
| 583 | 583 | } |
| 584 | 584 | |
| 585 | - return strtoupper( $str ); |
|
| 585 | + return strtoupper($str); |
|
| 586 | 586 | } |
| 587 | 587 | |
| 588 | 588 | /** |
@@ -596,12 +596,12 @@ discard block |
||
| 596 | 596 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 597 | 597 | * @return int Returns the position of the first occurrence of search in the string. |
| 598 | 598 | */ |
| 599 | -function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) { |
|
| 600 | - if ( function_exists( 'mb_strpos' ) ) { |
|
| 601 | - return mb_strpos( $str, $find, $offset, $encoding ); |
|
| 599 | +function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') { |
|
| 600 | + if (function_exists('mb_strpos')) { |
|
| 601 | + return mb_strpos($str, $find, $offset, $encoding); |
|
| 602 | 602 | } |
| 603 | 603 | |
| 604 | - return strpos( $str, $find, $offset ); |
|
| 604 | + return strpos($str, $find, $offset); |
|
| 605 | 605 | } |
| 606 | 606 | |
| 607 | 607 | /** |
@@ -615,12 +615,12 @@ discard block |
||
| 615 | 615 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 616 | 616 | * @return int Returns the position of the last occurrence of search. |
| 617 | 617 | */ |
| 618 | -function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) { |
|
| 619 | - if ( function_exists( 'mb_strrpos' ) ) { |
|
| 620 | - return mb_strrpos( $str, $find, $offset, $encoding ); |
|
| 618 | +function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') { |
|
| 619 | + if (function_exists('mb_strrpos')) { |
|
| 620 | + return mb_strrpos($str, $find, $offset, $encoding); |
|
| 621 | 621 | } |
| 622 | 622 | |
| 623 | - return strrpos( $str, $find, $offset ); |
|
| 623 | + return strrpos($str, $find, $offset); |
|
| 624 | 624 | } |
| 625 | 625 | |
| 626 | 626 | /** |
@@ -635,16 +635,16 @@ discard block |
||
| 635 | 635 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 636 | 636 | * @return string |
| 637 | 637 | */ |
| 638 | -function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) { |
|
| 639 | - if ( function_exists( 'mb_substr' ) ) { |
|
| 640 | - if ( $length === null ) { |
|
| 641 | - return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding ); |
|
| 638 | +function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') { |
|
| 639 | + if (function_exists('mb_substr')) { |
|
| 640 | + if ($length === null) { |
|
| 641 | + return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding); |
|
| 642 | 642 | } else { |
| 643 | - return mb_substr( $str, $start, $length, $encoding ); |
|
| 643 | + return mb_substr($str, $start, $length, $encoding); |
|
| 644 | 644 | } |
| 645 | 645 | } |
| 646 | 646 | |
| 647 | - return substr( $str, $start, $length ); |
|
| 647 | + return substr($str, $start, $length); |
|
| 648 | 648 | } |
| 649 | 649 | |
| 650 | 650 | /** |
@@ -656,48 +656,48 @@ discard block |
||
| 656 | 656 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
| 657 | 657 | * @return string The width of string. |
| 658 | 658 | */ |
| 659 | -function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) { |
|
| 660 | - if ( function_exists( 'mb_strwidth' ) ) { |
|
| 661 | - return mb_strwidth( $str, $encoding ); |
|
| 659 | +function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') { |
|
| 660 | + if (function_exists('mb_strwidth')) { |
|
| 661 | + return mb_strwidth($str, $encoding); |
|
| 662 | 662 | } |
| 663 | 663 | |
| 664 | - return wpinv_utf8_strlen( $str, $encoding ); |
|
| 664 | + return wpinv_utf8_strlen($str, $encoding); |
|
| 665 | 665 | } |
| 666 | 666 | |
| 667 | -function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) { |
|
| 668 | - if ( function_exists( 'mb_strlen' ) ) { |
|
| 669 | - $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding ); |
|
| 667 | +function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') { |
|
| 668 | + if (function_exists('mb_strlen')) { |
|
| 669 | + $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding); |
|
| 670 | 670 | $str_end = ""; |
| 671 | 671 | |
| 672 | - if ( $lower_str_end ) { |
|
| 673 | - $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding ); |
|
| 672 | + if ($lower_str_end) { |
|
| 673 | + $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding); |
|
| 674 | 674 | } else { |
| 675 | - $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ); |
|
| 675 | + $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding); |
|
| 676 | 676 | } |
| 677 | 677 | |
| 678 | 678 | return $first_letter . $str_end; |
| 679 | 679 | } |
| 680 | 680 | |
| 681 | - return ucfirst( $str ); |
|
| 681 | + return ucfirst($str); |
|
| 682 | 682 | } |
| 683 | 683 | |
| 684 | -function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) { |
|
| 685 | - if ( function_exists( 'mb_convert_case' ) ) { |
|
| 686 | - return mb_convert_case( $str, MB_CASE_TITLE, $encoding ); |
|
| 684 | +function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') { |
|
| 685 | + if (function_exists('mb_convert_case')) { |
|
| 686 | + return mb_convert_case($str, MB_CASE_TITLE, $encoding); |
|
| 687 | 687 | } |
| 688 | 688 | |
| 689 | - return ucwords( $str ); |
|
| 689 | + return ucwords($str); |
|
| 690 | 690 | } |
| 691 | 691 | |
| 692 | -function wpinv_period_in_days( $period, $unit ) { |
|
| 693 | - $period = absint( $period ); |
|
| 692 | +function wpinv_period_in_days($period, $unit) { |
|
| 693 | + $period = absint($period); |
|
| 694 | 694 | |
| 695 | - if ( $period > 0 ) { |
|
| 696 | - if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) { |
|
| 695 | + if ($period > 0) { |
|
| 696 | + if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) { |
|
| 697 | 697 | $period = $period * 7; |
| 698 | - } else if ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) { |
|
| 698 | + } else if (in_array(strtolower($unit), array('m', 'month', 'months'))) { |
|
| 699 | 699 | $period = $period * 30; |
| 700 | - } else if ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) { |
|
| 700 | + } else if (in_array(strtolower($unit), array('y', 'year', 'years'))) { |
|
| 701 | 701 | $period = $period * 365; |
| 702 | 702 | } |
| 703 | 703 | } |
@@ -7,28 +7,28 @@ 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_Ajax { |
| 15 | 15 | public static function init() { |
| 16 | - add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 ); |
|
| 17 | - add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 ); |
|
| 16 | + add_action('init', array(__CLASS__, 'define_ajax'), 0); |
|
| 17 | + add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0); |
|
| 18 | 18 | self::add_ajax_events(); |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | public static function define_ajax() { |
| 22 | - if ( !empty( $_GET['wpinv-ajax'] ) ) { |
|
| 23 | - if ( ! defined( 'DOING_AJAX' ) ) { |
|
| 24 | - define( 'DOING_AJAX', true ); |
|
| 22 | + if (!empty($_GET['wpinv-ajax'])) { |
|
| 23 | + if (!defined('DOING_AJAX')) { |
|
| 24 | + define('DOING_AJAX', true); |
|
| 25 | 25 | } |
| 26 | - if ( ! defined( 'WC_DOING_AJAX' ) ) { |
|
| 27 | - define( 'WC_DOING_AJAX', true ); |
|
| 26 | + if (!defined('WC_DOING_AJAX')) { |
|
| 27 | + define('WC_DOING_AJAX', true); |
|
| 28 | 28 | } |
| 29 | 29 | // Turn off display_errors during AJAX events to prevent malformed JSON |
| 30 | - if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { |
|
| 31 | - @ini_set( 'display_errors', 0 ); |
|
| 30 | + if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) { |
|
| 31 | + @ini_set('display_errors', 0); |
|
| 32 | 32 | } |
| 33 | 33 | $GLOBALS['wpdb']->hide_errors(); |
| 34 | 34 | } |
@@ -37,24 +37,24 @@ discard block |
||
| 37 | 37 | public static function do_wpinv_ajax() { |
| 38 | 38 | global $wp_query; |
| 39 | 39 | |
| 40 | - if ( !empty( $_GET['wpinv-ajax'] ) ) { |
|
| 41 | - $wp_query->set( 'wpinv-ajax', sanitize_text_field( $_GET['wpinv-ajax'] ) ); |
|
| 40 | + if (!empty($_GET['wpinv-ajax'])) { |
|
| 41 | + $wp_query->set('wpinv-ajax', sanitize_text_field($_GET['wpinv-ajax'])); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - if ( $action = $wp_query->get( 'wpinv-ajax' ) ) { |
|
| 44 | + if ($action = $wp_query->get('wpinv-ajax')) { |
|
| 45 | 45 | self::wpinv_ajax_headers(); |
| 46 | - do_action( 'wpinv_ajax_' . sanitize_text_field( $action ) ); |
|
| 46 | + do_action('wpinv_ajax_' . sanitize_text_field($action)); |
|
| 47 | 47 | die(); |
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | private static function wpinv_ajax_headers() { |
| 52 | 52 | send_origin_headers(); |
| 53 | - @header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
| 54 | - @header( 'X-Robots-Tag: noindex' ); |
|
| 53 | + @header('Content-Type: text/html; charset=' . get_option('blog_charset')); |
|
| 54 | + @header('X-Robots-Tag: noindex'); |
|
| 55 | 55 | send_nosniff_header(); |
| 56 | 56 | nocache_headers(); |
| 57 | - status_header( 200 ); |
|
| 57 | + status_header(200); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | public static function add_ajax_events() { |
@@ -76,39 +76,39 @@ discard block |
||
| 76 | 76 | 'remove_discount' => false, |
| 77 | 77 | ); |
| 78 | 78 | |
| 79 | - foreach ( $ajax_events as $ajax_event => $nopriv ) { |
|
| 80 | - add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
| 79 | + foreach ($ajax_events as $ajax_event => $nopriv) { |
|
| 80 | + add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
| 81 | 81 | |
| 82 | - if ( !defined( 'WPI_AJAX_' . strtoupper( $nopriv ) ) ) { |
|
| 83 | - define( 'WPI_AJAX_' . strtoupper( $nopriv ), 1 ); |
|
| 82 | + if (!defined('WPI_AJAX_' . strtoupper($nopriv))) { |
|
| 83 | + define('WPI_AJAX_' . strtoupper($nopriv), 1); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - if ( $nopriv ) { |
|
| 87 | - add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
| 86 | + if ($nopriv) { |
|
| 87 | + add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
| 88 | 88 | |
| 89 | - add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
| 89 | + add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
| 90 | 90 | } |
| 91 | 91 | } |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | public static function add_note() { |
| 95 | - check_ajax_referer( 'add-invoice-note', '_nonce' ); |
|
| 95 | + check_ajax_referer('add-invoice-note', '_nonce'); |
|
| 96 | 96 | |
| 97 | - if ( !current_user_can( 'manage_options' ) ) { |
|
| 97 | + if (!current_user_can('manage_options')) { |
|
| 98 | 98 | die(-1); |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - $post_id = absint( $_POST['post_id'] ); |
|
| 102 | - $note = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) ); |
|
| 103 | - $note_type = sanitize_text_field( $_POST['note_type'] ); |
|
| 101 | + $post_id = absint($_POST['post_id']); |
|
| 102 | + $note = wp_kses_post(trim(stripslashes($_POST['note']))); |
|
| 103 | + $note_type = sanitize_text_field($_POST['note_type']); |
|
| 104 | 104 | |
| 105 | 105 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
| 106 | 106 | |
| 107 | - if ( $post_id > 0 ) { |
|
| 108 | - $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note ); |
|
| 107 | + if ($post_id > 0) { |
|
| 108 | + $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note); |
|
| 109 | 109 | |
| 110 | - if ( $note_id > 0 && !is_wp_error( $note_id ) ) { |
|
| 111 | - wpinv_get_invoice_note_line_item( $note_id ); |
|
| 110 | + if ($note_id > 0 && !is_wp_error($note_id)) { |
|
| 111 | + wpinv_get_invoice_note_line_item($note_id); |
|
| 112 | 112 | } |
| 113 | 113 | } |
| 114 | 114 | |
@@ -116,16 +116,16 @@ discard block |
||
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | public static function delete_note() { |
| 119 | - check_ajax_referer( 'delete-invoice-note', '_nonce' ); |
|
| 119 | + check_ajax_referer('delete-invoice-note', '_nonce'); |
|
| 120 | 120 | |
| 121 | - if ( !current_user_can( 'manage_options' ) ) { |
|
| 121 | + if (!current_user_can('manage_options')) { |
|
| 122 | 122 | die(-1); |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | $note_id = (int)$_POST['note_id']; |
| 126 | 126 | |
| 127 | - if ( $note_id > 0 ) { |
|
| 128 | - wp_delete_comment( $note_id, true ); |
|
| 127 | + if ($note_id > 0) { |
|
| 128 | + wp_delete_comment($note_id, true); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | die(); |
@@ -138,8 +138,8 @@ discard block |
||
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | public static function checkout() { |
| 141 | - if ( ! defined( 'WPINV_CHECKOUT' ) ) { |
|
| 142 | - define( 'WPINV_CHECKOUT', true ); |
|
| 141 | + if (!defined('WPINV_CHECKOUT')) { |
|
| 142 | + define('WPINV_CHECKOUT', true); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | wpinv_process_checkout(); |
@@ -148,53 +148,53 @@ discard block |
||
| 148 | 148 | |
| 149 | 149 | public static function add_invoice_item() { |
| 150 | 150 | global $wpi_userID, $wpinv_ip_address_country; |
| 151 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
| 152 | - if ( !current_user_can( 'manage_options' ) ) { |
|
| 151 | + check_ajax_referer('invoice-item', '_nonce'); |
|
| 152 | + if (!current_user_can('manage_options')) { |
|
| 153 | 153 | die(-1); |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - $item_id = sanitize_text_field( $_POST['item_id'] ); |
|
| 157 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
| 156 | + $item_id = sanitize_text_field($_POST['item_id']); |
|
| 157 | + $invoice_id = absint($_POST['invoice_id']); |
|
| 158 | 158 | |
| 159 | - if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) { |
|
| 159 | + if (!is_numeric($invoice_id) || !is_numeric($item_id)) { |
|
| 160 | 160 | die(); |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 164 | - if ( empty( $invoice ) ) { |
|
| 163 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 164 | + if (empty($invoice)) { |
|
| 165 | 165 | die(); |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - if ( $invoice->is_paid() ) { |
|
| 168 | + if ($invoice->is_paid()) { |
|
| 169 | 169 | die(); // Don't allow modify items for paid invoice. |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | - if ( !empty( $_POST['user_id'] ) ) { |
|
| 173 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
| 172 | + if (!empty($_POST['user_id'])) { |
|
| 173 | + $wpi_userID = absint($_POST['user_id']); |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - $item = new WPInv_Item( $item_id ); |
|
| 177 | - if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) { |
|
| 176 | + $item = new WPInv_Item($item_id); |
|
| 177 | + if (!(!empty($item) && $item->post_type == 'wpi_item')) { |
|
| 178 | 178 | die(); |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | // Validate item before adding to invoice because recurring item must be paid individually. |
| 182 | - if ( !empty( $invoice->cart_details ) ) { |
|
| 182 | + if (!empty($invoice->cart_details)) { |
|
| 183 | 183 | $valid = true; |
| 184 | 184 | |
| 185 | - if ( $recurring_item = $invoice->get_recurring() ) { |
|
| 186 | - if ( $recurring_item != $item_id ) { |
|
| 185 | + if ($recurring_item = $invoice->get_recurring()) { |
|
| 186 | + if ($recurring_item != $item_id) { |
|
| 187 | 187 | $valid = false; |
| 188 | 188 | } |
| 189 | - } else if ( wpinv_is_recurring_item( $item_id ) ) { |
|
| 189 | + } else if (wpinv_is_recurring_item($item_id)) { |
|
| 190 | 190 | $valid = false; |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - if ( !$valid ) { |
|
| 193 | + if (!$valid) { |
|
| 194 | 194 | $response = array(); |
| 195 | 195 | $response['success'] = false; |
| 196 | - $response['msg'] = __( 'You can not add item to invoice because recurring item must be paid individually!', 'invoicing' ); |
|
| 197 | - wp_send_json( $response ); |
|
| 196 | + $response['msg'] = __('You can not add item to invoice because recurring item must be paid individually!', 'invoicing'); |
|
| 197 | + wp_send_json($response); |
|
| 198 | 198 | } |
| 199 | 199 | } |
| 200 | 200 | |
@@ -202,9 +202,9 @@ discard block |
||
| 202 | 202 | |
| 203 | 203 | $data = array(); |
| 204 | 204 | $data['invoice_id'] = $invoice_id; |
| 205 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
| 205 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
| 206 | 206 | |
| 207 | - wpinv_set_checkout_session( $data ); |
|
| 207 | + wpinv_set_checkout_session($data); |
|
| 208 | 208 | |
| 209 | 209 | $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int)$_POST['qty'] > 0 ? (int)$_POST['qty'] : 1; |
| 210 | 210 | |
@@ -219,21 +219,21 @@ discard block |
||
| 219 | 219 | 'fees' => array() |
| 220 | 220 | ); |
| 221 | 221 | |
| 222 | - $invoice->add_item( $item_id, $args ); |
|
| 222 | + $invoice->add_item($item_id, $args); |
|
| 223 | 223 | $invoice->save(); |
| 224 | 224 | |
| 225 | - if ( empty( $_POST['country'] ) ) { |
|
| 225 | + if (empty($_POST['country'])) { |
|
| 226 | 226 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
| 227 | 227 | } |
| 228 | - if ( empty( $_POST['state'] ) ) { |
|
| 228 | + if (empty($_POST['state'])) { |
|
| 229 | 229 | $_POST['state'] = $invoice->state; |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
| 233 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
| 232 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
| 233 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
| 234 | 234 | |
| 235 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
| 236 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
| 235 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
| 236 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
| 237 | 237 | |
| 238 | 238 | $wpinv_ip_address_country = $invoice->country; |
| 239 | 239 | |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | |
| 242 | 242 | $response = array(); |
| 243 | 243 | $response['success'] = true; |
| 244 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
| 244 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
| 245 | 245 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
| 246 | 246 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
| 247 | 247 | $response['data']['tax'] = $invoice->get_tax(); |
@@ -253,40 +253,40 @@ discard block |
||
| 253 | 253 | |
| 254 | 254 | wpinv_set_checkout_session($checkout_session); |
| 255 | 255 | |
| 256 | - wp_send_json( $response ); |
|
| 256 | + wp_send_json($response); |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | public static function remove_invoice_item() { |
| 260 | 260 | global $wpi_userID, $wpinv_ip_address_country; |
| 261 | 261 | |
| 262 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
| 263 | - if ( !current_user_can( 'manage_options' ) ) { |
|
| 262 | + check_ajax_referer('invoice-item', '_nonce'); |
|
| 263 | + if (!current_user_can('manage_options')) { |
|
| 264 | 264 | die(-1); |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | - $item_id = sanitize_text_field( $_POST['item_id'] ); |
|
| 268 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
| 269 | - $cart_index = isset( $_POST['index'] ) && $_POST['index'] >= 0 ? $_POST['index'] : false; |
|
| 267 | + $item_id = sanitize_text_field($_POST['item_id']); |
|
| 268 | + $invoice_id = absint($_POST['invoice_id']); |
|
| 269 | + $cart_index = isset($_POST['index']) && $_POST['index'] >= 0 ? $_POST['index'] : false; |
|
| 270 | 270 | |
| 271 | - if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) { |
|
| 271 | + if (!is_numeric($invoice_id) || !is_numeric($item_id)) { |
|
| 272 | 272 | die(); |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 276 | - if ( empty( $invoice ) ) { |
|
| 275 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 276 | + if (empty($invoice)) { |
|
| 277 | 277 | die(); |
| 278 | 278 | } |
| 279 | 279 | |
| 280 | - if ( $invoice->is_paid() ) { |
|
| 280 | + if ($invoice->is_paid()) { |
|
| 281 | 281 | die(); // Don't allow modify items for paid invoice. |
| 282 | 282 | } |
| 283 | 283 | |
| 284 | - if ( !empty( $_POST['user_id'] ) ) { |
|
| 285 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
| 284 | + if (!empty($_POST['user_id'])) { |
|
| 285 | + $wpi_userID = absint($_POST['user_id']); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | - $item = new WPInv_Item( $item_id ); |
|
| 289 | - if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) { |
|
| 288 | + $item = new WPInv_Item($item_id); |
|
| 289 | + if (!(!empty($item) && $item->post_type == 'wpi_item')) { |
|
| 290 | 290 | die(); |
| 291 | 291 | } |
| 292 | 292 | |
@@ -294,9 +294,9 @@ discard block |
||
| 294 | 294 | |
| 295 | 295 | $data = array(); |
| 296 | 296 | $data['invoice_id'] = $invoice_id; |
| 297 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
| 297 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
| 298 | 298 | |
| 299 | - wpinv_set_checkout_session( $data ); |
|
| 299 | + wpinv_set_checkout_session($data); |
|
| 300 | 300 | |
| 301 | 301 | $args = array( |
| 302 | 302 | 'id' => $item_id, |
@@ -304,21 +304,21 @@ discard block |
||
| 304 | 304 | 'cart_index' => $cart_index |
| 305 | 305 | ); |
| 306 | 306 | |
| 307 | - $invoice->remove_item( $item_id, $args ); |
|
| 307 | + $invoice->remove_item($item_id, $args); |
|
| 308 | 308 | $invoice->save(); |
| 309 | 309 | |
| 310 | - if ( empty( $_POST['country'] ) ) { |
|
| 310 | + if (empty($_POST['country'])) { |
|
| 311 | 311 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
| 312 | 312 | } |
| 313 | - if ( empty( $_POST['state'] ) ) { |
|
| 313 | + if (empty($_POST['state'])) { |
|
| 314 | 314 | $_POST['state'] = $invoice->state; |
| 315 | 315 | } |
| 316 | 316 | |
| 317 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
| 318 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
| 317 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
| 318 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
| 319 | 319 | |
| 320 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
| 321 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
| 320 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
| 321 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
| 322 | 322 | |
| 323 | 323 | $wpinv_ip_address_country = $invoice->country; |
| 324 | 324 | |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | |
| 327 | 327 | $response = array(); |
| 328 | 328 | $response['success'] = true; |
| 329 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
| 329 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
| 330 | 330 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
| 331 | 331 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
| 332 | 332 | $response['data']['tax'] = $invoice->get_tax(); |
@@ -338,40 +338,40 @@ discard block |
||
| 338 | 338 | |
| 339 | 339 | wpinv_set_checkout_session($checkout_session); |
| 340 | 340 | |
| 341 | - wp_send_json( $response ); |
|
| 341 | + wp_send_json($response); |
|
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | public static function create_invoice_item() { |
| 345 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
| 346 | - if ( !current_user_can( 'manage_options' ) ) { |
|
| 345 | + check_ajax_referer('invoice-item', '_nonce'); |
|
| 346 | + if (!current_user_can('manage_options')) { |
|
| 347 | 347 | die(-1); |
| 348 | 348 | } |
| 349 | 349 | |
| 350 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
| 350 | + $invoice_id = absint($_POST['invoice_id']); |
|
| 351 | 351 | |
| 352 | 352 | // Find the item |
| 353 | - if ( !is_numeric( $invoice_id ) ) { |
|
| 353 | + if (!is_numeric($invoice_id)) { |
|
| 354 | 354 | die(); |
| 355 | 355 | } |
| 356 | 356 | |
| 357 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 358 | - if ( empty( $invoice ) ) { |
|
| 357 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 358 | + if (empty($invoice)) { |
|
| 359 | 359 | die(); |
| 360 | 360 | } |
| 361 | 361 | |
| 362 | 362 | // Validate item before adding to invoice because recurring item must be paid individually. |
| 363 | - if ( !empty( $invoice->cart_details ) && $invoice->get_recurring() ) { |
|
| 363 | + if (!empty($invoice->cart_details) && $invoice->get_recurring()) { |
|
| 364 | 364 | $response = array(); |
| 365 | 365 | $response['success'] = false; |
| 366 | - $response['msg'] = __( 'You can not add item to invoice because recurring item must be paid individually!', 'invoicing' ); |
|
| 367 | - wp_send_json( $response ); |
|
| 366 | + $response['msg'] = __('You can not add item to invoice because recurring item must be paid individually!', 'invoicing'); |
|
| 367 | + wp_send_json($response); |
|
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | $save_item = $_POST['_wpinv_quick']; |
| 371 | 371 | |
| 372 | 372 | $meta = array(); |
| 373 | 373 | $meta['type'] = !empty($save_item['type']) ? sanitize_text_field($save_item['type']) : 'custom'; |
| 374 | - $meta['price'] = !empty($save_item['price']) ? wpinv_sanitize_amount( $save_item['price'] ) : 0; |
|
| 374 | + $meta['price'] = !empty($save_item['price']) ? wpinv_sanitize_amount($save_item['price']) : 0; |
|
| 375 | 375 | $meta['vat_rule'] = !empty($save_item['vat_rule']) ? sanitize_text_field($save_item['vat_rule']) : 'digital'; |
| 376 | 376 | $meta['vat_class'] = !empty($save_item['vat_class']) ? sanitize_text_field($save_item['vat_class']) : '_standard'; |
| 377 | 377 | |
@@ -381,9 +381,9 @@ discard block |
||
| 381 | 381 | $data['meta'] = $meta; |
| 382 | 382 | |
| 383 | 383 | $item = new WPInv_Item(); |
| 384 | - $item->create( $data ); |
|
| 384 | + $item->create($data); |
|
| 385 | 385 | |
| 386 | - if ( !empty( $item ) ) { |
|
| 386 | + if (!empty($item)) { |
|
| 387 | 387 | $_POST['item_id'] = $item->ID; |
| 388 | 388 | $_POST['qty'] = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int)$save_item['qty'] : 1; |
| 389 | 389 | |
@@ -393,15 +393,15 @@ discard block |
||
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | public static function get_billing_details() { |
| 396 | - check_ajax_referer( 'get-billing-details', '_nonce' ); |
|
| 396 | + check_ajax_referer('get-billing-details', '_nonce'); |
|
| 397 | 397 | |
| 398 | - if ( !current_user_can( 'manage_options' ) ) { |
|
| 398 | + if (!current_user_can('manage_options')) { |
|
| 399 | 399 | die(-1); |
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | $user_id = (int)$_POST['user_id']; |
| 403 | 403 | $billing_details = wpinv_get_user_address($user_id); |
| 404 | - $billing_details = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id ); |
|
| 404 | + $billing_details = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id); |
|
| 405 | 405 | |
| 406 | 406 | if (isset($billing_details['user_id'])) { |
| 407 | 407 | unset($billing_details['user_id']); |
@@ -415,20 +415,20 @@ discard block |
||
| 415 | 415 | $response['success'] = true; |
| 416 | 416 | $response['data']['billing_details'] = $billing_details; |
| 417 | 417 | |
| 418 | - wp_send_json( $response ); |
|
| 418 | + wp_send_json($response); |
|
| 419 | 419 | } |
| 420 | 420 | |
| 421 | 421 | public static function admin_recalculate_totals() { |
| 422 | 422 | global $wpi_userID, $wpinv_ip_address_country; |
| 423 | 423 | |
| 424 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
| 425 | - if ( !current_user_can( 'manage_options' ) ) { |
|
| 424 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
| 425 | + if (!current_user_can('manage_options')) { |
|
| 426 | 426 | die(-1); |
| 427 | 427 | } |
| 428 | 428 | |
| 429 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
| 430 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 431 | - if ( empty( $invoice ) ) { |
|
| 429 | + $invoice_id = absint($_POST['invoice_id']); |
|
| 430 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 431 | + if (empty($invoice)) { |
|
| 432 | 432 | die(); |
| 433 | 433 | } |
| 434 | 434 | |
@@ -436,23 +436,23 @@ discard block |
||
| 436 | 436 | |
| 437 | 437 | $data = array(); |
| 438 | 438 | $data['invoice_id'] = $invoice_id; |
| 439 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
| 439 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
| 440 | 440 | |
| 441 | - wpinv_set_checkout_session( $data ); |
|
| 441 | + wpinv_set_checkout_session($data); |
|
| 442 | 442 | |
| 443 | - if ( !empty( $_POST['user_id'] ) ) { |
|
| 444 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
| 443 | + if (!empty($_POST['user_id'])) { |
|
| 444 | + $wpi_userID = absint($_POST['user_id']); |
|
| 445 | 445 | } |
| 446 | 446 | |
| 447 | - if ( empty( $_POST['country'] ) ) { |
|
| 447 | + if (empty($_POST['country'])) { |
|
| 448 | 448 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
| 449 | 449 | } |
| 450 | 450 | |
| 451 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
| 452 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
| 453 | - if ( isset( $_POST['state'] ) ) { |
|
| 454 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
| 455 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
| 451 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
| 452 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
| 453 | + if (isset($_POST['state'])) { |
|
| 454 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
| 455 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
| 456 | 456 | } |
| 457 | 457 | |
| 458 | 458 | $wpinv_ip_address_country = $invoice->country; |
@@ -461,7 +461,7 @@ discard block |
||
| 461 | 461 | |
| 462 | 462 | $response = array(); |
| 463 | 463 | $response['success'] = true; |
| 464 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
| 464 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
| 465 | 465 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
| 466 | 466 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
| 467 | 467 | $response['data']['tax'] = $invoice->get_tax(); |
@@ -473,25 +473,25 @@ discard block |
||
| 473 | 473 | |
| 474 | 474 | wpinv_set_checkout_session($checkout_session); |
| 475 | 475 | |
| 476 | - wp_send_json( $response ); |
|
| 476 | + wp_send_json($response); |
|
| 477 | 477 | } |
| 478 | 478 | |
| 479 | 479 | public static function admin_apply_discount() { |
| 480 | 480 | global $wpi_userID; |
| 481 | 481 | |
| 482 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
| 483 | - if ( !current_user_can( 'manage_options' ) ) { |
|
| 482 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
| 483 | + if (!current_user_can('manage_options')) { |
|
| 484 | 484 | die(-1); |
| 485 | 485 | } |
| 486 | 486 | |
| 487 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
| 488 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
| 489 | - if ( empty( $invoice_id ) || empty( $discount_code ) ) { |
|
| 487 | + $invoice_id = absint($_POST['invoice_id']); |
|
| 488 | + $discount_code = sanitize_text_field($_POST['code']); |
|
| 489 | + if (empty($invoice_id) || empty($discount_code)) { |
|
| 490 | 490 | die(); |
| 491 | 491 | } |
| 492 | 492 | |
| 493 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 494 | - if ( empty( $invoice ) || ( !empty( $invoice ) && $invoice->is_paid() ) ) { |
|
| 493 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 494 | + if (empty($invoice) || (!empty($invoice) && $invoice->is_paid())) { |
|
| 495 | 495 | die(); |
| 496 | 496 | } |
| 497 | 497 | |
@@ -499,49 +499,49 @@ discard block |
||
| 499 | 499 | |
| 500 | 500 | $data = array(); |
| 501 | 501 | $data['invoice_id'] = $invoice_id; |
| 502 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
| 502 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
| 503 | 503 | |
| 504 | - wpinv_set_checkout_session( $data ); |
|
| 504 | + wpinv_set_checkout_session($data); |
|
| 505 | 505 | |
| 506 | 506 | $response = array(); |
| 507 | 507 | $response['success'] = false; |
| 508 | - $response['msg'] = __( 'This discount is invalid.', 'invoicing' ); |
|
| 508 | + $response['msg'] = __('This discount is invalid.', 'invoicing'); |
|
| 509 | 509 | $response['data']['code'] = $discount_code; |
| 510 | 510 | |
| 511 | - if ( wpinv_is_discount_valid( $discount_code, $invoice->get_user_id() ) ) { |
|
| 512 | - $discounts = wpinv_set_cart_discount( $discount_code ); |
|
| 511 | + if (wpinv_is_discount_valid($discount_code, $invoice->get_user_id())) { |
|
| 512 | + $discounts = wpinv_set_cart_discount($discount_code); |
|
| 513 | 513 | |
| 514 | 514 | $response['success'] = true; |
| 515 | - $response['msg'] = __( 'Discount has been applied successfully.', 'invoicing' ); |
|
| 516 | - } else { |
|
| 515 | + $response['msg'] = __('Discount has been applied successfully.', 'invoicing'); |
|
| 516 | + } else { |
|
| 517 | 517 | $errors = wpinv_get_errors(); |
| 518 | - if ( !empty( $errors['wpinv-discount-error'] ) ) { |
|
| 518 | + if (!empty($errors['wpinv-discount-error'])) { |
|
| 519 | 519 | $response['msg'] = $errors['wpinv-discount-error']; |
| 520 | 520 | } |
| 521 | - wpinv_unset_error( 'wpinv-discount-error' ); |
|
| 521 | + wpinv_unset_error('wpinv-discount-error'); |
|
| 522 | 522 | } |
| 523 | 523 | |
| 524 | 524 | wpinv_set_checkout_session($checkout_session); |
| 525 | 525 | |
| 526 | - wp_send_json( $response ); |
|
| 526 | + wp_send_json($response); |
|
| 527 | 527 | } |
| 528 | 528 | |
| 529 | 529 | public static function admin_remove_discount() { |
| 530 | 530 | global $wpi_userID; |
| 531 | 531 | |
| 532 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
| 533 | - if ( !current_user_can( 'manage_options' ) ) { |
|
| 532 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
| 533 | + if (!current_user_can('manage_options')) { |
|
| 534 | 534 | die(-1); |
| 535 | 535 | } |
| 536 | 536 | |
| 537 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
| 538 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
| 539 | - if ( empty( $invoice_id ) || empty( $discount_code ) ) { |
|
| 537 | + $invoice_id = absint($_POST['invoice_id']); |
|
| 538 | + $discount_code = sanitize_text_field($_POST['code']); |
|
| 539 | + if (empty($invoice_id) || empty($discount_code)) { |
|
| 540 | 540 | die(); |
| 541 | 541 | } |
| 542 | 542 | |
| 543 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 544 | - if ( empty( $invoice ) || ( !empty( $invoice ) && $invoice->is_paid() ) ) { |
|
| 543 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 544 | + if (empty($invoice) || (!empty($invoice) && $invoice->is_paid())) { |
|
| 545 | 545 | die(); |
| 546 | 546 | } |
| 547 | 547 | |
@@ -549,38 +549,38 @@ discard block |
||
| 549 | 549 | |
| 550 | 550 | $data = array(); |
| 551 | 551 | $data['invoice_id'] = $invoice_id; |
| 552 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
| 552 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
| 553 | 553 | |
| 554 | - wpinv_set_checkout_session( $data ); |
|
| 554 | + wpinv_set_checkout_session($data); |
|
| 555 | 555 | |
| 556 | 556 | $response = array(); |
| 557 | 557 | $response['success'] = false; |
| 558 | 558 | $response['msg'] = NULL; |
| 559 | 559 | |
| 560 | - $discounts = wpinv_unset_cart_discount( $discount_code ); |
|
| 560 | + $discounts = wpinv_unset_cart_discount($discount_code); |
|
| 561 | 561 | $response['success'] = true; |
| 562 | - $response['msg'] = __( 'Discount has been removed successfully.', 'invoicing' ); |
|
| 562 | + $response['msg'] = __('Discount has been removed successfully.', 'invoicing'); |
|
| 563 | 563 | |
| 564 | 564 | wpinv_set_checkout_session($checkout_session); |
| 565 | 565 | |
| 566 | - wp_send_json( $response ); |
|
| 566 | + wp_send_json($response); |
|
| 567 | 567 | } |
| 568 | 568 | |
| 569 | 569 | public static function check_email() { |
| 570 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
| 571 | - if ( !current_user_can( 'manage_options' ) ) { |
|
| 570 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
| 571 | + if (!current_user_can('manage_options')) { |
|
| 572 | 572 | die(-1); |
| 573 | 573 | } |
| 574 | 574 | |
| 575 | - $email = sanitize_text_field( $_POST['email'] ); |
|
| 575 | + $email = sanitize_text_field($_POST['email']); |
|
| 576 | 576 | |
| 577 | 577 | $response = array(); |
| 578 | - if ( is_email( $email ) && email_exists( $email ) && $user_data = get_user_by( 'email', $email ) ) { |
|
| 578 | + if (is_email($email) && email_exists($email) && $user_data = get_user_by('email', $email)) { |
|
| 579 | 579 | $user_id = $user_data->ID; |
| 580 | 580 | $user_login = $user_data->user_login; |
| 581 | 581 | $display_name = $user_data->display_name ? $user_data->display_name : $user_login; |
| 582 | 582 | $billing_details = wpinv_get_user_address($user_id); |
| 583 | - $billing_details = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id ); |
|
| 583 | + $billing_details = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id); |
|
| 584 | 584 | |
| 585 | 585 | if (isset($billing_details['user_id'])) { |
| 586 | 586 | unset($billing_details['user_id']); |
@@ -596,31 +596,31 @@ discard block |
||
| 596 | 596 | $response['data']['billing_details'] = $billing_details; |
| 597 | 597 | } |
| 598 | 598 | |
| 599 | - wp_send_json( $response ); |
|
| 599 | + wp_send_json($response); |
|
| 600 | 600 | } |
| 601 | 601 | |
| 602 | 602 | public static function run_tool() { |
| 603 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
| 604 | - if ( !current_user_can( 'manage_options' ) ) { |
|
| 603 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
| 604 | + if (!current_user_can('manage_options')) { |
|
| 605 | 605 | die(-1); |
| 606 | 606 | } |
| 607 | 607 | |
| 608 | - $tool = sanitize_text_field( $_POST['tool'] ); |
|
| 608 | + $tool = sanitize_text_field($_POST['tool']); |
|
| 609 | 609 | |
| 610 | - do_action( 'wpinv_run_tool' ); |
|
| 610 | + do_action('wpinv_run_tool'); |
|
| 611 | 611 | |
| 612 | - if ( !empty( $tool ) ) { |
|
| 613 | - do_action( 'wpinv_tool_' . $tool ); |
|
| 612 | + if (!empty($tool)) { |
|
| 613 | + do_action('wpinv_tool_' . $tool); |
|
| 614 | 614 | } |
| 615 | 615 | } |
| 616 | 616 | |
| 617 | 617 | public static function apply_discount() { |
| 618 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
| 618 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
| 619 | 619 | |
| 620 | 620 | $response = array(); |
| 621 | 621 | |
| 622 | - if ( isset( $_POST['code'] ) ) { |
|
| 623 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
| 622 | + if (isset($_POST['code'])) { |
|
| 623 | + $discount_code = sanitize_text_field($_POST['code']); |
|
| 624 | 624 | |
| 625 | 625 | $response['success'] = false; |
| 626 | 626 | $response['msg'] = ''; |
@@ -628,14 +628,14 @@ discard block |
||
| 628 | 628 | |
| 629 | 629 | $user = is_user_logged_in() ? get_current_user_id() : ''; |
| 630 | 630 | |
| 631 | - if ( wpinv_is_discount_valid( $discount_code, $user ) ) { |
|
| 632 | - $discount = wpinv_get_discount_by_code( $discount_code ); |
|
| 633 | - $discounts = wpinv_set_cart_discount( $discount_code ); |
|
| 634 | - $amount = wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) ); |
|
| 635 | - $total = wpinv_get_cart_total( null, $discounts ); |
|
| 636 | - $cart_totals = wpinv_recalculate_tax( true ); |
|
| 631 | + if (wpinv_is_discount_valid($discount_code, $user)) { |
|
| 632 | + $discount = wpinv_get_discount_by_code($discount_code); |
|
| 633 | + $discounts = wpinv_set_cart_discount($discount_code); |
|
| 634 | + $amount = wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID)); |
|
| 635 | + $total = wpinv_get_cart_total(null, $discounts); |
|
| 636 | + $cart_totals = wpinv_recalculate_tax(true); |
|
| 637 | 637 | |
| 638 | - if ( !empty( $cart_totals ) ) { |
|
| 638 | + if (!empty($cart_totals)) { |
|
| 639 | 639 | $response['success'] = true; |
| 640 | 640 | $response['data'] = $cart_totals; |
| 641 | 641 | $response['data']['code'] = $discount_code; |
@@ -644,29 +644,29 @@ discard block |
||
| 644 | 644 | } |
| 645 | 645 | } else { |
| 646 | 646 | $errors = wpinv_get_errors(); |
| 647 | - $response['msg'] = $errors['wpinv-discount-error']; |
|
| 648 | - wpinv_unset_error( 'wpinv-discount-error' ); |
|
| 647 | + $response['msg'] = $errors['wpinv-discount-error']; |
|
| 648 | + wpinv_unset_error('wpinv-discount-error'); |
|
| 649 | 649 | } |
| 650 | 650 | |
| 651 | 651 | // Allow for custom discount code handling |
| 652 | - $response = apply_filters( 'wpinv_ajax_discount_response', $response ); |
|
| 652 | + $response = apply_filters('wpinv_ajax_discount_response', $response); |
|
| 653 | 653 | } |
| 654 | 654 | |
| 655 | - wp_send_json( $response ); |
|
| 655 | + wp_send_json($response); |
|
| 656 | 656 | } |
| 657 | 657 | |
| 658 | 658 | public static function remove_discount() { |
| 659 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
| 659 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
| 660 | 660 | |
| 661 | 661 | $response = array(); |
| 662 | 662 | |
| 663 | - if ( isset( $_POST['code'] ) ) { |
|
| 664 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
| 665 | - $discounts = wpinv_unset_cart_discount( $discount_code ); |
|
| 666 | - $total = wpinv_get_cart_total( null, $discounts ); |
|
| 667 | - $cart_totals = wpinv_recalculate_tax( true ); |
|
| 663 | + if (isset($_POST['code'])) { |
|
| 664 | + $discount_code = sanitize_text_field($_POST['code']); |
|
| 665 | + $discounts = wpinv_unset_cart_discount($discount_code); |
|
| 666 | + $total = wpinv_get_cart_total(null, $discounts); |
|
| 667 | + $cart_totals = wpinv_recalculate_tax(true); |
|
| 668 | 668 | |
| 669 | - if ( !empty( $cart_totals ) ) { |
|
| 669 | + if (!empty($cart_totals)) { |
|
| 670 | 670 | $response['success'] = true; |
| 671 | 671 | $response['data'] = $cart_totals; |
| 672 | 672 | $response['data']['code'] = $discount_code; |
@@ -675,10 +675,10 @@ discard block |
||
| 675 | 675 | } |
| 676 | 676 | |
| 677 | 677 | // Allow for custom discount code handling |
| 678 | - $response = apply_filters( 'wpinv_ajax_discount_response', $response ); |
|
| 678 | + $response = apply_filters('wpinv_ajax_discount_response', $response); |
|
| 679 | 679 | } |
| 680 | 680 | |
| 681 | - wp_send_json( $response ); |
|
| 681 | + wp_send_json($response); |
|
| 682 | 682 | } |
| 683 | 683 | } |
| 684 | 684 | |
@@ -1,80 +1,80 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if (!defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
| 6 | -if ( !( $user_id = get_current_user_id() ) ) { |
|
| 6 | +if (!($user_id = get_current_user_id())) { |
|
| 7 | 7 | ?> |
| 8 | - <div class="wpinv-empty alert alert-error"><?php _e( 'You are not allowed to access this section', 'invoicing' ) ;?></div> |
|
| 8 | + <div class="wpinv-empty alert alert-error"><?php _e('You are not allowed to access this section', 'invoicing'); ?></div> |
|
| 9 | 9 | <?php |
| 10 | 10 | return; |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | global $current_page; |
| 14 | -$current_page = empty( $current_page ) ? 1 : absint( $current_page ); |
|
| 15 | -$query = apply_filters( 'wpinv_user_invoices_query', array( 'user' => $user_id, 'page' => $current_page, 'paginate' => true ) ); |
|
| 16 | -$user_invoices = wpinv_get_invoices( $query ); |
|
| 14 | +$current_page = empty($current_page) ? 1 : absint($current_page); |
|
| 15 | +$query = apply_filters('wpinv_user_invoices_query', array('user' => $user_id, 'page' => $current_page, 'paginate' => true)); |
|
| 16 | +$user_invoices = wpinv_get_invoices($query); |
|
| 17 | 17 | $has_invoices = 0 < $user_invoices->total; |
| 18 | 18 | |
| 19 | -do_action( 'wpinv_before_user_invoices', $has_invoices ); ?> |
|
| 19 | +do_action('wpinv_before_user_invoices', $has_invoices); ?> |
|
| 20 | 20 | |
| 21 | -<?php if ( $has_invoices ) { ?> |
|
| 21 | +<?php if ($has_invoices) { ?> |
|
| 22 | 22 | <table class="table table-bordered table-hover wpi-user-invoices"> |
| 23 | 23 | <thead> |
| 24 | 24 | <tr> |
| 25 | - <?php foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : ?> |
|
| 26 | - <th class="<?php echo esc_attr( $column_id ); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : '');?>"><span class="nobr"><?php echo esc_html( $column_name['title'] ); ?></span></th> |
|
| 25 | + <?php foreach (wpinv_get_user_invoices_columns() as $column_id => $column_name) : ?> |
|
| 26 | + <th class="<?php echo esc_attr($column_id); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : ''); ?>"><span class="nobr"><?php echo esc_html($column_name['title']); ?></span></th> |
|
| 27 | 27 | <?php endforeach; ?> |
| 28 | 28 | </tr> |
| 29 | 29 | </thead> |
| 30 | 30 | |
| 31 | 31 | <tbody> |
| 32 | - <?php foreach ( $user_invoices->invoices as $invoice ) { |
|
| 32 | + <?php foreach ($user_invoices->invoices as $invoice) { |
|
| 33 | 33 | ?> |
| 34 | 34 | <tr class="wpinv-item wpinv-item-<?php echo $invoice_status = $invoice->get_status(); ?>"> |
| 35 | - <?php foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : ?> |
|
| 36 | - <td class="<?php echo esc_attr( $column_id ); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : '');?>" data-title="<?php echo esc_attr( $column_name['title'] ); ?>"> |
|
| 37 | - <?php if ( has_action( 'wpinv_user_invoices_column_' . $column_id ) ) : ?> |
|
| 38 | - <?php do_action( 'wpinv_user_invoices_column_' . $column_id, $invoice ); ?> |
|
| 39 | - |
|
| 40 | - <?php elseif ( 'invoice-number' === $column_id ) : ?> |
|
| 41 | - <a href="<?php echo esc_url( $invoice->get_view_url() ); ?>"> |
|
| 42 | - <?php echo _x( '#', 'hash before invoice number', 'invoicing' ) . $invoice->get_number(); ?> |
|
| 35 | + <?php foreach (wpinv_get_user_invoices_columns() as $column_id => $column_name) : ?> |
|
| 36 | + <td class="<?php echo esc_attr($column_id); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : ''); ?>" data-title="<?php echo esc_attr($column_name['title']); ?>"> |
|
| 37 | + <?php if (has_action('wpinv_user_invoices_column_' . $column_id)) : ?> |
|
| 38 | + <?php do_action('wpinv_user_invoices_column_' . $column_id, $invoice); ?> |
|
| 39 | + |
|
| 40 | + <?php elseif ('invoice-number' === $column_id) : ?> |
|
| 41 | + <a href="<?php echo esc_url($invoice->get_view_url()); ?>"> |
|
| 42 | + <?php echo _x('#', 'hash before invoice number', 'invoicing') . $invoice->get_number(); ?> |
|
| 43 | 43 | </a> |
| 44 | 44 | |
| 45 | - <?php elseif ( 'invoice-date' === $column_id ) : $date = wpinv_get_invoice_date( $invoice->ID ); $dateYMD = wpinv_get_invoice_date( $invoice->ID, 'Y-m-d H:i:s' ); ?> |
|
| 46 | - <time datetime="<?php echo strtotime( $dateYMD ); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time> |
|
| 45 | + <?php elseif ('invoice-date' === $column_id) : $date = wpinv_get_invoice_date($invoice->ID); $dateYMD = wpinv_get_invoice_date($invoice->ID, 'Y-m-d H:i:s'); ?> |
|
| 46 | + <time datetime="<?php echo strtotime($dateYMD); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time> |
|
| 47 | 47 | |
| 48 | - <?php elseif ( 'invoice-status' === $column_id ) : ?> |
|
| 49 | - <?php echo wpinv_invoice_status_label( $invoice_status, $invoice->get_status( true ) ) ; ?> |
|
| 48 | + <?php elseif ('invoice-status' === $column_id) : ?> |
|
| 49 | + <?php echo wpinv_invoice_status_label($invoice_status, $invoice->get_status(true)); ?> |
|
| 50 | 50 | |
| 51 | - <?php elseif ( 'invoice-total' === $column_id ) : ?> |
|
| 52 | - <?php echo $invoice->get_total( true ); ?> |
|
| 51 | + <?php elseif ('invoice-total' === $column_id) : ?> |
|
| 52 | + <?php echo $invoice->get_total(true); ?> |
|
| 53 | 53 | |
| 54 | - <?php elseif ( 'invoice-actions' === $column_id ) : ?> |
|
| 54 | + <?php elseif ('invoice-actions' === $column_id) : ?> |
|
| 55 | 55 | <?php |
| 56 | 56 | $actions = array( |
| 57 | 57 | 'pay' => array( |
| 58 | 58 | 'url' => $invoice->get_checkout_payment_url(), |
| 59 | - 'name' => __( 'Pay Now', 'invoicing' ), |
|
| 59 | + 'name' => __('Pay Now', 'invoicing'), |
|
| 60 | 60 | 'class' => 'btn-success' |
| 61 | 61 | ), |
| 62 | 62 | 'print' => array( |
| 63 | 63 | 'url' => $invoice->get_view_url(), |
| 64 | - 'name' => __( 'Print', 'invoicing' ), |
|
| 64 | + 'name' => __('Print', 'invoicing'), |
|
| 65 | 65 | 'class' => 'btn-primary', |
| 66 | 66 | 'attrs' => 'target="_blank"' |
| 67 | 67 | ) |
| 68 | 68 | ); |
| 69 | 69 | |
| 70 | - if ( ! $invoice->needs_payment() ) { |
|
| 71 | - unset( $actions['pay'] ); |
|
| 70 | + if (!$invoice->needs_payment()) { |
|
| 71 | + unset($actions['pay']); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - if ( $actions = apply_filters( 'wpinv_user_invoices_actions', $actions, $invoice ) ) { |
|
| 75 | - foreach ( $actions as $key => $action ) { |
|
| 74 | + if ($actions = apply_filters('wpinv_user_invoices_actions', $actions, $invoice)) { |
|
| 75 | + foreach ($actions as $key => $action) { |
|
| 76 | 76 | $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; |
| 77 | - echo '<a href="' . esc_url( $action['url'] ) . '" class="btn btn-sm ' . $class . ' ' . sanitize_html_class( $key ) . '" ' . ( !empty($action['attrs']) ? $action['attrs'] : '' ) . '>' . $action['name'] . '</a>'; |
|
| 77 | + echo '<a href="' . esc_url($action['url']) . '" class="btn btn-sm ' . $class . ' ' . sanitize_html_class($key) . '" ' . (!empty($action['attrs']) ? $action['attrs'] : '') . '>' . $action['name'] . '</a>'; |
|
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | ?> |
@@ -86,9 +86,9 @@ discard block |
||
| 86 | 86 | </tbody> |
| 87 | 87 | </table> |
| 88 | 88 | |
| 89 | - <?php do_action( 'wpinv_before_user_invoices_pagination' ); ?> |
|
| 89 | + <?php do_action('wpinv_before_user_invoices_pagination'); ?> |
|
| 90 | 90 | |
| 91 | - <?php if ( 1 < $user_invoices->max_num_pages ) : ?> |
|
| 91 | + <?php if (1 < $user_invoices->max_num_pages) : ?> |
|
| 92 | 92 | <div class="invoicing-Pagination"> |
| 93 | 93 | <?php |
| 94 | 94 | $big = 999999; |
@@ -101,23 +101,23 @@ discard block |
||
| 101 | 101 | else |
| 102 | 102 | $current_page = 1; |
| 103 | 103 | |
| 104 | - echo paginate_links( array( |
|
| 105 | - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
| 104 | + echo paginate_links(array( |
|
| 105 | + 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
| 106 | 106 | 'format' => '?paged=%#%', |
| 107 | - 'current' => max( 1, $current_page ), |
|
| 107 | + 'current' => max(1, $current_page), |
|
| 108 | 108 | 'total' => $user_invoices->max_num_pages, |
| 109 | 109 | 'add_args' => array( |
| 110 | 110 | 'wpinv-cpt' => 'wpi_invoice', |
| 111 | 111 | ) |
| 112 | - ) ); |
|
| 112 | + )); |
|
| 113 | 113 | ?> |
| 114 | 114 | </div> |
| 115 | 115 | <?php endif; ?> |
| 116 | 116 | |
| 117 | 117 | <?php } else { ?> |
| 118 | 118 | <div class="wpinv-empty alert-info"> |
| 119 | - <?php _e( 'No invoice has been made yet.', 'invoicing' ); ?> |
|
| 119 | + <?php _e('No invoice has been made yet.', 'invoicing'); ?> |
|
| 120 | 120 | </div> |
| 121 | 121 | <?php } ?> |
| 122 | 122 | |
| 123 | -<?php do_action( 'wpinv_after_user_invoices', $has_invoices ); ?> |
|
| 123 | +<?php do_action('wpinv_after_user_invoices', $has_invoices); ?> |
|
@@ -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 ( !empty( $post ) && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) { |
|
| 91 | + if (!empty($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 ( !empty( $post ) && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) { |
|
| 104 | + if (!empty($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 ) && "wpi_invoice" === $invoice->post_type ) { |
|
| 881 | - if ( $invoice->is_paid() ) { |
|
| 882 | - return __( 'Paid', 'invoicing' ); |
|
| 880 | + if (!empty($invoice) && "wpi_invoice" === $invoice->post_type) { |
|
| 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 style="clear:both"></div> |
| 1553 | 1553 | <div class="col-sm-12 wpinv-discount-msg"> |
@@ -1560,10 +1560,10 @@ discard block |
||
| 1560 | 1560 | <?php |
| 1561 | 1561 | } |
| 1562 | 1562 | } |
| 1563 | -add_action( 'wpinv_after_checkout_cart', 'wpinv_discount_field', -10 ); |
|
| 1563 | +add_action('wpinv_after_checkout_cart', 'wpinv_discount_field', -10); |
|
| 1564 | 1564 | |
| 1565 | 1565 | function wpinv_agree_to_terms_js() { |
| 1566 | - if ( wpinv_get_option( 'show_agree_to_terms', false ) ) { |
|
| 1566 | + if (wpinv_get_option('show_agree_to_terms', false)) { |
|
| 1567 | 1567 | ?> |
| 1568 | 1568 | <script type="text/javascript"> |
| 1569 | 1569 | jQuery(document).ready(function($){ |
@@ -1578,126 +1578,126 @@ discard block |
||
| 1578 | 1578 | <?php |
| 1579 | 1579 | } |
| 1580 | 1580 | } |
| 1581 | -add_action( 'wpinv_checkout_form_top', 'wpinv_agree_to_terms_js' ); |
|
| 1581 | +add_action('wpinv_checkout_form_top', 'wpinv_agree_to_terms_js'); |
|
| 1582 | 1582 | |
| 1583 | 1583 | function wpinv_payment_mode_select() { |
| 1584 | - $gateways = wpinv_get_enabled_payment_gateways( true ); |
|
| 1585 | - $gateways = apply_filters( 'wpinv_payment_gateways_on_cart', $gateways ); |
|
| 1584 | + $gateways = wpinv_get_enabled_payment_gateways(true); |
|
| 1585 | + $gateways = apply_filters('wpinv_payment_gateways_on_cart', $gateways); |
|
| 1586 | 1586 | $page_URL = wpinv_get_current_page_url(); |
| 1587 | - $invoice = wpinv_get_invoice( 0, true ); |
|
| 1587 | + $invoice = wpinv_get_invoice(0, true); |
|
| 1588 | 1588 | |
| 1589 | 1589 | do_action('wpinv_payment_mode_top'); |
| 1590 | 1590 | $invoice_id = (int)$invoice->ID; |
| 1591 | - $chosen_gateway = wpinv_get_chosen_gateway( $invoice_id ); |
|
| 1591 | + $chosen_gateway = wpinv_get_chosen_gateway($invoice_id); |
|
| 1592 | 1592 | ?> |
| 1593 | - <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo ( $invoice->is_free() ? 'style="display:none;"' : '' ); ?>> |
|
| 1594 | - <?php do_action( 'wpinv_payment_mode_before_gateways_wrap' ); ?> |
|
| 1593 | + <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo ($invoice->is_free() ? 'style="display:none;"' : ''); ?>> |
|
| 1594 | + <?php do_action('wpinv_payment_mode_before_gateways_wrap'); ?> |
|
| 1595 | 1595 | <div id="wpinv-payment-mode-wrap" class="panel panel-default"> |
| 1596 | - <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Select Payment Method', 'invoicing' ); ?></h3></div> |
|
| 1596 | + <div class="panel-heading"><h3 class="panel-title"><?php _e('Select Payment Method', 'invoicing'); ?></h3></div> |
|
| 1597 | 1597 | <div class="panel-body list-group wpi-payment_methods"> |
| 1598 | 1598 | <?php |
| 1599 | - do_action( 'wpinv_payment_mode_before_gateways' ); |
|
| 1599 | + do_action('wpinv_payment_mode_before_gateways'); |
|
| 1600 | 1600 | |
| 1601 | - if(!empty($gateways)){ |
|
| 1602 | - foreach ( $gateways as $gateway_id => $gateway ) { |
|
| 1603 | - $checked = checked( $gateway_id, $chosen_gateway, false ); |
|
| 1604 | - $button_label = wpinv_get_gateway_button_label( $gateway_id ); |
|
| 1605 | - $description = wpinv_get_gateway_description( $gateway_id ); |
|
| 1601 | + if (!empty($gateways)) { |
|
| 1602 | + foreach ($gateways as $gateway_id => $gateway) { |
|
| 1603 | + $checked = checked($gateway_id, $chosen_gateway, false); |
|
| 1604 | + $button_label = wpinv_get_gateway_button_label($gateway_id); |
|
| 1605 | + $description = wpinv_get_gateway_description($gateway_id); |
|
| 1606 | 1606 | ?> |
| 1607 | 1607 | <div class="list-group-item"> |
| 1608 | 1608 | <div class="radio"> |
| 1609 | - <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 | + <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> |
|
| 1610 | 1610 | </div> |
| 1611 | - <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr( $gateway_id );?>" role="alert"> |
|
| 1612 | - <?php if ( !empty( $description ) ) { ?> |
|
| 1613 | - <div class="wpi-gateway-desc alert alert-info"><?php echo $description;?></div> |
|
| 1611 | + <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr($gateway_id); ?>" role="alert"> |
|
| 1612 | + <?php if (!empty($description)) { ?> |
|
| 1613 | + <div class="wpi-gateway-desc alert alert-info"><?php echo $description; ?></div> |
|
| 1614 | 1614 | <?php } ?> |
| 1615 | - <?php do_action( 'wpinv_' . $gateway_id . '_cc_form', $invoice_id ) ;?> |
|
| 1615 | + <?php do_action('wpinv_' . $gateway_id . '_cc_form', $invoice_id); ?> |
|
| 1616 | 1616 | </div> |
| 1617 | 1617 | </div> |
| 1618 | 1618 | <?php |
| 1619 | 1619 | } |
| 1620 | - }else{ |
|
| 1621 | - echo '<div class="alert alert-warning">'. __('No payment gateway active','invoicing') .'</div>'; |
|
| 1620 | + } else { |
|
| 1621 | + echo '<div class="alert alert-warning">' . __('No payment gateway active', 'invoicing') . '</div>'; |
|
| 1622 | 1622 | } |
| 1623 | 1623 | |
| 1624 | - do_action( 'wpinv_payment_mode_after_gateways' ); |
|
| 1624 | + do_action('wpinv_payment_mode_after_gateways'); |
|
| 1625 | 1625 | ?> |
| 1626 | 1626 | </div> |
| 1627 | 1627 | </div> |
| 1628 | - <?php do_action( 'wpinv_payment_mode_after_gateways_wrap' ); ?> |
|
| 1628 | + <?php do_action('wpinv_payment_mode_after_gateways_wrap'); ?> |
|
| 1629 | 1629 | </div> |
| 1630 | 1630 | <?php |
| 1631 | 1631 | do_action('wpinv_payment_mode_bottom'); |
| 1632 | 1632 | } |
| 1633 | -add_action( 'wpinv_payment_mode_select', 'wpinv_payment_mode_select' ); |
|
| 1633 | +add_action('wpinv_payment_mode_select', 'wpinv_payment_mode_select'); |
|
| 1634 | 1634 | |
| 1635 | 1635 | function wpinv_checkout_billing_info() { |
| 1636 | - if ( wpinv_is_checkout() ) { |
|
| 1636 | + if (wpinv_is_checkout()) { |
|
| 1637 | 1637 | $logged_in = is_user_logged_in(); |
| 1638 | 1638 | $billing_details = wpinv_checkout_billing_details(); |
| 1639 | - $selected_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : wpinv_default_billing_country(); |
|
| 1639 | + $selected_country = !empty($billing_details['country']) ? $billing_details['country'] : wpinv_default_billing_country(); |
|
| 1640 | 1640 | ?> |
| 1641 | 1641 | <div id="wpinv-fields" class="clearfix"> |
| 1642 | 1642 | <div id="wpi-billing" class="wpi-billing clearfix panel panel-default"> |
| 1643 | - <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Billing Details', 'invoicing' );?></h3></div> |
|
| 1643 | + <div class="panel-heading"><h3 class="panel-title"><?php _e('Billing Details', 'invoicing'); ?></h3></div> |
|
| 1644 | 1644 | <div id="wpinv-fields-box" class="panel-body"> |
| 1645 | - <?php do_action( 'wpinv_checkout_billing_fields_first', $billing_details ); ?> |
|
| 1645 | + <?php do_action('wpinv_checkout_billing_fields_first', $billing_details); ?> |
|
| 1646 | 1646 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
| 1647 | - <label for="wpinv_first_name" class="wpi-label"><?php _e( 'First Name', 'invoicing' );?><?php if ( wpinv_get_option( 'fname_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1647 | + <label for="wpinv_first_name" class="wpi-label"><?php _e('First Name', 'invoicing'); ?><?php if (wpinv_get_option('fname_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1648 | 1648 | <?php |
| 1649 | - echo wpinv_html_text( array( |
|
| 1649 | + echo wpinv_html_text(array( |
|
| 1650 | 1650 | 'id' => 'wpinv_first_name', |
| 1651 | 1651 | 'name' => 'wpinv_first_name', |
| 1652 | 1652 | 'value' => $billing_details['first_name'], |
| 1653 | 1653 | 'class' => 'wpi-input form-control required', |
| 1654 | - 'placeholder' => __( 'First name', 'invoicing' ), |
|
| 1655 | - 'required' => (bool)wpinv_get_option( 'fname_mandatory' ), |
|
| 1656 | - ) ); |
|
| 1654 | + 'placeholder' => __('First name', 'invoicing'), |
|
| 1655 | + 'required' => (bool)wpinv_get_option('fname_mandatory'), |
|
| 1656 | + )); |
|
| 1657 | 1657 | ?> |
| 1658 | 1658 | </p> |
| 1659 | 1659 | <p class="wpi-cart-field wpi-col2 wpi-coll"> |
| 1660 | - <label for="wpinv_last_name" class="wpi-label"><?php _e( 'Last Name', 'invoicing' );?><?php if ( wpinv_get_option( 'lname_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1660 | + <label for="wpinv_last_name" class="wpi-label"><?php _e('Last Name', 'invoicing'); ?><?php if (wpinv_get_option('lname_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1661 | 1661 | <?php |
| 1662 | - echo wpinv_html_text( array( |
|
| 1662 | + echo wpinv_html_text(array( |
|
| 1663 | 1663 | 'id' => 'wpinv_last_name', |
| 1664 | 1664 | 'name' => 'wpinv_last_name', |
| 1665 | 1665 | 'value' => $billing_details['last_name'], |
| 1666 | 1666 | 'class' => 'wpi-input form-control', |
| 1667 | - 'placeholder' => __( 'Last name', 'invoicing' ), |
|
| 1668 | - 'required' => (bool)wpinv_get_option( 'lname_mandatory' ), |
|
| 1669 | - ) ); |
|
| 1667 | + 'placeholder' => __('Last name', 'invoicing'), |
|
| 1668 | + 'required' => (bool)wpinv_get_option('lname_mandatory'), |
|
| 1669 | + )); |
|
| 1670 | 1670 | ?> |
| 1671 | 1671 | </p> |
| 1672 | 1672 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
| 1673 | - <label for="wpinv_address" class="wpi-label"><?php _e( 'Address', 'invoicing' );?><?php if ( wpinv_get_option( 'address_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1673 | + <label for="wpinv_address" class="wpi-label"><?php _e('Address', 'invoicing'); ?><?php if (wpinv_get_option('address_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1674 | 1674 | <?php |
| 1675 | - echo wpinv_html_text( array( |
|
| 1675 | + echo wpinv_html_text(array( |
|
| 1676 | 1676 | 'id' => 'wpinv_address', |
| 1677 | 1677 | 'name' => 'wpinv_address', |
| 1678 | 1678 | 'value' => $billing_details['address'], |
| 1679 | 1679 | 'class' => 'wpi-input form-control required', |
| 1680 | - 'placeholder' => __( 'Address', 'invoicing' ), |
|
| 1681 | - 'required' => (bool)wpinv_get_option( 'address_mandatory' ), |
|
| 1682 | - ) ); |
|
| 1680 | + 'placeholder' => __('Address', 'invoicing'), |
|
| 1681 | + 'required' => (bool)wpinv_get_option('address_mandatory'), |
|
| 1682 | + )); |
|
| 1683 | 1683 | ?> |
| 1684 | 1684 | </p> |
| 1685 | 1685 | <p class="wpi-cart-field wpi-col2 wpi-coll"> |
| 1686 | - <label for="wpinv_city" class="wpi-label"><?php _e( 'City', 'invoicing' );?><?php if ( wpinv_get_option( 'city_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1686 | + <label for="wpinv_city" class="wpi-label"><?php _e('City', 'invoicing'); ?><?php if (wpinv_get_option('city_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1687 | 1687 | <?php |
| 1688 | - echo wpinv_html_text( array( |
|
| 1688 | + echo wpinv_html_text(array( |
|
| 1689 | 1689 | 'id' => 'wpinv_city', |
| 1690 | 1690 | 'name' => 'wpinv_city', |
| 1691 | 1691 | 'value' => $billing_details['city'], |
| 1692 | 1692 | 'class' => 'wpi-input form-control required', |
| 1693 | - 'placeholder' => __( 'City', 'invoicing' ), |
|
| 1694 | - 'required' => (bool)wpinv_get_option( 'city_mandatory' ), |
|
| 1695 | - ) ); |
|
| 1693 | + 'placeholder' => __('City', 'invoicing'), |
|
| 1694 | + 'required' => (bool)wpinv_get_option('city_mandatory'), |
|
| 1695 | + )); |
|
| 1696 | 1696 | ?> |
| 1697 | 1697 | </p> |
| 1698 | 1698 | <p id="wpinv_country_box" class="wpi-cart-field wpi-col2 wpi-colf"> |
| 1699 | - <label for="wpinv_country" class="wpi-label"><?php _e( 'Country', 'invoicing' );?><?php if ( wpinv_get_option( 'country_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1700 | - <?php echo wpinv_html_select( array( |
|
| 1699 | + <label for="wpinv_country" class="wpi-label"><?php _e('Country', 'invoicing'); ?><?php if (wpinv_get_option('country_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1700 | + <?php echo wpinv_html_select(array( |
|
| 1701 | 1701 | 'options' => wpinv_get_country_list(), |
| 1702 | 1702 | 'name' => 'wpinv_country', |
| 1703 | 1703 | 'id' => 'wpinv_country', |
@@ -1705,16 +1705,16 @@ discard block |
||
| 1705 | 1705 | 'show_option_all' => false, |
| 1706 | 1706 | 'show_option_none' => false, |
| 1707 | 1707 | 'class' => 'wpi-input form-control required', |
| 1708 | - 'placeholder' => __( 'Choose a country', 'invoicing' ), |
|
| 1709 | - 'required' => (bool)wpinv_get_option( 'country_mandatory' ), |
|
| 1710 | - ) ); ?> |
|
| 1708 | + 'placeholder' => __('Choose a country', 'invoicing'), |
|
| 1709 | + 'required' => (bool)wpinv_get_option('country_mandatory'), |
|
| 1710 | + )); ?> |
|
| 1711 | 1711 | </p> |
| 1712 | 1712 | <p id="wpinv_state_box" class="wpi-cart-field wpi-col2 wpi-coll"> |
| 1713 | - <label for="wpinv_state" class="wpi-label"><?php _e( 'State / Province', 'invoicing' );?><?php if ( wpinv_get_option( 'state_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1713 | + <label for="wpinv_state" class="wpi-label"><?php _e('State / Province', 'invoicing'); ?><?php if (wpinv_get_option('state_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1714 | 1714 | <?php |
| 1715 | - $states = wpinv_get_country_states( $selected_country ); |
|
| 1716 | - if( !empty( $states ) ) { |
|
| 1717 | - echo wpinv_html_select( array( |
|
| 1715 | + $states = wpinv_get_country_states($selected_country); |
|
| 1716 | + if (!empty($states)) { |
|
| 1717 | + echo wpinv_html_select(array( |
|
| 1718 | 1718 | 'options' => $states, |
| 1719 | 1719 | 'name' => 'wpinv_state', |
| 1720 | 1720 | 'id' => 'wpinv_state', |
@@ -1722,61 +1722,61 @@ discard block |
||
| 1722 | 1722 | 'show_option_all' => false, |
| 1723 | 1723 | 'show_option_none' => false, |
| 1724 | 1724 | 'class' => 'wpi-input form-control required', |
| 1725 | - 'placeholder' => __( 'Choose a state', 'invoicing' ), |
|
| 1726 | - 'required' => (bool)wpinv_get_option( 'state_mandatory' ), |
|
| 1727 | - ) ); |
|
| 1725 | + 'placeholder' => __('Choose a state', 'invoicing'), |
|
| 1726 | + 'required' => (bool)wpinv_get_option('state_mandatory'), |
|
| 1727 | + )); |
|
| 1728 | 1728 | } else { |
| 1729 | - echo wpinv_html_text( array( |
|
| 1729 | + echo wpinv_html_text(array( |
|
| 1730 | 1730 | 'name' => 'wpinv_state', |
| 1731 | 1731 | 'value' => $billing_details['state'], |
| 1732 | 1732 | 'id' => 'wpinv_state', |
| 1733 | 1733 | 'class' => 'wpi-input form-control required', |
| 1734 | - 'placeholder' => __( 'State / Province', 'invoicing' ), |
|
| 1735 | - 'required' => (bool)wpinv_get_option( 'state_mandatory' ), |
|
| 1736 | - ) ); |
|
| 1734 | + 'placeholder' => __('State / Province', 'invoicing'), |
|
| 1735 | + 'required' => (bool)wpinv_get_option('state_mandatory'), |
|
| 1736 | + )); |
|
| 1737 | 1737 | } |
| 1738 | 1738 | ?> |
| 1739 | 1739 | </p> |
| 1740 | 1740 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
| 1741 | - <label for="wpinv_zip" class="wpi-label"><?php _e( 'ZIP / Postcode', 'invoicing' );?><?php if ( wpinv_get_option( 'zip_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1741 | + <label for="wpinv_zip" class="wpi-label"><?php _e('ZIP / Postcode', 'invoicing'); ?><?php if (wpinv_get_option('zip_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1742 | 1742 | <?php |
| 1743 | - echo wpinv_html_text( array( |
|
| 1743 | + echo wpinv_html_text(array( |
|
| 1744 | 1744 | 'name' => 'wpinv_zip', |
| 1745 | 1745 | 'value' => $billing_details['zip'], |
| 1746 | 1746 | 'id' => 'wpinv_zip', |
| 1747 | 1747 | 'class' => 'wpi-input form-control', |
| 1748 | - 'placeholder' => __( 'ZIP / Postcode', 'invoicing' ), |
|
| 1749 | - 'required' => (bool)wpinv_get_option( 'zip_mandatory' ), |
|
| 1750 | - ) ); |
|
| 1748 | + 'placeholder' => __('ZIP / Postcode', 'invoicing'), |
|
| 1749 | + 'required' => (bool)wpinv_get_option('zip_mandatory'), |
|
| 1750 | + )); |
|
| 1751 | 1751 | ?> |
| 1752 | 1752 | </p> |
| 1753 | 1753 | <p class="wpi-cart-field wpi-col2 wpi-coll"> |
| 1754 | - <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> |
|
| 1754 | + <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> |
|
| 1755 | 1755 | <?php |
| 1756 | - echo wpinv_html_text( array( |
|
| 1756 | + echo wpinv_html_text(array( |
|
| 1757 | 1757 | 'id' => 'wpinv_phone', |
| 1758 | 1758 | 'name' => 'wpinv_phone', |
| 1759 | 1759 | 'value' => $billing_details['phone'], |
| 1760 | 1760 | 'class' => 'wpi-input form-control', |
| 1761 | - 'placeholder' => __( 'Phone', 'invoicing' ), |
|
| 1762 | - 'required' => (bool)wpinv_get_option( 'phone_mandatory' ), |
|
| 1763 | - ) ); |
|
| 1761 | + 'placeholder' => __('Phone', 'invoicing'), |
|
| 1762 | + 'required' => (bool)wpinv_get_option('phone_mandatory'), |
|
| 1763 | + )); |
|
| 1764 | 1764 | ?> |
| 1765 | 1765 | </p> |
| 1766 | - <?php do_action( 'wpinv_checkout_billing_fields_last', $billing_details ); ?> |
|
| 1766 | + <?php do_action('wpinv_checkout_billing_fields_last', $billing_details); ?> |
|
| 1767 | 1767 | <div class="clearfix"></div> |
| 1768 | 1768 | </div> |
| 1769 | 1769 | </div> |
| 1770 | - <?php do_action( 'wpinv_after_billing_fields', $billing_details ); ?> |
|
| 1770 | + <?php do_action('wpinv_after_billing_fields', $billing_details); ?> |
|
| 1771 | 1771 | </div> |
| 1772 | 1772 | <?php |
| 1773 | 1773 | } |
| 1774 | 1774 | } |
| 1775 | -add_action( 'wpinv_checkout_billing_info', 'wpinv_checkout_billing_info' ); |
|
| 1775 | +add_action('wpinv_checkout_billing_info', 'wpinv_checkout_billing_info'); |
|
| 1776 | 1776 | |
| 1777 | 1777 | function wpinv_checkout_hidden_fields() { |
| 1778 | 1778 | ?> |
| 1779 | - <?php if ( is_user_logged_in() ) { ?> |
|
| 1779 | + <?php if (is_user_logged_in()) { ?> |
|
| 1780 | 1780 | <input type="hidden" name="wpinv_user_id" value="<?php echo get_current_user_id(); ?>"/> |
| 1781 | 1781 | <?php } ?> |
| 1782 | 1782 | <input type="hidden" name="wpi_action" value="payment" /> |
@@ -1786,9 +1786,9 @@ discard block |
||
| 1786 | 1786 | function wpinv_checkout_button_purchase() { |
| 1787 | 1787 | ob_start(); |
| 1788 | 1788 | ?> |
| 1789 | - <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' ) ?>"/> |
|
| 1789 | + <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') ?>"/> |
|
| 1790 | 1790 | <?php |
| 1791 | - return apply_filters( 'wpinv_checkout_button_purchase', ob_get_clean() ); |
|
| 1791 | + return apply_filters('wpinv_checkout_button_purchase', ob_get_clean()); |
|
| 1792 | 1792 | } |
| 1793 | 1793 | |
| 1794 | 1794 | function wpinv_checkout_total() { |
@@ -1797,96 +1797,96 @@ discard block |
||
| 1797 | 1797 | <div id="wpinv_checkout_total" class="panel panel-info"> |
| 1798 | 1798 | <div class="panel-body"> |
| 1799 | 1799 | <?php |
| 1800 | - do_action( 'wpinv_purchase_form_before_checkout_total' ); |
|
| 1800 | + do_action('wpinv_purchase_form_before_checkout_total'); |
|
| 1801 | 1801 | ?> |
| 1802 | - <strong><?php _e( 'Invoice Total:', 'invoicing' ) ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total;?></span> |
|
| 1802 | + <strong><?php _e('Invoice Total:', 'invoicing') ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total; ?></span> |
|
| 1803 | 1803 | <?php |
| 1804 | - do_action( 'wpinv_purchase_form_after_checkout_total' ); |
|
| 1804 | + do_action('wpinv_purchase_form_after_checkout_total'); |
|
| 1805 | 1805 | ?> |
| 1806 | 1806 | </div> |
| 1807 | 1807 | </div> |
| 1808 | 1808 | <?php |
| 1809 | 1809 | } |
| 1810 | -add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998 ); |
|
| 1810 | +add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998); |
|
| 1811 | 1811 | |
| 1812 | 1812 | function wpinv_checkout_submit() { |
| 1813 | 1813 | ?> |
| 1814 | 1814 | <div id="wpinv_purchase_submit" class="panel panel-success"> |
| 1815 | 1815 | <div class="panel-body text-center"> |
| 1816 | 1816 | <?php |
| 1817 | - do_action( 'wpinv_purchase_form_before_submit' ); |
|
| 1817 | + do_action('wpinv_purchase_form_before_submit'); |
|
| 1818 | 1818 | wpinv_checkout_hidden_fields(); |
| 1819 | 1819 | echo wpinv_checkout_button_purchase(); |
| 1820 | - do_action( 'wpinv_purchase_form_after_submit' ); |
|
| 1820 | + do_action('wpinv_purchase_form_after_submit'); |
|
| 1821 | 1821 | ?> |
| 1822 | 1822 | </div> |
| 1823 | 1823 | </div> |
| 1824 | 1824 | <?php |
| 1825 | 1825 | } |
| 1826 | -add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999 ); |
|
| 1826 | +add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999); |
|
| 1827 | 1827 | |
| 1828 | -function wpinv_receipt_billing_address( $invoice_id = 0 ) { |
|
| 1829 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 1828 | +function wpinv_receipt_billing_address($invoice_id = 0) { |
|
| 1829 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 1830 | 1830 | |
| 1831 | - if ( empty( $invoice ) ) { |
|
| 1831 | + if (empty($invoice)) { |
|
| 1832 | 1832 | return NULL; |
| 1833 | 1833 | } |
| 1834 | 1834 | |
| 1835 | 1835 | $billing_details = $invoice->get_user_info(); |
| 1836 | 1836 | $address_row = ''; |
| 1837 | - if ( $address = $billing_details['address'] ) { |
|
| 1838 | - $address_row .= wpautop( wp_kses_post( $address ) ); |
|
| 1837 | + if ($address = $billing_details['address']) { |
|
| 1838 | + $address_row .= wpautop(wp_kses_post($address)); |
|
| 1839 | 1839 | } |
| 1840 | 1840 | |
| 1841 | 1841 | $address_fields = array(); |
| 1842 | - if ( !empty( $billing_details['city'] ) ) { |
|
| 1842 | + if (!empty($billing_details['city'])) { |
|
| 1843 | 1843 | $address_fields[] = $billing_details['city']; |
| 1844 | 1844 | } |
| 1845 | 1845 | |
| 1846 | - $billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : ''; |
|
| 1847 | - if ( !empty( $billing_details['state'] ) ) { |
|
| 1848 | - $address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country ); |
|
| 1846 | + $billing_country = !empty($billing_details['country']) ? $billing_details['country'] : ''; |
|
| 1847 | + if (!empty($billing_details['state'])) { |
|
| 1848 | + $address_fields[] = wpinv_state_name($billing_details['state'], $billing_country); |
|
| 1849 | 1849 | } |
| 1850 | 1850 | |
| 1851 | - if ( !empty( $billing_country ) ) { |
|
| 1852 | - $address_fields[] = wpinv_country_name( $billing_country ); |
|
| 1851 | + if (!empty($billing_country)) { |
|
| 1852 | + $address_fields[] = wpinv_country_name($billing_country); |
|
| 1853 | 1853 | } |
| 1854 | 1854 | |
| 1855 | - if ( !empty( $address_fields ) ) { |
|
| 1856 | - $address_fields = implode( ", ", $address_fields ); |
|
| 1855 | + if (!empty($address_fields)) { |
|
| 1856 | + $address_fields = implode(", ", $address_fields); |
|
| 1857 | 1857 | |
| 1858 | - if ( !empty( $billing_details['zip'] ) ) { |
|
| 1858 | + if (!empty($billing_details['zip'])) { |
|
| 1859 | 1859 | $address_fields .= ' ' . $billing_details['zip']; |
| 1860 | 1860 | } |
| 1861 | 1861 | |
| 1862 | - $address_row .= wpautop( wp_kses_post( $address_fields ) ); |
|
| 1862 | + $address_row .= wpautop(wp_kses_post($address_fields)); |
|
| 1863 | 1863 | } |
| 1864 | 1864 | ob_start(); |
| 1865 | 1865 | ?> |
| 1866 | 1866 | <table class="table table-bordered table-sm wpi-billing-details"> |
| 1867 | 1867 | <tbody> |
| 1868 | 1868 | <tr class="wpi-receipt-name"> |
| 1869 | - <th class="text-left"><?php _e( 'Name', 'invoicing' ); ?></th> |
|
| 1870 | - <td><?php echo esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) ;?></td> |
|
| 1869 | + <th class="text-left"><?php _e('Name', 'invoicing'); ?></th> |
|
| 1870 | + <td><?php echo esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])); ?></td> |
|
| 1871 | 1871 | </tr> |
| 1872 | 1872 | <tr class="wpi-receipt-email"> |
| 1873 | - <th class="text-left"><?php _e( 'Email', 'invoicing' ); ?></th> |
|
| 1874 | - <td><?php echo $billing_details['email'] ;?></td> |
|
| 1873 | + <th class="text-left"><?php _e('Email', 'invoicing'); ?></th> |
|
| 1874 | + <td><?php echo $billing_details['email']; ?></td> |
|
| 1875 | 1875 | </tr> |
| 1876 | - <?php if ( $billing_details['company'] ) { ?> |
|
| 1876 | + <?php if ($billing_details['company']) { ?> |
|
| 1877 | 1877 | <tr class="wpi-receipt-company"> |
| 1878 | - <th class="text-left"><?php _e( 'Company', 'invoicing' ); ?></th> |
|
| 1879 | - <td><?php echo esc_html( $billing_details['company'] ) ;?></td> |
|
| 1878 | + <th class="text-left"><?php _e('Company', 'invoicing'); ?></th> |
|
| 1879 | + <td><?php echo esc_html($billing_details['company']); ?></td> |
|
| 1880 | 1880 | </tr> |
| 1881 | 1881 | <?php } ?> |
| 1882 | 1882 | <tr class="wpi-receipt-address"> |
| 1883 | - <th class="text-left"><?php _e( 'Address', 'invoicing' ); ?></th> |
|
| 1884 | - <td><?php echo $address_row ;?></td> |
|
| 1883 | + <th class="text-left"><?php _e('Address', 'invoicing'); ?></th> |
|
| 1884 | + <td><?php echo $address_row; ?></td> |
|
| 1885 | 1885 | </tr> |
| 1886 | - <?php if ( $billing_details['phone'] ) { ?> |
|
| 1886 | + <?php if ($billing_details['phone']) { ?> |
|
| 1887 | 1887 | <tr class="wpi-receipt-phone"> |
| 1888 | - <th class="text-left"><?php _e( 'Phone', 'invoicing' ); ?></th> |
|
| 1889 | - <td><?php echo esc_html( $billing_details['phone'] ) ;?></td> |
|
| 1888 | + <th class="text-left"><?php _e('Phone', 'invoicing'); ?></th> |
|
| 1889 | + <td><?php echo esc_html($billing_details['phone']); ?></td> |
|
| 1890 | 1890 | </tr> |
| 1891 | 1891 | <?php } ?> |
| 1892 | 1892 | </tbody> |
@@ -1894,98 +1894,98 @@ discard block |
||
| 1894 | 1894 | <?php |
| 1895 | 1895 | $output = ob_get_clean(); |
| 1896 | 1896 | |
| 1897 | - $output = apply_filters( 'wpinv_receipt_billing_address', $output, $invoice_id ); |
|
| 1897 | + $output = apply_filters('wpinv_receipt_billing_address', $output, $invoice_id); |
|
| 1898 | 1898 | |
| 1899 | 1899 | echo $output; |
| 1900 | 1900 | } |
| 1901 | 1901 | |
| 1902 | -function wpinv_filter_success_page_content( $content ) { |
|
| 1903 | - if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) { |
|
| 1904 | - if ( has_filter( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ) ) ) { |
|
| 1905 | - $content = apply_filters( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ), $content ); |
|
| 1902 | +function wpinv_filter_success_page_content($content) { |
|
| 1903 | + if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) { |
|
| 1904 | + if (has_filter('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']))) { |
|
| 1905 | + $content = apply_filters('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']), $content); |
|
| 1906 | 1906 | } |
| 1907 | 1907 | } |
| 1908 | 1908 | |
| 1909 | 1909 | return $content; |
| 1910 | 1910 | } |
| 1911 | -add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 ); |
|
| 1911 | +add_filter('the_content', 'wpinv_filter_success_page_content', 99999); |
|
| 1912 | 1912 | |
| 1913 | -function wpinv_receipt_actions( $invoice ) { |
|
| 1914 | - if ( !empty( $invoice ) ) { |
|
| 1913 | +function wpinv_receipt_actions($invoice) { |
|
| 1914 | + if (!empty($invoice)) { |
|
| 1915 | 1915 | $actions = array( |
| 1916 | 1916 | 'print' => array( |
| 1917 | 1917 | 'url' => $invoice->get_view_url(), |
| 1918 | - 'name' => __( 'Print Invoice', 'invoicing' ), |
|
| 1918 | + 'name' => __('Print Invoice', 'invoicing'), |
|
| 1919 | 1919 | 'class' => 'btn-primary', |
| 1920 | 1920 | ), |
| 1921 | 1921 | 'history' => array( |
| 1922 | 1922 | 'url' => wpinv_get_history_page_uri(), |
| 1923 | - 'name' => __( 'Invoice History', 'invoicing' ), |
|
| 1923 | + 'name' => __('Invoice History', 'invoicing'), |
|
| 1924 | 1924 | 'class' => 'btn-warning', |
| 1925 | 1925 | ) |
| 1926 | 1926 | ); |
| 1927 | 1927 | |
| 1928 | - $actions = apply_filters( 'wpinv_invoice_receipt_actions', $actions, $invoice ); |
|
| 1928 | + $actions = apply_filters('wpinv_invoice_receipt_actions', $actions, $invoice); |
|
| 1929 | 1929 | |
| 1930 | - if ( !empty( $actions ) ) { |
|
| 1930 | + if (!empty($actions)) { |
|
| 1931 | 1931 | ?> |
| 1932 | 1932 | <div class="wpinv-receipt-actions text-right"> |
| 1933 | - <?php foreach ( $actions as $key => $action ) { $class = !empty($action['class']) ? sanitize_html_class( $action['class'] ) : ''; ?> |
|
| 1934 | - <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> |
|
| 1933 | + <?php foreach ($actions as $key => $action) { $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; ?> |
|
| 1934 | + <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> |
|
| 1935 | 1935 | <?php } ?> |
| 1936 | 1936 | </div> |
| 1937 | 1937 | <?php |
| 1938 | 1938 | } |
| 1939 | 1939 | } |
| 1940 | 1940 | } |
| 1941 | -add_action( 'wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1 ); |
|
| 1941 | +add_action('wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1); |
|
| 1942 | 1942 | |
| 1943 | -function wpinv_invoice_link( $invoice_id ) { |
|
| 1944 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 1943 | +function wpinv_invoice_link($invoice_id) { |
|
| 1944 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 1945 | 1945 | |
| 1946 | - if ( empty( $invoice ) ) { |
|
| 1946 | + if (empty($invoice)) { |
|
| 1947 | 1947 | return NULL; |
| 1948 | 1948 | } |
| 1949 | 1949 | |
| 1950 | - $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>'; |
|
| 1950 | + $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>'; |
|
| 1951 | 1951 | |
| 1952 | - return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice ); |
|
| 1952 | + return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice); |
|
| 1953 | 1953 | } |
| 1954 | 1954 | |
| 1955 | -function wpinv_invoice_subscription_details( $invoice ) { |
|
| 1956 | - if ( !empty( $invoice ) && $invoice->is_recurring() && !wpinv_is_subscription_payment( $invoice ) ) { |
|
| 1955 | +function wpinv_invoice_subscription_details($invoice) { |
|
| 1956 | + if (!empty($invoice) && $invoice->is_recurring() && !wpinv_is_subscription_payment($invoice)) { |
|
| 1957 | 1957 | $total_payments = (int)$invoice->get_total_payments(); |
| 1958 | 1958 | $payments = $invoice->get_child_payments(); |
| 1959 | 1959 | |
| 1960 | 1960 | $subscription = $invoice->get_subscription_data(); |
| 1961 | 1961 | |
| 1962 | - if ( !( !empty( $subscription ) && !empty( $subscription['item_id'] ) ) ) { |
|
| 1962 | + if (!(!empty($subscription) && !empty($subscription['item_id']))) { |
|
| 1963 | 1963 | return; |
| 1964 | 1964 | } |
| 1965 | 1965 | |
| 1966 | - $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() ); |
|
| 1967 | - $times_billed = $total_payments . ' / ' . ( ( (int)$subscription['bill_times'] == 0 ) ? __( 'Until cancelled', 'invoicing' ) : $subscription['bill_times'] ); |
|
| 1966 | + $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()); |
|
| 1967 | + $times_billed = $total_payments . ' / ' . (((int)$subscription['bill_times'] == 0) ? __('Until cancelled', 'invoicing') : $subscription['bill_times']); |
|
| 1968 | 1968 | |
| 1969 | 1969 | $subscription_status = $invoice->get_subscription_status(); |
| 1970 | 1970 | |
| 1971 | 1971 | $status_desc = ''; |
| 1972 | - if ( $subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date() ) { |
|
| 1973 | - $status_desc = wp_sprintf( __( 'Until: %s', 'invoicing' ), $trial_end_date ); |
|
| 1974 | - } else if ( $subscription_status == 'cancelled' && $cancelled_date = $invoice->get_cancelled_date() ) { |
|
| 1975 | - $status_desc = wp_sprintf( __( 'On: %s', 'invoicing' ), $cancelled_date ); |
|
| 1972 | + if ($subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date()) { |
|
| 1973 | + $status_desc = wp_sprintf(__('Until: %s', 'invoicing'), $trial_end_date); |
|
| 1974 | + } else if ($subscription_status == 'cancelled' && $cancelled_date = $invoice->get_cancelled_date()) { |
|
| 1975 | + $status_desc = wp_sprintf(__('On: %s', 'invoicing'), $cancelled_date); |
|
| 1976 | 1976 | } |
| 1977 | 1977 | $status_desc = $status_desc != '' ? '<span class="meta">' . $status_desc . '</span>' : ''; |
| 1978 | 1978 | ?> |
| 1979 | 1979 | <div class="wpinv-subscriptions-details"> |
| 1980 | - <h3 class="wpinv-subscriptions-t"><?php echo apply_filters( 'wpinv_subscription_details_title', __( 'Subscription Details', 'invoicing' ) ); ?></h3> |
|
| 1980 | + <h3 class="wpinv-subscriptions-t"><?php echo apply_filters('wpinv_subscription_details_title', __('Subscription Details', 'invoicing')); ?></h3> |
|
| 1981 | 1981 | <table class="table"> |
| 1982 | 1982 | <thead> |
| 1983 | 1983 | <tr> |
| 1984 | - <th><?php _e( 'Billing Cycle', 'invoicing' ) ;?></th> |
|
| 1985 | - <th><?php _e( 'Start Date', 'invoicing' ) ;?></th> |
|
| 1986 | - <th><?php _e( 'Expiration Date', 'invoicing' ) ;?></th> |
|
| 1987 | - <th class="text-center"><?php _e( 'Times Billed', 'invoicing' ) ;?></th> |
|
| 1988 | - <th class="text-center"><?php _e( 'Status', 'invoicing' ) ;?></th> |
|
| 1984 | + <th><?php _e('Billing Cycle', 'invoicing'); ?></th> |
|
| 1985 | + <th><?php _e('Start Date', 'invoicing'); ?></th> |
|
| 1986 | + <th><?php _e('Expiration Date', 'invoicing'); ?></th> |
|
| 1987 | + <th class="text-center"><?php _e('Times Billed', 'invoicing'); ?></th> |
|
| 1988 | + <th class="text-center"><?php _e('Status', 'invoicing'); ?></th> |
|
| 1989 | 1989 | </tr> |
| 1990 | 1990 | </thead> |
| 1991 | 1991 | <tbody> |
@@ -1994,32 +1994,32 @@ discard block |
||
| 1994 | 1994 | <td><?php echo $invoice->get_subscription_start(); ?></td> |
| 1995 | 1995 | <td><?php echo $invoice->get_subscription_end(); ?></td> |
| 1996 | 1996 | <td class="text-center"><?php echo $times_billed; ?></td> |
| 1997 | - <td class="text-center wpi-sub-status"><?php echo $invoice->get_subscription_status_label() ;?> |
|
| 1997 | + <td class="text-center wpi-sub-status"><?php echo $invoice->get_subscription_status_label(); ?> |
|
| 1998 | 1998 | <?php echo $status_desc; ?> |
| 1999 | 1999 | </td> |
| 2000 | 2000 | </tr> |
| 2001 | 2001 | </tbody> |
| 2002 | 2002 | </table> |
| 2003 | 2003 | </div> |
| 2004 | - <?php if ( !empty( $payments ) ) { ?> |
|
| 2004 | + <?php if (!empty($payments)) { ?> |
|
| 2005 | 2005 | <div class="wpinv-renewal-payments"> |
| 2006 | - <h3 class="wpinv-renewals-t"><?php echo apply_filters( 'wpinv_renewal_payments_title', __( 'Renewal Payments', 'invoicing' ) ); ?></h3> |
|
| 2006 | + <h3 class="wpinv-renewals-t"><?php echo apply_filters('wpinv_renewal_payments_title', __('Renewal Payments', 'invoicing')); ?></h3> |
|
| 2007 | 2007 | <table class="table"> |
| 2008 | 2008 | <thead> |
| 2009 | 2009 | <tr> |
| 2010 | 2010 | <th>#</th> |
| 2011 | - <th><?php _e( 'Invoice', 'invoicing' ) ;?></th> |
|
| 2012 | - <th><?php _e( 'Date', 'invoicing' ) ;?></th> |
|
| 2013 | - <th class="text-right"><?php _e( 'Amount', 'invoicing' ) ;?></th> |
|
| 2011 | + <th><?php _e('Invoice', 'invoicing'); ?></th> |
|
| 2012 | + <th><?php _e('Date', 'invoicing'); ?></th> |
|
| 2013 | + <th class="text-right"><?php _e('Amount', 'invoicing'); ?></th> |
|
| 2014 | 2014 | </tr> |
| 2015 | 2015 | </thead> |
| 2016 | 2016 | <tbody> |
| 2017 | - <?php foreach ( $payments as $key => $invoice_id ) { ?> |
|
| 2017 | + <?php foreach ($payments as $key => $invoice_id) { ?> |
|
| 2018 | 2018 | <tr> |
| 2019 | - <th scope="row"><?php echo ( $key + 1 );?></th> |
|
| 2020 | - <td><?php echo wpinv_invoice_link( $invoice_id ) ;?></td> |
|
| 2021 | - <td><?php echo wpinv_get_invoice_date( $invoice_id ); ?></td> |
|
| 2022 | - <td class="text-right"><?php echo wpinv_payment_total( $invoice_id, true ); ?></td> |
|
| 2019 | + <th scope="row"><?php echo ($key + 1); ?></th> |
|
| 2020 | + <td><?php echo wpinv_invoice_link($invoice_id); ?></td> |
|
| 2021 | + <td><?php echo wpinv_get_invoice_date($invoice_id); ?></td> |
|
| 2022 | + <td class="text-right"><?php echo wpinv_payment_total($invoice_id, true); ?></td> |
|
| 2023 | 2023 | </tr> |
| 2024 | 2024 | <?php } ?> |
| 2025 | 2025 | <tr><td colspan="4" style="padding:0"></td></tr> |
@@ -2031,52 +2031,52 @@ discard block |
||
| 2031 | 2031 | } |
| 2032 | 2032 | } |
| 2033 | 2033 | |
| 2034 | -function wpinv_cart_total_label( $label, $invoice ) { |
|
| 2035 | - if ( empty( $invoice ) ) { |
|
| 2034 | +function wpinv_cart_total_label($label, $invoice) { |
|
| 2035 | + if (empty($invoice)) { |
|
| 2036 | 2036 | return $label; |
| 2037 | 2037 | } |
| 2038 | 2038 | |
| 2039 | 2039 | $prefix_label = ''; |
| 2040 | - if ( $invoice->is_parent() && $item_id = $invoice->get_recurring() ) { |
|
| 2041 | - $prefix_label = '<span class="label label-primary label-recurring">' . __( 'Recurring Payment', 'invoicing' ) . '</span> ' . wpinv_subscription_payment_desc( $invoice ); |
|
| 2042 | - } else if ( $invoice->is_renewal() ) { |
|
| 2043 | - $prefix_label = '<span class="label label-primary label-renewal">' . __( 'Renewal Payment', 'invoicing' ) . '</span> '; |
|
| 2040 | + if ($invoice->is_parent() && $item_id = $invoice->get_recurring()) { |
|
| 2041 | + $prefix_label = '<span class="label label-primary label-recurring">' . __('Recurring Payment', 'invoicing') . '</span> ' . wpinv_subscription_payment_desc($invoice); |
|
| 2042 | + } else if ($invoice->is_renewal()) { |
|
| 2043 | + $prefix_label = '<span class="label label-primary label-renewal">' . __('Renewal Payment', 'invoicing') . '</span> '; |
|
| 2044 | 2044 | } |
| 2045 | 2045 | |
| 2046 | - if ( $prefix_label != '' ) { |
|
| 2047 | - $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label; |
|
| 2046 | + if ($prefix_label != '') { |
|
| 2047 | + $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label; |
|
| 2048 | 2048 | } |
| 2049 | 2049 | |
| 2050 | 2050 | return $label; |
| 2051 | 2051 | } |
| 2052 | -add_filter( 'wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
| 2053 | -add_filter( 'wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
| 2054 | -add_filter( 'wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
| 2052 | +add_filter('wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
| 2053 | +add_filter('wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
| 2054 | +add_filter('wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
| 2055 | 2055 | |
| 2056 | -add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1 ); |
|
| 2056 | +add_action('wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1); |
|
| 2057 | 2057 | |
| 2058 | -function wpinv_invoice_print_description( $invoice ) { |
|
| 2059 | - if ( empty( $invoice ) ) { |
|
| 2058 | +function wpinv_invoice_print_description($invoice) { |
|
| 2059 | + if (empty($invoice)) { |
|
| 2060 | 2060 | return NULL; |
| 2061 | 2061 | } |
| 2062 | - if ( $description = wpinv_get_invoice_description( $invoice->ID ) ) { |
|
| 2062 | + if ($description = wpinv_get_invoice_description($invoice->ID)) { |
|
| 2063 | 2063 | ?> |
| 2064 | 2064 | <div class="row wpinv-lower"> |
| 2065 | 2065 | <div class="col-sm-12 wpinv-description"> |
| 2066 | - <?php echo wpautop( $description ); ?> |
|
| 2066 | + <?php echo wpautop($description); ?> |
|
| 2067 | 2067 | </div> |
| 2068 | 2068 | </div> |
| 2069 | 2069 | <?php |
| 2070 | 2070 | } |
| 2071 | 2071 | } |
| 2072 | -add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1 ); |
|
| 2072 | +add_action('wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1); |
|
| 2073 | 2073 | |
| 2074 | -function wpinv_invoice_print_payment_info( $invoice ) { |
|
| 2075 | - if ( empty( $invoice ) ) { |
|
| 2074 | +function wpinv_invoice_print_payment_info($invoice) { |
|
| 2075 | + if (empty($invoice)) { |
|
| 2076 | 2076 | return NULL; |
| 2077 | 2077 | } |
| 2078 | 2078 | |
| 2079 | - if ( $payments_info = wpinv_display_payments_info( $invoice->ID, false ) ) { |
|
| 2079 | + if ($payments_info = wpinv_display_payments_info($invoice->ID, false)) { |
|
| 2080 | 2080 | ?> |
| 2081 | 2081 | <div class="row wpinv-payments"> |
| 2082 | 2082 | <div class="col-sm-12"> |
@@ -2088,43 +2088,43 @@ discard block |
||
| 2088 | 2088 | } |
| 2089 | 2089 | // add_action( 'wpinv_invoice_print_after_line_items', 'wpinv_invoice_print_payment_info', 10, 1 ); |
| 2090 | 2090 | |
| 2091 | -function wpinv_get_invoice_note_line_item( $note, $echo = true ) { |
|
| 2092 | - if ( empty( $note ) ) { |
|
| 2091 | +function wpinv_get_invoice_note_line_item($note, $echo = true) { |
|
| 2092 | + if (empty($note)) { |
|
| 2093 | 2093 | return NULL; |
| 2094 | 2094 | } |
| 2095 | 2095 | |
| 2096 | - if ( is_int( $note ) ) { |
|
| 2097 | - $note = get_comment( $note ); |
|
| 2096 | + if (is_int($note)) { |
|
| 2097 | + $note = get_comment($note); |
|
| 2098 | 2098 | } |
| 2099 | 2099 | |
| 2100 | - if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) { |
|
| 2100 | + if (!(is_object($note) && is_a($note, 'WP_Comment'))) { |
|
| 2101 | 2101 | return NULL; |
| 2102 | 2102 | } |
| 2103 | 2103 | |
| 2104 | - $note_classes = array( 'note' ); |
|
| 2105 | - $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : ''; |
|
| 2106 | - $note_classes[] = $note->comment_author === __( 'System', 'invoicing' ) ? 'system-note' : ''; |
|
| 2107 | - $note_classes = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note ); |
|
| 2108 | - $note_classes = !empty( $note_classes ) ? implode( ' ', $note_classes ) : ''; |
|
| 2104 | + $note_classes = array('note'); |
|
| 2105 | + $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : ''; |
|
| 2106 | + $note_classes[] = $note->comment_author === __('System', 'invoicing') ? 'system-note' : ''; |
|
| 2107 | + $note_classes = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note); |
|
| 2108 | + $note_classes = !empty($note_classes) ? implode(' ', $note_classes) : ''; |
|
| 2109 | 2109 | |
| 2110 | 2110 | ob_start(); |
| 2111 | 2111 | ?> |
| 2112 | - <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?>"> |
|
| 2112 | + <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?>"> |
|
| 2113 | 2113 | <div class="note_content"> |
| 2114 | - <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?> |
|
| 2114 | + <?php echo wpautop(wptexturize(wp_kses_post($note->comment_content))); ?> |
|
| 2115 | 2115 | </div> |
| 2116 | 2116 | <p class="meta"> |
| 2117 | - <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> |
|
| 2118 | - <?php if($note->comment_author !== 'System') {?> |
|
| 2119 | - <a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a> |
|
| 2117 | + <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> |
|
| 2118 | + <?php if ($note->comment_author !== 'System') {?> |
|
| 2119 | + <a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a> |
|
| 2120 | 2120 | <?php } ?> |
| 2121 | 2121 | </p> |
| 2122 | 2122 | </li> |
| 2123 | 2123 | <?php |
| 2124 | 2124 | $note_content = ob_get_clean(); |
| 2125 | - $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo ); |
|
| 2125 | + $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo); |
|
| 2126 | 2126 | |
| 2127 | - if ( $echo ) { |
|
| 2127 | + if ($echo) { |
|
| 2128 | 2128 | echo $note_content; |
| 2129 | 2129 | } else { |
| 2130 | 2130 | return $note_content; |
@@ -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,14 +278,14 @@ discard block |
||
| 278 | 278 | |
| 279 | 279 | $post_item = wpinv_get_gd_package_item($invoice_info->package_id); |
| 280 | 280 | |
| 281 | - if ( $invoice_info->invoice_type == 'add_franchise' ) { |
|
| 281 | + if ($invoice_info->invoice_type == 'add_franchise') { |
|
| 282 | 282 | $custom_price = $invoice_info->amount; |
| 283 | 283 | } else { |
| 284 | 284 | $custom_price = ''; |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | - if ( !empty( $post_item ) ) { |
|
| 288 | - $cart_details = array(); |
|
| 287 | + if (!empty($post_item)) { |
|
| 288 | + $cart_details = array(); |
|
| 289 | 289 | $cart_details[] = array( |
| 290 | 290 | 'id' => $post_item->ID, |
| 291 | 291 | 'name' => $post_item->get_name(), |
@@ -299,19 +299,19 @@ discard block |
||
| 299 | 299 | ), |
| 300 | 300 | ); |
| 301 | 301 | |
| 302 | - $invoice_data['cart_details'] = $cart_details; |
|
| 302 | + $invoice_data['cart_details'] = $cart_details; |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | - $data = array( 'invoice' => $invoice_data ); |
|
| 305 | + $data = array('invoice' => $invoice_data); |
|
| 306 | 306 | |
| 307 | 307 | $wpinv_api = new WPInv_API(); |
| 308 | - $data = $wpinv_api->insert_invoice( $data ); |
|
| 308 | + $data = $wpinv_api->insert_invoice($data); |
|
| 309 | 309 | |
| 310 | - if ( is_wp_error( $data ) ) { |
|
| 311 | - wpinv_error_log( 'WPInv_Invoice: ' . $data->get_error_message() ); |
|
| 310 | + if (is_wp_error($data)) { |
|
| 311 | + wpinv_error_log('WPInv_Invoice: ' . $data->get_error_message()); |
|
| 312 | 312 | } else { |
| 313 | - if ( !empty( $data ) ) { |
|
| 314 | - update_post_meta( $data->ID, '_wpinv_gdp_id', $invoice_id ); |
|
| 313 | + if (!empty($data)) { |
|
| 314 | + update_post_meta($data->ID, '_wpinv_gdp_id', $invoice_id); |
|
| 315 | 315 | |
| 316 | 316 | $update_data = array(); |
| 317 | 317 | $update_data['tax_amount'] = $data->get_tax(); |
@@ -319,14 +319,14 @@ discard block |
||
| 319 | 319 | $update_data['invoice_id'] = $data->ID; |
| 320 | 320 | |
| 321 | 321 | global $wpdb; |
| 322 | - $wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $invoice_id ) ); |
|
| 322 | + $wpdb->update(INVOICE_TABLE, $update_data, array('id' => $invoice_id)); |
|
| 323 | 323 | |
| 324 | 324 | return $data; |
| 325 | 325 | } else { |
| 326 | - if ( $update ) { |
|
| 327 | - wpinv_error_log( 'WPInv_Invoice: ' . __( 'Fail to update invoice.', 'invoicing' ) ); |
|
| 326 | + if ($update) { |
|
| 327 | + wpinv_error_log('WPInv_Invoice: ' . __('Fail to update invoice.', 'invoicing')); |
|
| 328 | 328 | } else { |
| 329 | - wpinv_error_log( 'WPInv_Invoice: ' . __( 'Fail to create invoice.', 'invoicing' ) ); |
|
| 329 | + wpinv_error_log('WPInv_Invoice: ' . __('Fail to create invoice.', 'invoicing')); |
|
| 330 | 330 | } |
| 331 | 331 | } |
| 332 | 332 | } |
@@ -337,59 +337,59 @@ discard block |
||
| 337 | 337 | } |
| 338 | 338 | add_action('geodir_payment_invoice_created', 'wpinv_cpt_save', 11, 3); |
| 339 | 339 | |
| 340 | -function wpinv_cpt_update( $invoice_id ) { |
|
| 341 | - return wpinv_cpt_save( $invoice_id, true ); |
|
| 340 | +function wpinv_cpt_update($invoice_id) { |
|
| 341 | + return wpinv_cpt_save($invoice_id, true); |
|
| 342 | 342 | } |
| 343 | 343 | add_action('geodir_payment_invoice_updated', 'wpinv_cpt_update', 11, 1); |
| 344 | 344 | |
| 345 | -function wpinv_payment_status_changed( $invoice_id, $new_status, $old_status = 'pending', $subscription = false ) { |
|
| 346 | - $invoice_info = geodir_get_invoice( $invoice_id ); |
|
| 347 | - if ( empty( $invoice_info ) ) { |
|
| 345 | +function wpinv_payment_status_changed($invoice_id, $new_status, $old_status = 'pending', $subscription = false) { |
|
| 346 | + $invoice_info = geodir_get_invoice($invoice_id); |
|
| 347 | + if (empty($invoice_info)) { |
|
| 348 | 348 | return false; |
| 349 | 349 | } |
| 350 | 350 | |
| 351 | - $invoice = !empty( $invoice_info->invoice_id ) ? wpinv_get_invoice( $invoice_info->invoice_id ) : NULL; |
|
| 352 | - if ( !empty( $invoice ) ) { |
|
| 351 | + $invoice = !empty($invoice_info->invoice_id) ? wpinv_get_invoice($invoice_info->invoice_id) : NULL; |
|
| 352 | + if (!empty($invoice)) { |
|
| 353 | 353 | $new_status = wpinv_gdp_to_wpi_status($new_status); |
| 354 | - $invoice = wpinv_update_payment_status( $invoice->ID, $new_status ); |
|
| 354 | + $invoice = wpinv_update_payment_status($invoice->ID, $new_status); |
|
| 355 | 355 | } else { |
| 356 | - $invoice = wpinv_cpt_save( $invoice_id ); |
|
| 356 | + $invoice = wpinv_cpt_save($invoice_id); |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | return $invoice; |
| 360 | 360 | } |
| 361 | -add_action( 'geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4 ); |
|
| 361 | +add_action('geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4); |
|
| 362 | 362 | |
| 363 | -function wpinv_transaction_details_note( $invoice_id, $html ) { |
|
| 364 | - $invoice_info = geodir_get_invoice( $invoice_id ); |
|
| 365 | - if ( empty( $invoice_info ) ) { |
|
| 363 | +function wpinv_transaction_details_note($invoice_id, $html) { |
|
| 364 | + $invoice_info = geodir_get_invoice($invoice_id); |
|
| 365 | + if (empty($invoice_info)) { |
|
| 366 | 366 | return false; |
| 367 | 367 | } |
| 368 | 368 | |
| 369 | - $wpi_invoice_id = !empty( $invoice_info->invoice_id ) ? $invoice_info->invoice_id : NULL; |
|
| 369 | + $wpi_invoice_id = !empty($invoice_info->invoice_id) ? $invoice_info->invoice_id : NULL; |
|
| 370 | 370 | |
| 371 | - if ( !$wpi_invoice_id ) { |
|
| 372 | - $invoice = wpinv_cpt_save( $invoice_id, false, $old_status ); |
|
| 371 | + if (!$wpi_invoice_id) { |
|
| 372 | + $invoice = wpinv_cpt_save($invoice_id, false, $old_status); |
|
| 373 | 373 | |
| 374 | - if ( !empty( $invoice ) ) { |
|
| 374 | + if (!empty($invoice)) { |
|
| 375 | 375 | $wpi_invoice_id = $invoice->ID; |
| 376 | 376 | } |
| 377 | 377 | } |
| 378 | 378 | |
| 379 | - $invoice = wpinv_get_invoice( $wpi_invoice_id ); |
|
| 379 | + $invoice = wpinv_get_invoice($wpi_invoice_id); |
|
| 380 | 380 | |
| 381 | - if ( empty( $invoice ) ) { |
|
| 381 | + if (empty($invoice)) { |
|
| 382 | 382 | return false; |
| 383 | 383 | } |
| 384 | 384 | |
| 385 | - return $invoice->add_note( $html, true ); |
|
| 385 | + return $invoice->add_note($html, true); |
|
| 386 | 386 | } |
| 387 | -add_action( 'geodir_payment_invoice_transaction_details_changed', 'wpinv_transaction_details_note', 11, 2 ); |
|
| 387 | +add_action('geodir_payment_invoice_transaction_details_changed', 'wpinv_transaction_details_note', 11, 2); |
|
| 388 | 388 | |
| 389 | -function wpinv_gdp_to_wpi_status( $status ) { |
|
| 389 | +function wpinv_gdp_to_wpi_status($status) { |
|
| 390 | 390 | $inv_status = $status ? $status : 'pending'; |
| 391 | 391 | |
| 392 | - switch ( $status ) { |
|
| 392 | + switch ($status) { |
|
| 393 | 393 | case 'confirmed': |
| 394 | 394 | $inv_status = 'publish'; |
| 395 | 395 | break; |
@@ -409,10 +409,10 @@ discard block |
||
| 409 | 409 | return $inv_status; |
| 410 | 410 | } |
| 411 | 411 | |
| 412 | -function wpinv_wpi_to_gdp_status( $status ) { |
|
| 412 | +function wpinv_wpi_to_gdp_status($status) { |
|
| 413 | 413 | $inv_status = $status ? $status : 'pending'; |
| 414 | 414 | |
| 415 | - switch ( $status ) { |
|
| 415 | + switch ($status) { |
|
| 416 | 416 | case 'publish': |
| 417 | 417 | case 'wpi-processing': |
| 418 | 418 | case 'wpi-renewal': |
@@ -435,72 +435,72 @@ discard block |
||
| 435 | 435 | return $inv_status; |
| 436 | 436 | } |
| 437 | 437 | |
| 438 | -function wpinv_wpi_to_gdp_id( $invoice_id ) { |
|
| 438 | +function wpinv_wpi_to_gdp_id($invoice_id) { |
|
| 439 | 439 | global $wpdb; |
| 440 | 440 | |
| 441 | - 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 ) ) ); |
|
| 441 | + 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))); |
|
| 442 | 442 | } |
| 443 | 443 | |
| 444 | -function wpinv_gdp_to_wpi_id( $invoice_id ) { |
|
| 445 | - $invoice = geodir_get_invoice( $invoice_id ); |
|
| 446 | - return ( empty( $invoice->invoice_id ) ? $invoice->invoice_id : false); |
|
| 444 | +function wpinv_gdp_to_wpi_id($invoice_id) { |
|
| 445 | + $invoice = geodir_get_invoice($invoice_id); |
|
| 446 | + return (empty($invoice->invoice_id) ? $invoice->invoice_id : false); |
|
| 447 | 447 | } |
| 448 | 448 | |
| 449 | -function wpinv_to_gdp_recalculate_total( $invoice, $wpi_nosave ) { |
|
| 449 | +function wpinv_to_gdp_recalculate_total($invoice, $wpi_nosave) { |
|
| 450 | 450 | global $wpdb; |
| 451 | 451 | |
| 452 | - if ( !empty( $wpi_nosave ) ) { |
|
| 452 | + if (!empty($wpi_nosave)) { |
|
| 453 | 453 | return; |
| 454 | 454 | } |
| 455 | 455 | |
| 456 | - $gdp_invoice_id = wpinv_wpi_to_gdp_id( $invoice->ID ); |
|
| 456 | + $gdp_invoice_id = wpinv_wpi_to_gdp_id($invoice->ID); |
|
| 457 | 457 | |
| 458 | - if ( $gdp_invoice_id > 0 ) { |
|
| 458 | + if ($gdp_invoice_id > 0) { |
|
| 459 | 459 | $update_data = array(); |
| 460 | 460 | $update_data['tax_amount'] = $invoice->tax; |
| 461 | 461 | $update_data['paied_amount'] = $invoice->total; |
| 462 | 462 | $update_data['discount'] = $invoice->discount; |
| 463 | 463 | $update_data['coupon_code'] = $invoice->discount_code; |
| 464 | 464 | |
| 465 | - $wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $gdp_invoice_id ) ); |
|
| 465 | + $wpdb->update(INVOICE_TABLE, $update_data, array('id' => $gdp_invoice_id)); |
|
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | return; |
| 469 | 469 | } |
| 470 | 470 | //add_action( 'wpinv_invoice_recalculate_total', 'wpinv_to_gdp_recalculate_total', 10, 2 ); |
| 471 | 471 | |
| 472 | -function wpinv_gdp_to_wpi_invoice( $invoice_id ) { |
|
| 473 | - $invoice = geodir_get_invoice( $invoice_id ); |
|
| 474 | - if ( empty( $invoice->invoice_id ) ) { |
|
| 472 | +function wpinv_gdp_to_wpi_invoice($invoice_id) { |
|
| 473 | + $invoice = geodir_get_invoice($invoice_id); |
|
| 474 | + if (empty($invoice->invoice_id)) { |
|
| 475 | 475 | return false; |
| 476 | 476 | } |
| 477 | 477 | |
| 478 | - return wpinv_get_invoice( $invoice->invoice_id ); |
|
| 478 | + return wpinv_get_invoice($invoice->invoice_id); |
|
| 479 | 479 | } |
| 480 | 480 | |
| 481 | -function wpinv_payment_set_coupon_code( $status, $invoice_id, $coupon_code ) { |
|
| 482 | - $invoice = wpinv_gdp_to_wpi_invoice( $invoice_id ); |
|
| 483 | - if ( empty( $invoice ) ) { |
|
| 481 | +function wpinv_payment_set_coupon_code($status, $invoice_id, $coupon_code) { |
|
| 482 | + $invoice = wpinv_gdp_to_wpi_invoice($invoice_id); |
|
| 483 | + if (empty($invoice)) { |
|
| 484 | 484 | return $status; |
| 485 | 485 | } |
| 486 | 486 | |
| 487 | - if ( $status === 1 || $status === 0 ) { |
|
| 488 | - if ( $status === 1 ) { |
|
| 489 | - $discount = geodir_get_discount_amount( $coupon_code, $invoice->get_subtotal() ); |
|
| 487 | + if ($status === 1 || $status === 0) { |
|
| 488 | + if ($status === 1) { |
|
| 489 | + $discount = geodir_get_discount_amount($coupon_code, $invoice->get_subtotal()); |
|
| 490 | 490 | } else { |
| 491 | 491 | $discount = ''; |
| 492 | 492 | $coupon_code = ''; |
| 493 | 493 | } |
| 494 | 494 | |
| 495 | - $invoice->set( 'discount', $discount ); |
|
| 496 | - $invoice->set( 'discount_code', $coupon_code ); |
|
| 495 | + $invoice->set('discount', $discount); |
|
| 496 | + $invoice->set('discount_code', $coupon_code); |
|
| 497 | 497 | $invoice->save(); |
| 498 | 498 | $invoice->recalculate_total(); |
| 499 | 499 | } |
| 500 | 500 | |
| 501 | 501 | return $status; |
| 502 | 502 | } |
| 503 | -add_filter( 'geodir_payment_set_coupon_code', 'wpinv_payment_set_coupon_code', 10, 3 ); |
|
| 503 | +add_filter('geodir_payment_set_coupon_code', 'wpinv_payment_set_coupon_code', 10, 3); |
|
| 504 | 504 | |
| 505 | 505 | function wpinv_merge_gd_invoices() { |
| 506 | 506 | if (!defined('GEODIRPAYMENT_VERSION')) { |
@@ -508,157 +508,157 @@ discard block |
||
| 508 | 508 | } |
| 509 | 509 | ?> |
| 510 | 510 | <tr> |
| 511 | - <td><?php _e( 'Merge Price Packages', 'invoicing' ); ?></td> |
|
| 512 | - <td><p><?php _e( 'Merge GeoDirectory Payment Manager price packages to the Invoicing items.', 'invoicing' ); ?></p></td> |
|
| 513 | - <td><input type="button" data-tool="merge_packages" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td> |
|
| 511 | + <td><?php _e('Merge Price Packages', 'invoicing'); ?></td> |
|
| 512 | + <td><p><?php _e('Merge GeoDirectory Payment Manager price packages to the Invoicing items.', 'invoicing'); ?></p></td> |
|
| 513 | + <td><input type="button" data-tool="merge_packages" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td> |
|
| 514 | 514 | </tr> |
| 515 | 515 | <tr> |
| 516 | - <td><?php _e( 'Merge Invoices', 'invoicing' ); ?></td> |
|
| 517 | - <td><p><?php _e( 'Merge GeoDirectory Payment Manager invoices to the Invoicing.', 'invoicing' ); ?></p></td> |
|
| 518 | - <td><input type="button" data-tool="merge_invoices" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td> |
|
| 516 | + <td><?php _e('Merge Invoices', 'invoicing'); ?></td> |
|
| 517 | + <td><p><?php _e('Merge GeoDirectory Payment Manager invoices to the Invoicing.', 'invoicing'); ?></p></td> |
|
| 518 | + <td><input type="button" data-tool="merge_invoices" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td> |
|
| 519 | 519 | </tr> |
| 520 | 520 | <tr> |
| 521 | - <td><?php _e( 'Fix Taxes for Merged Invoices', 'invoicing' ); ?></td> |
|
| 522 | - <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> |
|
| 523 | - <td><input type="button" data-tool="merge_fix_taxes" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td> |
|
| 521 | + <td><?php _e('Fix Taxes for Merged Invoices', 'invoicing'); ?></td> |
|
| 522 | + <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> |
|
| 523 | + <td><input type="button" data-tool="merge_fix_taxes" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td> |
|
| 524 | 524 | </tr> |
| 525 | 525 | <tr> |
| 526 | - <td><?php _e( 'Merge Coupons', 'invoicing' ); ?></td> |
|
| 527 | - <td><p><?php _e( 'Merge GeoDirectory Payment Manager coupons to the Invoicing.', 'invoicing' ); ?></p></td> |
|
| 528 | - <td><input type="button" data-tool="merge_coupons" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td> |
|
| 526 | + <td><?php _e('Merge Coupons', 'invoicing'); ?></td> |
|
| 527 | + <td><p><?php _e('Merge GeoDirectory Payment Manager coupons to the Invoicing.', 'invoicing'); ?></p></td> |
|
| 528 | + <td><input type="button" data-tool="merge_coupons" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td> |
|
| 529 | 529 | </tr> |
| 530 | 530 | <?php |
| 531 | 531 | } |
| 532 | -add_action( 'wpinv_tools_row', 'wpinv_merge_gd_invoices', 10 ); |
|
| 532 | +add_action('wpinv_tools_row', 'wpinv_merge_gd_invoices', 10); |
|
| 533 | 533 | |
| 534 | 534 | function wpinv_tool_merge_packages() { |
| 535 | 535 | $packages = geodir_package_list_info(); |
| 536 | 536 | |
| 537 | 537 | $count = 0; |
| 538 | 538 | |
| 539 | - if ( !empty( $packages ) ) { |
|
| 539 | + if (!empty($packages)) { |
|
| 540 | 540 | $success = true; |
| 541 | 541 | |
| 542 | - foreach ( $packages as $key => $package ) { |
|
| 542 | + foreach ($packages as $key => $package) { |
|
| 543 | 543 | $item = wpinv_get_item_by('custom_id', $package->pid, 'package'); |
| 544 | - if ( !empty( $item ) ) { |
|
| 544 | + if (!empty($item)) { |
|
| 545 | 545 | continue; |
| 546 | 546 | } |
| 547 | 547 | |
| 548 | - $merged = wpinv_merge_gd_package_to_item( $package->pid, false, $package ); |
|
| 548 | + $merged = wpinv_merge_gd_package_to_item($package->pid, false, $package); |
|
| 549 | 549 | |
| 550 | - if ( !empty( $merged ) ) { |
|
| 551 | - wpinv_error_log( 'Package merge S : ' . $package->pid ); |
|
| 550 | + if (!empty($merged)) { |
|
| 551 | + wpinv_error_log('Package merge S : ' . $package->pid); |
|
| 552 | 552 | $count++; |
| 553 | 553 | } else { |
| 554 | - wpinv_error_log( 'Package merge F : ' . $package->pid ); |
|
| 554 | + wpinv_error_log('Package merge F : ' . $package->pid); |
|
| 555 | 555 | } |
| 556 | 556 | } |
| 557 | 557 | |
| 558 | - if ( $count > 0 ) { |
|
| 559 | - $message = sprintf( _n( 'Total <b>%d</b> price package is merged successfully.', 'Total <b>%d</b> price packages are merged successfully.', $count, 'invoicing' ), $count ); |
|
| 558 | + if ($count > 0) { |
|
| 559 | + $message = sprintf(_n('Total <b>%d</b> price package is merged successfully.', 'Total <b>%d</b> price packages are merged successfully.', $count, 'invoicing'), $count); |
|
| 560 | 560 | } else { |
| 561 | - $message = __( 'No price packages merged.', 'invoicing' ); |
|
| 561 | + $message = __('No price packages merged.', 'invoicing'); |
|
| 562 | 562 | } |
| 563 | 563 | } else { |
| 564 | 564 | $success = false; |
| 565 | - $message = __( 'No price packages found to merge!', 'invoicing' ); |
|
| 565 | + $message = __('No price packages found to merge!', 'invoicing'); |
|
| 566 | 566 | } |
| 567 | 567 | |
| 568 | 568 | $response = array(); |
| 569 | 569 | $response['success'] = $success; |
| 570 | 570 | $response['data']['message'] = $message; |
| 571 | - wp_send_json( $response ); |
|
| 571 | + wp_send_json($response); |
|
| 572 | 572 | } |
| 573 | -add_action( 'wpinv_tool_merge_packages', 'wpinv_tool_merge_packages' ); |
|
| 573 | +add_action('wpinv_tool_merge_packages', 'wpinv_tool_merge_packages'); |
|
| 574 | 574 | |
| 575 | 575 | function wpinv_tool_merge_invoices() { |
| 576 | 576 | global $wpdb, $wpi_gdp_inv_merge, $wpi_tax_rates; |
| 577 | 577 | |
| 578 | 578 | $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"; |
| 579 | 579 | |
| 580 | - $items = $wpdb->get_results( $sql ); |
|
| 580 | + $items = $wpdb->get_results($sql); |
|
| 581 | 581 | |
| 582 | 582 | $count = 0; |
| 583 | 583 | |
| 584 | - if ( !empty( $items ) ) { |
|
| 584 | + if (!empty($items)) { |
|
| 585 | 585 | $success = true; |
| 586 | 586 | $wpi_gdp_inv_merge = true; |
| 587 | 587 | |
| 588 | - foreach ( $items as $item ) { |
|
| 588 | + foreach ($items as $item) { |
|
| 589 | 589 | $wpi_tax_rates = NULL; |
| 590 | 590 | |
| 591 | - $wpdb->query( "UPDATE `" . INVOICE_TABLE . "` SET `invoice_id` = 0 WHERE id = '" . $item->id . "'" ); |
|
| 591 | + $wpdb->query("UPDATE `" . INVOICE_TABLE . "` SET `invoice_id` = 0 WHERE id = '" . $item->id . "'"); |
|
| 592 | 592 | |
| 593 | - $merged = wpinv_cpt_save( $item->id ); |
|
| 593 | + $merged = wpinv_cpt_save($item->id); |
|
| 594 | 594 | |
| 595 | - if ( !empty( $merged ) && !empty( $merged->ID ) ) { |
|
| 595 | + if (!empty($merged) && !empty($merged->ID)) { |
|
| 596 | 596 | $count++; |
| 597 | 597 | |
| 598 | - $post_date = !empty( $item->date ) && $item->date != '0000-00-00 00:00:00' ? $item->date : current_time( 'mysql' ); |
|
| 599 | - $post_date_gmt = get_gmt_from_date( $post_date ); |
|
| 600 | - $post_modified = !empty( $item->date_updated ) && $item->date_updated != '0000-00-00 00:00:00' ? $item->date_updated : $post_date; |
|
| 601 | - $post_modified_gmt = get_gmt_from_date( $post_modified ); |
|
| 598 | + $post_date = !empty($item->date) && $item->date != '0000-00-00 00:00:00' ? $item->date : current_time('mysql'); |
|
| 599 | + $post_date_gmt = get_gmt_from_date($post_date); |
|
| 600 | + $post_modified = !empty($item->date_updated) && $item->date_updated != '0000-00-00 00:00:00' ? $item->date_updated : $post_date; |
|
| 601 | + $post_modified_gmt = get_gmt_from_date($post_modified); |
|
| 602 | 602 | |
| 603 | - $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 ) ); |
|
| 603 | + $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)); |
|
| 604 | 604 | |
| 605 | - if ( $merged->is_paid() ) { |
|
| 606 | - update_post_meta( $merged->ID, '_wpinv_completed_date', $post_modified ); |
|
| 605 | + if ($merged->is_paid()) { |
|
| 606 | + update_post_meta($merged->ID, '_wpinv_completed_date', $post_modified); |
|
| 607 | 607 | } |
| 608 | 608 | |
| 609 | - clean_post_cache( $merged->ID ); |
|
| 609 | + clean_post_cache($merged->ID); |
|
| 610 | 610 | |
| 611 | - wpinv_error_log( 'Invoice merge S : ' . $item->id . ' => ' . $merged->ID ); |
|
| 611 | + wpinv_error_log('Invoice merge S : ' . $item->id . ' => ' . $merged->ID); |
|
| 612 | 612 | } else { |
| 613 | - wpinv_error_log( 'Invoice merge F : ' . $item->id ); |
|
| 613 | + wpinv_error_log('Invoice merge F : ' . $item->id); |
|
| 614 | 614 | } |
| 615 | 615 | } |
| 616 | 616 | |
| 617 | 617 | $wpi_gdp_inv_merge = false; |
| 618 | 618 | |
| 619 | - if ( $count > 0 ) { |
|
| 620 | - $message = sprintf( _n( 'Total <b>%d</b> invoice is merged successfully.', 'Total <b>%d</b> invoices are merged successfully.', $count, 'invoicing' ), $count ); |
|
| 619 | + if ($count > 0) { |
|
| 620 | + $message = sprintf(_n('Total <b>%d</b> invoice is merged successfully.', 'Total <b>%d</b> invoices are merged successfully.', $count, 'invoicing'), $count); |
|
| 621 | 621 | } else { |
| 622 | - $message = __( 'No invoices merged.', 'invoicing' ); |
|
| 622 | + $message = __('No invoices merged.', 'invoicing'); |
|
| 623 | 623 | } |
| 624 | 624 | } else { |
| 625 | 625 | $success = false; |
| 626 | - $message = __( 'No invoices found to merge!', 'invoicing' ); |
|
| 626 | + $message = __('No invoices found to merge!', 'invoicing'); |
|
| 627 | 627 | } |
| 628 | 628 | |
| 629 | 629 | $response = array(); |
| 630 | 630 | $response['success'] = $success; |
| 631 | 631 | $response['data']['message'] = $message; |
| 632 | - wp_send_json( $response ); |
|
| 632 | + wp_send_json($response); |
|
| 633 | 633 | } |
| 634 | -add_action( 'wpinv_tool_merge_invoices', 'wpinv_tool_merge_invoices' ); |
|
| 634 | +add_action('wpinv_tool_merge_invoices', 'wpinv_tool_merge_invoices'); |
|
| 635 | 635 | |
| 636 | 636 | function wpinv_tool_merge_coupons() { |
| 637 | 637 | global $wpdb; |
| 638 | 638 | |
| 639 | 639 | $sql = "SELECT * FROM `" . COUPON_TABLE . "` WHERE `coupon_code` IS NOT NULL AND `coupon_code` != '' ORDER BY `cid` ASC"; |
| 640 | - $items = $wpdb->get_results( $sql ); |
|
| 640 | + $items = $wpdb->get_results($sql); |
|
| 641 | 641 | $count = 0; |
| 642 | 642 | |
| 643 | - if ( !empty( $items ) ) { |
|
| 643 | + if (!empty($items)) { |
|
| 644 | 644 | $success = true; |
| 645 | 645 | |
| 646 | - foreach ( $items as $item ) { |
|
| 647 | - if ( wpinv_get_discount_by_code( $item->coupon_code ) ) { |
|
| 646 | + foreach ($items as $item) { |
|
| 647 | + if (wpinv_get_discount_by_code($item->coupon_code)) { |
|
| 648 | 648 | continue; |
| 649 | 649 | } |
| 650 | 650 | |
| 651 | 651 | $args = array( |
| 652 | 652 | 'post_type' => 'wpi_discount', |
| 653 | 653 | 'post_title' => $item->coupon_code, |
| 654 | - 'post_status' => !empty( $item->status ) ? 'publish' : 'pending' |
|
| 654 | + 'post_status' => !empty($item->status) ? 'publish' : 'pending' |
|
| 655 | 655 | ); |
| 656 | 656 | |
| 657 | - $merged = wp_insert_post( $args ); |
|
| 657 | + $merged = wp_insert_post($args); |
|
| 658 | 658 | |
| 659 | 659 | $item_id = $item->cid; |
| 660 | 660 | |
| 661 | - if ( $merged ) { |
|
| 661 | + if ($merged) { |
|
| 662 | 662 | $meta = array( |
| 663 | 663 | 'code' => $item->coupon_code, |
| 664 | 664 | 'type' => $item->discount_type != 'per' ? 'flat' : 'percent', |
@@ -666,65 +666,65 @@ discard block |
||
| 666 | 666 | 'max_uses' => (int)$item->usage_limit, |
| 667 | 667 | 'uses' => (int)$item->usage_count, |
| 668 | 668 | ); |
| 669 | - wpinv_store_discount( $merged, $meta, get_post( $merged ) ); |
|
| 669 | + wpinv_store_discount($merged, $meta, get_post($merged)); |
|
| 670 | 670 | |
| 671 | 671 | $count++; |
| 672 | 672 | |
| 673 | - wpinv_error_log( 'Coupon merge S : ' . $item_id . ' => ' . $merged ); |
|
| 673 | + wpinv_error_log('Coupon merge S : ' . $item_id . ' => ' . $merged); |
|
| 674 | 674 | } else { |
| 675 | - wpinv_error_log( 'Coupon merge F : ' . $item_id ); |
|
| 675 | + wpinv_error_log('Coupon merge F : ' . $item_id); |
|
| 676 | 676 | } |
| 677 | 677 | } |
| 678 | 678 | |
| 679 | - if ( $count > 0 ) { |
|
| 680 | - $message = sprintf( _n( 'Total <b>%d</b> coupon is merged successfully.', 'Total <b>%d</b> coupons are merged successfully.', $count, 'invoicing' ), $count ); |
|
| 679 | + if ($count > 0) { |
|
| 680 | + $message = sprintf(_n('Total <b>%d</b> coupon is merged successfully.', 'Total <b>%d</b> coupons are merged successfully.', $count, 'invoicing'), $count); |
|
| 681 | 681 | } else { |
| 682 | - $message = __( 'No coupons merged.', 'invoicing' ); |
|
| 682 | + $message = __('No coupons merged.', 'invoicing'); |
|
| 683 | 683 | } |
| 684 | 684 | } else { |
| 685 | 685 | $success = false; |
| 686 | - $message = __( 'No coupons found to merge!', 'invoicing' ); |
|
| 686 | + $message = __('No coupons found to merge!', 'invoicing'); |
|
| 687 | 687 | } |
| 688 | 688 | |
| 689 | 689 | $response = array(); |
| 690 | 690 | $response['success'] = $success; |
| 691 | 691 | $response['data']['message'] = $message; |
| 692 | - wp_send_json( $response ); |
|
| 692 | + wp_send_json($response); |
|
| 693 | 693 | } |
| 694 | -add_action( 'wpinv_tool_merge_coupons', 'wpinv_tool_merge_coupons' ); |
|
| 694 | +add_action('wpinv_tool_merge_coupons', 'wpinv_tool_merge_coupons'); |
|
| 695 | 695 | |
| 696 | -function wpinv_gdp_to_wpi_currency( $value, $option = '' ) { |
|
| 696 | +function wpinv_gdp_to_wpi_currency($value, $option = '') { |
|
| 697 | 697 | return wpinv_get_currency(); |
| 698 | 698 | } |
| 699 | -add_filter( 'pre_option_geodir_currency', 'wpinv_gdp_to_wpi_currency', 10, 2 ); |
|
| 699 | +add_filter('pre_option_geodir_currency', 'wpinv_gdp_to_wpi_currency', 10, 2); |
|
| 700 | 700 | |
| 701 | -function wpinv_gdp_to_wpi_currency_sign( $value, $option = '' ) { |
|
| 701 | +function wpinv_gdp_to_wpi_currency_sign($value, $option = '') { |
|
| 702 | 702 | return wpinv_currency_symbol(); |
| 703 | 703 | } |
| 704 | -add_filter( 'pre_option_geodir_currencysym', 'wpinv_gdp_to_wpi_currency_sign', 10, 2 ); |
|
| 704 | +add_filter('pre_option_geodir_currencysym', 'wpinv_gdp_to_wpi_currency_sign', 10, 2); |
|
| 705 | 705 | |
| 706 | -function wpinv_gdp_to_wpi_display_price( $price, $amount, $display = true , $decimal_sep, $thousand_sep ) { |
|
| 707 | - if ( !$display ) { |
|
| 708 | - $price = wpinv_round_amount( $amount ); |
|
| 706 | +function wpinv_gdp_to_wpi_display_price($price, $amount, $display = true, $decimal_sep, $thousand_sep) { |
|
| 707 | + if (!$display) { |
|
| 708 | + $price = wpinv_round_amount($amount); |
|
| 709 | 709 | } else { |
| 710 | - $price = wpinv_price( wpinv_format_amount( $amount ) ); |
|
| 710 | + $price = wpinv_price(wpinv_format_amount($amount)); |
|
| 711 | 711 | } |
| 712 | 712 | |
| 713 | 713 | return $price; |
| 714 | 714 | } |
| 715 | -add_filter( 'geodir_payment_price' , 'wpinv_gdp_to_wpi_display_price', 10000, 5 ); |
|
| 715 | +add_filter('geodir_payment_price', 'wpinv_gdp_to_wpi_display_price', 10000, 5); |
|
| 716 | 716 | |
| 717 | -function wpinv_gdp_to_inv_checkout_redirect( $redirect_url ) { |
|
| 717 | +function wpinv_gdp_to_inv_checkout_redirect($redirect_url) { |
|
| 718 | 718 | $invoice_id = geodir_payment_cart_id(); |
| 719 | - $invoice_info = geodir_get_invoice( $invoice_id ); |
|
| 720 | - $wpi_invoice = !empty( $invoice_info->invoice_id ) ? wpinv_get_invoice( $invoice_info->invoice_id ) : NULL; |
|
| 719 | + $invoice_info = geodir_get_invoice($invoice_id); |
|
| 720 | + $wpi_invoice = !empty($invoice_info->invoice_id) ? wpinv_get_invoice($invoice_info->invoice_id) : NULL; |
|
| 721 | 721 | |
| 722 | - if ( !( !empty( $wpi_invoice ) && !empty( $wpi_invoice->ID ) ) ) { |
|
| 723 | - $wpi_invoice_id = wpinv_cpt_save( $invoice_id ); |
|
| 724 | - $wpi_invoice = wpinv_get_invoice( $wpi_invoice_id ); |
|
| 722 | + if (!(!empty($wpi_invoice) && !empty($wpi_invoice->ID))) { |
|
| 723 | + $wpi_invoice_id = wpinv_cpt_save($invoice_id); |
|
| 724 | + $wpi_invoice = wpinv_get_invoice($wpi_invoice_id); |
|
| 725 | 725 | } |
| 726 | 726 | |
| 727 | - if ( !empty( $wpi_invoice ) && !empty( $wpi_invoice->ID ) ) { |
|
| 727 | + if (!empty($wpi_invoice) && !empty($wpi_invoice->ID)) { |
|
| 728 | 728 | |
| 729 | 729 | // Clear cart |
| 730 | 730 | geodir_payment_clear_cart(); |
@@ -734,121 +734,121 @@ discard block |
||
| 734 | 734 | |
| 735 | 735 | return $redirect_url; |
| 736 | 736 | } |
| 737 | -add_filter( 'geodir_payment_checkout_redirect_url', 'wpinv_gdp_to_inv_checkout_redirect', 100, 1 ); |
|
| 737 | +add_filter('geodir_payment_checkout_redirect_url', 'wpinv_gdp_to_inv_checkout_redirect', 100, 1); |
|
| 738 | 738 | |
| 739 | -function wpinv_gdp_dashboard_invoice_history_link( $dashboard_links ) { |
|
| 740 | - if ( get_current_user_id() ) { |
|
| 741 | - $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>'; |
|
| 739 | +function wpinv_gdp_dashboard_invoice_history_link($dashboard_links) { |
|
| 740 | + if (get_current_user_id()) { |
|
| 741 | + $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>'; |
|
| 742 | 742 | } |
| 743 | 743 | |
| 744 | 744 | return $dashboard_links; |
| 745 | 745 | } |
| 746 | -add_action( 'geodir_dashboard_links', 'wpinv_gdp_dashboard_invoice_history_link' ); |
|
| 747 | -remove_action( 'geodir_dashboard_links', 'geodir_payment_invoices_list_page_link' ); |
|
| 746 | +add_action('geodir_dashboard_links', 'wpinv_gdp_dashboard_invoice_history_link'); |
|
| 747 | +remove_action('geodir_dashboard_links', 'geodir_payment_invoices_list_page_link'); |
|
| 748 | 748 | |
| 749 | -function wpinv_wpi_to_gdp_update_status( $invoice_id, $new_status, $old_status ) { |
|
| 749 | +function wpinv_wpi_to_gdp_update_status($invoice_id, $new_status, $old_status) { |
|
| 750 | 750 | if (!defined('GEODIRPAYMENT_VERSION')) { |
| 751 | 751 | return false; |
| 752 | 752 | } |
| 753 | 753 | |
| 754 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 755 | - if ( empty( $invoice ) ) { |
|
| 754 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 755 | + if (empty($invoice)) { |
|
| 756 | 756 | return false; |
| 757 | 757 | } |
| 758 | 758 | |
| 759 | - remove_action( 'geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4 ); |
|
| 759 | + remove_action('geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4); |
|
| 760 | 760 | |
| 761 | - $invoice_id = wpinv_wpi_to_gdp_id( $invoice_id ); |
|
| 762 | - $new_status = wpinv_wpi_to_gdp_status( $new_status ); |
|
| 761 | + $invoice_id = wpinv_wpi_to_gdp_id($invoice_id); |
|
| 762 | + $new_status = wpinv_wpi_to_gdp_status($new_status); |
|
| 763 | 763 | |
| 764 | - geodir_update_invoice_status( $invoice_id, $new_status, $invoice->is_recurring() ); |
|
| 764 | + geodir_update_invoice_status($invoice_id, $new_status, $invoice->is_recurring()); |
|
| 765 | 765 | } |
| 766 | -add_action( 'wpinv_update_status', 'wpinv_wpi_to_gdp_update_status', 999, 3 ); |
|
| 766 | +add_action('wpinv_update_status', 'wpinv_wpi_to_gdp_update_status', 999, 3); |
|
| 767 | 767 | |
| 768 | -function wpinv_gdp_to_wpi_delete_package( $gd_package_id ) { |
|
| 769 | - $item = wpinv_get_item_by( 'custom_id', $gd_package_id, 'package' ); |
|
| 768 | +function wpinv_gdp_to_wpi_delete_package($gd_package_id) { |
|
| 769 | + $item = wpinv_get_item_by('custom_id', $gd_package_id, 'package'); |
|
| 770 | 770 | |
| 771 | - if ( !empty( $item ) ) { |
|
| 772 | - wpinv_remove_item( $item, true ); |
|
| 771 | + if (!empty($item)) { |
|
| 772 | + wpinv_remove_item($item, true); |
|
| 773 | 773 | } |
| 774 | 774 | } |
| 775 | -add_action( 'geodir_payment_post_delete_package', 'wpinv_gdp_to_wpi_delete_package', 10, 1 ) ; |
|
| 775 | +add_action('geodir_payment_post_delete_package', 'wpinv_gdp_to_wpi_delete_package', 10, 1); |
|
| 776 | 776 | |
| 777 | -function wpinv_can_delete_package_item( $return, $post_id ) { |
|
| 778 | - 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 ) ) { |
|
| 779 | - $gd_package = geodir_get_package_info_by_id( $package_id, '' ); |
|
| 777 | +function wpinv_can_delete_package_item($return, $post_id) { |
|
| 778 | + 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)) { |
|
| 779 | + $gd_package = geodir_get_package_info_by_id($package_id, ''); |
|
| 780 | 780 | |
| 781 | - if ( !empty( $gd_package ) ) { |
|
| 781 | + if (!empty($gd_package)) { |
|
| 782 | 782 | $return = false; |
| 783 | 783 | } |
| 784 | 784 | } |
| 785 | 785 | |
| 786 | 786 | return $return; |
| 787 | 787 | } |
| 788 | -add_filter( 'wpinv_can_delete_item', 'wpinv_can_delete_package_item', 10, 2 ); |
|
| 788 | +add_filter('wpinv_can_delete_item', 'wpinv_can_delete_package_item', 10, 2); |
|
| 789 | 789 | |
| 790 | -function wpinv_package_item_classes( $classes, $class, $post_id ) { |
|
| 790 | +function wpinv_package_item_classes($classes, $class, $post_id) { |
|
| 791 | 791 | global $typenow; |
| 792 | 792 | |
| 793 | - if ( $typenow == 'wpi_item' && in_array( 'wpi-gd-package', $classes ) ) { |
|
| 794 | - if ( wpinv_item_in_use( $post_id ) ) { |
|
| 793 | + if ($typenow == 'wpi_item' && in_array('wpi-gd-package', $classes)) { |
|
| 794 | + if (wpinv_item_in_use($post_id)) { |
|
| 795 | 795 | $classes[] = 'wpi-inuse-pkg'; |
| 796 | - } 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 ), '' ) ) ) { |
|
| 796 | + } 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), ''))) { |
|
| 797 | 797 | $classes[] = 'wpi-delete-pkg'; |
| 798 | 798 | } |
| 799 | 799 | } |
| 800 | 800 | |
| 801 | 801 | return $classes; |
| 802 | 802 | } |
| 803 | -add_filter( 'post_class', 'wpinv_package_item_classes', 10, 3 ); |
|
| 803 | +add_filter('post_class', 'wpinv_package_item_classes', 10, 3); |
|
| 804 | 804 | |
| 805 | -function wpinv_gdp_package_type_info( $post ) { |
|
| 806 | - if ( wpinv_pm_active() ) { |
|
| 807 | - ?><p class="wpi-m0"><?php _e( 'Package: GeoDirectory price packages items.', 'invoicing' );?></p> |
|
| 805 | +function wpinv_gdp_package_type_info($post) { |
|
| 806 | + if (wpinv_pm_active()) { |
|
| 807 | + ?><p class="wpi-m0"><?php _e('Package: GeoDirectory price packages items.', 'invoicing'); ?></p> |
|
| 808 | 808 | <?php |
| 809 | 809 | } |
| 810 | 810 | } |
| 811 | -add_action( 'wpinv_item_info_metabox_after', 'wpinv_gdp_package_type_info', 10, 1 ) ; |
|
| 811 | +add_action('wpinv_item_info_metabox_after', 'wpinv_gdp_package_type_info', 10, 1); |
|
| 812 | 812 | |
| 813 | -function wpinv_gdp_to_gdi_set_zero_tax( $is_taxable, $item_id, $country , $state ) { |
|
| 813 | +function wpinv_gdp_to_gdi_set_zero_tax($is_taxable, $item_id, $country, $state) { |
|
| 814 | 814 | global $wpi_zero_tax; |
| 815 | 815 | |
| 816 | - if ( $wpi_zero_tax ) { |
|
| 816 | + if ($wpi_zero_tax) { |
|
| 817 | 817 | $is_taxable = false; |
| 818 | 818 | } |
| 819 | 819 | |
| 820 | 820 | return $is_taxable; |
| 821 | 821 | } |
| 822 | -add_action( 'wpinv_item_is_taxable', 'wpinv_gdp_to_gdi_set_zero_tax', 10, 4 ) ; |
|
| 822 | +add_action('wpinv_item_is_taxable', 'wpinv_gdp_to_gdi_set_zero_tax', 10, 4); |
|
| 823 | 823 | |
| 824 | 824 | function wpinv_tool_merge_fix_taxes() { |
| 825 | 825 | global $wpdb; |
| 826 | 826 | |
| 827 | 827 | $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'"; |
| 828 | - $items = $wpdb->get_results( $sql ); |
|
| 828 | + $items = $wpdb->get_results($sql); |
|
| 829 | 829 | |
| 830 | - if ( !empty( $items ) ) { |
|
| 831 | - foreach ( $items as $item ) { |
|
| 832 | - if ( get_post_meta( $item->ID, '_wpinv_vat_class', true ) == '_exempt' ) { |
|
| 833 | - update_post_meta( $item->ID, '_wpinv_vat_class', '_standard' ); |
|
| 830 | + if (!empty($items)) { |
|
| 831 | + foreach ($items as $item) { |
|
| 832 | + if (get_post_meta($item->ID, '_wpinv_vat_class', true) == '_exempt') { |
|
| 833 | + update_post_meta($item->ID, '_wpinv_vat_class', '_standard'); |
|
| 834 | 834 | } |
| 835 | 835 | } |
| 836 | 836 | } |
| 837 | 837 | |
| 838 | 838 | $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"; |
| 839 | - $items = $wpdb->get_results( $sql ); |
|
| 839 | + $items = $wpdb->get_results($sql); |
|
| 840 | 840 | |
| 841 | - if ( !empty( $items ) ) { |
|
| 841 | + if (!empty($items)) { |
|
| 842 | 842 | $success = false; |
| 843 | - $message = __( 'Taxes fixed for non-paid merged GD invoices.', 'invoicing' ); |
|
| 843 | + $message = __('Taxes fixed for non-paid merged GD invoices.', 'invoicing'); |
|
| 844 | 844 | |
| 845 | 845 | global $wpi_userID, $wpinv_ip_address_country, $wpi_tax_rates; |
| 846 | 846 | |
| 847 | - foreach ( $items as $item ) { |
|
| 847 | + foreach ($items as $item) { |
|
| 848 | 848 | $wpi_tax_rates = NULL; |
| 849 | 849 | $data = wpinv_get_invoice($item->ID); |
| 850 | 850 | |
| 851 | - if ( empty( $data ) ) { |
|
| 851 | + if (empty($data)) { |
|
| 852 | 852 | continue; |
| 853 | 853 | } |
| 854 | 854 | |
@@ -856,51 +856,51 @@ discard block |
||
| 856 | 856 | |
| 857 | 857 | $data_session = array(); |
| 858 | 858 | $data_session['invoice_id'] = $data->ID; |
| 859 | - $data_session['cart_discounts'] = $data->get_discounts( true ); |
|
| 859 | + $data_session['cart_discounts'] = $data->get_discounts(true); |
|
| 860 | 860 | |
| 861 | - wpinv_set_checkout_session( $data_session ); |
|
| 861 | + wpinv_set_checkout_session($data_session); |
|
| 862 | 862 | |
| 863 | 863 | $wpi_userID = (int)$data->get_user_id(); |
| 864 | 864 | $_POST['country'] = !empty($data->country) ? $data->country : wpinv_get_default_country(); |
| 865 | 865 | |
| 866 | - $data->country = sanitize_text_field( $_POST['country'] ); |
|
| 867 | - $data->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
| 866 | + $data->country = sanitize_text_field($_POST['country']); |
|
| 867 | + $data->set('country', sanitize_text_field($_POST['country'])); |
|
| 868 | 868 | |
| 869 | 869 | $wpinv_ip_address_country = $data->country; |
| 870 | 870 | |
| 871 | 871 | $data->recalculate_totals(true); |
| 872 | 872 | |
| 873 | - wpinv_set_checkout_session( $checkout_session ); |
|
| 873 | + wpinv_set_checkout_session($checkout_session); |
|
| 874 | 874 | |
| 875 | 875 | $update_data = array(); |
| 876 | 876 | $update_data['tax_amount'] = $data->get_tax(); |
| 877 | 877 | $update_data['paied_amount'] = $data->get_total(); |
| 878 | 878 | $update_data['invoice_id'] = $data->ID; |
| 879 | 879 | |
| 880 | - $wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $item->gdp_id ) ); |
|
| 880 | + $wpdb->update(INVOICE_TABLE, $update_data, array('id' => $item->gdp_id)); |
|
| 881 | 881 | } |
| 882 | 882 | } else { |
| 883 | 883 | $success = false; |
| 884 | - $message = __( 'No invoices found to fix taxes!', 'invoicing' ); |
|
| 884 | + $message = __('No invoices found to fix taxes!', 'invoicing'); |
|
| 885 | 885 | } |
| 886 | 886 | |
| 887 | 887 | $response = array(); |
| 888 | 888 | $response['success'] = $success; |
| 889 | 889 | $response['data']['message'] = $message; |
| 890 | - wp_send_json( $response ); |
|
| 890 | + wp_send_json($response); |
|
| 891 | 891 | } |
| 892 | -add_action( 'wpinv_tool_merge_fix_taxes', 'wpinv_tool_merge_fix_taxes' ); |
|
| 893 | -remove_action( 'geodir_before_detail_fields' , 'geodir_build_coupon', 2 ); |
|
| 892 | +add_action('wpinv_tool_merge_fix_taxes', 'wpinv_tool_merge_fix_taxes'); |
|
| 893 | +remove_action('geodir_before_detail_fields', 'geodir_build_coupon', 2); |
|
| 894 | 894 | |
| 895 | -function wpinv_wpi_to_gdp_handle_subscription_cancel( $invoice_id, $invoice ) { |
|
| 896 | - if ( wpinv_pm_active() && !empty( $invoice ) && $invoice->is_recurring() ) { |
|
| 897 | - if ( $invoice->is_renewal() ) { |
|
| 895 | +function wpinv_wpi_to_gdp_handle_subscription_cancel($invoice_id, $invoice) { |
|
| 896 | + if (wpinv_pm_active() && !empty($invoice) && $invoice->is_recurring()) { |
|
| 897 | + if ($invoice->is_renewal()) { |
|
| 898 | 898 | $invoice = $invoice->get_parent_payment(); |
| 899 | 899 | } |
| 900 | 900 | |
| 901 | - if ( !empty( $invoice ) ) { |
|
| 902 | - wpinv_wpi_to_gdp_update_status( $invoice->ID, 'wpi-cancelled', $invoice->get_status() ); |
|
| 901 | + if (!empty($invoice)) { |
|
| 902 | + wpinv_wpi_to_gdp_update_status($invoice->ID, 'wpi-cancelled', $invoice->get_status()); |
|
| 903 | 903 | } |
| 904 | 904 | } |
| 905 | 905 | } |
| 906 | -add_action( 'wpinv_subscription_cancelled', 'wpinv_wpi_to_gdp_handle_subscription_cancel', 10, 2 ); |
|
| 907 | 906 | \ No newline at end of file |
| 907 | +add_action('wpinv_subscription_cancelled', 'wpinv_wpi_to_gdp_handle_subscription_cancel', 10, 2); |
|
| 908 | 908 | \ No newline at end of file |
@@ -1,28 +1,28 @@ 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_user_invoices( $current_page = 1 ) { |
|
| 5 | +function wpinv_user_invoices($current_page = 1) { |
|
| 6 | 6 | global $current_page; |
| 7 | - do_action( 'wpinv_before_user_invoices_template', $current_page ); |
|
| 8 | - wpinv_get_template_part( 'wpinv-invoice-history' ); |
|
| 9 | - do_action( 'wpinv_after_user_invoices_template', $current_page ); |
|
| 7 | + do_action('wpinv_before_user_invoices_template', $current_page); |
|
| 8 | + wpinv_get_template_part('wpinv-invoice-history'); |
|
| 9 | + do_action('wpinv_after_user_invoices_template', $current_page); |
|
| 10 | 10 | } |
| 11 | 11 | |
| 12 | -function wpinv_get_users_invoices( $user = 0, $number = 20, $pagination = false, $status = 'publish' ) { |
|
| 13 | - if ( empty( $user ) ) { |
|
| 12 | +function wpinv_get_users_invoices($user = 0, $number = 20, $pagination = false, $status = 'publish') { |
|
| 13 | + if (empty($user)) { |
|
| 14 | 14 | $user = get_current_user_id(); |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | - if ( 0 === $user ) { |
|
| 17 | + if (0 === $user) { |
|
| 18 | 18 | return false; |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | - if ( $pagination ) { |
|
| 22 | - if ( get_query_var( 'paged' ) ) |
|
| 21 | + if ($pagination) { |
|
| 22 | + if (get_query_var('paged')) |
|
| 23 | 23 | $paged = get_query_var('paged'); |
| 24 | - else if ( get_query_var( 'page' ) ) |
|
| 25 | - $paged = get_query_var( 'page' ); |
|
| 24 | + else if (get_query_var('page')) |
|
| 25 | + $paged = get_query_var('page'); |
|
| 26 | 26 | else |
| 27 | 27 | $paged = 1; |
| 28 | 28 | } |
@@ -31,21 +31,21 @@ discard block |
||
| 31 | 31 | 'post_type' => 'wpi_invoice', |
| 32 | 32 | 'posts_per_page' => 20, |
| 33 | 33 | 'paged' => null, |
| 34 | - 'post_status' => array( 'publish', 'pending' ), |
|
| 34 | + 'post_status' => array('publish', 'pending'), |
|
| 35 | 35 | 'user' => $user, |
| 36 | 36 | 'order' => 'date', |
| 37 | 37 | ); |
| 38 | 38 | |
| 39 | - $invoices = get_posts( $args ); |
|
| 39 | + $invoices = get_posts($args); |
|
| 40 | 40 | |
| 41 | 41 | // No invoices |
| 42 | - if ( ! $invoices ) |
|
| 42 | + if (!$invoices) |
|
| 43 | 43 | return false; |
| 44 | 44 | |
| 45 | 45 | return $invoices; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | -function wpinv_dropdown_users( $args = '' ) { |
|
| 48 | +function wpinv_dropdown_users($args = '') { |
|
| 49 | 49 | $defaults = array( |
| 50 | 50 | 'show_option_all' => '', 'show_option_none' => '', 'hide_if_only_one_author' => '', |
| 51 | 51 | 'orderby' => 'display_name', 'order' => 'ASC', |
@@ -56,18 +56,18 @@ discard block |
||
| 56 | 56 | 'option_none_value' => -1 |
| 57 | 57 | ); |
| 58 | 58 | |
| 59 | - $defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0; |
|
| 59 | + $defaults['selected'] = is_author() ? get_query_var('author') : 0; |
|
| 60 | 60 | |
| 61 | - $r = wp_parse_args( $args, $defaults ); |
|
| 61 | + $r = wp_parse_args($args, $defaults); |
|
| 62 | 62 | |
| 63 | - $query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order', 'who' ) ); |
|
| 63 | + $query_args = wp_array_slice_assoc($r, array('blog_id', 'include', 'exclude', 'orderby', 'order', 'who')); |
|
| 64 | 64 | |
| 65 | - $fields = array( 'ID', 'user_login', 'user_email' ); |
|
| 65 | + $fields = array('ID', 'user_login', 'user_email'); |
|
| 66 | 66 | |
| 67 | - $show = ! empty( $r['show'] ) ? $r['show'] : 'display_name'; |
|
| 68 | - if ( 'display_name_with_login' === $show ) { |
|
| 67 | + $show = !empty($r['show']) ? $r['show'] : 'display_name'; |
|
| 68 | + if ('display_name_with_login' === $show) { |
|
| 69 | 69 | $fields[] = 'display_name'; |
| 70 | - } else if ( 'display_name_with_email' === $show ) { |
|
| 70 | + } else if ('display_name_with_email' === $show) { |
|
| 71 | 71 | $fields[] = 'display_name'; |
| 72 | 72 | } else { |
| 73 | 73 | $fields[] = $show; |
@@ -79,99 +79,99 @@ discard block |
||
| 79 | 79 | $show_option_none = $r['show_option_none']; |
| 80 | 80 | $option_none_value = $r['option_none_value']; |
| 81 | 81 | |
| 82 | - $query_args = apply_filters( 'wpinv_dropdown_users_args', $query_args, $r ); |
|
| 82 | + $query_args = apply_filters('wpinv_dropdown_users_args', $query_args, $r); |
|
| 83 | 83 | |
| 84 | - $users = get_users( $query_args ); |
|
| 84 | + $users = get_users($query_args); |
|
| 85 | 85 | |
| 86 | 86 | $output = ''; |
| 87 | - if ( ! empty( $users ) && ( empty( $r['hide_if_only_one_author'] ) || count( $users ) > 1 ) ) { |
|
| 88 | - $name = esc_attr( $r['name'] ); |
|
| 89 | - if ( $r['multi'] && ! $r['id'] ) { |
|
| 87 | + if (!empty($users) && (empty($r['hide_if_only_one_author']) || count($users) > 1)) { |
|
| 88 | + $name = esc_attr($r['name']); |
|
| 89 | + if ($r['multi'] && !$r['id']) { |
|
| 90 | 90 | $id = ''; |
| 91 | 91 | } else { |
| 92 | - $id = $r['id'] ? " id='" . esc_attr( $r['id'] ) . "'" : " id='$name'"; |
|
| 92 | + $id = $r['id'] ? " id='" . esc_attr($r['id']) . "'" : " id='$name'"; |
|
| 93 | 93 | } |
| 94 | 94 | $output = "<select name='{$name}'{$id} class='" . $r['class'] . "'>\n"; |
| 95 | 95 | |
| 96 | - if ( $show_option_all ) { |
|
| 96 | + if ($show_option_all) { |
|
| 97 | 97 | $output .= "\t<option value='0'>$show_option_all</option>\n"; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - if ( $show_option_none ) { |
|
| 101 | - $_selected = selected( $option_none_value, $r['selected'], false ); |
|
| 102 | - $output .= "\t<option value='" . esc_attr( $option_none_value ) . "'$_selected>$show_option_none</option>\n"; |
|
| 100 | + if ($show_option_none) { |
|
| 101 | + $_selected = selected($option_none_value, $r['selected'], false); |
|
| 102 | + $output .= "\t<option value='" . esc_attr($option_none_value) . "'$_selected>$show_option_none</option>\n"; |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - if ( $r['include_selected'] && ( $r['selected'] > 0 ) ) { |
|
| 105 | + if ($r['include_selected'] && ($r['selected'] > 0)) { |
|
| 106 | 106 | $found_selected = false; |
| 107 | - $r['selected'] = (int) $r['selected']; |
|
| 108 | - foreach ( (array) $users as $user ) { |
|
| 109 | - $user->ID = (int) $user->ID; |
|
| 110 | - if ( $user->ID === $r['selected'] ) { |
|
| 107 | + $r['selected'] = (int)$r['selected']; |
|
| 108 | + foreach ((array)$users as $user) { |
|
| 109 | + $user->ID = (int)$user->ID; |
|
| 110 | + if ($user->ID === $r['selected']) { |
|
| 111 | 111 | $found_selected = true; |
| 112 | 112 | } |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - if ( ! $found_selected ) { |
|
| 116 | - $users[] = get_userdata( $r['selected'] ); |
|
| 115 | + if (!$found_selected) { |
|
| 116 | + $users[] = get_userdata($r['selected']); |
|
| 117 | 117 | } |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - foreach ( (array) $users as $user ) { |
|
| 121 | - if ( 'display_name_with_login' === $show ) { |
|
| 120 | + foreach ((array)$users as $user) { |
|
| 121 | + if ('display_name_with_login' === $show) { |
|
| 122 | 122 | /* translators: 1: display name, 2: user_login */ |
| 123 | - $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_login ); |
|
| 124 | - } elseif ( 'display_name_with_email' === $show ) { |
|
| 123 | + $display = sprintf(_x('%1$s (%2$s)', 'user dropdown'), $user->display_name, $user->user_login); |
|
| 124 | + } elseif ('display_name_with_email' === $show) { |
|
| 125 | 125 | /* translators: 1: display name, 2: user_email */ |
| 126 | - if ( $user->display_name == $user->user_email ) { |
|
| 126 | + if ($user->display_name == $user->user_email) { |
|
| 127 | 127 | $display = $user->display_name; |
| 128 | 128 | } else { |
| 129 | - $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_email ); |
|
| 129 | + $display = sprintf(_x('%1$s (%2$s)', 'user dropdown'), $user->display_name, $user->user_email); |
|
| 130 | 130 | } |
| 131 | - } elseif ( ! empty( $user->$show ) ) { |
|
| 131 | + } elseif (!empty($user->$show)) { |
|
| 132 | 132 | $display = $user->$show; |
| 133 | 133 | } else { |
| 134 | 134 | $display = '(' . $user->user_login . ')'; |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - $_selected = selected( $user->ID, $r['selected'], false ); |
|
| 138 | - $output .= "\t<option value='$user->ID'$_selected>" . esc_html( $display ) . "</option>\n"; |
|
| 137 | + $_selected = selected($user->ID, $r['selected'], false); |
|
| 138 | + $output .= "\t<option value='$user->ID'$_selected>" . esc_html($display) . "</option>\n"; |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | $output .= "</select>"; |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - $html = apply_filters( 'wpinv_dropdown_users', $output ); |
|
| 144 | + $html = apply_filters('wpinv_dropdown_users', $output); |
|
| 145 | 145 | |
| 146 | - if ( $r['echo'] ) { |
|
| 146 | + if ($r['echo']) { |
|
| 147 | 147 | echo $html; |
| 148 | 148 | } |
| 149 | 149 | return $html; |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | -function wpinv_guest_redirect( $redirect_to, $user_id = 0 ) { |
|
| 153 | - if ( (int)wpinv_get_option( 'guest_checkout' ) && $user_id > 0 ) { |
|
| 154 | - wpinv_login_user( $user_id ); |
|
| 152 | +function wpinv_guest_redirect($redirect_to, $user_id = 0) { |
|
| 153 | + if ((int)wpinv_get_option('guest_checkout') && $user_id > 0) { |
|
| 154 | + wpinv_login_user($user_id); |
|
| 155 | 155 | } else { |
| 156 | - $redirect_to = wp_login_url( $redirect_to ); |
|
| 156 | + $redirect_to = wp_login_url($redirect_to); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - $redirect_to = apply_filters( 'wpinv_invoice_link_guest_redirect', $redirect_to, $user_id ); |
|
| 159 | + $redirect_to = apply_filters('wpinv_invoice_link_guest_redirect', $redirect_to, $user_id); |
|
| 160 | 160 | |
| 161 | - wp_redirect( $redirect_to ); |
|
| 161 | + wp_redirect($redirect_to); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | -function wpinv_login_user( $user_id ) { |
|
| 165 | - if ( is_user_logged_in() ) { |
|
| 164 | +function wpinv_login_user($user_id) { |
|
| 165 | + if (is_user_logged_in()) { |
|
| 166 | 166 | return true; |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - $user = get_user_by( 'id', $user_id ); |
|
| 169 | + $user = get_user_by('id', $user_id); |
|
| 170 | 170 | |
| 171 | - if ( !empty( $user ) && !is_wp_error( $user ) && !empty( $user->user_login ) ) { |
|
| 172 | - wp_set_current_user( $user_id, $user->user_login ); |
|
| 173 | - wp_set_auth_cookie( $user_id ); |
|
| 174 | - do_action( 'wp_login', $user->user_login ); |
|
| 171 | + if (!empty($user) && !is_wp_error($user) && !empty($user->user_login)) { |
|
| 172 | + wp_set_current_user($user_id, $user->user_login); |
|
| 173 | + wp_set_auth_cookie($user_id); |
|
| 174 | + do_action('wp_login', $user->user_login); |
|
| 175 | 175 | |
| 176 | 176 | return true; |
| 177 | 177 | } |
@@ -7,12 +7,12 @@ discard block |
||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | // MUST have WordPress. |
| 10 | -if ( !defined( 'WPINC' ) ) { |
|
| 11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
| 10 | +if (!defined('WPINC')) { |
|
| 11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | function wpinv_init_transactional_emails() { |
| 15 | - $email_actions = apply_filters( 'wpinv_email_actions', array( |
|
| 15 | + $email_actions = apply_filters('wpinv_email_actions', array( |
|
| 16 | 16 | 'wpinv_status_pending_to_processing', |
| 17 | 17 | 'wpinv_status_pending_to_publish', |
| 18 | 18 | 'wpinv_status_pending_to_cancelled', |
@@ -28,79 +28,79 @@ discard block |
||
| 28 | 28 | 'wpinv_fully_refunded', |
| 29 | 29 | 'wpinv_partially_refunded', |
| 30 | 30 | 'wpinv_new_invoice_note' |
| 31 | - ) ); |
|
| 31 | + )); |
|
| 32 | 32 | |
| 33 | - foreach ( $email_actions as $action ) { |
|
| 34 | - add_action( $action, 'wpinv_send_transactional_email', 10, 10 ); |
|
| 33 | + foreach ($email_actions as $action) { |
|
| 34 | + add_action($action, 'wpinv_send_transactional_email', 10, 10); |
|
| 35 | 35 | } |
| 36 | 36 | } |
| 37 | -add_action( 'init', 'wpinv_init_transactional_emails' ); |
|
| 37 | +add_action('init', 'wpinv_init_transactional_emails'); |
|
| 38 | 38 | |
| 39 | 39 | // New invoice email |
| 40 | -add_action( 'wpinv_status_pending_to_processing_notification', 'wpinv_new_invoice_notification' ); |
|
| 41 | -add_action( 'wpinv_status_pending_to_publish_notification', 'wpinv_new_invoice_notification' ); |
|
| 42 | -add_action( 'wpinv_status_pending_to_onhold_notification', 'wpinv_new_invoice_notification' ); |
|
| 43 | -add_action( 'wpinv_status_failed_to_processing_notification', 'wpinv_new_invoice_notification' ); |
|
| 44 | -add_action( 'wpinv_status_failed_to_publish_notification', 'wpinv_new_invoice_notification' ); |
|
| 45 | -add_action( 'wpinv_status_failed_to_onhold_notification', 'wpinv_new_invoice_notification' ); |
|
| 40 | +add_action('wpinv_status_pending_to_processing_notification', 'wpinv_new_invoice_notification'); |
|
| 41 | +add_action('wpinv_status_pending_to_publish_notification', 'wpinv_new_invoice_notification'); |
|
| 42 | +add_action('wpinv_status_pending_to_onhold_notification', 'wpinv_new_invoice_notification'); |
|
| 43 | +add_action('wpinv_status_failed_to_processing_notification', 'wpinv_new_invoice_notification'); |
|
| 44 | +add_action('wpinv_status_failed_to_publish_notification', 'wpinv_new_invoice_notification'); |
|
| 45 | +add_action('wpinv_status_failed_to_onhold_notification', 'wpinv_new_invoice_notification'); |
|
| 46 | 46 | |
| 47 | 47 | // Cancelled invoice email |
| 48 | -add_action( 'wpinv_status_pending_to_cancelled_notification', 'wpinv_cancelled_invoice_notification' ); |
|
| 49 | -add_action( 'wpinv_status_onhold_to_cancelled_notification', 'wpinv_cancelled_invoice_notification' ); |
|
| 48 | +add_action('wpinv_status_pending_to_cancelled_notification', 'wpinv_cancelled_invoice_notification'); |
|
| 49 | +add_action('wpinv_status_onhold_to_cancelled_notification', 'wpinv_cancelled_invoice_notification'); |
|
| 50 | 50 | |
| 51 | 51 | // Failed invoice email |
| 52 | -add_action( 'wpinv_status_pending_to_failed_notification', 'wpinv_failed_invoice_notification' ); |
|
| 53 | -add_action( 'wpinv_status_onhold_to_failed_notification', 'wpinv_failed_invoice_notification' ); |
|
| 52 | +add_action('wpinv_status_pending_to_failed_notification', 'wpinv_failed_invoice_notification'); |
|
| 53 | +add_action('wpinv_status_onhold_to_failed_notification', 'wpinv_failed_invoice_notification'); |
|
| 54 | 54 | |
| 55 | 55 | // On hold invoice email |
| 56 | -add_action( 'wpinv_status_pending_to_onhold_notification', 'wpinv_onhold_invoice_notification' ); |
|
| 57 | -add_action( 'wpinv_status_failed_to_onhold_notification', 'wpinv_onhold_invoice_notification' ); |
|
| 56 | +add_action('wpinv_status_pending_to_onhold_notification', 'wpinv_onhold_invoice_notification'); |
|
| 57 | +add_action('wpinv_status_failed_to_onhold_notification', 'wpinv_onhold_invoice_notification'); |
|
| 58 | 58 | |
| 59 | 59 | // Processing invoice email |
| 60 | -add_action( 'wpinv_status_pending_to_processing_notification', 'wpinv_processing_invoice_notification' ); |
|
| 60 | +add_action('wpinv_status_pending_to_processing_notification', 'wpinv_processing_invoice_notification'); |
|
| 61 | 61 | |
| 62 | 62 | // Paid invoice email |
| 63 | -add_action( 'wpinv_status_publish_notification', 'wpinv_completed_invoice_notification' ); |
|
| 63 | +add_action('wpinv_status_publish_notification', 'wpinv_completed_invoice_notification'); |
|
| 64 | 64 | |
| 65 | 65 | // Refunded invoice email |
| 66 | -add_action( 'wpinv_fully_refunded_notification', 'wpinv_fully_refunded_notification' ); |
|
| 67 | -add_action( 'wpinv_partially_refunded_notification', 'wpinv_partially_refunded_notification' ); |
|
| 66 | +add_action('wpinv_fully_refunded_notification', 'wpinv_fully_refunded_notification'); |
|
| 67 | +add_action('wpinv_partially_refunded_notification', 'wpinv_partially_refunded_notification'); |
|
| 68 | 68 | |
| 69 | 69 | // Invoice note |
| 70 | -add_action( 'wpinv_new_invoice_note_notification', 'wpinv_new_invoice_note_notification' ); |
|
| 70 | +add_action('wpinv_new_invoice_note_notification', 'wpinv_new_invoice_note_notification'); |
|
| 71 | 71 | |
| 72 | -add_action( 'wpinv_email_header', 'wpinv_email_header' ); |
|
| 73 | -add_action( 'wpinv_email_footer', 'wpinv_email_footer' ); |
|
| 74 | -add_action( 'wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3 ); |
|
| 75 | -add_action( 'wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3 ); |
|
| 76 | -add_action( 'wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3 ); |
|
| 77 | -add_action( 'wpinv_email_before_note_details', 'wpinv_email_before_note_details', 10, 4 ); |
|
| 72 | +add_action('wpinv_email_header', 'wpinv_email_header'); |
|
| 73 | +add_action('wpinv_email_footer', 'wpinv_email_footer'); |
|
| 74 | +add_action('wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3); |
|
| 75 | +add_action('wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3); |
|
| 76 | +add_action('wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3); |
|
| 77 | +add_action('wpinv_email_before_note_details', 'wpinv_email_before_note_details', 10, 4); |
|
| 78 | 78 | |
| 79 | 79 | function wpinv_send_transactional_email() { |
| 80 | 80 | $args = func_get_args(); |
| 81 | 81 | $function = current_filter() . '_notification'; |
| 82 | - do_action_ref_array( $function, $args ); |
|
| 82 | + do_action_ref_array($function, $args); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | -function wpinv_new_invoice_notification( $invoice_id, $new_status = '' ) { |
|
| 85 | +function wpinv_new_invoice_notification($invoice_id, $new_status = '') { |
|
| 86 | 86 | global $wpinv_email_search, $wpinv_email_replace; |
| 87 | 87 | |
| 88 | 88 | $email_type = 'new_invoice'; |
| 89 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
| 89 | + if (!wpinv_email_is_enabled($email_type)) { |
|
| 90 | 90 | return false; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 94 | - if ( empty( $invoice ) ) { |
|
| 93 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 94 | + if (empty($invoice)) { |
|
| 95 | 95 | return false; |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
| 98 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
| 99 | 99 | return false; |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
| 103 | - if ( !is_email( $recipient ) ) { |
|
| 102 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
| 103 | + if (!is_email($recipient)) { |
|
| 104 | 104 | return false; |
| 105 | 105 | } |
| 106 | 106 | |
@@ -117,41 +117,41 @@ discard block |
||
| 117 | 117 | $wpinv_email_search = $search; |
| 118 | 118 | $wpinv_email_replace = $replace; |
| 119 | 119 | |
| 120 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
| 121 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
| 122 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
| 123 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
| 120 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
| 121 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
| 122 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
| 123 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
| 124 | 124 | |
| 125 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
| 125 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
| 126 | 126 | 'invoice' => $invoice, |
| 127 | 127 | 'email_type' => $email_type, |
| 128 | 128 | 'email_heading' => $email_heading, |
| 129 | 129 | 'sent_to_admin' => true, |
| 130 | 130 | 'plain_text' => false, |
| 131 | - ) ); |
|
| 131 | + )); |
|
| 132 | 132 | |
| 133 | - return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
| 133 | + return wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | -function wpinv_cancelled_invoice_notification( $invoice_id, $new_status = '' ) { |
|
| 136 | +function wpinv_cancelled_invoice_notification($invoice_id, $new_status = '') { |
|
| 137 | 137 | global $wpinv_email_search, $wpinv_email_replace; |
| 138 | 138 | |
| 139 | 139 | $email_type = 'cancelled_invoice'; |
| 140 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
| 140 | + if (!wpinv_email_is_enabled($email_type)) { |
|
| 141 | 141 | return false; |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 145 | - if ( empty( $invoice ) ) { |
|
| 144 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 145 | + if (empty($invoice)) { |
|
| 146 | 146 | return false; |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
| 149 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
| 150 | 150 | return false; |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
| 154 | - if ( !is_email( $recipient ) ) { |
|
| 153 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
| 154 | + if (!is_email($recipient)) { |
|
| 155 | 155 | return false; |
| 156 | 156 | } |
| 157 | 157 | |
@@ -168,41 +168,41 @@ discard block |
||
| 168 | 168 | $wpinv_email_search = $search; |
| 169 | 169 | $wpinv_email_replace = $replace; |
| 170 | 170 | |
| 171 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
| 172 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
| 173 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
| 174 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
| 171 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
| 172 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
| 173 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
| 174 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
| 175 | 175 | |
| 176 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
| 176 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
| 177 | 177 | 'invoice' => $invoice, |
| 178 | 178 | 'email_type' => $email_type, |
| 179 | 179 | 'email_heading' => $email_heading, |
| 180 | 180 | 'sent_to_admin' => true, |
| 181 | 181 | 'plain_text' => false, |
| 182 | - ) ); |
|
| 182 | + )); |
|
| 183 | 183 | |
| 184 | - return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
| 184 | + return wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | -function wpinv_failed_invoice_notification( $invoice_id, $new_status = '' ) { |
|
| 187 | +function wpinv_failed_invoice_notification($invoice_id, $new_status = '') { |
|
| 188 | 188 | global $wpinv_email_search, $wpinv_email_replace; |
| 189 | 189 | |
| 190 | 190 | $email_type = 'failed_invoice'; |
| 191 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
| 191 | + if (!wpinv_email_is_enabled($email_type)) { |
|
| 192 | 192 | return false; |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 196 | - if ( empty( $invoice ) ) { |
|
| 195 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 196 | + if (empty($invoice)) { |
|
| 197 | 197 | return false; |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
| 200 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
| 201 | 201 | return false; |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
| 205 | - if ( !is_email( $recipient ) ) { |
|
| 204 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
| 205 | + if (!is_email($recipient)) { |
|
| 206 | 206 | return false; |
| 207 | 207 | } |
| 208 | 208 | |
@@ -219,41 +219,41 @@ discard block |
||
| 219 | 219 | $wpinv_email_search = $search; |
| 220 | 220 | $wpinv_email_replace = $replace; |
| 221 | 221 | |
| 222 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
| 223 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
| 224 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
| 225 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
| 222 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
| 223 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
| 224 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
| 225 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
| 226 | 226 | |
| 227 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
| 227 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
| 228 | 228 | 'invoice' => $invoice, |
| 229 | 229 | 'email_type' => $email_type, |
| 230 | 230 | 'email_heading' => $email_heading, |
| 231 | 231 | 'sent_to_admin' => true, |
| 232 | 232 | 'plain_text' => false, |
| 233 | - ) ); |
|
| 233 | + )); |
|
| 234 | 234 | |
| 235 | - return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
| 235 | + return wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | -function wpinv_onhold_invoice_notification( $invoice_id, $new_status = '' ) { |
|
| 238 | +function wpinv_onhold_invoice_notification($invoice_id, $new_status = '') { |
|
| 239 | 239 | global $wpinv_email_search, $wpinv_email_replace; |
| 240 | 240 | |
| 241 | 241 | $email_type = 'onhold_invoice'; |
| 242 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
| 242 | + if (!wpinv_email_is_enabled($email_type)) { |
|
| 243 | 243 | return false; |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 247 | - if ( empty( $invoice ) ) { |
|
| 246 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 247 | + if (empty($invoice)) { |
|
| 248 | 248 | return false; |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
| 251 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
| 252 | 252 | return false; |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
| 256 | - if ( !is_email( $recipient ) ) { |
|
| 255 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
| 256 | + if (!is_email($recipient)) { |
|
| 257 | 257 | return false; |
| 258 | 258 | } |
| 259 | 259 | |
@@ -270,49 +270,49 @@ discard block |
||
| 270 | 270 | $wpinv_email_search = $search; |
| 271 | 271 | $wpinv_email_replace = $replace; |
| 272 | 272 | |
| 273 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
| 274 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
| 275 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
| 276 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
| 273 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
| 274 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
| 275 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
| 276 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
| 277 | 277 | |
| 278 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
| 278 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
| 279 | 279 | 'invoice' => $invoice, |
| 280 | 280 | 'email_type' => $email_type, |
| 281 | 281 | 'email_heading' => $email_heading, |
| 282 | 282 | 'sent_to_admin' => false, |
| 283 | 283 | 'plain_text' => false, |
| 284 | - ) ); |
|
| 284 | + )); |
|
| 285 | 285 | |
| 286 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
| 286 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
| 287 | 287 | |
| 288 | - if ( wpinv_mail_admin_bcc_active( $email_type ) ) { |
|
| 289 | - $recipient = wpinv_get_admin_email(); |
|
| 290 | - $subject .= ' - ADMIN BCC COPY'; |
|
| 291 | - wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
| 288 | + if (wpinv_mail_admin_bcc_active($email_type)) { |
|
| 289 | + $recipient = wpinv_get_admin_email(); |
|
| 290 | + $subject .= ' - ADMIN BCC COPY'; |
|
| 291 | + wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | return $sent; |
| 295 | 295 | } |
| 296 | 296 | |
| 297 | -function wpinv_processing_invoice_notification( $invoice_id, $new_status = '' ) { |
|
| 297 | +function wpinv_processing_invoice_notification($invoice_id, $new_status = '') { |
|
| 298 | 298 | global $wpinv_email_search, $wpinv_email_replace; |
| 299 | 299 | |
| 300 | 300 | $email_type = 'processing_invoice'; |
| 301 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
| 301 | + if (!wpinv_email_is_enabled($email_type)) { |
|
| 302 | 302 | return false; |
| 303 | 303 | } |
| 304 | 304 | |
| 305 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 306 | - if ( empty( $invoice ) ) { |
|
| 305 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 306 | + if (empty($invoice)) { |
|
| 307 | 307 | return false; |
| 308 | 308 | } |
| 309 | 309 | |
| 310 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
| 310 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
| 311 | 311 | return false; |
| 312 | 312 | } |
| 313 | 313 | |
| 314 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
| 315 | - if ( !is_email( $recipient ) ) { |
|
| 314 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
| 315 | + if (!is_email($recipient)) { |
|
| 316 | 316 | return false; |
| 317 | 317 | } |
| 318 | 318 | |
@@ -329,49 +329,49 @@ discard block |
||
| 329 | 329 | $wpinv_email_search = $search; |
| 330 | 330 | $wpinv_email_replace = $replace; |
| 331 | 331 | |
| 332 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
| 333 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
| 334 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
| 335 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
| 332 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
| 333 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
| 334 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
| 335 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
| 336 | 336 | |
| 337 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
| 337 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
| 338 | 338 | 'invoice' => $invoice, |
| 339 | 339 | 'email_type' => $email_type, |
| 340 | 340 | 'email_heading' => $email_heading, |
| 341 | 341 | 'sent_to_admin' => false, |
| 342 | 342 | 'plain_text' => false, |
| 343 | - ) ); |
|
| 343 | + )); |
|
| 344 | 344 | |
| 345 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
| 345 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
| 346 | 346 | |
| 347 | - if ( wpinv_mail_admin_bcc_active( $email_type ) ) { |
|
| 348 | - $recipient = wpinv_get_admin_email(); |
|
| 349 | - $subject .= ' - ADMIN BCC COPY'; |
|
| 350 | - wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
| 347 | + if (wpinv_mail_admin_bcc_active($email_type)) { |
|
| 348 | + $recipient = wpinv_get_admin_email(); |
|
| 349 | + $subject .= ' - ADMIN BCC COPY'; |
|
| 350 | + wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
| 351 | 351 | } |
| 352 | 352 | |
| 353 | 353 | return $sent; |
| 354 | 354 | } |
| 355 | 355 | |
| 356 | -function wpinv_completed_invoice_notification( $invoice_id, $new_status = '' ) { |
|
| 356 | +function wpinv_completed_invoice_notification($invoice_id, $new_status = '') { |
|
| 357 | 357 | global $wpinv_email_search, $wpinv_email_replace; |
| 358 | 358 | |
| 359 | 359 | $email_type = 'completed_invoice'; |
| 360 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
| 360 | + if (!wpinv_email_is_enabled($email_type)) { |
|
| 361 | 361 | return false; |
| 362 | 362 | } |
| 363 | 363 | |
| 364 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 365 | - if ( empty( $invoice ) ) { |
|
| 364 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 365 | + if (empty($invoice)) { |
|
| 366 | 366 | return false; |
| 367 | 367 | } |
| 368 | 368 | |
| 369 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
| 369 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
| 370 | 370 | return false; |
| 371 | 371 | } |
| 372 | 372 | |
| 373 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
| 374 | - if ( !is_email( $recipient ) ) { |
|
| 373 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
| 374 | + if (!is_email($recipient)) { |
|
| 375 | 375 | return false; |
| 376 | 376 | } |
| 377 | 377 | |
@@ -388,49 +388,49 @@ discard block |
||
| 388 | 388 | $wpinv_email_search = $search; |
| 389 | 389 | $wpinv_email_replace = $replace; |
| 390 | 390 | |
| 391 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
| 392 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
| 393 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
| 394 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
| 391 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
| 392 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
| 393 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
| 394 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
| 395 | 395 | |
| 396 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
| 396 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
| 397 | 397 | 'invoice' => $invoice, |
| 398 | 398 | 'email_type' => $email_type, |
| 399 | 399 | 'email_heading' => $email_heading, |
| 400 | 400 | 'sent_to_admin' => false, |
| 401 | 401 | 'plain_text' => false, |
| 402 | - ) ); |
|
| 402 | + )); |
|
| 403 | 403 | |
| 404 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
| 404 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
| 405 | 405 | |
| 406 | - if ( wpinv_mail_admin_bcc_active( $email_type ) ) { |
|
| 407 | - $recipient = wpinv_get_admin_email(); |
|
| 408 | - $subject .= ' - ADMIN BCC COPY'; |
|
| 409 | - wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
| 406 | + if (wpinv_mail_admin_bcc_active($email_type)) { |
|
| 407 | + $recipient = wpinv_get_admin_email(); |
|
| 408 | + $subject .= ' - ADMIN BCC COPY'; |
|
| 409 | + wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | return $sent; |
| 413 | 413 | } |
| 414 | 414 | |
| 415 | -function wpinv_fully_refunded_notification( $invoice_id, $new_status = '' ) { |
|
| 415 | +function wpinv_fully_refunded_notification($invoice_id, $new_status = '') { |
|
| 416 | 416 | global $wpinv_email_search, $wpinv_email_replace; |
| 417 | 417 | |
| 418 | 418 | $email_type = 'refunded_invoice'; |
| 419 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
| 419 | + if (!wpinv_email_is_enabled($email_type)) { |
|
| 420 | 420 | return false; |
| 421 | 421 | } |
| 422 | 422 | |
| 423 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 424 | - if ( empty( $invoice ) ) { |
|
| 423 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 424 | + if (empty($invoice)) { |
|
| 425 | 425 | return false; |
| 426 | 426 | } |
| 427 | 427 | |
| 428 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
| 428 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
| 429 | 429 | return false; |
| 430 | 430 | } |
| 431 | 431 | |
| 432 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
| 433 | - if ( !is_email( $recipient ) ) { |
|
| 432 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
| 433 | + if (!is_email($recipient)) { |
|
| 434 | 434 | return false; |
| 435 | 435 | } |
| 436 | 436 | |
@@ -447,50 +447,50 @@ discard block |
||
| 447 | 447 | $wpinv_email_search = $search; |
| 448 | 448 | $wpinv_email_replace = $replace; |
| 449 | 449 | |
| 450 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
| 451 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
| 452 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
| 453 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
| 450 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
| 451 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
| 452 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
| 453 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
| 454 | 454 | |
| 455 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
| 455 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
| 456 | 456 | 'invoice' => $invoice, |
| 457 | 457 | 'email_type' => $email_type, |
| 458 | 458 | 'email_heading' => $email_heading, |
| 459 | 459 | 'sent_to_admin' => false, |
| 460 | 460 | 'plain_text' => false, |
| 461 | 461 | 'partial_refund' => false |
| 462 | - ) ); |
|
| 462 | + )); |
|
| 463 | 463 | |
| 464 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
| 464 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
| 465 | 465 | |
| 466 | - if ( wpinv_mail_admin_bcc_active( $email_type ) ) { |
|
| 467 | - $recipient = wpinv_get_admin_email(); |
|
| 468 | - $subject .= ' - ADMIN BCC COPY'; |
|
| 469 | - wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
| 466 | + if (wpinv_mail_admin_bcc_active($email_type)) { |
|
| 467 | + $recipient = wpinv_get_admin_email(); |
|
| 468 | + $subject .= ' - ADMIN BCC COPY'; |
|
| 469 | + wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
| 470 | 470 | } |
| 471 | 471 | |
| 472 | 472 | return $sent; |
| 473 | 473 | } |
| 474 | 474 | |
| 475 | -function wpinv_partially_refunded_notification( $invoice_id, $new_status = '' ) { |
|
| 475 | +function wpinv_partially_refunded_notification($invoice_id, $new_status = '') { |
|
| 476 | 476 | global $wpinv_email_search, $wpinv_email_replace; |
| 477 | 477 | |
| 478 | 478 | $email_type = 'refunded_invoice'; |
| 479 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
| 479 | + if (!wpinv_email_is_enabled($email_type)) { |
|
| 480 | 480 | return false; |
| 481 | 481 | } |
| 482 | 482 | |
| 483 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 484 | - if ( empty( $invoice ) ) { |
|
| 483 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 484 | + if (empty($invoice)) { |
|
| 485 | 485 | return false; |
| 486 | 486 | } |
| 487 | 487 | |
| 488 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
| 488 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
| 489 | 489 | return false; |
| 490 | 490 | } |
| 491 | 491 | |
| 492 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
| 493 | - if ( !is_email( $recipient ) ) { |
|
| 492 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
| 493 | + if (!is_email($recipient)) { |
|
| 494 | 494 | return false; |
| 495 | 495 | } |
| 496 | 496 | |
@@ -507,53 +507,53 @@ discard block |
||
| 507 | 507 | $wpinv_email_search = $search; |
| 508 | 508 | $wpinv_email_replace = $replace; |
| 509 | 509 | |
| 510 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
| 511 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
| 512 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
| 513 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
| 510 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
| 511 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
| 512 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
| 513 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
| 514 | 514 | |
| 515 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
| 515 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
| 516 | 516 | 'invoice' => $invoice, |
| 517 | 517 | 'email_type' => $email_type, |
| 518 | 518 | 'email_heading' => $email_heading, |
| 519 | 519 | 'sent_to_admin' => false, |
| 520 | 520 | 'plain_text' => false, |
| 521 | 521 | 'partial_refund' => true |
| 522 | - ) ); |
|
| 522 | + )); |
|
| 523 | 523 | |
| 524 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
| 524 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
| 525 | 525 | |
| 526 | - if ( wpinv_mail_admin_bcc_active( $email_type ) ) { |
|
| 527 | - $recipient = wpinv_get_admin_email(); |
|
| 528 | - $subject .= ' - ADMIN BCC COPY'; |
|
| 529 | - wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
| 526 | + if (wpinv_mail_admin_bcc_active($email_type)) { |
|
| 527 | + $recipient = wpinv_get_admin_email(); |
|
| 528 | + $subject .= ' - ADMIN BCC COPY'; |
|
| 529 | + wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
| 530 | 530 | } |
| 531 | 531 | |
| 532 | 532 | return $sent; |
| 533 | 533 | } |
| 534 | 534 | |
| 535 | -function wpinv_new_invoice_note_notification( $invoice_id, $new_status = '' ) { |
|
| 535 | +function wpinv_new_invoice_note_notification($invoice_id, $new_status = '') { |
|
| 536 | 536 | } |
| 537 | 537 | |
| 538 | -function wpinv_user_invoice_notification( $invoice_id ) { |
|
| 538 | +function wpinv_user_invoice_notification($invoice_id) { |
|
| 539 | 539 | global $wpinv_email_search, $wpinv_email_replace; |
| 540 | 540 | |
| 541 | 541 | $email_type = 'user_invoice'; |
| 542 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
| 542 | + if (!wpinv_email_is_enabled($email_type)) { |
|
| 543 | 543 | return false; |
| 544 | 544 | } |
| 545 | 545 | |
| 546 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 547 | - if ( empty( $invoice ) ) { |
|
| 546 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 547 | + if (empty($invoice)) { |
|
| 548 | 548 | return false; |
| 549 | 549 | } |
| 550 | 550 | |
| 551 | - if ( !("wpi_invoice" === $invoice->post_type) ) { |
|
| 551 | + if (!("wpi_invoice" === $invoice->post_type)) { |
|
| 552 | 552 | return false; |
| 553 | 553 | } |
| 554 | 554 | |
| 555 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
| 556 | - if ( !is_email( $recipient ) ) { |
|
| 555 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
| 556 | + if (!is_email($recipient)) { |
|
| 557 | 557 | return false; |
| 558 | 558 | } |
| 559 | 559 | |
@@ -570,53 +570,53 @@ discard block |
||
| 570 | 570 | $wpinv_email_search = $search; |
| 571 | 571 | $wpinv_email_replace = $replace; |
| 572 | 572 | |
| 573 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
| 574 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
| 575 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
| 576 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
| 573 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
| 574 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
| 575 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
| 576 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
| 577 | 577 | |
| 578 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
| 578 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
| 579 | 579 | 'invoice' => $invoice, |
| 580 | 580 | 'email_type' => $email_type, |
| 581 | 581 | 'email_heading' => $email_heading, |
| 582 | 582 | 'sent_to_admin' => false, |
| 583 | 583 | 'plain_text' => false, |
| 584 | - ) ); |
|
| 584 | + )); |
|
| 585 | 585 | |
| 586 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
| 586 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
| 587 | 587 | |
| 588 | - if ( $sent ) { |
|
| 589 | - $note = __( 'Invoice has been emailed to the user.', 'invoicing' ); |
|
| 588 | + if ($sent) { |
|
| 589 | + $note = __('Invoice has been emailed to the user.', 'invoicing'); |
|
| 590 | 590 | } else { |
| 591 | - $note = __( 'Fail to send invoice to the user!', 'invoicing' ); |
|
| 591 | + $note = __('Fail to send invoice to the user!', 'invoicing'); |
|
| 592 | 592 | } |
| 593 | 593 | |
| 594 | - $invoice->add_note( $note, '', '', true ); // Add system note. |
|
| 594 | + $invoice->add_note($note, '', '', true); // Add system note. |
|
| 595 | 595 | |
| 596 | - if ( wpinv_mail_admin_bcc_active( $email_type ) ) { |
|
| 597 | - $recipient = wpinv_get_admin_email(); |
|
| 598 | - $subject .= ' - ADMIN BCC COPY'; |
|
| 599 | - wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
| 596 | + if (wpinv_mail_admin_bcc_active($email_type)) { |
|
| 597 | + $recipient = wpinv_get_admin_email(); |
|
| 598 | + $subject .= ' - ADMIN BCC COPY'; |
|
| 599 | + wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
| 600 | 600 | } |
| 601 | 601 | |
| 602 | 602 | return $sent; |
| 603 | 603 | } |
| 604 | 604 | |
| 605 | -function wpinv_user_note_notification( $invoice_id, $args = array() ) { |
|
| 605 | +function wpinv_user_note_notification($invoice_id, $args = array()) { |
|
| 606 | 606 | global $wpinv_email_search, $wpinv_email_replace; |
| 607 | 607 | |
| 608 | 608 | $email_type = 'user_note'; |
| 609 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
| 609 | + if (!wpinv_email_is_enabled($email_type)) { |
|
| 610 | 610 | return false; |
| 611 | 611 | } |
| 612 | 612 | |
| 613 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 614 | - if ( empty( $invoice ) ) { |
|
| 613 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 614 | + if (empty($invoice)) { |
|
| 615 | 615 | return false; |
| 616 | 616 | } |
| 617 | 617 | |
| 618 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
| 619 | - if ( !is_email( $recipient ) ) { |
|
| 618 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
| 619 | + if (!is_email($recipient)) { |
|
| 620 | 620 | return false; |
| 621 | 621 | } |
| 622 | 622 | |
@@ -624,7 +624,7 @@ discard block |
||
| 624 | 624 | 'user_note' => '' |
| 625 | 625 | ); |
| 626 | 626 | |
| 627 | - $args = wp_parse_args( $args, $defaults ); |
|
| 627 | + $args = wp_parse_args($args, $defaults); |
|
| 628 | 628 | |
| 629 | 629 | $search = array(); |
| 630 | 630 | $search['invoice_number'] = '{invoice_number}'; |
@@ -643,46 +643,46 @@ discard block |
||
| 643 | 643 | $wpinv_email_search = $search; |
| 644 | 644 | $wpinv_email_replace = $replace; |
| 645 | 645 | |
| 646 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
| 647 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
| 648 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
| 649 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
| 646 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
| 647 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
| 648 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
| 649 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
| 650 | 650 | |
| 651 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
| 651 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
| 652 | 652 | 'invoice' => $invoice, |
| 653 | 653 | 'email_type' => $email_type, |
| 654 | 654 | 'email_heading' => $email_heading, |
| 655 | 655 | 'sent_to_admin' => false, |
| 656 | 656 | 'plain_text' => false, |
| 657 | 657 | 'customer_note' => $args['user_note'] |
| 658 | - ) ); |
|
| 658 | + )); |
|
| 659 | 659 | |
| 660 | - $content = wpinv_email_format_text( $content ); |
|
| 660 | + $content = wpinv_email_format_text($content); |
|
| 661 | 661 | |
| 662 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
| 662 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
| 663 | 663 | |
| 664 | 664 | return $sent; |
| 665 | 665 | } |
| 666 | 666 | |
| 667 | 667 | function wpinv_mail_get_from_address() { |
| 668 | - $from_address = apply_filters( 'wpinv_mail_from_address', wpinv_get_option( 'email_from' ) ); |
|
| 669 | - return sanitize_email( $from_address ); |
|
| 668 | + $from_address = apply_filters('wpinv_mail_from_address', wpinv_get_option('email_from')); |
|
| 669 | + return sanitize_email($from_address); |
|
| 670 | 670 | } |
| 671 | 671 | |
| 672 | 672 | function wpinv_mail_get_from_name() { |
| 673 | - $from_name = apply_filters( 'wpinv_mail_from_name', wpinv_get_option( 'email_from_name' ) ); |
|
| 674 | - return wp_specialchars_decode( esc_html( $from_name ), ENT_QUOTES ); |
|
| 673 | + $from_name = apply_filters('wpinv_mail_from_name', wpinv_get_option('email_from_name')); |
|
| 674 | + return wp_specialchars_decode(esc_html($from_name), ENT_QUOTES); |
|
| 675 | 675 | } |
| 676 | 676 | |
| 677 | -function wpinv_mail_admin_bcc_active( $mail_type = '' ) { |
|
| 678 | - $active = apply_filters( 'wpinv_mail_admin_bcc_active', wpinv_get_option( 'email_' . $mail_type . '_admin_bcc' ) ); |
|
| 679 | - return ( $active ? true : false ); |
|
| 677 | +function wpinv_mail_admin_bcc_active($mail_type = '') { |
|
| 678 | + $active = apply_filters('wpinv_mail_admin_bcc_active', wpinv_get_option('email_' . $mail_type . '_admin_bcc')); |
|
| 679 | + return ($active ? true : false); |
|
| 680 | 680 | } |
| 681 | 681 | |
| 682 | -function wpinv_mail_get_content_type( $content_type = 'text/html', $email_type = 'html' ) { |
|
| 683 | - $email_type = apply_filters( 'wpinv_mail_content_type', $email_type ); |
|
| 682 | +function wpinv_mail_get_content_type($content_type = 'text/html', $email_type = 'html') { |
|
| 683 | + $email_type = apply_filters('wpinv_mail_content_type', $email_type); |
|
| 684 | 684 | |
| 685 | - switch ( $email_type ) { |
|
| 685 | + switch ($email_type) { |
|
| 686 | 686 | case 'html' : |
| 687 | 687 | $content_type = 'text/html'; |
| 688 | 688 | break; |
@@ -697,35 +697,35 @@ discard block |
||
| 697 | 697 | return $content_type; |
| 698 | 698 | } |
| 699 | 699 | |
| 700 | -function wpinv_mail_send( $to, $subject, $message, $headers, $attachments ) { |
|
| 701 | - add_filter( 'wp_mail_from', 'wpinv_mail_get_from_address' ); |
|
| 702 | - add_filter( 'wp_mail_from_name', 'wpinv_mail_get_from_name' ); |
|
| 703 | - add_filter( 'wp_mail_content_type', 'wpinv_mail_get_content_type' ); |
|
| 700 | +function wpinv_mail_send($to, $subject, $message, $headers, $attachments) { |
|
| 701 | + add_filter('wp_mail_from', 'wpinv_mail_get_from_address'); |
|
| 702 | + add_filter('wp_mail_from_name', 'wpinv_mail_get_from_name'); |
|
| 703 | + add_filter('wp_mail_content_type', 'wpinv_mail_get_content_type'); |
|
| 704 | 704 | |
| 705 | - $message = wpinv_email_style_body( $message ); |
|
| 706 | - $message = apply_filters( 'wpinv_mail_content', $message ); |
|
| 705 | + $message = wpinv_email_style_body($message); |
|
| 706 | + $message = apply_filters('wpinv_mail_content', $message); |
|
| 707 | 707 | |
| 708 | - $sent = wp_mail( $to, $subject, $message, $headers, $attachments ); |
|
| 708 | + $sent = wp_mail($to, $subject, $message, $headers, $attachments); |
|
| 709 | 709 | |
| 710 | - if ( !$sent ) { |
|
| 711 | - $log_message = wp_sprintf( __( "\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), ( is_array( $to ) ? implode( ', ', $to ) : $to ), $subject ); |
|
| 712 | - wpinv_error_log( $log_message, __( "Email from Invoicing plugin failed to send", 'invoicing' ), __FILE__, __LINE__ ); |
|
| 710 | + if (!$sent) { |
|
| 711 | + $log_message = wp_sprintf(__("\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing'), date_i18n('F j Y H:i:s', current_time('timestamp')), (is_array($to) ? implode(', ', $to) : $to), $subject); |
|
| 712 | + wpinv_error_log($log_message, __("Email from Invoicing plugin failed to send", 'invoicing'), __FILE__, __LINE__); |
|
| 713 | 713 | } |
| 714 | 714 | |
| 715 | - remove_filter( 'wp_mail_from', 'wpinv_mail_get_from_address' ); |
|
| 716 | - remove_filter( 'wp_mail_from_name', 'wpinv_mail_get_from_name' ); |
|
| 717 | - remove_filter( 'wp_mail_content_type', 'wpinv_mail_get_content_type' ); |
|
| 715 | + remove_filter('wp_mail_from', 'wpinv_mail_get_from_address'); |
|
| 716 | + remove_filter('wp_mail_from_name', 'wpinv_mail_get_from_name'); |
|
| 717 | + remove_filter('wp_mail_content_type', 'wpinv_mail_get_content_type'); |
|
| 718 | 718 | |
| 719 | 719 | return $sent; |
| 720 | 720 | } |
| 721 | 721 | |
| 722 | 722 | function wpinv_get_emails() { |
| 723 | 723 | $overdue_days_options = array(); |
| 724 | - $overdue_days_options[0] = __( 'On the Due Date', 'invoicing' ); |
|
| 725 | - $overdue_days_options[1] = __( '1 day after Due Date', 'invoicing' ); |
|
| 724 | + $overdue_days_options[0] = __('On the Due Date', 'invoicing'); |
|
| 725 | + $overdue_days_options[1] = __('1 day after Due Date', 'invoicing'); |
|
| 726 | 726 | |
| 727 | - for ( $i = 2; $i <= 10; $i++ ) { |
|
| 728 | - $overdue_days_options[$i] = wp_sprintf( __( '%d days after Due Date', 'invoicing' ), $i ); |
|
| 727 | + for ($i = 2; $i <= 10; $i++) { |
|
| 728 | + $overdue_days_options[$i] = wp_sprintf(__('%d days after Due Date', 'invoicing'), $i); |
|
| 729 | 729 | } |
| 730 | 730 | |
| 731 | 731 | // Default, built-in gateways |
@@ -733,130 +733,130 @@ discard block |
||
| 733 | 733 | 'new_invoice' => array( |
| 734 | 734 | 'email_new_invoice_header' => array( |
| 735 | 735 | 'id' => 'email_new_invoice_header', |
| 736 | - 'name' => '<h3>' . __( 'New Invoice', 'invoicing' ) . '</h3>', |
|
| 737 | - 'desc' => __( 'New invoice emails are sent to admin when a new invoice is received.', 'invoicing' ), |
|
| 736 | + 'name' => '<h3>' . __('New Invoice', 'invoicing') . '</h3>', |
|
| 737 | + 'desc' => __('New invoice emails are sent to admin when a new invoice is received.', 'invoicing'), |
|
| 738 | 738 | 'type' => 'header', |
| 739 | 739 | ), |
| 740 | 740 | 'email_new_invoice_active' => array( |
| 741 | 741 | 'id' => 'email_new_invoice_active', |
| 742 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
| 743 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
| 742 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
| 743 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
| 744 | 744 | 'type' => 'checkbox', |
| 745 | 745 | 'std' => 1 |
| 746 | 746 | ), |
| 747 | 747 | 'email_new_invoice_subject' => array( |
| 748 | 748 | 'id' => 'email_new_invoice_subject', |
| 749 | - 'name' => __( 'Subject', 'invoicing' ), |
|
| 750 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
| 749 | + 'name' => __('Subject', 'invoicing'), |
|
| 750 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
| 751 | 751 | 'type' => 'text', |
| 752 | - 'std' => __( '[{site_title}] New payment invoice ({invoice_number}) - {invoice_date}', 'invoicing' ), |
|
| 752 | + 'std' => __('[{site_title}] New payment invoice ({invoice_number}) - {invoice_date}', 'invoicing'), |
|
| 753 | 753 | 'size' => 'large' |
| 754 | 754 | ), |
| 755 | 755 | 'email_new_invoice_heading' => array( |
| 756 | 756 | 'id' => 'email_new_invoice_heading', |
| 757 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
| 758 | - 'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ), |
|
| 757 | + 'name' => __('Email Heading', 'invoicing'), |
|
| 758 | + 'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'), |
|
| 759 | 759 | 'type' => 'text', |
| 760 | - 'std' => __( 'New payment invoice', 'invoicing' ), |
|
| 760 | + 'std' => __('New payment invoice', 'invoicing'), |
|
| 761 | 761 | 'size' => 'large' |
| 762 | 762 | ), |
| 763 | 763 | ), |
| 764 | 764 | 'cancelled_invoice' => array( |
| 765 | 765 | 'email_cancelled_invoice_header' => array( |
| 766 | 766 | 'id' => 'email_cancelled_invoice_header', |
| 767 | - 'name' => '<h3>' . __( 'Cancelled Invoice', 'invoicing' ) . '</h3>', |
|
| 768 | - 'desc' => __( 'Cancelled invoice emails are sent to admin when invoices have been marked cancelled.', 'invoicing' ), |
|
| 767 | + 'name' => '<h3>' . __('Cancelled Invoice', 'invoicing') . '</h3>', |
|
| 768 | + 'desc' => __('Cancelled invoice emails are sent to admin when invoices have been marked cancelled.', 'invoicing'), |
|
| 769 | 769 | 'type' => 'header', |
| 770 | 770 | ), |
| 771 | 771 | 'email_cancelled_invoice_active' => array( |
| 772 | 772 | 'id' => 'email_cancelled_invoice_active', |
| 773 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
| 774 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
| 773 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
| 774 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
| 775 | 775 | 'type' => 'checkbox', |
| 776 | 776 | 'std' => 1 |
| 777 | 777 | ), |
| 778 | 778 | 'email_cancelled_invoice_subject' => array( |
| 779 | 779 | 'id' => 'email_cancelled_invoice_subject', |
| 780 | - 'name' => __( 'Subject', 'invoicing' ), |
|
| 781 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
| 780 | + 'name' => __('Subject', 'invoicing'), |
|
| 781 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
| 782 | 782 | 'type' => 'text', |
| 783 | - 'std' => __( '[{site_title}] Cancelled invoice ({invoice_number})', 'invoicing' ), |
|
| 783 | + 'std' => __('[{site_title}] Cancelled invoice ({invoice_number})', 'invoicing'), |
|
| 784 | 784 | 'size' => 'large' |
| 785 | 785 | ), |
| 786 | 786 | 'email_cancelled_invoice_heading' => array( |
| 787 | 787 | 'id' => 'email_cancelled_invoice_heading', |
| 788 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
| 789 | - 'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ), |
|
| 788 | + 'name' => __('Email Heading', 'invoicing'), |
|
| 789 | + 'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'), |
|
| 790 | 790 | 'type' => 'text', |
| 791 | - 'std' => __( 'Cancelled invoice', 'invoicing' ), |
|
| 791 | + 'std' => __('Cancelled invoice', 'invoicing'), |
|
| 792 | 792 | 'size' => 'large' |
| 793 | 793 | ), |
| 794 | 794 | ), |
| 795 | 795 | 'failed_invoice' => array( |
| 796 | 796 | 'email_failed_invoice_header' => array( |
| 797 | 797 | 'id' => 'email_failed_invoice_header', |
| 798 | - 'name' => '<h3>' . __( 'Failed Invoice', 'invoicing' ) . '</h3>', |
|
| 799 | - 'desc' => __( 'Failed invoice emails are sent to admin when invoices have been marked failed (if they were previously processing or on-hold).', 'invoicing' ), |
|
| 798 | + 'name' => '<h3>' . __('Failed Invoice', 'invoicing') . '</h3>', |
|
| 799 | + 'desc' => __('Failed invoice emails are sent to admin when invoices have been marked failed (if they were previously processing or on-hold).', 'invoicing'), |
|
| 800 | 800 | 'type' => 'header', |
| 801 | 801 | ), |
| 802 | 802 | 'email_failed_invoice_active' => array( |
| 803 | 803 | 'id' => 'email_failed_invoice_active', |
| 804 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
| 805 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
| 804 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
| 805 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
| 806 | 806 | 'type' => 'checkbox', |
| 807 | 807 | 'std' => 1 |
| 808 | 808 | ), |
| 809 | 809 | 'email_failed_invoice_subject' => array( |
| 810 | 810 | 'id' => 'email_failed_invoice_subject', |
| 811 | - 'name' => __( 'Subject', 'invoicing' ), |
|
| 812 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
| 811 | + 'name' => __('Subject', 'invoicing'), |
|
| 812 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
| 813 | 813 | 'type' => 'text', |
| 814 | - 'std' => __( '[{site_title}] Failed invoice ({invoice_number})', 'invoicing' ), |
|
| 814 | + 'std' => __('[{site_title}] Failed invoice ({invoice_number})', 'invoicing'), |
|
| 815 | 815 | 'size' => 'large' |
| 816 | 816 | ), |
| 817 | 817 | 'email_failed_invoice_heading' => array( |
| 818 | 818 | 'id' => 'email_failed_invoice_heading', |
| 819 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
| 820 | - 'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ), |
|
| 819 | + 'name' => __('Email Heading', 'invoicing'), |
|
| 820 | + 'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'), |
|
| 821 | 821 | 'type' => 'text', |
| 822 | - 'std' => __( 'Failed invoice', 'invoicing' ), |
|
| 822 | + 'std' => __('Failed invoice', 'invoicing'), |
|
| 823 | 823 | 'size' => 'large' |
| 824 | 824 | ) |
| 825 | 825 | ), |
| 826 | 826 | 'onhold_invoice' => array( |
| 827 | 827 | 'email_onhold_invoice_header' => array( |
| 828 | 828 | 'id' => 'email_onhold_invoice_header', |
| 829 | - 'name' => '<h3>' . __( 'On Hold Invoice', 'invoicing' ) . '</h3>', |
|
| 830 | - 'desc' => __( 'This is an invoice notification sent to users containing invoice details after an invoice is placed on-hold.', 'invoicing' ), |
|
| 829 | + 'name' => '<h3>' . __('On Hold Invoice', 'invoicing') . '</h3>', |
|
| 830 | + 'desc' => __('This is an invoice notification sent to users containing invoice details after an invoice is placed on-hold.', 'invoicing'), |
|
| 831 | 831 | 'type' => 'header', |
| 832 | 832 | ), |
| 833 | 833 | 'email_onhold_invoice_active' => array( |
| 834 | 834 | 'id' => 'email_onhold_invoice_active', |
| 835 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
| 836 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
| 835 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
| 836 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
| 837 | 837 | 'type' => 'checkbox', |
| 838 | 838 | 'std' => 1 |
| 839 | 839 | ), |
| 840 | 840 | 'email_onhold_invoice_subject' => array( |
| 841 | 841 | 'id' => 'email_onhold_invoice_subject', |
| 842 | - 'name' => __( 'Subject', 'invoicing' ), |
|
| 843 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
| 842 | + 'name' => __('Subject', 'invoicing'), |
|
| 843 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
| 844 | 844 | 'type' => 'text', |
| 845 | - 'std' => __( '[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing' ), |
|
| 845 | + 'std' => __('[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing'), |
|
| 846 | 846 | 'size' => 'large' |
| 847 | 847 | ), |
| 848 | 848 | 'email_onhold_invoice_heading' => array( |
| 849 | 849 | 'id' => 'email_onhold_invoice_heading', |
| 850 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
| 851 | - 'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ), |
|
| 850 | + 'name' => __('Email Heading', 'invoicing'), |
|
| 851 | + 'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'), |
|
| 852 | 852 | 'type' => 'text', |
| 853 | - 'std' => __( 'Thank you for your invoice', 'invoicing' ), |
|
| 853 | + 'std' => __('Thank you for your invoice', 'invoicing'), |
|
| 854 | 854 | 'size' => 'large' |
| 855 | 855 | ), |
| 856 | 856 | 'email_onhold_invoice_admin_bcc' => array( |
| 857 | 857 | 'id' => 'email_onhold_invoice_admin_bcc', |
| 858 | - 'name' => __( 'Enable Admin BCC', 'invoicing' ), |
|
| 859 | - 'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ), |
|
| 858 | + 'name' => __('Enable Admin BCC', 'invoicing'), |
|
| 859 | + 'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'), |
|
| 860 | 860 | 'type' => 'checkbox', |
| 861 | 861 | 'std' => 1 |
| 862 | 862 | ), |
@@ -864,37 +864,37 @@ discard block |
||
| 864 | 864 | 'processing_invoice' => array( |
| 865 | 865 | 'email_processing_invoice_header' => array( |
| 866 | 866 | 'id' => 'email_processing_invoice_header', |
| 867 | - 'name' => '<h3>' . __( 'Processing Invoice', 'invoicing' ) . '</h3>', |
|
| 868 | - 'desc' => __( 'This is an invoice notification sent to users containing invoice details after payment.', 'invoicing' ), |
|
| 867 | + 'name' => '<h3>' . __('Processing Invoice', 'invoicing') . '</h3>', |
|
| 868 | + 'desc' => __('This is an invoice notification sent to users containing invoice details after payment.', 'invoicing'), |
|
| 869 | 869 | 'type' => 'header', |
| 870 | 870 | ), |
| 871 | 871 | 'email_processing_invoice_active' => array( |
| 872 | 872 | 'id' => 'email_processing_invoice_active', |
| 873 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
| 874 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
| 873 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
| 874 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
| 875 | 875 | 'type' => 'checkbox', |
| 876 | 876 | 'std' => 1 |
| 877 | 877 | ), |
| 878 | 878 | 'email_processing_invoice_subject' => array( |
| 879 | 879 | 'id' => 'email_processing_invoice_subject', |
| 880 | - 'name' => __( 'Subject', 'invoicing' ), |
|
| 881 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
| 880 | + 'name' => __('Subject', 'invoicing'), |
|
| 881 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
| 882 | 882 | 'type' => 'text', |
| 883 | - 'std' => __( '[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing' ), |
|
| 883 | + 'std' => __('[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing'), |
|
| 884 | 884 | 'size' => 'large' |
| 885 | 885 | ), |
| 886 | 886 | 'email_processing_invoice_heading' => array( |
| 887 | 887 | 'id' => 'email_processing_invoice_heading', |
| 888 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
| 889 | - 'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ), |
|
| 888 | + 'name' => __('Email Heading', 'invoicing'), |
|
| 889 | + 'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'), |
|
| 890 | 890 | 'type' => 'text', |
| 891 | - 'std' => __( 'Thank you for your invoice', 'invoicing' ), |
|
| 891 | + 'std' => __('Thank you for your invoice', 'invoicing'), |
|
| 892 | 892 | 'size' => 'large' |
| 893 | 893 | ), |
| 894 | 894 | 'email_processing_invoice_admin_bcc' => array( |
| 895 | 895 | 'id' => 'email_processing_invoice_admin_bcc', |
| 896 | - 'name' => __( 'Enable Admin BCC', 'invoicing' ), |
|
| 897 | - 'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ), |
|
| 896 | + 'name' => __('Enable Admin BCC', 'invoicing'), |
|
| 897 | + 'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'), |
|
| 898 | 898 | 'type' => 'checkbox', |
| 899 | 899 | 'std' => 1 |
| 900 | 900 | ), |
@@ -902,37 +902,37 @@ discard block |
||
| 902 | 902 | 'completed_invoice' => array( |
| 903 | 903 | 'email_completed_invoice_header' => array( |
| 904 | 904 | 'id' => 'email_completed_invoice_header', |
| 905 | - 'name' => '<h3>' . __( 'Paid Invoice', 'invoicing' ) . '</h3>', |
|
| 906 | - 'desc' => __( 'Invoice paid emails are sent to users when their invoices are marked paid and usually indicate that their payment has been done.', 'invoicing' ), |
|
| 905 | + 'name' => '<h3>' . __('Paid Invoice', 'invoicing') . '</h3>', |
|
| 906 | + 'desc' => __('Invoice paid emails are sent to users when their invoices are marked paid and usually indicate that their payment has been done.', 'invoicing'), |
|
| 907 | 907 | 'type' => 'header', |
| 908 | 908 | ), |
| 909 | 909 | 'email_completed_invoice_active' => array( |
| 910 | 910 | 'id' => 'email_completed_invoice_active', |
| 911 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
| 912 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
| 911 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
| 912 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
| 913 | 913 | 'type' => 'checkbox', |
| 914 | 914 | 'std' => 1 |
| 915 | 915 | ), |
| 916 | 916 | 'email_completed_invoice_subject' => array( |
| 917 | 917 | 'id' => 'email_completed_invoice_subject', |
| 918 | - 'name' => __( 'Subject', 'invoicing' ), |
|
| 919 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
| 918 | + 'name' => __('Subject', 'invoicing'), |
|
| 919 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
| 920 | 920 | 'type' => 'text', |
| 921 | - 'std' => __( '[{site_title}] Your invoice from {invoice_date} has been paid', 'invoicing' ), |
|
| 921 | + 'std' => __('[{site_title}] Your invoice from {invoice_date} has been paid', 'invoicing'), |
|
| 922 | 922 | 'size' => 'large' |
| 923 | 923 | ), |
| 924 | 924 | 'email_completed_invoice_heading' => array( |
| 925 | 925 | 'id' => 'email_completed_invoice_heading', |
| 926 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
| 927 | - 'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ), |
|
| 926 | + 'name' => __('Email Heading', 'invoicing'), |
|
| 927 | + 'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'), |
|
| 928 | 928 | 'type' => 'text', |
| 929 | - 'std' => __( 'Your invoice has been paid', 'invoicing' ), |
|
| 929 | + 'std' => __('Your invoice has been paid', 'invoicing'), |
|
| 930 | 930 | 'size' => 'large' |
| 931 | 931 | ), |
| 932 | 932 | 'email_completed_invoice_admin_bcc' => array( |
| 933 | 933 | 'id' => 'email_completed_invoice_admin_bcc', |
| 934 | - 'name' => __( 'Enable Admin BCC', 'invoicing' ), |
|
| 935 | - 'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ), |
|
| 934 | + 'name' => __('Enable Admin BCC', 'invoicing'), |
|
| 935 | + 'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'), |
|
| 936 | 936 | 'type' => 'checkbox', |
| 937 | 937 | ), |
| 938 | 938 | 'std' => 1 |
@@ -940,37 +940,37 @@ discard block |
||
| 940 | 940 | 'refunded_invoice' => array( |
| 941 | 941 | 'email_refunded_invoice_header' => array( |
| 942 | 942 | 'id' => 'email_refunded_invoice_header', |
| 943 | - 'name' => '<h3>' . __( 'Refunded Invoice', 'invoicing' ) . '</h3>', |
|
| 944 | - 'desc' => __( 'Invoice refunded emails are sent to users when their invoices are marked refunded.', 'invoicing' ), |
|
| 943 | + 'name' => '<h3>' . __('Refunded Invoice', 'invoicing') . '</h3>', |
|
| 944 | + 'desc' => __('Invoice refunded emails are sent to users when their invoices are marked refunded.', 'invoicing'), |
|
| 945 | 945 | 'type' => 'header', |
| 946 | 946 | ), |
| 947 | 947 | 'email_refunded_invoice_active' => array( |
| 948 | 948 | 'id' => 'email_refunded_invoice_active', |
| 949 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
| 950 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
| 949 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
| 950 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
| 951 | 951 | 'type' => 'checkbox', |
| 952 | 952 | 'std' => 1 |
| 953 | 953 | ), |
| 954 | 954 | 'email_refunded_invoice_subject' => array( |
| 955 | 955 | 'id' => 'email_refunded_invoice_subject', |
| 956 | - 'name' => __( 'Subject', 'invoicing' ), |
|
| 957 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
| 956 | + 'name' => __('Subject', 'invoicing'), |
|
| 957 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
| 958 | 958 | 'type' => 'text', |
| 959 | - 'std' => __( '[{site_title}] Your invoice from {invoice_date} has been refunded', 'invoicing' ), |
|
| 959 | + 'std' => __('[{site_title}] Your invoice from {invoice_date} has been refunded', 'invoicing'), |
|
| 960 | 960 | 'size' => 'large' |
| 961 | 961 | ), |
| 962 | 962 | 'email_refunded_invoice_heading' => array( |
| 963 | 963 | 'id' => 'email_refunded_invoice_heading', |
| 964 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
| 965 | - 'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ), |
|
| 964 | + 'name' => __('Email Heading', 'invoicing'), |
|
| 965 | + 'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'), |
|
| 966 | 966 | 'type' => 'text', |
| 967 | - 'std' => __( 'Your invoice has been refunded', 'invoicing' ), |
|
| 967 | + 'std' => __('Your invoice has been refunded', 'invoicing'), |
|
| 968 | 968 | 'size' => 'large' |
| 969 | 969 | ), |
| 970 | 970 | 'email_refunded_invoice_admin_bcc' => array( |
| 971 | 971 | 'id' => 'email_refunded_invoice_admin_bcc', |
| 972 | - 'name' => __( 'Enable Admin BCC', 'invoicing' ), |
|
| 973 | - 'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ), |
|
| 972 | + 'name' => __('Enable Admin BCC', 'invoicing'), |
|
| 973 | + 'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'), |
|
| 974 | 974 | 'type' => 'checkbox', |
| 975 | 975 | 'std' => 1 |
| 976 | 976 | ), |
@@ -978,37 +978,37 @@ discard block |
||
| 978 | 978 | 'user_invoice' => array( |
| 979 | 979 | 'email_user_invoice_header' => array( |
| 980 | 980 | 'id' => 'email_user_invoice_header', |
| 981 | - 'name' => '<h3>' . __( 'Customer Invoice', 'invoicing' ) . '</h3>', |
|
| 982 | - 'desc' => __( 'Customer invoice emails can be sent to customers containing their invoice information and payment links.', 'invoicing' ), |
|
| 981 | + 'name' => '<h3>' . __('Customer Invoice', 'invoicing') . '</h3>', |
|
| 982 | + 'desc' => __('Customer invoice emails can be sent to customers containing their invoice information and payment links.', 'invoicing'), |
|
| 983 | 983 | 'type' => 'header', |
| 984 | 984 | ), |
| 985 | 985 | 'email_user_invoice_active' => array( |
| 986 | 986 | 'id' => 'email_user_invoice_active', |
| 987 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
| 988 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
| 987 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
| 988 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
| 989 | 989 | 'type' => 'checkbox', |
| 990 | 990 | 'std' => 1 |
| 991 | 991 | ), |
| 992 | 992 | 'email_user_invoice_subject' => array( |
| 993 | 993 | 'id' => 'email_user_invoice_subject', |
| 994 | - 'name' => __( 'Subject', 'invoicing' ), |
|
| 995 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
| 994 | + 'name' => __('Subject', 'invoicing'), |
|
| 995 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
| 996 | 996 | 'type' => 'text', |
| 997 | - 'std' => __( '[{site_title}] Your invoice from {invoice_date}', 'invoicing' ), |
|
| 997 | + 'std' => __('[{site_title}] Your invoice from {invoice_date}', 'invoicing'), |
|
| 998 | 998 | 'size' => 'large' |
| 999 | 999 | ), |
| 1000 | 1000 | 'email_user_invoice_heading' => array( |
| 1001 | 1001 | 'id' => 'email_user_invoice_heading', |
| 1002 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
| 1003 | - 'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ), |
|
| 1002 | + 'name' => __('Email Heading', 'invoicing'), |
|
| 1003 | + 'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'), |
|
| 1004 | 1004 | 'type' => 'text', |
| 1005 | - 'std' => __( 'Your invoice {invoice_number} details', 'invoicing' ), |
|
| 1005 | + 'std' => __('Your invoice {invoice_number} details', 'invoicing'), |
|
| 1006 | 1006 | 'size' => 'large' |
| 1007 | 1007 | ), |
| 1008 | 1008 | 'email_user_invoice_admin_bcc' => array( |
| 1009 | 1009 | 'id' => 'email_user_invoice_admin_bcc', |
| 1010 | - 'name' => __( 'Enable Admin BCC', 'invoicing' ), |
|
| 1011 | - 'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ), |
|
| 1010 | + 'name' => __('Enable Admin BCC', 'invoicing'), |
|
| 1011 | + 'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'), |
|
| 1012 | 1012 | 'type' => 'checkbox', |
| 1013 | 1013 | 'std' => 1 |
| 1014 | 1014 | ), |
@@ -1016,177 +1016,177 @@ discard block |
||
| 1016 | 1016 | 'user_note' => array( |
| 1017 | 1017 | 'email_user_note_header' => array( |
| 1018 | 1018 | 'id' => 'email_user_note_header', |
| 1019 | - 'name' => '<h3>' . __( 'Customer Note', 'invoicing' ) . '</h3>', |
|
| 1020 | - 'desc' => __( 'Customer note emails are sent when you add a note to an invoice.', 'invoicing' ), |
|
| 1019 | + 'name' => '<h3>' . __('Customer Note', 'invoicing') . '</h3>', |
|
| 1020 | + 'desc' => __('Customer note emails are sent when you add a note to an invoice.', 'invoicing'), |
|
| 1021 | 1021 | 'type' => 'header', |
| 1022 | 1022 | ), |
| 1023 | 1023 | 'email_user_note_active' => array( |
| 1024 | 1024 | 'id' => 'email_user_note_active', |
| 1025 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
| 1026 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
| 1025 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
| 1026 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
| 1027 | 1027 | 'type' => 'checkbox', |
| 1028 | 1028 | 'std' => 1 |
| 1029 | 1029 | ), |
| 1030 | 1030 | 'email_user_note_subject' => array( |
| 1031 | 1031 | 'id' => 'email_user_note_subject', |
| 1032 | - 'name' => __( 'Subject', 'invoicing' ), |
|
| 1033 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
| 1032 | + 'name' => __('Subject', 'invoicing'), |
|
| 1033 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
| 1034 | 1034 | 'type' => 'text', |
| 1035 | - 'std' => __( '[{site_title}] Note added to your invoice #{invoice_number} from {invoice_date}', 'invoicing' ), |
|
| 1035 | + 'std' => __('[{site_title}] Note added to your invoice #{invoice_number} from {invoice_date}', 'invoicing'), |
|
| 1036 | 1036 | 'size' => 'large' |
| 1037 | 1037 | ), |
| 1038 | 1038 | 'email_user_note_heading' => array( |
| 1039 | 1039 | 'id' => 'email_user_note_heading', |
| 1040 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
| 1041 | - 'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ), |
|
| 1040 | + 'name' => __('Email Heading', 'invoicing'), |
|
| 1041 | + 'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'), |
|
| 1042 | 1042 | 'type' => 'text', |
| 1043 | - 'std' => __( 'A note has been added to your invoice', 'invoicing' ), |
|
| 1043 | + 'std' => __('A note has been added to your invoice', 'invoicing'), |
|
| 1044 | 1044 | 'size' => 'large' |
| 1045 | 1045 | ), |
| 1046 | 1046 | ), |
| 1047 | 1047 | 'overdue' => array( |
| 1048 | 1048 | 'email_overdue_header' => array( |
| 1049 | 1049 | 'id' => 'email_overdue_header', |
| 1050 | - 'name' => '<h3>' . __( 'Payment Reminder', 'invoicing' ) . '</h3>', |
|
| 1051 | - 'desc' => __( 'Payment reminder emails are sent to user automatically.', 'invoicing' ), |
|
| 1050 | + 'name' => '<h3>' . __('Payment Reminder', 'invoicing') . '</h3>', |
|
| 1051 | + 'desc' => __('Payment reminder emails are sent to user automatically.', 'invoicing'), |
|
| 1052 | 1052 | 'type' => 'header', |
| 1053 | 1053 | ), |
| 1054 | 1054 | 'email_overdue_active' => array( |
| 1055 | 1055 | 'id' => 'email_overdue_active', |
| 1056 | - 'name' => __( 'Enable/Disable', 'invoicing' ), |
|
| 1057 | - 'desc' => __( 'Enable this email notification', 'invoicing' ), |
|
| 1056 | + 'name' => __('Enable/Disable', 'invoicing'), |
|
| 1057 | + 'desc' => __('Enable this email notification', 'invoicing'), |
|
| 1058 | 1058 | 'type' => 'checkbox', |
| 1059 | 1059 | 'std' => 1 |
| 1060 | 1060 | ), |
| 1061 | 1061 | 'email_due_reminder_days' => array( |
| 1062 | 1062 | 'id' => 'email_due_reminder_days', |
| 1063 | - 'name' => __( 'When to Send', 'sliced-invoices' ), |
|
| 1064 | - 'desc' => __( 'Check when you would like payment reminders sent out.', 'invoicing' ), |
|
| 1063 | + 'name' => __('When to Send', 'sliced-invoices'), |
|
| 1064 | + 'desc' => __('Check when you would like payment reminders sent out.', 'invoicing'), |
|
| 1065 | 1065 | 'default' => '', |
| 1066 | 1066 | 'type' => 'multicheck', |
| 1067 | 1067 | 'options' => $overdue_days_options, |
| 1068 | 1068 | ), |
| 1069 | 1069 | 'email_overdue_subject' => array( |
| 1070 | 1070 | 'id' => 'email_overdue_subject', |
| 1071 | - 'name' => __( 'Subject', 'invoicing' ), |
|
| 1072 | - 'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ), |
|
| 1071 | + 'name' => __('Subject', 'invoicing'), |
|
| 1072 | + 'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'), |
|
| 1073 | 1073 | 'type' => 'text', |
| 1074 | - 'std' => __( '[{site_title}] Payment Reminder', 'invoicing' ), |
|
| 1074 | + 'std' => __('[{site_title}] Payment Reminder', 'invoicing'), |
|
| 1075 | 1075 | 'size' => 'large' |
| 1076 | 1076 | ), |
| 1077 | 1077 | 'email_overdue_heading' => array( |
| 1078 | 1078 | 'id' => 'email_overdue_heading', |
| 1079 | - 'name' => __( 'Email Heading', 'invoicing' ), |
|
| 1080 | - 'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ), |
|
| 1079 | + 'name' => __('Email Heading', 'invoicing'), |
|
| 1080 | + 'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'), |
|
| 1081 | 1081 | 'type' => 'text', |
| 1082 | - 'std' => __( 'Payment reminder for your invoice', 'invoicing' ), |
|
| 1082 | + 'std' => __('Payment reminder for your invoice', 'invoicing'), |
|
| 1083 | 1083 | 'size' => 'large' |
| 1084 | 1084 | ), |
| 1085 | 1085 | 'email_overdue_body' => array( |
| 1086 | 1086 | 'id' => 'email_overdue_body', |
| 1087 | - 'name' => __( 'Email Content', 'invoicing' ), |
|
| 1088 | - 'desc' => __( 'The content of the email.', 'invoicing' ), |
|
| 1087 | + 'name' => __('Email Content', 'invoicing'), |
|
| 1088 | + 'desc' => __('The content of the email.', 'invoicing'), |
|
| 1089 | 1089 | 'type' => 'rich_editor', |
| 1090 | - 'std' => __( '<p>Hi {full_name},</p><p>This is just a friendly reminder your invoice <a href="{invoice_link}">#{invoice_number}</a> {is_was} due on {invoice_due_date}.</p><p>The total of this invoice is {invoice_total}</p><p>To pay now for this invoice please use the following link: <a href="{invoice_pay_link}">Pay Now</a></p>', 'invoicing' ), |
|
| 1090 | + 'std' => __('<p>Hi {full_name},</p><p>This is just a friendly reminder your invoice <a href="{invoice_link}">#{invoice_number}</a> {is_was} due on {invoice_due_date}.</p><p>The total of this invoice is {invoice_total}</p><p>To pay now for this invoice please use the following link: <a href="{invoice_pay_link}">Pay Now</a></p>', 'invoicing'), |
|
| 1091 | 1091 | 'class' => 'large', |
| 1092 | 1092 | 'size' => 10, |
| 1093 | 1093 | ), |
| 1094 | 1094 | ), |
| 1095 | 1095 | ); |
| 1096 | 1096 | |
| 1097 | - return apply_filters( 'wpinv_get_emails', $emails ); |
|
| 1097 | + return apply_filters('wpinv_get_emails', $emails); |
|
| 1098 | 1098 | } |
| 1099 | 1099 | |
| 1100 | -function wpinv_settings_emails( $settings = array() ) { |
|
| 1100 | +function wpinv_settings_emails($settings = array()) { |
|
| 1101 | 1101 | $emails = wpinv_get_emails(); |
| 1102 | 1102 | |
| 1103 | - if ( !empty( $emails ) ) { |
|
| 1104 | - foreach ( $emails as $key => $email ) { |
|
| 1103 | + if (!empty($emails)) { |
|
| 1104 | + foreach ($emails as $key => $email) { |
|
| 1105 | 1105 | $settings[$key] = $email; |
| 1106 | 1106 | } |
| 1107 | 1107 | } |
| 1108 | 1108 | |
| 1109 | - return apply_filters( 'wpinv_settings_get_emails', $settings ); |
|
| 1109 | + return apply_filters('wpinv_settings_get_emails', $settings); |
|
| 1110 | 1110 | } |
| 1111 | -add_filter( 'wpinv_settings_emails', 'wpinv_settings_emails', 10, 1 ); |
|
| 1111 | +add_filter('wpinv_settings_emails', 'wpinv_settings_emails', 10, 1); |
|
| 1112 | 1112 | |
| 1113 | -function wpinv_settings_sections_emails( $settings ) { |
|
| 1113 | +function wpinv_settings_sections_emails($settings) { |
|
| 1114 | 1114 | $emails = wpinv_get_emails(); |
| 1115 | 1115 | |
| 1116 | 1116 | if (!empty($emails)) { |
| 1117 | - foreach ($emails as $key => $email) { |
|
| 1118 | - $settings[$key] = !empty( $email['email_' . $key . '_header']['name'] ) ? strip_tags( $email['email_' . $key . '_header']['name'] ) : $key; |
|
| 1117 | + foreach ($emails as $key => $email) { |
|
| 1118 | + $settings[$key] = !empty($email['email_' . $key . '_header']['name']) ? strip_tags($email['email_' . $key . '_header']['name']) : $key; |
|
| 1119 | 1119 | } |
| 1120 | 1120 | } |
| 1121 | 1121 | |
| 1122 | 1122 | return $settings; |
| 1123 | 1123 | } |
| 1124 | -add_filter( 'wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1 ); |
|
| 1124 | +add_filter('wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1); |
|
| 1125 | 1125 | |
| 1126 | -function wpinv_email_is_enabled( $email_type ) { |
|
| 1126 | +function wpinv_email_is_enabled($email_type) { |
|
| 1127 | 1127 | $emails = wpinv_get_emails(); |
| 1128 | - $enabled = isset( $emails[$email_type] ) && wpinv_get_option( $email_type . '_active', 0 ) ? true : false; |
|
| 1128 | + $enabled = isset($emails[$email_type]) && wpinv_get_option($email_type . '_active', 0) ? true : false; |
|
| 1129 | 1129 | |
| 1130 | - return apply_filters( 'wpinv_email_is_enabled', $enabled, $email_type ); |
|
| 1130 | + return apply_filters('wpinv_email_is_enabled', $enabled, $email_type); |
|
| 1131 | 1131 | } |
| 1132 | 1132 | |
| 1133 | -function wpinv_email_get_recipient( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
| 1134 | - switch ( $email_type ) { |
|
| 1133 | +function wpinv_email_get_recipient($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
| 1134 | + switch ($email_type) { |
|
| 1135 | 1135 | case 'new_invoice': |
| 1136 | 1136 | case 'cancelled_invoice': |
| 1137 | 1137 | case 'failed_invoice': |
| 1138 | 1138 | $recipient = wpinv_get_admin_email(); |
| 1139 | 1139 | break; |
| 1140 | 1140 | default: |
| 1141 | - $invoice = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL ); |
|
| 1142 | - $recipient = !empty( $invoice ) ? $invoice->get_email() : ''; |
|
| 1141 | + $invoice = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL); |
|
| 1142 | + $recipient = !empty($invoice) ? $invoice->get_email() : ''; |
|
| 1143 | 1143 | break; |
| 1144 | 1144 | } |
| 1145 | 1145 | |
| 1146 | - return apply_filters( 'wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice ); |
|
| 1146 | + return apply_filters('wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice); |
|
| 1147 | 1147 | } |
| 1148 | 1148 | |
| 1149 | -function wpinv_email_get_subject( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
| 1150 | - $subject = wpinv_get_option( 'email_' . $email_type . '_subject' ); |
|
| 1149 | +function wpinv_email_get_subject($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
| 1150 | + $subject = wpinv_get_option('email_' . $email_type . '_subject'); |
|
| 1151 | 1151 | |
| 1152 | - $subject = wpinv_email_format_text( $subject ); |
|
| 1152 | + $subject = wpinv_email_format_text($subject); |
|
| 1153 | 1153 | |
| 1154 | - return apply_filters( 'wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice ); |
|
| 1154 | + return apply_filters('wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice); |
|
| 1155 | 1155 | } |
| 1156 | 1156 | |
| 1157 | -function wpinv_email_get_heading( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
| 1158 | - $email_heading = wpinv_get_option( 'email_' . $email_type . '_heading' ); |
|
| 1157 | +function wpinv_email_get_heading($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
| 1158 | + $email_heading = wpinv_get_option('email_' . $email_type . '_heading'); |
|
| 1159 | 1159 | |
| 1160 | - $email_heading = wpinv_email_format_text( $email_heading ); |
|
| 1160 | + $email_heading = wpinv_email_format_text($email_heading); |
|
| 1161 | 1161 | |
| 1162 | - return apply_filters( 'wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice ); |
|
| 1162 | + return apply_filters('wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice); |
|
| 1163 | 1163 | } |
| 1164 | 1164 | |
| 1165 | -function wpinv_email_get_content( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
| 1166 | - $content = wpinv_get_option( 'email_' . $email_type . '_body' ); |
|
| 1165 | +function wpinv_email_get_content($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
| 1166 | + $content = wpinv_get_option('email_' . $email_type . '_body'); |
|
| 1167 | 1167 | |
| 1168 | - $content = wpinv_email_format_text( $content ); |
|
| 1168 | + $content = wpinv_email_format_text($content); |
|
| 1169 | 1169 | |
| 1170 | - return apply_filters( 'wpinv_email_content', $content, $email_type, $invoice_id, $invoice ); |
|
| 1170 | + return apply_filters('wpinv_email_content', $content, $email_type, $invoice_id, $invoice); |
|
| 1171 | 1171 | } |
| 1172 | 1172 | |
| 1173 | -function wpinv_email_get_headers( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
| 1173 | +function wpinv_email_get_headers($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
| 1174 | 1174 | $from_name = wpinv_mail_get_from_address(); |
| 1175 | 1175 | $from_email = wpinv_mail_get_from_address(); |
| 1176 | 1176 | |
| 1177 | - $invoice = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL ); |
|
| 1177 | + $invoice = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL); |
|
| 1178 | 1178 | |
| 1179 | - $headers = "From: " . stripslashes_deep( html_entity_decode( $from_name, ENT_COMPAT, 'UTF-8' ) ) . " <$from_email>\r\n"; |
|
| 1180 | - $headers .= "Reply-To: ". $from_email . "\r\n"; |
|
| 1179 | + $headers = "From: " . stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8')) . " <$from_email>\r\n"; |
|
| 1180 | + $headers .= "Reply-To: " . $from_email . "\r\n"; |
|
| 1181 | 1181 | $headers .= "Content-Type: " . wpinv_mail_get_content_type() . "\r\n"; |
| 1182 | 1182 | |
| 1183 | - return apply_filters( 'wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice ); |
|
| 1183 | + return apply_filters('wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice); |
|
| 1184 | 1184 | } |
| 1185 | 1185 | |
| 1186 | -function wpinv_email_get_attachments( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
| 1186 | +function wpinv_email_get_attachments($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
| 1187 | 1187 | $attachments = array(); |
| 1188 | 1188 | |
| 1189 | - return apply_filters( 'wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice ); |
|
| 1189 | + return apply_filters('wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice); |
|
| 1190 | 1190 | } |
| 1191 | 1191 | |
| 1192 | 1192 | function wpinv_email_global_vars() { |
@@ -1203,73 +1203,73 @@ discard block |
||
| 1203 | 1203 | $replace['sitename'] = $blogname; |
| 1204 | 1204 | $replace['site-title'] = $blogname; |
| 1205 | 1205 | |
| 1206 | - return apply_filters( 'wpinv_email_global_vars', array( $search, $replace ) ); |
|
| 1206 | + return apply_filters('wpinv_email_global_vars', array($search, $replace)); |
|
| 1207 | 1207 | } |
| 1208 | 1208 | |
| 1209 | -function wpinv_email_format_text( $content ) { |
|
| 1209 | +function wpinv_email_format_text($content) { |
|
| 1210 | 1210 | global $wpinv_email_search, $wpinv_email_replace; |
| 1211 | 1211 | |
| 1212 | - if ( empty( $wpinv_email_search ) ) { |
|
| 1212 | + if (empty($wpinv_email_search)) { |
|
| 1213 | 1213 | $wpinv_email_search = array(); |
| 1214 | 1214 | } |
| 1215 | 1215 | |
| 1216 | - if ( empty( $wpinv_email_replace ) ) { |
|
| 1216 | + if (empty($wpinv_email_replace)) { |
|
| 1217 | 1217 | $wpinv_email_replace = array(); |
| 1218 | 1218 | } |
| 1219 | 1219 | |
| 1220 | - $wpinv_email_search = (array)apply_filters( 'wpinv_email_format_text_search', $wpinv_email_search ); |
|
| 1221 | - $wpinv_email_replace = (array)apply_filters( 'wpinv_email_format_text_replace', $wpinv_email_replace ); |
|
| 1220 | + $wpinv_email_search = (array)apply_filters('wpinv_email_format_text_search', $wpinv_email_search); |
|
| 1221 | + $wpinv_email_replace = (array)apply_filters('wpinv_email_format_text_replace', $wpinv_email_replace); |
|
| 1222 | 1222 | |
| 1223 | 1223 | $global_vars = wpinv_email_global_vars(); |
| 1224 | 1224 | |
| 1225 | - $search = array_merge( $global_vars[0], $wpinv_email_search ); |
|
| 1226 | - $replace = array_merge( $global_vars[1], $wpinv_email_replace ); |
|
| 1225 | + $search = array_merge($global_vars[0], $wpinv_email_search); |
|
| 1226 | + $replace = array_merge($global_vars[1], $wpinv_email_replace); |
|
| 1227 | 1227 | |
| 1228 | - if ( empty( $search ) || empty( $replace ) || !is_array( $search ) || !is_array( $replace ) ) { |
|
| 1228 | + if (empty($search) || empty($replace) || !is_array($search) || !is_array($replace)) { |
|
| 1229 | 1229 | return $content; |
| 1230 | 1230 | } |
| 1231 | 1231 | |
| 1232 | - return str_replace( $search, $replace, $content ); |
|
| 1232 | + return str_replace($search, $replace, $content); |
|
| 1233 | 1233 | } |
| 1234 | 1234 | |
| 1235 | -function wpinv_email_style_body( $content ) { |
|
| 1235 | +function wpinv_email_style_body($content) { |
|
| 1236 | 1236 | // make sure we only inline CSS for html emails |
| 1237 | - if ( in_array( wpinv_mail_get_content_type(), array( 'text/html', 'multipart/alternative' ) ) && class_exists( 'DOMDocument' ) ) { |
|
| 1237 | + if (in_array(wpinv_mail_get_content_type(), array('text/html', 'multipart/alternative')) && class_exists('DOMDocument')) { |
|
| 1238 | 1238 | ob_start(); |
| 1239 | - wpinv_get_template( 'emails/wpinv-email-styles.php' ); |
|
| 1240 | - $css = apply_filters( 'wpinv_email_styles', ob_get_clean() ); |
|
| 1239 | + wpinv_get_template('emails/wpinv-email-styles.php'); |
|
| 1240 | + $css = apply_filters('wpinv_email_styles', ob_get_clean()); |
|
| 1241 | 1241 | |
| 1242 | 1242 | // apply CSS styles inline for picky email clients |
| 1243 | 1243 | try { |
| 1244 | - $emogrifier = new Emogrifier( $content, $css ); |
|
| 1244 | + $emogrifier = new Emogrifier($content, $css); |
|
| 1245 | 1245 | $content = $emogrifier->emogrify(); |
| 1246 | - } catch ( Exception $e ) { |
|
| 1247 | - wpinv_error_log( $e->getMessage(), 'emogrifier' ); |
|
| 1246 | + } catch (Exception $e) { |
|
| 1247 | + wpinv_error_log($e->getMessage(), 'emogrifier'); |
|
| 1248 | 1248 | } |
| 1249 | 1249 | } |
| 1250 | 1250 | return $content; |
| 1251 | 1251 | } |
| 1252 | 1252 | |
| 1253 | -function wpinv_email_header( $email_heading = '', $invoice = array(), $email_type = '', $sent_to_admin = false ) { |
|
| 1254 | - wpinv_get_template( 'emails/wpinv-email-header.php', array( 'email_heading' => $email_heading, 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) ); |
|
| 1253 | +function wpinv_email_header($email_heading = '', $invoice = array(), $email_type = '', $sent_to_admin = false) { |
|
| 1254 | + wpinv_get_template('emails/wpinv-email-header.php', array('email_heading' => $email_heading, 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin)); |
|
| 1255 | 1255 | } |
| 1256 | 1256 | |
| 1257 | 1257 | /** |
| 1258 | 1258 | * Get the email footer. |
| 1259 | 1259 | */ |
| 1260 | -function wpinv_email_footer( $invoice = array(), $email_type = '', $sent_to_admin = false ) { |
|
| 1261 | - wpinv_get_template( 'emails/wpinv-email-footer.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) ); |
|
| 1260 | +function wpinv_email_footer($invoice = array(), $email_type = '', $sent_to_admin = false) { |
|
| 1261 | + wpinv_get_template('emails/wpinv-email-footer.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin)); |
|
| 1262 | 1262 | } |
| 1263 | 1263 | |
| 1264 | -function wpinv_email_wrap_message( $message ) { |
|
| 1264 | +function wpinv_email_wrap_message($message) { |
|
| 1265 | 1265 | // Buffer |
| 1266 | 1266 | ob_start(); |
| 1267 | 1267 | |
| 1268 | - do_action( 'wpinv_email_header' ); |
|
| 1268 | + do_action('wpinv_email_header'); |
|
| 1269 | 1269 | |
| 1270 | - echo wpautop( wptexturize( $message ) ); |
|
| 1270 | + echo wpautop(wptexturize($message)); |
|
| 1271 | 1271 | |
| 1272 | - do_action( 'wpinv_email_footer' ); |
|
| 1272 | + do_action('wpinv_email_footer'); |
|
| 1273 | 1273 | |
| 1274 | 1274 | // Get contents |
| 1275 | 1275 | $message = ob_get_clean(); |
@@ -1277,86 +1277,86 @@ discard block |
||
| 1277 | 1277 | return $message; |
| 1278 | 1278 | } |
| 1279 | 1279 | |
| 1280 | -function wpinv_email_invoice_details( $invoice, $email_type = '', $sent_to_admin = false ) { |
|
| 1281 | - wpinv_get_template( 'emails/wpinv-email-invoice-details.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) ); |
|
| 1280 | +function wpinv_email_invoice_details($invoice, $email_type = '', $sent_to_admin = false) { |
|
| 1281 | + wpinv_get_template('emails/wpinv-email-invoice-details.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin)); |
|
| 1282 | 1282 | } |
| 1283 | 1283 | |
| 1284 | -function wpinv_email_invoice_items( $invoice, $email_type = '', $sent_to_admin = false ) { |
|
| 1285 | - wpinv_get_template( 'emails/wpinv-email-invoice-items.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) ); |
|
| 1284 | +function wpinv_email_invoice_items($invoice, $email_type = '', $sent_to_admin = false) { |
|
| 1285 | + wpinv_get_template('emails/wpinv-email-invoice-items.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin)); |
|
| 1286 | 1286 | } |
| 1287 | 1287 | |
| 1288 | -function wpinv_email_billing_details( $invoice, $email_type = '', $sent_to_admin = false ) { |
|
| 1289 | - wpinv_get_template( 'emails/wpinv-email-billing-details.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) ); |
|
| 1288 | +function wpinv_email_billing_details($invoice, $email_type = '', $sent_to_admin = false) { |
|
| 1289 | + wpinv_get_template('emails/wpinv-email-billing-details.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin)); |
|
| 1290 | 1290 | } |
| 1291 | 1291 | |
| 1292 | -function wpinv_send_customer_invoice( $data = array() ) { |
|
| 1293 | - $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL; |
|
| 1292 | +function wpinv_send_customer_invoice($data = array()) { |
|
| 1293 | + $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL; |
|
| 1294 | 1294 | |
| 1295 | - if ( empty( $invoice_id ) ) { |
|
| 1295 | + if (empty($invoice_id)) { |
|
| 1296 | 1296 | return; |
| 1297 | 1297 | } |
| 1298 | 1298 | |
| 1299 | - if ( !current_user_can( 'manage_options' ) ) { |
|
| 1300 | - wp_die( __( 'You do not have permission to send invoice notification', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 1299 | + if (!current_user_can('manage_options')) { |
|
| 1300 | + wp_die(__('You do not have permission to send invoice notification', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
| 1301 | 1301 | } |
| 1302 | 1302 | |
| 1303 | - $sent = wpinv_user_invoice_notification( $invoice_id ); |
|
| 1303 | + $sent = wpinv_user_invoice_notification($invoice_id); |
|
| 1304 | 1304 | |
| 1305 | 1305 | $status = $sent ? 'email_sent' : 'email_fail'; |
| 1306 | 1306 | |
| 1307 | - $redirect = add_query_arg( array( 'wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false ) ); |
|
| 1308 | - wp_redirect( $redirect ); |
|
| 1307 | + $redirect = add_query_arg(array('wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false)); |
|
| 1308 | + wp_redirect($redirect); |
|
| 1309 | 1309 | exit; |
| 1310 | 1310 | } |
| 1311 | -add_action( 'wpinv_send_invoice', 'wpinv_send_customer_invoice' ); |
|
| 1311 | +add_action('wpinv_send_invoice', 'wpinv_send_customer_invoice'); |
|
| 1312 | 1312 | |
| 1313 | -function wpinv_send_overdue_reminder( $data = array() ) { |
|
| 1314 | - $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL; |
|
| 1313 | +function wpinv_send_overdue_reminder($data = array()) { |
|
| 1314 | + $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL; |
|
| 1315 | 1315 | |
| 1316 | - if ( empty( $invoice_id ) ) { |
|
| 1316 | + if (empty($invoice_id)) { |
|
| 1317 | 1317 | return; |
| 1318 | 1318 | } |
| 1319 | 1319 | |
| 1320 | - if ( !current_user_can( 'manage_options' ) ) { |
|
| 1321 | - wp_die( __( 'You do not have permission to send reminder notification', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 1320 | + if (!current_user_can('manage_options')) { |
|
| 1321 | + wp_die(__('You do not have permission to send reminder notification', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
| 1322 | 1322 | } |
| 1323 | 1323 | |
| 1324 | - $sent = wpinv_send_payment_reminder_notification( $invoice_id ); |
|
| 1324 | + $sent = wpinv_send_payment_reminder_notification($invoice_id); |
|
| 1325 | 1325 | |
| 1326 | 1326 | $status = $sent ? 'email_sent' : 'email_fail'; |
| 1327 | 1327 | |
| 1328 | - $redirect = add_query_arg( array( 'wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false ) ); |
|
| 1329 | - wp_redirect( $redirect ); |
|
| 1328 | + $redirect = add_query_arg(array('wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false)); |
|
| 1329 | + wp_redirect($redirect); |
|
| 1330 | 1330 | exit; |
| 1331 | 1331 | } |
| 1332 | -add_action( 'wpinv_send_reminder', 'wpinv_send_overdue_reminder' ); |
|
| 1332 | +add_action('wpinv_send_reminder', 'wpinv_send_overdue_reminder'); |
|
| 1333 | 1333 | |
| 1334 | -function wpinv_send_customer_note_email( $data ) { |
|
| 1335 | - $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL; |
|
| 1334 | +function wpinv_send_customer_note_email($data) { |
|
| 1335 | + $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL; |
|
| 1336 | 1336 | |
| 1337 | - if ( empty( $invoice_id ) ) { |
|
| 1337 | + if (empty($invoice_id)) { |
|
| 1338 | 1338 | return; |
| 1339 | 1339 | } |
| 1340 | 1340 | |
| 1341 | - $sent = wpinv_user_note_notification( $invoice_id, $data ); |
|
| 1341 | + $sent = wpinv_user_note_notification($invoice_id, $data); |
|
| 1342 | 1342 | } |
| 1343 | -add_action( 'wpinv_new_customer_note', 'wpinv_send_customer_note_email', 10, 1 ); |
|
| 1343 | +add_action('wpinv_new_customer_note', 'wpinv_send_customer_note_email', 10, 1); |
|
| 1344 | 1344 | |
| 1345 | -function wpinv_add_notes_to_invoice_email( $invoice, $email_type, $sent_to_admin ) { |
|
| 1346 | - if ( !empty( $invoice ) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes( $invoice->ID, true ) ) { |
|
| 1347 | - $date_format = get_option( 'date_format' ); |
|
| 1348 | - $time_format = get_option( 'time_format' ); |
|
| 1345 | +function wpinv_add_notes_to_invoice_email($invoice, $email_type, $sent_to_admin) { |
|
| 1346 | + if (!empty($invoice) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes($invoice->ID, true)) { |
|
| 1347 | + $date_format = get_option('date_format'); |
|
| 1348 | + $time_format = get_option('time_format'); |
|
| 1349 | 1349 | ?> |
| 1350 | 1350 | <div id="wpinv-email-notes"> |
| 1351 | - <h3 class="wpinv-notes-t"><?php echo apply_filters( 'wpinv_email_invoice_notes_title', __( 'Invoice Notes', 'invoicing' ) ); ?></h3> |
|
| 1351 | + <h3 class="wpinv-notes-t"><?php echo apply_filters('wpinv_email_invoice_notes_title', __('Invoice Notes', 'invoicing')); ?></h3> |
|
| 1352 | 1352 | <ol class="wpinv-notes-lists"> |
| 1353 | 1353 | <?php |
| 1354 | - foreach ( $invoice_notes as $note ) { |
|
| 1355 | - $note_time = strtotime( $note->comment_date ); |
|
| 1354 | + foreach ($invoice_notes as $note) { |
|
| 1355 | + $note_time = strtotime($note->comment_date); |
|
| 1356 | 1356 | ?> |
| 1357 | 1357 | <li class="comment wpinv-note"> |
| 1358 | - <p class="wpinv-note-date meta"><?php printf( __( '%2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( $date_format, $note_time ), date_i18n( $time_format, $note_time ), $note_time ); ?></p> |
|
| 1359 | - <div class="wpinv-note-desc description"><?php echo wpautop( wptexturize( $note->comment_content ) ); ?></div> |
|
| 1358 | + <p class="wpinv-note-date meta"><?php printf(__('%2$s at %3$s', 'invoicing'), $note->comment_author, date_i18n($date_format, $note_time), date_i18n($time_format, $note_time), $note_time); ?></p> |
|
| 1359 | + <div class="wpinv-note-desc description"><?php echo wpautop(wptexturize($note->comment_content)); ?></div> |
|
| 1360 | 1360 | </li> |
| 1361 | 1361 | <?php |
| 1362 | 1362 | } |
@@ -1365,21 +1365,21 @@ discard block |
||
| 1365 | 1365 | <?php |
| 1366 | 1366 | } |
| 1367 | 1367 | } |
| 1368 | -add_action( 'wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3 ); |
|
| 1368 | +add_action('wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3); |
|
| 1369 | 1369 | |
| 1370 | 1370 | function wpinv_email_payment_reminders() { |
| 1371 | 1371 | global $wpi_auto_reminder; |
| 1372 | - if ( !wpinv_get_option( 'email_overdue_active' ) ) { |
|
| 1372 | + if (!wpinv_get_option('email_overdue_active')) { |
|
| 1373 | 1373 | return; |
| 1374 | 1374 | } |
| 1375 | 1375 | |
| 1376 | - if ( $reminder_days = wpinv_get_option( 'email_due_reminder_days' ) ) { |
|
| 1377 | - $reminder_days = is_array( $reminder_days ) ? array_values( $reminder_days ) : ''; |
|
| 1376 | + if ($reminder_days = wpinv_get_option('email_due_reminder_days')) { |
|
| 1377 | + $reminder_days = is_array($reminder_days) ? array_values($reminder_days) : ''; |
|
| 1378 | 1378 | |
| 1379 | - if ( empty( $reminder_days ) ) { |
|
| 1379 | + if (empty($reminder_days)) { |
|
| 1380 | 1380 | return; |
| 1381 | 1381 | } |
| 1382 | - $reminder_days = array_unique( array_map( 'absint', $reminder_days ) ); |
|
| 1382 | + $reminder_days = array_unique(array_map('absint', $reminder_days)); |
|
| 1383 | 1383 | |
| 1384 | 1384 | $args = array( |
| 1385 | 1385 | 'post_type' => 'wpi_invoice', |
@@ -1389,7 +1389,7 @@ discard block |
||
| 1389 | 1389 | 'meta_query' => array( |
| 1390 | 1390 | array( |
| 1391 | 1391 | 'key' => '_wpinv_due_date', |
| 1392 | - 'value' => array( '', 'none' ), |
|
| 1392 | + 'value' => array('', 'none'), |
|
| 1393 | 1393 | 'compare' => 'NOT IN', |
| 1394 | 1394 | ) |
| 1395 | 1395 | ), |
@@ -1398,64 +1398,64 @@ discard block |
||
| 1398 | 1398 | 'order' => 'ASC', |
| 1399 | 1399 | ); |
| 1400 | 1400 | |
| 1401 | - $invoices = get_posts( $args ); |
|
| 1401 | + $invoices = get_posts($args); |
|
| 1402 | 1402 | |
| 1403 | - if ( empty( $invoices ) ) { |
|
| 1403 | + if (empty($invoices)) { |
|
| 1404 | 1404 | return; |
| 1405 | 1405 | } |
| 1406 | 1406 | |
| 1407 | - $date_to_send = array(); |
|
| 1407 | + $date_to_send = array(); |
|
| 1408 | 1408 | |
| 1409 | - foreach ( $invoices as $id ) { |
|
| 1410 | - $due_date = get_post_meta( $id, '_wpinv_due_date', true ); |
|
| 1409 | + foreach ($invoices as $id) { |
|
| 1410 | + $due_date = get_post_meta($id, '_wpinv_due_date', true); |
|
| 1411 | 1411 | |
| 1412 | - foreach ( $reminder_days as $key => $days ) { |
|
| 1413 | - if ( $days !== '' ) { |
|
| 1414 | - $date_to_send[$id][] = date_i18n( 'Y-m-d', strtotime( $due_date ) + ( $days * DAY_IN_SECONDS ) ); |
|
| 1412 | + foreach ($reminder_days as $key => $days) { |
|
| 1413 | + if ($days !== '') { |
|
| 1414 | + $date_to_send[$id][] = date_i18n('Y-m-d', strtotime($due_date) + ($days * DAY_IN_SECONDS)); |
|
| 1415 | 1415 | } |
| 1416 | 1416 | } |
| 1417 | 1417 | } |
| 1418 | 1418 | |
| 1419 | - $today = date_i18n( 'Y-m-d' ); |
|
| 1419 | + $today = date_i18n('Y-m-d'); |
|
| 1420 | 1420 | $wpi_auto_reminder = true; |
| 1421 | 1421 | |
| 1422 | - foreach ( $date_to_send as $id => $values ) { |
|
| 1423 | - if ( in_array( $today, $values ) ) { |
|
| 1424 | - $sent = get_post_meta( $id, '_wpinv_reminder_sent', true ); |
|
| 1422 | + foreach ($date_to_send as $id => $values) { |
|
| 1423 | + if (in_array($today, $values)) { |
|
| 1424 | + $sent = get_post_meta($id, '_wpinv_reminder_sent', true); |
|
| 1425 | 1425 | |
| 1426 | - if ( isset( $sent ) && !empty( $sent ) ) { |
|
| 1427 | - if ( !in_array( $today, $sent ) ) { |
|
| 1428 | - do_action( 'wpinv_send_payment_reminder_notification', $id ); |
|
| 1426 | + if (isset($sent) && !empty($sent)) { |
|
| 1427 | + if (!in_array($today, $sent)) { |
|
| 1428 | + do_action('wpinv_send_payment_reminder_notification', $id); |
|
| 1429 | 1429 | } |
| 1430 | 1430 | } else { |
| 1431 | - do_action( 'wpinv_send_payment_reminder_notification', $id ); |
|
| 1431 | + do_action('wpinv_send_payment_reminder_notification', $id); |
|
| 1432 | 1432 | } |
| 1433 | 1433 | } |
| 1434 | 1434 | } |
| 1435 | 1435 | |
| 1436 | - $wpi_auto_reminder = false; |
|
| 1436 | + $wpi_auto_reminder = false; |
|
| 1437 | 1437 | } |
| 1438 | 1438 | } |
| 1439 | 1439 | |
| 1440 | -function wpinv_send_payment_reminder_notification( $invoice_id ) { |
|
| 1440 | +function wpinv_send_payment_reminder_notification($invoice_id) { |
|
| 1441 | 1441 | global $wpinv_email_search, $wpinv_email_replace; |
| 1442 | 1442 | |
| 1443 | 1443 | $email_type = 'overdue'; |
| 1444 | - if ( !wpinv_email_is_enabled( $email_type ) ) { |
|
| 1444 | + if (!wpinv_email_is_enabled($email_type)) { |
|
| 1445 | 1445 | return false; |
| 1446 | 1446 | } |
| 1447 | 1447 | |
| 1448 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 1449 | - if ( empty( $invoice ) ) { |
|
| 1448 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 1449 | + if (empty($invoice)) { |
|
| 1450 | 1450 | return false; |
| 1451 | 1451 | } |
| 1452 | 1452 | |
| 1453 | - if ( !$invoice->needs_payment() ) { |
|
| 1453 | + if (!$invoice->needs_payment()) { |
|
| 1454 | 1454 | return false; |
| 1455 | 1455 | } |
| 1456 | 1456 | |
| 1457 | - $recipient = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice ); |
|
| 1458 | - if ( !is_email( $recipient ) ) { |
|
| 1457 | + $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice); |
|
| 1458 | + if (!is_email($recipient)) { |
|
| 1459 | 1459 | return false; |
| 1460 | 1460 | } |
| 1461 | 1461 | |
@@ -1471,70 +1471,70 @@ discard block |
||
| 1471 | 1471 | $replace = array(); |
| 1472 | 1472 | $replace['full_name'] = $invoice->get_user_full_name(); |
| 1473 | 1473 | $replace['invoice_number'] = $invoice->get_number(); |
| 1474 | - $replace['invoice_due_date']= $invoice->get_due_date( true ); |
|
| 1475 | - $replace['invoice_total'] = $invoice->get_total( true ); |
|
| 1476 | - $replace['invoice_link'] = $invoice->get_view_url( true ); |
|
| 1477 | - $replace['invoice_pay_link']= $invoice->get_checkout_payment_url( false, true ); |
|
| 1478 | - $replace['is_was'] = strtotime( $invoice->get_due_date() ) < strtotime( date_i18n( 'Y-m-d' ) ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ); |
|
| 1474 | + $replace['invoice_due_date'] = $invoice->get_due_date(true); |
|
| 1475 | + $replace['invoice_total'] = $invoice->get_total(true); |
|
| 1476 | + $replace['invoice_link'] = $invoice->get_view_url(true); |
|
| 1477 | + $replace['invoice_pay_link'] = $invoice->get_checkout_payment_url(false, true); |
|
| 1478 | + $replace['is_was'] = strtotime($invoice->get_due_date()) < strtotime(date_i18n('Y-m-d')) ? __('was', 'invoicing') : __('is', 'invoicing'); |
|
| 1479 | 1479 | |
| 1480 | 1480 | $wpinv_email_search = $search; |
| 1481 | 1481 | $wpinv_email_replace = $replace; |
| 1482 | 1482 | |
| 1483 | - $subject = wpinv_email_get_subject( $email_type, $invoice_id, $invoice ); |
|
| 1484 | - $email_heading = wpinv_email_get_heading( $email_type, $invoice_id, $invoice ); |
|
| 1485 | - $headers = wpinv_email_get_headers( $email_type, $invoice_id, $invoice ); |
|
| 1486 | - $attachments = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice ); |
|
| 1483 | + $subject = wpinv_email_get_subject($email_type, $invoice_id, $invoice); |
|
| 1484 | + $email_heading = wpinv_email_get_heading($email_type, $invoice_id, $invoice); |
|
| 1485 | + $headers = wpinv_email_get_headers($email_type, $invoice_id, $invoice); |
|
| 1486 | + $attachments = wpinv_email_get_attachments($email_type, $invoice_id, $invoice); |
|
| 1487 | 1487 | |
| 1488 | - $message_body = wpinv_email_get_content( $email_type, $invoice_id, $invoice ); |
|
| 1488 | + $message_body = wpinv_email_get_content($email_type, $invoice_id, $invoice); |
|
| 1489 | 1489 | |
| 1490 | - $content = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array( |
|
| 1490 | + $content = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array( |
|
| 1491 | 1491 | 'invoice' => $invoice, |
| 1492 | 1492 | 'email_type' => $email_type, |
| 1493 | 1493 | 'email_heading' => $email_heading, |
| 1494 | 1494 | 'sent_to_admin' => false, |
| 1495 | 1495 | 'plain_text' => false, |
| 1496 | 1496 | 'message_body' => $message_body |
| 1497 | - ) ); |
|
| 1497 | + )); |
|
| 1498 | 1498 | |
| 1499 | - $content = wpinv_email_format_text( $content ); |
|
| 1499 | + $content = wpinv_email_format_text($content); |
|
| 1500 | 1500 | |
| 1501 | - $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments ); |
|
| 1502 | - if ( $sent ) { |
|
| 1503 | - do_action( 'wpinv_payment_reminder_sent', $invoice_id, $invoice ); |
|
| 1501 | + $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments); |
|
| 1502 | + if ($sent) { |
|
| 1503 | + do_action('wpinv_payment_reminder_sent', $invoice_id, $invoice); |
|
| 1504 | 1504 | } |
| 1505 | 1505 | |
| 1506 | 1506 | return $sent; |
| 1507 | 1507 | } |
| 1508 | -add_action( 'wpinv_send_payment_reminder_notification', 'wpinv_send_payment_reminder_notification', 10, 1 ); |
|
| 1508 | +add_action('wpinv_send_payment_reminder_notification', 'wpinv_send_payment_reminder_notification', 10, 1); |
|
| 1509 | 1509 | |
| 1510 | -function wpinv_payment_reminder_sent( $invoice_id, $invoice ) { |
|
| 1510 | +function wpinv_payment_reminder_sent($invoice_id, $invoice) { |
|
| 1511 | 1511 | global $wpi_auto_reminder; |
| 1512 | 1512 | |
| 1513 | - $sent = get_post_meta( $invoice_id, '_wpinv_reminder_sent', true ); |
|
| 1513 | + $sent = get_post_meta($invoice_id, '_wpinv_reminder_sent', true); |
|
| 1514 | 1514 | |
| 1515 | - if ( empty( $sent ) ) { |
|
| 1515 | + if (empty($sent)) { |
|
| 1516 | 1516 | $sent = array(); |
| 1517 | 1517 | } |
| 1518 | - $sent[] = date_i18n( 'Y-m-d' ); |
|
| 1518 | + $sent[] = date_i18n('Y-m-d'); |
|
| 1519 | 1519 | |
| 1520 | - update_post_meta( $invoice_id, '_wpinv_reminder_sent', $sent ); |
|
| 1520 | + update_post_meta($invoice_id, '_wpinv_reminder_sent', $sent); |
|
| 1521 | 1521 | |
| 1522 | - if ( $wpi_auto_reminder ) { // Auto reminder note. |
|
| 1523 | - $note = __( 'Manual reminder sent to the user.', 'invoicing' ); |
|
| 1524 | - $invoice->add_note( $note, false, false, true ); |
|
| 1522 | + if ($wpi_auto_reminder) { // Auto reminder note. |
|
| 1523 | + $note = __('Manual reminder sent to the user.', 'invoicing'); |
|
| 1524 | + $invoice->add_note($note, false, false, true); |
|
| 1525 | 1525 | } else { // Menual reminder note. |
| 1526 | - $note = __( 'Manual reminder sent to the user.', 'invoicing' ); |
|
| 1527 | - $invoice->add_note( $note ); |
|
| 1526 | + $note = __('Manual reminder sent to the user.', 'invoicing'); |
|
| 1527 | + $invoice->add_note($note); |
|
| 1528 | 1528 | } |
| 1529 | 1529 | } |
| 1530 | -add_action( 'wpinv_payment_reminder_sent', 'wpinv_payment_reminder_sent', 10, 2 ); |
|
| 1530 | +add_action('wpinv_payment_reminder_sent', 'wpinv_payment_reminder_sent', 10, 2); |
|
| 1531 | 1531 | |
| 1532 | -function wpinv_email_before_note_details( $invoice, $email_type, $sent_to_admin, $customer_note ) { |
|
| 1532 | +function wpinv_email_before_note_details($invoice, $email_type, $sent_to_admin, $customer_note) { |
|
| 1533 | 1533 | if ("wpi_invoice" === $invoice->post_type && !empty($customer_note)) { |
| 1534 | 1534 | $before_note = ''; |
| 1535 | - $before_note .= __( 'Hello, a note has just been added to your invoice:', 'invoicing' ); |
|
| 1536 | - $before_note .= '<blockquote class="wpinv-note">'.wpautop( wptexturize( $customer_note ) ).'</blockquote>'; |
|
| 1537 | - $before_note .= __( 'For your reference, your invoice details are shown below.', 'invoicing' ); |
|
| 1535 | + $before_note .= __('Hello, a note has just been added to your invoice:', 'invoicing'); |
|
| 1536 | + $before_note .= '<blockquote class="wpinv-note">' . wpautop(wptexturize($customer_note)) . '</blockquote>'; |
|
| 1537 | + $before_note .= __('For your reference, your invoice details are shown below.', 'invoicing'); |
|
| 1538 | 1538 | echo $before_note; |
| 1539 | 1539 | } |
| 1540 | 1540 | } |
| 1541 | 1541 | \ No newline at end of file |
@@ -1,72 +1,72 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | // don't load directly |
| 3 | -if ( !defined('ABSPATH') ) |
|
| 3 | +if (!defined('ABSPATH')) |
|
| 4 | 4 | die('-1'); |
| 5 | 5 | |
| 6 | 6 | global $wpinv_euvat; |
| 7 | 7 | |
| 8 | -$sent_to_admin = !empty( $sent_to_admin ) ? true : false; |
|
| 9 | -if ( $sent_to_admin ) { |
|
| 10 | - $invoice_url = get_edit_post_link( $invoice->ID ); |
|
| 8 | +$sent_to_admin = !empty($sent_to_admin) ? true : false; |
|
| 9 | +if ($sent_to_admin) { |
|
| 10 | + $invoice_url = get_edit_post_link($invoice->ID); |
|
| 11 | 11 | } else { |
| 12 | - $secret = !empty( $email_type ) && $email_type == 'user_invoice' ? true : false; |
|
| 13 | - $invoice_url = $invoice->get_view_url( $secret ); |
|
| 12 | + $secret = !empty($email_type) && $email_type == 'user_invoice' ? true : false; |
|
| 13 | + $invoice_url = $invoice->get_view_url($secret); |
|
| 14 | 14 | } |
| 15 | 15 | $use_taxes = wpinv_use_taxes(); |
| 16 | 16 | $vat_name = $wpinv_euvat->get_vat_name(); |
| 17 | 17 | |
| 18 | -do_action( 'wpinv_email_before_invoice_details', $invoice, $sent_to_admin ); ?> |
|
| 18 | +do_action('wpinv_email_before_invoice_details', $invoice, $sent_to_admin); ?> |
|
| 19 | 19 | <div id="wpinv-email-details"> |
| 20 | - <h3 class="wpinv-details-t"><?php echo apply_filters( 'wpinv_email_details_title', __( 'Invoice Details', 'invoicing' ) ); ?></h3> |
|
| 20 | + <h3 class="wpinv-details-t"><?php echo apply_filters('wpinv_email_details_title', __('Invoice Details', 'invoicing')); ?></h3> |
|
| 21 | 21 | <table class="table table-bordered table-sm"> |
| 22 | - <?php if ( $invoice_number = $invoice->get_number() ) { ?> |
|
| 22 | + <?php if ($invoice_number = $invoice->get_number()) { ?> |
|
| 23 | 23 | <tr> |
| 24 | - <td><?php echo apply_filters( 'wpinv_email_details_number', __( 'Invoice Number', 'invoicing' ), $invoice ); ?></td> |
|
| 25 | - <td><a href="<?php echo esc_url( $invoice_url ) ;?>"><?php echo $invoice_number; ?></a></td> |
|
| 24 | + <td><?php echo apply_filters('wpinv_email_details_number', __('Invoice Number', 'invoicing'), $invoice); ?></td> |
|
| 25 | + <td><a href="<?php echo esc_url($invoice_url); ?>"><?php echo $invoice_number; ?></a></td> |
|
| 26 | 26 | </tr> |
| 27 | 27 | <?php } ?> |
| 28 | 28 | <tr> |
| 29 | - <td><?php echo apply_filters( 'wpinv_email_details_status', __( 'Invoice Status', 'invoicing' ), $invoice ); ?></td> |
|
| 30 | - <td><?php echo $invoice->get_status( true ); ?></td> |
|
| 29 | + <td><?php echo apply_filters('wpinv_email_details_status', __('Invoice Status', 'invoicing'), $invoice); ?></td> |
|
| 30 | + <td><?php echo $invoice->get_status(true); ?></td> |
|
| 31 | 31 | </tr> |
| 32 | - <?php if ( $invoice->is_renewal() ) { ?> |
|
| 32 | + <?php if ($invoice->is_renewal()) { ?> |
|
| 33 | 33 | <tr> |
| 34 | - <td><?php _e( 'Parent Invoice', 'invoicing' ); ?></td> |
|
| 35 | - <td><?php echo wpinv_invoice_link( $invoice->parent_invoice ); ?></td> |
|
| 34 | + <td><?php _e('Parent Invoice', 'invoicing'); ?></td> |
|
| 35 | + <td><?php echo wpinv_invoice_link($invoice->parent_invoice); ?></td> |
|
| 36 | 36 | </tr> |
| 37 | 37 | <?php } ?> |
| 38 | 38 | <tr> |
| 39 | - <td><?php _e( 'Payment Method', 'invoicing' ); ?></td> |
|
| 39 | + <td><?php _e('Payment Method', 'invoicing'); ?></td> |
|
| 40 | 40 | <td><?php echo $invoice->get_gateway_title(); ?></td> |
| 41 | 41 | </tr> |
| 42 | - <?php if ( $invoice_date = $invoice->get_invoice_date( false ) ) { ?> |
|
| 42 | + <?php if ($invoice_date = $invoice->get_invoice_date(false)) { ?> |
|
| 43 | 43 | <tr> |
| 44 | - <td><?php echo apply_filters( 'wpinv_email_details_date', __( 'Invoice Date', 'invoicing' ), $invoice ); ?></td> |
|
| 45 | - <td><?php echo wp_sprintf( '<time datetime="%s">%s</time>', date_i18n( 'c', strtotime( $invoice_date ) ), $invoice->get_invoice_date() ); ?></td> |
|
| 44 | + <td><?php echo apply_filters('wpinv_email_details_date', __('Invoice Date', 'invoicing'), $invoice); ?></td> |
|
| 45 | + <td><?php echo wp_sprintf('<time datetime="%s">%s</time>', date_i18n('c', strtotime($invoice_date)), $invoice->get_invoice_date()); ?></td> |
|
| 46 | 46 | </tr> |
| 47 | 47 | <?php } ?> |
| 48 | - <?php if ( wpinv_get_option( 'overdue_active' ) && $invoice->needs_payment() && ( $due_date = $invoice->get_due_date() ) ) { ?> |
|
| 48 | + <?php if (wpinv_get_option('overdue_active') && $invoice->needs_payment() && ($due_date = $invoice->get_due_date())) { ?> |
|
| 49 | 49 | <tr> |
| 50 | - <td><?php _e( 'Due Date', 'invoicing' ); ?></td> |
|
| 51 | - <td><?php echo wp_sprintf( '<time datetime="%s">%s</time>', date_i18n( 'c', strtotime( $due_date ) ), $invoice->get_due_date( true ) ); ?></td> |
|
| 50 | + <td><?php _e('Due Date', 'invoicing'); ?></td> |
|
| 51 | + <td><?php echo wp_sprintf('<time datetime="%s">%s</time>', date_i18n('c', strtotime($due_date)), $invoice->get_due_date(true)); ?></td> |
|
| 52 | 52 | </tr> |
| 53 | 53 | <?php } ?> |
| 54 | - <?php if ( empty( $sent_to_admin ) && $owner_vat_number = $wpinv_euvat->get_vat_number() ) { ?> |
|
| 54 | + <?php if (empty($sent_to_admin) && $owner_vat_number = $wpinv_euvat->get_vat_number()) { ?> |
|
| 55 | 55 | <tr> |
| 56 | - <td><?php echo wp_sprintf( __( 'Owner %s Number', 'invoicing' ), $vat_name ); ?></td> |
|
| 56 | + <td><?php echo wp_sprintf(__('Owner %s Number', 'invoicing'), $vat_name); ?></td> |
|
| 57 | 57 | <td><?php echo $owner_vat_number; ?></td> |
| 58 | 58 | </tr> |
| 59 | 59 | <?php } ?> |
| 60 | - <?php if ( $use_taxes && $user_vat_number = $invoice->vat_number ) { ?> |
|
| 60 | + <?php if ($use_taxes && $user_vat_number = $invoice->vat_number) { ?> |
|
| 61 | 61 | <tr> |
| 62 | - <td><?php echo wp_sprintf( __( 'Invoice %s Number', 'invoicing' ), $vat_name ); ?></td> |
|
| 62 | + <td><?php echo wp_sprintf(__('Invoice %s Number', 'invoicing'), $vat_name); ?></td> |
|
| 63 | 63 | <td><?php echo $user_vat_number; ?></td> |
| 64 | 64 | </tr> |
| 65 | 65 | <?php } ?> |
| 66 | 66 | <tr class="table-active"> |
| 67 | - <td><strong><?php _e( 'Total Amount', 'invoicing' ) ?></strong></td> |
|
| 68 | - <td><strong><?php echo $invoice->get_total( true ); ?></strong></td> |
|
| 67 | + <td><strong><?php _e('Total Amount', 'invoicing') ?></strong></td> |
|
| 68 | + <td><strong><?php echo $invoice->get_total(true); ?></strong></td> |
|
| 69 | 69 | </tr> |
| 70 | 70 | </table> |
| 71 | 71 | </div> |
| 72 | -<?php do_action( 'wpinv_email_after_invoice_details', $invoice, $sent_to_admin ); ?> |
|
| 73 | 72 | \ No newline at end of file |
| 73 | +<?php do_action('wpinv_email_after_invoice_details', $invoice, $sent_to_admin); ?> |
|
| 74 | 74 | \ No newline at end of file |