WordPress.org

Ready to get started?Download WordPress

Forums

page only for registered users (13 posts)

  1. kapara
    Member
    Posted 2 years ago #

    hi

    i'd like to create a page that only registerd users (who are logged-in) will be able to see it.

    if you are not registered/loged-in you will be redirected to a login/register page.

    if you are already registered and loged-in you will see the requested page.

    how do i do it?

    thanks

    lenny

  2. Peter Wooster
    Member
    Posted 2 years ago #

    Take a look at my Simple access Control plugin. It's intended for exactly that purpose.

    It currently doesn't do the redirect, it just advises the user to login.

    /peter

  3. Jacob Chappell
    Member
    Posted 2 years ago #

    All you need is to add this function to the top of the page you want to require authentication on. It will take care of the rest.

    <?php auth_redirect(); ?>

    If the user is logged in they will see the page normally, otherwise they will be redirected to login and then directed back to the page they left once they are successfully authenticated.

    This function sends headers so you'll need to make sure you use it early enough. I haven't tested this, but you can probably hook into the init action and run the code from there.

  4. kapara
    Member
    Posted 2 years ago #

    This function sends headers so you'll need to make sure you use it early enough. I haven't tested this, but you can probably hook into the init action and run the code from there.

    sorry, i'm not a programmer, could you please write ... slower, so i can understand?

    could you please explain what i should do?

    thank you very much

    lenny

  5. kapara
    Member
    Posted 2 years ago #

    to pkwooster:
    thanks, i'll try it

    lenny

  6. kapara
    Member
    Posted 2 years ago #

    to pkwooster:

    thanks, i DL and installed, i have a couple of questions but it looks great.

    i'll be in touch

    thanks

    lenny

  7. Jacob Chappell
    Member
    Posted 2 years ago #

    @kapara Try going into your theme's header.php and pasting this code at the very tip top:

    <?php if ( is_page( $PAGE_ID ) ) auth_redirect(); ?>

    Replace $PAGE_ID with the ID of the page that you're trying to restrict to members only. You should be able to find this page id easily by editing the page in your WordPress admin, then looking at the URL and finding the post=# bit where # is the page id.

    Edit: Added PHP tags.

  8. Peter Wooster
    Member
    Posted 2 years ago #

    Hi Lenny,

    I got your message and will add the ability to specify whether the menu should be filtered and a link to wp-login in the "not logged "in text.

    /peter

  9. Dave333
    Member
    Posted 2 years ago #

    This plugin looks like what you need.

    http://wordpress.org/extend/plugins/user-access-manager/

  10. Peter Wooster
    Member
    Posted 2 years ago #

    I originally used User Access Manager. That was the inspiration to write Simple Access Control. UAM is way more than you need, for more complex membership sites it's great.

    Unlike UAM Simple Access Control does not add any tables to your database and the code is simple enough that you can extend it if you need to.

    I've just updated Simple Access Control to provide the menu control and login link.

    /peter

  11. Dave333
    Member
    Posted 2 years ago #

    Thanks pkwooster.

    I'll try your plugin out too.

    What is the benefit of it not adding tables to the database? Doesn't that mean it won't be backed up with the normal database backup?

  12. Peter Wooster
    Member
    Posted 2 years ago #

    It uses the standard WordPress tables wp_options and wp_usermeta. The advantage is that you don't end up with database clutter.
    /peter

  13. vjpo
    Member
    Posted 2 years ago #

    One another note about UAM. Even if you only activated it, you are getting already about 50 extra database queries. After creating user groups it adds more and more database queries for each created user group.
    For example, the Members plugin doesn't add any one query.

Topic Closed

This topic has been closed to new replies.

About this Topic