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