Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Conditional check for activate page


  • Henry
    Member

    @henrywright-1

    Anyone know how to check when the currently viewed page is the activate page? “example.com/activate”

    I thought it would be something like this but it doesn’t work:

    if ( is_page('activate') ) {
       //do something
    }
Viewing 10 replies - 1 through 10 (of 10 total)

  • Brajesh Singh
    Participant

    @sbrajesh

    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.


    Henry
    Member

    @henrywright-1

    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.


    Henry
    Member

    @henrywright-1

    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');

    Brajesh Singh
    Participant

    @sbrajesh

    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


    Henry
    Member

    @henrywright-1

    @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!


    Henry
    Member

    @henrywright-1

    @hnla you beat me to it – i was just reading that exact page. Thanks for your help!


    Brajesh Singh
    Participant

    @sbrajesh

    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.


    Henry
    Member

    @henrywright-1

    thanks again @sbrajesh – i shouldn’t have assumed exiting was automatic!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘[Resolved] Conditional check for activate page’ is closed to new replies.
Skip to toolbar