WP eMember Miscellaneous Tweaks
If you are a developer and want to customize the code or if you want to add conditions around your content (can be useful when you want to protect content that you added to your theme’s template file) then here are a few code examples that might be of some help:
Find out if a member is logged in or not
You can use the following function call to determine if a member is logged in or not. The following function call will return true if a member is logged in (otherwise it will return false)
wp_emember_is_member_logged_in()
You can utilize the above function in the following way to ad code in your theme’s template file to add conditional block (for example: show a special message to your logged in users):
<?php if(wp_emember_is_member_logged_in()) { ?>
//Place your special message for members here
<?php } ?>
The following example can be useful if you want to show ad to non-members of the site:
<?php if(!wp_emember_is_member_logged_in()) { ?>
//Place your ad code here
<?php } ?>
The following example can be useful if you want to show a message to a member who belongs to membership level 1:
<?php if(wp_emember_is_member_logged_in('1')) { ?>
//Place your special message for members from membership level with ID 1
<?php } ?>
The following PHP code example shows how you can programmatically retrieve the member ID of a member and add condition:
<?php
global $emember_auth;
$user_id = $emember_auth->getUserInfo('member_id');
if (!empty($user_id))
{
//pleace code that only members can see
}
?>
Hiding Post Title From Non Members
We will use the “wp_emember_is_member_logged_in” function (explained above) to modify the “Twenty Eleven” theme and make the post title only visible to users who are logged in.
This is an example for when a post is displayed on a single page – ie, I edited the content-single.php file:
The original line of code was as follows:
<h1 class="entry-title"><?php the_title(); ?>
To hide the post heading/title , I modified it as follows:
<h1 class="entry-title"><?php if(wp_emember_is_member_logged_in()) the_title(); ?>
The above is a simple example which will suppress the post heading if someone is not logged in.
Get member id and his/her membership level
<?php
global $emember_auth;
$user_id = $emember_auth->getUserInfo('member_id');
if (!empty($user_id))
{
//User is logged in so add your conditional code here
$membership_level = $emember_auth->getUserInfo('membership_level');
if($membership_level == 1)
{
//Add stuff for this level
}
}
?>
Show Logged in Member’s Username or other details
<?php
global $emember_auth;
$username = $emember_auth->getUserInfo('user_name');
echo "Username of the logged in member: ".$username;
?>
Show Logged in Member’s Details Using Shortcode
You can use a shrotcode to show any details of the logged in member on a WordPress post or page. Refer to the eMember shortcode documentation for more details.

To simplify the above. You should have already created a Register or Registration page that has this shortcode:
[wp_eMember_registration_form:end]
1. Open the “old” Register/Registration page in your WP dashboard. Replace the original shortcode above with:
[free_rego_with_email_confirmation]
2. Cut and paste the original shortcode to the new Free Membership page:
[wp_eMember_registration_form:end]
3. In eMember control panel go to: WP eMembers – Pages Settings => Registration Page:
Change the path name to the new free membership page:
./pathname/free-membership-page-name/
4. Tweak copy on new Free Membership page to suit.
There are a few ways to do this… it all depends on your choice but you basically just need to enter the following shortcode on your “Join Us” page rather than telling them to the go directly to the “registration page”:
[free_rego_with_email_confirmation]
Leave your response!
Get the WP eMember Plugin
Categories
Blogroll
Recent Comments
Tips and Tricks Hot Items