/** * 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); }
/** * Disable activity commenting for blog posts based on certain criteria. * * If activity commenting is enabled for blog posts, we still need to disable * commenting if: * - comments are disabled for the WP blog post from the admin dashboard * - the WP blog post is supposed to be automatically closed from comments * based on a certain age * - the activity entry is a 'new_blog_comment' type * * @since 2.0.0 * * @param bool $retval Is activity commenting enabled for this activity entry. * @return bool */ function bp_blogs_disable_activity_commenting($retval) { global $activities_template; // If activity commenting is disabled, return current value. if (bp_disable_blogforum_comments() || !isset($activities_template->in_the_loop)) { return $retval; } $type = bp_get_activity_type(); // It's a post type supporting comment tracking. if (bp_activity_type_supports($type, 'post-type-comment-tracking')) { // The activity type is supporting comments or replies if (bp_activity_type_supports($type, 'post-type-comment-reply')) { // Setup some globals we'll need to reference later. bp_blogs_setup_activity_loop_globals($activities_template->activity); // If comments are closed for the WP blog post, we should disable // activity comments for this activity entry. if (empty(buddypress()->blogs->allow_comments[bp_get_activity_id()])) { $retval = false; } // The activity type does not support comments or replies } else { $retval = false; } } return $retval; }
/** * Determine if a comment can be made on an activity item. * * @since 1.2.0 * * @global object $activities_template {@link BP_Activity_Template} * * @return bool $can_comment True if item can receive comments. */ function bp_activity_can_comment() { global $activities_template; $bp = buddypress(); // Determine ability to comment based on activity type name. $activity_type = bp_get_activity_type(); // Get the 'comment-reply' support for the current activity type. $can_comment = bp_activity_type_supports($activity_type, 'comment-reply'); // Neutralize activity_comment. if ('activity_comment' === $activity_type) { $can_comment = false; } /** * Filters whether a comment can be made on an activity item. * * @since 1.5.0 * @since 2.5.0 Use $activity_type instead of $activity_name for the second parameter. * * @param bool $can_comment Status on if activity can be commented on. * @param string $activity_type Current activity type being checked on. */ return apply_filters('bp_activity_can_comment', $can_comment, $activity_type); }