Completed
Pull Request — develop (#630)
by
unknown
25:42
created
includes/fields/class-gravityview-fields.php 2 patches
Doc Comments   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 	/**
78 78
 	 * Alias for get_instance()
79 79
 	 *
80
-	 * @param $field_name
80
+	 * @param string $field_name
81 81
 	 *
82 82
 	 * @return GravityView_Field|false
83 83
 	 */
@@ -88,7 +88,6 @@  discard block
 block discarded – undo
88 88
 	/**
89 89
 	 * Alias for get_instance()
90 90
 	 *
91
-	 * @param string|GF_Field $field_name Gravity Forms field class or the class name type
92 91
 	 *
93 92
 	 * @return GravityView_Field
94 93
 	 */
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -42,8 +42,8 @@  discard block
 block discarded – undo
42 42
 	 * @return GravityView_Field | bool
43 43
 	 */
44 44
 	public static function create( $properties ) {
45
-		$type = isset( $properties['type'] ) ? $properties['type'] : '';
46
-		$type = empty( $properties['inputType'] ) ? $type : $properties['inputType'];
45
+		$type = isset( $properties[ 'type' ] ) ? $properties[ 'type' ] : '';
46
+		$type = empty( $properties[ 'inputType' ] ) ? $type : $properties[ 'inputType' ];
47 47
 		if ( empty( $type ) || ! isset( self::$_fields[ $type ] ) ) {
48 48
 			return new GravityView_Field( $properties );
49 49
 		}
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 	 * @return bool True: yes, it exists; False: nope
63 63
 	 */
64 64
 	public static function exists( $field_name ) {
65
-		return isset( self::$_fields["{$field_name}"] );
65
+		return isset( self::$_fields[ "{$field_name}" ] );
66 66
 	}
67 67
 
68 68
 	/**
@@ -96,8 +96,8 @@  discard block
 block discarded – undo
96 96
 
97 97
 		$field_type = is_a( $gf_field, 'GF_Field' ) ? get_class( $gf_field ) : $gf_field;
98 98
 
99
-		foreach( self::$_fields as $field ) {
100
-			if( $field_type === $field->_gf_field_class_name ) {
99
+		foreach ( self::$_fields as $field ) {
100
+			if ( $field_type === $field->_gf_field_class_name ) {
101 101
 				return $field;
102 102
 			}
103 103
 		}
@@ -116,10 +116,10 @@  discard block
 block discarded – undo
116 116
 	 */
117 117
 	public static function get_all( $group = '' ) {
118 118
 
119
-		if( '' !== $group ) {
119
+		if ( '' !== $group ) {
120 120
 			$return_fields = self::$_fields;
121 121
 			foreach ( $return_fields as $key => $field ) {
122
-				if( $group !== $field->group ) {
122
+				if ( $group !== $field->group ) {
123 123
 					unset( $return_fields[ $key ] );
124 124
 				}
125 125
 			}
Please login to merge, or discard this patch.
includes/extensions/edit-entry/class-edit-entry-render.php 3 patches
Spacing   +195 added lines, -195 removed lines patch added patch discarded remove patch
@@ -101,16 +101,16 @@  discard block
 block discarded – undo
101 101
     function load() {
102 102
 
103 103
         /** @define "GRAVITYVIEW_DIR" "../../../" */
104
-        include_once( GRAVITYVIEW_DIR .'includes/class-admin-approve-entries.php' );
104
+        include_once( GRAVITYVIEW_DIR . 'includes/class-admin-approve-entries.php' );
105 105
 
106 106
         // Don't display an embedded form when editing an entry
107 107
         add_action( 'wp_head', array( $this, 'prevent_render_form' ) );
108 108
         add_action( 'wp_footer', array( $this, 'prevent_render_form' ) );
109 109
 
110 110
         // Stop Gravity Forms processing what is ours!
111
-        add_filter( 'wp', array( $this, 'prevent_maybe_process_form'), 8 );
111
+        add_filter( 'wp', array( $this, 'prevent_maybe_process_form' ), 8 );
112 112
 
113
-        add_filter( 'gravityview_is_edit_entry', array( $this, 'is_edit_entry') );
113
+        add_filter( 'gravityview_is_edit_entry', array( $this, 'is_edit_entry' ) );
114 114
 
115 115
         add_action( 'gravityview_edit_entry', array( $this, 'init' ) );
116 116
 
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
         add_filter( 'gform_plupload_settings', array( $this, 'modify_fileupload_settings' ), 10, 3 );
122 122
 
123 123
         // Add fields expected by GFFormDisplay::validate()
124
-        add_filter( 'gform_pre_validation', array( $this, 'gform_pre_validation') );
124
+        add_filter( 'gform_pre_validation', array( $this, 'gform_pre_validation' ) );
125 125
 
126 126
     }
127 127
 
@@ -136,8 +136,8 @@  discard block
 block discarded – undo
136 136
      * @return void
137 137
      */
138 138
     function prevent_render_form() {
139
-        if( $this->is_edit_entry() ) {
140
-            if( 'wp_head' === current_filter() ) {
139
+        if ( $this->is_edit_entry() ) {
140
+            if ( 'wp_head' === current_filter() ) {
141 141
                 add_filter( 'gform_shortcode_form', '__return_empty_string' );
142 142
             } else {
143 143
                 remove_filter( 'gform_shortcode_form', '__return_empty_string' );
@@ -152,10 +152,10 @@  discard block
 block discarded – undo
152 152
      */
153 153
     function prevent_maybe_process_form() {
154 154
 
155
-        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[prevent_maybe_process_form] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) );
155
+        do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[prevent_maybe_process_form] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) );
156 156
 
157
-        if( $this->is_edit_entry_submission() && $this->verify_nonce() ) {
158
-            remove_action( 'wp',  array( 'RGForms', 'maybe_process_form'), 9 );
157
+        if ( $this->is_edit_entry_submission() && $this->verify_nonce() ) {
158
+            remove_action( 'wp', array( 'RGForms', 'maybe_process_form' ), 9 );
159 159
         }
160 160
     }
161 161
 
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
 
168 168
         $gf_page = ( 'entry' === RGForms::get( 'view' ) );
169 169
 
170
-        return ( $gf_page && isset( $_GET['edit'] ) || RGForms::post( 'action' ) === 'update' );
170
+        return ( $gf_page && isset( $_GET[ 'edit' ] ) || RGForms::post( 'action' ) === 'update' );
171 171
     }
172 172
 
173 173
 	/**
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
 	 * @return boolean
177 177
 	 */
178 178
 	public function is_edit_entry_submission() {
179
-		return !empty( $_POST[ self::$nonce_field ] );
179
+		return ! empty( $_POST[ self::$nonce_field ] );
180 180
 	}
181 181
 
182 182
     /**
@@ -187,13 +187,13 @@  discard block
 block discarded – undo
187 187
 
188 188
 
189 189
         $entries = $gravityview_view->getEntries();
190
-        $this->entry = $entries[0];
190
+        $this->entry = $entries[ 0 ];
191 191
 
192 192
         $this->form = $gravityview_view->getForm();
193 193
         $this->form_id = $gravityview_view->getFormId();
194 194
         $this->view_id = $gravityview_view->getViewId();
195 195
 
196
-        self::$nonce_key = GravityView_Edit_Entry::get_nonce_key( $this->view_id, $this->form_id, $this->entry['id'] );
196
+        self::$nonce_key = GravityView_Edit_Entry::get_nonce_key( $this->view_id, $this->form_id, $this->entry[ 'id' ] );
197 197
     }
198 198
 
199 199
 
@@ -213,12 +213,12 @@  discard block
 block discarded – undo
213 213
         $this->setup_vars();
214 214
 
215 215
         // Multiple Views embedded, don't proceed if nonce fails
216
-        if( $gv_data->has_multiple_views() && ! wp_verify_nonce( $_GET['edit'], self::$nonce_key ) ) {
216
+        if ( $gv_data->has_multiple_views() && ! wp_verify_nonce( $_GET[ 'edit' ], self::$nonce_key ) ) {
217 217
             return;
218 218
         }
219 219
 
220 220
         // Sorry, you're not allowed here.
221
-        if( false === $this->user_can_edit_entry( true ) ) {
221
+        if ( false === $this->user_can_edit_entry( true ) ) {
222 222
             return;
223 223
         }
224 224
 
@@ -238,9 +238,9 @@  discard block
 block discarded – undo
238 238
     function print_scripts() {
239 239
         $gravityview_view = GravityView_View::getInstance();
240 240
 
241
-        wp_register_script( 'gform_gravityforms', GFCommon::get_base_url().'/js/gravityforms.js', array( 'jquery', 'gform_json', 'gform_placeholder', 'sack', 'plupload-all', 'gravityview-fe-view' ) );
241
+        wp_register_script( 'gform_gravityforms', GFCommon::get_base_url() . '/js/gravityforms.js', array( 'jquery', 'gform_json', 'gform_placeholder', 'sack', 'plupload-all', 'gravityview-fe-view' ) );
242 242
 
243
-        GFFormDisplay::enqueue_form_scripts($gravityview_view->getForm(), false);
243
+        GFFormDisplay::enqueue_form_scripts( $gravityview_view->getForm(), false );
244 244
 
245 245
         // Sack is required for images
246 246
         wp_print_scripts( array( 'sack', 'gform_gravityforms' ) );
@@ -252,32 +252,32 @@  discard block
 block discarded – undo
252 252
      */
253 253
     function process_save() {
254 254
 
255
-        if( empty( $_POST ) ) {
255
+        if ( empty( $_POST ) ) {
256 256
             return;
257 257
         }
258 258
 
259 259
         // Make sure the entry, view, and form IDs are all correct
260 260
         $valid = $this->verify_nonce();
261 261
 
262
-        if( !$valid ) {
263
-            do_action('gravityview_log_error', __METHOD__ . ' Nonce validation failed.' );
262
+        if ( ! $valid ) {
263
+            do_action( 'gravityview_log_error', __METHOD__ . ' Nonce validation failed.' );
264 264
             return;
265 265
         }
266 266
 
267
-        if( $this->entry['id'] !== $_POST['lid'] ) {
268
-            do_action('gravityview_log_error', __METHOD__ . ' Entry ID did not match posted entry ID.' );
267
+        if ( $this->entry[ 'id' ] !== $_POST[ 'lid' ] ) {
268
+            do_action( 'gravityview_log_error', __METHOD__ . ' Entry ID did not match posted entry ID.' );
269 269
             return;
270 270
         }
271 271
 
272
-        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) );
272
+        do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[process_save] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) );
273 273
 
274 274
         $this->process_save_process_files( $this->form_id );
275 275
 
276 276
         $this->validate();
277 277
 
278
-        if( $this->is_valid ) {
278
+        if ( $this->is_valid ) {
279 279
 
280
-            do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] Submission is valid.' );
280
+            do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[process_save] Submission is valid.' );
281 281
 
282 282
             /**
283 283
              * @hack This step is needed to unset the adminOnly from form fields
@@ -287,12 +287,12 @@  discard block
 block discarded – undo
287 287
             /**
288 288
              * @hack to avoid the capability validation of the method save_lead for GF 1.9+
289 289
              */
290
-            unset( $_GET['page'] );
290
+            unset( $_GET[ 'page' ] );
291 291
 
292 292
             GFFormsModel::save_lead( $form, $this->entry );
293 293
 
294 294
             // If there's a post associated with the entry, process post fields
295
-            if( !empty( $this->entry['post_id'] ) ) {
295
+            if ( ! empty( $this->entry[ 'post_id' ] ) ) {
296 296
                 $this->maybe_update_post_fields( $form );
297 297
             }
298 298
 
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
              * @param array $form Gravity Forms form array
305 305
              * @param string $entry_id Numeric ID of the entry that was updated
306 306
              */
307
-            do_action( 'gravityview/edit_entry/after_update', $this->form, $this->entry['id'] );
307
+            do_action( 'gravityview/edit_entry/after_update', $this->form, $this->entry[ 'id' ] );
308 308
         }
309 309
 
310 310
     } // process_save
@@ -338,11 +338,11 @@  discard block
 block discarded – undo
338 338
      * @return mixed
339 339
      */
340 340
     public function modify_fileupload_settings( $plupload_init, $form_id, $instance ) {
341
-        if( ! $this->is_edit_entry() ) {
341
+        if ( ! $this->is_edit_entry() ) {
342 342
             return $plupload_init;
343 343
         }
344 344
 
345
-        $plupload_init['gf_vars']['max_files'] = 0;
345
+        $plupload_init[ 'gf_vars' ][ 'max_files' ] = 0;
346 346
 
347 347
         return $plupload_init;
348 348
     }
@@ -356,15 +356,15 @@  discard block
 block discarded – undo
356 356
         $form = $this->form;
357 357
 
358 358
         // add the fields with calculation properties so they could be recalculated
359
-        $form['fields'] = array_merge( $form['fields'], $this->fields_with_calculation );
359
+        $form[ 'fields' ] = array_merge( $form[ 'fields' ], $this->fields_with_calculation );
360 360
 
361
-        foreach( $form['fields'] as &$field ) {
361
+        foreach ( $form[ 'fields' ] as &$field ) {
362 362
 
363 363
             $field->adminOnly = false;
364 364
 
365
-            if( isset( $field->inputs ) && is_array( $field->inputs ) ) {
366
-                foreach( $field->inputs as $key => $input ) {
367
-                    $field->inputs[ $key ][ 'id' ] = (string)$input['id'];
365
+            if ( isset( $field->inputs ) && is_array( $field->inputs ) ) {
366
+                foreach ( $field->inputs as $key => $input ) {
367
+                    $field->inputs[ $key ][ 'id' ] = (string)$input[ 'id' ];
368 368
                 }
369 369
             }
370 370
         }
@@ -382,11 +382,11 @@  discard block
 block discarded – undo
382 382
      */
383 383
     function maybe_update_post_fields( $form ) {
384 384
 
385
-        $post_id = $this->entry['post_id'];
385
+        $post_id = $this->entry[ 'post_id' ];
386 386
 
387 387
         // Security check
388
-        if( false === GVCommon::has_cap( 'edit_post', $post_id ) ) {
389
-            do_action( 'gravityview_log_error', 'The current user does not have the ability to edit Post #'.$post_id );
388
+        if ( false === GVCommon::has_cap( 'edit_post', $post_id ) ) {
389
+            do_action( 'gravityview_log_error', 'The current user does not have the ability to edit Post #' . $post_id );
390 390
             return;
391 391
         }
392 392
 
@@ -400,11 +400,11 @@  discard block
 block discarded – undo
400 400
 
401 401
             $field = RGFormsModel::get_field( $form, $field_id );
402 402
 
403
-            if( class_exists('GF_Fields') ) {
403
+            if ( class_exists( 'GF_Fields' ) ) {
404 404
                 $field = GF_Fields::create( $field );
405 405
             }
406 406
 
407
-            if( GFCommon::is_post_field( $field ) ) {
407
+            if ( GFCommon::is_post_field( $field ) ) {
408 408
 
409 409
                 // Get the value of the field, including $_POSTed value
410 410
                 $value = RGFormsModel::get_field_value( $field );
@@ -412,7 +412,7 @@  discard block
 block discarded – undo
412 412
                # var_dump( $this->entry );
413 413
               #  die();
414 414
 
415
-                switch( $field->type ) {
415
+                switch ( $field->type ) {
416 416
 
417 417
                     case 'post_title':
418 418
                     case 'post_content':
@@ -435,14 +435,14 @@  discard block
 block discarded – undo
435 435
                         wp_set_post_categories( $post_id, $categories, false );
436 436
 
437 437
                         // if post_category is type checkbox, then value is an array of inputs
438
-                        if( isset( $value[ strval( $field_id ) ] ) ) {
439
-                            foreach( $value as $input_id => $val ) {
438
+                        if ( isset( $value[ strval( $field_id ) ] ) ) {
439
+                            foreach ( $value as $input_id => $val ) {
440 440
                                 $input_name = 'input_' . str_replace( '.', '_', $input_id );
441
-                                $this->entry[ strval( $input_id ) ] = RGFormsModel::prepare_value( $form, $field, $val, $input_name, $this->entry['id'] );
441
+                                $this->entry[ strval( $input_id ) ] = RGFormsModel::prepare_value( $form, $field, $val, $input_name, $this->entry[ 'id' ] );
442 442
                             }
443 443
                         } else {
444 444
                             $input_name = 'input_' . str_replace( '.', '_', $field_id );
445
-                            $this->entry[ strval( $field_id ) ] = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $this->entry['id'] );
445
+                            $this->entry[ strval( $field_id ) ] = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $this->entry[ 'id' ] );
446 446
                         }
447 447
 
448 448
                         break;
@@ -452,12 +452,12 @@  discard block
 block discarded – undo
452 452
                         $custom_field_name = $field->postCustomFieldName;
453 453
 
454 454
                         // Only certain custom field types are supported
455
-                        switch( $input_type ) {
455
+                        switch ( $input_type ) {
456 456
                             case 'fileupload':
457 457
                             /** @noinspection PhpMissingBreakStatementInspection */
458 458
                             case 'list':
459
-                                if( ! is_string( $value ) ) {
460
-                                    $value = function_exists('wp_json_encode') ? wp_json_encode( $value ) : json_encode( $value );
459
+                                if ( ! is_string( $value ) ) {
460
+                                    $value = function_exists( 'wp_json_encode' ) ? wp_json_encode( $value ) : json_encode( $value );
461 461
                                 }
462 462
                                 var_dump( $value );
463 463
                             // break; left intentionally out
@@ -475,12 +475,12 @@  discard block
 block discarded – undo
475 475
                 }
476 476
 
477 477
                 //ignore fields that have not changed
478
-                if ( $value === rgget( (string) $field_id, $this->entry ) ) {
478
+                if ( $value === rgget( (string)$field_id, $this->entry ) ) {
479 479
                     continue;
480 480
                 }
481 481
 
482 482
                 // update entry
483
-                if( 'post_category' !== $field->type ) {
483
+                if ( 'post_category' !== $field->type ) {
484 484
                     $this->entry[ strval( $field_id ) ] = $value;
485 485
                 }
486 486
 
@@ -490,25 +490,25 @@  discard block
 block discarded – undo
490 490
 
491 491
         }
492 492
 
493
-        if( $update_entry ) {
493
+        if ( $update_entry ) {
494 494
 
495 495
             $return_entry = GFAPI::update_entry( $this->entry );
496 496
 
497
-            if( is_wp_error( $return_entry ) ) {
497
+            if ( is_wp_error( $return_entry ) ) {
498 498
                 do_action( 'gravityview_log_error', 'Updating the entry post fields failed', $return_entry );
499 499
             } else {
500
-                do_action( 'gravityview_log_debug', 'Updating the entry post fields for post #'.$post_id.' succeeded' );
500
+                do_action( 'gravityview_log_debug', 'Updating the entry post fields for post #' . $post_id . ' succeeded' );
501 501
             }
502 502
 
503 503
         }
504 504
 
505 505
         $return_post = wp_update_post( $updated_post, true );
506 506
 
507
-        if( is_wp_error( $return_post ) ) {
507
+        if ( is_wp_error( $return_post ) ) {
508 508
             $return_post->add_data( $updated_post, '$updated_post' );
509 509
             do_action( 'gravityview_log_error', 'Updating the post content failed', $return_post );
510 510
         } else {
511
-            do_action( 'gravityview_log_debug', 'Updating the post content for post #'.$post_id.' succeeded', $updated_post );
511
+            do_action( 'gravityview_log_debug', 'Updating the post content for post #' . $post_id . ' succeeded', $updated_post );
512 512
         }
513 513
 
514 514
     }
@@ -524,18 +524,18 @@  discard block
 block discarded – undo
524 524
      */
525 525
     function after_update() {
526 526
 
527
-        do_action( 'gform_after_update_entry', $this->form, $this->entry['id'] );
528
-        do_action( "gform_after_update_entry_{$this->form['id']}", $this->form, $this->entry['id'] );
527
+        do_action( 'gform_after_update_entry', $this->form, $this->entry[ 'id' ] );
528
+        do_action( "gform_after_update_entry_{$this->form[ 'id' ]}", $this->form, $this->entry[ 'id' ] );
529 529
 
530 530
         // Re-define the entry now that we've updated it.
531
-        $entry = RGFormsModel::get_lead( $this->entry['id'] );
531
+        $entry = RGFormsModel::get_lead( $this->entry[ 'id' ] );
532 532
 
533 533
         $entry = GFFormsModel::set_entry_meta( $entry, $this->form );
534 534
 
535 535
         // We need to clear the cache because Gravity Forms caches the field values, which
536 536
         // we have just updated.
537
-        foreach ($this->form['fields'] as $key => $field) {
538
-            GFFormsModel::refresh_lead_field_value( $entry['id'], $field->id );
537
+        foreach ( $this->form[ 'fields' ] as $key => $field ) {
538
+            GFFormsModel::refresh_lead_field_value( $entry[ 'id' ], $field->id );
539 539
         }
540 540
 
541 541
         $this->entry = $entry;
@@ -553,7 +553,7 @@  discard block
 block discarded – undo
553 553
 
554 554
         <div class="gv-edit-entry-wrapper"><?php
555 555
 
556
-            $javascript = gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/inline-javascript.php', $this );
556
+            $javascript = gravityview_ob_include( GravityView_Edit_Entry::$file . '/partials/inline-javascript.php', $this );
557 557
 
558 558
             /**
559 559
              * Fixes weird wpautop() issue
@@ -569,7 +569,7 @@  discard block
 block discarded – undo
569 569
                      * @param string $edit_entry_title Modify the "Edit Entry" title
570 570
                      * @param GravityView_Edit_Entry_Render $this This object
571 571
                      */
572
-                    $edit_entry_title = apply_filters('gravityview_edit_entry_title', __('Edit Entry', 'gravityview'), $this );
572
+                    $edit_entry_title = apply_filters( 'gravityview_edit_entry_title', __( 'Edit Entry', 'gravityview' ), $this );
573 573
 
574 574
                     echo esc_attr( $edit_entry_title );
575 575
             ?></span>
@@ -609,20 +609,20 @@  discard block
 block discarded – undo
609 609
      */
610 610
     private function maybe_print_message() {
611 611
 
612
-        if( rgpost('action') === 'update' ) {
612
+        if ( rgpost( 'action' ) === 'update' ) {
613 613
 
614 614
             $back_link = esc_url( remove_query_arg( array( 'page', 'view', 'edit' ) ) );
615 615
 
616
-            if( ! $this->is_valid ){
616
+            if ( ! $this->is_valid ) {
617 617
 
618 618
                 // Keeping this compatible with Gravity Forms.
619
-                $validation_message = "<div class='validation_error'>" . __('There was a problem with your submission.', 'gravityview') . " " . __('Errors have been highlighted below.', 'gravityview') . "</div>";
620
-                $message = apply_filters("gform_validation_message_{$this->form['id']}", apply_filters("gform_validation_message", $validation_message, $this->form), $this->form);
619
+                $validation_message = "<div class='validation_error'>" . __( 'There was a problem with your submission.', 'gravityview' ) . " " . __( 'Errors have been highlighted below.', 'gravityview' ) . "</div>";
620
+                $message = apply_filters( "gform_validation_message_{$this->form[ 'id' ]}", apply_filters( "gform_validation_message", $validation_message, $this->form ), $this->form );
621 621
 
622
-                echo GVCommon::generate_notice( $message , 'gv-error' );
622
+                echo GVCommon::generate_notice( $message, 'gv-error' );
623 623
 
624 624
             } else {
625
-                $entry_updated_message = sprintf( esc_attr__('Entry Updated. %sReturn to Entry%s', 'gravityview'), '<a href="'. $back_link .'">', '</a>' );
625
+                $entry_updated_message = sprintf( esc_attr__( 'Entry Updated. %sReturn to Entry%s', 'gravityview' ), '<a href="' . $back_link . '">', '</a>' );
626 626
 
627 627
                 /**
628 628
                  * @filter `gravityview/edit_entry/success` Modify the edit entry success message (including the anchor link)
@@ -632,7 +632,7 @@  discard block
 block discarded – undo
632 632
                  * @param array $entry Gravity Forms entry array
633 633
                  * @param string $back_link URL to return to the original entry. @since 1.6
634 634
                  */
635
-                $message = apply_filters( 'gravityview/edit_entry/success', $entry_updated_message , $this->view_id, $this->entry, $back_link );
635
+                $message = apply_filters( 'gravityview/edit_entry/success', $entry_updated_message, $this->view_id, $this->entry, $back_link );
636 636
 
637 637
                 echo GVCommon::generate_notice( $message );
638 638
             }
@@ -653,15 +653,15 @@  discard block
 block discarded – undo
653 653
      */
654 654
     private function render_edit_form() {
655 655
 
656
-        add_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields'), 5000, 3 );
657
-        add_filter( 'gform_submit_button', array( $this, 'render_form_buttons') );
656
+        add_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields' ), 5000, 3 );
657
+        add_filter( 'gform_submit_button', array( $this, 'render_form_buttons' ) );
658 658
         add_filter( 'gform_disable_view_counter', '__return_true' );
659 659
 
660 660
         add_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5, 5 );
661 661
         add_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10, 5 );
662 662
 
663 663
         // We need to remove the fake $_GET['page'] arg to avoid rendering form as if in admin.
664
-        unset( $_GET['page'] );
664
+        unset( $_GET[ 'page' ] );
665 665
 
666 666
         // TODO: Make sure validation isn't handled by GF
667 667
         // TODO: Include CSS for file upload fields
@@ -669,7 +669,7 @@  discard block
 block discarded – undo
669 669
         // TODO: Product fields are not editable
670 670
         // TODO: Check Updated and Error messages
671 671
 
672
-        $html = GFFormDisplay::get_form( $this->form['id'], false, false, true, $this->entry );
672
+        $html = GFFormDisplay::get_form( $this->form[ 'id' ], false, false, true, $this->entry );
673 673
 
674 674
 	    remove_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields' ), 5000 );
675 675
         remove_filter( 'gform_submit_button', array( $this, 'render_form_buttons' ) );
@@ -686,7 +686,7 @@  discard block
 block discarded – undo
686 686
      * @return string
687 687
      */
688 688
     public function render_form_buttons() {
689
-        return gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/form-buttons.php', $this );
689
+        return gravityview_ob_include( GravityView_Edit_Entry::$file . '/partials/form-buttons.php', $this );
690 690
     }
691 691
 
692 692
 
@@ -706,17 +706,17 @@  discard block
 block discarded – undo
706 706
     public function filter_modify_form_fields( $form, $ajax = false, $field_values = '' ) {
707 707
 
708 708
         // In case we have validated the form, use it to inject the validation results into the form render
709
-        if( isset( $this->form_after_validation ) ) {
709
+        if ( isset( $this->form_after_validation ) ) {
710 710
             $form = $this->form_after_validation;
711 711
         } else {
712
-            $form['fields'] = $this->get_configured_edit_fields( $form, $this->view_id );
712
+            $form[ 'fields' ] = $this->get_configured_edit_fields( $form, $this->view_id );
713 713
         }
714 714
 
715 715
         $form = $this->filter_conditional_logic( $form );
716 716
 
717 717
         // for now we don't support Save and Continue feature.
718
-        if( ! self::$supports_save_and_continue ) {
719
-	        unset( $form['save'] );
718
+        if ( ! self::$supports_save_and_continue ) {
719
+	        unset( $form[ 'save' ] );
720 720
         }
721 721
 
722 722
         return $form;
@@ -737,29 +737,29 @@  discard block
 block discarded – undo
737 737
      */
738 738
     function verify_user_can_edit_post( $field_content = '', $field, $value, $lead_id = 0, $form_id ) {
739 739
 
740
-        if( GFCommon::is_post_field( $field ) ) {
740
+        if ( GFCommon::is_post_field( $field ) ) {
741 741
 
742 742
             $message = null;
743 743
 
744 744
             // First, make sure they have the capability to edit the post.
745
-            if( false === current_user_can( 'edit_post', $this->entry['post_id'] ) ) {
745
+            if ( false === current_user_can( 'edit_post', $this->entry[ 'post_id' ] ) ) {
746 746
 
747 747
                 /**
748 748
                  * @filter `gravityview/edit_entry/unsupported_post_field_text` Modify the message when someone isn't able to edit a post
749 749
                  * @param string $message The existing "You don't have permission..." text
750 750
                  */
751
-                $message = apply_filters('gravityview/edit_entry/unsupported_post_field_text', __('You don&rsquo;t have permission to edit this post.', 'gravityview') );
751
+                $message = apply_filters( 'gravityview/edit_entry/unsupported_post_field_text', __( 'You don&rsquo;t have permission to edit this post.', 'gravityview' ) );
752 752
 
753
-            } elseif( null === get_post( $this->entry['post_id'] ) ) {
753
+            } elseif ( null === get_post( $this->entry[ 'post_id' ] ) ) {
754 754
                 /**
755 755
                  * @filter `gravityview/edit_entry/no_post_text` Modify the message when someone is editing an entry attached to a post that no longer exists
756 756
                  * @param string $message The existing "This field is not editable; the post no longer exists." text
757 757
                  */
758
-                $message = apply_filters('gravityview/edit_entry/no_post_text', __('This field is not editable; the post no longer exists.', 'gravityview' ) );
758
+                $message = apply_filters( 'gravityview/edit_entry/no_post_text', __( 'This field is not editable; the post no longer exists.', 'gravityview' ) );
759 759
             }
760 760
 
761
-            if( $message ) {
762
-                $field_content = sprintf('<div class="ginput_container ginput_container_' . $field->type . '">%s</div>', wpautop( $message ) );
761
+            if ( $message ) {
762
+                $field_content = sprintf( '<div class="ginput_container ginput_container_' . $field->type . '">%s</div>', wpautop( $message ) );
763 763
             }
764 764
         }
765 765
 
@@ -784,7 +784,7 @@  discard block
 block discarded – undo
784 784
 
785 785
         // If the form has been submitted, then we don't need to pre-fill the values,
786 786
         // Except for fileupload type and when a field input is overridden- run always!!
787
-        if(
787
+        if (
788 788
             ( $this->is_edit_entry_submission() && 'fileupload' !== $field->type )
789 789
             && false === ( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) )
790 790
             || ! empty( $field_content )
@@ -794,8 +794,8 @@  discard block
 block discarded – undo
794 794
         }
795 795
 
796 796
         // Turn on Admin-style display for file upload fields only
797
-        if( 'fileupload' === $field->type ) {
798
-            $_GET['page'] = 'gf_entries';
797
+        if ( 'fileupload' === $field->type ) {
798
+            $_GET[ 'page' ] = 'gf_entries';
799 799
         }
800 800
 
801 801
         // SET SOME FIELD DEFAULTS TO PREVENT ISSUES
@@ -819,7 +819,7 @@  discard block
 block discarded – undo
819 819
 	    // Prevent any PHP warnings, like undefined index
820 820
 	    ob_start();
821 821
 
822
-        if( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) ) {
822
+        if ( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) ) {
823 823
             $return = $gv_field->get_field_input( $this->form, $field_value, $this->entry, $field );
824 824
         } else {
825 825
 	        $return = $field->get_field_input( $this->form, $field_value, $this->entry );
@@ -828,7 +828,7 @@  discard block
 block discarded – undo
828 828
 	    // If there was output, it's an error
829 829
 	    $warnings = ob_get_clean();
830 830
 
831
-	    if( !empty( $warnings ) ) {
831
+	    if ( ! empty( $warnings ) ) {
832 832
 		    do_action( 'gravityview_log_error', __METHOD__ . $warnings, $field_value );
833 833
 	    }
834 834
 
@@ -837,7 +837,7 @@  discard block
 block discarded – undo
837 837
          * We need the fileupload html field to render with the proper id
838 838
          *  ( <li id="field_80_16" ... > )
839 839
          */
840
-        unset( $_GET['page'] );
840
+        unset( $_GET[ 'page' ] );
841 841
 
842 842
         return $return;
843 843
     }
@@ -860,7 +860,7 @@  discard block
 block discarded – undo
860 860
         $override_saved_value = apply_filters( 'gravityview/edit_entry/pre_populate/override', false, $field );
861 861
 
862 862
         // We're dealing with multiple inputs (e.g. checkbox) but not time or date (as it doesn't store data in input IDs)
863
-        if( isset( $field->inputs ) && is_array( $field->inputs ) && !in_array( $field->type, array( 'time', 'date' ) ) ) {
863
+        if ( isset( $field->inputs ) && is_array( $field->inputs ) && ! in_array( $field->type, array( 'time', 'date' ) ) ) {
864 864
 
865 865
             $field_value = array();
866 866
 
@@ -869,10 +869,10 @@  discard block
 block discarded – undo
869 869
 
870 870
             foreach ( (array)$field->inputs as $input ) {
871 871
 
872
-                $input_id = strval( $input['id'] );
872
+                $input_id = strval( $input[ 'id' ] );
873 873
 
874 874
                 if ( ! gv_empty( $this->entry[ $input_id ], false ) ) {
875
-                    $field_value[ $input_id ] =  'post_category' === $field->type ? GFCommon::format_post_category( $this->entry[ $input_id ], true ) : $this->entry[ $input_id ];
875
+                    $field_value[ $input_id ] = 'post_category' === $field->type ? GFCommon::format_post_category( $this->entry[ $input_id ], true ) : $this->entry[ $input_id ];
876 876
                     $allow_pre_populated = false;
877 877
                 }
878 878
 
@@ -880,7 +880,7 @@  discard block
 block discarded – undo
880 880
 
881 881
             $pre_value = $field->get_value_submission( array(), false );
882 882
 
883
-            $field_value = ! $allow_pre_populated && ! ( $override_saved_value && !gv_empty( $pre_value, false ) ) ? $field_value : $pre_value;
883
+            $field_value = ! $allow_pre_populated && ! ( $override_saved_value && ! gv_empty( $pre_value, false ) ) ? $field_value : $pre_value;
884 884
 
885 885
         } else {
886 886
 
@@ -891,13 +891,13 @@  discard block
 block discarded – undo
891 891
 
892 892
             // saved field entry value (if empty, fallback to the pre-populated value, if exists)
893 893
             // or pre-populated value if not empty and set to override saved value
894
-            $field_value = !gv_empty( $this->entry[ $id ], false ) && ! ( $override_saved_value && !gv_empty( $pre_value, false ) ) ? $this->entry[ $id ] : $pre_value;
894
+            $field_value = ! gv_empty( $this->entry[ $id ], false ) && ! ( $override_saved_value && ! gv_empty( $pre_value, false ) ) ? $this->entry[ $id ] : $pre_value;
895 895
 
896 896
             // in case field is post_category but inputType is select, multi-select or radio, convert value into array of category IDs.
897
-            if ( 'post_category' === $field->type && !gv_empty( $field_value, false ) ) {
897
+            if ( 'post_category' === $field->type && ! gv_empty( $field_value, false ) ) {
898 898
                 $categories = array();
899 899
                 foreach ( explode( ',', $field_value ) as $cat_string ) {
900
-                    $categories[] = GFCommon::format_post_category( $cat_string, true );
900
+                    $categories[ ] = GFCommon::format_post_category( $cat_string, true );
901 901
                 }
902 902
                 $field_value = 'multiselect' === $field->get_input_type() ? $categories : implode( '', $categories );
903 903
             }
@@ -922,12 +922,12 @@  discard block
 block discarded – undo
922 922
      */
923 923
     function gform_pre_validation( $form ) {
924 924
 
925
-        if( ! $this->verify_nonce() ) {
925
+        if ( ! $this->verify_nonce() ) {
926 926
             return $form;
927 927
         }
928 928
 
929 929
         // Fix PHP warning regarding undefined index.
930
-        foreach ( $form['fields'] as &$field) {
930
+        foreach ( $form[ 'fields' ] as &$field ) {
931 931
 
932 932
             // This is because we're doing admin form pretending to be front-end, so Gravity Forms
933 933
             // expects certain field array items to be set.
@@ -940,7 +940,7 @@  discard block
 block discarded – undo
940 940
                 $field['emailConfirmEnabled'] = '';
941 941
             }*/
942 942
 
943
-            switch( RGFormsModel::get_input_type( $field ) ) {
943
+            switch ( RGFormsModel::get_input_type( $field ) ) {
944 944
 
945 945
                 /**
946 946
                  * 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.
@@ -955,37 +955,37 @@  discard block
 block discarded – undo
955 955
                     // Set the previous value
956 956
                     $entry = $this->get_entry();
957 957
 
958
-                    $input_name = 'input_'.$field->id;
959
-                    $form_id = $form['id'];
958
+                    $input_name = 'input_' . $field->id;
959
+                    $form_id = $form[ 'id' ];
960 960
 
961 961
                     $value = NULL;
962 962
 
963 963
                     // Use the previous entry value as the default.
964
-                    if( isset( $entry[ $field->id ] ) ) {
964
+                    if ( isset( $entry[ $field->id ] ) ) {
965 965
                         $value = $entry[ $field->id ];
966 966
                     }
967 967
 
968 968
                     // If this is a single upload file
969
-                    if( !empty( $_FILES[ $input_name ] ) && !empty( $_FILES[ $input_name ]['name'] ) ) {
970
-                        $file_path = GFFormsModel::get_file_upload_path( $form['id'], $_FILES[ $input_name ]['name'] );
971
-                        $value = $file_path['url'];
969
+                    if ( ! empty( $_FILES[ $input_name ] ) && ! empty( $_FILES[ $input_name ][ 'name' ] ) ) {
970
+                        $file_path = GFFormsModel::get_file_upload_path( $form[ 'id' ], $_FILES[ $input_name ][ 'name' ] );
971
+                        $value = $file_path[ 'url' ];
972 972
 
973 973
                     } else {
974 974
 
975 975
                         // Fix PHP warning on line 1498 of form_display.php for post_image fields
976 976
                         // Fix PHP Notice:  Undefined index:  size in form_display.php on line 1511
977
-                        $_FILES[ $input_name ] = array('name' => '', 'size' => '' );
977
+                        $_FILES[ $input_name ] = array( 'name' => '', 'size' => '' );
978 978
 
979 979
                     }
980 980
 
981
-                    if( rgar($field, "multipleFiles") ) {
981
+                    if ( rgar( $field, "multipleFiles" ) ) {
982 982
 
983 983
                         // If there are fresh uploads, process and merge them.
984 984
                         // Otherwise, use the passed values, which should be json-encoded array of URLs
985
-                        if( isset( GFFormsModel::$uploaded_files[$form_id][$input_name] ) ) {
985
+                        if ( isset( GFFormsModel::$uploaded_files[ $form_id ][ $input_name ] ) ) {
986 986
                             $value = empty( $value ) ? '[]' : $value;
987 987
                             $value = stripslashes_deep( $value );
988
-                            $value = GFFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'], array());
988
+                            $value = GFFormsModel::prepare_value( $form, $field, $value, $input_name, $entry[ 'id' ], array() );
989 989
                         }
990 990
 
991 991
                     } else {
@@ -1009,14 +1009,14 @@  discard block
 block discarded – undo
1009 1009
                     break;
1010 1010
                 case 'number':
1011 1011
                     // Fix "undefined index" issue at line 1286 in form_display.php
1012
-                    if( !isset( $_POST['input_'.$field->id ] ) ) {
1013
-                        $_POST['input_'.$field->id ] = NULL;
1012
+                    if ( ! isset( $_POST[ 'input_' . $field->id ] ) ) {
1013
+                        $_POST[ 'input_' . $field->id ] = NULL;
1014 1014
                     }
1015 1015
                     break;
1016 1016
                 case 'captcha':
1017 1017
                     // Fix issue with recaptcha_check_answer() on line 1458 in form_display.php
1018
-                    $_POST['recaptcha_challenge_field'] = NULL;
1019
-                    $_POST['recaptcha_response_field'] = NULL;
1018
+                    $_POST[ 'recaptcha_challenge_field' ] = NULL;
1019
+                    $_POST[ 'recaptcha_response_field' ] = NULL;
1020 1020
                     break;
1021 1021
             }
1022 1022
 
@@ -1045,7 +1045,7 @@  discard block
 block discarded – undo
1045 1045
          * You can enter whatever you want!
1046 1046
          * We try validating, and customize the results using `self::custom_validation()`
1047 1047
          */
1048
-        add_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10, 4);
1048
+        add_filter( 'gform_validation_' . $this->form_id, array( $this, 'custom_validation' ), 10, 4 );
1049 1049
 
1050 1050
         // Needed by the validate funtion
1051 1051
         $failed_validation_page = NULL;
@@ -1053,14 +1053,14 @@  discard block
 block discarded – undo
1053 1053
 
1054 1054
         // Prevent entry limit from running when editing an entry, also
1055 1055
         // prevent form scheduling from preventing editing
1056
-        unset( $this->form['limitEntries'], $this->form['scheduleForm'] );
1056
+        unset( $this->form[ 'limitEntries' ], $this->form[ 'scheduleForm' ] );
1057 1057
 
1058 1058
         // Hide fields depending on Edit Entry settings
1059
-        $this->form['fields'] = $this->get_configured_edit_fields( $this->form, $this->view_id );
1059
+        $this->form[ 'fields' ] = $this->get_configured_edit_fields( $this->form, $this->view_id );
1060 1060
 
1061 1061
         $this->is_valid = GFFormDisplay::validate( $this->form, $field_values, 1, $failed_validation_page );
1062 1062
 
1063
-        remove_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10 );
1063
+        remove_filter( 'gform_validation_' . $this->form_id, array( $this, 'custom_validation' ), 10 );
1064 1064
     }
1065 1065
 
1066 1066
 
@@ -1077,13 +1077,13 @@  discard block
 block discarded – undo
1077 1077
      */
1078 1078
     function custom_validation( $validation_results ) {
1079 1079
 
1080
-        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results: ', $validation_results );
1080
+        do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results: ', $validation_results );
1081 1081
 
1082
-        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) );
1082
+        do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) );
1083 1083
 
1084 1084
         $gv_valid = true;
1085 1085
 
1086
-        foreach ( $validation_results['form']['fields'] as $key => &$field ) {
1086
+        foreach ( $validation_results[ 'form' ][ 'fields' ] as $key => &$field ) {
1087 1087
 
1088 1088
             $value = RGFormsModel::get_field_value( $field );
1089 1089
             $field_type = RGFormsModel::get_input_type( $field );
@@ -1095,35 +1095,35 @@  discard block
 block discarded – undo
1095 1095
                 case 'fileupload' :
1096 1096
 
1097 1097
                     // in case nothing is uploaded but there are already files saved
1098
-                    if( !empty( $field->failed_validation ) && !empty( $field->isRequired ) && !empty( $value ) ) {
1098
+                    if ( ! empty( $field->failed_validation ) && ! empty( $field->isRequired ) && ! empty( $value ) ) {
1099 1099
                         $field->failed_validation = false;
1100 1100
                         unset( $field->validation_message );
1101 1101
                     }
1102 1102
 
1103 1103
                     // validate if multi file upload reached max number of files [maxFiles] => 2
1104
-                    if( rgobj( $field, 'maxFiles') && rgobj( $field, 'multipleFiles') ) {
1104
+                    if ( rgobj( $field, 'maxFiles' ) && rgobj( $field, 'multipleFiles' ) ) {
1105 1105
 
1106 1106
                         $input_name = 'input_' . $field->id;
1107 1107
                         //uploaded
1108
-                        $file_names = isset( GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] ) ? GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] : array();
1108
+                        $file_names = isset( GFFormsModel::$uploaded_files[ $validation_results[ 'form' ][ 'id' ] ][ $input_name ] ) ? GFFormsModel::$uploaded_files[ $validation_results[ 'form' ][ 'id' ] ][ $input_name ] : array();
1109 1109
 
1110 1110
                         //existent
1111 1111
                         $entry = $this->get_entry();
1112 1112
                         $value = NULL;
1113
-                        if( isset( $entry[ $field->id ] ) ) {
1113
+                        if ( isset( $entry[ $field->id ] ) ) {
1114 1114
                             $value = json_decode( $entry[ $field->id ], true );
1115 1115
                         }
1116 1116
 
1117 1117
                         // count uploaded files and existent entry files
1118 1118
                         $count_files = count( $file_names ) + count( $value );
1119 1119
 
1120
-                        if( $count_files > $field->maxFiles ) {
1120
+                        if ( $count_files > $field->maxFiles ) {
1121 1121
                             $field->validation_message = __( 'Maximum number of files reached', 'gravityview' );
1122 1122
                             $field->failed_validation = 1;
1123 1123
                             $gv_valid = false;
1124 1124
 
1125 1125
                             // in case of error make sure the newest upload files are removed from the upload input
1126
-                            GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ] = null;
1126
+                            GFFormsModel::$uploaded_files[ $validation_results[ 'form' ][ 'id' ] ] = null;
1127 1127
                         }
1128 1128
 
1129 1129
                     }
@@ -1134,7 +1134,7 @@  discard block
 block discarded – undo
1134 1134
             }
1135 1135
 
1136 1136
             // This field has failed validation.
1137
-            if( !empty( $field->failed_validation ) ) {
1137
+            if ( ! empty( $field->failed_validation ) ) {
1138 1138
 
1139 1139
                 do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field is invalid.', array( 'field' => $field, 'value' => $value ) );
1140 1140
 
@@ -1152,32 +1152,32 @@  discard block
 block discarded – undo
1152 1152
                 }
1153 1153
 
1154 1154
                 // You can't continue inside a switch, so we do it after.
1155
-                if( empty( $field->failed_validation ) ) {
1155
+                if ( empty( $field->failed_validation ) ) {
1156 1156
                     continue;
1157 1157
                 }
1158 1158
 
1159 1159
                 // checks if the No Duplicates option is not validating entry against itself, since
1160 1160
                 // we're editing a stored entry, it would also assume it's a duplicate.
1161
-                if( !empty( $field->noDuplicates ) ) {
1161
+                if ( ! empty( $field->noDuplicates ) ) {
1162 1162
 
1163 1163
                     $entry = $this->get_entry();
1164 1164
 
1165 1165
                     // If the value of the entry is the same as the stored value
1166 1166
                     // Then we can assume it's not a duplicate, it's the same.
1167
-                    if( !empty( $entry ) && $value == $entry[ $field->id ] ) {
1167
+                    if ( ! empty( $entry ) && $value == $entry[ $field->id ] ) {
1168 1168
                         //if value submitted was not changed, then don't validate
1169 1169
                         $field->failed_validation = false;
1170 1170
 
1171 1171
                         unset( $field->validation_message );
1172 1172
 
1173
-                        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', $entry );
1173
+                        do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', $entry );
1174 1174
 
1175 1175
                         continue;
1176 1176
                     }
1177 1177
                 }
1178 1178
 
1179 1179
                 // if here then probably we are facing the validation 'At least one field must be filled out'
1180
-                if( GFFormDisplay::is_empty( $field, $this->form_id  ) && empty( $field->isRequired ) ) {
1180
+                if ( GFFormDisplay::is_empty( $field, $this->form_id ) && empty( $field->isRequired ) ) {
1181 1181
                     unset( $field->validation_message );
1182 1182
 	                $field->validation_message = false;
1183 1183
                     continue;
@@ -1189,12 +1189,12 @@  discard block
 block discarded – undo
1189 1189
 
1190 1190
         }
1191 1191
 
1192
-        $validation_results['is_valid'] = $gv_valid;
1192
+        $validation_results[ 'is_valid' ] = $gv_valid;
1193 1193
 
1194
-        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results.', $validation_results );
1194
+        do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results.', $validation_results );
1195 1195
 
1196 1196
         // We'll need this result when rendering the form ( on GFFormDisplay::get_form )
1197
-        $this->form_after_validation = $validation_results['form'];
1197
+        $this->form_after_validation = $validation_results[ 'form' ];
1198 1198
 
1199 1199
         return $validation_results;
1200 1200
     }
@@ -1207,7 +1207,7 @@  discard block
 block discarded – undo
1207 1207
      */
1208 1208
     private function get_entry() {
1209 1209
 
1210
-        if( empty( $this->entry ) ) {
1210
+        if ( empty( $this->entry ) ) {
1211 1211
             // Get the database value of the entry that's being edited
1212 1212
             $this->entry = gravityview_get_entry( GravityView_frontend::is_single_entry() );
1213 1213
         }
@@ -1234,13 +1234,13 @@  discard block
 block discarded – undo
1234 1234
         $properties = GravityView_View_Data::getInstance()->get_fields( $view_id );
1235 1235
 
1236 1236
         // If edit tab not yet configured, show all fields
1237
-        $edit_fields = !empty( $properties['edit_edit-fields'] ) ? $properties['edit_edit-fields'] : NULL;
1237
+        $edit_fields = ! empty( $properties[ 'edit_edit-fields' ] ) ? $properties[ 'edit_edit-fields' ] : NULL;
1238 1238
 
1239 1239
 	    // Show hidden fields as text fields
1240 1240
 	    $form = $this->fix_hidden_fields( $form );
1241 1241
 
1242 1242
         // Hide fields depending on admin settings
1243
-        $fields = $this->filter_fields( $form['fields'], $edit_fields );
1243
+        $fields = $this->filter_fields( $form[ 'fields' ], $edit_fields );
1244 1244
 
1245 1245
 	    // If Edit Entry fields are configured, remove adminOnly field settings. Otherwise, don't.
1246 1246
 	    $fields = $this->filter_admin_only_fields( $fields, $edit_fields, $form, $view_id );
@@ -1258,11 +1258,11 @@  discard block
 block discarded – undo
1258 1258
 	private function fix_hidden_fields( $form ) {
1259 1259
 
1260 1260
 		/** @var GF_Field $field */
1261
-		foreach( $form['fields'] as $key => $field ) {
1262
-			if( 'hidden' === $field->type ) {
1261
+		foreach ( $form[ 'fields' ] as $key => $field ) {
1262
+			if ( 'hidden' === $field->type ) {
1263 1263
 				$text_field = new GF_Field_Text( $field );
1264 1264
 				$text_field->type = 'text';
1265
-				$form['fields'][ $key ] = $text_field;
1265
+				$form[ 'fields' ][ $key ] = $text_field;
1266 1266
 			}
1267 1267
 		}
1268 1268
 
@@ -1283,7 +1283,7 @@  discard block
 block discarded – undo
1283 1283
      */
1284 1284
     private function filter_fields( $fields, $configured_fields ) {
1285 1285
 
1286
-        if( empty( $fields ) || !is_array( $fields ) ) {
1286
+        if ( empty( $fields ) || ! is_array( $fields ) ) {
1287 1287
             return $fields;
1288 1288
         }
1289 1289
 
@@ -1300,13 +1300,13 @@  discard block
 block discarded – undo
1300 1300
 	     */
1301 1301
 	    $hide_product_fields = apply_filters( 'gravityview/edit_entry/hide-product-fields', empty( self::$supports_product_fields ) );
1302 1302
 
1303
-	    if( $hide_product_fields ) {
1304
-		    $field_type_blacklist[] = 'option';
1305
-		    $field_type_blacklist[] = 'quantity';
1306
-            $field_type_blacklist[] = 'product';
1307
-            $field_type_blacklist[] = 'total';
1308
-            $field_type_blacklist[] = 'shipping';
1309
-            $field_type_blacklist[] = 'calculation'; //todo: this field type doesn't exist ?
1303
+	    if ( $hide_product_fields ) {
1304
+		    $field_type_blacklist[ ] = 'option';
1305
+		    $field_type_blacklist[ ] = 'quantity';
1306
+            $field_type_blacklist[ ] = 'product';
1307
+            $field_type_blacklist[ ] = 'total';
1308
+            $field_type_blacklist[ ] = 'shipping';
1309
+            $field_type_blacklist[ ] = 'calculation'; //todo: this field type doesn't exist ?
1310 1310
 	    }
1311 1311
 
1312 1312
         // First, remove blacklist or calculation fields
@@ -1314,18 +1314,18 @@  discard block
 block discarded – undo
1314 1314
 
1315 1315
             // Remove the fields that have calculation properties and keep them to be used later
1316 1316
             // @since 1.16.2
1317
-            if( $field->has_calculation() ) {
1318
-                $this->fields_with_calculation[] = $field;
1317
+            if ( $field->has_calculation() ) {
1318
+                $this->fields_with_calculation[ ] = $field;
1319 1319
                 unset( $fields[ $key ] );
1320 1320
             }
1321 1321
 
1322
-            if( in_array( $field->type, $field_type_blacklist ) ) {
1322
+            if ( in_array( $field->type, $field_type_blacklist ) ) {
1323 1323
                 unset( $fields[ $key ] );
1324 1324
             }
1325 1325
         }
1326 1326
 
1327 1327
         // The Edit tab has not been configured, so we return all fields by default.
1328
-        if( empty( $configured_fields ) ) {
1328
+        if ( empty( $configured_fields ) ) {
1329 1329
             return $fields;
1330 1330
         }
1331 1331
 
@@ -1335,8 +1335,8 @@  discard block
 block discarded – undo
1335 1335
 	        /** @var GF_Field $field */
1336 1336
 	        foreach ( $fields as $field ) {
1337 1337
 
1338
-                if( intval( $configured_field['id'] ) === intval( $field->id ) && $this->user_can_edit_field( $configured_field, false ) ) {
1339
-                    $edit_fields[] = $this->merge_field_properties( $field, $configured_field );
1338
+                if ( intval( $configured_field[ 'id' ] ) === intval( $field->id ) && $this->user_can_edit_field( $configured_field, false ) ) {
1339
+                    $edit_fields[ ] = $this->merge_field_properties( $field, $configured_field );
1340 1340
                     break;
1341 1341
                 }
1342 1342
 
@@ -1359,14 +1359,14 @@  discard block
 block discarded – undo
1359 1359
 
1360 1360
         $return_field = $field;
1361 1361
 
1362
-        if( empty( $field_setting['show_label'] ) ) {
1362
+        if ( empty( $field_setting[ 'show_label' ] ) ) {
1363 1363
             $return_field->label = '';
1364
-        } elseif ( !empty( $field_setting['custom_label'] ) ) {
1365
-            $return_field->label = $field_setting['custom_label'];
1364
+        } elseif ( ! empty( $field_setting[ 'custom_label' ] ) ) {
1365
+            $return_field->label = $field_setting[ 'custom_label' ];
1366 1366
         }
1367 1367
 
1368
-        if( !empty( $field_setting['custom_class'] ) ) {
1369
-            $return_field->cssClass .= ' '. gravityview_sanitize_html_class( $field_setting['custom_class'] );
1368
+        if ( ! empty( $field_setting[ 'custom_class' ] ) ) {
1369
+            $return_field->cssClass .= ' ' . gravityview_sanitize_html_class( $field_setting[ 'custom_class' ] );
1370 1370
         }
1371 1371
 
1372 1372
         /**
@@ -1404,11 +1404,11 @@  discard block
 block discarded – undo
1404 1404
 	     */
1405 1405
 	    $use_gf_adminonly_setting = apply_filters( 'gravityview/edit_entry/use_gf_admin_only_setting', empty( $edit_fields ), $form, $view_id );
1406 1406
 
1407
-	    if( $use_gf_adminonly_setting && false === GVCommon::has_cap( 'gravityforms_edit_entries', $this->entry['id'] ) ) {
1407
+	    if ( $use_gf_adminonly_setting && false === GVCommon::has_cap( 'gravityforms_edit_entries', $this->entry[ 'id' ] ) ) {
1408 1408
             return $fields;
1409 1409
         }
1410 1410
 
1411
-	    foreach( $fields as &$field ) {
1411
+	    foreach ( $fields as &$field ) {
1412 1412
 		    $field->adminOnly = false;
1413 1413
         }
1414 1414
 
@@ -1435,16 +1435,16 @@  discard block
 block discarded – undo
1435 1435
          */
1436 1436
         $use_conditional_logic = apply_filters( 'gravityview/edit_entry/conditional_logic', true, $form );
1437 1437
 
1438
-        if( $use_conditional_logic ) {
1438
+        if ( $use_conditional_logic ) {
1439 1439
             return $form;
1440 1440
         }
1441 1441
 
1442
-        foreach( $form['fields'] as &$field ) {
1442
+        foreach ( $form[ 'fields' ] as &$field ) {
1443 1443
             /* @var GF_Field $field */
1444 1444
             $field->conditionalLogic = null;
1445 1445
         }
1446 1446
 
1447
-        unset( $form['button']['conditionalLogic'] );
1447
+        unset( $form[ 'button' ][ 'conditionalLogic' ] );
1448 1448
 
1449 1449
         return $form;
1450 1450
 
@@ -1461,7 +1461,7 @@  discard block
 block discarded – undo
1461 1461
      */
1462 1462
     function manage_conditional_logic( $has_conditional_logic, $form ) {
1463 1463
 
1464
-        if( ! $this->is_edit_entry() ) {
1464
+        if ( ! $this->is_edit_entry() ) {
1465 1465
             return $has_conditional_logic;
1466 1466
         }
1467 1467
 
@@ -1492,44 +1492,44 @@  discard block
 block discarded – undo
1492 1492
          *  2. There are two entries embedded using oEmbed
1493 1493
          *  3. One of the entries has just been saved
1494 1494
          */
1495
-        if( !empty( $_POST['lid'] ) && !empty( $_GET['entry'] ) && ( $_POST['lid'] !== $_GET['entry'] ) ) {
1495
+        if ( ! empty( $_POST[ 'lid' ] ) && ! empty( $_GET[ 'entry' ] ) && ( $_POST[ 'lid' ] !== $_GET[ 'entry' ] ) ) {
1496 1496
 
1497 1497
             $error = true;
1498 1498
 
1499 1499
         }
1500 1500
 
1501
-        if( !empty( $_GET['entry'] ) && (string)$this->entry['id'] !== $_GET['entry'] ) {
1501
+        if ( ! empty( $_GET[ 'entry' ] ) && (string)$this->entry[ 'id' ] !== $_GET[ 'entry' ] ) {
1502 1502
 
1503 1503
             $error = true;
1504 1504
 
1505
-        } elseif( ! $this->verify_nonce() ) {
1505
+        } elseif ( ! $this->verify_nonce() ) {
1506 1506
 
1507 1507
             /**
1508 1508
              * If the Entry is embedded, there may be two entries on the same page.
1509 1509
              * If that's the case, and one is being edited, the other should fail gracefully and not display an error.
1510 1510
              */
1511
-            if( GravityView_oEmbed::getInstance()->get_entry_id() ) {
1511
+            if ( GravityView_oEmbed::getInstance()->get_entry_id() ) {
1512 1512
                 $error = true;
1513 1513
             } else {
1514
-                $error = __( 'The link to edit this entry is not valid; it may have expired.', 'gravityview');
1514
+                $error = __( 'The link to edit this entry is not valid; it may have expired.', 'gravityview' );
1515 1515
             }
1516 1516
 
1517 1517
         }
1518 1518
 
1519
-        if( ! GravityView_Edit_Entry::check_user_cap_edit_entry( $this->entry ) ) {
1520
-            $error = __( 'You do not have permission to edit this entry.', 'gravityview');
1519
+        if ( ! GravityView_Edit_Entry::check_user_cap_edit_entry( $this->entry ) ) {
1520
+            $error = __( 'You do not have permission to edit this entry.', 'gravityview' );
1521 1521
         }
1522 1522
 
1523
-        if( $this->entry['status'] === 'trash' ) {
1524
-            $error = __('You cannot edit the entry; it is in the trash.', 'gravityview' );
1523
+        if ( $this->entry[ 'status' ] === 'trash' ) {
1524
+            $error = __( 'You cannot edit the entry; it is in the trash.', 'gravityview' );
1525 1525
         }
1526 1526
 
1527 1527
         // No errors; everything's fine here!
1528
-        if( empty( $error ) ) {
1528
+        if ( empty( $error ) ) {
1529 1529
             return true;
1530 1530
         }
1531 1531
 
1532
-        if( $echo && $error !== true ) {
1532
+        if ( $echo && $error !== true ) {
1533 1533
 
1534 1534
 	        $error = esc_html( $error );
1535 1535
 
@@ -1537,13 +1537,13 @@  discard block
 block discarded – undo
1537 1537
 	         * @since 1.9
1538 1538
 	         */
1539 1539
 	        if ( ! empty( $this->entry ) ) {
1540
-		        $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;" ) );
1540
+		        $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;" ) );
1541 1541
 	        }
1542 1542
 
1543
-            echo GVCommon::generate_notice( wpautop( $error ), 'gv-error error');
1543
+            echo GVCommon::generate_notice( wpautop( $error ), 'gv-error error' );
1544 1544
         }
1545 1545
 
1546
-        do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_entry]' . $error );
1546
+        do_action( 'gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_entry]' . $error );
1547 1547
 
1548 1548
         return false;
1549 1549
     }
@@ -1560,20 +1560,20 @@  discard block
 block discarded – undo
1560 1560
 
1561 1561
         $error = NULL;
1562 1562
 
1563
-        if( ! $this->check_user_cap_edit_field( $field ) ) {
1564
-            $error = __( 'You do not have permission to edit this field.', 'gravityview');
1563
+        if ( ! $this->check_user_cap_edit_field( $field ) ) {
1564
+            $error = __( 'You do not have permission to edit this field.', 'gravityview' );
1565 1565
         }
1566 1566
 
1567 1567
         // No errors; everything's fine here!
1568
-        if( empty( $error ) ) {
1568
+        if ( empty( $error ) ) {
1569 1569
             return true;
1570 1570
         }
1571 1571
 
1572
-        if( $echo ) {
1573
-            echo GVCommon::generate_notice( wpautop( esc_html( $error ) ), 'gv-error error');
1572
+        if ( $echo ) {
1573
+            echo GVCommon::generate_notice( wpautop( esc_html( $error ) ), 'gv-error error' );
1574 1574
         }
1575 1575
 
1576
-        do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_field]' . $error );
1576
+        do_action( 'gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_field]' . $error );
1577 1577
 
1578 1578
         return false;
1579 1579
 
@@ -1591,15 +1591,15 @@  discard block
 block discarded – undo
1591 1591
     private function check_user_cap_edit_field( $field ) {
1592 1592
 
1593 1593
         // If they can edit any entries (as defined in Gravity Forms), we're good.
1594
-        if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ) ) ) {
1594
+        if ( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ) ) ) {
1595 1595
             return true;
1596 1596
         }
1597 1597
 
1598
-        $field_cap = isset( $field['allow_edit_cap'] ) ? $field['allow_edit_cap'] : false;
1598
+        $field_cap = isset( $field[ 'allow_edit_cap' ] ) ? $field[ 'allow_edit_cap' ] : false;
1599 1599
 
1600 1600
         // If the field has custom editing capaibilities set, check those
1601
-        if( $field_cap ) {
1602
-            return GVCommon::has_cap( $field['allow_edit_cap'] );
1601
+        if ( $field_cap ) {
1602
+            return GVCommon::has_cap( $field[ 'allow_edit_cap' ] );
1603 1603
         }
1604 1604
 
1605 1605
         return false;
@@ -1613,17 +1613,17 @@  discard block
 block discarded – undo
1613 1613
     public function verify_nonce() {
1614 1614
 
1615 1615
         // Verify form submitted for editing single
1616
-        if( $this->is_edit_entry_submission() ) {
1616
+        if ( $this->is_edit_entry_submission() ) {
1617 1617
             $valid = wp_verify_nonce( $_POST[ self::$nonce_field ], self::$nonce_field );
1618 1618
         }
1619 1619
 
1620 1620
         // Verify
1621
-        else if( ! $this->is_edit_entry() ) {
1621
+        else if ( ! $this->is_edit_entry() ) {
1622 1622
             $valid = false;
1623 1623
         }
1624 1624
 
1625 1625
         else {
1626
-            $valid = wp_verify_nonce( $_GET['edit'], self::$nonce_key );
1626
+            $valid = wp_verify_nonce( $_GET[ 'edit' ], self::$nonce_key );
1627 1627
         }
1628 1628
 
1629 1629
         /**
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -613,7 +613,7 @@  discard block
 block discarded – undo
613 613
 
614 614
             $back_link = esc_url( remove_query_arg( array( 'page', 'view', 'edit' ) ) );
615 615
 
616
-            if( ! $this->is_valid ){
616
+            if( ! $this->is_valid ) {
617 617
 
618 618
                 // Keeping this compatible with Gravity Forms.
619 619
                 $validation_message = "<div class='validation_error'>" . __('There was a problem with your submission.', 'gravityview') . " " . __('Errors have been highlighted below.', 'gravityview') . "</div>";
@@ -1620,9 +1620,7 @@  discard block
 block discarded – undo
1620 1620
         // Verify
1621 1621
         else if( ! $this->is_edit_entry() ) {
1622 1622
             $valid = false;
1623
-        }
1624
-
1625
-        else {
1623
+        } else {
1626 1624
             $valid = wp_verify_nonce( $_GET['edit'], self::$nonce_key );
1627 1625
         }
1628 1626
 
Please login to merge, or discard this patch.
Indentation   +1311 added lines, -1311 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,131 +44,131 @@  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 change the content through this class lifecycle)
56
-     *
57
-     * @var array
58
-     */
59
-    var $form;
60
-
61
-    /**
62
-     * Gravity Forms form array (original form)
63
-     * @since 1.16.2
64
-     * @var array
65
-     */
66
-    var $fields_with_calculation = array();
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
-     * Gravity Forms form id
77
-     *
78
-     * @var int
79
-     */
80
-    var $form_id;
81
-
82
-    /**
83
-     * ID of the current view
84
-     *
85
-     * @var int
86
-     */
87
-    var $view_id;
88
-
89
-
90
-    /**
91
-     * Updated entry is valid (GF Validation object)
92
-     *
93
-     * @var array
94
-     */
95
-    var $is_valid = NULL;
96
-
97
-    function __construct( GravityView_Edit_Entry $loader ) {
98
-        $this->loader = $loader;
99
-    }
100
-
101
-    function load() {
102
-
103
-        /** @define "GRAVITYVIEW_DIR" "../../../" */
104
-        include_once( GRAVITYVIEW_DIR .'includes/class-admin-approve-entries.php' );
105
-
106
-        // Don't display an embedded form when editing an entry
107
-        add_action( 'wp_head', array( $this, 'prevent_render_form' ) );
108
-        add_action( 'wp_footer', array( $this, 'prevent_render_form' ) );
109
-
110
-        // Stop Gravity Forms processing what is ours!
111
-        add_filter( 'wp', array( $this, 'prevent_maybe_process_form'), 8 );
112
-
113
-        add_filter( 'gravityview_is_edit_entry', array( $this, 'is_edit_entry') );
114
-
115
-        add_action( 'gravityview_edit_entry', array( $this, 'init' ) );
116
-
117
-        // Disable conditional logic if needed (since 1.9)
118
-        add_filter( 'gform_has_conditional_logic', array( $this, 'manage_conditional_logic' ), 10, 2 );
119
-
120
-        // Make sure GF doesn't validate max files (since 1.9)
121
-        add_filter( 'gform_plupload_settings', array( $this, 'modify_fileupload_settings' ), 10, 3 );
122
-
123
-        // Add fields expected by GFFormDisplay::validate()
124
-        add_filter( 'gform_pre_validation', array( $this, 'gform_pre_validation') );
125
-
126
-    }
127
-
128
-    /**
129
-     * Don't show any forms embedded on a page when GravityView is in Edit Entry mode
130
-     *
131
-     * Adds a `__return_empty_string` filter on the Gravity Forms shortcode on the `wp_head` action
132
-     * And then removes it on the `wp_footer` action
133
-     *
134
-     * @since 1.16.1
135
-     *
136
-     * @return void
137
-     */
138
-    function prevent_render_form() {
139
-        if( $this->is_edit_entry() ) {
140
-            if( 'wp_head' === current_filter() ) {
141
-                add_filter( 'gform_shortcode_form', '__return_empty_string' );
142
-            } else {
143
-                remove_filter( 'gform_shortcode_form', '__return_empty_string' );
144
-            }
145
-        }
146
-    }
147
-
148
-    /**
149
-     * Because we're mimicking being a front-end Gravity Forms form while using a Gravity Forms
150
-     * backend form, we need to prevent them from saving twice.
151
-     * @return void
152
-     */
153
-    function prevent_maybe_process_form() {
154
-
155
-        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[prevent_maybe_process_form] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) );
156
-
157
-        if( $this->is_edit_entry_submission() && $this->verify_nonce() ) {
158
-            remove_action( 'wp',  array( 'RGForms', 'maybe_process_form'), 9 );
159
-        }
160
-    }
161
-
162
-    /**
163
-     * Is the current page an Edit Entry page?
164
-     * @return boolean
165
-     */
166
-    public function is_edit_entry() {
167
-
168
-        $gf_page = ( 'entry' === RGForms::get( 'view' ) );
169
-
170
-        return ( $gf_page && isset( $_GET['edit'] ) || RGForms::post( 'action' ) === 'update' );
171
-    }
47
+	/**
48
+	 * Gravity Forms entry array
49
+	 *
50
+	 * @var array
51
+	 */
52
+	var $entry;
53
+
54
+	/**
55
+	 * Gravity Forms form array (GravityView change the content through this class lifecycle)
56
+	 *
57
+	 * @var array
58
+	 */
59
+	var $form;
60
+
61
+	/**
62
+	 * Gravity Forms form array (original form)
63
+	 * @since 1.16.2
64
+	 * @var array
65
+	 */
66
+	var $fields_with_calculation = array();
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
+	 * Gravity Forms form id
77
+	 *
78
+	 * @var int
79
+	 */
80
+	var $form_id;
81
+
82
+	/**
83
+	 * ID of the current view
84
+	 *
85
+	 * @var int
86
+	 */
87
+	var $view_id;
88
+
89
+
90
+	/**
91
+	 * Updated entry is valid (GF Validation object)
92
+	 *
93
+	 * @var array
94
+	 */
95
+	var $is_valid = NULL;
96
+
97
+	function __construct( GravityView_Edit_Entry $loader ) {
98
+		$this->loader = $loader;
99
+	}
100
+
101
+	function load() {
102
+
103
+		/** @define "GRAVITYVIEW_DIR" "../../../" */
104
+		include_once( GRAVITYVIEW_DIR .'includes/class-admin-approve-entries.php' );
105
+
106
+		// Don't display an embedded form when editing an entry
107
+		add_action( 'wp_head', array( $this, 'prevent_render_form' ) );
108
+		add_action( 'wp_footer', array( $this, 'prevent_render_form' ) );
109
+
110
+		// Stop Gravity Forms processing what is ours!
111
+		add_filter( 'wp', array( $this, 'prevent_maybe_process_form'), 8 );
112
+
113
+		add_filter( 'gravityview_is_edit_entry', array( $this, 'is_edit_entry') );
114
+
115
+		add_action( 'gravityview_edit_entry', array( $this, 'init' ) );
116
+
117
+		// Disable conditional logic if needed (since 1.9)
118
+		add_filter( 'gform_has_conditional_logic', array( $this, 'manage_conditional_logic' ), 10, 2 );
119
+
120
+		// Make sure GF doesn't validate max files (since 1.9)
121
+		add_filter( 'gform_plupload_settings', array( $this, 'modify_fileupload_settings' ), 10, 3 );
122
+
123
+		// Add fields expected by GFFormDisplay::validate()
124
+		add_filter( 'gform_pre_validation', array( $this, 'gform_pre_validation') );
125
+
126
+	}
127
+
128
+	/**
129
+	 * Don't show any forms embedded on a page when GravityView is in Edit Entry mode
130
+	 *
131
+	 * Adds a `__return_empty_string` filter on the Gravity Forms shortcode on the `wp_head` action
132
+	 * And then removes it on the `wp_footer` action
133
+	 *
134
+	 * @since 1.16.1
135
+	 *
136
+	 * @return void
137
+	 */
138
+	function prevent_render_form() {
139
+		if( $this->is_edit_entry() ) {
140
+			if( 'wp_head' === current_filter() ) {
141
+				add_filter( 'gform_shortcode_form', '__return_empty_string' );
142
+			} else {
143
+				remove_filter( 'gform_shortcode_form', '__return_empty_string' );
144
+			}
145
+		}
146
+	}
147
+
148
+	/**
149
+	 * Because we're mimicking being a front-end Gravity Forms form while using a Gravity Forms
150
+	 * backend form, we need to prevent them from saving twice.
151
+	 * @return void
152
+	 */
153
+	function prevent_maybe_process_form() {
154
+
155
+		do_action('gravityview_log_debug', 'GravityView_Edit_Entry[prevent_maybe_process_form] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) );
156
+
157
+		if( $this->is_edit_entry_submission() && $this->verify_nonce() ) {
158
+			remove_action( 'wp',  array( 'RGForms', 'maybe_process_form'), 9 );
159
+		}
160
+	}
161
+
162
+	/**
163
+	 * Is the current page an Edit Entry page?
164
+	 * @return boolean
165
+	 */
166
+	public function is_edit_entry() {
167
+
168
+		$gf_page = ( 'entry' === RGForms::get( 'view' ) );
169
+
170
+		return ( $gf_page && isset( $_GET['edit'] ) || RGForms::post( 'action' ) === 'update' );
171
+	}
172 172
 
173 173
 	/**
174 174
 	 * Is the current page an Edit Entry page?
@@ -179,391 +179,391 @@  discard block
 block discarded – undo
179 179
 		return !empty( $_POST[ self::$nonce_field ] );
180 180
 	}
181 181
 
182
-    /**
183
-     * When Edit entry view is requested setup the vars
184
-     */
185
-    function setup_vars() {
186
-        $gravityview_view = GravityView_View::getInstance();
182
+	/**
183
+	 * When Edit entry view is requested setup the vars
184
+	 */
185
+	function setup_vars() {
186
+		$gravityview_view = GravityView_View::getInstance();
187 187
 
188 188
 
189
-        $entries = $gravityview_view->getEntries();
190
-        $this->entry = $entries[0];
189
+		$entries = $gravityview_view->getEntries();
190
+		$this->entry = $entries[0];
191 191
 
192
-        $this->form = $gravityview_view->getForm();
193
-        $this->form_id = $gravityview_view->getFormId();
194
-        $this->view_id = $gravityview_view->getViewId();
192
+		$this->form = $gravityview_view->getForm();
193
+		$this->form_id = $gravityview_view->getFormId();
194
+		$this->view_id = $gravityview_view->getViewId();
195 195
 
196
-        self::$nonce_key = GravityView_Edit_Entry::get_nonce_key( $this->view_id, $this->form_id, $this->entry['id'] );
197
-    }
196
+		self::$nonce_key = GravityView_Edit_Entry::get_nonce_key( $this->view_id, $this->form_id, $this->entry['id'] );
197
+	}
198 198
 
199 199
 
200
-    /**
201
-     * Load required files and trigger edit flow
202
-     *
203
-     * Run when the is_edit_entry returns true.
204
-     *
205
-     * @param GravityView_View_Data $gv_data GravityView Data object
206
-     * @return void
207
-     */
208
-    function init( $gv_data ) {
200
+	/**
201
+	 * Load required files and trigger edit flow
202
+	 *
203
+	 * Run when the is_edit_entry returns true.
204
+	 *
205
+	 * @param GravityView_View_Data $gv_data GravityView Data object
206
+	 * @return void
207
+	 */
208
+	function init( $gv_data ) {
209 209
 
210
-        require_once( GFCommon::get_base_path() . '/form_display.php' );
211
-        require_once( GFCommon::get_base_path() . '/entry_detail.php' );
210
+		require_once( GFCommon::get_base_path() . '/form_display.php' );
211
+		require_once( GFCommon::get_base_path() . '/entry_detail.php' );
212 212
 
213
-        $this->setup_vars();
213
+		$this->setup_vars();
214 214
 
215
-        // Multiple Views embedded, don't proceed if nonce fails
216
-        if( $gv_data->has_multiple_views() && ! wp_verify_nonce( $_GET['edit'], self::$nonce_key ) ) {
217
-            return;
218
-        }
215
+		// Multiple Views embedded, don't proceed if nonce fails
216
+		if( $gv_data->has_multiple_views() && ! wp_verify_nonce( $_GET['edit'], self::$nonce_key ) ) {
217
+			return;
218
+		}
219 219
 
220
-        // Sorry, you're not allowed here.
221
-        if( false === $this->user_can_edit_entry( true ) ) {
222
-            return;
223
-        }
220
+		// Sorry, you're not allowed here.
221
+		if( false === $this->user_can_edit_entry( true ) ) {
222
+			return;
223
+		}
224 224
 
225
-        $this->print_scripts();
225
+		$this->print_scripts();
226 226
 
227
-        $this->process_save();
227
+		$this->process_save();
228 228
 
229
-        $this->edit_entry_form();
229
+		$this->edit_entry_form();
230 230
 
231
-    }
231
+	}
232 232
 
233 233
 
234
-    /**
235
-     * Force Gravity Forms to output scripts as if it were in the admin
236
-     * @return void
237
-     */
238
-    function print_scripts() {
239
-        $gravityview_view = GravityView_View::getInstance();
234
+	/**
235
+	 * Force Gravity Forms to output scripts as if it were in the admin
236
+	 * @return void
237
+	 */
238
+	function print_scripts() {
239
+		$gravityview_view = GravityView_View::getInstance();
240 240
 
241
-        wp_register_script( 'gform_gravityforms', GFCommon::get_base_url().'/js/gravityforms.js', array( 'jquery', 'gform_json', 'gform_placeholder', 'sack', 'plupload-all', 'gravityview-fe-view' ) );
241
+		wp_register_script( 'gform_gravityforms', GFCommon::get_base_url().'/js/gravityforms.js', array( 'jquery', 'gform_json', 'gform_placeholder', 'sack', 'plupload-all', 'gravityview-fe-view' ) );
242 242
 
243
-        GFFormDisplay::enqueue_form_scripts($gravityview_view->getForm(), false);
243
+		GFFormDisplay::enqueue_form_scripts($gravityview_view->getForm(), false);
244 244
 
245
-        // Sack is required for images
246
-        wp_print_scripts( array( 'sack', 'gform_gravityforms' ) );
247
-    }
245
+		// Sack is required for images
246
+		wp_print_scripts( array( 'sack', 'gform_gravityforms' ) );
247
+	}
248 248
 
249 249
 
250
-    /**
251
-     * Process edit entry form save
252
-     */
253
-    function process_save() {
250
+	/**
251
+	 * Process edit entry form save
252
+	 */
253
+	function process_save() {
254 254
 
255
-        if( empty( $_POST ) ) {
256
-            return;
257
-        }
255
+		if( empty( $_POST ) ) {
256
+			return;
257
+		}
258 258
 
259
-        // Make sure the entry, view, and form IDs are all correct
260
-        $valid = $this->verify_nonce();
259
+		// Make sure the entry, view, and form IDs are all correct
260
+		$valid = $this->verify_nonce();
261 261
 
262
-        if( !$valid ) {
263
-            do_action('gravityview_log_error', __METHOD__ . ' Nonce validation failed.' );
264
-            return;
265
-        }
262
+		if( !$valid ) {
263
+			do_action('gravityview_log_error', __METHOD__ . ' Nonce validation failed.' );
264
+			return;
265
+		}
266 266
 
267
-        if( $this->entry['id'] !== $_POST['lid'] ) {
268
-            do_action('gravityview_log_error', __METHOD__ . ' Entry ID did not match posted entry ID.' );
269
-            return;
270
-        }
267
+		if( $this->entry['id'] !== $_POST['lid'] ) {
268
+			do_action('gravityview_log_error', __METHOD__ . ' Entry ID did not match posted entry ID.' );
269
+			return;
270
+		}
271 271
 
272
-        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) );
272
+		do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) );
273 273
 
274
-        $this->process_save_process_files( $this->form_id );
274
+		$this->process_save_process_files( $this->form_id );
275 275
 
276
-        $this->validate();
276
+		$this->validate();
277 277
 
278
-        if( $this->is_valid ) {
278
+		if( $this->is_valid ) {
279 279
 
280
-            do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] Submission is valid.' );
280
+			do_action('gravityview_log_debug', 'GravityView_Edit_Entry[process_save] Submission is valid.' );
281 281
 
282
-            /**
283
-             * @hack This step is needed to unset the adminOnly from form fields
284
-             */
285
-            $form = $this->form_prepare_for_save();
282
+			/**
283
+			 * @hack This step is needed to unset the adminOnly from form fields
284
+			 */
285
+			$form = $this->form_prepare_for_save();
286 286
 
287
-            /**
288
-             * @hack to avoid the capability validation of the method save_lead for GF 1.9+
289
-             */
290
-            unset( $_GET['page'] );
287
+			/**
288
+			 * @hack to avoid the capability validation of the method save_lead for GF 1.9+
289
+			 */
290
+			unset( $_GET['page'] );
291 291
 
292
-            GFFormsModel::save_lead( $form, $this->entry );
292
+			GFFormsModel::save_lead( $form, $this->entry );
293 293
 
294
-            // If there's a post associated with the entry, process post fields
295
-            if( !empty( $this->entry['post_id'] ) ) {
296
-                $this->maybe_update_post_fields( $form );
297
-            }
294
+			// If there's a post associated with the entry, process post fields
295
+			if( !empty( $this->entry['post_id'] ) ) {
296
+				$this->maybe_update_post_fields( $form );
297
+			}
298 298
 
299
-            // Perform actions normally performed after updating a lead
300
-            $this->after_update();
299
+			// Perform actions normally performed after updating a lead
300
+			$this->after_update();
301 301
 
302
-            /**
303
-             * @action `gravityview/edit_entry/after_update` Perform an action after the entry has been updated using Edit Entry
304
-             * @param array $form Gravity Forms form array
305
-             * @param string $entry_id Numeric ID of the entry that was updated
306
-             */
307
-            do_action( 'gravityview/edit_entry/after_update', $this->form, $this->entry['id'] );
308
-        }
302
+			/**
303
+			 * @action `gravityview/edit_entry/after_update` Perform an action after the entry has been updated using Edit Entry
304
+			 * @param array $form Gravity Forms form array
305
+			 * @param string $entry_id Numeric ID of the entry that was updated
306
+			 */
307
+			do_action( 'gravityview/edit_entry/after_update', $this->form, $this->entry['id'] );
308
+		}
309 309
 
310
-    } // process_save
310
+	} // process_save
311 311
 
312 312
 
313
-    /**
314
-     * Have GF handle file uploads
315
-     *
316
-     * Copy of code from GFFormDisplay::process_form()
317
-     *
318
-     * @param int $form_id
319
-     */
320
-    function process_save_process_files( $form_id ) {
313
+	/**
314
+	 * Have GF handle file uploads
315
+	 *
316
+	 * Copy of code from GFFormDisplay::process_form()
317
+	 *
318
+	 * @param int $form_id
319
+	 */
320
+	function process_save_process_files( $form_id ) {
321 321
 
322
-        //Loading files that have been uploaded to temp folder
323
-        $files = GFCommon::json_decode( stripslashes( RGForms::post( 'gform_uploaded_files' ) ) );
324
-        if ( ! is_array( $files ) ) {
325
-            $files = array();
326
-        }
322
+		//Loading files that have been uploaded to temp folder
323
+		$files = GFCommon::json_decode( stripslashes( RGForms::post( 'gform_uploaded_files' ) ) );
324
+		if ( ! is_array( $files ) ) {
325
+			$files = array();
326
+		}
327 327
 
328
-        RGFormsModel::$uploaded_files[ $form_id ] = $files;
329
-    }
328
+		RGFormsModel::$uploaded_files[ $form_id ] = $files;
329
+	}
330 330
 
331
-    /**
332
-     * Remove max_files validation (done on gravityforms.js) to avoid conflicts with GravityView
333
-     * Late validation done on self::custom_validation
334
-     *
335
-     * @param $plupload_init array Plupload settings
336
-     * @param $form_id
337
-     * @param $instance
338
-     * @return mixed
339
-     */
340
-    public function modify_fileupload_settings( $plupload_init, $form_id, $instance ) {
341
-        if( ! $this->is_edit_entry() ) {
342
-            return $plupload_init;
343
-        }
331
+	/**
332
+	 * Remove max_files validation (done on gravityforms.js) to avoid conflicts with GravityView
333
+	 * Late validation done on self::custom_validation
334
+	 *
335
+	 * @param $plupload_init array Plupload settings
336
+	 * @param $form_id
337
+	 * @param $instance
338
+	 * @return mixed
339
+	 */
340
+	public function modify_fileupload_settings( $plupload_init, $form_id, $instance ) {
341
+		if( ! $this->is_edit_entry() ) {
342
+			return $plupload_init;
343
+		}
344 344
 
345
-        $plupload_init['gf_vars']['max_files'] = 0;
345
+		$plupload_init['gf_vars']['max_files'] = 0;
346 346
 
347
-        return $plupload_init;
348
-    }
347
+		return $plupload_init;
348
+	}
349 349
 
350 350
 
351
-    /**
352
-     * Unset adminOnly and convert field input key to string
353
-     * @return array $form
354
-     */
355
-    private function form_prepare_for_save() {
356
-        $form = $this->form;
357
-
358
-        // add the fields with calculation properties so they could be recalculated
359
-        $form['fields'] = array_merge( $form['fields'], $this->fields_with_calculation );
351
+	/**
352
+	 * Unset adminOnly and convert field input key to string
353
+	 * @return array $form
354
+	 */
355
+	private function form_prepare_for_save() {
356
+		$form = $this->form;
360 357
 
361
-        foreach( $form['fields'] as &$field ) {
358
+		// add the fields with calculation properties so they could be recalculated
359
+		$form['fields'] = array_merge( $form['fields'], $this->fields_with_calculation );
362 360
 
363
-            $field->adminOnly = false;
361
+		foreach( $form['fields'] as &$field ) {
364 362
 
365
-            if( isset( $field->inputs ) && is_array( $field->inputs ) ) {
366
-                foreach( $field->inputs as $key => $input ) {
367
-                    $field->inputs[ $key ][ 'id' ] = (string)$input['id'];
368
-                }
369
-            }
370
-        }
363
+			$field->adminOnly = false;
371 364
 
372
-        return $form;
373
-    }
365
+			if( isset( $field->inputs ) && is_array( $field->inputs ) ) {
366
+				foreach( $field->inputs as $key => $input ) {
367
+					$field->inputs[ $key ][ 'id' ] = (string)$input['id'];
368
+				}
369
+			}
370
+		}
374 371
 
372
+		return $form;
373
+	}
375 374
 
376
-    /**
377
-     * Loop through the fields being edited and if they include Post fields, update the Entry's post object
378
-     *
379
-     * @param array $form Gravity Forms form
380
-     *
381
-     * @return void
382
-     */
383
-    function maybe_update_post_fields( $form ) {
384 375
 
385
-        $post_id = $this->entry['post_id'];
376
+	/**
377
+	 * Loop through the fields being edited and if they include Post fields, update the Entry's post object
378
+	 *
379
+	 * @param array $form Gravity Forms form
380
+	 *
381
+	 * @return void
382
+	 */
383
+	function maybe_update_post_fields( $form ) {
386 384
 
387
-        // Security check
388
-        if( false === GVCommon::has_cap( 'edit_post', $post_id ) ) {
389
-            do_action( 'gravityview_log_error', 'The current user does not have the ability to edit Post #'.$post_id );
390
-            return;
391
-        }
385
+		$post_id = $this->entry['post_id'];
392 386
 
393
-        $update_entry = false;
387
+		// Security check
388
+		if( false === GVCommon::has_cap( 'edit_post', $post_id ) ) {
389
+			do_action( 'gravityview_log_error', 'The current user does not have the ability to edit Post #'.$post_id );
390
+			return;
391
+		}
394 392
 
395
-        $updated_post = $original_post = get_post( $post_id );
393
+		$update_entry = false;
396 394
 
397
-        foreach ( $this->entry as $field_id => $value ) {
395
+		$updated_post = $original_post = get_post( $post_id );
398 396
 
399
-            //todo: only run through the edit entry configured fields
397
+		foreach ( $this->entry as $field_id => $value ) {
400 398
 
401
-            $field = RGFormsModel::get_field( $form, $field_id );
399
+			//todo: only run through the edit entry configured fields
402 400
 
403
-            if( class_exists('GF_Fields') ) {
404
-                $field = GF_Fields::create( $field );
405
-            }
401
+			$field = RGFormsModel::get_field( $form, $field_id );
406 402
 
407
-            if( GFCommon::is_post_field( $field ) ) {
403
+			if( class_exists('GF_Fields') ) {
404
+				$field = GF_Fields::create( $field );
405
+			}
408 406
 
409
-                // Get the value of the field, including $_POSTed value
410
-                $value = RGFormsModel::get_field_value( $field );
407
+			if( GFCommon::is_post_field( $field ) ) {
411 408
 
412
-                switch( $field->type ) {
413
-
414
-                    case 'post_title':
415
-                    case 'post_content':
416
-                    case 'post_excerpt':
417
-                        $updated_post->{$field->type} = $value;
418
-                        break;
419
-                    case 'post_tags':
420
-                        wp_set_post_tags( $post_id, $value, false );
421
-                        break;
422
-                    case 'post_category':
409
+				// Get the value of the field, including $_POSTed value
410
+				$value = RGFormsModel::get_field_value( $field );
423 411
 
424
-                        $categories = is_array( $value ) ? array_values( $value ) : (array)$value;
425
-                        $categories = array_filter( $categories );
412
+				switch( $field->type ) {
426 413
 
427
-                        wp_set_post_categories( $post_id, $categories, false );
414
+					case 'post_title':
415
+					case 'post_content':
416
+					case 'post_excerpt':
417
+						$updated_post->{$field->type} = $value;
418
+						break;
419
+					case 'post_tags':
420
+						wp_set_post_tags( $post_id, $value, false );
421
+						break;
422
+					case 'post_category':
428 423
 
429
-                        // if post_category is type checkbox, then value is an array of inputs
430
-                        if( isset( $value[ strval( $field_id ) ] ) ) {
431
-                            foreach( $value as $input_id => $val ) {
432
-                                $input_name = 'input_' . str_replace( '.', '_', $input_id );
433
-                                $this->entry[ strval( $input_id ) ] = RGFormsModel::prepare_value( $form, $field, $val, $input_name, $this->entry['id'] );
434
-                            }
435
-                        } else {
436
-                            $input_name = 'input_' . str_replace( '.', '_', $field_id );
437
-                            $this->entry[ strval( $field_id ) ] = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $this->entry['id'] );
438
-                        }
424
+						$categories = is_array( $value ) ? array_values( $value ) : (array)$value;
425
+						$categories = array_filter( $categories );
439 426
 
440
-                        break;
441
-                    case 'post_custom_field':
427
+						wp_set_post_categories( $post_id, $categories, false );
442 428
 
443
-                        $input_type = RGFormsModel::get_input_type( $field );
444
-                        $custom_field_name = $field->postCustomFieldName;
429
+						// if post_category is type checkbox, then value is an array of inputs
430
+						if( isset( $value[ strval( $field_id ) ] ) ) {
431
+							foreach( $value as $input_id => $val ) {
432
+								$input_name = 'input_' . str_replace( '.', '_', $input_id );
433
+								$this->entry[ strval( $input_id ) ] = RGFormsModel::prepare_value( $form, $field, $val, $input_name, $this->entry['id'] );
434
+							}
435
+						} else {
436
+							$input_name = 'input_' . str_replace( '.', '_', $field_id );
437
+							$this->entry[ strval( $field_id ) ] = RGFormsModel::prepare_value( $form, $field, $value, $input_name, $this->entry['id'] );
438
+						}
445 439
 
446
-                        // Only certain custom field types are supported
447
-                        switch( $input_type ) {
448
-                            case 'fileupload':
449
-                            /** @noinspection PhpMissingBreakStatementInspection */
450
-                            case 'list':
451
-                                if( ! is_string( $value ) ) {
452
-                                    $value = function_exists('wp_json_encode') ? wp_json_encode( $value ) : json_encode( $value );
453
-                                }
454
-                            // break; left intentionally out
455
-                            default:
456
-                                update_post_meta( $post_id, $custom_field_name, $value );
457
-                        }
440
+						break;
441
+					case 'post_custom_field':
458 442
 
459
-                        break;
443
+						$input_type = RGFormsModel::get_input_type( $field );
444
+						$custom_field_name = $field->postCustomFieldName;
460 445
 
461
-                    case 'post_image':
446
+						// Only certain custom field types are supported
447
+						switch( $input_type ) {
448
+							case 'fileupload':
449
+							/** @noinspection PhpMissingBreakStatementInspection */
450
+							case 'list':
451
+								if( ! is_string( $value ) ) {
452
+									$value = function_exists('wp_json_encode') ? wp_json_encode( $value ) : json_encode( $value );
453
+								}
454
+							// break; left intentionally out
455
+							default:
456
+								update_post_meta( $post_id, $custom_field_name, $value );
457
+						}
462 458
 
463
-                        $value = '';
464
-                        break;
459
+						break;
465 460
 
466
-                }
461
+					case 'post_image':
467 462
 
468
-                //ignore fields that have not changed
469
-                if ( $value === rgget( (string) $field_id, $this->entry ) ) {
470
-                    continue;
471
-                }
463
+						$value = '';
464
+						break;
472 465
 
473
-                // update entry
474
-                if( 'post_category' !== $field->type ) {
475
-                    $this->entry[ strval( $field_id ) ] = $value;
476
-                }
466
+				}
477 467
 
478
-                $update_entry = true;
468
+				//ignore fields that have not changed
469
+				if ( $value === rgget( (string) $field_id, $this->entry ) ) {
470
+					continue;
471
+				}
479 472
 
480
-            }
473
+				// update entry
474
+				if( 'post_category' !== $field->type ) {
475
+					$this->entry[ strval( $field_id ) ] = $value;
476
+				}
481 477
 
482
-        }
478
+				$update_entry = true;
483 479
 
484
-        if( $update_entry ) {
480
+			}
485 481
 
486
-            $return_entry = GFAPI::update_entry( $this->entry );
482
+		}
487 483
 
488
-            if( is_wp_error( $return_entry ) ) {
489
-                do_action( 'gravityview_log_error', 'Updating the entry post fields failed', $return_entry );
490
-            } else {
491
-                do_action( 'gravityview_log_debug', 'Updating the entry post fields for post #'.$post_id.' succeeded' );
492
-            }
484
+		if( $update_entry ) {
493 485
 
494
-        }
486
+			$return_entry = GFAPI::update_entry( $this->entry );
495 487
 
496
-        $return_post = wp_update_post( $updated_post, true );
488
+			if( is_wp_error( $return_entry ) ) {
489
+				do_action( 'gravityview_log_error', 'Updating the entry post fields failed', $return_entry );
490
+			} else {
491
+				do_action( 'gravityview_log_debug', 'Updating the entry post fields for post #'.$post_id.' succeeded' );
492
+			}
497 493
 
498
-        if( is_wp_error( $return_post ) ) {
499
-            $return_post->add_data( $updated_post, '$updated_post' );
500
-            do_action( 'gravityview_log_error', 'Updating the post content failed', $return_post );
501
-        } else {
502
-            do_action( 'gravityview_log_debug', 'Updating the post content for post #'.$post_id.' succeeded', $updated_post );
503
-        }
494
+		}
504 495
 
505
-    }
496
+		$return_post = wp_update_post( $updated_post, true );
506 497
 
507
-    /**
508
-     * Perform actions normally performed after updating a lead
509
-     *
510
-     * @since 1.8
511
-     *
512
-     * @see GFEntryDetail::lead_detail_page()
513
-     *
514
-     * @return void
515
-     */
516
-    function after_update() {
498
+		if( is_wp_error( $return_post ) ) {
499
+			$return_post->add_data( $updated_post, '$updated_post' );
500
+			do_action( 'gravityview_log_error', 'Updating the post content failed', $return_post );
501
+		} else {
502
+			do_action( 'gravityview_log_debug', 'Updating the post content for post #'.$post_id.' succeeded', $updated_post );
503
+		}
517 504
 
518
-        do_action( 'gform_after_update_entry', $this->form, $this->entry['id'] );
519
-        do_action( "gform_after_update_entry_{$this->form['id']}", $this->form, $this->entry['id'] );
505
+	}
520 506
 
521
-        // Re-define the entry now that we've updated it.
522
-        $entry = RGFormsModel::get_lead( $this->entry['id'] );
507
+	/**
508
+	 * Perform actions normally performed after updating a lead
509
+	 *
510
+	 * @since 1.8
511
+	 *
512
+	 * @see GFEntryDetail::lead_detail_page()
513
+	 *
514
+	 * @return void
515
+	 */
516
+	function after_update() {
523 517
 
524
-        $entry = GFFormsModel::set_entry_meta( $entry, $this->form );
518
+		do_action( 'gform_after_update_entry', $this->form, $this->entry['id'] );
519
+		do_action( "gform_after_update_entry_{$this->form['id']}", $this->form, $this->entry['id'] );
525 520
 
526
-        // We need to clear the cache because Gravity Forms caches the field values, which
527
-        // we have just updated.
528
-        foreach ($this->form['fields'] as $key => $field) {
529
-            GFFormsModel::refresh_lead_field_value( $entry['id'], $field->id );
530
-        }
521
+		// Re-define the entry now that we've updated it.
522
+		$entry = RGFormsModel::get_lead( $this->entry['id'] );
531 523
 
532
-        $this->entry = $entry;
533
-    }
524
+		$entry = GFFormsModel::set_entry_meta( $entry, $this->form );
534 525
 
526
+		// We need to clear the cache because Gravity Forms caches the field values, which
527
+		// we have just updated.
528
+		foreach ($this->form['fields'] as $key => $field) {
529
+			GFFormsModel::refresh_lead_field_value( $entry['id'], $field->id );
530
+		}
535 531
 
536
-    /**
537
-     * Display the Edit Entry form
538
-     *
539
-     * @return [type] [description]
540
-     */
541
-    public function edit_entry_form() {
532
+		$this->entry = $entry;
533
+	}
542 534
 
543
-        ?>
535
+
536
+	/**
537
+	 * Display the Edit Entry form
538
+	 *
539
+	 * @return [type] [description]
540
+	 */
541
+	public function edit_entry_form() {
542
+
543
+		?>
544 544
 
545 545
         <div class="gv-edit-entry-wrapper"><?php
546 546
 
547
-            $javascript = gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/inline-javascript.php', $this );
547
+			$javascript = gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/inline-javascript.php', $this );
548 548
 
549
-            /**
550
-             * Fixes weird wpautop() issue
551
-             * @see https://github.com/katzwebservices/GravityView/issues/451
552
-             */
553
-            echo gravityview_strip_whitespace( $javascript );
549
+			/**
550
+			 * Fixes weird wpautop() issue
551
+			 * @see https://github.com/katzwebservices/GravityView/issues/451
552
+			 */
553
+			echo gravityview_strip_whitespace( $javascript );
554 554
 
555
-            ?><h2 class="gv-edit-entry-title">
555
+			?><h2 class="gv-edit-entry-title">
556 556
                 <span><?php
557 557
 
558
-                    /**
559
-                     * @filter `gravityview_edit_entry_title` Modify the edit entry title
560
-                     * @param string $edit_entry_title Modify the "Edit Entry" title
561
-                     * @param GravityView_Edit_Entry_Render $this This object
562
-                     */
563
-                    $edit_entry_title = apply_filters('gravityview_edit_entry_title', __('Edit Entry', 'gravityview'), $this );
558
+					/**
559
+					 * @filter `gravityview_edit_entry_title` Modify the edit entry title
560
+					 * @param string $edit_entry_title Modify the "Edit Entry" title
561
+					 * @param GravityView_Edit_Entry_Render $this This object
562
+					 */
563
+					$edit_entry_title = apply_filters('gravityview_edit_entry_title', __('Edit Entry', 'gravityview'), $this );
564 564
 
565
-                    echo esc_attr( $edit_entry_title );
566
-            ?></span>
565
+					echo esc_attr( $edit_entry_title );
566
+			?></span>
567 567
             </h2>
568 568
 
569 569
             <?php $this->maybe_print_message(); ?>
@@ -574,664 +574,664 @@  discard block
 block discarded – undo
574 574
 
575 575
                 <?php
576 576
 
577
-                wp_nonce_field( self::$nonce_key, self::$nonce_key );
577
+				wp_nonce_field( self::$nonce_key, self::$nonce_key );
578 578
 
579
-                wp_nonce_field( self::$nonce_field, self::$nonce_field, false );
579
+				wp_nonce_field( self::$nonce_field, self::$nonce_field, false );
580 580
 
581
-                // Print the actual form HTML
582
-                $this->render_edit_form();
581
+				// Print the actual form HTML
582
+				$this->render_edit_form();
583 583
 
584
-                ?>
584
+				?>
585 585
             </form>
586 586
 
587 587
         </div>
588 588
 
589 589
     <?php
590
-    }
591
-
592
-    /**
593
-     * Display success or error message if the form has been submitted
594
-     *
595
-     * @uses GVCommon::generate_notice
596
-     *
597
-     * @since TODO
598
-     *
599
-     * @return void
600
-     */
601
-    private function maybe_print_message() {
602
-
603
-        if( rgpost('action') === 'update' ) {
604
-
605
-            $back_link = esc_url( remove_query_arg( array( 'page', 'view', 'edit' ) ) );
606
-
607
-            if( ! $this->is_valid ){
608
-
609
-                // Keeping this compatible with Gravity Forms.
610
-                $validation_message = "<div class='validation_error'>" . __('There was a problem with your submission.', 'gravityview') . " " . __('Errors have been highlighted below.', 'gravityview') . "</div>";
611
-                $message = apply_filters("gform_validation_message_{$this->form['id']}", apply_filters("gform_validation_message", $validation_message, $this->form), $this->form);
612
-
613
-                echo GVCommon::generate_notice( $message , 'gv-error' );
614
-
615
-            } else {
616
-                $entry_updated_message = sprintf( esc_attr__('Entry Updated. %sReturn to Entry%s', 'gravityview'), '<a href="'. $back_link .'">', '</a>' );
617
-
618
-                /**
619
-                 * @filter `gravityview/edit_entry/success` Modify the edit entry success message (including the anchor link)
620
-                 * @since 1.5.4
621
-                 * @param string $entry_updated_message Existing message
622
-                 * @param int $view_id View ID
623
-                 * @param array $entry Gravity Forms entry array
624
-                 * @param string $back_link URL to return to the original entry. @since 1.6
625
-                 */
626
-                $message = apply_filters( 'gravityview/edit_entry/success', $entry_updated_message , $this->view_id, $this->entry, $back_link );
627
-
628
-                echo GVCommon::generate_notice( $message );
629
-            }
630
-
631
-        }
632
-    }
633
-
634
-    /**
635
-     * Display the Edit Entry form in the original Gravity Forms format
636
-     *
637
-     * @since 1.9
638
-     *
639
-     * @param $form
640
-     * @param $lead
641
-     * @param $view_id
642
-     *
643
-     * @return void
644
-     */
645
-    private function render_edit_form() {
646
-
647
-        add_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields'), 5000, 3 );
648
-        add_filter( 'gform_submit_button', array( $this, 'render_form_buttons') );
649
-        add_filter( 'gform_disable_view_counter', '__return_true' );
650
-
651
-        add_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5, 5 );
652
-        add_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10, 5 );
653
-
654
-        // We need to remove the fake $_GET['page'] arg to avoid rendering form as if in admin.
655
-        unset( $_GET['page'] );
656
-
657
-        // TODO: Make sure validation isn't handled by GF
658
-        // TODO: Include CSS for file upload fields
659
-        // TODO: Verify multiple-page forms
660
-        // TODO: Product fields are not editable
661
-        // TODO: Check Updated and Error messages
662
-
663
-        $html = GFFormDisplay::get_form( $this->form['id'], false, false, true, $this->entry );
664
-
665
-	    remove_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields' ), 5000 );
666
-        remove_filter( 'gform_submit_button', array( $this, 'render_form_buttons' ) );
667
-        remove_filter( 'gform_disable_view_counter', '__return_true' );
668
-        remove_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5 );
669
-        remove_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10 );
670
-
671
-        echo $html;
672
-    }
673
-
674
-    /**
675
-     * Display the Update/Cancel/Delete buttons for the Edit Entry form
676
-     * @since 1.8
677
-     * @return string
678
-     */
679
-    public function render_form_buttons() {
680
-        return gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/form-buttons.php', $this );
681
-    }
682
-
683
-
684
-    /**
685
-     * Modify the form fields that are shown when using GFFormDisplay::get_form()
686
-     *
687
-     * By default, all fields will be shown. We only want the Edit Tab configured fields to be shown.
688
-     *
689
-     * @param array $form
690
-     * @param boolean $ajax Whether in AJAX mode
691
-     * @param array|string $field_values Passed parameters to the form
692
-     *
693
-     * @since 1.9
694
-     *
695
-     * @return array Modified form array
696
-     */
697
-    public function filter_modify_form_fields( $form, $ajax = false, $field_values = '' ) {
698
-
699
-        // In case we have validated the form, use it to inject the validation results into the form render
700
-        if( isset( $this->form_after_validation ) ) {
701
-            $form = $this->form_after_validation;
702
-        } else {
703
-            $form['fields'] = $this->get_configured_edit_fields( $form, $this->view_id );
704
-        }
705
-
706
-        $form = $this->filter_conditional_logic( $form );
707
-
708
-        // for now we don't support Save and Continue feature.
709
-        if( ! self::$supports_save_and_continue ) {
710
-	        unset( $form['save'] );
711
-        }
712
-
713
-        return $form;
714
-    }
715
-
716
-    /**
717
-     * 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.
718
-     *
719
-     * @since TODO
720
-     *
721
-     * @param string $field_content Always empty. Returning not-empty overrides the input.
722
-     * @param GF_Field $field
723
-     * @param string|array $value If array, it's a field with multiple inputs. If string, single input.
724
-     * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter.
725
-     * @param int $form_id Form ID
726
-     *
727
-     * @return string If error, the error message. If no error, blank string (modify_edit_field_input() runs next)
728
-     */
729
-    function verify_user_can_edit_post( $field_content = '', $field, $value, $lead_id = 0, $form_id ) {
730
-
731
-        if( GFCommon::is_post_field( $field ) ) {
732
-
733
-            $message = null;
734
-
735
-            // First, make sure they have the capability to edit the post.
736
-            if( false === current_user_can( 'edit_post', $this->entry['post_id'] ) ) {
737
-
738
-                /**
739
-                 * @filter `gravityview/edit_entry/unsupported_post_field_text` Modify the message when someone isn't able to edit a post
740
-                 * @param string $message The existing "You don't have permission..." text
741
-                 */
742
-                $message = apply_filters('gravityview/edit_entry/unsupported_post_field_text', __('You don&rsquo;t have permission to edit this post.', 'gravityview') );
743
-
744
-            } elseif( null === get_post( $this->entry['post_id'] ) ) {
745
-                /**
746
-                 * @filter `gravityview/edit_entry/no_post_text` Modify the message when someone is editing an entry attached to a post that no longer exists
747
-                 * @param string $message The existing "This field is not editable; the post no longer exists." text
748
-                 */
749
-                $message = apply_filters('gravityview/edit_entry/no_post_text', __('This field is not editable; the post no longer exists.', 'gravityview' ) );
750
-            }
751
-
752
-            if( $message ) {
753
-                $field_content = sprintf('<div class="ginput_container ginput_container_' . $field->type . '">%s</div>', wpautop( $message ) );
754
-            }
755
-        }
756
-
757
-        return $field_content;
758
-    }
759
-
760
-    /**
761
-     *
762
-     * Fill-in the saved values into the form inputs
763
-     *
764
-     * @param string $field_content Always empty. Returning not-empty overrides the input.
765
-     * @param GF_Field $field
766
-     * @param string|array $value If array, it's a field with multiple inputs. If string, single input.
767
-     * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter.
768
-     * @param int $form_id Form ID
769
-     *
770
-     * @return mixed
771
-     */
772
-    function modify_edit_field_input( $field_content = '', $field, $value, $lead_id = 0, $form_id ) {
773
-
774
-        $gv_field = GravityView_Fields::get_associated_field( $field );
775
-
776
-        // If the form has been submitted, then we don't need to pre-fill the values,
777
-        // Except for fileupload type and when a field input is overridden- run always!!
778
-        if(
779
-            ( $this->is_edit_entry_submission() && 'fileupload' !== $field->type )
780
-            && false === ( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) )
781
-            || ! empty( $field_content )
782
-            || GFCommon::is_product_field( $field->type ) // Prevent product fields from appearing editable
783
-        ) {
784
-	        return $field_content;
785
-        }
786
-
787
-        // Turn on Admin-style display for file upload fields only
788
-        if( 'fileupload' === $field->type ) {
789
-            $_GET['page'] = 'gf_entries';
790
-        }
791
-
792
-        // SET SOME FIELD DEFAULTS TO PREVENT ISSUES
793
-        $field->adminOnly = false; /** @see GFFormDisplay::get_counter_init_script() need to prevent adminOnly */
794
-
795
-        // add categories as choices for Post Category field
796
-        if ( 'post_category' === $field->type ) {
797
-            $field = GFCommon::add_categories_as_choices( $field, $value );
798
-        }
799
-
800
-        $field_value = $this->get_field_value( $field );
801
-
802
-        /**
803
-         * @filter `gravityview/edit_entry/field_value` Change the value of an Edit Entry field, if needed
804
-         * @since 1.11
805
-         * @param mixed $field_value field value used to populate the input
806
-         * @param object $field Gravity Forms field object ( Class GF_Field )
807
-         */
808
-        $field_value = apply_filters( 'gravityview/edit_entry/field_value', $field_value, $field );
809
-
810
-	    // Prevent any PHP warnings, like undefined index
811
-	    ob_start();
812
-
813
-        if( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) ) {
814
-            $return = $gv_field->get_field_input( $this->form, $field_value, $this->entry, $field );
815
-        } else {
816
-	        $return = $field->get_field_input( $this->form, $field_value, $this->entry );
817
-        }
818
-
819
-	    // If there was output, it's an error
820
-	    $warnings = ob_get_clean();
821
-
822
-	    if( !empty( $warnings ) ) {
823
-		    do_action( 'gravityview_log_error', __METHOD__ . $warnings, $field_value );
824
-	    }
825
-
826
-        /**
827
-         * Unset hack $_GET['page'] = 'gf_entries'
828
-         * We need the fileupload html field to render with the proper id
829
-         *  ( <li id="field_80_16" ... > )
830
-         */
831
-        unset( $_GET['page'] );
832
-
833
-        return $return;
834
-    }
835
-
836
-    /**
837
-     * Modify the value for the current field input
838
-     *
839
-     * @param GF_Field $field
840
-     *
841
-     * @return array|mixed|string|void
842
-     */
843
-    private function get_field_value( $field ) {
844
-
845
-        /**
846
-         * @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.
847
-         * @param boolean True: override saved values; False: don't override (default)
848
-         * @param $field GF_Field object Gravity Forms field object
849
-         * @since 1.13
850
-         */
851
-        $override_saved_value = apply_filters( 'gravityview/edit_entry/pre_populate/override', false, $field );
852
-
853
-        // We're dealing with multiple inputs (e.g. checkbox) but not time or date (as it doesn't store data in input IDs)
854
-        if( isset( $field->inputs ) && is_array( $field->inputs ) && !in_array( $field->type, array( 'time', 'date' ) ) ) {
855
-
856
-            $field_value = array();
857
-
858
-            // only accept pre-populated values if the field doesn't have any choice selected.
859
-            $allow_pre_populated = $field->allowsPrepopulate;
860
-
861
-            foreach ( (array)$field->inputs as $input ) {
862
-
863
-                $input_id = strval( $input['id'] );
864
-
865
-                if ( ! gv_empty( $this->entry[ $input_id ], false ) ) {
866
-                    $field_value[ $input_id ] =  'post_category' === $field->type ? GFCommon::format_post_category( $this->entry[ $input_id ], true ) : $this->entry[ $input_id ];
867
-                    $allow_pre_populated = false;
868
-                }
869
-
870
-            }
871
-
872
-            $pre_value = $field->get_value_submission( array(), false );
590
+	}
873 591
 
874
-            $field_value = ! $allow_pre_populated && ! ( $override_saved_value && !gv_empty( $pre_value, false ) ) ? $field_value : $pre_value;
875
-
876
-        } else {
877
-
878
-            $id = intval( $field->id );
879
-
880
-            // get pre-populated value if exists
881
-            $pre_value = $field->allowsPrepopulate ? GFFormsModel::get_parameter_value( $field->inputName, array(), $field ) : '';
592
+	/**
593
+	 * Display success or error message if the form has been submitted
594
+	 *
595
+	 * @uses GVCommon::generate_notice
596
+	 *
597
+	 * @since TODO
598
+	 *
599
+	 * @return void
600
+	 */
601
+	private function maybe_print_message() {
882 602
 
883
-            // saved field entry value (if empty, fallback to the pre-populated value, if exists)
884
-            // or pre-populated value if not empty and set to override saved value
885
-            $field_value = !gv_empty( $this->entry[ $id ], false ) && ! ( $override_saved_value && !gv_empty( $pre_value, false ) ) ? $this->entry[ $id ] : $pre_value;
603
+		if( rgpost('action') === 'update' ) {
886 604
 
887
-            // in case field is post_category but inputType is select, multi-select or radio, convert value into array of category IDs.
888
-            if ( 'post_category' === $field->type && !gv_empty( $field_value, false ) ) {
889
-                $categories = array();
890
-                foreach ( explode( ',', $field_value ) as $cat_string ) {
891
-                    $categories[] = GFCommon::format_post_category( $cat_string, true );
892
-                }
893
-                $field_value = 'multiselect' === $field->get_input_type() ? $categories : implode( '', $categories );
894
-            }
605
+			$back_link = esc_url( remove_query_arg( array( 'page', 'view', 'edit' ) ) );
895 606
 
896
-        }
607
+			if( ! $this->is_valid ){
897 608
 
898
-        // if value is empty get the default value if defined
899
-        $field_value = $field->get_value_default_if_empty( $field_value );
609
+				// Keeping this compatible with Gravity Forms.
610
+				$validation_message = "<div class='validation_error'>" . __('There was a problem with your submission.', 'gravityview') . " " . __('Errors have been highlighted below.', 'gravityview') . "</div>";
611
+				$message = apply_filters("gform_validation_message_{$this->form['id']}", apply_filters("gform_validation_message", $validation_message, $this->form), $this->form);
900 612
 
901
-        return $field_value;
902
-    }
613
+				echo GVCommon::generate_notice( $message , 'gv-error' );
903 614
 
615
+			} else {
616
+				$entry_updated_message = sprintf( esc_attr__('Entry Updated. %sReturn to Entry%s', 'gravityview'), '<a href="'. $back_link .'">', '</a>' );
904 617
 
905
-    // ---- Entry validation
618
+				/**
619
+				 * @filter `gravityview/edit_entry/success` Modify the edit entry success message (including the anchor link)
620
+				 * @since 1.5.4
621
+				 * @param string $entry_updated_message Existing message
622
+				 * @param int $view_id View ID
623
+				 * @param array $entry Gravity Forms entry array
624
+				 * @param string $back_link URL to return to the original entry. @since 1.6
625
+				 */
626
+				$message = apply_filters( 'gravityview/edit_entry/success', $entry_updated_message , $this->view_id, $this->entry, $back_link );
906 627
 
907
-    /**
908
-     * Add field keys that Gravity Forms expects.
909
-     *
910
-     * @see GFFormDisplay::validate()
911
-     * @param  array $form GF Form
912
-     * @return array       Modified GF Form
913
-     */
914
-    function gform_pre_validation( $form ) {
628
+				echo GVCommon::generate_notice( $message );
629
+			}
915 630
 
916
-        if( ! $this->verify_nonce() ) {
917
-            return $form;
918
-        }
631
+		}
632
+	}
919 633
 
920
-        // Fix PHP warning regarding undefined index.
921
-        foreach ( $form['fields'] as &$field) {
634
+	/**
635
+	 * Display the Edit Entry form in the original Gravity Forms format
636
+	 *
637
+	 * @since 1.9
638
+	 *
639
+	 * @param $form
640
+	 * @param $lead
641
+	 * @param $view_id
642
+	 *
643
+	 * @return void
644
+	 */
645
+	private function render_edit_form() {
922 646
 
923
-            // This is because we're doing admin form pretending to be front-end, so Gravity Forms
924
-            // expects certain field array items to be set.
925
-            foreach ( array( 'noDuplicates', 'adminOnly', 'inputType', 'isRequired', 'enablePrice', 'inputs', 'allowedExtensions' ) as $key ) {
926
-	            $field->{$key} = isset( $field->{$key} ) ? $field->{$key} : NULL;
927
-            }
647
+		add_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields'), 5000, 3 );
648
+		add_filter( 'gform_submit_button', array( $this, 'render_form_buttons') );
649
+		add_filter( 'gform_disable_view_counter', '__return_true' );
928 650
 
929
-            // unset emailConfirmEnabled for email type fields
930
-           /* if( 'email' === $field['type'] && !empty( $field['emailConfirmEnabled'] ) ) {
931
-                $field['emailConfirmEnabled'] = '';
932
-            }*/
651
+		add_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5, 5 );
652
+		add_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10, 5 );
933 653
 
934
-            switch( RGFormsModel::get_input_type( $field ) ) {
935
-
936
-                /**
937
-                 * 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.
938
-                 *
939
-                 * 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.
940
-                 *
941
-                 * @hack
942
-                 */
943
-                case 'fileupload':
944
-                case 'post_image':
945
-
946
-                    // Set the previous value
947
-                    $entry = $this->get_entry();
948
-
949
-                    $input_name = 'input_'.$field->id;
950
-                    $form_id = $form['id'];
654
+		// We need to remove the fake $_GET['page'] arg to avoid rendering form as if in admin.
655
+		unset( $_GET['page'] );
951 656
 
952
-                    $value = NULL;
657
+		// TODO: Make sure validation isn't handled by GF
658
+		// TODO: Include CSS for file upload fields
659
+		// TODO: Verify multiple-page forms
660
+		// TODO: Product fields are not editable
661
+		// TODO: Check Updated and Error messages
953 662
 
954
-                    // Use the previous entry value as the default.
955
-                    if( isset( $entry[ $field->id ] ) ) {
956
-                        $value = $entry[ $field->id ];
957
-                    }
958
-
959
-                    // If this is a single upload file
960
-                    if( !empty( $_FILES[ $input_name ] ) && !empty( $_FILES[ $input_name ]['name'] ) ) {
961
-                        $file_path = GFFormsModel::get_file_upload_path( $form['id'], $_FILES[ $input_name ]['name'] );
962
-                        $value = $file_path['url'];
963
-
964
-                    } else {
965
-
966
-                        // Fix PHP warning on line 1498 of form_display.php for post_image fields
967
-                        // Fix PHP Notice:  Undefined index:  size in form_display.php on line 1511
968
-                        $_FILES[ $input_name ] = array('name' => '', 'size' => '' );
969
-
970
-                    }
663
+		$html = GFFormDisplay::get_form( $this->form['id'], false, false, true, $this->entry );
971 664
 
972
-                    if( rgar($field, "multipleFiles") ) {
665
+		remove_filter( 'gform_pre_render', array( $this, 'filter_modify_form_fields' ), 5000 );
666
+		remove_filter( 'gform_submit_button', array( $this, 'render_form_buttons' ) );
667
+		remove_filter( 'gform_disable_view_counter', '__return_true' );
668
+		remove_filter( 'gform_field_input', array( $this, 'verify_user_can_edit_post' ), 5 );
669
+		remove_filter( 'gform_field_input', array( $this, 'modify_edit_field_input' ), 10 );
973 670
 
974
-                        // If there are fresh uploads, process and merge them.
975
-                        // Otherwise, use the passed values, which should be json-encoded array of URLs
976
-                        if( isset( GFFormsModel::$uploaded_files[$form_id][$input_name] ) ) {
977
-                            $value = empty( $value ) ? '[]' : $value;
978
-                            $value = stripslashes_deep( $value );
979
-                            $value = GFFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'], array());
980
-                        }
671
+		echo $html;
672
+	}
981 673
 
982
-                    } else {
674
+	/**
675
+	 * Display the Update/Cancel/Delete buttons for the Edit Entry form
676
+	 * @since 1.8
677
+	 * @return string
678
+	 */
679
+	public function render_form_buttons() {
680
+		return gravityview_ob_include( GravityView_Edit_Entry::$file .'/partials/form-buttons.php', $this );
681
+	}
983 682
 
984
-                        // A file already exists when editing an entry
985
-                        // We set this to solve issue when file upload fields are required.
986
-                        GFFormsModel::$uploaded_files[ $form_id ][ $input_name ] = $value;
987 683
 
988
-                    }
684
+	/**
685
+	 * Modify the form fields that are shown when using GFFormDisplay::get_form()
686
+	 *
687
+	 * By default, all fields will be shown. We only want the Edit Tab configured fields to be shown.
688
+	 *
689
+	 * @param array $form
690
+	 * @param boolean $ajax Whether in AJAX mode
691
+	 * @param array|string $field_values Passed parameters to the form
692
+	 *
693
+	 * @since 1.9
694
+	 *
695
+	 * @return array Modified form array
696
+	 */
697
+	public function filter_modify_form_fields( $form, $ajax = false, $field_values = '' ) {
989 698
 
990
-                    $this->entry[ $input_name ] = $value;
991
-                    $prepared_value = GFFormsModel::get_prepared_input_value( $form, $field, $entry, $field->id );
992
-                    $_POST[ $input_name ] = $value;
699
+		// In case we have validated the form, use it to inject the validation results into the form render
700
+		if( isset( $this->form_after_validation ) ) {
701
+			$form = $this->form_after_validation;
702
+		} else {
703
+			$form['fields'] = $this->get_configured_edit_fields( $form, $this->view_id );
704
+		}
993 705
 
994
-                    break;
995
-                case 'number':
996
-                    // Fix "undefined index" issue at line 1286 in form_display.php
997
-                    if( !isset( $_POST['input_'.$field->id ] ) ) {
998
-                        $_POST['input_'.$field->id ] = NULL;
999
-                    }
1000
-                    break;
1001
-                case 'captcha':
1002
-                    // Fix issue with recaptcha_check_answer() on line 1458 in form_display.php
1003
-                    $_POST['recaptcha_challenge_field'] = NULL;
1004
-                    $_POST['recaptcha_response_field'] = NULL;
1005
-                    break;
1006
-            }
706
+		$form = $this->filter_conditional_logic( $form );
1007 707
 
1008
-        }
708
+		// for now we don't support Save and Continue feature.
709
+		if( ! self::$supports_save_and_continue ) {
710
+			unset( $form['save'] );
711
+		}
1009 712
 
1010
-        return $form;
1011
-    }
713
+		return $form;
714
+	}
1012 715
 
716
+	/**
717
+	 * 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.
718
+	 *
719
+	 * @since TODO
720
+	 *
721
+	 * @param string $field_content Always empty. Returning not-empty overrides the input.
722
+	 * @param GF_Field $field
723
+	 * @param string|array $value If array, it's a field with multiple inputs. If string, single input.
724
+	 * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter.
725
+	 * @param int $form_id Form ID
726
+	 *
727
+	 * @return string If error, the error message. If no error, blank string (modify_edit_field_input() runs next)
728
+	 */
729
+	function verify_user_can_edit_post( $field_content = '', $field, $value, $lead_id = 0, $form_id ) {
1013 730
 
1014
-    /**
1015
-     * Process validation for a edit entry submission
1016
-     *
1017
-     * Sets the `is_valid` object var
1018
-     *
1019
-     * @return void
1020
-     */
1021
-    function validate() {
731
+		if( GFCommon::is_post_field( $field ) ) {
1022 732
 
1023
-        // If using GF User Registration Add-on, remove the validation step, otherwise generates error when updating the entry
1024
-        if ( class_exists( 'GFUser' ) ) {
1025
-            remove_filter( 'gform_validation', array( 'GFUser', 'user_registration_validation' ) );
1026
-        }
733
+			$message = null;
1027 734
 
1028
-        /**
1029
-         * For some crazy reason, Gravity Forms doesn't validate Edit Entry form submissions.
1030
-         * You can enter whatever you want!
1031
-         * We try validating, and customize the results using `self::custom_validation()`
1032
-         */
1033
-        add_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10, 4);
735
+			// First, make sure they have the capability to edit the post.
736
+			if( false === current_user_can( 'edit_post', $this->entry['post_id'] ) ) {
1034 737
 
1035
-        // Needed by the validate funtion
1036
-        $failed_validation_page = NULL;
1037
-        $field_values = RGForms::post( 'gform_field_values' );
738
+				/**
739
+				 * @filter `gravityview/edit_entry/unsupported_post_field_text` Modify the message when someone isn't able to edit a post
740
+				 * @param string $message The existing "You don't have permission..." text
741
+				 */
742
+				$message = apply_filters('gravityview/edit_entry/unsupported_post_field_text', __('You don&rsquo;t have permission to edit this post.', 'gravityview') );
1038 743
 
1039
-        // Prevent entry limit from running when editing an entry, also
1040
-        // prevent form scheduling from preventing editing
1041
-        unset( $this->form['limitEntries'], $this->form['scheduleForm'] );
744
+			} elseif( null === get_post( $this->entry['post_id'] ) ) {
745
+				/**
746
+				 * @filter `gravityview/edit_entry/no_post_text` Modify the message when someone is editing an entry attached to a post that no longer exists
747
+				 * @param string $message The existing "This field is not editable; the post no longer exists." text
748
+				 */
749
+				$message = apply_filters('gravityview/edit_entry/no_post_text', __('This field is not editable; the post no longer exists.', 'gravityview' ) );
750
+			}
1042 751
 
1043
-        // Hide fields depending on Edit Entry settings
1044
-        $this->form['fields'] = $this->get_configured_edit_fields( $this->form, $this->view_id );
752
+			if( $message ) {
753
+				$field_content = sprintf('<div class="ginput_container ginput_container_' . $field->type . '">%s</div>', wpautop( $message ) );
754
+			}
755
+		}
1045 756
 
1046
-        $this->is_valid = GFFormDisplay::validate( $this->form, $field_values, 1, $failed_validation_page );
757
+		return $field_content;
758
+	}
1047 759
 
1048
-        remove_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10 );
1049
-    }
760
+	/**
761
+	 *
762
+	 * Fill-in the saved values into the form inputs
763
+	 *
764
+	 * @param string $field_content Always empty. Returning not-empty overrides the input.
765
+	 * @param GF_Field $field
766
+	 * @param string|array $value If array, it's a field with multiple inputs. If string, single input.
767
+	 * @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter.
768
+	 * @param int $form_id Form ID
769
+	 *
770
+	 * @return mixed
771
+	 */
772
+	function modify_edit_field_input( $field_content = '', $field, $value, $lead_id = 0, $form_id ) {
773
+
774
+		$gv_field = GravityView_Fields::get_associated_field( $field );
775
+
776
+		// If the form has been submitted, then we don't need to pre-fill the values,
777
+		// Except for fileupload type and when a field input is overridden- run always!!
778
+		if(
779
+			( $this->is_edit_entry_submission() && 'fileupload' !== $field->type )
780
+			&& false === ( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) )
781
+			|| ! empty( $field_content )
782
+			|| GFCommon::is_product_field( $field->type ) // Prevent product fields from appearing editable
783
+		) {
784
+			return $field_content;
785
+		}
1050 786
 
787
+		// Turn on Admin-style display for file upload fields only
788
+		if( 'fileupload' === $field->type ) {
789
+			$_GET['page'] = 'gf_entries';
790
+		}
1051 791
 
1052
-    /**
1053
-     * Make validation work for Edit Entry
1054
-     *
1055
-     * Because we're calling the GFFormDisplay::validate() in an unusual way (as a front-end
1056
-     * form pretending to be a back-end form), validate() doesn't know we _can't_ edit post
1057
-     * fields. This goes through all the fields and if they're an invalid post field, we
1058
-     * set them as valid. If there are still issues, we'll return false.
1059
-     *
1060
-     * @param  [type] $validation_results [description]
1061
-     * @return [type]                     [description]
1062
-     */
1063
-    function custom_validation( $validation_results ) {
792
+		// SET SOME FIELD DEFAULTS TO PREVENT ISSUES
793
+		$field->adminOnly = false; /** @see GFFormDisplay::get_counter_init_script() need to prevent adminOnly */
1064 794
 
1065
-        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results: ', $validation_results );
795
+		// add categories as choices for Post Category field
796
+		if ( 'post_category' === $field->type ) {
797
+			$field = GFCommon::add_categories_as_choices( $field, $value );
798
+		}
1066 799
 
1067
-        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) );
800
+		$field_value = $this->get_field_value( $field );
1068 801
 
1069
-        $gv_valid = true;
802
+		/**
803
+		 * @filter `gravityview/edit_entry/field_value` Change the value of an Edit Entry field, if needed
804
+		 * @since 1.11
805
+		 * @param mixed $field_value field value used to populate the input
806
+		 * @param object $field Gravity Forms field object ( Class GF_Field )
807
+		 */
808
+		$field_value = apply_filters( 'gravityview/edit_entry/field_value', $field_value, $field );
1070 809
 
1071
-        foreach ( $validation_results['form']['fields'] as $key => &$field ) {
810
+		// Prevent any PHP warnings, like undefined index
811
+		ob_start();
1072 812
 
1073
-            $value = RGFormsModel::get_field_value( $field );
1074
-            $field_type = RGFormsModel::get_input_type( $field );
813
+		if( $gv_field && is_callable( array( $gv_field, 'get_field_input' ) ) ) {
814
+			$return = $gv_field->get_field_input( $this->form, $field_value, $this->entry, $field );
815
+		} else {
816
+			$return = $field->get_field_input( $this->form, $field_value, $this->entry );
817
+		}
1075 818
 
1076
-            // Validate always
1077
-            switch ( $field_type ) {
819
+		// If there was output, it's an error
820
+		$warnings = ob_get_clean();
1078 821
 
822
+		if( !empty( $warnings ) ) {
823
+			do_action( 'gravityview_log_error', __METHOD__ . $warnings, $field_value );
824
+		}
1079 825
 
1080
-                case 'fileupload' :
826
+		/**
827
+		 * Unset hack $_GET['page'] = 'gf_entries'
828
+		 * We need the fileupload html field to render with the proper id
829
+		 *  ( <li id="field_80_16" ... > )
830
+		 */
831
+		unset( $_GET['page'] );
1081 832
 
1082
-                    // in case nothing is uploaded but there are already files saved
1083
-                    if( !empty( $field->failed_validation ) && !empty( $field->isRequired ) && !empty( $value ) ) {
1084
-                        $field->failed_validation = false;
1085
-                        unset( $field->validation_message );
1086
-                    }
833
+		return $return;
834
+	}
1087 835
 
1088
-                    // validate if multi file upload reached max number of files [maxFiles] => 2
1089
-                    if( rgobj( $field, 'maxFiles') && rgobj( $field, 'multipleFiles') ) {
836
+	/**
837
+	 * Modify the value for the current field input
838
+	 *
839
+	 * @param GF_Field $field
840
+	 *
841
+	 * @return array|mixed|string|void
842
+	 */
843
+	private function get_field_value( $field ) {
1090 844
 
1091
-                        $input_name = 'input_' . $field->id;
1092
-                        //uploaded
1093
-                        $file_names = isset( GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] ) ? GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] : array();
845
+		/**
846
+		 * @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.
847
+		 * @param boolean True: override saved values; False: don't override (default)
848
+		 * @param $field GF_Field object Gravity Forms field object
849
+		 * @since 1.13
850
+		 */
851
+		$override_saved_value = apply_filters( 'gravityview/edit_entry/pre_populate/override', false, $field );
1094 852
 
1095
-                        //existent
1096
-                        $entry = $this->get_entry();
1097
-                        $value = NULL;
1098
-                        if( isset( $entry[ $field->id ] ) ) {
1099
-                            $value = json_decode( $entry[ $field->id ], true );
1100
-                        }
853
+		// We're dealing with multiple inputs (e.g. checkbox) but not time or date (as it doesn't store data in input IDs)
854
+		if( isset( $field->inputs ) && is_array( $field->inputs ) && !in_array( $field->type, array( 'time', 'date' ) ) ) {
1101 855
 
1102
-                        // count uploaded files and existent entry files
1103
-                        $count_files = count( $file_names ) + count( $value );
856
+			$field_value = array();
1104 857
 
1105
-                        if( $count_files > $field->maxFiles ) {
1106
-                            $field->validation_message = __( 'Maximum number of files reached', 'gravityview' );
1107
-                            $field->failed_validation = 1;
1108
-                            $gv_valid = false;
858
+			// only accept pre-populated values if the field doesn't have any choice selected.
859
+			$allow_pre_populated = $field->allowsPrepopulate;
1109 860
 
1110
-                            // in case of error make sure the newest upload files are removed from the upload input
1111
-                            GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ] = null;
1112
-                        }
861
+			foreach ( (array)$field->inputs as $input ) {
1113 862
 
1114
-                    }
863
+				$input_id = strval( $input['id'] );
1115 864
 
865
+				if ( ! gv_empty( $this->entry[ $input_id ], false ) ) {
866
+					$field_value[ $input_id ] =  'post_category' === $field->type ? GFCommon::format_post_category( $this->entry[ $input_id ], true ) : $this->entry[ $input_id ];
867
+					$allow_pre_populated = false;
868
+				}
1116 869
 
1117
-                    break;
870
+			}
1118 871
 
1119
-            }
872
+			$pre_value = $field->get_value_submission( array(), false );
1120 873
 
1121
-            // This field has failed validation.
1122
-            if( !empty( $field->failed_validation ) ) {
874
+			$field_value = ! $allow_pre_populated && ! ( $override_saved_value && !gv_empty( $pre_value, false ) ) ? $field_value : $pre_value;
1123 875
 
1124
-                do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field is invalid.', array( 'field' => $field, 'value' => $value ) );
876
+		} else {
1125 877
 
1126
-                switch ( $field_type ) {
878
+			$id = intval( $field->id );
1127 879
 
1128
-                    // Captchas don't need to be re-entered.
1129
-                    case 'captcha':
880
+			// get pre-populated value if exists
881
+			$pre_value = $field->allowsPrepopulate ? GFFormsModel::get_parameter_value( $field->inputName, array(), $field ) : '';
1130 882
 
1131
-                        // Post Image fields aren't editable, so we un-fail them.
1132
-                    case 'post_image':
1133
-                        $field->failed_validation = false;
1134
-                        unset( $field->validation_message );
1135
-                        break;
883
+			// saved field entry value (if empty, fallback to the pre-populated value, if exists)
884
+			// or pre-populated value if not empty and set to override saved value
885
+			$field_value = !gv_empty( $this->entry[ $id ], false ) && ! ( $override_saved_value && !gv_empty( $pre_value, false ) ) ? $this->entry[ $id ] : $pre_value;
1136 886
 
1137
-                }
887
+			// in case field is post_category but inputType is select, multi-select or radio, convert value into array of category IDs.
888
+			if ( 'post_category' === $field->type && !gv_empty( $field_value, false ) ) {
889
+				$categories = array();
890
+				foreach ( explode( ',', $field_value ) as $cat_string ) {
891
+					$categories[] = GFCommon::format_post_category( $cat_string, true );
892
+				}
893
+				$field_value = 'multiselect' === $field->get_input_type() ? $categories : implode( '', $categories );
894
+			}
1138 895
 
1139
-                // You can't continue inside a switch, so we do it after.
1140
-                if( empty( $field->failed_validation ) ) {
1141
-                    continue;
1142
-                }
896
+		}
1143 897
 
1144
-                // checks if the No Duplicates option is not validating entry against itself, since
1145
-                // we're editing a stored entry, it would also assume it's a duplicate.
1146
-                if( !empty( $field->noDuplicates ) ) {
898
+		// if value is empty get the default value if defined
899
+		$field_value = $field->get_value_default_if_empty( $field_value );
1147 900
 
1148
-                    $entry = $this->get_entry();
901
+		return $field_value;
902
+	}
1149 903
 
1150
-                    // If the value of the entry is the same as the stored value
1151
-                    // Then we can assume it's not a duplicate, it's the same.
1152
-                    if( !empty( $entry ) && $value == $entry[ $field->id ] ) {
1153
-                        //if value submitted was not changed, then don't validate
1154
-                        $field->failed_validation = false;
1155 904
 
1156
-                        unset( $field->validation_message );
905
+	// ---- Entry validation
1157 906
 
1158
-                        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', $entry );
907
+	/**
908
+	 * Add field keys that Gravity Forms expects.
909
+	 *
910
+	 * @see GFFormDisplay::validate()
911
+	 * @param  array $form GF Form
912
+	 * @return array       Modified GF Form
913
+	 */
914
+	function gform_pre_validation( $form ) {
1159 915
 
1160
-                        continue;
1161
-                    }
1162
-                }
916
+		if( ! $this->verify_nonce() ) {
917
+			return $form;
918
+		}
1163 919
 
1164
-                // if here then probably we are facing the validation 'At least one field must be filled out'
1165
-                if( GFFormDisplay::is_empty( $field, $this->form_id  ) && empty( $field->isRequired ) ) {
1166
-                    unset( $field->validation_message );
1167
-	                $field->validation_message = false;
1168
-                    continue;
1169
-                }
920
+		// Fix PHP warning regarding undefined index.
921
+		foreach ( $form['fields'] as &$field) {
1170 922
 
1171
-                $gv_valid = false;
923
+			// This is because we're doing admin form pretending to be front-end, so Gravity Forms
924
+			// expects certain field array items to be set.
925
+			foreach ( array( 'noDuplicates', 'adminOnly', 'inputType', 'isRequired', 'enablePrice', 'inputs', 'allowedExtensions' ) as $key ) {
926
+				$field->{$key} = isset( $field->{$key} ) ? $field->{$key} : NULL;
927
+			}
1172 928
 
1173
-            }
929
+			// unset emailConfirmEnabled for email type fields
930
+		   /* if( 'email' === $field['type'] && !empty( $field['emailConfirmEnabled'] ) ) {
931
+                $field['emailConfirmEnabled'] = '';
932
+            }*/
1174 933
 
1175
-        }
934
+			switch( RGFormsModel::get_input_type( $field ) ) {
935
+
936
+				/**
937
+				 * 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.
938
+				 *
939
+				 * 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.
940
+				 *
941
+				 * @hack
942
+				 */
943
+				case 'fileupload':
944
+				case 'post_image':
945
+
946
+					// Set the previous value
947
+					$entry = $this->get_entry();
948
+
949
+					$input_name = 'input_'.$field->id;
950
+					$form_id = $form['id'];
951
+
952
+					$value = NULL;
953
+
954
+					// Use the previous entry value as the default.
955
+					if( isset( $entry[ $field->id ] ) ) {
956
+						$value = $entry[ $field->id ];
957
+					}
958
+
959
+					// If this is a single upload file
960
+					if( !empty( $_FILES[ $input_name ] ) && !empty( $_FILES[ $input_name ]['name'] ) ) {
961
+						$file_path = GFFormsModel::get_file_upload_path( $form['id'], $_FILES[ $input_name ]['name'] );
962
+						$value = $file_path['url'];
963
+
964
+					} else {
965
+
966
+						// Fix PHP warning on line 1498 of form_display.php for post_image fields
967
+						// Fix PHP Notice:  Undefined index:  size in form_display.php on line 1511
968
+						$_FILES[ $input_name ] = array('name' => '', 'size' => '' );
969
+
970
+					}
971
+
972
+					if( rgar($field, "multipleFiles") ) {
973
+
974
+						// If there are fresh uploads, process and merge them.
975
+						// Otherwise, use the passed values, which should be json-encoded array of URLs
976
+						if( isset( GFFormsModel::$uploaded_files[$form_id][$input_name] ) ) {
977
+							$value = empty( $value ) ? '[]' : $value;
978
+							$value = stripslashes_deep( $value );
979
+							$value = GFFormsModel::prepare_value( $form, $field, $value, $input_name, $entry['id'], array());
980
+						}
981
+
982
+					} else {
983
+
984
+						// A file already exists when editing an entry
985
+						// We set this to solve issue when file upload fields are required.
986
+						GFFormsModel::$uploaded_files[ $form_id ][ $input_name ] = $value;
987
+
988
+					}
989
+
990
+					$this->entry[ $input_name ] = $value;
991
+					$prepared_value = GFFormsModel::get_prepared_input_value( $form, $field, $entry, $field->id );
992
+					$_POST[ $input_name ] = $value;
993
+
994
+					break;
995
+				case 'number':
996
+					// Fix "undefined index" issue at line 1286 in form_display.php
997
+					if( !isset( $_POST['input_'.$field->id ] ) ) {
998
+						$_POST['input_'.$field->id ] = NULL;
999
+					}
1000
+					break;
1001
+				case 'captcha':
1002
+					// Fix issue with recaptcha_check_answer() on line 1458 in form_display.php
1003
+					$_POST['recaptcha_challenge_field'] = NULL;
1004
+					$_POST['recaptcha_response_field'] = NULL;
1005
+					break;
1006
+			}
1176 1007
 
1177
-        $validation_results['is_valid'] = $gv_valid;
1008
+		}
1178 1009
 
1179
-        do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results.', $validation_results );
1010
+		return $form;
1011
+	}
1012
+
1013
+
1014
+	/**
1015
+	 * Process validation for a edit entry submission
1016
+	 *
1017
+	 * Sets the `is_valid` object var
1018
+	 *
1019
+	 * @return void
1020
+	 */
1021
+	function validate() {
1022
+
1023
+		// If using GF User Registration Add-on, remove the validation step, otherwise generates error when updating the entry
1024
+		if ( class_exists( 'GFUser' ) ) {
1025
+			remove_filter( 'gform_validation', array( 'GFUser', 'user_registration_validation' ) );
1026
+		}
1027
+
1028
+		/**
1029
+		 * For some crazy reason, Gravity Forms doesn't validate Edit Entry form submissions.
1030
+		 * You can enter whatever you want!
1031
+		 * We try validating, and customize the results using `self::custom_validation()`
1032
+		 */
1033
+		add_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10, 4);
1034
+
1035
+		// Needed by the validate funtion
1036
+		$failed_validation_page = NULL;
1037
+		$field_values = RGForms::post( 'gform_field_values' );
1038
+
1039
+		// Prevent entry limit from running when editing an entry, also
1040
+		// prevent form scheduling from preventing editing
1041
+		unset( $this->form['limitEntries'], $this->form['scheduleForm'] );
1042
+
1043
+		// Hide fields depending on Edit Entry settings
1044
+		$this->form['fields'] = $this->get_configured_edit_fields( $this->form, $this->view_id );
1045
+
1046
+		$this->is_valid = GFFormDisplay::validate( $this->form, $field_values, 1, $failed_validation_page );
1047
+
1048
+		remove_filter( 'gform_validation_'. $this->form_id, array( $this, 'custom_validation' ), 10 );
1049
+	}
1050
+
1051
+
1052
+	/**
1053
+	 * Make validation work for Edit Entry
1054
+	 *
1055
+	 * Because we're calling the GFFormDisplay::validate() in an unusual way (as a front-end
1056
+	 * form pretending to be a back-end form), validate() doesn't know we _can't_ edit post
1057
+	 * fields. This goes through all the fields and if they're an invalid post field, we
1058
+	 * set them as valid. If there are still issues, we'll return false.
1059
+	 *
1060
+	 * @param  [type] $validation_results [description]
1061
+	 * @return [type]                     [description]
1062
+	 */
1063
+	function custom_validation( $validation_results ) {
1064
+
1065
+		do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results: ', $validation_results );
1066
+
1067
+		do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] $_POSTed data (sanitized): ', esc_html( print_r( $_POST, true ) ) );
1068
+
1069
+		$gv_valid = true;
1070
+
1071
+		foreach ( $validation_results['form']['fields'] as $key => &$field ) {
1072
+
1073
+			$value = RGFormsModel::get_field_value( $field );
1074
+			$field_type = RGFormsModel::get_input_type( $field );
1075
+
1076
+			// Validate always
1077
+			switch ( $field_type ) {
1078
+
1079
+
1080
+				case 'fileupload' :
1081
+
1082
+					// in case nothing is uploaded but there are already files saved
1083
+					if( !empty( $field->failed_validation ) && !empty( $field->isRequired ) && !empty( $value ) ) {
1084
+						$field->failed_validation = false;
1085
+						unset( $field->validation_message );
1086
+					}
1087
+
1088
+					// validate if multi file upload reached max number of files [maxFiles] => 2
1089
+					if( rgobj( $field, 'maxFiles') && rgobj( $field, 'multipleFiles') ) {
1090
+
1091
+						$input_name = 'input_' . $field->id;
1092
+						//uploaded
1093
+						$file_names = isset( GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] ) ? GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ][ $input_name ] : array();
1094
+
1095
+						//existent
1096
+						$entry = $this->get_entry();
1097
+						$value = NULL;
1098
+						if( isset( $entry[ $field->id ] ) ) {
1099
+							$value = json_decode( $entry[ $field->id ], true );
1100
+						}
1101
+
1102
+						// count uploaded files and existent entry files
1103
+						$count_files = count( $file_names ) + count( $value );
1104
+
1105
+						if( $count_files > $field->maxFiles ) {
1106
+							$field->validation_message = __( 'Maximum number of files reached', 'gravityview' );
1107
+							$field->failed_validation = 1;
1108
+							$gv_valid = false;
1109
+
1110
+							// in case of error make sure the newest upload files are removed from the upload input
1111
+							GFFormsModel::$uploaded_files[ $validation_results['form']['id'] ] = null;
1112
+						}
1113
+
1114
+					}
1115
+
1116
+
1117
+					break;
1118
+
1119
+			}
1120
+
1121
+			// This field has failed validation.
1122
+			if( !empty( $field->failed_validation ) ) {
1123
+
1124
+				do_action( 'gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field is invalid.', array( 'field' => $field, 'value' => $value ) );
1125
+
1126
+				switch ( $field_type ) {
1127
+
1128
+					// Captchas don't need to be re-entered.
1129
+					case 'captcha':
1130
+
1131
+						// Post Image fields aren't editable, so we un-fail them.
1132
+					case 'post_image':
1133
+						$field->failed_validation = false;
1134
+						unset( $field->validation_message );
1135
+						break;
1136
+
1137
+				}
1180 1138
 
1181
-        // We'll need this result when rendering the form ( on GFFormDisplay::get_form )
1182
-        $this->form_after_validation = $validation_results['form'];
1139
+				// You can't continue inside a switch, so we do it after.
1140
+				if( empty( $field->failed_validation ) ) {
1141
+					continue;
1142
+				}
1183 1143
 
1184
-        return $validation_results;
1185
-    }
1144
+				// checks if the No Duplicates option is not validating entry against itself, since
1145
+				// we're editing a stored entry, it would also assume it's a duplicate.
1146
+				if( !empty( $field->noDuplicates ) ) {
1186 1147
 
1148
+					$entry = $this->get_entry();
1187 1149
 
1188
-    /**
1189
-     * TODO: This seems to be hacky... we should remove it. Entry is set when updating the form using setup_vars()!
1190
-     * Get the current entry and set it if it's not yet set.
1191
-     * @return array Gravity Forms entry array
1192
-     */
1193
-    private function get_entry() {
1150
+					// If the value of the entry is the same as the stored value
1151
+					// Then we can assume it's not a duplicate, it's the same.
1152
+					if( !empty( $entry ) && $value == $entry[ $field->id ] ) {
1153
+						//if value submitted was not changed, then don't validate
1154
+						$field->failed_validation = false;
1194 1155
 
1195
-        if( empty( $this->entry ) ) {
1196
-            // Get the database value of the entry that's being edited
1197
-            $this->entry = gravityview_get_entry( GravityView_frontend::is_single_entry() );
1198
-        }
1156
+						unset( $field->validation_message );
1199 1157
 
1200
-        return $this->entry;
1201
-    }
1158
+						do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', $entry );
1202 1159
 
1160
+						continue;
1161
+					}
1162
+				}
1203 1163
 
1164
+				// if here then probably we are facing the validation 'At least one field must be filled out'
1165
+				if( GFFormDisplay::is_empty( $field, $this->form_id  ) && empty( $field->isRequired ) ) {
1166
+					unset( $field->validation_message );
1167
+					$field->validation_message = false;
1168
+					continue;
1169
+				}
1204 1170
 
1205
-    // --- Filters
1171
+				$gv_valid = false;
1206 1172
 
1207
-    /**
1208
-     * Get the Edit Entry fields as configured in the View
1209
-     *
1210
-     * @since 1.8
1211
-     *
1212
-     * @param int $view_id
1213
-     *
1214
-     * @return array Array of fields that are configured in the Edit tab in the Admin
1215
-     */
1216
-    private function get_configured_edit_fields( $form, $view_id ) {
1173
+			}
1174
+
1175
+		}
1176
+
1177
+		$validation_results['is_valid'] = $gv_valid;
1217 1178
 
1218
-        // Get all fields for form
1219
-        $properties = GravityView_View_Data::getInstance()->get_fields( $view_id );
1179
+		do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results.', $validation_results );
1180
+
1181
+		// We'll need this result when rendering the form ( on GFFormDisplay::get_form )
1182
+		$this->form_after_validation = $validation_results['form'];
1183
+
1184
+		return $validation_results;
1185
+	}
1220 1186
 
1221
-        // If edit tab not yet configured, show all fields
1222
-        $edit_fields = !empty( $properties['edit_edit-fields'] ) ? $properties['edit_edit-fields'] : NULL;
1223 1187
 
1224
-	    // Show hidden fields as text fields
1225
-	    $form = $this->fix_hidden_fields( $form );
1188
+	/**
1189
+	 * TODO: This seems to be hacky... we should remove it. Entry is set when updating the form using setup_vars()!
1190
+	 * Get the current entry and set it if it's not yet set.
1191
+	 * @return array Gravity Forms entry array
1192
+	 */
1193
+	private function get_entry() {
1194
+
1195
+		if( empty( $this->entry ) ) {
1196
+			// Get the database value of the entry that's being edited
1197
+			$this->entry = gravityview_get_entry( GravityView_frontend::is_single_entry() );
1198
+		}
1199
+
1200
+		return $this->entry;
1201
+	}
1226 1202
 
1227
-        // Hide fields depending on admin settings
1228
-        $fields = $this->filter_fields( $form['fields'], $edit_fields );
1229 1203
 
1230
-	    // If Edit Entry fields are configured, remove adminOnly field settings. Otherwise, don't.
1231
-	    $fields = $this->filter_admin_only_fields( $fields, $edit_fields, $form, $view_id );
1232 1204
 
1233
-        return $fields;
1234
-    }
1205
+	// --- Filters
1206
+
1207
+	/**
1208
+	 * Get the Edit Entry fields as configured in the View
1209
+	 *
1210
+	 * @since 1.8
1211
+	 *
1212
+	 * @param int $view_id
1213
+	 *
1214
+	 * @return array Array of fields that are configured in the Edit tab in the Admin
1215
+	 */
1216
+	private function get_configured_edit_fields( $form, $view_id ) {
1217
+
1218
+		// Get all fields for form
1219
+		$properties = GravityView_View_Data::getInstance()->get_fields( $view_id );
1220
+
1221
+		// If edit tab not yet configured, show all fields
1222
+		$edit_fields = !empty( $properties['edit_edit-fields'] ) ? $properties['edit_edit-fields'] : NULL;
1223
+
1224
+		// Show hidden fields as text fields
1225
+		$form = $this->fix_hidden_fields( $form );
1226
+
1227
+		// Hide fields depending on admin settings
1228
+		$fields = $this->filter_fields( $form['fields'], $edit_fields );
1229
+
1230
+		// If Edit Entry fields are configured, remove adminOnly field settings. Otherwise, don't.
1231
+		$fields = $this->filter_admin_only_fields( $fields, $edit_fields, $form, $view_id );
1232
+
1233
+		return $fields;
1234
+	}
1235 1235
 
1236 1236
 	/**
1237 1237
 	 * @since 1.9.2
@@ -1255,372 +1255,372 @@  discard block
 block discarded – undo
1255 1255
 	}
1256 1256
 
1257 1257
 
1258
-    /**
1259
-     * Filter area fields based on specified conditions
1260
-     *  - This filter removes the fields that have calculation configured
1261
-     *
1262
-     * @uses GravityView_Edit_Entry::user_can_edit_field() Check caps
1263
-     * @access private
1264
-     * @param GF_Field[] $fields
1265
-     * @param array $configured_fields
1266
-     * @since  1.5
1267
-     * @return array $fields
1268
-     */
1269
-    private function filter_fields( $fields, $configured_fields ) {
1270
-
1271
-        if( empty( $fields ) || !is_array( $fields ) ) {
1272
-            return $fields;
1273
-        }
1274
-
1275
-        $edit_fields = array();
1276
-
1277
-        $field_type_blacklist = array(
1278
-            'page',
1279
-        );
1280
-
1281
-	    /**
1282
-	     * @filter `gravityview/edit_entry/hide-product-fields` Hide product fields from being editable.
1283
-	     * @since 1.9.1
1284
-         * @param boolean $hide_product_fields Whether to hide product fields in the editor.  Default: false
1285
-	     */
1286
-	    $hide_product_fields = apply_filters( 'gravityview/edit_entry/hide-product-fields', empty( self::$supports_product_fields ) );
1287
-
1288
-	    if( $hide_product_fields ) {
1289
-		    $field_type_blacklist[] = 'option';
1290
-		    $field_type_blacklist[] = 'quantity';
1291
-            $field_type_blacklist[] = 'product';
1292
-            $field_type_blacklist[] = 'total';
1293
-            $field_type_blacklist[] = 'shipping';
1294
-            $field_type_blacklist[] = 'calculation'; //todo: this field type doesn't exist ?
1295
-	    }
1296
-
1297
-        // First, remove blacklist or calculation fields
1298
-        foreach ( $fields as $key => $field ) {
1299
-
1300
-            // Remove the fields that have calculation properties and keep them to be used later
1301
-            // @since 1.16.2
1302
-            if( $field->has_calculation() ) {
1303
-                $this->fields_with_calculation[] = $field;
1304
-                unset( $fields[ $key ] );
1305
-            }
1306
-
1307
-            if( in_array( $field->type, $field_type_blacklist ) ) {
1308
-                unset( $fields[ $key ] );
1309
-            }
1310
-        }
1311
-
1312
-        // The Edit tab has not been configured, so we return all fields by default.
1313
-        if( empty( $configured_fields ) ) {
1314
-            return $fields;
1315
-        }
1316
-
1317
-        // The edit tab has been configured, so we loop through to configured settings
1318
-        foreach ( $configured_fields as $configured_field ) {
1319
-
1320
-	        /** @var GF_Field $field */
1321
-	        foreach ( $fields as $field ) {
1322
-
1323
-                if( intval( $configured_field['id'] ) === intval( $field->id ) && $this->user_can_edit_field( $configured_field, false ) ) {
1324
-                    $edit_fields[] = $this->merge_field_properties( $field, $configured_field );
1325
-                    break;
1326
-                }
1327
-
1328
-            }
1329
-
1330
-        }
1331
-
1332
-        return $edit_fields;
1333
-
1334
-    }
1335
-
1336
-    /**
1337
-     * Override GF Form field properties with the ones defined on the View
1338
-     * @param  GF_Field $field GF Form field object
1339
-     * @param  array $setting  GV field options
1340
-     * @since  1.5
1341
-     * @return array
1342
-     */
1343
-    private function merge_field_properties( $field, $field_setting ) {
1344
-
1345
-        $return_field = $field;
1346
-
1347
-        if( empty( $field_setting['show_label'] ) ) {
1348
-            $return_field->label = '';
1349
-        } elseif ( !empty( $field_setting['custom_label'] ) ) {
1350
-            $return_field->label = $field_setting['custom_label'];
1351
-        }
1352
-
1353
-        if( !empty( $field_setting['custom_class'] ) ) {
1354
-            $return_field->cssClass .= ' '. gravityview_sanitize_html_class( $field_setting['custom_class'] );
1355
-        }
1356
-
1357
-        /**
1358
-         * Normalize page numbers - avoid conflicts with page validation
1359
-         * @since 1.6
1360
-         */
1361
-        $return_field->pageNumber = 1;
1362
-
1363
-        return $return_field;
1364
-
1365
-    }
1366
-
1367
-    /**
1368
-     * Remove fields that shouldn't be visible based on the Gravity Forms adminOnly field property
1369
-     *
1370
-     * @since 1.9.1
1371
-     *
1372
-     * @param array|GF_Field[] $fields Gravity Forms form fields
1373
-     * @param array|null $edit_fields Fields for the Edit Entry tab configured in the View Configuration
1374
-     * @param array $form GF Form array
1375
-     * @param int $view_id View ID
1376
-     *
1377
-     * @return array Possibly modified form array
1378
-     */
1379
-    function filter_admin_only_fields( $fields = array(), $edit_fields = null, $form = array(), $view_id = 0 ) {
1380
-
1381
-	    /**
1382
-         * @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
1383
-	     * If the Edit Entry tab is not configured, adminOnly fields will not be shown to non-administrators.
1384
-	     * If the Edit Entry tab *is* configured, adminOnly fields will be shown to non-administrators, using the configured GV permissions
1385
-	     * @since 1.9.1
1386
-	     * @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.
1387
-	     * @param array $form GF Form array
1388
-	     * @param int $view_id View ID
1389
-	     */
1390
-	    $use_gf_adminonly_setting = apply_filters( 'gravityview/edit_entry/use_gf_admin_only_setting', empty( $edit_fields ), $form, $view_id );
1391
-
1392
-	    if( $use_gf_adminonly_setting && false === GVCommon::has_cap( 'gravityforms_edit_entries', $this->entry['id'] ) ) {
1393
-            return $fields;
1394
-        }
1395
-
1396
-	    foreach( $fields as &$field ) {
1397
-		    $field->adminOnly = false;
1398
-        }
1399
-
1400
-        return $fields;
1401
-    }
1402
-
1403
-    // --- Conditional Logic
1404
-
1405
-    /**
1406
-     * Remove the conditional logic rules from the form button and the form fields, if needed.
1407
-     *
1408
-     * @since 1.9
1409
-     *
1410
-     * @param array $form Gravity Forms form
1411
-     * @return array Modified form, if not using Conditional Logic
1412
-     */
1413
-    function filter_conditional_logic( $form ) {
1414
-
1415
-        /**
1416
-         * @filter `gravityview/edit_entry/conditional_logic` Should the Edit Entry form use Gravity Forms conditional logic showing/hiding of fields?
1417
-         * @since 1.9
1418
-         * @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
1419
-         * @param array $form Gravity Forms form
1420
-         */
1421
-        $use_conditional_logic = apply_filters( 'gravityview/edit_entry/conditional_logic', true, $form );
1422
-
1423
-        if( $use_conditional_logic ) {
1424
-            return $form;
1425
-        }
1426
-
1427
-        foreach( $form['fields'] as &$field ) {
1428
-            /* @var GF_Field $field */
1429
-            $field->conditionalLogic = null;
1430
-        }
1431
-
1432
-        unset( $form['button']['conditionalLogic'] );
1433
-
1434
-        return $form;
1435
-
1436
-    }
1437
-
1438
-    /**
1439
-     * Disable the Gravity Forms conditional logic script and features on the Edit Entry screen
1440
-     *
1441
-     * @since 1.9
1442
-     *
1443
-     * @param $has_conditional_logic
1444
-     * @param $form
1445
-     * @return mixed|void
1446
-     */
1447
-    function manage_conditional_logic( $has_conditional_logic, $form ) {
1448
-
1449
-        if( ! $this->is_edit_entry() ) {
1450
-            return $has_conditional_logic;
1451
-        }
1452
-
1453
-        return apply_filters( 'gravityview/edit_entry/conditional_logic', $has_conditional_logic, $form );
1454
-    }
1455
-
1456
-
1457
-    // --- User checks and nonces
1458
-
1459
-    /**
1460
-     * Check if the user can edit the entry
1461
-     *
1462
-     * - Is the nonce valid?
1463
-     * - Does the user have the right caps for the entry
1464
-     * - Is the entry in the trash?
1465
-     *
1466
-     * @todo Move to GVCommon
1467
-     *
1468
-     * @param  boolean $echo Show error messages in the form?
1469
-     * @return boolean        True: can edit form. False: nope.
1470
-     */
1471
-    function user_can_edit_entry( $echo = false ) {
1472
-
1473
-        $error = NULL;
1474
-
1475
-        /**
1476
-         *  1. Permalinks are turned off
1477
-         *  2. There are two entries embedded using oEmbed
1478
-         *  3. One of the entries has just been saved
1479
-         */
1480
-        if( !empty( $_POST['lid'] ) && !empty( $_GET['entry'] ) && ( $_POST['lid'] !== $_GET['entry'] ) ) {
1481
-
1482
-            $error = true;
1483
-
1484
-        }
1485
-
1486
-        if( !empty( $_GET['entry'] ) && (string)$this->entry['id'] !== $_GET['entry'] ) {
1487
-
1488
-            $error = true;
1258
+	/**
1259
+	 * Filter area fields based on specified conditions
1260
+	 *  - This filter removes the fields that have calculation configured
1261
+	 *
1262
+	 * @uses GravityView_Edit_Entry::user_can_edit_field() Check caps
1263
+	 * @access private
1264
+	 * @param GF_Field[] $fields
1265
+	 * @param array $configured_fields
1266
+	 * @since  1.5
1267
+	 * @return array $fields
1268
+	 */
1269
+	private function filter_fields( $fields, $configured_fields ) {
1270
+
1271
+		if( empty( $fields ) || !is_array( $fields ) ) {
1272
+			return $fields;
1273
+		}
1274
+
1275
+		$edit_fields = array();
1276
+
1277
+		$field_type_blacklist = array(
1278
+			'page',
1279
+		);
1280
+
1281
+		/**
1282
+		 * @filter `gravityview/edit_entry/hide-product-fields` Hide product fields from being editable.
1283
+		 * @since 1.9.1
1284
+		 * @param boolean $hide_product_fields Whether to hide product fields in the editor.  Default: false
1285
+		 */
1286
+		$hide_product_fields = apply_filters( 'gravityview/edit_entry/hide-product-fields', empty( self::$supports_product_fields ) );
1287
+
1288
+		if( $hide_product_fields ) {
1289
+			$field_type_blacklist[] = 'option';
1290
+			$field_type_blacklist[] = 'quantity';
1291
+			$field_type_blacklist[] = 'product';
1292
+			$field_type_blacklist[] = 'total';
1293
+			$field_type_blacklist[] = 'shipping';
1294
+			$field_type_blacklist[] = 'calculation'; //todo: this field type doesn't exist ?
1295
+		}
1296
+
1297
+		// First, remove blacklist or calculation fields
1298
+		foreach ( $fields as $key => $field ) {
1299
+
1300
+			// Remove the fields that have calculation properties and keep them to be used later
1301
+			// @since 1.16.2
1302
+			if( $field->has_calculation() ) {
1303
+				$this->fields_with_calculation[] = $field;
1304
+				unset( $fields[ $key ] );
1305
+			}
1306
+
1307
+			if( in_array( $field->type, $field_type_blacklist ) ) {
1308
+				unset( $fields[ $key ] );
1309
+			}
1310
+		}
1311
+
1312
+		// The Edit tab has not been configured, so we return all fields by default.
1313
+		if( empty( $configured_fields ) ) {
1314
+			return $fields;
1315
+		}
1316
+
1317
+		// The edit tab has been configured, so we loop through to configured settings
1318
+		foreach ( $configured_fields as $configured_field ) {
1319
+
1320
+			/** @var GF_Field $field */
1321
+			foreach ( $fields as $field ) {
1322
+
1323
+				if( intval( $configured_field['id'] ) === intval( $field->id ) && $this->user_can_edit_field( $configured_field, false ) ) {
1324
+					$edit_fields[] = $this->merge_field_properties( $field, $configured_field );
1325
+					break;
1326
+				}
1327
+
1328
+			}
1329
+
1330
+		}
1331
+
1332
+		return $edit_fields;
1333
+
1334
+	}
1335
+
1336
+	/**
1337
+	 * Override GF Form field properties with the ones defined on the View
1338
+	 * @param  GF_Field $field GF Form field object
1339
+	 * @param  array $setting  GV field options
1340
+	 * @since  1.5
1341
+	 * @return array
1342
+	 */
1343
+	private function merge_field_properties( $field, $field_setting ) {
1344
+
1345
+		$return_field = $field;
1346
+
1347
+		if( empty( $field_setting['show_label'] ) ) {
1348
+			$return_field->label = '';
1349
+		} elseif ( !empty( $field_setting['custom_label'] ) ) {
1350
+			$return_field->label = $field_setting['custom_label'];
1351
+		}
1352
+
1353
+		if( !empty( $field_setting['custom_class'] ) ) {
1354
+			$return_field->cssClass .= ' '. gravityview_sanitize_html_class( $field_setting['custom_class'] );
1355
+		}
1356
+
1357
+		/**
1358
+		 * Normalize page numbers - avoid conflicts with page validation
1359
+		 * @since 1.6
1360
+		 */
1361
+		$return_field->pageNumber = 1;
1362
+
1363
+		return $return_field;
1364
+
1365
+	}
1366
+
1367
+	/**
1368
+	 * Remove fields that shouldn't be visible based on the Gravity Forms adminOnly field property
1369
+	 *
1370
+	 * @since 1.9.1
1371
+	 *
1372
+	 * @param array|GF_Field[] $fields Gravity Forms form fields
1373
+	 * @param array|null $edit_fields Fields for the Edit Entry tab configured in the View Configuration
1374
+	 * @param array $form GF Form array
1375
+	 * @param int $view_id View ID
1376
+	 *
1377
+	 * @return array Possibly modified form array
1378
+	 */
1379
+	function filter_admin_only_fields( $fields = array(), $edit_fields = null, $form = array(), $view_id = 0 ) {
1380
+
1381
+		/**
1382
+		 * @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
1383
+		 * If the Edit Entry tab is not configured, adminOnly fields will not be shown to non-administrators.
1384
+		 * If the Edit Entry tab *is* configured, adminOnly fields will be shown to non-administrators, using the configured GV permissions
1385
+		 * @since 1.9.1
1386
+		 * @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.
1387
+		 * @param array $form GF Form array
1388
+		 * @param int $view_id View ID
1389
+		 */
1390
+		$use_gf_adminonly_setting = apply_filters( 'gravityview/edit_entry/use_gf_admin_only_setting', empty( $edit_fields ), $form, $view_id );
1391
+
1392
+		if( $use_gf_adminonly_setting && false === GVCommon::has_cap( 'gravityforms_edit_entries', $this->entry['id'] ) ) {
1393
+			return $fields;
1394
+		}
1395
+
1396
+		foreach( $fields as &$field ) {
1397
+			$field->adminOnly = false;
1398
+		}
1399
+
1400
+		return $fields;
1401
+	}
1402
+
1403
+	// --- Conditional Logic
1404
+
1405
+	/**
1406
+	 * Remove the conditional logic rules from the form button and the form fields, if needed.
1407
+	 *
1408
+	 * @since 1.9
1409
+	 *
1410
+	 * @param array $form Gravity Forms form
1411
+	 * @return array Modified form, if not using Conditional Logic
1412
+	 */
1413
+	function filter_conditional_logic( $form ) {
1414
+
1415
+		/**
1416
+		 * @filter `gravityview/edit_entry/conditional_logic` Should the Edit Entry form use Gravity Forms conditional logic showing/hiding of fields?
1417
+		 * @since 1.9
1418
+		 * @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
1419
+		 * @param array $form Gravity Forms form
1420
+		 */
1421
+		$use_conditional_logic = apply_filters( 'gravityview/edit_entry/conditional_logic', true, $form );
1422
+
1423
+		if( $use_conditional_logic ) {
1424
+			return $form;
1425
+		}
1426
+
1427
+		foreach( $form['fields'] as &$field ) {
1428
+			/* @var GF_Field $field */
1429
+			$field->conditionalLogic = null;
1430
+		}
1431
+
1432
+		unset( $form['button']['conditionalLogic'] );
1433
+
1434
+		return $form;
1435
+
1436
+	}
1437
+
1438
+	/**
1439
+	 * Disable the Gravity Forms conditional logic script and features on the Edit Entry screen
1440
+	 *
1441
+	 * @since 1.9
1442
+	 *
1443
+	 * @param $has_conditional_logic
1444
+	 * @param $form
1445
+	 * @return mixed|void
1446
+	 */
1447
+	function manage_conditional_logic( $has_conditional_logic, $form ) {
1448
+
1449
+		if( ! $this->is_edit_entry() ) {
1450
+			return $has_conditional_logic;
1451
+		}
1452
+
1453
+		return apply_filters( 'gravityview/edit_entry/conditional_logic', $has_conditional_logic, $form );
1454
+	}
1455
+
1456
+
1457
+	// --- User checks and nonces
1489 1458
 
1490
-        } elseif( ! $this->verify_nonce() ) {
1459
+	/**
1460
+	 * Check if the user can edit the entry
1461
+	 *
1462
+	 * - Is the nonce valid?
1463
+	 * - Does the user have the right caps for the entry
1464
+	 * - Is the entry in the trash?
1465
+	 *
1466
+	 * @todo Move to GVCommon
1467
+	 *
1468
+	 * @param  boolean $echo Show error messages in the form?
1469
+	 * @return boolean        True: can edit form. False: nope.
1470
+	 */
1471
+	function user_can_edit_entry( $echo = false ) {
1491 1472
 
1492
-            /**
1493
-             * If the Entry is embedded, there may be two entries on the same page.
1494
-             * If that's the case, and one is being edited, the other should fail gracefully and not display an error.
1495
-             */
1496
-            if( GravityView_oEmbed::getInstance()->get_entry_id() ) {
1497
-                $error = true;
1498
-            } else {
1499
-                $error = __( 'The link to edit this entry is not valid; it may have expired.', 'gravityview');
1500
-            }
1473
+		$error = NULL;
1501 1474
 
1502
-        }
1503
-
1504
-        if( ! GravityView_Edit_Entry::check_user_cap_edit_entry( $this->entry ) ) {
1505
-            $error = __( 'You do not have permission to edit this entry.', 'gravityview');
1506
-        }
1507
-
1508
-        if( $this->entry['status'] === 'trash' ) {
1509
-            $error = __('You cannot edit the entry; it is in the trash.', 'gravityview' );
1510
-        }
1475
+		/**
1476
+		 *  1. Permalinks are turned off
1477
+		 *  2. There are two entries embedded using oEmbed
1478
+		 *  3. One of the entries has just been saved
1479
+		 */
1480
+		if( !empty( $_POST['lid'] ) && !empty( $_GET['entry'] ) && ( $_POST['lid'] !== $_GET['entry'] ) ) {
1511 1481
 
1512
-        // No errors; everything's fine here!
1513
-        if( empty( $error ) ) {
1514
-            return true;
1515
-        }
1482
+			$error = true;
1516 1483
 
1517
-        if( $echo && $error !== true ) {
1484
+		}
1518 1485
 
1519
-	        $error = esc_html( $error );
1486
+		if( !empty( $_GET['entry'] ) && (string)$this->entry['id'] !== $_GET['entry'] ) {
1520 1487
 
1521
-	        /**
1522
-	         * @since 1.9
1523
-	         */
1524
-	        if ( ! empty( $this->entry ) ) {
1525
-		        $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;" ) );
1526
-	        }
1488
+			$error = true;
1527 1489
 
1528
-            echo GVCommon::generate_notice( wpautop( $error ), 'gv-error error');
1529
-        }
1490
+		} elseif( ! $this->verify_nonce() ) {
1530 1491
 
1531
-        do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_entry]' . $error );
1492
+			/**
1493
+			 * If the Entry is embedded, there may be two entries on the same page.
1494
+			 * If that's the case, and one is being edited, the other should fail gracefully and not display an error.
1495
+			 */
1496
+			if( GravityView_oEmbed::getInstance()->get_entry_id() ) {
1497
+				$error = true;
1498
+			} else {
1499
+				$error = __( 'The link to edit this entry is not valid; it may have expired.', 'gravityview');
1500
+			}
1532 1501
 
1533
-        return false;
1534
-    }
1502
+		}
1535 1503
 
1504
+		if( ! GravityView_Edit_Entry::check_user_cap_edit_entry( $this->entry ) ) {
1505
+			$error = __( 'You do not have permission to edit this entry.', 'gravityview');
1506
+		}
1536 1507
 
1537
-    /**
1538
-     * Check whether a field is editable by the current user, and optionally display an error message
1539
-     * @uses  GravityView_Edit_Entry->check_user_cap_edit_field() Check user capabilities
1540
-     * @param  array  $field Field or field settings array
1541
-     * @param  boolean $echo  Whether to show error message telling user they aren't allowed
1542
-     * @return boolean         True: user can edit the current field; False: nope, they can't.
1543
-     */
1544
-    private function user_can_edit_field( $field, $echo = false ) {
1545
-
1546
-        $error = NULL;
1508
+		if( $this->entry['status'] === 'trash' ) {
1509
+			$error = __('You cannot edit the entry; it is in the trash.', 'gravityview' );
1510
+		}
1547 1511
 
1548
-        if( ! $this->check_user_cap_edit_field( $field ) ) {
1549
-            $error = __( 'You do not have permission to edit this field.', 'gravityview');
1550
-        }
1512
+		// No errors; everything's fine here!
1513
+		if( empty( $error ) ) {
1514
+			return true;
1515
+		}
1516
+
1517
+		if( $echo && $error !== true ) {
1551 1518
 
1552
-        // No errors; everything's fine here!
1553
-        if( empty( $error ) ) {
1554
-            return true;
1555
-        }
1519
+			$error = esc_html( $error );
1556 1520
 
1557
-        if( $echo ) {
1558
-            echo GVCommon::generate_notice( wpautop( esc_html( $error ) ), 'gv-error error');
1559
-        }
1560
-
1561
-        do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_field]' . $error );
1521
+			/**
1522
+			 * @since 1.9
1523
+			 */
1524
+			if ( ! empty( $this->entry ) ) {
1525
+				$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;" ) );
1526
+			}
1562 1527
 
1563
-        return false;
1528
+			echo GVCommon::generate_notice( wpautop( $error ), 'gv-error error');
1529
+		}
1564 1530
 
1565
-    }
1531
+		do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_entry]' . $error );
1566 1532
 
1533
+		return false;
1534
+	}
1567 1535
 
1568
-    /**
1569
-     * checks if user has permissions to edit a specific field
1570
-     *
1571
-     * Needs to be used combined with GravityView_Edit_Entry::user_can_edit_field for maximum security!!
1572
-     *
1573
-     * @param  [type] $field [description]
1574
-     * @return bool
1575
-     */
1576
-    private function check_user_cap_edit_field( $field ) {
1577 1536
 
1578
-        // If they can edit any entries (as defined in Gravity Forms), we're good.
1579
-        if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ) ) ) {
1580
-            return true;
1581
-        }
1537
+	/**
1538
+	 * Check whether a field is editable by the current user, and optionally display an error message
1539
+	 * @uses  GravityView_Edit_Entry->check_user_cap_edit_field() Check user capabilities
1540
+	 * @param  array  $field Field or field settings array
1541
+	 * @param  boolean $echo  Whether to show error message telling user they aren't allowed
1542
+	 * @return boolean         True: user can edit the current field; False: nope, they can't.
1543
+	 */
1544
+	private function user_can_edit_field( $field, $echo = false ) {
1582 1545
 
1583
-        $field_cap = isset( $field['allow_edit_cap'] ) ? $field['allow_edit_cap'] : false;
1546
+		$error = NULL;
1584 1547
 
1585
-        // If the field has custom editing capaibilities set, check those
1586
-        if( $field_cap ) {
1587
-            return GVCommon::has_cap( $field['allow_edit_cap'] );
1588
-        }
1589
-
1590
-        return false;
1591
-    }
1548
+		if( ! $this->check_user_cap_edit_field( $field ) ) {
1549
+			$error = __( 'You do not have permission to edit this field.', 'gravityview');
1550
+		}
1592 1551
 
1552
+		// No errors; everything's fine here!
1553
+		if( empty( $error ) ) {
1554
+			return true;
1555
+		}
1593 1556
 
1594
-    /**
1595
-     * Is the current nonce valid for editing the entry?
1596
-     * @return boolean
1597
-     */
1598
-    public function verify_nonce() {
1557
+		if( $echo ) {
1558
+			echo GVCommon::generate_notice( wpautop( esc_html( $error ) ), 'gv-error error');
1559
+		}
1599 1560
 
1600
-        // Verify form submitted for editing single
1601
-        if( $this->is_edit_entry_submission() ) {
1602
-            $valid = wp_verify_nonce( $_POST[ self::$nonce_field ], self::$nonce_field );
1603
-        }
1561
+		do_action('gravityview_log_error', 'GravityView_Edit_Entry[user_can_edit_field]' . $error );
1604 1562
 
1605
-        // Verify
1606
-        else if( ! $this->is_edit_entry() ) {
1607
-            $valid = false;
1608
-        }
1563
+		return false;
1609 1564
 
1610
-        else {
1611
-            $valid = wp_verify_nonce( $_GET['edit'], self::$nonce_key );
1612
-        }
1565
+	}
1613 1566
 
1614
-        /**
1615
-         * @filter `gravityview/edit_entry/verify_nonce` Override Edit Entry nonce validation. Return true to declare nonce valid.
1616
-         * @since 1.13
1617
-         * @param int|boolean $valid False if invalid; 1 or 2 when nonce was generated
1618
-         * @param string $nonce_field Key used when validating submissions. Default: is_gv_edit_entry
1619
-         */
1620
-        $valid = apply_filters( 'gravityview/edit_entry/verify_nonce', $valid, self::$nonce_field );
1621 1567
 
1622
-        return $valid;
1623
-    }
1568
+	/**
1569
+	 * checks if user has permissions to edit a specific field
1570
+	 *
1571
+	 * Needs to be used combined with GravityView_Edit_Entry::user_can_edit_field for maximum security!!
1572
+	 *
1573
+	 * @param  [type] $field [description]
1574
+	 * @return bool
1575
+	 */
1576
+	private function check_user_cap_edit_field( $field ) {
1577
+
1578
+		// If they can edit any entries (as defined in Gravity Forms), we're good.
1579
+		if( GVCommon::has_cap( array( 'gravityforms_edit_entries', 'gravityview_edit_others_entries' ) ) ) {
1580
+			return true;
1581
+		}
1582
+
1583
+		$field_cap = isset( $field['allow_edit_cap'] ) ? $field['allow_edit_cap'] : false;
1584
+
1585
+		// If the field has custom editing capaibilities set, check those
1586
+		if( $field_cap ) {
1587
+			return GVCommon::has_cap( $field['allow_edit_cap'] );
1588
+		}
1589
+
1590
+		return false;
1591
+	}
1592
+
1593
+
1594
+	/**
1595
+	 * Is the current nonce valid for editing the entry?
1596
+	 * @return boolean
1597
+	 */
1598
+	public function verify_nonce() {
1599
+
1600
+		// Verify form submitted for editing single
1601
+		if( $this->is_edit_entry_submission() ) {
1602
+			$valid = wp_verify_nonce( $_POST[ self::$nonce_field ], self::$nonce_field );
1603
+		}
1604
+
1605
+		// Verify
1606
+		else if( ! $this->is_edit_entry() ) {
1607
+			$valid = false;
1608
+		}
1609
+
1610
+		else {
1611
+			$valid = wp_verify_nonce( $_GET['edit'], self::$nonce_key );
1612
+		}
1613
+
1614
+		/**
1615
+		 * @filter `gravityview/edit_entry/verify_nonce` Override Edit Entry nonce validation. Return true to declare nonce valid.
1616
+		 * @since 1.13
1617
+		 * @param int|boolean $valid False if invalid; 1 or 2 when nonce was generated
1618
+		 * @param string $nonce_field Key used when validating submissions. Default: is_gv_edit_entry
1619
+		 */
1620
+		$valid = apply_filters( 'gravityview/edit_entry/verify_nonce', $valid, self::$nonce_field );
1621
+
1622
+		return $valid;
1623
+	}
1624 1624
 
1625 1625
 
1626 1626
 
Please login to merge, or discard this patch.
includes/fields/class-gravityview-field-post-content.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -22,13 +22,13 @@  discard block
 block discarded – undo
22 22
 
23 23
 	function field_options( $field_options, $template_id, $field_id, $context, $input_type ) {
24 24
 
25
-		unset( $field_options['show_as_link'] );
25
+		unset( $field_options[ 'show_as_link' ] );
26 26
 
27
-		if( 'edit' === $context ) {
27
+		if ( 'edit' === $context ) {
28 28
 			return $field_options;
29 29
 		}
30 30
 
31
-		$this->add_field_support('dynamic_data', $field_options );
31
+		$this->add_field_support( 'dynamic_data', $field_options );
32 32
 
33 33
 		return $field_options;
34 34
 	}
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 	 */
45 45
 	public function get_field_input( $form, $value = '', $entry = null, GF_Field_Post_Content $field ) {
46 46
 
47
-		$id    = (int) $field->id;
47
+		$id    = (int)$field->id;
48 48
 		$input_name = "input_{$id}";
49 49
 		$class = esc_attr( $field->size );
50 50
 		$tabindex = $field->get_tabindex();
Please login to merge, or discard this patch.