Website Membership
Apart from User Accounts (which handle logging into the CMS Admin), CMS Builder supports member accounts on your public website: visitors can sign up, log in, edit their profile, and view members-only pages.
Front-end logins are handled by the Website Membership plugin. It’s included with modern CMS Builder releases as a required system plugin; if it isn’t in your plugins list, download it from the Website Membership plugin page.
How it works
Section titled “How it works”By default, the plugin stores website members in the same accounts table as CMS users,
so new sign-ups appear under Admin > User Accounts. It adds a set of
Code Generator page types for the membership pages, makes the logged-in
visitor available to front-end viewers as $CURRENT_USER, and provides a redirect
function for protecting pages.
Generating the membership pages
Section titled “Generating the membership pages”Admin > Code Generator > Website Membership generates four page types. Save each one under its recommended filename (or choose your own and update the matching URL variable in the plugin file; see Configuration below):
| Page type | Recommended filename |
|---|---|
| Login Page | user-login.php |
| Create Account | user-signup.php |
| Forgot Password | user-password-request.php |
| Edit Profile | user-profile.php |
The Forgot Password page handles both the request form and the emailed reset link (the email links back to the same page with a reset code). As with all generated code, adjust the HTML to match your site design.
Members-only pages
Section titled “Members-only pages”To require login for a page, add this to the top:
<?php require_once "cmsb/lib/viewer_functions.php"; ?><?php if (!$CURRENT_USER) { websiteLogin_redirectToLogin(); } ?>Visitors who aren’t logged in are sent to the login page and returned to the original page after logging in.
User-specific content
Section titled “User-specific content”$CURRENT_USER holds the logged-in visitor’s account record (or nothing when
logged out), so viewers can vary content by login state or account fields:
<?php if ($CURRENT_USER): ?> Welcome back, <?php echo htmlencode($CURRENT_USER['username']) ?>!<?php else: ?> <a href="/user-login.php">Log in</a> or <a href="/user-signup.php">create an account</a>.<?php endif ?>Any field on the accounts table works the same way, such as
$CURRENT_USER['premium'] for a checkbox that gates premium content.
To show each member only their own records, load records with the
createdBy.* fields (on by default via the loadCreatedBy
viewer option) and filter with a where clause
on createdByUserNum.
Configuration
Section titled “Configuration”Variables at the top of websiteMembership.php control the page URLs and
behavior:
WEBSITE_LOGIN_LOGIN_FORM_URL,WEBSITE_LOGIN_SIGNUP_URL,WEBSITE_LOGIN_REMINDER_URL,WEBSITE_LOGIN_PROFILE_URL— locations of the generated pages; update these if you save the pages under different names or paths.WEBSITE_LOGIN_POST_LOGIN_URL/WEBSITE_LOGIN_POST_LOGOFF_URL— where visitors land after logging in or out when no return page is set.WEBSITE_LOGIN_REQUIRED_FIELDS— account fields that must be filled in; logged-in members missing any of them are redirected to the profile page (default:agree_tos,agree_legal).WSM_ACCOUNTS_TABLE— set to a different table name to store website members separately from CMS users; the plugin creates a “Website Users” section for it automatically when specified.WSM_SEPARATE_LOGIN— allows being logged in to the website and the CMS Admin simultaneously as different users.
Email templates
Section titled “Email templates”The plugin installs two email templates, editable under Email Settings > Email Templates:
USER-SIGNUP— account details sent after sign-up.USER-PASSWORD-RESET— the password reset link, with#user.email#and#resetUrl#placeholders.