コード例 #1
0
 /**
  * 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));
 }
コード例 #2
0
ファイル: functions.php プロジェクト: ReLiFeD/irreversible.eu
/**
 * Is the current user the creator 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 the creator of the current group
 */
function bbp_group_is_creator()
{
    // 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_creator)) {
        $bbp->current_user->is_group_creator = groups_is_user_creator(get_current_user_id(), bp_get_current_group_id());
    }
    // Return the value
    return (bool) $bbp->current_user->is_group_creator;
}
コード例 #3
0
/**
 * 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);
}
コード例 #4
0
function wangguard_spam_all_data($user_id)
{
    global $wpdb, $bp;
    $wpdb->query($wpdb->prepare("DELETE FROM {$bp->blogs->table_name} WHERE user_id = %d", $user_id));
    friends_remove_data($user_id);
    $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));
    BP_Groups_Member::delete_all_for_user($user_id);
}