Completed
Push — develop ( ab6671...011f6a )
by
unknown
07:54
created
includes/class-data.php 2 patches
Spacing   +127 added lines, -127 removed lines patch added patch discarded remove patch
@@ -21,12 +21,12 @@  discard block
 block discarded – undo
21 21
 			gravityview()->request = gv_shim_new_GV_Dummy_Request();
22 22
 		}
23 23
 
24
-		if( !empty( $passed_post ) ) {
24
+		if ( ! empty( $passed_post ) ) {
25 25
 
26 26
 			$id_or_id_array = $this->maybe_get_view_id( $passed_post );
27 27
 
28 28
 			if ( defined( 'GRAVITYVIEW_FUTURE_CORE_LOADED' ) ) {
29
-				foreach( is_array( $id_or_id_array ) ? $id_or_id_array : array( $id_or_id_array ) as $view_id ) {
29
+				foreach ( is_array( $id_or_id_array ) ? $id_or_id_array : array( $id_or_id_array ) as $view_id ) {
30 30
 					if ( gv_shim_GV_View_exists( $view_id ) && ! gravityview()->views->contains( $view_id ) ) {
31 31
 						gravityview()->views->add( gv_shim_GV_View_by_id( $view_id ) );
32 32
 					}
@@ -73,24 +73,24 @@  discard block
 block discarded – undo
73 73
 	public function maybe_get_view_id( $passed_post ) {
74 74
 		$ids = array();
75 75
 
76
-		if( ! empty( $passed_post ) ) {
76
+		if ( ! empty( $passed_post ) ) {
77 77
 
78
-			if( is_numeric( $passed_post ) ) {
78
+			if ( is_numeric( $passed_post ) ) {
79 79
 				$passed_post = get_post( $passed_post );
80 80
 			}
81 81
 
82 82
 			// Convert WP_Posts into WP_Posts[] array
83
-			if( $passed_post instanceof WP_Post ) {
83
+			if ( $passed_post instanceof WP_Post ) {
84 84
 				$passed_post = array( $passed_post );
85 85
 			}
86 86
 
87
-			if( is_array( $passed_post ) ) {
87
+			if ( is_array( $passed_post ) ) {
88 88
 
89
-				foreach ( $passed_post as &$post) {
89
+				foreach ( $passed_post as &$post ) {
90 90
 					if ( defined( 'GRAVITYVIEW_FUTURE_CORE_LOADED' ) && $post instanceof WP_Post ) {
91 91
 						$views = gv_shim_GV_View_Collection_from_post( $post );
92 92
 						foreach ( $views->all() as $view ) {
93
-							$ids []= $view->ID;
93
+							$ids [ ] = $view->ID;
94 94
 
95 95
 							/** And as a side-effect... add each view to the global scope. */
96 96
 							if ( ! gravityview()->views->contains( $view->ID ) ) {
@@ -99,19 +99,19 @@  discard block
 block discarded – undo
99 99
 						}
100 100
 					} else {
101 101
 						/** Deprecated, see \GV\View_Collection::from_post */
102
-						if( ( get_post_type( $post ) === 'gravityview' ) ) {
103
-							$ids[] = $post->ID;
104
-						} else{
102
+						if ( ( get_post_type( $post ) === 'gravityview' ) ) {
103
+							$ids[ ] = $post->ID;
104
+						} else {
105 105
 							// Parse the Post Content
106 106
 							$id = $this->parse_post_content( $post->post_content );
107
-							if( $id ) {
108
-								$ids = array_merge( $ids, (array) $id );
107
+							if ( $id ) {
108
+								$ids = array_merge( $ids, (array)$id );
109 109
 							}
110 110
 
111 111
 							// Parse the Post Meta
112 112
 							$id = $this->parse_post_meta( $post->ID );
113
-							if( $id ) {
114
-								$ids = array_merge( $ids, (array) $id );
113
+							if ( $id ) {
114
+								$ids = array_merge( $ids, (array)$id );
115 115
 							}
116 116
 						}
117 117
 					}
@@ -125,37 +125,37 @@  discard block
 block discarded – undo
125 125
 					if ( defined( 'GRAVITYVIEW_FUTURE_CORE_LOADED' ) ) {
126 126
 						$shortcodes = gv_shim_GV_Shortcode_parse( $passed_post );
127 127
 						foreach ( $shortcodes as $shortcode ) {
128
-							if ( $shortcode->name == 'gravityview' && !empty( $shortcode->atts['id'] ) ) {
129
-								$ids []= $shortcode->atts['id'];
128
+							if ( $shortcode->name == 'gravityview' && ! empty( $shortcode->atts[ 'id' ] ) ) {
129
+								$ids [ ] = $shortcode->atts[ 'id' ];
130 130
 
131 131
 								/** And as a side-effect... add each view to the global scope. */
132
-								if ( ! gravityview()->views->contains( $shortcode->atts['id'] ) && gv_shim_GV_View_exists( $shortcode->atts['id'] ) ) {
133
-									gravityview()->views->add( $shortcode->atts['id'] );
132
+								if ( ! gravityview()->views->contains( $shortcode->atts[ 'id' ] ) && gv_shim_GV_View_exists( $shortcode->atts[ 'id' ] ) ) {
133
+									gravityview()->views->add( $shortcode->atts[ 'id' ] );
134 134
 								}
135 135
 							}
136 136
 						}
137 137
 					} else {
138 138
 						/** Deprecated, use \GV\Shortcode::parse. */
139 139
 						$id = $this->parse_post_content( $passed_post );
140
-						if( $id ) {
141
-							$ids = array_merge( $ids, (array) $id );
140
+						if ( $id ) {
141
+							$ids = array_merge( $ids, (array)$id );
142 142
 						}
143 143
 					}
144 144
 
145 145
 				} else {
146 146
 					$id = $this->get_id_from_atts( $passed_post );
147
-					$ids[] = intval( $id );
147
+					$ids[ ] = intval( $id );
148 148
 				}
149 149
 			}
150 150
 		}
151 151
 
152
-		if( empty($ids) ) {
152
+		if ( empty( $ids ) ) {
153 153
 			return NULL;
154 154
 		}
155 155
 
156 156
 		// If it's just one ID, return that.
157 157
 		// Otherwise, return array of IDs
158
-		return ( sizeof( $ids ) === 1 ) ? $ids[0] : $ids;
158
+		return ( sizeof( $ids ) === 1 ) ? $ids[ 0 ] : $ids;
159 159
 	}
160 160
 
161 161
 	/**
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
 	 */
164 164
 	public static function getInstance( $passed_post = NULL ) {
165 165
 
166
-		if( empty( self::$instance ) ) {
166
+		if ( empty( self::$instance ) ) {
167 167
 			self::$instance = new GravityView_View_Data( $passed_post );
168 168
 		}
169 169
 
@@ -208,19 +208,19 @@  discard block
 block discarded – undo
208 208
 			return $view->as_data();
209 209
 		}
210 210
 
211
-		if( ! is_numeric( $view_id) ) {
212
-			do_action('gravityview_log_error', sprintf('GravityView_View_Data[get_view] $view_id passed is not numeric.', $view_id) );
211
+		if ( ! is_numeric( $view_id ) ) {
212
+			do_action( 'gravityview_log_error', sprintf( 'GravityView_View_Data[get_view] $view_id passed is not numeric.', $view_id ) );
213 213
 			return false;
214 214
 		}
215 215
 
216 216
 		// Backup: the view hasn't been fetched yet. Doing it now.
217 217
 		if ( ! isset( $this->views[ $view_id ] ) ) {
218
-			do_action('gravityview_log_debug', sprintf('GravityView_View_Data[get_view] View #%s not set yet.', $view_id) );
218
+			do_action( 'gravityview_log_debug', sprintf( 'GravityView_View_Data[get_view] View #%s not set yet.', $view_id ) );
219 219
 			return $this->add_view( $view_id, $atts );
220 220
 		}
221 221
 
222 222
 		if ( empty( $this->views[ $view_id ] ) ) {
223
-			do_action('gravityview_log_debug', sprintf('GravityView_View_Data[get_view] Returning; View #%s was empty.', $view_id) );
223
+			do_action( 'gravityview_log_debug', sprintf( 'GravityView_View_Data[get_view] Returning; View #%s was empty.', $view_id ) );
224 224
 			return false;
225 225
 		}
226 226
 
@@ -265,8 +265,8 @@  discard block
 block discarded – undo
265 265
 		}
266 266
 
267 267
 		// Handle array of IDs
268
-		if( is_array( $view_id ) ) {
269
-			foreach( $view_id as $id ) {
268
+		if ( is_array( $view_id ) ) {
269
+			foreach ( $view_id as $id ) {
270 270
 
271 271
 				$this->add_view( $id, $atts );
272 272
 			}
@@ -275,21 +275,21 @@  discard block
 block discarded – undo
275 275
 		}
276 276
 
277 277
 		// The view has been set already; returning stored view.
278
-		if ( !empty( $this->views[ $view_id ] ) ) {
279
-			do_action('gravityview_log_debug', sprintf('GravityView_View_Data[add_view] Returning; View #%s already exists.', $view_id) );
278
+		if ( ! empty( $this->views[ $view_id ] ) ) {
279
+			do_action( 'gravityview_log_debug', sprintf( 'GravityView_View_Data[add_view] Returning; View #%s already exists.', $view_id ) );
280 280
 			return $this->views[ $view_id ];
281 281
 		}
282 282
 
283
-		if( ! $this->view_exists( $view_id ) ) {
284
-			do_action('gravityview_log_debug', sprintf('GravityView_View_Data[add_view] Returning; View #%s does not exist.', $view_id) );
283
+		if ( ! $this->view_exists( $view_id ) ) {
284
+			do_action( 'gravityview_log_debug', sprintf( 'GravityView_View_Data[add_view] Returning; View #%s does not exist.', $view_id ) );
285 285
 			return false;
286 286
 		}
287 287
 
288 288
 		$form_id = gravityview_get_form_id( $view_id );
289 289
 
290
-		if( empty( $form_id ) ) {
290
+		if ( empty( $form_id ) ) {
291 291
 
292
-			do_action('gravityview_log_debug', sprintf('GravityView_View_Data[add_view] Returning; Post ID #%s does not have a connected form.', $view_id) );
292
+			do_action( 'gravityview_log_debug', sprintf( 'GravityView_View_Data[add_view] Returning; Post ID #%s does not have a connected form.', $view_id ) );
293 293
 
294 294
 			return false;
295 295
 		}
@@ -297,21 +297,21 @@  discard block
 block discarded – undo
297 297
 		// Get the settings for the View ID
298 298
 		$view_settings = gravityview_get_template_settings( $view_id );
299 299
 
300
-		do_action('gravityview_log_debug', sprintf('GravityView_View_Data[add_view] Settings pulled in from View #%s', $view_id), $view_settings );
300
+		do_action( 'gravityview_log_debug', sprintf( 'GravityView_View_Data[add_view] Settings pulled in from View #%s', $view_id ), $view_settings );
301 301
 
302 302
 		// Merge the view settings with the defaults
303 303
 		$view_defaults = wp_parse_args( $view_settings, defined( 'GRAVITYVIEW_FUTURE_CORE_LOADED' ) ? gv_shim_GV_View_Settings_defaults() : self::get_default_args() );
304 304
 
305
-		do_action('gravityview_log_debug', 'GravityView_View_Data[add_view] View Defaults after merging View Settings with the default args.', $view_defaults );
305
+		do_action( 'gravityview_log_debug', 'GravityView_View_Data[add_view] View Defaults after merging View Settings with the default args.', $view_defaults );
306 306
 
307
-		if( ! empty( $atts ) && is_array( $atts ) ) {
307
+		if ( ! empty( $atts ) && is_array( $atts ) ) {
308 308
 
309
-			do_action('gravityview_log_debug', 'GravityView_View_Data[add_view] $atts before merging  with the $view_defaults', $atts );
309
+			do_action( 'gravityview_log_debug', 'GravityView_View_Data[add_view] $atts before merging  with the $view_defaults', $atts );
310 310
 
311 311
 			// Get the settings from the shortcode and merge them with defaults.
312 312
 			$atts = shortcode_atts( $view_defaults, $atts );
313 313
 
314
-			do_action('gravityview_log_debug', 'GravityView_View_Data[add_view] $atts after merging  with the $view_defaults', $atts );
314
+			do_action( 'gravityview_log_debug', 'GravityView_View_Data[add_view] $atts after merging  with the $view_defaults', $atts );
315 315
 
316 316
 		} else {
317 317
 
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
 
321 321
 		}
322 322
 
323
-		unset( $atts['id'], $view_defaults, $view_settings );
323
+		unset( $atts[ 'id' ], $view_defaults, $view_settings );
324 324
 
325 325
 		$data = array(
326 326
 			'id' => $view_id,
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
 			'form' => gravityview_get_form( $form_id ),
334 334
 		);
335 335
 
336
-		do_action('gravityview_log_debug', sprintf('GravityView_View_Data[add_view] View #%s being added.', $view_id), $data );
336
+		do_action( 'gravityview_log_debug', sprintf( 'GravityView_View_Data[add_view] View #%s being added.', $view_id ), $data );
337 337
 
338 338
 		$this->views[ $view_id ] = $data;
339 339
 
@@ -383,15 +383,15 @@  discard block
 block discarded – undo
383 383
 			throw new Exception( __METHOD__ . ' should not be called anymore. Why was it?' );
384 384
 		}
385 385
 
386
-		if( empty( $dir_fields ) || !is_array( $dir_fields ) ) {
386
+		if ( empty( $dir_fields ) || ! is_array( $dir_fields ) ) {
387 387
 			return $dir_fields;
388 388
 		}
389 389
 
390
-		foreach( $dir_fields as $area => $fields ) {
390
+		foreach ( $dir_fields as $area => $fields ) {
391 391
 
392
-			foreach( (array)$fields as $uniqid => $properties ) {
392
+			foreach ( (array)$fields as $uniqid => $properties ) {
393 393
 
394
-				if( $this->hide_field_check_conditions( $properties ) ) {
394
+				if ( $this->hide_field_check_conditions( $properties ) ) {
395 395
 					unset( $dir_fields[ $area ][ $uniqid ] );
396 396
 				}
397 397
 
@@ -418,7 +418,7 @@  discard block
 block discarded – undo
418 418
 		}
419 419
 
420 420
 		// logged-in visibility
421
-		if( ! empty( $properties['only_loggedin'] ) && ! GVCommon::has_cap( $properties['only_loggedin_cap'] ) ) {
421
+		if ( ! empty( $properties[ 'only_loggedin' ] ) && ! GVCommon::has_cap( $properties[ 'only_loggedin_cap' ] ) ) {
422 422
 			return true;
423 423
 		}
424 424
 
@@ -449,14 +449,14 @@  discard block
 block discarded – undo
449 449
 		// Get the settings from the shortcode and merge them with defaults.
450 450
 		$atts = wp_parse_args( $atts, defined( 'GRAVITYVIEW_FUTURE_CORE_LOADED' ) ? gv_shim_GV_View_Settings_defaults() : self::get_default_args() );
451 451
 
452
-		$view_id = ! empty( $atts['view_id'] ) ? (int)$atts['view_id'] : NULL;
452
+		$view_id = ! empty( $atts[ 'view_id' ] ) ? (int)$atts[ 'view_id' ] : NULL;
453 453
 
454
-		if( empty( $view_id ) && !empty( $atts['id'] ) ) {
455
-			$view_id = (int)$atts['id'];
454
+		if ( empty( $view_id ) && ! empty( $atts[ 'id' ] ) ) {
455
+			$view_id = (int)$atts[ 'id' ];
456 456
 		}
457 457
 
458
-		if( empty( $view_id ) ) {
459
-			do_action('gravityview_log_error', 'GravityView_View_Data[get_id_from_atts] Returning; no ID defined (Atts)', $atts );
458
+		if ( empty( $view_id ) ) {
459
+			do_action( 'gravityview_log_error', 'GravityView_View_Data[get_id_from_atts] Returning; no ID defined (Atts)', $atts );
460 460
 			return;
461 461
 		}
462 462
 
@@ -480,68 +480,68 @@  discard block
 block discarded – undo
480 480
 		if ( defined( 'GRAVITYVIEW_FUTURE_CORE_LOADED' ) ) {
481 481
 			$ids = array();
482 482
 			foreach ( gv_shim_GV_Shortcode_parse( $content ) as $shortcode ) {
483
-				if ( $shortcode->name == 'gravityview' && is_numeric( $shortcode->atts['id'] ) ) {
484
-					if ( gv_shim_GV_View_exists( $shortcode->atts['id'] ) && ! gravityview()->views->contains( $shortcode->atts['id'] ) ) {
485
-						gravityview()->views->add( gv_shim_GV_View_by_id( $shortcode->atts['id'] ) );
483
+				if ( $shortcode->name == 'gravityview' && is_numeric( $shortcode->atts[ 'id' ] ) ) {
484
+					if ( gv_shim_GV_View_exists( $shortcode->atts[ 'id' ] ) && ! gravityview()->views->contains( $shortcode->atts[ 'id' ] ) ) {
485
+						gravityview()->views->add( gv_shim_GV_View_by_id( $shortcode->atts[ 'id' ] ) );
486 486
 					}
487 487
 					/**
488 488
 					 * The original function outputs the ID even though it wasn't added by ::add_view()
489 489
 					 * Wether this is a bug or not remains a mystery. But we need to emulate this behavior
490 490
 					 * until better times.
491 491
 					 */
492
-					$ids []= $shortcode->atts['id'];
492
+					$ids [ ] = $shortcode->atts[ 'id' ];
493 493
 				}
494 494
 			}
495 495
 			if ( empty ( $ids ) ) {
496 496
 				return null;
497 497
 			}
498
-			return ( sizeof( $ids ) === 1 ) ? $ids[0] : $ids;
498
+			return ( sizeof( $ids ) === 1 ) ? $ids[ 0 ] : $ids;
499 499
 		}
500 500
 
501 501
 		/**
502 502
 		 * @hack This is so that the shortcode is registered for the oEmbed preview in the Admin
503 503
 		 * @since 1.6
504 504
 		 */
505
-		if( ! shortcode_exists('gravityview') && class_exists( 'GravityView_Shortcode' ) ) {
505
+		if ( ! shortcode_exists( 'gravityview' ) && class_exists( 'GravityView_Shortcode' ) ) {
506 506
 			new GravityView_Shortcode;
507 507
 		}
508 508
 
509 509
 		$shortcodes = gravityview_has_shortcode_r( $content, 'gravityview' );
510 510
 
511
-		if( empty( $shortcodes ) ) {
511
+		if ( empty( $shortcodes ) ) {
512 512
 			return NULL;
513 513
 		}
514 514
 
515
-		do_action('gravityview_log_debug', 'GravityView_View_Data[parse_post_content] Parsing content, found shortcodes:', $shortcodes );
515
+		do_action( 'gravityview_log_debug', 'GravityView_View_Data[parse_post_content] Parsing content, found shortcodes:', $shortcodes );
516 516
 
517 517
 		$ids = array();
518 518
 
519
-		foreach ($shortcodes as $key => $shortcode) {
519
+		foreach ( $shortcodes as $key => $shortcode ) {
520 520
 
521
-			$shortcode[3] = htmlspecialchars_decode( $shortcode[3], ENT_QUOTES );
521
+			$shortcode[ 3 ] = htmlspecialchars_decode( $shortcode[ 3 ], ENT_QUOTES );
522 522
 
523
-			$args = shortcode_parse_atts( $shortcode[3] );
523
+			$args = shortcode_parse_atts( $shortcode[ 3 ] );
524 524
 
525
-			if( empty( $args['id'] ) ) {
526
-				do_action('gravityview_log_error', 'GravityView_View_Data[parse_post_content] Returning; no ID defined in shortcode atts', $shortcode );
525
+			if ( empty( $args[ 'id' ] ) ) {
526
+				do_action( 'gravityview_log_error', 'GravityView_View_Data[parse_post_content] Returning; no ID defined in shortcode atts', $shortcode );
527 527
 				continue;
528 528
 			}
529 529
 
530
-			do_action('gravityview_log_debug', sprintf('GravityView_View_Data[parse_post_content] Adding view #%s with shortcode args', $args['id']), $args );
530
+			do_action( 'gravityview_log_debug', sprintf( 'GravityView_View_Data[parse_post_content] Adding view #%s with shortcode args', $args[ 'id' ] ), $args );
531 531
 
532 532
 			// Store the View to the object for later fetching.
533
-			$this->add_view( $args['id'], $args );
533
+			$this->add_view( $args[ 'id' ], $args );
534 534
 
535
-			$ids[] = $args['id'];
535
+			$ids[ ] = $args[ 'id' ];
536 536
 		}
537 537
 
538
-		if( empty($ids) ) {
538
+		if ( empty( $ids ) ) {
539 539
 			return NULL;
540 540
 		}
541 541
 
542 542
 		// If it's just one ID, return that.
543 543
 		// Otherwise, return array of IDs
544
-		return ( sizeof( $ids ) === 1 ) ? $ids[0] : $ids;
544
+		return ( sizeof( $ids ) === 1 ) ? $ids[ 0 ] : $ids;
545 545
 
546 546
 	}
547 547
 
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
 		 */
571 571
 		$meta_keys = (array)apply_filters( 'gravityview/data/parse/meta_keys', array(), $post_id );
572 572
 
573
-		if( empty( $meta_keys ) ) {
573
+		if ( empty( $meta_keys ) ) {
574 574
 			return NULL;
575 575
 		}
576 576
 
@@ -578,16 +578,16 @@  discard block
 block discarded – undo
578 578
 
579 579
 		$meta_content = '';
580 580
 
581
-		foreach( $meta_keys as $key ) {
582
-			$meta = get_post_meta( $post_id, $key , true );
583
-			if( ! is_string( $meta ) ) {
581
+		foreach ( $meta_keys as $key ) {
582
+			$meta = get_post_meta( $post_id, $key, true );
583
+			if ( ! is_string( $meta ) ) {
584 584
 				continue;
585 585
 			}
586 586
 			$meta_content .= $meta . ' ';
587 587
 		}
588 588
 
589
-		if( empty( $meta_content ) ) {
590
-			do_action('gravityview_log_error', sprintf( 'GravityView_View_Data[parse_post_meta] Returning; Empty custom fields for Post #%s (Custom fields keys:)', $post_id ), $meta_keys );
589
+		if ( empty( $meta_content ) ) {
590
+			do_action( 'gravityview_log_error', sprintf( 'GravityView_View_Data[parse_post_meta] Returning; Empty custom fields for Post #%s (Custom fields keys:)', $post_id ), $meta_keys );
591 591
 			return NULL;
592 592
 		}
593 593
 
@@ -615,16 +615,16 @@  discard block
 block discarded – undo
615 615
 		$message = NULL;
616 616
 
617 617
 		// Not invalid if not set!
618
-		if( empty( $post_id ) || empty( $view_id ) ) {
618
+		if ( empty( $post_id ) || empty( $view_id ) ) {
619 619
 
620
-			if( $empty_is_valid ) {
620
+			if ( $empty_is_valid ) {
621 621
 				return true;
622 622
 			}
623 623
 
624 624
 			$message = esc_html__( 'The ID is required.', 'gravityview' );
625 625
 		}
626 626
 
627
-		if( ! $message ) {
627
+		if ( ! $message ) {
628 628
 			$status = get_post_status( $post_id );
629 629
 
630 630
 			// Nothing exists with that post ID.
@@ -636,7 +636,7 @@  discard block
 block discarded – undo
636 636
 			}
637 637
 		}
638 638
 
639
-		if( ! $message ) {
639
+		if ( ! $message ) {
640 640
 
641 641
 			// Nothing exists with that post ID.
642 642
 			if ( empty( $status ) || in_array( $status, array( 'revision', 'attachment' ) ) ) {
@@ -645,8 +645,8 @@  discard block
 block discarded – undo
645 645
 
646 646
 		}
647 647
 
648
-		if( ! $message ) {
649
-			if ( defined( 'GRAVITYVIEW_FUTURE_CORE_LOADED' ) && $post = get_post( $post_id ) )  {
648
+		if ( ! $message ) {
649
+			if ( defined( 'GRAVITYVIEW_FUTURE_CORE_LOADED' ) && $post = get_post( $post_id ) ) {
650 650
 				$views = gv_shim_GV_View_Collection_from_post( $post );
651 651
 				$view_ids_in_post = array_map( 'gv_shim_view_ID_getter', $views->all() );
652 652
 			} else {
@@ -655,21 +655,21 @@  discard block
 block discarded – undo
655 655
 			}
656 656
 
657 657
 			// The post or page specified does not contain the shortcode.
658
-			if ( false === in_array( $view_id, (array) $view_ids_in_post ) ) {
658
+			if ( false === in_array( $view_id, (array)$view_ids_in_post ) ) {
659 659
 				$message = sprintf( esc_html__( 'The Post ID entered is not valid. You may have entered a post or page that does not contain the selected View. Make sure the post contains the following shortcode: %s', 'gravityview' ), '<br /><code>[gravityview id="' . intval( $view_id ) . '"]</code>' );
660 660
 			}
661 661
 		}
662 662
 
663
-		if( ! $message ) {
663
+		if ( ! $message ) {
664 664
 
665 665
 			// It's a View
666 666
 			if ( ( defined( 'GRAVITYVIEW_FUTURE_CORE_LOADED' ) && gv_shim_GV_View_exists( $post_id ) )
667 667
 				|| 'gravityview' === get_post_type( $post_id ) ) {
668
-				$message = esc_html__( 'The ID is already a View.', 'gravityview' );;
668
+				$message = esc_html__( 'The ID is already a View.', 'gravityview' ); ;
669 669
 			}
670 670
 		}
671 671
 
672
-		if( $message ) {
672
+		if ( $message ) {
673 673
 			return new WP_Error( 'invalid_embed_id', $message );
674 674
 		}
675 675
 
@@ -686,7 +686,7 @@  discard block
 block discarded – undo
686 686
 
687 687
 		$args = defined( 'GRAVITYVIEW_FUTURE_CORE_LOADED' ) ? gv_shim_GV_View_Settings_defaults( $with_details ) : self::get_default_args( $with_details );
688 688
 
689
-		if( !isset( $args[ $key ] ) ) { return NULL; }
689
+		if ( ! isset( $args[ $key ] ) ) { return NULL; }
690 690
 
691 691
 		return $args[ $key ];
692 692
 	}
@@ -723,7 +723,7 @@  discard block
 block discarded – undo
723 723
 		 */
724 724
 		$default_settings = apply_filters( 'gravityview_default_args', array(
725 725
 			'id' => array(
726
-				'label' => __('View ID', 'gravityview'),
726
+				'label' => __( 'View ID', 'gravityview' ),
727 727
 				'type' => 'number',
728 728
 				'group'	=> 'default',
729 729
 				'value' => NULL,
@@ -731,7 +731,7 @@  discard block
 block discarded – undo
731 731
 				'show_in_shortcode' => false,
732 732
 			),
733 733
 			'page_size' => array(
734
-				'label' 	=> __('Number of entries per page', 'gravityview'),
734
+				'label' 	=> __( 'Number of entries per page', 'gravityview' ),
735 735
 				'type' => 'number',
736 736
 				'class'	=> 'small-text',
737 737
 				'group'	=> 'default',
@@ -739,7 +739,7 @@  discard block
 block discarded – undo
739 739
 				'show_in_shortcode' => true,
740 740
 			),
741 741
 			'offset' => array(
742
-				'label' 	=> __('Offset entries starting from', 'gravityview'),
742
+				'label' 	=> __( 'Offset entries starting from', 'gravityview' ),
743 743
 				'type' => 'number',
744 744
 				'class'	=> 'small-text',
745 745
 				'group'	=> 'default',
@@ -763,8 +763,8 @@  discard block
 block discarded – undo
763 763
 			),
764 764
 			'admin_show_all_statuses' => array(
765 765
 				'label' => __( 'Show all entries to administrators', 'gravityview' ),
766
-				'desc'	=> __('Administrators will be able to see entries with any approval status.', 'gravityview'),
767
-				'tooltip' => __('Logged-out visitors and non-administrators will only see approved entries, while administrators will see entries with all statuses. This makes it easier for administrators to moderate entries from a View.', 'gravityview'),
766
+				'desc'	=> __( 'Administrators will be able to see entries with any approval status.', 'gravityview' ),
767
+				'tooltip' => __( 'Logged-out visitors and non-administrators will only see approved entries, while administrators will see entries with all statuses. This makes it easier for administrators to moderate entries from a View.', 'gravityview' ),
768 768
 				'requires' => 'show_only_approved',
769 769
 				'type' => 'checkbox',
770 770
 				'group'	=> 'default',
@@ -789,40 +789,40 @@  discard block
 block discarded – undo
789 789
 			'user_edit' => array(
790 790
 				'label'	=> __( 'Allow User Edit', 'gravityview' ),
791 791
 				'group'	=> 'default',
792
-				'desc'	=> __('Allow logged-in users to edit entries they created.', 'gravityview'),
792
+				'desc'	=> __( 'Allow logged-in users to edit entries they created.', 'gravityview' ),
793 793
 				'value'	=> 0,
794
-				'tooltip' => __('Display "Edit Entry" fields to non-administrator users if they created the entry. Edit Entry fields will always be displayed to site administrators.', 'gravityview'),
794
+				'tooltip' => __( 'Display "Edit Entry" fields to non-administrator users if they created the entry. Edit Entry fields will always be displayed to site administrators.', 'gravityview' ),
795 795
 				'type'	=> 'checkbox',
796 796
 				'show_in_shortcode' => true,
797 797
 			),
798 798
 			'user_delete' => array(
799 799
 				'label'	=> __( 'Allow User Delete', 'gravityview' ),
800 800
 				'group'	=> 'default',
801
-				'desc'	=> __('Allow logged-in users to delete entries they created.', 'gravityview'),
801
+				'desc'	=> __( 'Allow logged-in users to delete entries they created.', 'gravityview' ),
802 802
 				'value'	=> 0,
803
-				'tooltip' => __('Display "Delete Entry" fields to non-administrator users if they created the entry. Delete Entry fields will always be displayed to site administrators.', 'gravityview'),
803
+				'tooltip' => __( 'Display "Delete Entry" fields to non-administrator users if they created the entry. Delete Entry fields will always be displayed to site administrators.', 'gravityview' ),
804 804
 				'type'	=> 'checkbox',
805 805
 				'show_in_shortcode' => true,
806 806
 			),
807 807
 			'sort_field' => array(
808
-				'label'	=> __('Sort by field', 'gravityview'),
808
+				'label'	=> __( 'Sort by field', 'gravityview' ),
809 809
 				'type' => 'select',
810 810
 				'value' => '',
811 811
 				'group'	=> 'sort',
812 812
 				'options' => array(
813
-					'' => __( 'Default', 'gravityview'),
814
-					'date_created' => __( 'Date Created', 'gravityview'),
813
+					'' => __( 'Default', 'gravityview' ),
814
+					'date_created' => __( 'Date Created', 'gravityview' ),
815 815
 				),
816 816
 				'show_in_shortcode' => true,
817 817
 			),
818 818
 			'sort_direction' => array(
819
-				'label' 	=> __('Sort direction', 'gravityview'),
819
+				'label' 	=> __( 'Sort direction', 'gravityview' ),
820 820
 				'type' => 'select',
821 821
 				'value' => 'ASC',
822 822
 				'group'	=> 'sort',
823 823
 				'options' => array(
824
-					'ASC' => __('ASC', 'gravityview'),
825
-					'DESC' => __('DESC', 'gravityview'),
824
+					'ASC' => __( 'ASC', 'gravityview' ),
825
+					'DESC' => __( 'DESC', 'gravityview' ),
826 826
 					//'RAND' => __('Random', 'gravityview'),
827 827
 				),
828 828
 				'show_in_shortcode' => true,
@@ -838,69 +838,69 @@  discard block
 block discarded – undo
838 838
 				'show_in_template' => array( 'default_table', 'preset_business_data', 'preset_issue_tracker', 'preset_resume_board', 'preset_job_board' ),
839 839
 			),
840 840
 			'start_date' => array(
841
-				'label' 	=> __('Filter by Start Date', 'gravityview'),
841
+				'label' 	=> __( 'Filter by Start Date', 'gravityview' ),
842 842
 				'class'	=> 'gv-datepicker',
843
-				'desc'	=> __('Show entries submitted after this date. Supports relative dates, such as "-1 week" or "-1 month".', 'gravityview' ),
843
+				'desc'	=> __( 'Show entries submitted after this date. Supports relative dates, such as "-1 week" or "-1 month".', 'gravityview' ),
844 844
 				'type' => 'text',
845 845
 				'value' => '',
846 846
 				'group'	=> 'filter',
847 847
 				'show_in_shortcode' => true,
848 848
 			),
849 849
 			'end_date' => array(
850
-				'label' 	=> __('Filter by End Date', 'gravityview'),
850
+				'label' 	=> __( 'Filter by End Date', 'gravityview' ),
851 851
 				'class'	=> 'gv-datepicker',
852
-				'desc'	=> __('Show entries submitted before this date. Supports relative dates, such as "now" or "-3 days".', 'gravityview' ),
852
+				'desc'	=> __( 'Show entries submitted before this date. Supports relative dates, such as "now" or "-3 days".', 'gravityview' ),
853 853
 				'type' => 'text',
854 854
 				'value' => '',
855 855
 				'group'	=> 'filter',
856 856
 				'show_in_shortcode' => true,
857 857
 			),
858 858
 			'class' => array(
859
-				'label' 	=> __('CSS Class', 'gravityview'),
860
-				'desc'	=> __('CSS class to add to the wrapping HTML container.', 'gravityview'),
859
+				'label' 	=> __( 'CSS Class', 'gravityview' ),
860
+				'desc'	=> __( 'CSS class to add to the wrapping HTML container.', 'gravityview' ),
861 861
 				'group'	=> 'default',
862 862
 				'type' => 'text',
863 863
 				'value' => '',
864 864
 				'show_in_shortcode' => false,
865 865
 			),
866 866
 			'search_value' => array(
867
-				'label' 	=> __('Search Value', 'gravityview'),
868
-				'desc'	=> __('Define a default search value for the View', 'gravityview'),
867
+				'label' 	=> __( 'Search Value', 'gravityview' ),
868
+				'desc'	=> __( 'Define a default search value for the View', 'gravityview' ),
869 869
 				'type' => 'text',
870 870
 				'value' => '',
871 871
 				'group'	=> 'filter',
872 872
 				'show_in_shortcode' => false,
873 873
 			),
874 874
 			'search_field' => array(
875
-				'label' 	=> __('Search Field', 'gravityview'),
876
-				'desc'	=> __('If Search Value is set, you can define a specific field to search in. Otherwise, all fields will be searched.', 'gravityview'),
875
+				'label' 	=> __( 'Search Field', 'gravityview' ),
876
+				'desc'	=> __( 'If Search Value is set, you can define a specific field to search in. Otherwise, all fields will be searched.', 'gravityview' ),
877 877
 				'type' => 'number',
878 878
 				'value' => '',
879 879
 				'group'	=> 'filter',
880 880
 				'show_in_shortcode' => false,
881 881
 			),
882 882
 			'single_title' => array(
883
-				'label'	=> __('Single Entry Title', 'gravityview'),
883
+				'label'	=> __( 'Single Entry Title', 'gravityview' ),
884 884
 				'type'	=> 'text',
885
-				'desc'	=> __('When viewing a single entry, change the title of the page to this setting. Otherwise, the title will not change between the Multiple Entries and Single Entry views.', 'gravityview'),
885
+				'desc'	=> __( 'When viewing a single entry, change the title of the page to this setting. Otherwise, the title will not change between the Multiple Entries and Single Entry views.', 'gravityview' ),
886 886
 				'group'	=> 'default',
887 887
 				'value'	=> '',
888 888
 				'show_in_shortcode' => false,
889 889
 				'full_width' => true,
890 890
 			),
891 891
 			'back_link_label' => array(
892
-				'label'	=> __('Back Link Label', 'gravityview'),
892
+				'label'	=> __( 'Back Link Label', 'gravityview' ),
893 893
 				'group'	=> 'default',
894
-				'desc'	=> __('The text of the link that returns to the multiple entries view.', 'gravityview'),
894
+				'desc'	=> __( 'The text of the link that returns to the multiple entries view.', 'gravityview' ),
895 895
 				'type'	=> 'text',
896 896
 				'value'	=> '',
897 897
 				'show_in_shortcode' => false,
898 898
 				'full_width' => true,
899 899
 			),
900 900
 			'embed_only' => array(
901
-				'label'	=> __('Prevent Direct Access', 'gravityview'),
901
+				'label'	=> __( 'Prevent Direct Access', 'gravityview' ),
902 902
 				'group'	=> 'default',
903
-				'desc'	=> __('Only allow access to this View when embedded using the shortcode.', 'gravityview'),
903
+				'desc'	=> __( 'Only allow access to this View when embedded using the shortcode.', 'gravityview' ),
904 904
 				'type'	=> 'checkbox',
905 905
 				'value'	=> '',
906 906
 				'show_in_shortcode' => false,
@@ -911,15 +911,15 @@  discard block
 block discarded – undo
911 911
 				'value' => '',
912 912
 				'show_in_shortcode' => false,
913 913
 			),
914
-		));
914
+		) );
915 915
 
916 916
 		// By default, we only want the key => value pairing, not the whole array.
917
-		if( empty( $with_details ) ) {
917
+		if ( empty( $with_details ) ) {
918 918
 
919 919
 			$defaults = array();
920 920
 
921
-			foreach( $default_settings as $key => $value ) {
922
-				$defaults[ $key ] = $value['value'];
921
+			foreach ( $default_settings as $key => $value ) {
922
+				$defaults[ $key ] = $value[ 'value' ];
923 923
 			}
924 924
 
925 925
 			return $defaults;
@@ -928,12 +928,12 @@  discard block
 block discarded – undo
928 928
 		// But sometimes, we want all the details.
929 929
 		else {
930 930
 
931
-			foreach ($default_settings as $key => $value) {
931
+			foreach ( $default_settings as $key => $value ) {
932 932
 
933 933
 				// If the $group argument is set for the method,
934 934
 				// ignore any settings that aren't in that group.
935
-				if( !empty( $group ) && is_string( $group ) ) {
936
-					if( empty( $value['group'] ) || $value['group'] !== $group ) {
935
+				if ( ! empty( $group ) && is_string( $group ) ) {
936
+					if ( empty( $value[ 'group' ] ) || $value[ 'group' ] !== $group ) {
937 937
 						unset( $default_settings[ $key ] );
938 938
 					}
939 939
 				}
Please login to merge, or discard this patch.
Braces   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 						/** Deprecated, see \GV\View_Collection::from_post */
102 102
 						if( ( get_post_type( $post ) === 'gravityview' ) ) {
103 103
 							$ids[] = $post->ID;
104
-						} else{
104
+						} else {
105 105
 							// Parse the Post Content
106 106
 							$id = $this->parse_post_content( $post->post_content );
107 107
 							if( $id ) {
@@ -646,7 +646,7 @@  discard block
 block discarded – undo
646 646
 		}
647 647
 
648 648
 		if( ! $message ) {
649
-			if ( defined( 'GRAVITYVIEW_FUTURE_CORE_LOADED' ) && $post = get_post( $post_id ) )  {
649
+			if ( defined( 'GRAVITYVIEW_FUTURE_CORE_LOADED' ) && $post = get_post( $post_id ) ) {
650 650
 				$views = gv_shim_GV_View_Collection_from_post( $post );
651 651
 				$view_ids_in_post = array_map( 'gv_shim_view_ID_getter', $views->all() );
652 652
 			} else {
Please login to merge, or discard this patch.
includes/class-frontend-views.php 1 patch
Spacing   +113 added lines, -113 removed lines patch added patch discarded remove patch
@@ -85,9 +85,9 @@  discard block
 block discarded – undo
85 85
 	private function __construct() {}
86 86
 
87 87
 	private function initialize() {
88
-		add_action( 'wp', array( $this, 'parse_content'), 11 );
88
+		add_action( 'wp', array( $this, 'parse_content' ), 11 );
89 89
 		add_filter( 'parse_query', array( $this, 'parse_query_fix_frontpage' ), 10 );
90
-		add_action( 'template_redirect', array( $this, 'set_entry_data'), 1 );
90
+		add_action( 'template_redirect', array( $this, 'set_entry_data' ), 1 );
91 91
 
92 92
 		// Enqueue scripts and styles after GravityView_Template::register_styles()
93 93
 		add_action( 'wp_enqueue_scripts', array( $this, 'add_scripts_and_styles' ), 20 );
@@ -237,12 +237,12 @@  discard block
 block discarded – undo
237 237
 
238 238
 			$this->context_view_id = $view_id;
239 239
 
240
-		} elseif ( isset( $_GET['gvid'] ) && $multiple_views ) {
240
+		} elseif ( isset( $_GET[ 'gvid' ] ) && $multiple_views ) {
241 241
 			/**
242 242
 			 * used on a has_multiple_views context
243 243
 			 * @see GravityView_API::entry_link
244 244
 			 */
245
-			$this->context_view_id = $_GET['gvid'];
245
+			$this->context_view_id = $_GET[ 'gvid' ];
246 246
 
247 247
 		} elseif ( ! $multiple_views ) {
248 248
 			if ( defined( 'GRAVITYVIEW_FUTURE_CORE_LOADED' ) ) {
@@ -285,24 +285,24 @@  discard block
 block discarded – undo
285 285
 		global $wp_rewrite;
286 286
 
287 287
 		$is_front_page = ( $query->is_home || $query->is_page );
288
-		$show_on_front = ( 'page' === get_option('show_on_front') );
289
-		$front_page_id = get_option('page_on_front');
288
+		$show_on_front = ( 'page' === get_option( 'show_on_front' ) );
289
+		$front_page_id = get_option( 'page_on_front' );
290 290
 
291
-		if (  $is_front_page && $show_on_front && $front_page_id ) {
291
+		if ( $is_front_page && $show_on_front && $front_page_id ) {
292 292
 
293 293
 			// Force to be an array, potentially a query string ( entry=16 )
294 294
 			$_query = wp_parse_args( $query->query );
295 295
 
296 296
 			// pagename can be set and empty depending on matched rewrite rules. Ignore an empty pagename.
297
-			if ( isset( $_query['pagename'] ) && '' === $_query['pagename'] ) {
298
-				unset( $_query['pagename'] );
297
+			if ( isset( $_query[ 'pagename' ] ) && '' === $_query[ 'pagename' ] ) {
298
+				unset( $_query[ 'pagename' ] );
299 299
 			}
300 300
 
301 301
 			// this is where will break from core wordpress
302 302
 			$ignore = array( 'preview', 'page', 'paged', 'cpage' );
303 303
 			$endpoints = rgobj( $wp_rewrite, 'endpoints' );
304
-			foreach ( (array) $endpoints as $endpoint ) {
305
-				$ignore[] = $endpoint[1];
304
+			foreach ( (array)$endpoints as $endpoint ) {
305
+				$ignore[ ] = $endpoint[ 1 ];
306 306
 			}
307 307
 			unset( $endpoints );
308 308
 
@@ -312,21 +312,21 @@  discard block
 block discarded – undo
312 312
 			// - The query includes keys that are associated with registered endpoints. `entry`, for example.
313 313
 			if ( empty( $_query ) || ! array_diff( array_keys( $_query ), $ignore ) ) {
314 314
 
315
-				$qv =& $query->query_vars;
315
+				$qv = & $query->query_vars;
316 316
 
317 317
 				// Prevent redirect when on the single entry endpoint
318
-				if( self::is_single_entry() ) {
318
+				if ( self::is_single_entry() ) {
319 319
 					add_filter( 'redirect_canonical', '__return_false' );
320 320
 				}
321 321
 
322 322
 				$query->is_page = true;
323 323
 				$query->is_home = false;
324
-				$qv['page_id']  = $front_page_id;
324
+				$qv[ 'page_id' ]  = $front_page_id;
325 325
 
326 326
 				// Correct <!--nextpage--> for page_on_front
327
-				if ( ! empty( $qv['paged'] ) ) {
328
-					$qv['page'] = $qv['paged'];
329
-					unset( $qv['paged'] );
327
+				if ( ! empty( $qv[ 'paged' ] ) ) {
328
+					$qv[ 'page' ] = $qv[ 'paged' ];
329
+					unset( $qv[ 'paged' ] );
330 330
 				}
331 331
 			}
332 332
 
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
 
360 360
 		$this->setIsGravityviewPostType( get_post_type( $post ) === 'gravityview' );
361 361
 
362
-		$post_id = $this->getPostId() ? $this->getPostId() : (isset( $post ) ? $post->ID : null );
362
+		$post_id = $this->getPostId() ? $this->getPostId() : ( isset( $post ) ? $post->ID : null );
363 363
 		$this->setPostId( $post_id );
364 364
 		$post_has_shortcode = ! empty( $post->post_content ) ? gravityview_has_shortcode_r( $post->post_content, 'gravityview' ) : false;
365 365
 		$this->setPostHasShortcode( $this->isGravityviewPostType() ? null : ! empty( $post_has_shortcode ) );
@@ -395,7 +395,7 @@  discard block
 block discarded – undo
395 395
 
396 396
 		$search_method = GravityView_Widget_Search::getInstance()->get_search_method();
397 397
 
398
-		if( 'post' === $search_method ) {
398
+		if ( 'post' === $search_method ) {
399 399
 			$get = $_POST;
400 400
 		} else {
401 401
 			$get = $_GET;
@@ -451,20 +451,20 @@  discard block
 block discarded – undo
451 451
 		 * @param boolean $in_the_loop Whether to apply the filter to the menu title and the meta tag <title> - outside the loop
452 452
 		 * @param array $entry Current entry
453 453
 		 */
454
-		$apply_outside_loop = apply_filters( 'gravityview/single/title/out_loop' , in_the_loop(), $entry );
454
+		$apply_outside_loop = apply_filters( 'gravityview/single/title/out_loop', in_the_loop(), $entry );
455 455
 
456 456
 		if ( ! $apply_outside_loop ) {
457 457
 			return $title;
458 458
 		}
459 459
 
460 460
 		// User reported WooCommerce doesn't pass two args.
461
-		if ( empty( $passed_post_id ) )  {
461
+		if ( empty( $passed_post_id ) ) {
462 462
 			return $title;
463 463
 		}
464 464
 
465 465
 		// Don't modify the title for anything other than the current view/post.
466 466
 		// This is true for embedded shortcodes and Views.
467
-		if ( is_object( $post ) && (int) $post->ID !== (int) $passed_post_id ) {
467
+		if ( is_object( $post ) && (int)$post->ID !== (int)$passed_post_id ) {
468 468
 			return $title;
469 469
 		}
470 470
 
@@ -487,7 +487,7 @@  discard block
 block discarded – undo
487 487
 		} else {
488 488
 			if ( defined( 'GRAVITYVIEW_FUTURE_CORE_LOADED' ) ) {
489 489
 				foreach ( gravityview()->views->all() as $_view ) {
490
-					if ( intval( $_view->form->ID ) === intval( $entry['form_id'] ) ) {
490
+					if ( intval( $_view->form->ID ) === intval( $entry[ 'form_id' ] ) ) {
491 491
 						$view = $_view;
492 492
 						break;
493 493
 					}
@@ -499,7 +499,7 @@  discard block
 block discarded – undo
499 499
 			} else {
500 500
 				/** Deprecated. Use gravityview()->views->all() or gravityview()->request->all() */
501 501
 				foreach ( $this->getGvOutputData()->get_views() as $view_id => $view_data ) {
502
-					if ( intval( $view_data['form_id'] ) === intval( $entry['form_id'] ) ) {
502
+					if ( intval( $view_data[ 'form_id' ] ) === intval( $entry[ 'form_id' ] ) ) {
503 503
 						$view_meta = $view_data;
504 504
 						break;
505 505
 					}
@@ -514,12 +514,12 @@  discard block
 block discarded – undo
514 514
 			}
515 515
 		} else {
516 516
 			/** Deprecated stuff in the future. See the branch above. */
517
-			if ( ! empty( $view_meta['atts']['single_title'] ) ) {
517
+			if ( ! empty( $view_meta[ 'atts' ][ 'single_title' ] ) ) {
518 518
 
519
-				$title = $view_meta['atts']['single_title'];
519
+				$title = $view_meta[ 'atts' ][ 'single_title' ];
520 520
 
521 521
 				// We are allowing HTML in the fields, so no escaping the output
522
-				$title = GravityView_API::replace_variables( $title, $view_meta['form'], $entry );
522
+				$title = GravityView_API::replace_variables( $title, $view_meta[ 'form' ], $entry );
523 523
 
524 524
 				$title = do_shortcode( $title );
525 525
 			}
@@ -557,7 +557,7 @@  discard block
 block discarded – undo
557 557
 		}
558 558
 
559 559
 		// Only render in the loop. Fixes issues with the_content filter being applied in places like the sidebar
560
-		if( ! in_the_loop() ) {
560
+		if ( ! in_the_loop() ) {
561 561
 			return $content;
562 562
 		}
563 563
 
@@ -632,7 +632,7 @@  discard block
 block discarded – undo
632 632
 
633 633
 		$context = GravityView_View::getInstance()->getContext();
634 634
 
635
-		switch( $context ) {
635
+		switch ( $context ) {
636 636
 			case 'directory':
637 637
 				$tab = __( 'Multiple Entries', 'gravityview' );
638 638
 				break;
@@ -646,12 +646,12 @@  discard block
 block discarded – undo
646 646
 		}
647 647
 
648 648
 
649
-		$title = sprintf( esc_html_x('The %s layout has not been configured.', 'Displayed when a View is not configured. %s is replaced by the tab label', 'gravityview' ), $tab );
649
+		$title = sprintf( esc_html_x( 'The %s layout has not been configured.', 'Displayed when a View is not configured. %s is replaced by the tab label', 'gravityview' ), $tab );
650 650
 		$edit_link = admin_url( sprintf( 'post.php?post=%d&action=edit#%s-view', $view_id, $context ) );
651
-		$action_text = sprintf( esc_html__('Add fields to %s', 'gravityview' ), $tab );
651
+		$action_text = sprintf( esc_html__( 'Add fields to %s', 'gravityview' ), $tab );
652 652
 		$message = esc_html__( 'You can only see this message because you are able to edit this View.', 'gravityview' );
653 653
 
654
-		$image =  sprintf( '<img alt="%s" src="%s" style="margin-top: 10px;" />', $tab, esc_url(plugins_url( sprintf( 'assets/images/tab-%s.png', $context ), GRAVITYVIEW_FILE ) ) );
654
+		$image = sprintf( '<img alt="%s" src="%s" style="margin-top: 10px;" />', $tab, esc_url( plugins_url( sprintf( 'assets/images/tab-%s.png', $context ), GRAVITYVIEW_FILE ) ) );
655 655
 		$output = sprintf( '<h3>%s <strong><a href="%s">%s</a></strong></h3><p>%s</p>', $title, esc_url( $edit_link ), $action_text, $message );
656 656
 
657 657
 		echo GVCommon::generate_notice( $output . $image, 'gv-error error', 'edit_gravityview', $view_id );
@@ -682,7 +682,7 @@  discard block
 block discarded – undo
682 682
 	public function render_view( $passed_args ) {
683 683
 
684 684
 		// validate attributes
685
-		if ( empty( $passed_args['id'] ) ) {
685
+		if ( empty( $passed_args[ 'id' ] ) ) {
686 686
 			do_action( 'gravityview_log_error', '[render_view] Returning; no ID defined.', $passed_args );
687 687
 			return null;
688 688
 		}
@@ -704,7 +704,7 @@  discard block
 block discarded – undo
704 704
 			return null;
705 705
 		}
706 706
 
707
-		$view_id = $passed_args['id'];
707
+		$view_id = $passed_args[ 'id' ];
708 708
 
709 709
 		if ( defined( 'GRAVITYVIEW_FUTURE_CORE_LOADED' ) ) {
710 710
 			$view = gravityview()->views->get( $view_id );
@@ -734,7 +734,7 @@  discard block
 block discarded – undo
734 734
 			$passed_args = array_filter( $passed_args, 'strlen' );
735 735
 
736 736
 			//Override shortcode args over View template settings
737
-			$atts = wp_parse_args( $passed_args, $view_data['atts'] );
737
+			$atts = wp_parse_args( $passed_args, $view_data[ 'atts' ] );
738 738
 
739 739
 			do_action( 'gravityview_log_debug', '[render_view] Arguments after merging with View settings: ', $atts );
740 740
 		}
@@ -758,14 +758,14 @@  discard block
 block discarded – undo
758 758
 		 * @since 1.15
759 759
 		 * @since 1.17.2 Added check for if a user has no caps but is logged in (member of multisite, but not any site). Treat as if logged-out.
760 760
 		 */
761
-		if( is_user_logged_in() && ! ( empty( wp_get_current_user()->caps ) && empty( wp_get_current_user()->roles ) ) && false === GVCommon::has_cap( 'read_gravityview', $view_id ) ) {
761
+		if ( is_user_logged_in() && ! ( empty( wp_get_current_user()->caps ) && empty( wp_get_current_user()->roles ) ) && false === GVCommon::has_cap( 'read_gravityview', $view_id ) ) {
762 762
 
763 763
 			do_action( 'gravityview_log_debug', sprintf( '%s Returning: View %d is not visible by current user.', __METHOD__, $view_id ) );
764 764
 
765 765
 			return null;
766 766
 		}
767 767
 
768
-		if( $this->isGravityviewPostType() ) {
768
+		if ( $this->isGravityviewPostType() ) {
769 769
 
770 770
 			/**
771 771
 			 * @filter `gravityview_direct_access` Should Views be directly accessible, or only visible using the shortcode?
@@ -781,10 +781,10 @@  discard block
 block discarded – undo
781 781
 				$embed_only = $view->settings->get( 'embed_only' );
782 782
 			} else {
783 783
 				/** Deprecated. View attributes moved to \GV\View::$settings. */
784
-				$embed_only = ! empty( $atts['embed_only'] );
784
+				$embed_only = ! empty( $atts[ 'embed_only' ] );
785 785
 			}
786 786
 
787
-			if( ! $direct_access || ( $embed_only && ! GVCommon::has_cap( 'read_private_gravityviews' ) ) ) {
787
+			if ( ! $direct_access || ( $embed_only && ! GVCommon::has_cap( 'read_private_gravityviews' ) ) ) {
788 788
 				return __( 'You are not allowed to view this content.', 'gravityview' );
789 789
 			}
790 790
 		}
@@ -805,8 +805,8 @@  discard block
 block discarded – undo
805 805
 		} else {
806 806
 			/** These constructs are deprecated. Use the new gravityview() wrapper. */
807 807
 			$gravityview_view = new GravityView_View( $view_data );
808
-			$post_id = ! empty( $atts['post_id'] ) ? intval( $atts['post_id'] ) : get_the_ID();
809
-			$template_id = $view_data['template_id'];
808
+			$post_id = ! empty( $atts[ 'post_id' ] ) ? intval( $atts[ 'post_id' ] ) : get_the_ID();
809
+			$template_id = $view_data[ 'template_id' ];
810 810
 		}
811 811
 
812 812
 		$gravityview_view->setPostId( $post_id );
@@ -817,20 +817,20 @@  discard block
 block discarded – undo
817 817
 			do_action( 'gravityview_log_debug', '[render_view] Executing Directory View' );
818 818
 
819 819
 			//fetch template and slug
820
-			$view_slug = apply_filters( 'gravityview_template_slug_'. $template_id, 'table', 'directory' );
820
+			$view_slug = apply_filters( 'gravityview_template_slug_' . $template_id, 'table', 'directory' );
821 821
 
822 822
 			do_action( 'gravityview_log_debug', '[render_view] View template slug: ', $view_slug );
823 823
 
824 824
 			/**
825 825
 			 * Disable fetching initial entries for views that don't need it (DataTables)
826 826
 			 */
827
-			$get_entries = apply_filters( 'gravityview_get_view_entries_'.$view_slug, true );
827
+			$get_entries = apply_filters( 'gravityview_get_view_entries_' . $view_slug, true );
828 828
 
829 829
 			if ( defined( 'GRAVITYVIEW_FUTURE_CORE_LOADED' ) ) {
830 830
 				$hide_until_searched = $view->settings->get( 'hide_until_searched' );
831 831
 			} else {
832 832
 				/** $atts is deprecated, use \GV\View:$settings */
833
-				$hide_until_searched = ! empty( $atts['hide_until_searched'] );
833
+				$hide_until_searched = ! empty( $atts[ 'hide_until_searched' ] );
834 834
 			}
835 835
 
836 836
 			/**
@@ -848,12 +848,12 @@  discard block
 block discarded – undo
848 848
 					$sort_columns = $view->settings->get( 'sort_columns' );
849 849
 				} else {
850 850
 					/** $atts is deprecated, use \GV\View:$settings */
851
-					$sort_columns = ! empty( $atts['sort_columns'] );
851
+					$sort_columns = ! empty( $atts[ 'sort_columns' ] );
852 852
 				}
853 853
 
854 854
 				if ( $sort_columns ) {
855 855
 					// add filter to enable column sorting
856
-					add_filter( 'gravityview/template/field_label', array( $this, 'add_columns_sort_links' ) , 100, 3 );
856
+					add_filter( 'gravityview/template/field_label', array( $this, 'add_columns_sort_links' ), 100, 3 );
857 857
 				}
858 858
 
859 859
 				if ( defined( 'GRAVITYVIEW_FUTURE_CORE_LOADED' ) ) {
@@ -861,19 +861,19 @@  discard block
 block discarded – undo
861 861
 				} else {
862 862
 					/** $atts is deprecated, use \GV\View:$settings */
863 863
 					/** $view_data is depreacted, use \GV\View properties */
864
-					$view_entries = self::get_view_entries( $atts, $view_data['form_id'] );
864
+					$view_entries = self::get_view_entries( $atts, $view_data[ 'form_id' ] );
865 865
 				}
866 866
 
867
-				do_action( 'gravityview_log_debug', sprintf( '[render_view] Get Entries. Found %s entries total, showing %d entries', $view_entries['count'], sizeof( $view_entries['entries'] ) ) );
867
+				do_action( 'gravityview_log_debug', sprintf( '[render_view] Get Entries. Found %s entries total, showing %d entries', $view_entries[ 'count' ], sizeof( $view_entries[ 'entries' ] ) ) );
868 868
 
869 869
 			} else {
870 870
 
871 871
 				$view_entries = array( 'count' => null, 'entries' => null, 'paging' => null );
872 872
 
873
-				do_action( 'gravityview_log_debug', '[render_view] Not fetching entries because `gravityview_get_view_entries_'.$view_slug.'` is false' );
873
+				do_action( 'gravityview_log_debug', '[render_view] Not fetching entries because `gravityview_get_view_entries_' . $view_slug . '` is false' );
874 874
 			}
875 875
 
876
-			$gravityview_view->setPaging( $view_entries['paging'] );
876
+			$gravityview_view->setPaging( $view_entries[ 'paging' ] );
877 877
 			$gravityview_view->setContext( 'directory' );
878 878
 			$sections = array( 'header', 'body', 'footer' );
879 879
 
@@ -890,7 +890,7 @@  discard block
 block discarded – undo
890 890
 				do_action( 'gravityview_render_entry_' . $view->ID );
891 891
 			} else {
892 892
 				/** $view_data is depreacted, use \GV\View properties */
893
-				do_action( 'gravityview_render_entry_'.$view_data['id'] );
893
+				do_action( 'gravityview_render_entry_' . $view_data[ 'id' ] );
894 894
 			}
895 895
 
896 896
 			$entry = $this->getEntry();
@@ -901,7 +901,7 @@  discard block
 block discarded – undo
901 901
 				do_action( 'gravityview_log_debug', '[render_view] Entry does not exist. This may be because of View filters limiting access.' );
902 902
 
903 903
 				// Only display warning once when multiple Views are embedded
904
-				if( $view_id !== (int) GravityView_frontend::get_context_view_id() ) {
904
+				if ( $view_id !== (int)GravityView_frontend::get_context_view_id() ) {
905 905
 					ob_end_clean();
906 906
 					return null;
907 907
 				}
@@ -926,7 +926,7 @@  discard block
 block discarded – undo
926 926
 			// important: do not remove this as it prevents fake attempts of displaying entries from other views/forms
927 927
 			$multiple_views = defined( 'GRAVITYVIEW_FUTURE_CORE_LOADED' ) ? gravityview()->views->count() > 1 : $this->getGvOutputData()->has_multiple_views();
928 928
 			if ( $multiple_views && $view_id != $this->get_context_view_id() ) {
929
-				do_action( 'gravityview_log_debug', '[render_view] In single entry view, but the entry does not belong to this View. Perhaps there are multiple views on the page. View ID: '. $view_id );
929
+				do_action( 'gravityview_log_debug', '[render_view] In single entry view, but the entry does not belong to this View. Perhaps there are multiple views on the page. View ID: ' . $view_id );
930 930
 				ob_end_clean();
931 931
 				return null;
932 932
 			}
@@ -936,14 +936,14 @@  discard block
 block discarded – undo
936 936
 			do_action( 'gravityview_log_debug', '[render_view] View single template slug: ', $view_slug );
937 937
 
938 938
 			//fetch entry detail
939
-			$view_entries['count'] = 1;
940
-			$view_entries['entries'][] = $entry;
941
-			do_action( 'gravityview_log_debug', '[render_view] Get single entry: ', $view_entries['entries'] );
939
+			$view_entries[ 'count' ] = 1;
940
+			$view_entries[ 'entries' ][ ] = $entry;
941
+			do_action( 'gravityview_log_debug', '[render_view] Get single entry: ', $view_entries[ 'entries' ] );
942 942
 
943 943
 			if ( defined( 'GRAVITYVIEW_FUTURE_CORE_LOADED' ) ) {
944 944
 				$back_link_label = $view->settings->get( 'back_link_label', null );
945 945
 			} else {
946
-				$back_link_label = isset( $atts['back_link_label'] ) ? $atts['back_link_label'] : null;
946
+				$back_link_label = isset( $atts[ 'back_link_label' ] ) ? $atts[ 'back_link_label' ] : null;
947 947
 			}
948 948
 
949 949
 			// set back link label
@@ -957,8 +957,8 @@  discard block
 block discarded – undo
957 957
 		self::add_style( $template_id );
958 958
 
959 959
 		// Prepare to render view and set vars
960
-		$gravityview_view->setEntries( $view_entries['entries'] );
961
-		$gravityview_view->setTotalEntries( $view_entries['count'] );
960
+		$gravityview_view->setEntries( $view_entries[ 'entries' ] );
961
+		$gravityview_view->setTotalEntries( $view_entries[ 'count' ] );
962 962
 
963 963
 		// If Edit
964 964
 		if ( 'edit' === gravityview_get_context() ) {
@@ -975,7 +975,7 @@  discard block
 block discarded – undo
975 975
 
976 976
 			do_action( 'gravityview_log_debug', '[render_view] Sections to render: ', $sections );
977 977
 			foreach ( $sections as $section ) {
978
-				do_action( 'gravityview_log_debug', '[render_view] Rendering '. $section . ' section.' );
978
+				do_action( 'gravityview_log_debug', '[render_view] Rendering ' . $section . ' section.' );
979 979
 				$gravityview_view->render( $view_slug, $section, false );
980 980
 			}
981 981
 		}
@@ -1029,7 +1029,7 @@  discard block
 block discarded – undo
1029 1029
 				$datetime_format = 'Y-m-d H:i:s';
1030 1030
 				$search_is_outside_view_bounds = false;
1031 1031
 
1032
-				if( ! empty( $search_criteria[ $key ] ) ) {
1032
+				if ( ! empty( $search_criteria[ $key ] ) ) {
1033 1033
 
1034 1034
 					$search_date = strtotime( $search_criteria[ $key ] );
1035 1035
 
@@ -1057,14 +1057,14 @@  discard block
 block discarded – undo
1057 1057
 				if ( empty( $search_criteria[ $key ] ) || $search_is_outside_view_bounds ) {
1058 1058
 
1059 1059
 					// Then we override the search and re-set the start date
1060
-					$return_search_criteria[ $key ] = date_i18n( $datetime_format , $date, true );
1060
+					$return_search_criteria[ $key ] = date_i18n( $datetime_format, $date, true );
1061 1061
 				}
1062 1062
 			}
1063 1063
 		}
1064 1064
 
1065
-		if( isset( $return_search_criteria['start_date'] ) && isset( $return_search_criteria['end_date'] ) ) {
1065
+		if ( isset( $return_search_criteria[ 'start_date' ] ) && isset( $return_search_criteria[ 'end_date' ] ) ) {
1066 1066
 			// The start date is AFTER the end date. This will result in no results, but let's not force the issue.
1067
-			if ( strtotime( $return_search_criteria['start_date'] ) > strtotime( $return_search_criteria['end_date'] ) ) {
1067
+			if ( strtotime( $return_search_criteria[ 'start_date' ] ) > strtotime( $return_search_criteria[ 'end_date' ] ) ) {
1068 1068
 				do_action( 'gravityview_log_error', __METHOD__ . ' Invalid search: the start date is after the end date.', $return_search_criteria );
1069 1069
 			}
1070 1070
 		}
@@ -1083,19 +1083,19 @@  discard block
 block discarded – undo
1083 1083
 	public static function process_search_only_approved( $args, $search_criteria ) {
1084 1084
 
1085 1085
 		/** @since 1.19 */
1086
-		if( ! empty( $args['admin_show_all_statuses'] ) && GVCommon::has_cap('gravityview_moderate_entries') ) {
1086
+		if ( ! empty( $args[ 'admin_show_all_statuses' ] ) && GVCommon::has_cap( 'gravityview_moderate_entries' ) ) {
1087 1087
 			do_action( 'gravityview_log_debug', __METHOD__ . ': User can moderate entries; showing all approval statuses' );
1088 1088
 			return $search_criteria;
1089 1089
 		}
1090 1090
 
1091
-		if ( ! empty( $args['show_only_approved'] ) ) {
1091
+		if ( ! empty( $args[ 'show_only_approved' ] ) ) {
1092 1092
 
1093
-			$search_criteria['field_filters'][] = array(
1093
+			$search_criteria[ 'field_filters' ][ ] = array(
1094 1094
 				'key' => GravityView_Entry_Approval::meta_key,
1095 1095
 				'value' => GravityView_Entry_Approval_Status::APPROVED
1096 1096
 			);
1097 1097
 
1098
-			$search_criteria['field_filters']['mode'] = 'all'; // force all the criterias to be met
1098
+			$search_criteria[ 'field_filters' ][ 'mode' ] = 'all'; // force all the criterias to be met
1099 1099
 
1100 1100
 			do_action( 'gravityview_log_debug', '[process_search_only_approved] Search Criteria if show only approved: ', $search_criteria );
1101 1101
 		}
@@ -1122,18 +1122,18 @@  discard block
 block discarded – undo
1122 1122
 	 */
1123 1123
 	public static function is_entry_approved( $entry, $args = array() ) {
1124 1124
 
1125
-		if ( empty( $entry['id'] ) || ( array_key_exists( 'show_only_approved', $args ) && ! $args['show_only_approved'] ) ) {
1125
+		if ( empty( $entry[ 'id' ] ) || ( array_key_exists( 'show_only_approved', $args ) && ! $args[ 'show_only_approved' ] ) ) {
1126 1126
 			// is implicitly approved if entry is null or View settings doesn't require to check for approval
1127 1127
 			return true;
1128 1128
 		}
1129 1129
 
1130 1130
 		/** @since 1.19 */
1131
-		if( ! empty( $args['admin_show_all_statuses'] ) && GVCommon::has_cap('gravityview_moderate_entries') ) {
1131
+		if ( ! empty( $args[ 'admin_show_all_statuses' ] ) && GVCommon::has_cap( 'gravityview_moderate_entries' ) ) {
1132 1132
 			do_action( 'gravityview_log_debug', __METHOD__ . ': User can moderate entries, so entry is approved for viewing' );
1133 1133
 			return true;
1134 1134
 		}
1135 1135
 
1136
-		$is_approved = gform_get_meta( $entry['id'], GravityView_Entry_Approval::meta_key );
1136
+		$is_approved = gform_get_meta( $entry[ 'id' ], GravityView_Entry_Approval::meta_key );
1137 1137
 
1138 1138
 		return GravityView_Entry_Approval_Status::is_approved( $is_approved );
1139 1139
 	}
@@ -1167,29 +1167,29 @@  discard block
 block discarded – undo
1167 1167
 		do_action( 'gravityview_log_debug', '[get_search_criteria] Search Criteria after hook gravityview_fe_search_criteria: ', $search_criteria );
1168 1168
 
1169 1169
 		// implicity search
1170
-		if ( ! empty( $args['search_value'] ) ) {
1170
+		if ( ! empty( $args[ 'search_value' ] ) ) {
1171 1171
 
1172 1172
 			// Search operator options. Options: `is` or `contains`
1173
-			$operator = ! empty( $args['search_operator'] ) && in_array( $args['search_operator'], array( 'is', 'isnot', '>', '<', 'contains' ) ) ? $args['search_operator'] : 'contains';
1173
+			$operator = ! empty( $args[ 'search_operator' ] ) && in_array( $args[ 'search_operator' ], array( 'is', 'isnot', '>', '<', 'contains' ) ) ? $args[ 'search_operator' ] : 'contains';
1174 1174
 
1175
-			$search_criteria['field_filters'][] = array(
1175
+			$search_criteria[ 'field_filters' ][ ] = array(
1176 1176
 				'key' => rgget( 'search_field', $args ), // The field ID to search
1177
-				'value' => _wp_specialchars( $args['search_value'] ), // The value to search. Encode ampersands but not quotes.
1177
+				'value' => _wp_specialchars( $args[ 'search_value' ] ), // The value to search. Encode ampersands but not quotes.
1178 1178
 				'operator' => $operator,
1179 1179
 			);
1180 1180
 
1181 1181
 			// Lock search mode to "all" with implicit presearch filter.
1182
-			$search_criteria['field_filters']['mode'] = 'all';
1182
+			$search_criteria[ 'field_filters' ][ 'mode' ] = 'all';
1183 1183
 		}
1184 1184
 
1185
-		if( $search_criteria !== $original_search_criteria ) {
1185
+		if ( $search_criteria !== $original_search_criteria ) {
1186 1186
 			do_action( 'gravityview_log_debug', '[get_search_criteria] Search Criteria after implicity search: ', $search_criteria );
1187 1187
 		}
1188 1188
 
1189 1189
 		// Handle setting date range
1190 1190
 		$search_criteria = self::process_search_dates( $args, $search_criteria );
1191 1191
 
1192
-		if( $search_criteria !== $original_search_criteria ) {
1192
+		if ( $search_criteria !== $original_search_criteria ) {
1193 1193
 			do_action( 'gravityview_log_debug', '[get_search_criteria] Search Criteria after date params: ', $search_criteria );
1194 1194
 		}
1195 1195
 
@@ -1200,7 +1200,7 @@  discard block
 block discarded – undo
1200 1200
 		 * @filter `gravityview_status` Modify entry status requirements to be included in search results.
1201 1201
 		 * @param string $status Default: `active`. Accepts all Gravity Forms entry statuses, including `spam` and `trash`
1202 1202
 		 */
1203
-		$search_criteria['status'] = apply_filters( 'gravityview_status', 'active', $args );
1203
+		$search_criteria[ 'status' ] = apply_filters( 'gravityview_status', 'active', $args );
1204 1204
 
1205 1205
 		return $search_criteria;
1206 1206
 	}
@@ -1324,7 +1324,7 @@  discard block
 block discarded – undo
1324 1324
 			'search_criteria' => $search_criteria,
1325 1325
 			'sorting' => self::updateViewSorting( $args, $form_id ),
1326 1326
 			'paging' => $paging,
1327
-			'cache' => isset( $args['cache'] ) ? $args['cache'] : true,
1327
+			'cache' => isset( $args[ 'cache' ] ) ? $args[ 'cache' ] : true,
1328 1328
 		);
1329 1329
 
1330 1330
 		/**
@@ -1349,7 +1349,7 @@  discard block
 block discarded – undo
1349 1349
 		 * @param array $parameters Array with `search_criteria`, `sorting` and `paging` keys.
1350 1350
 		 * @param array $args View configuration args.
1351 1351
 		 */
1352
-		$parameters = apply_filters( 'gravityview_get_entries_'.$args['id'], $parameters, $args, $form_id );
1352
+		$parameters = apply_filters( 'gravityview_get_entries_' . $args[ 'id' ], $parameters, $args, $form_id );
1353 1353
 
1354 1354
 		do_action( 'gravityview_log_debug', __METHOD__ . ': $parameters passed to gravityview_get_entries(): ', $parameters );
1355 1355
 
@@ -1374,17 +1374,17 @@  discard block
 block discarded – undo
1374 1374
 		$default_page_size = apply_filters( 'gravityview_default_page_size', 25 );
1375 1375
 
1376 1376
 		// Paging & offset
1377
-		$page_size = ! empty( $args['page_size'] ) ? intval( $args['page_size'] ) : $default_page_size;
1377
+		$page_size = ! empty( $args[ 'page_size' ] ) ? intval( $args[ 'page_size' ] ) : $default_page_size;
1378 1378
 
1379 1379
 		if ( -1 === $page_size ) {
1380 1380
 			$page_size = PHP_INT_MAX;
1381 1381
 		}
1382 1382
 
1383
-		$curr_page = empty( $_GET['pagenum'] ) ? 1 : intval( $_GET['pagenum'] );
1383
+		$curr_page = empty( $_GET[ 'pagenum' ] ) ? 1 : intval( $_GET[ 'pagenum' ] );
1384 1384
 		$offset = ( $curr_page - 1 ) * $page_size;
1385 1385
 
1386
-		if ( ! empty( $args['offset'] ) ) {
1387
-			$offset += intval( $args['offset'] );
1386
+		if ( ! empty( $args[ 'offset' ] ) ) {
1387
+			$offset += intval( $args[ 'offset' ] );
1388 1388
 		}
1389 1389
 
1390 1390
 		$paging = array(
@@ -1408,8 +1408,8 @@  discard block
 block discarded – undo
1408 1408
 	 */
1409 1409
 	public static function updateViewSorting( $args, $form_id ) {
1410 1410
 		$sorting = array();
1411
-		$sort_field_id = isset( $_GET['sort'] ) ? $_GET['sort'] : rgar( $args, 'sort_field' );
1412
-		$sort_direction = isset( $_GET['dir'] ) ? $_GET['dir'] : rgar( $args, 'sort_direction' );
1411
+		$sort_field_id = isset( $_GET[ 'sort' ] ) ? $_GET[ 'sort' ] : rgar( $args, 'sort_field' );
1412
+		$sort_direction = isset( $_GET[ 'dir' ] ) ? $_GET[ 'dir' ] : rgar( $args, 'sort_direction' );
1413 1413
 
1414 1414
 		$sort_field_id = self::_override_sorting_id_by_field_type( $sort_field_id, $form_id );
1415 1415
 
@@ -1449,11 +1449,11 @@  discard block
 block discarded – undo
1449 1449
 
1450 1450
 		$sort_field = GFFormsModel::get_field( $form, $sort_field_id );
1451 1451
 
1452
-		if( ! $sort_field ) {
1452
+		if ( ! $sort_field ) {
1453 1453
 			return $sort_field_id;
1454 1454
 		}
1455 1455
 
1456
-		switch ( $sort_field['type'] ) {
1456
+		switch ( $sort_field[ 'type' ] ) {
1457 1457
 
1458 1458
 			case 'address':
1459 1459
 				// Sorting by full address
@@ -1470,7 +1470,7 @@  discard block
 block discarded – undo
1470 1470
 					 */
1471 1471
 					$address_part = apply_filters( 'gravityview/sorting/address', 'city', $sort_field_id, $form_id );
1472 1472
 
1473
-					switch( strtolower( $address_part ) ){
1473
+					switch ( strtolower( $address_part ) ) {
1474 1474
 						case 'street':
1475 1475
 							$sort_field_id .= '.1';
1476 1476
 							break;
@@ -1555,7 +1555,7 @@  discard block
 block discarded – undo
1555 1555
 		 */
1556 1556
 		$single_entry = apply_filters( 'gravityview/is_single_entry', $single_entry );
1557 1557
 
1558
-		if ( empty( $single_entry ) ){
1558
+		if ( empty( $single_entry ) ) {
1559 1559
 			return false;
1560 1560
 		} else {
1561 1561
 			return $single_entry;
@@ -1588,14 +1588,14 @@  discard block
 block discarded – undo
1588 1588
 					$template_id = $view->template ? $view->template->ID : null;
1589 1589
 					$data = $view->as_data();
1590 1590
 				} else {
1591
-					$template_id = $data['template_id'];
1591
+					$template_id = $data[ 'template_id' ];
1592 1592
 				}
1593 1593
 
1594 1594
 				/**
1595 1595
 				 * Don't enqueue the scripts or styles if it's not going to be displayed.
1596 1596
 				 * @since 1.15
1597 1597
 				 */
1598
-				if( is_user_logged_in() && false === GVCommon::has_cap( 'read_gravityview', $view_id ) ) {
1598
+				if ( is_user_logged_in() && false === GVCommon::has_cap( 'read_gravityview', $view_id ) ) {
1599 1599
 					continue;
1600 1600
 				}
1601 1601
 
@@ -1607,7 +1607,7 @@  discard block
 block discarded – undo
1607 1607
 					$lightbox = $view->settings->get( 'lightbox' );
1608 1608
 				} else {
1609 1609
 					/** View data attributes are now stored in \GV\View::$settings */
1610
-					$lightbox = ! empty( $data['atts']['lightbox'] );
1610
+					$lightbox = ! empty( $data[ 'atts' ][ 'lightbox' ] );
1611 1611
 				}
1612 1612
 
1613 1613
 				// If the thickbox is enqueued, add dependencies
@@ -1617,13 +1617,13 @@  discard block
 block discarded – undo
1617 1617
 					 * @filter `gravity_view_lightbox_script` Override the lightbox script to enqueue. Default: `thickbox`
1618 1618
 					 * @param string $script_slug If you want to use a different lightbox script, return the name of it here.
1619 1619
 					 */
1620
-					$js_dependencies[] = apply_filters( 'gravity_view_lightbox_script', 'thickbox' );
1620
+					$js_dependencies[ ] = apply_filters( 'gravity_view_lightbox_script', 'thickbox' );
1621 1621
 
1622 1622
 					/**
1623 1623
 					 * @filter `gravity_view_lightbox_style` Modify the lightbox CSS slug. Default: `thickbox`
1624 1624
 					 * @param string $script_slug If you want to use a different lightbox script, return the name of its CSS file here.
1625 1625
 					 */
1626
-					$css_dependencies[] = apply_filters( 'gravity_view_lightbox_style', 'thickbox' );
1626
+					$css_dependencies[ ] = apply_filters( 'gravity_view_lightbox_style', 'thickbox' );
1627 1627
 				}
1628 1628
 
1629 1629
 				/**
@@ -1631,19 +1631,19 @@  discard block
 block discarded – undo
1631 1631
 				 * @see https://github.com/katzwebservices/GravityView/issues/536
1632 1632
 				 * @since 1.15
1633 1633
 				 */
1634
-				if( gravityview_view_has_single_checkbox_or_radio( $data['form'], $data['fields'] ) ) {
1635
-					$css_dependencies[] = 'dashicons';
1634
+				if ( gravityview_view_has_single_checkbox_or_radio( $data[ 'form' ], $data[ 'fields' ] ) ) {
1635
+					$css_dependencies[ ] = 'dashicons';
1636 1636
 				}
1637 1637
 
1638 1638
 				wp_register_script( 'gravityview-jquery-cookie', plugins_url( 'assets/lib/jquery.cookie/jquery.cookie.min.js', GRAVITYVIEW_FILE ), array( 'jquery' ), GravityView_Plugin::version, true );
1639 1639
 
1640 1640
 				$script_debug = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
1641 1641
 
1642
-				wp_register_script( 'gravityview-fe-view', plugins_url( 'assets/js/fe-views' . $script_debug . '.js', GRAVITYVIEW_FILE ), apply_filters( 'gravityview_js_dependencies', $js_dependencies ) , GravityView_Plugin::version, true );
1642
+				wp_register_script( 'gravityview-fe-view', plugins_url( 'assets/js/fe-views' . $script_debug . '.js', GRAVITYVIEW_FILE ), apply_filters( 'gravityview_js_dependencies', $js_dependencies ), GravityView_Plugin::version, true );
1643 1643
 
1644 1644
 				wp_enqueue_script( 'gravityview-fe-view' );
1645 1645
 
1646
-				if ( ! empty( $data['atts']['sort_columns'] ) ) {
1646
+				if ( ! empty( $data[ 'atts' ][ 'sort_columns' ] ) ) {
1647 1647
 					wp_enqueue_style( 'gravityview_font', plugins_url( 'assets/css/font.css', GRAVITYVIEW_FILE ), $css_dependencies, GravityView_Plugin::version, 'all' );
1648 1648
 				}
1649 1649
 
@@ -1711,7 +1711,7 @@  discard block
 block discarded – undo
1711 1711
 		} elseif ( empty( $template_id ) ) {
1712 1712
 			do_action( 'gravityview_log_error', '[add_style] Cannot add template style; template_id is empty' );
1713 1713
 		} else {
1714
-			do_action( 'gravityview_log_error', sprintf( '[add_style] Cannot add template style; %s is not registered', 'gravityview_style_'.$template_id ) );
1714
+			do_action( 'gravityview_log_error', sprintf( '[add_style] Cannot add template style; %s is not registered', 'gravityview_style_' . $template_id ) );
1715 1715
 		}
1716 1716
 
1717 1717
 	}
@@ -1736,11 +1736,11 @@  discard block
 block discarded – undo
1736 1736
 		 * Not a table-based template; don't add sort icons
1737 1737
 		 * @since 1.12
1738 1738
 		 */
1739
-		if( ! preg_match( '/table/ism', GravityView_View::getInstance()->getTemplatePartSlug() ) ) {
1739
+		if ( ! preg_match( '/table/ism', GravityView_View::getInstance()->getTemplatePartSlug() ) ) {
1740 1740
 			return $label;
1741 1741
 		}
1742 1742
 
1743
-		if ( ! $this->is_field_sortable( $field['id'], $form ) ) {
1743
+		if ( ! $this->is_field_sortable( $field[ 'id' ], $form ) ) {
1744 1744
 			return $label;
1745 1745
 		}
1746 1746
 
@@ -1748,29 +1748,29 @@  discard block
 block discarded – undo
1748 1748
 
1749 1749
 		$class = 'gv-sort';
1750 1750
 
1751
-		$sort_field_id = self::_override_sorting_id_by_field_type( $field['id'], $form['id'] );
1751
+		$sort_field_id = self::_override_sorting_id_by_field_type( $field[ 'id' ], $form[ 'id' ] );
1752 1752
 
1753 1753
 		$sort_args = array(
1754
-			'sort' => $field['id'],
1754
+			'sort' => $field[ 'id' ],
1755 1755
 			'dir' => 'asc',
1756 1756
 		);
1757 1757
 
1758
-		if ( ! empty( $sorting['key'] ) && (string) $sort_field_id === (string) $sorting['key'] ) {
1758
+		if ( ! empty( $sorting[ 'key' ] ) && (string)$sort_field_id === (string)$sorting[ 'key' ] ) {
1759 1759
 			//toggle sorting direction.
1760
-			if ( 'asc' === $sorting['direction'] ) {
1761
-				$sort_args['dir'] = 'desc';
1760
+			if ( 'asc' === $sorting[ 'direction' ] ) {
1761
+				$sort_args[ 'dir' ] = 'desc';
1762 1762
 				$class .= ' gv-icon-sort-desc';
1763 1763
 			} else {
1764
-				$sort_args['dir'] = 'asc';
1764
+				$sort_args[ 'dir' ] = 'asc';
1765 1765
 				$class .= ' gv-icon-sort-asc';
1766 1766
 			}
1767 1767
 		} else {
1768 1768
 			$class .= ' gv-icon-caret-up-down';
1769 1769
 		}
1770 1770
 
1771
-		$url = add_query_arg( $sort_args, remove_query_arg( array('pagenum') ) );
1771
+		$url = add_query_arg( $sort_args, remove_query_arg( array( 'pagenum' ) ) );
1772 1772
 
1773
-		return '<a href="'. esc_url_raw( $url ) .'" class="'. $class .'" ></a>&nbsp;'. $label;
1773
+		return '<a href="' . esc_url_raw( $url ) . '" class="' . $class . '" ></a>&nbsp;' . $label;
1774 1774
 
1775 1775
 	}
1776 1776
 
@@ -1788,7 +1788,7 @@  discard block
 block discarded – undo
1788 1788
 
1789 1789
 		$field_type = $field_id;
1790 1790
 
1791
-		if( is_numeric( $field_id ) ) {
1791
+		if ( is_numeric( $field_id ) ) {
1792 1792
 			$field = GFFormsModel::get_field( $form, $field_id );
1793 1793
 			$field_type = $field->type;
1794 1794
 		}
@@ -1811,7 +1811,7 @@  discard block
 block discarded – undo
1811 1811
 			return false;
1812 1812
 		}
1813 1813
 
1814
-		return apply_filters( "gravityview/sortable/formfield_{$form['id']}_{$field_id}", apply_filters( "gravityview/sortable/field_{$field_id}", true, $form ) );
1814
+		return apply_filters( "gravityview/sortable/formfield_{$form[ 'id' ]}_{$field_id}", apply_filters( "gravityview/sortable/field_{$field_id}", true, $form ) );
1815 1815
 
1816 1816
 	}
1817 1817
 
Please login to merge, or discard this patch.
includes/class-api.php 1 patch
Spacing   +140 added lines, -140 removed lines patch added patch discarded remove patch
@@ -30,29 +30,29 @@  discard block
 block discarded – undo
30 30
 
31 31
 		$label = '';
32 32
 
33
-		if( !empty( $field['show_label'] ) || $force_show_label ) {
33
+		if ( ! empty( $field[ 'show_label' ] ) || $force_show_label ) {
34 34
 
35
-			$label = $field['label'];
35
+			$label = $field[ 'label' ];
36 36
 
37 37
 			// Support Gravity Forms 1.9+
38
-			if( class_exists( 'GF_Field' ) ) {
38
+			if ( class_exists( 'GF_Field' ) ) {
39 39
 
40
-				$field_object = RGFormsModel::get_field( $form, $field['id'] );
40
+				$field_object = RGFormsModel::get_field( $form, $field[ 'id' ] );
41 41
 
42
-				if( $field_object ) {
42
+				if ( $field_object ) {
43 43
 
44
-					$input = GFFormsModel::get_input( $field_object, $field['id'] );
44
+					$input = GFFormsModel::get_input( $field_object, $field[ 'id' ] );
45 45
 
46 46
 					// This is a complex field, with labels on a per-input basis
47
-					if( $input ) {
47
+					if ( $input ) {
48 48
 
49 49
 						// Does the input have a custom label on a per-input basis? Otherwise, default label.
50
-						$label = ! empty( $input['customLabel'] ) ? $input['customLabel'] : $input['label'];
50
+						$label = ! empty( $input[ 'customLabel' ] ) ? $input[ 'customLabel' ] : $input[ 'label' ];
51 51
 
52 52
 					} else {
53 53
 
54 54
 						// This is a field with one label
55
-						$label = $field_object->get_field_label( true, $field['label'] );
55
+						$label = $field_object->get_field_label( true, $field[ 'label' ] );
56 56
 
57 57
 					}
58 58
 
@@ -61,9 +61,9 @@  discard block
 block discarded – undo
61 61
 			}
62 62
 
63 63
 			// Use Gravity Forms label by default, but if a custom label is defined in GV, use it.
64
-			if ( !empty( $field['custom_label'] ) ) {
64
+			if ( ! empty( $field[ 'custom_label' ] ) ) {
65 65
 
66
-				$label = self::replace_variables( $field['custom_label'], $form, $entry );
66
+				$label = self::replace_variables( $field[ 'custom_label' ], $form, $entry );
67 67
 
68 68
 			}
69 69
 
@@ -117,11 +117,11 @@  discard block
 block discarded – undo
117 117
 
118 118
 		$width = NULL;
119 119
 
120
-		if( !empty( $field['width'] ) ) {
121
-			$width = absint( $field['width'] );
120
+		if ( ! empty( $field[ 'width' ] ) ) {
121
+			$width = absint( $field[ 'width' ] );
122 122
 
123 123
 			// If using percentages, limit to 100%
124
-			if( '%d%%' === $format && $width > 100 ) {
124
+			if ( '%d%%' === $format && $width > 100 ) {
125 125
 				$width = 100;
126 126
 			}
127 127
 
@@ -144,39 +144,39 @@  discard block
 block discarded – undo
144 144
 
145 145
 		$classes = array();
146 146
 
147
-		if( !empty( $field['custom_class'] ) ) {
147
+		if ( ! empty( $field[ 'custom_class' ] ) ) {
148 148
 
149
-            $custom_class = $field['custom_class'];
149
+            $custom_class = $field[ 'custom_class' ];
150 150
 
151
-            if( !empty( $entry ) ) {
151
+            if ( ! empty( $entry ) ) {
152 152
 
153 153
                 // We want the merge tag to be formatted as a class. The merge tag may be
154 154
                 // replaced by a multiple-word value that should be output as a single class.
155 155
                 // "Office Manager" will be formatted as `.OfficeManager`, not `.Office` and `.Manager`
156
-                add_filter('gform_merge_tag_filter', 'sanitize_html_class');
156
+                add_filter( 'gform_merge_tag_filter', 'sanitize_html_class' );
157 157
 
158
-                $custom_class = self::replace_variables( $custom_class, $form, $entry);
158
+                $custom_class = self::replace_variables( $custom_class, $form, $entry );
159 159
 
160 160
                 // And then we want life to return to normal
161
-                remove_filter('gform_merge_tag_filter', 'sanitize_html_class');
161
+                remove_filter( 'gform_merge_tag_filter', 'sanitize_html_class' );
162 162
             }
163 163
 
164 164
 			// And now we want the spaces to be handled nicely.
165
-			$classes[] = gravityview_sanitize_html_class( $custom_class );
165
+			$classes[ ] = gravityview_sanitize_html_class( $custom_class );
166 166
 
167 167
 		}
168 168
 
169
-		if(!empty($field['id'])) {
170
-			if( !empty( $form ) && !empty( $form['id'] ) ) {
171
-				$form_id = '-'.$form['id'];
169
+		if ( ! empty( $field[ 'id' ] ) ) {
170
+			if ( ! empty( $form ) && ! empty( $form[ 'id' ] ) ) {
171
+				$form_id = '-' . $form[ 'id' ];
172 172
 			} else {
173
-				$form_id = $gravityview_view->getFormId() ? '-'. $gravityview_view->getFormId() : '';
173
+				$form_id = $gravityview_view->getFormId() ? '-' . $gravityview_view->getFormId() : '';
174 174
 			}
175 175
 
176
-			$classes[] = 'gv-field'.$form_id.'-'.$field['id'];
176
+			$classes[ ] = 'gv-field' . $form_id . '-' . $field[ 'id' ];
177 177
 		}
178 178
 
179
-		return esc_attr(implode(' ', $classes));
179
+		return esc_attr( implode( ' ', $classes ) );
180 180
 	}
181 181
 
182 182
 	/**
@@ -193,16 +193,16 @@  discard block
 block discarded – undo
193 193
 	 */
194 194
 	public static function field_html_attr_id( $field, $form = array(), $entry = array() ) {
195 195
 		$gravityview_view = GravityView_View::getInstance();
196
-		$id = $field['id'];
196
+		$id = $field[ 'id' ];
197 197
 
198 198
 		if ( ! empty( $id ) ) {
199
-			if ( ! empty( $form ) && ! empty( $form['id'] ) ) {
200
-				$form_id = '-' . $form['id'];
199
+			if ( ! empty( $form ) && ! empty( $form[ 'id' ] ) ) {
200
+				$form_id = '-' . $form[ 'id' ];
201 201
 			} else {
202 202
 				$form_id = $gravityview_view->getFormId() ? '-' . $gravityview_view->getFormId() : '';
203 203
 			}
204 204
 
205
-			$id = 'gv-field' . $form_id . '-' . $field['id'];
205
+			$id = 'gv-field' . $form_id . '-' . $field[ 'id' ];
206 206
 		}
207 207
 
208 208
 		return esc_attr( $id );
@@ -219,17 +219,17 @@  discard block
 block discarded – undo
219 219
 	 */
220 220
 	public static function field_value( $entry, $field_settings, $format = 'html' ) {
221 221
 
222
-		if( empty( $entry['form_id'] ) || empty( $field_settings['id'] ) ) {
222
+		if ( empty( $entry[ 'form_id' ] ) || empty( $field_settings[ 'id' ] ) ) {
223 223
 			return NULL;
224 224
 		}
225 225
 
226 226
 		$gravityview_view = GravityView_View::getInstance();
227 227
 
228
-		$field_id = $field_settings['id'];
228
+		$field_id = $field_settings[ 'id' ];
229 229
 		$form = $gravityview_view->getForm();
230 230
 		$field = gravityview_get_field( $form, $field_id );
231 231
 
232
-		if( $field && is_numeric( $field_id ) ) {
232
+		if ( $field && is_numeric( $field_id ) ) {
233 233
 			// Used as file name of field template in GV.
234 234
 			// Don't use RGFormsModel::get_input_type( $field ); we don't care if it's a radio input; we want to know it's a 'quiz' field
235 235
 			$field_type = $field->type;
@@ -240,12 +240,12 @@  discard block
 block discarded – undo
240 240
 		}
241 241
 
242 242
 		// If a Gravity Forms Field is found, get the field display
243
-		if( $field ) {
243
+		if ( $field ) {
244 244
 
245 245
 			// Prevent any PHP warnings that may be generated
246 246
 			ob_start();
247 247
 
248
-			$display_value = GFCommon::get_lead_field_display( $field, $value, $entry["currency"], false, $format );
248
+			$display_value = GFCommon::get_lead_field_display( $field, $value, $entry[ "currency" ], false, $format );
249 249
 
250 250
 			if ( $errors = ob_get_clean() ) {
251 251
 				do_action( 'gravityview_log_error', 'GravityView_API[field_value] Errors when calling GFCommon::get_lead_field_display()', $errors );
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
 			$display_value = apply_filters( "gform_entry_field_value", $display_value, $field, $entry, $form );
255 255
 
256 256
 			// prevent the use of merge_tags for non-admin fields
257
-			if( !empty( $field->adminOnly ) ) {
257
+			if ( ! empty( $field->adminOnly ) ) {
258 258
 				$display_value = self::replace_variables( $display_value, $form, $entry );
259 259
 			}
260 260
 		} else {
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
 
265 265
 		// Check whether the field exists in /includes/fields/{$field_type}.php
266 266
 		// This can be overridden by user template files.
267
-		$field_path = $gravityview_view->locate_template("fields/{$field_type}.php");
267
+		$field_path = $gravityview_view->locate_template( "fields/{$field_type}.php" );
268 268
 
269 269
 		// Set the field data to be available in the templates
270 270
 		$gravityview_view->setCurrentField( array(
@@ -278,11 +278,11 @@  discard block
 block discarded – undo
278 278
 			'entry' => $entry,
279 279
 			'field_type' => $field_type, /** {@since 1.6} */
280 280
 		    'field_path' => $field_path, /** {@since 1.16} */
281
-		));
281
+		) );
282 282
 
283
-		if( ! empty( $field_path ) ) {
283
+		if ( ! empty( $field_path ) ) {
284 284
 
285
-			do_action( 'gravityview_log_debug', sprintf('[field_value] Rendering %s', $field_path ) );
285
+			do_action( 'gravityview_log_debug', sprintf( '[field_value] Rendering %s', $field_path ) );
286 286
 
287 287
 			ob_start();
288 288
 
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
 		}
299 299
 
300 300
 		// Get the field settings again so that the field template can override the settings
301
-		$field_settings = $gravityview_view->getCurrentField('field_settings');
301
+		$field_settings = $gravityview_view->getCurrentField( 'field_settings' );
302 302
 
303 303
 		/**
304 304
 		 * @filter `gravityview_field_entry_value_{$field_type}_pre_link` Modify the field value output for a field type before Show As Link setting is applied. Example: `gravityview_field_entry_value_number_pre_link`
@@ -327,9 +327,9 @@  discard block
 block discarded – undo
327 327
 		 * Fields can override this by modifying the field data variable inside the field. See /templates/fields/post_image.php for an example.
328 328
 		 *
329 329
 		 */
330
-		if( !empty( $field_settings['show_as_link'] ) && ! gv_empty( $output, false, false ) ) {
330
+		if ( ! empty( $field_settings[ 'show_as_link' ] ) && ! gv_empty( $output, false, false ) ) {
331 331
 
332
-			$link_atts = empty( $field_settings['new_window'] ) ? array() : array( 'target' => '_blank' );
332
+			$link_atts = empty( $field_settings[ 'new_window' ] ) ? array() : array( 'target' => '_blank' );
333 333
 
334 334
 			$output = self::entry_link_html( $entry, $output, $link_atts, $field_settings );
335 335
 
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
 		 * @param  array $field_settings Settings for the particular GV field
344 344
 		 * @param array $field Current field being displayed
345 345
 		 */
346
-		$output = apply_filters( 'gravityview_field_entry_value_'.$field_type, $output, $entry, $field_settings, $gravityview_view->getCurrentField() );
346
+		$output = apply_filters( 'gravityview_field_entry_value_' . $field_type, $output, $entry, $field_settings, $gravityview_view->getCurrentField() );
347 347
 
348 348
 		/**
349 349
 		 * @filter `gravityview_field_entry_value` Modify the field value output for all field types
@@ -372,14 +372,14 @@  discard block
 block discarded – undo
372 372
 	 */
373 373
 	public static function entry_link_html( $entry = array(), $anchor_text = '', $passed_tag_atts = array(), $field_settings = array() ) {
374 374
 
375
-		if ( empty( $entry ) || ! is_array( $entry ) || ! isset( $entry['id'] ) ) {
375
+		if ( empty( $entry ) || ! is_array( $entry ) || ! isset( $entry[ 'id' ] ) ) {
376 376
 			do_action( 'gravityview_log_debug', 'GravityView_API[entry_link_tag] Entry not defined; returning null', $entry );
377 377
 			return NULL;
378 378
 		}
379 379
 
380 380
 		$href = self::entry_link( $entry );
381 381
 
382
-		if( '' === $href ) {
382
+		if ( '' === $href ) {
383 383
 			return NULL;
384 384
 		}
385 385
 
@@ -402,19 +402,19 @@  discard block
 block discarded – undo
402 402
 	 * @param  boolean     $wpautop Apply wpautop() to the output?
403 403
 	 * @return string               HTML of "no results" text
404 404
 	 */
405
-	public static function no_results($wpautop = true) {
405
+	public static function no_results( $wpautop = true ) {
406 406
 		$gravityview_view = GravityView_View::getInstance();
407 407
 
408 408
 		$is_search = false;
409 409
 
410
-		if( $gravityview_view && ( $gravityview_view->curr_start || $gravityview_view->curr_end || $gravityview_view->curr_search ) ) {
410
+		if ( $gravityview_view && ( $gravityview_view->curr_start || $gravityview_view->curr_end || $gravityview_view->curr_search ) ) {
411 411
 			$is_search = true;
412 412
 		}
413 413
 
414
-		if($is_search) {
415
-			$output = __('This search returned no results.', 'gravityview');
414
+		if ( $is_search ) {
415
+			$output = __( 'This search returned no results.', 'gravityview' );
416 416
 		} else {
417
-			$output = __('No entries match your request.', 'gravityview');
417
+			$output = __( 'No entries match your request.', 'gravityview' );
418 418
 		}
419 419
 
420 420
 		/**
@@ -422,9 +422,9 @@  discard block
 block discarded – undo
422 422
 		 * @param string $output The existing "No Entries" text
423 423
 		 * @param boolean $is_search Is the current page a search result, or just a multiple entries screen?
424 424
 		 */
425
-		$output = apply_filters( 'gravitview_no_entries_text', $output, $is_search);
425
+		$output = apply_filters( 'gravitview_no_entries_text', $output, $is_search );
426 426
 
427
-		return $wpautop ? wpautop($output) : $output;
427
+		return $wpautop ? wpautop( $output ) : $output;
428 428
 	}
429 429
 
430 430
 	/**
@@ -441,37 +441,37 @@  discard block
 block discarded – undo
441 441
 
442 442
 		$gravityview_view = GravityView_View::getInstance();
443 443
 
444
-		if( empty( $post_id ) ) {
444
+		if ( empty( $post_id ) ) {
445 445
 
446 446
 			$post_id = false;
447 447
 
448 448
 			// DataTables passes the Post ID
449
-			if( defined('DOING_AJAX') && DOING_AJAX ) {
449
+			if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
450 450
 
451
-				$post_id = isset( $_POST['post_id'] ) ? (int)$_POST['post_id'] : false;
451
+				$post_id = isset( $_POST[ 'post_id' ] ) ? (int)$_POST[ 'post_id' ] : false;
452 452
 
453 453
 			} else {
454 454
 
455 455
 				// The Post ID has been passed via the shortcode
456
-				if( !empty( $gravityview_view ) && $gravityview_view->getPostId() ) {
456
+				if ( ! empty( $gravityview_view ) && $gravityview_view->getPostId() ) {
457 457
 
458 458
 					$post_id = $gravityview_view->getPostId();
459 459
 
460 460
 				} else {
461 461
 
462 462
 					// This is a GravityView post type
463
-					if( GravityView_frontend::getInstance()->isGravityviewPostType() ) {
463
+					if ( GravityView_frontend::getInstance()->isGravityviewPostType() ) {
464 464
 
465 465
 						$post_id = isset( $gravityview_view ) ? $gravityview_view->getViewId() : $post->ID;
466 466
 
467 467
 					} else {
468 468
 
469 469
 						// This is an embedded GravityView; use the embedded post's ID as the base.
470
-						if( GravityView_frontend::getInstance()->isPostHasShortcode() && is_a( $post, 'WP_Post' ) ) {
470
+						if ( GravityView_frontend::getInstance()->isPostHasShortcode() && is_a( $post, 'WP_Post' ) ) {
471 471
 
472 472
 							$post_id = $post->ID;
473 473
 
474
-						} elseif( $gravityview_view->getViewId() ) {
474
+						} elseif ( $gravityview_view->getViewId() ) {
475 475
 
476 476
 							// The GravityView has been embedded in a widget or in a template, and
477 477
 							// is not in the current content. Thus, we defer to the View's own ID.
@@ -486,36 +486,36 @@  discard block
 block discarded – undo
486 486
 		}
487 487
 
488 488
 		// No post ID, get outta here.
489
-		if( empty( $post_id ) ) {
489
+		if ( empty( $post_id ) ) {
490 490
 			return NULL;
491 491
 		}
492 492
 
493 493
 		// If we've saved the permalink in memory, use it
494 494
 		// @since 1.3
495
-		$link = wp_cache_get( 'gv_directory_link_'.$post_id );
495
+		$link = wp_cache_get( 'gv_directory_link_' . $post_id );
496 496
 
497
-		if( empty( $link ) ) {
497
+		if ( empty( $link ) ) {
498 498
 
499 499
 			$link = get_permalink( $post_id );
500 500
 
501 501
 			// If not yet saved, cache the permalink.
502 502
 			// @since 1.3
503
-			wp_cache_set( 'gv_directory_link_'.$post_id, $link );
503
+			wp_cache_set( 'gv_directory_link_' . $post_id, $link );
504 504
 
505 505
 		}
506 506
 
507 507
 		// Deal with returning to proper pagination for embedded views
508
-		if( $link && $add_query_args ) {
508
+		if ( $link && $add_query_args ) {
509 509
 
510 510
 			$args = array();
511 511
 
512
-			if( $pagenum = rgget('pagenum') ) {
513
-				$args['pagenum'] = intval( $pagenum );
512
+			if ( $pagenum = rgget( 'pagenum' ) ) {
513
+				$args[ 'pagenum' ] = intval( $pagenum );
514 514
 			}
515 515
 
516
-			if( $sort = rgget('sort') ) {
517
-				$args['sort'] = $sort;
518
-				$args['dir'] = rgget('dir');
516
+			if ( $sort = rgget( 'sort' ) ) {
517
+				$args[ 'sort' ] = $sort;
518
+				$args[ 'dir' ] = rgget( 'dir' );
519 519
 			}
520 520
 
521 521
 			$link = add_query_arg( $args, $link );
@@ -546,7 +546,7 @@  discard block
 block discarded – undo
546 546
 	private static function get_custom_entry_slug( $id, $entry = array() ) {
547 547
 
548 548
 		// Generate an unique hash to use as the default value
549
-		$slug = substr( wp_hash( $id, 'gravityview'.$id ), 0, 8 );
549
+		$slug = substr( wp_hash( $id, 'gravityview' . $id ), 0, 8 );
550 550
 
551 551
 		/**
552 552
 		 * @filter `gravityview_entry_slug` Modify the unique hash ID generated, if you want to improve usability or change the format. This will allow for custom URLs, such as `{entryid}-{first-name}` or even, if unique, `{first-name}-{last-name}`
@@ -557,7 +557,7 @@  discard block
 block discarded – undo
557 557
 		$slug = apply_filters( 'gravityview_entry_slug', $slug, $id, $entry );
558 558
 
559 559
 		// Make sure we have something - use the original ID as backup.
560
-		if( empty( $slug ) ) {
560
+		if ( empty( $slug ) ) {
561 561
 			$slug = $id;
562 562
 		}
563 563
 
@@ -586,7 +586,7 @@  discard block
 block discarded – undo
586 586
 		 * @filter `gravityview_custom_entry_slug` Whether to enable and use custom entry slugs.
587 587
 		 * @param boolean True: Allow for slugs based on entry values. False: always use entry IDs (default)
588 588
 		 */
589
-		$custom = apply_filters('gravityview_custom_entry_slug', false );
589
+		$custom = apply_filters( 'gravityview_custom_entry_slug', false );
590 590
 
591 591
 		// If we're using custom slug...
592 592
 		if ( $custom ) {
@@ -600,8 +600,8 @@  discard block
 block discarded – undo
600 600
 			// If it does have a hash set, and the hash is expected, use it.
601 601
 			// This check allows users to change the hash structure using the
602 602
 			// gravityview_entry_hash filter and have the old hashes expire.
603
-			if( empty( $value ) || $value !== $hash ) {
604
-				do_action( 'gravityview_log_debug', __METHOD__ . ' - Setting hash for entry "'.$id_or_string.'": ' . $hash );
603
+			if ( empty( $value ) || $value !== $hash ) {
604
+				do_action( 'gravityview_log_debug', __METHOD__ . ' - Setting hash for entry "' . $id_or_string . '": ' . $hash );
605 605
 				gform_update_meta( $id_or_string, 'gravityview_unique_id', $hash, rgar( $entry, 'form_id' ) );
606 606
 			}
607 607
 
@@ -627,15 +627,15 @@  discard block
 block discarded – undo
627 627
          * @param boolean $custom Should we process the custom entry slug?
628 628
          */
629 629
         $custom = apply_filters( 'gravityview_custom_entry_slug', false );
630
-        if( $custom ) {
630
+        if ( $custom ) {
631 631
             // create the gravityview_unique_id and save it
632 632
 
633 633
             // Get the entry hash
634
-            $hash = self::get_custom_entry_slug( $entry['id'], $entry );
634
+            $hash = self::get_custom_entry_slug( $entry[ 'id' ], $entry );
635 635
 
636
-	        do_action( 'gravityview_log_debug', __METHOD__ . ' - Setting hash for entry "'.$entry['id'].'": ' . $hash );
636
+	        do_action( 'gravityview_log_debug', __METHOD__ . ' - Setting hash for entry "' . $entry[ 'id' ] . '": ' . $hash );
637 637
 
638
-            gform_update_meta( $entry['id'], 'gravityview_unique_id', $hash, rgar( $entry, 'form_id' ) );
638
+            gform_update_meta( $entry[ 'id' ], 'gravityview_unique_id', $hash, rgar( $entry, 'form_id' ) );
639 639
 
640 640
         }
641 641
     }
@@ -652,14 +652,14 @@  discard block
 block discarded – undo
652 652
 	 */
653 653
 	public static function entry_link( $entry, $post_id = NULL, $add_directory_args = true ) {
654 654
 
655
-		if( ! empty( $entry ) && ! is_array( $entry ) ) {
655
+		if ( ! empty( $entry ) && ! is_array( $entry ) ) {
656 656
 			$entry = GVCommon::get_entry( $entry );
657
-		} else if( empty( $entry ) ) {
657
+		} else if ( empty( $entry ) ) {
658 658
 			$entry = GravityView_frontend::getInstance()->getEntry();
659 659
 		}
660 660
 
661 661
 		// Second parameter used to be passed as $field; this makes sure it's not an array
662
-		if( !is_numeric( $post_id ) ) {
662
+		if ( ! is_numeric( $post_id ) ) {
663 663
 			$post_id = NULL;
664 664
 		}
665 665
 
@@ -667,7 +667,7 @@  discard block
 block discarded – undo
667 667
 		$directory_link = self::directory_link( $post_id, false );
668 668
 
669 669
 		// No post ID? Get outta here.
670
-		if( empty( $directory_link ) ) {
670
+		if ( empty( $directory_link ) ) {
671 671
 			return '';
672 672
 		}
673 673
 
@@ -678,9 +678,9 @@  discard block
 block discarded – undo
678 678
 			$query_arg_name = GravityView_Post_Types::get_entry_var_name();
679 679
 		}
680 680
 
681
-		$entry_slug = self::get_entry_slug( $entry['id'], $entry );
681
+		$entry_slug = self::get_entry_slug( $entry[ 'id' ], $entry );
682 682
 
683
-		if( get_option('permalink_structure') && !is_preview() ) {
683
+		if ( get_option( 'permalink_structure' ) && ! is_preview() ) {
684 684
 
685 685
 			$args = array();
686 686
 
@@ -690,9 +690,9 @@  discard block
 block discarded – undo
690 690
 			 */
691 691
 			$link_parts = explode( '?', $directory_link );
692 692
 
693
-			$query = !empty( $link_parts[1] ) ? '?'.$link_parts[1] : '';
693
+			$query = ! empty( $link_parts[ 1 ] ) ? '?' . $link_parts[ 1 ] : '';
694 694
 
695
-			$directory_link = trailingslashit( $link_parts[0] ) . $query_arg_name . '/'. $entry_slug .'/' . $query;
695
+			$directory_link = trailingslashit( $link_parts[ 0 ] ) . $query_arg_name . '/' . $entry_slug . '/' . $query;
696 696
 
697 697
 		} else {
698 698
 
@@ -702,18 +702,18 @@  discard block
 block discarded – undo
702 702
 		/**
703 703
 		 * @since 1.7.3
704 704
 		 */
705
-		if( $add_directory_args ) {
705
+		if ( $add_directory_args ) {
706 706
 
707
-			if( !empty( $_GET['pagenum'] ) ) {
708
-				$args['pagenum'] = intval( $_GET['pagenum'] );
707
+			if ( ! empty( $_GET[ 'pagenum' ] ) ) {
708
+				$args[ 'pagenum' ] = intval( $_GET[ 'pagenum' ] );
709 709
 			}
710 710
 
711 711
 			/**
712 712
 			 * @since 1.7
713 713
 			 */
714
-			if( $sort = rgget('sort') ) {
715
-				$args['sort'] = $sort;
716
-				$args['dir'] = rgget('dir');
714
+			if ( $sort = rgget( 'sort' ) ) {
715
+				$args[ 'sort' ] = $sort;
716
+				$args[ 'dir' ] = rgget( 'dir' );
717 717
 			}
718 718
 
719 719
 		}
@@ -725,12 +725,12 @@  discard block
 block discarded – undo
725 725
 		 */
726 726
 		if ( defined( 'GRAVITYVIEW_FUTURE_CORE_LOADED' ) ) {
727 727
 			if ( gravityview()->views->count() > 1 ) {
728
-				$args['gvid'] = gravityview_get_view_id();
728
+				$args[ 'gvid' ] = gravityview_get_view_id();
729 729
 			}
730 730
 		} else {
731 731
 			/** Deprecated, do not use has_multiple_views(), please. */
732 732
 			if ( class_exists( 'GravityView_View_Data' ) && GravityView_View_Data::getInstance()->has_multiple_views() ) {
733
-				$args['gvid'] = gravityview_get_view_id();
733
+				$args[ 'gvid' ] = gravityview_get_view_id();
734 734
 			}
735 735
 		}
736 736
 
@@ -749,7 +749,7 @@  discard block
 block discarded – undo
749 749
 }
750 750
 
751 751
 function gv_class( $field, $form = NULL, $entry = array() ) {
752
-	return GravityView_API::field_class( $field, $form, $entry  );
752
+	return GravityView_API::field_class( $field, $form, $entry );
753 753
 }
754 754
 
755 755
 /**
@@ -771,15 +771,15 @@  discard block
 block discarded – undo
771 771
 
772 772
 	$default_css_class = ! empty( $view_id ) ? sprintf( 'gv-container gv-container-%d', $view_id ) : 'gv-container';
773 773
 
774
-	if( GravityView_View::getInstance()->isHideUntilSearched() ) {
774
+	if ( GravityView_View::getInstance()->isHideUntilSearched() ) {
775 775
 		$default_css_class .= ' hidden';
776 776
 	}
777 777
 
778
-	if( 0 === GravityView_View::getInstance()->getTotalEntries() ) {
778
+	if ( 0 === GravityView_View::getInstance()->getTotalEntries() ) {
779 779
 		$default_css_class .= ' gv-container-no-results';
780 780
 	}
781 781
 
782
-	$css_class = trim( $passed_css_class . ' '. $default_css_class );
782
+	$css_class = trim( $passed_css_class . ' ' . $default_css_class );
783 783
 
784 784
 	/**
785 785
 	 * @filter `gravityview/render/container/class` Modify the CSS class to be added to the wrapper <div> of a View
@@ -790,7 +790,7 @@  discard block
 block discarded – undo
790 790
 
791 791
 	$css_class = gravityview_sanitize_html_class( $css_class );
792 792
 
793
-	if( $echo ) {
793
+	if ( $echo ) {
794 794
 		echo $css_class;
795 795
 	}
796 796
 
@@ -801,7 +801,7 @@  discard block
 block discarded – undo
801 801
 
802 802
 	$value = GravityView_API::field_value( $entry, $field );
803 803
 
804
-	if( $value === '' ) {
804
+	if ( $value === '' ) {
805 805
 		/**
806 806
 		 * @filter `gravityview_empty_value` What to display when a field is empty
807 807
 		 * @param string $value (empty string)
@@ -820,7 +820,7 @@  discard block
 block discarded – undo
820 820
 	return GravityView_API::entry_link( $entry, $post_id );
821 821
 }
822 822
 
823
-function gv_no_results($wpautop = true) {
823
+function gv_no_results( $wpautop = true ) {
824 824
 	return GravityView_API::no_results( $wpautop );
825 825
 }
826 826
 
@@ -841,7 +841,7 @@  discard block
 block discarded – undo
841 841
 	 */
842 842
 	$href = apply_filters( 'gravityview_go_back_url', $href );
843 843
 
844
-	if( empty( $href ) ) { return NULL; }
844
+	if ( empty( $href ) ) { return NULL; }
845 845
 
846 846
 	// calculate link label
847 847
 	$gravityview_view = GravityView_View::getInstance();
@@ -857,7 +857,7 @@  discard block
 block discarded – undo
857 857
 
858 858
 	$link = gravityview_get_link( $href, esc_html( $label ), array(
859 859
 		'data-viewid' => $gravityview_view->getViewId()
860
-	));
860
+	) );
861 861
 
862 862
 	return $link;
863 863
 }
@@ -876,7 +876,7 @@  discard block
 block discarded – undo
876 876
  */
877 877
 function gravityview_get_field_value( $entry, $field_id, $display_value ) {
878 878
 
879
-	if( floatval( $field_id ) === floor( floatval( $field_id ) ) ) {
879
+	if ( floatval( $field_id ) === floor( floatval( $field_id ) ) ) {
880 880
 
881 881
 		// For the complete field value as generated by Gravity Forms
882 882
 		return $display_value;
@@ -906,16 +906,16 @@  discard block
 block discarded – undo
906 906
 
907 907
 	$terms = explode( ', ', $value );
908 908
 
909
-	foreach ($terms as $term_name ) {
909
+	foreach ( $terms as $term_name ) {
910 910
 
911 911
 		// If we're processing a category,
912
-		if( $taxonomy === 'category' ) {
912
+		if ( $taxonomy === 'category' ) {
913 913
 
914 914
 			// Use rgexplode to prevent errors if : doesn't exist
915 915
 			list( $term_name, $term_id ) = rgexplode( ':', $value, 2 );
916 916
 
917 917
 			// The explode was succesful; we have the category ID
918
-			if( !empty( $term_id )) {
918
+			if ( ! empty( $term_id ) ) {
919 919
 				$term = get_term_by( 'id', $term_id, $taxonomy );
920 920
 			} else {
921 921
 			// We have to fall back to the name
@@ -928,7 +928,7 @@  discard block
 block discarded – undo
928 928
 		}
929 929
 
930 930
 		// There's still a tag/category here.
931
-		if( $term ) {
931
+		if ( $term ) {
932 932
 
933 933
 			$term_link = get_term_link( $term, $taxonomy );
934 934
 
@@ -937,11 +937,11 @@  discard block
 block discarded – undo
937 937
 			    continue;
938 938
 			}
939 939
 
940
-			$output[] = gravityview_get_link( $term_link, esc_html( $term->name ) );
940
+			$output[ ] = gravityview_get_link( $term_link, esc_html( $term->name ) );
941 941
 		}
942 942
 	}
943 943
 
944
-	return implode(', ', $output );
944
+	return implode( ', ', $output );
945 945
 }
946 946
 
947 947
 /**
@@ -955,8 +955,8 @@  discard block
 block discarded – undo
955 955
 
956 956
 	$output = get_the_term_list( $post_id, $taxonomy, NULL, ', ' );
957 957
 
958
-	if( empty( $link ) ) {
959
-		return strip_tags( $output);
958
+	if ( empty( $link ) ) {
959
+		return strip_tags( $output );
960 960
 	}
961 961
 
962 962
 	return $output;
@@ -975,7 +975,7 @@  discard block
 block discarded – undo
975 975
 	$fe = GravityView_frontend::getInstance();
976 976
 
977 977
 	// Solve problem when loading content via admin-ajax.php
978
-	if( ! $fe->getGvOutputData() ) {
978
+	if ( ! $fe->getGvOutputData() ) {
979 979
 
980 980
 		do_action( 'gravityview_log_debug', '[gravityview_get_current_views] gv_output_data not defined; parsing content.' );
981 981
 
@@ -983,7 +983,7 @@  discard block
 block discarded – undo
983 983
 	}
984 984
 
985 985
 	// Make 100% sure that we're dealing with a properly called situation
986
-	if( !is_a( $fe->getGvOutputData(), 'GravityView_View_Data' ) ) {
986
+	if ( ! is_a( $fe->getGvOutputData(), 'GravityView_View_Data' ) ) {
987 987
 
988 988
 		do_action( 'gravityview_log_debug', '[gravityview_get_current_views] gv_output_data not an object or get_view not callable.', $fe->getGvOutputData() );
989 989
 
@@ -1091,11 +1091,11 @@  discard block
 block discarded – undo
1091 1091
 	 */
1092 1092
 	$is_edit_entry = apply_filters( 'gravityview_is_edit_entry', false );
1093 1093
 
1094
-	if( $is_edit_entry ) {
1094
+	if ( $is_edit_entry ) {
1095 1095
 		$context = 'edit';
1096
-	} else if( class_exists( 'GravityView_frontend' ) && $single = GravityView_frontend::is_single_entry() ) {
1096
+	} else if ( class_exists( 'GravityView_frontend' ) && $single = GravityView_frontend::is_single_entry() ) {
1097 1097
 		$context = 'single';
1098
-	} else if( class_exists( 'GravityView_View' ) ) {
1098
+	} else if ( class_exists( 'GravityView_View' ) ) {
1099 1099
 		$context = GravityView_View::getInstance()->getContext();
1100 1100
 	}
1101 1101
 
@@ -1123,12 +1123,12 @@  discard block
 block discarded – undo
1123 1123
 function gravityview_get_files_array( $value, $gv_class = '' ) {
1124 1124
 	/** @define "GRAVITYVIEW_DIR" "../" */
1125 1125
 
1126
-	if( !class_exists( 'GravityView_Field' ) ) {
1127
-		include_once( GRAVITYVIEW_DIR .'includes/fields/class-gravityview-field.php' );
1126
+	if ( ! class_exists( 'GravityView_Field' ) ) {
1127
+		include_once( GRAVITYVIEW_DIR . 'includes/fields/class-gravityview-field.php' );
1128 1128
 	}
1129 1129
 
1130
-	if( !class_exists( 'GravityView_Field_FileUpload' ) ) {
1131
-		include_once( GRAVITYVIEW_DIR .'includes/fields/fileupload.php' );
1130
+	if ( ! class_exists( 'GravityView_Field_FileUpload' ) ) {
1131
+		include_once( GRAVITYVIEW_DIR . 'includes/fields/fileupload.php' );
1132 1132
 	}
1133 1133
 
1134 1134
 	return GravityView_Field_FileUpload::get_files_array( $value, $gv_class );
@@ -1206,12 +1206,12 @@  discard block
 block discarded – undo
1206 1206
 	$args = apply_filters( 'gravityview/field_output/args', $args, $passed_args );
1207 1207
 
1208 1208
 	// Required fields.
1209
-	if ( empty( $args['field'] ) || empty( $args['form'] ) ) {
1209
+	if ( empty( $args[ 'field' ] ) || empty( $args[ 'form' ] ) ) {
1210 1210
 		do_action( 'gravityview_log_error', '[gravityview_field_output] Field or form are empty.', $args );
1211 1211
 		return '';
1212 1212
 	}
1213 1213
 
1214
-	$entry = empty( $args['entry'] ) ? array() : $args['entry'];
1214
+	$entry = empty( $args[ 'entry' ] ) ? array() : $args[ 'entry' ];
1215 1215
 
1216 1216
 	/**
1217 1217
 	 * Create the content variables for replacing.
@@ -1227,37 +1227,37 @@  discard block
 block discarded – undo
1227 1227
 		'field_id' => '',
1228 1228
 	);
1229 1229
 
1230
-	$context['value'] = gv_value( $entry, $args['field'] );
1230
+	$context[ 'value' ] = gv_value( $entry, $args[ 'field' ] );
1231 1231
 
1232 1232
 	// If the value is empty and we're hiding empty, return empty.
1233
-	if ( $context['value'] === '' && ! empty( $args['hide_empty'] ) ) {
1233
+	if ( $context[ 'value' ] === '' && ! empty( $args[ 'hide_empty' ] ) ) {
1234 1234
 		return '';
1235 1235
 	}
1236 1236
 
1237
-	if ( $context['value'] !== '' && ! empty( $args['wpautop'] ) ) {
1238
-		$context['value'] = wpautop( $context['value'] );
1237
+	if ( $context[ 'value' ] !== '' && ! empty( $args[ 'wpautop' ] ) ) {
1238
+		$context[ 'value' ] = wpautop( $context[ 'value' ] );
1239 1239
 	}
1240 1240
 
1241 1241
 	// Get width setting, if exists
1242
-	$context['width'] = GravityView_API::field_width( $args['field'] );
1242
+	$context[ 'width' ] = GravityView_API::field_width( $args[ 'field' ] );
1243 1243
 
1244 1244
 	// If replacing with CSS inline formatting, let's do it.
1245
-	$context['width:style'] = GravityView_API::field_width( $args['field'], 'width:' . $context['width'] . '%;' );
1245
+	$context[ 'width:style' ] = GravityView_API::field_width( $args[ 'field' ], 'width:' . $context[ 'width' ] . '%;' );
1246 1246
 
1247 1247
 	// Grab the Class using `gv_class`
1248
-	$context['class'] = gv_class( $args['field'], $args['form'], $entry );
1249
-	$context['field_id'] = GravityView_API::field_html_attr_id( $args['field'], $args['form'], $entry );
1248
+	$context[ 'class' ] = gv_class( $args[ 'field' ], $args[ 'form' ], $entry );
1249
+	$context[ 'field_id' ] = GravityView_API::field_html_attr_id( $args[ 'field' ], $args[ 'form' ], $entry );
1250 1250
 
1251 1251
 	// Get field label if needed
1252
-	if ( ! empty( $args['label_markup'] ) && ! empty( $args['field']['show_label'] ) ) {
1253
-		$context['label'] = str_replace( array( '{{label}}', '{{ label }}' ), '<span class="gv-field-label">{{ label_value }}</span>', $args['label_markup'] );
1252
+	if ( ! empty( $args[ 'label_markup' ] ) && ! empty( $args[ 'field' ][ 'show_label' ] ) ) {
1253
+		$context[ 'label' ] = str_replace( array( '{{label}}', '{{ label }}' ), '<span class="gv-field-label">{{ label_value }}</span>', $args[ 'label_markup' ] );
1254 1254
 	}
1255 1255
 
1256 1256
 	// Default Label value
1257
-	$context['label_value'] = gv_label( $args['field'], $entry );
1257
+	$context[ 'label_value' ] = gv_label( $args[ 'field' ], $entry );
1258 1258
 
1259
-	if ( empty( $context['label'] ) && ! empty( $context['label_value'] ) ){
1260
-		$context['label'] = '<span class="gv-field-label">{{ label_value }}</span>';
1259
+	if ( empty( $context[ 'label' ] ) && ! empty( $context[ 'label_value' ] ) ) {
1260
+		$context[ 'label' ] = '<span class="gv-field-label">{{ label_value }}</span>';
1261 1261
 	}
1262 1262
 
1263 1263
 	/**
@@ -1266,7 +1266,7 @@  discard block
 block discarded – undo
1266 1266
 	 * @param string $markup The HTML for the markup
1267 1267
 	 * @param array $args All args for the field output
1268 1268
 	 */
1269
-	$html = apply_filters( 'gravityview/field_output/pre_html', $args['markup'], $args );
1269
+	$html = apply_filters( 'gravityview/field_output/pre_html', $args[ 'markup' ], $args );
1270 1270
 
1271 1271
 	/**
1272 1272
 	 * @filter `gravityview/field_output/open_tag` Modify the opening tags for the template content placeholders
@@ -1289,7 +1289,7 @@  discard block
 block discarded – undo
1289 1289
 	foreach ( $context as $tag => $value ) {
1290 1290
 
1291 1291
 		// If the tag doesn't exist just skip it
1292
-		if ( false === strpos( $html, $open_tag . $tag . $close_tag ) && false === strpos( $html, $open_tag . ' ' . $tag . ' ' . $close_tag ) ){
1292
+		if ( false === strpos( $html, $open_tag . $tag . $close_tag ) && false === strpos( $html, $open_tag . ' ' . $tag . ' ' . $close_tag ) ) {
1293 1293
 			continue;
1294 1294
 		}
1295 1295
 
Please login to merge, or discard this patch.
includes/class-oembed.php 1 patch
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	 */
43 43
 	static function getInstance() {
44 44
 
45
-		if( empty( self::$instance ) ) {
45
+		if ( empty( self::$instance ) ) {
46 46
 			self::$instance = new self;
47 47
 
48 48
 			self::$instance->initialize();
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 		// Catch either
100 100
 		$match_regex = "(?:{$using_permalinks}|{$not_using_permalinks})";
101 101
 
102
-		return '#'.$match_regex.'#i';
102
+		return '#' . $match_regex . '#i';
103 103
 	}
104 104
 
105 105
 	/**
@@ -118,18 +118,18 @@  discard block
 block discarded – undo
118 118
 
119 119
 		$post_id = url_to_postid( $url );
120 120
 
121
-		if( empty( $post_id ) ) {
121
+		if ( empty( $post_id ) ) {
122 122
 
123 123
 			$args = array(
124 124
 				'post_status' => 'publish',
125 125
 				'name' => $slug,
126
-				'post_type' => array('any', 'gravityview'),
126
+				'post_type' => array( 'any', 'gravityview' ),
127 127
 			);
128 128
 
129 129
 			$posts = get_posts( $args );
130 130
 
131
-			if( !empty( $posts ) ) {
132
-				$post_id = $posts[0]->ID;
131
+			if ( ! empty( $posts ) ) {
132
+				$post_id = $posts[ 0 ]->ID;
133 133
 			}
134 134
 		}
135 135
 
@@ -162,17 +162,17 @@  discard block
 block discarded – undo
162 162
 	public function render_handler( $matches, $attr, $url, $rawattr ) {
163 163
 
164 164
 		// If not using permalinks, re-assign values for matching groups
165
-		if( !empty( $matches['entry_slug2'] ) ) {
166
-			$matches['is_cpt'] = $matches['is_cpt2'];
167
-			$matches['slug'] = $matches['slug2'];
168
-			$matches['entry_slug'] = $matches['entry_slug2'];
169
-			unset( $matches['is_cpt2'], $matches['slug2'], $matches['entry_slug2'] );
165
+		if ( ! empty( $matches[ 'entry_slug2' ] ) ) {
166
+			$matches[ 'is_cpt' ] = $matches[ 'is_cpt2' ];
167
+			$matches[ 'slug' ] = $matches[ 'slug2' ];
168
+			$matches[ 'entry_slug' ] = $matches[ 'entry_slug2' ];
169
+			unset( $matches[ 'is_cpt2' ], $matches[ 'slug2' ], $matches[ 'entry_slug2' ] );
170 170
 		}
171 171
 
172 172
 		// No Entry was found
173
-		if( empty( $matches['entry_slug'] ) ) {
173
+		if ( empty( $matches[ 'entry_slug' ] ) ) {
174 174
 
175
-			do_action('gravityview_log_error', 'GravityView_oEmbed[render_handler] $entry_slug not parsed by regex.', $matches );
175
+			do_action( 'gravityview_log_error', 'GravityView_oEmbed[render_handler] $entry_slug not parsed by regex.', $matches );
176 176
 
177 177
 			return '';
178 178
 		}
@@ -182,11 +182,11 @@  discard block
 block discarded – undo
182 182
 		// Setup the data used
183 183
 		$this->set_vars( $matches, $attr, $url, $rawattr );
184 184
 
185
-		if( is_admin() && !$this->is_full_oembed_preview ) {
185
+		if ( is_admin() && ! $this->is_full_oembed_preview ) {
186 186
 			$return = $this->render_admin( $matches, $attr, $url, $rawattr );
187 187
 		} else {
188 188
 
189
-			if( $this->is_full_oembed_preview ) {
189
+			if ( $this->is_full_oembed_preview ) {
190 190
 				$return .= $this->generate_preview_notice();
191 191
 			}
192 192
 
@@ -205,8 +205,8 @@  discard block
 block discarded – undo
205 205
 	private function generate_preview_notice() {
206 206
 		$floaty = GravityView_Admin::get_floaty();
207 207
 		$title = esc_html__( 'This will look better when it is embedded.', 'gravityview' );
208
-		$message = esc_html__('Styles don\'t get loaded when being previewed, so the content below will look strange. Don\'t be concerned!', 'gravityview');
209
-		return '<div class="updated notice">'. $floaty. '<h3>'.$title.'</h3><p>'.$message.'</p><br style="clear:both;" /></div>';
208
+		$message = esc_html__( 'Styles don\'t get loaded when being previewed, so the content below will look strange. Don\'t be concerned!', 'gravityview' );
209
+		return '<div class="updated notice">' . $floaty . '<h3>' . $title . '</h3><p>' . $message . '</p><br style="clear:both;" /></div>';
210 210
 	}
211 211
 
212 212
 	/**
@@ -219,14 +219,14 @@  discard block
 block discarded – undo
219 219
 	 */
220 220
 	private function set_vars( $matches, $attr, $url, $rawattr ) {
221 221
 
222
-		$this->entry_id = $matches['entry_slug'];
222
+		$this->entry_id = $matches[ 'entry_slug' ];
223 223
 
224
-		$post_id = $this->get_postid_from_url_and_slug( $url, $matches['slug'] );
224
+		$post_id = $this->get_postid_from_url_and_slug( $url, $matches[ 'slug' ] );
225 225
 
226 226
 		// The URL didn't have the View Custom Post Type structure.
227
-		if( empty( $matches['is_cpt'] ) || $matches['is_cpt'] !== 'gravityview' ) {
227
+		if ( empty( $matches[ 'is_cpt' ] ) || $matches[ 'is_cpt' ] !== 'gravityview' ) {
228 228
 
229
-			do_action('gravityview_log_debug', 'GravityView_oEmbed[render_handler] Embedding an entry inside a post or page', $matches );
229
+			do_action( 'gravityview_log_debug', 'GravityView_oEmbed[render_handler] Embedding an entry inside a post or page', $matches );
230 230
 
231 231
 			if ( defined( 'GRAVITYVIEW_FUTURE_CORE_LOADED' ) && $post = get_post( $post_id ) ) {
232 232
 				$views = gv_shim_GV_View_Collection_from_post( $post );
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
 						}
240 240
 					}
241 241
 
242
-					$this->view_id = $views[0]->ID;
242
+					$this->view_id = $views[ 0 ]->ID;
243 243
 				}
244 244
 			} else {
245 245
 				/** Deprecated. */
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
 		}
254 254
 
255 255
 		// The inline content has $_POST['type'] set to "embed", while the "Add Media" modal doesn't set that.
256
-		$this->is_full_oembed_preview = ( isset( $_POST['action'] ) && $_POST['action'] === 'parse-embed' && !isset( $_POST['type'] ) );
256
+		$this->is_full_oembed_preview = ( isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] === 'parse-embed' && ! isset( $_POST[ 'type' ] ) );
257 257
 	}
258 258
 
259 259
 	/**
@@ -271,15 +271,15 @@  discard block
 block discarded – undo
271 271
 		// Floaty the astronaut
272 272
 		$image = GravityView_Admin::get_floaty();
273 273
 
274
-		$embed_heading = sprintf( esc_html__('Embed Entry %d', 'gravityview'), $this->entry_id );
274
+		$embed_heading = sprintf( esc_html__( 'Embed Entry %d', 'gravityview' ), $this->entry_id );
275 275
 
276
-		$embed_text = sprintf( esc_html__('This entry will be displayed as it is configured in View %d', 'gravityview'), $this->view_id );
276
+		$embed_text = sprintf( esc_html__( 'This entry will be displayed as it is configured in View %d', 'gravityview' ), $this->view_id );
277 277
 
278 278
 		return '
279 279
 		<div class="loading-placeholder" style="background-color:#e6f0f5;">
280
-			<h3 style="margin:0; padding:0; font-family: -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, Oxygen-Sans, Ubuntu, Cantarell, \'Helvetica Neue\', sans-serif;">'.$image.$embed_heading.'</h3>
280
+			<h3 style="margin:0; padding:0; font-family: -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, Oxygen-Sans, Ubuntu, Cantarell, \'Helvetica Neue\', sans-serif;">'.$image . $embed_heading . '</h3>
281 281
 			<p style="margin:0; padding:0; font-family: -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, Oxygen-Sans, Ubuntu, Cantarell, \'Helvetica Neue\', sans-serif;">
282
-				'.$embed_text.'
282
+				'.$embed_text . '
283 283
 			</p>
284 284
 			<br style="clear: both;">
285 285
 		</div>';
@@ -334,14 +334,14 @@  discard block
 block discarded – undo
334 334
 	private function render_frontend( $matches, $attr, $url, $rawattr ) {
335 335
 
336 336
 		// If it's already been parsed, don't re-output it.
337
-		if( !empty( $this->output[ $this->entry_id ] ) ) {
337
+		if ( ! empty( $this->output[ $this->entry_id ] ) ) {
338 338
 			return $this->output[ $this->entry_id ];
339 339
 		}
340 340
 
341 341
 		$entry_output = $this->generate_entry_output();
342 342
 
343 343
 		// Wrap a container div around the output to allow for custom styling
344
-		$output = sprintf('<div class="gravityview-oembed gravityview-oembed-entry gravityview-oembed-entry-'.$this->entry_id.'">%s</div>', $entry_output );
344
+		$output = sprintf( '<div class="gravityview-oembed gravityview-oembed-entry gravityview-oembed-entry-' . $this->entry_id . '">%s</div>', $entry_output );
345 345
 
346 346
 		/**
347 347
 		 * @filter `gravityview/oembed/entry` Filter the output of the oEmbed entry embed
@@ -354,7 +354,7 @@  discard block
 block discarded – undo
354 354
 		 *  @var string $url The original URL that was matched by the regex. \n
355 355
 		 *  @var array $rawattr The original unmodified attributes.
356 356
 		 */
357
-		$output = apply_filters('gravityview/oembed/entry', $output, $this, compact( $entry_output, $matches, $attr, $url, $rawattr ) );
357
+		$output = apply_filters( 'gravityview/oembed/entry', $output, $this, compact( $entry_output, $matches, $attr, $url, $rawattr ) );
358 358
 
359 359
 		unset( $entry_output );
360 360
 
Please login to merge, or discard this patch.
includes/connector-functions.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -328,8 +328,8 @@  discard block
 block discarded – undo
328 328
  * @param  mixed $field_id Field ID or Field array
329 329
  * @return string field type
330 330
  */
331
-function gravityview_get_field_type(  $form = null , $field_id = '' ) {
332
-	return GVCommon::get_field_type(  $form, $field_id );
331
+function gravityview_get_field_type( $form = null, $field_id = '' ) {
332
+	return GVCommon::get_field_type( $form, $field_id );
333 333
 }
334 334
 
335 335
 
@@ -342,8 +342,8 @@  discard block
 block discarded – undo
342 342
  * @return string HTML of the output. Empty string if $view_id is empty.
343 343
  */
344 344
 function get_gravityview( $view_id = '', $atts = array() ) {
345
-	if( !empty( $view_id ) ) {
346
-		$atts['id'] = $view_id;
345
+	if ( ! empty( $view_id ) ) {
346
+		$atts[ 'id' ] = $view_id;
347 347
 		$args = wp_parse_args( $atts, defined( 'GRAVITYVIEW_FUTURE_CORE_LOADED' ) ? gv_shim_GV_View_Settings_defaults() : GravityView_View_Data::get_default_args() );
348 348
 		$GravityView_frontend = GravityView_frontend::getInstance();
349 349
 		$GravityView_frontend->setGvOutputData( GravityView_View_Data::getInstance( $view_id ) );
@@ -386,19 +386,19 @@  discard block
 block discarded – undo
386 386
  */
387 387
 function gravityview_view_has_single_checkbox_or_radio( $form, $view_fields ) {
388 388
 
389
-	if( $form_fields = GFFormsModel::get_fields_by_type( $form, array( 'checkbox', 'radio' ) ) ) {
389
+	if ( $form_fields = GFFormsModel::get_fields_by_type( $form, array( 'checkbox', 'radio' ) ) ) {
390 390
 
391 391
 		/** @var GF_Field_Radio|GF_Field_Checkbox $form_field */
392
-		foreach( $form_fields as $form_field ) {
392
+		foreach ( $form_fields as $form_field ) {
393 393
 			$field_id = $form_field->id;
394
-			foreach( $view_fields as $zone ) {
394
+			foreach ( $view_fields as $zone ) {
395 395
 
396 396
 				// ACF compatibility; ACF-added fields aren't arrays
397 397
 				if ( ! is_array( $zone ) ) { continue; }
398 398
 
399
-				foreach( $zone as $field ) {
399
+				foreach ( $zone as $field ) {
400 400
 					// If it's an input, not the parent and the parent ID matches a checkbox or radio
401
-					if( ( strpos( $field['id'], '.' ) > 0 ) && floor( $field['id'] ) === floor( $field_id ) ) {
401
+					if ( ( strpos( $field[ 'id' ], '.' ) > 0 ) && floor( $field[ 'id' ] ) === floor( $field_id ) ) {
402 402
 						return true;
403 403
 					}
404 404
 				}
Please login to merge, or discard this patch.
includes/extensions/edit-entry/class-edit-entry-render.php 1 patch
Indentation   +1604 added lines, -1604 removed lines patch added patch discarded remove patch
@@ -10,20 +10,20 @@  discard block
 block discarded – undo
10 10
  */
11 11
 
12 12
 if ( ! defined( 'WPINC' ) ) {
13
-    die;
13
+	die;
14 14
 }
15 15
 
16 16
 class GravityView_Edit_Entry_Render {
17 17
 
18
-    /**
19
-     * @var GravityView_Edit_Entry
20
-     */
21
-    protected $loader;
18
+	/**
19
+	 * @var GravityView_Edit_Entry
20
+	 */
21
+	protected $loader;
22 22
 
23 23
 	/**
24 24
 	 * @var string String used to generate unique nonce for the entry/form/view combination. Allows access to edit page.
25 25
 	 */
26
-    static $nonce_key;
26
+	static $nonce_key;
27 27
 
28 28
 	/**
29 29
 	 * @since 1.9
@@ -37,12 +37,12 @@  discard block
 block discarded – undo
37 37
 	 */
38 38
 	private static $supports_save_and_continue = false;
39 39
 
40
-    /**
41
-     * Gravity Forms entry array
42
-     *
43
-     * @var array
44
-     */
45
-    public $entry;
40
+	/**
41
+	 * Gravity Forms entry array
42
+	 *
43
+	 * @var array
44
+	 */
45
+	public $entry;
46 46
 
47 47
 	/**
48 48
 	 * Gravity Forms entry array (it won't get changed during this class lifecycle)
@@ -51,132 +51,132 @@  discard block
 block discarded – undo
51 51
 	 */
52 52
 	private static $original_entry = array();
53 53
 
54
-    /**
55
-     * Gravity Forms form array (GravityView modifies the content through this class lifecycle)
56
-     *
57
-     * @var array
58
-     */
54
+	/**
55
+	 * Gravity Forms form array (GravityView modifies the content through this class lifecycle)
56
+	 *
57
+	 * @var array
58
+	 */
59 59
 	public $form;
60 60
 
61
-    /**
62
-     * Gravity Forms form array (it won't get changed during this class lifecycle)
63
-     * @since 1.16.2.1
64
-     * @var array
65
-     */
66
-    private static $original_form;
67
-
68
-    /**
69
-     * Gravity Forms form array after the form validation process
70
-     * @since 1.13
71
-     * @var array
72
-     */
61
+	/**
62
+	 * Gravity Forms form array (it won't get changed during this class lifecycle)
63
+	 * @since 1.16.2.1
64
+	 * @var array
65
+	 */
66
+	private static $original_form;
67
+
68
+	/**
69
+	 * Gravity Forms form array after the form validation process
70
+	 * @since 1.13
71
+	 * @var array
72
+	 */
73 73
 	public $form_after_validation = null;
74 74
 
75
-    /**
76
-     * Hold an array of GF field objects that have calculation rules
77
-     * @var array
78
-     */
75
+	/**
76
+	 * Hold an array of GF field objects that have calculation rules
77
+	 * @var array
78
+	 */
79 79
 	public $fields_with_calculation = array();
80 80
 
81
-    /**
82
-     * Gravity Forms form id
83
-     *
84
-     * @var int
85
-     */
81
+	/**
82
+	 * Gravity Forms form id
83
+	 *
84
+	 * @var int
85
+	 */
86 86
 	public $form_id;
87 87
 
88
-    /**
89
-     * ID of the current view
90
-     *
91
-     * @var int
92
-     */
88
+	/**
89
+	 * ID of the current view
90
+	 *
91
+	 * @var int
92
+	 */
93 93
 	public $view_id;
94 94
 
95
-    /**
96
-     * Updated entry is valid (GF Validation object)
97
-     *
98
-     * @var array
99
-     */
95
+	/**
96
+	 * Updated entry is valid (GF Validation object)
97
+	 *
98
+	 * @var array
99
+	 */
100 100
 	public $is_valid = NULL;
101 101
 
102
-    function __construct( GravityView_Edit_Entry $loader ) {
103
-        $this->loader = $loader;
104
-    }
105
-
106
-    function load() {
107
-
108
-        /** @define "GRAVITYVIEW_DIR" "../../../" */
109
-        include_once( GRAVITYVIEW_DIR .'includes/class-admin-approve-entries.php' );
110
-
111
-        // Don't display an embedded form when editing an entry
112
-        add_action( 'wp_head', array( $this, 'prevent_render_form' ) );
113
-        add_action( 'wp_footer', array( $this, 'prevent_render_form' ) );
114
-
115
-        // Stop Gravity Forms processing what is ours!
116
-        add_filter( 'wp', array( $this, 'prevent_maybe_process_form'), 8 );
117
-
118
-        add_filter( 'gravityview_is_edit_entry', array( $this, 'is_edit_entry') );
119
-
120
-        add_action( 'gravityview_edit_entry', array( $this, 'init' ) );
121
-
122
-        // Disable conditional logic if needed (since 1.9)
123
-        add_filter( 'gform_has_conditional_logic', array( $this, 'manage_conditional_logic' ), 10, 2 );
124
-
125
-        // Make sure GF doesn't validate max files (since 1.9)
126
-        add_filter( 'gform_plupload_settings', array( $this, 'modify_fileupload_settings' ), 10, 3 );
127
-
128
-        // Add fields expected by GFFormDisplay::validate()
129
-        add_filter( 'gform_pre_validation', array( $this, 'gform_pre_validation') );
130
-
131
-    }
132
-
133
-    /**
134
-     * Don't show any forms embedded on a page when GravityView is in Edit Entry mode
135
-     *
136
-     * Adds a `__return_empty_string` filter on the Gravity Forms shortcode on the `wp_head` action
137
-     * And then removes it on the `wp_footer` action
138
-     *
139
-     * @since 1.16.1
140
-     *
141
-     * @return void
142
-     */
143
-    public function prevent_render_form() {
144
-        if( $this->is_edit_entry() ) {
145
-            if( 'wp_head' === current_filter() ) {
146
-                add_filter( 'gform_shortcode_form', '__return_empty_string' );
147
-            } else {
148
-                remove_filter( 'gform_shortcode_form', '__return_empty_string' );
149
-            }
150
-        }
151
-    }
152
-
153
-    /**
154
-     * Because we're mimicking being a front-end Gravity Forms form while using a Gravity Forms
155
-     * backend form, we need to prevent them from saving twice.
156
-     * @return void
157
-     */
158
-    public function prevent_maybe_process_form() {
159
-
160
-        if( ! empty( $_POST ) ) {
161
-	        do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[prevent_maybe_process_form] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) );
162
-        }
163
-
164
-        if( $this->is_edit_entry_submission() ) {
165
-            remove_action( 'wp',  array( 'RGForms', 'maybe_process_form'), 9 );
166
-	        remove_action( 'wp',  array( 'GFForms', 'maybe_process_form'), 9 );
167
-        }
168
-    }
169
-
170
-    /**
171
-     * Is the current page an Edit Entry page?
172
-     * @return boolean
173
-     */
174
-    public function is_edit_entry() {
175
-
176
-        $is_edit_entry = GravityView_frontend::is_single_entry() && ! empty( $_GET['edit'] );
177
-
178
-        return ( $is_edit_entry || $this->is_edit_entry_submission() );
179
-    }
102
+	function __construct( GravityView_Edit_Entry $loader ) {
103
+		$this->loader = $loader;
104
+	}
105
+
106
+	function load() {
107
+
108
+		/** @define "GRAVITYVIEW_DIR" "../../../" */
109
+		include_once( GRAVITYVIEW_DIR .'includes/class-admin-approve-entries.php' );
110
+
111
+		// Don't display an embedded form when editing an entry
112
+		add_action( 'wp_head', array( $this, 'prevent_render_form' ) );
113
+		add_action( 'wp_footer', array( $this, 'prevent_render_form' ) );
114
+
115
+		// Stop Gravity Forms processing what is ours!
116
+		add_filter( 'wp', array( $this, 'prevent_maybe_process_form'), 8 );
117
+
118
+		add_filter( 'gravityview_is_edit_entry', array( $this, 'is_edit_entry') );
119
+
120
+		add_action( 'gravityview_edit_entry', array( $this, 'init' ) );
121
+
122
+		// Disable conditional logic if needed (since 1.9)
123
+		add_filter( 'gform_has_conditional_logic', array( $this, 'manage_conditional_logic' ), 10, 2 );
124
+
125
+		// Make sure GF doesn't validate max files (since 1.9)
126
+		add_filter( 'gform_plupload_settings', array( $this, 'modify_fileupload_settings' ), 10, 3 );
127
+
128
+		// Add fields expected by GFFormDisplay::validate()
129
+		add_filter( 'gform_pre_validation', array( $this, 'gform_pre_validation') );
130
+
131
+	}
132
+
133
+	/**
134
+	 * Don't show any forms embedded on a page when GravityView is in Edit Entry mode
135
+	 *
136
+	 * Adds a `__return_empty_string` filter on the Gravity Forms shortcode on the `wp_head` action
137
+	 * And then removes it on the `wp_footer` action
138
+	 *
139
+	 * @since 1.16.1
140
+	 *
141
+	 * @return void
142
+	 */
143
+	public function prevent_render_form() {
144
+		if( $this->is_edit_entry() ) {
145
+			if( 'wp_head' === current_filter() ) {
146
+				add_filter( 'gform_shortcode_form', '__return_empty_string' );
147
+			} else {
148
+				remove_filter( 'gform_shortcode_form', '__return_empty_string' );
149
+			}
150
+		}
151
+	}
152
+
153
+	/**
154
+	 * Because we're mimicking being a front-end Gravity Forms form while using a Gravity Forms
155
+	 * backend form, we need to prevent them from saving twice.
156
+	 * @return void
157
+	 */
158
+	public function prevent_maybe_process_form() {
159
+
160
+		if( ! empty( $_POST ) ) {
161
+			do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[prevent_maybe_process_form] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) );
162
+		}
163
+
164
+		if( $this->is_edit_entry_submission() ) {
165
+			remove_action( 'wp',  array( 'RGForms', 'maybe_process_form'), 9 );
166
+			remove_action( 'wp',  array( 'GFForms', 'maybe_process_form'), 9 );
167
+		}
168
+	}
169
+
170
+	/**
171
+	 * Is the current page an Edit Entry page?
172
+	 * @return boolean
173
+	 */
174
+	public function is_edit_entry() {
175
+
176
+		$is_edit_entry = GravityView_frontend::is_single_entry() && ! empty( $_GET['edit'] );
177
+
178
+		return ( $is_edit_entry || $this->is_edit_entry_submission() );
179
+	}
180 180
 
181 181
 	/**
182 182
 	 * Is the current page an Edit Entry page?
@@ -187,229 +187,229 @@  discard block
 block discarded – undo
187 187
 		return !empty( $_POST[ self::$nonce_field ] );
188 188
 	}
189 189
 
190
-    /**
191
-     * When Edit entry view is requested setup the vars
192
-     */
193
-    private function setup_vars() {
194
-        $gravityview_view = GravityView_View::getInstance();
190
+	/**
191
+	 * When Edit entry view is requested setup the vars
192
+	 */
193
+	private function setup_vars() {
194
+		$gravityview_view = GravityView_View::getInstance();
195 195
 
196 196
 
197
-        $entries = $gravityview_view->getEntries();
198
-	    self::$original_entry = $entries[0];
199
-	    $this->entry = $entries[0];
197
+		$entries = $gravityview_view->getEntries();
198
+		self::$original_entry = $entries[0];
199
+		$this->entry = $entries[0];
200 200
 
201
-        self::$original_form = $gravityview_view->getForm();
202
-        $this->form = $gravityview_view->getForm();
203
-        $this->form_id = $gravityview_view->getFormId();
204
-        $this->view_id = $gravityview_view->getViewId();
201
+		self::$original_form = $gravityview_view->getForm();
202
+		$this->form = $gravityview_view->getForm();
203
+		$this->form_id = $gravityview_view->getFormId();
204
+		$this->view_id = $gravityview_view->getViewId();
205 205
 
206
-        self::$nonce_key = GravityView_Edit_Entry::get_nonce_key( $this->view_id, $this->form_id, $this->entry['id'] );
207
-    }
206
+		self::$nonce_key = GravityView_Edit_Entry::get_nonce_key( $this->view_id, $this->form_id, $this->entry['id'] );
207
+	}
208 208
 
209 209
 
210
-    /**
211
-     * Load required files and trigger edit flow
212
-     *
213
-     * Run when the is_edit_entry returns true.
214
-     *
215
-     * @param GravityView_View_Data $gv_data GravityView Data object
216
-     * @return void
217
-     */
218
-    public function init( $gv_data ) {
210
+	/**
211
+	 * Load required files and trigger edit flow
212
+	 *
213
+	 * Run when the is_edit_entry returns true.
214
+	 *
215
+	 * @param GravityView_View_Data $gv_data GravityView Data object
216
+	 * @return void
217
+	 */
218
+	public function init( $gv_data ) {
219 219
 
220
-        require_once( GFCommon::get_base_path() . '/form_display.php' );
221
-        require_once( GFCommon::get_base_path() . '/entry_detail.php' );
220
+		require_once( GFCommon::get_base_path() . '/form_display.php' );
221
+		require_once( GFCommon::get_base_path() . '/entry_detail.php' );
222 222
 
223
-        $this->setup_vars();
223
+		$this->setup_vars();
224 224
 
225
-        // Multiple Views embedded, don't proceed if nonce fails
225
+		// Multiple Views embedded, don't proceed if nonce fails
226 226
 		$multiple_views = defined( 'GRAVITYVIEW_FUTURE_CORE_LOADED' ) ? gravityview()->views->count() > 1 : $gv_data->has_multiple_views();
227
-        if( $multiple_views && ! wp_verify_nonce( $_GET['edit'], self::$nonce_key ) ) {
228
-            do_action('gravityview_log_error', __METHOD__ . ': Nonce validation failed for the Edit Entry request; returning' );
229
-            return;
230
-        }
227
+		if( $multiple_views && ! wp_verify_nonce( $_GET['edit'], self::$nonce_key ) ) {
228
+			do_action('gravityview_log_error', __METHOD__ . ': Nonce validation failed for the Edit Entry request; returning' );
229
+			return;
230
+		}
231 231
 
232
-        // Sorry, you're not allowed here.
233
-        if( false === $this->user_can_edit_entry( true ) ) {
234
-            do_action('gravityview_log_error', __METHOD__ . ': User is not allowed to edit this entry; returning', $this->entry );
235
-            return;
236
-        }
232
+		// Sorry, you're not allowed here.
233
+		if( false === $this->user_can_edit_entry( true ) ) {
234
+			do_action('gravityview_log_error', __METHOD__ . ': User is not allowed to edit this entry; returning', $this->entry );
235
+			return;
236
+		}
237 237
 
238
-        $this->print_scripts();
238
+		$this->print_scripts();
239 239
 
240
-        $this->process_save();
240
+		$this->process_save();
241 241
 
242
-        $this->edit_entry_form();
242
+		$this->edit_entry_form();
243 243
 
244
-    }
244
+	}
245 245
 
246 246
 
247
-    /**
248
-     * Force Gravity Forms to output scripts as if it were in the admin
249
-     * @return void
250
-     */
251
-    private function print_scripts() {
252
-        $gravityview_view = GravityView_View::getInstance();
247
+	/**
248
+	 * Force Gravity Forms to output scripts as if it were in the admin
249
+	 * @return void
250
+	 */
251
+	private function print_scripts() {
252
+		$gravityview_view = GravityView_View::getInstance();
253 253
 
254
-        wp_register_script( 'gform_gravityforms', GFCommon::get_base_url().'/js/gravityforms.js', array( 'jquery', 'gform_json', 'gform_placeholder', 'sack', 'plupload-all', 'gravityview-fe-view' ) );
254
+		wp_register_script( 'gform_gravityforms', GFCommon::get_base_url().'/js/gravityforms.js', array( 'jquery', 'gform_json', 'gform_placeholder', 'sack', 'plupload-all', 'gravityview-fe-view' ) );
255 255
 
256
-        GFFormDisplay::enqueue_form_scripts($gravityview_view->getForm(), false);
256
+		GFFormDisplay::enqueue_form_scripts($gravityview_view->getForm(), false);
257 257
 
258
-        // Sack is required for images
259
-        wp_print_scripts( array( 'sack', 'gform_gravityforms' ) );
260
-    }
258
+		// Sack is required for images
259
+		wp_print_scripts( array( 'sack', 'gform_gravityforms' ) );
260
+	}
261 261
 
262 262
 
263
-    /**
264
-     * Process edit entry form save
265
-     */
266
-    private function process_save() {
263
+	/**
264
+	 * Process edit entry form save
265
+	 */
266
+	private function process_save() {
267 267
 
268
-        if( empty( $_POST ) || ! isset( $_POST['lid'] ) ) {
269
-            return;
270
-        }
268
+		if( empty( $_POST ) || ! isset( $_POST['lid'] ) ) {
269
+			return;
270
+		}
271 271
 
272
-        // Make sure the entry, view, and form IDs are all correct
273
-        $valid = $this->verify_nonce();
272
+		// Make sure the entry, view, and form IDs are all correct
273
+		$valid = $this->verify_nonce();
274 274
 
275
-        if( !$valid ) {
276
-            do_action('gravityview_log_error', __METHOD__ . ' Nonce validation failed.' );
277
-            return;
278
-        }
275
+		if( !$valid ) {
276
+			do_action('gravityview_log_error', __METHOD__ . ' Nonce validation failed.' );
277
+			return;
278
+		}
279 279
 
280
-        if( $this->entry['id'] !== $_POST['lid'] ) {
281
-            do_action('gravityview_log_error', __METHOD__ . ' Entry ID did not match posted entry ID.' );
282
-            return;
283
-        }
280
+		if( $this->entry['id'] !== $_POST['lid'] ) {
281
+			do_action('gravityview_log_error', __METHOD__ . ' Entry ID did not match posted entry ID.' );
282
+			return;
283
+		}
284 284
 
285
-        do_action('gravityview_log_debug', __METHOD__ . ': $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) );
285
+		do_action('gravityview_log_debug', __METHOD__ . ': $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) );
286 286
 
287
-        $this->process_save_process_files( $this->form_id );
287
+		$this->process_save_process_files( $this->form_id );
288 288
 
289
-        $this->validate();
289
+		$this->validate();
290 290
 
291
-        if( $this->is_valid ) {
291
+		if( $this->is_valid ) {
292 292
 
293
-            do_action('gravityview_log_debug', __METHOD__ . ': Submission is valid.' );
293
+			do_action('gravityview_log_debug', __METHOD__ . ': Submission is valid.' );
294 294
 
295
-            /**
296
-             * @hack This step is needed to unset the adminOnly from form fields, to add the calculation fields
297
-             */
298
-            $form = $this->form_prepare_for_save();
295
+			/**
296
+			 * @hack This step is needed to unset the adminOnly from form fields, to add the calculation fields
297
+			 */
298
+			$form = $this->form_prepare_for_save();
299 299
 
300
-            /**
301
-             * @hack to avoid the capability validation of the method save_lead for GF 1.9+
302
-             */
303
-            unset( $_GET['page'] );
300
+			/**
301
+			 * @hack to avoid the capability validation of the method save_lead for GF 1.9+
302
+			 */
303
+			unset( $_GET['page'] );
304 304
 
305
-            $date_created = $this->entry['date_created'];
305
+			$date_created = $this->entry['date_created'];
306 306
 
307
-            /**
308
-             * @hack to force Gravity Forms to use $read_value_from_post in GFFormsModel::save_lead()
309
-             * @since 1.17.2
310
-             */
311
-            unset( $this->entry['date_created'] );
307
+			/**
308
+			 * @hack to force Gravity Forms to use $read_value_from_post in GFFormsModel::save_lead()
309
+			 * @since 1.17.2
310
+			 */
311
+			unset( $this->entry['date_created'] );
312 312
 
313
-            GFFormsModel::save_lead( $form, $this->entry );
313
+			GFFormsModel::save_lead( $form, $this->entry );
314 314
 
315
-	        // Delete the values for hidden inputs
316
-	        $this->unset_hidden_field_values();
315
+			// Delete the values for hidden inputs
316
+			$this->unset_hidden_field_values();
317 317
             
318
-            $this->entry['date_created'] = $date_created;
318
+			$this->entry['date_created'] = $date_created;
319 319
 
320
-            // Process calculation fields
321
-            $this->update_calculation_fields();
320
+			// Process calculation fields
321
+			$this->update_calculation_fields();
322 322
 
323
-            // Perform actions normally performed after updating a lead
324
-            $this->after_update();
323
+			// Perform actions normally performed after updating a lead
324
+			$this->after_update();
325 325
 
326
-	        /**
327
-             * Must be AFTER after_update()!
328
-             * @see https://github.com/gravityview/GravityView/issues/764
329
-             */
330
-            $this->maybe_update_post_fields( $form );
326
+			/**
327
+			 * Must be AFTER after_update()!
328
+			 * @see https://github.com/gravityview/GravityView/issues/764
329
+			 */
330
+			$this->maybe_update_post_fields( $form );
331 331
 
332
-            /**
333
-             * @action `gravityview/edit_entry/after_update` Perform an action after the entry has been updated using Edit Entry
334
-             * @param array $form Gravity Forms form array
335
-             * @param string $entry_id Numeric ID of the entry that was updated
336
-             * @param GravityView_Edit_Entry_Render $this This object
337
-             */
338
-            do_action( 'gravityview/edit_entry/after_update', $this->form, $this->entry['id'], $this );
332
+			/**
333
+			 * @action `gravityview/edit_entry/after_update` Perform an action after the entry has been updated using Edit Entry
334
+			 * @param array $form Gravity Forms form array
335
+			 * @param string $entry_id Numeric ID of the entry that was updated
336
+			 * @param GravityView_Edit_Entry_Render $this This object
337
+			 */
338
+			do_action( 'gravityview/edit_entry/after_update', $this->form, $this->entry['id'], $this );
339 339
 
340
-        } else {
341
-            do_action('gravityview_log_error', __METHOD__ . ': Submission is NOT valid.', $this->entry );
342
-        }
340
+		} else {
341
+			do_action('gravityview_log_error', __METHOD__ . ': Submission is NOT valid.', $this->entry );
342
+		}
343 343
 
344
-    } // process_save
344
+	} // process_save
345 345
 
346 346
 	/**
347 347
 	 * Delete the value of fields hidden by conditional logic when the entry is edited
348
-     *
349
-     * @uses GFFormsModel::update_lead_field_value()
350
-     *
351
-     * @since 1.17.4
352
-     *
353
-     * @return void
348
+	 *
349
+	 * @uses GFFormsModel::update_lead_field_value()
350
+	 *
351
+	 * @since 1.17.4
352
+	 *
353
+	 * @return void
354 354
 	 */
355
-    private function unset_hidden_field_values() {
356
-	    global $wpdb;
355
+	private function unset_hidden_field_values() {
356
+		global $wpdb;
357 357
 
358
-	    $lead_detail_table      = GFFormsModel::get_lead_details_table_name();
359
-	    $current_fields   = $wpdb->get_results( $wpdb->prepare( "SELECT id, field_number FROM $lead_detail_table WHERE lead_id=%d", $this->entry['id'] ) );
358
+		$lead_detail_table      = GFFormsModel::get_lead_details_table_name();
359
+		$current_fields   = $wpdb->get_results( $wpdb->prepare( "SELECT id, field_number FROM $lead_detail_table WHERE lead_id=%d", $this->entry['id'] ) );
360 360
 
361
-	    foreach ( $this->entry as $input_id => $field_value ) {
361
+		foreach ( $this->entry as $input_id => $field_value ) {
362 362
 
363
-		    $field = RGFormsModel::get_field( $this->form, $input_id );
363
+			$field = RGFormsModel::get_field( $this->form, $input_id );
364 364
 
365
-		    // Reset fields that are hidden
366
-		    // Don't pass $entry as fourth parameter; force using $_POST values to calculate conditional logic
367
-		    if ( GFFormsModel::is_field_hidden( $this->form, $field, array(), NULL ) ) {
365
+			// Reset fields that are hidden
366
+			// Don't pass $entry as fourth parameter; force using $_POST values to calculate conditional logic
367
+			if ( GFFormsModel::is_field_hidden( $this->form, $field, array(), NULL ) ) {
368 368
 
369
-		        // List fields are stored as empty arrays when empty
370
-			    $empty_value = $this->is_field_json_encoded( $field ) ? '[]' : '';
369
+				// List fields are stored as empty arrays when empty
370
+				$empty_value = $this->is_field_json_encoded( $field ) ? '[]' : '';
371 371
 
372
-			    $lead_detail_id = GFFormsModel::get_lead_detail_id( $current_fields, $input_id );
372
+				$lead_detail_id = GFFormsModel::get_lead_detail_id( $current_fields, $input_id );
373 373
 
374
-			    GFFormsModel::update_lead_field_value( $this->form, $this->entry, $field, $lead_detail_id, $input_id, $empty_value );
374
+				GFFormsModel::update_lead_field_value( $this->form, $this->entry, $field, $lead_detail_id, $input_id, $empty_value );
375 375
 
376
-			    // Prevent the $_POST values of hidden fields from being used as default values when rendering the form
377
-                // after submission
378
-			    $post_input_id = 'input_' . str_replace( '.', '_', $input_id );
379
-			    $_POST[ $post_input_id ] = '';
380
-		    }
381
-	    }
382
-    }
376
+				// Prevent the $_POST values of hidden fields from being used as default values when rendering the form
377
+				// after submission
378
+				$post_input_id = 'input_' . str_replace( '.', '_', $input_id );
379
+				$_POST[ $post_input_id ] = '';
380
+			}
381
+		}
382
+	}
383 383
 
384
-    /**
385
-     * Have GF handle file uploads
386
-     *
387
-     * Copy of code from GFFormDisplay::process_form()
388
-     *
389
-     * @param int $form_id
390
-     */
391
-    private function process_save_process_files( $form_id ) {
384
+	/**
385
+	 * Have GF handle file uploads
386
+	 *
387
+	 * Copy of code from GFFormDisplay::process_form()
388
+	 *
389
+	 * @param int $form_id
390
+	 */
391
+	private function process_save_process_files( $form_id ) {
392 392
 
393
-        //Loading files that have been uploaded to temp folder
394
-        $files = GFCommon::json_decode( stripslashes( RGForms::post( 'gform_uploaded_files' ) ) );
395
-        if ( ! is_array( $files ) ) {
396
-            $files = array();
397
-        }
393
+		//Loading files that have been uploaded to temp folder
394
+		$files = GFCommon::json_decode( stripslashes( RGForms::post( 'gform_uploaded_files' ) ) );
395
+		if ( ! is_array( $files ) ) {
396
+			$files = array();
397
+		}
398 398
 
399 399
 		/**
400 400
 		 * Make sure the fileuploads are not overwritten if no such request was done.
401
-         * @since 1.20.1
401
+		 * @since 1.20.1
402 402
 		 */
403 403
 		add_filter( "gform_save_field_value_$form_id", array( $this, 'save_field_value' ), 99, 5 );
404 404
 
405
-        RGFormsModel::$uploaded_files[ $form_id ] = $files;
406
-    }
405
+		RGFormsModel::$uploaded_files[ $form_id ] = $files;
406
+	}
407 407
 
408 408
 	/**
409 409
 	 * Make sure the fileuploads are not overwritten if no such request was done.
410 410
 	 *
411
-     * TO ONLY BE USED INTERNALLY; DO NOT DEVELOP ON; MAY BE REMOVED AT ANY TIME.
412
-     *
411
+	 * TO ONLY BE USED INTERNALLY; DO NOT DEVELOP ON; MAY BE REMOVED AT ANY TIME.
412
+	 *
413 413
 	 * @since 1.20.1
414 414
 	 *
415 415
 	 * @param string $value Field value
@@ -444,156 +444,156 @@  discard block
 block discarded – undo
444 444
 		return $value;
445 445
 	}
446 446
 
447
-    /**
448
-     * Remove max_files validation (done on gravityforms.js) to avoid conflicts with GravityView
449
-     * Late validation done on self::custom_validation
450
-     *
451
-     * @param $plupload_init array Plupload settings
452
-     * @param $form_id
453
-     * @param $instance
454
-     * @return mixed
455
-     */
456
-    public function modify_fileupload_settings( $plupload_init, $form_id, $instance ) {
457
-        if( ! $this->is_edit_entry() ) {
458
-            return $plupload_init;
459
-        }
460
-
461
-        $plupload_init['gf_vars']['max_files'] = 0;
462
-
463
-        return $plupload_init;
464
-    }
465
-
466
-
467
-    /**
468
-     * Unset adminOnly and convert field input key to string
469
-     * @return array $form
470
-     */
471
-    private function form_prepare_for_save() {
472
-
473
-        $form = $this->form;
474
-
475
-	    /** @var GF_Field $field */
476
-        foreach( $form['fields'] as $k => &$field ) {
477
-
478
-            /**
479
-             * Remove the fields with calculation formulas before save to avoid conflicts with GF logic
480
-             * @since 1.16.3
481
-             * @var GF_Field $field
482
-             */
483
-            if( $field->has_calculation() ) {
484
-                unset( $form['fields'][ $k ] );
485
-            }
486
-
487
-            $field->adminOnly = false;
488
-
489
-            if( isset( $field->inputs ) && is_array( $field->inputs ) ) {
490
-                foreach( $field->inputs as $key => $input ) {
491
-                    $field->inputs[ $key ][ 'id' ] = (string)$input['id'];
492
-                }
493
-            }
494
-        }
495
-
496
-        return $form;
497
-    }
498
-
499
-    private function update_calculation_fields() {
500
-
501
-        $form = self::$original_form;
502
-        $update = false;
503
-
504
-        // get the most up to date entry values
505
-        $entry = GFAPI::get_entry( $this->entry['id'] );
506
-
507
-        if( !empty( $this->fields_with_calculation ) ) {
508
-            $update = true;
509
-            foreach ( $this->fields_with_calculation as $calc_field ) {
510
-                $inputs = $calc_field->get_entry_inputs();
511
-                if ( is_array( $inputs ) ) {
512
-                    foreach ( $inputs as $input ) {
513
-                        $input_name = 'input_' . str_replace( '.', '_', $input['id'] );
514
-                        $entry[ strval( $input['id'] ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry['id'], $entry );
515
-                    }
516
-                } else {
517
-                    $input_name = 'input_' . str_replace( '.', '_', $calc_field->id);
518
-                    $entry[ strval( $calc_field->id ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry['id'], $entry );
519
-                }
520
-            }
521
-
522
-        }
523
-
524
-        if( $update ) {
525
-
526
-            $return_entry = GFAPI::update_entry( $entry );
527
-
528
-            if( is_wp_error( $return_entry ) ) {
529
-                do_action( 'gravityview_log_error', 'Updating the entry calculation fields failed', $return_entry );
530
-            } else {
531
-                do_action( 'gravityview_log_debug', 'Updating the entry calculation fields succeeded' );
532
-            }
533
-        }
534
-    }
535
-
536
-    /**
537
-     * Handle updating the Post Image field
538
-     *
539
-     * Sets a new Featured Image if configured in Gravity Forms; otherwise uploads/updates media
540
-     *
541
-     * @since 1.17
542
-     *
543
-     * @uses GFFormsModel::media_handle_upload
544
-     * @uses set_post_thumbnail
545
-     * 
546
-     * @param array $form GF Form array
547
-     * @param GF_Field $field GF Field
548
-     * @param string $field_id Numeric ID of the field
549
-     * @param string $value
550
-     * @param array $entry GF Entry currently being edited
551
-     * @param int $post_id ID of the Post being edited
552
-     *
553
-     * @return mixed|string
554
-     */
555
-    private function update_post_image( $form, $field, $field_id, $value, $entry, $post_id ) {
556
-
557
-        $input_name = 'input_' . $field_id;
558
-
559
-        if ( !empty( $_FILES[ $input_name ]['name'] ) ) {
560
-
561
-            // We have a new image
562
-
563
-            $value = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'] );
564
-
565
-            $ary = ! empty( $value ) ? explode( '|:|', $value ) : array();
566
-            $img_url = rgar( $ary, 0 );
567
-
568
-            $img_title       = count( $ary ) > 1 ? $ary[1] : '';
569
-            $img_caption     = count( $ary ) > 2 ? $ary[2] : '';
570
-            $img_description = count( $ary ) > 3 ? $ary[3] : '';
571
-
572
-            $image_meta = array(
573
-                'post_excerpt' => $img_caption,
574
-                'post_content' => $img_description,
575
-            );
576
-
577
-            //adding title only if it is not empty. It will default to the file name if it is not in the array
578
-            if ( ! empty( $img_title ) ) {
579
-                $image_meta['post_title'] = $img_title;
580
-            }
581
-
582
-            /**
583
-             * 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.
584
-             * Note: the method became public in GF 1.9.17.7, but we don't require that version yet.
585
-             */
586
-            require_once GRAVITYVIEW_DIR . 'includes/class-gravityview-gfformsmodel.php';
587
-            $media_id = GravityView_GFFormsModel::media_handle_upload( $img_url, $post_id, $image_meta );
588
-
589
-            // is this field set as featured image?
590
-            if ( $media_id && $field->postFeaturedImage ) {
591
-                set_post_thumbnail( $post_id, $media_id );
592
-            }
593
-
594
-        } elseif ( !empty( $_POST[ $input_name ] ) && is_array( $value ) ) {
595
-
596
-            $img_url = $_POST[ $input_name ];
447
+	/**
448
+	 * Remove max_files validation (done on gravityforms.js) to avoid conflicts with GravityView
449
+	 * Late validation done on self::custom_validation
450
+	 *
451
+	 * @param $plupload_init array Plupload settings
452
+	 * @param $form_id
453
+	 * @param $instance
454
+	 * @return mixed
455
+	 */
456
+	public function modify_fileupload_settings( $plupload_init, $form_id, $instance ) {
457
+		if( ! $this->is_edit_entry() ) {
458
+			return $plupload_init;
459
+		}
460
+
461
+		$plupload_init['gf_vars']['max_files'] = 0;
462
+
463
+		return $plupload_init;
464
+	}
465
+
466
+
467
+	/**
468
+	 * Unset adminOnly and convert field input key to string
469
+	 * @return array $form
470
+	 */
471
+	private function form_prepare_for_save() {
472
+
473
+		$form = $this->form;
474
+
475
+		/** @var GF_Field $field */
476
+		foreach( $form['fields'] as $k => &$field ) {
477
+
478
+			/**
479
+			 * Remove the fields with calculation formulas before save to avoid conflicts with GF logic
480
+			 * @since 1.16.3
481
+			 * @var GF_Field $field
482
+			 */
483
+			if( $field->has_calculation() ) {
484
+				unset( $form['fields'][ $k ] );
485
+			}
486
+
487
+			$field->adminOnly = false;
488
+
489
+			if( isset( $field->inputs ) && is_array( $field->inputs ) ) {
490
+				foreach( $field->inputs as $key => $input ) {
491
+					$field->inputs[ $key ][ 'id' ] = (string)$input['id'];
492
+				}
493
+			}
494
+		}
495
+
496
+		return $form;
497
+	}
498
+
499
+	private function update_calculation_fields() {
500
+
501
+		$form = self::$original_form;
502
+		$update = false;
503
+
504
+		// get the most up to date entry values
505
+		$entry = GFAPI::get_entry( $this->entry['id'] );
506
+
507
+		if( !empty( $this->fields_with_calculation ) ) {
508
+			$update = true;
509
+			foreach ( $this->fields_with_calculation as $calc_field ) {
510
+				$inputs = $calc_field->get_entry_inputs();
511
+				if ( is_array( $inputs ) ) {
512
+					foreach ( $inputs as $input ) {
513
+						$input_name = 'input_' . str_replace( '.', '_', $input['id'] );
514
+						$entry[ strval( $input['id'] ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry['id'], $entry );
515
+					}
516
+				} else {
517
+					$input_name = 'input_' . str_replace( '.', '_', $calc_field->id);
518
+					$entry[ strval( $calc_field->id ) ] = RGFormsModel::prepare_value( $form, $calc_field, '', $input_name, $entry['id'], $entry );
519
+				}
520
+			}
521
+
522
+		}
523
+
524
+		if( $update ) {
525
+
526
+			$return_entry = GFAPI::update_entry( $entry );
527
+
528
+			if( is_wp_error( $return_entry ) ) {
529
+				do_action( 'gravityview_log_error', 'Updating the entry calculation fields failed', $return_entry );
530
+			} else {
531
+				do_action( 'gravityview_log_debug', 'Updating the entry calculation fields succeeded' );
532
+			}
533
+		}
534
+	}
535
+
536
+	/**
537
+	 * Handle updating the Post Image field
538
+	 *
539
+	 * Sets a new Featured Image if configured in Gravity Forms; otherwise uploads/updates media
540
+	 *
541
+	 * @since 1.17
542
+	 *
543
+	 * @uses GFFormsModel::media_handle_upload
544
+	 * @uses set_post_thumbnail
545
+	 * 
546
+	 * @param array $form GF Form array
547
+	 * @param GF_Field $field GF Field
548
+	 * @param string $field_id Numeric ID of the field
549
+	 * @param string $value
550
+	 * @param array $entry GF Entry currently being edited
551
+	 * @param int $post_id ID of the Post being edited
552
+	 *
553
+	 * @return mixed|string
554
+	 */
555
+	private function update_post_image( $form, $field, $field_id, $value, $entry, $post_id ) {
556
+
557
+		$input_name = 'input_' . $field_id;
558
+
559
+		if ( !empty( $_FILES[ $input_name ]['name'] ) ) {
560
+
561
+			// We have a new image
562
+
563
+			$value = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'] );
564
+
565
+			$ary = ! empty( $value ) ? explode( '|:|', $value ) : array();
566
+			$img_url = rgar( $ary, 0 );
567
+
568
+			$img_title       = count( $ary ) > 1 ? $ary[1] : '';
569
+			$img_caption     = count( $ary ) > 2 ? $ary[2] : '';
570
+			$img_description = count( $ary ) > 3 ? $ary[3] : '';
571
+
572
+			$image_meta = array(
573
+				'post_excerpt' => $img_caption,
574
+				'post_content' => $img_description,
575
+			);
576
+
577
+			//adding title only if it is not empty. It will default to the file name if it is not in the array
578
+			if ( ! empty( $img_title ) ) {
579
+				$image_meta['post_title'] = $img_title;
580
+			}
581
+
582
+			/**
583
+			 * 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.
584
+			 * Note: the method became public in GF 1.9.17.7, but we don't require that version yet.
585
+			 */
586
+			require_once GRAVITYVIEW_DIR . 'includes/class-gravityview-gfformsmodel.php';
587
+			$media_id = GravityView_GFFormsModel::media_handle_upload( $img_url, $post_id, $image_meta );
588
+
589
+			// is this field set as featured image?
590
+			if ( $media_id && $field->postFeaturedImage ) {
591
+				set_post_thumbnail( $post_id, $media_id );
592
+			}
593
+
594
+		} elseif ( !empty( $_POST[ $input_name ] ) && is_array( $value ) ) {
595
+
596
+			$img_url = $_POST[ $input_name ];
597 597
 
598 598
 			$img_title       = rgar( $_POST, $input_name.'_1' );
599 599
 			$img_caption     = rgar( $_POST, $input_name .'_4' );
@@ -613,259 +613,259 @@  discard block
 block discarded – undo
613 613
 				// update image title, caption or description
614 614
 				wp_update_post( $image_meta );
615 615
 			}
616
-        } else {
617
-
618
-            // if we get here, image was removed or not set.
619
-            $value = '';
620
-
621
-            if ( $field->postFeaturedImage ) {
622
-                delete_post_thumbnail( $post_id );
623
-            }
624
-        }
625
-
626
-        return $value;
627
-    }
628
-
629
-    /**
630
-     * Loop through the fields being edited and if they include Post fields, update the Entry's post object
631
-     *
632
-     * @param array $form Gravity Forms form
633
-     *
634
-     * @return void
635
-     */
636
-    private function maybe_update_post_fields( $form ) {
637
-
638
-        if( empty( $this->entry['post_id'] ) ) {
639
-	        do_action( 'gravityview_log_debug', __METHOD__ . ': This entry has no post fields. Continuing...' );
640
-            return;
641
-        }
642
-
643
-        $post_id = $this->entry['post_id'];
644
-
645
-        // Security check
646
-        if( false === GVCommon::has_cap( 'edit_post', $post_id ) ) {
647
-            do_action( 'gravityview_log_error', 'The current user does not have the ability to edit Post #'.$post_id );
648
-            return;
649
-        }
650
-
651
-        $update_entry = false;
652
-
653
-        $updated_post = $original_post = get_post( $post_id );
654
-
655
-        foreach ( $this->entry as $field_id => $value ) {
616
+		} else {
656 617
 
657
-            $field = RGFormsModel::get_field( $form, $field_id );
618
+			// if we get here, image was removed or not set.
619
+			$value = '';
658 620
 
659
-            if( ! $field ) {
660
-                continue;
661
-            }
621
+			if ( $field->postFeaturedImage ) {
622
+				delete_post_thumbnail( $post_id );
623
+			}
624
+		}
662 625
 
663
-            if( GFCommon::is_post_field( $field ) && 'post_category' !== $field->type ) {
626
+		return $value;
627
+	}
664 628
 
665
-                // Get the value of the field, including $_POSTed value
666
-                $value = RGFormsModel::get_field_value( $field );
629
+	/**
630
+	 * Loop through the fields being edited and if they include Post fields, update the Entry's post object
631
+	 *
632
+	 * @param array $form Gravity Forms form
633
+	 *
634
+	 * @return void
635
+	 */
636
+	private function maybe_update_post_fields( $form ) {
667 637
 
668
-                // Use temporary entry variable, to make values available to fill_post_template() and update_post_image()
669
-                $entry_tmp = $this->entry;
670
-                $entry_tmp["{$field_id}"] = $value;
638
+		if( empty( $this->entry['post_id'] ) ) {
639
+			do_action( 'gravityview_log_debug', __METHOD__ . ': This entry has no post fields. Continuing...' );
640
+			return;
641
+		}
671 642
 
672
-                switch( $field->type ) {
643
+		$post_id = $this->entry['post_id'];
673 644
 
674
-                    case 'post_title':
675
-                        $post_title = $value;
676
-                        if( rgar( $form, 'postTitleTemplateEnabled' ) ) {
677
-                            $post_title = $this->fill_post_template( $form['postTitleTemplate'], $form, $entry_tmp );
678
-                        }
679
-                        $updated_post->post_title = $post_title;
680
-                        $updated_post->post_name  = $post_title;
681
-                        unset( $post_title );
682
-                        break;
645
+		// Security check
646
+		if( false === GVCommon::has_cap( 'edit_post', $post_id ) ) {
647
+			do_action( 'gravityview_log_error', 'The current user does not have the ability to edit Post #'.$post_id );
648
+			return;
649
+		}
683 650
 
684
-                    case 'post_content':
685
-                        $post_content = $value;
686
-                        if( rgar( $form, 'postContentTemplateEnabled' ) ) {
687
-                            $post_content = $this->fill_post_template( $form['postContentTemplate'], $form, $entry_tmp, true );
688
-                        }
689
-                        $updated_post->post_content = $post_content;
690
-                        unset( $post_content );
691
-                        break;
692
-                    case 'post_excerpt':
693
-                        $updated_post->post_excerpt = $value;
694
-                        break;
695
-                    case 'post_tags':
696
-                        wp_set_post_tags( $post_id, $value, false );
697
-                        break;
698
-                    case 'post_category':
699
-                        break;
700
-                    case 'post_custom_field':
701
-                        if( ! empty( $field->customFieldTemplateEnabled ) ) {
702
-                            $value = $this->fill_post_template( $field->customFieldTemplate, $form, $entry_tmp, true );
703
-                        }
651
+		$update_entry = false;
704 652
 
705
-	                    if ( $this->is_field_json_encoded( $field ) && ! is_string( $value ) ) {
706
-		                    $value = function_exists('wp_json_encode') ? wp_json_encode( $value ) : json_encode( $value );
707
-	                    }
653
+		$updated_post = $original_post = get_post( $post_id );
708 654
 
709
-                        update_post_meta( $post_id, $field->postCustomFieldName, $value );
710
-                        break;
655
+		foreach ( $this->entry as $field_id => $value ) {
711 656
 
712
-                    case 'post_image':
713
-                        $value = $this->update_post_image( $form, $field, $field_id, $value, $this->entry, $post_id );
714
-                        break;
657
+			$field = RGFormsModel::get_field( $form, $field_id );
715 658
 
716
-                }
659
+			if( ! $field ) {
660
+				continue;
661
+			}
717 662
 
718
-                // update entry after
719
-                $this->entry["{$field_id}"] = $value;
663
+			if( GFCommon::is_post_field( $field ) && 'post_category' !== $field->type ) {
664
+
665
+				// Get the value of the field, including $_POSTed value
666
+				$value = RGFormsModel::get_field_value( $field );
667
+
668
+				// Use temporary entry variable, to make values available to fill_post_template() and update_post_image()
669
+				$entry_tmp = $this->entry;
670
+				$entry_tmp["{$field_id}"] = $value;
671
+
672
+				switch( $field->type ) {
673
+
674
+					case 'post_title':
675
+						$post_title = $value;
676
+						if( rgar( $form, 'postTitleTemplateEnabled' ) ) {
677
+							$post_title = $this->fill_post_template( $form['postTitleTemplate'], $form, $entry_tmp );
678
+						}
679
+						$updated_post->post_title = $post_title;
680
+						$updated_post->post_name  = $post_title;
681
+						unset( $post_title );
682
+						break;
683
+
684
+					case 'post_content':
685
+						$post_content = $value;
686
+						if( rgar( $form, 'postContentTemplateEnabled' ) ) {
687
+							$post_content = $this->fill_post_template( $form['postContentTemplate'], $form, $entry_tmp, true );
688
+						}
689
+						$updated_post->post_content = $post_content;
690
+						unset( $post_content );
691
+						break;
692
+					case 'post_excerpt':
693
+						$updated_post->post_excerpt = $value;
694
+						break;
695
+					case 'post_tags':
696
+						wp_set_post_tags( $post_id, $value, false );
697
+						break;
698
+					case 'post_category':
699
+						break;
700
+					case 'post_custom_field':
701
+						if( ! empty( $field->customFieldTemplateEnabled ) ) {
702
+							$value = $this->fill_post_template( $field->customFieldTemplate, $form, $entry_tmp, true );
703
+						}
704
+
705
+						if ( $this->is_field_json_encoded( $field ) && ! is_string( $value ) ) {
706
+							$value = function_exists('wp_json_encode') ? wp_json_encode( $value ) : json_encode( $value );
707
+						}
708
+
709
+						update_post_meta( $post_id, $field->postCustomFieldName, $value );
710
+						break;
711
+
712
+					case 'post_image':
713
+						$value = $this->update_post_image( $form, $field, $field_id, $value, $this->entry, $post_id );
714
+						break;
715
+
716
+				}
717
+
718
+				// update entry after
719
+				$this->entry["{$field_id}"] = $value;
720
+
721
+				$update_entry = true;
722
+
723
+				unset( $entry_tmp );
724
+			}
720 725
 
721
-                $update_entry = true;
722
-
723
-                unset( $entry_tmp );
724
-            }
726
+		}
725 727
 
726
-        }
728
+		if( $update_entry ) {
727 729
 
728
-        if( $update_entry ) {
729
-
730
-            $return_entry = GFAPI::update_entry( $this->entry );
730
+			$return_entry = GFAPI::update_entry( $this->entry );
731 731
 
732
-            if( is_wp_error( $return_entry ) ) {
733
-               do_action( 'gravityview_log_error', 'Updating the entry post fields failed', array( '$this->entry' => $this->entry, '$return_entry' => $return_entry ) );
734
-            } else {
735
-                do_action( 'gravityview_log_debug', 'Updating the entry post fields for post #'.$post_id.' succeeded' );
736
-            }
732
+			if( is_wp_error( $return_entry ) ) {
733
+			   do_action( 'gravityview_log_error', 'Updating the entry post fields failed', array( '$this->entry' => $this->entry, '$return_entry' => $return_entry ) );
734
+			} else {
735
+				do_action( 'gravityview_log_debug', 'Updating the entry post fields for post #'.$post_id.' succeeded' );
736
+			}
737 737
 
738
-        }
738
+		}
739 739
 
740
-        $return_post = wp_update_post( $updated_post, true );
740
+		$return_post = wp_update_post( $updated_post, true );
741 741
 
742
-        if( is_wp_error( $return_post ) ) {
743
-            $return_post->add_data( $updated_post, '$updated_post' );
744
-            do_action( 'gravityview_log_error', 'Updating the post content failed', compact( 'updated_post', 'return_post' ) );
745
-        } else {
746
-            do_action( 'gravityview_log_debug', 'Updating the post content for post #'.$post_id.' succeeded', $updated_post );
747
-        }
748
-    }
742
+		if( is_wp_error( $return_post ) ) {
743
+			$return_post->add_data( $updated_post, '$updated_post' );
744
+			do_action( 'gravityview_log_error', 'Updating the post content failed', compact( 'updated_post', 'return_post' ) );
745
+		} else {
746
+			do_action( 'gravityview_log_debug', 'Updating the post content for post #'.$post_id.' succeeded', $updated_post );
747
+		}
748
+	}
749 749
 
750 750
 	/**
751
-     * Is the field stored in a JSON-encoded manner?
752
-     *
751
+	 * Is the field stored in a JSON-encoded manner?
752
+	 *
753 753
 	 * @param GF_Field $field
754 754
 	 *
755 755
 	 * @return bool True: stored in DB json_encode()'d; False: not encoded
756 756
 	 */
757
-    private function is_field_json_encoded( $field ) {
757
+	private function is_field_json_encoded( $field ) {
758 758
 
759
-	    $json_encoded = false;
759
+		$json_encoded = false;
760 760
 
761
-        $input_type = RGFormsModel::get_input_type( $field );
761
+		$input_type = RGFormsModel::get_input_type( $field );
762 762
 
763
-	    // Only certain custom field types are supported
764
-	    switch( $input_type ) {
765
-		    case 'fileupload':
766
-		    case 'list':
767
-		    case 'multiselect':
768
-			    $json_encoded = true;
769
-			    break;
770
-	    }
763
+		// Only certain custom field types are supported
764
+		switch( $input_type ) {
765
+			case 'fileupload':
766
+			case 'list':
767
+			case 'multiselect':
768
+				$json_encoded = true;
769
+				break;
770
+		}
771 771
 
772
-	    return $json_encoded;
773
-    }
772
+		return $json_encoded;
773
+	}
774 774
 
775
-    /**
776
-     * Convert a field content template into prepared output
777
-     *
778
-     * @uses GravityView_GFFormsModel::get_post_field_images()
779
-     *
780
-     * @since 1.17
781
-     *
782
-     * @param string $template The content template for the field
783
-     * @param array $form Gravity Forms form
784
-     * @param bool $do_shortcode Whether to process shortcode inside content. In GF, only run on Custom Field and Post Content fields
785
-     *
786
-     * @return string
787
-     */
788
-    private function fill_post_template( $template, $form, $entry, $do_shortcode = false ) {
775
+	/**
776
+	 * Convert a field content template into prepared output
777
+	 *
778
+	 * @uses GravityView_GFFormsModel::get_post_field_images()
779
+	 *
780
+	 * @since 1.17
781
+	 *
782
+	 * @param string $template The content template for the field
783
+	 * @param array $form Gravity Forms form
784
+	 * @param bool $do_shortcode Whether to process shortcode inside content. In GF, only run on Custom Field and Post Content fields
785
+	 *
786
+	 * @return string
787
+	 */
788
+	private function fill_post_template( $template, $form, $entry, $do_shortcode = false ) {
789 789
 
790
-        require_once GRAVITYVIEW_DIR . 'includes/class-gravityview-gfformsmodel.php';
790
+		require_once GRAVITYVIEW_DIR . 'includes/class-gravityview-gfformsmodel.php';
791 791
 
792
-        $post_images = GravityView_GFFormsModel::get_post_field_images( $form, $entry );
792
+		$post_images = GravityView_GFFormsModel::get_post_field_images( $form, $entry );
793 793
 
794
-        //replacing post image variables
795
-        $output = GFCommon::replace_variables_post_image( $template, $post_images, $entry );
794
+		//replacing post image variables
795
+		$output = GFCommon::replace_variables_post_image( $template, $post_images, $entry );
796 796
 
797
-        //replacing all other variables
798
-        $output = GFCommon::replace_variables( $output, $form, $entry, false, false, false );
797
+		//replacing all other variables
798
+		$output = GFCommon::replace_variables( $output, $form, $entry, false, false, false );
799 799
 
800
-        // replace conditional shortcodes
801
-        if( $do_shortcode ) {
802
-            $output = do_shortcode( $output );
803
-        }
800
+		// replace conditional shortcodes
801
+		if( $do_shortcode ) {
802
+			$output = do_shortcode( $output );
803
+		}
804 804
 
805
-        return $output;
806
-    }
805
+		return $output;
806
+	}
807 807
 
808 808
 
809
-    /**
810
-     * Perform actions normally performed after updating a lead
811
-     *
812
-     * @since 1.8
813
-     *
814
-     * @see GFEntryDetail::lead_detail_page()
815
-     *
816
-     * @return void
817
-     */
818
-    private function after_update() {
809
+	/**
810
+	 * Perform actions normally performed after updating a lead
811
+	 *
812
+	 * @since 1.8
813
+	 *
814
+	 * @see GFEntryDetail::lead_detail_page()
815
+	 *
816
+	 * @return void
817
+	 */
818
+	private function after_update() {
819 819
 
820
-        do_action( 'gform_after_update_entry', $this->form, $this->entry['id'], self::$original_entry );
821
-        do_action( "gform_after_update_entry_{$this->form['id']}", $this->form, $this->entry['id'], self::$original_entry );
820
+		do_action( 'gform_after_update_entry', $this->form, $this->entry['id'], self::$original_entry );
821
+		do_action( "gform_after_update_entry_{$this->form['id']}", $this->form, $this->entry['id'], self::$original_entry );
822 822
 
823
-        // Re-define the entry now that we've updated it.
824
-        $entry = RGFormsModel::get_lead( $this->entry['id'] );
823
+		// Re-define the entry now that we've updated it.
824
+		$entry = RGFormsModel::get_lead( $this->entry['id'] );
825 825
 
826
-        $entry = GFFormsModel::set_entry_meta( $entry, $this->form );
826
+		$entry = GFFormsModel::set_entry_meta( $entry, $this->form );
827 827
 
828
-        // We need to clear the cache because Gravity Forms caches the field values, which
829
-        // we have just updated.
830
-        foreach ($this->form['fields'] as $key => $field) {
831
-            GFFormsModel::refresh_lead_field_value( $entry['id'], $field->id );
832
-        }
828
+		// We need to clear the cache because Gravity Forms caches the field values, which
829
+		// we have just updated.
830
+		foreach ($this->form['fields'] as $key => $field) {
831
+			GFFormsModel::refresh_lead_field_value( $entry['id'], $field->id );
832
+		}
833 833
 
834
-        $this->entry = $entry;
835
-    }
834
+		$this->entry = $entry;
835
+	}
836 836
 
837 837
 
838
-    /**
839
-     * Display the Edit Entry form
840
-     *
841
-     * @return void
842
-     */
843
-    public function edit_entry_form() {
838
+	/**
839
+	 * Display the Edit Entry form
840
+	 *
841
+	 * @return void
842
+	 */
843
+	public function edit_entry_form() {
844 844
 
845
-        ?>
845
+		?>
846 846
 
847 847
         <div class="gv-edit-entry-wrapper"><?php
848 848
 
849
-            $javascript = gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/inline-javascript.php', $this );
849
+			$javascript = gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/inline-javascript.php', $this );
850 850
 
851
-            /**
852
-             * Fixes weird wpautop() issue
853
-             * @see https://github.com/katzwebservices/GravityView/issues/451
854
-             */
855
-            echo gravityview_strip_whitespace( $javascript );
851
+			/**
852
+			 * Fixes weird wpautop() issue
853
+			 * @see https://github.com/katzwebservices/GravityView/issues/451
854
+			 */
855
+			echo gravityview_strip_whitespace( $javascript );
856 856
 
857
-            ?><h2 class="gv-edit-entry-title">
857
+			?><h2 class="gv-edit-entry-title">
858 858
                 <span><?php
859 859
 
860
-                    /**
861
-                     * @filter `gravityview_edit_entry_title` Modify the edit entry title
862
-                     * @param string $edit_entry_title Modify the "Edit Entry" title
863
-                     * @param GravityView_Edit_Entry_Render $this This object
864
-                     */
865
-                    $edit_entry_title = apply_filters('gravityview_edit_entry_title', __('Edit Entry', 'gravityview'), $this );
860
+					/**
861
+					 * @filter `gravityview_edit_entry_title` Modify the edit entry title
862
+					 * @param string $edit_entry_title Modify the "Edit Entry" title
863
+					 * @param GravityView_Edit_Entry_Render $this This object
864
+					 */
865
+					$edit_entry_title = apply_filters('gravityview_edit_entry_title', __('Edit Entry', 'gravityview'), $this );
866 866
 
867
-                    echo esc_attr( $edit_entry_title );
868
-            ?></span>
867
+					echo esc_attr( $edit_entry_title );
868
+			?></span>
869 869
             </h2>
870 870
 
871 871
             <?php $this->maybe_print_message(); ?>
@@ -876,14 +876,14 @@  discard block
 block discarded – undo
876 876
 
877 877
                 <?php
878 878
 
879
-                wp_nonce_field( self::$nonce_key, self::$nonce_key );
879
+				wp_nonce_field( self::$nonce_key, self::$nonce_key );
880 880
 
881
-                wp_nonce_field( self::$nonce_field, self::$nonce_field, false );
881
+				wp_nonce_field( self::$nonce_field, self::$nonce_field, false );
882 882
 
883
-                // Print the actual form HTML
884
-                $this->render_edit_form();
883
+				// Print the actual form HTML
884
+				$this->render_edit_form();
885 885
 
886
-                ?>
886
+				?>
887 887
             </form>
888 888
 
889 889
             <script>
@@ -895,643 +895,643 @@  discard block
 block discarded – undo
895 895
         </div>
896 896
 
897 897
     <?php
898
-    }
899
-
900
-    /**
901
-     * Display success or error message if the form has been submitted
902
-     *
903
-     * @uses GVCommon::generate_notice
904
-     *
905
-     * @since 1.16.2.2
906
-     *
907
-     * @return void
908
-     */
909
-    private function maybe_print_message() {
910
-
911
-        if( rgpost('action') === 'update' ) {
912
-
913
-            $back_link = esc_url( remove_query_arg( array( 'page', 'view', 'edit' ) ) );
914
-
915
-            if( ! $this->is_valid ){
916
-
917
-                // Keeping this compatible with Gravity Forms.
918
-                $validation_message = "<div class='validation_error'>" . __('There was a problem with your submission.', 'gravityview') . " " . __('Errors have been highlighted below.', 'gravityview') . "</div>";
919
-                $message = apply_filters("gform_validation_message_{$this->form['id']}", apply_filters("gform_validation_message", $validation_message, $this->form), $this->form);
920
-
921
-                echo GVCommon::generate_notice( $message , 'gv-error' );
922
-
923
-            } else {
924
-                $entry_updated_message = sprintf( esc_attr__('Entry Updated. %sReturn to Entry%s', 'gravityview'), '<a href="'. $back_link .'">', '</a>' );
925
-
926
-                /**
927
-                 * @filter `gravityview/edit_entry/success` Modify the edit entry success message (including the anchor link)
928
-                 * @since 1.5.4
929
-                 * @param string $entry_updated_message Existing message
930
-                 * @param int $view_id View ID
931
-                 * @param array $entry Gravity Forms entry array
932
-                 * @param string $back_link URL to return to the original entry. @since 1.6
933
-                 */
934
-                $message = apply_filters( 'gravityview/edit_entry/success', $entry_updated_message , $this->view_id, $this->entry, $back_link );
935
-
936
-                echo GVCommon::generate_notice( $message );
937
-            }
938
-
939
-        }
940
-    }
941
-
942
-    /**
943
-     * Display the Edit Entry form in the original Gravity Forms format
944
-     *
945
-     * @since 1.9
946
-     *
947
-     * @return void
948
-     */
949
-    private function render_edit_form() {
950
-
951
-        /**
952
-         * @action `gravityview/edit-entry/render/before` Before rendering the Edit Entry form
953
-         * @since 1.17
954
-         * @param GravityView_Edit_Entry_Render $this
955
-         */
956
-        do_action( 'gravityview/edit-entry/render/before', $this );
957
-
958
-        add_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields'), 5000, 3 );
959
-        add_filter( 'gform_submit_button', array( $this, 'render_form_buttons') );
960
-        add_filter( 'gform_disable_view_counter', '__return_true' );
961
-
962
-        add_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5, 5 );
963
-        add_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10, 5 );
964
-
965
-        // We need to remove the fake $_GET['page'] arg to avoid rendering form as if in admin.
966
-        unset( $_GET['page'] );
967
-
968
-        // TODO: Verify multiple-page forms
969
-
970
-        ob_start(); // Prevent PHP warnings possibly caused by prefilling list fields for conditional logic
971
-
972
-        $html = GFFormDisplay::get_form( $this->form['id'], false, false, true, $this->entry );
973
-
974
-        ob_get_clean();
975
-
976
-	    remove_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields' ), 5000 );
977
-        remove_filter( 'gform_submit_button', array( $this, 'render_form_buttons' ) );
978
-        remove_filter( 'gform_disable_view_counter', '__return_true' );
979
-        remove_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5 );
980
-        remove_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10 );
981
-
982
-        echo $html;
983
-
984
-        /**
985
-         * @action `gravityview/edit-entry/render/after` After rendering the Edit Entry form
986
-         * @since 1.17
987
-         * @param GravityView_Edit_Entry_Render $this
988
-         */
989
-        do_action( 'gravityview/edit-entry/render/after', $this );
990
-    }
991
-
992
-    /**
993
-     * Display the Update/Cancel/Delete buttons for the Edit Entry form
994
-     * @since 1.8
995
-     * @return string
996
-     */
997
-    public function render_form_buttons() {
998
-        return gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/form-buttons.php', $this );
999
-    }
1000
-
1001
-
1002
-    /**
1003
-     * Modify the form fields that are shown when using GFFormDisplay::get_form()
1004
-     *
1005
-     * By default, all fields will be shown. We only want the Edit Tab configured fields to be shown.
1006
-     *
1007
-     * @param array $form
1008
-     * @param boolean $ajax Whether in AJAX mode
1009
-     * @param array|string $field_values Passed parameters to the form
1010
-     *
1011
-     * @since 1.9
1012
-     *
1013
-     * @return array Modified form array
1014
-     */
1015
-    public function filter_modify_form_fields( $form, $ajax = false, $field_values = '' ) {
1016
-
1017
-        // In case we have validated the form, use it to inject the validation results into the form render
1018
-        if( isset( $this->form_after_validation ) ) {
1019
-            $form = $this->form_after_validation;
1020
-        } else {
1021
-            $form['fields'] = $this->get_configured_edit_fields( $form, $this->view_id );
1022
-        }
1023
-
1024
-        $form = $this->filter_conditional_logic( $form );
1025
-
1026
-        $form = $this->prefill_conditional_logic( $form );
1027
-
1028
-        // for now we don't support Save and Continue feature.
1029
-        if( ! self::$supports_save_and_continue ) {
1030
-	        unset( $form['save'] );
1031
-        }
1032
-
1033
-        return $form;
1034
-    }
1035
-
1036
-    /**
1037
-     * 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.
1038
-     *
1039
-     * @since 1.16.2.2
1040
-     *
1041
-     * @param string $field_content Always empty. Returning not-empty overrides the input.
1042
-     * @param GF_Field $field
1043
-     * @param string|array $value If array, it's a field with multiple inputs. If string, single input.
1044
-     * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter.
1045
-     * @param int $form_id Form ID
1046
-     *
1047
-     * @return string If error, the error message. If no error, blank string (modify_edit_field_input() runs next)
1048
-     */
1049
-    public function verify_user_can_edit_post( $field_content = '', $field, $value, $lead_id = 0, $form_id ) {
1050
-
1051
-        if( GFCommon::is_post_field( $field ) ) {
1052
-
1053
-            $message = null;
1054
-
1055
-            // First, make sure they have the capability to edit the post.
1056
-            if( false === current_user_can( 'edit_post', $this->entry['post_id'] ) ) {
1057
-
1058
-                /**
1059
-                 * @filter `gravityview/edit_entry/unsupported_post_field_text` Modify the message when someone isn't able to edit a post
1060
-                 * @param string $message The existing "You don't have permission..." text
1061
-                 */
1062
-                $message = apply_filters('gravityview/edit_entry/unsupported_post_field_text', __('You don&rsquo;t have permission to edit this post.', 'gravityview') );
1063
-
1064
-            } elseif( null === get_post( $this->entry['post_id'] ) ) {
1065
-                /**
1066
-                 * @filter `gravityview/edit_entry/no_post_text` Modify the message when someone is editing an entry attached to a post that no longer exists
1067
-                 * @param string $message The existing "This field is not editable; the post no longer exists." text
1068
-                 */
1069
-                $message = apply_filters('gravityview/edit_entry/no_post_text', __('This field is not editable; the post no longer exists.', 'gravityview' ) );
1070
-            }
1071
-
1072
-            if( $message ) {
1073
-                $field_content = sprintf('<div class="ginput_container ginput_container_' . $field->type . '">%s</div>', wpautop( $message ) );
1074
-            }
1075
-        }
1076
-
1077
-        return $field_content;
1078
-    }
1079
-
1080
-    /**
1081
-     *
1082
-     * Fill-in the saved values into the form inputs
1083
-     *
1084
-     * @param string $field_content Always empty. Returning not-empty overrides the input.
1085
-     * @param GF_Field $field
1086
-     * @param string|array $value If array, it's a field with multiple inputs. If string, single input.
1087
-     * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter.
1088
-     * @param int $form_id Form ID
1089
-     *
1090
-     * @return mixed
1091
-     */
1092
-    public function modify_edit_field_input( $field_content = '', $field, $value, $lead_id = 0, $form_id ) {
1093
-
1094
-        $gv_field = GravityView_Fields::get_associated_field( $field );
1095
-
1096
-        // If the form has been submitted, then we don't need to pre-fill the values,
1097
-        // Except for fileupload type and when a field input is overridden- run always!!
1098
-        if(
1099
-            ( $this->is_edit_entry_submission() && !in_array( $field->type, array( 'fileupload', 'post_image' ) ) )
1100
-            && false === ( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) )
1101
-            && ! GFCommon::is_product_field( $field->type )
1102
-            || ! empty( $field_content )
1103
-            || in_array( $field->type, array( 'honeypot' ) )
1104
-        ) {
1105
-	        return $field_content;
1106
-        }
1107
-
1108
-        // SET SOME FIELD DEFAULTS TO PREVENT ISSUES
1109
-        $field->adminOnly = false; /** @see GFFormDisplay::get_counter_init_script() need to prevent adminOnly */
1110
-
1111
-        $field_value = $this->get_field_value( $field );
1112
-
1113
-	    // Prevent any PHP warnings, like undefined index
1114
-	    ob_start();
1115
-
1116
-	    $return = null;
1117
-
1118
-        /** @var GravityView_Field $gv_field */
1119
-        if( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) ) {
1120
-            $return = $gv_field->get_field_input( $this->form, $field_value, $this->entry, $field );
1121
-        } else {
1122
-	        $return = $field->get_field_input( $this->form, $field_value, $this->entry );
1123
-	    }
1124
-
1125
-	    // If there was output, it's an error
1126
-	    $warnings = ob_get_clean();
1127
-
1128
-	    if( !empty( $warnings ) ) {
1129
-		    do_action( 'gravityview_log_error', __METHOD__ . $warnings, $field_value );
1130
-	    }
1131
-
1132
-        return $return;
1133
-    }
1134
-
1135
-    /**
1136
-     * Modify the value for the current field input
1137
-     *
1138
-     * @param GF_Field $field
1139
-     *
1140
-     * @return array|mixed|string
1141
-     */
1142
-    private function get_field_value( $field ) {
1143
-
1144
-        /**
1145
-         * @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.
1146
-         * @param boolean True: override saved values; False: don't override (default)
1147
-         * @param $field GF_Field object Gravity Forms field object
1148
-         * @since 1.13
1149
-         */
1150
-        $override_saved_value = apply_filters( 'gravityview/edit_entry/pre_populate/override', false, $field );
1151
-
1152
-        // We're dealing with multiple inputs (e.g. checkbox) but not time or date (as it doesn't store data in input IDs)
1153
-        if( isset( $field->inputs ) && is_array( $field->inputs ) && !in_array( $field->type, array( 'time', 'date' ) ) ) {
1154
-
1155
-            $field_value = array();
1156
-
1157
-            // only accept pre-populated values if the field doesn't have any choice selected.
1158
-            $allow_pre_populated = $field->allowsPrepopulate;
1159
-
1160
-            foreach ( (array)$field->inputs as $input ) {
1161
-
1162
-                $input_id = strval( $input['id'] );
1163
-                
1164
-                if ( isset( $this->entry[ $input_id ] ) && ! gv_empty( $this->entry[ $input_id ], false, false ) ) {
1165
-                    $field_value[ $input_id ] =  'post_category' === $field->type ? GFCommon::format_post_category( $this->entry[ $input_id ], true ) : $this->entry[ $input_id ];
1166
-                    $allow_pre_populated = false;
1167
-                }
1168
-
1169
-            }
1170
-
1171
-            $pre_value = $field->get_value_submission( array(), false );
1172
-
1173
-            $field_value = ! $allow_pre_populated && ! ( $override_saved_value && !gv_empty( $pre_value, false, false ) ) ? $field_value : $pre_value;
1174
-
1175
-        } else {
1176
-
1177
-            $id = intval( $field->id );
898
+	}
1178 899
 
1179
-            // get pre-populated value if exists
1180
-            $pre_value = $field->allowsPrepopulate ? GFFormsModel::get_parameter_value( $field->inputName, array(), $field ) : '';
1181
-
1182
-            // saved field entry value (if empty, fallback to the pre-populated value, if exists)
1183
-            // or pre-populated value if not empty and set to override saved value
1184
-            $field_value = !gv_empty( $this->entry[ $id ], false, false ) && ! ( $override_saved_value && !gv_empty( $pre_value, false, false ) ) ? $this->entry[ $id ] : $pre_value;
900
+	/**
901
+	 * Display success or error message if the form has been submitted
902
+	 *
903
+	 * @uses GVCommon::generate_notice
904
+	 *
905
+	 * @since 1.16.2.2
906
+	 *
907
+	 * @return void
908
+	 */
909
+	private function maybe_print_message() {
1185 910
 
1186
-            // in case field is post_category but inputType is select, multi-select or radio, convert value into array of category IDs.
1187
-            if ( 'post_category' === $field->type && !gv_empty( $field_value, false, false ) ) {
1188
-                $categories = array();
1189
-                foreach ( explode( ',', $field_value ) as $cat_string ) {
1190
-                    $categories[] = GFCommon::format_post_category( $cat_string, true );
1191
-                }
1192
-                $field_value = 'multiselect' === $field->get_input_type() ? $categories : implode( '', $categories );
1193
-            }
911
+		if( rgpost('action') === 'update' ) {
1194 912
 
1195
-        }
913
+			$back_link = esc_url( remove_query_arg( array( 'page', 'view', 'edit' ) ) );
1196 914
 
1197
-        // if value is empty get the default value if defined
1198
-        $field_value = $field->get_value_default_if_empty( $field_value );
1199
-
1200
-	    /**
1201
-	     * @filter `gravityview/edit_entry/field_value` Change the value of an Edit Entry field, if needed
1202
-	     * @since 1.11
1203
-	     * @since 1.20 Added third param
1204
-	     * @param mixed $field_value field value used to populate the input
1205
-	     * @param object $field Gravity Forms field object ( Class GF_Field )
1206
-	     * @param GravityView_Edit_Entry_Render $this Current object
1207
-	     */
1208
-	    $field_value = apply_filters( 'gravityview/edit_entry/field_value', $field_value, $field, $this );
915
+			if( ! $this->is_valid ){
1209 916
 
1210
-	    /**
1211
-	     * @filter `gravityview/edit_entry/field_value_{field_type}` Change the value of an Edit Entry field for a specific field type
1212
-	     * @since 1.17
1213
-	     * @since 1.20 Added third param
1214
-	     * @param mixed $field_value field value used to populate the input
1215
-	     * @param GF_Field $field Gravity Forms field object
1216
-	     * @param GravityView_Edit_Entry_Render $this Current object
1217
-	     */
1218
-	    $field_value = apply_filters( 'gravityview/edit_entry/field_value_' . $field->type , $field_value, $field, $this );
917
+				// Keeping this compatible with Gravity Forms.
918
+				$validation_message = "<div class='validation_error'>" . __('There was a problem with your submission.', 'gravityview') . " " . __('Errors have been highlighted below.', 'gravityview') . "</div>";
919
+				$message = apply_filters("gform_validation_message_{$this->form['id']}", apply_filters("gform_validation_message", $validation_message, $this->form), $this->form);
1219 920
 
1220
-        return $field_value;
1221
-    }
921
+				echo GVCommon::generate_notice( $message , 'gv-error' );
1222 922
 
923
+			} else {
924
+				$entry_updated_message = sprintf( esc_attr__('Entry Updated. %sReturn to Entry%s', 'gravityview'), '<a href="'. $back_link .'">', '</a>' );
1223 925
 
1224
-    // ---- Entry validation
926
+				/**
927
+				 * @filter `gravityview/edit_entry/success` Modify the edit entry success message (including the anchor link)
928
+				 * @since 1.5.4
929
+				 * @param string $entry_updated_message Existing message
930
+				 * @param int $view_id View ID
931
+				 * @param array $entry Gravity Forms entry array
932
+				 * @param string $back_link URL to return to the original entry. @since 1.6
933
+				 */
934
+				$message = apply_filters( 'gravityview/edit_entry/success', $entry_updated_message , $this->view_id, $this->entry, $back_link );
1225 935
 
1226
-    /**
1227
-     * Add field keys that Gravity Forms expects.
1228
-     *
1229
-     * @see GFFormDisplay::validate()
1230
-     * @param  array $form GF Form
1231
-     * @return array       Modified GF Form
1232
-     */
1233
-    public function gform_pre_validation( $form ) {
936
+				echo GVCommon::generate_notice( $message );
937
+			}
1234 938
 
1235
-        if( ! $this->verify_nonce() ) {
1236
-            return $form;
1237
-        }
1238
-
1239
-        // Fix PHP warning regarding undefined index.
1240
-        foreach ( $form['fields'] as &$field) {
1241
-
1242
-            // This is because we're doing admin form pretending to be front-end, so Gravity Forms
1243
-            // expects certain field array items to be set.
1244
-            foreach ( array( 'noDuplicates', 'adminOnly', 'inputType', 'isRequired', 'enablePrice', 'inputs', 'allowedExtensions' ) as $key ) {
1245
-	            $field->{$key} = isset( $field->{$key} ) ? $field->{$key} : NULL;
1246
-            }
1247
-
1248
-            switch( RGFormsModel::get_input_type( $field ) ) {
1249
-
1250
-                /**
1251
-                 * 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.
1252
-                 *
1253
-                 * 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.
1254
-                 *
1255
-                 * @hack
1256
-                 */
1257
-                case 'fileupload':
1258
-
1259
-                    // Set the previous value
1260
-                    $entry = $this->get_entry();
1261
-
1262
-                    $input_name = 'input_'.$field->id;
1263
-                    $form_id = $form['id'];
1264
-
1265
-                    $value = NULL;
939
+		}
940
+	}
1266 941
 
1267
-                    // Use the previous entry value as the default.
1268
-                    if( isset( $entry[ $field->id ] ) ) {
1269
-                        $value = $entry[ $field->id ];
1270
-                    }
1271
-
1272
-                    // If this is a single upload file
1273
-                    if( !empty( $_FILES[ $input_name ] ) && !empty( $_FILES[ $input_name ]['name'] ) ) {
1274
-                        $file_path = GFFormsModel::get_file_upload_path( $form['id'], $_FILES[ $input_name ]['name'] );
1275
-                        $value = $file_path['url'];
1276
-
1277
-                    } else {
1278
-
1279
-                        // Fix PHP warning on line 1498 of form_display.php for post_image fields
1280
-                        // Fix PHP Notice:  Undefined index:  size in form_display.php on line 1511
1281
-                        $_FILES[ $input_name ] = array('name' => '', 'size' => '' );
1282
-
1283
-                    }
1284
-
1285
-                    if( rgar($field, "multipleFiles") ) {
1286
-
1287
-                        // If there are fresh uploads, process and merge them.
1288
-                        // Otherwise, use the passed values, which should be json-encoded array of URLs
1289
-                        if( isset( GFFormsModel::$uploaded_files[$form_id][$input_name] ) ) {
1290
-                            $value = empty( $value ) ? '[]' : $value;
1291
-                            $value = stripslashes_deep( $value );
1292
-                            $value = GFFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'], array());
1293
-                        }
942
+	/**
943
+	 * Display the Edit Entry form in the original Gravity Forms format
944
+	 *
945
+	 * @since 1.9
946
+	 *
947
+	 * @return void
948
+	 */
949
+	private function render_edit_form() {
1294 950
 
1295
-                    } else {
951
+		/**
952
+		 * @action `gravityview/edit-entry/render/before` Before rendering the Edit Entry form
953
+		 * @since 1.17
954
+		 * @param GravityView_Edit_Entry_Render $this
955
+		 */
956
+		do_action( 'gravityview/edit-entry/render/before', $this );
1296 957
 
1297
-                        // A file already exists when editing an entry
1298
-                        // We set this to solve issue when file upload fields are required.
1299
-                        GFFormsModel::$uploaded_files[ $form_id ][ $input_name ] = $value;
1300
-
1301
-                    }
1302
-
1303
-                    $this->entry[ $input_name ] = $value;
1304
-                    $_POST[ $input_name ] = $value;
958
+		add_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields'), 5000, 3 );
959
+		add_filter( 'gform_submit_button', array( $this, 'render_form_buttons') );
960
+		add_filter( 'gform_disable_view_counter', '__return_true' );
1305 961
 
1306
-                    break;
962
+		add_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5, 5 );
963
+		add_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10, 5 );
1307 964
 
1308
-                case 'number':
1309
-                    // Fix "undefined index" issue at line 1286 in form_display.php
1310
-                    if( !isset( $_POST['input_'.$field->id ] ) ) {
1311
-                        $_POST['input_'.$field->id ] = NULL;
1312
-                    }
1313
-                    break;
1314
-            }
965
+		// We need to remove the fake $_GET['page'] arg to avoid rendering form as if in admin.
966
+		unset( $_GET['page'] );
1315 967
 
1316
-        }
968
+		// TODO: Verify multiple-page forms
1317 969
 
1318
-        return $form;
1319
-    }
970
+		ob_start(); // Prevent PHP warnings possibly caused by prefilling list fields for conditional logic
1320 971
 
972
+		$html = GFFormDisplay::get_form( $this->form['id'], false, false, true, $this->entry );
1321 973
 
1322
-    /**
1323
-     * Process validation for a edit entry submission
1324
-     *
1325
-     * Sets the `is_valid` object var
1326
-     *
1327
-     * @return void
1328
-     */
1329
-    private function validate() {
974
+		ob_get_clean();
1330 975
 
1331
-        /**
1332
-         * If using GF User Registration Add-on, remove the validation step, otherwise generates error when updating the entry
1333
-         * GF User Registration Add-on version > 3.x has a different class name
1334
-         * @since 1.16.2
1335
-         */
1336
-        if ( class_exists( 'GF_User_Registration' ) ) {
1337
-            remove_filter( 'gform_validation', array( GF_User_Registration::get_instance(), 'validate' ) );
1338
-        } else  if ( class_exists( 'GFUser' ) ) {
1339
-            remove_filter( 'gform_validation', array( 'GFUser', 'user_registration_validation' ) );
1340
-        }
976
+		remove_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields' ), 5000 );
977
+		remove_filter( 'gform_submit_button', array( $this, 'render_form_buttons' ) );
978
+		remove_filter( 'gform_disable_view_counter', '__return_true' );
979
+		remove_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5 );
980
+		remove_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10 );
1341 981
 
982
+		echo $html;
1342 983
 
1343
-        /**
1344
-         * For some crazy reason, Gravity Forms doesn't validate Edit Entry form submissions.
1345
-         * You can enter whatever you want!
1346
-         * We try validating, and customize the results using `self::custom_validation()`
1347
-         */
1348
-        add_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10, 4);
984
+		/**
985
+		 * @action `gravityview/edit-entry/render/after` After rendering the Edit Entry form
986
+		 * @since 1.17
987
+		 * @param GravityView_Edit_Entry_Render $this
988
+		 */
989
+		do_action( 'gravityview/edit-entry/render/after', $this );
990
+	}
1349 991
 
1350
-        // Needed by the validate funtion
1351
-        $failed_validation_page = NULL;
1352
-        $field_values = RGForms::post( 'gform_field_values' );
992
+	/**
993
+	 * Display the Update/Cancel/Delete buttons for the Edit Entry form
994
+	 * @since 1.8
995
+	 * @return string
996
+	 */
997
+	public function render_form_buttons() {
998
+		return gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/form-buttons.php', $this );
999
+	}
1353 1000
 
1354
-        // Prevent entry limit from running when editing an entry, also
1355
-        // prevent form scheduling from preventing editing
1356
-        unset( $this->form['limitEntries'], $this->form['scheduleForm'] );
1357 1001
 
1358
-        // Hide fields depending on Edit Entry settings
1359
-        $this->form['fields'] = $this->get_configured_edit_fields( $this->form, $this->view_id );
1002
+	/**
1003
+	 * Modify the form fields that are shown when using GFFormDisplay::get_form()
1004
+	 *
1005
+	 * By default, all fields will be shown. We only want the Edit Tab configured fields to be shown.
1006
+	 *
1007
+	 * @param array $form
1008
+	 * @param boolean $ajax Whether in AJAX mode
1009
+	 * @param array|string $field_values Passed parameters to the form
1010
+	 *
1011
+	 * @since 1.9
1012
+	 *
1013
+	 * @return array Modified form array
1014
+	 */
1015
+	public function filter_modify_form_fields( $form, $ajax = false, $field_values = '' ) {
1360 1016
 
1361
-        $this->is_valid = GFFormDisplay::validate( $this->form, $field_values, 1, $failed_validation_page );
1017
+		// In case we have validated the form, use it to inject the validation results into the form render
1018
+		if( isset( $this->form_after_validation ) ) {
1019
+			$form = $this->form_after_validation;
1020
+		} else {
1021
+			$form['fields'] = $this->get_configured_edit_fields( $form, $this->view_id );
1022
+		}
1362 1023
 
1363
-        remove_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10 );
1364
-    }
1024
+		$form = $this->filter_conditional_logic( $form );
1365 1025
 
1026
+		$form = $this->prefill_conditional_logic( $form );
1366 1027
 
1367
-    /**
1368
-     * Make validation work for Edit Entry
1369
-     *
1370
-     * Because we're calling the GFFormDisplay::validate() in an unusual way (as a front-end
1371
-     * form pretending to be a back-end form), validate() doesn't know we _can't_ edit post
1372
-     * fields. This goes through all the fields and if they're an invalid post field, we
1373
-     * set them as valid. If there are still issues, we'll return false.
1374
-     *
1375
-     * @param  [type] $validation_results [description]
1376
-     * @return [type]                     [description]
1377
-     */
1378
-    public function custom_validation( $validation_results ) {
1028
+		// for now we don't support Save and Continue feature.
1029
+		if( ! self::$supports_save_and_continue ) {
1030
+			unset( $form['save'] );
1031
+		}
1379 1032
 
1380
-        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results: ', $validation_results );
1033
+		return $form;
1034
+	}
1381 1035
 
1382
-        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) );
1036
+	/**
1037
+	 * 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.
1038
+	 *
1039
+	 * @since 1.16.2.2
1040
+	 *
1041
+	 * @param string $field_content Always empty. Returning not-empty overrides the input.
1042
+	 * @param GF_Field $field
1043
+	 * @param string|array $value If array, it's a field with multiple inputs. If string, single input.
1044
+	 * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter.
1045
+	 * @param int $form_id Form ID
1046
+	 *
1047
+	 * @return string If error, the error message. If no error, blank string (modify_edit_field_input() runs next)
1048
+	 */
1049
+	public function verify_user_can_edit_post( $field_content = '', $field, $value, $lead_id = 0, $form_id ) {
1383 1050
 
1384
-        $gv_valid = true;
1051
+		if( GFCommon::is_post_field( $field ) ) {
1385 1052
 
1386
-        foreach ( $validation_results['form']['fields'] as $key => &$field ) {
1053
+			$message = null;
1387 1054
 
1388
-            $value = RGFormsModel::get_field_value( $field );
1389
-            $field_type = RGFormsModel::get_input_type( $field );
1055
+			// First, make sure they have the capability to edit the post.
1056
+			if( false === current_user_can( 'edit_post', $this->entry['post_id'] ) ) {
1390 1057
 
1391
-            // Validate always
1392
-            switch ( $field_type ) {
1058
+				/**
1059
+				 * @filter `gravityview/edit_entry/unsupported_post_field_text` Modify the message when someone isn't able to edit a post
1060
+				 * @param string $message The existing "You don't have permission..." text
1061
+				 */
1062
+				$message = apply_filters('gravityview/edit_entry/unsupported_post_field_text', __('You don&rsquo;t have permission to edit this post.', 'gravityview') );
1393 1063
 
1064
+			} elseif( null === get_post( $this->entry['post_id'] ) ) {
1065
+				/**
1066
+				 * @filter `gravityview/edit_entry/no_post_text` Modify the message when someone is editing an entry attached to a post that no longer exists
1067
+				 * @param string $message The existing "This field is not editable; the post no longer exists." text
1068
+				 */
1069
+				$message = apply_filters('gravityview/edit_entry/no_post_text', __('This field is not editable; the post no longer exists.', 'gravityview' ) );
1070
+			}
1394 1071
 
1395
-                case 'fileupload' :
1396
-                case 'post_image':
1072
+			if( $message ) {
1073
+				$field_content = sprintf('<div class="ginput_container ginput_container_' . $field->type . '">%s</div>', wpautop( $message ) );
1074
+			}
1075
+		}
1397 1076
 
1398
-                    // in case nothing is uploaded but there are already files saved
1399
-                    if( !empty( $field->failed_validation ) && !empty( $field->isRequired ) && !empty( $value ) ) {
1400
-                        $field->failed_validation = false;
1401
-                        unset( $field->validation_message );
1402
-                    }
1077
+		return $field_content;
1078
+	}
1403 1079
 
1404
-                    // validate if multi file upload reached max number of files [maxFiles] => 2
1405
-                    if( rgobj( $field, 'maxFiles') && rgobj( $field, 'multipleFiles') ) {
1080
+	/**
1081
+	 *
1082
+	 * Fill-in the saved values into the form inputs
1083
+	 *
1084
+	 * @param string $field_content Always empty. Returning not-empty overrides the input.
1085
+	 * @param GF_Field $field
1086
+	 * @param string|array $value If array, it's a field with multiple inputs. If string, single input.
1087
+	 * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter.
1088
+	 * @param int $form_id Form ID
1089
+	 *
1090
+	 * @return mixed
1091
+	 */
1092
+	public function modify_edit_field_input( $field_content = '', $field, $value, $lead_id = 0, $form_id ) {
1093
+
1094
+		$gv_field = GravityView_Fields::get_associated_field( $field );
1095
+
1096
+		// If the form has been submitted, then we don't need to pre-fill the values,
1097
+		// Except for fileupload type and when a field input is overridden- run always!!
1098
+		if(
1099
+			( $this->is_edit_entry_submission() && !in_array( $field->type, array( 'fileupload', 'post_image' ) ) )
1100
+			&& false === ( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) )
1101
+			&& ! GFCommon::is_product_field( $field->type )
1102
+			|| ! empty( $field_content )
1103
+			|| in_array( $field->type, array( 'honeypot' ) )
1104
+		) {
1105
+			return $field_content;
1106
+		}
1406 1107
 
1407
-                        $input_name = 'input_' . $field->id;
1408
-                        //uploaded
1409
-                        $file_names = isset( GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] ) ? GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] : array();
1108
+		// SET SOME FIELD DEFAULTS TO PREVENT ISSUES
1109
+		$field->adminOnly = false; /** @see GFFormDisplay::get_counter_init_script() need to prevent adminOnly */
1410 1110
 
1411
-                        //existent
1412
-                        $entry = $this->get_entry();
1413
-                        $value = NULL;
1414
-                        if( isset( $entry[ $field->id ] ) ) {
1415
-                            $value = json_decode( $entry[ $field->id ], true );
1416
-                        }
1111
+		$field_value = $this->get_field_value( $field );
1417 1112
 
1418
-                        // count uploaded files and existent entry files
1419
-                        $count_files = count( $file_names ) + count( $value );
1113
+		// Prevent any PHP warnings, like undefined index
1114
+		ob_start();
1420 1115
 
1421
-                        if( $count_files > $field->maxFiles ) {
1422
-                            $field->validation_message = __( 'Maximum number of files reached', 'gravityview' );
1423
-                            $field->failed_validation = 1;
1424
-                            $gv_valid = false;
1116
+		$return = null;
1425 1117
 
1426
-                            // in case of error make sure the newest upload files are removed from the upload input
1427
-                            GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ] = null;
1428
-                        }
1118
+		/** @var GravityView_Field $gv_field */
1119
+		if( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) ) {
1120
+			$return = $gv_field->get_field_input( $this->form, $field_value, $this->entry, $field );
1121
+		} else {
1122
+			$return = $field->get_field_input( $this->form, $field_value, $this->entry );
1123
+		}
1429 1124
 
1430
-                    }
1125
+		// If there was output, it's an error
1126
+		$warnings = ob_get_clean();
1431 1127
 
1128
+		if( !empty( $warnings ) ) {
1129
+			do_action( 'gravityview_log_error', __METHOD__ . $warnings, $field_value );
1130
+		}
1432 1131
 
1433
-                    break;
1132
+		return $return;
1133
+	}
1434 1134
 
1435
-            }
1135
+	/**
1136
+	 * Modify the value for the current field input
1137
+	 *
1138
+	 * @param GF_Field $field
1139
+	 *
1140
+	 * @return array|mixed|string
1141
+	 */
1142
+	private function get_field_value( $field ) {
1143
+
1144
+		/**
1145
+		 * @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.
1146
+		 * @param boolean True: override saved values; False: don't override (default)
1147
+		 * @param $field GF_Field object Gravity Forms field object
1148
+		 * @since 1.13
1149
+		 */
1150
+		$override_saved_value = apply_filters( 'gravityview/edit_entry/pre_populate/override', false, $field );
1151
+
1152
+		// We're dealing with multiple inputs (e.g. checkbox) but not time or date (as it doesn't store data in input IDs)
1153
+		if( isset( $field->inputs ) && is_array( $field->inputs ) && !in_array( $field->type, array( 'time', 'date' ) ) ) {
1154
+
1155
+			$field_value = array();
1156
+
1157
+			// only accept pre-populated values if the field doesn't have any choice selected.
1158
+			$allow_pre_populated = $field->allowsPrepopulate;
1159
+
1160
+			foreach ( (array)$field->inputs as $input ) {
1161
+
1162
+				$input_id = strval( $input['id'] );
1163
+                
1164
+				if ( isset( $this->entry[ $input_id ] ) && ! gv_empty( $this->entry[ $input_id ], false, false ) ) {
1165
+					$field_value[ $input_id ] =  'post_category' === $field->type ? GFCommon::format_post_category( $this->entry[ $input_id ], true ) : $this->entry[ $input_id ];
1166
+					$allow_pre_populated = false;
1167
+				}
1168
+
1169
+			}
1170
+
1171
+			$pre_value = $field->get_value_submission( array(), false );
1172
+
1173
+			$field_value = ! $allow_pre_populated && ! ( $override_saved_value && !gv_empty( $pre_value, false, false ) ) ? $field_value : $pre_value;
1174
+
1175
+		} else {
1176
+
1177
+			$id = intval( $field->id );
1178
+
1179
+			// get pre-populated value if exists
1180
+			$pre_value = $field->allowsPrepopulate ? GFFormsModel::get_parameter_value( $field->inputName, array(), $field ) : '';
1181
+
1182
+			// saved field entry value (if empty, fallback to the pre-populated value, if exists)
1183
+			// or pre-populated value if not empty and set to override saved value
1184
+			$field_value = !gv_empty( $this->entry[ $id ], false, false ) && ! ( $override_saved_value && !gv_empty( $pre_value, false, false ) ) ? $this->entry[ $id ] : $pre_value;
1185
+
1186
+			// in case field is post_category but inputType is select, multi-select or radio, convert value into array of category IDs.
1187
+			if ( 'post_category' === $field->type && !gv_empty( $field_value, false, false ) ) {
1188
+				$categories = array();
1189
+				foreach ( explode( ',', $field_value ) as $cat_string ) {
1190
+					$categories[] = GFCommon::format_post_category( $cat_string, true );
1191
+				}
1192
+				$field_value = 'multiselect' === $field->get_input_type() ? $categories : implode( '', $categories );
1193
+			}
1194
+
1195
+		}
1196
+
1197
+		// if value is empty get the default value if defined
1198
+		$field_value = $field->get_value_default_if_empty( $field_value );
1199
+
1200
+		/**
1201
+		 * @filter `gravityview/edit_entry/field_value` Change the value of an Edit Entry field, if needed
1202
+		 * @since 1.11
1203
+		 * @since 1.20 Added third param
1204
+		 * @param mixed $field_value field value used to populate the input
1205
+		 * @param object $field Gravity Forms field object ( Class GF_Field )
1206
+		 * @param GravityView_Edit_Entry_Render $this Current object
1207
+		 */
1208
+		$field_value = apply_filters( 'gravityview/edit_entry/field_value', $field_value, $field, $this );
1209
+
1210
+		/**
1211
+		 * @filter `gravityview/edit_entry/field_value_{field_type}` Change the value of an Edit Entry field for a specific field type
1212
+		 * @since 1.17
1213
+		 * @since 1.20 Added third param
1214
+		 * @param mixed $field_value field value used to populate the input
1215
+		 * @param GF_Field $field Gravity Forms field object
1216
+		 * @param GravityView_Edit_Entry_Render $this Current object
1217
+		 */
1218
+		$field_value = apply_filters( 'gravityview/edit_entry/field_value_' . $field->type , $field_value, $field, $this );
1219
+
1220
+		return $field_value;
1221
+	}
1436 1222
 
1437
-            // This field has failed validation.
1438
-            if( !empty( $field->failed_validation ) ) {
1439 1223
 
1440
-                do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field is invalid.', array( 'field' => $field, 'value' => $value ) );
1224
+	// ---- Entry validation
1441 1225
 
1442
-                switch ( $field_type ) {
1226
+	/**
1227
+	 * Add field keys that Gravity Forms expects.
1228
+	 *
1229
+	 * @see GFFormDisplay::validate()
1230
+	 * @param  array $form GF Form
1231
+	 * @return array       Modified GF Form
1232
+	 */
1233
+	public function gform_pre_validation( $form ) {
1234
+
1235
+		if( ! $this->verify_nonce() ) {
1236
+			return $form;
1237
+		}
1238
+
1239
+		// Fix PHP warning regarding undefined index.
1240
+		foreach ( $form['fields'] as &$field) {
1241
+
1242
+			// This is because we're doing admin form pretending to be front-end, so Gravity Forms
1243
+			// expects certain field array items to be set.
1244
+			foreach ( array( 'noDuplicates', 'adminOnly', 'inputType', 'isRequired', 'enablePrice', 'inputs', 'allowedExtensions' ) as $key ) {
1245
+				$field->{$key} = isset( $field->{$key} ) ? $field->{$key} : NULL;
1246
+			}
1247
+
1248
+			switch( RGFormsModel::get_input_type( $field ) ) {
1249
+
1250
+				/**
1251
+				 * 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.
1252
+				 *
1253
+				 * 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.
1254
+				 *
1255
+				 * @hack
1256
+				 */
1257
+				case 'fileupload':
1258
+
1259
+					// Set the previous value
1260
+					$entry = $this->get_entry();
1261
+
1262
+					$input_name = 'input_'.$field->id;
1263
+					$form_id = $form['id'];
1264
+
1265
+					$value = NULL;
1266
+
1267
+					// Use the previous entry value as the default.
1268
+					if( isset( $entry[ $field->id ] ) ) {
1269
+						$value = $entry[ $field->id ];
1270
+					}
1271
+
1272
+					// If this is a single upload file
1273
+					if( !empty( $_FILES[ $input_name ] ) && !empty( $_FILES[ $input_name ]['name'] ) ) {
1274
+						$file_path = GFFormsModel::get_file_upload_path( $form['id'], $_FILES[ $input_name ]['name'] );
1275
+						$value = $file_path['url'];
1276
+
1277
+					} else {
1278
+
1279
+						// Fix PHP warning on line 1498 of form_display.php for post_image fields
1280
+						// Fix PHP Notice:  Undefined index:  size in form_display.php on line 1511
1281
+						$_FILES[ $input_name ] = array('name' => '', 'size' => '' );
1282
+
1283
+					}
1443 1284
 
1444
-                    // Captchas don't need to be re-entered.
1445
-                    case 'captcha':
1285
+					if( rgar($field, "multipleFiles") ) {
1446 1286
 
1447
-                        // Post Image fields aren't editable, so we un-fail them.
1448
-                    case 'post_image':
1449
-                        $field->failed_validation = false;
1450
-                        unset( $field->validation_message );
1451
-                        break;
1287
+						// If there are fresh uploads, process and merge them.
1288
+						// Otherwise, use the passed values, which should be json-encoded array of URLs
1289
+						if( isset( GFFormsModel::$uploaded_files[$form_id][$input_name] ) ) {
1290
+							$value = empty( $value ) ? '[]' : $value;
1291
+							$value = stripslashes_deep( $value );
1292
+							$value = GFFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'], array());
1293
+						}
1452 1294
 
1453
-                }
1295
+					} else {
1454 1296
 
1455
-                // You can't continue inside a switch, so we do it after.
1456
-                if( empty( $field->failed_validation ) ) {
1457
-                    continue;
1458
-                }
1297
+						// A file already exists when editing an entry
1298
+						// We set this to solve issue when file upload fields are required.
1299
+						GFFormsModel::$uploaded_files[ $form_id ][ $input_name ] = $value;
1459 1300
 
1460
-                // checks if the No Duplicates option is not validating entry against itself, since
1461
-                // we're editing a stored entry, it would also assume it's a duplicate.
1462
-                if( !empty( $field->noDuplicates ) ) {
1301
+					}
1463 1302
 
1464
-                    $entry = $this->get_entry();
1303
+					$this->entry[ $input_name ] = $value;
1304
+					$_POST[ $input_name ] = $value;
1465 1305
 
1466
-                    // If the value of the entry is the same as the stored value
1467
-                    // Then we can assume it's not a duplicate, it's the same.
1468
-                    if( !empty( $entry ) && $value == $entry[ $field->id ] ) {
1469
-                        //if value submitted was not changed, then don't validate
1470
-                        $field->failed_validation = false;
1306
+					break;
1471 1307
 
1472
-                        unset( $field->validation_message );
1308
+				case 'number':
1309
+					// Fix "undefined index" issue at line 1286 in form_display.php
1310
+					if( !isset( $_POST['input_'.$field->id ] ) ) {
1311
+						$_POST['input_'.$field->id ] = NULL;
1312
+					}
1313
+					break;
1314
+			}
1473 1315
 
1474
-                        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', $entry );
1316
+		}
1475 1317
 
1476
-                        continue;
1477
-                    }
1478
-                }
1318
+		return $form;
1319
+	}
1479 1320
 
1480
-                // if here then probably we are facing the validation 'At least one field must be filled out'
1481
-                if( GFFormDisplay::is_empty( $field, $this->form_id  ) && empty( $field->isRequired ) ) {
1482
-                    unset( $field->validation_message );
1483
-	                $field->validation_message = false;
1484
-                    continue;
1485
-                }
1486 1321
 
1487
-                $gv_valid = false;
1322
+	/**
1323
+	 * Process validation for a edit entry submission
1324
+	 *
1325
+	 * Sets the `is_valid` object var
1326
+	 *
1327
+	 * @return void
1328
+	 */
1329
+	private function validate() {
1330
+
1331
+		/**
1332
+		 * If using GF User Registration Add-on, remove the validation step, otherwise generates error when updating the entry
1333
+		 * GF User Registration Add-on version > 3.x has a different class name
1334
+		 * @since 1.16.2
1335
+		 */
1336
+		if ( class_exists( 'GF_User_Registration' ) ) {
1337
+			remove_filter( 'gform_validation', array( GF_User_Registration::get_instance(), 'validate' ) );
1338
+		} else  if ( class_exists( 'GFUser' ) ) {
1339
+			remove_filter( 'gform_validation', array( 'GFUser', 'user_registration_validation' ) );
1340
+		}
1488 1341
 
1489
-            }
1490 1342
 
1491
-        }
1343
+		/**
1344
+		 * For some crazy reason, Gravity Forms doesn't validate Edit Entry form submissions.
1345
+		 * You can enter whatever you want!
1346
+		 * We try validating, and customize the results using `self::custom_validation()`
1347
+		 */
1348
+		add_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10, 4);
1492 1349
 
1493
-        $validation_results['is_valid'] = $gv_valid;
1350
+		// Needed by the validate funtion
1351
+		$failed_validation_page = NULL;
1352
+		$field_values = RGForms::post( 'gform_field_values' );
1494 1353
 
1495
-        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results.', $validation_results );
1354
+		// Prevent entry limit from running when editing an entry, also
1355
+		// prevent form scheduling from preventing editing
1356
+		unset( $this->form['limitEntries'], $this->form['scheduleForm'] );
1496 1357
 
1497
-        // We'll need this result when rendering the form ( on GFFormDisplay::get_form )
1498
-        $this->form_after_validation = $validation_results['form'];
1358
+		// Hide fields depending on Edit Entry settings
1359
+		$this->form['fields'] = $this->get_configured_edit_fields( $this->form, $this->view_id );
1499 1360
 
1500
-        return $validation_results;
1501
-    }
1361
+		$this->is_valid = GFFormDisplay::validate( $this->form, $field_values, 1, $failed_validation_page );
1502 1362
 
1363
+		remove_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10 );
1364
+	}
1503 1365
 
1504
-    /**
1505
-     * TODO: This seems to be hacky... we should remove it. Entry is set when updating the form using setup_vars()!
1506
-     * Get the current entry and set it if it's not yet set.
1507
-     * @return array Gravity Forms entry array
1508
-     */
1509
-    public function get_entry() {
1510 1366
 
1511
-        if( empty( $this->entry ) ) {
1512
-            // Get the database value of the entry that's being edited
1513
-            $this->entry = gravityview_get_entry( GravityView_frontend::is_single_entry() );
1514
-        }
1367
+	/**
1368
+	 * Make validation work for Edit Entry
1369
+	 *
1370
+	 * Because we're calling the GFFormDisplay::validate() in an unusual way (as a front-end
1371
+	 * form pretending to be a back-end form), validate() doesn't know we _can't_ edit post
1372
+	 * fields. This goes through all the fields and if they're an invalid post field, we
1373
+	 * set them as valid. If there are still issues, we'll return false.
1374
+	 *
1375
+	 * @param  [type] $validation_results [description]
1376
+	 * @return [type]                     [description]
1377
+	 */
1378
+	public function custom_validation( $validation_results ) {
1515 1379
 
1516
-        return $this->entry;
1517
-    }
1380
+		do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results: ', $validation_results );
1518 1381
 
1382
+		do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) );
1519 1383
 
1384
+		$gv_valid = true;
1520 1385
 
1521
-    // --- Filters
1386
+		foreach ( $validation_results['form']['fields'] as $key => &$field ) {
1522 1387
 
1523
-    /**
1524
-     * Get the Edit Entry fields as configured in the View
1525
-     *
1526
-     * @since 1.8
1527
-     *
1528
-     * @param int $view_id
1529
-     *
1530
-     * @return array Array of fields that are configured in the Edit tab in the Admin
1531
-     */
1532
-    private function get_configured_edit_fields( $form, $view_id ) {
1388
+			$value = RGFormsModel::get_field_value( $field );
1389
+			$field_type = RGFormsModel::get_input_type( $field );
1533 1390
 
1534
-        // Get all fields for form
1391
+			// Validate always
1392
+			switch ( $field_type ) {
1393
+
1394
+
1395
+				case 'fileupload' :
1396
+				case 'post_image':
1397
+
1398
+					// in case nothing is uploaded but there are already files saved
1399
+					if( !empty( $field->failed_validation ) && !empty( $field->isRequired ) && !empty( $value ) ) {
1400
+						$field->failed_validation = false;
1401
+						unset( $field->validation_message );
1402
+					}
1403
+
1404
+					// validate if multi file upload reached max number of files [maxFiles] => 2
1405
+					if( rgobj( $field, 'maxFiles') && rgobj( $field, 'multipleFiles') ) {
1406
+
1407
+						$input_name = 'input_' . $field->id;
1408
+						//uploaded
1409
+						$file_names = isset( GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] ) ? GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] : array();
1410
+
1411
+						//existent
1412
+						$entry = $this->get_entry();
1413
+						$value = NULL;
1414
+						if( isset( $entry[ $field->id ] ) ) {
1415
+							$value = json_decode( $entry[ $field->id ], true );
1416
+						}
1417
+
1418
+						// count uploaded files and existent entry files
1419
+						$count_files = count( $file_names ) + count( $value );
1420
+
1421
+						if( $count_files > $field->maxFiles ) {
1422
+							$field->validation_message = __( 'Maximum number of files reached', 'gravityview' );
1423
+							$field->failed_validation = 1;
1424
+							$gv_valid = false;
1425
+
1426
+							// in case of error make sure the newest upload files are removed from the upload input
1427
+							GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ] = null;
1428
+						}
1429
+
1430
+					}
1431
+
1432
+
1433
+					break;
1434
+
1435
+			}
1436
+
1437
+			// This field has failed validation.
1438
+			if( !empty( $field->failed_validation ) ) {
1439
+
1440
+				do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field is invalid.', array( 'field' => $field, 'value' => $value ) );
1441
+
1442
+				switch ( $field_type ) {
1443
+
1444
+					// Captchas don't need to be re-entered.
1445
+					case 'captcha':
1446
+
1447
+						// Post Image fields aren't editable, so we un-fail them.
1448
+					case 'post_image':
1449
+						$field->failed_validation = false;
1450
+						unset( $field->validation_message );
1451
+						break;
1452
+
1453
+				}
1454
+
1455
+				// You can't continue inside a switch, so we do it after.
1456
+				if( empty( $field->failed_validation ) ) {
1457
+					continue;
1458
+				}
1459
+
1460
+				// checks if the No Duplicates option is not validating entry against itself, since
1461
+				// we're editing a stored entry, it would also assume it's a duplicate.
1462
+				if( !empty( $field->noDuplicates ) ) {
1463
+
1464
+					$entry = $this->get_entry();
1465
+
1466
+					// If the value of the entry is the same as the stored value
1467
+					// Then we can assume it's not a duplicate, it's the same.
1468
+					if( !empty( $entry ) && $value == $entry[ $field->id ] ) {
1469
+						//if value submitted was not changed, then don't validate
1470
+						$field->failed_validation = false;
1471
+
1472
+						unset( $field->validation_message );
1473
+
1474
+						do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', $entry );
1475
+
1476
+						continue;
1477
+					}
1478
+				}
1479
+
1480
+				// if here then probably we are facing the validation 'At least one field must be filled out'
1481
+				if( GFFormDisplay::is_empty( $field, $this->form_id  ) && empty( $field->isRequired ) ) {
1482
+					unset( $field->validation_message );
1483
+					$field->validation_message = false;
1484
+					continue;
1485
+				}
1486
+
1487
+				$gv_valid = false;
1488
+
1489
+			}
1490
+
1491
+		}
1492
+
1493
+		$validation_results['is_valid'] = $gv_valid;
1494
+
1495
+		do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results.', $validation_results );
1496
+
1497
+		// We'll need this result when rendering the form ( on GFFormDisplay::get_form )
1498
+		$this->form_after_validation = $validation_results['form'];
1499
+
1500
+		return $validation_results;
1501
+	}
1502
+
1503
+
1504
+	/**
1505
+	 * TODO: This seems to be hacky... we should remove it. Entry is set when updating the form using setup_vars()!
1506
+	 * Get the current entry and set it if it's not yet set.
1507
+	 * @return array Gravity Forms entry array
1508
+	 */
1509
+	public function get_entry() {
1510
+
1511
+		if( empty( $this->entry ) ) {
1512
+			// Get the database value of the entry that's being edited
1513
+			$this->entry = gravityview_get_entry( GravityView_frontend::is_single_entry() );
1514
+		}
1515
+
1516
+		return $this->entry;
1517
+	}
1518
+
1519
+
1520
+
1521
+	// --- Filters
1522
+
1523
+	/**
1524
+	 * Get the Edit Entry fields as configured in the View
1525
+	 *
1526
+	 * @since 1.8
1527
+	 *
1528
+	 * @param int $view_id
1529
+	 *
1530
+	 * @return array Array of fields that are configured in the Edit tab in the Admin
1531
+	 */
1532
+	private function get_configured_edit_fields( $form, $view_id ) {
1533
+
1534
+		// Get all fields for form
1535 1535
 		if ( defined( 'GRAVITYVIEW_FUTURE_CORE_LOADED' ) ) {
1536 1536
 			if ( gv_shim_GV_View_exists( $view_id ) ) {
1537 1537
 				$view = gv_shim_GV_View_by_id( $view_id );
@@ -1542,446 +1542,446 @@  discard block
 block discarded – undo
1542 1542
 			$properties = GravityView_View_Data::getInstance()->get_fields( $view_id );
1543 1543
 		}
1544 1544
 
1545
-        // If edit tab not yet configured, show all fields
1546
-        $edit_fields = !empty( $properties['edit_edit-fields'] ) ? $properties['edit_edit-fields'] : NULL;
1545
+		// If edit tab not yet configured, show all fields
1546
+		$edit_fields = !empty( $properties['edit_edit-fields'] ) ? $properties['edit_edit-fields'] : NULL;
1547
+
1548
+		// Hide fields depending on admin settings
1549
+		$fields = $this->filter_fields( $form['fields'], $edit_fields );
1550
+
1551
+		// If Edit Entry fields are configured, remove adminOnly field settings. Otherwise, don't.
1552
+		$fields = $this->filter_admin_only_fields( $fields, $edit_fields, $form, $view_id );
1553
+
1554
+		/**
1555
+		 * @filter `gravityview/edit_entry/form_fields` Modify the fields displayed in Edit Entry form
1556
+		 * @since 1.17
1557
+		 * @param GF_Field[] $fields Gravity Forms form fields
1558
+		 * @param array|null $edit_fields Fields for the Edit Entry tab configured in the View Configuration
1559
+		 * @param array $form GF Form array (`fields` key modified to have only fields configured to show in Edit Entry)
1560
+		 * @param int $view_id View ID
1561
+		 */
1562
+		$fields = apply_filters( 'gravityview/edit_entry/form_fields', $fields, $edit_fields, $form, $view_id );
1563
+
1564
+		return $fields;
1565
+	}
1566
+
1567
+
1568
+	/**
1569
+	 * Filter area fields based on specified conditions
1570
+	 *  - This filter removes the fields that have calculation configured
1571
+	 *
1572
+	 * @uses GravityView_Edit_Entry::user_can_edit_field() Check caps
1573
+	 * @access private
1574
+	 * @param GF_Field[] $fields
1575
+	 * @param array $configured_fields
1576
+	 * @since  1.5
1577
+	 * @return array $fields
1578
+	 */
1579
+	private function filter_fields( $fields, $configured_fields ) {
1580
+
1581
+		if( empty( $fields ) || !is_array( $fields ) ) {
1582
+			return $fields;
1583
+		}
1584
+
1585
+		$edit_fields = array();
1547 1586
 
1548
-        // Hide fields depending on admin settings
1549
-        $fields = $this->filter_fields( $form['fields'], $edit_fields );
1587
+		$field_type_blacklist = $this->loader->get_field_blacklist( $this->entry );
1550 1588
 
1551
-	    // If Edit Entry fields are configured, remove adminOnly field settings. Otherwise, don't.
1552
-	    $fields = $this->filter_admin_only_fields( $fields, $edit_fields, $form, $view_id );
1589
+		// First, remove blacklist or calculation fields
1590
+		foreach ( $fields as $key => $field ) {
1553 1591
 
1554
-        /**
1555
-         * @filter `gravityview/edit_entry/form_fields` Modify the fields displayed in Edit Entry form
1556
-         * @since 1.17
1557
-         * @param GF_Field[] $fields Gravity Forms form fields
1558
-         * @param array|null $edit_fields Fields for the Edit Entry tab configured in the View Configuration
1559
-         * @param array $form GF Form array (`fields` key modified to have only fields configured to show in Edit Entry)
1560
-         * @param int $view_id View ID
1561
-         */
1562
-        $fields = apply_filters( 'gravityview/edit_entry/form_fields', $fields, $edit_fields, $form, $view_id );
1592
+			// Remove the fields that have calculation properties and keep them to be used later
1593
+			// @since 1.16.2
1594
+			if( $field->has_calculation() ) {
1595
+				$this->fields_with_calculation[] = $field;
1596
+				// don't remove the calculation fields on form render.
1597
+			}
1598
+
1599
+			if( in_array( $field->type, $field_type_blacklist ) ) {
1600
+				unset( $fields[ $key ] );
1601
+			}
1602
+		}
1603
+
1604
+		// The Edit tab has not been configured, so we return all fields by default.
1605
+		if( empty( $configured_fields ) ) {
1606
+			return $fields;
1607
+		}
1608
+
1609
+		// The edit tab has been configured, so we loop through to configured settings
1610
+		foreach ( $configured_fields as $configured_field ) {
1611
+
1612
+			/** @var GF_Field $field */
1613
+			foreach ( $fields as $field ) {
1614
+
1615
+				if( intval( $configured_field['id'] ) === intval( $field->id ) && $this->user_can_edit_field( $configured_field, false ) ) {
1616
+					$edit_fields[] = $this->merge_field_properties( $field, $configured_field );
1617
+					break;
1618
+				}
1619
+
1620
+			}
1621
+
1622
+		}
1623
+
1624
+		return $edit_fields;
1625
+
1626
+	}
1627
+
1628
+	/**
1629
+	 * Override GF Form field properties with the ones defined on the View
1630
+	 * @param  GF_Field $field GF Form field object
1631
+	 * @param  array $field_setting  GV field options
1632
+	 * @since  1.5
1633
+	 * @return array|GF_Field
1634
+	 */
1635
+	private function merge_field_properties( $field, $field_setting ) {
1636
+
1637
+		$return_field = $field;
1638
+
1639
+		if( empty( $field_setting['show_label'] ) ) {
1640
+			$return_field->label = '';
1641
+		} elseif ( !empty( $field_setting['custom_label'] ) ) {
1642
+			$return_field->label = $field_setting['custom_label'];
1643
+		}
1644
+
1645
+		if( !empty( $field_setting['custom_class'] ) ) {
1646
+			$return_field->cssClass .= ' '. gravityview_sanitize_html_class( $field_setting['custom_class'] );
1647
+		}
1648
+
1649
+		/**
1650
+		 * Normalize page numbers - avoid conflicts with page validation
1651
+		 * @since 1.6
1652
+		 */
1653
+		$return_field->pageNumber = 1;
1563 1654
 
1564
-        return $fields;
1565
-    }
1566
-
1567
-
1568
-    /**
1569
-     * Filter area fields based on specified conditions
1570
-     *  - This filter removes the fields that have calculation configured
1571
-     *
1572
-     * @uses GravityView_Edit_Entry::user_can_edit_field() Check caps
1573
-     * @access private
1574
-     * @param GF_Field[] $fields
1575
-     * @param array $configured_fields
1576
-     * @since  1.5
1577
-     * @return array $fields
1578
-     */
1579
-    private function filter_fields( $fields, $configured_fields ) {
1580
-
1581
-        if( empty( $fields ) || !is_array( $fields ) ) {
1582
-            return $fields;
1583
-        }
1584
-
1585
-        $edit_fields = array();
1586
-
1587
-        $field_type_blacklist = $this->loader->get_field_blacklist( $this->entry );
1588
-
1589
-        // First, remove blacklist or calculation fields
1590
-        foreach ( $fields as $key => $field ) {
1591
-
1592
-            // Remove the fields that have calculation properties and keep them to be used later
1593
-            // @since 1.16.2
1594
-            if( $field->has_calculation() ) {
1595
-                $this->fields_with_calculation[] = $field;
1596
-                // don't remove the calculation fields on form render.
1597
-            }
1598
-
1599
-            if( in_array( $field->type, $field_type_blacklist ) ) {
1600
-                unset( $fields[ $key ] );
1601
-            }
1602
-        }
1603
-
1604
-        // The Edit tab has not been configured, so we return all fields by default.
1605
-        if( empty( $configured_fields ) ) {
1606
-            return $fields;
1607
-        }
1608
-
1609
-        // The edit tab has been configured, so we loop through to configured settings
1610
-        foreach ( $configured_fields as $configured_field ) {
1611
-
1612
-	        /** @var GF_Field $field */
1613
-	        foreach ( $fields as $field ) {
1614
-
1615
-                if( intval( $configured_field['id'] ) === intval( $field->id ) && $this->user_can_edit_field( $configured_field, false ) ) {
1616
-                    $edit_fields[] = $this->merge_field_properties( $field, $configured_field );
1617
-                    break;
1618
-                }
1619
-
1620
-            }
1621
-
1622
-        }
1623
-
1624
-        return $edit_fields;
1625
-
1626
-    }
1627
-
1628
-    /**
1629
-     * Override GF Form field properties with the ones defined on the View
1630
-     * @param  GF_Field $field GF Form field object
1631
-     * @param  array $field_setting  GV field options
1632
-     * @since  1.5
1633
-     * @return array|GF_Field
1634
-     */
1635
-    private function merge_field_properties( $field, $field_setting ) {
1636
-
1637
-        $return_field = $field;
1638
-
1639
-        if( empty( $field_setting['show_label'] ) ) {
1640
-            $return_field->label = '';
1641
-        } elseif ( !empty( $field_setting['custom_label'] ) ) {
1642
-            $return_field->label = $field_setting['custom_label'];
1643
-        }
1644
-
1645
-        if( !empty( $field_setting['custom_class'] ) ) {
1646
-            $return_field->cssClass .= ' '. gravityview_sanitize_html_class( $field_setting['custom_class'] );
1647
-        }
1648
-
1649
-        /**
1650
-         * Normalize page numbers - avoid conflicts with page validation
1651
-         * @since 1.6
1652
-         */
1653
-        $return_field->pageNumber = 1;
1654
-
1655
-        return $return_field;
1656
-
1657
-    }
1658
-
1659
-    /**
1660
-     * Remove fields that shouldn't be visible based on the Gravity Forms adminOnly field property
1661
-     *
1662
-     * @since 1.9.1
1663
-     *
1664
-     * @param array|GF_Field[] $fields Gravity Forms form fields
1665
-     * @param array|null $edit_fields Fields for the Edit Entry tab configured in the View Configuration
1666
-     * @param array $form GF Form array
1667
-     * @param int $view_id View ID
1668
-     *
1669
-     * @return array Possibly modified form array
1670
-     */
1671
-    private function filter_admin_only_fields( $fields = array(), $edit_fields = null, $form = array(), $view_id = 0 ) {
1672
-
1673
-	    /**
1674
-         * @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
1675
-	     * If the Edit Entry tab is not configured, adminOnly fields will not be shown to non-administrators.
1676
-	     * If the Edit Entry tab *is* configured, adminOnly fields will be shown to non-administrators, using the configured GV permissions
1677
-	     * @since 1.9.1
1678
-	     * @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.
1679
-	     * @param array $form GF Form array
1680
-	     * @param int $view_id View ID
1681
-	     */
1682
-	    $use_gf_adminonly_setting = apply_filters( 'gravityview/edit_entry/use_gf_admin_only_setting', empty( $edit_fields ), $form, $view_id );
1683
-
1684
-	    if( $use_gf_adminonly_setting && false === GVCommon::has_cap( 'gravityforms_edit_entries', $this->entry['id'] ) ) {
1685
-            foreach( $fields as $k => $field ) {
1686
-                if( $field->adminOnly ) {
1687
-                    unset( $fields[ $k ] );
1688
-                }
1689
-            }
1690
-            return $fields;
1691
-        }
1692
-
1693
-	    foreach( $fields as &$field ) {
1694
-		    $field->adminOnly = false;
1695
-        }
1696
-
1697
-        return $fields;
1698
-    }
1699
-
1700
-    // --- Conditional Logic
1701
-
1702
-    /**
1703
-     * Conditional logic isn't designed to work with forms that already have content. When switching input values,
1704
-     * the dependent fields will be blank.
1705
-     *
1706
-     * Note: This is because GF populates a JavaScript variable with the input values. This is tough to filter at the input level;
1707
-     * via the `gform_field_value` filter; it requires lots of legwork. Doing it at the form level is easier.
1708
-     *
1709
-     * @since 1.17.4
1710
-     *
1711
-     * @param array $form Gravity Forms array object
1712
-     *
1713
-     * @return array $form, modified to fix conditional
1714
-     */
1715
-    function prefill_conditional_logic( $form ) {
1716
-
1717
-        if( ! GFFormDisplay::has_conditional_logic( $form ) ) {
1718
-            return $form;
1719
-        }
1720
-
1721
-        // Have Conditional Logic pre-fill fields as if the data were default values
1722
-        /** @var GF_Field $field */
1723
-        foreach ( $form['fields'] as &$field ) {
1724
-
1725
-            if( 'checkbox' === $field->type ) {
1726
-                foreach ( $field->get_entry_inputs() as $key => $input ) {
1727
-                    $input_id = $input['id'];
1728
-                    $choice = $field->choices[ $key ];
1729
-                    $value = rgar( $this->entry, $input_id );
1730
-                    $match = RGFormsModel::choice_value_match( $field, $choice, $value );
1731
-                    if( $match ) {
1732
-                        $field->choices[ $key ]['isSelected'] = true;
1733
-                    }
1734
-                }
1735
-            } else {
1736
-
1737
-                // We need to run through each field to set the default values
1738
-                foreach ( $this->entry as $field_id => $field_value ) {
1739
-
1740
-                    if( floatval( $field_id ) === floatval( $field->id ) ) {
1741
-
1742
-                        if( 'list' === $field->type ) {
1743
-                            $list_rows = maybe_unserialize( $field_value );
1744
-
1745
-                            $list_field_value = array();
1746
-                            foreach ( (array) $list_rows as $row ) {
1747
-                                foreach ( (array) $row as $column ) {
1748
-                                    $list_field_value[] = $column;
1749
-                                }
1750
-                            }
1751
-
1752
-                            $field->defaultValue = serialize( $list_field_value );
1753
-                        } else {
1754
-                            $field->defaultValue = $field_value;
1755
-                        }
1756
-                    }
1757
-                }
1758
-            }
1759
-        }
1760
-
1761
-        return $form;
1762
-    }
1763
-
1764
-    /**
1765
-     * Remove the conditional logic rules from the form button and the form fields, if needed.
1766
-     *
1767
-     * @todo Merge with caller method
1768
-     * @since 1.9
1769
-     *
1770
-     * @param array $form Gravity Forms form
1771
-     * @return array Modified form, if not using Conditional Logic
1772
-     */
1773
-    private function filter_conditional_logic( $form ) {
1774
-
1775
-        /**
1776
-         * @filter `gravityview/edit_entry/conditional_logic` Should the Edit Entry form use Gravity Forms conditional logic showing/hiding of fields?
1777
-         * @since 1.9
1778
-         * @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
1779
-         * @param array $form Gravity Forms form
1780
-         */
1781
-        $use_conditional_logic = apply_filters( 'gravityview/edit_entry/conditional_logic', true, $form );
1782
-
1783
-        if( $use_conditional_logic ) {
1784
-            return $form;
1785
-        }
1786
-
1787
-        foreach( $form['fields'] as &$field ) {
1788
-            /* @var GF_Field $field */
1789
-            $field->conditionalLogic = null;
1790
-        }
1791
-
1792
-        unset( $form['button']['conditionalLogic'] );
1793
-
1794
-        return $form;
1795
-
1796
-    }
1797
-
1798
-    /**
1799
-     * Disable the Gravity Forms conditional logic script and features on the Edit Entry screen
1800
-     *
1801
-     * @since 1.9
1802
-     *
1803
-     * @param $has_conditional_logic
1804
-     * @param $form
1805
-     * @return mixed
1806
-     */
1807
-    public function manage_conditional_logic( $has_conditional_logic, $form ) {
1808
-
1809
-        if( ! $this->is_edit_entry() ) {
1810
-            return $has_conditional_logic;
1811
-        }
1812
-
1813
-	    /** @see GravityView_Edit_Entry_Render::filter_conditional_logic for filter documentation */
1814
-        return apply_filters( 'gravityview/edit_entry/conditional_logic', $has_conditional_logic, $form );
1815
-    }
1816
-
1817
-
1818
-    // --- User checks and nonces
1819
-
1820
-    /**
1821
-     * Check if the user can edit the entry
1822
-     *
1823
-     * - Is the nonce valid?
1824
-     * - Does the user have the right caps for the entry
1825
-     * - Is the entry in the trash?
1826
-     *
1827
-     * @todo Move to GVCommon
1828
-     *
1829
-     * @param  boolean $echo Show error messages in the form?
1830
-     * @return boolean        True: can edit form. False: nope.
1831
-     */
1832
-    private function user_can_edit_entry( $echo = false ) {
1833
-
1834
-        $error = NULL;
1835
-
1836
-        /**
1837
-         *  1. Permalinks are turned off
1838
-         *  2. There are two entries embedded using oEmbed
1839
-         *  3. One of the entries has just been saved
1840
-         */
1841
-        if( !empty( $_POST['lid'] ) && !empty( $_GET['entry'] ) && ( $_POST['lid'] !== $_GET['entry'] ) ) {
1842
-
1843
-            $error = true;
1844
-
1845
-        }
1846
-
1847
-        if( !empty( $_GET['entry'] ) && (string)$this->entry['id'] !== $_GET['entry'] ) {
1848
-
1849
-            $error = true;
1850
-
1851
-        } elseif( ! $this->verify_nonce() ) {
1852
-
1853
-            /**
1854
-             * If the Entry is embedded, there may be two entries on the same page.
1855
-             * If that's the case, and one is being edited, the other should fail gracefully and not display an error.
1856
-             */
1857
-            if( GravityView_oEmbed::getInstance()->get_entry_id() ) {
1858
-                $error = true;
1859
-            } else {
1860
-                $error = __( 'The link to edit this entry is not valid; it may have expired.', 'gravityview');
1861
-            }
1862
-
1863
-        }
1864
-
1865
-        if( ! GravityView_Edit_Entry::check_user_cap_edit_entry( $this->entry ) ) {
1866
-            $error = __( 'You do not have permission to edit this entry.', 'gravityview');
1867
-        }
1868
-
1869
-        if( $this->entry['status'] === 'trash' ) {
1870
-            $error = __('You cannot edit the entry; it is in the trash.', 'gravityview' );
1871
-        }
1655
+		return $return_field;
1872 1656
 
1873
-        // No errors; everything's fine here!
1874
-        if( empty( $error ) ) {
1875
-            return true;
1876
-        }
1657
+	}
1877 1658
 
1878
-        if( $echo && $error !== true ) {
1659
+	/**
1660
+	 * Remove fields that shouldn't be visible based on the Gravity Forms adminOnly field property
1661
+	 *
1662
+	 * @since 1.9.1
1663
+	 *
1664
+	 * @param array|GF_Field[] $fields Gravity Forms form fields
1665
+	 * @param array|null $edit_fields Fields for the Edit Entry tab configured in the View Configuration
1666
+	 * @param array $form GF Form array
1667
+	 * @param int $view_id View ID
1668
+	 *
1669
+	 * @return array Possibly modified form array
1670
+	 */
1671
+	private function filter_admin_only_fields( $fields = array(), $edit_fields = null, $form = array(), $view_id = 0 ) {
1672
+
1673
+		/**
1674
+		 * @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
1675
+		 * If the Edit Entry tab is not configured, adminOnly fields will not be shown to non-administrators.
1676
+		 * If the Edit Entry tab *is* configured, adminOnly fields will be shown to non-administrators, using the configured GV permissions
1677
+		 * @since 1.9.1
1678
+		 * @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.
1679
+		 * @param array $form GF Form array
1680
+		 * @param int $view_id View ID
1681
+		 */
1682
+		$use_gf_adminonly_setting = apply_filters( 'gravityview/edit_entry/use_gf_admin_only_setting', empty( $edit_fields ), $form, $view_id );
1879 1683
 
1880
-	        $error = esc_html( $error );
1684
+		if( $use_gf_adminonly_setting && false === GVCommon::has_cap( 'gravityforms_edit_entries', $this->entry['id'] ) ) {
1685
+			foreach( $fields as $k => $field ) {
1686
+				if( $field->adminOnly ) {
1687
+					unset( $fields[ $k ] );
1688
+				}
1689
+			}
1690
+			return $fields;
1691
+		}
1881 1692
 
1882
-	        /**
1883
-	         * @since 1.9
1884
-	         */
1885
-	        if ( ! empty( $this->entry ) ) {
1886
-		        $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;" ) );
1887
-	        }
1693
+		foreach( $fields as &$field ) {
1694
+			$field->adminOnly = false;
1695
+		}
1888 1696
 
1889
-            echo GVCommon::generate_notice( wpautop( $error ), 'gv-error error');
1890
-        }
1697
+		return $fields;
1698
+	}
1891 1699
 
1892
-        do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_entry]' . $error );
1700
+	// --- Conditional Logic
1893 1701
 
1894
-        return false;
1895
-    }
1896
-
1897
-
1898
-    /**
1899
-     * Check whether a field is editable by the current user, and optionally display an error message
1900
-     * @uses  GravityView_Edit_Entry->check_user_cap_edit_field() Check user capabilities
1901
-     * @param  array  $field Field or field settings array
1902
-     * @param  boolean $echo  Whether to show error message telling user they aren't allowed
1903
-     * @return boolean         True: user can edit the current field; False: nope, they can't.
1904
-     */
1905
-    private function user_can_edit_field( $field, $echo = false ) {
1702
+	/**
1703
+	 * Conditional logic isn't designed to work with forms that already have content. When switching input values,
1704
+	 * the dependent fields will be blank.
1705
+	 *
1706
+	 * Note: This is because GF populates a JavaScript variable with the input values. This is tough to filter at the input level;
1707
+	 * via the `gform_field_value` filter; it requires lots of legwork. Doing it at the form level is easier.
1708
+	 *
1709
+	 * @since 1.17.4
1710
+	 *
1711
+	 * @param array $form Gravity Forms array object
1712
+	 *
1713
+	 * @return array $form, modified to fix conditional
1714
+	 */
1715
+	function prefill_conditional_logic( $form ) {
1906 1716
 
1907
-        $error = NULL;
1717
+		if( ! GFFormDisplay::has_conditional_logic( $form ) ) {
1718
+			return $form;
1719
+		}
1908 1720
 
1909
-        if( ! $this->check_user_cap_edit_field( $field ) ) {
1910
-            $error = __( 'You do not have permission to edit this field.', 'gravityview');
1911
-        }
1721
+		// Have Conditional Logic pre-fill fields as if the data were default values
1722
+		/** @var GF_Field $field */
1723
+		foreach ( $form['fields'] as &$field ) {
1724
+
1725
+			if( 'checkbox' === $field->type ) {
1726
+				foreach ( $field->get_entry_inputs() as $key => $input ) {
1727
+					$input_id = $input['id'];
1728
+					$choice = $field->choices[ $key ];
1729
+					$value = rgar( $this->entry, $input_id );
1730
+					$match = RGFormsModel::choice_value_match( $field, $choice, $value );
1731
+					if( $match ) {
1732
+						$field->choices[ $key ]['isSelected'] = true;
1733
+					}
1734
+				}
1735
+			} else {
1736
+
1737
+				// We need to run through each field to set the default values
1738
+				foreach ( $this->entry as $field_id => $field_value ) {
1739
+
1740
+					if( floatval( $field_id ) === floatval( $field->id ) ) {
1741
+
1742
+						if( 'list' === $field->type ) {
1743
+							$list_rows = maybe_unserialize( $field_value );
1744
+
1745
+							$list_field_value = array();
1746
+							foreach ( (array) $list_rows as $row ) {
1747
+								foreach ( (array) $row as $column ) {
1748
+									$list_field_value[] = $column;
1749
+								}
1750
+							}
1751
+
1752
+							$field->defaultValue = serialize( $list_field_value );
1753
+						} else {
1754
+							$field->defaultValue = $field_value;
1755
+						}
1756
+					}
1757
+				}
1758
+			}
1759
+		}
1912 1760
 
1913
-        // No errors; everything's fine here!
1914
-        if( empty( $error ) ) {
1915
-            return true;
1916
-        }
1761
+		return $form;
1762
+	}
1917 1763
 
1918
-        if( $echo ) {
1919
-            echo GVCommon::generate_notice( wpautop( esc_html( $error ) ), 'gv-error error');
1920
-        }
1921
-
1922
-        do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_field]' . $error );
1764
+	/**
1765
+	 * Remove the conditional logic rules from the form button and the form fields, if needed.
1766
+	 *
1767
+	 * @todo Merge with caller method
1768
+	 * @since 1.9
1769
+	 *
1770
+	 * @param array $form Gravity Forms form
1771
+	 * @return array Modified form, if not using Conditional Logic
1772
+	 */
1773
+	private function filter_conditional_logic( $form ) {
1923 1774
 
1924
-        return false;
1775
+		/**
1776
+		 * @filter `gravityview/edit_entry/conditional_logic` Should the Edit Entry form use Gravity Forms conditional logic showing/hiding of fields?
1777
+		 * @since 1.9
1778
+		 * @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
1779
+		 * @param array $form Gravity Forms form
1780
+		 */
1781
+		$use_conditional_logic = apply_filters( 'gravityview/edit_entry/conditional_logic', true, $form );
1925 1782
 
1926
-    }
1783
+		if( $use_conditional_logic ) {
1784
+			return $form;
1785
+		}
1927 1786
 
1787
+		foreach( $form['fields'] as &$field ) {
1788
+			/* @var GF_Field $field */
1789
+			$field->conditionalLogic = null;
1790
+		}
1928 1791
 
1929
-    /**
1930
-     * checks if user has permissions to edit a specific field
1931
-     *
1932
-     * Needs to be used combined with GravityView_Edit_Entry::user_can_edit_field for maximum security!!
1933
-     *
1934
-     * @param  [type] $field [description]
1935
-     * @return bool
1936
-     */
1937
-    private function check_user_cap_edit_field( $field ) {
1792
+		unset( $form['button']['conditionalLogic'] );
1938 1793
 
1939
-        // If they can edit any entries (as defined in Gravity Forms), we're good.
1940
-        if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ) ) ) {
1941
-            return true;
1942
-        }
1794
+		return $form;
1943 1795
 
1944
-        $field_cap = isset( $field['allow_edit_cap'] ) ? $field['allow_edit_cap'] : false;
1796
+	}
1945 1797
 
1946
-        // If the field has custom editing capaibilities set, check those
1947
-        if( $field_cap ) {
1948
-            return GVCommon::has_cap( $field['allow_edit_cap'] );
1949
-        }
1950
-
1951
-        return false;
1952
-    }
1798
+	/**
1799
+	 * Disable the Gravity Forms conditional logic script and features on the Edit Entry screen
1800
+	 *
1801
+	 * @since 1.9
1802
+	 *
1803
+	 * @param $has_conditional_logic
1804
+	 * @param $form
1805
+	 * @return mixed
1806
+	 */
1807
+	public function manage_conditional_logic( $has_conditional_logic, $form ) {
1953 1808
 
1809
+		if( ! $this->is_edit_entry() ) {
1810
+			return $has_conditional_logic;
1811
+		}
1954 1812
 
1955
-    /**
1956
-     * Is the current nonce valid for editing the entry?
1957
-     * @return boolean
1958
-     */
1959
-    public function verify_nonce() {
1813
+		/** @see GravityView_Edit_Entry_Render::filter_conditional_logic for filter documentation */
1814
+		return apply_filters( 'gravityview/edit_entry/conditional_logic', $has_conditional_logic, $form );
1815
+	}
1960 1816
 
1961
-        // Verify form submitted for editing single
1962
-        if( $this->is_edit_entry_submission() ) {
1963
-            $valid = wp_verify_nonce( $_POST[ self::$nonce_field ], self::$nonce_field );
1964
-        }
1965 1817
 
1966
-        // Verify
1967
-        else if( ! $this->is_edit_entry() ) {
1968
-            $valid = false;
1969
-        }
1818
+	// --- User checks and nonces
1970 1819
 
1971
-        else {
1972
-            $valid = wp_verify_nonce( $_GET['edit'], self::$nonce_key );
1973
-        }
1820
+	/**
1821
+	 * Check if the user can edit the entry
1822
+	 *
1823
+	 * - Is the nonce valid?
1824
+	 * - Does the user have the right caps for the entry
1825
+	 * - Is the entry in the trash?
1826
+	 *
1827
+	 * @todo Move to GVCommon
1828
+	 *
1829
+	 * @param  boolean $echo Show error messages in the form?
1830
+	 * @return boolean        True: can edit form. False: nope.
1831
+	 */
1832
+	private function user_can_edit_entry( $echo = false ) {
1974 1833
 
1975
-        /**
1976
-         * @filter `gravityview/edit_entry/verify_nonce` Override Edit Entry nonce validation. Return true to declare nonce valid.
1977
-         * @since 1.13
1978
-         * @param int|boolean $valid False if invalid; 1 or 2 when nonce was generated
1979
-         * @param string $nonce_field Key used when validating submissions. Default: is_gv_edit_entry
1980
-         */
1981
-        $valid = apply_filters( 'gravityview/edit_entry/verify_nonce', $valid, self::$nonce_field );
1834
+		$error = NULL;
1982 1835
 
1983
-        return $valid;
1984
-    }
1836
+		/**
1837
+		 *  1. Permalinks are turned off
1838
+		 *  2. There are two entries embedded using oEmbed
1839
+		 *  3. One of the entries has just been saved
1840
+		 */
1841
+		if( !empty( $_POST['lid'] ) && !empty( $_GET['entry'] ) && ( $_POST['lid'] !== $_GET['entry'] ) ) {
1842
+
1843
+			$error = true;
1844
+
1845
+		}
1846
+
1847
+		if( !empty( $_GET['entry'] ) && (string)$this->entry['id'] !== $_GET['entry'] ) {
1848
+
1849
+			$error = true;
1850
+
1851
+		} elseif( ! $this->verify_nonce() ) {
1852
+
1853
+			/**
1854
+			 * If the Entry is embedded, there may be two entries on the same page.
1855
+			 * If that's the case, and one is being edited, the other should fail gracefully and not display an error.
1856
+			 */
1857
+			if( GravityView_oEmbed::getInstance()->get_entry_id() ) {
1858
+				$error = true;
1859
+			} else {
1860
+				$error = __( 'The link to edit this entry is not valid; it may have expired.', 'gravityview');
1861
+			}
1862
+
1863
+		}
1864
+
1865
+		if( ! GravityView_Edit_Entry::check_user_cap_edit_entry( $this->entry ) ) {
1866
+			$error = __( 'You do not have permission to edit this entry.', 'gravityview');
1867
+		}
1868
+
1869
+		if( $this->entry['status'] === 'trash' ) {
1870
+			$error = __('You cannot edit the entry; it is in the trash.', 'gravityview' );
1871
+		}
1872
+
1873
+		// No errors; everything's fine here!
1874
+		if( empty( $error ) ) {
1875
+			return true;
1876
+		}
1877
+
1878
+		if( $echo && $error !== true ) {
1879
+
1880
+			$error = esc_html( $error );
1881
+
1882
+			/**
1883
+			 * @since 1.9
1884
+			 */
1885
+			if ( ! empty( $this->entry ) ) {
1886
+				$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;" ) );
1887
+			}
1888
+
1889
+			echo GVCommon::generate_notice( wpautop( $error ), 'gv-error error');
1890
+		}
1891
+
1892
+		do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_entry]' . $error );
1893
+
1894
+		return false;
1895
+	}
1896
+
1897
+
1898
+	/**
1899
+	 * Check whether a field is editable by the current user, and optionally display an error message
1900
+	 * @uses  GravityView_Edit_Entry->check_user_cap_edit_field() Check user capabilities
1901
+	 * @param  array  $field Field or field settings array
1902
+	 * @param  boolean $echo  Whether to show error message telling user they aren't allowed
1903
+	 * @return boolean         True: user can edit the current field; False: nope, they can't.
1904
+	 */
1905
+	private function user_can_edit_field( $field, $echo = false ) {
1906
+
1907
+		$error = NULL;
1908
+
1909
+		if( ! $this->check_user_cap_edit_field( $field ) ) {
1910
+			$error = __( 'You do not have permission to edit this field.', 'gravityview');
1911
+		}
1912
+
1913
+		// No errors; everything's fine here!
1914
+		if( empty( $error ) ) {
1915
+			return true;
1916
+		}
1917
+
1918
+		if( $echo ) {
1919
+			echo GVCommon::generate_notice( wpautop( esc_html( $error ) ), 'gv-error error');
1920
+		}
1921
+
1922
+		do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_field]' . $error );
1923
+
1924
+		return false;
1925
+
1926
+	}
1927
+
1928
+
1929
+	/**
1930
+	 * checks if user has permissions to edit a specific field
1931
+	 *
1932
+	 * Needs to be used combined with GravityView_Edit_Entry::user_can_edit_field for maximum security!!
1933
+	 *
1934
+	 * @param  [type] $field [description]
1935
+	 * @return bool
1936
+	 */
1937
+	private function check_user_cap_edit_field( $field ) {
1938
+
1939
+		// If they can edit any entries (as defined in Gravity Forms), we're good.
1940
+		if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ) ) ) {
1941
+			return true;
1942
+		}
1943
+
1944
+		$field_cap = isset( $field['allow_edit_cap'] ) ? $field['allow_edit_cap'] : false;
1945
+
1946
+		// If the field has custom editing capaibilities set, check those
1947
+		if( $field_cap ) {
1948
+			return GVCommon::has_cap( $field['allow_edit_cap'] );
1949
+		}
1950
+
1951
+		return false;
1952
+	}
1953
+
1954
+
1955
+	/**
1956
+	 * Is the current nonce valid for editing the entry?
1957
+	 * @return boolean
1958
+	 */
1959
+	public function verify_nonce() {
1960
+
1961
+		// Verify form submitted for editing single
1962
+		if( $this->is_edit_entry_submission() ) {
1963
+			$valid = wp_verify_nonce( $_POST[ self::$nonce_field ], self::$nonce_field );
1964
+		}
1965
+
1966
+		// Verify
1967
+		else if( ! $this->is_edit_entry() ) {
1968
+			$valid = false;
1969
+		}
1970
+
1971
+		else {
1972
+			$valid = wp_verify_nonce( $_GET['edit'], self::$nonce_key );
1973
+		}
1974
+
1975
+		/**
1976
+		 * @filter `gravityview/edit_entry/verify_nonce` Override Edit Entry nonce validation. Return true to declare nonce valid.
1977
+		 * @since 1.13
1978
+		 * @param int|boolean $valid False if invalid; 1 or 2 when nonce was generated
1979
+		 * @param string $nonce_field Key used when validating submissions. Default: is_gv_edit_entry
1980
+		 */
1981
+		$valid = apply_filters( 'gravityview/edit_entry/verify_nonce', $valid, self::$nonce_field );
1982
+
1983
+		return $valid;
1984
+	}
1985 1985
 
1986 1986
 
1987 1987
 
Please login to merge, or discard this patch.