PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.3.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.3.1
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/FrmEntry.php +183 -426 6.325.3.1 View file →
@@ -5,67 +5,45 @@
5 5
6 6 class FrmEntry {
7 7
8 8 /**
9 - * @since 6.16.3
10 - *
11 - * @var array
12 - */
13 - private static $unique_id_match_checks = array();
14 -
15 - /**
16 9 * Create a new entry
17 10 *
18 11 * @param array $values
19 12 *
20 - * @return bool|int Entry ID.
13 + * @return int | boolean $entry_id
21 14 */
22 15 public static function create( $values ) {
23 - return self::create_entry( $values, 'standard' );
16 + $entry_id = self::create_entry( $values, 'standard' );
17 +
18 + return $entry_id;
24 19 }
25 20
26 21 /**
27 22 * Create a new entry with some differences depending on type
28 23 *
29 - * @param array $values
24 + * @param array $values
30 25 * @param string $type
31 26 *
32 - * @return bool|int Entry ID.
27 + * @return int | boolean $entry_id
33 28 */
34 29 private static function create_entry( $values, $type ) {
35 30 $new_values = self::before_insert_entry_in_database( $values, $type );
36 31
37 32 // Don't check XML entries for duplicates
38 - if ( $type !== 'xml' && self::is_duplicate( $new_values, $values ) ) {
33 + if ( $type != 'xml' && self::is_duplicate( $new_values, $values ) ) {
39 34 return false;
40 35 }
41 36
42 - return self::continue_to_create_entry( $values, $new_values );
43 - }
37 + $entry_id = self::continue_to_create_entry( $values, $new_values );
44 38
45 - /**
46 - * Flag the memoized unique id check after a new entry is created.
47 - * This prevents possibly DB requests and helps avoid issues when creating repeater entries.
48 - *
49 - * @since 6.16.3
50 - *
51 - * @param string $unique_id
52 - *
53 - * @return void
54 - */
55 - private static function flag_new_unique_key( $unique_id ) {
56 - if ( ! isset( self::$unique_id_match_checks[ $unique_id ] ) ) {
57 - self::$unique_id_match_checks[ $unique_id ] = false;
58 - }
39 + return $entry_id;
59 40 }
60 41
61 42 /**
62 43 * Check for duplicate entries created in the last minute
63 44 *
64 - * @param array $new_values New values.
65 - * @param array $values Values.
66 - *
67 - * @return bool
45 + * @return boolean
68 46 */
69 47 public static function is_duplicate( $new_values, $values ) {
70 48 $duplicate_entry_time = apply_filters( 'frm_time_to_check_duplicates', 60, $new_values );
71 49
@@ -72,18 +50,13 @@
72 50 if ( false === self::is_duplicate_check_needed( $values, $duplicate_entry_time ) ) {
73 51 return false;
74 52 }
75 53
76 - if ( self::maybe_check_for_unique_id_match( $values, $new_values['created_at'] ) ) {
77 - return true;
78 - }
79 -
80 54 $check_val = $new_values;
81 - $check_val['created_at >'] = gmdate( 'Y-m-d H:i:s', strtotime( $new_values['created_at'] ) - absint( $duplicate_entry_time ) );
55 + $check_val['created_at >'] = gmdate( 'Y-m-d H:i:s', ( strtotime( $new_values['created_at'] ) - absint( $duplicate_entry_time ) ) );
82 56
83 57 unset( $check_val['created_at'], $check_val['updated_at'], $check_val['is_draft'], $check_val['id'], $check_val['item_key'] );
84 58
85 - // phpcs:ignore Universal.Operators.StrictComparisons
86 59 if ( $new_values['item_key'] == $new_values['name'] ) {
87 60 unset( $check_val['name'] );
88 61 }
89 62
@@ -88,34 +61,26 @@
88 61 }
89 62
90 63 $check_val = apply_filters( 'frm_duplicate_check_val', $check_val );
91 64
92 - if ( ! isset( $values['item_meta'] ) ) {
93 - return false;
94 - }
65 + global $wpdb;
66 + $entry_exists = FrmDb::get_col( $wpdb->prefix . 'frm_items', $check_val, 'id', array( 'order_by' => 'created_at DESC' ) );
95 67
96 - $entry_exists = FrmDb::get_col( 'frm_items', $check_val, 'id', array( 'order_by' => 'created_at DESC' ) );
97 -
98 - if ( ! $entry_exists ) {
68 + if ( ! $entry_exists || ! isset( $values['item_meta'] ) ) {
99 69 return false;
100 70 }
101 71
102 72 global $frm_vars;
103 73 $frm_vars['checking_duplicates'] = true;
104 - $is_duplicate = false;
105 74
75 + $is_duplicate = false;
106 76 foreach ( $entry_exists as $entry_exist ) {
107 77 $is_duplicate = true;
108 78
109 - // Make sure it's a duplicate
79 + // make sure it's a duplicate
110 80 $metas = FrmEntryMeta::get_entry_meta_info( $entry_exist );
111 81 $field_metas = array();
112 -
113 82 foreach ( $metas as $meta ) {
114 - if ( 0 === (int) $meta->field_id ) {
115 - continue;
116 - }
117 -
118 83 $field_metas[ $meta->field_id ] = $meta->meta_value;
119 84 }
120 85
121 86 $filtered_vals = array_filter( $values['item_meta'] );
@@ -122,13 +87,13 @@
122 87 $filtered_vals = self::convert_values_to_their_saved_value( $filtered_vals, $entry_exist );
123 88 $field_metas = array_filter( $field_metas );
124 89
125 90 // If prev entry is empty and current entry is not, they are not duplicates
126 - if ( ! $field_metas && $filtered_vals ) {
91 + if ( empty( $field_metas ) && ! empty( $filtered_vals ) ) {
127 92 return false;
128 93 }
129 94
130 - // Compare serialized values and not arrays
95 + // compare serialized values and not arrays
131 96 $new_meta = array_map( 'maybe_serialize', $filtered_vals );
132 97
133 98 if ( $field_metas === $new_meta ) {
134 99 $is_duplicate = true;
@@ -141,12 +106,12 @@
141 106 continue;
142 107 }
143 108
144 109 $diff = array_diff_assoc( $field_metas, $new_meta );
145 -
146 - foreach ( $diff as $meta_value ) {
147 - if ( $meta_value ) {
110 + foreach ( $diff as $field_id => $meta_value ) {
111 + if ( ! empty( $meta_value ) ) {
148 112 $is_duplicate = false;
113 + continue;
149 114 }
150 115 }
151 116
152 117 if ( $is_duplicate ) {
@@ -151,9 +116,9 @@
151 116
152 117 if ( $is_duplicate ) {
153 118 break;
154 119 }
155 - }//end foreach
120 + }
156 121
157 122 $frm_vars['checking_duplicates'] = false;
158 123
159 124 return $is_duplicate;
@@ -159,95 +124,25 @@
159 124 return $is_duplicate;
160 125 }
161 126
162 127 /**
163 - * @since 6.16.3
164 - *
165 - * @param array $values POST request data.
166 - * @param string $created_at The timestamp of the entry we are checking for.
167 - *
168 - * @return bool
169 - */
170 - private static function maybe_check_for_unique_id_match( $values, $created_at ) {
171 - if ( ! self::should_check_for_unique_id_match() ) {
172 - return false;
173 - }
174 -
175 - if ( empty( $values['unique_id'] ) ) {
176 - return false;
177 - }
178 -
179 - $unique_id = sanitize_key( $values['unique_id'] );
180 -
181 - if ( ! $unique_id ) {
182 - // Only continue if a unique ID was generated on form submit.
183 - return false;
184 - }
185 -
186 - if ( isset( self::$unique_id_match_checks[ $unique_id ] ) ) {
187 - return self::$unique_id_match_checks[ $unique_id ];
188 - }
189 -
190 - $timestamp = strtotime( $created_at );
191 -
192 - if ( false === $timestamp ) {
193 - $timestamp = time();
194 - }
195 -
196 - self::$unique_id_match_checks[ $unique_id ] = (bool) FrmDb::get_var(
197 - 'frm_item_metas',
198 - array(
199 - 'field_id' => 0,
200 - 'meta_value' => serialize( compact( 'unique_id' ) ),
201 - 'created_at >' => gmdate( 'Y-m-d H:i:s', $timestamp - MONTH_IN_SECONDS ),
202 - ),
203 - 'id'
204 - );
205 -
206 - return self::$unique_id_match_checks[ $unique_id ];
207 - }
208 -
209 - /**
210 - * @since 6.16.3
211 - *
212 - * @return bool
213 - */
214 - private static function should_check_for_unique_id_match() {
215 - /**
216 - * Allow users to opt out of the DB query, in case it causes performance issues.
217 - *
218 - * @since 6.16.3
219 - *
220 - * @param bool $should_extend
221 - */
222 - $should_check = apply_filters( 'frm_check_for_unique_id_match', true );
223 - return (bool) $should_check;
224 - }
225 -
226 - /**
227 128 * Convert form data to the actual value that would be saved into the database.
129 + * This is important for the duplicate check as something like 'a:2:{s:5:"typed";s:0:"";s:6:"output";s:0:"";}' (a signature value) is actually an empty string and does not get saved.
228 130 *
229 - * This is important for the duplicate check as something like 'a:2:{s:5:"typed";s:0:"";s:6:"output";s:0:"";}'
230 - * (a signature value) is actually an empty string and does not get saved.
231 - *
232 131 * @param array $filter_vals
233 132 * @param int $entry_id
234 - *
235 133 * @return array
236 134 */
237 135 private static function convert_values_to_their_saved_value( $filter_vals, $entry_id ) {
238 136 $reduced = array();
239 -
240 137 foreach ( $filter_vals as $field_id => $value ) {
241 138 $field = FrmFieldFactory::get_field_object( $field_id );
242 139 $reduced[ $field_id ] = $field->get_value_to_save( $value, array( 'entry_id' => $entry_id ) );
243 140 $reduced[ $field_id ] = $field->set_value_before_save( $reduced[ $field_id ] );
244 -
245 - if ( '' === $reduced[ $field_id ] || array() === $reduced[ $field_id ] ) {
141 + if ( '' === $reduced[ $field_id ] || ( is_array( $reduced[ $field_id ] ) && 0 === count( $reduced[ $field_id ] ) ) ) {
246 142 unset( $reduced[ $field_id ] );
247 143 }
248 144 }
249 -
250 145 return $reduced;
251 146 }
252 147
253 148 /**
@@ -255,15 +150,15 @@
255 150 *
256 151 * @since 2.0.23
257 152 *
258 153 * @param array $values
259 - * @param int $duplicate_entry_time
154 + * @param int $duplicate_entry_time
260 155 *
261 156 * @return bool
262 157 */
263 158 private static function is_duplicate_check_needed( $values, $duplicate_entry_time ) {
264 159 // If time for checking duplicates is set to an empty value, don't check for duplicates
265 - if ( ! $duplicate_entry_time ) {
160 + if ( empty( $duplicate_entry_time ) ) {
266 161 return false;
267 162 }
268 163
269 164 // If CSV is importing, don't check for duplicates
@@ -271,20 +166,20 @@
271 166 return false;
272 167 }
273 168
274 169 // If repeating field entries are getting created, don't check for duplicates
275 - return empty( $values['parent_form_id'] );
170 + if ( isset( $values['parent_form_id'] ) && $values['parent_form_id'] ) {
171 + return false;
172 + }
173 +
174 + return true;
276 175 }
277 176
278 - /**
279 - * @param int|string $id
280 - *
281 - * @return false|int
282 - */
283 177 public static function duplicate( $id ) {
284 178 global $wpdb;
285 179
286 - $values = self::getOne( $id );
180 + $values = self::getOne( $id );
181 +
287 182 $new_values = array();
288 183 $new_values['item_key'] = FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_items', 'item_key' );
289 184 $new_values['name'] = $values->name;
290 185 $new_values['is_draft'] = $values->is_draft;
@@ -294,9 +189,8 @@
294 189 $new_values['created_at'] = current_time( 'mysql', 1 );
295 190 $new_values['updated_at'] = $new_values['created_at'];
296 191
297 192 $query_results = $wpdb->insert( $wpdb->prefix . 'frm_items', $new_values );
298 -
299 193 if ( ! $query_results ) {
300 194 return false;
301 195 }
302 196
@@ -302,9 +196,8 @@
302 196
303 197 $entry_id = $wpdb->insert_id;
304 198
305 199 global $frm_vars;
306 -
307 200 if ( ! isset( $frm_vars['saved_entries'] ) ) {
308 201 $frm_vars['saved_entries'] = array();
309 202 }
310 203 $frm_vars['saved_entries'][] = (int) $entry_id;
@@ -319,15 +212,17 @@
319 212
320 213 /**
321 214 * Update an entry (not via XML)
322 215 *
323 - * @param int $id
216 + * @param int $id
324 217 * @param array $values
325 218 *
326 - * @return bool|int Update results.
219 + * @return boolean|int $update_results
327 220 */
328 221 public static function update( $id, $values ) {
329 - return self::update_entry( $id, $values, 'standard' );
222 + $update_results = self::update_entry( $id, $values, 'standard' );
223 +
224 + return $update_results;
330 225 }
331 226
332 227 /**
333 228 * Update an entry with some differences depending on the update type
@@ -333,24 +228,23 @@
333 228 * Update an entry with some differences depending on the update type
334 229 *
335 230 * @since 2.0.16
336 231 *
337 - * @param int $id
338 - * @param array $values
339 - * @param string $update_type
232 + * @param int $id
233 + * @param array $values
340 234 *
341 - * @return bool|int Query results.
235 + * @return boolean|int $query_results
342 236 */
343 237 private static function update_entry( $id, $values, $update_type ) {
344 238 global $wpdb;
345 239
346 240 $update = self::before_update_entry( $id, $values, $update_type );
347 -
348 241 if ( ! $update ) {
349 242 return false;
350 243 }
351 244
352 - $new_values = self::package_entry_to_update( $id, $values );
245 + $new_values = self::package_entry_to_update( $id, $values );
246 +
353 247 $query_results = $wpdb->update( $wpdb->prefix . 'frm_items', $new_values, compact( 'id' ) );
354 248
355 249 self::after_update_entry( $query_results, $id, $values, $new_values );
356 250
@@ -356,32 +250,19 @@
356 250
357 251 return $query_results;
358 252 }
359 253
360 - /**
361 - * Delete an entry.
362 - *
363 - * @param int|string $id
364 - *
365 - * @return bool True on success, false if nothing was deleted.
366 - */
367 254 public static function destroy( $id ) {
368 255 global $wpdb;
369 256 $id = (int) $id;
370 257
371 - // Item meta is required for conditional logic in actions with 'delete' events.
372 - $entry = self::getOne( $id, true );
258 + $entry = self::getOne( $id );
259 + if ( ! $entry ) {
260 + $result = false;
373 261
374 - if ( ! $entry ) {
375 - return false;
262 + return $result;
376 263 }
377 264
378 - /**
379 - * Trigger an action to run custom logic before the entry is deleted.
380 - *
381 - * @param int $id The id of the entry that was destroyed.
382 - * @param stdClass $entry The entry object.
383 - */
384 265 do_action( 'frm_before_destroy_entry', $id, $entry );
385 266
386 267 $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas WHERE item_id=%d', $id ) );
387 268 $result = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_items WHERE id=%d', $id ) );
@@ -387,34 +268,15 @@
387 268 $result = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_items WHERE id=%d', $id ) );
388 269
389 270 self::clear_cache();
390 271
391 - /**
392 - * Trigger an action to run custom logic after the entry is deleted.
393 - * Use this hook if you need to update caching after an entry is deleted.
394 - *
395 - * @since 5.4.1
396 - *
397 - * @param int $id The id of the entry that was destroyed.
398 - * @param stdClass $entry The entry object.
399 - */
400 - do_action( 'frm_after_destroy_entry', $id, $entry );
401 -
402 272 return $result;
403 273 }
404 274
405 - /**
406 - * @param int $id
407 - * @param mixed $value
408 - * @param int|string $form_id
409 - *
410 - * @return false|int
411 - */
412 275 public static function update_form( $id, $value, $form_id ) {
413 276 global $wpdb;
414 277 $form_id = isset( $value ) ? $form_id : null;
415 278 $result = $wpdb->update( $wpdb->prefix . 'frm_items', array( 'form_id' => $form_id ), array( 'id' => $id ) );
416 -
417 279 if ( $result ) {
418 280 self::clear_cache();
419 281 }
420 282
@@ -425,10 +287,8 @@
425 287 * Clear entry caching
426 288 * Called when an entry is changed
427 289 *
428 290 * @since 2.0.5
429 - *
430 - * @return void
431 291 */
432 292 public static function clear_cache() {
433 293 FrmDb::cache_delete_group( 'frm_entry' );
434 294 FrmDb::cache_delete_group( 'frm_item' );
@@ -440,42 +300,33 @@
440 300 * After switching to the wp_loaded hook for processing entries,
441 301 * we can no longer use 'name', but check it as a fallback
442 302 *
443 303 * @since 2.0.11
444 - *
445 - * @param array $values
446 - * @param array|string $default
447 - *
448 - * @return string
449 304 */
450 305 public static function get_new_entry_name( $values, $default = '' ) {
451 - $name = $values['item_name'] ?? $values['name'] ?? $default;
452 - return is_array( $name ) ? reset( $name ) : $name;
306 + $name = isset( $values['item_name'] ) ? $values['item_name'] : ( isset( $values['name'] ) ? $values['name'] : $default );
307 + if ( is_array( $name ) ) {
308 + $name = reset( $name );
309 + }
310 +
311 + return $name;
453 312 }
454 313
455 314 /**
456 315 * If $entry is numeric, get the entry object
457 316 *
317 + * @param int|object $entry by reference
318 + *
458 319 * @since 2.0.9
459 - *
460 - * @param int|object|string $entry By reference.
461 - *
462 - * @return void
463 320 */
464 321 public static function maybe_get_entry( &$entry ) {
465 322 if ( $entry && is_numeric( $entry ) ) {
466 323 $entry = self::getOne( $entry );
467 - } elseif ( ! $entry || 'false' === $entry ) {
324 + } elseif ( empty( $entry ) || 'false' === $entry ) {
468 325 $entry = false;
469 326 }
470 327 }
471 328
472 - /**
473 - * @param int|string $id
474 - * @param bool $meta
475 - *
476 - * @return object|null
477 - */
478 329 public static function getOne( $id, $meta = false ) {
479 330 global $wpdb;
480 331
481 332 $query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it
@@ -480,9 +331,9 @@
480 331
481 332 $query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it
482 333 LEFT OUTER JOIN {$wpdb->prefix}frm_forms fr ON it.form_id=fr.id WHERE ";
483 334
484 - $query .= is_numeric( $id ) ? 'it.id=%d' : 'it.item_key=%s';
335 + $query .= is_numeric( $id ) ? 'it.id=%d' : 'it.item_key=%s';
485 336 $query_args = array( $id );
486 337 $query = $wpdb->prepare( $query, $query_args ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
487 338
488 339 if ( ! $meta ) {
@@ -491,9 +342,8 @@
491 342 return $entry;
492 343 }
493 344
494 345 $entry = FrmDb::check_cache( $id, 'frm_entry' );
495 -
496 346 if ( $entry !== false ) {
497 347 self::prepare_entry( $entry );
498 348 return $entry;
499 349 }
@@ -508,19 +358,16 @@
508 358 /**
509 359 * @since 4.02.03
510 360 *
511 361 * @param object $entry
512 - *
513 - * @return void
514 362 */
515 363 private static function prepare_entry( &$entry ) {
516 - if ( ! $entry ) {
364 + if ( empty( $entry ) ) {
517 365 return;
518 366 }
519 367
520 368 FrmAppHelper::unserialize_or_decode( $entry->description );
521 - // TODO: Remove slashes on input only, not output.
522 - $entry = wp_unslash( $entry );
369 + $entry = wp_unslash( $entry ); // TODO: Remove slashes on input only, not output.
523 370 }
524 371
525 372 /**
526 373 * @since 4.02.03
@@ -525,10 +372,8 @@
525 372 /**
526 373 * @since 4.02.03
527 374 *
528 375 * @param array $entries
529 - *
530 - * @return void
531 376 */
532 377 private static function prepare_entries( &$entries ) {
533 378 foreach ( $entries as $k => $entry ) {
534 379 self::prepare_entry( $entry );
@@ -535,13 +380,8 @@
535 380 $entries[ $k ] = $entry;
536 381 }
537 382 }
538 383
539 - /**
540 - * @param object|null $entry
541 - *
542 - * @return object|null
543 - */
544 384 public static function get_meta( $entry ) {
545 385 if ( ! $entry ) {
546 386 return $entry;
547 387 }
@@ -552,21 +392,18 @@
552 392 array(
553 393 'item_id' => $entry->id,
554 394 'field_id !' => 0,
555 395 ),
556 - 'field_id, meta_value, field_key, item_id, f.type'
396 + 'field_id, meta_value, field_key, item_id'
557 397 );
558 398
559 399 $entry->metas = array();
560 400
561 401 $include_key = apply_filters( 'frm_include_meta_keys', false, array( 'form_id' => $entry->form_id ) );
562 -
563 402 foreach ( $metas as $meta_val ) {
564 - FrmFieldsHelper::prepare_field_value( $meta_val->meta_value, $meta_val->type );
565 -
566 - if ( (int) $meta_val->item_id === (int) $entry->id ) {
403 + if ( $meta_val->item_id == $entry->id ) {
404 + FrmAppHelper::unserialize_or_decode( $meta_val->meta_value );
567 405 $entry->metas[ $meta_val->field_id ] = $meta_val->meta_value;
568 -
569 406 if ( $include_key ) {
570 407 $entry->metas[ $meta_val->field_key ] = $entry->metas[ $meta_val->field_id ];
571 408 }
572 409 continue;
@@ -571,17 +408,18 @@
571 408 }
572 409 continue;
573 410 }
574 411
575 - // Include sub entries in an array
412 + // include sub entries in an array
576 413 if ( ! isset( $entry->metas[ $meta_val->field_id ] ) ) {
577 414 $entry->metas[ $meta_val->field_id ] = array();
578 415 }
579 416
417 + FrmAppHelper::unserialize_or_decode( $meta_val->meta_value );
580 418 $entry->metas[ $meta_val->field_id ][] = $meta_val->meta_value;
581 419
582 420 unset( $meta_val );
583 - }//end foreach
421 + }
584 422 unset( $metas );
585 423
586 424 FrmDb::set_cache( $entry->id, $entry, 'frm_entry' );
587 425
@@ -589,45 +427,43 @@
589 427 }
590 428
591 429 /**
592 430 * @param string $id
593 - *
594 - * @return bool
595 431 */
596 432 public static function exists( $id ) {
433 + global $wpdb;
434 +
597 435 if ( FrmDb::check_cache( $id, 'frm_entry' ) ) {
598 - return true;
436 + $exists = true;
437 +
438 + return $exists;
599 439 }
600 440
601 - $where = is_numeric( $id ) ? array( 'id' => $id ) : array( 'item_key' => $id );
602 - $id = FrmDb::get_var( 'frm_items', $where );
441 + if ( is_numeric( $id ) ) {
442 + $where = array( 'id' => $id );
443 + } else {
444 + $where = array( 'item_key' => $id );
445 + }
446 + $id = FrmDb::get_var( $wpdb->prefix . 'frm_items', $where );
603 447
604 - return $id && $id > 0;
448 + return ( $id && $id > 0 );
605 449 }
606 450
607 - /**
608 - * @param array|string $where
609 - * @param string $order_by
610 - * @param string $limit
611 - * @param bool $meta
612 - * @param bool $inc_form
613 - *
614 - * @return array
615 - */
616 451 public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) {
617 452 global $wpdb;
618 453
619 - $limit = FrmDb::esc_limit( $limit );
454 + $limit = FrmDb::esc_limit( $limit );
455 +
620 456 $cache_key = FrmAppHelper::maybe_json_encode( $where ) . $order_by . $limit . $inc_form;
621 457 $entries = wp_cache_get( $cache_key, 'frm_entry' );
622 458
623 459 if ( false === $entries ) {
624 - $fields = 'it.id, it.item_key, it.name, it.ip, it.form_id, it.post_id, it.user_id, it.parent_item_id, it.updated_by, it.created_at, it.updated_at, it.is_draft, it.description'; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
460 + $fields = 'it.id, it.item_key, it.name, it.ip, it.form_id, it.post_id, it.user_id, it.parent_item_id, it.updated_by, it.created_at, it.updated_at, it.is_draft';
625 461 $table = $wpdb->prefix . 'frm_items it ';
626 462
627 463 if ( $inc_form ) {
628 464 $fields = 'it.*, fr.name as form_name,fr.form_key as form_key';
629 - $table .= 'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id ';
465 + $table .= 'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id ';
630 466 }
631 467
632 468 if ( preg_match( '/ meta_([0-9]+)/', $order_by, $order_matches ) ) {
633 469 $fields .= self::sort_by_field( $order_matches[1] );
@@ -633,9 +469,9 @@
633 469 $fields .= self::sort_by_field( $order_matches[1] );
634 470 unset( $order_matches );
635 471 }
636 472
637 - // Prepare the query
473 + // prepare the query
638 474 $query = 'SELECT ' . $fields . ' FROM ' . $table . FrmDb::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
639 475
640 476 $entries = $wpdb->get_results( $query, OBJECT_K ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
641 477 unset( $query );
@@ -640,9 +476,9 @@
640 476 $entries = $wpdb->get_results( $query, OBJECT_K ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
641 477 unset( $query );
642 478
643 479 FrmDb::set_cache( $cache_key, $entries, 'frm_entry' );
644 - }//end if
480 + }
645 481
646 482 if ( ! $meta || ! $entries ) {
647 483 self::prepare_entries( $entries );
648 484 return $entries;
@@ -653,21 +489,15 @@
653 489 $where = array( 'it.form_id' => substr( $where, 11 ) );
654 490 }
655 491
656 492 $meta_where = array( 'field_id !' => 0 );
657 -
658 - // phpcs:ignore Universal.Operators.StrictComparisons
659 - if ( $limit == '' && is_array( $where ) && count( $where ) === 1 && isset( $where['it.form_id'] ) ) {
493 + if ( $limit == '' && is_array( $where ) && count( $where ) == 1 && isset( $where['it.form_id'] ) ) {
660 494 $meta_where['fi.form_id'] = $where['it.form_id'];
661 495 } else {
662 496 $meta_where['item_id'] = array_keys( $entries );
663 497 }
664 498
665 - $metas = FrmDb::get_results(
666 - $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON it.field_id = fi.id',
667 - $meta_where,
668 - 'item_id, meta_value, field_id, field_key, form_id, fi.type'
669 - );
499 + $metas = FrmDb::get_results( $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON (it.field_id = fi.id)', $meta_where, 'item_id, meta_value, field_id, field_key, form_id' );
670 500
671 501 unset( $meta_where );
672 502
673 503 if ( ! $metas ) {
@@ -683,9 +513,9 @@
683 513 if ( ! isset( $entries[ $meta_val->item_id ]->metas ) ) {
684 514 $entries[ $meta_val->item_id ]->metas = array();
685 515 }
686 516
687 - FrmFieldsHelper::prepare_field_value( $meta_val->meta_value, $meta_val->type );
517 + FrmAppHelper::unserialize_or_decode( $meta_val->meta_value );
688 518 $entries[ $meta_val->item_id ]->metas[ $meta_val->field_id ] = $meta_val->meta_value;
689 519 unset( $m_key, $meta_val );
690 520 }
691 521
@@ -700,15 +530,15 @@
700 530 return $entries;
701 531 }
702 532
703 533 /**
704 - * @param int|string $field_id
705 - *
534 + * @param int $field_id
706 535 * @return string
707 536 */
708 537 private static function sort_by_field( $field_id ) {
709 538 global $wpdb;
710 - $field_id = (int) $field_id;
539 + $field_id = (int) $field_id;
540 +
711 541 $field_options = FrmDb::get_var( 'frm_fields', array( 'id' => $field_id ), 'field_options' );
712 542 FrmAppHelper::unserialize_or_decode( $field_options );
713 543
714 544 if ( empty( $field_options['post_field'] ) ) {
@@ -721,15 +551,13 @@
721 551 }
722 552
723 553 // Pagination Methods
724 554 /**
725 - * @param array|int|string $where If int, use the form id.
726 - *
727 - * @return int|string
555 + * @param int|array|string If int, use the form id.
728 556 */
729 557 public static function getRecordCount( $where = '' ) {
730 558 global $wpdb;
731 - $table_join = $wpdb->prefix . 'frm_items it JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id';
559 + $table_join = $wpdb->prefix . 'frm_items it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id';
732 560
733 561 if ( is_numeric( $where ) ) {
734 562 $table_join = 'frm_items';
735 563 $where = array( 'form_id' => $where );
@@ -735,35 +563,29 @@
735 563 $where = array( 'form_id' => $where );
736 564 }
737 565
738 566 if ( is_array( $where ) ) {
739 - return FrmDb::get_count( $table_join, $where );
567 + $count = FrmDb::get_count( $table_join, $where );
568 + } else {
569 + $cache_key = 'count_' . FrmAppHelper::maybe_json_encode( $where );
570 + $query = 'SELECT COUNT(*) FROM ' . $table_join . FrmDb::prepend_and_or_where( ' WHERE ', $where );
571 + $count = FrmDb::check_cache( $cache_key, 'frm_entry', $query, 'get_var' );
740 572 }
741 573
742 - $cache_key = 'count_' . FrmAppHelper::maybe_json_encode( $where );
743 - $query = 'SELECT COUNT(*) FROM ' . $table_join . FrmDb::prepend_and_or_where( ' WHERE ', $where );
744 -
745 - return FrmDb::check_cache( $cache_key, 'frm_entry', $query, 'get_var' );
574 + return $count;
746 575 }
747 576
748 - /**
749 - * @param int|string $p_size
750 - * @param array|int|string $where
751 - *
752 - * @return int
753 - */
754 577 public static function getPageCount( $p_size, $where = '' ) {
755 578 $p_size = (int) $p_size;
756 -
579 + $count = 1;
757 580 if ( $p_size ) {
758 581 if ( ! is_numeric( $where ) ) {
759 582 $where = self::getRecordCount( $where );
760 583 }
761 -
762 - return ceil( (int) $where / $p_size );
584 + $count = ceil( (int) $where / $p_size );
763 585 }
764 586
765 - return 1;
587 + return $count;
766 588 }
767 589
768 590 /**
769 591 * Prepare the data before inserting it into the database
@@ -769,21 +591,24 @@
769 591 * Prepare the data before inserting it into the database
770 592 *
771 593 * @since 2.0.16
772 594 *
773 - * @param array $values
595 + * @param array $values
774 596 * @param string $type
775 597 *
776 - * @return array New values.
598 + * @return array $new_values
777 599 */
778 600 private static function before_insert_entry_in_database( &$values, $type ) {
601 +
779 602 self::sanitize_entry_post( $values );
780 603
781 - if ( $type !== 'xml' ) {
604 + if ( $type != 'xml' ) {
782 605 $values = apply_filters( 'frm_pre_create_entry', $values );
783 606 }
784 607
785 - return self::package_entry_data( $values );
608 + $new_values = self::package_entry_data( $values );
609 +
610 + return $new_values;
786 611 }
787 612
788 613 /**
789 614 * Create an entry and perform after create actions
@@ -792,13 +617,12 @@
792 617 *
793 618 * @param array $values
794 619 * @param array $new_values
795 620 *
796 - * @return bool|int Entry ID.
621 + * @return boolean|int $entry_id
797 622 */
798 623 private static function continue_to_create_entry( $values, $new_values ) {
799 624 $entry_id = self::insert_entry_into_database( $new_values );
800 -
801 625 if ( ! $entry_id ) {
802 626 return false;
803 627 }
804 628
@@ -811,11 +635,9 @@
811 635 * Sanitize the POST values before we use them
812 636 *
813 637 * @since 2.0
814 638 *
815 - * @param array $values The POST values by reference.
816 - *
817 - * @return void
639 + * @param array $values The POST values by reference
818 640 */
819 641 public static function sanitize_entry_post( &$values ) {
820 642 $sanitize_method = array(
821 643 'form_id' => 'absint',
@@ -840,9 +662,9 @@
840 662 * @since 2.0.16
841 663 *
842 664 * @param array $values
843 665 *
844 - * @return array New values.
666 + * @return array $new_values
845 667 */
846 668 private static function package_entry_data( &$values ) {
847 669 global $wpdb;
848 670
@@ -852,9 +674,9 @@
852 674
853 675 $item_name = self::get_new_entry_name( $values, $values['item_key'] );
854 676 $new_values = array(
855 677 'item_key' => FrmAppHelper::get_unique_key( $values['item_key'], $wpdb->prefix . 'frm_items', 'item_key' ),
856 - 'name' => FrmAppHelper::truncate( $item_name, 255, 1, '', true ),
678 + 'name' => FrmAppHelper::truncate( $item_name, 255, 1, '' ),
857 679 'ip' => self::get_ip( $values ),
858 680 'is_draft' => self::get_is_draft_value( $values ),
859 681 'form_id' => (int) self::get_entry_value( $values, 'form_id', null ),
860 682 'post_id' => (int) self::get_entry_value( $values, 'post_id', 0 ),
@@ -864,22 +686,15 @@
864 686 'description' => self::get_entry_description( $values ),
865 687 'user_id' => self::get_entry_user_id( $values ),
866 688 );
867 689
868 - $new_values['updated_by'] = $values['updated_by'] ?? $new_values['user_id'];
690 + $new_values['updated_by'] = isset( $values['updated_by'] ) ? $values['updated_by'] : $new_values['user_id'];
869 691
870 692 return $new_values;
871 693 }
872 694
873 - /**
874 - * @param array $values
875 - * @param string $name
876 - * @param mixed $default
877 - *
878 - * @return mixed
879 - */
880 695 private static function get_entry_value( $values, $name, $default ) {
881 - return $values[ $name ] ?? $default;
696 + return isset( $values[ $name ] ) ? $values[ $name ] : $default;
882 697 }
883 698
884 699 /**
885 700 * Get the ip for a new entry.
@@ -896,11 +711,10 @@
896 711 return '';
897 712 }
898 713
899 714 $ip = FrmAppHelper::get_ip_address();
900 -
901 715 if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) {
902 - return self::get_entry_value( $values, 'ip', $ip );
716 + $ip = self::get_entry_value( $values, 'ip', $ip );
903 717 }
904 718
905 719 return $ip;
906 720 }
@@ -914,13 +728,9 @@
914 728 *
915 729 * @return int
916 730 */
917 731 private static function get_is_draft_value( $values ) {
918 - if ( isset( $values['frm_saving_draft'] ) && FrmEntriesHelper::DRAFT_ENTRY_STATUS === (int) $values['frm_saving_draft'] ) {
919 - return FrmEntriesHelper::DRAFT_ENTRY_STATUS;
920 - }
921 -
922 - return isset( $values['is_draft'] ) ? absint( $values['is_draft'] ) : FrmEntriesHelper::SUBMITTED_ENTRY_STATUS;
732 + return ( ( isset( $values['frm_saving_draft'] ) && $values['frm_saving_draft'] == 1 ) || ( isset( $values['is_draft'] ) && $values['is_draft'] == 1 ) ) ? 1 : 0;
923 733 }
924 734
925 735 /**
926 736 * Get the created_at value for a new entry
@@ -944,9 +754,15 @@
944 754 *
945 755 * @return string
946 756 */
947 757 private static function get_updated_at( $values ) {
948 - return $values['updated_at'] ?? self::get_created_at( $values );
758 + if ( isset( $values['updated_at'] ) ) {
759 + $updated_at = $values['updated_at'];
760 + } else {
761 + $updated_at = self::get_created_at( $values );
762 + }
763 +
764 + return $updated_at;
949 765 }
950 766
951 767 /**
952 768 * Get the description value for a new entry
@@ -957,18 +773,20 @@
957 773 *
958 774 * @return string
959 775 */
960 776 private static function get_entry_description( $values ) {
961 - if ( ! empty( $values['description'] ) ) {
962 - return FrmAppHelper::maybe_json_encode( $values['description'] );
777 + if ( isset( $values['description'] ) && ! empty( $values['description'] ) ) {
778 + $description = FrmAppHelper::maybe_json_encode( $values['description'] );
779 + } else {
780 + $description = json_encode(
781 + array(
782 + 'browser' => FrmAppHelper::get_server_value( 'HTTP_USER_AGENT' ),
783 + 'referrer' => FrmAppHelper::get_server_value( 'HTTP_REFERER' ),
784 + )
785 + );
963 786 }
964 787
965 - return json_encode(
966 - array(
967 - 'browser' => FrmAppHelper::get_server_value( 'HTTP_USER_AGENT' ),
968 - 'referrer' => FrmAppHelper::get_server_value( 'HTTP_REFERER' ),
969 - )
970 - );
788 + return $description;
971 789 }
972 790
973 791 /**
974 792 * Get the user_id value for a new entry
@@ -980,13 +798,15 @@
980 798 * @return int
981 799 */
982 800 private static function get_entry_user_id( $values ) {
983 801 if ( isset( $values['frm_user_id'] ) && ( is_numeric( $values['frm_user_id'] ) || FrmAppHelper::is_admin() ) ) {
984 - return $values['frm_user_id'];
802 + $user_id = $values['frm_user_id'];
803 + } else {
804 + $current_user_id = get_current_user_id();
805 + $user_id = $current_user_id ? $current_user_id : 0;
985 806 }
986 807
987 - $current_user_id = get_current_user_id();
988 - return $current_user_id ? $current_user_id : 0;
808 + return $user_id;
989 809 }
990 810
991 811 /**
992 812 * Insert new entry into the database
@@ -994,9 +814,9 @@
994 814 * @since 2.0.16
995 815 *
996 816 * @param array $new_values
997 817 *
998 - * @return bool|int Entry ID.
818 + * @return int | boolean $entry_id
999 819 */
1000 820 private static function insert_entry_into_database( $new_values ) {
1001 821 global $wpdb;
1002 822
@@ -1001,9 +821,15 @@
1001 821 global $wpdb;
1002 822
1003 823 $query_results = $wpdb->insert( $wpdb->prefix . 'frm_items', $new_values );
1004 824
1005 - return $query_results ? $wpdb->insert_id : false;
825 + if ( ! $query_results ) {
826 + $entry_id = false;
827 + } else {
828 + $entry_id = $wpdb->insert_id;
829 + }
830 +
831 + return $entry_id;
1006 832 }
1007 833
1008 834 /**
1009 835 * Add the new entry to global $frm_vars
@@ -1009,11 +835,9 @@
1009 835 * Add the new entry to global $frm_vars
1010 836 *
1011 837 * @since 2.0.16
1012 838 *
1013 - * @param int|string $entry_id
1014 - *
1015 - * @return void
839 + * @param int $entry_id
1016 840 */
1017 841 private static function add_new_entry_to_frm_vars( $entry_id ) {
1018 842 global $frm_vars;
1019 843
@@ -1028,63 +852,32 @@
1028 852 * Add entry metas, if there are any
1029 853 *
1030 854 * @since 2.0.16
1031 855 *
1032 - * @param array $values
1033 - * @param int|string $entry_id
1034 - *
856 + * @param array $values
857 + * @param int $entry_id
1035 858 * @return void
1036 859 */
1037 860 private static function maybe_add_entry_metas( $values, $entry_id ) {
1038 861 if ( isset( $values['item_meta'] ) ) {
1039 862 FrmEntryMeta::update_entry_metas( $entry_id, $values['item_meta'] );
1040 - self::maybe_add_unique_id_meta( $values, $entry_id );
1041 863 }
1042 864 self::maybe_add_captcha_meta( (int) $values['form_id'], (int) $entry_id );
1043 865 }
1044 866
1045 867 /**
1046 - * @since 6.16.3
1047 - *
1048 - * @param array $values
1049 - * @param int $entry_id
1050 - *
1051 - * @return void
1052 - */
1053 - private static function maybe_add_unique_id_meta( $values, $entry_id ) {
1054 - if ( ! empty( $values['parent_form_id'] ) || empty( $values['unique_id'] ) || ! self::should_check_for_unique_id_match() ) {
1055 - return;
1056 - }
1057 -
1058 - // This unique ID is inserted with JS on form submit.
1059 - // It is used to check for duplicate entries.
1060 - $unique_id = sanitize_key( $values['unique_id'] );
1061 -
1062 - if ( ! $unique_id ) {
1063 - return;
1064 - }
1065 -
1066 - FrmEntryMeta::add_entry_meta( $entry_id, 0, '', compact( 'unique_id' ) );
1067 - self::flag_new_unique_key( $unique_id );
1068 - }
1069 -
1070 - /**
1071 868 * @since 5.0.15
1072 869 *
1073 870 * @param int $form_id
1074 871 * @param int $entry_id
1075 - *
1076 872 * @return void
1077 873 */
1078 874 private static function maybe_add_captcha_meta( $form_id, $entry_id ) {
1079 875 global $frm_vars;
1080 -
1081 - if ( ! array_key_exists( 'captcha_scores', $frm_vars ) || ! array_key_exists( $form_id, $frm_vars['captcha_scores'] ) ) {
1082 - return;
876 + if ( array_key_exists( 'captcha_scores', $frm_vars ) && array_key_exists( $form_id, $frm_vars['captcha_scores'] ) ) {
877 + $captcha_score_meta = array( 'captcha_score' => $frm_vars['captcha_scores'][ $form_id ] );
878 + FrmEntryMeta::add_entry_meta( $entry_id, 0, '', maybe_serialize( $captcha_score_meta ) );
1083 879 }
1084 -
1085 - $captcha_score_meta = array( 'captcha_score' => $frm_vars['captcha_scores'][ $form_id ] );
1086 - FrmEntryMeta::add_entry_meta( $entry_id, 0, '', maybe_serialize( $captcha_score_meta ) );
1087 880 }
1088 881
1089 882 /**
1090 883 * Trigger frm_after_create_entry hooks
@@ -1090,30 +883,17 @@
1090 883 * Trigger frm_after_create_entry hooks
1091 884 *
1092 885 * @since 2.0.16
1093 886 *
1094 - * @param int $entry_id
1095 - * @param array $values
887 + * @param int $entry_id
1096 888 * @param array $new_values
1097 - *
1098 - * @return void
1099 889 */
1100 890 private static function after_entry_created_actions( $entry_id, $values, $new_values ) {
1101 - // This is a child entry.
1102 - $is_child = isset( $values['parent_nonce'] ) && ! empty( $values['parent_form_id'] ) && wp_verify_nonce( $values['parent_nonce'], 'parent' );
891 + // this is a child entry
892 + $is_child = isset( $values['parent_form_id'] ) && isset( $values['parent_nonce'] ) && ! empty( $values['parent_form_id'] ) && wp_verify_nonce( $values['parent_nonce'], 'parent' );
1103 893
1104 894 do_action( 'frm_after_create_entry', $entry_id, $new_values['form_id'], compact( 'is_child' ) );
1105 895 do_action( 'frm_after_create_entry_' . $new_values['form_id'], $entry_id, compact( 'is_child' ) );
1106 -
1107 - if ( ! empty( $values['form_key'] ) ) {
1108 - /**
1109 - * @since 6.30
1110 - *
1111 - * @param int $entry_id
1112 - * @param array $is_child
1113 - */
1114 - do_action( 'frm_after_create_entry_' . $values['form_key'], $entry_id, compact( 'is_child' ) );
1115 - }
1116 896 }
1117 897
1118 898 /**
1119 899 * Actions to perform immediately after an entry is inserted in the frm_items database
@@ -1121,13 +901,12 @@
1121 901 * @since 2.0.16
1122 902 *
1123 903 * @param array $values
1124 904 * @param array $new_values
1125 - * @param int $entry_id
1126 - *
1127 - * @return void
905 + * @param int $entry_id
1128 906 */
1129 907 private static function after_insert_entry_in_database( $values, $new_values, $entry_id ) {
908 +
1130 909 self::add_new_entry_to_frm_vars( $entry_id );
1131 910
1132 911 self::maybe_add_entry_metas( $values, $entry_id );
1133 912
@@ -1140,13 +919,13 @@
1140 919 * Perform some actions right before updating an entry
1141 920 *
1142 921 * @since 2.0.16
1143 922 *
1144 - * @param int|string $id
1145 - * @param array $values
1146 - * @param string $update_type
923 + * @param int $id
924 + * @param array $values
925 + * @param string $update_type
1147 926 *
1148 - * @return bool Update.
927 + * @return boolean $update
1149 928 */
1150 929 private static function before_update_entry( $id, &$values, $update_type ) {
1151 930 $update = true;
1152 931
@@ -1151,14 +930,13 @@
1151 930 $update = true;
1152 931
1153 932 global $frm_vars;
1154 933
1155 - // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
1156 - if ( isset( $frm_vars['saved_entries'] ) && is_array( $frm_vars['saved_entries'] ) && in_array( (int) $id, $frm_vars['saved_entries'] ) ) {
934 + if ( isset( $frm_vars['saved_entries'] ) && is_array( $frm_vars['saved_entries'] ) && in_array( (int) $id, (array) $frm_vars['saved_entries'] ) ) {
1157 935 $update = false;
1158 936 }
1159 937
1160 - if ( $update && $update_type !== 'xml' ) {
938 + if ( $update && $update_type != 'xml' ) {
1161 939 $values = apply_filters( 'frm_pre_update_entry', $values, $id );
1162 940 }
1163 941
1164 942 return $update;
@@ -1168,22 +946,22 @@
1168 946 * Package the entry data for updating
1169 947 *
1170 948 * @since 2.0.16
1171 949 *
1172 - * @param int $id
950 + * @param int $id
1173 951 * @param array $values
1174 952 *
1175 - * @return array New values.
953 + * @return array $new_values
1176 954 */
1177 955 private static function package_entry_to_update( $id, $values ) {
1178 956 global $wpdb;
1179 957
1180 958 $new_values = array(
1181 - 'name' => FrmAppHelper::truncate( self::get_new_entry_name( $values ), 255, 1, '', true ),
959 + 'name' => self::get_new_entry_name( $values ),
1182 960 'form_id' => (int) self::get_entry_value( $values, 'form_id', null ),
1183 961 'is_draft' => self::get_is_draft_value( $values ),
1184 962 'updated_at' => current_time( 'mysql', 1 ),
1185 - 'updated_by' => $values['updated_by'] ?? get_current_user_id(),
963 + 'updated_by' => isset( $values['updated_by'] ) ? $values['updated_by'] : get_current_user_id(),
1186 964 );
1187 965
1188 966 if ( isset( $values['post_id'] ) ) {
1189 967 $new_values['post_id'] = (int) $values['post_id'];
@@ -1200,9 +978,11 @@
1200 978 if ( isset( $values['frm_user_id'] ) && is_numeric( $values['frm_user_id'] ) ) {
1201 979 $new_values['user_id'] = $values['frm_user_id'];
1202 980 }
1203 981
1204 - return apply_filters( 'frm_update_entry', $new_values, $id );
982 + $new_values = apply_filters( 'frm_update_entry', $new_values, $id );
983 +
984 + return $new_values;
1205 985 }
1206 986
1207 987 /**
1208 988 * Perform some actions right after updating an entry
@@ -1208,14 +988,12 @@
1208 988 * Perform some actions right after updating an entry
1209 989 *
1210 990 * @since 2.0.16
1211 991 *
1212 - * @param bool|int $query_results
1213 - * @param int|string $id
1214 - * @param array $values
1215 - * @param array $new_values
1216 - *
1217 - * @return void
992 + * @param boolean|int $query_results
993 + * @param int $id
994 + * @param array $values
995 + * @param array $new_values
1218 996 */
1219 997 private static function after_update_entry( $query_results, $id, $values, $new_values ) {
1220 998 if ( $query_results ) {
1221 999 self::clear_cache();
@@ -1221,9 +999,8 @@
1221 999 self::clear_cache();
1222 1000 }
1223 1001
1224 1002 global $frm_vars;
1225 -
1226 1003 if ( ! isset( $frm_vars['saved_entries'] ) ) {
1227 1004 $frm_vars['saved_entries'] = array();
1228 1005 }
1229 1006
@@ -1234,17 +1011,8 @@
1234 1011 }
1235 1012
1236 1013 do_action( 'frm_after_update_entry', $id, $new_values['form_id'] );
1237 1014 do_action( 'frm_after_update_entry_' . $new_values['form_id'], $id );
1238 -
1239 - if ( ! empty( $values['form_key'] ) ) {
1240 - /**
1241 - * @since 6.30
1242 - *
1243 - * @param int $entry_id
1244 - */
1245 - do_action( 'frm_after_update_entry_' . $values['form_key'], $id );
1246 - }
1247 1015 }
1248 1016
1249 1017 /**
1250 1018 * Create entry from an XML import
@@ -1253,12 +1021,14 @@
1253 1021 * @since 2.0.16
1254 1022 *
1255 1023 * @param array $values
1256 1024 *
1257 - * @return bool|int Entry ID.
1025 + * @return int | boolean $entry_id
1258 1026 */
1259 1027 public static function create_entry_from_xml( $values ) {
1260 - return self::create_entry( $values, 'xml' );
1028 + $entry_id = self::create_entry( $values, 'xml' );
1029 +
1030 + return $entry_id;
1261 1031 }
1262 1032
1263 1033 /**
1264 1034 * Update entry from an XML import
@@ -1265,15 +1035,17 @@
1265 1035 * Certain actions aren't necessary when importing (like saving sub entries and modifying other vals)
1266 1036 *
1267 1037 * @since 2.0.16
1268 1038 *
1269 - * @param int $id
1039 + * @param int $id
1270 1040 * @param array $values
1271 1041 *
1272 - * @return bool|int Updated.
1042 + * @return int | boolean $updated
1273 1043 */
1274 1044 public static function update_entry_from_xml( $id, $values ) {
1275 - return self::update_entry( $id, $values, 'xml' );
1045 + $updated = self::update_entry( $id, $values, 'xml' );
1046 +
1047 + return $updated;
1276 1048 }
1277 1049
1278 1050 /**
1279 1051 * @param string $key
@@ -1281,23 +1053,8 @@
1281 1053 * @return int entry_id
1282 1054 */
1283 1055 public static function get_id_by_key( $key ) {
1284 1056 $entry_id = FrmDb::get_var( 'frm_items', array( 'item_key' => sanitize_title( $key ) ) );
1057 +
1285 1058 return (int) $entry_id;
1286 - }
1287 -
1288 - /**
1289 - * Get entries count.
1290 - *
1291 - * @since 6.8
1292 - *
1293 - * @return int|string
1294 - */
1295 - public static function get_entries_count() {
1296 - $args = array(
1297 - 'or' => 1,
1298 - 'parent_form_id' => null,
1299 - 'parent_form_id <' => 1,
1300 - );
1301 - return self::getRecordCount( $args );
1302 1059 }
1303 1060 }