Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [Unreleased]
### Added
- feat: add plugin search and filter UI

## 1.1.0-beta.1

- Feat: Refactor for WPCS and best practices
Expand Down
27 changes: 27 additions & 0 deletions assets/src/js/admin.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
/**
* This will have admin related code only.
*/

// Add event listener for search input
const pluginSearchInput = document.getElementById('plugin-search-input');
const pluginTableRows = document.querySelectorAll('#plugin-browser-table tbody tr');

if (pluginSearchInput) {
pluginSearchInput.addEventListener('input', (event) => {
const searchTerm = event.target.value.toLowerCase();

pluginTableRows.forEach((row) => {
const pluginName = row.querySelector('.plugin-name').textContent.toLowerCase();
const pluginStatus = row.querySelector('.plugin-status').textContent.toLowerCase();

if (pluginName.includes(searchTerm) || pluginStatus.includes(searchTerm)) {
row.style.display = '';
} else {
row.style.display = 'none';
}
});
});
}

// Ensure the plugin browser table matches WordPress admin patterns
const pluginTable = document.getElementById('plugin-browser-table');
if (pluginTable) {
pluginTable.classList.add('wp-list-table', 'widefat', 'fixed', 'striped');
}
28 changes: 28 additions & 0 deletions inc/Modules/Core/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,32 @@ private function register_style( string $handle, string $filename, array $deps =
$media
);
}

/**
* AJAX handler for plugin search and filter.
*/
public function handle_plugin_search(): void {
check_ajax_referer( 'plugin_search_nonce', 'security' );

if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_error( [ 'message' => 'Unauthorized' ], 403 );
}

$search_term = isset( $_POST['search'] ) ? sanitize_text_field( wp_unslash( $_POST['search'] ) ) : '';
$plugins = $this->get_plugins(); // Assume this method fetches the plugin list.

$filtered_plugins = array_filter( $plugins, function ( $plugin ) use ( $search_term ) {
return stripos( $plugin['name'], $search_term ) !== false ||
stripos( $plugin['status'], $search_term ) !== false;
});

wp_send_json_success( [ 'plugins' => $filtered_plugins ] );
}

/**
* Register AJAX actions.
*/
public function register_ajax_actions(): void {
add_action( 'wp_ajax_plugin_search', [ $this, 'handle_plugin_search' ] );
}
}