@@ -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