Trying to query for categories and display archive pages in a protected plugin

I'm a "hunt and peck" PHP person - I really don't know that much about PHP, and generally just try to find examples that do what I want, and copy them. Sorry :slight_smile:

I am trying to edit a plugin that I purchased for another membership site that is locked down pretty tightly (this is not the WPMU Membership plugin).

If you are not logged in, you only have access to certain pages, and have no access to blog posts. I would like to give access to blog posts. My thought is that if I can make a query that will check for a category and return the archive page for that category regardless of whether logged in, that would work. So, I know that I'm close, because instead of getting a "you don't have access to this content" when trying to get to my "welcome" category, I get a blank page. I'm sure it's just that I have no idea what I'm supposed to "return" for the archive page. Here's what I've added:

if (is category ("welcome"))return '/archive.php';

I've also tried to "return $template" - my guess is that "return" might not be what I want. In any event, I would like for any posts in a couple of categories to be visible to all visitors. I know that once I get the context right, I can add an array for the categories, so I really just need to get one of them working.

Thanks!

Danita

  • Patrick
    • Support Monkey

    Hi @Danita

    I'm a hunt and peck" PHP person too :slight_smile:

    Does that membership plugin not have the capability to restrict specified post categories, rather than all posts?

    If not, then you may need to peek into the plugin files to find where the conditional is that locks not-logged-in users out. It may even be a simple if is_user_logged_in () conditional. In which case, you may be able to override it right there.

  • Ash
    • WordPress Hacker

    Hello there

    Welcome to WPMU community!

    I hope you are well today and thanks for asking the question.

    I'm a "hunt and peck" PHP person - I really don't know that much about PHP, and generally just try to find examples that do what I want, and copy them. Sorry :slight_smile:

    Don't worry about that. Most of the people do this and you are okay until you know what you want :slight_smile: and we people are here always to help you :slight_smile:

    So, I know that I'm close, because instead of getting a "you don't have access to this content" when trying to get to my "welcome" category, I get a blank page.

    As you are getting a blank/white page, it might be for producing an error. When you are seeing a blank page, would you please enable debug mode (in wp-config.php change define('WP_DEBUG', false) to define('WP_DEBUG', true) and refresh the page to check if there is any error shown,

    As this is a third party plugin, I am not pretty sure how they handles the restriction. But the idea could be like this - when the restriction is set, you can just ask the plugin not to add a specific category (with slug or ID may be) in the restricted area. Also you may use is_logged_in() function to override the rules.

    Otherwise, id you use our membership plugin plugin, you can restrict the content page-wise, category wise or even with group-url-wise. It's worth to take a look at:
    https://premium.wpmudev.org/project/membership/#usage
    https://premium.wpmudev.org/wp-content/uploads/2010/05/Membership-Manual3440.pdf
    http://www.youtube.com/playlist?list=PLV1BcivFAIdtF4p7CYVfMbVAJ4JQ1Rpe9

    Please let me know if it is helpful and feel free to ask more question if you have.

    Cheers
    Ash

  • Danita
    • The Incredible Code Injector

    I had a breakthrough!

    So, this particular plugin has a couple of unique things to it.

    1. All blog posts are protected.
    2. All blog posts have a "postmeta" field that designates what "day" a post should be delivered to a user, based on the member's start date.

    I had been testing this with the WPMU Membership plugin, just using their template for the layout, etc., and it was working excetp that without adding that delivery date, posts will not show up in the category archive. I finally poked around in the archive.php and found that metadata field, took it out, and now new posts do not need to receive that value to show up on the page! So I can use the membership "content" that I had already created with the other plugin, and now I can manage content delivery with WPMU Membership - so while I still don't know how to do what I original thought might work, it doesn't really matter, because I can instead just use the WPMU template (which is my preference anyway)!

    So, thanks for listening - heehee.

    Danita

  • Danita
    • The Incredible Code Injector

    Well, maybe! I'm running into another issue with Membership and how it does its "drip" memberships that might send me back to trying to edit this plugin. I guess I just need to figure out the syntax to return the archive.php template if the category is one that I want. And even if I do get the WPMU plugin issue solved, this will teach me something about PHP - so not a fruitless quest overall.

    So back to the original question I guess.

    if (is category ("welcome"))return '/archive.php';

    That doesn't return the page. So I suspect that I'm going about it the wrong way. But this is generally what I'm looking for. An "if" statement that says show the page if the category is "welcome".

    Thanks.

    Danita

  • Danita
    • The Incredible Code Injector

    No - I have a quandry. This membership plugin that I purchased last year (not WPMU) is too locked down, but the WPMU Membership Plugin doesn't have flexible enough "drip" rules to work the way I want. I either need to find a workaround for the WPMU plugin or a workaround for the old plugin.

    I would prefer to use the WPMU plugin, but someone over in that group is pondering my needs there. In the meantime, I'm trying to get ONE of them to work the way I need. This plugin I'm trying to modify would probably work perfectly if I could loosen it up a bit.

    Danita

  • Danita
    • The Incredible Code Injector

    I would SWEAR that I've done this very syntax over and over, but it's working, so I guess I must have been dreaming:

    if (is_category ("innerpeace")) return $template;
    if (is_category ("welcome")) return $template;

    Maybe I'll get brave now and try to combine the two lines into an array!!

    Thanks for the moral support - I appreciate having folks to bounce these things off.

    Danita

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.