The MU forums have moved to WordPress.org

details about how hooks work do_action (2 posts)

  1. horrorshow
    Member
    Posted 16 years ago #

    I don't yet have a good understanding of "do_action" and how hooks operate. I'd really appreciate it if someone could clarify this for me.

    Looking at the function wp_delete_comment($comment_id),
    there is a call: do_action('wp_set_comment_status',$comment_id, 'delete');

    So, from my plugin, if I add:
    add_action('wp_set_comment_status', 'my_set_comment_status', 5, 2);

    Does "my_set_comment_status" get called after "wp_set_comment_status()"?

    The confusing thing is looking at comment.php, the function wp_set_comment_status($comment_id, $comment_status) has a call to:
    "do_action('wp_set_comment_status', $comment_id, $comment_status);

    It seems like my function "my_set_comment_status" will get called again. (And "wp_set_comment_status" too in an infinite loop.)

    But this probably doesn't happen as it would be a silly thing to have done, and I am sure someone would have caught that.
    So I am missing something. Well, thanks for your help.

  2. hery
    Member
    Posted 16 years ago #

    You just care about "your" my_set_comment_status function, and don't care about any other do_action (before or after yours).

    There is no problem.

About this Topic