{"id":248,"date":"2010-08-15T18:48:01","date_gmt":"2010-08-16T01:48:01","guid":{"rendered":"http:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/?p=248"},"modified":"2017-07-22T17:38:37","modified_gmt":"2017-07-23T00:38:37","slug":"wp-emember-miscellaneous-tweaks","status":"publish","type":"post","link":"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/wp-emember-miscellaneous-tweaks-248","title":{"rendered":"WP eMember Miscellaneous Tweaks"},"content":{"rendered":"<p>If you are a developer and want to customize the code or if you want to add conditions around your content then the following code examples\u00a0should be helpful.<\/p>\n<h2>Find\u00a0out if a member is logged in or not<\/h2>\n<p>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)<\/p>\n<pre>wp_emember_is_member_logged_in()<\/pre>\n<p>You can utilize the above function\u00a0in\u00a0the following way to ad code in your theme&#8217;s template file to add conditional block (for example: show a special message to your logged in users):<\/p>\n<pre>&lt;?php if(wp_emember_is_member_logged_in()) { ?&gt;\r\n\/\/Place your special message for members here\r\n&lt;?php } ?&gt;<\/pre>\n<p>The following example can be useful if you want to show ad to non-members of the site:<\/p>\n<pre>&lt;?php if(!wp_emember_is_member_logged_in()) { ?&gt;\r\n\/\/Place your ad code here\r\n&lt;?php } ?&gt;<\/pre>\n<p>The following example can be useful if you want to show a message to a member who belongs to membership level 1:<\/p>\n<pre>&lt;?php if(wp_emember_is_member_logged_in('1')) { ?&gt;\r\n\/\/Place your special message for members from membership level with ID 1\r\n&lt;?php } ?&gt;<\/pre>\n<p>The following PHP code example shows how you can programmatically retrieve the member ID of a member and add condition:<\/p>\n<pre>&lt;?php\r\n$emember_auth = Emember_Auth::getInstance();\r\n$user_id = $emember_auth-&gt;getUserInfo('member_id');\r\nif (!empty($user_id))\r\n{\r\n    \/\/pleace code that only members can see\r\n}\r\n?&gt;<\/pre>\n<h2>Hiding Post Title From Non Members<\/h2>\n<p>We will use the &#8220;wp_emember_is_member_logged_in&#8221; function (explained above) to modify the &#8220;Twenty Eleven&#8221; theme and make the post title only visible to users who are logged in.<br \/>\nThis is an example for when a post is displayed on a single page &#8211; ie, I edited the content-single.php file:<\/p>\n<p>The original line of code was as follows:<\/p>\n<pre>&lt;h1 class=\"entry-title\"&gt;&lt;?php the_title(); ?&gt;<\/pre>\n<p>To hide the post heading\/title , I modified it as follows:<\/p>\n<pre>&lt;h1 class=\"entry-title\"&gt;&lt;?php if(wp_emember_is_member_logged_in()) the_title(); ?&gt;<\/pre>\n<p>The above is a simple example which will suppress the post heading if someone is not logged in.<\/p>\n<h2>Get member id and his\/her membership level<\/h2>\n<pre>&lt;?php\r\n$emember_auth = Emember_Auth::getInstance();\r\n$user_id = $emember_auth-&gt;getUserInfo('member_id');\r\nif (!empty($user_id))\r\n{\r\n    \/\/User is logged in so add your conditional code here\r\n    $membership_level = $emember_auth-&gt;getUserInfo('membership_level');\r\n    if($membership_level == 1)\r\n    {\r\n        \/\/Add stuff for this level\r\n    }\r\n}\r\n?&gt;<\/pre>\n<h2>Get the homepage URL from the logged in member&#8217;s membership level<\/h2>\n<pre>&lt;?php\r\n$emember_auth = Emember_Auth::getInstance();\r\n$user_id = $emember_auth-&gt;getUserInfo('member_id');\r\nif (!empty($user_id))\r\n{\r\n    \/\/User is logged in so add your conditional code here\r\n    $membership_level_resultset = $emember_auth-&gt;userInfo-&gt;primary_membership_level;\r\n    $home_page_url = $membership_level_resultset-&gt;loginredirect_page;\r\n    \/\/Do something with this URL\r\n}\r\n?&gt;<\/pre>\n<h2>Show Logged in Member&#8217;s Username or other details<\/h2>\n<pre>&lt;?php\r\n$emember_auth = Emember_Auth::getInstance();\r\n$username = $emember_auth-&gt;getUserInfo('user_name');\r\necho \"Username of the logged in member: \".$username;\r\n?&gt;<\/pre>\n<h2>Check if the Logged in Member is Allowed to See a Post<\/h2>\n<pre>&lt;?php\r\n$emember_auth = Emember_Auth::getInstance();\r\n$post_id = \"10\"\r\nif($emember_auth-&gt;is_protected_post($post_id))\r\n{\r\n    \/\/This member is allowed to see this post\r\n}<\/pre>\n<h2>Retrieve Member&#8217;s Data<\/h2>\n<ul>\n<li><a href=\"http:\/\/www.tipsandtricks-hq.com\/forum\/topic\/how-to-retrieve-and-show-a-particular-info-of-the-logged-in-member\" target=\"_blank\" rel=\"noopener\">How to retrieve logged-in member&#8217;s data using a shortcode or PHP code<\/a><\/li>\n<li><a href=\"http:\/\/www.tipsandtricks-hq.com\/forum\/topic\/how-to-retrieve-and-show-details-of-a-specific-member\" target=\"_blank\" rel=\"noopener\">How to retrieve a particular member&#8217;s data using shortcode or PHP<\/a><\/li>\n<\/ul>\n<h2>Retrieve a Member Record Using the Username<\/h2>\n<p>The following PHP code will retrieve a member&#8217;s record for the given username:<\/p>\n<pre>&lt;?php \r\n$username = \"johndoe\";\/\/Replace with the actual username\r\n$member = emember_get_member_by_username ($username);\r\necho \"Member's First Name: \" . $member-&gt;first_name; \/\/Output the first name\r\necho \"Member's Last Name: \" . $member-&gt;last_name; \/\/Output the last name\r\n?&gt;<\/pre>\n<h2>Retrieve Total Members Count<\/h2>\n<p>The following PHP code will display the total members count:<\/p>\n<pre>&lt;?php echo emember_get_total_members(array()); ?&gt;<\/pre>\n<h2>Member Registration Completion Hook<\/h2>\n<p>If you need to execute some custom code after a member completes the registration, use the following action hook:<\/p>\n<ul>\n<li><a href=\"http:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/member-registration-completion-hook-866\">Registration completion action hook<\/a><\/li>\n<\/ul>\n<h2>Show Different Navigation Menu to your Members and Non-members<\/h2>\n<ul>\n<li><a href=\"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/show-different-navigation-menu-to-your-members-and-non-members-551\" target=\"_blank\" rel=\"noopener\">Tweak your navigation menu to show dynamic menu items to members and non-members<\/a><\/li>\n<\/ul>\n<h2>Show Logged in Member&#8217;s Details Using Shortcode<\/h2>\n<p>You can use a shrotcode to show any details of the logged in member on a WordPress post or page. Refer to the <a href=\"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/wp-emember-shortcodes-and-functions-reference-124\">eMember shortcode documentation<\/a> for more details.<\/p>\n<h2>Placing a Registration Form For a Particular Membership Level to Give Backdoor Entrance<\/h2>\n<ul>\n<li><a href=\"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/create-a-registration-form-for-a-particular-membership-level-429\">How to create a Registration Form for a Particular Membership Level<\/a><\/li>\n<\/ul>\n<p><a name=\"email_confirm_for_free_membership\"><\/a><\/p>\n<h2>Free Members Must Confirm Their Email Address<\/h2>\n<ul>\n<li><a href=\"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/free-members-must-confirm-their-email-address-460\">How to make the free members to confirm their email address<\/a><\/li>\n<\/ul>\n<h2>Get the Login Page&#8217;s URL from the System<\/h2>\n<pre>$emember_config = Emember_Config::getInstance();\r\n$login_page_url = $emember_config-&gt;getValue('login_page_url');\r\n<\/pre>\n<h2>Get the Registration Page&#8217;s URL from the System<\/h2>\n<pre>$emember_config = Emember_Config::getInstance();\r\n$login_page_url = $emember_config-&gt;getValue('eMember_registration_page');\r\n<\/pre>\n<h2>Get the Edit Profile Page&#8217;s URL from the System<\/h2>\n<pre>$emember_config = Emember_Config::getInstance();\r\n$login_page_url = $emember_config-&gt;getValue('eMember_profile_edit_page');\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>If you are a developer and want to customize the code or if you want to add conditions around your content then the following code examples\u00a0should be helpful. Find\u00a0out 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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[14],"tags":[84,8,88,19,39],"class_list":{"0":"post-248","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-additional-resources","7":"tag-member","8":"tag-membership-level","9":"tag-membership-tweaks","10":"tag-shortcodes","11":"tag-wordpress-membership","12":"entry"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>WP eMember Miscellaneous Tweaks - WordPress Membership<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/wp-emember-miscellaneous-tweaks-248\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/wp-emember-miscellaneous-tweaks-248#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/wp-emember-miscellaneous-tweaks-248\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/#\/schema\/person\/d68b2ffa792aeb141f10f910dacccfdd\"},\"headline\":\"WP eMember Miscellaneous Tweaks\",\"datePublished\":\"2010-08-16T01:48:01+00:00\",\"dateModified\":\"2017-07-23T00:38:37+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/wp-emember-miscellaneous-tweaks-248\"},\"wordCount\":517,\"commentCount\":4,\"keywords\":[\"member\",\"Membership Level\",\"membership tweaks\",\"shortcodes\",\"WordPress membership\"],\"articleSection\":[\"Additional Resources\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/wp-emember-miscellaneous-tweaks-248#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/wp-emember-miscellaneous-tweaks-248\",\"url\":\"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/wp-emember-miscellaneous-tweaks-248\",\"name\":\"WP eMember Miscellaneous Tweaks - WordPress Membership\",\"isPartOf\":{\"@id\":\"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/#website\"},\"datePublished\":\"2010-08-16T01:48:01+00:00\",\"dateModified\":\"2017-07-23T00:38:37+00:00\",\"author\":{\"@id\":\"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/#\/schema\/person\/d68b2ffa792aeb141f10f910dacccfdd\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/wp-emember-miscellaneous-tweaks-248#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/wp-emember-miscellaneous-tweaks-248\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/wp-emember-miscellaneous-tweaks-248#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"WP eMember Miscellaneous Tweaks\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/#website\",\"url\":\"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/\",\"name\":\"WordPress Membership\",\"description\":\"Easy to use WordPress Membership plugin\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/#\/schema\/person\/d68b2ffa792aeb141f10f910dacccfdd\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/3a21ab4072e533cf470d80fc2f0fd3639872824ade4e23709397e109b24f8857?s=96&d=identicon&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/3a21ab4072e533cf470d80fc2f0fd3639872824ade4e23709397e109b24f8857?s=96&d=identicon&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/3a21ab4072e533cf470d80fc2f0fd3639872824ade4e23709397e109b24f8857?s=96&d=identicon&r=g\",\"caption\":\"admin\"},\"url\":\"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"WP eMember Miscellaneous Tweaks - WordPress Membership","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/wp-emember-miscellaneous-tweaks-248","twitter_misc":{"Written by":"admin","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/wp-emember-miscellaneous-tweaks-248#article","isPartOf":{"@id":"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/wp-emember-miscellaneous-tweaks-248"},"author":{"name":"admin","@id":"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/#\/schema\/person\/d68b2ffa792aeb141f10f910dacccfdd"},"headline":"WP eMember Miscellaneous Tweaks","datePublished":"2010-08-16T01:48:01+00:00","dateModified":"2017-07-23T00:38:37+00:00","mainEntityOfPage":{"@id":"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/wp-emember-miscellaneous-tweaks-248"},"wordCount":517,"commentCount":4,"keywords":["member","Membership Level","membership tweaks","shortcodes","WordPress membership"],"articleSection":["Additional Resources"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/wp-emember-miscellaneous-tweaks-248#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/wp-emember-miscellaneous-tweaks-248","url":"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/wp-emember-miscellaneous-tweaks-248","name":"WP eMember Miscellaneous Tweaks - WordPress Membership","isPartOf":{"@id":"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/#website"},"datePublished":"2010-08-16T01:48:01+00:00","dateModified":"2017-07-23T00:38:37+00:00","author":{"@id":"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/#\/schema\/person\/d68b2ffa792aeb141f10f910dacccfdd"},"breadcrumb":{"@id":"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/wp-emember-miscellaneous-tweaks-248#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/wp-emember-miscellaneous-tweaks-248"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/wp-emember-miscellaneous-tweaks-248#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/"},{"@type":"ListItem","position":2,"name":"WP eMember Miscellaneous Tweaks"}]},{"@type":"WebSite","@id":"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/#website","url":"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/","name":"WordPress Membership","description":"Easy to use WordPress Membership plugin","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/#\/schema\/person\/d68b2ffa792aeb141f10f910dacccfdd","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/3a21ab4072e533cf470d80fc2f0fd3639872824ade4e23709397e109b24f8857?s=96&d=identicon&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/3a21ab4072e533cf470d80fc2f0fd3639872824ade4e23709397e109b24f8857?s=96&d=identicon&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3a21ab4072e533cf470d80fc2f0fd3639872824ade4e23709397e109b24f8857?s=96&d=identicon&r=g","caption":"admin"},"url":"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/wp-json\/wp\/v2\/posts\/248","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/wp-json\/wp\/v2\/comments?post=248"}],"version-history":[{"count":0,"href":"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/wp-json\/wp\/v2\/posts\/248\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/wp-json\/wp\/v2\/media?parent=248"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/wp-json\/wp\/v2\/categories?post=248"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tipsandtricks-hq.com\/wordpress-membership\/wp-json\/wp\/v2\/tags?post=248"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}