https://github.com/xwp/wp-safe-input
A PHP library for working with form inputs in WordPress
https://github.com/xwp/wp-safe-input
php-library wordpress
Last synced: 10 months ago
JSON representation
A PHP library for working with form inputs in WordPress
- Host: GitHub
- URL: https://github.com/xwp/wp-safe-input
- Owner: xwp
- Created: 2019-02-12T10:58:59.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-02-12T13:47:31.000Z (almost 7 years ago)
- Last Synced: 2024-04-14T07:34:32.562Z (over 1 year ago)
- Topics: php-library, wordpress
- Language: PHP
- Size: 27.3 KB
- Stars: 1
- Watchers: 52
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Safe Input Library for WordPress
[](https://travis-ci.com/xwp/wp-safe-input)
[](https://coveralls.io/github/xwp/wp-safe-input?branch=master)
A helper library for validating and sanitizing form input data.
## Setup
Use [Composer](https://getcomposer.org) to add [this library](https://packagist.org/packages/xwp/wp-safe-input) to your project:
```bash
composer require xwp/wp-safe-input
```
## Usage
See the sample plugin in the [`example` directory](example).
The core logic looks like this:
```php
use XWP\SafeInput\PostMeta;
use XWP\SafeInput\Request;
add_action( 'save_post', function ( $post_id ) {
$request = new Request( INPUT_POST );
$meta = new PostMeta( $post_id );
if ( $request->verify_nonce( 'nonce-action', 'nonce-input-name' ) && $meta->can_save() ) {
if ( 'on' === $request->param( 'input-field-name' ) ) {
// Update post meta value.
} else {
// Delete post meta value.
}
}
} );
```
TODO: Document what happens in the example above.