Skip to:
Content

BuddyPress.org

Opened 5 years ago

Closed 4 years ago

#6306 closed defect (bug) (fixed)

custom post type support for activities

Reported by: shanebp Owned by: imath
Milestone: 2.3 Priority: normal
Severity: normal Version: 2.2
Component: Blogs Keywords: has-patch 2nd-opinion
Cc: shane@…

Description

An activity entry is created when a new cpt post is created.
But comments on custom post type post are not appearing in the activity stream.

I am not creating a component.

I create a custom post type.
I add post_type_support:

register_post_type( 'cpt',... 
	"supports" => array("title", "editor", "thumbnail", "author", "comments", "trackbacks", "buddypress-activity"),
	'bp_activity' => array(
		'component_id' => 'activity',
		'action_id'    => 'new_cpt',
		'contexts'     => array( 'activity', 'member', 'member_groups' ),
		'position'     => 100,
	),

A function hooked to bp_init runs this:

   bp_activity_set_post_type_tracking_args( 'cpt', array(
        'component_id'             => 'activity',
        'action_id'                => 'new_cpt',
        'bp_activity_admin_filter' => __( 'CPT', 'bp-domain' ),
        'bp_activity_front_filter' => __( 'CPT', 'bp-domain' ),
        'contexts'                 => array( 'activity', 'member', 'group' ),
        'activity_comment'         => true,
        'bp_activity_new_post'     => __( '%1$s created a new <a href="%2$s">CPT</a>', 'bp-domain' ),
        'bp_activity_new_post_ms'  => __( '%1$s created a new <a href="%2$s">CPT</a>, on the site %3$s', 'bp-domain' ),
        'position'                 => 100,
    ) )

I have Site Tracking and Allow activity stream commenting on blog and forum posts enabled.
Comments on regular blog posts appear in the activity stream.

So why don't comments on cpt posts?
Bug or mistake on my end?

Attachments (3)

6306.patch (1.3 KB) - added by imath 5 years ago.
6306.alt.patch (1.2 KB) - added by imath 5 years ago.
6306.unittests.patch (7.3 KB) - added by imath 5 years ago.

Download all attachments as: .zip

Change History (24)

#1 @imath
5 years ago

  • Milestone Awaiting Review deleted
  • Status changed from new to closed

No bug, no mistake. It's just something we need to work on for a future release, see my comment on #6294.

Thanks for your feedback, i think it's a duplicate.

#2 @shanebp
5 years ago

  • Status changed from closed to reopened

Ok, thanks.

Meanwhile, it seems that the 'old' method of adding cpts post and comments no longer adds comments to the activity stream. Is that not a bug?

function cpt_posts($post_types) {
    $post_types[] = 'cpt';
    return $post_types;
}
add_filter( 'bp_blogs_record_comment_post_types', 'cpt_posts' );  // doesn't work
add_filter( 'bp_blogs_record_post_post_types', 'cpt_posts' );  // works

// And the old method of customing the activity action doesn't work in 2.2 either
add_filter('bp_blogs_activity_new_post_action', 'cpt_activity_action', 15, 3);
Last edited 5 years ago by shanebp (previous) (diff)

#3 @mjc82in
5 years ago

Any updates on it, we having this same problem, I cant get comments from pages to display on the activity

#4 @imath
5 years ago

@shanebp @mjc82in

I understand your eagerness about this subject. When i've worked on the post type activities feature we've introduced in 2.2, i haven't touch any of the code involved into the comments tracking.

FYI, although the post types activities feature doesn't need the blogs component to be active, tracking comments is requiring it to be active. @shanebp have you tried filtering 'bp_blogs_record_comment_post_types' having the blogs component active ?

@mjc82in, as i've said here #6294, it's not a bug : tracking comments about Post types (!= post) is still a step we'll need to achieve in a future release.

If you can't wait, you can explore the way i'm tracking comments about ideas for my plugin WP Idea Stream @shanebp you'll see that as soon as the blogs component is active my filter on 'bp_blogs_record_comment_post_types' works fine. For this plugin, if the blogs component is not active, i'm not tracking the 'ideas' post type.

Thank you for your comprehension.

#5 follow-up: @shanebp
5 years ago

@imath - thanks for the Idea Stream link - it's informative.

tracking comments is requiring it to be active.

I thought the blogs component was always active on non-multi installs.
Or at least activated, which is why it doesn't show in the BP components Settings screen.

You're saying that I need to explicitly set the current component to blogs?
This was not the case prior BP 2.2 (?).

Last edited 5 years ago by shanebp (previous) (diff)

#6 in reply to: ↑ 5 @imath
5 years ago

Replying to shanebp:

I thought the blogs component was always active on non-multi installs.

No, when activating BuddyPress: the components automatically since version 1.7.0 (except for notifications i think this component was created in 1.9) activated are :

'activity'      => 1,
'members'       => 1,
'settings'      => 1,
'xprofile'      => 1,
'notifications' => 1,

see https://buddypress.trac.wordpress.org/browser/trunk/src/bp-core/bp-core-update.php#L185

You're saying that I need to explicitly set the current component to blogs?
This was not the case prior BP 2.2 (?).

No, i'm saying : in order to have comments tracking on post (and be able to filter bp_blogs_record_comment_post_types), you need to activate the blogs component. Functions about site tracking required the blogs component to be active since 1.5 i think.
If after activating the blogs component the comments about your post type are tracked, i'd suggest to close this ticket as a duplicate of #6294

#7 @imath
5 years ago

  • Status changed from reopened to closed

Just did some tests. I confirm :

  • nothing as changed in the comments tracking from 2.1 to 2.2
  • to use the 'bp_blogs_record_comment_post_types', you need to have the blogs (or Site Tracking) component active.
  • if this component is active, it's possible to tack the comment of a post type you're adding thanks to the above filter.

Closing this as a duplicate of #6294. We'll work on an enhancement to ease tracking comments for custom post types on a future release.

Thanks everyone for your contributions.

#8 follow-up: @shanebp
5 years ago

  • Status changed from closed to reopened

My testing shows that comments tracking does not work in BP 2.2

WP 4.1.1, BP 2.2.1, 2013 theme, no other plugins running

Site Tracking is ON.
'Allow activity stream commenting on blog and forum posts' is ON.

[Gist of test code]https://gist.github.com/shanebp/b0dcae45709fba43e41c

The result is that comments are not tracked.
The use of bp_blogs_activity_new_post_action does not affect the entry.
Instead it shows the generic wrote a new item.

The approach in used in the test code worked prior to BP 2.0
Perhaps a different approach is needed now for those of us who need comment tracking?

Last edited 5 years ago by shanebp (previous) (diff)

#9 in reply to: ↑ 8 @imath
5 years ago

Replying to shanebp:

My testing shows that comments tracking does not work in BP 2.2

I've used your code, and it's working.
Your problem is not linked to the Post type activity support we've introduced in 2.2, but is linked to #5130.

Since BuddyPress 2.0, when activating the option 'Allow activity stream commenting on blog and forum posts'. The comments made on regular post or on the activity of this post are synced. Meaning commenting an activity generates a comment and vice versa.

If you deactivate the option 'Allow activity stream commenting on blog and forum posts' then :

The result is that comments are not tracked.

becomes true

The use of bp_blogs_activity_new_post_action does not affect the entry.

still doesn't have any effects, you'll need to adapt your code using the gist

Perhaps a different approach is needed now for those of us who need comment tracking?

If you prefer to use the filter 'bp_blogs_activity_new_post_action' for you post type action string you can still use it, see this gist: https://gist.github.com/imath/36f588e77a7a574600cb#file-bp-custom-php-L27
I would advise to use the new way of adding activity support to post types, but it's up to you.

But 'bp_blogs_activity_new_post_action' is there to filter the action of a published post, which has nothing to do with the original reason of your ticket :

But comments on custom post type post are not appearing in the activity stream.

Again: we haven't changed anything in this area since 2.0. Custom post types still needs the blogs component to be active and still need to filter 'bp_blogs_record_comment_post_types'.

The only trouble i see is:
a notice error due to some code introduced in 2.3, i think it's relative to #6177

#10 @shanebp
5 years ago

I've been doing this testing using the old method per the gist on several installs on a shared Bluehost server.
With both 'Site Tracking' and 'Allow activity stream commenting on blog and forum posts' always on.
And it never worked.

[see Correction in next comment ]
Just tried it on a site5 server - and it works !!

I would advise to use the new way of adding activity support to post types, but it's up to you.

I would love to - But until it supports comment tracking for custom post types per #6294, it is not an option.


Last edited 5 years ago by shanebp (previous) (diff)

#11 @shanebp
5 years ago

CORRECTION -

The site5 install was using BP 2.1.1

I just switched my test installs on BlueHost from BP 2.2.1 to BP 2.1.1, and now comment tracking for custom post types is working.
Again, I'm using the old approach as shown in this gist: https://gist.github.com/imath/36f588e77a7a574600cb#file-bp-custom-php-L27

I've tried using the old approach on 3 different hosting platforms now.
In each case, it works with BP 2.1.1
In each case, it does Not work with BP 2.2.1

So this is definitely a bug in BP after BP 2.1.1

Last edited 5 years ago by shanebp (previous) (diff)

#12 @imath
5 years ago

  • Component changed from Component - Activity to Component - Blogs
  • Keywords has-patch 2nd-opinion added
  • Milestone set to Awaiting Review
  • Version changed from 2.2.1 to 2.2

If you read carefully my last comment, i've written:

If you deactivate the option 'Allow activity stream commenting on blog and forum posts' then

The result is that comments are not tracked.

becomes true

I'm rephrasing : if the option 'Allow activity stream commenting on blog and forum posts' is not set, your code is working (https://gist.github.com/imath/36f588e77a7a574600cb#file-bp-custom-php-L27).

Now, it seems you absolutely want to use the activity comments/comments syncing feature by setting the option 'Allow activity stream commenting on blog and forum posts' to true. Although i personaly think it's not a good idea, as it was possible in version 2.1.1 we can consider this as a regression we should fix in 2.2.2.

I strongly feel a plugin using custom post types shouldn't use a feature that is restricted for regular posts so far. #5130 introduced comments syncing, but restricted the feature to the 'new_blog_post' action. See https://buddypress.trac.wordpress.org/browser/trunk/src/bp-blogs/bp-blogs-activity.php#L530. But it's a personal feeling and i might be too conservative.

First, with a simple adaptation to the previous gist you can benefit from comment syncing without any change to core :
see https://gist.github.com/imath/8c7c9702df3cd57d583b#file-bp-custom-php-L29 - symply make sure your bp_activity parameter is containing an 'action_id' argument set to 'new_blog_post'.

If we consider this as a regression, then we have two choices to fix it:

  1. 6306.patch: Make sure plugins filtering 'bp_blogs_record_post_post_types' will get the regular posts activity tracking parameters. Meaning, the post types will not have it's own filter option in front or back.
  2. 6306.alt.patch: Or make sure plugins filtering 'bp_blogs_record_comment_post_types' will get the regular posts activity tracking parameters.

I personaly prefer this last option as it leaves a way to plugins only filtering 'bp_blogs_record_post_post_types' to still have their own activity action instead of being grouped with the regular post in the 'new_blog_post' action.

I'd like a second opinion on this issue to be absolutely sure we should take care of it as a regression and about the best option on how to fix it.

Last edited 5 years ago by imath (previous) (diff)

This ticket was mentioned in Slack in #buddypress by imath. View the logs.


5 years ago

#14 follow-up: @boonebgorges
5 years ago

I'll defer to imath and r-a-y, but at a glance I would say that posts and comments should be treated the same, which suggests that 1 is the better option. The other option is simply breaking backward compatibility here, and telling developers that they will need to use the new way of recording themselves in the activity stream. But it seems to me that if we can provide backward compatibility by using the old filter here, we should probably do it (but maybe make a note in the documentation that it's deprecated).

#15 @shanebp
5 years ago

All I'm asking for is consistency in how BP 2+ handles comment syncing for custom post types.

Since post_type_support does not yet handle sync, then it seems reasonable that we should be able to use the approach that works in BP 2.1.1.
And that means the option 'Allow activity stream commenting on blog and forum posts' is set to true.

#16 @DJPaul
5 years ago

  • Milestone changed from Awaiting Review to Under Consideration

#17 in reply to: ↑ 14 @imath
5 years ago

Replying to boonebgorges:

(but maybe make a note in the documentation that it's deprecated).

I'd follow your recommandation on option 1, but this last parenthese is introducing some hesitations :)
I agree that the filter 'bp_blogs_record_post_post_types' should be deprecated. But as we haven't worked on the comments about post types, the other filter 'bp_blogs_record_comment_post_type' can't be deprecated yet.

In bp-blogs-loader.php there's already a backward compability mechanism in place :
https://buddypress.trac.wordpress.org/browser/trunk/src/bp-blogs/bp-blogs-loader.php#L94

This filter should have been deprecated. Plugins using this filter are not a problem, default post types activity parameters are generated, there are new dropdown filters for the post type and by default the component is activity.

The real problem appears when they filter 'bp_blogs_record_comment_post_type', as the activity/comment synchronization is forcing the activity type to be 'new_blog_post' :
see https://buddypress.trac.wordpress.org/browser/trunk/src/bp-blogs/bp-blogs-activity.php#L530

I'll need to run some other tests, because i'm wondering what would happen if a plugin was using activity post types introduced in 2.2 and filter 'bp_blogs_record_comment_post_type'. In this case option 2 might make sure if the blogs component is active to filter the tracking args so that comment are synced with activities for the particular post type. But for sure option 1 wouldn't.

But i might overthink about it :)

@imath
5 years ago

@imath
5 years ago

#18 @imath
5 years ago

So 6306.patch will pass all tests except the test_bp_activity_post_types_filtering_blogs_comments one. 6306.alt.patch will pass all tests.

test_bp_activity_post_types_filtering_blogs_comments is testing the case where :

  • Post type is registering using the 'buddypress-activity' support
  • It filters 'bp_blogs_record_comment_post_type' to track the comments

I agree 6306.patch is the more consistent option. But means if you need to generate activity for the comments about your post types, do not use 'buddypress-activity' support but use a deprecated filter instead (a bit annoying).

6306.alt.patch means you can use 'buddypress-activity' support when registering your post type, but as soon you will filter 'bp_blogs_record_comment_post_type' to track comments about it, all activity tracking args will be the one of the 'Post' post types (a bit annoying also!).

#19 @DJPaul
5 years ago

  • Milestone changed from Under Consideration to 2.3

This ticket was mentioned in Slack in #buddypress by imath. View the logs.


5 years ago

#21 @imath
4 years ago

  • Owner set to imath
  • Resolution set to fixed
  • Status changed from reopened to closed

In 9837:

Make sure tracked post types registered using the bp_blogs_record_post_post_types filter will have the same activity tracking arguments than the post post type.

Since 2.2.0, and the introduction of the custom post types activities feature, when a post type was registered using the bp_blogs_record_post_post_types filter it had specific tracking arguments. It introduced some inconsistency as soon as the filter bp_blogs_record_comment_post_types was also used to track comments about this post type and when the activity/comment syncing feature was on.

From now on, post types registering to Site tracking using the filter bp_blogs_record_post_post_types will automatically get the same tracking arguments than the post post type to fix this inconsistency.

Props shanebp, boonebgorges

Fixes #6306

Note: See TracTickets for help on using tickets.