function mp_group_nav() { if (!bp_is_group()) { return; } $component = 'groups'; $component_id = groups_get_current_group()->id; if (mpp_user_can_create_gallery($component, $component_id)) { echo sprintf("<li><a href='%s'>%s</a></li>", mpp_get_gallery_base_url($component, $component_id), __('All Galleries', 'mediapress')); echo sprintf("<li><a href='%s'>%s</a></li>", mpp_get_gallery_create_url($component, $component_id), __('Create Gallery', 'mediapress')); } }
/** * Set up the Toolbar. * * @param array $wp_admin_nav See {BP_Component::setup_admin_bar()} * for details. */ public function setup_admin_bar($wp_admin_nav = array()) { $bp = buddypress(); // Menus for logged in user if the members gallery is enabled if (is_user_logged_in() && mpp_is_enabled('members', bp_loggedin_user_id())) { $component = 'members'; $component_id = get_current_user_id(); $gallery_link = trailingslashit(mpp_get_gallery_base_url($component, $component_id)); $title = __('Gallery', 'mediapress'); $my_galleries = __('My Gallery', 'mediapress'); $create = __('Create', 'mediapress'); // Add main mediapress menu $wp_admin_nav[] = array('parent' => $bp->my_account_menu_id, 'id' => 'my-account-' . $this->id, 'title' => $title, 'href' => trailingslashit($gallery_link)); // Add main mediapress menu $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-my-galleries', 'title' => $my_galleries, 'href' => trailingslashit($gallery_link)); if (mpp_user_can_create_gallery($component, $component_id)) { $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-create', 'title' => $create, 'href' => mpp_get_gallery_create_url($component, $component_id)); } } parent::setup_admin_bar($wp_admin_nav); }
/** * Handles Gallery creation on the front end in non ajax case * * @return type */ function mpp_action_create_gallery() { //allow gallery to be created from anywhere //the form must have mpp-action set and It should be set to 'create-gallery' if (empty($_POST['mpp-action']) || $_POST['mpp-action'] != 'create-gallery') { return; } $referer = wp_get_referer(); //if we are here, It is gallery create action if (!wp_verify_nonce($_POST['mpp-nonce'], 'mpp-create-gallery')) { //add error message and return back to the old page mpp_add_feedback(__('Action not authorized!', 'mediapress'), 'error'); if ($referer) { mpp_redirect($referer); } return; } //update it to allow passing component/id from the form $component = mpp_get_current_component(); $component_id = mpp_get_current_component_id(); //check for permission //we may want to allow passing of component from the form in future! if (!mpp_user_can_create_gallery($component, $component_id)) { mpp_add_feedback(__("You don't have permission to create gallery!", 'mediapress'), 'error'); if ($referer) { mpp_redirect($referer); } return; } //if we are here, validate the data and let us see if we can create $title = $_POST['mpp-gallery-title']; $description = $_POST['mpp-gallery-description']; $type = $_POST['mpp-gallery-type']; $status = $_POST['mpp-gallery-status']; $errors = array(); if (!mpp_is_active_status($status)) { $errors['status'] = __('Invalid Gallery status!', 'mediapress'); } if (!mpp_is_active_type($type)) { $errors['type'] = __('Invalid gallery type!', 'mediapress'); } //check for current component if (!mpp_is_active_component($component)) { $errors['component'] = __('Invalid gallery component!', 'mediapress'); } if (empty($title)) { $errors['title'] = __('Title can not be empty', 'mediapress'); } //give opportunity to other plugins to add their own validation errors $validation_errors = apply_filters('mpp-create-gallery-field-validation', $errors, $_POST); if (!empty($validation_errors)) { //let us add the validation error and return back to the earlier page $message = join('\\r\\n', $validation_errors); mpp_add_feedback($message, 'error'); if ($referer) { mpp_redirect($referer); } return; } //let us create gallery $gallery_id = mpp_create_gallery(array('title' => $title, 'description' => $description, 'type' => $type, 'status' => $status, 'creator_id' => get_current_user_id(), 'component' => $component, 'component_id' => $component_id)); if (!$gallery_id) { mpp_add_feedback(__('Unable to create gallery!', 'mediapress'), 'error'); if ($referer) { mpp_redirect($referer); } return; } //if we are here, the gallery was created successfully, //let us redirect to the gallery_slug/manage/upload page $redirect_url = mpp_get_gallery_add_media_url($gallery_id); mpp_add_feedback(__('Gallery created successfully!', 'mediapress')); mpp_redirect($redirect_url); }
<?php // Exit if the file is accessed directly over web if (!defined('ABSPATH')) { exit; } /** * Create Gallery shortcode * You can overwide it in yourtheme/mediapress/default/shortcodes/create-gallery.php * */ ?> <div id="mpp-create-gallery-form-wrapper" class="mpp-container" > <?php if (mpp_user_can_create_gallery(mpp_get_current_component(), mpp_get_current_component_id())) { ?> <form method="post" action="" id="mpp-create-gallery-form" class="mpp-form mpp-form-stacked mpp-create-gallery-form"> <?php $title = $description = $status = $type = $component = ''; if (!empty($_POST['mpp-gallery-title'])) { $title = $_POST['mpp-gallery-title']; } if (!empty($_POST['mpp-gallery-description'])) { $description = $_POST['mpp-gallery-description']; } if (!empty($_POST['mpp-gallery-status'])) { $status = $_POST['mpp-gallery-status']; } if (!empty($_POST['mpp-gallery-type'])) {
/** * Display a create Gallery Button * * @return string */ function mpp_gallery_create_button() { //check whether to display the link or not $component = mpp_get_current_component(); $component_id = mpp_get_current_component_id(); if (!mpp_user_can_create_gallery($component, $component_id)) { return false; } ?> <a id="add_new_gallery_link" href="<?php mpp_gallery_create_url($component, $component_id); ?> ">Add Gallery</a> <?php }