Improvements to Hooks


  • Dadman with a boy
  • Posts: 16,061
Improvements to Hooks
« on May 7th, 2011, 12:55 PM »Last edited on May 11th, 2011, 08:22 AM by Nao/Gilles
Feature: Improvements to Hooks
Developer: Nao (main), Arantor
Target: modders, admins
Status: 60% (source hooks completed; template hooks in progress; considering whether to add file param; once everything's done, need to look through the code and add hooks where useful.)

It took SMF a long time to add "real" support for hooks -- a way to allow plug-ins to safely add code to the main codebase without actually editing the original files. Still, it's far from being a usable standard.

We simplified the calls to begin with. "add_hook('hook_point', 'my_function', 'my_source_file')" will execute 'function' once Wedge reaches the specified hook point (you may specify a source file to load before calling it.)

We provided context data to a few more hooks, and deleted a few useless hooks and outdated mechanisms (such as pre_include, catch_settings or the SMF_INTEGRATION_SETTINGS array).

Mostly, though, we added hooks to various places that SMF doesn't handle, like auto-suggest, behavior check, friend additions, post creation/modification (before and after), browser detection, query string analysis, dynamic rewrite (pre-pretty URL output buffer time), admin settings, credits...

The code internals are also better laid out. Hooks are unregistered if they're no longer available (e.g. uninstalled add-on.) Everything is put into a $modSettings['hooks'] array, instead of scattered through multiple annoying $modSettings['integrate_*'] variables.
We also try and make sure existing hooks can actually do something instead of just stare at the sky. They can now for instance intercept and modify outstanding personal messages, new topics and error messages.

This feature is under development and hasn't yet a state where it can be considered to be feature-frozen. The goal is to enable modders to add their code anywhere, without having to use SMF's code edit hacks... Thus making it possible to upgrade Wedge versions without uninstalling and reinstalling plugins in the process.