PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.0
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.0
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 +41 -64 6.295.0 View file →
@@ -10,11 +10,11 @@
10 10
11 11 /**
12 12 * @since 2.04
13 13 *
14 - * @var stdClass|null
14 + * @var stdClass
15 15 */
16 - protected $field;
16 + protected $field = null;
17 17
18 18 /**
19 19 * @since 4.03
20 20 *
@@ -55,32 +55,19 @@
55 55 }
56 56
57 57 $this->entry = $entry;
58 58 $this->entry_id = $entry->id;
59 - $field = apply_filters( 'frm_field_value_object', $field );
59 + $field = apply_filters( 'frm_field_value_object', $field );
60 60 $this->field = $field;
61 61 $this->init_saved_value( $entry );
62 62 }
63 63
64 64 /**
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 65 * Initialize the saved_value property
77 66 *
78 67 * @since 2.04
79 68 *
80 69 * @param stdClass $entry
81 - *
82 - * @return void
83 70 */
84 71 protected function init_saved_value( $entry ) {
85 72 if ( $this->field->type === 'html' ) {
86 73 $this->saved_value = $this->field->description;
@@ -98,15 +85,12 @@
98 85 *
99 86 * @since 2.05
100 87 *
101 88 * @param array $atts
102 - *
103 - * @return void
104 89 */
105 90 public function prepare_displayed_value( $atts = array() ) {
106 91 $this->displayed_value = $this->saved_value;
107 - // This class shouldn't affect values.
108 - unset( $atts['class'] );
92 + unset( $atts['class'] ); // This class shouldn't affect values.
109 93 $this->generate_displayed_value_for_field_type( $atts );
110 94 $this->filter_displayed_value( $atts );
111 95 }
112 96
@@ -113,12 +97,8 @@
113 97 /**
114 98 * Get a value from the field settings
115 99 *
116 100 * @since 2.05.06
117 - *
118 - * @param string $value
119 - *
120 - * @return mixed
121 101 */
122 102 public function get_field_option( $value ) {
123 103 return FrmField::get_option( $this->field, $value );
124 104 }
@@ -124,12 +104,8 @@
124 104 }
125 105
126 106 /**
127 107 * @since 4.03
128 - *
129 - * @param string $option
130 - *
131 - * @return mixed
132 108 */
133 109 public function get_field_attr( $option ) {
134 110 return is_object( $this->field ) ? $this->field->{$option} : '';
135 111 }
@@ -135,10 +111,8 @@
135 111 }
136 112
137 113 /**
138 114 * @since 4.03
139 - *
140 - * @return stdClass
141 115 */
142 116 public function get_field() {
143 117 return $this->field;
144 118 }
@@ -146,10 +120,8 @@
146 120 /**
147 121 * Get the field property's label
148 122 *
149 123 * @since 2.04
150 - *
151 - * @return string
152 124 */
153 125 public function get_field_label() {
154 126 return $this->get_field_attr( 'name' );
155 127 }
@@ -157,10 +129,8 @@
157 129 /**
158 130 * Get the field property's id
159 131 *
160 132 * @since 2.05
161 - *
162 - * @return string
163 133 */
164 134 public function get_field_id() {
165 135 return $this->get_field_attr( 'id' );
166 136 }
@@ -168,10 +138,8 @@
168 138 /**
169 139 * Get the field property's key
170 140 *
171 141 * @since 2.04
172 - *
173 - * @return string
174 142 */
175 143 public function get_field_key() {
176 144 return $this->get_field_attr( 'field_key' );
177 145 }
@@ -179,10 +147,8 @@
179 147 /**
180 148 * Get the field property's type
181 149 *
182 150 * @since 2.04
183 - *
184 - * @return string
185 151 */
186 152 public function get_field_type() {
187 153 return $this->get_field_attr( 'type' );
188 154 }
@@ -190,10 +156,8 @@
190 156 /**
191 157 * Get the saved_value property
192 158 *
193 159 * @since 2.04
194 - *
195 - * @return mixed
196 160 */
197 161 public function get_saved_value() {
198 162 return $this->saved_value;
199 163 }
@@ -201,10 +165,8 @@
201 165 /**
202 166 * Get the displayed_value property
203 167 *
204 168 * @since 2.04
205 - *
206 - * @return mixed
207 169 */
208 170 public function get_displayed_value() {
209 171 if ( $this->displayed_value === 'frm_not_prepared' ) {
210 172 return __( 'The display value has not been prepared. Please use the prepare_display_value() method before calling get_displayed_value().', 'formidable' );
@@ -219,17 +181,16 @@
219 181 * @since 3.0
220 182 *
221 183 * @param array $atts
222 184 *
223 - * @return void
185 + * @return mixed
224 186 */
225 187 protected function generate_displayed_value_for_field_type( $atts ) {
226 - if ( FrmAppHelper::is_empty_value( $this->displayed_value, '' ) ) {
227 - return;
188 + if ( ! FrmAppHelper::is_empty_value( $this->displayed_value, '' ) ) {
189 + $field_obj = FrmFieldFactory::get_field_object( $this->field );
190 +
191 + $this->displayed_value = $field_obj->get_display_value( $this->displayed_value, $atts );
228 192 }
229 -
230 - $field_obj = FrmFieldFactory::get_field_object( $this->field );
231 - $this->displayed_value = $field_obj->get_display_value( $this->displayed_value, $atts );
232 193 }
233 194
234 195 /**
235 196 * Filter the displayed_value property
@@ -236,20 +197,41 @@
236 197 *
237 198 * @since 2.04
238 199 *
239 200 * @param array $atts
240 - *
241 - * @return void
242 201 */
243 202 protected function filter_displayed_value( $atts ) {
244 203 if ( ! is_object( $this->entry ) || empty( $this->entry->metas ) ) {
245 204 $this->entry = FrmEntry::getOne( $this->entry_id, true );
246 -
247 205 if ( ! is_object( $this->entry ) ) {
248 206 return;
249 207 }
250 208 }
251 209
210 + // TODO: maybe change from 'source' to 'run_filters' = 'email'
211 + if ( isset( $atts['source'] ) && $atts['source'] === 'entry_formatter' ) {
212 + // Deprecated frm_email_value hook
213 + $meta = array(
214 + 'item_id' => $this->entry->id,
215 + 'field_id' => $this->field->id,
216 + 'meta_value' => $this->saved_value,
217 + 'field_type' => $this->field->type,
218 + );
219 +
220 + if ( has_filter( 'frm_email_value' ) ) {
221 + _deprecated_function( 'The frm_email_value filter', '2.04', 'the frm_display_{fieldtype}_value_custom filter' );
222 + $this->displayed_value = apply_filters(
223 + 'frm_email_value',
224 + $this->displayed_value,
225 + (object) $meta,
226 + $this->entry,
227 + array(
228 + 'field' => $this->field,
229 + )
230 + );
231 + }
232 + }
233 +
252 234 // frm_display_{fieldtype}_value_custom hook
253 235 $this->displayed_value = apply_filters(
254 236 'frm_display_' . $this->field->type . '_value_custom',
255 237 $this->displayed_value,
@@ -262,25 +244,20 @@
262 244 $this->displayed_value = apply_filters( 'frm_display_value', $this->displayed_value, $this->field, $atts );
263 245 }
264 246
265 247 /**
266 - * Clean a field's saved value.
248 + * Clean a field's saved value
267 249 *
268 250 * @since 2.04
269 - *
270 - * @return void
271 251 */
272 252 protected function clean_saved_value() {
273 - if ( $this->saved_value === '' ) {
274 - return;
275 - }
253 + if ( $this->saved_value !== '' ) {
254 + if ( ! is_array( $this->saved_value ) && ! is_object( $this->saved_value ) ) {
255 + FrmAppHelper::unserialize_or_decode( $this->saved_value );
256 + }
276 257
277 - if ( ! is_array( $this->saved_value ) && ! is_object( $this->saved_value ) ) {
278 - $field_type = FrmField::get_field_type( $this->field );
279 - FrmFieldsHelper::prepare_field_value( $this->saved_value, $field_type );
280 - }
281 -
282 - if ( is_array( $this->saved_value ) && ! $this->saved_value ) {
283 - $this->saved_value = '';
258 + if ( is_array( $this->saved_value ) && empty( $this->saved_value ) ) {
259 + $this->saved_value = '';
260 + }
284 261 }
285 262 }
286 263 }