/**
 * Format activity action strings for custom post types comments.
 *
 * @since 2.5.0
 *
 * @param string $action   Static activity action.
 * @param object $activity Activity data object.
 *
 * @return string
 */
function bp_activity_format_activity_action_custom_post_type_comment($action, $activity)
{
    $bp = buddypress();
    // Fetch all the tracked post types once.
    if (empty($bp->activity->track)) {
        $bp->activity->track = bp_activity_get_post_types_tracking_args();
    }
    if (empty($activity->type) || empty($bp->activity->track[$activity->type])) {
        return $action;
    }
    $user_link = bp_core_get_userlink($activity->user_id);
    if (is_multisite()) {
        $blog_link = '<a href="' . esc_url(get_home_url($activity->item_id)) . '">' . get_blog_option($activity->item_id, 'blogname') . '</a>';
        if (!empty($bp->activity->track[$activity->type]->new_post_type_comment_action_ms)) {
            $action = sprintf($bp->activity->track[$activity->type]->new_post_type_comment_action_ms, $user_link, $activity->primary_link, $blog_link);
        } else {
            $action = sprintf(_x('%1$s commented on the <a href="%2$s">item</a>, on the site %3$s', 'Activity Custom Post Type comment action', 'buddypress'), $user_link, $activity->primary_link, $blog_link);
        }
    } else {
        if (!empty($bp->activity->track[$activity->type]->new_post_type_comment_action)) {
            $action = sprintf($bp->activity->track[$activity->type]->new_post_type_comment_action, $user_link, $activity->primary_link);
        } else {
            $action = sprintf(_x('%1$s commented on the <a href="%2$s">item</a>', 'Activity Custom Post Type post comment action', 'buddypress'), $user_link, $activity->primary_link);
        }
    }
    /**
     * Filters the formatted custom post type activity comment action string.
     *
     * @since 2.5.0
     *
     * @param string               $action   Activity action string value.
     * @param BP_Activity_Activity $activity Activity item object.
     */
    return apply_filters('bp_activity_custom_post_type_comment_action', $action, $activity);
}
/**
 * Format activity action strings for custom post types.
 *
 * @since BuddyPress (2.2.0)
 *
 * @param string $action   Static activity action.
 * @param object $activity Activity data object.
 * @return string
 */
function bp_activity_format_activity_action_custom_post_type_post( $action, $activity ) {
	$bp = buddypress();

	// Fetch all the tracked post types once.
	if ( empty( $bp->activity->track ) ) {
		$bp->activity->track = bp_activity_get_post_types_tracking_args();
	}

	if ( empty( $activity->type ) || empty( $bp->activity->track[ $activity->type ] ) ) {
		return $action;
	}

	$user_link = bp_core_get_userlink( $activity->user_id );
	$blog_url  = get_home_url( $activity->item_id );

	if ( empty( $activity->post_url ) ) {
		$post_url = add_query_arg( 'p', $activity->secondary_item_id, trailingslashit( $blog_url ) );
	} else {
		$post_url = $activity->post_url;
	}

	if ( is_multisite() ) {
		$blog_link = '<a href="' . $blog_url . '">' . get_blog_option( $activity->item_id, 'blogname' ) . '</a>';

		if ( ! empty( $bp->activity->track[ $activity->type ]->new_post_type_action_ms ) ) {
			$action = sprintf( $bp->activity->track[ $activity->type ]->new_post_type_action_ms, $user_link, $post_url, $blog_link );
		} else {
			$action = sprintf( _x( '%1$s wrote a new <a href="%2$s">item</a>, on the site %3$s', 'Activity Custom Post Type post action', 'buddypress' ), $user_link, $post_url, $blog_link );
		}
	} else {
		if ( ! empty( $bp->activity->track[ $activity->type ]->new_post_type_action ) ) {
			$action = sprintf( $bp->activity->track[ $activity->type ]->new_post_type_action, $user_link, $post_url );
		} else {
			$action = sprintf( _x( '%1$s wrote a new <a href="%2$s">item</a>', 'Activity Custom Post Type post action', 'buddypress' ), $user_link, $post_url );
		}
	}

	/**
	 * Filters the formatted custom post type activity post action string.
	 *
	 * @since BuddyPress (2.2.0)
	 *
	 * @param string               $action Activity action string value.
	 * @param BP_Activity_Activity $activity Activity item object.
	 */
	return apply_filters( 'bp_activity_custom_post_type_post_action', $action, $activity );
}
Пример #3
0
/**
 * Determine if a comment can be made on an activity item.
 *
 * @since BuddyPress (1.2.0)
 *
 * @global object $activities_template {@link BP_Activity_Template}
 * @uses bp_get_activity_action_name()
 * @uses apply_filters() To call the 'bp_activity_can_comment' hook.
 *
 * @return bool $can_comment True if item can receive comments.
 */
function bp_activity_can_comment()
{
    global $activities_template;
    $bp = buddypress();
    // Assume activity can be commented on
    $can_comment = true;
    // Determine ability to comment based on activity action name
    $activity_action = bp_get_activity_action_name();
    $turn_off = 0;
    if (!empty($activities_template->disable_blogforum_replies)) {
        $turn_off = 1;
    }
    $maybe_turn_off = array_fill_keys(array('new_blog_post', 'new_blog_comment', 'new_forum_topic', 'new_forum_post'), $turn_off);
    $maybe_turn_off['activity_comment'] = 1;
    // Fetch all the tracked post types once.
    if (empty($bp->activity->track)) {
        $bp->activity->track = bp_activity_get_post_types_tracking_args();
    }
    foreach ($bp->activity->track as $action => $tracking_args) {
        if (empty($tracking_args->activity_comment)) {
            $maybe_turn_off[$action] = $turn_off;
        }
    }
    $can_comment = empty($maybe_turn_off[$activity_action]);
    /**
     * Filters whether a comment can be made on an activity item.
     *
     * @since BuddyPress (1.5.0)
     *
     * @param bool   $can_comment Status on if activity can be commented on.
     * @param string $activity_action Current activity action being checked on.
     */
    return apply_filters('bp_activity_can_comment', $can_comment, $activity_action);
}
Пример #4
0
 /**
  * @group bp_activity_can_comment
  */
 public function test_bp_activity_can_comment_post_type_activity()
 {
     global $activities_template;
     $bp = buddypress();
     $reset_activities_template = $activities_template;
     $reset_activity_track = $bp->activity->track;
     $activities_template = new stdClass();
     $activities_template->disable_blogforum_replies = true;
     register_post_type('foo', array('label' => 'foo', 'public' => true, 'supports' => array('buddypress-activity')));
     $bp->activity->track = bp_activity_get_post_types_tracking_args();
     $activities_template->activity = (object) array('type' => 'new_foo');
     $this->assertTrue(bp_activity_can_comment(), 'If post type does not support comments, a post type activity can be commented');
     add_post_type_support('foo', 'comments');
     $bp->activity->track = bp_activity_get_post_types_tracking_args();
     $this->assertFalse(bp_activity_can_comment(), 'If post type support comments, a post type activity cannot be commented');
     $bp_activity_support = (array) $bp->activity->track['new_foo'];
     $bp_activity_support['activity_comment'] = true;
     bp_activity_set_post_type_tracking_args('foo', $bp_activity_support);
     $bp->activity->track = bp_activity_get_post_types_tracking_args();
     $this->assertTrue(bp_activity_can_comment(), 'If post type supports activity comments, a post type activity can be commented');
     // clean up!
     $activities_template = $reset_activities_template;
     $bp->activity->track = $reset_activity_track;
 }