In a previous blog post I announced that I had created a plugin to extend another plugin called Map List Pro. This was a while ago so you might be wondering why I’m now just considering myself a plugin developer. In fact, in addition to that plugin, I’ve developed a number of plugins specifically for client projects. What makes me a “real” plugin developer is I now have one on the official WordPress Plugin Repository. I had wanted to get one on there for while but didn’t know if it was difficult or what plugin might be useful enough to offer out into the world.
Why Submit This Plugin?
I was recently approached by a client to build out a community using BuddyPress. I’ve known about it for a while but was not familiar with the ins and outs of setting up Buddypress. In reviewing the project requirements profile privacy was a big concern. They wanted the members to have control over who can see their profile. I started looking for solutions and noticed that while code is available to lock out users that weren’t logged in and plugins that set the privacy by post there was no solution for the entire profile.
Unlike Map List Pro, Buddypress is a widely used platform. Also, from some posts over at BuddyPress support I saw interest in having profile privacy so this seemed like the perfect fit for the repository. With that I started in on the development of my first BuddyPress plugin Simple BuddyPress Profile Privacy.
Making BuddyPress My Buddy
As I mentioned I was, and still am, a newb when it comes to BuddyPress. I had set up an install on my nightly WordPress installation to review it for the project I was estimating. First thing I did was review the hooks available to setup the new profile settings for the user. After a little while I had myself the settings page and I was saving the user’s preferences to the their profiles metadata.
Next I added the check for whether the user was logged in and the redirect to the login/registration page if they aren’t. This was also very simple and after a couple of hours it was doing 75% of what I wanted. All that remained was hiding the profile from members that were logged in but weren’t friends with the profile being viewed.
Not Friendly
My relationship with Buddypress had a magical start. Like WordPress, BuddyPress offers built in functions to check what is currently being viewed or get info about a profile. These functions made figuring out if the profile that is logged in is friends with the profile being viewed simple. What I had a difficult time with was adding a new item to the profile to display the message telling the user that the profile was visible to friends only.
First I tried overriding the profile template file from my plugin. I’m still pretty sure you can do this but I wasn’t able to make it work. While I was able to load the new template it didn’t load core parts of the template. The page just never looked right.
There were more than a few frustrated hours so I stayed away from the project for a couple of days, occasionally did some research. This led me a to a presentation by Boone B Georges from 2014. Titled “BuddyPressifying a WordPress Plugin using BP_Component” it was exactly what I needed. It contained links to GitHub repos with skeleton code and examples on how to create a component for the profile page. Extending the BP_Component class was the key to getting to displaying my message. A few hooks were used to display the new component only when the content is blocked.
Plugin Complete
Well… not really. I see a ton of improvements that need to be made as well as some new features I want to add. To that end if you are a BuddyPress user or are just interested in the plugin please download Simple BuddyPress Profile Privacy and let me know what you think.
I got this up on the repository quickly so that the community can review it and so that I could learn the process of publishing a plugin. I’ll tell you more about how it went in my next blog post.