[buddypress-trac] [BuddyPress Trac] #7451: Adding comments from non-registered users into activity stream.
buddypress-trac
noreply at wordpress.org
Mon Feb 27 12:23:26 UTC 2017
#7451: Adding comments from non-registered users into activity stream.
-------------------------+-----------------------------
Reporter: pavelevap | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Activity | Version:
Severity: normal | Keywords:
-------------------------+-----------------------------
There was an old plugin "BP Include Non-member Comments" by @boonebgorges,
but it does not work anymore.
https://wordpress.org/plugins/bp-include-non-member-comments/
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: https://buddypress.trac.wordpress.org/browser/tags/2.8.1/src
/bp-activity/bp-activity-functions.php#L2310
2) Function `bp_activity_new_comment()` is also checking if `user_id` is
available: https://buddypress.trac.wordpress.org/browser/tags/2.8.1/src
/bp-activity/bp-activity-functions.php#L2587
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 :-(
--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/7451>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac
More information about the buddypress-trac
mailing list