NF_Session

NF_Session Class.

Defined (2)

The class is defined in the following location(s).

/deprecated/classes/session.php  
  1. class NF_Session { 
  2. /** 
  3. * Holds our session data 
  4. * @var array 
  5. * @access private 
  6. * @since 2.9.18 
  7. */ 
  8. private $session; 
  9. /** 
  10. * Session index prefix 
  11. * @var string 
  12. * @access private 
  13. * @since 2.9.18 
  14. */ 
  15. private $prefix = ''; 
  16. /** 
  17. * Get things started 
  18. * Defines our WP_Session constants, includes the necessary libraries and 
  19. * retrieves the WP Session instance 
  20. * @since 2.9.18 
  21. */ 
  22. public function __construct() { 
  23. // Use WP_Session (default) 
  24. if ( ! defined( 'WP_SESSION_COOKIE' ) ) { 
  25. define( 'WP_SESSION_COOKIE', 'nf_wp_session' ); 
  26. if ( ! class_exists( 'Recursive_ArrayAccess' ) ) { 
  27. require_once NF_PLUGIN_DIR . 'includes/libraries/class-recursive-arrayaccess.php'; 
  28. if ( ! class_exists( 'WP_Session' ) ) { 
  29. require_once NF_PLUGIN_DIR . 'includes/libraries/class-wp-session.php'; 
  30. require_once NF_PLUGIN_DIR . 'includes/libraries/wp-session.php'; 
  31.  
  32. add_filter( 'wp_session_expiration_variant', array( $this, 'set_expiration_variant_time' ), 99999 ); 
  33. add_filter( 'wp_session_expiration', array( $this, 'set_expiration_time' ), 99999 ); 
  34.  
  35. add_action( 'plugins_loaded', array( $this, 'init' ), -1 ); 
  36.  
  37. /** 
  38. * Setup the WP_Session instance 
  39. * @access public 
  40. * @since 2.9.18 
  41. * @return void 
  42. */ 
  43. public function init() { 
  44. $this->session = WP_Session::get_instance(); 
  45. return $this->session; 
  46. /** 
  47. * Retrieve session ID 
  48. * @access public 
  49. * @since 2.9.18 
  50. * @return string Session ID 
  51. */ 
  52. public function get_id() { 
  53. return $this->session->session_id; 
  54. /** 
  55. * Retrieve a session variable 
  56. * @access public 
  57. * @since 2.9.18 
  58. * @param string $key Session key 
  59. * @return string Session variable 
  60. */ 
  61. public function get( $key ) { 
  62. $key = sanitize_key( $key ); 
  63. return isset( $this->session[ $key ] ) ? maybe_unserialize( $this->session[ $key ] ) : false; 
  64. /** 
  65. * Set a session variable 
  66. * @since 2.9.18 
  67. * @param string $key Session key 
  68. * @param integer $value Session variable 
  69. * @return string Session variable 
  70. */ 
  71. public function set( $key, $value ) { 
  72. $key = sanitize_key( $key ); 
  73. if ( is_array( $value ) ) { 
  74. $this->session[ $key ] = serialize( $value ); 
  75. } else { 
  76. $this->session[ $key ] = $value; 
  77. return $this->session[ $key ]; 
  78.  
  79. /** 
  80. * Delete a session variable 
  81. * @since 2.9.28 
  82. * @param string $key 
  83. * @return void 
  84. */ 
  85. public function delete() { 
  86. delete_option( '_wp_session_' . $this->session->session_id ); 
  87. delete_option( '_wp_session_expires_' . $this->session->session_id ); 
  88.  
  89. /** 
  90. * Force the cookie expiration variant time to 23 minutes 
  91. * @access public 
  92. * @since 2.9.18 
  93. * @param int $exp Default expiration (1 hour) 
  94. * @return int 
  95. */ 
  96. public function set_expiration_variant_time( $exp ) { 
  97. return 60 * 23; 
  98. /** 
  99. * Force the cookie expiration time to 24 minutes 
  100. * @access public 
  101. * @since 2.9.18 
  102. * @param int $exp Default expiration (1 hour) 
  103. * @return int 
  104. */ 
  105. public function set_expiration_time( $exp ) { 
  106. return 60 * 24; 
/includes/Session.php  
  1. class NF_Session { 
  2. /** 
  3. * Holds our session data 
  4. * @var array 
  5. * @access private 
  6. * @since 2.9.18 
  7. */ 
  8. private $session; 
  9. /** 
  10. * Session index prefix 
  11. * @var string 
  12. * @access private 
  13. * @since 2.9.18 
  14. */ 
  15. private $prefix = ''; 
  16. /** 
  17. * Get things started 
  18. * Defines our WP_Session constants, includes the necessary libraries and 
  19. * retrieves the WP Session instance 
  20. * @since 2.9.18 
  21. */ 
  22. public function __construct() { 
  23. // Use WP_Session (default) 
  24. if ( ! defined( 'WP_SESSION_COOKIE' ) ) { 
  25. define( 'WP_SESSION_COOKIE', 'nf_wp_session' ); 
  26. if ( ! class_exists( 'Recursive_ArrayAccess' ) ) { 
  27. require_once Ninja_Forms::$dir . 'includes/Libraries/Session/class-recursive-arrayaccess.php'; 
  28. if ( ! class_exists( 'WP_Session' ) ) { 
  29. require_once Ninja_Forms::$dir . 'includes/Libraries/Session/class-wp-session.php'; 
  30. require_once Ninja_Forms::$dir . 'includes/Libraries/Session/wp-session.php'; 
  31.  
  32. add_filter( 'wp_session_expiration_variant', array( $this, 'set_expiration_variant_time' ), 99999 ); 
  33. add_filter( 'wp_session_expiration', array( $this, 'set_expiration_time' ), 99999 ); 
  34.  
  35. add_action( 'plugins_loaded', array( $this, 'init' ), -1 ); 
  36.  
  37. /** 
  38. * Setup the WP_Session instance 
  39. * @access public 
  40. * @since 2.9.18 
  41. * @return void 
  42. */ 
  43. public function init() { 
  44. $this->session = WP_Session::get_instance(); 
  45. return $this->session; 
  46. /** 
  47. * Retrieve session ID 
  48. * @access public 
  49. * @since 2.9.18 
  50. * @return string Session ID 
  51. */ 
  52. public function get_id() { 
  53. return $this->session->session_id; 
  54. /** 
  55. * Retrieve a session variable 
  56. * @access public 
  57. * @since 2.9.18 
  58. * @param string $key Session key 
  59. * @return string Session variable 
  60. */ 
  61. public function get( $key ) { 
  62. $key = sanitize_key( $key ); 
  63. return isset( $this->session[ $key ] ) ? maybe_unserialize( $this->session[ $key ] ) : false; 
  64. /** 
  65. * Set a session variable 
  66. * @since 2.9.18 
  67. * @param string $key Session key 
  68. * @param integer $value Session variable 
  69. * @return string Session variable 
  70. */ 
  71. public function set( $key, $value ) { 
  72.  
  73. /** 
  74. * Manually Set Cookie 
  75. */ 
  76. $this->session->set_cookie(); 
  77.  
  78. $key = sanitize_key( $key ); 
  79. if ( is_array( $value ) ) { 
  80. $this->session[ $key ] = serialize( $value ); 
  81. } else { 
  82. $this->session[ $key ] = $value; 
  83. return $this->session[ $key ]; 
  84.  
  85. /** 
  86. * Delete a session variable 
  87. * @since 2.9.28 
  88. * @param string $key 
  89. * @return void 
  90. */ 
  91. public function delete() { 
  92. delete_option( '_wp_session_' . $this->session->session_id ); 
  93. delete_option( '_wp_session_expires_' . $this->session->session_id ); 
  94.  
  95. /** 
  96. * Force the cookie expiration variant time to 23 minutes 
  97. * @access public 
  98. * @since 2.9.18 
  99. * @param int $exp Default expiration (1 hour) 
  100. * @return int 
  101. */ 
  102. public function set_expiration_variant_time( $exp ) { 
  103. return 60 * 23; 
  104. /** 
  105. * Force the cookie expiration time to 24 minutes 
  106. * @access public 
  107. * @since 2.9.18 
  108. * @param int $exp Default expiration (1 hour) 
  109. * @return int 
  110. */ 
  111. public function set_expiration_time( $exp ) { 
  112. return 60 * 24;