PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 1.2.5
JetFormBuilder — Dynamic Blocks Form Builder v1.2.5
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 4 years ago checkboxes-field-error.php 4 years ago error-handler.php 4 years ago media-field-error.php 4 years ago number-field-error.php 4 years ago repeater-field-error.php 4 years ago text-field-error.php 4 years ago textarea-field-error.php 4 years ago wysiwyg-field-error.php 4 years ago
error-handler.php
121 lines
1 <?php
2
3
4 namespace Jet_Form_Builder\Blocks\Modules\Fields_Errors;
5
6
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( $_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 */
65 public static function instance() {
66
67 if ( is_null( self::$instance ) ) {
68 self::$instance = new self();
69 }
70
71 return self::$instance;
72 }
73
74 private function __construct() {
75 $this->register_field_types();
76 $this->maybe_set_errors();
77 }
78
79
80 public function add( $type, $args ) {
81 if ( ! isset( $this->_types[ $type ] ) ) {
82 return false;
83 }
84 $field = $this->_types[ $type ];
85
86 $arguments = array_merge( array(
87 'name' => 'field_name',
88 'message' => false,
89 'params' => array()
90 ), $args );
91
92 $field->set_params( $arguments );
93
94 $message = $arguments['message'] ? $arguments['message'] : $field->error();
95
96 $this->_errors[ $arguments['name'] ] = array(
97 'message' => $message
98 );
99
100 return true;
101 }
102
103 public function empty_errors() {
104 return empty( $this->_errors );
105 }
106
107 public function has_error_by_name( $name ) {
108 return isset( $this->_errors[ $name ] );
109 }
110
111 public function error_by_name( $name ) {
112 if ( isset( $this->_errors[ $name ]['message'] ) ) {
113 return $this->_errors[ $name ]['message'];
114 }
115 }
116
117 public function errors() {
118 return $this->_errors;
119 }
120
121 }