ButlerBlog

chad butler's weblog

  • About
  • Blog
  • WordPress Plugins
  • Contact
Home / Web / WordPress / Verse-O-Matic / Customizing WP-Members with pluggable functions

Customizing WP-Members with pluggable functions

By Chad Butler 15 Comments

There are many requests that come into this blog asking how to customize certain elements of the WP-Members plug-in. While I’ve made attempts to have WP-Members be as flexible as possible, there are times when a specific customization request would be outside the existing process flow of the plug-in and would require making changes directly to the functions in the plug-in itself.  

Making direct changes to the functions within the plug-in is discouraged because it puts the user in a difficult situation. These types of changes are generally referred to as “hacks” and hacks must be reapplied anytime you upgrade the plug-in. Avoiding upgrades because of the need to update your hacks is a bad practice because upgrades often include important security updates.

So to make things a little more extensible, I have introduced pluggable functions to the WP-Members plug-in. Pluggable functions are functions that can be recreated outside of the plug-in itself without the need to make changes to the core script files directly. This actually was introduced out of my own needs as I have clients using the plug-in in a customized way and everytime I do an upgrade, I need to make sure their customizations stay compatible. This method has been working well in that regard, and so it is being introduced to the public users of the plug-in as well.

Caveats, Caution, Etc.

The process is not without its own caveats. For starters, you will need some basic understanding of PHP. Don’t let that scare you too much, because in general, you should be able to back out of your changes fairly easily. But I must warn you that you should know what you are doing if you deal with any code that makes any changes to your data (i.e. writing to the database).

You will also need to be aware that changes in an update may affect your plugged functions. You may still need to make updates and changes once your customizations are put into place. It is just that you won’t be doing this within the plugin itself. But you will still need to keep careful track of any updates that have been put into place with a new version release.

WordPress Standards

The WP-Members project attempts to follow WordPress best practices when it comes to development. This includes how the functions are named, commented, and documented.

Function Names

All (or almost all) of the functions within WP-Members carry a prefix of wpmem_ followed by the name of the function (admin functions are wpmem_a_name-of-function). This is to avoid the possibility of name collisions with WordPress functions or functions from another plugin.

Comments

I have tried to keep up with comments in the code, but it doesn’t always work out that way. But, in general, if something is new or has been changed from a previous version, then it is noted in the comments. This will be important to you in keeping your plugged functions up-to-date by knowing what changes have been made.

Documentation

WP-Members attempts to follow the PHP DocBlock standards. This is the location before the function that gives you information about the function, what it does, and what it needs.

Putting it all together

A pluggable function in WP-Members will be wrapped with the line:

if( ! function_exists( 'wpmem_name-of-function' ) ) :

It will end with this:

endif;

Your plugged function will, at the very least, carry the same name as the plug-in’s function thus overriding it.

Getting Started

To begin using pluggble functions in WP-Members, you will need to create a php file to store your functions in. Create a file named wp-members-pluggable.php and save it to your WordPress plugins directory. This file acts as a drop-in for the plug-in. When WP-Members is loaded by WordPress, it checks for the existence of wp-members-pluggable.php and if it is available, it will load it first.

IMPORTANT: the file MUST be named wp-members-pluggable.php and MUST be saved to your WordPress plugins directory, NOT the /plugins/wp-members/ directory. That way, it will not be overwritten when you upgrade the WP-Members plugin.

The easiest way to handle this is to copy the existing function to your wp-members-pluggable.php file.  Then make the changes to the function you need.  Based on most of the user requests I receive, this generally will amount to adding another function into the process.  For example, within the existing function, you want another process to occur.

I suggest that additional processes that you add be added as function calls (with the additional function process also stored in the pluggable file) to keep the original function as clean as possible.  This will make it easier to compare to any new version that come out so you know if you need to update the plugged function.

Enjoyed this article?

Don't miss a single post. Subscribe to our RSS feed!

  • Facebook
  • Twitter
  • Email
  • Print
  • More
  • LinkedIn
  • Reddit
  • Tumblr
  • Pocket
  • Pinterest

Filed Under: Verse-O-Matic Tagged With: tips, tutorials, WP-Members

About Chad Butler

Chad Butler is a freelance writer and web developer. He has developed several popular WordPress plugins and has written for forbes.com, sfomag.com, and investopedia.com. He also runs a small organic farm in east Georgia.

Join Us!

I will never share your information. No spam. No junk. No kidding. Unsubscribe anytime.

Recent Posts:

  • YouTube Success: Key Tips for Enhancing Video Optimization and Visibility
  • Mobile App vs. Mobile Website Ideal Choice for your Business
  • Top Strategies to Boost Your Brand’s Visibility and Impact
  • Advanced Blogging Strategies: Using Analytics, A/B Testing, and Conversion Optimization Techniques to Grow Your Audience
  • Unlock Real-Time Process Insights to Save Time and Money
  • How Writers Can Attract More Audience Attention
  • Dress for Success – Even at Home
  • Mastering the Art of Crafting SMART Marketing Goals
  • Rediscover Your Brand Story: 7 Tips for Refreshing Your Company Identity
  • Creating Engaging Content: Tips for a Successful Content Marketing Strategy

Archives

  • About
  • Blog
  • Archive
  • Contact

Site powered by WordPress, running on the Genesis Framework from StudioPress.

Unless otherwise noted, content on this site is © 2006-2025 ButlerBlog and may not be reproduced without express written permission from the author.

Some content may include affiliate links for which this site receives a small commission.