2017-12-01 9 views
0

Wordpressの資格情報でログインするには、wordpress "users"テーブルに接続するログインフォームを作成する必要があります。ユーザデータベースからのログインWordpress PHP

どうすればいいですか?

感謝:)

+0

あなたはこれまで何をしていますか? – Allan

+0

ここで進捗状況を更新してみるか、質問する前にhttps://stackoverflow.com/help/how-to-askを確認してください –

答えて

0

は、この意志はあなたを助けCheck from url

<?php wp_login_form(); ?> 

希望、

if (is_user_logged_in()) { 
    wp_redirect(get_site_url()); 
} 

//verfaying credentials. if yes redirects to login 
if (isset($_POST['sbtn-login'])) { 
global $error; 
$error = false; 
$emailid = $_POST['txt_email']; 
$password = $_POST['txt_password']; 

if (isset($emailid) && isset($password)) { 
    if ($emailid == "") { 
     $error = "Please fill the email id !"; 
    } elseif ($password == "") { 
     $error = "Please fill the password !"; 
    } else { 
     $creds = array(); 
     $creds['user_login'] = $emailid; 
     $creds['user_password'] = $password; 
     $creds['remember'] = true; 

     //verifying credentials 
     if (!email_exists($emailid)) { 
      $error = "Please try a valid email address !"; 
     } else { 
      $user = wp_signon($creds, false); 
      if (is_wp_error($user)) { 
       $error = "The password you entered for the email address " . $emailid . " is incorrect."; 
      } else { 
       wp_set_current_user($user->ID); 
       wp_safe_redirect(site_url()); 
       exit(); 
      } 
     } 
    } 
} 
} 

それとも、WordPressの機能を使用することができ、自分のフォームでこのスニペットを試してみてください。