Skip to content

Commit

Permalink
[issue-49] Display info when more results found
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzysztof Powelski committed Feb 10, 2014
1 parent 0cea330 commit 77bb1f9
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions includes/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

class WP_Stream_Admin {

const PRELOADED_AUTHORS_NUMBER = 50;

/**
* Menu page screen id
*
Expand Down Expand Up @@ -714,12 +716,24 @@ function( $user ) {
break;
}

// `search` arg for get_users() is not enough
$results = array_filter(
$results,
function( $result ) {
return mb_strpos( mb_strtolower( $result['text'] ), mb_strtolower( $_REQUEST['q'] ) ) !== false;
}
);

$results_count = count( $results );

if ( $results_count > self::PRELOADED_AUTHORS_NUMBER ) {
$results = array_slice( $results, 0, self::PRELOADED_AUTHORS_NUMBER );
$results[] = array(
'id' => 0,
'disabled' => true,
'text' => sprintf( _n( 'One more result...', '%d more results...', $results_count - self::PRELOADED_AUTHORS_NUMBER, 'stream' ), $results_count - self::PRELOADED_AUTHORS_NUMBER ),
);
}

echo json_encode( array_values( $results ) );
die();
Expand Down

0 comments on commit 77bb1f9

Please sign in to comment.