Skip to content

Commit

Permalink
Handle authors and roles separately in exclude queries, fixes #527
Browse files Browse the repository at this point in the history
  • Loading branch information
frankiejarrett committed May 23, 2014
1 parent fc1142e commit 4347ed3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
4 changes: 2 additions & 2 deletions includes/list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ function assemble_records( $column, $table = '' ) {
require_once WP_STREAM_INC_DIR . 'class-wp-stream-author.php';
$all_records = array();

// Short circuit and return empty array if we have more than 10 users, to use Ajax instead
// If the number of users exceeds the max authors constant value then return an empty array and use AJAX instead
$user_count = count_users();
$total_users = $user_count['total_users'];
if ( $total_users > WP_Stream_Admin::PRELOAD_AUTHORS_MAX ) {
Expand Down Expand Up @@ -797,7 +797,7 @@ function get_column_excluded_setting_key( $column ) {
$output = 'ip_addresses';
break;
case 'author':
$output = 'authors_and_roles';
$output = 'authors';
break;
default:
$output = false;
Expand Down
5 changes: 4 additions & 1 deletion includes/query.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,10 @@ public static function add_excluded_record_args( $args ) {
$args['action__not_in'] = WP_Stream_Settings::get_excluded_by_key( 'actions' );

// Remove record of excluded author
$args['author__not_in'] = WP_Stream_Settings::get_excluded_by_key( 'authors_and_roles' );
$args['author__not_in'] = WP_Stream_Settings::get_excluded_by_key( 'authors' );

// Remove record of excluded author role
$args['author_role__not_in'] = WP_Stream_Settings::get_excluded_by_key( 'roles' );

// Remove record of excluded ip
$args['ip__not_in'] = WP_Stream_Settings::get_excluded_by_key( 'ip_addresses' );
Expand Down
24 changes: 22 additions & 2 deletions includes/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -846,12 +846,13 @@ public static function get_active_connectors() {
}

/**
* @param $column string name of the setting key (actions|ip_addresses|contexts|connectors)
* @param $column string name of the setting key (authors|roles|actions|ip_addresses|contexts|connectors)
*
* @return array
*/
public static function get_excluded_by_key( $column ) {
$option_name = 'exclude_' . $column;
$option_name = ( 'authors' === $column || 'roles' === $column ) ? 'exclude_authors_and_roles' : 'exclude_' . $column;

$excluded_values = ( isset( self::$options[ $option_name ] ) ) ? self::$options[ $option_name ] : array();

if ( is_callable( $excluded_values ) ) {
Expand All @@ -860,6 +861,25 @@ public static function get_excluded_by_key( $column ) {

$excluded_values = wp_list_filter( $excluded_values, array( '__placeholder__' ), 'NOT' );

if ( 'authors' === $column || 'roles' === $column ) {
// Convert numeric strings to integers
array_walk( $excluded_values, function ( &$value ) {
if ( is_numeric( $value ) ) {
$value = absint( $value );
}
});

if ( 'authors' === $column ) {
$filter = 'is_int'; // Author ID's are always integers
}

if ( 'roles' === $column ) {
$filter = 'is_string'; // Author roles are always strings
}

$excluded_values = array_values( array_filter( $excluded_values, $filter ) ); // Reset the array keys
}

return $excluded_values;
}

Expand Down

0 comments on commit 4347ed3

Please sign in to comment.