/**
 * 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;
    }
}
/**
 * Handle the display of a group's admin/edit-details page.
 */
function groups_screen_group_admin_edit_details()
{
    if ('edit-details' != bp_get_group_current_admin_tab()) {
        return false;
    }
    if (bp_is_item_admin()) {
        $bp = buddypress();
        // If the edit form has been submitted, save the edited details.
        if (isset($_POST['save'])) {
            // Check the nonce.
            if (!check_admin_referer('groups_edit_group_details')) {
                return false;
            }
            $group_notify_members = isset($_POST['group-notify-members']) ? (int) $_POST['group-notify-members'] : 0;
            if (!groups_edit_base_group_details($_POST['group-id'], $_POST['group-name'], $_POST['group-desc'], $group_notify_members)) {
                bp_core_add_message(__('There was an error updating group details. Please try again.', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('Group details were successfully updated.', 'buddypress'));
            }
            /**
             * Fires before the redirect if a group details has been edited and saved.
             *
             * @since 1.0.0
             *
             * @param int $id ID of the group that was edited.
             */
            do_action('groups_group_details_edited', $bp->groups->current_group->id);
            bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . 'admin/edit-details/');
        }
        /**
         * Fires before the loading of the group admin/edit-details page template.
         *
         * @since 1.0.0
         *
         * @param int $id ID of the group that is being displayed.
         */
        do_action('groups_screen_group_admin_edit_details', $bp->groups->current_group->id);
        /**
         * Filters the template to load for a group's admin/edit-details page.
         *
         * @since 1.0.0
         *
         * @param string $value Path to a group's admin/edit-details template.
         */
        bp_core_load_template(apply_filters('groups_template_group_admin', 'groups/single/home'));
    }
}
/**
 * Handle the display of a group's admin/edit-details page.
 */
function groups_screen_group_admin_edit_details()
{
    if ('edit-details' != bp_get_group_current_admin_tab()) {
        return false;
    }
    if (bp_is_item_admin()) {
        $bp = buddypress();
        // If the edit form has been submitted, save the edited details
        if (isset($_POST['save'])) {
            // Check the nonce
            if (!check_admin_referer('groups_edit_group_details')) {
                return false;
            }
            $group_notify_members = isset($_POST['group-notify-members']) ? (int) $_POST['group-notify-members'] : 0;
            if (!groups_edit_base_group_details($_POST['group-id'], $_POST['group-name'], $_POST['group-desc'], $group_notify_members)) {
                bp_core_add_message(__('There was an error updating group details. Please try again.', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('Group details were successfully updated.', 'buddypress'));
            }
            do_action('groups_group_details_edited', $bp->groups->current_group->id);
            bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . 'admin/edit-details/');
        }
        do_action('groups_screen_group_admin_edit_details', $bp->groups->current_group->id);
        bp_core_load_template(apply_filters('groups_template_group_admin', 'groups/single/home'));
    }
}
示例#4
0
 /**
  * @group activity_action
  * @group bp_groups_format_activity_action_group_details_updated
  */
 public function test_bp_groups_format_activity_action_group_details_updated_with_updated_name_and_description()
 {
     $old_user = get_current_user_id();
     $u = $this->factory->user->create();
     $this->set_current_user($u);
     $group = $this->factory->group->create_and_get();
     groups_edit_base_group_details($group->id, 'Foo', 'Bar', true);
     $a = bp_activity_get(array('component' => buddypress()->groups->id, 'action' => 'group_details_updated', 'item_id' => $group->id));
     $this->assertNotEmpty($a['activities']);
     $expected = sprintf(__('%s changed the name and description of the group %s', 'buddypress'), bp_core_get_userlink($u), '<a href="' . bp_get_group_permalink($group) . '">Foo</a>');
     $this->assertSame($expected, $a['activities'][0]->action);
     $this->set_current_user($old_user);
 }
示例#5
0
function groups_screen_group_admin_edit_details() {
	global $bp;

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

		if ( $bp->is_item_admin || $bp->is_item_mod  ) {

			// If the edit form has been submitted, save the edited details
			if ( isset( $_POST['save'] ) ) {
				/* Check the nonce first. */
				if ( !check_admin_referer( 'groups_edit_group_details' ) )
					return false;

				if ( !groups_edit_base_group_details( $_POST['group-id'], $_POST['group-name'], $_POST['group-desc'], (int)$_POST['group-notify-members'] ) ) {
					bp_core_add_message( __( 'There was an error updating group details, please try again.', 'buddypress' ), 'error' );
				} else {
					bp_core_add_message( __( 'Group details were successfully updated.', 'buddypress' ) );
				}

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

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

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

			bp_core_load_template( apply_filters( 'groups_template_group_admin', 'groups/single/home' ) );
		}
	}
}
示例#6
0
function groups_screen_group_admin_edit_details()
{
    global $bp, $group_obj;
    if ($bp->current_component == $bp->groups->slug && 'edit-details' == $bp->action_variables[0]) {
        if ($bp->is_item_admin || $bp->is_item_mod) {
            // If the edit form has been submitted, save the edited details
            if (isset($_POST['save'])) {
                if (!groups_edit_base_group_details($_POST['group-id'], $_POST['group-name'], $_POST['group-desc'], $_POST['group-news'], (int) $_POST['group-notify-members'])) {
                    bp_core_add_message(__('There was an error updating group details, please try again.', 'buddypress'), 'error');
                } else {
                    bp_core_add_message(__('Group details were successfully updated.', 'buddypress'));
                }
                do_action('groups_group_details_edited', $group_obj->id);
                bp_core_redirect(site_url() . '/' . $bp->current_component . '/' . $bp->current_item . '/admin/edit-details');
            }
            do_action('groups_screen_group_admin_edit_details', $group_obj->id);
            bp_core_load_template(apply_filters('groups_template_group_admin_edit_details', 'groups/admin/edit-details'));
        }
    }
}