Replace FILTER_SANITIZE_STRING into better data sanitisation #3185
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Replace FILTER_SANITIZE_STRING with WordPress Sanitization Functions
Changes Made
Replaced all instances of
FILTER_SANITIZE_STRINGwith WordPress's built-in sanitization functions:sanitize_text_field()for single-line text inputssanitize_textarea_field()for multi-line text inputssanitize_email()for email fieldsUpdated form submission handling in
inc/form.php:filter_input_array()with direct$_POSThandlingUpdated admin filters in
inc/admin.php:filter_input()calls withsanitize_text_field()Updated post meta handling in
inc/post-meta.php:FILTER_SANITIZE_STRINGsanitize_text_field()directlyWhy This Change?
FILTER_SANITIZE_STRINGis deprecated in PHP 8.1Testing
The changes maintain the same functionality while improving security and future compatibility. All form submissions, admin filters, and post meta handling should work as before but with better sanitization.
!! Since we don't have testunit, this still needs a manual testing. Make sure that it has been tested thoroughly before merging!
Related Issues
Issue reported: #2525