Zibll(子比)主题6.4.1接入彩虹聚合登录系统详细教程

Zibll(子比)主题6.4.1接入彩虹聚合登录平台详细教程,在正式接入前请务必做好数据备份并下载聚合登录插件安装启用,如果你还没有找到合适的对接平台可以参考本站文章!

请按照提示将主题内原代码修改为本文给出的替换代码,请展开查看!

位置: /action/user.php

//用户解除第三方账户绑定
function zib_ajax_user_oauth_untying()
{
    if (empty($_POST['user_id']) || empty($_POST['type'])) {
        echo (json_encode(array('error' => 1, 'ys' => 'danger', 'msg' => '参数传入错误')));
        exit();
    }
    $cuid = get_current_user_id();
    if (!$cuid || $cuid != $_POST['user_id']) {
        echo (json_encode(array('error' => 1, 'ys' => 'danger', 'msg' => '权限不足')));
        exit;
    }

    delete_user_meta($_POST['user_id'], 'oauth_' . $_POST['type'] . '_openid');
    delete_user_meta($_POST['user_id'], 'oauth_' . $_POST['type'] . '_getUserInfo');

    $goto = zib_get_user_center_url('account');

    echo (json_encode(array('error' => 0, 'ys' => '', 'reload' => true, 'goto' => $goto, 'msg' => '已解除绑定')));

    exit();
}
add_action('wp_ajax_user_oauth_untying', 'zib_ajax_user_oauth_untying');
//用户解除第三方账户绑定
function zib_ajax_user_oauth_untying()
{
    if (empty($_POST['user_id']) || empty($_POST['type'])) {
        echo (json_encode(array('error' => 1, 'ys' => 'danger', 'msg' => '参数传入错误')));
        exit();
    }
    $cuid = get_current_user_id();
    if (!$cuid || $cuid != $_POST['user_id']) {
        echo (json_encode(array('error' => 1, 'ys' => 'danger', 'msg' => '权限不足')));
        exit;
    }

    delete_user_meta($_POST['user_id'], 'oauth_' . $_POST['type'] . '_openid');
    delete_user_meta($_POST['user_id'], 'oauth_' . $_POST['type'] . '_getUserInfo');
    delete_user_meta($_POST['user_id'], 'clogin_passport_' . $_POST['type']);

    $goto = zib_get_user_center_url('account');

    echo (json_encode(array('error' => 0, 'ys' => '', 'reload' => true, 'goto' => $goto, 'msg' => '已解除绑定')));

    exit();
}
add_action('wp_ajax_user_oauth_untying', 'zib_ajax_user_oauth_untying');

有两处:/inc/functions/functions.php

//获取社交登录的链接
//自动判断是否开启此社交登录方式,可直接当做判断函数使用
function zib_get_oauth_login_url($type, $rurl = '')
{
    $oauth_agent = _pz('oauth_agent', 'close');
    $option      = _pz('oauth_agent_client_option');
    $oauth_s     = !empty($option['oauth_s']) ? (array) $option['oauth_s'] : array();
    if (!$rurl) {
        $rurl = !empty($_GET['redirect_to']) ? $_GET['redirect_to'] : home_url(add_query_arg(null, null));
    }

    if ('client' == $oauth_agent && $option['url'] && $option['key'] && in_array($type, $oauth_s)) {
        return add_query_arg(array('rurl' => $rurl, 'type' => $type), home_url('/oauth/agent'));
    } elseif (_pz('oauth_' . $type . '_s')) {
        return add_query_arg('rurl', $rurl, home_url('/oauth/' . $type));
    }
    return false;
}
//社交登录按钮构建
function zib_social_login($echo = true)
{
    if (zib_is_close_sign()) {
        return;
    }

    $buttons = '';
    if (_pz('social') && function_exists('xh_social_loginbar')) {
        $buttons = xh_social_loginbar('', false);
    } else {
        $b_c    = _pz('oauth_button_lg') ? ' button-lg' : '';
        $args   = array();
        $args[] = array(
            'name'  => 'QQ',
            'type'  => 'qq',
            'class' => 'c-blue',
            'icon'  => 'fa-qq',
        );
        $args[] = array(
            'name'  => '微信',
            'type'  => 'weixin',
            'class' => 'c-green',
            'icon'  => 'fa-weixin',
        );
        $args[] = array(
            'name'   => '微信',
            'type'   => 'weixingzh',
            'class'  => 'c-green',
            'icon'   => 'fa-weixin',
            'qrcode' => !zib_is_wechat_app(),
        );
        $args[] = array(
            'name'  => '微博',
            'type'  => 'weibo',
            'class' => 'c-red',
            'icon'  => 'fa-weibo',
        );
        $args[] = array(
            'name'  => 'GitHub',
            'type'  => 'github',
            'class' => '',
            'icon'  => 'fa-github',
        );
        $args[] = array(
            'name'  => '码云',
            'type'  => 'gitee',
            'class' => '',
            'icon'  => '',
        );
        $args[] = array(
            'name'  => '百度',
            'type'  => 'baidu',
            'class' => '',
            'icon'  => 'baidu',
        );
        $args[] = array(
            'name'  => '支付宝',
            'type'  => 'alipay',
            'class' => 'c-blue',
            'icon'  => 'alipay',
        );
        foreach ($args as $arg) {
            $type = $arg['type'];
            $name = $arg['name'];
            $icon = '<i class="fa ' . $arg['icon'] . '"></i>';
            if ('alipay' == $type) {
                $icon = zib_get_svg('alipay');
                if (wp_is_mobile() && !strpos($_SERVER['HTTP_USER_AGENT'], 'Alipay')) {
                    continue;
                }
                //移动端并且不是支付宝APP不显示支付宝
            }
            if ('baidu' == $type) {
                $icon = zib_get_svg('baidu');
            }

            if ('gitee' == $type) {
                $icon = zib_get_svg('gitee');
            }

            $href = zib_get_oauth_login_url($type);
            if ($href) {
                $_class = $type . ($b_c ? $b_c : ' toggle-radius');
                if (!empty($arg['qrcode'])) {
                    $_class .= ' qrcode-signin';
                }

                $buttons .= '<a title="' . $name . '登录" href="' . esc_url($href) . '" class="social-login-item ' . $_class . '">' . $icon . ($b_c ? $name . '登录' : '') . '</a>';
            }
        }
    }
    if ($echo && $buttons) {
        echo '<p class="social-separator separator muted-3-color em09">社交帐号登录</p>';
        echo '<div class="social_loginbar">';
        echo $buttons;
        echo '</div>';
    } else {
        return $buttons;
    }
}
//获取社交登录的链接
//自动判断是否开启此社交登录方式,可直接当做判断函数使用
function zib_get_oauth_login_url($type, $rurl = '')
{
    $oauth_agent = _pz('oauth_agent', 'close');
    $option      = _pz('oauth_agent_client_option');
    $oauth_s     = !empty($option['oauth_s']) ? (array) $option['oauth_s'] : array();
    $clogin_types = get_option('clogin-passport-types', array());
    if (!$rurl) {
        $rurl = !empty($_GET['redirect_to']) ? $_GET['redirect_to'] : home_url(add_query_arg(null, null));
    }

    if (in_array($type, $clogin_types)) {
        return add_query_arg('rurl', $rurl, home_url('index.php/wp-json/clogin-passport/login/' . $type));
    } elseif ('client' == $oauth_agent && $option['url'] && $option['key'] && in_array($type, $oauth_s)) {
        return add_query_arg(array('rurl' => $rurl, 'type' => $type), home_url('/oauth/agent'));
    } elseif (_pz('oauth_' . $type . '_s')) {
        return add_query_arg('rurl', $rurl, home_url('/oauth/' . $type));
    }
    return false;
}
//社交登录按钮构建
function zib_social_login($echo = true)
{
    if (zib_is_close_sign()) {
        return;
    }

    $buttons = '';
    if (true) {
        $b_c    = _pz('oauth_button_lg') ? ' button-lg' : '';
        $args   = array();
        $args[] = array(
            'name'  => 'QQ',
            'type'  => 'qq',
            'class' => 'c-blue',
            'icon'  => 'fa-qq',
        );
        $args[] = array(
            'name'  => '微信',
            'type'  => 'wx',
            'class' => 'c-green',
            'icon'  => 'fa-weixin',
        );
        $args[] = array(
            'name'   => '微信',
            'type'   => 'weixingzh',
            'class'  => 'c-green',
            'icon'   => 'fa-weixin',
            'qrcode' => !zib_is_wechat_app(),
        );
        $args[] = array(
            'name'  => '微博',
            'type'  => 'sina',
            'class' => 'c-red',
            'icon'  => 'fa-weibo',
        );
        $args[] = array(
            'name'  => '百度',
            'type'  => 'baidu',
            'class' => '',
            'icon'  => 'baidu',
        );
        $args[] = array(
            'name'  => '支付宝',
            'type'  => 'alipay',
            'class' => 'c-blue',
            'icon'  => 'alipay',
        );
        $args[] = array(
            'name'  => 'GitHub',
            'type'  => 'github',
            'class' => '',
            'icon'  => 'fa-github',
        );
        $args[] = array(
            'name'  => '码云',
            'type'  => 'gitee',
            'class' => '',
            'icon'  => '',
        );
        foreach ($args as $arg) {
            $type = $arg['type'];
            $name = $arg['name'];
            $icon = '<i class="fa ' . $arg['icon'] . '"></i>';
            if ('alipay' == $type) {
                $icon = zib_get_svg('alipay');
            }
            if ('baidu' == $type) {
                $icon = zib_get_svg('baidu');
            }
            if ('gitee' == $type) {
                $icon = zib_get_svg('gitee');
            }

            $href = zib_get_oauth_login_url($type);
            if ($href) {
                if($type == 'sina') $type = 'weibo';
                elseif($type == 'wx') $type = 'weixin';
                $_class = $type . ($b_c ? $b_c : ' toggle-radius');
                if (!empty($arg['qrcode'])) {
                    $_class .= ' qrcode-signin';
                }

                $buttons .= '<a title="' . $name . '登录" href="' . esc_url($href) . '" class="social-login-item ' . $_class . '">' . $icon . ($b_c ? $name . '登录' : '') . '</a>';
            }
        }
    }
    if ($echo && $buttons) {
        echo '<p class="social-separator separator muted-3-color em09">社交帐号登录</p>';
        echo '<div class="social_loginbar">';
        echo $buttons;
        echo '</div>';
    } else {
        return $buttons;
    }
}

位置:/inc/functions/user/page.php

function zib_oauth_set($html, $user_id)
{
    if (!$user_id) {
        return;
    }

    $con  = '';
    $rurl = zib_get_user_center_url('account');

    $args   = array();
    $args[] = array(
        'name'     => 'QQ',
        'type'     => 'qq',
        'class'    => 'c-blue',
        'name_key' => 'nickname',
        'icon'     => 'fa-qq',
    );
    $args[] = array(
        'name'     => '微信',
        'type'     => 'weixin',
        'class'    => 'c-green',
        'name_key' => 'nickname',
        'icon'     => 'fa-weixin',
    );
    $args[] = array(
        'name'     => '微信',
        'type'     => 'weixingzh',
        'class'    => 'c-green',
        'name_key' => 'nickname',
        'icon'     => 'fa-weixin',
        'qrcode'   => !zib_is_wechat_app(),
    );
    $args[] = array(
        'name'     => '微博',
        'type'     => 'weibo',
        'class'    => 'c-red',
        'name_key' => 'screen_name',
        'icon'     => 'fa-weibo em12',
    );
    $args[] = array(
        'name'     => 'GitHub',
        'type'     => 'github',
        'class'    => '',
        'name_key' => 'name',
        'icon'     => 'fa-github em12',
    );
    $args[] = array(
        'name'     => '码云',
        'type'     => 'gitee',
        'class'    => 'c-red-2',
        'name_key' => 'name',
        'icon'     => '',
    );
    $args[] = array(
        'name'     => '百度',
        'type'     => 'baidu',
        'class'    => 'c-blue-2',
        'name_key' => 'username',
        'icon'     => '',
    );

    $args[] = array(
        'name'     => '支付宝',
        'type'     => 'alipay',
        'class'    => 'c-blue',
        'name_key' => 'username',
        'icon'     => '',
    );

    foreach ($args as $arg) {
        $name     = $arg['name'];
        $type     = $arg['type'];
        $class    = $arg['class'];
        $name_key = $arg['name_key'];
        $icon     = '<i class="fa ' . $arg['icon'] . '"></i>';
        if ('alipay' == $type) {
            $icon = zib_get_svg('alipay', '0 0 1024 1024', 'em12 icon');
            if (wp_is_mobile() && !strpos($_SERVER['HTTP_USER_AGENT'], 'Alipay')) {
                continue;
            }
            //移动端并且不是支付宝APP不显示支付宝
        }
        if ('baidu' == $type) {
            $icon = zib_get_svg('baidu', '0 0 1024 1024', 'em12 icon');
        }

        if ('gitee' == $type) {
            $icon = zib_get_svg('gitee');
        }

        $bind_href = zib_get_oauth_login_url($type, $rurl);
        if ($bind_href && !_pz('social')) {
            $oauth_info = get_user_meta($user_id, 'oauth_' . $type . '_getUserInfo', true);
            $oauth_id   = get_user_meta($user_id, 'oauth_' . $type . '_openid', true);
            if ($oauth_info && $oauth_id) {
                $name .= !empty($oauth_info['name']) ? ' ' . esc_attr($oauth_info['name']) : (!empty($oauth_info[$name_key]) ? ' ' . esc_attr($oauth_info[$name_key]) : '帐号');
                $con .= '<a data-toggle="tooltip" href="javascript:;" openid="' . esc_attr($oauth_id) . '" title="解绑' . $name . '帐号" user-id="' . $user_id . '" untying-type="' . $type . '" class="oauth-untying but oauth-but ' . $class . ' hollow">' . $icon . ' 已绑定' . $name . '</a>';
            } else {
                if (!empty($arg['qrcode'])) {
                    $class .= ' qrcode-signin';
                }
                $con .= '<a title="绑定' . $name . '帐号" href="' . esc_url(add_query_arg(array('bind' => $type), $bind_href)) . '" class="but oauth-but ' . $class . ' hollow">' . $icon . ' 绑定' . $name . '帐号</a>';
            }
        }
    }

    if (!$con) {
        return $html;
    }

    $html .= '<div class="box-body oauth-set">';
    $html .= '<div class="title-h-left"><b>绑定社交帐号</b></div><div class="muted-2-color mb20">绑定社交帐号之后,您可以更快速的一键登录本站</div>';
    $html .= $con;
    $html .= '</div>';
    return $html;
}
add_filter('user_center_account_setup', 'zib_oauth_set', 10, 2);

替换代码③ 请评论回复刷新页面获取!

© 版权声明
THE END
喜欢就支持一下吧
赞赏 分享
评论 共3条

请登录后发表评论