/**
 * 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;
    }
}
Beispiel #3
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' ) );
	}
}
/**
 * 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'));
}
Beispiel #5
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'));
    }
}
Beispiel #6
0
 /**
  * @group remove_from_group
  */
 public function test_wp_idea_stream_groups_member_banned_hidden_group()
 {
     $bp = buddypress();
     $group = new BP_Groups_Group($this->group_id);
     $group->status = 'hidden';
     $group->save();
     // Set current group
     $bp->groups->current_group = groups_get_group(array('group_id' => $this->group_id, 'populate_extras' => true));
     $u = $this->factory->user->create();
     groups_join_group($this->group_id, $u);
     $idea1 = $this->factory->idea->create(array('author' => $u, 'metas' => array('group_id' => $this->group_id), 'status' => 'private'));
     $idea2 = $this->factory->idea->create(array('author' => $u, 'metas' => array('group_id' => $this->group_id), 'status' => 'private'));
     $bp->is_item_admin = true;
     groups_ban_member($u, $this->group_id);
     // Check metas
     $this->assertEmpty(wp_idea_stream_ideas_get_meta($idea1, 'group_id'));
     $this->assertEmpty(wp_idea_stream_ideas_get_meta($idea2, 'group_id'));
     $ideas = wp_idea_stream_ideas_get_ideas(array('include' => array($idea1, $idea2)));
     $public_ideas = wp_filter_object_list($ideas['ideas'], array('post_status' => 'publish'), 'and', 'ID');
     $this->assertEqualSets(array($idea1, $idea2), $public_ideas, 'When a member is banned from the group, ideas should always be public');
     // Reset item admin
     $bp->is_item_admin = false;
 }
 /**
  * @group bp_group_is_user_banned
  */
 public function test_bp_group_is_user_banned_not_in_groups_loop()
 {
     $now = time();
     $u1 = $this->factory->user->create(array('last_activity' => date('Y-m-d H:i:s', $now - 100)));
     $u2 = $this->factory->user->create(array('last_activity' => date('Y-m-d H:i:s', $now - 100)));
     $g1 = $this->factory->group->create(array('creator_id' => $u1));
     $g2 = $this->factory->group->create(array('creator_id' => $u2));
     $this->add_user_to_group($u1, $g2, array('date_modified' => date('Y-m-d H:i:s', $now - 50)));
     $this->add_user_to_group($u2, $g2, array('date_modified' => date('Y-m-d H:i:s', $now - 500)));
     $this->add_user_to_group($u1, $g2, array('date_modified' => date('Y-m-d H:i:s', $now - 50)));
     // Ban user 1 from group 2
     // Fool the admin check
     $old_user = get_current_user_id();
     $this->set_current_user($u2);
     buddypress()->is_item_admin = true;
     groups_ban_member($u1, $g2);
     // Do group ban checks
     $group1 = new BP_Groups_Group($g1);
     $group2 = new BP_Groups_Group($g2);
     $found = array();
     $found[] = bp_group_is_user_banned($group1, $u1);
     $found[] = bp_group_is_user_banned($group2, $u1);
     // Assert
     $expected = array(false, true);
     $this->assertEquals($expected, $found);
     // Clean up
     $this->set_current_user($old_user);
 }
 /**
  * @group total_member_count
  * @group groups_unban_member
  */
 public function test_total_member_count_groups_unban_member()
 {
     $u1 = $this->factory->user->create();
     $u2 = $this->factory->user->create();
     $g1 = $this->factory->group->create(array('creator_id' => $u1));
     groups_join_group($g1, $u2);
     // Fool the admin check
     $this->set_current_user($u1);
     buddypress()->is_item_admin = true;
     groups_ban_member($u2, $g1);
     groups_unban_member($u2, $g1);
     $this->assertEquals(2, groups_get_groupmeta($g1, 'total_member_count'));
 }
/**
 * 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'));
    }
}