2, 'max' => 2, ) ); get_current_screen()->add_help_tab( array( 'id' => 'bp-group-edit-overview', 'title' => __( 'Overview', 'buddypress' ), 'content' => '

' . __( 'This page is a convenient way to edit the details associated with one of your groups.', 'buddypress' ) . '

' . '

' . __( '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' ) . '

' ) ); // Help panel - sidebar links get_current_screen()->set_help_sidebar( '

' . __( 'For more information:', 'buddypress' ) . '

' . '

' . __( 'Support Forums', 'buddypress' ) . '

' ); // 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' ); do_action( 'bp_groups_admin_meta_boxes' ); // Enqueue javascripts 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' => '

' . __( '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' ) . '

', ) ); get_current_screen()->add_help_tab( array( 'id' => 'bp-groups-overview-actions', 'title' => __( 'Group Actions', 'buddypress' ), 'content' => '

' . __( 'Clicking "Visit" will take you to the group’s public page. Use this link to see what the group looks like on the front end of your site.', 'buddypress' ) . '

' . '

' . __( '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' ) . '

' . '

' . __( '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’ll be asked to confirm the permanent deletion of the group(s).', 'buddypress' ) . '

', ) ); // Help panel - sidebar links get_current_screen()->set_help_sidebar( '

' . __( 'For more information:', 'buddypress' ) . '

' . '

' . __( 'Support Forums', 'buddypress' ) . '

' ); } $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_enqueue_style( 'bp_groups_admin_css', $bp->plugin_url . "bp-groups/admin/css/admin.{$min}css", array(), bp_get_version() ); 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' ), ) ); 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; } // Enable discussion forum $enable_forum = ( isset( $_POST['group-show-forum'] ) ) ? 1 : 0; // Privacy setting $allowed_status = apply_filters( 'groups_allowed_status', array( 'public', 'private', 'hidden' ) ); $status = ( in_array( $_POST['group-status'], (array) $allowed_status ) ) ? $_POST['group-status'] : 'public'; // Invite status $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( $_POST['new_members'] ) ) { $user_names = array_merge( $user_names, $_POST['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 ); } else if ( '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; } } } } } // Call actions for plugins to do something before we redirect 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 ); } // Redirect 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 save/update of screen options for the Groups component admin screen. * * @since BuddyPress (1.7.0) * * @param string $value Will always be false unless another plugin filters it first. * @param string $option Screen option name. * @param string $new_value Screen option form value. * @return string Option value. False to abandon update. */ function bp_groups_admin_screen_options( $value, $option, $new_value ) { if ( 'toplevel_page_bp_groups_per_page' != $option && 'toplevel_page_bp_groups_network_per_page' != $option ) return $value; // Per page $new_value = (int) $new_value; if ( $new_value < 1 || $new_value > 999 ) return $value; return $new_value; } /** * Select the appropirate Groups admin screen, and output it. * * @since BuddyPress (1.7.0) */ function bp_groups_admin() { // Decide whether to load the index or edit screen $doaction = bp_admin_list_table_current_bulk_action(); // Display the single group edit screen if ( 'edit' == $doaction && ! empty( $_GET['gid'] ) ) { bp_groups_admin_edit(); // Display the group deletion confirmation screen } else if ( 'delete' == $doaction && ! empty( $_GET['gid'] ) ) { bp_groups_admin_delete(); // Otherwise, display the groups index screen } else { bp_groups_admin_index(); } } /** * Display the single groups edit screen. * * @since BuddyPress (1.7.0) */ function bp_groups_admin_edit() { if ( ! current_user_can( 'bp_moderate' ) ) die( '-1' ); $messages = array(); // If the user has just made a change to a group, build status messages if ( !empty( $_REQUEST['no_admins'] ) || ! empty( $_REQUEST['error'] ) || ! empty( $_REQUEST['updated'] ) || ! empty( $_REQUEST['error_new'] ) || ! empty( $_REQUEST['success_new'] ) || ! empty( $_REQUEST['error_modified'] ) || ! empty( $_REQUEST['success_modified'] ) ) { $no_admins = ! empty( $_REQUEST['no_admins'] ) ? 1 : 0; $errors = ! empty( $_REQUEST['error'] ) ? $_REQUEST['error'] : ''; $updated = ! empty( $_REQUEST['updated'] ) ? $_REQUEST['updated'] : ''; $error_new = ! empty( $_REQUEST['error_new'] ) ? explode( ',', $_REQUEST['error_new'] ) : array(); $success_new = ! empty( $_REQUEST['success_new'] ) ? explode( ',', $_REQUEST['success_new'] ) : array(); $error_modified = ! empty( $_REQUEST['error_modified'] ) ? explode( ',', $_REQUEST['error_modified'] ) : array(); $success_modified = ! empty( $_REQUEST['success_modified'] ) ? explode( ',', $_REQUEST['success_modified'] ) : array(); if ( ! empty( $no_admins ) ) { $messages[] = __( 'You cannot remove all administrators from a group.', 'buddypress' ); } if ( ! empty( $errors ) ) { $messages[] = __( 'An error occurred when trying to update your group details.', 'buddypress' ); } else if ( ! empty( $updated ) ) { $messages[] = __( 'The group has been updated successfully.', 'buddypress' ); } if ( ! empty( $error_new ) ) { $messages[] = sprintf( __( 'The following users could not be added to the group: %s', 'buddypress' ), implode( ', ', $error_new ) ); } if ( ! empty( $success_new ) ) { $messages[] = sprintf( __( 'The following users were successfully added to the group: %s', 'buddypress' ), implode( ', ', $success_new ) ); } if ( ! empty( $error_modified ) ) { $error_modified = bp_groups_admin_get_usernames_from_ids( $error_modified ); $messages[] = sprintf( __( 'An error occurred when trying to modify the following members: %s', 'buddypress' ), implode( ', ', $error_modified ) ); } if ( ! empty( $success_modified ) ) { $success_modified = bp_groups_admin_get_usernames_from_ids( $success_modified ); $messages[] = sprintf( __( 'The following members were successfully modified: %s', 'buddypress' ), implode( ', ', $success_modified ) ); } } $is_error = ! empty( $no_admins ) || ! empty( $errors ) || ! empty( $error_new ) || ! empty( $error_modified ); // Get the group from the database $group = groups_get_group( 'group_id=' . $_GET['gid'] ); $group_name = isset( $group->name ) ? apply_filters( 'bp_get_group_name', $group->name ) : ''; // Construct URL for form $form_url = remove_query_arg( array( 'action', 'deleted', 'no_admins', 'error', 'error_new', 'success_new', 'error_modified', 'success_modified' ), $_SERVER['REQUEST_URI'] ); $form_url = add_query_arg( 'action', 'save', $form_url ); // Call an action for plugins to modify the group before we display the edit form do_action_ref_array( 'bp_groups_admin_edit', array( &$group ) ); ?>

\n", $messages ); ?>

description ), 'bp-groups-description', array( 'media_buttons' => false, 'teeny' => true, 'textarea_rows' => 5, 'quicktags' => array( 'buttons' => 'strong,em,link,block,del,ins,img,code,spell,close' ) ) ); ?>
id, 'side', $group ); ?>
id, 'normal', $group ); ?> id, 'advanced', $group ); ?>
id ); ?>

Go back and try again.', 'buddypress' ), esc_url( bp_get_admin_url( 'admin.php?page=bp-groups' ) ) ); ?>

$group_ids, 'show_hidden' => true, 'per_page' => null, // Return all results ) ); // Create a new list of group ids, based on those that actually exist $gids = array(); foreach ( $groups['groups'] as $group ) { $gids[] = $group->id; } $base_url = remove_query_arg( array( 'action', 'action2', 'paged', 's', '_wpnonce', 'gid' ), $_SERVER['REQUEST_URI'] ); ?>

0 ) { $messages[] = sprintf( _n( '%s group has been permanently deleted.', '%s groups have been permanently deleted.', $deleted, 'buddypress' ), number_format_i18n( $deleted ) ); } } // Prepare the group items for display $bp_groups_list_table->prepare_items(); // Call an action for plugins to modify the messages before we display the edit form do_action( 'bp_groups_admin_index', $messages ); ?>

\n", $messages ); ?>

views(); ?>
search_box( __( 'Search all Groups', 'buddypress' ), 'bp-groups' ); ?> display(); ?>
id, 'invite_status' ); ?>
array(), 'mod' => array(), 'member' => array(), 'banned' => array(), ); $pagination = array( 'admin' => array(), 'mod' => array(), 'member' => array(), 'banned' => array(), ); foreach ( $members as $type => &$member_type_users ) { $page_qs_key = $type . '_page'; $current_type_page = isset( $_GET[ $page_qs_key ] ) ? absint( $_GET[ $page_qs_key ] ) : 1; $member_type_query = new BP_Group_Member_Query( array( 'group_id' => $item->id, 'group_role' => array( $type ), 'type' => 'alphabetical', 'per_page' => 10, 'page' => $current_type_page, ) ); $member_type_users = $member_type_query->results; $pagination[ $type ] = bp_groups_admin_create_pagination_links( $member_type_query, $type ); } // Echo out the javascript variable echo ''; // Loop through each member type foreach ( $members as $member_type => $type_users ) : ?>

ID ); ?> $type_user->ID, 'width' => '32', 'height' => '32' ) ); ?> ID ) ?>
ID, $item ); ?>

'bp-groups', 'gid' => $item->id ), bp_get_admin_url( 'admin.php' ) ); ?>
'4' ) ); ?>
total_users <= $per_page ) { return $pagination; } $current_page_start = ( ( $page - 1 ) * $per_page ) + 1; $current_page_end = $page * $per_page > intval( $query->total_users ) ? $query->total_users : $page * $per_page; $pag_links = paginate_links( array( 'base' => add_query_arg( $qs_key, '%#%', $url_base ), 'format' => '', 'prev_text' => __( '«', 'buddypress' ), 'next_text' => __( '»', 'buddypress' ), 'total' => ceil( $query->total_users / $per_page ), 'current' => $page, ) ); $viewing_text = sprintf( __( 'Viewing %1$s - %2$s of %3$s', 'buddypress' ), number_format_i18n( $current_page_start ), number_format_i18n( $current_page_end ), sprintf( _n( '%s member', '%s members', $query->total_users, 'buddypress' ), $query->total_users ) ); $pagination .= '' . $viewing_text . ''; $pagination .= '' . $pag_links . ''; return $pagination; } /** * Get a set of usernames corresponding to a set of user IDs. * * @since BuddyPress (1.7.0) * * @param array $user_ids Array of user IDs. * @return array Array of user_logins corresponding to $user_ids. */ function bp_groups_admin_get_usernames_from_ids( $user_ids = array() ) { $usernames = array(); $users = new WP_User_Query( array( 'blog_id' => 0, 'include' => $user_ids ) ); foreach ( (array) $users->results as $user ) { $usernames[] = $user->user_login; } return $usernames; } /** * AJAX handler for group member autocomplete requests. * * @since BuddyPress (1.7.0) */ function bp_groups_admin_autocomplete_handler() { // Bail if user user shouldn't be here, or is a large network if ( ! current_user_can( 'bp_moderate' ) || ( is_multisite() && wp_is_large_network( 'users' ) ) ) wp_die( -1 ); $return = array(); // Exclude current group members $group_id = isset( $_GET['group_id'] ) ? wp_parse_id_list( $_GET['group_id'] ) : array(); $group_member_query = new BP_Group_Member_Query( array( 'group_id' => $group_id, 'per_page' => 0, // show all 'group_role' => array( 'member', 'mod', 'admin', ), 'populate_extras' => false, 'count_total' => false, ) ); $group_members = ! empty( $group_member_query->results ) ? wp_list_pluck( $group_member_query->results, 'ID' ) : array(); $terms = isset( $_GET['term'] ) ? $_GET['term'] : ''; $users = bp_core_get_users( array( 'type' => 'alphabetical', 'search_terms' => $terms, 'exclude' => $group_members, 'per_page' => 10, 'populate_extras' => false ) ); foreach ( (array) $users['users'] as $user ) { $return[] = array( /* translators: 1: user_login, 2: user_email */ 'label' => sprintf( __( '%1$s (%2$s)', 'buddypress' ), bp_is_username_compatibility_mode() ? $user->user_login : $user->user_nicename, $user->user_email ), 'value' => $user->user_nicename, ); } wp_die( json_encode( $return ) ); } add_action( 'wp_ajax_bp_group_admin_member_autocomplete', 'bp_groups_admin_autocomplete_handler' ); /** * List table class for the Groups component admin page. * * @since BuddyPress (1.7.0) */ class BP_Groups_List_Table extends WP_List_Table { /** * The type of view currently being displayed. * * e.g. "All", "Pending", "Approved", "Spam"... * * @since BuddyPress (1.7.0) * * @access public * @var string */ public $view = 'all'; /** * Group counts for each group type. * * @since BuddyPress (1.7.0) * * @access public * @var int */ public $group_counts = 0; /** * Constructor * * @since BuddyPress (1.7.0) */ public function __construct() { // Define singular and plural labels, as well as whether we support AJAX. parent::__construct( array( 'ajax' => false, 'plural' => 'groups', 'singular' => 'group', ) ); } /** * Set up items for display in the list table. * * Handles filtering of data, sorting, pagination, and any other data * manipulation required prior to rendering. * * @since BuddyPress (1.7.0) */ function prepare_items() { global $groups_template; $screen = get_current_screen(); // Option defaults $include_id = false; $search_terms = false; // Set current page $page = $this->get_pagenum(); // Set per page from the screen options $per_page = $this->get_items_per_page( str_replace( '-', '_', "{$screen->id}_per_page" ) ); // Sort order. $order = 'DESC'; if ( !empty( $_REQUEST['order'] ) ) { $order = ( 'desc' == strtolower( $_REQUEST['order'] ) ) ? 'DESC' : 'ASC'; } // Order by - default to newest $orderby = 'last_activity'; if ( ! empty( $_REQUEST['orderby'] ) ) { switch ( $_REQUEST['orderby'] ) { case 'name' : $orderby = 'name'; break; case 'id' : $orderby = 'date_created'; break; case 'members' : $orderby = 'total_member_count'; break; case 'last_active' : $orderby = 'last_activity'; break; } } // Are we doing a search? if ( !empty( $_REQUEST['s'] ) ) $search_terms = $_REQUEST['s']; // Check if user has clicked on a specific group (if so, fetch only that group). if ( !empty( $_REQUEST['gid'] ) ) $include_id = (int) $_REQUEST['gid']; // Set the current view if ( isset( $_GET['group_status'] ) && in_array( $_GET['group_status'], array( 'public', 'private', 'hidden' ) ) ) { $this->view = $_GET['group_status']; } // We'll use the ids of group types for the 'include' param $this->group_type_ids = BP_Groups_Group::get_group_type_ids(); // Pass a dummy array if there are no groups of this type $include = false; if ( 'all' != $this->view && isset( $this->group_type_ids[ $this->view ] ) ) { $include = ! empty( $this->group_type_ids[ $this->view ] ) ? $this->group_type_ids[ $this->view ] : array( 0 ); } // Get group type counts for display in the filter tabs $this->group_counts = array(); foreach ( $this->group_type_ids as $group_type => $group_ids ) { $this->group_counts[ $group_type ] = count( $group_ids ); } // If we're viewing a specific group, flatten all activites into a single array. if ( $include_id ) { $groups = array( (array) groups_get_group( 'group_id=' . $include_id ) ); } else { $groups_args = array( 'include' => $include, 'per_page' => $per_page, 'page' => $page, 'orderby' => $orderby, 'order' => $order ); $groups = array(); if ( bp_has_groups( $groups_args ) ) { while ( bp_groups() ) { bp_the_group(); $groups[] = (array) $groups_template->group; } } } // Set raw data to display $this->items = $groups; // Store information needed for handling table pagination $this->set_pagination_args( array( 'per_page' => $per_page, 'total_items' => $groups_template->total_group_count, 'total_pages' => ceil( $groups_template->total_group_count / $per_page ) ) ); } /** * Get an array of all the columns on the page. * * @since BuddyPress (1.7.0) * * @return array Array of column headers. */ function get_column_info() { $this->_column_headers = array( $this->get_columns(), array(), $this->get_sortable_columns(), ); return $this->_column_headers; } /** * Display a message on screen when no items are found ("No groups found"). * * @since BuddyPress (1.7.0) */ function no_items() { _e( 'No groups found.', 'buddypress' ); } /** * Output the Groups data table. * * @since BuddyPress (1.7.0) */ function display() { extract( $this->_args ); $this->display_tablenav( 'top' ); ?> print_column_headers(); ?> print_column_headers( false ); ?> display_rows_or_placeholder(); ?>
display_tablenav( 'bottom' ); } /** * Generate content for a single row of the table. * * @since BuddyPress (1.7.0) * * @param object $item The current group item in the loop. */ function single_row( $item = array() ) { static $even = false; $row_classes = array(); if ( $even ) { $row_classes = array( 'even' ); } else { $row_classes = array( 'alternate', 'odd' ); } $row_classes = apply_filters( 'bp_groups_admin_row_class', $row_classes, $item['id'] ); $row_class = ' class="' . implode( ' ', $row_classes ) . '"'; echo ''; echo $this->single_row_columns( $item ); echo ''; $even = ! $even; } /** * Get the list of views available on this table (e.g. "all", "public"). * * @since BuddyPress (1.7.0) */ function get_views() { $url_base = bp_get_admin_url( 'admin.php?page=bp-groups' ); ?> __( 'Delete', 'buddypress' ) ) ); } /** * Get the table column titles. * * @since BuddyPress (1.7.0) * * @see WP_List_Table::single_row_columns() * * @return array Array of column titles. */ function get_columns() { return apply_filters( 'bp_groups_list_table_get_columns', array( 'cb' => '', 'comment' => _x( 'Name', 'Groups admin Group Name column header', 'buddypress' ), 'description' => _x( 'Description', 'Groups admin Group Description column header', 'buddypress' ), 'status' => _x( 'Status', 'Groups admin Privacy Status column header', 'buddypress' ), 'members' => _x( '# Members', 'Groups admin Members column header', 'buddypress' ), 'last_active' => _x( 'Last Active', 'Groups admin Last Active column header', 'buddypress' ) ) ); } /** * Get the column names for sortable columns * * Note: It's not documented in WP, but the second item in the * nested arrays below is $desc_first. Normally, we would set * last_active to be desc_first (since you're generally interested in * the *most* recently active group, not the *least*). But because * the default sort for the Groups admin screen is DESC by last_active, * we want the first click on the Last Active column header to switch * the sort order - ie, to make it ASC. Thus last_active is set to * $desc_first = false. * * @since BuddyPress (1.7.0) * * @return array Array of sortable column names. */ function get_sortable_columns() { return array( 'gid' => array( 'gid', false ), 'comment' => array( 'name', false ), 'members' => array( 'members', false ), 'last_active' => array( 'last_active', false ), ); } /** * Markup for the Checkbox column. * * @since BuddyPress (1.7.0) * * @see WP_List_Table::single_row_columns() * * @param array $item A singular item (one full row). */ function column_cb( $item = array() ) { printf( '', $item['id'] ); } /** * Markup for the Group ID column. * * @since BuddyPress (1.7.0) * * @see WP_List_Table::single_row_columns() * * @param array $item A singular item (one full row). */ function column_gid( $item = array() ) { echo '' . $item['id'] . ''; } /** * Name column, and "quick admin" rollover actions. * * Called "comment" in the CSS so we can re-use some WP core CSS. * * @since BuddyPress (1.7.0) * * @see WP_List_Table::single_row_columns() * * @param array $item A singular item (one full row). */ function column_comment( $item = array() ) { // Preorder items: Visit | Edit | Delete $actions = array( 'visit' => '', 'edit' => '', 'delete' => '', ); // We need the group object for some BP functions $item_obj = (object) $item; // Build actions URLs $base_url = bp_get_admin_url( 'admin.php?page=bp-groups&gid=' . $item['id'] ); $delete_url = wp_nonce_url( $base_url . "&action=delete", 'bp-groups-delete' ); $edit_url = $base_url . '&action=edit'; $visit_url = bp_get_group_permalink( $item_obj ); // Rollover actions // Visit $actions['visit'] = sprintf( '%s', esc_url( $visit_url ), __( 'Visit', 'buddypress' ) ); // Edit $actions['edit'] = sprintf( '%s', esc_url( $edit_url ), __( 'Edit', 'buddypress' ) ); // Delete $actions['delete'] = sprintf( '%s', esc_url( $delete_url ), __( 'Delete', 'buddypress' ) ); // Other plugins can filter which actions are shown $actions = apply_filters( 'bp_groups_admin_comment_row_actions', array_filter( $actions ), $item ); // Get group name and avatar $avatar = bp_core_fetch_avatar( array( 'item_id' => $item['id'], 'object' => 'group', 'type' => 'thumb', 'avatar_dir' => 'group-avatars', 'alt' => sprintf( __( 'Group logo of %s', 'buddypress' ), $item['name'] ), 'width' => '32', 'height' => '32', 'title' => $item['name'] ) ); $content = apply_filters_ref_array( 'bp_get_group_name', array( $item['name'], $item ) ); echo $avatar . ' ' . $content . ' ' . $this->row_actions( $actions ); } /** * Markup for the Description column. * * @since BuddyPress (1.7.0) * * @param array Information about the current row. */ function column_description( $item = array() ) { echo apply_filters_ref_array( 'bp_get_group_description', array( $item['description'], $item ) ); } /** * Markup for the Status column. * * @since BuddyPress (1.7.0) * * @param array Information about the current row. */ function column_status( $item = array() ) { $status = $item['status']; $status_desc = ''; // @todo This should be abstracted out somewhere for the whole // Groups component switch ( $status ) { case 'public' : $status_desc = __( 'Public', 'buddypress' ); break; case 'private' : $status_desc = __( 'Private', 'buddypress' ); break; case 'hidden' : $status_desc = __( 'Hidden', 'buddypress' ); break; } echo apply_filters_ref_array( 'bp_groups_admin_get_group_status', array( $status_desc, $item ) ); } /** * Markup for the Number of Members column. * * @since BuddyPress (1.7.0) * * @param array Information about the current row. */ function column_members( $item = array() ) { $count = groups_get_groupmeta( $item['id'], 'total_member_count' ); echo apply_filters_ref_array( 'bp_groups_admin_get_group_member_count', array( (int) $count, $item ) ); } /** * Markup for the Last Active column. * * @since BuddyPress (1.7.0) * * @param array Information about the current row. */ function column_last_active( $item = array() ) { $last_active = groups_get_groupmeta( $item['id'], 'last_activity' ); echo apply_filters_ref_array( 'bp_groups_admin_get_group_last_active', array( $last_active, $item ) ); } /** * Allow plugins to add their costum column. * * @since BuddyPress 2.0.0 * * @param array Information about the current row. * @param string the column name. */ function column_default( $item = array(), $column_name = '' ) { return apply_filters( 'bp_groups_admin_get_group_custom_column', '', $column_name, $item ); } }