dpacmittal Posted March 14, 2010 Share Posted March 14, 2010 I want to create a plugin system similar to one implemented in wordpress. Google hasn't been of any help. I tried reading wordpress source but it would take much time to understand the underlying concept. I've checked its database and it doesn't store any plugin information in the database which means that it parses all the plugins everytime the page is loaded which, in my opinion, is not (?) a good way to do it. The system they've used is the hook system. There are hooks in most of the places. You add some action to the hook and when the hook is called, the action to attached is also executed. For eg; if you attach an action of cleaning a certain folder on the hook of add-post (say), everytime you add a post, the folder will be cleared. Okay, so I've not been able to understand how wordpress does it. However, I myself have a basic idea for this. I just want opinions if it is a good way to do it. I've thought of something like this: Plugins would have to call a function to attach an action to hook eg; attach_action ($hookname, $callback) When the plugin is installed, attach_action would add this information to the database. When the hook is called, it fetches all the actions attached to it from the database and executes them. When the plugin is uninstalled, the record from database is removed. So this is it. I want to know if this is better/worse way than how wordpress does? Thanks Quote Link to comment Share on other sites More sharing options...
hackalive Posted March 26, 2010 Share Posted March 26, 2010 I would be interested in this too Quote Link to comment Share on other sites More sharing options...
ignace Posted March 26, 2010 Share Posted March 26, 2010 function thirdparty_linkification($content) { //.. } plugin_register('news_content', 'thirdparty_linkification'); Assum a third-party developer wrote this. His plugin will linkify e-mails and http links in news articles more specifically in the content (body) of the article. I as a developer then write: function cms_get_latest_news($number = 10) { //.. while ($article = mysql_fetch_assoc($result)) { $article['content'] = plugin_apply('news_content', $article['content']); } return $articles; } This will give each and every registered plugin a chance of doing what it wants to do (linkify, footer, ..) I could expand this by adding for example news_time which will give every plugin a chance of telling how it should be formatted and so on. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.