Skip to:
Content
Pages
Categories
Search
Top
Bottom

bp_before_activity_add_parse_args vs. bp_activity_content_before_save


  • nm
    Participant

    @nahummadrid

    bp_before_activity_add_parse_args vs. bp_activity_content_before_save

    Which one is better for filtering content of blog posts activity entries? Considering that posts can be updated?
    bp_parse_args only records first time and doesn’t update an activity entry content for blog components entries while bp_activity_content_before_save does both it seems.

    Is it necessary to use both?

    
    /* add post content to activity blog component entries only */
    /*///////////////////////////////////////////////////////////////////////////////////////////*/
    add_filter('bp_before_activity_add_parse_args', 'record_cpt_blog_activity_content');
    
    function record_cpt_blog_activity_content( $cpt ) {
      
      if ( $cpt['component'] != 'blogs' ){
    
      $post = get_post( $cpt['secondary_item_id'] );
      $postid = $cpt['secondary_item_id'];
      $imgSize = '1x1';
    
        /*template starts*/
    
        $cpt['content'] .= '<div class="card created">';
    
        if(has_post_thumbnail($postid)) {
          
        $cpt['content'] .= '<a href="'.get_permalink($postid).'">'.get_the_post_thumbnail($postid, $imgSize).'</a>';
        
        } 
    
        $cpt['content'] .= '<div class="card-body"><div class="card-title"><a href="'.get_permalink($postid).'">'.get_the_title($postid).'</a></div>
    
            <div class="card-author">
                <a href="'.bp_core_get_user_domain($post->post_author ).'">'.  bp_core_get_username($post->post_author) .'</a>
            </div>';
        
        $cpt['content'] .= '<div class="card_excerpt"><p>'.  wp_trim_words(get_post_field('post_content', $cpt['secondary_item_id'] ), 10, '...').'</p></div>';
       
        $cpt['content'] .= '</div></div><!--end-card-->';
    
        /*template ends*/
      }
            
        return $cpt;
    }
    
    /* This updates content if the post is updated but also works when first recording */
    /*///////////////////////////////////////////////////////////////////////////////////////////*/
    add_filter('bp_activity_content_before_save', 'update_cpt_blog_activity_content', 10, 2);
    
    function update_cpt_blog_activity_content( $content, $cpt ) {
    
        if ( $cpt->component != 'blogs' ) {
     
        $content = '';
        $post = get_post( $cpt->secondary_item_id );
        $postid = $cpt->secondary_item_id;
        $imgSize = '1x1';
    
        /*template starts*/
    
        $cpt['content'] .= '<div class="card updated">';
    
        if(has_post_thumbnail($postid)) {
          
        $cpt['content'] .= '<a href="'.get_permalink($postid).'">'.get_the_post_thumbnail($postid, $imgSize).'</a>';
        
        } 
    
        $cpt['content'] .= '<div class="card-body"><div class="card-title"><a href="'.get_permalink($postid).'">'.get_the_title($postid).'</a></div>
    
            <div class="card-author">
                <a href="'.bp_core_get_user_domain($post->post_author ).'">'.  bp_core_get_username($post->post_author) .'</a>
            </div>';
        
        $cpt['content'] .= '<div class="card_excerpt"><p>'.  wp_trim_words(get_post_field('post_content', $cpt['secondary_item_id'] ), 10, '...').'</p></div>';
       
        $cpt['content'] .= '</div></div><!--end-card-->';
    
        /*template ends*/
    
      }
    
      return $content;
    }
    
  • You must be logged in to reply to this topic.
Skip to toolbar