diff --git a/inc/class-settings.php b/inc/class-settings.php index c8126af..ded856c 100644 --- a/inc/class-settings.php +++ b/inc/class-settings.php @@ -28,6 +28,11 @@ final class Settings { public const LOCATION_COMMENT_FORM = 'comment_form'; public const LOCATION_POST_PASSWORD_FORM = 'post_password_form'; + public const LOCATION_WC_LOGIN = 'wc_login'; + public const LOCATION_WC_LOST_PASSWORD = 'wc_lost_password'; + public const LOCATION_WC_REGISTER = 'wc_register'; + public const LOCATION_WC_CHECKOUT = 'wc_checkout'; + protected function __construct() { add_action('admin_menu', [$this, 'menu']); add_action('admin_init', [$this, 'init']); @@ -70,7 +75,14 @@ final class Settings { } public static function get_form_locations():array { - return (array) self::get('form_locations'); + $form_locations = (array) self::get('form_locations'); + if (Plugin::is_woocommerce_active()) { + $form_locations = array_merge( + $form_locations, + (array) self::get('wc_form_locations') + ); + } + return $form_locations; } public static function is_form_location_enabled(string $name):bool { @@ -101,6 +113,22 @@ final class Settings { return self::is_form_location_enabled(self::LOCATION_POST_PASSWORD_FORM); } + public static function is_wc_login_enabled():bool { + return self::is_form_location_enabled(self::LOCATION_WC_LOGIN); + } + + public static function is_wc_lost_password_enabled():bool { + return self::is_form_location_enabled(self::LOCATION_WC_LOST_PASSWORD); + } + + public static function is_wc_register_enabled():bool { + return self::is_form_location_enabled(self::LOCATION_WC_REGISTER); + } + + public static function is_wc_checkout_enabled():bool { + return self::is_form_location_enabled(self::LOCATION_WC_CHECKOUT); + } + public function menu() { if (!current_user_can(self::CAPABILITY)) return; add_options_page( @@ -176,7 +204,7 @@ final class Settings { add_settings_field( Plugin::get_id() . '_form_locations', - Plugin::__('Form locations'), + Plugin::__('WordPress form locations'), [$this, 'checkbox_field'], Plugin::get_id(), 'forms', @@ -193,6 +221,25 @@ final class Settings { 'description' => Plugin::__('Custom login form requires login page to also be enabled.'), ] ); + + if (Plugin::is_woocommerce_active()) { + add_settings_field( + Plugin::get_id() . '_wc_form_locations', + Plugin::__('WooCommerce form locations'), + [$this, 'checkbox_field'], + Plugin::get_id(), + 'forms', + [ + 'name' => 'wc_form_locations', + 'options' => [ + self::LOCATION_WC_LOGIN => Plugin::__('Login form'), + self::LOCATION_WC_LOST_PASSWORD => Plugin::__('Lost password form'), + self::LOCATION_WC_REGISTER => Plugin::__('Register form'), + self::LOCATION_WC_CHECKOUT => Plugin::__('Checkout form'), + ], + ] + ); + } } public function page() { diff --git a/inc/location/woocommerce/class-checkout.php b/inc/location/woocommerce/class-checkout.php new file mode 100644 index 0000000..4743552 --- /dev/null +++ b/inc/location/woocommerce/class-checkout.php @@ -0,0 +1,45 @@ +process($errors); + } + +} + +Checkout::instance(); diff --git a/inc/location/woocommerce/class-login.php b/inc/location/woocommerce/class-login.php new file mode 100644 index 0000000..3bd913a --- /dev/null +++ b/inc/location/woocommerce/class-login.php @@ -0,0 +1,48 @@ +process($validation_error); + return $validation_error; + } + +} + +Login::instance(); diff --git a/inc/location/woocommerce/class-lost-password.php b/inc/location/woocommerce/class-lost-password.php new file mode 100644 index 0000000..43f6e95 --- /dev/null +++ b/inc/location/woocommerce/class-lost-password.php @@ -0,0 +1,49 @@ +process($errors); + // NOTE: Potentially use `allow_password_reset` to display error message? + } + +} + +LostPassword::instance(); diff --git a/inc/location/woocommerce/class-register.php b/inc/location/woocommerce/class-register.php new file mode 100644 index 0000000..ca78875 --- /dev/null +++ b/inc/location/woocommerce/class-register.php @@ -0,0 +1,48 @@ +process($validation_error); + return $validation_error; + } + +} + +Register::instance(); diff --git a/ogre-captcha.php b/ogre-captcha.php index b69cfe0..21a77f3 100644 --- a/ogre-captcha.php +++ b/ogre-captcha.php @@ -35,6 +35,10 @@ require_once 'vendor/autoload.php'; final class Captcha extends Plugin { + public static function is_woocommerce_active():bool { + return is_plugin_active('woocommerce/woocommerce.php'); + } + protected function __construct() { parent::__construct(); @@ -50,6 +54,8 @@ final class Captcha extends Plugin { 'inc/location/class-post-password-form.php', 'inc/location/class-registration-page.php', ]); + + add_action('plugins_loaded', [$this, 'load_woocommerce'], 9, 0); } protected function enable():void { @@ -62,7 +68,7 @@ final class Captcha extends Plugin { remove_filter('plugin_action_links_' . self::get_basename(), [$this, 'action_links']); } - public function action_links($links) { + public function action_links(array $links):array { if (current_user_can('manage_options')) { array_unshift($links, sprintf( '%s', @@ -73,6 +79,17 @@ final class Captcha extends Plugin { 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', + ]); + } + } Captcha::instance();