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

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