Redirect code

OK, this may be custom code so I understand if nobody can help.

On the site http://www.divorceforcedsale.com, if you are not registered as a "seller" using the membership+ plugin, you cannot post a classified.

Right now when you can click the button "Post a Classified" which links to the visitor protected page of http://divorceforcedsale.com/?page=ads

Since they cannot access that page, it take them to a generic login page. Can I redirect them to the http://divorceforcedsale.com/register/ which will allow them to join via the membership plugin?

The page itself it protected under URL /?page=ads
Strip query strings from URL - NO
Regular Expression - NO

  • mort3n
    • The Crimson Coder

    Hi idomagic,

    You can choose the page to redirect attempts to access restricted content by choosing the page in the Membership -> Options -> Membership pages -> Protected content Say you want to show the Register page, then you pick that.

    You'll probably have set up a visitor access level and chosen this for the Stranger setting under Membership -> Options -> General

    On your site, you have both buyers and sellers as well as visitors. Perhaps you don't want to redirect buyers to the register page, since they're already registered.

    You could make use of the shortcodes eg. [level-buyer] buyer content [/level-buyer] to have just one page to redirect to that is customized for each of the different use-cases.

    You may want to show buyers an offer to upgrade to the seller subscription or similar.

    Hope this helps!

    Cheers
    Mort3n

  • idomagic
    • The Incredible Code Injector

    Strange in .

    Membership -> Options -> Membership pages ->

    I have the:

    Protected content page (set to) "Register"

    Should that not force any unregistered person to the register page? In fact, it would also redirect registered but not logged in accounts as well correct?

    You could make use of the shortcodes eg. [level-buyer] buyer content [/level-buyer] to have just one page to redirect to that is customized for each of the different use-cases.

    You may want to show buyers an offer to upgrade to the seller subscription or similar.

    Doesn't make sense. I'll try to absorb it though.

  • mort3n
    • The Crimson Coder

    Hi idomagic,

    Well, I admit it early at my location, so apologies for not making sense :slight_smile:

    You are quite right that your Protected content setting will redirect all non-logged in users to the Register page.

    I was trying to deal with the use-case :

    Buyer is logged in and clicks Post Classified button

    In this use-case the Register page is probably not where you want them to go, no?

    My suggestion was that you use the shortcodes of the plugin to set up a page that can deal with both cases as follows (assumes you have a Visitor access level)

    Common content stuff
    [level-visitor]
    Some register content
    [subscriptionform]
    [/level-visitor]
    [level-buyer]
    Some info and suggestion to upgrade
    [renewform]
    [/level-buyer]

    Hope this makes it clearer :slight_smile:

    Cheers
    Mort3n

  • idomagic
    • The Incredible Code Injector

    Maybe my redirect is set up wrong? The short codes make a ton of sense but they don't seem to work. Am I really this dense? Please see the screen shots.

    1. register-or-login seen as a visitor
    2. register-or-login seen as a admin
    3. configuration in membership
    4. register-or-login page short codes

  • mort3n
    • The Crimson Coder

    Hi idomagic,

    Glad that it made more sense the second time round :slight_smile:

    From your screenshots I don't initially see anything wrong.

    This leads me to wonder if my assumption that the Membership shortcodes allow for use of nested shortcodes is correct.

    @aristath perhaps you could get the developer to advice on this?

    idomagic, I advice you to stand-by until then.

    I'm looking forward to a follow-up :slight_smile:

    Cheers
    Mort3n

    PS. For general information on nested shortcodes, see the Codex

    http://codex.wordpress.org/Shortcode_API#Nested_Shortcodes

  • mort3n
    • The Crimson Coder

    Hi idomagic,

    Just a few more thoughts. :slight_smile:

    For the Visitor level to work I believe you need to have set the Stranger level Membership->Options->General to Visitor for this use-case to work.

    Since, you're logged in as an admin, you're not logged in as a buyer so that would be shown. Try logging in as a buyer and revisit the page.

    Hope this helps!
    Cheers
    Mort3n

  • aristath
    • Recruit

    Just brainstorming a bit here....
    You could create a custom template file for that particular page in your theme called page-{id}.php (see here for more details on template files priorities and structure) and in there use something like the code below:

    if ( current_user_on_level( $level_id ) ) {
      // do something if user is on that level
    } else {
      wp_redirect( 'http://divorceforcedsale.com/register/', 301 );
      exit;
    }

    I hope that helps a bit...
    Cheers,
    Ari.

  • aristath
    • Recruit

    what level ID is a visitor and where would I find it?

    When you edit an access level, you'll see a url similar to this:
    http://example.com/wp-admin/admin.php?page=membershiplevels&action=edit&level_id=1

    If you notice at the end, there's a "&level_id=1".
    That's where you'll find the ID of a level. :wink:

    So just find the level ID of the seller. let's suppose for now that in this example the level ID is 3.

    Copy the contents of page.php of your theme to the page-{id}.php file that I mentioned bofore.

    Next, put the following at the top of this file:

    <?php
    if ( current_user_on_level( 3 ) ) {
      // do something if user is on that level
    } else {
      wp_redirect( 'http://divorceforcedsale.com/register/', 301 );
      exit;
    }
    ?>

    Don't worry about the "// do something if user is on that level" part... after all, you want to redirect the users if they are NOT on level 3. I just wrote it like that to make it more versatile, so that you may more easily add something there in the future. :wink:

    Could you please try it and see if that works?

    If a user is NOT on level 3, they should be redirected to the page you want them to.

    Cheers,
    Ari.

  • idomagic
    • The Incredible Code Injector

    I sure appreciate the help but it's not working, I still redirect to the login page.

    I have a file named "page-1.php" in the classifieds theme folder next to the "page.php" file. I have added the above code to the file. I tried with user level 1, 2, 3 and even 0. I also tried adding the code to the actual "page.php" file.

    I'm sure it's me. I am reading and trying to learn php now but i am still really green. This is giving me knots in my stomach!

  • aristath
    • Recruit

    Hiya, just going through some of the older threads here.

    As it's been a little while since we last heard from you I thought I'd check in to see how you're going?

    If you're still looking for some further assistance with this thread then please feel free to reopen the thread or of course for any new and related issues you are most welcome to open a new thread.

    Thanks.
    Ari.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.