Edit File by line
/home/barbar84/www/wp-conte.../plugins/ninja-fo.../includes
File: Session.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* NF Session
[2] Fix | Delete
*
[3] Fix | Delete
* This is a wrapper class for WP_Session / PHP $_SESSION and handles the storage of cart items, purchase sessions, etc
[4] Fix | Delete
*
[5] Fix | Delete
* @package Ninja Forms
[6] Fix | Delete
* @subpackage Classes/Session
[7] Fix | Delete
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
[8] Fix | Delete
* @since 2.9.18
[9] Fix | Delete
*/
[10] Fix | Delete
// Exit if accessed directly
[11] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) exit;
[12] Fix | Delete
/**
[13] Fix | Delete
* NF_Session Class
[14] Fix | Delete
*
[15] Fix | Delete
* @since 1.5
[16] Fix | Delete
*/
[17] Fix | Delete
class NF_Session {
[18] Fix | Delete
/**
[19] Fix | Delete
* Holds our session data
[20] Fix | Delete
*
[21] Fix | Delete
* @var array
[22] Fix | Delete
* @access private
[23] Fix | Delete
* @since 2.9.18
[24] Fix | Delete
*/
[25] Fix | Delete
private $session;
[26] Fix | Delete
/**
[27] Fix | Delete
* Session index prefix
[28] Fix | Delete
*
[29] Fix | Delete
* @var string
[30] Fix | Delete
* @access private
[31] Fix | Delete
* @since 2.9.18
[32] Fix | Delete
*/
[33] Fix | Delete
private $prefix = '';
[34] Fix | Delete
/**
[35] Fix | Delete
* Get things started
[36] Fix | Delete
*
[37] Fix | Delete
* Defines our WP_Session constants, includes the necessary libraries and
[38] Fix | Delete
* retrieves the WP Session instance
[39] Fix | Delete
*
[40] Fix | Delete
* @since 2.9.18
[41] Fix | Delete
*/
[42] Fix | Delete
public function __construct() {
[43] Fix | Delete
// Use WP_Session (default)
[44] Fix | Delete
if ( ! defined( 'WP_SESSION_COOKIE' ) ) {
[45] Fix | Delete
define( 'WP_SESSION_COOKIE', 'nf_wp_session' );
[46] Fix | Delete
}
[47] Fix | Delete
if ( ! class_exists( 'Recursive_ArrayAccess' ) ) {
[48] Fix | Delete
require_once Ninja_Forms::$dir . 'includes/Libraries/Session/class-recursive-arrayaccess.php';
[49] Fix | Delete
}
[50] Fix | Delete
if ( ! class_exists( 'WP_Session' ) ) {
[51] Fix | Delete
require_once Ninja_Forms::$dir . 'includes/Libraries/Session/class-wp-session.php';
[52] Fix | Delete
require_once Ninja_Forms::$dir . 'includes/Libraries/Session/wp-session.php';
[53] Fix | Delete
}
[54] Fix | Delete
[55] Fix | Delete
add_filter( 'wp_session_expiration_variant', array( $this, 'set_expiration_variant_time' ), 99999 );
[56] Fix | Delete
add_filter( 'wp_session_expiration', array( $this, 'set_expiration_time' ), 99999 );
[57] Fix | Delete
[58] Fix | Delete
// Since we only loading this as needed, we will need to call init() manually.
[59] Fix | Delete
// add_action( 'plugins_loaded', array( $this, 'init' ), -1 );
[60] Fix | Delete
[61] Fix | Delete
}
[62] Fix | Delete
/**
[63] Fix | Delete
* Setup the WP_Session instance
[64] Fix | Delete
*
[65] Fix | Delete
* @access public
[66] Fix | Delete
* @since 2.9.18
[67] Fix | Delete
* @return void
[68] Fix | Delete
*/
[69] Fix | Delete
public function init() {
[70] Fix | Delete
$this->session = WP_Session::get_instance();
[71] Fix | Delete
return $this->session;
[72] Fix | Delete
}
[73] Fix | Delete
/**
[74] Fix | Delete
* Retrieve session ID
[75] Fix | Delete
*
[76] Fix | Delete
* @access public
[77] Fix | Delete
* @since 2.9.18
[78] Fix | Delete
* @return string Session ID
[79] Fix | Delete
*/
[80] Fix | Delete
public function get_id() {
[81] Fix | Delete
return $this->session->session_id;
[82] Fix | Delete
}
[83] Fix | Delete
/**
[84] Fix | Delete
* Retrieve a session variable
[85] Fix | Delete
*
[86] Fix | Delete
* @access public
[87] Fix | Delete
* @since 2.9.18
[88] Fix | Delete
* @param string $key Session key
[89] Fix | Delete
* @return string Session variable
[90] Fix | Delete
*/
[91] Fix | Delete
public function get( $key ) {
[92] Fix | Delete
$key = sanitize_key( $key );
[93] Fix | Delete
return isset( $this->session[ $key ] ) ? maybe_unserialize( $this->session[ $key ] ) : false;
[94] Fix | Delete
}
[95] Fix | Delete
/**
[96] Fix | Delete
* Set a session variable
[97] Fix | Delete
*
[98] Fix | Delete
* @since 2.9.18
[99] Fix | Delete
* @param string $key Session key
[100] Fix | Delete
* @param integer $value Session variable
[101] Fix | Delete
* @return string Session variable
[102] Fix | Delete
*/
[103] Fix | Delete
public function set( $key, $value ) {
[104] Fix | Delete
[105] Fix | Delete
/*
[106] Fix | Delete
* Manually Set Cookie
[107] Fix | Delete
*/
[108] Fix | Delete
$this->session->set_cookie();
[109] Fix | Delete
[110] Fix | Delete
$key = sanitize_key( $key );
[111] Fix | Delete
if ( is_array( $value ) ) {
[112] Fix | Delete
$this->session[ $key ] = serialize( $value );
[113] Fix | Delete
} else {
[114] Fix | Delete
$this->session[ $key ] = $value;
[115] Fix | Delete
}
[116] Fix | Delete
return $this->session[ $key ];
[117] Fix | Delete
}
[118] Fix | Delete
[119] Fix | Delete
/**
[120] Fix | Delete
* Delete a session variable
[121] Fix | Delete
*
[122] Fix | Delete
* @since 2.9.28
[123] Fix | Delete
* @param string $key
[124] Fix | Delete
* @return void
[125] Fix | Delete
*/
[126] Fix | Delete
public function delete() {
[127] Fix | Delete
delete_option( '_wp_session_' . $this->session->session_id );
[128] Fix | Delete
delete_option( '_wp_session_expires_' . $this->session->session_id );
[129] Fix | Delete
}
[130] Fix | Delete
[131] Fix | Delete
/**
[132] Fix | Delete
* Force the cookie expiration variant time to 23 minutes
[133] Fix | Delete
*
[134] Fix | Delete
* @access public
[135] Fix | Delete
* @since 2.9.18
[136] Fix | Delete
* @param int $exp Default expiration (1 hour)
[137] Fix | Delete
* @return int
[138] Fix | Delete
*/
[139] Fix | Delete
public function set_expiration_variant_time( $exp ) {
[140] Fix | Delete
return 60 * 23;
[141] Fix | Delete
}
[142] Fix | Delete
/**
[143] Fix | Delete
* Force the cookie expiration time to 24 minutes
[144] Fix | Delete
*
[145] Fix | Delete
* @access public
[146] Fix | Delete
* @since 2.9.18
[147] Fix | Delete
* @param int $exp Default expiration (1 hour)
[148] Fix | Delete
* @return int
[149] Fix | Delete
*/
[150] Fix | Delete
public function set_expiration_time( $exp ) {
[151] Fix | Delete
return 60 * 24;
[152] Fix | Delete
}
[153] Fix | Delete
}
[154] Fix | Delete
[155] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function