Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to add custom variable to bp_activity_add ?


  • King Ding
    Participant

    @dazzerr

    I’m creating a plugin that records wordpress comments as a bp_activity post. I’ve been successful at recording the activity, but there’s just one thing that I want to add… a new possible value! Here’s the plugin in a nutshell:

    function kd_record_activity($comment_id, $approval) {
        if($approval == 1) {
            $comment = get_comment($comment_id);
            $userlink = bp_core_get_userlink($comment->user_id);
            $postlink = '<a href="' . get_permalink($comment->comment_post_ID) . '">' 
                            . get_the_title($comment->comment_post_ID) . '</a>';
     
            bp_activity_add(array(
                'action'            => sprintf( __( '%1$s commented on: %2$s', 'buddypress' ), 
                                                    $userlink, $postlink),
                'content'           => $comment->comment_content,
                'component'         => 'groups',
                'user_id'           => $comment->user_id,
                'type'              => 'new_blog_comment',
    	    'new_row'           => '123'  //THIS is the new row I want to record
            ));
         
        }
    }
    //triggered just after a comment is saved in the database.
    add_action('comment_post', 'kd_record_activity', 10, 2);
    
    // We want activity entries of blog comments to be shown as mini-entries
    function kd_minify_activity($array) {
        $array[] = 'new_blog_comment';
        return $array;
    }
    add_filter('bp_activity_mini_activity_types', 'kd_minify_activity');

    I understand that by default, the bp_activity_add hook only allows for certain variables. I expected that I could just add another variable to the array in bp-activity-functions.php and everything would work as expected, but apparently not! Please find //MY NEW ROW! in the following code: https://pastebin.com/3nVE4fya

    What else am I missing? P.S – the row exists in the database, it’s just that it does not record any data that I set.

    Thank you!

  • You must be logged in to reply to this topic.
Skip to toolbar