diff --git a/assets/js/plugin-check-admin.js b/assets/js/plugin-check-admin.js index f067d600e..3c87accc5 100644 --- a/assets/js/plugin-check-admin.js +++ b/assets/js/plugin-check-admin.js @@ -218,6 +218,46 @@ return false; } + /** + * Counts the total number of errors and warnings in the aggregated results. + * + * @since 1.9.0 + * + * @return {Object} Object with errorCount and warningCount properties. + */ + function countResults() { + let errorCount = 0; + let warningCount = 0; + + // Count errors. + for ( const file of Object.keys( aggregatedResults.errors ) ) { + const lines = aggregatedResults.errors[ file ] || {}; + + for ( const line of Object.keys( lines ) ) { + const columns = lines[ line ] || {}; + + for ( const column of Object.keys( columns ) ) { + errorCount += ( columns[ column ] || [] ).length; + } + } + } + + // Count warnings. + for ( const file of Object.keys( aggregatedResults.warnings ) ) { + const lines = aggregatedResults.warnings[ file ] || {}; + + for ( const line of Object.keys( lines ) ) { + const columns = lines[ line ] || {}; + + for ( const column of Object.keys( columns ) ) { + warningCount += ( columns[ column ] || [] ).length; + } + } + } + + return { errorCount, warningCount }; + } + function defaultString( key ) { if ( pluginCheck.strings && @@ -545,9 +585,48 @@ */ function renderResultsMessage( isSuccessMessage ) { const messageType = isSuccessMessage ? 'success' : 'error'; - const messageText = isSuccessMessage - ? pluginCheck.successMessage - : pluginCheck.errorMessage; + let messageText; + + if ( isSuccessMessage ) { + messageText = pluginCheck.successMessage; + } else { + // Count errors and warnings. + const { errorCount, warningCount } = countResults(); + + // Build the message with counts. + let errorPart = ''; + if ( errorCount > 0 ) { + errorPart = + errorCount === 1 + ? pluginCheck.errorString.replace( '%d', errorCount ) + : pluginCheck.errorsString.replace( '%d', errorCount ); + } + + let warningPart = ''; + if ( warningCount > 0 ) { + warningPart = + warningCount === 1 + ? pluginCheck.warningString.replace( + '%d', + warningCount + ) + : pluginCheck.warningsString.replace( + '%d', + warningCount + ); + } + + if ( errorPart && warningPart ) { + messageText = errorPart + ' and ' + warningPart + ' found.'; + } else if ( errorPart ) { + messageText = errorPart + ' found.'; + } else if ( warningPart ) { + messageText = warningPart + ' found.'; + } else { + // Fallback to default message if somehow no errors/warnings. + messageText = pluginCheck.errorMessage; + } + } resultsContainer.innerHTML = renderTemplate( 'plugin-check-results-complete', { diff --git a/includes/Admin/Admin_Page.php b/includes/Admin/Admin_Page.php index 89e8d182d..1b589df05 100644 --- a/includes/Admin/Admin_Page.php +++ b/includes/Admin/Admin_Page.php @@ -204,6 +204,14 @@ public function enqueue_scripts() { 'actionExportResults' => Admin_AJAX::ACTION_EXPORT_RESULTS, 'successMessage' => __( 'No errors found.', 'plugin-check' ), 'errorMessage' => __( 'Errors were found.', 'plugin-check' ), + /* translators: %d: Number of errors found. */ + 'errorString' => __( '%d error', 'plugin-check' ), + /* translators: %d: Number of errors found. */ + 'errorsString' => __( '%d errors', 'plugin-check' ), + /* translators: %d: Number of warnings found. */ + 'warningString' => __( '%d warning', 'plugin-check' ), + /* translators: %d: Number of warnings found. */ + 'warningsString' => __( '%d warnings', 'plugin-check' ), 'strings' => array( 'exportCsv' => __( 'Export CSV', 'plugin-check' ), 'exportJson' => __( 'Export JSON', 'plugin-check' ),