Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/22/2015 04:58:34 AM (5 years ago)
Author:
tw2113
Message:

More docs cleanup for BP-Groups component.

See #6401.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/bp-groups-admin.php

    r10360 r10373  
    1818if ( !class_exists( 'WP_List_Table' ) ) require( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
    1919
    20 // per_page screen option. Has to be hooked in extremely early.
     20// The per_page screen option. Has to be hooked in extremely early.
    2121if ( is_admin() && ! empty( $_REQUEST['page'] ) && 'bp-groups' == $_REQUEST['page'] )
    2222    add_filter( 'set-screen-option', 'bp_groups_admin_screen_options', 10, 3 );
     
    2929function bp_groups_add_admin_menu() {
    3030
    31     // Add our screen
     31    // Add our screen.
    3232    $hook = add_menu_page(
    3333        _x( 'Groups', 'Admin Groups page title', 'buddypress' ),
     
    5353 *
    5454 * @param array $custom_menus Array of BP top-level menu items.
    55  *
    5655 * @return array Menu item array, with Groups added.
    5756 */
     
    7675    global $bp_groups_list_table;
    7776
    78     // Build redirection URL
     77    // Build redirection URL.
    7978    $redirect_to = remove_query_arg( array( 'action', 'action2', 'gid', 'deleted', 'error', 'updated', 'success_new', 'error_new', 'success_modified', 'error_modified' ), $_SERVER['REQUEST_URI'] );
    8079
    81     // Decide whether to load the dev version of the CSS and JavaScript
     80    // Decide whether to load the dev version of the CSS and JavaScript.
    8281    $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : 'min.';
    8382
     
    9392    do_action( 'bp_groups_admin_load', $doaction );
    9493
    95     // Edit screen
     94    // Edit screen.
    9695    if ( 'do_delete' == $doaction && ! empty( $_GET['gid'] ) ) {
    9796
     
    112111
    113112    } elseif ( 'edit' == $doaction && ! empty( $_GET['gid'] ) ) {
    114         // columns screen option
     113        // Columns screen option.
    115114        add_screen_option( 'layout_columns', array( 'default' => 2, 'max' => 2, ) );
    116115
     
    123122        ) );
    124123
    125         // Help panel - sidebar links
     124        // Help panel - sidebar links.
    126125        get_current_screen()->set_help_sidebar(
    127126            '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' .
     
    142141        do_action( 'bp_groups_admin_meta_boxes' );
    143142
    144         // Enqueue JavaScript files
     143        // Enqueue JavaScript files.
    145144        wp_enqueue_script( 'postbox' );
    146145        wp_enqueue_script( 'dashboard' );
    147146
    148     // Index screen
     147    // Index screen.
    149148    } else {
    150         // Create the Groups screen list table
     149        // Create the Groups screen list table.
    151150        $bp_groups_list_table = new BP_Groups_List_Table();
    152151
    153         // per_page screen option
     152        // The per_page screen option.
    154153        add_screen_option( 'per_page', array( 'label' => _x( 'Groups', 'Groups per page (screen options)', 'buddypress' )) );
    155154
    156         // Help panel - overview text
     155        // Help panel - overview text.
    157156        get_current_screen()->add_help_tab( array(
    158157            'id'      => 'bp-groups-overview',
     
    171170        ) );
    172171
    173         // Help panel - sidebar links
     172        // Help panel - sidebar links.
    174173        get_current_screen()->set_help_sidebar(
    175174            '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' .
     
    180179    $bp = buddypress();
    181180
    182     // Enqueue CSS and JavaScript
     181    // Enqueue CSS and JavaScript.
    183182    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 );
    184183    wp_localize_script( 'bp_groups_admin_js', 'BP_Group_Admin', array(
     
    195194
    196195    if ( $doaction && 'save' == $doaction ) {
    197         // Get group ID
     196        // Get group ID.
    198197        $group_id = isset( $_REQUEST['gid'] ) ? (int) $_REQUEST['gid'] : '';
    199198
     
    203202        ), $redirect_to );
    204203
    205         // Check this is a valid form submission
     204        // Check this is a valid form submission.
    206205        check_admin_referer( 'edit-group_' . $group_id );
    207206
    208         // Get the group from the database
     207        // Get the group from the database.
    209208        $group = groups_get_group( 'group_id=' . $group_id );
    210209
    211         // If the group doesn't exist, just redirect back to the index
     210        // If the group doesn't exist, just redirect back to the index.
    212211        if ( empty( $group->slug ) ) {
    213212            wp_redirect( $redirect_to );
     
    215214        }
    216215
    217         // Check the form for the updated properties
    218 
    219         // Store errors
     216        // Check the form for the updated properties.
     217        // Store errors.
    220218        $error = 0;
    221219        $success_new = $error_new = $success_modified = $error_modified = array();
    222220
    223221        // Group name and description are handled with
    224         // groups_edit_base_group_details()
     222        // groups_edit_base_group_details().
    225223        if ( !groups_edit_base_group_details( $group_id, $_POST['bp-groups-name'], $_POST['bp-groups-description'], 0 ) ) {
    226224            $error = $group_id;
    227225
    228             // using negative integers for different error messages... eek!
     226            // Using negative integers for different error messages... eek!
    229227            if ( empty( $_POST['bp-groups-name'] ) && empty( $_POST['bp-groups-description'] ) ) {
    230228                $error = -3;
     
    236234        }
    237235
    238         // Enable discussion forum
     236        // Enable discussion forum.
    239237        $enable_forum   = ( isset( $_POST['group-show-forum'] ) ) ? 1 : 0;
    240238
     
    263261        }
    264262
    265         // Process new members
     263        // Process new members.
    266264        $user_names = array();
    267265
     
    276274
    277275                // Make sure the user exists before attempting
    278                 // to add to the group
     276                // to add to the group.
    279277                $user = get_user_by( 'slug', $un );
    280278
     
    291289        }
    292290
    293         // Process member role changes
     291        // Process member role changes.
    294292        if ( ! empty( $_POST['bp-groups-role'] ) && ! empty( $_POST['bp-groups-existing-role'] ) ) {
    295293
    296294            // Before processing anything, make sure you're not
    297             // attempting to remove the all user admins
     295            // attempting to remove the all user admins.
    298296            $admin_count = 0;
    299297            foreach ( (array) $_POST['bp-groups-role'] as $new_role ) {
     
    311309            } else {
    312310
    313                 // Process only those users who have had their roles changed
     311                // Process only those users who have had their roles changed.
    314312                foreach ( (array) $_POST['bp-groups-role'] as $user_id => $new_role ) {
    315313
     
    321319                            case 'mod' :
    322320                                // Admin to mod is a demotion. Demote to
    323                                 // member, then fall through
     321                                // member, then fall through.
    324322                                if ( 'admin' == $existing_role ) {
    325323                                    groups_demote_member( $user_id, $group_id );
     
    328326                            case 'admin' :
    329327                                // If the user was banned, we must
    330                                 // unban first
     328                                // unban first.
    331329                                if ( 'banned' == $existing_role ) {
    332330                                    groups_unban_member( $user_id, $group_id );
     
    334332
    335333                                // At this point, each existing_role
    336                                 // is a member, so promote
     334                                // is a member, so promote.
    337335                                $result = groups_promote_member( $user_id, $group_id, $new_role );
    338336
     
    362360                        }
    363361
    364                         // Store the success or failure
     362                        // Store the success or failure.
    365363                        if ( $result ) {
    366364                            $success_modified[] = $user_id;
     
    382380        do_action( 'bp_group_admin_edit_after', $group_id );
    383381
    384         // Create the redirect URL
    385 
     382        // Create the redirect URL.
    386383        if ( $error ) {
    387             // This means there was an error updating group details
     384            // This means there was an error updating group details.
    388385            $redirect_to = add_query_arg( 'error', (int) $error, $redirect_to );
    389386        } else {
    390             // Group details were update successfully
     387            // Group details were update successfully.
    391388            $redirect_to = add_query_arg( 'updated', 1, $redirect_to );
    392389        }
     
    438435 * @param string $option    Screen option name.
    439436 * @param string $new_value Screen option form value.
    440  *
    441437 * @return string Option value. False to abandon update.
    442438 */
     
    445441        return $value;
    446442
    447     // Per page
     443    // Per page.
    448444    $new_value = (int) $new_value;
    449445    if ( $new_value < 1 || $new_value > 999 )
     
    459455 */
    460456function bp_groups_admin() {
    461     // Decide whether to load the index or edit screen
     457    // Decide whether to load the index or edit screen.
    462458    $doaction = bp_admin_list_table_current_bulk_action();
    463459
    464     // Display the single group edit screen
     460    // Display the single group edit screen.
    465461    if ( 'edit' == $doaction && ! empty( $_GET['gid'] ) ) {
    466462        bp_groups_admin_edit();
    467463
    468     // Display the group deletion confirmation screen
     464    // Display the group deletion confirmation screen.
    469465    } elseif ( 'delete' == $doaction && ! empty( $_GET['gid'] ) ) {
    470466        bp_groups_admin_delete();
    471467
    472     // Otherwise, display the groups index screen
     468    // Otherwise, display the groups index screen.
    473469    } else {
    474470        bp_groups_admin_index();
     
    488484    $messages = array();
    489485
    490     // If the user has just made a change to a group, build status messages
     486    // If the user has just made a change to a group, build status messages.
    491487    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'] ) ) {
    492488        $no_admins        = ! empty( $_REQUEST['no_admins']        ) ? 1                                             : 0;
     
    546542    $is_error = ! empty( $no_admins ) || ! empty( $errors ) || ! empty( $error_new ) || ! empty( $error_modified );
    547543
    548     // Get the group from the database
     544    // Get the group from the database.
    549545    $group      = groups_get_group( 'group_id=' . $_GET['gid'] );
    550546
     
    552548    $group_name = isset( $group->name ) ? apply_filters( 'bp_get_group_name', $group->name ) : '';
    553549
    554     // Construct URL for form
     550    // Construct URL for form.
    555551    $form_url = remove_query_arg( array( 'action', 'deleted', 'no_admins', 'error', 'error_new', 'success_new', 'error_modified', 'success_modified' ), $_SERVER['REQUEST_URI'] );
    556552    $form_url = add_query_arg( 'action', 'save', $form_url );
     
    576572        </h1>
    577573
    578         <?php // If the user has just made a change to an group, display the status messages ?>
     574        <?php // If the user has just made a change to an group, display the status messages. ?>
    579575        <?php if ( !empty( $messages ) ) : ?>
    580576            <div id="moderated" class="<?php echo ( $is_error ) ? 'error' : 'updated'; ?>"><p><?php echo implode( "</p><p>", $messages ); ?></p></div>
     
    652648        'include'     => $group_ids,
    653649        'show_hidden' => true,
    654         'per_page'    => null, // Return all results
     650        'per_page'    => null, // Return all results.
    655651    ) );
    656652
    657     // Create a new list of group ids, based on those that actually exist
     653    // Create a new list of group ids, based on those that actually exist.
    658654    $gids = array();
    659655    foreach ( $groups['groups'] as $group ) {
     
    697693    $messages = array();
    698694
    699     // If the user has just made a change to a group, build status messages
     695    // If the user has just made a change to a group, build status messages.
    700696    if ( ! empty( $_REQUEST['deleted'] ) ) {
    701697        $deleted  = ! empty( $_REQUEST['deleted'] ) ? (int) $_REQUEST['deleted'] : 0;
     
    706702    }
    707703
    708     // Prepare the group items for display
     704    // Prepare the group items for display.
    709705    $bp_groups_list_table->prepare_items();
    710706
     
    733729        </h1>
    734730
    735         <?php // If the user has just made a change to an group, display the status messages ?>
     731        <?php // If the user has just made a change to an group, display the status messages. ?>
    736732        <?php if ( !empty( $messages ) ) : ?>
    737733            <div id="moderated" class="<?php echo ( ! empty( $_REQUEST['error'] ) ) ? 'error' : 'updated'; ?>"><p><?php echo implode( "<br/>\n", $messages ); ?></p></div>
    738734        <?php endif; ?>
    739735
    740         <?php // Display each group on its own row ?>
     736        <?php // Display each group on its own row. ?>
    741737        <?php $bp_groups_list_table->views(); ?>
    742738
     
    800796 *
    801797 * @since 1.7.0
     798 *
     799 * @param BP_Groups_Group $item The BP_Groups_Group object for the current group.
    802800 */
    803801function bp_groups_admin_edit_metabox_add_new_members( $item ) {
     
    821819    // Pull up a list of group members, so we can separate out the types
    822820    // We'll also keep track of group members here to place them into a
    823     // JavaScript variable, which will help with group member autocomplete
     821    // JavaScript variable, which will help with group member autocomplete.
    824822    $members = array(
    825823        'admin'  => array(),
     
    851849    }
    852850
    853     // Echo out the JavaScript variable
     851    // Echo out the JavaScript variable.
    854852    echo '<script type="text/javascript">var group_id = "' . esc_js( $item->id ) . '";</script>';
    855853
    856     // Loop through each member type
     854    // Loop through each member type.
    857855    foreach ( $members as $member_type => $type_users ) : ?>
    858856
     
    10081006 * @param BP_Group_Member_Query $query       A BP_Group_Member_Query object.
    10091007 * @param string                $member_type member|mod|admin|banned.
    1010  *
    10111008 * @return string Pagination links HTML.
    10121009 */
     
    10181015    }
    10191016
    1020     // The key used to paginate this member type in the $_GET global
     1017    // The key used to paginate this member type in the $_GET global.
    10211018    $qs_key = $member_type . '_page';
    10221019    $url_base = remove_query_arg( array( $qs_key, 'updated', 'success_modified' ), $_SERVER['REQUEST_URI'] );
     
    10251022    $per_page = 10; // @todo Make this customizable?
    10261023
    1027     // Don't show anything if there's no pagination
     1024    // Don't show anything if there's no pagination.
    10281025    if ( 1 === $page && $query->total_users <= $per_page ) {
    10291026        return $pagination;
     
    10651062 *
    10661063 * @param array $user_ids Array of user IDs.
    1067  *
    10681064 * @return array Array of user_logins corresponding to $user_ids.
    10691065 */
     
    10871083function bp_groups_admin_autocomplete_handler() {
    10881084
    1089     // Bail if user user shouldn't be here, or is a large network
     1085    // Bail if user user shouldn't be here, or is a large network.
    10901086    if ( ! current_user_can( 'bp_moderate' ) || ( is_multisite() && wp_is_large_network( 'users' ) ) ) {
    10911087        wp_die( -1 );
     
    11121108
    11131109            $matches[] = array(
    1114                 // translators: 1: user_login, 2: user_email
     1110                // Translators: 1: user_login, 2: user_email.
    11151111                'label' => sprintf( __( '%1$s (%2$s)', 'buddypress' ), $user->name, $user->ID ),
    11161112                'value' => $user->ID,
     
    11331129     * The type of view currently being displayed.
    11341130     *
    1135      * e.g. "All", "Pending", "Approved", "Spam"...
     1131     * E.g. "All", "Pending", "Approved", "Spam"...
    11361132     *
    11371133     * @since 1.7.0
     
    11861182        $screen = get_current_screen();
    11871183
    1188         // Option defaults
     1184        // Option defaults.
    11891185        $include_id   = false;
    11901186        $search_terms = false;
    11911187
    1192         // Set current page
     1188        // Set current page.
    11931189        $page = $this->get_pagenum();
    11941190
    1195         // Set per page from the screen options
     1191        // Set per page from the screen options.
    11961192        $per_page = $this->get_items_per_page( str_replace( '-', '_', "{$screen->id}_per_page" ) );
    11971193
     
    12021198        }
    12031199
    1204         // Order by - default to newest
     1200        // Order by - default to newest.
    12051201        $orderby = 'last_activity';
    12061202        if ( ! empty( $_REQUEST['orderby'] ) ) {
     
    12291225            $include_id = (int) $_REQUEST['gid'];
    12301226
    1231         // Set the current view
     1227        // Set the current view.
    12321228        if ( isset( $_GET['group_status'] ) && in_array( $_GET['group_status'], array( 'public', 'private', 'hidden' ) ) ) {
    12331229            $this->view = $_GET['group_status'];
    12341230        }
    12351231
    1236         // We'll use the ids of group types for the 'include' param
     1232        // We'll use the ids of group types for the 'include' param.
    12371233        $this->group_type_ids = BP_Groups_Group::get_group_type_ids();
    12381234
    1239         // Pass a dummy array if there are no groups of this type
     1235        // Pass a dummy array if there are no groups of this type.
    12401236        $include = false;
    12411237        if ( 'all' != $this->view && isset( $this->group_type_ids[ $this->view ] ) ) {
     
    12431239        }
    12441240
    1245         // Get group type counts for display in the filter tabs
     1241        // Get group type counts for display in the filter tabs.
    12461242        $this->group_counts = array();
    12471243        foreach ( $this->group_type_ids as $group_type => $group_ids ) {
     
    12701266        }
    12711267
    1272         // Set raw data to display
     1268        // Set raw data to display.
    12731269        $this->items = $groups;
    12741270
    1275         // Store information needed for handling table pagination
     1271        // Store information needed for handling table pagination.
    12761272        $this->set_pagination_args( array(
    12771273            'per_page'    => $per_page,
     
    13071303     */
    13081304    protected function get_default_primary_column_name() {
    1309         // comment column is mapped to Group's name
     1305        // Comment column is mapped to Group's name.
    13101306        return 'comment';
    13111307    }
     
    13241320     *
    13251321     * @since 1.7.0
    1326     */
     1322     */
    13271323    public function display() {
    13281324        $this->display_tablenav( 'top' ); ?>
     
    14981494     * @since 2.3.4 Visibility set to public for compatibility with WP < 4.0.0.
    14991495     *
    1500      * @param array $actions The list of actions
    1501      * @param bool $always_visible Whether the actions should be always visible
     1496     * @param array $actions        The list of actions.
     1497     * @param bool  $always_visible Whether the actions should be always visible.
    15021498     * @return string
    15031499     */
     
    15591555    public function column_comment( $item = array() ) {
    15601556
    1561         // Preorder items: Edit | Delete | View
     1557        // Preorder items: Edit | Delete | View.
    15621558        $actions = array(
    15631559            'edit'   => '',
     
    15661562        );
    15671563
    1568         // We need the group object for some BP functions
     1564        // We need the group object for some BP functions.
    15691565        $item_obj = (object) $item;
    15701566
    1571         // Build actions URLs
     1567        // Build actions URLs.
    15721568        $base_url   = bp_get_admin_url( 'admin.php?page=bp-groups&amp;gid=' . $item['id'] );
    15731569        $delete_url = wp_nonce_url( $base_url . "&amp;action=delete", 'bp-groups-delete' );
     
    15851581        $group_name = apply_filters_ref_array( 'bp_get_group_name', array( $item['name'] ), $item );
    15861582
    1587         // Rollover actions
    1588 
    1589         // Edit
     1583        // Rollover actions.
     1584        // Edit.
    15901585        $actions['edit']   = sprintf( '<a href="%s">%s</a>', esc_url( $edit_url   ), __( 'Edit',   'buddypress' ) );
    15911586
    1592         // Delete
     1587        // Delete.
    15931588        $actions['delete'] = sprintf( '<a href="%s">%s</a>', esc_url( $delete_url ), __( 'Delete', 'buddypress' ) );
    15941589
    1595         // Visit
     1590        // Visit.
    15961591        $actions['view']   = sprintf( '<a href="%s">%s</a>', esc_url( $view_url   ), __( 'View',   'buddypress' ) );
    15971592
     
    16061601        $actions = apply_filters( 'bp_groups_admin_comment_row_actions', array_filter( $actions ), $item );
    16071602
    1608         // Get group name and avatar
     1603        // Get group name and avatar.
    16091604        $avatar = '';
    16101605
     
    16591654
    16601655        // @todo This should be abstracted out somewhere for the whole
    1661         // Groups component
     1656        // Groups component.
    16621657        switch ( $status ) {
    16631658            case 'public' :
     
    17321727     * @param array  $item        Information about the current row.
    17331728     * @param string $column_name The column name.
    1734      *
    17351729     * @return string
    17361730     */
Note: See TracChangeset for help on using the changeset viewer.