-
AuthorPosts
-
August 5, 2020 at 11:57 am #1235377
While playing around with the new version of my website, I came up with an Idea for the recaptcha script used by the widely spreaded CF7 plugin. Use the following snipet to load recaptcha only if the visitor has given his permission to do so.
// recaptcha only if consent cookie function ss_wpcf7_recaptcha_enqueue_scripts() { $googlerecaptchacookie = 'aviaPrivacyGoogleReCaptchaDisabled'; $enable_recaptcha = false; if (array_key_exists($googlerecaptchacookie, $_COOKIE) && isset($_COOKIE[$googlerecaptchacookie])) { $disable_recaptcha_check = boolval ($_COOKIE[$googlerecaptchacookie]); $enable_recaptcha = $disable_recaptcha_check; } else { $enable_recaptcha = true; } if($enable_recaptcha): $service = WPCF7_RECAPTCHA::get_instance(); if ( ! $service->is_active() ) { return; } wp_enqueue_script( 'google-recaptcha', add_query_arg( array( 'render' => $service->get_sitekey(), ), 'https://www.google.com/recaptcha/api.js' ), array(), '3.0', true ); wp_enqueue_script( 'wpcf7-recaptcha', wpcf7_plugin_url( 'modules/recaptcha/script.js' ), array( 'google-recaptcha' ), WPCF7_VERSION, true ); wp_localize_script( 'wpcf7-recaptcha', 'wpcf7_recaptcha', array( 'sitekey' => $service->get_sitekey(), 'actions' => apply_filters( 'wpcf7_recaptcha_actions', array( 'homepage' => 'homepage', 'contactform' => 'contactform', ) ), ) ); endif; } remove_action( 'wp_enqueue_scripts', 'wpcf7_recaptcha_enqueue_scripts', 10, 0 ); add_action( 'wp_enqueue_scripts', 'ss_wpcf7_recaptcha_enqueue_scripts', 10, 0 );
Maybe this is useful for someone, so I share that here.
August 6, 2020 at 10:29 am #1235644August 6, 2020 at 2:48 pm #1235749is there anything to adjust in your code – that it works?
Where did you enter the api key on cf7 integration – or on Enfold Options?Thanks
August 6, 2020 at 4:04 pm #1235786The api key has to be entered into the CF7 plugin settings, submenu integrations. The code is basically copied from the original CF7 plugin, wrapped with a little check and then readded. Works like a charm on my site.
August 6, 2020 at 5:49 pm #1235811Nice – thanks for the code.
I prefer my borlabs cookie – but this is a good addition for enfold usage. -
AuthorPosts
- You must be logged in to reply to this topic.