Skip to content

Conversation

@rollybueno
Copy link

Replace FILTER_SANITIZE_STRING with WordPress Sanitization Functions

Changes Made

  1. Replaced all instances of FILTER_SANITIZE_STRING with WordPress's built-in sanitization functions:

    • sanitize_text_field() for single-line text inputs
    • sanitize_textarea_field() for multi-line text inputs
    • sanitize_email() for email fields
  2. Updated form submission handling in inc/form.php:

    • Replaced filter_input_array() with direct $_POST handling
    • Added proper sanitization callbacks for each field type
    • Maintained array handling for multi-select fields
  3. Updated admin filters in inc/admin.php:

    • Replaced filter_input() calls with sanitize_text_field()
    • Simplified GET parameter handling
    • Maintained default empty string values
  4. Updated post meta handling in inc/post-meta.php:

    • Replaced custom sanitization callback using FILTER_SANITIZE_STRING
    • Now using sanitize_text_field() directly

Why This Change?

  1. FILTER_SANITIZE_STRING is deprecated in PHP 8.1
  2. WordPress's sanitization functions are:
    • Better maintained
    • More secure
    • Consistent with WordPress coding standards
    • Not affected by PHP version changes
    • Specifically designed for WordPress data

Testing

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

  • Addresses PHP 8.1 deprecation warnings
  • Improves security by using WordPress's recommended sanitization methods
  • Makes the code more maintainable and consistent with WordPress standards

Issue reported: #2525

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant