email – How to use the pluggable function get_user_by to apply changes in the value of the user’s mail field contained in the database

Question

I have chosen to render unusable/unreadable email adresses from database.

I added a few elements(chars) to email adress just after sending email to admin and user (user registration), and then I must remove these added elements to verify if email exists or display on user account or use for mailing list.

To decrypt the email I must use substr (remove elements added before) whith the value associated to $email field of get_user_by.
I read that email_exists use get_user_by which is a pluggable function. But I don’t know how to use the result of get_user_by inside email_exists.

Is it possible ? How should I do ?

        function get_user_by( 'email', $db_email ) {
            $ex = preg_split(''@'', $nr , -1);
            $dem = substr(substr($ex[0],2),0,-2);
            $rdem = substr($dem,0,2).substr($dem,2+1,strlen($dem)-2);
            $db_email = $rdem. '@' .$ex[1];
            
            $userdata = WP_User::get_data_by( 'email', $db_email );

            if ( ! $userdata ) {
                return false;
            }

            $user = new WP_User;
            $user->init( $userdata );

        return $user;
        }
        
        function email_exists( $email ) {
            $user = get_user_by( 'email', $db_email );
            if ( $user ) {
                $user_id = $user->ID;
            } else {
                $user_id = false;
            }
            return apply_filters( 'email_exists', $user_id, $email );
        }
        
        if (email_exists($email)){
            lq_errors()->add("emailexists","This email address already exist");
        }

0
imagIne 2 months 2021-03-17T05:08:53-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse