-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmihdan-form-validator.php
118 lines (101 loc) · 3.21 KB
/
mihdan-form-validator.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
/**
* Plugin Name: Mihdan: Form Validate
* Plugin URI: https://www.kobzarev.com/
* Description: With this feature rich jQuery plugin it becomes easy to validate user input while keeping your HTML markup clean from javascript code. Even though this plugin has a wide range of validation functions it's designed to require as little bandwidth as possible. This is achieved by grouping together validation functions in "modules", making it possible for the programmer to load only those functions that's needed to validate a particular form.
* Version: 1.0.0
* Author: Mikhail Kobzarev
* Author URI: https://www.kobzarev.com/
*
* GitHub Plugin URI: https://github.com/mihdan/mihdan-form-validator
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'Mihdan_Form_Validator' ) ) {
/**
* Class Mihdan_Form_Validator
*/
final class Mihdan_Form_Validator {
const SLUG = 'mihdan_form_validator';
/**
* Путь к плагину
*
* @var string
*/
public static $dir_path;
/**
* URL до плагина
*
* @var string
*/
public static $dir_uri;
/**
* Хранит экземпляр класса
*
* @var $instance
*/
private static $instance;
/**
* Вернуть единственный экземпляр класса
*
* @return Mihdan_Form_Validator
*/
public static function get_instance() {
if ( is_null( self::$instance ) ) {
self::$instance = new self;
}
return self::$instance;
}
/**
* Инициализируем нужные методы
*
* Mihdan_Form_Validator constructor.
*/
private function __construct() {
$this->setup();
$this->includes();
$this->hooks();
}
/**
* Установка основных переменных плагина
*/
private function setup() {
self::$dir_path = apply_filters( 'mihdan_form_validator_dir_path', trailingslashit( plugin_dir_path( __FILE__ ) ) );
self::$dir_uri = apply_filters( 'mihdan_form_validator_dir_uri', trailingslashit( plugin_dir_url( __FILE__ ) ) );
}
/**
* Подключаем зависимости
*/
private function includes() {}
/**
* Хукаем.
*/
private function hooks() {
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
}
/**
* Регистрируем скрипты
*/
public function enqueue_scripts() {
wp_register_script( self::SLUG, self::$dir_uri . 'vendor/form-validator/form-validator/jquery.form-validator.js', array( 'jquery' ), null, true );
$config = apply_filters( self::SLUG . '_config', array(
'modules' => 'toggleDisabled,security',
'lang' => 'ru',
'validateOnBlur' => 'true',
'validateHiddenInputs' => 'true',
'errorMessagePosition' => 'inline',
'disabledFormFilter' => 'form:not([novalidate])',
'addValidClassOnAll' => 'true',
) );
wp_enqueue_script( self::SLUG );
wp_localize_script( self::SLUG, self::SLUG . '_config', $config );
wp_add_inline_script( self::SLUG, 'jQuery(function($){ jQuery.validate( ' . self::SLUG . '_config ); });' );
}
}
function Mihdan_Form_Validator() {
return Mihdan_Form_Validator::get_instance();
}
$GLOBALS['mihdan_form_validator'] = Mihdan_Form_Validator();
}
// eof