Skip to content

Commit

Permalink
Add recaptch hooks on script enqueue
Browse files Browse the repository at this point in the history
Previously the hooks where added on instance creation which
would cause the hooks to be added on the job edit form and break
it.
  • Loading branch information
gikaragia committed Apr 9, 2024
1 parent d92678f commit 4614460
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions includes/abstracts/abstract-wp-job-manager-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}

/**
Expand Down
16 changes: 8 additions & 8 deletions includes/class-wp-job-manager-recaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ] );
}
}

/**
Expand All @@ -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 )
Expand Down

0 comments on commit 4614460

Please sign in to comment.