gglcptch_check

The Google Captcha (reCAPTCHA) by BestWebSoft gglcptch check function.

Description

gglcptch_check( (bool) $debug = false ); 

Parameters (1)

0. $debug — Optional. (bool) => false
The debug.

Usage

  1. if ( !function_exists( 'gglcptch_check' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'google-captcha-recaptcha-by-bestwebsoft/google-captcha.php'; 
  3.  
  4. // The debug. 
  5. $debug = false; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = gglcptch_check($debug); 
  9.  

Defined (1)

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

/google-captcha.php  
  1. function gglcptch_check( $debug = false ) { 
  2. global $gglcptch_options; 
  3.  
  4. if ( empty( $gglcptch_options ) ) 
  5.  
  6. $publickey = $gglcptch_options['public_key']; 
  7. $privatekey = $gglcptch_options['private_key']; 
  8.  
  9. if ( ! $privatekey || ! $publickey ) { 
  10. return array( 
  11. 'response' => false,  
  12. 'reason' => 'ERROR_NO_KEYS' 
  13. ); 
  14.  
  15. $gglcptch_remote_addr = filter_var( $_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP ); 
  16.  
  17. if ( 
  18. isset( $gglcptch_options['recaptcha_version'] ) && 
  19. in_array( $gglcptch_options['recaptcha_version'], array( 'v2', 'invisible' ) ) 
  20. ) { 
  21. if ( ! isset( $_POST["g-recaptcha-response"] ) ) { 
  22. return array( 
  23. 'response' => false,  
  24. 'reason' => 'RECAPTCHA_NO_RESPONSE' 
  25. ); 
  26. } elseif ( empty( $_POST["g-recaptcha-response"] ) ) { 
  27. return array( 
  28. 'response' => false,  
  29. 'reason' => 'RECAPTCHA_EMPTY_RESPONSE' 
  30. ); 
  31.  
  32. $response = gglcptch_get_response( $privatekey, $gglcptch_remote_addr ); 
  33.  
  34. if ( isset( $response['success'] ) && !! $response['success'] ) { 
  35. return array( 
  36. 'response' => true,  
  37. 'reason' => '' 
  38. ); 
  39. } else { 
  40. return array( 
  41. 'response' => false,  
  42. 'reason' => $debug ? $response['error-codes'] : 'VERIFICATION_FAILED' 
  43. ); 
  44. } else { 
  45. $gglcptch_recaptcha_challenge_field = $gglcptch_recaptcha_response_field = ''; 
  46.  
  47. if ( ! isset( $_POST['recaptcha_challenge_field'] ) && ! isset( $_POST['recaptcha_response_field'] ) ) { 
  48. return array( 
  49. 'response' => false,  
  50. 'reason' => 'RECAPTCHA_NO_RESPONSE' 
  51. ); 
  52. } elseif ( ! empty( $_POST['recaptcha_challenge_field'] ) && empty( $_POST['recaptcha_response_field'] ) ) { 
  53. return array( 
  54. 'response' => false,  
  55. 'reason' => 'RECAPTCHA_EMPTY_RESPONSE' 
  56. ); 
  57. } else { 
  58. $gglcptch_recaptcha_challenge_field = stripslashes( esc_html( $_POST['recaptcha_challenge_field'] ) ); 
  59. $gglcptch_recaptcha_response_field = stripslashes( esc_html( $_POST['recaptcha_response_field'] ) ); 
  60.  
  61. require_once( 'lib/recaptchalib.php' ); 
  62. $response = gglcptch_recaptcha_check_answer( $privatekey, $gglcptch_remote_addr, $gglcptch_recaptcha_challenge_field, $gglcptch_recaptcha_response_field ); 
  63.  
  64. if ( ! $response->is_valid ) { 
  65. return array( 
  66. 'response' => false,  
  67. 'reason' => $debug ? $response->error : 'VERIFICATION_FAILED' 
  68. ); 
  69. } else { 
  70. return array( 
  71. 'response' => true,  
  72. 'reason' => '' 
  73. );