MyBB Community Forums

Full Version: I really realllllly hate to ask but,
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Is there a list of hooks (i know of the wiki one) that tells me which hooks does what? i've gone through like 20 hooks and none do it right Sad
There isn't really a list of what they do, hooks are places where you can insert your own code into MyBB - and that's really what they are.

What are you having trouble with? Smile
(2009-04-28, 09:28 PM)Tomm M Wrote: [ -> ]There isn't really a list of what they do, hooks are places where you can insert your own code into MyBB - and that's really what they are.

What are you having trouble with? Smile

Finding which hook takes me where.

like i am trying to find which hook leads to the user cp, the email me hook... etc its hard to find on that wiki. lol i spend like 2 hours trying to find which is what....
The hook list in the wiki is nice, but may not be always up to date and it doesn't exactly tell which hook is called on which page and when. So instead, when I need a hook, I just add some debug message to the class_plugins.php::run_hook*() functions, like so (don't have the actual code here atm, you should get the idea though).

function run_hooks($var)
{
    echo "run_hooks($var)<br>";
...
function run_hooks_by_ref($var)
{
    echo "run_hooks_by_ref($var)<br>";
...

Then you go to the page you want to hook into and you get a nice list echoed out of the hooks that were called when that page was loaded and you can even tell in which order they were called, and then you just pick the most specific hook that works for your plugin.

Depending on what you want to do, there may not always be a hook for it. In that case I modify the core code, but I try to keep the number of these modifications as low as possible, and ensure that everything works even if my plugin is not enabled. For example my Google SEO plugin modifies inc/functions.php because there was just no other (sane) way to go about it.

If you can't tell how something works exactly by just looking at the code, adding debug messages is the way to go... Smile
This may be of use to you http://www.mybbcentral.com/docs/
Usually I look in the code where I want to insert something, then find the nearest plugin hook. But I understand that could be a bit difficult for people who aren't familiar with the code. Hmm.
MyBB code is commented in a places, and the easiest way to find things is to look up the "action" input. Searching for things like this:

action'] == "emailuser"

... in a file will take you straight to where that code is executed. When emailing a user, the url is member.php?action=emailuser. The hooks are then easy to see... Smile
So would the post bit have the email address and everything? that seems the easist Big Grin
Nice info froustuze
(2009-04-29, 12:19 PM)T0m Wrote: [ -> ]So would the post bit have the email address and everything? that seems the easist Big Grin

MyBB tries to protect the user's email, so it isn't on the postbit.

Smile
Pages: 1 2