@@ -512,7 +512,7 @@  | 
                                                    ||
| 512 | 512 | |
| 513 | 513 | $response['success'] = true;  | 
                                                        
| 514 | 514 | $response['msg'] = __( 'Discount has been applied successfully.', 'invoicing' );  | 
                                                        
| 515 | -        }  else { | 
                                                        |
| 515 | +        } else { | 
                                                        |
| 516 | 516 | $errors = wpinv_get_errors();  | 
                                                        
| 517 | 517 |              if ( !empty( $errors['wpinv-discount-error'] ) ) { | 
                                                        
| 518 | 518 | $response['msg'] = $errors['wpinv-discount-error'];  | 
                                                        
@@ -7,28 +7,28 @@ discard block  | 
                                                    ||
| 7 | 7 | */  | 
                                                        
| 8 | 8 | |
| 9 | 9 | // MUST have WordPress.  | 
                                                        
| 10 | -if ( !defined( 'WPINC' ) ) { | 
                                                        |
| 11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );  | 
                                                        |
| 10 | +if (!defined('WPINC')) { | 
                                                        |
| 11 | +    exit('Do NOT access this file directly: ' . basename(__FILE__)); | 
                                                        |
| 12 | 12 | }  | 
                                                        
| 13 | 13 | |
| 14 | 14 |  class WPInv_Ajax { | 
                                                        
| 15 | 15 |      public static function init() { | 
                                                        
| 16 | - add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );  | 
                                                        |
| 17 | - add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );  | 
                                                        |
| 16 | +        add_action('init', array(__CLASS__, 'define_ajax'), 0); | 
                                                        |
| 17 | +        add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0); | 
                                                        |
| 18 | 18 | self::add_ajax_events();  | 
                                                        
| 19 | 19 | }  | 
                                                        
| 20 | 20 | |
| 21 | 21 |      public static function define_ajax() { | 
                                                        
| 22 | -        if ( !empty( $_GET['wpinv-ajax'] ) ) { | 
                                                        |
| 23 | -            if ( ! defined( 'DOING_AJAX' ) ) { | 
                                                        |
| 24 | - define( 'DOING_AJAX', true );  | 
                                                        |
| 22 | +        if (!empty($_GET['wpinv-ajax'])) { | 
                                                        |
| 23 | +            if (!defined('DOING_AJAX')) { | 
                                                        |
| 24 | +                define('DOING_AJAX', true); | 
                                                        |
| 25 | 25 | }  | 
                                                        
| 26 | -            if ( ! defined( 'WC_DOING_AJAX' ) ) { | 
                                                        |
| 27 | - define( 'WC_DOING_AJAX', true );  | 
                                                        |
| 26 | +            if (!defined('WC_DOING_AJAX')) { | 
                                                        |
| 27 | +                define('WC_DOING_AJAX', true); | 
                                                        |
| 28 | 28 | }  | 
                                                        
| 29 | 29 | // Turn off display_errors during AJAX events to prevent malformed JSON  | 
                                                        
| 30 | -            if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { | 
                                                        |
| 31 | - @ini_set( 'display_errors', 0 );  | 
                                                        |
| 30 | +            if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) { | 
                                                        |
| 31 | +                @ini_set('display_errors', 0); | 
                                                        |
| 32 | 32 | }  | 
                                                        
| 33 | 33 | $GLOBALS['wpdb']->hide_errors();  | 
                                                        
| 34 | 34 | }  | 
                                                        
@@ -37,24 +37,24 @@ discard block  | 
                                                    ||
| 37 | 37 |      public static function do_wpinv_ajax() { | 
                                                        
| 38 | 38 | global $wp_query;  | 
                                                        
| 39 | 39 | |
| 40 | -        if ( !empty( $_GET['wpinv-ajax'] ) ) { | 
                                                        |
| 41 | - $wp_query->set( 'wpinv-ajax', sanitize_text_field( $_GET['wpinv-ajax'] ) );  | 
                                                        |
| 40 | +        if (!empty($_GET['wpinv-ajax'])) { | 
                                                        |
| 41 | +            $wp_query->set('wpinv-ajax', sanitize_text_field($_GET['wpinv-ajax'])); | 
                                                        |
| 42 | 42 | }  | 
                                                        
| 43 | 43 | |
| 44 | -        if ( $action = $wp_query->get( 'wpinv-ajax' ) ) { | 
                                                        |
| 44 | +        if ($action = $wp_query->get('wpinv-ajax')) { | 
                                                        |
| 45 | 45 | self::wpinv_ajax_headers();  | 
                                                        
| 46 | - do_action( 'wpinv_ajax_' . sanitize_text_field( $action ) );  | 
                                                        |
| 46 | +            do_action('wpinv_ajax_' . sanitize_text_field($action)); | 
                                                        |
| 47 | 47 | die();  | 
                                                        
| 48 | 48 | }  | 
                                                        
| 49 | 49 | }  | 
                                                        
| 50 | 50 | |
| 51 | 51 |      private static function wpinv_ajax_headers() { | 
                                                        
| 52 | 52 | send_origin_headers();  | 
                                                        
| 53 | - @header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );  | 
                                                        |
| 54 | - @header( 'X-Robots-Tag: noindex' );  | 
                                                        |
| 53 | +        @header('Content-Type: text/html; charset=' . get_option('blog_charset')); | 
                                                        |
| 54 | +        @header('X-Robots-Tag: noindex'); | 
                                                        |
| 55 | 55 | send_nosniff_header();  | 
                                                        
| 56 | 56 | nocache_headers();  | 
                                                        
| 57 | - status_header( 200 );  | 
                                                        |
| 57 | + status_header(200);  | 
                                                        |
| 58 | 58 | }  | 
                                                        
| 59 | 59 | |
| 60 | 60 |      public static function add_ajax_events() { | 
                                                        
@@ -77,39 +77,39 @@ discard block  | 
                                                    ||
| 77 | 77 | 'buy_items' => true,  | 
                                                        
| 78 | 78 | );  | 
                                                        
| 79 | 79 | |
| 80 | -        foreach ( $ajax_events as $ajax_event => $nopriv ) { | 
                                                        |
| 81 | - add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );  | 
                                                        |
| 80 | +        foreach ($ajax_events as $ajax_event => $nopriv) { | 
                                                        |
| 81 | +            add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); | 
                                                        |
| 82 | 82 | |
| 83 | -            if ( !defined( 'WPI_AJAX_' . strtoupper( $nopriv ) ) ) { | 
                                                        |
| 84 | - define( 'WPI_AJAX_' . strtoupper( $nopriv ), 1 );  | 
                                                        |
| 83 | +            if (!defined('WPI_AJAX_' . strtoupper($nopriv))) { | 
                                                        |
| 84 | +                define('WPI_AJAX_' . strtoupper($nopriv), 1); | 
                                                        |
| 85 | 85 | }  | 
                                                        
| 86 | 86 | |
| 87 | -            if ( $nopriv ) { | 
                                                        |
| 88 | - add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );  | 
                                                        |
| 87 | +            if ($nopriv) { | 
                                                        |
| 88 | +                add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); | 
                                                        |
| 89 | 89 | |
| 90 | - add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) );  | 
                                                        |
| 90 | +                add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event)); | 
                                                        |
| 91 | 91 | }  | 
                                                        
| 92 | 92 | }  | 
                                                        
| 93 | 93 | }  | 
                                                        
| 94 | 94 | |
| 95 | 95 |      public static function add_note() { | 
                                                        
| 96 | - check_ajax_referer( 'add-invoice-note', '_nonce' );  | 
                                                        |
| 96 | +        check_ajax_referer('add-invoice-note', '_nonce'); | 
                                                        |
| 97 | 97 | |
| 98 | -        if ( !current_user_can( 'manage_options' ) ) { | 
                                                        |
| 98 | +        if (!current_user_can('manage_options')) { | 
                                                        |
| 99 | 99 | die(-1);  | 
                                                        
| 100 | 100 | }  | 
                                                        
| 101 | 101 | |
| 102 | - $post_id = absint( $_POST['post_id'] );  | 
                                                        |
| 103 | - $note = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) );  | 
                                                        |
| 104 | - $note_type = sanitize_text_field( $_POST['note_type'] );  | 
                                                        |
| 102 | + $post_id = absint($_POST['post_id']);  | 
                                                        |
| 103 | + $note = wp_kses_post(trim(stripslashes($_POST['note'])));  | 
                                                        |
| 104 | + $note_type = sanitize_text_field($_POST['note_type']);  | 
                                                        |
| 105 | 105 | |
| 106 | 106 | $is_customer_note = $note_type == 'customer' ? 1 : 0;  | 
                                                        
| 107 | 107 | |
| 108 | -        if ( $post_id > 0 ) { | 
                                                        |
| 109 | - $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note );  | 
                                                        |
| 108 | +        if ($post_id > 0) { | 
                                                        |
| 109 | + $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note);  | 
                                                        |
| 110 | 110 | |
| 111 | -            if ( $note_id > 0 && !is_wp_error( $note_id ) ) { | 
                                                        |
| 112 | - wpinv_get_invoice_note_line_item( $note_id );  | 
                                                        |
| 111 | +            if ($note_id > 0 && !is_wp_error($note_id)) { | 
                                                        |
| 112 | + wpinv_get_invoice_note_line_item($note_id);  | 
                                                        |
| 113 | 113 | }  | 
                                                        
| 114 | 114 | }  | 
                                                        
| 115 | 115 | |
@@ -117,16 +117,16 @@ discard block  | 
                                                    ||
| 117 | 117 | }  | 
                                                        
| 118 | 118 | |
| 119 | 119 |      public static function delete_note() { | 
                                                        
| 120 | - check_ajax_referer( 'delete-invoice-note', '_nonce' );  | 
                                                        |
| 120 | +        check_ajax_referer('delete-invoice-note', '_nonce'); | 
                                                        |
| 121 | 121 | |
| 122 | -        if ( !current_user_can( 'manage_options' ) ) { | 
                                                        |
| 122 | +        if (!current_user_can('manage_options')) { | 
                                                        |
| 123 | 123 | die(-1);  | 
                                                        
| 124 | 124 | }  | 
                                                        
| 125 | 125 | |
| 126 | 126 | $note_id = (int)$_POST['note_id'];  | 
                                                        
| 127 | 127 | |
| 128 | -        if ( $note_id > 0 ) { | 
                                                        |
| 129 | - wp_delete_comment( $note_id, true );  | 
                                                        |
| 128 | +        if ($note_id > 0) { | 
                                                        |
| 129 | + wp_delete_comment($note_id, true);  | 
                                                        |
| 130 | 130 | }  | 
                                                        
| 131 | 131 | |
| 132 | 132 | die();  | 
                                                        
@@ -139,8 +139,8 @@ discard block  | 
                                                    ||
| 139 | 139 | }  | 
                                                        
| 140 | 140 | |
| 141 | 141 |      public static function checkout() { | 
                                                        
| 142 | -        if ( ! defined( 'WPINV_CHECKOUT' ) ) { | 
                                                        |
| 143 | - define( 'WPINV_CHECKOUT', true );  | 
                                                        |
| 142 | +        if (!defined('WPINV_CHECKOUT')) { | 
                                                        |
| 143 | +            define('WPINV_CHECKOUT', true); | 
                                                        |
| 144 | 144 | }  | 
                                                        
| 145 | 145 | |
| 146 | 146 | wpinv_process_checkout();  | 
                                                        
@@ -149,53 +149,53 @@ discard block  | 
                                                    ||
| 149 | 149 | |
| 150 | 150 |      public static function add_invoice_item() { | 
                                                        
| 151 | 151 | global $wpi_userID, $wpinv_ip_address_country;  | 
                                                        
| 152 | - check_ajax_referer( 'invoice-item', '_nonce' );  | 
                                                        |
| 153 | -        if ( !current_user_can( 'manage_options' ) ) { | 
                                                        |
| 152 | +        check_ajax_referer('invoice-item', '_nonce'); | 
                                                        |
| 153 | +        if (!current_user_can('manage_options')) { | 
                                                        |
| 154 | 154 | die(-1);  | 
                                                        
| 155 | 155 | }  | 
                                                        
| 156 | 156 | |
| 157 | - $item_id = sanitize_text_field( $_POST['item_id'] );  | 
                                                        |
| 158 | - $invoice_id = absint( $_POST['invoice_id'] );  | 
                                                        |
| 157 | + $item_id = sanitize_text_field($_POST['item_id']);  | 
                                                        |
| 158 | + $invoice_id = absint($_POST['invoice_id']);  | 
                                                        |
| 159 | 159 | |
| 160 | -        if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) { | 
                                                        |
| 160 | +        if (!is_numeric($invoice_id) || !is_numeric($item_id)) { | 
                                                        |
| 161 | 161 | die();  | 
                                                        
| 162 | 162 | }  | 
                                                        
| 163 | 163 | |
| 164 | - $invoice = wpinv_get_invoice( $invoice_id );  | 
                                                        |
| 165 | -        if ( empty( $invoice ) ) { | 
                                                        |
| 164 | + $invoice = wpinv_get_invoice($invoice_id);  | 
                                                        |
| 165 | +        if (empty($invoice)) { | 
                                                        |
| 166 | 166 | die();  | 
                                                        
| 167 | 167 | }  | 
                                                        
| 168 | 168 | |
| 169 | -        if ( $invoice->is_paid() || $invoice->is_refunded() ) { | 
                                                        |
| 169 | +        if ($invoice->is_paid() || $invoice->is_refunded()) { | 
                                                        |
| 170 | 170 | die(); // Don't allow modify items for paid invoice.  | 
                                                        
| 171 | 171 | }  | 
                                                        
| 172 | 172 | |
| 173 | -        if ( !empty( $_POST['user_id'] ) ) { | 
                                                        |
| 174 | - $wpi_userID = absint( $_POST['user_id'] );  | 
                                                        |
| 173 | +        if (!empty($_POST['user_id'])) { | 
                                                        |
| 174 | + $wpi_userID = absint($_POST['user_id']);  | 
                                                        |
| 175 | 175 | }  | 
                                                        
| 176 | 176 | |
| 177 | - $item = new WPInv_Item( $item_id );  | 
                                                        |
| 178 | -        if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) { | 
                                                        |
| 177 | + $item = new WPInv_Item($item_id);  | 
                                                        |
| 178 | +        if (!(!empty($item) && $item->post_type == 'wpi_item')) { | 
                                                        |
| 179 | 179 | die();  | 
                                                        
| 180 | 180 | }  | 
                                                        
| 181 | 181 | |
| 182 | 182 | // Validate item before adding to invoice because recurring item must be paid individually.  | 
                                                        
| 183 | -        if ( !empty( $invoice->cart_details ) ) { | 
                                                        |
| 183 | +        if (!empty($invoice->cart_details)) { | 
                                                        |
| 184 | 184 | $valid = true;  | 
                                                        
| 185 | 185 | |
| 186 | -            if ( $recurring_item = $invoice->get_recurring() ) { | 
                                                        |
| 187 | -                if ( $recurring_item != $item_id ) { | 
                                                        |
| 186 | +            if ($recurring_item = $invoice->get_recurring()) { | 
                                                        |
| 187 | +                if ($recurring_item != $item_id) { | 
                                                        |
| 188 | 188 | $valid = false;  | 
                                                        
| 189 | 189 | }  | 
                                                        
| 190 | -            } else if ( wpinv_is_recurring_item( $item_id ) ) { | 
                                                        |
| 190 | +            } else if (wpinv_is_recurring_item($item_id)) { | 
                                                        |
| 191 | 191 | $valid = false;  | 
                                                        
| 192 | 192 | }  | 
                                                        
| 193 | 193 | |
| 194 | -            if ( !$valid ) { | 
                                                        |
| 194 | +            if (!$valid) { | 
                                                        |
| 195 | 195 | $response = array();  | 
                                                        
| 196 | 196 | $response['success'] = false;  | 
                                                        
| 197 | - $response['msg'] = __( 'You can not add item because recurring item must be paid individually!', 'invoicing' );  | 
                                                        |
| 198 | - wp_send_json( $response );  | 
                                                        |
| 197 | +                $response['msg']        = __('You can not add item because recurring item must be paid individually!', 'invoicing'); | 
                                                        |
| 198 | + wp_send_json($response);  | 
                                                        |
| 199 | 199 | }  | 
                                                        
| 200 | 200 | }  | 
                                                        
| 201 | 201 | |
@@ -203,9 +203,9 @@ discard block  | 
                                                    ||
| 203 | 203 | |
| 204 | 204 | $data = array();  | 
                                                        
| 205 | 205 | $data['invoice_id'] = $invoice_id;  | 
                                                        
| 206 | - $data['cart_discounts'] = $invoice->get_discounts( true );  | 
                                                        |
| 206 | + $data['cart_discounts'] = $invoice->get_discounts(true);  | 
                                                        |
| 207 | 207 | |
| 208 | - wpinv_set_checkout_session( $data );  | 
                                                        |
| 208 | + wpinv_set_checkout_session($data);  | 
                                                        |
| 209 | 209 | |
| 210 | 210 | $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int)$_POST['qty'] > 0 ? (int)$_POST['qty'] : 1;  | 
                                                        
| 211 | 211 | |
@@ -220,21 +220,21 @@ discard block  | 
                                                    ||
| 220 | 220 | 'fees' => array()  | 
                                                        
| 221 | 221 | );  | 
                                                        
| 222 | 222 | |
| 223 | - $invoice->add_item( $item_id, $args );  | 
                                                        |
| 223 | + $invoice->add_item($item_id, $args);  | 
                                                        |
| 224 | 224 | $invoice->save();  | 
                                                        
| 225 | 225 | |
| 226 | -        if ( empty( $_POST['country'] ) ) { | 
                                                        |
| 226 | +        if (empty($_POST['country'])) { | 
                                                        |
| 227 | 227 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();  | 
                                                        
| 228 | 228 | }  | 
                                                        
| 229 | -        if ( empty( $_POST['state'] ) ) { | 
                                                        |
| 229 | +        if (empty($_POST['state'])) { | 
                                                        |
| 230 | 230 | $_POST['state'] = $invoice->state;  | 
                                                        
| 231 | 231 | }  | 
                                                        
| 232 | 232 | |
| 233 | - $invoice->country = sanitize_text_field( $_POST['country'] );  | 
                                                        |
| 234 | - $invoice->state = sanitize_text_field( $_POST['state'] );  | 
                                                        |
| 233 | + $invoice->country = sanitize_text_field($_POST['country']);  | 
                                                        |
| 234 | + $invoice->state = sanitize_text_field($_POST['state']);  | 
                                                        |
| 235 | 235 | |
| 236 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );  | 
                                                        |
| 237 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );  | 
                                                        |
| 236 | +        $invoice->set('country', sanitize_text_field($_POST['country'])); | 
                                                        |
| 237 | +        $invoice->set('state', sanitize_text_field($_POST['state'])); | 
                                                        |
| 238 | 238 | |
| 239 | 239 | $wpinv_ip_address_country = $invoice->country;  | 
                                                        
| 240 | 240 | |
@@ -242,7 +242,7 @@ discard block  | 
                                                    ||
| 242 | 242 | |
| 243 | 243 | $response = array();  | 
                                                        
| 244 | 244 | $response['success'] = true;  | 
                                                        
| 245 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice );  | 
                                                        |
| 245 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice);  | 
                                                        |
| 246 | 246 | $response['data']['subtotal'] = $invoice->get_subtotal();  | 
                                                        
| 247 | 247 | $response['data']['subtotalf'] = $invoice->get_subtotal(true);  | 
                                                        
| 248 | 248 | $response['data']['tax'] = $invoice->get_tax();  | 
                                                        
@@ -254,40 +254,40 @@ discard block  | 
                                                    ||
| 254 | 254 | |
| 255 | 255 | wpinv_set_checkout_session($checkout_session);  | 
                                                        
| 256 | 256 | |
| 257 | - wp_send_json( $response );  | 
                                                        |
| 257 | + wp_send_json($response);  | 
                                                        |
| 258 | 258 | }  | 
                                                        
| 259 | 259 | |
| 260 | 260 |      public static function remove_invoice_item() { | 
                                                        
| 261 | 261 | global $wpi_userID, $wpinv_ip_address_country;  | 
                                                        
| 262 | 262 | |
| 263 | - check_ajax_referer( 'invoice-item', '_nonce' );  | 
                                                        |
| 264 | -        if ( !current_user_can( 'manage_options' ) ) { | 
                                                        |
| 263 | +        check_ajax_referer('invoice-item', '_nonce'); | 
                                                        |
| 264 | +        if (!current_user_can('manage_options')) { | 
                                                        |
| 265 | 265 | die(-1);  | 
                                                        
| 266 | 266 | }  | 
                                                        
| 267 | 267 | |
| 268 | - $item_id = sanitize_text_field( $_POST['item_id'] );  | 
                                                        |
| 269 | - $invoice_id = absint( $_POST['invoice_id'] );  | 
                                                        |
| 270 | - $cart_index = isset( $_POST['index'] ) && $_POST['index'] >= 0 ? $_POST['index'] : false;  | 
                                                        |
| 268 | + $item_id = sanitize_text_field($_POST['item_id']);  | 
                                                        |
| 269 | + $invoice_id = absint($_POST['invoice_id']);  | 
                                                        |
| 270 | + $cart_index = isset($_POST['index']) && $_POST['index'] >= 0 ? $_POST['index'] : false;  | 
                                                        |
| 271 | 271 | |
| 272 | -        if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) { | 
                                                        |
| 272 | +        if (!is_numeric($invoice_id) || !is_numeric($item_id)) { | 
                                                        |
| 273 | 273 | die();  | 
                                                        
| 274 | 274 | }  | 
                                                        
| 275 | 275 | |
| 276 | - $invoice = wpinv_get_invoice( $invoice_id );  | 
                                                        |
| 277 | -        if ( empty( $invoice ) ) { | 
                                                        |
| 276 | + $invoice = wpinv_get_invoice($invoice_id);  | 
                                                        |
| 277 | +        if (empty($invoice)) { | 
                                                        |
| 278 | 278 | die();  | 
                                                        
| 279 | 279 | }  | 
                                                        
| 280 | 280 | |
| 281 | -        if ( $invoice->is_paid() || $invoice->is_refunded() ) { | 
                                                        |
| 281 | +        if ($invoice->is_paid() || $invoice->is_refunded()) { | 
                                                        |
| 282 | 282 | die(); // Don't allow modify items for paid invoice.  | 
                                                        
| 283 | 283 | }  | 
                                                        
| 284 | 284 | |
| 285 | -        if ( !empty( $_POST['user_id'] ) ) { | 
                                                        |
| 286 | - $wpi_userID = absint( $_POST['user_id'] );  | 
                                                        |
| 285 | +        if (!empty($_POST['user_id'])) { | 
                                                        |
| 286 | + $wpi_userID = absint($_POST['user_id']);  | 
                                                        |
| 287 | 287 | }  | 
                                                        
| 288 | 288 | |
| 289 | - $item = new WPInv_Item( $item_id );  | 
                                                        |
| 290 | -        if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) { | 
                                                        |
| 289 | + $item = new WPInv_Item($item_id);  | 
                                                        |
| 290 | +        if (!(!empty($item) && $item->post_type == 'wpi_item')) { | 
                                                        |
| 291 | 291 | die();  | 
                                                        
| 292 | 292 | }  | 
                                                        
| 293 | 293 | |
@@ -295,9 +295,9 @@ discard block  | 
                                                    ||
| 295 | 295 | |
| 296 | 296 | $data = array();  | 
                                                        
| 297 | 297 | $data['invoice_id'] = $invoice_id;  | 
                                                        
| 298 | - $data['cart_discounts'] = $invoice->get_discounts( true );  | 
                                                        |
| 298 | + $data['cart_discounts'] = $invoice->get_discounts(true);  | 
                                                        |
| 299 | 299 | |
| 300 | - wpinv_set_checkout_session( $data );  | 
                                                        |
| 300 | + wpinv_set_checkout_session($data);  | 
                                                        |
| 301 | 301 | |
| 302 | 302 | $args = array(  | 
                                                        
| 303 | 303 | 'id' => $item_id,  | 
                                                        
@@ -305,21 +305,21 @@ discard block  | 
                                                    ||
| 305 | 305 | 'cart_index' => $cart_index  | 
                                                        
| 306 | 306 | );  | 
                                                        
| 307 | 307 | |
| 308 | - $invoice->remove_item( $item_id, $args );  | 
                                                        |
| 308 | + $invoice->remove_item($item_id, $args);  | 
                                                        |
| 309 | 309 | $invoice->save();  | 
                                                        
| 310 | 310 | |
| 311 | -        if ( empty( $_POST['country'] ) ) { | 
                                                        |
| 311 | +        if (empty($_POST['country'])) { | 
                                                        |
| 312 | 312 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();  | 
                                                        
| 313 | 313 | }  | 
                                                        
| 314 | -        if ( empty( $_POST['state'] ) ) { | 
                                                        |
| 314 | +        if (empty($_POST['state'])) { | 
                                                        |
| 315 | 315 | $_POST['state'] = $invoice->state;  | 
                                                        
| 316 | 316 | }  | 
                                                        
| 317 | 317 | |
| 318 | - $invoice->country = sanitize_text_field( $_POST['country'] );  | 
                                                        |
| 319 | - $invoice->state = sanitize_text_field( $_POST['state'] );  | 
                                                        |
| 318 | + $invoice->country = sanitize_text_field($_POST['country']);  | 
                                                        |
| 319 | + $invoice->state = sanitize_text_field($_POST['state']);  | 
                                                        |
| 320 | 320 | |
| 321 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );  | 
                                                        |
| 322 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );  | 
                                                        |
| 321 | +        $invoice->set('country', sanitize_text_field($_POST['country'])); | 
                                                        |
| 322 | +        $invoice->set('state', sanitize_text_field($_POST['state'])); | 
                                                        |
| 323 | 323 | |
| 324 | 324 | $wpinv_ip_address_country = $invoice->country;  | 
                                                        
| 325 | 325 | |
@@ -327,7 +327,7 @@ discard block  | 
                                                    ||
| 327 | 327 | |
| 328 | 328 | $response = array();  | 
                                                        
| 329 | 329 | $response['success'] = true;  | 
                                                        
| 330 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice );  | 
                                                        |
| 330 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice);  | 
                                                        |
| 331 | 331 | $response['data']['subtotal'] = $invoice->get_subtotal();  | 
                                                        
| 332 | 332 | $response['data']['subtotalf'] = $invoice->get_subtotal(true);  | 
                                                        
| 333 | 333 | $response['data']['tax'] = $invoice->get_tax();  | 
                                                        
@@ -339,40 +339,40 @@ discard block  | 
                                                    ||
| 339 | 339 | |
| 340 | 340 | wpinv_set_checkout_session($checkout_session);  | 
                                                        
| 341 | 341 | |
| 342 | - wp_send_json( $response );  | 
                                                        |
| 342 | + wp_send_json($response);  | 
                                                        |
| 343 | 343 | }  | 
                                                        
| 344 | 344 | |
| 345 | 345 |      public static function create_invoice_item() { | 
                                                        
| 346 | - check_ajax_referer( 'invoice-item', '_nonce' );  | 
                                                        |
| 347 | -        if ( !current_user_can( 'manage_options' ) ) { | 
                                                        |
| 346 | +        check_ajax_referer('invoice-item', '_nonce'); | 
                                                        |
| 347 | +        if (!current_user_can('manage_options')) { | 
                                                        |
| 348 | 348 | die(-1);  | 
                                                        
| 349 | 349 | }  | 
                                                        
| 350 | 350 | |
| 351 | - $invoice_id = absint( $_POST['invoice_id'] );  | 
                                                        |
| 351 | + $invoice_id = absint($_POST['invoice_id']);  | 
                                                        |
| 352 | 352 | |
| 353 | 353 | // Find the item  | 
                                                        
| 354 | -        if ( !is_numeric( $invoice_id ) ) { | 
                                                        |
| 354 | +        if (!is_numeric($invoice_id)) { | 
                                                        |
| 355 | 355 | die();  | 
                                                        
| 356 | 356 | }  | 
                                                        
| 357 | 357 | |
| 358 | - $invoice = wpinv_get_invoice( $invoice_id );  | 
                                                        |
| 359 | -        if ( empty( $invoice ) ) { | 
                                                        |
| 358 | + $invoice = wpinv_get_invoice($invoice_id);  | 
                                                        |
| 359 | +        if (empty($invoice)) { | 
                                                        |
| 360 | 360 | die();  | 
                                                        
| 361 | 361 | }  | 
                                                        
| 362 | 362 | |
| 363 | 363 | // Validate item before adding to invoice because recurring item must be paid individually.  | 
                                                        
| 364 | -        if ( !empty( $invoice->cart_details ) && $invoice->get_recurring() ) { | 
                                                        |
| 364 | +        if (!empty($invoice->cart_details) && $invoice->get_recurring()) { | 
                                                        |
| 365 | 365 | $response = array();  | 
                                                        
| 366 | 366 | $response['success'] = false;  | 
                                                        
| 367 | - $response['msg'] = __( 'You can not add item because recurring item must be paid individually!', 'invoicing' );  | 
                                                        |
| 368 | - wp_send_json( $response );  | 
                                                        |
| 367 | +            $response['msg']        = __('You can not add item because recurring item must be paid individually!', 'invoicing'); | 
                                                        |
| 368 | + wp_send_json($response);  | 
                                                        |
| 369 | 369 | }  | 
                                                        
| 370 | 370 | |
| 371 | 371 | $save_item = $_POST['_wpinv_quick'];  | 
                                                        
| 372 | 372 | |
| 373 | 373 | $meta = array();  | 
                                                        
| 374 | 374 | $meta['type'] = !empty($save_item['type']) ? sanitize_text_field($save_item['type']) : 'custom';  | 
                                                        
| 375 | - $meta['price'] = !empty($save_item['price']) ? wpinv_sanitize_amount( $save_item['price'] ) : 0;  | 
                                                        |
| 375 | + $meta['price'] = !empty($save_item['price']) ? wpinv_sanitize_amount($save_item['price']) : 0;  | 
                                                        |
| 376 | 376 | $meta['vat_rule'] = !empty($save_item['vat_rule']) ? sanitize_text_field($save_item['vat_rule']) : 'digital';  | 
                                                        
| 377 | 377 | $meta['vat_class'] = !empty($save_item['vat_class']) ? sanitize_text_field($save_item['vat_class']) : '_standard';  | 
                                                        
| 378 | 378 | |
@@ -382,9 +382,9 @@ discard block  | 
                                                    ||
| 382 | 382 | $data['meta'] = $meta;  | 
                                                        
| 383 | 383 | |
| 384 | 384 | $item = new WPInv_Item();  | 
                                                        
| 385 | - $item->create( $data );  | 
                                                        |
| 385 | + $item->create($data);  | 
                                                        |
| 386 | 386 | |
| 387 | -        if ( !empty( $item ) ) { | 
                                                        |
| 387 | +        if (!empty($item)) { | 
                                                        |
| 388 | 388 | $_POST['item_id'] = $item->ID;  | 
                                                        
| 389 | 389 | $_POST['qty'] = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int)$save_item['qty'] : 1;  | 
                                                        
| 390 | 390 | |
@@ -394,15 +394,15 @@ discard block  | 
                                                    ||
| 394 | 394 | }  | 
                                                        
| 395 | 395 | |
| 396 | 396 |      public static function get_billing_details() { | 
                                                        
| 397 | - check_ajax_referer( 'get-billing-details', '_nonce' );  | 
                                                        |
| 397 | +        check_ajax_referer('get-billing-details', '_nonce'); | 
                                                        |
| 398 | 398 | |
| 399 | -        if ( !current_user_can( 'manage_options' ) ) { | 
                                                        |
| 399 | +        if (!current_user_can('manage_options')) { | 
                                                        |
| 400 | 400 | die(-1);  | 
                                                        
| 401 | 401 | }  | 
                                                        
| 402 | 402 | |
| 403 | 403 | $user_id = (int)$_POST['user_id'];  | 
                                                        
| 404 | 404 | $billing_details = wpinv_get_user_address($user_id);  | 
                                                        
| 405 | - $billing_details = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id );  | 
                                                        |
| 405 | +        $billing_details    = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id); | 
                                                        |
| 406 | 406 | |
| 407 | 407 |          if (isset($billing_details['user_id'])) { | 
                                                        
| 408 | 408 | unset($billing_details['user_id']);  | 
                                                        
@@ -416,20 +416,20 @@ discard block  | 
                                                    ||
| 416 | 416 | $response['success'] = true;  | 
                                                        
| 417 | 417 | $response['data']['billing_details'] = $billing_details;  | 
                                                        
| 418 | 418 | |
| 419 | - wp_send_json( $response );  | 
                                                        |
| 419 | + wp_send_json($response);  | 
                                                        |
| 420 | 420 | }  | 
                                                        
| 421 | 421 | |
| 422 | 422 |      public static function admin_recalculate_totals() { | 
                                                        
| 423 | 423 | global $wpi_userID, $wpinv_ip_address_country;  | 
                                                        
| 424 | 424 | |
| 425 | - check_ajax_referer( 'wpinv-nonce', '_nonce' );  | 
                                                        |
| 426 | -        if ( !current_user_can( 'manage_options' ) ) { | 
                                                        |
| 425 | +        check_ajax_referer('wpinv-nonce', '_nonce'); | 
                                                        |
| 426 | +        if (!current_user_can('manage_options')) { | 
                                                        |
| 427 | 427 | die(-1);  | 
                                                        
| 428 | 428 | }  | 
                                                        
| 429 | 429 | |
| 430 | - $invoice_id = absint( $_POST['invoice_id'] );  | 
                                                        |
| 431 | - $invoice = wpinv_get_invoice( $invoice_id );  | 
                                                        |
| 432 | -        if ( empty( $invoice ) ) { | 
                                                        |
| 430 | + $invoice_id = absint($_POST['invoice_id']);  | 
                                                        |
| 431 | + $invoice = wpinv_get_invoice($invoice_id);  | 
                                                        |
| 432 | +        if (empty($invoice)) { | 
                                                        |
| 433 | 433 | die();  | 
                                                        
| 434 | 434 | }  | 
                                                        
| 435 | 435 | |
@@ -437,23 +437,23 @@ discard block  | 
                                                    ||
| 437 | 437 | |
| 438 | 438 | $data = array();  | 
                                                        
| 439 | 439 | $data['invoice_id'] = $invoice_id;  | 
                                                        
| 440 | - $data['cart_discounts'] = $invoice->get_discounts( true );  | 
                                                        |
| 440 | + $data['cart_discounts'] = $invoice->get_discounts(true);  | 
                                                        |
| 441 | 441 | |
| 442 | - wpinv_set_checkout_session( $data );  | 
                                                        |
| 442 | + wpinv_set_checkout_session($data);  | 
                                                        |
| 443 | 443 | |
| 444 | -        if ( !empty( $_POST['user_id'] ) ) { | 
                                                        |
| 445 | - $wpi_userID = absint( $_POST['user_id'] );  | 
                                                        |
| 444 | +        if (!empty($_POST['user_id'])) { | 
                                                        |
| 445 | + $wpi_userID = absint($_POST['user_id']);  | 
                                                        |
| 446 | 446 | }  | 
                                                        
| 447 | 447 | |
| 448 | -        if ( empty( $_POST['country'] ) ) { | 
                                                        |
| 448 | +        if (empty($_POST['country'])) { | 
                                                        |
| 449 | 449 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();  | 
                                                        
| 450 | 450 | }  | 
                                                        
| 451 | 451 | |
| 452 | - $invoice->country = sanitize_text_field( $_POST['country'] );  | 
                                                        |
| 453 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );  | 
                                                        |
| 454 | -        if ( isset( $_POST['state'] ) ) { | 
                                                        |
| 455 | - $invoice->state = sanitize_text_field( $_POST['state'] );  | 
                                                        |
| 456 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );  | 
                                                        |
| 452 | + $invoice->country = sanitize_text_field($_POST['country']);  | 
                                                        |
| 453 | +        $invoice->set('country', sanitize_text_field($_POST['country'])); | 
                                                        |
| 454 | +        if (isset($_POST['state'])) { | 
                                                        |
| 455 | + $invoice->state = sanitize_text_field($_POST['state']);  | 
                                                        |
| 456 | +            $invoice->set('state', sanitize_text_field($_POST['state'])); | 
                                                        |
| 457 | 457 | }  | 
                                                        
| 458 | 458 | |
| 459 | 459 | $wpinv_ip_address_country = $invoice->country;  | 
                                                        
@@ -462,7 +462,7 @@ discard block  | 
                                                    ||
| 462 | 462 | |
| 463 | 463 | $response = array();  | 
                                                        
| 464 | 464 | $response['success'] = true;  | 
                                                        
| 465 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice );  | 
                                                        |
| 465 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice);  | 
                                                        |
| 466 | 466 | $response['data']['subtotal'] = $invoice->get_subtotal();  | 
                                                        
| 467 | 467 | $response['data']['subtotalf'] = $invoice->get_subtotal(true);  | 
                                                        
| 468 | 468 | $response['data']['tax'] = $invoice->get_tax();  | 
                                                        
@@ -474,25 +474,25 @@ discard block  | 
                                                    ||
| 474 | 474 | |
| 475 | 475 | wpinv_set_checkout_session($checkout_session);  | 
                                                        
| 476 | 476 | |
| 477 | - wp_send_json( $response );  | 
                                                        |
| 477 | + wp_send_json($response);  | 
                                                        |
| 478 | 478 | }  | 
                                                        
| 479 | 479 | |
| 480 | 480 |      public static function admin_apply_discount() { | 
                                                        
| 481 | 481 | global $wpi_userID;  | 
                                                        
| 482 | 482 | |
| 483 | - check_ajax_referer( 'wpinv-nonce', '_nonce' );  | 
                                                        |
| 484 | -        if ( !current_user_can( 'manage_options' ) ) { | 
                                                        |
| 483 | +        check_ajax_referer('wpinv-nonce', '_nonce'); | 
                                                        |
| 484 | +        if (!current_user_can('manage_options')) { | 
                                                        |
| 485 | 485 | die(-1);  | 
                                                        
| 486 | 486 | }  | 
                                                        
| 487 | 487 | |
| 488 | - $invoice_id = absint( $_POST['invoice_id'] );  | 
                                                        |
| 489 | - $discount_code = sanitize_text_field( $_POST['code'] );  | 
                                                        |
| 490 | -        if ( empty( $invoice_id ) || empty( $discount_code ) ) { | 
                                                        |
| 488 | + $invoice_id = absint($_POST['invoice_id']);  | 
                                                        |
| 489 | + $discount_code = sanitize_text_field($_POST['code']);  | 
                                                        |
| 490 | +        if (empty($invoice_id) || empty($discount_code)) { | 
                                                        |
| 491 | 491 | die();  | 
                                                        
| 492 | 492 | }  | 
                                                        
| 493 | 493 | |
| 494 | - $invoice = wpinv_get_invoice( $invoice_id );  | 
                                                        |
| 495 | -        if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) { | 
                                                        |
| 494 | + $invoice = wpinv_get_invoice($invoice_id);  | 
                                                        |
| 495 | +        if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) { | 
                                                        |
| 496 | 496 | die();  | 
                                                        
| 497 | 497 | }  | 
                                                        
| 498 | 498 | |
@@ -500,49 +500,49 @@ discard block  | 
                                                    ||
| 500 | 500 | |
| 501 | 501 | $data = array();  | 
                                                        
| 502 | 502 | $data['invoice_id'] = $invoice_id;  | 
                                                        
| 503 | - $data['cart_discounts'] = $invoice->get_discounts( true );  | 
                                                        |
| 503 | + $data['cart_discounts'] = $invoice->get_discounts(true);  | 
                                                        |
| 504 | 504 | |
| 505 | - wpinv_set_checkout_session( $data );  | 
                                                        |
| 505 | + wpinv_set_checkout_session($data);  | 
                                                        |
| 506 | 506 | |
| 507 | 507 | $response = array();  | 
                                                        
| 508 | 508 | $response['success'] = false;  | 
                                                        
| 509 | - $response['msg'] = __( 'This discount is invalid.', 'invoicing' );  | 
                                                        |
| 509 | +        $response['msg']        = __('This discount is invalid.', 'invoicing'); | 
                                                        |
| 510 | 510 | $response['data']['code'] = $discount_code;  | 
                                                        
| 511 | 511 | |
| 512 | -        if ( wpinv_is_discount_valid( $discount_code, $invoice->get_user_id() ) ) { | 
                                                        |
| 513 | - $discounts = wpinv_set_cart_discount( $discount_code );  | 
                                                        |
| 512 | +        if (wpinv_is_discount_valid($discount_code, $invoice->get_user_id())) { | 
                                                        |
| 513 | + $discounts = wpinv_set_cart_discount($discount_code);  | 
                                                        |
| 514 | 514 | |
| 515 | 515 | $response['success'] = true;  | 
                                                        
| 516 | - $response['msg'] = __( 'Discount has been applied successfully.', 'invoicing' );  | 
                                                        |
| 517 | -        }  else { | 
                                                        |
| 516 | +            $response['msg'] = __('Discount has been applied successfully.', 'invoicing'); | 
                                                        |
| 517 | +        } else { | 
                                                        |
| 518 | 518 | $errors = wpinv_get_errors();  | 
                                                        
| 519 | -            if ( !empty( $errors['wpinv-discount-error'] ) ) { | 
                                                        |
| 519 | +            if (!empty($errors['wpinv-discount-error'])) { | 
                                                        |
| 520 | 520 | $response['msg'] = $errors['wpinv-discount-error'];  | 
                                                        
| 521 | 521 | }  | 
                                                        
| 522 | - wpinv_unset_error( 'wpinv-discount-error' );  | 
                                                        |
| 522 | +            wpinv_unset_error('wpinv-discount-error'); | 
                                                        |
| 523 | 523 | }  | 
                                                        
| 524 | 524 | |
| 525 | 525 | wpinv_set_checkout_session($checkout_session);  | 
                                                        
| 526 | 526 | |
| 527 | - wp_send_json( $response );  | 
                                                        |
| 527 | + wp_send_json($response);  | 
                                                        |
| 528 | 528 | }  | 
                                                        
| 529 | 529 | |
| 530 | 530 |      public static function admin_remove_discount() { | 
                                                        
| 531 | 531 | global $wpi_userID;  | 
                                                        
| 532 | 532 | |
| 533 | - check_ajax_referer( 'wpinv-nonce', '_nonce' );  | 
                                                        |
| 534 | -        if ( !current_user_can( 'manage_options' ) ) { | 
                                                        |
| 533 | +        check_ajax_referer('wpinv-nonce', '_nonce'); | 
                                                        |
| 534 | +        if (!current_user_can('manage_options')) { | 
                                                        |
| 535 | 535 | die(-1);  | 
                                                        
| 536 | 536 | }  | 
                                                        
| 537 | 537 | |
| 538 | - $invoice_id = absint( $_POST['invoice_id'] );  | 
                                                        |
| 539 | - $discount_code = sanitize_text_field( $_POST['code'] );  | 
                                                        |
| 540 | -        if ( empty( $invoice_id ) || empty( $discount_code ) ) { | 
                                                        |
| 538 | + $invoice_id = absint($_POST['invoice_id']);  | 
                                                        |
| 539 | + $discount_code = sanitize_text_field($_POST['code']);  | 
                                                        |
| 540 | +        if (empty($invoice_id) || empty($discount_code)) { | 
                                                        |
| 541 | 541 | die();  | 
                                                        
| 542 | 542 | }  | 
                                                        
| 543 | 543 | |
| 544 | - $invoice = wpinv_get_invoice( $invoice_id );  | 
                                                        |
| 545 | -        if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) { | 
                                                        |
| 544 | + $invoice = wpinv_get_invoice($invoice_id);  | 
                                                        |
| 545 | +        if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) { | 
                                                        |
| 546 | 546 | die();  | 
                                                        
| 547 | 547 | }  | 
                                                        
| 548 | 548 | |
@@ -550,38 +550,38 @@ discard block  | 
                                                    ||
| 550 | 550 | |
| 551 | 551 | $data = array();  | 
                                                        
| 552 | 552 | $data['invoice_id'] = $invoice_id;  | 
                                                        
| 553 | - $data['cart_discounts'] = $invoice->get_discounts( true );  | 
                                                        |
| 553 | + $data['cart_discounts'] = $invoice->get_discounts(true);  | 
                                                        |
| 554 | 554 | |
| 555 | - wpinv_set_checkout_session( $data );  | 
                                                        |
| 555 | + wpinv_set_checkout_session($data);  | 
                                                        |
| 556 | 556 | |
| 557 | 557 | $response = array();  | 
                                                        
| 558 | 558 | $response['success'] = false;  | 
                                                        
| 559 | 559 | $response['msg'] = NULL;  | 
                                                        
| 560 | 560 | |
| 561 | - $discounts = wpinv_unset_cart_discount( $discount_code );  | 
                                                        |
| 561 | + $discounts = wpinv_unset_cart_discount($discount_code);  | 
                                                        |
| 562 | 562 | $response['success'] = true;  | 
                                                        
| 563 | - $response['msg'] = __( 'Discount has been removed successfully.', 'invoicing' );  | 
                                                        |
| 563 | +        $response['msg'] = __('Discount has been removed successfully.', 'invoicing'); | 
                                                        |
| 564 | 564 | |
| 565 | 565 | wpinv_set_checkout_session($checkout_session);  | 
                                                        
| 566 | 566 | |
| 567 | - wp_send_json( $response );  | 
                                                        |
| 567 | + wp_send_json($response);  | 
                                                        |
| 568 | 568 | }  | 
                                                        
| 569 | 569 | |
| 570 | 570 |      public static function check_email() { | 
                                                        
| 571 | - check_ajax_referer( 'wpinv-nonce', '_nonce' );  | 
                                                        |
| 572 | -        if ( !current_user_can( 'manage_options' ) ) { | 
                                                        |
| 571 | +        check_ajax_referer('wpinv-nonce', '_nonce'); | 
                                                        |
| 572 | +        if (!current_user_can('manage_options')) { | 
                                                        |
| 573 | 573 | die(-1);  | 
                                                        
| 574 | 574 | }  | 
                                                        
| 575 | 575 | |
| 576 | - $email = sanitize_text_field( $_POST['email'] );  | 
                                                        |
| 576 | + $email = sanitize_text_field($_POST['email']);  | 
                                                        |
| 577 | 577 | |
| 578 | 578 | $response = array();  | 
                                                        
| 579 | -        if ( is_email( $email ) && email_exists( $email ) && $user_data = get_user_by( 'email', $email ) ) { | 
                                                        |
| 579 | +        if (is_email($email) && email_exists($email) && $user_data = get_user_by('email', $email)) { | 
                                                        |
| 580 | 580 | $user_id = $user_data->ID;  | 
                                                        
| 581 | 581 | $user_login = $user_data->user_login;  | 
                                                        
| 582 | 582 | $display_name = $user_data->display_name ? $user_data->display_name : $user_login;  | 
                                                        
| 583 | 583 | $billing_details = wpinv_get_user_address($user_id);  | 
                                                        
| 584 | - $billing_details = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id );  | 
                                                        |
| 584 | +            $billing_details    = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id); | 
                                                        |
| 585 | 585 | |
| 586 | 586 |              if (isset($billing_details['user_id'])) { | 
                                                        
| 587 | 587 | unset($billing_details['user_id']);  | 
                                                        
@@ -597,54 +597,54 @@ discard block  | 
                                                    ||
| 597 | 597 | $response['data']['billing_details'] = $billing_details;  | 
                                                        
| 598 | 598 | }  | 
                                                        
| 599 | 599 | |
| 600 | - wp_send_json( $response );  | 
                                                        |
| 600 | + wp_send_json($response);  | 
                                                        |
| 601 | 601 | }  | 
                                                        
| 602 | 602 | |
| 603 | 603 |      public static function run_tool() { | 
                                                        
| 604 | - check_ajax_referer( 'wpinv-nonce', '_nonce' );  | 
                                                        |
| 605 | -        if ( !current_user_can( 'manage_options' ) ) { | 
                                                        |
| 604 | +        check_ajax_referer('wpinv-nonce', '_nonce'); | 
                                                        |
| 605 | +        if (!current_user_can('manage_options')) { | 
                                                        |
| 606 | 606 | die(-1);  | 
                                                        
| 607 | 607 | }  | 
                                                        
| 608 | 608 | |
| 609 | - $tool = sanitize_text_field( $_POST['tool'] );  | 
                                                        |
| 609 | + $tool = sanitize_text_field($_POST['tool']);  | 
                                                        |
| 610 | 610 | |
| 611 | - do_action( 'wpinv_run_tool' );  | 
                                                        |
| 611 | +        do_action('wpinv_run_tool'); | 
                                                        |
| 612 | 612 | |
| 613 | -        if ( !empty( $tool ) ) { | 
                                                        |
| 614 | - do_action( 'wpinv_tool_' . $tool );  | 
                                                        |
| 613 | +        if (!empty($tool)) { | 
                                                        |
| 614 | +            do_action('wpinv_tool_' . $tool); | 
                                                        |
| 615 | 615 | }  | 
                                                        
| 616 | 616 | }  | 
                                                        
| 617 | 617 | |
| 618 | 618 |      public static function apply_discount() { | 
                                                        
| 619 | 619 | global $wpi_userID;  | 
                                                        
| 620 | 620 | |
| 621 | - check_ajax_referer( 'wpinv-nonce', '_nonce' );  | 
                                                        |
| 621 | +        check_ajax_referer('wpinv-nonce', '_nonce'); | 
                                                        |
| 622 | 622 | |
| 623 | 623 | $response = array();  | 
                                                        
| 624 | 624 | |
| 625 | -        if ( isset( $_POST['code'] ) ) { | 
                                                        |
| 626 | - $discount_code = sanitize_text_field( $_POST['code'] );  | 
                                                        |
| 625 | +        if (isset($_POST['code'])) { | 
                                                        |
| 626 | + $discount_code = sanitize_text_field($_POST['code']);  | 
                                                        |
| 627 | 627 | |
| 628 | 628 | $response['success'] = false;  | 
                                                        
| 629 | 629 | $response['msg'] = '';  | 
                                                        
| 630 | 630 | $response['data']['code'] = $discount_code;  | 
                                                        
| 631 | 631 | |
| 632 | 632 | $invoice = wpinv_get_invoice_cart();  | 
                                                        
| 633 | -            if ( empty( $invoice->ID ) ) { | 
                                                        |
| 634 | - $response['msg'] = __( 'Invalid checkout request.', 'invoicing' );  | 
                                                        |
| 635 | - wp_send_json( $response );  | 
                                                        |
| 633 | +            if (empty($invoice->ID)) { | 
                                                        |
| 634 | +                $response['msg'] = __('Invalid checkout request.', 'invoicing'); | 
                                                        |
| 635 | + wp_send_json($response);  | 
                                                        |
| 636 | 636 | }  | 
                                                        
| 637 | 637 | |
| 638 | 638 | $wpi_userID = $invoice->get_user_id();  | 
                                                        
| 639 | 639 | |
| 640 | -            if ( wpinv_is_discount_valid( $discount_code, $wpi_userID ) ) { | 
                                                        |
| 641 | - $discount = wpinv_get_discount_by_code( $discount_code );  | 
                                                        |
| 642 | - $discounts = wpinv_set_cart_discount( $discount_code );  | 
                                                        |
| 643 | - $amount = wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) );  | 
                                                        |
| 644 | - $total = wpinv_get_cart_total( null, $discounts );  | 
                                                        |
| 645 | - $cart_totals = wpinv_recalculate_tax( true );  | 
                                                        |
| 640 | +            if (wpinv_is_discount_valid($discount_code, $wpi_userID)) { | 
                                                        |
| 641 | + $discount = wpinv_get_discount_by_code($discount_code);  | 
                                                        |
| 642 | + $discounts = wpinv_set_cart_discount($discount_code);  | 
                                                        |
| 643 | + $amount = wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID));  | 
                                                        |
| 644 | + $total = wpinv_get_cart_total(null, $discounts);  | 
                                                        |
| 645 | + $cart_totals = wpinv_recalculate_tax(true);  | 
                                                        |
| 646 | 646 | |
| 647 | -                if ( !empty( $cart_totals ) ) { | 
                                                        |
| 647 | +                if (!empty($cart_totals)) { | 
                                                        |
| 648 | 648 | $response['success'] = true;  | 
                                                        
| 649 | 649 | $response['data'] = $cart_totals;  | 
                                                        
| 650 | 650 | $response['data']['code'] = $discount_code;  | 
                                                        
@@ -653,29 +653,29 @@ discard block  | 
                                                    ||
| 653 | 653 | }  | 
                                                        
| 654 | 654 |              } else { | 
                                                        
| 655 | 655 | $errors = wpinv_get_errors();  | 
                                                        
| 656 | - $response['msg'] = $errors['wpinv-discount-error'];  | 
                                                        |
| 657 | - wpinv_unset_error( 'wpinv-discount-error' );  | 
                                                        |
| 656 | + $response['msg'] = $errors['wpinv-discount-error'];  | 
                                                        |
| 657 | +                wpinv_unset_error('wpinv-discount-error'); | 
                                                        |
| 658 | 658 | }  | 
                                                        
| 659 | 659 | |
| 660 | 660 | // Allow for custom discount code handling  | 
                                                        
| 661 | - $response = apply_filters( 'wpinv_ajax_discount_response', $response );  | 
                                                        |
| 661 | +            $response = apply_filters('wpinv_ajax_discount_response', $response); | 
                                                        |
| 662 | 662 | }  | 
                                                        
| 663 | 663 | |
| 664 | - wp_send_json( $response );  | 
                                                        |
| 664 | + wp_send_json($response);  | 
                                                        |
| 665 | 665 | }  | 
                                                        
| 666 | 666 | |
| 667 | 667 |      public static function remove_discount() { | 
                                                        
| 668 | - check_ajax_referer( 'wpinv-nonce', '_nonce' );  | 
                                                        |
| 668 | +        check_ajax_referer('wpinv-nonce', '_nonce'); | 
                                                        |
| 669 | 669 | |
| 670 | 670 | $response = array();  | 
                                                        
| 671 | 671 | |
| 672 | -        if ( isset( $_POST['code'] ) ) { | 
                                                        |
| 673 | - $discount_code = sanitize_text_field( $_POST['code'] );  | 
                                                        |
| 674 | - $discounts = wpinv_unset_cart_discount( $discount_code );  | 
                                                        |
| 675 | - $total = wpinv_get_cart_total( null, $discounts );  | 
                                                        |
| 676 | - $cart_totals = wpinv_recalculate_tax( true );  | 
                                                        |
| 672 | +        if (isset($_POST['code'])) { | 
                                                        |
| 673 | + $discount_code = sanitize_text_field($_POST['code']);  | 
                                                        |
| 674 | + $discounts = wpinv_unset_cart_discount($discount_code);  | 
                                                        |
| 675 | + $total = wpinv_get_cart_total(null, $discounts);  | 
                                                        |
| 676 | + $cart_totals = wpinv_recalculate_tax(true);  | 
                                                        |
| 677 | 677 | |
| 678 | -            if ( !empty( $cart_totals ) ) { | 
                                                        |
| 678 | +            if (!empty($cart_totals)) { | 
                                                        |
| 679 | 679 | $response['success'] = true;  | 
                                                        
| 680 | 680 | $response['data'] = $cart_totals;  | 
                                                        
| 681 | 681 | $response['data']['code'] = $discount_code;  | 
                                                        
@@ -684,10 +684,10 @@ discard block  | 
                                                    ||
| 684 | 684 | }  | 
                                                        
| 685 | 685 | |
| 686 | 686 | // Allow for custom discount code handling  | 
                                                        
| 687 | - $response = apply_filters( 'wpinv_ajax_discount_response', $response );  | 
                                                        |
| 687 | +            $response = apply_filters('wpinv_ajax_discount_response', $response); | 
                                                        |
| 688 | 688 | }  | 
                                                        
| 689 | 689 | |
| 690 | - wp_send_json( $response );  | 
                                                        |
| 690 | + wp_send_json($response);  | 
                                                        |
| 691 | 691 | }  | 
                                                        
| 692 | 692 | |
| 693 | 693 | |
@@ -699,53 +699,53 @@ discard block  | 
                                                    ||
| 699 | 699 |      public static function buy_items() { | 
                                                        
| 700 | 700 | $user_id = get_current_user_id();  | 
                                                        
| 701 | 701 | |
| 702 | -        if ( empty( $user_id ) ) { // If not logged in then lets redirect to the login page | 
                                                        |
| 703 | - wp_send_json( array(  | 
                                                        |
| 704 | - 'success' => wp_login_url( wp_get_referer() )  | 
                                                        |
| 705 | - ) );  | 
                                                        |
| 702 | +        if (empty($user_id)) { // If not logged in then lets redirect to the login page | 
                                                        |
| 703 | + wp_send_json(array(  | 
                                                        |
| 704 | + 'success' => wp_login_url(wp_get_referer())  | 
                                                        |
| 705 | + ));  | 
                                                        |
| 706 | 706 |          } else { | 
                                                        
| 707 | 707 | // Only check nonce if logged in as it could be cached when logged out.  | 
                                                        
| 708 | -            if ( ! isset( $_POST['wpinv_buy_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_buy_nonce'], 'wpinv_buy_items' ) ) { | 
                                                        |
| 709 | - wp_send_json( array(  | 
                                                        |
| 710 | - 'error' => __( 'Security checks failed.', 'invoicing' )  | 
                                                        |
| 711 | - ) );  | 
                                                        |
| 708 | +            if (!isset($_POST['wpinv_buy_nonce']) || !wp_verify_nonce($_POST['wpinv_buy_nonce'], 'wpinv_buy_items')) { | 
                                                        |
| 709 | + wp_send_json(array(  | 
                                                        |
| 710 | +                    'error' => __('Security checks failed.', 'invoicing') | 
                                                        |
| 711 | + ));  | 
                                                        |
| 712 | 712 | wp_die();  | 
                                                        
| 713 | 713 | }  | 
                                                        
| 714 | 714 | |
| 715 | 715 | // allow to set a custom price through post_id  | 
                                                        
| 716 | 716 | $items = $_POST['items'];  | 
                                                        
| 717 | - $related_post_id = isset( $_POST['post_id'] ) ? (int)$_POST['post_id'] : 0;  | 
                                                        |
| 718 | - $custom_item_price = $related_post_id ? abs( get_post_meta( $related_post_id, '_wpi_custom_price', true ) ) : 0;  | 
                                                        |
| 717 | + $related_post_id = isset($_POST['post_id']) ? (int)$_POST['post_id'] : 0;  | 
                                                        |
| 718 | + $custom_item_price = $related_post_id ? abs(get_post_meta($related_post_id, '_wpi_custom_price', true)) : 0;  | 
                                                        |
| 719 | 719 | |
| 720 | 720 | $cart_items = array();  | 
                                                        
| 721 | -            if ( $items ) { | 
                                                        |
| 722 | - $items = explode( ',', $items );  | 
                                                        |
| 721 | +            if ($items) { | 
                                                        |
| 722 | +                $items = explode(',', $items); | 
                                                        |
| 723 | 723 | |
| 724 | -                foreach( $items as $item ) { | 
                                                        |
| 724 | +                foreach ($items as $item) { | 
                                                        |
| 725 | 725 | $item_id = $item;  | 
                                                        
| 726 | 726 | $quantity = 1;  | 
                                                        
| 727 | 727 | |
| 728 | -                    if ( strpos( $item, '|' ) !== false ) { | 
                                                        |
| 729 | - $item_parts = explode( '|', $item );  | 
                                                        |
| 728 | +                    if (strpos($item, '|') !== false) { | 
                                                        |
| 729 | +                        $item_parts = explode('|', $item); | 
                                                        |
| 730 | 730 | $item_id = $item_parts[0];  | 
                                                        
| 731 | 731 | $quantity = $item_parts[1];  | 
                                                        
| 732 | 732 | }  | 
                                                        
| 733 | 733 | |
| 734 | -                    if ( $item_id && $quantity ) { | 
                                                        |
| 734 | +                    if ($item_id && $quantity) { | 
                                                        |
| 735 | 735 | $cart_items_arr = array(  | 
                                                        
| 736 | 736 | 'id' => (int)$item_id,  | 
                                                        
| 737 | 737 | 'quantity' => (int)$quantity  | 
                                                        
| 738 | 738 | );  | 
                                                        
| 739 | 739 | |
| 740 | 740 | // If there is a related post id then add it to meta  | 
                                                        
| 741 | -                        if ( $related_post_id ) { | 
                                                        |
| 741 | +                        if ($related_post_id) { | 
                                                        |
| 742 | 742 | $cart_items_arr['meta'] = array(  | 
                                                        
| 743 | 743 | 'post_id' => $related_post_id  | 
                                                        
| 744 | 744 | );  | 
                                                        
| 745 | 745 | }  | 
                                                        
| 746 | 746 | |
| 747 | 747 | // If there is a custom price then set it.  | 
                                                        
| 748 | -                        if ( $custom_item_price ) { | 
                                                        |
| 748 | +                        if ($custom_item_price) { | 
                                                        |
| 749 | 749 | $cart_items_arr['custom_price'] = $custom_item_price;  | 
                                                        
| 750 | 750 | }  | 
                                                        
| 751 | 751 | |
@@ -761,37 +761,37 @@ discard block  | 
                                                    ||
| 761 | 761 | * @param int $related_post_id The related post id if any.  | 
                                                        
| 762 | 762 | * @since 1.0.0  | 
                                                        
| 763 | 763 | */  | 
                                                        
| 764 | - $cart_items = apply_filters( 'wpinv_buy_cart_items', $cart_items, $related_post_id );  | 
                                                        |
| 764 | +            $cart_items = apply_filters('wpinv_buy_cart_items', $cart_items, $related_post_id); | 
                                                        |
| 765 | 765 | |
| 766 | 766 | // Make sure its not in the cart already, if it is then redirect to checkout.  | 
                                                        
| 767 | 767 | $cart_invoice = wpinv_get_invoice_cart();  | 
                                                        
| 768 | 768 | |
| 769 | -            if ( isset( $cart_invoice->items ) && !empty( $cart_invoice->items ) && !empty( $cart_items ) && serialize( $cart_invoice->items ) == serialize( $cart_items ) ) { | 
                                                        |
| 770 | - wp_send_json( array(  | 
                                                        |
| 769 | +            if (isset($cart_invoice->items) && !empty($cart_invoice->items) && !empty($cart_items) && serialize($cart_invoice->items) == serialize($cart_items)) { | 
                                                        |
| 770 | + wp_send_json(array(  | 
                                                        |
| 771 | 771 | 'success' => $cart_invoice->get_checkout_payment_url()  | 
                                                        
| 772 | - ) );  | 
                                                        |
| 772 | + ));  | 
                                                        |
| 773 | 773 | wp_die();  | 
                                                        
| 774 | 774 | }  | 
                                                        
| 775 | 775 | |
| 776 | 776 | // Check if user has invoice with same items waiting to be paid.  | 
                                                        
| 777 | - $user_invoices = wpinv_get_users_invoices( $user_id , 10 , false , 'wpi-pending' );  | 
                                                        |
| 778 | -            if ( !empty( $user_invoices ) ) { | 
                                                        |
| 779 | -                foreach( $user_invoices as $user_invoice ) { | 
                                                        |
| 777 | + $user_invoices = wpinv_get_users_invoices($user_id, 10, false, 'wpi-pending');  | 
                                                        |
| 778 | +            if (!empty($user_invoices)) { | 
                                                        |
| 779 | +                foreach ($user_invoices as $user_invoice) { | 
                                                        |
| 780 | 780 | $user_cart_details = array();  | 
                                                        
| 781 | - $invoice = wpinv_get_invoice( $user_invoice->ID );  | 
                                                        |
| 781 | + $invoice = wpinv_get_invoice($user_invoice->ID);  | 
                                                        |
| 782 | 782 | $cart_details = $invoice->get_cart_details();  | 
                                                        
| 783 | 783 | |
| 784 | -                    if ( !empty( $cart_details ) ) { | 
                                                        |
| 785 | -                        foreach ( $cart_details as $invoice_item ) { | 
                                                        |
| 784 | +                    if (!empty($cart_details)) { | 
                                                        |
| 785 | +                        foreach ($cart_details as $invoice_item) { | 
                                                        |
| 786 | 786 | $ii_arr = array();  | 
                                                        
| 787 | 787 | $ii_arr['id'] = (int)$invoice_item['id'];  | 
                                                        
| 788 | 788 | $ii_arr['quantity'] = (int)$invoice_item['quantity'];  | 
                                                        
| 789 | 789 | |
| 790 | -                            if (isset( $invoice_item['meta'] ) && !empty( $invoice_item['meta'] ) ) { | 
                                                        |
| 790 | +                            if (isset($invoice_item['meta']) && !empty($invoice_item['meta'])) { | 
                                                        |
| 791 | 791 | $ii_arr['meta'] = $invoice_item['meta'];  | 
                                                        
| 792 | 792 | }  | 
                                                        
| 793 | 793 | |
| 794 | -                            if ( isset( $invoice_item['custom_price'] ) && !empty( $invoice_item['custom_price'] ) ) { | 
                                                        |
| 794 | +                            if (isset($invoice_item['custom_price']) && !empty($invoice_item['custom_price'])) { | 
                                                        |
| 795 | 795 | $ii_arr['custom_price'] = $invoice_item['custom_price'];  | 
                                                        
| 796 | 796 | }  | 
                                                        
| 797 | 797 | |
@@ -799,17 +799,17 @@ discard block  | 
                                                    ||
| 799 | 799 | }  | 
                                                        
| 800 | 800 | }  | 
                                                        
| 801 | 801 | |
| 802 | -                    if ( !empty( $user_cart_details ) && serialize( $cart_items ) == serialize( $user_cart_details ) ) { | 
                                                        |
| 803 | - wp_send_json( array(  | 
                                                        |
| 802 | +                    if (!empty($user_cart_details) && serialize($cart_items) == serialize($user_cart_details)) { | 
                                                        |
| 803 | + wp_send_json(array(  | 
                                                        |
| 804 | 804 | 'success' => $invoice->get_checkout_payment_url()  | 
                                                        
| 805 | - ) );  | 
                                                        |
| 805 | + ));  | 
                                                        |
| 806 | 806 | wp_die();  | 
                                                        
| 807 | 807 | }  | 
                                                        
| 808 | 808 | }  | 
                                                        
| 809 | 809 | }  | 
                                                        
| 810 | 810 | |
| 811 | 811 | // Create invoice and send user to checkout  | 
                                                        
| 812 | -            if ( !empty( $cart_items ) ) { | 
                                                        |
| 812 | +            if (!empty($cart_items)) { | 
                                                        |
| 813 | 813 | $invoice_data = array(  | 
                                                        
| 814 | 814 | 'status' => 'wpi-pending',  | 
                                                        
| 815 | 815 | 'created_via' => 'wpi',  | 
                                                        
@@ -817,21 +817,21 @@ discard block  | 
                                                    ||
| 817 | 817 | 'cart_details' => $cart_items,  | 
                                                        
| 818 | 818 | );  | 
                                                        
| 819 | 819 | |
| 820 | - $invoice = wpinv_insert_invoice( $invoice_data, true );  | 
                                                        |
| 820 | + $invoice = wpinv_insert_invoice($invoice_data, true);  | 
                                                        |
| 821 | 821 | |
| 822 | -                if ( !empty( $invoice ) && isset( $invoice->ID ) ) { | 
                                                        |
| 823 | - wp_send_json( array(  | 
                                                        |
| 822 | +                if (!empty($invoice) && isset($invoice->ID)) { | 
                                                        |
| 823 | + wp_send_json(array(  | 
                                                        |
| 824 | 824 | 'success' => $invoice->get_checkout_payment_url()  | 
                                                        
| 825 | - ) );  | 
                                                        |
| 825 | + ));  | 
                                                        |
| 826 | 826 |                  } else { | 
                                                        
| 827 | - wp_send_json( array(  | 
                                                        |
| 828 | - 'error' => __( 'Invoice failed to create', 'invoicing' )  | 
                                                        |
| 829 | - ) );  | 
                                                        |
| 827 | + wp_send_json(array(  | 
                                                        |
| 828 | +                        'error' => __('Invoice failed to create', 'invoicing') | 
                                                        |
| 829 | + ));  | 
                                                        |
| 830 | 830 | }  | 
                                                        
| 831 | 831 |              } else { | 
                                                        
| 832 | - wp_send_json( array(  | 
                                                        |
| 833 | - 'error' => __( 'Items not valid.', 'invoicing' )  | 
                                                        |
| 834 | - ) );  | 
                                                        |
| 832 | + wp_send_json(array(  | 
                                                        |
| 833 | +                    'error' => __('Items not valid.', 'invoicing') | 
                                                        |
| 834 | + ));  | 
                                                        |
| 835 | 835 | }  | 
                                                        
| 836 | 836 | }  | 
                                                        
| 837 | 837 | |
@@ -1,6 +1,8 @@  | 
                                                    ||
| 1 | 1 | <?php  | 
                                                        
| 2 | 2 | // Exit if accessed directly.  | 
                                                        
| 3 | -if (!defined( 'ABSPATH' ) ) exit;  | 
                                                        |
| 3 | +if (!defined( 'ABSPATH' ) ) { | 
                                                        |
| 4 | + exit;  | 
                                                        |
| 5 | +}  | 
                                                        |
| 4 | 6 | |
| 5 | 7 | /**  | 
                                                        
| 6 | 8 | * The Subscriptions DB Class  | 
                                                        
@@ -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 | /**  | 
                                                        
| 6 | 6 | * The Subscriptions DB Class  | 
                                                        
@@ -68,8 +68,8 @@ discard block  | 
                                                    ||
| 68 | 68 | 'transaction_id' => '',  | 
                                                        
| 69 | 69 | 'parent_payment_id' => 0,  | 
                                                        
| 70 | 70 | 'product_id' => 0,  | 
                                                        
| 71 | - 'created' => date( 'Y-m-d H:i:s' ),  | 
                                                        |
| 72 | - 'expiration' => date( 'Y-m-d H:i:s' ),  | 
                                                        |
| 71 | +            'created'           => date('Y-m-d H:i:s'), | 
                                                        |
| 72 | +            'expiration'        => date('Y-m-d H:i:s'), | 
                                                        |
| 73 | 73 | 'trial_period' => '',  | 
                                                        
| 74 | 74 | 'status' => '',  | 
                                                        
| 75 | 75 | 'profile_id' => '',  | 
                                                        
@@ -82,11 +82,11 @@ discard block  | 
                                                    ||
| 82 | 82 | * @access public  | 
                                                        
| 83 | 83 | * @since 1.0.0  | 
                                                        
| 84 | 84 | */  | 
                                                        
| 85 | -    public function get_subscriptions( $args = array() ) { | 
                                                        |
| 85 | +    public function get_subscriptions($args = array()) { | 
                                                        |
| 86 | 86 | global $wpdb;  | 
                                                        
| 87 | 87 | |
| 88 | 88 | $defaults = array(  | 
                                                        
| 89 | - 'number' => get_option( 'posts_per_page' ),  | 
                                                        |
| 89 | +            'number'       => get_option('posts_per_page'), | 
                                                        |
| 90 | 90 | 'offset' => 0,  | 
                                                        
| 91 | 91 | 'search' => '',  | 
                                                        
| 92 | 92 | 'customer_id' => 0,  | 
                                                        
@@ -94,21 +94,21 @@ discard block  | 
                                                    ||
| 94 | 94 | 'order' => 'DESC'  | 
                                                        
| 95 | 95 | );  | 
                                                        
| 96 | 96 | |
| 97 | - $args = wp_parse_args( $args, $defaults );  | 
                                                        |
| 97 | + $args = wp_parse_args($args, $defaults);  | 
                                                        |
| 98 | 98 | |
| 99 | -        if( $args['number'] < 1 ) { | 
                                                        |
| 99 | +        if ($args['number'] < 1) { | 
                                                        |
| 100 | 100 | $args['number'] = 999999999999;  | 
                                                        
| 101 | 101 | }  | 
                                                        
| 102 | 102 | |
| 103 | 103 | $where = ' WHERE 1=1 ';  | 
                                                        
| 104 | 104 | |
| 105 | 105 | // specific customers  | 
                                                        
| 106 | -        if( ! empty( $args['id'] ) ) { | 
                                                        |
| 106 | +        if (!empty($args['id'])) { | 
                                                        |
| 107 | 107 | |
| 108 | -            if( is_array( $args['id'] ) ) { | 
                                                        |
| 109 | -                $ids = implode( ',', array_map('intval', $args['id'] ) ); | 
                                                        |
| 108 | +            if (is_array($args['id'])) { | 
                                                        |
| 109 | +                $ids = implode(',', array_map('intval', $args['id'])); | 
                                                        |
| 110 | 110 |              } else { | 
                                                        
| 111 | - $ids = intval( $args['id'] );  | 
                                                        |
| 111 | + $ids = intval($args['id']);  | 
                                                        |
| 112 | 112 | }  | 
                                                        
| 113 | 113 | |
| 114 | 114 |              $where .= " AND `id` IN( {$ids} ) "; | 
                                                        
@@ -116,12 +116,12 @@ discard block  | 
                                                    ||
| 116 | 116 | }  | 
                                                        
| 117 | 117 | |
| 118 | 118 | // Specific products  | 
                                                        
| 119 | -        if( ! empty( $args['product_id'] ) ) { | 
                                                        |
| 119 | +        if (!empty($args['product_id'])) { | 
                                                        |
| 120 | 120 | |
| 121 | -            if( is_array( $args['product_id'] ) ) { | 
                                                        |
| 122 | -                $product_ids = implode( ',', array_map('intval', $args['product_id'] ) ); | 
                                                        |
| 121 | +            if (is_array($args['product_id'])) { | 
                                                        |
| 122 | +                $product_ids = implode(',', array_map('intval', $args['product_id'])); | 
                                                        |
| 123 | 123 |              } else { | 
                                                        
| 124 | - $product_ids = intval( $args['product_id'] );  | 
                                                        |
| 124 | + $product_ids = intval($args['product_id']);  | 
                                                        |
| 125 | 125 | }  | 
                                                        
| 126 | 126 | |
| 127 | 127 |              $where .= " AND `product_id` IN( {$product_ids} ) "; | 
                                                        
@@ -129,12 +129,12 @@ discard block  | 
                                                    ||
| 129 | 129 | }  | 
                                                        
| 130 | 130 | |
| 131 | 131 | // Specific parent payments  | 
                                                        
| 132 | -        if( ! empty( $args['parent_payment_id'] ) ) { | 
                                                        |
| 132 | +        if (!empty($args['parent_payment_id'])) { | 
                                                        |
| 133 | 133 | |
| 134 | -            if( is_array( $args['parent_payment_id'] ) ) { | 
                                                        |
| 135 | -                $parent_payment_ids = implode( ',', array_map('intval', $args['parent_payment_id'] ) ); | 
                                                        |
| 134 | +            if (is_array($args['parent_payment_id'])) { | 
                                                        |
| 135 | +                $parent_payment_ids = implode(',', array_map('intval', $args['parent_payment_id'])); | 
                                                        |
| 136 | 136 |              } else { | 
                                                        
| 137 | - $parent_payment_ids = intval( $args['parent_payment_id'] );  | 
                                                        |
| 137 | + $parent_payment_ids = intval($args['parent_payment_id']);  | 
                                                        |
| 138 | 138 | }  | 
                                                        
| 139 | 139 | |
| 140 | 140 |              $where .= " AND `parent_payment_id` IN( {$parent_payment_ids} ) "; | 
                                                        
@@ -142,12 +142,12 @@ discard block  | 
                                                    ||
| 142 | 142 | }  | 
                                                        
| 143 | 143 | |
| 144 | 144 | // Specific transaction IDs  | 
                                                        
| 145 | -        if( ! empty( $args['transaction_id'] ) ) { | 
                                                        |
| 145 | +        if (!empty($args['transaction_id'])) { | 
                                                        |
| 146 | 146 | |
| 147 | -            if( is_array( $args['transaction_id'] ) ) { | 
                                                        |
| 148 | -                $transaction_ids = implode( "','", array_map('sanitize_text_field', $args['transaction_id'] ) ); | 
                                                        |
| 147 | +            if (is_array($args['transaction_id'])) { | 
                                                        |
| 148 | +                $transaction_ids = implode("','", array_map('sanitize_text_field', $args['transaction_id'])); | 
                                                        |
| 149 | 149 |              } else { | 
                                                        
| 150 | - $transaction_ids = sanitize_text_field( $args['transaction_id'] );  | 
                                                        |
| 150 | + $transaction_ids = sanitize_text_field($args['transaction_id']);  | 
                                                        |
| 151 | 151 | }  | 
                                                        
| 152 | 152 | |
| 153 | 153 |              $where .= " AND `transaction_id` IN ( '{$transaction_ids}' ) "; | 
                                                        
@@ -155,12 +155,12 @@ discard block  | 
                                                    ||
| 155 | 155 | }  | 
                                                        
| 156 | 156 | |
| 157 | 157 | // Subscriptoins for specific customers  | 
                                                        
| 158 | -        if( ! empty( $args['customer_id'] ) ) { | 
                                                        |
| 158 | +        if (!empty($args['customer_id'])) { | 
                                                        |
| 159 | 159 | |
| 160 | -            if( is_array( $args['customer_id'] ) ) { | 
                                                        |
| 161 | -                $customer_ids = implode( ',', array_map('intval', $args['customer_id'] ) ); | 
                                                        |
| 160 | +            if (is_array($args['customer_id'])) { | 
                                                        |
| 161 | +                $customer_ids = implode(',', array_map('intval', $args['customer_id'])); | 
                                                        |
| 162 | 162 |              } else { | 
                                                        
| 163 | - $customer_ids = intval( $args['customer_id'] );  | 
                                                        |
| 163 | + $customer_ids = intval($args['customer_id']);  | 
                                                        |
| 164 | 164 | }  | 
                                                        
| 165 | 165 | |
| 166 | 166 |              $where .= " AND `customer_id` IN( {$customer_ids} ) "; | 
                                                        
@@ -168,12 +168,12 @@ discard block  | 
                                                    ||
| 168 | 168 | }  | 
                                                        
| 169 | 169 | |
| 170 | 170 | // Subscriptions for specific profile IDs  | 
                                                        
| 171 | -        if( ! empty( $args['profile_id'] ) ) { | 
                                                        |
| 171 | +        if (!empty($args['profile_id'])) { | 
                                                        |
| 172 | 172 | |
| 173 | -            if( is_array( $args['profile_id'] ) ) { | 
                                                        |
| 174 | -                $profile_ids = implode( "','", array_map('sanitize_text_field', $args['profile_id'] ) ); | 
                                                        |
| 173 | +            if (is_array($args['profile_id'])) { | 
                                                        |
| 174 | +                $profile_ids = implode("','", array_map('sanitize_text_field', $args['profile_id'])); | 
                                                        |
| 175 | 175 |              } else { | 
                                                        
| 176 | - $profile_ids = sanitize_text_field( $args['profile_id'] );  | 
                                                        |
| 176 | + $profile_ids = sanitize_text_field($args['profile_id']);  | 
                                                        |
| 177 | 177 | }  | 
                                                        
| 178 | 178 | |
| 179 | 179 |              $where .= " AND `profile_id` IN( '{$profile_ids}' ) "; | 
                                                        
@@ -181,12 +181,12 @@ discard block  | 
                                                    ||
| 181 | 181 | }  | 
                                                        
| 182 | 182 | |
| 183 | 183 | // Subscriptions for specific statuses  | 
                                                        
| 184 | -        if( ! empty( $args['status'] ) ) { | 
                                                        |
| 184 | +        if (!empty($args['status'])) { | 
                                                        |
| 185 | 185 | |
| 186 | -            if( is_array( $args['status'] ) ) { | 
                                                        |
| 187 | - $statuses = implode( "','", array_map( 'sanitize_text_field', $args['status'] ) );  | 
                                                        |
| 186 | +            if (is_array($args['status'])) { | 
                                                        |
| 187 | +                $statuses = implode("','", array_map('sanitize_text_field', $args['status'])); | 
                                                        |
| 188 | 188 |              } else { | 
                                                        
| 189 | - $statuses = sanitize_text_field( $args['status'] );  | 
                                                        |
| 189 | + $statuses = sanitize_text_field($args['status']);  | 
                                                        |
| 190 | 190 | }  | 
                                                        
| 191 | 191 | |
| 192 | 192 |              $where .= " AND `status` IN( '{$statuses}' ) "; | 
                                                        
@@ -194,21 +194,21 @@ discard block  | 
                                                    ||
| 194 | 194 | }  | 
                                                        
| 195 | 195 | |
| 196 | 196 | // Subscriptions created for a specific date or in a date range  | 
                                                        
| 197 | -        if( ! empty( $args['date'] ) ) { | 
                                                        |
| 197 | +        if (!empty($args['date'])) { | 
                                                        |
| 198 | 198 | |
| 199 | -            if( is_array( $args['date'] ) ) { | 
                                                        |
| 199 | +            if (is_array($args['date'])) { | 
                                                        |
| 200 | 200 | |
| 201 | -                if( ! empty( $args['date']['start'] ) ) { | 
                                                        |
| 201 | +                if (!empty($args['date']['start'])) { | 
                                                        |
| 202 | 202 | |
| 203 | - $start = date( 'Y-m-d H:i:s', strtotime( $args['date']['start'] ) );  | 
                                                        |
| 203 | +                    $start = date('Y-m-d H:i:s', strtotime($args['date']['start'])); | 
                                                        |
| 204 | 204 | |
| 205 | 205 |                      $where .= " AND `created` >= '{$start}'"; | 
                                                        
| 206 | 206 | |
| 207 | 207 | }  | 
                                                        
| 208 | 208 | |
| 209 | -                if( ! empty( $args['date']['end'] ) ) { | 
                                                        |
| 209 | +                if (!empty($args['date']['end'])) { | 
                                                        |
| 210 | 210 | |
| 211 | - $end = date( 'Y-m-d H:i:s', strtotime( $args['date']['end'] ) );  | 
                                                        |
| 211 | +                    $end = date('Y-m-d H:i:s', strtotime($args['date']['end'])); | 
                                                        |
| 212 | 212 | |
| 213 | 213 |                      $where .= " AND `created` <= '{$end}'"; | 
                                                        
| 214 | 214 | |
@@ -216,9 +216,9 @@ discard block  | 
                                                    ||
| 216 | 216 | |
| 217 | 217 |              } else { | 
                                                        
| 218 | 218 | |
| 219 | - $year = date( 'Y', strtotime( $args['date'] ) );  | 
                                                        |
| 220 | - $month = date( 'm', strtotime( $args['date'] ) );  | 
                                                        |
| 221 | - $day = date( 'd', strtotime( $args['date'] ) );  | 
                                                        |
| 219 | +                $year  = date('Y', strtotime($args['date'])); | 
                                                        |
| 220 | +                $month = date('m', strtotime($args['date'])); | 
                                                        |
| 221 | +                $day   = date('d', strtotime($args['date'])); | 
                                                        |
| 222 | 222 | |
| 223 | 223 | $where .= " AND $year = YEAR ( created ) AND $month = MONTH ( created ) AND $day = DAY ( created )";  | 
                                                        
| 224 | 224 | }  | 
                                                        
@@ -226,21 +226,21 @@ discard block  | 
                                                    ||
| 226 | 226 | }  | 
                                                        
| 227 | 227 | |
| 228 | 228 | // Subscriptions with a specific expiration date or in an expiration date range  | 
                                                        
| 229 | -        if( ! empty( $args['expiration'] ) ) { | 
                                                        |
| 229 | +        if (!empty($args['expiration'])) { | 
                                                        |
| 230 | 230 | |
| 231 | -            if( is_array( $args['expiration'] ) ) { | 
                                                        |
| 231 | +            if (is_array($args['expiration'])) { | 
                                                        |
| 232 | 232 | |
| 233 | -                if( ! empty( $args['expiration']['start'] ) ) { | 
                                                        |
| 233 | +                if (!empty($args['expiration']['start'])) { | 
                                                        |
| 234 | 234 | |
| 235 | - $start = date( 'Y-m-d H:i:s', strtotime( $args['expiration']['start'] ) );  | 
                                                        |
| 235 | +                    $start = date('Y-m-d H:i:s', strtotime($args['expiration']['start'])); | 
                                                        |
| 236 | 236 | |
| 237 | 237 |                      $where .= " AND `expiration` >= '{$start}'"; | 
                                                        
| 238 | 238 | |
| 239 | 239 | }  | 
                                                        
| 240 | 240 | |
| 241 | -                if( ! empty( $args['expiration']['end'] ) ) { | 
                                                        |
| 241 | +                if (!empty($args['expiration']['end'])) { | 
                                                        |
| 242 | 242 | |
| 243 | - $end = date( 'Y-m-d H:i:s', strtotime( $args['expiration']['end'] ) );  | 
                                                        |
| 243 | +                    $end = date('Y-m-d H:i:s', strtotime($args['expiration']['end'])); | 
                                                        |
| 244 | 244 | |
| 245 | 245 |                      $where .= " AND `expiration` <= '{$end}'"; | 
                                                        
| 246 | 246 | |
@@ -248,73 +248,73 @@ discard block  | 
                                                    ||
| 248 | 248 | |
| 249 | 249 |              } else { | 
                                                        
| 250 | 250 | |
| 251 | - $year = date( 'Y', strtotime( $args['expiration'] ) );  | 
                                                        |
| 252 | - $month = date( 'm', strtotime( $args['expiration'] ) );  | 
                                                        |
| 253 | - $day = date( 'd', strtotime( $args['expiration'] ) );  | 
                                                        |
| 251 | +                $year  = date('Y', strtotime($args['expiration'])); | 
                                                        |
| 252 | +                $month = date('m', strtotime($args['expiration'])); | 
                                                        |
| 253 | +                $day   = date('d', strtotime($args['expiration'])); | 
                                                        |
| 254 | 254 | |
| 255 | 255 | $where .= " AND $year = YEAR ( expiration ) AND $month = MONTH ( expiration ) AND $day = DAY ( expiration )";  | 
                                                        
| 256 | 256 | }  | 
                                                        
| 257 | 257 | |
| 258 | 258 | }  | 
                                                        
| 259 | 259 | |
| 260 | -        if ( ! empty( $args['search'] ) ) { | 
                                                        |
| 260 | +        if (!empty($args['search'])) { | 
                                                        |
| 261 | 261 | |
| 262 | -            if( false !== strpos( 'id:', $args['search'] ) ) { | 
                                                        |
| 262 | +            if (false !== strpos('id:', $args['search'])) { | 
                                                        |
| 263 | 263 | |
| 264 | - $args['search'] = trim( str_replace( 'id:', '', $args['search'] ) );  | 
                                                        |
| 265 | - $where .= " AND `id` = '" . esc_sql( $args['search'] ) . "'";  | 
                                                        |
| 264 | +                $args['search'] = trim(str_replace('id:', '', $args['search'])); | 
                                                        |
| 265 | + $where .= " AND `id` = '" . esc_sql($args['search']) . "'";  | 
                                                        |
| 266 | 266 | |
| 267 | -            } else if( false !== strpos( $args['search'], 'txn:' ) ) { | 
                                                        |
| 267 | +            } else if (false !== strpos($args['search'], 'txn:')) { | 
                                                        |
| 268 | 268 | |
| 269 | - $args['search'] = trim( str_replace( 'txn:', '', $args['search'] ) );  | 
                                                        |
| 270 | - $where .= " AND `transaction_id` = '" . esc_sql( $args['search'] ) . "'";  | 
                                                        |
| 269 | +                $args['search'] = trim(str_replace('txn:', '', $args['search'])); | 
                                                        |
| 270 | + $where .= " AND `transaction_id` = '" . esc_sql($args['search']) . "'";  | 
                                                        |
| 271 | 271 | |
| 272 | -            } else if( false !== strpos( $args['search'], 'profile_id:' ) ) { | 
                                                        |
| 272 | +            } else if (false !== strpos($args['search'], 'profile_id:')) { | 
                                                        |
| 273 | 273 | |
| 274 | - $args['search'] = trim( str_replace( 'profile_id:', '', $args['search'] ) );  | 
                                                        |
| 275 | - $where .= " AND `profile_id` = '" . esc_sql( $args['search'] ) . "'";  | 
                                                        |
| 274 | +                $args['search'] = trim(str_replace('profile_id:', '', $args['search'])); | 
                                                        |
| 275 | + $where .= " AND `profile_id` = '" . esc_sql($args['search']) . "'";  | 
                                                        |
| 276 | 276 | |
| 277 | -            } else if( false !== strpos( $args['search'], 'product_id:' ) ) { | 
                                                        |
| 277 | +            } else if (false !== strpos($args['search'], 'product_id:')) { | 
                                                        |
| 278 | 278 | |
| 279 | - $args['search'] = trim( str_replace( 'product_id:', '', $args['search'] ) );  | 
                                                        |
| 280 | - $where .= " AND `product_id` = '" . esc_sql( $args['search'] ) . "'";  | 
                                                        |
| 279 | +                $args['search'] = trim(str_replace('product_id:', '', $args['search'])); | 
                                                        |
| 280 | + $where .= " AND `product_id` = '" . esc_sql($args['search']) . "'";  | 
                                                        |
| 281 | 281 | |
| 282 | -            } else if( false !== strpos( $args['search'], 'customer_id:' ) ) { | 
                                                        |
| 282 | +            } else if (false !== strpos($args['search'], 'customer_id:')) { | 
                                                        |
| 283 | 283 | |
| 284 | - $args['search'] = trim( str_replace( 'customer_id:', '', $args['search'] ) );  | 
                                                        |
| 285 | - $where .= " AND `customer_id` = '" . esc_sql( $args['search'] ) . "'";  | 
                                                        |
| 284 | +                $args['search'] = trim(str_replace('customer_id:', '', $args['search'])); | 
                                                        |
| 285 | + $where .= " AND `customer_id` = '" . esc_sql($args['search']) . "'";  | 
                                                        |
| 286 | 286 | |
| 287 | 287 |              } else { | 
                                                        
| 288 | 288 | |
| 289 | - $where .= " AND ( `parent_payment_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `profile_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `transaction_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `product_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `id` = '" . esc_sql( $args['search'] ) . "' )";  | 
                                                        |
| 289 | + $where .= " AND ( `parent_payment_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `profile_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `transaction_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `product_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `id` = '" . esc_sql($args['search']) . "' )";  | 
                                                        |
| 290 | 290 | |
| 291 | 291 | }  | 
                                                        
| 292 | 292 | |
| 293 | 293 | }  | 
                                                        
| 294 | 294 | |
| 295 | - $args['orderby'] = ! array_key_exists( $args['orderby'], $this->get_columns() ) ? 'id' : $args['orderby'];  | 
                                                        |
| 295 | + $args['orderby'] = !array_key_exists($args['orderby'], $this->get_columns()) ? 'id' : $args['orderby'];  | 
                                                        |
| 296 | 296 | |
| 297 | -        if( 'amount' == $args['orderby'] ) { | 
                                                        |
| 297 | +        if ('amount' == $args['orderby']) { | 
                                                        |
| 298 | 298 | $args['orderby'] = 'amount+0';  | 
                                                        
| 299 | 299 | }  | 
                                                        
| 300 | 300 | |
| 301 | - $cache_key = md5( 'wpinv_subscriptions_' . serialize( $args ) );  | 
                                                        |
| 301 | +        $cache_key = md5('wpinv_subscriptions_' . serialize($args)); | 
                                                        |
| 302 | 302 | |
| 303 | - $subscriptions = wp_cache_get( $cache_key, 'subscriptions' );  | 
                                                        |
| 303 | + $subscriptions = wp_cache_get($cache_key, 'subscriptions');  | 
                                                        |
| 304 | 304 | |
| 305 | - $args['orderby'] = esc_sql( $args['orderby'] );  | 
                                                        |
| 306 | - $args['order'] = esc_sql( $args['order'] );  | 
                                                        |
| 305 | + $args['orderby'] = esc_sql($args['orderby']);  | 
                                                        |
| 306 | + $args['order'] = esc_sql($args['order']);  | 
                                                        |
| 307 | 307 | |
| 308 | -        if( $subscriptions === false ) { | 
                                                        |
| 309 | -            $subscriptions = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM  $this->table_name $where ORDER BY {$args['orderby']} {$args['order']} LIMIT %d,%d;", absint( $args['offset'] ), absint( $args['number'] ) ), OBJECT ); | 
                                                        |
| 308 | +        if ($subscriptions === false) { | 
                                                        |
| 309 | +            $subscriptions = $wpdb->get_results($wpdb->prepare("SELECT * FROM  $this->table_name $where ORDER BY {$args['orderby']} {$args['order']} LIMIT %d,%d;", absint($args['offset']), absint($args['number'])), OBJECT); | 
                                                        |
| 310 | 310 | |
| 311 | -            if( ! empty( $subscriptions ) ) { | 
                                                        |
| 311 | +            if (!empty($subscriptions)) { | 
                                                        |
| 312 | 312 | |
| 313 | -                foreach( $subscriptions as $key => $subscription ) { | 
                                                        |
| 314 | - $subscriptions[ $key ] = new WPInv_Subscription( $subscription );  | 
                                                        |
| 313 | +                foreach ($subscriptions as $key => $subscription) { | 
                                                        |
| 314 | + $subscriptions[$key] = new WPInv_Subscription($subscription);  | 
                                                        |
| 315 | 315 | }  | 
                                                        
| 316 | 316 | |
| 317 | - wp_cache_set( $cache_key, $subscriptions, 'subscriptions', 3600 );  | 
                                                        |
| 317 | + wp_cache_set($cache_key, $subscriptions, 'subscriptions', 3600);  | 
                                                        |
| 318 | 318 | |
| 319 | 319 | }  | 
                                                        
| 320 | 320 | |
@@ -329,19 +329,19 @@ discard block  | 
                                                    ||
| 329 | 329 | * @access public  | 
                                                        
| 330 | 330 | * @since 1.0.0  | 
                                                        
| 331 | 331 | */  | 
                                                        
| 332 | -    public function count( $args = array() ) { | 
                                                        |
| 332 | +    public function count($args = array()) { | 
                                                        |
| 333 | 333 | |
| 334 | 334 | global $wpdb;  | 
                                                        
| 335 | 335 | |
| 336 | 336 | $where = ' WHERE 1=1 ';  | 
                                                        
| 337 | 337 | |
| 338 | 338 | // specific customers  | 
                                                        
| 339 | -        if( ! empty( $args['id'] ) ) { | 
                                                        |
| 339 | +        if (!empty($args['id'])) { | 
                                                        |
| 340 | 340 | |
| 341 | -            if( is_array( $args['id'] ) ) { | 
                                                        |
| 342 | -                $ids = implode( ',', array_map('intval', $args['id'] ) ); | 
                                                        |
| 341 | +            if (is_array($args['id'])) { | 
                                                        |
| 342 | +                $ids = implode(',', array_map('intval', $args['id'])); | 
                                                        |
| 343 | 343 |              } else { | 
                                                        
| 344 | - $ids = intval( $args['id'] );  | 
                                                        |
| 344 | + $ids = intval($args['id']);  | 
                                                        |
| 345 | 345 | }  | 
                                                        
| 346 | 346 | |
| 347 | 347 |              $where .= " AND `id` IN( {$ids} ) "; | 
                                                        
@@ -349,12 +349,12 @@ discard block  | 
                                                    ||
| 349 | 349 | }  | 
                                                        
| 350 | 350 | |
| 351 | 351 | // Specific products  | 
                                                        
| 352 | -        if( ! empty( $args['product_id'] ) ) { | 
                                                        |
| 352 | +        if (!empty($args['product_id'])) { | 
                                                        |
| 353 | 353 | |
| 354 | -            if( is_array( $args['product_id'] ) ) { | 
                                                        |
| 355 | -                $product_ids = implode( ',', array_map('intval', $args['product_id'] ) ); | 
                                                        |
| 354 | +            if (is_array($args['product_id'])) { | 
                                                        |
| 355 | +                $product_ids = implode(',', array_map('intval', $args['product_id'])); | 
                                                        |
| 356 | 356 |              } else { | 
                                                        
| 357 | - $product_ids = intval( $args['product_id'] );  | 
                                                        |
| 357 | + $product_ids = intval($args['product_id']);  | 
                                                        |
| 358 | 358 | }  | 
                                                        
| 359 | 359 | |
| 360 | 360 |              $where .= " AND `product_id` IN( {$product_ids} ) "; | 
                                                        
@@ -362,12 +362,12 @@ discard block  | 
                                                    ||
| 362 | 362 | }  | 
                                                        
| 363 | 363 | |
| 364 | 364 | // Specific parent payments  | 
                                                        
| 365 | -        if( ! empty( $args['parent_payment_id'] ) ) { | 
                                                        |
| 365 | +        if (!empty($args['parent_payment_id'])) { | 
                                                        |
| 366 | 366 | |
| 367 | -            if( is_array( $args['parent_payment_id'] ) ) { | 
                                                        |
| 368 | -                $parent_payment_ids = implode( ',', array_map('intval', $args['parent_payment_id'] ) ); | 
                                                        |
| 367 | +            if (is_array($args['parent_payment_id'])) { | 
                                                        |
| 368 | +                $parent_payment_ids = implode(',', array_map('intval', $args['parent_payment_id'])); | 
                                                        |
| 369 | 369 |              } else { | 
                                                        
| 370 | - $parent_payment_ids = intval( $args['parent_payment_id'] );  | 
                                                        |
| 370 | + $parent_payment_ids = intval($args['parent_payment_id']);  | 
                                                        |
| 371 | 371 | }  | 
                                                        
| 372 | 372 | |
| 373 | 373 |              $where .= " AND `parent_payment_id` IN( {$parent_payment_ids} ) "; | 
                                                        
@@ -375,12 +375,12 @@ discard block  | 
                                                    ||
| 375 | 375 | }  | 
                                                        
| 376 | 376 | |
| 377 | 377 | // Subscriptoins for specific customers  | 
                                                        
| 378 | -        if( ! empty( $args['customer_id'] ) ) { | 
                                                        |
| 378 | +        if (!empty($args['customer_id'])) { | 
                                                        |
| 379 | 379 | |
| 380 | -            if( is_array( $args['customer_id'] ) ) { | 
                                                        |
| 381 | -                $customer_ids = implode( ',', array_map('intval', $args['customer_id'] ) ); | 
                                                        |
| 380 | +            if (is_array($args['customer_id'])) { | 
                                                        |
| 381 | +                $customer_ids = implode(',', array_map('intval', $args['customer_id'])); | 
                                                        |
| 382 | 382 |              } else { | 
                                                        
| 383 | - $customer_ids = intval( $args['customer_id'] );  | 
                                                        |
| 383 | + $customer_ids = intval($args['customer_id']);  | 
                                                        |
| 384 | 384 | }  | 
                                                        
| 385 | 385 | |
| 386 | 386 |              $where .= " AND `customer_id` IN( {$customer_ids} ) "; | 
                                                        
@@ -388,12 +388,12 @@ discard block  | 
                                                    ||
| 388 | 388 | }  | 
                                                        
| 389 | 389 | |
| 390 | 390 | // Subscriptions for specific profile IDs  | 
                                                        
| 391 | -        if( ! empty( $args['profile_id'] ) ) { | 
                                                        |
| 391 | +        if (!empty($args['profile_id'])) { | 
                                                        |
| 392 | 392 | |
| 393 | -            if( is_array( $args['profile_id'] ) ) { | 
                                                        |
| 394 | -                $profile_ids = implode( ',', array_map('intval', $args['profile_id'] ) ); | 
                                                        |
| 393 | +            if (is_array($args['profile_id'])) { | 
                                                        |
| 394 | +                $profile_ids = implode(',', array_map('intval', $args['profile_id'])); | 
                                                        |
| 395 | 395 |              } else { | 
                                                        
| 396 | - $profile_ids = intval( $args['profile_id'] );  | 
                                                        |
| 396 | + $profile_ids = intval($args['profile_id']);  | 
                                                        |
| 397 | 397 | }  | 
                                                        
| 398 | 398 | |
| 399 | 399 |              $where .= " AND `profile_id` IN( {$profile_ids} ) "; | 
                                                        
@@ -401,12 +401,12 @@ discard block  | 
                                                    ||
| 401 | 401 | }  | 
                                                        
| 402 | 402 | |
| 403 | 403 | // Specific transaction IDs  | 
                                                        
| 404 | -        if( ! empty( $args['transaction_id'] ) ) { | 
                                                        |
| 404 | +        if (!empty($args['transaction_id'])) { | 
                                                        |
| 405 | 405 | |
| 406 | -            if( is_array( $args['transaction_id'] ) ) { | 
                                                        |
| 407 | -                $transaction_ids = implode( ',', array_map('sanitize_text_field', $args['transaction_id'] ) ); | 
                                                        |
| 406 | +            if (is_array($args['transaction_id'])) { | 
                                                        |
| 407 | +                $transaction_ids = implode(',', array_map('sanitize_text_field', $args['transaction_id'])); | 
                                                        |
| 408 | 408 |              } else { | 
                                                        
| 409 | - $transaction_ids = sanitize_text_field( $args['transaction_id'] );  | 
                                                        |
| 409 | + $transaction_ids = sanitize_text_field($args['transaction_id']);  | 
                                                        |
| 410 | 410 | }  | 
                                                        
| 411 | 411 | |
| 412 | 412 |              $where .= " AND `transaction_id` IN( {$transaction_ids} ) "; | 
                                                        
@@ -414,10 +414,10 @@ discard block  | 
                                                    ||
| 414 | 414 | }  | 
                                                        
| 415 | 415 | |
| 416 | 416 | // Subscriptions for specific statuses  | 
                                                        
| 417 | -        if( ! empty( $args['status'] ) ) { | 
                                                        |
| 417 | +        if (!empty($args['status'])) { | 
                                                        |
| 418 | 418 | |
| 419 | -            if( is_array( $args['status'] ) ) { | 
                                                        |
| 420 | - $statuses = implode( ',', $args['status'] );  | 
                                                        |
| 419 | +            if (is_array($args['status'])) { | 
                                                        |
| 420 | +                $statuses = implode(',', $args['status']); | 
                                                        |
| 421 | 421 |                  $where  .= " AND `status` IN( {$statuses} ) "; | 
                                                        
| 422 | 422 |              } else { | 
                                                        
| 423 | 423 | $statuses = $args['status'];  | 
                                                        
@@ -429,21 +429,21 @@ discard block  | 
                                                    ||
| 429 | 429 | }  | 
                                                        
| 430 | 430 | |
| 431 | 431 | // Subscriptions created for a specific date or in a date range  | 
                                                        
| 432 | -        if( ! empty( $args['date'] ) ) { | 
                                                        |
| 432 | +        if (!empty($args['date'])) { | 
                                                        |
| 433 | 433 | |
| 434 | -            if( is_array( $args['date'] ) ) { | 
                                                        |
| 434 | +            if (is_array($args['date'])) { | 
                                                        |
| 435 | 435 | |
| 436 | -                if( ! empty( $args['date']['start'] ) ) { | 
                                                        |
| 436 | +                if (!empty($args['date']['start'])) { | 
                                                        |
| 437 | 437 | |
| 438 | - $start = date( 'Y-m-d H:i:s', strtotime( $args['date']['start'] ) );  | 
                                                        |
| 438 | +                    $start = date('Y-m-d H:i:s', strtotime($args['date']['start'])); | 
                                                        |
| 439 | 439 | |
| 440 | 440 |                      $where .= " AND `created` >= '{$start}'"; | 
                                                        
| 441 | 441 | |
| 442 | 442 | }  | 
                                                        
| 443 | 443 | |
| 444 | -                if( ! empty( $args['date']['end'] ) ) { | 
                                                        |
| 444 | +                if (!empty($args['date']['end'])) { | 
                                                        |
| 445 | 445 | |
| 446 | - $end = date( 'Y-m-d H:i:s', strtotime( $args['date']['end'] ) );  | 
                                                        |
| 446 | +                    $end = date('Y-m-d H:i:s', strtotime($args['date']['end'])); | 
                                                        |
| 447 | 447 | |
| 448 | 448 |                      $where .= " AND `created` <= '{$end}'"; | 
                                                        
| 449 | 449 | |
@@ -451,9 +451,9 @@ discard block  | 
                                                    ||
| 451 | 451 | |
| 452 | 452 |              } else { | 
                                                        
| 453 | 453 | |
| 454 | - $year = date( 'Y', strtotime( $args['date'] ) );  | 
                                                        |
| 455 | - $month = date( 'm', strtotime( $args['date'] ) );  | 
                                                        |
| 456 | - $day = date( 'd', strtotime( $args['date'] ) );  | 
                                                        |
| 454 | +                $year  = date('Y', strtotime($args['date'])); | 
                                                        |
| 455 | +                $month = date('m', strtotime($args['date'])); | 
                                                        |
| 456 | +                $day   = date('d', strtotime($args['date'])); | 
                                                        |
| 457 | 457 | |
| 458 | 458 | $where .= " AND $year = YEAR ( created ) AND $month = MONTH ( created ) AND $day = DAY ( created )";  | 
                                                        
| 459 | 459 | }  | 
                                                        
@@ -461,21 +461,21 @@ discard block  | 
                                                    ||
| 461 | 461 | }  | 
                                                        
| 462 | 462 | |
| 463 | 463 | // Subscriptions with a specific expiration date or in an expiration date range  | 
                                                        
| 464 | -        if( ! empty( $args['expiration'] ) ) { | 
                                                        |
| 464 | +        if (!empty($args['expiration'])) { | 
                                                        |
| 465 | 465 | |
| 466 | -            if( is_array( $args['expiration'] ) ) { | 
                                                        |
| 466 | +            if (is_array($args['expiration'])) { | 
                                                        |
| 467 | 467 | |
| 468 | -                if( ! empty( $args['expiration']['start'] ) ) { | 
                                                        |
| 468 | +                if (!empty($args['expiration']['start'])) { | 
                                                        |
| 469 | 469 | |
| 470 | - $start = date( 'Y-m-d H:i:s', strtotime( $args['expiration']['start'] ) );  | 
                                                        |
| 470 | +                    $start = date('Y-m-d H:i:s', strtotime($args['expiration']['start'])); | 
                                                        |
| 471 | 471 | |
| 472 | 472 |                      $where .= " AND `expiration` >= '{$start}'"; | 
                                                        
| 473 | 473 | |
| 474 | 474 | }  | 
                                                        
| 475 | 475 | |
| 476 | -                if( ! empty( $args['expiration']['end'] ) ) { | 
                                                        |
| 476 | +                if (!empty($args['expiration']['end'])) { | 
                                                        |
| 477 | 477 | |
| 478 | - $end = date( 'Y-m-d H:i:s', strtotime( $args['expiration']['end'] ) );  | 
                                                        |
| 478 | +                    $end = date('Y-m-d H:i:s', strtotime($args['expiration']['end'])); | 
                                                        |
| 479 | 479 | |
| 480 | 480 |                      $where .= " AND `expiration` <= '{$end}'"; | 
                                                        
| 481 | 481 | |
@@ -483,64 +483,64 @@ discard block  | 
                                                    ||
| 483 | 483 | |
| 484 | 484 |              } else { | 
                                                        
| 485 | 485 | |
| 486 | - $year = date( 'Y', strtotime( $args['expiration'] ) );  | 
                                                        |
| 487 | - $month = date( 'm', strtotime( $args['expiration'] ) );  | 
                                                        |
| 488 | - $day = date( 'd', strtotime( $args['expiration'] ) );  | 
                                                        |
| 486 | +                $year  = date('Y', strtotime($args['expiration'])); | 
                                                        |
| 487 | +                $month = date('m', strtotime($args['expiration'])); | 
                                                        |
| 488 | +                $day   = date('d', strtotime($args['expiration'])); | 
                                                        |
| 489 | 489 | |
| 490 | 490 | $where .= " AND $year = YEAR ( expiration ) AND $month = MONTH ( expiration ) AND $day = DAY ( expiration )";  | 
                                                        
| 491 | 491 | }  | 
                                                        
| 492 | 492 | |
| 493 | 493 | }  | 
                                                        
| 494 | 494 | |
| 495 | -        if ( ! empty( $args['search'] ) ) { | 
                                                        |
| 495 | +        if (!empty($args['search'])) { | 
                                                        |
| 496 | 496 | |
| 497 | -            if( false !== strpos( 'id:', $args['search'] ) ) { | 
                                                        |
| 497 | +            if (false !== strpos('id:', $args['search'])) { | 
                                                        |
| 498 | 498 | |
| 499 | - $args['search'] = trim( str_replace( 'id:', '', $args['search'] ) );  | 
                                                        |
| 500 | - $where .= " AND `id` = '" . esc_sql( $args['search'] ) . "'";  | 
                                                        |
| 499 | +                $args['search'] = trim(str_replace('id:', '', $args['search'])); | 
                                                        |
| 500 | + $where .= " AND `id` = '" . esc_sql($args['search']) . "'";  | 
                                                        |
| 501 | 501 | |
| 502 | -            } else if( false !== strpos( $args['search'], 'txn:' ) ) { | 
                                                        |
| 502 | +            } else if (false !== strpos($args['search'], 'txn:')) { | 
                                                        |
| 503 | 503 | |
| 504 | - $args['search'] = trim( str_replace( 'txn:', '', $args['search'] ) );  | 
                                                        |
| 505 | - $where .= " AND `transaction_id` = '" . esc_sql( $args['search'] ) . "'";  | 
                                                        |
| 504 | +                $args['search'] = trim(str_replace('txn:', '', $args['search'])); | 
                                                        |
| 505 | + $where .= " AND `transaction_id` = '" . esc_sql($args['search']) . "'";  | 
                                                        |
| 506 | 506 | |
| 507 | -            } else if( false !== strpos( $args['search'], 'profile_id:' ) ) { | 
                                                        |
| 507 | +            } else if (false !== strpos($args['search'], 'profile_id:')) { | 
                                                        |
| 508 | 508 | |
| 509 | - $args['search'] = trim( str_replace( 'profile_id:', '', $args['search'] ) );  | 
                                                        |
| 510 | - $where .= " AND `profile_id` = '" . esc_sql( $args['search'] ) . "'";  | 
                                                        |
| 509 | +                $args['search'] = trim(str_replace('profile_id:', '', $args['search'])); | 
                                                        |
| 510 | + $where .= " AND `profile_id` = '" . esc_sql($args['search']) . "'";  | 
                                                        |
| 511 | 511 | |
| 512 | -            } else if( false !== strpos( $args['search'], 'product_id:' ) ) { | 
                                                        |
| 512 | +            } else if (false !== strpos($args['search'], 'product_id:')) { | 
                                                        |
| 513 | 513 | |
| 514 | - $args['search'] = trim( str_replace( 'product_id:', '', $args['search'] ) );  | 
                                                        |
| 515 | - $where .= " AND `product_id` = '" . esc_sql( $args['search'] ) . "'";  | 
                                                        |
| 514 | +                $args['search'] = trim(str_replace('product_id:', '', $args['search'])); | 
                                                        |
| 515 | + $where .= " AND `product_id` = '" . esc_sql($args['search']) . "'";  | 
                                                        |
| 516 | 516 | |
| 517 | -            } else if( false !== strpos( $args['search'], 'customer_id:' ) ) { | 
                                                        |
| 517 | +            } else if (false !== strpos($args['search'], 'customer_id:')) { | 
                                                        |
| 518 | 518 | |
| 519 | - $args['search'] = trim( str_replace( 'customer_id:', '', $args['search'] ) );  | 
                                                        |
| 520 | - $where .= " AND `customer_id` = '" . esc_sql( $args['search'] ) . "'";  | 
                                                        |
| 519 | +                $args['search'] = trim(str_replace('customer_id:', '', $args['search'])); | 
                                                        |
| 520 | + $where .= " AND `customer_id` = '" . esc_sql($args['search']) . "'";  | 
                                                        |
| 521 | 521 | |
| 522 | 522 |              } else { | 
                                                        
| 523 | 523 | |
| 524 | - $where .= " AND ( `parent_payment_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `profile_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `transaction_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `product_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `id` = '" . esc_sql( $args['search'] ) . "' )";  | 
                                                        |
| 524 | + $where .= " AND ( `parent_payment_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `profile_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `transaction_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `product_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `id` = '" . esc_sql($args['search']) . "' )";  | 
                                                        |
| 525 | 525 | |
| 526 | 526 | }  | 
                                                        
| 527 | 527 | |
| 528 | 528 | }  | 
                                                        
| 529 | 529 | |
| 530 | - $cache_key = md5( 'wpinv_subscriptions_count' . serialize( $args ) );  | 
                                                        |
| 530 | +        $cache_key = md5('wpinv_subscriptions_count' . serialize($args)); | 
                                                        |
| 531 | 531 | |
| 532 | - $count = wp_cache_get( $cache_key, 'subscriptions' );  | 
                                                        |
| 532 | + $count = wp_cache_get($cache_key, 'subscriptions');  | 
                                                        |
| 533 | 533 | |
| 534 | -        if( $count === false ) { | 
                                                        |
| 534 | +        if ($count === false) { | 
                                                        |
| 535 | 535 | |
| 536 | 536 |              $sql   = "SELECT COUNT($this->primary_key) FROM " . $this->table_name . "{$where};"; | 
                                                        
| 537 | - $count = $wpdb->get_var( $sql );  | 
                                                        |
| 537 | + $count = $wpdb->get_var($sql);  | 
                                                        |
| 538 | 538 | |
| 539 | - wp_cache_set( $cache_key, $count, 'subscriptions', 3600 );  | 
                                                        |
| 539 | + wp_cache_set($cache_key, $count, 'subscriptions', 3600);  | 
                                                        |
| 540 | 540 | |
| 541 | 541 | }  | 
                                                        
| 542 | 542 | |
| 543 | - return absint( $count );  | 
                                                        |
| 543 | + return absint($count);  | 
                                                        |
| 544 | 544 | |
| 545 | 545 | }  | 
                                                        
| 546 | 546 | |
@@ -553,7 +553,7 @@ discard block  | 
                                                    ||
| 553 | 553 |      public function create_table() { | 
                                                        
| 554 | 554 | global $wpdb;  | 
                                                        
| 555 | 555 | |
| 556 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );  | 
                                                        |
| 556 | + require_once(ABSPATH . 'wp-admin/includes/upgrade.php');  | 
                                                        |
| 557 | 557 | |
| 558 | 558 | $sql = "CREATE TABLE " . $this->table_name . " (  | 
                                                        
| 559 | 559 | id bigint(20) NOT NULL AUTO_INCREMENT,  | 
                                                        
@@ -578,9 +578,9 @@ discard block  | 
                                                    ||
| 578 | 578 | KEY customer_and_status ( customer_id, status)  | 
                                                        
| 579 | 579 | ) CHARACTER SET utf8 COLLATE utf8_general_ci;";  | 
                                                        
| 580 | 580 | |
| 581 | - dbDelta( $sql );  | 
                                                        |
| 581 | + dbDelta($sql);  | 
                                                        |
| 582 | 582 | |
| 583 | - update_option( $this->table_name . '_db_version', $this->version );  | 
                                                        |
| 583 | + update_option($this->table_name . '_db_version', $this->version);  | 
                                                        |
| 584 | 584 | }  | 
                                                        
| 585 | 585 | |
| 586 | 586 | }  | 
                                                        
| 587 | 587 | \ No newline at end of file  | 
                                                        
@@ -5,237 +5,237 @@  | 
                                                    ||
| 5 | 5 | |
| 6 | 6 |  abstract class Wpinv_DB { | 
                                                        
| 7 | 7 | |
| 8 | - /**  | 
                                                        |
| 9 | - * The name of our database table  | 
                                                        |
| 10 | - *  | 
                                                        |
| 11 | - * @access public  | 
                                                        |
| 12 | - * @since 1.0.0  | 
                                                        |
| 13 | - */  | 
                                                        |
| 14 | - public $table_name;  | 
                                                        |
| 15 | -  | 
                                                        |
| 16 | - /**  | 
                                                        |
| 17 | - * The version of our database table  | 
                                                        |
| 18 | - *  | 
                                                        |
| 19 | - * @access public  | 
                                                        |
| 20 | - * @since 1.0.0  | 
                                                        |
| 21 | - */  | 
                                                        |
| 22 | - public $version;  | 
                                                        |
| 23 | -  | 
                                                        |
| 24 | - /**  | 
                                                        |
| 25 | - * The name of the primary column  | 
                                                        |
| 26 | - *  | 
                                                        |
| 27 | - * @access public  | 
                                                        |
| 28 | - * @since 1.0.0  | 
                                                        |
| 29 | - */  | 
                                                        |
| 30 | - public $primary_key;  | 
                                                        |
| 31 | -  | 
                                                        |
| 32 | - /**  | 
                                                        |
| 33 | - * Get things started  | 
                                                        |
| 34 | - *  | 
                                                        |
| 35 | - * @access public  | 
                                                        |
| 36 | - * @since 1.0.0  | 
                                                        |
| 37 | - */  | 
                                                        |
| 38 | -	public function __construct() {} | 
                                                        |
| 39 | -  | 
                                                        |
| 40 | - /**  | 
                                                        |
| 41 | - * Whitelist of columns  | 
                                                        |
| 42 | - *  | 
                                                        |
| 43 | - * @access public  | 
                                                        |
| 44 | - * @since 1.0.0  | 
                                                        |
| 45 | - * @return array  | 
                                                        |
| 46 | - */  | 
                                                        |
| 47 | -	public function get_columns() { | 
                                                        |
| 48 | - return array();  | 
                                                        |
| 49 | - }  | 
                                                        |
| 50 | -  | 
                                                        |
| 51 | - /**  | 
                                                        |
| 52 | - * Default column values  | 
                                                        |
| 53 | - *  | 
                                                        |
| 54 | - * @access public  | 
                                                        |
| 55 | - * @since 1.0.0  | 
                                                        |
| 56 | - * @return array  | 
                                                        |
| 57 | - */  | 
                                                        |
| 58 | -	public function get_column_defaults() { | 
                                                        |
| 59 | - return array();  | 
                                                        |
| 60 | - }  | 
                                                        |
| 61 | -  | 
                                                        |
| 62 | - /**  | 
                                                        |
| 63 | - * Retrieve a row by the primary key  | 
                                                        |
| 64 | - *  | 
                                                        |
| 65 | - * @access public  | 
                                                        |
| 66 | - * @since 1.0.0  | 
                                                        |
| 67 | - * @return object  | 
                                                        |
| 68 | - */  | 
                                                        |
| 69 | -	public function get( $row_id ) { | 
                                                        |
| 70 | - global $wpdb;  | 
                                                        |
| 71 | - return $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id ) );  | 
                                                        |
| 72 | - }  | 
                                                        |
| 73 | -  | 
                                                        |
| 74 | - /**  | 
                                                        |
| 75 | - * Retrieve a row by a specific column / value  | 
                                                        |
| 76 | - *  | 
                                                        |
| 77 | - * @access public  | 
                                                        |
| 78 | - * @since 1.0.0  | 
                                                        |
| 79 | - * @return object  | 
                                                        |
| 80 | - */  | 
                                                        |
| 81 | -	public function get_by( $column, $row_id ) { | 
                                                        |
| 82 | - global $wpdb;  | 
                                                        |
| 83 | - $column = esc_sql( $column );  | 
                                                        |
| 84 | - return $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $this->table_name WHERE $column = %s LIMIT 1;", $row_id ) );  | 
                                                        |
| 85 | - }  | 
                                                        |
| 86 | -  | 
                                                        |
| 87 | - /**  | 
                                                        |
| 88 | - * Retrieve a specific column's value by the primary key  | 
                                                        |
| 89 | - *  | 
                                                        |
| 90 | - * @access public  | 
                                                        |
| 91 | - * @since 1.0.0  | 
                                                        |
| 92 | - * @return string  | 
                                                        |
| 93 | - */  | 
                                                        |
| 94 | -	public function get_column( $column, $row_id ) { | 
                                                        |
| 95 | - global $wpdb;  | 
                                                        |
| 96 | - $column = esc_sql( $column );  | 
                                                        |
| 97 | - return $wpdb->get_var( $wpdb->prepare( "SELECT $column FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id ) );  | 
                                                        |
| 98 | - }  | 
                                                        |
| 99 | -  | 
                                                        |
| 100 | - /**  | 
                                                        |
| 101 | - * Retrieve a specific column's value by the the specified column / value  | 
                                                        |
| 102 | - *  | 
                                                        |
| 103 | - * @access public  | 
                                                        |
| 104 | - * @since 1.0.0  | 
                                                        |
| 105 | - * @return string  | 
                                                        |
| 106 | - */  | 
                                                        |
| 107 | -	public function get_column_by( $column, $column_where, $column_value ) { | 
                                                        |
| 108 | - global $wpdb;  | 
                                                        |
| 109 | - $column_where = esc_sql( $column_where );  | 
                                                        |
| 110 | - $column = esc_sql( $column );  | 
                                                        |
| 111 | - return $wpdb->get_var( $wpdb->prepare( "SELECT $column FROM $this->table_name WHERE $column_where = %s LIMIT 1;", $column_value ) );  | 
                                                        |
| 112 | - }  | 
                                                        |
| 113 | -  | 
                                                        |
| 114 | - /**  | 
                                                        |
| 115 | - * Insert a new row  | 
                                                        |
| 116 | - *  | 
                                                        |
| 117 | - * @access public  | 
                                                        |
| 118 | - * @since 1.0.0  | 
                                                        |
| 119 | - * @return int  | 
                                                        |
| 120 | - */  | 
                                                        |
| 121 | -	public function insert( $data, $type = '' ) { | 
                                                        |
| 122 | - global $wpdb;  | 
                                                        |
| 123 | -  | 
                                                        |
| 124 | - // Set default values  | 
                                                        |
| 125 | - $data = wp_parse_args( $data, $this->get_column_defaults() );  | 
                                                        |
| 126 | -  | 
                                                        |
| 127 | - do_action( 'wpinv_pre_insert_' . $type, $data );  | 
                                                        |
| 128 | -  | 
                                                        |
| 129 | - // Initialise column format array  | 
                                                        |
| 130 | - $column_formats = $this->get_columns();  | 
                                                        |
| 131 | -  | 
                                                        |
| 132 | - // Force fields to lower case  | 
                                                        |
| 133 | - $data = array_change_key_case( $data );  | 
                                                        |
| 134 | -  | 
                                                        |
| 135 | - // White list columns  | 
                                                        |
| 136 | - $data = array_intersect_key( $data, $column_formats );  | 
                                                        |
| 137 | -  | 
                                                        |
| 138 | - // Reorder $column_formats to match the order of columns given in $data  | 
                                                        |
| 139 | - $data_keys = array_keys( $data );  | 
                                                        |
| 140 | - $column_formats = array_merge( array_flip( $data_keys ), $column_formats );  | 
                                                        |
| 141 | -  | 
                                                        |
| 142 | - $wpdb->insert( $this->table_name, $data, $column_formats );  | 
                                                        |
| 143 | - $wpdb_insert_id = $wpdb->insert_id;  | 
                                                        |
| 144 | -  | 
                                                        |
| 145 | - do_action( 'wpinv_post_insert_' . $type, $wpdb_insert_id, $data );  | 
                                                        |
| 146 | -  | 
                                                        |
| 147 | - return $wpdb_insert_id;  | 
                                                        |
| 148 | - }  | 
                                                        |
| 149 | -  | 
                                                        |
| 150 | - /**  | 
                                                        |
| 151 | - * Update a row  | 
                                                        |
| 152 | - *  | 
                                                        |
| 153 | - * @access public  | 
                                                        |
| 154 | - * @since 1.0.0  | 
                                                        |
| 155 | - * @return bool  | 
                                                        |
| 156 | - */  | 
                                                        |
| 157 | -	public function update( $row_id, $data = array(), $where = '' ) { | 
                                                        |
| 158 | -  | 
                                                        |
| 159 | - global $wpdb;  | 
                                                        |
| 160 | -  | 
                                                        |
| 161 | - // Row ID must be positive integer  | 
                                                        |
| 162 | - $row_id = absint( $row_id );  | 
                                                        |
| 163 | -  | 
                                                        |
| 164 | -		if( empty( $row_id ) ) { | 
                                                        |
| 165 | - return false;  | 
                                                        |
| 166 | - }  | 
                                                        |
| 167 | -  | 
                                                        |
| 168 | -		if( empty( $where ) ) { | 
                                                        |
| 169 | - $where = $this->primary_key;  | 
                                                        |
| 170 | - }  | 
                                                        |
| 171 | -  | 
                                                        |
| 172 | - // Initialise column format array  | 
                                                        |
| 173 | - $column_formats = $this->get_columns();  | 
                                                        |
| 174 | -  | 
                                                        |
| 175 | - // Force fields to lower case  | 
                                                        |
| 176 | - $data = array_change_key_case( $data );  | 
                                                        |
| 177 | -  | 
                                                        |
| 178 | - // White list columns  | 
                                                        |
| 179 | - $data = array_intersect_key( $data, $column_formats );  | 
                                                        |
| 180 | -  | 
                                                        |
| 181 | - // Reorder $column_formats to match the order of columns given in $data  | 
                                                        |
| 182 | - $data_keys = array_keys( $data );  | 
                                                        |
| 183 | - $column_formats = array_merge( array_flip( $data_keys ), $column_formats );  | 
                                                        |
| 184 | -  | 
                                                        |
| 185 | -		if ( false === $wpdb->update( $this->table_name, $data, array( $where => $row_id ), $column_formats ) ) { | 
                                                        |
| 186 | - return false;  | 
                                                        |
| 187 | - }  | 
                                                        |
| 188 | -  | 
                                                        |
| 189 | - return true;  | 
                                                        |
| 190 | - }  | 
                                                        |
| 191 | -  | 
                                                        |
| 192 | - /**  | 
                                                        |
| 193 | - * Delete a row identified by the primary key  | 
                                                        |
| 194 | - *  | 
                                                        |
| 195 | - * @access public  | 
                                                        |
| 196 | - * @since 1.0.0  | 
                                                        |
| 197 | - * @return bool  | 
                                                        |
| 198 | - */  | 
                                                        |
| 199 | -	public function delete( $row_id = 0 ) { | 
                                                        |
| 200 | -  | 
                                                        |
| 201 | - global $wpdb;  | 
                                                        |
| 202 | -  | 
                                                        |
| 203 | - // Row ID must be positive integer  | 
                                                        |
| 204 | - $row_id = absint( $row_id );  | 
                                                        |
| 205 | -  | 
                                                        |
| 206 | -		if( empty( $row_id ) ) { | 
                                                        |
| 207 | - return false;  | 
                                                        |
| 208 | - }  | 
                                                        |
| 209 | -  | 
                                                        |
| 210 | -		if ( false === $wpdb->query( $wpdb->prepare( "DELETE FROM $this->table_name WHERE $this->primary_key = %d", $row_id ) ) ) { | 
                                                        |
| 211 | - return false;  | 
                                                        |
| 212 | - }  | 
                                                        |
| 213 | -  | 
                                                        |
| 214 | - return true;  | 
                                                        |
| 215 | - }  | 
                                                        |
| 216 | -  | 
                                                        |
| 217 | - /**  | 
                                                        |
| 218 | - * Check if the given table exists  | 
                                                        |
| 219 | - *  | 
                                                        |
| 220 | - * @since 2.4  | 
                                                        |
| 221 | - * @param string $table The table name  | 
                                                        |
| 222 | - * @return bool If the table name exists  | 
                                                        |
| 223 | - */  | 
                                                        |
| 224 | -	public function table_exists( $table ) { | 
                                                        |
| 225 | - global $wpdb;  | 
                                                        |
| 226 | - $table = sanitize_text_field( $table );  | 
                                                        |
| 227 | -  | 
                                                        |
| 228 | - return $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE '%s'", $table ) ) === $table;  | 
                                                        |
| 229 | - }  | 
                                                        |
| 230 | -  | 
                                                        |
| 231 | - /**  | 
                                                        |
| 232 | - * Check if the table was ever installed  | 
                                                        |
| 233 | - *  | 
                                                        |
| 234 | - * @since 2.4  | 
                                                        |
| 235 | - * @return bool Returns if the customers table was installed and upgrade routine run  | 
                                                        |
| 236 | - */  | 
                                                        |
| 237 | -	public function installed() { | 
                                                        |
| 238 | - return $this->table_exists( $this->table_name );  | 
                                                        |
| 239 | - }  | 
                                                        |
| 8 | + /**  | 
                                                        |
| 9 | + * The name of our database table  | 
                                                        |
| 10 | + *  | 
                                                        |
| 11 | + * @access public  | 
                                                        |
| 12 | + * @since 1.0.0  | 
                                                        |
| 13 | + */  | 
                                                        |
| 14 | + public $table_name;  | 
                                                        |
| 15 | +  | 
                                                        |
| 16 | + /**  | 
                                                        |
| 17 | + * The version of our database table  | 
                                                        |
| 18 | + *  | 
                                                        |
| 19 | + * @access public  | 
                                                        |
| 20 | + * @since 1.0.0  | 
                                                        |
| 21 | + */  | 
                                                        |
| 22 | + public $version;  | 
                                                        |
| 23 | +  | 
                                                        |
| 24 | + /**  | 
                                                        |
| 25 | + * The name of the primary column  | 
                                                        |
| 26 | + *  | 
                                                        |
| 27 | + * @access public  | 
                                                        |
| 28 | + * @since 1.0.0  | 
                                                        |
| 29 | + */  | 
                                                        |
| 30 | + public $primary_key;  | 
                                                        |
| 31 | +  | 
                                                        |
| 32 | + /**  | 
                                                        |
| 33 | + * Get things started  | 
                                                        |
| 34 | + *  | 
                                                        |
| 35 | + * @access public  | 
                                                        |
| 36 | + * @since 1.0.0  | 
                                                        |
| 37 | + */  | 
                                                        |
| 38 | +    public function __construct() {} | 
                                                        |
| 39 | +  | 
                                                        |
| 40 | + /**  | 
                                                        |
| 41 | + * Whitelist of columns  | 
                                                        |
| 42 | + *  | 
                                                        |
| 43 | + * @access public  | 
                                                        |
| 44 | + * @since 1.0.0  | 
                                                        |
| 45 | + * @return array  | 
                                                        |
| 46 | + */  | 
                                                        |
| 47 | +    public function get_columns() { | 
                                                        |
| 48 | + return array();  | 
                                                        |
| 49 | + }  | 
                                                        |
| 50 | +  | 
                                                        |
| 51 | + /**  | 
                                                        |
| 52 | + * Default column values  | 
                                                        |
| 53 | + *  | 
                                                        |
| 54 | + * @access public  | 
                                                        |
| 55 | + * @since 1.0.0  | 
                                                        |
| 56 | + * @return array  | 
                                                        |
| 57 | + */  | 
                                                        |
| 58 | +    public function get_column_defaults() { | 
                                                        |
| 59 | + return array();  | 
                                                        |
| 60 | + }  | 
                                                        |
| 61 | +  | 
                                                        |
| 62 | + /**  | 
                                                        |
| 63 | + * Retrieve a row by the primary key  | 
                                                        |
| 64 | + *  | 
                                                        |
| 65 | + * @access public  | 
                                                        |
| 66 | + * @since 1.0.0  | 
                                                        |
| 67 | + * @return object  | 
                                                        |
| 68 | + */  | 
                                                        |
| 69 | +    public function get( $row_id ) { | 
                                                        |
| 70 | + global $wpdb;  | 
                                                        |
| 71 | + return $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id ) );  | 
                                                        |
| 72 | + }  | 
                                                        |
| 73 | +  | 
                                                        |
| 74 | + /**  | 
                                                        |
| 75 | + * Retrieve a row by a specific column / value  | 
                                                        |
| 76 | + *  | 
                                                        |
| 77 | + * @access public  | 
                                                        |
| 78 | + * @since 1.0.0  | 
                                                        |
| 79 | + * @return object  | 
                                                        |
| 80 | + */  | 
                                                        |
| 81 | +    public function get_by( $column, $row_id ) { | 
                                                        |
| 82 | + global $wpdb;  | 
                                                        |
| 83 | + $column = esc_sql( $column );  | 
                                                        |
| 84 | + return $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $this->table_name WHERE $column = %s LIMIT 1;", $row_id ) );  | 
                                                        |
| 85 | + }  | 
                                                        |
| 86 | +  | 
                                                        |
| 87 | + /**  | 
                                                        |
| 88 | + * Retrieve a specific column's value by the primary key  | 
                                                        |
| 89 | + *  | 
                                                        |
| 90 | + * @access public  | 
                                                        |
| 91 | + * @since 1.0.0  | 
                                                        |
| 92 | + * @return string  | 
                                                        |
| 93 | + */  | 
                                                        |
| 94 | +    public function get_column( $column, $row_id ) { | 
                                                        |
| 95 | + global $wpdb;  | 
                                                        |
| 96 | + $column = esc_sql( $column );  | 
                                                        |
| 97 | + return $wpdb->get_var( $wpdb->prepare( "SELECT $column FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id ) );  | 
                                                        |
| 98 | + }  | 
                                                        |
| 99 | +  | 
                                                        |
| 100 | + /**  | 
                                                        |
| 101 | + * Retrieve a specific column's value by the the specified column / value  | 
                                                        |
| 102 | + *  | 
                                                        |
| 103 | + * @access public  | 
                                                        |
| 104 | + * @since 1.0.0  | 
                                                        |
| 105 | + * @return string  | 
                                                        |
| 106 | + */  | 
                                                        |
| 107 | +    public function get_column_by( $column, $column_where, $column_value ) { | 
                                                        |
| 108 | + global $wpdb;  | 
                                                        |
| 109 | + $column_where = esc_sql( $column_where );  | 
                                                        |
| 110 | + $column = esc_sql( $column );  | 
                                                        |
| 111 | + return $wpdb->get_var( $wpdb->prepare( "SELECT $column FROM $this->table_name WHERE $column_where = %s LIMIT 1;", $column_value ) );  | 
                                                        |
| 112 | + }  | 
                                                        |
| 113 | +  | 
                                                        |
| 114 | + /**  | 
                                                        |
| 115 | + * Insert a new row  | 
                                                        |
| 116 | + *  | 
                                                        |
| 117 | + * @access public  | 
                                                        |
| 118 | + * @since 1.0.0  | 
                                                        |
| 119 | + * @return int  | 
                                                        |
| 120 | + */  | 
                                                        |
| 121 | +    public function insert( $data, $type = '' ) { | 
                                                        |
| 122 | + global $wpdb;  | 
                                                        |
| 123 | +  | 
                                                        |
| 124 | + // Set default values  | 
                                                        |
| 125 | + $data = wp_parse_args( $data, $this->get_column_defaults() );  | 
                                                        |
| 126 | +  | 
                                                        |
| 127 | + do_action( 'wpinv_pre_insert_' . $type, $data );  | 
                                                        |
| 128 | +  | 
                                                        |
| 129 | + // Initialise column format array  | 
                                                        |
| 130 | + $column_formats = $this->get_columns();  | 
                                                        |
| 131 | +  | 
                                                        |
| 132 | + // Force fields to lower case  | 
                                                        |
| 133 | + $data = array_change_key_case( $data );  | 
                                                        |
| 134 | +  | 
                                                        |
| 135 | + // White list columns  | 
                                                        |
| 136 | + $data = array_intersect_key( $data, $column_formats );  | 
                                                        |
| 137 | +  | 
                                                        |
| 138 | + // Reorder $column_formats to match the order of columns given in $data  | 
                                                        |
| 139 | + $data_keys = array_keys( $data );  | 
                                                        |
| 140 | + $column_formats = array_merge( array_flip( $data_keys ), $column_formats );  | 
                                                        |
| 141 | +  | 
                                                        |
| 142 | + $wpdb->insert( $this->table_name, $data, $column_formats );  | 
                                                        |
| 143 | + $wpdb_insert_id = $wpdb->insert_id;  | 
                                                        |
| 144 | +  | 
                                                        |
| 145 | + do_action( 'wpinv_post_insert_' . $type, $wpdb_insert_id, $data );  | 
                                                        |
| 146 | +  | 
                                                        |
| 147 | + return $wpdb_insert_id;  | 
                                                        |
| 148 | + }  | 
                                                        |
| 149 | +  | 
                                                        |
| 150 | + /**  | 
                                                        |
| 151 | + * Update a row  | 
                                                        |
| 152 | + *  | 
                                                        |
| 153 | + * @access public  | 
                                                        |
| 154 | + * @since 1.0.0  | 
                                                        |
| 155 | + * @return bool  | 
                                                        |
| 156 | + */  | 
                                                        |
| 157 | +    public function update( $row_id, $data = array(), $where = '' ) { | 
                                                        |
| 158 | +  | 
                                                        |
| 159 | + global $wpdb;  | 
                                                        |
| 160 | +  | 
                                                        |
| 161 | + // Row ID must be positive integer  | 
                                                        |
| 162 | + $row_id = absint( $row_id );  | 
                                                        |
| 163 | +  | 
                                                        |
| 164 | +        if( empty( $row_id ) ) { | 
                                                        |
| 165 | + return false;  | 
                                                        |
| 166 | + }  | 
                                                        |
| 167 | +  | 
                                                        |
| 168 | +        if( empty( $where ) ) { | 
                                                        |
| 169 | + $where = $this->primary_key;  | 
                                                        |
| 170 | + }  | 
                                                        |
| 171 | +  | 
                                                        |
| 172 | + // Initialise column format array  | 
                                                        |
| 173 | + $column_formats = $this->get_columns();  | 
                                                        |
| 174 | +  | 
                                                        |
| 175 | + // Force fields to lower case  | 
                                                        |
| 176 | + $data = array_change_key_case( $data );  | 
                                                        |
| 177 | +  | 
                                                        |
| 178 | + // White list columns  | 
                                                        |
| 179 | + $data = array_intersect_key( $data, $column_formats );  | 
                                                        |
| 180 | +  | 
                                                        |
| 181 | + // Reorder $column_formats to match the order of columns given in $data  | 
                                                        |
| 182 | + $data_keys = array_keys( $data );  | 
                                                        |
| 183 | + $column_formats = array_merge( array_flip( $data_keys ), $column_formats );  | 
                                                        |
| 184 | +  | 
                                                        |
| 185 | +        if ( false === $wpdb->update( $this->table_name, $data, array( $where => $row_id ), $column_formats ) ) { | 
                                                        |
| 186 | + return false;  | 
                                                        |
| 187 | + }  | 
                                                        |
| 188 | +  | 
                                                        |
| 189 | + return true;  | 
                                                        |
| 190 | + }  | 
                                                        |
| 191 | +  | 
                                                        |
| 192 | + /**  | 
                                                        |
| 193 | + * Delete a row identified by the primary key  | 
                                                        |
| 194 | + *  | 
                                                        |
| 195 | + * @access public  | 
                                                        |
| 196 | + * @since 1.0.0  | 
                                                        |
| 197 | + * @return bool  | 
                                                        |
| 198 | + */  | 
                                                        |
| 199 | +    public function delete( $row_id = 0 ) { | 
                                                        |
| 200 | +  | 
                                                        |
| 201 | + global $wpdb;  | 
                                                        |
| 202 | +  | 
                                                        |
| 203 | + // Row ID must be positive integer  | 
                                                        |
| 204 | + $row_id = absint( $row_id );  | 
                                                        |
| 205 | +  | 
                                                        |
| 206 | +        if( empty( $row_id ) ) { | 
                                                        |
| 207 | + return false;  | 
                                                        |
| 208 | + }  | 
                                                        |
| 209 | +  | 
                                                        |
| 210 | +        if ( false === $wpdb->query( $wpdb->prepare( "DELETE FROM $this->table_name WHERE $this->primary_key = %d", $row_id ) ) ) { | 
                                                        |
| 211 | + return false;  | 
                                                        |
| 212 | + }  | 
                                                        |
| 213 | +  | 
                                                        |
| 214 | + return true;  | 
                                                        |
| 215 | + }  | 
                                                        |
| 216 | +  | 
                                                        |
| 217 | + /**  | 
                                                        |
| 218 | + * Check if the given table exists  | 
                                                        |
| 219 | + *  | 
                                                        |
| 220 | + * @since 2.4  | 
                                                        |
| 221 | + * @param string $table The table name  | 
                                                        |
| 222 | + * @return bool If the table name exists  | 
                                                        |
| 223 | + */  | 
                                                        |
| 224 | +    public function table_exists( $table ) { | 
                                                        |
| 225 | + global $wpdb;  | 
                                                        |
| 226 | + $table = sanitize_text_field( $table );  | 
                                                        |
| 227 | +  | 
                                                        |
| 228 | + return $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE '%s'", $table ) ) === $table;  | 
                                                        |
| 229 | + }  | 
                                                        |
| 230 | +  | 
                                                        |
| 231 | + /**  | 
                                                        |
| 232 | + * Check if the table was ever installed  | 
                                                        |
| 233 | + *  | 
                                                        |
| 234 | + * @since 2.4  | 
                                                        |
| 235 | + * @return bool Returns if the customers table was installed and upgrade routine run  | 
                                                        |
| 236 | + */  | 
                                                        |
| 237 | +    public function installed() { | 
                                                        |
| 238 | + return $this->table_exists( $this->table_name );  | 
                                                        |
| 239 | + }  | 
                                                        |
| 240 | 240 | |
| 241 | 241 | }  | 
                                                        
@@ -1,7 +1,7 @@ discard block  | 
                                                    ||
| 1 | 1 | <?php  | 
                                                        
| 2 | 2 | |
| 3 | 3 | // Exit if accessed directly  | 
                                                        
| 4 | -if ( ! defined( 'ABSPATH' ) ) exit;  | 
                                                        |
| 4 | +if (!defined('ABSPATH')) exit; | 
                                                        |
| 5 | 5 | |
| 6 | 6 |  abstract class Wpinv_DB { | 
                                                        
| 7 | 7 | |
@@ -66,9 +66,9 @@ discard block  | 
                                                    ||
| 66 | 66 | * @since 1.0.0  | 
                                                        
| 67 | 67 | * @return object  | 
                                                        
| 68 | 68 | */  | 
                                                        
| 69 | -	public function get( $row_id ) { | 
                                                        |
| 69 | +	public function get($row_id) { | 
                                                        |
| 70 | 70 | global $wpdb;  | 
                                                        
| 71 | - return $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id ) );  | 
                                                        |
| 71 | +		return $wpdb->get_row($wpdb->prepare("SELECT * FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id)); | 
                                                        |
| 72 | 72 | }  | 
                                                        
| 73 | 73 | |
| 74 | 74 | /**  | 
                                                        
@@ -78,10 +78,10 @@ discard block  | 
                                                    ||
| 78 | 78 | * @since 1.0.0  | 
                                                        
| 79 | 79 | * @return object  | 
                                                        
| 80 | 80 | */  | 
                                                        
| 81 | -	public function get_by( $column, $row_id ) { | 
                                                        |
| 81 | +	public function get_by($column, $row_id) { | 
                                                        |
| 82 | 82 | global $wpdb;  | 
                                                        
| 83 | - $column = esc_sql( $column );  | 
                                                        |
| 84 | - return $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $this->table_name WHERE $column = %s LIMIT 1;", $row_id ) );  | 
                                                        |
| 83 | + $column = esc_sql($column);  | 
                                                        |
| 84 | +		return $wpdb->get_row($wpdb->prepare("SELECT * FROM $this->table_name WHERE $column = %s LIMIT 1;", $row_id)); | 
                                                        |
| 85 | 85 | }  | 
                                                        
| 86 | 86 | |
| 87 | 87 | /**  | 
                                                        
@@ -91,10 +91,10 @@ discard block  | 
                                                    ||
| 91 | 91 | * @since 1.0.0  | 
                                                        
| 92 | 92 | * @return string  | 
                                                        
| 93 | 93 | */  | 
                                                        
| 94 | -	public function get_column( $column, $row_id ) { | 
                                                        |
| 94 | +	public function get_column($column, $row_id) { | 
                                                        |
| 95 | 95 | global $wpdb;  | 
                                                        
| 96 | - $column = esc_sql( $column );  | 
                                                        |
| 97 | - return $wpdb->get_var( $wpdb->prepare( "SELECT $column FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id ) );  | 
                                                        |
| 96 | + $column = esc_sql($column);  | 
                                                        |
| 97 | +		return $wpdb->get_var($wpdb->prepare("SELECT $column FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id)); | 
                                                        |
| 98 | 98 | }  | 
                                                        
| 99 | 99 | |
| 100 | 100 | /**  | 
                                                        
@@ -104,11 +104,11 @@ discard block  | 
                                                    ||
| 104 | 104 | * @since 1.0.0  | 
                                                        
| 105 | 105 | * @return string  | 
                                                        
| 106 | 106 | */  | 
                                                        
| 107 | -	public function get_column_by( $column, $column_where, $column_value ) { | 
                                                        |
| 107 | +	public function get_column_by($column, $column_where, $column_value) { | 
                                                        |
| 108 | 108 | global $wpdb;  | 
                                                        
| 109 | - $column_where = esc_sql( $column_where );  | 
                                                        |
| 110 | - $column = esc_sql( $column );  | 
                                                        |
| 111 | - return $wpdb->get_var( $wpdb->prepare( "SELECT $column FROM $this->table_name WHERE $column_where = %s LIMIT 1;", $column_value ) );  | 
                                                        |
| 109 | + $column_where = esc_sql($column_where);  | 
                                                        |
| 110 | + $column = esc_sql($column);  | 
                                                        |
| 111 | +		return $wpdb->get_var($wpdb->prepare("SELECT $column FROM $this->table_name WHERE $column_where = %s LIMIT 1;", $column_value)); | 
                                                        |
| 112 | 112 | }  | 
                                                        
| 113 | 113 | |
| 114 | 114 | /**  | 
                                                        
@@ -118,31 +118,31 @@ discard block  | 
                                                    ||
| 118 | 118 | * @since 1.0.0  | 
                                                        
| 119 | 119 | * @return int  | 
                                                        
| 120 | 120 | */  | 
                                                        
| 121 | -	public function insert( $data, $type = '' ) { | 
                                                        |
| 121 | +	public function insert($data, $type = '') { | 
                                                        |
| 122 | 122 | global $wpdb;  | 
                                                        
| 123 | 123 | |
| 124 | 124 | // Set default values  | 
                                                        
| 125 | - $data = wp_parse_args( $data, $this->get_column_defaults() );  | 
                                                        |
| 125 | + $data = wp_parse_args($data, $this->get_column_defaults());  | 
                                                        |
| 126 | 126 | |
| 127 | - do_action( 'wpinv_pre_insert_' . $type, $data );  | 
                                                        |
| 127 | +		do_action('wpinv_pre_insert_' . $type, $data); | 
                                                        |
| 128 | 128 | |
| 129 | 129 | // Initialise column format array  | 
                                                        
| 130 | 130 | $column_formats = $this->get_columns();  | 
                                                        
| 131 | 131 | |
| 132 | 132 | // Force fields to lower case  | 
                                                        
| 133 | - $data = array_change_key_case( $data );  | 
                                                        |
| 133 | + $data = array_change_key_case($data);  | 
                                                        |
| 134 | 134 | |
| 135 | 135 | // White list columns  | 
                                                        
| 136 | - $data = array_intersect_key( $data, $column_formats );  | 
                                                        |
| 136 | + $data = array_intersect_key($data, $column_formats);  | 
                                                        |
| 137 | 137 | |
| 138 | 138 | // Reorder $column_formats to match the order of columns given in $data  | 
                                                        
| 139 | - $data_keys = array_keys( $data );  | 
                                                        |
| 140 | - $column_formats = array_merge( array_flip( $data_keys ), $column_formats );  | 
                                                        |
| 139 | + $data_keys = array_keys($data);  | 
                                                        |
| 140 | + $column_formats = array_merge(array_flip($data_keys), $column_formats);  | 
                                                        |
| 141 | 141 | |
| 142 | - $wpdb->insert( $this->table_name, $data, $column_formats );  | 
                                                        |
| 142 | + $wpdb->insert($this->table_name, $data, $column_formats);  | 
                                                        |
| 143 | 143 | $wpdb_insert_id = $wpdb->insert_id;  | 
                                                        
| 144 | 144 | |
| 145 | - do_action( 'wpinv_post_insert_' . $type, $wpdb_insert_id, $data );  | 
                                                        |
| 145 | +		do_action('wpinv_post_insert_' . $type, $wpdb_insert_id, $data); | 
                                                        |
| 146 | 146 | |
| 147 | 147 | return $wpdb_insert_id;  | 
                                                        
| 148 | 148 | }  | 
                                                        
@@ -154,18 +154,18 @@ discard block  | 
                                                    ||
| 154 | 154 | * @since 1.0.0  | 
                                                        
| 155 | 155 | * @return bool  | 
                                                        
| 156 | 156 | */  | 
                                                        
| 157 | -	public function update( $row_id, $data = array(), $where = '' ) { | 
                                                        |
| 157 | +	public function update($row_id, $data = array(), $where = '') { | 
                                                        |
| 158 | 158 | |
| 159 | 159 | global $wpdb;  | 
                                                        
| 160 | 160 | |
| 161 | 161 | // Row ID must be positive integer  | 
                                                        
| 162 | - $row_id = absint( $row_id );  | 
                                                        |
| 162 | + $row_id = absint($row_id);  | 
                                                        |
| 163 | 163 | |
| 164 | -		if( empty( $row_id ) ) { | 
                                                        |
| 164 | +		if (empty($row_id)) { | 
                                                        |
| 165 | 165 | return false;  | 
                                                        
| 166 | 166 | }  | 
                                                        
| 167 | 167 | |
| 168 | -		if( empty( $where ) ) { | 
                                                        |
| 168 | +		if (empty($where)) { | 
                                                        |
| 169 | 169 | $where = $this->primary_key;  | 
                                                        
| 170 | 170 | }  | 
                                                        
| 171 | 171 | |
@@ -173,16 +173,16 @@ discard block  | 
                                                    ||
| 173 | 173 | $column_formats = $this->get_columns();  | 
                                                        
| 174 | 174 | |
| 175 | 175 | // Force fields to lower case  | 
                                                        
| 176 | - $data = array_change_key_case( $data );  | 
                                                        |
| 176 | + $data = array_change_key_case($data);  | 
                                                        |
| 177 | 177 | |
| 178 | 178 | // White list columns  | 
                                                        
| 179 | - $data = array_intersect_key( $data, $column_formats );  | 
                                                        |
| 179 | + $data = array_intersect_key($data, $column_formats);  | 
                                                        |
| 180 | 180 | |
| 181 | 181 | // Reorder $column_formats to match the order of columns given in $data  | 
                                                        
| 182 | - $data_keys = array_keys( $data );  | 
                                                        |
| 183 | - $column_formats = array_merge( array_flip( $data_keys ), $column_formats );  | 
                                                        |
| 182 | + $data_keys = array_keys($data);  | 
                                                        |
| 183 | + $column_formats = array_merge(array_flip($data_keys), $column_formats);  | 
                                                        |
| 184 | 184 | |
| 185 | -		if ( false === $wpdb->update( $this->table_name, $data, array( $where => $row_id ), $column_formats ) ) { | 
                                                        |
| 185 | +		if (false === $wpdb->update($this->table_name, $data, array($where => $row_id), $column_formats)) { | 
                                                        |
| 186 | 186 | return false;  | 
                                                        
| 187 | 187 | }  | 
                                                        
| 188 | 188 | |
@@ -196,18 +196,18 @@ discard block  | 
                                                    ||
| 196 | 196 | * @since 1.0.0  | 
                                                        
| 197 | 197 | * @return bool  | 
                                                        
| 198 | 198 | */  | 
                                                        
| 199 | -	public function delete( $row_id = 0 ) { | 
                                                        |
| 199 | +	public function delete($row_id = 0) { | 
                                                        |
| 200 | 200 | |
| 201 | 201 | global $wpdb;  | 
                                                        
| 202 | 202 | |
| 203 | 203 | // Row ID must be positive integer  | 
                                                        
| 204 | - $row_id = absint( $row_id );  | 
                                                        |
| 204 | + $row_id = absint($row_id);  | 
                                                        |
| 205 | 205 | |
| 206 | -		if( empty( $row_id ) ) { | 
                                                        |
| 206 | +		if (empty($row_id)) { | 
                                                        |
| 207 | 207 | return false;  | 
                                                        
| 208 | 208 | }  | 
                                                        
| 209 | 209 | |
| 210 | -		if ( false === $wpdb->query( $wpdb->prepare( "DELETE FROM $this->table_name WHERE $this->primary_key = %d", $row_id ) ) ) { | 
                                                        |
| 210 | +		if (false === $wpdb->query($wpdb->prepare("DELETE FROM $this->table_name WHERE $this->primary_key = %d", $row_id))) { | 
                                                        |
| 211 | 211 | return false;  | 
                                                        
| 212 | 212 | }  | 
                                                        
| 213 | 213 | |
@@ -221,11 +221,11 @@ discard block  | 
                                                    ||
| 221 | 221 | * @param string $table The table name  | 
                                                        
| 222 | 222 | * @return bool If the table name exists  | 
                                                        
| 223 | 223 | */  | 
                                                        
| 224 | -	public function table_exists( $table ) { | 
                                                        |
| 224 | +	public function table_exists($table) { | 
                                                        |
| 225 | 225 | global $wpdb;  | 
                                                        
| 226 | - $table = sanitize_text_field( $table );  | 
                                                        |
| 226 | + $table = sanitize_text_field($table);  | 
                                                        |
| 227 | 227 | |
| 228 | - return $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE '%s'", $table ) ) === $table;  | 
                                                        |
| 228 | +		return $wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE '%s'", $table)) === $table; | 
                                                        |
| 229 | 229 | }  | 
                                                        
| 230 | 230 | |
| 231 | 231 | /**  | 
                                                        
@@ -235,7 +235,7 @@ discard block  | 
                                                    ||
| 235 | 235 | * @return bool Returns if the customers table was installed and upgrade routine run  | 
                                                        
| 236 | 236 | */  | 
                                                        
| 237 | 237 |  	public function installed() { | 
                                                        
| 238 | - return $this->table_exists( $this->table_name );  | 
                                                        |
| 238 | + return $this->table_exists($this->table_name);  | 
                                                        |
| 239 | 239 | }  | 
                                                        
| 240 | 240 | |
| 241 | 241 | }  | 
                                                        
@@ -1,7 +1,9 @@  | 
                                                    ||
| 1 | 1 | <?php  | 
                                                        
| 2 | 2 | |
| 3 | 3 | // Exit if accessed directly  | 
                                                        
| 4 | -if ( ! defined( 'ABSPATH' ) ) exit;  | 
                                                        |
| 4 | +if ( ! defined( 'ABSPATH' ) ) { | 
                                                        |
| 5 | + exit;  | 
                                                        |
| 6 | +}  | 
                                                        |
| 5 | 7 | |
| 6 | 8 |  abstract class Wpinv_DB { | 
                                                        
| 7 | 9 | |
@@ -8,7 +8,9 @@  | 
                                                    ||
| 8 | 8 | |
| 9 | 9 | |
| 10 | 10 | // Exit if accessed directly  | 
                                                        
| 11 | -if ( ! defined( 'ABSPATH' ) ) exit;  | 
                                                        |
| 11 | +if ( ! defined( 'ABSPATH' ) ) { | 
                                                        |
| 12 | + exit;  | 
                                                        |
| 13 | +}  | 
                                                        |
| 12 | 14 | |
| 13 | 15 | |
| 14 | 16 | // Load WP_List_Table if not loaded  | 
                                                        
@@ -13,7 +13,7 @@ discard block  | 
                                                    ||
| 13 | 13 | |
| 14 | 14 | // Load WP_List_Table if not loaded  | 
                                                        
| 15 | 15 |  if( ! class_exists( 'WP_List_Table' ) ) { | 
                                                        
| 16 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';  | 
                                                        |
| 16 | + require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';  | 
                                                        |
| 17 | 17 | }  | 
                                                        
| 18 | 18 | |
| 19 | 19 | /**  | 
                                                        
@@ -23,102 +23,102 @@ discard block  | 
                                                    ||
| 23 | 23 | */  | 
                                                        
| 24 | 24 |  class WPInv_Subscription_Reports_Table extends WP_List_Table { | 
                                                        
| 25 | 25 | |
| 26 | - /**  | 
                                                        |
| 27 | - * Number of results to show per page  | 
                                                        |
| 28 | - *  | 
                                                        |
| 29 | - * @since 1.0.0  | 
                                                        |
| 30 | - */  | 
                                                        |
| 31 | -  | 
                                                        |
| 32 | - public $per_page = 20;  | 
                                                        |
| 33 | - public $total_count = 0;  | 
                                                        |
| 34 | - public $active_count = 0;  | 
                                                        |
| 35 | - public $pending_count = 0;  | 
                                                        |
| 36 | - public $expired_count = 0;  | 
                                                        |
| 37 | - public $completed_count = 0;  | 
                                                        |
| 38 | - public $trialling_count = 0;  | 
                                                        |
| 39 | - public $cancelled_count = 0;  | 
                                                        |
| 40 | - public $failing_count = 0;  | 
                                                        |
| 41 | -  | 
                                                        |
| 42 | - /**  | 
                                                        |
| 43 | - * Get things started  | 
                                                        |
| 44 | - *  | 
                                                        |
| 45 | - * @access private  | 
                                                        |
| 46 | - * @since 1.0.0  | 
                                                        |
| 47 | - * @return void  | 
                                                        |
| 48 | - */  | 
                                                        |
| 49 | -	function __construct(){ | 
                                                        |
| 50 | - global $status, $page;  | 
                                                        |
| 51 | -  | 
                                                        |
| 52 | - // Set parent defaults  | 
                                                        |
| 53 | - parent::__construct( array(  | 
                                                        |
| 54 | - 'singular' => 'subscription',  | 
                                                        |
| 55 | - 'plural' => 'subscriptions',  | 
                                                        |
| 56 | - 'ajax' => false  | 
                                                        |
| 57 | - ) );  | 
                                                        |
| 58 | -  | 
                                                        |
| 59 | - $this->get_subscription_counts();  | 
                                                        |
| 60 | -  | 
                                                        |
| 61 | - }  | 
                                                        |
| 62 | -  | 
                                                        |
| 63 | - /**  | 
                                                        |
| 64 | - * Retrieve the view types  | 
                                                        |
| 65 | - *  | 
                                                        |
| 66 | - * @access public  | 
                                                        |
| 67 | - * @since 1.0.0  | 
                                                        |
| 68 | - * @return array $views All the views available  | 
                                                        |
| 69 | - */  | 
                                                        |
| 70 | -	public function get_views() { | 
                                                        |
| 71 | -  | 
                                                        |
| 72 | - $current = isset( $_GET['status'] ) ? $_GET['status'] : '';  | 
                                                        |
| 73 | -		$total_count     = ' <span class="count">(' . $this->total_count    . ')</span>'; | 
                                                        |
| 74 | -		$active_count    = ' <span class="count">(' . $this->active_count . ')</span>'; | 
                                                        |
| 75 | -		$pending_count   = ' <span class="count">(' . $this->pending_count . ')</span>'; | 
                                                        |
| 76 | -		$expired_count   = ' <span class="count">(' . $this->expired_count  . ')</span>'; | 
                                                        |
| 77 | -		$completed_count = ' <span class="count">(' . $this->completed_count . ')</span>'; | 
                                                        |
| 78 | -		$trialling_count  = ' <span class="count">(' . $this->trialling_count   . ')</span>'; | 
                                                        |
| 79 | -		$cancelled_count = ' <span class="count">(' . $this->cancelled_count   . ')</span>'; | 
                                                        |
| 80 | -		$failing_count   = ' <span class="count">(' . $this->failing_count   . ')</span>'; | 
                                                        |
| 81 | -  | 
                                                        |
| 82 | - $views = array(  | 
                                                        |
| 83 | -			'all'       => sprintf( '<a href="%s"%s>%s</a>', remove_query_arg( array( 'status', 'paged' ) ), $current === 'all' || $current == '' ? ' class="current"' : '', __('All','invoicing' ) . $total_count ), | 
                                                        |
| 84 | -			'active'    => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'active', 'paged' => FALSE ) ), $current === 'active' ? ' class="current"' : '', __('Active','invoicing' ) . $active_count ), | 
                                                        |
| 85 | -			'pending'   => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'pending', 'paged' => FALSE ) ), $current === 'pending' ? ' class="current"' : '', __('Pending','invoicing' ) . $pending_count ), | 
                                                        |
| 86 | -			'expired'   => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'expired', 'paged' => FALSE ) ), $current === 'expired' ? ' class="current"' : '', __('Expired','invoicing' ) . $expired_count ), | 
                                                        |
| 87 | -			'completed' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'completed', 'paged' => FALSE ) ), $current === 'completed' ? ' class="current"' : '', __('Completed','invoicing' ) . $completed_count ), | 
                                                        |
| 88 | -			'trialling'  => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'trialling', 'paged' => FALSE ) ), $current === 'trialling' ? ' class="current"' : '', __('Trialling','invoicing' ) . $trialling_count ), | 
                                                        |
| 89 | -			'cancelled' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'cancelled', 'paged' => FALSE ) ), $current === 'cancelled' ? ' class="current"' : '', __('Cancelled','invoicing' ) . $cancelled_count ), | 
                                                        |
| 90 | -			'failing'   => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'failing', 'paged' => FALSE ) ), $current === 'failing' ? ' class="current"' : '', __('Failing','invoicing' ) . $failing_count ), | 
                                                        |
| 91 | - );  | 
                                                        |
| 92 | -  | 
                                                        |
| 93 | - return apply_filters( 'wpinv_recurring_subscriptions_table_views', $views );  | 
                                                        |
| 94 | - }  | 
                                                        |
| 95 | -  | 
                                                        |
| 96 | - /**  | 
                                                        |
| 97 | - * Show the search field  | 
                                                        |
| 98 | - *  | 
                                                        |
| 99 | - * @since 2.5  | 
                                                        |
| 100 | - * @access public  | 
                                                        |
| 101 | - *  | 
                                                        |
| 102 | - * @param string $text Label for the search box  | 
                                                        |
| 103 | - * @param string $input_id ID of the search box  | 
                                                        |
| 104 | - *  | 
                                                        |
| 105 | - * @return void  | 
                                                        |
| 106 | - */  | 
                                                        |
| 107 | -	public function search_box( $text, $input_id ) { | 
                                                        |
| 108 | -  | 
                                                        |
| 109 | -		if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) { | 
                                                        |
| 110 | - return;  | 
                                                        |
| 111 | - }  | 
                                                        |
| 112 | -  | 
                                                        |
| 113 | - $input_id = $input_id . '-search-input';  | 
                                                        |
| 114 | -  | 
                                                        |
| 115 | -		if ( ! empty( $_REQUEST['orderby'] ) ) { | 
                                                        |
| 116 | - echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />';  | 
                                                        |
| 117 | - }  | 
                                                        |
| 118 | -  | 
                                                        |
| 119 | -		if ( ! empty( $_REQUEST['order'] ) ) { | 
                                                        |
| 120 | - echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />';  | 
                                                        |
| 121 | - }  | 
                                                        |
| 26 | + /**  | 
                                                        |
| 27 | + * Number of results to show per page  | 
                                                        |
| 28 | + *  | 
                                                        |
| 29 | + * @since 1.0.0  | 
                                                        |
| 30 | + */  | 
                                                        |
| 31 | +  | 
                                                        |
| 32 | + public $per_page = 20;  | 
                                                        |
| 33 | + public $total_count = 0;  | 
                                                        |
| 34 | + public $active_count = 0;  | 
                                                        |
| 35 | + public $pending_count = 0;  | 
                                                        |
| 36 | + public $expired_count = 0;  | 
                                                        |
| 37 | + public $completed_count = 0;  | 
                                                        |
| 38 | + public $trialling_count = 0;  | 
                                                        |
| 39 | + public $cancelled_count = 0;  | 
                                                        |
| 40 | + public $failing_count = 0;  | 
                                                        |
| 41 | +  | 
                                                        |
| 42 | + /**  | 
                                                        |
| 43 | + * Get things started  | 
                                                        |
| 44 | + *  | 
                                                        |
| 45 | + * @access private  | 
                                                        |
| 46 | + * @since 1.0.0  | 
                                                        |
| 47 | + * @return void  | 
                                                        |
| 48 | + */  | 
                                                        |
| 49 | +    function __construct(){ | 
                                                        |
| 50 | + global $status, $page;  | 
                                                        |
| 51 | +  | 
                                                        |
| 52 | + // Set parent defaults  | 
                                                        |
| 53 | + parent::__construct( array(  | 
                                                        |
| 54 | + 'singular' => 'subscription',  | 
                                                        |
| 55 | + 'plural' => 'subscriptions',  | 
                                                        |
| 56 | + 'ajax' => false  | 
                                                        |
| 57 | + ) );  | 
                                                        |
| 58 | +  | 
                                                        |
| 59 | + $this->get_subscription_counts();  | 
                                                        |
| 60 | +  | 
                                                        |
| 61 | + }  | 
                                                        |
| 62 | +  | 
                                                        |
| 63 | + /**  | 
                                                        |
| 64 | + * Retrieve the view types  | 
                                                        |
| 65 | + *  | 
                                                        |
| 66 | + * @access public  | 
                                                        |
| 67 | + * @since 1.0.0  | 
                                                        |
| 68 | + * @return array $views All the views available  | 
                                                        |
| 69 | + */  | 
                                                        |
| 70 | +    public function get_views() { | 
                                                        |
| 71 | +  | 
                                                        |
| 72 | + $current = isset( $_GET['status'] ) ? $_GET['status'] : '';  | 
                                                        |
| 73 | +        $total_count     = ' <span class="count">(' . $this->total_count    . ')</span>'; | 
                                                        |
| 74 | +        $active_count    = ' <span class="count">(' . $this->active_count . ')</span>'; | 
                                                        |
| 75 | +        $pending_count   = ' <span class="count">(' . $this->pending_count . ')</span>'; | 
                                                        |
| 76 | +        $expired_count   = ' <span class="count">(' . $this->expired_count  . ')</span>'; | 
                                                        |
| 77 | +        $completed_count = ' <span class="count">(' . $this->completed_count . ')</span>'; | 
                                                        |
| 78 | +        $trialling_count  = ' <span class="count">(' . $this->trialling_count   . ')</span>'; | 
                                                        |
| 79 | +        $cancelled_count = ' <span class="count">(' . $this->cancelled_count   . ')</span>'; | 
                                                        |
| 80 | +        $failing_count   = ' <span class="count">(' . $this->failing_count   . ')</span>'; | 
                                                        |
| 81 | +  | 
                                                        |
| 82 | + $views = array(  | 
                                                        |
| 83 | +            'all'       => sprintf( '<a href="%s"%s>%s</a>', remove_query_arg( array( 'status', 'paged' ) ), $current === 'all' || $current == '' ? ' class="current"' : '', __('All','invoicing' ) . $total_count ), | 
                                                        |
| 84 | +            'active'    => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'active', 'paged' => FALSE ) ), $current === 'active' ? ' class="current"' : '', __('Active','invoicing' ) . $active_count ), | 
                                                        |
| 85 | +            'pending'   => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'pending', 'paged' => FALSE ) ), $current === 'pending' ? ' class="current"' : '', __('Pending','invoicing' ) . $pending_count ), | 
                                                        |
| 86 | +            'expired'   => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'expired', 'paged' => FALSE ) ), $current === 'expired' ? ' class="current"' : '', __('Expired','invoicing' ) . $expired_count ), | 
                                                        |
| 87 | +            'completed' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'completed', 'paged' => FALSE ) ), $current === 'completed' ? ' class="current"' : '', __('Completed','invoicing' ) . $completed_count ), | 
                                                        |
| 88 | +            'trialling'  => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'trialling', 'paged' => FALSE ) ), $current === 'trialling' ? ' class="current"' : '', __('Trialling','invoicing' ) . $trialling_count ), | 
                                                        |
| 89 | +            'cancelled' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'cancelled', 'paged' => FALSE ) ), $current === 'cancelled' ? ' class="current"' : '', __('Cancelled','invoicing' ) . $cancelled_count ), | 
                                                        |
| 90 | +            'failing'   => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'failing', 'paged' => FALSE ) ), $current === 'failing' ? ' class="current"' : '', __('Failing','invoicing' ) . $failing_count ), | 
                                                        |
| 91 | + );  | 
                                                        |
| 92 | +  | 
                                                        |
| 93 | + return apply_filters( 'wpinv_recurring_subscriptions_table_views', $views );  | 
                                                        |
| 94 | + }  | 
                                                        |
| 95 | +  | 
                                                        |
| 96 | + /**  | 
                                                        |
| 97 | + * Show the search field  | 
                                                        |
| 98 | + *  | 
                                                        |
| 99 | + * @since 2.5  | 
                                                        |
| 100 | + * @access public  | 
                                                        |
| 101 | + *  | 
                                                        |
| 102 | + * @param string $text Label for the search box  | 
                                                        |
| 103 | + * @param string $input_id ID of the search box  | 
                                                        |
| 104 | + *  | 
                                                        |
| 105 | + * @return void  | 
                                                        |
| 106 | + */  | 
                                                        |
| 107 | +    public function search_box( $text, $input_id ) { | 
                                                        |
| 108 | +  | 
                                                        |
| 109 | +        if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) { | 
                                                        |
| 110 | + return;  | 
                                                        |
| 111 | + }  | 
                                                        |
| 112 | +  | 
                                                        |
| 113 | + $input_id = $input_id . '-search-input';  | 
                                                        |
| 114 | +  | 
                                                        |
| 115 | +        if ( ! empty( $_REQUEST['orderby'] ) ) { | 
                                                        |
| 116 | + echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />';  | 
                                                        |
| 117 | + }  | 
                                                        |
| 118 | +  | 
                                                        |
| 119 | +        if ( ! empty( $_REQUEST['order'] ) ) { | 
                                                        |
| 120 | + echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />';  | 
                                                        |
| 121 | + }  | 
                                                        |
| 122 | 122 | ?>  | 
                                                        
| 123 | 123 | <p class="search-box">  | 
                                                        
| 124 | 124 | <?php do_action( 'wpinv_recurring_subscription_search_box' ); ?>  | 
                                                        
@@ -127,18 +127,18 @@ discard block  | 
                                                    ||
| 127 | 127 |  			<?php submit_button( $text, 'button', false, false, array('ID' => 'search-submit') ); ?><br/> | 
                                                        
| 128 | 128 | </p>  | 
                                                        
| 129 | 129 | <?php  | 
                                                        
| 130 | - }  | 
                                                        |
| 131 | -  | 
                                                        |
| 132 | - /**  | 
                                                        |
| 133 | - * Render most columns  | 
                                                        |
| 134 | - *  | 
                                                        |
| 135 | - * @access private  | 
                                                        |
| 136 | - * @since 1.0.0  | 
                                                        |
| 137 | - * @return string  | 
                                                        |
| 138 | - */  | 
                                                        |
| 139 | -	function column_default( $item, $column_name ) { | 
                                                        |
| 140 | - return $item->$column_name;  | 
                                                        |
| 141 | - }  | 
                                                        |
| 130 | + }  | 
                                                        |
| 131 | +  | 
                                                        |
| 132 | + /**  | 
                                                        |
| 133 | + * Render most columns  | 
                                                        |
| 134 | + *  | 
                                                        |
| 135 | + * @access private  | 
                                                        |
| 136 | + * @since 1.0.0  | 
                                                        |
| 137 | + * @return string  | 
                                                        |
| 138 | + */  | 
                                                        |
| 139 | +    function column_default( $item, $column_name ) { | 
                                                        |
| 140 | + return $item->$column_name;  | 
                                                        |
| 141 | + }  | 
                                                        |
| 142 | 142 | |
| 143 | 143 | /**  | 
                                                        
| 144 | 144 | * Subscription id column  | 
                                                        
@@ -151,244 +151,244 @@ discard block  | 
                                                    ||
| 151 | 151 | return '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $item->id ) ) . '" target="_blank">' . $item->id . '</a>';  | 
                                                        
| 152 | 152 | }  | 
                                                        
| 153 | 153 | |
| 154 | - /**  | 
                                                        |
| 155 | - * Customer column  | 
                                                        |
| 156 | - *  | 
                                                        |
| 157 | - * @access private  | 
                                                        |
| 158 | - * @since 1.0.0  | 
                                                        |
| 159 | - * @return string  | 
                                                        |
| 160 | - */  | 
                                                        |
| 161 | -	function column_customer_id( $item ) { | 
                                                        |
| 162 | - $subscriber = get_userdata( $item->customer_id );  | 
                                                        |
| 163 | - $customer = ! empty( $subscriber->display_name ) ? $subscriber->display_name : $subscriber->user_email;  | 
                                                        |
| 164 | -  | 
                                                        |
| 165 | - return '<a href="' . esc_url( get_edit_user_link( $item->customer_id ) ) . '" target="_blank">' . $customer . '</a>';  | 
                                                        |
| 166 | - }  | 
                                                        |
| 167 | -  | 
                                                        |
| 168 | - /**  | 
                                                        |
| 169 | - * Status column  | 
                                                        |
| 170 | - *  | 
                                                        |
| 171 | - * @access private  | 
                                                        |
| 172 | - * @since 1.0.0  | 
                                                        |
| 173 | - * @return string  | 
                                                        |
| 174 | - */  | 
                                                        |
| 175 | -	function column_status( $item ) { | 
                                                        |
| 176 | - return $item->get_status_label();  | 
                                                        |
| 177 | - }  | 
                                                        |
| 178 | -  | 
                                                        |
| 179 | - /**  | 
                                                        |
| 180 | - * Period column  | 
                                                        |
| 181 | - *  | 
                                                        |
| 182 | - * @access private  | 
                                                        |
| 183 | - * @since 1.0.0  | 
                                                        |
| 184 | - * @return string  | 
                                                        |
| 185 | - */  | 
                                                        |
| 186 | -	function column_period( $item ) { | 
                                                        |
| 187 | -  | 
                                                        |
| 188 | - $period = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->period,$item->frequency );  | 
                                                        |
| 189 | -  | 
                                                        |
| 190 | - return wpinv_price( wpinv_format_amount( $item->recurring_amount ), wpinv_get_invoice_currency_code( $item->parent_payment_id ) ) . ' / ' . $period;  | 
                                                        |
| 191 | - }  | 
                                                        |
| 192 | -  | 
                                                        |
| 193 | - /**  | 
                                                        |
| 194 | - * Billing Times column  | 
                                                        |
| 195 | - *  | 
                                                        |
| 196 | - * @access private  | 
                                                        |
| 197 | - * @since 1.0.0  | 
                                                        |
| 198 | - * @return string  | 
                                                        |
| 199 | - */  | 
                                                        |
| 200 | -	function column_bill_times( $item ) { | 
                                                        |
| 201 | - return $item->get_times_billed() . ' / ' . ( ( $item->bill_times == 0 ) ? 'Until Cancelled' : $item->bill_times );  | 
                                                        |
| 202 | - }  | 
                                                        |
| 203 | -  | 
                                                        |
| 204 | - /**  | 
                                                        |
| 205 | - * Initial Amount column  | 
                                                        |
| 206 | - *  | 
                                                        |
| 207 | - * @access private  | 
                                                        |
| 208 | - * @since 1.0.0  | 
                                                        |
| 209 | - * @return string  | 
                                                        |
| 210 | - */  | 
                                                        |
| 211 | -	function column_initial_amount( $item ) { | 
                                                        |
| 212 | - return wpinv_price( wpinv_format_amount( $item->initial_amount ), wpinv_get_invoice_currency_code( $item->parent_payment_id ) );  | 
                                                        |
| 213 | - }  | 
                                                        |
| 214 | -  | 
                                                        |
| 215 | - /**  | 
                                                        |
| 216 | - * Renewal date column  | 
                                                        |
| 217 | - *  | 
                                                        |
| 218 | - * @access private  | 
                                                        |
| 219 | - * @since 1.0.0  | 
                                                        |
| 220 | - * @return string  | 
                                                        |
| 221 | - */  | 
                                                        |
| 222 | -	function column_renewal_date( $item ) { | 
                                                        |
| 223 | - return $renewal_date = ! empty( $item->expiration ) ? date_i18n( get_option( 'date_format' ), strtotime( $item->expiration ) ) : __( 'N/A', 'invoicing' );  | 
                                                        |
| 224 | - }  | 
                                                        |
| 225 | -  | 
                                                        |
| 226 | - /**  | 
                                                        |
| 227 | - * Payment column  | 
                                                        |
| 228 | - *  | 
                                                        |
| 229 | - * @access private  | 
                                                        |
| 230 | - * @since 1.0.0  | 
                                                        |
| 231 | - * @return string  | 
                                                        |
| 232 | - */  | 
                                                        |
| 233 | -	function column_parent_payment_id( $item ) { | 
                                                        |
| 234 | - return '<a href="' . get_edit_post_link( $item->parent_payment_id ) . '" target="_blank">' . wpinv_get_invoice_number( $item->parent_payment_id ) . '</a>';  | 
                                                        |
| 235 | - }  | 
                                                        |
| 236 | -  | 
                                                        |
| 237 | - /**  | 
                                                        |
| 238 | - * Product ID column  | 
                                                        |
| 239 | - *  | 
                                                        |
| 240 | - * @access private  | 
                                                        |
| 241 | - * @since 1.0.0  | 
                                                        |
| 242 | - * @return string  | 
                                                        |
| 243 | - */  | 
                                                        |
| 244 | -	function column_product_id( $item ) { | 
                                                        |
| 245 | - return '<a href="' . esc_url( admin_url( 'post.php?action=edit&post=' . $item->product_id ) ) . '" target="_blank">' . get_the_title( $item->product_id ) . '</a>';  | 
                                                        |
| 246 | - }  | 
                                                        |
| 247 | -  | 
                                                        |
| 248 | - /**  | 
                                                        |
| 249 | - * Render the edit column  | 
                                                        |
| 250 | - *  | 
                                                        |
| 251 | - * @access private  | 
                                                        |
| 252 | - * @since 2.0  | 
                                                        |
| 253 | - * @return string  | 
                                                        |
| 254 | - */  | 
                                                        |
| 255 | -	function column_actions( $item ) { | 
                                                        |
| 256 | - return '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $item->id ) ) . '" title="' . esc_attr( __( 'View or edit subscription', 'invoicing' ) ) . '" target="_blank">' . __( 'View', 'invoicing' ) . '</a>';  | 
                                                        |
| 257 | - }  | 
                                                        |
| 258 | -  | 
                                                        |
| 259 | -  | 
                                                        |
| 260 | - /**  | 
                                                        |
| 261 | - * Retrieve the table columns  | 
                                                        |
| 262 | - *  | 
                                                        |
| 263 | - * @access private  | 
                                                        |
| 264 | - * @since 1.0.0  | 
                                                        |
| 265 | - * @return array  | 
                                                        |
| 266 | - */  | 
                                                        |
| 267 | -  | 
                                                        |
| 268 | -	function get_columns(){ | 
                                                        |
| 269 | - $columns = array(  | 
                                                        |
| 270 | - 'sub_id' => __( 'ID', 'invoicing' ),  | 
                                                        |
| 271 | - 'customer_id' => __( 'Customer', 'invoicing' ),  | 
                                                        |
| 272 | - 'status' => __( 'Status', 'invoicing' ),  | 
                                                        |
| 273 | - 'period' => __( 'Billing Cycle', 'invoicing' ),  | 
                                                        |
| 274 | - 'initial_amount' => __( 'Initial Amount', 'invoicing' ),  | 
                                                        |
| 275 | - 'bill_times' => __( 'Times Billed', 'invoicing' ),  | 
                                                        |
| 276 | - 'renewal_date' => __( 'Renewal Date', 'invoicing' ),  | 
                                                        |
| 277 | - 'parent_payment_id' => __( 'Invoice', 'invoicing' ),  | 
                                                        |
| 278 | - 'product_id' => __( 'Item', 'invoicing' ),  | 
                                                        |
| 279 | - 'actions' => __( 'Actions', 'invoicing' ),  | 
                                                        |
| 280 | - );  | 
                                                        |
| 281 | -  | 
                                                        |
| 282 | - return apply_filters( 'wpinv_report_subscription_columns', $columns );  | 
                                                        |
| 283 | - }  | 
                                                        |
| 284 | -  | 
                                                        |
| 285 | - /**  | 
                                                        |
| 286 | - * Retrieve the current page number  | 
                                                        |
| 287 | - *  | 
                                                        |
| 288 | - * @access private  | 
                                                        |
| 289 | - * @since 1.0.0  | 
                                                        |
| 290 | - * @return int  | 
                                                        |
| 291 | - */  | 
                                                        |
| 292 | -	function get_paged() { | 
                                                        |
| 293 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;  | 
                                                        |
| 294 | - }  | 
                                                        |
| 295 | -  | 
                                                        |
| 296 | - /**  | 
                                                        |
| 297 | - * Retrieve the subscription counts  | 
                                                        |
| 298 | - *  | 
                                                        |
| 299 | - * @access public  | 
                                                        |
| 300 | - * @since 1.4  | 
                                                        |
| 301 | - * @return void  | 
                                                        |
| 302 | - */  | 
                                                        |
| 303 | -	public function get_subscription_counts() { | 
                                                        |
| 304 | -  | 
                                                        |
| 305 | - global $wp_query;  | 
                                                        |
| 306 | -  | 
                                                        |
| 307 | - $db = new WPInv_Subscriptions_DB;  | 
                                                        |
| 308 | -  | 
                                                        |
| 309 | - $search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : '';  | 
                                                        |
| 310 | -  | 
                                                        |
| 311 | - $this->total_count = $db->count();  | 
                                                        |
| 312 | - $this->active_count = $db->count( array( 'status' => 'active', 'search' => $search ) );  | 
                                                        |
| 313 | - $this->pending_count = $db->count( array( 'status' => 'pending', 'search' => $search ) );  | 
                                                        |
| 314 | - $this->expired_count = $db->count( array( 'status' => 'expired', 'search' => $search ) );  | 
                                                        |
| 315 | - $this->trialling_count = $db->count( array( 'status' => 'trialling', 'search' => $search ) );  | 
                                                        |
| 316 | - $this->cancelled_count = $db->count( array( 'status' => 'cancelled', 'search' => $search ) );  | 
                                                        |
| 317 | - $this->completed_count = $db->count( array( 'status' => 'completed', 'search' => $search ) );  | 
                                                        |
| 318 | - $this->failing_count = $db->count( array( 'status' => 'failing', 'search' => $search ) );  | 
                                                        |
| 319 | -  | 
                                                        |
| 320 | - }  | 
                                                        |
| 321 | -  | 
                                                        |
| 322 | - /**  | 
                                                        |
| 323 | - * Setup the final data for the table  | 
                                                        |
| 324 | - *  | 
                                                        |
| 325 | - * @access private  | 
                                                        |
| 326 | - * @since 1.0.0  | 
                                                        |
| 327 | - * @uses $this->_column_headers  | 
                                                        |
| 328 | - * @uses $this->items  | 
                                                        |
| 329 | - * @uses $this->get_columns()  | 
                                                        |
| 330 | - * @uses $this->get_sortable_columns()  | 
                                                        |
| 331 | - * @uses $this->get_pagenum()  | 
                                                        |
| 332 | - * @uses $this->set_pagination_args()  | 
                                                        |
| 333 | - * @return array  | 
                                                        |
| 334 | - */  | 
                                                        |
| 335 | -	function prepare_items() { | 
                                                        |
| 336 | -  | 
                                                        |
| 337 | - $columns = $this->get_columns();  | 
                                                        |
| 338 | - $hidden = array(); // No hidden columns  | 
                                                        |
| 339 | - $status = isset( $_GET['status'] ) ? $_GET['status'] : 'any';  | 
                                                        |
| 340 | - $sortable = $this->get_sortable_columns();  | 
                                                        |
| 341 | -  | 
                                                        |
| 342 | - $this->_column_headers = array( $columns, $hidden, $sortable );  | 
                                                        |
| 343 | -  | 
                                                        |
| 344 | - $current_page = $this->get_pagenum();  | 
                                                        |
| 345 | -  | 
                                                        |
| 346 | - $db = new WPInv_Subscriptions_DB;  | 
                                                        |
| 347 | - $search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : '';  | 
                                                        |
| 348 | - $args = array(  | 
                                                        |
| 349 | - 'number' => $this->per_page,  | 
                                                        |
| 350 | - 'offset' => $this->per_page * ( $this->get_paged() - 1 ),  | 
                                                        |
| 351 | - 'search' => $search  | 
                                                        |
| 352 | - );  | 
                                                        |
| 353 | -  | 
                                                        |
| 354 | -		if ( 'any' !== $status ) { | 
                                                        |
| 355 | - $args['status'] = $status;  | 
                                                        |
| 356 | - }  | 
                                                        |
| 357 | -  | 
                                                        |
| 358 | - $this->items = $db->get_subscriptions( $args );  | 
                                                        |
| 359 | -  | 
                                                        |
| 360 | -		switch ( $status ) { | 
                                                        |
| 361 | - case 'active':  | 
                                                        |
| 362 | - $total_items = $this->active_count;  | 
                                                        |
| 363 | - break;  | 
                                                        |
| 364 | - case 'pending':  | 
                                                        |
| 365 | - $total_items = $this->pending_count;  | 
                                                        |
| 366 | - break;  | 
                                                        |
| 367 | - case 'expired':  | 
                                                        |
| 368 | - $total_items = $this->expired_count;  | 
                                                        |
| 369 | - break;  | 
                                                        |
| 370 | - case 'cancelled':  | 
                                                        |
| 371 | - $total_items = $this->cancelled_count;  | 
                                                        |
| 372 | - break;  | 
                                                        |
| 373 | - case 'failing':  | 
                                                        |
| 374 | - $total_items = $this->failing_count;  | 
                                                        |
| 375 | - break;  | 
                                                        |
| 376 | - case 'trialling':  | 
                                                        |
| 377 | - $total_items = $this->trialling_count;  | 
                                                        |
| 378 | - break;  | 
                                                        |
| 379 | - case 'completed':  | 
                                                        |
| 380 | - $total_items = $this->completed_count;  | 
                                                        |
| 381 | - break;  | 
                                                        |
| 382 | - case 'any':  | 
                                                        |
| 383 | - default:  | 
                                                        |
| 384 | - $total_items = $this->total_count;  | 
                                                        |
| 385 | - break;  | 
                                                        |
| 386 | - }  | 
                                                        |
| 387 | -  | 
                                                        |
| 388 | - $this->set_pagination_args( array(  | 
                                                        |
| 389 | - 'total_items' => $total_items,  | 
                                                        |
| 390 | - 'per_page' => $this->per_page,  | 
                                                        |
| 391 | - 'total_pages' => ceil( $total_items / $this->per_page )  | 
                                                        |
| 392 | - ) );  | 
                                                        |
| 393 | - }  | 
                                                        |
| 154 | + /**  | 
                                                        |
| 155 | + * Customer column  | 
                                                        |
| 156 | + *  | 
                                                        |
| 157 | + * @access private  | 
                                                        |
| 158 | + * @since 1.0.0  | 
                                                        |
| 159 | + * @return string  | 
                                                        |
| 160 | + */  | 
                                                        |
| 161 | +    function column_customer_id( $item ) { | 
                                                        |
| 162 | + $subscriber = get_userdata( $item->customer_id );  | 
                                                        |
| 163 | + $customer = ! empty( $subscriber->display_name ) ? $subscriber->display_name : $subscriber->user_email;  | 
                                                        |
| 164 | +  | 
                                                        |
| 165 | + return '<a href="' . esc_url( get_edit_user_link( $item->customer_id ) ) . '" target="_blank">' . $customer . '</a>';  | 
                                                        |
| 166 | + }  | 
                                                        |
| 167 | +  | 
                                                        |
| 168 | + /**  | 
                                                        |
| 169 | + * Status column  | 
                                                        |
| 170 | + *  | 
                                                        |
| 171 | + * @access private  | 
                                                        |
| 172 | + * @since 1.0.0  | 
                                                        |
| 173 | + * @return string  | 
                                                        |
| 174 | + */  | 
                                                        |
| 175 | +    function column_status( $item ) { | 
                                                        |
| 176 | + return $item->get_status_label();  | 
                                                        |
| 177 | + }  | 
                                                        |
| 178 | +  | 
                                                        |
| 179 | + /**  | 
                                                        |
| 180 | + * Period column  | 
                                                        |
| 181 | + *  | 
                                                        |
| 182 | + * @access private  | 
                                                        |
| 183 | + * @since 1.0.0  | 
                                                        |
| 184 | + * @return string  | 
                                                        |
| 185 | + */  | 
                                                        |
| 186 | +    function column_period( $item ) { | 
                                                        |
| 187 | +  | 
                                                        |
| 188 | + $period = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->period,$item->frequency );  | 
                                                        |
| 189 | +  | 
                                                        |
| 190 | + return wpinv_price( wpinv_format_amount( $item->recurring_amount ), wpinv_get_invoice_currency_code( $item->parent_payment_id ) ) . ' / ' . $period;  | 
                                                        |
| 191 | + }  | 
                                                        |
| 192 | +  | 
                                                        |
| 193 | + /**  | 
                                                        |
| 194 | + * Billing Times column  | 
                                                        |
| 195 | + *  | 
                                                        |
| 196 | + * @access private  | 
                                                        |
| 197 | + * @since 1.0.0  | 
                                                        |
| 198 | + * @return string  | 
                                                        |
| 199 | + */  | 
                                                        |
| 200 | +    function column_bill_times( $item ) { | 
                                                        |
| 201 | + return $item->get_times_billed() . ' / ' . ( ( $item->bill_times == 0 ) ? 'Until Cancelled' : $item->bill_times );  | 
                                                        |
| 202 | + }  | 
                                                        |
| 203 | +  | 
                                                        |
| 204 | + /**  | 
                                                        |
| 205 | + * Initial Amount column  | 
                                                        |
| 206 | + *  | 
                                                        |
| 207 | + * @access private  | 
                                                        |
| 208 | + * @since 1.0.0  | 
                                                        |
| 209 | + * @return string  | 
                                                        |
| 210 | + */  | 
                                                        |
| 211 | +    function column_initial_amount( $item ) { | 
                                                        |
| 212 | + return wpinv_price( wpinv_format_amount( $item->initial_amount ), wpinv_get_invoice_currency_code( $item->parent_payment_id ) );  | 
                                                        |
| 213 | + }  | 
                                                        |
| 214 | +  | 
                                                        |
| 215 | + /**  | 
                                                        |
| 216 | + * Renewal date column  | 
                                                        |
| 217 | + *  | 
                                                        |
| 218 | + * @access private  | 
                                                        |
| 219 | + * @since 1.0.0  | 
                                                        |
| 220 | + * @return string  | 
                                                        |
| 221 | + */  | 
                                                        |
| 222 | +    function column_renewal_date( $item ) { | 
                                                        |
| 223 | + return $renewal_date = ! empty( $item->expiration ) ? date_i18n( get_option( 'date_format' ), strtotime( $item->expiration ) ) : __( 'N/A', 'invoicing' );  | 
                                                        |
| 224 | + }  | 
                                                        |
| 225 | +  | 
                                                        |
| 226 | + /**  | 
                                                        |
| 227 | + * Payment column  | 
                                                        |
| 228 | + *  | 
                                                        |
| 229 | + * @access private  | 
                                                        |
| 230 | + * @since 1.0.0  | 
                                                        |
| 231 | + * @return string  | 
                                                        |
| 232 | + */  | 
                                                        |
| 233 | +    function column_parent_payment_id( $item ) { | 
                                                        |
| 234 | + return '<a href="' . get_edit_post_link( $item->parent_payment_id ) . '" target="_blank">' . wpinv_get_invoice_number( $item->parent_payment_id ) . '</a>';  | 
                                                        |
| 235 | + }  | 
                                                        |
| 236 | +  | 
                                                        |
| 237 | + /**  | 
                                                        |
| 238 | + * Product ID column  | 
                                                        |
| 239 | + *  | 
                                                        |
| 240 | + * @access private  | 
                                                        |
| 241 | + * @since 1.0.0  | 
                                                        |
| 242 | + * @return string  | 
                                                        |
| 243 | + */  | 
                                                        |
| 244 | +    function column_product_id( $item ) { | 
                                                        |
| 245 | + return '<a href="' . esc_url( admin_url( 'post.php?action=edit&post=' . $item->product_id ) ) . '" target="_blank">' . get_the_title( $item->product_id ) . '</a>';  | 
                                                        |
| 246 | + }  | 
                                                        |
| 247 | +  | 
                                                        |
| 248 | + /**  | 
                                                        |
| 249 | + * Render the edit column  | 
                                                        |
| 250 | + *  | 
                                                        |
| 251 | + * @access private  | 
                                                        |
| 252 | + * @since 2.0  | 
                                                        |
| 253 | + * @return string  | 
                                                        |
| 254 | + */  | 
                                                        |
| 255 | +    function column_actions( $item ) { | 
                                                        |
| 256 | + return '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $item->id ) ) . '" title="' . esc_attr( __( 'View or edit subscription', 'invoicing' ) ) . '" target="_blank">' . __( 'View', 'invoicing' ) . '</a>';  | 
                                                        |
| 257 | + }  | 
                                                        |
| 258 | +  | 
                                                        |
| 259 | +  | 
                                                        |
| 260 | + /**  | 
                                                        |
| 261 | + * Retrieve the table columns  | 
                                                        |
| 262 | + *  | 
                                                        |
| 263 | + * @access private  | 
                                                        |
| 264 | + * @since 1.0.0  | 
                                                        |
| 265 | + * @return array  | 
                                                        |
| 266 | + */  | 
                                                        |
| 267 | +  | 
                                                        |
| 268 | +    function get_columns(){ | 
                                                        |
| 269 | + $columns = array(  | 
                                                        |
| 270 | + 'sub_id' => __( 'ID', 'invoicing' ),  | 
                                                        |
| 271 | + 'customer_id' => __( 'Customer', 'invoicing' ),  | 
                                                        |
| 272 | + 'status' => __( 'Status', 'invoicing' ),  | 
                                                        |
| 273 | + 'period' => __( 'Billing Cycle', 'invoicing' ),  | 
                                                        |
| 274 | + 'initial_amount' => __( 'Initial Amount', 'invoicing' ),  | 
                                                        |
| 275 | + 'bill_times' => __( 'Times Billed', 'invoicing' ),  | 
                                                        |
| 276 | + 'renewal_date' => __( 'Renewal Date', 'invoicing' ),  | 
                                                        |
| 277 | + 'parent_payment_id' => __( 'Invoice', 'invoicing' ),  | 
                                                        |
| 278 | + 'product_id' => __( 'Item', 'invoicing' ),  | 
                                                        |
| 279 | + 'actions' => __( 'Actions', 'invoicing' ),  | 
                                                        |
| 280 | + );  | 
                                                        |
| 281 | +  | 
                                                        |
| 282 | + return apply_filters( 'wpinv_report_subscription_columns', $columns );  | 
                                                        |
| 283 | + }  | 
                                                        |
| 284 | +  | 
                                                        |
| 285 | + /**  | 
                                                        |
| 286 | + * Retrieve the current page number  | 
                                                        |
| 287 | + *  | 
                                                        |
| 288 | + * @access private  | 
                                                        |
| 289 | + * @since 1.0.0  | 
                                                        |
| 290 | + * @return int  | 
                                                        |
| 291 | + */  | 
                                                        |
| 292 | +    function get_paged() { | 
                                                        |
| 293 | + return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;  | 
                                                        |
| 294 | + }  | 
                                                        |
| 295 | +  | 
                                                        |
| 296 | + /**  | 
                                                        |
| 297 | + * Retrieve the subscription counts  | 
                                                        |
| 298 | + *  | 
                                                        |
| 299 | + * @access public  | 
                                                        |
| 300 | + * @since 1.4  | 
                                                        |
| 301 | + * @return void  | 
                                                        |
| 302 | + */  | 
                                                        |
| 303 | +    public function get_subscription_counts() { | 
                                                        |
| 304 | +  | 
                                                        |
| 305 | + global $wp_query;  | 
                                                        |
| 306 | +  | 
                                                        |
| 307 | + $db = new WPInv_Subscriptions_DB;  | 
                                                        |
| 308 | +  | 
                                                        |
| 309 | + $search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : '';  | 
                                                        |
| 310 | +  | 
                                                        |
| 311 | + $this->total_count = $db->count();  | 
                                                        |
| 312 | + $this->active_count = $db->count( array( 'status' => 'active', 'search' => $search ) );  | 
                                                        |
| 313 | + $this->pending_count = $db->count( array( 'status' => 'pending', 'search' => $search ) );  | 
                                                        |
| 314 | + $this->expired_count = $db->count( array( 'status' => 'expired', 'search' => $search ) );  | 
                                                        |
| 315 | + $this->trialling_count = $db->count( array( 'status' => 'trialling', 'search' => $search ) );  | 
                                                        |
| 316 | + $this->cancelled_count = $db->count( array( 'status' => 'cancelled', 'search' => $search ) );  | 
                                                        |
| 317 | + $this->completed_count = $db->count( array( 'status' => 'completed', 'search' => $search ) );  | 
                                                        |
| 318 | + $this->failing_count = $db->count( array( 'status' => 'failing', 'search' => $search ) );  | 
                                                        |
| 319 | +  | 
                                                        |
| 320 | + }  | 
                                                        |
| 321 | +  | 
                                                        |
| 322 | + /**  | 
                                                        |
| 323 | + * Setup the final data for the table  | 
                                                        |
| 324 | + *  | 
                                                        |
| 325 | + * @access private  | 
                                                        |
| 326 | + * @since 1.0.0  | 
                                                        |
| 327 | + * @uses $this->_column_headers  | 
                                                        |
| 328 | + * @uses $this->items  | 
                                                        |
| 329 | + * @uses $this->get_columns()  | 
                                                        |
| 330 | + * @uses $this->get_sortable_columns()  | 
                                                        |
| 331 | + * @uses $this->get_pagenum()  | 
                                                        |
| 332 | + * @uses $this->set_pagination_args()  | 
                                                        |
| 333 | + * @return array  | 
                                                        |
| 334 | + */  | 
                                                        |
| 335 | +    function prepare_items() { | 
                                                        |
| 336 | +  | 
                                                        |
| 337 | + $columns = $this->get_columns();  | 
                                                        |
| 338 | + $hidden = array(); // No hidden columns  | 
                                                        |
| 339 | + $status = isset( $_GET['status'] ) ? $_GET['status'] : 'any';  | 
                                                        |
| 340 | + $sortable = $this->get_sortable_columns();  | 
                                                        |
| 341 | +  | 
                                                        |
| 342 | + $this->_column_headers = array( $columns, $hidden, $sortable );  | 
                                                        |
| 343 | +  | 
                                                        |
| 344 | + $current_page = $this->get_pagenum();  | 
                                                        |
| 345 | +  | 
                                                        |
| 346 | + $db = new WPInv_Subscriptions_DB;  | 
                                                        |
| 347 | + $search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : '';  | 
                                                        |
| 348 | + $args = array(  | 
                                                        |
| 349 | + 'number' => $this->per_page,  | 
                                                        |
| 350 | + 'offset' => $this->per_page * ( $this->get_paged() - 1 ),  | 
                                                        |
| 351 | + 'search' => $search  | 
                                                        |
| 352 | + );  | 
                                                        |
| 353 | +  | 
                                                        |
| 354 | +        if ( 'any' !== $status ) { | 
                                                        |
| 355 | + $args['status'] = $status;  | 
                                                        |
| 356 | + }  | 
                                                        |
| 357 | +  | 
                                                        |
| 358 | + $this->items = $db->get_subscriptions( $args );  | 
                                                        |
| 359 | +  | 
                                                        |
| 360 | +        switch ( $status ) { | 
                                                        |
| 361 | + case 'active':  | 
                                                        |
| 362 | + $total_items = $this->active_count;  | 
                                                        |
| 363 | + break;  | 
                                                        |
| 364 | + case 'pending':  | 
                                                        |
| 365 | + $total_items = $this->pending_count;  | 
                                                        |
| 366 | + break;  | 
                                                        |
| 367 | + case 'expired':  | 
                                                        |
| 368 | + $total_items = $this->expired_count;  | 
                                                        |
| 369 | + break;  | 
                                                        |
| 370 | + case 'cancelled':  | 
                                                        |
| 371 | + $total_items = $this->cancelled_count;  | 
                                                        |
| 372 | + break;  | 
                                                        |
| 373 | + case 'failing':  | 
                                                        |
| 374 | + $total_items = $this->failing_count;  | 
                                                        |
| 375 | + break;  | 
                                                        |
| 376 | + case 'trialling':  | 
                                                        |
| 377 | + $total_items = $this->trialling_count;  | 
                                                        |
| 378 | + break;  | 
                                                        |
| 379 | + case 'completed':  | 
                                                        |
| 380 | + $total_items = $this->completed_count;  | 
                                                        |
| 381 | + break;  | 
                                                        |
| 382 | + case 'any':  | 
                                                        |
| 383 | + default:  | 
                                                        |
| 384 | + $total_items = $this->total_count;  | 
                                                        |
| 385 | + break;  | 
                                                        |
| 386 | + }  | 
                                                        |
| 387 | +  | 
                                                        |
| 388 | + $this->set_pagination_args( array(  | 
                                                        |
| 389 | + 'total_items' => $total_items,  | 
                                                        |
| 390 | + 'per_page' => $this->per_page,  | 
                                                        |
| 391 | + 'total_pages' => ceil( $total_items / $this->per_page )  | 
                                                        |
| 392 | + ) );  | 
                                                        |
| 393 | + }  | 
                                                        |
| 394 | 394 | }  | 
                                                        
@@ -8,11 +8,11 @@ discard block  | 
                                                    ||
| 8 | 8 | |
| 9 | 9 | |
| 10 | 10 | // Exit if accessed directly  | 
                                                        
| 11 | -if ( ! defined( 'ABSPATH' ) ) exit;  | 
                                                        |
| 11 | +if (!defined('ABSPATH')) exit; | 
                                                        |
| 12 | 12 | |
| 13 | 13 | |
| 14 | 14 | // Load WP_List_Table if not loaded  | 
                                                        
| 15 | -if( ! class_exists( 'WP_List_Table' ) ) { | 
                                                        |
| 15 | +if (!class_exists('WP_List_Table')) { | 
                                                        |
| 16 | 16 | require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';  | 
                                                        
| 17 | 17 | }  | 
                                                        
| 18 | 18 | |
@@ -35,7 +35,7 @@ discard block  | 
                                                    ||
| 35 | 35 | public $pending_count = 0;  | 
                                                        
| 36 | 36 | public $expired_count = 0;  | 
                                                        
| 37 | 37 | public $completed_count = 0;  | 
                                                        
| 38 | - public $trialling_count = 0;  | 
                                                        |
| 38 | + public $trialling_count = 0;  | 
                                                        |
| 39 | 39 | public $cancelled_count = 0;  | 
                                                        
| 40 | 40 | public $failing_count = 0;  | 
                                                        
| 41 | 41 | |
@@ -46,15 +46,15 @@ discard block  | 
                                                    ||
| 46 | 46 | * @since 1.0.0  | 
                                                        
| 47 | 47 | * @return void  | 
                                                        
| 48 | 48 | */  | 
                                                        
| 49 | -	function __construct(){ | 
                                                        |
| 49 | +	function __construct() { | 
                                                        |
| 50 | 50 | global $status, $page;  | 
                                                        
| 51 | 51 | |
| 52 | 52 | // Set parent defaults  | 
                                                        
| 53 | - parent::__construct( array(  | 
                                                        |
| 53 | + parent::__construct(array(  | 
                                                        |
| 54 | 54 | 'singular' => 'subscription',  | 
                                                        
| 55 | 55 | 'plural' => 'subscriptions',  | 
                                                        
| 56 | 56 | 'ajax' => false  | 
                                                        
| 57 | - ) );  | 
                                                        |
| 57 | + ));  | 
                                                        |
| 58 | 58 | |
| 59 | 59 | $this->get_subscription_counts();  | 
                                                        
| 60 | 60 | |
@@ -69,28 +69,28 @@ discard block  | 
                                                    ||
| 69 | 69 | */  | 
                                                        
| 70 | 70 |  	public function get_views() { | 
                                                        
| 71 | 71 | |
| 72 | - $current = isset( $_GET['status'] ) ? $_GET['status'] : '';  | 
                                                        |
| 73 | -		$total_count     = ' <span class="count">(' . $this->total_count    . ')</span>'; | 
                                                        |
| 72 | + $current = isset($_GET['status']) ? $_GET['status'] : '';  | 
                                                        |
| 73 | +		$total_count     = ' <span class="count">(' . $this->total_count . ')</span>'; | 
                                                        |
| 74 | 74 |  		$active_count    = ' <span class="count">(' . $this->active_count . ')</span>'; | 
                                                        
| 75 | 75 |  		$pending_count   = ' <span class="count">(' . $this->pending_count . ')</span>'; | 
                                                        
| 76 | -		$expired_count   = ' <span class="count">(' . $this->expired_count  . ')</span>'; | 
                                                        |
| 76 | +		$expired_count   = ' <span class="count">(' . $this->expired_count . ')</span>'; | 
                                                        |
| 77 | 77 |  		$completed_count = ' <span class="count">(' . $this->completed_count . ')</span>'; | 
                                                        
| 78 | -		$trialling_count  = ' <span class="count">(' . $this->trialling_count   . ')</span>'; | 
                                                        |
| 79 | -		$cancelled_count = ' <span class="count">(' . $this->cancelled_count   . ')</span>'; | 
                                                        |
| 80 | -		$failing_count   = ' <span class="count">(' . $this->failing_count   . ')</span>'; | 
                                                        |
| 78 | +		$trialling_count = ' <span class="count">(' . $this->trialling_count . ')</span>'; | 
                                                        |
| 79 | +		$cancelled_count = ' <span class="count">(' . $this->cancelled_count . ')</span>'; | 
                                                        |
| 80 | +		$failing_count   = ' <span class="count">(' . $this->failing_count . ')</span>'; | 
                                                        |
| 81 | 81 | |
| 82 | 82 | $views = array(  | 
                                                        
| 83 | -			'all'       => sprintf( '<a href="%s"%s>%s</a>', remove_query_arg( array( 'status', 'paged' ) ), $current === 'all' || $current == '' ? ' class="current"' : '', __('All','invoicing' ) . $total_count ), | 
                                                        |
| 84 | -			'active'    => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'active', 'paged' => FALSE ) ), $current === 'active' ? ' class="current"' : '', __('Active','invoicing' ) . $active_count ), | 
                                                        |
| 85 | -			'pending'   => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'pending', 'paged' => FALSE ) ), $current === 'pending' ? ' class="current"' : '', __('Pending','invoicing' ) . $pending_count ), | 
                                                        |
| 86 | -			'expired'   => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'expired', 'paged' => FALSE ) ), $current === 'expired' ? ' class="current"' : '', __('Expired','invoicing' ) . $expired_count ), | 
                                                        |
| 87 | -			'completed' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'completed', 'paged' => FALSE ) ), $current === 'completed' ? ' class="current"' : '', __('Completed','invoicing' ) . $completed_count ), | 
                                                        |
| 88 | -			'trialling'  => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'trialling', 'paged' => FALSE ) ), $current === 'trialling' ? ' class="current"' : '', __('Trialling','invoicing' ) . $trialling_count ), | 
                                                        |
| 89 | -			'cancelled' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'cancelled', 'paged' => FALSE ) ), $current === 'cancelled' ? ' class="current"' : '', __('Cancelled','invoicing' ) . $cancelled_count ), | 
                                                        |
| 90 | -			'failing'   => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'failing', 'paged' => FALSE ) ), $current === 'failing' ? ' class="current"' : '', __('Failing','invoicing' ) . $failing_count ), | 
                                                        |
| 83 | +			'all'       => sprintf('<a href="%s"%s>%s</a>', remove_query_arg(array('status', 'paged')), $current === 'all' || $current == '' ? ' class="current"' : '', __('All', 'invoicing') . $total_count), | 
                                                        |
| 84 | +			'active'    => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'active', 'paged' => FALSE)), $current === 'active' ? ' class="current"' : '', __('Active', 'invoicing') . $active_count), | 
                                                        |
| 85 | +			'pending'   => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'pending', 'paged' => FALSE)), $current === 'pending' ? ' class="current"' : '', __('Pending', 'invoicing') . $pending_count), | 
                                                        |
| 86 | +			'expired'   => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'expired', 'paged' => FALSE)), $current === 'expired' ? ' class="current"' : '', __('Expired', 'invoicing') . $expired_count), | 
                                                        |
| 87 | +			'completed' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'completed', 'paged' => FALSE)), $current === 'completed' ? ' class="current"' : '', __('Completed', 'invoicing') . $completed_count), | 
                                                        |
| 88 | +			'trialling'  => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'trialling', 'paged' => FALSE)), $current === 'trialling' ? ' class="current"' : '', __('Trialling', 'invoicing') . $trialling_count), | 
                                                        |
| 89 | +			'cancelled' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'cancelled', 'paged' => FALSE)), $current === 'cancelled' ? ' class="current"' : '', __('Cancelled', 'invoicing') . $cancelled_count), | 
                                                        |
| 90 | +			'failing'   => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'failing', 'paged' => FALSE)), $current === 'failing' ? ' class="current"' : '', __('Failing', 'invoicing') . $failing_count), | 
                                                        |
| 91 | 91 | );  | 
                                                        
| 92 | 92 | |
| 93 | - return apply_filters( 'wpinv_recurring_subscriptions_table_views', $views );  | 
                                                        |
| 93 | +		return apply_filters('wpinv_recurring_subscriptions_table_views', $views); | 
                                                        |
| 94 | 94 | }  | 
                                                        
| 95 | 95 | |
| 96 | 96 | /**  | 
                                                        
@@ -104,27 +104,27 @@ discard block  | 
                                                    ||
| 104 | 104 | *  | 
                                                        
| 105 | 105 | * @return void  | 
                                                        
| 106 | 106 | */  | 
                                                        
| 107 | -	public function search_box( $text, $input_id ) { | 
                                                        |
| 107 | +	public function search_box($text, $input_id) { | 
                                                        |
| 108 | 108 | |
| 109 | -		if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) { | 
                                                        |
| 109 | +		if (empty($_REQUEST['s']) && !$this->has_items()) { | 
                                                        |
| 110 | 110 | return;  | 
                                                        
| 111 | 111 | }  | 
                                                        
| 112 | 112 | |
| 113 | 113 | $input_id = $input_id . '-search-input';  | 
                                                        
| 114 | 114 | |
| 115 | -		if ( ! empty( $_REQUEST['orderby'] ) ) { | 
                                                        |
| 116 | - echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />';  | 
                                                        |
| 115 | +		if (!empty($_REQUEST['orderby'])) { | 
                                                        |
| 116 | + echo '<input type="hidden" name="orderby" value="' . esc_attr($_REQUEST['orderby']) . '" />';  | 
                                                        |
| 117 | 117 | }  | 
                                                        
| 118 | 118 | |
| 119 | -		if ( ! empty( $_REQUEST['order'] ) ) { | 
                                                        |
| 120 | - echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />';  | 
                                                        |
| 119 | +		if (!empty($_REQUEST['order'])) { | 
                                                        |
| 120 | + echo '<input type="hidden" name="order" value="' . esc_attr($_REQUEST['order']) . '" />';  | 
                                                        |
| 121 | 121 | }  | 
                                                        
| 122 | 122 | ?>  | 
                                                        
| 123 | 123 | <p class="search-box">  | 
                                                        
| 124 | - <?php do_action( 'wpinv_recurring_subscription_search_box' ); ?>  | 
                                                        |
| 124 | +			<?php do_action('wpinv_recurring_subscription_search_box'); ?> | 
                                                        |
| 125 | 125 | <label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label>  | 
                                                        
| 126 | 126 | <input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>" />  | 
                                                        
| 127 | -			<?php submit_button( $text, 'button', false, false, array('ID' => 'search-submit') ); ?><br/> | 
                                                        |
| 127 | +			<?php submit_button($text, 'button', false, false, array('ID' => 'search-submit')); ?><br/> | 
                                                        |
| 128 | 128 | </p>  | 
                                                        
| 129 | 129 | <?php  | 
                                                        
| 130 | 130 | }  | 
                                                        
@@ -136,7 +136,7 @@ discard block  | 
                                                    ||
| 136 | 136 | * @since 1.0.0  | 
                                                        
| 137 | 137 | * @return string  | 
                                                        
| 138 | 138 | */  | 
                                                        
| 139 | -	function column_default( $item, $column_name ) { | 
                                                        |
| 139 | +	function column_default($item, $column_name) { | 
                                                        |
| 140 | 140 | return $item->$column_name;  | 
                                                        
| 141 | 141 | }  | 
                                                        
| 142 | 142 | |
@@ -147,8 +147,8 @@ discard block  | 
                                                    ||
| 147 | 147 | * @since 1.0.0  | 
                                                        
| 148 | 148 | * @return string  | 
                                                        
| 149 | 149 | */  | 
                                                        
| 150 | -    function column_sub_id( $item ) { | 
                                                        |
| 151 | - return '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $item->id ) ) . '" target="_blank">' . $item->id . '</a>';  | 
                                                        |
| 150 | +    function column_sub_id($item) { | 
                                                        |
| 151 | +        return '<a href="' . esc_url(admin_url('admin.php?page=wpinv-subscriptions&id=' . $item->id)) . '" target="_blank">' . $item->id . '</a>'; | 
                                                        |
| 152 | 152 | }  | 
                                                        
| 153 | 153 | |
| 154 | 154 | /**  | 
                                                        
@@ -158,11 +158,11 @@ discard block  | 
                                                    ||
| 158 | 158 | * @since 1.0.0  | 
                                                        
| 159 | 159 | * @return string  | 
                                                        
| 160 | 160 | */  | 
                                                        
| 161 | -	function column_customer_id( $item ) { | 
                                                        |
| 162 | - $subscriber = get_userdata( $item->customer_id );  | 
                                                        |
| 163 | - $customer = ! empty( $subscriber->display_name ) ? $subscriber->display_name : $subscriber->user_email;  | 
                                                        |
| 161 | +	function column_customer_id($item) { | 
                                                        |
| 162 | + $subscriber = get_userdata($item->customer_id);  | 
                                                        |
| 163 | + $customer = !empty($subscriber->display_name) ? $subscriber->display_name : $subscriber->user_email;  | 
                                                        |
| 164 | 164 | |
| 165 | - return '<a href="' . esc_url( get_edit_user_link( $item->customer_id ) ) . '" target="_blank">' . $customer . '</a>';  | 
                                                        |
| 165 | + return '<a href="' . esc_url(get_edit_user_link($item->customer_id)) . '" target="_blank">' . $customer . '</a>';  | 
                                                        |
| 166 | 166 | }  | 
                                                        
| 167 | 167 | |
| 168 | 168 | /**  | 
                                                        
@@ -172,7 +172,7 @@ discard block  | 
                                                    ||
| 172 | 172 | * @since 1.0.0  | 
                                                        
| 173 | 173 | * @return string  | 
                                                        
| 174 | 174 | */  | 
                                                        
| 175 | -	function column_status( $item ) { | 
                                                        |
| 175 | +	function column_status($item) { | 
                                                        |
| 176 | 176 | return $item->get_status_label();  | 
                                                        
| 177 | 177 | }  | 
                                                        
| 178 | 178 | |
@@ -183,11 +183,11 @@ discard block  | 
                                                    ||
| 183 | 183 | * @since 1.0.0  | 
                                                        
| 184 | 184 | * @return string  | 
                                                        
| 185 | 185 | */  | 
                                                        
| 186 | -	function column_period( $item ) { | 
                                                        |
| 186 | +	function column_period($item) { | 
                                                        |
| 187 | 187 | |
| 188 | - $period = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->period,$item->frequency );  | 
                                                        |
| 188 | + $period = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($item->period, $item->frequency);  | 
                                                        |
| 189 | 189 | |
| 190 | - return wpinv_price( wpinv_format_amount( $item->recurring_amount ), wpinv_get_invoice_currency_code( $item->parent_payment_id ) ) . ' / ' . $period;  | 
                                                        |
| 190 | + return wpinv_price(wpinv_format_amount($item->recurring_amount), wpinv_get_invoice_currency_code($item->parent_payment_id)) . ' / ' . $period;  | 
                                                        |
| 191 | 191 | }  | 
                                                        
| 192 | 192 | |
| 193 | 193 | /**  | 
                                                        
@@ -197,8 +197,8 @@ discard block  | 
                                                    ||
| 197 | 197 | * @since 1.0.0  | 
                                                        
| 198 | 198 | * @return string  | 
                                                        
| 199 | 199 | */  | 
                                                        
| 200 | -	function column_bill_times( $item ) { | 
                                                        |
| 201 | - return $item->get_times_billed() . ' / ' . ( ( $item->bill_times == 0 ) ? 'Until Cancelled' : $item->bill_times );  | 
                                                        |
| 200 | +	function column_bill_times($item) { | 
                                                        |
| 201 | + return $item->get_times_billed() . ' / ' . (($item->bill_times == 0) ? 'Until Cancelled' : $item->bill_times);  | 
                                                        |
| 202 | 202 | }  | 
                                                        
| 203 | 203 | |
| 204 | 204 | /**  | 
                                                        
@@ -208,8 +208,8 @@ discard block  | 
                                                    ||
| 208 | 208 | * @since 1.0.0  | 
                                                        
| 209 | 209 | * @return string  | 
                                                        
| 210 | 210 | */  | 
                                                        
| 211 | -	function column_initial_amount( $item ) { | 
                                                        |
| 212 | - return wpinv_price( wpinv_format_amount( $item->initial_amount ), wpinv_get_invoice_currency_code( $item->parent_payment_id ) );  | 
                                                        |
| 211 | +	function column_initial_amount($item) { | 
                                                        |
| 212 | + return wpinv_price(wpinv_format_amount($item->initial_amount), wpinv_get_invoice_currency_code($item->parent_payment_id));  | 
                                                        |
| 213 | 213 | }  | 
                                                        
| 214 | 214 | |
| 215 | 215 | /**  | 
                                                        
@@ -219,8 +219,8 @@ discard block  | 
                                                    ||
| 219 | 219 | * @since 1.0.0  | 
                                                        
| 220 | 220 | * @return string  | 
                                                        
| 221 | 221 | */  | 
                                                        
| 222 | -	function column_renewal_date( $item ) { | 
                                                        |
| 223 | - return $renewal_date = ! empty( $item->expiration ) ? date_i18n( get_option( 'date_format' ), strtotime( $item->expiration ) ) : __( 'N/A', 'invoicing' );  | 
                                                        |
| 222 | +	function column_renewal_date($item) { | 
                                                        |
| 223 | +		return $renewal_date = !empty($item->expiration) ? date_i18n(get_option('date_format'), strtotime($item->expiration)) : __('N/A', 'invoicing'); | 
                                                        |
| 224 | 224 | }  | 
                                                        
| 225 | 225 | |
| 226 | 226 | /**  | 
                                                        
@@ -230,8 +230,8 @@ discard block  | 
                                                    ||
| 230 | 230 | * @since 1.0.0  | 
                                                        
| 231 | 231 | * @return string  | 
                                                        
| 232 | 232 | */  | 
                                                        
| 233 | -	function column_parent_payment_id( $item ) { | 
                                                        |
| 234 | - return '<a href="' . get_edit_post_link( $item->parent_payment_id ) . '" target="_blank">' . wpinv_get_invoice_number( $item->parent_payment_id ) . '</a>';  | 
                                                        |
| 233 | +	function column_parent_payment_id($item) { | 
                                                        |
| 234 | + return '<a href="' . get_edit_post_link($item->parent_payment_id) . '" target="_blank">' . wpinv_get_invoice_number($item->parent_payment_id) . '</a>';  | 
                                                        |
| 235 | 235 | }  | 
                                                        
| 236 | 236 | |
| 237 | 237 | /**  | 
                                                        
@@ -241,8 +241,8 @@ discard block  | 
                                                    ||
| 241 | 241 | * @since 1.0.0  | 
                                                        
| 242 | 242 | * @return string  | 
                                                        
| 243 | 243 | */  | 
                                                        
| 244 | -	function column_product_id( $item ) { | 
                                                        |
| 245 | - return '<a href="' . esc_url( admin_url( 'post.php?action=edit&post=' . $item->product_id ) ) . '" target="_blank">' . get_the_title( $item->product_id ) . '</a>';  | 
                                                        |
| 244 | +	function column_product_id($item) { | 
                                                        |
| 245 | +		return '<a href="' . esc_url(admin_url('post.php?action=edit&post=' . $item->product_id)) . '" target="_blank">' . get_the_title($item->product_id) . '</a>'; | 
                                                        |
| 246 | 246 | }  | 
                                                        
| 247 | 247 | |
| 248 | 248 | /**  | 
                                                        
@@ -252,8 +252,8 @@ discard block  | 
                                                    ||
| 252 | 252 | * @since 2.0  | 
                                                        
| 253 | 253 | * @return string  | 
                                                        
| 254 | 254 | */  | 
                                                        
| 255 | -	function column_actions( $item ) { | 
                                                        |
| 256 | - return '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $item->id ) ) . '" title="' . esc_attr( __( 'View or edit subscription', 'invoicing' ) ) . '" target="_blank">' . __( 'View', 'invoicing' ) . '</a>';  | 
                                                        |
| 255 | +	function column_actions($item) { | 
                                                        |
| 256 | +		return '<a href="' . esc_url(admin_url('admin.php?page=wpinv-subscriptions&id=' . $item->id)) . '" title="' . esc_attr(__('View or edit subscription', 'invoicing')) . '" target="_blank">' . __('View', 'invoicing') . '</a>'; | 
                                                        |
| 257 | 257 | }  | 
                                                        
| 258 | 258 | |
| 259 | 259 | |
@@ -265,21 +265,21 @@ discard block  | 
                                                    ||
| 265 | 265 | * @return array  | 
                                                        
| 266 | 266 | */  | 
                                                        
| 267 | 267 | |
| 268 | -	function get_columns(){ | 
                                                        |
| 268 | +	function get_columns() { | 
                                                        |
| 269 | 269 | $columns = array(  | 
                                                        
| 270 | - 'sub_id' => __( 'ID', 'invoicing' ),  | 
                                                        |
| 271 | - 'customer_id' => __( 'Customer', 'invoicing' ),  | 
                                                        |
| 272 | - 'status' => __( 'Status', 'invoicing' ),  | 
                                                        |
| 273 | - 'period' => __( 'Billing Cycle', 'invoicing' ),  | 
                                                        |
| 274 | - 'initial_amount' => __( 'Initial Amount', 'invoicing' ),  | 
                                                        |
| 275 | - 'bill_times' => __( 'Times Billed', 'invoicing' ),  | 
                                                        |
| 276 | - 'renewal_date' => __( 'Renewal Date', 'invoicing' ),  | 
                                                        |
| 277 | - 'parent_payment_id' => __( 'Invoice', 'invoicing' ),  | 
                                                        |
| 278 | - 'product_id' => __( 'Item', 'invoicing' ),  | 
                                                        |
| 279 | - 'actions' => __( 'Actions', 'invoicing' ),  | 
                                                        |
| 270 | +			'sub_id'            => __('ID', 'invoicing'), | 
                                                        |
| 271 | +			'customer_id'       => __('Customer', 'invoicing'), | 
                                                        |
| 272 | +			'status'            => __('Status', 'invoicing'), | 
                                                        |
| 273 | +			'period'            => __('Billing Cycle', 'invoicing'), | 
                                                        |
| 274 | +			'initial_amount'    => __('Initial Amount', 'invoicing'), | 
                                                        |
| 275 | +			'bill_times'        => __('Times Billed', 'invoicing'), | 
                                                        |
| 276 | +			'renewal_date'      => __('Renewal Date', 'invoicing'), | 
                                                        |
| 277 | +			'parent_payment_id' => __('Invoice', 'invoicing'), | 
                                                        |
| 278 | +			'product_id'        => __('Item', 'invoicing'), | 
                                                        |
| 279 | +			'actions'           => __('Actions', 'invoicing'), | 
                                                        |
| 280 | 280 | );  | 
                                                        
| 281 | 281 | |
| 282 | - return apply_filters( 'wpinv_report_subscription_columns', $columns );  | 
                                                        |
| 282 | +		return apply_filters('wpinv_report_subscription_columns', $columns); | 
                                                        |
| 283 | 283 | }  | 
                                                        
| 284 | 284 | |
| 285 | 285 | /**  | 
                                                        
@@ -290,7 +290,7 @@ discard block  | 
                                                    ||
| 290 | 290 | * @return int  | 
                                                        
| 291 | 291 | */  | 
                                                        
| 292 | 292 |  	function get_paged() { | 
                                                        
| 293 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;  | 
                                                        |
| 293 | + return isset($_GET['paged']) ? absint($_GET['paged']) : 1;  | 
                                                        |
| 294 | 294 | }  | 
                                                        
| 295 | 295 | |
| 296 | 296 | /**  | 
                                                        
@@ -306,16 +306,16 @@ discard block  | 
                                                    ||
| 306 | 306 | |
| 307 | 307 | $db = new WPInv_Subscriptions_DB;  | 
                                                        
| 308 | 308 | |
| 309 | - $search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : '';  | 
                                                        |
| 309 | + $search = !empty($_GET['s']) ? sanitize_text_field($_GET['s']) : '';  | 
                                                        |
| 310 | 310 | |
| 311 | 311 | $this->total_count = $db->count();  | 
                                                        
| 312 | - $this->active_count = $db->count( array( 'status' => 'active', 'search' => $search ) );  | 
                                                        |
| 313 | - $this->pending_count = $db->count( array( 'status' => 'pending', 'search' => $search ) );  | 
                                                        |
| 314 | - $this->expired_count = $db->count( array( 'status' => 'expired', 'search' => $search ) );  | 
                                                        |
| 315 | - $this->trialling_count = $db->count( array( 'status' => 'trialling', 'search' => $search ) );  | 
                                                        |
| 316 | - $this->cancelled_count = $db->count( array( 'status' => 'cancelled', 'search' => $search ) );  | 
                                                        |
| 317 | - $this->completed_count = $db->count( array( 'status' => 'completed', 'search' => $search ) );  | 
                                                        |
| 318 | - $this->failing_count = $db->count( array( 'status' => 'failing', 'search' => $search ) );  | 
                                                        |
| 312 | +		$this->active_count    = $db->count(array('status' => 'active', 'search' => $search)); | 
                                                        |
| 313 | +		$this->pending_count   = $db->count(array('status' => 'pending', 'search' => $search)); | 
                                                        |
| 314 | +		$this->expired_count   = $db->count(array('status' => 'expired', 'search' => $search)); | 
                                                        |
| 315 | +		$this->trialling_count = $db->count(array('status' => 'trialling', 'search' => $search)); | 
                                                        |
| 316 | +		$this->cancelled_count = $db->count(array('status' => 'cancelled', 'search' => $search)); | 
                                                        |
| 317 | +		$this->completed_count = $db->count(array('status' => 'completed', 'search' => $search)); | 
                                                        |
| 318 | +		$this->failing_count   = $db->count(array('status' => 'failing', 'search' => $search)); | 
                                                        |
| 319 | 319 | |
| 320 | 320 | }  | 
                                                        
| 321 | 321 | |
@@ -336,28 +336,28 @@ discard block  | 
                                                    ||
| 336 | 336 | |
| 337 | 337 | $columns = $this->get_columns();  | 
                                                        
| 338 | 338 | $hidden = array(); // No hidden columns  | 
                                                        
| 339 | - $status = isset( $_GET['status'] ) ? $_GET['status'] : 'any';  | 
                                                        |
| 339 | + $status = isset($_GET['status']) ? $_GET['status'] : 'any';  | 
                                                        |
| 340 | 340 | $sortable = $this->get_sortable_columns();  | 
                                                        
| 341 | 341 | |
| 342 | - $this->_column_headers = array( $columns, $hidden, $sortable );  | 
                                                        |
| 342 | + $this->_column_headers = array($columns, $hidden, $sortable);  | 
                                                        |
| 343 | 343 | |
| 344 | 344 | $current_page = $this->get_pagenum();  | 
                                                        
| 345 | 345 | |
| 346 | 346 | $db = new WPInv_Subscriptions_DB;  | 
                                                        
| 347 | - $search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : '';  | 
                                                        |
| 347 | + $search = !empty($_GET['s']) ? sanitize_text_field($_GET['s']) : '';  | 
                                                        |
| 348 | 348 | $args = array(  | 
                                                        
| 349 | 349 | 'number' => $this->per_page,  | 
                                                        
| 350 | - 'offset' => $this->per_page * ( $this->get_paged() - 1 ),  | 
                                                        |
| 350 | + 'offset' => $this->per_page * ($this->get_paged() - 1),  | 
                                                        |
| 351 | 351 | 'search' => $search  | 
                                                        
| 352 | 352 | );  | 
                                                        
| 353 | 353 | |
| 354 | -		if ( 'any' !== $status ) { | 
                                                        |
| 354 | +		if ('any' !== $status) { | 
                                                        |
| 355 | 355 | $args['status'] = $status;  | 
                                                        
| 356 | 356 | }  | 
                                                        
| 357 | 357 | |
| 358 | - $this->items = $db->get_subscriptions( $args );  | 
                                                        |
| 358 | + $this->items = $db->get_subscriptions($args);  | 
                                                        |
| 359 | 359 | |
| 360 | -		switch ( $status ) { | 
                                                        |
| 360 | +		switch ($status) { | 
                                                        |
| 361 | 361 | case 'active':  | 
                                                        
| 362 | 362 | $total_items = $this->active_count;  | 
                                                        
| 363 | 363 | break;  | 
                                                        
@@ -385,10 +385,10 @@ discard block  | 
                                                    ||
| 385 | 385 | break;  | 
                                                        
| 386 | 386 | }  | 
                                                        
| 387 | 387 | |
| 388 | - $this->set_pagination_args( array(  | 
                                                        |
| 388 | + $this->set_pagination_args(array(  | 
                                                        |
| 389 | 389 | 'total_items' => $total_items,  | 
                                                        
| 390 | 390 | 'per_page' => $this->per_page,  | 
                                                        
| 391 | - 'total_pages' => ceil( $total_items / $this->per_page )  | 
                                                        |
| 392 | - ) );  | 
                                                        |
| 391 | + 'total_pages' => ceil($total_items / $this->per_page)  | 
                                                        |
| 392 | + ));  | 
                                                        |
| 393 | 393 | }  | 
                                                        
| 394 | 394 | }  | 
                                                        
@@ -1,6 +1,8 @@  | 
                                                    ||
| 1 | 1 | <?php  | 
                                                        
| 2 | 2 | // Exit if accessed directly.  | 
                                                        
| 3 | -if (!defined( 'ABSPATH' ) ) exit;  | 
                                                        |
| 3 | +if (!defined( 'ABSPATH' ) ) { | 
                                                        |
| 4 | + exit;  | 
                                                        |
| 5 | +}  | 
                                                        |
| 4 | 6 | |
| 5 | 7 |  function wpinv_subscription_init() { | 
                                                        
| 6 | 8 | return WPInv_Subscriptions::instance();  | 
                                                        
@@ -1,11 +1,11 @@ discard block  | 
                                                    ||
| 1 | 1 | <?php  | 
                                                        
| 2 | 2 | // Exit if accessed directly.  | 
                                                        
| 3 | -if (!defined( 'ABSPATH' ) ) exit;  | 
                                                        |
| 3 | +if (!defined('ABSPATH')) exit; | 
                                                        |
| 4 | 4 | |
| 5 | 5 |  function wpinv_subscription_init() { | 
                                                        
| 6 | 6 | return WPInv_Subscriptions::instance();  | 
                                                        
| 7 | 7 | }  | 
                                                        
| 8 | -add_action( 'plugins_loaded', 'wpinv_subscription_init', 100 );  | 
                                                        |
| 8 | +add_action('plugins_loaded', 'wpinv_subscription_init', 100); | 
                                                        |
| 9 | 9 | |
| 10 | 10 | /**  | 
                                                        
| 11 | 11 | * WPInv_Subscriptions Class.  | 
                                                        
@@ -20,7 +20,7 @@ discard block  | 
                                                    ||
| 20 | 20 | * Main WPInv_Subscriptions Instance  | 
                                                        
| 21 | 21 | */  | 
                                                        
| 22 | 22 |      public static function instance() { | 
                                                        
| 23 | -        if ( ! isset( self::$instance ) ) { | 
                                                        |
| 23 | +        if (!isset(self::$instance)) { | 
                                                        |
| 24 | 24 | self::$instance = new WPInv_Subscriptions;  | 
                                                        
| 25 | 25 | |
| 26 | 26 | self::$instance->init();  | 
                                                        
@@ -34,7 +34,7 @@ discard block  | 
                                                    ||
| 34 | 34 | *  | 
                                                        
| 35 | 35 | * @since 1.0.0  | 
                                                        
| 36 | 36 | */  | 
                                                        
| 37 | -    private function __construct(){ | 
                                                        |
| 37 | +    private function __construct() { | 
                                                        |
| 38 | 38 | |
| 39 | 39 | }  | 
                                                        
| 40 | 40 | |
@@ -63,8 +63,8 @@ discard block  | 
                                                    ||
| 63 | 63 |      private function setup_constants() { | 
                                                        
| 64 | 64 | |
| 65 | 65 | // Make sure CAL_GREGORIAN is defined.  | 
                                                        
| 66 | -        if ( ! defined( 'CAL_GREGORIAN' ) ) { | 
                                                        |
| 67 | - define( 'CAL_GREGORIAN', 1 );  | 
                                                        |
| 66 | +        if (!defined('CAL_GREGORIAN')) { | 
                                                        |
| 67 | +            define('CAL_GREGORIAN', 1); | 
                                                        |
| 68 | 68 | }  | 
                                                        
| 69 | 69 | }  | 
                                                        
| 70 | 70 | |
@@ -76,13 +76,13 @@ discard block  | 
                                                    ||
| 76 | 76 | */  | 
                                                        
| 77 | 77 |      private function actions() { | 
                                                        
| 78 | 78 | |
| 79 | - add_action( 'admin_menu', array( $this, 'wpinv_subscriptions_list' ), 10 );  | 
                                                        |
| 80 | - add_action( 'admin_notices', array( $this, 'notices' ) );  | 
                                                        |
| 81 | - add_action( 'init', array( $this, 'wpinv_post_actions' ) );  | 
                                                        |
| 82 | - add_action( 'init', array( $this, 'wpinv_get_actions' ) );  | 
                                                        |
| 83 | - add_action( 'wpinv_cancel_subscription', array( $this, 'wpinv_process_cancellation' ) );  | 
                                                        |
| 84 | - add_action( 'wpi-pending_wpi_invoice', array( $this, 'wpinv_add_update_subscription' ), 10, 2 );  | 
                                                        |
| 85 | - add_action( 'wpinv_subscriptions_front_notices', array( $this, 'notices' ) );  | 
                                                        |
| 79 | +        add_action('admin_menu', array($this, 'wpinv_subscriptions_list'), 10); | 
                                                        |
| 80 | +        add_action('admin_notices', array($this, 'notices')); | 
                                                        |
| 81 | +        add_action('init', array($this, 'wpinv_post_actions')); | 
                                                        |
| 82 | +        add_action('init', array($this, 'wpinv_get_actions')); | 
                                                        |
| 83 | +        add_action('wpinv_cancel_subscription', array($this, 'wpinv_process_cancellation')); | 
                                                        |
| 84 | +        add_action('wpi-pending_wpi_invoice', array($this, 'wpinv_add_update_subscription'), 10, 2); | 
                                                        |
| 85 | +        add_action('wpinv_subscriptions_front_notices', array($this, 'notices')); | 
                                                        |
| 86 | 86 | }  | 
                                                        
| 87 | 87 | |
| 88 | 88 | /**  | 
                                                        
@@ -104,8 +104,8 @@ discard block  | 
                                                    ||
| 104 | 104 |      public function wpinv_subscriptions_list() { | 
                                                        
| 105 | 105 | add_submenu_page(  | 
                                                        
| 106 | 106 | 'wpinv',  | 
                                                        
| 107 | - __( 'Subscriptions', 'invoicing' ),  | 
                                                        |
| 108 | - __( 'Subscriptions', 'invoicing' ),  | 
                                                        |
| 107 | +            __('Subscriptions', 'invoicing'), | 
                                                        |
| 108 | +            __('Subscriptions', 'invoicing'), | 
                                                        |
| 109 | 109 | 'manage_invoicing',  | 
                                                        
| 110 | 110 | 'wpinv-subscriptions',  | 
                                                        
| 111 | 111 | 'wpinv_subscriptions_page'  | 
                                                        
@@ -114,37 +114,37 @@ discard block  | 
                                                    ||
| 114 | 114 | |
| 115 | 115 |      public function notices() { | 
                                                        
| 116 | 116 | |
| 117 | -        if( empty( $_GET['wpinv-message'] ) ) { | 
                                                        |
| 117 | +        if (empty($_GET['wpinv-message'])) { | 
                                                        |
| 118 | 118 | return;  | 
                                                        
| 119 | 119 | }  | 
                                                        
| 120 | 120 | |
| 121 | 121 | $type = 'updated';  | 
                                                        
| 122 | 122 | $message = '';  | 
                                                        
| 123 | 123 | |
| 124 | -        switch( strtolower( $_GET['wpinv-message'] ) ) { | 
                                                        |
| 124 | +        switch (strtolower($_GET['wpinv-message'])) { | 
                                                        |
| 125 | 125 | |
| 126 | 126 | case 'updated' :  | 
                                                        
| 127 | 127 | |
| 128 | - $message = __( 'Subscription updated successfully.', 'invoicing' );  | 
                                                        |
| 128 | +                $message = __('Subscription updated successfully.', 'invoicing'); | 
                                                        |
| 129 | 129 | |
| 130 | 130 | break;  | 
                                                        
| 131 | 131 | |
| 132 | 132 | case 'deleted' :  | 
                                                        
| 133 | 133 | |
| 134 | - $message = __( 'Subscription deleted successfully.', 'invoicing' );  | 
                                                        |
| 134 | +                $message = __('Subscription deleted successfully.', 'invoicing'); | 
                                                        |
| 135 | 135 | |
| 136 | 136 | break;  | 
                                                        
| 137 | 137 | |
| 138 | 138 | case 'cancelled' :  | 
                                                        
| 139 | 139 | |
| 140 | - $message = __( 'Subscription cancelled successfully.', 'invoicing' );  | 
                                                        |
| 140 | +                $message = __('Subscription cancelled successfully.', 'invoicing'); | 
                                                        |
| 141 | 141 | |
| 142 | 142 | break;  | 
                                                        
| 143 | 143 | |
| 144 | 144 | }  | 
                                                        
| 145 | 145 | |
| 146 | -        if ( ! empty( $message ) ) { | 
                                                        |
| 147 | - echo '<div class="' . esc_attr( $type ) . '"><p>' . $message . '</p></div>';  | 
                                                        |
| 146 | +        if (!empty($message)) { | 
                                                        |
| 147 | + echo '<div class="' . esc_attr($type) . '"><p>' . $message . '</p></div>';  | 
                                                        |
| 148 | 148 | }  | 
                                                        
| 149 | 149 | |
| 150 | 150 | }  | 
                                                        
@@ -157,8 +157,8 @@ discard block  | 
                                                    ||
| 157 | 157 | * @return void  | 
                                                        
| 158 | 158 | */  | 
                                                        
| 159 | 159 |      function wpinv_get_actions() { | 
                                                        
| 160 | -        if ( isset( $_GET['wpinv_action'] ) ) { | 
                                                        |
| 161 | - do_action( 'wpinv_' . $_GET['wpinv_action'], $_GET );  | 
                                                        |
| 160 | +        if (isset($_GET['wpinv_action'])) { | 
                                                        |
| 161 | +            do_action('wpinv_' . $_GET['wpinv_action'], $_GET); | 
                                                        |
| 162 | 162 | }  | 
                                                        
| 163 | 163 | }  | 
                                                        
| 164 | 164 | |
@@ -170,8 +170,8 @@ discard block  | 
                                                    ||
| 170 | 170 | * @return void  | 
                                                        
| 171 | 171 | */  | 
                                                        
| 172 | 172 |      function wpinv_post_actions() { | 
                                                        
| 173 | -        if ( isset( $_POST['wpinv_action'] ) ) { | 
                                                        |
| 174 | - do_action( 'wpinv_' . $_POST['wpinv_action'], $_POST );  | 
                                                        |
| 173 | +        if (isset($_POST['wpinv_action'])) { | 
                                                        |
| 174 | +            do_action('wpinv_' . $_POST['wpinv_action'], $_POST); | 
                                                        |
| 175 | 175 | }  | 
                                                        
| 176 | 176 | }  | 
                                                        
| 177 | 177 | |
@@ -182,24 +182,24 @@ discard block  | 
                                                    ||
| 182 | 182 | * @param int $frequency_count The frequency of the period.  | 
                                                        
| 183 | 183 | * @return mixed|string|void  | 
                                                        
| 184 | 184 | */  | 
                                                        
| 185 | -    public static function wpinv_get_pretty_subscription_frequency( $period, $frequency_count = 1) { | 
                                                        |
| 185 | +    public static function wpinv_get_pretty_subscription_frequency($period, $frequency_count = 1) { | 
                                                        |
| 186 | 186 | $frequency = '';  | 
                                                        
| 187 | 187 | //Format period details  | 
                                                        
| 188 | -        switch ( $period ) { | 
                                                        |
| 188 | +        switch ($period) { | 
                                                        |
| 189 | 189 | case 'day' :  | 
                                                        
| 190 | -                $frequency = sprintf( _n('%d Day', '%d Days', $frequency_count, 'invoicing'), $frequency_count); | 
                                                        |
| 190 | +                $frequency = sprintf(_n('%d Day', '%d Days', $frequency_count, 'invoicing'), $frequency_count); | 
                                                        |
| 191 | 191 | break;  | 
                                                        
| 192 | 192 | case 'week' :  | 
                                                        
| 193 | -                $frequency = sprintf( _n('%d Week', '%d Weeks', $frequency_count, 'invoicing'), $frequency_count); | 
                                                        |
| 193 | +                $frequency = sprintf(_n('%d Week', '%d Weeks', $frequency_count, 'invoicing'), $frequency_count); | 
                                                        |
| 194 | 194 | break;  | 
                                                        
| 195 | 195 | case 'month' :  | 
                                                        
| 196 | -                $frequency = sprintf( _n('%d Month', '%d Months', $frequency_count, 'invoicing'), $frequency_count); | 
                                                        |
| 196 | +                $frequency = sprintf(_n('%d Month', '%d Months', $frequency_count, 'invoicing'), $frequency_count); | 
                                                        |
| 197 | 197 | break;  | 
                                                        
| 198 | 198 | case 'year' :  | 
                                                        
| 199 | -                $frequency = sprintf( _n('%d Year', '%d Years', $frequency_count, 'invoicing'), $frequency_count); | 
                                                        |
| 199 | +                $frequency = sprintf(_n('%d Year', '%d Years', $frequency_count, 'invoicing'), $frequency_count); | 
                                                        |
| 200 | 200 | break;  | 
                                                        
| 201 | 201 | default :  | 
                                                        
| 202 | - $frequency = apply_filters( 'wpinv_recurring_subscription_frequency', $frequency, $period, $frequency_count );  | 
                                                        |
| 202 | +                $frequency = apply_filters('wpinv_recurring_subscription_frequency', $frequency, $period, $frequency_count); | 
                                                        |
| 203 | 203 | break;  | 
                                                        
| 204 | 204 | }  | 
                                                        
| 205 | 205 | |
@@ -214,50 +214,50 @@ discard block  | 
                                                    ||
| 214 | 214 | * @since 1.0.0  | 
                                                        
| 215 | 215 | * @return void  | 
                                                        
| 216 | 216 | */  | 
                                                        
| 217 | -    public function wpinv_process_cancellation( $data ) { | 
                                                        |
| 217 | +    public function wpinv_process_cancellation($data) { | 
                                                        |
| 218 | 218 | |
| 219 | 219 | |
| 220 | -        if( empty( $data['sub_id'] ) ) { | 
                                                        |
| 220 | +        if (empty($data['sub_id'])) { | 
                                                        |
| 221 | 221 | return;  | 
                                                        
| 222 | 222 | }  | 
                                                        
| 223 | 223 | |
| 224 | -        if( ! is_user_logged_in() ) { | 
                                                        |
| 224 | +        if (!is_user_logged_in()) { | 
                                                        |
| 225 | 225 | return;  | 
                                                        
| 226 | 226 | }  | 
                                                        
| 227 | 227 | |
| 228 | -        if( ! wp_verify_nonce( $data['_wpnonce'], 'wpinv-recurring-cancel' ) ) { | 
                                                        |
| 229 | - wp_die( __( 'Error', 'invoicing' ), __( 'Nonce verification failed', 'invoicing' ), array( 'response' => 403 ) );  | 
                                                        |
| 228 | +        if (!wp_verify_nonce($data['_wpnonce'], 'wpinv-recurring-cancel')) { | 
                                                        |
| 229 | +            wp_die(__('Error', 'invoicing'), __('Nonce verification failed', 'invoicing'), array('response' => 403)); | 
                                                        |
| 230 | 230 | }  | 
                                                        
| 231 | 231 | |
| 232 | - $data['sub_id'] = absint( $data['sub_id'] );  | 
                                                        |
| 233 | - $subscription = new WPInv_Subscription( $data['sub_id'] );  | 
                                                        |
| 232 | + $data['sub_id'] = absint($data['sub_id']);  | 
                                                        |
| 233 | + $subscription = new WPInv_Subscription($data['sub_id']);  | 
                                                        |
| 234 | 234 | |
| 235 | -        if( ! $subscription->can_cancel() ) { | 
                                                        |
| 236 | - wp_die( __( 'Error', 'invoicing' ), __( 'This subscription cannot be cancelled', 'invoicing' ), array( 'response' => 403 ) );  | 
                                                        |
| 235 | +        if (!$subscription->can_cancel()) { | 
                                                        |
| 236 | +            wp_die(__('Error', 'invoicing'), __('This subscription cannot be cancelled', 'invoicing'), array('response' => 403)); | 
                                                        |
| 237 | 237 | }  | 
                                                        
| 238 | 238 | |
| 239 | 239 |          try { | 
                                                        
| 240 | 240 | |
| 241 | - do_action( 'wpinv_recurring_cancel_' . $subscription->gateway . '_subscription', $subscription, true );  | 
                                                        |
| 241 | +            do_action('wpinv_recurring_cancel_' . $subscription->gateway . '_subscription', $subscription, true); | 
                                                        |
| 242 | 242 | |
| 243 | 243 | $subscription->cancel();  | 
                                                        
| 244 | 244 | |
| 245 | -            if( is_admin() ) { | 
                                                        |
| 245 | +            if (is_admin()) { | 
                                                        |
| 246 | 246 | |
| 247 | - wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=cancelled&id=' . $subscription->id ) );  | 
                                                        |
| 247 | +                wp_redirect(admin_url('admin.php?page=wpinv-subscriptions&wpinv-message=cancelled&id=' . $subscription->id)); | 
                                                        |
| 248 | 248 | exit;  | 
                                                        
| 249 | 249 | |
| 250 | 250 |              } else { | 
                                                        
| 251 | 251 | |
| 252 | - $redirect = remove_query_arg( array( '_wpnonce', 'wpinv_action', 'sub_id' ), add_query_arg( array( 'wpinv-message' => 'cancelled' ) ) );  | 
                                                        |
| 253 | - $redirect = apply_filters( 'wpinv_recurring_cancellation_redirect', $redirect, $subscription );  | 
                                                        |
| 254 | - wp_safe_redirect( $redirect );  | 
                                                        |
| 252 | +                $redirect = remove_query_arg(array('_wpnonce', 'wpinv_action', 'sub_id'), add_query_arg(array('wpinv-message' => 'cancelled'))); | 
                                                        |
| 253 | +                $redirect = apply_filters('wpinv_recurring_cancellation_redirect', $redirect, $subscription); | 
                                                        |
| 254 | + wp_safe_redirect($redirect);  | 
                                                        |
| 255 | 255 | exit;  | 
                                                        
| 256 | 256 | |
| 257 | 257 | }  | 
                                                        
| 258 | 258 | |
| 259 | -        } catch ( Exception $e ) { | 
                                                        |
| 260 | - wp_die( __( 'Error', 'invoicing' ), $e->getMessage(), array( 'response' => 403 ) );  | 
                                                        |
| 259 | +        } catch (Exception $e) { | 
                                                        |
| 260 | +            wp_die(__('Error', 'invoicing'), $e->getMessage(), array('response' => 403)); | 
                                                        |
| 261 | 261 | }  | 
                                                        
| 262 | 262 | |
| 263 | 263 | }  | 
                                                        
@@ -269,51 +269,51 @@ discard block  | 
                                                    ||
| 269 | 269 | * @since 1.0.0  | 
                                                        
| 270 | 270 | * @return void  | 
                                                        
| 271 | 271 | */  | 
                                                        
| 272 | -    public function wpinv_add_update_subscription( $invoice_id, $post ) { | 
                                                        |
| 273 | - remove_action( 'save_post', __FUNCTION__ );  | 
                                                        |
| 272 | +    public function wpinv_add_update_subscription($invoice_id, $post) { | 
                                                        |
| 273 | +        remove_action('save_post', __FUNCTION__); | 
                                                        |
| 274 | 274 | |
| 275 | -        if ( ! ( ! empty( $invoice_id ) && 'wpi_invoice' == get_post_type( $invoice_id ) ) ) { | 
                                                        |
| 275 | +        if (!(!empty($invoice_id) && 'wpi_invoice' == get_post_type($invoice_id))) { | 
                                                        |
| 276 | 276 | return;  | 
                                                        
| 277 | 277 | }  | 
                                                        
| 278 | 278 | |
| 279 | -        if ( defined( 'DOING_AUTOSAVE' ) ) { | 
                                                        |
| 279 | +        if (defined('DOING_AUTOSAVE')) { | 
                                                        |
| 280 | 280 | return;  | 
                                                        
| 281 | 281 | }  | 
                                                        
| 282 | 282 | |
| 283 | -        if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { | 
                                                        |
| 283 | +        if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) { | 
                                                        |
| 284 | 284 | return;  | 
                                                        
| 285 | 285 | }  | 
                                                        
| 286 | 286 | |
| 287 | - $invoice = new WPInv_Invoice( $invoice_id );  | 
                                                        |
| 287 | + $invoice = new WPInv_Invoice($invoice_id);  | 
                                                        |
| 288 | 288 | |
| 289 | -        if ( ! ( ! empty( $invoice->ID ) && $invoice->is_recurring() ) ) { | 
                                                        |
| 289 | +        if (!(!empty($invoice->ID) && $invoice->is_recurring())) { | 
                                                        |
| 290 | 290 | return;  | 
                                                        
| 291 | 291 | }  | 
                                                        
| 292 | 292 | |
| 293 | - $item = $invoice->get_recurring( true );  | 
                                                        |
| 294 | -        if ( empty( $item ) ) { | 
                                                        |
| 293 | + $item = $invoice->get_recurring(true);  | 
                                                        |
| 294 | +        if (empty($item)) { | 
                                                        |
| 295 | 295 | return;  | 
                                                        
| 296 | 296 | }  | 
                                                        
| 297 | 297 | |
| 298 | - $invoice_date = $invoice->get_invoice_date( false );  | 
                                                        |
| 298 | + $invoice_date = $invoice->get_invoice_date(false);  | 
                                                        |
| 299 | 299 | $status = 'pending';  | 
                                                        
| 300 | 300 | |
| 301 | - $period = $item->get_recurring_period( true );  | 
                                                        |
| 301 | + $period = $item->get_recurring_period(true);  | 
                                                        |
| 302 | 302 | $interval = $item->get_recurring_interval();  | 
                                                        
| 303 | 303 | $bill_times = (int)$item->get_recurring_limit();  | 
                                                        
| 304 | 304 | $add_period = $interval . ' ' . $period;  | 
                                                        
| 305 | 305 | $trial_period = '';  | 
                                                        
| 306 | 306 | |
| 307 | -        if ( $invoice->is_free_trial() ) { | 
                                                        |
| 307 | +        if ($invoice->is_free_trial()) { | 
                                                        |
| 308 | 308 | $status = 'trialling';  | 
                                                        
| 309 | - $trial_period = $item->get_trial_period( true );  | 
                                                        |
| 309 | + $trial_period = $item->get_trial_period(true);  | 
                                                        |
| 310 | 310 | $free_interval = $item->get_trial_interval();  | 
                                                        
| 311 | 311 | $trial_period = $free_interval . ' ' . $trial_period;  | 
                                                        
| 312 | 312 | |
| 313 | 313 | $add_period = $trial_period;  | 
                                                        
| 314 | 314 | }  | 
                                                        
| 315 | 315 | |
| 316 | - $expiration = date_i18n( 'Y-m-d H:i:s', strtotime( '+' . $add_period . ' 23:59:59', strtotime( $invoice_date ) ) );  | 
                                                        |
| 316 | +        $expiration         = date_i18n('Y-m-d H:i:s', strtotime('+' . $add_period . ' 23:59:59', strtotime($invoice_date))); | 
                                                        |
| 317 | 317 | |
| 318 | 318 | $args = array(  | 
                                                        
| 319 | 319 | 'product_id' => $item->ID,  | 
                                                        
@@ -323,7 +323,7 @@ discard block  | 
                                                    ||
| 323 | 323 | 'frequency' => $interval,  | 
                                                        
| 324 | 324 | 'period' => $period,  | 
                                                        
| 325 | 325 | 'initial_amount' => $invoice->get_total(),  | 
                                                        
| 326 | - 'recurring_amount' => $invoice->get_recurring_details( 'total' ),  | 
                                                        |
| 326 | +            'recurring_amount'  => $invoice->get_recurring_details('total'), | 
                                                        |
| 327 | 327 | 'bill_times' => $bill_times,  | 
                                                        
| 328 | 328 | 'created' => $invoice_date,  | 
                                                        
| 329 | 329 | 'expiration' => $expiration,  | 
                                                        
@@ -333,12 +333,12 @@ discard block  | 
                                                    ||
| 333 | 333 | );  | 
                                                        
| 334 | 334 | |
| 335 | 335 | $subs_db = new WPInv_Subscriptions_DB;  | 
                                                        
| 336 | - $subs = $subs_db->get_subscriptions( array( 'parent_payment_id' => $invoice->ID, 'number' => 1 ) );  | 
                                                        |
| 337 | - $subscription = reset( $subs );  | 
                                                        |
| 336 | +        $subs         = $subs_db->get_subscriptions(array('parent_payment_id' => $invoice->ID, 'number' => 1)); | 
                                                        |
| 337 | + $subscription = reset($subs);  | 
                                                        |
| 338 | 338 | |
| 339 | -        if ( empty( $subscription ) || $subscription->id <= 0 ) { | 
                                                        |
| 339 | +        if (empty($subscription) || $subscription->id <= 0) { | 
                                                        |
| 340 | 340 | $subscription = new WPInv_Subscription();  | 
                                                        
| 341 | - $subscription->create( $args );  | 
                                                        |
| 341 | + $subscription->create($args);  | 
                                                        |
| 342 | 342 | }  | 
                                                        
| 343 | 343 | }  | 
                                                        
| 344 | 344 | }  | 
                                                        
| 345 | 345 | \ No newline at end of file  | 
                                                        
@@ -9,58 +9,58 @@  | 
                                                    ||
| 9 | 9 | */  | 
                                                        
| 10 | 10 | |
| 11 | 11 | // If uninstall not called from WordPress, then exit.  | 
                                                        
| 12 | -if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { | 
                                                        |
| 12 | +if (!defined('WP_UNINSTALL_PLUGIN')) { | 
                                                        |
| 13 | 13 | exit;  | 
                                                        
| 14 | 14 | }  | 
                                                        
| 15 | 15 | |
| 16 | 16 | global $wpdb, $wp_version;  | 
                                                        
| 17 | 17 | |
| 18 | -$remove_data = get_option( 'wpinv_remove_data_on_invoice_unistall' );  | 
                                                        |
| 18 | +$remove_data = get_option('wpinv_remove_data_on_invoice_unistall'); | 
                                                        |
| 19 | 19 | |
| 20 | 20 | /*  | 
                                                        
| 21 | 21 | * Only remove ALL product and page data if WPINV_REMOVE_ALL_DATA constant is set to true in user's  | 
                                                        
| 22 | 22 | * wp-config.php. This is to prevent data loss when deleting the plugin from the backend  | 
                                                        
| 23 | 23 | * and to ensure only the site owner can perform this action.  | 
                                                        
| 24 | 24 | */  | 
                                                        
| 25 | -if ( defined( 'WPINV_REMOVE_ALL_DATA' ) ) { | 
                                                        |
| 25 | +if (defined('WPINV_REMOVE_ALL_DATA')) { | 
                                                        |
| 26 | 26 | $remove_data = true === WPINV_REMOVE_ALL_DATA ? true : false;  | 
                                                        
| 27 | 27 | }  | 
                                                        
| 28 | 28 | |
| 29 | -if ( $remove_data ) { | 
                                                        |
| 29 | +if ($remove_data) { | 
                                                        |
| 30 | 30 | // Load Invoicing file.  | 
                                                        
| 31 | - include_once( 'invoicing.php' );  | 
                                                        |
| 31 | +    include_once('invoicing.php'); | 
                                                        |
| 32 | 32 | |
| 33 | 33 | // Roles + caps.  | 
                                                        
| 34 | - include_once( dirname( __FILE__ ) . '/includes/admin/install.php' );  | 
                                                        |
| 34 | + include_once(dirname(__FILE__) . '/includes/admin/install.php');  | 
                                                        |
| 35 | 35 | wpinv_remove_admin_caps();  | 
                                                        
| 36 | 36 | |
| 37 | - $settings = get_option( 'wpinv_settings' );  | 
                                                        |
| 37 | +    $settings = get_option('wpinv_settings'); | 
                                                        |
| 38 | 38 | |
| 39 | 39 | // Delete pages.  | 
                                                        
| 40 | - $wpi_pages = array( 'checkout_page', 'success_page', 'failure_page', 'invoice_history_page', 'quote_history_page', 'invoice_subscription_page' );  | 
                                                        |
| 41 | -    foreach ( $wpi_pages as $page ) { | 
                                                        |
| 42 | -        if ( !empty( $page ) && !empty( $settings[ $page ] ) ) { | 
                                                        |
| 43 | - wp_delete_post( $settings[ $page ], true );  | 
                                                        |
| 40 | +    $wpi_pages = array('checkout_page', 'success_page', 'failure_page', 'invoice_history_page', 'quote_history_page', 'invoice_subscription_page'); | 
                                                        |
| 41 | +    foreach ($wpi_pages as $page) { | 
                                                        |
| 42 | +        if (!empty($page) && !empty($settings[$page])) { | 
                                                        |
| 43 | + wp_delete_post($settings[$page], true);  | 
                                                        |
| 44 | 44 | }  | 
                                                        
| 45 | 45 | }  | 
                                                        
| 46 | 46 | |
| 47 | 47 | // Delete posts + data.  | 
                                                        
| 48 | -    $wpdb->query( "DELETE FROM {$wpdb->posts} WHERE post_type IN ( 'wpi_invoice', 'wpi_item', 'wpi_discount', 'wpi_quote' );" ); | 
                                                        |
| 49 | -    $wpdb->query( "DELETE meta FROM {$wpdb->postmeta} meta LEFT JOIN {$wpdb->posts} posts ON posts.ID = meta.post_id WHERE posts.ID IS NULL;" ); | 
                                                        |
| 48 | +    $wpdb->query("DELETE FROM {$wpdb->posts} WHERE post_type IN ( 'wpi_invoice', 'wpi_item', 'wpi_discount', 'wpi_quote' );"); | 
                                                        |
| 49 | +    $wpdb->query("DELETE meta FROM {$wpdb->postmeta} meta LEFT JOIN {$wpdb->posts} posts ON posts.ID = meta.post_id WHERE posts.ID IS NULL;"); | 
                                                        |
| 50 | 50 | |
| 51 | 51 | // Delete comments.  | 
                                                        
| 52 | -    $wpdb->query( "DELETE FROM {$wpdb->comments} WHERE comment_type LIKE 'wpinv_note';" ); | 
                                                        |
| 53 | -    $wpdb->query( "DELETE meta FROM {$wpdb->commentmeta} meta LEFT JOIN {$wpdb->comments} comments ON comments.comment_ID = meta.comment_id WHERE comments.comment_ID IS NULL;" ); | 
                                                        |
| 52 | +    $wpdb->query("DELETE FROM {$wpdb->comments} WHERE comment_type LIKE 'wpinv_note';"); | 
                                                        |
| 53 | +    $wpdb->query("DELETE meta FROM {$wpdb->commentmeta} meta LEFT JOIN {$wpdb->comments} comments ON comments.comment_ID = meta.comment_id WHERE comments.comment_ID IS NULL;"); | 
                                                        |
| 54 | 54 | |
| 55 | 55 | // Delete user meta.  | 
                                                        
| 56 | -    $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE '%_wpinv_%' OR meta_key LIKE '%_wpi_invoice%' OR meta_key LIKE '%_wpi_item%' OR meta_key LIKE '%_wpi_discount%' OR meta_key LIKE '_wpi_stripe%' OR meta_key LIKE '%_wpi_quote%';" ); | 
                                                        |
| 56 | +    $wpdb->query("DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE '%_wpinv_%' OR meta_key LIKE '%_wpi_invoice%' OR meta_key LIKE '%_wpi_item%' OR meta_key LIKE '%_wpi_discount%' OR meta_key LIKE '_wpi_stripe%' OR meta_key LIKE '%_wpi_quote%';"); | 
                                                        |
| 57 | 57 | |
| 58 | 58 | // Cleanup Cron Schedule  | 
                                                        
| 59 | - wp_clear_scheduled_hook( 'wp_session_garbage_collection' );  | 
                                                        |
| 60 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' );  | 
                                                        |
| 59 | +    wp_clear_scheduled_hook('wp_session_garbage_collection'); | 
                                                        |
| 60 | +    wp_clear_scheduled_hook('wpinv_register_schedule_event_twicedaily'); | 
                                                        |
| 61 | 61 | |
| 62 | 62 | // Delete options.  | 
                                                        
| 63 | -    $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'wpinv_%' OR option_name LIKE '_wpinv_%' OR option_name LIKE '\_transient\_wpinv\_%';" ); | 
                                                        |
| 63 | +    $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE 'wpinv_%' OR option_name LIKE '_wpinv_%' OR option_name LIKE '\_transient\_wpinv\_%';"); | 
                                                        |
| 64 | 64 | |
| 65 | 65 | // Clear any cached data that has been removed  | 
                                                        
| 66 | 66 | wp_cache_flush();  | 
                                                        
@@ -30,36 +30,36 @@ discard block  | 
                                                    ||
| 30 | 30 | }  | 
                                                        
| 31 | 31 | |
| 32 | 32 |  function wpinv_can_checkout() { | 
                                                        
| 33 | - $can_checkout = true; // Always true for now  | 
                                                        |
| 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 | 65 |  function wpinv_is_subscriptions_history_page() { | 
                                                        
@@ -69,7 +69,7 @@ discard block  | 
                                                    ||
| 69 | 69 | }  | 
                                                        
| 70 | 70 | |
| 71 | 71 |  function wpinv_send_to_success_page( $args = null ) { | 
                                                        
| 72 | - $redirect = wpinv_get_success_page_uri();  | 
                                                        |
| 72 | + $redirect = wpinv_get_success_page_uri();  | 
                                                        |
| 73 | 73 | |
| 74 | 74 |      if ( !empty( $args ) ) { | 
                                                        
| 75 | 75 | // Check for backward compatibility  | 
                                                        
@@ -89,7 +89,7 @@ discard block  | 
                                                    ||
| 89 | 89 | }  | 
                                                        
| 90 | 90 | |
| 91 | 91 |  function wpinv_send_to_failed_page( $args = null ) { | 
                                                        
| 92 | - $redirect = wpinv_get_failed_transaction_uri();  | 
                                                        |
| 92 | + $redirect = wpinv_get_failed_transaction_uri();  | 
                                                        |
| 93 | 93 | |
| 94 | 94 |      if ( !empty( $args ) ) { | 
                                                        
| 95 | 95 | // Check for backward compatibility  | 
                                                        
@@ -109,72 +109,72 @@ discard block  | 
                                                    ||
| 109 | 109 | }  | 
                                                        
| 110 | 110 | |
| 111 | 111 |  function wpinv_get_checkout_uri( $args = array() ) { | 
                                                        
| 112 | - $uri = wpinv_get_option( 'checkout_page', false );  | 
                                                        |
| 113 | - $uri = isset( $uri ) ? get_permalink( $uri ) : NULL;  | 
                                                        |
| 112 | + $uri = wpinv_get_option( 'checkout_page', false );  | 
                                                        |
| 113 | + $uri = isset( $uri ) ? get_permalink( $uri ) : NULL;  | 
                                                        |
| 114 | 114 | |
| 115 | -	if ( !empty( $args ) ) { | 
                                                        |
| 116 | - // Check for backward compatibility  | 
                                                        |
| 117 | - if ( is_string( $args ) )  | 
                                                        |
| 118 | - $args = str_replace( '?', '', $args );  | 
                                                        |
| 115 | +    if ( !empty( $args ) ) { | 
                                                        |
| 116 | + // Check for backward compatibility  | 
                                                        |
| 117 | + if ( is_string( $args ) )  | 
                                                        |
| 118 | + $args = str_replace( '?', '', $args );  | 
                                                        |
| 119 | 119 | |
| 120 | - $args = wp_parse_args( $args );  | 
                                                        |
| 120 | + $args = wp_parse_args( $args );  | 
                                                        |
| 121 | 121 | |
| 122 | - $uri = add_query_arg( $args, $uri );  | 
                                                        |
| 123 | - }  | 
                                                        |
| 122 | + $uri = add_query_arg( $args, $uri );  | 
                                                        |
| 123 | + }  | 
                                                        |
| 124 | 124 | |
| 125 | - $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin';  | 
                                                        |
| 125 | + $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin';  | 
                                                        |
| 126 | 126 | |
| 127 | - $ajax_url = admin_url( 'admin-ajax.php', $scheme );  | 
                                                        |
| 127 | + $ajax_url = admin_url( 'admin-ajax.php', $scheme );  | 
                                                        |
| 128 | 128 | |
| 129 | -	if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) { | 
                                                        |
| 130 | - $uri = preg_replace( '/^http:/', 'https:', $uri );  | 
                                                        |
| 131 | - }  | 
                                                        |
| 129 | +    if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) { | 
                                                        |
| 130 | + $uri = preg_replace( '/^http:/', 'https:', $uri );  | 
                                                        |
| 131 | + }  | 
                                                        |
| 132 | 132 | |
| 133 | - return apply_filters( 'wpinv_get_checkout_uri', $uri );  | 
                                                        |
| 133 | + return apply_filters( 'wpinv_get_checkout_uri', $uri );  | 
                                                        |
| 134 | 134 | }  | 
                                                        
| 135 | 135 | |
| 136 | 136 |  function wpinv_send_back_to_checkout( $args = array() ) { | 
                                                        
| 137 | - $redirect = wpinv_get_checkout_uri();  | 
                                                        |
| 137 | + $redirect = wpinv_get_checkout_uri();  | 
                                                        |
| 138 | 138 | |
| 139 | -	if ( ! empty( $args ) ) { | 
                                                        |
| 140 | - // Check for backward compatibility  | 
                                                        |
| 141 | - if ( is_string( $args ) )  | 
                                                        |
| 142 | - $args = str_replace( '?', '', $args );  | 
                                                        |
| 139 | +    if ( ! empty( $args ) ) { | 
                                                        |
| 140 | + // Check for backward compatibility  | 
                                                        |
| 141 | + if ( is_string( $args ) )  | 
                                                        |
| 142 | + $args = str_replace( '?', '', $args );  | 
                                                        |
| 143 | 143 | |
| 144 | - $args = wp_parse_args( $args );  | 
                                                        |
| 144 | + $args = wp_parse_args( $args );  | 
                                                        |
| 145 | 145 | |
| 146 | - $redirect = add_query_arg( $args, $redirect );  | 
                                                        |
| 147 | - }  | 
                                                        |
| 146 | + $redirect = add_query_arg( $args, $redirect );  | 
                                                        |
| 147 | + }  | 
                                                        |
| 148 | 148 | |
| 149 | - wp_redirect( apply_filters( 'wpinv_send_back_to_checkout', $redirect, $args ) );  | 
                                                        |
| 150 | - exit;  | 
                                                        |
| 149 | + wp_redirect( apply_filters( 'wpinv_send_back_to_checkout', $redirect, $args ) );  | 
                                                        |
| 150 | + exit;  | 
                                                        |
| 151 | 151 | }  | 
                                                        
| 152 | 152 | |
| 153 | 153 |  function wpinv_get_success_page_url( $query_string = null ) { | 
                                                        
| 154 | - $success_page = wpinv_get_option( 'success_page', 0 );  | 
                                                        |
| 155 | - $success_page = get_permalink( $success_page );  | 
                                                        |
| 154 | + $success_page = wpinv_get_option( 'success_page', 0 );  | 
                                                        |
| 155 | + $success_page = get_permalink( $success_page );  | 
                                                        |
| 156 | 156 | |
| 157 | - if ( $query_string )  | 
                                                        |
| 158 | - $success_page .= $query_string;  | 
                                                        |
| 157 | + if ( $query_string )  | 
                                                        |
| 158 | + $success_page .= $query_string;  | 
                                                        |
| 159 | 159 | |
| 160 | - return apply_filters( 'wpinv_success_page_url', $success_page );  | 
                                                        |
| 160 | + return apply_filters( 'wpinv_success_page_url', $success_page );  | 
                                                        |
| 161 | 161 | }  | 
                                                        
| 162 | 162 | |
| 163 | 163 |  function wpinv_get_failed_transaction_uri( $extras = false ) { | 
                                                        
| 164 | - $uri = wpinv_get_option( 'failure_page', '' );  | 
                                                        |
| 165 | - $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url();  | 
                                                        |
| 164 | + $uri = wpinv_get_option( 'failure_page', '' );  | 
                                                        |
| 165 | + $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url();  | 
                                                        |
| 166 | 166 | |
| 167 | - if ( $extras )  | 
                                                        |
| 168 | - $uri .= $extras;  | 
                                                        |
| 167 | + if ( $extras )  | 
                                                        |
| 168 | + $uri .= $extras;  | 
                                                        |
| 169 | 169 | |
| 170 | - return apply_filters( 'wpinv_get_failed_transaction_uri', $uri );  | 
                                                        |
| 170 | + return apply_filters( 'wpinv_get_failed_transaction_uri', $uri );  | 
                                                        |
| 171 | 171 | }  | 
                                                        
| 172 | 172 | |
| 173 | 173 |  function wpinv_is_failed_transaction_page() { | 
                                                        
| 174 | - $ret = wpinv_get_option( 'failure_page', false );  | 
                                                        |
| 175 | - $ret = isset( $ret ) ? is_page( $ret ) : false;  | 
                                                        |
| 174 | + $ret = wpinv_get_option( 'failure_page', false );  | 
                                                        |
| 175 | + $ret = isset( $ret ) ? is_page( $ret ) : false;  | 
                                                        |
| 176 | 176 | |
| 177 | - return apply_filters( 'wpinv_is_failure_page', $ret );  | 
                                                        |
| 177 | + return apply_filters( 'wpinv_is_failure_page', $ret );  | 
                                                        |
| 178 | 178 | }  | 
                                                        
| 179 | 179 | |
| 180 | 180 |  function wpinv_transaction_query( $type = 'start' ) { | 
                                                        
@@ -7,201 +7,201 @@ 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 | 65 |  function wpinv_is_subscriptions_history_page() { | 
                                                        
| 66 | - $ret = wpinv_get_option( 'invoice_subscription_page', false );  | 
                                                        |
| 67 | - $ret = $ret ? is_page( $ret ) : false;  | 
                                                        |
| 68 | - return apply_filters( 'wpinv_is_subscriptions_history_page', $ret );  | 
                                                        |
| 66 | +    $ret = wpinv_get_option('invoice_subscription_page', false); | 
                                                        |
| 67 | + $ret = $ret ? is_page($ret) : false;  | 
                                                        |
| 68 | +    return apply_filters('wpinv_is_subscriptions_history_page', $ret); | 
                                                        |
| 69 | 69 | }  | 
                                                        
| 70 | 70 | |
| 71 | -function wpinv_send_to_success_page( $args = null ) { | 
                                                        |
| 71 | +function wpinv_send_to_success_page($args = null) { | 
                                                        |
| 72 | 72 | $redirect = wpinv_get_success_page_uri();  | 
                                                        
| 73 | 73 | |
| 74 | -    if ( !empty( $args ) ) { | 
                                                        |
| 74 | +    if (!empty($args)) { | 
                                                        |
| 75 | 75 | // Check for backward compatibility  | 
                                                        
| 76 | - if ( is_string( $args ) )  | 
                                                        |
| 77 | - $args = str_replace( '?', '', $args );  | 
                                                        |
| 76 | + if (is_string($args))  | 
                                                        |
| 77 | +            $args = str_replace('?', '', $args); | 
                                                        |
| 78 | 78 | |
| 79 | - $args = wp_parse_args( $args );  | 
                                                        |
| 79 | + $args = wp_parse_args($args);  | 
                                                        |
| 80 | 80 | |
| 81 | - $redirect = add_query_arg( $args, $redirect );  | 
                                                        |
| 81 | + $redirect = add_query_arg($args, $redirect);  | 
                                                        |
| 82 | 82 | }  | 
                                                        
| 83 | 83 | |
| 84 | - $gateway = isset( $_REQUEST['wpi-gateway'] ) ? $_REQUEST['wpi-gateway'] : '';  | 
                                                        |
| 84 | + $gateway = isset($_REQUEST['wpi-gateway']) ? $_REQUEST['wpi-gateway'] : '';  | 
                                                        |
| 85 | 85 | |
| 86 | - $redirect = apply_filters( 'wpinv_success_page_redirect', $redirect, $gateway, $args );  | 
                                                        |
| 87 | - wp_redirect( $redirect );  | 
                                                        |
| 86 | +    $redirect = apply_filters('wpinv_success_page_redirect', $redirect, $gateway, $args); | 
                                                        |
| 87 | + wp_redirect($redirect);  | 
                                                        |
| 88 | 88 | exit;  | 
                                                        
| 89 | 89 | }  | 
                                                        
| 90 | 90 | |
| 91 | -function wpinv_send_to_failed_page( $args = null ) { | 
                                                        |
| 91 | +function wpinv_send_to_failed_page($args = null) { | 
                                                        |
| 92 | 92 | $redirect = wpinv_get_failed_transaction_uri();  | 
                                                        
| 93 | 93 | |
| 94 | -    if ( !empty( $args ) ) { | 
                                                        |
| 94 | +    if (!empty($args)) { | 
                                                        |
| 95 | 95 | // Check for backward compatibility  | 
                                                        
| 96 | - if ( is_string( $args ) )  | 
                                                        |
| 97 | - $args = str_replace( '?', '', $args );  | 
                                                        |
| 96 | + if (is_string($args))  | 
                                                        |
| 97 | +            $args = str_replace('?', '', $args); | 
                                                        |
| 98 | 98 | |
| 99 | - $args = wp_parse_args( $args );  | 
                                                        |
| 99 | + $args = wp_parse_args($args);  | 
                                                        |
| 100 | 100 | |
| 101 | - $redirect = add_query_arg( $args, $redirect );  | 
                                                        |
| 101 | + $redirect = add_query_arg($args, $redirect);  | 
                                                        |
| 102 | 102 | }  | 
                                                        
| 103 | 103 | |
| 104 | - $gateway = isset( $_REQUEST['wpi-gateway'] ) ? $_REQUEST['wpi-gateway'] : '';  | 
                                                        |
| 104 | + $gateway = isset($_REQUEST['wpi-gateway']) ? $_REQUEST['wpi-gateway'] : '';  | 
                                                        |
| 105 | 105 | |
| 106 | - $redirect = apply_filters( 'wpinv_failed_page_redirect', $redirect, $gateway, $args );  | 
                                                        |
| 107 | - wp_redirect( $redirect );  | 
                                                        |
| 106 | +    $redirect = apply_filters('wpinv_failed_page_redirect', $redirect, $gateway, $args); | 
                                                        |
| 107 | + wp_redirect($redirect);  | 
                                                        |
| 108 | 108 | exit;  | 
                                                        
| 109 | 109 | }  | 
                                                        
| 110 | 110 | |
| 111 | -function wpinv_get_checkout_uri( $args = array() ) { | 
                                                        |
| 112 | - $uri = wpinv_get_option( 'checkout_page', false );  | 
                                                        |
| 113 | - $uri = isset( $uri ) ? get_permalink( $uri ) : NULL;  | 
                                                        |
| 111 | +function wpinv_get_checkout_uri($args = array()) { | 
                                                        |
| 112 | +	$uri = wpinv_get_option('checkout_page', false); | 
                                                        |
| 113 | + $uri = isset($uri) ? get_permalink($uri) : NULL;  | 
                                                        |
| 114 | 114 | |
| 115 | -	if ( !empty( $args ) ) { | 
                                                        |
| 115 | +	if (!empty($args)) { | 
                                                        |
| 116 | 116 | // Check for backward compatibility  | 
                                                        
| 117 | - if ( is_string( $args ) )  | 
                                                        |
| 118 | - $args = str_replace( '?', '', $args );  | 
                                                        |
| 117 | + if (is_string($args))  | 
                                                        |
| 118 | +			$args = str_replace('?', '', $args); | 
                                                        |
| 119 | 119 | |
| 120 | - $args = wp_parse_args( $args );  | 
                                                        |
| 120 | + $args = wp_parse_args($args);  | 
                                                        |
| 121 | 121 | |
| 122 | - $uri = add_query_arg( $args, $uri );  | 
                                                        |
| 122 | + $uri = add_query_arg($args, $uri);  | 
                                                        |
| 123 | 123 | }  | 
                                                        
| 124 | 124 | |
| 125 | - $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin';  | 
                                                        |
| 125 | +	$scheme = defined('FORCE_SSL_ADMIN') && FORCE_SSL_ADMIN ? 'https' : 'admin'; | 
                                                        |
| 126 | 126 | |
| 127 | - $ajax_url = admin_url( 'admin-ajax.php', $scheme );  | 
                                                        |
| 127 | +	$ajax_url = admin_url('admin-ajax.php', $scheme); | 
                                                        |
| 128 | 128 | |
| 129 | -	if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) { | 
                                                        |
| 130 | - $uri = preg_replace( '/^http:/', 'https:', $uri );  | 
                                                        |
| 129 | +	if ((!preg_match('/^https/', $uri) && preg_match('/^https/', $ajax_url)) || wpinv_is_ssl_enforced()) { | 
                                                        |
| 130 | +		$uri = preg_replace('/^http:/', 'https:', $uri); | 
                                                        |
| 131 | 131 | }  | 
                                                        
| 132 | 132 | |
| 133 | - return apply_filters( 'wpinv_get_checkout_uri', $uri );  | 
                                                        |
| 133 | +	return apply_filters('wpinv_get_checkout_uri', $uri); | 
                                                        |
| 134 | 134 | }  | 
                                                        
| 135 | 135 | |
| 136 | -function wpinv_send_back_to_checkout( $args = array() ) { | 
                                                        |
| 136 | +function wpinv_send_back_to_checkout($args = array()) { | 
                                                        |
| 137 | 137 | $redirect = wpinv_get_checkout_uri();  | 
                                                        
| 138 | 138 | |
| 139 | -	if ( ! empty( $args ) ) { | 
                                                        |
| 139 | +	if (!empty($args)) { | 
                                                        |
| 140 | 140 | // Check for backward compatibility  | 
                                                        
| 141 | - if ( is_string( $args ) )  | 
                                                        |
| 142 | - $args = str_replace( '?', '', $args );  | 
                                                        |
| 141 | + if (is_string($args))  | 
                                                        |
| 142 | +			$args = str_replace('?', '', $args); | 
                                                        |
| 143 | 143 | |
| 144 | - $args = wp_parse_args( $args );  | 
                                                        |
| 144 | + $args = wp_parse_args($args);  | 
                                                        |
| 145 | 145 | |
| 146 | - $redirect = add_query_arg( $args, $redirect );  | 
                                                        |
| 146 | + $redirect = add_query_arg($args, $redirect);  | 
                                                        |
| 147 | 147 | }  | 
                                                        
| 148 | 148 | |
| 149 | - wp_redirect( apply_filters( 'wpinv_send_back_to_checkout', $redirect, $args ) );  | 
                                                        |
| 149 | +	wp_redirect(apply_filters('wpinv_send_back_to_checkout', $redirect, $args)); | 
                                                        |
| 150 | 150 | exit;  | 
                                                        
| 151 | 151 | }  | 
                                                        
| 152 | 152 | |
| 153 | -function wpinv_get_success_page_url( $query_string = null ) { | 
                                                        |
| 154 | - $success_page = wpinv_get_option( 'success_page', 0 );  | 
                                                        |
| 155 | - $success_page = get_permalink( $success_page );  | 
                                                        |
| 153 | +function wpinv_get_success_page_url($query_string = null) { | 
                                                        |
| 154 | +	$success_page = wpinv_get_option('success_page', 0); | 
                                                        |
| 155 | + $success_page = get_permalink($success_page);  | 
                                                        |
| 156 | 156 | |
| 157 | - if ( $query_string )  | 
                                                        |
| 157 | + if ($query_string)  | 
                                                        |
| 158 | 158 | $success_page .= $query_string;  | 
                                                        
| 159 | 159 | |
| 160 | - return apply_filters( 'wpinv_success_page_url', $success_page );  | 
                                                        |
| 160 | +	return apply_filters('wpinv_success_page_url', $success_page); | 
                                                        |
| 161 | 161 | }  | 
                                                        
| 162 | 162 | |
| 163 | -function wpinv_get_failed_transaction_uri( $extras = false ) { | 
                                                        |
| 164 | - $uri = wpinv_get_option( 'failure_page', '' );  | 
                                                        |
| 165 | - $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url();  | 
                                                        |
| 163 | +function wpinv_get_failed_transaction_uri($extras = false) { | 
                                                        |
| 164 | +	$uri = wpinv_get_option('failure_page', ''); | 
                                                        |
| 165 | + $uri = !empty($uri) ? trailingslashit(get_permalink($uri)) : home_url();  | 
                                                        |
| 166 | 166 | |
| 167 | - if ( $extras )  | 
                                                        |
| 167 | + if ($extras)  | 
                                                        |
| 168 | 168 | $uri .= $extras;  | 
                                                        
| 169 | 169 | |
| 170 | - return apply_filters( 'wpinv_get_failed_transaction_uri', $uri );  | 
                                                        |
| 170 | +	return apply_filters('wpinv_get_failed_transaction_uri', $uri); | 
                                                        |
| 171 | 171 | }  | 
                                                        
| 172 | 172 | |
| 173 | 173 |  function wpinv_is_failed_transaction_page() { | 
                                                        
| 174 | - $ret = wpinv_get_option( 'failure_page', false );  | 
                                                        |
| 175 | - $ret = isset( $ret ) ? is_page( $ret ) : false;  | 
                                                        |
| 174 | +	$ret = wpinv_get_option('failure_page', false); | 
                                                        |
| 175 | + $ret = isset($ret) ? is_page($ret) : false;  | 
                                                        |
| 176 | 176 | |
| 177 | - return apply_filters( 'wpinv_is_failure_page', $ret );  | 
                                                        |
| 177 | +	return apply_filters('wpinv_is_failure_page', $ret); | 
                                                        |
| 178 | 178 | }  | 
                                                        
| 179 | 179 | |
| 180 | -function wpinv_transaction_query( $type = 'start' ) { | 
                                                        |
| 180 | +function wpinv_transaction_query($type = 'start') { | 
                                                        |
| 181 | 181 | global $wpdb;  | 
                                                        
| 182 | 182 | |
| 183 | 183 | $wpdb->hide_errors();  | 
                                                        
| 184 | 184 | |
| 185 | -    if ( ! defined( 'WPINV_USE_TRANSACTIONS' ) ) { | 
                                                        |
| 186 | - define( 'WPINV_USE_TRANSACTIONS', true );  | 
                                                        |
| 185 | +    if (!defined('WPINV_USE_TRANSACTIONS')) { | 
                                                        |
| 186 | +        define('WPINV_USE_TRANSACTIONS', true); | 
                                                        |
| 187 | 187 | }  | 
                                                        
| 188 | 188 | |
| 189 | -    if ( WPINV_USE_TRANSACTIONS ) { | 
                                                        |
| 190 | -        switch ( $type ) { | 
                                                        |
| 189 | +    if (WPINV_USE_TRANSACTIONS) { | 
                                                        |
| 190 | +        switch ($type) { | 
                                                        |
| 191 | 191 | case 'commit' :  | 
                                                        
| 192 | - $wpdb->query( 'COMMIT' );  | 
                                                        |
| 192 | +                $wpdb->query('COMMIT'); | 
                                                        |
| 193 | 193 | break;  | 
                                                        
| 194 | 194 | case 'rollback' :  | 
                                                        
| 195 | - $wpdb->query( 'ROLLBACK' );  | 
                                                        |
| 195 | +                $wpdb->query('ROLLBACK'); | 
                                                        |
| 196 | 196 | break;  | 
                                                        
| 197 | 197 | default :  | 
                                                        
| 198 | - $wpdb->query( 'START TRANSACTION' );  | 
                                                        |
| 198 | +                $wpdb->query('START TRANSACTION'); | 
                                                        |
| 199 | 199 | break;  | 
                                                        
| 200 | 200 | }  | 
                                                        
| 201 | 201 | }  | 
                                                        
| 202 | 202 | }  | 
                                                        
| 203 | 203 | |
| 204 | -function wpinv_create_invoice( $args = array(), $data = array(), $wp_error = false ) { | 
                                                        |
| 204 | +function wpinv_create_invoice($args = array(), $data = array(), $wp_error = false) { | 
                                                        |
| 205 | 205 | $default_args = array(  | 
                                                        
| 206 | 206 | 'status' => '',  | 
                                                        
| 207 | 207 | 'user_id' => null,  | 
                                                        
@@ -211,63 +211,63 @@ discard block  | 
                                                    ||
| 211 | 211 | 'parent' => 0  | 
                                                        
| 212 | 212 | );  | 
                                                        
| 213 | 213 | |
| 214 | - $args = wp_parse_args( $args, $default_args );  | 
                                                        |
| 214 | + $args = wp_parse_args($args, $default_args);  | 
                                                        |
| 215 | 215 | $invoice_data = array();  | 
                                                        
| 216 | 216 | |
| 217 | -    if ( $args['invoice_id'] > 0 ) { | 
                                                        |
| 218 | - $updating = true;  | 
                                                        |
| 217 | +    if ($args['invoice_id'] > 0) { | 
                                                        |
| 218 | + $updating = true;  | 
                                                        |
| 219 | 219 | $invoice_data['post_type'] = 'wpi_invoice';  | 
                                                        
| 220 | 220 | $invoice_data['ID'] = $args['invoice_id'];  | 
                                                        
| 221 | 221 |      } else { | 
                                                        
| 222 | 222 | $updating = false;  | 
                                                        
| 223 | 223 | $invoice_data['post_type'] = 'wpi_invoice';  | 
                                                        
| 224 | - $invoice_data['post_status'] = apply_filters( 'wpinv_default_invoice_status', 'wpi-pending' );  | 
                                                        |
| 224 | +        $invoice_data['post_status']    = apply_filters('wpinv_default_invoice_status', 'wpi-pending'); | 
                                                        |
| 225 | 225 | $invoice_data['ping_status'] = 'closed';  | 
                                                        
| 226 | - $invoice_data['post_author'] = !empty( $args['user_id'] ) ? $args['user_id'] : get_current_user_id();  | 
                                                        |
| 227 | - $invoice_data['post_title'] = wpinv_format_invoice_number( '0' );  | 
                                                        |
| 228 | - $invoice_data['post_parent'] = absint( $args['parent'] );  | 
                                                        |
| 229 | -        if ( !empty( $args['created_date'] ) ) { | 
                                                        |
| 226 | + $invoice_data['post_author'] = !empty($args['user_id']) ? $args['user_id'] : get_current_user_id();  | 
                                                        |
| 227 | +        $invoice_data['post_title']     = wpinv_format_invoice_number('0'); | 
                                                        |
| 228 | + $invoice_data['post_parent'] = absint($args['parent']);  | 
                                                        |
| 229 | +        if (!empty($args['created_date'])) { | 
                                                        |
| 230 | 230 | $invoice_data['post_date'] = $args['created_date'];  | 
                                                        
| 231 | - $invoice_data['post_date_gmt'] = get_gmt_from_date( $args['created_date'] );  | 
                                                        |
| 231 | + $invoice_data['post_date_gmt'] = get_gmt_from_date($args['created_date']);  | 
                                                        |
| 232 | 232 | }  | 
                                                        
| 233 | 233 | }  | 
                                                        
| 234 | 234 | |
| 235 | -    if ( $args['status'] ) { | 
                                                        |
| 236 | -        if ( ! in_array( $args['status'], array_keys( wpinv_get_invoice_statuses() ) ) ) { | 
                                                        |
| 237 | - return new WP_Error( 'wpinv_invalid_invoice_status', wp_sprintf( __( 'Invalid invoice status: %s', 'invoicing' ), $args['status'] ) );  | 
                                                        |
| 235 | +    if ($args['status']) { | 
                                                        |
| 236 | +        if (!in_array($args['status'], array_keys(wpinv_get_invoice_statuses()))) { | 
                                                        |
| 237 | +            return new WP_Error('wpinv_invalid_invoice_status', wp_sprintf(__('Invalid invoice status: %s', 'invoicing'), $args['status'])); | 
                                                        |
| 238 | 238 | }  | 
                                                        
| 239 | - $invoice_data['post_status'] = $args['status'];  | 
                                                        |
| 239 | + $invoice_data['post_status'] = $args['status'];  | 
                                                        |
| 240 | 240 | }  | 
                                                        
| 241 | 241 | |
| 242 | -    if ( ! is_null( $args['user_note'] ) ) { | 
                                                        |
| 243 | - $invoice_data['post_excerpt'] = $args['user_note'];  | 
                                                        |
| 242 | +    if (!is_null($args['user_note'])) { | 
                                                        |
| 243 | + $invoice_data['post_excerpt'] = $args['user_note'];  | 
                                                        |
| 244 | 244 | }  | 
                                                        
| 245 | 245 | |
| 246 | -    if ( $updating ) { | 
                                                        |
| 247 | - $invoice_id = wp_update_post( $invoice_data, true );  | 
                                                        |
| 246 | +    if ($updating) { | 
                                                        |
| 247 | + $invoice_id = wp_update_post($invoice_data, true);  | 
                                                        |
| 248 | 248 |      } else { | 
                                                        
| 249 | - $invoice_id = wp_insert_post( apply_filters( 'wpinv_new_invoice_data', $invoice_data ), true );  | 
                                                        |
| 249 | +        $invoice_id = wp_insert_post(apply_filters('wpinv_new_invoice_data', $invoice_data), true); | 
                                                        |
| 250 | 250 | }  | 
                                                        
| 251 | 251 | |
| 252 | -    if ( is_wp_error( $invoice_id ) ) { | 
                                                        |
| 252 | +    if (is_wp_error($invoice_id)) { | 
                                                        |
| 253 | 253 | return $wp_error ? $invoice_id : 0;  | 
                                                        
| 254 | 254 | }  | 
                                                        
| 255 | 255 | |
| 256 | - $invoice = wpinv_get_invoice( $invoice_id );  | 
                                                        |
| 257 | -  | 
                                                        |
| 258 | -    if ( !$updating ) { | 
                                                        |
| 259 | - update_post_meta( $invoice_id, '_wpinv_key', apply_filters( 'wpinv_generate_invoice_key', uniqid( 'wpinv_' ) ) );  | 
                                                        |
| 260 | - update_post_meta( $invoice_id, '_wpinv_currency', wpinv_get_currency() );  | 
                                                        |
| 261 | - update_post_meta( $invoice_id, '_wpinv_include_tax', get_option( 'wpinv_prices_include_tax' ) );  | 
                                                        |
| 262 | - update_post_meta( $invoice_id, '_wpinv_user_ip', wpinv_get_ip() );  | 
                                                        |
| 263 | - update_post_meta( $invoice_id, '_wpinv_user_agent', wpinv_get_user_agent() );  | 
                                                        |
| 264 | - update_post_meta( $invoice_id, '_wpinv_created_via', sanitize_text_field( $args['created_via'] ) );  | 
                                                        |
| 256 | + $invoice = wpinv_get_invoice($invoice_id);  | 
                                                        |
| 257 | +  | 
                                                        |
| 258 | +    if (!$updating) { | 
                                                        |
| 259 | +        update_post_meta($invoice_id, '_wpinv_key', apply_filters('wpinv_generate_invoice_key', uniqid('wpinv_'))); | 
                                                        |
| 260 | + update_post_meta($invoice_id, '_wpinv_currency', wpinv_get_currency());  | 
                                                        |
| 261 | +        update_post_meta($invoice_id, '_wpinv_include_tax', get_option('wpinv_prices_include_tax')); | 
                                                        |
| 262 | + update_post_meta($invoice_id, '_wpinv_user_ip', wpinv_get_ip());  | 
                                                        |
| 263 | + update_post_meta($invoice_id, '_wpinv_user_agent', wpinv_get_user_agent());  | 
                                                        |
| 264 | + update_post_meta($invoice_id, '_wpinv_created_via', sanitize_text_field($args['created_via']));  | 
                                                        |
| 265 | 265 | |
| 266 | 266 | // Add invoice note  | 
                                                        
| 267 | - $invoice->add_note( wp_sprintf( __( 'Invoice is created with status %s.', 'invoicing' ), wpinv_status_nicename( $invoice->status ) ) );  | 
                                                        |
| 267 | +        $invoice->add_note(wp_sprintf(__('Invoice is created with status %s.', 'invoicing'), wpinv_status_nicename($invoice->status))); | 
                                                        |
| 268 | 268 | }  | 
                                                        
| 269 | 269 | |
| 270 | - update_post_meta( $invoice_id, '_wpinv_version', WPINV_VERSION );  | 
                                                        |
| 270 | + update_post_meta($invoice_id, '_wpinv_version', WPINV_VERSION);  | 
                                                        |
| 271 | 271 | |
| 272 | 272 | return $invoice;  | 
                                                        
| 273 | 273 | }  | 
                                                        
@@ -275,178 +275,178 @@ discard block  | 
                                                    ||
| 275 | 275 |  function wpinv_get_prefix() { | 
                                                        
| 276 | 276 | $invoice_prefix = 'INV-';  | 
                                                        
| 277 | 277 | |
| 278 | - return apply_filters( 'wpinv_get_prefix', $invoice_prefix );  | 
                                                        |
| 278 | +    return apply_filters('wpinv_get_prefix', $invoice_prefix); | 
                                                        |
| 279 | 279 | }  | 
                                                        
| 280 | 280 | |
| 281 | 281 |  function wpinv_get_business_logo() { | 
                                                        
| 282 | - $business_logo = wpinv_get_option( 'logo' );  | 
                                                        |
| 283 | - return apply_filters( 'wpinv_get_business_logo', $business_logo );  | 
                                                        |
| 282 | +    $business_logo = wpinv_get_option('logo'); | 
                                                        |
| 283 | +    return apply_filters('wpinv_get_business_logo', $business_logo); | 
                                                        |
| 284 | 284 | }  | 
                                                        
| 285 | 285 | |
| 286 | 286 |  function wpinv_get_business_name() { | 
                                                        
| 287 | 287 |      $business_name = wpinv_get_option('store_name'); | 
                                                        
| 288 | - return apply_filters( 'wpinv_get_business_name', $business_name );  | 
                                                        |
| 288 | +    return apply_filters('wpinv_get_business_name', $business_name); | 
                                                        |
| 289 | 289 | }  | 
                                                        
| 290 | 290 | |
| 291 | 291 |  function wpinv_get_blogname() { | 
                                                        
| 292 | - return wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );  | 
                                                        |
| 292 | +    return wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); | 
                                                        |
| 293 | 293 | }  | 
                                                        
| 294 | 294 | |
| 295 | 295 |  function wpinv_get_admin_email() { | 
                                                        
| 296 | - $admin_email = get_option( 'admin_email' );  | 
                                                        |
| 297 | - return apply_filters( 'wpinv_admin_email', $admin_email );  | 
                                                        |
| 296 | +    $admin_email = get_option('admin_email'); | 
                                                        |
| 297 | +    return apply_filters('wpinv_admin_email', $admin_email); | 
                                                        |
| 298 | 298 | }  | 
                                                        
| 299 | 299 | |
| 300 | 300 |  function wpinv_get_business_website() { | 
                                                        
| 301 | - $business_website = home_url( '/' );  | 
                                                        |
| 302 | - return apply_filters( 'wpinv_get_business_website', $business_website );  | 
                                                        |
| 301 | +    $business_website = home_url('/'); | 
                                                        |
| 302 | +    return apply_filters('wpinv_get_business_website', $business_website); | 
                                                        |
| 303 | 303 | }  | 
                                                        
| 304 | 304 | |
| 305 | -function wpinv_get_terms_text( $invoice_id = 0 ) { | 
                                                        |
| 305 | +function wpinv_get_terms_text($invoice_id = 0) { | 
                                                        |
| 306 | 306 | $terms_text = '';  | 
                                                        
| 307 | - return apply_filters( 'wpinv_get_terms_text', $terms_text, $invoice_id );  | 
                                                        |
| 307 | +    return apply_filters('wpinv_get_terms_text', $terms_text, $invoice_id); | 
                                                        |
| 308 | 308 | }  | 
                                                        
| 309 | 309 | |
| 310 | 310 |  function wpinv_get_business_footer() { | 
                                                        
| 311 | - $site_link = '<a target="_blank" href="' . esc_url( wpinv_get_business_website() ) . '">' . esc_html( wpinv_get_business_name() ) . '</a>';  | 
                                                        |
| 312 | - $business_footer = wp_sprintf( __( 'Thanks for using %s', 'invoicing' ), $site_link );  | 
                                                        |
| 313 | - return apply_filters( 'wpinv_get_business_footer', $business_footer );  | 
                                                        |
| 311 | + $site_link = '<a target="_blank" href="' . esc_url(wpinv_get_business_website()) . '">' . esc_html(wpinv_get_business_name()) . '</a>';  | 
                                                        |
| 312 | +    $business_footer = wp_sprintf(__('Thanks for using %s', 'invoicing'), $site_link); | 
                                                        |
| 313 | +    return apply_filters('wpinv_get_business_footer', $business_footer); | 
                                                        |
| 314 | 314 | }  | 
                                                        
| 315 | 315 | |
| 316 | 316 |  function wpinv_checkout_required_fields() { | 
                                                        
| 317 | 317 | $required_fields = array();  | 
                                                        
| 318 | 318 | |
| 319 | 319 | // Let payment gateways and other extensions determine if address fields should be required  | 
                                                        
| 320 | - $require_billing_details = apply_filters( 'wpinv_checkout_required_billing_details', wpinv_use_taxes() );  | 
                                                        |
| 320 | +    $require_billing_details = apply_filters('wpinv_checkout_required_billing_details', wpinv_use_taxes()); | 
                                                        |
| 321 | 321 | |
| 322 | -    if ( $require_billing_details ) { | 
                                                        |
| 322 | +    if ($require_billing_details) { | 
                                                        |
| 323 | 323 | ///$required_fields['email'] = array(  | 
                                                        
| 324 | 324 | ///'error_id' => 'invalid_email',  | 
                                                        
| 325 | 325 | ///'error_message' => __( 'Please enter a valid email address', 'invoicing' )  | 
                                                        
| 326 | 326 | ///);  | 
                                                        
| 327 | 327 | $required_fields['first_name'] = array(  | 
                                                        
| 328 | 328 | 'error_id' => 'invalid_first_name',  | 
                                                        
| 329 | - 'error_message' => __( 'Please enter your first name', 'invoicing' )  | 
                                                        |
| 329 | +                'error_message' => __('Please enter your first name', 'invoicing') | 
                                                        |
| 330 | 330 | );  | 
                                                        
| 331 | 331 | $required_fields['address'] = array(  | 
                                                        
| 332 | 332 | 'error_id' => 'invalid_address',  | 
                                                        
| 333 | - 'error_message' => __( 'Please enter your address', 'invoicing' )  | 
                                                        |
| 333 | +                'error_message' => __('Please enter your address', 'invoicing') | 
                                                        |
| 334 | 334 | );  | 
                                                        
| 335 | 335 | $required_fields['city'] = array(  | 
                                                        
| 336 | 336 | 'error_id' => 'invalid_city',  | 
                                                        
| 337 | - 'error_message' => __( 'Please enter your billing city', 'invoicing' )  | 
                                                        |
| 337 | +                'error_message' => __('Please enter your billing city', 'invoicing') | 
                                                        |
| 338 | 338 | );  | 
                                                        
| 339 | 339 | $required_fields['state'] = array(  | 
                                                        
| 340 | 340 | 'error_id' => 'invalid_state',  | 
                                                        
| 341 | - 'error_message' => __( 'Please enter billing state / province', 'invoicing' )  | 
                                                        |
| 341 | +                'error_message' => __('Please enter billing state / province', 'invoicing') | 
                                                        |
| 342 | 342 | );  | 
                                                        
| 343 | 343 | $required_fields['country'] = array(  | 
                                                        
| 344 | 344 | 'error_id' => 'invalid_country',  | 
                                                        
| 345 | - 'error_message' => __( 'Please select your billing country', 'invoicing' )  | 
                                                        |
| 345 | +                'error_message' => __('Please select your billing country', 'invoicing') | 
                                                        |
| 346 | 346 | );  | 
                                                        
| 347 | 347 | }  | 
                                                        
| 348 | 348 | |
| 349 | - return apply_filters( 'wpinv_checkout_required_fields', $required_fields );  | 
                                                        |
| 349 | +    return apply_filters('wpinv_checkout_required_fields', $required_fields); | 
                                                        |
| 350 | 350 | }  | 
                                                        
| 351 | 351 | |
| 352 | 352 |  function wpinv_is_ssl_enforced() { | 
                                                        
| 353 | - $ssl_enforced = wpinv_get_option( 'enforce_ssl', false );  | 
                                                        |
| 354 | - return (bool) apply_filters( 'wpinv_is_ssl_enforced', $ssl_enforced );  | 
                                                        |
| 353 | +    $ssl_enforced = wpinv_get_option('enforce_ssl', false); | 
                                                        |
| 354 | +    return (bool)apply_filters('wpinv_is_ssl_enforced', $ssl_enforced); | 
                                                        |
| 355 | 355 | }  | 
                                                        
| 356 | 356 | |
| 357 | -function wpinv_user_can_view_invoice( $post ) { | 
                                                        |
| 357 | +function wpinv_user_can_view_invoice($post) { | 
                                                        |
| 358 | 358 | $allow = false;  | 
                                                        
| 359 | 359 | |
| 360 | - $post = get_post( $post );  | 
                                                        |
| 360 | + $post = get_post($post);  | 
                                                        |
| 361 | 361 | |
| 362 | -    if ( empty( $post->ID ) ) { | 
                                                        |
| 362 | +    if (empty($post->ID)) { | 
                                                        |
| 363 | 363 | return $allow;  | 
                                                        
| 364 | 364 | }  | 
                                                        
| 365 | 365 | |
| 366 | - $invoice = wpinv_get_invoice( $post->ID );  | 
                                                        |
| 367 | -    if ( empty( $invoice->ID ) ) { | 
                                                        |
| 366 | + $invoice = wpinv_get_invoice($post->ID);  | 
                                                        |
| 367 | +    if (empty($invoice->ID)) { | 
                                                        |
| 368 | 368 | return $allow;  | 
                                                        
| 369 | 369 | }  | 
                                                        
| 370 | 370 | |
| 371 | 371 | // Don't allow trash, draft status  | 
                                                        
| 372 | -    if ( $invoice->has_status( array_keys( wpinv_get_invoice_statuses() ) ) ) { | 
                                                        |
| 373 | -        if ( current_user_can( 'manage_options' ) ) { // Admin user | 
                                                        |
| 372 | +    if ($invoice->has_status(array_keys(wpinv_get_invoice_statuses()))) { | 
                                                        |
| 373 | +        if (current_user_can('manage_options')) { // Admin user | 
                                                        |
| 374 | 374 | $allow = true;  | 
                                                        
| 375 | 375 |          } else { | 
                                                        
| 376 | -            if ( is_user_logged_in() ) { | 
                                                        |
| 377 | -                if ( (int)$invoice->get_user_id() === (int)get_current_user_id() ) { | 
                                                        |
| 376 | +            if (is_user_logged_in()) { | 
                                                        |
| 377 | +                if ((int)$invoice->get_user_id() === (int)get_current_user_id()) { | 
                                                        |
| 378 | 378 | $allow = true;  | 
                                                        
| 379 | -                } else if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { | 
                                                        |
| 379 | +                } else if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) { | 
                                                        |
| 380 | 380 | $allow = true;  | 
                                                        
| 381 | 381 | }  | 
                                                        
| 382 | 382 |              } else { | 
                                                        
| 383 | -                if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { | 
                                                        |
| 383 | +                if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) { | 
                                                        |
| 384 | 384 | $allow = true;  | 
                                                        
| 385 | 385 | }  | 
                                                        
| 386 | 386 | }  | 
                                                        
| 387 | 387 | }  | 
                                                        
| 388 | 388 | }  | 
                                                        
| 389 | 389 | |
| 390 | - return apply_filters( 'wpinv_can_print_invoice', $allow, $post, $invoice );  | 
                                                        |
| 390 | +    return apply_filters('wpinv_can_print_invoice', $allow, $post, $invoice); | 
                                                        |
| 391 | 391 | }  | 
                                                        
| 392 | 392 | |
| 393 | 393 |  function wpinv_schedule_events() { | 
                                                        
| 394 | 394 | // hourly, daily and twicedaily  | 
                                                        
| 395 | -    if ( !wp_next_scheduled( 'wpinv_register_schedule_event_twicedaily' ) ) { | 
                                                        |
| 396 | - wp_schedule_event( current_time( 'timestamp' ), 'twicedaily', 'wpinv_register_schedule_event_twicedaily' );  | 
                                                        |
| 395 | +    if (!wp_next_scheduled('wpinv_register_schedule_event_twicedaily')) { | 
                                                        |
| 396 | +        wp_schedule_event(current_time('timestamp'), 'twicedaily', 'wpinv_register_schedule_event_twicedaily'); | 
                                                        |
| 397 | 397 | }  | 
                                                        
| 398 | 398 | }  | 
                                                        
| 399 | -add_action( 'wp', 'wpinv_schedule_events' );  | 
                                                        |
| 399 | +add_action('wp', 'wpinv_schedule_events'); | 
                                                        |
| 400 | 400 | |
| 401 | 401 |  function wpinv_schedule_event_twicedaily() { | 
                                                        
| 402 | 402 | wpinv_email_payment_reminders();  | 
                                                        
| 403 | 403 | }  | 
                                                        
| 404 | -add_action( 'wpinv_register_schedule_event_twicedaily', 'wpinv_schedule_event_twicedaily' );  | 
                                                        |
| 404 | +add_action('wpinv_register_schedule_event_twicedaily', 'wpinv_schedule_event_twicedaily'); | 
                                                        |
| 405 | 405 | |
| 406 | 406 |  function wpinv_require_login_to_checkout() { | 
                                                        
| 407 | - $return = wpinv_get_option( 'login_to_checkout', false );  | 
                                                        |
| 408 | - return (bool) apply_filters( 'wpinv_require_login_to_checkout', $return );  | 
                                                        |
| 407 | +    $return = wpinv_get_option('login_to_checkout', false); | 
                                                        |
| 408 | +    return (bool)apply_filters('wpinv_require_login_to_checkout', $return); | 
                                                        |
| 409 | 409 | }  | 
                                                        
| 410 | 410 | |
| 411 | -function wpinv_sequential_number_active( $type = '' ) { | 
                                                        |
| 412 | - $check = apply_filters( 'wpinv_pre_check_sequential_number_active', null, $type );  | 
                                                        |
| 413 | -    if ( null !== $check ) { | 
                                                        |
| 411 | +function wpinv_sequential_number_active($type = '') { | 
                                                        |
| 412 | +    $check = apply_filters('wpinv_pre_check_sequential_number_active', null, $type); | 
                                                        |
| 413 | +    if (null !== $check) { | 
                                                        |
| 414 | 414 | return $check;  | 
                                                        
| 415 | 415 | }  | 
                                                        
| 416 | 416 | |
| 417 | - return wpinv_get_option( 'sequential_invoice_number' );  | 
                                                        |
| 417 | +    return wpinv_get_option('sequential_invoice_number'); | 
                                                        |
| 418 | 418 | }  | 
                                                        
| 419 | 419 | |
| 420 | -function wpinv_switch_to_locale( $locale = NULL ) { | 
                                                        |
| 420 | +function wpinv_switch_to_locale($locale = NULL) { | 
                                                        |
| 421 | 421 | global $invoicing, $wpi_switch_locale;  | 
                                                        
| 422 | 422 | |
| 423 | -    if ( ! empty( $invoicing ) && function_exists( 'switch_to_locale' ) ) { | 
                                                        |
| 424 | - $locale = empty( $locale ) ? get_locale() : $locale;  | 
                                                        |
| 423 | +    if (!empty($invoicing) && function_exists('switch_to_locale')) { | 
                                                        |
| 424 | + $locale = empty($locale) ? get_locale() : $locale;  | 
                                                        |
| 425 | 425 | |
| 426 | - switch_to_locale( $locale );  | 
                                                        |
| 426 | + switch_to_locale($locale);  | 
                                                        |
| 427 | 427 | |
| 428 | 428 | $wpi_switch_locale = $locale;  | 
                                                        
| 429 | 429 | |
| 430 | - add_filter( 'plugin_locale', 'get_locale' );  | 
                                                        |
| 430 | +        add_filter('plugin_locale', 'get_locale'); | 
                                                        |
| 431 | 431 | |
| 432 | 432 | $invoicing->load_textdomain();  | 
                                                        
| 433 | 433 | |
| 434 | - do_action( 'wpinv_switch_to_locale', $locale );  | 
                                                        |
| 434 | +        do_action('wpinv_switch_to_locale', $locale); | 
                                                        |
| 435 | 435 | }  | 
                                                        
| 436 | 436 | }  | 
                                                        
| 437 | 437 | |
| 438 | 438 |  function wpinv_restore_locale() { | 
                                                        
| 439 | 439 | global $invoicing, $wpi_switch_locale;  | 
                                                        
| 440 | 440 | |
| 441 | -    if ( ! empty( $invoicing ) && function_exists( 'restore_previous_locale' ) && $wpi_switch_locale ) { | 
                                                        |
| 441 | +    if (!empty($invoicing) && function_exists('restore_previous_locale') && $wpi_switch_locale) { | 
                                                        |
| 442 | 442 | restore_previous_locale();  | 
                                                        
| 443 | 443 | |
| 444 | 444 | $wpi_switch_locale = NULL;  | 
                                                        
| 445 | 445 | |
| 446 | - remove_filter( 'plugin_locale', 'get_locale' );  | 
                                                        |
| 446 | +        remove_filter('plugin_locale', 'get_locale'); | 
                                                        |
| 447 | 447 | |
| 448 | 448 | $invoicing->load_textdomain();  | 
                                                        
| 449 | 449 | |
| 450 | - do_action( 'wpinv_restore_locale' );  | 
                                                        |
| 450 | +        do_action('wpinv_restore_locale'); | 
                                                        |
| 451 | 451 | }  | 
                                                        
| 452 | 452 | }  | 
                                                        
| 453 | 453 | \ No newline at end of file  | 
                                                        
@@ -1,68 +1,68 @@  | 
                                                    ||
| 1 | 1 | <?php  | 
                                                        
| 2 | 2 | // don't load directly  | 
                                                        
| 3 | -if ( !defined('ABSPATH') ) | 
                                                        |
| 3 | +if (!defined('ABSPATH')) | 
                                                        |
| 4 | 4 |      die('-1'); | 
                                                        
| 5 | 5 | |
| 6 | 6 | global $wpinv_euvat;  | 
                                                        
| 7 | 7 | |
| 8 | -$sent_to_admin = !empty( $sent_to_admin ) ? true : false;  | 
                                                        |
| 9 | -$invoice_url = $invoice->get_view_url( true );  | 
                                                        |
| 8 | +$sent_to_admin = !empty($sent_to_admin) ? true : false;  | 
                                                        |
| 9 | +$invoice_url = $invoice->get_view_url(true);  | 
                                                        |
| 10 | 10 | $use_taxes = wpinv_use_taxes();  | 
                                                        
| 11 | 11 | $vat_name = $wpinv_euvat->get_vat_name();  | 
                                                        
| 12 | 12 | |
| 13 | -do_action( 'wpinv_email_before_invoice_details', $invoice, $sent_to_admin ); ?>  | 
                                                        |
| 13 | +do_action('wpinv_email_before_invoice_details', $invoice, $sent_to_admin); ?> | 
                                                        |
| 14 | 14 | <div id="wpinv-email-details">  | 
                                                        
| 15 | - <h3 class="wpinv-details-t"><?php echo apply_filters( 'wpinv_email_details_title', __( 'Invoice Details', 'invoicing' ), $invoice ); ?></h3>  | 
                                                        |
| 15 | +    <h3 class="wpinv-details-t"><?php echo apply_filters('wpinv_email_details_title', __('Invoice Details', 'invoicing'), $invoice); ?></h3> | 
                                                        |
| 16 | 16 | <table class="table table-bordered table-sm">  | 
                                                        
| 17 | -        <?php if ( $invoice_number = $invoice->get_number() ) { ?> | 
                                                        |
| 17 | +        <?php if ($invoice_number = $invoice->get_number()) { ?> | 
                                                        |
| 18 | 18 | <tr>  | 
                                                        
| 19 | - <td><?php echo apply_filters( 'wpinv_invoice_number_label', __( 'Invoice Number', 'invoicing' ), $invoice ); ?></td>  | 
                                                        |
| 20 | - <td><a href="<?php echo esc_url( $invoice_url ) ;?>"><?php echo $invoice_number; ?></a></td>  | 
                                                        |
| 19 | +                <td><?php echo apply_filters('wpinv_invoice_number_label', __('Invoice Number', 'invoicing'), $invoice); ?></td> | 
                                                        |
| 20 | + <td><a href="<?php echo esc_url($invoice_url); ?>"><?php echo $invoice_number; ?></a></td>  | 
                                                        |
| 21 | 21 | </tr>  | 
                                                        
| 22 | 22 | <?php } ?>  | 
                                                        
| 23 | 23 | <tr>  | 
                                                        
| 24 | - <td><?php echo apply_filters( 'wpinv_invoice_status_label', __( 'Invoice Status', 'invoicing' ), $invoice ); ?></td>  | 
                                                        |
| 25 | - <td><?php echo $invoice->get_status( true ); ?></td>  | 
                                                        |
| 24 | +            <td><?php echo apply_filters('wpinv_invoice_status_label', __('Invoice Status', 'invoicing'), $invoice); ?></td> | 
                                                        |
| 25 | + <td><?php echo $invoice->get_status(true); ?></td>  | 
                                                        |
| 26 | 26 | </tr>  | 
                                                        
| 27 | -        <?php if ( $invoice->is_renewal() ) { ?> | 
                                                        |
| 27 | +        <?php if ($invoice->is_renewal()) { ?> | 
                                                        |
| 28 | 28 | <tr>  | 
                                                        
| 29 | - <td><?php echo apply_filters( 'wpinv_invoice_parent_invoice_label', __( 'Parent Invoice', 'invoicing' ), $invoice ); ?></td>  | 
                                                        |
| 30 | - <td><?php echo wpinv_invoice_link( $invoice->parent_invoice ); ?></td>  | 
                                                        |
| 29 | +            <td><?php echo apply_filters('wpinv_invoice_parent_invoice_label', __('Parent Invoice', 'invoicing'), $invoice); ?></td> | 
                                                        |
| 30 | + <td><?php echo wpinv_invoice_link($invoice->parent_invoice); ?></td>  | 
                                                        |
| 31 | 31 | </tr>  | 
                                                        
| 32 | 32 | <?php } ?>  | 
                                                        
| 33 | -        <?php if ( ( $gateway_title = $invoice->get_gateway_title() ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) { ?> | 
                                                        |
| 34 | - <td><?php echo apply_filters( 'wpinv_invoice_payment_method_label', __( 'Payment Method', 'invoicing' ), $invoice ); ?></td>  | 
                                                        |
| 33 | +        <?php if (($gateway_title = $invoice->get_gateway_title()) && ($invoice->is_paid() || $invoice->is_refunded())) { ?> | 
                                                        |
| 34 | +            <td><?php echo apply_filters('wpinv_invoice_payment_method_label', __('Payment Method', 'invoicing'), $invoice); ?></td> | 
                                                        |
| 35 | 35 | <td><?php echo $gateway_title; ?></td>  | 
                                                        
| 36 | 36 | <?php } ?>  | 
                                                        
| 37 | -        <?php if ( $invoice_date = $invoice->get_invoice_date( false ) ) { ?> | 
                                                        |
| 37 | +        <?php if ($invoice_date = $invoice->get_invoice_date(false)) { ?> | 
                                                        |
| 38 | 38 | <tr>  | 
                                                        
| 39 | - <td><?php echo apply_filters( 'wpinv_invoice_date_label', __( 'Invoice Date', 'invoicing' ), $invoice ); ?></td>  | 
                                                        |
| 40 | - <td><?php echo wp_sprintf( '<time datetime="%s">%s</time>', date_i18n( 'c', strtotime( $invoice_date ) ), $invoice->get_invoice_date() ); ?></td>  | 
                                                        |
| 39 | +                <td><?php echo apply_filters('wpinv_invoice_date_label', __('Invoice Date', 'invoicing'), $invoice); ?></td> | 
                                                        |
| 40 | +                <td><?php echo wp_sprintf('<time datetime="%s">%s</time>', date_i18n('c', strtotime($invoice_date)), $invoice->get_invoice_date()); ?></td> | 
                                                        |
| 41 | 41 | </tr>  | 
                                                        
| 42 | 42 | <?php } ?>  | 
                                                        
| 43 | -        <?php if ( wpinv_get_option( 'overdue_active' ) && $invoice->needs_payment() && ( $due_date = $invoice->get_due_date() ) ) { ?> | 
                                                        |
| 43 | +        <?php if (wpinv_get_option('overdue_active') && $invoice->needs_payment() && ($due_date = $invoice->get_due_date())) { ?> | 
                                                        |
| 44 | 44 | <tr>  | 
                                                        
| 45 | - <td><?php echo apply_filters( 'wpinv_invoice_due_date_label', __( 'Due Date', 'invoicing' ), $invoice ); ?></td>  | 
                                                        |
| 46 | - <td><?php echo wp_sprintf( '<time datetime="%s">%s</time>', date_i18n( 'c', strtotime( $due_date ) ), $invoice->get_due_date( true ) ); ?></td>  | 
                                                        |
| 45 | +                <td><?php echo apply_filters('wpinv_invoice_due_date_label', __('Due Date', 'invoicing'), $invoice); ?></td> | 
                                                        |
| 46 | +                <td><?php echo wp_sprintf('<time datetime="%s">%s</time>', date_i18n('c', strtotime($due_date)), $invoice->get_due_date(true)); ?></td> | 
                                                        |
| 47 | 47 | </tr>  | 
                                                        
| 48 | 48 | <?php } ?>  | 
                                                        
| 49 | - <?php do_action( 'wpinv_email_invoice_details_after_due_date', $invoice->ID ); ?>  | 
                                                        |
| 50 | -        <?php if ( empty( $sent_to_admin ) && ( $owner_vat_number = $wpinv_euvat->get_vat_number() ) ) { ?> | 
                                                        |
| 49 | +        <?php do_action('wpinv_email_invoice_details_after_due_date', $invoice->ID); ?> | 
                                                        |
| 50 | +        <?php if (empty($sent_to_admin) && ($owner_vat_number = $wpinv_euvat->get_vat_number())) { ?> | 
                                                        |
| 51 | 51 | <tr>  | 
                                                        
| 52 | - <td><?php echo apply_filters( 'wpinv_invoice_owner_vat_number_label', wp_sprintf( __( 'Owner %s Number', 'invoicing' ), $vat_name ), $invoice, $vat_name ); ?></td>  | 
                                                        |
| 52 | +                <td><?php echo apply_filters('wpinv_invoice_owner_vat_number_label', wp_sprintf(__('Owner %s Number', 'invoicing'), $vat_name), $invoice, $vat_name); ?></td> | 
                                                        |
| 53 | 53 | <td><?php echo $owner_vat_number; ?></td>  | 
                                                        
| 54 | 54 | </tr>  | 
                                                        
| 55 | 55 | <?php } ?>  | 
                                                        
| 56 | -        <?php if ( $use_taxes && ( $user_vat_number = $invoice->vat_number ) ) { ?> | 
                                                        |
| 56 | +        <?php if ($use_taxes && ($user_vat_number = $invoice->vat_number)) { ?> | 
                                                        |
| 57 | 57 | <tr>  | 
                                                        
| 58 | - <td><?php echo apply_filters( 'wpinv_invoice_user_vat_number_label', wp_sprintf( __( 'Invoice %s Number', 'invoicing' ), $vat_name ), $invoice, $vat_name ); ?></td>  | 
                                                        |
| 58 | +                <td><?php echo apply_filters('wpinv_invoice_user_vat_number_label', wp_sprintf(__('Invoice %s Number', 'invoicing'), $vat_name), $invoice, $vat_name); ?></td> | 
                                                        |
| 59 | 59 | <td><?php echo $user_vat_number; ?></td>  | 
                                                        
| 60 | 60 | </tr>  | 
                                                        
| 61 | 61 | <?php } ?>  | 
                                                        
| 62 | 62 | <tr class="table-active">  | 
                                                        
| 63 | - <td><strong><?php _e( 'Total Amount', 'invoicing' ) ?></strong></td>  | 
                                                        |
| 64 | - <td><strong><?php echo $invoice->get_total( true ); ?></strong></td>  | 
                                                        |
| 63 | +            <td><strong><?php _e('Total Amount', 'invoicing') ?></strong></td> | 
                                                        |
| 64 | + <td><strong><?php echo $invoice->get_total(true); ?></strong></td>  | 
                                                        |
| 65 | 65 | </tr>  | 
                                                        
| 66 | 66 | </table>  | 
                                                        
| 67 | 67 | </div>  | 
                                                        
| 68 | -<?php do_action( 'wpinv_email_after_invoice_details', $invoice, $sent_to_admin ); ?>  | 
                                                        |
| 69 | 68 | \ No newline at end of file  | 
                                                        
| 69 | +<?php do_action('wpinv_email_after_invoice_details', $invoice, $sent_to_admin); ?> | 
                                                        |
| 70 | 70 | \ No newline at end of file  | 
                                                        
@@ -1,156 +1,156 @@ discard block  | 
                                                    ||
| 1 | 1 | <?php  | 
                                                        
| 2 | 2 | |
| 3 | -function wpinv_is_subscription_payment( $invoice = '' ) { | 
                                                        |
| 4 | -    if ( empty( $invoice ) ) { | 
                                                        |
| 3 | +function wpinv_is_subscription_payment($invoice = '') { | 
                                                        |
| 4 | +    if (empty($invoice)) { | 
                                                        |
| 5 | 5 | return false;  | 
                                                        
| 6 | 6 | }  | 
                                                        
| 7 | 7 | |
| 8 | -    if ( !is_object( $invoice ) && is_scalar( $invoice ) ) { | 
                                                        |
| 9 | - $invoice = wpinv_get_invoice( $invoice );  | 
                                                        |
| 8 | +    if (!is_object($invoice) && is_scalar($invoice)) { | 
                                                        |
| 9 | + $invoice = wpinv_get_invoice($invoice);  | 
                                                        |
| 10 | 10 | }  | 
                                                        
| 11 | 11 | |
| 12 | -    if ( empty( $invoice ) ) { | 
                                                        |
| 12 | +    if (empty($invoice)) { | 
                                                        |
| 13 | 13 | return false;  | 
                                                        
| 14 | 14 | }  | 
                                                        
| 15 | 15 | |
| 16 | -    if ( $invoice->is_renewal() ) { | 
                                                        |
| 16 | +    if ($invoice->is_renewal()) { | 
                                                        |
| 17 | 17 | return true;  | 
                                                        
| 18 | 18 | }  | 
                                                        
| 19 | 19 | |
| 20 | 20 | return false;  | 
                                                        
| 21 | 21 | }  | 
                                                        
| 22 | 22 | |
| 23 | -function wpinv_payment_link_transaction_id( $invoice = '' ) { | 
                                                        |
| 24 | -    if ( empty( $invoice ) ) { | 
                                                        |
| 23 | +function wpinv_payment_link_transaction_id($invoice = '') { | 
                                                        |
| 24 | +    if (empty($invoice)) { | 
                                                        |
| 25 | 25 | return false;  | 
                                                        
| 26 | 26 | }  | 
                                                        
| 27 | 27 | |
| 28 | -    if ( !is_object( $invoice ) && is_scalar( $invoice ) ) { | 
                                                        |
| 29 | - $invoice = wpinv_get_invoice( $invoice );  | 
                                                        |
| 28 | +    if (!is_object($invoice) && is_scalar($invoice)) { | 
                                                        |
| 29 | + $invoice = wpinv_get_invoice($invoice);  | 
                                                        |
| 30 | 30 | }  | 
                                                        
| 31 | 31 | |
| 32 | -    if ( empty( $invoice ) ) { | 
                                                        |
| 32 | +    if (empty($invoice)) { | 
                                                        |
| 33 | 33 | return false;  | 
                                                        
| 34 | 34 | }  | 
                                                        
| 35 | 35 | |
| 36 | - return apply_filters( 'wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice );  | 
                                                        |
| 36 | +    return apply_filters('wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice); | 
                                                        |
| 37 | 37 | }  | 
                                                        
| 38 | 38 | |
| 39 | -function wpinv_subscription_initial_payment_desc( $amount, $period, $interval, $trial_period = '', $trial_interval = 0 ) { | 
                                                        |
| 39 | +function wpinv_subscription_initial_payment_desc($amount, $period, $interval, $trial_period = '', $trial_interval = 0) { | 
                                                        |
| 40 | 40 | $interval = (int)$interval > 0 ? (int)$interval : 1;  | 
                                                        
| 41 | 41 | |
| 42 | -    if ( $trial_interval > 0 && !empty( $trial_period ) ) { | 
                                                        |
| 43 | - $amount = __( 'Free', 'invoicing' );  | 
                                                        |
| 42 | +    if ($trial_interval > 0 && !empty($trial_period)) { | 
                                                        |
| 43 | +        $amount = __('Free', 'invoicing'); | 
                                                        |
| 44 | 44 | $interval = $trial_interval;  | 
                                                        
| 45 | 45 | $period = $trial_period;  | 
                                                        
| 46 | 46 | }  | 
                                                        
| 47 | 47 | |
| 48 | 48 | $description = '';  | 
                                                        
| 49 | -    switch ( $period ) { | 
                                                        |
| 49 | +    switch ($period) { | 
                                                        |
| 50 | 50 | case 'D' :  | 
                                                        
| 51 | 51 | case 'day' :  | 
                                                        
| 52 | - $description = wp_sprintf( _n( '%s for the first day.', '%s for the first %d days.', $interval, 'invoicing' ), $amount, $interval );  | 
                                                        |
| 52 | +            $description = wp_sprintf(_n('%s for the first day.', '%s for the first %d days.', $interval, 'invoicing'), $amount, $interval); | 
                                                        |
| 53 | 53 | break;  | 
                                                        
| 54 | 54 | case 'W' :  | 
                                                        
| 55 | 55 | case 'week' :  | 
                                                        
| 56 | - $description = wp_sprintf( _n( '%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing' ), $amount, $interval );  | 
                                                        |
| 56 | +            $description = wp_sprintf(_n('%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing'), $amount, $interval); | 
                                                        |
| 57 | 57 | break;  | 
                                                        
| 58 | 58 | case 'M' :  | 
                                                        
| 59 | 59 | case 'month' :  | 
                                                        
| 60 | - $description = wp_sprintf( _n( '%s for the first month.', '%s for the first %d months.', $interval, 'invoicing' ), $amount, $interval );  | 
                                                        |
| 60 | +            $description = wp_sprintf(_n('%s for the first month.', '%s for the first %d months.', $interval, 'invoicing'), $amount, $interval); | 
                                                        |
| 61 | 61 | break;  | 
                                                        
| 62 | 62 | case 'Y' :  | 
                                                        
| 63 | 63 | case 'year' :  | 
                                                        
| 64 | - $description = wp_sprintf( _n( '%s for the first year.', '%s for the first %d years.', $interval, 'invoicing' ), $amount, $interval );  | 
                                                        |
| 64 | +            $description = wp_sprintf(_n('%s for the first year.', '%s for the first %d years.', $interval, 'invoicing'), $amount, $interval); | 
                                                        |
| 65 | 65 | break;  | 
                                                        
| 66 | 66 | }  | 
                                                        
| 67 | 67 | |
| 68 | - return apply_filters( 'wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval );  | 
                                                        |
| 68 | +    return apply_filters('wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval); | 
                                                        |
| 69 | 69 | }  | 
                                                        
| 70 | 70 | |
| 71 | -function wpinv_subscription_recurring_payment_desc( $amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0 ) { | 
                                                        |
| 71 | +function wpinv_subscription_recurring_payment_desc($amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0) { | 
                                                        |
| 72 | 72 | $interval = (int)$interval > 0 ? (int)$interval : 1;  | 
                                                        
| 73 | 73 | $bill_times = (int)$bill_times > 0 ? (int)$bill_times : 0;  | 
                                                        
| 74 | 74 | |
| 75 | 75 | $description = '';  | 
                                                        
| 76 | -    switch ( $period ) { | 
                                                        |
| 76 | +    switch ($period) { | 
                                                        |
| 77 | 77 | case 'D' :  | 
                                                        
| 78 | 78 | case 'day' :  | 
                                                        
| 79 | -            if ( (int)$bill_times > 0 ) { | 
                                                        |
| 80 | -                if ( $interval > 1 ) { | 
                                                        |
| 81 | -                    if ( $bill_times > 1 ) { | 
                                                        |
| 82 | - $description = wp_sprintf( __( '%s for each %d days, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );  | 
                                                        |
| 79 | +            if ((int)$bill_times > 0) { | 
                                                        |
| 80 | +                if ($interval > 1) { | 
                                                        |
| 81 | +                    if ($bill_times > 1) { | 
                                                        |
| 82 | +                        $description = wp_sprintf(__('%s for each %d days, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); | 
                                                        |
| 83 | 83 |                      } else { | 
                                                        
| 84 | - $description = wp_sprintf( __( '%s for %d days.', 'invoicing' ), $amount, $interval );  | 
                                                        |
| 84 | +                        $description = wp_sprintf(__('%s for %d days.', 'invoicing'), $amount, $interval); | 
                                                        |
| 85 | 85 | }  | 
                                                        
| 86 | 86 |                  } else { | 
                                                        
| 87 | - $description = wp_sprintf( _n( '%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );  | 
                                                        |
| 87 | +                    $description = wp_sprintf(_n('%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); | 
                                                        |
| 88 | 88 | }  | 
                                                        
| 89 | 89 |              } else { | 
                                                        
| 90 | - $description = wp_sprintf( _n( '%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval );  | 
                                                        |
| 90 | +                $description = wp_sprintf(_n('%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval); | 
                                                        |
| 91 | 91 | }  | 
                                                        
| 92 | 92 | break;  | 
                                                        
| 93 | 93 | case 'W' :  | 
                                                        
| 94 | 94 | case 'week' :  | 
                                                        
| 95 | -            if ( (int)$bill_times > 0 ) { | 
                                                        |
| 96 | -                if ( $interval > 1 ) { | 
                                                        |
| 97 | -                    if ( $bill_times > 1 ) { | 
                                                        |
| 98 | - $description = wp_sprintf( __( '%s for each %d weeks, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );  | 
                                                        |
| 95 | +            if ((int)$bill_times > 0) { | 
                                                        |
| 96 | +                if ($interval > 1) { | 
                                                        |
| 97 | +                    if ($bill_times > 1) { | 
                                                        |
| 98 | +                        $description = wp_sprintf(__('%s for each %d weeks, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); | 
                                                        |
| 99 | 99 |                      } else { | 
                                                        
| 100 | - $description = wp_sprintf( __( '%s for %d weeks.', 'invoicing' ), $amount, $interval );  | 
                                                        |
| 100 | +                        $description = wp_sprintf(__('%s for %d weeks.', 'invoicing'), $amount, $interval); | 
                                                        |
| 101 | 101 | }  | 
                                                        
| 102 | 102 |                  } else { | 
                                                        
| 103 | - $description = wp_sprintf( _n( '%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );  | 
                                                        |
| 103 | +                    $description = wp_sprintf(_n('%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); | 
                                                        |
| 104 | 104 | }  | 
                                                        
| 105 | 105 |              } else { | 
                                                        
| 106 | - $description = wp_sprintf( _n( '%s for each week.', '%s for each %d weeks.', $interval, 'invoicing' ), $amount, $interval );  | 
                                                        |
| 106 | +                $description = wp_sprintf(_n('%s for each week.', '%s for each %d weeks.', $interval, 'invoicing'), $amount, $interval); | 
                                                        |
| 107 | 107 | }  | 
                                                        
| 108 | 108 | break;  | 
                                                        
| 109 | 109 | case 'M' :  | 
                                                        
| 110 | 110 | case 'month' :  | 
                                                        
| 111 | -            if ( (int)$bill_times > 0 ) { | 
                                                        |
| 112 | -                if ( $interval > 1 ) { | 
                                                        |
| 113 | -                    if ( $bill_times > 1 ) { | 
                                                        |
| 114 | - $description = wp_sprintf( __( '%s for each %d months, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );  | 
                                                        |
| 111 | +            if ((int)$bill_times > 0) { | 
                                                        |
| 112 | +                if ($interval > 1) { | 
                                                        |
| 113 | +                    if ($bill_times > 1) { | 
                                                        |
| 114 | +                        $description = wp_sprintf(__('%s for each %d months, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); | 
                                                        |
| 115 | 115 |                      } else { | 
                                                        
| 116 | - $description = wp_sprintf( __( '%s for %d months.', 'invoicing' ), $amount, $interval );  | 
                                                        |
| 116 | +                        $description = wp_sprintf(__('%s for %d months.', 'invoicing'), $amount, $interval); | 
                                                        |
| 117 | 117 | }  | 
                                                        
| 118 | 118 |                  } else { | 
                                                        
| 119 | - $description = wp_sprintf( _n( '%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );  | 
                                                        |
| 119 | +                    $description = wp_sprintf(_n('%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); | 
                                                        |
| 120 | 120 | }  | 
                                                        
| 121 | 121 |              } else { | 
                                                        
| 122 | - $description = wp_sprintf( _n( '%s for each month.', '%s for each %d months.', $interval, 'invoicing' ), $amount, $interval );  | 
                                                        |
| 122 | +                $description = wp_sprintf(_n('%s for each month.', '%s for each %d months.', $interval, 'invoicing'), $amount, $interval); | 
                                                        |
| 123 | 123 | }  | 
                                                        
| 124 | 124 | break;  | 
                                                        
| 125 | 125 | case 'Y' :  | 
                                                        
| 126 | 126 | case 'year' :  | 
                                                        
| 127 | -            if ( (int)$bill_times > 0 ) { | 
                                                        |
| 128 | -                if ( $interval > 1 ) { | 
                                                        |
| 129 | -                    if ( $bill_times > 1 ) { | 
                                                        |
| 130 | - $description = wp_sprintf( __( '%s for each %d years, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );  | 
                                                        |
| 127 | +            if ((int)$bill_times > 0) { | 
                                                        |
| 128 | +                if ($interval > 1) { | 
                                                        |
| 129 | +                    if ($bill_times > 1) { | 
                                                        |
| 130 | +                        $description = wp_sprintf(__('%s for each %d years, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); | 
                                                        |
| 131 | 131 |                      } else { | 
                                                        
| 132 | - $description = wp_sprintf( __( '%s for %d years.', 'invoicing'), $amount, $interval );  | 
                                                        |
| 132 | +                        $description = wp_sprintf(__('%s for %d years.', 'invoicing'), $amount, $interval); | 
                                                        |
| 133 | 133 | }  | 
                                                        
| 134 | 134 |                  } else { | 
                                                        
| 135 | - $description = wp_sprintf( _n( '%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );  | 
                                                        |
| 135 | +                    $description = wp_sprintf(_n('%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); | 
                                                        |
| 136 | 136 | }  | 
                                                        
| 137 | 137 |              } else { | 
                                                        
| 138 | - $description = wp_sprintf( _n( '%s for each year.', '%s for each %d years.', $interval, 'invoicing' ), $amount, $interval );  | 
                                                        |
| 138 | +                $description = wp_sprintf(_n('%s for each year.', '%s for each %d years.', $interval, 'invoicing'), $amount, $interval); | 
                                                        |
| 139 | 139 | }  | 
                                                        
| 140 | 140 | break;  | 
                                                        
| 141 | 141 | }  | 
                                                        
| 142 | 142 | |
| 143 | - return apply_filters( 'wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval );  | 
                                                        |
| 143 | +    return apply_filters('wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval); | 
                                                        |
| 144 | 144 | }  | 
                                                        
| 145 | 145 | |
| 146 | -function wpinv_subscription_payment_desc( $invoice ) { | 
                                                        |
| 147 | -    if ( empty( $invoice ) ) { | 
                                                        |
| 146 | +function wpinv_subscription_payment_desc($invoice) { | 
                                                        |
| 147 | +    if (empty($invoice)) { | 
                                                        |
| 148 | 148 | return NULL;  | 
                                                        
| 149 | 149 | }  | 
                                                        
| 150 | 150 | |
| 151 | 151 | $description = '';  | 
                                                        
| 152 | -    if ( $invoice->is_parent() && $item = $invoice->get_recurring( true ) ) { | 
                                                        |
| 153 | -        if ( $item->has_free_trial() ) { | 
                                                        |
| 152 | +    if ($invoice->is_parent() && $item = $invoice->get_recurring(true)) { | 
                                                        |
| 153 | +        if ($item->has_free_trial()) { | 
                                                        |
| 154 | 154 | $trial_period = $item->get_trial_period();  | 
                                                        
| 155 | 155 | $trial_interval = $item->get_trial_interval();  | 
                                                        
| 156 | 156 |          } else { | 
                                                        
@@ -158,45 +158,45 @@ discard block  | 
                                                    ||
| 158 | 158 | $trial_interval = 0;  | 
                                                        
| 159 | 159 | }  | 
                                                        
| 160 | 160 | |
| 161 | - $description = wpinv_get_billing_cycle( $invoice->get_total(), $invoice->get_recurring_details( 'total' ), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency() );  | 
                                                        |
| 161 | +        $description = wpinv_get_billing_cycle($invoice->get_total(), $invoice->get_recurring_details('total'), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency()); | 
                                                        |
| 162 | 162 | }  | 
                                                        
| 163 | 163 | |
| 164 | - return apply_filters( 'wpinv_subscription_payment_desc', $description, $invoice );  | 
                                                        |
| 164 | +    return apply_filters('wpinv_subscription_payment_desc', $description, $invoice); | 
                                                        |
| 165 | 165 | }  | 
                                                        
| 166 | 166 | |
| 167 | -function wpinv_get_billing_cycle( $initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '' ) { | 
                                                        |
| 168 | - $initial_total = wpinv_round_amount( $initial );  | 
                                                        |
| 169 | - $recurring_total = wpinv_round_amount( $recurring );  | 
                                                        |
| 167 | +function wpinv_get_billing_cycle($initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '') { | 
                                                        |
| 168 | + $initial_total = wpinv_round_amount($initial);  | 
                                                        |
| 169 | + $recurring_total = wpinv_round_amount($recurring);  | 
                                                        |
| 170 | 170 | |
| 171 | -    if ( $trial_interval > 0 && !empty( $trial_period ) ) { | 
                                                        |
| 171 | +    if ($trial_interval > 0 && !empty($trial_period)) { | 
                                                        |
| 172 | 172 | // Free trial  | 
                                                        
| 173 | 173 |      } else { | 
                                                        
| 174 | -        if ( $bill_times == 1 ) { | 
                                                        |
| 174 | +        if ($bill_times == 1) { | 
                                                        |
| 175 | 175 | $recurring_total = $initial_total;  | 
                                                        
| 176 | -        } else if ( $bill_times > 1 && $initial_total != $recurring_total ) { | 
                                                        |
| 176 | +        } else if ($bill_times > 1 && $initial_total != $recurring_total) { | 
                                                        |
| 177 | 177 | $bill_times--;  | 
                                                        
| 178 | 178 | }  | 
                                                        
| 179 | 179 | }  | 
                                                        
| 180 | 180 | |
| 181 | - $initial_amount = wpinv_price( wpinv_format_amount( $initial_total ), $currency );  | 
                                                        |
| 182 | - $recurring_amount = wpinv_price( wpinv_format_amount( $recurring_total ), $currency );  | 
                                                        |
| 181 | + $initial_amount = wpinv_price(wpinv_format_amount($initial_total), $currency);  | 
                                                        |
| 182 | + $recurring_amount = wpinv_price(wpinv_format_amount($recurring_total), $currency);  | 
                                                        |
| 183 | 183 | |
| 184 | - $recurring = wpinv_subscription_recurring_payment_desc( $recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval );  | 
                                                        |
| 184 | + $recurring = wpinv_subscription_recurring_payment_desc($recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval);  | 
                                                        |
| 185 | 185 | |
| 186 | -    if ( $initial_total != $recurring_total ) { | 
                                                        |
| 187 | - $initial = wpinv_subscription_initial_payment_desc( $initial_amount, $period, $interval, $trial_period, $trial_interval );  | 
                                                        |
| 186 | +    if ($initial_total != $recurring_total) { | 
                                                        |
| 187 | + $initial = wpinv_subscription_initial_payment_desc($initial_amount, $period, $interval, $trial_period, $trial_interval);  | 
                                                        |
| 188 | 188 | |
| 189 | - $description = wp_sprintf( __( '%s Then %s', 'invoicing' ), $initial, $recurring );  | 
                                                        |
| 189 | +        $description    = wp_sprintf(__('%s Then %s', 'invoicing'), $initial, $recurring); | 
                                                        |
| 190 | 190 |      } else { | 
                                                        
| 191 | 191 | $description = $recurring;  | 
                                                        
| 192 | 192 | }  | 
                                                        
| 193 | 193 | |
| 194 | - return apply_filters( 'wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency );  | 
                                                        |
| 194 | +    return apply_filters('wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency); | 
                                                        |
| 195 | 195 | }  | 
                                                        
| 196 | 196 | |
| 197 | -function wpinv_recurring_send_payment_failed( $invoice ) { | 
                                                        |
| 198 | -    if ( !empty( $invoice->ID ) ) { | 
                                                        |
| 199 | - wpinv_failed_invoice_notification( $invoice->ID );  | 
                                                        |
| 197 | +function wpinv_recurring_send_payment_failed($invoice) { | 
                                                        |
| 198 | +    if (!empty($invoice->ID)) { | 
                                                        |
| 199 | + wpinv_failed_invoice_notification($invoice->ID);  | 
                                                        |
| 200 | 200 | }  | 
                                                        
| 201 | 201 | }  | 
                                                        
| 202 | -add_action( 'wpinv_recurring_payment_failed', 'wpinv_recurring_send_payment_failed', 10, 1 );  | 
                                                        |
| 203 | 202 | \ No newline at end of file  | 
                                                        
| 203 | +add_action('wpinv_recurring_payment_failed', 'wpinv_recurring_send_payment_failed', 10, 1); | 
                                                        |
| 204 | 204 | \ No newline at end of file  |