Files
ogre-captcha/ogre-captcha.php
2026-07-15 10:22:44 -05:00

128 lines
4.2 KiB
PHP

<?php
/**
* Ogre CAPTCHA
*
* @package ogre-captcha
* @author cleverogre
* @copyright 2026 CleverOgre
* @license GLP-3.0-or-later
* @version 1.2.6
* @since 1.0.0
*
* @wordpress-plugin
* Plugin Name: Ogre CAPTCHA
* Plugin URI: https://git.cleverogre.com/cleverogre/ogre-captcha/
* Description: Protect your site with CAPTCHA
* Version: 1.2.6
* Requires at least: 6.0
* Requires PHP: 8.2
* Author: CleverOgre
* Author URI: https://cleverogre.com/
* Text Domain: ogre-captcha
* License: GPLv3 or later
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
* Update URI: https://git.cleverogre.com/cleverogre/ogre-captcha/
* Domain Path: /lang
* Icon1x: https://plugins.cleverogre.com/wp-content/uploads/ogre-captcha-icon-128x128.png
* Icon2x: https://plugins.cleverogre.com/wp-content/uploads/ogre-captcha-icon-256x256.png
* BannerLow: https://plugins.cleverogre.com/wp-content/uploads/ogre-captcha-banner-772x250.png
* BannerHigh: https://plugins.cleverogre.com/wp-content/uploads/ogre-captcha-banner-1544x500.png
* Require License: yes
*/
namespace Ogre;
use Ogre\Captcha\Settings;
use Ogre\Captcha\GravityForms\Addon;
use GFAddOn;
use Override;
defined('ABSPATH') || exit;
require_once 'vendor/autoload.php';
if (!class_exists('Ogre\Captcha')) {
final class Captcha extends Plugin {
public static function is_woocommerce_active():bool {
return is_plugin_active('woocommerce/woocommerce.php');
}
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');
}
}
#[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);
}
}
Captcha::instance();
}