xwp / wp-safe-input
0.0.1
2019-02-12 13:30 UTC
Requires (Dev)
- 10up/wp_mock: ^0.4.0
- dealerdirect/phpcodesniffer-composer-installer: ^0.5.0
- php-coveralls/php-coveralls: ^2.1
- phpunit/phpunit: ^4.0 || ^5.0 || ^6.0 || ^7.0
- wp-coding-standards/wpcs: ^2.0
This package is auto-updated.
Last update: 2024-11-13 04:11:46 UTC
README
A helper library for validating and sanitizing form input data.
Setup
Use Composer to add this library to your project:
composer require xwp/wp-safe-input
Usage
See the sample plugin in the example
directory.
The core logic looks like this:
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.