/**
 * This function handles actions related to member management on the group admin.
 */
function groups_screen_group_admin_manage_members()
{
    if ('manage-members' != bp_get_group_current_admin_tab()) {
        return false;
    }
    if (!bp_is_item_admin()) {
        return false;
    }
    $bp = buddypress();
    if (bp_action_variable(1) && bp_action_variable(2) && bp_action_variable(3)) {
        if (bp_is_action_variable('promote', 1) && (bp_is_action_variable('mod', 2) || bp_is_action_variable('admin', 2)) && is_numeric(bp_action_variable(3))) {
            $user_id = bp_action_variable(3);
            $status = bp_action_variable(2);
            // Check the nonce first.
            if (!check_admin_referer('groups_promote_member')) {
                return false;
            }
            // Promote a user.
            if (!groups_promote_member($user_id, $bp->groups->current_group->id, $status)) {
                bp_core_add_message(__('There was an error when promoting that user. Please try again.', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('User promoted successfully', 'buddypress'));
            }
            /**
             * Fires before the redirect after a group member has been promoted.
             *
             * @since 1.0.0
             *
             * @param int $user_id ID of the user being promoted.
             * @param int $id      ID of the group user is promoted within.
             */
            do_action('groups_promoted_member', $user_id, $bp->groups->current_group->id);
            bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . 'admin/manage-members/');
        }
    }
    if (bp_action_variable(1) && bp_action_variable(2)) {
        if (bp_is_action_variable('demote', 1) && is_numeric(bp_action_variable(2))) {
            $user_id = bp_action_variable(2);
            // Check the nonce first.
            if (!check_admin_referer('groups_demote_member')) {
                return false;
            }
            // Stop sole admins from abandoning their group.
            $group_admins = groups_get_group_admins($bp->groups->current_group->id);
            if (1 == count($group_admins) && $group_admins[0]->user_id == $user_id) {
                bp_core_add_message(__('This group must have at least one admin', 'buddypress'), 'error');
            } elseif (!groups_demote_member($user_id, $bp->groups->current_group->id)) {
                bp_core_add_message(__('There was an error when demoting that user. Please try again.', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('User demoted successfully', 'buddypress'));
            }
            /**
             * Fires before the redirect after a group member has been demoted.
             *
             * @since 1.0.0
             *
             * @param int $user_id ID of the user being demoted.
             * @param int $id      ID of the group user is demoted within.
             */
            do_action('groups_demoted_member', $user_id, $bp->groups->current_group->id);
            bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . 'admin/manage-members/');
        }
        if (bp_is_action_variable('ban', 1) && is_numeric(bp_action_variable(2))) {
            $user_id = bp_action_variable(2);
            // Check the nonce first.
            if (!check_admin_referer('groups_ban_member')) {
                return false;
            }
            // Ban a user.
            if (!groups_ban_member($user_id, $bp->groups->current_group->id)) {
                bp_core_add_message(__('There was an error when banning that user. Please try again.', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('User banned successfully', 'buddypress'));
            }
            /**
             * Fires before the redirect after a group member has been banned.
             *
             * @since 1.0.0
             *
             * @param int $user_id ID of the user being banned.
             * @param int $id      ID of the group user is banned from.
             */
            do_action('groups_banned_member', $user_id, $bp->groups->current_group->id);
            bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . 'admin/manage-members/');
        }
        if (bp_is_action_variable('unban', 1) && is_numeric(bp_action_variable(2))) {
            $user_id = bp_action_variable(2);
            // Check the nonce first.
            if (!check_admin_referer('groups_unban_member')) {
                return false;
            }
            // Remove a ban for user.
            if (!groups_unban_member($user_id, $bp->groups->current_group->id)) {
                bp_core_add_message(__('There was an error when unbanning that user. Please try again.', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('User ban removed successfully', 'buddypress'));
            }
            /**
             * Fires before the redirect after a group member has been unbanned.
             *
             * @since 1.0.0
             *
             * @param int $user_id ID of the user being unbanned.
             * @param int $id      ID of the group user is unbanned from.
             */
            do_action('groups_unbanned_member', $user_id, $bp->groups->current_group->id);
            bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . 'admin/manage-members/');
        }
        if (bp_is_action_variable('remove', 1) && is_numeric(bp_action_variable(2))) {
            $user_id = bp_action_variable(2);
            // Check the nonce first.
            if (!check_admin_referer('groups_remove_member')) {
                return false;
            }
            // Remove a user.
            if (!groups_remove_member($user_id, $bp->groups->current_group->id)) {
                bp_core_add_message(__('There was an error removing that user from the group. Please try again.', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('User removed successfully', 'buddypress'));
            }
            /**
             * Fires before the redirect after a group member has been removed.
             *
             * @since 1.2.6
             *
             * @param int $user_id ID of the user being removed.
             * @param int $id      ID of the group the user is removed from.
             */
            do_action('groups_removed_member', $user_id, $bp->groups->current_group->id);
            bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . 'admin/manage-members/');
        }
    }
    /**
     * Fires before the loading of a group's manage members template.
     *
     * @since 1.0.0
     *
     * @param int $id ID of the group whose manage members page is being displayed.
     */
    do_action('groups_screen_group_admin_manage_members', $bp->groups->current_group->id);
    /**
     * Filters the template to load for a group's manage members page.
     *
     * @since 1.0.0
     *
     * @param string $value Path to a group's manage members template.
     */
    bp_core_load_template(apply_filters('groups_template_group_admin_manage_members', 'groups/single/home'));
}
/**
 * Set up the Groups admin page.
 *
 * Loaded before the page is rendered, this function does all initial setup,
 * including: processing form requests, registering contextual help, and
 * setting up screen options.
 *
 * @since 1.7.0
 *
 * @global BP_Groups_List_Table $bp_groups_list_table Groups screen list table.
 */
function bp_groups_admin_load()
{
    global $bp_groups_list_table;
    // Build redirection URL
    $redirect_to = remove_query_arg(array('action', 'action2', 'gid', 'deleted', 'error', 'updated', 'success_new', 'error_new', 'success_modified', 'error_modified'), $_SERVER['REQUEST_URI']);
    // Decide whether to load the dev version of the CSS and JavaScript
    $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : 'min.';
    $doaction = bp_admin_list_table_current_bulk_action();
    /**
     * Fires at top of groups admin page.
     *
     * @since 1.7.0
     *
     * @param string $doaction Current $_GET action being performed in admin screen.
     */
    do_action('bp_groups_admin_load', $doaction);
    // Edit screen
    if ('do_delete' == $doaction && !empty($_GET['gid'])) {
        check_admin_referer('bp-groups-delete');
        $group_ids = wp_parse_id_list($_GET['gid']);
        $count = 0;
        foreach ($group_ids as $group_id) {
            if (groups_delete_group($group_id)) {
                $count++;
            }
        }
        $redirect_to = add_query_arg('deleted', $count, $redirect_to);
        bp_core_redirect($redirect_to);
    } elseif ('edit' == $doaction && !empty($_GET['gid'])) {
        // columns screen option
        add_screen_option('layout_columns', array('default' => 2, 'max' => 2));
        get_current_screen()->add_help_tab(array('id' => 'bp-group-edit-overview', 'title' => __('Overview', 'buddypress'), 'content' => '<p>' . __('This page is a convenient way to edit the details associated with one of your groups.', 'buddypress') . '</p>' . '<p>' . __('The Name and Description box is fixed in place, but you can reposition all the other boxes using drag and drop, and can minimize or expand them by clicking the title bar of each box. Use the Screen Options tab to hide or unhide, or to choose a 1- or 2-column layout for this screen.', 'buddypress') . '</p>'));
        // Help panel - sidebar links
        get_current_screen()->set_help_sidebar('<p><strong>' . __('For more information:', 'buddypress') . '</strong></p>' . '<p><a href="https://buddypress.org/support">' . __('Support Forums', 'buddypress') . '</a></p>');
        // Register metaboxes for the edit screen.
        add_meta_box('submitdiv', _x('Save', 'group admin edit screen', 'buddypress'), 'bp_groups_admin_edit_metabox_status', get_current_screen()->id, 'side', 'high');
        add_meta_box('bp_group_settings', _x('Settings', 'group admin edit screen', 'buddypress'), 'bp_groups_admin_edit_metabox_settings', get_current_screen()->id, 'side', 'core');
        add_meta_box('bp_group_add_members', _x('Add New Members', 'group admin edit screen', 'buddypress'), 'bp_groups_admin_edit_metabox_add_new_members', get_current_screen()->id, 'normal', 'core');
        add_meta_box('bp_group_members', _x('Manage Members', 'group admin edit screen', 'buddypress'), 'bp_groups_admin_edit_metabox_members', get_current_screen()->id, 'normal', 'core');
        /**
         * Fires after the registration of all of the default group meta boxes.
         *
         * @since 1.7.0
         */
        do_action('bp_groups_admin_meta_boxes');
        // Enqueue JavaScript files
        wp_enqueue_script('postbox');
        wp_enqueue_script('dashboard');
        // Index screen
    } else {
        // Create the Groups screen list table
        $bp_groups_list_table = new BP_Groups_List_Table();
        // per_page screen option
        add_screen_option('per_page', array('label' => _x('Groups', 'Groups per page (screen options)', 'buddypress')));
        // Help panel - overview text
        get_current_screen()->add_help_tab(array('id' => 'bp-groups-overview', 'title' => __('Overview', 'buddypress'), 'content' => '<p>' . __('You can manage groups much like you can manage comments and other content. This screen is customizable in the same ways as other management screens, and you can act on groups by using the on-hover action links or the Bulk Actions.', 'buddypress') . '</p>'));
        get_current_screen()->add_help_tab(array('id' => 'bp-groups-overview-actions', 'title' => __('Group Actions', 'buddypress'), 'content' => '<p>' . __('Clicking "Visit" will take you to the group&#8217;s public page. Use this link to see what the group looks like on the front end of your site.', 'buddypress') . '</p>' . '<p>' . __('Clicking "Edit" will take you to a Dashboard panel where you can manage various details about the group, such as its name and description, its members, and other settings.', 'buddypress') . '</p>' . '<p>' . __('If you click "Delete" under a specific group, or select a number of groups and then choose Delete from the Bulk Actions menu, you will be led to a page where you&#8217;ll be asked to confirm the permanent deletion of the group(s).', 'buddypress') . '</p>'));
        // Help panel - sidebar links
        get_current_screen()->set_help_sidebar('<p><strong>' . __('For more information:', 'buddypress') . '</strong></p>' . '<p>' . __('<a href="https://buddypress.org/support/">Support Forums</a>', 'buddypress') . '</p>');
    }
    $bp = buddypress();
    // Enqueue CSS and JavaScript
    wp_enqueue_script('bp_groups_admin_js', $bp->plugin_url . "bp-groups/admin/js/admin.{$min}js", array('jquery', 'wp-ajax-response', 'jquery-ui-autocomplete'), bp_get_version(), true);
    wp_localize_script('bp_groups_admin_js', 'BP_Group_Admin', array('add_member_placeholder' => __('Start typing a username to add a new member.', 'buddypress'), 'warn_on_leave' => __('If you leave this page, you will lose any unsaved changes you have made to the group.', 'buddypress')));
    wp_enqueue_style('bp_groups_admin_css', $bp->plugin_url . "bp-groups/admin/css/admin.{$min}css", array(), bp_get_version());
    wp_style_add_data('bp_groups_admin_css', 'rtl', true);
    if ($min) {
        wp_style_add_data('bp_groups_admin_css', 'suffix', $min);
    }
    if ($doaction && 'save' == $doaction) {
        // Get group ID
        $group_id = isset($_REQUEST['gid']) ? (int) $_REQUEST['gid'] : '';
        $redirect_to = add_query_arg(array('gid' => (int) $group_id, 'action' => 'edit'), $redirect_to);
        // Check this is a valid form submission
        check_admin_referer('edit-group_' . $group_id);
        // Get the group from the database
        $group = groups_get_group('group_id=' . $group_id);
        // If the group doesn't exist, just redirect back to the index
        if (empty($group->slug)) {
            wp_redirect($redirect_to);
            exit;
        }
        // Check the form for the updated properties
        // Store errors
        $error = 0;
        $success_new = $error_new = $success_modified = $error_modified = array();
        // Group name and description are handled with
        // groups_edit_base_group_details()
        if (!groups_edit_base_group_details($group_id, $_POST['bp-groups-name'], $_POST['bp-groups-description'], 0)) {
            $error = $group_id;
            // using negative integers for different error messages... eek!
            if (empty($_POST['bp-groups-name']) && empty($_POST['bp-groups-description'])) {
                $error = -3;
            } elseif (empty($_POST['bp-groups-name'])) {
                $error = -1;
            } elseif (empty($_POST['bp-groups-description'])) {
                $error = -2;
            }
        }
        // Enable discussion forum
        $enable_forum = isset($_POST['group-show-forum']) ? 1 : 0;
        /**
         * Filters the allowed status values for the group.
         *
         * @since 1.0.2
         *
         * @param array $value Array of allowed group statuses.
         */
        $allowed_status = apply_filters('groups_allowed_status', array('public', 'private', 'hidden'));
        $status = in_array($_POST['group-status'], (array) $allowed_status) ? $_POST['group-status'] : 'public';
        /**
         * Filters the allowed invite status values for the group.
         *
         * @since 1.5.0
         *
         * @param array $value Array of allowed invite statuses.
         */
        $allowed_invite_status = apply_filters('groups_allowed_invite_status', array('members', 'mods', 'admins'));
        $invite_status = in_array($_POST['group-invite-status'], (array) $allowed_invite_status) ? $_POST['group-invite-status'] : 'members';
        if (!groups_edit_group_settings($group_id, $enable_forum, $status, $invite_status)) {
            $error = $group_id;
        }
        // Process new members
        $user_names = array();
        if (!empty($_POST['bp-groups-new-members'])) {
            $user_names = array_merge($user_names, explode(',', $_POST['bp-groups-new-members']));
        }
        if (!empty($user_names)) {
            foreach (array_values($user_names) as $user_name) {
                $un = trim($user_name);
                // Make sure the user exists before attempting
                // to add to the group
                $user = get_user_by('slug', $un);
                if (empty($user)) {
                    $error_new[] = $un;
                } else {
                    if (!groups_join_group($group_id, $user->ID)) {
                        $error_new[] = $un;
                    } else {
                        $success_new[] = $un;
                    }
                }
            }
        }
        // Process member role changes
        if (!empty($_POST['bp-groups-role']) && !empty($_POST['bp-groups-existing-role'])) {
            // Before processing anything, make sure you're not
            // attempting to remove the all user admins
            $admin_count = 0;
            foreach ((array) $_POST['bp-groups-role'] as $new_role) {
                if ('admin' == $new_role) {
                    $admin_count++;
                    break;
                }
            }
            if (!$admin_count) {
                $redirect_to = add_query_arg('no_admins', 1, $redirect_to);
                $error = $group_id;
            } else {
                // Process only those users who have had their roles changed
                foreach ((array) $_POST['bp-groups-role'] as $user_id => $new_role) {
                    $existing_role = isset($_POST['bp-groups-existing-role'][$user_id]) ? $_POST['bp-groups-existing-role'][$user_id] : '';
                    if ($existing_role != $new_role) {
                        switch ($new_role) {
                            case 'mod':
                                // Admin to mod is a demotion. Demote to
                                // member, then fall through
                                if ('admin' == $existing_role) {
                                    groups_demote_member($user_id, $group_id);
                                }
                            case 'admin':
                                // If the user was banned, we must
                                // unban first
                                if ('banned' == $existing_role) {
                                    groups_unban_member($user_id, $group_id);
                                }
                                // At this point, each existing_role
                                // is a member, so promote
                                $result = groups_promote_member($user_id, $group_id, $new_role);
                                break;
                            case 'member':
                                if ('admin' == $existing_role || 'mod' == $existing_role) {
                                    $result = groups_demote_member($user_id, $group_id);
                                } elseif ('banned' == $existing_role) {
                                    $result = groups_unban_member($user_id, $group_id);
                                }
                                break;
                            case 'banned':
                                $result = groups_ban_member($user_id, $group_id);
                                break;
                            case 'remove':
                                $result = groups_remove_member($user_id, $group_id);
                                break;
                        }
                        // Store the success or failure
                        if ($result) {
                            $success_modified[] = $user_id;
                        } else {
                            $error_modified[] = $user_id;
                        }
                    }
                }
            }
        }
        /**
         * Fires before redirect so plugins can do something first on save action.
         *
         * @since 1.6.0
         *
         * @param int $group_id ID of the group being edited.
         */
        do_action('bp_group_admin_edit_after', $group_id);
        // Create the redirect URL
        if ($error) {
            // This means there was an error updating group details
            $redirect_to = add_query_arg('error', (int) $error, $redirect_to);
        } else {
            // Group details were update successfully
            $redirect_to = add_query_arg('updated', 1, $redirect_to);
        }
        if (!empty($success_new)) {
            $success_new = implode(',', array_filter($success_new, 'urlencode'));
            $redirect_to = add_query_arg('success_new', $success_new, $redirect_to);
        }
        if (!empty($error_new)) {
            $error_new = implode(',', array_filter($error_new, 'urlencode'));
            $redirect_to = add_query_arg('error_new', $error_new, $redirect_to);
        }
        if (!empty($success_modified)) {
            $success_modified = implode(',', array_filter($success_modified, 'urlencode'));
            $redirect_to = add_query_arg('success_modified', $success_modified, $redirect_to);
        }
        if (!empty($error_modified)) {
            $error_modified = implode(',', array_filter($error_modified, 'urlencode'));
            $redirect_to = add_query_arg('error_modified', $error_modified, $redirect_to);
        }
        /**
         * Filters the URL to redirect to after successfully editing a group.
         *
         * @since 1.7.0
         *
         * @param string $redirect_to URL to redirect user to.
         */
        wp_redirect(apply_filters('bp_group_admin_edit_redirect', $redirect_to));
        exit;
        // If a referrer and a nonce is supplied, but no action, redirect back.
    } elseif (!empty($_GET['_wp_http_referer'])) {
        wp_redirect(remove_query_arg(array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI'])));
        exit;
    }
}
/**
 * This function handles actions related to member management on the group admin.
 */
function groups_screen_group_admin_manage_members()
{
    if ('manage-members' != bp_get_group_current_admin_tab()) {
        return false;
    }
    if (!bp_is_item_admin()) {
        return false;
    }
    $bp = buddypress();
    if (bp_action_variable(1) && bp_action_variable(2) && bp_action_variable(3)) {
        if (bp_is_action_variable('promote', 1) && (bp_is_action_variable('mod', 2) || bp_is_action_variable('admin', 2)) && is_numeric(bp_action_variable(3))) {
            $user_id = bp_action_variable(3);
            $status = bp_action_variable(2);
            // Check the nonce first.
            if (!check_admin_referer('groups_promote_member')) {
                return false;
            }
            // Promote a user.
            if (!groups_promote_member($user_id, $bp->groups->current_group->id, $status)) {
                bp_core_add_message(__('There was an error when promoting that user. Please try again.', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('User promoted successfully', 'buddypress'));
            }
            do_action('groups_promoted_member', $user_id, $bp->groups->current_group->id);
            bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . 'admin/manage-members/');
        }
    }
    if (bp_action_variable(1) && bp_action_variable(2)) {
        if (bp_is_action_variable('demote', 1) && is_numeric(bp_action_variable(2))) {
            $user_id = bp_action_variable(2);
            // Check the nonce first.
            if (!check_admin_referer('groups_demote_member')) {
                return false;
            }
            // Stop sole admins from abandoning their group
            $group_admins = groups_get_group_admins($bp->groups->current_group->id);
            if (1 == count($group_admins) && $group_admins[0]->user_id == $user_id) {
                bp_core_add_message(__('This group must have at least one admin', 'buddypress'), 'error');
            } elseif (!groups_demote_member($user_id, $bp->groups->current_group->id)) {
                bp_core_add_message(__('There was an error when demoting that user. Please try again.', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('User demoted successfully', 'buddypress'));
            }
            do_action('groups_demoted_member', $user_id, $bp->groups->current_group->id);
            bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . 'admin/manage-members/');
        }
        if (bp_is_action_variable('ban', 1) && is_numeric(bp_action_variable(2))) {
            $user_id = bp_action_variable(2);
            // Check the nonce first.
            if (!check_admin_referer('groups_ban_member')) {
                return false;
            }
            // Ban a user.
            if (!groups_ban_member($user_id, $bp->groups->current_group->id)) {
                bp_core_add_message(__('There was an error when banning that user. Please try again.', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('User banned successfully', 'buddypress'));
            }
            do_action('groups_banned_member', $user_id, $bp->groups->current_group->id);
            bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . 'admin/manage-members/');
        }
        if (bp_is_action_variable('unban', 1) && is_numeric(bp_action_variable(2))) {
            $user_id = bp_action_variable(2);
            // Check the nonce first.
            if (!check_admin_referer('groups_unban_member')) {
                return false;
            }
            // Remove a ban for user.
            if (!groups_unban_member($user_id, $bp->groups->current_group->id)) {
                bp_core_add_message(__('There was an error when unbanning that user. Please try again.', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('User ban removed successfully', 'buddypress'));
            }
            do_action('groups_unbanned_member', $user_id, $bp->groups->current_group->id);
            bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . 'admin/manage-members/');
        }
        if (bp_is_action_variable('remove', 1) && is_numeric(bp_action_variable(2))) {
            $user_id = bp_action_variable(2);
            // Check the nonce first.
            if (!check_admin_referer('groups_remove_member')) {
                return false;
            }
            // Remove a user.
            if (!groups_remove_member($user_id, $bp->groups->current_group->id)) {
                bp_core_add_message(__('There was an error removing that user from the group. Please try again.', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('User removed successfully', 'buddypress'));
            }
            do_action('groups_removed_member', $user_id, $bp->groups->current_group->id);
            bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . 'admin/manage-members/');
        }
    }
    do_action('groups_screen_group_admin_manage_members', $bp->groups->current_group->id);
    bp_core_load_template(apply_filters('groups_template_group_admin_manage_members', 'groups/single/home'));
}
示例#4
0
function groups_screen_group_admin_manage_members() {
	global $bp;

	if ( $bp->current_component == $bp->groups->slug && 'manage-members' == $bp->action_variables[0] ) {

		if ( !$bp->is_item_admin )
			return false;

		if ( 'promote' == $bp->action_variables[1] && ( 'mod' == $bp->action_variables[2] || 'admin' == $bp->action_variables[2] ) && is_numeric( $bp->action_variables[3] ) ) {
			$user_id = $bp->action_variables[3];
			$status = $bp->action_variables[2];

			// Check the nonce first.
			if ( !check_admin_referer( 'groups_promote_member' ) )
				return false;

			// Promote a user.
			if ( !groups_promote_member( $user_id, $bp->groups->current_group->id, $status ) )
				bp_core_add_message( __( 'There was an error when promoting that user, please try again', 'buddypress' ), 'error' );
			else
				bp_core_add_message( __( 'User promoted successfully', 'buddypress' ) );

			do_action( 'groups_promoted_member', $user_id, $bp->groups->current_group->id );

			bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . 'admin/manage-members/' );
		}

		if ( 'demote' == $bp->action_variables[1] && is_numeric( $bp->action_variables[2] ) ) {
			$user_id = $bp->action_variables[2];

			// Check the nonce first.
			if ( !check_admin_referer( 'groups_demote_member' ) )
				return false;

			// Demote a user.
			if ( !groups_demote_member( $user_id, $bp->groups->current_group->id ) )
				bp_core_add_message( __( 'There was an error when demoting that user, please try again', 'buddypress' ), 'error' );
			else
				bp_core_add_message( __( 'User demoted successfully', 'buddypress' ) );

			do_action( 'groups_demoted_member', $user_id, $bp->groups->current_group->id );

			bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . 'admin/manage-members/' );
		}

		if ( 'ban' == $bp->action_variables[1] && is_numeric( $bp->action_variables[2] ) ) {
			$user_id = $bp->action_variables[2];

			// Check the nonce first.
			if ( !check_admin_referer( 'groups_ban_member' ) )
				return false;

			// Ban a user.
			if ( !groups_ban_member( $user_id, $bp->groups->current_group->id ) )
				bp_core_add_message( __( 'There was an error when banning that user, please try again', 'buddypress' ), 'error' );
			else
				bp_core_add_message( __( 'User banned successfully', 'buddypress' ) );

			do_action( 'groups_banned_member', $user_id, $bp->groups->current_group->id );

			bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . 'admin/manage-members/' );
		}

		if ( 'unban' == $bp->action_variables[1] && is_numeric( $bp->action_variables[2] ) ) {
			$user_id = $bp->action_variables[2];

			// Check the nonce first.
			if ( !check_admin_referer( 'groups_unban_member' ) )
				return false;

			// Remove a ban for user.
			if ( !groups_unban_member( $user_id, $bp->groups->current_group->id ) )
				bp_core_add_message( __( 'There was an error when unbanning that user, please try again', 'buddypress' ), 'error' );
			else
				bp_core_add_message( __( 'User ban removed successfully', 'buddypress' ) );

			do_action( 'groups_unbanned_member', $user_id, $bp->groups->current_group->id );

			bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . 'admin/manage-members/' );
		}

		if ( 'remove' == $bp->action_variables[1] && is_numeric( $bp->action_variables[2] ) ) {
			$user_id = $bp->action_variables[2];

			// Check the nonce first.
			if ( !check_admin_referer( 'groups_remove_member' ) )
				return false;

			// Remove a user.
			if ( !groups_remove_member( $user_id, $bp->groups->current_group->id ) )
				bp_core_add_message( __( 'There was an error removing that user from the group, please try again', 'buddypress' ), 'error' );
			else
				bp_core_add_message( __( 'User removed successfully', 'buddypress' ) );

			do_action( 'groups_removed_member', $user_id, $bp->groups->current_group->id );

			bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . 'admin/manage-members/' );
		}

		do_action( 'groups_screen_group_admin_manage_members', $bp->groups->current_group->id );

		bp_core_load_template( apply_filters( 'groups_template_group_admin_manage_members', 'groups/single/home' ) );
	}
}
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">&larr; <?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&amp;action=edit&amp;id=" . $id . "&amp;member_id=" . bp_get_group_member_id() . "&amp;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&amp;action=edit&amp;id=" . $id . "&amp;member_id=" . bp_get_group_member_id() . "&amp;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&amp;action=edit&amp;id=" . $id . "&amp;member_id=" . bp_get_group_member_id() . "&amp;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&amp;action=edit&amp;id=" . $id . "&amp;member_id=" . bp_get_group_member_id() . "&amp;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&amp;action=edit&amp;id=" . $id . "&amp;member_id=" . bp_get_group_member_id() . "&amp;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&amp;action=edit&amp;id=" . $id . "&amp;member_id=" . bp_get_group_member_id() . "&amp;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 &amp; 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 
}
示例#6
0
function groups_screen_group_admin_manage_members()
{
    global $bp, $group_obj;
    if ($bp->current_component == $bp->groups->slug && 'manage-members' == $bp->action_variables[0]) {
        if (!$bp->is_item_admin) {
            return false;
        }
        if ('promote' == $bp->action_variables[1] && is_numeric($bp->action_variables[2])) {
            $user_id = $bp->action_variables[2];
            // Promote a user.
            if (!groups_promote_member($user_id, $group_obj->id)) {
                bp_core_add_message(__('There was an error when promoting that user, please try again', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('User promoted successfully', 'buddypress'));
            }
            do_action('groups_promoted_member', $user_id, $group_obj->id);
            bp_core_redirect(site_url() . '/' . $bp->current_component . '/' . $bp->current_item . '/admin/manage-members');
        }
        if ('demote' == $bp->action_variables[1] && is_numeric($bp->action_variables[2])) {
            $user_id = $bp->action_variables[2];
            // Demote a user.
            if (!groups_demote_member($user_id, $group_obj->id)) {
                bp_core_add_message(__('There was an error when demoting that user, please try again', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('User demoted successfully', 'buddypress'));
            }
            do_action('groups_demoted_member', $user_id, $group_obj->id);
            bp_core_redirect(site_url() . '/' . $bp->current_component . '/' . $bp->current_item . '/admin/manage-members');
        }
        if ('ban' == $bp->action_variables[1] && is_numeric($bp->action_variables[2])) {
            $user_id = $bp->action_variables[2];
            // Ban a user.
            if (!groups_ban_member($user_id, $group_obj->id)) {
                bp_core_add_message(__('There was an error when banning that user, please try again', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('User banned successfully', 'buddypress'));
            }
            do_action('groups_banned_member', $user_id, $group_obj->id);
            bp_core_redirect(site_url() . '/' . $bp->current_component . '/' . $bp->current_item . '/admin/manage-members');
        }
        if ('unban' == $bp->action_variables[1] && is_numeric($bp->action_variables[2])) {
            $user_id = $bp->action_variables[2];
            // Remove a ban for user.
            if (!groups_unban_member($user_id, $group_obj->id)) {
                bp_core_add_message(__('There was an error when unbanning that user, please try again', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('User ban removed successfully', 'buddypress'));
            }
            do_action('groups_unbanned_member', $user_id, $group_obj->id);
            bp_core_redirect(site_url() . '/' . $bp->current_component . '/' . $bp->current_item . '/admin/manage-members');
        }
        do_action('groups_screen_group_admin_manage_members', $group_obj->id);
        bp_core_load_template(apply_filters('groups_template_group_admin_manage_members', 'groups/admin/manage-members'));
    }
}
示例#7
0
/**
 * This function handles actions related to member management on the group admin.
 *
 * @package BuddyPress
 */
function groups_screen_group_admin_manage_members()
{
    global $bp;
    if (bp_is_groups_component() && bp_is_action_variable('manage-members', 0)) {
        if (!$bp->is_item_admin) {
            return false;
        }
        if (bp_action_variable(1) && bp_action_variable(2) && bp_action_variable(3)) {
            if (bp_is_action_variable('promote', 1) && (bp_is_action_variable('mod', 2) || bp_is_action_variable('admin', 2)) && is_numeric(bp_action_variable(3))) {
                $user_id = bp_action_variable(3);
                $status = bp_action_variable(2);
                // Check the nonce first.
                if (!check_admin_referer('groups_promote_member')) {
                    return false;
                }
                // Promote a user.
                if (!groups_promote_member($user_id, $bp->groups->current_group->id, $status)) {
                    bp_core_add_message(__('There was an error when promoting that user, please try again', 'buddypress'), 'error');
                } else {
                    bp_core_add_message(__('User promoted successfully', 'buddypress'));
                }
                do_action('groups_promoted_member', $user_id, $bp->groups->current_group->id);
                bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . 'admin/manage-members/');
            }
        }
        if (bp_action_variable(1) && bp_action_variable(2)) {
            if (bp_is_action_variable('demote', 1) && is_numeric(bp_action_variable(2))) {
                $user_id = bp_action_variable(2);
                // Check the nonce first.
                if (!check_admin_referer('groups_demote_member')) {
                    return false;
                }
                // Demote a user.
                if (!groups_demote_member($user_id, $bp->groups->current_group->id)) {
                    bp_core_add_message(__('There was an error when demoting that user, please try again', 'buddypress'), 'error');
                } else {
                    bp_core_add_message(__('User demoted successfully', 'buddypress'));
                }
                do_action('groups_demoted_member', $user_id, $bp->groups->current_group->id);
                bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . 'admin/manage-members/');
            }
            if (bp_is_action_variable('ban', 1) && is_numeric(bp_action_variable(2))) {
                $user_id = bp_action_variable(2);
                // Check the nonce first.
                if (!check_admin_referer('groups_ban_member')) {
                    return false;
                }
                // Ban a user.
                if (!groups_ban_member($user_id, $bp->groups->current_group->id)) {
                    bp_core_add_message(__('There was an error when banning that user, please try again', 'buddypress'), 'error');
                } else {
                    bp_core_add_message(__('User banned successfully', 'buddypress'));
                }
                do_action('groups_banned_member', $user_id, $bp->groups->current_group->id);
                bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . 'admin/manage-members/');
            }
            if (bp_is_action_variable('unban', 1) && is_numeric(bp_action_variable(2))) {
                $user_id = bp_action_variable(2);
                // Check the nonce first.
                if (!check_admin_referer('groups_unban_member')) {
                    return false;
                }
                // Remove a ban for user.
                if (!groups_unban_member($user_id, $bp->groups->current_group->id)) {
                    bp_core_add_message(__('There was an error when unbanning that user, please try again', 'buddypress'), 'error');
                } else {
                    bp_core_add_message(__('User ban removed successfully', 'buddypress'));
                }
                do_action('groups_unbanned_member', $user_id, $bp->groups->current_group->id);
                bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . 'admin/manage-members/');
            }
            if (bp_is_action_variable('remove', 1) && is_numeric(bp_action_variable(2))) {
                $user_id = bp_action_variable(2);
                // Check the nonce first.
                if (!check_admin_referer('groups_remove_member')) {
                    return false;
                }
                // Remove a user.
                if (!groups_remove_member($user_id, $bp->groups->current_group->id)) {
                    bp_core_add_message(__('There was an error removing that user from the group, please try again', 'buddypress'), 'error');
                } else {
                    bp_core_add_message(__('User removed successfully', 'buddypress'));
                }
                do_action('groups_removed_member', $user_id, $bp->groups->current_group->id);
                bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . 'admin/manage-members/');
            }
        }
        do_action('groups_screen_group_admin_manage_members', $bp->groups->current_group->id);
        bp_core_load_template(apply_filters('groups_template_group_admin_manage_members', 'groups/single/home'));
    }
}