• Skip to main content

Victor Font Consulting Group, LLC

Digital Business Strategists

Call Us:

+1 919-604-5828

  • Home
  • Care Plans
    • Care Articles
    • Optional Subscriptions
  • Consultations
  • Products
    • Code Snippets
    • Public GitHub Repositories
    • Gist Snippets
    • Pastebin Snippets (Free)
    • Free Plugins
  • FAQs
  • Support
    • Graphic Design
  • Our Team
    • Contact
    • Speakers
    • Portfolio
  • Resources
    • Free WordPress Video Training
    • Tutorials
    • Articles
    • Cybersecurity
    • EU Referral Network
You are here: Home / Code Snippet / Raising the WP eMember Public Directory Bar to the Next Level

Raising the WP eMember Public Directory Bar to the Next Level

By Victor M. Font Jr.
August 20, 20112 Comments

I am a diehard fan of the plugins developed by Tips and Tricks HQ. As an author, I especially like their PDF stamper plugin. I use it to protect the contents of my book, “Principles for Maturing Your System Development Life Cycle: The Ultimate Guide to the SDLC,” which can be purchased at http://www.ultimatesdlc.com. So when my colleagues in the North Carolina Executive Roundtable (NCER) asked me to build membership features into their website, I readily selected WP eMember.

Needless to say, the NCER membership was very happy with the WP eMember plugin, with one exception. They didn’t care for the native public directory and asked that the phone number field be added to the display. This is where I started to run into problems.

My first instinct is to contact the plugin author to modify the plugin. After all, how hard could it be to modify the display table to add an additional field? The author’s reply:

There is no option to show the phone field in the user directory table. The user directory table is embedded on a page so it can't have too many columns due to the page width restriction. After several testing we found that 3 to 4 columns yields the best result.

Coupled with another response in the same thread, it’s clear that he won’t edit his plugin to add the field. I was disappointed. I had made other suggestions to this author before which he implemented and have always found their support team to be very responsive. This time, however, he was adamant. He wasn’t going to modify the code. His

adsasd

decision left me with two choices. I could either modify his code myself or write a new, custom directory function that accesses his tables and displays the data therein. Since modifying delivered code is never a good option, I opted for writing my own directory function that mimics that found in the WP eMember plugin, except it looks nicer and displays a whole lot faster

Before we dive into the code, let me warn you that this is as simple as it comes. I do not build bells and whistles into this code. It simply extracts what it needs from the database and displays it. There is a second .php file that populates a popup when you click on a members name. The popup uses ThickBox. ThickBox is a webpage UI dialog widget written in JavaScript on top of the jQuery library. ThickBox is delivered natively in WordPress.

<?php
   // connect to the server
   $host="<your host name>";
   $user="<your user id>";
   $pass="<your password>";
   $mysql_link = mysql_connect($host,$user,$pass,true);

   // select database
   mysql_select_db("<your database>", $mysql_link);

   // get active user count to calculate pagination -- pagination code to be added later when we there are enough records to justify it
   $query = "SELECT COUNT(*) as count FROM `wp_wp_eMember_members_tbl` where account_state = 'active' ORDER BY member_id";
	 $mysql_results = mysql_query($query, $mysql_link);
	 $row = mysql_fetch_array($mysql_results);
   $emember_user_count = $row["count"];

   // get active member data
   $query = "SELECT last_name, first_name, email, phone, member_id FROM `wp_wp_eMember_members_tbl` where account_state = 'active' order by last_name;";
   $mysql_results = mysql_query($query, $mysql_link);

   //close data connection
   mysql_close($mysql_link);
?>

<table style='margin: 6px; padding: 6px; width: 640px;'>
<tbody>
        <tr>
           <td style='color: #FFFFFF; font-family: Arial, Helvetica, sans-serif; text-align: center; background-color: #680014'>
               <b>Name</b></td>
           <td style='color: #FFFFFF; font-family: Arial, Helvetica, sans-serif; text-align: center; background-color: #680014'>
               <b>Email</b></td>
           <td style='color: #FFFFFF; font-family: Arial, Helvetica, sans-serif; text-align: center; background-color: #680014'>
               <b>Phone</b></td>
        </tr>

<?php
   //get user data
   while($row = mysql_fetch_row($mysql_results))
   {
   	print("<tr>n");

   	// build link to personajax.php
   	print("<td>n");
   	$link_code = "<a href=";
   	$link_code .= "'http://www.your-url.org/displaycode.php?id=";
   	$link_code .= $row[4];
    $link_code .= "&height=300&width=400' class='thickbox' title='";
   	$link_code .= $row[1];
   	$link_code .= " ";
   	$link_code .= $row[0];
   	$link_code .= "'>";
   	$link_code .= $row[0];
   	$link_code .= ", ";
   	$link_code .= $row[1];
   	$link_code .= "</a>";

   	print($link_code);

   	print("</td>n");
   	print("<td>n");
   	print("<a href='mailto:");
   	print($row[2]);
   	print("'>");
   	print($row[2]);
   	print("</a></td>n");
   	print("<td>n");
   	print($row[3]);
   	print("</td>n");
   	print("</tr>n");
  }

   print("</tbody>n");
	 print("</table>n");

?>

The only thing you really have to do to this code is add the server and database access details. The code builds a hyperlink that calls personajax.php. The output of that file displays in a ThickBox.

<?php

	 $id = $_GET['id'];
	 if($id == ''){
	 		return;
	 	}
   // connect to the server
   $host="<your host name>";
   $user="<your user id>";
   $pass="<your password>";
   $mysql_link = mysql_connect($host,$user,$pass,true);

   // select database
   mysql_select_db("<your database>", $mysql_link);

   // get active member data
   $query = "SELECT a.member_id, a.first_name, a.last_name, b.alias as member_role, a.email, a.phone, a.address_street, a.address_city, a.address_state, a.address_zipcode ";
   $query .= "FROM `wp_wp_eMember_members_tbl` a LEFT JOIN `wp_wp_eMember_membership_tbl` b ON a.membership_level = b.id where a.account_state='active' and a.member_id=";
   $query .= $id;
   $query .= ";";
   $mysql_results = mysql_query($query, $mysql_link);

   $affectedrows = mysql_affected_rows($mysql_link);

   if ($affectedrows == -1)
   {
   	return;
   	}

   while($row = mysql_fetch_row($mysql_results))
   {

?>

<table style="width: 100%;" class="mceItemTable" align="center" data-mce-style="width: 100%;">
<tbody>
<tr>
<td vAlign="middle" align="center"><img alt="<?php print($row[1]); print(" align="middle" src="http://www.ncer1.org/wp-content/uploads/emember/<?php print($row[0]); ?>.jpeg" width="150" height="150" data-mce-src="http://www.ncer1.org/wp-content/uploads/emember/<?php print($row[0]); ?>.jpeg">
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"></td>
<td align="center"><strong>Membership Role:  <?php print($row[3]); ?></strong></td>
  • 0share
  • Facebook0
  • Twitter0
  • Pinterest0
  • LinkedIn0
  • Print
  • SMS0

About Victor M. Font Jr.

Victor M. Font Jr. is an award winning author, entrepreneur, and Senior IT Executive. A Founding Board Member of the North Carolina Executive Roundtable, he has served on the Board of Advisors, of the North Carolina Technology Association, the International Institute of Business Analysis, Association of Information Technology Professionals, Toastmasters International, and the North Carolina Commission for Mental Health, Developmental Disabilities, and Substance Abuse Services. He is author of several books including The Ultimate Guide to the SDLC and Winning With WordPress Basics, and Cybersecurity.

Reader Interactions

VictorFont.com runs on the Genesis Framework

Genesis FrameworkThe Genesis Framework empowers you to quickly and easily build incredible websites with WordPress. Genesis provides the secure and search-engine-optimized foundation that takes WordPress to places you never thought it could go.

Check out the incredible features and the selection of designs. It's that simple—start using Genesis now!

Click here to download The Genesis Guide for Absolute Beginners (PDF - 1.4 MB)

Leave a Reply to Victor Font Cancel reply

Your email address and website will not be published. Required fields are marked *
Posting a comment means that you agree with and accept our Comment & Product Review Policy

Comments

  1. pachouli

    March 4, 2012 at 3:50 pm

    Hi, I’m trying to do something similar, but for some reason I can’t see the code above. I “click to toggle” and nothing happens. Would love to try the code. Thanks
    (I do like tipsandtricks plugin but I have found their support less than helpful, event to the point of being unecessarily rude.)

    Reply
    • Victor Font

      March 4, 2012 at 6:22 pm

      The toggle feature was working fine for me, nevertheless, I’ve removed the toggle feature for you. If you have any further problems, let me know and I’ll send you the code directly.

      Reply

Call: +1 919-604-5828

Send us an E-mail

Accessibility Statement | Affiliate Marketing Disclosure | Capability Statement

Cookie Policy | Comment & Product Review Policy | Privacy Policy | Site Map | Terms & Conditions

Copyright © 2003–2021 Victor M. Font Jr.

Return to top of page
Cover image: 5 Things You Can Fix On Your Website In The Next Week To Increase Engagement

Attract New Customers Automatically for Free!

  • Learn how to use the Internet to attract REAL clients
  • Avoid the 3 big mistakes EVERYBODY makes
  • Put this system on AUTOPILOT with the tools the Pros use!

GET YOUR COPY!

This little ebook has helped hundreds of business professionals get real results.
Now it's your turn!

ebook lead capture
Privacy Policy
{"cookieName":"wBounce","isAggressive":false,"isSitewide":true,"hesitation":"","openAnimation":false,"exitAnimation":false,"timer":"","sensitivity":"","cookieExpire":"7","cookieDomain":"","autoFire":"","isAnalyticsEnabled":false}