Ticket #5367: 5367.03.diff
File 5367.03.diff, 19.1 KB (added by , 11 years ago) |
---|
-
bp-members/admin/bp-members-classes.php
323 323 } 324 324 } 325 325 326 /** 327 * List table class for members admin page. 328 * 329 * @since BuddyPress (2.0.0) 330 */ 331 class BP_Members_Subsite_List_Table extends WP_Users_List_Table { 332 333 /** 334 * Member counts. 335 * 336 * @since BuddyPress (2.0.0) 337 * 338 * @access public 339 * @var int 340 */ 341 public $static_members_counts = 0; 342 public $members_counts = 0; 343 344 /** 345 * Excluded users. 346 * 347 * @since BuddyPress (2.0.0) 348 * 349 * @access public 350 * @var array 351 */ 352 public $exclude = array(); 353 354 /** 355 * Constructor. 356 * 357 * @since BuddyPress (2.0.0) 358 */ 359 public function __construct( $args = array() ) { 360 // Define singular and plural labels, as well as whether we support AJAX. 361 parent::__construct( array( 362 'ajax' => false, 363 'plural' => 'members', 364 'singular' => 'member', 365 ) ); 366 367 if ( ! empty( $args['members_count'] ) ) { 368 $this->static_members_counts = absint( $args['members_count'] ); 369 } 370 371 if ( ! empty( $args['exclude'] ) ) 372 $this->exclude = array_map( 'absint', (array) $args['exclude'] ); 373 } 374 375 /** 376 * Set up items for display in the list table. 377 * 378 * Handles filtering of data, sorting, pagination, and any other data 379 * manipulation required prior to rendering. 380 * 381 * @since BuddyPress (2.0.0) 382 */ 383 public function prepare_items() { 384 global $usersearch; 385 386 $usersearch = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : ''; 387 388 $members_per_page = $this->get_items_per_page( str_replace( '-', '_', "{$this->screen->id}_per_page" ) ); 389 390 $paged = $this->get_pagenum(); 391 392 $args = array( 393 'type' => 'alphabetical', 394 'per_page' => $members_per_page, 395 'page' => $paged, 396 'search_terms' => $usersearch, 397 'exclude' => $this->exclude, 398 ); 399 400 // In front end spammers are removed from query, we need them in back end. 401 add_action( 'bp_pre_user_query', array( $this, 'include_spammers' ), 10, 1 ); 402 $members = bp_core_get_users( $args ); 403 remove_action( 'bp_pre_user_query', array( $this, 'include_spammers' ), 10, 1 ); 404 405 $this->items = $members['users']; 406 $this->members_count = $members['total']; 407 408 $this->set_pagination_args( array( 409 'total_items' => $this->members_count, 410 'per_page' => $members_per_page, 411 ) ); 412 } 413 414 /** 415 * Force the spammers to show up in results 416 * 417 * We need spammers here in order to let the admin manage them. 418 * Moreover it's an action in wp-admin/community profile.. 419 * else the user won't show in the subsite in case he was marked as spammer 420 * 421 * @since BuddyPress (2.0.0) 422 * 423 * @param BP_User_Query $bp_user_query 424 */ 425 public function include_spammers( $bp_user_query = null ) { 426 $bp_user_query->uid_clauses["where"] = preg_replace( '/WHERE (.*) user_status = 0 \) AND/', 'WHERE', $bp_user_query->uid_clauses["where"] ); 427 } 428 429 /** 430 * Get the views (the links above the WP List Table). 431 * 432 * @since BuddyPress (2.0.0) 433 * 434 * @uses WP_Users_List_Table::get_views() to get the users views 435 */ 436 public function get_views() { 437 $views = parent::get_views(); 438 439 // Remove the 'current' class from the 'All' link 440 $views['all'] = str_replace( 'class="current"', '', $views['all'] ); 441 $views['members'] = '<a href="' . add_query_arg( 'page', 'bp-members', bp_get_admin_url( 'users.php' ) ) . '" class="current">' . sprintf( _x( 'Member <span class="count">(%s)</span>', 'member users', 'buddypress' ), number_format_i18n( $this->static_members_counts ) ) . '</a>'; 442 443 return $views; 444 } 445 446 /** 447 * Get rid of the extra nav. 448 * 449 * WP_Users_List_Table will add an extra nav to change user's role. 450 * As we're dealing with members that are not blog users, we don't need this. 451 * 452 * @since BuddyPress (2.0.0) 453 */ 454 public function extra_tablenav( $which ) { 455 return; 456 } 457 458 /** 459 * Specific members columns 460 * 461 * @since BuddyPress (2.0.0) 462 */ 463 public function get_columns() { 464 return apply_filters( 'bp_members_member_columns', array( 465 'cb' => '<input type="checkbox" />', 466 'username' => __( 'Username', 'buddypress' ), 467 'name' => __( 'Name', 'buddypress' ), 468 'email' => __( 'E-mail', 'buddypress' ), 469 'last_active' => __( 'Last Active', 'buddypress' ) 470 ) ); 471 } 472 473 /** 474 * No bulk actions for members. 475 * 476 * @since BuddyPress (2.0.0) 477 */ 478 public function get_bulk_actions() { 479 return array(); 480 } 481 482 /** 483 * The text shown when no items are found. 484 * 485 * @since BuddyPress (2.0.0) 486 */ 487 public function no_items() { 488 _e( 'No members found.', 'buddypress' ); 489 } 490 491 /** 492 * Changing the order is not available. 493 * 494 * @since BuddyPress (2.0.0) 495 */ 496 public function get_sortable_columns() { 497 return array(); 498 } 499 500 /** 501 * Display members rows. 502 * 503 * @since BuddyPress (2.0.0) 504 */ 505 public function display_rows() { 506 $style = ''; 507 foreach ( $this->items as $userid => $member_object ) { 508 $style = ( ' class="alternate"' == $style ) ? '' : ' class="alternate"'; 509 echo "\n\t" . $this->single_row( $member_object, $style ); 510 } 511 } 512 513 /** 514 * Display a member row. 515 * 516 * @since BuddyPress (2.0.0) 517 * 518 * @see WP_List_Table::single_row() for explanation of params. 519 */ 520 public function single_row( $member_object = null, $style = '', $role = '', $numposts = 0 ) { 521 echo '<tr' . $style . ' id="member-' . esc_attr( $member_object->id ) . '">'; 522 echo $this->single_row_columns( $member_object ); 523 echo '</tr>'; 524 } 525 526 /** 527 * As no bulk actions, no checkbox. 528 * 529 * @since BuddyPress (2.0.0) 530 */ 531 public function column_cb( $member_object = null ) {} 532 533 /** 534 * The row actions (edit/profile/delete). 535 * 536 * @since BuddyPress (2.0.0) 537 * 538 * @param object $member_object The member data object. 539 */ 540 public function column_username( $member_object = null ) { 541 $avatar = get_avatar( $member_object->user_email, 32 ); 542 $referer = false; 543 $actions = array(); 544 545 if ( ! empty( $_REQUEST['wp_http_referer'] ) ) { 546 $referer = urlencode( stripslashes_deep( $_REQUEST['wp_http_referer'] ) ); 547 } else { 548 $referer = urlencode( stripslashes_deep( $_SERVER['REQUEST_URI'] ) ); 549 } 550 551 // Edit link & Delete link are restricted to network admins. 552 if ( current_user_can( 'manage_network_users' ) ) { 553 554 $edit_query_arg = array( 555 'user_id' => $member_object->id, 556 'wp_http_referer' => $referer 557 ); 558 559 $edit_link = add_query_arg( $edit_query_arg, network_admin_url( 'user-edit.php' ) ); 560 561 // if current user wants to edit his profile 562 if ( get_current_user_id() == $member_object->id ) { 563 $edit_link = network_admin_url( 'profile.php' ); 564 } 565 566 $actions['edit'] = '<a href="' . esc_url( $edit_link ) . '">' . esc_html__( 'Edit', 'buddypress' ) . '</a>'; 567 568 if ( ! in_array( $member_object->user_login, get_super_admins() ) ) { 569 $delete_query_arg = array( 570 'action' => 'deleteuser', 571 'id' => $member_object->id, 572 'wp_http_referer' => $referer 573 ); 574 575 $delete_link = wp_nonce_url( add_query_arg( $delete_query_arg , network_admin_url( 'users.php' ) ), 'deleteuser' ); 576 } 577 } 578 579 $profile_query_arg = array( 580 'page' => 'bp-profile-edit', 581 'user_id' => $member_object->id, 582 'wp_http_referer' => $referer 583 ); 584 585 // Profile link 586 $profile_link = add_query_arg( $profile_query_arg, bp_get_admin_url( 'users.php' ) ); 587 588 $actions['edit-profile'] = '<a href="' . esc_url( $profile_link ) . '">' . esc_html__( 'Profile', 'buddypress' ) . '</a>'; 589 590 echo $avatar . '<strong>' . $member_object->user_login .'</strong><br/>'; 591 592 if ( current_user_can( 'manage_network_users' ) ) { 593 $actions['delete'] = '<a href="' . esc_url( $delete_link ) . '" class="delete">' . esc_html__( 'Delete', 'buddypress' ) . '</a>'; 594 } 595 596 $actions = apply_filters( 'bp_members_member_subsite_row_actions', $actions, $member_object ); 597 echo $this->row_actions( $actions ); 598 } 599 600 /** 601 * Display user name, if any. 602 * 603 * @since BuddyPress (2.0.0) 604 * 605 * @param object $member_object The member data object. 606 */ 607 public function column_name( $member_object = null ) { 608 echo esc_html( $member_object->user_nicename ); 609 } 610 611 /** 612 * Display user email. 613 * 614 * @since BuddyPress (2.0.0) 615 * 616 * @param object $member_object The member data object. 617 */ 618 public function column_email( $member_object = null ) { 619 echo '<a href="mailto:' . esc_attr( $member_object->user_email ) . '">' . esc_html( $member_object->user_email ) .'</a>'; 620 } 621 622 /** 623 * Display last activity date. 624 * 625 * @since BuddyPress (2.0.0) 626 * 627 * @param object $member_object The member data object. 628 */ 629 public function column_last_active( $member_object = null ) { 630 echo mysql2date( 'Y/m/d', $member_object->last_activity ); 631 } 632 } 633 634 326 635 endif; 327 636 328 637 if ( class_exists( 'WP_MS_Users_List_Table' ) ) : -
bp-members/bp-members-admin.php
127 127 $this->users_screen = bp_core_do_network_admin() ? 'users-network' : 'users'; 128 128 129 129 // Specific config: BuddyPress is not network activated 130 $this->members_page = ''; 130 131 $this->subsite_activated = (bool) is_multisite() && ! bp_is_network_activated(); 131 132 132 133 // When BuddyPress is not network activated, only Super Admin can moderate signups … … 170 171 if ( current_user_can( $this->capability ) ) { 171 172 // Reorganise the views navigation in users.php and signups page 172 173 add_filter( "views_{$this->users_screen}", array( $this, 'signup_filter_view' ), 10, 1 ); 173 add_filter( 'set-screen-option', array( $this, 'signup_screen_options' ), 10, 3 ); 174 add_filter( "views_users_page_bp-members", array( $this, 'signup_filter_view' ), 10, 1 ); 175 add_filter( 'set-screen-option', array( $this, 'screen_options' ), 10, 3 ); 174 176 } 175 177 } 178 179 /** Specific config BuddyPress is not network activated **********************/ 180 181 if ( ! empty( $this->subsite_activated ) ) { 182 // Reorganise the views navigation in users.php and do it before signups view 183 add_filter( "views_{$this->users_screen}", array( $this, 'member_filter_view' ), 9, 1 ); 184 add_filter( "views_users_page_bp-signups", array( $this, 'member_filter_view' ), 10, 1 ); 185 add_filter( 'set-screen-option', array( $this, 'screen_options' ), 10, 3 ); 186 } 176 187 } 177 188 178 189 /** … … 205 216 ); 206 217 } 207 218 219 // Add a Members view in users Administration for specific config 220 // where BuddyPress is not network activated 221 if ( ! empty( $this->subsite_activated ) ) { 222 $hooks['members'] = $this->members_page = add_users_page( 223 __( 'Members', 'buddypress' ), 224 __( 'Members', 'buddypress' ), 225 'bp_moderate', 226 'bp-members', 227 array( &$this, 'members_admin' ) 228 ); 229 } 230 208 231 $edit_page = 'user-edit'; 209 232 $this->users_page = 'users'; 210 233 … … 219 242 220 243 foreach ( $hooks as $key => $hook ) { 221 244 add_action( "load-$hook", array( $this, $key . '_admin_load' ) ); 245 246 // We're showing the Admin menu for signups 247 if ( 'signups' == $key ) 248 continue; 249 250 add_action( "admin_head-$hook", array( $this, 'modify_admin_menu_highlight' ) ); 222 251 } 223 252 224 add_action( "admin_head-$this->user_page", array( $this, 'modify_admin_menu_highlight' ) );225 226 253 } 227 254 228 255 /** 229 * Highlight the Users menu if on Edit Profile .256 * Highlight the Users menu if on Edit Profile or on Members view (specific config). 230 257 * 231 258 * @access public 232 259 * @since BuddyPress (2.0.0) … … 235 262 global $plugin_page, $submenu_file; 236 263 237 264 // Only Show the All users menu 238 if ( $plugin_page = 'bp-profile-edit') {265 if ( in_array( $plugin_page, array( 'bp-profile-edit', 'bp-members' ) ) ) { 239 266 $submenu_file = 'users.php'; 240 267 } 241 268 } … … 253 280 public function admin_head() { 254 281 // Remove submenu to force using Profile Navigation 255 282 remove_submenu_page( 'users.php', 'bp-profile-edit' ); 283 284 // Remove submenu for the specific config 285 if ( ! empty( $this->subsite_activated ) ) 286 remove_submenu_page( 'users.php', 'bp-members' ); 256 287 } 257 288 258 289 /** Community Profile ************************************************/ … … 309 340 $query_args['wp_http_referer'] = urlencode( stripslashes_deep( $_REQUEST['wp_http_referer'] ) ); 310 341 } 311 342 343 $wordpress_url = $this->edit_url; 312 344 $community_url = add_query_arg( $query_args, $this->edit_profile_url ); 313 345 $wordpress_url = add_query_arg( $query_args, $this->edit_url ); 314 346 347 if ( $this->subsite_activated && ! is_user_member_of_blog( $user->ID, bp_get_root_blog_id() ) ) { 348 $wordpress_url = network_admin_url( 'user-edit.php' ); 349 350 if( get_current_user_id() == $user->ID ) { 351 $wordpress_url = network_admin_url( 'profile.php' ); 352 $query_args = array(); 353 } 354 } 355 356 $wordpress_url = add_query_arg( $query_args, $wordpress_url ); 357 315 358 $bp_active = false; 316 359 $wp_active = ' nav-tab-active'; 317 360 if ( 'BuddyPress' === $active ) { … … 794 837 * @param int $new_value 795 838 * @return int the pagination preferences 796 839 */ 797 public function s ignup_screen_options( $value = 0, $option = '', $new_value = 0 ) {798 if ( 'users_page_bp_signups_network_per_page' != $option && 'users_page_bp_signups_per_page' != $option ) {840 public function screen_options( $value = 0, $option = '', $new_value = 0 ) { 841 if ( 'users_page_bp_signups_network_per_page' != $option && 'users_page_bp_signups_per_page' != $option && 'users_page_bp_members_per_page' != $option ) { 799 842 return $value; 800 843 } 801 844 … … 850 893 * @return array The views with the signup view added. 851 894 */ 852 895 public function signup_filter_view( $views = array() ) { 896 897 if ( ! current_user_can( $this->capability ) ) 898 return $views; 899 853 900 $class = ''; 854 901 855 902 $signups = BP_Signup::count_signups(); … … 873 920 * 874 921 * @param string $class The name of the class to use. 875 922 * @param string $required The parent class. 923 * @param array $args extra args to pass to the List Table 876 924 * @return WP_List_Table The List table. 877 925 */ 878 public static function get_list_table_class( $class = '', $required = '' ) {926 public static function get_list_table_class( $class = '', $required = '', $args = array() ) { 879 927 if ( empty( $class ) ) { 880 928 return; 881 929 } … … 885 933 require_once( buddypress()->members->admin->admin_dir . 'bp-members-classes.php' ); 886 934 } 887 935 888 return new $class( );936 return new $class( $args ); 889 937 } 890 938 891 939 /** … … 1435 1483 1436 1484 <?php 1437 1485 } 1486 1487 /** 1488 * Get the count and exclude args 1489 * 1490 * 'All' shows blog users with a capability 1491 * 'Member' shows users with no capability on the blog 1492 * 1493 * @since BuddyPress (2.0.0) 1494 */ 1495 public function member_list_table_args() { 1496 global $wpdb; 1497 1498 /** 1499 * we need to get the ids to exclude in members WP_List_Table 1500 */ 1501 $blog_prefix = $wpdb->get_blog_prefix( bp_get_root_blog_id() ); 1502 $this->blog_users = $wpdb->get_col( 1503 "SELECT u.ID FROM {$wpdb->users} u LEFT JOIN {$wpdb->usermeta} m 1504 ON ( u.ID = m.user_id ) 1505 WHERE m.meta_key = '{$blog_prefix}capabilities'" 1506 ); 1507 1508 // That's annoying but as bp_core_get_total_member_count() or get_user_count() don't include spammer... 1509 $users_count = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->users}"); 1510 1511 // Members count 1512 $this->members_count = $users_count - count( $this->blog_users ); 1513 1514 return array( 'members_count' => $this->members_count, 'exclude' => $this->blog_users ); 1515 } 1516 1517 /** 1518 * Add the member view to views 1519 * 1520 * @since BuddyPress (2.0.0) 1521 */ 1522 public function member_filter_view( $views = array() ) { 1523 $class = ''; 1524 1525 $member_args = array(); 1526 1527 if ( empty( $this->members_count ) ) { 1528 $member_args = $this->member_list_table_args(); 1529 } else { 1530 $member_args['members_count'] = $this->members_count; 1531 } 1532 1533 // Remove the 'current' class from All if we're on the members view 1534 // view 1535 if ( $this->members_page == get_current_screen()->id ) { 1536 $views['all'] = str_replace( 'class="current"', '', $views['all'] ); 1537 $class = ' class="current"'; 1538 } 1539 1540 $views['members'] = '<a href="' . add_query_arg( 'page', 'bp-members', bp_get_admin_url( 'users.php' ) ) . '"' . $class . '>' . sprintf( _x( 'Member <span class="count">(%s)</span>', 'member users', 'buddypress' ), number_format_i18n( $member_args['members_count'] ) ) . '</a>'; 1541 1542 // reorder if on bp signups page 1543 if ( $this->signups_page == get_current_screen()->id ) { 1544 $signups_view = $views['registered']; 1545 unset( $views['registered'] ); 1546 $views['registered'] = $signups_view; 1547 } 1548 1549 return $views; 1550 } 1551 1552 /** 1553 * Load the WP Liste Table 1554 * 1555 * @since BuddyPress (2.0.0) 1556 */ 1557 public function members_admin_load() { 1558 global $bp_members_member_list_table; 1559 1560 if ( ! empty( $this->members_count ) && ! empty( $this->blog_users ) ) { 1561 $member_args = array( 'members_count' => $this->members_count, 'exclude' => $this->blog_users ); 1562 } else { 1563 $member_args = $this->member_list_table_args(); 1564 } 1565 1566 $bp_members_member_list_table = self::get_list_table_class( 'BP_Members_Subsite_List_Table', 'users', $member_args ); 1567 1568 // per_page screen option 1569 add_screen_option( 'per_page', array( 'label' => _x( 'Members', 'Members Subsite per page (screen options)', 'buddypress' ) ) ); 1570 } 1571 1572 /** 1573 * Display the members admin page 1574 * 1575 * @since BuddyPress (2.0.0) 1576 */ 1577 public function members_admin() { 1578 global $plugin_page, $bp_members_member_list_table; 1579 1580 $usersearch = ! empty( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : ''; 1581 1582 // Prepare the group items for display 1583 $bp_members_member_list_table->prepare_items(); 1584 1585 $form_url = add_query_arg( 1586 array( 1587 'page' => 'bp-members', 1588 ), 1589 bp_get_admin_url( 'users.php' ) 1590 ); 1591 1592 $search_form_url = $_SERVER['REQUEST_URI']; 1593 ?> 1594 1595 <div class="wrap"> 1596 <?php screen_icon( 'users' ); ?> 1597 <h2> 1598 <?php 1599 _e( 'Users', 'buddypress' ); 1600 if ( current_user_can( 'create_users' ) ) { ?> 1601 <a href="user-new.php" class="add-new-h2"><?php echo esc_html_x( 'Add New', 'user' ); ?></a> 1602 <?php } elseif ( is_multisite() && current_user_can( 'promote_users' ) ) { ?> 1603 <a href="user-new.php" class="add-new-h2"><?php echo esc_html_x( 'Add Existing', 'user' ); ?></a> 1604 <?php } 1605 1606 if ( $usersearch ) { 1607 printf( '<span class="subtitle">' . __('Search results for “%s”') . '</span>', esc_html( $usersearch ) ); 1608 } 1609 1610 ?> 1611 </h2> 1612 1613 <?php // Display each signups on its own row ?> 1614 <?php $bp_members_member_list_table->views(); ?> 1615 1616 <form id="bp-members-search-form" action="<?php echo esc_url( $search_form_url ) ;?>"> 1617 <input type="hidden" name="page" value="<?php echo esc_attr( $plugin_page ); ?>" /> 1618 <?php $bp_members_member_list_table->search_box( __( 'Search Members', 'buddypress' ), 'bp-members' ); ?> 1619 </form> 1620 1621 <form id="bp-members-form" action="<?php echo esc_url( $form_url );?>" method="post"> 1622 <?php $bp_members_member_list_table->display(); ?> 1623 </form> 1624 </div> 1625 <?php 1626 } 1438 1627 } 1439 1628 endif; // class_exists check 1440 1629