| @@ -9,8 +9,9 @@ | ||
| 9 | 9 | * @param int $entry_id |
| 10 | 10 | * @param int $field_id |
| 11 | 11 | * @param string $meta_key usually set to '' as this parameter is no longer used. |
| 12 | 12 | * @param mixed $meta_value |
| 13 | + * @return int | |
| 13 | 14 | */ |
| 14 | 15 | public static function add_entry_meta( $entry_id, $field_id, $meta_key, $meta_value ) { |
| 15 | 16 | global $wpdb; |
| 16 | 17 | |
| @@ -42,11 +43,11 @@ | ||
| 42 | 43 | return $id; |
| 43 | 44 | } |
| 44 | 45 | |
| 45 | 46 | /** |
| 46 | - * @param int $entry_id | |
| 47 | - * @param int $field_id | |
| 48 | - * @param string $meta_key deprecated | |
| 47 | + * @param int $entry_id | |
| 48 | + * @param int $field_id | |
| 49 | + * @param string $meta_key Deprecated. | |
| 49 | 50 | * @param array|string $meta_value |
| 50 | 51 | * |
| 51 | 52 | * @return bool|false|int |
| 52 | 53 | */ |
| @@ -139,9 +140,9 @@ | ||
| 139 | 140 | } else { |
| 140 | 141 | // if value does not exist, then create it |
| 141 | 142 | self::add_entry_meta( $entry_id, $field_id, '', $meta_value ); |
| 142 | 143 | } |
| 143 | - } | |
| 144 | + }//end foreach | |
| 144 | 145 | |
| 145 | 146 | if ( empty( $prev_values ) ) { |
| 146 | 147 | return; |
| 147 | 148 | } |
| @@ -201,15 +202,18 @@ | ||
| 201 | 202 | } |
| 202 | 203 | |
| 203 | 204 | /** |
| 204 | 205 | * @since 2.0.9 |
| 206 | + * | |
| 207 | + * @param stdClass $entry | |
| 208 | + * @param int|string $field_id | |
| 209 | + * @return mixed | |
| 205 | 210 | */ |
| 206 | 211 | public static function get_meta_value( $entry, $field_id ) { |
| 207 | 212 | if ( isset( $entry->metas ) ) { |
| 208 | 213 | return isset( $entry->metas[ $field_id ] ) ? $entry->metas[ $field_id ] : false; |
| 209 | - } else { | |
| 210 | - return self::get_entry_meta_by_field( $entry->id, $field_id ); | |
| 211 | 214 | } |
| 215 | + return self::get_entry_meta_by_field( $entry->id, $field_id ); | |
| 212 | 216 | } |
| 213 | 217 | |
| 214 | 218 | public static function get_entry_meta_by_field( $entry_id, $field_id ) { |
| 215 | 219 | global $wpdb; |
| @@ -233,9 +237,9 @@ | ||
| 233 | 237 | $query = array( 'item_id' => $entry_id ); |
| 234 | 238 | if ( is_numeric( $field_id ) ) { |
| 235 | 239 | $query['field_id'] = $field_id; |
| 236 | 240 | } else { |
| 237 | - $get_table .= ' it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON it.field_id=fi.id'; | |
| 241 | + $get_table .= ' it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON it.field_id=fi.id'; | |
| 238 | 242 | $query['fi.field_key'] = $field_id; |
| 239 | 243 | } |
| 240 | 244 | |
| 241 | 245 | $result = FrmDb::get_var( $get_table, $query, 'meta_value' ); |
| @@ -274,10 +278,13 @@ | ||
| 274 | 278 | return wp_unslash( $values ); |
| 275 | 279 | } |
| 276 | 280 | |
| 277 | 281 | /** |
| 278 | - * @param string $order | |
| 279 | - * @param string $limit | |
| 282 | + * @param int|string $field_id | |
| 283 | + * @param string $order | |
| 284 | + * @param string $limit | |
| 285 | + * @param array $args | |
| 286 | + * @param array $query | |
| 280 | 287 | */ |
| 281 | 288 | private static function meta_field_query( $field_id, $order, $limit, $args, array &$query ) { |
| 282 | 289 | global $wpdb; |
| 283 | 290 | $query[] = 'SELECT'; |
| @@ -307,8 +314,15 @@ | ||
| 307 | 314 | public static function get_entry_meta_info( $entry_id ) { |
| 308 | 315 | return FrmDb::get_results( 'frm_item_metas', array( 'item_id' => $entry_id ) ); |
| 309 | 316 | } |
| 310 | 317 | |
| 318 | + /** | |
| 319 | + * @param array $where | |
| 320 | + * @param string $order_by | |
| 321 | + * @param string $limit | |
| 322 | + * @param bool $stripslashes | |
| 323 | + * @return array | |
| 324 | + */ | |
| 311 | 325 | public static function getAll( $where = array(), $order_by = '', $limit = '', $stripslashes = false ) { |
| 312 | 326 | global $wpdb; |
| 313 | 327 | $query = 'SELECT it.*, fi.type as field_type, fi.field_key as field_key, |
| 314 | 328 | fi.required as required, fi.form_id as field_form_id, fi.name as field_name, fi.options as fi_options |
| @@ -361,11 +375,11 @@ | ||
| 361 | 375 | return self::getEntryIds( $query, '', '', true, $args ); |
| 362 | 376 | } |
| 363 | 377 | |
| 364 | 378 | /** |
| 365 | - * @param string|array $where | |
| 366 | - * @param string $order_by | |
| 367 | - * @param string $limit | |
| 379 | + * @param array|string $where | |
| 380 | + * @param string $order_by | |
| 381 | + * @param string $limit | |
| 368 | 382 | */ |
| 369 | 383 | private static function get_ids_query( $where, $order_by, $limit, $unique, $args, array &$query ) { |
| 370 | 384 | global $wpdb; |
| 371 | 385 | $query[] = 'SELECT'; |
| @@ -392,11 +406,31 @@ | ||
| 392 | 406 | $query[] = 'INNER JOIN ' . $wpdb->prefix . 'frm_items e ON (e.id=it.item_id)'; |
| 393 | 407 | if ( is_array( $where ) ) { |
| 394 | 408 | if ( ! $args['is_draft'] ) { |
| 395 | 409 | $where['e.is_draft'] = 0; |
| 396 | - } elseif ( $args['is_draft'] == 1 ) { | |
| 397 | - $where['e.is_draft'] = 1; | |
| 398 | - } | |
| 410 | + } elseif ( is_numeric( $args['is_draft'] ) ) { | |
| 411 | + if ( class_exists( 'FrmAbandonmentHooksController', false ) ) { | |
| 412 | + $where['e.is_draft'] = absint( $args['is_draft'] ); | |
| 413 | + } else { | |
| 414 | + $where['e.is_draft'] = 1; | |
| 415 | + } | |
| 416 | + } elseif ( 'both' === $args['is_draft'] && class_exists( 'FrmAbandonmentHooksController', false ) ) { | |
| 417 | + $where['e.is_draft'] = array( 0, 1 ); | |
| 418 | + } elseif ( false !== strpos( $args['is_draft'], ',' ) ) { | |
| 419 | + $is_draft = array_reduce( | |
| 420 | + explode( ',', $args['is_draft'] ), | |
| 421 | + function ( $total, $current ) { | |
| 422 | + if ( is_numeric( $current ) ) { | |
| 423 | + $total[] = absint( $current ); | |
| 424 | + } | |
| 425 | + return $total; | |
| 426 | + }, | |
| 427 | + array() | |
| 428 | + ); | |
| 429 | + if ( $is_draft ) { | |
| 430 | + $where['e.is_draft'] = $is_draft; | |
| 431 | + } | |
| 432 | + }//end if | |
| 399 | 433 | |
| 400 | 434 | if ( ! empty( $args['user_id'] ) ) { |
| 401 | 435 | $where['e.user_id'] = $args['user_id']; |
| 402 | 436 | } |
| @@ -406,9 +440,9 @@ | ||
| 406 | 440 | $query[] = ' GROUP BY ' . sanitize_text_field( $args['group_by'] ); |
| 407 | 441 | } |
| 408 | 442 | |
| 409 | 443 | return; |
| 410 | - } | |
| 444 | + }//end if | |
| 411 | 445 | |
| 412 | 446 | $draft_where = ''; |
| 413 | 447 | $user_where = ''; |
| 414 | 448 | if ( ! $args['is_draft'] ) { |
| @@ -462,15 +496,15 @@ | ||
| 462 | 496 | } |
| 463 | 497 | $where .= $wpdb->prepare( ' meta_value ' . $operator . ' %s and', $value ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 464 | 498 | } |
| 465 | 499 | $where .= $wpdb->prepare( ' field_id=%d', $field_id ); |
| 466 | - $query = 'SELECT DISTINCT item_id FROM ' . $wpdb->prefix . 'frm_item_metas' . FrmDb::prepend_and_or_where( ' WHERE ', $where ); | |
| 500 | + $query = 'SELECT DISTINCT item_id FROM ' . $wpdb->prefix . 'frm_item_metas' . FrmDb::prepend_and_or_where( ' WHERE ', $where ); | |
| 467 | 501 | } else { |
| 468 | - if ( $operator == 'LIKE' ) { | |
| 502 | + if ( $operator === 'LIKE' ) { | |
| 469 | 503 | $search = '%' . $search . '%'; |
| 470 | 504 | } |
| 471 | 505 | $query = $wpdb->prepare( "SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas WHERE meta_value {$operator} %s and field_id = %d", $search, $field_id ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
| 472 | - } | |
| 506 | + }//end if | |
| 473 | 507 | |
| 474 | 508 | $results = $wpdb->get_col( $query, 0 ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 475 | 509 | FrmDb::set_cache( $cache_key, $results, 'frm_entry' ); |
| 476 | 510 | |