Ejemplo n.º 1
0
 /**
  * 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 BuddyPress (2.0.0)
  *
  * @param array $item An array version of the BP_Activity_Activity object.
  *
  * @return bool
  */
 protected function can_comment($item)
 {
     $can_comment = true;
     if ($this->disable_blogforum_comments) {
         switch ($item['type']) {
             case 'new_blog_post':
             case 'new_blog_comment':
             case 'new_forum_topic':
             case 'new_forum_post':
                 $can_comment = false;
                 break;
         }
         // activity comments supported
     } else {
         // activity comment
         if ('activity_comment' == $item['type']) {
             // blogs
             if (bp_is_active('blogs')) {
                 // grab the parent activity entry
                 $parent_activity = new BP_Activity_Activity($item['item_id']);
                 // fetch blog post comment depth and if the blog post's comments are open
                 bp_blogs_setup_activity_loop_globals($parent_activity);
                 // check if the activity item can be replied to
                 if (false === bp_blogs_can_comment_reply(true, $item)) {
                     $can_comment = false;
                 }
             }
             // blog post
         } elseif ('new_blog_post' == $item['type']) {
             if (bp_is_active('blogs')) {
                 bp_blogs_setup_activity_loop_globals((object) $item);
                 if (empty(buddypress()->blogs->allow_comments[$item['id']])) {
                     $can_comment = false;
                 }
             }
         }
     }
     /**
      * Filters if an activity item can be commented on or not.
      *
      * @since BuddyPress (2.0.0)
      *
      * @param bool $can_comment Whether an activity item can be commented on or not.
      */
     return apply_filters('bp_activity_list_table_can_comment', $can_comment);
 }
/**
 * 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;
}
Ejemplo n.º 3
0
/**
 * 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 BuddyPress (2.0.0)
 *
 * @param bool $retval Is activity commenting enabled for this activity entry?
 * @return bool
 */
function bp_blogs_disable_activity_commenting( $retval ) {
	// if activity commenting is disabled, return current value
	if ( bp_disable_blogforum_comments() ) {
		return $retval;
	}

	// activity commenting is enabled for blog posts
	switch ( bp_get_activity_action_name() ) {

		// we still have to disable activity commenting for 'new_blog_comment' items
		// commenting should only be done on the parent 'new_blog_post' item
		case 'new_blog_comment' :
			$retval = false;

			break;

		// check if commenting is disabled for the WP blog post
		// we should extrapolate this and automate this for plugins... or not
		case 'new_blog_post' :
			global $activities_template;

			// 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;
			}

			break;
	}

	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);
 }