gglcptch_whitelisted_ip

The Google Captcha (reCAPTCHA) by BestWebSoft gglcptch whitelisted ip function.

Description

gglcptch_whitelisted_ip(); 

Usage

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

Defined (1)

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

/google-captcha.php  
  1. function gglcptch_whitelisted_ip() { 
  2. global $wpdb, $gglcptch_options; 
  3. $checked = false; 
  4. if ( empty( $gglcptch_options ) ) 
  5. $gglcptch_options = get_option( 'gglcptch_options' ); 
  6. $whitelist_exist = $wpdb->query( "SHOW TABLES LIKE '{$wpdb->prefix}gglcptch_whitelist'" ); 
  7. if ( 1 === $whitelist_exist ) { 
  8. $ip = ''; 
  9. if ( isset( $_SERVER ) ) { 
  10. $server_vars = array( 'HTTP_X_REAL_IP', 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'REMOTE_ADDR' ); 
  11. foreach( $server_vars as $var ) { 
  12. if ( isset( $_SERVER[ $var ] ) && ! empty( $_SERVER[ $var ] ) ) { 
  13. if ( filter_var( $_SERVER[ $var ], FILTER_VALIDATE_IP ) ) { 
  14. $ip = $_SERVER[ $var ]; 
  15. break; 
  16. } else { /** if proxy */ 
  17. $ip_array = explode( ', ', $_SERVER[ $var ] ); 
  18. if ( is_array( $ip_array ) && ! empty( $ip_array ) && filter_var( $ip_array[0], FILTER_VALIDATE_IP ) ) { 
  19. $ip = $ip_array[0]; 
  20. break; 
  21.  
  22. if ( ! empty( $ip ) ) { 
  23. $ip_int = sprintf( '%u', ip2long( $ip ) ); 
  24. $result = $wpdb->get_var( 
  25. "SELECT `id` 
  26. FROM `{$wpdb->prefix}gglcptch_whitelist` 
  27. WHERE ( `ip_from_int` <= {$ip_int} AND `ip_to_int` >= {$ip_int} ) OR `ip` LIKE '{$ip}' LIMIT 1;" 
  28. ); 
  29. $checked = is_null( $result ) || ! $result ? false : true; 
  30. } else { 
  31. $checked = false; 
  32. return $checked;