PluginProbe
JetFormBuilder — Dynamic Blocks Form Builder / 3.6.4
JetFormBuilder — Dynamic Blocks Form Builder v3.6.4
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 1.1.2 1.1.3 1.1.4 1.1.5 All 130 releases
jetformbuilder / includes / form-response / response.php
response.php
72 lines 1.4 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_Response;
5
6 use Jet_Form_Builder\Form_Response\Types\Response_It;
7
8 // If this file is called directly, abort.
9 if ( ! defined( 'WPINC' ) ) {
10 die;
11 }
12
13 class Response {
14
15 public $manager;
16 private $query_args = array();
17 public $args = array();
18
19 public $default_args = array(
20 'status' => 'success',
21 'errors' => array(),
22 );
23
24 public function __construct( Response_It $instance, $query_args = array() ) {
25 $this->manager = $instance;
26 $this->add_query_args( $query_args );
27 }
28
29 public function send() {
30 $this->manager->send(
31 apply_filters( 'jet-fb/response-handler/query-args', $this->query_args, $this )
32 );
33 }
34
35 private function init_query_args() {
36 $this->add_query_args(
37 array( 'status' => $this->manager->parse_status( $this->args['status'] ) )
38 );
39 }
40
41 public function init( array $args ) {
42 $this->args = wp_parse_args( $args, $this->default_args );
43
44 $this->init_query_args();
45 $this->call_on_status();
46
47 return $this;
48 }
49
50 private function call_on_status() {
51 $callable = array( $this, 'on_' . $this->args['status'] );
52
53 if ( is_callable( $callable ) ) {
54 call_user_func( $callable );
55 }
56 }
57
58 private function add_query_args( $args ) {
59 $this->query_args = array_merge( $this->query_args, $args );
60 }
61
62 public function on_validation_failed() {
63 $this->add_query_args(
64 array(
65 'fields' => $this->manager->get_field_errors( $this->args['errors'] ),
66 )
67 );
68 }
69
70
71 }
72