If you are checking for BuddyPress activation page, you can use any of the following
if( bp_is_activation_page() ) {
//do something
}
or
if ( bp_is_current_component( 'activate' ) ){
//do something
}
hope that helps.
Hi @sbrajesh
Have you tested bp_is_activation_page()
recently? Both that and bp_is_current_component( 'activate' )
don’t seem to be working for me even though similar functions such as bp_is_register_page()
work perfectly.
I am trying to redirect logged-in users away from the activate page if they try to access it. This is what I have which isn’t working
//redirect logged-in users away from activate page
function bp_redirect_activate_to_profile() {
global $bp;
if ( is_user_logged_in() && bp_is_activation_page() ) {
wp_redirect( $bp->loggedin_user->domain );
}
}
add_action('wp','bp_redirect_activate_to_profile');
Hi Henry,
That code works. All you are missing is an exit statement.
here is the code I modified for you
//redirect logged-in users away from activate page
function bp_redirect_activate_to_profile() {
global $bp;
if ( is_user_logged_in() && bp_is_activation_page() ) {
wp_redirect( $bp->loggedin_user->domain );
exit(0);
}
}
add_action('wp','bp_redirect_activate_to_profile');
That will work. Please do let me know if it works for you or not ?
bp_is_current_component( ‘activate’ ) you’re trying to tell the page the active component is ‘activate’?
whereas ‘activate’ == bp_is_current_component() works or at least does for other components, I’ll always var_dump things like this out to see what they are returning
@sbrajesh thank you! Adding exit(0);
nailed it!
@hnla
bp_is_current_component( ‘activate’ )
and ‘activate’ == bp_is_current_component()
and bp_is_activation_page()
and is_page('activate')
all work by themselves – it was my function that was missing an exit statement that was the problem. Thanks to @sbrajesh it’s all sorted now.
@sbrajesh i do wonder the reason for the exit statement? doesn’t the function get exited automatically? no real issue though as the problem is resolved.
the answer to that question is in the codex 🙂
https://codex.wordpress.org/Function_Reference/wp_redirect – it doesn’t exit automatically!
@hnla you beat me to it – i was just reading that exact page. Thanks for your help!
Hi Henry,
As Hugo linked, the function does not uses exit. You might use ‘bp_core_redirect’ though, which does not require you to put exit after it.
thanks again @sbrajesh – i shouldn’t have assumed exiting was automatic!