BP_Groups_List_Table

List table class for the Groups component admin page.

Description

Source

File: bp-groups/classes/class-bp-groups-list-table.php

20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
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
     * @var string
     */
    public $view = 'all';
 
    /**
     * Group counts for each group type.
     *
     * @since BuddyPress 1.7.0
     * @var int
     */
    public $group_counts = 0;
 
    /**
     * Multidimensional array of group visibility (status) types and their groups.
     *
     * @var array
     */
    public $group_type_ids = array();
 
    /**
     * 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',
        ) );
 
        // Add Group Type column and bulk change controls.
        if ( bp_groups_get_group_types() ) {
            // Add Group Type column.
            add_filter( 'bp_groups_list_table_get_columns',        array( $this, 'add_type_column' )                  );
            add_filter( 'bp_groups_admin_get_group_custom_column', array( $this, 'column_content_group_type' ), 10, 3 );
            // Add the bulk change select.
            add_action( 'bp_groups_list_table_after_bulk_actions', array( $this, 'add_group_type_bulk_change_select' ) );
        }
    }
 
    /**
     * 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
     */
    public 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 status 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 );
        }
 
        // Group types
        $group_type = false;
        if ( isset( $_GET['bp-group-type'] ) && null !== bp_groups_get_group_type_object( $_GET['bp-group-type'] ) ) {
            $group_type = $_GET['bp-group-type'];
        }
 
        // If we're viewing a specific group, flatten all activities into a single array.
        if ( $include_id ) {
            $groups = array( (array) groups_get_group( $include_id ) );
        } else {
            $groups_args = array(
                'include'  => $include,
                'per_page' => $per_page,
                'page'     => $page,
                'orderby'  => $orderby,
                'order'    => $order
            );
 
            if ( $group_type ) {
                $groups_args['group_type'] = $group_type;
            }
 
            $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.
     */
    public function get_column_info() {
        $this->_column_headers = array(
            $this->get_columns(),
            array(),
            $this->get_sortable_columns(),
            $this->get_default_primary_column_name(),
        );
 
        return $this->_column_headers;
    }
 
    /**
     * Get name of default primary column
     *
     * @since BuddyPress 2.3.3
     *
     * @return string
     */
    protected function get_default_primary_column_name() {
        // Comment column is mapped to Group's name.
        return 'comment';
    }
 
    /**
     * Display a message on screen when no items are found ("No groups found").
     *
     * @since BuddyPress 1.7.0
     */
    public function no_items() {
        _e( 'No groups found.', 'buddyboss' );
    }
 
    /**
     * Output the Groups data table.
     *
     * @since BuddyPress 1.7.0
     */
    public function display() {
        $this->display_tablenav( 'top' ); ?>
 
        <h2 class="screen-reader-text"><?php
            /* translators: accessibility text */
            _e( 'Groups list', 'buddyboss' );
        ?></h2>
 
        <table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>" cellspacing="0">
            <thead>
                <tr>
                    <?php $this->print_column_headers(); ?>
                </tr>
            </thead>
 
            <tbody id="the-comment-list">
                <?php $this->display_rows_or_placeholder(); ?>
            </tbody>
 
            <tfoot>
                <tr>
                    <?php $this->print_column_headers( false ); ?>
                </tr>
            </tfoot>
        </table>
        <?php
 
        $this->display_tablenav( 'bottom' );
    }
 
    /**
     * Extra controls to be displayed between bulk actions and pagination
     *
     * @since BuddyPress 2.7.0
     * @access protected
     *
     * @param string $which
     */
    protected function extra_tablenav( $which ) {
        /**
         * Fires just after the bulk action controls in the WP Admin groups list table.
         *
         * @since BuddyPress 2.7.0
         *
         * @param string $which The location of the extra table nav markup: 'top' or 'bottom'.
         */
        do_action( 'bp_groups_list_table_after_bulk_actions', $which );
    }
 
    /**
     * Generate content for a single row of the table.
     *
     * @since BuddyPress 1.7.0
     *
     * @param object|array $item The current group item in the loop.
     */
    public function single_row( $item = array() ) {
        static $even = false;
 
        $row_classes = array();
 
        if ( $even ) {
            $row_classes = array( 'even' );
        } else {
            $row_classes = array( 'alternate', 'odd' );
        }
 
        /**
         * Filters the classes applied to a single row in the groups list table.
         *
         * @since BuddyPress 1.9.0
         *
         * @param array  $row_classes Array of classes to apply to the row.
         * @param string $value       ID of the current group being displayed.
         */
        $row_classes = apply_filters( 'bp_groups_admin_row_class', $row_classes, $item['id'] );
        $row_class = ' class="' . implode( ' ', $row_classes ) . '"';
 
        echo '<tr' . $row_class . ' id="group-' . esc_attr( $item['id'] ) . '" data-parent_id="' . esc_attr( $item['id'] ) . '" data-root_id="' . esc_attr( $item['id'] ) . '">';
        echo $this->single_row_columns( $item );
        echo '</tr>';
 
        $even = ! $even;
    }
 
    /**
     * Get the list of views available on this table (e.g. "all", "public").
     *
     * @since BuddyPress 1.7.0
     */
    public function get_views() {
        $url_base = bp_get_admin_url( 'admin.php?page=bp-groups' ); ?>
 
        <h2 class="screen-reader-text"><?php
            /* translators: accessibility text */
            _e( 'Filter groups list', 'buddyboss' );
        ?></h2>
 
        <ul class="subsubsub">
            <li class="all"><a href="<?php echo esc_url( $url_base ); ?>" class="<?php if ( 'all' == $this->view ) echo 'current'; ?>"><?php _e( 'All', 'buddyboss' ); ?></a> |</li>
            <li class="public"><a href="<?php echo esc_url( add_query_arg( 'group_status', 'public', $url_base ) ); ?>" class="<?php if ( 'public' == $this->view ) echo 'current'; ?>"><?php printf( _n( 'Public <span class="count">(%s)</span>', 'Public <span class="count">(%s)</span>', $this->group_counts['public'], 'buddyboss' ), number_format_i18n( $this->group_counts['public'] ) ); ?></a> |</li>
            <li class="private"><a href="<?php echo esc_url( add_query_arg( 'group_status', 'private', $url_base ) ); ?>" class="<?php if ( 'private' == $this->view ) echo 'current'; ?>"><?php printf( _n( 'Private <span class="count">(%s)</span>', 'Private <span class="count">(%s)</span>', $this->group_counts['private'], 'buddyboss' ), number_format_i18n( $this->group_counts['private'] ) ); ?></a> |</li>
            <li class="hidden"><a href="<?php echo esc_url( add_query_arg( 'group_status', 'hidden', $url_base ) ); ?>" class="<?php if ( 'hidden' == $this->view ) echo 'current'; ?>"><?php printf( _n( 'Hidden <span class="count">(%s)</span>', 'Hidden <span class="count">(%s)</span>', $this->group_counts['hidden'], 'buddyboss' ), number_format_i18n( $this->group_counts['hidden'] ) ); ?></a></li>
 
            <?php
 
            /**
             * Fires inside listing of views so plugins can add their own.
             *
             * @since BuddyPress 1.7.0
             *
             * @param string $url_base Current URL base for view.
             * @param string $view     Current view being displayed.
             */
            do_action( 'bp_groups_list_table_get_views', $url_base, $this->view ); ?>
        </ul>
    <?php
    }
 
    /**
     * Get bulk actions for single group row.
     *
     * @since BuddyPress 1.7.0
     *
     * @return array Key/value pairs for the bulk actions dropdown.
     */
    public function get_bulk_actions() {
 
        /**
         * Filters the list of bulk actions to display on a single group row.
         *
         * @since BuddyPress 1.7.0
         *
         * @param array $value Array of bulk actions to display.
         */
        return apply_filters( 'bp_groups_list_table_get_bulk_actions', array(
            'delete' => __( 'Delete', 'buddyboss' )
        ) );
    }
 
    /**
     * Get the table column titles.
     *
     * @since BuddyPress 1.7.0
     *
     * @see WP_List_Table::single_row_columns()
     *
     * @return array Array of column titles.
     */
    public function get_columns() {
 
        /**
         * Filters the titles for the columns for the groups list table.
         *
         * @since BuddyPress 2.0.0
         *
         * @param array $value Array of slugs and titles for the columns.
         */
        return apply_filters( 'bp_groups_list_table_get_columns', array(
            'cb'          => '<input name type="checkbox" />',
            'comment'     => __( 'Name', 'buddyboss' ),
            'description' => __( 'Description', 'buddyboss' ),
            'status'      => __( 'Status', 'buddyboss' ),
            'members'     => __( 'Members', 'buddyboss' ),
            'last_active' => __( 'Last Active', 'buddyboss' )
        ) );
    }
 
    /**
     * 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.
     */
    public function get_sortable_columns() {
        return array(
            'gid'         => array( 'gid', false ),
            'comment'     => array( 'name', false ),
            'members'     => array( 'members', false ),
            'last_active' => array( 'last_active', false ),
        );
    }
 
    /**
     * Override WP_List_Table::row_actions().
     *
     * Basically a duplicate of the row_actions() method, but removes the
     * unnecessary <button> addition.
     *
     * @since BuddyPress 2.3.3
     * @since BuddyPress 2.3.4 Visibility set to public for compatibility with WP < 4.0.0.
     *
     * @param array $actions        The list of actions.
     * @param bool  $always_visible Whether the actions should be always visible.
     * @return string
     */
    public function row_actions( $actions, $always_visible = false ) {
        $action_count = count( $actions );
        $i = 0;
 
        if ( !$action_count )
            return '';
 
        $out = '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">';
        foreach ( $actions as $action => $link ) {
            ++$i;
            ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
            $out .= "<span class='$action'>$link$sep</span>";
        }
        $out .= '</div>';
 
        return $out;
    }
 
    /**
     * 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).
     */
    public function column_cb( $item = array() ) {
        /* translators: accessibility text */
        printf( '<label class="screen-reader-text" for="gid-%1$d">' . __( 'Select group %1$d', 'buddyboss' ) . '</label><input type="checkbox" name="gid[]" value="%1$d" id="gid-%1$d" />', $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).
     */
    public function column_gid( $item = array() ) {
        echo '<strong>' . absint( $item['id'] ) . '</strong>';
    }
 
    /**
     * 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).
     */
    public function column_comment( $item = array() ) {
 
        // Preorder items: Edit | Delete | View.
        $actions = array(
            'edit'   => '',
            'delete' => '',
            'view'   => '',
        );
 
        // 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&amp;gid=' . $item['id'] );
        $delete_url = wp_nonce_url( $base_url . "&amp;action=delete", 'bp-groups-delete' );
        $edit_url   = $base_url . '&amp;action=edit';
        $view_url   = bp_get_group_permalink( $item_obj );
 
        /**
         * Filters the group name for a group's column content.
         *
         * @since BuddyPress 1.7.0
         *
         * @param string $value Name of the group being rendered.
         * @param array  $item  Array for the current group item.
         */
        $group_name = apply_filters_ref_array( 'bp_get_group_name', array( $item['name'], $item ) );
 
        // Rollover actions.
        // Edit.
        $actions['edit']   = sprintf( '<a href="%s">%s</a>', esc_url( $edit_url   ), __( 'Edit',   'buddyboss' ) );
 
        // Delete.
        $actions['delete'] = sprintf( '<a href="%s">%s</a>', esc_url( $delete_url ), __( 'Delete', 'buddyboss' ) );
 
        // Visit.
        $actions['view']   = sprintf( '<a href="%s">%s</a>', esc_url( $view_url   ), __( 'View',   'buddyboss' ) );
 
        /**
         * Filters the actions that will be shown for the column content.
         *
         * @since BuddyPress 1.7.0
         *
         * @param array $value Array of actions to be displayed for the column content.
         * @param array $item  The current group item in the loop.
         */
        $actions = apply_filters( 'bp_groups_admin_comment_row_actions', array_filter( $actions ), $item );
 
        // Get group name and avatar.
        $avatar = '';
 
        if ( buddypress()->avatar->show_avatars ) {
            $avatar  = bp_core_fetch_avatar( array(
                'item_id'    => $item['id'],
                'object'     => 'group',
                'type'       => 'thumb',
                'avatar_dir' => 'group-avatars',
                'alt'        => sprintf( __( 'Group logo of %s', 'buddyboss' ), $group_name ),
                'width'      => '32',
                'height'     => '32',
                'title'      => $group_name
            ) );
        }
 
        $content = sprintf( '<strong><a href="%s">%s</a></strong>', esc_url( $edit_url ), $group_name );
 
        echo $avatar . ' ' . $content . ' ' . $this->row_actions( $actions );
    }
 
    /**
     * Markup for the Description column.
     *
     * @since BuddyPress 1.7.0
     *
     * @param array $item Information about the current row.
     */
    public function column_description( $item = array() ) {
 
        /**
         * Filters the markup for the Description column.
         *
         * @since BuddyPress 1.0.0
         *
         * @param string $value Markup for the Description column.
         * @param array  $item  The current group item in the loop.
         */
        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 $item Information about the current row.
     */
    public 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', 'buddyboss' );
                break;
            case 'private' :
                $status_desc = __( 'Private', 'buddyboss' );
                break;
            case 'hidden' :
                $status_desc = __( 'Hidden', 'buddyboss' );
                break;
        }
 
        /**
         * Filters the markup for the Status column.
         *
         * @since BuddyPress 1.7.0
         *
         * @param string $status_desc Markup for the Status column.
         * @parma array  $item        The current group item in the loop.
         */
        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 $item Information about the current row.
     */
    public function column_members( $item = array() ) {
        $count = groups_get_groupmeta( $item['id'], 'total_member_count' );
 
        /**
         * Filters the markup for the number of Members column.
         *
         * @since BuddyPress 1.7.0
         *
         * @param int   $count Markup for the number of Members column.
         * @parma array $item  The current group item in the loop.
         */
        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 $item Information about the current row.
     */
    public function column_last_active( $item = array() ) {
        $last_active = groups_get_groupmeta( $item['id'], 'last_activity' );
 
        /**
         * Filters the markup for the Last Active column.
         *
         * @since BuddyPress 1.7.0
         *
         * @param string $last_active Markup for the Last Active column.
         * @parma array  $item        The current group item in the loop.
         */
        echo apply_filters_ref_array( 'bp_groups_admin_get_group_last_active', array( $last_active, $item ) );
    }
 
    /**
     * Allow plugins to add their custom column.
     *
     * @since BuddyPress 2.0.0
     *
     * @param array  $item        Information about the current row.
     * @param string $column_name The column name.
     * @return string
     */
    public function column_default( $item = array(), $column_name = '' ) {
 
        /**
         * Filters a string to allow plugins to add custom column content.
         *
         * @since BuddyPress 2.0.0
         *
         * @param string $value       Empty string.
         * @param string $column_name Name of the column being rendered.
         * @param array  $item        The current group item in the loop.
         */
        return apply_filters( 'bp_groups_admin_get_group_custom_column', '', $column_name, $item );
    }
 
    // Group Types
 
    /**
     * Add group type column to the WordPress admin groups list table.
     *
     * @since BuddyPress 2.7.0
     *
     * @param array $columns Groups table columns.
     *
     * @return array $columns
     */
    public function add_type_column( $columns = array() ) {
        $columns['bp_group_type'] = __( 'Group Type', 'buddyboss' );
 
        return $columns;
    }
 
    /**
     * Markup for the Group Type column.
     *
     * @since BuddyPress 2.7.0
     *
     * @param string $retval      Empty string.
     * @param string $column_name Name of the column being rendered.
     * @param array  $item        The current group item in the loop.
     * @return string
     */
    public function column_content_group_type( $retval = '', $column_name, $item ) {
        if ( 'bp_group_type' !== $column_name ) {
            return $retval;
        }
 
        add_filter( 'bp_get_group_type_directory_permalink', array( $this, 'group_type_permalink_use_admin_filter' ), 10, 2 );
        $retval = bp_get_group_type_list( $item['id'], array(
            'parent_element' => '',
            'label_element'  => '',
            'label'          => '',
            'show_all'       => true
        ) );
        remove_filter( 'bp_get_group_type_directory_permalink', array( $this, 'group_type_permalink_use_admin_filter' ), 10 );
 
        /**
         * Filters the markup for the Group Type column.
         *
         * @since BuddyPress 2.7.0
         *
         * @param string $retval Markup for the Group Type column.
         * @parma array  $item   The current group item in the loop.
         */
        echo apply_filters_ref_array( 'bp_groups_admin_get_group_type_column', array( $retval, $item ) );
    }
 
    /**
     * Filters the group type list permalink in the Group Type column.
     *
     * Changes the group type permalink to use the admin URL.
     *
     * @since BuddyPress 2.7.0
     *
     * @param  string $retval Current group type permalink.
     * @param  object $type   Group type object.
     * @return string
     */
    public function group_type_permalink_use_admin_filter( $retval, $type ) {
        return add_query_arg( array( 'bp-group-type' => urlencode( $type->name ) ) );
    }
 
    /**
     * Markup for the Group Type bulk change select.
     *
     * @since BuddyPress 2.7.0
     *
     * @param string $which The location of the extra table nav markup: 'top' or 'bottom'.
     */
    public function add_group_type_bulk_change_select( $which ) {
        // `$which` is only passed in WordPress 4.6+. Avoid duplicating controls in earlier versions.
        static $displayed = false;
        if ( version_compare( bp_get_major_wp_version(), '4.6', '<' ) && $displayed ) {
            return;
        }
        $displayed = true;
        $id_name = 'bottom' === $which ? 'bp_change_type2' : 'bp_change_type';
 
        $types = bp_groups_get_group_types( array(), 'objects' );
        ?>
        <div class="alignleft actions">
            <label class="screen-reader-text" for="<?php echo $id_name; ?>"><?php _e( 'Change group type to&hellip;', 'buddyboss' ) ?></label>
            <select name="<?php echo $id_name; ?>" id="<?php echo $id_name; ?>" style="display:inline-block;float:none;">
                <option value=""><?php _e( 'Change group type to&hellip;', 'buddyboss' ) ?></option>
 
                <?php foreach( $types as $type ) : ?>
 
                    <option value="<?php echo esc_attr( $type->name ); ?>"><?php echo esc_html( $type->labels['singular_name'] ); ?></option>
 
                <?php endforeach; ?>
 
                <option value="remove_group_type"><?php _e( 'No Group Type', 'buddyboss' ) ?></option>
 
            </select>
            <?php
            wp_nonce_field( 'bp-bulk-groups-change-type-' . bp_loggedin_user_id(), 'bp-bulk-groups-change-type-nonce' );
            submit_button( __( 'Change', 'buddyboss' ), 'button', 'bp_change_group_type', false );
        ?>
        </div>
        <?php
    }
}

Changelog

Changelog
Version Description
BuddyPress 1.7.0 Introduced.

Methods

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.