Overview
  • Namespace
  • Class

Namespaces

  • None
  • WC_POS
    • Admin
      • Settings
        • Receipt
    • API
    • Gateways
    • Integrations
    • Products

Classes

  • WC_POS\Activator
  • WC_POS\Admin
  • WC_POS\Admin\Gateways
  • WC_POS\Admin\Menu
  • WC_POS\Admin\Notices
  • WC_POS\Admin\Orders
  • WC_POS\Admin\Page
  • WC_POS\Admin\Permalink
  • WC_POS\Admin\Plugins
  • WC_POS\Admin\Products
  • WC_POS\Admin\Settings
  • WC_POS\Admin\Settings\Access
  • WC_POS\Admin\Settings\Checkout
  • WC_POS\Admin\Settings\Customers
  • WC_POS\Admin\Settings\Gateways
  • WC_POS\Admin\Settings\General
  • WC_POS\Admin\Settings\HotKeys
  • WC_POS\Admin\Settings\Page
  • WC_POS\Admin\Settings\Receipt\Options
  • WC_POS\Admin\Settings\Receipt\Template
  • WC_POS\Admin\Settings\Receipts
  • WC_POS\Admin\Settings\Status
  • WC_POS\Admin\Settings\Tools
  • WC_POS\Admin\Status
  • WC_POS\Ajax
  • WC_POS\API
  • WC_POS\API\Coupons
  • WC_POS\API\Customers
  • WC_POS\API\Gateways
  • WC_POS\API\i18n
  • WC_POS\API\Orders
  • WC_POS\API\Params
  • WC_POS\API\Payload
  • WC_POS\API\Products
  • WC_POS\API\Settings
  • WC_POS\API\Support
  • WC_POS\API\Templates
  • WC_POS\Customers
  • WC_POS\Deactivator
  • WC_POS\Gateways
  • WC_POS\Gateways\Card
  • WC_POS\Gateways\Cash
  • WC_POS\i18n
  • WC_POS\Integrations\Bookings
  • WC_POS\Products
  • WC_POS\Products\Visibility
  • WC_POS\Setup
  • WC_POS\Status
  • WC_POS\Tax
  • WC_POS\Template

Functions

  • is_pos
  • is_pos_admin
  • wc_pos_get_option
  • wc_pos_json_encode
  • wc_pos_locate_template
  • wc_pos_trim_html_string
  • wc_pos_update_option
  • wc_pos_url
  1 <?php
  2 
  3 /**
  4  * Abstract Settings Class
  5  *
  6  * @class    WC_POS_Admin_Settings_Page
  7  * @package  WooCommerce POS
  8  * @author   Paul Kilmurray <paul@kilbot.com.au>
  9  * @link     http://www.woopos.com.au
 10  */
 11 
 12 namespace WC_POS\Admin\Settings;
 13 
 14 use WC_POS\Admin\Settings;
 15 
 16 class Page {
 17 
 18   protected static $instance;
 19 
 20   protected $defaults;
 21 
 22   protected $flush_local_data = null;
 23 
 24   public $current_user_authorized = true;
 25 
 26   protected $section_handlers = array();
 27 
 28   /**
 29    * Returns the Singleton instance of this class.
 30    * - late static binding requires PHP 5.3+
 31    *
 32    * @return Singleton
 33    */
 34   public static function get_instance() {
 35     $class = get_called_class();
 36     if ( null === static::$instance ) {
 37       static::$instance = new $class();
 38     }
 39 
 40     return static::$instance;
 41   }
 42 
 43   protected function __construct() {
 44   }
 45 
 46   protected function __clone() {
 47   }
 48 
 49   protected function __wakeup() {
 50   }
 51 
 52   /**
 53    * @return array
 54    */
 55   public function get_payload() {
 56     return array(
 57       'id'       => $this->id,
 58       'label'    => $this->label,
 59       'data'     => $this->get(),
 60       'template' => $this->get_template(),
 61       'sections' => $this->get_sections()
 62     );
 63   }
 64 
 65   /**
 66    * Output the view file
 67    */
 68   public function output() {
 69     $file = dirname(__FILE__) . '/views/' . $this->id . '.php';
 70     if ( is_readable( $file ) ) {
 71       include $file;
 72     }
 73   }
 74 
 75   /**
 76    * Catch output and format
 77    */
 78   public function get_template(){
 79     ob_start();
 80     $this->output();
 81     $template = wc_pos_trim_html_string( ob_get_clean() );
 82     return apply_filters( 'woocommerce_pos_' . $this->id . '_settings_template', $template, $this );
 83   }
 84 
 85   /**
 86    * Return db key
 87    * @return string
 88    */
 89   public function option_name(){
 90     return Settings::DB_PREFIX . $this->id;
 91   }
 92 
 93   /**
 94    * Get options
 95    * @param null $key
 96    * @return bool|mixed|void
 97    */
 98   public function get($key = null){
 99     $data = get_option( $this->option_name() );
100     if(!$data){
101       $data = apply_filters( 'woocommerce_pos_' . $this->id . '_settings_defaults', $this->get_defaults() );
102     }
103     if($key && is_array($data)) {
104       $data = array_key_exists($key, $data) ? $data[$key] : false;
105     }
106     return $data;
107   }
108 
109   /**
110    * @param array $data
111    * @return array|bool
112    */
113   public function set(array $data){
114     $data['updated_at'] = time(); // forces update_option to return true
115     $updated = add_option( $this->option_name(), $data, '', 'no' );
116     if(!$updated) {
117       $updated = update_option( $this->option_name(), $data );
118     }
119     return $updated ? $data : false;
120   }
121 
122   /**
123    *
124    */
125   public function delete(){
126     delete_option( $this->option_name() );
127     return $this->get();
128   }
129 
130   /**
131    * @return mixed|string|void
132    */
133   public function getJSON(){
134 //    return json_encode( $this->get(), JSON_FORCE_OBJECT ); // empty array as object??
135     $data = $this->get();
136     return $data ? json_encode( $data ) : false;
137   }
138 
139   /**
140    *
141    */
142   public function get_sections(){
143     $sections = array();
144 
145     foreach( $this->section_handlers as $class ){
146       $handler = $class::get_instance();
147       $sections[] = $handler->get_payload();
148     }
149 
150     return $sections;
151   }
152 
153   /**
154    * Return setting defaults
155    */
156   public function get_defaults(){
157     return $this->defaults;
158   }
159 
160   /**
161    * @param $data
162    * @return bool
163    */
164   public function flush_local_data( $data = array() ){
165     $keys = apply_filters( 'woocommerce_pos_' . $this->id . '_settings_flush_local_data', $this->flush_local_data );
166     return ! is_null( $keys );
167   }
168 
169 }
API documentation generated by ApiGen