diff --git a/assets/js/plugin-check-admin.js b/assets/js/plugin-check-admin.js index 089b32bf8..086eef5c4 100644 --- a/assets/js/plugin-check-admin.js +++ b/assets/js/plugin-check-admin.js @@ -35,6 +35,29 @@ canRunChecks(); pluginsList.addEventListener( 'change', canRunChecks ); + function saveUserSettings() { + const selectedCategories = []; + + // Assuming you have a list of category checkboxes, find the selected ones. + categoriesList.forEach( function ( checkbox ) { + if ( checkbox.checked ) { + selectedCategories.push( checkbox.value ); + } + } ); + + // Join the selected category slugs with '__' and save it as a user setting. + const settingValue = selectedCategories.join( '__' ); + window.setUserSetting( + 'plugin_check_category_preferences', + settingValue + ); + } + + // Attach the saveUserSettings function when a category checkbox is clicked. + categoriesList.forEach( function ( checkbox ) { + checkbox.addEventListener( 'change', saveUserSettings ); + } ); + // When the Check it button is clicked. checkItButton.addEventListener( 'click', ( e ) => { e.preventDefault(); diff --git a/includes/Admin/Admin_Page.php b/includes/Admin/Admin_Page.php index 51588bdef..4e6b61c6b 100644 --- a/includes/Admin/Admin_Page.php +++ b/includes/Admin/Admin_Page.php @@ -150,16 +150,20 @@ private function get_available_plugins() { * Renders the "Plugin Check" page. * * @since n.e.x.t + * + * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ public function render_page() { - global $available_plugins, $selected_plugin_basename, $categories; - $available_plugins = $this->get_available_plugins(); $selected_plugin_basename = filter_input( INPUT_GET, 'plugin', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); $categories = Check_Categories::get_categories(); + // Get user settings for category preferences and set a default value to check all categories by default. + $user_enabled_categories = get_user_setting( 'plugin_check_category_preferences', 'all_categories' ); + $user_enabled_categories = 'all_categories' === $user_enabled_categories ? $categories : explode( '__', $user_enabled_categories ); + require WP_PLUGIN_CHECK_PLUGIN_DIR_PATH . 'templates/admin-page.php'; } diff --git a/templates/admin-page.php b/templates/admin-page.php index 2188fa656..37445e1c8 100644 --- a/templates/admin-page.php +++ b/templates/admin-page.php @@ -45,7 +45,7 @@