PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.0.8
JetFormBuilder — Dynamic Blocks Form Builder v3.0.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 / ssr-validation / validation-callbacks.php
jetformbuilder / includes / blocks / ssr-validation Last commit date
base-validation-callback.php 3 years ago is-user-email-unique.php 3 years ago is-user-login-unique.php 3 years ago rest-controller.php 3 years ago rest-validation-endpoint.php 3 years ago validation-callbacks.php 3 years ago
validation-callbacks.php
98 lines
1 <?php
2
3
4 namespace Jet_Form_Builder\Blocks\Ssr_Validation;
5
6
7 use Jet_Form_Builder\Blocks\Block_Helper;
8 use Jet_Form_Builder\Classes\Repository\Repository_Pattern_Trait;
9 use Jet_Form_Builder\Exceptions\Repository_Exception;
10 use Jet_Form_Builder\Request\Parser_Context;
11 use JET_SM\Gutenberg\Block_Manager;
12
13 class Validation_Callbacks {
14
15 use Repository_Pattern_Trait;
16
17 public function __construct() {
18 $this->rep_install();
19 }
20
21 public function rep_instances(): array {
22 return apply_filters(
23 'jet-form-builder/validation-callbacks',
24 array(
25 new Is_User_Login_Unique(),
26 new Is_User_Email_Unique(),
27 )
28 );
29 }
30
31 /**
32 * @return Base_Validation_Callback[]
33 */
34 public function get_items(): array {
35 return $this->rep_get_items();
36 }
37
38
39 public function validate( $value, string $function_name, Parser_Context $context ): bool {
40 try {
41 /** @var Base_Validation_Callback $callback */
42 $callback = $this->rep_get_item( $function_name );
43 } catch ( Repository_Exception $exception ) {
44 return $this->validate_custom( $value, $function_name, $context );
45 }
46
47 return $callback->is_valid( $value, $context );
48 }
49
50 protected function validate_custom( $value, string $function_name, Parser_Context $context ): bool {
51 $name = $this->validate_callback( $function_name, $context );
52
53 if ( ! $name ) {
54 return false;
55 }
56
57 return (bool) call_user_func( $name, $value, $context );
58 }
59
60 protected function validate_callback( string $function_name, Parser_Context $context ): string {
61 $name = preg_replace( '/[^\w]/i', '', $function_name );
62 $form_id = jet_fb_handler()->get_form_id();
63
64 if ( ! function_exists( $name ) || ! $form_id ) {
65 return '';
66 }
67
68 $all_blocks = Block_Helper::get_blocks_by_post( $form_id );
69
70 $block = Block_Helper::find_block(
71 function ( $block ) use ( $name, $context ) {
72 if (
73 empty( $block['attrs']['validation']['rules'] ) ||
74 empty( $block['attrs']['name'] ) ||
75 $block['attrs']['name'] !== $context->get_name()
76 ) {
77 return false;
78 }
79
80 foreach ( $block['attrs']['validation']['rules'] as $rule ) {
81 if (
82 'ssr' !== ( $rule['type'] ?? '' ) ||
83 $name !== ( $rule['value'] ?? '' )
84 ) {
85 continue;
86 }
87
88 return true;
89 }
90
91 return false;
92 },
93 $all_blocks
94 );
95
96 return empty( $block ) ? '' : $function_name;
97 }
98 }