This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!

[WP] Contact Form 7 - Block Domains

By: beatter on Mar 14th, 2012  |  syntax: PHP  |  size: 1.19 KB  |  views: 269  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }
clone this paste RAW Paste Data