@@ -1,66 +1,66 @@ discard block  | 
                                                    ||
| 1 | 1 | <?php  | 
                                                        
| 2 | 2 | // MUST have WordPress.  | 
                                                        
| 3 | -if ( !defined( 'WPINC' ) ) { | 
                                                        |
| 4 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );  | 
                                                        |
| 3 | +if (!defined('WPINC')) { | 
                                                        |
| 4 | +    exit('Do NOT access this file directly: ' . basename(__FILE__)); | 
                                                        |
| 5 | 5 | }  | 
                                                        
| 6 | 6 | |
| 7 | -add_action( 'admin_menu', 'wpinv_add_options_link', 10 );  | 
                                                        |
| 7 | +add_action('admin_menu', 'wpinv_add_options_link', 10); | 
                                                        |
| 8 | 8 |  function wpinv_add_options_link() { | 
                                                        
| 9 | 9 | global $menu;  | 
                                                        
| 10 | 10 | |
| 11 | -    if ( current_user_can( 'manage_options' ) ) { | 
                                                        |
| 12 | - $menu[] = array( '', 'read', 'separator-wpinv', '', 'wp-menu-separator wpinv' );  | 
                                                        |
| 11 | +    if (current_user_can('manage_options')) { | 
                                                        |
| 12 | +        $menu[] = array('', 'read', 'separator-wpinv', '', 'wp-menu-separator wpinv'); | 
                                                        |
| 13 | 13 | }  | 
                                                        
| 14 | 14 | |
| 15 | - $wpi_invoice = get_post_type_object( 'wpi_invoice' );  | 
                                                        |
| 15 | +    $wpi_invoice = get_post_type_object('wpi_invoice'); | 
                                                        |
| 16 | 16 | |
| 17 | - add_menu_page( __( 'Invoicing', 'invoicing' ), __( 'Invoicing', 'invoicing' ), 'manage_options', 'wpinv', null, $wpi_invoice->menu_icon, '54.123460' );  | 
                                                        |
| 17 | +    add_menu_page(__('Invoicing', 'invoicing'), __('Invoicing', 'invoicing'), 'manage_options', 'wpinv', null, $wpi_invoice->menu_icon, '54.123460'); | 
                                                        |
| 18 | 18 | |
| 19 | - $wpi_settings_page = add_submenu_page( 'wpinv', __( 'Invoice Settings', 'invoicing' ), __( 'Settings', 'invoicing' ), 'manage_options', 'wpinv-settings', 'wpinv_options_page' );  | 
                                                        |
| 19 | +    $wpi_settings_page = add_submenu_page('wpinv', __('Invoice Settings', 'invoicing'), __('Settings', 'invoicing'), 'manage_options', 'wpinv-settings', 'wpinv_options_page'); | 
                                                        |
| 20 | 20 | }  | 
                                                        
| 21 | 21 | |
| 22 | -add_action( 'admin_menu', 'wpinv_remove_admin_submenus', 999 );  | 
                                                        |
| 22 | +add_action('admin_menu', 'wpinv_remove_admin_submenus', 999); | 
                                                        |
| 23 | 23 |  function wpinv_remove_admin_submenus() { | 
                                                        
| 24 | - remove_submenu_page( 'edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice' );  | 
                                                        |
| 24 | +    remove_submenu_page('edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice'); | 
                                                        |
| 25 | 25 | }  | 
                                                        
| 26 | 26 | |
| 27 | -add_filter( 'manage_wpi_discount_posts_columns', 'wpinv_discount_columns' );  | 
                                                        |
| 28 | -function wpinv_discount_columns( $existing_columns ) { | 
                                                        |
| 27 | +add_filter('manage_wpi_discount_posts_columns', 'wpinv_discount_columns'); | 
                                                        |
| 28 | +function wpinv_discount_columns($existing_columns) { | 
                                                        |
| 29 | 29 | $columns = array();  | 
                                                        
| 30 | 30 | $columns['cb'] = $existing_columns['cb'];  | 
                                                        
| 31 | - $columns['name'] = __( 'Name', 'invoicing' );  | 
                                                        |
| 32 | - $columns['code'] = __( 'Code', 'invoicing' );  | 
                                                        |
| 33 | - $columns['amount'] = __( 'Amount', 'invoicing' );  | 
                                                        |
| 34 | - $columns['usage'] = __( 'Usage / Limit', 'invoicing' );  | 
                                                        |
| 35 | - $columns['expiry_date'] = __( 'Expiry Date', 'invoicing' );  | 
                                                        |
| 36 | - $columns['status'] = __( 'Status', 'invoicing' );  | 
                                                        |
| 31 | +    $columns['name']        = __('Name', 'invoicing'); | 
                                                        |
| 32 | +    $columns['code']        = __('Code', 'invoicing'); | 
                                                        |
| 33 | +    $columns['amount']      = __('Amount', 'invoicing'); | 
                                                        |
| 34 | +    $columns['usage']       = __('Usage / Limit', 'invoicing'); | 
                                                        |
| 35 | +    $columns['expiry_date'] = __('Expiry Date', 'invoicing'); | 
                                                        |
| 36 | +    $columns['status']      = __('Status', 'invoicing'); | 
                                                        |
| 37 | 37 | |
| 38 | 38 | return $columns;  | 
                                                        
| 39 | 39 | }  | 
                                                        
| 40 | 40 | |
| 41 | -add_action( 'manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column' );  | 
                                                        |
| 42 | -function wpinv_discount_custom_column( $column ) { | 
                                                        |
| 41 | +add_action('manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column'); | 
                                                        |
| 42 | +function wpinv_discount_custom_column($column) { | 
                                                        |
| 43 | 43 | global $post;  | 
                                                        
| 44 | 44 | |
| 45 | 45 | $discount = $post;  | 
                                                        
| 46 | 46 | |
| 47 | -    switch ( $column ) { | 
                                                        |
| 47 | +    switch ($column) { | 
                                                        |
| 48 | 48 | case 'name' :  | 
                                                        
| 49 | - echo get_the_title( $discount->ID );  | 
                                                        |
| 49 | + echo get_the_title($discount->ID);  | 
                                                        |
| 50 | 50 | break;  | 
                                                        
| 51 | 51 | case 'code' :  | 
                                                        
| 52 | - echo wpinv_get_discount_code( $discount->ID );  | 
                                                        |
| 52 | + echo wpinv_get_discount_code($discount->ID);  | 
                                                        |
| 53 | 53 | break;  | 
                                                        
| 54 | 54 | case 'amount' :  | 
                                                        
| 55 | - echo wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) );  | 
                                                        |
| 55 | + echo wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID));  | 
                                                        |
| 56 | 56 | break;  | 
                                                        
| 57 | 57 | case 'usage_limit' :  | 
                                                        
| 58 | - echo wpinv_get_discount_uses( $discount->ID );  | 
                                                        |
| 58 | + echo wpinv_get_discount_uses($discount->ID);  | 
                                                        |
| 59 | 59 | break;  | 
                                                        
| 60 | 60 | case 'usage' :  | 
                                                        
| 61 | - $usage = wpinv_get_discount_uses( $discount->ID ) . ' / ';  | 
                                                        |
| 62 | -            if ( wpinv_get_discount_max_uses( $discount->ID ) ) { | 
                                                        |
| 63 | - $usage .= wpinv_get_discount_max_uses( $discount->ID );  | 
                                                        |
| 61 | + $usage = wpinv_get_discount_uses($discount->ID) . ' / ';  | 
                                                        |
| 62 | +            if (wpinv_get_discount_max_uses($discount->ID)) { | 
                                                        |
| 63 | + $usage .= wpinv_get_discount_max_uses($discount->ID);  | 
                                                        |
| 64 | 64 |              } else { | 
                                                        
| 65 | 65 | $usage .= ' ∞';  | 
                                                        
| 66 | 66 | }  | 
                                                        
@@ -68,162 +68,162 @@ discard block  | 
                                                    ||
| 68 | 68 | echo $usage;  | 
                                                        
| 69 | 69 | break;  | 
                                                        
| 70 | 70 | case 'expiry_date' :  | 
                                                        
| 71 | -            if ( wpinv_get_discount_expiration( $discount->ID ) ) { | 
                                                        |
| 72 | - $expiration = date_i18n( get_option( 'date_format' ), strtotime( wpinv_get_discount_expiration( $discount->ID ) ) );  | 
                                                        |
| 71 | +            if (wpinv_get_discount_expiration($discount->ID)) { | 
                                                        |
| 72 | +                $expiration = date_i18n(get_option('date_format'), strtotime(wpinv_get_discount_expiration($discount->ID))); | 
                                                        |
| 73 | 73 |              } else { | 
                                                        
| 74 | - $expiration = __( 'Never', 'invoicing' );  | 
                                                        |
| 74 | +                $expiration = __('Never', 'invoicing'); | 
                                                        |
| 75 | 75 | }  | 
                                                        
| 76 | 76 | |
| 77 | 77 | echo $expiration;  | 
                                                        
| 78 | 78 | break;  | 
                                                        
| 79 | 79 | case 'description' :  | 
                                                        
| 80 | - echo wp_kses_post( $post->post_excerpt );  | 
                                                        |
| 80 | + echo wp_kses_post($post->post_excerpt);  | 
                                                        |
| 81 | 81 | break;  | 
                                                        
| 82 | 82 | case 'status' :  | 
                                                        
| 83 | - $status = wpinv_is_discount_expired( $discount->ID ) ? 'expired' : $discount->post_status;  | 
                                                        |
| 83 | + $status = wpinv_is_discount_expired($discount->ID) ? 'expired' : $discount->post_status;  | 
                                                        |
| 84 | 84 | |
| 85 | - echo wpinv_discount_status( $status );  | 
                                                        |
| 85 | + echo wpinv_discount_status($status);  | 
                                                        |
| 86 | 86 | break;  | 
                                                        
| 87 | 87 | }  | 
                                                        
| 88 | 88 | }  | 
                                                        
| 89 | 89 | |
| 90 | -add_filter( 'post_row_actions', 'wpinv_post_row_actions', 9999, 2 );  | 
                                                        |
| 91 | -function wpinv_post_row_actions( $actions, $post ) { | 
                                                        |
| 92 | - $post_type = !empty( $post->post_type ) ? $post->post_type : '';  | 
                                                        |
| 90 | +add_filter('post_row_actions', 'wpinv_post_row_actions', 9999, 2); | 
                                                        |
| 91 | +function wpinv_post_row_actions($actions, $post) { | 
                                                        |
| 92 | + $post_type = !empty($post->post_type) ? $post->post_type : '';  | 
                                                        |
| 93 | 93 | |
| 94 | -    if ( $post_type == 'wpi_invoice' ) { | 
                                                        |
| 94 | +    if ($post_type == 'wpi_invoice') { | 
                                                        |
| 95 | 95 | $actions = array();  | 
                                                        
| 96 | 96 | }  | 
                                                        
| 97 | 97 | |
| 98 | -    if ( $post_type == 'wpi_discount' ) { | 
                                                        |
| 99 | - $actions = wpinv_discount_row_actions( $post, $actions );  | 
                                                        |
| 98 | +    if ($post_type == 'wpi_discount') { | 
                                                        |
| 99 | + $actions = wpinv_discount_row_actions($post, $actions);  | 
                                                        |
| 100 | 100 | }  | 
                                                        
| 101 | 101 | |
| 102 | 102 | return $actions;  | 
                                                        
| 103 | 103 | }  | 
                                                        
| 104 | 104 | |
| 105 | -function wpinv_discount_row_actions( $discount, $row_actions ) { | 
                                                        |
| 106 | - $row_actions = array();  | 
                                                        |
| 107 | - $edit_link = get_edit_post_link( $discount->ID );  | 
                                                        |
| 108 | - $row_actions['edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'invoicing' ) . '</a>';  | 
                                                        |
| 105 | +function wpinv_discount_row_actions($discount, $row_actions) { | 
                                                        |
| 106 | + $row_actions = array();  | 
                                                        |
| 107 | + $edit_link = get_edit_post_link($discount->ID);  | 
                                                        |
| 108 | +    $row_actions['edit'] = '<a href="' . esc_url($edit_link) . '">' . __('Edit', 'invoicing') . '</a>'; | 
                                                        |
| 109 | 109 | |
| 110 | -    if( in_array( strtolower( $discount->post_status ),  array(  'publish' ) ) ) { | 
                                                        |
| 111 | - $row_actions['deactivate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'deactivate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Deactivate', 'invoicing' ) . '</a>';  | 
                                                        |
| 112 | -    } elseif( in_array( strtolower( $discount->post_status ),  array( 'pending', 'draft' ) ) ) { | 
                                                        |
| 113 | - $row_actions['activate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'activate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Activate', 'invoicing' ) . '</a>';  | 
                                                        |
| 110 | +    if (in_array(strtolower($discount->post_status), array('publish'))) { | 
                                                        |
| 111 | +        $row_actions['deactivate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'deactivate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Deactivate', 'invoicing') . '</a>'; | 
                                                        |
| 112 | +    } elseif (in_array(strtolower($discount->post_status), array('pending', 'draft'))) { | 
                                                        |
| 113 | +        $row_actions['activate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'activate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Activate', 'invoicing') . '</a>'; | 
                                                        |
| 114 | 114 | }  | 
                                                        
| 115 | 115 | |
| 116 | -    if ( wpinv_get_discount_uses( $discount->ID ) > 0 ) { | 
                                                        |
| 117 | -        if ( isset( $row_actions['delete'] ) ) { | 
                                                        |
| 118 | - unset( $row_actions['delete'] ); // Don't delete used discounts.  | 
                                                        |
| 116 | +    if (wpinv_get_discount_uses($discount->ID) > 0) { | 
                                                        |
| 117 | +        if (isset($row_actions['delete'])) { | 
                                                        |
| 118 | + unset($row_actions['delete']); // Don't delete used discounts.  | 
                                                        |
| 119 | 119 | }  | 
                                                        
| 120 | 120 |      } else { | 
                                                        
| 121 | - $row_actions['delete'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'delete_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Delete', 'invoicing' ) . '</a>';  | 
                                                        |
| 121 | +        $row_actions['delete'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'delete_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Delete', 'invoicing') . '</a>'; | 
                                                        |
| 122 | 122 | }  | 
                                                        
| 123 | 123 | |
| 124 | 124 | |
| 125 | - $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount );  | 
                                                        |
| 125 | +    $row_actions = apply_filters('wpinv_discount_row_actions', $row_actions, $discount); | 
                                                        |
| 126 | 126 | |
| 127 | 127 | return $row_actions;  | 
                                                        
| 128 | 128 | }  | 
                                                        
| 129 | 129 | |
| 130 | -add_filter( 'list_table_primary_column', 'wpinv_table_primary_column', 10, 2 );  | 
                                                        |
| 131 | -function wpinv_table_primary_column( $default, $screen_id ) { | 
                                                        |
| 132 | -    if ( 'edit-wpi_invoice' === $screen_id ) { | 
                                                        |
| 130 | +add_filter('list_table_primary_column', 'wpinv_table_primary_column', 10, 2); | 
                                                        |
| 131 | +function wpinv_table_primary_column($default, $screen_id) { | 
                                                        |
| 132 | +    if ('edit-wpi_invoice' === $screen_id) { | 
                                                        |
| 133 | 133 | return 'name';  | 
                                                        
| 134 | 134 | }  | 
                                                        
| 135 | 135 | |
| 136 | 136 | return $default;  | 
                                                        
| 137 | 137 | }  | 
                                                        
| 138 | 138 | |
| 139 | -function wpinv_discount_bulk_actions( $actions, $display = false ) {     | 
                                                        |
| 140 | -    if ( !$display ) { | 
                                                        |
| 139 | +function wpinv_discount_bulk_actions($actions, $display = false) {     | 
                                                        |
| 140 | +    if (!$display) { | 
                                                        |
| 141 | 141 | return array();  | 
                                                        
| 142 | 142 | }  | 
                                                        
| 143 | 143 | |
| 144 | 144 | $actions = array(  | 
                                                        
| 145 | - 'activate' => __( 'Activate', 'invoicing' ),  | 
                                                        |
| 146 | - 'deactivate' => __( 'Deactivate', 'invoicing' ),  | 
                                                        |
| 147 | - 'delete' => __( 'Delete', 'invoicing' ),  | 
                                                        |
| 145 | +        'activate'   => __('Activate', 'invoicing'), | 
                                                        |
| 146 | +        'deactivate' => __('Deactivate', 'invoicing'), | 
                                                        |
| 147 | +        'delete'     => __('Delete', 'invoicing'), | 
                                                        |
| 148 | 148 | );  | 
                                                        
| 149 | 149 | $two = '';  | 
                                                        
| 150 | 150 | $which = 'top';  | 
                                                        
| 151 | 151 | echo '</div><div class="alignleft actions bulkactions">';  | 
                                                        
| 152 | - echo '<label for="bulk-action-selector-' . esc_attr( $which ) . '" class="screen-reader-text">' . __( 'Select bulk action' ) . '</label>';  | 
                                                        |
| 153 | - echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr( $which ) . "\">";  | 
                                                        |
| 154 | - echo '<option value="-1">' . __( 'Bulk Actions' ) . "</option>";  | 
                                                        |
| 152 | +    echo '<label for="bulk-action-selector-' . esc_attr($which) . '" class="screen-reader-text">' . __('Select bulk action') . '</label>'; | 
                                                        |
| 153 | + echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr($which) . "\">";  | 
                                                        |
| 154 | +    echo '<option value="-1">' . __('Bulk Actions') . "</option>"; | 
                                                        |
| 155 | 155 | |
| 156 | -    foreach ( $actions as $name => $title ) { | 
                                                        |
| 156 | +    foreach ($actions as $name => $title) { | 
                                                        |
| 157 | 157 | $class = 'edit' === $name ? ' class="hide-if-no-js"' : '';  | 
                                                        
| 158 | 158 | |
| 159 | 159 | echo "" . '<option value="' . $name . '"' . $class . '>' . $title . "</option>";  | 
                                                        
| 160 | 160 | }  | 
                                                        
| 161 | 161 | echo "</select>";  | 
                                                        
| 162 | 162 | |
| 163 | - submit_button( __( 'Apply' ), 'action', '', false, array( 'id' => "doaction$two" ) );  | 
                                                        |
| 163 | +    submit_button(__('Apply'), 'action', '', false, array('id' => "doaction$two")); | 
                                                        |
| 164 | 164 | |
| 165 | 165 | echo '</div><div class="alignleft actions">';  | 
                                                        
| 166 | 166 | }  | 
                                                        
| 167 | -add_filter( 'bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10 );  | 
                                                        |
| 167 | +add_filter('bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10); | 
                                                        |
| 168 | 168 | |
| 169 | -function wpinv_disable_months_dropdown( $disable, $post_type ) { | 
                                                        |
| 170 | -    if ( $post_type == 'wpi_discount' ) { | 
                                                        |
| 169 | +function wpinv_disable_months_dropdown($disable, $post_type) { | 
                                                        |
| 170 | +    if ($post_type == 'wpi_discount') { | 
                                                        |
| 171 | 171 | $disable = true;  | 
                                                        
| 172 | 172 | }  | 
                                                        
| 173 | 173 | |
| 174 | 174 | return $disable;  | 
                                                        
| 175 | 175 | }  | 
                                                        
| 176 | -add_filter( 'disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2 );  | 
                                                        |
| 176 | +add_filter('disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2); | 
                                                        |
| 177 | 177 | |
| 178 | 178 |  function wpinv_restrict_manage_posts() { | 
                                                        
| 179 | 179 | global $typenow;  | 
                                                        
| 180 | 180 | |
| 181 | -    if( 'wpi_discount' == $typenow ) { | 
                                                        |
| 181 | +    if ('wpi_discount' == $typenow) { | 
                                                        |
| 182 | 182 | wpinv_discount_filters();  | 
                                                        
| 183 | 183 | }  | 
                                                        
| 184 | 184 | }  | 
                                                        
| 185 | -add_action( 'restrict_manage_posts', 'wpinv_restrict_manage_posts', 10 );  | 
                                                        |
| 185 | +add_action('restrict_manage_posts', 'wpinv_restrict_manage_posts', 10); | 
                                                        |
| 186 | 186 | |
| 187 | 187 |  function wpinv_discount_filters() { | 
                                                        
| 188 | - echo wpinv_discount_bulk_actions( array(), true );  | 
                                                        |
| 188 | + echo wpinv_discount_bulk_actions(array(), true);  | 
                                                        |
| 189 | 189 | |
| 190 | 190 | ?>  | 
                                                        
| 191 | 191 | <select name="discount_type" id="dropdown_wpinv_discount_type">  | 
                                                        
| 192 | - <option value=""><?php _e( 'Show all types', 'invoicing' ); ?></option>  | 
                                                        |
| 192 | +        <option value=""><?php _e('Show all types', 'invoicing'); ?></option> | 
                                                        |
| 193 | 193 | <?php  | 
                                                        
| 194 | 194 | $types = wpinv_get_discount_types();  | 
                                                        
| 195 | 195 | |
| 196 | -            foreach ( $types as $name => $type ) { | 
                                                        |
| 197 | - echo '<option value="' . esc_attr( $name ) . '"';  | 
                                                        |
| 196 | +            foreach ($types as $name => $type) { | 
                                                        |
| 197 | + echo '<option value="' . esc_attr($name) . '"';  | 
                                                        |
| 198 | 198 | |
| 199 | - if ( isset( $_GET['discount_type'] ) )  | 
                                                        |
| 200 | - selected( $name, $_GET['discount_type'] );  | 
                                                        |
| 199 | + if (isset($_GET['discount_type']))  | 
                                                        |
| 200 | + selected($name, $_GET['discount_type']);  | 
                                                        |
| 201 | 201 | |
| 202 | - echo '>' . esc_html__( $type, 'invoicing' ) . '</option>';  | 
                                                        |
| 202 | + echo '>' . esc_html__($type, 'invoicing') . '</option>';  | 
                                                        |
| 203 | 203 | }  | 
                                                        
| 204 | 204 | ?>  | 
                                                        
| 205 | 205 | </select>  | 
                                                        
| 206 | 206 | <?php  | 
                                                        
| 207 | 207 | }  | 
                                                        
| 208 | 208 | |
| 209 | -function wpinv_request( $vars ) { | 
                                                        |
| 209 | +function wpinv_request($vars) { | 
                                                        |
| 210 | 210 | global $typenow, $wp_query, $wp_post_statuses;  | 
                                                        
| 211 | 211 | |
| 212 | -    if ( 'wpi_invoice' === $typenow or 'wpi_quote' === $typenow ) { | 
                                                        |
| 213 | -        if ( !isset( $vars['post_status'] ) ) { | 
                                                        |
| 212 | +    if ('wpi_invoice' === $typenow or 'wpi_quote' === $typenow) { | 
                                                        |
| 213 | +        if (!isset($vars['post_status'])) { | 
                                                        |
| 214 | 214 | $post_statuses = wpinv_get_invoice_statuses();  | 
                                                        
| 215 | 215 | |
| 216 | -            foreach ( $post_statuses as $status => $value ) { | 
                                                        |
| 217 | -                if ( isset( $wp_post_statuses[ $status ] ) && false === $wp_post_statuses[ $status ]->show_in_admin_all_list ) { | 
                                                        |
| 218 | - unset( $post_statuses[ $status ] );  | 
                                                        |
| 216 | +            foreach ($post_statuses as $status => $value) { | 
                                                        |
| 217 | +                if (isset($wp_post_statuses[$status]) && false === $wp_post_statuses[$status]->show_in_admin_all_list) { | 
                                                        |
| 218 | + unset($post_statuses[$status]);  | 
                                                        |
| 219 | 219 | }  | 
                                                        
| 220 | 220 | }  | 
                                                        
| 221 | 221 | |
| 222 | - $vars['post_status'] = array_keys( $post_statuses );  | 
                                                        |
| 222 | + $vars['post_status'] = array_keys($post_statuses);  | 
                                                        |
| 223 | 223 | }  | 
                                                        
| 224 | 224 | |
| 225 | -        if ( isset( $vars['orderby'] ) ) { | 
                                                        |
| 226 | -            if ( 'amount' == $vars['orderby'] ) { | 
                                                        |
| 225 | +        if (isset($vars['orderby'])) { | 
                                                        |
| 226 | +            if ('amount' == $vars['orderby']) { | 
                                                        |
| 227 | 227 | $vars = array_merge(  | 
                                                        
| 228 | 228 | $vars,  | 
                                                        
| 229 | 229 | array(  | 
                                                        
@@ -231,7 +231,7 @@ discard block  | 
                                                    ||
| 231 | 231 | 'orderby' => 'meta_value_num'  | 
                                                        
| 232 | 232 | )  | 
                                                        
| 233 | 233 | );  | 
                                                        
| 234 | -            } else if ( 'customer' == $vars['orderby'] ) { | 
                                                        |
| 234 | +            } else if ('customer' == $vars['orderby']) { | 
                                                        |
| 235 | 235 | $vars = array_merge(  | 
                                                        
| 236 | 236 | $vars,  | 
                                                        
| 237 | 237 | array(  | 
                                                        
@@ -241,9 +241,9 @@ discard block  | 
                                                    ||
| 241 | 241 | );  | 
                                                        
| 242 | 242 | }  | 
                                                        
| 243 | 243 | }  | 
                                                        
| 244 | -    } else if ( 'wpi_item' == $typenow ) { | 
                                                        |
| 244 | +    } else if ('wpi_item' == $typenow) { | 
                                                        |
| 245 | 245 | // Check if 'orderby' is set to "price"  | 
                                                        
| 246 | -        if ( isset( $vars['orderby'] ) && 'price' == $vars['orderby'] ) { | 
                                                        |
| 246 | +        if (isset($vars['orderby']) && 'price' == $vars['orderby']) { | 
                                                        |
| 247 | 247 | $vars = array_merge(  | 
                                                        
| 248 | 248 | $vars,  | 
                                                        
| 249 | 249 | array(  | 
                                                        
@@ -254,7 +254,7 @@ discard block  | 
                                                    ||
| 254 | 254 | }  | 
                                                        
| 255 | 255 | |
| 256 | 256 | // Check if "orderby" is set to "vat_rule"  | 
                                                        
| 257 | -        if ( isset( $vars['orderby'] ) && 'vat_rule' == $vars['orderby'] ) { | 
                                                        |
| 257 | +        if (isset($vars['orderby']) && 'vat_rule' == $vars['orderby']) { | 
                                                        |
| 258 | 258 | $vars = array_merge(  | 
                                                        
| 259 | 259 | $vars,  | 
                                                        
| 260 | 260 | array(  | 
                                                        
@@ -265,7 +265,7 @@ discard block  | 
                                                    ||
| 265 | 265 | }  | 
                                                        
| 266 | 266 | |
| 267 | 267 | // Check if "orderby" is set to "vat_class"  | 
                                                        
| 268 | -        if ( isset( $vars['orderby'] ) && 'vat_class' == $vars['orderby'] ) { | 
                                                        |
| 268 | +        if (isset($vars['orderby']) && 'vat_class' == $vars['orderby']) { | 
                                                        |
| 269 | 269 | $vars = array_merge(  | 
                                                        
| 270 | 270 | $vars,  | 
                                                        
| 271 | 271 | array(  | 
                                                        
@@ -276,7 +276,7 @@ discard block  | 
                                                    ||
| 276 | 276 | }  | 
                                                        
| 277 | 277 | |
| 278 | 278 | // Check if "orderby" is set to "type"  | 
                                                        
| 279 | -        if ( isset( $vars['orderby'] ) && 'type' == $vars['orderby'] ) { | 
                                                        |
| 279 | +        if (isset($vars['orderby']) && 'type' == $vars['orderby']) { | 
                                                        |
| 280 | 280 | $vars = array_merge(  | 
                                                        
| 281 | 281 | $vars,  | 
                                                        
| 282 | 282 | array(  | 
                                                        
@@ -287,7 +287,7 @@ discard block  | 
                                                    ||
| 287 | 287 | }  | 
                                                        
| 288 | 288 | |
| 289 | 289 | // Check if "orderby" is set to "recurring"  | 
                                                        
| 290 | -        if ( isset( $vars['orderby'] ) && 'recurring' == $vars['orderby'] ) { | 
                                                        |
| 290 | +        if (isset($vars['orderby']) && 'recurring' == $vars['orderby']) { | 
                                                        |
| 291 | 291 | $vars = array_merge(  | 
                                                        
| 292 | 292 | $vars,  | 
                                                        
| 293 | 293 | array(  | 
                                                        
@@ -297,120 +297,120 @@ discard block  | 
                                                    ||
| 297 | 297 | );  | 
                                                        
| 298 | 298 | }  | 
                                                        
| 299 | 299 | |
| 300 | - $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array();  | 
                                                        |
| 300 | + $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array();  | 
                                                        |
| 301 | 301 | // Filter vat rule type  | 
                                                        
| 302 | -        if ( isset( $_GET['vat_rule'] ) && $_GET['vat_rule'] !== '' ) { | 
                                                        |
| 302 | +        if (isset($_GET['vat_rule']) && $_GET['vat_rule'] !== '') { | 
                                                        |
| 303 | 303 | $meta_query[] = array(  | 
                                                        
| 304 | 304 | 'key' => '_wpinv_vat_rule',  | 
                                                        
| 305 | - 'value' => sanitize_text_field( $_GET['vat_rule'] ),  | 
                                                        |
| 305 | + 'value' => sanitize_text_field($_GET['vat_rule']),  | 
                                                        |
| 306 | 306 | 'compare' => '='  | 
                                                        
| 307 | 307 | );  | 
                                                        
| 308 | 308 | }  | 
                                                        
| 309 | 309 | |
| 310 | 310 | // Filter vat class  | 
                                                        
| 311 | -        if ( isset( $_GET['vat_class'] ) && $_GET['vat_class'] !== '' ) { | 
                                                        |
| 311 | +        if (isset($_GET['vat_class']) && $_GET['vat_class'] !== '') { | 
                                                        |
| 312 | 312 | $meta_query[] = array(  | 
                                                        
| 313 | 313 | 'key' => '_wpinv_vat_class',  | 
                                                        
| 314 | - 'value' => sanitize_text_field( $_GET['vat_class'] ),  | 
                                                        |
| 314 | + 'value' => sanitize_text_field($_GET['vat_class']),  | 
                                                        |
| 315 | 315 | 'compare' => '='  | 
                                                        
| 316 | 316 | );  | 
                                                        
| 317 | 317 | }  | 
                                                        
| 318 | 318 | |
| 319 | 319 | // Filter item type  | 
                                                        
| 320 | -        if ( isset( $_GET['type'] ) && $_GET['type'] !== '' ) { | 
                                                        |
| 320 | +        if (isset($_GET['type']) && $_GET['type'] !== '') { | 
                                                        |
| 321 | 321 | $meta_query[] = array(  | 
                                                        
| 322 | 322 | 'key' => '_wpinv_type',  | 
                                                        
| 323 | - 'value' => sanitize_text_field( $_GET['type'] ),  | 
                                                        |
| 323 | + 'value' => sanitize_text_field($_GET['type']),  | 
                                                        |
| 324 | 324 | 'compare' => '='  | 
                                                        
| 325 | 325 | );  | 
                                                        
| 326 | 326 | }  | 
                                                        
| 327 | 327 | |
| 328 | -        if ( !empty( $meta_query ) ) { | 
                                                        |
| 328 | +        if (!empty($meta_query)) { | 
                                                        |
| 329 | 329 | $vars['meta_query'] = $meta_query;  | 
                                                        
| 330 | 330 | }  | 
                                                        
| 331 | -    } else if ( 'wpi_discount' == $typenow ) { | 
                                                        |
| 332 | - $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array();  | 
                                                        |
| 331 | +    } else if ('wpi_discount' == $typenow) { | 
                                                        |
| 332 | + $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array();  | 
                                                        |
| 333 | 333 | // Filter vat rule type  | 
                                                        
| 334 | -        if ( isset( $_GET['discount_type'] ) && $_GET['discount_type'] !== '' ) { | 
                                                        |
| 334 | +        if (isset($_GET['discount_type']) && $_GET['discount_type'] !== '') { | 
                                                        |
| 335 | 335 | $meta_query[] = array(  | 
                                                        
| 336 | 336 | 'key' => '_wpi_discount_type',  | 
                                                        
| 337 | - 'value' => sanitize_text_field( $_GET['discount_type'] ),  | 
                                                        |
| 337 | + 'value' => sanitize_text_field($_GET['discount_type']),  | 
                                                        |
| 338 | 338 | 'compare' => '='  | 
                                                        
| 339 | 339 | );  | 
                                                        
| 340 | 340 | }  | 
                                                        
| 341 | 341 | |
| 342 | -        if ( !empty( $meta_query ) ) { | 
                                                        |
| 342 | +        if (!empty($meta_query)) { | 
                                                        |
| 343 | 343 | $vars['meta_query'] = $meta_query;  | 
                                                        
| 344 | 344 | }  | 
                                                        
| 345 | 345 | }  | 
                                                        
| 346 | 346 | |
| 347 | 347 | return $vars;  | 
                                                        
| 348 | 348 | }  | 
                                                        
| 349 | -add_filter( 'request', 'wpinv_request' );  | 
                                                        |
| 349 | +add_filter('request', 'wpinv_request'); | 
                                                        |
| 350 | 350 | |
| 351 | 351 |  function wpinv_options_page() { | 
                                                        
| 352 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false;  | 
                                                        |
| 352 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : false;  | 
                                                        |
| 353 | 353 | |
| 354 | -    if ( $page !== 'wpinv-settings' ) { | 
                                                        |
| 354 | +    if ($page !== 'wpinv-settings') { | 
                                                        |
| 355 | 355 | return;  | 
                                                        
| 356 | 356 | }  | 
                                                        
| 357 | 357 | |
| 358 | 358 | $settings_tabs = wpinv_get_settings_tabs();  | 
                                                        
| 359 | 359 | $settings_tabs = empty($settings_tabs) ? array() : $settings_tabs;  | 
                                                        
| 360 | - $active_tab = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $settings_tabs ) ? sanitize_text_field( $_GET['tab'] ) : 'general';  | 
                                                        |
| 361 | - $sections = wpinv_get_settings_tab_sections( $active_tab );  | 
                                                        |
| 360 | + $active_tab = isset($_GET['tab']) && array_key_exists($_GET['tab'], $settings_tabs) ? sanitize_text_field($_GET['tab']) : 'general';  | 
                                                        |
| 361 | + $sections = wpinv_get_settings_tab_sections($active_tab);  | 
                                                        |
| 362 | 362 | $key = 'main';  | 
                                                        
| 363 | 363 | |
| 364 | -    if ( is_array( $sections ) ) { | 
                                                        |
| 365 | - $key = key( $sections );  | 
                                                        |
| 364 | +    if (is_array($sections)) { | 
                                                        |
| 365 | + $key = key($sections);  | 
                                                        |
| 366 | 366 | }  | 
                                                        
| 367 | 367 | |
| 368 | - $registered_sections = wpinv_get_settings_tab_sections( $active_tab );  | 
                                                        |
| 369 | - $section = isset( $_GET['section'] ) && ! empty( $registered_sections ) && array_key_exists( $_GET['section'], $registered_sections ) ? $_GET['section'] : $key;  | 
                                                        |
| 368 | + $registered_sections = wpinv_get_settings_tab_sections($active_tab);  | 
                                                        |
| 369 | + $section = isset($_GET['section']) && !empty($registered_sections) && array_key_exists($_GET['section'], $registered_sections) ? $_GET['section'] : $key;  | 
                                                        |
| 370 | 370 | ob_start();  | 
                                                        
| 371 | 371 | ?>  | 
                                                        
| 372 | 372 | <div class="wrap">  | 
                                                        
| 373 | 373 | <h1 class="nav-tab-wrapper">  | 
                                                        
| 374 | 374 | <?php  | 
                                                        
| 375 | -            foreach( wpinv_get_settings_tabs() as $tab_id => $tab_name ) { | 
                                                        |
| 376 | - $tab_url = add_query_arg( array(  | 
                                                        |
| 375 | +            foreach (wpinv_get_settings_tabs() as $tab_id => $tab_name) { | 
                                                        |
| 376 | + $tab_url = add_query_arg(array(  | 
                                                        |
| 377 | 377 | 'settings-updated' => false,  | 
                                                        
| 378 | 378 | 'tab' => $tab_id,  | 
                                                        
| 379 | - ) );  | 
                                                        |
| 379 | + ));  | 
                                                        |
| 380 | 380 | |
| 381 | 381 | // Remove the section from the tabs so we always end up at the main section  | 
                                                        
| 382 | - $tab_url = remove_query_arg( 'section', $tab_url );  | 
                                                        |
| 383 | - $tab_url = remove_query_arg( 'wpi_sub', $tab_url );  | 
                                                        |
| 382 | +                $tab_url = remove_query_arg('section', $tab_url); | 
                                                        |
| 383 | +                $tab_url = remove_query_arg('wpi_sub', $tab_url); | 
                                                        |
| 384 | 384 | |
| 385 | 385 | $active = $active_tab == $tab_id ? ' nav-tab-active' : '';  | 
                                                        
| 386 | 386 | |
| 387 | - echo '<a href="' . esc_url( $tab_url ) . '" title="' . esc_attr( $tab_name ) . '" class="nav-tab' . $active . '">';  | 
                                                        |
| 388 | - echo esc_html( $tab_name );  | 
                                                        |
| 387 | + echo '<a href="' . esc_url($tab_url) . '" title="' . esc_attr($tab_name) . '" class="nav-tab' . $active . '">';  | 
                                                        |
| 388 | + echo esc_html($tab_name);  | 
                                                        |
| 389 | 389 | echo '</a>';  | 
                                                        
| 390 | 390 | }  | 
                                                        
| 391 | 391 | ?>  | 
                                                        
| 392 | 392 | </h1>  | 
                                                        
| 393 | 393 | <?php  | 
                                                        
| 394 | - $number_of_sections = count( $sections );  | 
                                                        |
| 394 | + $number_of_sections = count($sections);  | 
                                                        |
| 395 | 395 | $number = 0;  | 
                                                        
| 396 | -        if ( $number_of_sections > 1 ) { | 
                                                        |
| 396 | +        if ($number_of_sections > 1) { | 
                                                        |
| 397 | 397 | echo '<div><ul class="subsubsub">';  | 
                                                        
| 398 | -            foreach( $sections as $section_id => $section_name ) { | 
                                                        |
| 398 | +            foreach ($sections as $section_id => $section_name) { | 
                                                        |
| 399 | 399 | echo '<li>';  | 
                                                        
| 400 | 400 | $number++;  | 
                                                        
| 401 | - $tab_url = add_query_arg( array(  | 
                                                        |
| 401 | + $tab_url = add_query_arg(array(  | 
                                                        |
| 402 | 402 | 'settings-updated' => false,  | 
                                                        
| 403 | 403 | 'tab' => $active_tab,  | 
                                                        
| 404 | 404 | 'section' => $section_id  | 
                                                        
| 405 | - ) );  | 
                                                        |
| 406 | - $tab_url = remove_query_arg( 'wpi_sub', $tab_url );  | 
                                                        |
| 405 | + ));  | 
                                                        |
| 406 | +                $tab_url = remove_query_arg('wpi_sub', $tab_url); | 
                                                        |
| 407 | 407 | $class = '';  | 
                                                        
| 408 | -                if ( $section == $section_id ) { | 
                                                        |
| 408 | +                if ($section == $section_id) { | 
                                                        |
| 409 | 409 | $class = 'current';  | 
                                                        
| 410 | 410 | }  | 
                                                        
| 411 | - echo '<a class="' . $class . '" href="' . esc_url( $tab_url ) . '">' . $section_name . '</a>';  | 
                                                        |
| 411 | + echo '<a class="' . $class . '" href="' . esc_url($tab_url) . '">' . $section_name . '</a>';  | 
                                                        |
| 412 | 412 | |
| 413 | -                if ( $number != $number_of_sections ) { | 
                                                        |
| 413 | +                if ($number != $number_of_sections) { | 
                                                        |
| 414 | 414 | echo ' | ';  | 
                                                        
| 415 | 415 | }  | 
                                                        
| 416 | 416 | echo '</li>';  | 
                                                        
@@ -422,19 +422,19 @@ discard block  | 
                                                    ||
| 422 | 422 | <form method="post" action="options.php">  | 
                                                        
| 423 | 423 | <table class="form-table">  | 
                                                        
| 424 | 424 | <?php  | 
                                                        
| 425 | - settings_fields( 'wpinv_settings' );  | 
                                                        |
| 425 | +                settings_fields('wpinv_settings'); | 
                                                        |
| 426 | 426 | |
| 427 | -                if ( 'main' === $section ) { | 
                                                        |
| 428 | - do_action( 'wpinv_settings_tab_top', $active_tab );  | 
                                                        |
| 427 | +                if ('main' === $section) { | 
                                                        |
| 428 | +                    do_action('wpinv_settings_tab_top', $active_tab); | 
                                                        |
| 429 | 429 | }  | 
                                                        
| 430 | 430 | |
| 431 | - do_action( 'wpinv_settings_tab_top_' . $active_tab . '_' . $section );  | 
                                                        |
| 432 | - do_settings_sections( 'wpinv_settings_' . $active_tab . '_' . $section );  | 
                                                        |
| 433 | - do_action( 'wpinv_settings_tab_bottom_' . $active_tab . '_' . $section );  | 
                                                        |
| 431 | +                do_action('wpinv_settings_tab_top_' . $active_tab . '_' . $section); | 
                                                        |
| 432 | +                do_settings_sections('wpinv_settings_' . $active_tab . '_' . $section); | 
                                                        |
| 433 | +                do_action('wpinv_settings_tab_bottom_' . $active_tab . '_' . $section); | 
                                                        |
| 434 | 434 | |
| 435 | 435 | // For backwards compatibility  | 
                                                        
| 436 | -                if ( 'main' === $section ) { | 
                                                        |
| 437 | - do_action( 'wpinv_settings_tab_bottom', $active_tab );  | 
                                                        |
| 436 | +                if ('main' === $section) { | 
                                                        |
| 437 | +                    do_action('wpinv_settings_tab_bottom', $active_tab); | 
                                                        |
| 438 | 438 | }  | 
                                                        
| 439 | 439 | ?>  | 
                                                        
| 440 | 440 | </table>  | 
                                                        
@@ -447,12 +447,12 @@ discard block  | 
                                                    ||
| 447 | 447 | echo $content;  | 
                                                        
| 448 | 448 | }  | 
                                                        
| 449 | 449 | |
| 450 | -function wpinv_item_type_class( $classes, $class, $post_id ) { | 
                                                        |
| 450 | +function wpinv_item_type_class($classes, $class, $post_id) { | 
                                                        |
| 451 | 451 | global $pagenow, $typenow;  | 
                                                        
| 452 | 452 | |
| 453 | -    if ( $pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type( $post_id ) == $typenow && $type = get_post_meta( $post_id, '_wpinv_type', true ) ) { | 
                                                        |
| 454 | - $classes[] = 'wpi-type-' . sanitize_html_class( $type );  | 
                                                        |
| 453 | +    if ($pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type($post_id) == $typenow && $type = get_post_meta($post_id, '_wpinv_type', true)) { | 
                                                        |
| 454 | + $classes[] = 'wpi-type-' . sanitize_html_class($type);  | 
                                                        |
| 455 | 455 | }  | 
                                                        
| 456 | 456 | return $classes;  | 
                                                        
| 457 | 457 | }  | 
                                                        
| 458 | -add_filter( 'post_class', 'wpinv_item_type_class', 10, 3 );  | 
                                                        |
| 459 | 458 | \ No newline at end of file  | 
                                                        
| 459 | +add_filter('post_class', 'wpinv_item_type_class', 10, 3); | 
                                                        |
| 460 | 460 | \ No newline at end of file  | 
                                                        
@@ -47,6 +47,9 @@ discard block  | 
                                                    ||
| 47 | 47 | }  | 
                                                        
| 48 | 48 | }  | 
                                                        
| 49 | 49 | |
| 50 | + /**  | 
                                                        |
| 51 | + * @param integer $code  | 
                                                        |
| 52 | + */  | 
                                                        |
| 50 | 53 |      public function send_status( $code ) { | 
                                                        
| 51 | 54 | status_header( $code );  | 
                                                        
| 52 | 55 | }  | 
                                                        
@@ -195,6 +198,11 @@ discard block  | 
                                                    ||
| 195 | 198 |  class WPInv_API_Exception extends Exception { | 
                                                        
| 196 | 199 | protected $error_code;  | 
                                                        
| 197 | 200 | |
| 201 | + /**  | 
                                                        |
| 202 | + * @param string $error_code  | 
                                                        |
| 203 | + * @param string $error_message  | 
                                                        |
| 204 | + * @param integer $http_status_code  | 
                                                        |
| 205 | + */  | 
                                                        |
| 198 | 206 |      public function __construct( $error_code, $error_message, $http_status_code ) { | 
                                                        
| 199 | 207 | $this->error_code = $error_code;  | 
                                                        
| 200 | 208 | parent::__construct( $error_message, $http_status_code );  | 
                                                        
@@ -7,51 +7,51 @@ 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_API { | 
                                                        
| 15 | 15 | protected $post_type = 'wpi_invoice';  | 
                                                        
| 16 | 16 | |
| 17 | -    public function __construct( $params = array() ) { | 
                                                        |
| 17 | +    public function __construct($params = array()) { | 
                                                        |
| 18 | 18 | }  | 
                                                        
| 19 | -    public function insert_invoice( $data ) { | 
                                                        |
| 19 | +    public function insert_invoice($data) { | 
                                                        |
| 20 | 20 | global $wpdb;  | 
                                                        
| 21 | 21 | //wpinv_transaction_query( 'start' );  | 
                                                        
| 22 | 22 | |
| 23 | 23 |          try { | 
                                                        
| 24 | -            if ( empty( $data['invoice'] ) ) { | 
                                                        |
| 25 | - throw new WPInv_API_Exception( 'wpinv_api_missing_invoice_data', sprintf( __( 'No %1$s data specified to create %1$s', 'invoicing' ), 'invoice' ), 400 );  | 
                                                        |
| 24 | +            if (empty($data['invoice'])) { | 
                                                        |
| 25 | +                throw new WPInv_API_Exception('wpinv_api_missing_invoice_data', sprintf(__('No %1$s data specified to create %1$s', 'invoicing'), 'invoice'), 400); | 
                                                        |
| 26 | 26 | }  | 
                                                        
| 27 | 27 | |
| 28 | - $data = apply_filters( 'wpinv_api_create_invoice_data', $data['invoice'], $this );  | 
                                                        |
| 28 | +            $data = apply_filters('wpinv_api_create_invoice_data', $data['invoice'], $this); | 
                                                        |
| 29 | 29 | |
| 30 | - $invoice = wpinv_insert_invoice( $data, true );  | 
                                                        |
| 31 | -            if ( empty( $invoice->ID ) || is_wp_error( $invoice ) ) { | 
                                                        |
| 32 | - throw new WPInv_API_Exception( 'wpinv_api_cannot_create_invoice', sprintf( __( 'Cannot create invoice: %s', 'invoicing' ), implode( ', ', $invoice->get_error_messages() ) ), 400 );  | 
                                                        |
| 30 | + $invoice = wpinv_insert_invoice($data, true);  | 
                                                        |
| 31 | +            if (empty($invoice->ID) || is_wp_error($invoice)) { | 
                                                        |
| 32 | +                throw new WPInv_API_Exception('wpinv_api_cannot_create_invoice', sprintf(__('Cannot create invoice: %s', 'invoicing'), implode(', ', $invoice->get_error_messages())), 400); | 
                                                        |
| 33 | 33 | }  | 
                                                        
| 34 | 34 | |
| 35 | 35 | // HTTP 201 Created  | 
                                                        
| 36 | - $this->send_status( 201 );  | 
                                                        |
| 36 | + $this->send_status(201);  | 
                                                        |
| 37 | 37 | |
| 38 | - do_action( 'wpinv_api_create_invoice', $invoice->ID, $data, $this );  | 
                                                        |
| 38 | +            do_action('wpinv_api_create_invoice', $invoice->ID, $data, $this); | 
                                                        |
| 39 | 39 | |
| 40 | 40 | //wpinv_transaction_query( 'commit' );  | 
                                                        
| 41 | 41 | |
| 42 | - return wpinv_get_invoice( $invoice->ID );  | 
                                                        |
| 43 | -        } catch ( WPInv_API_Exception $e ) { | 
                                                        |
| 42 | + return wpinv_get_invoice($invoice->ID);  | 
                                                        |
| 43 | +        } catch (WPInv_API_Exception $e) { | 
                                                        |
| 44 | 44 | //wpinv_transaction_query( 'rollback' );  | 
                                                        
| 45 | 45 | |
| 46 | - return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );  | 
                                                        |
| 46 | +            return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode())); | 
                                                        |
| 47 | 47 | }  | 
                                                        
| 48 | 48 | }  | 
                                                        
| 49 | 49 | |
| 50 | -    public function send_status( $code ) { | 
                                                        |
| 51 | - status_header( $code );  | 
                                                        |
| 50 | +    public function send_status($code) { | 
                                                        |
| 51 | + status_header($code);  | 
                                                        |
| 52 | 52 | }  | 
                                                        
| 53 | 53 | |
| 54 | -    protected function set_billing_details( $invoice, $data ) { | 
                                                        |
| 54 | +    protected function set_billing_details($invoice, $data) { | 
                                                        |
| 55 | 55 | $address_fields = array(  | 
                                                        
| 56 | 56 | 'user_id',  | 
                                                        
| 57 | 57 | 'first_name',  | 
                                                        
@@ -70,66 +70,66 @@ discard block  | 
                                                    ||
| 70 | 70 | $billing_details = array();  | 
                                                        
| 71 | 71 | $user_id = $invoice->get_user_id();  | 
                                                        
| 72 | 72 | |
| 73 | -        foreach ( $address_fields as $field ) { | 
                                                        |
| 74 | -            if ( isset( $data['billing_details'][ $field ] ) ) { | 
                                                        |
| 75 | - $value = sanitize_text_field( $data['billing_details'][ $field ] );  | 
                                                        |
| 73 | +        foreach ($address_fields as $field) { | 
                                                        |
| 74 | +            if (isset($data['billing_details'][$field])) { | 
                                                        |
| 75 | + $value = sanitize_text_field($data['billing_details'][$field]);  | 
                                                        |
| 76 | 76 | |
| 77 | -                if ( $field == 'country' && empty( $value ) ) { | 
                                                        |
| 78 | -                    if ( !empty( $invoice->country ) ) { | 
                                                        |
| 77 | +                if ($field == 'country' && empty($value)) { | 
                                                        |
| 78 | +                    if (!empty($invoice->country)) { | 
                                                        |
| 79 | 79 | $value = $invoice->country;  | 
                                                        
| 80 | 80 |                      } else { | 
                                                        
| 81 | - $value = wpinv_default_billing_country( '', $user_id );  | 
                                                        |
| 81 | +                        $value = wpinv_default_billing_country('', $user_id); | 
                                                        |
| 82 | 82 | }  | 
                                                        
| 83 | 83 | }  | 
                                                        
| 84 | 84 | |
| 85 | -                if ( $field == 'state' && empty( $value ) ) { | 
                                                        |
| 86 | -                    if ( !empty( $invoice->state ) ) { | 
                                                        |
| 85 | +                if ($field == 'state' && empty($value)) { | 
                                                        |
| 86 | +                    if (!empty($invoice->state)) { | 
                                                        |
| 87 | 87 | $value = $invoice->state;  | 
                                                        
| 88 | 88 |                      } else { | 
                                                        
| 89 | 89 | $value = wpinv_get_default_state();  | 
                                                        
| 90 | 90 | }  | 
                                                        
| 91 | 91 | }  | 
                                                        
| 92 | 92 | |
| 93 | - $invoice->set( $field, $value );  | 
                                                        |
| 93 | + $invoice->set($field, $value);  | 
                                                        |
| 94 | 94 | |
| 95 | - update_post_meta( $invoice->ID, '_wpinv_' . $field, $value );  | 
                                                        |
| 95 | + update_post_meta($invoice->ID, '_wpinv_' . $field, $value);  | 
                                                        |
| 96 | 96 | }  | 
                                                        
| 97 | 97 | }  | 
                                                        
| 98 | 98 | |
| 99 | 99 | return $invoice;  | 
                                                        
| 100 | 100 | }  | 
                                                        
| 101 | 101 | |
| 102 | -    protected function set_discount( $invoice, $data ) { | 
                                                        |
| 103 | -        if ( isset( $data['discount'] ) ) { | 
                                                        |
| 104 | - $invoice->set( 'discount', wpinv_round_amount( $data['discount'] ) );  | 
                                                        |
| 102 | +    protected function set_discount($invoice, $data) { | 
                                                        |
| 103 | +        if (isset($data['discount'])) { | 
                                                        |
| 104 | +            $invoice->set('discount', wpinv_round_amount($data['discount'])); | 
                                                        |
| 105 | 105 | |
| 106 | - update_post_meta( $invoice->ID, '_wpinv_discount', wpinv_round_amount( $data['discount'] ) );  | 
                                                        |
| 106 | + update_post_meta($invoice->ID, '_wpinv_discount', wpinv_round_amount($data['discount']));  | 
                                                        |
| 107 | 107 | |
| 108 | -            if ( isset( $data['discount_code'] ) ) { | 
                                                        |
| 109 | - $invoice->set( 'discount_code', $data['discount_code'] );  | 
                                                        |
| 108 | +            if (isset($data['discount_code'])) { | 
                                                        |
| 109 | +                $invoice->set('discount_code', $data['discount_code']); | 
                                                        |
| 110 | 110 | |
| 111 | - update_post_meta( $invoice->ID, '_wpinv_discount_code', $data['discount_code'] );  | 
                                                        |
| 111 | + update_post_meta($invoice->ID, '_wpinv_discount_code', $data['discount_code']);  | 
                                                        |
| 112 | 112 | }  | 
                                                        
| 113 | 113 | }  | 
                                                        
| 114 | 114 | |
| 115 | 115 | return $invoice;  | 
                                                        
| 116 | 116 | }  | 
                                                        
| 117 | 117 | |
| 118 | -    protected function set_items( $invoice, $data ) { | 
                                                        |
| 119 | -        if ( !empty( $data['items'] ) && is_array( $data['items'] ) ) { | 
                                                        |
| 118 | +    protected function set_items($invoice, $data) { | 
                                                        |
| 119 | +        if (!empty($data['items']) && is_array($data['items'])) { | 
                                                        |
| 120 | 120 | $items_array = array();  | 
                                                        
| 121 | 121 | |
| 122 | -            if ( !empty( $invoice->country ) ) { | 
                                                        |
| 122 | +            if (!empty($invoice->country)) { | 
                                                        |
| 123 | 123 | $country = $invoice->country;  | 
                                                        
| 124 | -            } else if ( !empty( $data['billing_details']['country'] ) ) { | 
                                                        |
| 124 | +            } else if (!empty($data['billing_details']['country'])) { | 
                                                        |
| 125 | 125 | $country = $data['billing_details']['country'];  | 
                                                        
| 126 | 126 |              } else { | 
                                                        
| 127 | - $country = wpinv_default_billing_country( '', $invoice->get_user_id() );  | 
                                                        |
| 127 | +                $country = wpinv_default_billing_country('', $invoice->get_user_id()); | 
                                                        |
| 128 | 128 | }  | 
                                                        
| 129 | 129 | |
| 130 | -            if ( !empty( $invoice->state ) ) { | 
                                                        |
| 130 | +            if (!empty($invoice->state)) { | 
                                                        |
| 131 | 131 | $state = $invoice->state;  | 
                                                        
| 132 | -            } else if ( !empty( $data['billing_details']['state'] ) ) { | 
                                                        |
| 132 | +            } else if (!empty($data['billing_details']['state'])) { | 
                                                        |
| 133 | 133 | $state = $data['billing_details']['state'];  | 
                                                        
| 134 | 134 |              } else { | 
                                                        
| 135 | 135 | $state = wpinv_get_default_state();  | 
                                                        
@@ -138,54 +138,54 @@ discard block  | 
                                                    ||
| 138 | 138 | $_POST['country'] = $country;  | 
                                                        
| 139 | 139 | $_POST['state'] = $state;  | 
                                                        
| 140 | 140 | |
| 141 | - $rate = wpinv_get_tax_rate( $country, $state, 'global' );  | 
                                                        |
| 141 | + $rate = wpinv_get_tax_rate($country, $state, 'global');  | 
                                                        |
| 142 | 142 | |
| 143 | 143 | $total_tax = 0;  | 
                                                        
| 144 | -            foreach ( $data['items'] as $item ) { | 
                                                        |
| 145 | - $id = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : '';  | 
                                                        |
| 146 | - $title = isset( $item['title'] ) ? sanitize_text_field( $item['title'] ) : '';  | 
                                                        |
| 147 | - $desc = isset( $item['description'] ) ? sanitize_text_field( $item['description'] ) : '';  | 
                                                        |
| 148 | - $amount = isset( $item['amount'] ) ? wpinv_round_amount( $item['amount'] ) : 0;  | 
                                                        |
| 144 | +            foreach ($data['items'] as $item) { | 
                                                        |
| 145 | + $id = isset($item['id']) ? sanitize_text_field($item['id']) : '';  | 
                                                        |
| 146 | + $title = isset($item['title']) ? sanitize_text_field($item['title']) : '';  | 
                                                        |
| 147 | + $desc = isset($item['description']) ? sanitize_text_field($item['description']) : '';  | 
                                                        |
| 148 | + $amount = isset($item['amount']) ? wpinv_round_amount($item['amount']) : 0;  | 
                                                        |
| 149 | 149 | |
| 150 | -                if ( !empty( $item['vat_rates_class'] ) ) { | 
                                                        |
| 150 | +                if (!empty($item['vat_rates_class'])) { | 
                                                        |
| 151 | 151 | $vat_rates_class = $item['vat_rates_class'];  | 
                                                        
| 152 | 152 |                  } else { | 
                                                        
| 153 | 153 | $vat_rates_class = '_standard';  | 
                                                        
| 154 | 154 | }  | 
                                                        
| 155 | - $vat_rate = wpinv_get_tax_rate( $country, $state, $id );  | 
                                                        |
| 155 | + $vat_rate = wpinv_get_tax_rate($country, $state, $id);  | 
                                                        |
| 156 | 156 | |
| 157 | - $tax = $amount > 0 ? ( $amount * 0.01 * (float)$vat_rate ) : 0;  | 
                                                        |
| 157 | + $tax = $amount > 0 ? ($amount * 0.01 * (float)$vat_rate) : 0;  | 
                                                        |
| 158 | 158 | $total_tax += $tax;  | 
                                                        
| 159 | 159 | |
| 160 | 160 | $items_array[] = array(  | 
                                                        
| 161 | 161 | 'id' => $id,  | 
                                                        
| 162 | - 'title' => esc_html( $title ),  | 
                                                        |
| 163 | - 'description' => esc_html( $desc ),  | 
                                                        |
| 164 | - 'amount' => $amount > 0 ? wpinv_round_amount( $amount ) : 0,  | 
                                                        |
| 165 | - 'subtotal' => $amount > 0 ? wpinv_round_amount( $amount ) : 0,  | 
                                                        |
| 162 | + 'title' => esc_html($title),  | 
                                                        |
| 163 | + 'description' => esc_html($desc),  | 
                                                        |
| 164 | + 'amount' => $amount > 0 ? wpinv_round_amount($amount) : 0,  | 
                                                        |
| 165 | + 'subtotal' => $amount > 0 ? wpinv_round_amount($amount) : 0,  | 
                                                        |
| 166 | 166 | 'vat_rates_class' => $vat_rates_class,  | 
                                                        
| 167 | 167 | 'vat_rate' => $vat_rate,  | 
                                                        
| 168 | - 'tax' => $tax > 0 ? wpinv_round_amount( $tax ) : 0,  | 
                                                        |
| 168 | + 'tax' => $tax > 0 ? wpinv_round_amount($tax) : 0,  | 
                                                        |
| 169 | 169 | );  | 
                                                        
| 170 | 170 | }  | 
                                                        
| 171 | 171 | |
| 172 | - update_post_meta( $invoice->ID, '_wpinv_tax', wpinv_round_amount( $total_tax ) );  | 
                                                        |
| 173 | - $invoice->set( 'tax', wpinv_round_amount( $total_tax ) );  | 
                                                        |
| 172 | + update_post_meta($invoice->ID, '_wpinv_tax', wpinv_round_amount($total_tax));  | 
                                                        |
| 173 | +            $invoice->set('tax', wpinv_round_amount($total_tax)); | 
                                                        |
| 174 | 174 | |
| 175 | - $items_array = apply_filters( 'wpinv_save_invoice_items', $items_array, $data['items'], $invoice );  | 
                                                        |
| 175 | +            $items_array = apply_filters('wpinv_save_invoice_items', $items_array, $data['items'], $invoice); | 
                                                        |
| 176 | 176 | |
| 177 | - $invoice->set( 'items', $items_array );  | 
                                                        |
| 178 | - update_post_meta( $invoice->ID, '_wpinv_items', $items_array );  | 
                                                        |
| 177 | +            $invoice->set('items', $items_array); | 
                                                        |
| 178 | + update_post_meta($invoice->ID, '_wpinv_items', $items_array);  | 
                                                        |
| 179 | 179 | }  | 
                                                        
| 180 | 180 | |
| 181 | 181 | return $invoice;  | 
                                                        
| 182 | 182 | }  | 
                                                        
| 183 | 183 | |
| 184 | -    protected function set_invoice_meta( $invoice_id, $invoice_meta ) { | 
                                                        |
| 185 | -        foreach ( $invoice_meta as $meta_key => $meta_value ) { | 
                                                        |
| 184 | +    protected function set_invoice_meta($invoice_id, $invoice_meta) { | 
                                                        |
| 185 | +        foreach ($invoice_meta as $meta_key => $meta_value) { | 
                                                        |
| 186 | 186 | |
| 187 | -            if ( is_string( $meta_key) && ! is_protected_meta( $meta_key ) && is_scalar( $meta_value ) ) { | 
                                                        |
| 188 | - update_post_meta( $invoice_id, $meta_key, $meta_value );  | 
                                                        |
| 187 | +            if (is_string($meta_key) && !is_protected_meta($meta_key) && is_scalar($meta_value)) { | 
                                                        |
| 188 | + update_post_meta($invoice_id, $meta_key, $meta_value);  | 
                                                        |
| 189 | 189 | }  | 
                                                        
| 190 | 190 | }  | 
                                                        
| 191 | 191 | }  | 
                                                        
@@ -195,9 +195,9 @@ discard block  | 
                                                    ||
| 195 | 195 |  class WPInv_API_Exception extends Exception { | 
                                                        
| 196 | 196 | protected $error_code;  | 
                                                        
| 197 | 197 | |
| 198 | -    public function __construct( $error_code, $error_message, $http_status_code ) { | 
                                                        |
| 198 | +    public function __construct($error_code, $error_message, $http_status_code) { | 
                                                        |
| 199 | 199 | $this->error_code = $error_code;  | 
                                                        
| 200 | - parent::__construct( $error_message, $http_status_code );  | 
                                                        |
| 200 | + parent::__construct($error_message, $http_status_code);  | 
                                                        |
| 201 | 201 | }  | 
                                                        
| 202 | 202 | |
| 203 | 203 |      public function getErrorCode() { | 
                                                        
@@ -83,6 +83,9 @@ discard block  | 
                                                    ||
| 83 | 83 | return $value;  | 
                                                        
| 84 | 84 | }  | 
                                                        
| 85 | 85 | |
| 86 | + /**  | 
                                                        |
| 87 | + * @param string $key  | 
                                                        |
| 88 | + */  | 
                                                        |
| 86 | 89 |      public function set( $key, $value ) { | 
                                                        
| 87 | 90 | $ignore = array( 'items', 'cart_details', 'fees', '_ID' );  | 
                                                        
| 88 | 91 | |
@@ -916,6 +919,9 @@ discard block  | 
                                                    ||
| 916 | 919 | return $removed;  | 
                                                        
| 917 | 920 | }  | 
                                                        
| 918 | 921 | |
| 922 | + /**  | 
                                                        |
| 923 | + * @param string $key  | 
                                                        |
| 924 | + */  | 
                                                        |
| 919 | 925 |      public function remove_fee_by( $key, $value, $global = false ) { | 
                                                        
| 920 | 926 | $allowed_fee_keys = apply_filters( 'wpinv_fee_keys', array(  | 
                                                        
| 921 | 927 | 'index', 'label', 'amount', 'type',  | 
                                                        
@@ -1375,6 +1381,9 @@ discard block  | 
                                                    ||
| 1375 | 1381 | return apply_filters( 'wpinv_get_invoice_final_total', $final_total, $this, $currency );  | 
                                                        
| 1376 | 1382 | }  | 
                                                        
| 1377 | 1383 | |
| 1384 | + /**  | 
                                                        |
| 1385 | + * @return boolean  | 
                                                        |
| 1386 | + */  | 
                                                        |
| 1378 | 1387 |      public function get_discounts( $array = false ) { | 
                                                        
| 1379 | 1388 | $discounts = $this->discounts;  | 
                                                        
| 1380 | 1389 |          if ( $array && $discounts ) { | 
                                                        
@@ -1383,6 +1392,9 @@ discard block  | 
                                                    ||
| 1383 | 1392 | return apply_filters( 'wpinv_payment_discounts', $discounts, $this->ID, $this, $array );  | 
                                                        
| 1384 | 1393 | }  | 
                                                        
| 1385 | 1394 | |
| 1395 | + /**  | 
                                                        |
| 1396 | + * @return string  | 
                                                        |
| 1397 | + */  | 
                                                        |
| 1386 | 1398 |      public function get_discount( $currency = false, $dash = false ) { | 
                                                        
| 1387 | 1399 |          if ( !empty( $this->discounts ) ) { | 
                                                        
| 1388 | 1400 | global $ajax_cart_details;  | 
                                                        
@@ -1479,10 +1491,16 @@ discard block  | 
                                                    ||
| 1479 | 1491 | return apply_filters( 'wpinv_user_full_name', $this->full_name, $this->ID, $this );  | 
                                                        
| 1480 | 1492 | }  | 
                                                        
| 1481 | 1493 | |
| 1494 | + /**  | 
                                                        |
| 1495 | + * @return string  | 
                                                        |
| 1496 | + */  | 
                                                        |
| 1482 | 1497 |      public function get_user_info() { | 
                                                        
| 1483 | 1498 | return apply_filters( 'wpinv_user_info', $this->user_info, $this->ID, $this );  | 
                                                        
| 1484 | 1499 | }  | 
                                                        
| 1485 | 1500 | |
| 1501 | + /**  | 
                                                        |
| 1502 | + * @return string  | 
                                                        |
| 1503 | + */  | 
                                                        |
| 1486 | 1504 |      public function get_email() { | 
                                                        
| 1487 | 1505 | return apply_filters( 'wpinv_user_email', $this->email, $this->ID, $this );  | 
                                                        
| 1488 | 1506 | }  | 
                                                        
@@ -1525,10 +1543,16 @@ discard block  | 
                                                    ||
| 1525 | 1543 | return apply_filters( 'wpinv_currency_code', $this->currency, $this->ID, $this );  | 
                                                        
| 1526 | 1544 | }  | 
                                                        
| 1527 | 1545 | |
| 1546 | + /**  | 
                                                        |
| 1547 | + * @return string  | 
                                                        |
| 1548 | + */  | 
                                                        |
| 1528 | 1549 |      public function get_created_date() { | 
                                                        
| 1529 | 1550 | return apply_filters( 'wpinv_created_date', $this->date, $this->ID, $this );  | 
                                                        
| 1530 | 1551 | }  | 
                                                        
| 1531 | 1552 | |
| 1553 | + /**  | 
                                                        |
| 1554 | + * @return string  | 
                                                        |
| 1555 | + */  | 
                                                        |
| 1532 | 1556 |      public function get_due_date( $display = false ) { | 
                                                        
| 1533 | 1557 | $due_date = apply_filters( 'wpinv_due_date', $this->due_date, $this->ID, $this );  | 
                                                        
| 1534 | 1558 | |
@@ -2081,6 +2105,9 @@ discard block  | 
                                                    ||
| 2081 | 2105 | return apply_filters( 'wpinv_invoice_get_subscription_name', $name, $this );  | 
                                                        
| 2082 | 2106 | }  | 
                                                        
| 2083 | 2107 | |
| 2108 | + /**  | 
                                                        |
| 2109 | + * @return string  | 
                                                        |
| 2110 | + */  | 
                                                        |
| 2084 | 2111 |      public function get_expiration() { | 
                                                        
| 2085 | 2112 | $expiration = $this->get_meta( '_wpinv_subscr_expiration', true );  | 
                                                        
| 2086 | 2113 | return $expiration;  | 
                                                        
@@ -2096,6 +2123,9 @@ discard block  | 
                                                    ||
| 2096 | 2123 | return $cancelled_date;  | 
                                                        
| 2097 | 2124 | }  | 
                                                        
| 2098 | 2125 | |
| 2126 | + /**  | 
                                                        |
| 2127 | + * @return string  | 
                                                        |
| 2128 | + */  | 
                                                        |
| 2099 | 2129 |      public function get_trial_end_date( $formatted = true ) { | 
                                                        
| 2100 | 2130 |          if ( !$this->is_free_trial() || !$this->is_paid() ) { | 
                                                        
| 2101 | 2131 | return NULL;  | 
                                                        
@@ -2117,6 +2147,9 @@ discard block  | 
                                                    ||
| 2117 | 2147 | return $trial_end_date;  | 
                                                        
| 2118 | 2148 | }  | 
                                                        
| 2119 | 2149 | |
| 2150 | + /**  | 
                                                        |
| 2151 | + * @return string  | 
                                                        |
| 2152 | + */  | 
                                                        |
| 2120 | 2153 |      public function get_subscription_created( $default = true ) { | 
                                                        
| 2121 | 2154 | $created = $this->get_meta( '_wpinv_subscr_created', true );  | 
                                                        
| 2122 | 2155 | |
@@ -2126,6 +2159,9 @@ discard block  | 
                                                    ||
| 2126 | 2159 | return $created;  | 
                                                        
| 2127 | 2160 | }  | 
                                                        
| 2128 | 2161 | |
| 2162 | + /**  | 
                                                        |
| 2163 | + * @return string  | 
                                                        |
| 2164 | + */  | 
                                                        |
| 2129 | 2165 |      public function get_subscription_start( $formatted = true ) { | 
                                                        
| 2130 | 2166 |          if ( !$this->is_paid() ) { | 
                                                        
| 2131 | 2167 | return '-';  | 
                                                        
@@ -7,12 +7,12 @@ discard block  | 
                                                    ||
| 7 | 7 | */  | 
                                                        
| 8 | 8 | |
| 9 | 9 | // MUST have WordPress.  | 
                                                        
| 10 | -if ( !defined( 'WPINC' ) ) { | 
                                                        |
| 11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );  | 
                                                        |
| 10 | +if (!defined('WPINC')) { | 
                                                        |
| 11 | +    exit('Do NOT access this file directly: ' . basename(__FILE__)); | 
                                                        |
| 12 | 12 | }  | 
                                                        
| 13 | 13 | |
| 14 | 14 |  final class WPInv_Invoice { | 
                                                        
| 15 | - public $ID = 0;  | 
                                                        |
| 15 | + public $ID = 0;  | 
                                                        |
| 16 | 16 | public $title;  | 
                                                        
| 17 | 17 | public $post_type;  | 
                                                        
| 18 | 18 | |
@@ -65,17 +65,17 @@ discard block  | 
                                                    ||
| 65 | 65 | public $full_name = '';  | 
                                                        
| 66 | 66 | public $parent_invoice = 0;  | 
                                                        
| 67 | 67 | |
| 68 | -    public function __construct( $invoice_id = false ) { | 
                                                        |
| 69 | -        if( empty( $invoice_id ) ) { | 
                                                        |
| 68 | +    public function __construct($invoice_id = false) { | 
                                                        |
| 69 | +        if (empty($invoice_id)) { | 
                                                        |
| 70 | 70 | return false;  | 
                                                        
| 71 | 71 | }  | 
                                                        
| 72 | 72 | |
| 73 | - $this->setup_invoice( $invoice_id );  | 
                                                        |
| 73 | + $this->setup_invoice($invoice_id);  | 
                                                        |
| 74 | 74 | }  | 
                                                        
| 75 | 75 | |
| 76 | -    public function get( $key ) { | 
                                                        |
| 77 | -        if ( method_exists( $this, 'get_' . $key ) ) { | 
                                                        |
| 78 | - $value = call_user_func( array( $this, 'get_' . $key ) );  | 
                                                        |
| 76 | +    public function get($key) { | 
                                                        |
| 77 | +        if (method_exists($this, 'get_' . $key)) { | 
                                                        |
| 78 | + $value = call_user_func(array($this, 'get_' . $key));  | 
                                                        |
| 79 | 79 |          } else { | 
                                                        
| 80 | 80 | $value = $this->$key;  | 
                                                        
| 81 | 81 | }  | 
                                                        
@@ -83,51 +83,51 @@ discard block  | 
                                                    ||
| 83 | 83 | return $value;  | 
                                                        
| 84 | 84 | }  | 
                                                        
| 85 | 85 | |
| 86 | -    public function set( $key, $value ) { | 
                                                        |
| 87 | - $ignore = array( 'items', 'cart_details', 'fees', '_ID' );  | 
                                                        |
| 86 | +    public function set($key, $value) { | 
                                                        |
| 87 | +        $ignore = array('items', 'cart_details', 'fees', '_ID'); | 
                                                        |
| 88 | 88 | |
| 89 | -        if ( $key === 'status' ) { | 
                                                        |
| 89 | +        if ($key === 'status') { | 
                                                        |
| 90 | 90 | $this->old_status = $this->status;  | 
                                                        
| 91 | 91 | }  | 
                                                        
| 92 | 92 | |
| 93 | -        if ( ! in_array( $key, $ignore ) ) { | 
                                                        |
| 94 | - $this->pending[ $key ] = $value;  | 
                                                        |
| 93 | +        if (!in_array($key, $ignore)) { | 
                                                        |
| 94 | + $this->pending[$key] = $value;  | 
                                                        |
| 95 | 95 | }  | 
                                                        
| 96 | 96 | |
| 97 | -        if( '_ID' !== $key ) { | 
                                                        |
| 97 | +        if ('_ID' !== $key) { | 
                                                        |
| 98 | 98 | $this->$key = $value;  | 
                                                        
| 99 | 99 | }  | 
                                                        
| 100 | 100 | }  | 
                                                        
| 101 | 101 | |
| 102 | -    public function _isset( $name ) { | 
                                                        |
| 103 | -        if ( property_exists( $this, $name) ) { | 
                                                        |
| 104 | - return false === empty( $this->$name );  | 
                                                        |
| 102 | +    public function _isset($name) { | 
                                                        |
| 103 | +        if (property_exists($this, $name)) { | 
                                                        |
| 104 | + return false === empty($this->$name);  | 
                                                        |
| 105 | 105 |          } else { | 
                                                        
| 106 | 106 | return null;  | 
                                                        
| 107 | 107 | }  | 
                                                        
| 108 | 108 | }  | 
                                                        
| 109 | 109 | |
| 110 | -    private function setup_invoice( $invoice_id ) { | 
                                                        |
| 110 | +    private function setup_invoice($invoice_id) { | 
                                                        |
| 111 | 111 | $this->pending = array();  | 
                                                        
| 112 | 112 | |
| 113 | -        if ( empty( $invoice_id ) ) { | 
                                                        |
| 113 | +        if (empty($invoice_id)) { | 
                                                        |
| 114 | 114 | return false;  | 
                                                        
| 115 | 115 | }  | 
                                                        
| 116 | 116 | |
| 117 | - $invoice = get_post( $invoice_id );  | 
                                                        |
| 117 | + $invoice = get_post($invoice_id);  | 
                                                        |
| 118 | 118 | |
| 119 | -        if( !$invoice || is_wp_error( $invoice ) ) { | 
                                                        |
| 119 | +        if (!$invoice || is_wp_error($invoice)) { | 
                                                        |
| 120 | 120 | return false;  | 
                                                        
| 121 | 121 | }  | 
                                                        
| 122 | 122 | |
| 123 | -        if( !('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type) ) { | 
                                                        |
| 123 | +        if (!('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type)) { | 
                                                        |
| 124 | 124 | return false;  | 
                                                        
| 125 | 125 | }  | 
                                                        
| 126 | 126 | |
| 127 | - do_action( 'wpinv_pre_setup_invoice', $this, $invoice_id );  | 
                                                        |
| 127 | +        do_action('wpinv_pre_setup_invoice', $this, $invoice_id); | 
                                                        |
| 128 | 128 | |
| 129 | 129 | // Primary Identifier  | 
                                                        
| 130 | - $this->ID = absint( $invoice_id );  | 
                                                        |
| 130 | + $this->ID = absint($invoice_id);  | 
                                                        |
| 131 | 131 | $this->post_type = $invoice->post_type;  | 
                                                        
| 132 | 132 | |
| 133 | 133 | // We have a payment, get the generic payment_meta item to reduce calls to it  | 
                                                        
@@ -139,7 +139,7 @@ discard block  | 
                                                    ||
| 139 | 139 | $this->post_status = $this->status;  | 
                                                        
| 140 | 140 | $this->mode = $this->setup_mode();  | 
                                                        
| 141 | 141 | $this->parent_invoice = $invoice->post_parent;  | 
                                                        
| 142 | - $this->post_name = $this->setup_post_name( $invoice );  | 
                                                        |
| 142 | + $this->post_name = $this->setup_post_name($invoice);  | 
                                                        |
| 143 | 143 | $this->status_nicename = $this->setup_status_nicename($invoice->post_status);  | 
                                                        
| 144 | 144 | |
| 145 | 145 | // Items  | 
                                                        
@@ -161,8 +161,8 @@ discard block  | 
                                                    ||
| 161 | 161 | |
| 162 | 162 | // User based  | 
                                                        
| 163 | 163 | $this->ip = $this->setup_ip();  | 
                                                        
| 164 | - $this->user_id = !empty( $invoice->post_author ) ? $invoice->post_author : get_current_user_id();///$this->setup_user_id();  | 
                                                        |
| 165 | - $this->email = get_the_author_meta( 'email', $this->user_id );  | 
                                                        |
| 164 | + $this->user_id = !empty($invoice->post_author) ? $invoice->post_author : get_current_user_id(); ///$this->setup_user_id();  | 
                                                        |
| 165 | +        $this->email           = get_the_author_meta('email', $this->user_id); | 
                                                        |
| 166 | 166 | |
| 167 | 167 | $this->user_info = $this->setup_user_info();  | 
                                                        
| 168 | 168 | |
@@ -171,7 +171,7 @@ discard block  | 
                                                    ||
| 171 | 171 | $this->company = $this->user_info['company'];  | 
                                                        
| 172 | 172 | $this->vat_number = $this->user_info['vat_number'];  | 
                                                        
| 173 | 173 | $this->vat_rate = $this->user_info['vat_rate'];  | 
                                                        
| 174 | - $this->adddress_confirmed = $this->user_info['adddress_confirmed'];  | 
                                                        |
| 174 | + $this->adddress_confirmed = $this->user_info['adddress_confirmed'];  | 
                                                        |
| 175 | 175 | $this->address = $this->user_info['address'];  | 
                                                        
| 176 | 176 | $this->city = $this->user_info['city'];  | 
                                                        
| 177 | 177 | $this->country = $this->user_info['country'];  | 
                                                        
@@ -186,47 +186,47 @@ discard block  | 
                                                    ||
| 186 | 186 | // Other Identifiers  | 
                                                        
| 187 | 187 | $this->key = $this->setup_invoice_key();  | 
                                                        
| 188 | 188 | $this->number = $this->setup_invoice_number();  | 
                                                        
| 189 | - $this->title = !empty( $invoice->post_title ) ? $invoice->post_title : $this->number;  | 
                                                        |
| 189 | + $this->title = !empty($invoice->post_title) ? $invoice->post_title : $this->number;  | 
                                                        |
| 190 | 190 | |
| 191 | - $this->full_name = trim( $this->first_name . ' '. $this->last_name );  | 
                                                        |
| 191 | + $this->full_name = trim($this->first_name . ' ' . $this->last_name);  | 
                                                        |
| 192 | 192 | |
| 193 | 193 | // Allow extensions to add items to this object via hook  | 
                                                        
| 194 | - do_action( 'wpinv_setup_invoice', $this, $invoice_id );  | 
                                                        |
| 194 | +        do_action('wpinv_setup_invoice', $this, $invoice_id); | 
                                                        |
| 195 | 195 | |
| 196 | 196 | return true;  | 
                                                        
| 197 | 197 | }  | 
                                                        
| 198 | 198 | |
| 199 | 199 |      private function setup_status_nicename($status) { | 
                                                        
| 200 | - $all_invoice_statuses = wpinv_get_invoice_statuses();  | 
                                                        |
| 201 | - $status = isset( $all_invoice_statuses[$status] ) ? $all_invoice_statuses[$status] : __( $status, 'invoicing' );  | 
                                                        |
| 200 | + $all_invoice_statuses = wpinv_get_invoice_statuses();  | 
                                                        |
| 201 | + $status = isset($all_invoice_statuses[$status]) ? $all_invoice_statuses[$status] : __($status, 'invoicing');  | 
                                                        |
| 202 | 202 | |
| 203 | - return apply_filters( 'setup_status_nicename', $status );  | 
                                                        |
| 203 | +        return apply_filters('setup_status_nicename', $status); | 
                                                        |
| 204 | 204 | }  | 
                                                        
| 205 | 205 | |
| 206 | -    private function setup_post_name( $post = NULL ) { | 
                                                        |
| 206 | +    private function setup_post_name($post = NULL) { | 
                                                        |
| 207 | 207 | $post_name = '';  | 
                                                        
| 208 | 208 | |
| 209 | -        if ( !empty( $post ) ) { | 
                                                        |
| 210 | -            if( !empty( $post->post_name ) ) { | 
                                                        |
| 209 | +        if (!empty($post)) { | 
                                                        |
| 210 | +            if (!empty($post->post_name)) { | 
                                                        |
| 211 | 211 | $post_name = $post->post_name;  | 
                                                        
| 212 | -            } else if ( !empty( $post->ID ) && !empty( $post->post_title ) ) { | 
                                                        |
| 213 | - $post_name = sanitize_title( $post->post_title );  | 
                                                        |
| 212 | +            } else if (!empty($post->ID) && !empty($post->post_title)) { | 
                                                        |
| 213 | + $post_name = sanitize_title($post->post_title);  | 
                                                        |
| 214 | 214 | |
| 215 | 215 | global $wpdb;  | 
                                                        
| 216 | - $wpdb->update( $wpdb->posts, array( 'post_name' => $post_name ), array( 'ID' => $post->ID ) );  | 
                                                        |
| 216 | +                $wpdb->update($wpdb->posts, array('post_name' => $post_name), array('ID' => $post->ID)); | 
                                                        |
| 217 | 217 | }  | 
                                                        
| 218 | 218 | }  | 
                                                        
| 219 | 219 | |
| 220 | - $this->post_name = $post_name;  | 
                                                        |
| 220 | + $this->post_name = $post_name;  | 
                                                        |
| 221 | 221 | }  | 
                                                        
| 222 | 222 | |
| 223 | 223 |      private function setup_due_date() { | 
                                                        
| 224 | - $due_date = $this->get_meta( '_wpinv_due_date' );  | 
                                                        |
| 224 | +        $due_date = $this->get_meta('_wpinv_due_date'); | 
                                                        |
| 225 | 225 | |
| 226 | -        if ( empty( $due_date ) ) { | 
                                                        |
| 227 | - $overdue_time = strtotime( $this->date ) + ( DAY_IN_SECONDS * absint( wpinv_get_option( 'overdue_days' ) ) );  | 
                                                        |
| 228 | - $due_date = date_i18n( 'Y-m-d', $overdue_time );  | 
                                                        |
| 229 | -        } else if ( $due_date == 'none' ) { | 
                                                        |
| 226 | +        if (empty($due_date)) { | 
                                                        |
| 227 | +            $overdue_time = strtotime($this->date) + (DAY_IN_SECONDS * absint(wpinv_get_option('overdue_days'))); | 
                                                        |
| 228 | +            $due_date = date_i18n('Y-m-d', $overdue_time); | 
                                                        |
| 229 | +        } else if ($due_date == 'none') { | 
                                                        |
| 230 | 230 | $due_date = '';  | 
                                                        
| 231 | 231 | }  | 
                                                        
| 232 | 232 | |
@@ -234,63 +234,63 @@ discard block  | 
                                                    ||
| 234 | 234 | }  | 
                                                        
| 235 | 235 | |
| 236 | 236 |      private function setup_completed_date() { | 
                                                        
| 237 | - $invoice = get_post( $this->ID );  | 
                                                        |
| 237 | + $invoice = get_post($this->ID);  | 
                                                        |
| 238 | 238 | |
| 239 | -        if ( 'pending' == $invoice->post_status || 'preapproved' == $invoice->post_status ) { | 
                                                        |
| 239 | +        if ('pending' == $invoice->post_status || 'preapproved' == $invoice->post_status) { | 
                                                        |
| 240 | 240 | return false; // This invoice was never paid  | 
                                                        
| 241 | 241 | }  | 
                                                        
| 242 | 242 | |
| 243 | - $date = ( $date = $this->get_meta( '_wpinv_completed_date', true ) ) ? $date : $invoice->modified_date;  | 
                                                        |
| 243 | +        $date = ($date = $this->get_meta('_wpinv_completed_date', true)) ? $date : $invoice->modified_date; | 
                                                        |
| 244 | 244 | |
| 245 | 245 | return $date;  | 
                                                        
| 246 | 246 | }  | 
                                                        
| 247 | 247 | |
| 248 | 248 |      private function setup_cart_details() { | 
                                                        
| 249 | - $cart_details = isset( $this->payment_meta['cart_details'] ) ? maybe_unserialize( $this->payment_meta['cart_details'] ) : array();  | 
                                                        |
| 249 | + $cart_details = isset($this->payment_meta['cart_details']) ? maybe_unserialize($this->payment_meta['cart_details']) : array();  | 
                                                        |
| 250 | 250 | return $cart_details;  | 
                                                        
| 251 | 251 | }  | 
                                                        
| 252 | 252 | |
| 253 | 253 |      public function array_convert() { | 
                                                        
| 254 | - return get_object_vars( $this );  | 
                                                        |
| 254 | + return get_object_vars($this);  | 
                                                        |
| 255 | 255 | }  | 
                                                        
| 256 | 256 | |
| 257 | 257 |      private function setup_items() { | 
                                                        
| 258 | - $items = isset( $this->payment_meta['items'] ) ? maybe_unserialize( $this->payment_meta['items'] ) : array();  | 
                                                        |
| 258 | + $items = isset($this->payment_meta['items']) ? maybe_unserialize($this->payment_meta['items']) : array();  | 
                                                        |
| 259 | 259 | return $items;  | 
                                                        
| 260 | 260 | }  | 
                                                        
| 261 | 261 | |
| 262 | 262 |      private function setup_fees() { | 
                                                        
| 263 | - $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array();  | 
                                                        |
| 263 | + $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array();  | 
                                                        |
| 264 | 264 | return $payment_fees;  | 
                                                        
| 265 | 265 | }  | 
                                                        
| 266 | 266 | |
| 267 | 267 |      private function setup_currency() { | 
                                                        
| 268 | - $currency = isset( $this->payment_meta['currency'] ) ? $this->payment_meta['currency'] : apply_filters( 'wpinv_currency_default', wpinv_get_currency(), $this );  | 
                                                        |
| 268 | +        $currency = isset($this->payment_meta['currency']) ? $this->payment_meta['currency'] : apply_filters('wpinv_currency_default', wpinv_get_currency(), $this); | 
                                                        |
| 269 | 269 | return $currency;  | 
                                                        
| 270 | 270 | }  | 
                                                        
| 271 | 271 | |
| 272 | 272 |      private function setup_discount() { | 
                                                        
| 273 | 273 | //$discount = $this->get_meta( '_wpinv_discount', true );  | 
                                                        
| 274 | - $discount = (float)$this->subtotal - ( (float)$this->total - (float)$this->tax - (float)$this->fees_total );  | 
                                                        |
| 275 | -        if ( $discount < 0 ) { | 
                                                        |
| 274 | + $discount = (float)$this->subtotal - ((float)$this->total - (float)$this->tax - (float)$this->fees_total);  | 
                                                        |
| 275 | +        if ($discount < 0) { | 
                                                        |
| 276 | 276 | $discount = 0;  | 
                                                        
| 277 | 277 | }  | 
                                                        
| 278 | - $discount = wpinv_round_amount( $discount );  | 
                                                        |
| 278 | + $discount = wpinv_round_amount($discount);  | 
                                                        |
| 279 | 279 | |
| 280 | 280 | return $discount;  | 
                                                        
| 281 | 281 | }  | 
                                                        
| 282 | 282 | |
| 283 | 283 |      private function setup_discount_code() { | 
                                                        
| 284 | - $discount_code = !empty( $this->discounts ) ? $this->discounts : $this->get_meta( '_wpinv_discount_code', true );  | 
                                                        |
| 284 | +        $discount_code = !empty($this->discounts) ? $this->discounts : $this->get_meta('_wpinv_discount_code', true); | 
                                                        |
| 285 | 285 | return $discount_code;  | 
                                                        
| 286 | 286 | }  | 
                                                        
| 287 | 287 | |
| 288 | 288 |      private function setup_tax() { | 
                                                        
| 289 | - $tax = $this->get_meta( '_wpinv_tax', true );  | 
                                                        |
| 289 | +        $tax = $this->get_meta('_wpinv_tax', true); | 
                                                        |
| 290 | 290 | |
| 291 | 291 | // We don't have tax as it's own meta and no meta was passed  | 
                                                        
| 292 | -        if ( '' === $tax ) {             | 
                                                        |
| 293 | - $tax = isset( $this->payment_meta['tax'] ) ? $this->payment_meta['tax'] : 0;  | 
                                                        |
| 292 | +        if ('' === $tax) {             | 
                                                        |
| 293 | + $tax = isset($this->payment_meta['tax']) ? $this->payment_meta['tax'] : 0;  | 
                                                        |
| 294 | 294 | }  | 
                                                        
| 295 | 295 | |
| 296 | 296 | return $tax;  | 
                                                        
@@ -300,9 +300,9 @@ discard block  | 
                                                    ||
| 300 | 300 | $subtotal = 0;  | 
                                                        
| 301 | 301 | $cart_details = $this->cart_details;  | 
                                                        
| 302 | 302 | |
| 303 | -        if ( is_array( $cart_details ) ) { | 
                                                        |
| 304 | -            foreach ( $cart_details as $item ) { | 
                                                        |
| 305 | -                if ( isset( $item['subtotal'] ) ) { | 
                                                        |
| 303 | +        if (is_array($cart_details)) { | 
                                                        |
| 304 | +            foreach ($cart_details as $item) { | 
                                                        |
| 305 | +                if (isset($item['subtotal'])) { | 
                                                        |
| 306 | 306 | $subtotal += $item['subtotal'];  | 
                                                        
| 307 | 307 | }  | 
                                                        
| 308 | 308 | }  | 
                                                        
@@ -316,18 +316,18 @@ discard block  | 
                                                    ||
| 316 | 316 | }  | 
                                                        
| 317 | 317 | |
| 318 | 318 |      private function setup_discounts() { | 
                                                        
| 319 | - $discounts = ! empty( $this->payment_meta['user_info']['discount'] ) ? $this->payment_meta['user_info']['discount'] : array();  | 
                                                        |
| 319 | + $discounts = !empty($this->payment_meta['user_info']['discount']) ? $this->payment_meta['user_info']['discount'] : array();  | 
                                                        |
| 320 | 320 | return $discounts;  | 
                                                        
| 321 | 321 | }  | 
                                                        
| 322 | 322 | |
| 323 | 323 |      private function setup_total() { | 
                                                        
| 324 | - $amount = $this->get_meta( '_wpinv_total', true );  | 
                                                        |
| 324 | +        $amount = $this->get_meta('_wpinv_total', true); | 
                                                        |
| 325 | 325 | |
| 326 | -        if ( empty( $amount ) && '0.00' != $amount ) { | 
                                                        |
| 327 | - $meta = $this->get_meta( '_wpinv_payment_meta', true );  | 
                                                        |
| 328 | - $meta = maybe_unserialize( $meta );  | 
                                                        |
| 326 | +        if (empty($amount) && '0.00' != $amount) { | 
                                                        |
| 327 | +            $meta   = $this->get_meta('_wpinv_payment_meta', true); | 
                                                        |
| 328 | + $meta = maybe_unserialize($meta);  | 
                                                        |
| 329 | 329 | |
| 330 | -            if ( isset( $meta['amount'] ) ) { | 
                                                        |
| 330 | +            if (isset($meta['amount'])) { | 
                                                        |
| 331 | 331 | $amount = $meta['amount'];  | 
                                                        
| 332 | 332 | }  | 
                                                        
| 333 | 333 | }  | 
                                                        
@@ -336,13 +336,13 @@ discard block  | 
                                                    ||
| 336 | 336 | }  | 
                                                        
| 337 | 337 | |
| 338 | 338 |      private function setup_mode() { | 
                                                        
| 339 | - return $this->get_meta( '_wpinv_mode' );  | 
                                                        |
| 339 | +        return $this->get_meta('_wpinv_mode'); | 
                                                        |
| 340 | 340 | }  | 
                                                        
| 341 | 341 | |
| 342 | 342 |      private function setup_gateway() { | 
                                                        
| 343 | - $gateway = $this->get_meta( '_wpinv_gateway' );  | 
                                                        |
| 343 | +        $gateway = $this->get_meta('_wpinv_gateway'); | 
                                                        |
| 344 | 344 | |
| 345 | -        if ( empty( $gateway ) && 'publish' === $this->status ) { | 
                                                        |
| 345 | +        if (empty($gateway) && 'publish' === $this->status) { | 
                                                        |
| 346 | 346 | $gateway = 'manual';  | 
                                                        
| 347 | 347 | }  | 
                                                        
| 348 | 348 | |
@@ -350,23 +350,23 @@ discard block  | 
                                                    ||
| 350 | 350 | }  | 
                                                        
| 351 | 351 | |
| 352 | 352 |      private function setup_gateway_title() { | 
                                                        
| 353 | - $gateway_title = wpinv_get_gateway_checkout_label( $this->gateway );  | 
                                                        |
| 353 | + $gateway_title = wpinv_get_gateway_checkout_label($this->gateway);  | 
                                                        |
| 354 | 354 | return $gateway_title;  | 
                                                        
| 355 | 355 | }  | 
                                                        
| 356 | 356 | |
| 357 | 357 |      private function setup_transaction_id() { | 
                                                        
| 358 | - $transaction_id = $this->get_meta( '_wpinv_transaction_id' );  | 
                                                        |
| 358 | +        $transaction_id = $this->get_meta('_wpinv_transaction_id'); | 
                                                        |
| 359 | 359 | |
| 360 | -        if ( empty( $transaction_id ) || (int) $transaction_id === (int) $this->ID ) { | 
                                                        |
| 360 | +        if (empty($transaction_id) || (int)$transaction_id === (int)$this->ID) { | 
                                                        |
| 361 | 361 | $gateway = $this->gateway;  | 
                                                        
| 362 | - $transaction_id = apply_filters( 'wpinv_get_invoice_transaction_id-' . $gateway, $this->ID );  | 
                                                        |
| 362 | +            $transaction_id = apply_filters('wpinv_get_invoice_transaction_id-' . $gateway, $this->ID); | 
                                                        |
| 363 | 363 | }  | 
                                                        
| 364 | 364 | |
| 365 | 365 | return $transaction_id;  | 
                                                        
| 366 | 366 | }  | 
                                                        
| 367 | 367 | |
| 368 | 368 |      private function setup_ip() { | 
                                                        
| 369 | - $ip = $this->get_meta( '_wpinv_user_ip' );  | 
                                                        |
| 369 | +        $ip = $this->get_meta('_wpinv_user_ip'); | 
                                                        |
| 370 | 370 | return $ip;  | 
                                                        
| 371 | 371 | }  | 
                                                        
| 372 | 372 | |
@@ -376,62 +376,62 @@ discard block  | 
                                                    ||
| 376 | 376 | ///}  | 
                                                        
| 377 | 377 | |
| 378 | 378 |      private function setup_first_name() { | 
                                                        
| 379 | - $first_name = $this->get_meta( '_wpinv_first_name' );  | 
                                                        |
| 379 | +        $first_name = $this->get_meta('_wpinv_first_name'); | 
                                                        |
| 380 | 380 | return $first_name;  | 
                                                        
| 381 | 381 | }  | 
                                                        
| 382 | 382 | |
| 383 | 383 |      private function setup_last_name() { | 
                                                        
| 384 | - $last_name = $this->get_meta( '_wpinv_last_name' );  | 
                                                        |
| 384 | +        $last_name = $this->get_meta('_wpinv_last_name'); | 
                                                        |
| 385 | 385 | return $last_name;  | 
                                                        
| 386 | 386 | }  | 
                                                        
| 387 | 387 | |
| 388 | 388 |      private function setup_company() { | 
                                                        
| 389 | - $company = $this->get_meta( '_wpinv_company' );  | 
                                                        |
| 389 | +        $company = $this->get_meta('_wpinv_company'); | 
                                                        |
| 390 | 390 | return $company;  | 
                                                        
| 391 | 391 | }  | 
                                                        
| 392 | 392 | |
| 393 | 393 |      private function setup_vat_number() { | 
                                                        
| 394 | - $vat_number = $this->get_meta( '_wpinv_vat_number' );  | 
                                                        |
| 394 | +        $vat_number = $this->get_meta('_wpinv_vat_number'); | 
                                                        |
| 395 | 395 | return $vat_number;  | 
                                                        
| 396 | 396 | }  | 
                                                        
| 397 | 397 | |
| 398 | 398 |      private function setup_vat_rate() { | 
                                                        
| 399 | - $vat_rate = $this->get_meta( '_wpinv_vat_rate' );  | 
                                                        |
| 399 | +        $vat_rate = $this->get_meta('_wpinv_vat_rate'); | 
                                                        |
| 400 | 400 | return $vat_rate;  | 
                                                        
| 401 | 401 | }  | 
                                                        
| 402 | 402 | |
| 403 | 403 |      private function setup_adddress_confirmed() { | 
                                                        
| 404 | - $adddress_confirmed = $this->get_meta( '_wpinv_adddress_confirmed' );  | 
                                                        |
| 404 | +        $adddress_confirmed = $this->get_meta('_wpinv_adddress_confirmed'); | 
                                                        |
| 405 | 405 | return $adddress_confirmed;  | 
                                                        
| 406 | 406 | }  | 
                                                        
| 407 | 407 | |
| 408 | 408 |      private function setup_phone() { | 
                                                        
| 409 | - $phone = $this->get_meta( '_wpinv_phone' );  | 
                                                        |
| 409 | +        $phone = $this->get_meta('_wpinv_phone'); | 
                                                        |
| 410 | 410 | return $phone;  | 
                                                        
| 411 | 411 | }  | 
                                                        
| 412 | 412 | |
| 413 | 413 |      private function setup_address() { | 
                                                        
| 414 | - $address = $this->get_meta( '_wpinv_address', true );  | 
                                                        |
| 414 | +        $address = $this->get_meta('_wpinv_address', true); | 
                                                        |
| 415 | 415 | return $address;  | 
                                                        
| 416 | 416 | }  | 
                                                        
| 417 | 417 | |
| 418 | 418 |      private function setup_city() { | 
                                                        
| 419 | - $city = $this->get_meta( '_wpinv_city', true );  | 
                                                        |
| 419 | +        $city = $this->get_meta('_wpinv_city', true); | 
                                                        |
| 420 | 420 | return $city;  | 
                                                        
| 421 | 421 | }  | 
                                                        
| 422 | 422 | |
| 423 | 423 |      private function setup_country() { | 
                                                        
| 424 | - $country = $this->get_meta( '_wpinv_country', true );  | 
                                                        |
| 424 | +        $country = $this->get_meta('_wpinv_country', true); | 
                                                        |
| 425 | 425 | return $country;  | 
                                                        
| 426 | 426 | }  | 
                                                        
| 427 | 427 | |
| 428 | 428 |      private function setup_state() { | 
                                                        
| 429 | - $state = $this->get_meta( '_wpinv_state', true );  | 
                                                        |
| 429 | +        $state = $this->get_meta('_wpinv_state', true); | 
                                                        |
| 430 | 430 | return $state;  | 
                                                        
| 431 | 431 | }  | 
                                                        
| 432 | 432 | |
| 433 | 433 |      private function setup_zip() { | 
                                                        
| 434 | - $zip = $this->get_meta( '_wpinv_zip', true );  | 
                                                        |
| 434 | +        $zip = $this->get_meta('_wpinv_zip', true); | 
                                                        |
| 435 | 435 | return $zip;  | 
                                                        
| 436 | 436 | }  | 
                                                        
| 437 | 437 | |
@@ -440,7 +440,7 @@ discard block  | 
                                                    ||
| 440 | 440 | 'user_id' => $this->user_id,  | 
                                                        
| 441 | 441 | 'first_name' => $this->first_name,  | 
                                                        
| 442 | 442 | 'last_name' => $this->last_name,  | 
                                                        
| 443 | - 'email' => get_the_author_meta( 'email', $this->user_id ),  | 
                                                        |
| 443 | +            'email'          => get_the_author_meta('email', $this->user_id), | 
                                                        |
| 444 | 444 | 'phone' => $this->phone,  | 
                                                        
| 445 | 445 | 'address' => $this->address,  | 
                                                        
| 446 | 446 | 'city' => $this->city,  | 
                                                        
@@ -455,12 +455,12 @@ discard block  | 
                                                    ||
| 455 | 455 | );  | 
                                                        
| 456 | 456 | |
| 457 | 457 | $user_info = array();  | 
                                                        
| 458 | -        if ( isset( $this->payment_meta['user_info'] ) ) { | 
                                                        |
| 459 | - $user_info = maybe_unserialize( $this->payment_meta['user_info'] );  | 
                                                        |
| 458 | +        if (isset($this->payment_meta['user_info'])) { | 
                                                        |
| 459 | + $user_info = maybe_unserialize($this->payment_meta['user_info']);  | 
                                                        |
| 460 | 460 | |
| 461 | -            if ( !empty( $user_info ) && isset( $user_info['user_id'] ) && $post = get_post( $this->ID ) ) { | 
                                                        |
| 461 | +            if (!empty($user_info) && isset($user_info['user_id']) && $post = get_post($this->ID)) { | 
                                                        |
| 462 | 462 | $this->user_id = $post->post_author;  | 
                                                        
| 463 | - $this->email = get_the_author_meta( 'email', $this->user_id );  | 
                                                        |
| 463 | +                $this->email = get_the_author_meta('email', $this->user_id); | 
                                                        |
| 464 | 464 | |
| 465 | 465 | $user_info['user_id'] = $this->user_id;  | 
                                                        
| 466 | 466 | $user_info['email'] = $this->email;  | 
                                                        
@@ -469,13 +469,13 @@ discard block  | 
                                                    ||
| 469 | 469 | }  | 
                                                        
| 470 | 470 | }  | 
                                                        
| 471 | 471 | |
| 472 | - $user_info = wp_parse_args( $user_info, $defaults );  | 
                                                        |
| 472 | + $user_info = wp_parse_args($user_info, $defaults);  | 
                                                        |
| 473 | 473 | |
| 474 | 474 | // Get the user, but only if it's been created  | 
                                                        
| 475 | - $user = get_userdata( $this->user_id );  | 
                                                        |
| 475 | + $user = get_userdata($this->user_id);  | 
                                                        |
| 476 | 476 | |
| 477 | -        if ( !empty( $user ) && $user->ID > 0 ) { | 
                                                        |
| 478 | -            if ( empty( $user_info ) ) { | 
                                                        |
| 477 | +        if (!empty($user) && $user->ID > 0) { | 
                                                        |
| 478 | +            if (empty($user_info)) { | 
                                                        |
| 479 | 479 | $user_info = array(  | 
                                                        
| 480 | 480 | 'user_id' => $user->ID,  | 
                                                        
| 481 | 481 | 'first_name' => $user->first_name,  | 
                                                        
@@ -484,23 +484,23 @@ discard block  | 
                                                    ||
| 484 | 484 | 'discount' => '',  | 
                                                        
| 485 | 485 | );  | 
                                                        
| 486 | 486 |              } else { | 
                                                        
| 487 | -                foreach ( $user_info as $key => $value ) { | 
                                                        |
| 488 | -                    if ( ! empty( $value ) ) { | 
                                                        |
| 487 | +                foreach ($user_info as $key => $value) { | 
                                                        |
| 488 | +                    if (!empty($value)) { | 
                                                        |
| 489 | 489 | continue;  | 
                                                        
| 490 | 490 | }  | 
                                                        
| 491 | 491 | |
| 492 | -                    switch( $key ) { | 
                                                        |
| 492 | +                    switch ($key) { | 
                                                        |
| 493 | 493 | case 'user_id':  | 
                                                        
| 494 | - $user_info[ $key ] = $user->ID;  | 
                                                        |
| 494 | + $user_info[$key] = $user->ID;  | 
                                                        |
| 495 | 495 | break;  | 
                                                        
| 496 | 496 | case 'first_name':  | 
                                                        
| 497 | - $user_info[ $key ] = $user->first_name;  | 
                                                        |
| 497 | + $user_info[$key] = $user->first_name;  | 
                                                        |
| 498 | 498 | break;  | 
                                                        
| 499 | 499 | case 'last_name':  | 
                                                        
| 500 | - $user_info[ $key ] = $user->last_name;  | 
                                                        |
| 500 | + $user_info[$key] = $user->last_name;  | 
                                                        |
| 501 | 501 | break;  | 
                                                        
| 502 | 502 | case 'email':  | 
                                                        
| 503 | - $user_info[ $key ] = $user->user_email;  | 
                                                        |
| 503 | + $user_info[$key] = $user->user_email;  | 
                                                        |
| 504 | 504 | break;  | 
                                                        
| 505 | 505 | }  | 
                                                        
| 506 | 506 | }  | 
                                                        
@@ -511,16 +511,16 @@ discard block  | 
                                                    ||
| 511 | 511 | }  | 
                                                        
| 512 | 512 | |
| 513 | 513 |      private function setup_invoice_key() { | 
                                                        
| 514 | - $key = $this->get_meta( '_wpinv_key', true );  | 
                                                        |
| 514 | +        $key = $this->get_meta('_wpinv_key', true); | 
                                                        |
| 515 | 515 | |
| 516 | 516 | return $key;  | 
                                                        
| 517 | 517 | }  | 
                                                        
| 518 | 518 | |
| 519 | 519 |      private function setup_invoice_number() { | 
                                                        
| 520 | - $number = $this->get_meta( '_wpinv_number', true );  | 
                                                        |
| 520 | +        $number = $this->get_meta('_wpinv_number', true); | 
                                                        |
| 521 | 521 | |
| 522 | -        if ( !$number ) { | 
                                                        |
| 523 | - $number = wpinv_format_invoice_number( $this->ID );  | 
                                                        |
| 522 | +        if (!$number) { | 
                                                        |
| 523 | + $number = wpinv_format_invoice_number($this->ID);  | 
                                                        |
| 524 | 524 | }  | 
                                                        
| 525 | 525 | |
| 526 | 526 | return $number;  | 
                                                        
@@ -531,18 +531,18 @@ discard block  | 
                                                    ||
| 531 | 531 | |
| 532 | 532 |          if ($number = $this->get_number()) { | 
                                                        
| 533 | 533 | $invoice_title = $number;  | 
                                                        
| 534 | -        } else if ( ! empty( $this->ID ) ) { | 
                                                        |
| 535 | - $invoice_title = wpinv_format_invoice_number( $this->ID );  | 
                                                        |
| 534 | +        } else if (!empty($this->ID)) { | 
                                                        |
| 535 | + $invoice_title = wpinv_format_invoice_number($this->ID);  | 
                                                        |
| 536 | 536 |          } else { | 
                                                        
| 537 | - $invoice_title = wpinv_format_invoice_number( 0 );  | 
                                                        |
| 537 | + $invoice_title = wpinv_format_invoice_number(0);  | 
                                                        |
| 538 | 538 | }  | 
                                                        
| 539 | 539 | |
| 540 | -        if ( empty( $this->key ) ) { | 
                                                        |
| 540 | +        if (empty($this->key)) { | 
                                                        |
| 541 | 541 | $this->key = self::generate_key();  | 
                                                        
| 542 | 542 | $this->pending['key'] = $this->key;  | 
                                                        
| 543 | 543 | }  | 
                                                        
| 544 | 544 | |
| 545 | -        if ( empty( $this->ip ) ) { | 
                                                        |
| 545 | +        if (empty($this->ip)) { | 
                                                        |
| 546 | 546 | $this->ip = wpinv_get_ip();  | 
                                                        
| 547 | 547 | $this->pending['ip'] = $this->ip;  | 
                                                        
| 548 | 548 | }  | 
                                                        
@@ -574,75 +574,75 @@ discard block  | 
                                                    ||
| 574 | 574 | 'fees' => $this->fees,  | 
                                                        
| 575 | 575 | );  | 
                                                        
| 576 | 576 | |
| 577 | - $post_name = sanitize_title( $invoice_title );  | 
                                                        |
| 577 | + $post_name = sanitize_title($invoice_title);  | 
                                                        |
| 578 | 578 | |
| 579 | 579 | $post_data = array(  | 
                                                        
| 580 | 580 | 'post_title' => $invoice_title,  | 
                                                        
| 581 | 581 | 'post_status' => $this->status,  | 
                                                        
| 582 | 582 | 'post_author' => $this->user_id,  | 
                                                        
| 583 | 583 | 'post_type' => $this->post_type,  | 
                                                        
| 584 | - 'post_date' => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time( 'mysql' ),  | 
                                                        |
| 585 | - 'post_date_gmt' => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date( $this->date ) : current_time( 'mysql', 1 ),  | 
                                                        |
| 584 | +                        'post_date'     => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time('mysql'), | 
                                                        |
| 585 | +                        'post_date_gmt' => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date($this->date) : current_time('mysql', 1), | 
                                                        |
| 586 | 586 | 'post_parent' => $this->parent_invoice,  | 
                                                        
| 587 | 587 | );  | 
                                                        
| 588 | - $args = apply_filters( 'wpinv_insert_invoice_args', $post_data, $this );  | 
                                                        |
| 588 | +        $args = apply_filters('wpinv_insert_invoice_args', $post_data, $this); | 
                                                        |
| 589 | 589 | |
| 590 | 590 | // Create a blank invoice  | 
                                                        
| 591 | -        if ( !empty( $this->ID ) ) { | 
                                                        |
| 591 | +        if (!empty($this->ID)) { | 
                                                        |
| 592 | 592 | $args['ID'] = $this->ID;  | 
                                                        
| 593 | 593 | $args['post_name'] = $post_name;  | 
                                                        
| 594 | 594 | |
| 595 | - $invoice_id = wp_update_post( $args );  | 
                                                        |
| 595 | + $invoice_id = wp_update_post($args);  | 
                                                        |
| 596 | 596 |          } else { | 
                                                        
| 597 | - $invoice_id = wp_insert_post( $args );  | 
                                                        |
| 597 | + $invoice_id = wp_insert_post($args);  | 
                                                        |
| 598 | 598 | |
| 599 | - $post_title = wpinv_format_invoice_number( $invoice_id );  | 
                                                        |
| 599 | + $post_title = wpinv_format_invoice_number($invoice_id);  | 
                                                        |
| 600 | 600 | global $wpdb;  | 
                                                        
| 601 | - $wpdb->update( $wpdb->posts, array( 'post_title' => $post_title, 'post_name' => sanitize_title( $post_title ) ), array( 'ID' => $invoice_id ) );  | 
                                                        |
| 602 | - clean_post_cache( $invoice_id );  | 
                                                        |
| 601 | +            $wpdb->update($wpdb->posts, array('post_title' => $post_title, 'post_name' => sanitize_title($post_title)), array('ID' => $invoice_id)); | 
                                                        |
| 602 | + clean_post_cache($invoice_id);  | 
                                                        |
| 603 | 603 | }  | 
                                                        
| 604 | 604 | |
| 605 | -        if ( !empty( $invoice_id ) ) {              | 
                                                        |
| 605 | +        if (!empty($invoice_id)) {              | 
                                                        |
| 606 | 606 | $this->ID = $invoice_id;  | 
                                                        
| 607 | 607 | $this->_ID = $invoice_id;  | 
                                                        
| 608 | 608 | |
| 609 | 609 | ///$this->pending['user_id'] = $this->user_id;  | 
                                                        
| 610 | -            if ( isset( $this->pending['number'] ) ) { | 
                                                        |
| 610 | +            if (isset($this->pending['number'])) { | 
                                                        |
| 611 | 611 | $this->pending['number'] = $post_name;  | 
                                                        
| 612 | 612 | }  | 
                                                        
| 613 | 613 | |
| 614 | - $this->payment_meta = apply_filters( 'wpinv_payment_meta', $this->payment_meta, $payment_data );  | 
                                                        |
| 615 | -            if ( ! empty( $this->payment_meta['fees'] ) ) { | 
                                                        |
| 616 | - $this->fees = array_merge( $this->fees, $this->payment_meta['fees'] );  | 
                                                        |
| 617 | -                foreach( $this->fees as $fee ) { | 
                                                        |
| 618 | - $this->increase_fees( $fee['amount'] );  | 
                                                        |
| 614 | +            $this->payment_meta = apply_filters('wpinv_payment_meta', $this->payment_meta, $payment_data); | 
                                                        |
| 615 | +            if (!empty($this->payment_meta['fees'])) { | 
                                                        |
| 616 | + $this->fees = array_merge($this->fees, $this->payment_meta['fees']);  | 
                                                        |
| 617 | +                foreach ($this->fees as $fee) { | 
                                                        |
| 618 | + $this->increase_fees($fee['amount']);  | 
                                                        |
| 619 | 619 | }  | 
                                                        
| 620 | 620 | }  | 
                                                        
| 621 | 621 | |
| 622 | - $this->update_meta( '_wpinv_payment_meta', $this->payment_meta );  | 
                                                        |
| 622 | +            $this->update_meta('_wpinv_payment_meta', $this->payment_meta);             | 
                                                        |
| 623 | 623 | $this->new = true;  | 
                                                        
| 624 | 624 | }  | 
                                                        
| 625 | 625 | |
| 626 | 626 | return $this->ID;  | 
                                                        
| 627 | 627 | }  | 
                                                        
| 628 | 628 | |
| 629 | -    public function save( $setup = false ) { | 
                                                        |
| 629 | +    public function save($setup = false) { | 
                                                        |
| 630 | 630 | global $wpi_session;  | 
                                                        
| 631 | 631 | |
| 632 | 632 | $saved = false;  | 
                                                        
| 633 | -        if ( empty( $this->items ) ) { | 
                                                        |
| 633 | +        if (empty($this->items)) { | 
                                                        |
| 634 | 634 | return $saved; // Don't save empty invoice.  | 
                                                        
| 635 | 635 | }  | 
                                                        
| 636 | 636 | |
| 637 | -        if ( empty( $this->key ) ) { | 
                                                        |
| 637 | +        if (empty($this->key)) { | 
                                                        |
| 638 | 638 | $this->key = self::generate_key();  | 
                                                        
| 639 | 639 | $this->pending['key'] = $this->key;  | 
                                                        
| 640 | 640 | }  | 
                                                        
| 641 | 641 | |
| 642 | -        if ( empty( $this->ID ) ) { | 
                                                        |
| 642 | +        if (empty($this->ID)) { | 
                                                        |
| 643 | 643 | $invoice_id = $this->insert_invoice();  | 
                                                        
| 644 | 644 | |
| 645 | -            if ( false === $invoice_id ) { | 
                                                        |
| 645 | +            if (false === $invoice_id) { | 
                                                        |
| 646 | 646 | $saved = false;  | 
                                                        
| 647 | 647 |              } else { | 
                                                        
| 648 | 648 | $this->ID = $invoice_id;  | 
                                                        
@@ -650,27 +650,27 @@ discard block  | 
                                                    ||
| 650 | 650 | }  | 
                                                        
| 651 | 651 | |
| 652 | 652 | // If we have something pending, let's save it  | 
                                                        
| 653 | -        if ( !empty( $this->pending ) ) { | 
                                                        |
| 653 | +        if (!empty($this->pending)) { | 
                                                        |
| 654 | 654 | $total_increase = 0;  | 
                                                        
| 655 | 655 | $total_decrease = 0;  | 
                                                        
| 656 | 656 | |
| 657 | -            foreach ( $this->pending as $key => $value ) { | 
                                                        |
| 658 | -                switch( $key ) { | 
                                                        |
| 657 | +            foreach ($this->pending as $key => $value) { | 
                                                        |
| 658 | +                switch ($key) { | 
                                                        |
| 659 | 659 | case 'items':  | 
                                                        
| 660 | 660 | // Update totals for pending items  | 
                                                        
| 661 | -                        foreach ( $this->pending[ $key ] as $item ) { | 
                                                        |
| 662 | -                            switch( $item['action'] ) { | 
                                                        |
| 661 | +                        foreach ($this->pending[$key] as $item) { | 
                                                        |
| 662 | +                            switch ($item['action']) { | 
                                                        |
| 663 | 663 | case 'add':  | 
                                                        
| 664 | 664 | $price = $item['price'];  | 
                                                        
| 665 | 665 | $taxes = $item['tax'];  | 
                                                        
| 666 | 666 | |
| 667 | -                                    if ( 'publish' === $this->status ) { | 
                                                        |
| 667 | +                                    if ('publish' === $this->status) { | 
                                                        |
| 668 | 668 | $total_increase += $price;  | 
                                                        
| 669 | 669 | }  | 
                                                        
| 670 | 670 | break;  | 
                                                        
| 671 | 671 | |
| 672 | 672 | case 'remove':  | 
                                                        
| 673 | -                                    if ( 'publish' === $this->status ) { | 
                                                        |
| 673 | +                                    if ('publish' === $this->status) { | 
                                                        |
| 674 | 674 | $total_decrease += $item['price'];  | 
                                                        
| 675 | 675 | }  | 
                                                        
| 676 | 676 | break;  | 
                                                        
@@ -678,16 +678,16 @@ discard block  | 
                                                    ||
| 678 | 678 | }  | 
                                                        
| 679 | 679 | break;  | 
                                                        
| 680 | 680 | case 'fees':  | 
                                                        
| 681 | -                        if ( 'publish' !== $this->status ) { | 
                                                        |
| 681 | +                        if ('publish' !== $this->status) { | 
                                                        |
| 682 | 682 | break;  | 
                                                        
| 683 | 683 | }  | 
                                                        
| 684 | 684 | |
| 685 | -                        if ( empty( $this->pending[ $key ] ) ) { | 
                                                        |
| 685 | +                        if (empty($this->pending[$key])) { | 
                                                        |
| 686 | 686 | break;  | 
                                                        
| 687 | 687 | }  | 
                                                        
| 688 | 688 | |
| 689 | -                        foreach ( $this->pending[ $key ] as $fee ) { | 
                                                        |
| 690 | -                            switch( $fee['action'] ) { | 
                                                        |
| 689 | +                        foreach ($this->pending[$key] as $fee) { | 
                                                        |
| 690 | +                            switch ($fee['action']) { | 
                                                        |
| 691 | 691 | case 'add':  | 
                                                        
| 692 | 692 | $total_increase += $fee['amount'];  | 
                                                        
| 693 | 693 | break;  | 
                                                        
@@ -699,86 +699,86 @@ discard block  | 
                                                    ||
| 699 | 699 | }  | 
                                                        
| 700 | 700 | break;  | 
                                                        
| 701 | 701 | case 'status':  | 
                                                        
| 702 | - $this->update_status( $this->status );  | 
                                                        |
| 702 | + $this->update_status($this->status);  | 
                                                        |
| 703 | 703 | break;  | 
                                                        
| 704 | 704 | case 'gateway':  | 
                                                        
| 705 | - $this->update_meta( '_wpinv_gateway', $this->gateway );  | 
                                                        |
| 705 | +                        $this->update_meta('_wpinv_gateway', $this->gateway); | 
                                                        |
| 706 | 706 | break;  | 
                                                        
| 707 | 707 | case 'mode':  | 
                                                        
| 708 | - $this->update_meta( '_wpinv_mode', $this->mode );  | 
                                                        |
| 708 | +                        $this->update_meta('_wpinv_mode', $this->mode); | 
                                                        |
| 709 | 709 | break;  | 
                                                        
| 710 | 710 | case 'transaction_id':  | 
                                                        
| 711 | - $this->update_meta( '_wpinv_transaction_id', $this->transaction_id );  | 
                                                        |
| 711 | +                        $this->update_meta('_wpinv_transaction_id', $this->transaction_id); | 
                                                        |
| 712 | 712 | break;  | 
                                                        
| 713 | 713 | case 'ip':  | 
                                                        
| 714 | - $this->update_meta( '_wpinv_user_ip', $this->ip );  | 
                                                        |
| 714 | +                        $this->update_meta('_wpinv_user_ip', $this->ip); | 
                                                        |
| 715 | 715 | break;  | 
                                                        
| 716 | 716 | ///case 'user_id':  | 
                                                        
| 717 | 717 | ///$this->update_meta( '_wpinv_user_id', $this->user_id );  | 
                                                        
| 718 | 718 | ///$this->user_info['user_id'] = $this->user_id;  | 
                                                        
| 719 | 719 | ///break;  | 
                                                        
| 720 | 720 | case 'first_name':  | 
                                                        
| 721 | - $this->update_meta( '_wpinv_first_name', $this->first_name );  | 
                                                        |
| 721 | +                        $this->update_meta('_wpinv_first_name', $this->first_name); | 
                                                        |
| 722 | 722 | $this->user_info['first_name'] = $this->first_name;  | 
                                                        
| 723 | 723 | break;  | 
                                                        
| 724 | 724 | case 'last_name':  | 
                                                        
| 725 | - $this->update_meta( '_wpinv_last_name', $this->last_name );  | 
                                                        |
| 725 | +                        $this->update_meta('_wpinv_last_name', $this->last_name); | 
                                                        |
| 726 | 726 | $this->user_info['last_name'] = $this->last_name;  | 
                                                        
| 727 | 727 | break;  | 
                                                        
| 728 | 728 | case 'phone':  | 
                                                        
| 729 | - $this->update_meta( '_wpinv_phone', $this->phone );  | 
                                                        |
| 729 | +                        $this->update_meta('_wpinv_phone', $this->phone); | 
                                                        |
| 730 | 730 | $this->user_info['phone'] = $this->phone;  | 
                                                        
| 731 | 731 | break;  | 
                                                        
| 732 | 732 | case 'address':  | 
                                                        
| 733 | - $this->update_meta( '_wpinv_address', $this->address );  | 
                                                        |
| 733 | +                        $this->update_meta('_wpinv_address', $this->address); | 
                                                        |
| 734 | 734 | $this->user_info['address'] = $this->address;  | 
                                                        
| 735 | 735 | break;  | 
                                                        
| 736 | 736 | case 'city':  | 
                                                        
| 737 | - $this->update_meta( '_wpinv_city', $this->city );  | 
                                                        |
| 737 | +                        $this->update_meta('_wpinv_city', $this->city); | 
                                                        |
| 738 | 738 | $this->user_info['city'] = $this->city;  | 
                                                        
| 739 | 739 | break;  | 
                                                        
| 740 | 740 | case 'country':  | 
                                                        
| 741 | - $this->update_meta( '_wpinv_country', $this->country );  | 
                                                        |
| 741 | +                        $this->update_meta('_wpinv_country', $this->country); | 
                                                        |
| 742 | 742 | $this->user_info['country'] = $this->country;  | 
                                                        
| 743 | 743 | break;  | 
                                                        
| 744 | 744 | case 'state':  | 
                                                        
| 745 | - $this->update_meta( '_wpinv_state', $this->state );  | 
                                                        |
| 745 | +                        $this->update_meta('_wpinv_state', $this->state); | 
                                                        |
| 746 | 746 | $this->user_info['state'] = $this->state;  | 
                                                        
| 747 | 747 | break;  | 
                                                        
| 748 | 748 | case 'zip':  | 
                                                        
| 749 | - $this->update_meta( '_wpinv_zip', $this->zip );  | 
                                                        |
| 749 | +                        $this->update_meta('_wpinv_zip', $this->zip); | 
                                                        |
| 750 | 750 | $this->user_info['zip'] = $this->zip;  | 
                                                        
| 751 | 751 | break;  | 
                                                        
| 752 | 752 | case 'company':  | 
                                                        
| 753 | - $this->update_meta( '_wpinv_company', $this->company );  | 
                                                        |
| 753 | +                        $this->update_meta('_wpinv_company', $this->company); | 
                                                        |
| 754 | 754 | $this->user_info['company'] = $this->company;  | 
                                                        
| 755 | 755 | break;  | 
                                                        
| 756 | 756 | case 'vat_number':  | 
                                                        
| 757 | - $this->update_meta( '_wpinv_vat_number', $this->vat_number );  | 
                                                        |
| 757 | +                        $this->update_meta('_wpinv_vat_number', $this->vat_number); | 
                                                        |
| 758 | 758 | $this->user_info['vat_number'] = $this->vat_number;  | 
                                                        
| 759 | 759 | |
| 760 | - $vat_info = $wpi_session->get( 'user_vat_data' );  | 
                                                        |
| 761 | -                        if ( $this->vat_number && !empty( $vat_info ) && isset( $vat_info['number'] ) && isset( $vat_info['valid'] ) && $vat_info['number'] == $this->vat_number ) { | 
                                                        |
| 762 | - $adddress_confirmed = isset( $vat_info['adddress_confirmed'] ) ? $vat_info['adddress_confirmed'] : false;  | 
                                                        |
| 763 | - $this->update_meta( '_wpinv_adddress_confirmed', (bool)$adddress_confirmed );  | 
                                                        |
| 760 | +                        $vat_info = $wpi_session->get('user_vat_data'); | 
                                                        |
| 761 | +                        if ($this->vat_number && !empty($vat_info) && isset($vat_info['number']) && isset($vat_info['valid']) && $vat_info['number'] == $this->vat_number) { | 
                                                        |
| 762 | + $adddress_confirmed = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;  | 
                                                        |
| 763 | +                            $this->update_meta('_wpinv_adddress_confirmed', (bool)$adddress_confirmed); | 
                                                        |
| 764 | 764 | $this->user_info['adddress_confirmed'] = (bool)$adddress_confirmed;  | 
                                                        
| 765 | 765 | }  | 
                                                        
| 766 | 766 | |
| 767 | 767 | break;  | 
                                                        
| 768 | 768 | case 'vat_rate':  | 
                                                        
| 769 | - $this->update_meta( '_wpinv_vat_rate', $this->vat_rate );  | 
                                                        |
| 769 | +                        $this->update_meta('_wpinv_vat_rate', $this->vat_rate); | 
                                                        |
| 770 | 770 | $this->user_info['vat_rate'] = $this->vat_rate;  | 
                                                        
| 771 | 771 | break;  | 
                                                        
| 772 | 772 | case 'adddress_confirmed':  | 
                                                        
| 773 | - $this->update_meta( '_wpinv_adddress_confirmed', $this->adddress_confirmed );  | 
                                                        |
| 773 | +                        $this->update_meta('_wpinv_adddress_confirmed', $this->adddress_confirmed); | 
                                                        |
| 774 | 774 | $this->user_info['adddress_confirmed'] = $this->adddress_confirmed;  | 
                                                        
| 775 | 775 | break;  | 
                                                        
| 776 | 776 | |
| 777 | 777 | case 'key':  | 
                                                        
| 778 | - $this->update_meta( '_wpinv_key', $this->key );  | 
                                                        |
| 778 | +                        $this->update_meta('_wpinv_key', $this->key); | 
                                                        |
| 779 | 779 | break;  | 
                                                        
| 780 | 780 | case 'number':  | 
                                                        
| 781 | - $this->update_meta( '_wpinv_number', $this->number );  | 
                                                        |
| 781 | +                        $this->update_meta('_wpinv_number', $this->number); | 
                                                        |
| 782 | 782 | break;  | 
                                                        
| 783 | 783 | case 'date':  | 
                                                        
| 784 | 784 | $args = array(  | 
                                                        
@@ -787,34 +787,34 @@ discard block  | 
                                                    ||
| 787 | 787 | 'edit_date' => true,  | 
                                                        
| 788 | 788 | );  | 
                                                        
| 789 | 789 | |
| 790 | - wp_update_post( $args );  | 
                                                        |
| 790 | + wp_update_post($args);  | 
                                                        |
| 791 | 791 | break;  | 
                                                        
| 792 | 792 | case 'due_date':  | 
                                                        
| 793 | -                        if ( empty( $this->due_date ) ) { | 
                                                        |
| 793 | +                        if (empty($this->due_date)) { | 
                                                        |
| 794 | 794 | $this->due_date = 'none';  | 
                                                        
| 795 | 795 | }  | 
                                                        
| 796 | 796 | |
| 797 | - $this->update_meta( '_wpinv_due_date', $this->due_date );  | 
                                                        |
| 797 | +                        $this->update_meta('_wpinv_due_date', $this->due_date); | 
                                                        |
| 798 | 798 | break;  | 
                                                        
| 799 | 799 | case 'completed_date':  | 
                                                        
| 800 | - $this->update_meta( '_wpinv_completed_date', $this->completed_date );  | 
                                                        |
| 800 | +                        $this->update_meta('_wpinv_completed_date', $this->completed_date); | 
                                                        |
| 801 | 801 | break;  | 
                                                        
| 802 | 802 | case 'discounts':  | 
                                                        
| 803 | -                        if ( ! is_array( $this->discounts ) ) { | 
                                                        |
| 804 | - $this->discounts = explode( ',', $this->discounts );  | 
                                                        |
| 803 | +                        if (!is_array($this->discounts)) { | 
                                                        |
| 804 | +                            $this->discounts = explode(',', $this->discounts); | 
                                                        |
| 805 | 805 | }  | 
                                                        
| 806 | 806 | |
| 807 | - $this->user_info['discount'] = implode( ',', $this->discounts );  | 
                                                        |
| 807 | +                        $this->user_info['discount'] = implode(',', $this->discounts); | 
                                                        |
| 808 | 808 | break;  | 
                                                        
| 809 | 809 | |
| 810 | 810 | //case 'tax':  | 
                                                        
| 811 | 811 | //$this->update_meta( '_wpinv_tax', wpinv_round_amount( $this->tax ) );  | 
                                                        
| 812 | 812 | //break;  | 
                                                        
| 813 | 813 | case 'discount':  | 
                                                        
| 814 | - $this->update_meta( '_wpinv_discount', wpinv_round_amount( $this->discount ) );  | 
                                                        |
| 814 | +                        $this->update_meta('_wpinv_discount', wpinv_round_amount($this->discount)); | 
                                                        |
| 815 | 815 | break;  | 
                                                        
| 816 | 816 | case 'discount_code':  | 
                                                        
| 817 | - $this->update_meta( '_wpinv_discount_code', $this->discount_code );  | 
                                                        |
| 817 | +                        $this->update_meta('_wpinv_discount_code', $this->discount_code); | 
                                                        |
| 818 | 818 | break;  | 
                                                        
| 819 | 819 | //case 'fees':  | 
                                                        
| 820 | 820 | //$this->update_meta( '_wpinv_fees', $this->fees );  | 
                                                        
@@ -824,19 +824,19 @@ discard block  | 
                                                    ||
| 824 | 824 | 'ID' => $this->ID,  | 
                                                        
| 825 | 825 | 'post_parent' => $this->parent_invoice,  | 
                                                        
| 826 | 826 | );  | 
                                                        
| 827 | - wp_update_post( $args );  | 
                                                        |
| 827 | + wp_update_post($args);  | 
                                                        |
| 828 | 828 | break;  | 
                                                        
| 829 | 829 | default:  | 
                                                        
| 830 | - do_action( 'wpinv_save', $this, $key );  | 
                                                        |
| 830 | +                        do_action('wpinv_save', $this, $key); | 
                                                        |
| 831 | 831 | break;  | 
                                                        
| 832 | 832 | }  | 
                                                        
| 833 | 833 | }  | 
                                                        
| 834 | 834 | |
| 835 | - $this->update_meta( '_wpinv_subtotal', wpinv_round_amount( $this->subtotal ) );  | 
                                                        |
| 836 | - $this->update_meta( '_wpinv_total', wpinv_round_amount( $this->total ) );  | 
                                                        |
| 837 | - $this->update_meta( '_wpinv_tax', wpinv_round_amount( $this->tax ) );  | 
                                                        |
| 835 | +            $this->update_meta('_wpinv_subtotal', wpinv_round_amount($this->subtotal)); | 
                                                        |
| 836 | +            $this->update_meta('_wpinv_total', wpinv_round_amount($this->total)); | 
                                                        |
| 837 | +            $this->update_meta('_wpinv_tax', wpinv_round_amount($this->tax)); | 
                                                        |
| 838 | 838 | |
| 839 | - $this->items = array_values( $this->items );  | 
                                                        |
| 839 | + $this->items = array_values($this->items);  | 
                                                        |
| 840 | 840 | |
| 841 | 841 | $new_meta = array(  | 
                                                        
| 842 | 842 | 'items' => $this->items,  | 
                                                        
@@ -847,12 +847,12 @@ discard block  | 
                                                    ||
| 847 | 847 | );  | 
                                                        
| 848 | 848 | |
| 849 | 849 | $meta = $this->get_meta();  | 
                                                        
| 850 | - $merged_meta = array_merge( $meta, $new_meta );  | 
                                                        |
| 850 | + $merged_meta = array_merge($meta, $new_meta);  | 
                                                        |
| 851 | 851 | |
| 852 | 852 | // Only save the payment meta if it's changed  | 
                                                        
| 853 | -            if ( md5( serialize( $meta ) ) !== md5( serialize( $merged_meta) ) ) { | 
                                                        |
| 854 | - $updated = $this->update_meta( '_wpinv_payment_meta', $merged_meta );  | 
                                                        |
| 855 | -                if ( false !== $updated ) { | 
                                                        |
| 853 | +            if (md5(serialize($meta)) !== md5(serialize($merged_meta))) { | 
                                                        |
| 854 | +                $updated = $this->update_meta('_wpinv_payment_meta', $merged_meta); | 
                                                        |
| 855 | +                if (false !== $updated) { | 
                                                        |
| 856 | 856 | $saved = true;  | 
                                                        
| 857 | 857 | }  | 
                                                        
| 858 | 858 | }  | 
                                                        
@@ -860,15 +860,15 @@ discard block  | 
                                                    ||
| 860 | 860 | $this->pending = array();  | 
                                                        
| 861 | 861 | $saved = true;  | 
                                                        
| 862 | 862 |          } else { | 
                                                        
| 863 | - $this->update_meta( '_wpinv_subtotal', wpinv_round_amount( $this->subtotal ) );  | 
                                                        |
| 864 | - $this->update_meta( '_wpinv_total', wpinv_round_amount( $this->total ) );  | 
                                                        |
| 865 | - $this->update_meta( '_wpinv_tax', wpinv_round_amount( $this->tax ) );  | 
                                                        |
| 863 | +            $this->update_meta('_wpinv_subtotal', wpinv_round_amount($this->subtotal)); | 
                                                        |
| 864 | +            $this->update_meta('_wpinv_total', wpinv_round_amount($this->total)); | 
                                                        |
| 865 | +            $this->update_meta('_wpinv_tax', wpinv_round_amount($this->tax)); | 
                                                        |
| 866 | 866 | }  | 
                                                        
| 867 | 867 | |
| 868 | - do_action( 'wpinv_invoice_save', $this, $saved );  | 
                                                        |
| 868 | +        do_action('wpinv_invoice_save', $this, $saved); | 
                                                        |
| 869 | 869 | |
| 870 | -        if ( true === $saved || $setup ) { | 
                                                        |
| 871 | - $this->setup_invoice( $this->ID );  | 
                                                        |
| 870 | +        if (true === $saved || $setup) { | 
                                                        |
| 871 | + $this->setup_invoice($this->ID);  | 
                                                        |
| 872 | 872 | }  | 
                                                        
| 873 | 873 | |
| 874 | 874 | $this->refresh_item_ids();  | 
                                                        
@@ -876,7 +876,7 @@ discard block  | 
                                                    ||
| 876 | 876 | return $saved;  | 
                                                        
| 877 | 877 | }  | 
                                                        
| 878 | 878 | |
| 879 | -    public function add_fee( $args, $global = true ) { | 
                                                        |
| 879 | +    public function add_fee($args, $global = true) { | 
                                                        |
| 880 | 880 | $default_args = array(  | 
                                                        
| 881 | 881 | 'label' => '',  | 
                                                        
| 882 | 882 | 'amount' => 0,  | 
                                                        
@@ -886,75 +886,75 @@ discard block  | 
                                                    ||
| 886 | 886 | 'item_id' => 0,  | 
                                                        
| 887 | 887 | );  | 
                                                        
| 888 | 888 | |
| 889 | - $fee = wp_parse_args( $args, $default_args );  | 
                                                        |
| 889 | + $fee = wp_parse_args($args, $default_args);  | 
                                                        |
| 890 | 890 | |
| 891 | -        if ( !empty( $fee['label'] ) ) { | 
                                                        |
| 891 | +        if (!empty($fee['label'])) { | 
                                                        |
| 892 | 892 | return false;  | 
                                                        
| 893 | 893 | }  | 
                                                        
| 894 | 894 | |
| 895 | - $fee['id'] = sanitize_title( $fee['label'] );  | 
                                                        |
| 895 | + $fee['id'] = sanitize_title($fee['label']);  | 
                                                        |
| 896 | 896 | |
| 897 | - $this->fees[] = $fee;  | 
                                                        |
| 897 | + $this->fees[] = $fee;  | 
                                                        |
| 898 | 898 | |
| 899 | 899 | $added_fee = $fee;  | 
                                                        
| 900 | 900 | $added_fee['action'] = 'add';  | 
                                                        
| 901 | 901 | $this->pending['fees'][] = $added_fee;  | 
                                                        
| 902 | - reset( $this->fees );  | 
                                                        |
| 902 | + reset($this->fees);  | 
                                                        |
| 903 | 903 | |
| 904 | - $this->increase_fees( $fee['amount'] );  | 
                                                        |
| 904 | + $this->increase_fees($fee['amount']);  | 
                                                        |
| 905 | 905 | return true;  | 
                                                        
| 906 | 906 | }  | 
                                                        
| 907 | 907 | |
| 908 | -    public function remove_fee( $key ) { | 
                                                        |
| 908 | +    public function remove_fee($key) { | 
                                                        |
| 909 | 909 | $removed = false;  | 
                                                        
| 910 | 910 | |
| 911 | -        if ( is_numeric( $key ) ) { | 
                                                        |
| 912 | - $removed = $this->remove_fee_by( 'index', $key );  | 
                                                        |
| 911 | +        if (is_numeric($key)) { | 
                                                        |
| 912 | +            $removed = $this->remove_fee_by('index', $key); | 
                                                        |
| 913 | 913 | }  | 
                                                        
| 914 | 914 | |
| 915 | 915 | return $removed;  | 
                                                        
| 916 | 916 | }  | 
                                                        
| 917 | 917 | |
| 918 | -    public function remove_fee_by( $key, $value, $global = false ) { | 
                                                        |
| 919 | - $allowed_fee_keys = apply_filters( 'wpinv_fee_keys', array(  | 
                                                        |
| 918 | +    public function remove_fee_by($key, $value, $global = false) { | 
                                                        |
| 919 | +        $allowed_fee_keys = apply_filters('wpinv_fee_keys', array( | 
                                                        |
| 920 | 920 | 'index', 'label', 'amount', 'type',  | 
                                                        
| 921 | - ) );  | 
                                                        |
| 921 | + ));  | 
                                                        |
| 922 | 922 | |
| 923 | -        if ( ! in_array( $key, $allowed_fee_keys ) ) { | 
                                                        |
| 923 | +        if (!in_array($key, $allowed_fee_keys)) { | 
                                                        |
| 924 | 924 | return false;  | 
                                                        
| 925 | 925 | }  | 
                                                        
| 926 | 926 | |
| 927 | 927 | $removed = false;  | 
                                                        
| 928 | -        if ( 'index' === $key && array_key_exists( $value, $this->fees ) ) { | 
                                                        |
| 929 | - $removed_fee = $this->fees[ $value ];  | 
                                                        |
| 928 | +        if ('index' === $key && array_key_exists($value, $this->fees)) { | 
                                                        |
| 929 | + $removed_fee = $this->fees[$value];  | 
                                                        |
| 930 | 930 | $removed_fee['action'] = 'remove';  | 
                                                        
| 931 | 931 | $this->pending['fees'][] = $removed_fee;  | 
                                                        
| 932 | 932 | |
| 933 | - $this->decrease_fees( $removed_fee['amount'] );  | 
                                                        |
| 933 | + $this->decrease_fees($removed_fee['amount']);  | 
                                                        |
| 934 | 934 | |
| 935 | - unset( $this->fees[ $value ] );  | 
                                                        |
| 935 | + unset($this->fees[$value]);  | 
                                                        |
| 936 | 936 | $removed = true;  | 
                                                        
| 937 | -        } else if ( 'index' !== $key ) { | 
                                                        |
| 938 | -            foreach ( $this->fees as $index => $fee ) { | 
                                                        |
| 939 | -                if ( isset( $fee[ $key ] ) && $fee[ $key ] == $value ) { | 
                                                        |
| 937 | +        } else if ('index' !== $key) { | 
                                                        |
| 938 | +            foreach ($this->fees as $index => $fee) { | 
                                                        |
| 939 | +                if (isset($fee[$key]) && $fee[$key] == $value) { | 
                                                        |
| 940 | 940 | $removed_fee = $fee;  | 
                                                        
| 941 | 941 | $removed_fee['action'] = 'remove';  | 
                                                        
| 942 | 942 | $this->pending['fees'][] = $removed_fee;  | 
                                                        
| 943 | 943 | |
| 944 | - $this->decrease_fees( $removed_fee['amount'] );  | 
                                                        |
| 944 | + $this->decrease_fees($removed_fee['amount']);  | 
                                                        |
| 945 | 945 | |
| 946 | - unset( $this->fees[ $index ] );  | 
                                                        |
| 946 | + unset($this->fees[$index]);  | 
                                                        |
| 947 | 947 | $removed = true;  | 
                                                        
| 948 | 948 | |
| 949 | -                    if ( false === $global ) { | 
                                                        |
| 949 | +                    if (false === $global) { | 
                                                        |
| 950 | 950 | break;  | 
                                                        
| 951 | 951 | }  | 
                                                        
| 952 | 952 | }  | 
                                                        
| 953 | 953 | }  | 
                                                        
| 954 | 954 | }  | 
                                                        
| 955 | 955 | |
| 956 | -        if ( true === $removed ) { | 
                                                        |
| 957 | - $this->fees = array_values( $this->fees );  | 
                                                        |
| 956 | +        if (true === $removed) { | 
                                                        |
| 957 | + $this->fees = array_values($this->fees);  | 
                                                        |
| 958 | 958 | }  | 
                                                        
| 959 | 959 | |
| 960 | 960 | return $removed;  | 
                                                        
@@ -962,35 +962,35 @@ discard block  | 
                                                    ||
| 962 | 962 | |
| 963 | 963 | |
| 964 | 964 | |
| 965 | -    public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) { | 
                                                        |
| 965 | +    public function add_note($note = '', $customer_type = false, $added_by_user = false, $system = false) { | 
                                                        |
| 966 | 966 | // Bail if no note specified  | 
                                                        
| 967 | -        if( !$note ) { | 
                                                        |
| 967 | +        if (!$note) { | 
                                                        |
| 968 | 968 | return false;  | 
                                                        
| 969 | 969 | }  | 
                                                        
| 970 | 970 | |
| 971 | - if ( empty( $this->ID ) )  | 
                                                        |
| 971 | + if (empty($this->ID))  | 
                                                        |
| 972 | 972 | return false;  | 
                                                        
| 973 | 973 | |
| 974 | -        if ( ( ( is_user_logged_in() && current_user_can( 'manage_options' ) ) || $added_by_user ) && !$system ) { | 
                                                        |
| 975 | - $user = get_user_by( 'id', get_current_user_id() );  | 
                                                        |
| 974 | +        if (((is_user_logged_in() && current_user_can('manage_options')) || $added_by_user) && !$system) { | 
                                                        |
| 975 | +            $user                 = get_user_by('id', get_current_user_id()); | 
                                                        |
| 976 | 976 | $comment_author = $user->display_name;  | 
                                                        
| 977 | 977 | $comment_author_email = $user->user_email;  | 
                                                        
| 978 | 978 |          } else { | 
                                                        
| 979 | - $comment_author = __( 'System', 'invoicing' );  | 
                                                        |
| 980 | - $comment_author_email = strtolower( __( 'System', 'invoicing' ) ) . '@';  | 
                                                        |
| 981 | - $comment_author_email .= isset( $_SERVER['HTTP_HOST'] ) ? str_replace( 'www.', '', $_SERVER['HTTP_HOST'] ) : 'noreply.com';  | 
                                                        |
| 982 | - $comment_author_email = sanitize_email( $comment_author_email );  | 
                                                        |
| 979 | +            $comment_author       = __('System', 'invoicing'); | 
                                                        |
| 980 | +            $comment_author_email = strtolower(__('System', 'invoicing')) . '@'; | 
                                                        |
| 981 | +            $comment_author_email .= isset($_SERVER['HTTP_HOST']) ? str_replace('www.', '', $_SERVER['HTTP_HOST']) : 'noreply.com'; | 
                                                        |
| 982 | + $comment_author_email = sanitize_email($comment_author_email);  | 
                                                        |
| 983 | 983 | }  | 
                                                        
| 984 | 984 | |
| 985 | - do_action( 'wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type );  | 
                                                        |
| 985 | +        do_action('wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type); | 
                                                        |
| 986 | 986 | |
| 987 | - $note_id = wp_insert_comment( wp_filter_comment( array(  | 
                                                        |
| 987 | + $note_id = wp_insert_comment(wp_filter_comment(array(  | 
                                                        |
| 988 | 988 | 'comment_post_ID' => $this->ID,  | 
                                                        
| 989 | 989 | 'comment_content' => $note,  | 
                                                        
| 990 | 990 | 'comment_agent' => 'GeoDirectory',  | 
                                                        
| 991 | 991 | 'user_id' => is_admin() ? get_current_user_id() : 0,  | 
                                                        
| 992 | - 'comment_date' => current_time( 'mysql' ),  | 
                                                        |
| 993 | - 'comment_date_gmt' => current_time( 'mysql', 1 ),  | 
                                                        |
| 992 | +            'comment_date'         => current_time('mysql'), | 
                                                        |
| 993 | +            'comment_date_gmt'     => current_time('mysql', 1), | 
                                                        |
| 994 | 994 | 'comment_approved' => 1,  | 
                                                        
| 995 | 995 | 'comment_parent' => 0,  | 
                                                        
| 996 | 996 | 'comment_author' => $comment_author,  | 
                                                        
@@ -998,53 +998,53 @@ discard block  | 
                                                    ||
| 998 | 998 | 'comment_author_url' => '',  | 
                                                        
| 999 | 999 | 'comment_author_email' => $comment_author_email,  | 
                                                        
| 1000 | 1000 | 'comment_type' => 'wpinv_note'  | 
                                                        
| 1001 | - ) ) );  | 
                                                        |
| 1001 | + )));  | 
                                                        |
| 1002 | 1002 | |
| 1003 | - do_action( 'wpinv_insert_payment_note', $note_id, $this->ID, $note );  | 
                                                        |
| 1003 | +        do_action('wpinv_insert_payment_note', $note_id, $this->ID, $note); | 
                                                        |
| 1004 | 1004 | |
| 1005 | -        if ( $customer_type ) { | 
                                                        |
| 1006 | - add_comment_meta( $note_id, '_wpi_customer_note', 1 );  | 
                                                        |
| 1005 | +        if ($customer_type) { | 
                                                        |
| 1006 | + add_comment_meta($note_id, '_wpi_customer_note', 1);  | 
                                                        |
| 1007 | 1007 | |
| 1008 | - do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $this->ID, 'user_note' => $note ) );  | 
                                                        |
| 1008 | +            do_action('wpinv_new_customer_note', array('invoice_id' => $this->ID, 'user_note' => $note)); | 
                                                        |
| 1009 | 1009 | }  | 
                                                        
| 1010 | 1010 | |
| 1011 | 1011 | return $note_id;  | 
                                                        
| 1012 | 1012 | }  | 
                                                        
| 1013 | 1013 | |
| 1014 | -    private function increase_subtotal( $amount = 0.00 ) { | 
                                                        |
| 1015 | - $amount = (float) $amount;  | 
                                                        |
| 1014 | +    private function increase_subtotal($amount = 0.00) { | 
                                                        |
| 1015 | + $amount = (float)$amount;  | 
                                                        |
| 1016 | 1016 | $this->subtotal += $amount;  | 
                                                        
| 1017 | - $this->subtotal = wpinv_round_amount( $this->subtotal );  | 
                                                        |
| 1017 | + $this->subtotal = wpinv_round_amount($this->subtotal);  | 
                                                        |
| 1018 | 1018 | |
| 1019 | 1019 | $this->recalculate_total();  | 
                                                        
| 1020 | 1020 | }  | 
                                                        
| 1021 | 1021 | |
| 1022 | -    private function decrease_subtotal( $amount = 0.00 ) { | 
                                                        |
| 1023 | - $amount = (float) $amount;  | 
                                                        |
| 1022 | +    private function decrease_subtotal($amount = 0.00) { | 
                                                        |
| 1023 | + $amount = (float)$amount;  | 
                                                        |
| 1024 | 1024 | $this->subtotal -= $amount;  | 
                                                        
| 1025 | - $this->subtotal = wpinv_round_amount( $this->subtotal );  | 
                                                        |
| 1025 | + $this->subtotal = wpinv_round_amount($this->subtotal);  | 
                                                        |
| 1026 | 1026 | |
| 1027 | -        if ( $this->subtotal < 0 ) { | 
                                                        |
| 1027 | +        if ($this->subtotal < 0) { | 
                                                        |
| 1028 | 1028 | $this->subtotal = 0;  | 
                                                        
| 1029 | 1029 | }  | 
                                                        
| 1030 | 1030 | |
| 1031 | 1031 | $this->recalculate_total();  | 
                                                        
| 1032 | 1032 | }  | 
                                                        
| 1033 | 1033 | |
| 1034 | -    private function increase_fees( $amount = 0.00 ) { | 
                                                        |
| 1034 | +    private function increase_fees($amount = 0.00) { | 
                                                        |
| 1035 | 1035 | $amount = (float)$amount;  | 
                                                        
| 1036 | 1036 | $this->fees_total += $amount;  | 
                                                        
| 1037 | - $this->fees_total = wpinv_round_amount( $this->fees_total );  | 
                                                        |
| 1037 | + $this->fees_total = wpinv_round_amount($this->fees_total);  | 
                                                        |
| 1038 | 1038 | |
| 1039 | 1039 | $this->recalculate_total();  | 
                                                        
| 1040 | 1040 | }  | 
                                                        
| 1041 | 1041 | |
| 1042 | -    private function decrease_fees( $amount = 0.00 ) { | 
                                                        |
| 1043 | - $amount = (float) $amount;  | 
                                                        |
| 1042 | +    private function decrease_fees($amount = 0.00) { | 
                                                        |
| 1043 | + $amount = (float)$amount;  | 
                                                        |
| 1044 | 1044 | $this->fees_total -= $amount;  | 
                                                        
| 1045 | - $this->fees_total = wpinv_round_amount( $this->fees_total );  | 
                                                        |
| 1045 | + $this->fees_total = wpinv_round_amount($this->fees_total);  | 
                                                        |
| 1046 | 1046 | |
| 1047 | -        if ( $this->fees_total < 0 ) { | 
                                                        |
| 1047 | +        if ($this->fees_total < 0) { | 
                                                        |
| 1048 | 1048 | $this->fees_total = 0;  | 
                                                        
| 1049 | 1049 | }  | 
                                                        
| 1050 | 1050 | |
@@ -1055,54 +1055,54 @@ discard block  | 
                                                    ||
| 1055 | 1055 | global $wpi_nosave;  | 
                                                        
| 1056 | 1056 | |
| 1057 | 1057 | $this->total = $this->subtotal + $this->tax + $this->fees_total;  | 
                                                        
| 1058 | - $this->total = wpinv_round_amount( $this->total );  | 
                                                        |
| 1058 | + $this->total = wpinv_round_amount($this->total);  | 
                                                        |
| 1059 | 1059 | |
| 1060 | - do_action( 'wpinv_invoice_recalculate_total', $this, $wpi_nosave );  | 
                                                        |
| 1060 | +        do_action('wpinv_invoice_recalculate_total', $this, $wpi_nosave); | 
                                                        |
| 1061 | 1061 | }  | 
                                                        
| 1062 | 1062 | |
| 1063 | -    public function increase_tax( $amount = 0.00 ) { | 
                                                        |
| 1064 | - $amount = (float) $amount;  | 
                                                        |
| 1063 | +    public function increase_tax($amount = 0.00) { | 
                                                        |
| 1064 | + $amount = (float)$amount;  | 
                                                        |
| 1065 | 1065 | $this->tax += $amount;  | 
                                                        
| 1066 | 1066 | |
| 1067 | 1067 | $this->recalculate_total();  | 
                                                        
| 1068 | 1068 | }  | 
                                                        
| 1069 | 1069 | |
| 1070 | -    public function decrease_tax( $amount = 0.00 ) { | 
                                                        |
| 1071 | - $amount = (float) $amount;  | 
                                                        |
| 1070 | +    public function decrease_tax($amount = 0.00) { | 
                                                        |
| 1071 | + $amount = (float)$amount;  | 
                                                        |
| 1072 | 1072 | $this->tax -= $amount;  | 
                                                        
| 1073 | 1073 | |
| 1074 | -        if ( $this->tax < 0 ) { | 
                                                        |
| 1074 | +        if ($this->tax < 0) { | 
                                                        |
| 1075 | 1075 | $this->tax = 0;  | 
                                                        
| 1076 | 1076 | }  | 
                                                        
| 1077 | 1077 | |
| 1078 | 1078 | $this->recalculate_total();  | 
                                                        
| 1079 | 1079 | }  | 
                                                        
| 1080 | 1080 | |
| 1081 | -    public function update_status( $new_status = false, $note = '', $manual = false ) { | 
                                                        |
| 1082 | - $old_status = ! empty( $this->old_status ) ? $this->old_status : get_post_status( $this->ID );  | 
                                                        |
| 1081 | +    public function update_status($new_status = false, $note = '', $manual = false) { | 
                                                        |
| 1082 | + $old_status = !empty($this->old_status) ? $this->old_status : get_post_status($this->ID);  | 
                                                        |
| 1083 | 1083 | |
| 1084 | -        if ( $old_status === $new_status && in_array( $new_status, array_keys( wpinv_get_invoice_statuses() ) ) ) { | 
                                                        |
| 1084 | +        if ($old_status === $new_status && in_array($new_status, array_keys(wpinv_get_invoice_statuses()))) { | 
                                                        |
| 1085 | 1085 | return false; // Don't permit status changes that aren't changes  | 
                                                        
| 1086 | 1086 | }  | 
                                                        
| 1087 | 1087 | |
| 1088 | - $do_change = apply_filters( 'wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status );  | 
                                                        |
| 1088 | +        $do_change = apply_filters('wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status); | 
                                                        |
| 1089 | 1089 | $updated = false;  | 
                                                        
| 1090 | 1090 | |
| 1091 | -        if ( $do_change ) { | 
                                                        |
| 1092 | - do_action( 'wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status );  | 
                                                        |
| 1091 | +        if ($do_change) { | 
                                                        |
| 1092 | +            do_action('wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status); | 
                                                        |
| 1093 | 1093 | |
| 1094 | 1094 | $update_post_data = array();  | 
                                                        
| 1095 | 1095 | $update_post_data['ID'] = $this->ID;  | 
                                                        
| 1096 | 1096 | $update_post_data['post_status'] = $new_status;  | 
                                                        
| 1097 | - $update_post_data['edit_date'] = current_time( 'mysql', 0 );  | 
                                                        |
| 1098 | - $update_post_data['edit_date_gmt'] = current_time( 'mysql', 1 );  | 
                                                        |
| 1097 | +            $update_post_data['edit_date']      = current_time('mysql', 0); | 
                                                        |
| 1098 | +            $update_post_data['edit_date_gmt']  = current_time('mysql', 1); | 
                                                        |
| 1099 | 1099 | |
| 1100 | - $update_post_data = apply_filters( 'wpinv_update_invoice_status_fields', $update_post_data, $this->ID );  | 
                                                        |
| 1100 | +            $update_post_data = apply_filters('wpinv_update_invoice_status_fields', $update_post_data, $this->ID); | 
                                                        |
| 1101 | 1101 | |
| 1102 | - $updated = wp_update_post( $update_post_data );  | 
                                                        |
| 1102 | + $updated = wp_update_post($update_post_data);  | 
                                                        |
| 1103 | 1103 | |
| 1104 | 1104 | // Process any specific status functions  | 
                                                        
| 1105 | -            switch( $new_status ) { | 
                                                        |
| 1105 | +            switch ($new_status) { | 
                                                        |
| 1106 | 1106 | case 'wpi-refunded':  | 
                                                        
| 1107 | 1107 | $this->process_refund();  | 
                                                        
| 1108 | 1108 | break;  | 
                                                        
@@ -1115,9 +1115,9 @@ discard block  | 
                                                    ||
| 1115 | 1115 | }  | 
                                                        
| 1116 | 1116 | |
| 1117 | 1117 | // Status was changed.  | 
                                                        
| 1118 | - do_action( 'wpinv_status_' . $new_status, $this->ID, $old_status );  | 
                                                        |
| 1119 | - do_action( 'wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status );  | 
                                                        |
| 1120 | - do_action( 'wpinv_update_status', $this->ID, $new_status, $old_status );  | 
                                                        |
| 1118 | +            do_action('wpinv_status_' . $new_status, $this->ID, $old_status); | 
                                                        |
| 1119 | +            do_action('wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status); | 
                                                        |
| 1120 | +            do_action('wpinv_update_status', $this->ID, $new_status, $old_status); | 
                                                        |
| 1121 | 1121 | }  | 
                                                        
| 1122 | 1122 | |
| 1123 | 1123 | return $updated;  | 
                                                        
@@ -1131,72 +1131,72 @@ discard block  | 
                                                    ||
| 1131 | 1131 | $this->save();  | 
                                                        
| 1132 | 1132 | }  | 
                                                        
| 1133 | 1133 | |
| 1134 | -    public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) { | 
                                                        |
| 1135 | -        if ( empty( $meta_key ) ) { | 
                                                        |
| 1134 | +    public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') { | 
                                                        |
| 1135 | +        if (empty($meta_key)) { | 
                                                        |
| 1136 | 1136 | return false;  | 
                                                        
| 1137 | 1137 | }  | 
                                                        
| 1138 | 1138 | |
| 1139 | -        if ( $meta_key == 'key' || $meta_key == 'date' ) { | 
                                                        |
| 1139 | +        if ($meta_key == 'key' || $meta_key == 'date') { | 
                                                        |
| 1140 | 1140 | $current_meta = $this->get_meta();  | 
                                                        
| 1141 | - $current_meta[ $meta_key ] = $meta_value;  | 
                                                        |
| 1141 | + $current_meta[$meta_key] = $meta_value;  | 
                                                        |
| 1142 | 1142 | |
| 1143 | 1143 | $meta_key = '_wpinv_payment_meta';  | 
                                                        
| 1144 | 1144 | $meta_value = $current_meta;  | 
                                                        
| 1145 | 1145 | }  | 
                                                        
| 1146 | 1146 | |
| 1147 | - $meta_value = apply_filters( 'wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID );  | 
                                                        |
| 1147 | +        $meta_value = apply_filters('wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID); | 
                                                        |
| 1148 | 1148 | |
| 1149 | -        if ( $meta_key == '_wpinv_completed_date' && !empty( $meta_value ) ) { | 
                                                        |
| 1149 | +        if ($meta_key == '_wpinv_completed_date' && !empty($meta_value)) { | 
                                                        |
| 1150 | 1150 | $args = array(  | 
                                                        
| 1151 | 1151 | 'ID' => $this->ID,  | 
                                                        
| 1152 | 1152 | 'post_date' => $meta_value,  | 
                                                        
| 1153 | 1153 | 'edit_date' => true,  | 
                                                        
| 1154 | - 'post_date_gmt' => get_gmt_from_date( $meta_value ),  | 
                                                        |
| 1154 | + 'post_date_gmt' => get_gmt_from_date($meta_value),  | 
                                                        |
| 1155 | 1155 | 'post_modified' => $meta_value,  | 
                                                        
| 1156 | - 'post_modified_gmt' => get_gmt_from_date( $meta_value )  | 
                                                        |
| 1156 | + 'post_modified_gmt' => get_gmt_from_date($meta_value)  | 
                                                        |
| 1157 | 1157 | );  | 
                                                        
| 1158 | - wp_update_post( $args );  | 
                                                        |
| 1158 | + wp_update_post($args);  | 
                                                        |
| 1159 | 1159 | }  | 
                                                        
| 1160 | 1160 | |
| 1161 | - return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value );  | 
                                                        |
| 1161 | + return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value);  | 
                                                        |
| 1162 | 1162 | }  | 
                                                        
| 1163 | 1163 | |
| 1164 | 1164 |      private function process_refund() { | 
                                                        
| 1165 | 1165 | $process_refund = true;  | 
                                                        
| 1166 | 1166 | |
| 1167 | 1167 | // If the payment was not in publish, don't decrement stats as they were never incremented  | 
                                                        
| 1168 | -        if ( 'publish' != $this->old_status || 'wpi-refunded' != $this->status ) { | 
                                                        |
| 1168 | +        if ('publish' != $this->old_status || 'wpi-refunded' != $this->status) { | 
                                                        |
| 1169 | 1169 | $process_refund = false;  | 
                                                        
| 1170 | 1170 | }  | 
                                                        
| 1171 | 1171 | |
| 1172 | 1172 | // Allow extensions to filter for their own payment types, Example: Recurring Payments  | 
                                                        
| 1173 | - $process_refund = apply_filters( 'wpinv_should_process_refund', $process_refund, $this );  | 
                                                        |
| 1173 | +        $process_refund = apply_filters('wpinv_should_process_refund', $process_refund, $this); | 
                                                        |
| 1174 | 1174 | |
| 1175 | -        if ( false === $process_refund ) { | 
                                                        |
| 1175 | +        if (false === $process_refund) { | 
                                                        |
| 1176 | 1176 | return;  | 
                                                        
| 1177 | 1177 | }  | 
                                                        
| 1178 | 1178 | |
| 1179 | - do_action( 'wpinv_pre_refund_invoice', $this );  | 
                                                        |
| 1179 | +        do_action('wpinv_pre_refund_invoice', $this); | 
                                                        |
| 1180 | 1180 | |
| 1181 | - $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_refund', true, $this );  | 
                                                        |
| 1182 | - $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_refund', true, $this );  | 
                                                        |
| 1183 | - $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_refund', true, $this );  | 
                                                        |
| 1181 | +        $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_refund', true, $this); | 
                                                        |
| 1182 | +        $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_refund', true, $this); | 
                                                        |
| 1183 | +        $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_refund', true, $this); | 
                                                        |
| 1184 | 1184 | |
| 1185 | - do_action( 'wpinv_post_refund_invoice', $this );  | 
                                                        |
| 1185 | +        do_action('wpinv_post_refund_invoice', $this); | 
                                                        |
| 1186 | 1186 | }  | 
                                                        
| 1187 | 1187 | |
| 1188 | 1188 |      private function process_failure() { | 
                                                        
| 1189 | 1189 | $discounts = $this->discounts;  | 
                                                        
| 1190 | -        if ( empty( $discounts ) ) { | 
                                                        |
| 1190 | +        if (empty($discounts)) { | 
                                                        |
| 1191 | 1191 | return;  | 
                                                        
| 1192 | 1192 | }  | 
                                                        
| 1193 | 1193 | |
| 1194 | -        if ( ! is_array( $discounts ) ) { | 
                                                        |
| 1195 | - $discounts = array_map( 'trim', explode( ',', $discounts ) );  | 
                                                        |
| 1194 | +        if (!is_array($discounts)) { | 
                                                        |
| 1195 | +            $discounts = array_map('trim', explode(',', $discounts)); | 
                                                        |
| 1196 | 1196 | }  | 
                                                        
| 1197 | 1197 | |
| 1198 | -        foreach ( $discounts as $discount ) { | 
                                                        |
| 1199 | - wpinv_decrease_discount_usage( $discount );  | 
                                                        |
| 1198 | +        foreach ($discounts as $discount) { | 
                                                        |
| 1199 | + wpinv_decrease_discount_usage($discount);  | 
                                                        |
| 1200 | 1200 | }  | 
                                                        
| 1201 | 1201 | }  | 
                                                        
| 1202 | 1202 | |
@@ -1204,92 +1204,92 @@ discard block  | 
                                                    ||
| 1204 | 1204 | $process_pending = true;  | 
                                                        
| 1205 | 1205 | |
| 1206 | 1206 | // If the payment was not in publish or revoked status, don't decrement stats as they were never incremented  | 
                                                        
| 1207 | -        if ( ( 'publish' != $this->old_status && 'revoked' != $this->old_status ) || 'pending' != $this->status ) { | 
                                                        |
| 1207 | +        if (('publish' != $this->old_status && 'revoked' != $this->old_status) || 'pending' != $this->status) { | 
                                                        |
| 1208 | 1208 | $process_pending = false;  | 
                                                        
| 1209 | 1209 | }  | 
                                                        
| 1210 | 1210 | |
| 1211 | 1211 | // Allow extensions to filter for their own payment types, Example: Recurring Payments  | 
                                                        
| 1212 | - $process_pending = apply_filters( 'wpinv_should_process_pending', $process_pending, $this );  | 
                                                        |
| 1212 | +        $process_pending = apply_filters('wpinv_should_process_pending', $process_pending, $this); | 
                                                        |
| 1213 | 1213 | |
| 1214 | -        if ( false === $process_pending ) { | 
                                                        |
| 1214 | +        if (false === $process_pending) { | 
                                                        |
| 1215 | 1215 | return;  | 
                                                        
| 1216 | 1216 | }  | 
                                                        
| 1217 | 1217 | |
| 1218 | - $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_pending', true, $this );  | 
                                                        |
| 1219 | - $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_pending', true, $this );  | 
                                                        |
| 1220 | - $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_pending', true, $this );  | 
                                                        |
| 1218 | +        $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_pending', true, $this); | 
                                                        |
| 1219 | +        $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_pending', true, $this); | 
                                                        |
| 1220 | +        $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_pending', true, $this); | 
                                                        |
| 1221 | 1221 | |
| 1222 | 1222 | $this->completed_date = '';  | 
                                                        
| 1223 | - $this->update_meta( '_wpinv_completed_date', '' );  | 
                                                        |
| 1223 | +        $this->update_meta('_wpinv_completed_date', ''); | 
                                                        |
| 1224 | 1224 | }  | 
                                                        
| 1225 | 1225 | |
| 1226 | 1226 | // get data  | 
                                                        
| 1227 | -    public function get_meta( $meta_key = '_wpinv_payment_meta', $single = true ) { | 
                                                        |
| 1228 | - $meta = get_post_meta( $this->ID, $meta_key, $single );  | 
                                                        |
| 1227 | +    public function get_meta($meta_key = '_wpinv_payment_meta', $single = true) { | 
                                                        |
| 1228 | + $meta = get_post_meta($this->ID, $meta_key, $single);  | 
                                                        |
| 1229 | 1229 | |
| 1230 | -        if ( $meta_key === '_wpinv_payment_meta' ) { | 
                                                        |
| 1230 | +        if ($meta_key === '_wpinv_payment_meta') { | 
                                                        |
| 1231 | 1231 | |
| 1232 | -            if(!is_array($meta)){$meta = array();} // we need this to be an array so make sure it is. | 
                                                        |
| 1232 | +            if (!is_array($meta)) {$meta = array(); } // we need this to be an array so make sure it is. | 
                                                        |
| 1233 | 1233 | |
| 1234 | -            if ( empty( $meta['key'] ) ) { | 
                                                        |
| 1234 | +            if (empty($meta['key'])) { | 
                                                        |
| 1235 | 1235 | $meta['key'] = $this->setup_invoice_key();  | 
                                                        
| 1236 | 1236 | }  | 
                                                        
| 1237 | 1237 | |
| 1238 | -            if ( empty( $meta['date'] ) ) { | 
                                                        |
| 1239 | - $meta['date'] = get_post_field( 'post_date', $this->ID );  | 
                                                        |
| 1238 | +            if (empty($meta['date'])) { | 
                                                        |
| 1239 | +                $meta['date'] = get_post_field('post_date', $this->ID); | 
                                                        |
| 1240 | 1240 | }  | 
                                                        
| 1241 | 1241 | }  | 
                                                        
| 1242 | 1242 | |
| 1243 | - $meta = apply_filters( 'wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID );  | 
                                                        |
| 1243 | +        $meta = apply_filters('wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID); | 
                                                        |
| 1244 | 1244 | |
| 1245 | - return apply_filters( 'wpinv_get_invoice_meta', $meta, $this->ID, $meta_key );  | 
                                                        |
| 1245 | +        return apply_filters('wpinv_get_invoice_meta', $meta, $this->ID, $meta_key); | 
                                                        |
| 1246 | 1246 | }  | 
                                                        
| 1247 | 1247 | |
| 1248 | 1248 |      public function get_description() { | 
                                                        
| 1249 | - $post = get_post( $this->ID );  | 
                                                        |
| 1249 | + $post = get_post($this->ID);  | 
                                                        |
| 1250 | 1250 | |
| 1251 | - $description = !empty( $post ) ? $post->post_content : '';  | 
                                                        |
| 1252 | - return apply_filters( 'wpinv_get_description', $description, $this->ID, $this );  | 
                                                        |
| 1251 | + $description = !empty($post) ? $post->post_content : '';  | 
                                                        |
| 1252 | +        return apply_filters('wpinv_get_description', $description, $this->ID, $this); | 
                                                        |
| 1253 | 1253 | }  | 
                                                        
| 1254 | 1254 | |
| 1255 | -    public function get_status( $nicename = false ) { | 
                                                        |
| 1256 | -        if ( !$nicename ) { | 
                                                        |
| 1255 | +    public function get_status($nicename = false) { | 
                                                        |
| 1256 | +        if (!$nicename) { | 
                                                        |
| 1257 | 1257 | $status = $this->status;  | 
                                                        
| 1258 | 1258 |          } else { | 
                                                        
| 1259 | 1259 | $status = $this->status_nicename;  | 
                                                        
| 1260 | 1260 | }  | 
                                                        
| 1261 | 1261 | |
| 1262 | - return apply_filters( 'wpinv_get_status', $status, $nicename, $this->ID, $this );  | 
                                                        |
| 1262 | +        return apply_filters('wpinv_get_status', $status, $nicename, $this->ID, $this); | 
                                                        |
| 1263 | 1263 | }  | 
                                                        
| 1264 | 1264 | |
| 1265 | 1265 |      public function get_cart_details() { | 
                                                        
| 1266 | - return apply_filters( 'wpinv_cart_details', $this->cart_details, $this->ID, $this );  | 
                                                        |
| 1266 | +        return apply_filters('wpinv_cart_details', $this->cart_details, $this->ID, $this); | 
                                                        |
| 1267 | 1267 | }  | 
                                                        
| 1268 | 1268 | |
| 1269 | -    public function get_subtotal( $currency = false ) { | 
                                                        |
| 1270 | - $subtotal = wpinv_round_amount( $this->subtotal );  | 
                                                        |
| 1269 | +    public function get_subtotal($currency = false) { | 
                                                        |
| 1270 | + $subtotal = wpinv_round_amount($this->subtotal);  | 
                                                        |
| 1271 | 1271 | |
| 1272 | -        if ( $currency ) { | 
                                                        |
| 1273 | - $subtotal = wpinv_price( wpinv_format_amount( $subtotal, NULL, !$currency ), $this->get_currency() );  | 
                                                        |
| 1272 | +        if ($currency) { | 
                                                        |
| 1273 | + $subtotal = wpinv_price(wpinv_format_amount($subtotal, NULL, !$currency), $this->get_currency());  | 
                                                        |
| 1274 | 1274 | }  | 
                                                        
| 1275 | 1275 | |
| 1276 | - return apply_filters( 'wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency );  | 
                                                        |
| 1276 | +        return apply_filters('wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency); | 
                                                        |
| 1277 | 1277 | }  | 
                                                        
| 1278 | 1278 | |
| 1279 | -    public function get_total( $currency = false ) {         | 
                                                        |
| 1280 | -        if ( $this->is_free_trial() ) { | 
                                                        |
| 1281 | - $total = wpinv_round_amount( 0 );  | 
                                                        |
| 1279 | +    public function get_total($currency = false) {         | 
                                                        |
| 1280 | +        if ($this->is_free_trial()) { | 
                                                        |
| 1281 | + $total = wpinv_round_amount(0);  | 
                                                        |
| 1282 | 1282 |          } else { | 
                                                        
| 1283 | - $total = wpinv_round_amount( $this->total );  | 
                                                        |
| 1283 | + $total = wpinv_round_amount($this->total);  | 
                                                        |
| 1284 | 1284 | }  | 
                                                        
| 1285 | -        if ( $currency ) { | 
                                                        |
| 1286 | - $total = wpinv_price( wpinv_format_amount( $total, NULL, !$currency ), $this->get_currency() );  | 
                                                        |
| 1285 | +        if ($currency) { | 
                                                        |
| 1286 | + $total = wpinv_price(wpinv_format_amount($total, NULL, !$currency), $this->get_currency());  | 
                                                        |
| 1287 | 1287 | }  | 
                                                        
| 1288 | 1288 | |
| 1289 | - return apply_filters( 'wpinv_get_invoice_total', $total, $this->ID, $this, $currency );  | 
                                                        |
| 1289 | +        return apply_filters('wpinv_get_invoice_total', $total, $this->ID, $this, $currency); | 
                                                        |
| 1290 | 1290 | }  | 
                                                        
| 1291 | 1291 | |
| 1292 | -    public function get_recurring_details( $field = '', $currency = false ) {         | 
                                                        |
| 1292 | +    public function get_recurring_details($field = '', $currency = false) {         | 
                                                        |
| 1293 | 1293 | $data = array();  | 
                                                        
| 1294 | 1294 | $data['cart_details'] = $this->cart_details;  | 
                                                        
| 1295 | 1295 | $data['subtotal'] = $this->get_subtotal();  | 
                                                        
@@ -1297,45 +1297,45 @@ discard block  | 
                                                    ||
| 1297 | 1297 | $data['tax'] = $this->get_tax();  | 
                                                        
| 1298 | 1298 | $data['total'] = $this->get_total();  | 
                                                        
| 1299 | 1299 | |
| 1300 | -        if ( !empty( $this->cart_details ) && ( $this->is_parent() || $this->is_renewal() ) ) { | 
                                                        |
| 1300 | +        if (!empty($this->cart_details) && ($this->is_parent() || $this->is_renewal())) { | 
                                                        |
| 1301 | 1301 | $is_free_trial = $this->is_free_trial();  | 
                                                        
| 1302 | - $discounts = $this->get_discounts( true );  | 
                                                        |
| 1302 | + $discounts = $this->get_discounts(true);  | 
                                                        |
| 1303 | 1303 | |
| 1304 | -            if ( $is_free_trial || !empty( $discounts ) ) { | 
                                                        |
| 1304 | +            if ($is_free_trial || !empty($discounts)) { | 
                                                        |
| 1305 | 1305 | $first_use_only = false;  | 
                                                        
| 1306 | 1306 | |
| 1307 | -                if ( !empty( $discounts ) ) { | 
                                                        |
| 1308 | -                    foreach ( $discounts as $key => $code ) { | 
                                                        |
| 1309 | -                        if ( wpinv_discount_is_recurring( $code, true ) ) { | 
                                                        |
| 1307 | +                if (!empty($discounts)) { | 
                                                        |
| 1308 | +                    foreach ($discounts as $key => $code) { | 
                                                        |
| 1309 | +                        if (wpinv_discount_is_recurring($code, true)) { | 
                                                        |
| 1310 | 1310 | $first_use_only = true;  | 
                                                        
| 1311 | 1311 | break;  | 
                                                        
| 1312 | 1312 | }  | 
                                                        
| 1313 | 1313 | }  | 
                                                        
| 1314 | 1314 | }  | 
                                                        
| 1315 | 1315 | |
| 1316 | -                if ( !$first_use_only ) { | 
                                                        |
| 1317 | - $data['subtotal'] = wpinv_round_amount( $this->subtotal );  | 
                                                        |
| 1318 | - $data['discount'] = wpinv_round_amount( $this->discount );  | 
                                                        |
| 1319 | - $data['tax'] = wpinv_round_amount( $this->tax );  | 
                                                        |
| 1320 | - $data['total'] = wpinv_round_amount( $this->total );  | 
                                                        |
| 1316 | +                if (!$first_use_only) { | 
                                                        |
| 1317 | + $data['subtotal'] = wpinv_round_amount($this->subtotal);  | 
                                                        |
| 1318 | + $data['discount'] = wpinv_round_amount($this->discount);  | 
                                                        |
| 1319 | + $data['tax'] = wpinv_round_amount($this->tax);  | 
                                                        |
| 1320 | + $data['total'] = wpinv_round_amount($this->total);  | 
                                                        |
| 1321 | 1321 |                  } else { | 
                                                        
| 1322 | 1322 | $cart_subtotal = 0;  | 
                                                        
| 1323 | 1323 | $cart_discount = 0;  | 
                                                        
| 1324 | 1324 | $cart_tax = 0;  | 
                                                        
| 1325 | 1325 | |
| 1326 | -                    foreach ( $this->cart_details as $key => $item ) { | 
                                                        |
| 1327 | - $item_quantity = $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;  | 
                                                        |
| 1328 | - $item_subtotal = !empty( $item['subtotal'] ) ? $item['subtotal'] : $item['item_price'] * $item_quantity;  | 
                                                        |
| 1326 | +                    foreach ($this->cart_details as $key => $item) { | 
                                                        |
| 1327 | + $item_quantity = $item['quantity'] > 0 ? absint($item['quantity']) : 1;  | 
                                                        |
| 1328 | + $item_subtotal = !empty($item['subtotal']) ? $item['subtotal'] : $item['item_price'] * $item_quantity;  | 
                                                        |
| 1329 | 1329 | $item_discount = 0;  | 
                                                        
| 1330 | - $item_tax = $item_subtotal > 0 && !empty( $item['vat_rate'] ) ? ( $item_subtotal * 0.01 * (float)$item['vat_rate'] ) : 0;  | 
                                                        |
| 1330 | + $item_tax = $item_subtotal > 0 && !empty($item['vat_rate']) ? ($item_subtotal * 0.01 * (float)$item['vat_rate']) : 0;  | 
                                                        |
| 1331 | 1331 | |
| 1332 | -                        if ( wpinv_prices_include_tax() ) { | 
                                                        |
| 1333 | - $item_subtotal -= wpinv_round_amount( $item_tax );  | 
                                                        |
| 1332 | +                        if (wpinv_prices_include_tax()) { | 
                                                        |
| 1333 | + $item_subtotal -= wpinv_round_amount($item_tax);  | 
                                                        |
| 1334 | 1334 | }  | 
                                                        
| 1335 | 1335 | |
| 1336 | 1336 | $item_total = $item_subtotal - $item_discount + $item_tax;  | 
                                                        
| 1337 | 1337 | // Do not allow totals to go negative  | 
                                                        
| 1338 | -                        if ( $item_total < 0 ) { | 
                                                        |
| 1338 | +                        if ($item_total < 0) { | 
                                                        |
| 1339 | 1339 | $item_total = 0;  | 
                                                        
| 1340 | 1340 | }  | 
                                                        
| 1341 | 1341 | |
@@ -1343,113 +1343,113 @@ discard block  | 
                                                    ||
| 1343 | 1343 | $cart_discount += (float)($item_discount);  | 
                                                        
| 1344 | 1344 | $cart_tax += (float)($item_tax);  | 
                                                        
| 1345 | 1345 | |
| 1346 | - $data['cart_details'][$key]['discount'] = wpinv_round_amount( $item_discount );  | 
                                                        |
| 1347 | - $data['cart_details'][$key]['tax'] = wpinv_round_amount( $item_tax );  | 
                                                        |
| 1348 | - $data['cart_details'][$key]['price'] = wpinv_round_amount( $item_total );  | 
                                                        |
| 1346 | + $data['cart_details'][$key]['discount'] = wpinv_round_amount($item_discount);  | 
                                                        |
| 1347 | + $data['cart_details'][$key]['tax'] = wpinv_round_amount($item_tax);  | 
                                                        |
| 1348 | + $data['cart_details'][$key]['price'] = wpinv_round_amount($item_total);  | 
                                                        |
| 1349 | 1349 | }  | 
                                                        
| 1350 | 1350 | |
| 1351 | - $data['subtotal'] = wpinv_round_amount( $cart_subtotal );  | 
                                                        |
| 1352 | - $data['discount'] = wpinv_round_amount( $cart_discount );  | 
                                                        |
| 1353 | - $data['tax'] = wpinv_round_amount( $cart_tax );  | 
                                                        |
| 1354 | - $data['total'] = wpinv_round_amount( $data['subtotal'] + $data['tax'] );  | 
                                                        |
| 1351 | + $data['subtotal'] = wpinv_round_amount($cart_subtotal);  | 
                                                        |
| 1352 | + $data['discount'] = wpinv_round_amount($cart_discount);  | 
                                                        |
| 1353 | + $data['tax'] = wpinv_round_amount($cart_tax);  | 
                                                        |
| 1354 | + $data['total'] = wpinv_round_amount($data['subtotal'] + $data['tax']);  | 
                                                        |
| 1355 | 1355 | }  | 
                                                        
| 1356 | 1356 | }  | 
                                                        
| 1357 | 1357 | }  | 
                                                        
| 1358 | 1358 | |
| 1359 | - $data = apply_filters( 'wpinv_get_invoice_recurring_details', $data, $this, $field, $currency );  | 
                                                        |
| 1359 | +        $data = apply_filters('wpinv_get_invoice_recurring_details', $data, $this, $field, $currency); | 
                                                        |
| 1360 | 1360 | |
| 1361 | -        if ( isset( $data[$field] ) ) { | 
                                                        |
| 1362 | - return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] );  | 
                                                        |
| 1361 | +        if (isset($data[$field])) { | 
                                                        |
| 1362 | + return ($currency ? wpinv_price($data[$field], $this->get_currency()) : $data[$field]);  | 
                                                        |
| 1363 | 1363 | }  | 
                                                        
| 1364 | 1364 | |
| 1365 | 1365 | return $data;  | 
                                                        
| 1366 | 1366 | }  | 
                                                        
| 1367 | 1367 | |
| 1368 | -    public function get_final_tax( $currency = false ) {         | 
                                                        |
| 1369 | - $final_total = wpinv_round_amount( $this->tax );  | 
                                                        |
| 1370 | -        if ( $currency ) { | 
                                                        |
| 1371 | - $final_total = wpinv_price( wpinv_format_amount( $final_total, NULL, !$currency ), $this->get_currency() );  | 
                                                        |
| 1368 | +    public function get_final_tax($currency = false) {         | 
                                                        |
| 1369 | + $final_total = wpinv_round_amount($this->tax);  | 
                                                        |
| 1370 | +        if ($currency) { | 
                                                        |
| 1371 | + $final_total = wpinv_price(wpinv_format_amount($final_total, NULL, !$currency), $this->get_currency());  | 
                                                        |
| 1372 | 1372 | }  | 
                                                        
| 1373 | 1373 | |
| 1374 | - return apply_filters( 'wpinv_get_invoice_final_total', $final_total, $this, $currency );  | 
                                                        |
| 1374 | +        return apply_filters('wpinv_get_invoice_final_total', $final_total, $this, $currency); | 
                                                        |
| 1375 | 1375 | }  | 
                                                        
| 1376 | 1376 | |
| 1377 | -    public function get_discounts( $array = false ) { | 
                                                        |
| 1377 | +    public function get_discounts($array = false) { | 
                                                        |
| 1378 | 1378 | $discounts = $this->discounts;  | 
                                                        
| 1379 | -        if ( $array && $discounts ) { | 
                                                        |
| 1380 | - $discounts = explode( ',', $discounts );  | 
                                                        |
| 1379 | +        if ($array && $discounts) { | 
                                                        |
| 1380 | +            $discounts = explode(',', $discounts); | 
                                                        |
| 1381 | 1381 | }  | 
                                                        
| 1382 | - return apply_filters( 'wpinv_payment_discounts', $discounts, $this->ID, $this, $array );  | 
                                                        |
| 1382 | +        return apply_filters('wpinv_payment_discounts', $discounts, $this->ID, $this, $array); | 
                                                        |
| 1383 | 1383 | }  | 
                                                        
| 1384 | 1384 | |
| 1385 | -    public function get_discount( $currency = false, $dash = false ) { | 
                                                        |
| 1386 | -        if ( !empty( $this->discounts ) ) { | 
                                                        |
| 1385 | +    public function get_discount($currency = false, $dash = false) { | 
                                                        |
| 1386 | +        if (!empty($this->discounts)) { | 
                                                        |
| 1387 | 1387 | global $ajax_cart_details;  | 
                                                        
| 1388 | 1388 | $ajax_cart_details = $this->get_cart_details();  | 
                                                        
| 1389 | 1389 | |
| 1390 | -            if ( !empty( $ajax_cart_details ) && count( $ajax_cart_details ) == count( $this->items ) ) { | 
                                                        |
| 1390 | +            if (!empty($ajax_cart_details) && count($ajax_cart_details) == count($this->items)) { | 
                                                        |
| 1391 | 1391 | $cart_items = $ajax_cart_details;  | 
                                                        
| 1392 | 1392 |              } else { | 
                                                        
| 1393 | 1393 | $cart_items = $this->items;  | 
                                                        
| 1394 | 1394 | }  | 
                                                        
| 1395 | 1395 | |
| 1396 | - $this->discount = wpinv_get_cart_items_discount_amount( $cart_items , $this->discounts );  | 
                                                        |
| 1396 | + $this->discount = wpinv_get_cart_items_discount_amount($cart_items, $this->discounts);  | 
                                                        |
| 1397 | 1397 | }  | 
                                                        
| 1398 | - $discount = wpinv_round_amount( $this->discount );  | 
                                                        |
| 1398 | + $discount = wpinv_round_amount($this->discount);  | 
                                                        |
| 1399 | 1399 | $dash = $dash && $discount > 0 ? '–' : '';  | 
                                                        
| 1400 | 1400 | |
| 1401 | -        if ( $currency ) { | 
                                                        |
| 1402 | - $discount = wpinv_price( wpinv_format_amount( $discount, NULL, !$currency ), $this->get_currency() );  | 
                                                        |
| 1401 | +        if ($currency) { | 
                                                        |
| 1402 | + $discount = wpinv_price(wpinv_format_amount($discount, NULL, !$currency), $this->get_currency());  | 
                                                        |
| 1403 | 1403 | }  | 
                                                        
| 1404 | 1404 | |
| 1405 | - $discount = $dash . $discount;  | 
                                                        |
| 1405 | + $discount = $dash . $discount;  | 
                                                        |
| 1406 | 1406 | |
| 1407 | - return apply_filters( 'wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash );  | 
                                                        |
| 1407 | +        return apply_filters('wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash); | 
                                                        |
| 1408 | 1408 | }  | 
                                                        
| 1409 | 1409 | |
| 1410 | 1410 |      public function get_discount_code() { | 
                                                        
| 1411 | 1411 | return $this->discount_code;  | 
                                                        
| 1412 | 1412 | }  | 
                                                        
| 1413 | 1413 | |
| 1414 | -    public function get_tax( $currency = false ) { | 
                                                        |
| 1415 | - $tax = wpinv_round_amount( $this->tax );  | 
                                                        |
| 1414 | +    public function get_tax($currency = false) { | 
                                                        |
| 1415 | + $tax = wpinv_round_amount($this->tax);  | 
                                                        |
| 1416 | 1416 | |
| 1417 | -        if ( $currency ) { | 
                                                        |
| 1418 | - $tax = wpinv_price( wpinv_format_amount( $tax, NULL, !$currency ), $this->get_currency() );  | 
                                                        |
| 1417 | +        if ($currency) { | 
                                                        |
| 1418 | + $tax = wpinv_price(wpinv_format_amount($tax, NULL, !$currency), $this->get_currency());  | 
                                                        |
| 1419 | 1419 | }  | 
                                                        
| 1420 | 1420 | |
| 1421 | - return apply_filters( 'wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency );  | 
                                                        |
| 1421 | +        return apply_filters('wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency); | 
                                                        |
| 1422 | 1422 | }  | 
                                                        
| 1423 | 1423 | |
| 1424 | -    public function get_fees( $type = 'all' ) { | 
                                                        |
| 1425 | - $fees = array();  | 
                                                        |
| 1424 | +    public function get_fees($type = 'all') { | 
                                                        |
| 1425 | + $fees = array();  | 
                                                        |
| 1426 | 1426 | |
| 1427 | -        if ( ! empty( $this->fees ) && is_array( $this->fees ) ) { | 
                                                        |
| 1428 | -            foreach ( $this->fees as $fee ) { | 
                                                        |
| 1429 | -                if( 'all' != $type && ! empty( $fee['type'] ) && $type != $fee['type'] ) { | 
                                                        |
| 1427 | +        if (!empty($this->fees) && is_array($this->fees)) { | 
                                                        |
| 1428 | +            foreach ($this->fees as $fee) { | 
                                                        |
| 1429 | +                if ('all' != $type && !empty($fee['type']) && $type != $fee['type']) { | 
                                                        |
| 1430 | 1430 | continue;  | 
                                                        
| 1431 | 1431 | }  | 
                                                        
| 1432 | 1432 | |
| 1433 | - $fee['label'] = stripslashes( $fee['label'] );  | 
                                                        |
| 1434 | - $fee['amount_display'] = wpinv_price( $fee['amount'], $this->get_currency() );  | 
                                                        |
| 1435 | - $fees[] = $fee;  | 
                                                        |
| 1433 | + $fee['label'] = stripslashes($fee['label']);  | 
                                                        |
| 1434 | + $fee['amount_display'] = wpinv_price($fee['amount'], $this->get_currency());  | 
                                                        |
| 1435 | + $fees[] = $fee;  | 
                                                        |
| 1436 | 1436 | }  | 
                                                        
| 1437 | 1437 | }  | 
                                                        
| 1438 | 1438 | |
| 1439 | - return apply_filters( 'wpinv_get_invoice_fees', $fees, $this->ID, $this );  | 
                                                        |
| 1439 | +        return apply_filters('wpinv_get_invoice_fees', $fees, $this->ID, $this); | 
                                                        |
| 1440 | 1440 | }  | 
                                                        
| 1441 | 1441 | |
| 1442 | -    public function get_fees_total( $type = 'all' ) { | 
                                                        |
| 1443 | - $fees_total = (float) 0.00;  | 
                                                        |
| 1442 | +    public function get_fees_total($type = 'all') { | 
                                                        |
| 1443 | + $fees_total = (float)0.00;  | 
                                                        |
| 1444 | 1444 | |
| 1445 | - $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array();  | 
                                                        |
| 1446 | -        if ( ! empty( $payment_fees ) ) { | 
                                                        |
| 1447 | -            foreach ( $payment_fees as $fee ) { | 
                                                        |
| 1448 | - $fees_total += (float) $fee['amount'];  | 
                                                        |
| 1445 | + $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array();  | 
                                                        |
| 1446 | +        if (!empty($payment_fees)) { | 
                                                        |
| 1447 | +            foreach ($payment_fees as $fee) { | 
                                                        |
| 1448 | + $fees_total += (float)$fee['amount'];  | 
                                                        |
| 1449 | 1449 | }  | 
                                                        
| 1450 | 1450 | }  | 
                                                        
| 1451 | 1451 | |
| 1452 | - return apply_filters( 'wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this );  | 
                                                        |
| 1452 | +        return apply_filters('wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this); | 
                                                        |
| 1453 | 1453 | /*  | 
                                                        
| 1454 | 1454 | $fees = $this->get_fees( $type );  | 
                                                        
| 1455 | 1455 | |
@@ -1469,116 +1469,116 @@ discard block  | 
                                                    ||
| 1469 | 1469 | }  | 
                                                        
| 1470 | 1470 | |
| 1471 | 1471 |      public function get_user_id() { | 
                                                        
| 1472 | - return apply_filters( 'wpinv_user_id', $this->user_id, $this->ID, $this );  | 
                                                        |
| 1472 | +        return apply_filters('wpinv_user_id', $this->user_id, $this->ID, $this); | 
                                                        |
| 1473 | 1473 | }  | 
                                                        
| 1474 | 1474 | |
| 1475 | 1475 |      public function get_first_name() { | 
                                                        
| 1476 | - return apply_filters( 'wpinv_first_name', $this->first_name, $this->ID, $this );  | 
                                                        |
| 1476 | +        return apply_filters('wpinv_first_name', $this->first_name, $this->ID, $this); | 
                                                        |
| 1477 | 1477 | }  | 
                                                        
| 1478 | 1478 | |
| 1479 | 1479 |      public function get_last_name() { | 
                                                        
| 1480 | - return apply_filters( 'wpinv_last_name', $this->last_name, $this->ID, $this );  | 
                                                        |
| 1480 | +        return apply_filters('wpinv_last_name', $this->last_name, $this->ID, $this); | 
                                                        |
| 1481 | 1481 | }  | 
                                                        
| 1482 | 1482 | |
| 1483 | 1483 |      public function get_user_full_name() { | 
                                                        
| 1484 | - return apply_filters( 'wpinv_user_full_name', $this->full_name, $this->ID, $this );  | 
                                                        |
| 1484 | +        return apply_filters('wpinv_user_full_name', $this->full_name, $this->ID, $this); | 
                                                        |
| 1485 | 1485 | }  | 
                                                        
| 1486 | 1486 | |
| 1487 | 1487 |      public function get_user_info() { | 
                                                        
| 1488 | - return apply_filters( 'wpinv_user_info', $this->user_info, $this->ID, $this );  | 
                                                        |
| 1488 | +        return apply_filters('wpinv_user_info', $this->user_info, $this->ID, $this); | 
                                                        |
| 1489 | 1489 | }  | 
                                                        
| 1490 | 1490 | |
| 1491 | 1491 |      public function get_email() { | 
                                                        
| 1492 | - return apply_filters( 'wpinv_user_email', $this->email, $this->ID, $this );  | 
                                                        |
| 1492 | +        return apply_filters('wpinv_user_email', $this->email, $this->ID, $this); | 
                                                        |
| 1493 | 1493 | }  | 
                                                        
| 1494 | 1494 | |
| 1495 | 1495 |      public function get_address() { | 
                                                        
| 1496 | - return apply_filters( 'wpinv_address', $this->address, $this->ID, $this );  | 
                                                        |
| 1496 | +        return apply_filters('wpinv_address', $this->address, $this->ID, $this); | 
                                                        |
| 1497 | 1497 | }  | 
                                                        
| 1498 | 1498 | |
| 1499 | 1499 |      public function get_phone() { | 
                                                        
| 1500 | - return apply_filters( 'wpinv_phone', $this->phone, $this->ID, $this );  | 
                                                        |
| 1500 | +        return apply_filters('wpinv_phone', $this->phone, $this->ID, $this); | 
                                                        |
| 1501 | 1501 | }  | 
                                                        
| 1502 | 1502 | |
| 1503 | 1503 |      public function get_number() { | 
                                                        
| 1504 | - return apply_filters( 'wpinv_number', $this->number, $this->ID, $this );  | 
                                                        |
| 1504 | +        return apply_filters('wpinv_number', $this->number, $this->ID, $this); | 
                                                        |
| 1505 | 1505 | }  | 
                                                        
| 1506 | 1506 | |
| 1507 | 1507 |      public function get_items() { | 
                                                        
| 1508 | - return apply_filters( 'wpinv_payment_meta_items', $this->items, $this->ID, $this );  | 
                                                        |
| 1508 | +        return apply_filters('wpinv_payment_meta_items', $this->items, $this->ID, $this); | 
                                                        |
| 1509 | 1509 | }  | 
                                                        
| 1510 | 1510 | |
| 1511 | 1511 |      public function get_key() { | 
                                                        
| 1512 | - return apply_filters( 'wpinv_key', $this->key, $this->ID, $this );  | 
                                                        |
| 1512 | +        return apply_filters('wpinv_key', $this->key, $this->ID, $this); | 
                                                        |
| 1513 | 1513 | }  | 
                                                        
| 1514 | 1514 | |
| 1515 | 1515 |      public function get_transaction_id() { | 
                                                        
| 1516 | - return apply_filters( 'wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this );  | 
                                                        |
| 1516 | +        return apply_filters('wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this); | 
                                                        |
| 1517 | 1517 | }  | 
                                                        
| 1518 | 1518 | |
| 1519 | 1519 |      public function get_gateway() { | 
                                                        
| 1520 | - return apply_filters( 'wpinv_gateway', $this->gateway, $this->ID, $this );  | 
                                                        |
| 1520 | +        return apply_filters('wpinv_gateway', $this->gateway, $this->ID, $this); | 
                                                        |
| 1521 | 1521 | }  | 
                                                        
| 1522 | 1522 | |
| 1523 | 1523 |      public function get_gateway_title() { | 
                                                        
| 1524 | - $this->gateway_title = !empty( $this->gateway_title ) ? $this->gateway_title : wpinv_get_gateway_checkout_label( $this->gateway );  | 
                                                        |
| 1524 | + $this->gateway_title = !empty($this->gateway_title) ? $this->gateway_title : wpinv_get_gateway_checkout_label($this->gateway);  | 
                                                        |
| 1525 | 1525 | |
| 1526 | - return apply_filters( 'wpinv_gateway_title', $this->gateway_title, $this->ID, $this );  | 
                                                        |
| 1526 | +        return apply_filters('wpinv_gateway_title', $this->gateway_title, $this->ID, $this); | 
                                                        |
| 1527 | 1527 | }  | 
                                                        
| 1528 | 1528 | |
| 1529 | 1529 |      public function get_currency() { | 
                                                        
| 1530 | - return apply_filters( 'wpinv_currency_code', $this->currency, $this->ID, $this );  | 
                                                        |
| 1530 | +        return apply_filters('wpinv_currency_code', $this->currency, $this->ID, $this); | 
                                                        |
| 1531 | 1531 | }  | 
                                                        
| 1532 | 1532 | |
| 1533 | 1533 |      public function get_created_date() { | 
                                                        
| 1534 | - return apply_filters( 'wpinv_created_date', $this->date, $this->ID, $this );  | 
                                                        |
| 1534 | +        return apply_filters('wpinv_created_date', $this->date, $this->ID, $this); | 
                                                        |
| 1535 | 1535 | }  | 
                                                        
| 1536 | 1536 | |
| 1537 | -    public function get_due_date( $display = false ) { | 
                                                        |
| 1538 | - $due_date = apply_filters( 'wpinv_due_date', $this->due_date, $this->ID, $this );  | 
                                                        |
| 1537 | +    public function get_due_date($display = false) { | 
                                                        |
| 1538 | +        $due_date = apply_filters('wpinv_due_date', $this->due_date, $this->ID, $this); | 
                                                        |
| 1539 | 1539 | |
| 1540 | -        if ( !$display || empty( $due_date ) ) { | 
                                                        |
| 1540 | +        if (!$display || empty($due_date)) { | 
                                                        |
| 1541 | 1541 | return $due_date;  | 
                                                        
| 1542 | 1542 | }  | 
                                                        
| 1543 | 1543 | |
| 1544 | - return date_i18n( get_option( 'date_format' ), strtotime( $due_date ) );  | 
                                                        |
| 1544 | +        return date_i18n(get_option('date_format'), strtotime($due_date)); | 
                                                        |
| 1545 | 1545 | }  | 
                                                        
| 1546 | 1546 | |
| 1547 | 1547 |      public function get_completed_date() { | 
                                                        
| 1548 | - return apply_filters( 'wpinv_completed_date', $this->completed_date, $this->ID, $this );  | 
                                                        |
| 1548 | +        return apply_filters('wpinv_completed_date', $this->completed_date, $this->ID, $this); | 
                                                        |
| 1549 | 1549 | }  | 
                                                        
| 1550 | 1550 | |
| 1551 | -    public function get_invoice_date( $formatted = true ) { | 
                                                        |
| 1551 | +    public function get_invoice_date($formatted = true) { | 
                                                        |
| 1552 | 1552 | $date_completed = $this->completed_date;  | 
                                                        
| 1553 | 1553 | $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? $date_completed : '';  | 
                                                        
| 1554 | 1554 | |
| 1555 | -        if ( $invoice_date == '' ) { | 
                                                        |
| 1555 | +        if ($invoice_date == '') { | 
                                                        |
| 1556 | 1556 | $date_created = $this->date;  | 
                                                        
| 1557 | 1557 | $invoice_date = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? $date_created : '';  | 
                                                        
| 1558 | 1558 | }  | 
                                                        
| 1559 | 1559 | |
| 1560 | -        if ( $formatted && $invoice_date ) { | 
                                                        |
| 1561 | - $invoice_date = date_i18n( get_option( 'date_format' ), strtotime( $invoice_date ) );  | 
                                                        |
| 1560 | +        if ($formatted && $invoice_date) { | 
                                                        |
| 1561 | +            $invoice_date = date_i18n(get_option('date_format'), strtotime($invoice_date)); | 
                                                        |
| 1562 | 1562 | }  | 
                                                        
| 1563 | 1563 | |
| 1564 | - return apply_filters( 'wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this );  | 
                                                        |
| 1564 | +        return apply_filters('wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this); | 
                                                        |
| 1565 | 1565 | }  | 
                                                        
| 1566 | 1566 | |
| 1567 | 1567 |      public function get_ip() { | 
                                                        
| 1568 | - return apply_filters( 'wpinv_user_ip', $this->ip, $this->ID, $this );  | 
                                                        |
| 1568 | +        return apply_filters('wpinv_user_ip', $this->ip, $this->ID, $this); | 
                                                        |
| 1569 | 1569 | }  | 
                                                        
| 1570 | 1570 | |
| 1571 | -    public function has_status( $status ) { | 
                                                        |
| 1572 | - return apply_filters( 'wpinv_has_status', ( is_array( $status ) && in_array( $this->get_status(), $status ) ) || $this->get_status() === $status ? true : false, $this, $status );  | 
                                                        |
| 1571 | +    public function has_status($status) { | 
                                                        |
| 1572 | +        return apply_filters('wpinv_has_status', (is_array($status) && in_array($this->get_status(), $status)) || $this->get_status() === $status ? true : false, $this, $status); | 
                                                        |
| 1573 | 1573 | }  | 
                                                        
| 1574 | 1574 | |
| 1575 | -    public function add_item( $item_id = 0, $args = array() ) { | 
                                                        |
| 1575 | +    public function add_item($item_id = 0, $args = array()) { | 
                                                        |
| 1576 | 1576 | global $wpi_current_id, $wpi_item_id;  | 
                                                        
| 1577 | 1577 | |
| 1578 | - $item = new WPInv_Item( $item_id );  | 
                                                        |
| 1578 | + $item = new WPInv_Item($item_id);  | 
                                                        |
| 1579 | 1579 | |
| 1580 | 1580 | // Bail if this post isn't a item  | 
                                                        
| 1581 | -        if( !$item || $item->post_type !== 'wpi_item' ) { | 
                                                        |
| 1581 | +        if (!$item || $item->post_type !== 'wpi_item') { | 
                                                        |
| 1582 | 1582 | return false;  | 
                                                        
| 1583 | 1583 | }  | 
                                                        
| 1584 | 1584 | |
@@ -1597,8 +1597,8 @@ discard block  | 
                                                    ||
| 1597 | 1597 | 'fees' => array()  | 
                                                        
| 1598 | 1598 | );  | 
                                                        
| 1599 | 1599 | |
| 1600 | - $args = wp_parse_args( apply_filters( 'wpinv_add_item_args', $args, $item->ID ), $defaults );  | 
                                                        |
| 1601 | - $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint( $args['quantity'] ) : 1;  | 
                                                        |
| 1600 | +        $args = wp_parse_args(apply_filters('wpinv_add_item_args', $args, $item->ID), $defaults); | 
                                                        |
| 1601 | + $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint($args['quantity']) : 1;  | 
                                                        |
| 1602 | 1602 | |
| 1603 | 1603 | $wpi_current_id = $this->ID;  | 
                                                        
| 1604 | 1604 | $wpi_item_id = $item->ID;  | 
                                                        
@@ -1610,19 +1610,19 @@ discard block  | 
                                                    ||
| 1610 | 1610 | $found_cart_key = false;  | 
                                                        
| 1611 | 1611 | |
| 1612 | 1612 |          if ($has_quantities) { | 
                                                        
| 1613 | - $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details;  | 
                                                        |
| 1613 | + $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details;  | 
                                                        |
| 1614 | 1614 | |
| 1615 | -            foreach ( $this->items as $key => $cart_item ) { | 
                                                        |
| 1616 | -                if ( (int)$item_id !== (int)$cart_item['id'] ) { | 
                                                        |
| 1615 | +            foreach ($this->items as $key => $cart_item) { | 
                                                        |
| 1616 | +                if ((int)$item_id !== (int)$cart_item['id']) { | 
                                                        |
| 1617 | 1617 | continue;  | 
                                                        
| 1618 | 1618 | }  | 
                                                        
| 1619 | 1619 | |
| 1620 | - $this->items[ $key ]['quantity'] += $args['quantity'];  | 
                                                        |
| 1620 | + $this->items[$key]['quantity'] += $args['quantity'];  | 
                                                        |
| 1621 | 1621 | break;  | 
                                                        
| 1622 | 1622 | }  | 
                                                        
| 1623 | 1623 | |
| 1624 | -            foreach ( $this->cart_details as $cart_key => $cart_item ) { | 
                                                        |
| 1625 | -                if ( $item_id != $cart_item['id'] ) { | 
                                                        |
| 1624 | +            foreach ($this->cart_details as $cart_key => $cart_item) { | 
                                                        |
| 1625 | +                if ($item_id != $cart_item['id']) { | 
                                                        |
| 1626 | 1626 | continue;  | 
                                                        
| 1627 | 1627 | }  | 
                                                        
| 1628 | 1628 | |
@@ -1634,29 +1634,29 @@ discard block  | 
                                                    ||
| 1634 | 1634 |          if ($has_quantities && $found_cart_key !== false) { | 
                                                        
| 1635 | 1635 | $cart_item = $this->cart_details[$found_cart_key];  | 
                                                        
| 1636 | 1636 | $item_price = $cart_item['item_price'];  | 
                                                        
| 1637 | - $quantity = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1;  | 
                                                        |
| 1638 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0;  | 
                                                        |
| 1637 | + $quantity = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1;  | 
                                                        |
| 1638 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0;  | 
                                                        |
| 1639 | 1639 | |
| 1640 | 1640 | $new_quantity = $quantity + $args['quantity'];  | 
                                                        
| 1641 | 1641 | $subtotal = $item_price * $new_quantity;  | 
                                                        
| 1642 | 1642 | |
| 1643 | 1643 | $args['quantity'] = $new_quantity;  | 
                                                        
| 1644 | - $discount = !empty( $args['discount'] ) ? $args['discount'] : 0;  | 
                                                        |
| 1645 | - $tax = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;  | 
                                                        |
| 1644 | + $discount = !empty($args['discount']) ? $args['discount'] : 0;  | 
                                                        |
| 1645 | + $tax = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;  | 
                                                        |
| 1646 | 1646 | |
| 1647 | 1647 | $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float)$cart_item['discount'] ? $discount - (float)$cart_item['discount'] : 0;  | 
                                                        
| 1648 | 1648 | $tax_increased = $tax > 0 && $subtotal > 0 && $tax > (float)$cart_item['tax'] ? $tax - (float)$cart_item['tax'] : 0;  | 
                                                        
| 1649 | 1649 | // The total increase equals the number removed * the item_price  | 
                                                        
| 1650 | - $total_increased = wpinv_round_amount( $item_price );  | 
                                                        |
| 1650 | + $total_increased = wpinv_round_amount($item_price);  | 
                                                        |
| 1651 | 1651 | |
| 1652 | -            if ( wpinv_prices_include_tax() ) { | 
                                                        |
| 1653 | - $subtotal -= wpinv_round_amount( $tax );  | 
                                                        |
| 1652 | +            if (wpinv_prices_include_tax()) { | 
                                                        |
| 1653 | + $subtotal -= wpinv_round_amount($tax);  | 
                                                        |
| 1654 | 1654 | }  | 
                                                        
| 1655 | 1655 | |
| 1656 | - $total = $subtotal - $discount + $tax;  | 
                                                        |
| 1656 | + $total = $subtotal - $discount + $tax;  | 
                                                        |
| 1657 | 1657 | |
| 1658 | 1658 | // Do not allow totals to go negative  | 
                                                        
| 1659 | -            if( $total < 0 ) { | 
                                                        |
| 1659 | +            if ($total < 0) { | 
                                                        |
| 1660 | 1660 | $total = 0;  | 
                                                        
| 1661 | 1661 | }  | 
                                                        
| 1662 | 1662 | |
@@ -1672,25 +1672,25 @@ discard block  | 
                                                    ||
| 1672 | 1672 | $this->cart_details[$found_cart_key] = $cart_item;  | 
                                                        
| 1673 | 1673 |          } else { | 
                                                        
| 1674 | 1674 | // Set custom price.  | 
                                                        
| 1675 | -            if ( $args['custom_price'] !== '' ) { | 
                                                        |
| 1675 | +            if ($args['custom_price'] !== '') { | 
                                                        |
| 1676 | 1676 | $item_price = $args['custom_price'];  | 
                                                        
| 1677 | 1677 |              } else { | 
                                                        
| 1678 | 1678 | // Allow overriding the price  | 
                                                        
| 1679 | -                if ( false !== $args['item_price'] ) { | 
                                                        |
| 1679 | +                if (false !== $args['item_price']) { | 
                                                        |
| 1680 | 1680 | $item_price = $args['item_price'];  | 
                                                        
| 1681 | 1681 |                  } else { | 
                                                        
| 1682 | - $item_price = wpinv_get_item_price( $item->ID );  | 
                                                        |
| 1682 | + $item_price = wpinv_get_item_price($item->ID);  | 
                                                        |
| 1683 | 1683 | }  | 
                                                        
| 1684 | 1684 | }  | 
                                                        
| 1685 | 1685 | |
| 1686 | 1686 | // Sanitizing the price here so we don't have a dozen calls later  | 
                                                        
| 1687 | - $item_price = wpinv_sanitize_amount( $item_price );  | 
                                                        |
| 1688 | - $subtotal = wpinv_round_amount( $item_price * $args['quantity'] );  | 
                                                        |
| 1687 | + $item_price = wpinv_sanitize_amount($item_price);  | 
                                                        |
| 1688 | + $subtotal = wpinv_round_amount($item_price * $args['quantity']);  | 
                                                        |
| 1689 | 1689 | |
| 1690 | - $discount = !empty( $args['discount'] ) ? $args['discount'] : 0;  | 
                                                        |
| 1691 | - $tax_class = !empty( $args['vat_class'] ) ? $args['vat_class'] : '';  | 
                                                        |
| 1692 | - $tax_rate = !empty( $args['vat_rate'] ) ? $args['vat_rate'] : 0;  | 
                                                        |
| 1693 | - $tax = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;  | 
                                                        |
| 1690 | + $discount = !empty($args['discount']) ? $args['discount'] : 0;  | 
                                                        |
| 1691 | + $tax_class = !empty($args['vat_class']) ? $args['vat_class'] : '';  | 
                                                        |
| 1692 | + $tax_rate = !empty($args['vat_rate']) ? $args['vat_rate'] : 0;  | 
                                                        |
| 1693 | + $tax = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;  | 
                                                        |
| 1694 | 1694 | |
| 1695 | 1695 | // Setup the items meta item  | 
                                                        
| 1696 | 1696 | $new_item = array(  | 
                                                        
@@ -1698,29 +1698,29 @@ discard block  | 
                                                    ||
| 1698 | 1698 | 'quantity' => $args['quantity'],  | 
                                                        
| 1699 | 1699 | );  | 
                                                        
| 1700 | 1700 | |
| 1701 | - $this->items[] = $new_item;  | 
                                                        |
| 1701 | + $this->items[] = $new_item;  | 
                                                        |
| 1702 | 1702 | |
| 1703 | -            if ( wpinv_prices_include_tax() ) { | 
                                                        |
| 1704 | - $subtotal -= wpinv_round_amount( $tax );  | 
                                                        |
| 1703 | +            if (wpinv_prices_include_tax()) { | 
                                                        |
| 1704 | + $subtotal -= wpinv_round_amount($tax);  | 
                                                        |
| 1705 | 1705 | }  | 
                                                        
| 1706 | 1706 | |
| 1707 | - $total = $subtotal - $discount + $tax;  | 
                                                        |
| 1707 | + $total = $subtotal - $discount + $tax;  | 
                                                        |
| 1708 | 1708 | |
| 1709 | 1709 | // Do not allow totals to go negative  | 
                                                        
| 1710 | -            if( $total < 0 ) { | 
                                                        |
| 1710 | +            if ($total < 0) { | 
                                                        |
| 1711 | 1711 | $total = 0;  | 
                                                        
| 1712 | 1712 | }  | 
                                                        
| 1713 | 1713 | |
| 1714 | 1714 | $this->cart_details[] = array(  | 
                                                        
| 1715 | 1715 | 'name' => !empty($args['name']) ? $args['name'] : $item->get_name(),  | 
                                                        
| 1716 | 1716 | 'id' => $item->ID,  | 
                                                        
| 1717 | - 'item_price' => wpinv_round_amount( $item_price ),  | 
                                                        |
| 1718 | - 'custom_price' => ( $args['custom_price'] !== '' ? wpinv_round_amount( $args['custom_price'] ) : '' ),  | 
                                                        |
| 1717 | + 'item_price' => wpinv_round_amount($item_price),  | 
                                                        |
| 1718 | + 'custom_price' => ($args['custom_price'] !== '' ? wpinv_round_amount($args['custom_price']) : ''),  | 
                                                        |
| 1719 | 1719 | 'quantity' => $args['quantity'],  | 
                                                        
| 1720 | 1720 | 'discount' => $discount,  | 
                                                        
| 1721 | - 'subtotal' => wpinv_round_amount( $subtotal ),  | 
                                                        |
| 1722 | - 'tax' => wpinv_round_amount( $tax ),  | 
                                                        |
| 1723 | - 'price' => wpinv_round_amount( $total ),  | 
                                                        |
| 1721 | + 'subtotal' => wpinv_round_amount($subtotal),  | 
                                                        |
| 1722 | + 'tax' => wpinv_round_amount($tax),  | 
                                                        |
| 1723 | + 'price' => wpinv_round_amount($total),  | 
                                                        |
| 1724 | 1724 | 'vat_rate' => $tax_rate,  | 
                                                        
| 1725 | 1725 | 'vat_class' => $tax_class,  | 
                                                        
| 1726 | 1726 | 'meta' => $args['meta'],  | 
                                                        
@@ -1730,18 +1730,18 @@ discard block  | 
                                                    ||
| 1730 | 1730 | $subtotal = $subtotal - $discount;  | 
                                                        
| 1731 | 1731 | }  | 
                                                        
| 1732 | 1732 | |
| 1733 | - $added_item = end( $this->cart_details );  | 
                                                        |
| 1734 | - $added_item['action'] = 'add';  | 
                                                        |
| 1733 | + $added_item = end($this->cart_details);  | 
                                                        |
| 1734 | + $added_item['action'] = 'add';  | 
                                                        |
| 1735 | 1735 | |
| 1736 | 1736 | $this->pending['items'][] = $added_item;  | 
                                                        
| 1737 | 1737 | |
| 1738 | - $this->increase_subtotal( $subtotal );  | 
                                                        |
| 1739 | - $this->increase_tax( $tax );  | 
                                                        |
| 1738 | + $this->increase_subtotal($subtotal);  | 
                                                        |
| 1739 | + $this->increase_tax($tax);  | 
                                                        |
| 1740 | 1740 | |
| 1741 | 1741 | return true;  | 
                                                        
| 1742 | 1742 | }  | 
                                                        
| 1743 | 1743 | |
| 1744 | -    public function remove_item( $item_id, $args = array() ) { | 
                                                        |
| 1744 | +    public function remove_item($item_id, $args = array()) { | 
                                                        |
| 1745 | 1745 | // Set some defaults  | 
                                                        
| 1746 | 1746 | $defaults = array(  | 
                                                        
| 1747 | 1747 | 'quantity' => 1,  | 
                                                        
@@ -1749,51 +1749,51 @@ discard block  | 
                                                    ||
| 1749 | 1749 | 'custom_price' => '',  | 
                                                        
| 1750 | 1750 | 'cart_index' => false,  | 
                                                        
| 1751 | 1751 | );  | 
                                                        
| 1752 | - $args = wp_parse_args( $args, $defaults );  | 
                                                        |
| 1752 | + $args = wp_parse_args($args, $defaults);  | 
                                                        |
| 1753 | 1753 | |
| 1754 | 1754 | // Bail if this post isn't a item  | 
                                                        
| 1755 | -        if ( get_post_type( $item_id ) !== 'wpi_item' ) { | 
                                                        |
| 1755 | +        if (get_post_type($item_id) !== 'wpi_item') { | 
                                                        |
| 1756 | 1756 | return false;  | 
                                                        
| 1757 | 1757 | }  | 
                                                        
| 1758 | 1758 | |
| 1759 | - $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details;  | 
                                                        |
| 1759 | + $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details;  | 
                                                        |
| 1760 | 1760 | |
| 1761 | -        foreach ( $this->items as $key => $item ) { | 
                                                        |
| 1762 | -            if ( !empty($item['id']) && (int)$item_id !== (int)$item['id'] ) { | 
                                                        |
| 1761 | +        foreach ($this->items as $key => $item) { | 
                                                        |
| 1762 | +            if (!empty($item['id']) && (int)$item_id !== (int)$item['id']) { | 
                                                        |
| 1763 | 1763 | continue;  | 
                                                        
| 1764 | 1764 | }  | 
                                                        
| 1765 | 1765 | |
| 1766 | -            if ( false !== $args['cart_index'] ) { | 
                                                        |
| 1767 | - $cart_index = absint( $args['cart_index'] );  | 
                                                        |
| 1768 | - $cart_item = ! empty( $this->cart_details[ $cart_index ] ) ? $this->cart_details[ $cart_index ] : false;  | 
                                                        |
| 1766 | +            if (false !== $args['cart_index']) { | 
                                                        |
| 1767 | + $cart_index = absint($args['cart_index']);  | 
                                                        |
| 1768 | + $cart_item = !empty($this->cart_details[$cart_index]) ? $this->cart_details[$cart_index] : false;  | 
                                                        |
| 1769 | 1769 | |
| 1770 | -                if ( ! empty( $cart_item ) ) { | 
                                                        |
| 1770 | +                if (!empty($cart_item)) { | 
                                                        |
| 1771 | 1771 | // If the cart index item isn't the same item ID, don't remove it  | 
                                                        
| 1772 | -                    if ( !empty($cart_item['id']) && $cart_item['id'] != $item['id'] ) { | 
                                                        |
| 1772 | +                    if (!empty($cart_item['id']) && $cart_item['id'] != $item['id']) { | 
                                                        |
| 1773 | 1773 | continue;  | 
                                                        
| 1774 | 1774 | }  | 
                                                        
| 1775 | 1775 | }  | 
                                                        
| 1776 | 1776 | }  | 
                                                        
| 1777 | 1777 | |
| 1778 | - $item_quantity = $this->items[ $key ]['quantity'];  | 
                                                        |
| 1779 | -            if ( $item_quantity > $args['quantity'] ) { | 
                                                        |
| 1780 | - $this->items[ $key ]['quantity'] -= $args['quantity'];  | 
                                                        |
| 1778 | + $item_quantity = $this->items[$key]['quantity'];  | 
                                                        |
| 1779 | +            if ($item_quantity > $args['quantity']) { | 
                                                        |
| 1780 | + $this->items[$key]['quantity'] -= $args['quantity'];  | 
                                                        |
| 1781 | 1781 | break;  | 
                                                        
| 1782 | 1782 |              } else { | 
                                                        
| 1783 | - unset( $this->items[ $key ] );  | 
                                                        |
| 1783 | + unset($this->items[$key]);  | 
                                                        |
| 1784 | 1784 | break;  | 
                                                        
| 1785 | 1785 | }  | 
                                                        
| 1786 | 1786 | }  | 
                                                        
| 1787 | 1787 | |
| 1788 | 1788 | $found_cart_key = false;  | 
                                                        
| 1789 | -        if ( false === $args['cart_index'] ) { | 
                                                        |
| 1790 | -            foreach ( $this->cart_details as $cart_key => $item ) { | 
                                                        |
| 1791 | -                if ( $item_id != $item['id'] ) { | 
                                                        |
| 1789 | +        if (false === $args['cart_index']) { | 
                                                        |
| 1790 | +            foreach ($this->cart_details as $cart_key => $item) { | 
                                                        |
| 1791 | +                if ($item_id != $item['id']) { | 
                                                        |
| 1792 | 1792 | continue;  | 
                                                        
| 1793 | 1793 | }  | 
                                                        
| 1794 | 1794 | |
| 1795 | -                if ( false !== $args['item_price'] ) { | 
                                                        |
| 1796 | -                    if ( isset( $item['item_price'] ) && (float) $args['item_price'] != (float) $item['item_price'] ) { | 
                                                        |
| 1795 | +                if (false !== $args['item_price']) { | 
                                                        |
| 1796 | +                    if (isset($item['item_price']) && (float)$args['item_price'] != (float)$item['item_price']) { | 
                                                        |
| 1797 | 1797 | continue;  | 
                                                        
| 1798 | 1798 | }  | 
                                                        
| 1799 | 1799 | }  | 
                                                        
@@ -1802,13 +1802,13 @@ discard block  | 
                                                    ||
| 1802 | 1802 | break;  | 
                                                        
| 1803 | 1803 | }  | 
                                                        
| 1804 | 1804 |          } else { | 
                                                        
| 1805 | - $cart_index = absint( $args['cart_index'] );  | 
                                                        |
| 1805 | + $cart_index = absint($args['cart_index']);  | 
                                                        |
| 1806 | 1806 | |
| 1807 | -            if ( ! array_key_exists( $cart_index, $this->cart_details ) ) { | 
                                                        |
| 1807 | +            if (!array_key_exists($cart_index, $this->cart_details)) { | 
                                                        |
| 1808 | 1808 | return false; // Invalid cart index passed.  | 
                                                        
| 1809 | 1809 | }  | 
                                                        
| 1810 | 1810 | |
| 1811 | -            if ( (int) $this->cart_details[ $cart_index ]['id'] > 0 && (int) $this->cart_details[ $cart_index ]['id'] !== (int) $item_id ) { | 
                                                        |
| 1811 | +            if ((int)$this->cart_details[$cart_index]['id'] > 0 && (int)$this->cart_details[$cart_index]['id'] !== (int)$item_id) { | 
                                                        |
| 1812 | 1812 | return false; // We still need the proper Item ID to be sure.  | 
                                                        
| 1813 | 1813 | }  | 
                                                        
| 1814 | 1814 | |
@@ -1816,41 +1816,41 @@ discard block  | 
                                                    ||
| 1816 | 1816 | }  | 
                                                        
| 1817 | 1817 | |
| 1818 | 1818 | $cart_item = $this->cart_details[$found_cart_key];  | 
                                                        
| 1819 | - $quantity = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1;  | 
                                                        |
| 1819 | + $quantity = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1;  | 
                                                        |
| 1820 | 1820 | |
| 1821 | -        if ( count( $this->cart_details ) == 1 && ( $quantity - $args['quantity'] ) < 1 ) { | 
                                                        |
| 1821 | +        if (count($this->cart_details) == 1 && ($quantity - $args['quantity']) < 1) { | 
                                                        |
| 1822 | 1822 | return false; // Invoice must contain at least one item.  | 
                                                        
| 1823 | 1823 | }  | 
                                                        
| 1824 | 1824 | |
| 1825 | - $discounts = $this->get_discounts();  | 
                                                        |
| 1825 | + $discounts = $this->get_discounts();  | 
                                                        |
| 1826 | 1826 | |
| 1827 | -        if ( $quantity > $args['quantity'] ) { | 
                                                        |
| 1827 | +        if ($quantity > $args['quantity']) { | 
                                                        |
| 1828 | 1828 | $item_price = $cart_item['item_price'];  | 
                                                        
| 1829 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0;  | 
                                                        |
| 1829 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0;  | 
                                                        |
| 1830 | 1830 | |
| 1831 | - $new_quantity = max( $quantity - $args['quantity'], 1);  | 
                                                        |
| 1831 | + $new_quantity = max($quantity - $args['quantity'], 1);  | 
                                                        |
| 1832 | 1832 | $subtotal = $item_price * $new_quantity;  | 
                                                        
| 1833 | 1833 | |
| 1834 | 1834 | $args['quantity'] = $new_quantity;  | 
                                                        
| 1835 | - $discount = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0;  | 
                                                        |
| 1836 | - $tax = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;  | 
                                                        |
| 1835 | + $discount = !empty($cart_item['discount']) ? $cart_item['discount'] : 0;  | 
                                                        |
| 1836 | + $tax = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;  | 
                                                        |
| 1837 | 1837 | |
| 1838 | - $discount_decrease = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['discount'] / $quantity ) ) : 0;  | 
                                                        |
| 1838 | + $discount_decrease = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount(((float)$cart_item['discount'] / $quantity)) : 0;  | 
                                                        |
| 1839 | 1839 | $discount_decrease = $discount > 0 && $subtotal > 0 && (float)$cart_item['discount'] > $discount ? (float)$cart_item['discount'] - $discount : $discount_decrease;  | 
                                                        
| 1840 | - $tax_decrease = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['tax'] / $quantity ) ) : 0;  | 
                                                        |
| 1840 | + $tax_decrease = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount(((float)$cart_item['tax'] / $quantity)) : 0;  | 
                                                        |
| 1841 | 1841 | $tax_decrease = $tax > 0 && $subtotal > 0 && (float)$cart_item['tax'] > $tax ? (float)$cart_item['tax'] - $tax : $tax_decrease;  | 
                                                        
| 1842 | 1842 | |
| 1843 | 1843 | // The total increase equals the number removed * the item_price  | 
                                                        
| 1844 | - $total_decrease = wpinv_round_amount( $item_price );  | 
                                                        |
| 1844 | + $total_decrease = wpinv_round_amount($item_price);  | 
                                                        |
| 1845 | 1845 | |
| 1846 | -            if ( wpinv_prices_include_tax() ) { | 
                                                        |
| 1847 | - $subtotal -= wpinv_round_amount( $tax );  | 
                                                        |
| 1846 | +            if (wpinv_prices_include_tax()) { | 
                                                        |
| 1847 | + $subtotal -= wpinv_round_amount($tax);  | 
                                                        |
| 1848 | 1848 | }  | 
                                                        
| 1849 | 1849 | |
| 1850 | - $total = $subtotal - $discount + $tax;  | 
                                                        |
| 1850 | + $total = $subtotal - $discount + $tax;  | 
                                                        |
| 1851 | 1851 | |
| 1852 | 1852 | // Do not allow totals to go negative  | 
                                                        
| 1853 | -            if( $total < 0 ) { | 
                                                        |
| 1853 | +            if ($total < 0) { | 
                                                        |
| 1854 | 1854 | $total = 0;  | 
                                                        
| 1855 | 1855 | }  | 
                                                        
| 1856 | 1856 | |
@@ -1869,16 +1869,16 @@ discard block  | 
                                                    ||
| 1869 | 1869 | |
| 1870 | 1870 | $this->cart_details[$found_cart_key] = $cart_item;  | 
                                                        
| 1871 | 1871 | |
| 1872 | - $remove_item = end( $this->cart_details );  | 
                                                        |
| 1872 | + $remove_item = end($this->cart_details);  | 
                                                        |
| 1873 | 1873 |          } else { | 
                                                        
| 1874 | 1874 | $item_price = $cart_item['item_price'];  | 
                                                        
| 1875 | - $discount = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0;  | 
                                                        |
| 1876 | - $tax = !empty( $cart_item['tax'] ) ? $cart_item['tax'] : 0;  | 
                                                        |
| 1875 | + $discount = !empty($cart_item['discount']) ? $cart_item['discount'] : 0;  | 
                                                        |
| 1876 | + $tax = !empty($cart_item['tax']) ? $cart_item['tax'] : 0;  | 
                                                        |
| 1877 | 1877 | |
| 1878 | - $subtotal_decrease = ( $item_price * $quantity ) - $discount;  | 
                                                        |
| 1878 | + $subtotal_decrease = ($item_price * $quantity) - $discount;  | 
                                                        |
| 1879 | 1879 | $tax_decrease = $tax;  | 
                                                        
| 1880 | 1880 | |
| 1881 | - unset( $this->cart_details[$found_cart_key] );  | 
                                                        |
| 1881 | + unset($this->cart_details[$found_cart_key]);  | 
                                                        |
| 1882 | 1882 | |
| 1883 | 1883 | $remove_item = $args;  | 
                                                        
| 1884 | 1884 | $remove_item['id'] = $item_id;  | 
                                                        
@@ -1889,8 +1889,8 @@ discard block  | 
                                                    ||
| 1889 | 1889 | $remove_item['action'] = 'remove';  | 
                                                        
| 1890 | 1890 | $this->pending['items'][] = $remove_item;  | 
                                                        
| 1891 | 1891 | |
| 1892 | - $this->decrease_subtotal( $subtotal_decrease );  | 
                                                        |
| 1893 | - $this->decrease_tax( $tax_decrease );  | 
                                                        |
| 1892 | + $this->decrease_subtotal($subtotal_decrease);  | 
                                                        |
| 1893 | + $this->decrease_tax($tax_decrease);  | 
                                                        |
| 1894 | 1894 | |
| 1895 | 1895 | return true;  | 
                                                        
| 1896 | 1896 | }  | 
                                                        
@@ -1898,7 +1898,7 @@ discard block  | 
                                                    ||
| 1898 | 1898 |      public function update_items($temp = false) { | 
                                                        
| 1899 | 1899 | global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpi_nosave;  | 
                                                        
| 1900 | 1900 | |
| 1901 | -        if ( !empty( $this->cart_details ) ) { | 
                                                        |
| 1901 | +        if (!empty($this->cart_details)) { | 
                                                        |
| 1902 | 1902 | $wpi_nosave = $temp;  | 
                                                        
| 1903 | 1903 | $cart_subtotal = 0;  | 
                                                        
| 1904 | 1904 | $cart_discount = 0;  | 
                                                        
@@ -1908,42 +1908,42 @@ discard block  | 
                                                    ||
| 1908 | 1908 | $_POST['wpinv_country'] = $this->country;  | 
                                                        
| 1909 | 1909 | $_POST['wpinv_state'] = $this->state;  | 
                                                        
| 1910 | 1910 | |
| 1911 | -            foreach ( $this->cart_details as $key => $item ) { | 
                                                        |
| 1911 | +            foreach ($this->cart_details as $key => $item) { | 
                                                        |
| 1912 | 1912 | $item_price = $item['item_price'];  | 
                                                        
| 1913 | - $quantity = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;  | 
                                                        |
| 1914 | - $amount = wpinv_round_amount( $item_price * $quantity );  | 
                                                        |
| 1913 | + $quantity = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint($item['quantity']) : 1;  | 
                                                        |
| 1914 | + $amount = wpinv_round_amount($item_price * $quantity);  | 
                                                        |
| 1915 | 1915 | $subtotal = $item_price * $quantity;  | 
                                                        
| 1916 | 1916 | |
| 1917 | 1917 | $wpi_current_id = $this->ID;  | 
                                                        
| 1918 | 1918 | $wpi_item_id = $item['id'];  | 
                                                        
| 1919 | 1919 | |
| 1920 | - $discount = wpinv_get_cart_item_discount_amount( $item, $this->get_discounts() );  | 
                                                        |
| 1920 | + $discount = wpinv_get_cart_item_discount_amount($item, $this->get_discounts());  | 
                                                        |
| 1921 | 1921 | |
| 1922 | - $tax_rate = wpinv_get_tax_rate( $this->country, $this->state, $wpi_item_id );  | 
                                                        |
| 1923 | - $tax_class = $wpinv_euvat->get_item_class( $wpi_item_id );  | 
                                                        |
| 1924 | - $tax = $item_price > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;  | 
                                                        |
| 1922 | + $tax_rate = wpinv_get_tax_rate($this->country, $this->state, $wpi_item_id);  | 
                                                        |
| 1923 | + $tax_class = $wpinv_euvat->get_item_class($wpi_item_id);  | 
                                                        |
| 1924 | + $tax = $item_price > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;  | 
                                                        |
| 1925 | 1925 | |
| 1926 | -                if ( wpinv_prices_include_tax() ) { | 
                                                        |
| 1927 | - $subtotal -= wpinv_round_amount( $tax );  | 
                                                        |
| 1926 | +                if (wpinv_prices_include_tax()) { | 
                                                        |
| 1927 | + $subtotal -= wpinv_round_amount($tax);  | 
                                                        |
| 1928 | 1928 | }  | 
                                                        
| 1929 | 1929 | |
| 1930 | - $total = $subtotal - $discount + $tax;  | 
                                                        |
| 1930 | + $total = $subtotal - $discount + $tax;  | 
                                                        |
| 1931 | 1931 | |
| 1932 | 1932 | // Do not allow totals to go negative  | 
                                                        
| 1933 | -                if( $total < 0 ) { | 
                                                        |
| 1933 | +                if ($total < 0) { | 
                                                        |
| 1934 | 1934 | $total = 0;  | 
                                                        
| 1935 | 1935 | }  | 
                                                        
| 1936 | 1936 | |
| 1937 | 1937 | $cart_details[] = array(  | 
                                                        
| 1938 | 1938 | 'id' => $item['id'],  | 
                                                        
| 1939 | 1939 | 'name' => $item['name'],  | 
                                                        
| 1940 | - 'item_price' => wpinv_round_amount( $item_price ),  | 
                                                        |
| 1941 | - 'custom_price'=> ( isset( $item['custom_price'] ) ? $item['custom_price'] : '' ),  | 
                                                        |
| 1940 | + 'item_price' => wpinv_round_amount($item_price),  | 
                                                        |
| 1941 | + 'custom_price'=> (isset($item['custom_price']) ? $item['custom_price'] : ''),  | 
                                                        |
| 1942 | 1942 | 'quantity' => $quantity,  | 
                                                        
| 1943 | 1943 | 'discount' => $discount,  | 
                                                        
| 1944 | - 'subtotal' => wpinv_round_amount( $subtotal ),  | 
                                                        |
| 1945 | - 'tax' => wpinv_round_amount( $tax ),  | 
                                                        |
| 1946 | - 'price' => wpinv_round_amount( $total ),  | 
                                                        |
| 1944 | + 'subtotal' => wpinv_round_amount($subtotal),  | 
                                                        |
| 1945 | + 'tax' => wpinv_round_amount($tax),  | 
                                                        |
| 1946 | + 'price' => wpinv_round_amount($total),  | 
                                                        |
| 1947 | 1947 | 'vat_rate' => $tax_rate,  | 
                                                        
| 1948 | 1948 | 'vat_class' => $tax_class,  | 
                                                        
| 1949 | 1949 | 'meta' => isset($item['meta']) ? $item['meta'] : array(),  | 
                                                        
@@ -1954,9 +1954,9 @@ discard block  | 
                                                    ||
| 1954 | 1954 | $cart_discount += (float)($discount);  | 
                                                        
| 1955 | 1955 | $cart_tax += (float)($tax);  | 
                                                        
| 1956 | 1956 | }  | 
                                                        
| 1957 | - $this->subtotal = wpinv_round_amount( $cart_subtotal );  | 
                                                        |
| 1958 | - $this->tax = wpinv_round_amount( $cart_tax );  | 
                                                        |
| 1959 | - $this->discount = wpinv_round_amount( $cart_discount );  | 
                                                        |
| 1957 | + $this->subtotal = wpinv_round_amount($cart_subtotal);  | 
                                                        |
| 1958 | + $this->tax = wpinv_round_amount($cart_tax);  | 
                                                        |
| 1959 | + $this->discount = wpinv_round_amount($cart_discount);  | 
                                                        |
| 1960 | 1960 | |
| 1961 | 1961 | $this->recalculate_total();  | 
                                                        
| 1962 | 1962 | |
@@ -1968,221 +1968,221 @@ discard block  | 
                                                    ||
| 1968 | 1968 | |
| 1969 | 1969 |      public function recalculate_totals($temp = false) {         | 
                                                        
| 1970 | 1970 | $this->update_items($temp);  | 
                                                        
| 1971 | - $this->save( true );  | 
                                                        |
| 1971 | + $this->save(true);  | 
                                                        |
| 1972 | 1972 | |
| 1973 | 1973 | return $this;  | 
                                                        
| 1974 | 1974 | }  | 
                                                        
| 1975 | 1975 | |
| 1976 | 1976 |      public function needs_payment() { | 
                                                        
| 1977 | - $valid_invoice_statuses = apply_filters( 'wpinv_valid_invoice_statuses_for_payment', array( 'pending' ), $this );  | 
                                                        |
| 1977 | +        $valid_invoice_statuses = apply_filters('wpinv_valid_invoice_statuses_for_payment', array('pending'), $this); | 
                                                        |
| 1978 | 1978 | |
| 1979 | -        if ( $this->has_status( $valid_invoice_statuses ) && ( $this->get_total() > 0 || $this->is_free_trial() || $this->is_free() ) ) { | 
                                                        |
| 1979 | +        if ($this->has_status($valid_invoice_statuses) && ($this->get_total() > 0 || $this->is_free_trial() || $this->is_free())) { | 
                                                        |
| 1980 | 1980 | $needs_payment = true;  | 
                                                        
| 1981 | 1981 |          } else { | 
                                                        
| 1982 | 1982 | $needs_payment = false;  | 
                                                        
| 1983 | 1983 | }  | 
                                                        
| 1984 | 1984 | |
| 1985 | - return apply_filters( 'wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses );  | 
                                                        |
| 1985 | +        return apply_filters('wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses); | 
                                                        |
| 1986 | 1986 | }  | 
                                                        
| 1987 | 1987 | |
| 1988 | -    public function get_checkout_payment_url( $on_checkout = false, $secret = false ) { | 
                                                        |
| 1988 | +    public function get_checkout_payment_url($on_checkout = false, $secret = false) { | 
                                                        |
| 1989 | 1989 | $pay_url = wpinv_get_checkout_uri();  | 
                                                        
| 1990 | 1990 | |
| 1991 | -        if ( is_ssl() ) { | 
                                                        |
| 1992 | - $pay_url = str_replace( 'http:', 'https:', $pay_url );  | 
                                                        |
| 1991 | +        if (is_ssl()) { | 
                                                        |
| 1992 | +            $pay_url = str_replace('http:', 'https:', $pay_url); | 
                                                        |
| 1993 | 1993 | }  | 
                                                        
| 1994 | 1994 | |
| 1995 | 1995 | $key = $this->get_key();  | 
                                                        
| 1996 | 1996 | |
| 1997 | -        if ( $on_checkout ) { | 
                                                        |
| 1998 | - $pay_url = add_query_arg( 'invoice_key', $key, $pay_url );  | 
                                                        |
| 1997 | +        if ($on_checkout) { | 
                                                        |
| 1998 | +            $pay_url = add_query_arg('invoice_key', $key, $pay_url); | 
                                                        |
| 1999 | 1999 |          } else { | 
                                                        
| 2000 | - $pay_url = add_query_arg( array( 'wpi_action' => 'pay_for_invoice', 'invoice_key' => $key ), $pay_url );  | 
                                                        |
| 2000 | +            $pay_url = add_query_arg(array('wpi_action' => 'pay_for_invoice', 'invoice_key' => $key), $pay_url); | 
                                                        |
| 2001 | 2001 | }  | 
                                                        
| 2002 | 2002 | |
| 2003 | -        if ( $secret ) { | 
                                                        |
| 2004 | - $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $key ) ), $pay_url );  | 
                                                        |
| 2003 | +        if ($secret) { | 
                                                        |
| 2004 | +            $pay_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $key)), $pay_url); | 
                                                        |
| 2005 | 2005 | }  | 
                                                        
| 2006 | 2006 | |
| 2007 | - return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this );  | 
                                                        |
| 2007 | +        return apply_filters('wpinv_get_checkout_payment_url', $pay_url, $this); | 
                                                        |
| 2008 | 2008 | }  | 
                                                        
| 2009 | 2009 | |
| 2010 | -    public function get_view_url( $secret = false ) { | 
                                                        |
| 2011 | - $print_url = get_permalink( $this->ID );  | 
                                                        |
| 2010 | +    public function get_view_url($secret = false) { | 
                                                        |
| 2011 | + $print_url = get_permalink($this->ID);  | 
                                                        |
| 2012 | 2012 | |
| 2013 | -        if ( $secret ) { | 
                                                        |
| 2014 | - $print_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $print_url );  | 
                                                        |
| 2013 | +        if ($secret) { | 
                                                        |
| 2014 | +            $print_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key())), $print_url); | 
                                                        |
| 2015 | 2015 | }  | 
                                                        
| 2016 | 2016 | |
| 2017 | - return apply_filters( 'wpinv_get_view_url', $print_url, $this );  | 
                                                        |
| 2017 | +        return apply_filters('wpinv_get_view_url', $print_url, $this); | 
                                                        |
| 2018 | 2018 | }  | 
                                                        
| 2019 | 2019 | |
| 2020 | -    public function generate_key( $string = '' ) { | 
                                                        |
| 2021 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : '';  | 
                                                        |
| 2022 | - return strtolower( md5( $string . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'wpinv', true ) ) ); // Unique key  | 
                                                        |
| 2020 | +    public function generate_key($string = '') { | 
                                                        |
| 2021 | +        $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; | 
                                                        |
| 2022 | +        return strtolower(md5($string . date('Y-m-d H:i:s') . $auth_key . uniqid('wpinv', true))); // Unique key | 
                                                        |
| 2023 | 2023 | }  | 
                                                        
| 2024 | 2024 | |
| 2025 | 2025 |      public function is_recurring() { | 
                                                        
| 2026 | -        if ( empty( $this->cart_details ) ) { | 
                                                        |
| 2026 | +        if (empty($this->cart_details)) { | 
                                                        |
| 2027 | 2027 | return false;  | 
                                                        
| 2028 | 2028 | }  | 
                                                        
| 2029 | 2029 | |
| 2030 | 2030 | $has_subscription = false;  | 
                                                        
| 2031 | -        foreach( $this->cart_details as $cart_item ) { | 
                                                        |
| 2032 | -            if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) { | 
                                                        |
| 2031 | +        foreach ($this->cart_details as $cart_item) { | 
                                                        |
| 2032 | +            if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { | 
                                                        |
| 2033 | 2033 | $has_subscription = true;  | 
                                                        
| 2034 | 2034 | break;  | 
                                                        
| 2035 | 2035 | }  | 
                                                        
| 2036 | 2036 | }  | 
                                                        
| 2037 | 2037 | |
| 2038 | -        if ( count( $this->cart_details ) > 1 ) { | 
                                                        |
| 2038 | +        if (count($this->cart_details) > 1) { | 
                                                        |
| 2039 | 2039 | $has_subscription = false;  | 
                                                        
| 2040 | 2040 | }  | 
                                                        
| 2041 | 2041 | |
| 2042 | - return apply_filters( 'wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details );  | 
                                                        |
| 2042 | +        return apply_filters('wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details); | 
                                                        |
| 2043 | 2043 | }  | 
                                                        
| 2044 | 2044 | |
| 2045 | 2045 |      public function is_free_trial() { | 
                                                        
| 2046 | 2046 | $is_free_trial = false;  | 
                                                        
| 2047 | 2047 | |
| 2048 | -        if ( $this->is_parent() && $item = $this->get_recurring( true ) ) { | 
                                                        |
| 2049 | -            if ( !empty( $item ) && $item->has_free_trial() ) { | 
                                                        |
| 2048 | +        if ($this->is_parent() && $item = $this->get_recurring(true)) { | 
                                                        |
| 2049 | +            if (!empty($item) && $item->has_free_trial()) { | 
                                                        |
| 2050 | 2050 | $is_free_trial = true;  | 
                                                        
| 2051 | 2051 | }  | 
                                                        
| 2052 | 2052 | }  | 
                                                        
| 2053 | 2053 | |
| 2054 | - return apply_filters( 'wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details );  | 
                                                        |
| 2054 | +        return apply_filters('wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details); | 
                                                        |
| 2055 | 2055 | }  | 
                                                        
| 2056 | 2056 | |
| 2057 | -    public function get_recurring( $object = false ) { | 
                                                        |
| 2057 | +    public function get_recurring($object = false) { | 
                                                        |
| 2058 | 2058 | $item = NULL;  | 
                                                        
| 2059 | 2059 | |
| 2060 | -        if ( empty( $this->cart_details ) ) { | 
                                                        |
| 2060 | +        if (empty($this->cart_details)) { | 
                                                        |
| 2061 | 2061 | return $item;  | 
                                                        
| 2062 | 2062 | }  | 
                                                        
| 2063 | 2063 | |
| 2064 | -        foreach( $this->cart_details as $cart_item ) { | 
                                                        |
| 2065 | -            if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) { | 
                                                        |
| 2064 | +        foreach ($this->cart_details as $cart_item) { | 
                                                        |
| 2065 | +            if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { | 
                                                        |
| 2066 | 2066 | $item = $cart_item['id'];  | 
                                                        
| 2067 | 2067 | break;  | 
                                                        
| 2068 | 2068 | }  | 
                                                        
| 2069 | 2069 | }  | 
                                                        
| 2070 | 2070 | |
| 2071 | -        if ( $object ) { | 
                                                        |
| 2072 | - $item = $item ? new WPInv_Item( $item ) : NULL;  | 
                                                        |
| 2071 | +        if ($object) { | 
                                                        |
| 2072 | + $item = $item ? new WPInv_Item($item) : NULL;  | 
                                                        |
| 2073 | 2073 | |
| 2074 | - apply_filters( 'wpinv_invoice_get_recurring_item', $item, $this );  | 
                                                        |
| 2074 | +            apply_filters('wpinv_invoice_get_recurring_item', $item, $this); | 
                                                        |
| 2075 | 2075 | }  | 
                                                        
| 2076 | 2076 | |
| 2077 | - return apply_filters( 'wpinv_invoice_get_recurring_item_id', $item, $this );  | 
                                                        |
| 2077 | +        return apply_filters('wpinv_invoice_get_recurring_item_id', $item, $this); | 
                                                        |
| 2078 | 2078 | }  | 
                                                        
| 2079 | 2079 | |
| 2080 | 2080 |      public function get_subscription_name() { | 
                                                        
| 2081 | - $item = $this->get_recurring( true );  | 
                                                        |
| 2081 | + $item = $this->get_recurring(true);  | 
                                                        |
| 2082 | 2082 | |
| 2083 | -        if ( empty( $item ) ) { | 
                                                        |
| 2083 | +        if (empty($item)) { | 
                                                        |
| 2084 | 2084 | return NULL;  | 
                                                        
| 2085 | 2085 | }  | 
                                                        
| 2086 | 2086 | |
| 2087 | -        if ( !($name = $item->get_name()) ) { | 
                                                        |
| 2087 | +        if (!($name = $item->get_name())) { | 
                                                        |
| 2088 | 2088 | $name = $item->post_name;  | 
                                                        
| 2089 | 2089 | }  | 
                                                        
| 2090 | 2090 | |
| 2091 | - return apply_filters( 'wpinv_invoice_get_subscription_name', $name, $this );  | 
                                                        |
| 2091 | +        return apply_filters('wpinv_invoice_get_subscription_name', $name, $this); | 
                                                        |
| 2092 | 2092 | }  | 
                                                        
| 2093 | 2093 | |
| 2094 | 2094 |      public function get_expiration() { | 
                                                        
| 2095 | - $expiration = $this->get_meta( '_wpinv_subscr_expiration', true );  | 
                                                        |
| 2095 | +        $expiration = $this->get_meta('_wpinv_subscr_expiration', true); | 
                                                        |
| 2096 | 2096 | return $expiration;  | 
                                                        
| 2097 | 2097 | }  | 
                                                        
| 2098 | 2098 | |
| 2099 | -    public function get_cancelled_date( $formatted = true ) { | 
                                                        |
| 2100 | - $cancelled_date = $this->get_subscription_status() == 'cancelled' ? $this->get_meta( '_wpinv_subscr_cancelled_on', true ) : '';  | 
                                                        |
| 2099 | +    public function get_cancelled_date($formatted = true) { | 
                                                        |
| 2100 | +        $cancelled_date = $this->get_subscription_status() == 'cancelled' ? $this->get_meta('_wpinv_subscr_cancelled_on', true) : ''; | 
                                                        |
| 2101 | 2101 | |
| 2102 | -        if ( $formatted && $cancelled_date ) { | 
                                                        |
| 2103 | - $cancelled_date = date_i18n( get_option( 'date_format' ), strtotime( $cancelled_date ) );  | 
                                                        |
| 2102 | +        if ($formatted && $cancelled_date) { | 
                                                        |
| 2103 | +            $cancelled_date = date_i18n(get_option('date_format'), strtotime($cancelled_date)); | 
                                                        |
| 2104 | 2104 | }  | 
                                                        
| 2105 | 2105 | |
| 2106 | 2106 | return $cancelled_date;  | 
                                                        
| 2107 | 2107 | }  | 
                                                        
| 2108 | 2108 | |
| 2109 | -    public function get_trial_end_date( $formatted = true ) { | 
                                                        |
| 2110 | -        if ( !$this->is_free_trial() || !$this->is_paid() ) { | 
                                                        |
| 2109 | +    public function get_trial_end_date($formatted = true) { | 
                                                        |
| 2110 | +        if (!$this->is_free_trial() || !$this->is_paid()) { | 
                                                        |
| 2111 | 2111 | return NULL;  | 
                                                        
| 2112 | 2112 | }  | 
                                                        
| 2113 | 2113 | |
| 2114 | - $trial_end_date = $this->get_subscription_status() == 'trialing' ? $this->get_meta( '_wpinv_subscr_trial_end', true ) : '';  | 
                                                        |
| 2114 | +        $trial_end_date = $this->get_subscription_status() == 'trialing' ? $this->get_meta('_wpinv_subscr_trial_end', true) : ''; | 
                                                        |
| 2115 | 2115 | |
| 2116 | -        if ( empty( $trial_end_date ) ) { | 
                                                        |
| 2117 | - $trial_start_time = strtotime( $this->get_subscription_start() );  | 
                                                        |
| 2118 | - $trial_start_time += ( wpinv_period_in_days( $this->get_subscription_trial_interval(), $this->get_subscription_trial_period() ) * DAY_IN_SECONDS ) ;  | 
                                                        |
| 2116 | +        if (empty($trial_end_date)) { | 
                                                        |
| 2117 | + $trial_start_time = strtotime($this->get_subscription_start());  | 
                                                        |
| 2118 | + $trial_start_time += (wpinv_period_in_days($this->get_subscription_trial_interval(), $this->get_subscription_trial_period()) * DAY_IN_SECONDS);  | 
                                                        |
| 2119 | 2119 | |
| 2120 | - $trial_end_date = date_i18n( 'Y-m-d H:i:s', $trial_start_time );  | 
                                                        |
| 2120 | +            $trial_end_date = date_i18n('Y-m-d H:i:s', $trial_start_time); | 
                                                        |
| 2121 | 2121 | }  | 
                                                        
| 2122 | 2122 | |
| 2123 | -        if ( $formatted && $trial_end_date ) { | 
                                                        |
| 2124 | - $trial_end_date = date_i18n( get_option( 'date_format' ), strtotime( $trial_end_date ) );  | 
                                                        |
| 2123 | +        if ($formatted && $trial_end_date) { | 
                                                        |
| 2124 | +            $trial_end_date = date_i18n(get_option('date_format'), strtotime($trial_end_date)); | 
                                                        |
| 2125 | 2125 | }  | 
                                                        
| 2126 | 2126 | |
| 2127 | 2127 | return $trial_end_date;  | 
                                                        
| 2128 | 2128 | }  | 
                                                        
| 2129 | 2129 | |
| 2130 | -    public function get_subscription_created( $default = true ) { | 
                                                        |
| 2131 | - $created = $this->get_meta( '_wpinv_subscr_created', true );  | 
                                                        |
| 2130 | +    public function get_subscription_created($default = true) { | 
                                                        |
| 2131 | +        $created = $this->get_meta('_wpinv_subscr_created', true); | 
                                                        |
| 2132 | 2132 | |
| 2133 | -        if ( empty( $created ) && $default ) { | 
                                                        |
| 2133 | +        if (empty($created) && $default) { | 
                                                        |
| 2134 | 2134 | $created = $this->date;  | 
                                                        
| 2135 | 2135 | }  | 
                                                        
| 2136 | 2136 | return $created;  | 
                                                        
| 2137 | 2137 | }  | 
                                                        
| 2138 | 2138 | |
| 2139 | -    public function get_subscription_start( $formatted = true ) { | 
                                                        |
| 2140 | -        if ( !$this->is_paid() ) { | 
                                                        |
| 2139 | +    public function get_subscription_start($formatted = true) { | 
                                                        |
| 2140 | +        if (!$this->is_paid()) { | 
                                                        |
| 2141 | 2141 | return '-';  | 
                                                        
| 2142 | 2142 | }  | 
                                                        
| 2143 | - $start = $this->get_subscription_created();  | 
                                                        |
| 2143 | + $start = $this->get_subscription_created();  | 
                                                        |
| 2144 | 2144 | |
| 2145 | -        if ( $formatted ) { | 
                                                        |
| 2146 | - $date = date_i18n( get_option( 'date_format' ), strtotime( $start ) );  | 
                                                        |
| 2145 | +        if ($formatted) { | 
                                                        |
| 2146 | +            $date = date_i18n(get_option('date_format'), strtotime($start)); | 
                                                        |
| 2147 | 2147 |          } else { | 
                                                        
| 2148 | - $date = date_i18n( 'Y-m-d H:i:s', strtotime( $start ) );  | 
                                                        |
| 2148 | +            $date = date_i18n('Y-m-d H:i:s', strtotime($start)); | 
                                                        |
| 2149 | 2149 | }  | 
                                                        
| 2150 | 2150 | |
| 2151 | 2151 | return $date;  | 
                                                        
| 2152 | 2152 | }  | 
                                                        
| 2153 | 2153 | |
| 2154 | -    public function get_subscription_end( $formatted = true ) { | 
                                                        |
| 2155 | -        if ( !$this->is_paid() ) { | 
                                                        |
| 2154 | +    public function get_subscription_end($formatted = true) { | 
                                                        |
| 2155 | +        if (!$this->is_paid()) { | 
                                                        |
| 2156 | 2156 | return '-';  | 
                                                        
| 2157 | 2157 | }  | 
                                                        
| 2158 | 2158 | $start = $this->get_subscription_created();  | 
                                                        
| 2159 | 2159 | $interval = $this->get_subscription_interval();  | 
                                                        
| 2160 | - $period = $this->get_subscription_period( true );  | 
                                                        |
| 2160 | + $period = $this->get_subscription_period(true);  | 
                                                        |
| 2161 | 2161 | $bill_times = (int)$this->get_bill_times();  | 
                                                        
| 2162 | 2162 | |
| 2163 | -        if ( $bill_times == 0 ) { | 
                                                        |
| 2164 | - return $formatted ? __( 'Until cancelled', 'invoicing' ) : $bill_times;  | 
                                                        |
| 2163 | +        if ($bill_times == 0) { | 
                                                        |
| 2164 | +            return $formatted ? __('Until cancelled', 'invoicing') : $bill_times; | 
                                                        |
| 2165 | 2165 | }  | 
                                                        
| 2166 | 2166 | |
| 2167 | - $total_period = $start . '+' . ( $interval * $bill_times ) . ' ' . $period;  | 
                                                        |
| 2167 | + $total_period = $start . '+' . ($interval * $bill_times) . ' ' . $period;  | 
                                                        |
| 2168 | 2168 | |
| 2169 | - $end_time = strtotime( $start . '+' . ( $interval * $bill_times ) . ' ' . $period );  | 
                                                        |
| 2169 | + $end_time = strtotime($start . '+' . ($interval * $bill_times) . ' ' . $period);  | 
                                                        |
| 2170 | 2170 | |
| 2171 | -        if ( $this->is_free_trial() ) { | 
                                                        |
| 2172 | - $end_time += ( wpinv_period_in_days( $this->get_subscription_trial_interval(), $this->get_subscription_trial_period() ) * DAY_IN_SECONDS ) ;  | 
                                                        |
| 2171 | +        if ($this->is_free_trial()) { | 
                                                        |
| 2172 | + $end_time += (wpinv_period_in_days($this->get_subscription_trial_interval(), $this->get_subscription_trial_period()) * DAY_IN_SECONDS);  | 
                                                        |
| 2173 | 2173 | }  | 
                                                        
| 2174 | 2174 | |
| 2175 | -        if ( $formatted ) { | 
                                                        |
| 2176 | - $date = date_i18n( get_option( 'date_format' ), $end_time );  | 
                                                        |
| 2175 | +        if ($formatted) { | 
                                                        |
| 2176 | +            $date = date_i18n(get_option('date_format'), $end_time); | 
                                                        |
| 2177 | 2177 |          } else { | 
                                                        
| 2178 | - $date = date_i18n( 'Y-m-d H:i:s', $end_time );  | 
                                                        |
| 2178 | +            $date = date_i18n('Y-m-d H:i:s', $end_time); | 
                                                        |
| 2179 | 2179 | }  | 
                                                        
| 2180 | 2180 | |
| 2181 | 2181 | return $date;  | 
                                                        
| 2182 | 2182 | }  | 
                                                        
| 2183 | 2183 | |
| 2184 | 2184 |      public function get_expiration_time() { | 
                                                        
| 2185 | - return strtotime( $this->get_expiration(), current_time( 'timestamp' ) );  | 
                                                        |
| 2185 | +        return strtotime($this->get_expiration(), current_time('timestamp')); | 
                                                        |
| 2186 | 2186 | }  | 
                                                        
| 2187 | 2187 | |
| 2188 | 2188 |      public function get_original_invoice_id() {         | 
                                                        
@@ -2194,125 +2194,125 @@ discard block  | 
                                                    ||
| 2194 | 2194 | return $subscription_data['bill_times'];  | 
                                                        
| 2195 | 2195 | }  | 
                                                        
| 2196 | 2196 | |
| 2197 | -    public function get_child_payments( $self = false ) { | 
                                                        |
| 2198 | - $invoices = get_posts( array(  | 
                                                        |
| 2197 | +    public function get_child_payments($self = false) { | 
                                                        |
| 2198 | + $invoices = get_posts(array(  | 
                                                        |
| 2199 | 2199 | 'post_type' => $this->post_type,  | 
                                                        
| 2200 | 2200 | 'post_parent' => (int)$this->ID,  | 
                                                        
| 2201 | 2201 | 'posts_per_page' => '999',  | 
                                                        
| 2202 | - 'post_status' => array( 'publish', 'wpi-processing', 'wpi-renewal' ),  | 
                                                        |
| 2202 | +            'post_status'       => array('publish', 'wpi-processing', 'wpi-renewal'), | 
                                                        |
| 2203 | 2203 | 'orderby' => 'ID',  | 
                                                        
| 2204 | 2204 | 'order' => 'DESC',  | 
                                                        
| 2205 | 2205 | 'fields' => 'ids'  | 
                                                        
| 2206 | - ) );  | 
                                                        |
| 2206 | + ));  | 
                                                        |
| 2207 | 2207 | |
| 2208 | -        if ( $this->is_free_trial() ) { | 
                                                        |
| 2208 | +        if ($this->is_free_trial()) { | 
                                                        |
| 2209 | 2209 | $self = false;  | 
                                                        
| 2210 | 2210 | }  | 
                                                        
| 2211 | 2211 | |
| 2212 | -        if ( $self && $this->is_paid() ) { | 
                                                        |
| 2213 | -            if ( !empty( $invoices ) ) { | 
                                                        |
| 2212 | +        if ($self && $this->is_paid()) { | 
                                                        |
| 2213 | +            if (!empty($invoices)) { | 
                                                        |
| 2214 | 2214 | $invoices[] = (int)$this->ID;  | 
                                                        
| 2215 | 2215 |              } else { | 
                                                        
| 2216 | - $invoices = array( $this->ID );  | 
                                                        |
| 2216 | + $invoices = array($this->ID);  | 
                                                        |
| 2217 | 2217 | }  | 
                                                        
| 2218 | 2218 | |
| 2219 | - $invoices = array_unique( $invoices );  | 
                                                        |
| 2219 | + $invoices = array_unique($invoices);  | 
                                                        |
| 2220 | 2220 | }  | 
                                                        
| 2221 | 2221 | |
| 2222 | 2222 | return $invoices;  | 
                                                        
| 2223 | 2223 | }  | 
                                                        
| 2224 | 2224 | |
| 2225 | -    public function get_total_payments( $self = true ) { | 
                                                        |
| 2226 | - return count( $this->get_child_payments( $self ) );  | 
                                                        |
| 2225 | +    public function get_total_payments($self = true) { | 
                                                        |
| 2226 | + return count($this->get_child_payments($self));  | 
                                                        |
| 2227 | 2227 | }  | 
                                                        
| 2228 | 2228 | |
| 2229 | -    public function get_subscriptions( $limit = -1 ) { | 
                                                        |
| 2230 | - $subscriptions = wpinv_get_subscriptions( array( 'parent_invoice_id' => $this->ID, 'numberposts' => $limit ) );  | 
                                                        |
| 2229 | +    public function get_subscriptions($limit = -1) { | 
                                                        |
| 2230 | +        $subscriptions = wpinv_get_subscriptions(array('parent_invoice_id' => $this->ID, 'numberposts' => $limit)); | 
                                                        |
| 2231 | 2231 | |
| 2232 | 2232 | return $subscriptions;  | 
                                                        
| 2233 | 2233 | }  | 
                                                        
| 2234 | 2234 | |
| 2235 | 2235 |      public function get_subscription_id() { | 
                                                        
| 2236 | - $subscription_id = $this->get_meta( '_wpinv_subscr_profile_id', true );  | 
                                                        |
| 2236 | +        $subscription_id = $this->get_meta('_wpinv_subscr_profile_id', true); | 
                                                        |
| 2237 | 2237 | |
| 2238 | -        if ( empty( $subscription_id ) && !empty( $this->parent_invoice ) ) { | 
                                                        |
| 2239 | - $parent_invoice = wpinv_get_invoice( $this->parent_invoice );  | 
                                                        |
| 2238 | +        if (empty($subscription_id) && !empty($this->parent_invoice)) { | 
                                                        |
| 2239 | + $parent_invoice = wpinv_get_invoice($this->parent_invoice);  | 
                                                        |
| 2240 | 2240 | |
| 2241 | - $subscription_id = $parent_invoice->get_meta( '_wpinv_subscr_profile_id', true );  | 
                                                        |
| 2241 | +            $subscription_id = $parent_invoice->get_meta('_wpinv_subscr_profile_id', true); | 
                                                        |
| 2242 | 2242 | }  | 
                                                        
| 2243 | 2243 | |
| 2244 | 2244 | return $subscription_id;  | 
                                                        
| 2245 | 2245 | }  | 
                                                        
| 2246 | 2246 | |
| 2247 | 2247 |      public function get_subscription_status() { | 
                                                        
| 2248 | - $subscription_status = $this->get_meta( '_wpinv_subscr_status', true );  | 
                                                        |
| 2248 | +        $subscription_status = $this->get_meta('_wpinv_subscr_status', true); | 
                                                        |
| 2249 | 2249 | |
| 2250 | -        if ( empty( $subscription_status ) ) { | 
                                                        |
| 2250 | +        if (empty($subscription_status)) { | 
                                                        |
| 2251 | 2251 | $status = 'pending';  | 
                                                        
| 2252 | 2252 | |
| 2253 | -            if ( $this->is_paid() ) {         | 
                                                        |
| 2253 | +            if ($this->is_paid()) {         | 
                                                        |
| 2254 | 2254 | $bill_times = (int)$this->get_bill_times();  | 
                                                        
| 2255 | 2255 | $times_billed = (int)$this->get_total_payments();  | 
                                                        
| 2256 | - $expiration = $this->get_subscription_end( false );  | 
                                                        |
| 2257 | - $expired = $bill_times != 0 && $expiration != '' && $expiration != '-' && strtotime( date_i18n( 'Y-m-d', strtotime( $expiration ) ) ) < strtotime( date_i18n( 'Y-m-d', current_time( 'timestamp' ) ) ) ? true : false;  | 
                                                        |
| 2256 | + $expiration = $this->get_subscription_end(false);  | 
                                                        |
| 2257 | +                $expired = $bill_times != 0 && $expiration != '' && $expiration != '-' && strtotime(date_i18n('Y-m-d', strtotime($expiration))) < strtotime(date_i18n('Y-m-d', current_time('timestamp'))) ? true : false; | 
                                                        |
| 2258 | 2258 | |
| 2259 | -                if ( (int)$bill_times == 0 ) { | 
                                                        |
| 2259 | +                if ((int)$bill_times == 0) { | 
                                                        |
| 2260 | 2260 | $status = $expired ? 'expired' : 'active';  | 
                                                        
| 2261 | -                } else if ( $bill_times > 0 && $times_billed >= $bill_times ) { | 
                                                        |
| 2261 | +                } else if ($bill_times > 0 && $times_billed >= $bill_times) { | 
                                                        |
| 2262 | 2262 | $status = 'completed';  | 
                                                        
| 2263 | -                } else if ( $expired ) { | 
                                                        |
| 2263 | +                } else if ($expired) { | 
                                                        |
| 2264 | 2264 | $status = 'expired';  | 
                                                        
| 2265 | -                } else if ( $bill_times > 0 ) { | 
                                                        |
| 2265 | +                } else if ($bill_times > 0) { | 
                                                        |
| 2266 | 2266 | $status = 'active';  | 
                                                        
| 2267 | 2267 |                  } else { | 
                                                        
| 2268 | 2268 | $status = 'pending';  | 
                                                        
| 2269 | 2269 | }  | 
                                                        
| 2270 | 2270 | }  | 
                                                        
| 2271 | 2271 | |
| 2272 | -            if ( $status && $status != $subscription_status ) { | 
                                                        |
| 2272 | +            if ($status && $status != $subscription_status) { | 
                                                        |
| 2273 | 2273 | $subscription_status = $status;  | 
                                                        
| 2274 | 2274 | |
| 2275 | - $this->update_meta( '_wpinv_subscr_status', $status );  | 
                                                        |
| 2275 | +                $this->update_meta('_wpinv_subscr_status', $status); | 
                                                        |
| 2276 | 2276 | }  | 
                                                        
| 2277 | 2277 | }  | 
                                                        
| 2278 | 2278 | |
| 2279 | 2279 | return $subscription_status;  | 
                                                        
| 2280 | 2280 | }  | 
                                                        
| 2281 | 2281 | |
| 2282 | -    public function get_subscription_status_label( $status = '' ) { | 
                                                        |
| 2283 | - $status = !empty( $status ) ? $status : $this->get_subscription_status();  | 
                                                        |
| 2282 | +    public function get_subscription_status_label($status = '') { | 
                                                        |
| 2283 | + $status = !empty($status) ? $status : $this->get_subscription_status();  | 
                                                        |
| 2284 | 2284 | |
| 2285 | -        switch( $status ) { | 
                                                        |
| 2285 | +        switch ($status) { | 
                                                        |
| 2286 | 2286 | case 'active' :  | 
                                                        
| 2287 | - $status_label = __( 'Active', 'invoicing' );  | 
                                                        |
| 2287 | +                $status_label = __('Active', 'invoicing'); | 
                                                        |
| 2288 | 2288 | break;  | 
                                                        
| 2289 | 2289 | |
| 2290 | 2290 | case 'cancelled' :  | 
                                                        
| 2291 | - $status_label = __( 'Cancelled', 'invoicing' );  | 
                                                        |
| 2291 | +                $status_label = __('Cancelled', 'invoicing'); | 
                                                        |
| 2292 | 2292 | break;  | 
                                                        
| 2293 | 2293 | |
| 2294 | 2294 | case 'completed' :  | 
                                                        
| 2295 | - $status_label = __( 'Completed', 'invoicing' );  | 
                                                        |
| 2295 | +                $status_label = __('Completed', 'invoicing'); | 
                                                        |
| 2296 | 2296 | break;  | 
                                                        
| 2297 | 2297 | |
| 2298 | 2298 | case 'expired' :  | 
                                                        
| 2299 | - $status_label = __( 'Expired', 'invoicing' );  | 
                                                        |
| 2299 | +                $status_label = __('Expired', 'invoicing'); | 
                                                        |
| 2300 | 2300 | break;  | 
                                                        
| 2301 | 2301 | |
| 2302 | 2302 | case 'pending' :  | 
                                                        
| 2303 | - $status_label = __( 'Pending', 'invoicing' );  | 
                                                        |
| 2303 | +                $status_label = __('Pending', 'invoicing'); | 
                                                        |
| 2304 | 2304 | break;  | 
                                                        
| 2305 | 2305 | |
| 2306 | 2306 | case 'failing' :  | 
                                                        
| 2307 | - $status_label = __( 'Failing', 'invoicing' );  | 
                                                        |
| 2307 | +                $status_label = __('Failing', 'invoicing'); | 
                                                        |
| 2308 | 2308 | break;  | 
                                                        
| 2309 | 2309 | |
| 2310 | 2310 | case 'stopped' :  | 
                                                        
| 2311 | - $status_label = __( 'Stopped', 'invoicing' );  | 
                                                        |
| 2311 | +                $status_label = __('Stopped', 'invoicing'); | 
                                                        |
| 2312 | 2312 | break;  | 
                                                        
| 2313 | 2313 | |
| 2314 | 2314 | case 'trialing' :  | 
                                                        
| 2315 | - $status_label = __( 'Trialing', 'invoicing' );  | 
                                                        |
| 2315 | +                $status_label = __('Trialing', 'invoicing'); | 
                                                        |
| 2316 | 2316 | break;  | 
                                                        
| 2317 | 2317 | |
| 2318 | 2318 | default:  | 
                                                        
@@ -2323,26 +2323,26 @@ discard block  | 
                                                    ||
| 2323 | 2323 | return $status_label;  | 
                                                        
| 2324 | 2324 | }  | 
                                                        
| 2325 | 2325 | |
| 2326 | -    public function get_subscription_period( $full = false ) { | 
                                                        |
| 2327 | - $period = $this->get_meta( '_wpinv_subscr_period', true );  | 
                                                        |
| 2326 | +    public function get_subscription_period($full = false) { | 
                                                        |
| 2327 | +        $period = $this->get_meta('_wpinv_subscr_period', true); | 
                                                        |
| 2328 | 2328 | |
| 2329 | 2329 | // Fix period for old invoices  | 
                                                        
| 2330 | -        if ( $period == 'day' ) { | 
                                                        |
| 2330 | +        if ($period == 'day') { | 
                                                        |
| 2331 | 2331 | $period = 'D';  | 
                                                        
| 2332 | -        } else if ( $period == 'week' ) { | 
                                                        |
| 2332 | +        } else if ($period == 'week') { | 
                                                        |
| 2333 | 2333 | $period = 'W';  | 
                                                        
| 2334 | -        } else if ( $period == 'month' ) { | 
                                                        |
| 2334 | +        } else if ($period == 'month') { | 
                                                        |
| 2335 | 2335 | $period = 'M';  | 
                                                        
| 2336 | -        } else if ( $period == 'year' ) { | 
                                                        |
| 2336 | +        } else if ($period == 'year') { | 
                                                        |
| 2337 | 2337 | $period = 'Y';  | 
                                                        
| 2338 | 2338 | }  | 
                                                        
| 2339 | 2339 | |
| 2340 | -        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) { | 
                                                        |
| 2340 | +        if (!in_array($period, array('D', 'W', 'M', 'Y'))) { | 
                                                        |
| 2341 | 2341 | $period = 'D';  | 
                                                        
| 2342 | 2342 | }  | 
                                                        
| 2343 | 2343 | |
| 2344 | -        if ( $full ) { | 
                                                        |
| 2345 | -            switch( $period ) { | 
                                                        |
| 2344 | +        if ($full) { | 
                                                        |
| 2345 | +            switch ($period) { | 
                                                        |
| 2346 | 2346 | case 'D':  | 
                                                        
| 2347 | 2347 | $period = 'day';  | 
                                                        
| 2348 | 2348 | break;  | 
                                                        
@@ -2362,39 +2362,39 @@ discard block  | 
                                                    ||
| 2362 | 2362 | }  | 
                                                        
| 2363 | 2363 | |
| 2364 | 2364 |      public function get_subscription_interval() { | 
                                                        
| 2365 | - $interval = (int)$this->get_meta( '_wpinv_subscr_interval', true );  | 
                                                        |
| 2365 | +        $interval = (int)$this->get_meta('_wpinv_subscr_interval', true); | 
                                                        |
| 2366 | 2366 | |
| 2367 | -        if ( !$interval > 0 ) { | 
                                                        |
| 2367 | +        if (!$interval > 0) { | 
                                                        |
| 2368 | 2368 | $interval = 1;  | 
                                                        
| 2369 | 2369 | }  | 
                                                        
| 2370 | 2370 | |
| 2371 | 2371 | return $interval;  | 
                                                        
| 2372 | 2372 | }  | 
                                                        
| 2373 | 2373 | |
| 2374 | -    public function get_subscription_trial_period( $full = false ) { | 
                                                        |
| 2375 | -        if ( !$this->is_free_trial() ) { | 
                                                        |
| 2374 | +    public function get_subscription_trial_period($full = false) { | 
                                                        |
| 2375 | +        if (!$this->is_free_trial()) { | 
                                                        |
| 2376 | 2376 | return '';  | 
                                                        
| 2377 | 2377 | }  | 
                                                        
| 2378 | 2378 | |
| 2379 | - $period = $this->get_meta( '_wpinv_subscr_trial_period', true );  | 
                                                        |
| 2379 | +        $period = $this->get_meta('_wpinv_subscr_trial_period', true); | 
                                                        |
| 2380 | 2380 | |
| 2381 | 2381 | // Fix period for old invoices  | 
                                                        
| 2382 | -        if ( $period == 'day' ) { | 
                                                        |
| 2382 | +        if ($period == 'day') { | 
                                                        |
| 2383 | 2383 | $period = 'D';  | 
                                                        
| 2384 | -        } else if ( $period == 'week' ) { | 
                                                        |
| 2384 | +        } else if ($period == 'week') { | 
                                                        |
| 2385 | 2385 | $period = 'W';  | 
                                                        
| 2386 | -        } else if ( $period == 'month' ) { | 
                                                        |
| 2386 | +        } else if ($period == 'month') { | 
                                                        |
| 2387 | 2387 | $period = 'M';  | 
                                                        
| 2388 | -        } else if ( $period == 'year' ) { | 
                                                        |
| 2388 | +        } else if ($period == 'year') { | 
                                                        |
| 2389 | 2389 | $period = 'Y';  | 
                                                        
| 2390 | 2390 | }  | 
                                                        
| 2391 | 2391 | |
| 2392 | -        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) { | 
                                                        |
| 2392 | +        if (!in_array($period, array('D', 'W', 'M', 'Y'))) { | 
                                                        |
| 2393 | 2393 | $period = 'D';  | 
                                                        
| 2394 | 2394 | }  | 
                                                        
| 2395 | 2395 | |
| 2396 | -        if ( $full ) { | 
                                                        |
| 2397 | -            switch( $period ) { | 
                                                        |
| 2396 | +        if ($full) { | 
                                                        |
| 2397 | +            switch ($period) { | 
                                                        |
| 2398 | 2398 | case 'D':  | 
                                                        
| 2399 | 2399 | $period = 'day';  | 
                                                        
| 2400 | 2400 | break;  | 
                                                        
@@ -2414,13 +2414,13 @@ discard block  | 
                                                    ||
| 2414 | 2414 | }  | 
                                                        
| 2415 | 2415 | |
| 2416 | 2416 |      public function get_subscription_trial_interval() { | 
                                                        
| 2417 | -        if ( !$this->is_free_trial() ) { | 
                                                        |
| 2417 | +        if (!$this->is_free_trial()) { | 
                                                        |
| 2418 | 2418 | return 0;  | 
                                                        
| 2419 | 2419 | }  | 
                                                        
| 2420 | 2420 | |
| 2421 | - $interval = (int)$this->get_meta( '_wpinv_subscr_trial_interval', true );  | 
                                                        |
| 2421 | +        $interval = (int)$this->get_meta('_wpinv_subscr_trial_interval', true); | 
                                                        |
| 2422 | 2422 | |
| 2423 | -        if ( !$interval > 0 ) { | 
                                                        |
| 2423 | +        if (!$interval > 0) { | 
                                                        |
| 2424 | 2424 | $interval = 1;  | 
                                                        
| 2425 | 2425 | }  | 
                                                        
| 2426 | 2426 | |
@@ -2432,8 +2432,8 @@ discard block  | 
                                                    ||
| 2432 | 2432 | 'status' => 'failing'  | 
                                                        
| 2433 | 2433 | );  | 
                                                        
| 2434 | 2434 | |
| 2435 | -        if ( $this->update_subscription( $args ) ) { | 
                                                        |
| 2436 | - do_action( 'wpinv_subscription_failing', $this->ID, $this );  | 
                                                        |
| 2435 | +        if ($this->update_subscription($args)) { | 
                                                        |
| 2436 | +            do_action('wpinv_subscription_failing', $this->ID, $this); | 
                                                        |
| 2437 | 2437 | return true;  | 
                                                        
| 2438 | 2438 | }  | 
                                                        
| 2439 | 2439 | |
@@ -2445,8 +2445,8 @@ discard block  | 
                                                    ||
| 2445 | 2445 | 'status' => 'stopped'  | 
                                                        
| 2446 | 2446 | );  | 
                                                        
| 2447 | 2447 | |
| 2448 | -        if ( $this->update_subscription( $args ) ) { | 
                                                        |
| 2449 | - do_action( 'wpinv_subscription_stopped', $this->ID, $this );  | 
                                                        |
| 2448 | +        if ($this->update_subscription($args)) { | 
                                                        |
| 2449 | +            do_action('wpinv_subscription_stopped', $this->ID, $this); | 
                                                        |
| 2450 | 2450 | return true;  | 
                                                        
| 2451 | 2451 | }  | 
                                                        
| 2452 | 2452 | |
@@ -2458,8 +2458,8 @@ discard block  | 
                                                    ||
| 2458 | 2458 | 'status' => 'active'  | 
                                                        
| 2459 | 2459 | );  | 
                                                        
| 2460 | 2460 | |
| 2461 | -        if ( $this->update_subscription( $args ) ) { | 
                                                        |
| 2462 | - do_action( 'wpinv_subscription_restarted', $this->ID, $this );  | 
                                                        |
| 2461 | +        if ($this->update_subscription($args)) { | 
                                                        |
| 2462 | +            do_action('wpinv_subscription_restarted', $this->ID, $this); | 
                                                        |
| 2463 | 2463 | return true;  | 
                                                        
| 2464 | 2464 | }  | 
                                                        
| 2465 | 2465 | |
@@ -2471,23 +2471,23 @@ discard block  | 
                                                    ||
| 2471 | 2471 | 'status' => 'cancelled'  | 
                                                        
| 2472 | 2472 | );  | 
                                                        
| 2473 | 2473 | |
| 2474 | -        if ( $this->update_subscription( $args ) ) { | 
                                                        |
| 2475 | -            if ( is_user_logged_in() ) { | 
                                                        |
| 2476 | - $userdata = get_userdata( get_current_user_id() );  | 
                                                        |
| 2474 | +        if ($this->update_subscription($args)) { | 
                                                        |
| 2475 | +            if (is_user_logged_in()) { | 
                                                        |
| 2476 | + $userdata = get_userdata(get_current_user_id());  | 
                                                        |
| 2477 | 2477 | $user = $userdata->user_login;  | 
                                                        
| 2478 | 2478 |              } else { | 
                                                        
| 2479 | - $user = __( 'gateway', 'invoicing' );  | 
                                                        |
| 2479 | +                $user = __('gateway', 'invoicing'); | 
                                                        |
| 2480 | 2480 | }  | 
                                                        
| 2481 | 2481 | |
| 2482 | 2482 | $subscription_id = $this->get_subscription_id();  | 
                                                        
| 2483 | -            if ( !$subscription_id ) { | 
                                                        |
| 2483 | +            if (!$subscription_id) { | 
                                                        |
| 2484 | 2484 | $subscription_id = $this->ID;  | 
                                                        
| 2485 | 2485 | }  | 
                                                        
| 2486 | 2486 | |
| 2487 | - $note = sprintf( __( 'Subscription %s has been cancelled by %s', 'invoicing' ), $subscription_id, $user );  | 
                                                        |
| 2488 | - $this->add_note( $note );  | 
                                                        |
| 2487 | +            $note = sprintf(__('Subscription %s has been cancelled by %s', 'invoicing'), $subscription_id, $user); | 
                                                        |
| 2488 | + $this->add_note($note);  | 
                                                        |
| 2489 | 2489 | |
| 2490 | - do_action( 'wpinv_subscription_cancelled', $this->ID, $this );  | 
                                                        |
| 2490 | +            do_action('wpinv_subscription_cancelled', $this->ID, $this); | 
                                                        |
| 2491 | 2491 | return true;  | 
                                                        
| 2492 | 2492 | }  | 
                                                        
| 2493 | 2493 | |
@@ -2495,11 +2495,11 @@ discard block  | 
                                                    ||
| 2495 | 2495 | }  | 
                                                        
| 2496 | 2496 | |
| 2497 | 2497 |      public function can_cancel() { | 
                                                        
| 2498 | - return apply_filters( 'wpinv_subscription_can_cancel', false, $this );  | 
                                                        |
| 2498 | +        return apply_filters('wpinv_subscription_can_cancel', false, $this); | 
                                                        |
| 2499 | 2499 | }  | 
                                                        
| 2500 | 2500 | |
| 2501 | -    public function add_subscription( $data = array() ) { | 
                                                        |
| 2502 | -        if ( empty( $this->ID ) ) { | 
                                                        |
| 2501 | +    public function add_subscription($data = array()) { | 
                                                        |
| 2502 | +        if (empty($this->ID)) { | 
                                                        |
| 2503 | 2503 | return false;  | 
                                                        
| 2504 | 2504 | }  | 
                                                        
| 2505 | 2505 | |
@@ -2518,85 +2518,85 @@ discard block  | 
                                                    ||
| 2518 | 2518 | 'profile_id' => '',  | 
                                                        
| 2519 | 2519 | );  | 
                                                        
| 2520 | 2520 | |
| 2521 | - $args = wp_parse_args( $data, $defaults );  | 
                                                        |
| 2521 | + $args = wp_parse_args($data, $defaults);  | 
                                                        |
| 2522 | 2522 | |
| 2523 | -        if ( $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) { | 
                                                        |
| 2524 | -            if ( 'active' == $args['status'] || $args['status'] == 'trialing' ) { | 
                                                        |
| 2523 | +        if ($args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) { | 
                                                        |
| 2524 | +            if ('active' == $args['status'] || $args['status'] == 'trialing') { | 
                                                        |
| 2525 | 2525 | $args['status'] = 'expired';  | 
                                                        
| 2526 | 2526 | }  | 
                                                        
| 2527 | 2527 | }  | 
                                                        
| 2528 | 2528 | |
| 2529 | - do_action( 'wpinv_subscription_pre_create', $args, $data, $this );  | 
                                                        |
| 2529 | +        do_action('wpinv_subscription_pre_create', $args, $data, $this); | 
                                                        |
| 2530 | 2530 | |
| 2531 | -        if ( !empty( $args ) ) { | 
                                                        |
| 2532 | -            foreach ( $args as $key => $value ) { | 
                                                        |
| 2533 | - $this->update_meta( '_wpinv_subscr_' . $key, $value );  | 
                                                        |
| 2531 | +        if (!empty($args)) { | 
                                                        |
| 2532 | +            foreach ($args as $key => $value) { | 
                                                        |
| 2533 | +                $this->update_meta('_wpinv_subscr_' . $key, $value); | 
                                                        |
| 2534 | 2534 | }  | 
                                                        
| 2535 | 2535 | }  | 
                                                        
| 2536 | 2536 | |
| 2537 | - do_action( 'wpinv_subscription_post_create', $args, $data, $this );  | 
                                                        |
| 2537 | +        do_action('wpinv_subscription_post_create', $args, $data, $this); | 
                                                        |
| 2538 | 2538 | |
| 2539 | 2539 | return true;  | 
                                                        
| 2540 | 2540 | }  | 
                                                        
| 2541 | 2541 | |
| 2542 | -    public function update_subscription( $args = array() ) { | 
                                                        |
| 2543 | -        if ( empty( $this->ID ) ) { | 
                                                        |
| 2542 | +    public function update_subscription($args = array()) { | 
                                                        |
| 2543 | +        if (empty($this->ID)) { | 
                                                        |
| 2544 | 2544 | return false;  | 
                                                        
| 2545 | 2545 | }  | 
                                                        
| 2546 | 2546 | |
| 2547 | -        if ( !empty( $args['expiration'] ) && $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) { | 
                                                        |
| 2548 | -            if ( !isset( $args['status'] ) || ( isset( $args['status'] ) && ( 'active' == $args['status'] || $args['status'] == 'trialing' ) ) ) { | 
                                                        |
| 2547 | +        if (!empty($args['expiration']) && $args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) { | 
                                                        |
| 2548 | +            if (!isset($args['status']) || (isset($args['status']) && ('active' == $args['status'] || $args['status'] == 'trialing'))) { | 
                                                        |
| 2549 | 2549 | $args['status'] = 'expired';  | 
                                                        
| 2550 | 2550 | }  | 
                                                        
| 2551 | 2551 | }  | 
                                                        
| 2552 | 2552 | |
| 2553 | -        if ( isset( $args['status'] ) && $args['status'] == 'cancelled' && empty( $args['cancelled_on'] ) ) { | 
                                                        |
| 2554 | - $args['cancelled_on'] = date_i18n( 'Y-m-d H:i:s', current_time( 'timestamp' ) );  | 
                                                        |
| 2553 | +        if (isset($args['status']) && $args['status'] == 'cancelled' && empty($args['cancelled_on'])) { | 
                                                        |
| 2554 | +            $args['cancelled_on'] = date_i18n('Y-m-d H:i:s', current_time('timestamp')); | 
                                                        |
| 2555 | 2555 | }  | 
                                                        
| 2556 | 2556 | |
| 2557 | - do_action( 'wpinv_subscription_pre_update', $args, $this );  | 
                                                        |
| 2557 | +        do_action('wpinv_subscription_pre_update', $args, $this); | 
                                                        |
| 2558 | 2558 | |
| 2559 | -        if ( !empty( $args ) ) { | 
                                                        |
| 2560 | -            foreach ( $args as $key => $value ) { | 
                                                        |
| 2561 | - $this->update_meta( '_wpinv_subscr_' . $key, $value );  | 
                                                        |
| 2559 | +        if (!empty($args)) { | 
                                                        |
| 2560 | +            foreach ($args as $key => $value) { | 
                                                        |
| 2561 | +                $this->update_meta('_wpinv_subscr_' . $key, $value); | 
                                                        |
| 2562 | 2562 | }  | 
                                                        
| 2563 | 2563 | }  | 
                                                        
| 2564 | 2564 | |
| 2565 | - do_action( 'wpinv_subscription_post_update', $args, $this );  | 
                                                        |
| 2565 | +        do_action('wpinv_subscription_post_update', $args, $this); | 
                                                        |
| 2566 | 2566 | |
| 2567 | 2567 | return true;  | 
                                                        
| 2568 | 2568 | }  | 
                                                        
| 2569 | 2569 | |
| 2570 | 2570 |      public function renew_subscription() { | 
                                                        
| 2571 | 2571 | $parent_invoice = $this->get_parent_payment();  | 
                                                        
| 2572 | - $parent_invoice = empty( $parent_invoice ) ? $this : $parent_invoice;  | 
                                                        |
| 2572 | + $parent_invoice = empty($parent_invoice) ? $this : $parent_invoice;  | 
                                                        |
| 2573 | 2573 | |
| 2574 | - $current_time = current_time( 'timestamp' );  | 
                                                        |
| 2574 | +        $current_time   = current_time('timestamp'); | 
                                                        |
| 2575 | 2575 | $start = $this->get_subscription_created();  | 
                                                        
| 2576 | - $start = $start ? strtotime( $start ) : $current_time;  | 
                                                        |
| 2576 | + $start = $start ? strtotime($start) : $current_time;  | 
                                                        |
| 2577 | 2577 | $expires = $this->get_expiration_time();  | 
                                                        
| 2578 | 2578 | |
| 2579 | -        if ( !$expires ) { | 
                                                        |
| 2580 | - $expires = strtotime( '+' . $parent_invoice->get_subscription_interval() . ' ' . $parent_invoice->get_subscription_period( true ), $start );  | 
                                                        |
| 2579 | +        if (!$expires) { | 
                                                        |
| 2580 | +            $expires    = strtotime('+' . $parent_invoice->get_subscription_interval() . ' ' . $parent_invoice->get_subscription_period(true), $start); | 
                                                        |
| 2581 | 2581 | }  | 
                                                        
| 2582 | 2582 | |
| 2583 | - $expiration = date_i18n( 'Y-m-d 23:59:59', $expires );  | 
                                                        |
| 2584 | - $expiration = apply_filters( 'wpinv_subscription_renewal_expiration', $expiration, $this->ID, $this );  | 
                                                        |
| 2583 | +        $expiration     = date_i18n('Y-m-d 23:59:59', $expires); | 
                                                        |
| 2584 | +        $expiration     = apply_filters('wpinv_subscription_renewal_expiration', $expiration, $this->ID, $this); | 
                                                        |
| 2585 | 2585 | $bill_times = $parent_invoice->get_bill_times();  | 
                                                        
| 2586 | 2586 | $times_billed = $parent_invoice->get_total_payments();  | 
                                                        
| 2587 | 2587 | |
| 2588 | -        if ( $parent_invoice->get_subscription_status() == 'trialing' && ( $times_billed > 0 || strtotime( date_i18n( 'Y-m-d' ) ) < strtotime( $parent_invoice->get_trial_end_date( false ) ) ) ) { | 
                                                        |
| 2588 | +        if ($parent_invoice->get_subscription_status() == 'trialing' && ($times_billed > 0 || strtotime(date_i18n('Y-m-d')) < strtotime($parent_invoice->get_trial_end_date(false)))) { | 
                                                        |
| 2589 | 2589 | $args = array(  | 
                                                        
| 2590 | 2590 | 'status' => 'active',  | 
                                                        
| 2591 | 2591 | );  | 
                                                        
| 2592 | 2592 | |
| 2593 | - $parent_invoice->update_subscription( $args );  | 
                                                        |
| 2593 | + $parent_invoice->update_subscription($args);  | 
                                                        |
| 2594 | 2594 | }  | 
                                                        
| 2595 | 2595 | |
| 2596 | - do_action( 'wpinv_subscription_pre_renew', $this->ID, $expiration, $this );  | 
                                                        |
| 2596 | +        do_action('wpinv_subscription_pre_renew', $this->ID, $expiration, $this); | 
                                                        |
| 2597 | 2597 | |
| 2598 | - $status = 'active';  | 
                                                        |
| 2599 | -        if ( $bill_times > 0 && $times_billed >= $bill_times ) { | 
                                                        |
| 2598 | + $status = 'active';  | 
                                                        |
| 2599 | +        if ($bill_times > 0 && $times_billed >= $bill_times) { | 
                                                        |
| 2600 | 2600 | $this->complete_subscription();  | 
                                                        
| 2601 | 2601 | $status = 'completed';  | 
                                                        
| 2602 | 2602 | }  | 
                                                        
@@ -2606,10 +2606,10 @@ discard block  | 
                                                    ||
| 2606 | 2606 | 'status' => $status,  | 
                                                        
| 2607 | 2607 | );  | 
                                                        
| 2608 | 2608 | |
| 2609 | - $this->update_subscription( $args );  | 
                                                        |
| 2609 | + $this->update_subscription($args);  | 
                                                        |
| 2610 | 2610 | |
| 2611 | - do_action( 'wpinv_subscription_post_renew', $this->ID, $expiration, $this );  | 
                                                        |
| 2612 | - do_action( 'wpinv_recurring_set_subscription_status', $this->ID, $status, $this );  | 
                                                        |
| 2611 | +        do_action('wpinv_subscription_post_renew', $this->ID, $expiration, $this); | 
                                                        |
| 2612 | +        do_action('wpinv_recurring_set_subscription_status', $this->ID, $status, $this); | 
                                                        |
| 2613 | 2613 | }  | 
                                                        
| 2614 | 2614 | |
| 2615 | 2615 |      public function complete_subscription() { | 
                                                        
@@ -2617,8 +2617,8 @@ discard block  | 
                                                    ||
| 2617 | 2617 | 'status' => 'completed'  | 
                                                        
| 2618 | 2618 | );  | 
                                                        
| 2619 | 2619 | |
| 2620 | -        if ( $this->update_subscription( $args ) ) { | 
                                                        |
| 2621 | - do_action( 'wpinv_subscription_completed', $this->ID, $this );  | 
                                                        |
| 2620 | +        if ($this->update_subscription($args)) { | 
                                                        |
| 2621 | +            do_action('wpinv_subscription_completed', $this->ID, $this); | 
                                                        |
| 2622 | 2622 | }  | 
                                                        
| 2623 | 2623 | }  | 
                                                        
| 2624 | 2624 | |
@@ -2627,44 +2627,44 @@ discard block  | 
                                                    ||
| 2627 | 2627 | 'status' => 'expired'  | 
                                                        
| 2628 | 2628 | );  | 
                                                        
| 2629 | 2629 | |
| 2630 | -        if ( $this->update_subscription( $args ) ) { | 
                                                        |
| 2631 | - do_action( 'wpinv_subscription_expired', $this->ID, $this );  | 
                                                        |
| 2630 | +        if ($this->update_subscription($args)) { | 
                                                        |
| 2631 | +            do_action('wpinv_subscription_expired', $this->ID, $this); | 
                                                        |
| 2632 | 2632 | }  | 
                                                        
| 2633 | 2633 | }  | 
                                                        
| 2634 | 2634 | |
| 2635 | 2635 |      public function get_cancel_url() { | 
                                                        
| 2636 | - $url = wp_nonce_url( add_query_arg( array( 'wpi_action' => 'cancel_subscription', 'sub_id' => $this->ID ) ), 'wpinv-recurring-cancel' );  | 
                                                        |
| 2636 | +        $url = wp_nonce_url(add_query_arg(array('wpi_action' => 'cancel_subscription', 'sub_id' => $this->ID)), 'wpinv-recurring-cancel'); | 
                                                        |
| 2637 | 2637 | |
| 2638 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );  | 
                                                        |
| 2638 | +        return apply_filters('wpinv_subscription_cancel_url', $url, $this); | 
                                                        |
| 2639 | 2639 | }  | 
                                                        
| 2640 | 2640 | |
| 2641 | 2641 |      public function can_update() { | 
                                                        
| 2642 | - return apply_filters( 'wpinv_subscription_can_update', false, $this );  | 
                                                        |
| 2642 | +        return apply_filters('wpinv_subscription_can_update', false, $this); | 
                                                        |
| 2643 | 2643 | }  | 
                                                        
| 2644 | 2644 | |
| 2645 | 2645 |      public function get_update_url() { | 
                                                        
| 2646 | - $url = add_query_arg( array( 'action' => 'update', 'sub_id' => $this->ID ) );  | 
                                                        |
| 2646 | +        $url = add_query_arg(array('action' => 'update', 'sub_id' => $this->ID)); | 
                                                        |
| 2647 | 2647 | |
| 2648 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this );  | 
                                                        |
| 2648 | +        return apply_filters('wpinv_subscription_update_url', $url, $this); | 
                                                        |
| 2649 | 2649 | }  | 
                                                        
| 2650 | 2650 | |
| 2651 | 2651 |      public function is_parent() { | 
                                                        
| 2652 | - $is_parent = empty( $this->parent_invoice ) ? true : false;  | 
                                                        |
| 2652 | + $is_parent = empty($this->parent_invoice) ? true : false;  | 
                                                        |
| 2653 | 2653 | |
| 2654 | - return apply_filters( 'wpinv_invoice_is_parent', $is_parent, $this );  | 
                                                        |
| 2654 | +        return apply_filters('wpinv_invoice_is_parent', $is_parent, $this); | 
                                                        |
| 2655 | 2655 | }  | 
                                                        
| 2656 | 2656 | |
| 2657 | 2657 |      public function is_renewal() { | 
                                                        
| 2658 | 2658 | $is_renewal = $this->parent_invoice && $this->parent_invoice != $this->ID ? true : false;  | 
                                                        
| 2659 | 2659 | |
| 2660 | - return apply_filters( 'wpinv_invoice_is_renewal', $is_renewal, $this );  | 
                                                        |
| 2660 | +        return apply_filters('wpinv_invoice_is_renewal', $is_renewal, $this); | 
                                                        |
| 2661 | 2661 | }  | 
                                                        
| 2662 | 2662 | |
| 2663 | 2663 |      public function get_parent_payment() { | 
                                                        
| 2664 | 2664 | $parent_payment = NULL;  | 
                                                        
| 2665 | 2665 | |
| 2666 | -        if ( $this->is_renewal() ) { | 
                                                        |
| 2667 | - $parent_payment = wpinv_get_invoice( $this->parent_invoice );  | 
                                                        |
| 2666 | +        if ($this->is_renewal()) { | 
                                                        |
| 2667 | + $parent_payment = wpinv_get_invoice($this->parent_invoice);  | 
                                                        |
| 2668 | 2668 | }  | 
                                                        
| 2669 | 2669 | |
| 2670 | 2670 | return $parent_payment;  | 
                                                        
@@ -2675,100 +2675,100 @@ discard block  | 
                                                    ||
| 2675 | 2675 | |
| 2676 | 2676 | $subscription_status = $this->get_subscription_status();  | 
                                                        
| 2677 | 2677 | |
| 2678 | -        if( ! $this->is_subscription_expired() && ( $subscription_status == 'active' || $subscription_status == 'cancelled' || $subscription_status == 'trialing' ) ) { | 
                                                        |
| 2678 | +        if (!$this->is_subscription_expired() && ($subscription_status == 'active' || $subscription_status == 'cancelled' || $subscription_status == 'trialing')) { | 
                                                        |
| 2679 | 2679 | $ret = true;  | 
                                                        
| 2680 | 2680 | }  | 
                                                        
| 2681 | 2681 | |
| 2682 | - return apply_filters( 'wpinv_subscription_is_active', $ret, $this->ID, $this );  | 
                                                        |
| 2682 | +        return apply_filters('wpinv_subscription_is_active', $ret, $this->ID, $this); | 
                                                        |
| 2683 | 2683 | }  | 
                                                        
| 2684 | 2684 | |
| 2685 | 2685 |      public function is_subscription_expired() { | 
                                                        
| 2686 | 2686 | $ret = false;  | 
                                                        
| 2687 | 2687 | $subscription_status = $this->get_subscription_status();  | 
                                                        
| 2688 | 2688 | |
| 2689 | -        if ( $subscription_status == 'expired' ) { | 
                                                        |
| 2689 | +        if ($subscription_status == 'expired') { | 
                                                        |
| 2690 | 2690 | $ret = true;  | 
                                                        
| 2691 | -        } else if ( 'active' === $subscription_status || 'cancelled' === $subscription_status || 'trialing' == $subscription_status ) { | 
                                                        |
| 2691 | +        } else if ('active' === $subscription_status || 'cancelled' === $subscription_status || 'trialing' == $subscription_status) { | 
                                                        |
| 2692 | 2692 | $ret = false;  | 
                                                        
| 2693 | 2693 | $expiration = $this->get_expiration_time();  | 
                                                        
| 2694 | 2694 | |
| 2695 | -            if ( $expiration && strtotime( 'NOW', current_time( 'timestamp' ) ) > $expiration ) { | 
                                                        |
| 2695 | +            if ($expiration && strtotime('NOW', current_time('timestamp')) > $expiration) { | 
                                                        |
| 2696 | 2696 | $ret = true;  | 
                                                        
| 2697 | 2697 | |
| 2698 | -                if ( 'active' === $subscription_status || 'trialing' === $subscription_status ) { | 
                                                        |
| 2698 | +                if ('active' === $subscription_status || 'trialing' === $subscription_status) { | 
                                                        |
| 2699 | 2699 | $this->expire_subscription();  | 
                                                        
| 2700 | 2700 | }  | 
                                                        
| 2701 | 2701 | }  | 
                                                        
| 2702 | 2702 | }  | 
                                                        
| 2703 | 2703 | |
| 2704 | - return apply_filters( 'wpinv_subscription_is_expired', $ret, $this->ID, $this );  | 
                                                        |
| 2704 | +        return apply_filters('wpinv_subscription_is_expired', $ret, $this->ID, $this); | 
                                                        |
| 2705 | 2705 | }  | 
                                                        
| 2706 | 2706 | |
| 2707 | -    public function get_new_expiration( $item_id = 0, $trial = true ) { | 
                                                        |
| 2708 | - $item = new WPInv_Item( $item_id );  | 
                                                        |
| 2707 | +    public function get_new_expiration($item_id = 0, $trial = true) { | 
                                                        |
| 2708 | + $item = new WPInv_Item($item_id);  | 
                                                        |
| 2709 | 2709 | $interval = $item->get_recurring_interval();  | 
                                                        
| 2710 | - $period = $item->get_recurring_period( true );  | 
                                                        |
| 2710 | + $period = $item->get_recurring_period(true);  | 
                                                        |
| 2711 | 2711 | |
| 2712 | - $expiration_time = strtotime( '+' . $interval . ' ' . $period );  | 
                                                        |
| 2712 | +        $expiration_time = strtotime('+' . $interval . ' ' . $period); | 
                                                        |
| 2713 | 2713 | |
| 2714 | -        if ( $trial && $this->is_free_trial() && $item->has_free_trial() ) { | 
                                                        |
| 2715 | - $expiration_time += ( wpinv_period_in_days( $item->get_trial_interval(), $item->get_trial_period() ) * DAY_IN_SECONDS ) ;  | 
                                                        |
| 2714 | +        if ($trial && $this->is_free_trial() && $item->has_free_trial()) { | 
                                                        |
| 2715 | + $expiration_time += (wpinv_period_in_days($item->get_trial_interval(), $item->get_trial_period()) * DAY_IN_SECONDS);  | 
                                                        |
| 2716 | 2716 | }  | 
                                                        
| 2717 | 2717 | |
| 2718 | - return date_i18n( 'Y-m-d 23:59:59', $expiration_time );  | 
                                                        |
| 2718 | +        return date_i18n('Y-m-d 23:59:59', $expiration_time); | 
                                                        |
| 2719 | 2719 | }  | 
                                                        
| 2720 | 2720 | |
| 2721 | -    public function get_subscription_data( $filed = '' ) { | 
                                                        |
| 2722 | - $fields = array( 'item_id', 'status', 'period', 'initial_amount', 'recurring_amount', 'interval', 'bill_times', 'trial_period', 'trial_interval', 'expiration', 'profile_id', 'created', 'cancelled_on' );  | 
                                                        |
| 2721 | +    public function get_subscription_data($filed = '') { | 
                                                        |
| 2722 | +        $fields = array('item_id', 'status', 'period', 'initial_amount', 'recurring_amount', 'interval', 'bill_times', 'trial_period', 'trial_interval', 'expiration', 'profile_id', 'created', 'cancelled_on'); | 
                                                        |
| 2723 | 2723 | |
| 2724 | 2724 | $subscription_meta = array();  | 
                                                        
| 2725 | -        foreach ( $fields as $field ) { | 
                                                        |
| 2726 | - $subscription_meta[ $field ] = $this->get_meta( '_wpinv_subscr_' . $field );  | 
                                                        |
| 2725 | +        foreach ($fields as $field) { | 
                                                        |
| 2726 | +            $subscription_meta[$field] = $this->get_meta('_wpinv_subscr_' . $field); | 
                                                        |
| 2727 | 2727 | }  | 
                                                        
| 2728 | 2728 | |
| 2729 | - $item = $this->get_recurring( true );  | 
                                                        |
| 2729 | + $item = $this->get_recurring(true);  | 
                                                        |
| 2730 | 2730 | |
| 2731 | -        if ( !empty( $item ) ) { | 
                                                        |
| 2732 | -            if ( empty( $subscription_meta['item_id'] ) ) { | 
                                                        |
| 2731 | +        if (!empty($item)) { | 
                                                        |
| 2732 | +            if (empty($subscription_meta['item_id'])) { | 
                                                        |
| 2733 | 2733 | $subscription_meta['item_id'] = $item->ID;  | 
                                                        
| 2734 | 2734 | }  | 
                                                        
| 2735 | -            if ( empty( $subscription_meta['period'] ) ) { | 
                                                        |
| 2735 | +            if (empty($subscription_meta['period'])) { | 
                                                        |
| 2736 | 2736 | $subscription_meta['period'] = $item->get_recurring_period();  | 
                                                        
| 2737 | 2737 | }  | 
                                                        
| 2738 | -            if ( empty( $subscription_meta['interval'] ) ) { | 
                                                        |
| 2738 | +            if (empty($subscription_meta['interval'])) { | 
                                                        |
| 2739 | 2739 | $subscription_meta['interval'] = $item->get_recurring_interval();  | 
                                                        
| 2740 | 2740 | }  | 
                                                        
| 2741 | -            if ( $item->has_free_trial() ) { | 
                                                        |
| 2742 | -                if ( empty( $subscription_meta['trial_period'] ) ) { | 
                                                        |
| 2741 | +            if ($item->has_free_trial()) { | 
                                                        |
| 2742 | +                if (empty($subscription_meta['trial_period'])) { | 
                                                        |
| 2743 | 2743 | $subscription_meta['trial_period'] = $item->get_trial_period();  | 
                                                        
| 2744 | 2744 | }  | 
                                                        
| 2745 | -                if ( empty( $subscription_meta['trial_interval'] ) ) { | 
                                                        |
| 2745 | +                if (empty($subscription_meta['trial_interval'])) { | 
                                                        |
| 2746 | 2746 | $subscription_meta['trial_interval'] = $item->get_trial_interval();  | 
                                                        
| 2747 | 2747 | }  | 
                                                        
| 2748 | 2748 |              } else { | 
                                                        
| 2749 | 2749 | $subscription_meta['trial_period'] = '';  | 
                                                        
| 2750 | 2750 | $subscription_meta['trial_interval'] = 0;  | 
                                                        
| 2751 | 2751 | }  | 
                                                        
| 2752 | -            if ( !$subscription_meta['bill_times'] && $subscription_meta['bill_times'] !== 0 ) { | 
                                                        |
| 2752 | +            if (!$subscription_meta['bill_times'] && $subscription_meta['bill_times'] !== 0) { | 
                                                        |
| 2753 | 2753 | $subscription_meta['bill_times'] = $item->get_recurring_limit();  | 
                                                        
| 2754 | 2754 | }  | 
                                                        
| 2755 | -            if ( $subscription_meta['initial_amount'] === '' || $subscription_meta['recurring_amount'] === '' ) { | 
                                                        |
| 2756 | - $subscription_meta['initial_amount'] = wpinv_round_amount( $this->get_total() );  | 
                                                        |
| 2757 | - $subscription_meta['recurring_amount'] = wpinv_round_amount( $this->get_recurring_details( 'total' ) );  | 
                                                        |
| 2755 | +            if ($subscription_meta['initial_amount'] === '' || $subscription_meta['recurring_amount'] === '') { | 
                                                        |
| 2756 | + $subscription_meta['initial_amount'] = wpinv_round_amount($this->get_total());  | 
                                                        |
| 2757 | +                $subscription_meta['recurring_amount']  = wpinv_round_amount($this->get_recurring_details('total')); | 
                                                        |
| 2758 | 2758 | }  | 
                                                        
| 2759 | 2759 | }  | 
                                                        
| 2760 | 2760 | |
| 2761 | -        if ( $filed === '' ) { | 
                                                        |
| 2762 | - return apply_filters( 'wpinv_get_invoice_subscription_data', $subscription_meta, $this );  | 
                                                        |
| 2761 | +        if ($filed === '') { | 
                                                        |
| 2762 | +            return apply_filters('wpinv_get_invoice_subscription_data', $subscription_meta, $this); | 
                                                        |
| 2763 | 2763 | }  | 
                                                        
| 2764 | 2764 | |
| 2765 | - $value = isset( $subscription_meta[$filed] ) ? $subscription_meta[$filed] : '';  | 
                                                        |
| 2765 | + $value = isset($subscription_meta[$filed]) ? $subscription_meta[$filed] : '';  | 
                                                        |
| 2766 | 2766 | |
| 2767 | - return apply_filters( 'wpinv_invoice_subscription_data_value', $value, $subscription_meta, $this );  | 
                                                        |
| 2767 | +        return apply_filters('wpinv_invoice_subscription_data_value', $value, $subscription_meta, $this); | 
                                                        |
| 2768 | 2768 | }  | 
                                                        
| 2769 | 2769 | |
| 2770 | 2770 |      public function is_paid() { | 
                                                        
| 2771 | -        if ( $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) ) ) { | 
                                                        |
| 2771 | +        if ($this->has_status(array('publish', 'wpi-processing', 'wpi-renewal'))) { | 
                                                        |
| 2772 | 2772 | return true;  | 
                                                        
| 2773 | 2773 | }  | 
                                                        
| 2774 | 2774 | |
@@ -2778,15 +2778,15 @@ discard block  | 
                                                    ||
| 2778 | 2778 |      public function is_free() { | 
                                                        
| 2779 | 2779 | $is_free = false;  | 
                                                        
| 2780 | 2780 | |
| 2781 | -        if ( !( (float)wpinv_round_amount( $this->get_total() ) > 0 ) ) { | 
                                                        |
| 2782 | -            if ( $this->is_parent() && $this->is_recurring() ) { | 
                                                        |
| 2783 | - $is_free = (float)wpinv_round_amount( $this->get_recurring_details( 'total' ) ) > 0 ? false : true;  | 
                                                        |
| 2781 | +        if (!((float)wpinv_round_amount($this->get_total()) > 0)) { | 
                                                        |
| 2782 | +            if ($this->is_parent() && $this->is_recurring()) { | 
                                                        |
| 2783 | +                $is_free = (float)wpinv_round_amount($this->get_recurring_details('total')) > 0 ? false : true; | 
                                                        |
| 2784 | 2784 |              } else { | 
                                                        
| 2785 | 2785 | $is_free = true;  | 
                                                        
| 2786 | 2786 | }  | 
                                                        
| 2787 | 2787 | }  | 
                                                        
| 2788 | 2788 | |
| 2789 | - return apply_filters( 'wpinv_invoice_is_free', $is_free, $this );  | 
                                                        |
| 2789 | +        return apply_filters('wpinv_invoice_is_free', $is_free, $this); | 
                                                        |
| 2790 | 2790 | }  | 
                                                        
| 2791 | 2791 | |
| 2792 | 2792 |      public function has_vat() { | 
                                                        
@@ -2794,41 +2794,41 @@ discard block  | 
                                                    ||
| 2794 | 2794 | |
| 2795 | 2795 | $requires_vat = false;  | 
                                                        
| 2796 | 2796 | |
| 2797 | -        if ( $this->country ) { | 
                                                        |
| 2797 | +        if ($this->country) { | 
                                                        |
| 2798 | 2798 | $wpi_country = $this->country;  | 
                                                        
| 2799 | 2799 | |
| 2800 | - $requires_vat = $wpinv_euvat->requires_vat( $requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule( $this ) );  | 
                                                        |
| 2800 | + $requires_vat = $wpinv_euvat->requires_vat($requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule($this));  | 
                                                        |
| 2801 | 2801 | }  | 
                                                        
| 2802 | 2802 | |
| 2803 | - return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this );  | 
                                                        |
| 2803 | +        return apply_filters('wpinv_invoice_has_vat', $requires_vat, $this); | 
                                                        |
| 2804 | 2804 | }  | 
                                                        
| 2805 | 2805 | |
| 2806 | 2806 |      public function refresh_item_ids() { | 
                                                        
| 2807 | 2807 | $item_ids = array();  | 
                                                        
| 2808 | 2808 | |
| 2809 | -        if ( !empty( $this->cart_details ) ) { | 
                                                        |
| 2810 | -            foreach ( $this->cart_details as $key => $item ) { | 
                                                        |
| 2811 | -                if ( !empty( $item['id'] ) ) { | 
                                                        |
| 2809 | +        if (!empty($this->cart_details)) { | 
                                                        |
| 2810 | +            foreach ($this->cart_details as $key => $item) { | 
                                                        |
| 2811 | +                if (!empty($item['id'])) { | 
                                                        |
| 2812 | 2812 | $item_ids[] = $item['id'];  | 
                                                        
| 2813 | 2813 | }  | 
                                                        
| 2814 | 2814 | }  | 
                                                        
| 2815 | 2815 | }  | 
                                                        
| 2816 | 2816 | |
| 2817 | - $item_ids = !empty( $item_ids ) ? implode( ',', array_unique( $item_ids ) ) : '';  | 
                                                        |
| 2817 | +        $item_ids = !empty($item_ids) ? implode(',', array_unique($item_ids)) : ''; | 
                                                        |
| 2818 | 2818 | |
| 2819 | - update_post_meta( $this->ID, '_wpinv_item_ids', $item_ids );  | 
                                                        |
| 2819 | + update_post_meta($this->ID, '_wpinv_item_ids', $item_ids);  | 
                                                        |
| 2820 | 2820 | }  | 
                                                        
| 2821 | 2821 | |
| 2822 | -    public function get_invoice_quote_type( $post_id ) { | 
                                                        |
| 2823 | -        if ( empty( $post_id ) ) { | 
                                                        |
| 2822 | +    public function get_invoice_quote_type($post_id) { | 
                                                        |
| 2823 | +        if (empty($post_id)) { | 
                                                        |
| 2824 | 2824 | return '';  | 
                                                        
| 2825 | 2825 | }  | 
                                                        
| 2826 | 2826 | |
| 2827 | - $type = get_post_type( $post_id );  | 
                                                        |
| 2827 | + $type = get_post_type($post_id);  | 
                                                        |
| 2828 | 2828 | |
| 2829 | -        if ( 'wpi_invoice' === $type ) { | 
                                                        |
| 2829 | +        if ('wpi_invoice' === $type) { | 
                                                        |
| 2830 | 2830 |              $post_type = __('Invoice', 'invoicing'); | 
                                                        
| 2831 | -        } else{ | 
                                                        |
| 2831 | +        } else { | 
                                                        |
| 2832 | 2832 |              $post_type = __('Quote', 'invoicing'); | 
                                                        
| 2833 | 2833 | }  | 
                                                        
| 2834 | 2834 | |
@@ -740,6 +740,9 @@  | 
                                                    ||
| 740 | 740 | add_action( 'geodir_dashboard_links', 'wpinv_gdp_dashboard_invoice_history_link' );  | 
                                                        
| 741 | 741 | remove_action( 'geodir_dashboard_links', 'geodir_payment_invoices_list_page_link' );  | 
                                                        
| 742 | 742 | |
| 743 | +/**  | 
                                                        |
| 744 | + * @param string $new_status  | 
                                                        |
| 745 | + */  | 
                                                        |
| 743 | 746 |  function wpinv_wpi_to_gdp_update_status( $invoice_id, $new_status, $old_status ) { | 
                                                        
| 744 | 747 |      if (!defined('GEODIRPAYMENT_VERSION')) { | 
                                                        
| 745 | 748 | return false;  | 
                                                        
@@ -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,6 +1,6 @@ discard block  | 
                                                    ||
| 1 | 1 | <?php  | 
                                                        
| 2 | 2 | // Exit if accessed directly  | 
                                                        
| 3 | -if ( ! defined( 'ABSPATH' ) ) exit;  | 
                                                        |
| 3 | +if (!defined('ABSPATH')) exit; | 
                                                        |
| 4 | 4 | |
| 5 | 5 |  class WPInv_Item { | 
                                                        
| 6 | 6 | public $ID = 0;  | 
                                                        
@@ -33,26 +33,26 @@ discard block  | 
                                                    ||
| 33 | 33 | public $filter;  | 
                                                        
| 34 | 34 | |
| 35 | 35 | |
| 36 | -    public function __construct( $_id = false, $_args = array() ) { | 
                                                        |
| 37 | - $item = WP_Post::get_instance( $_id );  | 
                                                        |
| 38 | - return $this->setup_item( $item );  | 
                                                        |
| 36 | +    public function __construct($_id = false, $_args = array()) { | 
                                                        |
| 37 | + $item = WP_Post::get_instance($_id);  | 
                                                        |
| 38 | + return $this->setup_item($item);  | 
                                                        |
| 39 | 39 | }  | 
                                                        
| 40 | 40 | |
| 41 | -    private function setup_item( $item ) { | 
                                                        |
| 42 | -        if( ! is_object( $item ) ) { | 
                                                        |
| 41 | +    private function setup_item($item) { | 
                                                        |
| 42 | +        if (!is_object($item)) { | 
                                                        |
| 43 | 43 | return false;  | 
                                                        
| 44 | 44 | }  | 
                                                        
| 45 | 45 | |
| 46 | -        if( ! is_a( $item, 'WP_Post' ) ) { | 
                                                        |
| 46 | +        if (!is_a($item, 'WP_Post')) { | 
                                                        |
| 47 | 47 | return false;  | 
                                                        
| 48 | 48 | }  | 
                                                        
| 49 | 49 | |
| 50 | -        if( 'wpi_item' !== $item->post_type ) { | 
                                                        |
| 50 | +        if ('wpi_item' !== $item->post_type) { | 
                                                        |
| 51 | 51 | return false;  | 
                                                        
| 52 | 52 | }  | 
                                                        
| 53 | 53 | |
| 54 | -        foreach ( $item as $key => $value ) { | 
                                                        |
| 55 | -            switch ( $key ) { | 
                                                        |
| 54 | +        foreach ($item as $key => $value) { | 
                                                        |
| 55 | +            switch ($key) { | 
                                                        |
| 56 | 56 | default:  | 
                                                        
| 57 | 57 | $this->$key = $value;  | 
                                                        
| 58 | 58 | break;  | 
                                                        
@@ -62,38 +62,38 @@ discard block  | 
                                                    ||
| 62 | 62 | return true;  | 
                                                        
| 63 | 63 | }  | 
                                                        
| 64 | 64 | |
| 65 | -    public function __get( $key ) { | 
                                                        |
| 66 | -        if ( method_exists( $this, 'get_' . $key ) ) { | 
                                                        |
| 67 | - return call_user_func( array( $this, 'get_' . $key ) );  | 
                                                        |
| 65 | +    public function __get($key) { | 
                                                        |
| 66 | +        if (method_exists($this, 'get_' . $key)) { | 
                                                        |
| 67 | + return call_user_func(array($this, 'get_' . $key));  | 
                                                        |
| 68 | 68 |          } else { | 
                                                        
| 69 | - return new WP_Error( 'wpinv-item-invalid-property', sprintf( __( 'Can\'t get property %s', 'invoicing' ), $key ) );  | 
                                                        |
| 69 | +            return new WP_Error('wpinv-item-invalid-property', sprintf(__('Can\'t get property %s', 'invoicing'), $key)); | 
                                                        |
| 70 | 70 | }  | 
                                                        
| 71 | 71 | }  | 
                                                        
| 72 | 72 | |
| 73 | -    public function create( $data = array(), $wp_error = false ) { | 
                                                        |
| 74 | -        if ( $this->ID != 0 ) { | 
                                                        |
| 73 | +    public function create($data = array(), $wp_error = false) { | 
                                                        |
| 74 | +        if ($this->ID != 0) { | 
                                                        |
| 75 | 75 | return false;  | 
                                                        
| 76 | 76 | }  | 
                                                        
| 77 | 77 | |
| 78 | 78 | $defaults = array(  | 
                                                        
| 79 | 79 | 'post_type' => 'wpi_item',  | 
                                                        
| 80 | 80 | 'post_status' => 'draft',  | 
                                                        
| 81 | - 'post_title' => __( 'New Invoice Item', 'invoicing' )  | 
                                                        |
| 81 | +            'post_title'  => __('New Invoice Item', 'invoicing') | 
                                                        |
| 82 | 82 | );  | 
                                                        
| 83 | 83 | |
| 84 | - $args = wp_parse_args( $data, $defaults );  | 
                                                        |
| 84 | + $args = wp_parse_args($data, $defaults);  | 
                                                        |
| 85 | 85 | |
| 86 | - do_action( 'wpinv_item_pre_create', $args );  | 
                                                        |
| 86 | +        do_action('wpinv_item_pre_create', $args); | 
                                                        |
| 87 | 87 | |
| 88 | - $id = wp_insert_post( $args, $wp_error );  | 
                                                        |
| 88 | + $id = wp_insert_post($args, $wp_error);  | 
                                                        |
| 89 | 89 |          if ($wp_error && is_wp_error($id)) { | 
                                                        
| 90 | 90 | return $id;  | 
                                                        
| 91 | 91 | }  | 
                                                        
| 92 | -        if ( !$id ) { | 
                                                        |
| 92 | +        if (!$id) { | 
                                                        |
| 93 | 93 | return false;  | 
                                                        
| 94 | 94 | }  | 
                                                        
| 95 | 95 | |
| 96 | - $item = WP_Post::get_instance( $id );  | 
                                                        |
| 96 | + $item = WP_Post::get_instance($id);  | 
                                                        |
| 97 | 97 | |
| 98 | 98 |          if (!empty($item) && !empty($data['meta'])) { | 
                                                        
| 99 | 99 | $this->ID = $item->ID;  | 
                                                        
@@ -101,47 +101,47 @@ discard block  | 
                                                    ||
| 101 | 101 | }  | 
                                                        
| 102 | 102 | |
| 103 | 103 | // Set custom id if not set.  | 
                                                        
| 104 | -        if ( empty( $data['meta']['custom_id'] ) && !$this->get_custom_id() ) { | 
                                                        |
| 105 | - $item->save_metas( array( 'custom_id' => $id ) );  | 
                                                        |
| 104 | +        if (empty($data['meta']['custom_id']) && !$this->get_custom_id()) { | 
                                                        |
| 105 | +            $item->save_metas(array('custom_id' => $id)); | 
                                                        |
| 106 | 106 | }  | 
                                                        
| 107 | 107 | |
| 108 | - do_action( 'wpinv_item_create', $id, $args );  | 
                                                        |
| 108 | +        do_action('wpinv_item_create', $id, $args); | 
                                                        |
| 109 | 109 | |
| 110 | - return $this->setup_item( $item );  | 
                                                        |
| 110 | + return $this->setup_item($item);  | 
                                                        |
| 111 | 111 | }  | 
                                                        
| 112 | 112 | |
| 113 | -    public function update( $data = array(), $wp_error = false ) { | 
                                                        |
| 114 | -        if ( !$this->ID > 0 ) { | 
                                                        |
| 113 | +    public function update($data = array(), $wp_error = false) { | 
                                                        |
| 114 | +        if (!$this->ID > 0) { | 
                                                        |
| 115 | 115 | return false;  | 
                                                        
| 116 | 116 | }  | 
                                                        
| 117 | 117 | |
| 118 | 118 | $data['ID'] = $this->ID;  | 
                                                        
| 119 | 119 | |
| 120 | - do_action( 'wpinv_item_pre_update', $data );  | 
                                                        |
| 120 | +        do_action('wpinv_item_pre_update', $data); | 
                                                        |
| 121 | 121 | |
| 122 | - $id = wp_update_post( $data, $wp_error );  | 
                                                        |
| 122 | + $id = wp_update_post($data, $wp_error);  | 
                                                        |
| 123 | 123 |          if ($wp_error && is_wp_error($id)) { | 
                                                        
| 124 | 124 | return $id;  | 
                                                        
| 125 | 125 | }  | 
                                                        
| 126 | 126 | |
| 127 | -        if ( !$id ) { | 
                                                        |
| 127 | +        if (!$id) { | 
                                                        |
| 128 | 128 | return false;  | 
                                                        
| 129 | 129 | }  | 
                                                        
| 130 | 130 | |
| 131 | - $item = WP_Post::get_instance( $id );  | 
                                                        |
| 131 | + $item = WP_Post::get_instance($id);  | 
                                                        |
| 132 | 132 |          if (!empty($item) && !empty($data['meta'])) { | 
                                                        
| 133 | 133 | $this->ID = $item->ID;  | 
                                                        
| 134 | 134 | $this->save_metas($data['meta']);  | 
                                                        
| 135 | 135 | }  | 
                                                        
| 136 | 136 | |
| 137 | 137 | // Set custom id if not set.  | 
                                                        
| 138 | -        if ( empty( $data['meta']['custom_id'] ) && !$this->get_custom_id() ) { | 
                                                        |
| 139 | - $item->save_metas( array( 'custom_id' => $id ) );  | 
                                                        |
| 138 | +        if (empty($data['meta']['custom_id']) && !$this->get_custom_id()) { | 
                                                        |
| 139 | +            $item->save_metas(array('custom_id' => $id)); | 
                                                        |
| 140 | 140 | }  | 
                                                        
| 141 | 141 | |
| 142 | - do_action( 'wpinv_item_update', $id, $data );  | 
                                                        |
| 142 | +        do_action('wpinv_item_update', $id, $data); | 
                                                        |
| 143 | 143 | |
| 144 | - return $this->setup_item( $item );  | 
                                                        |
| 144 | + return $this->setup_item($item);  | 
                                                        |
| 145 | 145 | }  | 
                                                        
| 146 | 146 | |
| 147 | 147 |      public function get_ID() { | 
                                                        
@@ -149,105 +149,105 @@ discard block  | 
                                                    ||
| 149 | 149 | }  | 
                                                        
| 150 | 150 | |
| 151 | 151 |      public function get_name() { | 
                                                        
| 152 | - return get_the_title( $this->ID );  | 
                                                        |
| 152 | + return get_the_title($this->ID);  | 
                                                        |
| 153 | 153 | }  | 
                                                        
| 154 | 154 | |
| 155 | 155 |      public function get_summary() { | 
                                                        
| 156 | - return get_the_excerpt( $this->ID );  | 
                                                        |
| 156 | + return get_the_excerpt($this->ID);  | 
                                                        |
| 157 | 157 | }  | 
                                                        
| 158 | 158 | |
| 159 | 159 |      public function get_price() { | 
                                                        
| 160 | -        if ( ! isset( $this->price ) ) { | 
                                                        |
| 161 | - $this->price = get_post_meta( $this->ID, '_wpinv_price', true );  | 
                                                        |
| 160 | +        if (!isset($this->price)) { | 
                                                        |
| 161 | + $this->price = get_post_meta($this->ID, '_wpinv_price', true);  | 
                                                        |
| 162 | 162 | |
| 163 | -            if ( $this->price ) { | 
                                                        |
| 164 | - $this->price = wpinv_sanitize_amount( $this->price );  | 
                                                        |
| 163 | +            if ($this->price) { | 
                                                        |
| 164 | + $this->price = wpinv_sanitize_amount($this->price);  | 
                                                        |
| 165 | 165 |              } else { | 
                                                        
| 166 | 166 | $this->price = 0;  | 
                                                        
| 167 | 167 | }  | 
                                                        
| 168 | 168 | }  | 
                                                        
| 169 | 169 | |
| 170 | - return apply_filters( 'wpinv_get_item_price', $this->price, $this->ID );  | 
                                                        |
| 170 | +        return apply_filters('wpinv_get_item_price', $this->price, $this->ID); | 
                                                        |
| 171 | 171 | }  | 
                                                        
| 172 | 172 | |
| 173 | 173 |      public function get_the_price() { | 
                                                        
| 174 | - $item_price = wpinv_price( wpinv_format_amount( $this->price ) );  | 
                                                        |
| 174 | + $item_price = wpinv_price(wpinv_format_amount($this->price));  | 
                                                        |
| 175 | 175 | |
| 176 | - return apply_filters( 'wpinv_get_the_item_price', $item_price, $this->ID );  | 
                                                        |
| 176 | +        return apply_filters('wpinv_get_the_item_price', $item_price, $this->ID); | 
                                                        |
| 177 | 177 | }  | 
                                                        
| 178 | 178 | |
| 179 | 179 |      public function get_vat_rule() { | 
                                                        
| 180 | 180 | global $wpinv_euvat;  | 
                                                        
| 181 | 181 | |
| 182 | -        if( !isset( $this->vat_rule ) ) { | 
                                                        |
| 183 | - $this->vat_rule = get_post_meta( $this->ID, '_wpinv_vat_rule', true );  | 
                                                        |
| 182 | +        if (!isset($this->vat_rule)) { | 
                                                        |
| 183 | + $this->vat_rule = get_post_meta($this->ID, '_wpinv_vat_rule', true);  | 
                                                        |
| 184 | 184 | |
| 185 | -            if ( empty( $this->vat_rule ) ) {         | 
                                                        |
| 185 | +            if (empty($this->vat_rule)) {         | 
                                                        |
| 186 | 186 | $this->vat_rule = $wpinv_euvat->allow_vat_rules() ? 'digital' : 'physical';  | 
                                                        
| 187 | 187 | }  | 
                                                        
| 188 | 188 | }  | 
                                                        
| 189 | 189 | |
| 190 | - return apply_filters( 'wpinv_get_item_vat_rule', $this->vat_rule, $this->ID );  | 
                                                        |
| 190 | +        return apply_filters('wpinv_get_item_vat_rule', $this->vat_rule, $this->ID); | 
                                                        |
| 191 | 191 | }  | 
                                                        
| 192 | 192 | |
| 193 | 193 |      public function get_vat_class() { | 
                                                        
| 194 | -        if( !isset( $this->vat_class ) ) { | 
                                                        |
| 195 | - $this->vat_class = get_post_meta( $this->ID, '_wpinv_vat_class', true );  | 
                                                        |
| 194 | +        if (!isset($this->vat_class)) { | 
                                                        |
| 195 | + $this->vat_class = get_post_meta($this->ID, '_wpinv_vat_class', true);  | 
                                                        |
| 196 | 196 | |
| 197 | -            if ( empty( $this->vat_class ) ) {         | 
                                                        |
| 197 | +            if (empty($this->vat_class)) {         | 
                                                        |
| 198 | 198 | $this->vat_class = '_standard';  | 
                                                        
| 199 | 199 | }  | 
                                                        
| 200 | 200 | }  | 
                                                        
| 201 | 201 | |
| 202 | - return apply_filters( 'wpinv_get_item_vat_class', $this->vat_class, $this->ID );  | 
                                                        |
| 202 | +        return apply_filters('wpinv_get_item_vat_class', $this->vat_class, $this->ID); | 
                                                        |
| 203 | 203 | }  | 
                                                        
| 204 | 204 | |
| 205 | 205 |      public function get_type() { | 
                                                        
| 206 | -        if( ! isset( $this->type ) ) { | 
                                                        |
| 207 | - $this->type = get_post_meta( $this->ID, '_wpinv_type', true );  | 
                                                        |
| 206 | +        if (!isset($this->type)) { | 
                                                        |
| 207 | + $this->type = get_post_meta($this->ID, '_wpinv_type', true);  | 
                                                        |
| 208 | 208 | |
| 209 | -            if ( empty( $this->type ) ) { | 
                                                        |
| 209 | +            if (empty($this->type)) { | 
                                                        |
| 210 | 210 | $this->type = 'custom';  | 
                                                        
| 211 | 211 | }  | 
                                                        
| 212 | 212 | }  | 
                                                        
| 213 | 213 | |
| 214 | - return apply_filters( 'wpinv_get_item_type', $this->type, $this->ID );  | 
                                                        |
| 214 | +        return apply_filters('wpinv_get_item_type', $this->type, $this->ID); | 
                                                        |
| 215 | 215 | }  | 
                                                        
| 216 | 216 | |
| 217 | 217 |      public function get_custom_id() { | 
                                                        
| 218 | - $custom_id = get_post_meta( $this->ID, '_wpinv_custom_id', true );  | 
                                                        |
| 218 | + $custom_id = get_post_meta($this->ID, '_wpinv_custom_id', true);  | 
                                                        |
| 219 | 219 | |
| 220 | - return apply_filters( 'wpinv_get_item_custom_id', $custom_id, $this->ID );  | 
                                                        |
| 220 | +        return apply_filters('wpinv_get_item_custom_id', $custom_id, $this->ID); | 
                                                        |
| 221 | 221 | }  | 
                                                        
| 222 | 222 | |
| 223 | 223 |      public function get_custom_name() { | 
                                                        
| 224 | - $custom_name = get_post_meta( $this->ID, '_wpinv_custom_name', true );  | 
                                                        |
| 224 | + $custom_name = get_post_meta($this->ID, '_wpinv_custom_name', true);  | 
                                                        |
| 225 | 225 | |
| 226 | - return apply_filters( 'wpinv_get_item_custom_name', $custom_name, $this->ID );  | 
                                                        |
| 226 | +        return apply_filters('wpinv_get_item_custom_name', $custom_name, $this->ID); | 
                                                        |
| 227 | 227 | }  | 
                                                        
| 228 | 228 | |
| 229 | 229 |      public function get_custom_singular_name() { | 
                                                        
| 230 | - $custom_singular_name = get_post_meta( $this->ID, '_wpinv_custom_singular_name', true );  | 
                                                        |
| 230 | + $custom_singular_name = get_post_meta($this->ID, '_wpinv_custom_singular_name', true);  | 
                                                        |
| 231 | 231 | |
| 232 | - return apply_filters( 'wpinv_get_item_custom_singular_name', $custom_singular_name, $this->ID );  | 
                                                        |
| 232 | +        return apply_filters('wpinv_get_item_custom_singular_name', $custom_singular_name, $this->ID); | 
                                                        |
| 233 | 233 | }  | 
                                                        
| 234 | 234 | |
| 235 | 235 |      public function is_recurring() { | 
                                                        
| 236 | - $is_recurring = get_post_meta( $this->ID, '_wpinv_is_recurring', true );  | 
                                                        |
| 236 | + $is_recurring = get_post_meta($this->ID, '_wpinv_is_recurring', true);  | 
                                                        |
| 237 | 237 | |
| 238 | - return (bool)apply_filters( 'wpinv_is_recurring_item', $is_recurring, $this->ID );  | 
                                                        |
| 238 | +        return (bool)apply_filters('wpinv_is_recurring_item', $is_recurring, $this->ID); | 
                                                        |
| 239 | 239 | |
| 240 | 240 | }  | 
                                                        
| 241 | 241 | |
| 242 | -    public function get_recurring_period( $full = false ) { | 
                                                        |
| 243 | - $period = get_post_meta( $this->ID, '_wpinv_recurring_period', true );  | 
                                                        |
| 242 | +    public function get_recurring_period($full = false) { | 
                                                        |
| 243 | + $period = get_post_meta($this->ID, '_wpinv_recurring_period', true);  | 
                                                        |
| 244 | 244 | |
| 245 | -        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) { | 
                                                        |
| 245 | +        if (!in_array($period, array('D', 'W', 'M', 'Y'))) { | 
                                                        |
| 246 | 246 | $period = 'D';  | 
                                                        
| 247 | 247 | }  | 
                                                        
| 248 | 248 | |
| 249 | -        if ( $full ) { | 
                                                        |
| 250 | -            switch( $period ) { | 
                                                        |
| 249 | +        if ($full) { | 
                                                        |
| 250 | +            switch ($period) { | 
                                                        |
| 251 | 251 | case 'D':  | 
                                                        
| 252 | 252 | $period = 'day';  | 
                                                        
| 253 | 253 | break;  | 
                                                        
@@ -263,45 +263,45 @@ discard block  | 
                                                    ||
| 263 | 263 | }  | 
                                                        
| 264 | 264 | }  | 
                                                        
| 265 | 265 | |
| 266 | - return apply_filters( 'wpinv_item_recurring_period', $period, $full, $this->ID );  | 
                                                        |
| 266 | +        return apply_filters('wpinv_item_recurring_period', $period, $full, $this->ID); | 
                                                        |
| 267 | 267 | |
| 268 | 268 | }  | 
                                                        
| 269 | 269 | |
| 270 | 270 |      public function get_recurring_interval() { | 
                                                        
| 271 | - $interval = (int)get_post_meta( $this->ID, '_wpinv_recurring_interval', true );  | 
                                                        |
| 271 | + $interval = (int)get_post_meta($this->ID, '_wpinv_recurring_interval', true);  | 
                                                        |
| 272 | 272 | |
| 273 | -        if ( !$interval > 0 ) { | 
                                                        |
| 273 | +        if (!$interval > 0) { | 
                                                        |
| 274 | 274 | $interval = 1;  | 
                                                        
| 275 | 275 | }  | 
                                                        
| 276 | 276 | |
| 277 | - return apply_filters( 'wpinv_item_recurring_interval', $interval, $this->ID );  | 
                                                        |
| 277 | +        return apply_filters('wpinv_item_recurring_interval', $interval, $this->ID); | 
                                                        |
| 278 | 278 | |
| 279 | 279 | }  | 
                                                        
| 280 | 280 | |
| 281 | 281 |      public function get_recurring_limit() { | 
                                                        
| 282 | - $limit = get_post_meta( $this->ID, '_wpinv_recurring_limit', true );  | 
                                                        |
| 282 | + $limit = get_post_meta($this->ID, '_wpinv_recurring_limit', true);  | 
                                                        |
| 283 | 283 | |
| 284 | - return (int)apply_filters( 'wpinv_item_recurring_limit', $limit, $this->ID );  | 
                                                        |
| 284 | +        return (int)apply_filters('wpinv_item_recurring_limit', $limit, $this->ID); | 
                                                        |
| 285 | 285 | |
| 286 | 286 | }  | 
                                                        
| 287 | 287 | |
| 288 | 288 |      public function has_free_trial() { | 
                                                        
| 289 | - $free_trial = get_post_meta( $this->ID, '_wpinv_free_trial', true );  | 
                                                        |
| 290 | - $free_trial = $this->is_recurring() && !empty( $free_trial ) ? true : false;  | 
                                                        |
| 289 | + $free_trial = get_post_meta($this->ID, '_wpinv_free_trial', true);  | 
                                                        |
| 290 | + $free_trial = $this->is_recurring() && !empty($free_trial) ? true : false;  | 
                                                        |
| 291 | 291 | |
| 292 | - return (bool)apply_filters( 'wpinv_item_has_free_trial', $free_trial, $this->ID );  | 
                                                        |
| 292 | +        return (bool)apply_filters('wpinv_item_has_free_trial', $free_trial, $this->ID); | 
                                                        |
| 293 | 293 | |
| 294 | 294 | }  | 
                                                        
| 295 | 295 | |
| 296 | -    public function get_trial_period( $full = false ) { | 
                                                        |
| 297 | - $period = get_post_meta( $this->ID, '_wpinv_trial_period', true );  | 
                                                        |
| 296 | +    public function get_trial_period($full = false) { | 
                                                        |
| 297 | + $period = get_post_meta($this->ID, '_wpinv_trial_period', true);  | 
                                                        |
| 298 | 298 | |
| 299 | -        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) { | 
                                                        |
| 299 | +        if (!in_array($period, array('D', 'W', 'M', 'Y'))) { | 
                                                        |
| 300 | 300 | $period = 'D';  | 
                                                        
| 301 | 301 | }  | 
                                                        
| 302 | 302 | |
| 303 | -        if ( $full ) { | 
                                                        |
| 304 | -            switch( $period ) { | 
                                                        |
| 303 | +        if ($full) { | 
                                                        |
| 304 | +            switch ($period) { | 
                                                        |
| 305 | 305 | case 'D':  | 
                                                        
| 306 | 306 | $period = 'day';  | 
                                                        
| 307 | 307 | break;  | 
                                                        
@@ -317,47 +317,47 @@ discard block  | 
                                                    ||
| 317 | 317 | }  | 
                                                        
| 318 | 318 | }  | 
                                                        
| 319 | 319 | |
| 320 | - return apply_filters( 'wpinv_item_trial_period', $period, $full, $this->ID );  | 
                                                        |
| 320 | +        return apply_filters('wpinv_item_trial_period', $period, $full, $this->ID); | 
                                                        |
| 321 | 321 | |
| 322 | 322 | }  | 
                                                        
| 323 | 323 | |
| 324 | 324 |      public function get_trial_interval() { | 
                                                        
| 325 | - $interval = absint( get_post_meta( $this->ID, '_wpinv_trial_interval', true ) );  | 
                                                        |
| 325 | + $interval = absint(get_post_meta($this->ID, '_wpinv_trial_interval', true));  | 
                                                        |
| 326 | 326 | |
| 327 | -        if ( !$interval > 0 ) { | 
                                                        |
| 327 | +        if (!$interval > 0) { | 
                                                        |
| 328 | 328 | $interval = 1;  | 
                                                        
| 329 | 329 | }  | 
                                                        
| 330 | 330 | |
| 331 | - return apply_filters( 'wpinv_item_trial_interval', $interval, $this->ID );  | 
                                                        |
| 331 | +        return apply_filters('wpinv_item_trial_interval', $interval, $this->ID); | 
                                                        |
| 332 | 332 | |
| 333 | 333 | }  | 
                                                        
| 334 | 334 | |
| 335 | 335 |      public function is_free() { | 
                                                        
| 336 | 336 | $is_free = false;  | 
                                                        
| 337 | 337 | |
| 338 | - $price = get_post_meta( $this->ID, '_wpinv_price', true );  | 
                                                        |
| 338 | + $price = get_post_meta($this->ID, '_wpinv_price', true);  | 
                                                        |
| 339 | 339 | |
| 340 | -        if ( (float)$price == 0 ) { | 
                                                        |
| 340 | +        if ((float)$price == 0) { | 
                                                        |
| 341 | 341 | $is_free = true;  | 
                                                        
| 342 | 342 | }  | 
                                                        
| 343 | 343 | |
| 344 | - return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID );  | 
                                                        |
| 344 | +        return (bool)apply_filters('wpinv_is_free_item', $is_free, $this->ID); | 
                                                        |
| 345 | 345 | |
| 346 | 346 | }  | 
                                                        
| 347 | 347 | |
| 348 | 348 |      public function is_package() { | 
                                                        
| 349 | 349 | $is_package = $this->get_type() == 'package' ? true : false;  | 
                                                        
| 350 | 350 | |
| 351 | - return (bool) apply_filters( 'wpinv_is_package_item', $is_package, $this->ID );  | 
                                                        |
| 351 | +        return (bool)apply_filters('wpinv_is_package_item', $is_package, $this->ID); | 
                                                        |
| 352 | 352 | |
| 353 | 353 | }  | 
                                                        
| 354 | 354 | |
| 355 | -    public function save_metas( $metas = array() ) { | 
                                                        |
| 356 | -        if ( empty( $metas ) ) { | 
                                                        |
| 355 | +    public function save_metas($metas = array()) { | 
                                                        |
| 356 | +        if (empty($metas)) { | 
                                                        |
| 357 | 357 | return false;  | 
                                                        
| 358 | 358 | }  | 
                                                        
| 359 | 359 | |
| 360 | -        foreach ( $metas as $meta_key => $meta_value ) { | 
                                                        |
| 360 | +        foreach ($metas as $meta_key => $meta_value) { | 
                                                        |
| 361 | 361 | $meta_key = strpos($meta_key, '_wpinv_') !== 0 ? '_wpinv_' . $meta_key : $meta_key;  | 
                                                        
| 362 | 362 | |
| 363 | 363 | $this->update_meta($meta_key, $meta_value);  | 
                                                        
@@ -366,66 +366,66 @@ discard block  | 
                                                    ||
| 366 | 366 | return true;  | 
                                                        
| 367 | 367 | }  | 
                                                        
| 368 | 368 | |
| 369 | -    public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) { | 
                                                        |
| 370 | -        if ( empty( $meta_key ) ) { | 
                                                        |
| 369 | +    public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') { | 
                                                        |
| 370 | +        if (empty($meta_key)) { | 
                                                        |
| 371 | 371 | return false;  | 
                                                        
| 372 | 372 | }  | 
                                                        
| 373 | 373 | |
| 374 | - $meta_value = apply_filters( 'wpinv_update_item_meta_' . $meta_key, $meta_value, $this->ID );  | 
                                                        |
| 374 | +        $meta_value = apply_filters('wpinv_update_item_meta_' . $meta_key, $meta_value, $this->ID); | 
                                                        |
| 375 | 375 | |
| 376 | - return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value );  | 
                                                        |
| 376 | + return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value);  | 
                                                        |
| 377 | 377 | }  | 
                                                        
| 378 | 378 | |
| 379 | -    public function get_fees( $type = 'fee', $item_id = 0 ) { | 
                                                        |
| 379 | +    public function get_fees($type = 'fee', $item_id = 0) { | 
                                                        |
| 380 | 380 | global $wpi_session;  | 
                                                        
| 381 | 381 | |
| 382 | - $fees = $wpi_session->get( 'wpi_cart_fees' );  | 
                                                        |
| 382 | +        $fees = $wpi_session->get('wpi_cart_fees'); | 
                                                        |
| 383 | 383 | |
| 384 | -        if ( ! wpinv_get_cart_contents() ) { | 
                                                        |
| 384 | +        if (!wpinv_get_cart_contents()) { | 
                                                        |
| 385 | 385 | // We can only get item type fees when the cart is empty  | 
                                                        
| 386 | 386 | $type = 'custom';  | 
                                                        
| 387 | 387 | }  | 
                                                        
| 388 | 388 | |
| 389 | -        if ( ! empty( $fees ) && ! empty( $type ) && 'all' !== $type ) { | 
                                                        |
| 390 | -            foreach( $fees as $key => $fee ) { | 
                                                        |
| 391 | -                if( ! empty( $fee['type'] ) && $type != $fee['type'] ) { | 
                                                        |
| 392 | - unset( $fees[ $key ] );  | 
                                                        |
| 389 | +        if (!empty($fees) && !empty($type) && 'all' !== $type) { | 
                                                        |
| 390 | +            foreach ($fees as $key => $fee) { | 
                                                        |
| 391 | +                if (!empty($fee['type']) && $type != $fee['type']) { | 
                                                        |
| 392 | + unset($fees[$key]);  | 
                                                        |
| 393 | 393 | }  | 
                                                        
| 394 | 394 | }  | 
                                                        
| 395 | 395 | }  | 
                                                        
| 396 | 396 | |
| 397 | -        if ( ! empty( $fees ) && ! empty( $item_id ) ) { | 
                                                        |
| 397 | +        if (!empty($fees) && !empty($item_id)) { | 
                                                        |
| 398 | 398 | // Remove fees that don't belong to the specified Item  | 
                                                        
| 399 | -            foreach ( $fees as $key => $fee ) { | 
                                                        |
| 400 | -                if ( (int) $item_id !== (int)$fee['custom_id'] ) { | 
                                                        |
| 401 | - unset( $fees[ $key ] );  | 
                                                        |
| 399 | +            foreach ($fees as $key => $fee) { | 
                                                        |
| 400 | +                if ((int)$item_id !== (int)$fee['custom_id']) { | 
                                                        |
| 401 | + unset($fees[$key]);  | 
                                                        |
| 402 | 402 | }  | 
                                                        
| 403 | 403 | }  | 
                                                        
| 404 | 404 | }  | 
                                                        
| 405 | 405 | |
| 406 | -        if ( ! empty( $fees ) ) { | 
                                                        |
| 406 | +        if (!empty($fees)) { | 
                                                        |
| 407 | 407 | // Remove fees that belong to a specific item but are not in the cart  | 
                                                        
| 408 | -            foreach( $fees as $key => $fee ) { | 
                                                        |
| 409 | -                if( empty( $fee['custom_id'] ) ) { | 
                                                        |
| 408 | +            foreach ($fees as $key => $fee) { | 
                                                        |
| 409 | +                if (empty($fee['custom_id'])) { | 
                                                        |
| 410 | 410 | continue;  | 
                                                        
| 411 | 411 | }  | 
                                                        
| 412 | 412 | |
| 413 | -                if ( !wpinv_item_in_cart( $fee['custom_id'] ) ) { | 
                                                        |
| 414 | - unset( $fees[ $key ] );  | 
                                                        |
| 413 | +                if (!wpinv_item_in_cart($fee['custom_id'])) { | 
                                                        |
| 414 | + unset($fees[$key]);  | 
                                                        |
| 415 | 415 | }  | 
                                                        
| 416 | 416 | }  | 
                                                        
| 417 | 417 | }  | 
                                                        
| 418 | 418 | |
| 419 | - return ! empty( $fees ) ? $fees : array();  | 
                                                        |
| 419 | + return !empty($fees) ? $fees : array();  | 
                                                        |
| 420 | 420 | }  | 
                                                        
| 421 | 421 | |
| 422 | 422 |      public function can_purchase() { | 
                                                        
| 423 | 423 | $can_purchase = true;  | 
                                                        
| 424 | 424 | |
| 425 | -        if ( !current_user_can( 'edit_post', $this->ID ) && $this->post_status != 'publish' ) { | 
                                                        |
| 425 | +        if (!current_user_can('edit_post', $this->ID) && $this->post_status != 'publish') { | 
                                                        |
| 426 | 426 | $can_purchase = false;  | 
                                                        
| 427 | 427 | }  | 
                                                        
| 428 | 428 | |
| 429 | - return (bool)apply_filters( 'wpinv_can_purchase_item', $can_purchase, $this );  | 
                                                        |
| 429 | +        return (bool)apply_filters('wpinv_can_purchase_item', $can_purchase, $this); | 
                                                        |
| 430 | 430 | }  | 
                                                        
| 431 | 431 | }  | 
                                                        
@@ -7,195 +7,195 @@ discard block  | 
                                                    ||
| 7 | 7 | */  | 
                                                        
| 8 | 8 | |
| 9 | 9 | // MUST have WordPress.  | 
                                                        
| 10 | -if ( !defined( 'WPINC' ) ) { | 
                                                        |
| 11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );  | 
                                                        |
| 10 | +if (!defined('WPINC')) { | 
                                                        |
| 11 | +    exit('Do NOT access this file directly: ' . basename(__FILE__)); | 
                                                        |
| 12 | 12 | }  | 
                                                        
| 13 | 13 | |
| 14 | 14 |  function wpinv_is_checkout() { | 
                                                        
| 15 | 15 | global $wp_query;  | 
                                                        
| 16 | 16 | |
| 17 | - $is_object_set = isset( $wp_query->queried_object );  | 
                                                        |
| 18 | - $is_object_id_set = isset( $wp_query->queried_object_id );  | 
                                                        |
| 19 | - $is_checkout = is_page( wpinv_get_option( 'checkout_page' ) );  | 
                                                        |
| 17 | + $is_object_set = isset($wp_query->queried_object);  | 
                                                        |
| 18 | + $is_object_id_set = isset($wp_query->queried_object_id);  | 
                                                        |
| 19 | +    $is_checkout      = is_page(wpinv_get_option('checkout_page')); | 
                                                        |
| 20 | 20 | |
| 21 | -    if ( !$is_object_set ) { | 
                                                        |
| 22 | - unset( $wp_query->queried_object );  | 
                                                        |
| 21 | +    if (!$is_object_set) { | 
                                                        |
| 22 | + unset($wp_query->queried_object);  | 
                                                        |
| 23 | 23 | }  | 
                                                        
| 24 | 24 | |
| 25 | -    if ( !$is_object_id_set ) { | 
                                                        |
| 26 | - unset( $wp_query->queried_object_id );  | 
                                                        |
| 25 | +    if (!$is_object_id_set) { | 
                                                        |
| 26 | + unset($wp_query->queried_object_id);  | 
                                                        |
| 27 | 27 | }  | 
                                                        
| 28 | 28 | |
| 29 | - return apply_filters( 'wpinv_is_checkout', $is_checkout );  | 
                                                        |
| 29 | +    return apply_filters('wpinv_is_checkout', $is_checkout); | 
                                                        |
| 30 | 30 | }  | 
                                                        
| 31 | 31 | |
| 32 | 32 |  function wpinv_can_checkout() { | 
                                                        
| 33 | 33 | $can_checkout = true; // Always true for now  | 
                                                        
| 34 | 34 | |
| 35 | - return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout );  | 
                                                        |
| 35 | +	return (bool)apply_filters('wpinv_can_checkout', $can_checkout); | 
                                                        |
| 36 | 36 | }  | 
                                                        
| 37 | 37 | |
| 38 | 38 |  function wpinv_get_success_page_uri() { | 
                                                        
| 39 | - $page_id = wpinv_get_option( 'success_page', 0 );  | 
                                                        |
| 40 | - $page_id = absint( $page_id );  | 
                                                        |
| 39 | +	$page_id = wpinv_get_option('success_page', 0); | 
                                                        |
| 40 | + $page_id = absint($page_id);  | 
                                                        |
| 41 | 41 | |
| 42 | - return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) );  | 
                                                        |
| 42 | +	return apply_filters('wpinv_get_success_page_uri', get_permalink($page_id)); | 
                                                        |
| 43 | 43 | }  | 
                                                        
| 44 | 44 | |
| 45 | 45 |  function wpinv_get_history_page_uri() { | 
                                                        
| 46 | - $page_id = wpinv_get_option( 'invoice_history_page', 0 );  | 
                                                        |
| 47 | - $page_id = absint( $page_id );  | 
                                                        |
| 46 | +	$page_id = wpinv_get_option('invoice_history_page', 0); | 
                                                        |
| 47 | + $page_id = absint($page_id);  | 
                                                        |
| 48 | 48 | |
| 49 | - return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ) );  | 
                                                        |
| 49 | +	return apply_filters('wpinv_get_history_page_uri', get_permalink($page_id)); | 
                                                        |
| 50 | 50 | }  | 
                                                        
| 51 | 51 | |
| 52 | 52 |  function wpinv_is_success_page() { | 
                                                        
| 53 | - $is_success_page = wpinv_get_option( 'success_page', false );  | 
                                                        |
| 54 | - $is_success_page = isset( $is_success_page ) ? is_page( $is_success_page ) : false;  | 
                                                        |
| 53 | +	$is_success_page = wpinv_get_option('success_page', false); | 
                                                        |
| 54 | + $is_success_page = isset($is_success_page) ? is_page($is_success_page) : false;  | 
                                                        |
| 55 | 55 | |
| 56 | - return apply_filters( 'wpinv_is_success_page', $is_success_page );  | 
                                                        |
| 56 | +	return apply_filters('wpinv_is_success_page', $is_success_page); | 
                                                        |
| 57 | 57 | }  | 
                                                        
| 58 | 58 | |
| 59 | 59 |  function wpinv_is_invoice_history_page() { | 
                                                        
| 60 | - $ret = wpinv_get_option( 'invoice_history_page', false );  | 
                                                        |
| 61 | - $ret = $ret ? is_page( $ret ) : false;  | 
                                                        |
| 62 | - return apply_filters( 'wpinv_is_invoice_history_page', $ret );  | 
                                                        |
| 60 | +	$ret = wpinv_get_option('invoice_history_page', false); | 
                                                        |
| 61 | + $ret = $ret ? is_page($ret) : false;  | 
                                                        |
| 62 | +	return apply_filters('wpinv_is_invoice_history_page', $ret); | 
                                                        |
| 63 | 63 | }  | 
                                                        
| 64 | 64 | |
| 65 | -function wpinv_send_to_success_page( $args = null ) { | 
                                                        |
| 65 | +function wpinv_send_to_success_page($args = null) { | 
                                                        |
| 66 | 66 | $redirect = wpinv_get_success_page_uri();  | 
                                                        
| 67 | 67 | |
| 68 | -    if ( !empty( $args ) ) { | 
                                                        |
| 68 | +    if (!empty($args)) { | 
                                                        |
| 69 | 69 | // Check for backward compatibility  | 
                                                        
| 70 | - if ( is_string( $args ) )  | 
                                                        |
| 71 | - $args = str_replace( '?', '', $args );  | 
                                                        |
| 70 | + if (is_string($args))  | 
                                                        |
| 71 | +            $args = str_replace('?', '', $args); | 
                                                        |
| 72 | 72 | |
| 73 | - $args = wp_parse_args( $args );  | 
                                                        |
| 73 | + $args = wp_parse_args($args);  | 
                                                        |
| 74 | 74 | |
| 75 | - $redirect = add_query_arg( $args, $redirect );  | 
                                                        |
| 75 | + $redirect = add_query_arg($args, $redirect);  | 
                                                        |
| 76 | 76 | }  | 
                                                        
| 77 | 77 | |
| 78 | - $gateway = isset( $_REQUEST['wpi-gateway'] ) ? $_REQUEST['wpi-gateway'] : '';  | 
                                                        |
| 78 | + $gateway = isset($_REQUEST['wpi-gateway']) ? $_REQUEST['wpi-gateway'] : '';  | 
                                                        |
| 79 | 79 | |
| 80 | - $redirect = apply_filters( 'wpinv_success_page_redirect', $redirect, $gateway, $args );  | 
                                                        |
| 81 | - wp_redirect( $redirect );  | 
                                                        |
| 80 | +    $redirect = apply_filters('wpinv_success_page_redirect', $redirect, $gateway, $args); | 
                                                        |
| 81 | + wp_redirect($redirect);  | 
                                                        |
| 82 | 82 | exit;  | 
                                                        
| 83 | 83 | }  | 
                                                        
| 84 | 84 | |
| 85 | -function wpinv_send_to_failed_page( $args = null ) { | 
                                                        |
| 85 | +function wpinv_send_to_failed_page($args = null) { | 
                                                        |
| 86 | 86 | $redirect = wpinv_get_failed_transaction_uri();  | 
                                                        
| 87 | 87 | |
| 88 | -    if ( !empty( $args ) ) { | 
                                                        |
| 88 | +    if (!empty($args)) { | 
                                                        |
| 89 | 89 | // Check for backward compatibility  | 
                                                        
| 90 | - if ( is_string( $args ) )  | 
                                                        |
| 91 | - $args = str_replace( '?', '', $args );  | 
                                                        |
| 90 | + if (is_string($args))  | 
                                                        |
| 91 | +            $args = str_replace('?', '', $args); | 
                                                        |
| 92 | 92 | |
| 93 | - $args = wp_parse_args( $args );  | 
                                                        |
| 93 | + $args = wp_parse_args($args);  | 
                                                        |
| 94 | 94 | |
| 95 | - $redirect = add_query_arg( $args, $redirect );  | 
                                                        |
| 95 | + $redirect = add_query_arg($args, $redirect);  | 
                                                        |
| 96 | 96 | }  | 
                                                        
| 97 | 97 | |
| 98 | - $gateway = isset( $_REQUEST['wpi-gateway'] ) ? $_REQUEST['wpi-gateway'] : '';  | 
                                                        |
| 98 | + $gateway = isset($_REQUEST['wpi-gateway']) ? $_REQUEST['wpi-gateway'] : '';  | 
                                                        |
| 99 | 99 | |
| 100 | - $redirect = apply_filters( 'wpinv_failed_page_redirect', $redirect, $gateway, $args );  | 
                                                        |
| 101 | - wp_redirect( $redirect );  | 
                                                        |
| 100 | +    $redirect = apply_filters('wpinv_failed_page_redirect', $redirect, $gateway, $args); | 
                                                        |
| 101 | + wp_redirect($redirect);  | 
                                                        |
| 102 | 102 | exit;  | 
                                                        
| 103 | 103 | }  | 
                                                        
| 104 | 104 | |
| 105 | -function wpinv_get_checkout_uri( $args = array() ) { | 
                                                        |
| 106 | - $uri = wpinv_get_option( 'checkout_page', false );  | 
                                                        |
| 107 | - $uri = isset( $uri ) ? get_permalink( $uri ) : NULL;  | 
                                                        |
| 105 | +function wpinv_get_checkout_uri($args = array()) { | 
                                                        |
| 106 | +	$uri = wpinv_get_option('checkout_page', false); | 
                                                        |
| 107 | + $uri = isset($uri) ? get_permalink($uri) : NULL;  | 
                                                        |
| 108 | 108 | |
| 109 | -	if ( !empty( $args ) ) { | 
                                                        |
| 109 | +	if (!empty($args)) { | 
                                                        |
| 110 | 110 | // Check for backward compatibility  | 
                                                        
| 111 | - if ( is_string( $args ) )  | 
                                                        |
| 112 | - $args = str_replace( '?', '', $args );  | 
                                                        |
| 111 | + if (is_string($args))  | 
                                                        |
| 112 | +			$args = str_replace('?', '', $args); | 
                                                        |
| 113 | 113 | |
| 114 | - $args = wp_parse_args( $args );  | 
                                                        |
| 114 | + $args = wp_parse_args($args);  | 
                                                        |
| 115 | 115 | |
| 116 | - $uri = add_query_arg( $args, $uri );  | 
                                                        |
| 116 | + $uri = add_query_arg($args, $uri);  | 
                                                        |
| 117 | 117 | }  | 
                                                        
| 118 | 118 | |
| 119 | - $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin';  | 
                                                        |
| 119 | +	$scheme = defined('FORCE_SSL_ADMIN') && FORCE_SSL_ADMIN ? 'https' : 'admin'; | 
                                                        |
| 120 | 120 | |
| 121 | - $ajax_url = admin_url( 'admin-ajax.php', $scheme );  | 
                                                        |
| 121 | +	$ajax_url = admin_url('admin-ajax.php', $scheme); | 
                                                        |
| 122 | 122 | |
| 123 | -	if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) { | 
                                                        |
| 124 | - $uri = preg_replace( '/^http:/', 'https:', $uri );  | 
                                                        |
| 123 | +	if ((!preg_match('/^https/', $uri) && preg_match('/^https/', $ajax_url)) || wpinv_is_ssl_enforced()) { | 
                                                        |
| 124 | +		$uri = preg_replace('/^http:/', 'https:', $uri); | 
                                                        |
| 125 | 125 | }  | 
                                                        
| 126 | 126 | |
| 127 | - return apply_filters( 'wpinv_get_checkout_uri', $uri );  | 
                                                        |
| 127 | +	return apply_filters('wpinv_get_checkout_uri', $uri); | 
                                                        |
| 128 | 128 | }  | 
                                                        
| 129 | 129 | |
| 130 | -function wpinv_send_back_to_checkout( $args = array() ) { | 
                                                        |
| 130 | +function wpinv_send_back_to_checkout($args = array()) { | 
                                                        |
| 131 | 131 | $redirect = wpinv_get_checkout_uri();  | 
                                                        
| 132 | 132 | |
| 133 | -	if ( ! empty( $args ) ) { | 
                                                        |
| 133 | +	if (!empty($args)) { | 
                                                        |
| 134 | 134 | // Check for backward compatibility  | 
                                                        
| 135 | - if ( is_string( $args ) )  | 
                                                        |
| 136 | - $args = str_replace( '?', '', $args );  | 
                                                        |
| 135 | + if (is_string($args))  | 
                                                        |
| 136 | +			$args = str_replace('?', '', $args); | 
                                                        |
| 137 | 137 | |
| 138 | - $args = wp_parse_args( $args );  | 
                                                        |
| 138 | + $args = wp_parse_args($args);  | 
                                                        |
| 139 | 139 | |
| 140 | - $redirect = add_query_arg( $args, $redirect );  | 
                                                        |
| 140 | + $redirect = add_query_arg($args, $redirect);  | 
                                                        |
| 141 | 141 | }  | 
                                                        
| 142 | 142 | |
| 143 | - wp_redirect( apply_filters( 'wpinv_send_back_to_checkout', $redirect, $args ) );  | 
                                                        |
| 143 | +	wp_redirect(apply_filters('wpinv_send_back_to_checkout', $redirect, $args)); | 
                                                        |
| 144 | 144 | exit;  | 
                                                        
| 145 | 145 | }  | 
                                                        
| 146 | 146 | |
| 147 | -function wpinv_get_success_page_url( $query_string = null ) { | 
                                                        |
| 148 | - $success_page = wpinv_get_option( 'success_page', 0 );  | 
                                                        |
| 149 | - $success_page = get_permalink( $success_page );  | 
                                                        |
| 147 | +function wpinv_get_success_page_url($query_string = null) { | 
                                                        |
| 148 | +	$success_page = wpinv_get_option('success_page', 0); | 
                                                        |
| 149 | + $success_page = get_permalink($success_page);  | 
                                                        |
| 150 | 150 | |
| 151 | - if ( $query_string )  | 
                                                        |
| 151 | + if ($query_string)  | 
                                                        |
| 152 | 152 | $success_page .= $query_string;  | 
                                                        
| 153 | 153 | |
| 154 | - return apply_filters( 'wpinv_success_page_url', $success_page );  | 
                                                        |
| 154 | +	return apply_filters('wpinv_success_page_url', $success_page); | 
                                                        |
| 155 | 155 | }  | 
                                                        
| 156 | 156 | |
| 157 | -function wpinv_get_failed_transaction_uri( $extras = false ) { | 
                                                        |
| 158 | - $uri = wpinv_get_option( 'failure_page', '' );  | 
                                                        |
| 159 | - $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url();  | 
                                                        |
| 157 | +function wpinv_get_failed_transaction_uri($extras = false) { | 
                                                        |
| 158 | +	$uri = wpinv_get_option('failure_page', ''); | 
                                                        |
| 159 | + $uri = !empty($uri) ? trailingslashit(get_permalink($uri)) : home_url();  | 
                                                        |
| 160 | 160 | |
| 161 | - if ( $extras )  | 
                                                        |
| 161 | + if ($extras)  | 
                                                        |
| 162 | 162 | $uri .= $extras;  | 
                                                        
| 163 | 163 | |
| 164 | - return apply_filters( 'wpinv_get_failed_transaction_uri', $uri );  | 
                                                        |
| 164 | +	return apply_filters('wpinv_get_failed_transaction_uri', $uri); | 
                                                        |
| 165 | 165 | }  | 
                                                        
| 166 | 166 | |
| 167 | 167 |  function wpinv_is_failed_transaction_page() { | 
                                                        
| 168 | - $ret = wpinv_get_option( 'failure_page', false );  | 
                                                        |
| 169 | - $ret = isset( $ret ) ? is_page( $ret ) : false;  | 
                                                        |
| 168 | +	$ret = wpinv_get_option('failure_page', false); | 
                                                        |
| 169 | + $ret = isset($ret) ? is_page($ret) : false;  | 
                                                        |
| 170 | 170 | |
| 171 | - return apply_filters( 'wpinv_is_failure_page', $ret );  | 
                                                        |
| 171 | +	return apply_filters('wpinv_is_failure_page', $ret); | 
                                                        |
| 172 | 172 | }  | 
                                                        
| 173 | 173 | |
| 174 | -function wpinv_transaction_query( $type = 'start' ) { | 
                                                        |
| 174 | +function wpinv_transaction_query($type = 'start') { | 
                                                        |
| 175 | 175 | global $wpdb;  | 
                                                        
| 176 | 176 | |
| 177 | 177 | $wpdb->hide_errors();  | 
                                                        
| 178 | 178 | |
| 179 | -    if ( ! defined( 'WPINV_USE_TRANSACTIONS' ) ) { | 
                                                        |
| 180 | - define( 'WPINV_USE_TRANSACTIONS', true );  | 
                                                        |
| 179 | +    if (!defined('WPINV_USE_TRANSACTIONS')) { | 
                                                        |
| 180 | +        define('WPINV_USE_TRANSACTIONS', true); | 
                                                        |
| 181 | 181 | }  | 
                                                        
| 182 | 182 | |
| 183 | -    if ( WPINV_USE_TRANSACTIONS ) { | 
                                                        |
| 184 | -        switch ( $type ) { | 
                                                        |
| 183 | +    if (WPINV_USE_TRANSACTIONS) { | 
                                                        |
| 184 | +        switch ($type) { | 
                                                        |
| 185 | 185 | case 'commit' :  | 
                                                        
| 186 | - $wpdb->query( 'COMMIT' );  | 
                                                        |
| 186 | +                $wpdb->query('COMMIT'); | 
                                                        |
| 187 | 187 | break;  | 
                                                        
| 188 | 188 | case 'rollback' :  | 
                                                        
| 189 | - $wpdb->query( 'ROLLBACK' );  | 
                                                        |
| 189 | +                $wpdb->query('ROLLBACK'); | 
                                                        |
| 190 | 190 | break;  | 
                                                        
| 191 | 191 | default :  | 
                                                        
| 192 | - $wpdb->query( 'START TRANSACTION' );  | 
                                                        |
| 192 | +                $wpdb->query('START TRANSACTION'); | 
                                                        |
| 193 | 193 | break;  | 
                                                        
| 194 | 194 | }  | 
                                                        
| 195 | 195 | }  | 
                                                        
| 196 | 196 | }  | 
                                                        
| 197 | 197 | |
| 198 | -function wpinv_create_invoice( $args = array(), $data = array(), $wp_error = false ) { | 
                                                        |
| 198 | +function wpinv_create_invoice($args = array(), $data = array(), $wp_error = false) { | 
                                                        |
| 199 | 199 | $default_args = array(  | 
                                                        
| 200 | 200 | 'status' => '',  | 
                                                        
| 201 | 201 | 'user_id' => null,  | 
                                                        
@@ -205,72 +205,72 @@ discard block  | 
                                                    ||
| 205 | 205 | 'parent' => 0  | 
                                                        
| 206 | 206 | );  | 
                                                        
| 207 | 207 | |
| 208 | - $args = wp_parse_args( $args, $default_args );  | 
                                                        |
| 208 | + $args = wp_parse_args($args, $default_args);  | 
                                                        |
| 209 | 209 | $invoice_data = array();  | 
                                                        
| 210 | 210 | |
| 211 | -    if ( $args['invoice_id'] > 0 ) { | 
                                                        |
| 212 | - $updating = true;  | 
                                                        |
| 211 | +    if ($args['invoice_id'] > 0) { | 
                                                        |
| 212 | + $updating = true;  | 
                                                        |
| 213 | 213 | $invoice_data['post_type'] = 'wpi_invoice';  | 
                                                        
| 214 | 214 | $invoice_data['ID'] = $args['invoice_id'];  | 
                                                        
| 215 | 215 |      } else { | 
                                                        
| 216 | 216 | $updating = false;  | 
                                                        
| 217 | 217 | $invoice_data['post_type'] = 'wpi_invoice';  | 
                                                        
| 218 | - $invoice_data['post_status'] = apply_filters( 'wpinv_default_invoice_status', 'pending' );  | 
                                                        |
| 218 | +        $invoice_data['post_status']    = apply_filters('wpinv_default_invoice_status', 'pending'); | 
                                                        |
| 219 | 219 | $invoice_data['ping_status'] = 'closed';  | 
                                                        
| 220 | - $invoice_data['post_author'] = !empty( $args['user_id'] ) ? $args['user_id'] : get_current_user_id();  | 
                                                        |
| 221 | - $invoice_data['post_title'] = wpinv_format_invoice_number( '0' );  | 
                                                        |
| 222 | - $invoice_data['post_parent'] = absint( $args['parent'] );  | 
                                                        |
| 223 | -        if ( !empty( $args['created_date'] ) ) { | 
                                                        |
| 220 | + $invoice_data['post_author'] = !empty($args['user_id']) ? $args['user_id'] : get_current_user_id();  | 
                                                        |
| 221 | +        $invoice_data['post_title']     = wpinv_format_invoice_number('0'); | 
                                                        |
| 222 | + $invoice_data['post_parent'] = absint($args['parent']);  | 
                                                        |
| 223 | +        if (!empty($args['created_date'])) { | 
                                                        |
| 224 | 224 | $invoice_data['post_date'] = $args['created_date'];  | 
                                                        
| 225 | - $invoice_data['post_date_gmt'] = get_gmt_from_date( $args['created_date'] );  | 
                                                        |
| 225 | + $invoice_data['post_date_gmt'] = get_gmt_from_date($args['created_date']);  | 
                                                        |
| 226 | 226 | }  | 
                                                        
| 227 | 227 | }  | 
                                                        
| 228 | 228 | |
| 229 | -    if ( $args['status'] ) { | 
                                                        |
| 230 | -        if ( ! in_array( $args['status'], array_keys( wpinv_get_invoice_statuses() ) ) ) { | 
                                                        |
| 231 | - return new WP_Error( 'wpinv_invalid_invoice_status', wp_sprintf( __( 'Invalid invoice status: %s', 'invoicing' ), $args['status'] ) );  | 
                                                        |
| 229 | +    if ($args['status']) { | 
                                                        |
| 230 | +        if (!in_array($args['status'], array_keys(wpinv_get_invoice_statuses()))) { | 
                                                        |
| 231 | +            return new WP_Error('wpinv_invalid_invoice_status', wp_sprintf(__('Invalid invoice status: %s', 'invoicing'), $args['status'])); | 
                                                        |
| 232 | 232 | }  | 
                                                        
| 233 | - $invoice_data['post_status'] = $args['status'];  | 
                                                        |
| 233 | + $invoice_data['post_status'] = $args['status'];  | 
                                                        |
| 234 | 234 | }  | 
                                                        
| 235 | 235 | |
| 236 | -    if ( ! is_null( $args['user_note'] ) ) { | 
                                                        |
| 237 | - $invoice_data['post_excerpt'] = $args['user_note'];  | 
                                                        |
| 236 | +    if (!is_null($args['user_note'])) { | 
                                                        |
| 237 | + $invoice_data['post_excerpt'] = $args['user_note'];  | 
                                                        |
| 238 | 238 | }  | 
                                                        
| 239 | 239 | |
| 240 | -    if ( $updating ) { | 
                                                        |
| 241 | - $invoice_id = wp_update_post( $invoice_data, true );  | 
                                                        |
| 240 | +    if ($updating) { | 
                                                        |
| 241 | + $invoice_id = wp_update_post($invoice_data, true);  | 
                                                        |
| 242 | 242 |      } else { | 
                                                        
| 243 | - $invoice_id = wp_insert_post( apply_filters( 'wpinv_new_invoice_data', $invoice_data ), true );  | 
                                                        |
| 243 | +        $invoice_id = wp_insert_post(apply_filters('wpinv_new_invoice_data', $invoice_data), true); | 
                                                        |
| 244 | 244 | }  | 
                                                        
| 245 | 245 | |
| 246 | -    if ( is_wp_error( $invoice_id ) ) { | 
                                                        |
| 246 | +    if (is_wp_error($invoice_id)) { | 
                                                        |
| 247 | 247 | return $wp_error ? $invoice_id : 0;  | 
                                                        
| 248 | 248 |      } else { | 
                                                        
| 249 | -        if ( !$updating ) { | 
                                                        |
| 250 | - $invoice_number = wpinv_format_invoice_number( $invoice_id );  | 
                                                        |
| 249 | +        if (!$updating) { | 
                                                        |
| 250 | + $invoice_number = wpinv_format_invoice_number($invoice_id);  | 
                                                        |
| 251 | 251 | |
| 252 | - $update = array( 'ID' => $invoice_id, 'post_title' => $invoice_number, 'post_name' => sanitize_title( $invoice_number ) );  | 
                                                        |
| 253 | - wp_update_post( $update );  | 
                                                        |
| 252 | +            $update = array('ID' => $invoice_id, 'post_title' => $invoice_number, 'post_name' => sanitize_title($invoice_number)); | 
                                                        |
| 253 | + wp_update_post($update);  | 
                                                        |
| 254 | 254 | |
| 255 | - update_post_meta( $invoice_id, '_wpinv_number', $invoice_number );  | 
                                                        |
| 255 | + update_post_meta($invoice_id, '_wpinv_number', $invoice_number);  | 
                                                        |
| 256 | 256 | }  | 
                                                        
| 257 | 257 | }  | 
                                                        
| 258 | 258 | |
| 259 | - $invoice = wpinv_get_invoice( $invoice_id );  | 
                                                        |
| 260 | -  | 
                                                        |
| 261 | -    if ( !$updating ) { | 
                                                        |
| 262 | - update_post_meta( $invoice_id, '_wpinv_key', apply_filters( 'wpinv_generate_invoice_key', uniqid( 'wpinv_' ) ) );  | 
                                                        |
| 263 | - update_post_meta( $invoice_id, '_wpinv_currency', wpinv_get_currency() );  | 
                                                        |
| 264 | - update_post_meta( $invoice_id, '_wpinv_include_tax', get_option( 'wpinv_prices_include_tax' ) );  | 
                                                        |
| 265 | - update_post_meta( $invoice_id, '_wpinv_user_ip', wpinv_get_ip() );  | 
                                                        |
| 266 | - update_post_meta( $invoice_id, '_wpinv_user_agent', wpinv_get_user_agent() );  | 
                                                        |
| 267 | - update_post_meta( $invoice_id, '_wpinv_created_via', sanitize_text_field( $args['created_via'] ) );  | 
                                                        |
| 259 | + $invoice = wpinv_get_invoice($invoice_id);  | 
                                                        |
| 260 | +  | 
                                                        |
| 261 | +    if (!$updating) { | 
                                                        |
| 262 | +        update_post_meta($invoice_id, '_wpinv_key', apply_filters('wpinv_generate_invoice_key', uniqid('wpinv_'))); | 
                                                        |
| 263 | + update_post_meta($invoice_id, '_wpinv_currency', wpinv_get_currency());  | 
                                                        |
| 264 | +        update_post_meta($invoice_id, '_wpinv_include_tax', get_option('wpinv_prices_include_tax')); | 
                                                        |
| 265 | + update_post_meta($invoice_id, '_wpinv_user_ip', wpinv_get_ip());  | 
                                                        |
| 266 | + update_post_meta($invoice_id, '_wpinv_user_agent', wpinv_get_user_agent());  | 
                                                        |
| 267 | + update_post_meta($invoice_id, '_wpinv_created_via', sanitize_text_field($args['created_via']));  | 
                                                        |
| 268 | 268 | |
| 269 | 269 | // Add invoice note  | 
                                                        
| 270 | - $invoice->add_note( wp_sprintf( __( 'Invoice is created with status %s.', 'invoicing' ), wpinv_status_nicename( $invoice->status ) ) );  | 
                                                        |
| 270 | +        $invoice->add_note(wp_sprintf(__('Invoice is created with status %s.', 'invoicing'), wpinv_status_nicename($invoice->status))); | 
                                                        |
| 271 | 271 | }  | 
                                                        
| 272 | 272 | |
| 273 | - update_post_meta( $invoice_id, '_wpinv_version', WPINV_VERSION );  | 
                                                        |
| 273 | + update_post_meta($invoice_id, '_wpinv_version', WPINV_VERSION);  | 
                                                        |
| 274 | 274 | |
| 275 | 275 | return $invoice;  | 
                                                        
| 276 | 276 | }  | 
                                                        
@@ -278,118 +278,118 @@ discard block  | 
                                                    ||
| 278 | 278 |  function wpinv_get_prefix() { | 
                                                        
| 279 | 279 | $invoice_prefix = 'INV-';  | 
                                                        
| 280 | 280 | |
| 281 | - return apply_filters( 'wpinv_get_prefix', $invoice_prefix );  | 
                                                        |
| 281 | +    return apply_filters('wpinv_get_prefix', $invoice_prefix); | 
                                                        |
| 282 | 282 | }  | 
                                                        
| 283 | 283 | |
| 284 | 284 |  function wpinv_get_business_logo() { | 
                                                        
| 285 | - $business_logo = wpinv_get_option( 'logo' );  | 
                                                        |
| 286 | - return apply_filters( 'wpinv_get_business_logo', $business_logo );  | 
                                                        |
| 285 | +    $business_logo = wpinv_get_option('logo'); | 
                                                        |
| 286 | +    return apply_filters('wpinv_get_business_logo', $business_logo); | 
                                                        |
| 287 | 287 | }  | 
                                                        
| 288 | 288 | |
| 289 | 289 |  function wpinv_get_business_name() { | 
                                                        
| 290 | 290 |      $business_name = wpinv_get_option('store_name'); | 
                                                        
| 291 | - return apply_filters( 'wpinv_get_business_name', $business_name );  | 
                                                        |
| 291 | +    return apply_filters('wpinv_get_business_name', $business_name); | 
                                                        |
| 292 | 292 | }  | 
                                                        
| 293 | 293 | |
| 294 | 294 |  function wpinv_get_blogname() { | 
                                                        
| 295 | - return wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );  | 
                                                        |
| 295 | +    return wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); | 
                                                        |
| 296 | 296 | }  | 
                                                        
| 297 | 297 | |
| 298 | 298 |  function wpinv_get_admin_email() { | 
                                                        
| 299 | - $admin_email = get_option( 'admin_email' );  | 
                                                        |
| 300 | - return apply_filters( 'wpinv_admin_email', $admin_email );  | 
                                                        |
| 299 | +    $admin_email = get_option('admin_email'); | 
                                                        |
| 300 | +    return apply_filters('wpinv_admin_email', $admin_email); | 
                                                        |
| 301 | 301 | }  | 
                                                        
| 302 | 302 | |
| 303 | 303 |  function wpinv_get_business_website() { | 
                                                        
| 304 | - $business_website = home_url( '/' );  | 
                                                        |
| 305 | - return apply_filters( 'wpinv_get_business_website', $business_website );  | 
                                                        |
| 304 | +    $business_website = home_url('/'); | 
                                                        |
| 305 | +    return apply_filters('wpinv_get_business_website', $business_website); | 
                                                        |
| 306 | 306 | }  | 
                                                        
| 307 | 307 | |
| 308 | -function wpinv_get_terms_text( $invoice_id = 0 ) { | 
                                                        |
| 308 | +function wpinv_get_terms_text($invoice_id = 0) { | 
                                                        |
| 309 | 309 | $terms_text = '';  | 
                                                        
| 310 | - return apply_filters( 'wpinv_get_terms_text', $terms_text, $invoice_id );  | 
                                                        |
| 310 | +    return apply_filters('wpinv_get_terms_text', $terms_text, $invoice_id); | 
                                                        |
| 311 | 311 | }  | 
                                                        
| 312 | 312 | |
| 313 | 313 |  function wpinv_get_business_footer() { | 
                                                        
| 314 | - $site_link = '<a target="_blank" href="' . esc_url( wpinv_get_business_website() ) . '">' . esc_html( wpinv_get_business_name() ) . '</a>';  | 
                                                        |
| 315 | - $business_footer = wp_sprintf( __( 'Thanks for using %s', 'invoicing' ), $site_link );  | 
                                                        |
| 316 | - return apply_filters( 'wpinv_get_business_footer', $business_footer );  | 
                                                        |
| 314 | + $site_link = '<a target="_blank" href="' . esc_url(wpinv_get_business_website()) . '">' . esc_html(wpinv_get_business_name()) . '</a>';  | 
                                                        |
| 315 | +    $business_footer = wp_sprintf(__('Thanks for using %s', 'invoicing'), $site_link); | 
                                                        |
| 316 | +    return apply_filters('wpinv_get_business_footer', $business_footer); | 
                                                        |
| 317 | 317 | }  | 
                                                        
| 318 | 318 | |
| 319 | 319 |  function wpinv_checkout_required_fields() { | 
                                                        
| 320 | 320 | $required_fields = array();  | 
                                                        
| 321 | 321 | |
| 322 | 322 | // Let payment gateways and other extensions determine if address fields should be required  | 
                                                        
| 323 | - $require_billing_details = apply_filters( 'wpinv_checkout_required_billing_details', wpinv_use_taxes() );  | 
                                                        |
| 323 | +    $require_billing_details = apply_filters('wpinv_checkout_required_billing_details', wpinv_use_taxes()); | 
                                                        |
| 324 | 324 | |
| 325 | -    if ( $require_billing_details ) { | 
                                                        |
| 325 | +    if ($require_billing_details) { | 
                                                        |
| 326 | 326 | ///$required_fields['email'] = array(  | 
                                                        
| 327 | 327 | ///'error_id' => 'invalid_email',  | 
                                                        
| 328 | 328 | ///'error_message' => __( 'Please enter a valid email address', 'invoicing' )  | 
                                                        
| 329 | 329 | ///);  | 
                                                        
| 330 | 330 | $required_fields['first_name'] = array(  | 
                                                        
| 331 | 331 | 'error_id' => 'invalid_first_name',  | 
                                                        
| 332 | - 'error_message' => __( 'Please enter your first name', 'invoicing' )  | 
                                                        |
| 332 | +                'error_message' => __('Please enter your first name', 'invoicing') | 
                                                        |
| 333 | 333 | );  | 
                                                        
| 334 | 334 | $required_fields['address'] = array(  | 
                                                        
| 335 | 335 | 'error_id' => 'invalid_address',  | 
                                                        
| 336 | - 'error_message' => __( 'Please enter your address', 'invoicing' )  | 
                                                        |
| 336 | +                'error_message' => __('Please enter your address', 'invoicing') | 
                                                        |
| 337 | 337 | );  | 
                                                        
| 338 | 338 | $required_fields['city'] = array(  | 
                                                        
| 339 | 339 | 'error_id' => 'invalid_city',  | 
                                                        
| 340 | - 'error_message' => __( 'Please enter your billing city', 'invoicing' )  | 
                                                        |
| 340 | +                'error_message' => __('Please enter your billing city', 'invoicing') | 
                                                        |
| 341 | 341 | );  | 
                                                        
| 342 | 342 | $required_fields['state'] = array(  | 
                                                        
| 343 | 343 | 'error_id' => 'invalid_state',  | 
                                                        
| 344 | - 'error_message' => __( 'Please enter billing state / province', 'invoicing' )  | 
                                                        |
| 344 | +                'error_message' => __('Please enter billing state / province', 'invoicing') | 
                                                        |
| 345 | 345 | );  | 
                                                        
| 346 | 346 | $required_fields['country'] = array(  | 
                                                        
| 347 | 347 | 'error_id' => 'invalid_country',  | 
                                                        
| 348 | - 'error_message' => __( 'Please select your billing country', 'invoicing' )  | 
                                                        |
| 348 | +                'error_message' => __('Please select your billing country', 'invoicing') | 
                                                        |
| 349 | 349 | );  | 
                                                        
| 350 | 350 | }  | 
                                                        
| 351 | 351 | |
| 352 | - return apply_filters( 'wpinv_checkout_required_fields', $required_fields );  | 
                                                        |
| 352 | +    return apply_filters('wpinv_checkout_required_fields', $required_fields); | 
                                                        |
| 353 | 353 | }  | 
                                                        
| 354 | 354 | |
| 355 | 355 |  function wpinv_is_ssl_enforced() { | 
                                                        
| 356 | - $ssl_enforced = wpinv_get_option( 'enforce_ssl', false );  | 
                                                        |
| 357 | - return (bool) apply_filters( 'wpinv_is_ssl_enforced', $ssl_enforced );  | 
                                                        |
| 356 | +    $ssl_enforced = wpinv_get_option('enforce_ssl', false); | 
                                                        |
| 357 | +    return (bool)apply_filters('wpinv_is_ssl_enforced', $ssl_enforced); | 
                                                        |
| 358 | 358 | }  | 
                                                        
| 359 | 359 | |
| 360 | -function wpinv_user_can_print_invoice( $post ) { | 
                                                        |
| 360 | +function wpinv_user_can_print_invoice($post) { | 
                                                        |
| 361 | 361 | $allow = false;  | 
                                                        
| 362 | 362 | |
| 363 | -    if ( !( $user_id = get_current_user_id() ) ) { | 
                                                        |
| 363 | +    if (!($user_id = get_current_user_id())) { | 
                                                        |
| 364 | 364 | return $allow;  | 
                                                        
| 365 | 365 | }  | 
                                                        
| 366 | 366 | |
| 367 | -    if ( is_int( $post ) ) { | 
                                                        |
| 368 | - $post = get_post( $post );  | 
                                                        |
| 367 | +    if (is_int($post)) { | 
                                                        |
| 368 | + $post = get_post($post);  | 
                                                        |
| 369 | 369 | }  | 
                                                        
| 370 | 370 | |
| 371 | 371 | // Allow to owner.  | 
                                                        
| 372 | -    if ( is_object( $post ) && !empty( $post->post_author ) && $post->post_author == $user_id ) { | 
                                                        |
| 372 | +    if (is_object($post) && !empty($post->post_author) && $post->post_author == $user_id) { | 
                                                        |
| 373 | 373 | $allow = true;  | 
                                                        
| 374 | 374 | }  | 
                                                        
| 375 | 375 | |
| 376 | 376 | // Allow to admin user.  | 
                                                        
| 377 | -    if ( current_user_can( 'manage_options' ) ) { | 
                                                        |
| 377 | +    if (current_user_can('manage_options')) { | 
                                                        |
| 378 | 378 | $allow = true;  | 
                                                        
| 379 | 379 | }  | 
                                                        
| 380 | 380 | |
| 381 | - return apply_filters( 'wpinv_can_print_invoice', $allow, $post );  | 
                                                        |
| 381 | +    return apply_filters('wpinv_can_print_invoice', $allow, $post); | 
                                                        |
| 382 | 382 | }  | 
                                                        
| 383 | 383 | |
| 384 | 384 |  function wpinv_schedule_events() { | 
                                                        
| 385 | 385 | // hourly, daily and twicedaily  | 
                                                        
| 386 | -    if ( !wp_next_scheduled( 'wpinv_register_schedule_event_twicedaily' ) ) { | 
                                                        |
| 387 | - wp_schedule_event( current_time( 'timestamp' ), 'twicedaily', 'wpinv_register_schedule_event_twicedaily' );  | 
                                                        |
| 386 | +    if (!wp_next_scheduled('wpinv_register_schedule_event_twicedaily')) { | 
                                                        |
| 387 | +        wp_schedule_event(current_time('timestamp'), 'twicedaily', 'wpinv_register_schedule_event_twicedaily'); | 
                                                        |
| 388 | 388 | }  | 
                                                        
| 389 | 389 | }  | 
                                                        
| 390 | -add_action( 'wp', 'wpinv_schedule_events' );  | 
                                                        |
| 390 | +add_action('wp', 'wpinv_schedule_events'); | 
                                                        |
| 391 | 391 | |
| 392 | 392 |  function wpinv_schedule_event_twicedaily() { | 
                                                        
| 393 | 393 | wpinv_email_payment_reminders();  | 
                                                        
| 394 | 394 | }  | 
                                                        
| 395 | -add_action( 'wpinv_register_schedule_event_twicedaily', 'wpinv_schedule_event_twicedaily' );  | 
                                                        |
| 396 | 395 | \ No newline at end of file  | 
                                                        
| 396 | +add_action('wpinv_register_schedule_event_twicedaily', 'wpinv_schedule_event_twicedaily'); | 
                                                        |
| 397 | 397 | \ No newline at end of file  | 
                                                        
@@ -1,5 +1,5 @@ discard block  | 
                                                    ||
| 1 | 1 | <?php  | 
                                                        
| 2 | -if ( ! defined( 'ABSPATH' ) ) { | 
                                                        |
| 2 | +if (!defined('ABSPATH')) { | 
                                                        |
| 3 | 3 | exit; // Exit if accessed directly  | 
                                                        
| 4 | 4 | }  | 
                                                        
| 5 | 5 | |
@@ -14,73 +14,73 @@ discard block  | 
                                                    ||
| 14 | 14 | }  | 
                                                        
| 15 | 15 | |
| 16 | 16 |      public function init() { | 
                                                        
| 17 | - do_action( 'wpinv_class_notes_init', $this );  | 
                                                        |
| 17 | +        do_action('wpinv_class_notes_init', $this); | 
                                                        |
| 18 | 18 | }  | 
                                                        
| 19 | 19 | |
| 20 | 20 |      public function includes() { | 
                                                        
| 21 | - do_action( 'wpinv_class_notes_includes', $this );  | 
                                                        |
| 21 | +        do_action('wpinv_class_notes_includes', $this); | 
                                                        |
| 22 | 22 | }  | 
                                                        
| 23 | 23 | |
| 24 | 24 |      public function actions() { | 
                                                        
| 25 | 25 | // Secure inovice notes  | 
                                                        
| 26 | - add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 );  | 
                                                        |
| 26 | +        add_action('pre_get_comments', array($this, 'set_invoice_note_type'), 11, 1); | 
                                                        |
| 27 | 27 | |
| 28 | 28 | // Count comments  | 
                                                        
| 29 | - add_filter( 'wp_count_comments', array( $this, 'wp_count_comments' ), 11, 2 );  | 
                                                        |
| 29 | +        add_filter('wp_count_comments', array($this, 'wp_count_comments'), 11, 2); | 
                                                        |
| 30 | 30 | |
| 31 | 31 | // Delete comments count cache whenever there is a new comment or a comment status changes  | 
                                                        
| 32 | - add_action( 'wp_insert_comment', array( $this, 'delete_comments_count_cache' ) );  | 
                                                        |
| 33 | - add_action( 'wp_set_comment_status', array( $this, 'delete_comments_count_cache' ) );  | 
                                                        |
| 32 | +        add_action('wp_insert_comment', array($this, 'delete_comments_count_cache')); | 
                                                        |
| 33 | +        add_action('wp_set_comment_status', array($this, 'delete_comments_count_cache')); | 
                                                        |
| 34 | 34 | |
| 35 | - do_action( 'wpinv_class_notes_actions', $this );  | 
                                                        |
| 35 | +        do_action('wpinv_class_notes_actions', $this); | 
                                                        |
| 36 | 36 | }  | 
                                                        
| 37 | 37 | |
| 38 | -    public function set_invoice_note_type( $query ) { | 
                                                        |
| 39 | - $post_ID = !empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id'];  | 
                                                        |
| 38 | +    public function set_invoice_note_type($query) { | 
                                                        |
| 39 | + $post_ID = !empty($query->query_vars['post_ID']) ? $query->query_vars['post_ID'] : $query->query_vars['post_id'];  | 
                                                        |
| 40 | 40 | |
| 41 | -        if ( $post_ID && get_post_type( $post_ID ) == $this->invoice_post_type ) { | 
                                                        |
| 41 | +        if ($post_ID && get_post_type($post_ID) == $this->invoice_post_type) { | 
                                                        |
| 42 | 42 | $query->query_vars['type__in'] = $this->comment_type;  | 
                                                        
| 43 | 43 | $query->query_vars['type__not_in'] = '';  | 
                                                        
| 44 | 44 |          } else {         | 
                                                        
| 45 | -            if ( isset( $query->query_vars['type__in'] ) && $type_in = $query->query_vars['type__in'] ) { | 
                                                        |
| 46 | -                if ( is_array( $type_in ) && in_array( $this->comment_type, $type_in ) ) { | 
                                                        |
| 47 | - $key = array_search( $this->comment_type, $type_in );  | 
                                                        |
| 48 | - unset( $query->query_vars['type__in'][$key] );  | 
                                                        |
| 49 | -                } else if ( !is_array( $type_in ) && $type_in == $this->comment_type ) { | 
                                                        |
| 45 | +            if (isset($query->query_vars['type__in']) && $type_in = $query->query_vars['type__in']) { | 
                                                        |
| 46 | +                if (is_array($type_in) && in_array($this->comment_type, $type_in)) { | 
                                                        |
| 47 | + $key = array_search($this->comment_type, $type_in);  | 
                                                        |
| 48 | + unset($query->query_vars['type__in'][$key]);  | 
                                                        |
| 49 | +                } else if (!is_array($type_in) && $type_in == $this->comment_type) { | 
                                                        |
| 50 | 50 | $query->query_vars['type__in'] = '';  | 
                                                        
| 51 | 51 | }  | 
                                                        
| 52 | 52 | }  | 
                                                        
| 53 | 53 | |
| 54 | -            if ( isset( $query->query_vars['type__not_in'] ) && $type_not_in = $query->query_vars['type__not_in'] ) { | 
                                                        |
| 55 | -                if ( is_array( $type_not_in ) && !in_array( $this->comment_type, $type_not_in ) ) { | 
                                                        |
| 54 | +            if (isset($query->query_vars['type__not_in']) && $type_not_in = $query->query_vars['type__not_in']) { | 
                                                        |
| 55 | +                if (is_array($type_not_in) && !in_array($this->comment_type, $type_not_in)) { | 
                                                        |
| 56 | 56 | $query->query_vars['type__not_in'][] = $this->comment_type;  | 
                                                        
| 57 | -                } else if ( !is_array( $type_not_in ) && $type_not_in != $this->comment_type ) { | 
                                                        |
| 57 | +                } else if (!is_array($type_not_in) && $type_not_in != $this->comment_type) { | 
                                                        |
| 58 | 58 | $query->query_vars['type__not_in'] = (array)$query->query_vars['type__not_in'];  | 
                                                        
| 59 | 59 | $query->query_vars['type__not_in'][] = $this->comment_type;  | 
                                                        
| 60 | 60 | }  | 
                                                        
| 61 | 61 |              } else { | 
                                                        
| 62 | - $query->query_vars['type__not_in'] = $this->comment_type;  | 
                                                        |
| 62 | + $query->query_vars['type__not_in'] = $this->comment_type;  | 
                                                        |
| 63 | 63 | }  | 
                                                        
| 64 | 64 | }  | 
                                                        
| 65 | 65 | |
| 66 | 66 | return $query;  | 
                                                        
| 67 | 67 | }  | 
                                                        
| 68 | 68 | |
| 69 | -    public function get_invoice_notes( $invoice_id = 0, $type = '' ) { | 
                                                        |
| 69 | +    public function get_invoice_notes($invoice_id = 0, $type = '') { | 
                                                        |
| 70 | 70 | $args = array(  | 
                                                        
| 71 | 71 | 'post_id' => $invoice_id,  | 
                                                        
| 72 | 72 | 'orderby' => 'comment_ID',  | 
                                                        
| 73 | 73 | 'order' => 'DESC',  | 
                                                        
| 74 | 74 | );  | 
                                                        
| 75 | 75 | |
| 76 | -        if ( $type == 'customer' ) { | 
                                                        |
| 76 | +        if ($type == 'customer') { | 
                                                        |
| 77 | 77 | $args['meta_key'] = '_wpi_customer_note';  | 
                                                        
| 78 | 78 | $args['meta_value'] = 1;  | 
                                                        
| 79 | 79 | }  | 
                                                        
| 80 | 80 | |
| 81 | - $args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type );  | 
                                                        |
| 81 | +        $args = apply_filters('wpinv_invoice_notes_args', $args, $this, $invoice_id, $type); | 
                                                        |
| 82 | 82 | |
| 83 | - return get_comments( $args );  | 
                                                        |
| 83 | + return get_comments($args);  | 
                                                        |
| 84 | 84 | }  | 
                                                        
| 85 | 85 | |
| 86 | 86 | /**  | 
                                                        
@@ -91,7 +91,7 @@ discard block  | 
                                                    ||
| 91 | 91 | * @return void  | 
                                                        
| 92 | 92 | */  | 
                                                        
| 93 | 93 |      public function delete_comments_count_cache() { | 
                                                        
| 94 | - delete_transient( 'wpinv_count_comments' );  | 
                                                        |
| 94 | +        delete_transient('wpinv_count_comments'); | 
                                                        |
| 95 | 95 | }  | 
                                                        
| 96 | 96 | |
| 97 | 97 | /**  | 
                                                        
@@ -102,16 +102,16 @@ discard block  | 
                                                    ||
| 102 | 102 | * @param int $post_id Post ID.  | 
                                                        
| 103 | 103 | * @return object  | 
                                                        
| 104 | 104 | */  | 
                                                        
| 105 | -    public function wp_count_comments( $stats, $post_id ) { | 
                                                        |
| 105 | +    public function wp_count_comments($stats, $post_id) { | 
                                                        |
| 106 | 106 | global $wpdb;  | 
                                                        
| 107 | 107 | |
| 108 | -        if ( 0 === $post_id ) { | 
                                                        |
| 109 | - $stats = get_transient( 'wpinv_count_comments' );  | 
                                                        |
| 108 | +        if (0 === $post_id) { | 
                                                        |
| 109 | +            $stats = get_transient('wpinv_count_comments'); | 
                                                        |
| 110 | 110 | |
| 111 | -            if ( ! $stats ) { | 
                                                        |
| 111 | +            if (!$stats) { | 
                                                        |
| 112 | 112 | $stats = array();  | 
                                                        
| 113 | 113 | |
| 114 | -                $count = $wpdb->get_results( "SELECT comment_approved, COUNT(*) AS num_comments FROM {$wpdb->comments} WHERE comment_type NOT IN ('" . $this->comment_type . "') GROUP BY comment_approved", ARRAY_A ); | 
                                                        |
| 114 | +                $count = $wpdb->get_results("SELECT comment_approved, COUNT(*) AS num_comments FROM {$wpdb->comments} WHERE comment_type NOT IN ('" . $this->comment_type . "') GROUP BY comment_approved", ARRAY_A); | 
                                                        |
| 115 | 115 | |
| 116 | 116 | $total = 0;  | 
                                                        
| 117 | 117 | $approved = array(  | 
                                                        
@@ -122,26 +122,26 @@ discard block  | 
                                                    ||
| 122 | 122 | 'post-trashed' => 'post-trashed',  | 
                                                        
| 123 | 123 | );  | 
                                                        
| 124 | 124 | |
| 125 | -                foreach ( (array) $count as $row ) { | 
                                                        |
| 125 | +                foreach ((array)$count as $row) { | 
                                                        |
| 126 | 126 | // Do not count post-trashed toward totals.  | 
                                                        
| 127 | -                    if ( 'post-trashed' !== $row['comment_approved'] && 'trash' !== $row['comment_approved'] ) { | 
                                                        |
| 127 | +                    if ('post-trashed' !== $row['comment_approved'] && 'trash' !== $row['comment_approved']) { | 
                                                        |
| 128 | 128 | $total += $row['num_comments'];  | 
                                                        
| 129 | 129 | }  | 
                                                        
| 130 | -                    if ( isset( $approved[ $row['comment_approved'] ] ) ) { | 
                                                        |
| 131 | - $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments'];  | 
                                                        |
| 130 | +                    if (isset($approved[$row['comment_approved']])) { | 
                                                        |
| 131 | + $stats[$approved[$row['comment_approved']]] = $row['num_comments'];  | 
                                                        |
| 132 | 132 | }  | 
                                                        
| 133 | 133 | }  | 
                                                        
| 134 | 134 | |
| 135 | 135 | $stats['total_comments'] = $total;  | 
                                                        
| 136 | 136 | $stats['all'] = $total;  | 
                                                        
| 137 | -                foreach ( $approved as $key ) { | 
                                                        |
| 138 | -                    if ( empty( $stats[ $key ] ) ) { | 
                                                        |
| 139 | - $stats[ $key ] = 0;  | 
                                                        |
| 137 | +                foreach ($approved as $key) { | 
                                                        |
| 138 | +                    if (empty($stats[$key])) { | 
                                                        |
| 139 | + $stats[$key] = 0;  | 
                                                        |
| 140 | 140 | }  | 
                                                        
| 141 | 141 | }  | 
                                                        
| 142 | 142 | |
| 143 | - $stats = (object) $stats;  | 
                                                        |
| 144 | - set_transient( 'wpinv_count_comments', $stats );  | 
                                                        |
| 143 | + $stats = (object)$stats;  | 
                                                        |
| 144 | +                set_transient('wpinv_count_comments', $stats); | 
                                                        |
| 145 | 145 | }  | 
                                                        
| 146 | 146 | }  | 
                                                        
| 147 | 147 | |
@@ -11,37 +11,37 @@  | 
                                                    ||
| 11 | 11 | * @since 1.0.0  | 
                                                        
| 12 | 12 | */  | 
                                                        
| 13 | 13 |  function wpinv_automatic_upgrade() { | 
                                                        
| 14 | - $wpi_version = get_option( 'wpinv_version' );  | 
                                                        |
| 14 | +    $wpi_version = get_option('wpinv_version'); | 
                                                        |
| 15 | 15 | |
| 16 | -    if ( $wpi_version == WPINV_VERSION ) { | 
                                                        |
| 16 | +    if ($wpi_version == WPINV_VERSION) { | 
                                                        |
| 17 | 17 | return;  | 
                                                        
| 18 | 18 | }  | 
                                                        
| 19 | 19 | |
| 20 | -    if ( version_compare( $wpi_version, '0.0.5', '<' ) ) { | 
                                                        |
| 20 | +    if (version_compare($wpi_version, '0.0.5', '<')) { | 
                                                        |
| 21 | 21 | wpinv_v005_upgrades();  | 
                                                        
| 22 | 22 | }  | 
                                                        
| 23 | 23 | |
| 24 | - update_option( 'wpinv_version', WPINV_VERSION );  | 
                                                        |
| 24 | +    update_option('wpinv_version', WPINV_VERSION); | 
                                                        |
| 25 | 25 | }  | 
                                                        
| 26 | -add_action( 'admin_init', 'wpinv_automatic_upgrade' );  | 
                                                        |
| 26 | +add_action('admin_init', 'wpinv_automatic_upgrade'); | 
                                                        |
| 27 | 27 | |
| 28 | 28 |  function wpinv_v005_upgrades() { | 
                                                        
| 29 | 29 | global $wpdb;  | 
                                                        
| 30 | 30 | |
| 31 | 31 | // Invoices status  | 
                                                        
| 32 | - $wpdb->query( "UPDATE " . $wpdb->posts . " SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );  | 
                                                        |
| 32 | +    $wpdb->query("UPDATE " . $wpdb->posts . " SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )"); | 
                                                        |
| 33 | 33 | |
| 34 | 34 | // Item meta key changes  | 
                                                        
| 35 | 35 | $query = "SELECT DISTINCT post_id FROM " . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )";  | 
                                                        
| 36 | - $results = $wpdb->get_results( $query );  | 
                                                        |
| 36 | + $results = $wpdb->get_results($query);  | 
                                                        |
| 37 | 37 | |
| 38 | -    if ( !empty( $results ) ) { | 
                                                        |
| 39 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" );  | 
                                                        |
| 40 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" );  | 
                                                        |
| 41 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" );  | 
                                                        |
| 38 | +    if (!empty($results)) { | 
                                                        |
| 39 | +        $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )"); | 
                                                        |
| 40 | +        $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'"); | 
                                                        |
| 41 | +        $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'"); | 
                                                        |
| 42 | 42 | |
| 43 | -        foreach ( $results as $row ) { | 
                                                        |
| 44 | - clean_post_cache( $row->post_id );  | 
                                                        |
| 43 | +        foreach ($results as $row) { | 
                                                        |
| 44 | + clean_post_cache($row->post_id);  | 
                                                        |
| 45 | 45 | }  | 
                                                        
| 46 | 46 | }  | 
                                                        
| 47 | 47 | }  | 
                                                        
| 48 | 48 | \ No newline at end of file  | 
                                                        
@@ -1,22 +1,22 @@ discard block  | 
                                                    ||
| 1 | 1 | <?php  | 
                                                        
| 2 | 2 | // MUST have WordPress.  | 
                                                        
| 3 | -if ( !defined( 'WPINC' ) ) { | 
                                                        |
| 4 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );  | 
                                                        |
| 3 | +if (!defined('WPINC')) { | 
                                                        |
| 4 | +    exit('Do NOT access this file directly: ' . basename(__FILE__)); | 
                                                        |
| 5 | 5 | }  | 
                                                        
| 6 | 6 | |
| 7 | 7 |  class WPInv_Meta_Box_Items { | 
                                                        
| 8 | -    public static function output( $post ) {         | 
                                                        |
| 8 | +    public static function output($post) {         | 
                                                        |
| 9 | 9 | global $wpinv_euvat, $ajax_cart_details;  | 
                                                        
| 10 | 10 | |
| 11 | - $post_id = !empty( $post->ID ) ? $post->ID : 0;  | 
                                                        |
| 12 | - $invoice = new WPInv_Invoice( $post_id );  | 
                                                        |
| 11 | + $post_id = !empty($post->ID) ? $post->ID : 0;  | 
                                                        |
| 12 | + $invoice = new WPInv_Invoice($post_id);  | 
                                                        |
| 13 | 13 | $ajax_cart_details = $invoice->get_cart_details();  | 
                                                        
| 14 | - $subtotal = $invoice->get_subtotal( true );  | 
                                                        |
| 14 | + $subtotal = $invoice->get_subtotal(true);  | 
                                                        |
| 15 | 15 | $discount_raw = $invoice->get_discount();  | 
                                                        
| 16 | - $discount = wpinv_price( $discount_raw, $invoice->get_currency() );  | 
                                                        |
| 16 | + $discount = wpinv_price($discount_raw, $invoice->get_currency());  | 
                                                        |
| 17 | 17 | $discounts = $discount_raw > 0 ? $invoice->get_discounts() : '';  | 
                                                        
| 18 | - $tax = $invoice->get_tax( true );  | 
                                                        |
| 19 | - $total = $invoice->get_total( true );  | 
                                                        |
| 18 | + $tax = $invoice->get_tax(true);  | 
                                                        |
| 19 | + $total = $invoice->get_total(true);  | 
                                                        |
| 20 | 20 | $item_quantities = wpinv_item_quantities_enabled();  | 
                                                        
| 21 | 21 | $use_taxes = wpinv_use_taxes();  | 
                                                        
| 22 | 22 | $item_types = wpinv_get_item_types();  | 
                                                        
@@ -29,17 +29,17 @@ discard block  | 
                                                    ||
| 29 | 29 | }  | 
                                                        
| 30 | 30 | |
| 31 | 31 | $cols = 5;  | 
                                                        
| 32 | -        if ( $item_quantities ) { | 
                                                        |
| 32 | +        if ($item_quantities) { | 
                                                        |
| 33 | 33 | $cols++;  | 
                                                        
| 34 | 34 | }  | 
                                                        
| 35 | -        if ( $use_taxes ) { | 
                                                        |
| 35 | +        if ($use_taxes) { | 
                                                        |
| 36 | 36 | $cols++;  | 
                                                        
| 37 | 37 | }  | 
                                                        
| 38 | 38 | $class = '';  | 
                                                        
| 39 | -        if ( $invoice->is_paid() ) { | 
                                                        |
| 39 | +        if ($invoice->is_paid()) { | 
                                                        |
| 40 | 40 | $class .= ' wpinv-paid';  | 
                                                        
| 41 | 41 | }  | 
                                                        
| 42 | -        if ( $is_recurring ) { | 
                                                        |
| 42 | +        if ($is_recurring) { | 
                                                        |
| 43 | 43 | $class .= ' wpi-recurring';  | 
                                                        
| 44 | 44 | }  | 
                                                        
| 45 | 45 | ?>  | 
                                                        
@@ -47,21 +47,21 @@ discard block  | 
                                                    ||
| 47 | 47 | <table id="wpinv_items" class="wpinv-items" cellspacing="0" cellpadding="0">  | 
                                                        
| 48 | 48 | <thead>  | 
                                                        
| 49 | 49 | <tr>  | 
                                                        
| 50 | - <th class="id"><?php _e( 'ID', 'invoicing' );?></th>  | 
                                                        |
| 51 | - <th class="title"><?php _e( 'Item', 'invoicing' );?></th>  | 
                                                        |
| 52 | - <th class="price"><?php _e( 'Price', 'invoicing' );?></th>  | 
                                                        |
| 53 | -                        <?php if ( $item_quantities ) { ?> | 
                                                        |
| 54 | - <th class="qty"><?php _e( 'Qty', 'invoicing' );?></th>  | 
                                                        |
| 50 | +                        <th class="id"><?php _e('ID', 'invoicing'); ?></th> | 
                                                        |
| 51 | +                        <th class="title"><?php _e('Item', 'invoicing'); ?></th> | 
                                                        |
| 52 | +                        <th class="price"><?php _e('Price', 'invoicing'); ?></th> | 
                                                        |
| 53 | +                        <?php if ($item_quantities) { ?> | 
                                                        |
| 54 | +                        <th class="qty"><?php _e('Qty', 'invoicing'); ?></th> | 
                                                        |
| 55 | 55 | <?php } ?>  | 
                                                        
| 56 | - <th class="total"><?php _e( 'Total', 'invoicing' );?></th>  | 
                                                        |
| 57 | -                        <?php if ( $use_taxes ) { ?> | 
                                                        |
| 58 | - <th class="tax"><?php _e( 'Tax (%)', 'invoicing' );?></th>  | 
                                                        |
| 56 | +                        <th class="total"><?php _e('Total', 'invoicing'); ?></th> | 
                                                        |
| 57 | +                        <?php if ($use_taxes) { ?> | 
                                                        |
| 58 | +                        <th class="tax"><?php _e('Tax (%)', 'invoicing'); ?></th> | 
                                                        |
| 59 | 59 | <?php } ?>  | 
                                                        
| 60 | 60 | <th class="action"></th>  | 
                                                        
| 61 | 61 | </tr>  | 
                                                        
| 62 | 62 | </thead>  | 
                                                        
| 63 | 63 | <tbody class="wpinv-line-items">  | 
                                                        
| 64 | - <?php echo wpinv_admin_get_line_items( $invoice ); ?>  | 
                                                        |
| 64 | + <?php echo wpinv_admin_get_line_items($invoice); ?>  | 
                                                        |
| 65 | 65 | </tbody>  | 
                                                        
| 66 | 66 | <tfoot class="wpinv-totals">  | 
                                                        
| 67 | 67 | <tr>  | 
                                                        
@@ -73,44 +73,44 @@ discard block  | 
                                                    ||
| 73 | 73 | </td>  | 
                                                        
| 74 | 74 | <td class="title">  | 
                                                        
| 75 | 75 | <input type="text" class="regular-text" placeholder="Item name" value="" name="_wpinv_quick[name]">  | 
                                                        
| 76 | -                                            <?php if ( $wpinv_euvat->allow_vat_rules() ) { ?> | 
                                                        |
| 76 | +                                            <?php if ($wpinv_euvat->allow_vat_rules()) { ?> | 
                                                        |
| 77 | 77 | <div class="wp-clearfix">  | 
                                                        
| 78 | 78 | <label class="wpi-vat-rule">  | 
                                                        
| 79 | - <span class="title"><?php _e( 'VAT rule type', 'invoicing' );?></span>  | 
                                                        |
| 79 | +                                                    <span class="title"><?php _e('VAT rule type', 'invoicing'); ?></span> | 
                                                        |
| 80 | 80 | <span class="input-text-wrap">  | 
                                                        
| 81 | - <?php echo wpinv_html_select( array(  | 
                                                        |
| 81 | + <?php echo wpinv_html_select(array(  | 
                                                        |
| 82 | 82 | 'options' => $wpinv_euvat->get_rules(),  | 
                                                        
| 83 | 83 | 'name' => '_wpinv_quick[vat_rule]',  | 
                                                        
| 84 | 84 | 'id' => '_wpinv_quick_vat_rule',  | 
                                                        
| 85 | 85 | 'show_option_all' => false,  | 
                                                        
| 86 | 86 | 'show_option_none' => false,  | 
                                                        
| 87 | 87 | 'class' => 'gdmbx2-text-medium wpinv-quick-vat-rule',  | 
                                                        
| 88 | - ) ); ?>  | 
                                                        |
| 88 | + )); ?>  | 
                                                        |
| 89 | 89 | </span>  | 
                                                        
| 90 | 90 | </label>  | 
                                                        
| 91 | 91 | </div>  | 
                                                        
| 92 | -                                            <?php } if ( $wpinv_euvat->allow_vat_classes() ) { ?> | 
                                                        |
| 92 | +                                            <?php } if ($wpinv_euvat->allow_vat_classes()) { ?> | 
                                                        |
| 93 | 93 | <div class="wp-clearfix">  | 
                                                        
| 94 | 94 | <label class="wpi-vat-class">  | 
                                                        
| 95 | - <span class="title"><?php _e( 'VAT class', 'invoicing' );?></span>  | 
                                                        |
| 95 | +                                                    <span class="title"><?php _e('VAT class', 'invoicing'); ?></span> | 
                                                        |
| 96 | 96 | <span class="input-text-wrap">  | 
                                                        
| 97 | - <?php echo wpinv_html_select( array(  | 
                                                        |
| 97 | + <?php echo wpinv_html_select(array(  | 
                                                        |
| 98 | 98 | 'options' => $wpinv_euvat->get_all_classes(),  | 
                                                        
| 99 | 99 | 'name' => '_wpinv_quick[vat_class]',  | 
                                                        
| 100 | 100 | 'id' => '_wpinv_quick_vat_class',  | 
                                                        
| 101 | 101 | 'show_option_all' => false,  | 
                                                        
| 102 | 102 | 'show_option_none' => false,  | 
                                                        
| 103 | 103 | 'class' => 'gdmbx2-text-medium wpinv-quick-vat-class',  | 
                                                        
| 104 | - ) ); ?>  | 
                                                        |
| 104 | + )); ?>  | 
                                                        |
| 105 | 105 | </span>  | 
                                                        
| 106 | 106 | </label>  | 
                                                        
| 107 | 107 | </div>  | 
                                                        
| 108 | 108 | <?php } ?>  | 
                                                        
| 109 | 109 | <div class="wp-clearfix">  | 
                                                        
| 110 | 110 | <label class="wpi-item-type">  | 
                                                        
| 111 | - <span class="title"><?php _e( 'Item type', 'invoicing' );?></span>  | 
                                                        |
| 111 | +                                                    <span class="title"><?php _e('Item type', 'invoicing'); ?></span> | 
                                                        |
| 112 | 112 | <span class="input-text-wrap">  | 
                                                        
| 113 | - <?php echo wpinv_html_select( array(  | 
                                                        |
| 113 | + <?php echo wpinv_html_select(array(  | 
                                                        |
| 114 | 114 | 'options' => $item_types,  | 
                                                        
| 115 | 115 | 'name' => '_wpinv_quick[type]',  | 
                                                        
| 116 | 116 | 'id' => '_wpinv_quick_type',  | 
                                                        
@@ -118,7 +118,7 @@ discard block  | 
                                                    ||
| 118 | 118 | 'show_option_all' => false,  | 
                                                        
| 119 | 119 | 'show_option_none' => false,  | 
                                                        
| 120 | 120 | 'class' => 'gdmbx2-text-medium wpinv-quick-type',  | 
                                                        
| 121 | - ) ); ?>  | 
                                                        |
| 121 | + )); ?>  | 
                                                        |
| 122 | 122 | </span>  | 
                                                        
| 123 | 123 | </label>  | 
                                                        
| 124 | 124 | </div>  | 
                                                        
@@ -131,11 +131,11 @@ discard block  | 
                                                    ||
| 131 | 131 | </div>  | 
                                                        
| 132 | 132 | </td>  | 
                                                        
| 133 | 133 | <td class="price"><input type="text" placeholder="0.00" class="wpi-field-price wpi-price" name="_wpinv_quick[price]" /></td>  | 
                                                        
| 134 | -                                        <?php if ( $item_quantities ) { ?> | 
                                                        |
| 134 | +                                        <?php if ($item_quantities) { ?> | 
                                                        |
| 135 | 135 | <td class="qty"><input type="number" class="small-text" step="1" min="1" value="1" name="_wpinv_quick[qty]" /></td>  | 
                                                        
| 136 | 136 | <?php } ?>  | 
                                                        
| 137 | 137 | <td class="total"></td>  | 
                                                        
| 138 | -                                        <?php if ( $use_taxes ) { ?> | 
                                                        |
| 138 | +                                        <?php if ($use_taxes) { ?> | 
                                                        |
| 139 | 139 | <td class="tax"></td>  | 
                                                        
| 140 | 140 | <?php } ?>  | 
                                                        
| 141 | 141 | <td class="action"></td>  | 
                                                        
@@ -148,29 +148,29 @@ discard block  | 
                                                    ||
| 148 | 148 | <td colspan="<?php echo $cols; ?>"></td>  | 
                                                        
| 149 | 149 | </tr>  | 
                                                        
| 150 | 150 | <tr class="totals">  | 
                                                        
| 151 | - <td colspan="<?php echo ( $cols - 4 ); ?>"></td>  | 
                                                        |
| 151 | + <td colspan="<?php echo ($cols - 4); ?>"></td>  | 
                                                        |
| 152 | 152 | <td colspan="4">  | 
                                                        
| 153 | 153 | <table cellspacing="0" cellpadding="0">  | 
                                                        
| 154 | 154 | <tr class="subtotal">  | 
                                                        
| 155 | - <td class="name"><?php _e( 'Sub Total:', 'invoicing' );?></td>  | 
                                                        |
| 156 | - <td class="total"><?php echo $subtotal;?></td>  | 
                                                        |
| 155 | +                                    <td class="name"><?php _e('Sub Total:', 'invoicing'); ?></td> | 
                                                        |
| 156 | + <td class="total"><?php echo $subtotal; ?></td>  | 
                                                        |
| 157 | 157 | <td class="action"></td>  | 
                                                        
| 158 | 158 | </tr>  | 
                                                        
| 159 | 159 | <tr class="discount">  | 
                                                        
| 160 | - <td class="name"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice->ID ) ); ?>:</td>  | 
                                                        |
| 161 | - <td class="total"><?php echo wpinv_discount( $invoice->ID, true, true ); ?></td>  | 
                                                        |
| 160 | + <td class="name"><?php wpinv_get_discount_label(wpinv_discount_code($invoice->ID)); ?>:</td>  | 
                                                        |
| 161 | + <td class="total"><?php echo wpinv_discount($invoice->ID, true, true); ?></td>  | 
                                                        |
| 162 | 162 | <td class="action"></td>  | 
                                                        
| 163 | 163 | </tr>  | 
                                                        
| 164 | -                                <?php if ( $use_taxes ) { ?> | 
                                                        |
| 164 | +                                <?php if ($use_taxes) { ?> | 
                                                        |
| 165 | 165 | <tr class="tax">  | 
                                                        
| 166 | - <td class="name"><?php _e( 'Tax:', 'invoicing' );?></td>  | 
                                                        |
| 167 | - <td class="total"><?php echo $tax;?></td>  | 
                                                        |
| 166 | +                                    <td class="name"><?php _e('Tax:', 'invoicing'); ?></td> | 
                                                        |
| 167 | + <td class="total"><?php echo $tax; ?></td>  | 
                                                        |
| 168 | 168 | <td class="action"></td>  | 
                                                        
| 169 | 169 | </tr>  | 
                                                        
| 170 | 170 | <?php } ?>  | 
                                                        
| 171 | 171 | <tr class="total">  | 
                                                        
| 172 | - <td class="name"><?php _e( 'Invoice Total:', 'invoicing' );?></td>  | 
                                                        |
| 173 | - <td class="total"><?php echo $total;?></td>  | 
                                                        |
| 172 | +                                    <td class="name"><?php _e('Invoice Total:', 'invoicing'); ?></td> | 
                                                        |
| 173 | + <td class="total"><?php echo $total; ?></td>  | 
                                                        |
| 174 | 174 | <td class="action"></td>  | 
                                                        
| 175 | 175 | </tr>  | 
                                                        
| 176 | 176 | </table>  | 
                                                        
@@ -180,89 +180,89 @@ discard block  | 
                                                    ||
| 180 | 180 | </table>  | 
                                                        
| 181 | 181 | <div class="wpinv-actions">  | 
                                                        
| 182 | 182 | <?php  | 
                                                        
| 183 | -                    if ( !$invoice->is_paid() ) { | 
                                                        |
| 184 | -                    if ( !$invoice->is_recurring() ) { | 
                                                        |
| 185 | - echo wpinv_item_dropdown( array(  | 
                                                        |
| 183 | +                    if (!$invoice->is_paid()) { | 
                                                        |
| 184 | +                    if (!$invoice->is_recurring()) { | 
                                                        |
| 185 | + echo wpinv_item_dropdown(array(  | 
                                                        |
| 186 | 186 | 'name' => 'wpinv_invoice_item',  | 
                                                        
| 187 | 187 | 'id' => 'wpinv_invoice_item',  | 
                                                        
| 188 | 188 | 'with_packages' => false,  | 
                                                        
| 189 | 189 | 'show_recurring' => true,  | 
                                                        
| 190 | - ) );  | 
                                                        |
| 190 | + ));  | 
                                                        |
| 191 | 191 | ?>  | 
                                                        
| 192 | - <input type="button" value="<?php echo sprintf(esc_attr__( 'Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e( 'Create new item', 'invoicing' );?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e( 'Recalculate Totals', 'invoicing' );?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">  | 
                                                        |
| 192 | +                <input type="button" value="<?php echo sprintf(esc_attr__('Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e('Create new item', 'invoicing'); ?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e('Recalculate Totals', 'invoicing'); ?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals"> | 
                                                        |
| 193 | 193 | <?php } ?>  | 
                                                        
| 194 | - <?php do_action( 'wpinv_invoice_items_actions', $invoice ); ?>  | 
                                                        |
| 194 | +                <?php do_action('wpinv_invoice_items_actions', $invoice); ?> | 
                                                        |
| 195 | 195 | </div>  | 
                                                        
| 196 | 196 | </div>  | 
                                                        
| 197 | 197 | <?php  | 
                                                        
| 198 | 198 | }  | 
                                                        
| 199 | 199 | |
| 200 | -    public static function prices( $post ) {         | 
                                                        |
| 200 | +    public static function prices($post) {         | 
                                                        |
| 201 | 201 | $symbol = wpinv_currency_symbol();  | 
                                                        
| 202 | 202 | $position = wpinv_currency_position();  | 
                                                        
| 203 | - $item = new WPInv_Item( $post->ID );  | 
                                                        |
| 203 | + $item = new WPInv_Item($post->ID);  | 
                                                        |
| 204 | 204 | |
| 205 | 205 | $price = $item->get_price();  | 
                                                        
| 206 | 206 | $is_recurring = $item->is_recurring();  | 
                                                        
| 207 | 207 | $period = $item->get_recurring_period();  | 
                                                        
| 208 | - $interval = absint( $item->get_recurring_interval() );  | 
                                                        |
| 209 | - $times = absint( $item->get_recurring_limit() );  | 
                                                        |
| 208 | + $interval = absint($item->get_recurring_interval());  | 
                                                        |
| 209 | + $times = absint($item->get_recurring_limit());  | 
                                                        |
| 210 | 210 | $free_trial = $item->has_free_trial();  | 
                                                        
| 211 | 211 | $trial_interval = $item->get_trial_interval();  | 
                                                        
| 212 | 212 | $trial_period = $item->get_trial_period();  | 
                                                        
| 213 | 213 | |
| 214 | 214 | $intervals = array();  | 
                                                        
| 215 | -        for ( $i = 1; $i <= 90; $i++ ) { | 
                                                        |
| 215 | +        for ($i = 1; $i <= 90; $i++) { | 
                                                        |
| 216 | 216 | $intervals[$i] = $i;  | 
                                                        
| 217 | 217 | }  | 
                                                        
| 218 | 218 | |
| 219 | - $interval = $interval > 0 ? $interval : 1;  | 
                                                        |
| 219 | + $interval = $interval > 0 ? $interval : 1;  | 
                                                        |
| 220 | 220 | |
| 221 | 221 | $class = $is_recurring ? 'wpinv-recurring-y' : 'wpinv-recurring-n';  | 
                                                        
| 222 | 222 | ?>  | 
                                                        
| 223 | - <p class="wpinv-row-prices"><?php echo ( $position != 'right' ? $symbol . ' ' : '' );?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount( 0 ); ?>" value="<?php echo $price;?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled( $item->is_package(), true ); ?> /><?php echo ( $position == 'right' ? ' ' . $symbol : '' );?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce( 'wpinv_item_meta_box_save' ) ;?>" />  | 
                                                        |
| 224 | -        <?php if ( $item->is_package() ) { ?> | 
                                                        |
| 225 | - <span class="description"><?php _e( 'GD package item price can be edited only from GD payment manager.', 'invoicing' ); ?></span>  | 
                                                        |
| 223 | +        <p class="wpinv-row-prices"><?php echo ($position != 'right' ? $symbol . ' ' : ''); ?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount(0); ?>" value="<?php echo $price; ?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled($item->is_package(), true); ?> /><?php echo ($position == 'right' ? ' ' . $symbol : ''); ?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce('wpinv_item_meta_box_save'); ?>" /> | 
                                                        |
| 224 | +        <?php if ($item->is_package()) { ?> | 
                                                        |
| 225 | +        <span class="description"><?php _e('GD package item price can be edited only from GD payment manager.', 'invoicing'); ?></span> | 
                                                        |
| 226 | 226 | <?php } ?>  | 
                                                        
| 227 | 227 | </p>  | 
                                                        
| 228 | 228 | <p class="wpinv-row-is-recurring">  | 
                                                        
| 229 | 229 | <label for="wpinv_is_recurring">  | 
                                                        
| 230 | - <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked( 1, $is_recurring ); ?> />  | 
                                                        |
| 231 | - <?php echo apply_filters( 'wpinv_is_recurring_toggle_text', __( 'Is Recurring Item?', 'invoicing' ) ); ?>  | 
                                                        |
| 230 | + <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked(1, $is_recurring); ?> />  | 
                                                        |
| 231 | +                <?php echo apply_filters('wpinv_is_recurring_toggle_text', __('Is Recurring Item?', 'invoicing')); ?> | 
                                                        |
| 232 | 232 | </label>  | 
                                                        
| 233 | 233 | </p>  | 
                                                        
| 234 | - <p class="wpinv-row-recurring-fields <?php echo $class;?>">  | 
                                                        |
| 235 | - <label class="wpinv-period" for="wpinv_recurring_period"><?php _e( 'Recurring', 'invoicing' );?> <select class="wpinv-select " id="wpinv_recurring_period" name="wpinv_recurring_period"><option value="D" data-text="<?php esc_attr_e( 'day(s)', 'invoicing' ); ?>" <?php selected( 'D', $period );?>><?php _e( 'Daily', 'invoicing' ); ?></option><option value="W" data-text="<?php esc_attr_e( 'week(s)', 'invoicing' ); ?>" <?php selected( 'W', $period );?>><?php _e( 'Weekly', 'invoicing' ); ?></option><option value="M" data-text="<?php esc_attr_e( 'month(s)', 'invoicing' ); ?>" <?php selected( 'M', $period );?>><?php _e( 'Monthly', 'invoicing' ); ?></option><option value="Y" data-text="<?php esc_attr_e( 'year(s)', 'invoicing' ); ?>" <?php selected( 'Y', $period );?>><?php _e( 'Yearly', 'invoicing' ); ?></option></select></label>  | 
                                                        |
| 236 | - <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e( 'at every', 'invoicing' );?> <?php echo wpinv_html_select( array(  | 
                                                        |
| 234 | + <p class="wpinv-row-recurring-fields <?php echo $class; ?>">  | 
                                                        |
| 235 | +                <label class="wpinv-period" for="wpinv_recurring_period"><?php _e('Recurring', 'invoicing'); ?> <select class="wpinv-select " id="wpinv_recurring_period" name="wpinv_recurring_period"><option value="D" data-text="<?php esc_attr_e('day(s)', 'invoicing'); ?>" <?php selected('D', $period); ?>><?php _e('Daily', 'invoicing'); ?></option><option value="W" data-text="<?php esc_attr_e('week(s)', 'invoicing'); ?>" <?php selected('W', $period); ?>><?php _e('Weekly', 'invoicing'); ?></option><option value="M" data-text="<?php esc_attr_e('month(s)', 'invoicing'); ?>" <?php selected('M', $period); ?>><?php _e('Monthly', 'invoicing'); ?></option><option value="Y" data-text="<?php esc_attr_e('year(s)', 'invoicing'); ?>" <?php selected('Y', $period); ?>><?php _e('Yearly', 'invoicing'); ?></option></select></label> | 
                                                        |
| 236 | +                <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e('at every', 'invoicing'); ?> <?php echo wpinv_html_select(array( | 
                                                        |
| 237 | 237 | 'options' => $intervals,  | 
                                                        
| 238 | 238 | 'name' => 'wpinv_recurring_interval',  | 
                                                        
| 239 | 239 | 'id' => 'wpinv_recurring_interval',  | 
                                                        
| 240 | 240 | 'selected' => $interval,  | 
                                                        
| 241 | 241 | 'show_option_all' => false,  | 
                                                        
| 242 | 242 | 'show_option_none' => false  | 
                                                        
| 243 | - ) ); ?> <span id="wpinv_interval_text"><?php _e( 'day(s)', 'invoicing' );?></span></label>  | 
                                                        |
| 244 | - <label class="wpinv-times" for="wpinv_recurring_limit"> <?php _e( 'for', 'invoicing' );?> <input class="small-text" type="number" value="<?php echo $times;?>" size="4" id="wpinv_recurring_limit" name="wpinv_recurring_limit" step="1" min="0"> <?php _e( 'time(s) <i>(select 0 for recurring forever until cancelled</i>)', 'invoicing' );?></label>  | 
                                                        |
| 243 | +                )); ?> <span id="wpinv_interval_text"><?php _e('day(s)', 'invoicing'); ?></span></label> | 
                                                        |
| 244 | +                <label class="wpinv-times" for="wpinv_recurring_limit"> <?php _e('for', 'invoicing'); ?> <input class="small-text" type="number" value="<?php echo $times; ?>" size="4" id="wpinv_recurring_limit" name="wpinv_recurring_limit" step="1" min="0"> <?php _e('time(s) <i>(select 0 for recurring forever until cancelled</i>)', 'invoicing'); ?></label> | 
                                                        |
| 245 | 245 | <span class="clear wpi-trial-clr"></span>  | 
                                                        
| 246 | 246 | <label class="wpinv-free-trial" for="wpinv_free_trial">  | 
                                                        
| 247 | - <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked( true, (bool)$free_trial ); ?> />  | 
                                                        |
| 248 | - <?php echo __( 'Offer free trial for', 'invoicing' ); ?>  | 
                                                        |
| 247 | + <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked(true, (bool)$free_trial); ?> />  | 
                                                        |
| 248 | +                    <?php echo __('Offer free trial for', 'invoicing'); ?> | 
                                                        |
| 249 | 249 | </label>  | 
                                                        
| 250 | 250 | <label class="wpinv-trial-interval" for="wpinv_trial_interval">  | 
                                                        
| 251 | - <input class="small-text" type="number" value="<?php echo $trial_interval;?>" size="4" id="wpinv_trial_interval" name="wpinv_trial_interval" step="1" min="1"> <select class="wpinv-select" id="wpinv_trial_period" name="wpinv_trial_period"><option value="D" <?php selected( 'D', $trial_period );?>><?php _e( 'day(s)', 'invoicing' ); ?></option><option value="W" <?php selected( 'W', $trial_period );?>><?php _e( 'week(s)', 'invoicing' ); ?></option><option value="M" <?php selected( 'M', $trial_period );?>><?php _e( 'month(s)', 'invoicing' ); ?></option><option value="Y" <?php selected( 'Y', $trial_period );?>><?php _e( 'year(s)', 'invoicing' ); ?></option></select>  | 
                                                        |
| 251 | +                    <input class="small-text" type="number" value="<?php echo $trial_interval; ?>" size="4" id="wpinv_trial_interval" name="wpinv_trial_interval" step="1" min="1"> <select class="wpinv-select" id="wpinv_trial_period" name="wpinv_trial_period"><option value="D" <?php selected('D', $trial_period); ?>><?php _e('day(s)', 'invoicing'); ?></option><option value="W" <?php selected('W', $trial_period); ?>><?php _e('week(s)', 'invoicing'); ?></option><option value="M" <?php selected('M', $trial_period); ?>><?php _e('month(s)', 'invoicing'); ?></option><option value="Y" <?php selected('Y', $trial_period); ?>><?php _e('year(s)', 'invoicing'); ?></option></select> | 
                                                        |
| 252 | 252 | </label>  | 
                                                        
| 253 | 253 | </p>  | 
                                                        
| 254 | - <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type( $post->ID ); ?>" />  | 
                                                        |
| 255 | - <?php do_action( 'wpinv_item_price_field', $post->ID ); ?>  | 
                                                        |
| 254 | + <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type($post->ID); ?>" />  | 
                                                        |
| 255 | +        <?php do_action('wpinv_item_price_field', $post->ID); ?> | 
                                                        |
| 256 | 256 | <?php  | 
                                                        
| 257 | 257 | }  | 
                                                        
| 258 | 258 | |
| 259 | -    public static function vat_rules( $post ) { | 
                                                        |
| 259 | +    public static function vat_rules($post) { | 
                                                        |
| 260 | 260 | global $wpinv_euvat;  | 
                                                        
| 261 | 261 | |
| 262 | - $rule_type = $wpinv_euvat->get_item_rule( $post->ID );  | 
                                                        |
| 262 | + $rule_type = $wpinv_euvat->get_item_rule($post->ID);  | 
                                                        |
| 263 | 263 | ?>  | 
                                                        
| 264 | - <p><label for="wpinv_vat_rules"><strong><?php _e( 'Select how VAT rules will be applied:', 'invoicing' );?></strong></label>     | 
                                                        |
| 265 | - <?php echo wpinv_html_select( array(  | 
                                                        |
| 264 | +        <p><label for="wpinv_vat_rules"><strong><?php _e('Select how VAT rules will be applied:', 'invoicing'); ?></strong></label>    | 
                                                        |
| 265 | + <?php echo wpinv_html_select(array(  | 
                                                        |
| 266 | 266 | 'options' => $wpinv_euvat->get_rules(),  | 
                                                        
| 267 | 267 | 'name' => 'wpinv_vat_rules',  | 
                                                        
| 268 | 268 | 'id' => 'wpinv_vat_rules',  | 
                                                        
@@ -270,19 +270,19 @@ discard block  | 
                                                    ||
| 270 | 270 | 'show_option_all' => false,  | 
                                                        
| 271 | 271 | 'show_option_none' => false,  | 
                                                        
| 272 | 272 | 'class' => 'gdmbx2-text-medium wpinv-vat-rules',  | 
                                                        
| 273 | - ) ); ?>  | 
                                                        |
| 273 | + )); ?>  | 
                                                        |
| 274 | 274 | </p>  | 
                                                        
| 275 | - <p class="wpi-m0"><?php _e( 'When you select physical product rules, only consumers and businesses in your country will be charged VAT. The VAT rate used will be the rate in your country.', 'invoicing' ); ?></p>  | 
                                                        |
| 276 | - <p class="wpi-m0"><?php _e( 'If you select Digital product rules, VAT will be charged at the rate that applies in the country of the consumer. Only businesses in your country will be charged VAT.', 'invoicing' ); ?></p>  | 
                                                        |
| 275 | +        <p class="wpi-m0"><?php _e('When you select physical product rules, only consumers and businesses in your country will be charged VAT.  The VAT rate used will be the rate in your country.', 'invoicing'); ?></p> | 
                                                        |
| 276 | +        <p class="wpi-m0"><?php _e('If you select Digital product rules, VAT will be charged at the rate that applies in the country of the consumer.  Only businesses in your country will be charged VAT.', 'invoicing'); ?></p> | 
                                                        |
| 277 | 277 | <?php  | 
                                                        
| 278 | 278 | }  | 
                                                        
| 279 | 279 | |
| 280 | -    public static function vat_classes( $post ) { | 
                                                        |
| 280 | +    public static function vat_classes($post) { | 
                                                        |
| 281 | 281 | global $wpinv_euvat;  | 
                                                        
| 282 | 282 | |
| 283 | - $vat_class = $wpinv_euvat->get_item_class( $post->ID );  | 
                                                        |
| 283 | + $vat_class = $wpinv_euvat->get_item_class($post->ID);  | 
                                                        |
| 284 | 284 | ?>  | 
                                                        
| 285 | - <p><?php echo wpinv_html_select( array(  | 
                                                        |
| 285 | + <p><?php echo wpinv_html_select(array(  | 
                                                        |
| 286 | 286 | 'options' => $wpinv_euvat->get_all_classes(),  | 
                                                        
| 287 | 287 | 'name' => 'wpinv_vat_class',  | 
                                                        
| 288 | 288 | 'id' => 'wpinv_vat_class',  | 
                                                        
@@ -290,18 +290,18 @@ discard block  | 
                                                    ||
| 290 | 290 | 'show_option_all' => false,  | 
                                                        
| 291 | 291 | 'show_option_none' => false,  | 
                                                        
| 292 | 292 | 'class' => 'gdmbx2-text-medium wpinv-vat-class',  | 
                                                        
| 293 | - ) ); ?>  | 
                                                        |
| 293 | + )); ?>  | 
                                                        |
| 294 | 294 | </p>  | 
                                                        
| 295 | - <p class="wpi-m0"><?php _e( 'Select the VAT rate class to use for this invoice item.', 'invoicing' ); ?></p>  | 
                                                        |
| 295 | +        <p class="wpi-m0"><?php _e('Select the VAT rate class to use for this invoice item.', 'invoicing'); ?></p> | 
                                                        |
| 296 | 296 | <?php  | 
                                                        
| 297 | 297 | }  | 
                                                        
| 298 | 298 | |
| 299 | -    public static function item_info( $post ) { | 
                                                        |
| 300 | - $item_type = wpinv_get_item_type( $post->ID );  | 
                                                        |
| 301 | - do_action( 'wpinv_item_info_metabox_before', $post );  | 
                                                        |
| 299 | +    public static function item_info($post) { | 
                                                        |
| 300 | + $item_type = wpinv_get_item_type($post->ID);  | 
                                                        |
| 301 | +        do_action('wpinv_item_info_metabox_before', $post); | 
                                                        |
| 302 | 302 | ?>  | 
                                                        
| 303 | - <p><label for="wpinv_item_type"><strong><?php _e( 'Type:', 'invoicing' );?></strong></label>     | 
                                                        |
| 304 | - <?php echo wpinv_html_select( array(  | 
                                                        |
| 303 | +        <p><label for="wpinv_item_type"><strong><?php _e('Type:', 'invoicing'); ?></strong></label>    | 
                                                        |
| 304 | + <?php echo wpinv_html_select(array(  | 
                                                        |
| 305 | 305 | 'options' => wpinv_get_item_types(),  | 
                                                        
| 306 | 306 | 'name' => 'wpinv_item_type',  | 
                                                        
| 307 | 307 | 'id' => 'wpinv_item_type',  | 
                                                        
@@ -310,114 +310,114 @@ discard block  | 
                                                    ||
| 310 | 310 | 'show_option_none' => false,  | 
                                                        
| 311 | 311 | 'class' => 'gdmbx2-text-medium wpinv-item-type',  | 
                                                        
| 312 | 312 | //'disabled' => $item_type == 'package' ? true : false,  | 
                                                        
| 313 | - ) ); ?>  | 
                                                        |
| 313 | + )); ?>  | 
                                                        |
| 314 | 314 | </p>  | 
                                                        
| 315 | - <p class="wpi-m0"><?php _e( 'Select item type.', 'invoicing' );?><br><?php _e( 'Standard: standard item type', 'invoicing' );?><br><?php _e( 'Fee: like Registration Fee, Signup Fee etc.', 'invoicing' );?></p>  | 
                                                        |
| 315 | +        <p class="wpi-m0"><?php _e('Select item type.', 'invoicing'); ?><br><?php _e('Standard: standard item type', 'invoicing'); ?><br><?php _e('Fee: like Registration Fee, Signup Fee etc.', 'invoicing'); ?></p> | 
                                                        |
| 316 | 316 | <?php  | 
                                                        
| 317 | - do_action( 'wpinv_item_info_metabox_after', $post );  | 
                                                        |
| 317 | +        do_action('wpinv_item_info_metabox_after', $post); | 
                                                        |
| 318 | 318 | }  | 
                                                        
| 319 | 319 | |
| 320 | -    public static function meta_values( $post ) { | 
                                                        |
| 321 | - $meta_keys = apply_filters( 'wpinv_show_meta_values_for_keys', array(  | 
                                                        |
| 320 | +    public static function meta_values($post) { | 
                                                        |
| 321 | +        $meta_keys = apply_filters('wpinv_show_meta_values_for_keys', array( | 
                                                        |
| 322 | 322 | 'type',  | 
                                                        
| 323 | 323 | 'custom_id'  | 
                                                        
| 324 | - ) );  | 
                                                        |
| 324 | + ));  | 
                                                        |
| 325 | 325 | |
| 326 | -        if ( empty( $meta_keys ) ) { | 
                                                        |
| 326 | +        if (empty($meta_keys)) { | 
                                                        |
| 327 | 327 | return;  | 
                                                        
| 328 | 328 | }  | 
                                                        
| 329 | 329 | |
| 330 | - do_action( 'wpinv_meta_values_metabox_before', $post );  | 
                                                        |
| 330 | +        do_action('wpinv_meta_values_metabox_before', $post); | 
                                                        |
| 331 | 331 | |
| 332 | -        foreach ( $meta_keys as $meta_key ) { | 
                                                        |
| 332 | +        foreach ($meta_keys as $meta_key) { | 
                                                        |
| 333 | 333 | ?>  | 
                                                        
| 334 | - <p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta( $post->ID, '_wpinv_' . $meta_key, true ); ?></label></p>  | 
                                                        |
| 334 | + <p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta($post->ID, '_wpinv_' . $meta_key, true); ?></label></p>  | 
                                                        |
| 335 | 335 | <?php  | 
                                                        
| 336 | 336 | }  | 
                                                        
| 337 | 337 | |
| 338 | - do_action( 'wpinv_meta_values_metabox_after', $post );  | 
                                                        |
| 338 | +        do_action('wpinv_meta_values_metabox_after', $post); | 
                                                        |
| 339 | 339 | }  | 
                                                        
| 340 | 340 | |
| 341 | -    public static function save( $post_id, $data, $post ) { | 
                                                        |
| 342 | - $invoice = new WPInv_Invoice( $post_id );  | 
                                                        |
| 341 | +    public static function save($post_id, $data, $post) { | 
                                                        |
| 342 | + $invoice = new WPInv_Invoice($post_id);  | 
                                                        |
| 343 | 343 | |
| 344 | 344 | // Billing  | 
                                                        
| 345 | - $first_name = sanitize_text_field( $data['wpinv_first_name'] );  | 
                                                        |
| 346 | - $last_name = sanitize_text_field( $data['wpinv_last_name'] );  | 
                                                        |
| 347 | - $company = sanitize_text_field( $data['wpinv_company'] );  | 
                                                        |
| 348 | - $vat_number = sanitize_text_field( $data['wpinv_vat_number'] );  | 
                                                        |
| 349 | - $phone = sanitize_text_field( $data['wpinv_phone'] );  | 
                                                        |
| 350 | - $address = sanitize_text_field( $data['wpinv_address'] );  | 
                                                        |
| 351 | - $city = sanitize_text_field( $data['wpinv_city'] );  | 
                                                        |
| 352 | - $zip = sanitize_text_field( $data['wpinv_zip'] );  | 
                                                        |
| 353 | - $country = sanitize_text_field( $data['wpinv_country'] );  | 
                                                        |
| 354 | - $state = sanitize_text_field( $data['wpinv_state'] );  | 
                                                        |
| 345 | + $first_name = sanitize_text_field($data['wpinv_first_name']);  | 
                                                        |
| 346 | + $last_name = sanitize_text_field($data['wpinv_last_name']);  | 
                                                        |
| 347 | + $company = sanitize_text_field($data['wpinv_company']);  | 
                                                        |
| 348 | + $vat_number = sanitize_text_field($data['wpinv_vat_number']);  | 
                                                        |
| 349 | + $phone = sanitize_text_field($data['wpinv_phone']);  | 
                                                        |
| 350 | + $address = sanitize_text_field($data['wpinv_address']);  | 
                                                        |
| 351 | + $city = sanitize_text_field($data['wpinv_city']);  | 
                                                        |
| 352 | + $zip = sanitize_text_field($data['wpinv_zip']);  | 
                                                        |
| 353 | + $country = sanitize_text_field($data['wpinv_country']);  | 
                                                        |
| 354 | + $state = sanitize_text_field($data['wpinv_state']);  | 
                                                        |
| 355 | 355 | |
| 356 | 356 | // Details  | 
                                                        
| 357 | - $status = sanitize_text_field( $data['wpinv_status'] );  | 
                                                        |
| 358 | - $old_status = !empty( $data['original_post_status'] ) ? sanitize_text_field( $data['original_post_status'] ) : $status;  | 
                                                        |
| 359 | - $number = sanitize_text_field( $data['wpinv_number'] );  | 
                                                        |
| 360 | - $due_date = isset( $data['wpinv_due_date'] ) ? sanitize_text_field( $data['wpinv_due_date'] ) : '';  | 
                                                        |
| 357 | + $status = sanitize_text_field($data['wpinv_status']);  | 
                                                        |
| 358 | + $old_status = !empty($data['original_post_status']) ? sanitize_text_field($data['original_post_status']) : $status;  | 
                                                        |
| 359 | + $number = sanitize_text_field($data['wpinv_number']);  | 
                                                        |
| 360 | + $due_date = isset($data['wpinv_due_date']) ? sanitize_text_field($data['wpinv_due_date']) : '';  | 
                                                        |
| 361 | 361 | //$discounts = sanitize_text_field( $data['wpinv_discounts'] );  | 
                                                        
| 362 | 362 | //$discount = sanitize_text_field( $data['wpinv_discount'] );  | 
                                                        
| 363 | 363 | |
| 364 | - $ip = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip();  | 
                                                        |
| 364 | + $ip = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip();  | 
                                                        |
| 365 | 365 | |
| 366 | - $invoice->set( 'due_date', $due_date );  | 
                                                        |
| 367 | - $invoice->set( 'first_name', $first_name );  | 
                                                        |
| 368 | - $invoice->set( 'last_name', $last_name );  | 
                                                        |
| 369 | - $invoice->set( 'company', $company );  | 
                                                        |
| 370 | - $invoice->set( 'vat_number', $vat_number );  | 
                                                        |
| 371 | - $invoice->set( 'phone', $phone );  | 
                                                        |
| 372 | - $invoice->set( 'address', $address );  | 
                                                        |
| 373 | - $invoice->set( 'city', $city );  | 
                                                        |
| 374 | - $invoice->set( 'zip', $zip );  | 
                                                        |
| 375 | - $invoice->set( 'country', $country );  | 
                                                        |
| 376 | - $invoice->set( 'state', $state );  | 
                                                        |
| 377 | - $invoice->set( 'status', $status );  | 
                                                        |
| 378 | - $invoice->set( 'number', $number );  | 
                                                        |
| 366 | +        $invoice->set('due_date', $due_date); | 
                                                        |
| 367 | +        $invoice->set('first_name', $first_name); | 
                                                        |
| 368 | +        $invoice->set('last_name', $last_name); | 
                                                        |
| 369 | +        $invoice->set('company', $company); | 
                                                        |
| 370 | +        $invoice->set('vat_number', $vat_number); | 
                                                        |
| 371 | +        $invoice->set('phone', $phone); | 
                                                        |
| 372 | +        $invoice->set('address', $address); | 
                                                        |
| 373 | +        $invoice->set('city', $city); | 
                                                        |
| 374 | +        $invoice->set('zip', $zip); | 
                                                        |
| 375 | +        $invoice->set('country', $country); | 
                                                        |
| 376 | +        $invoice->set('state', $state); | 
                                                        |
| 377 | +        $invoice->set('status', $status); | 
                                                        |
| 378 | +        $invoice->set('number', $number); | 
                                                        |
| 379 | 379 | //$invoice->set( 'discounts', $discounts );  | 
                                                        
| 380 | 380 | //$invoice->set( 'discount', $discount );  | 
                                                        
| 381 | - $invoice->set( 'ip', $ip );  | 
                                                        |
| 381 | +        $invoice->set('ip', $ip); | 
                                                        |
| 382 | 382 | $invoice->old_status = $_POST['original_post_status'];  | 
                                                        
| 383 | 383 | $invoice->currency = wpinv_get_currency();  | 
                                                        
| 384 | -        if ( !empty( $data['wpinv_gateway'] ) ) { | 
                                                        |
| 385 | - $invoice->set( 'gateway', sanitize_text_field( $data['wpinv_gateway'] ) );  | 
                                                        |
| 384 | +        if (!empty($data['wpinv_gateway'])) { | 
                                                        |
| 385 | +            $invoice->set('gateway', sanitize_text_field($data['wpinv_gateway'])); | 
                                                        |
| 386 | 386 | }  | 
                                                        
| 387 | 387 | $saved = $invoice->save();  | 
                                                        
| 388 | 388 | |
| 389 | 389 | // Check for payment notes  | 
                                                        
| 390 | -        if ( !empty( $data['invoice_note'] ) ) { | 
                                                        |
| 391 | - $note = wp_kses( $data['invoice_note'], array() );  | 
                                                        |
| 392 | - $note_type = sanitize_text_field( $data['invoice_note_type'] );  | 
                                                        |
| 390 | +        if (!empty($data['invoice_note'])) { | 
                                                        |
| 391 | + $note = wp_kses($data['invoice_note'], array());  | 
                                                        |
| 392 | + $note_type = sanitize_text_field($data['invoice_note_type']);  | 
                                                        |
| 393 | 393 | $is_customer_note = $note_type == 'customer' ? 1 : 0;  | 
                                                        
| 394 | 394 | |
| 395 | - wpinv_insert_payment_note( $invoice->ID, $note, $is_customer_note );  | 
                                                        |
| 395 | + wpinv_insert_payment_note($invoice->ID, $note, $is_customer_note);  | 
                                                        |
| 396 | 396 | }  | 
                                                        
| 397 | 397 | |
| 398 | 398 | // Update user address if empty.  | 
                                                        
| 399 | -        if ( $saved && !empty( $invoice ) ) { | 
                                                        |
| 400 | -            if ( $user_id = $invoice->get_user_id() ) { | 
                                                        |
| 401 | - $user_address = wpinv_get_user_address( $user_id, false );  | 
                                                        |
| 399 | +        if ($saved && !empty($invoice)) { | 
                                                        |
| 400 | +            if ($user_id = $invoice->get_user_id()) { | 
                                                        |
| 401 | + $user_address = wpinv_get_user_address($user_id, false);  | 
                                                        |
| 402 | 402 | |
| 403 | 403 |                  if (empty($user_address['first_name'])) { | 
                                                        
| 404 | - update_user_meta( $user_id, '_wpinv_first_name', $first_name );  | 
                                                        |
| 405 | - update_user_meta( $user_id, '_wpinv_last_name', $last_name );  | 
                                                        |
| 404 | + update_user_meta($user_id, '_wpinv_first_name', $first_name);  | 
                                                        |
| 405 | + update_user_meta($user_id, '_wpinv_last_name', $last_name);  | 
                                                        |
| 406 | 406 |                  } else if (empty($user_address['last_name']) && $user_address['first_name'] == $first_name) { | 
                                                        
| 407 | - update_user_meta( $user_id, '_wpinv_last_name', $last_name );  | 
                                                        |
| 407 | + update_user_meta($user_id, '_wpinv_last_name', $last_name);  | 
                                                        |
| 408 | 408 | }  | 
                                                        
| 409 | 409 | |
| 410 | 410 |                  if (empty($user_address['address']) || empty($user_address['city']) || empty($user_address['state']) || empty($user_address['country'])) { | 
                                                        
| 411 | - update_user_meta( $user_id, '_wpinv_address', $address );  | 
                                                        |
| 412 | - update_user_meta( $user_id, '_wpinv_city', $city );  | 
                                                        |
| 413 | - update_user_meta( $user_id, '_wpinv_state', $state );  | 
                                                        |
| 414 | - update_user_meta( $user_id, '_wpinv_country', $country );  | 
                                                        |
| 415 | - update_user_meta( $user_id, '_wpinv_zip', $zip );  | 
                                                        |
| 416 | - update_user_meta( $user_id, '_wpinv_phone', $phone );  | 
                                                        |
| 411 | + update_user_meta($user_id, '_wpinv_address', $address);  | 
                                                        |
| 412 | + update_user_meta($user_id, '_wpinv_city', $city);  | 
                                                        |
| 413 | + update_user_meta($user_id, '_wpinv_state', $state);  | 
                                                        |
| 414 | + update_user_meta($user_id, '_wpinv_country', $country);  | 
                                                        |
| 415 | + update_user_meta($user_id, '_wpinv_zip', $zip);  | 
                                                        |
| 416 | + update_user_meta($user_id, '_wpinv_phone', $phone);  | 
                                                        |
| 417 | 417 | }  | 
                                                        
| 418 | 418 | }  | 
                                                        
| 419 | 419 | |
| 420 | - do_action( 'wpinv_invoice_metabox_saved', $invoice );  | 
                                                        |
| 420 | +            do_action('wpinv_invoice_metabox_saved', $invoice); | 
                                                        |
| 421 | 421 | }  | 
                                                        
| 422 | 422 | |
| 423 | 423 | return $saved;  |