[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-groups/classes/ -> class-bp-groups-list-table.php (source)

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


Generated: Sat Dec 14 01:01:40 2019 Cross-referenced by PHPXref 0.7.1