PluginProbe
JetFormBuilder — Dynamic Blocks Form Builder / 3.5.6.1
JetFormBuilder — Dynamic Blocks Form Builder v3.5.6.1
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-messages / status-info.php
status-info.php
93 lines 1.8 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 Status_Info {
12
13 private $raw = '';
14 private $is_dynamic;
15 private $is_success;
16 private $parsed;
17
18 public function __construct( string $status ) {
19 $this->raw = $status;
20 }
21
22 /**
23 * @return string
24 */
25 public function get_raw_message(): string {
26 return $this->raw;
27 }
28
29 public function is_dynamic(): bool {
30 if ( is_null( $this->is_dynamic ) ) {
31 $this->set_dynamic_and_success();
32 }
33
34 return $this->is_dynamic;
35 }
36
37 public function is_success(): bool {
38 if ( is_null( $this->is_success ) ) {
39 $this->set_dynamic_and_success();
40 }
41
42 return $this->is_success;
43 }
44
45 public function get_parsed(): array {
46 if ( ! is_array( $this->parsed ) ) {
47 $this->parsed = Manager::parse_message( $this->raw );
48 }
49
50 return $this->parsed;
51 }
52
53 public function get_message(): string {
54 $parsed = $this->get_parsed();
55
56 if ( $this->is_dynamic() ) {
57 return $parsed[1] ?? $parsed[0];
58 }
59
60 return $parsed[0];
61 }
62
63 private function set_dynamic_and_success(): Status_Info {
64 $dynamic = Manager::dynamic_types();
65 $message = $this->get_parsed();
66 $this->is_dynamic = isset( $dynamic[ $message[0] ] ) && ! empty( $message[1] );
67
68 if ( $this->is_dynamic ) {
69 $this->is_success = ( 'success' === ( $dynamic[ $message[0] ]['type'] ?? '' ) );
70 } else {
71 $this->is_success = in_array( $message[0], array( 'success' ), true );
72 }
73
74 do_action( 'jet-form-builder/response-status/init', $this );
75
76 return $this;
77 }
78
79
80 public function get_css_class(): string {
81 return $this->is_success() ? 'success' : 'error';
82 }
83
84 /**
85 * @since 3.2.2
86 * @param bool $is_success
87 */
88 public function set_is_success( bool $is_success ) {
89 $this->is_success = $is_success;
90 }
91
92 }
93