Home> CMS Tutorial> WordPress> body text

Set up a password-free WordPress login form

藏色散人
Release: 2021-05-08 11:48:15
forward
1571 people have browsed it

The following columnWordPress Tutorialwill introduce to you how to set up a WordPress login form without entering a password. I hope it will be helpful to friends in need!

WordPress login form without entering password

If you want to add a form in your WordPress theme that does not require entering a password, just enter your username or email to log in , which can be achieved using the following method.

Copy the following code and paste it where you want to display the form

Copy after login

Then, paste the following code into the theme function template functions.php:

add_action('init', function(){ // Return if not the login request if( !isset( $_POST['action'] ) || $_POST['action'] !== 'my_login_action' ) return; $result; $username = $_POST['userlog']; if ( ! $result ) { $result = get_user_by( 'email', $username ); // user email } if ( ! $result ) { $result = get_user_by('login', $username ); // user name } if ( !is_wp_error($result) ){ wp_clear_auth_cookie(); wp_set_current_user($result->ID); wp_set_auth_cookie($result->ID); wp_redirect( home_url( '/' ) ); exit; } die(); });
Copy after login

Only suitable for specific occasions Use, under normal circumstances if others know your login information, it is very risky to use this function...

The above is the detailed content of Set up a password-free WordPress login form. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:zmingcx.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!