Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Conditional Tag to Target Specific Buddypress Group Page


  • Mark
    Participant

    @markob17

    Hi,

    Is there an equivalent conditional tag to bp_is_current_component(‘events’) but for Buddypress groups?

    I am trying to target a non default Buddypress group page for an event plugin I am using. Using bp_is_current_component(‘events’) works perfect for the tab in member profiles but I tried all the tags on the Buddypress Template tag reference page for groups to no avail.

    I know there must be a way to do this. Appreciate all the help. I am using latest version of WP and BP.

    Best Regards,

    Mark

Viewing 8 replies - 1 through 8 (of 8 total)

  • Henry Wright
    Moderator

    @henrywright


    Mark
    Participant

    @markob17

    @henrywright This conditional tag doesn’t seem to work for me. When a subscriber tries to access a specific tab within a group or their profile I want to redirect them to my sales page. I got this to work fine with the ‘events’ page on member profiles but not groups. Using bp_is_groups_component() redirects all group pages, not just the events page.

    Here’s the code I am using:

    
    function wp_redirectauser() {
        if ( current_user_can('subscriber') AND bp_is_groups_component('events') ) {
            wp_redirect( 'http://www.mywebsite.com/sales-page/' );
            exit;
        }
    }
    add_action( 'wp', 'wp_redirectauser' );
    

    Any ideas on how to get this to work with just the ‘events’ group page? I’m new to all this so maybe I am just missing something in my function.

    Best Regards,

    Mark


    Henry Wright
    Moderator

    @henrywright

    Haven’t used it in a while but try bp_is_current_item(). So, your condition would be:

    if ( bp_is_groups_component() && bp_is_current_item( 'events' ) ) {
        // Code.
    }

    Mark
    Participant

    @markob17

    @henrywright Thanks Henry, unfortunately your function didn’t work either, however, you put me on the right track! Before speaking to you I had already sworn off bp_is_groups_component(). Interestingly enough bp_is_current_action is also needed alongside it to do what I need.

    Here’s what worked:

    function wp_redirectauser() {
        if ( current_user_can('subscriber') && bp_is_groups_component() && bp_is_current_action( 'events' ) ) {
            wp_redirect( 'http://www.mywebsite.com/sales-page/' );
            exit;
        }
    }
    add_action( 'wp', 'wp_redirectauser' );

    Henry Wright
    Moderator

    @henrywright

    @markob17 great to see you got it working. I’m wondering though, which function of mine isn’t working?


    Mark
    Participant

    @markob17

    @henrywright Hi Henry, I was referring to this one:

    if ( bp_is_groups_component() && bp_is_current_item( 'events' ) ) {
        // Code.
    }

    I had to use bp_is_current_action( 'events' ) in place of bp_is_current_item( 'events' )


    Henry Wright
    Moderator

    @henrywright

    Thanks for letting me know, @markob17. I always get current_action and current_item mixed up and should really do more testing 🙂


    Mark
    Participant

    @markob17

    No problem @henrywright, thank you for your help. My coding experience is nil so it has been an interesting experience as I have to Google around for everything. It’s great to have this forum which is full of code snippets to use/modify and experts like yourself to ask for help when I hit a wall. Thanks!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘[Resolved] Conditional Tag to Target Specific Buddypress Group Page’ is closed to new replies.
Skip to toolbar