Passed
Pull Request — master (#345)
by Brian
121:27
created
includes/wpinv-invoice-functions.php 1 patch
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -700,7 +700,7 @@  discard block
 block discarded – undo
700 700
 }
701 701
 
702 702
 function wpinv_get_payment_key( $invoice_id = 0 ) {
703
-	$invoice = new WPInv_Invoice( $invoice_id );
703
+    $invoice = new WPInv_Invoice( $invoice_id );
704 704
     return $invoice->get_key();
705 705
 }
706 706
 
@@ -966,7 +966,7 @@  discard block
 block discarded – undo
966 966
         return false;
967 967
     }
968 968
     $invoice = wpinv_get_invoice_cart();
969
-	if ( empty( $invoice ) ) {
969
+    if ( empty( $invoice ) ) {
970 970
         return false;
971 971
     }
972 972
 
@@ -1259,20 +1259,20 @@  discard block
 block discarded – undo
1259 1259
 }
1260 1260
 
1261 1261
 function wpinv_checkout_get_cc_info() {
1262
-	$cc_info = array();
1263
-	$cc_info['card_name']      = isset( $_POST['card_name'] )       ? sanitize_text_field( $_POST['card_name'] )       : '';
1264
-	$cc_info['card_number']    = isset( $_POST['card_number'] )     ? sanitize_text_field( $_POST['card_number'] )     : '';
1265
-	$cc_info['card_cvc']       = isset( $_POST['card_cvc'] )        ? sanitize_text_field( $_POST['card_cvc'] )        : '';
1266
-	$cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] )  ? sanitize_text_field( $_POST['card_exp_month'] )  : '';
1267
-	$cc_info['card_exp_year']  = isset( $_POST['card_exp_year'] )   ? sanitize_text_field( $_POST['card_exp_year'] )   : '';
1268
-	$cc_info['card_address']   = isset( $_POST['wpinv_address'] )  ? sanitize_text_field( $_POST['wpinv_address'] ) : '';
1269
-	$cc_info['card_city']      = isset( $_POST['wpinv_city'] )     ? sanitize_text_field( $_POST['wpinv_city'] )    : '';
1270
-	$cc_info['card_state']     = isset( $_POST['wpinv_state'] )    ? sanitize_text_field( $_POST['wpinv_state'] )   : '';
1271
-	$cc_info['card_country']   = isset( $_POST['wpinv_country'] )  ? sanitize_text_field( $_POST['wpinv_country'] ) : '';
1272
-	$cc_info['card_zip']       = isset( $_POST['wpinv_zip'] )      ? sanitize_text_field( $_POST['wpinv_zip'] )     : '';
1273
-
1274
-	// Return cc info
1275
-	return $cc_info;
1262
+    $cc_info = array();
1263
+    $cc_info['card_name']      = isset( $_POST['card_name'] )       ? sanitize_text_field( $_POST['card_name'] )       : '';
1264
+    $cc_info['card_number']    = isset( $_POST['card_number'] )     ? sanitize_text_field( $_POST['card_number'] )     : '';
1265
+    $cc_info['card_cvc']       = isset( $_POST['card_cvc'] )        ? sanitize_text_field( $_POST['card_cvc'] )        : '';
1266
+    $cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] )  ? sanitize_text_field( $_POST['card_exp_month'] )  : '';
1267
+    $cc_info['card_exp_year']  = isset( $_POST['card_exp_year'] )   ? sanitize_text_field( $_POST['card_exp_year'] )   : '';
1268
+    $cc_info['card_address']   = isset( $_POST['wpinv_address'] )  ? sanitize_text_field( $_POST['wpinv_address'] ) : '';
1269
+    $cc_info['card_city']      = isset( $_POST['wpinv_city'] )     ? sanitize_text_field( $_POST['wpinv_city'] )    : '';
1270
+    $cc_info['card_state']     = isset( $_POST['wpinv_state'] )    ? sanitize_text_field( $_POST['wpinv_state'] )   : '';
1271
+    $cc_info['card_country']   = isset( $_POST['wpinv_country'] )  ? sanitize_text_field( $_POST['wpinv_country'] ) : '';
1272
+    $cc_info['card_zip']       = isset( $_POST['wpinv_zip'] )      ? sanitize_text_field( $_POST['wpinv_zip'] )     : '';
1273
+
1274
+    // Return cc info
1275
+    return $cc_info;
1276 1276
 }
1277 1277
 
1278 1278
 function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) {
@@ -1479,7 +1479,7 @@  discard block
 block discarded – undo
1479 1479
         $required_fields  = wpinv_checkout_required_fields();
1480 1480
 
1481 1481
         // Loop through required fields and show error messages
1482
-         if ( !empty( $required_fields ) ) {
1482
+            if ( !empty( $required_fields ) ) {
1483 1483
             foreach ( $required_fields as $field_name => $value ) {
1484 1484
                 if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) {
1485 1485
                     wpinv_set_error( $value['error_id'], $value['error_message'] );
@@ -1581,7 +1581,7 @@  discard block
 block discarded – undo
1581 1581
 }
1582 1582
 
1583 1583
 function wpinv_get_checkout_session() {
1584
-	global $wpi_session;
1584
+    global $wpi_session;
1585 1585
     return $wpi_session->get( 'wpinv_checkout' );
1586 1586
 }
1587 1587
 
@@ -1661,7 +1661,7 @@  discard block
 block discarded – undo
1661 1661
         $response['data']['taxf']       = $invoice->get_tax( true );
1662 1662
         $response['data']['total']      = $invoice->get_total();
1663 1663
         $response['data']['totalf']     = $invoice->get_total( true );
1664
-	    $response['data']['free']       = $invoice->is_free() && ( ! ( (float) $response['data']['total'] > 0 ) || $invoice->is_free_trial() ) ? true : false;
1664
+        $response['data']['free']       = $invoice->is_free() && ( ! ( (float) $response['data']['total'] > 0 ) || $invoice->is_free_trial() ) ? true : false;
1665 1665
 
1666 1666
         wp_send_json( $response );
1667 1667
     }
@@ -1731,8 +1731,8 @@  discard block
 block discarded – undo
1731 1731
     // Allow themes and plugins to hook before the gateway
1732 1732
     do_action( 'wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data );
1733 1733
 
1734
-     // If it is free, abort.
1735
-     if ( $invoice->is_free() && ( ! $invoice->is_recurring() || 0 ==  $invoice->get_recurring_details( 'total' ) ) ) {
1734
+        // If it is free, abort.
1735
+        if ( $invoice->is_free() && ( ! $invoice->is_recurring() || 0 ==  $invoice->get_recurring_details( 'total' ) ) ) {
1736 1736
         $invoice_data['gateway'] = 'manual';
1737 1737
         $_POST['wpi-gateway'] = 'manual';
1738 1738
     }
@@ -1948,52 +1948,52 @@  discard block
 block discarded – undo
1948 1948
  * Given an invoice key, this function returns the id.
1949 1949
  */
1950 1950
 function wpinv_get_invoice_id_by_key( $key ) {
1951
-	global $wpdb;
1951
+    global $wpdb;
1952 1952
     $table      = $wpdb->prefix . 'getpaid_invoices';
1953
-	return (int) $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $table WHERE`key` = %s LIMIT 1", $key ) );
1953
+    return (int) $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $table WHERE`key` = %s LIMIT 1", $key ) );
1954 1954
 }
1955 1955
 
1956 1956
 function wpinv_can_view_receipt( $invoice_key = '' ) {
1957
-	$return = current_user_can( 'manage_options' );
1957
+    $return = current_user_can( 'manage_options' );
1958 1958
 
1959
-	if ( empty( $invoice_key ) ) {
1960
-		return false;
1961
-	}
1959
+    if ( empty( $invoice_key ) ) {
1960
+        return false;
1961
+    }
1962 1962
 
1963
-	global $wpinv_receipt_args;
1963
+    global $wpinv_receipt_args;
1964 1964
 
1965
-	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key );
1966
-	if ( isset( $_GET['invoice-id'] ) ) {
1967
-		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0;
1968
-	}
1965
+    $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key );
1966
+    if ( isset( $_GET['invoice-id'] ) ) {
1967
+        $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0;
1968
+    }
1969 1969
 
1970
-	if ( empty( $wpinv_receipt_args['id'] ) ) {
1971
-		return $return;
1972
-	}
1970
+    if ( empty( $wpinv_receipt_args['id'] ) ) {
1971
+        return $return;
1972
+    }
1973 1973
 
1974
-	$invoice = wpinv_get_invoice( $wpinv_receipt_args['id'] );
1975
-	if ( !( !empty( $invoice->ID ) && $invoice->get_key() === $invoice_key ) ) {
1976
-		return $return;
1977
-	}
1974
+    $invoice = wpinv_get_invoice( $wpinv_receipt_args['id'] );
1975
+    if ( !( !empty( $invoice->ID ) && $invoice->get_key() === $invoice_key ) ) {
1976
+        return $return;
1977
+    }
1978 1978
 
1979
-	if ( is_user_logged_in() ) {
1980
-		if ( (int)$invoice->get_user_id() === (int) get_current_user_id() ) {
1981
-			$return = true;
1982
-		}
1983
-	}
1979
+    if ( is_user_logged_in() ) {
1980
+        if ( (int)$invoice->get_user_id() === (int) get_current_user_id() ) {
1981
+            $return = true;
1982
+        }
1983
+    }
1984 1984
 
1985
-	$session = wpinv_get_checkout_session();
1986
-	if ( isset( $_GET['invoice_key'] ) || ( $session && isset( $session['invoice_key'] ) ) ) {
1987
-		$check_key = isset( $_GET['invoice_key'] ) ? $_GET['invoice_key'] : $session['invoice_key'];
1985
+    $session = wpinv_get_checkout_session();
1986
+    if ( isset( $_GET['invoice_key'] ) || ( $session && isset( $session['invoice_key'] ) ) ) {
1987
+        $check_key = isset( $_GET['invoice_key'] ) ? $_GET['invoice_key'] : $session['invoice_key'];
1988 1988
 
1989
-		if ( wpinv_require_login_to_checkout() ) {
1990
-			$return = $return && $check_key == $invoice_key;
1991
-		} else {
1992
-			$return = $check_key == $invoice_key;
1993
-		}
1994
-	}
1989
+        if ( wpinv_require_login_to_checkout() ) {
1990
+            $return = $return && $check_key == $invoice_key;
1991
+        } else {
1992
+            $return = $check_key == $invoice_key;
1993
+        }
1994
+    }
1995 1995
 
1996
-	return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key );
1996
+    return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key );
1997 1997
 }
1998 1998
 
1999 1999
 function wpinv_pay_for_invoice() {
@@ -2303,14 +2303,14 @@  discard block
 block discarded – undo
2303 2303
 
2304 2304
     if ( isset( $_GET['invoice_key'] ) || is_singular( 'wpi_invoice' ) || is_singular( 'wpi_quote' ) ) {
2305 2305
         $invoice_key = isset( $_GET['invoice_key'] ) ? urldecode($_GET['invoice_key']) : '';
2306
-	    global $post;
2306
+        global $post;
2307 2307
 
2308 2308
         if(!empty($invoice_key)){
2309
-	        $invoice_id = wpinv_get_invoice_id_by_key($invoice_key);
2309
+            $invoice_id = wpinv_get_invoice_id_by_key($invoice_key);
2310 2310
         } else if(!empty( $post ) && ($post->post_type == 'wpi_invoice' || $post->post_type == 'wpi_quote')) {
2311
-			$invoice_id = $post->ID;
2311
+            $invoice_id = $post->ID;
2312 2312
         } else {
2313
-        	return;
2313
+            return;
2314 2314
         }
2315 2315
 
2316 2316
         $invoice = new WPInv_Invoice($invoice_id);
@@ -2319,17 +2319,17 @@  discard block
 block discarded – undo
2319 2319
             return;
2320 2320
         }
2321 2321
 
2322
-	    if ( is_user_logged_in() ) {
2323
-		    if ( (int)$invoice->get_user_id() === get_current_user_id() ) {
2324
-			    update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2325
-		    } else if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2326
-			    update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2327
-		    }
2328
-	    } else {
2329
-		    if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2330
-			    update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2331
-		    }
2332
-	    }
2322
+        if ( is_user_logged_in() ) {
2323
+            if ( (int)$invoice->get_user_id() === get_current_user_id() ) {
2324
+                update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2325
+            } else if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2326
+                update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2327
+            }
2328
+        } else {
2329
+            if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2330
+                update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2331
+            }
2332
+        }
2333 2333
     }
2334 2334
 
2335 2335
 }
Please login to merge, or discard this patch.
includes/class-wpinv-session-handler.php 1 patch
Indentation   +268 added lines, -268 removed lines patch added patch discarded remove patch
@@ -12,125 +12,125 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class WPInv_Session_Handler extends WPInv_Session {
14 14
 
15
-	/**
16
-	 * Cookie name used for the session.
17
-	 *
18
-	 * @var string cookie name
19
-	 */
20
-	protected $_cookie;
21
-
22
-	/**
23
-	 * Stores session expiry.
24
-	 *
25
-	 * @var int session due to expire timestamp
26
-	 */
27
-	protected $_session_expiring;
28
-
29
-	/**
30
-	 * Stores session due to expire timestamp.
31
-	 *
32
-	 * @var string session expiration timestamp
33
-	 */
34
-	protected $_session_expiration;
35
-
36
-	/**
37
-	 * True when the cookie exists.
38
-	 *
39
-	 * @var bool Based on whether a cookie exists.
40
-	 */
41
-	protected $_has_cookie = false;
42
-
43
-	/**
44
-	 * Table name for session data.
45
-	 *
46
-	 * @var string Custom session table name
47
-	 */
48
-	protected $_table;
49
-
50
-	/**
51
-	 * Constructor for the session class.
52
-	 */
53
-	public function __construct() {
54
-
55
-	    $this->_cookie = apply_filters( 'wpinv_cookie', 'wpinv_session_' . COOKIEHASH );
15
+    /**
16
+     * Cookie name used for the session.
17
+     *
18
+     * @var string cookie name
19
+     */
20
+    protected $_cookie;
21
+
22
+    /**
23
+     * Stores session expiry.
24
+     *
25
+     * @var int session due to expire timestamp
26
+     */
27
+    protected $_session_expiring;
28
+
29
+    /**
30
+     * Stores session due to expire timestamp.
31
+     *
32
+     * @var string session expiration timestamp
33
+     */
34
+    protected $_session_expiration;
35
+
36
+    /**
37
+     * True when the cookie exists.
38
+     *
39
+     * @var bool Based on whether a cookie exists.
40
+     */
41
+    protected $_has_cookie = false;
42
+
43
+    /**
44
+     * Table name for session data.
45
+     *
46
+     * @var string Custom session table name
47
+     */
48
+    protected $_table;
49
+
50
+    /**
51
+     * Constructor for the session class.
52
+     */
53
+    public function __construct() {
54
+
55
+        $this->_cookie = apply_filters( 'wpinv_cookie', 'wpinv_session_' . COOKIEHASH );
56 56
         add_action( 'init', array( $this, 'init' ), -1 );
57
-		add_action( 'wp_logout', array( $this, 'destroy_session' ) );
58
-		add_action( 'wp', array( $this, 'set_customer_session_cookie' ), 10 );
59
-		add_action( 'shutdown', array( $this, 'save_data' ), 20 );
60
-
61
-	}
62
-
63
-	/**
64
-	 * Init hooks and session data.
65
-	 *
66
-	 * @since 3.3.0
67
-	 */
68
-	public function init() {
69
-		$this->init_session_cookie();
70
-
71
-		if ( ! is_user_logged_in() ) {
72
-			add_filter( 'nonce_user_logged_out', array( $this, 'nonce_user_logged_out' ) );
73
-		}
74
-	}
75
-
76
-	/**
77
-	 * Setup cookie and customer ID.
78
-	 *
79
-	 * @since 3.6.0
80
-	 */
81
-	public function init_session_cookie() {
82
-		$cookie = $this->get_session_cookie();
83
-
84
-		if ( $cookie ) {
85
-			$this->_customer_id        = $cookie[0];
86
-			$this->_session_expiration = $cookie[1];
87
-			$this->_session_expiring   = $cookie[2];
88
-			$this->_has_cookie         = true;
89
-			$this->_data               = $this->get_session_data();
90
-
91
-			// If the user logs in, update session.
92
-			if ( is_user_logged_in() && get_current_user_id() != $this->_customer_id ) {
93
-				$this->_customer_id = get_current_user_id();
94
-				$this->_dirty       = true;
95
-				$this->save_data();
96
-				$this->set_customer_session_cookie( true );
97
-			}
98
-
99
-			// Update session if its close to expiring.
100
-			if ( time() > $this->_session_expiring ) {
101
-				$this->set_session_expiration();
102
-				$this->update_session_timestamp( $this->_customer_id, $this->_session_expiration );
103
-			}
104
-		} else {
105
-			$this->set_session_expiration();
106
-			$this->_customer_id = $this->generate_customer_id();
107
-			$this->_data        = $this->get_session_data();
108
-		}
109
-	}
110
-
111
-	/**
112
-	 * Sets the session cookie on-demand (usually after adding an item to the cart).
113
-	 *
114
-	 * Since the cookie name (as of 2.1) is prepended with wp, cache systems like batcache will not cache pages when set.
115
-	 *
116
-	 * Warning: Cookies will only be set if this is called before the headers are sent.
117
-	 *
118
-	 * @param bool $set Should the session cookie be set.
119
-	 */
120
-	public function set_customer_session_cookie( $set ) {
121
-		if ( $set ) {
122
-			$to_hash           = $this->_customer_id . '|' . $this->_session_expiration;
123
-			$cookie_hash       = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) );
124
-			$cookie_value      = $this->_customer_id . '||' . $this->_session_expiration . '||' . $this->_session_expiring . '||' . $cookie_hash;
125
-			$this->_has_cookie = true;
126
-
127
-			if ( ! isset( $_COOKIE[ $this->_cookie ] ) || $_COOKIE[ $this->_cookie ] !== $cookie_value ) {
128
-				$this->setcookie( $this->_cookie, $cookie_value, $this->_session_expiration, $this->use_secure_cookie(), true );
129
-			}
130
-		}
131
-	}
132
-
133
-	public function setcookie($name, $value, $expire = 0, $secure = false, $httponly = false){
57
+        add_action( 'wp_logout', array( $this, 'destroy_session' ) );
58
+        add_action( 'wp', array( $this, 'set_customer_session_cookie' ), 10 );
59
+        add_action( 'shutdown', array( $this, 'save_data' ), 20 );
60
+
61
+    }
62
+
63
+    /**
64
+     * Init hooks and session data.
65
+     *
66
+     * @since 3.3.0
67
+     */
68
+    public function init() {
69
+        $this->init_session_cookie();
70
+
71
+        if ( ! is_user_logged_in() ) {
72
+            add_filter( 'nonce_user_logged_out', array( $this, 'nonce_user_logged_out' ) );
73
+        }
74
+    }
75
+
76
+    /**
77
+     * Setup cookie and customer ID.
78
+     *
79
+     * @since 3.6.0
80
+     */
81
+    public function init_session_cookie() {
82
+        $cookie = $this->get_session_cookie();
83
+
84
+        if ( $cookie ) {
85
+            $this->_customer_id        = $cookie[0];
86
+            $this->_session_expiration = $cookie[1];
87
+            $this->_session_expiring   = $cookie[2];
88
+            $this->_has_cookie         = true;
89
+            $this->_data               = $this->get_session_data();
90
+
91
+            // If the user logs in, update session.
92
+            if ( is_user_logged_in() && get_current_user_id() != $this->_customer_id ) {
93
+                $this->_customer_id = get_current_user_id();
94
+                $this->_dirty       = true;
95
+                $this->save_data();
96
+                $this->set_customer_session_cookie( true );
97
+            }
98
+
99
+            // Update session if its close to expiring.
100
+            if ( time() > $this->_session_expiring ) {
101
+                $this->set_session_expiration();
102
+                $this->update_session_timestamp( $this->_customer_id, $this->_session_expiration );
103
+            }
104
+        } else {
105
+            $this->set_session_expiration();
106
+            $this->_customer_id = $this->generate_customer_id();
107
+            $this->_data        = $this->get_session_data();
108
+        }
109
+    }
110
+
111
+    /**
112
+     * Sets the session cookie on-demand (usually after adding an item to the cart).
113
+     *
114
+     * Since the cookie name (as of 2.1) is prepended with wp, cache systems like batcache will not cache pages when set.
115
+     *
116
+     * Warning: Cookies will only be set if this is called before the headers are sent.
117
+     *
118
+     * @param bool $set Should the session cookie be set.
119
+     */
120
+    public function set_customer_session_cookie( $set ) {
121
+        if ( $set ) {
122
+            $to_hash           = $this->_customer_id . '|' . $this->_session_expiration;
123
+            $cookie_hash       = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) );
124
+            $cookie_value      = $this->_customer_id . '||' . $this->_session_expiration . '||' . $this->_session_expiring . '||' . $cookie_hash;
125
+            $this->_has_cookie = true;
126
+
127
+            if ( ! isset( $_COOKIE[ $this->_cookie ] ) || $_COOKIE[ $this->_cookie ] !== $cookie_value ) {
128
+                $this->setcookie( $this->_cookie, $cookie_value, $this->_session_expiration, $this->use_secure_cookie(), true );
129
+            }
130
+        }
131
+    }
132
+
133
+    public function setcookie($name, $value, $expire = 0, $secure = false, $httponly = false){
134 134
         if ( ! headers_sent() ) {
135 135
             setcookie( $name, $value, $expire, COOKIEPATH ? COOKIEPATH : '/', COOKIE_DOMAIN, $secure, apply_filters( 'wpinv_cookie_httponly', $httponly, $name, $value, $expire, $secure ) );
136 136
         } elseif ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
@@ -139,86 +139,86 @@  discard block
 block discarded – undo
139 139
         }
140 140
     }
141 141
 
142
-	/**
143
-	 * Should the session cookie be secure?
144
-	 *
145
-	 * @since 3.6.0
146
-	 * @return bool
147
-	 */
148
-	protected function use_secure_cookie() {
142
+    /**
143
+     * Should the session cookie be secure?
144
+     *
145
+     * @since 3.6.0
146
+     * @return bool
147
+     */
148
+    protected function use_secure_cookie() {
149 149
         $is_https = false !== strstr( get_option( 'home' ), 'https:' );
150
-		return apply_filters( 'wpinv_session_use_secure_cookie', $is_https && is_ssl() );
151
-	}
152
-
153
-	/**
154
-	 * Return true if the current user has an active session, i.e. a cookie to retrieve values.
155
-	 *
156
-	 * @return bool
157
-	 */
158
-	public function has_session() {
159
-		return isset( $_COOKIE[ $this->_cookie ] ) || $this->_has_cookie || is_user_logged_in(); // @codingStandardsIgnoreLine.
160
-	}
161
-
162
-	/**
163
-	 * Set session expiration.
164
-	 */
165
-	public function set_session_expiration() {
166
-		$this->_session_expiring   = time() + intval( apply_filters( 'wpinv_session_expiring', 60 * 60 * 47 ) ); // 47 Hours.
167
-		$this->_session_expiration = time() + intval( apply_filters( 'wpinv_session_expiration', 60 * 60 * 48 ) ); // 48 Hours.
168
-	}
169
-
170
-	/**
171
-	 * Generates session ids.
172
-	 *
173
-	 * @return string
174
-	 */
175
-	public function generate_customer_id() {
176
-		require_once ABSPATH . 'wp-includes/class-phpass.php';
177
-		$hasher      = new PasswordHash( 8, false );
178
-		return md5( $hasher->get_random_bytes( 32 ) );
179
-	}
180
-
181
-	/**
182
-	 * Get the session cookie, if set. Otherwise return false.
183
-	 *
184
-	 * Session cookies without a customer ID are invalid.
185
-	 *
186
-	 * @return bool|array
187
-	 */
188
-	public function get_session_cookie() {
189
-		$cookie_value = isset( $_COOKIE[ $this->_cookie ] ) ? wp_unslash( $_COOKIE[ $this->_cookie ] ) : false; // @codingStandardsIgnoreLine.
190
-
191
-		if ( empty( $cookie_value ) || ! is_string( $cookie_value ) ) {
192
-			return false;
193
-		}
194
-
195
-		list( $customer_id, $session_expiration, $session_expiring, $cookie_hash ) = explode( '||', $cookie_value );
196
-
197
-		if ( empty( $customer_id ) ) {
198
-			return false;
199
-		}
200
-
201
-		// Validate hash.
202
-		$to_hash = $customer_id . '|' . $session_expiration;
203
-		$hash    = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) );
204
-
205
-		if ( empty( $cookie_hash ) || ! hash_equals( $hash, $cookie_hash ) ) {
206
-			return false;
207
-		}
208
-
209
-		return array( $customer_id, $session_expiration, $session_expiring, $cookie_hash );
210
-	}
211
-
212
-	/**
213
-	 * Get session data.
214
-	 *
215
-	 * @return array
216
-	 */
217
-	public function get_session_data() {
218
-		return $this->has_session() ? (array) $this->get_session( $this->_customer_id ) : array();
219
-	}
220
-
221
-	public function generate_key($customer_id){
150
+        return apply_filters( 'wpinv_session_use_secure_cookie', $is_https && is_ssl() );
151
+    }
152
+
153
+    /**
154
+     * Return true if the current user has an active session, i.e. a cookie to retrieve values.
155
+     *
156
+     * @return bool
157
+     */
158
+    public function has_session() {
159
+        return isset( $_COOKIE[ $this->_cookie ] ) || $this->_has_cookie || is_user_logged_in(); // @codingStandardsIgnoreLine.
160
+    }
161
+
162
+    /**
163
+     * Set session expiration.
164
+     */
165
+    public function set_session_expiration() {
166
+        $this->_session_expiring   = time() + intval( apply_filters( 'wpinv_session_expiring', 60 * 60 * 47 ) ); // 47 Hours.
167
+        $this->_session_expiration = time() + intval( apply_filters( 'wpinv_session_expiration', 60 * 60 * 48 ) ); // 48 Hours.
168
+    }
169
+
170
+    /**
171
+     * Generates session ids.
172
+     *
173
+     * @return string
174
+     */
175
+    public function generate_customer_id() {
176
+        require_once ABSPATH . 'wp-includes/class-phpass.php';
177
+        $hasher      = new PasswordHash( 8, false );
178
+        return md5( $hasher->get_random_bytes( 32 ) );
179
+    }
180
+
181
+    /**
182
+     * Get the session cookie, if set. Otherwise return false.
183
+     *
184
+     * Session cookies without a customer ID are invalid.
185
+     *
186
+     * @return bool|array
187
+     */
188
+    public function get_session_cookie() {
189
+        $cookie_value = isset( $_COOKIE[ $this->_cookie ] ) ? wp_unslash( $_COOKIE[ $this->_cookie ] ) : false; // @codingStandardsIgnoreLine.
190
+
191
+        if ( empty( $cookie_value ) || ! is_string( $cookie_value ) ) {
192
+            return false;
193
+        }
194
+
195
+        list( $customer_id, $session_expiration, $session_expiring, $cookie_hash ) = explode( '||', $cookie_value );
196
+
197
+        if ( empty( $customer_id ) ) {
198
+            return false;
199
+        }
200
+
201
+        // Validate hash.
202
+        $to_hash = $customer_id . '|' . $session_expiration;
203
+        $hash    = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) );
204
+
205
+        if ( empty( $cookie_hash ) || ! hash_equals( $hash, $cookie_hash ) ) {
206
+            return false;
207
+        }
208
+
209
+        return array( $customer_id, $session_expiration, $session_expiring, $cookie_hash );
210
+    }
211
+
212
+    /**
213
+     * Get session data.
214
+     *
215
+     * @return array
216
+     */
217
+    public function get_session_data() {
218
+        return $this->has_session() ? (array) $this->get_session( $this->_customer_id ) : array();
219
+    }
220
+
221
+    public function generate_key($customer_id){
222 222
         if(!$customer_id){
223 223
             return;
224 224
         }
@@ -226,62 +226,62 @@  discard block
 block discarded – undo
226 226
         return 'wpi_trans_'.$customer_id;
227 227
     }
228 228
 
229
-	/**
230
-	 * Save data.
231
-	 */
232
-	public function save_data() {
233
-		// Dirty if something changed - prevents saving nothing new.
234
-		if ( $this->_dirty && $this->has_session() ) {
229
+    /**
230
+     * Save data.
231
+     */
232
+    public function save_data() {
233
+        // Dirty if something changed - prevents saving nothing new.
234
+        if ( $this->_dirty && $this->has_session() ) {
235 235
 
236 236
             set_transient( $this->generate_key($this->_customer_id), $this->_data, $this->_session_expiration);
237 237
 
238
-			$this->_dirty = false;
239
-		}
240
-	}
241
-
242
-	/**
243
-	 * Destroy all session data.
244
-	 */
245
-	public function destroy_session() {
246
-		$this->delete_session( $this->_customer_id );
247
-		$this->forget_session();
248
-	}
249
-
250
-	/**
251
-	 * Forget all session data without destroying it.
252
-	 */
253
-	public function forget_session() {
254
-		$this->setcookie( $this->_cookie, '', time() - YEAR_IN_SECONDS, $this->use_secure_cookie(), true );
255
-
256
-		wpinv_empty_cart();
257
-
258
-		$this->_data        = array();
259
-		$this->_dirty       = false;
260
-		$this->_customer_id = $this->generate_customer_id();
261
-	}
262
-
263
-	/**
264
-	 * When a user is logged out, ensure they have a unique nonce by using the customer/session ID.
265
-	 *
266
-	 * @param int $uid User ID.
267
-	 * @return string
268
-	 */
269
-	public function nonce_user_logged_out( $uid ) {
270
-		return $this->has_session() && $this->_customer_id ? $this->_customer_id : $uid;
271
-	}
272
-
273
-	/**
274
-	 * Returns the session.
275
-	 *
276
-	 * @param string $customer_id Customer ID.
277
-	 * @param mixed  $default Default session value.
278
-	 * @return string|array
279
-	 */
280
-	public function get_session( $customer_id, $default = false ) {
281
-
282
-		if ( defined( 'WP_SETUP_CONFIG' ) ) {
283
-			return array();
284
-		}
238
+            $this->_dirty = false;
239
+        }
240
+    }
241
+
242
+    /**
243
+     * Destroy all session data.
244
+     */
245
+    public function destroy_session() {
246
+        $this->delete_session( $this->_customer_id );
247
+        $this->forget_session();
248
+    }
249
+
250
+    /**
251
+     * Forget all session data without destroying it.
252
+     */
253
+    public function forget_session() {
254
+        $this->setcookie( $this->_cookie, '', time() - YEAR_IN_SECONDS, $this->use_secure_cookie(), true );
255
+
256
+        wpinv_empty_cart();
257
+
258
+        $this->_data        = array();
259
+        $this->_dirty       = false;
260
+        $this->_customer_id = $this->generate_customer_id();
261
+    }
262
+
263
+    /**
264
+     * When a user is logged out, ensure they have a unique nonce by using the customer/session ID.
265
+     *
266
+     * @param int $uid User ID.
267
+     * @return string
268
+     */
269
+    public function nonce_user_logged_out( $uid ) {
270
+        return $this->has_session() && $this->_customer_id ? $this->_customer_id : $uid;
271
+    }
272
+
273
+    /**
274
+     * Returns the session.
275
+     *
276
+     * @param string $customer_id Customer ID.
277
+     * @param mixed  $default Default session value.
278
+     * @return string|array
279
+     */
280
+    public function get_session( $customer_id, $default = false ) {
281
+
282
+        if ( defined( 'WP_SETUP_CONFIG' ) ) {
283
+            return array();
284
+        }
285 285
 
286 286
         if ( !is_user_logged_in() ) {
287 287
             if(!wp_verify_nonce( $customer_id, 'wpinv-session-customer-id' )){
@@ -296,32 +296,32 @@  discard block
 block discarded – undo
296 296
             $value = $default;
297 297
         }
298 298
 
299
-		return maybe_unserialize( $value );
300
-	}
299
+        return maybe_unserialize( $value );
300
+    }
301 301
 
302
-	/**
303
-	 * Delete the session from the cache and database.
304
-	 *
305
-	 * @param int $customer_id Customer ID.
306
-	 */
307
-	public function delete_session( $customer_id ) {
302
+    /**
303
+     * Delete the session from the cache and database.
304
+     *
305
+     * @param int $customer_id Customer ID.
306
+     */
307
+    public function delete_session( $customer_id ) {
308 308
 
309 309
         $key = $this->generate_key($customer_id);
310 310
 
311
-		delete_transient($key);
312
-	}
311
+        delete_transient($key);
312
+    }
313 313
 
314
-	/**
315
-	 * Update the session expiry timestamp.
316
-	 *
317
-	 * @param string $customer_id Customer ID.
318
-	 * @param int    $timestamp Timestamp to expire the cookie.
319
-	 */
320
-	public function update_session_timestamp( $customer_id, $timestamp ) {
314
+    /**
315
+     * Update the session expiry timestamp.
316
+     *
317
+     * @param string $customer_id Customer ID.
318
+     * @param int    $timestamp Timestamp to expire the cookie.
319
+     */
320
+    public function update_session_timestamp( $customer_id, $timestamp ) {
321 321
 
322 322
         set_transient( $this->generate_key($customer_id), maybe_serialize( $this->_data ), $timestamp);
323 323
 
324
-	}
324
+    }
325 325
 }
326 326
 
327 327
 global $wpi_session;
Please login to merge, or discard this patch.