Jump to content

Members only content


AnotherAndrew
 Share

Recommended Posts

I'm trying to wrap my head around how to implement a members only section of a site where specific content could be delivered to a site visitor based on their login credentials. For example, "Sarah" logins and she sees content only specified for her and "Bob" logins and sees only content for him, and so on. And it would also need to be easy for the site administrator to easily add the login credentials, and then also easily add content for that user.

I have a client who wants to be able to share videos with potential customers and they don't want the general public to see these videos. I have done a PW site that has a members only section, but everyone sees the same content since they have the same login info. I'm thinking that I would have to have the site admin be able to add a new role to a user to be able to view a page specific to them.

Can this be done with PW and if so, does anyone have suggestions as to how I can implement this?

Thanks!

Link to comment
Share on other sites

One of the ways is to extend user template (don't forget to set filter to display system fields in the list) with a new field "viewable_pages" of a Page type and let site admins select pages that user need view. In order it to work you have to add additional check if the current page is accessible to a user into all of your templates (you can do it in the header you include in each template). Then if the page is in the list you output it's content to a user otherwise you redirect them or show them an error message.

Should be something like this:

if ($user->viewable_pages->has($page)) showUserContent();
else showError();

This is one of the basic methods, there are many of them, as always in PW ;)

  • Like 3
Link to comment
Share on other sites

  • 1 month later...

Slkwrm, I set up a new template and called it members template. At the top of that I put in this check:


<?php
if ($user->viewable_pages->has($page))
{
echo $page->body;
}
else {
echo "Nope";
};
?>

But I keep getting this in the error logs: Error Call to a member function has() on a non-object, and the user content is not displayed.

Link to comment
Share on other sites

Slkwrm, I set up a new template and called it members template. At the top of that I put in this check:
<?phpif ($user->viewable_pages->has($page)){echo $page->body;}else {echo "Nope";};?>

But I keep getting this in the error logs: Error Call to a member function has() on a non-object, and the user content is not displayed.

That error indicates the $user->viewable_pages either doesn't exist and or is not an page array so it can't call has().

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...