[wp-trac] [WordPress Trac] #51379: Add filter to function email_exists()

WordPress Trac noreply at wordpress.org
Wed Sep 23 09:24:43 UTC 2020


#51379: Add filter to function email_exists()
-----------------------------+-----------------------------
 Reporter:  apermo           |      Owner:  (none)
     Type:  feature request  |     Status:  new
 Priority:  normal           |  Milestone:  Awaiting Review
Component:  General          |    Version:  trunk
 Severity:  normal           |   Keywords:  has-patch
  Focuses:                   |
-----------------------------+-----------------------------
 At a current project I'm running WordPress together with a third party
 tool that is the leading system for the user data, but I'm also able to
 register new users, obviously I want to throw an error if a username or an
 e-mail address is already taken.

 In case of the function `username_exists` a filter has been added in 4.9
 that I can use just for this.

 With this addition the same functionality would be available for
 `email_exists()` as well

 {{{#!php
 <?php
 /**
  * Determines whether the given email exists.
  *
  * For more information on this and similar theme functions, check out
  * the {@link https://developer.wordpress.org/themes/basics/conditional-
 tags/
  * Conditional Tags} article in the Theme Developer Handbook.
  *
  * @since 2.1.0
  *
  * @param string $email Email.
  * @return int|false The user's ID on success, and false on failure.
  */
 function email_exists( $email ) {
         $user = get_user_by( 'email', $email );
         if ( $user ) {
                 $user_id = $user->ID;
         } else {
                 $user_id = false;
         }

         /**
          * Filters whether the given email exists or not.
          *
          * @since TBD
          *
          * @param int|false $user_id The user's ID on success, and false
 on failure.
          * @param string    $email   Email.
          */
         return apply_filters( 'email_exists', $user_id, $email );
 }
 }}}

 The filter name is in line with what is used in `username_exists` and is
 checked to be unused within WordPress Core.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/51379>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list