Completed
Push — develop ( b56630...d45961 )
by Zack
16:53
created
includes/widgets/search-widget/class-search-widget.php 1 patch
Spacing   +143 added lines, -143 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 				'type' => 'radio',
65 65
 				'full_width' => true,
66 66
 				'label' => esc_html__( 'Search Mode', 'gravityview' ),
67
-				'desc' => __('Should search results match all search fields, or any?', 'gravityview'),
67
+				'desc' => __( 'Should search results match all search fields, or any?', 'gravityview' ),
68 68
 				'value' => 'any',
69 69
 				'class' => 'hide-if-js',
70 70
 				'options' => array(
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 
87 87
 			// admin - add scripts - run at 1100 to make sure GravityView_Admin_Views::add_scripts_and_styles() runs first at 999
88 88
 			add_action( 'admin_enqueue_scripts', array( $this, 'add_scripts_and_styles' ), 1100 );
89
-			add_action( 'wp_enqueue_scripts', array( $this, 'register_scripts') );
89
+			add_action( 'wp_enqueue_scripts', array( $this, 'register_scripts' ) );
90 90
 			add_filter( 'gravityview_noconflict_scripts', array( $this, 'register_no_conflict' ) );
91 91
 
92 92
 			// ajax - get the searchable fields
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
 		$script_min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
230 230
 		$script_source = empty( $script_min ) ? '/source' : '';
231 231
 
232
-		wp_enqueue_script( 'gravityview_searchwidget_admin', plugins_url( 'assets/js'.$script_source.'/admin-search-widget'.$script_min.'.js', __FILE__ ), array( 'jquery', 'gravityview_views_scripts' ), \GV\Plugin::$version );
232
+		wp_enqueue_script( 'gravityview_searchwidget_admin', plugins_url( 'assets/js' . $script_source . '/admin-search-widget' . $script_min . '.js', __FILE__ ), array( 'jquery', 'gravityview_views_scripts' ), \GV\Plugin::$version );
233 233
 
234 234
 		wp_localize_script( 'gravityview_searchwidget_admin', 'gvSearchVar', array(
235 235
 			'nonce' => wp_create_nonce( 'gravityview_ajaxsearchwidget' ),
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
 	 * @return array Scripts allowed in no-conflict mode, plus the search widget script
252 252
 	 */
253 253
 	public function register_no_conflict( $allowed ) {
254
-		$allowed[] = 'gravityview_searchwidget_admin';
254
+		$allowed[ ] = 'gravityview_searchwidget_admin';
255 255
 		return $allowed;
256 256
 	}
257 257
 
@@ -264,24 +264,24 @@  discard block
 block discarded – undo
264 264
 	 */
265 265
 	public static function get_searchable_fields() {
266 266
 
267
-		if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'gravityview_ajaxsearchwidget' ) ) {
267
+		if ( ! isset( $_POST[ 'nonce' ] ) || ! wp_verify_nonce( $_POST[ 'nonce' ], 'gravityview_ajaxsearchwidget' ) ) {
268 268
 			exit( '0' );
269 269
 		}
270 270
 
271 271
 		$form = '';
272 272
 
273 273
 		// Fetch the form for the current View
274
-		if ( ! empty( $_POST['view_id'] ) ) {
274
+		if ( ! empty( $_POST[ 'view_id' ] ) ) {
275 275
 
276
-			$form = gravityview_get_form_id( $_POST['view_id'] );
276
+			$form = gravityview_get_form_id( $_POST[ 'view_id' ] );
277 277
 
278
-		} elseif ( ! empty( $_POST['formid'] ) ) {
278
+		} elseif ( ! empty( $_POST[ 'formid' ] ) ) {
279 279
 
280
-			$form = (int) $_POST['formid'];
280
+			$form = (int)$_POST[ 'formid' ];
281 281
 
282
-		} elseif ( ! empty( $_POST['template_id'] ) && class_exists( 'GravityView_Ajax' ) ) {
282
+		} elseif ( ! empty( $_POST[ 'template_id' ] ) && class_exists( 'GravityView_Ajax' ) ) {
283 283
 
284
-			$form = GravityView_Ajax::pre_get_form_fields( $_POST['template_id'] );
284
+			$form = GravityView_Ajax::pre_get_form_fields( $_POST[ 'template_id' ] );
285 285
 
286 286
 		}
287 287
 
@@ -331,14 +331,14 @@  discard block
 block discarded – undo
331 331
 		);
332 332
 
333 333
 		if ( gravityview()->plugin->supports( \GV\Plugin::FEATURE_GFQUERY ) ) {
334
-			$custom_fields['is_approved'] = array(
334
+			$custom_fields[ 'is_approved' ] = array(
335 335
 				'text' => esc_html__( 'Approval Status', 'gravityview' ),
336 336
 				'type' => 'multi',
337 337
 			);
338 338
 		}
339 339
 
340
-		foreach( $custom_fields as $custom_field_key => $custom_field ) {
341
-			$output .= sprintf( '<option value="%s" %s data-inputtypes="%s" data-placeholder="%s">%s</option>', $custom_field_key, selected( $custom_field_key, $current, false ), $custom_field['type'], self::get_field_label( array('field' => $custom_field_key ) ), $custom_field['text'] );
340
+		foreach ( $custom_fields as $custom_field_key => $custom_field ) {
341
+			$output .= sprintf( '<option value="%s" %s data-inputtypes="%s" data-placeholder="%s">%s</option>', $custom_field_key, selected( $custom_field_key, $current, false ), $custom_field[ 'type' ], self::get_field_label( array( 'field' => $custom_field_key ) ), $custom_field[ 'text' ] );
342 342
 		}
343 343
 
344 344
 		// Get fields with sub-inputs and no parent
@@ -360,13 +360,13 @@  discard block
 block discarded – undo
360 360
 
361 361
 			foreach ( $fields as $id => $field ) {
362 362
 
363
-				if ( in_array( $field['type'], $blacklist_field_types ) ) {
363
+				if ( in_array( $field[ 'type' ], $blacklist_field_types ) ) {
364 364
 					continue;
365 365
 				}
366 366
 
367
-				$types = self::get_search_input_types( $id, $field['type'] );
367
+				$types = self::get_search_input_types( $id, $field[ 'type' ] );
368 368
 
369
-				$output .= '<option value="'. $id .'" '. selected( $id, $current, false ).'data-inputtypes="'. esc_attr( $types ) .'">'. esc_html( $field['label'] ) .'</option>';
369
+				$output .= '<option value="' . $id . '" ' . selected( $id, $current, false ) . 'data-inputtypes="' . esc_attr( $types ) . '">' . esc_html( $field[ 'label' ] ) . '</option>';
370 370
 			}
371 371
 		}
372 372
 
@@ -389,7 +389,7 @@  discard block
 block discarded – undo
389 389
 	public static function get_search_input_types( $field_id = '', $field_type = null ) {
390 390
 
391 391
 		// @todo - This needs to be improved - many fields have . including products and addresses
392
-		if ( false !== strpos( (string) $field_id, '.' ) && in_array( $field_type, array( 'checkbox' ) ) || in_array( $field_id, array( 'is_fulfilled' ) ) ) {
392
+		if ( false !== strpos( (string)$field_id, '.' ) && in_array( $field_type, array( 'checkbox' ) ) || in_array( $field_id, array( 'is_fulfilled' ) ) ) {
393 393
 			$input_type = 'boolean'; // on/off checkbox
394 394
 		} elseif ( in_array( $field_type, array( 'checkbox', 'post_category', 'multiselect' ) ) ) {
395 395
 			$input_type = 'multi'; //multiselect
@@ -433,19 +433,19 @@  discard block
 block discarded – undo
433 433
 			$post_id = 0;
434 434
 
435 435
 			// We're in the WordPress Widget context, and an overriding post ID has been set.
436
-			if ( ! empty( $widget_args['post_id'] ) ) {
437
-				$post_id = absint( $widget_args['post_id'] );
436
+			if ( ! empty( $widget_args[ 'post_id' ] ) ) {
437
+				$post_id = absint( $widget_args[ 'post_id' ] );
438 438
 			}
439 439
 			// We're in the WordPress Widget context, and the base View ID should be used
440
-			else if ( ! empty( $widget_args['view_id'] ) ) {
441
-				$post_id = absint( $widget_args['view_id'] );
440
+			else if ( ! empty( $widget_args[ 'view_id' ] ) ) {
441
+				$post_id = absint( $widget_args[ 'view_id' ] );
442 442
 			}
443 443
 
444 444
 			$args = gravityview_get_permalink_query_args( $post_id );
445 445
 
446 446
 			// Add hidden fields to the search form
447 447
 			foreach ( $args as $key => $value ) {
448
-				$search_fields[] = array(
448
+				$search_fields[ ] = array(
449 449
 					'name'  => $key,
450 450
 					'input' => 'hidden',
451 451
 					'value' => $value,
@@ -484,22 +484,22 @@  discard block
 block discarded – undo
484 484
 		/**
485 485
 		 * Include the sidebar Widgets.
486 486
 		 */
487
-		$widgets = (array) get_option( 'widget_gravityview_search', array() );
487
+		$widgets = (array)get_option( 'widget_gravityview_search', array() );
488 488
 
489 489
 		foreach ( $widgets as $widget ) {
490
-			if ( ! empty( $widget['view_id'] ) && $widget['view_id'] == $view->ID ) {
491
-				if( $_fields = json_decode( $widget['search_fields'], true ) ) {
490
+			if ( ! empty( $widget[ 'view_id' ] ) && $widget[ 'view_id' ] == $view->ID ) {
491
+				if ( $_fields = json_decode( $widget[ 'search_fields' ], true ) ) {
492 492
 					foreach ( $_fields as $field ) {
493
-						$searchable_fields [] = $with_full_field ? $field : $field['field'];
493
+						$searchable_fields [ ] = $with_full_field ? $field : $field[ 'field' ];
494 494
 					}
495 495
 				}
496 496
 			}
497 497
 		}
498 498
 
499 499
 		foreach ( $view->widgets->by_id( $this->get_widget_id() )->all() as $widget ) {
500
-			if( $_fields = json_decode( $widget->configuration->get( 'search_fields' ), true ) ) {
500
+			if ( $_fields = json_decode( $widget->configuration->get( 'search_fields' ), true ) ) {
501 501
 				foreach ( $_fields as $field ) {
502
-					$searchable_fields [] = $with_full_field ? $field : $field['field'];
502
+					$searchable_fields [ ] = $with_full_field ? $field : $field[ 'field' ];
503 503
 				}
504 504
 			}
505 505
 		}
@@ -529,7 +529,7 @@  discard block
 block discarded – undo
529 529
 			return $search_criteria; // Return the original criteria, GF_Query modification kicks in later
530 530
 		}
531 531
 
532
-		if( 'post' === $this->search_method ) {
532
+		if ( 'post' === $this->search_method ) {
533 533
 			$get = $_POST;
534 534
 		} else {
535 535
 			$get = $_GET;
@@ -548,14 +548,14 @@  discard block
 block discarded – undo
548 548
 		$get = gv_map_deep( $get, 'rawurldecode' );
549 549
 
550 550
 		// Make sure array key is set up
551
-		$search_criteria['field_filters'] = \GV\Utils::get( $search_criteria, 'field_filters', array() );
551
+		$search_criteria[ 'field_filters' ] = \GV\Utils::get( $search_criteria, 'field_filters', array() );
552 552
 
553 553
 		$searchable_fields = $this->get_view_searchable_fields( $view );
554 554
 
555 555
 		// add free search
556
-		if ( isset( $get['gv_search'] ) && '' !== $get['gv_search'] && in_array( 'search_all', $searchable_fields ) ) {
556
+		if ( isset( $get[ 'gv_search' ] ) && '' !== $get[ 'gv_search' ] && in_array( 'search_all', $searchable_fields ) ) {
557 557
 
558
-			$search_all_value = trim( $get['gv_search'] );
558
+			$search_all_value = trim( $get[ 'gv_search' ] );
559 559
 
560 560
 			/**
561 561
 			 * @filter `gravityview/search-all-split-words` Search for each word separately or the whole phrase?
@@ -580,7 +580,7 @@  discard block
 block discarded – undo
580 580
 			}
581 581
 
582 582
 			foreach ( $words as $word ) {
583
-				$search_criteria['field_filters'][] = array(
583
+				$search_criteria[ 'field_filters' ][ ] = array(
584 584
 					'key' => null, // The field ID to search
585 585
 					'value' => $word, // The value to search
586 586
 					'operator' => 'contains', // What to search in. Options: `is` or `contains`
@@ -593,14 +593,14 @@  discard block
 block discarded – undo
593 593
 			/**
594 594
 			 * Get and normalize the dates according to the input format.
595 595
 			 */
596
-			if ( $curr_start = ! empty( $get['gv_start'] ) ? $get['gv_start'] : '' ) {
597
-				if( $curr_start_date = date_create_from_format( $this->get_datepicker_format( true ), $curr_start ) ) {
596
+			if ( $curr_start = ! empty( $get[ 'gv_start' ] ) ? $get[ 'gv_start' ] : '' ) {
597
+				if ( $curr_start_date = date_create_from_format( $this->get_datepicker_format( true ), $curr_start ) ) {
598 598
 					$curr_start = $curr_start_date->format( 'Y-m-d' );
599 599
 				}
600 600
 			}
601 601
 
602
-			if ( $curr_end = ! empty( $get['gv_start'] ) ? ( ! empty( $get['gv_end'] ) ? $get['gv_end'] : '' ) : '' ) {
603
-				if( $curr_end_date = date_create_from_format( $this->get_datepicker_format( true ), $curr_end ) ) {
602
+			if ( $curr_end = ! empty( $get[ 'gv_start' ] ) ? ( ! empty( $get[ 'gv_end' ] ) ? $get[ 'gv_end' ] : '' ) : '' ) {
603
+				if ( $curr_end_date = date_create_from_format( $this->get_datepicker_format( true ), $curr_end ) ) {
604 604
 					$curr_end = $curr_end_date->format( 'Y-m-d' );
605 605
 				}
606 606
 			}
@@ -635,22 +635,22 @@  discard block
 block discarded – undo
635 635
 			 */
636 636
 			if ( ! empty( $curr_start ) ) {
637 637
 				$curr_start = date( 'Y-m-d H:i:s', strtotime( $curr_start ) );
638
-				$search_criteria['start_date'] = $adjust_tz ? get_gmt_from_date( $curr_start ) : $curr_start;
638
+				$search_criteria[ 'start_date' ] = $adjust_tz ? get_gmt_from_date( $curr_start ) : $curr_start;
639 639
 			}
640 640
 
641 641
 			if ( ! empty( $curr_end ) ) {
642 642
 				// Fast-forward 24 hour on the end time
643 643
 				$curr_end = date( 'Y-m-d H:i:s', strtotime( $curr_end ) + DAY_IN_SECONDS );
644
-				$search_criteria['end_date'] = $adjust_tz ? get_gmt_from_date( $curr_end ) : $curr_end;
645
-				if ( strpos( $search_criteria['end_date'], '00:00:00' ) ) { // See https://github.com/gravityview/GravityView/issues/1056
646
-					$search_criteria['end_date'] = date( 'Y-m-d H:i:s', strtotime( $search_criteria['end_date'] ) - 1 );
644
+				$search_criteria[ 'end_date' ] = $adjust_tz ? get_gmt_from_date( $curr_end ) : $curr_end;
645
+				if ( strpos( $search_criteria[ 'end_date' ], '00:00:00' ) ) { // See https://github.com/gravityview/GravityView/issues/1056
646
+					$search_criteria[ 'end_date' ] = date( 'Y-m-d H:i:s', strtotime( $search_criteria[ 'end_date' ] ) - 1 );
647 647
 				}
648 648
 			}
649 649
 		}
650 650
 
651 651
 		// search for a specific entry ID
652 652
 		if ( ! empty( $get[ 'gv_id' ] ) && in_array( 'entry_id', $searchable_fields ) ) {
653
-			$search_criteria['field_filters'][] = array(
653
+			$search_criteria[ 'field_filters' ][ ] = array(
654 654
 				'key' => 'id',
655 655
 				'value' => absint( $get[ 'gv_id' ] ),
656 656
 				'operator' => '=',
@@ -659,41 +659,41 @@  discard block
 block discarded – undo
659 659
 
660 660
 		// search for a specific Created_by ID
661 661
 		if ( ! empty( $get[ 'gv_by' ] ) && in_array( 'created_by', $searchable_fields ) ) {
662
-			$search_criteria['field_filters'][] = array(
662
+			$search_criteria[ 'field_filters' ][ ] = array(
663 663
 				'key' => 'created_by',
664
-				'value' => $get['gv_by'],
664
+				'value' => $get[ 'gv_by' ],
665 665
 				'operator' => '=',
666 666
 			);
667 667
 		}
668 668
 
669 669
 		// Get search mode passed in URL
670
-		$mode = isset( $get['mode'] ) && in_array( $get['mode'], array( 'any', 'all' ) ) ?  $get['mode'] : 'any';
670
+		$mode = isset( $get[ 'mode' ] ) && in_array( $get[ 'mode' ], array( 'any', 'all' ) ) ? $get[ 'mode' ] : 'any';
671 671
 
672 672
 		// get the other search filters
673 673
 		foreach ( $get as $key => $value ) {
674 674
 
675
-			if ( 0 !== strpos( $key, 'filter_' ) || gv_empty( $value, false, false ) || ( is_array( $value ) && count( $value ) === 1 && gv_empty( $value[0], false, false ) ) ) {
675
+			if ( 0 !== strpos( $key, 'filter_' ) || gv_empty( $value, false, false ) || ( is_array( $value ) && count( $value ) === 1 && gv_empty( $value[ 0 ], false, false ) ) ) {
676 676
 				continue;
677 677
 			}
678 678
 
679 679
 			$filter_key = $this->convert_request_key_to_filter_key( $key );
680 680
 
681 681
 			// could return simple filter or multiple filters
682
-			if ( ! in_array( 'search_all', $searchable_fields ) && ! in_array( $filter_key , $searchable_fields ) ) {
682
+			if ( ! in_array( 'search_all', $searchable_fields ) && ! in_array( $filter_key, $searchable_fields ) ) {
683 683
 				continue;
684 684
 			}
685 685
 
686 686
 			$filter = $this->prepare_field_filter( $filter_key, $value, $view );
687 687
 
688
-			if ( isset( $filter[0]['value'] ) ) {
689
-				$search_criteria['field_filters'] = array_merge( $search_criteria['field_filters'], $filter );
688
+			if ( isset( $filter[ 0 ][ 'value' ] ) ) {
689
+				$search_criteria[ 'field_filters' ] = array_merge( $search_criteria[ 'field_filters' ], $filter );
690 690
 
691 691
 				// if date range type, set search mode to ALL
692
-				if ( ! empty( $filter[0]['operator'] ) && in_array( $filter[0]['operator'], array( '>=', '<=', '>', '<' ) ) ) {
692
+				if ( ! empty( $filter[ 0 ][ 'operator' ] ) && in_array( $filter[ 0 ][ 'operator' ], array( '>=', '<=', '>', '<' ) ) ) {
693 693
 					$mode = 'all';
694 694
 				}
695
-			} elseif( !empty( $filter ) ) {
696
-				$search_criteria['field_filters'][] = $filter;
695
+			} elseif ( ! empty( $filter ) ) {
696
+				$search_criteria[ 'field_filters' ][ ] = $filter;
697 697
 			}
698 698
 		}
699 699
 
@@ -702,7 +702,7 @@  discard block
 block discarded – undo
702 702
 		 * @since 1.5.1
703 703
 		 * @param[out,in] string $mode Search mode (`any` vs `all`)
704 704
 		 */
705
-		$search_criteria['field_filters']['mode'] = apply_filters( 'gravityview/search/mode', $mode );
705
+		$search_criteria[ 'field_filters' ][ 'mode' ] = apply_filters( 'gravityview/search/mode', $mode );
706 706
 
707 707
 		gravityview()->log->debug( 'Returned Search Criteria: ', array( 'data' => $search_criteria ) );
708 708
 
@@ -727,19 +727,19 @@  discard block
 block discarded – undo
727 727
 		 */
728 728
 		$search_criteria = $this->filter_entries( array(), null, array( 'id' => $view->ID ), true /** force search_criteria */ );
729 729
 
730
-		if ( empty( $search_criteria['field_filters'] ) ) {
730
+		if ( empty( $search_criteria[ 'field_filters' ] ) ) {
731 731
 			return;
732 732
 		}
733 733
 
734 734
 		$widgets = $view->widgets->by_id( $this->widget_id );
735 735
 		if ( $widgets->count() ) {
736 736
 			$widgets = $widgets->all();
737
-			$widget  = $widgets[0];
737
+			$widget  = $widgets[ 0 ];
738 738
 
739 739
 			$search_fields = json_decode( $widget->configuration->get( 'search_fields' ), true );
740 740
 
741
-			foreach ( (array) $search_fields as $search_field ) {
742
-				if ( 'created_by' === $search_field['field'] && 'input_text' === $search_field['input'] ) {
741
+			foreach ( (array)$search_fields as $search_field ) {
742
+				if ( 'created_by' === $search_field[ 'field' ] && 'input_text' === $search_field[ 'input' ] ) {
743 743
 					$created_by_text_mode = true;
744 744
 				}
745 745
 			}
@@ -747,19 +747,19 @@  discard block
 block discarded – undo
747 747
 
748 748
 		$extra_conditions = array();
749 749
 
750
-		foreach ( $search_criteria['field_filters'] as &$filter ) {
750
+		foreach ( $search_criteria[ 'field_filters' ] as &$filter ) {
751 751
 			if ( ! is_array( $filter ) ) {
752 752
 				continue;
753 753
 			}
754 754
 
755 755
 			// Construct a manual query for unapproved statuses
756
-			if ( 'is_approved' === $filter['key'] && in_array( \GravityView_Entry_Approval_Status::UNAPPROVED, (array) $filter['value'] ) ) {
757
-				$_tmp_query       = new GF_Query( $view->form->ID, array(
756
+			if ( 'is_approved' === $filter[ 'key' ] && in_array( \GravityView_Entry_Approval_Status::UNAPPROVED, (array)$filter[ 'value' ] ) ) {
757
+				$_tmp_query = new GF_Query( $view->form->ID, array(
758 758
 					'field_filters' => array(
759 759
 						array(
760 760
 							'operator' => 'in',
761 761
 							'key'      => 'is_approved',
762
-							'value'    => (array) $filter['value'],
762
+							'value'    => (array)$filter[ 'value' ],
763 763
 						),
764 764
 						array(
765 765
 							'operator' => 'is',
@@ -771,25 +771,25 @@  discard block
 block discarded – undo
771 771
 				) );
772 772
 				$_tmp_query_parts = $_tmp_query->_introspect();
773 773
 
774
-				$extra_conditions[] = $_tmp_query_parts['where'];
774
+				$extra_conditions[ ] = $_tmp_query_parts[ 'where' ];
775 775
 
776 776
 				$filter = false;
777 777
 				continue;
778 778
 			}
779 779
 
780 780
 			// Construct manual query for text mode creator search
781
-			if ( 'created_by' === $filter['key'] && ! empty( $created_by_text_mode ) ) {
782
-				$extra_conditions[] = new GravityView_Widget_Search_GF_Query_Condition( $filter, $view );
781
+			if ( 'created_by' === $filter[ 'key' ] && ! empty( $created_by_text_mode ) ) {
782
+				$extra_conditions[ ] = new GravityView_Widget_Search_GF_Query_Condition( $filter, $view );
783 783
 				$filter = false;
784 784
 				continue;
785 785
 			}
786 786
 
787 787
 			// By default, we want searches to be wildcard for each field.
788
-			$filter['operator'] = empty( $filter['operator'] ) ? 'contains' : $filter['operator'];
788
+			$filter[ 'operator' ] = empty( $filter[ 'operator' ] ) ? 'contains' : $filter[ 'operator' ];
789 789
 
790 790
 			// For multichoice, let's have an in (OR) search.
791
-			if ( is_array( $filter['value'] ) ) {
792
-				$filter['operator'] = 'in'; // @todo what about in contains (OR LIKE chains)?
791
+			if ( is_array( $filter[ 'value' ] ) ) {
792
+				$filter[ 'operator' ] = 'in'; // @todo what about in contains (OR LIKE chains)?
793 793
 			}
794 794
 
795 795
 			/**
@@ -797,10 +797,10 @@  discard block
 block discarded – undo
797 797
 			 * @param string $operator Existing search operator
798 798
 			 * @param array $filter array with `key`, `value`, `operator`, `type` keys
799 799
 			 */
800
-			$filter['operator'] = apply_filters( 'gravityview_search_operator', $filter['operator'], $filter );
800
+			$filter[ 'operator' ] = apply_filters( 'gravityview_search_operator', $filter[ 'operator' ], $filter );
801 801
 		}
802 802
 
803
-		$search_criteria['field_filters'] = array_filter( $search_criteria['field_filters'] );
803
+		$search_criteria[ 'field_filters' ] = array_filter( $search_criteria[ 'field_filters' ] );
804 804
 
805 805
 		/**
806 806
 		 * Parse the filter criteria to generate the needed
@@ -813,12 +813,12 @@  discard block
 block discarded – undo
813 813
 		/**
814 814
 		 * Grab the current clauses. We'll be combining them shortly.
815 815
 		 */
816
-		$query_parts      = $query->_introspect();
816
+		$query_parts = $query->_introspect();
817 817
 
818 818
 		/**
819 819
 		 * Combine the parts as a new WHERE clause.
820 820
 		 */
821
-		$where = call_user_func_array( '\GF_Query_Condition::_and', array_merge( array( $query_parts['where'], $_tmp_query_parts['where'] ), $extra_conditions ) );
821
+		$where = call_user_func_array( '\GF_Query_Condition::_and', array_merge( array( $query_parts[ 'where' ], $_tmp_query_parts[ 'where' ] ), $extra_conditions ) );
822 822
 		$query->where( $where );
823 823
 	}
824 824
 
@@ -841,7 +841,7 @@  discard block
 block discarded – undo
841 841
 		$field_id = str_replace( 'filter_', '', $key );
842 842
 
843 843
 		// calculates field_id, removing 'filter_' and for '_' for advanced fields ( like name or checkbox )
844
-		if ( preg_match('/^[0-9_]+$/ism', $field_id ) ) {
844
+		if ( preg_match( '/^[0-9_]+$/ism', $field_id ) ) {
845 845
 			$field_id = str_replace( '_', '.', $field_id );
846 846
 		}
847 847
 
@@ -876,7 +876,7 @@  discard block
 block discarded – undo
876 876
 
877 877
 			case 'select':
878 878
 			case 'radio':
879
-				$filter['operator'] = 'is';
879
+				$filter[ 'operator' ] = 'is';
880 880
 				break;
881 881
 
882 882
 			case 'post_category':
@@ -890,7 +890,7 @@  discard block
 block discarded – undo
890 890
 
891 891
 				foreach ( $value as $val ) {
892 892
 					$cat = get_term( $val, 'category' );
893
-					$filter[] = array(
893
+					$filter[ ] = array(
894 894
 						'key'      => $filter_key,
895 895
 						'value'    => esc_attr( $cat->name ) . ':' . $val,
896 896
 						'operator' => 'is',
@@ -909,7 +909,7 @@  discard block
 block discarded – undo
909 909
 				$filter = array();
910 910
 
911 911
 				foreach ( $value as $val ) {
912
-					$filter[] = array( 'key' => $filter_key, 'value' => $val );
912
+					$filter[ ] = array( 'key' => $filter_key, 'value' => $val );
913 913
 				}
914 914
 
915 915
 				break;
@@ -918,9 +918,9 @@  discard block
 block discarded – undo
918 918
 				// convert checkbox on/off into the correct search filter
919 919
 				if ( false !== strpos( $filter_key, '.' ) && ! empty( $form_field->inputs ) && ! empty( $form_field->choices ) ) {
920 920
 					foreach ( $form_field->inputs as $k => $input ) {
921
-						if ( $input['id'] == $filter_key ) {
922
-							$filter['value'] = $form_field->choices[ $k ]['value'];
923
-							$filter['operator'] = 'is';
921
+						if ( $input[ 'id' ] == $filter_key ) {
922
+							$filter[ 'value' ] = $form_field->choices[ $k ][ 'value' ];
923
+							$filter[ 'operator' ] = 'is';
924 924
 							break;
925 925
 						}
926 926
 					}
@@ -930,7 +930,7 @@  discard block
 block discarded – undo
930 930
 					$filter = array();
931 931
 
932 932
 					foreach ( $value as $val ) {
933
-						$filter[] = array(
933
+						$filter[ ] = array(
934 934
 							'key'      => $filter_key,
935 935
 							'value'    => $val,
936 936
 							'operator' => 'is',
@@ -951,9 +951,9 @@  discard block
 block discarded – undo
951 951
 					foreach ( $words as $word ) {
952 952
 						if ( ! empty( $word ) && strlen( $word ) > 1 ) {
953 953
 							// Keep the same key for each filter
954
-							$filter['value'] = $word;
954
+							$filter[ 'value' ] = $word;
955 955
 							// Add a search for the value
956
-							$filters[] = $filter;
956
+							$filters[ ] = $filter;
957 957
 						}
958 958
 					}
959 959
 
@@ -967,19 +967,19 @@  discard block
 block discarded – undo
967 967
 
968 968
 					foreach ( $searchable_fields as $searchable_field ) {
969 969
 
970
-						if( $form_field->ID !== $searchable_field['field'] ) {
970
+						if ( $form_field->ID !== $searchable_field[ 'field' ] ) {
971 971
 							continue;
972 972
 						}
973 973
 
974 974
 						// Only exact-match dropdowns, not text search
975
-						if( in_array( $searchable_field['input'], array( 'text', 'search' ), true ) ) {
975
+						if ( in_array( $searchable_field[ 'input' ], array( 'text', 'search' ), true ) ) {
976 976
 							continue;
977 977
 						}
978 978
 
979 979
 						$input_id = gravityview_get_input_id_from_id( $form_field->ID );
980 980
 
981 981
 						if ( 4 === $input_id ) {
982
-							$filter['operator'] = 'is';
982
+							$filter[ 'operator' ] = 'is';
983 983
 						};
984 984
 					}
985 985
 				}
@@ -1006,12 +1006,12 @@  discard block
 block discarded – undo
1006 1006
 						 * @since 1.16.3
1007 1007
 						 * Safeguard until GF implements '<=' operator
1008 1008
 						 */
1009
-						if( !GFFormsModel::is_valid_operator( $operator ) && $operator === '<=' ) {
1009
+						if ( ! GFFormsModel::is_valid_operator( $operator ) && $operator === '<=' ) {
1010 1010
 							$operator = '<';
1011 1011
 							$date = date( 'Y-m-d', strtotime( self::get_formatted_date( $date, 'Y-m-d', $date_format ) . ' +1 day' ) );
1012 1012
 						}
1013 1013
 
1014
-						$filter[] = array(
1014
+						$filter[ ] = array(
1015 1015
 							'key'      => $filter_key,
1016 1016
 							'value'    => self::get_formatted_date( $date, 'Y-m-d', $date_format ),
1017 1017
 							'operator' => $operator,
@@ -1019,7 +1019,7 @@  discard block
 block discarded – undo
1019 1019
 					}
1020 1020
 				} else {
1021 1021
 					$date = $value;
1022
-					$filter['value'] = self::get_formatted_date( $date, 'Y-m-d', $date_format );
1022
+					$filter[ 'value' ] = self::get_formatted_date( $date, 'Y-m-d', $date_format );
1023 1023
 				}
1024 1024
 
1025 1025
 				break;
@@ -1050,7 +1050,7 @@  discard block
 block discarded – undo
1050 1050
 			'ymd_dot' => 'Y.m.d',
1051 1051
 		);
1052 1052
 
1053
-		if ( ! empty( $field->dateFormat ) && isset( $datepicker[ $field->dateFormat ] ) ){
1053
+		if ( ! empty( $field->dateFormat ) && isset( $datepicker[ $field->dateFormat ] ) ) {
1054 1054
 			$format = $datepicker[ $field->dateFormat ];
1055 1055
 		}
1056 1056
 
@@ -1087,7 +1087,7 @@  discard block
 block discarded – undo
1087 1087
 	public function add_template_path( $file_paths ) {
1088 1088
 
1089 1089
 		// Index 100 is the default GravityView template path.
1090
-		$file_paths[102] = self::$file . 'templates/';
1090
+		$file_paths[ 102 ] = self::$file . 'templates/';
1091 1091
 
1092 1092
 		return $file_paths;
1093 1093
 	}
@@ -1106,7 +1106,7 @@  discard block
 block discarded – undo
1106 1106
 		$has_date = false;
1107 1107
 
1108 1108
 		foreach ( $search_fields as $k => $field ) {
1109
-			if ( in_array( $field['input'], array( 'date', 'date_range', 'entry_date' ) ) ) {
1109
+			if ( in_array( $field[ 'input' ], array( 'date', 'date_range', 'entry_date' ) ) ) {
1110 1110
 				$has_date = true;
1111 1111
 				break;
1112 1112
 			}
@@ -1133,7 +1133,7 @@  discard block
 block discarded – undo
1133 1133
 		}
1134 1134
 
1135 1135
 		// get configured search fields
1136
-		$search_fields = ! empty( $widget_args['search_fields'] ) ? json_decode( $widget_args['search_fields'], true ) : '';
1136
+		$search_fields = ! empty( $widget_args[ 'search_fields' ] ) ? json_decode( $widget_args[ 'search_fields' ], true ) : '';
1137 1137
 
1138 1138
 		if ( empty( $search_fields ) || ! is_array( $search_fields ) ) {
1139 1139
 			gravityview()->log->debug( 'No search fields configured for widget:', array( 'data' => $widget_args ) );
@@ -1148,40 +1148,40 @@  discard block
 block discarded – undo
1148 1148
 
1149 1149
 			$updated_field = $this->get_search_filter_details( $updated_field );
1150 1150
 
1151
-			switch ( $field['field'] ) {
1151
+			switch ( $field[ 'field' ] ) {
1152 1152
 
1153 1153
 				case 'search_all':
1154
-					$updated_field['key'] = 'search_all';
1155
-					$updated_field['input'] = 'search_all';
1156
-					$updated_field['value'] = $this->rgget_or_rgpost( 'gv_search' );
1154
+					$updated_field[ 'key' ] = 'search_all';
1155
+					$updated_field[ 'input' ] = 'search_all';
1156
+					$updated_field[ 'value' ] = $this->rgget_or_rgpost( 'gv_search' );
1157 1157
 					break;
1158 1158
 
1159 1159
 				case 'entry_date':
1160
-					$updated_field['key'] = 'entry_date';
1161
-					$updated_field['input'] = 'entry_date';
1162
-					$updated_field['value'] = array(
1160
+					$updated_field[ 'key' ] = 'entry_date';
1161
+					$updated_field[ 'input' ] = 'entry_date';
1162
+					$updated_field[ 'value' ] = array(
1163 1163
 						'start' => $this->rgget_or_rgpost( 'gv_start' ),
1164 1164
 						'end' => $this->rgget_or_rgpost( 'gv_end' ),
1165 1165
 					);
1166 1166
 					break;
1167 1167
 
1168 1168
 				case 'entry_id':
1169
-					$updated_field['key'] = 'entry_id';
1170
-					$updated_field['input'] = 'entry_id';
1171
-					$updated_field['value'] = $this->rgget_or_rgpost( 'gv_id' );
1169
+					$updated_field[ 'key' ] = 'entry_id';
1170
+					$updated_field[ 'input' ] = 'entry_id';
1171
+					$updated_field[ 'value' ] = $this->rgget_or_rgpost( 'gv_id' );
1172 1172
 					break;
1173 1173
 
1174 1174
 				case 'created_by':
1175
-					$updated_field['key'] = 'created_by';
1176
-					$updated_field['name'] = 'gv_by';
1177
-					$updated_field['value'] = $this->rgget_or_rgpost( 'gv_by' );
1178
-					$updated_field['choices'] = self::get_created_by_choices();
1175
+					$updated_field[ 'key' ] = 'created_by';
1176
+					$updated_field[ 'name' ] = 'gv_by';
1177
+					$updated_field[ 'value' ] = $this->rgget_or_rgpost( 'gv_by' );
1178
+					$updated_field[ 'choices' ] = self::get_created_by_choices();
1179 1179
 					break;
1180 1180
 				
1181 1181
 				case 'is_approved':
1182
-					$updated_field['key'] = 'is_approved';
1183
-					$updated_field['value'] = $this->rgget_or_rgpost( 'filter_is_approved' );
1184
-					$updated_field['choices'] = self::get_is_approved_choices();
1182
+					$updated_field[ 'key' ] = 'is_approved';
1183
+					$updated_field[ 'value' ] = $this->rgget_or_rgpost( 'filter_is_approved' );
1184
+					$updated_field[ 'choices' ] = self::get_is_approved_choices();
1185 1185
 					break;
1186 1186
 			}
1187 1187
 
@@ -1200,16 +1200,16 @@  discard block
 block discarded – undo
1200 1200
 		 */
1201 1201
 		$gravityview_view->search_fields = apply_filters( 'gravityview_widget_search_filters', $search_fields, $this, $widget_args, $context );
1202 1202
 
1203
-		$gravityview_view->search_layout = ! empty( $widget_args['search_layout'] ) ? $widget_args['search_layout'] : 'horizontal';
1203
+		$gravityview_view->search_layout = ! empty( $widget_args[ 'search_layout' ] ) ? $widget_args[ 'search_layout' ] : 'horizontal';
1204 1204
 
1205 1205
 		/** @since 1.14 */
1206
-		$gravityview_view->search_mode = ! empty( $widget_args['search_mode'] ) ? $widget_args['search_mode'] : 'any';
1206
+		$gravityview_view->search_mode = ! empty( $widget_args[ 'search_mode' ] ) ? $widget_args[ 'search_mode' ] : 'any';
1207 1207
 
1208
-		$custom_class = ! empty( $widget_args['custom_class'] ) ? $widget_args['custom_class'] : '';
1208
+		$custom_class = ! empty( $widget_args[ 'custom_class' ] ) ? $widget_args[ 'custom_class' ] : '';
1209 1209
 
1210 1210
 		$gravityview_view->search_class = self::get_search_class( $custom_class );
1211 1211
 
1212
-		$gravityview_view->search_clear = ! empty( $widget_args['search_clear'] ) ? $widget_args['search_clear'] : false;
1212
+		$gravityview_view->search_clear = ! empty( $widget_args[ 'search_clear' ] ) ? $widget_args[ 'search_clear' ] : false;
1213 1213
 
1214 1214
 		if ( $this->has_date_field( $search_fields ) ) {
1215 1215
 			// enqueue datepicker stuff only if needed!
@@ -1231,10 +1231,10 @@  discard block
 block discarded – undo
1231 1231
 	public static function get_search_class( $custom_class = '' ) {
1232 1232
 		$gravityview_view = GravityView_View::getInstance();
1233 1233
 
1234
-		$search_class = 'gv-search-'.$gravityview_view->search_layout;
1234
+		$search_class = 'gv-search-' . $gravityview_view->search_layout;
1235 1235
 
1236
-		if ( ! empty( $custom_class )  ) {
1237
-			$search_class .= ' '.$custom_class;
1236
+		if ( ! empty( $custom_class ) ) {
1237
+			$search_class .= ' ' . $custom_class;
1238 1238
 		}
1239 1239
 
1240 1240
 		/**
@@ -1278,9 +1278,9 @@  discard block
 block discarded – undo
1278 1278
 
1279 1279
 		if ( ! $label ) {
1280 1280
 
1281
-			$label = isset( $form_field['label'] ) ? $form_field['label'] : '';
1281
+			$label = isset( $form_field[ 'label' ] ) ? $form_field[ 'label' ] : '';
1282 1282
 
1283
-			switch( $field['field'] ) {
1283
+			switch ( $field[ 'field' ] ) {
1284 1284
 				case 'search_all':
1285 1285
 					$label = __( 'Search Entries:', 'gravityview' );
1286 1286
 					break;
@@ -1292,10 +1292,10 @@  discard block
 block discarded – undo
1292 1292
 					break;
1293 1293
 				default:
1294 1294
 					// If this is a field input, not a field
1295
-					if ( strpos( $field['field'], '.' ) > 0 && ! empty( $form_field['inputs'] ) ) {
1295
+					if ( strpos( $field[ 'field' ], '.' ) > 0 && ! empty( $form_field[ 'inputs' ] ) ) {
1296 1296
 
1297 1297
 						// Get the label for the field in question, which returns an array
1298
-						$items = wp_list_filter( $form_field['inputs'], array( 'id' => $field['field'] ) );
1298
+						$items = wp_list_filter( $form_field[ 'inputs' ], array( 'id' => $field[ 'field' ] ) );
1299 1299
 
1300 1300
 						// Get the item with the `label` key
1301 1301
 						$values = wp_list_pluck( $items, 'label' );
@@ -1334,32 +1334,32 @@  discard block
 block discarded – undo
1334 1334
 		$form = $gravityview_view->getForm();
1335 1335
 
1336 1336
 		// for advanced field ids (eg, first name / last name )
1337
-		$name = 'filter_' . str_replace( '.', '_', $field['field'] );
1337
+		$name = 'filter_' . str_replace( '.', '_', $field[ 'field' ] );
1338 1338
 
1339 1339
 		// get searched value from $_GET/$_POST (string or array)
1340 1340
 		$value = $this->rgget_or_rgpost( $name );
1341 1341
 
1342 1342
 		// get form field details
1343
-		$form_field = gravityview_get_field( $form, $field['field'] );
1343
+		$form_field = gravityview_get_field( $form, $field[ 'field' ] );
1344 1344
 
1345 1345
 		$filter = array(
1346
-			'key' => $field['field'],
1346
+			'key' => $field[ 'field' ],
1347 1347
 			'name' => $name,
1348 1348
 			'label' => self::get_field_label( $field, $form_field ),
1349
-			'input' => $field['input'],
1349
+			'input' => $field[ 'input' ],
1350 1350
 			'value' => $value,
1351
-			'type' => $form_field['type'],
1351
+			'type' => $form_field[ 'type' ],
1352 1352
 		);
1353 1353
 
1354 1354
 		// collect choices
1355
-		if ( 'post_category' === $form_field['type'] && ! empty( $form_field['displayAllCategories'] ) && empty( $form_field['choices'] ) ) {
1356
-			$filter['choices'] = gravityview_get_terms_choices();
1357
-		} elseif ( ! empty( $form_field['choices'] ) ) {
1358
-			$filter['choices'] = $form_field['choices'];
1355
+		if ( 'post_category' === $form_field[ 'type' ] && ! empty( $form_field[ 'displayAllCategories' ] ) && empty( $form_field[ 'choices' ] ) ) {
1356
+			$filter[ 'choices' ] = gravityview_get_terms_choices();
1357
+		} elseif ( ! empty( $form_field[ 'choices' ] ) ) {
1358
+			$filter[ 'choices' ] = $form_field[ 'choices' ];
1359 1359
 		}
1360 1360
 
1361
-		if ( 'date_range' === $field['input'] && empty( $value ) ) {
1362
-			$filter['value'] = array( 'start' => '', 'end' => '' );
1361
+		if ( 'date_range' === $field[ 'input' ] && empty( $value ) ) {
1362
+			$filter[ 'value' ] = array( 'start' => '', 'end' => '' );
1363 1363
 		}
1364 1364
 
1365 1365
 		return $filter;
@@ -1383,7 +1383,7 @@  discard block
 block discarded – undo
1383 1383
 
1384 1384
 		$choices = array();
1385 1385
 		foreach ( $users as $user ) {
1386
-			$choices[] = array(
1386
+			$choices[ ] = array(
1387 1387
 				'value' => $user->ID,
1388 1388
 				'text' => $user->display_name,
1389 1389
 			);
@@ -1403,9 +1403,9 @@  discard block
 block discarded – undo
1403 1403
 
1404 1404
 		$choices = array();
1405 1405
 		foreach ( GravityView_Entry_Approval_Status::get_all() as $status ) {
1406
-			$choices[] = array(
1407
-				'value' => $status['value'],
1408
-				'text' => $status['label'],
1406
+			$choices[ ] = array(
1407
+				'value' => $status[ 'value' ],
1408
+				'text' => $status[ 'label' ],
1409 1409
 			);
1410 1410
 		}
1411 1411
 
@@ -1457,7 +1457,7 @@  discard block
 block discarded – undo
1457 1457
 	 */
1458 1458
 	public function add_datepicker_js_dependency( $js_dependencies ) {
1459 1459
 
1460
-		$js_dependencies[] = 'jquery-ui-datepicker';
1460
+		$js_dependencies[ ] = 'jquery-ui-datepicker';
1461 1461
 
1462 1462
 		return $js_dependencies;
1463 1463
 	}
@@ -1501,7 +1501,7 @@  discard block
 block discarded – undo
1501 1501
 			'isRTL'             => is_rtl(),
1502 1502
 		), $view_data );
1503 1503
 
1504
-		$localizations['datepicker'] = $datepicker_settings;
1504
+		$localizations[ 'datepicker' ] = $datepicker_settings;
1505 1505
 
1506 1506
 		return $localizations;
1507 1507
 
@@ -1528,7 +1528,7 @@  discard block
 block discarded – undo
1528 1528
 	 * @return void
1529 1529
 	 */
1530 1530
 	private function maybe_enqueue_flexibility() {
1531
-		if ( isset( $_SERVER['HTTP_USER_AGENT'] ) && preg_match( '/MSIE [8-9]/', $_SERVER['HTTP_USER_AGENT'] ) ) {
1531
+		if ( isset( $_SERVER[ 'HTTP_USER_AGENT' ] ) && preg_match( '/MSIE [8-9]/', $_SERVER[ 'HTTP_USER_AGENT' ] ) ) {
1532 1532
 			wp_enqueue_script( 'gv-flexibility' );
1533 1533
 		}
1534 1534
 	}
@@ -1550,7 +1550,7 @@  discard block
 block discarded – undo
1550 1550
 		add_filter( 'gravityview_js_localization', array( $this, 'add_datepicker_localization' ), 10, 2 );
1551 1551
 
1552 1552
 		$scheme = is_ssl() ? 'https://' : 'http://';
1553
-		wp_enqueue_style( 'jquery-ui-datepicker', $scheme.'ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/themes/smoothness/jquery-ui.css' );
1553
+		wp_enqueue_style( 'jquery-ui-datepicker', $scheme . 'ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/themes/smoothness/jquery-ui.css' );
1554 1554
 
1555 1555
 		/**
1556 1556
 		 * @filter `gravityview_search_datepicker_class`
@@ -1629,7 +1629,7 @@  discard block
 block discarded – undo
1629 1629
 	public function add_preview_inputs() {
1630 1630
 		global $wp;
1631 1631
 
1632
-		if ( ! is_preview() || ! current_user_can( 'publish_gravityviews') ) {
1632
+		if ( ! is_preview() || ! current_user_can( 'publish_gravityviews' ) ) {
1633 1633
 			return;
1634 1634
 		}
1635 1635
 
@@ -1654,7 +1654,7 @@  discard block
 block discarded – undo
1654 1654
  */
1655 1655
 class GravityView_Widget_Search_GF_Query_Condition extends \GF_Query_Condition {
1656 1656
 	public function __construct( $filter, $view ) {
1657
-		$this->value = $filter['value'];
1657
+		$this->value = $filter[ 'value' ];
1658 1658
 		$this->view = $view;
1659 1659
 	}
1660 1660
 
@@ -1686,11 +1686,11 @@  discard block
 block discarded – undo
1686 1686
 		$conditions = array();
1687 1687
 
1688 1688
 		foreach ( $user_fields as $user_field ) {
1689
-			$conditions[] = $wpdb->prepare( "`u`.`$user_field` LIKE %s", '%' . $wpdb->esc_like( $this->value ) .  '%' );
1689
+			$conditions[ ] = $wpdb->prepare( "`u`.`$user_field` LIKE %s", '%' . $wpdb->esc_like( $this->value ) . '%' );
1690 1690
 		}
1691 1691
 
1692 1692
 		foreach ( $user_meta_fields as $meta_field ) {
1693
-			$conditions[] = $wpdb->prepare( "(`um`.`meta_key` = %s AND `um`.`meta_value` LIKE %s)", $meta_field, '%' . $wpdb->esc_like( $this->value ) .  '%' );
1693
+			$conditions[ ] = $wpdb->prepare( "(`um`.`meta_key` = %s AND `um`.`meta_value` LIKE %s)", $meta_field, '%' . $wpdb->esc_like( $this->value ) . '%' );
1694 1694
 		}
1695 1695
 
1696 1696
 		$conditions = '(' . implode( ' OR ', $conditions ) . ')';
Please login to merge, or discard this patch.