0

Long term reader, first question.

I've got a custom buddypress // Wordpress 3.8.1 setup with Paid Membership Pro. The code is if you're not a premium member type 1, redirect to free member (2 or 3) page. And hide the link to the premium pages.

I've looked at the docs, but can't solve it for two problems.

  1. I'm getting 'Warning: Division by zero' on the second if statement. I'm familiar with this with maths, but not with true/false. - Fixed by @markB

  2. Where I have indicated , I need to link to the URL without using the static URL.

So it should redirect from '/profile/edit/group/12/' to '/profile/edit/group/1/'.

I believe the answer can be done with strpos, but I'm not familiar with it. See: Check if URL has certain string with PHP

if( bp_is_my_profile() && $loggged_in_memberships[0]->membership_id != 1) {
    if ($_SERVER['HTTP_HOST'] == 
        “localhost/wordpress/members/<user>/profile/edit/group/12/”) {
        header("localhost/wordpress/members/<user>/profile/edit/group/1/");
    }
    echo "statement"
}

--Edit-- Based on comments I have modified code:

if( bp_is_my_profile() && $loggged_in_memberships[0]->membership_id != 1) {
        if ($_SERVER['REQUEST_URI'] == '/members/'.$current_user->user_login.'/profile/edit/group/5/') {
            global $current_user;
            bp_core_redirect(get_option('siteurl').'/members/'.$current_user->user_login.'/profile/edit/group/12/');
}

Thanks in advance.

Community
  • 1
  • 1
tgrrr
  • 706
  • 6
  • 16
  • 1
    `“` and `”` are not valid PHP quote characters... don't use Word or other non-text editors for editing your code... – Marc B Feb 07 '14 at 01:24
  • @MarcB thx. I use sublime3, but copy/pasted the code because it normally avoids errors. – tgrrr Feb 07 '14 at 03:39
  • 1
    See http://codex.buddypress.org/developer/the-bp-global/ and current_action and action_variables to find out what page and edit step you are on. Then use bp_core_redirect() to send them to first edit step. Don't use $_SERVER or header – shanebp Feb 07 '14 at 15:53
  • Definitely make use of bp_core_redirect() as @shanebp suggested. It's the SEO-friendly way to redirect. – henrywright Feb 07 '14 at 23:57
  • Updated code above. Help with the problem with code would be appreciated. – tgrrr Feb 09 '14 at 09:47
  • bp_core_redirect( bp_loggedin_user_domain() . '/profile/edit/group/1/'); – shanebp Feb 09 '14 at 21:38

0 Answers0