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