Skip to content

Commit

Permalink
Merge pull request #382 from faishal/master
Browse files Browse the repository at this point in the history
Fix Stream filter issue with exclude settings #362
  • Loading branch information
frankiejarrett committed Apr 2, 2014
2 parents b29c796 + f32f40b commit 1f25dc0
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 33 deletions.
9 changes: 5 additions & 4 deletions includes/context-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ function parse_query_vars( $query ) {
$lookup = array( '=', 'IN', 'NOT IN' );
$compare = $lookup[ $i ];
if ( ! empty( $query[ $key . $suffix ] ) ) {
$context_query[0][ $key ] = array(
'value' => $query[ $key . $suffix ],
'compare' => $compare,
);
$context_query[ ] = array(
$key => array(
'value' => $query[ $key . $suffix ], 'compare' => $compare,
)
);
}
}
}
Expand Down
59 changes: 45 additions & 14 deletions includes/list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,27 @@ public function get_term_title( $term, $type ) {
* @return array options to be displayed in search filters
*/
function assemble_records( $column, $table = '' ) {

$setting_key = self::get_column_excluded_setting_key( $column );

/**
* Toggle visibility of disabled connectors/actions/contexts on list table filter dropdown
*
* @param bool $hidden Visibility status, default is Hide Previous Record value set in Exclude setting.
*/
$hide_disabled_column_filter = apply_filters( 'wp_stream_list_table_hide_disabled_ ' . $setting_key, ( WP_Stream_Settings::$options[ 'exclude_hide_previous_records' ] === 0 ) ? false : true );

if ( 'author' === $column ) {
$all_records = array();
$authors = get_users();
if ( $hide_disabled_column_filter ) {
$excluded_records = WP_Stream_Settings::get_excluded_by_key( $setting_key );
}

foreach ( $authors as $author ) {
if ( $hide_disabled_column_filter && in_array( $author->ID, $excluded_records ) ) {
continue;
}
$author = get_user_by( 'id', $author->ID );
if ( $author ) {
$all_records[ $author->ID ] = $author;
Expand All @@ -404,20 +421,11 @@ function assemble_records( $column, $table = '' ) {
$prefixed_column = sprintf( 'stream_%s', $column );
$all_records = WP_Stream_Connectors::$term_labels[ $prefixed_column ];

if ( 'connector' === $column ) {
/**
* Toggle visibility of disabled connectors on list table filter dropdown
*
* @param bool $hidden Visibility status, hidden by default.
*/
$hide_disabled_connectors_filter = apply_filters( 'wp_stream_list_table_hide_disabled_connectors', true );

if ( true === $hide_disabled_connectors_filter ) {
$excluded_connectors = WP_Stream_Settings::get_excluded_by_key( 'connectors' );
foreach ( array_keys( $all_records ) as $_connector ) {
if ( in_array( $_connector, $excluded_connectors ) ) {
unset( $all_records[ $_connector ] );
}
if ( true === $hide_disabled_column_filter ) {
$excluded_records = WP_Stream_Settings::get_excluded_by_key( $setting_key );
foreach ( array_keys( $all_records ) as $_connector ) {
if ( in_array( $_connector, $excluded_records ) ) {
unset( $all_records[ $_connector ] );
}
}
}
Expand Down Expand Up @@ -694,4 +702,27 @@ static function live_update_checkbox( $status, $args ) {
return ob_get_clean();
}

/**
* This function is use to map List table column name with excluded setting keys
*
* @param $column string list table column name
*
* @return string setting name for that column
*/
function get_column_excluded_setting_key( $column ) {
switch ( $column ) {
case 'connector' :
return 'connectors';
case 'context' :
return 'contexts';
case 'action' :
return 'action';
case 'ip':
return 'ip_addresses';
case 'author':
return 'authors_and_roles';
default:
return false;
}
}
}
20 changes: 5 additions & 15 deletions includes/query.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,29 +324,19 @@ public function query( $args ) {
*/
public static function add_excluded_record_args( $args ) {
// Remove record of excluded connector
if ( empty( $args['connector'] ) ) {
$args['connector__not_in'] = WP_Stream_Settings::get_excluded_by_key( 'connectors' );
}
$args['connector__not_in'] = WP_Stream_Settings::get_excluded_by_key( 'connectors' );

// Remove record of excluded context
if ( empty( $args['context'] ) ) {
$args['context__not_in'] = WP_Stream_Settings::get_excluded_by_key( 'contexts' );
}
$args['context__not_in'] = WP_Stream_Settings::get_excluded_by_key( 'contexts' );

// Remove record of excluded actions
if ( empty( $args['action'] ) ) {
$args['action__not_in'] = WP_Stream_Settings::get_excluded_by_key( 'actions' );
}
$args['action__not_in'] = WP_Stream_Settings::get_excluded_by_key( 'actions' );

// Remove record of excluded author
if ( empty( $args['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_and_roles' );

// Remove record of excluded ip
if ( empty( $args['ip'] ) ) {
$args['ip__not_in'] = WP_Stream_Settings::get_excluded_by_key( 'ip_addresses' );
}
$args['ip__not_in'] = WP_Stream_Settings::get_excluded_by_key( 'ip_addresses' );

return $args;
}
Expand Down

0 comments on commit 1f25dc0

Please sign in to comment.