Skip to:
Content
Pages
Categories
Search
Top
Bottom

new custom post to profile and group activity stream.


  • sk_tamilan
    Participant

    @sk_tamilan

    WordPress Version 4.1
    BuddyPress Version Version 2.1.1

    I am new to buddypress and i am using the latest version. I have a custom post type called rewards and it has a custom taxonomy with it. I have created groups which matching names respective to the rewards taxonomy. Every time a new reward is create it will have one or more “groups” associated with them.

    Now the following code works on the member’s main activity feed.

    
    /* Tell Buddypress to add Rewards to activity stream */
    function activity_publish_custom_post_types($post_types)
    {
        $post_types[] = 'rewards';
        return $post_types;
        
    }
    add_filter('bp_blogs_record_post_post_types', 'activity_publish_custom_post_types',1);
    
    /* Filter for action for post type reward*/
    function rewards_activity_action($activity_action, $post, $post_permalink)
    {
        global $bp;
        if ($post->post_type == 'rewards') {
            
            $activity_action = sprintf(__('%1$s posted a new reward : %2$s', 'buddypress'), bp_core_get_userlink((int) $post->post_author), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>');
           return $activity_action; 
        }
       
    }
    
    add_filter('bp_blogs_activity_new_post_action', 'rewards_activity_action', 1, 3);
    add_filter('bp_activity_before_save', 'rewards_activity_content', 3);
    
    /* Filter for content for post type reward before saved to database */
    function rewards_activity_content($activity){
    
        global $post;
    
        if ($post->post_type == 'rewards') {
    
            $activity_id = (int) $activity->id;
            $post_id = (int) $activity->secondary_item_id;
            $user_id = (int) $activity->user_id;
          
            $post_type = get_post_type( $post_id );
            $thumbnail = get_the_post_thumbnail($post_id);
    
            
            $activity_content  = "<div class='post-id'>The post ID : {$post_id}</div>\n";
            $activity_content = "<div class='thumbnail'>{$thumbnail}</div>\n";
            $activity->content = $activity_content;
    
        }
    }

    My questions :-

    1. within the rewards_activity_content function I cannot add the custom activity action name as such shown below

    $activity->action = sprintf(__('%1$s posted a new reward : %2$s', 'buddypress'), bp_core_get_userlink((int) $post->post_author), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>');

    hence why i have created the rewards_activity_action function.

    2. Based on the custom taxonomies that have been selected every time a new reward is created this needs to match the groups activity stream and a record needs to go in there for that particular group with the same
    action and content name

    Please tell me how I can acheive this

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

  • shanebp
    Moderator

    @shanebp

    add_filter should always return something.

    Try this:

     // snipped
            $activity->content = $activity_content;
        }
        return $activity; 
    }

    Or this:

     // snipped
            $activity_action = sprintf(__('%1$s posted a new reward : %2$s', 'buddypress'), bp_core_get_userlink((int) $post->post_author), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>');
           
        }
       return $activity_action; 
    }

    sk_tamilan
    Participant

    @sk_tamilan

    hi @shanebp I just tried that and its not working

    function rewards_activity_content($activity){
    
        global $post;
    
        if ($post->post_type == 'rewards') {
    
            $activity_id = (int) $activity->id;
            $post_id = (int) $activity->secondary_item_id;
            $user_id = (int) $activity->user_id;
          
            $post_type = get_post_type( $post_id );
            $thumbnail = get_the_post_thumbnail($post_id);
            $post_permalink = get_permalink($post_id);
    
            
            $activity_content  = "<div class='post-id'>The post ID : {$post_id}</div>\n";
            $activity_content = "<div class='thumbnail'>{$thumbnail}</div>\n";
            $activity->content = $activity_content;
            $activity->action = sprintf(__('%1$s posted a new reward: %2$s', 'buddypress'), bp_core_get_userlink((int) $post->post_author), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>');
    
        }
        return $activity;
    
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘new custom post to profile and group activity stream.’ is closed to new replies.
Skip to toolbar