Skip to content

Commit 74603f6

Browse files
authored
Merge pull request #57 from ProgressPlanner/develop
Another fix included for v1.5.1
2 parents 3ff545c + 9a8e5e3 commit 74603f6

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

css/style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
.aaa_option_table select {
2323
max-width: 20% !important;
2424
}
25+
/* Overrider for the Source <select> in the tfoot. */
26+
.aaa_option_table tfoot select {
27+
max-width: 200px !important;
28+
}
2529
.aaa_option_table .actions .button-delete, .aaa-option-optimizer-reset .button-delete {
2630
margin-right: 0;
2731
color: #a00;

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Please do a pull request via GitHub on [this file](https://github.com/Emilia-Cap
5757
= 1.5.1 =
5858

5959
* Add "select all" checkbox.
60+
* Fix table filtering by Source column.
6061

6162
= 1.5.0 =
6263

src/class-rest.php

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,14 @@ public function get_unused_options() {
254254
// Find unused autoloaded option names.
255255
$autoload_option_keys = array_fill_keys( $autoloaded_option_names, true );
256256
$unused_keys = array_diff_key( $autoload_option_keys, $used_options );
257-
$total_unused = count( $unused_keys );
257+
258+
// Apply source filter to unused keys if specified.
259+
$filter_by_source = isset( $_GET['columns'][2]['search']['value'] ) ? trim( \sanitize_text_field( \wp_unslash( $_GET['columns'][2]['search']['value'] ) ) ) : '';
260+
if ( '' !== $filter_by_source ) {
261+
$unused_keys = $this->filter_by_source( $unused_keys, $filter_by_source );
262+
}
263+
264+
$total_unused = count( $unused_keys );
258265

259266
// Sort order.
260267
[ $order_column, $order_dir ] = $this->get_sort_params();
@@ -359,6 +366,12 @@ public function get_used_not_autoloaded_options() {
359366
// Find used options that are not autoloaded.
360367
$non_autoloaded_used_keys = array_diff_key( $used_options, $autoload_option_keys );
361368

369+
// Filter by source (plugin).
370+
$filter_by_source = isset( $_GET['columns'][2]['search']['value'] ) ? trim( \sanitize_text_field( \wp_unslash( $_GET['columns'][2]['search']['value'] ) ) ) : '';
371+
if ( '' !== $filter_by_source ) {
372+
$non_autoloaded_used_keys = $this->filter_by_source( $non_autoloaded_used_keys, $filter_by_source );
373+
}
374+
362375
// Search.
363376
$search = isset( $_GET['search']['value'] ) ? trim( \sanitize_text_field( \wp_unslash( $_GET['search']['value'] ) ) ) : '';
364377
if ( '' !== $search ) {
@@ -477,6 +490,12 @@ public function get_options_that_do_not_exist() {
477490
// Get used options that are not autoloaded.
478491
$non_autoloaded_keys = array_diff_key( $used_options, $autoload_option_keys );
479492

493+
// Filter by source (plugin).
494+
$filter_by_source = isset( $_GET['columns'][1]['search']['value'] ) ? trim( \sanitize_text_field( \wp_unslash( $_GET['columns'][1]['search']['value'] ) ) ) : '';
495+
if ( '' !== $filter_by_source ) {
496+
$non_autoloaded_keys = $this->filter_by_source( $non_autoloaded_keys, $filter_by_source );
497+
}
498+
480499
// Search.
481500
$search = isset( $_GET['search']['value'] ) ? trim( \sanitize_text_field( \wp_unslash( $_GET['search']['value'] ) ) ) : '';
482501
if ( '' !== $search ) {
@@ -791,4 +810,28 @@ private function get_length( $value ) {
791810
private function get_plugin_name( $option ) {
792811
return $this->map_plugin_to_options->get_plugin_name( $option );
793812
}
813+
814+
/**
815+
* Filter options array by source (plugin) name.
816+
*
817+
* @param array<string, mixed> $options_array The options array to filter.
818+
* @param string $filter_term The filter term to match against plugin names.
819+
*
820+
* @return array<string, mixed> The filtered options array.
821+
*/
822+
private function filter_by_source( array $options_array, string $filter_term ): array {
823+
824+
if ( ! $filter_term ) {
825+
return $options_array;
826+
}
827+
828+
return array_filter(
829+
$options_array,
830+
function ( $option_name ) use ( $filter_term ) {
831+
$plugin_name = $this->get_plugin_name( $option_name );
832+
return false !== stripos( $plugin_name, $filter_term );
833+
},
834+
ARRAY_FILTER_USE_KEY
835+
);
836+
}
794837
}

0 commit comments

Comments
 (0)