Advertisement
beatter

[WP] Contact Form 7 - Block Domains

Mar 14th, 2012
1,391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.19 KB | None | 0 0
  1. function wpcf7_text_validation_filter( $result, $tag ) {
  2.     /* Array of free email domains */
  3.     $FREE_DOMAINS = array('gmail.com', 'yahoo.com', 'hotmail.com');
  4.    
  5.     $type = $tag['type'];
  6.     $name = $tag['name'];
  7.  
  8.     $_POST[$name] = trim( strtr( (string) $_POST[$name], "\n", " " ) );
  9.  
  10.     if ( 'text*' == $type ) {
  11.         if ( '' == $_POST[$name] ) {
  12.             $result['valid'] = false;
  13.             $result['reason'][$name] = wpcf7_get_message( 'invalid_required' );
  14.         }
  15.     }
  16.  
  17.     if ( 'email' == $type || 'email*' == $type ) {
  18.         $arr = explode( '@', $_POST[$name] );
  19.         if( ! empty( $arr[1] ) ){
  20.             $domain = strtolower( trim( $arr[1] ) );
  21.         } else {
  22.             $domain = false;
  23.         }
  24.        
  25.         if ( 'email*' == $type && '' == $_POST[$name] ) {
  26.             $result['valid'] = false;
  27.             $result['reason'][$name] = wpcf7_get_message( 'invalid_required' );
  28.         } elseif ( '' != $_POST[$name] && ! is_email( $_POST[$name] ) ) {
  29.             $arr = explode( '@', $_POST[$name] );
  30.             $result['valid'] = false;
  31.             $result['reason'][$name] = wpcf7_get_message( 'invalid_email' );
  32.         } elseif ( $domain && in_array( $domain, $FREE_DOMAINS ) ) {
  33.             $result['valid'] = false;
  34.             $result['reason'][$name] = wpcf7_get_message( 'invalid_email' );
  35.         }
  36.     }
  37.  
  38.     return $result;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement