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  * Global helper functions for WooCommerce POS
  5  *
  6  * @package   WooCommerce POS
  7  * @author    Paul Kilmurray <paul@kilbot.com.au>
  8  * @link      http://www.woopos.com.au
  9  *
 10  */
 11 
 12 /**
 13  * Construct the POS permalink
 14  *
 15  * @param string $page
 16  *
 17  * @return string|void
 18  */
 19 function wc_pos_url( $page = '' ) {
 20   $slug = WC_POS\Admin\Permalink::get_slug();
 21   return home_url( $slug . '/' .$page );
 22 }
 23 
 24 
 25 /**
 26  * Test for POS requests to the server
 27  *
 28  * @param $type
 29  *
 30  * @return bool
 31  */
 32 function is_pos( $type = false ) {
 33 
 34   // test for template requests, ie: matched rewrite rule
 35   // also matches $_GET & $_POST for pos=1
 36   if( $type == 'template' || !$type ){
 37     global $wp;
 38     if( isset( $wp->query_vars['pos'] ) && $wp->query_vars['pos'] == 1 ){
 39       return true;
 40     }
 41   }
 42 
 43   // test for WC REST API requests, ie: matched request header
 44   if( $type == 'ajax' || !$type ) {
 45     // check server global first
 46     if( isset( $_SERVER['HTTP_X_WC_POS'] ) && $_SERVER['HTTP_X_WC_POS'] == 1 ){
 47       return true;
 48     }
 49     // backup check getallheaders() - can cause problems
 50     if ( function_exists( 'getallheaders' ) && is_array( getallheaders() ) && array_key_exists( 'X-WC-POS', getallheaders() ) ) {
 51       return true;
 52     }
 53   }
 54 
 55   return false;
 56 }
 57 
 58 /**
 59  *
 60  */
 61 function is_pos_admin() {
 62   if ( function_exists( 'getallheaders' )
 63     && $headers = getallheaders()
 64     && isset( $headers['X-WC-POS-ADMIN'] )
 65   ) {
 66     return $headers['X-WC-POS-ADMIN'];
 67   } elseif ( isset( $_SERVER[ 'HTTP_X_WC_POS_ADMIN' ] ) ) {
 68     return $_SERVER[ 'HTTP_X_WC_POS_ADMIN' ];
 69   }
 70 
 71   return false;
 72 }
 73 
 74     /**
 75  * Add or update a WordPress option.
 76  * The option will _not_ auto-load by default.
 77  *
 78  * @param string $name
 79  * @param mixed $value
 80  * @param string $autoload
 81  * @return bool
 82  */
 83 function wc_pos_update_option( $name, $value, $autoload = 'no' ) {
 84   $success = add_option( $name, $value, '', $autoload );
 85 
 86   if ( ! $success ) {
 87     $success = update_option( $name, $value );
 88   }
 89 
 90   return $success;
 91 }
 92 
 93 /**
 94  * Simple wrapper for json_encode
 95  *
 96  * Use JSON_FORCE_OBJECT for PHP 5.3 or higher with fallback for
 97  * PHP less than 5.3.
 98  *
 99  * WP 4.1 adds some wp_json_encode sanity checks which may be
100  * useful at some later stage.
101  *
102  * @param $data
103  * @return mixed
104  */
105 function wc_pos_json_encode($data){
106   $args = array( $data, JSON_FORCE_OBJECT );
107   return call_user_func_array( 'json_encode', $args );
108 }
109 
110 /**
111  * Return template path
112  *
113  * @param string $path
114  * @return mixed|void
115  */
116 function wc_pos_locate_template($path = ''){
117   $template = locate_template(array(
118     'woocommerce-pos/' . $path
119   ));
120 
121   if( !$template ){
122     $template = WC_POS_PLUGIN_PATH. 'includes/views/' . $path;
123   }
124 
125   if ( file_exists( $template ) ) {
126     return apply_filters('woocommerce_pos_locate_template', $template, $path);
127   }
128 }
129 
130 /**
131  * @param $id
132  * @param $key
133  * @return bool
134  */
135 function wc_pos_get_option( $id, $key = false ){
136   $handlers = (array) WC_POS\Admin\Settings::handlers();
137   if( ! array_key_exists( $id, $handlers ) )
138     return false;
139 
140   $settings = $handlers[$id]::get_instance();
141   return $settings->get( $key );
142 }
143 
144 /**
145  * Remove newlines and code spacing
146  *
147  * @param $str
148  * @return mixed
149  */
150 function wc_pos_trim_html_string( $str ) {
151   return preg_replace( '/^\s+|\n|\r|\s+$/m', '', $str );
152 }
153 
API documentation generated by ApiGen