PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 2.1.8
JetFormBuilder — Dynamic Blocks Form Builder v2.1.8
3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / includes / blocks / modules / fields-errors / error-handler.php
jetformbuilder / includes / blocks / modules / fields-errors Last commit date
base-field-error.php 3 years ago checkboxes-field-error.php 3 years ago error-handler.php 3 years ago media-field-error.php 3 years ago number-field-error.php 3 years ago repeater-field-error.php 3 years ago text-field-error.php 3 years ago textarea-field-error.php 3 years ago wysiwyg-field-error.php 3 years ago
error-handler.php
124 lines
1 <?php
2
3
4 namespace Jet_Form_Builder\Blocks\Modules\Fields_Errors;
5
6 use Jet_Form_Builder\Classes\Tools;
7
8 class Error_Handler {
9
10 private static $instance = null;
11
12 private $_types = array();
13 private $_errors = array();
14
15 private function register_field_types() {
16
17 $types = array(
18 new Text_Field_Error(),
19 new Textarea_Field_Error(),
20 new Number_Field_Error(),
21 new Checkboxes_Field_Error(),
22 new Media_Field_Error(),
23 new Wysiwyg_Field_Error(),
24 new Repeater_Field_Error(),
25 );
26
27 foreach ( $types as $type ) {
28 $this->register_field_type( $type );
29 }
30
31 do_action( 'jet-form-builder/fields-errors/register', $this );
32
33 }
34
35 private function maybe_set_errors() {
36 if ( empty( $_REQUEST ) || ! isset( $_REQUEST['fields'] ) ) {
37 return;
38 }
39 $request = stripslashes( Tools::sanitize_recursive( $_REQUEST['fields'] ) );
40
41 if ( is_array( json_decode( $request, true ) ) && json_last_error() == JSON_ERROR_NONE ) {
42
43 $this->_errors = json_decode( $request, true );
44 }
45 }
46
47 public function register_field_type( $field ) {
48 if ( $field instanceof Base_Field_Error ) {
49 $this->_types[ $field->get_name() ] = $field;
50 }
51 }
52
53
54 /**
55 * Instance.
56 *
57 * Ensures only one instance of the plugin class is loaded or can be loaded.
58 *
59 * @return Error_Handler An instance of the class.
60 * @since 1.0.0
61 * @access public
62 * @static
63 */
64 public static function instance() {
65
66 if ( is_null( self::$instance ) ) {
67 self::$instance = new self();
68 }
69
70 return self::$instance;
71 }
72
73 private function __construct() {
74 $this->register_field_types();
75 $this->maybe_set_errors();
76 }
77
78
79 public function add( $type, $args ) {
80 if ( ! isset( $this->_types[ $type ] ) ) {
81 return false;
82 }
83 $field = $this->_types[ $type ];
84
85 $arguments = array_merge(
86 array(
87 'name' => 'field_name',
88 'message' => false,
89 'params' => array(),
90 ),
91 $args
92 );
93
94 $field->set_params( $arguments );
95
96 $message = $arguments['message'] ? $arguments['message'] : $field->error();
97
98 $this->_errors[ $arguments['name'] ] = array(
99 'message' => $message,
100 );
101
102 return true;
103 }
104
105 public function empty_errors() {
106 return empty( $this->_errors );
107 }
108
109 public function has_error_by_name( $name ) {
110 return isset( $this->_errors[ $name ] );
111 }
112
113 public function error_by_name( $name ) {
114 if ( isset( $this->_errors[ $name ]['message'] ) ) {
115 return $this->_errors[ $name ]['message'];
116 }
117 }
118
119 public function errors() {
120 return $this->_errors;
121 }
122
123 }
124