Hi, I am writing a piece of software that I would later open for plugins. So for this reason I would like to implement a Hook System like the one that wordpress uses. How do I develop this? Can me anyone give me some advice? Thanks
do you need to write an CMS or whatever which allow users to implement a plug-ins ? you can write a plugins module which will load a standard users plugins which it will override the system functionalities
This is all going a little bit over my head lol. Does anyone have any links to any tutorials or more in detail explanations? Thanks.
if you want it like wordpress does, why don't you just browse into wordpress source and learn how they've done it.
I tried that but wordpress is huge and at times looks quite messy. I will just develop the framework first and will add hooks later.
Ideally it should be link events & event registration. 1. Write a function, which allows various modules to register to particular hooks. 2. Another function to check the registered modules for a hook and call function supplied during registration. Best example of this can be found in MyBB forum software.
Wordpress kinda does it like this: First it includes all plugins with active hooks, regardless if they get called or not; I included this plugin as an example // in ./wp-content/plugins/save-remote-images/save-remote-images.php add_action('save_post', 'save_remote_images'); // "save_post" is the name of the hook that gets called after a successfully saved or updated post; "save_remote_images" is your function that gets called when that event fires function save_remote_images($postId) { // ... } PHP: Then when you save or update a post, this function gets called function save_remote_images ($postId) // in ./wp-includes/post.php function wp_insert_post($args) { // code that parses post data // ... // after it parses and saves the post do_action('save_post', $post_ID, $post); // this is the point where your hook gets called, in this case function "save_remote_images" return $post_ID; } PHP:
All you would really need to do is check every so often that the plugins do not want anything. If they do, do the function they want to do then keep going. That's what Wordpress does I do believe.
There are lots of ways and it can be tricky. There are some good answers to a similar question on stackoverflow: http://stackoverflow.com/questions/217659/build-a-plugin-system-with-php