WC_Session

Handle data for the current customers session.

Defined (1)

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

/includes/abstracts/abstract-wc-session.php  
  1. abstract class WC_Session { 
  2.  
  3. /** @var int $_customer_id */ 
  4. protected $_customer_id; 
  5.  
  6. /** @var array $_data */ 
  7. protected $_data = array(); 
  8.  
  9. /** @var bool $_dirty When something changes */ 
  10. protected $_dirty = false; 
  11.  
  12. /** 
  13. * __get function. 
  14. * @param mixed $key 
  15. * @return mixed 
  16. */ 
  17. public function __get( $key ) { 
  18. return $this->get( $key ); 
  19.  
  20. /** 
  21. * __set function. 
  22. * @param mixed $key 
  23. * @param mixed $value 
  24. */ 
  25. public function __set( $key, $value ) { 
  26. $this->set( $key, $value ); 
  27.  
  28. /** 
  29. * __isset function. 
  30. * @param mixed $key 
  31. * @return bool 
  32. */ 
  33. public function __isset( $key ) { 
  34. return isset( $this->_data[ sanitize_title( $key ) ] ); 
  35.  
  36. /** 
  37. * __unset function. 
  38. * @param mixed $key 
  39. */ 
  40. public function __unset( $key ) { 
  41. if ( isset( $this->_data[ $key ] ) ) { 
  42. unset( $this->_data[ $key ] ); 
  43. $this->_dirty = true; 
  44.  
  45. /** 
  46. * Get a session variable. 
  47. * @param string $key 
  48. * @param mixed $default used if the session variable isn't set 
  49. * @return array|string value of session variable 
  50. */ 
  51. public function get( $key, $default = null ) { 
  52. $key = sanitize_key( $key ); 
  53. return isset( $this->_data[ $key ] ) ? maybe_unserialize( $this->_data[ $key ] ) : $default; 
  54.  
  55. /** 
  56. * Set a session variable. 
  57. * @param string $key 
  58. * @param mixed $value 
  59. */ 
  60. public function set( $key, $value ) { 
  61. if ( $value !== $this->get( $key ) ) { 
  62. $this->_data[ sanitize_key( $key ) ] = maybe_serialize( $value ); 
  63. $this->_dirty = true; 
  64.  
  65. /** 
  66. * get_customer_id function. 
  67. * @access public 
  68. * @return int 
  69. */ 
  70. public function get_customer_id() { 
  71. return $this->_customer_id;