fb custom plugin login problem
-
Hi I created a small fb login plugin as the usual ones do not work as the users are also registered in a separate database. My problem is suddenly if any user logs in they automatically login as this 1 user, and have access to his page and cannot login with their own fb “account” to their page.
I hope someone can help – thank you in advance
Below is the code:<?php /** * Plugin Name: fb_login * Description: Extends wp-login to use Facebook login. Uses email registered with fb to log in to WordPress. * Version: 1.0 * Author: Mel */ function javascript_init() { //if ($redirect_to == ''){$redirect_to = site_url();} if ($requested_redirect_to == ''){$redirect_to = site_url();}else{$redirect_to = $requested_redirect_to;} ?> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"><!--mce:0--></script> <script> window.fbAsyncInit = function() { FB.init({ appId : '699853586802508', xfbml : true, version : 'v2.5' }); }; (function(d, s, id){ var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) {return;} js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_US/sdk.js"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk')); </script> <script type="text/javascript"> function login_to_wp(email) { $.ajax({ type: "POST", url: "<?php echo plugins_url().'/fb_login/log_user_in.php'; ?>", data: ({user_email: email, path: "<?php echo ABSPATH; ?>"}), success: function(msg) { if (msg == 'true') { window.location.href = "<?php echo $redirect_to; ?>"; } else { document.getElementById('fb_login_message').innerHTML = 'There is no user with email: '+email; } } }); } </script> <?php } add_action('login_head', 'javascript_init'); function fb_message() { return '<div id="fb_login_message"></div>'; } add_filter('login_message', 'fb_message'); function facebook_login() { $url = site_url(); ?> <div class="login label">Connect with:</div> <div class="buttonspace"><div class="fb-login-button" data-max-rows="1" data-size="medium" data-show-faces="false" data-auto-logout-link="false" data-scope="public_profile, email" onlogin="checkLoginState()"></div></div> <div id="status"></div> <script type="text/javascript"> function checkLoginState() { FB.getLoginStatus(function(response) { statusChangeCallback(response); }); } function statusChangeCallback(response) { if (response.status === 'connected') { FB.api('/me', function(user_mail){ email = user_mail.email; login_to_wp(email); }); } else { document.getElementById('fb_login_message').innerHTML = 'Could not log in to Facebook'; } } </script> <?php } add_action( 'login_form', 'facebook_login' ); ?>
- The topic ‘fb custom plugin login problem’ is closed to new replies.