-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunthings-category-children-coupons.php
More file actions
84 lines (69 loc) · 2.83 KB
/
runthings-category-children-coupons.php
File metadata and controls
84 lines (69 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/**
* Plugin Name: Category Children Coupons for WooCommerce
* Plugin URI: https://runthings.dev/wordpress-plugins/category-children-coupons/
* Description: Restrict coupons by product categories, automatically including all child/descendant categories.
* Version: 1.4.1
* Author: runthingsdev
* Author URI: https://runthings.dev/
* License: GPLv3 or later
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
* Requires at least: 6.4
* Requires PHP: 8.0
* Requires Plugins: woocommerce
* Text Domain: runthings-category-children-coupons
* Domain Path: /languages
*/
/*
Copyright 2025 Matthew Harris
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
namespace Runthings\CategoryChildrenCoupons;
if (!defined('WPINC')) {
die;
}
define('RUNTHINGS_CCC_VERSION', '1.4.1');
define('RUNTHINGS_CCC_URL', plugin_dir_url(__FILE__));
define('RUNTHINGS_CCC_DIR', plugin_dir_path(__FILE__));
class Bootstrap
{
public function __construct()
{
add_action('plugins_loaded', [$this, 'init']);
}
public function init(): void
{
if (!$this->is_woocommerce_active()) {
add_action('admin_notices', [$this, 'admin_notice_wc_inactive']);
return;
}
require_once RUNTHINGS_CCC_DIR . 'lib/Plugin.php';
require_once RUNTHINGS_CCC_DIR . 'lib/Admin.php';
require_once RUNTHINGS_CCC_DIR . 'lib/Validator.php';
require_once RUNTHINGS_CCC_DIR . 'lib/AutomateWooMetaCopier.php';
require_once RUNTHINGS_CCC_DIR . 'lib/Migrator.php';
new Plugin();
}
private function is_woocommerce_active(): bool
{
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- core WP filter
return in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')), true) ||
(is_multisite() && array_key_exists('woocommerce/woocommerce.php', get_site_option('active_sitewide_plugins', [])));
}
public function admin_notice_wc_inactive(): void
{
echo '<div class="error"><p>';
esc_html_e('Category Children Coupons for WooCommerce requires WooCommerce to be active. Please install and activate WooCommerce.', 'runthings-category-children-coupons');
echo '</p></div>';
}
}
new Bootstrap();