-
Notifications
You must be signed in to change notification settings - Fork 0
/
wfv-validate.php
49 lines (43 loc) · 1.32 KB
/
wfv-validate.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
defined( 'ABSPATH' ) || die();
/*
Plugin Name: WFV - Form Validation
Plugin URI: https://macder.github.io/wfv/
Description: A simple fluid and concise API to manage user input, validation, feedback, and safe output.
Version: 0.12.1
Author: Maciej Derulski
Author URI: https://github.com/macder
License: BSD 3-Clause
License URI: https://github.com/macder/wfv-validation/blob/master/LICENSE
*/
define( 'WFV_VALIDATE_VERSION', '0.12.1' );
define( 'WFV_VALIDATE__MINIMUM_WP_VERSION', '3.7' );
define( 'WFV_VALIDATE__PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
require_once WFV_VALIDATE__PLUGIN_DIR . '/vendor/autoload.php';
use WFV\FormComposite;
use WFV\RuleFactory;
use WFV\Validator;
use WFV\Artisan\Director;
use WFV\Artisan\FormArtisan;
use WFV\Collection\MessageCollection;
/**
*
*
* @since 0.10.0
*
* @param string $action
* @param array $form Form arguments
* @param bool $trim Trim whitespace from beginning and end of string
*/
function wfv_create( $action, array &$form, $trim = true ) {
$messages = new MessageCollection( $form );
$builder = new FormArtisan( $form, $action );
$form = ( new Director() )
->with( 'input' )
->with( 'rules' )
->with( 'errors' )
->compose( $builder );
if( $form->input()->is_populated() ) {
( new Validator( new RuleFactory(), $messages ) )->validate( $form );
}
}