From 773425e7bcd9a0e51ad3cb4545778edaf38b629c Mon Sep 17 00:00:00 2001 From: Allen Snook Date: Wed, 22 Jul 2015 15:34:43 -0700 Subject: [PATCH] Test for woocommerce installation before attempting anything --- .../woocommerce-beta-tester.php | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/plugins/woocommerce-beta-tester/woocommerce-beta-tester.php b/plugins/woocommerce-beta-tester/woocommerce-beta-tester.php index bab478013ba..eb6f17660bf 100644 --- a/plugins/woocommerce-beta-tester/woocommerce-beta-tester.php +++ b/plugins/woocommerce-beta-tester/woocommerce-beta-tester.php @@ -15,7 +15,16 @@ if ( ! defined( 'ABSPATH' ) ) { exit; } -if ( ! class_exists( 'WC_Beta_Tester' ) ) : +/** + * Confirm woocommerce is at least installed before doing anything + * Curiously, developers are discouraged from using WP_PLUGIN_DIR and not given a + * function with which to get the plugin directory, so this is what we have to do + */ +if ( ! file_exists( trailingslashit( dirname( dirname( __FILE__ ) ) ) . 'woocommerce/woocommerce.php' ) ) : + + add_action( 'admin_notices', 'wcbt_woocoommerce_not_installed' ); + +elseif ( ! class_exists( 'WC_Beta_Tester' ) ) : /** * WC_Beta_Tester Main Class @@ -281,3 +290,17 @@ if ( ! class_exists( 'WC_Beta_Tester' ) ) : add_action( 'admin_init', array( 'WC_Beta_Tester', 'instance' ) ); endif; + + +/** +* WooCommerce Not Installed Notice +**/ +if ( ! function_exists( 'wcbt_woocoommerce_not_installed' ) ) { + + function wcbt_woocoommerce_not_installed() { + + echo '

' . sprintf( __( 'WooCommerce Beta Tester requires %s to be installed.', 'woocommerce-beta-tester' ), 'WooCommerce' ) . '

'; + + } + +}