Blocking Specific Email Addresses on Registration

Welcome mkmcst community Forum Web programming WordPress Ultimate Member Code Examples Blocking Specific Email Addresses on Registration

Viewing 0 reply threads
  • Author
    Posts
    • #2633
      michael mc
      Keymaster
      @michael

      Ultimate Member allows you to block specific email addresses from registering or signing in on your site.

      Go to wp-admin> Ultimate Member> Settings > Access> Others.
      To block multiple email addresses, you must use one blocked email address per line.

      If you encounter any issues or a security configuration warning message appears. You can try and use this code:

      function um_102621_blockedemails( $args ) {
      
          $emails = UM()->options()->get( 'blocked_emails' );
          if ( ! $emails ) {
              return;
          }
      
          $emails = array_map( 'rtrim', explode( "\n", $emails ) );
      
          if ( isset( $args['user_email'] ) && is_email( $args['user_email'] ) ) {
      
              $domain = explode( '@', $args['user_email'] );
              $check_domain = str_replace( $domain[0], '*', $args['user_email'] );
      
              if ( in_array( strtolower( $args['user_email'] ), $emails ) ) {
                  exit( wp_redirect( esc_url( add_query_arg( 'err', 'blocked_email' ) ) ) );
              }
      
              if ( in_array( strtolower( $check_domain ), $emails ) ) {
                  exit( wp_redirect( esc_url( add_query_arg( 'err', 'blocked_domain' ) ) ) );
              }
      
          }
      
          if ( isset( $args['username'] ) && is_email( $args['username'] ) ) {
      
              $domain = explode( '@', $args['username'] );
              $check_domain = str_replace( $domain[0], '*', $args['username'] );
      
              if ( in_array( strtolower( $args['username'] ), $emails ) ) {
                  exit( wp_redirect( esc_url( add_query_arg( 'err', 'blocked_email' ) ) ) );
              }
      
              if ( in_array( strtolower( $check_domain ), $emails ) ) {
                  exit( wp_redirect( esc_url( add_query_arg( 'err', 'blocked_domain' ) ) ) );
              }
      
          }
      }
      
      add_action( 'um_submit_form_errors_hook__blockedemails', 'um_102621_blockedemails', 10 );
      remove_action( 'um_submit_form_errors_hook__blockedemails', 'um_submit_form_errors_hook__blockedemails', 10 );
      Change one line from the code above as indicated below to block multiple email addresses by using a comma as a separator.
      
      $emails = array_map( 'rtrim', explode( ",", $emails ) );
      
Viewing 0 reply threads
  • You must be logged in to reply to this topic.