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/FrmEntryValues.php +38 -102 6.295.0 View file →
@@ -8,11 +8,11 @@
8 8 */
9 9 class FrmEntryValues {
10 10
11 11 /**
12 - * @var false|stdClass|null
12 + * @var stdClass
13 13 */
14 - protected $entry;
14 + protected $entry = null;
15 15
16 16 /**
17 17 * @var int
18 18 */
@@ -48,9 +48,9 @@
48 48 *
49 49 * @since 2.04
50 50 *
51 51 * @param int|string $entry_id
52 - * @param array $atts
52 + * @param array $atts
53 53 */
54 54 public function __construct( $entry_id, $atts = array() ) {
55 55 if ( isset( $atts['entry'] ) && is_object( $atts['entry'] ) && ! empty( $atts['entry']->metas ) ) {
56 56 $this->entry = $atts['entry'];
@@ -75,10 +75,8 @@
75 75 *
76 76 * @since 2.04
77 77 *
78 78 * @param int|string $entry_id
79 - *
80 - * @return void
81 79 */
82 80 protected function init_entry( $entry_id ) {
83 81 $this->entry = FrmEntry::getOne( $entry_id, true );
84 82 }
@@ -83,24 +81,11 @@
83 81 $this->entry = FrmEntry::getOne( $entry_id, true );
84 82 }
85 83
86 84 /**
87 - * Gets entry property.
88 - *
89 - * @since 5.0.16
90 - *
91 - * @return stdClass
92 - */
93 - public function get_entry() {
94 - return $this->entry;
95 - }
96 -
97 - /**
98 85 * Set the form_id property
99 86 *
100 87 * @since 2.04
101 - *
102 - * @return void
103 88 */
104 89 protected function init_form_id() {
105 90 $this->form_id = (int) $this->entry->form_id;
106 91 }
@@ -110,38 +95,31 @@
110 95 *
111 96 * @since 2.04
112 97 *
113 98 * @param array $atts
114 - *
115 - * @return void
116 99 */
117 100 protected function init_include_fields( $atts ) {
118 - // For reverse compatibility with the fields parameter.
119 - if ( empty( $atts['include_fields'] ) && ! empty( $atts['fields'] ) ) {
120 - if ( is_array( $atts['fields'] ) ) {
121 - $atts['include_fields'] = '';
122 101
123 - foreach ( $atts['fields'] as $included_field ) {
124 - $atts['include_fields'] .= $included_field->id . ',';
102 + // For reverse compatibility with the fields parameter
103 + if ( ! isset( $atts['include_fields'] ) || empty( $atts['include_fields'] ) ) {
104 +
105 + if ( isset( $atts['fields'] ) && ! empty( $atts['fields'] ) ) {
106 +
107 + if ( ! is_array( $atts['fields'] ) ) {
108 + $atts['include_fields'] = $atts['fields'];
109 + } else {
110 + $atts['include_fields'] = '';
111 +
112 + foreach ( $atts['fields'] as $included_field ) {
113 + $atts['include_fields'] .= $included_field->id . ',';
114 + }
115 +
116 + $atts['include_fields'] = rtrim( $atts['include_fields'], ',' );
125 117 }
126 -
127 - $atts['include_fields'] = rtrim( $atts['include_fields'], ',' );
128 - } else {
129 - $atts['include_fields'] = $atts['fields'];
130 118 }
131 119 }
132 120
133 121 $this->include_fields = $this->prepare_array_property( 'include_fields', $atts );
134 -
135 - /**
136 - * Allows modifying the IDs of include_fields used in the entry values.
137 - *
138 - * @since 5.0.04
139 - *
140 - * @param array $field_ids The list of field IDs.
141 - * @param array $atts The arguments. See {@see FrmEntriesController::show_entry_shortcode()}.
142 - */
143 - $this->include_fields = apply_filters( 'frm_entry_values_include_fields', $this->include_fields, $atts );
144 122 }
145 123
146 124 /**
147 125 * Set the exclude_fields property
@@ -148,23 +126,11 @@
148 126 *
149 127 * @since 2.04
150 128 *
151 129 * @param array $atts
152 - *
153 - * @return void
154 130 */
155 131 protected function init_exclude_fields( $atts ) {
156 132 $this->exclude_fields = $this->prepare_array_property( 'exclude_fields', $atts );
157 -
158 - /**
159 - * Allows modifying the IDs of exclude_fields used in the entry values.
160 - *
161 - * @since 5.0.04
162 - *
163 - * @param array $field_ids The list of field IDs.
164 - * @param array $atts The arguments. See {@see FrmEntriesController::show_entry_shortcode()}.
165 - */
166 - $this->exclude_fields = apply_filters( 'frm_entry_values_exclude_fields', $this->exclude_fields, $atts );
167 133 }
168 134
169 135 /**
170 136 * Prepare an array property value, such as include_fields and exclude_fields
@@ -171,18 +137,25 @@
171 137 *
172 138 * @since 2.04
173 139 *
174 140 * @param string $index
175 - * @param array $atts
141 + * @param array $atts
176 142 *
177 143 * @return array
178 144 */
179 145 private function prepare_array_property( $index, $atts ) {
180 - if ( ! empty( $atts[ $index ] ) ) {
181 - return is_array( $atts[ $index ] ) ? $atts[ $index ] : explode( ',', $atts[ $index ] );
146 + if ( isset( $atts[ $index ] ) && ! empty( $atts[ $index ] ) ) {
147 +
148 + if ( is_array( $atts[ $index ] ) ) {
149 + $property = $atts[ $index ];
150 + } else {
151 + $property = explode( ',', $atts[ $index ] );
152 + }
153 + } else {
154 + $property = array();
182 155 }
183 156
184 - return array();
157 + return $property;
185 158 }
186 159
187 160 /**
188 161 * Set the fields property
@@ -187,30 +160,11 @@
187 160 /**
188 161 * Set the fields property
189 162 *
190 163 * @since 2.04
191 - *
192 - * @return void
193 164 */
194 165 protected function init_fields() {
195 166 $this->fields = FrmField::get_all_for_form( $this->form_id, '', 'exclude', 'exclude' );
196 -
197 - /**
198 - * Allows modifying the list of all field in the form that is used in the entry values.
199 - *
200 - * @since 5.0.04
201 - *
202 - * @param array $fields The list of fields.
203 - * @param array $args The arguments. Contains `form_id`, `entry`.
204 - */
205 - $this->fields = apply_filters(
206 - 'frm_entry_values_fields',
207 - $this->fields,
208 - array(
209 - 'form_id' => $this->form_id,
210 - 'entry' => $this->entry,
211 - )
212 - );
213 167 }
214 168
215 169 /**
216 170 * Set the field_values property
@@ -215,10 +169,8 @@
215 169 /**
216 170 * Set the field_values property
217 171 *
218 172 * @since 2.04
219 - *
220 - * @return void
221 173 */
222 174 protected function init_field_values() {
223 175 foreach ( $this->fields as $field ) {
224 176 if ( $this->is_field_included( $field ) ) {
@@ -241,10 +193,8 @@
241 193 /**
242 194 * Set the user_info property
243 195 *
244 196 * @since 2.04
245 - *
246 - * @return void
247 197 */
248 198 protected function init_user_info() {
249 199 if ( isset( $this->entry->description ) ) {
250 200 $entry_description = (array) $this->entry->description;
@@ -254,32 +204,23 @@
254 204 'referrer' => '',
255 205 );
256 206 }
257 207
258 - $ip = array(
208 + $ip = array(
259 209 'label' => __( 'IP Address', 'formidable' ),
260 210 'value' => $this->entry->ip,
261 211 );
262 - $browser = array(
212 +
213 + $browser = array(
263 214 'label' => __( 'User-Agent (Browser/OS)', 'formidable' ),
264 - 'value' => isset( $entry_description['browser'] ) ? FrmEntriesHelper::get_browser( $entry_description['browser'] ) : '',
215 + 'value' => FrmEntriesHelper::get_browser( $entry_description['browser'] ),
265 216 );
217 +
266 218 $referrer = array(
267 219 'label' => __( 'Referrer', 'formidable' ),
268 - 'value' => $entry_description['referrer'] ?? '',
220 + 'value' => $entry_description['referrer'],
269 221 );
270 222
271 - /**
272 - * Allow the referrer to be modified.
273 - *
274 - * @since 5.5.1
275 - *
276 - * @param array $referrer
277 - * @param array $entry_description
278 - * @param object $entry
279 - */
280 - $referrer = apply_filters( 'frm_user_info_referrer', $referrer, $entry_description, $this->entry );
281 -
282 223 $this->user_info = array(
283 224 'ip' => $ip,
284 225 'browser' => $browser,
285 226 'referrer' => $referrer,
@@ -307,16 +248,14 @@
307 248 * @return bool
308 249 */
309 250 protected function is_field_included( $field ) {
310 251 $is_included = true;
311 -
312 - if ( $this->include_fields ) {
252 + if ( ! empty( $this->include_fields ) ) {
313 253 $is_included = $this->is_field_in_array( $field, $this->include_fields );
314 254 }
315 255
316 - if ( $this->exclude_fields ) {
256 + if ( ! empty( $this->exclude_fields ) ) {
317 257 $is_excluded = $this->is_field_in_array( $field, $this->exclude_fields );
318 -
319 258 if ( $is_excluded ) {
320 259 $is_included = false;
321 260 }
322 261 }
@@ -329,14 +268,13 @@
329 268 *
330 269 * @since 2.04
331 270 *
332 271 * @param stdClass $field
333 - * @param array $array
272 + * @param array $array
334 273 *
335 274 * @return bool
336 275 */
337 276 protected function is_field_in_array( $field, $array ) {
338 - // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
339 277 return in_array( $field->id, $array ) || in_array( (string) $field->field_key, $array, true );
340 278 }
341 279
342 280 /**
@@ -344,10 +282,8 @@
344 282 *
345 283 * @since 2.04
346 284 *
347 285 * @param stdClass $field
348 - *
349 - * @return void
350 286 */
351 287 protected function add_field_values( $field ) {
352 288 $this->field_values[ $field->id ] = new FrmFieldValue( $field, $this->entry );
353 289 }