WC_POS_Status

The WooCommerce POS WC POS Status class.

Defined (1)

The class is defined in the following location(s).

/includes/class-wc-pos-status.php  
  1. class WC_POS_Status { 
  2.  
  3. public function output() { 
  4. $results = array( 
  5. $this->test_wc_version(),  
  6. $this->test_php_version(),  
  7. $this->test_wc_rest_api() 
  8. ); 
  9. return $results; 
  10.  
  11. /** 
  12. * Test WC >= $wc_min_version 
  13. * @return boolean 
  14. */ 
  15. private function test_wc_version() { 
  16. $result = array( 
  17. 'title' => __( 'WC Version', 'woocommerce-pos' ),  
  18. 'pass' => version_compare( WC()->version, WC_POS_Activator::WC_MIN_VERSION, '>=' ),  
  19. 'message' => esc_html( WC()->version ) 
  20. ); 
  21.  
  22. if( ! $result['pass'] ) { 
  23. $result = array_merge( $result, array( 
  24. 'message' => sprintf( __( 'WooCommerce >= %s required', 'woocommerce-pos' ), WC_POS_Activator::WC_MIN_VERSION),  
  25. 'buttons' => array( 
  26. array( 
  27. 'href' => admin_url( 'update-core.php' ),  
  28. /** translators: wordpress */ 
  29. 'prompt' => __( 'Update' ) 
  30. )); 
  31.  
  32. return $result; 
  33.  
  34. /** 
  35. * Test PHP >= $php_min_version 
  36. * @return boolean 
  37. */ 
  38. private function test_php_version() { 
  39. if( ! function_exists('phpversion') ) 
  40. return; 
  41.  
  42. $php_version = phpversion(); 
  43.  
  44. $result = array( 
  45. 'title' => /** translators: woocommerce */ __( 'PHP Version', 'woocommerce' ),  
  46. 'pass' => version_compare( $php_version, WC_POS_Activator::PHP_MIN_VERSION, '>' ),  
  47. 'message' => esc_html( $php_version ) 
  48. ); 
  49.  
  50. if( ! $result['pass'] ) { 
  51. $result = array_merge( $result, array( 
  52. 'message' => sprintf( __( 'PHP >= %s required', 'woocommerce-pos' ), WC_POS_Activator::PHP_MIN_VERSION ),  
  53. 'buttons' => array( 
  54. array( 
  55. 'href' => 'http://docs.woothemes.com/document/how-to-update-your-php-version/',  
  56. /** translators: wordpress */ 
  57. 'prompt' => __( 'Update' ) 
  58. )); 
  59.  
  60. return $result; 
  61.  
  62. /** 
  63. * Test WC REST API is accessible using RESTful HTTP methods 
  64. * @return array 
  65. */ 
  66. private function test_wc_rest_api() { 
  67. $result = array( 
  68. 'pass' => true,  
  69. 'title' => __( 'WC REST API', 'woocommerce-pos' ),  
  70. 'message' => __( 'API is active', 'woocommerce-pos' ) 
  71. ); 
  72.  
  73. if( $fail = self::permalinks_disabled() ) 
  74. return array_merge( $result, $fail ); 
  75.  
  76. if( $fail = self::wc_rest_api_disabled() ) 
  77. return array_merge( $result, $fail ); 
  78.  
  79. return $result; 
  80.  
  81. /** 
  82. * Option for to emulate RESTful HTTP requests 
  83. */ 
  84. static public function toggle_legacy_server() { 
  85. if( isset($_GET['enable']) && $_GET['enable'] === 'true' ) { 
  86. update_option( 'woocommerce_pos_emulateHTTP', true ); 
  87. } else { 
  88. delete_option( 'woocommerce_pos_emulateHTTP' ); 
  89.  
  90. /** 
  91. * @return array 
  92. */ 
  93. static public function wc_rest_api_disabled() { 
  94. if( get_option('woocommerce_api_enabled') !== 'yes' ) { 
  95.  
  96. // api settings changes in WC 2.4 
  97. $href = admin_url('admin.php?page=wc-settings'); 
  98. if( version_compare( WC()->version, '2.4', '>=' ) ) { 
  99. $href .= '&tab=api'; 
  100.  
  101. return array( 
  102. 'pass' => false,  
  103. 'message' => __('Access to the REST API is required', 'woocommerce-pos'),  
  104. 'buttons' => array( 
  105. array( 
  106. 'href' => $href,  
  107. /** translators: woocommerce */ 
  108. 'prompt' => __('Enable the REST API', 'woocommerce') 
  109. ); 
  110.  
  111. /** 
  112. * @return array 
  113. */ 
  114. static public function permalinks_disabled() { 
  115. $permalinks = get_option('permalink_structure'); 
  116. if( empty( $permalinks ) ) { 
  117. return array( 
  118. 'pass' => false,  
  119. 'message' => __( '<strong>WooCommerce REST API</strong> requires <em>pretty</em> permalinks to work correctly', 'woocommerce-pos' ),  
  120. 'buttons' => array( 
  121. array( 
  122. 'href' => admin_url('options-permalink.php'),  
  123. 'prompt' => __( 'Enable permalinks', 'woocommerce-pos' ) 
  124. ); 
  125.