|
Table of Contents
HooksHooks are a more dynamic way of manipulate with pluck than the current system. The current system is based on files, and the names of them. pluck looks for a specific file and then does something with it. The new system is based on functions, and are much more flexible. Do you want to add an extra menu in the admin panel? You are now able to do that. This document will show the idea behind hooks, and how to use them.
This hooks system will be included in pluck 4.7. This version is in development at the moment.
Your first moduleStart by creating a new folder in data/modules. This will also be the prefix we will use for every function in the module. But more about that later. Now, create a PHP file in the module folder, with the same name as the module folder. If your folder is test, your file will be test.php. You should now have an empty file here: data/modules/test/test.php PREFIX_info()The first function we need is, funny enough, an info function. It looks like this: function PREFIX_info() { $module_info = array( 'name' => 'test module', 'intro' => 'Created to show the new hooks.', 'version' => '0.1', 'author' => 'Anders Jørgensen', 'website' => 'http://spirit55555.dk', 'icon' => 'images/test.png', 'compatibility' => '4.7' ); return $module_info; } You can change the info as you like. Two things you should note:
The module now shows up in options → manage modules, but it's not "hooking" anything yet. The first hookDevelopers can run hooks anywhere they want in pluck. In the core, in themes and even in modules. That will be explained later, because right now, we are focusing on how to add something to an existing hook. This tutorial will show how to add some CSS in the admin panel, so the font color becomes pink or any other color you like. There is a hook called admin_header_main between <head> and </head>. Sounds like the perfect place to inject some CSS. Add the following code to your PHP file: function PREFIX_admin_header_main() { echo '<style type="text/css">body {color: pink;}</style>'; } And that's it! You don't have to do anything more. This is how every hook works. Just create a function starting with PREFIX_, and then the hook name (in this case it was admin_header_main). Include your module in a page |