PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 3.06.06
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v3.06.06
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/models/FrmFieldValue.php +36 -91 6.273.06.06 View file →
@@ -1,8 +1,5 @@
1 1 <?php
2 -if ( ! defined( 'ABSPATH' ) ) {
3 - die( 'You are not allowed to call this page directly.' );
4 -}
5 2
6 3 /**
7 4 * @since 2.04
8 5 */
@@ -10,20 +7,13 @@
10 7
11 8 /**
12 9 * @since 2.04
13 10 *
14 - * @var stdClass|null
11 + * @var stdClass
15 12 */
16 - protected $field;
13 + protected $field = null;
17 14
18 15 /**
19 - * @since 4.03
20 - *
21 - * @var object
22 - */
23 - protected $entry;
24 -
25 - /**
26 16 * @since 2.04
27 17 *
28 18 * @var int
29 19 */
@@ -53,39 +43,24 @@
53 43 if ( ! is_object( $field ) || ! is_object( $entry ) || ! isset( $entry->metas ) ) {
54 44 return;
55 45 }
56 46
57 - $this->entry = $entry;
58 47 $this->entry_id = $entry->id;
59 - $field = apply_filters( 'frm_field_value_object', $field );
60 - $this->field = $field;
48 + $this->field = $field;
61 49 $this->init_saved_value( $entry );
62 50 }
63 51
64 52 /**
65 - * Gets entry property.
66 - *
67 - * @since 5.0.16
68 - *
69 - * @return stdClass
70 - */
71 - public function get_entry() {
72 - return $this->entry;
73 - }
74 -
75 - /**
76 53 * Initialize the saved_value property
77 54 *
78 55 * @since 2.04
79 56 *
80 57 * @param stdClass $entry
81 - *
82 - * @return void
83 58 */
84 59 protected function init_saved_value( $entry ) {
85 60 if ( $this->field->type === 'html' ) {
86 61 $this->saved_value = $this->field->description;
87 - } elseif ( isset( $entry->metas[ $this->field->id ] ) ) {
62 + } else if ( isset( $entry->metas[ $this->field->id ] ) ) {
88 63 $this->saved_value = $entry->metas[ $this->field->id ];
89 64 } else {
90 65 $this->saved_value = '';
91 66 }
@@ -98,15 +73,11 @@
98 73 *
99 74 * @since 2.05
100 75 *
101 76 * @param array $atts
102 - *
103 - * @return void
104 77 */
105 78 public function prepare_displayed_value( $atts = array() ) {
106 79 $this->displayed_value = $this->saved_value;
107 - // This class shouldn't affect values.
108 - unset( $atts['class'] );
109 80 $this->generate_displayed_value_for_field_type( $atts );
110 81 $this->filter_displayed_value( $atts );
111 82 }
112 83
@@ -113,12 +84,8 @@
113 84 /**
114 85 * Get a value from the field settings
115 86 *
116 87 * @since 2.05.06
117 - *
118 - * @param string $value
119 - *
120 - * @return mixed
121 88 */
122 89 public function get_field_option( $value ) {
123 90 return FrmField::get_option( $this->field, $value );
124 91 }
@@ -123,36 +90,14 @@
123 90 return FrmField::get_option( $this->field, $value );
124 91 }
125 92
126 93 /**
127 - * @since 4.03
128 - *
129 - * @param string $option
130 - *
131 - * @return mixed
132 - */
133 - public function get_field_attr( $option ) {
134 - return is_object( $this->field ) ? $this->field->{$option} : '';
135 - }
136 -
137 - /**
138 - * @since 4.03
139 - *
140 - * @return stdClass
141 - */
142 - public function get_field() {
143 - return $this->field;
144 - }
145 -
146 - /**
147 94 * Get the field property's label
148 95 *
149 96 * @since 2.04
150 - *
151 - * @return string
152 97 */
153 98 public function get_field_label() {
154 - return $this->get_field_attr( 'name' );
99 + return $this->field->name;
155 100 }
156 101
157 102 /**
158 103 * Get the field property's id
@@ -157,13 +102,11 @@
157 102 /**
158 103 * Get the field property's id
159 104 *
160 105 * @since 2.05
161 - *
162 - * @return string
163 106 */
164 107 public function get_field_id() {
165 - return $this->get_field_attr( 'id' );
108 + return $this->field->id;
166 109 }
167 110
168 111 /**
169 112 * Get the field property's key
@@ -168,13 +111,11 @@
168 111 /**
169 112 * Get the field property's key
170 113 *
171 114 * @since 2.04
172 - *
173 - * @return string
174 115 */
175 116 public function get_field_key() {
176 - return $this->get_field_attr( 'field_key' );
117 + return $this->field->field_key;
177 118 }
178 119
179 120 /**
180 121 * Get the field property's type
@@ -179,13 +120,11 @@
179 120 /**
180 121 * Get the field property's type
181 122 *
182 123 * @since 2.04
183 - *
184 - * @return string
185 124 */
186 125 public function get_field_type() {
187 - return $this->get_field_attr( 'type' );
126 + return $this->field->type;
188 127 }
189 128
190 129 /**
191 130 * Get the saved_value property
@@ -190,10 +129,8 @@
190 129 /**
191 130 * Get the saved_value property
192 131 *
193 132 * @since 2.04
194 - *
195 - * @return mixed
196 133 */
197 134 public function get_saved_value() {
198 135 return $this->saved_value;
199 136 }
@@ -201,10 +138,8 @@
201 138 /**
202 139 * Get the displayed_value property
203 140 *
204 141 * @since 2.04
205 - *
206 - * @return mixed
207 142 */
208 143 public function get_displayed_value() {
209 144 if ( $this->displayed_value === 'frm_not_prepared' ) {
210 145 return __( 'The display value has not been prepared. Please use the prepare_display_value() method before calling get_displayed_value().', 'formidable' );
@@ -219,13 +154,13 @@
219 154 * @since 3.0
220 155 *
221 156 * @param array $atts
222 157 *
223 - * @return void
158 + * @return mixed
224 159 */
225 160 protected function generate_displayed_value_for_field_type( $atts ) {
226 161 if ( ! FrmAppHelper::is_empty_value( $this->displayed_value, '' ) ) {
227 - $field_obj = FrmFieldFactory::get_field_object( $this->field );
162 + $field_obj = FrmFieldFactory::get_field_object( $this->field );
228 163 $this->displayed_value = $field_obj->get_display_value( $this->displayed_value, $atts );
229 164 }
230 165 }
231 166
@@ -234,17 +169,33 @@
234 169 *
235 170 * @since 2.04
236 171 *
237 172 * @param array $atts
238 - *
239 - * @return void
240 173 */
241 174 protected function filter_displayed_value( $atts ) {
242 - if ( ! is_object( $this->entry ) || empty( $this->entry->metas ) ) {
243 - $this->entry = FrmEntry::getOne( $this->entry_id, true );
175 + $entry = FrmEntry::getOne( $this->entry_id, true );
244 176
245 - if ( ! is_object( $this->entry ) ) {
246 - return;
177 + // TODO: maybe change from 'source' to 'run_filters' = 'email'
178 + if ( isset( $atts['source'] ) && $atts['source'] === 'entry_formatter' ) {
179 + // Deprecated frm_email_value hook
180 + $meta = array(
181 + 'item_id' => $entry->id,
182 + 'field_id' => $this->field->id,
183 + 'meta_value' => $this->saved_value,
184 + 'field_type' => $this->field->type,
185 + );
186 +
187 + if ( has_filter( 'frm_email_value' ) ) {
188 + _deprecated_function( 'The frm_email_value filter', '2.04', 'the frm_display_{fieldtype}_value_custom filter' );
189 + $this->displayed_value = apply_filters(
190 + 'frm_email_value',
191 + $this->displayed_value,
192 + (object) $meta,
193 + $entry,
194 + array(
195 + 'field' => $this->field,
196 + )
197 + );
247 198 }
248 199 }
249 200
250 201 // frm_display_{fieldtype}_value_custom hook
@@ -252,28 +203,22 @@
252 203 'frm_display_' . $this->field->type . '_value_custom',
253 204 $this->displayed_value,
254 205 array(
255 206 'field' => $this->field,
256 - 'entry' => $this->entry,
207 + 'entry' => $entry,
257 208 )
258 209 );
259 -
260 - $this->displayed_value = apply_filters( 'frm_display_value', $this->displayed_value, $this->field, $atts );
261 210 }
262 211
263 212 /**
264 - * Clean a field's saved value.
213 + * Clean a field's saved value
265 214 *
266 215 * @since 2.04
267 - *
268 - * @return void
269 216 */
270 217 protected function clean_saved_value() {
271 218 if ( $this->saved_value !== '' ) {
272 - if ( ! is_array( $this->saved_value ) && ! is_object( $this->saved_value ) ) {
273 - $field_type = FrmField::get_field_type( $this->field );
274 - FrmFieldsHelper::prepare_field_value( $this->saved_value, $field_type );
275 - }
219 +
220 + $this->saved_value = maybe_unserialize( $this->saved_value );
276 221
277 222 if ( is_array( $this->saved_value ) && empty( $this->saved_value ) ) {
278 223 $this->saved_value = '';
279 224 }