WC_POS_Admin_Settings_Abstract

Abstract Settings Class.

Defined (1)

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

/includes/admin/settings/class-wc-pos-abstract.php  
  1. class WC_POS_Admin_Settings_Abstract { 
  2.  
  3. protected static $instance; 
  4. protected $defaults; 
  5. public $current_user_authorized = true; 
  6.  
  7. /** 
  8. * Returns the Singleton instance of this class. 
  9. * - late static binding requires PHP 5.3+ 
  10. * @return Singleton 
  11. */ 
  12. public static function get_instance() { 
  13. $class = get_called_class(); 
  14. if (null === static::$instance) { 
  15. static::$instance = new $class(); 
  16. return static::$instance; 
  17.  
  18. protected function __construct() {} 
  19. protected function __clone() {} 
  20. protected function __wakeup() {} 
  21.  
  22. /** 
  23. * Output the view file 
  24. */ 
  25. public function output() { 
  26. include 'views/' . $this->id . '.php'; 
  27. do_action( 'woocommerce_pos_' . $this->id . '_settings_after_output', $this ); 
  28.  
  29. /** 
  30. * Return db key 
  31. * @return string 
  32. */ 
  33. public function option_name() { 
  34. return WC_POS_Admin_Settings::DB_PREFIX . $this->id; 
  35.  
  36. /** 
  37. * Get options 
  38. * @param bool|false $key 
  39. * @return bool|mixed|void 
  40. */ 
  41. public function get($key = false) { 
  42. $data = get_option( $this->option_name() ); 
  43. if(!$data) { 
  44. $data = apply_filters( 'woocommerce_pos_' . $this->id . '_settings_defaults', $this->defaults ); 
  45. if($key && is_array($data)) { 
  46. $data = array_key_exists($key, $data) ? $data[$key] : false; 
  47. return $data; 
  48.  
  49. /** 
  50. * @param array $data 
  51. * @return array|bool 
  52. */ 
  53. public function set(array $data) { 
  54. $data['updated_at'] = time(); // forces update_option to return true 
  55. $updated = add_option( $this->option_name(), $data, '', 'no' ); 
  56. if(!$updated) { 
  57. $updated = update_option( $this->option_name(), $data ); 
  58. return $updated ? $data : false; 
  59.  
  60. /** 
  61. */ 
  62. public function delete() { 
  63. delete_option( $this->option_name() ); 
  64. return $this->get(); 
  65.  
  66. /** 
  67. * @return mixed|string|void 
  68. */ 
  69. public function getJSON() { 
  70. // return json_encode( $this->get(), JSON_FORCE_OBJECT ); // empty array as object?? 
  71. $data = $this->get(); 
  72. return $data ? json_encode( $data ) : false; 
  73.