Skip to:
Content
Pages
Categories
Search
Top
Bottom

Custom Post Type Support for Activity


  • Monkey1980
    Participant

    @monkey1980

    Saw the 2.2 update today and was very pleased to see we can now have activity for Custom Post Types – so exited was I that I updated immediately!!! (coincidentally doing some dev’ stuff/maintenance)

    However my excitement soon passed – after poking around for the last few hours as the code you suggested did not seem to work fully it seems I have the following situation:

    1. When I specify my Custom Post Type, i do indeed get an activity entry …wahaay!!! – unfortunately the message is the default and not my custom message :0(

    2. If I specify the post type as ‘page’ – the message is my custom one (front end and back end) but obviously the activity feed is not updated as ‘page’ is not my CPT (previous entries from testing revealed this behaviour as when I changed the CPT back to page I have left the ‘action_id’ set to my CPT) :0(

    I also have a question, it seems the custom message %1$s for the user’s name – %2$s for the the link and %3$s for site name.

    For some reason %3$s doesn’t do anything?

    I would also prefer to show the page title as is shown when a blog is posted as supposed to just showing “User has posted a new ‘item'” – perhaps a %4$s can be added???

    Any help here would be most appreciated!! :0)

    Regards

    Sam

Viewing 11 replies - 26 through 36 (of 36 total)

  • pavoljurik
    Participant

    @pavoljurik

    hi, thanks for this – specialy code for displaying title in activity feed. I think its very useful and should be in core, actually I am not developer but this function and string replacing looks bit ugly to me anyway 🙂
    cheers


    ineedyou
    Participant

    @ineedyou

    Sorry for my english…
    I can show everything about Music CPT buddypress activity (site-wide and members activity) with below code by @imath -also thanks for all other plugings 🙂 –

    My Question or Problem.

    I am using types tools pluging and i have a – frontend – add new music form (about music CPT) and members use this form to add new music with different fields. Also using rich editor and can add media from URL… Buddypress activity stream can show this form body (actually show post body normally). If i add also image from URL to this frontend music CPT form, we can see this image also on buddypress activity. Well i love buddypress.. Flexiable, great..

    1 – But if i add video URL on this form do not show embed video on activity stream. I mean that, i tried 100 times frontend or backend, embed video (if use in any CPT) do not show on buddypress. When i click this activty open page and i can see video. I know missing something.

    2 – If my author create any music CPT –backend admin side– with Visual Composer, there 3 different actions.

    Action:1 – First, Buddypress activty show all font color or image, or texts created by visual composer. Its ok. Love buddypress. But when i select (site-wide or members activty) show post, friendship or comment than turn to everything or music cpt, buddypress now do not display this music CPT, so i must refresh the page. I mean that when a user select everything to post (or comment) or commet to everything: page must otomatically refresh to display my visual composer codes. If i dont refresh the page, activiy stream show like that [vc_row][vc_column][vc_text][/vc_column][/vc_row].

    Action 2: When i edit this CPT -backend and created by VC-, buddypress sometimes dont load any activity.. If i delete this post from again backend, everything is ok, all activity is coming back. I dont know how try search this on forum.

    Action 3: I am on backend admin and creating a new music CPT without visual composer.. No problem, all edit can show on buddypress again. Such as i shared music 3 hours ago but now editing. I can see this new edit when i scroll actvity page 3 hours ago… BUT, What i want, buddypress activtiy can create a new music post (for this edit) and can say “edited music” … Maybe we can put icon or color original (3 hours ago) cpt, also same time can create clone music for same cpt 🙂 on activity stream… I dont know how to search this 🙂

    Long sentences long, i know 🙂 … Maybe someone help me… Becuase i am not developer just copypaste code user 🙂

    add_post_type_support( 'music', 'buddypress-activity' );
    function customize_page_tracking_args() {
        // Check if the Activity component is active before using it.
        if ( ! bp_is_active( 'activity' ) ) {
            return; }
         bp_activity_set_post_type_tracking_args( 'music', array(
            'component_id'             => 'activity',
            'action_id'                => 'new_music',
            'bp_activity_admin_filter' => __( 'My Music', 'custom-domain' ),
            'bp_activity_front_filter' => __( 'Music', 'custom-domain' ),
            'contexts'                 => array( 'activity', 'member' ),
            'bp_activity_new_post'     => __( '%1$s published <a href="%2$s">Music Suggest</a>', 'xxx' ),
            'bp_activity_new_post_ms'  => __( '%1$s published <a href="%2$s">Musik/a>, on the site %3$s', 'xxx' ),
                   
           
        ) );
    }
    add_action( 'init', 'customize_page_tracking_args', 1000 );

    jbakuk
    Participant

    @jbakuk

    @milenushka Thanks for sharing your code, I’ve been trying to get this set up for days without success. Really, really appreciate you taking the time to post your code. 🙂


    caykimtien88
    Participant

    @caykimtien88

    function plugin_registers_post_type() {
    	$args = array(
    		'public'   => true,
    		'labels'   => array(
    			'name'                     => __( 'Artikel', 'your-plugin-textdomain' ),
    			'singular_name'            => __( 'Artikel', 'sozialdynamik' ),
    			'bp_activity_admin_filter' => __( 'Neuer Artikel veröffentlicht', 'sozialdynamik' ),
    			'bp_activity_front_filter' => __( 'Artikel', 'sozialdynamik' ),
     			'bp_activity_new_post'     => __( '%1$s hat den neuen <a href="%2$s">Artikel</a>', 'sozialdynamik' ),
     			'bp_activity_new_post_ms'  => __( '%1$s hat den neuen <a href="%2$s">Artikel</a>, on the site %3$s', 'sozialdynamik' ),
    		),
    		'supports'    => array( 'title', 'editor', 'buddypress-activity' ),
    		'bp_activity' => array(
    			'component_id' => 'activity',
    			'action_id'    => 'new_sd_article',
    			'contexts'     => array( 'activity', 'member' ),
    			'position'     => 100,
    		),
    	);
    	register_post_type( 'sd_article', $args );
    }
    add_action( 'init', 'plugin_registers_post_type' );

    caykimtien88
    Participant

    @caykimtien88

    thank you so much for writing back. For some reason I didn’t get the notification, and was depressed over the site for a month. Today I decided to finally face the issue again, and what a nice surprise!


    Eric
    Participant

    @eric01

    Hi,

    does someone use the code from @imath to replace the link to the article with the topic posted to de activity stream and link to the article?
    doesn´t work for me.

    i am also still looking for code to add the featured image of an custom post type article to the activity stream..

    tnx, Eric


    magland
    Participant

    @magland

    I’m using this code to add featured images from a custom post type into my activity feed:

    /* function to pull content into activity feed from post */
    function record_cpt_blog_activity_content( $cpt ) {
     	
    	if (strpos($cpt['type'], 'NAME_OF_YOUR_POST_TYPE') !== false) {
    		$existing = $cpt['content'];
    		
    		$imgSize = 'YOUR_CUSTOM_IMAGE_SIZE';
    		
    		if(has_post_thumbnail($cpt['secondary_item_id'])) {
    			$content .= '<div class="bpfb_images">';
    			$content .= '<a href="'.get_permalink($cpt['secondary_item_id']).'">';
    			$content .= get_the_post_thumbnail($cpt['secondary_item_id'], $imgSize);		
    			$content .= '</a>';
    			$content .= '</div>';
    		}
    		$content .= '<br /><h1><a href="'.get_permalink($cpt['secondary_item_id']).'">'.get_the_title($cpt['secondary_item_id']).'</a></h1>';
    		
            $cpt['content'] = $content;
    	}     
     
        return $cpt;
    }
    add_filter('bp_before_activity_add_parse_args', 'record_cpt_blog_activity_content');
    
    /* This fixes the status update content if the post is subsequently updated */
    function update_cpt_blog_activity_content( $content, $cpt ) {
     	if($cpt->secondary_item_id && strpos($cpt->type, 'NAME_OF_YOUR_POST_TYPE') !== false) {
    		
    		$content = '';
    		
    		$imgSize = 'YOUR_CUSTOM_IMAGE_SIZE';
    		
    		if(has_post_thumbnail($cpt->secondary_item_id)) {
    			$content .= '<div class="bpfb_images">';
    			$content .= '<a href="'.get_permalink($cpt->secondary_item_id).'">';
    			$content .= get_the_post_thumbnail($cpt->secondary_item_id, $imgSize);		
    			$content .= '</a>';
    			$content .= '</div>';
    		}
    		
    		$content .= '<br /><h1><a href="'.get_permalink($cpt->secondary_item_id).'">'.get_the_title($cpt->secondary_item_id).'</a></h1>';
    	}
    	
    	return $content;
    }
    add_filter('bp_activity_content_before_save', 'update_cpt_blog_activity_content', 10, 2);

    The first function catches when the post is added. It may not have a featured image at the point it is posted, so the second function catches when the post is updated and updates the activity. Hope that helps. You’ll need to swap out NAME_OF_YOUR_POST_TYPE and YOUR_CUSTOM_IMAGE_SIZE


    glouton
    Participant

    @glouton

    Hello there,

    I’m reviving this old thread cause I can’t wrap my head around the text domain.

    I’ve read this thread, the codex and this example : https://gist.github.com/imath/dce8426f686da1727f82

    It works for me, I understand how and the code but in case of adding buddypress-activity support to a post type created by another plugin (CBX Poll) I can’t figure out what text domain to use when I put this code in bp-custom.php

    With a home made plugin I would add support at post type registration and use this custom plugin’s domain.

    I guess I could use the functions.php of the theme and the theme’s domain but then it’s theme dependent.

    If anyone can enlighten me…


    annadito
    Participant

    @annadito

    @imath I realize this post is 5+ years old, but the steps are still working for me for the most part. However, the filter that is set up to replace the world “Artikel” with the actual post name only works when the custom post type is published. Once it is edited, the activity feed changes back to the original word (Artikel in your example). Any ideas as to how I may be able to fix this?

    I appreciate any help!


    annadito
    Participant

    @annadito

    @imath I realize this post is 5+ years old, but the steps are still working for me for the most part. However, the filter that is set up to replace the world “Artikel” with the actual post name only works when the custom post type is published. Once it is edited, the activity feed changes back to the original word (Artikel in your example). Any ideas as to how I may be able to fix this?

    I appreciate any help!

    How would you add a CPT post activity item in a specific group (say user has a “main” group that i have recorded in either user meta or bp xprofile field called ‘master-groupname’ ?

Viewing 11 replies - 26 through 36 (of 36 total)
  • You must be logged in to reply to this topic.
Skip to toolbar