首页 文章

wordpress页面中仅限Facebook的登录按钮

提问于
浏览
0

我需要在页面中插入一个仅限Facebook的登录按钮,不使用其中一个功能重定向(登录后的用户保持在同一页面上),如果可能的话创建一个短代码 . 这些功能来自网站上的活动插件 . 该插件管理所有wordpress登录,但我需要在一个页面上只登录Facebook .

add_action('userpro_inside_form_submit','userpro_social_connect');

function userpro_social_connect($array){

    global $userpro;



    // only in login/register

    if ($array['template'] == 'login' || $array['template'] == 'register' ) {



        echo '<div class="userpro-social-connect">';



        if (userpro_get_option('facebook_app_id') != '' && userpro_get_option('facebook_connect') == 1) {

            ?>



            <div id="fb-root" class="userpro-column"></div>

            <script>

            window.fbAsyncInit = function() {



                FB.init({

                    appId      : "<?php echo userpro_get_option('facebook_app_id'); ?>", // Set YOUR APP ID

                    status     : true, // check login status

                    cookie     : true, // enable cookies to allow the server to access the session

                    xfbml      : true  // parse XFBML

                });



                FB.Event.subscribe('auth.authResponseChange', function(response)

                {

                if (response.status === 'connected')

                {



                //SUCCESS



                }   

                else if (response.status === 'not_authorized')

                {



                //FAILED



                } else

                {



                //UNKNOWN ERROR



                }

                });



            };



            // Login user

            function Login(element){



                var form = jQuery(element).parents('.userpro').find('form');

                userpro_init_load( form );



                if ( element.data('redirect')) {

                    var redirect = element.data('redirect');

                } else {

                    var redirect = '';

                }



                FB.login(function(response) {

                    if (response.authResponse){



                        // post to wall

                        <?php if (userpro_get_option('facebook_autopost')) { ?>



                        <?php $scope = 'email,user_photos,publish_stream'; ?>



                        <?php if ( userpro_get_option('facebook_autopost_name') ) { ?>

                        var name = "<?php echo userpro_get_option('facebook_autopost_name'); ?>"; // post title

                        <?php } else { ?>

                        var name = '';

                        <?php } ?>



                        <?php if ( userpro_get_option('facebook_autopost_body') ) { ?>

                        var body = "<?php echo userpro_get_option('facebook_autopost_body'); ?>"; // post body

                        <?php } else { ?>

                        var body = '';

                        <?php } ?>



                        <?php if ( userpro_get_option('facebook_autopost_caption') ) { ?>

                        var caption = "<?php echo userpro_get_option('facebook_autopost_caption'); ?>"; // caption, url, etc.

                        <?php } else { ?>

                        var caption = '';

                        <?php } ?>



                        <?php if ( userpro_get_option('facebook_autopost_description') ) { ?>

                        var description = "<?php echo userpro_get_option('facebook_autopost_description'); ?>"; // full description

                        <?php } else { ?>

                        var description = '';

                        <?php } ?>



                        <?php if ( userpro_get_option('facebook_autopost_link') ) { ?>

                        var link = "<?php echo userpro_get_option('facebook_autopost_link'); ?>"; // link

                        <?php } else { ?>

                        var link = '';

                        <?php } ?>



                        FB.api('/me/feed', 'post', { message:body,caption:caption,link:link,name:name,description:description}, function (response) { });



                        <?php } else { $scope = 'email,user_photos'; } // end post to wall ?>



                        // get profile picture

                        FB.api('/me/picture?type=large', function(response) {

                            profilepicture = response.data.url;

                        });



                        // connect via facebook

                        FB.api('/me', function(response) {



                            jQuery.ajax({

                                url: userpro_ajax_url,

                                data: "action=userpro_fbconnect&id="+response.id+"&username="+response.username+"&first_name="+response.first_name+"&last_name="+response.last_name+"&gender="+response.gender+"&email="+response.email+"&name="+response.name+"&link="+response.link+"&profilepicture="+profilepicture+"&redirect="+redirect,

                                dataType: 'JSON',

                                type: 'POST',

                                success:function(data){



                                    userpro_end_load( form );



                                    /* custom message */

                                    if (data.custom_message){

                                    form.parents('.userpro').find('.userpro-body').prepend( data.custom_message );

                                    }



                                    /* redirect after form */

                                    if (data.redirect_uri){

                                        if (data.redirect_uri =='refresh') {

                                            document.location.href=jQuery(location).attr('href');

                                        } else {

                                            document.location.href=data.redirect_uri;

                                        }

                                    }



                                },

                                error: function(){

                                    alert('Something wrong happened.');

                                }

                            });



                        });



                    // cancelled

                    } else {

                        alert( 'Unauthorized or cancelled' );

                        userpro_end_load( form );

                    }

                },{scope: '<?php echo $scope; ?>'});



            }



            // Logout

            function Logout(){

                FB.logout(function(){document.location.reload();});

            }



            // 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>



            <a href="#" class="userpro-social-facebook userpro-tip" data-redirect="<?php echo $array['facebook_redirect']; ?>" title="<?php _e('Login with Facebook','userpro'); ?>"></a>



            <?php

        }

1 回答

  • 0

    访问此链接

    https://developers.facebook.com/docs/plugins/login-button

    点击获取代码按钮并按照说明操作 . 您必须在那里指定重定向网址,还需要创建应用ID . 该按钮仅在您指定托管网站网址时有效 . 显然,在发展层面是不可能的 .

    如果登录按钮不起作用 . 然后尝试类似按钮代码 .

    或者第三个解决方案是,为wordpress安装maxbutton插件,它将为您提供创建指向facebook.com的按钮的工具 . 谢谢

相关问题