| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: WebToffee EU Order Withdrawal Button for WooCommerce |
| 4 |
* Plugin URI: https://www.wordpress.org/plugins/wt-eu-withdrawal-button |
| 5 |
* Description: Manage withdrawal of contract / order cancellation requests for WooCommerce orders. EU-compliant, HPOS-compatible. |
| 6 |
* Version: 1.0.9 |
| 7 |
* Author: webtoffee |
| 8 |
* Author URI: https://www.webtoffee.com/ |
| 9 |
* License: GPL-3.0+ |
| 10 |
* License URI: https://www.gnu.org/licenses/gpl-3.0.html |
| 11 |
* Text Domain: wt-eu-withdrawal-button |
| 12 |
* Domain Path: /languages |
| 13 |
* Requires Plugins: woocommerce |
| 14 |
* Requires at least: 6.0 |
| 15 |
* Tested up to: 7.1 |
| 16 |
* Requires PHP: 7.4 |
| 17 |
* WC requires at least: 7.0 |
| 18 |
* WC tested up to: 11.0.0 |
| 19 |
* |
| 20 |
* @package Wbte_Eu_Withdrawal_Button |
| 21 |
* @since 1.0.0 |
| 22 |
*/ |
| 23 |
|
| 24 |
if ( ! defined( 'ABSPATH' ) ) { |
| 25 |
exit; |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Plugin version. |
| 30 |
* |
| 31 |
* @since 1.0.0 |
| 32 |
*/ |
| 33 |
define( 'WBTE_EWB_VERSION', '1.0.9' ); |
| 34 |
|
| 35 |
/** |
| 36 |
* Plugin file path. |
| 37 |
* |
| 38 |
* @since 1.0.0 |
| 39 |
*/ |
| 40 |
define( 'WBTE_EWB_PLUGIN_FILE', __FILE__ ); |
| 41 |
|
| 42 |
/** |
| 43 |
* Plugin directory path. |
| 44 |
* |
| 45 |
* @since 1.0.0 |
| 46 |
*/ |
| 47 |
define( 'WBTE_EWB_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); |
| 48 |
|
| 49 |
/** |
| 50 |
* Plugin directory URL. |
| 51 |
* |
| 52 |
* @since 1.0.0 |
| 53 |
*/ |
| 54 |
define( 'WBTE_EWB_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); |
| 55 |
|
| 56 |
/** |
| 57 |
* Plugin basename. |
| 58 |
* |
| 59 |
* @since 1.0.0 |
| 60 |
*/ |
| 61 |
define( 'WBTE_EWB_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); |
| 62 |
|
| 63 |
/** |
| 64 |
* Database schema version. |
| 65 |
* |
| 66 |
* @since 1.0.0 |
| 67 |
*/ |
| 68 |
define( 'WBTE_EWB_DB_VERSION', '1.1.0' ); |
| 69 |
|
| 70 |
/** |
| 71 |
* Declare HPOS compatibility. |
| 72 |
* |
| 73 |
* @since 1.0.0 |
| 74 |
*/ |
| 75 |
add_action( |
| 76 |
'before_woocommerce_init', |
| 77 |
function () { |
| 78 |
if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) { |
| 79 |
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( |
| 80 |
'custom_order_tables', |
| 81 |
__FILE__, |
| 82 |
true |
| 83 |
); |
| 84 |
} |
| 85 |
} |
| 86 |
); |
| 87 |
|
| 88 |
/** |
| 89 |
* Check if WooCommerce is active before initialising. |
| 90 |
* |
| 91 |
* @since 1.0.0 |
| 92 |
* |
| 93 |
* @return bool |
| 94 |
*/ |
| 95 |
function wbte_ewb_is_woocommerce_active() { |
| 96 |
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Core filter name. |
| 97 |
return in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ), true ) |
| 98 |
|| ( is_multisite() && array_key_exists( 'woocommerce/woocommerce.php', get_site_option( 'active_sitewide_plugins', array() ) ) ); |
| 99 |
} |
| 100 |
|
| 101 |
/** |
| 102 |
* Display an admin notice if WooCommerce is not active. |
| 103 |
* |
| 104 |
* @since 1.0.0 |
| 105 |
*/ |
| 106 |
function wbte_ewb_woocommerce_missing_notice() { |
| 107 |
?> |
| 108 |
<div class="notice notice-error"> |
| 109 |
<p> |
| 110 |
<?php |
| 111 |
echo esc_html__( |
| 112 |
'WebToffee EU Withdrawal Button for WooCommerce requires WooCommerce to be installed and active.', |
| 113 |
'wt-eu-withdrawal-button' |
| 114 |
); |
| 115 |
?> |
| 116 |
</p> |
| 117 |
</div> |
| 118 |
<?php |
| 119 |
} |
| 120 |
|
| 121 |
// Activation / deactivation hooks (must be registered before any conditional returns). |
| 122 |
require_once WBTE_EWB_PLUGIN_DIR . 'includes/class-wbte-ewb-activator.php'; |
| 123 |
require_once WBTE_EWB_PLUGIN_DIR . 'includes/class-wbte-ewb-deactivator.php'; |
| 124 |
|
| 125 |
register_activation_hook( __FILE__, array( 'Wbte_Ewb_Activator', 'activate' ) ); |
| 126 |
register_deactivation_hook( __FILE__, array( 'Wbte_Ewb_Deactivator', 'deactivate' ) ); |
| 127 |
|
| 128 |
if ( ! wbte_ewb_is_woocommerce_active() ) { |
| 129 |
add_action( 'admin_notices', 'wbte_ewb_woocommerce_missing_notice' ); |
| 130 |
return; |
| 131 |
} |
| 132 |
|
| 133 |
// Bootstrap the plugin. |
| 134 |
require_once WBTE_EWB_PLUGIN_DIR . 'includes/class-wbte-ewb-plugin.php'; |
| 135 |
|
| 136 |
/** |
| 137 |
* Return the singleton plugin instance. |
| 138 |
* |
| 139 |
* @since 1.0.0 |
| 140 |
* |
| 141 |
* @return Wbte_Ewb_Plugin |
| 142 |
*/ |
| 143 |
function wbte_ewb() { |
| 144 |
return Wbte_Ewb_Plugin::instance(); |
| 145 |
} |
| 146 |
|
| 147 |
// Ignition. |
| 148 |
wbte_ewb(); |
| 149 |
|