Skip to content

Commit

Permalink
Add a sanitizer for the summary_meta_data
Browse files Browse the repository at this point in the history
  • Loading branch information
pattonwebz committed Apr 4, 2024
1 parent 23975b9 commit 5d8dae3
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion includes/classes/class-summary-generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,33 @@ private function get_readability( $summary ) {
* @since 1.9.0
*/
private function save_summary_meta_data( $summary ) {
update_post_meta( $this->post_id, '_edac_summary', $summary );
update_post_meta( $this->post_id, '_edac_summary', $this->sanitize_summary_meta_data( $summary ) );
update_post_meta( $this->post_id, '_edac_summary_passed_tests', absint( $summary['passed_tests'] ) );
update_post_meta( $this->post_id, '_edac_summary_errors', absint( $summary['errors'] ) );
update_post_meta( $this->post_id, '_edac_summary_warnings', absint( $summary['warnings'] ) );
update_post_meta( $this->post_id, '_edac_summary_ignored', absint( $summary['ignored'] ) );
update_post_meta( $this->post_id, '_edac_summary_contrast_errors', absint( $summary['contrast_errors'] ) );
}

/**
* Sanitizes the summary metadata before saving it to the database.
*
* @param array $summary An associative array containing the summary of accessibility checks.
*
* @return array The sanitized summary metadata.
*
* @since 1.11.0
*/
private function sanitize_summary_meta_data( array $summary ): array {
return array(
'passed_tests' => absint( $summary['passed_tests'] ?? 0 ),
'errors' => absint( $summary['errors'] ?? 0 ),
'warnings' => absint( $summary['warnings'] ?? 0 ),
'ignored' => absint( $summary['ignored'] ?? 0 ),
'contrast_errors' => absint( $summary['contrast_errors'] ?? 0 ),
'content_grade' => absint( $summary['content_grade'] ?? 0 ),
'readability' => sanitize_text_field( $summary['readability'] ?? '' ),
'simplified_summary' => filter_var( $summary['simplified_summary'] ?? false, FILTER_VALIDATE_BOOLEAN ),
);
}
}

0 comments on commit 5d8dae3

Please sign in to comment.