The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

[resolved] Can someone explain "Hooks" and "do_action" to me? (6 posts)

  1. Johnny T
    Posted 6 years ago #

    Hi all,

    I spent a happy hour last night trying to de-bug my registration page. It ends up that the fault was due to my SimplePress installation (a brilliant plugin by the way - I'm not trying to denegrate it here at all). SimplePress required a Math question to be answered but my registration page wasn't providing the answer. It was therefore silently killing all my registration attempts.

    Anyhoo... during my fault finding I came across this line of code:
    do_action('register_post', $user_login, $user_email, $errors);

    I naturally thought that "do_action" was passing the arguments $user_login, $user_email etc into a function called "register_post". But there isn't a register_post function?

    My bleary-eyed searches on the net seemed to suggest that "do_action" was something to do with "Hooks".

    I've seen the term Hooks referred to a LOT during my work with WordPress but I don't understand exactly what they are.


    1) Could someone explain in laymans terms what "Hooks" are please?
    2) Could someone explain how to go about fault-finding on "do_action" statements? i.e. Do they call a function or are they indirectly calling a function? How do you trace through them to find where the code goes next?

    If you have any ideas on these questions or could shed any light on this at all it will be very much appreciated, not only by me, but by my rapidly thinning scalp!


    John ;-)

  2. James Huff
    Support Team Rep.
    Posted 6 years ago #

  3. Johnny T
    Posted 6 years ago #

    Hi Macmanx,
    Thanks for the info. I've read most of it and I *kind of* understand hooks...

    So a hook is basically a gap in the code at certain junctures that allows plugins to interject something or alter something if they wish? Is that correct?

    The trouble I've got is that I can't find any other reference to register_post in my code anywhere (using a Search program that checks every php file).

    I would expect to find an add_action('register_post', 'some_function') somewhere if I'm understanding your information correctly??

    Or am I missing something here??


    John ;-)

  4. James Huff
    Support Team Rep.
    Posted 6 years ago #

    Hooks are basically little bits of code that say, "Execute plugin actions here."

    As for how to build plugins to make use of them, that's a bit outside my knowledge right now. This may help:


  5. Johnny T
    Posted 6 years ago #

    Thanks for all your help macmanx (in this thread and others!) it is really appreciated.



  6. James Huff
    Support Team Rep.
    Posted 6 years ago #

    You're welcome!

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.