/** * Formats single activity comment entries to use the blog comment action. * * This is only done if the activity comment is associated with a blog comment. * * @since 2.0.1 * * @param string $retval The activity action. * @param BP_Activity_Activity $activity Activity object. * @return string */ function bp_blogs_activity_comment_single_action($retval, $activity) { if ('activity_comment' !== $activity->type) { return $retval; } if (bp_disable_blogforum_comments()) { return $retval; } $parent_activity = new BP_Activity_Activity($activity->item_id); if (!isset($parent_activity->type)) { return $retval; } $post_type = bp_activity_post_type_get_tracking_arg($parent_activity->type, 'post_type'); if (!$post_type) { return $retval; } $blog_comment_id = bp_activity_get_meta($activity->id, "bp_blogs_{$post_type}_comment_id"); if (!empty($blog_comment_id)) { $bp = buddypress(); // Check if a comment action id is set for the parent activity $comment_action_id = bp_activity_post_type_get_tracking_arg($parent_activity->type, 'comment_action_id'); // Use the action string callback for the activity type if (!empty($comment_action_id)) { // Fake a 'new_{post_type}_comment' by cloning the activity object. $object = clone $activity; // Set the type of the activity to be a comment about a post type $object->type = $comment_action_id; // Use the blog ID as the item_id. $object->item_id = $parent_activity->item_id; // Use comment ID as the secondary_item_id. $object->secondary_item_id = $blog_comment_id; // Get the format callback for this activity comment $format_callback = bp_activity_post_type_get_tracking_arg($comment_action_id, 'format_callback'); // now format the activity action using the 'new_{post_type}_comment' action callback if (is_callable($format_callback)) { $retval = call_user_func_array($format_callback, array('', $object)); } } } return $retval; }
/** * Checks if an activity item can be replied to. * * This method merges functionality from {@link bp_activity_can_comment()} and * {@link bp_blogs_disable_activity_commenting()}. This is done because the activity * list table doesn't use a BuddyPress activity loop, which prevents those * functions from working as intended. * * @since 2.0.0 * @since 2.5.0 Include Post type activities types * * @param array $item An array version of the BP_Activity_Activity object. * @return bool $can_comment */ protected function can_comment($item) { $can_comment = bp_activity_type_supports($item['type'], 'comment-reply'); if (!$this->disable_blogforum_comments && bp_is_active('blogs')) { $parent_activity = false; if (bp_activity_type_supports($item['type'], 'post-type-comment-tracking')) { $parent_activity = (object) $item; } elseif ('activity_comment' === $item['type']) { $parent_activity = new BP_Activity_Activity($item['item_id']); } if (isset($parent_activity->type) && bp_activity_post_type_get_tracking_arg($parent_activity->type, 'post_type')) { // Fetch blog post comment depth and if the blog post's comments are open. bp_blogs_setup_activity_loop_globals($parent_activity); $can_comment = bp_blogs_can_comment_reply(true, $item); } } /** * Filters if an activity item can be commented on or not. * * @since 2.0.0 * @since 2.5.0 Add a second parameter to include the activity item into the filter. * * @param bool $can_comment Whether an activity item can be commented on or not. * @param array $item An array version of the BP_Activity_Activity object. */ return apply_filters('bp_activity_list_table_can_comment', $can_comment, $item); }