/** * @param EM_Event $EM_Event */ function bp_em_group_event_save($result, $EM_Event) { if (is_object($EM_Event) && !empty($EM_Event->event_id)) { if (!empty($_REQUEST['group_id']) && is_numeric($_REQUEST['group_id']) && bp_is_active('groups')) { //we have been requested an event creation tied to a group, so does this group exist, and does this person have admin rights to it? if (groups_is_user_admin(get_current_user_id(), $_REQUEST['group_id'])) { $EM_Event->group_id = $_REQUEST['group_id']; } if (!empty($EM_Event->group_id)) { //if group is private, make it private $group = groups_get_group(array('group_id' => $EM_Event->group_id)); $is_member = groups_is_user_member(get_current_user_id(), $EM_Event->group_id) || groups_is_user_admin(get_current_user_id(), $EM_Event->group_id) || groups_is_user_mod(get_current_user_id(), $EM_Event->group_id); if ($group->status != 'public' && $is_member) { //Make sure event status is private and set post status to private global $wpdb; $EM_Event->event_private = 1; $wpdb->update($wpdb->posts, array('post_status' => 'private'), array('ID' => $EM_Event->post_id)); $wpdb->update(EM_EVENTS_TABLE, array('event_private' => 1), array('event_id' => $EM_Event->event_id)); } } } else { $EM_Event->group_id = null; } } return $result; }
/** * Can the current user post to group blog * @global type $bp * @return type */ function bcg_current_user_can_post() { $user_id = bp_loggedin_user_id(); $group_id = bp_get_current_group_id(); $can_post = is_user_logged_in() && (groups_is_user_admin($user_id, $group_id) || groups_is_user_mod($user_id, $group_id)); return apply_filters('bcg_current_user_can_post', $can_post, $group_id, $user_id); }
public function test_groups_is_user_mod_should_return_false_when_user_is_also_banned() { $this->add_user_to_group(self::$user, self::$groups[0], array('is_mod' => false)); $this->add_user_to_group(self::$user, self::$groups[1], array('is_mod' => true)); $m = new BP_Groups_Member(self::$user, self::$groups[1]); $m->ban(); $this->assertEquals(false, groups_is_user_mod(self::$user, self::$groups[1])); }
/** * Test whether logged in user is a moderator * * @param Array $moderator_roles Moderator roles * @return bool $moderator True if moderator False if not */ function wpmudev_chat_is_moderator($chat_session, $debug = false) { global $current_user, $bp; if ($chat_session['session_type'] === "bp-group") { if (function_exists('groups_is_user_mod') && function_exists('groups_is_user_admin')) { if (groups_is_user_mod($bp->loggedin_user->id, $bp->groups->current_group->id) || groups_is_user_admin($bp->loggedin_user->id, $bp->groups->current_group->id) || is_super_admin()) { return true; } } return false; } if ($chat_session['session_type'] === "private") { global $wpmudev_chat; if (!isset($chat_session['invite-info']['message']['host']['auth_hash'])) { return false; } else { if (!isset($wpmudev_chat->chat_auth['auth_hash'])) { return false; } else { if ($chat_session['invite-info']['message']['host']['auth_hash'] === $wpmudev_chat->chat_auth['auth_hash']) { return true; } else { return false; } } } } // all others // If the chat session doesn't have any defined moderator roles then no need to go further. if (!is_array($chat_session['moderator_roles']) || !count($chat_session['moderator_roles'])) { return false; } if (!is_multisite()) { if ($current_user->ID) { foreach ($chat_session['moderator_roles'] as $role) { if (in_array($role, $current_user->roles)) { return true; } } } } else { // We only consider super admins IF the normal 'administrator' role is set. if (is_super_admin() && array_search('administrator', $chat_session['moderator_roles']) !== false) { return true; } if ($current_user->ID) { foreach ($chat_session['moderator_roles'] as $role) { if (in_array($role, $current_user->roles)) { return true; } } } } return false; }
function rtmedia_media_actions_backbone($media_array) { $context_id = $media_array->context_id; $user_id = get_current_user_id(); if (is_rt_admin() || function_exists('groups_is_user_mod') && groups_is_user_mod($user_id, $context_id) || $media_array->media_author == get_current_user_id()) { $media_array->media_actions = "<div class='rtmedia-gallery-item-actions'><a href='" . $media_array->rt_permalink . "edit' class='no-popup' target='_blank' title='" . __('Edit this media', 'buddypress-media') . "'><i class='dashicons dashicons-edit rtmicon'></i>" . __('Edit', 'buddypress-media') . "</a><a href='#' class='no-popup rtm-delete-media' title='" . __('Delete this media', 'buddypress-media') . "' ><i class='dashicons dashicons-trash rtmicon'></i>" . __('Delete', 'buddypress-media') . "</a></div>"; } else { $media_array->media_actions = ""; } return $media_array; }
/** * Here you can see more customization of the config options */ function __construct() { global $buddyforms, $buddyforms_user_can; $buddyforms_pig = get_option('buddyforms_pig_options'); $this->post_in_group_form_slug = groups_get_groupmeta(bp_get_current_group_id(), '_bf_pig_form_slug', true); $this->buddyforms_pig = groups_get_groupmeta(bp_get_current_group_id(), '_buddyforms_pig', true); $buddyforms_user_can = false; //$this->enable_create_step = false; $form_slug = $this->post_in_group_form_slug; $name = $buddyforms[$form_slug]['name']; if (isset($this->buddyforms_pig['create'])) { switch ($this->buddyforms_pig['create']) { case 'admin': if (groups_is_user_admin(bp_loggedin_user_id(), bp_get_current_group_id())) { $buddyforms_user_can = true; } break; case 'mod': if (groups_is_user_mod(bp_loggedin_user_id(), bp_get_current_group_id()) || groups_is_user_admin(bp_loggedin_user_id(), bp_get_current_group_id())) { $buddyforms_user_can = true; } break; case 'member': default: if (groups_is_user_member(bp_loggedin_user_id(), bp_get_current_group_id())) { $buddyforms_user_can = true; } break; } } $args = array('slug' => $form_slug, 'name' => $name); switch ($buddyforms_pig['permission']) { case 'all': add_action('bp_after_group_settings_admin', array($this, 'bp_pig_after_group_manage_members_admin'), 1, 1); add_action('groups_group_settings_edited', array($this, 'bf_pig_groups_group_settings_edited'), 10, 1); add_action('bp_after_group_settings_creation_step', array($this, 'bp_pig_after_group_manage_members_admin'), 1, 1); add_action('groups_create_group_step_save_group-settings', array($this, 'bf_pig_groups_group_settings_edited'), 10, 1); break; case 'group-admin': add_action('bp_after_group_settings_admin', array($this, 'bp_pig_after_group_manage_members_admin'), 1, 1); add_action('groups_group_settings_edited', array($this, 'bf_pig_groups_group_settings_edited'), 10, 1); break; case 'admin': if (is_super_admin()) { add_action('bp_after_group_settings_admin', array($this, 'bp_pig_after_group_manage_members_admin'), 1, 1); add_action('groups_group_settings_edited', array($this, 'bf_pig_groups_group_settings_edited'), 10, 1); } break; } parent::init($args); }
function before_render() { if (!class_exists('BuddyPress') || !bp_is_active('groups')) { return false; } $this->get(); // if group id is not set, don't render "Set featured" if (empty($this->group_id)) { return false; } $user_id = get_current_user_id(); // if current is not group moderator or group admin, don't render "Set featured" if (!groups_is_user_mod($user_id, $this->group_id) && !groups_is_user_admin($user_id, $this->group_id) && !is_rt_admin()) { return false; } // if current media is not any group media, don't render "Set featured" if (!(isset($this->settings[$this->media->media_type]) && $this->settings[$this->media->media_type]) || isset($this->media->context) && 'group' != $this->media->context) { return false; } if (isset($this->action_query) && isset($this->action_query->id) && $this->action_query->id == $this->featured) { $this->label = $this->undo_label; } }
/** * Check whether the current user meets an access condition. * * @param string $access_condition 'anyone', 'loggedin', 'member', * 'mod', 'admin' or 'noone'. * @return bool */ protected function user_meets_access_condition($access_condition) { $group = groups_get_group(array('group_id' => $this->group_id)); switch ($access_condition) { case 'admin': $meets_condition = groups_is_user_admin(bp_loggedin_user_id(), $this->group_id); break; case 'mod': $meets_condition = groups_is_user_mod(bp_loggedin_user_id(), $this->group_id); break; case 'member': $meets_condition = groups_is_user_member(bp_loggedin_user_id(), $this->group_id); break; case 'loggedin': $meets_condition = is_user_logged_in(); break; case 'noone': $meets_condition = false; break; case 'anyone': default: $meets_condition = true; break; } return $meets_condition; }
/** * In some places in CP, cp_check_permissions() is used as a wrapper for current_user_can(), * which maps against a built-in user role rather than a custom cp_ cap. This method * requires a different kind of workaround from map_meta_cap() (above). */ function has_cap_edit($retval, $type) { if (bp_is_group()) { $edit_delete_role = isset($this->group_settings['edit_delete_role']) ? $this->group_settings['edit_delete_role'] : ''; switch ($edit_delete_role) { case 'admins-mods-owners': // The way that CP handles redirects is inconsistent, // so we do some manual checks to make sure a delete GET // argument is for real if (isset($_GET['cp-delete-task-id'])) { $maybe_item_id = $_GET['cp-delete-task-id']; } else { if (isset($_GET['cp-delete-task-list-id'])) { $maybe_item_id = $_GET['cp-delete-task-list-id']; } } if (!empty($maybe_item_id)) { $maybe_item = get_post($maybe_item_id); if (isset($maybe_item->post_status) && 'trash' != $maybe_item->post_status) { $is_delete_attempt = true; } } // Check to see whether this is the main project loop, // in which case there's no item author if (!bp_action_variables()) { $is_project_list = true; } if (isset($_POST['cp-edit-task-id'])) { $item_id = $_POST['cp-edit-task-id']; $item = get_post($item_id); $item_author = $item->post_author; } else { if (isset($_POST['cp-edit-task-list-id'])) { $item_id = $_POST['cp-edit-task-list-id']; $item = get_post($item_id); $item_author = $item->post_author; } else { if (isset($_POST['cp-edit-project-id'])) { $item_id = $_POST['cp-edit-project-id']; $item = get_post($item_id); $item_author = $item->post_author; } else { if (!empty($is_delete_attempt)) { $item_author = $maybe_item->post_author; } else { if (!empty($is_project_list)) { $item_author = 0; } else { $item_author = get_the_author_meta('ID'); } } } } } if (groups_is_user_admin(bp_loggedin_user_id(), bp_get_current_group_id()) || groups_is_user_mod(bp_loggedin_user_id(), bp_get_current_group_id()) || $item_author == bp_loggedin_user_id()) { $retval = 'exist'; } else { $retval = 'do_not_allow'; } break; case 'group-members': if (groups_is_user_member(bp_loggedin_user_id(), bp_get_current_group_id())) { $retval = 'exist'; } else { $retval = 'do_not_allow'; } break; } } return $retval; }
/** * bp_groupblog_upgrade_user( $user_id, $group_id, $blog_id ) * * Subscribes user in question to blog in question * This code was initially inspired by Burt Adsit re-interpreted by Boone */ function bp_groupblog_upgrade_user($user_id, $group_id, $blog_id = false) { global $bp; if (!$blog_id) { $blog_id = groups_get_groupmeta($group_id, 'groupblog_blog_id'); } // If the group has no blog linked, get the heck out of here! if (!$blog_id) { return; } // Set up some variables $groupblog_silent_add = groups_get_groupmeta($group_id, 'groupblog_silent_add'); $groupblog_default_member_role = groups_get_groupmeta($group_id, 'groupblog_default_member_role'); $groupblog_default_mod_role = groups_get_groupmeta($group_id, 'groupblog_default_mod_role'); $groupblog_default_admin_role = groups_get_groupmeta($group_id, 'groupblog_default_admin_role'); $groupblog_creator_role = 'admin'; $user = new WP_User($user_id); $user_role = bp_groupblog_get_user_role($user_id, $user->data->user_login, $blog_id); // Get the current user's group status. For efficiency, we try first to look at the // current group object if (isset($bp->groups->current_group->id) && $group_id == $bp->groups->current_group->id) { // It's tricky to walk through the admin/mod lists over and over, so let's format if (empty($bp->groups->current_group->adminlist)) { $bp->groups->current_group->adminlist = array(); if (isset($bp->groups->current_group->admins)) { foreach ((array) $bp->groups->current_group->admins as $admin) { if (isset($admin->user_id)) { $bp->groups->current_group->adminlist[] = $admin->user_id; } } } } if (empty($bp->groups->current_group->modlist)) { $bp->groups->current_group->modlist = array(); if (isset($bp->groups->current_group->mods)) { foreach ((array) $bp->groups->current_group->mods as $mod) { if (isset($mod->user_id)) { $bp->groups->current_group->modlist[] = $mod->user_id; } } } } if (in_array($user_id, $bp->groups->current_group->adminlist)) { $user_group_status = 'admin'; } elseif (in_array($user_id, $bp->groups->current_group->modlist)) { $user_group_status = 'mod'; } else { // I'm assuming that if a user is passed to this function, they're a member // Doing an actual lookup is costly. Try to look for an efficient method $user_group_status = 'member'; } } else { if (groups_is_user_admin($user_id, $group_id)) { $user_group_status = 'admin'; } else { if (groups_is_user_mod($user_id, $group_id)) { $user_group_status = 'mod'; } else { if (groups_is_user_member($user_id, $group_id)) { $user_group_status = 'member'; } else { return false; } } } } switch ($user_group_status) { case 'admin': $default_role = $groupblog_default_admin_role; break; case 'mod': $default_role = $groupblog_default_mod_role; break; case 'member': default: $default_role = $groupblog_default_member_role; break; } if ($user_role == $default_role && $groupblog_silent_add == true) { return false; } if (!$groupblog_silent_add) { $default_role = 'subscriber'; } add_user_to_blog($blog_id, $user_id, $default_role); do_action('bp_groupblog_upgrade_user', $user_id, $user_role, $default_role); }
/** * Maps the user's capabilities for the group's context * * @package WP Idea Stream * @subpackage buddypress/groups * * @since 2.0.0 * * @param array $caps Capabilities for meta capability * @param string $cap Capability name * @param int $user_id User id * @param mixed $args Arguments * @uses bp_is_group() to make sure the user is displaying a group * @uses groups_get_current_group() to get the current group object * @uses groups_is_user_member() to check if the user is a member of the group * @uses groups_is_user_admin() to check if the user is an admin of the group * @uses groups_is_user_mod() to check if the user is a mod of the group * @uses apply_filters() call 'wp_idea_stream_buddypress_group_map_meta_caps' to override caps * @return array Actual capabilities for meta capability */ public function group_map_meta_caps($caps = array(), $cap = '', $user_id = 0, $args = array()) { // Group meta caps territory is limited to groups if (!bp_is_group() && !self::is_group_admin() && !wp_idea_stream_buddypress_is_delete_account()) { return $caps; } // Not logged in user can't do anything in groups if (empty($user_id)) { return array('do_not_allow'); } // Let's get the current group (we'll have the status available) $group = groups_get_current_group(); if (empty($group->id) && !empty($this->group_delete)) { $group = new StdClass(); $group->id = $this->group_delete; } switch ($cap) { case 'publish_ideas': case 'comment_group_ideas': case 'rate_ideas': case 'read_private_ideas': case 'read_idea': if (!empty($group->id) && groups_is_user_member($user_id, $group->id)) { $caps = array('exist'); /** * We need a else there to be sure an admin can remove ideas comment * from the group Administration screen */ } else { $caps = array('manage_options'); } break; case 'edit_idea': if (!empty($group->id)) { // Group admins can edit idea if (groups_is_user_admin($user_id, $group->id)) { $caps = array('exist'); // Is the author a group member ? } else { if (groups_is_user_member($user_id, $group->id)) { $_post = get_post($args[0]); if (!empty($_post)) { $caps = array(); if (!is_admin() && (int) $user_id === (int) $_post->post_author) { $caps = array('exist'); // Unknown, so map to manage_options } else { $caps = array('manage_options'); } } // Defaults to manage_options } else { $caps = array('manage_options'); } } /** * We need a else there to be sure an admin can edit group ideas * from the group Administration screen */ } else { $caps = array('manage_options'); } break; case 'remove_group_ideas': case 'edit_others_ideas': case 'edit_private_ideas': case 'edit_published_ideas': case 'edit_ideas': if (!empty($group->id) && groups_is_user_admin($user_id, $group->id)) { $caps = array('exist'); /** * We need a else there to be sure an admin can remove group ideas * from the group Administration screen */ } else { $caps = array('manage_options'); } break; case 'edit_comment': case 'trash_group_idea_comments': case 'spam_group_idea_comments': if (!empty($group->id) && (groups_is_user_admin($user_id, $group->id) || groups_is_user_mod($user_id, $group->id))) { $caps = array('exist'); /** * We need a else there to be sure an admin can trash/span ideas comment * from the group Administration screen */ } else { $caps = array('manage_options'); } break; } /** * @param array $caps Capabilities for meta capability * @param string $cap Capability name * @param int $user_id User id * @param mixed $args Arguments */ return apply_filters('wp_idea_stream_buddypress_group_map_meta_caps', $caps, $cap, $user_id, $args, $group); }
function groups_setup_nav() { global $bp, $current_blog; global $group_obj; if ($group_id = BP_Groups_Group::group_exists($bp->current_action)) { /* This is a single group page. */ $bp->is_single_item = true; $group_obj = new BP_Groups_Group($group_id); /* Using "item" not "group" for generic support in other components. */ if (is_site_admin()) { $bp->is_item_admin = 1; } else { $bp->is_item_admin = groups_is_user_admin($bp->loggedin_user->id, $group_obj->id); } /* If the user is not an admin, check if they are a moderator */ if (!$bp->is_item_admin) { $bp->is_item_mod = groups_is_user_mod($bp->loggedin_user->id, $group_obj->id); } /* Is the logged in user a member of the group? */ $is_member = groups_is_user_member($bp->loggedin_user->id, $group_obj->id) ? true : false; /* Should this group be visible to the logged in user? */ $is_visible = 'public' == $group_obj->status || $is_member ? true : false; } /* Add 'Groups' to the main navigation */ bp_core_add_nav_item(__('Groups', 'buddypress'), $bp->groups->slug); if ($bp->displayed_user->id) { bp_core_add_nav_default($bp->groups->slug, 'groups_screen_my_groups', 'my-groups'); } $groups_link = $bp->loggedin_user->domain . $bp->groups->slug . '/'; /* Add the subnav items to the groups nav item */ bp_core_add_subnav_item($bp->groups->slug, 'my-groups', __('My Groups', 'buddypress'), $groups_link, 'groups_screen_my_groups', 'my-groups-list'); bp_core_add_subnav_item($bp->groups->slug, 'create', __('Create a Group', 'buddypress'), $groups_link, 'groups_screen_create_group', false, bp_is_home()); bp_core_add_subnav_item($bp->groups->slug, 'invites', __('Invites', 'buddypress'), $groups_link, 'groups_screen_group_invites', false, bp_is_home()); if ($bp->current_component == $bp->groups->slug) { if (bp_is_home() && !$bp->is_single_item) { $bp->bp_options_title = __('My Groups', 'buddypress'); } else { if (!bp_is_home() && !$bp->is_single_item) { $bp->bp_options_avatar = bp_core_get_avatar($bp->displayed_user->id, 1); $bp->bp_options_title = $bp->displayed_user->fullname; } else { if ($bp->is_single_item) { // We are viewing a single group, so set up the // group navigation menu using the $group_obj global. /* 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_variables[0]; array_shift($bp->action_variables); $bp->bp_options_title = $group_obj->name; $bp->bp_options_avatar = '<img src="' . $group_obj->avatar_thumb . '" alt="Group Avatar Thumbnail" />'; $group_link = $bp->root_domain . '/' . $bp->groups->slug . '/' . $group_obj->slug . '/'; // If this is a private or hidden group, does the user have access? if ('private' == $group_obj->status || 'hidden' == $group_obj->status) { if (groups_is_user_member($bp->loggedin_user->id, $group_obj->id) && is_user_logged_in()) { $has_access = true; } else { $has_access = false; } } else { $has_access = true; } // Reset the existing subnav items bp_core_reset_subnav_items($bp->groups->slug); bp_core_add_nav_default($bp->groups->slug, 'groups_screen_group_home', 'home'); bp_core_add_subnav_item($bp->groups->slug, 'home', __('Home', 'buddypress'), $group_link, 'groups_screen_group_home', 'group-home'); // If the user is a group mod or more, then show the group admin nav item */ if ($bp->is_item_mod || $bp->is_item_admin) { bp_core_add_subnav_item($bp->groups->slug, 'admin', __('Admin', 'buddypress'), $group_link, 'groups_screen_group_admin', 'group-admin', $bp->is_item_admin + (int) $bp->is_item_mod); } // If this is a private group, and the user is not a member, show a "Request Membership" nav item. if (!$has_access && !groups_check_for_membership_request($bp->loggedin_user->id, $group_obj->id) && $group_obj->status == 'private') { bp_core_add_subnav_item($bp->groups->slug, 'request-membership', __('Request Membership', 'buddypress'), $group_link, 'groups_screen_group_request_membership', 'request-membership'); } if ($has_access && $group_obj->enable_forum && function_exists('bp_forums_setup')) { bp_core_add_subnav_item($bp->groups->slug, 'forum', __('Forum', 'buddypress'), $group_link, 'groups_screen_group_forum', 'group-forum', $is_visible); } if ($has_access && $group_obj->enable_wire && function_exists('bp_wire_install')) { bp_core_add_subnav_item($bp->groups->slug, 'wire', __('Wire', 'buddypress'), $group_link, 'groups_screen_group_wire', 'group-wire', $is_visible); } if ($has_access && $group_obj->enable_photos && function_exists('bp_gallery_install')) { bp_core_add_subnav_item($bp->groups->slug, 'photos', __('Photos', 'buddypress'), $group_link, 'groups_screen_group_photos', 'group-photos', $is_visible); } if ($has_access) { bp_core_add_subnav_item($bp->groups->slug, 'members', __('Members', 'buddypress'), $group_link, 'groups_screen_group_members', 'group-members', $is_visible); } if (is_user_logged_in() && groups_is_user_member($bp->loggedin_user->id, $group_obj->id)) { if (function_exists('friends_install')) { bp_core_add_subnav_item($bp->groups->slug, 'send-invites', __('Send Invites', 'buddypress'), $group_link, 'groups_screen_group_invite', 'group-invite', $is_member); } bp_core_add_subnav_item($bp->groups->slug, 'leave-group', __('Leave Group', 'buddypress'), $group_link, 'groups_screen_group_leave', 'group-leave', $is_member); } } } } } }
/** * Can a given user associate a doc with a given group? */ public static function user_can_associate_doc_with_group($user_id, $group_id) { _deprecated_function(__FUNCTION__, '1.8', "Use current_user_can( 'bp_docs_associate_with_group' ) instead"); $group = groups_get_group(array('group_id' => intval($group_id))); // No one can associate anything with a non-existent group if (empty($group->name)) { return false; } // Site admins can do anything if (bp_current_user_can('bp_moderate')) { return true; } // Non-group-members can't associate a doc with a group if (!groups_is_user_member($user_id, $group_id)) { return false; } // Check against group settings. Default to 'member' // @todo Abstract default settings out better $group_settings = bp_docs_get_group_settings($group_id); $can_create = isset($group_settings['can-create']) ? $group_settings['can-create'] : 'member'; if ('admin' == $can_create) { return (bool) groups_is_user_admin($user_id, $group_id); } else { if ('mod' == $can_create) { return groups_is_user_admin($user_id, $group_id) || groups_is_user_mod($user_id, $group_id); } } return true; }
/** * Setup globals * * The BP_GROUPS_SLUG constant is deprecated, and only used here for * backwards compatibility. * * @since BuddyPress (1.5) * @global BuddyPress $bp The one true BuddyPress instance */ function setup_globals() { 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'); // All globals for messaging component. // Note that global_tables is included in this array. $globals = array('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); parent::setup_globals($globals); /** Single Group Globals **********************************************/ // Are we viewing a single group? if (bp_is_groups_component() && ($group_id = BP_Groups_Group::group_exists(bp_current_action()))) { $bp->is_single_item = true; $current_group_class = apply_filters('bp_groups_current_group_class', 'BP_Groups_Group'); $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 (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() || 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 (!bp_is_current_action('home') && !bp_is_current_action('request-membership')) { // 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; }
/** * bp_groupblog_options_nav() * * Manually create the navigation for the group since we can't fetch any other way. * You should manually add items if you have third party plugins that add a menu item. * * The BuddyPress function we duplicate is called bp_get_options_nav() */ function bp_groupblog_options_nav() { global $bp; $checks = get_site_option('bp_groupblog_blog_defaults_options'); ?> <li id="home-personal-li"<?php if ($checks['deep_group_integration']) { ?> class="current selected"<?php } ?> > <a id="home" href="<?php bp_group_permalink(); ?> "><?php _e('Home', 'groupblog'); ?> </a> </li> <?php if (groups_is_user_admin($bp->loggedin_user->id, bp_get_group_id()) || groups_is_user_mod($bp->loggedin_user->id, bp_get_group_id())) { ?> <li id="admin-personal-li" > <a id="admin" href="<?php bp_group_permalink(); ?> admin/"><?php _e('Admin', 'groupblog'); ?> </a> </li> <?php } ?> <?php if (bp_group_is_visible()) { ?> <?php if (bp_groupblog_is_blog_enabled(bp_get_group_id())) { ?> <?php if (!$checks['deep_group_integration']) { ?> <li id="<?php echo BP_GROUPBLOG_SLUG; ?> -personal-li"<?php //if ( is_page() ) : ?> class="current selected"<?php //endif; ?> > <a id="<?php echo BP_GROUPBLOG_SLUG; ?> " href="<?php bp_group_permalink(); ?> blog/"><?php _e('Blog', 'groupblog'); ?> </a> </li> <?php } ?> <?php } ?> <?php if (bp_is_active('forums') && (function_exists('bp_forums_is_installed_correctly') && bp_group_is_forum_enabled() && !(int) bp_get_option('bp-disable-forum-directory')) && bp_forums_is_installed_correctly()) { ?> <li id="<?php echo BP_FORUMS_SLUG; ?> -personal-li" > <a id="<?php echo BP_FORUMS_SLUG; ?> " href="<?php bp_group_permalink(); ?> forum/"><?php _e('Forum', 'groupblog'); ?> </a> </li> <?php } ?> <li id="<?php echo BP_MEMBERS_SLUG; ?> -personal-li" > <a id="<?php echo BP_MEMBERS_SLUG; ?> " href="<?php bp_group_permalink(); ?> members/"><?php _e('Members', 'groupblog'); ?> (<?php bp_group_total_members(); ?> )</a> </li> <li id="invite-personal-li" > <a id="invite" href="<?php bp_group_permalink(); ?> send-invites/"><?php _e('Send Invites', 'groupblog'); ?> </a> </li> <?php } elseif (!bp_group_is_visible() && bp_get_group_status() != 'hidden') { ?> <li id="request-membership-personal-li" > <a id="request-membership" href="<?php bp_group_permalink(); ?> request-membership/"><?php _e('Request Membership', 'groupblog'); ?> </a> </li> <?php } ?> <?php }
function groups_setup_nav() { global $bp; if ( $bp->current_component == $bp->groups->slug && $group_id = BP_Groups_Group::group_exists($bp->current_action) ) { /* This is a single group page. */ $bp->is_single_item = true; $bp->groups->current_group = new BP_Groups_Group( $group_id ); /* Using "item" not "group" for generic support in other components. */ if ( is_super_admin() ) $bp->is_item_admin = 1; else $bp->is_item_admin = groups_is_user_admin( $bp->loggedin_user->id, $bp->groups->current_group->id ); /* If the user is not an admin, check if they are a moderator */ if ( !$bp->is_item_admin ) $bp->is_item_mod = groups_is_user_mod( $bp->loggedin_user->id, $bp->groups->current_group->id ); /* Is the logged in user a member of the group? */ $bp->groups->current_group->is_user_member = ( is_user_logged_in() && groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) ) ? true : false; /* Should this group be visible to the logged in user? */ $bp->groups->current_group->is_group_visible_to_member = ( 'public' == $bp->groups->current_group->status || $is_member ) ? true : false; } /* Add 'Groups' to the main navigation */ bp_core_new_nav_item( array( 'name' => sprintf( __( 'Groups <span>(%d)</span>', 'buddypress' ), groups_total_groups_for_user() ), 'slug' => $bp->groups->slug, 'position' => 70, 'screen_function' => 'groups_screen_my_groups', 'default_subnav_slug' => 'my-groups', 'item_css_id' => $bp->groups->id ) ); $groups_link = $bp->loggedin_user->domain . $bp->groups->slug . '/'; /* Add the subnav items to the groups nav item */ bp_core_new_subnav_item( array( 'name' => __( 'My Groups', 'buddypress' ), 'slug' => 'my-groups', 'parent_url' => $groups_link, 'parent_slug' => $bp->groups->slug, 'screen_function' => 'groups_screen_my_groups', 'position' => 10, 'item_css_id' => 'groups-my-groups' ) ); bp_core_new_subnav_item( array( 'name' => __( 'Invites', 'buddypress' ), 'slug' => 'invites', 'parent_url' => $groups_link, 'parent_slug' => $bp->groups->slug, 'screen_function' => 'groups_screen_group_invites', 'position' => 30, 'user_has_access' => bp_is_my_profile() ) ); if ( $bp->current_component == $bp->groups->slug ) { if ( bp_is_my_profile() && !$bp->is_single_item ) { $bp->bp_options_title = __( 'My Groups', 'buddypress' ); } else if ( !bp_is_my_profile() && !$bp->is_single_item ) { $bp->bp_options_avatar = bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => 'thumb' ) ); $bp->bp_options_title = $bp->displayed_user->fullname; } else if ( $bp->is_single_item ) { // We are viewing a single group, so set up the // group navigation menu using the $bp->groups->current_group global. /* 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_variables[0]; array_shift($bp->action_variables); $bp->bp_options_title = $bp->groups->current_group->name; if ( !$bp->bp_options_avatar = bp_core_fetch_avatar( array( 'item_id' => $bp->groups->current_group->id, 'object' => 'group', 'type' => 'thumb', 'avatar_dir' => 'group-avatars', 'alt' => __( 'Group Avatar', 'buddypress' ) ) ) ) $bp->bp_options_avatar = '<img src="' . esc_attr( $group->avatar_full ) . '" class="avatar" alt="' . esc_attr( $group->name ) . '" />'; $group_link = $bp->root_domain . '/' . $bp->groups->slug . '/' . $bp->groups->current_group->slug . '/'; // If this is a private or hidden group, does the user have access? if ( 'private' == $bp->groups->current_group->status || 'hidden' == $bp->groups->current_group->status ) { if ( $bp->groups->current_group->is_user_member && is_user_logged_in() || is_super_admin() ) $bp->groups->current_group->user_has_access = true; else $bp->groups->current_group->user_has_access = false; } else { $bp->groups->current_group->user_has_access = true; } /* Reset the existing subnav items */ bp_core_reset_subnav_items($bp->groups->slug); /* Add a new default subnav item for when the groups nav is selected. */ bp_core_new_nav_default( array( 'parent_slug' => $bp->groups->slug, 'screen_function' => 'groups_screen_group_home', 'subnav_slug' => 'home' ) ); /* Add the "Home" subnav item, as this will always be present */ bp_core_new_subnav_item( array( 'name' => __( 'Home', 'buddypress' ), 'slug' => 'home', 'parent_url' => $group_link, 'parent_slug' => $bp->groups->slug, 'screen_function' => 'groups_screen_group_home', 'position' => 10, 'item_css_id' => 'home' ) ); /* If the user is a group mod or more, then show the group admin nav item */ if ( $bp->is_item_mod || $bp->is_item_admin ) bp_core_new_subnav_item( array( 'name' => __( 'Admin', 'buddypress' ), 'slug' => 'admin', 'parent_url' => $group_link, 'parent_slug' => $bp->groups->slug, 'screen_function' => 'groups_screen_group_admin', 'position' => 20, 'user_has_access' => ( $bp->is_item_admin + (int)$bp->is_item_mod ), 'item_css_id' => 'admin' ) ); // If this is a private group, and the user is not a member, show a "Request Membership" nav item. if ( !is_super_admin() && is_user_logged_in() && !$bp->groups->current_group->is_user_member && !groups_check_for_membership_request( $bp->loggedin_user->id, $bp->groups->current_group->id ) && $bp->groups->current_group->status == 'private' ) bp_core_new_subnav_item( array( 'name' => __( 'Request Membership', 'buddypress' ), 'slug' => 'request-membership', 'parent_url' => $group_link, 'parent_slug' => $bp->groups->slug, 'screen_function' => 'groups_screen_group_request_membership', 'position' => 30 ) ); if ( $bp->groups->current_group->enable_forum && function_exists('bp_forums_setup') ) bp_core_new_subnav_item( array( 'name' => __( 'Forum', 'buddypress' ), 'slug' => 'forum', 'parent_url' => $group_link, 'parent_slug' => $bp->groups->slug, 'screen_function' => 'groups_screen_group_forum', 'position' => 40, 'user_has_access' => $bp->groups->current_group->user_has_access, 'item_css_id' => 'forums' ) ); bp_core_new_subnav_item( array( 'name' => sprintf( __( 'Members (%s)', 'buddypress' ), number_format( $bp->groups->current_group->total_member_count ) ), 'slug' => 'members', 'parent_url' => $group_link, 'parent_slug' => $bp->groups->slug, 'screen_function' => 'groups_screen_group_members', 'position' => 60, 'user_has_access' => $bp->groups->current_group->user_has_access, 'item_css_id' => 'members' ) ); if ( is_user_logged_in() && groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) ) { if ( function_exists('friends_install') ) bp_core_new_subnav_item( array( 'name' => __( 'Send Invites', 'buddypress' ), 'slug' => 'send-invites', 'parent_url' => $group_link, 'parent_slug' => $bp->groups->slug, 'screen_function' => 'groups_screen_group_invite', 'item_css_id' => 'invite', 'position' => 70, 'user_has_access' => $bp->groups->current_group->user_has_access ) ); } } } do_action( 'groups_setup_nav', $bp->groups->current_group->user_has_access ); }
/** * Is the current user a moderator of the current group * * @since bbPress (r4632) * * @uses is_user_logged_in() * @uses bp_is_group() * @uses bbpress() * @uses get_current_user_id() * @uses bp_get_current_group_id() * @uses groups_is_user_admin() * @return bool If current user is a moderator of the current group */ function bbp_group_is_mod() { // Bail if user is not logged in or not looking at a group if (!is_user_logged_in() || !bp_is_group()) { return false; } $bbp = bbpress(); // Set the global if not set if (!isset($bbp->current_user->is_group_mod)) { $bbp->current_user->is_group_mod = groups_is_user_mod(get_current_user_id(), bp_get_current_group_id()); } // Return the value return (bool) $bbp->current_user->is_group_mod; }
/** * Can the current user moderate posts? * Mods and Admins of groups that posts are sydicated to should be able to disassociate posts from that group * (but NOT the origin group-- they can edit it there.) * * @return boolean */ function ccgn_current_user_can_moderate($post_id = null) { // We need to know the origin group of this post, so if we can't figure out the post_id and the origin group, bail. if (!($post_id = $post_id ? $post_id : get_the_ID())) { return false; } if (!($origin_group = ccgn_get_origin_group($post_id))) { return false; } $can_mod = false; $user_id = bp_loggedin_user_id(); $current_group = bp_get_current_group_id(); // User must be a mod or admin in the current group (and the current group can't be the origin group) if ($origin_group != $current_group && $user_id) { $can_mod = current_user_can('activate_plugins') || groups_is_user_admin($user_id, $origin_group) || groups_is_user_mod($user_id, $origin_group); } return apply_filters('ccgn_current_user_can_moderate', $can_mod, $current_group, $origin_group, $user_id); }
/** * The routine run after the user clicks Save from your admin tab * * You'll be pulling your data out of the $_POST global. Be sure to * sanitize as necessary. */ function edit_screen_save() { global $bp, $wpdb; if (!bp_is_group_admin_screen($this->slug)) { return false; } if (!isset($_POST['wpmudev_chat_settings_save_wpnonce']) || !wp_verify_nonce($_POST['wpmudev_chat_settings_save_wpnonce'], 'wpmudev_chat_settings_save')) { return false; } // Controls our menu visibility. See the __construct logic. if (isset($_POST[$this->settings_slug . '_enable']) && $_POST[$this->settings_slug . '_enable'] == "on") { $enabled = "yes"; } else { $enabled = "no"; } groups_update_groupmeta($bp->groups->current_group->id, $this->settings_slug . '_enable', $enabled); if (!isset($_POST['chat'])) { return false; } if (groups_is_user_mod($bp->loggedin_user->id, $bp->groups->current_group->id) || groups_is_user_admin($bp->loggedin_user->id, $bp->groups->current_group->id) || is_super_admin()) { $success = $chat_section = false; $chat_settings = $_POST['chat']; if (isset($chat_settings['section'])) { $chat_section = $chat_settings['section']; unset($chat_settings['section']); } $chat_settings['session_type'] = 'bp-group'; $chat_settings['id'] = 'wpmudev-chat-bp-group-' . $bp->groups->current_group->id; $chat_settings['blog_id'] = $wpdb->blogid; groups_update_groupmeta($bp->groups->current_group->id, $this->settings_slug, $chat_settings); /* Insert your edit screen save code here */ $success = true; /* To post an error/success message to the screen, use the following */ if (!$success) { bp_core_add_message(__('There was an error saving, please try again', 'buddypress'), 'error'); } else { bp_core_add_message(__('Settings saved successfully', 'buddypress')); } } bp_core_redirect(bp_get_group_permalink($bp->groups->current_group) . 'admin/' . $this->slug); }
function bp_group_management_admin_edit() { ?> <div class="wrap"> <?php $id = (int) $_GET['id']; $group = new BP_Groups_Group($id, true); $member_action = isset($_GET['member_action']) ? $_GET['member_action'] : false; $member_id = isset($_GET['member_id']) ? $_GET['member_id'] : false; switch ($member_action) { case "kick": if (!check_admin_referer('bp-group-management-action_kick')) { return false; } if (!bp_group_management_ban_member($member_id, $id)) { ?> <div id="message" class="updated fade"><p><?php _e('Sorry, there was an error.', 'bp-group-management'); ?> </p></div>'; <?php } else { ?> <div id="message" class="updated fade"><p><?php _e('Member kicked and banned', 'bp-group-management'); ?> </p></div> <?php } do_action('groups_banned_member', $member_id, $id); break; case "unkick": if (!check_admin_referer('bp-group-management-action_unkick')) { return false; } if (!bp_group_management_unban_member($member_id, $id)) { ?> <div id="message" class="updated fade"><p><?php _e('Sorry, there was an error.', 'bp-group-management'); ?> </p></div> <?php } else { ?> <div id="message" class="updated fade"><p><?php _e('Member unbanned', 'bp-group-management'); ?> </p></div> <?php } do_action('groups_banned_member', $member_id, $id); break; case "demote": if (!check_admin_referer('bp-group-management-action_demote')) { return false; } if (!groups_demote_member($member_id, $id)) { ?> <div id="message" class="updated fade"><p><?php _e('Sorry, there was an error.', 'bp-group-management'); ?> </p></div> <?php } else { ?> <div id="message" class="updated fade"><p><?php _e('Member demoted', 'bp-group-management'); ?> </p></div> <?php } do_action('groups_demoted_member', $member_id, $id); break; case "mod": if (!check_admin_referer('bp-group-management-action_mod')) { return false; } if (!bp_group_management_promote_member($member_id, $id, 'mod')) { ?> <div id="message" class="updated fade"><p><?php _e('Sorry, there was an error.', 'bp-group-management'); ?> </p></div> <?php } else { ?> <div id="message" class="updated fade"><p><?php _e('Member promoted to moderator', 'bp-group-management'); ?> </p></div> <?php } do_action('groups_promoted_member', $member_id, $id); break; case "admin": if (!check_admin_referer('bp-group-management-action_admin')) { return false; } if (!bp_group_management_promote_member($member_id, $id, 'admin')) { ?> <div id="message" class="updated fade"><p><?php _e('Sorry, there was an error.', 'bp-group-management'); ?> </p></div> <?php } else { ?> <div id="message" class="updated fade"><p><?php _e('Member promoted to admin', 'bp-group-management'); ?> </p></div> <?php } break; case "add": if (!check_admin_referer('bp-group-management-action_add')) { return false; } if (!bp_group_management_join_group($id, $member_id)) { ?> <div id="message" class="updated fade"><p><?php _e('Sorry, there was an error.', 'bp-group-management'); ?> </p></div> <?php } else { ?> <div id="message" class="updated fade"><p><?php _e('User added to group', 'bp-group-management'); ?> </p></div> <?php } break; case "remove": if (!check_admin_referer('bp-group-management-action_remove')) { return false; } if (!groups_leave_group($id, $_GET['member_id'])) { ?> <div id="message" class="updated fade"><p><?php _e('Sorry, there was an error.', 'bp-group-management'); ?> </p></div> <?php } else { ?> <div id="message" class="updated fade"><p><?php _e('User removed from group', 'bp-group-management'); ?> </p></div> <?php } break; default: do_action('bp_gm_member_action', $group, $id, $member_action, $member_id); break; } ?> <h2><?php _e('Group Management', 'bp-group-management'); ?> : <?php echo bp_get_group_name($group); ?> </h2> <a href="admin.php?page=bp-group-management">← <?php _e('Group index', 'bp-group-management'); ?> </a> <div class="bp-gm-group-actions"> <h3><?php _e('Group actions', 'bp-group-management'); ?> </h3> <?php bp_group_management_group_action_buttons($id, $group); ?> </div> <div class="bp-gm-group-members"> <?php if (bp_group_has_members('group_id=' . $id . '&exclude_admins_mods=0&exclude_banned=0')) { ?> <h3><?php _e('Manage current and banned group members', 'bp-group-management'); ?> </h3> <?php if (bp_group_member_needs_pagination()) { ?> <div class="pagination no-ajax"> <div id="member-count" class="pag-count"> <?php bp_group_member_pagination_count(); ?> </div> <div id="member-admin-pagination" class="pagination-links"> <?php bp_group_member_admin_pagination(); ?> </div> </div> <?php } ?> <ul id="members-list" class="item-list single-line"> <?php while (bp_group_members()) { bp_group_the_member(); ?> <?php if (bp_get_group_member_is_banned()) { ?> <li class="banned-user"> <?php bp_group_member_avatar_mini(); ?> <?php $unkicklink = "admin.php?page=bp-group-management&action=edit&id=" . $id . "&member_id=" . bp_get_group_member_id() . "&member_action=unkick"; $unkicklink = function_exists('wp_nonce_url') ? wp_nonce_url($unkicklink, 'bp-group-management-action_unkick') : $unkicklink; ?> <?php bp_group_member_link(); ?> <?php _e('(banned)', 'bp-group-management'); ?> <span class="small"> - <a href="<?php echo $unkicklink; ?> " class="confirm" title="<?php _e('Remove Ban', 'bp-group-management'); ?> "><?php _e('Remove Ban', 'bp-group-management'); ?> </a> <?php } else { ?> <li> <?php bp_group_member_avatar_mini(); ?> <?php $kicklink = "admin.php?page=bp-group-management&action=edit&id=" . $id . "&member_id=" . bp_get_group_member_id() . "&member_action=kick"; $kicklink = function_exists('wp_nonce_url') ? wp_nonce_url($kicklink, 'bp-group-management-action_kick') : $kicklink; $removelink = "admin.php?page=bp-group-management&action=edit&id=" . $id . "&member_id=" . bp_get_group_member_id() . "&member_action=remove"; $removelink = function_exists('wp_nonce_url') ? wp_nonce_url($removelink, 'bp-group-management-action_remove') : $removelink; $modlink = "admin.php?page=bp-group-management&action=edit&id=" . $id . "&member_id=" . bp_get_group_member_id() . "&member_action=mod"; $modlink = function_exists('wp_nonce_url') ? wp_nonce_url($modlink, 'bp-group-management-action_mod') : $modlink; $demotelink = "admin.php?page=bp-group-management&action=edit&id=" . $id . "&member_id=" . bp_get_group_member_id() . "&member_action=demote"; $demotelink = function_exists('wp_nonce_url') ? wp_nonce_url($demotelink, 'bp-group-management-action_demote') : $demotelink; $adminlink = "admin.php?page=bp-group-management&action=edit&id=" . $id . "&member_id=" . bp_get_group_member_id() . "&member_action=admin"; $adminlink = function_exists('wp_nonce_url') ? wp_nonce_url($adminlink, 'bp-group-management-action_admin') : $adminlink; ?> <strong><?php bp_group_member_link(); ?> </strong> <span class="small"> - <a href="<?php echo $removelink; ?> " title="<?php _e('Remove Member', 'bp-group-management'); ?> "><?php _e('Remove', 'bp-group-management'); ?> </a> | <a href="<?php echo $kicklink; ?> " class="confirm" title="<?php _e('Kick and ban this member', 'bp-group-management'); ?> "><?php _e('Kick & Ban', 'bp-group-management'); ?> </a> | <?php if (groups_is_user_admin(bp_get_group_member_id(), $id)) { ?> <a href="<?php echo $demotelink; ?> " class="confirm" title="<?php _e('Demote to Member', 'bp-group-management'); ?> "><?php _e('Demote to Member', 'bp-group-management'); ?> </a> <?php } elseif (groups_is_user_mod(bp_get_group_member_id(), $id)) { ?> <a href="<?php echo $demotelink; ?> " class="confirm" title="<?php _e('Demote to Member', 'bp-group-management'); ?> "><?php _e('Demote to Member', 'bp-group-management'); ?> </a> | <a href="<?php echo $adminlink; ?> " class="confirm" title="<?php _e('Promote to Admin', 'bp-group-management'); ?> "><?php _e('Promote to Admin', 'bp-group-management'); ?> </a></span> <?php } else { ?> <a href="<?php echo $modlink; ?> " class="confirm" title="<?php _e('Promote to Moderator', 'bp-group-management'); ?> "><?php _e('Promote to Moderator', 'bp-group-management'); ?> </a> | <a href="<?php echo $adminlink; ?> " class="confirm" title="<?php _e('Promote to Admin', 'bp-group-management'); ?> "><?php _e('Promote to Admin', 'bp-group-management'); ?> </a></span> <?php } ?> <?php } ?> <?php do_action('bp_group_manage_members_admin_item'); ?> </li> <?php } ?> </ul> <?php } ?> </div> <?php bp_group_management_add_member_list($id); ?> <?php do_action('bp_gm_more_group_actions'); ?> </div> <?php }
/** * Can a given user associate a doc with a given group? */ public static function user_can_associate_doc_with_group($user_id, $group_id) { $group = groups_get_group('group_id=' . intval($group_id)); // No one can associate anything with a non-existent group if (empty($group->name)) { return false; } // Site admins can do anything if (bp_current_user_can('bp_moderate')) { return true; } // Non-group-members can't associate a doc with a group if (!groups_is_user_member($user_id, $group_id)) { return false; } // Check against group settings. Default to 'member' // @todo Abstract default settings out better $group_settings = groups_get_groupmeta($group_id, 'bp-docs'); $can_create = isset($group_settings['can-create']) ? $group_settings['can-create'] : 'member'; if ('admin' == $can_create) { return groups_is_user_admin($user_id, $group_id); } else { if ('mod' == $can_create) { return groups_is_user_mod($user_id, $group_id); } } return true; }
/** * Can a user send invitations in the specified group? * * @since 1.5.0 * @since 2.2.0 Added the $user_id parameter. * * @param int $group_id The group ID to check. * @param int $user_id The user ID to check. * @return bool */ function bp_groups_user_can_send_invites($group_id = 0, $user_id = 0) { $can_send_invites = false; $invite_status = false; // If $user_id isn't specified, we check against the logged-in user. if (!$user_id) { $user_id = bp_loggedin_user_id(); } // If $group_id isn't specified, use existing one if available. if (!$group_id) { $group_id = bp_get_current_group_id(); } if ($user_id) { // Users with the 'bp_moderate' cap can always send invitations. if (user_can($user_id, 'bp_moderate')) { $can_send_invites = true; } else { $invite_status = bp_group_get_invite_status($group_id); switch ($invite_status) { case 'admins': if (groups_is_user_admin($user_id, $group_id)) { $can_send_invites = true; } break; case 'mods': if (groups_is_user_mod($user_id, $group_id) || groups_is_user_admin($user_id, $group_id)) { $can_send_invites = true; } break; case 'members': if (groups_is_user_member($user_id, $group_id)) { $can_send_invites = true; } break; } } } /** * Filters whether a user can send invites in a group. * * @since 1.5.0 * @since 2.2.0 Added the $user_id parameter. * * @param bool $can_send_invites Whether the user can send invites * @param int $group_id The group ID being checked * @param bool $invite_status The group's current invite status * @param int $user_id The user ID being checked */ return apply_filters('bp_groups_user_can_send_invites', $can_send_invites, $group_id, $invite_status, $user_id); }
/** * Set up component global data. * * The BP_GROUPS_SLUG constant is deprecated, and only used here for * backwards compatibility. * * @since 1.5.0 * * @see BP_Component::setup_globals() for a description of arguments. * * @param array $args See BP_Component::setup_globals() for a description. */ public function setup_globals($args = array()) { $bp = buddypress(); // Define a slug, if necessary. if (!defined('BP_GROUPS_SLUG')) { define('BP_GROUPS_SLUG', $this->id); } // Global tables for groups 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 groups component. // Note that global_tables is included in this array. $args = array('slug' => BP_GROUPS_SLUG, 'root_slug' => isset($bp->pages->groups->slug) ? $bp->pages->groups->slug : BP_GROUPS_SLUG, 'has_directory' => true, 'directory_title' => _x('Groups', 'component directory title', 'buddypress'), 'notification_callback' => 'groups_format_notifications', 'search_string' => _x('Search Groups...', 'Component directory search', 'buddypress'), 'global_tables' => $global_tables, 'meta_tables' => $meta_tables); parent::setup_globals($args); /* Single Group Globals **********************************************/ // Are we viewing a single group? if (bp_is_groups_component() && ($group_id = BP_Groups_Group::group_exists(bp_current_action()))) { $bp->is_single_item = true; /** * Filters the current PHP Class being used. * * @since 1.5.0 * * @param string $value Name of the class being used. */ $current_group_class = apply_filters('bp_groups_current_group_class', 'BP_Groups_Group'); if ($current_group_class == 'BP_Groups_Group') { $this->current_group = groups_get_group(array('group_id' => $group_id, 'populate_extras' => true)); } else { /** * Filters the current group object being instantiated from previous filter. * * @since 1.5.0 * * @param object $value Newly instantiated object for the group. */ $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 (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() || 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; } // Check once if the current group has a custom front template. $this->current_group->front_template = bp_groups_get_front_template($this->current_group); // Set current_group to 0 to prevent debug errors. } else { $this->current_group = 0; } /** * Filters the list of illegal groups names/slugs. * * @since 1.0.0 * * @param array $value Array of 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; } /** * Filters the preconfigured groups creation steps. * * @since 1.1.0 * * @param array $value Array of preconfigured group creation steps. */ $this->group_creation_steps = apply_filters('groups_create_group_steps', array('group-details' => array('name' => _x('Details', 'Group screen nav', 'buddypress'), 'position' => 0), 'group-settings' => array('name' => _x('Settings', 'Group screen nav', 'buddypress'), 'position' => 10))); // If avatar uploads are not disabled, add avatar option. $disabled_avatar_uploads = (int) bp_disable_group_avatar_uploads(); if (!$disabled_avatar_uploads && $bp->avatar->show_avatars) { $this->group_creation_steps['group-avatar'] = array('name' => _x('Photo', 'Group screen nav', 'buddypress'), 'position' => 20); } if (bp_group_use_cover_image_header()) { $this->group_creation_steps['group-cover-image'] = array('name' => _x('Cover Image', 'Group screen nav', 'buddypress'), 'position' => 25); } // If friends component is active, add invitations. if (bp_is_active('friends')) { $this->group_creation_steps['group-invites'] = array('name' => _x('Invites', 'Group screen nav', 'buddypress'), 'position' => 30); } /** * Filters the list of valid groups statuses. * * @since 1.1.0 * * @param array $value Array of valid group 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; }
function ass_show_subscription_status_in_member_list($user_id = '') { global $bp, $members_template; $group_id = bp_get_current_group_id(); if (groups_is_user_admin(bp_loggedin_user_id(), $group_id) || groups_is_user_mod(bp_loggedin_user_id(), $group_id) || is_super_admin()) { if (!$user_id) { $user_id = $members_template->member->user_id; } $sub_type = ass_get_group_subscription_status($user_id, $group_id); echo '<div class="ass_members_status">' . __('Email status:', 'bp-ass') . ' ' . ass_subscribe_translate($sub_type) . '</div>'; } }
/** * * @param type $group_id * @param type $user_id * * @return boolean */ function can_user_create_album_in_group($group_id = false, $user_id = false) { if ($group_id == false) { $group = groups_get_current_group(); $group_id = $group->id; } $upload_level = groups_get_groupmeta($group_id, "rt_media_group_control_level"); if (empty($upload_level)) { $upload_level = groups_get_groupmeta($group_id, "bp_media_group_control_level"); if (empty($upload_level)) { $upload_level = "all"; } } $user_id = get_current_user_id(); $display_flag = false; if (groups_is_user_member($user_id, $group_id)) { if ($upload_level == "admin") { if (groups_is_user_admin($user_id, $group_id) > 0) { $display_flag = true; } } else { if ($upload_level == "moderators") { if (groups_is_user_mod($user_id, $group_id) || groups_is_user_admin($user_id, $group_id)) { $display_flag = true; } } else { $display_flag = true; } } } $display_flag = apply_filters('can_user_create_album_in_group', $display_flag); return $display_flag; }
class="selected"<?php } ?> href="<?php echo site_url('?p=video'); ?> " title="<?php _e('Video', 'p2'); ?> "><?php _e('Video', 'p2'); ?> </a></li> <?php if (groups_is_user_admin(bp_loggedin_user_id(), bp_get_group_id()) || groups_is_user_mod(bp_loggedin_user_id(), bp_get_group_id())) { ?> <li><a id="featured"<?php if ($action == 'featured') { ?> class="selected"<?php } ?> href="<?php echo site_url('?p=featured'); ?> " title="<?php _e('Featured', 'p2'); ?> "><?php _e('Featured', 'p2');
/** * Determine access setting for a group/user pair. * * @param int $group_id Group ID. Default: current group ID. * @param int $user_id User ID. Default: current user ID. */ function invite_anyone_group_invite_access_test($group_id = 0, $user_id = 0) { global $current_user, $bp; if (empty($group_id)) { $group_id = bp_is_group() ? bp_get_current_group_id() : 0; } if (empty($group_id) && !bp_is_group_create()) { return 'noone'; } if (empty($user_id)) { $user_id = bp_loggedin_user_id(); } if (empty($user_id)) { return 'noone'; } $iaoptions = invite_anyone_options(); if (bp_is_group_create()) { if (empty($iaoptions['group_invites_can_group_admin']) || $iaoptions['group_invites_can_group_admin'] == 'anyone' || !$iaoptions['group_invites_can_group_admin']) { return 'anyone'; } if ($iaoptions['group_invites_can_group_admin'] == 'friends') { return 'friends'; } if ($iaoptions['group_invites_can_group_admin'] == 'noone') { return 'noone'; } } if (!groups_is_user_member($user_id, $group_id)) { return 'noone'; } if (user_can($user_id, 'bp_moderate')) { if (empty($iaoptions['group_invites_can_admin']) || $iaoptions['group_invites_can_admin'] == 'anyone' || !$iaoptions['group_invites_can_admin']) { return 'anyone'; } if ($iaoptions['group_invites_can_admin'] == 'friends') { return 'friends'; } if ($iaoptions['group_invites_can_admin'] == 'noone') { return 'noone'; } } else { if (groups_is_user_admin($user_id, $group_id)) { if (empty($iaoptions['group_invites_can_group_admin']) || $iaoptions['group_invites_can_group_admin'] == 'anyone' || !$iaoptions['group_invites_can_group_admin']) { return 'anyone'; } if ($iaoptions['group_invites_can_group_admin'] == 'friends') { return 'friends'; } if ($iaoptions['group_invites_can_group_admin'] == 'noone') { return 'noone'; } } else { if (groups_is_user_mod($user_id, $group_id)) { if (empty($iaoptions['group_invites_can_group_mod']) || $iaoptions['group_invites_can_group_mod'] == 'anyone' || !$iaoptions['group_invites_can_group_mod']) { return 'anyone'; } if ($iaoptions['group_invites_can_group_mod'] == 'friends') { return 'friends'; } if ($iaoptions['group_invites_can_group_mod'] == 'noone') { return 'noone'; } } else { if (empty($iaoptions['group_invites_can_group_member']) || $iaoptions['group_invites_can_group_member'] == 'anyone' || !$iaoptions['group_invites_can_group_member']) { return 'anyone'; } if ($iaoptions['group_invites_can_group_member'] == 'friends') { return 'friends'; } if ($iaoptions['group_invites_can_group_member'] == 'noone') { return 'noone'; } } } } return 'noone'; }
function mpp_group_check_media_permission($can, $media, $gallery, $user_id) { $media = mpp_get_media($media); //if it is not a group gallery, we should not be worried if ($media->component != 'groups') { return $can; } $group_id = $media->component_id; if (groups_is_user_admin($user_id, $group_id) || groups_is_user_mod($user_id, $group_id)) { $can = true; } return $can; }
/** * Can the logged-in user send invitations in the specified group? * * @package BuddyPress * @subpackage Groups Template * @since BuddyPress (1.5) * * @param int $group_id (optional) The id of the group whose status you want to check * @return bool $can_send_invites */ function bp_groups_user_can_send_invites($group_id = false) { global $bp; $can_send_invites = false; $invite_status = false; if (is_user_logged_in()) { if (bp_current_user_can('bp_moderate')) { // Super admins can always send invitations $can_send_invites = true; } else { // If no $group_id is provided, default to the current group id if (!$group_id) { $group_id = isset($bp->groups->current_group->id) ? $bp->groups->current_group->id : 0; } // If no group has been found, bail if (!$group_id) { return false; } $invite_status = bp_group_get_invite_status($group_id); if (!$invite_status) { return false; } switch ($invite_status) { case 'admins': if (groups_is_user_admin(bp_loggedin_user_id(), $group_id)) { $can_send_invites = true; } break; case 'mods': if (groups_is_user_mod(bp_loggedin_user_id(), $group_id) || groups_is_user_admin(bp_loggedin_user_id(), $group_id)) { $can_send_invites = true; } break; case 'members': if (groups_is_user_member(bp_loggedin_user_id(), $group_id)) { $can_send_invites = true; } break; } } } return apply_filters('bp_groups_user_can_send_invites', $can_send_invites, $group_id, $invite_status); }
function task_breaker_can_add_task_comment($project_id, $task_id = 0) { $group_id = absint(get_post_meta($project_id, 'task_breaker_project_group_id', true)); if (!is_user_logged_in()) { return false; } // Return true if the current user is an administrator. if (current_user_can('manage_options')) { return true; } // Return true if the current user is a moderator of the group. if (groups_is_user_mod(get_current_user_id(), $group_id)) { return true; } // Only members of the group can add comment to project. if (task_breaker_current_user_is_member_of_group($group_id)) { // Check to see if the current task has assigned members on it. if (task_has_members_assigned($task_id)) { // If it has assign members on it, disallow un-assigned members to update the task. if (!task_current_member_is_assign_to($task_id)) { return false; } } return true; } return false; }