Skip to content
Permalink
Browse files

fix woocommerce check

  • Loading branch information...
kilbot committed Jun 23, 2015
1 parent f962780 commit 80285c4e90c6932f146e59ff2c8254e3cbc660bd
@@ -125,16 +125,20 @@ static private function add_pos_capability(){
* Check dependencies
*/
public function run_checks() {
if ( defined( 'DOING_AJAX' ) && DOING_AJAX )
return;
if( ! current_user_can( 'activate_plugins' ) )
return;
$this->version_check();
$this->woocommerce_check();
$this->wc_api_check();
$this->permalink_check();
}
/**
* Check version number, runs every time
* Check version number, runs every admin page load
*/
public function version_check(){
private function version_check(){
// next check the POS version number
$old = get_option( 'woocommerce_pos_db_version' );
if( !$old || version_compare( $old, WC_POS_VERSION, '<' ) ) {
@@ -146,7 +150,7 @@ public function version_check(){
/**
* Upgrade database
*/
public function db_upgrade( $old, $current ) {
private function db_upgrade( $old, $current ) {
$db_updates = array(
'0.4' => 'updates/update-0.4.php'
);
@@ -159,57 +163,23 @@ public function db_upgrade( $old, $current ) {
}
/**
* Check if WooCommerce is active
* WooCommerce POS will not load if WooCommerce is not present
*/
private function woocommerce_check() {
if( ! current_user_can( 'activate_plugins' ) )
return;
if ( ! class_exists( 'WooCommerce' ) && current_user_can( 'activate_plugins' ) ) {
// alert the user
$error = array (
'msg_type' => 'error',
'msg' => sprintf( __('<strong>WooCommerce POS</strong> requires <a href="%s">WooCommerce</a>. Please <a href="%s">install and activate WooCommerce</a>', 'woocommerce-pos' ), 'http://wordpress.org/plugins/woocommerce/', admin_url('plugins.php') ) . ' &raquo;'
);
do_action('woocommerce_pos_add_admin_notice', $error);
}
if( ! class_exists( 'WooCommerce' ) )
add_action( 'admin_notices', array( $this, 'woocommerce_alert' ) );
}
/**
* Check if the WC API option is enabled
* Admin message - WooCommerce not activated
*/
private function wc_api_check() {
if( ! current_user_can( 'manage_woocommerce' ) )
return;
if( get_option( 'woocommerce_api_enabled' ) !== 'yes' && ! isset( $_POST['woocommerce_api_enabled'] ) ) {
// alert the user
$error = array (
'msg_type' => 'error',
'msg' => sprintf( __('<strong>WooCommerce POS</strong> requires the WooCommerce REST API. Please <a href="%s">enable the REST API</a>', 'woocommerce-pos' ), admin_url('admin.php?page=wc-settings') ) . ' &raquo;'
);
do_action('woocommerce_pos_add_admin_notice', $error);
}
public function woocommerce_alert(){
echo '<div class="error">
<p>'. sprintf( __('<strong>WooCommerce POS</strong> requires <a href="%s">WooCommerce</a>. Please <a href="%s">install and activate WooCommerce</a>', 'woocommerce-pos' ), 'http://wordpress.org/plugins/woocommerce/', admin_url('plugins.php') ) . ' &raquo;</p>
</div>';
}
/**
* Check if permalinks enabled, WC API needs permalinks
*/
private function permalink_check() {
global $wp_rewrite;
if( $wp_rewrite->permalink_structure == '' ) {
// alert the user
$error = array (
'msg_type' => 'error',
'msg' => sprintf( __('<strong>WooCommerce REST API</strong> requires <em>pretty</em> permalinks to work correctly. Please <a href="%s">enable permalinks</a>.', 'woocommerce-pos'), admin_url('options-permalink.php') ) . ' &raquo;'
);
do_action('woocommerce_pos_add_admin_notice', $error);
}
}
}
}
// self loading
new WC_POS_Activator();
@@ -50,6 +50,7 @@ public function dispatch_args($args, $callback){
}
/**
* - this filter was introduced in WC 2.3
* @param $args
* @param $request_args
* @return mixed
@@ -10,7 +10,7 @@
class WC_POS_Status {
private $wc_min_version = '2.2';
private $wc_min_version = '2.3';
public function output() {
$results = array(
@@ -21,7 +21,7 @@ public function output() {
}
/**
* Test WC >= 2.2
* Test WC >= $wc_min_version
* @return boolean
*/
private function test_wc_version() {
@@ -71,14 +71,6 @@ private function test_wc_rest_api() {
));
}
// check curl
if( !function_exists('curl_init') ){
return array_merge( $result, array(
'pass' => false,
'message' => __( 'Unable to test the REST API', 'woocommerce-pos' )
));
}
// check API access
if( $this->http_status( get_woocommerce_api_url('') ) !== 200 ){
return array_merge( $result, array(
@@ -126,16 +118,11 @@ private function use_restful_http_methods(){
* @return bool|int
*/
private function http_status( $url, $method = 'GET' ){
if( $ch = curl_init($url)) {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return (int) $status;
} else {
return false;
}
$args = array(
'method' => $method
);
$response = wp_remote_request( $url, $args );
return wp_remote_retrieve_response_code( $response );
}
}
@@ -70,7 +70,6 @@ public function init() {
// admin only
if (is_admin() && (!defined('DOING_AJAX') || !DOING_AJAX)) {
new WC_POS_Activator(); // contains sanity checks
new WC_POS_Admin();
}
@@ -24,7 +24,7 @@ You can see a demo of the WooCommerce POS plugin in action by going to [http://d
* Upgrade to Pro: http://woopos.com.au/pro

= REQUIREMENTS =
* WooCommerce >= 2.2.0
* WooCommerce >= 2.3.0
* [A modern browser](http://woopos.com.au/faq/browser-compatibility/)

== Installation ==
@@ -2,26 +2,23 @@
class Integration_Test_WC_POS {
private $wp_root;
public function __construct(){
ini_set( 'display_errors','on' );
error_reporting( E_ALL );
$this->includes();
switch_theme('WooCommerce-POS-Test-Theme', 'WooCommerce-POS-Test-Theme');
update_option('active_plugins', array(
'woocommerce-pos/woocommerce-pos.php',
'woocommerce/woocommerce.php'
));
register_shutdown_function( array( $this, 'after_tests' ) );
$this->setup();
register_shutdown_function( array( $this, 'shutdown' ) );
}
/**
* include wp-load
* include composer autoloader
*/
private function includes(){
public function includes(){
require_once(__DIR__.'/../../../../../../wp-load.php');
if( is_readable( 'vendor/autoload.php' ) ){
@@ -34,10 +31,18 @@ private function includes(){
}
public function setup(){
switch_theme('WooCommerce-POS-Test-Theme', 'WooCommerce-POS-Test-Theme');
update_option('active_plugins', array(
'woocommerce-pos/woocommerce-pos.php',
'woocommerce/woocommerce.php'
));
}
/**
* runs after all tests are complete
*/
public function after_tests(){
public function shutdown(){
switch_theme('twentyfifteen', 'twentyfifteen');
}
@@ -0,0 +1,45 @@
<?php
class ActivationTest extends PHPUnit_Framework_TestCase {
protected $client;
public function setUp() {
$this->client = new GuzzleHttp\Client([
'defaults' => ['exceptions' => false],
]);
}
public function test_load() {
$response = $this->client->get( wc_pos_url(), [
'allow_redirects' => false
]);
// expect 302 redirect to login
$this->assertEquals(302, $response->getStatusCode());
}
public function test_load_order() {
// reverse plugin load order
update_option('active_plugins', array(
'woocommerce/woocommerce.php',
'woocommerce-pos/woocommerce-pos.php'
));
$response = $this->client->get( wc_pos_url(), [
'allow_redirects' => false
]);
// expect 302 redirect to login
$this->assertEquals(302, $response->getStatusCode());
// restore plugin load order
update_option('active_plugins', array(
'woocommerce-pos/woocommerce-pos.php',
'woocommerce/woocommerce.php'
));
}
public function tearDown(){
}
}
@@ -51,7 +51,12 @@
/**
* Begins execution of the plugin.
*/
add_action( 'woocommerce_loaded', 'run_woocommerce_pos' );
function run_woocommerce_pos() {
new WC_POS();
}
global $wp_actions;
if ( isset( $wp_actions['woocommerce_loaded'] ) ) {
run_woocommerce_pos();
} else {
add_action( 'woocommerce_loaded', 'run_woocommerce_pos' );
}

0 comments on commit 80285c4

Please sign in to comment.
You can’t perform that action at this time.