arraypress / wp-sanitize-polyfills
Additional sanitization functions that complement WordPress core.
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/arraypress/wp-sanitize-polyfills
Requires
- php: >=7.4
This package is auto-updated.
Last update: 2026-02-04 17:12:34 UTC
README
Additional sanitization functions that complement WordPress core. These functions follow WordPress naming conventions and feel like native functions that should exist in core.
Installation
composer require arraypress/wp-sanitize-polyfills
Functions
sanitize_object_ids
Sanitize an array of object IDs (post IDs, term IDs, user IDs, etc.).
$ids = sanitize_object_ids( [ '1', 2, '3', 0, '', 2, 'abc' ] ); // Returns: [ 1, 2, 3 ]
sanitize_amount
Sanitize a monetary/decimal amount.
$price = sanitize_amount( '$1,234.567' ); // Returns: '1234.57' $price = sanitize_amount( '99.9', 0 ); // Returns: '100' $price = sanitize_amount( '-45.5', 2 ); // Returns: '-45.50'
sanitize_comma_list
Sanitize a comma-separated list into an array.
$tags = sanitize_comma_list( 'apple, banana, , cherry' ); // Returns: [ 'apple', 'banana', 'cherry' ]
sanitize_newline_list
Sanitize a newline-separated list into an array.
$lines = sanitize_newline_list( "line one\nline two\n\nline three" ); // Returns: [ 'line one', 'line two', 'line three' ]
sanitize_emails
Sanitize a list of email addresses. Accepts comma-separated string, newline-separated string, or array.
// From comma-separated string $emails = sanitize_emails( 'john@example.com, invalid, jane@example.com' ); // Returns: [ 'john@example.com', 'jane@example.com' ] // From array $emails = sanitize_emails( [ 'john@example.com', 'not-an-email', 'jane@example.com' ] ); // Returns: [ 'john@example.com', 'jane@example.com' ]
is_valid_json
Check if a string is valid JSON.
is_valid_json( '{"name": "John"}' ); // true is_valid_json( 'not json' ); // false is_valid_json( '' ); // false
Requirements
- PHP 7.4+
- WordPress (for
sanitize_text_field(),sanitize_email(),is_email())
License
GPL-2.0-or-later