Membership and user management is often one of those features most required for a complex online property and yet one of the more difficult to deal with. With the Placester plugin and WordPress, this however becomes very easy to implement. In fact the entire problem is reduced to incorporating just a few lines of PHP into your theme. The primary function of memberships at this time is to save favorite listings. In future, saved searches and notifications will be added to this.
Testing If User Is Logged In
There may be some sections you only want to have appear if a user is logged in or not. To test for this, use the WordPress function is_user_logged_in().
<?php if (!is_user_logged_in()): // Do stuff if user is not logged in else : //do something else if they are. endif; ?>
Provide Login and Registration Forms
Its useful at the top of the page to have an area with links to either Login to the site or register for an account. To include this just use the PLS_Plugin_API method: placester_lead_control_panel. When the user visits the page, they will see a login form or a sign up form when they click on those links.
<?php echo PLS_Plugin_API::placester_lead_control_panel(array('separator' => ' or ')); ?>
In the case of the code sample above, only a single parameter is given: separator. Separator is what separates the links shown in the lead control panel. But you could include a few other parameters as listed below:
- loginout – defaults to true
- profile – defaults to true
- register – defaults to true
- container_tag – defaults to false
- anchor_tag – defaults to false
- anchor_tag – defaults to false
- separator – defaults to ‘|’
- inside_pre_tag – defaults to false
- inside_post_tag – defaults to false
- no_forms – defaults to false
One of the features most users will expect is the ability to add a property to a list of favorites. You will find this feature in all of the placester themes and is quite easy to add to your own themes with a little PHP.
Typically you would show the Add to Favorites link at the bottom of the listing in either the list of listings or the property detail view. In both cases the code to use is exactly the same:
<?php echo PL_Membership::placester_favorite_link_toggle(array('property_id' => $listing['id'], 'add_text' => 'Add to Favorites', 'remove_text' => 'Remove from Favorites')); ?>
In the above code, there are three parameters being passed to the placester_favorite_link_toggle method: property_id, add_text, and remove_text. You should always include the property_id but if the other two are left out, they default to: “Add property to favorites” and “Remove property from favorites”.
Show All Favorites
When a user has collected a few favorites, they can visit their account page to see a list of all their favorited listings. To generate this list, you use the same get_listings_list_ajax you use for regular property listings with one main difference:
<?php echo PLS_Partials::get_listings_list_ajax('context=listings_search&table_id=placester_fav_list&show_sort=1'); ?>
It’s the table_id=placester_fav_list that does all the magic here of collecting the favorite listings of this user.
Edit Account Information
After a user has created an account so they can save their favorites, they might want to edit their information. To modify this functionality is a bit more awkward at the moment. For an example of how to do this, look at sidebar-page-client-profile.php in Blueprint or in some of the Placester themes.