登录重定向到特定业务伙伴配置文件页面

时间:2011-09-26 作者:Jeremy Love

我试图重定向到某个bp配置文件页面,但由于某种原因,它会一直转到登录时的主页。

这是我的代码,我不完全确定问题是什么,为什么它会一直出现在主页上。

add_action(\'login_form\', \'redirect_after_login\');
function redirect_after_login() {
    global $redirect_to;
    if (!isset($_GET[\'redirect_real\'])) {
        $redirect_to = bp_core_get_user_domain($user->ID);
        $redirect_real = \'$redirect_to/mypics\';
    }
}

2 个回复
最合适的回答,由SO网友:Jeremy Love 整理而成

我能够从中找到此功能的成功之处BP Redirect to Profile (见GitHub repository):

<?php
/*
Plugin Name: BP Redirect to Profile for Buddypress
Description:Redirect user to their profile when they login
Version: 1.1
Requires at least: BuddyPress 1.1
Tested up to: BuddyPress 1.2+wpmu 2.9.1
License: GNU General Public License 2.0 (GPL) http://www.gnu.org/licenses/gpl.html
Author: Brajesh Singh
Author URI: http://buddydev.com
Plugin URI:http://buddydev.com/buddypress/bp-redirect-to-profile-plugin-redirect-users-to-their-profile-on-login-on-buddypress-sites/
Last updated:16th feb 2010
*/
/***
    Copyright (C) 2009 Brajesh Singh(buddydev.com)

    This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or  any later version.

    This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses>.

    */
/*Add a filter to filter the redirect url for login*/
add_filter("login_redirect","bpdev_redirect_to_profile",100,3);
function bpdev_redirect_to_profile($redirect_to_calculated,$redirect_url_specified,$user)
{
/*if no redirect was specified,let us think ,user wants to be in wp-dashboard*/
if(empty($redirect_to_calculated))
    $redirect_to_calculated=admin_url();

    /*if the user is not site admin,redirect to his/her profile*/
    if(!is_site_admin($user->user_login))
        return bp_core_get_user_domain($user->ID).mypics;
    else
        return $redirect_to_calculated; /*if site admin or not logged in,do not do anything much*/

}

SO网友:daniel

这一个更好用,不是我的代码,顺便说一句:)

将其放入/插件/bp自定义。php

    //=Redirect to User\'s Profile Page after Login
    function rt_login_redirect($redirect_to, $set_for, $user){
    $redirect_to = bp_core_get_user_domain($user->id);
    return $redirect_to;
    }
    add_filter(\'login_redirect\', \'rt_login_redirect\', 20, 3);

结束