Prevent double loading
This commit is contained in:
+75
-71
@@ -41,83 +41,87 @@ defined('ABSPATH') || exit;
|
||||
|
||||
require_once 'vendor/autoload.php';
|
||||
|
||||
final class Captcha extends Plugin {
|
||||
if (!class_exists('Ogre\Captcha')) {
|
||||
|
||||
public static function is_woocommerce_active():bool {
|
||||
return is_plugin_active('woocommerce/woocommerce.php');
|
||||
}
|
||||
final class Captcha extends Plugin {
|
||||
|
||||
public static function is_gravityforms_active():bool {
|
||||
return is_plugin_active('gravityforms/gravityforms.php');
|
||||
}
|
||||
|
||||
protected function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
$this->add_files([
|
||||
'inc/class-settings.php',
|
||||
'inc/class-api.php',
|
||||
'inc/class-widget.php',
|
||||
'inc/abstract-location.php',
|
||||
'inc/location/class-comment-form.php',
|
||||
'inc/location/class-login-form.php',
|
||||
'inc/location/class-login-page.php',
|
||||
'inc/location/class-lost-password-form.php',
|
||||
'inc/location/class-post-password-form.php',
|
||||
'inc/location/class-registration-page.php',
|
||||
]);
|
||||
|
||||
if (class_exists('WP_CLI')) {
|
||||
$this->add_file('inc/class-cli.php');
|
||||
public static function is_woocommerce_active():bool {
|
||||
return is_plugin_active('woocommerce/woocommerce.php');
|
||||
}
|
||||
}
|
||||
|
||||
#[Override]
|
||||
protected function enable():void {
|
||||
parent::enable();
|
||||
add_filter('plugin_action_links_' . self::get_basename(), [$this, 'action_links']);
|
||||
add_action('plugins_loaded', [$this, 'load_woocommerce'], 2, 0);
|
||||
add_action('gform_loaded', [$this, 'load_gravityforms'], 5, 0);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
protected function disable():void {
|
||||
parent::disable();
|
||||
remove_filter('plugin_action_links_' . self::get_basename(), [$this, 'action_links']);
|
||||
remove_action('plugins_loaded', [$this, 'load_woocommerce'], 2);
|
||||
remove_action('gform_loaded', [$this, 'load_gravityforms'], 5);
|
||||
}
|
||||
|
||||
public function action_links(array $links):array {
|
||||
if (current_user_can('manage_options')) {
|
||||
array_unshift($links, sprintf(
|
||||
'<a href="%s">%s</a>',
|
||||
esc_url(Settings::get_url()),
|
||||
esc_html(self::__('Settings'))
|
||||
));
|
||||
public static function is_gravityforms_active():bool {
|
||||
return is_plugin_active('gravityforms/gravityforms.php');
|
||||
}
|
||||
return $links;
|
||||
|
||||
protected function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
$this->add_files([
|
||||
'inc/class-settings.php',
|
||||
'inc/class-api.php',
|
||||
'inc/class-widget.php',
|
||||
'inc/abstract-location.php',
|
||||
'inc/location/class-comment-form.php',
|
||||
'inc/location/class-login-form.php',
|
||||
'inc/location/class-login-page.php',
|
||||
'inc/location/class-lost-password-form.php',
|
||||
'inc/location/class-post-password-form.php',
|
||||
'inc/location/class-registration-page.php',
|
||||
]);
|
||||
|
||||
if (class_exists('WP_CLI')) {
|
||||
$this->add_file('inc/class-cli.php');
|
||||
}
|
||||
}
|
||||
|
||||
#[Override]
|
||||
protected function enable():void {
|
||||
parent::enable();
|
||||
add_filter('plugin_action_links_' . self::get_basename(), [$this, 'action_links']);
|
||||
add_action('plugins_loaded', [$this, 'load_woocommerce'], 2, 0);
|
||||
add_action('gform_loaded', [$this, 'load_gravityforms'], 5, 0);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
protected function disable():void {
|
||||
parent::disable();
|
||||
remove_filter('plugin_action_links_' . self::get_basename(), [$this, 'action_links']);
|
||||
remove_action('plugins_loaded', [$this, 'load_woocommerce'], 2);
|
||||
remove_action('gform_loaded', [$this, 'load_gravityforms'], 5);
|
||||
}
|
||||
|
||||
public function action_links(array $links):array {
|
||||
if (current_user_can('manage_options')) {
|
||||
array_unshift($links, sprintf(
|
||||
'<a href="%s">%s</a>',
|
||||
esc_url(Settings::get_url()),
|
||||
esc_html(self::__('Settings'))
|
||||
));
|
||||
}
|
||||
return $links;
|
||||
}
|
||||
|
||||
public function load_woocommerce():void {
|
||||
if (!self::is_woocommerce_active()) return;
|
||||
|
||||
$this->add_files([
|
||||
'inc/location/woocommerce/class-checkout.php',
|
||||
'inc/location/woocommerce/class-login.php',
|
||||
'inc/location/woocommerce/class-lost-password.php',
|
||||
'inc/location/woocommerce/class-register.php',
|
||||
]);
|
||||
}
|
||||
|
||||
public function load_gravityforms():void {
|
||||
if (!self::is_gravityforms_active() || !method_exists('GFForms', 'include_addon_framework')) return;
|
||||
|
||||
require_once('inc/gravityforms/class-addon.php');
|
||||
|
||||
GFAddOn::register(Addon::class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function load_woocommerce():void {
|
||||
if (!self::is_woocommerce_active()) return;
|
||||
|
||||
$this->add_files([
|
||||
'inc/location/woocommerce/class-checkout.php',
|
||||
'inc/location/woocommerce/class-login.php',
|
||||
'inc/location/woocommerce/class-lost-password.php',
|
||||
'inc/location/woocommerce/class-register.php',
|
||||
]);
|
||||
}
|
||||
|
||||
public function load_gravityforms():void {
|
||||
if (!self::is_gravityforms_active() || !method_exists('GFForms', 'include_addon_framework')) return;
|
||||
|
||||
require_once('inc/gravityforms/class-addon.php');
|
||||
|
||||
GFAddOn::register(Addon::class);
|
||||
}
|
||||
Captcha::instance();
|
||||
|
||||
}
|
||||
|
||||
Captcha::instance();
|
||||
|
||||
Reference in New Issue
Block a user