I’m creating a plugin which displays a tabbed view. The way it currently works is when the user clicks a tab class Loader
reads the $_GET
parameter and creates an instance of the class specific to that tabs content. Now that I have this working, I want to be able to extend the functionality of this plugin to others. ie, I want another plugin to be able to create a new tab type. Each of my tab classes are derived from an abstract base though I can work around this using if_method_exists()
.
How can I make an instance or the name of a class available from a second plugin to my plugin?
What I want to achieve is for my Loader
class to have available a list of class names from which it can first populate the tabs then create the instance when that tab is selected.
Build some kind of a registry where other plugins can register new tabs. Letâs say your pluginâs admin page handler is called
Main_Controller
:Tab_List
is the list with all registered tabs:The method
register
expects a well defined instance of a classTab
:Now other plugins can register their tabs with a simple hook:
The classes
My_Color_Data
andMy_Color_View
are custom. I leave that up to your imagination. 🙂See also: