/**
 * Delete a project
 */
function bp_portfolio_delete_item($project_id)
{
    global $bp;
    $project = new BP_Portfolio_Item(array('id' => $project_id, 'author_id' => bp_loggedin_user_id()));
    $project->get();
    if ($project->query->post->post_author == bp_loggedin_user_id() and $project->query->post->post_type == 'portfolio') {
        // post_parent is the ID of thumbnail
        $thumbnail_id = $project->query->post->post_parent;
        // So delete this project
        if ($project->delete()) {
            if ($thumbnail_id != 0) {
                wp_delete_attachment($thumbnail_id);
            }
            return true;
        }
    }
    return false;
}
<?php

global $bp_portfolio_widget_last_projects_max;
$projects = new BP_Portfolio_Item();
$projects->get(array('posts_per_page' => $bp_portfolio_widget_last_projects_max));
//print_r($projects);
?>

<?php 
foreach ($projects->query->posts as $project) {
    $attachment = wp_get_attachment_image_src($project->post_parent, 'portfolio-widget-thumb');
    if ($attachment != 0) {
        $thumbnail = apply_filters('bp_portfolio_get_item_thumbnail', $attachment[0]);
    } else {
        $thumbnail = apply_filters('bp_portfolio_get_item_thumbnail', BP_PORTFOLIO_PLUGIN_URL . '/templates/' . BP_PORTFOLIO_TEMPLATE . '/img/default.png');
    }
    ?>

    <div class="widget-item-project">
        <div class="widget-item-project-pictures">
            <img src="<?php 
    echo $thumbnail;
    ?>
" width="36px" height="36px" />
        </div>
        <div class="widget-item-project-content">
            <p>
                <a href="<?php 
    echo bp_core_get_user_domain($project->post_author) . BP_PORTFOLIO_SLUG;
    ?>
" title="<?php 
/**
 * Return the total of projects for a particular user
 */
function bp_portfolio_get_user_projects_count($user_id)
{
    if (isset($user_id) && is_int($user_id)) {
        $projects = new BP_Portfolio_Item();
        $projects->get(array('author_id' => $user_id));
        return apply_filters('bp_portfolio_get_user_projects_count', $projects->query->found_posts, $projects);
    } else {
        return 0;
    }
}
/**
 * Sets up and displays the screen output for the sub nav item "portfolio/edit/%d"
 */
function bp_portfolio_screen_edit()
{
    if (bp_is_portfolio_component() and bp_is_current_action('edit') and bp_displayed_user_id() == bp_loggedin_user_id()) {
        if (isset($_POST['edit'])) {
            // Check to see if the project belong to the logged_in user
            global $project;
            $project_id = bp_action_variable();
            $project = new BP_Portfolio_Item();
            $project->get(array('id' => $project_id));
            if ($project->query->post->post_author != bp_loggedin_user_id()) {
                bp_core_add_message(__('There was an error recording the project, please try again', 'bp-portfolio'), 'error');
                bp_core_load_template(apply_filters('bp_portfolio_template_screen_add', BP_PORTFOLIO_TEMPLATE . '/personal'));
            }
            // Check the nonce
            if (!wp_verify_nonce($_POST['_wpnonce'], 'project_form_nonce')) {
                bp_core_add_message(__('There was an error recording the project, please try again', 'bp-portfolio'), 'error');
                bp_core_load_template(apply_filters('bp_portfolio_template_screen_add', BP_PORTFOLIO_TEMPLATE . '/personal'));
            }
            if (empty($_POST['title-input']) or empty($_POST['url-input']) or empty($_POST['description'])) {
                bp_core_add_message(__('All fields are required', 'bp-portfolio'), 'error');
                $project_id = bp_action_variable();
                global $project;
                $project = new BP_Portfolio_Item();
                $project->get(array('id' => $project_id));
            } else {
                // Edit the post
                $posts = array('id' => bp_action_variable(), 'author_id' => bp_loggedin_user_id(), 'title' => $_POST['title-input'], 'description' => $_POST['description'], 'url' => $_POST['url-input']);
                // Is that a capture has been sent ?
                if (isset($_FILES['screenshot-input']) and $_FILES['screenshot-input']['error'] == 0) {
                    $posts['screenshot'] = $_FILES['screenshot-input'];
                }
                if ($item = bp_portfolio_save_item($posts)) {
                    bp_core_add_message(__('Project has been edited', 'bp-portfolio'));
                    bp_core_redirect(bp_core_get_user_domain(bp_loggedin_user_id()) . bp_get_portfolio_slug());
                } else {
                    bp_core_add_message(__('There was an error recording the item, please try again', 'bp-portfolio'), 'error');
                }
            }
        } else {
            // Create a global $project, so template will know that this is the edit page
            if ($project_id = bp_action_variable()) {
                global $project;
                $project_id = bp_action_variable();
                $project = new BP_Portfolio_Item();
                $project->get(array('id' => $project_id));
                if ($project->query->post->post_author == bp_loggedin_user_id()) {
                    bp_core_load_template(apply_filters('bp_portfolio_template_screen_one', BP_PORTFOLIO_TEMPLATE . '/add'));
                }
            }
        }
    }
}
<?php

global $bp_portfolio_widget_last_user_projects_max;
global $bp_portfolio_widget_last_user_projects_user;
$projects = new BP_Portfolio_Item();
$projects->get(array('posts_per_page' => $bp_portfolio_widget_last_user_projects_max, 'author_id' => $bp_portfolio_widget_last_user_projects_user));
$user_diplayname = $bp_portfolio_widget_last_user_projects_user != 0 ? bp_core_get_user_displayname($bp_portfolio_widget_last_user_projects_user) : bp_core_get_user_displayname(bp_displayed_user_id());
$user_domain = $bp_portfolio_widget_last_user_projects_user != 0 ? bp_core_get_user_domain($bp_portfolio_widget_last_user_projects_user) : bp_core_get_user_domain(bp_displayed_user_id());
?>

<?php 
foreach ($projects->query->posts as $project) {
    $attachment = wp_get_attachment_image_src($project->post_parent, 'portfolio-widget-thumb');
    if ($attachment != 0) {
        $thumbnail = apply_filters('bp_portfolio_get_item_thumbnail', $attachment[0]);
    } else {
        $thumbnail = apply_filters('bp_portfolio_get_item_thumbnail', BP_PORTFOLIO_PLUGIN_URL . '/templates/' . BP_PORTFOLIO_TEMPLATE . '/img/default.png');
    }
    ?>

    <div class="widget-item-project">
        <div class="widget-item-project-pictures">
            <img src="<?php 
    echo $thumbnail;
    ?>
" width="36px" height="36px" />
        </div>
        <div class="widget-item-project-content">
            <p>
                <a href="<?php 
    echo bp_core_get_user_domain($project->post_author) . BP_PORTFOLIO_SLUG;