I don't market this service much. I develop and manage web sites using WordPress. I often run into situations that other developers don't seem to encounter.
I'm building a new site for Veterans. It user s2Member (use coupon code
SAVE10-A:3670 to get 10% off) to control memberships, and BuddyPress and BBPress for the community aspects of the site. It also uses a Formidable form to allow members to create WordPress posts from the front end.
The theme I'm using is called Vivacity from GhostPool on ThemeForest.net. It's a great theme – very advanced and very customizable. Vivacity uses an “Author Info” box that is displayed on every port. It shows the post author's bio info from the WordPress database.
This is all very straightforward. However, introduce s2Member into the mix, and things get messy. s2Member controls the use of Custom Fields that will be used with BuddyPress. It doesn't use the default Author Bio info. The Author Info box described above users that data from the WordPress bio. So, any “regular” WordPress authors will be able to fill out their bio info in the WordPress admin back end. I don't want members accessing the back end, and their bio info, stored by s2Member, won't be shown in the Author Info display.
I spent quite a bit of time searching for an answer. The options seemed simple enough:
- Hack the theme's author-info.php file and pull the Bio data from s2Member's custom fields table.
- Hack the profile form and insert that data into the WordPress user fields when the member registers.
I realized that option 2 would require code to not only update the WP field from the registration form, but also would need to update the field any time the user updated their info. This is getting messy.
Option 1 seemed much better – just show the data from s2Member. Any “regular” author on the site will be a BuddyPress member as well, and can easily populate that field on their own. How hard could that be? Well, I went down the rabbit hole on this one! s2Member didn't seem to have any functions for pulling custom field data, without jumping through some major hoops. On their own support forum there are a number of people looking for the same thing. The answers range from “that's customization and we don't do it” to “read the WordPress Codex and figure it out.
I played with it for quite a while. There's a pile of hair on my floor from pulling it out over the last 24 hours!
I finally came up with this:
$person = get_userdata( get_the_author_meta( 'ID' ) );
This is pretty elegant, right? Very simple, too! It was a matter of using the WordPress functions get_userdata and get_the_author_meta to pull the user ID of the current post author, then passing that ID to s2Member's custom field function. BTW – I never did find this function on s2Member's web site. I found it in a discussion on another WordPress theme's web site!
Next I might go ahead and check for a bio entry in the regular WordPress data field, and use it if it exists. Otherwise, use the code above. This should protect the code from needing modification if s2Member, or BuddyPress, or anything else decides to change the way they work.