1 <?php
  2   3   4   5   6   7   8   9 
 10 
 11 namespace WC_POS;
 12 
 13 class Status {
 14 
 15   public function output() {
 16     $results = array(
 17       $this->test_wc_version(),
 18       $this->test_php_version(),
 19       $this->test_wc_rest_api()
 20     );
 21     return $results;
 22   }
 23 
 24    25  26  27 
 28   private function test_wc_version() {
 29     $result = array(
 30       'title'   => __( 'WC Version', 'woocommerce-pos' ),
 31       'pass'    => version_compare( WC()->version, Activator::WC_MIN_VERSION, '>=' ),
 32       'message' => esc_html( WC()->version )
 33     );
 34 
 35     if( ! $result['pass'] ){
 36       $result = array_merge( $result, array(
 37         'message' => sprintf( __( 'WooCommerce >= %s required', 'woocommerce-pos' ), Activator::WC_MIN_VERSION),
 38         'buttons' => array(
 39           array(
 40             'href'  => admin_url( 'update-core.php' ),
 41             
 42             'prompt'  => __( 'Update' )
 43           )
 44         )
 45       ));
 46     }
 47 
 48     return $result;
 49   }
 50 
 51    52  53  54 
 55   private function test_php_version() {
 56     if( ! function_exists('phpversion') )
 57       return;
 58 
 59     $php_version = phpversion();
 60 
 61     $result = array(
 62       'title'   =>  __( 'PHP Version', 'woocommerce' ),
 63       'pass'    => version_compare( $php_version, Activator::PHP_MIN_VERSION, '>' ),
 64       'message' => esc_html( $php_version )
 65     );
 66 
 67     if( ! $result['pass'] ){
 68       $result = array_merge( $result, array(
 69         'message' => sprintf( __( 'PHP >= %s required', 'woocommerce-pos' ), Activator::PHP_MIN_VERSION ),
 70         'buttons' => array(
 71           array(
 72             'href'  => 'http://docs.woothemes.com/document/how-to-update-your-php-version/',
 73             
 74             'prompt'  => __( 'Update' )
 75           )
 76         )
 77       ));
 78     }
 79 
 80     return $result;
 81   }
 82 
 83    84  85  86 
 87   private function test_wc_rest_api() {
 88     $result = array(
 89       'pass'    => true,
 90       'title'   => __( 'WC REST API', 'woocommerce-pos' ),
 91       'message' => __( 'API is active', 'woocommerce-pos' )
 92     );
 93 
 94     if( $fail = self::permalinks_disabled() )
 95       return array_merge( $result, $fail );
 96 
 97     if( $fail = self::wc_rest_api_disabled() )
 98       return array_merge( $result, $fail );
 99 
100     return $result;
101   }
102 
103   104 105 
106   static public function toggle_legacy_server(){
107     if( isset($_GET['enable']) && $_GET['enable'] === 'true' ) {
108       update_option( 'woocommerce_pos_emulateHTTP', true );
109     } else {
110       delete_option( 'woocommerce_pos_emulateHTTP' );
111     }
112   }
113 
114   115 116 
117   static public function wc_rest_api_disabled(){
118     if( get_option('woocommerce_api_enabled') !== 'yes' ) {
119 
120       
121       $href = admin_url('admin.php?page=wc-settings');
122       if( version_compare( WC()->version, '2.4', '>=' ) ){
123         $href .= '&tab=api';
124       }
125 
126       return array(
127         'pass' => false,
128         'message' => __('Access to the REST API is required', 'woocommerce-pos'),
129         'buttons' => array(
130           array(
131             'href' => $href,
132             
133             'prompt' => __('Enable the REST API', 'woocommerce')
134           )
135         )
136       );
137     }
138   }
139 
140   141 142 
143   static public function permalinks_disabled(){
144     $permalinks = get_option('permalink_structure');
145     if( empty( $permalinks ) ) {
146       return array(
147         'pass'    => false,
148         'message' => __( '<strong>WooCommerce REST API</strong> requires <em>pretty</em> permalinks to work correctly', 'woocommerce-pos' ),
149         'buttons' => array(
150           array(
151             'href'  => admin_url('options-permalink.php'),
152             'prompt'  => __( 'Enable permalinks', 'woocommerce-pos' )
153           )
154         )
155       );
156     }
157   }
158 
159 }