WooCommerce_Session_Helper

The Woocommerce Poor Guys Swiss Knife WooCommerce Session Helper class.

Defined (1)

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

/classes/woocommerce_session_helper.php  
  1. class WooCommerce_Session_Helper { 
  2.  
  3.  
  4.  
  5. /** 
  6. * Store a value in the session 
  7. * @param string $key The key to store 
  8. * @param mixed $value The value to store 
  9. */ 
  10. public static function _set ( $key, $value ) { 
  11.  
  12. global $woocommerce; 
  13.  
  14. switch (self::storage_method()) { 
  15.  
  16. case 'wc_session': 
  17. $woocommerce->session->$key = $value; 
  18. break; 
  19.  
  20. case 'raw_session': 
  21. default: 
  22. $_SESSION[$key] = $value; 
  23. break; 
  24.  
  25.  
  26.  
  27.  
  28. /** 
  29. * Retrieve a value from the session 
  30. * @param string $key The key to retrieve 
  31. * @return mixed The value of the key, or false if no value is stored 
  32. */ 
  33. public static function _get ( $key ) { 
  34.  
  35. global $woocommerce; 
  36.  
  37. switch (self::storage_method()) { 
  38.  
  39. case 'wc_session': 
  40. return isset ( $woocommerce->session->$key ) ? $woocommerce->session->$key : false; 
  41. break; 
  42.  
  43. case 'raw_session': 
  44. default: 
  45. return isset ( $_SESSION[$key] ) ? $_SESSION[$key] : false; 
  46. break; 
  47.  
  48.  
  49.  
  50.  
  51. /** 
  52. * Unset a value in the session 
  53. * @param string $key The key to unset 
  54. */ 
  55. public static function _unset ( $key ) { 
  56.  
  57. global $woocommerce; 
  58.  
  59. switch (self::storage_method()) { 
  60.  
  61. case 'wc_session': 
  62. unset ( $woocommerce->session->$key ); 
  63. break; 
  64.  
  65. case 'raw_session': 
  66. default: 
  67. unset ( $_SESSION[$key] ); 
  68. break; 
  69.  
  70.  
  71.  
  72.  
  73. /** 
  74. * Check whether a key is set in the session storage 
  75. * @param string $key The key to check 
  76. * @return boolean Returns true if the key isset, false if not 
  77. */ 
  78. public static function _isset ( $key ) { 
  79.  
  80. global $woocommerce; 
  81.  
  82. switch (self::storage_method()) { 
  83.  
  84. case 'wc_session': 
  85. return isset ( $woocommerce->session->$key ); 
  86. break; 
  87.  
  88. case 'raw_session': 
  89. default: 
  90. return isset ( $_SESSION[$key] ); 
  91. break; 
  92.  
  93.  
  94.  
  95.  
  96.  
  97. /** 
  98. * Detects which storage engine is in use by checking for a session in the 
  99. * global $woocommerce object. 
  100. * NOTE: This will only return the correct engine reliably AFTER plugins_loaded 
  101. * @return string A string identifying which storage engine is in use. 
  102. */ 
  103. private function storage_method() { 
  104.  
  105. global $woocommerce; 
  106. //return ( 'raw_session' ); 
  107.  
  108. if ( class_exists ( 'WC_Session' ) ) { 
  109. return ( 'wc_session' ); 
  110. } else { 
  111. return ( 'raw_session' ); 
  112.  
  113.  
  114.