| 680 | | return array_merge( $new_edit_actions, $actions ); |
| | 697 | $actions = array_merge( $new_edit_actions, $actions ); |
| | 698 | |
| | 699 | // Specific to handle the case when BuddyPress is not networked activated |
| | 700 | if ( ! empty( $user->is_bp_member ) && current_user_can( 'manage_network_users') ) { |
| | 701 | // No need to remove this user from blog, he's not attached to this blog |
| | 702 | unset( $actions['remove'] ); |
| | 703 | |
| | 704 | $referer_args = array( |
| | 705 | 'wp_http_referer' => urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ) |
| | 706 | ); |
| | 707 | $edit_args = array_merge( array( 'user_id' => $user->ID ), $referer_args ); |
| | 708 | |
| | 709 | $edit_link = add_query_arg( $edit_args, network_admin_url( 'user-edit.php' ) ); |
| | 710 | |
| | 711 | /** |
| | 712 | * This might not be needed.. |
| | 713 | * @see https://buddypress.trac.wordpress.org/ticket/5365 |
| | 714 | */ |
| | 715 | if ( get_current_user_id() == $user->ID ) { |
| | 716 | $edit_link = network_admin_url( 'profile.php' ); |
| | 717 | } |
| | 718 | |
| | 719 | $actions['edit'] = '<a href="' . esc_url( $edit_link ) . '">' . esc_html__( 'Edit', 'buddypress' ) . '</a>'; |
| | 720 | |
| | 721 | if ( current_user_can( 'delete_user', $user->ID ) && ! in_array( $user->user_login, get_super_admins() ) ) { |
| | 722 | $delete_args = array_merge( array( 'action' => 'deleteuser', 'id' => $user->ID ), $referer_args ); |
| | 723 | $actions['delete'] = '<a href="' . $delete = esc_url( wp_nonce_url( add_query_arg( $delete_args , network_admin_url( 'users.php' ) ), 'deleteuser' ) ) . '" class="delete">' . __( 'Delete', 'buddypress' ) . '</a>'; |
| | 724 | } |
| | 725 | } |
| | 726 | |
| | 727 | return $actions; |
| | 729 | |
| | 730 | /** Specific config : BuddyPress is not activated on the network **/ |
| | 731 | |
| | 732 | /** |
| | 733 | * Globalize the Users list table of the BuddyPress root blog |
| | 734 | * |
| | 735 | * @access public |
| | 736 | * @since BuddyPress (2.0.0) |
| | 737 | * |
| | 738 | * @global $wp_list_table Users List Table class. |
| | 739 | */ |
| | 740 | public function list_table_globalize() { |
| | 741 | /** |
| | 742 | * globalizing the list table will allow us |
| | 743 | * to manipulate datas once the query has been run |
| | 744 | */ |
| | 745 | global $wp_list_table; |
| | 746 | } |
| | 747 | |
| | 748 | /** |
| | 749 | * Edit the query in order to get all BuddyPress members |
| | 750 | * |
| | 751 | * @access public |
| | 752 | * @since BuddyPress (2.0.0) |
| | 753 | * |
| | 754 | * @global $wpdb db class. |
| | 755 | * @param WP_User_Query $query WordPress User Query class. |
| | 756 | */ |
| | 757 | public function list_table_append_members( $query = null ) { |
| | 758 | global $wpdb; |
| | 759 | $blog_prefix = $wpdb->get_blog_prefix( bp_get_root_blog_id() ); |
| | 760 | |
| | 761 | // Query parts organized in WP Meta Query arguments |
| | 762 | $meta_query_relation = array( 'relation' => 'AND' ); |
| | 763 | |
| | 764 | /** |
| | 765 | * Specific to BuddyPress |
| | 766 | * This will need to be refreshed to avoid the use of last_activity |
| | 767 | * @see https://buddypress.trac.wordpress.org/ticket/5128 |
| | 768 | */ |
| | 769 | $meta_query_bp = array( |
| | 770 | array( |
| | 771 | 'key' => 'last_activity', |
| | 772 | 'compare' => 'EXISTS' |
| | 773 | ), |
| | 774 | array( |
| | 775 | 'key' => $blog_prefix . 'user_level', |
| | 776 | 'compare' => 'NOT EXISTS' |
| | 777 | ) |
| | 778 | ); |
| | 779 | |
| | 780 | // All users view |
| | 781 | if ( empty( $query->query_vars['role'] ) ) { |
| | 782 | |
| | 783 | // Easiest to rebuild the role query than to edit it |
| | 784 | $meta_query_args = array( |
| | 785 | array( |
| | 786 | 'key' => $blog_prefix . 'capabilities', |
| | 787 | 'compare' => 'EXISTS' |
| | 788 | ), |
| | 789 | ); |
| | 790 | |
| | 791 | //merging meta query parts |
| | 792 | $meta_query_args = array_merge( $meta_query_relation, $meta_query_args, $meta_query_bp ); |
| | 793 | |
| | 794 | $meta_query = new WP_Meta_Query( $meta_query_args ); |
| | 795 | $mq_sql = $meta_query->get_sql( 'user', $wpdb->users, 'ID' ); |
| | 796 | |
| | 797 | // Rewriting the query parts to match our need |
| | 798 | preg_match_all( '/AND(.*)[^\(]/', $mq_sql['where'], $matches ); |
| | 799 | |
| | 800 | if ( ! empty( $matches[1][1] ) && ! empty( $matches[1][2] ) ) { |
| | 801 | $mq_sql['where'] = str_replace( $matches[0][1], ' OR ( '. $matches[1][1], $mq_sql['where'] ); |
| | 802 | $mq_sql['where'] = str_replace( $matches[0][2], ' AND '. $matches[1][2] .' ) )', $mq_sql['where'] ); |
| | 803 | |
| | 804 | // At this point we will get all members that are active in the community |
| | 805 | $query->query_fields = "DISTINCT ". $query->query_fields; |
| | 806 | $query->query_from = "FROM {$wpdb->users}" . $mq_sql['join']; |
| | 807 | // Ban/Unban is managed in the Network Admin |
| | 808 | $query->query_where = "WHERE {$wpdb->users}.user_status = 0" . $mq_sql['where']; |
| | 809 | } |
| | 810 | |
| | 811 | // Members view : listing BuddyPress members (not users of the blog) |
| | 812 | } else if ( 'members' == $query->query_vars['role'] ) { |
| | 813 | |
| | 814 | //merging specific meta query parts |
| | 815 | $meta_query_args = array_merge( $meta_query_relation, $meta_query_bp ); |
| | 816 | |
| | 817 | $meta_query = new WP_Meta_Query( $meta_query_args ); |
| | 818 | $mq_sql = $meta_query->get_sql( 'user', $wpdb->users, 'ID' ); |
| | 819 | |
| | 820 | $query->query_from = "FROM {$wpdb->users}" . $mq_sql['join']; |
| | 821 | // Ban/Unban is managed in the Network Admin |
| | 822 | $query->query_where = "WHERE {$wpdb->users}.user_status = 0" . $mq_sql['where']; |
| | 823 | } |
| | 824 | } |
| | 825 | |
| | 826 | /** |
| | 827 | * Count the BuddyPress members once only |
| | 828 | * |
| | 829 | * @access public |
| | 830 | * @since BuddyPress (2.0.0) |
| | 831 | * |
| | 832 | * @global $wpdb db class. |
| | 833 | */ |
| | 834 | public function list_table_set_members_count() { |
| | 835 | global $wpdb; |
| | 836 | |
| | 837 | $this->all_members = (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->usermeta} WHERE meta_key='last_activity'" ); |
| | 838 | } |
| | 839 | |
| | 840 | /** |
| | 841 | * Count the BuddyPress members once only |
| | 842 | * |
| | 843 | * @access public |
| | 844 | * @since BuddyPress (2.0.0) |
| | 845 | * |
| | 846 | * @global $wp_list_table Users List Table class. |
| | 847 | * @param array $views the views to edit |
| | 848 | * @return array $views the edited views |
| | 849 | */ |
| | 850 | public function list_table_filter_views( $views = array() ) { |
| | 851 | global $wp_list_table; |
| | 852 | |
| | 853 | // Making sure members will show as they might have no role |
| | 854 | // on this blog |
| | 855 | foreach ( $wp_list_table->items as $key => $user_data ) { |
| | 856 | if ( empty( $user_data->allcaps ) ) { |
| | 857 | $user_data->allcaps = array( 'read' => true ); |
| | 858 | $user_data->is_bp_member = true; |
| | 859 | $wp_list_table->items[ $key ] = $user_data; |
| | 860 | } |
| | 861 | } |
| | 862 | |
| | 863 | // Set the Members view link to current view |
| | 864 | $class = false; |
| | 865 | if ( !empty( $_GET['role'] ) && 'members' == $_GET['role'] ) { |
| | 866 | $class = ' class="current"'; |
| | 867 | } |
| | 868 | |
| | 869 | // We need the $all_count to adjust the BuddyPress members count |
| | 870 | $pattern = '/\<span class=\"count\"\>\((.?)\)\<\/span\>/'; |
| | 871 | preg_match( $pattern, $views['all'], $all_count ); |
| | 872 | |
| | 873 | if ( ! empty( $all_count[1] ) ) { |
| | 874 | $views['all'] = preg_replace( '/\<span class=\"count\"\>\((.?)\)\<\/span\>/', '('. $this->all_members .')', $views['all'] ); |
| | 875 | $members = $this->all_members - absint( $all_count[1] ); |
| | 876 | $views['members'] = '<a href="' . add_query_arg( 'role', 'members', bp_get_admin_url( 'users.php' ) ) . '"' . $class . '>' . sprintf( _nx( 'Member <span class="count">(%s)</span>', 'Members <span class="count">(%s)</span>', $members, 'buddypress members', 'buddypress' ), number_format_i18n( $members ) ) . '</a>'; |
| | 877 | } |
| | 878 | |
| | 879 | return $views; |
| | 880 | } |
| | 881 | |
| | 882 | /** |
| | 883 | * Reset the bulk actions to avoid the remove from blog action |
| | 884 | * |
| | 885 | * @access public |
| | 886 | * @since BuddyPress (2.0.0) |
| | 887 | * |
| | 888 | * @param array $bulk_actions the actions to edit |
| | 889 | * @return array $bulk_actions the edited actions |
| | 890 | */ |
| | 891 | public function list_table_bulk_actions( $bulk_actions = array() ) { |
| | 892 | if( ( empty( $_GET['role'] ) || ( ! empty( $_GET['role'] ) && 'members' == $_GET['role'] ) ) && 'users' == get_current_screen()->id ) |
| | 893 | $bulk_actions = array(); |
| | 894 | |
| | 895 | return $bulk_actions; |
| | 896 | } |