diff --git a/includes/list-table.php b/includes/list-table.php index 03e823586..63b699950 100644 --- a/includes/list-table.php +++ b/includes/list-table.php @@ -137,6 +137,21 @@ 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_Stream_Settings::get_active_connectors(); + } + } + + if ( ! isset( $args['records_per_page'] ) ) { $args['records_per_page'] = $this->get_items_per_page( 'edit_stream_per_page', 20 ); } @@ -377,6 +392,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_hide_disabled_connectors', true ); + + if ( true === $hide_disabled_connectors_filter ) { + $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 ] ); + } + } + } + } } $existing_records = existing_records( $column, $table ); 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 *