Skip to:
Content

BuddyPress.org

Ticket #5367: 5367.02.diff

File 5367.02.diff, 9.7 KB (added by imath, 11 years ago)
  • bp-members/bp-members-admin.php

     
    116116
    117117                // BuddyPress edit user's profile url
    118118                $this->edit_profile_url = add_query_arg( 'page', 'bp-profile-edit', bp_get_admin_url( 'users.php' ) );
     119
     120                // BuddyPress specific config
     121                $this->ms_child_activated = (bool) is_multisite() && ! bp_is_network_activated() && bp_is_root_blog();
    119122        }
    120123
    121124        /**
     
    146149                // Add a row action to users listing
    147150                add_filter( bp_core_do_network_admin() ? 'ms_user_row_actions' : 'user_row_actions', array( $this, 'row_actions' ), 10, 2 );
    148151
     152                /** Specific config *******************************************/
     153
     154                // Specific hooks in case BuddyPress is not activated on the network
     155                if ( ! empty( $this->ms_child_activated ) && current_user_can( 'manage_network_users') ) {
     156                        add_action( 'load-users.php',     array( $this, 'members_load_screen' ),       10    );
     157                        add_action( 'pre_user_query',     array( $this, 'members_query' ),             10, 1 );
     158                        add_filter( 'views_users',        array( $this, 'members_filter_views' ),      10, 1 );
     159                        add_filter( 'bulk_actions-users', array( $this, 'members_bulk_actions' ),      10, 1 );
     160                }
     161
    149162        }
    150163
    151164        /**
     
    224237                        $query_args['wp_http_referer'] = urlencode( wp_unslash( $_REQUEST['wp_http_referer'] ) );
    225238                }
    226239
     240                $wordpress_url = $this->edit_url;
    227241                $community_url = add_query_arg( $query_args, $this->edit_profile_url );
    228                 $wordpress_url = add_query_arg( $query_args, $this->edit_url         );
    229242
     243                if ( $this->ms_child_activated && ! is_user_member_of_blog( $user->ID, bp_get_root_blog_id() ) ) {
     244                        $wordpress_url = network_admin_url( 'user-edit.php' );
     245
     246                        if( get_current_user_id() == $user->ID ) {
     247                                $wordpress_url = network_admin_url( 'profile.php' );
     248                                $query_args = array();
     249                        }
     250                }
     251
     252                $wordpress_url = add_query_arg( $query_args, $wordpress_url );
     253
    230254                $bp_active = false;
    231255                $wp_active = ' nav-tab-active';
    232256                if ( 'BuddyPress' === $active ) {
     
    664688         */
    665689        public function row_actions( $actions = '', $user = null ) {
    666690
     691                if( $this->ms_child_activated && ! $this->is_specific_members_screen() )
     692                        return $actions;
     693
    667694                $edit_profile = add_query_arg( array(
    668695                        'user_id'         => $user->ID,
    669696                        'wp_http_referer' => urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ),
     
    677704                        'edit-profile' => '<a href="' . esc_url( $edit_profile ) . '">' . esc_html__( 'Profile', 'buddypress' ) . '</a>'
    678705                );
    679706
    680                 return array_merge( $new_edit_actions, $actions );
     707                $actions = array_merge( $new_edit_actions, $actions );
     708
     709                // Specific to handle the case when BuddyPress is not networked activated
     710                if ( ! empty( $user->is_bp_member ) && current_user_can( 'manage_network_users' ) ) {
     711                        // No need to remove this user from blog, he's not attached to this blog
     712                        unset( $actions['remove'] );
     713
     714                        $referer_args = array(
     715                                'wp_http_referer' => urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) )
     716                        );
     717 
     718                        if ( current_user_can( 'delete_user', $user->ID ) && ! in_array( $user->user_login, get_super_admins() ) ) {
     719                                $delete_args = array_merge( array( 'action' => 'deleteuser', 'id' => $user->ID ), $referer_args );
     720                                $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>';
     721                        }
     722                }
     723
     724                return $actions;
    681725        }
     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        }
    682924}
    683925endif; // class_exists check
    684926