Support » Plugins » do_action() in wp_die() doesn’t pass parameter

  • I am working on a plugin to ajaxify commens as wpmu-plugin. It’s almost done, with a weird little problem remaining.

    I added a new hook in wp_die() to catch error messages. I added it this way:

    1244: do_action('wp_abort', $message);

    (line 1244 is right after $message is processed)

    Good so far. So I hooked my function on:

    add_action('wp_abort', 'ajax_comments_send');

    The function, which doesn’t do much more than this:

    function ajax_comments_send () {
        $passed = func_get_arg();
        $comment = @get_comment($passed);
        if (!is_object($comment)) {
            header('HTTP/1.0 406 Not Acceptable');
        // code for sending the comment on success

    The problem is: Whatever I do, the $message isn’t passed to ajax_comments_send. I tried to add the die($passed); as first statement, but it doesn’t output anything.

    Furthermore I digged into the code and did a little debugging. My results:

    • do_action() is being executed as expected
    • in plugin.php, do_action(), the parameter is there and is being passed to call_user_func_array() correctly
    • ajax_comments_send works, the correct header is being sent
    • ajax_comments_send works, on success the comment is successfully being transmitted

    Further investigation showed that I also can’t call the function directly in do_action:

    if ($tag == 'wp_abort') {

    After a sleepless night I’m left with a big what the heck?

Viewing 1 replies (of 1 total)
  • @kno: hey buddy, thanks for all your hard work on this. you really tore the original plugin apart, didn’t you? that’s ok, that’s what open source is about. community. learning. getting involved. making a difference. I appreciate it, and I even learned something new!

    FYI: I recently updated AJAX Comments to work with the latest version of WordPress, as well as WordPress MU.

    I was also able to build some pretty robust error handling, which not only catches WordPress errors from wp_die(), but unexpected plugin errors, and even fatal PHP errors that would normally halt processing in eerie silence.

    License is now GPLv2, and documentation is also included this time for the WP Hacker in all of us. I invite you to check it out and see how it works:

    AJAX Comments WordPress Plugin

    I welcome your feedback on this. If you have any suggestions for improvement, I would also be open to that.

    Happy holidays! 🙂

Viewing 1 replies (of 1 total)
  • The topic ‘do_action() in wp_die() doesn’t pass parameter’ is closed to new replies.