Skip to content

Commit

Permalink
Check WooCommerce is active during plugin initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
alexminza committed Mar 21, 2018
1 parent 3e262f5 commit c6f6703
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
24 changes: 24 additions & 0 deletions composer.json
@@ -0,0 +1,24 @@
{
"name": "alexminza/wc-alcohol",
"description": "WooCommerce Alcohol Sale Restrictions",
"type": "wordpress-plugin",
"keywords": ["woocommerce", "alcohol", "sale", "restriction"],
"homepage": "https://github.com/alexminza/wc-alcohol",
"license": "GPL-3.0-or-later",
"authors": [
{
"name": "Alexander Minza",
"homepage": "http://alexminza.com",
"role": "Developer"
}
],
"support": {
"issues": "https://github.com/alexminza/wc-alcohol/issues",
"forum": "https://wordpress.org/support/plugin/wc-alcohol",
"source": "https://github.com/alexminza/wc-alcohol"
},
"require": {
"php": ">=7.0",
"composer/installers": "~1.2"
}
}
7 changes: 5 additions & 2 deletions readme.txt
Expand Up @@ -33,6 +33,9 @@ Use the WooCommerce -> Settings -> Products -> Alcohol sale restrictions screen

== Changelog ==

= 1.0.3 =
Check WooCommerce is active during plugin initialization

= 1.0.2 =
Display warning options on product and category pages

Expand All @@ -41,5 +44,5 @@ Initial release

== Upgrade Notice ==

= 1.0.2 =
Display warning options on product and category pages
= 1.0.3 =
Check WooCommerce is active during plugin initialization
12 changes: 7 additions & 5 deletions wc-alcohol.php
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: WooCommerce Alcohol Sale Restrictions
* Description: WooCommerce alcohol sale limitations during restriction hours
* Plugin URI: https://wordpress.org/plugins/wc-alcohol/
* Version: 1.0.2
* Version: 1.0.3
* Author: Alexander Minza
* Author URI: https://profiles.wordpress.org/alexminza
* Developer: Alexander Minza
Expand All @@ -15,7 +15,7 @@
* Requires at least: 4.8
* Tested up to: 4.9.4
* WC requires at least: 3.2
* WC tested up to: 3.3.3
* WC tested up to: 3.3.4
*/

//Looking to contribute code to this plugin? Go ahead and fork the repository over at GitHub https://github.com/alexminza/wc-alcohol
Expand Down Expand Up @@ -401,12 +401,14 @@ protected static function string_empty($string) {
}

//https://docs.woocommerce.com/document/create-a-plugin/
protected static function check_wc_active() {
public static function is_wc_active() {
//Check if WooCommerce is active
return in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')));
}
}

//initialize plugin
add_action('plugins_loaded', array(WC_Alcohol::class, 'get_instance'));
if(WC_Alcohol::is_wc_active()) {
//initialize plugin
add_action('plugins_loaded', array(WC_Alcohol::class, 'get_instance'));
}
endif;

0 comments on commit c6f6703

Please sign in to comment.