I’m curious how plugins work, I just know that instead of changing the code we use plugins, but how do they do their job without changing the code ? and what should a coder consider when coding a new project so it can have plugins ? and thank you very much 😀
Leave a Reply
You must be logged in to post a comment.
There are multiple variations on how to implement a plugin system. WordPress uses a quite common scheme often described as “hooks.” I don’t know the exact implementation but it basically works like this:
Where the
hook_type
is often an action name or something. And when the main application runs through a specific point (or e.g. needs some data processsed) it invokes all registered callback functions:This is often implemented behind the scenes as a simple loop:
Now it depends on the hook/action type what parameters are present, and if any result text is expected. There are also differences in parameter passing (e.g. some callbacks require &$var references). And some plugin systems rely on objects instead (if not as many varying action types exist or more complex structures are to be worked with).