/**
 * Deletes a group forum topic and also any corresponding activity items.
 *
 * Uses the bundled version of bbPress packaged with BuddyPress.
 *
 * @package BuddyPress
 *
 * @uses bp_activity_delete() to delete corresponding activity items
 * @uses bp_forums_get_topic_posts() to get the child posts
 * @uses bp_forums_delete_topic() to do the deletion itself
 * @param int $topic_id The id of the topic to be deleted
 * @return bool True if the delete routine went through properly
 *
 * @since BuddyPress (1.1)
 */
function groups_delete_group_forum_topic($topic_id)
{
    global $bp;
    // Before deleting the thread, get the post ids so that their activity items can be deleted
    $posts = bp_forums_get_topic_posts(array('topic_id' => $topic_id, 'per_page' => -1));
    if (bp_forums_delete_topic(array('topic_id' => $topic_id))) {
        do_action('groups_before_delete_group_forum_topic', $topic_id);
        // Delete the corresponding activity stream items
        if (bp_is_active('activity')) {
            // The activity item for the initial topic
            bp_activity_delete(array('item_id' => bp_get_current_group_id(), 'secondary_item_id' => $topic_id, 'component' => $bp->groups->id, 'type' => 'new_forum_topic'));
            // The activity item for each post
            foreach ((array) $posts as $post) {
                bp_activity_delete(array('item_id' => bp_get_current_group_id(), 'secondary_item_id' => $post->post_id, 'component' => $bp->groups->id, 'type' => 'new_forum_post'));
            }
        }
        do_action('groups_delete_group_forum_topic', $topic_id);
        return true;
    }
    return false;
}
Пример #2
0
/**
 * Delete a group forum topic and also any corresponding activity items.
 *
 * Uses the bundled version of bbPress packaged with BuddyPress.
 *
 * @since BuddyPress (1.1.0)
 *
 * @param int $topic_id The ID of the topic to be deleted.
 *
 * @return bool True if the delete routine went through properly.
 */
function groups_delete_group_forum_topic($topic_id)
{
    $bp = buddypress();
    // Before deleting the thread, get the post ids so that their activity items can be deleted
    $posts = bp_forums_get_topic_posts(array('topic_id' => $topic_id, 'per_page' => -1));
    $action = bp_forums_delete_topic(array('topic_id' => $topic_id));
    if (!empty($action)) {
        /**
         * Fires before the deletion of a group forum topic.
         *
         * @since BuddyPress (1.2.9)
         *
         * @param int $topic_id ID of the topic to be deleted.
         */
        do_action('groups_before_delete_group_forum_topic', $topic_id);
        // Delete the corresponding activity stream items
        if (bp_is_active('activity')) {
            // The activity item for the initial topic
            bp_activity_delete(array('item_id' => bp_get_current_group_id(), 'secondary_item_id' => $topic_id, 'component' => $bp->groups->id, 'type' => 'new_forum_topic'));
            // The activity item for each post
            foreach ((array) $posts as $post) {
                bp_activity_delete(array('item_id' => bp_get_current_group_id(), 'secondary_item_id' => $post->post_id, 'component' => $bp->groups->id, 'type' => 'new_forum_post'));
            }
        }
        /**
         * Fires after the deletion of a group forum topic.
         *
         * @since BuddyPress (1.1.0)
         *
         * @param int $topic_id ID of the topic that was deleted.
         */
        do_action('groups_delete_group_forum_topic', $topic_id);
    }
    return (bool) $action;
}
Пример #3
0
function groups_delete_group_forum_topic( $topic_id ) {
	global $bp;

	if ( bp_forums_delete_topic( array( 'topic_id' => $topic_id ) ) ) {
		/* Delete the activity stream item */
		if ( function_exists( 'bp_activity_delete' ) ) {
			bp_activity_delete( array( 'item_id' => $bp->groups->current_group->id, 'secondary_item_id' => $topic_id, 'component' => $bp->groups->id, 'type' => 'new_forum_topic' ) );
		}

		do_action( 'groups_delete_group_forum_topic', $topic_id );

		return true;
	}

	return false;
}