我为网站访问者提供了一个自定义登录页面,并希望包含"使用Facebook登录"按钮,以便应用程序检查用户电子邮件是否已注册,如果已注册,则会让用户登录。
使用wp_signon,我可以通过提供电子邮件和密码来登录用户,但在这种情况下,我没有用户的密码,所以有没有一种方法可以在不使用插件的情况下提供Facebook登录按钮?
如果你想在没有插件的情况下实现它,那么你需要自己实现OAuth。你可以使用这篇文章作为参考,从零开始为你的主题创建一个没有插件的facebook登录按钮。
WordPress前端Facebook登录
使用此代码并将APP ID替换为和您的域。。。
<html>
<head>
<title>Login with Facebook</title>
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'YOUR_APP_ID', // App ID
channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
};
// Load the SDK Asynchronously
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
</script>
<div class="fb-login-button">Login with Facebook</div>
</body>