/** * Set the component's navigation */ public function setup_nav() { // Main navigation $main_nav = array('name' => sprintf(__('Projects <span>%s</span>', 'bp-portfolio'), bp_portfolio_get_user_projects_count(bp_displayed_user_id())), 'slug' => bp_get_portfolio_slug(), 'position' => 80, 'screen_function' => 'bp_portfolio_screen_personal', 'default_subnav_slug' => 'personal'); $portfolio_link = trailingslashit(bp_loggedin_user_domain() . bp_get_portfolio_slug()); // Add a few subnav items under the main Portfolio tab $sub_nav[] = array('name' => __('Personal', 'bp-portfolio'), 'slug' => 'personal', 'parent_url' => $portfolio_link, 'parent_slug' => bp_get_portfolio_slug(), 'screen_function' => 'bp_portfolio_screen_personal', 'position' => 10); if (bp_displayed_user_id() == bp_loggedin_user_id()) { // Add a few subnav items under the main Portfolio tab $sub_nav[] = array('name' => __('Add', 'bp-portfolio'), 'slug' => 'add', 'parent_url' => $portfolio_link, 'parent_slug' => bp_get_portfolio_slug(), 'screen_function' => 'bp_portfolio_screen_add', 'position' => 20); } parent::setup_nav($main_nav, $sub_nav); }
/** * Delte an item */ function bp_portfolio_item_delete() { if (bp_is_portfolio_component() and bp_is_current_action('delete') and bp_displayed_user_id() == bp_loggedin_user_id()) { if ($project_id = bp_action_variable() and wp_verify_nonce($_REQUEST['_wpnonce'], 'delete_project')) { if (bp_portfolio_delete_item($project_id)) { bp_core_add_message(__('Project deleted !', 'bp-portfolio')); } else { bp_core_add_message(__('An error occured, please try again.', 'bp-portfolio'), 'error'); } } else { bp_core_add_message(__('An error occured, please try again.', 'bp-portfolio'), 'error'); } bp_core_redirect(bp_core_get_user_domain(bp_loggedin_user_id()) . bp_get_portfolio_slug()); } }
<h3> <?php bp_portfolio_item_title(); ?> <?php if (bp_is_my_profile()) { ?> <div class="item-project-content-meta"> <span class="edit"><a href="<?php echo bp_core_get_user_domain(bp_loggedin_user_id()) . bp_get_portfolio_slug() . '/edit/' . get_the_ID(); ?> ">Edit</a></span> | <span class="delete"><a href="<?php echo wp_nonce_url(bp_core_get_user_domain(bp_loggedin_user_id()) . bp_get_portfolio_slug() . '/delete/' . get_the_ID(), 'delete_project'); ?> " onclick="javascript:return confirm('<?php _e('Are you sure ?', 'bp-portfolio'); ?> ')"><?php _e('Delete', 'bp-portfolio'); ?> </a</span> </div> <?php } ?> </h3> <span><a href="<?php bp_portfolio_item_url();
/** * 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')); } } } } }
/** * Returns the form action for Portfolio HTML forms */ function bp_get_portfolio_form_action($action) { return apply_filters('bp_get_portfolio_form_action', trailingslashit(bp_loggedin_user_domain() . bp_get_portfolio_slug() . '/' . $action . '/' . bp_action_variable(0))); }