diff --git a/includes/abstracts/abstract-wp-job-manager-form.php b/includes/abstracts/abstract-wp-job-manager-form.php index 9dca801fe..dfadf11c9 100644 --- a/includes/abstracts/abstract-wp-job-manager-form.php +++ b/includes/abstracts/abstract-wp-job-manager-form.php @@ -136,7 +136,7 @@ public function process() { * @param array $atts Attributes to use in the view handler. */ public function output( $atts = [] ) { - WP_Job_Manager\WP_Job_Manager_Recaptcha::enqueue_scripts(); + WP_Job_Manager\WP_Job_Manager_Recaptcha::enqueue_recaptcha(); $step_key = $this->get_step_key( $this->step ); $this->show_errors(); $this->show_messages(); @@ -323,7 +323,7 @@ public function clear_fields() { */ public function enqueue_scripts() { _deprecated_function( __METHOD__, '$$next-version$$', 'WP_Job_Manager\WP_Job_Manager_Form::enqueue_scripts' ); - WP_Job_Manager\WP_Job_Manager_Recaptcha::enqueue_scripts(); + WP_Job_Manager\WP_Job_Manager_Recaptcha::enqueue_recaptcha(); } /** diff --git a/includes/class-wp-job-manager-recaptcha.php b/includes/class-wp-job-manager-recaptcha.php index a16d4a83e..792979ad5 100644 --- a/includes/class-wp-job-manager-recaptcha.php +++ b/includes/class-wp-job-manager-recaptcha.php @@ -55,12 +55,6 @@ private function __construct() { $this->site_key = get_option( self::RECAPTCHA_SITE_KEY ); $this->secret_key = get_option( self::RECAPTCHA_SECRET_KEY ); $this->recaptcha_version = get_option( self::RECAPTCHA_VERSION, 'v2' ); - - if ( $this->use_recaptcha_field() ) { - add_action( 'submit_job_form_end', [ $this, 'display_recaptcha_field' ] ); - add_filter( 'submit_job_form_validate_fields', [ $this, 'validate_recaptcha_field' ] ); - add_filter( 'submit_draft_job_form_validate_fields', [ $this, 'validate_recaptcha_field' ] ); - } } /** @@ -76,11 +70,17 @@ public function use_recaptcha_field() { } /** - * Enqueue the scripts for the form. + * Enqueue the scripts and add appropriate hooks for the recaptcha to load. */ - public static function enqueue_scripts() { + public static function enqueue_recaptcha() { $instance = self::instance(); + if ( $instance->use_recaptcha_field() ) { + add_action( 'submit_job_form_end', [ $instance, 'display_recaptcha_field' ] ); + add_filter( 'submit_job_form_validate_fields', [ $instance, 'validate_recaptcha_field' ] ); + add_filter( 'submit_draft_job_form_validate_fields', [ $instance, 'validate_recaptcha_field' ] ); + } + if ( $instance->use_recaptcha_field() && in_array( $instance->recaptcha_version, [ 'v2', 'v3' ], true )