Extensible plugins are a topic that I enjoy to speak about and I love it when I come across a plugin that is extensible. The options framework, a plugin which I have recently defaulted to for providing a ‘Site Options’ page in WordPress projects has many extensible features allowing me to customise the plugin so it is tailored to my clients. Here is how I have recently utilised some of its extensibility features.
In case you are not familiar with the term extensible plugins let me briefly outline what is meant by this. WordPress core utilises these features too, in fact it is what allows the plugin architecture to exist.
An extensible plugin is one that can be modified and extended upon without altering the core plugin code itself.
This has many benefits, but perhaps the best is that when you update the plugin your modifications are not lost.
Below are the modifications using extensibility features that I have made use of with the Options Framework plugin.
The Options Menu Item
By default the Options Framework plugin provides you with an admin sub menu labelled ‘Theme Options’ underneath the parent menu item of Appearance. If you are building a WordPress theme to be sold or to go into the WordPress theme repository this name makes sense. However when you are building a site for clients, theme options makes little sense to them. Lets face it, most of my clients don’t know what a WordPress theme is, and why should they? Therefore I wanted to be able to change this name and its location within the admin menu.
The Options Framework plugin provides all the extensibility features needed in order to do this. The plugin uses a filter named
optionsframework_menu. This filter can be used to alter all of the menu parameters such as the menu name, position, page title and more. You will find that the plugin adds its menu using the code here – https://github.com/devinsays/options-framework-theme/blob/34c286996d387a29cb7871cfc2c8fdc09f03e5ca/inc/includes/class-options-framework-admin.php#L83-L104
Before sending the menu information to WordPress, it is passed through a filter named
optionsframework_menu which allows us developers to alter the menu settings to change the way in which the menu is outputted. I used the code below in order to change the menu label, its position (make it appear below Settings) and make it is a top level parent menu item rather than being a child of Appearance.
Customise the Options Name
By default the plugin uses your themes stylesheet as the prefix for all of the options stored in the options table. However you can change this should you wish to do so using another handy extensibility feature. This is where you can overwrite one of the functions in the plugin with your own. The code below would change the name of the options to
All of your saved options would now be stored in the options table as an array in an option with the name
To go hand in hand with this you can then create your own function to get those options to use in your theme. The following function does this:
Theme Independent Option Declarations
By default the plugin looks for a file in your theme named
options.php. This file then contains all of the options for your site. However I wanted to keep the options separate from my theme in case I changed themes and still wanted access to the options.
Again the plugins extensible features allow you to do this too. You can use the
of_options filter to do this, like so.
I hope this goes to show that extensible plugins are the best! Thanks to Devin Price for building a wonderful extensible WordPress plugin.