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 Admin Page Class
  5  *
  6  * @class    WC_POS_Admin_Abstract
  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;
 13 
 14 class Page {
 15 
 16   /* @var string The db prefix for WP Options table */
 17   const DB_PREFIX = 'woocommerce_pos_settings_';
 18 
 19   /* @var string The settings screen id */
 20   protected $screen_id;
 21 
 22   /* @var string JS var with page id, used for API requests */
 23   protected $wc_pos_adminpage = '';
 24 
 25   /**
 26    * Constructor
 27    */
 28   public function __construct() {
 29     add_action( 'admin_menu', array( $this, 'admin_menu' ) );
 30   }
 31 
 32   /**
 33    *
 34    */
 35   public function conditional_init() {
 36       // Enqueue scripts for the admin pages
 37       add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles' ), 99 );
 38       add_action( 'admin_print_scripts', array( $this, 'admin_print_scripts' ) );
 39       add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ), 99 );
 40       add_action( 'admin_print_footer_scripts', array( $this, 'print_footer_scripts' ), 99 );
 41   }
 42 
 43   /**
 44    *
 45    */
 46   public function admin_menu(){
 47     if( $this->screen_id ){
 48       add_action( 'load-' . $this->screen_id, array( $this, 'conditional_init' ) );
 49     }
 50   }
 51 
 52   /**
 53    *
 54    */
 55   public function enqueue_admin_scripts(){}
 56 
 57   /**
 58    * Admin styles
 59    * note single stylesheet for all settings and system status
 60    */
 61   public function enqueue_admin_styles() {
 62     wp_enqueue_style(
 63       \WC_POS\PLUGIN_NAME . '-admin',
 64       \WC_POS\PLUGIN_URL . 'assets/css/admin.min.css',
 65       null,
 66       \WC_POS\VERSION
 67     );
 68   }
 69 
 70   /**
 71    *
 72    */
 73   public function admin_print_scripts(){
 74     echo '<script>var wc_pos_admin = "' . $this->wc_pos_adminpage . '";</script>';
 75   }
 76 
 77   /**
 78    * Start the Admin App
 79    */
 80   public function print_footer_scripts() {
 81     echo '<script>
 82     if(window.POS){
 83       POS.start(\'' . get_woocommerce_api_url(null) . '\');
 84     } else {
 85       alert(\'' . __('POS assets failed to load', 'woocommerce-pos') . '\');
 86     }
 87     </script>';
 88   }
 89 
 90   /**
 91    * @return int
 92    */
 93   static public function get_db_version(){
 94     return get_option( self::DB_PREFIX . 'db_version', 0 );
 95   }
 96 
 97   /**
 98    * updates db to new version number
 99    * bumps the idb version number
100    */
101   static public function bump_versions(){
102     self::update_option( self::DB_PREFIX . 'db_version', \WC_POS\VERSION );
103     self::bump_idb_version();
104   }
105 
106   /*
107    *
108    */
109   static public function get_idb_version(){
110     $version = (int) get_option( self::DB_PREFIX . 'idb_version', 0 );
111     return $version ? $version : self::bump_idb_version();
112   }
113 
114   /*
115    *
116    */
117   static public function bump_idb_version(){
118     $version = (int) get_option( self::DB_PREFIX . 'idb_version', 0 ) + 1;
119     if( self::update_option( self::DB_PREFIX . 'idb_version', $version ) ){
120       return $version;
121     }
122   }
123 
124   /**
125    * @param $id
126    * @param $key
127    * @return bool
128    */
129   static public function get_option( $id, $key = false ){
130     $handlers = (array) Settings::handlers();
131     if( !array_key_exists( $id, $handlers ) )
132       return false;
133 
134     $settings = $handlers[$id]::get_instance();
135     return $settings->get( $key );
136   }
137 
138   /**
139    * Add or update a WordPress option.
140    * The option will _not_ auto-load by default.
141    *
142    * @param string $name
143    * @param mixed $value
144    * @param string $autoload
145    * @return bool
146    */
147   static public function update_option( $name, $value, $autoload = 'no' ) {
148     $success = add_option( $name, $value, '', $autoload );
149     return $success ? $success : update_option( $name, $value );
150   }
151 
152 }
API documentation generated by ApiGen