WordPress.org

Ready to get started?Download WordPress

Forums

WP-Members
custom page template issue (10 posts)

  1. seanpre
    Member
    Posted 2 years ago #

    Firstly - thank you for a wonderful plugin.
    I have reviewed many membership plugins and this one stands out head and shoulders above the rest.

    I am trying to protect all content unless a user is logged in.
    My default settings are pages & posts protected + not showing excerpts.
    This works well for all pages that do not use custom templates...

    However I have two pages using custom page templates and the privacy is simply overridden. I delved into the template page code and was able to make the login appear by including <?php the_content(); ?> but then the custom page template content is displayed below this.

    If I use the custom field switch for just that page, I can get the login to appear and disappear depending on the switch used but the page content is ignored.

    I guess this is related to the loop and how my page template is structured.
    Any advice on how to set this up correctly with a custom page template?

    http://wordpress.org/extend/plugins/wp-members/

  2. spectrus
    Member
    Posted 2 years ago #

    I have a similar issue, using a custom WP_Query in a custom page template.

    If I remove the custom query code and leave the usual if ( have_posts() ) stuff in - it works fine. Has anyone else seen behaviour like this?

    Thanks.

  3. Chad Butler
    Member
    Plugin Author

    Posted 2 years ago #

    @seanpre - that's an interesting dilemma.

    Do the custom templates display multiple posts or single?

    The plugin is designed to filter the contents returned by the_content, so if you are using the Loop to display, it should function normally.

    How is the content being delivered to the template?

    If these templates show multiple posts, are you using the 'more' tag?

  4. Chad Butler
    Member
    Plugin Author

    Posted 2 years ago #

    @spectrus - the plugin is designed as a filter for the_content. If you use wp_query outside the loop to deliver the content, the plugin doesn't know to protect it.

    If this is something that is relatively static, the solution might be to go a step further and use is_user_logged_in. Something like:

    <?php
    if( is_user_logged_in() ) {
    
    	// user is logged in
    	// do your wp_query here...
    
    } else {
    
    	// user is not logged in
    	// display something else
    
    }
    ?>
  5. seanpre
    Member
    Posted 2 years ago #

    Thanks for the reply Chad.

    The two page templates are not displaying multiple posts or pages.
    The one is an order form which has form elements linking to custom fields and some jQuery to handle the price calculations on the fly.
    The other is a booking form, so both are serving their own unique content from within the respective template.

    I used your suggestion above and it works thank you.
    I put all the necessary code in a 3rd file and call this with an include if the user is logged in, if not I display the_content so your login form is displayed.

    <?php
    if ( is_user_logged_in() ) {
        include "bookings-calculation.php";
    } else {
         the_content();
    }
    ?>
  6. Chad Butler
    Member
    Plugin Author

    Posted 2 years ago #

    Glad that is working out! And thanks for posting this because I know there are others out there doing similar things. It's good to have some examples out there.

  7. spectrus
    Member
    Posted 2 years ago #

    Thank you very much Chad, I take off my hat to you for such speedy responses on this board.

    I fixed it by altering your code sample to the following:

    <?php
    if( is_user_logged_in() ) {
    
    	// my wp_query here...
    
    } else {
        if (function_exists('wpmem_securify'))
        {
            // display loging prompt as on other pages
            echo '<h1 class="entry-title">' . get_the_title() . "</h1>";
            wpmem_securify();
            the_content();
        }
    }
    ?>
  8. Chad Butler
    Member
    Plugin Author

    Posted 2 years ago #

    That's good stuff... thanks!

  9. Chad Butler
    Member
    Plugin Author

    Posted 2 years ago #

    Thanks for helping fine tune this. I've been getting this question in various formats quite a bit lately, so I put this together in a specific 'how-to' kind of post.

  10. seanpre
    Member
    Posted 2 years ago #

    wow! - great feedback and support Chad.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags