Skip to:
Content
Pages
Categories
Search
Top
Bottom

Custom post type comment tracking


  • agnesmeil
    Participant

    @agnesmeil

    Yay for the new release! I love how the comments synchronise.
    I was super excited when I saw the Custom Post Type Comment Tracking function would be added to the new version of BuddyPress, so I’ve been waiting (im)patiently for the release, but I can’t get it to work. I want comments to lessons of the Namaste! LMS plugin (post type = namaste_lesson) to show up in the activity stream.

    I use WP 4.4.2 and BP 2.5.0, single site install
    I tried with twenty fifteen theme, still the same problem.
    I tried all repair tools, deinstalled all plugins, reinstalled just BP and Namaste, and also tried it without Namaste with another CPT
    I tried adding
    add_post_type_support( 'namaste_lesson', 'buddypress-activity' );
    to bp_custom.php
    I also tried this this snippet https://codex.buddypress.org/plugindev/post-types-activities/#1-add-comments-tracking-to-an-existing-post-type but I wasn’t sure how to use the namaste_lesson because of the underscore, for instance in
    'action_id' => 'new_blog_page',
    does that become
    'new_namaste_lesson'
    ??
    As you can tell I’m completely new to coding. I would love to learn, though.

    Thanks so much!

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

  • RecoilDesign
    Participant

    @recoildesign

    I’m in the same boat and would love to hear some feedback on this question. It’s exciting to see Custom Post Type Tracking included in 2.5 but the documentation is a little hard to understand.

    If anyone could please explain how to enable comment tracking for custom post types (in layman’s terms), it would be a huge help.


    shanebp
    Moderator

    @shanebp


    @agnesmeil
    – Try:

    function agnes_customize_lesson_tracking_args() {
    
        if ( ! bp_is_active( 'activity' ) ) 
            return;
     
        add_post_type_support( 'namaste_lesson', 'buddypress-activity' );
     
        bp_activity_set_post_type_tracking_args( 'namaste_lesson', array(
            'action_id'                         => 'new_namaste_lesson',
            'bp_activity_admin_filter'          => __( 'Published a new Lesson', 'custom-textdomain' ),
            'bp_activity_front_filter'          => __( 'Lessons', 'custom-textdomain' ),
            'bp_activity_new_post'              => __( '%1$s posted a new <a href="%2$s">Lesson</a>', 'custom-textdomain' ),
            'bp_activity_new_post_ms'           => __( '%1$s posted a new <a href="%2$s">Lesson</a>, on the site %3$s', 'custom-textdomain' ),
            'contexts'                          => array( 'activity', 'member' ),
            'comment_action_id'                 => 'new_namaste_lesson_comment',
            'bp_activity_comments_admin_filter' => __( 'Commented a Lesson', 'custom-textdomain' ),
            'bp_activity_comments_front_filter' => __( 'Lessons Comments', 'custom-textdomain' ),
            'bp_activity_new_comment'           => __( '%1$s commented on the <a href="%2$s">Lesson</a>', 'custom-textdomain' ),
            'bp_activity_new_comment_ms'        => __( '%1$s commented on the <a href="%2$s">Lesson</a>, on the site %3$s', 'custom-textdomain' ),
            'position'                          => 100,
        ) );
    }
    add_action( 'bp_init', 'agnes_customize_lesson_tracking_args' );

    agnesmeil
    Participant

    @agnesmeil

    Thanks for your help Shane! But it doesn’t seem to do the trick…


    shanebp
    Moderator

    @shanebp

    Are you 100% certain that the cpt is called ‘namaste_lesson’ ?


    RecoilDesign
    Participant

    @recoildesign

    The only way I was able to get this to work was by modifying my custom post type directly in the functions.php. Agnes, perhaps this will help you as well:

    function create_post_type_videos() {
    	register_post_type( 'my_videos',
    		array(
    			'labels' => array(
    				'name' => __( 'Videos' ),
    				'add_new_item' => __( 'Add Video' ),
    				'edit_item' => __( 'Edit Video' ),
    				'all_items' => __( 'All Videos' ),
    				'singular_name' => __( 'Videos' ),
    				'view' => __( 'View Videos' ),
    				'view_item' => __( 'View Video' ),
    				'search_items' => __( 'Search Videos' ),
    				'not_found' => __( 'No videos found.' ),
    				'not_found_in_trash' => __( 'No videos found in Trash.' ),
    			),
    			'public' => true,
    			'has_archive' => false,
    			'supports' => array( 'title', 'author', 'editor', 'thumbnail', 'revisions', 'comments', 'buddypress-activity' ),
    			'taxonomies' => array( 'product_type', 'videos_categories' ),
    			'rewrite' => array('slug' => 'videos'),
    			'menu_icon' => 'dashicons-video-alt3',
    			'menu_position' => 5,
    			'bp_activity' => array(
    			    'action_id'         => 'new_video',
    			    'comment_action_id' => 'new_video_comment',
    			)
    		)
    	);
    }
    add_action( 'init', 'create_post_type_videos' );
    

    The key bits of code are the ‘buddypress-activity’ the ‘supports’ array and the ‘bp-activity’ array at the end. After modifying my custom post type to include this code, I now see comments appearing in the Activity Stream.

    Perhaps someone could verify if this code is correct, and also explain why the code in Shane’s example (and in the BP docs) is not working?


    agnesmeil
    Participant

    @agnesmeil

    I’m quite sure, but it’s absolutely possible I misunderstood the code. This is in plugins/namaste-lms/models/lesson-model:

    	static function register_lesson_type() {		
    		$lesson_slug = get_option('namaste_lesson_slug');
    	   if(empty($lesson_slug)) $lesson_slug = 'namaste-lesson';
    	   
    		$args=array(
    			"label" => __("Namaste! Lessons", 'namaste'),
    			"labels" => array
    				(
    					"name"=>__("Lessons", 'namaste'), 
    					"singular_name"=>__("Lesson", 'namaste'),
    					"add_new_item"=>__("Add New Lesson", 'namaste')
    				),
    			"public"=> true,
    			"show_ui"=>true,
    			"has_archive"=>true,
    			"rewrite"=> array("slug"=>$lesson_slug, "with_front"=>false),
    			"description"=>__("This will create a new lesson in your Namaste! LMS.",'namaste'),
    			"supports"=>array("title", 'editor', 'author', 'thumbnail', 'excerpt', 'comments', 'post-formats'),
    			"taxonomies"=>array("category"),
    			"show_in_nav_menus"=>'true',
    			'show_in_menu' => 'namaste_options',
    			"register_meta_box_cb"=>array(__CLASS__,"meta_boxes")
    		);
    		register_post_type( 'namaste_lesson', $args );

    That very last line tells us it’s called ‘namaste_lesson’ right?

    Maybe I can somehow add some extra code to this file? But then there would be the problem of updates, right?
    Would it help (and how would I do that) if the namaste_lesson cpt is made WITH the buddypress-activity support like suggested by RecoilDesign BEFORE the Namaste plugin is activated or something?

    Thanks so much for helping me 🙂


    shanebp
    Moderator

    @shanebp

    It might be a timing thing – bp_init is called before the namaste code creates the cpt.

    Anyhow… try this in the creation of the namaste cpt:

    "supports"=>array("title", 'editor', 'author', 'thumbnail', 'excerpt', 'comments', 'post-formats', 'buddypress-activity'),
    'bp_activity' => array(
        'component_id'          => buddypress()->activity->id,
        'action_id'             => 'new_namaste_lesson',
        'contexts'              => array( 'activity', 'member', 'groups', 'member-groups' ),
        'position'              => 70,
    ),
    "taxonomies"=>array("category"),


    agnesmeil
    Participant

    @agnesmeil

    I added it, but still nothing happens if I post a comment to a lesson.

    Could it still be a timing issue? I imagine namaste already made the post type. Maybe I should try deinstalling and installing namaste again with the buddypress changes made?


    shanebp
    Moderator

    @shanebp

    Try this in your function register_lesson_type()

    $args=array(
    	"label" => __("Namaste! Lessons", 'namaste'),
    	"labels" => array (
    	    "name"=>__("Lessons", 'namaste'), 
    	    "singular_name"=>__("Lesson", 'namaste'),
    	    "add_new_item"=>__("Add New Lesson", 'namaste'),
                'bp_activity_admin_filter' => __( 'Lessons', 'namaste' ),
                'bp_activity_front_filter' => __( 'Lessons', 'namaste' ),
                'bp_activity_new_post' => __( '%1$s created a new <a href="%2$s">Lesson</a>', 'namaste' ),
    	    'bp_activity_comments_admin_filter' => __( 'Comments about Lessons', 'namaste' ), 
    	    'bp_activity_comments_front_filter' => __( 'Lesson Comments', 'namaste' ), 
    	    'bp_activity_new_comment'  => __( '%1$s commented on the <a href="%2$s">Lesson</a>', 'namaste' ),
    	),
    	"public"        => true,
    	"show_ui"       => true,
    	"has_archive"   => true,
    	"rewrite"       => array("slug"=>$lesson_slug, "with_front"=>false),
    	"description"   => __("This will create a new lesson in your Namaste! LMS.",'namaste'),
    	"supports"      => array("title", 'editor', 'author', 'thumbnail', 'excerpt', 'comments', 'post-formats', 'buddypress-activity'),
            'bp_activity' => array(
                'action_id'             => 'new_lesson',
                'contexts'              => array( 'activity', 'member' ),
                'comment_action_id'     => 'new_lesson_comment', 
                'position'              => 70,
            ),			
    	"taxonomies"    => array("category"),
    	"show_in_nav_menus "    =>  'true',
    	'show_in_menu'  => 'namaste_options',
    	"register_meta_box_cb" => array(__CLASS__,"meta_boxes")
    );
    register_post_type( 'namaste_lesson', $args );

    agnesmeil
    Participant

    @agnesmeil

    Wooohooo, that did the trick!!!

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