/**
 * Deletes associated media entry and its files upon deletion of an activity.
 * 
 * @since BP Media 2.0
 */
function bp_media_delete_activity_handler($activity_id, $user)
{
    global $bp_media_count;
    bp_media_init_count(bp_loggedin_user_id());
    $post_id = bp_activity_get_meta($activity_id, 'bp_media_parent_post');
    $type = get_post_meta($post_id, 'bp_media_type', true);
    switch ($type) {
        case 'image':
            $bp_media_count['images'] = intval($bp_media_count['images']) - 1;
            break;
        case 'video':
            $bp_media_count['videos'] = intval($bp_media_count['videos']) - 1;
            break;
        case 'audio':
            $bp_media_count['audio'] = intval($bp_media_count['audio']) - 1;
            break;
    }
    $attachment_id = get_post_meta($post_id, 'bp_media_child_attachment', true);
    wp_delete_attachment($attachment_id, true);
    wp_delete_post($post_id, true);
    bp_update_user_meta(bp_loggedin_user_id(), 'bp_media_count', $bp_media_count);
}
	function delete_media(){
		global $bp_media_count;
		bp_media_init_count($this->owner);
		switch ($this->type) {
			case 'image':
				$bp_media_count['images'] = intval($bp_media_count['images']) - 1;
				break;
			case 'video':
				$bp_media_count['videos'] = intval($bp_media_count['videos']) - 1;
				break;
			case 'audio':
				$bp_media_count['audio'] = intval($bp_media_count['audio']) - 1;
				break;
		}
		
		wp_delete_attachment($this->attachment_id);
//		$activity_id = get_post_meta($post_id, 'bp_media_child_activity', true);
//		if($activity_id)
//			bp_activity_delete_by_activity_id($activity_id);
		wp_delete_post($this->id);
		bp_update_user_meta($this->owner, 'bp_media_count', $bp_media_count);
	}
function bp_media_delete_attachment_handler($attachment_id)
{
    if (get_post_meta($attachment_id, 'bp-media-key')) {
        do_action('bp_media_before_delete_media', $attachment_id);
        global $bp_media_count;
        $attachment = get_post($attachment_id);
        preg_match_all('/audio|video|image/i', $attachment->post_mime_type, $result);
        if (isset($result[0][0])) {
            $type = $result[0][0];
        } else {
            return false;
        }
        bp_media_init_count($attachment->post_author);
        switch ($type) {
            case 'image':
                $images = intval($bp_media_count['images']) ? intval($bp_media_count['images']) : 0;
                $bp_media_count['images'] = $images - 1;
                break;
            case 'audio':
                $bp_media_count['audio'] = intval($bp_media_count['audio']) - 1;
                break;
            case 'video':
                $bp_media_count['videos'] = intval($bp_media_count['videos']) - 1;
                break;
            default:
                return false;
        }
        bp_update_user_meta($attachment->post_author, 'bp_media_count', $bp_media_count);
        do_action('bp_media_after_delete_media', $attachment_id);
        return true;
    }
}
 /**
  * Deletes the Media Entry
  */
 function delete_media()
 {
     do_action('bp_media_before_delete_media', $this->id);
     global $bp_media_count;
     bp_media_init_count($this->owner);
     switch ($this->type) {
         case 'image':
             $bp_media_count['images'] = intval($bp_media_count['images']) - 1;
             break;
         case 'video':
             $bp_media_count['videos'] = intval($bp_media_count['videos']) - 1;
             break;
         case 'audio':
             $bp_media_count['audio'] = intval($bp_media_count['audio']) - 1;
             break;
     }
     wp_delete_attachment($this->id, true);
     bp_update_user_meta($this->owner, 'bp_media_count', $bp_media_count);
     do_action('bp_media_after_delete_media', $this->id);
 }
 /**
  * Deletes the album and all associated attachments
  *
  * @since BP Media 2.2
  */
 function delete_album()
 {
     do_action('bp_media_before_delete_album', $this);
     foreach ($this->media_entries as $entry) {
         wp_delete_attachment($entry->ID, true);
     }
     $author_id = $this->owner;
     bp_media_init_count($author_id);
     wp_delete_post($this->id, true);
     global $bp_media_count;
     $bp_media_count['albums'] = intval(isset($bp_media_count['albums']) ? $bp_media_count['albums'] : 0) - 1;
     bp_update_user_meta($author_id, 'bp_media_count', $bp_media_count);
     do_action('bp_media_after_delete_album', $this);
 }