/** * Protect access to single groups. * * @since BuddyPress (2.1.0) */ function bp_groups_group_access_protection() { if (!bp_is_group()) { return; } $current_group = groups_get_current_group(); $user_has_access = $current_group->user_has_access; $no_access_args = array(); if (!$user_has_access && 'hidden' !== $current_group->status) { // Always allow access to home and request-membership if (bp_is_current_action('home') || bp_is_current_action('request-membership')) { $user_has_access = true; // User doesn't have access, so set up redirect args } else { if (is_user_logged_in()) { $no_access_args = array('message' => __('You do not have access to this group.', 'buddypress'), 'root' => bp_get_group_permalink($current_group) . 'home/', 'redirect' => false); } } } // Protect the admin tab from non-admins if (bp_is_current_action('admin') && !bp_is_item_admin()) { $user_has_access = false; $no_access_args = array('message' => __('You are not an admin of this group.', 'buddypress'), 'root' => bp_get_group_permalink($current_group), 'redirect' => false); } /** * Allow plugins to filter whether the current user has access to this group content. * * Note that if a plugin sets $user_has_access to false, it may also * want to change the $no_access_args, to avoid problems such as * logged-in users being redirected to wp-login.php. * * @since BuddyPress (2.1.0) * * @param bool $user_has_access True if the user has access to the * content, otherwise false. * @param array $no_access_args Arguments to be passed to * bp_core_no_access() in case of no access. Note that this * value is passed by reference, so it can be modified by the * filter callback. */ $user_has_access = apply_filters_ref_array('bp_group_user_has_access', array($user_has_access, &$no_access_args)); // If user has access, we return rather than redirect if ($user_has_access) { return; } // Hidden groups should return a 404 for non-members. // Unset the current group so that you're not redirected // to the default group tab if ('hidden' == $current_group->status) { buddypress()->groups->current_group = 0; buddypress()->is_single_item = false; bp_do_404(); return; } else { bp_core_no_access($no_access_args); } }
/** * Add menu items to the BuddyBar. * * @since BuddyPress (1.0.0) * * @global BuddyPress $bp */ function bp_groups_adminbar_admin_menu() { global $bp; if (empty($bp->groups->current_group)) { return false; } // Only group admins and site admins can see this menu if (!current_user_can('edit_users') && !bp_current_user_can('bp_moderate') && !bp_is_item_admin()) { return false; } ?> <li id="bp-adminbar-adminoptions-menu"> <a href="<?php bp_groups_action_link('admin'); ?> "><?php _e('Admin Options', 'buddypress'); ?> </a> <ul> <li><a href="<?php bp_groups_action_link('admin/edit-details'); ?> "><?php _e('Edit Details', 'buddypress'); ?> </a></li> <li><a href="<?php bp_groups_action_link('admin/group-settings'); ?> "><?php _e('Group Settings', 'buddypress'); ?> </a></li> <?php if (!(int) bp_get_option('bp-disable-avatar-uploads')) { ?> <li><a href="<?php bp_groups_action_link('admin/group-avatar'); ?> "><?php _e('Group Avatar', 'buddypress'); ?> </a></li> <?php } ?> <?php if (bp_is_active('friends')) { ?> <li><a href="<?php bp_groups_action_link('send-invites'); ?> "><?php _e('Manage Invitations', 'buddypress'); ?> </a></li> <?php } ?> <li><a href="<?php bp_groups_action_link('admin/manage-members'); ?> "><?php _e('Manage Members', 'buddypress'); ?> </a></li> <?php if ($bp->groups->current_group->status == 'private') { ?> <li><a href="<?php bp_groups_action_link('admin/membership-requests'); ?> "><?php _e('Membership Requests', 'buddypress'); ?> </a></li> <?php } ?> <li><a class="confirm" href="<?php echo wp_nonce_url(bp_get_group_permalink($bp->groups->current_group) . 'admin/delete-group/', 'groups_delete_group'); ?> &delete-group-button=1&delete-group-understand=1"><?php _e("Delete Group", 'buddypress'); ?> </a></li> <?php do_action('bp_groups_adminbar_admin_menu'); ?> </ul> </li> <?php }
function groups_remove_member($user_id, $group_id) { if (!bp_is_item_admin()) { return false; } $member = new BP_Groups_Member($user_id, $group_id); do_action('groups_remove_member', $group_id, $user_id); return $member->remove(); }
/** * Add topic row action HTML when viewing group forum admin * * @since bbPress (r3653) * @uses bp_is_item_admin() * @uses bbp_get_forum_id() */ public function topic_row_actions() { // Only admins can take actions on forums if (is_super_admin() || current_user_can('moderate') || bp_is_item_admin() || bp_is_item_mod()) { ?> <div class="row-actions"> <?php echo 'Edit | View | Trash | Close | Stick (To Front) | Spam'; ?> </div> <?php } }
/** * Remove a member from a group. * * @param int $user_id ID of the user. * @param int $group_id ID of the group. * * @return bool True on success, false on failure. */ function groups_remove_member($user_id, $group_id) { if (!bp_is_item_admin()) { // bp_is_item_admin may not be set if this function is called outside of group context. // Site admins and group admins can remove a member from a group. // A member may also request to remove herself from a group. if (!current_user_can('bp_moderate') && !groups_is_user_admin(bp_loggedin_user_id(), $group_id) && $user_id != bp_loggedin_user_id()) { return false; } } $member = new BP_Groups_Member($user_id, $group_id); /** * Fires before the removal of a member from a group. * * @since 1.2.6 * * @param int $group_id ID of the group being removed from. * @param int $user_id ID of the user being removed. */ do_action('groups_remove_member', $group_id, $user_id); return $member->remove(); }
/** * Return the admin links for the current topic in the loop. * * @param array $args { * @type string $seperator The character to use when separating * links. Default: '|'. * } * @return HTML string containing the admin links for the current topic. */ function bp_get_the_topic_admin_links($args = '') { global $forum_template; $defaults = array('seperator' => '|'); $r = wp_parse_args($args, $defaults); extract($r, EXTR_SKIP); $links[] = '<a href="' . wp_nonce_url(bp_get_the_topic_permalink() . 'edit', 'bp_forums_edit_topic') . '">' . __('Edit Topic', 'buddypress') . '</a>'; if (bp_is_item_admin() || bp_is_item_mod() || bp_current_user_can('bp_moderate')) { if (0 == (int) $forum_template->topic->topic_sticky) { $links[] = '<a href="' . wp_nonce_url(bp_get_the_topic_permalink() . 'stick', 'bp_forums_stick_topic') . '">' . __('Sticky Topic', 'buddypress') . '</a>'; } else { $links[] = '<a href="' . wp_nonce_url(bp_get_the_topic_permalink() . 'unstick', 'bp_forums_unstick_topic') . '">' . __('Un-stick Topic', 'buddypress') . '</a>'; } if (0 == (int) $forum_template->topic->topic_open) { $links[] = '<a href="' . wp_nonce_url(bp_get_the_topic_permalink() . 'open', 'bp_forums_open_topic') . '">' . __('Open Topic', 'buddypress') . '</a>'; } else { $links[] = '<a href="' . wp_nonce_url(bp_get_the_topic_permalink() . 'close', 'bp_forums_close_topic') . '">' . __('Close Topic', 'buddypress') . '</a>'; } $links[] = '<a class="confirm" id="topic-delete-link" href="' . wp_nonce_url(bp_get_the_topic_permalink() . 'delete', 'bp_forums_delete_topic') . '">' . __('Delete Topic', 'buddypress') . '</a>'; } return implode(' ' . $seperator . ' ', (array) $links); }
/** * Check the current user's capability to edit an avatar for a given object. * * @since 2.3.0 * * @param string $capability The capability to check. * @param array $args An array containing the item_id and the object to check. * * @return bool */ function bp_attachments_current_user_can($capability, $args = array()) { $can = false; if ('edit_avatar' === $capability || 'edit_cover_image' === $capability) { /** * Needed avatar arguments are set. */ if (isset($args['item_id']) && isset($args['object'])) { // Group profile photo if (bp_is_active('groups') && 'group' === $args['object']) { if (bp_is_group_create()) { $can = (bool) groups_is_user_creator(bp_loggedin_user_id(), $args['item_id']) || bp_current_user_can('bp_moderate'); } else { $can = (bool) groups_is_user_admin(bp_loggedin_user_id(), $args['item_id']) || bp_current_user_can('bp_moderate'); } // User profile photo } elseif (bp_is_active('xprofile') && 'user' === $args['object']) { $can = bp_loggedin_user_id() === (int) $args['item_id'] || bp_current_user_can('bp_moderate'); } /** * No avatar arguments, fallback to bp_user_can_create_groups() * or bp_is_item_admin() */ } else { if (bp_is_group_create()) { $can = bp_user_can_create_groups(); } else { $can = bp_is_item_admin(); } } } return apply_filters('bp_attachments_current_user_can', $can, $capability, $args); }
function bp_link_is_admin() { return true === bp_is_item_admin() || true === bp_links_is_admin(); }
/** * Determine if the current user can delete an activity item. * * @since BuddyPress (1.2.0) * * @global object $activities_template {@link BP_Activity_Template} * @uses apply_filters() To call the 'bp_activity_user_can_delete' hook * * @param object $activity Optional. Falls back on the current item in the loop. * @return bool True if can delete, false otherwise. */ function bp_activity_user_can_delete($activity = false) { global $activities_template; // Try to use current activity if none was passed if (empty($activity) && !empty($activities_template->activity)) { $activity = $activities_template->activity; } // If current_comment is set, we'll use that in place of the main activity if (isset($activity->current_comment)) { $activity = $activity->current_comment; } // Assume the user cannot delete the activity item $can_delete = false; // Only logged in users can delete activity if (is_user_logged_in()) { // Community moderators can always delete activity (at least for now) if (bp_current_user_can('bp_moderate')) { $can_delete = true; } // Users are allowed to delete their own activity. This is actually // quite powerful, because doing so also deletes all comments to that // activity item. We should revisit this eventually. if (isset($activity->user_id) && (int) $activity->user_id === bp_loggedin_user_id()) { $can_delete = true; } // Viewing a single item, and this user is an admin of that item if (bp_is_single_item() && bp_is_item_admin()) { $can_delete = true; } } /** * Filters whether the current user can delete an activity item. * * @since BuddyPress (1.5.0) * * @param bool $can_delete Whether the user can delete the item. * @param object $activity Current activity item object. */ return (bool) apply_filters('bp_activity_user_can_delete', $can_delete, $activity); }
/** * Determine if the current user can delete an activity item. * * @since BuddyPress (1.2) * * @global object $activities_template {@link BP_Activity_Template} * @uses apply_filters() To call the 'bp_activity_user_can_delete' hook * * @param object $activity Optional. Falls back on the current item in the loop. * @return bool True if can delete, false otherwise. */ function bp_activity_user_can_delete($activity = false) { global $activities_template; if (!$activity) { $activity = $activities_template->activity; } if (isset($activity->current_comment)) { $activity = $activity->current_comment; } $can_delete = false; if (bp_current_user_can('bp_moderate')) { $can_delete = true; } if (is_user_logged_in() && $activity->user_id == bp_loggedin_user_id()) { $can_delete = true; } if (bp_is_item_admin() && bp_is_single_item()) { $can_delete = true; } return apply_filters('bp_activity_user_can_delete', $can_delete, $activity); }
/** * Handles group's moderating actions about ideas * * @package WP Idea Stream * @subpackage buddypress/groups * * @since 2.0.0 * * @uses bp_is_group() to check a group is displayed * @uses bp_is_current_action() to check the group's current action * @uses wp_idea_stream_root_slug() to get the IdeaStream root slug * @uses wp_idea_stream_action_get_slug() to get the IdeaStream's action slug * @uses bp_action_variable() to get a specific action variable * @uses groups_get_current_group() to get the current group's object * @uses WP_Idea_Stream_Group->group_ideas_archive_url() to get the group's IdeaStream archive page * @uses check_admin_referer() to check the request was made on the site * @uses wp_idea_stream_user_can() to check user's capability * @uses WP_Idea_Stream_Group->remove_from_group() to remove one or more ideas from a group * @uses wp_get_referer() to get the url the user came from * @uses wp_spam_comment() to spam a comment made on an idea * @uses wp_trash_comment() to trash a comment made on an idea * @uses wp_idea_stream_add_message() to add a feedback to display to the user once redirected * @uses bp_core_redirect() to safely redirect the user */ public function group_actions() { if (!bp_is_group()) { return; } $group = groups_get_current_group(); // This part is to catch the group status before it might be updated if ('group-settings' == bp_get_group_current_admin_tab() && bp_is_item_admin()) { $this->group_update_ideas_stati = $group; if (!empty($_POST['group-status']) && in_array($_POST['group-status'], array('public', 'private', 'hidden'))) { $this->group_update_ideas_stati->new_status = $_POST['group-status']; } } // This part is for ideastream moderation actions. if (!(bp_is_current_action(wp_idea_stream_root_slug()) && wp_idea_stream_action_get_slug() == bp_action_variable(0) && bp_action_variable(1))) { return; } $feedback = array(); // Default to group's home $redirect = $this->group_ideas_archive_url($group, true); switch (bp_action_variable(1)) { case 'remove-idea': check_admin_referer('group-remove-idea'); if (!bp_action_variable(2)) { $feedback['type'] = 'error'; $feedback['content'] = __('Removing the idea failed.', 'wp-idea-stream'); break; } $idea_id = absint(bp_action_variable(2)); if (!wp_idea_stream_user_can('remove_group_ideas')) { $feedback['type'] = 'error'; $feedback['content'] = __('Removing the idea failed. You do not have the capability to remove ideas.', 'wp-idea-stream'); break; } if (false === $this->remove_from_group($idea_id, $group->id)) { $feedback['type'] = 'error'; $feedback['content'] = __('Removing the idea failed.', 'wp-idea-stream'); $redirect = wp_get_referer(); } else { $feedback['type'] = 'success'; $feedback['content'] = __('The idea was successfully removed.', 'wp-idea-stream'); } break; case 'spam-comment': check_admin_referer('group-spam-comment'); $redirect = wp_get_referer(); if (!bp_action_variable(2)) { $feedback['type'] = 'error'; $feedback['content'] = __('Spamming the comment failed.', 'wp-idea-stream'); break; } $comment_id = absint(bp_action_variable(2)); if (!wp_idea_stream_user_can('spam_group_idea_comments')) { $feedback['type'] = 'error'; $feedback['content'] = __('Spamming the comment failed. You do not have the capability to spam comments.', 'wp-idea-stream'); break; } if (false === wp_spam_comment($comment_id)) { $feedback['type'] = 'error'; $feedback['content'] = __('Spamming the comment failed.', 'wp-idea-stream'); } else { $feedback['type'] = 'success'; $feedback['content'] = __('The comment was successfully marked as spam.', 'wp-idea-stream'); } break; case 'trash-comment': check_admin_referer('group-trash-comment'); $redirect = wp_get_referer(); if (!bp_action_variable(2)) { $feedback['type'] = 'error'; $feedback['content'] = __('Deleting the comment failed.', 'wp-idea-stream'); break; } $comment_id = absint(bp_action_variable(2)); if (!wp_idea_stream_user_can('trash_group_idea_comments')) { $feedback['type'] = 'error'; $feedback['content'] = __('Deleting the comment failed. You do not have the capability to delete comments.', 'wp-idea-stream'); break; } if (false === wp_trash_comment($comment_id)) { $feedback['type'] = 'error'; $feedback['content'] = __('Deleting the comment failed.', 'wp-idea-stream'); } else { $feedback['type'] = 'success'; $feedback['content'] = __('The comment was successfully deleted.', 'wp-idea-stream'); } break; } if (!empty($feedback)) { wp_idea_stream_add_message($feedback); bp_core_redirect($redirect); } }
/** * A hierarchy-aware copy of the setup_globals function from BP_Groups_Component */ function setup_globals($args = array()) { global $bp; // Define a slug, if necessary if (!defined('BP_GROUPS_SLUG')) { define('BP_GROUPS_SLUG', $this->id); } // Global tables for messaging component $global_tables = array('table_name' => $bp->table_prefix . 'bp_groups', 'table_name_members' => $bp->table_prefix . 'bp_groups_members', 'table_name_groupmeta' => $bp->table_prefix . 'bp_groups_groupmeta'); // Metadata tables for groups component $meta_tables = array('group' => $bp->table_prefix . 'bp_groups_groupmeta'); // All globals for messaging component. // Note that global_tables is included in this array. $globals = array('path' => BP_PLUGIN_DIR, 'slug' => BP_GROUPS_SLUG, 'root_slug' => isset($bp->pages->groups->slug) ? $bp->pages->groups->slug : BP_GROUPS_SLUG, 'has_directory' => true, 'notification_callback' => 'groups_format_notifications', 'search_string' => __('Search Groups...', 'buddypress'), 'global_tables' => $global_tables, 'meta_tables' => $meta_tables); call_user_func(array(get_parent_class(get_parent_class($this)), 'setup_globals'), $globals); /** Single Group Globals **********************************************/ // Are we viewing a single group? if (bp_is_groups_component() && ($group_id = BP_Groups_Hierarchy::group_exists(bp_current_action()))) { $bp->is_single_item = true; $current_group_class = apply_filters('bp_groups_current_group_class', 'BP_Groups_Hierarchy'); if ('BP_Groups_Hierarchy' == $current_group_class) { $this->current_group = new BP_Groups_Hierarchy($group_id, 0, array('populate_extras' => true)); } else { $this->current_group = apply_filters('bp_groups_current_group_object', new $current_group_class($group_id)); } // When in a single group, the first action is bumped down one because of the // group name, so we need to adjust this and set the group name to current_item. $bp->current_item = bp_current_action(); $bp->current_action = bp_action_variable(0); array_shift($bp->action_variables); // Using "item" not "group" for generic support in other components. if (is_super_admin() || function_exists('bp_current_user_can') && bp_current_user_can('bp_moderate')) { bp_update_is_item_admin(true, 'groups'); } else { bp_update_is_item_admin(groups_is_user_admin(bp_loggedin_user_id(), $this->current_group->id), 'groups'); } // If the user is not an admin, check if they are a moderator if (!bp_is_item_admin()) { bp_update_is_item_mod(groups_is_user_mod(bp_loggedin_user_id(), $this->current_group->id), 'groups'); } // Is the logged in user a member of the group? if (is_user_logged_in() && groups_is_user_member(bp_loggedin_user_id(), $this->current_group->id)) { $this->current_group->is_user_member = true; } else { $this->current_group->is_user_member = false; } // Should this group be visible to the logged in user? if ('public' == $this->current_group->status || $this->current_group->is_user_member) { $this->current_group->is_visible = true; } else { $this->current_group->is_visible = false; } // If this is a private or hidden group, does the user have access? if ('private' == $this->current_group->status || 'hidden' == $this->current_group->status) { if ($this->current_group->is_user_member && is_user_logged_in() || is_super_admin() || function_exists('bp_current_user_can') && bp_current_user_can('bp_moderate')) { $this->current_group->user_has_access = true; } else { $this->current_group->user_has_access = false; } } else { $this->current_group->user_has_access = true; } // Set current_group to 0 to prevent debug errors } else { $this->current_group = 0; } // Illegal group names/slugs $this->forbidden_names = apply_filters('groups_forbidden_names', array('my-groups', 'create', 'invites', 'send-invites', 'forum', 'delete', 'add', 'admin', 'request-membership', 'members', 'settings', 'avatar', $this->slug, $this->root_slug)); // If the user was attempting to access a group, but no group by that name was found, 404 if (bp_is_groups_component() && empty($this->current_group) && bp_current_action() && !in_array(bp_current_action(), $this->forbidden_names)) { bp_do_404(); return; } if (bp_is_groups_component() && !empty($this->current_group)) { $this->default_extension = apply_filters('bp_groups_default_extension', defined('BP_GROUPS_DEFAULT_EXTENSION') ? BP_GROUPS_DEFAULT_EXTENSION : 'home'); if (!bp_current_action()) { $bp->current_action = $this->default_extension; } // Prepare for a redirect to the canonical URL $bp->canonical_stack['base_url'] = bp_get_group_permalink($this->current_group); if (bp_current_action()) { $bp->canonical_stack['action'] = bp_current_action(); } if (!empty($bp->action_variables)) { $bp->canonical_stack['action_variables'] = bp_action_variables(); } // When viewing the default extension, the canonical URL should not have // that extension's slug, unless more has been tacked onto the URL via // action variables if (bp_is_current_action($this->default_extension) && empty($bp->action_variables)) { unset($bp->canonical_stack['action']); } } // Group access control if (bp_is_groups_component() && !empty($this->current_group)) { if (!$this->current_group->user_has_access) { // Hidden groups should return a 404 for non-members. // Unset the current group so that you're not redirected // to the default group tab if ('hidden' == $this->current_group->status) { $this->current_group = 0; $bp->is_single_item = false; bp_do_404(); return; // Skip the no_access check on home and membership request pages } elseif (!in_array(bp_current_action(), apply_filters('bp_group_hierarchy_allow_anon_access', array('home', 'request-membership', BP_GROUP_HIERARCHY_SLUG)))) { // Off-limits to this user. Throw an error and redirect to the group's home page if (is_user_logged_in()) { bp_core_no_access(array('message' => __('You do not have access to this group.', 'buddypress'), 'root' => bp_get_group_permalink($bp->groups->current_group), 'redirect' => false)); // User does not have access, and does not get a message } else { bp_core_no_access(); } } } // Protect the admin tab from non-admins if (bp_is_current_action('admin') && !bp_is_item_admin()) { bp_core_no_access(array('message' => __('You are not an admin of this group.', 'buddypress'), 'root' => bp_get_group_permalink($bp->groups->current_group), 'redirect' => false)); } } // Preconfigured group creation steps $this->group_creation_steps = apply_filters('groups_create_group_steps', array('group-details' => array('name' => __('Details', 'buddypress'), 'position' => 0), 'group-settings' => array('name' => __('Settings', 'buddypress'), 'position' => 10))); // If avatar uploads are not disabled, add avatar option if (!(int) bp_get_option('bp-disable-avatar-uploads')) { $this->group_creation_steps['group-avatar'] = array('name' => __('Avatar', 'buddypress'), 'position' => 20); } // If friends component is active, add invitations if (bp_is_active('friends')) { $this->group_creation_steps['group-invites'] = array('name' => __('Invites', 'buddypress'), 'position' => 30); } // Groups statuses $this->valid_status = apply_filters('groups_valid_status', array('public', 'private', 'hidden')); // Auto join group when non group member performs group activity $this->auto_join = defined('BP_DISABLE_AUTO_GROUP_JOIN') && BP_DISABLE_AUTO_GROUP_JOIN ? false : true; }
/** * Remove a member from a group. * * @since 1.2.6 * * @param int $user_id ID of the user. * @param int $group_id ID of the group. * @return bool True on success, false on failure. */ function groups_remove_member($user_id, $group_id) { if (!bp_is_item_admin()) { return false; } $member = new BP_Groups_Member($user_id, $group_id); /** * Fires before the removal of a member from a group. * * @since 1.2.6 * * @param int $group_id ID of the group being removed from. * @param int $user_id ID of the user being removed. */ do_action('groups_remove_member', $group_id, $user_id); return $member->remove(); }
<?php if (!bp_is_item_admin()) { die; } ?> <div class="item-list-tabs no-ajax" id="subnav" role="tablist"> <ul class="nav nav-pills" id="nav-sub"> <?php /* * Note that for the including of templates, we follow that the files * so make sure that file naming matches the keys */ $admin_menu = array('edit-details' => 'Details', 'group-settings' => 'Settings', 'group-avatar' => 'Photo', 'manage-members' => 'Members', 'membership-requests' => 'Requests', 'delete-group' => 'Delete'); $current_tab = bp_get_group_current_admin_tab(); $group = groups_get_current_group(); foreach ($admin_menu as $url_key => $name) { if ($group->status !== 'private' && $url_key == 'membership-requests') { continue; } $url = trailingslashit(bp_get_group_permalink($group)) . 'admin/' . $url_key; $tpl = $current_tab == $url_key ? "<li class=\"active\">" : "<li>"; $tpl .= "<a href=\"%s\">%s</a>"; $tpl .= "</li>"; printf($tpl, $url, $name); } ?> </ul>
/** * Should we show the group's custom front page ? */ private function show_front_page() { $retval = false; if (bp_is_group_create()) { return $retval; } if (!bp_is_group()) { return $retval; } $group_id = bp_get_current_group_id(); if (empty($group_id)) { return $retval; } if (bp_is_item_admin()) { return $retval; } if (!groups_is_user_member(bp_loggedin_user_id(), $group_id) && $this->has_front_page($group_id)) { $retval = true; } return $retval; }
/** * Handle the display of the Delete Group page. */ function groups_screen_group_admin_delete_group() { global $bp; if ('delete-group' != bp_get_group_current_admin_tab()) { return false; } if (!bp_is_item_admin() && !bp_current_user_can('bp_moderate')) { return false; } if (isset($_REQUEST['delete-group-button']) && isset($_REQUEST['delete-group-understand'])) { // Check the nonce first. if (!check_admin_referer('groups_delete_group')) { return false; } do_action('groups_before_group_deleted', $bp->groups->current_group->id); // Group admin has deleted the group, now do it. if (!groups_delete_group($bp->groups->current_group->id)) { bp_core_add_message(__('There was an error deleting the group. Please try again.', 'buddypress'), 'error'); } else { bp_core_add_message(__('The group was deleted successfully', 'buddypress')); do_action('groups_group_deleted', $bp->groups->current_group->id); bp_core_redirect(trailingslashit(bp_loggedin_user_domain() . bp_get_groups_slug())); } bp_core_redirect(trailingslashit(bp_loggedin_user_domain() . bp_get_groups_slug())); } do_action('groups_screen_group_admin_delete_group', $bp->groups->current_group->id); bp_core_load_template(apply_filters('groups_template_group_admin_delete_group', 'groups/single/home')); }
/** * Set up component navigation. * * @since 1.5.0 * * @see BP_Component::setup_nav() for a description of arguments. * * @param array $main_nav Optional. See BP_Component::setup_nav() for description. * @param array $sub_nav Optional. See BP_Component::setup_nav() for description. */ public function setup_nav($main_nav = array(), $sub_nav = array()) { // Determine user to use. if (bp_displayed_user_domain()) { $user_domain = bp_displayed_user_domain(); } elseif (bp_loggedin_user_domain()) { $user_domain = bp_loggedin_user_domain(); } else { $user_domain = false; } // Only grab count if we're on a user page. if (bp_is_user()) { $count = bp_get_total_group_count_for_user(); $class = 0 === $count ? 'no-count' : 'count'; $nav_name = sprintf(_x('Groups <span class="%s">%s</span>', 'Group screen nav with counter', 'buddypress'), esc_attr($class), bp_core_number_format($count)); } else { $nav_name = _x('Groups', 'Group screen nav without counter', 'buddypress'); } $slug = bp_get_groups_slug(); // Add 'Groups' to the main navigation. $main_nav = array('name' => $nav_name, 'slug' => $slug, 'position' => 70, 'screen_function' => 'groups_screen_my_groups', 'default_subnav_slug' => 'my-groups', 'item_css_id' => $this->id); if (!empty($user_domain)) { $access = bp_core_can_edit_settings(); $groups_link = trailingslashit($user_domain . $slug); // Add the My Groups nav item. $sub_nav[] = array('name' => __('Memberships', 'buddypress'), 'slug' => 'my-groups', 'parent_url' => $groups_link, 'parent_slug' => $slug, 'screen_function' => 'groups_screen_my_groups', 'position' => 10, 'item_css_id' => 'groups-my-groups'); // Add the Group Invites nav item. $sub_nav[] = array('name' => __('Invitations', 'buddypress'), 'slug' => 'invites', 'parent_url' => $groups_link, 'parent_slug' => $slug, 'screen_function' => 'groups_screen_group_invites', 'user_has_access' => $access, 'position' => 30); parent::setup_nav($main_nav, $sub_nav); } if (bp_is_groups_component() && bp_is_single_item()) { // Reset sub nav. $sub_nav = array(); // Add 'Groups' to the main navigation. $main_nav = array('name' => __('Memberships', 'buddypress'), 'slug' => $this->current_group->slug, 'position' => -1, 'screen_function' => 'groups_screen_group_home', 'default_subnav_slug' => $this->default_extension, 'item_css_id' => $this->id); $group_link = bp_get_group_permalink($this->current_group); // Add the "Home" subnav item, as this will always be present. $sub_nav[] = array('name' => _x('Home', 'Group screen navigation title', 'buddypress'), 'slug' => 'home', 'parent_url' => $group_link, 'parent_slug' => $this->current_group->slug, 'screen_function' => 'groups_screen_group_home', 'position' => 10, 'item_css_id' => 'home'); // If this is a private group, and the user is not a // member and does not have an outstanding invitation, // show a "Request Membership" nav item. if (is_user_logged_in() && !$this->current_group->is_user_member && !groups_check_for_membership_request(bp_loggedin_user_id(), $this->current_group->id) && $this->current_group->status == 'private' && !groups_check_user_has_invite(bp_loggedin_user_id(), $this->current_group->id)) { $sub_nav[] = array('name' => _x('Request Membership', 'Group screen nav', 'buddypress'), 'slug' => 'request-membership', 'parent_url' => $group_link, 'parent_slug' => $this->current_group->slug, 'screen_function' => 'groups_screen_group_request_membership', 'position' => 30); } // Forums are enabled and turned on. if ($this->current_group->enable_forum && bp_is_active('forums')) { $sub_nav[] = array('name' => _x('Forum', 'My Group screen nav', 'buddypress'), 'slug' => 'forum', 'parent_url' => $group_link, 'parent_slug' => $this->current_group->slug, 'screen_function' => 'groups_screen_group_forum', 'position' => 40, 'user_has_access' => $this->current_group->user_has_access, 'item_css_id' => 'forums'); } if ($this->current_group->front_template || bp_is_active('activity')) { /** * If the theme is using a custom front, create activity subnav. */ if ($this->current_group->front_template && bp_is_active('activity')) { $sub_nav[] = array('name' => _x('Activity', 'My Group screen nav', 'buddypress'), 'slug' => 'activity', 'parent_url' => $group_link, 'parent_slug' => $this->current_group->slug, 'screen_function' => 'groups_screen_group_activity', 'position' => 11, 'user_has_access' => $this->current_group->user_has_access, 'item_css_id' => 'activity', 'no_access_url' => $group_link); } /** * Only add the members subnav if it's not the home's nav. */ $sub_nav[] = array('name' => sprintf(_x('Members %s', 'My Group screen nav', 'buddypress'), '<span>' . number_format($this->current_group->total_member_count) . '</span>'), 'slug' => 'members', 'parent_url' => $group_link, 'parent_slug' => $this->current_group->slug, 'screen_function' => 'groups_screen_group_members', 'position' => 60, 'user_has_access' => $this->current_group->user_has_access, 'item_css_id' => 'members', 'no_access_url' => $group_link); } if (bp_is_active('friends') && bp_groups_user_can_send_invites()) { $sub_nav[] = array('name' => _x('Send Invites', 'My Group screen nav', 'buddypress'), 'slug' => 'send-invites', 'parent_url' => $group_link, 'parent_slug' => $this->current_group->slug, 'screen_function' => 'groups_screen_group_invite', 'item_css_id' => 'invite', 'position' => 70, 'user_has_access' => $this->current_group->user_has_access, 'no_access_url' => $group_link); } // If the user is a group admin, then show the group admin nav item. if (bp_is_item_admin()) { $sub_nav[] = array('name' => _x('Manage', 'My Group screen nav', 'buddypress'), 'slug' => 'admin', 'parent_url' => $group_link, 'parent_slug' => $this->current_group->slug, 'screen_function' => 'groups_screen_group_admin', 'position' => 1000, 'user_has_access' => true, 'item_css_id' => 'admin', 'no_access_url' => $group_link); $admin_link = trailingslashit($group_link . 'admin'); // Common params to all nav items. $default_params = array('parent_url' => $admin_link, 'parent_slug' => $this->current_group->slug . '_manage', 'screen_function' => 'groups_screen_group_admin', 'user_has_access' => bp_is_item_admin(), 'show_in_admin_bar' => true); $sub_nav[] = array_merge(array('name' => __('Details', 'buddypress'), 'slug' => 'edit-details', 'position' => 0), $default_params); $sub_nav[] = array_merge(array('name' => __('Settings', 'buddypress'), 'slug' => 'group-settings', 'position' => 10), $default_params); if (!bp_disable_group_avatar_uploads() && buddypress()->avatar->show_avatars) { $sub_nav[] = array_merge(array('name' => __('Photo', 'buddypress'), 'slug' => 'group-avatar', 'position' => 20), $default_params); } if (bp_group_use_cover_image_header()) { $sub_nav[] = array_merge(array('name' => __('Cover Image', 'buddypress'), 'slug' => 'group-cover-image', 'position' => 25), $default_params); } $sub_nav[] = array_merge(array('name' => __('Members', 'buddypress'), 'slug' => 'manage-members', 'position' => 30), $default_params); if ('private' == $this->current_group->status) { $sub_nav[] = array_merge(array('name' => __('Requests', 'buddypress'), 'slug' => 'membership-requests', 'position' => 40), $default_params); } $sub_nav[] = array_merge(array('name' => __('Delete', 'buddypress'), 'slug' => 'delete-group', 'position' => 1000), $default_params); } parent::setup_nav($main_nav, $sub_nav); } if (isset($this->current_group->user_has_access)) { /** * Fires at the end of the groups navigation setup if user has access. * * @since 1.0.2 * * @param bool $user_has_access Whether or not user has access. */ do_action('groups_setup_nav', $this->current_group->user_has_access); } else { /** This action is documented in bp-groups/bp-groups-loader.php */ do_action('groups_setup_nav'); } }
/** * Setup BuddyBar navigation * * @global BuddyPress $bp The one true BuddyPress instance */ function setup_nav() { // Define local variables $sub_nav = array(); // Add 'Groups' to the main navigation $main_nav = array('name' => sprintf(__('Groups <span>%d</span>', 'buddypress'), groups_total_groups_for_user()), 'slug' => $this->slug, 'position' => 70, 'screen_function' => 'groups_screen_my_groups', 'default_subnav_slug' => 'my-groups', 'item_css_id' => $this->id); $groups_link = trailingslashit(bp_loggedin_user_domain() . $this->slug); // Add the My Groups nav item $sub_nav[] = array('name' => __('Memberships', 'buddypress'), 'slug' => 'my-groups', 'parent_url' => $groups_link, 'parent_slug' => $this->slug, 'screen_function' => 'groups_screen_my_groups', 'position' => 10, 'item_css_id' => 'groups-my-groups'); // Add the Group Invites nav item $sub_nav[] = array('name' => __('Invitations', 'buddypress'), 'slug' => 'invites', 'parent_url' => $groups_link, 'parent_slug' => $this->slug, 'screen_function' => 'groups_screen_group_invites', 'user_has_access' => bp_is_my_profile(), 'position' => 30); parent::setup_nav($main_nav, $sub_nav); if (bp_is_groups_component() && bp_is_single_item()) { // Reset sub nav $sub_nav = array(); // Add 'Groups' to the main navigation $main_nav = array('name' => __('Memberships', 'buddypress'), 'slug' => $this->current_group->slug, 'position' => -1, 'screen_function' => 'groups_screen_group_home', 'default_subnav_slug' => $this->default_extension, 'item_css_id' => $this->id); $group_link = bp_get_group_permalink($this->current_group); // Add the "Home" subnav item, as this will always be present $sub_nav[] = array('name' => _x('Home', 'Group home navigation title', 'buddypress'), 'slug' => 'home', 'parent_url' => $group_link, 'parent_slug' => $this->current_group->slug, 'screen_function' => 'groups_screen_group_home', 'position' => 10, 'item_css_id' => 'home'); // If this is a private group, and the user is not a member, show a "Request Membership" nav item. if (is_user_logged_in() && !bp_current_user_can('bp_moderate') && !$this->current_group->is_user_member && !groups_check_for_membership_request(bp_loggedin_user_id(), $this->current_group->id) && $this->current_group->status == 'private') { $sub_nav[] = array('name' => __('Request Membership', 'buddypress'), 'slug' => 'request-membership', 'parent_url' => $group_link, 'parent_slug' => $this->current_group->slug, 'screen_function' => 'groups_screen_group_request_membership', 'position' => 30); } // Forums are enabled and turned on if ($this->current_group->enable_forum && bp_is_active('forums')) { $sub_nav[] = array('name' => __('Forum', 'buddypress'), 'slug' => 'forum', 'parent_url' => $group_link, 'parent_slug' => $this->current_group->slug, 'screen_function' => 'groups_screen_group_forum', 'position' => 40, 'user_has_access' => $this->current_group->user_has_access, 'item_css_id' => 'forums'); } $sub_nav[] = array('name' => sprintf(__('Members <span>%s</span>', 'buddypress'), number_format($this->current_group->total_member_count)), 'slug' => 'members', 'parent_url' => $group_link, 'parent_slug' => $this->current_group->slug, 'screen_function' => 'groups_screen_group_members', 'position' => 60, 'user_has_access' => $this->current_group->user_has_access, 'item_css_id' => 'members'); if (bp_is_active('friends') && bp_groups_user_can_send_invites()) { $sub_nav[] = array('name' => __('Send Invites', 'buddypress'), 'slug' => 'send-invites', 'parent_url' => $group_link, 'parent_slug' => $this->current_group->slug, 'screen_function' => 'groups_screen_group_invite', 'item_css_id' => 'invite', 'position' => 70, 'user_has_access' => $this->current_group->user_has_access); } // If the user is a group mod or more, then show the group admin nav item if (bp_is_item_admin() || bp_is_item_mod()) { $sub_nav[] = array('name' => __('Admin', 'buddypress'), 'slug' => 'admin', 'parent_url' => $group_link, 'parent_slug' => $this->current_group->slug, 'screen_function' => 'groups_screen_group_admin', 'position' => 1000, 'user_has_access' => true, 'item_css_id' => 'admin'); } parent::setup_nav($main_nav, $sub_nav); } if (isset($this->current_group->user_has_access)) { do_action('groups_setup_nav', $this->current_group->user_has_access); } else { do_action('groups_setup_nav'); } }
/** * Handle the display of the Delete Group page. */ function groups_screen_group_admin_delete_group() { if ('delete-group' != bp_get_group_current_admin_tab()) { return false; } if (!bp_is_item_admin() && !bp_current_user_can('bp_moderate')) { return false; } $bp = buddypress(); if (isset($_REQUEST['delete-group-button']) && isset($_REQUEST['delete-group-understand'])) { // Check the nonce first. if (!check_admin_referer('groups_delete_group')) { return false; } /** * Fires before the deletion of a group from the Delete Group page. * * @since 1.5.0 * * @param int $id ID of the group being deleted. */ do_action('groups_before_group_deleted', $bp->groups->current_group->id); // Group admin has deleted the group, now do it. if (!groups_delete_group($bp->groups->current_group->id)) { bp_core_add_message(__('There was an error deleting the group. Please try again.', 'buddypress'), 'error'); } else { bp_core_add_message(__('The group was deleted successfully.', 'buddypress')); /** * Fires after the deletion of a group from the Delete Group page. * * @since 1.0.0 * * @param int $id ID of the group being deleted. */ do_action('groups_group_deleted', $bp->groups->current_group->id); bp_core_redirect(trailingslashit(bp_loggedin_user_domain() . bp_get_groups_slug())); } bp_core_redirect(trailingslashit(bp_loggedin_user_domain() . bp_get_groups_slug())); } /** * Fires before the loading of the Delete Group page template. * * @since 1.0.0 * * @param int $id ID of the group that is being displayed. */ do_action('groups_screen_group_admin_delete_group', $bp->groups->current_group->id); /** * Filters the template to load for the Delete Group page. * * @since 1.0.0 * * @param string $value Path to the Delete Group template. */ bp_core_load_template(apply_filters('groups_template_group_admin_delete_group', 'groups/single/home')); }
/** * Set up component navigation. * * @since BuddyPress (1.5.0) * * @see BP_Component::setup_nav() for a description of arguments. * * @param array $main_nav Optional. See BP_Component::setup_nav() for * description. * @param array $sub_nav Optional. See BP_Component::setup_nav() for * description. */ public function setup_nav($main_nav = array(), $sub_nav = array()) { // Only grab count if we're on a user page if (bp_is_user()) { $count = bp_get_total_group_count_for_user(); $class = 0 === $count ? 'no-count' : 'count'; $nav_name = sprintf(_x('Groups <span class="%s">%s</span>', 'Group screen nav with counter', 'buddypress'), esc_attr($class), number_format_i18n($count)); } else { $nav_name = _x('Groups', 'Group screen nav without counter', 'buddypress'); } // Add 'Groups' to the main navigation $main_nav = array('name' => $nav_name, 'slug' => $this->slug, 'position' => 70, 'screen_function' => 'groups_screen_my_groups', 'default_subnav_slug' => 'my-groups', 'item_css_id' => $this->id); // Determine user to use if (bp_displayed_user_domain()) { $user_domain = bp_displayed_user_domain(); } elseif (bp_loggedin_user_domain()) { $user_domain = bp_loggedin_user_domain(); } else { $user_domain = false; } if (!empty($user_domain)) { $groups_link = trailingslashit($user_domain . $this->slug); // Add the My Groups nav item $sub_nav[] = array('name' => __('Memberships', 'buddypress'), 'slug' => 'my-groups', 'parent_url' => $groups_link, 'parent_slug' => $this->slug, 'screen_function' => 'groups_screen_my_groups', 'position' => 10, 'item_css_id' => 'groups-my-groups'); // Add the Group Invites nav item $sub_nav[] = array('name' => __('Invitations', 'buddypress'), 'slug' => 'invites', 'parent_url' => $groups_link, 'parent_slug' => $this->slug, 'screen_function' => 'groups_screen_group_invites', 'user_has_access' => bp_core_can_edit_settings(), 'position' => 30); parent::setup_nav($main_nav, $sub_nav); } if (bp_is_groups_component() && bp_is_single_item()) { // Reset sub nav $sub_nav = array(); // Add 'Groups' to the main navigation $main_nav = array('name' => __('Memberships', 'buddypress'), 'slug' => $this->current_group->slug, 'position' => -1, 'screen_function' => 'groups_screen_group_home', 'default_subnav_slug' => $this->default_extension, 'item_css_id' => $this->id); $group_link = bp_get_group_permalink($this->current_group); // Add the "Home" subnav item, as this will always be present $sub_nav[] = array('name' => _x('Home', 'Group screen navigation title', 'buddypress'), 'slug' => 'home', 'parent_url' => $group_link, 'parent_slug' => $this->current_group->slug, 'screen_function' => 'groups_screen_group_home', 'position' => 10, 'item_css_id' => 'home'); // If this is a private group, and the user is not a // member and does not have an outstanding invitation, // show a "Request Membership" nav item. if (is_user_logged_in() && !$this->current_group->is_user_member && !groups_check_for_membership_request(bp_loggedin_user_id(), $this->current_group->id) && $this->current_group->status == 'private' && !groups_check_user_has_invite(bp_loggedin_user_id(), $this->current_group->id)) { $sub_nav[] = array('name' => _x('Request Membership', 'Group screen nav', 'buddypress'), 'slug' => 'request-membership', 'parent_url' => $group_link, 'parent_slug' => $this->current_group->slug, 'screen_function' => 'groups_screen_group_request_membership', 'position' => 30); } // Forums are enabled and turned on if ($this->current_group->enable_forum && bp_is_active('forums')) { $sub_nav[] = array('name' => _x('Forum', 'My Group screen nav', 'buddypress'), 'slug' => 'forum', 'parent_url' => $group_link, 'parent_slug' => $this->current_group->slug, 'screen_function' => 'groups_screen_group_forum', 'position' => 40, 'user_has_access' => $this->current_group->user_has_access, 'item_css_id' => 'forums'); } $sub_nav[] = array('name' => sprintf(_x('Members <span>%s</span>', 'My Group screen nav', 'buddypress'), number_format($this->current_group->total_member_count)), 'slug' => 'members', 'parent_url' => $group_link, 'parent_slug' => $this->current_group->slug, 'screen_function' => 'groups_screen_group_members', 'position' => 60, 'user_has_access' => $this->current_group->user_has_access, 'item_css_id' => 'members', 'no_access_url' => $group_link); if (bp_is_active('friends') && bp_groups_user_can_send_invites()) { $sub_nav[] = array('name' => _x('Send Invites', 'My Group screen nav', 'buddypress'), 'slug' => 'send-invites', 'parent_url' => $group_link, 'parent_slug' => $this->current_group->slug, 'screen_function' => 'groups_screen_group_invite', 'item_css_id' => 'invite', 'position' => 70, 'user_has_access' => $this->current_group->user_has_access, 'no_access_url' => $group_link); } // If the user is a group admin, then show the group admin nav item if (bp_is_item_admin()) { $sub_nav[] = array('name' => _x('Manage', 'My Group screen nav', 'buddypress'), 'slug' => 'admin', 'parent_url' => $group_link, 'parent_slug' => $this->current_group->slug, 'screen_function' => 'groups_screen_group_admin', 'position' => 1000, 'user_has_access' => true, 'item_css_id' => 'admin', 'no_access_url' => $group_link); $admin_link = trailingslashit($group_link . 'admin'); // Common params to all nav items $default_params = array('parent_url' => $admin_link, 'parent_slug' => $this->current_group->slug . '_manage', 'screen_function' => 'groups_screen_group_admin', 'user_has_access' => bp_is_item_admin(), 'show_in_admin_bar' => true); $sub_nav[] = array_merge(array('name' => __('Details', 'buddypress'), 'slug' => 'edit-details', 'position' => 0), $default_params); $sub_nav[] = array_merge(array('name' => __('Settings', 'buddypress'), 'slug' => 'group-settings', 'position' => 10), $default_params); if (!(int) bp_get_option('bp-disable-avatar-uploads') && buddypress()->avatar->show_avatars) { $sub_nav[] = array_merge(array('name' => __('Photo', 'buddypress'), 'slug' => 'group-avatar', 'position' => 20), $default_params); } $sub_nav[] = array_merge(array('name' => __('Members', 'buddypress'), 'slug' => 'manage-members', 'position' => 30), $default_params); if ('private' == $this->current_group->status) { $sub_nav[] = array_merge(array('name' => __('Requests', 'buddypress'), 'slug' => 'membership-requests', 'position' => 40), $default_params); } $sub_nav[] = array_merge(array('name' => __('Delete', 'buddypress'), 'slug' => 'delete-group', 'position' => 1000), $default_params); } parent::setup_nav($main_nav, $sub_nav); } if (isset($this->current_group->user_has_access)) { do_action('groups_setup_nav', $this->current_group->user_has_access); } else { do_action('groups_setup_nav'); } }
/** * Determine whether the current user is the admin of the current group. * * Alias of {@link bp_is_item_admin()}. * * @since 1.1.0 * * @return bool */ function bp_group_is_admin() { return bp_is_item_admin(); }
/** * Hook this extension's Edit panel into BuddyPress, if necessary. * * @since BuddyPress (1.8.0) */ protected function setup_edit_hooks() { // Bail if not in a group if (!bp_is_group()) { return; } // Bail if not an edit screen if (!$this->is_screen_enabled('edit') || !bp_is_item_admin()) { return; } $screen = $this->screens['edit']; $position = isset($screen['position']) ? (int) $screen['position'] : 10; $position += 40; $current_group = groups_get_current_group(); $admin_link = trailingslashit(bp_get_group_permalink($current_group) . 'admin'); $subnav_args = array('name' => $screen['name'], 'slug' => $screen['slug'], 'parent_slug' => $current_group->slug . '_manage', 'parent_url' => trailingslashit(bp_get_group_permalink($current_group) . 'admin'), 'user_has_access' => bp_is_item_admin(), 'position' => $position, 'screen_function' => 'groups_screen_group_admin'); // Should we add a menu to the Group's WP Admin Bar if (!empty($screen['show_in_admin_bar'])) { $subnav_args['show_in_admin_bar'] = true; } // Add the tab to the manage navigation bp_core_new_subnav_item($subnav_args); // Catch the edit screen and forward it to the plugin template if (bp_is_groups_component() && bp_is_current_action('admin') && bp_is_action_variable($screen['slug'], 0)) { $this->call_edit_screen_save($this->group_id); add_action('groups_custom_edit_steps', array(&$this, 'call_edit_screen')); // Determine the proper template and save for later // loading if ('' !== bp_locate_template(array('groups/single/home.php'), false)) { $this->edit_screen_template = '/groups/single/home'; } else { add_action('bp_template_content_header', create_function('', 'echo "<ul class=\\"content-header-nav\\">"; bp_group_admin_tabs(); echo "</ul>";')); add_action('bp_template_content', array(&$this, 'call_edit_screen')); $this->edit_screen_template = '/groups/single/plugins'; } // We load the template at bp_screens, to give all // extensions a chance to load add_action('bp_screens', array($this, 'call_edit_screen_template_loader')); } }
function bp_group_admin_tabs($group = false) { global $bp, $groups_template; if (empty($group)) { $group = $groups_template->group ? $groups_template->group : $bp->groups->current_group; } $current_tab = bp_get_group_current_admin_tab(); if (bp_is_item_admin()) { ?> <li<?php if ('edit-details' == $current_tab || empty($current_tab)) { ?> class="current"<?php } ?> ><a href="<?php echo trailingslashit(bp_get_group_permalink($group) . 'admin/edit-details'); ?> "><?php _e('Details', 'buddypress'); ?> </a></li> <?php } ?> <?php if (!bp_is_item_admin()) { return false; } ?> <li<?php if ('group-settings' == $current_tab) { ?> class="current"<?php } ?> ><a href="<?php echo trailingslashit(bp_get_group_permalink($group) . 'admin/group-settings'); ?> "><?php _e('Settings', 'buddypress'); ?> </a></li> <?php if (!(int) bp_get_option('bp-disable-avatar-uploads')) { ?> <li<?php if ('group-avatar' == $current_tab) { ?> class="current"<?php } ?> ><a href="<?php echo trailingslashit(bp_get_group_permalink($group) . 'admin/group-avatar'); ?> "><?php _e('Avatar', 'buddypress'); ?> </a></li> <?php } ?> <li<?php if ('manage-members' == $current_tab) { ?> class="current"<?php } ?> ><a href="<?php echo trailingslashit(bp_get_group_permalink($group) . 'admin/manage-members'); ?> "><?php _e('Members', 'buddypress'); ?> </a></li> <?php if ($groups_template->group->status == 'private') { ?> <li<?php if ('membership-requests' == $current_tab) { ?> class="current"<?php } ?> ><a href="<?php echo trailingslashit(bp_get_group_permalink($group) . 'admin/membership-requests'); ?> "><?php _e('Requests', 'buddypress'); ?> </a></li> <?php } ?> <?php do_action('groups_admin_tabs', $current_tab, $group->slug); ?> <li<?php if ('delete-group' == $current_tab) { ?> class="current"<?php } ?> ><a href="<?php echo trailingslashit(bp_get_group_permalink($group) . 'admin/delete-group'); ?> "><?php _e('Delete', 'buddypress'); ?> </a></li> <?php }
/** * Hook this extension's Edit panel into BuddyPress, if necessary * * @since BuddyPress (1.8) */ protected function setup_edit_hooks() { // Bail if not an edit screen if (!$this->is_screen_enabled('edit') || !bp_is_item_admin()) { return; } $screen = $this->screens['edit']; $position = isset($screen['position']) ? (int) $screen['position'] : 10; // Add the tab // @todo BP should be using bp_core_new_subnav_item() add_action('groups_admin_tabs', create_function('$current, $group_slug', '$selected = ""; if ( "' . esc_attr($screen['slug']) . '" == $current ) $selected = " class=\\"current\\""; echo "<li{$selected}><a href=\\"' . trailingslashit(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/{$group_slug}/admin/' . esc_attr($screen['slug'])) . '\\">' . esc_attr($screen['name']) . '</a></li>";'), $position, 2); // Catch the edit screen and forward it to the plugin template if (bp_is_groups_component() && bp_is_current_action('admin') && bp_is_action_variable($screen['slug'], 0)) { $this->call_edit_screen_save($this->group_id); add_action('groups_custom_edit_steps', array(&$this, 'call_edit_screen')); // Determine the proper template and save for later // loading if ('' !== bp_locate_template(array('groups/single/home.php'), false)) { $this->edit_screen_template = '/groups/single/home'; } else { add_action('bp_template_content_header', create_function('', 'echo "<ul class=\\"content-header-nav\\">"; bp_group_admin_tabs(); echo "</ul>";')); add_action('bp_template_content', array(&$this, 'call_edit_screen')); $this->edit_screen_template = '/groups/single/plugins'; } // We load the template at bp_screens, to give all // extensions a chance to load add_action('bp_screens', array($this, 'call_edit_screen_template_loader')); } }
function _register() { global $bp; // If admin/create names and slugs are not provided, they fall back on the main // name and slug for the extension if (!$this->admin_name) { $this->admin_name = $this->name; } if (!$this->admin_slug) { $this->admin_slug = $this->slug; } if (!$this->create_name) { $this->create_name = $this->name; } if (!$this->create_slug) { $this->create_slug = $this->slug; } if (!empty($this->enable_create_step)) { // Insert the group creation step for the new group extension $bp->groups->group_creation_steps[$this->create_slug] = array('name' => $this->create_name, 'slug' => $this->create_slug, 'position' => $this->create_step_position); // Attach the group creation step display content action add_action('groups_custom_create_steps', array(&$this, 'create_screen')); // Attach the group creation step save content action add_action('groups_create_group_step_save_' . $this->create_slug, array(&$this, 'create_screen_save')); } // When we are viewing a single group, add the group extension nav item if (bp_is_group()) { if ($this->visibility == 'public' || $this->visibility != 'public' && $bp->groups->current_group->user_has_access) { if ($this->enable_nav_item) { bp_core_new_subnav_item(array('name' => !$this->nav_item_name ? $this->name : $this->nav_item_name, 'slug' => $this->slug, 'parent_slug' => $bp->groups->current_group->slug, 'parent_url' => bp_get_group_permalink($bp->groups->current_group), 'position' => $this->nav_item_position, 'item_css_id' => 'nav-' . $this->slug, 'screen_function' => array(&$this, '_display_hook'), 'user_has_access' => $this->enable_nav_item)); // When we are viewing the extension display page, set the title and options title if (bp_is_current_action($this->slug)) { add_action('bp_template_content_header', create_function('', 'echo "' . esc_attr($this->name) . '";')); add_action('bp_template_title', create_function('', 'echo "' . esc_attr($this->name) . '";')); } } // Hook the group home widget if (!bp_current_action() && bp_is_current_action('home')) { add_action($this->display_hook, array(&$this, 'widget_display')); } } } // Construct the admin edit tab for the new group extension if (!empty($this->enable_edit_item) && bp_is_item_admin()) { add_action('groups_admin_tabs', create_function('$current, $group_slug', '$selected = ""; if ( "' . esc_attr($this->admin_slug) . '" == $current ) $selected = " class=\\"current\\""; echo "<li{$selected}><a href=\\"' . trailingslashit(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/{$group_slug}/admin/' . esc_attr($this->admin_slug)) . '\\">' . esc_attr($this->admin_name) . '</a></li>";'), 10, 2); // Catch the edit screen and forward it to the plugin template if (bp_is_groups_component() && bp_is_current_action('admin') && bp_is_action_variable($this->admin_slug, 0)) { // Check whether the user is saving changes $this->edit_screen_save(); add_action('groups_custom_edit_steps', array(&$this, 'edit_screen')); if ('' != locate_template(array('groups/single/home.php'), false)) { bp_core_load_template(apply_filters('groups_template_group_home', 'groups/single/home')); } else { add_action('bp_template_content_header', create_function('', 'echo "<ul class=\\"content-header-nav\\">"; bp_group_admin_tabs(); echo "</ul>";')); add_action('bp_template_content', array(&$this, 'edit_screen')); bp_core_load_template(apply_filters('bp_core_template_plugin', '/groups/single/plugins')); } } } }
/** * Output the forums for a group in the edit screens * * @since bbPress (r3653) * @uses bp_get_current_group_id() * @uses bbp_get_group_forum_ids() * @uses bbp_has_forums() * @uses bbp_get_template_part() */ public function display_forums($offset = 0) { // Allow actions immediately before group forum output do_action('bbp_before_group_forum_display'); // Load up bbPress once $bbp = bbpress(); // Forum data $forum_slug = bp_action_variable($offset); $forum_ids = bbp_get_group_forum_ids(bp_get_current_group_id()); $forum_args = array('post__in' => $forum_ids, 'post_parent' => null); // Unset global queries $bbp->forum_query = new stdClass(); $bbp->topic_query = new stdClass(); $bbp->reply_query = new stdClass(); // Unset global ID's $bbp->current_forum_id = 0; $bbp->current_topic_id = 0; $bbp->current_reply_id = 0; $bbp->current_topic_tag_id = 0; // Reset the post data wp_reset_postdata(); // Allow admins special views $post_status = array(bbp_get_closed_status_id(), bbp_get_public_status_id()); if (is_super_admin() || current_user_can('moderate') || bp_is_item_admin() || bp_is_item_mod()) { $post_status = array_merge($post_status, array(bbp_get_spam_status_id(), bbp_get_trash_status_id())); } ?> <div id="bbpress-forums"> <?php // Looking at the group forum root if (empty($forum_slug) || 'page' == $forum_slug) { // Query forums and show them if they exist if (!empty($forum_ids) && bbp_has_forums($forum_args)) { // Only one forum found if (1 == $bbp->forum_query->post_count) { // Remove 'name' check for paginated requests if ('page' == $forum_slug) { $forum_args = array('post_type' => bbp_get_forum_post_type()); } else { $forum_args = array('name' => $forum_slug, 'post_type' => bbp_get_forum_post_type()); } // Get the forums $forums = get_posts($forum_args); bbp_the_forum(); // Forum exists if (!empty($forums)) { $forum = $forums[0]; // Suppress subforums for now add_filter('bbp_get_forum_subforum_count', '__return_false'); // Set up forum data bbpress()->current_forum_id = $forum->ID; bbp_set_query_name('bbp_single_forum'); ?> <h3><?php bbp_forum_title(); ?> </h3> <?php bbp_get_template_part('content', 'single-forum'); ?> <?php // Remove the subforum suppression filter remove_filter('bbp_get_forum_subforum_count', '__return_false'); ?> <?php } else { ?> <?php bbp_get_template_part('feedback', 'no-topics'); ?> <?php bbp_get_template_part('form', 'topic'); ?> <?php } // More than 1 forum found or group forum admin screen } elseif (1 < $bbp->forum_query->post_count) { ?> <h3><?php _e('Forums', 'bbpress'); ?> </h3> <?php bbp_get_template_part('loop', 'forums'); ?> <h3><?php _e('Topics', 'bbpress'); ?> </h3> <?php if (bbp_has_topics(array('post_parent__in' => $forum_ids))) { ?> <?php bbp_get_template_part('pagination', 'topics'); ?> <?php bbp_get_template_part('loop', 'topics'); ?> <?php bbp_get_template_part('pagination', 'topics'); ?> <?php bbp_get_template_part('form', 'topic'); ?> <?php } else { ?> <?php bbp_get_template_part('feedback', 'no-topics'); ?> <?php bbp_get_template_part('form', 'topic'); ?> <?php } // No forums found } else { ?> <div id="message" class="info"> <p><?php _e('This group does not currently have any forums.', 'bbpress'); ?> </p> </div> <?php } // No forums found } else { ?> <div id="message" class="info"> <p><?php _e('This group does not currently have any forums.', 'bbpress'); ?> </p> </div> <?php } // Single forum } elseif (bp_action_variable($offset) != $this->slug && bp_action_variable($offset) != $this->topic_slug && bp_action_variable($offset) != $this->reply_slug) { // Get forum data $forum_slug = bp_action_variable($offset); $forum_args = array('name' => $forum_slug, 'post_type' => bbp_get_forum_post_type()); $forums = get_posts($forum_args); // Forum exists if (!empty($forums)) { $forum = $forums[0]; // Set up forum data $forum_id = bbpress()->current_forum_id = $forum->ID; // Reset necessary forum_query attributes for forums loop to function $bbp->forum_query->query_vars['post_type'] = bbp_get_forum_post_type(); $bbp->forum_query->in_the_loop = true; $bbp->forum_query->post = get_post($forum_id); // Forum edit if (bp_action_variable($offset + 1) == $bbp->edit_id) { global $wp_query, $post; $wp_query->bbp_is_edit = true; $wp_query->bbp_is_forum_edit = true; $post = $forum; bbp_set_query_name('bbp_forum_form'); bbp_get_template_part('form', 'forum'); } else { bbp_set_query_name('bbp_single_forum'); ?> <h3><?php bbp_forum_title(); ?> </h3> <?php bbp_get_template_part('content', 'single-forum'); } } else { bbp_get_template_part('feedback', 'no-topics'); bbp_get_template_part('form', 'topic'); } // Single topic } elseif (bp_action_variable($offset) == $this->topic_slug) { // Get topic data $topic_slug = bp_action_variable($offset + 1); $topic_args = array('name' => $topic_slug, 'post_type' => bbp_get_topic_post_type(), 'post_status' => $post_status); $topics = get_posts($topic_args); // Topic exists if (!empty($topics)) { $topic = $topics[0]; // Set up topic data $topic_id = bbpress()->current_topic_id = $topic->ID; $forum_id = bbp_get_topic_forum_id($topic_id); // Reset necessary forum_query attributes for topics loop to function $bbp->forum_query->query_vars['post_type'] = bbp_get_forum_post_type(); $bbp->forum_query->in_the_loop = true; $bbp->forum_query->post = get_post($forum_id); // Reset necessary topic_query attributes for topics loop to function $bbp->topic_query->query_vars['post_type'] = bbp_get_topic_post_type(); $bbp->topic_query->in_the_loop = true; $bbp->topic_query->post = $topic; // Topic edit if (bp_action_variable($offset + 2) == $bbp->edit_id) { global $wp_query, $post; $wp_query->bbp_is_edit = true; $wp_query->bbp_is_topic_edit = true; $post = $topic; // Merge if (!empty($_GET['action']) && 'merge' == $_GET['action']) { bbp_set_query_name('bbp_topic_merge'); bbp_get_template_part('form', 'topic-merge'); // Split } elseif (!empty($_GET['action']) && 'split' == $_GET['action']) { bbp_set_query_name('bbp_topic_split'); bbp_get_template_part('form', 'topic-split'); // Edit } else { bbp_set_query_name('bbp_topic_form'); bbp_get_template_part('form', 'topic'); } // Single Topic } else { bbp_set_query_name('bbp_single_topic'); ?> <h3><?php bbp_topic_title(); ?> </h3> <?php bbp_get_template_part('content', 'single-topic'); } // No Topics } else { bbp_get_template_part('feedback', 'no-topics'); bbp_get_template_part('form', 'topic'); } // Single reply } elseif (bp_action_variable($offset) == $this->reply_slug) { // Get reply data $reply_slug = bp_action_variable($offset + 1); $reply_args = array('name' => $reply_slug, 'post_type' => bbp_get_reply_post_type()); $replies = get_posts($reply_args); if (empty($replies)) { return; } // Get the first reply $reply = $replies[0]; // Set up reply data $reply_id = bbpress()->current_reply_id = $reply->ID; $topic_id = bbp_get_reply_topic_id($reply_id); $forum_id = bbp_get_reply_forum_id($reply_id); // Reset necessary forum_query attributes for reply to function $bbp->forum_query->query_vars['post_type'] = bbp_get_forum_post_type(); $bbp->forum_query->in_the_loop = true; $bbp->forum_query->post = get_post($forum_id); // Reset necessary topic_query attributes for reply to function $bbp->topic_query->query_vars['post_type'] = bbp_get_topic_post_type(); $bbp->topic_query->in_the_loop = true; $bbp->topic_query->post = get_post($topic_id); // Reset necessary reply_query attributes for reply to function $bbp->reply_query->query_vars['post_type'] = bbp_get_reply_post_type(); $bbp->reply_query->in_the_loop = true; $bbp->reply_query->post = $reply; if (bp_action_variable($offset + 2) == $bbp->edit_id) { global $wp_query, $post; $wp_query->bbp_is_edit = true; $wp_query->bbp_is_reply_edit = true; $post = $reply; bbp_set_query_name('bbp_reply_form'); bbp_get_template_part('form', 'reply'); } } ?> </div> <?php // Allow actions immediately after group forum output do_action('bbp_after_group_forum_display'); }