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