Skip to:
Content

BuddyPress.org

Ticket #5114: 5114.diff

File 5114.diff, 2.2 KB (added by imath, 12 years ago)
  • bp-core/bp-core-classes.php

     
    281281                        // 'alphabetical' sorts depend on the xprofile setup
    282282                        case 'alphabetical' :
    283283
     284                                // Even if it penalizes performance, the use of last_activity is interesting to
     285                                // - neutralize the display of spammers and to avoid 404 for non admins
     286                                // - have a count that is coherent with the tab "All Members"
     287                                $this->uid_name = 'user_id';
     288                                $sql['select']  = "SELECT DISTINCT u.{$this->uid_name} as id FROM {$wpdb->usermeta} u";
     289                                $sql['where'][] = $wpdb->prepare( "u.meta_key = %s", bp_get_user_meta_key( 'last_activity' ) );
     290
    284291                                // We prefer to do alphabetical sorts against the display_name field
    285292                                // of wp_users, because the table is smaller and better indexed. We
    286293                                // can do so if xprofile sync is enabled, or if xprofile is inactive.
    287294                                //
    288295                                // @todo remove need for bp_is_active() check
    289296                                if ( ! bp_disable_profile_sync() || ! bp_is_active( 'xprofile' ) ) {
    290                                         $this->uid_name = 'ID';
    291                                         $sql['select']  = "SELECT DISTINCT u.{$this->uid_name} as id FROM {$wpdb->users} u";
    292                                         $sql['orderby'] = "ORDER BY u.display_name";
     297                                        $sql['select']  .= " LEFT JOIN {$wpdb->users} us ON( u.{$this->uid_name} = us.ID )";
     298                                        $sql['orderby'] = "ORDER BY us.display_name";
    293299                                        $sql['order']   = "ASC";
    294300
    295301                                // When profile sync is disabled, alphabetical sorts must happen against
     
    297303                                } else {
    298304                                        $fullname_field_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_fields} WHERE name = %s", bp_xprofile_fullname_field_name() ) );
    299305
    300                                         $this->uid_name = 'user_id';
    301                                         $sql['select']  = "SELECT DISTINCT u.{$this->uid_name} as id FROM {$bp->profile->table_name_data} u";
    302                                         $sql['where'][] = "u.field_id = {$fullname_field_id}";
    303                                         $sql['orderby'] = "ORDER BY u.value";
     306                                        $sql['select']  .= " LEFT JOIN {$bp->profile->table_name_data} us ON( u.{$this->uid_name} = us.{$this->uid_name} )";
     307                                        $sql['where'][] = "us.field_id = {$fullname_field_id}";
     308                                        $sql['orderby'] = "ORDER BY us.value";
    304309                                        $sql['order']   = "ASC";
    305310                                }
    306311