Skip to:
Content
Pages
Categories
Search
Top
Bottom

add_action not running when do_action is called


  • westpointer
    Participant

    @westpointer

    In bp-groups (@ line 1560) is the line

    do_action( ‘groups_new_forum_topic_post’, $group_obj->id, $forum_post );

    I’ve created a function –

    function my_notification_new_post($groupid, $mypostarray)

    in a file that I placed in the mu-plugins folder. That file is basically:

    function my_notification_new_post($groupid, $mypostarray) {

    stuff happens here;

    }

    add_action( ‘groups_new_form_topic_post’, ‘my_notification_new_post’ );

    But, when a new post is created, my function isn’t getting called.

    However, if instead of having the add action, I hacked bp-groups.php to look like:

    do_action( ‘groups_new_forum_topic_post’, $group_obj->id, $forum_post );

    my_notification_new_post($group_obj->id, $forum_post);

    My function is called and works great. What am I missing???

Viewing 8 replies - 1 through 8 (of 8 total)

  • nicolagreco
    Participant

    @nicolagreco

    add_action( ‘groups_new_form_topic_post’, ‘my_notification_new_post’ );

    must be

    add_action( ‘groups_new_form_topic_post’, ‘my_notification_new_post’, 1,2 );

    1 is the priority

    2 are the parametres

    ;)

    Nicola


    westpointer
    Participant

    @westpointer

    I tried that but still no luck. (BTW – aren’t the last two parameters optional? Or is it only optional if the number of variables passed is 1?)

    What else could I be missing?? the add_action just doesn’t seem to be getting included in the list of actions to run when the do_action is executed.

    I also tried adding:

    global $group_obj->id, $forum_post;

    as the first line of the function. (grabbing at straws). nothing. But if a directly call my function by adding a line below the do_action line, it works great. :-(


    nicolagreco
    Participant

    @nicolagreco

    the 4th parameter in this case i needed, because you’ve to declare how many parameters can be used

    don’t use global $group_obj!

    function my_function() {

    global $group_obj;

    }

    if the plugin is not in mu-plugins it will not work…

    paste here your code to receive help..


    jeff-sayre
    Participant

    @jeff-sayre

    westpointer-

    Just is case…

    In your first post you listed your add_action code as:

    add_action( 'groups_new_form_topic_post', 'my_notification_new_post' );

    If that is the actual code you’re using, then you have a typo. You need to change the word “form” to “forum” to match the do_action line. Of course, you need to include the proper parameters as nicola pointed out.

    I hope it’s as simple as that little typo!


    westpointer
    Participant

    @westpointer

    OK, here’s some quick and dirty TESTING code. In a file that is located in mu-plugins, I have:

    function my_hello_world($groupid, $mypostarray) {

    print_r($groupid);

    echo ‘Hello World‘;

    print_r($mypostarray);

    die;

    }

    add_action( ‘groups_new_form_topic_post’, ‘my_hello_world’, 1, 2 );

    When it runs, I should see the variables listed along with “Hello World”. (The page dies before going back to the forum post listing). But the code inside the function is not executed.

    If instead, I modify bp-groups.php to be:

    do_action( ‘groups_new_forum_topic_post’, $group_obj->id, $forum_post );

    /* Brent mod */

    my_hello_world($group_obj->id, $forum_post);

    the function runs. I see “Hello World” and the arrays printed.


    westpointer
    Participant

    @westpointer

    If that is the actual code you’re using, then you have a typo.

    OMG! How in the HE$$ did I miss that! grrr .. sorry for wasting everyone’s time! Thanks!


    nicolagreco
    Participant

    @nicolagreco

    if the hook is do_action( ‘groups_new_forum_topic_post…

    why are you using

    add_action( ‘groups_new_form_topic_post’..

    the error is in add_action the hook to use is ‘groups_new_forum_topic_post’ not ‘groups_new_form_topic_post’


    westpointer
    Participant

    @westpointer

    @ Nicola – thanks again for your time. I knew I was making a bone-head mistake!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘add_action not running when do_action is called’ is closed to new replies.
Skip to toolbar