logo
Ask your WordPress questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$30
Password protect entire wordpress site, apart from one page.

Hello,

This is a follow on to this question... http://wpquestions.com/question/showLoggedIn/id/3794

PROBLEM

I'm using Gravity Form User Registration add-on for a detailed data capture on profiles. But I am working on a wordpress site that is completely hidden from non members.

@Francisco suggested I use gravity forms for my detailed registration form, because all other advanced registration form plugins are failing me, due to profile custom fields.

So far the Gravity Form User Registration add-on seems to work great, with one problem... I can't add the GF registration form to my http://....../wp-login.php?action=register page.

How ever, Gravity Forms User Registration add-on has on option of redirecting from http://....../wp-login.php?action=register to any desired wordpress page

So I've created a page called User Registration and have placed the GF form on this page. I've then set it up so the http://....../wp-login.php?action=register link now redirects to the User Registration page.

But because I need my entire website to be only accessible by members, and hidden entirely from the public, I've been using the password protect plugin for wordpress. This works fine, but because my GF registration form now lives on a page within the site, when you click Register on the wp-login page, it redirects straight back to the wp-login page.


WHAT I'VE TRIED

I deactivated the password protect plugin for wordpress, and installed the members access plugin.

I configured these settings... Plugin Settings and the Page Settings.

But when you click on the Register button, it gets into a infinite loop for some reason, and eventually times out, and displays a blank page. Don't understand this?

Also, the members access plugin doesn't support custom post types.


WHAT I NEED

I need either...

( A ) For my Gravity User Registration form to live on my http://....../wp-login.php?action=register like the normal registration form, but with my extra fields etc.

or

( B ) A new password protection solution for my wordpress site that locks the entire site from non-members/public and redirects to the wp-login page, apart from my User Registration page, which in theory means my gravity form register redirection should work.


If you need anymore info then please let me know.

Thanks

This question has been answered.

Josh Cranwell | 01/26/12 at 3:23pm Edit

Previous versions of this question: 01/26/12 at 3:25pm | 01/26/12 at 3:27pm | 01/26/12 at 3:28pm

(3) Possible Answers Submitted...

See a chronological view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    01/26/12
    3:30pm
    Julio Potier says:

    Hard, but understandable :

    1) you redirect the login page on a wordpress page
    2) you got a plugin which redirect non logged users on login page
    3) go to (1)
    ...
    i'll think about a solution ...

    • 01/26/12 3:33pm

      Josh Cranwell says:

      1) I'm redirecting the 'register' button on the login page to a wordpress page
      2) I've got a plugin which redirects non logged users on login page
      3) go to (1)

      ...it's tricky

  • avatar
    Last edited:
    01/26/12
    3:41pm
    Ivaylo Draganov says:

    Hello,

    what you're trying to do is actually doable without a plugin. Try this for plan B:


    /**
    * Block site for non-logged in users
    *
    * @note pass to is_page() a detail about your login page - it can be the ID, path or title
    * @var $login_registration_url holds the URL to the page where login/registration takes place
    */
    add_action('get_header', 'wpq_member_only_site');

    function wpq_member_only_site() {

    // logged in users or visits to a specified page are allowed
    if ( !is_user_logged_in() && !is_page('register') ) {

    // the URL where login/registration takes place
    $login_registration_url = get_home_url() . '/wp-login.php?action=register';

    // redirect visitors
    wp_redirect( $login_registration_url, 302);
    exit;

    }

    }

    Previous versions of this answer: 01/26/12 at 3:33pm | 01/26/12 at 3:40pm | 01/26/12 at 3:41pm

    • 01/26/12 3:38pm

      Josh Cranwell says:

      Interesting.

      So by adding this into my functions.php, how do I define the page/pages I want to be visible to public?

      example my 'User Registration' page.

      Thanks

    • 01/26/12 3:42pm

      Josh Cranwell says:

      I've just seen where I change, gimme 2 secs

    • 01/26/12 3:43pm

      Ivaylo Draganov says:

      So by adding this into my functions.php, how do I define the page/pages I want to be visible to public?


      You can add any condition to the if statement:

      if ( !is_user_logged_in() && !is_page('register') && !is_page(23) && !is_category('public_posts') ) {

    • 01/26/12 4:07pm

      Ivaylo Draganov says:

      Multiple pages can be passed as an array:


      is_page(array('register', 'public_page', 23, 'Page Title'))

    • 01/26/12 4:11pm

      Josh Cranwell says:

      It seems to work, but in the wrong way.

      Please see below...


      http://example.com/
      http://example.com/about
      http://example.com/downloads
      http://example.com/page
      http://example.com/help
      http://example.com/news
      ...etc


      ...these all need to redirect to wp-login if your not a member.


      The register button ( http://example.com/wp-login.php?action=register) on the wp-login page needs to redirect to...

      http://example.com/user-registration


      Does this make sense?

      Thanks Ivaylo

    • 01/26/12 4:12pm

      Josh Cranwell says:

      http://example.com/
      http://example.com/about
      http://example.com/downloads
      http://example.com/page
      http://example.com/help
      http://example.com/news
      ...etc


      This represents my entire site.

    • 01/26/12 4:13pm

      Josh Cranwell says:

      ...these all need to redirect to wp-login if your not a member.


      I meant to say...

      these all need to redirect to wp-login if your not logged in.

    • 01/26/12 4:18pm

      Ivaylo Draganov says:

      Then the conditional line should be:


      if ( !is_user_logged_in() && !is_page('user-registration') ) {


      This means that not logged in users will be redirected, except if the page being requested is 'user-registration'.

      And what do you mean by "wrong way"?

    • 01/26/12 4:25pm

      Josh Cranwell says:

      For example, if I got to...

      http://example.com/

      it redirects to http://example.com/user-registration


      I need it to do this...

      When you visit http://example.com/ or any other part of the site, it has to redirect you to the wp-login page. If you successfully log-in, it has to redirect you back to http://example.com/ or what ever URL you we're originally trying to visit.

      But for the exception of the http://example.com/user-registration page. This is the only page I want visible to the public, and not to have any redirect.


      Thanks

    • 01/26/12 4:38pm

      Ivaylo Draganov says:

      Okay, this should get you there:


      /**
      * Block site for non-logged in users
      */
      add_action('get_header', 'wpq_member_only_site');

      function wpq_member_only_site() {

      // logged in users or visits to a specified page are allowed
      if ( !is_user_logged_in() && !is_page('user-registration') ) {

      // vars
      $redirect_after_login = 'http://' . $_SERVER["HTTP_HOST"] . $_SERVER['REQUEST_URI'];
      $login_url = get_home_url() . '/wp-login.php?redirect_to=' . $redirect_after_login;

      // redirect visitors
      wp_redirect( $login_url, 302);
      exit;

      }

      }

    • 01/26/12 5:02pm

      Josh Cranwell says:

      Thanks it seems to nearlly work but it's a little buggy.

      Because I'm using WPML, its adds this...

      ?lang=es

      and

      ?lang=it

      for different languages. If I click my log-out button on the site when I'm in a different language it's gets into a weird infinite loop...

      Is there anyway of stopping this? Thanks

      Josh

    • 01/26/12 5:05pm

      Josh Cranwell says:

      I was not meant to post the URL to my site then...

      I was meant to post this...

      http://www.example.com/wp?lang=eswp-loginphpredirecttohttpwwwexamplecomwplangeswp-loginphpredirecttohttpwwwexamplecomwplangeswp-loginphpredirecttohttpwwwexamplecomwplangeswp-loginphpredirecttohttpwwwexamplecomwplangeswp-loginphpredirecttohttpwwwexamplecomwplangeswp-loginphpredirecttohttpwwwexamplecomwplangeswp-loginphpredirecttohttpwwwexamplecomwplangeswp-loginphpredirecttohttpwwwexamplecomwplangeswp-loginphpredirecttohttpwwwexamplecomwplangeswp-loginphpredirecttohttpwwwexamplecomwplangeswp-loginphpredirecttohttpwwwexamplecomwplangeswp-loginphpredirecttohttpwwwexamplecomwplangeswp-loginphpredirecttohttpwwwexamplecomwplangeswp-loginphpredirecttohttpwwwexamplecomwplangeswp-loginphpredirecttohttpwwwexamplecomwplangeswp-loginphpredirecttohttpwwwexamplecomwplangeswp-loginphpredirecttohttpwwwexamplecomwplangeswp-loginphpredirecttohttpwwwexamplecomwplangeswp

    • 01/26/12 5:30pm

      Josh Cranwell says:

      Sorry I didn't explain myself very well...

      Once logged in, if I switch to spanish, it adds this...

      http://www.example.com/?lang=es

      and for italian it adds this...

      http://www.example.com/?lang=it

      On my site, I have a log out button using this code...

      <?php echo wp_logout_url( home_url() ); ?>


      If I'm on another language (not the default english), if I click that log out button, it creates the infinite loop I posted above.

    • 01/26/12 5:31pm

      Ivaylo Draganov says:

      Give me some time to make at test case with WPML.

    • 01/26/12 5:34pm

      Josh Cranwell says:

      Thank you, let me know if you need WPML

    • 01/26/12 5:36pm

      Ivaylo Draganov says:

      Oh, sorry WPML is no longer available for free download... Hm, how shall we proceed on this...

    • 01/26/12 5:40pm

      Josh Cranwell says:

      For debugging purposes... http://wtrns.fr/plC7PpOp82zHCA

      To add the language selector on your site, add this...

      <?php do_action('icl_language_selector'); ?>

    • 01/26/12 6:09pm

      Ivaylo Draganov says:

      I think I've nailed it :--) WPML is filtering the get_home_url() function and appending the "lang" query string (e.g. ?lang=es). And since I was using that function it got into and endless loop because it was passing the same query string... Well - the redirect URL was simply messed up. Here's the code that works:


      /**
      * Block site for non-logged in users
      */
      add_action('get_header', 'wpq_member_only_site');

      function wpq_member_only_site() {

      // logged in users or visits to a specified page are allowed
      if ( !is_user_logged_in() && !is_page( 'user-registration' ) ) {

      // vars
      $redirect_after_login = 'http://' . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
      $login_url = wp_login_url( $redirect_after_login );

      // redirect visitors
      wp_redirect( $login_url, 302 );
      exit;

      }

      }


      I made some tests and it seems there are no issues. Let me know if it's OK.

    • 01/26/12 6:21pm

      Josh Cranwell says:

      Dude, you are a legend!!!

      I've tested it through out my site. Seems to work perfect. Even when on different languages and no problems logging out.

      I think you nailed it. Cant thank you enough!!!

      If I notice anything weird I'll drop you an email but think we're pretty good.

      Thanks Ivaylo

  • avatar
    Last edited:
    01/26/12
    3:39pm
    Ross Wilson says:

    Odd, you should be able to use the member access plugin. Do you have a link for your registration page you can share. My guess is that the page you are submitting the registration to is causing the redirect.

    Ross

    Previous versions of this answer: 01/26/12 at 3:39pm

This question has expired.



Gabriel Reguly, idt, Hai Bui, Christianto, Josh Cranwell, Julio Potier, Luis Abarca, Francisco Javier Carazo Gil, Ross Wilson voted on this question.



Current status of this question: Completed



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.