Completed
Pull Request — master (#756)
by Zack
16:02 queued 11:18
created
includes/admin/class-gravityview-admin-view-item.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -42,9 +42,9 @@  discard block
 block discarded – undo
42 42
 	function __construct( $title = '', $item_id, $item = array(), $settings = array() ) {
43 43
 
44 44
 		// Backward compat
45
-		if ( ! empty( $item['type'] ) ) {
46
-			$item['input_type'] = $item['type'];
47
-			unset( $item['type'] );
45
+		if ( ! empty( $item[ 'type' ] ) ) {
46
+			$item[ 'input_type' ] = $item[ 'type' ];
47
+			unset( $item[ 'type' ] );
48 48
 		}
49 49
 
50 50
 		// Prevent items from not having index set
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 		$this->item       = $item;
65 65
 		$this->id         = $item_id;
66 66
 		$this->settings   = $settings;
67
-		$this->label_type = $item['label_type'];
67
+		$this->label_type = $item[ 'label_type' ];
68 68
 	}
69 69
 
70 70
 	/**
@@ -107,10 +107,10 @@  discard block
 block discarded – undo
107 107
 		if ( $html ) {
108 108
 
109 109
 			foreach ( $field_info_items as $item ) {
110
-				$class = isset( $item['class'] ) ? sanitize_html_class( $item['class'] ) . ' description' : 'description';
110
+				$class = isset( $item[ 'class' ] ) ? sanitize_html_class( $item[ 'class' ] ) . ' description' : 'description';
111 111
 				// Add the title in case the value's long, in which case, it'll be truncated by CSS.
112 112
 				$output .= '<span class="' . $class . '">';
113
-				$output .= esc_html( $item['value'] );
113
+				$output .= esc_html( $item[ 'value' ] );
114 114
 				$output .= '</span>';
115 115
 			}
116 116
 
@@ -138,29 +138,29 @@  discard block
 block discarded – undo
138 138
 
139 139
 		// $settings_html will just be hidden inputs if empty. Otherwise, it'll have an <ul>. Ugly hack, I know.
140 140
 		// TODO: Un-hack this
141
-		$hide_settings_link = ( empty( $this->item['settings_html'] ) || strpos( $this->item['settings_html'], '<!-- No Options -->' ) > 0 ) ? 'hide-if-js' : '';
141
+		$hide_settings_link = ( empty( $this->item[ 'settings_html' ] ) || strpos( $this->item[ 'settings_html' ], '<!-- No Options -->' ) > 0 ) ? 'hide-if-js' : '';
142 142
 		$settings_link      = sprintf( '<a href="#settings" class="dashicons-admin-generic dashicons %s" title="%s"></a>', $hide_settings_link, esc_attr( $settings_title ) );
143 143
 
144 144
 		// Should we show the icon that the field is being used as a link to single entry?
145
-		$hide_show_as_link_class = empty( $this->settings['show_as_link'] ) ? 'hide-if-js' : '';
145
+		$hide_show_as_link_class = empty( $this->settings[ 'show_as_link' ] ) ? 'hide-if-js' : '';
146 146
 		$show_as_link            = '<span class="dashicons dashicons-admin-links ' . $hide_show_as_link_class . '" title="' . esc_attr( $single_link_title ) . '"></span>';
147 147
 
148 148
 		// When a field label is empty, use the Field ID
149 149
 		$label = empty( $this->title ) ? sprintf( _x( 'Field #%s (No Label)', 'Label in field picker for empty label', 'gravityview' ), $this->id ) : $this->title;
150 150
 
151 151
 		// If there's a custom label, and show label is checked, use that as the field heading
152
-		if ( ! empty( $this->settings['custom_label'] ) && ! empty( $this->settings['show_label'] ) ) {
153
-			$label = $this->settings['custom_label'];
154
-		} else if ( ! empty( $this->item['customLabel'] ) ) {
155
-			$label = $this->item['customLabel'];
152
+		if ( ! empty( $this->settings[ 'custom_label' ] ) && ! empty( $this->settings[ 'show_label' ] ) ) {
153
+			$label = $this->settings[ 'custom_label' ];
154
+		} else if ( ! empty( $this->item[ 'customLabel' ] ) ) {
155
+			$label = $this->item[ 'customLabel' ];
156 156
 		}
157 157
 
158 158
 		$output = '<h5 class="selectable gfield field-id-' . esc_attr( $this->id ) . '">';
159 159
 
160 160
 		$label = esc_attr( $label );
161 161
 
162
-		if ( ! empty( $this->item['parent'] ) ) {
163
-			$label .= ' <small>(' . esc_attr( $this->item['parent']['label'] ) . ')</small>';
162
+		if ( ! empty( $this->item[ 'parent' ] ) ) {
163
+			$label .= ' <small>(' . esc_attr( $this->item[ 'parent' ][ 'label' ] ) . ')</small>';
164 164
 		}
165 165
 
166 166
 		// Name of field / widget
@@ -176,9 +176,9 @@  discard block
 block discarded – undo
176 176
 
177 177
 		$output .= '</h5>';
178 178
 
179
-		$container_class = ! empty( $this->item['parent'] ) ? ' gv-child-field' : '';
179
+		$container_class = ! empty( $this->item[ 'parent' ] ) ? ' gv-child-field' : '';
180 180
 
181
-		$output = '<div data-fieldid="' . esc_attr( $this->id ) . '" data-inputtype="' . esc_attr( $this->item['input_type'] ) . '" class="gv-fields' . $container_class . '">' . $output . $this->item['settings_html'] . '</div>';
181
+		$output = '<div data-fieldid="' . esc_attr( $this->id ) . '" data-inputtype="' . esc_attr( $this->item[ 'input_type' ] ) . '" class="gv-fields' . $container_class . '">' . $output . $this->item[ 'settings_html' ] . '</div>';
182 182
 
183 183
 		return $output;
184 184
 	}
Please login to merge, or discard this patch.
includes/class-common.php 1 patch
Spacing   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 
125 125
 		$entry = self::get_entry( $entry_slug, true );
126 126
 
127
-		$form = self::get_form( $entry['form_id'] );
127
+		$form = self::get_form( $entry[ 'form_id' ] );
128 128
 
129 129
 		return $form;
130 130
 	}
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 
183 183
 		$results = GFAPI::get_entries( intval( $form_id ), $search_criteria, null, $paging );
184 184
 
185
-		$result = ( ! empty( $results ) && ! empty( $results[0]['id'] ) ) ? $results[0]['id'] : null;
185
+		$result = ( ! empty( $results ) && ! empty( $results[ 0 ][ 'id' ] ) ) ? $results[ 0 ][ 'id' ] : null;
186 186
 
187 187
 		return $result;
188 188
 	}
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
 	 *
198 198
 	 * @return array Empty array if GFAPI class isn't available or no forms. Otherwise, the array of Forms
199 199
 	 */
200
-	public static function get_forms(  $active = true, $trash = false ) {
200
+	public static function get_forms( $active = true, $trash = false ) {
201 201
 		$forms = array();
202 202
 		if ( class_exists( 'GFAPI' ) ) {
203 203
 			$forms = GFAPI::get_forms( $active, $trash );
@@ -225,10 +225,10 @@  discard block
 block discarded – undo
225 225
 		$has_post_fields = false;
226 226
 
227 227
 		if ( $form ) {
228
-			foreach ( $form['fields'] as $field ) {
228
+			foreach ( $form[ 'fields' ] as $field ) {
229 229
 
230
-				if ( $include_parent_field || empty( $field['inputs'] ) ) {
231
-					$fields["{$field->id}"] = array(
230
+				if ( $include_parent_field || empty( $field[ 'inputs' ] ) ) {
231
+					$fields[ "{$field->id}" ] = array(
232 232
 						'label' => rgar( $field, 'label' ),
233 233
 						'parent' => null,
234 234
 						'type' => rgar( $field, 'type' ),
@@ -243,10 +243,10 @@  discard block
 block discarded – undo
243 243
                          * @hack
244 244
                          * In case of email/email confirmation, the input for email has the same id as the parent field
245 245
                          */
246
-						if( 'email' === $field->type && false === strpos( $input['id'], '.' ) ) {
246
+						if ( 'email' === $field->type && false === strpos( $input[ 'id' ], '.' ) ) {
247 247
                             continue;
248 248
                         }
249
-						$fields["{$input['id']}"] = array(
249
+						$fields[ "{$input[ 'id' ]}" ] = array(
250 250
 							'label' => rgar( $input, 'label' ),
251 251
 							'customLabel' => rgar( $input, 'customLabel' ),
252 252
 							'parent' => $field,
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
 				}
259 259
 
260 260
 
261
-				if( GFCommon::is_product_field( $field->type ) ){
261
+				if ( GFCommon::is_product_field( $field->type ) ) {
262 262
 					$has_product_fields = true;
263 263
 				}
264 264
 
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
 		 * @since 1.7
273 273
 		 */
274 274
 		if ( $has_post_fields ) {
275
-			$fields['post_id'] = array(
275
+			$fields[ 'post_id' ] = array(
276 276
 				'label' => __( 'Post ID', 'gravityview' ),
277 277
 				'type' => 'post_id',
278 278
 			);
@@ -283,10 +283,10 @@  discard block
 block discarded – undo
283 283
 			$payment_fields = GravityView_Fields::get_all( 'pricing' );
284 284
 
285 285
 			foreach ( $payment_fields as $payment_field ) {
286
-				if( isset( $fields["{$payment_field->name}"] ) ) {
286
+				if ( isset( $fields[ "{$payment_field->name}" ] ) ) {
287 287
 					continue;
288 288
 				}
289
-				$fields["{$payment_field->name}"] = array(
289
+				$fields[ "{$payment_field->name}" ] = array(
290 290
 					'label' => $payment_field->label,
291 291
 					'desc' => $payment_field->description,
292 292
 					'type' => $payment_field->name,
@@ -318,9 +318,9 @@  discard block
 block discarded – undo
318 318
 
319 319
 		$fields = array();
320 320
 
321
-		foreach ( $extra_fields as $key => $field ){
322
-			if ( ! empty( $only_default_column ) && ! empty( $field['is_default_column'] ) ) {
323
-				$fields[ $key ] = array( 'label' => $field['label'], 'type' => 'entry_meta' );
321
+		foreach ( $extra_fields as $key => $field ) {
322
+			if ( ! empty( $only_default_column ) && ! empty( $field[ 'is_default_column' ] ) ) {
323
+				$fields[ $key ] = array( 'label' => $field[ 'label' ], 'type' => 'entry_meta' );
324 324
 			}
325 325
 		}
326 326
 
@@ -360,32 +360,32 @@  discard block
 block discarded – undo
360 360
 			'search_criteria' => null,
361 361
 			'sorting' => null,
362 362
 			'paging' => null,
363
-			'cache' => (isset( $passed_criteria['cache'] ) ? $passed_criteria['cache'] : true),
363
+			'cache' => ( isset( $passed_criteria[ 'cache' ] ) ? $passed_criteria[ 'cache' ] : true ),
364 364
 		);
365 365
 
366 366
 		$criteria = wp_parse_args( $passed_criteria, $search_criteria_defaults );
367 367
 
368
-		if ( ! empty( $criteria['search_criteria']['field_filters'] ) ) {
369
-			foreach ( $criteria['search_criteria']['field_filters'] as &$filter ) {
368
+		if ( ! empty( $criteria[ 'search_criteria' ][ 'field_filters' ] ) ) {
369
+			foreach ( $criteria[ 'search_criteria' ][ 'field_filters' ] as &$filter ) {
370 370
 
371 371
 				if ( ! is_array( $filter ) ) {
372 372
 					continue;
373 373
 				}
374 374
 
375 375
 				// By default, we want searches to be wildcard for each field.
376
-				$filter['operator'] = empty( $filter['operator'] ) ? 'contains' : $filter['operator'];
376
+				$filter[ 'operator' ] = empty( $filter[ 'operator' ] ) ? 'contains' : $filter[ 'operator' ];
377 377
 
378 378
 				/**
379 379
 				 * @filter `gravityview_search_operator` Modify the search operator for the field (contains, is, isnot, etc)
380 380
 				 * @param string $operator Existing search operator
381 381
 				 * @param array $filter array with `key`, `value`, `operator`, `type` keys
382 382
 				 */
383
-				$filter['operator'] = apply_filters( 'gravityview_search_operator', $filter['operator'], $filter );
383
+				$filter[ 'operator' ] = apply_filters( 'gravityview_search_operator', $filter[ 'operator' ], $filter );
384 384
 			}
385 385
 
386 386
 			// don't send just the [mode] without any field filter.
387
-			if( count( $criteria['search_criteria']['field_filters'] ) === 1 && array_key_exists( 'mode' , $criteria['search_criteria']['field_filters'] ) ) {
388
-				unset( $criteria['search_criteria']['field_filters']['mode'] );
387
+			if ( count( $criteria[ 'search_criteria' ][ 'field_filters' ] ) === 1 && array_key_exists( 'mode', $criteria[ 'search_criteria' ][ 'field_filters' ] ) ) {
388
+				unset( $criteria[ 'search_criteria' ][ 'field_filters' ][ 'mode' ] );
389 389
 			}
390 390
 
391 391
 		}
@@ -396,21 +396,21 @@  discard block
 block discarded – undo
396 396
 		 * Prepare date formats to be in Gravity Forms DB format;
397 397
 		 * $passed_criteria may include date formats incompatible with Gravity Forms.
398 398
 		 */
399
-		foreach ( array('start_date', 'end_date' ) as $key ) {
399
+		foreach ( array( 'start_date', 'end_date' ) as $key ) {
400 400
 
401
-			if ( ! empty( $criteria['search_criteria'][ $key ] ) ) {
401
+			if ( ! empty( $criteria[ 'search_criteria' ][ $key ] ) ) {
402 402
 
403 403
 				// Use date_create instead of new DateTime so it returns false if invalid date format.
404
-				$date = date_create( $criteria['search_criteria'][ $key ] );
404
+				$date = date_create( $criteria[ 'search_criteria' ][ $key ] );
405 405
 
406 406
 				if ( $date ) {
407 407
 					// Gravity Forms wants dates in the `Y-m-d H:i:s` format.
408
-					$criteria['search_criteria'][ $key ] = $date->format( 'Y-m-d H:i:s' );
408
+					$criteria[ 'search_criteria' ][ $key ] = $date->format( 'Y-m-d H:i:s' );
409 409
 				} else {
410 410
 					// If it's an invalid date, unset it. Gravity Forms freaks out otherwise.
411
-					unset( $criteria['search_criteria'][ $key ] );
411
+					unset( $criteria[ 'search_criteria' ][ $key ] );
412 412
 
413
-					do_action( 'gravityview_log_error', '[filter_get_entries_criteria] '.$key.' Date format not valid:', $criteria['search_criteria'][ $key ] );
413
+					do_action( 'gravityview_log_error', '[filter_get_entries_criteria] ' . $key . ' Date format not valid:', $criteria[ 'search_criteria' ][ $key ] );
414 414
 				}
415 415
 			}
416 416
 		}
@@ -418,12 +418,12 @@  discard block
 block discarded – undo
418 418
 
419 419
 		// When multiple views are embedded, OR single entry, calculate the context view id and send it to the advanced filter
420 420
 		if ( class_exists( 'GravityView_View_Data' ) && GravityView_View_Data::getInstance()->has_multiple_views() || GravityView_frontend::getInstance()->getSingleEntry() ) {
421
-			$criteria['context_view_id'] = GravityView_frontend::getInstance()->get_context_view_id();
421
+			$criteria[ 'context_view_id' ] = GravityView_frontend::getInstance()->get_context_view_id();
422 422
 		} elseif ( 'delete' === RGForms::get( 'action' ) ) {
423
-			$criteria['context_view_id'] = isset( $_GET['view_id'] ) ? intval( $_GET['view_id'] ) : null;
424
-		} elseif( !isset( $criteria['context_view_id'] ) ) {
423
+			$criteria[ 'context_view_id' ] = isset( $_GET[ 'view_id' ] ) ? intval( $_GET[ 'view_id' ] ) : null;
424
+		} elseif ( ! isset( $criteria[ 'context_view_id' ] ) ) {
425 425
             // Prevent overriding the Context View ID: Some widgets could set the context_view_id (e.g. Recent Entries widget)
426
-			$criteria['context_view_id'] = null;
426
+			$criteria[ 'context_view_id' ] = null;
427 427
 		}
428 428
 
429 429
 		/**
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
 		 * @param array $form_ids Forms to search
433 433
 		 * @param int $view_id ID of the view being used to search
434 434
 		 */
435
-		$criteria = apply_filters( 'gravityview_search_criteria', $criteria, $form_ids, $criteria['context_view_id'] );
435
+		$criteria = apply_filters( 'gravityview_search_criteria', $criteria, $form_ids, $criteria[ 'context_view_id' ] );
436 436
 
437 437
 		return (array)$criteria;
438 438
 
@@ -463,7 +463,7 @@  discard block
 block discarded – undo
463 463
 		/** Reduce # of database calls */
464 464
 		add_filter( 'gform_is_encrypted_field', '__return_false' );
465 465
 
466
-		if ( ! empty( $criteria['cache'] ) ) {
466
+		if ( ! empty( $criteria[ 'cache' ] ) ) {
467 467
 
468 468
 			$Cache = new GravityView_Cache( $form_ids, $criteria );
469 469
 
@@ -471,7 +471,7 @@  discard block
 block discarded – undo
471 471
 
472 472
 				// Still update the total count when using cached results
473 473
 				if ( ! is_null( $total ) ) {
474
-					$total = GFAPI::count_entries( $form_ids, $criteria['search_criteria'] );
474
+					$total = GFAPI::count_entries( $form_ids, $criteria[ 'search_criteria' ] );
475 475
 				}
476 476
 
477 477
 				$return = $entries;
@@ -491,9 +491,9 @@  discard block
 block discarded – undo
491 491
 			$entries = apply_filters( 'gravityview_before_get_entries', null, $criteria, $passed_criteria, $total );
492 492
 
493 493
 			// No entries returned from gravityview_before_get_entries
494
-			if( is_null( $entries ) ) {
494
+			if ( is_null( $entries ) ) {
495 495
 
496
-				$entries = GFAPI::get_entries( $form_ids, $criteria['search_criteria'], $criteria['sorting'], $criteria['paging'], $total );
496
+				$entries = GFAPI::get_entries( $form_ids, $criteria[ 'search_criteria' ], $criteria[ 'sorting' ], $criteria[ 'paging' ], $total );
497 497
 
498 498
 				if ( is_wp_error( $entries ) ) {
499 499
 					do_action( 'gravityview_log_error', $entries->get_error_message(), $entries );
@@ -502,7 +502,7 @@  discard block
 block discarded – undo
502 502
 				}
503 503
 			}
504 504
 
505
-			if ( ! empty( $criteria['cache'] ) && isset( $Cache ) ) {
505
+			if ( ! empty( $criteria[ 'cache' ] ) && isset( $Cache ) ) {
506 506
 
507 507
 				// Cache results
508 508
 				$Cache->set( $entries, 'entries' );
@@ -589,7 +589,7 @@  discard block
 block discarded – undo
589 589
 			 */
590 590
 			$check_entry_display = apply_filters( 'gravityview/common/get_entry/check_entry_display', $check_entry_display, $entry );
591 591
 
592
-			if( $check_entry_display ) {
592
+			if ( $check_entry_display ) {
593 593
 				// Is the entry allowed
594 594
 				$entry = self::check_entry_display( $entry );
595 595
 			}
@@ -622,12 +622,12 @@  discard block
 block discarded – undo
622 622
 
623 623
 		$value = false;
624 624
 
625
-		if( 'context' === $val1 ) {
625
+		if ( 'context' === $val1 ) {
626 626
 
627 627
 			$matching_contexts = array( $val2 );
628 628
 
629 629
 			// We allow for non-standard contexts.
630
-			switch( $val2 ) {
630
+			switch ( $val2 ) {
631 631
 				// Check for either single or edit
632 632
 				case 'singular':
633 633
 					$matching_contexts = array( 'single', 'edit' );
@@ -687,7 +687,7 @@  discard block
 block discarded – undo
687 687
 			return false;
688 688
 		}
689 689
 
690
-		if ( empty( $entry['form_id'] ) ) {
690
+		if ( empty( $entry[ 'form_id' ] ) ) {
691 691
 			do_action( 'gravityview_log_debug', '[apply_filters_to_entry] Entry is empty! Entry:', $entry );
692 692
 			return false;
693 693
 		}
@@ -695,26 +695,26 @@  discard block
 block discarded – undo
695 695
 		$criteria = self::calculate_get_entries_criteria();
696 696
 
697 697
 		// Make sure the current View is connected to the same form as the Entry
698
-		if( ! empty( $criteria['context_view_id'] ) ) {
699
-			$context_view_id = intval( $criteria['context_view_id'] );
698
+		if ( ! empty( $criteria[ 'context_view_id' ] ) ) {
699
+			$context_view_id = intval( $criteria[ 'context_view_id' ] );
700 700
 			$context_form_id = gravityview_get_form_id( $context_view_id );
701
-			if( intval( $context_form_id ) !== intval( $entry['form_id'] ) ) {
702
-				do_action( 'gravityview_log_debug', sprintf( '[apply_filters_to_entry] Entry form ID does not match current View connected form ID:', $entry['form_id'] ), $criteria['context_view_id'] );
701
+			if ( intval( $context_form_id ) !== intval( $entry[ 'form_id' ] ) ) {
702
+				do_action( 'gravityview_log_debug', sprintf( '[apply_filters_to_entry] Entry form ID does not match current View connected form ID:', $entry[ 'form_id' ] ), $criteria[ 'context_view_id' ] );
703 703
 				return false;
704 704
 			}
705 705
 		}
706 706
 
707
-		if ( empty( $criteria['search_criteria'] ) || ! is_array( $criteria['search_criteria'] ) ) {
707
+		if ( empty( $criteria[ 'search_criteria' ] ) || ! is_array( $criteria[ 'search_criteria' ] ) ) {
708 708
 			do_action( 'gravityview_log_debug', '[apply_filters_to_entry] Entry approved! No search criteria found:', $criteria );
709 709
 			return $entry;
710 710
 		}
711 711
 
712
-		$search_criteria = $criteria['search_criteria'];
712
+		$search_criteria = $criteria[ 'search_criteria' ];
713 713
 		unset( $criteria );
714 714
 
715 715
 		// check entry status
716
-		if ( array_key_exists( 'status', $search_criteria ) && $search_criteria['status'] != $entry['status'] ) {
717
-			do_action( 'gravityview_log_debug', sprintf( '[apply_filters_to_entry] Entry status - %s - is not valid according to filter:', $entry['status'] ), $search_criteria );
716
+		if ( array_key_exists( 'status', $search_criteria ) && $search_criteria[ 'status' ] != $entry[ 'status' ] ) {
717
+			do_action( 'gravityview_log_debug', sprintf( '[apply_filters_to_entry] Entry status - %s - is not valid according to filter:', $entry[ 'status' ] ), $search_criteria );
718 718
 			return false;
719 719
 		}
720 720
 
@@ -722,37 +722,37 @@  discard block
 block discarded – undo
722 722
 		// @todo: Does it make sense to apply the Date create filters to the single entry?
723 723
 
724 724
 		// field_filters
725
-		if ( empty( $search_criteria['field_filters'] ) || ! is_array( $search_criteria['field_filters'] ) ) {
725
+		if ( empty( $search_criteria[ 'field_filters' ] ) || ! is_array( $search_criteria[ 'field_filters' ] ) ) {
726 726
 			do_action( 'gravityview_log_debug', '[apply_filters_to_entry] Entry approved! No field filters criteria found:', $search_criteria );
727 727
 			return $entry;
728 728
 		}
729 729
 
730
-		$filters = $search_criteria['field_filters'];
730
+		$filters = $search_criteria[ 'field_filters' ];
731 731
 		unset( $search_criteria );
732 732
 
733
-		$mode = array_key_exists( 'mode', $filters ) ? strtolower( $filters['mode'] ) : 'all';
734
-		unset( $filters['mode'] );
733
+		$mode = array_key_exists( 'mode', $filters ) ? strtolower( $filters[ 'mode' ] ) : 'all';
734
+		unset( $filters[ 'mode' ] );
735 735
 
736
-		$form = self::get_form( $entry['form_id'] );
736
+		$form = self::get_form( $entry[ 'form_id' ] );
737 737
 
738 738
 		foreach ( $filters as $filter ) {
739 739
 
740
-			if ( ! isset( $filter['key'] ) ) {
740
+			if ( ! isset( $filter[ 'key' ] ) ) {
741 741
 				continue;
742 742
 			}
743 743
 
744
-			$k = $filter['key'];
744
+			$k = $filter[ 'key' ];
745 745
 
746 746
 			if ( in_array( $k, array( 'created_by', 'payment_status' ) ) ) {
747 747
 				$field_value = $entry[ $k ];
748 748
 				$field = null;
749 749
 			} else {
750 750
 				$field = self::get_field( $form, $k );
751
-				$field_value  = GFFormsModel::get_lead_field_value( $entry, $field );
751
+				$field_value = GFFormsModel::get_lead_field_value( $entry, $field );
752 752
 			}
753 753
 
754
-			$operator = isset( $filter['operator'] ) ? strtolower( $filter['operator'] ) : 'is';
755
-			$is_value_match = GFFormsModel::is_value_match( $field_value, $filter['value'], $operator, $field );
754
+			$operator = isset( $filter[ 'operator' ] ) ? strtolower( $filter[ 'operator' ] ) : 'is';
755
+			$is_value_match = GFFormsModel::is_value_match( $field_value, $filter[ 'value' ], $operator, $field );
756 756
 
757 757
 			// verify if we are already free to go!
758 758
 			if ( ! $is_value_match && 'all' === $mode ) {
@@ -810,18 +810,18 @@  discard block
 block discarded – undo
810 810
 		 * Gravity Forms code to adjust date to locally-configured Time Zone
811 811
 		 * @see GFCommon::format_date() for original code
812 812
 		 */
813
-		$date_gmt_time   = mysql2date( 'G', $date_string );
813
+		$date_gmt_time = mysql2date( 'G', $date_string );
814 814
 		$date_local_timestamp = GFCommon::get_local_timestamp( $date_gmt_time );
815 815
 
816
-		$format  = rgar( $atts, 'format' );
817
-		$is_human  = ! empty( $atts['human'] );
818
-		$is_diff  = ! empty( $atts['diff'] );
819
-		$is_raw = ! empty( $atts['raw'] );
820
-		$is_timestamp = ! empty( $atts['timestamp'] );
821
-		$include_time = ! empty( $atts['time'] );
816
+		$format = rgar( $atts, 'format' );
817
+		$is_human = ! empty( $atts[ 'human' ] );
818
+		$is_diff = ! empty( $atts[ 'diff' ] );
819
+		$is_raw = ! empty( $atts[ 'raw' ] );
820
+		$is_timestamp = ! empty( $atts[ 'timestamp' ] );
821
+		$include_time = ! empty( $atts[ 'time' ] );
822 822
 
823 823
 		// If we're using time diff, we want to have a different default format
824
-		if( empty( $format ) ) {
824
+		if ( empty( $format ) ) {
825 825
 			/* translators: %s: relative time from now, used for generic date comparisons. "1 day ago", or "20 seconds ago" */
826 826
 			$format = $is_diff ? esc_html__( '%s ago', 'gravityview' ) : get_option( 'date_format' );
827 827
 		}
@@ -829,7 +829,7 @@  discard block
 block discarded – undo
829 829
 		// If raw was specified, don't modify the stored value
830 830
 		if ( $is_raw ) {
831 831
 			$formatted_date = $date_string;
832
-		} elseif( $is_timestamp ) {
832
+		} elseif ( $is_timestamp ) {
833 833
 			$formatted_date = $date_local_timestamp;
834 834
 		} elseif ( $is_diff ) {
835 835
 			$formatted_date = sprintf( $format, human_time_diff( $date_gmt_time ) );
@@ -863,7 +863,7 @@  discard block
 block discarded – undo
863 863
 
864 864
 		$label = rgar( $field, 'label' );
865 865
 
866
-		if( floor( $field_id ) !== floatval( $field_id ) ) {
866
+		if ( floor( $field_id ) !== floatval( $field_id ) ) {
867 867
 			$label = GFFormsModel::get_choice_text( $field, $field_value, $field_id );
868 868
 		}
869 869
 
@@ -884,7 +884,7 @@  discard block
 block discarded – undo
884 884
 	 * @return GF_Field|null Gravity Forms field object, or NULL: Gravity Forms GFFormsModel does not exist or field at $field_id doesn't exist.
885 885
 	 */
886 886
 	public static function get_field( $form, $field_id ) {
887
-		if ( class_exists( 'GFFormsModel' ) ){
887
+		if ( class_exists( 'GFFormsModel' ) ) {
888 888
 			return GFFormsModel::get_field( $form, $field_id );
889 889
 		} else {
890 890
 			return null;
@@ -931,19 +931,19 @@  discard block
 block discarded – undo
931 931
 			$shortcodes = array();
932 932
 
933 933
 			preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER );
934
-			if ( empty( $matches ) ){
934
+			if ( empty( $matches ) ) {
935 935
 				return false;
936 936
 			}
937 937
 
938 938
 			foreach ( $matches as $shortcode ) {
939
-				if ( $tag === $shortcode[2] ) {
939
+				if ( $tag === $shortcode[ 2 ] ) {
940 940
 
941 941
 					// Changed this to $shortcode instead of true so we get the parsed atts.
942
-					$shortcodes[] = $shortcode;
942
+					$shortcodes[ ] = $shortcode;
943 943
 
944
-				} else if ( isset( $shortcode[5] ) && $results = self::has_shortcode_r( $shortcode[5], $tag ) ) {
945
-					foreach( $results as $result ) {
946
-						$shortcodes[] = $result;
944
+				} else if ( isset( $shortcode[ 5 ] ) && $results = self::has_shortcode_r( $shortcode[ 5 ], $tag ) ) {
945
+					foreach ( $results as $result ) {
946
+						$shortcodes[ ] = $result;
947 947
 					}
948 948
 				}
949 949
 			}
@@ -1087,7 +1087,7 @@  discard block
 block discarded – undo
1087 1087
 	public static function get_directory_fields( $post_id, $apply_filter = true ) {
1088 1088
 		$fields = get_post_meta( $post_id, '_gravityview_directory_fields', true );
1089 1089
 
1090
-		if( $apply_filter ) {
1090
+		if ( $apply_filter ) {
1091 1091
 			/**
1092 1092
 			 * @filter `gravityview/configuration/fields` Filter the View fields' configuration array
1093 1093
 			 * @since 1.6.5
@@ -1110,7 +1110,7 @@  discard block
 block discarded – undo
1110 1110
 	 * @return string         html
1111 1111
 	 */
1112 1112
 	public static function get_sortable_fields( $formid, $current = '' ) {
1113
-		$output = '<option value="" ' . selected( '', $current, false ).'>' . esc_html__( 'Default', 'gravityview' ) .'</option>';
1113
+		$output = '<option value="" ' . selected( '', $current, false ) . '>' . esc_html__( 'Default', 'gravityview' ) . '</option>';
1114 1114
 
1115 1115
 		if ( empty( $formid ) ) {
1116 1116
 			return $output;
@@ -1123,11 +1123,11 @@  discard block
 block discarded – undo
1123 1123
 			$blacklist_field_types = apply_filters( 'gravityview_blacklist_field_types', array( 'list', 'textarea' ), null );
1124 1124
 
1125 1125
 			foreach ( $fields as $id => $field ) {
1126
-				if ( in_array( $field['type'], $blacklist_field_types ) ) {
1126
+				if ( in_array( $field[ 'type' ], $blacklist_field_types ) ) {
1127 1127
 					continue;
1128 1128
 				}
1129 1129
 
1130
-				$output .= '<option value="'. $id .'" '. selected( $id, $current, false ).'>'. esc_attr( $field['label'] ) .'</option>';
1130
+				$output .= '<option value="' . $id . '" ' . selected( $id, $current, false ) . '>' . esc_attr( $field[ 'label' ] ) . '</option>';
1131 1131
 			}
1132 1132
 		}
1133 1133
 
@@ -1162,9 +1162,9 @@  discard block
 block discarded – undo
1162 1162
 		$blacklist_field_types = apply_filters( 'gravityview_blacklist_field_types', $blacklist, NULL );
1163 1163
 
1164 1164
 		// TODO: Convert to using array_filter
1165
-		foreach( $fields as $id => $field ) {
1165
+		foreach ( $fields as $id => $field ) {
1166 1166
 
1167
-			if( in_array( $field['type'], $blacklist_field_types ) ) {
1167
+			if ( in_array( $field[ 'type' ], $blacklist_field_types ) ) {
1168 1168
 				unset( $fields[ $id ] );
1169 1169
 			}
1170 1170
 		}
@@ -1205,14 +1205,14 @@  discard block
 block discarded – undo
1205 1205
 	 * @param  int|array  $field field key or field array
1206 1206
 	 * @return boolean
1207 1207
 	 */
1208
-	public static function is_field_numeric(  $form = null, $field = '' ) {
1208
+	public static function is_field_numeric( $form = null, $field = '' ) {
1209 1209
 
1210 1210
 		if ( ! is_array( $form ) && ! is_array( $field ) ) {
1211 1211
 			$form = self::get_form( $form );
1212 1212
 		}
1213 1213
 
1214 1214
 		// If entry meta, it's a string. Otherwise, numeric
1215
-		if( ! is_numeric( $field ) && is_string( $field ) ) {
1215
+		if ( ! is_numeric( $field ) && is_string( $field ) ) {
1216 1216
 			$type = $field;
1217 1217
 		} else {
1218 1218
 			$type = self::get_field_type( $form, $field );
@@ -1226,9 +1226,9 @@  discard block
 block discarded – undo
1226 1226
 		$numeric_types = apply_filters( 'gravityview/common/numeric_types', array( 'number', 'time' ) );
1227 1227
 
1228 1228
 		// Defer to GravityView_Field setting, if the field type is registered and `is_numeric` is true
1229
-		if( $gv_field = GravityView_Fields::get( $type ) ) {
1230
-			if( true === $gv_field->is_numeric ) {
1231
-				$numeric_types[] = $gv_field->is_numeric;
1229
+		if ( $gv_field = GravityView_Fields::get( $type ) ) {
1230
+			if ( true === $gv_field->is_numeric ) {
1231
+				$numeric_types[ ] = $gv_field->is_numeric;
1232 1232
 			}
1233 1233
 		}
1234 1234
 
@@ -1378,18 +1378,18 @@  discard block
 block discarded – undo
1378 1378
 		$final_atts = array_filter( $final_atts );
1379 1379
 
1380 1380
 		// If the href wasn't passed as an attribute, use the value passed to the function
1381
-		if ( empty( $final_atts['href'] ) && ! empty( $href ) ) {
1382
-			$final_atts['href'] = $href;
1381
+		if ( empty( $final_atts[ 'href' ] ) && ! empty( $href ) ) {
1382
+			$final_atts[ 'href' ] = $href;
1383 1383
 		}
1384 1384
 
1385
-		$final_atts['href'] = esc_url_raw( $href );
1385
+		$final_atts[ 'href' ] = esc_url_raw( $href );
1386 1386
 
1387 1387
 		/**
1388 1388
 		 * Fix potential security issue with target=_blank
1389 1389
 		 * @see https://dev.to/ben/the-targetblank-vulnerability-by-example
1390 1390
 		 */
1391
-		if( '_blank' === rgar( $final_atts, 'target' ) ) {
1392
-			$final_atts['rel'] = trim( rgar( $final_atts, 'rel', '' ) . ' noopener noreferrer' );
1391
+		if ( '_blank' === rgar( $final_atts, 'target' ) ) {
1392
+			$final_atts[ 'rel' ] = trim( rgar( $final_atts, 'rel', '' ) . ' noopener noreferrer' );
1393 1393
 		}
1394 1394
 
1395 1395
 		// Sort the attributes alphabetically, to help testing
@@ -1401,7 +1401,7 @@  discard block
 block discarded – undo
1401 1401
 			$output .= sprintf( ' %s="%s"', $attr, esc_attr( $value ) );
1402 1402
 		}
1403 1403
 
1404
-		if( '' !== $output ) {
1404
+		if ( '' !== $output ) {
1405 1405
 			$output = '<a' . $output . '>' . $anchor_text . '</a>';
1406 1406
 		}
1407 1407
 
@@ -1428,7 +1428,7 @@  discard block
 block discarded – undo
1428 1428
 			if ( is_array( $value ) && isset( $merged[ $key ] ) && is_array( $merged[ $key ] ) ) {
1429 1429
 				$merged[ $key ] = self::array_merge_recursive_distinct( $merged[ $key ], $value );
1430 1430
 			} else if ( is_numeric( $key ) && isset( $merged[ $key ] ) ) {
1431
-				$merged[] = $value;
1431
+				$merged[ ] = $value;
1432 1432
 			} else {
1433 1433
 				$merged[ $key ] = $value;
1434 1434
 			}
@@ -1461,7 +1461,7 @@  discard block
 block discarded – undo
1461 1461
 		 * `$context` is where are we using this information (e.g. change_entry_creator, search_widget ..)
1462 1462
 		 * @param array $settings Settings array, with `number` key defining the # of users to display
1463 1463
 		 */
1464
-		$get_users_settings = apply_filters( 'gravityview/get_users/'. $context, apply_filters( 'gravityview_change_entry_creator_user_parameters', $get_users_settings ) );
1464
+		$get_users_settings = apply_filters( 'gravityview/get_users/' . $context, apply_filters( 'gravityview_change_entry_creator_user_parameters', $get_users_settings ) );
1465 1465
 
1466 1466
 		return get_users( $get_users_settings );
1467 1467
 	}
@@ -1476,7 +1476,7 @@  discard block
 block discarded – undo
1476 1476
      * @return string
1477 1477
      */
1478 1478
     public static function generate_notice( $notice, $class = '' ) {
1479
-        return '<div class="gv-notice '.gravityview_sanitize_html_class( $class ) .'">'. $notice .'</div>';
1479
+        return '<div class="gv-notice ' . gravityview_sanitize_html_class( $class ) . '">' . $notice . '</div>';
1480 1480
     }
1481 1481
 
1482 1482
 	/**
Please login to merge, or discard this patch.
includes/widgets/class-gravityview-widget-page-links.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -11,35 +11,35 @@  discard block
 block discarded – undo
11 11
 
12 12
 	function __construct() {
13 13
 
14
-		$this->widget_description = __('Links to multiple pages of results.', 'gravityview' );
14
+		$this->widget_description = __( 'Links to multiple pages of results.', 'gravityview' );
15 15
 
16 16
 		$default_values = array( 'header' => 1, 'footer' => 1 );
17 17
 		$settings = array( 'show_all' => array(
18 18
 			'type' => 'checkbox',
19 19
 			'label' => __( 'Show each page number', 'gravityview' ),
20
-			'desc' => __('Show every page number instead of summary (eg: 1 2 3 ... 8 »)', 'gravityview'),
20
+			'desc' => __( 'Show every page number instead of summary (eg: 1 2 3 ... 8 »)', 'gravityview' ),
21 21
 			'value' => false
22
-		));
23
-		parent::__construct( __( 'Page Links', 'gravityview' ) , 'page_links', $default_values, $settings );
22
+		) );
23
+		parent::__construct( __( 'Page Links', 'gravityview' ), 'page_links', $default_values, $settings );
24 24
 
25 25
 	}
26 26
 
27
-	public function render_frontend( $widget_args, $content = '', $context = '') {
27
+	public function render_frontend( $widget_args, $content = '', $context = '' ) {
28 28
 		$gravityview_view = GravityView_View::getInstance();
29 29
 
30
-		if( !$this->pre_render_frontend() ) {
30
+		if ( ! $this->pre_render_frontend() ) {
31 31
 			return;
32 32
 		}
33 33
 
34 34
 		$atts = shortcode_atts( array(
35 35
 			'page_size' => rgar( $gravityview_view->paging, 'page_size' ),
36 36
 			'total' => $gravityview_view->total_entries,
37
-			'show_all' => !empty( $this->settings['show_all']['default'] ),
38
-			'current' => (int) rgar( $_GET, 'pagenum', 1 ),
37
+			'show_all' => ! empty( $this->settings[ 'show_all' ][ 'default' ] ),
38
+			'current' => (int)rgar( $_GET, 'pagenum', 1 ),
39 39
 		), $widget_args, 'gravityview_widget_page_links' );
40 40
 		
41 41
 		$page_link_args = array(
42
-			'base' => add_query_arg('pagenum','%#%', gv_directory_link() ),
42
+			'base' => add_query_arg( 'pagenum', '%#%', gv_directory_link() ),
43 43
 			'format' => '&pagenum=%#%',
44 44
 			'add_args' => array(), //
45 45
 			'prev_text' => '&laquo;',
@@ -47,9 +47,9 @@  discard block
 block discarded – undo
47 47
 			'type' => 'list',
48 48
 			'end_size' => 1,
49 49
 			'mid_size' => 2,
50
-			'total' => empty( $atts['page_size'] ) ? 0 : ceil( $atts['total'] / $atts['page_size'] ),
51
-			'current' => $atts['current'],
52
-			'show_all' => !empty( $atts['show_all'] ), // to be available at backoffice
50
+			'total' => empty( $atts[ 'page_size' ] ) ? 0 : ceil( $atts[ 'total' ] / $atts[ 'page_size' ] ),
51
+			'current' => $atts[ 'current' ],
52
+			'show_all' => ! empty( $atts[ 'show_all' ] ), // to be available at backoffice
53 53
 		);
54 54
 
55 55
 		/**
@@ -57,14 +57,14 @@  discard block
 block discarded – undo
57 57
 		 * @since 1.1.4
58 58
 		 * @param array  $page_link_args Array of arguments for the `paginate_links()` function. [Read more about `paginate_links()`](http://developer.wordpress.org/reference/functions/paginate_links/)
59 59
 		 */
60
-		$page_link_args = apply_filters('gravityview_page_links_args', $page_link_args );
60
+		$page_link_args = apply_filters( 'gravityview_page_links_args', $page_link_args );
61 61
 
62 62
 		$page_links = paginate_links( $page_link_args );
63 63
 
64
-		if( !empty( $page_links )) {
65
-			$class = !empty( $widget_args['custom_class'] ) ? $widget_args['custom_class'] : '';
64
+		if ( ! empty( $page_links ) ) {
65
+			$class = ! empty( $widget_args[ 'custom_class' ] ) ? $widget_args[ 'custom_class' ] : '';
66 66
 			$class = gravityview_sanitize_html_class( $class );
67
-			echo '<div class="gv-widget-page-links '.$class.'">'. $page_links .'</div>';
67
+			echo '<div class="gv-widget-page-links ' . $class . '">' . $page_links . '</div>';
68 68
 		} else {
69 69
 			do_action( 'gravityview_log_debug', 'GravityView_Widget_Page_Links[render_frontend] No page links; paginate_links() returned empty response.' );
70 70
 		}
Please login to merge, or discard this patch.
includes/widgets/search-widget/class-search-widget.php 1 patch
Spacing   +106 added lines, -106 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 				'type' => 'radio',
64 64
 				'full_width' => true,
65 65
 				'label' => esc_html__( 'Search Mode', 'gravityview' ),
66
-				'desc' => __('Should search results match all search fields, or any?', 'gravityview'),
66
+				'desc' => __( 'Should search results match all search fields, or any?', 'gravityview' ),
67 67
 				'value' => 'any',
68 68
 				'class' => 'hide-if-js',
69 69
 				'options' => array(
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 
86 86
 		// admin - add scripts - run at 1100 to make sure GravityView_Admin_Views::add_scripts_and_styles() runs first at 999
87 87
 		add_action( 'admin_enqueue_scripts', array( $this, 'add_scripts_and_styles' ), 1100 );
88
-		add_action( 'wp_enqueue_scripts', array( $this, 'register_scripts') );
88
+		add_action( 'wp_enqueue_scripts', array( $this, 'register_scripts' ) );
89 89
 		add_filter( 'gravityview_noconflict_scripts', array( $this, 'register_no_conflict' ) );
90 90
 
91 91
 		// ajax - get the searchable fields
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 		$script_min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
150 150
 		$script_source = empty( $script_min ) ? '/source' : '';
151 151
 
152
-		wp_enqueue_script( 'gravityview_searchwidget_admin', plugins_url( 'assets/js'.$script_source.'/admin-search-widget'.$script_min.'.js', __FILE__ ), array( 'jquery', 'gravityview_views_scripts' ), GravityView_Plugin::version );
152
+		wp_enqueue_script( 'gravityview_searchwidget_admin', plugins_url( 'assets/js' . $script_source . '/admin-search-widget' . $script_min . '.js', __FILE__ ), array( 'jquery', 'gravityview_views_scripts' ), GravityView_Plugin::version );
153 153
 
154 154
 
155 155
 		/**
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
 	 * @return array Scripts allowed in no-conflict mode, plus the search widget script
205 205
 	 */
206 206
 	public function register_no_conflict( $allowed ) {
207
-		$allowed[] = 'gravityview_searchwidget_admin';
207
+		$allowed[ ] = 'gravityview_searchwidget_admin';
208 208
 		return $allowed;
209 209
 	}
210 210
 
@@ -217,24 +217,24 @@  discard block
 block discarded – undo
217 217
 	 */
218 218
 	public static function get_searchable_fields() {
219 219
 
220
-		if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'gravityview_ajaxsearchwidget' ) ) {
220
+		if ( ! isset( $_POST[ 'nonce' ] ) || ! wp_verify_nonce( $_POST[ 'nonce' ], 'gravityview_ajaxsearchwidget' ) ) {
221 221
 			exit( '0' );
222 222
 		}
223 223
 
224 224
 		$form = '';
225 225
 
226 226
 		// Fetch the form for the current View
227
-		if ( ! empty( $_POST['view_id'] ) ) {
227
+		if ( ! empty( $_POST[ 'view_id' ] ) ) {
228 228
 
229
-			$form = gravityview_get_form_id( $_POST['view_id'] );
229
+			$form = gravityview_get_form_id( $_POST[ 'view_id' ] );
230 230
 
231
-		} elseif ( ! empty( $_POST['formid'] ) ) {
231
+		} elseif ( ! empty( $_POST[ 'formid' ] ) ) {
232 232
 
233
-			$form = (int) $_POST['formid'];
233
+			$form = (int)$_POST[ 'formid' ];
234 234
 
235
-		} elseif ( ! empty( $_POST['template_id'] ) && class_exists( 'GravityView_Ajax' ) ) {
235
+		} elseif ( ! empty( $_POST[ 'template_id' ] ) && class_exists( 'GravityView_Ajax' ) ) {
236 236
 
237
-			$form = GravityView_Ajax::pre_get_form_fields( $_POST['template_id'] );
237
+			$form = GravityView_Ajax::pre_get_form_fields( $_POST[ 'template_id' ] );
238 238
 
239 239
 		}
240 240
 
@@ -279,8 +279,8 @@  discard block
 block discarded – undo
279 279
 			)
280 280
 		);
281 281
 
282
-		foreach( $custom_fields as $custom_field_key => $custom_field ) {
283
-			$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'] );
282
+		foreach ( $custom_fields as $custom_field_key => $custom_field ) {
283
+			$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' ] );
284 284
 		}
285 285
 
286 286
 		// Get fields with sub-inputs and no parent
@@ -302,13 +302,13 @@  discard block
 block discarded – undo
302 302
 
303 303
 			foreach ( $fields as $id => $field ) {
304 304
 
305
-				if ( in_array( $field['type'], $blacklist_field_types ) ) {
305
+				if ( in_array( $field[ 'type' ], $blacklist_field_types ) ) {
306 306
 					continue;
307 307
 				}
308 308
 
309
-				$types = self::get_search_input_types( $id, $field['type'] );
309
+				$types = self::get_search_input_types( $id, $field[ 'type' ] );
310 310
 
311
-				$output .= '<option value="'. $id .'" '. selected( $id, $current, false ).'data-inputtypes="'. esc_attr( $types ) .'">'. esc_html( $field['label'] ) .'</option>';
311
+				$output .= '<option value="' . $id . '" ' . selected( $id, $current, false ) . 'data-inputtypes="' . esc_attr( $types ) . '">' . esc_html( $field[ 'label' ] ) . '</option>';
312 312
 			}
313 313
 		}
314 314
 
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
 	public static function get_search_input_types( $id = '', $field_type = null ) {
331 331
 
332 332
 		// @todo - This needs to be improved - many fields have . including products and addresses
333
-		if ( false !== strpos( (string) $id, '.' ) && in_array( $field_type, array( 'checkbox' ) ) || in_array( $id, array( 'is_fulfilled' ) ) ) {
333
+		if ( false !== strpos( (string)$id, '.' ) && in_array( $field_type, array( 'checkbox' ) ) || in_array( $id, array( 'is_fulfilled' ) ) ) {
334 334
 			$input_type = 'boolean'; // on/off checkbox
335 335
 		} elseif ( in_array( $field_type, array( 'checkbox', 'post_category', 'multiselect' ) ) ) {
336 336
 			$input_type = 'multi'; //multiselect
@@ -372,19 +372,19 @@  discard block
 block discarded – undo
372 372
 			$post_id = 0;
373 373
 
374 374
 			// We're in the WordPress Widget context, and an overriding post ID has been set.
375
-			if ( ! empty( $widget_args['post_id'] ) ) {
376
-				$post_id = absint( $widget_args['post_id'] );
375
+			if ( ! empty( $widget_args[ 'post_id' ] ) ) {
376
+				$post_id = absint( $widget_args[ 'post_id' ] );
377 377
 			}
378 378
 			// We're in the WordPress Widget context, and the base View ID should be used
379
-			else if ( ! empty( $widget_args['view_id'] ) ) {
380
-				$post_id = absint( $widget_args['view_id'] );
379
+			else if ( ! empty( $widget_args[ 'view_id' ] ) ) {
380
+				$post_id = absint( $widget_args[ 'view_id' ] );
381 381
 			}
382 382
 
383 383
 			$args = gravityview_get_permalink_query_args( $post_id );
384 384
 
385 385
 			// Add hidden fields to the search form
386 386
 			foreach ( $args as $key => $value ) {
387
-				$search_fields[] = array(
387
+				$search_fields[ ] = array(
388 388
 					'name'  => $key,
389 389
 					'input' => 'hidden',
390 390
 					'value' => $value,
@@ -405,7 +405,7 @@  discard block
 block discarded – undo
405 405
 	 */
406 406
 	public function filter_entries( $search_criteria ) {
407 407
 
408
-		if( 'post' === $this->search_method ) {
408
+		if ( 'post' === $this->search_method ) {
409 409
 			$get = $_POST;
410 410
 		} else {
411 411
 			$get = $_GET;
@@ -422,15 +422,15 @@  discard block
 block discarded – undo
422 422
 		$get = gv_map_deep( $get, 'rawurldecode' );
423 423
 
424 424
 		// add free search
425
-		if ( ! empty( $get['gv_search'] ) ) {
425
+		if ( ! empty( $get[ 'gv_search' ] ) ) {
426 426
 
427 427
 			// Search for a piece
428
-			$words = explode( ' ', $get['gv_search'] );
428
+			$words = explode( ' ', $get[ 'gv_search' ] );
429 429
 
430 430
 			$words = array_filter( $words );
431 431
 
432 432
 			foreach ( $words as $word ) {
433
-				$search_criteria['field_filters'][] = array(
433
+				$search_criteria[ 'field_filters' ][ ] = array(
434 434
 					'key' => null, // The field ID to search
435 435
 					'value' => $word, // The value to search
436 436
 					'operator' => 'contains', // What to search in. Options: `is` or `contains`
@@ -439,8 +439,8 @@  discard block
 block discarded – undo
439 439
 		}
440 440
 
441 441
 		//start date & end date
442
-		$curr_start = !empty( $get['gv_start'] ) ? $get['gv_start'] : '';
443
-		$curr_end = !empty( $get['gv_start'] ) ? $get['gv_end'] : '';
442
+		$curr_start = ! empty( $get[ 'gv_start' ] ) ? $get[ 'gv_start' ] : '';
443
+		$curr_end = ! empty( $get[ 'gv_start' ] ) ? $get[ 'gv_end' ] : '';
444 444
 
445 445
         /**
446 446
          * @filter `gravityview_date_created_adjust_timezone` Whether to adjust the timezone for entries. \n
@@ -455,16 +455,16 @@  discard block
 block discarded – undo
455 455
 		/**
456 456
 		 * Don't set $search_criteria['start_date'] if start_date is empty as it may lead to bad query results (GFAPI::get_entries)
457 457
 		 */
458
-		if( !empty( $curr_start ) ) {
459
-			$search_criteria['start_date'] = $adjust_tz ? get_gmt_from_date( $curr_start ) : $curr_start;
458
+		if ( ! empty( $curr_start ) ) {
459
+			$search_criteria[ 'start_date' ] = $adjust_tz ? get_gmt_from_date( $curr_start ) : $curr_start;
460 460
 		}
461
-		if( !empty( $curr_end ) ) {
462
-			$search_criteria['end_date'] = $adjust_tz ? get_gmt_from_date( $curr_end ) : $curr_end;
461
+		if ( ! empty( $curr_end ) ) {
462
+			$search_criteria[ 'end_date' ] = $adjust_tz ? get_gmt_from_date( $curr_end ) : $curr_end;
463 463
 		}
464 464
 
465 465
 		// search for a specific entry ID
466 466
 		if ( ! empty( $get[ 'gv_id' ] ) ) {
467
-			$search_criteria['field_filters'][] = array(
467
+			$search_criteria[ 'field_filters' ][ ] = array(
468 468
 				'key' => 'id',
469 469
 				'value' => absint( $get[ 'gv_id' ] ),
470 470
 				'operator' => '=',
@@ -473,36 +473,36 @@  discard block
 block discarded – undo
473 473
 
474 474
 		// search for a specific Created_by ID
475 475
 		if ( ! empty( $get[ 'gv_by' ] ) ) {
476
-			$search_criteria['field_filters'][] = array(
476
+			$search_criteria[ 'field_filters' ][ ] = array(
477 477
 				'key' => 'created_by',
478
-				'value' => absint( $get['gv_by'] ),
478
+				'value' => absint( $get[ 'gv_by' ] ),
479 479
 				'operator' => '=',
480 480
 			);
481 481
 		}
482 482
 
483 483
 
484 484
 		// Get search mode passed in URL
485
-		$mode = isset( $get['mode'] ) && in_array( $get['mode'], array( 'any', 'all' ) ) ?  $get['mode'] : 'any';
485
+		$mode = isset( $get[ 'mode' ] ) && in_array( $get[ 'mode' ], array( 'any', 'all' ) ) ? $get[ 'mode' ] : 'any';
486 486
 
487 487
 		// get the other search filters
488 488
 		foreach ( $get as $key => $value ) {
489 489
 
490
-			if ( 0 !== strpos( $key, 'filter_' ) || empty( $value ) || ( is_array( $value ) && count( $value ) === 1 && empty( $value[0] ) ) ) {
490
+			if ( 0 !== strpos( $key, 'filter_' ) || empty( $value ) || ( is_array( $value ) && count( $value ) === 1 && empty( $value[ 0 ] ) ) ) {
491 491
 				continue;
492 492
 			}
493 493
 
494 494
 			// could return simple filter or multiple filters
495 495
 			$filter = $this->prepare_field_filter( $key, $value );
496 496
 
497
-			if ( isset( $filter[0]['value'] ) ) {
498
-				$search_criteria['field_filters'] = array_merge( $search_criteria['field_filters'], $filter );
497
+			if ( isset( $filter[ 0 ][ 'value' ] ) ) {
498
+				$search_criteria[ 'field_filters' ] = array_merge( $search_criteria[ 'field_filters' ], $filter );
499 499
 
500 500
 				// if date range type, set search mode to ALL
501
-				if ( ! empty( $filter[0]['operator'] ) && in_array( $filter[0]['operator'], array( '>=', '<=', '>', '<' ) ) ) {
501
+				if ( ! empty( $filter[ 0 ][ 'operator' ] ) && in_array( $filter[ 0 ][ 'operator' ], array( '>=', '<=', '>', '<' ) ) ) {
502 502
 					$mode = 'all';
503 503
 				}
504
-			} elseif( !empty( $filter ) ) {
505
-				$search_criteria['field_filters'][] = $filter;
504
+			} elseif ( ! empty( $filter ) ) {
505
+				$search_criteria[ 'field_filters' ][ ] = $filter;
506 506
 			}
507 507
 		}
508 508
 
@@ -511,7 +511,7 @@  discard block
 block discarded – undo
511 511
 		 * @since 1.5.1
512 512
 		 * @param[out,in] string $mode Search mode (`any` vs `all`)
513 513
 		 */
514
-		$search_criteria['field_filters']['mode'] = apply_filters( 'gravityview/search/mode', $mode );
514
+		$search_criteria[ 'field_filters' ][ 'mode' ] = apply_filters( 'gravityview/search/mode', $mode );
515 515
 
516 516
 		do_action( 'gravityview_log_debug', sprintf( '%s[filter_entries] Returned Search Criteria: ', get_class( $this ) ), $search_criteria );
517 517
 
@@ -537,7 +537,7 @@  discard block
 block discarded – undo
537 537
 		$field_id = str_replace( 'filter_', '', $key );
538 538
 
539 539
 		// calculates field_id, removing 'filter_' and for '_' for advanced fields ( like name or checkbox )
540
-		if ( preg_match('/^[0-9_]+$/ism', $field_id ) ) {
540
+		if ( preg_match( '/^[0-9_]+$/ism', $field_id ) ) {
541 541
 			$field_id = str_replace( '_', '.', $field_id );
542 542
 		}
543 543
 
@@ -551,11 +551,11 @@  discard block
 block discarded – undo
551 551
 			'value' => $value,
552 552
 		);
553 553
 
554
-		switch ( $form_field['type'] ) {
554
+		switch ( $form_field[ 'type' ] ) {
555 555
 
556 556
 			case 'select':
557 557
 			case 'radio':
558
-				$filter['operator'] = 'is';
558
+				$filter[ 'operator' ] = 'is';
559 559
 				break;
560 560
 
561 561
 			case 'post_category':
@@ -569,7 +569,7 @@  discard block
 block discarded – undo
569 569
 
570 570
 				foreach ( $value as $val ) {
571 571
 					$cat = get_term( $val, 'category' );
572
-					$filter[] = array(
572
+					$filter[ ] = array(
573 573
 						'key' => $field_id,
574 574
 						'value' => esc_attr( $cat->name ) . ':' . $val,
575 575
 						'operator' => 'is',
@@ -588,18 +588,18 @@  discard block
 block discarded – undo
588 588
 				$filter = array();
589 589
 
590 590
 				foreach ( $value as $val ) {
591
-					$filter[] = array( 'key' => $field_id, 'value' => $val );
591
+					$filter[ ] = array( 'key' => $field_id, 'value' => $val );
592 592
 				}
593 593
 
594 594
 				break;
595 595
 
596 596
 			case 'checkbox':
597 597
 				// convert checkbox on/off into the correct search filter
598
-				if ( false !== strpos( $field_id, '.' ) && ! empty( $form_field['inputs'] ) && ! empty( $form_field['choices'] ) ) {
599
-					foreach ( $form_field['inputs'] as $k => $input ) {
600
-						if ( $input['id'] == $field_id ) {
601
-							$filter['value'] = $form_field['choices'][ $k ]['value'];
602
-							$filter['operator'] = 'is';
598
+				if ( false !== strpos( $field_id, '.' ) && ! empty( $form_field[ 'inputs' ] ) && ! empty( $form_field[ 'choices' ] ) ) {
599
+					foreach ( $form_field[ 'inputs' ] as $k => $input ) {
600
+						if ( $input[ 'id' ] == $field_id ) {
601
+							$filter[ 'value' ] = $form_field[ 'choices' ][ $k ][ 'value' ];
602
+							$filter[ 'operator' ] = 'is';
603 603
 							break;
604 604
 						}
605 605
 					}
@@ -609,7 +609,7 @@  discard block
 block discarded – undo
609 609
 					$filter = array();
610 610
 
611 611
 					foreach ( $value as $val ) {
612
-						$filter[] = array(
612
+						$filter[ ] = array(
613 613
 								'key'   => $field_id,
614 614
 								'value' => $val,
615 615
 								'operator' => 'is',
@@ -630,9 +630,9 @@  discard block
 block discarded – undo
630 630
 					foreach ( $words as $word ) {
631 631
 						if ( ! empty( $word ) && strlen( $word ) > 1 ) {
632 632
 							// Keep the same key for each filter
633
-							$filter['value'] = $word;
633
+							$filter[ 'value' ] = $word;
634 634
 							// Add a search for the value
635
-							$filters[] = $filter;
635
+							$filters[ ] = $filter;
636 636
 						}
637 637
 					}
638 638
 
@@ -659,19 +659,19 @@  discard block
 block discarded – undo
659 659
 						 * @since 1.16.3
660 660
 						 * Safeguard until GF implements '<=' operator
661 661
 						 */
662
-						if( !GFFormsModel::is_valid_operator( $operator ) && $operator === '<=' ) {
662
+						if ( ! GFFormsModel::is_valid_operator( $operator ) && $operator === '<=' ) {
663 663
 							$operator = '<';
664 664
 							$date = date( 'Y-m-d', strtotime( $date . ' +1 day' ) );
665 665
 						}
666 666
 
667
-						$filter[] = array(
667
+						$filter[ ] = array(
668 668
 							'key' => $field_id,
669 669
 							'value' => self::get_formatted_date( $date, 'Y-m-d' ),
670 670
 							'operator' => $operator,
671 671
 						);
672 672
 					}
673 673
 				} else {
674
-					$filter['value'] = self::get_formatted_date( $value, 'Y-m-d' );
674
+					$filter[ 'value' ] = self::get_formatted_date( $value, 'Y-m-d' );
675 675
 				}
676 676
 
677 677
 				break;
@@ -702,7 +702,7 @@  discard block
 block discarded – undo
702 702
 			'ymd_dot' => 'Y.m.d',
703 703
 		);
704 704
 
705
-		if ( ! empty( $field->dateFormat ) && isset( $datepicker[ $field->dateFormat ] ) ){
705
+		if ( ! empty( $field->dateFormat ) && isset( $datepicker[ $field->dateFormat ] ) ) {
706 706
 			$format = $datepicker[ $field->dateFormat ];
707 707
 		}
708 708
 
@@ -733,7 +733,7 @@  discard block
 block discarded – undo
733 733
 	public function add_template_path( $file_paths ) {
734 734
 
735 735
 		// Index 100 is the default GravityView template path.
736
-		$file_paths[102] = self::$file . 'templates/';
736
+		$file_paths[ 102 ] = self::$file . 'templates/';
737 737
 
738 738
 		return $file_paths;
739 739
 	}
@@ -756,7 +756,7 @@  discard block
 block discarded – undo
756 756
 		}
757 757
 
758 758
 		// get configured search fields
759
-		$search_fields = ! empty( $widget_args['search_fields'] ) ? json_decode( $widget_args['search_fields'], true ) : '';
759
+		$search_fields = ! empty( $widget_args[ 'search_fields' ] ) ? json_decode( $widget_args[ 'search_fields' ], true ) : '';
760 760
 
761 761
 		if ( empty( $search_fields ) || ! is_array( $search_fields ) ) {
762 762
 			do_action( 'gravityview_log_debug', sprintf( '%s[render_frontend] No search fields configured for widget:', get_class( $this ) ), $widget_args );
@@ -770,26 +770,26 @@  discard block
 block discarded – undo
770 770
 
771 771
 			$updated_field = $field;
772 772
 
773
-			if ( in_array( $field['input'], array( 'date', 'date_range' ) ) ) {
773
+			if ( in_array( $field[ 'input' ], array( 'date', 'date_range' ) ) ) {
774 774
 				$has_date = true;
775 775
 			}
776 776
 
777 777
 			$updated_field = $this->get_search_filter_details( $updated_field );
778 778
 
779
-			error_log("Field:Field = " . print_r($field['field'], true));
779
+			error_log( "Field:Field = " . print_r( $field[ 'field' ], true ) );
780 780
 
781
-			switch ( $field['field'] ) {
781
+			switch ( $field[ 'field' ] ) {
782 782
 
783 783
 				case 'search_all':
784
-					$updated_field['key'] = 'search_all';
785
-					$updated_field['input'] = 'search_all';
786
-					$updated_field['value'] = $this->rgget_or_rgpost( 'gv_search' );
784
+					$updated_field[ 'key' ] = 'search_all';
785
+					$updated_field[ 'input' ] = 'search_all';
786
+					$updated_field[ 'value' ] = $this->rgget_or_rgpost( 'gv_search' );
787 787
 					break;
788 788
 
789 789
 				case 'entry_date':
790
-					$updated_field['key'] = 'entry_date';
791
-					$updated_field['input'] = 'entry_date';
792
-					$updated_field['value'] = array(
790
+					$updated_field[ 'key' ] = 'entry_date';
791
+					$updated_field[ 'input' ] = 'entry_date';
792
+					$updated_field[ 'value' ] = array(
793 793
 						'start' => $this->rgget_or_rgpost( 'gv_start' ),
794 794
 						'end' => $this->rgget_or_rgpost( 'gv_end' ),
795 795
 					);
@@ -797,16 +797,16 @@  discard block
 block discarded – undo
797 797
 					break;
798 798
 
799 799
 				case 'entry_id':
800
-					$updated_field['key'] = 'entry_id';
801
-					$updated_field['input'] = 'entry_id';
802
-					$updated_field['value'] = $this->rgget_or_rgpost( 'gv_id' );
800
+					$updated_field[ 'key' ] = 'entry_id';
801
+					$updated_field[ 'input' ] = 'entry_id';
802
+					$updated_field[ 'value' ] = $this->rgget_or_rgpost( 'gv_id' );
803 803
 					break;
804 804
 
805 805
 				case 'created_by':
806
-					$updated_field['key'] = 'created_by';
807
-					$updated_field['name'] = 'gv_by';
808
-					$updated_field['value'] = $this->rgget_or_rgpost( 'gv_by' );
809
-					$updated_field['choices'] = self::get_created_by_choices();
806
+					$updated_field[ 'key' ] = 'created_by';
807
+					$updated_field[ 'name' ] = 'gv_by';
808
+					$updated_field[ 'value' ] = $this->rgget_or_rgpost( 'gv_by' );
809
+					$updated_field[ 'choices' ] = self::get_created_by_choices();
810 810
 					break;
811 811
 			}
812 812
 
@@ -824,16 +824,16 @@  discard block
 block discarded – undo
824 824
 		 */
825 825
 		$gravityview_view->search_fields = apply_filters( 'gravityview_widget_search_filters', $search_fields, $this, $widget_args );
826 826
 
827
-		$gravityview_view->search_layout = ! empty( $widget_args['search_layout'] ) ? $widget_args['search_layout'] : 'horizontal';
827
+		$gravityview_view->search_layout = ! empty( $widget_args[ 'search_layout' ] ) ? $widget_args[ 'search_layout' ] : 'horizontal';
828 828
 
829 829
 		/** @since 1.14 */
830
-		$gravityview_view->search_mode = ! empty( $widget_args['search_mode'] ) ? $widget_args['search_mode'] : 'any';
830
+		$gravityview_view->search_mode = ! empty( $widget_args[ 'search_mode' ] ) ? $widget_args[ 'search_mode' ] : 'any';
831 831
 
832
-		$custom_class = ! empty( $widget_args['custom_class'] ) ? $widget_args['custom_class'] : '';
832
+		$custom_class = ! empty( $widget_args[ 'custom_class' ] ) ? $widget_args[ 'custom_class' ] : '';
833 833
 
834 834
 		$gravityview_view->search_class = self::get_search_class( $custom_class );
835 835
 
836
-		$gravityview_view->search_clear = ! empty( $widget_args['search_clear'] ) ? $widget_args['search_clear'] : false;
836
+		$gravityview_view->search_clear = ! empty( $widget_args[ 'search_clear' ] ) ? $widget_args[ 'search_clear' ] : false;
837 837
 
838 838
 		if ( $has_date ) {
839 839
 			// enqueue datepicker stuff only if needed!
@@ -855,10 +855,10 @@  discard block
 block discarded – undo
855 855
 	public static function get_search_class( $custom_class = '' ) {
856 856
 		$gravityview_view = GravityView_View::getInstance();
857 857
 
858
-		$search_class = 'gv-search-'.$gravityview_view->search_layout;
858
+		$search_class = 'gv-search-' . $gravityview_view->search_layout;
859 859
 
860
-		if ( ! empty( $custom_class )  ) {
861
-			$search_class .= ' '.$custom_class;
860
+		if ( ! empty( $custom_class ) ) {
861
+			$search_class .= ' ' . $custom_class;
862 862
 		}
863 863
 
864 864
 		/**
@@ -900,11 +900,11 @@  discard block
 block discarded – undo
900 900
 
901 901
 		$label = rgget( 'label', $field );
902 902
 
903
-		if( '' === $label ) {
903
+		if ( '' === $label ) {
904 904
 
905
-			$label = isset( $form_field['label'] ) ? $form_field['label'] : '';
905
+			$label = isset( $form_field[ 'label' ] ) ? $form_field[ 'label' ] : '';
906 906
 
907
-			switch( $field['field'] ) {
907
+			switch ( $field[ 'field' ] ) {
908 908
 				case 'search_all':
909 909
 					$label = __( 'Search Entries:', 'gravityview' );
910 910
 					break;
@@ -916,10 +916,10 @@  discard block
 block discarded – undo
916 916
 					break;
917 917
 				default:
918 918
 					// If this is a field input, not a field
919
-					if ( strpos( $field['field'], '.' ) > 0 && ! empty( $form_field['inputs'] ) ) {
919
+					if ( strpos( $field[ 'field' ], '.' ) > 0 && ! empty( $form_field[ 'inputs' ] ) ) {
920 920
 
921 921
 						// Get the label for the field in question, which returns an array
922
-						$items = wp_list_filter( $form_field['inputs'], array( 'id' => $field['field'] ) );
922
+						$items = wp_list_filter( $form_field[ 'inputs' ], array( 'id' => $field[ 'field' ] ) );
923 923
 
924 924
 						// Get the item with the `label` key
925 925
 						$values = wp_list_pluck( $items, 'label' );
@@ -958,32 +958,32 @@  discard block
 block discarded – undo
958 958
 		$form = $gravityview_view->getForm();
959 959
 
960 960
 		// for advanced field ids (eg, first name / last name )
961
-		$name = 'filter_' . str_replace( '.', '_', $field['field'] );
961
+		$name = 'filter_' . str_replace( '.', '_', $field[ 'field' ] );
962 962
 
963 963
 		// get searched value from $_GET/$_POST (string or array)
964 964
 		$value = $this->rgget_or_rgpost( $name );
965 965
 
966 966
 		// get form field details
967
-		$form_field = gravityview_get_field( $form, $field['field'] );
967
+		$form_field = gravityview_get_field( $form, $field[ 'field' ] );
968 968
 
969 969
 		$filter = array(
970
-			'key' => $field['field'],
970
+			'key' => $field[ 'field' ],
971 971
 			'name' => $name,
972 972
 			'label' => self::get_field_label( $field, $form_field ),
973
-			'input' => $field['input'],
973
+			'input' => $field[ 'input' ],
974 974
 			'value' => $value,
975
-			'type' => $form_field['type'],
975
+			'type' => $form_field[ 'type' ],
976 976
 		);
977 977
 
978 978
 		// collect choices
979
-		if ( 'post_category' === $form_field['type'] && ! empty( $form_field['displayAllCategories'] ) && empty( $form_field['choices'] ) ) {
980
-			$filter['choices'] = gravityview_get_terms_choices();
981
-		} elseif ( ! empty( $form_field['choices'] ) ) {
982
-			$filter['choices'] = $form_field['choices'];
979
+		if ( 'post_category' === $form_field[ 'type' ] && ! empty( $form_field[ 'displayAllCategories' ] ) && empty( $form_field[ 'choices' ] ) ) {
980
+			$filter[ 'choices' ] = gravityview_get_terms_choices();
981
+		} elseif ( ! empty( $form_field[ 'choices' ] ) ) {
982
+			$filter[ 'choices' ] = $form_field[ 'choices' ];
983 983
 		}
984 984
 
985
-		if ( 'date_range' === $field['input'] && empty( $value ) ) {
986
-			$filter['value'] = array( 'start' => '', 'end' => '' );
985
+		if ( 'date_range' === $field[ 'input' ] && empty( $value ) ) {
986
+			$filter[ 'value' ] = array( 'start' => '', 'end' => '' );
987 987
 		}
988 988
 
989 989
 		return $filter;
@@ -1007,7 +1007,7 @@  discard block
 block discarded – undo
1007 1007
 
1008 1008
 		$choices = array();
1009 1009
 		foreach ( $users as $user ) {
1010
-			$choices[] = array(
1010
+			$choices[ ] = array(
1011 1011
 				'value' => $user->ID,
1012 1012
 				'text' => $user->display_name,
1013 1013
 			);
@@ -1062,7 +1062,7 @@  discard block
 block discarded – undo
1062 1062
 	 */
1063 1063
 	public function add_datepicker_js_dependency( $js_dependencies ) {
1064 1064
 
1065
-		$js_dependencies[] = 'jquery-ui-datepicker';
1065
+		$js_dependencies[ ] = 'jquery-ui-datepicker';
1066 1066
 
1067 1067
 		return $js_dependencies;
1068 1068
 	}
@@ -1106,7 +1106,7 @@  discard block
 block discarded – undo
1106 1106
 			'isRTL'             => is_rtl(),
1107 1107
 		), $view_data );
1108 1108
 
1109
-		$localizations['datepicker'] = $datepicker_settings;
1109
+		$localizations[ 'datepicker' ] = $datepicker_settings;
1110 1110
 
1111 1111
 		return $localizations;
1112 1112
 
@@ -1135,7 +1135,7 @@  discard block
 block discarded – undo
1135 1135
 	 * @return void
1136 1136
 	 */
1137 1137
 	private function maybe_enqueue_flexibility() {
1138
-		if ( isset( $_SERVER['HTTP_USER_AGENT'] ) && preg_match( '/MSIE [8-9]/', $_SERVER['HTTP_USER_AGENT'] ) ) {
1138
+		if ( isset( $_SERVER[ 'HTTP_USER_AGENT' ] ) && preg_match( '/MSIE [8-9]/', $_SERVER[ 'HTTP_USER_AGENT' ] ) ) {
1139 1139
 			wp_enqueue_script( 'gv-flexibility' );
1140 1140
 		}
1141 1141
 	}
@@ -1157,7 +1157,7 @@  discard block
 block discarded – undo
1157 1157
 		add_filter( 'gravityview_js_localization', array( $this, 'add_datepicker_localization' ), 10, 2 );
1158 1158
 
1159 1159
 		$scheme = is_ssl() ? 'https://' : 'http://';
1160
-		wp_enqueue_style( 'jquery-ui-datepicker', $scheme.'ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/themes/smoothness/jquery-ui.css' );
1160
+		wp_enqueue_style( 'jquery-ui-datepicker', $scheme . 'ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/themes/smoothness/jquery-ui.css' );
1161 1161
 
1162 1162
 		/**
1163 1163
 		 * @filter `gravityview_search_datepicker_class`
Please login to merge, or discard this patch.
includes/class-admin-views.php 1 patch
Spacing   +170 added lines, -170 removed lines patch added patch discarded remove patch
@@ -28,30 +28,30 @@  discard block
 block discarded – undo
28 28
 		add_filter( 'gravityview_blacklist_field_types', array( $this, 'default_field_blacklist' ), 10, 2 );
29 29
 
30 30
 		// Tooltips
31
-		add_filter( 'gform_tooltips', array( $this, 'tooltips') );
31
+		add_filter( 'gform_tooltips', array( $this, 'tooltips' ) );
32 32
 
33 33
 		// adding styles and scripts
34
-		add_action( 'admin_enqueue_scripts', array( 'GravityView_Admin_Views', 'add_scripts_and_styles'), 999 );
35
-		add_filter( 'gform_noconflict_styles', array( $this, 'register_no_conflict') );
36
-		add_filter( 'gform_noconflict_scripts', array( $this, 'register_no_conflict') );
37
-		add_filter( 'gravityview_noconflict_styles', array( $this, 'register_no_conflict') );
38
-		add_filter( 'gravityview_noconflict_scripts', array( $this, 'register_no_conflict') );
39
-
40
-		add_action( 'gravityview_render_directory_active_areas', array( $this, 'render_directory_active_areas'), 10, 4 );
41
-		add_action( 'gravityview_render_widgets_active_areas', array( $this, 'render_widgets_active_areas'), 10, 3 );
42
-		add_action( 'gravityview_render_available_fields', array( $this, 'render_available_fields'), 10, 2 );
43
-		add_action( 'gravityview_render_available_widgets', array( $this, 'render_available_widgets') );
44
-		add_action( 'gravityview_render_active_areas', array( $this, 'render_active_areas'), 10, 5 );
34
+		add_action( 'admin_enqueue_scripts', array( 'GravityView_Admin_Views', 'add_scripts_and_styles' ), 999 );
35
+		add_filter( 'gform_noconflict_styles', array( $this, 'register_no_conflict' ) );
36
+		add_filter( 'gform_noconflict_scripts', array( $this, 'register_no_conflict' ) );
37
+		add_filter( 'gravityview_noconflict_styles', array( $this, 'register_no_conflict' ) );
38
+		add_filter( 'gravityview_noconflict_scripts', array( $this, 'register_no_conflict' ) );
39
+
40
+		add_action( 'gravityview_render_directory_active_areas', array( $this, 'render_directory_active_areas' ), 10, 4 );
41
+		add_action( 'gravityview_render_widgets_active_areas', array( $this, 'render_widgets_active_areas' ), 10, 3 );
42
+		add_action( 'gravityview_render_available_fields', array( $this, 'render_available_fields' ), 10, 2 );
43
+		add_action( 'gravityview_render_available_widgets', array( $this, 'render_available_widgets' ) );
44
+		add_action( 'gravityview_render_active_areas', array( $this, 'render_active_areas' ), 10, 5 );
45 45
 
46 46
 		// @todo check if this hook is needed..
47 47
 		//add_action( 'gravityview_render_field_options', array( $this, 'render_field_options'), 10, 9 );
48 48
 
49 49
 		// Add Connected Form column
50
-		add_filter('manage_gravityview_posts_columns' , array( $this, 'add_post_type_columns' ) );
50
+		add_filter( 'manage_gravityview_posts_columns', array( $this, 'add_post_type_columns' ) );
51 51
 
52 52
 		add_filter( 'gform_toolbar_menu', array( 'GravityView_Admin_Views', 'gform_toolbar_menu' ), 10, 2 );
53 53
 
54
-		add_action( 'manage_gravityview_posts_custom_column', array( $this, 'add_custom_column_content'), 10, 2 );
54
+		add_action( 'manage_gravityview_posts_custom_column', array( $this, 'add_custom_column_content' ), 10, 2 );
55 55
 
56 56
 		add_action( 'restrict_manage_posts', array( $this, 'add_view_dropdown' ) );
57 57
 
@@ -66,11 +66,11 @@  discard block
 block discarded – undo
66 66
 	public function filter_pre_get_posts_by_gravityview_form_id( &$query ) {
67 67
 		global $pagenow;
68 68
 
69
-		if ( !is_admin() ) {
69
+		if ( ! is_admin() ) {
70 70
 			return;
71 71
 		}
72 72
 
73
-		if( 'edit.php' !== $pagenow || ! rgget( 'gravityview_form_id' ) || ! isset( $query->query_vars[ 'post_type' ] ) ) {
73
+		if ( 'edit.php' !== $pagenow || ! rgget( 'gravityview_form_id' ) || ! isset( $query->query_vars[ 'post_type' ] ) ) {
74 74
 			return;
75 75
 		}
76 76
 
@@ -87,18 +87,18 @@  discard block
 block discarded – undo
87 87
 	function add_view_dropdown() {
88 88
 		$current_screen = get_current_screen();
89 89
 
90
-		if( 'gravityview' !== $current_screen->post_type ) {
90
+		if ( 'gravityview' !== $current_screen->post_type ) {
91 91
 			return;
92 92
 		}
93 93
 
94 94
 		$forms = gravityview_get_forms();
95 95
 		$current_form = rgget( 'gravityview_form_id' );
96 96
 		// If there are no forms to select, show no forms.
97
-		if( !empty( $forms ) ) { ?>
97
+		if ( ! empty( $forms ) ) { ?>
98 98
 			<select name="gravityview_form_id" id="gravityview_form_id">
99 99
 				<option value="" <?php selected( '', $current_form, true ); ?>><?php esc_html_e( 'All forms', 'gravityview' ); ?></option>
100
-				<?php foreach( $forms as $form ) { ?>
101
-					<option value="<?php echo $form['id']; ?>" <?php selected( $form['id'], $current_form, true ); ?>><?php echo esc_html( $form['title'] ); ?></option>
100
+				<?php foreach ( $forms as $form ) { ?>
101
+					<option value="<?php echo $form[ 'id' ]; ?>" <?php selected( $form[ 'id' ], $current_form, true ); ?>><?php echo esc_html( $form[ 'title' ] ); ?></option>
102 102
 				<?php } ?>
103 103
 			</select>
104 104
 		<?php }
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 	 */
112 112
 	public static function render_setting_row( $key = '', $current_settings = array(), $override_input = null, $name = 'template_settings[%s]', $id = 'gravityview_se_%s' ) {
113 113
 		_deprecated_function( 'GravityView_Admin_Views::render_setting_row', '1.1.7', 'GravityView_Render_Settings::render_setting_row' );
114
-		GravityView_Render_Settings::render_setting_row( $key, $current_settings, $override_input, $name , $id );
114
+		GravityView_Render_Settings::render_setting_row( $key, $current_settings, $override_input, $name, $id );
115 115
 	}
116 116
 
117 117
 	/**
@@ -134,37 +134,37 @@  discard block
 block discarded – undo
134 134
 
135 135
 		$connected_views = gravityview_get_connected_views( $id );
136 136
 
137
-		if( empty( $connected_views ) ) {
137
+		if ( empty( $connected_views ) ) {
138 138
 			return $menu_items;
139 139
 		}
140 140
 
141 141
 		$sub_menu_items = array();
142 142
 		foreach ( (array)$connected_views as $view ) {
143 143
 
144
-			if( ! GVCommon::has_cap( 'edit_gravityview', $view->ID ) ) {
144
+			if ( ! GVCommon::has_cap( 'edit_gravityview', $view->ID ) ) {
145 145
 				continue;
146 146
 			}
147 147
 
148
-			$label = empty( $view->post_title ) ? sprintf( __('No Title (View #%d)', 'gravityview' ), $view->ID ) : $view->post_title;
148
+			$label = empty( $view->post_title ) ? sprintf( __( 'No Title (View #%d)', 'gravityview' ), $view->ID ) : $view->post_title;
149 149
 
150
-			$sub_menu_items[] = array(
150
+			$sub_menu_items[ ] = array(
151 151
 				'label' => esc_attr( $label ),
152
-				'url' => admin_url( 'post.php?action=edit&post='.$view->ID ),
152
+				'url' => admin_url( 'post.php?action=edit&post=' . $view->ID ),
153 153
 			);
154 154
 		}
155 155
 
156 156
 		// If there were no items added, then let's create the parent menu
157
-		if( $sub_menu_items ) {
157
+		if ( $sub_menu_items ) {
158 158
 
159 159
 			// Make sure Gravity Forms uses the submenu; if there's only one item, it uses a link instead of a dropdown
160
-			$sub_menu_items[] = array(
160
+			$sub_menu_items[ ] = array(
161 161
 				'url' => '#',
162 162
 				'label' => '',
163 163
 				'menu_class' => 'hidden',
164 164
 				'capabilities' => '',
165 165
 			);
166 166
 
167
-			$menu_items['gravityview'] = array(
167
+			$menu_items[ 'gravityview' ] = array(
168 168
 				'label'          => __( 'Connected Views', 'gravityview' ),
169 169
 				'icon'           => '<i class="fa fa-lg gv-icon-astronaut-head gv-icon"></i>',
170 170
 				'title'          => __( 'GravityView Views using this form as a data source', 'gravityview' ),
@@ -194,8 +194,8 @@  discard block
 block discarded – undo
194 194
 		$add = array( 'captcha', 'page' );
195 195
 
196 196
 		// Don't allowing editing the following values:
197
-		if( $context === 'edit' ) {
198
-			$add[] = 'post_id';
197
+		if ( $context === 'edit' ) {
198
+			$add[ ] = 'post_id';
199 199
 		}
200 200
 
201 201
 		$return = array_merge( $array, $add );
@@ -218,32 +218,32 @@  discard block
 block discarded – undo
218 218
 		foreach ( $default_args as $key => $arg ) {
219 219
 
220 220
 			// If an arg has `tooltip` defined, but it's false, don't display a tooltip
221
-			if( isset( $arg['tooltip'] ) && empty( $arg['tooltip'] ) ) { continue; }
221
+			if ( isset( $arg[ 'tooltip' ] ) && empty( $arg[ 'tooltip' ] ) ) { continue; }
222 222
 
223 223
 			// By default, use `tooltip` if defined.
224
-			$tooltip = empty( $arg['tooltip'] ) ? NULL : $arg['tooltip'];
224
+			$tooltip = empty( $arg[ 'tooltip' ] ) ? NULL : $arg[ 'tooltip' ];
225 225
 
226 226
 			// Otherwise, use the description as a tooltip.
227
-			if( empty( $tooltip ) && !empty( $arg['desc'] ) ) {
228
-				$tooltip = $arg['desc'];
227
+			if ( empty( $tooltip ) && ! empty( $arg[ 'desc' ] ) ) {
228
+				$tooltip = $arg[ 'desc' ];
229 229
 			}
230 230
 
231 231
 			// If there's no tooltip set, continue
232
-			if( empty( $tooltip ) ) {
232
+			if ( empty( $tooltip ) ) {
233 233
 				continue;
234 234
 			}
235 235
 
236 236
 			// Add the tooltip
237
-			$gv_tooltips[ 'gv_'.$key ] = array(
238
-				'title'	=> $arg['label'],
237
+			$gv_tooltips[ 'gv_' . $key ] = array(
238
+				'title'	=> $arg[ 'label' ],
239 239
 				'value'	=> $tooltip,
240 240
 			);
241 241
 
242 242
 		}
243 243
 
244
-		$gv_tooltips['gv_css_merge_tags'] = array(
245
-			'title' => __('CSS Merge Tags', 'gravityview'),
246
-			'value' => sprintf( __( 'Developers: The CSS classes will be sanitized using the %ssanitize_title_with_dashes()%s function.', 'gravityview'), '<code>', '</code>' )
244
+		$gv_tooltips[ 'gv_css_merge_tags' ] = array(
245
+			'title' => __( 'CSS Merge Tags', 'gravityview' ),
246
+			'value' => sprintf( __( 'Developers: The CSS classes will be sanitized using the %ssanitize_title_with_dashes()%s function.', 'gravityview' ), '<code>', '</code>' )
247 247
 		);
248 248
 
249 249
 		/**
@@ -254,9 +254,9 @@  discard block
 block discarded – undo
254 254
 
255 255
 		foreach ( $gv_tooltips as $key => $tooltip ) {
256 256
 
257
-			$title = empty( $tooltip['title'] ) ? '' : '<h6>'.esc_html( $tooltip['title'] ) .'</h6>';
257
+			$title = empty( $tooltip[ 'title' ] ) ? '' : '<h6>' . esc_html( $tooltip[ 'title' ] ) . '</h6>';
258 258
 
259
-			$tooltips[ $key ] = $title . wpautop( esc_html( $tooltip['value'] ) );
259
+			$tooltips[ $key ] = $title . wpautop( esc_html( $tooltip[ 'value' ] ) );
260 260
 		}
261 261
 
262 262
 		return $tooltips;
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
 	 *
271 271
 	 * @return void
272 272
 	 */
273
-	public function add_custom_column_content( $column_name = NULL, $post_id )	{
273
+	public function add_custom_column_content( $column_name = NULL, $post_id ) {
274 274
 
275 275
 		$output = '';
276 276
 
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
 				// Generate backup if label doesn't exist: `example_name` => `Example Name`
293 293
 				$template_id_pretty = ucwords( implode( ' ', explode( '_', $template_id ) ) );
294 294
 
295
-				$output = $template ? $template['label'] : $template_id_pretty;
295
+				$output = $template ? $template[ 'label' ] : $template_id_pretty;
296 296
 
297 297
 				break;
298 298
 
@@ -333,44 +333,44 @@  discard block
 block discarded – undo
333 333
 	static public function get_connected_form_links( $form, $include_form_link = true ) {
334 334
 
335 335
 		// Either the form is empty or the form ID is 0, not yet set.
336
-		if( empty( $form ) ) {
336
+		if ( empty( $form ) ) {
337 337
 			return '';
338 338
 		}
339 339
 
340 340
 		// The $form is passed as the form ID
341
-		if( !is_array( $form ) ) {
341
+		if ( ! is_array( $form ) ) {
342 342
 			$form = gravityview_get_form( $form );
343 343
 		}
344 344
 
345
-		$form_id = $form['id'];
345
+		$form_id = $form[ 'id' ];
346 346
 		$links = array();
347 347
 
348
-		if( GVCommon::has_cap( 'gravityforms_edit_forms' ) ) {
348
+		if ( GVCommon::has_cap( 'gravityforms_edit_forms' ) ) {
349 349
 			$form_url = admin_url( sprintf( 'admin.php?page=gf_edit_forms&amp;id=%d', $form_id ) );
350
-			$form_link = '<strong class="gv-form-title">'.gravityview_get_link( $form_url, $form['title'], 'class=row-title' ).'</strong>';
351
-			$links[] = '<span>'.gravityview_get_link( $form_url, __('Edit Form', 'gravityview') ).'</span>';
350
+			$form_link = '<strong class="gv-form-title">' . gravityview_get_link( $form_url, $form[ 'title' ], 'class=row-title' ) . '</strong>';
351
+			$links[ ] = '<span>' . gravityview_get_link( $form_url, __( 'Edit Form', 'gravityview' ) ) . '</span>';
352 352
 		} else {
353
-			$form_link = '<strong class="gv-form-title">'. esc_html( $form['title'] ). '</strong>';
353
+			$form_link = '<strong class="gv-form-title">' . esc_html( $form[ 'title' ] ) . '</strong>';
354 354
 		}
355 355
 
356
-		if( GVCommon::has_cap( 'gravityforms_view_entries' ) ) {
356
+		if ( GVCommon::has_cap( 'gravityforms_view_entries' ) ) {
357 357
 			$entries_url = admin_url( sprintf( 'admin.php?page=gf_entries&amp;id=%d', $form_id ) );
358
-			$links[] = '<span>'.gravityview_get_link( $entries_url, __('Entries', 'gravityview') ).'</span>';
358
+			$links[ ] = '<span>' . gravityview_get_link( $entries_url, __( 'Entries', 'gravityview' ) ) . '</span>';
359 359
 		}
360 360
 
361
-		if( GVCommon::has_cap( array( 'gravityforms_edit_settings', 'gravityview_view_settings' ) ) ) {
361
+		if ( GVCommon::has_cap( array( 'gravityforms_edit_settings', 'gravityview_view_settings' ) ) ) {
362 362
 			$settings_url = admin_url( sprintf( 'admin.php?page=gf_edit_forms&amp;view=settings&amp;id=%d', $form_id ) );
363
-			$links[] = '<span>'.gravityview_get_link( $settings_url, __('Settings', 'gravityview'), 'title='.__('Edit settings for this form', 'gravityview') ).'</span>';
363
+			$links[ ] = '<span>' . gravityview_get_link( $settings_url, __( 'Settings', 'gravityview' ), 'title=' . __( 'Edit settings for this form', 'gravityview' ) ) . '</span>';
364 364
 		}
365 365
 
366
-		if( GVCommon::has_cap( array("gravityforms_edit_forms", "gravityforms_create_form", "gravityforms_preview_forms") ) ) {
366
+		if ( GVCommon::has_cap( array( "gravityforms_edit_forms", "gravityforms_create_form", "gravityforms_preview_forms" ) ) ) {
367 367
 			$preview_url = site_url( sprintf( '?gf_page=preview&amp;id=%d', $form_id ) );
368
-			$links[] = '<span>'.gravityview_get_link( $preview_url, __('Preview Form', 'gravityview'), 'title='.__('Preview this form', 'gravityview') ).'</span>';
368
+			$links[ ] = '<span>' . gravityview_get_link( $preview_url, __( 'Preview Form', 'gravityview' ), 'title=' . __( 'Preview this form', 'gravityview' ) ) . '</span>';
369 369
 		}
370 370
 
371 371
 		$output = '';
372 372
 
373
-		if( !empty( $include_form_link ) ) {
373
+		if ( ! empty( $include_form_link ) ) {
374 374
 			$output .= $form_link;
375 375
 		}
376 376
 
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
 		 */
383 383
 		$links = apply_filters( 'gravityview_connected_form_links', $links, $form );
384 384
 
385
-		$output .= '<div class="row-actions">'. implode( ' | ', $links ) .'</div>';
385
+		$output .= '<div class="row-actions">' . implode( ' | ', $links ) . '</div>';
386 386
 
387 387
 		return $output;
388 388
 	}
@@ -396,8 +396,8 @@  discard block
 block discarded – undo
396 396
 		// Get the date column and save it for later to add back in.
397 397
 		// This adds it after the Data Source column.
398 398
 		// This way, we don't need to do array_slice, array_merge, etc.
399
-		$date = $columns['date'];
400
-		unset( $columns['date'] );
399
+		$date = $columns[ 'date' ];
400
+		unset( $columns[ 'date' ] );
401 401
 
402 402
 		$data_source_required_caps = array(
403 403
 			'gravityforms_edit_forms',
@@ -408,14 +408,14 @@  discard block
 block discarded – undo
408 408
 			'gravityforms_preview_forms',
409 409
 		);
410 410
 
411
-		if( GVCommon::has_cap( $data_source_required_caps ) ) {
412
-			$columns['gv_connected_form'] = __( 'Data Source', 'gravityview' );
411
+		if ( GVCommon::has_cap( $data_source_required_caps ) ) {
412
+			$columns[ 'gv_connected_form' ] = __( 'Data Source', 'gravityview' );
413 413
 		}
414 414
 
415
-		$columns['gv_template'] = _x( 'Template', 'Column title that shows what template is being used for Views', 'gravityview' );
415
+		$columns[ 'gv_template' ] = _x( 'Template', 'Column title that shows what template is being used for Views', 'gravityview' );
416 416
 
417 417
 		// Add the date back in.
418
-		$columns['date'] = $date;
418
+		$columns[ 'date' ] = $date;
419 419
 
420 420
 		return $columns;
421 421
 	}
@@ -429,12 +429,12 @@  discard block
 block discarded – undo
429 429
 	 */
430 430
 	function save_postdata( $post_id ) {
431 431
 
432
-		if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ){
432
+		if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
433 433
 			return;
434 434
 		}
435 435
 
436 436
 		// validate post_type
437
-		if ( ! isset( $_POST['post_type'] ) || 'gravityview' != $_POST['post_type'] ) {
437
+		if ( ! isset( $_POST[ 'post_type' ] ) || 'gravityview' != $_POST[ 'post_type' ] ) {
438 438
 			return;
439 439
 		}
440 440
 
@@ -449,63 +449,63 @@  discard block
 block discarded – undo
449 449
 		$statii = array();
450 450
 
451 451
 		// check if this is a start fresh View
452
-		if ( isset( $_POST['gravityview_select_form_nonce'] ) && wp_verify_nonce( $_POST['gravityview_select_form_nonce'], 'gravityview_select_form' ) ) {
452
+		if ( isset( $_POST[ 'gravityview_select_form_nonce' ] ) && wp_verify_nonce( $_POST[ 'gravityview_select_form_nonce' ], 'gravityview_select_form' ) ) {
453 453
 
454
-			$form_id = !empty( $_POST['gravityview_form_id'] ) ? $_POST['gravityview_form_id'] : '';
454
+			$form_id = ! empty( $_POST[ 'gravityview_form_id' ] ) ? $_POST[ 'gravityview_form_id' ] : '';
455 455
 			// save form id
456
-			$statii['form_id'] = update_post_meta( $post_id, '_gravityview_form_id', $form_id );
456
+			$statii[ 'form_id' ] = update_post_meta( $post_id, '_gravityview_form_id', $form_id );
457 457
 
458 458
 		}
459 459
 
460
-		if( false === GVCommon::has_cap( 'gravityforms_create_form' ) && empty( $statii['form_id'] ) ) {
460
+		if ( false === GVCommon::has_cap( 'gravityforms_create_form' ) && empty( $statii[ 'form_id' ] ) ) {
461 461
 			do_action( 'gravityview_log_error', __METHOD__ . ' - Current user does not have the capability to create a new Form.', wp_get_current_user() );
462 462
 			return;
463 463
 		}
464 464
 
465 465
 		// Was this a start fresh?
466
-		if ( ! empty( $_POST['gravityview_form_id_start_fresh'] ) ) {
467
-			$statii['start_fresh'] = add_post_meta( $post_id, '_gravityview_start_fresh', 1 );
466
+		if ( ! empty( $_POST[ 'gravityview_form_id_start_fresh' ] ) ) {
467
+			$statii[ 'start_fresh' ] = add_post_meta( $post_id, '_gravityview_start_fresh', 1 );
468 468
 		} else {
469
-			$statii['start_fresh'] = delete_post_meta( $post_id, '_gravityview_start_fresh' );
469
+			$statii[ 'start_fresh' ] = delete_post_meta( $post_id, '_gravityview_start_fresh' );
470 470
 		}
471 471
 
472 472
 		// Check if we have a template id
473
-		if ( isset( $_POST['gravityview_select_template_nonce'] ) && wp_verify_nonce( $_POST['gravityview_select_template_nonce'], 'gravityview_select_template' ) ) {
473
+		if ( isset( $_POST[ 'gravityview_select_template_nonce' ] ) && wp_verify_nonce( $_POST[ 'gravityview_select_template_nonce' ], 'gravityview_select_template' ) ) {
474 474
 
475
-			$template_id = !empty( $_POST['gravityview_directory_template'] ) ? $_POST['gravityview_directory_template'] : '';
475
+			$template_id = ! empty( $_POST[ 'gravityview_directory_template' ] ) ? $_POST[ 'gravityview_directory_template' ] : '';
476 476
 
477 477
 			// now save template id
478
-			$statii['directory_template'] = update_post_meta( $post_id, '_gravityview_directory_template', $template_id );
478
+			$statii[ 'directory_template' ] = update_post_meta( $post_id, '_gravityview_directory_template', $template_id );
479 479
 		}
480 480
 
481 481
 
482 482
 		// save View Configuration metabox
483
-		if ( isset( $_POST['gravityview_view_configuration_nonce'] ) && wp_verify_nonce( $_POST['gravityview_view_configuration_nonce'], 'gravityview_view_configuration' ) ) {
483
+		if ( isset( $_POST[ 'gravityview_view_configuration_nonce' ] ) && wp_verify_nonce( $_POST[ 'gravityview_view_configuration_nonce' ], 'gravityview_view_configuration' ) ) {
484 484
 
485 485
 			// template settings
486
-			if( empty( $_POST['template_settings'] ) ) {
487
-				$_POST['template_settings'] = array();
486
+			if ( empty( $_POST[ 'template_settings' ] ) ) {
487
+				$_POST[ 'template_settings' ] = array();
488 488
 			}
489
-			$statii['template_settings'] = update_post_meta( $post_id, '_gravityview_template_settings', $_POST['template_settings'] );
489
+			$statii[ 'template_settings' ] = update_post_meta( $post_id, '_gravityview_template_settings', $_POST[ 'template_settings' ] );
490 490
 
491 491
 			$fields = array();
492 492
 
493 493
 			// Directory&single Visible Fields
494
-			if( !empty( $preset_fields ) ) {
494
+			if ( ! empty( $preset_fields ) ) {
495 495
 
496 496
 				$fields = $preset_fields;
497 497
 
498
-			} elseif( !empty( $_POST['gv_fields'] ) ) {
498
+			} elseif ( ! empty( $_POST[ 'gv_fields' ] ) ) {
499 499
 				$fields = _gravityview_process_posted_fields();
500 500
 			}
501 501
 
502
-			$statii['directory_fields'] = update_post_meta( $post_id, '_gravityview_directory_fields', $fields );
502
+			$statii[ 'directory_fields' ] = update_post_meta( $post_id, '_gravityview_directory_fields', $fields );
503 503
 
504 504
 			// Directory Visible Widgets
505
-			if( empty( $_POST['widgets'] ) ) {
506
-				$_POST['widgets'] = array();
505
+			if ( empty( $_POST[ 'widgets' ] ) ) {
506
+				$_POST[ 'widgets' ] = array();
507 507
 			}
508
-			$statii['directory_widgets'] = gravityview_set_directory_widgets( $post_id, $_POST['widgets'] );
508
+			$statii[ 'directory_widgets' ] = gravityview_set_directory_widgets( $post_id, $_POST[ 'widgets' ] );
509 509
 
510 510
 		} // end save view configuration
511 511
 
@@ -515,9 +515,9 @@  discard block
 block discarded – undo
515 515
 		 * @param array $statii Array of statuses of the post meta saving processes. If saving worked, each key should be mapped to a value of the post ID (`directory_widgets` => `124`). If failed (or didn't change), the value will be false.
516 516
 		 * @since 1.17.2
517 517
 		 */
518
-		do_action('gravityview_view_saved', $post_id, $statii );
518
+		do_action( 'gravityview_view_saved', $post_id, $statii );
519 519
 
520
-		do_action('gravityview_log_debug', '[save_postdata] Update Post Meta Statuses (also returns false if nothing changed)', array_map( 'intval', $statii ) );
520
+		do_action( 'gravityview_log_debug', '[save_postdata] Update Post Meta Statuses (also returns false if nothing changed)', array_map( 'intval', $statii ) );
521 521
 	}
522 522
 
523 523
 	/**
@@ -549,20 +549,20 @@  discard block
 block discarded – undo
549 549
 
550 550
 		$output = '';
551 551
 
552
-		if( !empty( $fields ) ) {
552
+		if ( ! empty( $fields ) ) {
553 553
 
554
-			foreach( $fields as $id => $details ) {
554
+			foreach ( $fields as $id => $details ) {
555 555
 
556
-				if( in_array( $details['type'], $blacklist_field_types ) ) {
556
+				if ( in_array( $details[ 'type' ], $blacklist_field_types ) ) {
557 557
 					continue;
558 558
 				}
559 559
 
560 560
 				// Edit mode only allows editing the parent fields, not single inputs.
561
-				if( $context === 'edit' && !empty( $details['parent'] ) ) {
561
+				if ( $context === 'edit' && ! empty( $details[ 'parent' ] ) ) {
562 562
 					continue;
563 563
 				}
564 564
 
565
-				$output .= new GravityView_Admin_View_Field( $details['label'], $id, $details );
565
+				$output .= new GravityView_Admin_View_Field( $details[ 'label' ], $id, $details );
566 566
 
567 567
 			} // End foreach
568 568
 		}
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
 		echo $output;
571 571
 
572 572
 		// For the EDIT view we only want to allow the form fields.
573
-		if( $context === 'edit' ) {
573
+		if ( $context === 'edit' ) {
574 574
 			return;
575 575
 		}
576 576
 
@@ -594,16 +594,16 @@  discard block
 block discarded – undo
594 594
 		$additional_fields = apply_filters( 'gravityview_additional_fields', array(
595 595
 			array(
596 596
 				'label_text' => __( '+ Add All Fields', 'gravityview' ),
597
-				'desc' => __('Add all the available fields at once.', 'gravityview'),
597
+				'desc' => __( 'Add all the available fields at once.', 'gravityview' ),
598 598
 				'field_id' => 'all-fields',
599 599
 				'label_type' => 'field',
600 600
 				'input_type' => NULL,
601 601
 				'field_options' => NULL,
602 602
 				'settings_html'	=> NULL,
603 603
 			)
604
-		));
604
+		) );
605 605
 
606
-		if( !empty( $additional_fields )) {
606
+		if ( ! empty( $additional_fields ) ) {
607 607
 			foreach ( (array)$additional_fields as $item ) {
608 608
 
609 609
 				// Prevent items from not having index set
@@ -614,16 +614,16 @@  discard block
 block discarded – undo
614 614
 					'input_type' => NULL,
615 615
 					'field_options' => NULL,
616 616
 					'settings_html'	=> NULL,
617
-				));
617
+				) );
618 618
 
619 619
 				// Backward compat.
620
-				if( !empty( $item['field_options'] ) ) {
620
+				if ( ! empty( $item[ 'field_options' ] ) ) {
621 621
 					// Use settings_html from now on.
622
-					$item['settings_html'] = $item['field_options'];
622
+					$item[ 'settings_html' ] = $item[ 'field_options' ];
623 623
 				}
624 624
 
625 625
 				// Render a label for each of them
626
-				echo new GravityView_Admin_View_Field( $item['label_text'], $item['field_id'], $item );
626
+				echo new GravityView_Admin_View_Field( $item[ 'label_text' ], $item[ 'field_id' ], $item );
627 627
 
628 628
 			}
629 629
 		}
@@ -636,63 +636,63 @@  discard block
 block discarded – undo
636 636
 	 * @param  string $zone   Either 'single', 'directory', 'header', 'footer'
637 637
 	 * @return array
638 638
 	 */
639
-	function get_entry_default_fields($form, $zone) {
639
+	function get_entry_default_fields( $form, $zone ) {
640 640
 
641 641
 		$entry_default_fields = array();
642 642
 
643
-		if( in_array( $zone, array( 'directory', 'single' ) ) ) {
643
+		if ( in_array( $zone, array( 'directory', 'single' ) ) ) {
644 644
 
645 645
 			$entry_default_fields = array(
646 646
 				'id' => array(
647
-					'label' => __('Entry ID', 'gravityview'),
647
+					'label' => __( 'Entry ID', 'gravityview' ),
648 648
 					'type' => 'id',
649
-					'desc'	=> __('The unique ID of the entry.', 'gravityview'),
649
+					'desc'	=> __( 'The unique ID of the entry.', 'gravityview' ),
650 650
 				),
651 651
 				'date_created' => array(
652
-					'label' => __('Entry Date', 'gravityview'),
653
-					'desc'	=> __('The date the entry was created.', 'gravityview'),
652
+					'label' => __( 'Entry Date', 'gravityview' ),
653
+					'desc'	=> __( 'The date the entry was created.', 'gravityview' ),
654 654
 					'type' => 'date_created',
655 655
 				),
656 656
 				'source_url' => array(
657
-					'label' => __('Source URL', 'gravityview'),
657
+					'label' => __( 'Source URL', 'gravityview' ),
658 658
 					'type' => 'source_url',
659
-					'desc'	=> __('The URL of the page where the form was submitted.', 'gravityview'),
659
+					'desc'	=> __( 'The URL of the page where the form was submitted.', 'gravityview' ),
660 660
 				),
661 661
 				'ip' => array(
662
-					'label' => __('User IP', 'gravityview'),
662
+					'label' => __( 'User IP', 'gravityview' ),
663 663
 					'type' => 'ip',
664
-					'desc'	=> __('The IP Address of the user who created the entry.', 'gravityview'),
664
+					'desc'	=> __( 'The IP Address of the user who created the entry.', 'gravityview' ),
665 665
 				),
666 666
 				'created_by' => array(
667
-					'label' => __('User', 'gravityview'),
667
+					'label' => __( 'User', 'gravityview' ),
668 668
 					'type' => 'created_by',
669
-					'desc'	=> __('Details of the logged-in user who created the entry (if any).', 'gravityview'),
669
+					'desc'	=> __( 'Details of the logged-in user who created the entry (if any).', 'gravityview' ),
670 670
 				),
671 671
 
672 672
 				/**
673 673
 				 * @since  1.2
674 674
 				 */
675 675
 				'custom'	=> array(
676
-					'label'	=> __('Custom Content', 'gravityview'),
676
+					'label'	=> __( 'Custom Content', 'gravityview' ),
677 677
 					'type'	=> 'custom',
678
-					'desc'	=> __('Insert custom text or HTML.', 'gravityview'),
678
+					'desc'	=> __( 'Insert custom text or HTML.', 'gravityview' ),
679 679
 				),
680 680
 
681 681
 				/**
682 682
 				 * @since 1.7.2
683 683
 				 */
684 684
 			    'other_entries' => array(
685
-				    'label'	=> __('Other Entries', 'gravityview'),
685
+				    'label'	=> __( 'Other Entries', 'gravityview' ),
686 686
 				    'type'	=> 'other_entries',
687
-				    'desc'	=> __('Display other entries created by the entry creator.', 'gravityview'),
687
+				    'desc'	=> __( 'Display other entries created by the entry creator.', 'gravityview' ),
688 688
 			    ),
689 689
 	        );
690 690
 
691
-			if( 'single' !== $zone) {
691
+			if ( 'single' !== $zone ) {
692 692
 
693
-				$entry_default_fields['entry_link'] = array(
694
-					'label' => __('Link to Entry', 'gravityview'),
695
-					'desc'	=> __('A dedicated link to the single entry with customizable text.', 'gravityview'),
693
+				$entry_default_fields[ 'entry_link' ] = array(
694
+					'label' => __( 'Link to Entry', 'gravityview' ),
695
+					'desc'	=> __( 'A dedicated link to the single entry with customizable text.', 'gravityview' ),
696 696
 					'type' => 'entry_link',
697 697
 				);
698 698
 			}
@@ -706,7 +706,7 @@  discard block
 block discarded – undo
706 706
 		 * @param  string|array $form form_ID or form object
707 707
 		 * @param  string $zone   Either 'single', 'directory', 'header', 'footer'
708 708
 		 */
709
-		return apply_filters( 'gravityview_entry_default_fields', $entry_default_fields, $form, $zone);
709
+		return apply_filters( 'gravityview_entry_default_fields', $entry_default_fields, $form, $zone );
710 710
 	}
711 711
 
712 712
 	/**
@@ -717,7 +717,7 @@  discard block
 block discarded – undo
717 717
 	 */
718 718
 	function get_available_fields( $form = '', $zone = NULL ) {
719 719
 
720
-		if( empty( $form ) ) {
720
+		if ( empty( $form ) ) {
721 721
 			do_action( 'gravityview_log_error', '[get_available_fields] $form is empty' );
722 722
 			return array();
723 723
 		}
@@ -726,7 +726,7 @@  discard block
 block discarded – undo
726 726
 		$fields = gravityview_get_form_fields( $form, true );
727 727
 
728 728
 		// get meta fields ( only if form was already created )
729
-		if( !is_array( $form ) ) {
729
+		if ( ! is_array( $form ) ) {
730 730
 			$meta_fields = gravityview_get_entry_meta( $form );
731 731
 		} else {
732 732
 			$meta_fields = array();
@@ -750,11 +750,11 @@  discard block
 block discarded – undo
750 750
 
751 751
 		$widgets = $this->get_registered_widgets();
752 752
 
753
-		if( !empty( $widgets ) ) {
753
+		if ( ! empty( $widgets ) ) {
754 754
 
755
-			foreach( $widgets as $id => $details ) {
755
+			foreach ( $widgets as $id => $details ) {
756 756
 
757
-				echo new GravityView_Admin_View_Widget( $details['label'], $id, $details );
757
+				echo new GravityView_Admin_View_Widget( $details[ 'label' ], $id, $details );
758 758
 
759 759
 			}
760 760
 		}
@@ -788,7 +788,7 @@  discard block
 block discarded – undo
788 788
 	function render_active_areas( $template_id, $type, $zone, $rows, $values ) {
789 789
 		global $post;
790 790
 
791
-		if( $type === 'widget' ) {
791
+		if ( $type === 'widget' ) {
792 792
 			$button_label = __( 'Add Widget', 'gravityview' );
793 793
 		} else {
794 794
 			$button_label = __( 'Add Field', 'gravityview' );
@@ -797,15 +797,15 @@  discard block
 block discarded – undo
797 797
 		$available_items = array();
798 798
 
799 799
 		// if saved values, get available fields to label everyone
800
-		if( !empty( $values ) && ( !empty( $post->ID ) || !empty( $_POST['template_id'] ) ) ) {
800
+		if ( ! empty( $values ) && ( ! empty( $post->ID ) || ! empty( $_POST[ 'template_id' ] ) ) ) {
801 801
 
802
-			if( !empty( $_POST['template_id'] ) ) {
803
-				$form = GravityView_Ajax::pre_get_form_fields( $_POST['template_id'] );
802
+			if ( ! empty( $_POST[ 'template_id' ] ) ) {
803
+				$form = GravityView_Ajax::pre_get_form_fields( $_POST[ 'template_id' ] );
804 804
 			} else {
805 805
 				$form = gravityview_get_form_id( $post->ID );
806 806
 			}
807 807
 
808
-			if( 'field' === $type ) {
808
+			if ( 'field' === $type ) {
809 809
 				$available_items = $this->get_available_fields( $form, $zone );
810 810
 			} else {
811 811
 				$available_items = $this->get_registered_widgets();
@@ -813,39 +813,39 @@  discard block
 block discarded – undo
813 813
 
814 814
 		}
815 815
 
816
-		foreach( $rows as $row ) :
817
-			foreach( $row as $col => $areas ) :
818
-				$column = ($col == '2-2') ? '1-2' : $col; ?>
816
+		foreach ( $rows as $row ) :
817
+			foreach ( $row as $col => $areas ) :
818
+				$column = ( $col == '2-2' ) ? '1-2' : $col; ?>
819 819
 
820 820
 				<div class="gv-grid-col-<?php echo esc_attr( $column ); ?>">
821 821
 
822
-					<?php foreach( $areas as $area ) : 	?>
822
+					<?php foreach ( $areas as $area ) : 	?>
823 823
 
824 824
 						<div class="gv-droppable-area">
825
-							<div class="active-drop active-drop-<?php echo esc_attr( $type ); ?>" data-areaid="<?php echo esc_attr( $zone .'_'. $area['areaid'] ); ?>">
825
+							<div class="active-drop active-drop-<?php echo esc_attr( $type ); ?>" data-areaid="<?php echo esc_attr( $zone . '_' . $area[ 'areaid' ] ); ?>">
826 826
 
827 827
 								<?php // render saved fields
828 828
 
829
-								if( !empty( $values[ $zone .'_'. $area['areaid'] ] ) ) {
829
+								if ( ! empty( $values[ $zone . '_' . $area[ 'areaid' ] ] ) ) {
830 830
 
831
-									foreach( $values[ $zone .'_'. $area['areaid'] ] as $uniqid => $field ) {
831
+									foreach ( $values[ $zone . '_' . $area[ 'areaid' ] ] as $uniqid => $field ) {
832 832
 
833 833
 										$input_type = NULL;
834
-										$original_item = isset( $available_items[ $field['id'] ] ) ? $available_items[ $field['id'] ] : false ;
834
+										$original_item = isset( $available_items[ $field[ 'id' ] ] ) ? $available_items[ $field[ 'id' ] ] : false;
835 835
 
836
-										if( !$original_item ) {
836
+										if ( ! $original_item ) {
837 837
 
838
-											do_action('gravityview_log_error', 'An item was not available when rendering the output; maybe it was added by a plugin that is now de-activated.', array('available_items' => $available_items, 'field' => $field ));
838
+											do_action( 'gravityview_log_error', 'An item was not available when rendering the output; maybe it was added by a plugin that is now de-activated.', array( 'available_items' => $available_items, 'field' => $field ) );
839 839
 
840 840
 											$original_item = $field;
841 841
 										} else {
842 842
 
843
-											$input_type = isset( $original_item['type'] ) ? $original_item['type'] : NULL;
843
+											$input_type = isset( $original_item[ 'type' ] ) ? $original_item[ 'type' ] : NULL;
844 844
 
845 845
 										}
846 846
 
847 847
 										// Field options dialog box
848
-										$field_options = GravityView_Render_Settings::render_field_options( $type, $template_id, $field['id'], $original_item['label'], $zone .'_'. $area['areaid'], $input_type, $uniqid, $field, $zone, $original_item );
848
+										$field_options = GravityView_Render_Settings::render_field_options( $type, $template_id, $field[ 'id' ], $original_item[ 'label' ], $zone . '_' . $area[ 'areaid' ], $input_type, $uniqid, $field, $zone, $original_item );
849 849
 
850 850
 										$item = array(
851 851
 											'input_type' => $input_type,
@@ -854,16 +854,16 @@  discard block
 block discarded – undo
854 854
 										);
855 855
 
856 856
 										// Merge the values with the current item to pass things like widget descriptions and original field names
857
-										if( $original_item ) {
857
+										if ( $original_item ) {
858 858
 											$item = wp_parse_args( $item, $original_item );
859 859
 										}
860 860
 
861
-										switch( $type ) {
861
+										switch ( $type ) {
862 862
 											case 'widget':
863
-												echo new GravityView_Admin_View_Widget( $item['label'], $field['id'], $item, $field );
863
+												echo new GravityView_Admin_View_Widget( $item[ 'label' ], $field[ 'id' ], $item, $field );
864 864
 												break;
865 865
 											default:
866
-												echo new GravityView_Admin_View_Field( $item['label'], $field['id'], $item, $field );
866
+												echo new GravityView_Admin_View_Field( $item[ 'label' ], $field[ 'id' ], $item, $field );
867 867
 										}
868 868
 
869 869
 
@@ -873,11 +873,11 @@  discard block
 block discarded – undo
873 873
 
874 874
 								} // End if zone is not empty ?>
875 875
 
876
-								<span class="drop-message"><?php echo sprintf(esc_attr__('"+ %s" or drag existing %ss here.', 'gravityview'), $button_label, $type ); ?></span>
876
+								<span class="drop-message"><?php echo sprintf( esc_attr__( '"+ %s" or drag existing %ss here.', 'gravityview' ), $button_label, $type ); ?></span>
877 877
 							</div>
878 878
 							<div class="gv-droppable-area-action">
879
-								<a href="#" class="gv-add-field button-secondary" title="" data-objecttype="<?php echo esc_attr( $type ); ?>" data-areaid="<?php echo esc_attr( $zone .'_'. $area['areaid'] ); ?>" data-context="<?php echo esc_attr( $zone ); ?>"><?php echo '+ '.esc_html( $button_label ); ?></a>
880
-								<p class="gv-droppable-area-title"><strong><?php echo esc_html( $area['title'] ); ?></strong><?php if( !empty( $area['subtitle'] ) ) { ?><span class="gv-droppable-area-subtitle"> &ndash; <?php echo esc_html( $area['subtitle'] ); ?></span><?php } ?></p>
879
+								<a href="#" class="gv-add-field button-secondary" title="" data-objecttype="<?php echo esc_attr( $type ); ?>" data-areaid="<?php echo esc_attr( $zone . '_' . $area[ 'areaid' ] ); ?>" data-context="<?php echo esc_attr( $zone ); ?>"><?php echo '+ ' . esc_html( $button_label ); ?></a>
880
+								<p class="gv-droppable-area-title"><strong><?php echo esc_html( $area[ 'title' ] ); ?></strong><?php if ( ! empty( $area[ 'subtitle' ] ) ) { ?><span class="gv-droppable-area-subtitle"> &ndash; <?php echo esc_html( $area[ 'subtitle' ] ); ?></span><?php } ?></p>
881 881
 							</div>
882 882
 						</div>
883 883
 
@@ -899,7 +899,7 @@  discard block
 block discarded – undo
899 899
 		$default_widget_areas = GravityView_Plugin::get_default_widget_areas();
900 900
 
901 901
 		$widgets = array();
902
-		if( !empty( $post_id ) ) {
902
+		if ( ! empty( $post_id ) ) {
903 903
 			$widgets = gravityview_get_directory_widgets( $post_id );
904 904
 		}
905 905
 
@@ -929,7 +929,7 @@  discard block
 block discarded – undo
929 929
 	 */
930 930
 	function render_directory_active_areas( $template_id = '', $context = 'single', $post_id = '', $echo = false ) {
931 931
 
932
-		if( empty( $template_id ) ) {
932
+		if ( empty( $template_id ) ) {
933 933
 			do_action( 'gravityview_log_debug', '[render_directory_active_areas] $template_id is empty' );
934 934
 			return '';
935 935
 		}
@@ -943,12 +943,12 @@  discard block
 block discarded – undo
943 943
 		 */
944 944
 		$template_areas = apply_filters( 'gravityview_template_active_areas', array(), $template_id, $context );
945 945
 
946
-		if( empty( $template_areas ) ) {
946
+		if ( empty( $template_areas ) ) {
947 947
 
948 948
 			do_action( 'gravityview_log_debug', '[render_directory_active_areas] No areas defined. Maybe template %s is disabled.', $template_id );
949 949
 			$output = '<div>';
950
-			$output .= '<h2 class="description" style="font-size: 16px; margin:0">'. sprintf( esc_html__( 'This View is configured using the %s View type, which is disabled.', 'gravityview' ), '<em>'.$template_id.'</em>' ) .'</h2>';
951
-			$output .= '<p class="description" style="font-size: 14px; margin:0 0 1em 0;padding:0">'.esc_html__('The data is not lost; re-activate the associated plugin and the configuration will re-appear.', 'gravityview').'</p>';
950
+			$output .= '<h2 class="description" style="font-size: 16px; margin:0">' . sprintf( esc_html__( 'This View is configured using the %s View type, which is disabled.', 'gravityview' ), '<em>' . $template_id . '</em>' ) . '</h2>';
951
+			$output .= '<p class="description" style="font-size: 14px; margin:0 0 1em 0;padding:0">' . esc_html__( 'The data is not lost; re-activate the associated plugin and the configuration will re-appear.', 'gravityview' ) . '</p>';
952 952
 			$output .= '</div>';
953 953
 		} else {
954 954
 
@@ -963,7 +963,7 @@  discard block
 block discarded – undo
963 963
 
964 964
 		}
965 965
 
966
-		if( $echo ) {
966
+		if ( $echo ) {
967 967
 			echo $output;
968 968
 		}
969 969
 
@@ -983,25 +983,25 @@  discard block
 block discarded – undo
983 983
 		$is_widgets_page = ( $pagenow === 'widgets.php' );
984 984
 
985 985
 		// Add the GV font (with the Astronaut)
986
-		wp_enqueue_style( 'gravityview_global', plugins_url('assets/css/admin-global.css', GRAVITYVIEW_FILE), array(), GravityView_Plugin::version );
986
+		wp_enqueue_style( 'gravityview_global', plugins_url( 'assets/css/admin-global.css', GRAVITYVIEW_FILE ), array(), GravityView_Plugin::version );
987 987
 
988
-		wp_register_script( 'gravityview-jquery-cookie', plugins_url('assets/lib/jquery.cookie/jquery.cookie.min.js', GRAVITYVIEW_FILE), array( 'jquery' ), GravityView_Plugin::version, true );
988
+		wp_register_script( 'gravityview-jquery-cookie', plugins_url( 'assets/lib/jquery.cookie/jquery.cookie.min.js', GRAVITYVIEW_FILE ), array( 'jquery' ), GravityView_Plugin::version, true );
989 989
 
990 990
 		// Don't process any scripts below here if it's not a GravityView page.
991
-		if( !gravityview_is_admin_page($hook) && !$is_widgets_page ) { return; }
991
+		if ( ! gravityview_is_admin_page( $hook ) && ! $is_widgets_page ) { return; }
992 992
 
993 993
 		// Only enqueue the following on single pages
994
-		if( gravityview_is_admin_page($hook, 'single') || $is_widgets_page ) {
994
+		if ( gravityview_is_admin_page( $hook, 'single' ) || $is_widgets_page ) {
995 995
 
996 996
 			wp_enqueue_script( 'jquery-ui-datepicker' );
997
-			wp_enqueue_style( 'gravityview_views_datepicker', plugins_url('assets/css/admin-datepicker.css', GRAVITYVIEW_FILE), GravityView_Plugin::version );
997
+			wp_enqueue_style( 'gravityview_views_datepicker', plugins_url( 'assets/css/admin-datepicker.css', GRAVITYVIEW_FILE ), GravityView_Plugin::version );
998 998
 
999
-			$script_debug = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min';
999
+			$script_debug = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
1000 1000
 
1001 1001
 			//enqueue scripts
1002 1002
 			wp_enqueue_script( 'gravityview_views_scripts', plugins_url( 'assets/js/admin-views' . $script_debug . '.js', GRAVITYVIEW_FILE ), array( 'jquery-ui-tabs', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable', 'jquery-ui-tooltip', 'jquery-ui-dialog', 'gravityview-jquery-cookie', 'jquery-ui-datepicker', 'underscore' ), GravityView_Plugin::version );
1003 1003
 
1004
-			wp_localize_script('gravityview_views_scripts', 'gvGlobals', array(
1004
+			wp_localize_script( 'gravityview_views_scripts', 'gvGlobals', array(
1005 1005
 				'cookiepath' => COOKIEPATH,
1006 1006
 				'nonce' => wp_create_nonce( 'gravityview_ajaxviews' ),
1007 1007
 				'label_viewname' => __( 'Enter View name here', 'gravityview' ),
@@ -1014,9 +1014,9 @@  discard block
 block discarded – undo
1014 1014
 				'loading_error' => esc_html__( 'There was an error loading dynamic content.', 'gravityview' ),
1015 1015
 				'field_loaderror' => __( 'Error while adding the field. Please try again or contact GravityView support.', 'gravityview' ),
1016 1016
 				'remove_all_fields' => __( 'Would you like to remove all fields in this zone? (You are seeing this message because you were holding down the ALT key)', 'gravityview' ),
1017
-			));
1017
+			) );
1018 1018
 
1019
-			wp_enqueue_style( 'gravityview_views_styles', plugins_url( 'assets/css/admin-views.css', GRAVITYVIEW_FILE ), array('dashicons', 'wp-jquery-ui-dialog' ), GravityView_Plugin::version );
1019
+			wp_enqueue_style( 'gravityview_views_styles', plugins_url( 'assets/css/admin-views.css', GRAVITYVIEW_FILE ), array( 'dashicons', 'wp-jquery-ui-dialog' ), GravityView_Plugin::version );
1020 1020
 
1021 1021
 			self::enqueue_gravity_forms_scripts();
1022 1022
 
@@ -1035,10 +1035,10 @@  discard block
 block discarded – undo
1035 1035
 		);
1036 1036
 
1037 1037
 		if ( wp_is_mobile() ) {
1038
-		    $scripts[] = 'jquery-touch-punch';
1038
+		    $scripts[ ] = 'jquery-touch-punch';
1039 1039
 		}
1040 1040
 
1041
-		foreach ($scripts as $script) {
1041
+		foreach ( $scripts as $script ) {
1042 1042
 			wp_enqueue_script( $script );
1043 1043
 		}
1044 1044
 	}
Please login to merge, or discard this patch.
includes/extensions/edit-entry/class-edit-entry-render.php 1 patch
Indentation   +1618 added lines, -1618 removed lines patch added patch discarded remove patch
@@ -10,21 +10,21 @@  discard block
 block discarded – undo
10 10
  */
11 11
 
12 12
 if ( ! defined( 'WPINC' ) ) {
13
-    die;
13
+	die;
14 14
 }
15 15
 
16 16
 
17 17
 class GravityView_Edit_Entry_Render {
18 18
 
19
-    /**
20
-     * @var GravityView_Edit_Entry
21
-     */
22
-    protected $loader;
19
+	/**
20
+	 * @var GravityView_Edit_Entry
21
+	 */
22
+	protected $loader;
23 23
 
24 24
 	/**
25 25
 	 * @var string String used to generate unique nonce for the entry/form/view combination. Allows access to edit page.
26 26
 	 */
27
-    static $nonce_key;
27
+	static $nonce_key;
28 28
 
29 29
 	/**
30 30
 	 * @since 1.9
@@ -44,12 +44,12 @@  discard block
 block discarded – undo
44 44
 	 */
45 45
 	private static $supports_product_fields = false;
46 46
 
47
-    /**
48
-     * Gravity Forms entry array
49
-     *
50
-     * @var array
51
-     */
52
-    public $entry;
47
+	/**
48
+	 * Gravity Forms entry array
49
+	 *
50
+	 * @var array
51
+	 */
52
+	public $entry;
53 53
 
54 54
 	/**
55 55
 	 * Gravity Forms entry array (it won't get changed during this class lifecycle)
@@ -58,135 +58,135 @@  discard block
 block discarded – undo
58 58
 	 */
59 59
 	private static $original_entry = array();
60 60
 
61
-    /**
62
-     * Gravity Forms form array (GravityView modifies the content through this class lifecycle)
63
-     *
64
-     * @var array
65
-     */
61
+	/**
62
+	 * Gravity Forms form array (GravityView modifies the content through this class lifecycle)
63
+	 *
64
+	 * @var array
65
+	 */
66 66
 	public $form;
67 67
 
68
-    /**
69
-     * Gravity Forms form array (it won't get changed during this class lifecycle)
70
-     * @since 1.16.2.1
71
-     * @var array
72
-     */
73
-    private static $original_form;
74
-
75
-    /**
76
-     * Gravity Forms form array after the form validation process
77
-     * @since 1.13
78
-     * @var array
79
-     */
68
+	/**
69
+	 * Gravity Forms form array (it won't get changed during this class lifecycle)
70
+	 * @since 1.16.2.1
71
+	 * @var array
72
+	 */
73
+	private static $original_form;
74
+
75
+	/**
76
+	 * Gravity Forms form array after the form validation process
77
+	 * @since 1.13
78
+	 * @var array
79
+	 */
80 80
 	public $form_after_validation = null;
81 81
 
82
-    /**
83
-     * Hold an array of GF field objects that have calculation rules
84
-     * @var array
85
-     */
82
+	/**
83
+	 * Hold an array of GF field objects that have calculation rules
84
+	 * @var array
85
+	 */
86 86
 	public $fields_with_calculation = array();
87 87
 
88
-    /**
89
-     * Hold an array of GF field objects with type 'total'
90
-     * @var array
91
-     */
88
+	/**
89
+	 * Hold an array of GF field objects with type 'total'
90
+	 * @var array
91
+	 */
92 92
 	public $total_fields = array();
93 93
 
94
-    /**
95
-     * Gravity Forms form id
96
-     *
97
-     * @var int
98
-     */
94
+	/**
95
+	 * Gravity Forms form id
96
+	 *
97
+	 * @var int
98
+	 */
99 99
 	public $form_id;
100 100
 
101
-    /**
102
-     * ID of the current view
103
-     *
104
-     * @var int
105
-     */
101
+	/**
102
+	 * ID of the current view
103
+	 *
104
+	 * @var int
105
+	 */
106 106
 	public $view_id;
107 107
 
108
-    /**
109
-     * Updated entry is valid (GF Validation object)
110
-     *
111
-     * @var array
112
-     */
108
+	/**
109
+	 * Updated entry is valid (GF Validation object)
110
+	 *
111
+	 * @var array
112
+	 */
113 113
 	public $is_valid = NULL;
114 114
 
115
-    function __construct( GravityView_Edit_Entry $loader ) {
116
-        $this->loader = $loader;
117
-    }
115
+	function __construct( GravityView_Edit_Entry $loader ) {
116
+		$this->loader = $loader;
117
+	}
118 118
 
119
-    function load() {
119
+	function load() {
120 120
 
121
-        /** @define "GRAVITYVIEW_DIR" "../../../" */
122
-        include_once( GRAVITYVIEW_DIR .'includes/class-admin-approve-entries.php' );
121
+		/** @define "GRAVITYVIEW_DIR" "../../../" */
122
+		include_once( GRAVITYVIEW_DIR .'includes/class-admin-approve-entries.php' );
123 123
 
124
-        // Don't display an embedded form when editing an entry
125
-        add_action( 'wp_head', array( $this, 'prevent_render_form' ) );
126
-        add_action( 'wp_footer', array( $this, 'prevent_render_form' ) );
124
+		// Don't display an embedded form when editing an entry
125
+		add_action( 'wp_head', array( $this, 'prevent_render_form' ) );
126
+		add_action( 'wp_footer', array( $this, 'prevent_render_form' ) );
127 127
 
128
-        // Stop Gravity Forms processing what is ours!
129
-        add_filter( 'wp', array( $this, 'prevent_maybe_process_form'), 8 );
128
+		// Stop Gravity Forms processing what is ours!
129
+		add_filter( 'wp', array( $this, 'prevent_maybe_process_form'), 8 );
130 130
 
131
-        add_filter( 'gravityview_is_edit_entry', array( $this, 'is_edit_entry') );
131
+		add_filter( 'gravityview_is_edit_entry', array( $this, 'is_edit_entry') );
132 132
 
133
-        add_action( 'gravityview_edit_entry', array( $this, 'init' ) );
133
+		add_action( 'gravityview_edit_entry', array( $this, 'init' ) );
134 134
 
135
-        // Disable conditional logic if needed (since 1.9)
136
-        add_filter( 'gform_has_conditional_logic', array( $this, 'manage_conditional_logic' ), 10, 2 );
135
+		// Disable conditional logic if needed (since 1.9)
136
+		add_filter( 'gform_has_conditional_logic', array( $this, 'manage_conditional_logic' ), 10, 2 );
137 137
 
138
-        // Make sure GF doesn't validate max files (since 1.9)
139
-        add_filter( 'gform_plupload_settings', array( $this, 'modify_fileupload_settings' ), 10, 3 );
138
+		// Make sure GF doesn't validate max files (since 1.9)
139
+		add_filter( 'gform_plupload_settings', array( $this, 'modify_fileupload_settings' ), 10, 3 );
140 140
 
141
-        // Add fields expected by GFFormDisplay::validate()
142
-        add_filter( 'gform_pre_validation', array( $this, 'gform_pre_validation') );
141
+		// Add fields expected by GFFormDisplay::validate()
142
+		add_filter( 'gform_pre_validation', array( $this, 'gform_pre_validation') );
143 143
 
144
-    }
144
+	}
145 145
 
146
-    /**
147
-     * Don't show any forms embedded on a page when GravityView is in Edit Entry mode
148
-     *
149
-     * Adds a `__return_empty_string` filter on the Gravity Forms shortcode on the `wp_head` action
150
-     * And then removes it on the `wp_footer` action
151
-     *
152
-     * @since 1.16.1
153
-     *
154
-     * @return void
155
-     */
156
-    public function prevent_render_form() {
157
-        if( $this->is_edit_entry() ) {
158
-            if( 'wp_head' === current_filter() ) {
159
-                add_filter( 'gform_shortcode_form', '__return_empty_string' );
160
-            } else {
161
-                remove_filter( 'gform_shortcode_form', '__return_empty_string' );
162
-            }
163
-        }
164
-    }
146
+	/**
147
+	 * Don't show any forms embedded on a page when GravityView is in Edit Entry mode
148
+	 *
149
+	 * Adds a `__return_empty_string` filter on the Gravity Forms shortcode on the `wp_head` action
150
+	 * And then removes it on the `wp_footer` action
151
+	 *
152
+	 * @since 1.16.1
153
+	 *
154
+	 * @return void
155
+	 */
156
+	public function prevent_render_form() {
157
+		if( $this->is_edit_entry() ) {
158
+			if( 'wp_head' === current_filter() ) {
159
+				add_filter( 'gform_shortcode_form', '__return_empty_string' );
160
+			} else {
161
+				remove_filter( 'gform_shortcode_form', '__return_empty_string' );
162
+			}
163
+		}
164
+	}
165 165
 
166
-    /**
167
-     * Because we're mimicking being a front-end Gravity Forms form while using a Gravity Forms
168
-     * backend form, we need to prevent them from saving twice.
169
-     * @return void
170
-     */
171
-    public function prevent_maybe_process_form() {
166
+	/**
167
+	 * Because we're mimicking being a front-end Gravity Forms form while using a Gravity Forms
168
+	 * backend form, we need to prevent them from saving twice.
169
+	 * @return void
170
+	 */
171
+	public function prevent_maybe_process_form() {
172 172
 
173
-        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[prevent_maybe_process_form] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) );
173
+		do_action('gravityview_log_debug', 'GravityView_Edit_Entry[prevent_maybe_process_form] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) );
174 174
 
175
-        if( $this->is_edit_entry_submission() && $this->verify_nonce() ) {
176
-            remove_action( 'wp',  array( 'RGForms', 'maybe_process_form'), 9 );
177
-        }
178
-    }
175
+		if( $this->is_edit_entry_submission() && $this->verify_nonce() ) {
176
+			remove_action( 'wp',  array( 'RGForms', 'maybe_process_form'), 9 );
177
+		}
178
+	}
179 179
 
180
-    /**
181
-     * Is the current page an Edit Entry page?
182
-     * @return boolean
183
-     */
184
-    public function is_edit_entry() {
180
+	/**
181
+	 * Is the current page an Edit Entry page?
182
+	 * @return boolean
183
+	 */
184
+	public function is_edit_entry() {
185 185
 
186
-        $is_edit_entry = GravityView_frontend::is_single_entry() && ! empty( $_GET['edit'] );
186
+		$is_edit_entry = GravityView_frontend::is_single_entry() && ! empty( $_GET['edit'] );
187 187
 
188
-        return ( $is_edit_entry || $this->is_edit_entry_submission() );
189
-    }
188
+		return ( $is_edit_entry || $this->is_edit_entry_submission() );
189
+	}
190 190
 
191 191
 	/**
192 192
 	 * Is the current page an Edit Entry page?
@@ -197,578 +197,578 @@  discard block
 block discarded – undo
197 197
 		return !empty( $_POST[ self::$nonce_field ] );
198 198
 	}
199 199
 
200
-    /**
201
-     * When Edit entry view is requested setup the vars
202
-     */
203
-    private function setup_vars() {
204
-        $gravityview_view = GravityView_View::getInstance();
200
+	/**
201
+	 * When Edit entry view is requested setup the vars
202
+	 */
203
+	private function setup_vars() {
204
+		$gravityview_view = GravityView_View::getInstance();
205
+
206
+
207
+		$entries = $gravityview_view->getEntries();
208
+		self::$original_entry = $entries[0];
209
+		$this->entry = $entries[0];
210
+
211
+		self::$original_form = $gravityview_view->getForm();
212
+		$this->form = $gravityview_view->getForm();
213
+		$this->form_id = $gravityview_view->getFormId();
214
+		$this->view_id = $gravityview_view->getViewId();
215
+
216
+		self::$nonce_key = GravityView_Edit_Entry::get_nonce_key( $this->view_id, $this->form_id, $this->entry['id'] );
217
+	}
218
+
205 219
 
220
+	/**
221
+	 * Load required files and trigger edit flow
222
+	 *
223
+	 * Run when the is_edit_entry returns true.
224
+	 *
225
+	 * @param GravityView_View_Data $gv_data GravityView Data object
226
+	 * @return void
227
+	 */
228
+	public function init( $gv_data ) {
206 229
 
207
-        $entries = $gravityview_view->getEntries();
208
-	    self::$original_entry = $entries[0];
209
-	    $this->entry = $entries[0];
230
+		require_once( GFCommon::get_base_path() . '/form_display.php' );
231
+		require_once( GFCommon::get_base_path() . '/entry_detail.php' );
210 232
 
211
-        self::$original_form = $gravityview_view->getForm();
212
-        $this->form = $gravityview_view->getForm();
213
-        $this->form_id = $gravityview_view->getFormId();
214
-        $this->view_id = $gravityview_view->getViewId();
233
+		$this->setup_vars();
215 234
 
216
-        self::$nonce_key = GravityView_Edit_Entry::get_nonce_key( $this->view_id, $this->form_id, $this->entry['id'] );
217
-    }
235
+		// Multiple Views embedded, don't proceed if nonce fails
236
+		if( $gv_data->has_multiple_views() && ! wp_verify_nonce( $_GET['edit'], self::$nonce_key ) ) {
237
+			return;
238
+		}
218 239
 
240
+		// Sorry, you're not allowed here.
241
+		if( false === $this->user_can_edit_entry( true ) ) {
242
+			return;
243
+		}
219 244
 
220
-    /**
221
-     * Load required files and trigger edit flow
222
-     *
223
-     * Run when the is_edit_entry returns true.
224
-     *
225
-     * @param GravityView_View_Data $gv_data GravityView Data object
226
-     * @return void
227
-     */
228
-    public function init( $gv_data ) {
245
+		$this->print_scripts();
229 246
 
230
-        require_once( GFCommon::get_base_path() . '/form_display.php' );
231
-        require_once( GFCommon::get_base_path() . '/entry_detail.php' );
247
+		$this->process_save();
232 248
 
233
-        $this->setup_vars();
249
+		$this->edit_entry_form();
234 250
 
235
-        // Multiple Views embedded, don't proceed if nonce fails
236
-        if( $gv_data->has_multiple_views() && ! wp_verify_nonce( $_GET['edit'], self::$nonce_key ) ) {
237
-            return;
238
-        }
251
+	}
239 252
 
240
-        // Sorry, you're not allowed here.
241
-        if( false === $this->user_can_edit_entry( true ) ) {
242
-            return;
243
-        }
244 253
 
245
-        $this->print_scripts();
254
+	/**
255
+	 * Force Gravity Forms to output scripts as if it were in the admin
256
+	 * @return void
257
+	 */
258
+	private function print_scripts() {
259
+		$gravityview_view = GravityView_View::getInstance();
246 260
 
247
-        $this->process_save();
261
+		wp_register_script( 'gform_gravityforms', GFCommon::get_base_url().'/js/gravityforms.js', array( 'jquery', 'gform_json', 'gform_placeholder', 'sack', 'plupload-all', 'gravityview-fe-view' ) );
248 262
 
249
-        $this->edit_entry_form();
263
+		GFFormDisplay::enqueue_form_scripts($gravityview_view->getForm(), false);
250 264
 
251
-    }
265
+		// Sack is required for images
266
+		wp_print_scripts( array( 'sack', 'gform_gravityforms' ) );
267
+	}
252 268
 
253 269
 
254
-    /**
255
-     * Force Gravity Forms to output scripts as if it were in the admin
256
-     * @return void
257
-     */
258
-    private function print_scripts() {
259
-        $gravityview_view = GravityView_View::getInstance();
270
+	/**
271
+	 * Process edit entry form save
272
+	 */
273
+	private function process_save() {
260 274
 
261
-        wp_register_script( 'gform_gravityforms', GFCommon::get_base_url().'/js/gravityforms.js', array( 'jquery', 'gform_json', 'gform_placeholder', 'sack', 'plupload-all', 'gravityview-fe-view' ) );
275
+		if( empty( $_POST ) || ! isset( $_POST['lid'] ) ) {
276
+			return;
277
+		}
262 278
 
263
-        GFFormDisplay::enqueue_form_scripts($gravityview_view->getForm(), false);
279
+		// Make sure the entry, view, and form IDs are all correct
280
+		$valid = $this->verify_nonce();
264 281
 
265
-        // Sack is required for images
266
-        wp_print_scripts( array( 'sack', 'gform_gravityforms' ) );
267
-    }
282
+		if( !$valid ) {
283
+			do_action('gravityview_log_error', __METHOD__ . ' Nonce validation failed.' );
284
+			return;
285
+		}
268 286
 
287
+		if( $this->entry['id'] !== $_POST['lid'] ) {
288
+			do_action('gravityview_log_error', __METHOD__ . ' Entry ID did not match posted entry ID.' );
289
+			return;
290
+		}
269 291
 
270
-    /**
271
-     * Process edit entry form save
272
-     */
273
-    private function process_save() {
292
+		do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) );
274 293
 
275
-        if( empty( $_POST ) || ! isset( $_POST['lid'] ) ) {
276
-            return;
277
-        }
294
+		$this->process_save_process_files( $this->form_id );
278 295
 
279
-        // Make sure the entry, view, and form IDs are all correct
280
-        $valid = $this->verify_nonce();
296
+		$this->validate();
281 297
 
282
-        if( !$valid ) {
283
-            do_action('gravityview_log_error', __METHOD__ . ' Nonce validation failed.' );
284
-            return;
285
-        }
298
+		if( $this->is_valid ) {
286 299
 
287
-        if( $this->entry['id'] !== $_POST['lid'] ) {
288
-            do_action('gravityview_log_error', __METHOD__ . ' Entry ID did not match posted entry ID.' );
289
-            return;
290
-        }
300
+			do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] Submission is valid.' );
291 301
 
292
-        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) );
302
+			/**
303
+			 * @hack This step is needed to unset the adminOnly from form fields, to add the calculation fields
304
+			 */
305
+			$form = $this->form_prepare_for_save();
293 306
 
294
-        $this->process_save_process_files( $this->form_id );
307
+			/**
308
+			 * @hack to avoid the capability validation of the method save_lead for GF 1.9+
309
+			 */
310
+			unset( $_GET['page'] );
295 311
 
296
-        $this->validate();
312
+			GFFormsModel::save_lead( $form, $this->entry );
297 313
 
298
-        if( $this->is_valid ) {
314
+			// If there's a post associated with the entry, process post fields
315
+			if( !empty( $this->entry['post_id'] ) ) {
316
+				$this->maybe_update_post_fields( $form );
317
+			}
299 318
 
300
-            do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] Submission is valid.' );
319
+			// Process calculation fields
320
+			$this->update_calculation_fields();
301 321
 
302
-            /**
303
-             * @hack This step is needed to unset the adminOnly from form fields, to add the calculation fields
304
-             */
305
-            $form = $this->form_prepare_for_save();
322
+			// Perform actions normally performed after updating a lead
323
+			$this->after_update();
306 324
 
307
-            /**
308
-             * @hack to avoid the capability validation of the method save_lead for GF 1.9+
309
-             */
310
-            unset( $_GET['page'] );
325
+			/**
326
+			 * @action `gravityview/edit_entry/after_update` Perform an action after the entry has been updated using Edit Entry
327
+			 * @param array $form Gravity Forms form array
328
+			 * @param string $entry_id Numeric ID of the entry that was updated
329
+			 */
330
+			do_action( 'gravityview/edit_entry/after_update', $this->form, $this->entry['id'] );
331
+		}
311 332
 
312
-            GFFormsModel::save_lead( $form, $this->entry );
333
+	} // process_save
313 334
 
314
-            // If there's a post associated with the entry, process post fields
315
-            if( !empty( $this->entry['post_id'] ) ) {
316
-                $this->maybe_update_post_fields( $form );
317
-            }
318 335
 
319
-            // Process calculation fields
320
-            $this->update_calculation_fields();
336
+	/**
337
+	 * Have GF handle file uploads
338
+	 *
339
+	 * Copy of code from GFFormDisplay::process_form()
340
+	 *
341
+	 * @param int $form_id
342
+	 */
343
+	private function process_save_process_files( $form_id ) {
321 344
 
322
-            // Perform actions normally performed after updating a lead
323
-            $this->after_update();
345
+		//Loading files that have been uploaded to temp folder
346
+		$files = GFCommon::json_decode( stripslashes( RGForms::post( 'gform_uploaded_files' ) ) );
347
+		if ( ! is_array( $files ) ) {
348
+			$files = array();
349
+		}
324 350
 
325
-            /**
326
-             * @action `gravityview/edit_entry/after_update` Perform an action after the entry has been updated using Edit Entry
327
-             * @param array $form Gravity Forms form array
328
-             * @param string $entry_id Numeric ID of the entry that was updated
329
-             */
330
-            do_action( 'gravityview/edit_entry/after_update', $this->form, $this->entry['id'] );
331
-        }
351
+		RGFormsModel::$uploaded_files[ $form_id ] = $files;
352
+	}
332 353
 
333
-    } // process_save
354
+	/**
355
+	 * Remove max_files validation (done on gravityforms.js) to avoid conflicts with GravityView
356
+	 * Late validation done on self::custom_validation
357
+	 *
358
+	 * @param $plupload_init array Plupload settings
359
+	 * @param $form_id
360
+	 * @param $instance
361
+	 * @return mixed
362
+	 */
363
+	public function modify_fileupload_settings( $plupload_init, $form_id, $instance ) {
364
+		if( ! $this->is_edit_entry() ) {
365
+			return $plupload_init;
366
+		}
334 367
 
368
+		$plupload_init['gf_vars']['max_files'] = 0;
335 369
 
336
-    /**
337
-     * Have GF handle file uploads
338
-     *
339
-     * Copy of code from GFFormDisplay::process_form()
340
-     *
341
-     * @param int $form_id
342
-     */
343
-    private function process_save_process_files( $form_id ) {
370
+		return $plupload_init;
371
+	}
344 372
 
345
-        //Loading files that have been uploaded to temp folder
346
-        $files = GFCommon::json_decode( stripslashes( RGForms::post( 'gform_uploaded_files' ) ) );
347
-        if ( ! is_array( $files ) ) {
348
-            $files = array();
349
-        }
350 373
 
351
-        RGFormsModel::$uploaded_files[ $form_id ] = $files;
352
-    }
353
-
354
-    /**
355
-     * Remove max_files validation (done on gravityforms.js) to avoid conflicts with GravityView
356
-     * Late validation done on self::custom_validation
357
-     *
358
-     * @param $plupload_init array Plupload settings
359
-     * @param $form_id
360
-     * @param $instance
361
-     * @return mixed
362
-     */
363
-    public function modify_fileupload_settings( $plupload_init, $form_id, $instance ) {
364
-        if( ! $this->is_edit_entry() ) {
365
-            return $plupload_init;
366
-        }
367
-
368
-        $plupload_init['gf_vars']['max_files'] = 0;
369
-
370
-        return $plupload_init;
371
-    }
372
-
373
-
374
-    /**
375
-     * Unset adminOnly and convert field input key to string
376
-     * @return array $form
377
-     */
378
-    private function form_prepare_for_save() {
379
-
380
-        $form = $this->form;
381
-
382
-        foreach( $form['fields'] as $k => &$field ) {
383
-
384
-            // Remove the fields with calculation formulas before save to avoid conflicts with GF logic
385
-            // @since 1.16.3
386
-            if( $field->has_calculation() ) {
387
-                unset( $form['fields'][ $k ] );
388
-            }
389
-
390
-            $field->adminOnly = false;
391
-
392
-            if( isset( $field->inputs ) && is_array( $field->inputs ) ) {
393
-                foreach( $field->inputs as $key => $input ) {
394
-                    $field->inputs[ $key ][ 'id' ] = (string)$input['id'];
395
-                }
396
-            }
397
-        }
398
-
399
-        return $form;
400
-    }
401
-
402
-    private function update_calculation_fields() {
403
-
404
-        $form = self::$original_form;
405
-        $update = false;
406
-
407
-        // get the most up to date entry values
408
-        $entry = GFAPI::get_entry( $this->entry['id'] );
409
-
410
-        if( !empty( $this->fields_with_calculation ) ) {
411
-            $update = true;
412
-            foreach ( $this->fields_with_calculation as $calc_field ) {
413
-                $inputs = $calc_field->get_entry_inputs();
414
-                if ( is_array( $inputs ) ) {
415
-                    foreach ( $inputs as $input ) {
416
-                        $input_name = 'input_' . str_replace( '.', '_', $input['id'] );
417
-                        $entry[ strval( $input['id'] ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry['id'], $entry );
418
-                    }
419
-                } else {
420
-                    $input_name = 'input_' . str_replace( '.', '_', $calc_field->id);
421
-                    $entry[ strval( $calc_field->id ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry['id'], $entry );
422
-                }
423
-            }
424
-
425
-        }
426
-
427
-        //saving total field as the last field of the form.
428
-        if ( ! empty( $this->total_fields ) ) {
429
-            $update = true;
430
-            foreach ( $this->total_fields as $total_field ) {
431
-                $input_name = 'input_' . str_replace( '.', '_', $total_field->id);
432
-                $entry[ strval( $total_field->id ) ] = RGFormsModel::prepare_value( $form, $total_field, '', $input_name, $entry['id'], $entry );
433
-            }
434
-        }
435
-
436
-        if( $update ) {
437
-
438
-            $return_entry = GFAPI::update_entry( $entry );
439
-
440
-            if( is_wp_error( $return_entry ) ) {
441
-                do_action( 'gravityview_log_error', 'Updating the entry calculation and total fields failed', $return_entry );
442
-            } else {
443
-                do_action( 'gravityview_log_debug', 'Updating the entry calculation and total fields succeeded' );
444
-            }
445
-        }
446
-    }
447
-
448
-    /**
449
-     * Handle updating the Post Image field
450
-     *
451
-     * Sets a new Featured Image if configured in Gravity Forms; otherwise uploads/updates media
452
-     *
453
-     * @since 1.17
454
-     *
455
-     * @uses GFFormsModel::media_handle_upload
456
-     * @uses set_post_thumbnail
457
-     * 
458
-     * @param array $form GF Form array
459
-     * @param GF_Field $field GF Field
460
-     * @param string $field_id Numeric ID of the field
461
-     * @param string $value
462
-     * @param array $entry GF Entry currently being edited
463
-     * @param int $post_id ID of the Post being edited
464
-     *
465
-     * @return mixed|string
466
-     */
467
-    private function update_post_image( $form, $field, $field_id, $value, $entry, $post_id ) {
468
-
469
-        $input_name = 'input_' . $field_id;
470
-
471
-        if ( !empty( $_FILES[ $input_name ]['name'] ) ) {
472
-
473
-            // We have a new image
474
-
475
-            $value = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'] );
476
-
477
-            $ary = ! empty( $value ) ? explode( '|:|', $value ) : array();
478
-            $img_url = rgar( $ary, 0 );
479
-
480
-            $img_title       = count( $ary ) > 1 ? $ary[1] : '';
481
-            $img_caption     = count( $ary ) > 2 ? $ary[2] : '';
482
-            $img_description = count( $ary ) > 3 ? $ary[3] : '';
483
-
484
-            $image_meta = array(
485
-                'post_excerpt' => $img_caption,
486
-                'post_content' => $img_description,
487
-            );
488
-
489
-            //adding title only if it is not empty. It will default to the file name if it is not in the array
490
-            if ( ! empty( $img_title ) ) {
491
-                $image_meta['post_title'] = $img_title;
492
-            }
493
-
494
-            /**
495
-             * todo: As soon as \GFFormsModel::media_handle_upload becomes a public method, move this call to \GFFormsModel::media_handle_upload and remove the hack from this class.
496
-             * Note: the method became public in GF 1.9.17.7, but we don't require that version yet.
497
-             */
498
-            require_once GRAVITYVIEW_DIR . 'includes/class-gravityview-gfformsmodel.php';
499
-            $media_id = GravityView_GFFormsModel::media_handle_upload( $img_url, $post_id, $image_meta );
500
-
501
-            // is this field set as featured image?
502
-            if ( $media_id && $field->postFeaturedImage ) {
503
-                set_post_thumbnail( $post_id, $media_id );
504
-            }
505
-
506
-        } elseif ( !empty( $_POST[ $input_name ] ) && is_array( $value ) ) {
507
-
508
-            // Same image although the image title, caption or description might have changed
509
-
510
-            $ary = array();
511
-            if( ! empty( $entry[ $field_id ] ) ) {
512
-                $ary = is_array( $entry[ $field_id ] ) ? $entry[ $field_id ] : explode( '|:|', $entry[ $field_id ] );
513
-            }
514
-            $img_url = rgar( $ary, 0 );
515
-
516
-            // is this really the same image or something went wrong ?
517
-            if( $img_url === $_POST[ $input_name ] ) {
518
-
519
-                $img_title       = rgar( $value, $field_id .'.1' );
520
-                $img_caption     = rgar( $value, $field_id .'.4' );
521
-                $img_description = rgar( $value, $field_id .'.7' );
522
-
523
-                $value = ! empty( $img_url ) ? $img_url . "|:|" . $img_title . "|:|" . $img_caption . "|:|" . $img_description : '';
524
-
525
-                if ( $field->postFeaturedImage ) {
526
-
527
-                    $image_meta = array(
528
-                        'ID' => get_post_thumbnail_id( $post_id ),
529
-                        'post_title' => $img_title,
530
-                        'post_excerpt' => $img_caption,
531
-                        'post_content' => $img_description,
532
-                    );
533
-
534
-                    // update image title, caption or description
535
-                    wp_update_post( $image_meta );
536
-                }
537
-            }
538
-
539
-        } else {
540
-
541
-            // if we get here, image was removed or not set.
542
-            $value = '';
543
-
544
-            if ( $field->postFeaturedImage ) {
545
-                delete_post_thumbnail( $post_id );
546
-            }
547
-        }
548
-
549
-        return $value;
550
-    }
551
-
552
-    /**
553
-     * Loop through the fields being edited and if they include Post fields, update the Entry's post object
554
-     *
555
-     * @param array $form Gravity Forms form
556
-     *
557
-     * @return void
558
-     */
559
-    private function maybe_update_post_fields( $form ) {
560
-
561
-        $post_id = $this->entry['post_id'];
562
-
563
-        // Security check
564
-        if( false === GVCommon::has_cap( 'edit_post', $post_id ) ) {
565
-            do_action( 'gravityview_log_error', 'The current user does not have the ability to edit Post #'.$post_id );
566
-            return;
567
-        }
374
+	/**
375
+	 * Unset adminOnly and convert field input key to string
376
+	 * @return array $form
377
+	 */
378
+	private function form_prepare_for_save() {
568 379
 
569
-        $update_entry = false;
380
+		$form = $this->form;
570 381
 
571
-        $updated_post = $original_post = get_post( $post_id );
382
+		foreach( $form['fields'] as $k => &$field ) {
572 383
 
573
-        foreach ( $this->entry as $field_id => $value ) {
574
-
575
-            $field = RGFormsModel::get_field( $form, $field_id );
576
-
577
-            if( ! $field ) {
578
-                continue;
579
-            }
580
-
581
-            if( GFCommon::is_post_field( $field ) && 'post_category' !== $field->type ) {
582
-
583
-                // Get the value of the field, including $_POSTed value
584
-                $value = RGFormsModel::get_field_value( $field );
585
-
586
-                // Use temporary entry variable, to make values available to fill_post_template() and update_post_image()
587
-                $entry_tmp = $this->entry;
588
-                $entry_tmp["{$field_id}"] = $value;
589
-
590
-                switch( $field->type ) {
591
-
592
-                    case 'post_title':
593
-                        $post_title = $value;
594
-                        if( rgar( $form, 'postTitleTemplateEnabled' ) ) {
595
-                            $post_title = $this->fill_post_template( $form['postTitleTemplate'], $form, $entry_tmp );
596
-                        }
597
-                        $updated_post->post_title = $post_title;
598
-                        $updated_post->post_name  = $post_title;
599
-                        unset( $post_title );
600
-                        break;
601
-
602
-                    case 'post_content':
603
-                        $post_content = $value;
604
-                        if( rgar( $form, 'postContentTemplateEnabled' ) ) {
605
-                            $post_content = $this->fill_post_template( $form['postContentTemplate'], $form, $entry_tmp, true );
606
-                        }
607
-                        $updated_post->post_content = $post_content;
608
-                        unset( $post_content );
609
-                        break;
610
-                    case 'post_excerpt':
611
-                        $updated_post->post_excerpt = $value;
612
-                        break;
613
-                    case 'post_tags':
614
-                        wp_set_post_tags( $post_id, $value, false );
615
-                        break;
616
-                    case 'post_category':
617
-                        break;
618
-                    case 'post_custom_field':
619
-                        if( ! empty( $field->customFieldTemplateEnabled ) ) {
620
-                            $value = $this->fill_post_template( $field->customFieldTemplate, $form, $entry_tmp, true );
621
-                        }
622
-
623
-                        $input_type = RGFormsModel::get_input_type( $field );
624
-
625
-                        // Only certain custom field types are supported
626
-                        switch( $input_type ) {
627
-                            case 'fileupload':
628
-                            case 'list':
629
-                            case 'multiselect':
630
-                                if( ! is_string( $value ) ) {
631
-                                    $value = function_exists('wp_json_encode') ? wp_json_encode( $value ) : json_encode( $value );
632
-                                }
633
-                            // break; left intentionally out
634
-                            default:
635
-                                update_post_meta( $post_id, $field->postCustomFieldName, $value );
636
-                        }
637
-
638
-                        break;
639
-
640
-                    case 'post_image':
641
-                        $value = $this->update_post_image( $form, $field, $field_id, $value, $this->entry, $post_id );
642
-                        break;
643
-
644
-                }
645
-
646
-                // update entry after
647
-                $this->entry["{$field_id}"] = $value;
648
-
649
-                $update_entry = true;
650
-
651
-                unset( $entry_tmp );
652
-            }
653
-
654
-        }
655
-
656
-        if( $update_entry ) {
657
-
658
-            $return_entry = GFAPI::update_entry( $this->entry );
659
-
660
-            if( is_wp_error( $return_entry ) ) {
661
-               do_action( 'gravityview_log_error', 'Updating the entry post fields failed', array( '$this->entry' => $this->entry, '$return_entry' => $return_entry ) );
662
-            } else {
663
-                do_action( 'gravityview_log_debug', 'Updating the entry post fields for post #'.$post_id.' succeeded' );
664
-            }
665
-
666
-        }
667
-
668
-        $return_post = wp_update_post( $updated_post, true );
669
-
670
-        if( is_wp_error( $return_post ) ) {
671
-            $return_post->add_data( $updated_post, '$updated_post' );
672
-            do_action( 'gravityview_log_error', 'Updating the post content failed', compact( 'updated_post', 'return_post' ) );
673
-        } else {
674
-            do_action( 'gravityview_log_debug', 'Updating the post content for post #'.$post_id.' succeeded', $updated_post );
675
-        }
676
-    }
677
-
678
-    /**
679
-     * Convert a field content template into prepared output
680
-     *
681
-     * @uses GravityView_GFFormsModel::get_post_field_images()
682
-     *
683
-     * @since 1.17
684
-     *
685
-     * @param string $template The content template for the field
686
-     * @param array $form Gravity Forms form
687
-     * @param bool $do_shortcode Whether to process shortcode inside content. In GF, only run on Custom Field and Post Content fields
688
-     *
689
-     * @return mixed|string|void
690
-     */
691
-    private function fill_post_template( $template, $form, $entry, $do_shortcode = false ) {
692
-
693
-        require_once GRAVITYVIEW_DIR . 'includes/class-gravityview-gfformsmodel.php';
694
-
695
-        $post_images = GravityView_GFFormsModel::get_post_field_images( $form, $entry );
696
-
697
-        //replacing post image variables
698
-        $output = GFCommon::replace_variables_post_image( $template, $post_images, $entry );
699
-
700
-        //replacing all other variables
701
-        $output = GFCommon::replace_variables( $output, $form, $entry, false, false, false );
702
-
703
-        // replace conditional shortcodes
704
-        if( $do_shortcode ) {
705
-            $output = do_shortcode( $output );
706
-        }
707
-
708
-        return $output;
709
-    }
710
-
711
-
712
-    /**
713
-     * Perform actions normally performed after updating a lead
714
-     *
715
-     * @since 1.8
716
-     *
717
-     * @see GFEntryDetail::lead_detail_page()
718
-     *
719
-     * @return void
720
-     */
721
-    private function after_update() {
384
+			// Remove the fields with calculation formulas before save to avoid conflicts with GF logic
385
+			// @since 1.16.3
386
+			if( $field->has_calculation() ) {
387
+				unset( $form['fields'][ $k ] );
388
+			}
722 389
 
723
-        do_action( 'gform_after_update_entry', $this->form, $this->entry['id'], self::$original_entry );
724
-        do_action( "gform_after_update_entry_{$this->form['id']}", $this->form, $this->entry['id'] );
390
+			$field->adminOnly = false;
725 391
 
726
-        // Re-define the entry now that we've updated it.
727
-        $entry = RGFormsModel::get_lead( $this->entry['id'] );
392
+			if( isset( $field->inputs ) && is_array( $field->inputs ) ) {
393
+				foreach( $field->inputs as $key => $input ) {
394
+					$field->inputs[ $key ][ 'id' ] = (string)$input['id'];
395
+				}
396
+			}
397
+		}
728 398
 
729
-        $entry = GFFormsModel::set_entry_meta( $entry, $this->form );
399
+		return $form;
400
+	}
730 401
 
731
-        // We need to clear the cache because Gravity Forms caches the field values, which
732
-        // we have just updated.
733
-        foreach ($this->form['fields'] as $key => $field) {
734
-            GFFormsModel::refresh_lead_field_value( $entry['id'], $field->id );
735
-        }
402
+	private function update_calculation_fields() {
403
+
404
+		$form = self::$original_form;
405
+		$update = false;
406
+
407
+		// get the most up to date entry values
408
+		$entry = GFAPI::get_entry( $this->entry['id'] );
409
+
410
+		if( !empty( $this->fields_with_calculation ) ) {
411
+			$update = true;
412
+			foreach ( $this->fields_with_calculation as $calc_field ) {
413
+				$inputs = $calc_field->get_entry_inputs();
414
+				if ( is_array( $inputs ) ) {
415
+					foreach ( $inputs as $input ) {
416
+						$input_name = 'input_' . str_replace( '.', '_', $input['id'] );
417
+						$entry[ strval( $input['id'] ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry['id'], $entry );
418
+					}
419
+				} else {
420
+					$input_name = 'input_' . str_replace( '.', '_', $calc_field->id);
421
+					$entry[ strval( $calc_field->id ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry['id'], $entry );
422
+				}
423
+			}
736 424
 
737
-        $this->entry = $entry;
738
-    }
425
+		}
739 426
 
427
+		//saving total field as the last field of the form.
428
+		if ( ! empty( $this->total_fields ) ) {
429
+			$update = true;
430
+			foreach ( $this->total_fields as $total_field ) {
431
+				$input_name = 'input_' . str_replace( '.', '_', $total_field->id);
432
+				$entry[ strval( $total_field->id ) ] = RGFormsModel::prepare_value( $form, $total_field, '', $input_name, $entry['id'], $entry );
433
+			}
434
+		}
740 435
 
741
-    /**
742
-     * Display the Edit Entry form
743
-     *
744
-     * @return [type] [description]
745
-     */
746
-    public function edit_entry_form() {
436
+		if( $update ) {
747 437
 
748
-        ?>
438
+			$return_entry = GFAPI::update_entry( $entry );
439
+
440
+			if( is_wp_error( $return_entry ) ) {
441
+				do_action( 'gravityview_log_error', 'Updating the entry calculation and total fields failed', $return_entry );
442
+			} else {
443
+				do_action( 'gravityview_log_debug', 'Updating the entry calculation and total fields succeeded' );
444
+			}
445
+		}
446
+	}
447
+
448
+	/**
449
+	 * Handle updating the Post Image field
450
+	 *
451
+	 * Sets a new Featured Image if configured in Gravity Forms; otherwise uploads/updates media
452
+	 *
453
+	 * @since 1.17
454
+	 *
455
+	 * @uses GFFormsModel::media_handle_upload
456
+	 * @uses set_post_thumbnail
457
+	 * 
458
+	 * @param array $form GF Form array
459
+	 * @param GF_Field $field GF Field
460
+	 * @param string $field_id Numeric ID of the field
461
+	 * @param string $value
462
+	 * @param array $entry GF Entry currently being edited
463
+	 * @param int $post_id ID of the Post being edited
464
+	 *
465
+	 * @return mixed|string
466
+	 */
467
+	private function update_post_image( $form, $field, $field_id, $value, $entry, $post_id ) {
468
+
469
+		$input_name = 'input_' . $field_id;
470
+
471
+		if ( !empty( $_FILES[ $input_name ]['name'] ) ) {
472
+
473
+			// We have a new image
474
+
475
+			$value = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'] );
476
+
477
+			$ary = ! empty( $value ) ? explode( '|:|', $value ) : array();
478
+			$img_url = rgar( $ary, 0 );
479
+
480
+			$img_title       = count( $ary ) > 1 ? $ary[1] : '';
481
+			$img_caption     = count( $ary ) > 2 ? $ary[2] : '';
482
+			$img_description = count( $ary ) > 3 ? $ary[3] : '';
483
+
484
+			$image_meta = array(
485
+				'post_excerpt' => $img_caption,
486
+				'post_content' => $img_description,
487
+			);
488
+
489
+			//adding title only if it is not empty. It will default to the file name if it is not in the array
490
+			if ( ! empty( $img_title ) ) {
491
+				$image_meta['post_title'] = $img_title;
492
+			}
493
+
494
+			/**
495
+			 * todo: As soon as \GFFormsModel::media_handle_upload becomes a public method, move this call to \GFFormsModel::media_handle_upload and remove the hack from this class.
496
+			 * Note: the method became public in GF 1.9.17.7, but we don't require that version yet.
497
+			 */
498
+			require_once GRAVITYVIEW_DIR . 'includes/class-gravityview-gfformsmodel.php';
499
+			$media_id = GravityView_GFFormsModel::media_handle_upload( $img_url, $post_id, $image_meta );
500
+
501
+			// is this field set as featured image?
502
+			if ( $media_id && $field->postFeaturedImage ) {
503
+				set_post_thumbnail( $post_id, $media_id );
504
+			}
505
+
506
+		} elseif ( !empty( $_POST[ $input_name ] ) && is_array( $value ) ) {
507
+
508
+			// Same image although the image title, caption or description might have changed
509
+
510
+			$ary = array();
511
+			if( ! empty( $entry[ $field_id ] ) ) {
512
+				$ary = is_array( $entry[ $field_id ] ) ? $entry[ $field_id ] : explode( '|:|', $entry[ $field_id ] );
513
+			}
514
+			$img_url = rgar( $ary, 0 );
515
+
516
+			// is this really the same image or something went wrong ?
517
+			if( $img_url === $_POST[ $input_name ] ) {
518
+
519
+				$img_title       = rgar( $value, $field_id .'.1' );
520
+				$img_caption     = rgar( $value, $field_id .'.4' );
521
+				$img_description = rgar( $value, $field_id .'.7' );
522
+
523
+				$value = ! empty( $img_url ) ? $img_url . "|:|" . $img_title . "|:|" . $img_caption . "|:|" . $img_description : '';
524
+
525
+				if ( $field->postFeaturedImage ) {
526
+
527
+					$image_meta = array(
528
+						'ID' => get_post_thumbnail_id( $post_id ),
529
+						'post_title' => $img_title,
530
+						'post_excerpt' => $img_caption,
531
+						'post_content' => $img_description,
532
+					);
533
+
534
+					// update image title, caption or description
535
+					wp_update_post( $image_meta );
536
+				}
537
+			}
538
+
539
+		} else {
540
+
541
+			// if we get here, image was removed or not set.
542
+			$value = '';
543
+
544
+			if ( $field->postFeaturedImage ) {
545
+				delete_post_thumbnail( $post_id );
546
+			}
547
+		}
548
+
549
+		return $value;
550
+	}
551
+
552
+	/**
553
+	 * Loop through the fields being edited and if they include Post fields, update the Entry's post object
554
+	 *
555
+	 * @param array $form Gravity Forms form
556
+	 *
557
+	 * @return void
558
+	 */
559
+	private function maybe_update_post_fields( $form ) {
560
+
561
+		$post_id = $this->entry['post_id'];
562
+
563
+		// Security check
564
+		if( false === GVCommon::has_cap( 'edit_post', $post_id ) ) {
565
+			do_action( 'gravityview_log_error', 'The current user does not have the ability to edit Post #'.$post_id );
566
+			return;
567
+		}
568
+
569
+		$update_entry = false;
570
+
571
+		$updated_post = $original_post = get_post( $post_id );
572
+
573
+		foreach ( $this->entry as $field_id => $value ) {
574
+
575
+			$field = RGFormsModel::get_field( $form, $field_id );
576
+
577
+			if( ! $field ) {
578
+				continue;
579
+			}
580
+
581
+			if( GFCommon::is_post_field( $field ) && 'post_category' !== $field->type ) {
582
+
583
+				// Get the value of the field, including $_POSTed value
584
+				$value = RGFormsModel::get_field_value( $field );
585
+
586
+				// Use temporary entry variable, to make values available to fill_post_template() and update_post_image()
587
+				$entry_tmp = $this->entry;
588
+				$entry_tmp["{$field_id}"] = $value;
589
+
590
+				switch( $field->type ) {
591
+
592
+					case 'post_title':
593
+						$post_title = $value;
594
+						if( rgar( $form, 'postTitleTemplateEnabled' ) ) {
595
+							$post_title = $this->fill_post_template( $form['postTitleTemplate'], $form, $entry_tmp );
596
+						}
597
+						$updated_post->post_title = $post_title;
598
+						$updated_post->post_name  = $post_title;
599
+						unset( $post_title );
600
+						break;
601
+
602
+					case 'post_content':
603
+						$post_content = $value;
604
+						if( rgar( $form, 'postContentTemplateEnabled' ) ) {
605
+							$post_content = $this->fill_post_template( $form['postContentTemplate'], $form, $entry_tmp, true );
606
+						}
607
+						$updated_post->post_content = $post_content;
608
+						unset( $post_content );
609
+						break;
610
+					case 'post_excerpt':
611
+						$updated_post->post_excerpt = $value;
612
+						break;
613
+					case 'post_tags':
614
+						wp_set_post_tags( $post_id, $value, false );
615
+						break;
616
+					case 'post_category':
617
+						break;
618
+					case 'post_custom_field':
619
+						if( ! empty( $field->customFieldTemplateEnabled ) ) {
620
+							$value = $this->fill_post_template( $field->customFieldTemplate, $form, $entry_tmp, true );
621
+						}
622
+
623
+						$input_type = RGFormsModel::get_input_type( $field );
624
+
625
+						// Only certain custom field types are supported
626
+						switch( $input_type ) {
627
+							case 'fileupload':
628
+							case 'list':
629
+							case 'multiselect':
630
+								if( ! is_string( $value ) ) {
631
+									$value = function_exists('wp_json_encode') ? wp_json_encode( $value ) : json_encode( $value );
632
+								}
633
+							// break; left intentionally out
634
+							default:
635
+								update_post_meta( $post_id, $field->postCustomFieldName, $value );
636
+						}
637
+
638
+						break;
639
+
640
+					case 'post_image':
641
+						$value = $this->update_post_image( $form, $field, $field_id, $value, $this->entry, $post_id );
642
+						break;
643
+
644
+				}
645
+
646
+				// update entry after
647
+				$this->entry["{$field_id}"] = $value;
648
+
649
+				$update_entry = true;
650
+
651
+				unset( $entry_tmp );
652
+			}
653
+
654
+		}
655
+
656
+		if( $update_entry ) {
657
+
658
+			$return_entry = GFAPI::update_entry( $this->entry );
659
+
660
+			if( is_wp_error( $return_entry ) ) {
661
+			   do_action( 'gravityview_log_error', 'Updating the entry post fields failed', array( '$this->entry' => $this->entry, '$return_entry' => $return_entry ) );
662
+			} else {
663
+				do_action( 'gravityview_log_debug', 'Updating the entry post fields for post #'.$post_id.' succeeded' );
664
+			}
665
+
666
+		}
667
+
668
+		$return_post = wp_update_post( $updated_post, true );
669
+
670
+		if( is_wp_error( $return_post ) ) {
671
+			$return_post->add_data( $updated_post, '$updated_post' );
672
+			do_action( 'gravityview_log_error', 'Updating the post content failed', compact( 'updated_post', 'return_post' ) );
673
+		} else {
674
+			do_action( 'gravityview_log_debug', 'Updating the post content for post #'.$post_id.' succeeded', $updated_post );
675
+		}
676
+	}
677
+
678
+	/**
679
+	 * Convert a field content template into prepared output
680
+	 *
681
+	 * @uses GravityView_GFFormsModel::get_post_field_images()
682
+	 *
683
+	 * @since 1.17
684
+	 *
685
+	 * @param string $template The content template for the field
686
+	 * @param array $form Gravity Forms form
687
+	 * @param bool $do_shortcode Whether to process shortcode inside content. In GF, only run on Custom Field and Post Content fields
688
+	 *
689
+	 * @return mixed|string|void
690
+	 */
691
+	private function fill_post_template( $template, $form, $entry, $do_shortcode = false ) {
692
+
693
+		require_once GRAVITYVIEW_DIR . 'includes/class-gravityview-gfformsmodel.php';
694
+
695
+		$post_images = GravityView_GFFormsModel::get_post_field_images( $form, $entry );
696
+
697
+		//replacing post image variables
698
+		$output = GFCommon::replace_variables_post_image( $template, $post_images, $entry );
699
+
700
+		//replacing all other variables
701
+		$output = GFCommon::replace_variables( $output, $form, $entry, false, false, false );
702
+
703
+		// replace conditional shortcodes
704
+		if( $do_shortcode ) {
705
+			$output = do_shortcode( $output );
706
+		}
707
+
708
+		return $output;
709
+	}
710
+
711
+
712
+	/**
713
+	 * Perform actions normally performed after updating a lead
714
+	 *
715
+	 * @since 1.8
716
+	 *
717
+	 * @see GFEntryDetail::lead_detail_page()
718
+	 *
719
+	 * @return void
720
+	 */
721
+	private function after_update() {
722
+
723
+		do_action( 'gform_after_update_entry', $this->form, $this->entry['id'], self::$original_entry );
724
+		do_action( "gform_after_update_entry_{$this->form['id']}", $this->form, $this->entry['id'] );
725
+
726
+		// Re-define the entry now that we've updated it.
727
+		$entry = RGFormsModel::get_lead( $this->entry['id'] );
728
+
729
+		$entry = GFFormsModel::set_entry_meta( $entry, $this->form );
730
+
731
+		// We need to clear the cache because Gravity Forms caches the field values, which
732
+		// we have just updated.
733
+		foreach ($this->form['fields'] as $key => $field) {
734
+			GFFormsModel::refresh_lead_field_value( $entry['id'], $field->id );
735
+		}
736
+
737
+		$this->entry = $entry;
738
+	}
739
+
740
+
741
+	/**
742
+	 * Display the Edit Entry form
743
+	 *
744
+	 * @return [type] [description]
745
+	 */
746
+	public function edit_entry_form() {
747
+
748
+		?>
749 749
 
750 750
         <div class="gv-edit-entry-wrapper"><?php
751 751
 
752
-            $javascript = gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/inline-javascript.php', $this );
752
+			$javascript = gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/inline-javascript.php', $this );
753 753
 
754
-            /**
755
-             * Fixes weird wpautop() issue
756
-             * @see https://github.com/katzwebservices/GravityView/issues/451
757
-             */
758
-            echo gravityview_strip_whitespace( $javascript );
754
+			/**
755
+			 * Fixes weird wpautop() issue
756
+			 * @see https://github.com/katzwebservices/GravityView/issues/451
757
+			 */
758
+			echo gravityview_strip_whitespace( $javascript );
759 759
 
760
-            ?><h2 class="gv-edit-entry-title">
760
+			?><h2 class="gv-edit-entry-title">
761 761
                 <span><?php
762 762
 
763
-                    /**
764
-                     * @filter `gravityview_edit_entry_title` Modify the edit entry title
765
-                     * @param string $edit_entry_title Modify the "Edit Entry" title
766
-                     * @param GravityView_Edit_Entry_Render $this This object
767
-                     */
768
-                    $edit_entry_title = apply_filters('gravityview_edit_entry_title', __('Edit Entry', 'gravityview'), $this );
763
+					/**
764
+					 * @filter `gravityview_edit_entry_title` Modify the edit entry title
765
+					 * @param string $edit_entry_title Modify the "Edit Entry" title
766
+					 * @param GravityView_Edit_Entry_Render $this This object
767
+					 */
768
+					$edit_entry_title = apply_filters('gravityview_edit_entry_title', __('Edit Entry', 'gravityview'), $this );
769 769
 
770
-                    echo esc_attr( $edit_entry_title );
771
-            ?></span>
770
+					echo esc_attr( $edit_entry_title );
771
+			?></span>
772 772
             </h2>
773 773
 
774 774
             <?php $this->maybe_print_message(); ?>
@@ -779,1145 +779,1145 @@  discard block
 block discarded – undo
779 779
 
780 780
                 <?php
781 781
 
782
-                wp_nonce_field( self::$nonce_key, self::$nonce_key );
782
+				wp_nonce_field( self::$nonce_key, self::$nonce_key );
783 783
 
784
-                wp_nonce_field( self::$nonce_field, self::$nonce_field, false );
784
+				wp_nonce_field( self::$nonce_field, self::$nonce_field, false );
785 785
 
786
-                // Print the actual form HTML
787
-                $this->render_edit_form();
786
+				// Print the actual form HTML
787
+				$this->render_edit_form();
788 788
 
789
-                ?>
789
+				?>
790 790
             </form>
791 791
 
792 792
         </div>
793 793
 
794 794
     <?php
795
-    }
796
-
797
-    /**
798
-     * Display success or error message if the form has been submitted
799
-     *
800
-     * @uses GVCommon::generate_notice
801
-     *
802
-     * @since 1.16.2.2
803
-     *
804
-     * @return void
805
-     */
806
-    private function maybe_print_message() {
807
-
808
-        if( rgpost('action') === 'update' ) {
809
-
810
-            $back_link = esc_url( remove_query_arg( array( 'page', 'view', 'edit' ) ) );
811
-
812
-            if( ! $this->is_valid ){
813
-
814
-                // Keeping this compatible with Gravity Forms.
815
-                $validation_message = "<div class='validation_error'>" . __('There was a problem with your submission.', 'gravityview') . " " . __('Errors have been highlighted below.', 'gravityview') . "</div>";
816
-                $message = apply_filters("gform_validation_message_{$this->form['id']}", apply_filters("gform_validation_message", $validation_message, $this->form), $this->form);
817
-
818
-                echo GVCommon::generate_notice( $message , 'gv-error' );
819
-
820
-            } else {
821
-                $entry_updated_message = sprintf( esc_attr__('Entry Updated. %sReturn to Entry%s', 'gravityview'), '<a href="'. $back_link .'">', '</a>' );
822
-
823
-                /**
824
-                 * @filter `gravityview/edit_entry/success` Modify the edit entry success message (including the anchor link)
825
-                 * @since 1.5.4
826
-                 * @param string $entry_updated_message Existing message
827
-                 * @param int $view_id View ID
828
-                 * @param array $entry Gravity Forms entry array
829
-                 * @param string $back_link URL to return to the original entry. @since 1.6
830
-                 */
831
-                $message = apply_filters( 'gravityview/edit_entry/success', $entry_updated_message , $this->view_id, $this->entry, $back_link );
832
-
833
-                echo GVCommon::generate_notice( $message );
834
-            }
835
-
836
-        }
837
-    }
838
-
839
-    /**
840
-     * Display the Edit Entry form in the original Gravity Forms format
841
-     *
842
-     * @since 1.9
843
-     *
844
-     * @return void
845
-     */
846
-    private function render_edit_form() {
847
-
848
-        /**
849
-         * @action `gravityview/edit-entry/render/before` Before rendering the Edit Entry form
850
-         * @since 1.17
851
-         * @param GravityView_Edit_Entry_Render $this
852
-         */
853
-        do_action( 'gravityview/edit-entry/render/before', $this );
854
-
855
-        add_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields'), 5000, 3 );
856
-        add_filter( 'gform_submit_button', array( $this, 'render_form_buttons') );
857
-        add_filter( 'gform_disable_view_counter', '__return_true' );
858
-
859
-        add_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5, 5 );
860
-        add_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10, 5 );
861
-
862
-        add_filter( 'gform_field_value', array( $this, 'fix_survey_fields_value'), 10, 3 );
863
-
864
-        // We need to remove the fake $_GET['page'] arg to avoid rendering form as if in admin.
865
-        unset( $_GET['page'] );
866
-
867
-        // TODO: Verify multiple-page forms
868
-        // TODO: Product fields are not editable
869
-
870
-        $html = GFFormDisplay::get_form( $this->form['id'], false, false, true, $this->entry );
871
-
872
-        remove_filter( 'gform_field_value', array( $this, 'fix_survey_fields_value'), 10 );
873
-	    remove_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields' ), 5000 );
874
-        remove_filter( 'gform_submit_button', array( $this, 'render_form_buttons' ) );
875
-        remove_filter( 'gform_disable_view_counter', '__return_true' );
876
-        remove_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5 );
877
-        remove_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10 );
878
-
879
-        echo $html;
880
-
881
-        /**
882
-         * @action `gravityview/edit-entry/render/after` After rendering the Edit Entry form
883
-         * @since 1.17
884
-         * @param GravityView_Edit_Entry_Render $this
885
-         */
886
-        do_action( 'gravityview/edit-entry/render/after', $this );
887
-    }
888
-
889
-    /**
890
-     * Survey fields inject their output using `gform_field_input` filter, but in Edit Entry, the values were empty.
891
-     * We filter the values here because it was the easiest access point: tell the survey field the correct value, GF outputs it.
892
-     *
893
-     * @TODO: REMOVE; now added in class-gravityview-plugin-hooks-gravity-forms-survey.php
894
-     * 
895
-     * @since 1.16.4
896
-     *
897
-     * @param string $value Existing value
898
-     * @param GF_Field $field
899
-     * @param string $name Field custom parameter name, normally blank.
900
-     *
901
-     * @return mixed
902
-     */
903
-    public function fix_survey_fields_value( $value, $field, $name ) {
795
+	}
796
+
797
+	/**
798
+	 * Display success or error message if the form has been submitted
799
+	 *
800
+	 * @uses GVCommon::generate_notice
801
+	 *
802
+	 * @since 1.16.2.2
803
+	 *
804
+	 * @return void
805
+	 */
806
+	private function maybe_print_message() {
807
+
808
+		if( rgpost('action') === 'update' ) {
809
+
810
+			$back_link = esc_url( remove_query_arg( array( 'page', 'view', 'edit' ) ) );
811
+
812
+			if( ! $this->is_valid ){
813
+
814
+				// Keeping this compatible with Gravity Forms.
815
+				$validation_message = "<div class='validation_error'>" . __('There was a problem with your submission.', 'gravityview') . " " . __('Errors have been highlighted below.', 'gravityview') . "</div>";
816
+				$message = apply_filters("gform_validation_message_{$this->form['id']}", apply_filters("gform_validation_message", $validation_message, $this->form), $this->form);
817
+
818
+				echo GVCommon::generate_notice( $message , 'gv-error' );
819
+
820
+			} else {
821
+				$entry_updated_message = sprintf( esc_attr__('Entry Updated. %sReturn to Entry%s', 'gravityview'), '<a href="'. $back_link .'">', '</a>' );
822
+
823
+				/**
824
+				 * @filter `gravityview/edit_entry/success` Modify the edit entry success message (including the anchor link)
825
+				 * @since 1.5.4
826
+				 * @param string $entry_updated_message Existing message
827
+				 * @param int $view_id View ID
828
+				 * @param array $entry Gravity Forms entry array
829
+				 * @param string $back_link URL to return to the original entry. @since 1.6
830
+				 */
831
+				$message = apply_filters( 'gravityview/edit_entry/success', $entry_updated_message , $this->view_id, $this->entry, $back_link );
832
+
833
+				echo GVCommon::generate_notice( $message );
834
+			}
835
+
836
+		}
837
+	}
838
+
839
+	/**
840
+	 * Display the Edit Entry form in the original Gravity Forms format
841
+	 *
842
+	 * @since 1.9
843
+	 *
844
+	 * @return void
845
+	 */
846
+	private function render_edit_form() {
847
+
848
+		/**
849
+		 * @action `gravityview/edit-entry/render/before` Before rendering the Edit Entry form
850
+		 * @since 1.17
851
+		 * @param GravityView_Edit_Entry_Render $this
852
+		 */
853
+		do_action( 'gravityview/edit-entry/render/before', $this );
854
+
855
+		add_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields'), 5000, 3 );
856
+		add_filter( 'gform_submit_button', array( $this, 'render_form_buttons') );
857
+		add_filter( 'gform_disable_view_counter', '__return_true' );
858
+
859
+		add_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5, 5 );
860
+		add_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10, 5 );
861
+
862
+		add_filter( 'gform_field_value', array( $this, 'fix_survey_fields_value'), 10, 3 );
863
+
864
+		// We need to remove the fake $_GET['page'] arg to avoid rendering form as if in admin.
865
+		unset( $_GET['page'] );
866
+
867
+		// TODO: Verify multiple-page forms
868
+		// TODO: Product fields are not editable
869
+
870
+		$html = GFFormDisplay::get_form( $this->form['id'], false, false, true, $this->entry );
871
+
872
+		remove_filter( 'gform_field_value', array( $this, 'fix_survey_fields_value'), 10 );
873
+		remove_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields' ), 5000 );
874
+		remove_filter( 'gform_submit_button', array( $this, 'render_form_buttons' ) );
875
+		remove_filter( 'gform_disable_view_counter', '__return_true' );
876
+		remove_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5 );
877
+		remove_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10 );
878
+
879
+		echo $html;
880
+
881
+		/**
882
+		 * @action `gravityview/edit-entry/render/after` After rendering the Edit Entry form
883
+		 * @since 1.17
884
+		 * @param GravityView_Edit_Entry_Render $this
885
+		 */
886
+		do_action( 'gravityview/edit-entry/render/after', $this );
887
+	}
888
+
889
+	/**
890
+	 * Survey fields inject their output using `gform_field_input` filter, but in Edit Entry, the values were empty.
891
+	 * We filter the values here because it was the easiest access point: tell the survey field the correct value, GF outputs it.
892
+	 *
893
+	 * @TODO: REMOVE; now added in class-gravityview-plugin-hooks-gravity-forms-survey.php
894
+	 * 
895
+	 * @since 1.16.4
896
+	 *
897
+	 * @param string $value Existing value
898
+	 * @param GF_Field $field
899
+	 * @param string $name Field custom parameter name, normally blank.
900
+	 *
901
+	 * @return mixed
902
+	 */
903
+	public function fix_survey_fields_value( $value, $field, $name ) {
904 904
         
905
-        if( 'survey' === $field->type ) {
906
-
907
-	        // We need to run through each survey row until we find a match for expected values
908
-	        foreach ( $this->entry as $field_id => $field_value ) {
909
-
910
-		        if ( floor( $field_id ) !== floor( $field->id ) ) {
911
-			        continue;
912
-		        }
913
-
914
-		        if( rgar( $field, 'gsurveyLikertEnableMultipleRows' ) ) {
915
-			        list( $row_val, $col_val ) = explode( ':', $field_value, 2 );
916
-
917
-		            // If the $name matches the $row_val, we are processing the correct row
918
-			        if( $row_val === $name ) {
919
-				        $value = $field_value;
920
-				        break;
921
-			        }
922
-		        } else {
923
-			        // When not processing multiple rows, the value is the $entry[ $field_id ] value.
924
-			        $value = $field_value;
925
-				    break;
926
-		        }
905
+		if( 'survey' === $field->type ) {
906
+
907
+			// We need to run through each survey row until we find a match for expected values
908
+			foreach ( $this->entry as $field_id => $field_value ) {
909
+
910
+				if ( floor( $field_id ) !== floor( $field->id ) ) {
911
+					continue;
912
+				}
913
+
914
+				if( rgar( $field, 'gsurveyLikertEnableMultipleRows' ) ) {
915
+					list( $row_val, $col_val ) = explode( ':', $field_value, 2 );
916
+
917
+					// If the $name matches the $row_val, we are processing the correct row
918
+					if( $row_val === $name ) {
919
+						$value = $field_value;
920
+						break;
921
+					}
922
+				} else {
923
+					// When not processing multiple rows, the value is the $entry[ $field_id ] value.
924
+					$value = $field_value;
925
+					break;
926
+				}
927
+			}
928
+		}
929
+
930
+		return $value;
931
+	}
932
+
933
+	/**
934
+	 * Display the Update/Cancel/Delete buttons for the Edit Entry form
935
+	 * @since 1.8
936
+	 * @return string
937
+	 */
938
+	public function render_form_buttons() {
939
+		return gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/form-buttons.php', $this );
940
+	}
941
+
942
+
943
+	/**
944
+	 * Modify the form fields that are shown when using GFFormDisplay::get_form()
945
+	 *
946
+	 * By default, all fields will be shown. We only want the Edit Tab configured fields to be shown.
947
+	 *
948
+	 * @param array $form
949
+	 * @param boolean $ajax Whether in AJAX mode
950
+	 * @param array|string $field_values Passed parameters to the form
951
+	 *
952
+	 * @since 1.9
953
+	 *
954
+	 * @return array Modified form array
955
+	 */
956
+	public function filter_modify_form_fields( $form, $ajax = false, $field_values = '' ) {
957
+
958
+		// In case we have validated the form, use it to inject the validation results into the form render
959
+		if( isset( $this->form_after_validation ) ) {
960
+			$form = $this->form_after_validation;
961
+		} else {
962
+			$form['fields'] = $this->get_configured_edit_fields( $form, $this->view_id );
963
+		}
964
+
965
+		$form = $this->filter_conditional_logic( $form );
966
+
967
+		// for now we don't support Save and Continue feature.
968
+		if( ! self::$supports_save_and_continue ) {
969
+			unset( $form['save'] );
970
+		}
971
+
972
+		return $form;
973
+	}
974
+
975
+	/**
976
+	 * When displaying a field, check if it's a Post Field, and if so, make sure the post exists and current user has edit rights.
977
+	 *
978
+	 * @since 1.16.2.2
979
+	 *
980
+	 * @param string $field_content Always empty. Returning not-empty overrides the input.
981
+	 * @param GF_Field $field
982
+	 * @param string|array $value If array, it's a field with multiple inputs. If string, single input.
983
+	 * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter.
984
+	 * @param int $form_id Form ID
985
+	 *
986
+	 * @return string If error, the error message. If no error, blank string (modify_edit_field_input() runs next)
987
+	 */
988
+	public function verify_user_can_edit_post( $field_content = '', $field, $value, $lead_id = 0, $form_id ) {
989
+
990
+		if( GFCommon::is_post_field( $field ) ) {
991
+
992
+			$message = null;
993
+
994
+			// First, make sure they have the capability to edit the post.
995
+			if( false === current_user_can( 'edit_post', $this->entry['post_id'] ) ) {
996
+
997
+				/**
998
+				 * @filter `gravityview/edit_entry/unsupported_post_field_text` Modify the message when someone isn't able to edit a post
999
+				 * @param string $message The existing "You don't have permission..." text
1000
+				 */
1001
+				$message = apply_filters('gravityview/edit_entry/unsupported_post_field_text', __('You don&rsquo;t have permission to edit this post.', 'gravityview') );
1002
+
1003
+			} elseif( null === get_post( $this->entry['post_id'] ) ) {
1004
+				/**
1005
+				 * @filter `gravityview/edit_entry/no_post_text` Modify the message when someone is editing an entry attached to a post that no longer exists
1006
+				 * @param string $message The existing "This field is not editable; the post no longer exists." text
1007
+				 */
1008
+				$message = apply_filters('gravityview/edit_entry/no_post_text', __('This field is not editable; the post no longer exists.', 'gravityview' ) );
1009
+			}
1010
+
1011
+			if( $message ) {
1012
+				$field_content = sprintf('<div class="ginput_container ginput_container_' . $field->type . '">%s</div>', wpautop( $message ) );
927 1013
 			}
928
-        }
929
-
930
-        return $value;
931
-    }
932
-
933
-    /**
934
-     * Display the Update/Cancel/Delete buttons for the Edit Entry form
935
-     * @since 1.8
936
-     * @return string
937
-     */
938
-    public function render_form_buttons() {
939
-        return gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/form-buttons.php', $this );
940
-    }
941
-
942
-
943
-    /**
944
-     * Modify the form fields that are shown when using GFFormDisplay::get_form()
945
-     *
946
-     * By default, all fields will be shown. We only want the Edit Tab configured fields to be shown.
947
-     *
948
-     * @param array $form
949
-     * @param boolean $ajax Whether in AJAX mode
950
-     * @param array|string $field_values Passed parameters to the form
951
-     *
952
-     * @since 1.9
953
-     *
954
-     * @return array Modified form array
955
-     */
956
-    public function filter_modify_form_fields( $form, $ajax = false, $field_values = '' ) {
957
-
958
-        // In case we have validated the form, use it to inject the validation results into the form render
959
-        if( isset( $this->form_after_validation ) ) {
960
-            $form = $this->form_after_validation;
961
-        } else {
962
-            $form['fields'] = $this->get_configured_edit_fields( $form, $this->view_id );
963
-        }
964
-
965
-        $form = $this->filter_conditional_logic( $form );
966
-
967
-        // for now we don't support Save and Continue feature.
968
-        if( ! self::$supports_save_and_continue ) {
969
-	        unset( $form['save'] );
970
-        }
971
-
972
-        return $form;
973
-    }
974
-
975
-    /**
976
-     * When displaying a field, check if it's a Post Field, and if so, make sure the post exists and current user has edit rights.
977
-     *
978
-     * @since 1.16.2.2
979
-     *
980
-     * @param string $field_content Always empty. Returning not-empty overrides the input.
981
-     * @param GF_Field $field
982
-     * @param string|array $value If array, it's a field with multiple inputs. If string, single input.
983
-     * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter.
984
-     * @param int $form_id Form ID
985
-     *
986
-     * @return string If error, the error message. If no error, blank string (modify_edit_field_input() runs next)
987
-     */
988
-    public function verify_user_can_edit_post( $field_content = '', $field, $value, $lead_id = 0, $form_id ) {
989
-
990
-        if( GFCommon::is_post_field( $field ) ) {
991
-
992
-            $message = null;
993
-
994
-            // First, make sure they have the capability to edit the post.
995
-            if( false === current_user_can( 'edit_post', $this->entry['post_id'] ) ) {
996
-
997
-                /**
998
-                 * @filter `gravityview/edit_entry/unsupported_post_field_text` Modify the message when someone isn't able to edit a post
999
-                 * @param string $message The existing "You don't have permission..." text
1000
-                 */
1001
-                $message = apply_filters('gravityview/edit_entry/unsupported_post_field_text', __('You don&rsquo;t have permission to edit this post.', 'gravityview') );
1002
-
1003
-            } elseif( null === get_post( $this->entry['post_id'] ) ) {
1004
-                /**
1005
-                 * @filter `gravityview/edit_entry/no_post_text` Modify the message when someone is editing an entry attached to a post that no longer exists
1006
-                 * @param string $message The existing "This field is not editable; the post no longer exists." text
1007
-                 */
1008
-                $message = apply_filters('gravityview/edit_entry/no_post_text', __('This field is not editable; the post no longer exists.', 'gravityview' ) );
1009
-            }
1010
-
1011
-            if( $message ) {
1012
-                $field_content = sprintf('<div class="ginput_container ginput_container_' . $field->type . '">%s</div>', wpautop( $message ) );
1013
-            }
1014
-        }
1015
-
1016
-        return $field_content;
1017
-    }
1018
-
1019
-    /**
1020
-     *
1021
-     * Fill-in the saved values into the form inputs
1022
-     *
1023
-     * @param string $field_content Always empty. Returning not-empty overrides the input.
1024
-     * @param GF_Field $field
1025
-     * @param string|array $value If array, it's a field with multiple inputs. If string, single input.
1026
-     * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter.
1027
-     * @param int $form_id Form ID
1028
-     *
1029
-     * @return mixed
1030
-     */
1031
-    public function modify_edit_field_input( $field_content = '', $field, $value, $lead_id = 0, $form_id ) {
1032
-
1033
-        $gv_field = GravityView_Fields::get_associated_field( $field );
1034
-
1035
-        // If the form has been submitted, then we don't need to pre-fill the values,
1036
-        // Except for fileupload type and when a field input is overridden- run always!!
1037
-        if(
1038
-            ( $this->is_edit_entry_submission() && !in_array( $field->type, array( 'fileupload', 'post_image' ) ) )
1039
-            && false === ( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) )
1040
-            || ! empty( $field_content )
1041
-            || in_array( $field->type, array( 'honeypot' ) )
1042
-            || GFCommon::is_product_field( $field->type ) // Prevent product fields from appearing editable
1043
-        ) {
1044
-	        return $field_content;
1045
-        }
1046
-
1047
-        // Turn on Admin-style display for file upload fields only
1048
-        if( 'fileupload' === $field->type ) {
1049
-            $_GET['page'] = 'gf_entries';
1050
-        }
1051
-
1052
-        // SET SOME FIELD DEFAULTS TO PREVENT ISSUES
1053
-        $field->adminOnly = false; /** @see GFFormDisplay::get_counter_init_script() need to prevent adminOnly */
1054
-
1055
-        // add categories as choices for Post Category field
1056
-        if ( 'post_category' === $field->type ) {
1057
-            $field = GFCommon::add_categories_as_choices( $field, $value );
1058
-        }
1059
-
1060
-        $field_value = $this->get_field_value( $field );
1061
-
1062
-        /**
1063
-         * @filter `gravityview/edit_entry/field_value` Change the value of an Edit Entry field, if needed
1064
-         * @since 1.11
1065
-         * @param mixed $field_value field value used to populate the input
1066
-         * @param object $field Gravity Forms field object ( Class GF_Field )
1067
-         */
1068
-        $field_value = apply_filters( 'gravityview/edit_entry/field_value', $field_value, $field );
1069
-
1070
-        /**
1071
-         * @filter `gravityview/edit_entry/field_value_{field_type}` Change the value of an Edit Entry field for a specific field type
1072
-         * @since 1.17
1073
-         * @param mixed $field_value field value used to populate the input
1074
-         * @param GF_Field $field Gravity Forms field object
1075
-         */
1076
-        $field_value = apply_filters( 'gravityview/edit_entry/field_value_' . $field->type , $field_value, $field );
1077
-
1078
-	    // Prevent any PHP warnings, like undefined index
1079
-	    ob_start();
1080
-
1081
-        if( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) ) {
1082
-            /** @var GF_Field $gv_field */
1083
-            $return = $gv_field->get_field_input( $this->form, $field_value, $this->entry, $field );
1084
-        } else {
1085
-	        $return = $field->get_field_input( $this->form, $field_value, $this->entry );
1086
-        }
1087
-
1088
-
1089
-	    // If there was output, it's an error
1090
-	    $warnings = ob_get_clean();
1091
-
1092
-	    if( !empty( $warnings ) ) {
1093
-		    do_action( 'gravityview_log_error', __METHOD__ . $warnings, $field_value );
1094
-	    }
1095
-
1096
-        /**
1097
-         * Unset hack $_GET['page'] = 'gf_entries'
1098
-         * We need the fileupload html field to render with the proper id
1099
-         *  ( <li id="field_80_16" ... > )
1100
-         */
1101
-        unset( $_GET['page'] );
1102
-
1103
-        return $return;
1104
-    }
1105
-
1106
-    /**
1107
-     * Modify the value for the current field input
1108
-     *
1109
-     * @param GF_Field $field
1110
-     *
1111
-     * @return array|mixed|string|void
1112
-     */
1113
-    private function get_field_value( $field ) {
1114
-
1115
-        /**
1116
-         * @filter `gravityview/edit_entry/pre_populate/override` Allow the pre-populated value to override saved value in Edit Entry form. By default, pre-populate mechanism only kicks on empty fields.
1117
-         * @param boolean True: override saved values; False: don't override (default)
1118
-         * @param $field GF_Field object Gravity Forms field object
1119
-         * @since 1.13
1120
-         */
1121
-        $override_saved_value = apply_filters( 'gravityview/edit_entry/pre_populate/override', false, $field );
1122
-
1123
-        // We're dealing with multiple inputs (e.g. checkbox) but not time or date (as it doesn't store data in input IDs)
1124
-        if( isset( $field->inputs ) && is_array( $field->inputs ) && !in_array( $field->type, array( 'time', 'date' ) ) ) {
1125
-
1126
-            $field_value = array();
1127
-
1128
-            // only accept pre-populated values if the field doesn't have any choice selected.
1129
-            $allow_pre_populated = $field->allowsPrepopulate;
1130
-
1131
-            foreach ( (array)$field->inputs as $input ) {
1132
-
1133
-                $input_id = strval( $input['id'] );
1014
+		}
1015
+
1016
+		return $field_content;
1017
+	}
1018
+
1019
+	/**
1020
+	 *
1021
+	 * Fill-in the saved values into the form inputs
1022
+	 *
1023
+	 * @param string $field_content Always empty. Returning not-empty overrides the input.
1024
+	 * @param GF_Field $field
1025
+	 * @param string|array $value If array, it's a field with multiple inputs. If string, single input.
1026
+	 * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter.
1027
+	 * @param int $form_id Form ID
1028
+	 *
1029
+	 * @return mixed
1030
+	 */
1031
+	public function modify_edit_field_input( $field_content = '', $field, $value, $lead_id = 0, $form_id ) {
1032
+
1033
+		$gv_field = GravityView_Fields::get_associated_field( $field );
1034
+
1035
+		// If the form has been submitted, then we don't need to pre-fill the values,
1036
+		// Except for fileupload type and when a field input is overridden- run always!!
1037
+		if(
1038
+			( $this->is_edit_entry_submission() && !in_array( $field->type, array( 'fileupload', 'post_image' ) ) )
1039
+			&& false === ( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) )
1040
+			|| ! empty( $field_content )
1041
+			|| in_array( $field->type, array( 'honeypot' ) )
1042
+			|| GFCommon::is_product_field( $field->type ) // Prevent product fields from appearing editable
1043
+		) {
1044
+			return $field_content;
1045
+		}
1046
+
1047
+		// Turn on Admin-style display for file upload fields only
1048
+		if( 'fileupload' === $field->type ) {
1049
+			$_GET['page'] = 'gf_entries';
1050
+		}
1051
+
1052
+		// SET SOME FIELD DEFAULTS TO PREVENT ISSUES
1053
+		$field->adminOnly = false; /** @see GFFormDisplay::get_counter_init_script() need to prevent adminOnly */
1054
+
1055
+		// add categories as choices for Post Category field
1056
+		if ( 'post_category' === $field->type ) {
1057
+			$field = GFCommon::add_categories_as_choices( $field, $value );
1058
+		}
1059
+
1060
+		$field_value = $this->get_field_value( $field );
1061
+
1062
+		/**
1063
+		 * @filter `gravityview/edit_entry/field_value` Change the value of an Edit Entry field, if needed
1064
+		 * @since 1.11
1065
+		 * @param mixed $field_value field value used to populate the input
1066
+		 * @param object $field Gravity Forms field object ( Class GF_Field )
1067
+		 */
1068
+		$field_value = apply_filters( 'gravityview/edit_entry/field_value', $field_value, $field );
1069
+
1070
+		/**
1071
+		 * @filter `gravityview/edit_entry/field_value_{field_type}` Change the value of an Edit Entry field for a specific field type
1072
+		 * @since 1.17
1073
+		 * @param mixed $field_value field value used to populate the input
1074
+		 * @param GF_Field $field Gravity Forms field object
1075
+		 */
1076
+		$field_value = apply_filters( 'gravityview/edit_entry/field_value_' . $field->type , $field_value, $field );
1077
+
1078
+		// Prevent any PHP warnings, like undefined index
1079
+		ob_start();
1080
+
1081
+		if( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) ) {
1082
+			/** @var GF_Field $gv_field */
1083
+			$return = $gv_field->get_field_input( $this->form, $field_value, $this->entry, $field );
1084
+		} else {
1085
+			$return = $field->get_field_input( $this->form, $field_value, $this->entry );
1086
+		}
1087
+
1088
+
1089
+		// If there was output, it's an error
1090
+		$warnings = ob_get_clean();
1091
+
1092
+		if( !empty( $warnings ) ) {
1093
+			do_action( 'gravityview_log_error', __METHOD__ . $warnings, $field_value );
1094
+		}
1095
+
1096
+		/**
1097
+		 * Unset hack $_GET['page'] = 'gf_entries'
1098
+		 * We need the fileupload html field to render with the proper id
1099
+		 *  ( <li id="field_80_16" ... > )
1100
+		 */
1101
+		unset( $_GET['page'] );
1102
+
1103
+		return $return;
1104
+	}
1105
+
1106
+	/**
1107
+	 * Modify the value for the current field input
1108
+	 *
1109
+	 * @param GF_Field $field
1110
+	 *
1111
+	 * @return array|mixed|string|void
1112
+	 */
1113
+	private function get_field_value( $field ) {
1114
+
1115
+		/**
1116
+		 * @filter `gravityview/edit_entry/pre_populate/override` Allow the pre-populated value to override saved value in Edit Entry form. By default, pre-populate mechanism only kicks on empty fields.
1117
+		 * @param boolean True: override saved values; False: don't override (default)
1118
+		 * @param $field GF_Field object Gravity Forms field object
1119
+		 * @since 1.13
1120
+		 */
1121
+		$override_saved_value = apply_filters( 'gravityview/edit_entry/pre_populate/override', false, $field );
1122
+
1123
+		// We're dealing with multiple inputs (e.g. checkbox) but not time or date (as it doesn't store data in input IDs)
1124
+		if( isset( $field->inputs ) && is_array( $field->inputs ) && !in_array( $field->type, array( 'time', 'date' ) ) ) {
1125
+
1126
+			$field_value = array();
1127
+
1128
+			// only accept pre-populated values if the field doesn't have any choice selected.
1129
+			$allow_pre_populated = $field->allowsPrepopulate;
1130
+
1131
+			foreach ( (array)$field->inputs as $input ) {
1132
+
1133
+				$input_id = strval( $input['id'] );
1134 1134
                 
1135
-                if ( isset( $this->entry[ $input_id ] ) && ! gv_empty( $this->entry[ $input_id ], false, false ) ) {
1136
-                    $field_value[ $input_id ] =  'post_category' === $field->type ? GFCommon::format_post_category( $this->entry[ $input_id ], true ) : $this->entry[ $input_id ];
1137
-                    $allow_pre_populated = false;
1138
-                }
1135
+				if ( isset( $this->entry[ $input_id ] ) && ! gv_empty( $this->entry[ $input_id ], false, false ) ) {
1136
+					$field_value[ $input_id ] =  'post_category' === $field->type ? GFCommon::format_post_category( $this->entry[ $input_id ], true ) : $this->entry[ $input_id ];
1137
+					$allow_pre_populated = false;
1138
+				}
1139 1139
 
1140
-            }
1140
+			}
1141 1141
 
1142
-            $pre_value = $field->get_value_submission( array(), false );
1142
+			$pre_value = $field->get_value_submission( array(), false );
1143 1143
 
1144
-            $field_value = ! $allow_pre_populated && ! ( $override_saved_value && !gv_empty( $pre_value, false, false ) ) ? $field_value : $pre_value;
1144
+			$field_value = ! $allow_pre_populated && ! ( $override_saved_value && !gv_empty( $pre_value, false, false ) ) ? $field_value : $pre_value;
1145 1145
 
1146
-        } else {
1146
+		} else {
1147 1147
 
1148
-            $id = intval( $field->id );
1148
+			$id = intval( $field->id );
1149 1149
 
1150
-            // get pre-populated value if exists
1151
-            $pre_value = $field->allowsPrepopulate ? GFFormsModel::get_parameter_value( $field->inputName, array(), $field ) : '';
1150
+			// get pre-populated value if exists
1151
+			$pre_value = $field->allowsPrepopulate ? GFFormsModel::get_parameter_value( $field->inputName, array(), $field ) : '';
1152 1152
 
1153
-            // saved field entry value (if empty, fallback to the pre-populated value, if exists)
1154
-            // or pre-populated value if not empty and set to override saved value
1155
-            $field_value = !gv_empty( $this->entry[ $id ], false, false ) && ! ( $override_saved_value && !gv_empty( $pre_value, false, false ) ) ? $this->entry[ $id ] : $pre_value;
1153
+			// saved field entry value (if empty, fallback to the pre-populated value, if exists)
1154
+			// or pre-populated value if not empty and set to override saved value
1155
+			$field_value = !gv_empty( $this->entry[ $id ], false, false ) && ! ( $override_saved_value && !gv_empty( $pre_value, false, false ) ) ? $this->entry[ $id ] : $pre_value;
1156 1156
 
1157
-            // in case field is post_category but inputType is select, multi-select or radio, convert value into array of category IDs.
1158
-            if ( 'post_category' === $field->type && !gv_empty( $field_value, false, false ) ) {
1159
-                $categories = array();
1160
-                foreach ( explode( ',', $field_value ) as $cat_string ) {
1161
-                    $categories[] = GFCommon::format_post_category( $cat_string, true );
1162
-                }
1163
-                $field_value = 'multiselect' === $field->get_input_type() ? $categories : implode( '', $categories );
1164
-            }
1157
+			// in case field is post_category but inputType is select, multi-select or radio, convert value into array of category IDs.
1158
+			if ( 'post_category' === $field->type && !gv_empty( $field_value, false, false ) ) {
1159
+				$categories = array();
1160
+				foreach ( explode( ',', $field_value ) as $cat_string ) {
1161
+					$categories[] = GFCommon::format_post_category( $cat_string, true );
1162
+				}
1163
+				$field_value = 'multiselect' === $field->get_input_type() ? $categories : implode( '', $categories );
1164
+			}
1165 1165
 
1166
-        }
1166
+		}
1167 1167
 
1168
-        // if value is empty get the default value if defined
1169
-        $field_value = $field->get_value_default_if_empty( $field_value );
1168
+		// if value is empty get the default value if defined
1169
+		$field_value = $field->get_value_default_if_empty( $field_value );
1170 1170
 
1171
-        return $field_value;
1172
-    }
1171
+		return $field_value;
1172
+	}
1173 1173
 
1174 1174
 
1175
-    // ---- Entry validation
1175
+	// ---- Entry validation
1176 1176
 
1177
-    /**
1178
-     * Add field keys that Gravity Forms expects.
1179
-     *
1180
-     * @see GFFormDisplay::validate()
1181
-     * @param  array $form GF Form
1182
-     * @return array       Modified GF Form
1183
-     */
1184
-    public function gform_pre_validation( $form ) {
1177
+	/**
1178
+	 * Add field keys that Gravity Forms expects.
1179
+	 *
1180
+	 * @see GFFormDisplay::validate()
1181
+	 * @param  array $form GF Form
1182
+	 * @return array       Modified GF Form
1183
+	 */
1184
+	public function gform_pre_validation( $form ) {
1185 1185
 
1186
-        if( ! $this->verify_nonce() ) {
1187
-            return $form;
1188
-        }
1186
+		if( ! $this->verify_nonce() ) {
1187
+			return $form;
1188
+		}
1189 1189
 
1190
-        // Fix PHP warning regarding undefined index.
1191
-        foreach ( $form['fields'] as &$field) {
1190
+		// Fix PHP warning regarding undefined index.
1191
+		foreach ( $form['fields'] as &$field) {
1192 1192
 
1193
-            // This is because we're doing admin form pretending to be front-end, so Gravity Forms
1194
-            // expects certain field array items to be set.
1195
-            foreach ( array( 'noDuplicates', 'adminOnly', 'inputType', 'isRequired', 'enablePrice', 'inputs', 'allowedExtensions' ) as $key ) {
1196
-	            $field->{$key} = isset( $field->{$key} ) ? $field->{$key} : NULL;
1197
-            }
1193
+			// This is because we're doing admin form pretending to be front-end, so Gravity Forms
1194
+			// expects certain field array items to be set.
1195
+			foreach ( array( 'noDuplicates', 'adminOnly', 'inputType', 'isRequired', 'enablePrice', 'inputs', 'allowedExtensions' ) as $key ) {
1196
+				$field->{$key} = isset( $field->{$key} ) ? $field->{$key} : NULL;
1197
+			}
1198 1198
 
1199
-            // unset emailConfirmEnabled for email type fields
1200
-           /* if( 'email' === $field['type'] && !empty( $field['emailConfirmEnabled'] ) ) {
1199
+			// unset emailConfirmEnabled for email type fields
1200
+		   /* if( 'email' === $field['type'] && !empty( $field['emailConfirmEnabled'] ) ) {
1201 1201
                 $field['emailConfirmEnabled'] = '';
1202 1202
             }*/
1203 1203
 
1204
-            switch( RGFormsModel::get_input_type( $field ) ) {
1204
+			switch( RGFormsModel::get_input_type( $field ) ) {
1205 1205
 
1206
-                /**
1207
-                 * this whole fileupload hack is because in the admin, Gravity Forms simply doesn't update any fileupload field if it's empty, but it DOES in the frontend.
1208
-                 *
1209
-                 * What we have to do is set the value so that it doesn't get overwritten as empty on save and appears immediately in the Edit Entry screen again.
1210
-                 *
1211
-                 * @hack
1212
-                 */
1213
-                case 'fileupload':
1214
-
1215
-                    // Set the previous value
1216
-                    $entry = $this->get_entry();
1217
-
1218
-                    $input_name = 'input_'.$field->id;
1219
-                    $form_id = $form['id'];
1220
-
1221
-                    $value = NULL;
1222
-
1223
-                    // Use the previous entry value as the default.
1224
-                    if( isset( $entry[ $field->id ] ) ) {
1225
-                        $value = $entry[ $field->id ];
1226
-                    }
1206
+				/**
1207
+				 * this whole fileupload hack is because in the admin, Gravity Forms simply doesn't update any fileupload field if it's empty, but it DOES in the frontend.
1208
+				 *
1209
+				 * What we have to do is set the value so that it doesn't get overwritten as empty on save and appears immediately in the Edit Entry screen again.
1210
+				 *
1211
+				 * @hack
1212
+				 */
1213
+				case 'fileupload':
1227 1214
 
1228
-                    // If this is a single upload file
1229
-                    if( !empty( $_FILES[ $input_name ] ) && !empty( $_FILES[ $input_name ]['name'] ) ) {
1230
-                        $file_path = GFFormsModel::get_file_upload_path( $form['id'], $_FILES[ $input_name ]['name'] );
1231
-                        $value = $file_path['url'];
1215
+					// Set the previous value
1216
+					$entry = $this->get_entry();
1232 1217
 
1233
-                    } else {
1234
-
1235
-                        // Fix PHP warning on line 1498 of form_display.php for post_image fields
1236
-                        // Fix PHP Notice:  Undefined index:  size in form_display.php on line 1511
1237
-                        $_FILES[ $input_name ] = array('name' => '', 'size' => '' );
1238
-
1239
-                    }
1240
-
1241
-                    if( rgar($field, "multipleFiles") ) {
1242
-
1243
-                        // If there are fresh uploads, process and merge them.
1244
-                        // Otherwise, use the passed values, which should be json-encoded array of URLs
1245
-                        if( isset( GFFormsModel::$uploaded_files[$form_id][$input_name] ) ) {
1246
-                            $value = empty( $value ) ? '[]' : $value;
1247
-                            $value = stripslashes_deep( $value );
1248
-                            $value = GFFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'], array());
1249
-                        }
1218
+					$input_name = 'input_'.$field->id;
1219
+					$form_id = $form['id'];
1250 1220
 
1251
-                    } else {
1221
+					$value = NULL;
1252 1222
 
1253
-                        // A file already exists when editing an entry
1254
-                        // We set this to solve issue when file upload fields are required.
1255
-                        GFFormsModel::$uploaded_files[ $form_id ][ $input_name ] = $value;
1223
+					// Use the previous entry value as the default.
1224
+					if( isset( $entry[ $field->id ] ) ) {
1225
+						$value = $entry[ $field->id ];
1226
+					}
1256 1227
 
1257
-                    }
1228
+					// If this is a single upload file
1229
+					if( !empty( $_FILES[ $input_name ] ) && !empty( $_FILES[ $input_name ]['name'] ) ) {
1230
+						$file_path = GFFormsModel::get_file_upload_path( $form['id'], $_FILES[ $input_name ]['name'] );
1231
+						$value = $file_path['url'];
1258 1232
 
1259
-                    $this->entry[ $input_name ] = $value;
1260
-                    $_POST[ $input_name ] = $value;
1233
+					} else {
1261 1234
 
1262
-                    break;
1235
+						// Fix PHP warning on line 1498 of form_display.php for post_image fields
1236
+						// Fix PHP Notice:  Undefined index:  size in form_display.php on line 1511
1237
+						$_FILES[ $input_name ] = array('name' => '', 'size' => '' );
1263 1238
 
1264
-                case 'number':
1265
-                    // Fix "undefined index" issue at line 1286 in form_display.php
1266
-                    if( !isset( $_POST['input_'.$field->id ] ) ) {
1267
-                        $_POST['input_'.$field->id ] = NULL;
1268
-                    }
1269
-                    break;
1270
-                case 'captcha':
1271
-                    // Fix issue with recaptcha_check_answer() on line 1458 in form_display.php
1272
-                    $_POST['recaptcha_challenge_field'] = NULL;
1273
-                    $_POST['recaptcha_response_field'] = NULL;
1274
-                    break;
1275
-            }
1239
+					}
1276 1240
 
1277
-        }
1241
+					if( rgar($field, "multipleFiles") ) {
1278 1242
 
1279
-        return $form;
1280
-    }
1243
+						// If there are fresh uploads, process and merge them.
1244
+						// Otherwise, use the passed values, which should be json-encoded array of URLs
1245
+						if( isset( GFFormsModel::$uploaded_files[$form_id][$input_name] ) ) {
1246
+							$value = empty( $value ) ? '[]' : $value;
1247
+							$value = stripslashes_deep( $value );
1248
+							$value = GFFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'], array());
1249
+						}
1281 1250
 
1251
+					} else {
1282 1252
 
1283
-    /**
1284
-     * Process validation for a edit entry submission
1285
-     *
1286
-     * Sets the `is_valid` object var
1287
-     *
1288
-     * @return void
1289
-     */
1290
-    private function validate() {
1253
+						// A file already exists when editing an entry
1254
+						// We set this to solve issue when file upload fields are required.
1255
+						GFFormsModel::$uploaded_files[ $form_id ][ $input_name ] = $value;
1291 1256
 
1292
-        /**
1293
-         * If using GF User Registration Add-on, remove the validation step, otherwise generates error when updating the entry
1294
-         * GF User Registration Add-on version > 3.x has a different class name
1295
-         * @since 1.16.2
1296
-         */
1297
-        if ( class_exists( 'GF_User_Registration' ) ) {
1298
-            remove_filter( 'gform_validation', array( GF_User_Registration::get_instance(), 'validate' ) );
1299
-        } else  if ( class_exists( 'GFUser' ) ) {
1300
-            remove_filter( 'gform_validation', array( 'GFUser', 'user_registration_validation' ) );
1301
-        }
1257
+					}
1302 1258
 
1259
+					$this->entry[ $input_name ] = $value;
1260
+					$_POST[ $input_name ] = $value;
1303 1261
 
1304
-        /**
1305
-         * For some crazy reason, Gravity Forms doesn't validate Edit Entry form submissions.
1306
-         * You can enter whatever you want!
1307
-         * We try validating, and customize the results using `self::custom_validation()`
1308
-         */
1309
-        add_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10, 4);
1262
+					break;
1310 1263
 
1311
-        // Needed by the validate funtion
1312
-        $failed_validation_page = NULL;
1313
-        $field_values = RGForms::post( 'gform_field_values' );
1264
+				case 'number':
1265
+					// Fix "undefined index" issue at line 1286 in form_display.php
1266
+					if( !isset( $_POST['input_'.$field->id ] ) ) {
1267
+						$_POST['input_'.$field->id ] = NULL;
1268
+					}
1269
+					break;
1270
+				case 'captcha':
1271
+					// Fix issue with recaptcha_check_answer() on line 1458 in form_display.php
1272
+					$_POST['recaptcha_challenge_field'] = NULL;
1273
+					$_POST['recaptcha_response_field'] = NULL;
1274
+					break;
1275
+			}
1314 1276
 
1315
-        // Prevent entry limit from running when editing an entry, also
1316
-        // prevent form scheduling from preventing editing
1317
-        unset( $this->form['limitEntries'], $this->form['scheduleForm'] );
1277
+		}
1318 1278
 
1319
-        // Hide fields depending on Edit Entry settings
1320
-        $this->form['fields'] = $this->get_configured_edit_fields( $this->form, $this->view_id );
1279
+		return $form;
1280
+	}
1321 1281
 
1322
-        $this->is_valid = GFFormDisplay::validate( $this->form, $field_values, 1, $failed_validation_page );
1323 1282
 
1324
-        remove_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10 );
1325
-    }
1283
+	/**
1284
+	 * Process validation for a edit entry submission
1285
+	 *
1286
+	 * Sets the `is_valid` object var
1287
+	 *
1288
+	 * @return void
1289
+	 */
1290
+	private function validate() {
1326 1291
 
1292
+		/**
1293
+		 * If using GF User Registration Add-on, remove the validation step, otherwise generates error when updating the entry
1294
+		 * GF User Registration Add-on version > 3.x has a different class name
1295
+		 * @since 1.16.2
1296
+		 */
1297
+		if ( class_exists( 'GF_User_Registration' ) ) {
1298
+			remove_filter( 'gform_validation', array( GF_User_Registration::get_instance(), 'validate' ) );
1299
+		} else  if ( class_exists( 'GFUser' ) ) {
1300
+			remove_filter( 'gform_validation', array( 'GFUser', 'user_registration_validation' ) );
1301
+		}
1327 1302
 
1328
-    /**
1329
-     * Make validation work for Edit Entry
1330
-     *
1331
-     * Because we're calling the GFFormDisplay::validate() in an unusual way (as a front-end
1332
-     * form pretending to be a back-end form), validate() doesn't know we _can't_ edit post
1333
-     * fields. This goes through all the fields and if they're an invalid post field, we
1334
-     * set them as valid. If there are still issues, we'll return false.
1335
-     *
1336
-     * @param  [type] $validation_results [description]
1337
-     * @return [type]                     [description]
1338
-     */
1339
-    public function custom_validation( $validation_results ) {
1340 1303
 
1341
-        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results: ', $validation_results );
1304
+		/**
1305
+		 * For some crazy reason, Gravity Forms doesn't validate Edit Entry form submissions.
1306
+		 * You can enter whatever you want!
1307
+		 * We try validating, and customize the results using `self::custom_validation()`
1308
+		 */
1309
+		add_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10, 4);
1342 1310
 
1343
-        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) );
1311
+		// Needed by the validate funtion
1312
+		$failed_validation_page = NULL;
1313
+		$field_values = RGForms::post( 'gform_field_values' );
1344 1314
 
1345
-        $gv_valid = true;
1315
+		// Prevent entry limit from running when editing an entry, also
1316
+		// prevent form scheduling from preventing editing
1317
+		unset( $this->form['limitEntries'], $this->form['scheduleForm'] );
1346 1318
 
1347
-        foreach ( $validation_results['form']['fields'] as $key => &$field ) {
1319
+		// Hide fields depending on Edit Entry settings
1320
+		$this->form['fields'] = $this->get_configured_edit_fields( $this->form, $this->view_id );
1348 1321
 
1349
-            $value = RGFormsModel::get_field_value( $field );
1350
-            $field_type = RGFormsModel::get_input_type( $field );
1322
+		$this->is_valid = GFFormDisplay::validate( $this->form, $field_values, 1, $failed_validation_page );
1351 1323
 
1352
-            // Validate always
1353
-            switch ( $field_type ) {
1324
+		remove_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10 );
1325
+	}
1354 1326
 
1355 1327
 
1356
-                case 'fileupload' :
1357
-                case 'post_image':
1328
+	/**
1329
+	 * Make validation work for Edit Entry
1330
+	 *
1331
+	 * Because we're calling the GFFormDisplay::validate() in an unusual way (as a front-end
1332
+	 * form pretending to be a back-end form), validate() doesn't know we _can't_ edit post
1333
+	 * fields. This goes through all the fields and if they're an invalid post field, we
1334
+	 * set them as valid. If there are still issues, we'll return false.
1335
+	 *
1336
+	 * @param  [type] $validation_results [description]
1337
+	 * @return [type]                     [description]
1338
+	 */
1339
+	public function custom_validation( $validation_results ) {
1340
+
1341
+		do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results: ', $validation_results );
1358 1342
 
1359
-                    // in case nothing is uploaded but there are already files saved
1360
-                    if( !empty( $field->failed_validation ) && !empty( $field->isRequired ) && !empty( $value ) ) {
1361
-                        $field->failed_validation = false;
1362
-                        unset( $field->validation_message );
1363
-                    }
1343
+		do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) );
1364 1344
 
1365
-                    // validate if multi file upload reached max number of files [maxFiles] => 2
1366
-                    if( rgobj( $field, 'maxFiles') && rgobj( $field, 'multipleFiles') ) {
1345
+		$gv_valid = true;
1367 1346
 
1368
-                        $input_name = 'input_' . $field->id;
1369
-                        //uploaded
1370
-                        $file_names = isset( GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] ) ? GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] : array();
1347
+		foreach ( $validation_results['form']['fields'] as $key => &$field ) {
1371 1348
 
1372
-                        //existent
1373
-                        $entry = $this->get_entry();
1374
-                        $value = NULL;
1375
-                        if( isset( $entry[ $field->id ] ) ) {
1376
-                            $value = json_decode( $entry[ $field->id ], true );
1377
-                        }
1349
+			$value = RGFormsModel::get_field_value( $field );
1350
+			$field_type = RGFormsModel::get_input_type( $field );
1378 1351
 
1379
-                        // count uploaded files and existent entry files
1380
-                        $count_files = count( $file_names ) + count( $value );
1352
+			// Validate always
1353
+			switch ( $field_type ) {
1381 1354
 
1382
-                        if( $count_files > $field->maxFiles ) {
1383
-                            $field->validation_message = __( 'Maximum number of files reached', 'gravityview' );
1384
-                            $field->failed_validation = 1;
1385
-                            $gv_valid = false;
1386 1355
 
1387
-                            // in case of error make sure the newest upload files are removed from the upload input
1388
-                            GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ] = null;
1389
-                        }
1356
+				case 'fileupload' :
1357
+				case 'post_image':
1390 1358
 
1391
-                    }
1359
+					// in case nothing is uploaded but there are already files saved
1360
+					if( !empty( $field->failed_validation ) && !empty( $field->isRequired ) && !empty( $value ) ) {
1361
+						$field->failed_validation = false;
1362
+						unset( $field->validation_message );
1363
+					}
1392 1364
 
1365
+					// validate if multi file upload reached max number of files [maxFiles] => 2
1366
+					if( rgobj( $field, 'maxFiles') && rgobj( $field, 'multipleFiles') ) {
1393 1367
 
1394
-                    break;
1368
+						$input_name = 'input_' . $field->id;
1369
+						//uploaded
1370
+						$file_names = isset( GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] ) ? GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] : array();
1395 1371
 
1396
-            }
1372
+						//existent
1373
+						$entry = $this->get_entry();
1374
+						$value = NULL;
1375
+						if( isset( $entry[ $field->id ] ) ) {
1376
+							$value = json_decode( $entry[ $field->id ], true );
1377
+						}
1397 1378
 
1398
-            // This field has failed validation.
1399
-            if( !empty( $field->failed_validation ) ) {
1379
+						// count uploaded files and existent entry files
1380
+						$count_files = count( $file_names ) + count( $value );
1400 1381
 
1401
-                do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field is invalid.', array( 'field' => $field, 'value' => $value ) );
1382
+						if( $count_files > $field->maxFiles ) {
1383
+							$field->validation_message = __( 'Maximum number of files reached', 'gravityview' );
1384
+							$field->failed_validation = 1;
1385
+							$gv_valid = false;
1402 1386
 
1403
-                switch ( $field_type ) {
1387
+							// in case of error make sure the newest upload files are removed from the upload input
1388
+							GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ] = null;
1389
+						}
1404 1390
 
1405
-                    // Captchas don't need to be re-entered.
1406
-                    case 'captcha':
1391
+					}
1407 1392
 
1408
-                        // Post Image fields aren't editable, so we un-fail them.
1409
-                    case 'post_image':
1410
-                        $field->failed_validation = false;
1411
-                        unset( $field->validation_message );
1412
-                        break;
1413 1393
 
1414
-                }
1394
+					break;
1415 1395
 
1416
-                // You can't continue inside a switch, so we do it after.
1417
-                if( empty( $field->failed_validation ) ) {
1418
-                    continue;
1419
-                }
1396
+			}
1420 1397
 
1421
-                // checks if the No Duplicates option is not validating entry against itself, since
1422
-                // we're editing a stored entry, it would also assume it's a duplicate.
1423
-                if( !empty( $field->noDuplicates ) ) {
1398
+			// This field has failed validation.
1399
+			if( !empty( $field->failed_validation ) ) {
1424 1400
 
1425
-                    $entry = $this->get_entry();
1401
+				do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field is invalid.', array( 'field' => $field, 'value' => $value ) );
1426 1402
 
1427
-                    // If the value of the entry is the same as the stored value
1428
-                    // Then we can assume it's not a duplicate, it's the same.
1429
-                    if( !empty( $entry ) && $value == $entry[ $field->id ] ) {
1430
-                        //if value submitted was not changed, then don't validate
1431
-                        $field->failed_validation = false;
1403
+				switch ( $field_type ) {
1432 1404
 
1433
-                        unset( $field->validation_message );
1405
+					// Captchas don't need to be re-entered.
1406
+					case 'captcha':
1434 1407
 
1435
-                        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', $entry );
1408
+						// Post Image fields aren't editable, so we un-fail them.
1409
+					case 'post_image':
1410
+						$field->failed_validation = false;
1411
+						unset( $field->validation_message );
1412
+						break;
1436 1413
 
1437
-                        continue;
1438
-                    }
1439
-                }
1414
+				}
1440 1415
 
1441
-                // if here then probably we are facing the validation 'At least one field must be filled out'
1442
-                if( GFFormDisplay::is_empty( $field, $this->form_id  ) && empty( $field->isRequired ) ) {
1443
-                    unset( $field->validation_message );
1444
-	                $field->validation_message = false;
1445
-                    continue;
1446
-                }
1416
+				// You can't continue inside a switch, so we do it after.
1417
+				if( empty( $field->failed_validation ) ) {
1418
+					continue;
1419
+				}
1447 1420
 
1448
-                $gv_valid = false;
1421
+				// checks if the No Duplicates option is not validating entry against itself, since
1422
+				// we're editing a stored entry, it would also assume it's a duplicate.
1423
+				if( !empty( $field->noDuplicates ) ) {
1449 1424
 
1450
-            }
1425
+					$entry = $this->get_entry();
1451 1426
 
1452
-        }
1427
+					// If the value of the entry is the same as the stored value
1428
+					// Then we can assume it's not a duplicate, it's the same.
1429
+					if( !empty( $entry ) && $value == $entry[ $field->id ] ) {
1430
+						//if value submitted was not changed, then don't validate
1431
+						$field->failed_validation = false;
1453 1432
 
1454
-        $validation_results['is_valid'] = $gv_valid;
1433
+						unset( $field->validation_message );
1455 1434
 
1456
-        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results.', $validation_results );
1435
+						do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', $entry );
1457 1436
 
1458
-        // We'll need this result when rendering the form ( on GFFormDisplay::get_form )
1459
-        $this->form_after_validation = $validation_results['form'];
1437
+						continue;
1438
+					}
1439
+				}
1460 1440
 
1461
-        return $validation_results;
1462
-    }
1441
+				// if here then probably we are facing the validation 'At least one field must be filled out'
1442
+				if( GFFormDisplay::is_empty( $field, $this->form_id  ) && empty( $field->isRequired ) ) {
1443
+					unset( $field->validation_message );
1444
+					$field->validation_message = false;
1445
+					continue;
1446
+				}
1463 1447
 
1448
+				$gv_valid = false;
1449
+
1450
+			}
1464 1451
 
1465
-    /**
1466
-     * TODO: This seems to be hacky... we should remove it. Entry is set when updating the form using setup_vars()!
1467
-     * Get the current entry and set it if it's not yet set.
1468
-     * @return array Gravity Forms entry array
1469
-     */
1470
-    public function get_entry() {
1452
+		}
1471 1453
 
1472
-        if( empty( $this->entry ) ) {
1473
-            // Get the database value of the entry that's being edited
1474
-            $this->entry = gravityview_get_entry( GravityView_frontend::is_single_entry() );
1475
-        }
1454
+		$validation_results['is_valid'] = $gv_valid;
1476 1455
 
1477
-        return $this->entry;
1478
-    }
1456
+		do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results.', $validation_results );
1457
+
1458
+		// We'll need this result when rendering the form ( on GFFormDisplay::get_form )
1459
+		$this->form_after_validation = $validation_results['form'];
1460
+
1461
+		return $validation_results;
1462
+	}
1463
+
1464
+
1465
+	/**
1466
+	 * TODO: This seems to be hacky... we should remove it. Entry is set when updating the form using setup_vars()!
1467
+	 * Get the current entry and set it if it's not yet set.
1468
+	 * @return array Gravity Forms entry array
1469
+	 */
1470
+	public function get_entry() {
1471
+
1472
+		if( empty( $this->entry ) ) {
1473
+			// Get the database value of the entry that's being edited
1474
+			$this->entry = gravityview_get_entry( GravityView_frontend::is_single_entry() );
1475
+		}
1476
+
1477
+		return $this->entry;
1478
+	}
1479 1479
 
1480 1480
 
1481 1481
 
1482
-    // --- Filters
1482
+	// --- Filters
1483 1483
 
1484
-    /**
1485
-     * Get the Edit Entry fields as configured in the View
1486
-     *
1487
-     * @since 1.8
1488
-     *
1489
-     * @param int $view_id
1490
-     *
1491
-     * @return array Array of fields that are configured in the Edit tab in the Admin
1492
-     */
1493
-    private function get_configured_edit_fields( $form, $view_id ) {
1484
+	/**
1485
+	 * Get the Edit Entry fields as configured in the View
1486
+	 *
1487
+	 * @since 1.8
1488
+	 *
1489
+	 * @param int $view_id
1490
+	 *
1491
+	 * @return array Array of fields that are configured in the Edit tab in the Admin
1492
+	 */
1493
+	private function get_configured_edit_fields( $form, $view_id ) {
1494 1494
 
1495
-        // Get all fields for form
1496
-        $properties = GravityView_View_Data::getInstance()->get_fields( $view_id );
1495
+		// Get all fields for form
1496
+		$properties = GravityView_View_Data::getInstance()->get_fields( $view_id );
1497 1497
 
1498
-        // If edit tab not yet configured, show all fields
1499
-        $edit_fields = !empty( $properties['edit_edit-fields'] ) ? $properties['edit_edit-fields'] : NULL;
1498
+		// If edit tab not yet configured, show all fields
1499
+		$edit_fields = !empty( $properties['edit_edit-fields'] ) ? $properties['edit_edit-fields'] : NULL;
1500 1500
 
1501
-        // Show hidden fields as text fields
1502
-        $form = $this->fix_survey_fields( $form );
1501
+		// Show hidden fields as text fields
1502
+		$form = $this->fix_survey_fields( $form );
1503 1503
 
1504
-        // Hide fields depending on admin settings
1505
-        $fields = $this->filter_fields( $form['fields'], $edit_fields );
1504
+		// Hide fields depending on admin settings
1505
+		$fields = $this->filter_fields( $form['fields'], $edit_fields );
1506 1506
 
1507
-	    // If Edit Entry fields are configured, remove adminOnly field settings. Otherwise, don't.
1508
-	    $fields = $this->filter_admin_only_fields( $fields, $edit_fields, $form, $view_id );
1507
+		// If Edit Entry fields are configured, remove adminOnly field settings. Otherwise, don't.
1508
+		$fields = $this->filter_admin_only_fields( $fields, $edit_fields, $form, $view_id );
1509 1509
 
1510
-        /**
1511
-         * @filter `gravityview/edit_entry/form_fields` Modify the fields displayed in Edit Entry form
1512
-         * @since 1.17
1513
-         * @param GF_Field[] $fields Gravity Forms form fields
1514
-         * @param array|null $edit_fields Fields for the Edit Entry tab configured in the View Configuration
1515
-         * @param array $form GF Form array (`fields` key modified to have only fields configured to show in Edit Entry)
1516
-         * @param int $view_id View ID
1517
-         */
1518
-        $fields = apply_filters( 'gravityview/edit_entry/form_fields', $fields, $edit_fields, $form, $view_id );
1510
+		/**
1511
+		 * @filter `gravityview/edit_entry/form_fields` Modify the fields displayed in Edit Entry form
1512
+		 * @since 1.17
1513
+		 * @param GF_Field[] $fields Gravity Forms form fields
1514
+		 * @param array|null $edit_fields Fields for the Edit Entry tab configured in the View Configuration
1515
+		 * @param array $form GF Form array (`fields` key modified to have only fields configured to show in Edit Entry)
1516
+		 * @param int $view_id View ID
1517
+		 */
1518
+		$fields = apply_filters( 'gravityview/edit_entry/form_fields', $fields, $edit_fields, $form, $view_id );
1519 1519
 
1520
-        return $fields;
1521
-    }
1520
+		return $fields;
1521
+	}
1522 1522
 
1523
-    /**
1524
-     * Make sure Survey fields accept pre-populating values; otherwise existing values won't be filled-in
1525
-     *
1526
-     * @since 1.16.4
1527
-     *
1528
-     * @param array $form
1529
-     *
1530
-     * @return array Form, with all fields set to `allowsPrepopulate => true`
1531
-     */
1532
-    private function fix_survey_fields( $form ) {
1523
+	/**
1524
+	 * Make sure Survey fields accept pre-populating values; otherwise existing values won't be filled-in
1525
+	 *
1526
+	 * @since 1.16.4
1527
+	 *
1528
+	 * @param array $form
1529
+	 *
1530
+	 * @return array Form, with all fields set to `allowsPrepopulate => true`
1531
+	 */
1532
+	private function fix_survey_fields( $form ) {
1533 1533
 
1534
-        /** @var GF_Field $field */
1535
-        foreach( $form['fields'] as &$field ) {
1536
-            $field->allowsPrepopulate = true;
1537
-        }
1534
+		/** @var GF_Field $field */
1535
+		foreach( $form['fields'] as &$field ) {
1536
+			$field->allowsPrepopulate = true;
1537
+		}
1538 1538
 
1539
-        return $form;
1540
-    }
1539
+		return $form;
1540
+	}
1541 1541
     
1542 1542
 
1543
-    /**
1544
-     * Filter area fields based on specified conditions
1545
-     *  - This filter removes the fields that have calculation configured
1546
-     *
1547
-     * @uses GravityView_Edit_Entry::user_can_edit_field() Check caps
1548
-     * @access private
1549
-     * @param GF_Field[] $fields
1550
-     * @param array $configured_fields
1551
-     * @since  1.5
1552
-     * @return array $fields
1553
-     */
1554
-    private function filter_fields( $fields, $configured_fields ) {
1555
-
1556
-        if( empty( $fields ) || !is_array( $fields ) ) {
1557
-            return $fields;
1558
-        }
1559
-
1560
-        $edit_fields = array();
1561
-
1562
-        $field_type_blacklist = array(
1563
-            'page',
1564
-        );
1565
-
1566
-	    /**
1567
-	     * @filter `gravityview/edit_entry/hide-product-fields` Hide product fields from being editable.
1568
-	     * @since 1.9.1
1569
-         * @param boolean $hide_product_fields Whether to hide product fields in the editor.  Default: false
1570
-	     */
1571
-	    $hide_product_fields = apply_filters( 'gravityview/edit_entry/hide-product-fields', empty( self::$supports_product_fields ) );
1572
-
1573
-	    if( $hide_product_fields ) {
1574
-		    $field_type_blacklist[] = 'option';
1575
-		    $field_type_blacklist[] = 'quantity';
1576
-            $field_type_blacklist[] = 'product';
1577
-            $field_type_blacklist[] = 'total';
1578
-            $field_type_blacklist[] = 'shipping';
1579
-            $field_type_blacklist[] = 'calculation';
1580
-	    }
1581
-
1582
-        // First, remove blacklist or calculation fields
1583
-        foreach ( $fields as $key => $field ) {
1584
-
1585
-            // Remove the fields that have calculation properties and keep them to be used later
1586
-            // @since 1.16.2
1587
-            if( $field->has_calculation() ) {
1588
-                $this->fields_with_calculation[] = $field;
1589
-                // don't remove the calculation fields on form render.
1590
-            }
1591
-
1592
-            // process total field after all fields have been saved
1593
-            if ( $field->type == 'total' ) {
1594
-                $this->total_fields[] = $field;
1595
-                unset( $fields[ $key ] );
1596
-            }
1597
-
1598
-            if( in_array( $field->type, $field_type_blacklist ) ) {
1599
-                unset( $fields[ $key ] );
1600
-            }
1601
-        }
1602
-
1603
-        // The Edit tab has not been configured, so we return all fields by default.
1604
-        if( empty( $configured_fields ) ) {
1605
-            return $fields;
1606
-        }
1607
-
1608
-        // The edit tab has been configured, so we loop through to configured settings
1609
-        foreach ( $configured_fields as $configured_field ) {
1610
-
1611
-	        /** @var GF_Field $field */
1612
-	        foreach ( $fields as $field ) {
1613
-
1614
-                if( intval( $configured_field['id'] ) === intval( $field->id ) && $this->user_can_edit_field( $configured_field, false ) ) {
1615
-                    $edit_fields[] = $this->merge_field_properties( $field, $configured_field );
1616
-                    break;
1617
-                }
1618
-
1619
-            }
1620
-
1621
-        }
1622
-
1623
-        return $edit_fields;
1624
-
1625
-    }
1626
-
1627
-    /**
1628
-     * Override GF Form field properties with the ones defined on the View
1629
-     * @param  GF_Field $field GF Form field object
1630
-     * @param  array $setting  GV field options
1631
-     * @since  1.5
1632
-     * @return array|GF_Field
1633
-     */
1634
-    private function merge_field_properties( $field, $field_setting ) {
1635
-
1636
-        $return_field = $field;
1637
-
1638
-        if( empty( $field_setting['show_label'] ) ) {
1639
-            $return_field->label = '';
1640
-        } elseif ( !empty( $field_setting['custom_label'] ) ) {
1641
-            $return_field->label = $field_setting['custom_label'];
1642
-        }
1643
-
1644
-        if( !empty( $field_setting['custom_class'] ) ) {
1645
-            $return_field->cssClass .= ' '. gravityview_sanitize_html_class( $field_setting['custom_class'] );
1646
-        }
1647
-
1648
-        /**
1649
-         * Normalize page numbers - avoid conflicts with page validation
1650
-         * @since 1.6
1651
-         */
1652
-        $return_field->pageNumber = 1;
1653
-
1654
-        return $return_field;
1655
-
1656
-    }
1657
-
1658
-    /**
1659
-     * Remove fields that shouldn't be visible based on the Gravity Forms adminOnly field property
1660
-     *
1661
-     * @since 1.9.1
1662
-     *
1663
-     * @param array|GF_Field[] $fields Gravity Forms form fields
1664
-     * @param array|null $edit_fields Fields for the Edit Entry tab configured in the View Configuration
1665
-     * @param array $form GF Form array
1666
-     * @param int $view_id View ID
1667
-     *
1668
-     * @return array Possibly modified form array
1669
-     */
1670
-    private function filter_admin_only_fields( $fields = array(), $edit_fields = null, $form = array(), $view_id = 0 ) {
1671
-
1672
-	    /**
1673
-         * @filter `gravityview/edit_entry/use_gf_admin_only_setting` When Edit tab isn't configured, should the Gravity Forms "Admin Only" field settings be used to control field display to non-admins? Default: true
1674
-	     * If the Edit Entry tab is not configured, adminOnly fields will not be shown to non-administrators.
1675
-	     * If the Edit Entry tab *is* configured, adminOnly fields will be shown to non-administrators, using the configured GV permissions
1676
-	     * @since 1.9.1
1677
-	     * @param boolean $use_gf_adminonly_setting True: Hide field if set to Admin Only in GF and the user is not an admin. False: show field based on GV permissions, ignoring GF permissions.
1678
-	     * @param array $form GF Form array
1679
-	     * @param int $view_id View ID
1680
-	     */
1681
-	    $use_gf_adminonly_setting = apply_filters( 'gravityview/edit_entry/use_gf_admin_only_setting', empty( $edit_fields ), $form, $view_id );
1682
-
1683
-	    if( $use_gf_adminonly_setting && false === GVCommon::has_cap( 'gravityforms_edit_entries', $this->entry['id'] ) ) {
1684
-            foreach( $fields as $k => $field ) {
1685
-                if( $field->adminOnly ) {
1686
-                    unset( $fields[ $k ] );
1687
-                }
1688
-            }
1689
-            return $fields;
1690
-        }
1691
-
1692
-	    foreach( $fields as &$field ) {
1693
-		    $field->adminOnly = false;
1694
-        }
1695
-
1696
-        return $fields;
1697
-    }
1698
-
1699
-    // --- Conditional Logic
1700
-
1701
-    /**
1702
-     * Remove the conditional logic rules from the form button and the form fields, if needed.
1703
-     *
1704
-     * @todo Merge with caller method
1705
-     * @since 1.9
1706
-     *
1707
-     * @param array $form Gravity Forms form
1708
-     * @return array Modified form, if not using Conditional Logic
1709
-     */
1710
-    private function filter_conditional_logic( $form ) {
1711
-
1712
-        /**
1713
-         * @filter `gravityview/edit_entry/conditional_logic` Should the Edit Entry form use Gravity Forms conditional logic showing/hiding of fields?
1714
-         * @since 1.9
1715
-         * @param bool $use_conditional_logic True: Gravity Forms will show/hide fields just like in the original form; False: conditional logic will be disabled and fields will be shown based on configuration. Default: true
1716
-         * @param array $form Gravity Forms form
1717
-         */
1718
-        $use_conditional_logic = apply_filters( 'gravityview/edit_entry/conditional_logic', true, $form );
1719
-
1720
-        if( $use_conditional_logic ) {
1721
-            return $form;
1722
-        }
1723
-
1724
-        foreach( $form['fields'] as &$field ) {
1725
-            /* @var GF_Field $field */
1726
-            $field->conditionalLogic = null;
1727
-        }
1728
-
1729
-        unset( $form['button']['conditionalLogic'] );
1730
-
1731
-        return $form;
1732
-
1733
-    }
1734
-
1735
-    /**
1736
-     * Disable the Gravity Forms conditional logic script and features on the Edit Entry screen
1737
-     *
1738
-     * @since 1.9
1739
-     *
1740
-     * @param $has_conditional_logic
1741
-     * @param $form
1742
-     * @return mixed|void
1743
-     */
1744
-    public function manage_conditional_logic( $has_conditional_logic, $form ) {
1745
-
1746
-        if( ! $this->is_edit_entry() ) {
1747
-            return $has_conditional_logic;
1748
-        }
1749
-
1750
-        return apply_filters( 'gravityview/edit_entry/conditional_logic', $has_conditional_logic, $form );
1751
-    }
1752
-
1753
-
1754
-    // --- User checks and nonces
1755
-
1756
-    /**
1757
-     * Check if the user can edit the entry
1758
-     *
1759
-     * - Is the nonce valid?
1760
-     * - Does the user have the right caps for the entry
1761
-     * - Is the entry in the trash?
1762
-     *
1763
-     * @todo Move to GVCommon
1764
-     *
1765
-     * @param  boolean $echo Show error messages in the form?
1766
-     * @return boolean        True: can edit form. False: nope.
1767
-     */
1768
-    private function user_can_edit_entry( $echo = false ) {
1769
-
1770
-        $error = NULL;
1771
-
1772
-        /**
1773
-         *  1. Permalinks are turned off
1774
-         *  2. There are two entries embedded using oEmbed
1775
-         *  3. One of the entries has just been saved
1776
-         */
1777
-        if( !empty( $_POST['lid'] ) && !empty( $_GET['entry'] ) && ( $_POST['lid'] !== $_GET['entry'] ) ) {
1778
-
1779
-            $error = true;
1780
-
1781
-        }
1782
-
1783
-        if( !empty( $_GET['entry'] ) && (string)$this->entry['id'] !== $_GET['entry'] ) {
1784
-
1785
-            $error = true;
1786
-
1787
-        } elseif( ! $this->verify_nonce() ) {
1788
-
1789
-            /**
1790
-             * If the Entry is embedded, there may be two entries on the same page.
1791
-             * If that's the case, and one is being edited, the other should fail gracefully and not display an error.
1792
-             */
1793
-            if( GravityView_oEmbed::getInstance()->get_entry_id() ) {
1794
-                $error = true;
1795
-            } else {
1796
-                $error = __( 'The link to edit this entry is not valid; it may have expired.', 'gravityview');
1797
-            }
1543
+	/**
1544
+	 * Filter area fields based on specified conditions
1545
+	 *  - This filter removes the fields that have calculation configured
1546
+	 *
1547
+	 * @uses GravityView_Edit_Entry::user_can_edit_field() Check caps
1548
+	 * @access private
1549
+	 * @param GF_Field[] $fields
1550
+	 * @param array $configured_fields
1551
+	 * @since  1.5
1552
+	 * @return array $fields
1553
+	 */
1554
+	private function filter_fields( $fields, $configured_fields ) {
1555
+
1556
+		if( empty( $fields ) || !is_array( $fields ) ) {
1557
+			return $fields;
1558
+		}
1559
+
1560
+		$edit_fields = array();
1561
+
1562
+		$field_type_blacklist = array(
1563
+			'page',
1564
+		);
1565
+
1566
+		/**
1567
+		 * @filter `gravityview/edit_entry/hide-product-fields` Hide product fields from being editable.
1568
+		 * @since 1.9.1
1569
+		 * @param boolean $hide_product_fields Whether to hide product fields in the editor.  Default: false
1570
+		 */
1571
+		$hide_product_fields = apply_filters( 'gravityview/edit_entry/hide-product-fields', empty( self::$supports_product_fields ) );
1572
+
1573
+		if( $hide_product_fields ) {
1574
+			$field_type_blacklist[] = 'option';
1575
+			$field_type_blacklist[] = 'quantity';
1576
+			$field_type_blacklist[] = 'product';
1577
+			$field_type_blacklist[] = 'total';
1578
+			$field_type_blacklist[] = 'shipping';
1579
+			$field_type_blacklist[] = 'calculation';
1580
+		}
1581
+
1582
+		// First, remove blacklist or calculation fields
1583
+		foreach ( $fields as $key => $field ) {
1584
+
1585
+			// Remove the fields that have calculation properties and keep them to be used later
1586
+			// @since 1.16.2
1587
+			if( $field->has_calculation() ) {
1588
+				$this->fields_with_calculation[] = $field;
1589
+				// don't remove the calculation fields on form render.
1590
+			}
1591
+
1592
+			// process total field after all fields have been saved
1593
+			if ( $field->type == 'total' ) {
1594
+				$this->total_fields[] = $field;
1595
+				unset( $fields[ $key ] );
1596
+			}
1798 1597
 
1799
-        }
1800
-
1801
-        if( ! GravityView_Edit_Entry::check_user_cap_edit_entry( $this->entry ) ) {
1802
-            $error = __( 'You do not have permission to edit this entry.', 'gravityview');
1803
-        }
1804
-
1805
-        if( $this->entry['status'] === 'trash' ) {
1806
-            $error = __('You cannot edit the entry; it is in the trash.', 'gravityview' );
1807
-        }
1598
+			if( in_array( $field->type, $field_type_blacklist ) ) {
1599
+				unset( $fields[ $key ] );
1600
+			}
1601
+		}
1808 1602
 
1809
-        // No errors; everything's fine here!
1810
-        if( empty( $error ) ) {
1811
-            return true;
1812
-        }
1603
+		// The Edit tab has not been configured, so we return all fields by default.
1604
+		if( empty( $configured_fields ) ) {
1605
+			return $fields;
1606
+		}
1813 1607
 
1814
-        if( $echo && $error !== true ) {
1608
+		// The edit tab has been configured, so we loop through to configured settings
1609
+		foreach ( $configured_fields as $configured_field ) {
1815 1610
 
1816
-	        $error = esc_html( $error );
1611
+			/** @var GF_Field $field */
1612
+			foreach ( $fields as $field ) {
1817 1613
 
1818
-	        /**
1819
-	         * @since 1.9
1820
-	         */
1821
-	        if ( ! empty( $this->entry ) ) {
1822
-		        $error .= ' ' . gravityview_get_link( '#', _x('Go back.', 'Link shown when invalid Edit Entry link is clicked', 'gravityview' ), array( 'onclick' => "window.history.go(-1); return false;" ) );
1823
-	        }
1614
+				if( intval( $configured_field['id'] ) === intval( $field->id ) && $this->user_can_edit_field( $configured_field, false ) ) {
1615
+					$edit_fields[] = $this->merge_field_properties( $field, $configured_field );
1616
+					break;
1617
+				}
1824 1618
 
1825
-            echo GVCommon::generate_notice( wpautop( $error ), 'gv-error error');
1826
-        }
1619
+			}
1827 1620
 
1828
-        do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_entry]' . $error );
1621
+		}
1829 1622
 
1830
-        return false;
1831
-    }
1623
+		return $edit_fields;
1832 1624
 
1625
+	}
1833 1626
 
1834
-    /**
1835
-     * Check whether a field is editable by the current user, and optionally display an error message
1836
-     * @uses  GravityView_Edit_Entry->check_user_cap_edit_field() Check user capabilities
1837
-     * @param  array  $field Field or field settings array
1838
-     * @param  boolean $echo  Whether to show error message telling user they aren't allowed
1839
-     * @return boolean         True: user can edit the current field; False: nope, they can't.
1840
-     */
1841
-    private function user_can_edit_field( $field, $echo = false ) {
1842
-
1843
-        $error = NULL;
1627
+	/**
1628
+	 * Override GF Form field properties with the ones defined on the View
1629
+	 * @param  GF_Field $field GF Form field object
1630
+	 * @param  array $setting  GV field options
1631
+	 * @since  1.5
1632
+	 * @return array|GF_Field
1633
+	 */
1634
+	private function merge_field_properties( $field, $field_setting ) {
1844 1635
 
1845
-        if( ! $this->check_user_cap_edit_field( $field ) ) {
1846
-            $error = __( 'You do not have permission to edit this field.', 'gravityview');
1847
-        }
1636
+		$return_field = $field;
1848 1637
 
1849
-        // No errors; everything's fine here!
1850
-        if( empty( $error ) ) {
1851
-            return true;
1852
-        }
1638
+		if( empty( $field_setting['show_label'] ) ) {
1639
+			$return_field->label = '';
1640
+		} elseif ( !empty( $field_setting['custom_label'] ) ) {
1641
+			$return_field->label = $field_setting['custom_label'];
1642
+		}
1853 1643
 
1854
-        if( $echo ) {
1855
-            echo GVCommon::generate_notice( wpautop( esc_html( $error ) ), 'gv-error error');
1856
-        }
1857
-
1858
-        do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_field]' . $error );
1644
+		if( !empty( $field_setting['custom_class'] ) ) {
1645
+			$return_field->cssClass .= ' '. gravityview_sanitize_html_class( $field_setting['custom_class'] );
1646
+		}
1859 1647
 
1860
-        return false;
1648
+		/**
1649
+		 * Normalize page numbers - avoid conflicts with page validation
1650
+		 * @since 1.6
1651
+		 */
1652
+		$return_field->pageNumber = 1;
1861 1653
 
1862
-    }
1654
+		return $return_field;
1863 1655
 
1656
+	}
1864 1657
 
1865
-    /**
1866
-     * checks if user has permissions to edit a specific field
1867
-     *
1868
-     * Needs to be used combined with GravityView_Edit_Entry::user_can_edit_field for maximum security!!
1869
-     *
1870
-     * @param  [type] $field [description]
1871
-     * @return bool
1872
-     */
1873
-    private function check_user_cap_edit_field( $field ) {
1658
+	/**
1659
+	 * Remove fields that shouldn't be visible based on the Gravity Forms adminOnly field property
1660
+	 *
1661
+	 * @since 1.9.1
1662
+	 *
1663
+	 * @param array|GF_Field[] $fields Gravity Forms form fields
1664
+	 * @param array|null $edit_fields Fields for the Edit Entry tab configured in the View Configuration
1665
+	 * @param array $form GF Form array
1666
+	 * @param int $view_id View ID
1667
+	 *
1668
+	 * @return array Possibly modified form array
1669
+	 */
1670
+	private function filter_admin_only_fields( $fields = array(), $edit_fields = null, $form = array(), $view_id = 0 ) {
1671
+
1672
+		/**
1673
+		 * @filter `gravityview/edit_entry/use_gf_admin_only_setting` When Edit tab isn't configured, should the Gravity Forms "Admin Only" field settings be used to control field display to non-admins? Default: true
1674
+		 * If the Edit Entry tab is not configured, adminOnly fields will not be shown to non-administrators.
1675
+		 * If the Edit Entry tab *is* configured, adminOnly fields will be shown to non-administrators, using the configured GV permissions
1676
+		 * @since 1.9.1
1677
+		 * @param boolean $use_gf_adminonly_setting True: Hide field if set to Admin Only in GF and the user is not an admin. False: show field based on GV permissions, ignoring GF permissions.
1678
+		 * @param array $form GF Form array
1679
+		 * @param int $view_id View ID
1680
+		 */
1681
+		$use_gf_adminonly_setting = apply_filters( 'gravityview/edit_entry/use_gf_admin_only_setting', empty( $edit_fields ), $form, $view_id );
1682
+
1683
+		if( $use_gf_adminonly_setting && false === GVCommon::has_cap( 'gravityforms_edit_entries', $this->entry['id'] ) ) {
1684
+			foreach( $fields as $k => $field ) {
1685
+				if( $field->adminOnly ) {
1686
+					unset( $fields[ $k ] );
1687
+				}
1688
+			}
1689
+			return $fields;
1690
+		}
1874 1691
 
1875
-        // If they can edit any entries (as defined in Gravity Forms), we're good.
1876
-        if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ) ) ) {
1877
-            return true;
1878
-        }
1692
+		foreach( $fields as &$field ) {
1693
+			$field->adminOnly = false;
1694
+		}
1879 1695
 
1880
-        $field_cap = isset( $field['allow_edit_cap'] ) ? $field['allow_edit_cap'] : false;
1696
+		return $fields;
1697
+	}
1881 1698
 
1882
-        // If the field has custom editing capaibilities set, check those
1883
-        if( $field_cap ) {
1884
-            return GVCommon::has_cap( $field['allow_edit_cap'] );
1885
-        }
1886
-
1887
-        return false;
1888
-    }
1699
+	// --- Conditional Logic
1889 1700
 
1701
+	/**
1702
+	 * Remove the conditional logic rules from the form button and the form fields, if needed.
1703
+	 *
1704
+	 * @todo Merge with caller method
1705
+	 * @since 1.9
1706
+	 *
1707
+	 * @param array $form Gravity Forms form
1708
+	 * @return array Modified form, if not using Conditional Logic
1709
+	 */
1710
+	private function filter_conditional_logic( $form ) {
1711
+
1712
+		/**
1713
+		 * @filter `gravityview/edit_entry/conditional_logic` Should the Edit Entry form use Gravity Forms conditional logic showing/hiding of fields?
1714
+		 * @since 1.9
1715
+		 * @param bool $use_conditional_logic True: Gravity Forms will show/hide fields just like in the original form; False: conditional logic will be disabled and fields will be shown based on configuration. Default: true
1716
+		 * @param array $form Gravity Forms form
1717
+		 */
1718
+		$use_conditional_logic = apply_filters( 'gravityview/edit_entry/conditional_logic', true, $form );
1719
+
1720
+		if( $use_conditional_logic ) {
1721
+			return $form;
1722
+		}
1723
+
1724
+		foreach( $form['fields'] as &$field ) {
1725
+			/* @var GF_Field $field */
1726
+			$field->conditionalLogic = null;
1727
+		}
1728
+
1729
+		unset( $form['button']['conditionalLogic'] );
1730
+
1731
+		return $form;
1732
+
1733
+	}
1734
+
1735
+	/**
1736
+	 * Disable the Gravity Forms conditional logic script and features on the Edit Entry screen
1737
+	 *
1738
+	 * @since 1.9
1739
+	 *
1740
+	 * @param $has_conditional_logic
1741
+	 * @param $form
1742
+	 * @return mixed|void
1743
+	 */
1744
+	public function manage_conditional_logic( $has_conditional_logic, $form ) {
1745
+
1746
+		if( ! $this->is_edit_entry() ) {
1747
+			return $has_conditional_logic;
1748
+		}
1749
+
1750
+		return apply_filters( 'gravityview/edit_entry/conditional_logic', $has_conditional_logic, $form );
1751
+	}
1752
+
1753
+
1754
+	// --- User checks and nonces
1755
+
1756
+	/**
1757
+	 * Check if the user can edit the entry
1758
+	 *
1759
+	 * - Is the nonce valid?
1760
+	 * - Does the user have the right caps for the entry
1761
+	 * - Is the entry in the trash?
1762
+	 *
1763
+	 * @todo Move to GVCommon
1764
+	 *
1765
+	 * @param  boolean $echo Show error messages in the form?
1766
+	 * @return boolean        True: can edit form. False: nope.
1767
+	 */
1768
+	private function user_can_edit_entry( $echo = false ) {
1890 1769
 
1891
-    /**
1892
-     * Is the current nonce valid for editing the entry?
1893
-     * @return boolean
1894
-     */
1895
-    public function verify_nonce() {
1770
+		$error = NULL;
1896 1771
 
1897
-        // Verify form submitted for editing single
1898
-        if( $this->is_edit_entry_submission() ) {
1899
-            $valid = wp_verify_nonce( $_POST[ self::$nonce_field ], self::$nonce_field );
1900
-        }
1772
+		/**
1773
+		 *  1. Permalinks are turned off
1774
+		 *  2. There are two entries embedded using oEmbed
1775
+		 *  3. One of the entries has just been saved
1776
+		 */
1777
+		if( !empty( $_POST['lid'] ) && !empty( $_GET['entry'] ) && ( $_POST['lid'] !== $_GET['entry'] ) ) {
1901 1778
 
1902
-        // Verify
1903
-        else if( ! $this->is_edit_entry() ) {
1904
-            $valid = false;
1905
-        }
1779
+			$error = true;
1906 1780
 
1907
-        else {
1908
-            $valid = wp_verify_nonce( $_GET['edit'], self::$nonce_key );
1909
-        }
1781
+		}
1910 1782
 
1911
-        /**
1912
-         * @filter `gravityview/edit_entry/verify_nonce` Override Edit Entry nonce validation. Return true to declare nonce valid.
1913
-         * @since 1.13
1914
-         * @param int|boolean $valid False if invalid; 1 or 2 when nonce was generated
1915
-         * @param string $nonce_field Key used when validating submissions. Default: is_gv_edit_entry
1916
-         */
1917
-        $valid = apply_filters( 'gravityview/edit_entry/verify_nonce', $valid, self::$nonce_field );
1783
+		if( !empty( $_GET['entry'] ) && (string)$this->entry['id'] !== $_GET['entry'] ) {
1918 1784
 
1919
-        return $valid;
1920
-    }
1785
+			$error = true;
1786
+
1787
+		} elseif( ! $this->verify_nonce() ) {
1788
+
1789
+			/**
1790
+			 * If the Entry is embedded, there may be two entries on the same page.
1791
+			 * If that's the case, and one is being edited, the other should fail gracefully and not display an error.
1792
+			 */
1793
+			if( GravityView_oEmbed::getInstance()->get_entry_id() ) {
1794
+				$error = true;
1795
+			} else {
1796
+				$error = __( 'The link to edit this entry is not valid; it may have expired.', 'gravityview');
1797
+			}
1798
+
1799
+		}
1800
+
1801
+		if( ! GravityView_Edit_Entry::check_user_cap_edit_entry( $this->entry ) ) {
1802
+			$error = __( 'You do not have permission to edit this entry.', 'gravityview');
1803
+		}
1804
+
1805
+		if( $this->entry['status'] === 'trash' ) {
1806
+			$error = __('You cannot edit the entry; it is in the trash.', 'gravityview' );
1807
+		}
1808
+
1809
+		// No errors; everything's fine here!
1810
+		if( empty( $error ) ) {
1811
+			return true;
1812
+		}
1813
+
1814
+		if( $echo && $error !== true ) {
1815
+
1816
+			$error = esc_html( $error );
1817
+
1818
+			/**
1819
+			 * @since 1.9
1820
+			 */
1821
+			if ( ! empty( $this->entry ) ) {
1822
+				$error .= ' ' . gravityview_get_link( '#', _x('Go back.', 'Link shown when invalid Edit Entry link is clicked', 'gravityview' ), array( 'onclick' => "window.history.go(-1); return false;" ) );
1823
+			}
1824
+
1825
+			echo GVCommon::generate_notice( wpautop( $error ), 'gv-error error');
1826
+		}
1827
+
1828
+		do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_entry]' . $error );
1829
+
1830
+		return false;
1831
+	}
1832
+
1833
+
1834
+	/**
1835
+	 * Check whether a field is editable by the current user, and optionally display an error message
1836
+	 * @uses  GravityView_Edit_Entry->check_user_cap_edit_field() Check user capabilities
1837
+	 * @param  array  $field Field or field settings array
1838
+	 * @param  boolean $echo  Whether to show error message telling user they aren't allowed
1839
+	 * @return boolean         True: user can edit the current field; False: nope, they can't.
1840
+	 */
1841
+	private function user_can_edit_field( $field, $echo = false ) {
1842
+
1843
+		$error = NULL;
1844
+
1845
+		if( ! $this->check_user_cap_edit_field( $field ) ) {
1846
+			$error = __( 'You do not have permission to edit this field.', 'gravityview');
1847
+		}
1848
+
1849
+		// No errors; everything's fine here!
1850
+		if( empty( $error ) ) {
1851
+			return true;
1852
+		}
1853
+
1854
+		if( $echo ) {
1855
+			echo GVCommon::generate_notice( wpautop( esc_html( $error ) ), 'gv-error error');
1856
+		}
1857
+
1858
+		do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_field]' . $error );
1859
+
1860
+		return false;
1861
+
1862
+	}
1863
+
1864
+
1865
+	/**
1866
+	 * checks if user has permissions to edit a specific field
1867
+	 *
1868
+	 * Needs to be used combined with GravityView_Edit_Entry::user_can_edit_field for maximum security!!
1869
+	 *
1870
+	 * @param  [type] $field [description]
1871
+	 * @return bool
1872
+	 */
1873
+	private function check_user_cap_edit_field( $field ) {
1874
+
1875
+		// If they can edit any entries (as defined in Gravity Forms), we're good.
1876
+		if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ) ) ) {
1877
+			return true;
1878
+		}
1879
+
1880
+		$field_cap = isset( $field['allow_edit_cap'] ) ? $field['allow_edit_cap'] : false;
1881
+
1882
+		// If the field has custom editing capaibilities set, check those
1883
+		if( $field_cap ) {
1884
+			return GVCommon::has_cap( $field['allow_edit_cap'] );
1885
+		}
1886
+
1887
+		return false;
1888
+	}
1889
+
1890
+
1891
+	/**
1892
+	 * Is the current nonce valid for editing the entry?
1893
+	 * @return boolean
1894
+	 */
1895
+	public function verify_nonce() {
1896
+
1897
+		// Verify form submitted for editing single
1898
+		if( $this->is_edit_entry_submission() ) {
1899
+			$valid = wp_verify_nonce( $_POST[ self::$nonce_field ], self::$nonce_field );
1900
+		}
1901
+
1902
+		// Verify
1903
+		else if( ! $this->is_edit_entry() ) {
1904
+			$valid = false;
1905
+		}
1906
+
1907
+		else {
1908
+			$valid = wp_verify_nonce( $_GET['edit'], self::$nonce_key );
1909
+		}
1910
+
1911
+		/**
1912
+		 * @filter `gravityview/edit_entry/verify_nonce` Override Edit Entry nonce validation. Return true to declare nonce valid.
1913
+		 * @since 1.13
1914
+		 * @param int|boolean $valid False if invalid; 1 or 2 when nonce was generated
1915
+		 * @param string $nonce_field Key used when validating submissions. Default: is_gv_edit_entry
1916
+		 */
1917
+		$valid = apply_filters( 'gravityview/edit_entry/verify_nonce', $valid, self::$nonce_field );
1918
+
1919
+		return $valid;
1920
+	}
1921 1921
 
1922 1922
 
1923 1923
 
Please login to merge, or discard this patch.
includes/fields/class-gravityview-field-uid.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@
 block discarded – undo
47 47
 	function edit_entry_fix_hidden_fields( $fields ) {
48 48
 
49 49
 		/** @var GF_Field $field */
50
-		foreach( $fields as &$field ) {
50
+		foreach ( $fields as &$field ) {
51 51
 			if ( 'hidden' === $field->type ) {
52 52
 
53 53
 				// Replace GF_Field_Hidden with GF_Field_Text, copying all the data from $field
Please login to merge, or discard this patch.