arraypress/wp-sanitize-polyfills
Composer 安装命令:
composer require arraypress/wp-sanitize-polyfills
包简介
Additional sanitization functions that complement WordPress core.
README 文档
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
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2026-02-04