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