[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * BuddyPress Groups admin list table class. 4 * 5 * Props to WordPress core for the Comments admin screen, and its contextual 6 * help text, on which this implementation is heavily based. 7 * 8 * @package BuddyPress 9 * @subpackage Groups 10 * @since 1.7.0 11 */ 12 13 // Exit if accessed directly. 14 defined( 'ABSPATH' ) || exit; 15 16 /** 17 * List table class for the Groups component admin page. 18 * 19 * @since 1.7.0 20 */ 21 class BP_Groups_List_Table extends WP_List_Table { 22 23 /** 24 * The type of view currently being displayed. 25 * 26 * E.g. "All", "Pending", "Approved", "Spam"... 27 * 28 * @since 1.7.0 29 * @var string 30 */ 31 public $view = 'all'; 32 33 /** 34 * Group counts for each group type. 35 * 36 * @since 1.7.0 37 * @var int 38 */ 39 public $group_counts = 0; 40 41 /** 42 * Multidimensional array of group visibility (status) types and their groups. 43 * 44 * @link https://buddypress.trac.wordpress.org/ticket/6277 45 * @var array 46 */ 47 public $group_type_ids = array(); 48 49 /** 50 * Constructor 51 * 52 * @since 1.7.0 53 */ 54 public function __construct() { 55 56 // Define singular and plural labels, as well as whether we support AJAX. 57 parent::__construct( array( 58 'ajax' => false, 59 'plural' => 'groups', 60 'singular' => 'group', 61 ) ); 62 63 // Add Group Type column and bulk change controls. 64 if ( bp_groups_get_group_types() ) { 65 // Add Group Type column. 66 add_filter( 'bp_groups_list_table_get_columns', array( $this, 'add_type_column' ) ); 67 add_filter( 'bp_groups_admin_get_group_custom_column', array( $this, 'column_content_group_type' ), 10, 3 ); 68 // Add the bulk change select. 69 add_action( 'bp_groups_list_table_after_bulk_actions', array( $this, 'add_group_type_bulk_change_select' ) ); 70 } 71 } 72 73 /** 74 * Set up items for display in the list table. 75 * 76 * Handles filtering of data, sorting, pagination, and any other data 77 * manipulation required prior to rendering. 78 * 79 * @since 1.7.0 80 */ 81 public function prepare_items() { 82 global $groups_template; 83 84 $screen = get_current_screen(); 85 86 // Option defaults. 87 $include_id = false; 88 $search_terms = false; 89 90 // Set current page. 91 $page = $this->get_pagenum(); 92 93 // Set per page from the screen options. 94 $per_page = $this->get_items_per_page( str_replace( '-', '_', "{$screen->id}_per_page" ) ); 95 96 // Sort order. 97 $order = 'DESC'; 98 if ( ! empty( $_REQUEST['order'] ) ) { 99 $order = bp_esc_sql_order( $_REQUEST['order'] ); 100 } 101 102 // Order by - default to newest. 103 $orderby = 'last_activity'; 104 if ( ! empty( $_REQUEST['orderby'] ) ) { 105 switch ( $_REQUEST['orderby'] ) { 106 case 'name' : 107 $orderby = 'name'; 108 break; 109 case 'id' : 110 $orderby = 'date_created'; 111 break; 112 case 'members' : 113 $orderby = 'total_member_count'; 114 break; 115 case 'last_active' : 116 $orderby = 'last_activity'; 117 break; 118 } 119 } 120 121 // Are we doing a search? 122 if ( ! empty( $_REQUEST['s'] ) ) { 123 $search_terms = $_REQUEST['s']; 124 125 // Set the view as a search request. 126 $this->view = 'search'; 127 } 128 129 // Check if user has clicked on a specific group (if so, fetch only that group). 130 if ( ! empty( $_REQUEST['gid'] ) ) { 131 $include_id = (int) $_REQUEST['gid']; 132 133 // Set the view as a single activity. 134 $this->view = 'single'; 135 } 136 137 // Use the status request to set the current view. 138 if ( isset( $_GET['group_status'] ) && in_array( $_GET['group_status'], array( 'public', 'private', 'hidden' ) ) ) { 139 $this->view = $_GET['group_status']; 140 } 141 142 // We'll use the ids of group status types for the 'include' param. 143 $this->group_type_ids = BP_Groups_Group::get_group_type_ids(); 144 145 // Pass a dummy array if there are no groups of this type. 146 $include = false; 147 if ( 'all' != $this->view && isset( $this->group_type_ids[ $this->view ] ) ) { 148 $include = ! empty( $this->group_type_ids[ $this->view ] ) ? $this->group_type_ids[ $this->view ] : array( 0 ); 149 } 150 151 // Get group type counts for display in the filter tabs. 152 $this->group_counts = array(); 153 foreach ( $this->group_type_ids as $group_type => $group_ids ) { 154 $this->group_counts[ $group_type ] = count( $group_ids ); 155 } 156 157 // Group types 158 $group_type = false; 159 if ( isset( $_GET['bp-group-type'] ) && null !== bp_groups_get_group_type_object( $_GET['bp-group-type'] ) ) { 160 $group_type = $_GET['bp-group-type']; 161 } 162 163 // If we're viewing a specific group, flatten all activities into a single array. 164 if ( $include_id ) { 165 $groups = array( (array) groups_get_group( $include_id ) ); 166 } else { 167 $groups_args = array( 168 'include' => $include, 169 'per_page' => $per_page, 170 'page' => $page, 171 'orderby' => $orderby, 172 'order' => $order 173 ); 174 175 if ( $group_type ) { 176 $groups_args['group_type'] = $group_type; 177 } 178 179 $groups = array(); 180 if ( bp_has_groups( $groups_args ) ) { 181 while ( bp_groups() ) { 182 bp_the_group(); 183 $groups[] = (array) $groups_template->group; 184 } 185 } 186 } 187 188 // Set raw data to display. 189 $this->items = $groups; 190 191 // Store information needed for handling table pagination. 192 $this->set_pagination_args( array( 193 'per_page' => $per_page, 194 'total_items' => $groups_template->total_group_count, 195 'total_pages' => ceil( $groups_template->total_group_count / $per_page ) 196 ) ); 197 198 // Set the Total number of groups. 199 if ( 'all' === $this->view ) { 200 $this->group_counts['all'] = (int) $groups_template->total_group_count; 201 202 // Only perform a query if not on the main list view. 203 } elseif ( 'single' !== $this->view ) { 204 $count_groups = groups_get_groups( 205 array( 206 'fields' => 'ids', 207 'show_hidden' => true, 208 ) 209 ); 210 211 if ( $count_groups['total'] ) { 212 $this->group_counts['all'] = (int) $count_groups['total']; 213 } 214 } 215 } 216 217 /** 218 * Get an array of all the columns on the page. 219 * 220 * @since 1.7.0 221 * 222 * @return array Array of column headers. 223 */ 224 public function get_column_info() { 225 $this->_column_headers = array( 226 $this->get_columns(), 227 array(), 228 $this->get_sortable_columns(), 229 $this->get_default_primary_column_name(), 230 ); 231 232 return $this->_column_headers; 233 } 234 235 /** 236 * Get name of default primary column 237 * 238 * @since 2.3.3 239 * 240 * @return string 241 */ 242 protected function get_default_primary_column_name() { 243 // Comment column is mapped to Group's name. 244 return 'comment'; 245 } 246 247 /** 248 * Display a message on screen when no items are found ("No groups found"). 249 * 250 * @since 1.7.0 251 */ 252 public function no_items() { 253 _e( 'No groups found.', 'buddypress' ); 254 } 255 256 /** 257 * Output the Groups data table. 258 * 259 * @since 1.7.0 260 */ 261 public function display() { 262 $this->display_tablenav( 'top' ); ?> 263 264 <h2 class="screen-reader-text"><?php 265 /* translators: accessibility text */ 266 _e( 'Groups list', 'buddypress' ); 267 ?></h2> 268 269 <table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>" cellspacing="0"> 270 <thead> 271 <tr> 272 <?php $this->print_column_headers(); ?> 273 </tr> 274 </thead> 275 276 <tbody id="the-comment-list"> 277 <?php $this->display_rows_or_placeholder(); ?> 278 </tbody> 279 280 <tfoot> 281 <tr> 282 <?php $this->print_column_headers( false ); ?> 283 </tr> 284 </tfoot> 285 </table> 286 <?php 287 288 $this->display_tablenav( 'bottom' ); 289 } 290 291 /** 292 * Extra controls to be displayed between bulk actions and pagination 293 * 294 * @since 2.7.0 295 * @access protected 296 * 297 * @param string $which 298 */ 299 protected function extra_tablenav( $which ) { 300 /** 301 * Fires just after the bulk action controls in the WP Admin groups list table. 302 * 303 * @since 2.7.0 304 * 305 * @param string $which The location of the extra table nav markup: 'top' or 'bottom'. 306 */ 307 do_action( 'bp_groups_list_table_after_bulk_actions', $which ); 308 } 309 310 /** 311 * Generate content for a single row of the table. 312 * 313 * @since 1.7.0 314 * 315 * @param object|array $item The current group item in the loop. 316 */ 317 public function single_row( $item = array() ) { 318 static $even = false; 319 320 $row_classes = array(); 321 322 if ( $even ) { 323 $row_classes = array( 'even' ); 324 } else { 325 $row_classes = array( 'alternate', 'odd' ); 326 } 327 328 /** 329 * Filters the classes applied to a single row in the groups list table. 330 * 331 * @since 1.9.0 332 * 333 * @param array $row_classes Array of classes to apply to the row. 334 * @param string $value ID of the current group being displayed. 335 */ 336 $row_classes = apply_filters( 'bp_groups_admin_row_class', $row_classes, $item['id'] ); 337 $row_class = ' class="' . implode( ' ', $row_classes ) . '"'; 338 339 echo '<tr' . $row_class . ' id="group-' . esc_attr( $item['id'] ) . '" data-parent_id="' . esc_attr( $item['id'] ) . '" data-root_id="' . esc_attr( $item['id'] ) . '">'; 340 echo $this->single_row_columns( $item ); 341 echo '</tr>'; 342 343 $even = ! $even; 344 } 345 346 /** 347 * Get the list of views available on this table (e.g. "all", "public"). 348 * 349 * @since 1.7.0 350 */ 351 public function get_views() { 352 $url_base = bp_get_admin_url( 'admin.php?page=bp-groups' ); ?> 353 354 <h2 class="screen-reader-text"><?php 355 /* translators: accessibility text */ 356 _e( 'Filter groups list', 'buddypress' ); 357 ?></h2> 358 359 <ul class="subsubsub"> 360 <li class="all"> 361 <a href="<?php echo esc_url( $url_base ); ?>" class="<?php if ( 'all' === $this->view ) echo 'current'; ?>"> 362 <?php printf( 363 /* translators: %s is the placeholder for the count html tag `<span class="count"/>` */ 364 esc_html__( 'All %s', 'buddypress' ), 365 sprintf( 366 '<span class="count">(%s)</span>', 367 number_format_i18n( $this->group_counts['all'] ) 368 ) 369 ); ?> 370 </a> | 371 </li> 372 <li class="public"> 373 <a href="<?php echo esc_url( add_query_arg( 'group_status', 'public', $url_base ) ); ?>" class="<?php if ( 'public' === $this->view ) echo 'current'; ?>"> 374 <?php printf( 375 /* translators: %s is the placeholder for the count html `<span class="count"/>` */ 376 _n( 'Public %s', 'Public %s', $this->group_counts['public'], 'buddypress' ), 377 sprintf( 378 '<span class="count">(%s)</span>', 379 number_format_i18n( $this->group_counts['public'] ) 380 ) 381 ); ?> 382 </a> | 383 </li> 384 <li class="private"> 385 <a href="<?php echo esc_url( add_query_arg( 'group_status', 'private', $url_base ) ); ?>" class="<?php if ( 'private' === $this->view ) echo 'current'; ?>"> 386 <?php printf( 387 /* translators: %s is the placeholder for the count html `<span class="count"/>` */ 388 _n( 'Private %s', 'Private %s', $this->group_counts['private'], 'buddypress' ), 389 sprintf( 390 '<span class="count">(%s)</span>', 391 number_format_i18n( $this->group_counts['private'] ) 392 ) 393 ); ?> 394 </a> | 395 </li> 396 <li class="hidden"> 397 <a href="<?php echo esc_url( add_query_arg( 'group_status', 'hidden', $url_base ) ); ?>" class="<?php if ( 'hidden' === $this->view ) echo 'current'; ?>"> 398 <?php printf( 399 /* translators: %s is the placeholder for the count html tag */ 400 _n( 'Hidden %s', 'Hidden %s', $this->group_counts['hidden'], 'buddypress' ), 401 sprintf( 402 '<span class="count">(%s)</span>', 403 number_format_i18n( $this->group_counts['hidden'] ) 404 ) 405 ); ?> 406 </a> 407 </li> 408 409 <?php 410 411 /** 412 * Fires inside listing of views so plugins can add their own. 413 * 414 * @since 1.7.0 415 * 416 * @param string $url_base Current URL base for view. 417 * @param string $view Current view being displayed. 418 */ 419 do_action( 'bp_groups_list_table_get_views', $url_base, $this->view ); ?> 420 </ul> 421 <?php 422 } 423 424 /** 425 * Get bulk actions for single group row. 426 * 427 * @since 1.7.0 428 * 429 * @return array Key/value pairs for the bulk actions dropdown. 430 */ 431 public function get_bulk_actions() { 432 433 /** 434 * Filters the list of bulk actions to display on a single group row. 435 * 436 * @since 1.7.0 437 * 438 * @param array $value Array of bulk actions to display. 439 */ 440 return apply_filters( 'bp_groups_list_table_get_bulk_actions', array( 441 'delete' => __( 'Delete', 'buddypress' ) 442 ) ); 443 } 444 445 /** 446 * Get the table column titles. 447 * 448 * @since 1.7.0 449 * 450 * @see WP_List_Table::single_row_columns() 451 * 452 * @return array Array of column titles. 453 */ 454 public function get_columns() { 455 456 /** 457 * Filters the titles for the columns for the groups list table. 458 * 459 * @since 2.0.0 460 * 461 * @param array $value Array of slugs and titles for the columns. 462 */ 463 return apply_filters( 'bp_groups_list_table_get_columns', array( 464 'cb' => '<input name type="checkbox" />', 465 'comment' => _x( 'Name', 'Groups admin Group Name column header', 'buddypress' ), 466 'description' => _x( 'Description', 'Groups admin Group Description column header', 'buddypress' ), 467 'status' => _x( 'Status', 'Groups admin Privacy Status column header', 'buddypress' ), 468 'members' => _x( 'Members', 'Groups admin Members column header', 'buddypress' ), 469 'last_active' => _x( 'Last Active', 'Groups admin Last Active column header', 'buddypress' ) 470 ) ); 471 } 472 473 /** 474 * Get the column names for sortable columns. 475 * 476 * Note: It's not documented in WP, but the second item in the 477 * nested arrays below is $desc_first. Normally, we would set 478 * last_active to be desc_first (since you're generally interested in 479 * the *most* recently active group, not the *least*). But because 480 * the default sort for the Groups admin screen is DESC by last_active, 481 * we want the first click on the Last Active column header to switch 482 * the sort order - ie, to make it ASC. Thus last_active is set to 483 * $desc_first = false. 484 * 485 * @since 1.7.0 486 * 487 * @return array Array of sortable column names. 488 */ 489 public function get_sortable_columns() { 490 491 /** 492 * Filters the column names for the sortable columns. 493 * 494 * @since 5.0.0 495 * 496 * @param array $value Array of keys and their values. 497 */ 498 return apply_filters( 'bp_groups_list_table_get_sortable_columns', array( 499 'gid' => array( 'gid', false ), 500 'comment' => array( 'name', false ), 501 'members' => array( 'members', false ), 502 'last_active' => array( 'last_active', false ), 503 ) ); 504 } 505 506 /** 507 * Override WP_List_Table::row_actions(). 508 * 509 * Basically a duplicate of the row_actions() method, but removes the 510 * unnecessary <button> addition. 511 * 512 * @since 2.3.3 513 * @since 2.3.4 Visibility set to public for compatibility with WP < 4.0.0. 514 * 515 * @param array $actions The list of actions. 516 * @param bool $always_visible Whether the actions should be always visible. 517 * @return string 518 */ 519 public function row_actions( $actions, $always_visible = false ) { 520 $action_count = count( $actions ); 521 $i = 0; 522 523 if ( !$action_count ) 524 return ''; 525 526 $out = '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">'; 527 foreach ( $actions as $action => $link ) { 528 ++$i; 529 ( $i == $action_count ) ? $sep = '' : $sep = ' | '; 530 $out .= "<span class='$action'>$link$sep</span>"; 531 } 532 $out .= '</div>'; 533 534 return $out; 535 } 536 537 /** 538 * Markup for the Checkbox column. 539 * 540 * @since 1.7.0 541 * 542 * @see WP_List_Table::single_row_columns() 543 * 544 * @param array $item A singular item (one full row). 545 */ 546 public function column_cb( $item = array() ) { 547 /* translators: accessibility text */ 548 printf( '<label class="screen-reader-text" for="gid-%1$d">' . __( 'Select group %1$d', 'buddypress' ) . '</label><input type="checkbox" name="gid[]" value="%1$d" id="gid-%1$d" />', $item['id'] ); 549 } 550 551 /** 552 * Markup for the Group ID column. 553 * 554 * @since 1.7.0 555 * 556 * @see WP_List_Table::single_row_columns() 557 * 558 * @param array $item A singular item (one full row). 559 */ 560 public function column_gid( $item = array() ) { 561 echo '<strong>' . absint( $item['id'] ) . '</strong>'; 562 } 563 564 /** 565 * Name column, and "quick admin" rollover actions. 566 * 567 * Called "comment" in the CSS so we can re-use some WP core CSS. 568 * 569 * @since 1.7.0 570 * 571 * @see WP_List_Table::single_row_columns() 572 * 573 * @param array $item A singular item (one full row). 574 */ 575 public function column_comment( $item = array() ) { 576 577 // Preorder items: Edit | Delete | View. 578 $actions = array( 579 'edit' => '', 580 'delete' => '', 581 'view' => '', 582 ); 583 584 // We need the group object for some BP functions. 585 $item_obj = (object) $item; 586 587 // Build actions URLs. 588 $base_url = bp_get_admin_url( 'admin.php?page=bp-groups&gid=' . $item['id'] ); 589 $delete_url = wp_nonce_url( $base_url . "&action=delete", 'bp-groups-delete' ); 590 $edit_url = $base_url . '&action=edit'; 591 $view_url = bp_get_group_permalink( $item_obj ); 592 593 /** 594 * Filters the group name for a group's column content. 595 * 596 * @since 1.7.0 597 * 598 * @param string $value Name of the group being rendered. 599 * @param array $item Array for the current group item. 600 */ 601 $group_name = apply_filters_ref_array( 'bp_get_group_name', array( $item['name'], $item ) ); 602 603 // Rollover actions. 604 // Edit. 605 $actions['edit'] = sprintf( '<a href="%s">%s</a>', esc_url( $edit_url ), __( 'Edit', 'buddypress' ) ); 606 607 // Delete. 608 $actions['delete'] = sprintf( '<a href="%s">%s</a>', esc_url( $delete_url ), __( 'Delete', 'buddypress' ) ); 609 610 // Visit. 611 $actions['view'] = sprintf( '<a href="%s">%s</a>', esc_url( $view_url ), __( 'View', 'buddypress' ) ); 612 613 /** 614 * Filters the actions that will be shown for the column content. 615 * 616 * @since 1.7.0 617 * 618 * @param array $value Array of actions to be displayed for the column content. 619 * @param array $item The current group item in the loop. 620 */ 621 $actions = apply_filters( 'bp_groups_admin_comment_row_actions', array_filter( $actions ), $item ); 622 623 // Get group name and avatar. 624 $avatar = ''; 625 626 if ( buddypress()->avatar->show_avatars ) { 627 $avatar = bp_core_fetch_avatar( array( 628 'item_id' => $item['id'], 629 'object' => 'group', 630 'type' => 'thumb', 631 'avatar_dir' => 'group-avatars', 632 'alt' => sprintf( __( 'Group logo of %s', 'buddypress' ), $group_name ), 633 'width' => '32', 634 'height' => '32', 635 'title' => $group_name 636 ) ); 637 } 638 639 $content = sprintf( '<strong><a href="%s">%s</a></strong>', esc_url( $edit_url ), $group_name ); 640 641 echo $avatar . ' ' . $content . ' ' . $this->row_actions( $actions ); 642 } 643 644 /** 645 * Markup for the Description column. 646 * 647 * @since 1.7.0 648 * 649 * @param array $item Information about the current row. 650 */ 651 public function column_description( $item = array() ) { 652 653 /** 654 * Filters the markup for the Description column. 655 * 656 * @since 1.0.0 657 * 658 * @param string $value Markup for the Description column. 659 * @param array $item The current group item in the loop. 660 */ 661 echo apply_filters_ref_array( 'bp_get_group_description', array( $item['description'], $item ) ); 662 } 663 664 /** 665 * Markup for the Status column. 666 * 667 * @since 1.7.0 668 * 669 * @param array $item Information about the current row. 670 */ 671 public function column_status( $item = array() ) { 672 $status = $item['status']; 673 $status_desc = ''; 674 675 // @todo This should be abstracted out somewhere for the whole 676 // Groups component. 677 switch ( $status ) { 678 case 'public' : 679 $status_desc = __( 'Public', 'buddypress' ); 680 break; 681 case 'private' : 682 $status_desc = __( 'Private', 'buddypress' ); 683 break; 684 case 'hidden' : 685 $status_desc = __( 'Hidden', 'buddypress' ); 686 break; 687 } 688 689 /** 690 * Filters the markup for the Status column. 691 * 692 * @since 1.7.0 693 * 694 * @param string $status_desc Markup for the Status column. 695 * @parma array $item The current group item in the loop. 696 */ 697 echo apply_filters_ref_array( 'bp_groups_admin_get_group_status', array( $status_desc, $item ) ); 698 } 699 700 /** 701 * Markup for the Number of Members column. 702 * 703 * @since 1.7.0 704 * @since 10.0.0 Updated to use `groups_get_total_member_count`. 705 * 706 * @param array $item Information about the current row. 707 */ 708 public function column_members( $item = array() ) { 709 $count = groups_get_total_member_count( absint( $item['id'] ) ); 710 711 /** 712 * Filters the markup for the number of Members column. 713 * 714 * @since 1.7.0 715 * 716 * @param int $count Markup for the number of Members column. 717 * @parma array $item The current group item in the loop. 718 */ 719 echo apply_filters_ref_array( 'bp_groups_admin_get_group_member_count', array( (int) $count, $item ) ); 720 } 721 722 /** 723 * Markup for the Last Active column. 724 * 725 * @since 1.7.0 726 * 727 * @param array $item Information about the current row. 728 */ 729 public function column_last_active( $item = array() ) { 730 $last_active = groups_get_groupmeta( $item['id'], 'last_activity' ); 731 732 /** 733 * Filters the markup for the Last Active column. 734 * 735 * @since 1.7.0 736 * 737 * @param string $last_active Markup for the Last Active column. 738 * @parma array $item The current group item in the loop. 739 */ 740 echo apply_filters_ref_array( 'bp_groups_admin_get_group_last_active', array( $last_active, $item ) ); 741 } 742 743 /** 744 * Allow plugins to add their custom column. 745 * 746 * @since 2.0.0 747 * 748 * @param array $item Information about the current row. 749 * @param string $column_name The column name. 750 * @return string 751 */ 752 public function column_default( $item = array(), $column_name = '' ) { 753 754 /** 755 * Filters a string to allow plugins to add custom column content. 756 * 757 * @since 2.0.0 758 * 759 * @param string $value Empty string. 760 * @param string $column_name Name of the column being rendered. 761 * @param array $item The current group item in the loop. 762 */ 763 return apply_filters( 'bp_groups_admin_get_group_custom_column', '', $column_name, $item ); 764 } 765 766 // Group Types 767 768 /** 769 * Add group type column to the WordPress admin groups list table. 770 * 771 * @since 2.7.0 772 * 773 * @param array $columns Groups table columns. 774 * 775 * @return array $columns 776 */ 777 public function add_type_column( $columns = array() ) { 778 $columns['bp_group_type'] = _x( 'Group Type', 'Label for the WP groups table group type column', 'buddypress' ); 779 780 return $columns; 781 } 782 783 /** 784 * Markup for the Group Type column. 785 * 786 * @since 2.7.0 787 * 788 * @param string $retval Empty string. 789 * @param string $column_name Name of the column being rendered. 790 * @param array $item The current group item in the loop. 791 * @return string 792 */ 793 public function column_content_group_type( $retval = '', $column_name = '', $item = array() ) { 794 if ( 'bp_group_type' !== $column_name ) { 795 return $retval; 796 } 797 798 add_filter( 'bp_get_group_type_directory_permalink', array( $this, 'group_type_permalink_use_admin_filter' ), 10, 2 ); 799 $retval = bp_get_group_type_list( $item['id'], array( 800 'parent_element' => '', 801 'label_element' => '', 802 'label' => '', 803 'show_all' => true 804 ) ); 805 remove_filter( 'bp_get_group_type_directory_permalink', array( $this, 'group_type_permalink_use_admin_filter' ), 10 ); 806 807 /** 808 * Filters the markup for the Group Type column. 809 * 810 * @since 2.7.0 811 * 812 * @param string $retval Markup for the Group Type column. 813 * @parma array $item The current group item in the loop. 814 */ 815 echo apply_filters_ref_array( 'bp_groups_admin_get_group_type_column', array( $retval, $item ) ); 816 } 817 818 /** 819 * Filters the group type list permalink in the Group Type column. 820 * 821 * Changes the group type permalink to use the admin URL. 822 * 823 * @since 2.7.0 824 * 825 * @param string $retval Current group type permalink. 826 * @param object $type Group type object. 827 * @return string 828 */ 829 public function group_type_permalink_use_admin_filter( $retval, $type ) { 830 return add_query_arg( array( 'bp-group-type' => urlencode( $type->name ) ) ); 831 } 832 833 /** 834 * Markup for the Group Type bulk change select. 835 * 836 * @since 2.7.0 837 * 838 * @param string $which The location of the extra table nav markup: 'top' or 'bottom'. 839 */ 840 public function add_group_type_bulk_change_select( $which ) { 841 // `$which` is only passed in WordPress 4.6+. Avoid duplicating controls in earlier versions. 842 static $displayed = false; 843 if ( version_compare( bp_get_major_wp_version(), '4.6', '<' ) && $displayed ) { 844 return; 845 } 846 $displayed = true; 847 $id_name = 'bottom' === $which ? 'bp_change_type2' : 'bp_change_type'; 848 849 $types = bp_groups_get_group_types( array(), 'objects' ); 850 ?> 851 <div class="alignleft actions"> 852 <label class="screen-reader-text" for="<?php echo $id_name; ?>"><?php _e( 'Change group type to…', 'buddypress' ) ?></label> 853 <select name="<?php echo $id_name; ?>" id="<?php echo $id_name; ?>" style="display:inline-block;float:none;"> 854 <option value=""><?php _e( 'Change group type to…', 'buddypress' ) ?></option> 855 856 <?php foreach( $types as $type ) : ?> 857 858 <option value="<?php echo esc_attr( $type->name ); ?>"><?php echo esc_html( $type->labels['singular_name'] ); ?></option> 859 860 <?php endforeach; ?> 861 862 <option value="remove_group_type"><?php _e( 'No Group Type', 'buddypress' ) ?></option> 863 864 </select> 865 <?php 866 wp_nonce_field( 'bp-bulk-groups-change-type-' . bp_loggedin_user_id(), 'bp-bulk-groups-change-type-nonce' ); 867 submit_button( __( 'Change', 'buddypress' ), 'button', 'bp_change_group_type', false ); 868 ?> 869 </div> 870 <?php 871 } 872 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Nov 21 01:00:57 2024 | Cross-referenced by PHPXref 0.7.1 |