wpcf7_recaptcha_callback_script

The Contact Form 7 wpcf7 recaptcha callback script function.

Description

wpcf7_recaptcha_callback_script(); 

Usage

  1. if ( !function_exists( 'wpcf7_recaptcha_callback_script' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'contact-form-7/modules/recaptcha.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wpcf7_recaptcha_callback_script(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/modules/recaptcha.php  
  1. function wpcf7_recaptcha_callback_script() { 
  2. if ( ! wp_script_is( 'google-recaptcha', 'enqueued' ) ) { 
  3. return; 
  4.  
  5. ?> 
  6. <script type="text/javascript"> 
  7. var recaptchaWidgets = []; 
  8. var recaptchaCallback = function() { 
  9. var forms = document.getElementsByTagName('form'); 
  10. var pattern = /(^|\s)g-recaptcha(\s|$)/; 
  11.  
  12. for (var i = 0; i < forms.length; i++) { 
  13. var divs = forms[i].getElementsByTagName('div'); 
  14.  
  15. for (var j = 0; j < divs.length; j++) { 
  16. var sitekey = divs[j].getAttribute('data-sitekey'); 
  17.  
  18. if (divs[j].className && divs[j].className.match(pattern) && sitekey) { 
  19. var params = { 
  20. 'sitekey': sitekey,  
  21. 'theme': divs[j].getAttribute('data-theme'),  
  22. 'type': divs[j].getAttribute('data-type'),  
  23. 'size': divs[j].getAttribute('data-size'),  
  24. 'tabindex': divs[j].getAttribute('data-tabindex') 
  25. }; 
  26.  
  27. var callback = divs[j].getAttribute('data-callback'); 
  28.  
  29. if (callback && 'function' == typeof window[callback]) { 
  30. params['callback'] = window[callback]; 
  31.  
  32. var expired_callback = divs[j].getAttribute('data-expired-callback'); 
  33.  
  34. if (expired_callback && 'function' == typeof window[expired_callback]) { 
  35. params['expired-callback'] = window[expired_callback]; 
  36.  
  37. var widget_id = grecaptcha.render(divs[j], params); 
  38. recaptchaWidgets.push(widget_id); 
  39. break; 
  40. </script> 
  41. <?php