-
Author
Tagged: buddypress, menu, ajax, profile menu
-
February 25, 2015 at 18:51 #47607Rincon805Participant
This is a random question, but on the homepage, I have tabs connected to different functions – one of them being the buddypress activity stream, another to the groups listing. See here: col.thelaw.agency
This are all called when the page loads. I’d like to change the site to redirect logged in users to their profile page upon logging in, but before I do, I was wondering if it was possible to:
1.) Change the profile menu
2.) change the profile menu to load via ajax or something similar so that clicking menu option doesn’t require a full page reload.
3.) change the profile menu to add an option that shows the entire activity stream.Any tips?
Thanks,February 25, 2015 at 19:05 #47611sharmstrModerator1 – I have a write up on my site: http://sharmstr.com/login-redirect/
2 – You’ll have to ask over on Buddypress forum
3 – See #2 answer 🙂 But adding tabs is easy, its the activity load that you’ll have issues with since you’ll be trying to display within the member context.Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solutionThis support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com
February 25, 2015 at 19:09 #47612sharmstrModeratorSorry
1 – should be ” look a the bp_core_new_nav_item() function ” https://codex.buddypress.org/developer/function-examples/core/bp_core_new_nav_item/
Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solutionThis support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com
February 26, 2015 at 19:01 #47828Rincon805ParticipantHey Sharmstr,
Thanks for the assist (again), but I’m not sure that i’m understanding you correctly. I implemented the code off your post, but upon login I’m not getting redirect.This is what I entered into my child theme’s functions.php
function kleo_ajax_login()
{
// Check the nonce, if it fails the function will break
check_ajax_referer( ‘kleo-ajax-login-nonce’, ‘security’ );// Nonce is checked, get the POST data and sign in user
$info = array();
$info[‘user_login’] = $_POST[‘log’];
$info[‘user_password’] = $_POST[‘pwd’];
$info[‘remember’] = (isset( $_POST[‘remember’] ) && $_POST[‘remember’] === true) ? true : false ;$info = apply_filters(‘kleo_ajaxlogin_atts’, $info);
$user_signon = wp_signon( $info, false );
if ( is_wp_error( $user_signon ) ){
$error_msg = $user_signon->get_error_message();
echo json_encode(array( ‘loggedin’ => false, ‘message’ => ‘<span class=”wrong-response”><i class=”icon icon-attention”></i> ‘ . $error_msg . ‘</span>’ ));
//echo json_encode(array( ‘loggedin’ => false, ‘message’ => ‘<span class=”wrong-response”><i class=”icon icon-attention”></i> ‘ . __( ‘Wrong username or password. Please try again.’, ‘kleo_framework’ ) . ‘</span>’ ));
} else {
if ( sq_option( ‘login_redirect’ , ‘default’ ) == ‘reload’ ) {
$redirecturl = apply_filters( ‘kleo_modal_login_redirect’, ‘/activity/’, ”, $user_signon );
}
else {
$redirecturl = apply_filters( ‘kleo_modal_login_redirect’, ‘/’ . BP_MEMBERS_SLUG . ‘/’ . $info[‘user_login’], ”, $user_signon );
}echo json_encode(array(‘loggedin’=>true, ‘redirecturl’ => $redirecturl, ‘message’=> ‘<span class=”good-response”><i class=”icon icon-ok-circled”></i> ‘ . __( ‘Login successful, redirecting…’,’kleo_framework’ ) . ‘</span>’ ));
}die();
}Thanks,
February 26, 2015 at 20:18 #47844sharmstrModeratorSorry, they changed the login code in the last update. I’ve updated the post with new code.
Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solutionThis support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com
February 26, 2015 at 22:19 #47866Rincon805ParticipantHmm… it appears that the FB redirect works well, but I can’t get the regular login to redirect me.
Here’s the code I’m using:
<?php
/**
* @package WordPress
* @subpackage Kleo
* @author SeventhQueen <themesupport@seventhqueen.com>
* @since Kleo 1.0
*//**
* Kleo Child Theme Functions
* Add custom code below
*/
function kleo_ajax_login()
{
// Check the nonce, if it fails the function will break
check_ajax_referer( ‘kleo-ajax-login-nonce’, ‘security’ );// Nonce is checked, continue
$secure_cookie = ”;// If the user wants ssl but the session is not ssl, force a secure cookie.
if ( !empty($_POST[‘log’]) && !force_ssl_admin() ) {
$user_name = sanitize_user($_POST[‘log’]);
if ( $user = get_user_by(‘login’, $user_name) ) {
if ( get_user_option(‘use_ssl’, $user->ID) ) {
$secure_cookie = true;
force_ssl_admin(true);
}
}
}if ( isset( $_REQUEST[‘redirect_to’] ) ) {
$redirect_to = $_REQUEST[‘redirect_to’];
// Redirect to https if user wants ssl
if ( $secure_cookie && false !== strpos($redirect_to, ‘wp-admin’) )
$redirect_to = preg_replace(‘|^http://|’, ‘https://’, $redirect_to);
} else {
$redirect_to = ”;
}$user_signon = wp_signon( ”, $secure_cookie );
if ( is_wp_error( $user_signon ) ){
$error_msg = $user_signon->get_error_message();
echo json_encode(array( ‘loggedin’ => false, ‘message’ => ‘<span class=”wrong-response”><i class=”icon icon-attention”></i> ‘ . $error_msg . ‘</span>’ ));
//echo json_encode(array( ‘loggedin’ => false, ‘message’ => ‘<span class=”wrong-response”><i class=”icon icon-attention”></i> ‘ . __( ‘Wrong username or password. Please try again.’, ‘kleo_framework’ ) . ‘</span>’ ));
} else {
if ( sq_option( ‘login_redirect’ , ‘default’ ) == ‘reload’ ) {
$redirecturl = apply_filters( ‘kleo_modal_login_redirect’, ‘/’ . BP_MEMBERS_SLUG . ‘/’ . $_POST[‘log’], ”,}
else {
$requested_redirect_to = isset( $_REQUEST[‘redirect_to’] ) ? $_REQUEST[‘redirect_to’] : ”;
/**
* Filter the login redirect URL.
*
* @since 3.0.0
*
* @param string $redirect_to The redirect destination URL.
* @param string $requested_redirect_to The requested redirect destination URL passed as a parameter.
* @param WP_User|WP_Error $user WP_User object if login was successful, WP_Error object otherwise.
*/
$redirecturl = apply_filters( ‘login_redirect’, $redirect_to, $requested_redirect_to, $user_signon );}
echo json_encode(array(‘loggedin’=>true, ‘redirecturl’ => $redirecturl, ‘message’=> ‘<span class=”good-response”><i class=”icon icon-ok-circled”></i> ‘ . __( ‘Login successful, redirecting…’,’kleo_framework’ ) . ‘</span>’ ));
}die();
}February 26, 2015 at 22:49 #47873Rincon805ParticipantAlso, how would i go about changing the FB login to be the member’s profile – not just a static page?
Thanks,
March 1, 2015 at 06:05 #48223Rincon805ParticipantTo all those that are interested, here’s how I got the redirect working. I set the default component to be the activity page. Now all I have to do is figure out how to add a submenu item that calls all activity….
This was put into bp-custom.php
<?php
/*Make sure profile is default component*/
define(‘BP_DEFAULT_COMPONENT’,’activity’);/*let us filter where to redirect */
add_filter(“login_redirect”,”bpdev_redirect_to_profile”,10,3);function bpdev_redirect_to_profile($redirect_to_calculated,$redirect_url_specified,$user)
{
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 );
else
return $redirect_to_calculated; /*if site admin or not logged in,do not do anything much*/}
add_filter(‘logout_url’,”bpdev_logout_url”,100,2);
function bpdev_logout_url( $logout_url, $redirect) {
//simply ignore the redirect and set it to the main domain
//let us check for buddyopress,if yes,let us get the bp root domain right ?
if(function_exists(“bp_core_get_root_domain”))
$redirect=bp_core_get_root_domain();
else
$redirect = get_blog_option( SITE_ID_CURRENT_SITE, ‘siteurl’ );$args = array( ‘action’ => ‘logout’ );
if ( !empty($redirect) ) {
$args[‘redirect_to’] = $redirect;
}$logout_url = add_query_arg($args, site_url(‘wp-login.php’, ‘login’));
$logout_url = wp_nonce_url( $logout_url, ‘log-out’ );return $logout_url;
}
?> -
AuthorPosts
The forum ‘KLEO’ is closed to new topics and replies.