WordPress.org

Ready to get started?Download WordPress

Forums

125

Members only sections (131 posts)

  1. mach2racer
    Member
    Posted 6 years ago #

    Looking for a flawless or semi flawless plugin that will enable a members only sections of a wordpress site?
    Looking for something that will turn it into a pay per view site.. Any one know of such a plugin?

  2. mores
    Member
    Posted 6 years ago #

    Write it yourself.
    Create a template, and assign this template to the pages you want to make accessible only for members.

    I did it by copying the index.php file, called it index_secure.php and added a `
    <?php
    /*
    Template Name: For Registered Users only
    */
    ?>`
    at the top. Then, where everything is being displayed, meaning before the loop, I added `
    <?php if (is_user_logged_in()) { ?>`
    so that in the else part I could write "sorry, you need to be logged in".

    Hope this helps.

  3. mach2racer
    Member
    Posted 6 years ago #

    Okay so you take the frame out of index.php and add that code for whereit needs to go and you can make a sorta VIP page or even area out of it?
    I checked out your site I like the look, but don't know what it says..lol

  4. mach2racer
    Member
    Posted 6 years ago #

    Do you implement the users page with the page template selection?

  5. mach2racer
    Member
    Posted 6 years ago #

    Okay so does this go into the template or theme?

  6. mach2racer
    Member
    Posted 6 years ago #

    okay I made it and when I published the page it didn't show up. So it is hiding. No what do I do to put it on the page and make it so people have to sign up to get on there?

  7. flick
    Member
    Posted 6 years ago #

    The code that mores gave you should be used in a separate template file (called e.g. members.php) that is uploaded to your server. Then when you create the page itself with wordpress, the page template for this page will be members.php (or whatever you decide to name it)

    Might be worth doing a search on the forums for a possible plugin (no promises here) but I know this isn't the first time that someone has asked for it :)

  8. mach2racer
    Member
    Posted 6 years ago #

    well the code hid the page.. I was just wondering how to you access it once it is hiding? where and how?

  9. Dan Milward
    Member
    Posted 6 years ago #

    http://www.instinct.co.nz/e-commerce

    If you use WP e-Commerce you can use the members only module to lock pages and posts to members only.

    We're actually doing a chunk of work on this at the moment. We are building a members only token system - so if you are a member to a site and you want to view members only content (i.e. video file) it will cost you one token per video you watch.

    Ciao,

    Dan

  10. mach2racer
    Member
    Posted 6 years ago #

    Thanks Dan I will try that..

  11. flick
    Member
    Posted 6 years ago #

    @machracer: You could probably insert something outside the 'if user logged in' part to show the login form or a message to say 'registration needed' or 'you need to be logged in'?

  12. mach2racer
    Member
    Posted 6 years ago #

    What do you mean mosey?

  13. flick
    Member
    Posted 6 years ago #

    Mores mentioned this already in his post

    so that in the else part I could write "sorry, you need to be logged in".

    I'm not familiar with PHP, but apparently if you put:

    IF (this condition) A happens

    ELSE B happens.

    So in your case, where users aren't logged in, the instructions are B. And you might put something like 'sorry you need to be loggedin' as mores suggested or a link to the login page.

  14. mach2racer
    Member
    Posted 6 years ago #

    yeah, and rught now I am looking for a plugin that will lock a page. and another put in a sign in link on it.

  15. flick
    Member
    Posted 6 years ago #

    I'm not sure how best to explain this. With the code that mores provided, it is possible to NOT use a plugin to create member-only sections.

    How does it work?
    I'm presuming you have an understanding of how a page template works, and bearing in mind I have not tested this code: This particular part <?php if (is_user_logged_in()) { ?> sets a condition:

    If the user is logged, they can see the content after this code and before the closing tag.

    Example:

    <?php if (is_user_logged_in()) { ?>
    Oranges and lemons
    <? } ?>

    If the user is logged in, they can see 'Oranges and lemons'. If they're not, they can't and the page is blank.

    But let's presume you want to inform the users who aren't logged in that they have to login to see this content.

    So this is where the else comes in.

    <?php if (is_user_logged_in()) { ?>
    Oranges and lemons
    <? } else { ?>
    You must be logged in!
    <? } ?>

    Anyone who isn't logged in will see 'You must be logged in!' And you can easily put a link to the login page.

    I'm not quite sure how else to explain this, but this sort of explanation worked for me (and I'm a slow learner) so hopefully you'll find it helpful too.

  16. mach2racer
    Member
    Posted 6 years ago #

    Yeah it is.. I am going to do my best to contact you.. or if I cant can you contact me? You would be so helpful if we talked more. I am helping out a friend and I am stuck.

  17. flick
    Member
    Posted 6 years ago #

    @mach2racer: I'm not sure how much I would be able to help (since I just poke around WordPress rather than work under the hood) but I've sent a message through the contact form on your website.

  18. mach2racer
    Member
    Posted 6 years ago #

    Hey same here..lol

  19. Joni
    Member
    Posted 6 years ago #

    Yep, it worked like a charm, thanks!

    See it here:
    http://wordpress.mytestbed.com/members-only

    Here's the code I put in the page; mind you, the style hooks will be different on your page template, more than likely. [CODE EDITED at 9:02 PM]

    <?php
    /*
    Template Name: Members Only
    */
    ?>
    
    <?php get_header(); ?>
    <div id="container">
    <div id="content">
    <?php if (is_user_logged_in()) { ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    
    <h3 class="page-title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_title(); ?></a></h3>
    
    <div class="post">
    		<?php the_content(); ?>
    [deleted first .post closing division]
    
    <?php endwhile; ?>
    <?php endif; ?>
    <? } else { ?>
    
    <h3>Sorry But You Must Be Logged in to View This Page</h3>
    <div class="post">
    
    		We're sorry, but this area is only for registered, logged in users. If you are a registered user, please use the link below to login to the site.  If you have not yet registered, please use the link below to register to become a member of this site and view content not available to the general public.  If you have any questions, please contact us.
    
    <? } ?>
    </div> <!-- /post -->
    </div><!-- /content -->
    </div><!-- /container -->
    <?php get_sidebar(); ?>
  20. ClaytonJames
    Member
    Posted 6 years ago #

    I have a question... and I'll tell you right up front, I become easily lost in the PHP forest, so if the answer to this is already obvious, just give me a slap and I'll go dig out a text book. This really appeals to me because I hate password protected pages, but is it possible to easily modify the " <?php if (is_user_logged_in()) { ?> " statement to limit viewing to a particular user or group of users?

  21. flick
    Member
    Posted 6 years ago #

    Thanks jonimueller! :) I think the code you've posted will be really useful for lots of people! Will the testbed site stay up for umm... forever? :p

    @ClaytonJames (and everyone else) : I just found a site/page by Ben at RedWingStudio which talks about user-only/protected pages. And he actually addresses the issue of limiting viewing to a particular group of users in the comments, by using another plugin called Role Manager.

    Is anyone willing to try it out perhaps and share the results here? :)

  22. Joni
    Member
    Posted 6 years ago #

    Actually, Mosey posted the essential code. I just took that and fleshed it out a bit; but without him, I'd have been clueless!

    As far as my test site is concerned, since I own mytestbed.com and have renewed it for 10 years, it'll be up for awhile. I put all my test stuff there. I'll install role manager and play with the RedWingStudio script tomorrow.

  23. mach2racer
    Member
    Posted 6 years ago #

    Now the question is how do you go and build a registration, area? I am sure you can use cform? Or is that too much?

  24. ClaytonJames
    Member
    Posted 6 years ago #

    Is anyone willing to try it out perhaps and share the results here? :)

    I think I might. I already use role manager, so I will read the article and see if it is something I can get a handle on. Thank you!

  25. mach2racer
    Member
    Posted 6 years ago #

    Way to take one for the team

  26. flick
    Member
    Posted 6 years ago #

    Thanks in advance, jonimueller and ClaytonJames!

    @jonimueller: It's the fleshing out that makes it make more sense! Otherwise it would be difficult to figure out where each part goes. I was just wondering if it was going to be online (for people searching say several months on from now) otherwise I guess could always include a screenshot instead of having a live site? Thanks :)

  27. mores
    Member
    Posted 6 years ago #

    Sorry for being away so long, but jonimueller's code is basically what you need.

    Where it says "Sorry, need to be logged in" I added a login box using this

    <form class="ddfm" name='loginform' id='loginform' action='/wp-login.php' method='post'>
    	<p class="fieldwrap"><label for="log">Username</label><input class="fmtext" type="text" name="log" id="log" value="" tabindex='1' /></p>
    	<p class="fieldwrap"><label for="pwd">Password</label><input class="fmtext" type='password' name='pwd' id='pwd' value='' tabindex='2' /></p>
    	<input name='rememberme' type='hidden' id='rememberme' value='false' />
    	<div class="submit">
    		<input type='submit' name='submit' id='submit' value='Login &raquo;' tabindex='3' />
    		<?php //use a hidden field to return them to the page they came from ?>
    		<input type="hidden" name="redirect_to" value="<?php echo $_SERVER["REQUEST_URI"]; ?>" />
    	</div>
    </form>

    I actually can't remember why I have the form named after the dragon design form mailer, maybe I was just lazy and used some code. I don't think you need ddfm for that.
    But underneath this I added a "If you want to request a login, send me an email" with a ddfm mail form under it using <?php global $ddfm; echo $ddfm{3}->generate_data(); ?>

    This only works when you set your WordPress installation to "users cannot register". Otherwise they just register and get immediate access. You control the site by adding users when you want them added.

  28. mach2racer
    Member
    Posted 6 years ago #

    Thanks I saved that bad boy.

  29. ClaytonJames
    Member
    Posted 6 years ago #

    mosey- Great link, thank you!
    joni- You make it look so easy!

    The info in this comment thread worked for me.

    http://www.redwingstudio.com/2007/04/05/user-onlyprotected-pages-in-wordpress-2/#comment-294

    Steps I took:

    A) Installed Role Manager plugin. (I already had it in use).

    http://www.im-web-gefunden.de/wordpress-plugins/role-manager/

    B) Created a new capability exactly per the instructions, and assigned it to a specific account.

    C) Downloaded the template:

    http://www.redwingstudio.com/downloads/user-and-role-protected.php.zip

    D) Modified the template to fit my theme, uploaded it to my theme folder, created a new page and applied the template. The page was then only available to the account I gave the new capability to. I then created a sub-page for my new page, and applied the same "hidden" template. Successful test. Page and subpage are only viewable by the account with capabilities.I then created a sub-page on an unprotected (normal) page and applied the template. The unprotected page remained viewable while the new subpage required a log in. Another Successful test.

    There is a login form in the template by default, but I could not get it to work for me. I already use a re-direct on login, so maybe there was some conflict. I did not pursue it because it wasn't important to me. (I know, I'm a selfish bastard sometimes). Now here's a big one... Is there a way to take this one step further and hide the page links until an authorized user logs in, rather than displaying them with a "restricted" notice?

  30. flick
    Member
    Posted 6 years ago #

    Thanks for evaluating the solution suggested by RedwingStudio, claytonjames! :) Am really glad to read that it does work!

    Unfortunately I'm not sure about the login box either, but with regards to the page links, do you mean not displaying links in the navigation bar to visitors (rather than registered users)?

    If this is the case, the most straightforward way I can think of would be to exclude the page ids from the usual navigation, and then perhaps use the function again somewhere else on the page but this time include the 'if user logged in' condition before <?php wp_list_pages(); ?>?

    I'm 100% certain there are better ways of doing this, so any suggestions would be great! ^^

125

Topic Closed

This topic has been closed to new replies.

About this Topic