Bug in displaying Google Recpatcha
-
Hello. We are a paying customer of WP Job Manager.
We develop our own theme. Our plugins are up to date. Our version of WP Job Manger is Version 2.4.0.
The issue is that on our submit-job page, using the shortcode
[submit_job_form]. When you first load the page, our recpatcha field “Are you human?” does not appear. There are no browser console errors. The script for recaptcha from Google is not loaded. If you fill out the form fully and click submit, you will receive a validation error that recpatcha did not validate. The recaptcha field now displays and you are able to submit the form.In summary, the recaptcha field only displays after the first form submission.
We have Recpatcha configured in WP Job Manager settings. V2 checkbox. Site/secret key are correct. “Display a CATPCHA field on your job submission form.” is checked.
I have debugged the site. The bug is that WP Job Manager attempts to load the recpatcha ‘https://www.google.com/recaptcha/api.js’ too late in WordPress’s request life cycle. WP Job Manager is triggered by finding the shortcode
[submit_job_form]. Unfortunately, that is after the wp_enqueue_scripts action has executed. Because of this, .google.com/recaptcha/api.js is never added to the page. Please see this demonstrated in the screenshot below.
(html\wp-content\plugins\wp-job-manager\includes\class-wp-job-manager-recaptcha.php ALT Image is a screenshot of Visual Studio Code while debugging class-wp-job-manager-recaptcha.php. The debugger call stack shows the code was triggered by do_shortcode. The code in class-wp-job-manager-recaptcha.php adds to wp_enqueue_scripts too late so the method enqueue_scripts is never called. )
Let’s see what happens after the form is submitted where recpatcha is loaded correctly.

( ALT image is a screenshot of Visual Studio Code while debugging class-wp-job-manager-recaptcha.php. The debugger call stack shows the code was triggered by load_posted_form. The code in class-wp-job-manager-recaptcha.php adds to wp_enqueue_scripts earlier enough in the request that enqueue scripts is called. )
We can see here the wp_enqueue_scripts action is added early enough in the life cycle that enqueue_scripts does get called, google.com/recaptcha/api.js is added to the page, and the recpatcha field is loaded correctly.
We believe this is a bug in the WP Job Manager Plugin and have not yet found a workaround.
The topic ‘Bug in displaying Google Recpatcha’ is closed to new replies.