Adding extensions to PHP Open Source applications - callbacks
Archive - Originally posted on "The Horse's Mouth" - 2010-03-17 18:53:55 - Graham EllisOver the last two days, I've installed and configured MediaWiki, WordPress, Status.net and Drupal on one of our training systems, and looked (in each case) at how to configure them and install extra plugins / modules - both standardly available ones, and also how to start writing your own.
In two days we've only been able to scratch the surface of these huge topic, but the question arose "How do the standard packages see / register call the add ons". Details vary, but much of it is done through the use of callbacks. So - how do callbacks work?
The base code of each of these open source applications includes arrays which contain the names of all the functions that might be called - as strings. And other strings can be dynamically added to the list too.
When the code if run, these extra routines will be called at predetermined places in the source, thus running that extra code; a check with function_exists ensures that the application doesn't fall over by trying to run code that's not available. There's a demonstration [here] which shows you the mechanism.
I was very impressed by the extensive documentation in MediaWiki for its extension hooks - see [here] - perhaps this is the open source application that I'm most familiar with tailoring, although we also use the SMF forum in many guises ;-)