PHP code example of xwp / wp-safe-input
1. Go to this page and download the library: Download xwp/wp-safe-input library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
xwp / wp-safe-input example snippets
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.
}
}
} );