@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
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.
}
@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' );
@markob17 great to see you got it working. I’m wondering though, which function of mine isn’t working?
@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' )
Thanks for letting me know, @markob17. I always get current_action and current_item mixed up and should really do more testing 🙂
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!