| 726 | |
| 727 | /** Specific config : BuddyPress is not activated on the network **/ |
| 728 | |
| 729 | /** |
| 730 | * Is this the members screen ? |
| 731 | * |
| 732 | * @access public |
| 733 | * @since BuddyPress (2.0.0) |
| 734 | */ |
| 735 | public function is_specific_members_screen() { |
| 736 | $retval = false; |
| 737 | |
| 738 | if ( ! empty( $_GET['role'] ) && 'members' == $_GET['role'] && 'users' == get_current_screen()->id ) { |
| 739 | $retval = true; |
| 740 | } |
| 741 | |
| 742 | return $retval; |
| 743 | } |
| 744 | |
| 745 | /** |
| 746 | * Globalize the Users list table of the BuddyPress root blog |
| 747 | * |
| 748 | * @access public |
| 749 | * @since BuddyPress (2.0.0) |
| 750 | * |
| 751 | * @global $wp_list_table Users List Table class. |
| 752 | */ |
| 753 | public function members_load_screen() { |
| 754 | // Bail If not on the specific members view |
| 755 | if ( ! $this->is_specific_members_screen() ) |
| 756 | return; |
| 757 | /** |
| 758 | * globalizing the list table will allow us |
| 759 | * to manipulate datas once the query has been run |
| 760 | */ |
| 761 | global $wp_list_table; |
| 762 | |
| 763 | // Manage help tabs for this screen |
| 764 | add_filter( 'contextual_help', array( $this, 'members_help_tabs' ), 10, 3 ); |
| 765 | // Filter the edit user link |
| 766 | add_filter( 'get_edit_user_link', array( $this, 'members_edit_link' ), 10, 2 ); |
| 767 | } |
| 768 | |
| 769 | /** |
| 770 | * Edit the query in order to get all BuddyPress members |
| 771 | * |
| 772 | * @access public |
| 773 | * @since BuddyPress (2.0.0) |
| 774 | * |
| 775 | * @global $wpdb db class. |
| 776 | * @param WP_User_Query $query WordPress User Query class. |
| 777 | */ |
| 778 | public function members_query( $query = null ) { |
| 779 | global $wpdb; |
| 780 | |
| 781 | // Bail If not on the specific members view |
| 782 | if ( ! $this->is_specific_members_screen() ) |
| 783 | return; |
| 784 | |
| 785 | /** |
| 786 | * This will need to be refreshed to avoid the use of last_activity |
| 787 | * @see https://buddypress.trac.wordpress.org/ticket/5128 |
| 788 | */ |
| 789 | $meta_query_bp = array( |
| 790 | array( |
| 791 | 'key' => 'last_activity', |
| 792 | 'compare' => 'EXISTS' |
| 793 | ) |
| 794 | ); |
| 795 | |
| 796 | $meta_query = new WP_Meta_Query( $meta_query_bp ); |
| 797 | $mq_sql = $meta_query->get_sql( 'user', $wpdb->users, 'ID' ); |
| 798 | |
| 799 | $query->query_from = "FROM {$wpdb->users}" . $mq_sql['join']; |
| 800 | $query->query_where = "WHERE {$wpdb->users}.user_status = 0" . $mq_sql['where']; |
| 801 | } |
| 802 | |
| 803 | /** |
| 804 | * Count the BuddyPress members once only |
| 805 | * |
| 806 | * @access public |
| 807 | * @since BuddyPress (2.0.0) |
| 808 | * |
| 809 | * @global $wp_list_table Users List Table class. |
| 810 | * @param array $views the views to edit |
| 811 | * @return array $views the edited views |
| 812 | */ |
| 813 | public function members_filter_views( $views = array() ) { |
| 814 | global $wp_list_table; |
| 815 | |
| 816 | if ( ! empty( $wp_list_table ) ) { |
| 817 | // Making sure members will show as they might have no role |
| 818 | // on this blog |
| 819 | foreach ( $wp_list_table->items as $key => $user_data ) { |
| 820 | if ( empty( $user_data->allcaps ) ) { |
| 821 | $user_data->allcaps = array( 'read' => true ); |
| 822 | $user_data->is_bp_member = true; |
| 823 | $wp_list_table->items[ $key ] = $user_data; |
| 824 | } |
| 825 | } |
| 826 | } |
| 827 | // Get the active members |
| 828 | $members = bp_core_get_active_member_count(); |
| 829 | |
| 830 | // Set the Members view link to current view |
| 831 | $class = false; |
| 832 | if ( !empty( $_GET['role'] ) && 'members' == $_GET['role'] ) { |
| 833 | $class = ' class="current"'; |
| 834 | } |
| 835 | |
| 836 | $views['members'] = '<a href="' . add_query_arg( 'role', 'members', bp_get_admin_url( 'users.php' ) ) . '"' . $class . '>' . sprintf( __( ' All Members <span class="count">(%d)</span>', 'buddypress members'), absint( $members ) ) . '</a>'; |
| 837 | |
| 838 | |
| 839 | return $views; |
| 840 | } |
| 841 | |
| 842 | /** |
| 843 | * Reset the bulk actions to avoid the remove from blog action |
| 844 | * |
| 845 | * @access public |
| 846 | * @since BuddyPress (2.0.0) |
| 847 | * |
| 848 | * @param array $bulk_actions the actions to edit |
| 849 | * @return array $bulk_actions the edited actions |
| 850 | */ |
| 851 | public function members_bulk_actions( $bulk_actions = array() ) { |
| 852 | // No bulk actions for members |
| 853 | if ( $this->is_specific_members_screen() && 'users' == get_current_screen()->id ) |
| 854 | $bulk_actions = array(); |
| 855 | |
| 856 | return $bulk_actions; |
| 857 | } |
| 858 | |
| 859 | /** |
| 860 | * Change the help tab of the members screen |
| 861 | * |
| 862 | * @access public |
| 863 | * @since BuddyPress (2.0.0) |
| 864 | * |
| 865 | * @param string $old_help |
| 866 | * @param int $help_id |
| 867 | * @param WP_Screen $wp_screen |
| 868 | * @return string $old_help unchanged |
| 869 | */ |
| 870 | public function members_help_tabs( $old_help = '', $help_id = 0, $wp_screen = null ) { |
| 871 | $wp_screen->add_help_tab( array( |
| 872 | 'id' => 'overview', |
| 873 | 'title' => __( 'Overview', 'buddypress' ), |
| 874 | 'content' => |
| 875 | '<p>' . __( 'This screen lists all the existing members of your site. As BuddyPress is not activated on the network, this is the place where you will be able to edit the community profile of your members.', 'buddypress' ) . '</p>' . |
| 876 | '<p>' . __( 'Only the Network administrators can see this screen.', 'buddypress' ) . '</p>' |
| 877 | ) ); |
| 878 | |
| 879 | $wp_screen->add_help_tab( array( |
| 880 | 'id' => 'actions', |
| 881 | 'title' => __( 'Actions', 'buddypress' ), |
| 882 | 'content' => |
| 883 | '<p>' . __( 'Hovering over a row in the members list will display action links that allow you to manage members. You can perform the following actions:', 'buddypress' ) . '</p>' . |
| 884 | '<ul><li>' . __( 'Edit takes you to the WordPress profile screen for that member. If he is not a user of the blog, this profile will be opened in the network administration.', 'buddypress' ) . '</li>' . |
| 885 | '<li>' . __( 'Profile takes you to the Community profile screen for that member.', 'buddypress' ) . '</li></ul>' |
| 886 | ) ); |
| 887 | |
| 888 | return $old_help; |
| 889 | } |
| 890 | |
| 891 | /** |
| 892 | * Filter the edit link in favor of the network edit link if needed |
| 893 | * |
| 894 | * @access public |
| 895 | * @since BuddyPress (2.0.0) |
| 896 | * |
| 897 | * @global $wp_list_table Users List Table class. |
| 898 | * @param string $edit_link the link to edit user's profile |
| 899 | * @param int $user_id the id of the user |
| 900 | * @return [type] [description] |
| 901 | */ |
| 902 | public function members_edit_link( $edit_link = '', $user_id = 0 ) { |
| 903 | global $wp_list_table; |
| 904 | |
| 905 | if ( empty( $user_id ) ) |
| 906 | return $edit_link; |
| 907 | |
| 908 | if ( !empty( $wp_list_table->items[ $user_id ]->data->is_bp_member ) ) { |
| 909 | $referer_args = array( |
| 910 | 'user_id' => $user_id, |
| 911 | 'wp_http_referer' => urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ) |
| 912 | ); |
| 913 | $edit_args = array_merge( $referer_args ); |
| 914 | |
| 915 | $edit_link = add_query_arg( $edit_args, network_admin_url( 'user-edit.php' ) ); |
| 916 | |
| 917 | if ( get_current_user_id() == $user_id ) { |
| 918 | $edit_link = network_admin_url( 'profile.php' ); |
| 919 | } |
| 920 | } |
| 921 | |
| 922 | return $edit_link; |
| 923 | } |