PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 2.1.5
JetFormBuilder — Dynamic Blocks Form Builder v2.1.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 / form-messages / manager.php
jetformbuilder / includes / form-messages Last commit date
builder.php 3 years ago manager.php 3 years ago msg-router.php 3 years ago status-info.php 3 years ago
manager.php
110 lines
1 <?php
2
3
4 namespace Jet_Form_Builder\Form_Messages;
5
6 use Jet_Form_Builder\Plugin;
7
8 class Manager {
9
10 public $_types = array();
11
12 const DYNAMIC_SUCCESS_PREF = 'dsuccess|';
13 const DYNAMIC_FAILED_PREF = 'derror|';
14
15
16 public static function dynamic_success( $message ) {
17 return self::DYNAMIC_SUCCESS_PREF . $message;
18 }
19
20 public static function dynamic_error( $message ) {
21 return self::DYNAMIC_FAILED_PREF . $message;
22 }
23
24 public static function dynamic_types() {
25 return array(
26 'dsuccess' => array(
27 'type' => 'success',
28 ),
29 'derror' => array(
30 'type' => 'failed',
31 ),
32 );
33 }
34
35 /**
36 * @return Manager
37 */
38 public function set_up() {
39 if ( ! jet_form_builder()->msg_router->get_form_id() || $this->get_messages() ) {
40 return $this;
41 }
42
43 $this->_types = array_merge(
44 $this->get_form_types_messages(),
45 $this->get_action_types_messages()
46 );
47
48 return $this;
49 }
50
51 public function get_form_types_messages() {
52 return Plugin::instance()->post_type->get_messages(
53 jet_form_builder()->msg_router->get_form_id()
54 );
55 }
56
57 public function get_action_types_messages() {
58 $messages = array();
59
60 foreach ( jet_form_builder()->msg_router->get_actions() as $action ) {
61 if ( ! isset( $action->messages ) ) {
62 continue;
63 }
64 $default_action_messages = wp_list_pluck( $action->messages, 'value' );
65 $action_messages = isset( $action->settings['messages'] ) ? $action->settings['messages'] : array();
66
67 $messages = array_merge( $messages, $default_action_messages, $action_messages );
68 }
69
70 return $messages;
71 }
72
73 public function isset_message_type( $type ) {
74 return isset( $this->_types[ $type ] );
75 }
76
77
78 public function get_message( $type ): string {
79 $info = new Status_Info( $type );
80
81 /**
82 * Return dynamic message
83 */
84 return $this->get_message_by_info( $info );
85 }
86
87 public function get_message_by_info( Status_Info $info ): string {
88 if ( $info->is_dynamic() ) {
89 return $info->get_message();
90 }
91
92 $status = $info->get_message();
93
94 if ( $this->isset_message_type( $status ) ) {
95 return $this->_types[ $status ]['value'] ?? $this->_types[ $status ];
96 }
97
98 return $info->get_raw_message();
99 }
100
101 public function get_messages() {
102 return $this->_types;
103 }
104
105 public static function parse_message( $status ) {
106 return explode( '|', $status );
107 }
108
109 }
110