PluginProbe
JetFormBuilder — Dynamic Blocks Form Builder / 3.6.5.4
JetFormBuilder — Dynamic Blocks Form Builder v3.6.5.4
3.6.6.1 3.6.6 3.6.5.4 3.6.5.3 3.6.5.2 3.6.5.1 3.6.5 3.6.4.2 3.6.4.1 3.6.4 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 All 134 releases
jetformbuilder / includes / form-messages / msg-router.php

msg-router.php in JetFormBuilder — Dynamic Blocks Form Builder 3.6.5.4, at includes/form-messages/msg-router.php

123 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4 namespace Jet_Form_Builder\Form_Messages;
5
6 // If this file is called directly, abort.
7 if ( ! defined( 'WPINC' ) ) {
8 die;
9 }
10
11 class Msg_Router {
12
13 /** @var Builder */
14 private $builder;
15
16 /** @var Manager */
17 private $manager;
18
19 private $form_id;
20 private $actions;
21
22
23 public function __construct() {
24 $this->builder = new Builder();
25 $this->manager = new Manager();
26 }
27
28 public function get_form_id() {
29 return (int) $this->form_id;
30 }
31
32 public function set_form_id( $form_id ) {
33 if ( ! $form_id || $form_id === $this->get_form_id() ) {
34 return false;
35 }
36 $this->form_id = (int) $form_id;
37
38 return true;
39 }
40
41 public function set_actions( $actions ) {
42 if ( ! $actions || ! is_array( $actions ) ) {
43 return false;
44 }
45 $this->actions = $actions;
46
47 return true;
48 }
49
50 public function get_actions() {
51 return (array) $this->actions;
52 }
53
54
55 public function set_up( $data = false ) {
56 $this->maybe_set_form_id_from_handler( $data['form_id'] ?? false );
57 $this->maybe_set_actions_from_handler( $data['actions'] ?? false );
58
59 return $this;
60 }
61
62 public function maybe_set_form_id_from_handler( $form_id ) {
63 if ( $this->set_form_id( $form_id ) ) {
64 return true;
65 }
66
67 // phpcs:ignore Universal.Operators.DisallowShortTernary.Found
68 return $this->set_form_id( jet_form_builder()->form_handler->form_id ?: false );
69 }
70
71 public function maybe_set_actions_from_handler( $actions ) {
72 if ( $this->set_actions( $actions ) ) {
73 return true;
74 }
75
76 return $this->query_actions_if_empty();
77 }
78
79 public function query_actions() {
80 if ( ! $this->form_id ) {
81 return false;
82 }
83
84 $this->set_actions(
85 jet_fb_action_handler()
86 ->set_form_id( $this->form_id )
87 ->get_all()
88 );
89
90 return true;
91 }
92
93 public function query_actions_if_empty() {
94 if (
95 ( $this->actions && is_array( $this->actions ) ) ||
96 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
97 empty( $_GET['status'] ?? '' )
98 ) {
99 return true;
100 }
101
102 return $this->query_actions();
103 }
104
105 /**
106 * @param $data
107 *
108 * @return Builder
109 */
110 public function get_builder( $data = array() ) {
111 $this->set_up( $data );
112
113 return $this->builder;
114 }
115
116 public function get_manager( $data = array() ) {
117 $this->set_up( $data );
118
119 return $this->manager->set_up();
120 }
121
122 }
123