xwp/wp-safe-input

0.0.1 2019-02-12 13:30 UTC

This package is auto-updated.

Last update: 2024-09-13 03:51:30 UTC


README

Build Status Coverage Status

这是一个用于验证和清理表单输入数据的辅助库。

设置

使用 Composer 将此库添加到您的项目中 (此库链接)

composer require xwp/wp-safe-input

用法

请查看 example 目录中的示例插件

核心逻辑如下

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.
		}
	}
} );

待办:记录上述示例中发生的事情。