From ea9b54dd311caf78efc417233fa2e18c2a045b1b Mon Sep 17 00:00:00 2001 From: Dzikri Aziz Date: Thu, 20 Feb 2014 03:10:42 +0700 Subject: [PATCH 1/5] Hide disabled connectors on list table filter dropdown Introduce new filter: 'wp_stream_list_table_show_disabled_connectors' to toggle the visibility. --- includes/list-table.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/includes/list-table.php b/includes/list-table.php index 03e823586..7d8fd6f98 100644 --- a/includes/list-table.php +++ b/includes/list-table.php @@ -377,6 +377,24 @@ function assemble_records( $column, $table = '' ) { } } else { $all_records = WP_Stream_Connectors::$term_labels['stream_' . $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_show_disabled_connectors', true ); + + if ( true === $hide_disabled_connectors_filter ) { + $active_connectors = WP_Stream_Settings::$options['connectors_active_connectors']; + foreach ( array_keys( $all_records ) as $_connector ) { + if ( ! in_array( $_connector, $active_connectors ) ) { + unset( $all_records[ $_connector ] ); + } + } + } + } } $existing_records = existing_records( $column, $table ); From fbcd9f02173be3b5df6e8bacd13c859135cb6e30 Mon Sep 17 00:00:00 2001 From: Dzikri Aziz Date: Thu, 20 Feb 2014 03:12:48 +0700 Subject: [PATCH 2/5] Hide disabled connectors on list table filter dropdown Introduce new filter: 'wp_stream_list_table_hide_disabled_connectors' for toggling the visibility. --- includes/list-table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/list-table.php b/includes/list-table.php index 7d8fd6f98..5cd1ffb24 100644 --- a/includes/list-table.php +++ b/includes/list-table.php @@ -384,7 +384,7 @@ function assemble_records( $column, $table = '' ) { * * @param bool $hidden Visibility status, hidden by default. */ - $hide_disabled_connectors_filter = apply_filters( 'wp_stream_list_table_show_disabled_connectors', true ); + $hide_disabled_connectors_filter = apply_filters( 'wp_stream_list_table_hide_disabled_connectors', true ); if ( true === $hide_disabled_connectors_filter ) { $active_connectors = WP_Stream_Settings::$options['connectors_active_connectors']; From 7713e616972057c1ae7a07b185caf3212a07d20f Mon Sep 17 00:00:00 2001 From: Dzikri Aziz Date: Thu, 20 Feb 2014 04:17:42 +0700 Subject: [PATCH 3/5] Hide records from disabled connectors on list table Introduce 'wp_stream_list_table_hide_disabled_connectors_records' filter --- includes/list-table.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/includes/list-table.php b/includes/list-table.php index 5cd1ffb24..796b0545d 100644 --- a/includes/list-table.php +++ b/includes/list-table.php @@ -137,6 +137,25 @@ function get_records() { } $args['paged'] = $this->get_pagenum(); + // Exclude disabled connectors + if ( empty( $args['connector'] ) ) { + /** + * Toggle visibility of records from disabled connectors on list table + * + * @param bool $hidden Visibility status, hidden by default. + */ + $hide_disabled_connectors_records = apply_filters( 'wp_stream_list_table_hide_disabled_connectors_records', true ); + + if ( true === $hide_disabled_connectors_records ) { + $args['connector__in'] = wp_list_filter( + WP_Stream_Settings::$options['connectors_active_connectors'], + array( '__placeholder__' ), + 'NOT' + ); + } + } + + if ( ! isset( $args['records_per_page'] ) ) { $args['records_per_page'] = $this->get_items_per_page( 'edit_stream_per_page', 20 ); } From c7e9472ddea82211a45363757b503ae9babb1cb7 Mon Sep 17 00:00:00 2001 From: Dzikri Aziz Date: Thu, 20 Feb 2014 04:49:10 +0700 Subject: [PATCH 4/5] Fix active connectors checking on post list table --- includes/list-table.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/includes/list-table.php b/includes/list-table.php index 796b0545d..8beee1ae0 100644 --- a/includes/list-table.php +++ b/includes/list-table.php @@ -147,11 +147,11 @@ function get_records() { $hide_disabled_connectors_records = apply_filters( 'wp_stream_list_table_hide_disabled_connectors_records', true ); if ( true === $hide_disabled_connectors_records ) { - $args['connector__in'] = wp_list_filter( - WP_Stream_Settings::$options['connectors_active_connectors'], - array( '__placeholder__' ), - 'NOT' - ); + $active_connectors = WP_Stream_Settings::$options['connectors_active_connectors']; + if ( is_callable( $active_connectors ) ) { + $active_connectors = call_user_func( $active_connectors ); + } + $args['connector__in'] = wp_list_filter( $active_connectors, array( '__placeholder__' ), 'NOT' ); } } From 220cbe3bf5dbfa2fb699064891bc7dfda59cba16 Mon Sep 17 00:00:00 2001 From: Dzikri Aziz Date: Thu, 20 Feb 2014 05:33:11 +0700 Subject: [PATCH 5/5] Fix active connectors checking Introduce WP_Stream_Settings::get_active_connectors() --- includes/list-table.php | 8 ++------ includes/settings.php | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/includes/list-table.php b/includes/list-table.php index 8beee1ae0..63b699950 100644 --- a/includes/list-table.php +++ b/includes/list-table.php @@ -147,11 +147,7 @@ function get_records() { $hide_disabled_connectors_records = apply_filters( 'wp_stream_list_table_hide_disabled_connectors_records', true ); if ( true === $hide_disabled_connectors_records ) { - $active_connectors = WP_Stream_Settings::$options['connectors_active_connectors']; - if ( is_callable( $active_connectors ) ) { - $active_connectors = call_user_func( $active_connectors ); - } - $args['connector__in'] = wp_list_filter( $active_connectors, array( '__placeholder__' ), 'NOT' ); + $args['connector__in'] = WP_Stream_Settings::get_active_connectors(); } } @@ -406,7 +402,7 @@ function assemble_records( $column, $table = '' ) { $hide_disabled_connectors_filter = apply_filters( 'wp_stream_list_table_hide_disabled_connectors', true ); if ( true === $hide_disabled_connectors_filter ) { - $active_connectors = WP_Stream_Settings::$options['connectors_active_connectors']; + $active_connectors = WP_Stream_Settings::get_active_connectors(); foreach ( array_keys( $all_records ) as $_connector ) { if ( ! in_array( $_connector, $active_connectors ) ) { unset( $all_records[ $_connector ] ); diff --git a/includes/settings.php b/includes/settings.php index 2a5fde003..52e2a5ae7 100644 --- a/includes/settings.php +++ b/includes/settings.php @@ -406,6 +406,25 @@ public static function get_default_connectors() { return array_keys( WP_Stream_Connectors::$term_labels['stream_connector'] ); } + /** + * Get an array of active Connectors + * + * @return array + */ + public static function get_active_connectors() { + $active_connectors = self::$options['connectors_active_connectors']; + if ( is_callable( $active_connectors ) ) { + $active_connectors = call_user_func( $active_connectors ); + } + $active_connectors = wp_list_filter( + $active_connectors, + array( '__placeholder__' ), + 'NOT' + ); + + return $active_connectors; + } + /** * Get translations of serialized Stream settings *