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  * Activation checks and set up
  5  *
  6  * @class     WC_POS_Activator
  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;
 13 
 14 class Activator {
 15 
 16   // minimum requirements
 17   const WC_MIN_VERSION = '2.3.7';
 18   const PHP_MIN_VERSION = '5.4';
 19 
 20   /**
 21    *
 22    */
 23   public function __construct() {
 24     register_activation_hook( PLUGIN_FILE, array( $this, 'activate' ) );
 25     add_action( 'wpmu_new_blog', array( $this, 'activate_new_site' ) );
 26     add_action( 'plugins_loaded', array( $this, 'run' ) );
 27   }
 28 
 29   /**
 30    * Checks for valid install and begins execution of the plugin.
 31    */
 32   public function run(){
 33     // Check for min requirements to run
 34     if( $this->php_check() && $this->woocommerce_check() ){
 35 
 36       // check permalinks
 37       if( is_admin() && (!defined('\DOING_AJAX') || !\DOING_AJAX) ){
 38         $this->permalink_check();
 39       }
 40 
 41       // Run update script if required
 42       $this->version_check();
 43       
 44       // resolve plugin plugins
 45       $this->plugin_check();
 46 
 47       new Setup();
 48     }
 49   }
 50 
 51   /**
 52    * Fired when the plugin is activated.
 53    *
 54    * @param $network_wide
 55    */
 56   public function activate( $network_wide ) {
 57     if ( function_exists( 'is_multisite' ) && is_multisite() ) {
 58 
 59       if ( $network_wide  ) {
 60 
 61         // Get all blog ids
 62         $blog_ids = $this->get_blog_ids();
 63 
 64         foreach ( $blog_ids as $blog_id ) {
 65 
 66           switch_to_blog( $blog_id );
 67           $this->single_activate();
 68 
 69           restore_current_blog();
 70         }
 71 
 72       } else {
 73         self::single_activate();
 74       }
 75 
 76     } else {
 77       self::single_activate();
 78     }
 79   }
 80 
 81   /**
 82    * Fired when a new site is activated with a WPMU environment.
 83    *
 84    * @param $blog_id
 85    */
 86   public function activate_new_site( $blog_id ) {
 87 
 88     if ( 1 !== did_action( 'wpmu_new_blog' ) ) {
 89       return;
 90     }
 91 
 92     switch_to_blog( $blog_id );
 93     $this->single_activate();
 94     restore_current_blog();
 95 
 96   }
 97 
 98   /**
 99    * Get all blog ids of blogs in the current network that are:
100    * - not archived
101    * - not spam
102    * - not deleted
103    */
104   private function get_blog_ids() {
105 
106     global $wpdb;
107 
108     // get an array of blog ids
109     $sql = "SELECT blog_id FROM $wpdb->blogs
110       WHERE archived = '0' AND spam = '0'
111       AND deleted = '0'";
112 
113     return $wpdb->get_col( $sql );
114 
115   }
116 
117   /**
118    * Fired when the plugin is activated.
119    */
120   public function single_activate() {
121     // add pos capabilities
122     $this->add_pos_capability();
123 
124     // set the auto redirection on next page load
125     //set_transient( 'woocommere_pos_welcome', 1, 30 );
126   }
127 
128   /**
129    * add default pos capabilities to administrator and
130    * shop_manager roles
131    */
132   private function add_pos_capability(){
133     $roles = array('administrator', 'shop_manager');
134     $caps = array('manage_woocommerce_pos', 'access_woocommerce_pos');
135     foreach($roles as $slug) :
136       $role = get_role($slug);
137       if($role) : foreach($caps as $cap) :
138         $role->add_cap($cap);
139       endforeach; endif;
140     endforeach;
141   }
142 
143   /**
144    * Check version number, runs every admin page load
145    */
146   private function version_check(){
147     $old = Admin\Settings::get_db_version();
148     if( version_compare( $old, VERSION, '<' ) ){
149       Admin\Settings::bump_versions();
150       $this->db_upgrade( $old, VERSION );
151     }
152   }
153 
154   /**
155    * Upgrade database
156    * @param $old
157    * @param $current
158    */
159   private function db_upgrade( $old, $current ) {
160     $db_updates = array(
161       '0.4'   => 'updates/update-0.4.php',
162       '0.4.6' => 'updates/update-0.4.6.php'
163     );
164     foreach ( $db_updates as $version => $updater ) {
165       if ( version_compare( $version, $old, '>' ) &&
166         version_compare( $version, $current, '<=' ) ) {
167         include( $updater );
168       }
169     }
170   }
171 
172   /**
173    * Check min version of WooCommerce installed
174    */
175   private function woocommerce_check() {
176     if( class_exists( '\WooCommerce' ) && version_compare( WC()->version, self::WC_MIN_VERSION, '>=' ) )
177       return true;
178 
179     $message = sprintf(
180       __('<strong>WooCommerce POS</strong> requires <a href="%s">WooCommerce %s or higher</a>. Please <a href="%s">install and activate WooCommerce</a>', 'woocommerce-pos' ),
181       'http://wordpress.org/plugins/woocommerce/',
182       self::WC_MIN_VERSION,
183       admin_url('plugins.php')
184     ) . ' &raquo;';
185     
186     Admin\Notices::add( $message );
187   }
188 
189   /**
190    * Check min version of PHP
191    */
192   private function php_check(){
193     $php_version = phpversion();
194     if( version_compare( $php_version, self::PHP_MIN_VERSION, '>' ) )
195       return true;
196 
197     $message = sprintf(
198       __('<strong>WooCommerce POS</strong> requires PHP %s or higher. Read more information about <a href="%s">how you can update</a>', 'woocommerce-pos' ),
199       self::PHP_MIN_VERSION,
200       'http://www.wpupdatephp.com/update/'
201     ) . ' &raquo;';
202     
203     Admin\Notices::add( $message );
204   }
205 
206   /**
207    * POS Frontend will give 404 if pretty permalinks not active
208    * - requires autoloader, ie: WC_POS()
209    */
210   private function permalink_check(){
211     $fail = Status::permalinks_disabled();
212     if( $fail ){
213       $message = $fail['message'] . '. ';
214       $message .= sprintf( '<a href="%s">%s</a>', $fail['buttons'][0]['href'], $fail['buttons'][0]['prompt'] ) . ' &raquo;';
215       
216       Admin\Notices::add( $message );
217     }
218   }
219 
220   /**
221    * Plugin conflicts
222    *
223    * - NextGEN Gallery is a terrible plugin. It buffers all content on 'init' action, priority -1 and inserts junk code.
224    *
225    */
226   private function plugin_check(){
227 
228     // disable NextGEN Gallery resource manager
229     if( !defined('NGG_DISABLE_RESOURCE_MANAGER') )
230       define( 'NGG_DISABLE_RESOURCE_MANAGER', true );
231 
232   }
233 
234 }
API documentation generated by ApiGen