Skip to:

Opened 8 months ago

Last modified 6 months ago

#7451 new enhancement

Adding comments from non-registered users into activity stream.

Reported by: pavelevap Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Activity Keywords: needs-patch
Cc: pavelevap@…


There was an old plugin "BP Include Non-member Comments" by @boonebgorges, but it does not work anymore.

I tried to update it, but there is too much new functionality that I would have to duplicate too much code. So, I tried to use comment_post action and adding comments to activity stream, but there are some blocking points:

1) Function bp_activity_post_type_comment() is checking if user is registered:

2) Function bp_activity_new_comment() is also checking if user_id is available:

When it is be possible to go through both places (for example with the help of some hook), it could be achived easily.

I did not want to hardcode changes, so I used some kind of cache hack to bypass it (adding user with user_id = 9999999 into user cache before BuddyPress will check it):

add_action( 'comment_post', 'custom_include_non_registered_comments_into_stream', 8, 2 );
function custom_include_non_registered_comments_into_stream( $comment_id, $is_approved ) {
  if ( $is_approved == 1 ) {
    $comment = get_comment( $comment_id );
    $user = get_user_by( 'email', $comment->comment_author_email );
    if ( empty ( $user ) ) {
      wp_cache_add( $comment->comment_author_email, 9999999, 'useremail' );
      $user_object = new WP_User();
      $user_object->ID = 9999999;
      wp_cache_add( 9999999, $user_object, 'users' );

Everything works now, there are no warnings, but I am not sure if there are any possible consequences? I had to use also filters bp_activity_comment_action, bp_core_gravatar_email, bp_activity_comment_name and bp_activity_comment_user_link to customize display of these comments in activity stream (especially to handle special user_id = 9999999), but hook with possibility of adding comments from non-registered users (empty or zero user_id) would be easier and very helpful for some users. I understand that BuddyPress is network of registered members, but in this case blog comments from non-registered users in activity stream can be also helpful.

Maybe there is another way to achieve, but I did not find it :-(

Change History (2)

#1 @tw2113
6 months ago

Honestly feels like Boone's plugin should be amended, or perhaps deprecated, for the current BP version instead of trying to change BP core for the sake of one plugin with a very low install count.

#2 @boonebgorges
6 months ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to Future Release

@pavelevap Thanks for the ticket.

I agree with @tw2113 that my plugin is not so important as to require major changes in BP. That said, the root problem here is not my plugin - it's the fact that BP hardcodes the user_id requirement in a way that's very difficult to circumvent. If a plugin or a site wants to allow anonymous activity items to be created, why shouldn't BP let it? We should centralize our user_id checks so that they occur higher in the stack, or make the requirement filterable, or something like that.

Note: See TracTickets for help on using tickets.