function bp_gtm_get_access($user_id = false, $group_id = false, $action = false) { global $wpdb, $bp; if (!$user_id) { $user_id = $bp->loggedin_user->id; } if (!$bp->groups->current_group->id) { return false; } if (!$group_id) { $group_id = $bp->groups->current_group->id; } if (groups_is_user_admin($bp->loggedin_user->id, $bp->groups->current_group->id) || is_super_admin() || is_network_admin()) { return true; } $sql = "SELECT `{$bp->gtm->table_roles}`. *\n FROM `{$bp->gtm->table_roles}`\n INNER JOIN `{$bp->gtm->table_roles_caps}` ON {$bp->gtm->table_roles_caps}.`role_id` = `{$bp->gtm->table_roles}`.`id`\n WHERE `{$bp->gtm->table_roles_caps}`.`user_id` = {$user_id}\n AND `{$bp->gtm->table_roles_caps}`.`group_id` = {$group_id}\n AND (\n `{$bp->gtm->table_roles}`.`group_id` = {$group_id}\n OR `{$bp->gtm->table_roles}`.`group_id` = '0'\n )\n LIMIT 1"; $result = $wpdb->get_results($wpdb->prepare($sql)); if (empty($result)) { return false; } if ($result[0]->{$action} == 1) { return true; } return false; }
/** * 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); }
/** * 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; }
/** * @param boolean $result * @param EM_Event $EM_Event */ function bp_em_group_event_can_manage($result, $EM_Event) { if (!$result && !empty($EM_Event->group_id) && bp_is_active('groups')) { //only override if already false, incase it's true if (groups_is_user_admin(get_current_user_id(), $EM_Event->group_id) && current_user_can('edit_events')) { //This user is an admin of the owner's group, so they can edit this event. return true; } } return $result; }
/** * 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 add_class_to_rtmedia_gallery($classes) { global $rtmedia_query; $user_id = get_current_user_id(); if (is_rt_admin() || isset($rtmedia_query->query['context']) && $rtmedia_query->query['context'] == 'profile' && isset($rtmedia_query->query['context_id']) && $rtmedia_query->query['context_id'] == $user_id) { $classes .= " rtm-pro-allow-action"; } if (isset($rtmedia_query->query['context']) && $rtmedia_query->query['context'] == 'group') { $group_id = $rtmedia_query->query['context_id']; if (groups_is_user_mod($user_id, $group_id) || groups_is_user_admin($user_id, $group_id)) { $classes .= " rtm-pro-allow-action"; } } return $classes; }
/** * Overrides the default capability of the user for another owner's event if the user is a group admin and the event belongs to a group. * User must have the relevant permissions globally in order to inherit that capability for this event as well. * @param boolean $result * @param EM_Event $EM_Event */ function bp_em_group_event_can_manage($result, $EM_Event, $owner_capability, $admin_capability, $user_to_check) { if (!$result && $EM_Event->event_owner != get_current_user_id() && !empty($EM_Event->group_id) && bp_is_active('groups')) { //only override if already false, incase it's true //if the user is an admin of this group, and actually has the relevant permissions globally, they can manage this event $EM_Object = new EM_Object(); //create new object to prevent infinite loop should we call $EM_Event->can_manage(); if (groups_is_user_admin(get_current_user_id(), $EM_Event->group_id) && $EM_Object->can_manage($owner_capability, $admin_capability, $user_to_check)) { //This user is an admin of the owner's group, so they can edit this event. return true; } else { $EM_Event->add_error($EM_Object->get_errors()); //add any applicable errors } } return $result; }
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; } }
function groups_ajax_invite_user() { global $bp; check_ajax_referer('groups_invite_uninvite_user'); if (!$_POST['friend_id'] || !$_POST['friend_action'] || !$_POST['group_id']) { return false; } if (!groups_is_user_admin($bp->loggedin_user->id, $_POST['group_id'])) { return false; } if (!friends_check_friendship($bp->loggedin_user->id, $_POST['friend_id'])) { return false; } if ('invite' == $_POST['friend_action']) { if (!groups_invite_user($_POST['friend_id'], $_POST['group_id'])) { return false; } $user = new BP_Core_User($_POST['friend_id']); echo '<li id="uid-' . $user->id . '">'; echo attribute_escape($user->avatar_thumb); echo '<h4>' . attribute_escape($user->user_link) . '</h4>'; echo '<span class="activity">' . attribute_escape($user->last_active) . '</span>'; echo '<div class="action"> <a class="remove" href="' . wp_nonce_url($bp->loggedin_user->domain . $bp->groups->slug . '/' . $_POST['group_id'] . '/invites/remove/' . $user->id, 'groups_invite_uninvite_user') . '" id="uid-' . attribute_escape($user->id) . '">' . __('Remove Invite', 'buddypress') . '</a> </div>'; echo '</li>'; } else { if ('uninvite' == $_POST['friend_action']) { if (!groups_uninvite_user($_POST['friend_id'], $_POST['group_id'])) { return false; } return true; } else { return false; } } }
/** * Notify group member they have been promoted. * * @since 1.0.0 * * @param int $user_id ID of the user. * @param int $group_id ID of the group. * @return false|null False on failure. */ function groups_notification_promoted_member($user_id = 0, $group_id = 0) { // What type of promotion is this? if (groups_is_user_admin($user_id, $group_id)) { $promoted_to = __('an administrator', 'buddypress'); $type = 'member_promoted_to_admin'; } else { $promoted_to = __('a moderator', 'buddypress'); $type = 'member_promoted_to_mod'; } // Trigger a BuddyPress Notification. if (bp_is_active('notifications')) { bp_notifications_add_notification(array('user_id' => $user_id, 'item_id' => $group_id, 'component_name' => buddypress()->groups->id, 'component_action' => $type)); } // Bail if admin opted out of receiving this email. if ('no' === bp_get_user_meta($user_id, 'notification_groups_admin_promotion', true)) { return false; } $group = groups_get_group(array('group_id' => $group_id)); $ud = bp_core_get_core_userdata($user_id); $group_link = bp_get_group_permalink($group); $settings_slug = function_exists('bp_get_settings_slug') ? bp_get_settings_slug() : 'settings'; $settings_link = bp_core_get_user_domain($user_id) . $settings_slug . '/notifications/'; // Set up and send the message. $to = $ud->user_email; $subject = bp_get_email_subject(array('text' => sprintf(__('You have been promoted in the group: "%s"', 'buddypress'), $group->name))); $message = sprintf(__('You have been promoted to %1$s for the group: "%2$s". To view the group please visit: %3$s --------------------- ', 'buddypress'), $promoted_to, $group->name, $group_link); // Only show the disable notifications line if the settings component is enabled. if (bp_is_active('settings')) { $message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link); } /** * Filters the user email that the group promotion notification will be sent to. * * @since 1.2.0 * * @param string $to User email the promotion notification is being sent to. */ $to = apply_filters('groups_notification_promoted_member_to', $to); /** * Filters the group promotion notification subject that will be sent to user. * * @since 1.2.0 * * @param string $subject Promotion notification email subject text. * @param BP_Groups_Group $group Object holding the current group instance. Passed by reference. */ $subject = apply_filters_ref_array('groups_notification_promoted_member_subject', array($subject, &$group)); /** * Filters the group promotion notification message that will be sent to user. * * @since 1.2.0 * * @param string $message Promotion notification email message text. * @param BP_Groups_Group $group Object holding the current group instance. Passed by reference. * @param string $promoted_to Role that the user was promoted to within the group. * @param string $group_link URL permalink for the group that the promotion was related to. * @param string $settings_link URL permalink for the user's notification settings area. */ $message = apply_filters_ref_array('groups_notification_promoted_member_message', array($message, &$group, $promoted_to, $group_link, $settings_link)); wp_mail($to, $subject, $message); /** * Fires after the notification is sent that a member has been promoted. * * @since 1.5.0 * * @param int $user_id ID of the user who was promoted. * @param string $subject Email notification subject text. * @param string $message Email notification message text. * @param int $group_id ID of the group that the user is a member of. */ do_action('bp_groups_sent_promoted_email', $user_id, $subject, $message, $group_id); }
public function test_groups_is_user_admin_expected_false() { $this->add_user_to_group(self::$user, self::$groups[0], array('is_admin' => false)); $this->add_user_to_group(self::$user, self::$groups[1], array('is_admin' => true)); $this->assertEquals(false, groups_is_user_admin(self::$user, self::$groups[0])); }
/** * Get a list of friends that a user can invite into this group. * * Excludes friends that are already in the group, and banned friends if the * user is not a group admin. * * @since BuddyPress (1.0.0) * * @param int $user_id User ID whose friends to see can be invited. Default: * ID of the logged-in user. * @param int $group_id Group to check possible invitations against. * @return mixed False if no friends, array of users if friends. */ function friends_get_friends_invite_list($user_id = 0, $group_id = 0) { // Default to logged in user id if (empty($user_id)) { $user_id = bp_loggedin_user_id(); } // Only group admins can invited previously banned users $user_is_admin = (bool) groups_is_user_admin($user_id, $group_id); // Assume no friends $friends = array(); // Default args $args = apply_filters('bp_friends_pre_get_invite_list', array('user_id' => $user_id, 'type' => 'alphabetical', 'per_page' => 0)); // User has friends if (bp_has_members($args)) { /** * Loop through all friends and try to add them to the invitation list. * * Exclude friends that: * 1. are already members of the group * 2. are banned from this group if the current user is also not a * group admin. */ while (bp_members()) { // Load the member bp_the_member(); // Get the user ID of the friend $friend_user_id = bp_get_member_user_id(); // Skip friend if already in the group if (groups_is_user_member($friend_user_id, $group_id)) { continue; } // Skip friend if not group admin and user banned from group if (false === $user_is_admin && groups_is_user_banned($friend_user_id, $group_id)) { continue; } // Friend is safe, so add it to the array of possible friends $friends[] = array('id' => $friend_user_id, 'full_name' => bp_get_member_name()); } } // If no friends, explicitly set to false if (empty($friends)) { $friends = false; } // Allow friends to be filtered return apply_filters('bp_friends_get_invite_list', $friends, $user_id, $group_id); }
/** * Map rendez-vous caps for the group's context * * @package Rendez Vous * @subpackage Groups * * @since Rendez Vous (1.1.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 * @return array Actual capabilities for meta capability */ public function map_meta_caps($caps = array(), $cap = '', $user_id = 0, $args = array()) { if (!bp_is_group() || empty($user_id)) { return $caps; } $group = groups_get_current_group(); switch ($cap) { case 'publish_rendez_vouss': if (!empty($group->id) && groups_is_user_member($user_id, $group->id)) { $caps = array('exist'); } break; case 'subscribe_rendez_vous': if (groups_is_user_member($user_id, $group->id)) { $caps = array('exist'); } else { $caps = array('manage_options'); } break; // Group Admins have full powers // Group Admins have full powers case 'read_private_rendez_vouss': case 'edit_rendez_vouss': case 'edit_others_rendez_vouss': case 'edit_rendez_vous': case 'delete_rendez_vous': case 'delete_rendez_vouss': case 'delete_others_rendez_vouss': if (!in_array('exist', $caps) && groups_is_user_admin($user_id, $group->id)) { $caps = array('exist'); } break; } return $caps; }
/** * * @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; }
function groups_notification_promoted_member($user_id, $group_id) { if (groups_is_user_admin($user_id, $group_id)) { $promoted_to = __('an administrator', 'buddypress'); $type = 'member_promoted_to_admin'; } else { $promoted_to = __('a moderator', 'buddypress'); $type = 'member_promoted_to_mod'; } // Post a screen notification first. bp_core_add_notification($group_id, $user_id, 'groups', $type); if ('no' == bp_get_user_meta($user_id, 'notification_groups_admin_promotion', true)) { return false; } $group = groups_get_group(array('group_id' => $group_id)); $ud = bp_core_get_core_userdata($user_id); $group_link = bp_get_group_permalink($group); $settings_slug = function_exists('bp_get_settings_slug') ? bp_get_settings_slug() : 'settings'; $settings_link = bp_core_get_user_domain($user_id) . $settings_slug . '/notifications/'; // Set up and send the message $to = $ud->user_email; $subject = bp_get_email_subject(array('text' => sprintf(__('You have been promoted in the group: "%s"', 'buddypress'), $group->name))); $message = sprintf(__('You have been promoted to %1$s for the group: "%2$s". To view the group please visit: %3$s --------------------- ', 'buddypress'), $promoted_to, $group->name, $group_link); // Only show the disable notifications line if the settings component is enabled if (bp_is_active('settings')) { $message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link); } /* Send the message */ $to = apply_filters('groups_notification_promoted_member_to', $to); $subject = apply_filters_ref_array('groups_notification_promoted_member_subject', array($subject, &$group)); $message = apply_filters_ref_array('groups_notification_promoted_member_message', array($message, &$group, $promoted_to, $group_link, $settings_link)); wp_mail($to, $subject, $message); do_action('bp_groups_sent_promoted_email', $user_id, $subject, $message, $group_id); }
<?php global $EM_Event; if (!function_exists('bp_is_active') || !bp_is_active('groups')) { return false; } $user_groups = array(); $group_data = groups_get_user_groups(get_current_user_id()); if (!is_super_admin()) { foreach ($group_data['groups'] as $group_id) { if (groups_is_user_admin(get_current_user_id(), $group_id)) { $user_groups[] = groups_get_group(array('group_id' => $group_id)); } } $group_count = count($user_groups); } else { $groups = groups_get_groups(array('show_hidden' => true, 'per_page' => 0)); $user_groups = $groups['groups']; $group_count = $groups['total']; } if (count($user_groups) > 0) { ?> <p> <select name="group_id"> <option value=""><?php _e('Not a Group Event', 'dbem'); ?> </option> <?php //in case user isn't a group mod, but can edit other users' events if (!empty($EM_Event->group_id) && !in_array($EM_Event->group_id, $group_data['groups'])) {
private function current_user_can_modify_settings($group_id = false) { if (!$group_id) { $group_id = bp_get_current_group_id(); } if (is_super_admin() || groups_is_user_admin(get_current_user_id(), $group_id)) { return true; } return false; }
function groups_leave_group($group_id, $user_id = 0) { global $bp; if (empty($user_id)) { $user_id = bp_loggedin_user_id(); } // Don't let single admins leave the group. if (count(groups_get_group_admins($group_id)) < 2) { if (groups_is_user_admin($user_id, $group_id)) { bp_core_add_message(__('As the only Admin, you cannot leave the group.', 'buddypress'), 'error'); return false; } } $membership = new BP_Groups_Member($user_id, $group_id); // This is exactly the same as deleting an invite, just is_confirmed = 1 NOT 0. if (!groups_uninvite_user($user_id, $group_id)) { return false; } /** * If the user joined this group less than five minutes ago, remove the * joined_group activity so users cannot flood the activity stream by * joining/leaving the group in quick succession. */ if (bp_is_active('activity') && gmmktime() <= strtotime('+5 minutes', (int) strtotime($membership->date_modified))) { bp_activity_delete(array('component' => $bp->groups->id, 'type' => 'joined_group', 'user_id' => $user_id, 'item_id' => $group_id)); } bp_core_add_message(__('You successfully left the group.', 'buddypress')); do_action('groups_leave_group', $group_id, $user_id); return true; }
/** * 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); }
/** * Notify group member they have been promoted. * * @since 1.0.0 * * @param int $user_id ID of the user. * @param int $group_id ID of the group. */ function groups_notification_promoted_member($user_id = 0, $group_id = 0) { // What type of promotion is this? if (groups_is_user_admin($user_id, $group_id)) { $promoted_to = __('an administrator', 'buddypress'); $type = 'member_promoted_to_admin'; } else { $promoted_to = __('a moderator', 'buddypress'); $type = 'member_promoted_to_mod'; } // Trigger a BuddyPress Notification. if (bp_is_active('notifications')) { bp_notifications_add_notification(array('user_id' => $user_id, 'item_id' => $group_id, 'component_name' => buddypress()->groups->id, 'component_action' => $type)); } // Bail if admin opted out of receiving this email. if ('no' === bp_get_user_meta($user_id, 'notification_groups_admin_promotion', true)) { return; } $unsubscribe_args = array('user_id' => $user_id, 'notification_type' => 'groups-member-promoted'); $group = groups_get_group($group_id); $args = array('tokens' => array('group' => $group, 'group.id' => $group_id, 'group.url' => esc_url(bp_get_group_permalink($group)), 'group.name' => $group->name, 'promoted_to' => $promoted_to, 'user.id' => $user_id, 'unsubscribe' => esc_url(bp_email_get_unsubscribe_link($unsubscribe_args)))); bp_send_email('groups-member-promoted', (int) $user_id, $args); }
/** * 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); }
/** * 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); }
/** * Various checks to see if a user can remove an item from a group * * @param int $group_id the group id * @uses bp_get_current_group_id() to get current group id * @uses buddydrive_is_group() to check we're on a group's BuddyDrive * @uses buddydrive_get_parent_item_id() to get parent item * @uses groups_is_user_admin() to check if the current user is admin of the group * @uses bp_loggedin_user_id() to get current user id * @uses is_super_admin() to give power to admin ! * @return boolean $can_remove */ function buddydrive_current_user_can_remove($group_id = false) { $can_remove = false; if (empty($group_id)) { $group_id = bp_get_current_group_id(); } if (!buddydrive_is_group() || buddydrive_get_parent_item_id()) { $can_remove = false; } else { if (groups_is_user_admin(bp_loggedin_user_id(), $group_id)) { $can_remove = true; } else { if (is_super_admin()) { $can_remove = true; } } } return apply_filters('buddydrive_current_user_can_remove', $can_remove); }
/** * 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(); }
/** * 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'; }
/** * 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; }
/** * 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); }
/** * 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; }
/** * Delete all group membership information for the specified user * * @global object $bp BuddyPress global settings * @global wpdb $wpdb WordPress database object * @param int $user_id * @since 1.0 * @uses BP_Groups_Member */ function delete_all_for_user($user_id) { global $bp, $wpdb; // Get all the group ids for the current user's groups and update counts $group_ids = BP_Groups_Member::get_group_ids($user_id); foreach ($group_ids['groups'] as $group_id) { groups_update_groupmeta($group_id, 'total_member_count', groups_get_total_member_count($group_id) - 1); // If current user is the creator of a group and is the sole admin, delete that group to avoid counts going out-of-sync if (groups_is_user_admin($user_id, $group_id) && count(groups_get_group_admins($group_id)) < 2 && groups_is_user_creator($user_id, $group_id)) { groups_delete_group($group_id); } } return $wpdb->query($wpdb->prepare("DELETE FROM {$bp->groups->table_name_members} WHERE user_id = %d", $user_id)); }
function bp_legacy_theme_ajax_my_is_user_group_admin() { $mygroupname = $_POST['groupname']; $mygroupid = (int) groups_get_id($mygroupname); if (!($group = groups_get_group(array('group_id' => $mygroupid)))) { return; } if (groups_is_user_admin(bp_loggedin_user_id(), $group->id)) { echo "1"; error_log("og admin group user is group"); } else { echo "0"; error_log("og no admin group no 0"); } exit; }