Skip to:
Content
Pages
Categories
Search
Top
Bottom

Adding custom posts to activity- and changing the name of the activity action


  • milenushka
    Participant

    @milenushka

    Hi ,

    I needed to add custom posts to the activity feed, and found this thread useful.


    @shanebp
    said :

    And if you go thru the trouble of creating a CPT, why not filter the activity action so it isn’t the generic ‘…wrote a new post’. For example:

    
    add_filter(‘bp_blogs_activity_new_post_action’, ‘record_cpt_activity_action’, 1, 3);
    function record_cpt_activity_action( $activity_action, $post, $post_permalink ) {
    global $bp;
    if( $post->post_type == ‘videos’ ) {
    if ( is_multisite() )
    $activity_action = sprintf( __( ‘%1$s created a new Videos post, %2$s, on the site %3$s’, ‘buddypress’ ), bp_core_get_userlink( (int) $post->post_author ), ‘‘ . $post->post_title . ‘‘, ‘‘ . get_blog_option( $blog_id, ‘blogname’ ) . ‘‘ );
    
    else
    $activity_action = sprintf( __( ‘%1$s created a new Videos post, %2$s’, ‘buddypress’ ), bp_core_get_userlink( (int) $post->post_author ), ‘‘ . $post->post_title . ‘‘ );
    
    }
    
    return $activity_action;
    }
    

    However if I do that, the link to the custom post itself disappears. It shows up but is un-clickable.
    Is the code missing something?

    Would really appreciate the help!

    Thanks

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

  • shanebp
    Moderator

    @shanebp

    Try replacing all the single quotes.
    For example ‘videos’ should ‘videos’.
    If you copy and paste, make sure the single quotes are converted to ‘ or ’


    milenushka
    Participant

    @milenushka

    Hi @shanebp,

    I am sorry I don’t quite understand..

    My exact code looks like this:

    add_filter( 'bp_blogs_record_post_post_types', 'inspired_record_more_types' );
    function inspired_record_more_types( $types ) {
        $types[] = 'projects';
            return $types;
    }
    
    add_filter('bp_blogs_activity_new_post_action', 'record_cpt_activity_action', 1, 3);
    function record_cpt_activity_action( $activity_action, $post, $post_permalink ) {
    global $bp;
    if( $post->post_type == 'projects' ) {
    if ( is_multisite() )
    $activity_action = sprintf( __( '%1$s created a new project, %2$s, on the site %3$s', 'buddypress' ), bp_core_get_userlink( (int) $post->post_author ), '' . $post->post_title . '', '' . get_blog_option( $blog_id, 'blogname' ) . '' );
    else
    $activity_action = sprintf( __( '%1$s created a new project, %2$s', 'buddypress' ), bp_core_get_userlink( (int) $post->post_author ), '' . $post->post_title . '' );
    }
    return $activity_action;
    }

    and the link to the project custom post is not showing. It does show with only the first part of the code- but the slug is generic – .. “wrote a new post”


    milenushka
    Participant

    @milenushka

    p.s. it’s a singe blog installation (not a multisite)


    shanebp
    Moderator

    @shanebp

    Your code is garbled and missing the href. Try this:

    add_filter('bp_blogs_activity_new_post_action', 'record_cpt_activity_action', 1, 3);
    function record_cpt_activity_action( $activity_action,  $post, $post_permalink ) { 
    
       if( $post->post_type == 'projects' ) {
    	$activity_action  = sprintf( __( '%1$s created a new Project, %2$s', 'buddypress' ), bp_core_get_userlink( (int) $post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );
       }
    	
       return $activity_action;
    }

    milenushka
    Participant

    @milenushka

    Wow, @shanebp, thank you so much! That worked perfectly!

    Perhaps you can help me with something else, i’ve been struggling for some time?

    I would like to add the featured image to these activity updates (whether it’s a regular blog post or the custom post – such as projects).

    I found this code before- this one is for posts. It works, but there is something in it that makes all the excerpts in the activity – short and unclickable.
    Also some custom post types do not show the attached image.

    function icondeposit_bp_activity_entry_meta() {
     
        if ( bp_get_activity_object_name() == 'blogs' && bp_get_activity_type() == 'new_blog_post' ) {?>
            <?php
            global $wpdb, $post, $bp;
            $theimg = wp_get_attachment_image_src(  get_post_thumbnail_id( bp_get_activity_secondary_item_id() ) );
            ?>
            <img src="<?php echo $theimg[0]; ?>" >
     
        <?php }
     
    }
    add_action('bp_activity_excerpt_append_text', 'icondeposit_bp_activity_entry_meta');

    And another thing I was researching and could find any reference to :
    How can I add the group description to the activity update?
    I think if it shows up in the activity- it should at least carry some information that will make members want to click and join the group.

    Thank you for your help!


    milenushka
    Participant

    @milenushka

    Hi @shanebp,

    Thank you for your help. I found this article by @boonebgorges about adding the comments to custom posts to the activity feed. I actually have that working already, but the text is generic- “user commented on a post”. Is there a way to add a specific slug here too?

      function bbg_record_my_custom_post_type_comments( $post_types ) {
          $post_types[] = 'dolphin'; // Add your custom post type name to the array. If you have a post type called 'dolphin' then you have a weird plugin
          return $post_types;
      }
      add_filter( 'bp_blogs_record_comment_post_types', 'bbg_record_my_custom_post_type_comments' );

    With kind regards,

    M

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Adding custom posts to activity- and changing the name of the activity action’ is closed to new replies.
Skip to toolbar